diff options
author | Hannes Reinecke <hare@suse.de> | 2021-04-27 10:30:13 +0200 |
---|---|---|
committer | Martin K. Petersen <martin.petersen@oracle.com> | 2021-05-31 22:48:21 -0400 |
commit | f2b1e9c6f867ec8f929e96ba4e4010e267587448 (patch) | |
tree | 5bf630724f083e7dd2a8e82959d9bb342f0b3644 /drivers/scsi/myrb.c | |
parent | ced202f7bd78eb6a79c441a8b217e0f3d38bccfc (diff) |
scsi: core: Introduce scsi_build_sense()
Introduce scsi_build_sense() as a wrapper around scsi_build_sense_buffer()
to format the buffer and set the correct SCSI status.
Link: https://lore.kernel.org/r/20210427083046.31620-8-hare@suse.de
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Diffstat (limited to 'drivers/scsi/myrb.c')
-rw-r--r-- | drivers/scsi/myrb.c | 64 |
1 files changed, 15 insertions, 49 deletions
diff --git a/drivers/scsi/myrb.c b/drivers/scsi/myrb.c index d9c82e211ae7..542ed88ef90d 100644 --- a/drivers/scsi/myrb.c +++ b/drivers/scsi/myrb.c @@ -1397,8 +1397,7 @@ myrb_mode_sense(struct myrb_hba *cb, struct scsi_cmnd *scmd, static void myrb_request_sense(struct myrb_hba *cb, struct scsi_cmnd *scmd) { - scsi_build_sense_buffer(0, scmd->sense_buffer, - NO_SENSE, 0, 0); + scsi_build_sense(scmd, 0, NO_SENSE, 0, 0); scsi_sg_copy_from_buffer(scmd, scmd->sense_buffer, SCSI_SENSE_BUFFERSIZE); } @@ -1447,10 +1446,7 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost, case INQUIRY: if (scmd->cmnd[1] & 1) { /* Illegal request, invalid field in CDB */ - scsi_build_sense_buffer(0, scmd->sense_buffer, - ILLEGAL_REQUEST, 0x24, 0); - scmd->result = (DRIVER_SENSE << 24) | - SAM_STAT_CHECK_CONDITION; + scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x24, 0); } else { myrb_inquiry(cb, scmd); scmd->result = (DID_OK << 16); @@ -1465,10 +1461,7 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost, if ((scmd->cmnd[2] & 0x3F) != 0x3F && (scmd->cmnd[2] & 0x3F) != 0x08) { /* Illegal request, invalid field in CDB */ - scsi_build_sense_buffer(0, scmd->sense_buffer, - ILLEGAL_REQUEST, 0x24, 0); - scmd->result = (DRIVER_SENSE << 24) | - SAM_STAT_CHECK_CONDITION; + scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x24, 0); } else { myrb_mode_sense(cb, scmd, ldev_info); scmd->result = (DID_OK << 16); @@ -1479,20 +1472,14 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost, if ((scmd->cmnd[1] & 1) || (scmd->cmnd[8] & 1)) { /* Illegal request, invalid field in CDB */ - scsi_build_sense_buffer(0, scmd->sense_buffer, - ILLEGAL_REQUEST, 0x24, 0); - scmd->result = (DRIVER_SENSE << 24) | - SAM_STAT_CHECK_CONDITION; + scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x24, 0); scmd->scsi_done(scmd); return 0; } lba = get_unaligned_be32(&scmd->cmnd[2]); if (lba) { /* Illegal request, invalid field in CDB */ - scsi_build_sense_buffer(0, scmd->sense_buffer, - ILLEGAL_REQUEST, 0x24, 0); - scmd->result = (DRIVER_SENSE << 24) | - SAM_STAT_CHECK_CONDITION; + scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x24, 0); scmd->scsi_done(scmd); return 0; } @@ -1506,10 +1493,7 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost, case SEND_DIAGNOSTIC: if (scmd->cmnd[1] != 0x04) { /* Illegal request, invalid field in CDB */ - scsi_build_sense_buffer(0, scmd->sense_buffer, - ILLEGAL_REQUEST, 0x24, 0); - scmd->result = (DRIVER_SENSE << 24) | - SAM_STAT_CHECK_CONDITION; + scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x24, 0); } else { /* Assume good status */ scmd->result = (DID_OK << 16); @@ -1519,10 +1503,7 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost, case READ_6: if (ldev_info->state == MYRB_DEVICE_WO) { /* Data protect, attempt to read invalid data */ - scsi_build_sense_buffer(0, scmd->sense_buffer, - DATA_PROTECT, 0x21, 0x06); - scmd->result = (DRIVER_SENSE << 24) | - SAM_STAT_CHECK_CONDITION; + scsi_build_sense(scmd, 0, DATA_PROTECT, 0x21, 0x06); scmd->scsi_done(scmd); return 0; } @@ -1536,10 +1517,7 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost, case READ_10: if (ldev_info->state == MYRB_DEVICE_WO) { /* Data protect, attempt to read invalid data */ - scsi_build_sense_buffer(0, scmd->sense_buffer, - DATA_PROTECT, 0x21, 0x06); - scmd->result = (DRIVER_SENSE << 24) | - SAM_STAT_CHECK_CONDITION; + scsi_build_sense(scmd, 0, DATA_PROTECT, 0x21, 0x06); scmd->scsi_done(scmd); return 0; } @@ -1553,10 +1531,7 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost, case READ_12: if (ldev_info->state == MYRB_DEVICE_WO) { /* Data protect, attempt to read invalid data */ - scsi_build_sense_buffer(0, scmd->sense_buffer, - DATA_PROTECT, 0x21, 0x06); - scmd->result = (DRIVER_SENSE << 24) | - SAM_STAT_CHECK_CONDITION; + scsi_build_sense(scmd, 0, DATA_PROTECT, 0x21, 0x06); scmd->scsi_done(scmd); return 0; } @@ -1569,9 +1544,7 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost, break; default: /* Illegal request, invalid opcode */ - scsi_build_sense_buffer(0, scmd->sense_buffer, - ILLEGAL_REQUEST, 0x20, 0); - scmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; + scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x20, 0); scmd->scsi_done(scmd); return 0; } @@ -2352,25 +2325,19 @@ static void myrb_handle_scsi(struct myrb_hba *cb, struct myrb_cmdblk *cmd_blk, "Bad Data Encountered\n"); if (scmd->sc_data_direction == DMA_FROM_DEVICE) /* Unrecovered read error */ - scsi_build_sense_buffer(0, scmd->sense_buffer, - MEDIUM_ERROR, 0x11, 0); + scsi_build_sense(scmd, 0, MEDIUM_ERROR, 0x11, 0); else /* Write error */ - scsi_build_sense_buffer(0, scmd->sense_buffer, - MEDIUM_ERROR, 0x0C, 0); - scmd->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION; + scsi_build_sense(scmd, 0, MEDIUM_ERROR, 0x0C, 0); break; case MYRB_STATUS_IRRECOVERABLE_DATA_ERROR: scmd_printk(KERN_ERR, scmd, "Irrecoverable Data Error\n"); if (scmd->sc_data_direction == DMA_FROM_DEVICE) /* Unrecovered read error, auto-reallocation failed */ - scsi_build_sense_buffer(0, scmd->sense_buffer, - MEDIUM_ERROR, 0x11, 0x04); + scsi_build_sense(scmd, 0, MEDIUM_ERROR, 0x11, 0x04); else /* Write error, auto-reallocation failed */ - scsi_build_sense_buffer(0, scmd->sense_buffer, - MEDIUM_ERROR, 0x0C, 0x02); - scmd->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION; + scsi_build_sense(scmd, 0, MEDIUM_ERROR, 0x0C, 0x02); break; case MYRB_STATUS_LDRV_NONEXISTENT_OR_OFFLINE: dev_dbg(&scmd->device->sdev_gendev, @@ -2381,8 +2348,7 @@ static void myrb_handle_scsi(struct myrb_hba *cb, struct myrb_cmdblk *cmd_blk, dev_dbg(&scmd->device->sdev_gendev, "Attempt to Access Beyond End of Logical Drive"); /* Logical block address out of range */ - scsi_build_sense_buffer(0, scmd->sense_buffer, - NOT_READY, 0x21, 0); + scsi_build_sense(scmd, 0, NOT_READY, 0x21, 0); break; case MYRB_STATUS_DEVICE_NONRESPONSIVE: dev_dbg(&scmd->device->sdev_gendev, "Device nonresponsive\n"); |