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>
This commit is contained in:
Hannes Reinecke 2021-04-27 10:30:13 +02:00 committed by Martin K. Petersen
parent ced202f7bd
commit f2b1e9c6f8
18 changed files with 85 additions and 164 deletions

View File

@ -196,9 +196,7 @@ void ata_scsi_set_sense(struct ata_device *dev, struct scsi_cmnd *cmd,
if (!cmd) if (!cmd)
return; return;
cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; scsi_build_sense(cmd, d_sense, sk, asc, ascq);
scsi_build_sense_buffer(d_sense, cmd->sense_buffer, sk, asc, ascq);
} }
void ata_scsi_set_sense_information(struct ata_device *dev, void ata_scsi_set_sense_information(struct ata_device *dev,
@ -882,8 +880,7 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc)
* ATA PASS-THROUGH INFORMATION AVAILABLE * ATA PASS-THROUGH INFORMATION AVAILABLE
* Always in descriptor format sense. * Always in descriptor format sense.
*/ */
scsi_build_sense_buffer(1, cmd->sense_buffer, scsi_build_sense(cmd, 1, RECOVERED_ERROR, 0, 0x1D);
RECOVERED_ERROR, 0, 0x1D);
} }
if ((cmd->sense_buffer[0] & 0x7f) >= 0x72) { if ((cmd->sense_buffer[0] & 0x7f) >= 0x72) {

View File

@ -856,10 +856,7 @@ void zfcp_scsi_set_prot(struct zfcp_adapter *adapter)
*/ */
void zfcp_scsi_dif_sense_error(struct scsi_cmnd *scmd, int ascq) void zfcp_scsi_dif_sense_error(struct scsi_cmnd *scmd, int ascq)
{ {
scsi_build_sense_buffer(1, scmd->sense_buffer, scsi_build_sense(scmd, 1, ILLEGAL_REQUEST, 0x10, ascq);
ILLEGAL_REQUEST, 0x10, ascq);
set_driver_byte(scmd, DRIVER_SENSE);
scmd->result |= SAM_STAT_CHECK_CONDITION;
set_host_byte(scmd, DID_SOFT_ERROR); set_host_byte(scmd, DID_SOFT_ERROR);
} }

View File

@ -1977,7 +1977,7 @@ static int tw_scsi_queue_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_c
printk(KERN_NOTICE "3w-xxxx: scsi%d: Unknown scsi opcode: 0x%x\n", tw_dev->host->host_no, *command); printk(KERN_NOTICE "3w-xxxx: scsi%d: Unknown scsi opcode: 0x%x\n", tw_dev->host->host_no, *command);
tw_dev->state[request_id] = TW_S_COMPLETED; tw_dev->state[request_id] = TW_S_COMPLETED;
tw_state_request_finish(tw_dev, request_id); tw_state_request_finish(tw_dev, request_id);
scsi_build_sense_buffer(1, SCpnt->sense_buffer, ILLEGAL_REQUEST, 0x20, 0); scsi_build_sense(SCpnt, 1, ILLEGAL_REQUEST, 0x20, 0);
done(SCpnt); done(SCpnt);
retval = 0; retval = 0;
} }

View File

