linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Christoph Hellwig <hch@lst.de>,
	James Bottomley <james.bottomley@hansenpartnership.com>,
	Bart van Assche <bvanassche@acm.org>,
	linux-scsi@vger.kernel.org, Hannes Reinecke <hare@suse.de>
Subject: [PATCH 18/40] dc395: use standard macros to set SCSI result
Date: Tue, 27 Apr 2021 10:30:24 +0200	[thread overview]
Message-ID: <20210427083046.31620-19-hare@suse.de> (raw)
In-Reply-To: <20210427083046.31620-1-hare@suse.de>

Use standard macros to set the SCSI result and drop the internal ones.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 drivers/scsi/dc395x.c | 76 ++++++++++++++++---------------------------
 1 file changed, 28 insertions(+), 48 deletions(-)

diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
index a713fe605dda..598448ece8d0 100644
--- a/drivers/scsi/dc395x.c
+++ b/drivers/scsi/dc395x.c
@@ -160,22 +160,6 @@
 #define DC395x_write16(acb,address,value)	outw((value), acb->io_port_base + (address))
 #define DC395x_write32(acb,address,value)	outl((value), acb->io_port_base + (address))
 
-/* cmd->result */
-#define RES_TARGET		0x000000FF	/* Target State */
-#define RES_TARGET_LNX  STATUS_MASK	/* Only official ... */
-#define RES_ENDMSG		0x0000FF00	/* End Message */
-#define RES_DID			0x00FF0000	/* DID_ codes */
-#define RES_DRV			0xFF000000	/* DRIVER_ codes */
-
-#define MK_RES(drv,did,msg,tgt) ((int)(drv)<<24 | (int)(did)<<16 | (int)(msg)<<8 | (int)(tgt))
-#define MK_RES_LNX(drv,did,msg,tgt) ((int)(drv)<<24 | (int)(did)<<16 | (int)(msg)<<8 | (int)(tgt)<<1)
-
-#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
 
 /*
@@ -986,7 +970,7 @@ static int dc395x_queue_command_lck(struct scsi_cmnd *cmd, void (*done)(struct s
 		cmd, cmd->device->id, (u8)cmd->device->lun, cmd->cmnd[0]);
 
 	/* Assume BAD_TARGET; will be cleared later */
