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
This commit is contained in:
Kenneth D. Merry 2011-10-03 20:32:55 +00:00
parent db92413e6a
commit 1cc052e80f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=225950
24 changed files with 2648 additions and 369 deletions

View File

@ -1907,7 +1907,9 @@ readdefects(struct cam_device *device, int argc, char **argv,
int error_code, sense_key, asc, ascq;
sense = &ccb->csio.sense_data;
scsi_extract_sense(sense, &error_code, &sense_key, &asc, &ascq);
scsi_extract_sense_len(sense, ccb->csio.sense_len -
ccb->csio.sense_resid, &error_code, &sense_key, &asc,
&ascq, /*show_errors*/ 1);
/*
* According to the SCSI spec, if the disk doesn't support
@ -3798,8 +3800,9 @@ scsiformat(struct cam_device *device, int argc, char **argv,
int error_code, sense_key, asc, ascq;
sense = &ccb->csio.sense_data;
scsi_extract_sense(sense, &error_code, &sense_key,
&asc, &ascq);
scsi_extract_sense_len(sense, ccb->csio.sense_len -
ccb->csio.sense_resid, &error_code, &sense_key,
&asc, &ascq, /*show_errors*/ 1);
/*
* According to the SCSI-2 and SCSI-3 specs, a
@ -3810,15 +3813,15 @@ scsiformat(struct cam_device *device, int argc, char **argv,
*/
if ((sense_key == SSD_KEY_NOT_READY)
&& (asc == 0x04) && (ascq == 0x04)) {
if ((sense->extra_len >= 10)
&& ((sense->sense_key_spec[0] &
SSD_SCS_VALID) != 0)
uint8_t sks[3];
if ((scsi_get_sks(sense, ccb->csio.sense_len -
ccb->csio.sense_resid, sks) == 0)
&& (quiet == 0)) {
int val;
u_int64_t percentage;
val = scsi_2btoul(
&sense->sense_key_spec[1]);
val = scsi_2btoul(&sks[1]);
percentage = 10000 * val;
fprintf(stdout,

View File

@ -242,22 +242,22 @@ 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;
struct scsi_sense_data *sense;
struct scsi_sense_data_fixed *sense;
/* 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? */
sense = &istate->sense_data;
sense = (struct scsi_sense_data_fixed *)&istate->sense_data;
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 =
offsetof(struct scsi_sense_data, sense_key_spec[2]) -
offsetof(struct scsi_sense_data, extra_len);
offsetof(struct scsi_sense_data_fixed, sense_key_spec[2]) -
offsetof(struct scsi_sense_data_fixed, extra_len);
/* Fill out the supplied CTIO */
if (ctio != NULL) {
@ -298,7 +298,7 @@ tcmd_inquiry(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio)
struct scsi_inquiry *inq;
struct atio_descr *a_descr;
struct initiator_state *istate;
struct scsi_sense_data *sense;
struct scsi_sense_data_fixed *sense;
a_descr = (struct atio_descr *)atio->ccb_h.targ_descr;
inq = (struct scsi_inquiry *)a_descr->cdb;
@ -310,7 +310,7 @@ tcmd_inquiry(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio)
* complain if EVPD or CMDDT is set.
*/
istate = tcmd_get_istate(ctio->init_id);
sense = &istate->sense_data;
sense = (struct scsi_sense_data_fixed *)&istate->sense_data;
if ((inq->byte2 & SI_EVPD) != 0) {
tcmd_illegal_req(atio, ctio);
sense->sense_key_spec[0] = SSD_SCS_VALID | SSD_FIELDPTR_CMD |
@ -376,7 +376,7 @@ static int
tcmd_req_sense(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio)
{
struct scsi_request_sense *rsense;
struct scsi_sense_data *sense;
struct scsi_sense_data_fixed *sense;
struct initiator_state *istate;
size_t dlen;
struct atio_descr *a_descr;
@ -385,7 +385,7 @@ tcmd_req_sense(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio)
rsense = (struct scsi_request_sense *)a_descr->cdb;
istate = tcmd_get_istate(ctio->init_id);
sense = &istate->sense_data;
sense = (struct scsi_sense_data_fixed *)&istate->sense_data;
if (debug) {
cdb_debug(a_descr->cdb, "REQ SENSE from %u: ", atio->init_id);
@ -400,7 +400,7 @@ tcmd_req_sense(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio)
}
bcopy(sense, ctio->data_ptr, sizeof(struct scsi_sense_data));
dlen = offsetof(struct scsi_sense_data, extra_len) +
dlen = offsetof(struct scsi_sense_data_fixed, extra_len) +
sense->extra_len + 1;
ctio->dxfer_len = min(dlen, SCSI_CDB6_LEN(rsense->length));
ctio->ccb_h.flags |= CAM_DIR_IN | CAM_SEND_STATUS;
@ -482,7 +482,7 @@ tcmd_rdwr(struct ccb_accept_tio *atio, struct ccb_scsiio *ctio)
c_descr = (struct ctio_descr *)ctio->ccb_h.targ_descr;
/* Command needs to be decoded */
if ((a_descr->flags & CAM_DIR_MASK) == CAM_DIR_RESV) {
if ((a_descr->flags & CAM_DIR_MASK) == CAM_DIR_BOTH) {
if (debug)
warnx("Calling rdwr_decode");
ret = tcmd_rdwr_decode(atio, ctio);

View File

@ -651,7 +651,7 @@ work_atio(struct ccb_accept_tio *atio)
* receiving this ATIO.
*/
if (atio->sense_len != 0) {
struct scsi_sense_data *sense;
struct scsi_sense_data_fixed *sense;
if (debug) {
warnx("ATIO with %u bytes sense received",
@ -825,9 +825,9 @@ work_inot(struct ccb_immed_notify *inot)
/* If there is sense data, use it */
if (sense != 0) {
struct scsi_sense_data *sense;
struct scsi_sense_data_fixed *sense;
sense = &inot->sense_data;
sense = (struct scsi_sense_data_fixed *)&inot->sense_data;
tcmd_sense(inot->initiator_id, NULL, sense->flags,
sense->add_sense_code, sense->add_sense_code_qual);
if (debug)

View File

@ -50,19 +50,32 @@
# ALL DEVICE TYPES
0x0a "Control Mode Page" {
{Reserved} *t7
{TST} t3
{TMF_ONLY} t1
{DPICZ} t1
{D_SENSE} t1
{GLTSD} t1
{RLEC} t1
{Queue Algorithm Modifier} t4
{Reserved} *t2
{QErr} t1
{NUAR} t1
{QErr} t2
{DQue} t1
{EECA} t1
{Reserved} *t4
{RAC} t1
{UA_INTLCK_CTRL} t2
{SWP} t1
{RAENP} t1
{UAAENP} t1
{EAENP} t1
{Reserved} *i1
{ATO} t1
{TAS} t1
{ATMPE} t1
{RWWP} t1
{Reserved} *t1
{Autoload Mode} t3
{Ready AEN Holdoff Period} i2
{Busy Timeout Period} i2
{Extended Self-Test Completion Time} i2
}
0x02 "Disconnect-Reconnect Page" {

View File

@ -539,7 +539,7 @@ struct ccb_dev_match {
/*
* Definitions for the path inquiry CCB fields.
*/
#define CAM_VERSION 0x15 /* Hex value for current version */
#define CAM_VERSION 0x16 /* Hex value for current version */
typedef enum {
PI_MDP_ABLE = 0x80, /* Supports MDP message */

View File

@ -1085,7 +1085,6 @@ camperiphsensedone(struct cam_periph *periph, union ccb *done_ccb)
union ccb *saved_ccb = (union ccb *)done_ccb->ccb_h.saved_ccb_ptr;
cam_status status;
int frozen = 0;
u_int sense_key;
int depth = done_ccb->ccb_h.recovery_depth;
status = done_ccb->ccb_h.status;
@ -1101,22 +1100,25 @@ camperiphsensedone(struct cam_periph *periph, union ccb *done_ccb)
switch (status) {
case CAM_REQ_CMP:
{
int error_code, sense_key, asc, ascq;
scsi_extract_sense_len(&saved_ccb->csio.sense_data,
saved_ccb->csio.sense_len -
saved_ccb->csio.sense_resid,
&error_code, &sense_key, &asc, &ascq,
/*show_errors*/ 1);
/*
* If we manually retrieved sense into a CCB and got
* something other than "NO SENSE" send the updated CCB
* back to the client via xpt_done() to be processed via
* the error recovery code again.
*/
sense_key = saved_ccb->csio.sense_data.flags;
sense_key &= SSD_KEY;
if (sense_key != SSD_KEY_NO_SENSE) {
saved_ccb->ccb_h.status |=
CAM_AUTOSNS_VALID;
if ((sense_key != -1)
&& (sense_key != SSD_KEY_NO_SENSE)) {
saved_ccb->ccb_h.status |= CAM_AUTOSNS_VALID;
} else {
saved_ccb->ccb_h.status &=
~CAM_STATUS_MASK;
saved_ccb->ccb_h.status |=
CAM_AUTOSENSE_FAIL;
saved_ccb->ccb_h.status &= ~CAM_STATUS_MASK;
saved_ccb->ccb_h.status |= CAM_AUTOSENSE_FAIL;
}
saved_ccb->csio.sense_resid = done_ccb->csio.resid;
bcopy(saved_ccb, done_ccb, sizeof(union ccb));
@ -1198,12 +1200,15 @@ camperiphdone(struct cam_periph *periph, union ccb *done_ccb)
if (status & CAM_AUTOSNS_VALID) {
struct ccb_getdev cgd;
struct scsi_sense_data *sense;
int error_code, sense_key, asc, ascq;
int error_code, sense_key, asc, ascq, sense_len;
scsi_sense_action err_action;
sense = &done_ccb->csio.sense_data;
scsi_extract_sense(sense, &error_code,
&sense_key, &asc, &ascq);
sense_len = done_ccb->csio.sense_len -
done_ccb->csio.sense_resid;
scsi_extract_sense_len(sense, sense_len, &error_code,
&sense_key, &asc, &ascq,
/*show_errors*/ 1);
/*
* Grab the inquiry data for this device.
*/

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1691,9 +1691,10 @@ cddone(struct cam_periph *periph, union ccb *done_ccb)
if (have_sense) {
sense = &csio->sense_data;
scsi_extract_sense(sense, &error_code,
&sense_key,
&asc, &ascq);
scsi_extract_sense_len(sense,
csio->sense_len - csio->sense_resid,
&error_code, &sense_key, &asc,
&ascq, /*show_errors*/ 1);
}
/*
* Attach to anything that claims to be a
@ -3126,8 +3127,9 @@ cderror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
&& ((ccb->ccb_h.flags & CAM_SENSE_PTR) == 0)) {
int sense_key, error_code, asc, ascq;
scsi_extract_sense(&ccb->csio.sense_data,
&error_code, &sense_key, &asc, &ascq);
scsi_extract_sense_len(&ccb->csio.sense_data,
ccb->csio.sense_len - ccb->csio.sense_resid, &error_code,
&sense_key, &asc, &ascq, /*show_errors*/ 1);
if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
error = cd6byteworkaround(ccb);
}

View File

@ -753,10 +753,10 @@ daclose(struct disk *dp)
int asc, ascq;
int sense_key, error_code;
scsi_extract_sense(&ccb->csio.sense_data,
&error_code,
&sense_key,
&asc, &ascq);
scsi_extract_sense_len(&ccb->csio.sense_data,
ccb->csio.sense_len - ccb->csio.sense_resid,
&error_code, &sense_key, &asc, &ascq,
/*show_errors*/ 1);
if (sense_key != SSD_KEY_ILLEGAL_REQUEST)
scsi_sense_print(&ccb->csio);
} else {
@ -916,10 +916,10 @@ dadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t leng
int asc, ascq;
int sense_key, error_code;
scsi_extract_sense(&csio.sense_data,
&error_code,
&sense_key,
&asc, &ascq);
scsi_extract_sense_len(&csio.sense_data,
csio.sense_len - csio.sense_resid,
&error_code, &sense_key, &asc, &ascq,
/*show_errors*/ 1);
if (sense_key != SSD_KEY_ILLEGAL_REQUEST)
scsi_sense_print(&csio);
} else {
@ -1802,9 +1802,10 @@ dadone(struct cam_periph *periph, union ccb *done_ccb)
if (have_sense) {
sense = &csio->sense_data;
scsi_extract_sense(sense, &error_code,
&sense_key,
&asc, &ascq);
scsi_extract_sense_len(sense,
csio->sense_len - csio->sense_resid,
&error_code, &sense_key, &asc,
&ascq, /*show_errors*/ 1);
}
/*
* Attach to anything that claims to be a

View File

@ -2577,12 +2577,16 @@ scsi_low_setup_done(slp, cb)
#ifdef SCSI_LOW_DEBUG
if (scsi_low_debug & SCSI_LOW_DEBUG_SENSE)
{
printf("SENSE: [%x][%x][%x][%x][%x]\n",
(u_int) cb->ccb_sense.error_code,
(u_int) cb->ccb_sense.segment,
(u_int) cb->ccb_sense.flags,
(u_int) cb->ccb_sense.add_sense_code,
(u_int) cb->ccb_sense.add_sense_code_qual);
int error_code, sense_key, asc, ascq;
scsi_extract_sense(&cb->ccb_sense,
&error_code,
&sense_key,
&asc,
&ascq);
printf("SENSE: [%x][%x][%x][%x]\n",
error_code, sense_key, asc,
ascq);
}
#endif /* SCSI_LOW_DEBUG */
}

View File

@ -235,10 +235,10 @@ struct sa_softc {
*/
struct {
struct scsi_sense_data _last_io_sense;
u_int32_t _last_io_resid;
u_int64_t _last_io_resid;
u_int8_t _last_io_cdb[CAM_MAX_CDBLEN];
struct scsi_sense_data _last_ctl_sense;
u_int32_t _last_ctl_resid;
u_int64_t _last_ctl_resid;
u_int8_t _last_ctl_cdb[CAM_MAX_CDBLEN];
#define last_io_sense errinfo._last_io_sense
#define last_io_resid errinfo._last_io_resid
@ -849,8 +849,10 @@ saioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, struct thread *td)
*/
if ((periph->flags & CAM_PERIPH_LOCKED) == 0) {
error = cam_periph_hold(periph, PRIBIO|PCATCH);
if (error != 0)
if (error != 0) {
cam_periph_unlock(periph);
return (error);
}
didlockperiph = 1;
}
break;
@ -884,12 +886,15 @@ saioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flag, struct thread *td)
* access to data structures.
*/
error = cam_periph_hold(periph, PRIBIO|PCATCH);
if (error != 0)
if (error != 0) {
cam_periph_unlock(periph);
return (error);
}
didlockperiph = 1;
break;
default:
cam_periph_unlock(periph);
return (EINVAL);
}
}
@ -2322,17 +2327,28 @@ saerror(union ccb *ccb, u_int32_t cflgs, u_int32_t sflgs)
struct sa_softc *softc;
struct ccb_scsiio *csio;
struct scsi_sense_data *sense;
u_int32_t resid = 0;
int32_t info = 0;
uint64_t resid = 0;
int64_t info = 0;
cam_status status;
int error_code, sense_key, asc, ascq, error, aqvalid;
int error_code, sense_key, asc, ascq, error, aqvalid, stream_valid;
int sense_len;
uint8_t stream_bits;
periph = xpt_path_periph(ccb->ccb_h.path);
softc = (struct sa_softc *)periph->softc;
csio = &ccb->csio;
sense = &csio->sense_data;
scsi_extract_sense(sense, &error_code, &sense_key, &asc, &ascq);
aqvalid = sense->extra_len >= 6;
sense_len = csio->sense_len - csio->sense_resid;
scsi_extract_sense_len(sense, sense_len, &error_code, &sense_key,
&asc, &ascq, /*show_errors*/ 1);
if (asc != -1 && ascq != -1)
aqvalid = 1;
else
aqvalid = 0;
if (scsi_get_stream_info(sense, sense_len, NULL, &stream_bits) == 0)
stream_valid = 1;
else
stream_valid = 0;
error = 0;
status = csio->ccb_h.status & CAM_STATUS_MASK;
@ -2343,9 +2359,8 @@ saerror(union ccb *ccb, u_int32_t cflgs, u_int32_t sflgs)
* unit.
*/
if (status == CAM_SCSI_STATUS_ERROR) {
if ((sense->error_code & SSD_ERRCODE_VALID) != 0) {
info = (int32_t) scsi_4btoul(sense->info);
resid = info;
if (scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &resid,
&info) == 0) {
if ((softc->flags & SA_FLAG_FIXED) != 0)
resid *= softc->media_blksize;
} else {
@ -2372,10 +2387,11 @@ saerror(union ccb *ccb, u_int32_t cflgs, u_int32_t sflgs)
softc->last_resid_was_io = 0;
}
CAM_DEBUG(periph->path, CAM_DEBUG_INFO, ("CDB[0]=0x%x Key 0x%x "
"ASC/ASCQ 0x%x/0x%x CAM STATUS 0x%x flags 0x%x resid %d "
"ASC/ASCQ 0x%x/0x%x CAM STATUS 0x%x flags 0x%x resid %jd "
"dxfer_len %d\n", csio->cdb_io.cdb_bytes[0] & 0xff,
sense_key, asc, ascq, status,
sense->flags & ~SSD_KEY_RESERVED, resid, csio->dxfer_len));
(stream_valid) ? stream_bits : 0, (intmax_t)resid,
csio->dxfer_len));
} else {
CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
("Cam Status 0x%x\n", status));
@ -2431,7 +2447,7 @@ saerror(union ccb *ccb, u_int32_t cflgs, u_int32_t sflgs)
if (sense_key == SSD_KEY_VOLUME_OVERFLOW) {
csio->resid = resid;
error = ENOSPC;
} else if (sense->flags & SSD_EOM) {
} else if ((stream_valid != 0) && (stream_bits & SSD_EOM)) {
softc->flags |= SA_FLAG_EOM_PENDING;
/*
* Grotesque as it seems, the few times
@ -2450,7 +2466,7 @@ saerror(union ccb *ccb, u_int32_t cflgs, u_int32_t sflgs)
} else {
error = EIO;
}
} else if (sense->flags & SSD_FILEMARK) {
} else if ((stream_valid != 0) && (stream_bits & SSD_FILEMARK)){
if (softc->flags & SA_FLAG_FIXED) {
error = -1;
softc->flags |= SA_FLAG_EOF_PENDING;
@ -2470,7 +2486,7 @@ saerror(union ccb *ccb, u_int32_t cflgs, u_int32_t sflgs)
/*
* Incorrect Length usually applies to read, but can apply to writes.
*/
if (error == 0 && (sense->flags & SSD_ILI)) {
if (error == 0 && (stream_valid != 0) && (stream_bits & SSD_ILI)) {
if (info < 0) {
xpt_print(csio->ccb_h.path, toobig,
csio->dxfer_len - info);
@ -2485,7 +2501,8 @@ saerror(union ccb *ccb, u_int32_t cflgs, u_int32_t sflgs)
* Bump the block number if we hadn't seen a filemark.
* Do this independent of errors (we've moved anyway).
*/
if ((sense->flags & SSD_FILEMARK) == 0) {
if ((stream_valid == 0) ||
(stream_bits & SSD_FILEMARK) == 0) {
if (softc->blkno != (daddr_t) -1) {
softc->blkno++;
csio->ccb_h.ccb_pflags |=

View File

@ -112,20 +112,20 @@ static struct scsi_inquiry_data no_lun_inq_data =
/* version */2, /* format version */2
};
static struct scsi_sense_data no_lun_sense_data =
static struct scsi_sense_data_fixed no_lun_sense_data =
{
SSD_CURRENT_ERROR|SSD_ERRCODE_VALID,
0,
SSD_KEY_NOT_READY,
{ 0, 0, 0, 0 },
/*extra_len*/offsetof(struct scsi_sense_data, fru)
- offsetof(struct scsi_sense_data, extra_len),
/*extra_len*/offsetof(struct scsi_sense_data_fixed, fru)
- offsetof(struct scsi_sense_data_fixed, extra_len),
{ 0, 0, 0, 0 },
/* Logical Unit Not Supported */
/*ASC*/0x25, /*ASCQ*/0
};
static const int request_sense_size = offsetof(struct scsi_sense_data, fru);
static const int request_sense_size = offsetof(struct scsi_sense_data_fixed, fru);
static periph_init_t targbhinit;
static void targbhasync(void *callback_arg, u_int32_t code,
@ -587,7 +587,9 @@ targbhdone(struct cam_periph *periph, union ccb *done_ccb)
* This needs to have other than a
* no_lun_sense_data response.
*/
atio->sense_data = no_lun_sense_data;
bcopy(&no_lun_sense_data, &atio->sense_data,
min(sizeof(no_lun_sense_data),
sizeof(atio->sense_data)));
atio->sense_len = sizeof(no_lun_sense_data);
descr->data_resid = 0;
descr->data_increment = 0;
@ -630,7 +632,9 @@ targbhdone(struct cam_periph *periph, union ccb *done_ccb)
/* Direction is always relative to the initator */
atio->ccb_h.flags &= ~CAM_DIR_MASK;
atio->ccb_h.flags |= CAM_DIR_NONE;
atio->sense_data = no_lun_sense_data;
bcopy(&no_lun_sense_data, &atio->sense_data,
min(sizeof(no_lun_sense_data),
sizeof(atio->sense_data)));
atio->sense_len = sizeof (no_lun_sense_data);
descr->data_resid = 0;
descr->data_increment = 0;

View File

@ -3249,13 +3249,17 @@ ciss_cam_complete(struct ciss_request *cr)
ce->sense_length, ce->residual_count);
bzero(&csio->sense_data, SSD_FULL_SIZE);
bcopy(&ce->sense_info[0], &csio->sense_data, ce->sense_length);
csio->sense_len = ce->sense_length;
if (csio->sense_len > ce->sense_length)
csio->sense_resid = csio->sense_len - ce->sense_length;
else
csio->sense_resid = 0;
csio->resid = ce->residual_count;
csio->ccb_h.status |= CAM_SCSI_STATUS_ERROR | CAM_AUTOSNS_VALID;
#ifdef CISS_DEBUG
{
struct scsi_sense_data *sns = (struct scsi_sense_data *)&ce->sense_info[0];
debug(0, "sense key %x", sns->flags & SSD_KEY);
debug(0, "sense key %x", scsi_get_sense_key(sns, csio->sense_len -
csio->sense_resid, /*show_errors*/ 1));
}
#endif
break;

View File

@ -1515,10 +1515,10 @@ static void
sbp_scsi_status(struct sbp_status *sbp_status, struct sbp_ocb *ocb)
{
struct sbp_cmd_status *sbp_cmd_status;
struct scsi_sense_data *sense;
struct scsi_sense_data_fixed *sense;
sbp_cmd_status = (struct sbp_cmd_status *)sbp_status->data;
sense = &ocb->ccb->csio.sense_data;
sense = (struct scsi_sense_data_fixed *)&ocb->ccb->csio.sense_data;
SBP_DEBUG(0)
sbp_print_scsi_cmd(ocb);

View File

@ -41,6 +41,7 @@
#include <sys/types.h>
#include <sys/conf.h>
#include <sys/malloc.h>
#include <sys/endian.h>
#if __FreeBSD_version < 500000
#include <sys/devicestat.h>
#endif
@ -632,6 +633,12 @@ sbp_targ_send_status(struct orb_info *orbi, union ccb *ccb)
{
struct sbp_cmd_status *sbp_cmd_status;
struct scsi_sense_data *sense;
int error_code, sense_key, asc, ascq;
uint8_t stream_bits;
uint8_t sks[3];
uint64_t info;
int64_t sinfo;
int sense_len;
if (debug)
printf("%s: STATUS %d\n", __func__,
@ -659,35 +666,75 @@ sbp_targ_send_status(struct orb_info *orbi, union ccb *ccb)
#endif
#endif
if ((sense->error_code & SSD_ERRCODE) == SSD_CURRENT_ERROR)
sense_len = ccb->csio.sense_len - ccb->csio.sense_resid;
scsi_extract_sense_len(sense, sense_len, &error_code,
&sense_key, &asc, &ascq, /*show_errors*/ 0);
switch (error_code) {
case SSD_CURRENT_ERROR:
case SSD_DESC_CURRENT_ERROR:
sbp_cmd_status->sfmt = SBP_SFMT_CURR;
else
break;
default:
sbp_cmd_status->sfmt = SBP_SFMT_DEFER;
break;
}
sbp_cmd_status->valid = (sense->error_code & SSD_ERRCODE_VALID)
? 1 : 0;
sbp_cmd_status->s_key = sense->flags & SSD_KEY;
sbp_cmd_status->mark = (sense->flags & SSD_FILEMARK)? 1 : 0;
sbp_cmd_status->eom = (sense->flags & SSD_EOM) ? 1 : 0;
sbp_cmd_status->ill_len = (sense->flags & SSD_ILI) ? 1 : 0;
if (scsi_get_sense_info(sense, sense_len, SSD_DESC_INFO, &info,
&sinfo) == 0) {
uint32_t info_trunc;
sbp_cmd_status->valid = 1;
info_trunc = info;
bcopy(&sense->info[0], &sbp_cmd_status->info, 4);
sbp_cmd_status->info = htobe32(info_trunc);
} else {
sbp_cmd_status->valid = 0;
}
if (sense->extra_len <= 6)
/* add_sense_code(_qual), info, cmd_spec_info */
sbp_status->len = 4;
else
/* fru, sense_key_spec */
sbp_cmd_status->s_key = sense_key;
if (scsi_get_stream_info(sense, sense_len, NULL,
&stream_bits) == 0) {
sbp_cmd_status->mark =
(stream_bits & SSD_FILEMARK) ? 1 : 0;
sbp_cmd_status->eom =
(stream_bits & SSD_EOM) ? 1 : 0;
sbp_cmd_status->ill_len =
(stream_bits & SSD_ILI) ? 1 : 0;
} else {
sbp_cmd_status->mark = 0;
sbp_cmd_status->eom = 0;
sbp_cmd_status->ill_len = 0;
}
/* add_sense_code(_qual), info, cmd_spec_info */
sbp_status->len = 4;
if (scsi_get_sense_info(sense, sense_len, SSD_DESC_COMMAND,
&info, &sinfo) == 0) {
uint32_t cmdspec_trunc;
cmdspec_trunc = info;
sbp_cmd_status->cdb = htobe32(cmdspec_trunc);
}
sbp_cmd_status->s_code = asc;
sbp_cmd_status->s_qlfr = ascq;
if (scsi_get_sense_info(sense, sense_len, SSD_DESC_FRU, &info,
&sinfo) == 0) {
sbp_cmd_status->fru = (uint8_t)info;
sbp_status->len = 5;
bcopy(&sense->cmd_spec_info[0], &sbp_cmd_status->cdb, 4);
} else {
sbp_cmd_status->fru = 0;
}
sbp_cmd_status->s_code = sense->add_sense_code;
sbp_cmd_status->s_qlfr = sense->add_sense_code_qual;
sbp_cmd_status->fru = sense->fru;
bcopy(&sense->sense_key_spec[0],
&sbp_cmd_status->s_keydep[0], 3);
if (scsi_get_sks(sense, sense_len, sks) == 0) {
bcopy(sks, &sbp_cmd_status->s_keydep[0], sizeof(sks));
sbp_status->len = 5;
}
break;
}

View File

@ -1839,13 +1839,20 @@ gdt_sync_event(struct gdt_softc *gdt, int service,
} else {
/* error */
if (gccb->gc_service == GDT_CACHESERVICE) {
struct scsi_sense_data *sense;
ccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR | CAM_AUTOSNS_VALID;
ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
ccb->csio.scsi_status = SCSI_STATUS_CHECK_COND;
bzero(&ccb->csio.sense_data, ccb->csio.sense_len);
ccb->csio.sense_data.error_code =
SSD_CURRENT_ERROR | SSD_ERRCODE_VALID;
ccb->csio.sense_data.flags = SSD_KEY_NOT_READY;
sense = &ccb->csio.sense_data;
scsi_set_sense_data(sense,
/*sense_format*/ SSD_TYPE_NONE,
/*current_error*/ 1,
/*sense_key*/ SSD_KEY_NOT_READY,
/*asc*/ 0x4,
/*ascq*/ 0x01,
SSD_ELEM_NONE);
gdt->sc_dvr.size = sizeof(gdt->sc_dvr.eu.sync);
gdt->sc_dvr.eu.sync.ionode = gdt->sc_hanum;

View File

@ -153,6 +153,7 @@ getSenseData(u_int status, union ccb *ccb, pduq_t *pq)
scsi_rsp_t *cmd = &pp->ipdu.scsi_rsp;
caddr_t bp;
int sense_len, mustfree = 0;
int error_code, sense_key, asc, ascq;
bp = mtod(pq->mp, caddr_t);
if((sense_len = scsi_2btoul(bp)) == 0)
@ -174,10 +175,14 @@ getSenseData(u_int status, union ccb *ccb, pduq_t *pq)
scsi->sense_resid = 0;
if(cmd->flag & (BIT(1)|BIT(2)))
scsi->sense_resid = ntohl(pp->ipdu.scsi_rsp.rcnt);
scsi_extract_sense_len(sense, scsi->sense_len - scsi->sense_resid,
&error_code, &sense_key, &asc, &ascq, /*show_errors*/ 1);
debug(3, "sense_len=%d rcnt=%d sense_resid=%d dsl=%d error_code=%x flags=%x",
sense_len,
ntohl(pp->ipdu.scsi_rsp.rcnt), scsi->sense_resid,
pp->ds_len, sense->error_code, sense->flags);
pp->ds_len, error_code, sense_key);
if(mustfree)
free(bp, M_ISCSI);

View File

@ -438,11 +438,19 @@ default: \
#define XS_SNSP(ccb) (&(ccb)->sense_data)
#define XS_SNSLEN(ccb) \
imin((sizeof((ccb)->sense_data)), ccb->sense_len)
imin((sizeof((ccb)->sense_data)), ccb->sense_len - ccb->sense_resid)
#define XS_SNSKEY(ccb) ((ccb)->sense_data.flags & 0xf)
#define XS_SNSASC(ccb) ((ccb)->sense_data.add_sense_code)
#define XS_SNSASCQ(ccb) ((ccb)->sense_data.add_sense_code_qual)
#define XS_SNSKEY(ccb) (scsi_get_sense_key(&(ccb)->sense_data, \
ccb->sense_len - ccb->sense_resid, \
/*show_errors*/ 1))
#define XS_SNSASC(ccb) (scsi_get_asc(&(ccb)->sense_data, \
ccb->sense_len - ccb->sense_resid, \
/*show_errors*/ 1))
#define XS_SNSASCQ(ccb) (scsi_get_ascq(&(ccb)->sense_data, \
ccb->sense_len - ccb->sense_resid, \
/*show_errors*/ 1))
#define XS_TAG_P(ccb) \
(((ccb)->ccb_h.flags & CAM_TAG_ACTION_VALID) && \
(ccb)->tag_action != CAM_TAG_ACTION_NONE)
@ -476,9 +484,13 @@ default: \
#define XS_INITERR(ccb) \
XS_SETERR(ccb, CAM_REQ_INPROG), (ccb)->ccb_h.spriv_field0 = 0
#define XS_SAVE_SENSE(xs, sense_ptr, sense_len) \
(xs)->ccb_h.status |= CAM_AUTOSNS_VALID; \
memcpy(&(xs)->sense_data, sense_ptr, imin(XS_SNSLEN(xs), sense_len))
#define XS_SAVE_SENSE(xs, sense_ptr, slen) do { \
(xs)->ccb_h.status |= CAM_AUTOSNS_VALID; \
memcpy(&(xs)->sense_data, sense_ptr, imin(XS_SNSLEN(xs),\
slen)); \
if (slen < (xs)->sense_len) \
(xs)->sense_resid = (xs)->sense_len - slen; \
} while (0);
#define XS_SENSE_VALID(xs) (((xs)->ccb_h.status & CAM_AUTOSNS_VALID) != 0)

View File

@ -1294,9 +1294,11 @@ mly_complete_event(struct mly_command *mc)
static void
mly_process_event(struct mly_softc *sc, struct mly_event *me)
{
struct scsi_sense_data *ssd = (struct scsi_sense_data *)&me->sense[0];
char *fp, *tp;
int bus, target, event, class, action;
struct scsi_sense_data_fixed *ssd;
char *fp, *tp;
int bus, target, event, class, action;
ssd = (struct scsi_sense_data_fixed *)&me->sense[0];
/*
* Errors can be reported using vendor-unique sense data. In this case, the

View File

@ -1490,7 +1490,6 @@ mpssas_scsiio_complete(struct mps_softc *sc, struct mps_command *cm)
MPI2_SCSI_IO_REPLY *rep;
union ccb *ccb;
struct mpssas_softc *sassc;
u_int sense_len;
int dir = 0;
mps_dprint(sc, MPS_TRACE, "%s\n", __func__);
@ -1666,10 +1665,16 @@ mpssas_scsiio_complete(struct mps_softc *sc, struct mps_command *cm)
}
if (rep->SCSIState & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
sense_len = MIN(rep->SenseCount,
sizeof(struct scsi_sense_data));
if (sense_len < rep->SenseCount)
ccb->csio.sense_resid = rep->SenseCount - sense_len;
int sense_len;
if (rep->SenseCount < ccb->csio.sense_len)
ccb->csio.sense_resid = ccb->csio.sense_len -
rep->SenseCount;
else
ccb->csio.sense_resid = 0;
sense_len = min(rep->SenseCount, ccb->csio.sense_len -
ccb->csio.sense_resid);
bcopy(cm->cm_sense, &ccb->csio.sense_data, sense_len);
ccb->ccb_h.status |= CAM_AUTOSNS_VALID;
}

View File

@ -3167,12 +3167,19 @@ mpt_scsi_reply_frame_handler(struct mpt_softc *mpt, request_t *req,
if ((sstate & MPI_SCSI_STATE_AUTOSENSE_VALID) != 0
&& (ccb->ccb_h.flags & (CAM_SENSE_PHYS | CAM_SENSE_PTR)) == 0) {
uint32_t sense_returned;
ccb->ccb_h.status |= CAM_AUTOSNS_VALID;
ccb->csio.sense_resid =
ccb->csio.sense_len - le32toh(scsi_io_reply->SenseCount);
sense_returned = le32toh(scsi_io_reply->SenseCount);
if (sense_returned < ccb->csio.sense_len)
ccb->csio.sense_resid = ccb->csio.sense_len -
sense_returned;
else
ccb->csio.sense_resid = 0;
bcopy(req->sense_vbuf, &ccb->csio.sense_data,
min(ccb->csio.sense_len,
le32toh(scsi_io_reply->SenseCount)));
min(ccb->csio.sense_len, sense_returned));
}
if ((sstate & MPI_SCSI_STATE_QUEUE_TAG_REJECTED) != 0) {

View File

@ -2344,14 +2344,14 @@ umass_cam_action(struct cam_sim *sim, union ccb *ccb)
*/
if ((sc->sc_quirks & (NO_INQUIRY_EVPD | NO_INQUIRY)) &&
(sc->sc_transfer.cmd_data[1] & SI_EVPD)) {
struct scsi_sense_data *sense;
sense = &ccb->csio.sense_data;
bzero(sense, sizeof(*sense));
sense->error_code = SSD_CURRENT_ERROR;
sense->flags = SSD_KEY_ILLEGAL_REQUEST;
sense->add_sense_code = 0x24;
sense->extra_len = 10;
scsi_set_sense_data(&ccb->csio.sense_data,
/*sense_format*/ SSD_TYPE_NONE,
/*current_error*/ 1,
/*sense_key*/ SSD_KEY_ILLEGAL_REQUEST,
/*asc*/ 0x24,
/*ascq*/ 0x00,
/*extra args*/ SSD_ELEM_NONE);
ccb->csio.scsi_status = SCSI_STATUS_CHECK_COND;
ccb->ccb_h.status = CAM_SCSI_STATUS_ERROR |
CAM_AUTOSNS_VALID;
@ -2631,12 +2631,17 @@ umass_cam_sense_cb(struct umass_softc *sc, union ccb *ccb, uint32_t residue,
uint8_t status)
{
uint8_t *cmd;
uint8_t key;
switch (status) {
case STATUS_CMD_OK:
case STATUS_CMD_UNKNOWN:
case STATUS_CMD_FAILED:
case STATUS_CMD_FAILED: {
int key, sense_len;
ccb->csio.sense_resid = residue;
sense_len = ccb->csio.sense_len - ccb->csio.sense_resid;
key = scsi_get_sense_key(&ccb->csio.sense_data, sense_len,
/*show_errors*/ 1);
if (ccb->csio.ccb_h.flags & CAM_CDB_POINTER) {
cmd = (uint8_t *)(ccb->csio.cdb_io.cdb_ptr);
@ -2644,8 +2649,6 @@ umass_cam_sense_cb(struct umass_softc *sc, union ccb *ccb, uint32_t residue,
cmd = (uint8_t *)(ccb->csio.cdb_io.cdb_bytes);
}
key = (ccb->csio.sense_data.flags & SSD_KEY);
/*
* Getting sense data always succeeds (apart from wire
* failures):
@ -2704,7 +2707,7 @@ umass_cam_sense_cb(struct umass_softc *sc, union ccb *ccb, uint32_t residue,
}
xpt_done(ccb);
break;
}
default:
DPRINTF(sc, UDMASS_SCSI, "Autosense failed, "
"status %d\n", status);

View File

@ -506,21 +506,19 @@ ps3cdrom_intr(void *arg)
if (!ps3cdrom_decode_lv1_status(status, &sense_key,
&asc, &ascq)) {
struct scsi_sense_data sense_data;
CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE,
("sense key 0x%02x asc 0x%02x ascq 0x%02x\n",
sense_key, asc, ascq));
bzero(&sense_data, sizeof(sense_data));
sense_data.error_code = SSD_CURRENT_ERROR;
sense_data.flags |= sense_key;
sense_data.extra_len = 0xa;
sense_data.add_sense_code = asc;
sense_data.add_sense_code_qual = ascq;
ccb->csio.sense_len = sizeof(sense_data);
bcopy(&sense_data, &ccb->csio.sense_data,
ccb->csio.sense_len);
scsi_set_sense_data(&ccb->csio.sense_data,
/*sense_format*/ SSD_TYPE_NONE,
/*current_error*/ 1,
sense_key,
asc,
ascq,
SSD_ELEM_NONE);
ccb->csio.sense_len = SSD_FULL_SIZE;
ccb->ccb_h.status = CAM_SCSI_STATUS_ERROR |
CAM_AUTOSNS_VALID;
}
@ -643,8 +641,6 @@ ps3cdrom_transfer(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
}
if (err) {
struct scsi_sense_data sense_data;
device_printf(dev, "ATAPI command 0x%02x failed (%d)\n",
cdb[0], err);
@ -653,11 +649,18 @@ ps3cdrom_transfer(void *arg, bus_dma_segment_t *segs, int nsegs, int error)
xp->x_ccb = NULL;
TAILQ_INSERT_TAIL(&sc->sc_free_xferq, xp, x_queue);
bzero(&sense_data, sizeof(sense_data));
sense_data.error_code = SSD_CURRENT_ERROR;
sense_data.flags |= SSD_KEY_ILLEGAL_REQUEST;
ccb->csio.sense_len = sizeof(sense_data);
bcopy(&sense_data, &ccb->csio.sense_data, ccb->csio.sense_len);
bzero(&ccb->csio.sense_data, sizeof(ccb->csio.sense_data));
/* Invalid field in parameter list */
scsi_set_sense_data(&ccb->csio.sense_data,
/*sense_format*/ SSD_TYPE_NONE,
/*current_error*/ 1,
/*sense_key*/ SSD_KEY_ILLEGAL_REQUEST,
/*asc*/ 0x26,
/*ascq*/ 0x00,
SSD_ELEM_NONE);
ccb->csio.sense_len = SSD_FULL_SIZE;
ccb->csio.scsi_status = SCSI_STATUS_CHECK_COND;
ccb->ccb_h.status = CAM_SCSI_STATUS_ERROR | CAM_AUTOSNS_VALID;
xpt_done(ccb);
} else {