diff mbox series

[23/42] nsp32: use standard macros to set SCSI result

Message ID 20210421174749.11221-24-hare@suse.de
State New
Headers show
Series SCSI result cleanup, part 2 | expand

Commit Message

Hannes Reinecke April 21, 2021, 5:47 p.m. UTC
Use standard macros to set the SCSI result to avoid shift and mask
error.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/nsp32.c | 47 ++++++++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 23 deletions(-)
diff mbox series

Patch

diff --git a/drivers/scsi/nsp32.c b/drivers/scsi/nsp32.c
index 134bbd2d8b66..4a12ee577f2a 100644
--- a/drivers/scsi/nsp32.c
+++ b/drivers/scsi/nsp32.c
@@ -461,7 +461,7 @@  static int nsp32_selection_autopara(struct scsi_cmnd *SCpnt)
 	if (phase != BUSMON_BUS_FREE) {
 		nsp32_msg(KERN_WARNING, "bus busy");
 		show_busphase(phase & BUSMON_PHASE_MASK);
-		SCpnt->result = DID_BUS_BUSY << 16;
+		set_host_byte(SCpnt, DID_BUS_BUSY);
 		return FALSE;
 	}
 
@@ -473,7 +473,7 @@  static int nsp32_selection_autopara(struct scsi_cmnd *SCpnt)
 	 */
 	if (data->msgout_len == 0) {
 		nsp32_msg(KERN_ERR, "SCSI MsgOut without any message!");
-		SCpnt->result = DID_ERROR << 16;
+		set_host_byte(SCpnt, DID_ERROR);
 		return FALSE;
 	} else if (data->msgout_len > 0 && data->msgout_len <= 3) {
 		msgout = 0;
@@ -596,7 +596,7 @@  static int nsp32_selection_autoscsi(struct scsi_cmnd *SCpnt)
 	phase = nsp32_read1(base, SCSI_BUS_MONITOR);
 	if ((phase & BUSMON_BSY) || (phase & BUSMON_SEL)) {
 		nsp32_msg(KERN_WARNING, "bus busy");
-		SCpnt->result = DID_BUS_BUSY << 16;
+		set_host_byte(SCpnt, DID_BUS_BUSY);
 		status = 1;
 		goto out;
         }
@@ -632,7 +632,7 @@  static int nsp32_selection_autoscsi(struct scsi_cmnd *SCpnt)
 	 */
 	if (data->msgout_len == 0) {
 		nsp32_msg(KERN_ERR, "SCSI MsgOut without any message!");
-		SCpnt->result = DID_ERROR << 16;
+		set_host_byte(SCpnt, DID_ERROR);
 		status = 1;
 		goto out;
 	} else if (data->msgout_len > 0 && data->msgout_len <= 3) {
@@ -762,11 +762,10 @@  static int nsp32_arbitration(struct scsi_cmnd *SCpnt, unsigned int base)
 
 	if (arbit & ARBIT_WIN) {
 		/* Arbitration succeeded */
-		SCpnt->result = DID_OK << 16;
 		nsp32_index_write1(base, EXT_PORT, LED_ON); /* PCI LED on */
 	} else if (arbit & ARBIT_FAIL) {
 		/* Arbitration failed */
-		SCpnt->result = DID_BUS_BUSY << 16;
+		set_host_byte(SCpnt, DID_BUS_BUSY);
 		status = FALSE;
 	} else {
 		/*
@@ -774,7 +773,7 @@  static int nsp32_arbitration(struct scsi_cmnd *SCpnt, unsigned int base)
 		 * something lock up! guess no connection.
 		 */
 		nsp32_dbg(NSP32_DEBUG_AUTOSCSI, "arbit timeout");
-		SCpnt->result = DID_NO_CONNECT << 16;
+		set_host_byte(SCpnt, DID_NO_CONNECT);
 		status = FALSE;
         }
 
@@ -907,10 +906,12 @@  static int nsp32_queuecommand_lck(struct scsi_cmnd *SCpnt, void (*done)(struct s
 		  SCpnt->device->id, SCpnt->device->lun, SCpnt->cmnd[0], SCpnt->cmd_len,
 		  scsi_sg_count(SCpnt), scsi_sglist(SCpnt), scsi_bufflen(SCpnt));
 
+	set_host_byte(SCpnt, DID_OK);
+	set_status_byte(SCpnt, SAM_STAT_GOOD);
 	if (data->CurrentSC != NULL) {
 		nsp32_msg(KERN_ERR, "Currentsc != NULL. Cancel this command request");
 		data->CurrentSC = NULL;
-		SCpnt->result   = DID_NO_CONNECT << 16;
+		set_host_byte(SCpnt, DID_NO_CONNECT);
 		done(SCpnt);
 		return 0;
 	}
@@ -918,7 +919,7 @@  static int nsp32_queuecommand_lck(struct scsi_cmnd *SCpnt, void (*done)(struct s
 	/* check target ID is not same as this initiator ID */
 	if (scmd_id(SCpnt) == SCpnt->device->host->this_id) {
 		nsp32_dbg(NSP32_DEBUG_QUEUECOMMAND, "target==host???");
-		SCpnt->result = DID_BAD_TARGET << 16;
+		set_host_byte(SCpnt, DID_BAD_TARGET);
 		done(SCpnt);
 		return 0;
 	}
@@ -926,7 +927,7 @@  static int nsp32_queuecommand_lck(struct scsi_cmnd *SCpnt, void (*done)(struct s
 	/* check target LUN is allowable value */
 	if (SCpnt->device->lun >= MAX_LUN) {
 		nsp32_dbg(NSP32_DEBUG_QUEUECOMMAND, "no more lun");
-		SCpnt->result = DID_BAD_TARGET << 16;
+		set_host_byte(SCpnt, DID_BAD_TARGET);
 		done(SCpnt);
 		return 0;
 	}
@@ -958,7 +959,7 @@  static int nsp32_queuecommand_lck(struct scsi_cmnd *SCpnt, void (*done)(struct s
 	ret = nsp32_setup_sg_table(SCpnt);
 	if (ret == FALSE) {
 		nsp32_msg(KERN_ERR, "SGT fail");
-		SCpnt->result = DID_ERROR << 16;
+		set_host_byte(SCpnt, DID_ERROR);
 		nsp32_scsi_done(SCpnt);
 		return 0;
 	}
@@ -1181,7 +1182,7 @@  static irqreturn_t do_nsp32_isr(int irq, void *dev_id)
 		nsp32_msg(KERN_INFO, "card disconnect");
 		if (data->CurrentSC != NULL) {
 			nsp32_msg(KERN_INFO, "clean up current SCSI command");
-			SCpnt->result = DID_BAD_TARGET << 16;
+			set_host_byte(SCpnt, DID_BAD_TARGET);
 			nsp32_scsi_done(SCpnt);
 		}
 		goto out;
@@ -1199,7 +1200,7 @@  static irqreturn_t do_nsp32_isr(int irq, void *dev_id)
 		nsp32_msg(KERN_INFO, "detected someone do bus reset");
 		nsp32_do_bus_reset(data);
 		if (SCpnt != NULL) {
-			SCpnt->result = DID_RESET << 16;
+			set_host_byte(SCpnt, DID_RESET);
 			nsp32_scsi_done(SCpnt);
 		}
 		goto out;
@@ -1227,7 +1228,7 @@  static irqreturn_t do_nsp32_isr(int irq, void *dev_id)
 			nsp32_dbg(NSP32_DEBUG_INTR,
 				  "selection timeout occurred");
 
-			SCpnt->result = DID_TIME_OUT << 16;
+			set_host_byte(SCpnt, DID_TIME_OUT);
 			nsp32_scsi_done(SCpnt);
 			goto out;
 		}
@@ -1309,7 +1310,8 @@  static irqreturn_t do_nsp32_isr(int irq, void *dev_id)
 			 * low level driver to indicate status), then checks 
 			 * status_byte (SCSI status byte).
 			 */
-			SCpnt->result =	(int)nsp32_read1(base, SCSI_CSB_IN);
+			set_status_byte(SCpnt,
+					nsp32_read1(base, SCSI_CSB_IN));
 		}
 
 		if (auto_stat & ILLEGAL_PHASE) {
@@ -1666,20 +1668,19 @@  static int nsp32_busfree_occur(struct scsi_cmnd *SCpnt, unsigned short execph)
 		nsp32_dbg(NSP32_DEBUG_BUSFREE, "command complete");
 
 		SCpnt->SCp.Status  = nsp32_read1(base, SCSI_CSB_IN);
-		SCpnt->SCp.Message = 0;
+		SCpnt->SCp.Message = COMMAND_COMPLETE;
 		nsp32_dbg(NSP32_DEBUG_BUSFREE, 
 			  "normal end stat=0x%x resid=0x%x\n",
 			  SCpnt->SCp.Status, scsi_get_resid(SCpnt));
-		SCpnt->result = (DID_OK             << 16) |
-			        (SCpnt->SCp.Message <<  8) |
-			        (SCpnt->SCp.Status  <<  0);
+		set_msg_byte(SCpnt, SCpnt->SCp.Message);
+		set_status_byte(SCpnt, SCpnt->SCp.Status);
 		nsp32_scsi_done(SCpnt);
 		/* All operation is done */
 		return TRUE;
 	} else if (execph & MSGIN_04_VALID) {
 		/* MsgIn 04: Disconnect */
-		SCpnt->SCp.Status  = nsp32_read1(base, SCSI_CSB_IN);
-		SCpnt->SCp.Message = 4;
+		set_status_byte(SCpnt, nsp32_read1(base, SCSI_CSB_IN));
+		SCpnt->SCp.Message = DISCONNECT;
 		
 		nsp32_dbg(NSP32_DEBUG_BUSFREE, "disconnect");
 		return TRUE;
@@ -1689,7 +1690,7 @@  static int nsp32_busfree_occur(struct scsi_cmnd *SCpnt, unsigned short execph)
 
 		/* DID_ERROR? */
 		//SCpnt->result   = (DID_OK << 16) | (SCpnt->SCp.Message << 8) | (SCpnt->SCp.Status << 0);
-		SCpnt->result = DID_ERROR << 16;
+		set_host_byte(SCpnt, DID_ERROR);
 		nsp32_scsi_done(SCpnt);
 		return TRUE;
 	}
@@ -2812,7 +2813,7 @@  static int nsp32_eh_abort(struct scsi_cmnd *SCpnt)
 	nsp32_write2(base, TRANSFER_CONTROL, 0);
 	nsp32_write2(base, BM_CNT,           0);
 
-	SCpnt->result = DID_ABORT << 16;
+	set_host_byte(SCpnt, DID_ABORT);
 	nsp32_scsi_done(SCpnt);
 
 	nsp32_dbg(NSP32_DEBUG_BUSRESET, "abort success");