scsi: core: Introduce scsi_status_is_check_condition()
authorHannes Reinecke <hare@suse.de>
Tue, 27 Apr 2021 08:30:14 +0000 (10:30 +0200)
committerMartin K. Petersen <martin.petersen@oracle.com>
Tue, 1 Jun 2021 02:48:21 +0000 (22:48 -0400)
Add a helper function scsi_status_is_check_condition() to encapsulate the
frequent checks for SAM_STAT_CHECK_CONDITION.

Link: https://lore.kernel.org/r/20210427083046.31620-9-hare@suse.de
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>
drivers/scsi/ibmvscsi/ibmvscsi.c
drivers/scsi/scsi.c
drivers/scsi/scsi_error.c
drivers/scsi/scsi_lib.c
include/scsi/scsi.h

index e75b006..e6a3eaa 100644 (file)
@@ -1005,7 +1005,7 @@ static void handle_cmd_rsp(struct srp_event_struct *evt_struct)
        
        if (cmnd) {
                cmnd->result |= rsp->status;
-               if (((cmnd->result >> 1) & 0x1f) == CHECK_CONDITION)
+               if (scsi_status_is_check_condition(cmnd->result))
                        memcpy(cmnd->sense_buffer,
                               rsp->data,
                               be32_to_cpu(rsp->sense_data_len));
index 99dc6ec..1ce46e6 100644 (file)
@@ -144,7 +144,7 @@ void scsi_log_completion(struct scsi_cmnd *cmd, int disposition)
                    (level > 1)) {
                        scsi_print_result(cmd, "Done", disposition);
                        scsi_print_command(cmd);
-                       if (status_byte(cmd->result) == CHECK_CONDITION)
+                       if (scsi_status_is_check_condition(cmd->result))
                                scsi_print_sense(cmd);
                        if (level > 3)
                                scmd_printk(KERN_INFO, cmd,
index d8fafe7..0967021 100644 (file)
@@ -1258,7 +1258,7 @@ int scsi_eh_get_sense(struct list_head *work_q,
                                             current->comm));
                        break;
                }
-               if (status_byte(scmd->result) != CHECK_CONDITION)
+               if (!scsi_status_is_check_condition(scmd->result))
                        /*
                         * don't request sense if there's no check condition
                         * status because the error we're processing isn't one
@@ -1774,7 +1774,7 @@ int scsi_noretry_cmd(struct scsi_cmnd *scmd)
                return (scmd->request->cmd_flags & REQ_FAILFAST_DRIVER);
        }
 
-       if (status_byte(scmd->result) != CHECK_CONDITION)
+       if (!scsi_status_is_check_condition(scmd->result))
                return 0;
 
 check_type:
index 9b24913..d6b0cb2 100644 (file)
@@ -2164,7 +2164,7 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
                                        goto retry;
                                }
                        }
-                       if ((status_byte(result) == CHECK_CONDITION) &&
+                       if (scsi_status_is_check_condition(result) &&
                            sshdr->sense_key == UNIT_ATTENTION &&
                            retry_count) {
                                retry_count--;
index 6dc2d1b..57f0ca0 100644 (file)
@@ -62,6 +62,21 @@ static inline int scsi_is_wlun(u64 lun)
        return (lun & 0xff00) == SCSI_W_LUN_BASE;
 }
 
+/**
+ * scsi_status_is_check_condition - check the status return.
+ *
+ * @status: the status passed up from the driver (including host and
+ *          driver components)
+ *
+ * This returns true if the status code is SAM_STAT_CHECK_CONDITION.
+ */
+static inline int scsi_status_is_check_condition(int status)
+{
+       if (status < 0)
+               return false;
+       status &= 0xfe;
+       return status == SAM_STAT_CHECK_CONDITION;
+}
 
 /*
  *  MESSAGE CODES