@ -829,10 +829,7 @@ static void iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
ascq = session->tt->check_protection(task, &sector); ascq = session->tt->check_protection(task, &sector);
if (ascq) { if (ascq) {
sc->result = DRIVER_SENSE << 24 | scsi_build_sense(sc, 1, ILLEGAL_REQUEST, 0x10, ascq);
SAM_STAT_CHECK_CONDITION;
scsi_build_sense_buffer(1, sc->sense_buffer,
ILLEGAL_REQUEST, 0x10, ascq);
scsi_set_sense_information(sc->sense_buffer, scsi_set_sense_information(sc->sense_buffer,
SCSI_SENSE_BUFFERSIZE, SCSI_SENSE_BUFFERSIZE,
sector); sector);

View File

@ -2896,10 +2896,8 @@ skipit:
} }
out: out:
if (err_type == BGS_GUARD_ERR_MASK) { if (err_type == BGS_GUARD_ERR_MASK) {
scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x1);
0x10, 0x1); set_host_byte(cmd, DID_ABORT);
cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
SAM_STAT_CHECK_CONDITION;
phba->bg_guard_err_cnt++; phba->bg_guard_err_cnt++;
lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
"9069 BLKGRD: reftag %x grd_tag err %x != %x\n", "9069 BLKGRD: reftag %x grd_tag err %x != %x\n",
@ -2907,10 +2905,8 @@ out:
sum, guard_tag); sum, guard_tag);
} else if (err_type == BGS_REFTAG_ERR_MASK) { } else if (err_type == BGS_REFTAG_ERR_MASK) {
scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x3);
0x10, 0x3); set_host_byte(cmd, DID_ABORT);
cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
SAM_STAT_CHECK_CONDITION;
phba->bg_reftag_err_cnt++; phba->bg_reftag_err_cnt++;
lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
@ -2919,10 +2915,8 @@ out:
ref_tag, start_ref_tag); ref_tag, start_ref_tag);
} else if (err_type == BGS_APPTAG_ERR_MASK) { } else if (err_type == BGS_APPTAG_ERR_MASK) {
scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x2);
0x10, 0x2); set_host_byte(cmd, DID_ABORT);
cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
SAM_STAT_CHECK_CONDITION;
phba->bg_apptag_err_cnt++; phba->bg_apptag_err_cnt++;
lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
@ -2981,10 +2975,8 @@ lpfc_sli4_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
if (lpfc_bgs_get_guard_err(bgstat)) { if (lpfc_bgs_get_guard_err(bgstat)) {
ret = 1; ret = 1;
scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x1);
0x10, 0x1); set_host_byte(cmd, DID_ABORT);
cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
SAM_STAT_CHECK_CONDITION;
phba->bg_guard_err_cnt++; phba->bg_guard_err_cnt++;
lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
"9059 BLKGRD: Guard Tag error in cmd" "9059 BLKGRD: Guard Tag error in cmd"
@ -2997,10 +2989,8 @@ lpfc_sli4_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
if (lpfc_bgs_get_reftag_err(bgstat)) { if (lpfc_bgs_get_reftag_err(bgstat)) {
ret = 1; ret = 1;
scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x3);
0x10, 0x3); set_host_byte(cmd, DID_ABORT);
cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
SAM_STAT_CHECK_CONDITION;
phba->bg_reftag_err_cnt++; phba->bg_reftag_err_cnt++;
lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
@ -3014,10 +3004,8 @@ lpfc_sli4_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
if (lpfc_bgs_get_apptag_err(bgstat)) { if (lpfc_bgs_get_apptag_err(bgstat)) {
ret = 1; ret = 1;
scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x2);
0x10, 0x2); set_host_byte(cmd, DID_ABORT);
cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
SAM_STAT_CHECK_CONDITION;
phba->bg_apptag_err_cnt++; phba->bg_apptag_err_cnt++;
lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
@ -3127,10 +3115,8 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
if (lpfc_bgs_get_guard_err(bgstat)) { if (lpfc_bgs_get_guard_err(bgstat)) {
ret = 1; ret = 1;
scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x1);
0x10, 0x1); set_host_byte(cmd, DID_ABORT);
cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
SAM_STAT_CHECK_CONDITION;
phba->bg_guard_err_cnt++; phba->bg_guard_err_cnt++;
lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
"9055 BLKGRD: Guard Tag error in cmd " "9055 BLKGRD: Guard Tag error in cmd "
@ -3143,10 +3129,8 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
if (lpfc_bgs_get_reftag_err(bgstat)) { if (lpfc_bgs_get_reftag_err(bgstat)) {
ret = 1; ret = 1;
scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x3);
0x10, 0x3); set_host_byte(cmd, DID_ABORT);
cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
SAM_STAT_CHECK_CONDITION;
phba->bg_reftag_err_cnt++; phba->bg_reftag_err_cnt++;
lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
@ -3160,10 +3144,8 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
if (lpfc_bgs_get_apptag_err(bgstat)) { if (lpfc_bgs_get_apptag_err(bgstat)) {
ret = 1; ret = 1;
scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x2);
0x10, 0x2); set_host_byte(cmd, DID_ABORT);
cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
SAM_STAT_CHECK_CONDITION;
phba->bg_apptag_err_cnt++; phba->bg_apptag_err_cnt++;
lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG, lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,

View File

