2002-11-22 22:55:51 +00:00
|
|
|
/*
|
|
|
|
* SCSI Disk Emulator
|
|
|
|
*
|
|
|
|
* Copyright (c) 2002 Nate Lawson.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions, and the following disclaimer,
|
|
|
|
* without modification, immediately at the beginning of the file.
|
|
|
|
* 2. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <aio.h>
|
2006-09-27 15:38:13 +00:00
|
|
|
#include <unistd.h>
|
2002-11-22 22:55:51 +00:00
|
|
|
#include <assert.h>
|
2003-10-18 04:54:08 +00:00
|
|
|
#include <sys/param.h>
|
2002-11-22 22:55:51 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <cam/cam.h>
|
|
|
|
#include <cam/cam_ccb.h>
|
|
|
|
#include <cam/scsi/scsi_all.h>
|
|
|
|
#include <cam/scsi/scsi_targetio.h>
|
|
|
|
#include "scsi_target.h"
|
|
|
|
|
|
|
|
typedef int targ_start_func(struct ccb_accept_tio *, struct ccb_scsiio *);
|
|
|
|
typedef void targ_done_func(struct ccb_accept_tio *, struct ccb_scsiio *,
|
|
|
|
io_ops);
|
2006-03-22 01:30:07 +00:00
|
|
|
#ifndef REPORT_LUNS
|
|
|
|
#define REPORT_LUNS 0xa0
|
|
|
|
#endif
|
2002-11-22 22:55:51 +00:00
|
|
|
|
|
|
|
struct targ_cdb_handlers {
|
|
|
|
u_int8_t cmd;
|
|
|
|
targ_start_func *start;
|
|
|
|
targ_done_func *done;
|
|
|
|
#define ILLEGAL_CDB 0xFF
|
|
|
|
};
|
|
|
|
|
|
|
|
static targ_start_func tcmd_inquiry;
|
|
|
|
static targ_start_func tcmd_req_sense;
|
|
|
|
static targ_start_func tcmd_rd_cap;
|
2003-10-18 04:54:08 +00:00
|
|
|
#ifdef READ_16
|
|
|
|
static targ_start_func tcmd_rd_cap16;
|
|
|
|
#endif
|
2002-11-22 22:55:51 +00:00
|
|
|
static targ_start_func tcmd_rdwr;
|
|
|
|
static targ_start_func tcmd_rdwr_decode;
|
|
|
|
static targ_done_func tcmd_rdwr_done;
|
|
|
|
static targ_start_func tcmd_null_ok;
|
|
|
|
static targ_start_func tcmd_illegal_req;
|
|
|
|
static int start_io(struct ccb_accept_tio *atio,
|
|
|
|
struct ccb_scsiio *ctio, int dir);
|
|
|
|
static int init_inquiry(u_int16_t req_flags, u_int16_t sim_flags);
|
|
|
|
static struct initiator_state *
|
|
|
|
tcmd_get_istate(u_int init_id);
|
|
|
|
static void cdb_debug(u_int8_t *cdb, const char *msg, ...);
|
|
|
|
|
|
|
|
static struct targ_cdb_handlers cdb_handlers[] = {
|
|
|
|
{ READ_10, tcmd_rdwr, tcmd_rdwr_done },
|
|
|
|
{ WRITE_10, tcmd_rdwr, tcmd_rdwr_done },
|
|
|
|
{ READ_6, tcmd_rdwr, tcmd_rdwr_done },
|
|
|
|
{ WRITE_6, tcmd_rdwr, tcmd_rdwr_done },
|
|
|
|
{ INQUIRY, tcmd_inquiry, NULL },
|
|
|
|
{ REQUEST_SENSE, tcmd_req_sense, NULL },
|
|
|
|
{ READ_CAPACITY, tcmd_rd_cap, NULL },
|
|
|
|
{ TEST_UNIT_READY, tcmd_null_ok, NULL },
|
|
|
|
{ START_STOP_UNIT, tcmd_null_ok, NULL },
|
|
|
|
{ SYNCHRONIZE_CACHE, tcmd_null_ok, NULL },
|
|
|
|
{ MODE_SENSE_6, tcmd_illegal_req, NULL },
|
|
|
|
{ MODE_SELECT_6, tcmd_illegal_req, NULL },
|
2006-03-22 01:30:07 +00:00
|
|
|
{ REPORT_LUNS, tcmd_illegal_req, NULL },
|
2003-10-18 04:54:08 +00:00
|
|
|
#ifdef READ_16
|
|
|
|
{ READ_16, tcmd_rdwr, tcmd_rdwr_done },
|
|
|
|
{ WRITE_16, tcmd_rdwr, tcmd_rdwr_done },
|
|
|
|
{ SERVICE_ACTION_IN, tcmd_rd_cap16, NULL },
|
|
|
|
#endif
|
2002-11-22 22:55:51 +00:00
|
|
|
{ ILLEGAL_CDB, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct scsi_inquiry_data inq_data;
|
|
|
|
static struct initiator_state istates[MAX_INITIATORS];
|
|
|
|
extern int debug;
|
2011-12-13 11:13:28 +00:00
|
|
|
extern off_t volume_size;
|
|
|
|
extern u_int sector_size;
|
2002-11-22 22:55:51 +00:00
|
|
|
extern size_t buf_size;
|
|
|
|
|
|
|
|
cam_status
|
|
|
|
tcmd_init(u_int16_t req_inq_flags, u_int16_t sim_inq_flags)
|
|
|
|
{
|
|
|
|
struct initiator_state *istate;
|
|
|
|
int i, ret;
|
|
|
|
|
|
|
|
/* Initialize our inquiry data */
|
|
|
|
ret = init_inquiry(req_inq_flags, sim_inq_flags);
|
|
|
|
if (ret != 0)
|
|
|
|
return (ret);
|
|
|
|
|
|
|
|
/* We start out life with a UA to indicate power-on/reset. */
|
|
|
|
for (i = 0; i < MAX_INITIATORS; i++) {
|
|
|
|
istate = tcmd_get_istate(i);
|
|
|
|
bzero(istate, sizeof(*istate));
|
|
|
|
istate->pending_ua = UA_POWER_ON;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Caller allocates CTIO, sets its init_id
|
|
|
|
return 0 if done, 1 if more processing needed
|
|
|
|
on 0, caller sets SEND_STATUS */
|
|
|
|
int
|
|
|
|
tcmd_handle(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio, io_ops event)
|
|
|
|
{
|
|
|
|
static struct targ_cdb_handlers *last_cmd;
|
|
|
|
struct initiator_state *istate;
|
|
|
|
struct atio_descr *a_descr;
|
|
|
|
int ret;
|
|
|
|
|
2003-01-16 00:24:29 +00:00
|
|
|
if (debug) {
|
|
|
|
warnx("tcmd_handle atio %p ctio %p atioflags %#x", atio, ctio,
|
|
|
|
atio->ccb_h.flags);
|
|
|
|
}
|
2002-11-22 22:55:51 +00:00
|
|
|
ret = 0;
|
|
|
|
a_descr = (struct atio_descr *)atio->ccb_h.targ_descr;
|
|
|
|
|
|
|
|
/* Do a full lookup if one-behind cache failed */
|
|
|
|
if (last_cmd == NULL || last_cmd->cmd != a_descr->cdb[0]) {
|
|
|
|
struct targ_cdb_handlers *h;
|
|
|
|
|
|
|
|
for (h = cdb_handlers; h->cmd != ILLEGAL_CDB; h++) {
|
|
|
|
if (a_descr->cdb[0] == h->cmd)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
last_cmd = h;
|
|
|
|
}
|
2006-03-25 18:18:26 +00:00
|
|
|
|
|
|
|
/* call completion and exit */
|
|
|
|
if (event != ATIO_WORK) {
|
|
|
|
if (last_cmd->done != NULL)
|
|
|
|
last_cmd->done(atio, ctio, event);
|
|
|
|
else
|
|
|
|
free_ccb((union ccb *)ctio);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2002-11-22 22:55:51 +00:00
|
|
|
if (last_cmd->cmd == ILLEGAL_CDB) {
|
|
|
|
if (event != ATIO_WORK) {
|
|
|
|
warnx("no done func for %#x???", a_descr->cdb[0]);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
/* Not found, return illegal request */
|
|
|
|
warnx("cdb %#x not handled", a_descr->cdb[0]);
|
|
|
|
tcmd_illegal_req(atio, ctio);
|
|
|
|
send_ccb((union ccb *)ctio, /*priority*/1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
istate = tcmd_get_istate(ctio->init_id);
|
|
|
|
if (istate == NULL) {
|
|
|
|
tcmd_illegal_req(atio, ctio);
|
|
|
|
send_ccb((union ccb *)ctio, /*priority*/1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (istate->pending_ca == 0 && istate->pending_ua != 0 &&
|
|
|
|
a_descr->cdb[0] != INQUIRY) {
|
|
|
|
tcmd_sense(ctio->init_id, ctio, SSD_KEY_UNIT_ATTENTION,
|
|
|
|
0x29, istate->pending_ua == UA_POWER_ON ? 1 : 2);
|
|
|
|
istate->pending_ca = CA_UNIT_ATTN;
|
|
|
|
if (debug) {
|
|
|
|
cdb_debug(a_descr->cdb, "UA active for %u: ",
|
|
|
|
atio->init_id);
|
|
|
|
}
|
|
|
|
send_ccb((union ccb *)ctio, /*priority*/1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Store current CA and UA for later */
|
|
|
|
istate->orig_ua = istate->pending_ua;
|
|
|
|
istate->orig_ca = istate->pending_ca;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* As per SAM2, any command that occurs
|
|
|
|
* after a CA is reported, clears the CA. We must
|
|
|
|
* also clear the UA condition, if any, that caused
|
|
|
|
* the CA to occur assuming the UA is not for a
|
|
|
|
* persistent condition.
|
|
|
|
*/
|
|
|
|
istate->pending_ca = CA_NONE;
|
|
|
|
if (istate->orig_ca == CA_UNIT_ATTN)
|
|
|
|
istate->pending_ua = UA_NONE;
|
|
|
|
|
|
|
|
/* If we have a valid handler, call start or completion function */
|
|
|
|
if (last_cmd->cmd != ILLEGAL_CDB) {
|
|
|
|
ret = last_cmd->start(atio, ctio);
|
|
|
|
/* XXX hack */
|
|
|
|
if (last_cmd->start != tcmd_rdwr) {
|
|
|
|
a_descr->init_req += ctio->dxfer_len;
|
|
|
|
send_ccb((union ccb *)ctio, /*priority*/1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct initiator_state *
|
|
|
|
tcmd_get_istate(u_int init_id)
|
|
|
|
{
|
|
|
|
if (init_id >= MAX_INITIATORS) {
|
|
|
|
warnx("illegal init_id %d, max %d", init_id, MAX_INITIATORS - 1);
|
|
|
|
return (NULL);
|
|
|
|
} else {
|
|
|
|
return (&istates[init_id]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tcmd_sense(u_int init_id, struct ccb_scsiio *ctio, u_int8_t flags,
|
|
|
|
u_int8_t asc, u_int8_t ascq)
|
|
|
|
{
|
|
|
|
struct initiator_state *istate;
|
Add descriptor sense support to CAM, and honor sense residuals properly in
CAM.
Desriptor sense is a new sense data format that originated in SPC-3. Among
other things, it allows for an 8-byte info field, which is necessary to
pass back block numbers larger than 4 bytes.
This change adds a number of new functions to scsi_all.c (and therefore
libcam) that abstract out most access to sense data.
This includes a bump of CAM_VERSION, because the CCB ABI has changed.
Userland programs that use the CAM pass(4) driver will need to be
recompiled.
camcontrol.c: Change uses of scsi_extract_sense() to use
scsi_extract_sense_len().
Use scsi_get_sks() instead of accessing sense key specific
data directly.
scsi_modes: Update the control mode page to the latest version (SPC-4).
scsi_cmds.c,
scsi_target.c: Change references to struct scsi_sense_data to struct
scsi_sense_data_fixed. This should be changed to allow the
user to specify fixed or descriptor sense, and then use
scsi_set_sense_data() to build the sense data.
ps3cdrom.c: Use scsi_set_sense_data() instead of setting sense data
manually.
cam_periph.c: Use scsi_extract_sense_len() instead of using
scsi_extract_sense() or accessing sense data directly.
cam_ccb.h: Bump the CAM_VERSION from 0x15 to 0x16. The change of
struct scsi_sense_data from 32 to 252 bytes changes the
size of struct ccb_scsiio, but not the size of union ccb.
So the version must be bumped to prevent structure
mis-matches.
scsi_all.h: Lots of updated SCSI sense data and other structures.
Add function prototypes for the new sense data functions.
Take out the inline implementation of scsi_extract_sense().
It is now too large to put in a header file.
Add macros to calculate whether fields are present and
filled in fixed and descriptor sense data
scsi_all.c: In scsi_op_desc(), allow the user to pass in NULL inquiry
data, and we'll assume a direct access device in that case.
Changed the SCSI RESERVED sense key name and description
to COMPLETED, as it is now defined in the spec.
Change the error recovery action for a number of read errors
to prevent lots of retries when the drive has said that the
block isn't accessible. This speeds up reconstruction of
the block by any RAID software running on top of the drive
(e.g. ZFS).
In scsi_sense_desc(), allow for invalid sense key numbers.
This allows calling this routine without checking the input
values first.
Change scsi_error_action() to use scsi_extract_sense_len(),
and handle things when invalid asc/ascq values are
encountered.
Add a new routine, scsi_desc_iterate(), that will call the
supplied function for every descriptor in descriptor format
sense data.
Add scsi_set_sense_data(), and scsi_set_sense_data_va(),
which build descriptor and fixed format sense data. They
currently default to fixed format sense data.
Add a number of scsi_get_*() functions, which get different
types of sense data fields from either fixed or descriptor
format sense data, if the data is present.
Add a number of scsi_*_sbuf() functions, which print
formatted versions of various sense data fields. These
functions work for either fixed or descriptor sense.
Add a number of scsi_sense_*_sbuf() functions, which have a
standard calling interface and print the indicated field.
These functions take descriptors only.
Add scsi_sense_desc_sbuf(), which will print a formatted
version of the given sense descriptor.
Pull out a majority of the scsi_sense_sbuf() function and
put it into scsi_sense_only_sbuf(). This allows callers
that don't use struct ccb_scsiio to easily utilize the
printing routines. Revamp that function to handle
descriptor sense and use the new sense fetching and
printing routines.
Move scsi_extract_sense() into scsi_all.c, and implement it
in terms of the new function, scsi_extract_sense_len().
The _len() version takes a length (which should be the
sense length - residual) and can indicate which fields are
present and valid in the sense data.
Add a couple of new scsi_get_*() routines to get the sense
key, asc, and ascq only.
mly.c: Rename struct scsi_sense_data to struct
scsi_sense_data_fixed.
sbp_targ.c: Use the new sense fetching routines to get sense data
instead of accessing it directly.
sbp.c: Change the firewire/SCSI sense data transformation code to
use struct scsi_sense_data_fixed instead of struct
scsi_sense_data. This should be changed later to use
scsi_set_sense_data().
ciss.c: Calculate the sense residual properly. Use
scsi_get_sense_key() to fetch the sense key.
mps_sas.c,
mpt_cam.c: Set the sense residual properly.
iir.c: Use scsi_set_sense_data() instead of building sense data by
hand.
iscsi_subr.c: Use scsi_extract_sense_len() instead of grabbing sense data
directly.
umass.c: Use scsi_set_sense_data() to build sense data.
Grab the sense key using scsi_get_sense_key().
Calculate the sense residual properly.
isp_freebsd.h: Use scsi_get_*() routines to grab asc, ascq, and sense key
values.
Calculate and set the sense residual.
MFC after: 3 days
Sponsored by: Spectra Logic Corporation
2011-10-03 20:32:55 +00:00
|
|
|
struct scsi_sense_data_fixed *sense;
|
2002-11-22 22:55:51 +00:00
|
|
|
|
|
|
|
/* Set our initiator's istate */
|
|
|
|
istate = tcmd_get_istate(init_id);
|
|
|
|
if (istate == NULL)
|
|
|
|
return;
|
|
|
|
istate->pending_ca |= CA_CMD_SENSE; /* XXX set instead of or? */
|
Add descriptor sense support to CAM, and honor sense residuals properly in
CAM.
Desriptor sense is a new sense data format that originated in SPC-3. Among
other things, it allows for an 8-byte info field, which is necessary to
pass back block numbers larger than 4 bytes.
This change adds a number of new functions to scsi_all.c (and therefore
libcam) that abstract out most access to sense data.
This includes a bump of CAM_VERSION, because the CCB ABI has changed.
Userland programs that use the CAM pass(4) driver will need to be
recompiled.
camcontrol.c: Change uses of scsi_extract_sense() to use
scsi_extract_sense_len().
Use scsi_get_sks() instead of accessing sense key specific
data directly.
scsi_modes: Update the control mode page to the latest version (SPC-4).
scsi_cmds.c,
scsi_target.c: Change references to struct scsi_sense_data to struct
scsi_sense_data_fixed. This should be changed to allow the
user to specify fixed or descriptor sense, and then use
scsi_set_sense_data() to build the sense data.
ps3cdrom.c: Use scsi_set_sense_data() instead of setting sense data
manually.
cam_periph.c: Use scsi_extract_sense_len() instead of using
scsi_extract_sense() or accessing sense data directly.
cam_ccb.h: Bump the CAM_VERSION from 0x15 to 0x16. The change of
struct scsi_sense_data from 32 to 252 bytes changes the
size of struct ccb_scsiio, but not the size of union ccb.
So the version must be bumped to prevent structure
mis-matches.
scsi_all.h: Lots of updated SCSI sense data and other structures.
Add function prototypes for the new sense data functions.
Take out the inline implementation of scsi_extract_sense().
It is now too large to put in a header file.
Add macros to calculate whether fields are present and
filled in fixed and descriptor sense data
scsi_all.c: In scsi_op_desc(), allow the user to pass in NULL inquiry
data, and we'll assume a direct access device in that case.
Changed the SCSI RESERVED sense key name and description
to COMPLETED, as it is now defined in the spec.
Change the error recovery action for a number of read errors
to prevent lots of retries when the drive has said that the
block isn't accessible. This speeds up reconstruction of
the block by any RAID software running on top of the drive
(e.g. ZFS).
In scsi_sense_desc(), allow for invalid sense key numbers.
This allows calling this routine without checking the input
values first.
Change scsi_error_action() to use scsi_extract_sense_len(),
and handle things when invalid asc/ascq values are
encountered.
Add a new routine, scsi_desc_iterate(), that will call the
supplied function for every descriptor in descriptor format
sense data.
Add scsi_set_sense_data(), and scsi_set_sense_data_va(),
which build descriptor and fixed format sense data. They
currently default to fixed format sense data.
Add a number of scsi_get_*() functions, which get different
types of sense data fields from either fixed or descriptor
format sense data, if the data is present.
Add a number of scsi_*_sbuf() functions, which print
formatted versions of various sense data fields. These
functions work for either fixed or descriptor sense.
Add a number of scsi_sense_*_sbuf() functions, which have a
standard calling interface and print the indicated field.
These functions take descriptors only.
Add scsi_sense_desc_sbuf(), which will print a formatted
version of the given sense descriptor.
Pull out a majority of the scsi_sense_sbuf() function and
put it into scsi_sense_only_sbuf(). This allows callers
that don't use struct ccb_scsiio to easily utilize the
printing routines. Revamp that function to handle
descriptor sense and use the new sense fetching and
printing routines.
Move scsi_extract_sense() into scsi_all.c, and implement it
in terms of the new function, scsi_extract_sense_len().
The _len() version takes a length (which should be the
sense length - residual) and can indicate which fields are
present and valid in the sense data.
Add a couple of new scsi_get_*() routines to get the sense
key, asc, and ascq only.
mly.c: Rename struct scsi_sense_data to struct
scsi_sense_data_fixed.
sbp_targ.c: Use the new sense fetching routines to get sense data
instead of accessing it directly.
sbp.c: Change the firewire/SCSI sense data transformation code to
use struct scsi_sense_data_fixed instead of struct
scsi_sense_data. This should be changed later to use
scsi_set_sense_data().
ciss.c: Calculate the sense residual properly. Use
scsi_get_sense_key() to fetch the sense key.
mps_sas.c,
mpt_cam.c: Set the sense residual properly.
iir.c: Use scsi_set_sense_data() instead of building sense data by
hand.
iscsi_subr.c: Use scsi_extract_sense_len() instead of grabbing sense data
directly.
umass.c: Use scsi_set_sense_data() to build sense data.
Grab the sense key using scsi_get_sense_key().
Calculate the sense residual properly.
isp_freebsd.h: Use scsi_get_*() routines to grab asc, ascq, and sense key
values.
Calculate and set the sense residual.
MFC after: 3 days
Sponsored by: Spectra Logic Corporation
2011-10-03 20:32:55 +00:00
|
|
|
sense = (struct scsi_sense_data_fixed *)&istate->sense_data;
|
2002-11-22 22:55:51 +00:00
|
|
|
bzero(sense, sizeof(*sense));
|
|
|
|
sense->error_code = SSD_CURRENT_ERROR;
|
|
|
|
sense->flags = flags;
|
|
|
|
sense->add_sense_code = asc;
|
|
|
|
sense->add_sense_code_qual = ascq;
|
|
|
|
sense->extra_len =
|
Add descriptor sense support to CAM, and honor sense residuals properly in
CAM.
Desriptor sense is a new sense data format that originated in SPC-3. Among
other things, it allows for an 8-byte info field, which is necessary to
pass back block numbers larger than 4 bytes.
This change adds a number of new functions to scsi_all.c (and therefore
libcam) that abstract out most access to sense data.
This includes a bump of CAM_VERSION, because the CCB ABI has changed.
Userland programs that use the CAM pass(4) driver will need to be
recompiled.
camcontrol.c: Change uses of scsi_extract_sense() to use
scsi_extract_sense_len().
Use scsi_get_sks() instead of accessing sense key specific
data directly.
scsi_modes: Update the control mode page to the latest version (SPC-4).
scsi_cmds.c,
scsi_target.c: Change references to struct scsi_sense_data to struct
scsi_sense_data_fixed. This should be changed to allow the
user to specify fixed or descriptor sense, and then use
scsi_set_sense_data() to build the sense data.
ps3cdrom.c: Use scsi_set_sense_data() instead of setting sense data
manually.
cam_periph.c: Use scsi_extract_sense_len() instead of using
scsi_extract_sense() or accessing sense data directly.
cam_ccb.h: Bump the CAM_VERSION from 0x15 to 0x16. The change of
struct scsi_sense_data from 32 to 252 bytes changes the
size of struct ccb_scsiio, but not the size of union ccb.
So the version must be bumped to prevent structure
mis-matches.
scsi_all.h: Lots of updated SCSI sense data and other structures.
Add function prototypes for the new sense data functions.
Take out the inline implementation of scsi_extract_sense().
It is now too large to put in a header file.
Add macros to calculate whether fields are present and
filled in fixed and descriptor sense data
scsi_all.c: In scsi_op_desc(), allow the user to pass in NULL inquiry
data, and we'll assume a direct access device in that case.
Changed the SCSI RESERVED sense key name and description
to COMPLETED, as it is now defined in the spec.
Change the error recovery action for a number of read errors
to prevent lots of retries when the drive has said that the
block isn't accessible. This speeds up reconstruction of
the block by any RAID software running on top of the drive
(e.g. ZFS).
In scsi_sense_desc(), allow for invalid sense key numbers.
This allows calling this routine without checking the input
values first.
Change scsi_error_action() to use scsi_extract_sense_len(),
and handle things when invalid asc/ascq values are
encountered.
Add a new routine, scsi_desc_iterate(), that will call the
supplied function for every descriptor in descriptor format
sense data.
Add scsi_set_sense_data(), and scsi_set_sense_data_va(),
which build descriptor and fixed format sense data. They
currently default to fixed format sense data.
Add a number of scsi_get_*() functions, which get different
types of sense data fields from either fixed or descriptor
format sense data, if the data is present.
Add a number of scsi_*_sbuf() functions, which print
formatted versions of various sense data fields. These
functions work for either fixed or descriptor sense.
Add a number of scsi_sense_*_sbuf() functions, which have a
standard calling interface and print the indicated field.
These functions take descriptors only.
Add scsi_sense_desc_sbuf(), which will print a formatted
version of the given sense descriptor.
Pull out a majority of the scsi_sense_sbuf() function and
put it into scsi_sense_only_sbuf(). This allows callers
that don't use struct ccb_scsiio to easily utilize the
printing routines. Revamp that function to handle
descriptor sense and use the new sense fetching and
printing routines.
Move scsi_extract_sense() into scsi_all.c, and implement it
in terms of the new function, scsi_extract_sense_len().
The _len() version takes a length (which should be the
sense length - residual) and can indicate which fields are
present and valid in the sense data.
Add a couple of new scsi_get_*() routines to get the sense
key, asc, and ascq only.
mly.c: Rename struct scsi_sense_data to struct
scsi_sense_data_fixed.
sbp_targ.c: Use the new sense fetching routines to get sense data
instead of accessing it directly.
sbp.c: Change the firewire/SCSI sense data transformation code to
use struct scsi_sense_data_fixed instead of struct
scsi_sense_data. This should be changed later to use
scsi_set_sense_data().
ciss.c: Calculate the sense residual properly. Use
scsi_get_sense_key() to fetch the sense key.
mps_sas.c,
mpt_cam.c: Set the sense residual properly.
iir.c: Use scsi_set_sense_data() instead of building sense data by
hand.
iscsi_subr.c: Use scsi_extract_sense_len() instead of grabbing sense data
directly.
umass.c: Use scsi_set_sense_data() to build sense data.
Grab the sense key using scsi_get_sense_key().
Calculate the sense residual properly.
isp_freebsd.h: Use scsi_get_*() routines to grab asc, ascq, and sense key
values.
Calculate and set the sense residual.
MFC after: 3 days
Sponsored by: Spectra Logic Corporation
2011-10-03 20:32:55 +00:00
|
|
|
offsetof(struct scsi_sense_data_fixed, sense_key_spec[2]) -
|
|
|
|
offsetof(struct scsi_sense_data_fixed, extra_len);
|
2002-11-22 22:55:51 +00:00
|
|
|
|
|
|
|
/* Fill out the supplied CTIO */
|
|
|
|
if (ctio != NULL) {
|
|
|
|
bcopy(sense, &ctio->sense_data, sizeof(*sense));
|
2003-09-25 05:43:26 +00:00
|
|
|
ctio->sense_len = sizeof(*sense); /* XXX */
|
2002-11-22 22:55:51 +00:00
|
|
|
ctio->ccb_h.flags &= ~CAM_DIR_MASK;
|
2004-01-09 19:27:18 +00:00
|
|
|
ctio->ccb_h.flags |= CAM_DIR_NONE | CAM_SEND_SENSE |
|
2002-11-22 22:55:51 +00:00
|
|
|
CAM_SEND_STATUS;
|
|
|
|
ctio->dxfer_len = 0;
|
|
|
|
ctio->scsi_status = SCSI_STATUS_CHECK_COND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tcmd_ua(u_int init_id, ua_types new_ua)
|
|
|
|
{
|
|
|
|
struct initiator_state *istate;
|
|
|
|
u_int start, end;
|
|
|
|
|
|
|
|
if (init_id == CAM_TARGET_WILDCARD) {
|
|
|
|
start = 0;
|
|
|
|
end = MAX_INITIATORS - 1;
|
|
|
|
} else {
|
|
|
|
start = end = init_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; start <= end; start++) {
|
|
|
|
istate = tcmd_get_istate(start);
|
|
|
|
if (istate == NULL)
|
|
|
|
break;
|
|
|
|
istate->pending_ua = new_ua;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
tcmd_inquiry(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio)
|
|
|
|
{
|
|
|
|
struct scsi_inquiry *inq;
|
|
|
|
struct atio_descr *a_descr;
|
|
|
|
struct initiator_state *istate;
|
Add descriptor sense support to CAM, and honor sense residuals properly in
CAM.
Desriptor sense is a new sense data format that originated in SPC-3. Among
other things, it allows for an 8-byte info field, which is necessary to
pass back block numbers larger than 4 bytes.
This change adds a number of new functions to scsi_all.c (and therefore
libcam) that abstract out most access to sense data.
This includes a bump of CAM_VERSION, because the CCB ABI has changed.
Userland programs that use the CAM pass(4) driver will need to be
recompiled.
camcontrol.c: Change uses of scsi_extract_sense() to use
scsi_extract_sense_len().
Use scsi_get_sks() instead of accessing sense key specific
data directly.
scsi_modes: Update the control mode page to the latest version (SPC-4).
scsi_cmds.c,
scsi_target.c: Change references to struct scsi_sense_data to struct
scsi_sense_data_fixed. This should be changed to allow the
user to specify fixed or descriptor sense, and then use
scsi_set_sense_data() to build the sense data.
ps3cdrom.c: Use scsi_set_sense_data() instead of setting sense data
manually.
cam_periph.c: Use scsi_extract_sense_len() instead of using
scsi_extract_sense() or accessing sense data directly.
cam_ccb.h: Bump the CAM_VERSION from 0x15 to 0x16. The change of
struct scsi_sense_data from 32 to 252 bytes changes the
size of struct ccb_scsiio, but not the size of union ccb.
So the version must be bumped to prevent structure
mis-matches.
scsi_all.h: Lots of updated SCSI sense data and other structures.
Add function prototypes for the new sense data functions.
Take out the inline implementation of scsi_extract_sense().
It is now too large to put in a header file.
Add macros to calculate whether fields are present and
filled in fixed and descriptor sense data
scsi_all.c: In scsi_op_desc(), allow the user to pass in NULL inquiry
data, and we'll assume a direct access device in that case.
Changed the SCSI RESERVED sense key name and description
to COMPLETED, as it is now defined in the spec.
Change the error recovery action for a number of read errors
to prevent lots of retries when the drive has said that the
block isn't accessible. This speeds up reconstruction of
the block by any RAID software running on top of the drive
(e.g. ZFS).
In scsi_sense_desc(), allow for invalid sense key numbers.
This allows calling this routine without checking the input
values first.
Change scsi_error_action() to use scsi_extract_sense_len(),
and handle things when invalid asc/ascq values are
encountered.
Add a new routine, scsi_desc_iterate(), that will call the
supplied function for every descriptor in descriptor format
sense data.
Add scsi_set_sense_data(), and scsi_set_sense_data_va(),
which build descriptor and fixed format sense data. They
currently default to fixed format sense data.
Add a number of scsi_get_*() functions, which get different
types of sense data fields from either fixed or descriptor
format sense data, if the data is present.
Add a number of scsi_*_sbuf() functions, which print
formatted versions of various sense data fields. These
functions work for either fixed or descriptor sense.
Add a number of scsi_sense_*_sbuf() functions, which have a
standard calling interface and print the indicated field.
These functions take descriptors only.
Add scsi_sense_desc_sbuf(), which will print a formatted
version of the given sense descriptor.
Pull out a majority of the scsi_sense_sbuf() function and
put it into scsi_sense_only_sbuf(). This allows callers
that don't use struct ccb_scsiio to easily utilize the
printing routines. Revamp that function to handle
descriptor sense and use the new sense fetching and
printing routines.
Move scsi_extract_sense() into scsi_all.c, and implement it
in terms of the new function, scsi_extract_sense_len().
The _len() version takes a length (which should be the
sense length - residual) and can indicate which fields are
present and valid in the sense data.
Add a couple of new scsi_get_*() routines to get the sense
key, asc, and ascq only.
mly.c: Rename struct scsi_sense_data to struct
scsi_sense_data_fixed.
sbp_targ.c: Use the new sense fetching routines to get sense data
instead of accessing it directly.
sbp.c: Change the firewire/SCSI sense data transformation code to
use struct scsi_sense_data_fixed instead of struct
scsi_sense_data. This should be changed later to use
scsi_set_sense_data().
ciss.c: Calculate the sense residual properly. Use
scsi_get_sense_key() to fetch the sense key.
mps_sas.c,
mpt_cam.c: Set the sense residual properly.
iir.c: Use scsi_set_sense_data() instead of building sense data by
hand.
iscsi_subr.c: Use scsi_extract_sense_len() instead of grabbing sense data
directly.
umass.c: Use scsi_set_sense_data() to build sense data.
Grab the sense key using scsi_get_sense_key().
Calculate the sense residual properly.
isp_freebsd.h: Use scsi_get_*() routines to grab asc, ascq, and sense key
values.
Calculate and set the sense residual.
MFC after: 3 days
Sponsored by: Spectra Logic Corporation
2011-10-03 20:32:55 +00:00
|
|
|
struct scsi_sense_data_fixed *sense;
|
2002-11-22 22:55:51 +00:00
|
|
|
|
|
|
|
a_descr = (struct atio_descr *)atio->ccb_h.targ_descr;
|
|
|
|
inq = (struct scsi_inquiry *)a_descr->cdb;
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
cdb_debug(a_descr->cdb, "INQUIRY from %u: ", atio->init_id);
|
|
|
|
/*
|
|
|
|
* Validate the command. We don't support any VPD pages, so
|
|
|
|
* complain if EVPD or CMDDT is set.
|
|
|
|
*/
|
|
|
|
istate = tcmd_get_istate(ctio->init_id);
|
Add descriptor sense support to CAM, and honor sense residuals properly in
CAM.
Desriptor sense is a new sense data format that originated in SPC-3. Among
other things, it allows for an 8-byte info field, which is necessary to
pass back block numbers larger than 4 bytes.
This change adds a number of new functions to scsi_all.c (and therefore
libcam) that abstract out most access to sense data.
This includes a bump of CAM_VERSION, because the CCB ABI has changed.
Userland programs that use the CAM pass(4) driver will need to be
recompiled.
camcontrol.c: Change uses of scsi_extract_sense() to use
scsi_extract_sense_len().
Use scsi_get_sks() instead of accessing sense key specific
data directly.
scsi_modes: Update the control mode page to the latest version (SPC-4).
scsi_cmds.c,
scsi_target.c: Change references to struct scsi_sense_data to struct
scsi_sense_data_fixed. This should be changed to allow the
user to specify fixed or descriptor sense, and then use
scsi_set_sense_data() to build the sense data.
ps3cdrom.c: Use scsi_set_sense_data() instead of setting sense data
manually.
cam_periph.c: Use scsi_extract_sense_len() instead of using
scsi_extract_sense() or accessing sense data directly.
cam_ccb.h: Bump the CAM_VERSION from 0x15 to 0x16. The change of
struct scsi_sense_data from 32 to 252 bytes changes the
size of struct ccb_scsiio, but not the size of union ccb.
So the version must be bumped to prevent structure
mis-matches.
scsi_all.h: Lots of updated SCSI sense data and other structures.
Add function prototypes for the new sense data functions.
Take out the inline implementation of scsi_extract_sense().
It is now too large to put in a header file.
Add macros to calculate whether fields are present and
filled in fixed and descriptor sense data
scsi_all.c: In scsi_op_desc(), allow the user to pass in NULL inquiry
data, and we'll assume a direct access device in that case.
Changed the SCSI RESERVED sense key name and description
to COMPLETED, as it is now defined in the spec.
Change the error recovery action for a number of read errors
to prevent lots of retries when the drive has said that the
block isn't accessible. This speeds up reconstruction of
the block by any RAID software running on top of the drive
(e.g. ZFS).
In scsi_sense_desc(), allow for invalid sense key numbers.
This allows calling this routine without checking the input
values first.
Change scsi_error_action() to use scsi_extract_sense_len(),
and handle things when invalid asc/ascq values are
encountered.
Add a new routine, scsi_desc_iterate(), that will call the
supplied function for every descriptor in descriptor format
sense data.
Add scsi_set_sense_data(), and scsi_set_sense_data_va(),
which build descriptor and fixed format sense data. They
currently default to fixed format sense data.
Add a number of scsi_get_*() functions, which get different
types of sense data fields from either fixed or descriptor
format sense data, if the data is present.
Add a number of scsi_*_sbuf() functions, which print
formatted versions of various sense data fields. These
functions work for either fixed or descriptor sense.
Add a number of scsi_sense_*_sbuf() functions, which have a
standard calling interface and print the indicated field.
These functions take descriptors only.
Add scsi_sense_desc_sbuf(), which will print a formatted
version of the given sense descriptor.
Pull out a majority of the scsi_sense_sbuf() function and
put it into scsi_sense_only_sbuf(). This allows callers
that don't use struct ccb_scsiio to easily utilize the
printing routines. Revamp that function to handle
descriptor sense and use the new sense fetching and
printing routines.
Move scsi_extract_sense() into scsi_all.c, and implement it
in terms of the new function, scsi_extract_sense_len().
The _len() version takes a length (which should be the
sense length - residual) and can indicate which fields are
present and valid in the sense data.
Add a couple of new scsi_get_*() routines to get the sense
key, asc, and ascq only.
mly.c: Rename struct scsi_sense_data to struct
scsi_sense_data_fixed.
sbp_targ.c: Use the new sense fetching routines to get sense data
instead of accessing it directly.
sbp.c: Change the firewire/SCSI sense data transformation code to
use struct scsi_sense_data_fixed instead of struct
scsi_sense_data. This should be changed later to use
scsi_set_sense_data().
ciss.c: Calculate the sense residual properly. Use
scsi_get_sense_key() to fetch the sense key.
mps_sas.c,
mpt_cam.c: Set the sense residual properly.
iir.c: Use scsi_set_sense_data() instead of building sense data by
hand.
iscsi_subr.c: Use scsi_extract_sense_len() instead of grabbing sense data
directly.
umass.c: Use scsi_set_sense_data() to build sense data.
Grab the sense key using scsi_get_sense_key().
Calculate the sense residual properly.
isp_freebsd.h: Use scsi_get_*() routines to grab asc, ascq, and sense key
values.
Calculate and set the sense residual.
MFC after: 3 days
Sponsored by: Spectra Logic Corporation
2011-10-03 20:32:55 +00:00
|
|
|
sense = (struct scsi_sense_data_fixed *)&istate->sense_data;
|
2002-11-22 22:55:51 +00:00
|
|
|
if ((inq->byte2 & SI_EVPD) != 0) {
|
|
|
|
tcmd_illegal_req(atio, ctio);
|
|
|
|
sense->sense_key_spec[0] = SSD_SCS_VALID | SSD_FIELDPTR_CMD |
|
|
|
|
SSD_BITPTR_VALID | /*bit value*/1;
|
|
|
|
sense->sense_key_spec[1] = 0;
|
|
|
|
sense->sense_key_spec[2] =
|
|
|
|
offsetof(struct scsi_inquiry, byte2);
|
|
|
|
} else if (inq->page_code != 0) {
|
|
|
|
tcmd_illegal_req(atio, ctio);
|
|
|
|
sense->sense_key_spec[0] = SSD_SCS_VALID | SSD_FIELDPTR_CMD;
|
|
|
|
sense->sense_key_spec[1] = 0;
|
|
|
|
sense->sense_key_spec[2] =
|
|
|
|
offsetof(struct scsi_inquiry, page_code);
|
|
|
|
} else {
|
|
|
|
bcopy(&inq_data, ctio->data_ptr, sizeof(inq_data));
|
|
|
|
ctio->dxfer_len = inq_data.additional_length + 4;
|
|
|
|
ctio->dxfer_len = min(ctio->dxfer_len,
|
Add the CAM Target Layer (CTL).
CTL is a disk and processor device emulation subsystem originally written
for Copan Systems under Linux starting in 2003. It has been shipping in
Copan (now SGI) products since 2005.
It was ported to FreeBSD in 2008, and thanks to an agreement between SGI
(who acquired Copan's assets in 2010) and Spectra Logic in 2010, CTL is
available under a BSD-style license. The intent behind the agreement was
that Spectra would work to get CTL into the FreeBSD tree.
Some CTL features:
- Disk and processor device emulation.
- Tagged queueing
- SCSI task attribute support (ordered, head of queue, simple tags)
- SCSI implicit command ordering support. (e.g. if a read follows a mode
select, the read will be blocked until the mode select completes.)
- Full task management support (abort, LUN reset, target reset, etc.)
- Support for multiple ports
- Support for multiple simultaneous initiators
- Support for multiple simultaneous backing stores
- Persistent reservation support
- Mode sense/select support
- Error injection support
- High Availability support (1)
- All I/O handled in-kernel, no userland context switch overhead.
(1) HA Support is just an API stub, and needs much more to be fully
functional.
ctl.c: The core of CTL. Command handlers and processing,
character driver, and HA support are here.
ctl.h: Basic function declarations and data structures.
ctl_backend.c,
ctl_backend.h: The basic CTL backend API.
ctl_backend_block.c,
ctl_backend_block.h: The block and file backend. This allows for using
a disk or a file as the backing store for a LUN.
Multiple threads are started to do I/O to the
backing device, primarily because the VFS API
requires that to get any concurrency.
ctl_backend_ramdisk.c: A "fake" ramdisk backend. It only allocates a
small amount of memory to act as a source and sink
for reads and writes from an initiator. Therefore
it cannot be used for any real data, but it can be
used to test for throughput. It can also be used
to test initiators' support for extremely large LUNs.
ctl_cmd_table.c: This is a table with all 256 possible SCSI opcodes,
and command handler functions defined for supported
opcodes.
ctl_debug.h: Debugging support.
ctl_error.c,
ctl_error.h: CTL-specific wrappers around the CAM sense building
functions.
ctl_frontend.c,
ctl_frontend.h: These files define the basic CTL frontend port API.
ctl_frontend_cam_sim.c: This is a CTL frontend port that is also a CAM SIM.
This frontend allows for using CTL without any
target-capable hardware. So any LUNs you create in
CTL are visible in CAM via this port.
ctl_frontend_internal.c,
ctl_frontend_internal.h:
This is a frontend port written for Copan to do
some system-specific tasks that required sending
commands into CTL from inside the kernel. This
isn't entirely relevant to FreeBSD in general,
but can perhaps be repurposed.
ctl_ha.h: This is a stubbed-out High Availability API. Much
more is needed for full HA support. See the
comments in the header and the description of what
is needed in the README.ctl.txt file for more
details.
ctl_io.h: This defines most of the core CTL I/O structures.
union ctl_io is conceptually very similar to CAM's
union ccb.
ctl_ioctl.h: This defines all ioctls available through the CTL
character device, and the data structures needed
for those ioctls.
ctl_mem_pool.c,
ctl_mem_pool.h: Generic memory pool implementation used by the
internal frontend.
ctl_private.h: Private data structres (e.g. CTL softc) and
function prototypes. This also includes the SCSI
vendor and product names used by CTL.
ctl_scsi_all.c,
ctl_scsi_all.h: CTL wrappers around CAM sense printing functions.
ctl_ser_table.c: Command serialization table. This defines what
happens when one type of command is followed by
another type of command.
ctl_util.c,
ctl_util.h: CTL utility functions, primarily designed to be
used from userland. See ctladm for the primary
consumer of these functions. These include CDB
building functions.
scsi_ctl.c: CAM target peripheral driver and CTL frontend port.
This is the path into CTL for commands from
target-capable hardware/SIMs.
README.ctl.txt: CTL code features, roadmap, to-do list.
usr.sbin/Makefile: Add ctladm.
ctladm/Makefile,
ctladm/ctladm.8,
ctladm/ctladm.c,
ctladm/ctladm.h,
ctladm/util.c: ctladm(8) is the CTL management utility.
It fills a role similar to camcontrol(8).
It allow configuring LUNs, issuing commands,
injecting errors and various other control
functions.
usr.bin/Makefile: Add ctlstat.
ctlstat/Makefile
ctlstat/ctlstat.8,
ctlstat/ctlstat.c: ctlstat(8) fills a role similar to iostat(8).
It reports I/O statistics for CTL.
sys/conf/files: Add CTL files.
sys/conf/NOTES: Add device ctl.
sys/cam/scsi_all.h: To conform to more recent specs, the inquiry CDB
length field is now 2 bytes long.
Add several mode page definitions for CTL.
sys/cam/scsi_all.c: Handle the new 2 byte inquiry length.
sys/dev/ciss/ciss.c,
sys/dev/ata/atapi-cam.c,
sys/cam/scsi/scsi_targ_bh.c,
scsi_target/scsi_cmds.c,
mlxcontrol/interface.c: Update for 2 byte inquiry length field.
scsi_da.h: Add versions of the format and rigid disk pages
that are in a more reasonable format for CTL.
amd64/conf/GENERIC,
i386/conf/GENERIC,
ia64/conf/GENERIC,
sparc64/conf/GENERIC: Add device ctl.
i386/conf/PAE: The CTL frontend SIM at least does not compile
cleanly on PAE.
Sponsored by: Copan Systems, SGI and Spectra Logic
MFC after: 1 month
2012-01-12 00:34:33 +00:00
|
|
|
scsi_2btoul(inq->length));
|
2002-11-22 22:55:51 +00:00
|
|
|
ctio->ccb_h.flags |= CAM_DIR_IN | CAM_SEND_STATUS;
|
|
|
|
ctio->scsi_status = SCSI_STATUS_OK;
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the inquiry response structure with the requested flags */
|
|
|
|
static int
|
|
|
|
init_inquiry(u_int16_t req_flags, u_int16_t sim_flags)
|
|
|
|
{
|
|
|
|
struct scsi_inquiry_data *inq;
|
|
|
|
|
|
|
|
inq = &inq_data;
|
|
|
|
bzero(inq, sizeof(*inq));
|
|
|
|
inq->device = T_DIRECT | (SID_QUAL_LU_CONNECTED << 5);
|
2003-09-25 05:43:26 +00:00
|
|
|
#ifdef SCSI_REV_SPC
|
2002-11-22 22:55:51 +00:00
|
|
|
inq->version = SCSI_REV_SPC; /* was 2 */
|
2003-09-25 05:43:26 +00:00
|
|
|
#else
|
|
|
|
inq->version = SCSI_REV_3; /* was 2 */
|
|
|
|
#endif
|
2002-11-22 22:55:51 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX cpi.hba_inquiry doesn't support Addr16 so we give the
|
|
|
|
* user what they want if they ask for it.
|
|
|
|
*/
|
|
|
|
if ((req_flags & SID_Addr16) != 0) {
|
|
|
|
sim_flags |= SID_Addr16;
|
|
|
|
warnx("Not sure SIM supports Addr16 but enabling it anyway");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Advertise only what the SIM can actually support */
|
|
|
|
req_flags &= sim_flags;
|
2006-09-27 15:38:13 +00:00
|
|
|
scsi_ulto2b(req_flags, &inq->spc2_flags);
|
2002-11-22 22:55:51 +00:00
|
|
|
|
|
|
|
inq->response_format = 2; /* SCSI2 Inquiry Format */
|
|
|
|
inq->additional_length = SHORT_INQUIRY_LENGTH -
|
|
|
|
offsetof(struct scsi_inquiry_data, additional_length);
|
|
|
|
bcopy("FreeBSD ", inq->vendor, SID_VENDOR_SIZE);
|
|
|
|
bcopy("Emulated Disk ", inq->product, SID_PRODUCT_SIZE);
|
|
|
|
bcopy("0.1 ", inq->revision, SID_REVISION_SIZE);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
tcmd_req_sense(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio)
|
|
|
|
{
|
|
|
|
struct scsi_request_sense *rsense;
|
Add descriptor sense support to CAM, and honor sense residuals properly in
CAM.
Desriptor sense is a new sense data format that originated in SPC-3. Among
other things, it allows for an 8-byte info field, which is necessary to
pass back block numbers larger than 4 bytes.
This change adds a number of new functions to scsi_all.c (and therefore
libcam) that abstract out most access to sense data.
This includes a bump of CAM_VERSION, because the CCB ABI has changed.
Userland programs that use the CAM pass(4) driver will need to be
recompiled.
camcontrol.c: Change uses of scsi_extract_sense() to use
scsi_extract_sense_len().
Use scsi_get_sks() instead of accessing sense key specific
data directly.
scsi_modes: Update the control mode page to the latest version (SPC-4).
scsi_cmds.c,
scsi_target.c: Change references to struct scsi_sense_data to struct
scsi_sense_data_fixed. This should be changed to allow the
user to specify fixed or descriptor sense, and then use
scsi_set_sense_data() to build the sense data.
ps3cdrom.c: Use scsi_set_sense_data() instead of setting sense data
manually.
cam_periph.c: Use scsi_extract_sense_len() instead of using
scsi_extract_sense() or accessing sense data directly.
cam_ccb.h: Bump the CAM_VERSION from 0x15 to 0x16. The change of
struct scsi_sense_data from 32 to 252 bytes changes the
size of struct ccb_scsiio, but not the size of union ccb.
So the version must be bumped to prevent structure
mis-matches.
scsi_all.h: Lots of updated SCSI sense data and other structures.
Add function prototypes for the new sense data functions.
Take out the inline implementation of scsi_extract_sense().
It is now too large to put in a header file.
Add macros to calculate whether fields are present and
filled in fixed and descriptor sense data
scsi_all.c: In scsi_op_desc(), allow the user to pass in NULL inquiry
data, and we'll assume a direct access device in that case.
Changed the SCSI RESERVED sense key name and description
to COMPLETED, as it is now defined in the spec.
Change the error recovery action for a number of read errors
to prevent lots of retries when the drive has said that the
block isn't accessible. This speeds up reconstruction of
the block by any RAID software running on top of the drive
(e.g. ZFS).
In scsi_sense_desc(), allow for invalid sense key numbers.
This allows calling this routine without checking the input
values first.
Change scsi_error_action() to use scsi_extract_sense_len(),
and handle things when invalid asc/ascq values are
encountered.
Add a new routine, scsi_desc_iterate(), that will call the
supplied function for every descriptor in descriptor format
sense data.
Add scsi_set_sense_data(), and scsi_set_sense_data_va(),
which build descriptor and fixed format sense data. They
currently default to fixed format sense data.
Add a number of scsi_get_*() functions, which get different
types of sense data fields from either fixed or descriptor
format sense data, if the data is present.
Add a number of scsi_*_sbuf() functions, which print
formatted versions of various sense data fields. These
functions work for either fixed or descriptor sense.
Add a number of scsi_sense_*_sbuf() functions, which have a
standard calling interface and print the indicated field.
These functions take descriptors only.
Add scsi_sense_desc_sbuf(), which will print a formatted
version of the given sense descriptor.
Pull out a majority of the scsi_sense_sbuf() function and
put it into scsi_sense_only_sbuf(). This allows callers
that don't use struct ccb_scsiio to easily utilize the
printing routines. Revamp that function to handle
descriptor sense and use the new sense fetching and
printing routines.
Move scsi_extract_sense() into scsi_all.c, and implement it
in terms of the new function, scsi_extract_sense_len().
The _len() version takes a length (which should be the
sense length - residual) and can indicate which fields are
present and valid in the sense data.
Add a couple of new scsi_get_*() routines to get the sense
key, asc, and ascq only.
mly.c: Rename struct scsi_sense_data to struct
scsi_sense_data_fixed.
sbp_targ.c: Use the new sense fetching routines to get sense data
instead of accessing it directly.
sbp.c: Change the firewire/SCSI sense data transformation code to
use struct scsi_sense_data_fixed instead of struct
scsi_sense_data. This should be changed later to use
scsi_set_sense_data().
ciss.c: Calculate the sense residual properly. Use
scsi_get_sense_key() to fetch the sense key.
mps_sas.c,
mpt_cam.c: Set the sense residual properly.
iir.c: Use scsi_set_sense_data() instead of building sense data by
hand.
iscsi_subr.c: Use scsi_extract_sense_len() instead of grabbing sense data
directly.
umass.c: Use scsi_set_sense_data() to build sense data.
Grab the sense key using scsi_get_sense_key().
Calculate the sense residual properly.
isp_freebsd.h: Use scsi_get_*() routines to grab asc, ascq, and sense key
values.
Calculate and set the sense residual.
MFC after: 3 days
Sponsored by: Spectra Logic Corporation
2011-10-03 20:32:55 +00:00
|
|
|
struct scsi_sense_data_fixed *sense;
|
2002-11-22 22:55:51 +00:00
|
|
|
struct initiator_state *istate;
|
|
|
|
size_t dlen;
|
|
|
|
struct atio_descr *a_descr;
|
|
|
|
|
|
|
|
a_descr = (struct atio_descr *)atio->ccb_h.targ_descr;
|
|
|
|
rsense = (struct scsi_request_sense *)a_descr->cdb;
|
|
|
|
|
|
|
|
istate = tcmd_get_istate(ctio->init_id);
|
Add descriptor sense support to CAM, and honor sense residuals properly in
CAM.
Desriptor sense is a new sense data format that originated in SPC-3. Among
other things, it allows for an 8-byte info field, which is necessary to
pass back block numbers larger than 4 bytes.
This change adds a number of new functions to scsi_all.c (and therefore
libcam) that abstract out most access to sense data.
This includes a bump of CAM_VERSION, because the CCB ABI has changed.
Userland programs that use the CAM pass(4) driver will need to be
recompiled.
camcontrol.c: Change uses of scsi_extract_sense() to use
scsi_extract_sense_len().
Use scsi_get_sks() instead of accessing sense key specific
data directly.
scsi_modes: Update the control mode page to the latest version (SPC-4).
scsi_cmds.c,
scsi_target.c: Change references to struct scsi_sense_data to struct
scsi_sense_data_fixed. This should be changed to allow the
user to specify fixed or descriptor sense, and then use
scsi_set_sense_data() to build the sense data.
ps3cdrom.c: Use scsi_set_sense_data() instead of setting sense data
manually.
cam_periph.c: Use scsi_extract_sense_len() instead of using
scsi_extract_sense() or accessing sense data directly.
cam_ccb.h: Bump the CAM_VERSION from 0x15 to 0x16. The change of
struct scsi_sense_data from 32 to 252 bytes changes the
size of struct ccb_scsiio, but not the size of union ccb.
So the version must be bumped to prevent structure
mis-matches.
scsi_all.h: Lots of updated SCSI sense data and other structures.
Add function prototypes for the new sense data functions.
Take out the inline implementation of scsi_extract_sense().
It is now too large to put in a header file.
Add macros to calculate whether fields are present and
filled in fixed and descriptor sense data
scsi_all.c: In scsi_op_desc(), allow the user to pass in NULL inquiry
data, and we'll assume a direct access device in that case.
Changed the SCSI RESERVED sense key name and description
to COMPLETED, as it is now defined in the spec.
Change the error recovery action for a number of read errors
to prevent lots of retries when the drive has said that the
block isn't accessible. This speeds up reconstruction of
the block by any RAID software running on top of the drive
(e.g. ZFS).
In scsi_sense_desc(), allow for invalid sense key numbers.
This allows calling this routine without checking the input
values first.
Change scsi_error_action() to use scsi_extract_sense_len(),
and handle things when invalid asc/ascq values are
encountered.
Add a new routine, scsi_desc_iterate(), that will call the
supplied function for every descriptor in descriptor format
sense data.
Add scsi_set_sense_data(), and scsi_set_sense_data_va(),
which build descriptor and fixed format sense data. They
currently default to fixed format sense data.
Add a number of scsi_get_*() functions, which get different
types of sense data fields from either fixed or descriptor
format sense data, if the data is present.
Add a number of scsi_*_sbuf() functions, which print
formatted versions of various sense data fields. These
functions work for either fixed or descriptor sense.
Add a number of scsi_sense_*_sbuf() functions, which have a
standard calling interface and print the indicated field.
These functions take descriptors only.
Add scsi_sense_desc_sbuf(), which will print a formatted
version of the given sense descriptor.
Pull out a majority of the scsi_sense_sbuf() function and
put it into scsi_sense_only_sbuf(). This allows callers
that don't use struct ccb_scsiio to easily utilize the
printing routines. Revamp that function to handle
descriptor sense and use the new sense fetching and
printing routines.
Move scsi_extract_sense() into scsi_all.c, and implement it
in terms of the new function, scsi_extract_sense_len().
The _len() version takes a length (which should be the
sense length - residual) and can indicate which fields are
present and valid in the sense data.
Add a couple of new scsi_get_*() routines to get the sense
key, asc, and ascq only.
mly.c: Rename struct scsi_sense_data to struct
scsi_sense_data_fixed.
sbp_targ.c: Use the new sense fetching routines to get sense data
instead of accessing it directly.
sbp.c: Change the firewire/SCSI sense data transformation code to
use struct scsi_sense_data_fixed instead of struct
scsi_sense_data. This should be changed later to use
scsi_set_sense_data().
ciss.c: Calculate the sense residual properly. Use
scsi_get_sense_key() to fetch the sense key.
mps_sas.c,
mpt_cam.c: Set the sense residual properly.
iir.c: Use scsi_set_sense_data() instead of building sense data by
hand.
iscsi_subr.c: Use scsi_extract_sense_len() instead of grabbing sense data
directly.
umass.c: Use scsi_set_sense_data() to build sense data.
Grab the sense key using scsi_get_sense_key().
Calculate the sense residual properly.
isp_freebsd.h: Use scsi_get_*() routines to grab asc, ascq, and sense key
values.
Calculate and set the sense residual.
MFC after: 3 days
Sponsored by: Spectra Logic Corporation
2011-10-03 20:32:55 +00:00
|
|
|
sense = (struct scsi_sense_data_fixed *)&istate->sense_data;
|
2002-11-22 22:55:51 +00:00
|
|
|
|
|
|
|
if (debug) {
|
|
|
|
cdb_debug(a_descr->cdb, "REQ SENSE from %u: ", atio->init_id);
|
|
|
|
warnx("Sending sense: %#x %#x %#x", sense->flags,
|
|
|
|
sense->add_sense_code, sense->add_sense_code_qual);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (istate->orig_ca == 0) {
|
|
|
|
tcmd_sense(ctio->init_id, NULL, SSD_KEY_NO_SENSE, 0, 0);
|
|
|
|
warnx("REQUEST SENSE from %u but no pending CA!",
|
|
|
|
ctio->init_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
bcopy(sense, ctio->data_ptr, sizeof(struct scsi_sense_data));
|
Add descriptor sense support to CAM, and honor sense residuals properly in
CAM.
Desriptor sense is a new sense data format that originated in SPC-3. Among
other things, it allows for an 8-byte info field, which is necessary to
pass back block numbers larger than 4 bytes.
This change adds a number of new functions to scsi_all.c (and therefore
libcam) that abstract out most access to sense data.
This includes a bump of CAM_VERSION, because the CCB ABI has changed.
Userland programs that use the CAM pass(4) driver will need to be
recompiled.
camcontrol.c: Change uses of scsi_extract_sense() to use
scsi_extract_sense_len().
Use scsi_get_sks() instead of accessing sense key specific
data directly.
scsi_modes: Update the control mode page to the latest version (SPC-4).
scsi_cmds.c,
scsi_target.c: Change references to struct scsi_sense_data to struct
scsi_sense_data_fixed. This should be changed to allow the
user to specify fixed or descriptor sense, and then use
scsi_set_sense_data() to build the sense data.
ps3cdrom.c: Use scsi_set_sense_data() instead of setting sense data
manually.
cam_periph.c: Use scsi_extract_sense_len() instead of using
scsi_extract_sense() or accessing sense data directly.
cam_ccb.h: Bump the CAM_VERSION from 0x15 to 0x16. The change of
struct scsi_sense_data from 32 to 252 bytes changes the
size of struct ccb_scsiio, but not the size of union ccb.
So the version must be bumped to prevent structure
mis-matches.
scsi_all.h: Lots of updated SCSI sense data and other structures.
Add function prototypes for the new sense data functions.
Take out the inline implementation of scsi_extract_sense().
It is now too large to put in a header file.
Add macros to calculate whether fields are present and
filled in fixed and descriptor sense data
scsi_all.c: In scsi_op_desc(), allow the user to pass in NULL inquiry
data, and we'll assume a direct access device in that case.
Changed the SCSI RESERVED sense key name and description
to COMPLETED, as it is now defined in the spec.
Change the error recovery action for a number of read errors
to prevent lots of retries when the drive has said that the
block isn't accessible. This speeds up reconstruction of
the block by any RAID software running on top of the drive
(e.g. ZFS).
In scsi_sense_desc(), allow for invalid sense key numbers.
This allows calling this routine without checking the input
values first.
Change scsi_error_action() to use scsi_extract_sense_len(),
and handle things when invalid asc/ascq values are
encountered.
Add a new routine, scsi_desc_iterate(), that will call the
supplied function for every descriptor in descriptor format
sense data.
Add scsi_set_sense_data(), and scsi_set_sense_data_va(),
which build descriptor and fixed format sense data. They
currently default to fixed format sense data.
Add a number of scsi_get_*() functions, which get different
types of sense data fields from either fixed or descriptor
format sense data, if the data is present.
Add a number of scsi_*_sbuf() functions, which print
formatted versions of various sense data fields. These
functions work for either fixed or descriptor sense.
Add a number of scsi_sense_*_sbuf() functions, which have a
standard calling interface and print the indicated field.
These functions take descriptors only.
Add scsi_sense_desc_sbuf(), which will print a formatted
version of the given sense descriptor.
Pull out a majority of the scsi_sense_sbuf() function and
put it into scsi_sense_only_sbuf(). This allows callers
that don't use struct ccb_scsiio to easily utilize the
printing routines. Revamp that function to handle
descriptor sense and use the new sense fetching and
printing routines.
Move scsi_extract_sense() into scsi_all.c, and implement it
in terms of the new function, scsi_extract_sense_len().
The _len() version takes a length (which should be the
sense length - residual) and can indicate which fields are
present and valid in the sense data.
Add a couple of new scsi_get_*() routines to get the sense
key, asc, and ascq only.
mly.c: Rename struct scsi_sense_data to struct
scsi_sense_data_fixed.
sbp_targ.c: Use the new sense fetching routines to get sense data
instead of accessing it directly.
sbp.c: Change the firewire/SCSI sense data transformation code to
use struct scsi_sense_data_fixed instead of struct
scsi_sense_data. This should be changed later to use
scsi_set_sense_data().
ciss.c: Calculate the sense residual properly. Use
scsi_get_sense_key() to fetch the sense key.
mps_sas.c,
mpt_cam.c: Set the sense residual properly.
iir.c: Use scsi_set_sense_data() instead of building sense data by
hand.
iscsi_subr.c: Use scsi_extract_sense_len() instead of grabbing sense data
directly.
umass.c: Use scsi_set_sense_data() to build sense data.
Grab the sense key using scsi_get_sense_key().
Calculate the sense residual properly.
isp_freebsd.h: Use scsi_get_*() routines to grab asc, ascq, and sense key
values.
Calculate and set the sense residual.
MFC after: 3 days
Sponsored by: Spectra Logic Corporation
2011-10-03 20:32:55 +00:00
|
|
|
dlen = offsetof(struct scsi_sense_data_fixed, extra_len) +
|
2002-11-22 22:55:51 +00:00
|
|
|
sense->extra_len + 1;
|
|
|
|
ctio->dxfer_len = min(dlen, SCSI_CDB6_LEN(rsense->length));
|
|
|
|
ctio->ccb_h.flags |= CAM_DIR_IN | CAM_SEND_STATUS;
|
|
|
|
ctio->scsi_status = SCSI_STATUS_OK;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
tcmd_rd_cap(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio)
|
|
|
|
{
|
|
|
|
struct scsi_read_capacity_data *srp;
|
|
|
|
struct atio_descr *a_descr;
|
2003-10-18 04:54:08 +00:00
|
|
|
uint32_t vsize;
|
2002-11-22 22:55:51 +00:00
|
|
|
|
|
|
|
a_descr = (struct atio_descr *)atio->ccb_h.targ_descr;
|
|
|
|
srp = (struct scsi_read_capacity_data *)ctio->data_ptr;
|
|
|
|
|
2003-10-18 04:54:08 +00:00
|
|
|
if (volume_size > 0xffffffff)
|
|
|
|
vsize = 0xffffffff;
|
|
|
|
else
|
|
|
|
vsize = (uint32_t)(volume_size - 1);
|
|
|
|
|
2002-11-22 22:55:51 +00:00
|
|
|
if (debug) {
|
|
|
|
cdb_debug(a_descr->cdb, "READ CAP from %u (%u, %u): ",
|
2003-10-18 04:54:08 +00:00
|
|
|
atio->init_id, vsize, sector_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
bzero(srp, sizeof(*srp));
|
|
|
|
scsi_ulto4b(vsize, srp->addr);
|
|
|
|
scsi_ulto4b(sector_size, srp->length);
|
|
|
|
|
|
|
|
ctio->dxfer_len = sizeof(*srp);
|
|
|
|
ctio->ccb_h.flags |= CAM_DIR_IN | CAM_SEND_STATUS;
|
|
|
|
ctio->scsi_status = SCSI_STATUS_OK;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef READ_16
|
|
|
|
static int
|
|
|
|
tcmd_rd_cap16(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio)
|
|
|
|
{
|
|
|
|
struct scsi_read_capacity_16 *scsi_cmd;
|
|
|
|
struct scsi_read_capacity_data_long *srp;
|
|
|
|
struct atio_descr *a_descr;
|
|
|
|
|
|
|
|
a_descr = (struct atio_descr *)atio->ccb_h.targ_descr;
|
|
|
|
scsi_cmd = (struct scsi_read_capacity_16 *)a_descr->cdb;
|
|
|
|
srp = (struct scsi_read_capacity_data_long *)ctio->data_ptr;
|
|
|
|
|
|
|
|
if (scsi_cmd->service_action != SRC16_SERVICE_ACTION) {
|
|
|
|
tcmd_illegal_req(atio, ctio);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (debug) {
|
|
|
|
cdb_debug(a_descr->cdb, "READ CAP16 from %u (%u, %u): ",
|
2002-11-22 22:55:51 +00:00
|
|
|
atio->init_id, volume_size - 1, sector_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
bzero(srp, sizeof(*srp));
|
2003-10-18 04:54:08 +00:00
|
|
|
scsi_u64to8b(volume_size - 1, srp->addr);
|
2002-11-22 22:55:51 +00:00
|
|
|
scsi_ulto4b(sector_size, srp->length);
|
|
|
|
|
|
|
|
ctio->dxfer_len = sizeof(*srp);
|
|
|
|
ctio->ccb_h.flags |= CAM_DIR_IN | CAM_SEND_STATUS;
|
|
|
|
ctio->scsi_status = SCSI_STATUS_OK;
|
|
|
|
return (0);
|
|
|
|
}
|
2003-10-18 04:54:08 +00:00
|
|
|
#endif
|
2002-11-22 22:55:51 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
tcmd_rdwr(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio)
|
|
|
|
{
|
|
|
|
struct atio_descr *a_descr;
|
|
|
|
struct ctio_descr *c_descr;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
a_descr = (struct atio_descr *)atio->ccb_h.targ_descr;
|
|
|
|
c_descr = (struct ctio_descr *)ctio->ccb_h.targ_descr;
|
|
|
|
|
|
|
|
/* Command needs to be decoded */
|
Add descriptor sense support to CAM, and honor sense residuals properly in
CAM.
Desriptor sense is a new sense data format that originated in SPC-3. Among
other things, it allows for an 8-byte info field, which is necessary to
pass back block numbers larger than 4 bytes.
This change adds a number of new functions to scsi_all.c (and therefore
libcam) that abstract out most access to sense data.
This includes a bump of CAM_VERSION, because the CCB ABI has changed.
Userland programs that use the CAM pass(4) driver will need to be
recompiled.
camcontrol.c: Change uses of scsi_extract_sense() to use
scsi_extract_sense_len().
Use scsi_get_sks() instead of accessing sense key specific
data directly.
scsi_modes: Update the control mode page to the latest version (SPC-4).
scsi_cmds.c,
scsi_target.c: Change references to struct scsi_sense_data to struct
scsi_sense_data_fixed. This should be changed to allow the
user to specify fixed or descriptor sense, and then use
scsi_set_sense_data() to build the sense data.
ps3cdrom.c: Use scsi_set_sense_data() instead of setting sense data
manually.
cam_periph.c: Use scsi_extract_sense_len() instead of using
scsi_extract_sense() or accessing sense data directly.
cam_ccb.h: Bump the CAM_VERSION from 0x15 to 0x16. The change of
struct scsi_sense_data from 32 to 252 bytes changes the
size of struct ccb_scsiio, but not the size of union ccb.
So the version must be bumped to prevent structure
mis-matches.
scsi_all.h: Lots of updated SCSI sense data and other structures.
Add function prototypes for the new sense data functions.
Take out the inline implementation of scsi_extract_sense().
It is now too large to put in a header file.
Add macros to calculate whether fields are present and
filled in fixed and descriptor sense data
scsi_all.c: In scsi_op_desc(), allow the user to pass in NULL inquiry
data, and we'll assume a direct access device in that case.
Changed the SCSI RESERVED sense key name and description
to COMPLETED, as it is now defined in the spec.
Change the error recovery action for a number of read errors
to prevent lots of retries when the drive has said that the
block isn't accessible. This speeds up reconstruction of
the block by any RAID software running on top of the drive
(e.g. ZFS).
In scsi_sense_desc(), allow for invalid sense key numbers.
This allows calling this routine without checking the input
values first.
Change scsi_error_action() to use scsi_extract_sense_len(),
and handle things when invalid asc/ascq values are
encountered.
Add a new routine, scsi_desc_iterate(), that will call the
supplied function for every descriptor in descriptor format
sense data.
Add scsi_set_sense_data(), and scsi_set_sense_data_va(),
which build descriptor and fixed format sense data. They
currently default to fixed format sense data.
Add a number of scsi_get_*() functions, which get different
types of sense data fields from either fixed or descriptor
format sense data, if the data is present.
Add a number of scsi_*_sbuf() functions, which print
formatted versions of various sense data fields. These
functions work for either fixed or descriptor sense.
Add a number of scsi_sense_*_sbuf() functions, which have a
standard calling interface and print the indicated field.
These functions take descriptors only.
Add scsi_sense_desc_sbuf(), which will print a formatted
version of the given sense descriptor.
Pull out a majority of the scsi_sense_sbuf() function and
put it into scsi_sense_only_sbuf(). This allows callers
that don't use struct ccb_scsiio to easily utilize the
printing routines. Revamp that function to handle
descriptor sense and use the new sense fetching and
printing routines.
Move scsi_extract_sense() into scsi_all.c, and implement it
in terms of the new function, scsi_extract_sense_len().
The _len() version takes a length (which should be the
sense length - residual) and can indicate which fields are
present and valid in the sense data.
Add a couple of new scsi_get_*() routines to get the sense
key, asc, and ascq only.
mly.c: Rename struct scsi_sense_data to struct
scsi_sense_data_fixed.
sbp_targ.c: Use the new sense fetching routines to get sense data
instead of accessing it directly.
sbp.c: Change the firewire/SCSI sense data transformation code to
use struct scsi_sense_data_fixed instead of struct
scsi_sense_data. This should be changed later to use
scsi_set_sense_data().
ciss.c: Calculate the sense residual properly. Use
scsi_get_sense_key() to fetch the sense key.
mps_sas.c,
mpt_cam.c: Set the sense residual properly.
iir.c: Use scsi_set_sense_data() instead of building sense data by
hand.
iscsi_subr.c: Use scsi_extract_sense_len() instead of grabbing sense data
directly.
umass.c: Use scsi_set_sense_data() to build sense data.
Grab the sense key using scsi_get_sense_key().
Calculate the sense residual properly.
isp_freebsd.h: Use scsi_get_*() routines to grab asc, ascq, and sense key
values.
Calculate and set the sense residual.
MFC after: 3 days
Sponsored by: Spectra Logic Corporation
2011-10-03 20:32:55 +00:00
|
|
|
if ((a_descr->flags & CAM_DIR_MASK) == CAM_DIR_BOTH) {
|
2002-11-22 22:55:51 +00:00
|
|
|
if (debug)
|
|
|
|
warnx("Calling rdwr_decode");
|
|
|
|
ret = tcmd_rdwr_decode(atio, ctio);
|
|
|
|
if (ret == 0) {
|
|
|
|
send_ccb((union ccb *)ctio, /*priority*/1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ctio->ccb_h.flags |= a_descr->flags;
|
|
|
|
|
|
|
|
/* Call appropriate work function */
|
|
|
|
if ((a_descr->flags & CAM_DIR_IN) != 0) {
|
|
|
|
ret = start_io(atio, ctio, CAM_DIR_IN);
|
|
|
|
if (debug)
|
2006-09-27 15:38:13 +00:00
|
|
|
warnx("Starting %p DIR_IN @" OFF_FMT ":%u",
|
|
|
|
a_descr, c_descr->offset, a_descr->targ_req);
|
2002-11-22 22:55:51 +00:00
|
|
|
} else {
|
|
|
|
ret = start_io(atio, ctio, CAM_DIR_OUT);
|
|
|
|
if (debug)
|
2006-09-27 15:38:13 +00:00
|
|
|
warnx("Starting %p DIR_OUT @" OFF_FMT ":%u",
|
|
|
|
a_descr, c_descr->offset, a_descr->init_req);
|
2002-11-22 22:55:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
tcmd_rdwr_decode(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio)
|
|
|
|
{
|
2003-10-18 04:54:08 +00:00
|
|
|
uint64_t blkno;
|
|
|
|
uint32_t count;
|
2002-11-22 22:55:51 +00:00
|
|
|
struct atio_descr *a_descr;
|
|
|
|
u_int8_t *cdb;
|
|
|
|
|
|
|
|
a_descr = (struct atio_descr *)atio->ccb_h.targ_descr;
|
|
|
|
cdb = a_descr->cdb;
|
|
|
|
if (debug)
|
|
|
|
cdb_debug(cdb, "R/W from %u: ", atio->init_id);
|
|
|
|
|
2003-10-18 04:54:08 +00:00
|
|
|
switch (cdb[0]) {
|
|
|
|
case READ_6:
|
|
|
|
case WRITE_6:
|
|
|
|
{
|
2002-11-22 22:55:51 +00:00
|
|
|
struct scsi_rw_6 *rw_6 = (struct scsi_rw_6 *)cdb;
|
|
|
|
blkno = scsi_3btoul(rw_6->addr);
|
|
|
|
count = rw_6->length;
|
2003-10-18 04:54:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case READ_10:
|
|
|
|
case WRITE_10:
|
|
|
|
{
|
2002-11-22 22:55:51 +00:00
|
|
|
struct scsi_rw_10 *rw_10 = (struct scsi_rw_10 *)cdb;
|
|
|
|
blkno = scsi_4btoul(rw_10->addr);
|
|
|
|
count = scsi_2btoul(rw_10->length);
|
2003-10-18 04:54:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#ifdef READ_16
|
|
|
|
case READ_16:
|
|
|
|
case WRITE_16:
|
|
|
|
{
|
|
|
|
struct scsi_rw_16 *rw_16 = (struct scsi_rw_16 *)cdb;
|
|
|
|
blkno = scsi_8btou64(rw_16->addr);
|
|
|
|
count = scsi_4btoul(rw_16->length);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
tcmd_illegal_req(atio, ctio);
|
|
|
|
return (0);
|
2002-11-22 22:55:51 +00:00
|
|
|
}
|
|
|
|
if (blkno + count > volume_size) {
|
|
|
|
warnx("Attempt to access past end of volume");
|
|
|
|
tcmd_sense(ctio->init_id, ctio,
|
|
|
|
SSD_KEY_ILLEGAL_REQUEST, 0x21, 0);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get an (overall) data length and set direction */
|
|
|
|
a_descr->base_off = ((off_t)blkno) * sector_size;
|
|
|
|
a_descr->total_len = count * sector_size;
|
|
|
|
if (a_descr->total_len == 0) {
|
|
|
|
if (debug)
|
2006-09-27 15:38:13 +00:00
|
|
|
warnx("r/w 0 blocks @ blkno " OFF_FMT, blkno);
|
2002-11-22 22:55:51 +00:00
|
|
|
tcmd_null_ok(atio, ctio);
|
|
|
|
return (0);
|
|
|
|
} else if (cdb[0] == WRITE_6 || cdb[0] == WRITE_10) {
|
|
|
|
a_descr->flags |= CAM_DIR_OUT;
|
|
|
|
if (debug)
|
2006-09-27 15:38:13 +00:00
|
|
|
warnx("write %u blocks @ blkno " OFF_FMT, count, blkno);
|
2002-11-22 22:55:51 +00:00
|
|
|
} else {
|
|
|
|
a_descr->flags |= CAM_DIR_IN;
|
|
|
|
if (debug)
|
2006-09-27 15:38:13 +00:00
|
|
|
warnx("read %u blocks @ blkno " OFF_FMT, count, blkno);
|
2002-11-22 22:55:51 +00:00
|
|
|
}
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
start_io(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio, int dir)
|
|
|
|
{
|
|
|
|
struct atio_descr *a_descr;
|
|
|
|
struct ctio_descr *c_descr;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Set up common structures */
|
|
|
|
a_descr = (struct atio_descr *)atio->ccb_h.targ_descr;
|
|
|
|
c_descr = (struct ctio_descr *)ctio->ccb_h.targ_descr;
|
|
|
|
|
|
|
|
if (dir == CAM_DIR_IN) {
|
|
|
|
c_descr->offset = a_descr->base_off + a_descr->targ_req;
|
|
|
|
ctio->dxfer_len = a_descr->total_len - a_descr->targ_req;
|
|
|
|
} else {
|
|
|
|
c_descr->offset = a_descr->base_off + a_descr->init_req;
|
|
|
|
ctio->dxfer_len = a_descr->total_len - a_descr->init_req;
|
|
|
|
}
|
|
|
|
ctio->dxfer_len = min(ctio->dxfer_len, buf_size);
|
|
|
|
assert(ctio->dxfer_len >= 0);
|
|
|
|
|
|
|
|
c_descr->aiocb.aio_offset = c_descr->offset;
|
|
|
|
c_descr->aiocb.aio_nbytes = ctio->dxfer_len;
|
|
|
|
|
|
|
|
/* If DIR_IN, start read from target, otherwise begin CTIO xfer. */
|
|
|
|
ret = 1;
|
|
|
|
if (dir == CAM_DIR_IN) {
|
2006-09-27 15:38:13 +00:00
|
|
|
if (notaio) {
|
|
|
|
if (debug)
|
2011-12-13 11:13:28 +00:00
|
|
|
warnx("read sync %lu @ block " OFF_FMT,
|
2006-09-27 15:38:13 +00:00
|
|
|
(unsigned long)
|
|
|
|
(ctio->dxfer_len / sector_size),
|
|
|
|
c_descr->offset / sector_size);
|
|
|
|
if (lseek(c_descr->aiocb.aio_fildes,
|
|
|
|
c_descr->aiocb.aio_offset, SEEK_SET) < 0) {
|
|
|
|
perror("lseek");
|
|
|
|
err(1, "lseek");
|
|
|
|
}
|
|
|
|
if (read(c_descr->aiocb.aio_fildes,
|
|
|
|
(void *)c_descr->aiocb.aio_buf,
|
|
|
|
ctio->dxfer_len) != ctio->dxfer_len) {
|
|
|
|
err(1, "read");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (debug)
|
2011-12-13 11:13:28 +00:00
|
|
|
warnx("read async %lu @ block " OFF_FMT,
|
2006-09-27 15:38:13 +00:00
|
|
|
(unsigned long)
|
|
|
|
(ctio->dxfer_len / sector_size),
|
|
|
|
c_descr->offset / sector_size);
|
|
|
|
if (aio_read(&c_descr->aiocb) < 0) {
|
|
|
|
err(1, "aio_read"); /* XXX */
|
|
|
|
}
|
|
|
|
}
|
2002-11-22 22:55:51 +00:00
|
|
|
a_descr->targ_req += ctio->dxfer_len;
|
2006-09-27 15:38:13 +00:00
|
|
|
/* if we're done, we can mark the CCB as to send status */
|
2002-11-22 22:55:51 +00:00
|
|
|
if (a_descr->targ_req == a_descr->total_len) {
|
|
|
|
ctio->ccb_h.flags |= CAM_SEND_STATUS;
|
|
|
|
ctio->scsi_status = SCSI_STATUS_OK;
|
|
|
|
ret = 0;
|
|
|
|
}
|
2006-09-27 15:38:13 +00:00
|
|
|
if (notaio)
|
|
|
|
tcmd_rdwr_done(atio, ctio, AIO_DONE);
|
2002-11-22 22:55:51 +00:00
|
|
|
} else {
|
|
|
|
if (a_descr->targ_ack == a_descr->total_len)
|
|
|
|
tcmd_null_ok(atio, ctio);
|
|
|
|
a_descr->init_req += ctio->dxfer_len;
|
|
|
|
if (a_descr->init_req == a_descr->total_len &&
|
|
|
|
ctio->dxfer_len > 0) {
|
|
|
|
/*
|
|
|
|
* If data phase done, remove atio from workq.
|
|
|
|
* The completion handler will call work_atio to
|
|
|
|
* send the final status.
|
|
|
|
*/
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
send_ccb((union ccb *)ctio, /*priority*/1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
tcmd_rdwr_done(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio,
|
|
|
|
io_ops event)
|
|
|
|
{
|
|
|
|
struct atio_descr *a_descr;
|
|
|
|
struct ctio_descr *c_descr;
|
|
|
|
|
|
|
|
a_descr = (struct atio_descr *)atio->ccb_h.targ_descr;
|
|
|
|
c_descr = (struct ctio_descr *)ctio->ccb_h.targ_descr;
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case AIO_DONE:
|
2006-09-27 15:38:13 +00:00
|
|
|
if (!notaio && aio_return(&c_descr->aiocb) < 0) {
|
2002-11-22 22:55:51 +00:00
|
|
|
warn("aio_return error");
|
|
|
|
/* XXX */
|
|
|
|
tcmd_sense(ctio->init_id, ctio,
|
|
|
|
SSD_KEY_MEDIUM_ERROR, 0, 0);
|
|
|
|
send_ccb((union ccb *)ctio, /*priority*/1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
a_descr->targ_ack += ctio->dxfer_len;
|
|
|
|
if ((a_descr->flags & CAM_DIR_IN) != 0) {
|
2006-09-27 15:38:13 +00:00
|
|
|
if (debug) {
|
|
|
|
if (notaio)
|
|
|
|
warnx("sending CTIO for AIO read");
|
|
|
|
else
|
|
|
|
warnx("sending CTIO for sync read");
|
|
|
|
}
|
2002-11-22 22:55:51 +00:00
|
|
|
a_descr->init_req += ctio->dxfer_len;
|
|
|
|
send_ccb((union ccb *)ctio, /*priority*/1);
|
|
|
|
} else {
|
|
|
|
/* Use work function to send final status */
|
|
|
|
if (a_descr->init_req == a_descr->total_len)
|
|
|
|
work_atio(atio);
|
|
|
|
if (debug)
|
|
|
|
warnx("AIO done freeing CTIO");
|
|
|
|
free_ccb((union ccb *)ctio);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CTIO_DONE:
|
2006-04-11 21:36:43 +00:00
|
|
|
switch (ctio->ccb_h.status & CAM_STATUS_MASK) {
|
|
|
|
case CAM_REQ_CMP:
|
|
|
|
break;
|
|
|
|
case CAM_REQUEUE_REQ:
|
|
|
|
warnx("requeueing request");
|
|
|
|
if ((a_descr->flags & CAM_DIR_MASK) == CAM_DIR_OUT) {
|
|
|
|
if (aio_write(&c_descr->aiocb) < 0) {
|
|
|
|
err(1, "aio_write"); /* XXX */
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (aio_read(&c_descr->aiocb) < 0) {
|
|
|
|
err(1, "aio_read"); /* XXX */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
default:
|
2002-11-22 22:55:51 +00:00
|
|
|
errx(1, "CTIO failed, status %#x", ctio->ccb_h.status);
|
|
|
|
}
|
|
|
|
a_descr->init_ack += ctio->dxfer_len;
|
|
|
|
if ((a_descr->flags & CAM_DIR_MASK) == CAM_DIR_OUT &&
|
|
|
|
ctio->dxfer_len > 0) {
|
|
|
|
a_descr->targ_req += ctio->dxfer_len;
|
2006-09-27 15:38:13 +00:00
|
|
|
if (notaio) {
|
|
|
|
if (debug)
|
2011-12-13 11:13:28 +00:00
|
|
|
warnx("write sync %lu @ block "
|
2006-09-27 15:38:13 +00:00
|
|
|
OFF_FMT, (unsigned long)
|
|
|
|
(ctio->dxfer_len / sector_size),
|
|
|
|
c_descr->offset / sector_size);
|
|
|
|
if (lseek(c_descr->aiocb.aio_fildes,
|
|
|
|
c_descr->aiocb.aio_offset, SEEK_SET) < 0) {
|
|
|
|
perror("lseek");
|
|
|
|
err(1, "lseek");
|
|
|
|
}
|
|
|
|
if (write(c_descr->aiocb.aio_fildes,
|
|
|
|
(void *) c_descr->aiocb.aio_buf,
|
|
|
|
ctio->dxfer_len) != ctio->dxfer_len) {
|
|
|
|
err(1, "write");
|
|
|
|
}
|
|
|
|
tcmd_rdwr_done(atio, ctio, AIO_DONE);
|
|
|
|
} else {
|
|
|
|
if (debug)
|
2011-12-13 11:13:28 +00:00
|
|
|
warnx("write async %lu @ block "
|
2006-09-27 15:38:13 +00:00
|
|
|
OFF_FMT, (unsigned long)
|
|
|
|
(ctio->dxfer_len / sector_size),
|
|
|
|
c_descr->offset / sector_size);
|
|
|
|
if (aio_write(&c_descr->aiocb) < 0) {
|
|
|
|
err(1, "aio_write"); /* XXX */
|
|
|
|
}
|
|
|
|
}
|
2002-11-22 22:55:51 +00:00
|
|
|
} else {
|
|
|
|
if (debug)
|
|
|
|
warnx("CTIO done freeing CTIO");
|
|
|
|
free_ccb((union ccb *)ctio);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
warnx("Unknown completion code %d", event);
|
|
|
|
abort();
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Simple ok message used by TUR, SYNC_CACHE, etc. */
|
|
|
|
static int
|
|
|
|
tcmd_null_ok(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio)
|
|
|
|
{
|
|
|
|
if (debug) {
|
|
|
|
struct atio_descr *a_descr;
|
|
|
|
|
|
|
|
a_descr = (struct atio_descr *)atio->ccb_h.targ_descr;
|
|
|
|
cdb_debug(a_descr->cdb, "Sending null ok to %u : ", atio->init_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
ctio->dxfer_len = 0;
|
|
|
|
ctio->ccb_h.flags &= ~CAM_DIR_MASK;
|
|
|
|
ctio->ccb_h.flags |= CAM_DIR_NONE | CAM_SEND_STATUS;
|
|
|
|
ctio->scsi_status = SCSI_STATUS_OK;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Simple illegal request message used by MODE SENSE, etc. */
|
|
|
|
static int
|
|
|
|
tcmd_illegal_req(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio)
|
|
|
|
{
|
|
|
|
if (debug) {
|
|
|
|
struct atio_descr *a_descr;
|
|
|
|
|
|
|
|
a_descr = (struct atio_descr *)atio->ccb_h.targ_descr;
|
|
|
|
cdb_debug(a_descr->cdb, "Sending ill req to %u: ", atio->init_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
tcmd_sense(atio->init_id, ctio, SSD_KEY_ILLEGAL_REQUEST,
|
|
|
|
/*asc*/0x24, /*ascq*/0);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cdb_debug(u_int8_t *cdb, const char *msg, ...)
|
|
|
|
{
|
|
|
|
char msg_buf[512];
|
|
|
|
int len;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, msg);
|
|
|
|
vsnprintf(msg_buf, sizeof(msg_buf), msg, ap);
|
|
|
|
va_end(ap);
|
|
|
|
len = strlen(msg_buf);
|
|
|
|
scsi_cdb_string(cdb, msg_buf + len, sizeof(msg_buf) - len);
|
|
|
|
warnx("%s", msg_buf);
|
|
|
|
}
|