From df7e5429bc91a9a1952154bba8fb132c498d8a52 Mon Sep 17 00:00:00 2001 From: marius Date: Fri, 7 Oct 2011 08:59:54 +0000 Subject: Merge from r225950: Set the sense residual properly. Reviewed by: ken --- sys/dev/esp/ncr53c9x.c | 12 ++++++++++-- sys/dev/sym/sym_hipd.c | 14 +++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/sys/dev/esp/ncr53c9x.c b/sys/dev/esp/ncr53c9x.c index 9373420..bf3ef4c 100644 --- a/sys/dev/esp/ncr53c9x.c +++ b/sys/dev/esp/ncr53c9x.c @@ -1367,7 +1367,8 @@ ncr53c9x_sense(struct ncr53c9x_softc *sc, struct ncr53c9x_ecb *ecb) ss->byte2 = ccb->ccb_h.target_lun << SCSI_CMD_LUN_SHIFT; ss->length = sizeof(struct scsi_sense_data); ecb->clen = sizeof(*ss); - ecb->daddr = (char *)&ecb->ccb->csio.sense_data; + memset(&ccb->csio.sense_data, 0, sizeof(ccb->csio.sense_data)); + ecb->daddr = (char *)&ccb->csio.sense_data; ecb->dleft = sizeof(struct scsi_sense_data); ecb->flags |= ECB_SENSE; ecb->timeout = NCR_SENSE_TIMEOUT; @@ -1397,7 +1398,7 @@ ncr53c9x_done(struct ncr53c9x_softc *sc, struct ncr53c9x_ecb *ecb) union ccb *ccb = ecb->ccb; struct ncr53c9x_linfo *li; struct ncr53c9x_tinfo *ti; - int lun; + int lun, sense_returned; NCR_LOCK_ASSERT(sc, MA_OWNED); @@ -1426,6 +1427,13 @@ ncr53c9x_done(struct ncr53c9x_softc *sc, struct ncr53c9x_ecb *ecb) ccb->csio.scsi_status = SCSI_STATUS_CHECK_COND; ccb->ccb_h.status = CAM_SCSI_STATUS_ERROR | CAM_AUTOSNS_VALID; + sense_returned = sizeof(ccb->csio.sense_data) - + ecb->dleft; + if (sense_returned < ccb->csio.sense_len) + ccb->csio.sense_resid = ccb->csio.sense_len - + sense_returned; + else + ccb->csio.sense_resid = 0; } else if (ecb->stat == SCSI_STATUS_CHECK_COND) { if ((ecb->flags & ECB_SENSE) != 0) ccb->ccb_h.status = CAM_AUTOSENSE_FAIL; diff --git a/sys/dev/sym/sym_hipd.c b/sys/dev/sym/sym_hipd.c index bc1ddcc..d4e1aca 100644 --- a/sys/dev/sym/sym_hipd.c +++ b/sys/dev/sym/sym_hipd.c @@ -7154,7 +7154,7 @@ static void sym_complete_error (hcb_p np, ccb_p cp) { struct ccb_scsiio *csio; u_int cam_status; - int i; + int i, sense_returned; SYM_LOCK_ASSERT(MA_OWNED); @@ -7214,11 +7214,15 @@ static void sym_complete_error (hcb_p np, ccb_p cp) * Bounce back the sense data to user and * fix the residual. */ - bzero(&csio->sense_data, csio->sense_len); + bzero(&csio->sense_data, sizeof(csio->sense_data)); + sense_returned = SYM_SNS_BBUF_LEN - csio->sense_resid; + if (sense_returned < csio->sense_len) + csio->sense_resid = csio->sense_len - + sense_returned; + else + csio->sense_resid = 0; bcopy(cp->sns_bbuf, &csio->sense_data, - MIN(csio->sense_len, SYM_SNS_BBUF_LEN)); - csio->sense_resid += csio->sense_len; - csio->sense_resid -= SYM_SNS_BBUF_LEN; + MIN(csio->sense_len, sense_returned)); #if 0 /* * If the device reports a UNIT ATTENTION condition -- cgit v1.1