@ -1596,11 +1596,9 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
cmd->result = (DRIVER_SENSE << 24) | cmd->result = (DRIVER_SENSE << 24) |
(DID_OK << 16) | (DID_OK << 16) |
(CHECK_CONDITION << 1); (CHECK_CONDITION << 1);
} else { } else
cmd->sense_buffer[0] = 0x70; scsi_build_sense(cmd, 0,
cmd->sense_buffer[2] = ABORTED_COMMAND; ABORTED_COMMAND, 0, 0);
cmd->result |= (CHECK_CONDITION << 1);
}
} }
break; break;

View File

@ -1574,10 +1574,8 @@ megaraid_mbox_build_cmd(adapter_t *adapter, struct scsi_cmnd *scp, int *busy)
} }
if (scp->cmnd[1] & MEGA_SCSI_INQ_EVPD) { if (scp->cmnd[1] & MEGA_SCSI_INQ_EVPD) {
scp->sense_buffer[0] = 0x70; scsi_build_sense(scp, 0, ILLEGAL_REQUEST,
scp->sense_buffer[2] = ILLEGAL_REQUEST; MEGA_INVALID_FIELD_IN_CDB, 0);
scp->sense_buffer[12] = MEGA_INVALID_FIELD_IN_CDB;
scp->result = CHECK_CONDITION << 1;
return NULL; return NULL;
} }
@ -2313,11 +2311,9 @@ megaraid_mbox_dpc(unsigned long devp)
scp->result = DRIVER_SENSE << 24 | scp->result = DRIVER_SENSE << 24 |
DID_OK << 16 | DID_OK << 16 |
CHECK_CONDITION << 1; CHECK_CONDITION << 1;
} else { } else
scp->sense_buffer[0] = 0x70; scsi_build_sense(scp, 0,
scp->sense_buffer[2] = ABORTED_COMMAND; ABORTED_COMMAND, 0, 0);
scp->result = CHECK_CONDITION << 1;
}
} }
break; break;

View File

