diff mbox

[VERY,EARLY,RFC,03/13] scsi: add enum for host byte codes

Message ID 20180418150116.18807-4-jthumshirn@suse.de (mailing list archive)
State Changes Requested
Headers show

Commit Message

Johannes Thumshirn April 18, 2018, 3:01 p.m. UTC
Add enum for host byte codes and adopt set_host_byte()'s and host_byte()'s
signature.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Suggested-by: Bart Van Assche <Bart.VanAssche@wdc.com>
---
 drivers/scsi/dc395x.c     |  3 +--
 drivers/scsi/megaraid.c   |  6 ++++--
 drivers/scsi/scsi_error.c |  2 ++
 include/scsi/scsi.h       | 55 ++++++++++++++++++++++++++---------------------
 include/scsi/scsi_cmnd.h  |  3 ++-
 5 files changed, 39 insertions(+), 30 deletions(-)
diff mbox

Patch

diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
index da28f08ae185..379a1bc37576 100644
--- a/drivers/scsi/dc395x.c
+++ b/drivers/scsi/dc395x.c
@@ -173,7 +173,6 @@ 
 #define SET_RES_TARGET(who,tgt) { who &= ~RES_TARGET; who |= (int)(tgt); }
 #define SET_RES_TARGET_LNX(who,tgt) { who &= ~RES_TARGET_LNX; who |= (int)(tgt) << 1; }
 #define SET_RES_MSG(who,msg) { who &= ~RES_ENDMSG; who |= (int)(msg) << 8; }
-#define SET_RES_DID(who,did) { who &= ~RES_DID; who |= (int)(did) << 16; }
 #define SET_RES_DRV(who,drv) { who &= ~RES_DRV; who |= (int)(drv) << 24; }
 
 #define TAG_NONE 255
@@ -3443,7 +3442,7 @@  static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb,
 
 			srb->adapter_status = 0;
 			srb->target_status = 0;
-			SET_RES_DID(cmd->result, DID_OK);
+			set_host_byte(cmd, DID_OK);
 		}
 	}
 
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index 4d769db4435a..284bc8c4c6d5 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -1473,7 +1473,8 @@  mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
 					"aborted cmd [%x] complete\n",
 					scb->idx);
 
-				scb->cmd->result = (DID_ABORT << 16);
+				scb->cmd->result = 0;
+				set_host_byte(scb->cmd, DID_ABORT);
 
 				list_add_tail(SCSI_LIST(scb->cmd),
 						&adapter->completed_list);
@@ -1492,7 +1493,8 @@  mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
 					"reset cmd [%x] complete\n",
 					scb->idx);
 
-				scb->cmd->result = (DID_RESET << 16);
+				scb->cmd->result = 0;
+				set_host_byte(scb->cmd, DID_RESET);
 
 				list_add_tail(SCSI_LIST(scb->cmd),
 						&adapter->completed_list);
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 946039117bf4..7e80f457367e 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -1699,6 +1699,8 @@  int scsi_noretry_cmd(struct scsi_cmnd *scmd)
 		/* fall through */
 	case DID_SOFT_ERROR:
 		return (scmd->request->cmd_flags & REQ_FAILFAST_DRIVER);
+	default:
+		break;
 	}
 
 	if (status_byte(scmd->result) != CHECK_CONDITION)
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
index eb7853c1a23b..4dfc5e11a5b2 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -132,33 +132,35 @@  static inline int scsi_is_wlun(u64 lun)
 /*
  * Host byte codes
  */
