From 464a00c9e0ad45e3f42ff6ea705491a356df818e Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Tue, 27 Apr 2021 10:30:15 +0200 Subject: scsi: core: Kill DRIVER_SENSE Replace the check for DRIVER_SENSE with a check for scsi_status_is_check_condition(). Audit all callsites to ensure the SAM status is set correctly. For backwards compability move the DRIVER_SENSE definition to sg.h, and update sg, bsg, and scsi_ioctl to set the DRIVER_SENSE driver_status whenever SAM_STAT_CHECK_CONDITION is present. [mkp: fix zeroday srp warning] Link: https://lore.kernel.org/r/20210427083046.31620-10-hare@suse.de Signed-off-by: Hannes Reinecke Signed-off-by: Martin K. Petersen fix --- drivers/xen/xen-scsiback.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers/xen') diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c index 55a4763da05e..3ec038cd4332 100644 --- a/drivers/xen/xen-scsiback.c +++ b/drivers/xen/xen-scsiback.c @@ -1401,8 +1401,7 @@ static int scsiback_queue_status(struct se_cmd *se_cmd) if (se_cmd->sense_buffer && ((se_cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) || (se_cmd->se_cmd_flags & SCF_EMULATED_TASK_SENSE))) - pending_req->result = (DRIVER_SENSE << 24) | - SAM_STAT_CHECK_CONDITION; + pending_req->result = SAM_STAT_CHECK_CONDITION; else pending_req->result = se_cmd->scsi_status; -- cgit v1.2.3 From 58bedf351f3eace10447b5e1f70b9079ab4d04d2 Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Tue, 27 Apr 2021 10:30:18 +0200 Subject: scsi: xen-scsiback: Use DID_ERROR instead of DRIVER_ERROR DRIVER_ERROR was supposed to signal an error generated by the driver, which xen-scsiback arguably isn't. Also the driver bytes don't have a detailed error recovery, so we should rather return DID_ERROR instead of DRIVER_ERROR. Link: https://lore.kernel.org/r/20210427083046.31620-13-hare@suse.de Reviewed-by: Bart Van Assche Reviewed-by: Christoph Hellwig Signed-off-by: Hannes Reinecke Signed-off-by: Martin K. Petersen --- drivers/xen/xen-scsiback.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/xen') diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c index 3ec038cd4332..b7f0ff80efe2 100644 --- a/drivers/xen/xen-scsiback.c +++ b/drivers/xen/xen-scsiback.c @@ -719,10 +719,10 @@ static int scsiback_do_cmd_fn(struct vscsibk_info *info, result = DID_NO_CONNECT; break; default: - result = DRIVER_ERROR; + result = DID_ERROR; break; } - scsiback_send_response(info, NULL, result << 24, 0, + scsiback_send_response(info, NULL, result << 16, 0, ring_req.rqid); return 1; } @@ -732,7 +732,7 @@ static int scsiback_do_cmd_fn(struct vscsibk_info *info, if (scsiback_gnttab_data_map(&ring_req, pending_req)) { scsiback_fast_flush_area(pending_req); scsiback_do_resp_with_sense(NULL, - DRIVER_ERROR << 24, 0, pending_req); + DID_ERROR << 16, 0, pending_req); transport_generic_free_cmd(&pending_req->se_cmd, 0); } else { scsiback_cmd_exec(pending_req); @@ -747,7 +747,7 @@ static int scsiback_do_cmd_fn(struct vscsibk_info *info, break; default: pr_err_ratelimited("invalid request\n"); - scsiback_do_resp_with_sense(NULL, DRIVER_ERROR << 24, 0, + scsiback_do_resp_with_sense(NULL, DID_ERROR << 16, 0, pending_req); transport_generic_free_cmd(&pending_req->se_cmd, 0); break; -- cgit v1.2.3 From 54c29086195fd72b6a290ef367e71f73fa657b1f Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Tue, 27 Apr 2021 10:30:20 +0200 Subject: scsi: core: Drop the now obsolete driver_byte definitions The driver_byte field in the result is now unused, so we can drop the definitions. Link: https://lore.kernel.org/r/20210427083046.31620-15-hare@suse.de Reviewed-by: Bart Van Assche Reviewed-by: Christoph Hellwig Signed-off-by: Hannes Reinecke Signed-off-by: Martin K. Petersen --- Documentation/scsi/scsi_mid_low_api.rst | 3 +-- block/bsg-lib.c | 2 +- block/bsg.c | 2 +- block/scsi_ioctl.c | 2 +- drivers/scsi/constants.c | 15 --------------- drivers/scsi/scsi_logging.c | 10 ++-------- drivers/scsi/sd.c | 9 ++++----- drivers/scsi/sr.c | 2 +- drivers/scsi/sr_ioctl.c | 2 +- drivers/scsi/st.c | 4 ++-- drivers/xen/xen-scsiback.c | 4 ++-- include/scsi/scsi.h | 16 ---------------- include/scsi/scsi_cmnd.h | 4 ---- include/scsi/sg.h | 2 ++ include/trace/events/scsi.h | 15 +-------------- 15 files changed, 19 insertions(+), 73 deletions(-) (limited to 'drivers/xen') diff --git a/Documentation/scsi/scsi_mid_low_api.rst b/Documentation/scsi/scsi_mid_low_api.rst index 096ffe9cae0e..b99b4e418ba9 100644 --- a/Documentation/scsi/scsi_mid_low_api.rst +++ b/Documentation/scsi/scsi_mid_low_api.rst @@ -1174,8 +1174,7 @@ Members of interest: target device). 'result' is a 32 bit unsigned integer that can be viewed as 4 related bytes. The SCSI status value is in the LSB. See include/scsi/scsi.h status_byte(), - msg_byte(), host_byte() and driver_byte() macros and - related constants. + msg_byte() and host_byte() macros and related constants. sense_buffer - an array (maximum size: SCSI_SENSE_BUFFERSIZE bytes) that should be written when the SCSI status (LSB of 'result') diff --git a/block/bsg-lib.c b/block/bsg-lib.c index 330fede77271..cf1811261722 100644 --- a/block/bsg-lib.c +++ b/block/bsg-lib.c @@ -84,7 +84,7 @@ static int bsg_transport_complete_rq(struct request *rq, struct sg_io_v4 *hdr) */ hdr->device_status = job->result & 0xff; hdr->transport_status = host_byte(job->result); - hdr->driver_status = driver_byte(job->result); + hdr->driver_status = 0; hdr->info = 0; if (hdr->device_status || hdr->transport_status || hdr->driver_status) hdr->info |= SG_INFO_CHECK; diff --git a/block/bsg.c b/block/bsg.c index 9e6ff0d71d25..33e3f82ed03a 100644 --- a/block/bsg.c +++ b/block/bsg.c @@ -96,7 +96,7 @@ static int bsg_scsi_complete_rq(struct request *rq, struct sg_io_v4 *hdr) */ hdr->device_status = sreq->result & 0xff; hdr->transport_status = host_byte(sreq->result); - hdr->driver_status = driver_byte(sreq->result); + hdr->driver_status = 0; if (scsi_status_is_check_condition(sreq->result)) hdr->driver_status = DRIVER_SENSE; hdr->info = 0; diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c index eb65bcde166f..3a9c071b3799 100644 --- a/block/scsi_ioctl.c +++ b/block/scsi_ioctl.c @@ -256,7 +256,7 @@ static int blk_complete_sghdr_rq(struct request *rq, struct sg_io_hdr *hdr, hdr->masked_status = status_byte(req->result); hdr->msg_status = msg_byte(req->result); hdr->host_status = host_byte(req->result); - hdr->driver_status = driver_byte(req->result); + hdr->driver_status = 0; if (scsi_status_is_check_condition(hdr->status)) hdr->driver_status = DRIVER_SENSE; hdr->info = 0; diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c index 84d73f57292b..41bcfed08260 100644 --- a/drivers/scsi/constants.c +++ b/drivers/scsi/constants.c @@ -406,10 +406,6 @@ static const char * const hostbyte_table[]={ "DID_TRANSPORT_DISRUPTED", "DID_TRANSPORT_FAILFAST", "DID_TARGET_FAILURE", "DID_NEXUS_FAILURE", "DID_ALLOC_FAILURE", "DID_MEDIUM_ERROR" }; -static const char * const driverbyte_table[]={ -"DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT", "DRIVER_MEDIA", "DRIVER_ERROR", -"DRIVER_INVALID", "DRIVER_TIMEOUT", "DRIVER_HARD", "DRIVER_SENSE"}; - const char *scsi_hostbyte_string(int result) { const char *hb_string = NULL; @@ -421,17 +417,6 @@ const char *scsi_hostbyte_string(int result) } EXPORT_SYMBOL(scsi_hostbyte_string); -const char *scsi_driverbyte_string(int result) -{ - const char *db_string = NULL; - int db = driver_byte(result); - - if (db < ARRAY_SIZE(driverbyte_table)) - db_string = driverbyte_table[db]; - return db_string; -} -EXPORT_SYMBOL(scsi_driverbyte_string); - #define scsi_mlreturn_name(result) { result, #result } static const struct value_name_pair scsi_mlreturn_arr[] = { scsi_mlreturn_name(NEEDS_RETRY), diff --git a/drivers/scsi/scsi_logging.c b/drivers/scsi/scsi_logging.c index 8ea44c6595ef..2317717935e9 100644 --- a/drivers/scsi/scsi_logging.c +++ b/drivers/scsi/scsi_logging.c @@ -385,7 +385,6 @@ void scsi_print_result(const struct scsi_cmnd *cmd, const char *msg, size_t off, logbuf_len; const char *mlret_string = scsi_mlreturn_string(disposition); const char *hb_string = scsi_hostbyte_string(cmd->result); - const char *db_string = scsi_driverbyte_string(cmd->result); unsigned long cmd_age = (jiffies - cmd->jiffies_at_alloc) / HZ; logbuf = scsi_log_reserve_buffer(&logbuf_len); @@ -426,13 +425,8 @@ void scsi_print_result(const struct scsi_cmnd *cmd, const char *msg, if (WARN_ON(off >= logbuf_len)) goto out_printk; - if (db_string) - off += scnprintf(logbuf + off, logbuf_len - off, - "driverbyte=%s ", db_string); - else - off += scnprintf(logbuf + off, logbuf_len - off, - "driverbyte=0x%02x ", - driver_byte(cmd->result)); + off += scnprintf(logbuf + off, logbuf_len - off, + "driverbyte=DRIVER_OK "); off += scnprintf(logbuf + off, logbuf_len - off, "cmd_age=%lus", cmd_age); diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 66cb161667af..20739072f21a 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3810,15 +3810,14 @@ void sd_print_sense_hdr(struct scsi_disk *sdkp, struct scsi_sense_hdr *sshdr) void sd_print_result(const struct scsi_disk *sdkp, const char *msg, int result) { const char *hb_string = scsi_hostbyte_string(result); - const char *db_string = scsi_driverbyte_string(result); - if (hb_string || db_string) + if (hb_string) sd_printk(KERN_INFO, sdkp, "%s: Result: hostbyte=%s driverbyte=%s\n", msg, hb_string ? hb_string : "invalid", - db_string ? db_string : "invalid"); + "DRIVER_OK"); else sd_printk(KERN_INFO, sdkp, - "%s: Result: hostbyte=0x%02x driverbyte=0x%02x\n", - msg, host_byte(result), driver_byte(result)); + "%s: Result: hostbyte=0x%02x driverbyte=%s\n", + msg, host_byte(result), "DRIVER_OK"); } diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index 9b2ccf0c9a8c..e9cb874f6891 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -338,7 +338,7 @@ static int sr_done(struct scsi_cmnd *SCpnt) * care is taken to avoid unnecessary additional work such as * memcpy's that could be avoided. */ - if (driver_byte(result) != 0 && /* An error occurred */ + if (status_byte(result) == SAM_STAT_CHECK_CONDITION && (SCpnt->sense_buffer[0] & 0x7f) == 0x70) { /* Sense current */ switch (SCpnt->sense_buffer[2]) { case MEDIUM_ERROR: diff --git a/drivers/scsi/sr_ioctl.c b/drivers/scsi/sr_ioctl.c index 0d6a716d281e..93c77dd9a476 100644 --- a/drivers/scsi/sr_ioctl.c +++ b/drivers/scsi/sr_ioctl.c @@ -205,7 +205,7 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc) err = result; goto out; } - if (driver_byte(result) != 0) { + if (status_byte(result) == SAM_STAT_CHECK_CONDITION) { switch (sshdr->sense_key) { case UNIT_ATTENTION: SDev->changed = 1; diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c index 5d840bc69639..66f48bd6da76 100644 --- a/drivers/scsi/st.c +++ b/drivers/scsi/st.c @@ -390,8 +390,8 @@ static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt) if (!debugging) { /* Abnormal conditions for tape */ if (!cmdstatp->have_sense) st_printk(KERN_WARNING, STp, - "Error %x (driver bt 0x%x, host bt 0x%x).\n", - result, driver_byte(result), host_byte(result)); + "Error %x (driver bt 0, host bt 0x%x).\n", + result, host_byte(result)); else if (cmdstatp->have_sense && scode != NO_SENSE && scode != RECOVERED_ERROR && diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c index b7f0ff80efe2..a6bb2600a2d7 100644 --- a/drivers/xen/xen-scsiback.c +++ b/drivers/xen/xen-scsiback.c @@ -222,10 +222,10 @@ static void scsiback_print_status(char *sense_buffer, int errors, { struct scsiback_tpg *tpg = pending_req->v2p->tpg; - pr_err("[%s:%d] cmnd[0]=%02x -> st=%02x msg=%02x host=%02x drv=%02x\n", + pr_err("[%s:%d] cmnd[0]=%02x -> st=%02x msg=%02x host=%02x\n", tpg->tport->tport_name, pending_req->v2p->lun, pending_req->cmnd[0], status_byte(errors), msg_byte(errors), - host_byte(errors), driver_byte(errors)); + host_byte(errors)); } static void scsiback_fast_flush_area(struct vscsibk_pend *req) diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h index 57f0ca00ddda..bd8eb6033bf4 100644 --- a/include/scsi/scsi.h +++ b/include/scsi/scsi.h @@ -152,20 +152,6 @@ static inline int scsi_status_is_check_condition(int status) #define DID_TRANSPORT_MARGINAL 0x14 /* Transport marginal errors */ #define DRIVER_OK 0x00 /* Driver status */ -/* - * These indicate the error that occurred, and what is available. - */ - -#define DRIVER_BUSY 0x01 -#define DRIVER_SOFT 0x02 -#define DRIVER_MEDIA 0x03 -#define DRIVER_ERROR 0x04 - -#define DRIVER_INVALID 0x05 -#define DRIVER_TIMEOUT 0x06 -#define DRIVER_HARD 0x07 -#define DRIVER_SENSE 0x08 - /* * Internal return values. */ @@ -197,12 +183,10 @@ enum scsi_disposition { * status byte = set from target device * msg_byte = return status from host adapter itself. * host_byte = set by low-level driver to indicate status. - * driver_byte = set by mid-level. */ #define status_byte(result) (((result) >> 1) & 0x7f) #define msg_byte(result) (((result) >> 8) & 0xff) #define host_byte(result) (((result) >> 16) & 0xff) -#define driver_byte(result) (((result) >> 24) & 0xff) #define sense_class(sense) (((sense) >> 4) & 0x7) #define sense_error(sense) ((sense) & 0xf) diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h index 4e2a8f2a3045..e7986b9babaf 100644 --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h @@ -325,10 +325,6 @@ static inline void set_host_byte(struct scsi_cmnd *cmd, char status) cmd->result = (cmd->result & 0xff00ffff) | (status << 16); } -static inline void set_driver_byte(struct scsi_cmnd *cmd, char status) -{ - cmd->result = (cmd->result & 0x00ffffff) | (status << 24); -} static inline unsigned scsi_transfer_length(struct scsi_cmnd *scmd) { diff --git a/include/scsi/sg.h b/include/scsi/sg.h index d5c17775c3b4..e9dd5477ca7a 100644 --- a/include/scsi/sg.h +++ b/include/scsi/sg.h @@ -142,6 +142,8 @@ struct compat_sg_io_hdr { * keep setting this byte to be compatible with previous releases. */ #define DRIVER_SENSE 0x08 +/* Obsolete driver_byte() declaration */ +#define driver_byte(result) (((result) >> 24) & 0xff) typedef struct sg_scsi_id { /* used by SG_GET_SCSI_ID ioctl() */ int host_no; /* as in "scsi" where 'n' is one of 0, 1, 2 etc */ diff --git a/include/trace/events/scsi.h b/include/trace/events/scsi.h index f624969a4f14..428cca71c2ba 100644 --- a/include/trace/events/scsi.h +++ b/include/trace/events/scsi.h @@ -124,19 +124,6 @@ scsi_hostbyte_name(DID_TRANSPORT_DISRUPTED), \ scsi_hostbyte_name(DID_TRANSPORT_FAILFAST)) -#define scsi_driverbyte_name(result) { result, #result } -#define show_driverbyte_name(val) \ - __print_symbolic(val, \ - scsi_driverbyte_name(DRIVER_OK), \ - scsi_driverbyte_name(DRIVER_BUSY), \ - scsi_driverbyte_name(DRIVER_SOFT), \ - scsi_driverbyte_name(DRIVER_MEDIA), \ - scsi_driverbyte_name(DRIVER_ERROR), \ - scsi_driverbyte_name(DRIVER_INVALID), \ - scsi_driverbyte_name(DRIVER_TIMEOUT), \ - scsi_driverbyte_name(DRIVER_HARD), \ - scsi_driverbyte_name(DRIVER_SENSE)) - #define scsi_msgbyte_name(result) { result, #result } #define show_msgbyte_name(val) \ __print_symbolic(val, \ @@ -327,7 +314,7 @@ DECLARE_EVENT_CLASS(scsi_cmd_done_timeout_template, show_opcode_name(__entry->opcode), __parse_cdb(__get_dynamic_array(cmnd), __entry->cmd_len), __print_hex(__get_dynamic_array(cmnd), __entry->cmd_len), - show_driverbyte_name(((__entry->result) >> 24) & 0xff), + "DRIVER_OK", show_hostbyte_name(((__entry->result) >> 16) & 0xff), show_msgbyte_name(((__entry->result) >> 8) & 0xff), show_statusbyte_name(__entry->result & 0xff)) -- cgit v1.2.3 From 54cf31d07aa859e142c527f04eefa254659e1af2 Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Tue, 27 Apr 2021 10:30:43 +0200 Subject: scsi: core: Drop message byte helper The message byte is now unused, so we can drop the helper to set the message byte and the check for message bytes during error recovery. Link: https://lore.kernel.org/r/20210427083046.31620-38-hare@suse.de Reviewed-by: Bart Van Assche Signed-off-by: Hannes Reinecke Signed-off-by: Martin K. Petersen --- block/scsi_ioctl.c | 2 +- drivers/scsi/scsi_error.c | 18 ++---------------- drivers/scsi/sg.c | 2 +- drivers/xen/xen-scsiback.c | 2 +- include/scsi/scsi.h | 3 +-- include/scsi/scsi_cmnd.h | 5 ----- 6 files changed, 6 insertions(+), 26 deletions(-) (limited to 'drivers/xen') diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c index 3a9c071b3799..fa6df11b8bdd 100644 --- a/block/scsi_ioctl.c +++ b/block/scsi_ioctl.c @@ -254,7 +254,7 @@ static int blk_complete_sghdr_rq(struct request *rq, struct sg_io_hdr *hdr, */ hdr->status = req->result & 0xff; hdr->masked_status = status_byte(req->result); - hdr->msg_status = msg_byte(req->result); + hdr->msg_status = COMMAND_COMPLETE; hdr->host_status = host_byte(req->result); hdr->driver_status = 0; if (scsi_status_is_check_condition(hdr->status)) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 689ee628eff9..3e6e456816fc 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -741,12 +741,6 @@ static enum scsi_disposition scsi_eh_completed_normally(struct scsi_cmnd *scmd) if (host_byte(scmd->result) != DID_OK) return FAILED; - /* - * next, check the message byte. - */ - if (msg_byte(scmd->result) != COMMAND_COMPLETE) - return FAILED; - /* * now, check the status byte to see if this indicates * anything special. @@ -1766,8 +1760,7 @@ int scsi_noretry_cmd(struct scsi_cmnd *scmd) case DID_PARITY: return (scmd->request->cmd_flags & REQ_FAILFAST_DEV); case DID_ERROR: - if (msg_byte(scmd->result) == COMMAND_COMPLETE && - status_byte(scmd->result) == RESERVATION_CONFLICT) + if (status_byte(scmd->result) == RESERVATION_CONFLICT) return 0; fallthrough; case DID_SOFT_ERROR: @@ -1883,8 +1876,7 @@ enum scsi_disposition scsi_decide_disposition(struct scsi_cmnd *scmd) */ return SUCCESS; case DID_ERROR: - if (msg_byte(scmd->result) == COMMAND_COMPLETE && - status_byte(scmd->result) == RESERVATION_CONFLICT) + if (status_byte(scmd->result) == RESERVATION_CONFLICT) /* * execute reservation conflict processing code * lower down @@ -1912,12 +1904,6 @@ enum scsi_disposition scsi_decide_disposition(struct scsi_cmnd *scmd) return FAILED; } - /* - * next, check the message byte. - */ - if (msg_byte(scmd->result) != COMMAND_COMPLETE) - return FAILED; - /* * check the status byte to see if this indicates anything special. */ diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index faf7716c8851..4e66994be190 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -1376,7 +1376,7 @@ sg_rq_end_io(struct request *rq, blk_status_t status) srp->header.status = 0xff & result; srp->header.masked_status = status_byte(result); - srp->header.msg_status = msg_byte(result); + srp->header.msg_status = COMMAND_COMPLETE; srp->header.host_status = host_byte(result); srp->header.driver_status = driver_byte(result); if ((sdp->sgdebug > 0) && diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c index a6bb2600a2d7..bea22f71c782 100644 --- a/drivers/xen/xen-scsiback.c +++ b/drivers/xen/xen-scsiback.c @@ -224,7 +224,7 @@ static void scsiback_print_status(char *sense_buffer, int errors, pr_err("[%s:%d] cmnd[0]=%02x -> st=%02x msg=%02x host=%02x\n", tpg->tport->tport_name, pending_req->v2p->lun, - pending_req->cmnd[0], status_byte(errors), msg_byte(errors), + pending_req->cmnd[0], status_byte(errors), COMMAND_COMPLETE, host_byte(errors)); } diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h index bd8eb6033bf4..f4fb7e7728b4 100644 --- a/include/scsi/scsi.h +++ b/include/scsi/scsi.h @@ -181,11 +181,10 @@ enum scsi_disposition { * These are set by: * * status byte = set from target device - * msg_byte = return status from host adapter itself. + * msg_byte (unused) * host_byte = set by low-level driver to indicate status. */ #define status_byte(result) (((result) >> 1) & 0x7f) -#define msg_byte(result) (((result) >> 8) & 0xff) #define host_byte(result) (((result) >> 16) & 0xff) #define sense_class(sense) (((sense) >> 4) & 0x7) diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h index efcf33c29efa..779a59fe8676 100644 --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h @@ -320,11 +320,6 @@ static inline u8 get_status_byte(struct scsi_cmnd *cmd) return cmd->result & 0xff; } -static inline void set_msg_byte(struct scsi_cmnd *cmd, char status) -{ - cmd->result = (cmd->result & 0xffff00ff) | (status << 8); -} - static inline void set_host_byte(struct scsi_cmnd *cmd, char status) { cmd->result = (cmd->result & 0xff00ffff) | (status << 16); -- cgit v1.2.3 From 3d45cefc8edd7f560e6c97a8d9928ad571f76dec Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Tue, 27 Apr 2021 10:30:46 +0200 Subject: scsi: core: Drop obsolete Linux-specific SCSI status codes Originally the SCSI subsystem has been using 'special' SCSI status codes, which were the SAM-specified ones but shifted by 1. As most drivers have now been modified to use the SAM-specified ones, having two nearly identical sets of definitions only causes confusion. The Linux-specifed SCSI status codes have been marked obsolete for several years so drop them and use the SAM-specified status codes throughout. Link: https://lore.kernel.org/r/20210427083046.31620-41-hare@suse.de Reviewed-by: Bart Van Assche Reviewed-by: Douglas Gilbert Signed-off-by: Hannes Reinecke Signed-off-by: Martin K. Petersen --- drivers/ata/libata-scsi.c | 2 +- drivers/infiniband/ulp/srp/ib_srp.c | 2 +- drivers/scsi/3w-9xxx.c | 2 +- drivers/scsi/3w-xxxx.c | 4 +-- drivers/scsi/53c700.c | 6 ++--- drivers/scsi/NCR5380.c | 2 +- drivers/scsi/arcmsr/arcmsr_hba.c | 4 +-- drivers/scsi/esas2r/esas2r_main.c | 2 +- drivers/scsi/megaraid.c | 4 +-- drivers/scsi/megaraid/megaraid_mbox.c | 4 +-- drivers/scsi/scsi_error.c | 48 +++++++++++++++++------------------ drivers/scsi/scsi_lib.c | 2 +- drivers/scsi/sr.c | 2 +- drivers/scsi/sr_ioctl.c | 2 +- drivers/xen/xen-scsiback.c | 2 +- include/scsi/scsi.h | 1 - include/scsi/scsi_proto.h | 22 +--------------- include/scsi/sg.h | 20 +++++++++++++++ 18 files changed, 65 insertions(+), 66 deletions(-) (limited to 'drivers/xen') diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 31b47ad073ad..b9588c52815d 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -642,7 +642,7 @@ static struct ata_queued_cmd *ata_scsi_qc_new(struct ata_device *dev, if (cmd->request->rq_flags & RQF_QUIET) qc->flags |= ATA_QCFLAG_QUIET; } else { - cmd->result = (DID_OK << 16) | (QUEUE_FULL << 1); + cmd->result = (DID_OK << 16) | SAM_STAT_TASK_SET_FULL; cmd->scsi_done(cmd); } diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c index 31f8aa2c40ed..62d9b70f7c63 100644 --- a/drivers/infiniband/ulp/srp/ib_srp.c +++ b/drivers/infiniband/ulp/srp/ib_srp.c @@ -2232,7 +2232,7 @@ static int srp_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd) * to reduce queue depth temporarily. */ scmnd->result = len == -ENOMEM ? - DID_OK << 16 | QUEUE_FULL << 1 : DID_ERROR << 16; + DID_OK << 16 | SAM_STAT_TASK_SET_FULL : DID_ERROR << 16; goto err_iu; } diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c index 2b4b629a6e96..e41cc354cc8a 100644 --- a/drivers/scsi/3w-9xxx.c +++ b/drivers/scsi/3w-9xxx.c @@ -1338,7 +1338,7 @@ static irqreturn_t twa_interrupt(int irq, void *dev_instance) /* If error, command failed */ if (error == 1) { /* Ask for a host reset */ - cmd->result = (DID_OK << 16) | (CHECK_CONDITION << 1); + cmd->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION; } /* Report residual bytes for single sgl */ diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c index 7a0b4a44395d..4ee485ab2714 100644 --- a/drivers/scsi/3w-xxxx.c +++ b/drivers/scsi/3w-xxxx.c @@ -429,7 +429,7 @@ static int tw_decode_sense(TW_Device_Extension *tw_dev, int request_id, int fill /* Additional sense code qualifier */ tw_dev->srb[request_id]->sense_buffer[13] = tw_sense_table[i][3]; - tw_dev->srb[request_id]->result = (DID_OK << 16) | (CHECK_CONDITION << 1); + tw_dev->srb[request_id]->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION; return TW_ISR_DONT_RESULT; /* Special case for isr to not over-write result */ } } @@ -2159,7 +2159,7 @@ static irqreturn_t tw_interrupt(int irq, void *dev_instance) /* If error, command failed */ if (error == 1) { /* Ask for a host reset */ - tw_dev->srb[request_id]->result = (DID_OK << 16) | (CHECK_CONDITION << 1); + tw_dev->srb[request_id]->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION; } /* Now complete the io */ diff --git a/drivers/scsi/53c700.c b/drivers/scsi/53c700.c index 77ccb96e5ed4..1c6b4e672687 100644 --- a/drivers/scsi/53c700.c +++ b/drivers/scsi/53c700.c @@ -978,10 +978,10 @@ process_script_interrupt(__u32 dsps, __u32 dsp, struct scsi_cmnd *SCp, if (NCR_700_get_tag_neg_state(SCp->device) == NCR_700_DURING_TAG_NEGOTIATION) NCR_700_set_tag_neg_state(SCp->device, NCR_700_FINISHED_TAG_NEGOTIATION); - + /* check for contingent allegiance conditions */ - if (hostdata->status[0] >> 1 == CHECK_CONDITION || - hostdata->status[0] >> 1 == COMMAND_TERMINATED) { + if (hostdata->status[0] == SAM_STAT_CHECK_CONDITION || + hostdata->status[0] == SAM_STAT_COMMAND_TERMINATED) { struct NCR_700_command_slot *slot = (struct NCR_700_command_slot *)SCp->host_scribble; if(slot->flags == NCR_700_FLAG_AUTOSENSE) { diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c index a74674941e7d..8aa964cd54df 100644 --- a/drivers/scsi/NCR5380.c +++ b/drivers/scsi/NCR5380.c @@ -538,7 +538,7 @@ static void complete_cmd(struct Scsi_Host *instance, if (hostdata->sensing == cmd) { /* Autosense processing ends here */ - if (status_byte(cmd->result) != GOOD) { + if (get_status_byte(cmd) != SAM_STAT_GOOD) { scsi_eh_restore_cmnd(cmd, &hostdata->ses); } else { scsi_eh_restore_cmnd(cmd, &hostdata->ses); diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c index c01a5b2ff67a..e5149c9fd4e6 100644 --- a/drivers/scsi/arcmsr/arcmsr_hba.c +++ b/drivers/scsi/arcmsr/arcmsr_hba.c @@ -1326,7 +1326,7 @@ static void arcmsr_report_sense_info(struct CommandControlBlock *ccb) struct scsi_cmnd *pcmd = ccb->pcmd; struct SENSE_DATA *sensebuffer = (struct SENSE_DATA *)pcmd->sense_buffer; - pcmd->result = (DID_OK << 16) | (CHECK_CONDITION << 1); + pcmd->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION; if (sensebuffer) { int sense_data_length = sizeof(struct SENSE_DATA) < SCSI_SENSE_BUFFERSIZE @@ -3253,7 +3253,7 @@ static int arcmsr_queue_command_lck(struct scsi_cmnd *cmd, if (!ccb) return SCSI_MLQUEUE_HOST_BUSY; if (arcmsr_build_ccb( acb, ccb, cmd ) == FAILED) { - cmd->result = (DID_ERROR << 16) | (RESERVATION_CONFLICT << 1); + cmd->result = (DID_ERROR << 16) | SAM_STAT_RESERVATION_CONFLICT; cmd->scsi_done(cmd); return 0; } diff --git a/drivers/scsi/esas2r/esas2r_main.c b/drivers/scsi/esas2r/esas2r_main.c index 45ec9f16c085..647f82898b6e 100644 --- a/drivers/scsi/esas2r/esas2r_main.c +++ b/drivers/scsi/esas2r/esas2r_main.c @@ -1525,7 +1525,7 @@ void esas2r_complete_request_cb(struct esas2r_adapter *a, rq->cmd->result = ((esas2r_req_status_to_error(rq->req_stat) << 16) - | (rq->func_rsp.scsi_rsp.scsi_stat & STATUS_MASK)); + | rq->func_rsp.scsi_rsp.scsi_stat); if (rq->req_stat == RS_UNDERRUN) scsi_set_resid(rq->cmd, diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c index 1880471c632a..56910e94dbf2 100644 --- a/drivers/scsi/megaraid.c +++ b/drivers/scsi/megaraid.c @@ -1611,7 +1611,7 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status) */ if( cmd->cmnd[0] == TEST_UNIT_READY ) { cmd->result |= (DID_ERROR << 16) | - (RESERVATION_CONFLICT << 1); + SAM_STAT_RESERVATION_CONFLICT; } else /* @@ -1623,7 +1623,7 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status) cmd->cmnd[0] == RELEASE) ) { cmd->result |= (DID_ERROR << 16) | - (RESERVATION_CONFLICT << 1); + SAM_STAT_RESERVATION_CONFLICT; } else #endif diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c index bb8b2fba4b3d..d3fac99db786 100644 --- a/drivers/scsi/megaraid/megaraid_mbox.c +++ b/drivers/scsi/megaraid/megaraid_mbox.c @@ -2327,7 +2327,7 @@ megaraid_mbox_dpc(unsigned long devp) */ if (scp->cmnd[0] == TEST_UNIT_READY) { scp->result = DID_ERROR << 16 | - RESERVATION_CONFLICT << 1; + SAM_STAT_RESERVATION_CONFLICT; } else /* @@ -2338,7 +2338,7 @@ megaraid_mbox_dpc(unsigned long devp) scp->cmnd[0] == RELEASE)) { scp->result = DID_ERROR << 16 | - RESERVATION_CONFLICT << 1; + SAM_STAT_RESERVATION_CONFLICT; } else { scp->result = DID_BAD_TARGET << 16 | status; diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 3e6e456816fc..c6cd5a8e5c85 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -745,32 +745,32 @@ static enum scsi_disposition scsi_eh_completed_normally(struct scsi_cmnd *scmd) * now, check the status byte to see if this indicates * anything special. */ - switch (status_byte(scmd->result)) { - case GOOD: + switch (get_status_byte(scmd)) { + case SAM_STAT_GOOD: scsi_handle_queue_ramp_up(scmd->device); fallthrough; - case COMMAND_TERMINATED: + case SAM_STAT_COMMAND_TERMINATED: return SUCCESS; - case CHECK_CONDITION: + case SAM_STAT_CHECK_CONDITION: return scsi_check_sense(scmd); - case CONDITION_GOOD: - case INTERMEDIATE_GOOD: - case INTERMEDIATE_C_GOOD: + case SAM_STAT_CONDITION_MET: + case SAM_STAT_INTERMEDIATE: + case SAM_STAT_INTERMEDIATE_CONDITION_MET: /* * who knows? FIXME(eric) */ return SUCCESS; - case RESERVATION_CONFLICT: + case SAM_STAT_RESERVATION_CONFLICT: if (scmd->cmnd[0] == TEST_UNIT_READY) /* it is a success, we probed the device and * found it */ return SUCCESS; /* otherwise, we failed to send the command */ return FAILED; - case QUEUE_FULL: + case SAM_STAT_TASK_SET_FULL: scsi_handle_queue_full(scmd->device); fallthrough; - case BUSY: + case SAM_STAT_BUSY: return NEEDS_RETRY; default: return FAILED; @@ -1760,7 +1760,7 @@ int scsi_noretry_cmd(struct scsi_cmnd *scmd) case DID_PARITY: return (scmd->request->cmd_flags & REQ_FAILFAST_DEV); case DID_ERROR: - if (status_byte(scmd->result) == RESERVATION_CONFLICT) + if (get_status_byte(scmd) == SAM_STAT_RESERVATION_CONFLICT) return 0; fallthrough; case DID_SOFT_ERROR: @@ -1876,7 +1876,7 @@ enum scsi_disposition scsi_decide_disposition(struct scsi_cmnd *scmd) */ return SUCCESS; case DID_ERROR: - if (status_byte(scmd->result) == RESERVATION_CONFLICT) + if (get_status_byte(scmd) == SAM_STAT_RESERVATION_CONFLICT) /* * execute reservation conflict processing code * lower down @@ -1907,15 +1907,15 @@ enum scsi_disposition scsi_decide_disposition(struct scsi_cmnd *scmd) /* * check the status byte to see if this indicates anything special. */ - switch (status_byte(scmd->result)) { - case QUEUE_FULL: + switch (get_status_byte(scmd)) { + case SAM_STAT_TASK_SET_FULL: scsi_handle_queue_full(scmd->device); /* * the case of trying to send too many commands to a * tagged queueing device. */ fallthrough; - case BUSY: + case SAM_STAT_BUSY: /* * device can't talk to us at the moment. Should only * occur (SAM-3) when the task queue is empty, so will cause @@ -1923,16 +1923,16 @@ enum scsi_disposition scsi_decide_disposition(struct scsi_cmnd *scmd) * device. */ return ADD_TO_MLQUEUE; - case GOOD: + case SAM_STAT_GOOD: if (scmd->cmnd[0] == REPORT_LUNS) scmd->device->sdev_target->expecting_lun_change = 0; scsi_handle_queue_ramp_up(scmd->device); fallthrough; - case COMMAND_TERMINATED: + case SAM_STAT_COMMAND_TERMINATED: return SUCCESS; - case TASK_ABORTED: + case SAM_STAT_TASK_ABORTED: goto maybe_retry; - case CHECK_CONDITION: + case SAM_STAT_CHECK_CONDITION: rtn = scsi_check_sense(scmd); if (rtn == NEEDS_RETRY) goto maybe_retry; @@ -1941,16 +1941,16 @@ enum scsi_disposition scsi_decide_disposition(struct scsi_cmnd *scmd) * to collect the sense and redo the decide * disposition */ return rtn; - case CONDITION_GOOD: - case INTERMEDIATE_GOOD: - case INTERMEDIATE_C_GOOD: - case ACA_ACTIVE: + case SAM_STAT_CONDITION_MET: + case SAM_STAT_INTERMEDIATE: + case SAM_STAT_INTERMEDIATE_CONDITION_MET: + case SAM_STAT_ACA_ACTIVE: /* * who knows? FIXME(eric) */ return SUCCESS; - case RESERVATION_CONFLICT: + case SAM_STAT_RESERVATION_CONFLICT: sdev_printk(KERN_INFO, scmd->device, "reservation conflict\n"); set_host_byte(scmd, DID_NEXUS_FAILURE); diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index e3897bb424b4..6b994baf87c2 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -873,7 +873,7 @@ static int scsi_io_completion_nz_result(struct scsi_cmnd *cmd, int result, * if it can't fit). Treat SAM_STAT_CONDITION_MET and the related * intermediate statuses (both obsolete in SAM-4) as good. */ - if (status_byte(result) && scsi_status_is_good(result)) { + if ((result & 0xff) && scsi_status_is_good(result)) { result = 0; *blk_statp = BLK_STS_OK; } diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index e9cb874f6891..482a07b662a9 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -338,7 +338,7 @@ static int sr_done(struct scsi_cmnd *SCpnt) * care is taken to avoid unnecessary additional work such as * memcpy's that could be avoided. */ - if (status_byte(result) == SAM_STAT_CHECK_CONDITION && + if (scsi_status_is_check_condition(result) && (SCpnt->sense_buffer[0] & 0x7f) == 0x70) { /* Sense current */ switch (SCpnt->sense_buffer[2]) { case MEDIUM_ERROR: diff --git a/drivers/scsi/sr_ioctl.c b/drivers/scsi/sr_ioctl.c index 93c77dd9a476..79d9aa2df528 100644 --- a/drivers/scsi/sr_ioctl.c +++ b/drivers/scsi/sr_ioctl.c @@ -205,7 +205,7 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc) err = result; goto out; } - if (status_byte(result) == SAM_STAT_CHECK_CONDITION) { + if (scsi_status_is_check_condition(result)) { switch (sshdr->sense_key) { case UNIT_ATTENTION: SDev->changed = 1; diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c index bea22f71c782..61ce0d142eea 100644 --- a/drivers/xen/xen-scsiback.c +++ b/drivers/xen/xen-scsiback.c @@ -224,7 +224,7 @@ static void scsiback_print_status(char *sense_buffer, int errors, pr_err("[%s:%d] cmnd[0]=%02x -> st=%02x msg=%02x host=%02x\n", tpg->tport->tport_name, pending_req->v2p->lun, - pending_req->cmnd[0], status_byte(errors), COMMAND_COMPLETE, + pending_req->cmnd[0], errors & 0xff, COMMAND_COMPLETE, host_byte(errors)); } diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h index f4fb7e7728b4..358f969f368f 100644 --- a/include/scsi/scsi.h +++ b/include/scsi/scsi.h @@ -184,7 +184,6 @@ enum scsi_disposition { * msg_byte (unused) * host_byte = set by low-level driver to indicate status. */ -#define status_byte(result) (((result) >> 1) & 0x7f) #define host_byte(result) (((result) >> 16) & 0xff) #define sense_class(sense) (((sense) >> 4) & 0x7) diff --git a/include/scsi/scsi_proto.h b/include/scsi/scsi_proto.h index 5c106c4f249e..cb218a576bcf 100644 --- a/include/scsi/scsi_proto.h +++ b/include/scsi/scsi_proto.h @@ -202,27 +202,7 @@ struct scsi_varlen_cdb_hdr { #define SAM_STAT_ACA_ACTIVE 0x30 #define SAM_STAT_TASK_ABORTED 0x40 -/* - * Status codes. These are deprecated as they are shifted 1 bit right - * from those found in the SCSI standards. This causes confusion for - * applications that are ported to several OSes. Prefer SAM Status codes - * above. - */ - -#define GOOD 0x00 -#define CHECK_CONDITION 0x01 -#define CONDITION_GOOD 0x02 -#define BUSY 0x04 -#define INTERMEDIATE_GOOD 0x08 -#define INTERMEDIATE_C_GOOD 0x0a -#define RESERVATION_CONFLICT 0x0c -#define COMMAND_TERMINATED 0x11 -#define QUEUE_FULL 0x14 -#define ACA_ACTIVE 0x18 -#define TASK_ABORTED 0x20 - -#define STATUS_MASK 0xfe - +#define STATUS_MASK 0xfe /* * SENSE KEYS */ diff --git a/include/scsi/sg.h b/include/scsi/sg.h index e9dd5477ca7a..843cefb8efce 100644 --- a/include/scsi/sg.h +++ b/include/scsi/sg.h @@ -145,6 +145,26 @@ struct compat_sg_io_hdr { /* Obsolete driver_byte() declaration */ #define driver_byte(result) (((result) >> 24) & 0xff) +/* + * Original linux SCSI Status codes. They are shifted 1 bit right + * from those found in the SCSI standards. + */ + +#define GOOD 0x00 +#define CHECK_CONDITION 0x01 +#define CONDITION_GOOD 0x02 +#define BUSY 0x04 +#define INTERMEDIATE_GOOD 0x08 +#define INTERMEDIATE_C_GOOD 0x0a +#define RESERVATION_CONFLICT 0x0c +#define COMMAND_TERMINATED 0x11 +#define QUEUE_FULL 0x14 +#define ACA_ACTIVE 0x18 +#define TASK_ABORTED 0x20 + +/* Obsolete status_byte() declaration */ +#define status_byte(result) (((result) >> 1) & 0x7f) + typedef struct sg_scsi_id { /* used by SG_GET_SCSI_ID ioctl() */ int host_no; /* as in "scsi" where 'n' is one of 0, 1, 2 etc */ int channel; -- cgit v1.2.3