@ -5119,10 +5119,8 @@ _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
ascq = 0x00; ascq = 0x00;
break; break;
} }
scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10, scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x10, ascq);
ascq); set_host_byte(scmd, DID_ABORT);
scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
SAM_STAT_CHECK_CONDITION;
} }
/** /**
@ -5879,12 +5877,8 @@ _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) { else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID; mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION; mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
scmd->result = (DRIVER_SENSE << 24) | scsi_build_sense(scmd, 0, ILLEGAL_REQUEST,
SAM_STAT_CHECK_CONDITION; 0x20, 0);
scmd->sense_buffer[0] = 0x70;
scmd->sense_buffer[2] = ILLEGAL_REQUEST;
scmd->sense_buffer[12] = 0x20;
scmd->sense_buffer[13] = 0;
} }
break; break;

View File

@ -2068,10 +2068,7 @@ static unsigned char mvumi_build_frame(struct mvumi_hba *mhba,
return 0; return 0;
error: error:
scmd->result = (DID_OK << 16) | (DRIVER_SENSE << 24) | scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x24, 0);
SAM_STAT_CHECK_CONDITION;
scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x24,
0);
return -1; return -1;
} }

View File

@ -1397,8 +1397,7 @@ myrb_mode_sense(struct myrb_hba *cb, struct scsi_cmnd *scmd,
static void myrb_request_sense(struct myrb_hba *cb, static void myrb_request_sense(struct myrb_hba *cb,
struct scsi_cmnd *scmd) struct scsi_cmnd *scmd)
{ {
scsi_build_sense_buffer(0, scmd->sense_buffer, scsi_build_sense(scmd, 0, NO_SENSE, 0, 0);
NO_SENSE, 0, 0);
scsi_sg_copy_from_buffer(scmd, scmd->sense_buffer, scsi_sg_copy_from_buffer(scmd, scmd->sense_buffer,
SCSI_SENSE_BUFFERSIZE); SCSI_SENSE_BUFFERSIZE);
} }
@ -1447,10 +1446,7 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost,
case INQUIRY: case INQUIRY:
if (scmd->cmnd[1] & 1) { if (scmd->cmnd[1] & 1) {
/* Illegal request, invalid field in CDB */ /* Illegal request, invalid field in CDB */
scsi_build_sense_buffer(0, scmd->sense_buffer, scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x24, 0);
ILLEGAL_REQUEST, 0x24, 0);
scmd->result = (DRIVER_SENSE << 24) |
SAM_STAT_CHECK_CONDITION;
} else { } else {
myrb_inquiry(cb, scmd); myrb_inquiry(cb, scmd);
scmd->result = (DID_OK << 16); scmd->result = (DID_OK << 16);
@ -1465,10 +1461,7 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost,
if ((scmd->cmnd[2] & 0x3F) != 0x3F && if ((scmd->cmnd[2] & 0x3F) != 0x3F &&
(scmd->cmnd[2] & 0x3F) != 0x08) { (scmd->cmnd[2] & 0x3F) != 0x08) {
/* Illegal request, invalid field in CDB */ /* Illegal request, invalid field in CDB */
scsi_build_sense_buffer(0, scmd->sense_buffer, scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x24, 0);
ILLEGAL_REQUEST, 0x24, 0);
scmd->result = (DRIVER_SENSE << 24) |
SAM_STAT_CHECK_CONDITION;
} else { } else {
myrb_mode_sense(cb, scmd, ldev_info); myrb_mode_sense(cb, scmd, ldev_info);
scmd->result = (DID_OK << 16); scmd->result = (DID_OK << 16);
@ -1479,20 +1472,14 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost,
if ((scmd->cmnd[1] & 1) || if ((scmd->cmnd[1] & 1) ||
(scmd->cmnd[8] & 1)) { (scmd->cmnd[8] & 1)) {
/* Illegal request, invalid field in CDB */ /* Illegal request, invalid field in CDB */
scsi_build_sense_buffer(0, scmd->sense_buffer, scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x24, 0);
ILLEGAL_REQUEST, 0x24, 0);
scmd->result = (DRIVER_SENSE << 24) |
SAM_STAT_CHECK_CONDITION;
scmd->scsi_done(scmd); scmd->scsi_done(scmd);
return 0; return 0;
} }
lba = get_unaligned_be32(&scmd->cmnd[2]); lba = get_unaligned_be32(&scmd->cmnd[2]);
if (lba) { if (lba) {
/* Illegal request, invalid field in CDB */ /* Illegal request, invalid field in CDB */
scsi_build_sense_buffer(0, scmd->sense_buffer, scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x24, 0);
ILLEGAL_REQUEST, 0x24, 0);
scmd->result = (DRIVER_SENSE << 24) |
SAM_STAT_CHECK_CONDITION;
scmd->scsi_done(scmd); scmd->scsi_done(scmd);
return 0; return 0;
} }
@ -1506,10 +1493,7 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost,
case SEND_DIAGNOSTIC: case SEND_DIAGNOSTIC:
if (scmd->cmnd[1] != 0x04) { if (scmd->cmnd[1] != 0x04) {
/* Illegal request, invalid field in CDB */ /* Illegal request, invalid field in CDB */
scsi_build_sense_buffer(0, scmd->sense_buffer, scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x24, 0);
ILLEGAL_REQUEST, 0x24, 0);
scmd->result = (DRIVER_SENSE << 24) |
SAM_STAT_CHECK_CONDITION;
} else { } else {
/* Assume good status */ /* Assume good status */
scmd->result = (DID_OK << 16); scmd->result = (DID_OK << 16);
@ -1519,10 +1503,7 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost,
case READ_6: case READ_6:
if (ldev_info->state == MYRB_DEVICE_WO) { if (ldev_info->state == MYRB_DEVICE_WO) {
/* Data protect, attempt to read invalid data */ /* Data protect, attempt to read invalid data */
scsi_build_sense_buffer(0, scmd->sense_buffer, scsi_build_sense(scmd, 0, DATA_PROTECT, 0x21, 0x06);
DATA_PROTECT, 0x21, 0x06);
scmd->result = (DRIVER_SENSE << 24) |
SAM_STAT_CHECK_CONDITION;
scmd->scsi_done(scmd); scmd->scsi_done(scmd);
return 0; return 0;
} }
@ -1536,10 +1517,7 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost,
case READ_10: case READ_10:
if (ldev_info->state == MYRB_DEVICE_WO) { if (ldev_info->state == MYRB_DEVICE_WO) {
/* Data protect, attempt to read invalid data */ /* Data protect, attempt to read invalid data */
scsi_build_sense_buffer(0, scmd->sense_buffer, scsi_build_sense(scmd, 0, DATA_PROTECT, 0x21, 0x06);
DATA_PROTECT, 0x21, 0x06);
scmd->result = (DRIVER_SENSE << 24) |
SAM_STAT_CHECK_CONDITION;
scmd->scsi_done(scmd); scmd->scsi_done(scmd);
return 0; return 0;
} }
@ -1553,10 +1531,7 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost,
case READ_12: case READ_12:
if (ldev_info->state == MYRB_DEVICE_WO) { if (ldev_info->state == MYRB_DEVICE_WO) {
/* Data protect, attempt to read invalid data */ /* Data protect, attempt to read invalid data */
scsi_build_sense_buffer(0, scmd->sense_buffer, scsi_build_sense(scmd, 0, DATA_PROTECT, 0x21, 0x06);
DATA_PROTECT, 0x21, 0x06);
scmd->result = (DRIVER_SENSE << 24) |
SAM_STAT_CHECK_CONDITION;
scmd->scsi_done(scmd); scmd->scsi_done(scmd);
return 0; return 0;
} }
@ -1569,9 +1544,7 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost,
break; break;
default: default:
/* Illegal request, invalid opcode */ /* Illegal request, invalid opcode */
scsi_build_sense_buffer(0, scmd->sense_buffer, scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x20, 0);
ILLEGAL_REQUEST, 0x20, 0);
scmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
scmd->scsi_done(scmd); scmd->scsi_done(scmd);
return 0; return 0;
} }
@ -2352,25 +2325,19 @@ static void myrb_handle_scsi(struct myrb_hba *cb, struct myrb_cmdblk *cmd_blk,
"Bad Data Encountered\n"); "Bad Data Encountered\n");
if (scmd->sc_data_direction == DMA_FROM_DEVICE) if (scmd->sc_data_direction == DMA_FROM_DEVICE)
/* Unrecovered read error */ /* Unrecovered read error */
scsi_build_sense_buffer(0, scmd->sense_buffer, scsi_build_sense(scmd, 0, MEDIUM_ERROR, 0x11, 0);
MEDIUM_ERROR, 0x11, 0);
else else
/* Write error */ /* Write error */
scsi_build_sense_buffer(0, scmd->sense_buffer, scsi_build_sense(scmd, 0, MEDIUM_ERROR, 0x0C, 0);
MEDIUM_ERROR, 0x0C, 0);
scmd->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
break; break;
case MYRB_STATUS_IRRECOVERABLE_DATA_ERROR: case MYRB_STATUS_IRRECOVERABLE_DATA_ERROR:
scmd_printk(KERN_ERR, scmd, "Irrecoverable Data Error\n"); scmd_printk(KERN_ERR, scmd, "Irrecoverable Data Error\n");
if (scmd->sc_data_direction == DMA_FROM_DEVICE) if (scmd->sc_data_direction == DMA_FROM_DEVICE)
/* Unrecovered read error, auto-reallocation failed */ /* Unrecovered read error, auto-reallocation failed */
scsi_build_sense_buffer(0, scmd->sense_buffer, scsi_build_sense(scmd, 0, MEDIUM_ERROR, 0x11, 0x04);
MEDIUM_ERROR, 0x11, 0x04);
else else
/* Write error, auto-reallocation failed */ /* Write error, auto-reallocation failed */
scsi_build_sense_buffer(0, scmd->sense_buffer, scsi_build_sense(scmd, 0, MEDIUM_ERROR, 0x0C, 0x02);
MEDIUM_ERROR, 0x0C, 0x02);
scmd->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
break; break;
case MYRB_STATUS_LDRV_NONEXISTENT_OR_OFFLINE: case MYRB_STATUS_LDRV_NONEXISTENT_OR_OFFLINE:
dev_dbg(&scmd->device->sdev_gendev, 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, dev_dbg(&scmd->device->sdev_gendev,
"Attempt to Access Beyond End of Logical Drive"); "Attempt to Access Beyond End of Logical Drive");
/* Logical block address out of range */ /* Logical block address out of range */
scsi_build_sense_buffer(0, scmd->sense_buffer, scsi_build_sense(scmd, 0, NOT_READY, 0x21, 0);
NOT_READY, 0x21, 0);
break; break;
case MYRB_STATUS_DEVICE_NONRESPONSIVE: case MYRB_STATUS_DEVICE_NONRESPONSIVE:
dev_dbg(&scmd->device->sdev_gendev, "Device nonresponsive\n"); dev_dbg(&scmd->device->sdev_gendev, "Device nonresponsive\n");