-	cmd->result = DID_BAD_TARGET << 16;
+	set_host_byte(cmd, DID_BAD_TARGET);
 
 	/* ignore invalid targets */
 	if (cmd->device->id >= acb->scsi_host->max_id ||
@@ -1013,7 +997,8 @@ static int dc395x_queue_command_lck(struct scsi_cmnd *cmd, void (*done)(struct s
 
 	/* set callback and clear result in the command */
 	cmd->scsi_done = done;
-	cmd->result = 0;
+	set_host_byte(cmd, DID_OK);
+	set_status_byte(cmd, SAM_STAT_GOOD);
 
 	srb = list_first_entry_or_null(&acb->srb_free_list,
 			struct ScsiReqBlk, list);
@@ -1250,7 +1235,7 @@ static int dc395x_eh_abort(struct scsi_cmnd *cmd)
 		free_tag(dcb, srb);
 		list_add_tail(&srb->list, &acb->srb_free_list);
 		dprintkl(KERN_DEBUG, "eh_abort: Command was waiting\n");
-		cmd->result = DID_ABORT << 16;
+		set_host_byte(cmd, DID_ABORT);
 		return SUCCESS;
 	}
 	srb = find_cmd(cmd, &dcb->srb_going_list);
@@ -3178,6 +3163,8 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb,
 		   srb, scsi_sg_count(cmd), srb->sg_index, srb->sg_count,
 		   scsi_sgtalbe(cmd));
 	status = srb->target_status;
+	set_host_byte(cmd, DID_OK);
+	set_status_byte(cmd, SAM_STAT_GOOD);
 	if (srb->flag & AUTO_REQSENSE) {
 		dprintkdbg(DBG_0, "srb_done: AUTO_REQSENSE1\n");
 		pci_unmap_srb_sense(acb, srb);
@@ -3186,7 +3173,7 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb,
 		 */
 		srb->flag &= ~AUTO_REQSENSE;
 		srb->adapter_status = 0;
-		srb->target_status = CHECK_CONDITION << 1;
+		srb->target_status = SAM_STAT_CHECK_CONDITION;
 		if (debug_enabled(DBG_1)) {
 			switch (cmd->sense_buffer[2] & 0x0f) {
 			case NOT_READY:
@@ -3233,15 +3220,14 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb,
 					*((unsigned int *)(cmd->sense_buffer + 3)));
 		}
 
-		if (status == (CHECK_CONDITION << 1)) {
-			cmd->result = DID_BAD_TARGET << 16;
+		if (status == SAM_STAT_CHECK_CONDITION) {
+			set_host_byte(cmd, DID_BAD_TARGET);
 			goto ckc_e;
 		}
 		dprintkdbg(DBG_0, "srb_done: AUTO_REQSENSE2\n");
 
-		cmd->result =
-		    MK_RES(0, DID_OK,
-			   srb->end_message, SAM_STAT_CHECK_CONDITION);
+		set_msg_byte(cmd, srb->end_message);
+		set_status_byte(cmd, SAM_STAT_CHECK_CONDITION);
 
 		goto ckc_e;
 	}
@@ -3251,10 +3237,10 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb,
 		/*
 		 * target status..........................
 		 */
-		if (status >> 1 == CHECK_CONDITION) {
+		if (status == SAM_STAT_CHECK_CONDITION) {
 			request_sense(acb, dcb, srb);
 			return;
-		} else if (status >> 1 == QUEUE_FULL) {
+		} else if (status == SAM_STAT_TASK_SET_FULL) {
 			tempcnt = (u8)list_size(&dcb->srb_going_list);
 			dprintkl(KERN_INFO, "QUEUE_FULL for dev <%02i-%i> with %i cmnds\n",
 			     dcb->target_id, dcb->target_lun, tempcnt);
@@ -3270,13 +3256,12 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb,
 		} else if (status == SCSI_STAT_SEL_TIMEOUT) {
 			srb->adapter_status = H_SEL_TIMEOUT;
 			srb->target_status = 0;
-			cmd->result = DID_NO_CONNECT << 16;
+			set_host_byte(cmd, DID_NO_CONNECT);
 		} else {
 			srb->adapter_status = 0;
-			SET_RES_DID(cmd->result, DID_ERROR);
-			SET_RES_MSG(cmd->result, srb->end_message);
-			SET_RES_TARGET(cmd->result, status);
-
+			set_host_byte(cmd, DID_ERROR);
+			set_msg_byte(cmd, srb->end_message);
+			set_status_byte(cmd, status);
 		}
 	} else {
 		/*
@@ -3285,16 +3270,14 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb,
 		status = srb->adapter_status;
 		if (status & H_OVER_UNDER_RUN) {
 			srb->target_status = 0;
-			SET_RES_DID(cmd->result, DID_OK);
-			SET_RES_MSG(cmd->result, srb->end_message);
+			set_msg_byte(cmd, srb->end_message);
 		} else if (srb->status & PARITY_ERROR) {
-			SET_RES_DID(cmd->result, DID_PARITY);
-			SET_RES_MSG(cmd->result, srb->end_message);
+			set_host_byte(cmd, DID_PARITY);
+			set_msg_byte(cmd, srb->end_message);
 		} else {	/* No error */
 
 			srb->adapter_status = 0;
 			srb->target_status = 0;
-			SET_RES_DID(cmd->result, DID_OK);
 		}
 	}
 
@@ -3315,15 +3298,15 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb,
 		base = scsi_kmap_atomic_sg(sg, scsi_sg_count(cmd), &offset, &len);
 		ptr = (struct ScsiInqData *)(base + offset);
 
-		if (!ckc_only && (cmd->result & RES_DID) == 0
+		if (!ckc_only && get_host_byte(cmd) == DID_OK
 		    && cmd->cmnd[2] == 0 && scsi_bufflen(cmd) >= 8
 		    && dir != DMA_NONE && ptr && (ptr->Vers & 0x07) >= 2)
 			dcb->inquiry7 = ptr->Flags;
 
 	/*if( srb->cmd->cmnd[0] == INQUIRY && */
 	/*  (host_byte(cmd->result) == DID_OK || status_byte(cmd->result) & CHECK_CONDITION) ) */
-		if ((cmd->result == (DID_OK << 16) ||
-		     status_byte(cmd->result) == CHECK_CONDITION)) {
+		if ((get_host_byte(cmd) == DID_OK) ||
+		    (get_status_byte(cmd) == SAM_STAT_CHECK_CONDITION)) {
 			if (!dcb->init_tcq_flag) {
 				add_dev(acb, dcb, ptr);
 				dcb->init_tcq_flag = 1;
@@ -3350,7 +3333,7 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb,
 	if (srb != acb->tmp_srb) {
 		/* Add to free list */
 		dprintkdbg(DBG_0, "srb_done: (0x%p) done result=0x%08x\n",
-			cmd, cmd->result);
+			   cmd, cmd->result);
 		list_move_tail(&srb->list, &acb->srb_free_list);
 	} else {
 		dprintkl(KERN_ERR, "srb_done: ERROR! Completed cmd with tmp_srb\n");
@@ -3374,16 +3357,14 @@ static void doing_srb_done(struct AdapterCtlBlk *acb, u8 did_flag,
 		struct scsi_cmnd *p;
 
 		list_for_each_entry_safe(srb, tmp, &dcb->srb_going_list, list) {
-			int result;
-
 			p = srb->cmd;
-			result = MK_RES(0, did_flag, 0, 0);
 			printk("G:%p(%02i-%i) ", p,
 			       p->device->id, (u8)p->device->lun);
 			list_del(&srb->list);
 			free_tag(dcb, srb);
 			list_add_tail(&srb->list, &acb->srb_free_list);
-			p->result = result;
+			set_host_byte(p, did_flag);
+			set_status_byte(p, SAM_STAT_GOOD);
 			pci_unmap_srb_sense(acb, srb);
 			pci_unmap_srb(acb, srb);
 			if (force) {
@@ -3404,14 +3385,13 @@ static void doing_srb_done(struct AdapterCtlBlk *acb, u8 did_flag,
 
 		/* Waiting queue */
 		list_for_each_entry_safe(srb, tmp, &dcb->srb_waiting_list, list) {
-			int result;
 			p = srb->cmd;
 
-			result = MK_RES(0, did_flag, 0, 0);
 			printk("W:%p<%02i-%i>", p, p->device->id,
 			       (u8)p->device->lun);
 			list_move_tail(&srb->list, &acb->srb_free_list);
-			p->result = result;
+			set_host_byte(p, did_flag);
+			set_status_byte(p, SAM_STAT_GOOD);
 			pci_unmap_srb_sense(acb, srb);
 			pci_unmap_srb(acb, srb);
 			if (force) {
-- 
2.29.2


  parent reply	other threads:[~2021-04-27  8:31 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-27  8:30 [PATCHv3 00/40] SCSI result cleanup, part 2 Hannes Reinecke
2021-04-27  8:30 ` [PATCH 01/40] st: return error code in st_scsi_execute() Hannes Reinecke
2021-04-27 12:11   ` "Kai Mäkisara (Kolumbus)"
2021-04-27  8:30 ` [PATCH 02/40] scsi_ioctl: return error code when blk_rq_map_kern() fails Hannes Reinecke
2021-04-27  8:30 ` [PATCH 03/40] scsi: Fixup calling convention for scsi_mode_sense() Hannes Reinecke
2021-04-27  8:30 ` [PATCH 04/40] scsi: reshuffle response handling in scsi_mode_sense() Hannes Reinecke
2021-04-27  8:30 ` [PATCH 05/40] scsi_dh_alua: check for negative result value Hannes Reinecke
2021-04-27  8:30 ` [PATCH 06/40] scsi: stop using DRIVER_ERROR Hannes Reinecke
2021-04-27  8:30 ` [PATCH 07/40] scsi: introduce scsi_build_sense() Hannes Reinecke
2021-04-27  8:30 ` [PATCH 08/40] scsi: introduce scsi_status_is_check_condition() Hannes Reinecke
2021-04-27  8:30 ` [PATCH 09/40] scsi: Kill DRIVER_SENSE Hannes Reinecke
2021-04-27  8:30 ` [PATCH 10/40] scsi: do not use DRIVER_INVALID Hannes Reinecke
2021-04-27  8:30 ` [PATCH 11/40] scsi_error: use DID_TIME_OUT instead of DRIVER_TIMEOUT Hannes Reinecke
2021-04-27  8:30 ` [PATCH 12/40] xen-scsiback: use DID_ERROR instead of DRIVER_ERROR Hannes Reinecke
2021-04-27  8:30 ` [PATCH 13/40] xen-scsifront: compability status handling Hannes Reinecke
2021-04-27  8:30 ` [PATCH 14/40] scsi: Drop the now obsolete driver_byte definitions Hannes Reinecke
2021-04-27  8:30 ` [PATCH 15/40] NCR5380: Fold SCSI message ABORT onto DID_ABORT Hannes Reinecke
2021-04-27  8:30 ` [PATCH 16/40] scsi: add get_{status,host}_byte() accessor function Hannes Reinecke
2021-04-27  8:30 ` [PATCH 17/40] scsi: add scsi_msg_to_host_byte() Hannes Reinecke
2021-04-27  8:30 ` Hannes Reinecke [this message]
2021-04-27  8:30 ` [PATCH 19/40] dc395: translate message bytes Hannes Reinecke
2021-04-27  8:30 ` [PATCH 20/40] qlogicfas408: make ql_pcmd() a void function Hannes Reinecke
2021-04-27  8:30 ` [PATCH 21/40] qlogicfas408: whitespace cleanup Hannes Reinecke
2021-04-27  8:30 ` [PATCH 22/40] qlogicfas408: translate message to host byte status Hannes Reinecke
2021-04-27  8:30 ` [PATCH 23/40] nsp32: whitespace cleanup Hannes Reinecke
2021-04-27  8:30 ` [PATCH 24/40] nsp32: do not set message byte Hannes Reinecke
2021-04-27  8:30 ` [PATCH 25/40] wd33c93: translate message byte to host byte Hannes Reinecke
2021-04-27  8:30 ` [PATCH 26/40] mesh: translate message to host byte status Hannes Reinecke
2021-04-27  8:30 ` [PATCH 27/40] acornscsi: remove acornscsi_reportstatus() Hannes Reinecke
2021-04-27  8:30 ` [PATCH 28/40] acornscsi: translate message byte to host byte Hannes Reinecke
2021-04-27  8:30 ` [PATCH 29/40] aha152x: modify done() to use separate status bytes Hannes Reinecke
2021-04-27  8:30 ` [PATCH 30/40] aha152x: do not set message byte when calling scsi_done() Hannes Reinecke
2021-04-27  8:30 ` [PATCH 31/40] advansys: do not set message byte in SCSI status Hannes Reinecke
2021-04-27  8:30 ` [PATCH 32/40] fas216: translate message to host byte status Hannes Reinecke
2021-04-27  8:30 ` [PATCH 33/40] fas216: Use get_status_byte() to avoid using linux-specific status codes Hannes Reinecke
2021-04-27  8:30 ` [PATCH 34/40] FlashPoint: Use standard SCSI definitions Hannes Reinecke
2021-04-27  8:30 ` [PATCH 35/40] fdomain: drop last argument to fdomain_finish_cmd() Hannes Reinecke
2021-04-27  8:30 ` [PATCH 36/40] fdomain: translate message to host byte status Hannes Reinecke
2021-04-27  8:30 ` [PATCH 37/40] scsi: drop message byte helper Hannes Reinecke
2021-04-27  8:30 ` [PATCH 38/40] scsi: kill message byte Hannes Reinecke
2021-04-27  8:30 ` [PATCH 39/40] target: use standard SAM status types Hannes Reinecke
2021-04-27  8:30 ` [PATCH 40/40] scsi: drop obsolete linux-specific SCSI status codes Hannes Reinecke
2021-04-29  6:48   ` Christoph Hellwig
2021-04-29  7:29     ` Hannes Reinecke
2021-04-29 15:52     ` Douglas Gilbert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210427083046.31620-19-hare@suse.de \
    --to=hare@suse.de \
    --cc=bvanassche@acm.org \
    --cc=hch@lst.de \
    --cc=james.bottomley@hansenpartnership.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).