-
-#define DID_OK          0x00	/* NO error                                */
-#define DID_NO_CONNECT  0x01	/* Couldn't connect before timeout period  */
-#define DID_BUS_BUSY    0x02	/* BUS stayed busy through time out period */
-#define DID_TIME_OUT    0x03	/* TIMED OUT for other reason              */
-#define DID_BAD_TARGET  0x04	/* BAD target.                             */
-#define DID_ABORT       0x05	/* Told to abort for some other reason     */
-#define DID_PARITY      0x06	/* Parity error                            */
-#define DID_ERROR       0x07	/* Internal error                          */
-#define DID_RESET       0x08	/* Reset by somebody.                      */
-#define DID_BAD_INTR    0x09	/* Got an interrupt we weren't expecting.  */
-#define DID_PASSTHROUGH 0x0a	/* Force command past mid-layer            */
-#define DID_SOFT_ERROR  0x0b	/* The low level driver just wish a retry  */
-#define DID_IMM_RETRY   0x0c	/* Retry without decrementing retry count  */
-#define DID_REQUEUE	0x0d	/* Requeue command (no immediate retry) also
+enum scsi_host_byte {
+	DID_OK,			/* NO error                                */
+	DID_NO_CONNECT,		/* Couldn't connect before timeout period  */
+	DID_BUS_BUSY,		/* BUS stayed busy through time out period */
+	DID_TIME_OUT,		/* TIMED OUT for other reason              */
+	DID_BAD_TARGET,		/* BAD target.                             */
+	DID_ABORT,		/* Told to abort for some other reason     */
+	DID_PARITY,		/* Parity error                            */
+	DID_ERROR,		/* Internal error                          */
+	DID_RESET,		/* Reset by somebody.                      */
+	DID_BAD_INTR,		/* Got an interrupt we weren't expecting.  */
+	DID_PASSTHROUGH,	/* Force command past mid-layer            */
+	DID_SOFT_ERROR,		/* The low level driver just wish a retry  */
+	DID_IMM_RETRY,		/* Retry without decrementing retry count  */
+	DID_REQUEUE,		/* Requeue command (no immediate retry) also
 				 * without decrementing the retry count	   */
-#define DID_TRANSPORT_DISRUPTED 0x0e /* Transport error disrupted execution
-				      * and the driver blocked the port to
-				      * recover the link. Transport class will
-				      * retry or fail IO */
-#define DID_TRANSPORT_FAILFAST	0x0f /* Transport class fastfailed the io */
-#define DID_TARGET_FAILURE 0x10 /* Permanent target failure, do not retry on
+	DID_TRANSPORT_DISRUPTED,/* Transport error disrupted execution
+				 * and the driver blocked the port to
+				 * recover the link. Transport class will
+				 * retry or fail IO
+				 */
+	DID_TRANSPORT_FAILFAST,	/* Transport class fastfailed the io */
+	DID_TARGET_FAILURE,	/* Permanent target failure, do not retry on
 				 * other paths */
-#define DID_NEXUS_FAILURE 0x11  /* Permanent nexus failure, retry on other
+	DID_NEXUS_FAILURE,	/* Permanent nexus failure, retry on other
 				 * paths might yield different results */
-#define DID_ALLOC_FAILURE 0x12  /* Space allocation on the device failed */
-#define DID_MEDIUM_ERROR  0x13  /* Medium error */
+	DID_ALLOC_FAILURE,	/* Space allocation on the device failed */
+	DID_MEDIUM_ERROR,	/* Medium error */
+};
 #define DRIVER_OK       0x00	/* Driver status                           */
 
 /*
@@ -209,7 +211,10 @@  static inline int scsi_is_wlun(u64 lun)
  */
 #define status_byte(result) (((result) >> 1) & 0x7f)
 #define msg_byte(result)    (((result) >> 8) & 0xff)
-#define host_byte(result)   (((result) >> 16) & 0xff)
+static inline enum scsi_host_byte host_byte(int result)
+{
+	return (result >> 16) & 0xff;
+}
 #define driver_byte(result) (((result) >> 24) & 0xff)
 
 #define sense_class(sense)  (((sense) >> 4) & 0x7)
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index aaf1e971c6a3..b678cd99b12b 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -342,7 +342,8 @@  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)
+static inline void set_host_byte(struct scsi_cmnd *cmd,
+				 enum scsi_host_byte status)
 {
 	cmd->result = (cmd->result & 0xff00ffff) | (status << 16);
 }