View File

@ -1600,9 +1600,7 @@ static int myrs_queuecommand(struct Scsi_Host *shost,
switch (scmd->cmnd[0]) { switch (scmd->cmnd[0]) {
case REPORT_LUNS: case REPORT_LUNS:
scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x20, 0x0);
0x20, 0x0);
scmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
scmd->scsi_done(scmd); scmd->scsi_done(scmd);
return 0; return 0;
case MODE_SENSE: case MODE_SENSE:
@ -1612,10 +1610,7 @@ static int myrs_queuecommand(struct Scsi_Host *shost,
if ((scmd->cmnd[2] & 0x3F) != 0x3F && if ((scmd->cmnd[2] & 0x3F) != 0x3F &&
(scmd->cmnd[2] & 0x3F) != 0x08) { (scmd->cmnd[2] & 0x3F) != 0x08) {
/* Illegal request, invalid field in CDB */ /* Illegal request, invalid field in CDB */
scsi_build_sense_buffer(0, scmd->sense_buffer, scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x24, 0);
ILLEGAL_REQUEST, 0x24, 0);
scmd->result = (DRIVER_SENSE << 24) |
SAM_STAT_CHECK_CONDITION;
} else { } else {
myrs_mode_sense(cs, scmd, ldev_info); myrs_mode_sense(cs, scmd, ldev_info);
scmd->result = (DID_OK << 16); scmd->result = (DID_OK << 16);

View File

@ -234,10 +234,8 @@ static int ps3rom_queuecommand_lck(struct scsi_cmnd *cmd,
} }
if (res) { if (res) {
memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); scsi_build_sense(cmd, 0, ILLEGAL_REQUEST, 0, 0);
cmd->result = res; cmd->result = res;
cmd->sense_buffer[0] = 0x70;
cmd->sense_buffer[2] = ILLEGAL_REQUEST;
priv->curr_cmd = NULL; priv->curr_cmd = NULL;
cmd->scsi_done(cmd); cmd->scsi_done(cmd);
} }
@ -319,8 +317,7 @@ static irqreturn_t ps3rom_interrupt(int irq, void *data)
goto done; goto done;
} }
scsi_build_sense_buffer(0, cmd->sense_buffer, sense_key, asc, ascq); scsi_build_sense(cmd, 0, sense_key, asc, ascq);
cmd->result = SAM_STAT_CHECK_CONDITION;
done: done:
priv->curr_cmd = NULL; priv->curr_cmd = NULL;

