sbd_scsi.c revision 450396635f70344c58b6b1e4db38cf17ff34445c
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
1b7fc709228029b3f29f1c3de6d817a476f7c583tim szeto * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/conf.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/file.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ddi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/sunddi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/modctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/scsi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/impl/scsi_reset_notify.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/generic/mode.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/disp.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/byteorder.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/atomic.h>
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto#include <sys/sdt.h>
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#include <sys/dkio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stmf.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <lpif.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <portif.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stmf_ioctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stmf_sbd.h>
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#include <stmf_sbd_ioctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sbd_impl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto#define SCSI2_CONFLICT_FREE_CMDS(cdb) ( \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* ----------------------- */ \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Refer Both */ \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* SPC-2 (rev 20) Table 10 */ \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* SPC-3 (rev 23) Table 31 */ \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* ----------------------- */ \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ((cdb[0]) == SCMD_INQUIRY) || \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ((cdb[0]) == SCMD_LOG_SENSE_G1) || \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ((cdb[0]) == SCMD_RELEASE) || \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ((cdb[0]) == SCMD_RELEASE_G1) || \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ((cdb[0]) == SCMD_REPORT_LUNS) || \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ((cdb[0]) == SCMD_REQUEST_SENSE) || \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* PREVENT ALLOW MEDIUM REMOVAL with prevent == 0 */ \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ((((cdb[0]) == SCMD_DOORLOCK) && (((cdb[4]) & 0x3) == 0))) || \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* SERVICE ACTION IN with READ MEDIA SERIAL NUMBER (0x01) */ \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (((cdb[0]) == SCMD_SVC_ACTION_IN_G5) && ( \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ((cdb[1]) & 0x1F) == 0x01)) || \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* MAINTENANCE IN with service actions REPORT ALIASES (0x0Bh) */ \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* REPORT DEVICE IDENTIFIER (0x05) REPORT PRIORITY (0x0Eh) */ \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* REPORT TARGET PORT GROUPS (0x0A) REPORT TIMESTAMP (0x0F) */ \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (((cdb[0]) == SCMD_MAINTENANCE_IN) && ( \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (((cdb[1]) & 0x1F) == 0x0B) || \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (((cdb[1]) & 0x1F) == 0x05) || \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (((cdb[1]) & 0x1F) == 0x0E) || \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (((cdb[1]) & 0x1F) == 0x0A) || \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (((cdb[1]) & 0x1F) == 0x0F))) || \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* ----------------------- */ \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* SBC-3 (rev 17) Table 3 */ \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* ----------------------- */ \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* READ CAPACITY(10) */ \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ((cdb[0]) == SCMD_READ_CAPACITY) || \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* READ CAPACITY(16) */ \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (((cdb[0]) == SCMD_SVC_ACTION_IN_G4) && ( \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ((cdb[1]) & 0x1F) == 0x10)) || \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* START STOP UNIT with START bit 0 and POWER CONDITION 0 */ \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (((cdb[0]) == SCMD_START_STOP) && ( \
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (((cdb[4]) & 0xF0) == 0) && (((cdb[4]) & 0x01) == 0))))
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto/* End of SCSI2_CONFLICT_FREE_CMDS */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t sbd_lu_reset_state(stmf_lu_t *lu);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void sbd_handle_sync_cache(struct scsi_task *task,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stmf_data_buf *initial_dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid sbd_handle_read_xfer_completion(struct scsi_task *task,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_cmd_t *scmd, struct stmf_data_buf *dbuf);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetovoid sbd_handle_short_write_xfer_completion(scsi_task_t *task,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_data_buf_t *dbuf);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetovoid sbd_handle_short_write_transfers(scsi_task_t *task,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_data_buf_t *dbuf, uint32_t cdb_xfer_size);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetostatic void sbd_handle_sync_cache(struct scsi_task *task,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto struct stmf_data_buf *initial_dbuf);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetovoid sbd_handle_mode_select_xfer(scsi_task_t *task, uint8_t *buf,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint32_t buflen);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetovoid sbd_handle_mode_select(scsi_task_t *task, stmf_data_buf_t *dbuf);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoextern void sbd_pgr_initialize_it(scsi_task_t *);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoextern int sbd_pgr_reservation_conflict(scsi_task_t *);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forteextern void sbd_pgr_reset(sbd_lu_t *);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoextern void sbd_pgr_remove_it_handle(sbd_lu_t *, sbd_it_data_t *);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoextern void sbd_handle_pgr_in_cmd(scsi_task_t *, stmf_data_buf_t *);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoextern void sbd_handle_pgr_out_cmd(scsi_task_t *, stmf_data_buf_t *);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoextern void sbd_handle_pgr_out_data(scsi_task_t *, stmf_data_buf_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * IMPORTANT NOTE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * =================
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The whole world here is based on the assumption that everything within
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a scsi task executes in a single threaded manner, even the aborts.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Dont ever change that. There wont be any performance gain but there
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * will be tons of race conditions.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesbd_do_read_xfer(struct scsi_task *task, sbd_cmd_t *scmd,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stmf_data_buf *dbuf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_lu_t *sl = (sbd_lu_t *)task->task_lu->lu_provider_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t laddr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t len, buflen, iolen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ndx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int bufs_to_take;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Lets try not to hog all the buffers the port has. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufs_to_take = ((task->task_max_nbufs > 2) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (task->task_cmd_xfer_length < (32 * 1024))) ? 2 :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_max_nbufs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = scmd->len > dbuf->db_buf_size ? dbuf->db_buf_size : scmd->len;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto laddr = scmd->addr + scmd->current_ro;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (buflen = 0, ndx = 0; (buflen < len) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ndx < dbuf->db_sglist_length); ndx++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iolen = min(len - buflen, dbuf->db_sglist[ndx].seg_length);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iolen == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sbd_data_read(sl, laddr, (uint64_t)iolen,
8e326937258295218b5a1f9a63fa6bb760376bbeZhong Wang dbuf->db_sglist[ndx].seg_addr) != STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->flags |= SBD_SCSI_CMD_XFER_FAIL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Do not need to do xfer anymore, just complete it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_data_size = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_xfer_status = STMF_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_handle_read_xfer_completion(task, scmd, dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buflen += iolen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte laddr += (uint64_t)iolen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_relative_offset = scmd->current_ro;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_data_size = buflen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_flags = DB_DIRECTION_TO_RPORT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_xfer_data(task, dbuf, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->len -= buflen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->current_ro += buflen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scmd->len && (scmd->nbufs < bufs_to_take)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t maxsize, minsize, old_minsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte maxsize = (scmd->len > (128*1024)) ? 128*1024 : scmd->len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte minsize = maxsize >> 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * A bad port implementation can keep on failing the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the request but keep on sending us a false
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * minsize.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old_minsize = minsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf = stmf_alloc_dbuf(task, maxsize, &minsize, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while ((dbuf == NULL) && (old_minsize > minsize) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (minsize >= 512));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dbuf == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->nbufs++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_do_read_xfer(task, scmd, dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesbd_handle_read_xfer_completion(struct scsi_task *task, sbd_cmd_t *scmd,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stmf_data_buf *dbuf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dbuf->db_xfer_status != STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort(STMF_QUEUE_TASK_ABORT, task,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_xfer_status, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_nbytes_transferred += dbuf->db_data_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scmd->len == 0 || scmd->flags & SBD_SCSI_CMD_XFER_FAIL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_free_dbuf(task, dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->nbufs--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scmd->nbufs)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return; /* wait for all buffers to complete */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->flags &= ~SBD_SCSI_CMD_ACTIVE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scmd->flags & SBD_SCSI_CMD_XFER_FAIL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SAA_READ_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_GOOD, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang if (dbuf->db_flags & DB_DONT_REUSE) {
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang /* allocate new dbuf */
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang uint32_t maxsize, minsize, old_minsize;
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang stmf_free_dbuf(task, dbuf);
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang maxsize = (scmd->len > (128*1024)) ? 128*1024 : scmd->len;
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang minsize = maxsize >> 2;
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang do {
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang old_minsize = minsize;
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang dbuf = stmf_alloc_dbuf(task, maxsize, &minsize, 0);
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang } while ((dbuf == NULL) && (old_minsize > minsize) &&
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang (minsize >= 512));
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang if (dbuf == NULL) {
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang scmd->nbufs --;
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang if (scmd->nbufs == 0) {
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang stmf_abort(STMF_QUEUE_TASK_ABORT, task,
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang STMF_ALLOC_FAILURE, NULL);
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang }
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang return;
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang }
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_do_read_xfer(task, scmd, dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesbd_handle_read(struct scsi_task *task, struct stmf_data_buf *initial_dbuf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t lba, laddr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t op = task->task_cdb[0];
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_lu_t *sl = (sbd_lu_t *)task->task_lu->lu_provider_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_cmd_t *scmd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_data_buf_t *dbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fast_path;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (op == SCMD_READ) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lba = READ_SCSI21(&task->task_cdb[1], uint64_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = (uint32_t)task->task_cdb[4];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (len == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = 256;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (op == SCMD_READ_G1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lba = READ_SCSI32(&task->task_cdb[2], uint64_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = READ_SCSI16(&task->task_cdb[7], uint32_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (op == SCMD_READ_G5) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lba = READ_SCSI32(&task->task_cdb[2], uint64_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = READ_SCSI32(&task->task_cdb[6], uint32_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (op == SCMD_READ_G4) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lba = READ_SCSI64(&task->task_cdb[2], uint64_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = READ_SCSI32(&task->task_cdb[10], uint32_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SAA_INVALID_OPCODE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto laddr = lba << sl->sl_data_blocksize_shift;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto len <<= sl->sl_data_blocksize_shift;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((laddr + (uint64_t)len) > sl->sl_lu_size) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SAA_LBA_OUT_OF_RANGE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_cmd_xfer_length = len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (task->task_additional_flags & TASK_AF_NO_EXPECTED_XFER_LENGTH) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_expected_xfer_length = len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (len != task->task_expected_xfer_length) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fast_path = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = (len > task->task_expected_xfer_length) ?
1b7fc709228029b3f29f1c3de6d817a476f7c583tim szeto task->task_expected_xfer_length : len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fast_path = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (len == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_GOOD, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (initial_dbuf == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t maxsize, minsize, old_minsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte maxsize = (len > (128*1024)) ? 128*1024 : len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte minsize = maxsize >> 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old_minsize = minsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte initial_dbuf = stmf_alloc_dbuf(task, maxsize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &minsize, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while ((initial_dbuf == NULL) && (old_minsize > minsize) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (minsize >= 512));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (initial_dbuf == NULL) {
1b7fc709228029b3f29f1c3de6d817a476f7c583tim szeto stmf_scsilib_send_status(task, STATUS_QFULL, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf = initial_dbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dbuf->db_buf_size >= len) && fast_path &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (dbuf->db_sglist_length == 1)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sbd_data_read(sl, laddr, (uint64_t)len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_sglist[0].seg_addr) == STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_relative_offset = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_data_size = len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_flags = DB_SEND_STATUS_GOOD |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DB_DIRECTION_TO_RPORT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_xfer_data(task, dbuf, STMF_IOF_LU_DONE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SAA_READ_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (task->task_lu_private) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd = (sbd_cmd_t *)task->task_lu_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd = (sbd_cmd_t *)kmem_alloc(sizeof (sbd_cmd_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_lu_private = scmd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->flags = SBD_SCSI_CMD_ACTIVE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->cmd_type = SBD_CMD_SCSI_READ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->nbufs = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->addr = laddr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->len = len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->current_ro = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_do_read_xfer(task, scmd, dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesbd_do_write_xfer(struct scsi_task *task, sbd_cmd_t *scmd,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stmf_data_buf *dbuf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int bufs_to_take;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Lets try not to hog all the buffers the port has. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufs_to_take = ((task->task_max_nbufs > 2) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (task->task_cmd_xfer_length < (32 * 1024))) ? 2 :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_max_nbufs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = scmd->len > dbuf->db_buf_size ? dbuf->db_buf_size : scmd->len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_relative_offset = scmd->current_ro;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_data_size = len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_flags = DB_DIRECTION_FROM_RPORT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_xfer_data(task, dbuf, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->len -= len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->current_ro += len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scmd->len && (scmd->nbufs < bufs_to_take)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t maxsize, minsize, old_minsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte maxsize = (scmd->len > (128*1024)) ? 128*1024 : scmd->len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte minsize = maxsize >> 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old_minsize = minsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf = stmf_alloc_dbuf(task, maxsize, &minsize, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while ((dbuf == NULL) && (old_minsize > minsize) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (minsize >= 512));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dbuf == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->nbufs++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_do_write_xfer(task, scmd, dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesbd_handle_write_xfer_completion(struct scsi_task *task, sbd_cmd_t *scmd,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stmf_data_buf *dbuf, uint8_t dbuf_reusable)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_lu_t *sl = (sbd_lu_t *)task->task_lu->lu_provider_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t laddr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t buflen, iolen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ndx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dbuf->db_xfer_status != STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort(STMF_QUEUE_TASK_ABORT, task,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_xfer_status, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scmd->flags & SBD_SCSI_CMD_XFER_FAIL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto WRITE_XFER_DONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto laddr = scmd->addr + dbuf->db_relative_offset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (buflen = 0, ndx = 0; (buflen < dbuf->db_data_size) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ndx < dbuf->db_sglist_length); ndx++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iolen = min(dbuf->db_data_size - buflen,
1b7fc709228029b3f29f1c3de6d817a476f7c583tim szeto dbuf->db_sglist[ndx].seg_length);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iolen == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sbd_data_write(sl, laddr, (uint64_t)iolen,
8e326937258295218b5a1f9a63fa6bb760376bbeZhong Wang dbuf->db_sglist[ndx].seg_addr) != STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->flags |= SBD_SCSI_CMD_XFER_FAIL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buflen += iolen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte laddr += (uint64_t)iolen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_nbytes_transferred += buflen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteWRITE_XFER_DONE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scmd->len == 0 || scmd->flags & SBD_SCSI_CMD_XFER_FAIL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_free_dbuf(task, dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->nbufs--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scmd->nbufs)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return; /* wait for all buffers to complete */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->flags &= ~SBD_SCSI_CMD_ACTIVE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scmd->flags & SBD_SCSI_CMD_XFER_FAIL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SAA_WRITE_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_GOOD, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
2a8164df8a5f42c8a00f10c67d7bc84f80ae9c41Zhong Wang if (dbuf->db_flags & DB_DONT_REUSE || dbuf_reusable == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t maxsize, minsize, old_minsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* free current dbuf and allocate a new one */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_free_dbuf(task, dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte maxsize = (scmd->len > (128*1024)) ? 128*1024 : scmd->len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte minsize = maxsize >> 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old_minsize = minsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf = stmf_alloc_dbuf(task, maxsize, &minsize, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while ((dbuf == NULL) && (old_minsize > minsize) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (minsize >= 512));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dbuf == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->nbufs --;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scmd->nbufs == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort(STMF_QUEUE_TASK_ABORT, task,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_ALLOC_FAILURE, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_do_write_xfer(task, scmd, dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesbd_handle_write(struct scsi_task *task, struct stmf_data_buf *initial_dbuf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t lba, laddr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t op = task->task_cdb[0], do_immediate_data = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_lu_t *sl = (sbd_lu_t *)task->task_lu->lu_provider_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_cmd_t *scmd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_data_buf_t *dbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sl->sl_flags & SL_WRITE_PROTECTED) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_scsilib_send_status(task, STATUS_CHECK,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_SAA_WRITE_PROTECTED);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (op == SCMD_WRITE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lba = READ_SCSI21(&task->task_cdb[1], uint64_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = (uint32_t)task->task_cdb[4];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (len == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = 256;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (op == SCMD_WRITE_G1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lba = READ_SCSI32(&task->task_cdb[2], uint64_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = READ_SCSI16(&task->task_cdb[7], uint32_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (op == SCMD_WRITE_G5) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lba = READ_SCSI32(&task->task_cdb[2], uint64_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = READ_SCSI32(&task->task_cdb[6], uint32_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (op == SCMD_WRITE_G4) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lba = READ_SCSI64(&task->task_cdb[2], uint64_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = READ_SCSI32(&task->task_cdb[10], uint32_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SAA_INVALID_OPCODE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto laddr = lba << sl->sl_data_blocksize_shift;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto len <<= sl->sl_data_blocksize_shift;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((laddr + (uint64_t)len) > sl->sl_lu_size) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SAA_LBA_OUT_OF_RANGE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_cmd_xfer_length = len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (task->task_additional_flags & TASK_AF_NO_EXPECTED_XFER_LENGTH) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_expected_xfer_length = len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = (len > task->task_expected_xfer_length) ?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_expected_xfer_length : len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (len == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_GOOD, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (initial_dbuf == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t maxsize, minsize, old_minsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte maxsize = (len > (128*1024)) ? 128*1024 : len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte minsize = maxsize >> 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old_minsize = minsize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte initial_dbuf = stmf_alloc_dbuf(task, maxsize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &minsize, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while ((initial_dbuf == NULL) && (old_minsize > minsize) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (minsize >= 512));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (initial_dbuf == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort(STMF_QUEUE_TASK_ABORT, task,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_ALLOC_FAILURE, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (task->task_flags & TF_INITIAL_BURST) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (initial_dbuf->db_data_size > len) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (initial_dbuf->db_data_size >
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_expected_xfer_length) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* protocol error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort(STMF_QUEUE_TASK_ABORT, task,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_INVALID_ARG, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte initial_dbuf->db_data_size = len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do_immediate_data = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf = initial_dbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (task->task_lu_private) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd = (sbd_cmd_t *)task->task_lu_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd = (sbd_cmd_t *)kmem_alloc(sizeof (sbd_cmd_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_lu_private = scmd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->flags = SBD_SCSI_CMD_ACTIVE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->cmd_type = SBD_CMD_SCSI_WRITE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->nbufs = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->addr = laddr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->len = len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->current_ro = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (do_immediate_data) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->len -= dbuf->db_data_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->current_ro += dbuf->db_data_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_xfer_status = STMF_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_handle_write_xfer_completion(task, scmd, dbuf, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_do_write_xfer(task, scmd, dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Utility routine to handle small non performance data transfers to the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * initiators. dbuf is an initial data buf (if any), 'p' points to a data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * buffer which is source of data for transfer, cdb_xfer_size is the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * transfer size based on CDB, cmd_xfer_size is the actual amount of data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * which this command would transfer (the size of data pointed to by 'p').
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesbd_handle_short_read_transfers(scsi_task_t *task, stmf_data_buf_t *dbuf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *p, uint32_t cdb_xfer_size, uint32_t cmd_xfer_size)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t bufsize, ndx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_cmd_t *scmd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmd_xfer_size = min(cmd_xfer_size, cdb_xfer_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_cmd_xfer_length = cmd_xfer_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (task->task_additional_flags & TASK_AF_NO_EXPECTED_XFER_LENGTH) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_expected_xfer_length = cmd_xfer_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmd_xfer_size = min(cmd_xfer_size,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_expected_xfer_length);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cmd_xfer_size == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SAA_INVALID_FIELD_IN_CDB);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dbuf == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t minsize = cmd_xfer_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf = stmf_alloc_dbuf(task, cmd_xfer_size, &minsize, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dbuf == NULL) {
1b7fc709228029b3f29f1c3de6d817a476f7c583tim szeto stmf_scsilib_send_status(task, STATUS_QFULL, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (bufsize = 0, ndx = 0; bufsize < cmd_xfer_size; ndx++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t *d;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte d = dbuf->db_sglist[ndx].seg_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s = min((cmd_xfer_size - bufsize),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_sglist[ndx].seg_length);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(p+bufsize, d, s);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bufsize += s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_relative_offset = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_data_size = cmd_xfer_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_flags = DB_DIRECTION_TO_RPORT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (task->task_lu_private == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_lu_private =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_alloc(sizeof (sbd_cmd_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd = (sbd_cmd_t *)task->task_lu_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->cmd_type = SBD_CMD_SMALL_READ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->flags = SBD_SCSI_CMD_ACTIVE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_xfer_data(task, dbuf, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesbd_handle_short_read_xfer_completion(struct scsi_task *task, sbd_cmd_t *scmd,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stmf_data_buf *dbuf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dbuf->db_xfer_status != STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_abort(STMF_QUEUE_TASK_ABORT, task,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dbuf->db_xfer_status, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_nbytes_transferred = dbuf->db_data_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->flags &= ~SBD_SCSI_CMD_ACTIVE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_GOOD, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetovoid
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetosbd_handle_short_write_transfers(scsi_task_t *task,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_data_buf_t *dbuf, uint32_t cdb_xfer_size)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_cmd_t *scmd;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto task->task_cmd_xfer_length = cdb_xfer_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (task->task_additional_flags & TASK_AF_NO_EXPECTED_XFER_LENGTH) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto task->task_expected_xfer_length = cdb_xfer_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto cdb_xfer_size = min(cdb_xfer_size,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto task->task_expected_xfer_length);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (cdb_xfer_size == 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_scsilib_send_status(task, STATUS_CHECK,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_SAA_INVALID_FIELD_IN_CDB);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (task->task_lu_private == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto task->task_lu_private = kmem_zalloc(sizeof (sbd_cmd_t),
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto KM_SLEEP);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bzero(task->task_lu_private, sizeof (sbd_cmd_t));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto scmd = (sbd_cmd_t *)task->task_lu_private;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto scmd->cmd_type = SBD_CMD_SMALL_WRITE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto scmd->flags = SBD_SCSI_CMD_ACTIVE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto scmd->len = cdb_xfer_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (dbuf == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint32_t minsize = cdb_xfer_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto dbuf = stmf_alloc_dbuf(task, cdb_xfer_size, &minsize, 0);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (dbuf == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_abort(STMF_QUEUE_TASK_ABORT, task,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_ALLOC_FAILURE, NULL);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto dbuf->db_data_size = cdb_xfer_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto dbuf->db_relative_offset = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto dbuf->db_flags = DB_DIRECTION_FROM_RPORT;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_xfer_data(task, dbuf, 0);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (dbuf->db_data_size < cdb_xfer_size) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_abort(STMF_QUEUE_TASK_ABORT, task,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_ABORTED, NULL);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto dbuf->db_data_size = cdb_xfer_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_handle_short_write_xfer_completion(task, dbuf);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetovoid
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetosbd_handle_short_write_xfer_completion(scsi_task_t *task,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_data_buf_t *dbuf)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_cmd_t *scmd;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_status_t st_ret;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sbd_lu_t *sl = (sbd_lu_t *)task->task_lu->lu_provider_private;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * For now lets assume we will get only one sglist element
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * for short writes. If that ever changes, we should allocate
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * a local buffer and copy all the sg elements to one linear space.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((dbuf->db_xfer_status != STMF_SUCCESS) ||
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (dbuf->db_sglist_length > 1)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_abort(STMF_QUEUE_TASK_ABORT, task,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto dbuf->db_xfer_status, NULL);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto task->task_nbytes_transferred = dbuf->db_data_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto scmd = (sbd_cmd_t *)task->task_lu_private;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto scmd->flags &= ~SBD_SCSI_CMD_ACTIVE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Lets find out who to call */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (task->task_cdb[0]) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case SCMD_MODE_SELECT:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case SCMD_MODE_SELECT_G1:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (sl->sl_access_state == SBD_LU_STANDBY) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte st_ret = stmf_proxy_scsi_cmd(task, dbuf);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (st_ret != STMF_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_SAA_LU_NO_ACCESS_UNAVAIL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sbd_handle_mode_select_xfer(task,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte dbuf->db_sglist[0].seg_addr, dbuf->db_data_size);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case SCMD_PERSISTENT_RESERVE_OUT:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (sl->sl_access_state == SBD_LU_STANDBY) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte st_ret = stmf_proxy_scsi_cmd(task, dbuf);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (st_ret != STMF_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_SAA_LU_NO_ACCESS_UNAVAIL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sbd_handle_pgr_out_data(task, dbuf);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* This should never happen */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_abort(STMF_QUEUE_TASK_ABORT, task,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_ABORTED, NULL);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesbd_handle_read_capacity(struct scsi_task *task,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stmf_data_buf *initial_dbuf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_lu_t *sl = (sbd_lu_t *)task->task_lu->lu_provider_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t cdb_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t p[32];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t s;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint16_t blksize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto s = sl->sl_lu_size >> sl->sl_data_blocksize_shift;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s--;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto blksize = ((uint16_t)1) << sl->sl_data_blocksize_shift;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (task->task_cdb[0]) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case SCMD_READ_CAPACITY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (s & 0xffffffff00000000ull) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[0] = p[1] = p[2] = p[3] = 0xFF;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[0] = (s >> 24) & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[1] = (s >> 16) & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[2] = (s >> 8) & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[3] = s & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[4] = 0; p[5] = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[6] = (blksize >> 8) & 0xff;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[7] = blksize & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_handle_short_read_transfers(task, initial_dbuf, p, 8, 8);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case SCMD_SVC_ACTION_IN_G4:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb_len = READ_SCSI32(&task->task_cdb[10], uint32_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(p, 32);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[0] = (s >> 56) & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[1] = (s >> 48) & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[2] = (s >> 40) & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[3] = (s >> 32) & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[4] = (s >> 24) & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[5] = (s >> 16) & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[6] = (s >> 8) & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[7] = s & 0xff;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[10] = (blksize >> 8) & 0xff;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[11] = blksize & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_handle_short_read_transfers(task, initial_dbuf, p,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb_len, 32);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetovoid
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetosbd_calc_geometry(uint64_t s, uint16_t blksize, uint8_t *nsectors,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint8_t *nheads, uint32_t *ncyl)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (s < (4ull * 1024ull * 1024ull * 1024ull)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *nsectors = 32;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *nheads = 8;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *nsectors = 254;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *nheads = 254;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto *ncyl = s / ((uint64_t)blksize * (uint64_t)(*nsectors) *
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (uint64_t)(*nheads));
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesbd_handle_mode_sense(struct scsi_task *task,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto struct stmf_data_buf *initial_dbuf, uint8_t *buf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_lu_t *sl = (sbd_lu_t *)task->task_lu->lu_provider_private;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint32_t cmd_size, n;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint8_t *cdb;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint32_t ncyl;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint8_t nsectors, nheads;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint8_t page, ctrl, header_size, pc_valid;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint16_t nbytes;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint8_t *p;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint64_t s = sl->sl_lu_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint32_t dev_spec_param_offset;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p = buf; /* buf is assumed to be zeroed out and large enough */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto n = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto cdb = &task->task_cdb[0];
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto page = cdb[2] & 0x3F;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ctrl = (cdb[2] >> 6) & 3;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto cmd_size = (cdb[0] == SCMD_MODE_SENSE) ? cdb[4] :
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto READ_SCSI16(&cdb[7], uint32_t);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (cdb[0] == SCMD_MODE_SENSE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto header_size = 4;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto dev_spec_param_offset = 2;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto header_size = 8;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto dev_spec_param_offset = 3;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Now validate the command */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((cdb[2] == 0) || (page == MODEPAGE_ALLPAGES) || (page == 0x08) ||
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto (page == 0x0A) || (page == 0x03) || (page == 0x04)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto pc_valid = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto pc_valid = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((cmd_size < header_size) || (pc_valid == 0)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_scsilib_send_status(task, STATUS_CHECK,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_SAA_INVALID_FIELD_IN_CDB);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* We will update the length in the mode header at the end */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Block dev device specific param in mode param header has wp bit */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sl->sl_flags & SL_WRITE_PROTECTED) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[n + dev_spec_param_offset] = BIT_7;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto n += header_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* We are not going to return any block descriptor */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto nbytes = ((uint16_t)1) << sl->sl_data_blocksize_shift;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_calc_geometry(s, nbytes, &nsectors, &nheads, &ncyl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((page == 0x03) || (page == MODEPAGE_ALLPAGES)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[n] = 0x03;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[n+1] = 0x16;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ctrl != 1) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[n + 11] = nsectors;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[n + 12] = nbytes >> 8;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[n + 13] = nbytes & 0xff;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[n + 20] = 0x80;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto n += 24;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((page == 0x04) || (page == MODEPAGE_ALLPAGES)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[n] = 0x04;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[n + 1] = 0x16;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ctrl != 1) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[n + 2] = ncyl >> 16;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[n + 3] = ncyl >> 8;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[n + 4] = ncyl & 0xff;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[n + 5] = nheads;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[n + 20] = 0x15;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[n + 21] = 0x18;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto n += 24;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((page == MODEPAGE_CACHING) || (page == MODEPAGE_ALLPAGES)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto struct mode_caching *mode_caching_page;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mode_caching_page = (struct mode_caching *)&p[n];
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mode_caching_page->mode_page.code = MODEPAGE_CACHING;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mode_caching_page->mode_page.ps = 1; /* A saveable page */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mode_caching_page->mode_page.length = 0x12;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (ctrl) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case (0):
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Current */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((sl->sl_flags & SL_WRITEBACK_CACHE_DISABLE) == 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mode_caching_page->wce = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case (1):
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Changeable */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((sl->sl_flags &
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto SL_WRITEBACK_CACHE_SET_UNSUPPORTED) == 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mode_caching_page->wce = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((sl->sl_flags &
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto SL_SAVED_WRITE_CACHE_DISABLE) == 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mode_caching_page->wce = 1;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto n += (sizeof (struct mode_page) +
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mode_caching_page->mode_page.length);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((page == MODEPAGE_CTRL_MODE) || (page == MODEPAGE_ALLPAGES)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto struct mode_control_scsi3 *mode_control_page;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mode_control_page = (struct mode_control_scsi3 *)&p[n];
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mode_control_page->mode_page.code = MODEPAGE_CTRL_MODE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mode_control_page->mode_page.length =
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto PAGELENGTH_MODE_CONTROL_SCSI3;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (ctrl != 1) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* If not looking for changeable values, report this. */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mode_control_page->que_mod = CTRL_QMOD_UNRESTRICT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto n += (sizeof (struct mode_page) +
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mode_control_page->mode_page.length);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (cdb[0] == SCMD_MODE_SENSE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (n > 255) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_scsilib_send_status(task, STATUS_CHECK,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_SAA_INVALID_FIELD_IN_CDB);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Mode parameter header length doesn't include the number
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * of bytes in the length field, so adjust the count.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Byte count minus header length field size.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto buf[0] = (n - 1) & 0xff;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Byte count minus header length field size. */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto buf[1] = (n - 2) & 0xff;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto buf[0] = ((n - 2) >> 8) & 0xff;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_handle_short_read_transfers(task, initial_dbuf, buf,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto cmd_size, n);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetovoid
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetosbd_handle_mode_select(scsi_task_t *task, stmf_data_buf_t *dbuf)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint32_t cmd_xfer_len;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (task->task_cdb[0] == SCMD_MODE_SELECT) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto cmd_xfer_len = (uint32_t)task->task_cdb[4];
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto cmd_xfer_len = READ_SCSI16(&task->task_cdb[7], uint32_t);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((task->task_cdb[1] & 0xFE) != 0x10) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SAA_INVALID_FIELD_IN_CDB);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (cmd_xfer_len == 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* zero byte mode selects are allowed */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_scsilib_send_status(task, STATUS_GOOD, 0);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_handle_short_write_transfers(task, dbuf, cmd_xfer_len);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetovoid
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetosbd_handle_mode_select_xfer(scsi_task_t *task, uint8_t *buf, uint32_t buflen)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_lu_t *sl = (sbd_lu_t *)task->task_lu->lu_provider_private;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_it_data_t *it;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int hdr_len, bd_len;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_status_t sret;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int i;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (task->task_cdb[0] == SCMD_MODE_SELECT) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto hdr_len = 4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto hdr_len = 8;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (buflen < hdr_len)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto mode_sel_param_len_err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bd_len = hdr_len == 4 ? buf[3] : READ_SCSI16(&buf[6], int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (buflen < (hdr_len + bd_len + 2))
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto mode_sel_param_len_err;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto buf += hdr_len + bd_len;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto buflen -= hdr_len + bd_len;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((buf[0] != 8) || (buflen != ((uint32_t)buf[1] + 2))) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto mode_sel_param_len_err;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (buf[2] & 0xFB) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto mode_sel_param_field_err;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto for (i = 3; i < (buf[1] + 2); i++) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (buf[i]) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto mode_sel_param_field_err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sret = SBD_SUCCESS;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* All good. Lets handle the write cache change, if any */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (buf[2] & BIT_2) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sret = sbd_wcd_set(0, sl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sret = sbd_wcd_set(1, sl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sret != SBD_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_scsilib_send_status(task, STATUS_CHECK,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_SAA_WRITE_ERROR);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* set on the device passed, now set the flags */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_enter(&sl->sl_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (buf[2] & BIT_2) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sl->sl_flags &= ~SL_WRITEBACK_CACHE_DISABLE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sl->sl_flags |= SL_WRITEBACK_CACHE_DISABLE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto for (it = sl->sl_it_list; it != NULL; it = it->sbd_it_next) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (it == task->task_lu_itl_handle)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto continue;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto it->sbd_it_ua_conditions |= SBD_UA_MODE_PARAMETERS_CHANGED;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (task->task_cdb[1] & 1) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (buf[2] & BIT_2) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sl->sl_flags &= ~SL_SAVED_WRITE_CACHE_DISABLE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sl->sl_flags |= SL_SAVED_WRITE_CACHE_DISABLE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&sl->sl_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sret = sbd_write_lu_info(sl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&sl->sl_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sret == SBD_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_scsilib_send_status(task, STATUS_GOOD, 0);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_scsilib_send_status(task, STATUS_CHECK,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_SAA_WRITE_ERROR);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetomode_sel_param_len_err:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_scsilib_send_status(task, STATUS_CHECK,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_SAA_PARAM_LIST_LENGTH_ERROR);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetomode_sel_param_field_err:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_scsilib_send_status(task, STATUS_CHECK,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_SAA_INVALID_FIELD_IN_PARAM_LIST);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan/*
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan * This function parse through a string, passed to it as a pointer to a string,
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan * by adjusting the pointer to the first non-space character and returns
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan * the count/length of the first bunch of non-space characters. Multiple
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan * Management URLs are stored as a space delimited string in sl_mgmt_url
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan * field of sbd_lu_t. This function is used to retrieve one url at a time.
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan *
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan * i/p : pointer to pointer to a url string
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan * o/p : Adjust the pointer to the url to the first non white character
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan * and returns the length of the URL
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan */
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyanuint16_t
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyansbd_parse_mgmt_url(char **url_addr) {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan uint16_t url_length = 0;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan char *url;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan url = *url_addr;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan while (*url != '\0') {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan if (*url == ' ' || *url == '\t' || *url == '\n') {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan (*url_addr)++;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan url = *url_addr;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan } else {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan break;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan }
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan }
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan while (*url != '\0') {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan if (*url == ' ' || *url == '\t' ||
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan *url == '\n' || *url == '\0') {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan break;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan }
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan url++;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan url_length++;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan }
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan return (url_length);
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan}
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyansbd_handle_inquiry(struct scsi_task *task, struct stmf_data_buf *initial_dbuf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_lu_t *sl = (sbd_lu_t *)task->task_lu->lu_provider_private;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint8_t *cdbp = (uint8_t *)&task->task_cdb[0];
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan uint8_t *p;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint8_t byte0;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan uint8_t page_length;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan uint16_t bsize = 512;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan uint16_t cmd_size;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan uint32_t xfer_size = 4;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan uint32_t mgmt_url_size = 0;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto byte0 = DTYPE_DIRECT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Basic protocol checks.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((((cdbp[1] & 1) == 0) && cdbp[2]) || cdbp[5]) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SAA_INVALID_FIELD_IN_CDB);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Zero byte allocation length is not an error. Just
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan cmd_size = (((uint16_t)cdbp[3]) << 8) | cdbp[4];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cmd_size == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_cmd_xfer_length = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (task->task_additional_flags &
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte TASK_AF_NO_EXPECTED_XFER_LENGTH) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_expected_xfer_length = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_GOOD, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan if (sl->sl_mgmt_url) {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan mgmt_url_size = strlen(sl->sl_mgmt_url);
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan }
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Standard inquiry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cdbp[1] & 1) == 0) {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan int i;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan struct scsi_inquiry *inq;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan p = (uint8_t *)kmem_zalloc(bsize, KM_SLEEP);
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan inq = (struct scsi_inquiry *)p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan page_length = 69;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan xfer_size = page_length + 5;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto inq->inq_dtype = DTYPE_DIRECT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inq->inq_ansi = 5; /* SPC-3 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inq->inq_hisup = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inq->inq_rdf = 2; /* Response data format for SPC-3 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inq->inq_len = page_length;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan inq->inq_tpgs = TPGS_FAILOVER_IMPLICIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inq->inq_cmdque = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sl->sl_flags & SL_VID_VALID) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(sl->sl_vendor_id, inq->inq_vid, 8);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(sbd_vendor_id, inq->inq_vid, 8);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sl->sl_flags & SL_PID_VALID) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(sl->sl_product_id, inq->inq_pid, 16);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(sbd_product_id, inq->inq_pid, 16);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sl->sl_flags & SL_REV_VALID) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(sl->sl_revision, inq->inq_revision, 4);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(sbd_revision, inq->inq_revision, 4);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan /* Adding Version Descriptors */
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan i = 0;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan /* SAM-3 no version */
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan inq->inq_vd[i].inq_vd_msb = 0x00;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan inq->inq_vd[i].inq_vd_lsb = 0x60;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan i++;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan /* transport */
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan switch (task->task_lport->lport_id->protocol_id) {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan case PROTOCOL_FIBRE_CHANNEL:
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan inq->inq_vd[i].inq_vd_msb = 0x09;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan inq->inq_vd[i].inq_vd_lsb = 0x00;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan i++;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan break;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan case PROTOCOL_PARALLEL_SCSI:
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan case PROTOCOL_SSA:
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan case PROTOCOL_IEEE_1394:
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan /* Currently no claims of conformance */
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan break;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan case PROTOCOL_SRP:
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan inq->inq_vd[i].inq_vd_msb = 0x09;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan inq->inq_vd[i].inq_vd_lsb = 0x40;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan i++;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan break;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan case PROTOCOL_iSCSI:
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan inq->inq_vd[i].inq_vd_msb = 0x09;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan inq->inq_vd[i].inq_vd_lsb = 0x60;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan i++;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan break;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan case PROTOCOL_SAS:
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan case PROTOCOL_ADT:
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan case PROTOCOL_ATAPI:
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan default:
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan /* Currently no claims of conformance */
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan break;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan }
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan /* SPC-3 no version */
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan inq->inq_vd[i].inq_vd_msb = 0x03;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan inq->inq_vd[i].inq_vd_lsb = 0x00;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan i++;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan /* SBC-2 no version */
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan inq->inq_vd[i].inq_vd_msb = 0x03;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan inq->inq_vd[i].inq_vd_lsb = 0x20;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_handle_short_read_transfers(task, initial_dbuf, p, cmd_size,
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan min(cmd_size, xfer_size));
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan kmem_free(p, bsize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * EVPD handling
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan /* Default 512 bytes may not be enough, increase bsize if necessary */
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan if (cdbp[2] == 0x83 || cdbp[2] == 0x85) {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan if (bsize < cmd_size)
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan bsize = cmd_size;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan }
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan p = (uint8_t *)kmem_zalloc(bsize, KM_SLEEP);
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (cdbp[2]) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 0x00:
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan page_length = 4 + (mgmt_url_size ? 1 : 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[0] = byte0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[3] = page_length;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan /* Supported VPD pages in ascending order */
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan uint8_t i = 5;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan p[i++] = 0x80;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan p[i++] = 0x83;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan if (mgmt_url_size != 0)
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan p[i++] = 0x85;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan p[i++] = 0x86;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan }
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan xfer_size = page_length + 4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case 0x80:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sl->sl_serial_no_size) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto page_length = sl->sl_serial_no_size;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(sl->sl_serial_no, p + 4, sl->sl_serial_no_size);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan /* if no serial num is specified set 4 spaces */
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan page_length = 4;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bcopy(" ", p + 4, 4);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[0] = byte0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[1] = 0x80;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[3] = page_length;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan xfer_size = page_length + 4;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 0x83:
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan xfer_size = stmf_scsilib_prepare_vpd_page83(task, p,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto bsize, byte0, STMF_VPD_LU_ID|STMF_VPD_TARGET_ID|
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan STMF_VPD_TP_GROUP|STMF_VPD_RELATIVE_TP_ID);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan case 0x85:
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan if (mgmt_url_size == 0) {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan stmf_scsilib_send_status(task, STATUS_CHECK,
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan STMF_SAA_INVALID_FIELD_IN_CDB);
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan kmem_free(p, bsize);
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan return;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan }
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan uint16_t idx, newidx, sz, url_size;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan char *url;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan p[0] = byte0;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan p[1] = 0x85;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan idx = 4;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan url = sl->sl_mgmt_url;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan url_size = sbd_parse_mgmt_url(&url);
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan /* Creating Network Service Descriptors */
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan while (url_size != 0) {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan /* Null terminated and 4 Byte aligned */
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan sz = url_size + 1;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan sz += (sz % 4) ? 4 - (sz % 4) : 0;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan newidx = idx + sz + 4;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan if (newidx < bsize) {
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan /*
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan * SPC-3r23 : Table 320 (Sec 7.6.5)
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan * (Network service descriptor format
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan *
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan * Note: Hard coding service type as
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan * "Storage Configuration Service".
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan */
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan p[idx] = 1;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan SCSI_WRITE16(p + idx + 2, sz);
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan bcopy(url, p + idx + 4, url_size);
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan xfer_size = newidx + 4;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan }
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan idx = newidx;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan /* skip to next mgmt url if any */
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan url += url_size;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan url_size = sbd_parse_mgmt_url(&url);
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan }
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan /* Total descriptor length */
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan SCSI_WRITE16(p + 2, idx - 4);
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan break;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan }
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 0x86:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte page_length = 0x3c;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p[0] = byte0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[1] = 0x86; /* Page 86 response */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[3] = page_length;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Bits 0, 1, and 2 will need to be updated
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to reflect the queue tag handling if/when
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * that is implemented. For now, we're going
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to claim support only for Simple TA.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p[5] = 1;
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan xfer_size = page_length + 4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SAA_INVALID_FIELD_IN_CDB);
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan kmem_free(p, bsize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_handle_short_read_transfers(task, initial_dbuf, p, cmd_size,
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan min(cmd_size, xfer_size));
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan kmem_free(p, bsize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesbd_task_alloc(struct scsi_task *task)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((task->task_lu_private =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_alloc(sizeof (sbd_cmd_t), KM_NOSLEEP)) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_cmd_t *scmd = (sbd_cmd_t *)task->task_lu_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->flags = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ALLOC_FAILURE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetosbd_remove_it_handle(sbd_lu_t *sl, sbd_it_data_t *it)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_it_data_t **ppit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_pgr_remove_it_handle(sl, it);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_enter(&sl->sl_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto for (ppit = &sl->sl_it_list; *ppit != NULL;
1b7fc709228029b3f29f1c3de6d817a476f7c583tim szeto ppit = &((*ppit)->sbd_it_next)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*ppit) == it) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *ppit = it->sbd_it_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&sl->sl_lock);
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto DTRACE_PROBE2(itl__nexus__end, stmf_lu_t *, sl->sl_lu,
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto sbd_it_data_t *, it);
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(it, sizeof (*it));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetosbd_check_and_clear_scsi2_reservation(sbd_lu_t *sl, sbd_it_data_t *it)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_enter(&sl->sl_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((sl->sl_flags & SL_LU_HAS_SCSI2_RESERVATION) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If we dont have any reservations, just get out. */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&sl->sl_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (it == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Find the I_T nexus which is holding the reservation. */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto for (it = sl->sl_it_list; it != NULL; it = it->sbd_it_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (it->sbd_it_flags & SBD_IT_HAS_SCSI2_RESERVATION) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(it->sbd_it_session_id ==
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sl->sl_rs_owner_session_id);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(it != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We were passed an I_T nexus. If this nexus does not hold
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the reservation, do nothing. This is why this function is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * called "check_and_clear".
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((it->sbd_it_flags & SBD_IT_HAS_SCSI2_RESERVATION) == 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&sl->sl_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte it->sbd_it_flags &= ~SBD_IT_HAS_SCSI2_RESERVATION;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sl->sl_flags &= ~SL_LU_HAS_SCSI2_RESERVATION;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&sl->sl_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesbd_new_task(struct scsi_task *task, struct stmf_data_buf *initial_dbuf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_lu_t *sl = (sbd_lu_t *)task->task_lu->lu_provider_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_it_data_t *it;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint8_t cdb0, cdb1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_status_t st_ret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((it = task->task_lu_itl_handle) == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_enter(&sl->sl_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto for (it = sl->sl_it_list; it != NULL; it = it->sbd_it_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (it->sbd_it_session_id ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_session->ss_session_id) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&sl->sl_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_BUSY, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte it = (sbd_it_data_t *)kmem_zalloc(sizeof (*it), KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (it == NULL) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&sl->sl_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_BUSY, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte it->sbd_it_session_id = task->task_session->ss_session_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(task->task_lun_no, it->sbd_it_lun, 8);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto it->sbd_it_next = sl->sl_it_list;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sl->sl_it_list = it;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&sl->sl_lock);
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto DTRACE_PROBE1(itl__nexus__start, scsi_task *, task);
e17f3b2227c590f1d761b9ec4613cfb05982e6abtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_pgr_initialize_it(task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_register_itl_handle(task->task_lu, task->task_lun_no,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_session, it->sbd_it_session_id, it)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != STMF_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_remove_it_handle(sl, it);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_BUSY, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_lu_itl_handle = it;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (sl->sl_access_state != SBD_LU_STANDBY) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte it->sbd_it_ua_conditions = SBD_UA_POR;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else if (it->sbd_it_flags & SBD_IT_PGR_CHECK_FLAG) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_pgr_initialize_it(task);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_enter(&sl->sl_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto it->sbd_it_flags &= ~SBD_IT_PGR_CHECK_FLAG;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&sl->sl_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (task->task_mgmt_function) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_handle_task_mgmt(task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * if we're transitioning between access
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * states, return NOT READY
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (sl->sl_access_state == SBD_LU_TRANSITION_TO_STANDBY ||
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sl->sl_access_state == SBD_LU_TRANSITION_TO_ACTIVE) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_SAA_LU_NO_ACCESS_UNAVAIL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Checking ua conditions as per SAM3R14 5.3.2 specified order */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((it->sbd_it_ua_conditions) && (task->task_cdb[0] != SCMD_INQUIRY)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint32_t saa = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_enter(&sl->sl_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (it->sbd_it_ua_conditions & SBD_UA_POR) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto it->sbd_it_ua_conditions &= ~SBD_UA_POR;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto saa = STMF_SAA_POR;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&sl->sl_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (saa) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_scsilib_send_status(task, STATUS_CHECK, saa);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Reservation conflict checks */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (sl->sl_access_state != SBD_LU_STANDBY) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (SBD_PGR_RSVD(sl->sl_pgr)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (sbd_pgr_reservation_conflict(task)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_scsilib_send_status(task,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STATUS_RESERVATION_CONFLICT, 0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else if ((sl->sl_flags & SL_LU_HAS_SCSI2_RESERVATION) &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ((it->sbd_it_flags & SBD_IT_HAS_SCSI2_RESERVATION) == 0)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (!(SCSI2_CONFLICT_FREE_CMDS(task->task_cdb))) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_scsilib_send_status(task,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STATUS_RESERVATION_CONFLICT, 0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Rest of the ua conndition checks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((it->sbd_it_ua_conditions) && (task->task_cdb[0] != SCMD_INQUIRY)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t saa = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_enter(&sl->sl_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (it->sbd_it_ua_conditions & SBD_UA_CAPACITY_CHANGED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte it->sbd_it_ua_conditions &= ~SBD_UA_CAPACITY_CHANGED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((task->task_cdb[0] == SCMD_READ_CAPACITY) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((task->task_cdb[0] == SCMD_SVC_ACTION_IN_G4) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (task->task_cdb[1] ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SSVC_ACTION_READ_CAPACITY_G4))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte saa = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte saa = STMF_SAA_CAPACITY_DATA_HAS_CHANGED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else if (it->sbd_it_ua_conditions &
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto SBD_UA_MODE_PARAMETERS_CHANGED) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto it->sbd_it_ua_conditions &=
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ~SBD_UA_MODE_PARAMETERS_CHANGED;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto saa = STMF_SAA_MODE_PARAMETERS_CHANGED;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else if (it->sbd_it_ua_conditions &
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte SBD_UA_ASYMMETRIC_ACCESS_CHANGED) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte it->sbd_it_ua_conditions &=
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ~SBD_UA_ASYMMETRIC_ACCESS_CHANGED;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte saa = STMF_SAA_ASYMMETRIC_ACCESS_CHANGED;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else if (it->sbd_it_ua_conditions &
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte SBD_UA_ACCESS_STATE_TRANSITION) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte it->sbd_it_ua_conditions &=
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ~SBD_UA_ACCESS_STATE_TRANSITION;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte saa = STMF_SAA_LU_NO_ACCESS_TRANSITION;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte it->sbd_it_ua_conditions = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte saa = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&sl->sl_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (saa) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK, saa);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cdb0 = task->task_cdb[0];
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cdb1 = task->task_cdb[1];
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (sl->sl_access_state == SBD_LU_STANDBY) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (cdb0 != SCMD_INQUIRY &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cdb0 != SCMD_MODE_SENSE &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cdb0 != SCMD_MODE_SENSE_G1 &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cdb0 != SCMD_MODE_SELECT &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cdb0 != SCMD_MODE_SELECT_G1 &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cdb0 != SCMD_RESERVE &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cdb0 != SCMD_RELEASE &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cdb0 != SCMD_PERSISTENT_RESERVE_OUT &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cdb0 != SCMD_PERSISTENT_RESERVE_IN &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte cdb0 != SCMD_REQUEST_SENSE &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte !(cdb0 == SCMD_MAINTENANCE_IN &&
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (cdb1 & 0x1F) == 0x0A)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_SAA_LU_NO_ACCESS_STANDBY);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * is this a short write?
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * if so, we'll need to wait until we have the buffer
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * before proxying the command
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (cdb0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case SCMD_MODE_SELECT:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case SCMD_MODE_SELECT_G1:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case SCMD_PERSISTENT_RESERVE_OUT:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte default:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte st_ret = stmf_proxy_scsi_cmd(task,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte initial_dbuf);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (st_ret != STMF_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_scsilib_send_status(task,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STATUS_CHECK,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte STMF_SAA_LU_NO_ACCESS_UNAVAIL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb0 = task->task_cdb[0] & 0x1F;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cdb0 == SCMD_READ) || (cdb0 == SCMD_WRITE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (task->task_additional_flags & TASK_AF_PORT_LOAD_HIGH) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_QFULL, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdb0 == SCMD_READ) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_handle_read(task, initial_dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_handle_write(task, initial_dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb0 = task->task_cdb[0];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb1 = task->task_cdb[1];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdb0 == SCMD_INQUIRY) { /* Inquiry */
2f624233c43c1f4fe0d930648d6ece6fffe7aa49Nattuvetty Bhavyan sbd_handle_inquiry(task, initial_dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (cdb0 == SCMD_PERSISTENT_RESERVE_OUT) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_handle_pgr_out_cmd(task, initial_dbuf);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (cdb0 == SCMD_PERSISTENT_RESERVE_IN) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_handle_pgr_in_cmd(task, initial_dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (cdb0 == SCMD_RELEASE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (cdb1) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_scsilib_send_status(task, STATUS_CHECK,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_SAA_INVALID_FIELD_IN_CDB);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_enter(&sl->sl_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sl->sl_flags & SL_LU_HAS_SCSI2_RESERVATION) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* If not owner don't release it, just return good */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (it->sbd_it_session_id !=
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sl->sl_rs_owner_session_id) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&sl->sl_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_scsilib_send_status(task, STATUS_GOOD, 0);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sl->sl_flags &= ~SL_LU_HAS_SCSI2_RESERVATION;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto it->sbd_it_flags &= ~SBD_IT_HAS_SCSI2_RESERVATION;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&sl->sl_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_scsilib_send_status(task, STATUS_GOOD, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (cdb0 == SCMD_RESERVE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (cdb1) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_scsilib_send_status(task, STATUS_CHECK,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_SAA_INVALID_FIELD_IN_CDB);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_enter(&sl->sl_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sl->sl_flags & SL_LU_HAS_SCSI2_RESERVATION) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* If not owner, return conflict status */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (it->sbd_it_session_id !=
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sl->sl_rs_owner_session_id) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&sl->sl_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_scsilib_send_status(task,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STATUS_RESERVATION_CONFLICT, 0);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sl->sl_flags |= SL_LU_HAS_SCSI2_RESERVATION;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto it->sbd_it_flags |= SBD_IT_HAS_SCSI2_RESERVATION;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sl->sl_rs_owner_session_id = it->sbd_it_session_id;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&sl->sl_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_scsilib_send_status(task, STATUS_GOOD, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdb0 == SCMD_REQUEST_SENSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * LU provider needs to store unretrieved sense data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (e.g. after power-on/reset). For now, we'll just
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return good status with no sense.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cdb1 & ~1) || task->task_cdb[2] || task->task_cdb[3] ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_cdb[5]) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SAA_INVALID_FIELD_IN_CDB);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_GOOD, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /* Report Target Port Groups */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((cdb0 == SCMD_MAINTENANCE_IN) &&
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ((cdb1 & 0x1F) == 0x0A)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_scsilib_handle_report_tpgs(task, initial_dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (cdb0 == SCMD_START_STOP) { /* Start stop */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto task->task_cmd_xfer_length = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (task->task_cdb[4] & 0xFC) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
1b7fc709228029b3f29f1c3de6d817a476f7c583tim szeto STMF_SAA_INVALID_FIELD_IN_CDB);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (task->task_cdb[4] & 2) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_scsilib_send_status(task, STATUS_CHECK,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto STMF_SAA_INVALID_FIELD_IN_CDB);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto stmf_scsilib_send_status(task, STATUS_GOOD, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((cdb0 == SCMD_MODE_SENSE) || (cdb0 == SCMD_MODE_SENSE_G1)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint8_t *p;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto p = kmem_zalloc(512, KM_SLEEP);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_handle_mode_sense(task, initial_dbuf, p);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto kmem_free(p, 512);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((cdb0 == SCMD_MODE_SELECT) || (cdb0 == SCMD_MODE_SELECT_G1)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_handle_mode_select(task, initial_dbuf);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (cdb0 == SCMD_TEST_UNIT_READY) { /* Test unit ready */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto task->task_cmd_xfer_length = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_GOOD, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (cdb0 == SCMD_READ_CAPACITY) { /* Read Capacity */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_handle_read_capacity(task, initial_dbuf);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (cdb0 == SCMD_SVC_ACTION_IN_G4) { /* Read Capacity or read long */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (cdb1 == SSVC_ACTION_READ_CAPACITY_G4) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_handle_read_capacity(task, initial_dbuf);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * } else if (cdb1 == SSVC_ACTION_READ_LONG_G4) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * sbd_handle_read(task, initial_dbuf);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * return;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * if (cdb0 == SCMD_SVC_ACTION_OUT_G4) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * if (cdb1 == SSVC_ACTION_WRITE_LONG_G4) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * sbd_handle_write(task, initial_dbuf);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * return;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (cdb0 == SCMD_VERIFY) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto /*
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto * Something more likely needs to be done here.
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto */
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto task->task_cmd_xfer_length = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_GOOD, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cdb0 == SCMD_SYNCHRONIZE_CACHE ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cdb0 == SCMD_SYNCHRONIZE_CACHE_G4) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_handle_sync_cache(task, initial_dbuf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK, STMF_SAA_INVALID_OPCODE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesbd_dbuf_xfer_done(struct scsi_task *task, struct stmf_data_buf *dbuf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_cmd_t *scmd = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd = (sbd_cmd_t *)task->task_lu_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((scmd == NULL) || ((scmd->flags & SBD_SCSI_CMD_ACTIVE) == 0))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto switch (scmd->cmd_type) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case (SBD_CMD_SCSI_READ):
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_handle_read_xfer_completion(task, scmd, dbuf);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case (SBD_CMD_SCSI_WRITE):
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_handle_write_xfer_completion(task, scmd, dbuf, 1);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case (SBD_CMD_SMALL_READ):
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_handle_short_read_xfer_completion(task, scmd, dbuf);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto case (SBD_CMD_SMALL_WRITE):
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_handle_short_write_xfer_completion(task, dbuf);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC, "Unknown cmd type, task = %p", (void *)task);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesbd_send_status_done(struct scsi_task *task)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC,
1b7fc709228029b3f29f1c3de6d817a476f7c583tim szeto "sbd_send_status_done: this should not have been called");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesbd_task_free(struct scsi_task *task)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (task->task_lu_private) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_cmd_t *scmd = (sbd_cmd_t *)task->task_lu_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scmd->flags & SBD_SCSI_CMD_ACTIVE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC, "cmd is active, task = %p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)task);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(scmd, sizeof (sbd_cmd_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Aborts are synchronus w.r.t. I/O AND
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * All the I/O which SBD does is synchronous AND
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Everything within a task is single threaded.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * IT MEANS
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If this function is called, we are doing nothing with this task
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * inside of sbd module.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesbd_abort(struct stmf_lu *lu, int abort_cmd, void *arg, uint32_t flags)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_lu_t *sl = (sbd_lu_t *)lu->lu_provider_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scsi_task_t *task;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (abort_cmd == STMF_LU_RESET_STATE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (sbd_lu_reset_state(lu));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (abort_cmd == STMF_LU_ITL_HANDLE_REMOVED) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_check_and_clear_scsi2_reservation(sl, (sbd_it_data_t *)arg);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_remove_it_handle(sl, (sbd_it_data_t *)arg);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(abort_cmd == STMF_LU_ABORT_TASK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task = (scsi_task_t *)arg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (task->task_lu_private) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbd_cmd_t *scmd = (sbd_cmd_t *)task->task_lu_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (scmd->flags & SBD_SCSI_CMD_ACTIVE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte scmd->flags &= ~SBD_SCSI_CMD_ACTIVE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_ABORT_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_NOT_FOUND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesbd_ctl(struct stmf_lu *lu, int cmd, void *arg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_lu_t *sl = (sbd_lu_t *)lu->lu_provider_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_change_status_t st;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT((cmd == STMF_CMD_LU_ONLINE) ||
1b7fc709228029b3f29f1c3de6d817a476f7c583tim szeto (cmd == STMF_CMD_LU_OFFLINE) ||
1b7fc709228029b3f29f1c3de6d817a476f7c583tim szeto (cmd == STMF_ACK_LU_ONLINE_COMPLETE) ||
1b7fc709228029b3f29f1c3de6d817a476f7c583tim szeto (cmd == STMF_ACK_LU_OFFLINE_COMPLETE));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st.st_completion_status = STMF_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st.st_additional_info = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (cmd) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_CMD_LU_ONLINE:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sl->sl_state == STMF_STATE_ONLINE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st.st_completion_status = STMF_ALREADY;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto else if (sl->sl_state != STMF_STATE_OFFLINE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st.st_completion_status = STMF_FAILURE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (st.st_completion_status == STMF_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sl->sl_state = STMF_STATE_ONLINE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sl->sl_state_not_acked = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_ctl(STMF_CMD_LU_ONLINE_COMPLETE, lu, &st);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_CMD_LU_OFFLINE:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sl->sl_state == STMF_STATE_OFFLINE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st.st_completion_status = STMF_ALREADY;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto else if (sl->sl_state != STMF_STATE_ONLINE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte st.st_completion_status = STMF_FAILURE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (st.st_completion_status == STMF_SUCCESS) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sl->sl_flags &= ~(SL_MEDIUM_REMOVAL_PREVENTED |
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto SL_LU_HAS_SCSI2_RESERVATION);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sl->sl_state = STMF_STATE_OFFLINE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sl->sl_state_not_acked = 1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sbd_pgr_reset(sl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) stmf_ctl(STMF_CMD_LU_OFFLINE_COMPLETE, lu, &st);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_ACK_LU_ONLINE_COMPLETE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Fallthrough */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case STMF_ACK_LU_OFFLINE_COMPLETE:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sl->sl_state_not_acked = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesbd_info(uint32_t cmd, stmf_lu_t *lu, void *arg, uint8_t *buf,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto uint32_t *bufsizep)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_NOT_SUPPORTED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestmf_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesbd_lu_reset_state(stmf_lu_t *lu)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_lu_t *sl = (sbd_lu_t *)lu->lu_provider_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_enter(&sl->sl_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sl->sl_flags & SL_SAVED_WRITE_CACHE_DISABLE) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sl->sl_flags |= SL_WRITEBACK_CACHE_DISABLE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&sl->sl_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (sl->sl_access_state == SBD_LU_ACTIVE) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) sbd_wcd_set(1, sl);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sl->sl_flags &= ~SL_WRITEBACK_CACHE_DISABLE;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&sl->sl_lock);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (sl->sl_access_state == SBD_LU_ACTIVE) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) sbd_wcd_set(0, sl);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sbd_pgr_reset(sl);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_check_and_clear_scsi2_reservation(sl, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stmf_deregister_all_lu_itl_handles(lu) != STMF_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_FAILURE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (STMF_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetosbd_status_t
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetosbd_flush_data_cache(sbd_lu_t *sl, int fsync_done)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int r = 0;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto int ret;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (fsync_done)
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto goto over_fsync;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((sl->sl_data_vtype == VREG) || (sl->sl_data_vtype == VBLK)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (VOP_FSYNC(sl->sl_data_vp, FSYNC, kcred, NULL))
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (SBD_FAILURE);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szetoover_fsync:
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (((sl->sl_data_vtype == VCHR) || (sl->sl_data_vtype == VBLK)) &&
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ((sl->sl_flags & SL_NO_DATA_DKIOFLUSH) == 0)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto ret = VOP_IOCTL(sl->sl_data_vp, DKIOCFLUSHWRITECACHE, NULL,
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto FKIOCTL, kcred, &r, NULL);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((ret == ENOTTY) || (ret == ENOTSUP)) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_enter(&sl->sl_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sl->sl_flags |= SL_NO_DATA_DKIOFLUSH;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto mutex_exit(&sl->sl_lock);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto } else if (ret != 0) {
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (SBD_FAILURE);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto }
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto return (SBD_SUCCESS);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto}
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesbd_handle_sync_cache(struct scsi_task *task,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stmf_data_buf *initial_dbuf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_lu_t *sl = (sbd_lu_t *)task->task_lu->lu_provider_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t lba, laddr;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sbd_status_t sret;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int is_g4 = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int immed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto task->task_cmd_xfer_length = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Determine if this is a 10 or 16 byte CDB
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (task->task_cdb[0] == SCMD_SYNCHRONIZE_CACHE_G4)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte is_g4 = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Determine other requested parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We don't have a non-volatile cache, so don't care about SYNC_NV.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Do not support the IMMED bit.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte immed = (task->task_cdb[1] & 0x02);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (immed) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SAA_INVALID_FIELD_IN_CDB);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check to be sure we're not being asked to sync an LBA
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * that is out of range. While checking, verify reserved fields.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (is_g4) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((task->task_cdb[1] & 0xf9) || task->task_cdb[14] ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_cdb[15]) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SAA_INVALID_FIELD_IN_CDB);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lba = READ_SCSI64(&task->task_cdb[2], uint64_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = READ_SCSI32(&task->task_cdb[10], uint32_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((task->task_cdb[1] & 0xf9) || task->task_cdb[6] ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte task->task_cdb[9]) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SAA_INVALID_FIELD_IN_CDB);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lba = READ_SCSI32(&task->task_cdb[2], uint64_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = READ_SCSI16(&task->task_cdb[7], uint32_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto laddr = lba << sl->sl_data_blocksize_shift;
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto len <<= sl->sl_data_blocksize_shift;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if ((laddr + (uint64_t)len) > sl->sl_lu_size) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SAA_LBA_OUT_OF_RANGE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto sret = sbd_flush_data_cache(sl, 0);
8fe960854f0d52e2e8a80ba68e8621a5ac6a866dtim szeto if (sret != SBD_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_CHECK,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STMF_SAA_WRITE_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stmf_scsilib_send_status(task, STATUS_GOOD, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}