View File

@ -2694,31 +2694,22 @@ qla2x00_handle_dif_error(srb_t *sp, struct sts_entry_24xx *sts24)
/* check guard */ /* check guard */
if (e_guard != a_guard) { if (e_guard != a_guard) {
scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x1);
0x10, 0x1);
set_driver_byte(cmd, DRIVER_SENSE);
set_host_byte(cmd, DID_ABORT); set_host_byte(cmd, DID_ABORT);
cmd->result |= SAM_STAT_CHECK_CONDITION;
return 1; return 1;
} }
/* check ref tag */ /* check ref tag */
if (e_ref_tag != a_ref_tag) { if (e_ref_tag != a_ref_tag) {
scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x3);
0x10, 0x3);
set_driver_byte(cmd, DRIVER_SENSE);
set_host_byte(cmd, DID_ABORT); set_host_byte(cmd, DID_ABORT);
cmd->result |= SAM_STAT_CHECK_CONDITION;
return 1; return 1;
} }
/* check appl tag */ /* check appl tag */
if (e_app_tag != a_app_tag) { if (e_app_tag != a_app_tag) {
scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST, scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x2);
0x10, 0x2);
set_driver_byte(cmd, DRIVER_SENSE);
set_host_byte(cmd, DID_ABORT); set_host_byte(cmd, DID_ABORT);
cmd->result |= SAM_STAT_CHECK_CONDITION;
return 1; return 1;
} }

View File

@ -931,7 +931,7 @@ static void mk_sense_invalid_fld(struct scsi_cmnd *scp,
} }
asc = c_d ? INVALID_FIELD_IN_CDB : INVALID_FIELD_IN_PARAM_LIST; asc = c_d ? INVALID_FIELD_IN_CDB : INVALID_FIELD_IN_PARAM_LIST;
memset(sbuff, 0, SCSI_SENSE_BUFFERSIZE); memset(sbuff, 0, SCSI_SENSE_BUFFERSIZE);
scsi_build_sense_buffer(sdebug_dsense, sbuff, ILLEGAL_REQUEST, asc, 0); scsi_build_sense(scp, sdebug_dsense, ILLEGAL_REQUEST, asc, 0);
memset(sks, 0, sizeof(sks)); memset(sks, 0, sizeof(sks));
sks[0] = 0x80; sks[0] = 0x80;
if (c_d) if (c_d)
@ -957,17 +957,14 @@ static void mk_sense_invalid_fld(struct scsi_cmnd *scp,
static void mk_sense_buffer(struct scsi_cmnd *scp, int key, int asc, int asq) static void mk_sense_buffer(struct scsi_cmnd *scp, int key, int asc, int asq)
{ {
unsigned char *sbuff; if (!scp->sense_buffer) {
sbuff = scp->sense_buffer;
if (!sbuff) {
sdev_printk(KERN_ERR, scp->device, sdev_printk(KERN_ERR, scp->device,
"%s: sense_buffer is NULL\n", __func__); "%s: sense_buffer is NULL\n", __func__);
return; return;
} }
memset(sbuff, 0, SCSI_SENSE_BUFFERSIZE); memset(scp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
scsi_build_sense_buffer(sdebug_dsense, sbuff, key, asc, asq); scsi_build_sense(scp, sdebug_dsense, key, asc, asq);
if (sdebug_verbose) if (sdebug_verbose)
sdev_printk(KERN_INFO, scp->device, sdev_printk(KERN_INFO, scp->device,

View File

@ -3222,3 +3222,21 @@ int scsi_vpd_tpg_id(struct scsi_device *sdev, int *rel_id)
return group_id; return group_id;
} }
EXPORT_SYMBOL(scsi_vpd_tpg_id); EXPORT_SYMBOL(scsi_vpd_tpg_id);
/**
* scsi_build_sense - build sense data for a command
* @scmd: scsi command for which the sense should be formatted
* @desc: Sense format (non-zero == descriptor format,
* 0 == fixed format)
* @key: Sense key
* @asc: Additional sense code
* @ascq: Additional sense code qualifier
*
**/
void scsi_build_sense(struct scsi_cmnd *scmd, int desc, u8 key, u8 asc, u8 ascq)
{
scsi_build_sense_buffer(desc, scmd->sense_buffer, key, asc, ascq);
scmd->result = (DRIVER_SENSE << 24) | (DID_OK << 16) |
SAM_STAT_CHECK_CONDITION;
}
EXPORT_SYMBOL_GPL(scsi_build_sense);

View File

@ -3087,8 +3087,7 @@ static void pqi_process_aio_io_error(struct pqi_io_request *io_request)
} }
if (device_offline && sense_data_length == 0) if (device_offline && sense_data_length == 0)
scsi_build_sense_buffer(0, scmd->sense_buffer, HARDWARE_ERROR, scsi_build_sense(scmd, 0, HARDWARE_ERROR, 0x3e, 0x1);
0x3e, 0x1);
scmd->result = scsi_status; scmd->result = scsi_status;
set_host_byte(scmd, host_byte); set_host_byte(scmd, host_byte);

View File

@ -398,11 +398,8 @@ static struct status_msg *stex_get_status(struct st_hba *hba)
static void stex_invalid_field(struct scsi_cmnd *cmd, static void stex_invalid_field(struct scsi_cmnd *cmd,
void (*done)(struct scsi_cmnd *)) void (*done)(struct scsi_cmnd *))
{ {
cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
/* "Invalid field in cdb" */ /* "Invalid field in cdb" */
scsi_build_sense_buffer(0, cmd->sense_buffer, ILLEGAL_REQUEST, 0x24, scsi_build_sense(cmd, 0, ILLEGAL_REQUEST, 0x24, 0x0);
0x0);
done(cmd); done(cmd);
} }

View File

@ -341,4 +341,7 @@ static inline unsigned scsi_transfer_length(struct scsi_cmnd *scmd)
return xfer_len; return xfer_len;
} }
extern void scsi_build_sense(struct scsi_cmnd *scmd, int desc,
u8 key, u8 asc, u8 ascq);
#endif /* _SCSI_SCSI_CMND_H */ #endif /* _SCSI_SCSI_CMND_H */