All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 00/42] SCSI result cleanup, part 2
@ 2021-04-21 17:47 Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 01/42] st: return error code in st_scsi_execute() Hannes Reinecke
                   ` (43 more replies)
  0 siblings, 44 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Hi all,

here is now my alternative approach on how the SCSI result could be
cleaned up. It's based on the observation that two fields (namely
driver_byte and message_byte) are essentially unused.
The driver byte really is an unloved thing, with very few drivers
using it, and not really consistent, either.
It's only DRIVER_SENSE which has a meaning for userspace, and that
just indicates if a sense code is present; as such it can easily
inferred by looking at the sense code itself.
The message byte is a different story, as it's being used internally
by some SCSI parallel drivers. But even here, in the end the message
byte is only ever relevant for SCSI EH, and that just checks if
any message byte is set apart from COMMAND_COMPLETE.
And we have the SCp.Message field, which can be used to hold the
message values for drivers which had been using the message byte
in the SCSI result.

So with this approach we can stop using the driver_byte and the
message_byte values in the SCSI result, which means we only
have two values (host byte and status byte) left to deal with.

My plan here is move every driver to use accessors for the
remaining bytes in the SCSI result, and with that move the
SCSI result over into two separate values.

A patchset implementing this can be found at:

git://git.kernel.org/pub/scm/linux/kernel/hare/scsi-devel.git
scsi-result-rework

This patchset is the first part of that, and is intentionally posted
as an RFC as it directly competes with Barts patchset.

As usual, comments and reviews are welcome.

Hannes Reinecke (42):
  st: return error code in st_scsi_execute()
  scsi_ioctl: return error code when blk_rq_map_kern() fails
  scsi_dh_alua: do not interpret DRIVER_ERROR
  scsi: Fixup calling convention for scsi_mode_sense()
  scsi: stop using DRIVER_ERROR
  scsi: introduce scsi_build_sense()
  scsi: Kill DRIVER_SENSE
  scsi: do not use DRIVER_INVALID
  scsi_error: use DID_TIME_OUT instead of DRIVER_TIMEOUT
  xen-scsiback: use DID_ERROR instead of DRIVER_ERROR
  xen-scsifront: compability status handling
  scsi: Drop the now obsolete driver_byte definitions
  scsi: add get_{status,host}_byte() accessor function
  scsi: add scsi_result_is_good()
  NCR5380: use SCSI result accessors
  NCR5380: Fold SCSI message ABORT onto DID_ABORT
  scsi: add translate_msg_byte()
  dc395: use standard macros to set SCSI result
  dc395: translate message bytes
  qlogicfas408: make ql_pcmd() a void function
  qlogicfas408: whitespace cleanup
  qlogicfas408: translate message to host byte status
  nsp32: use standard macros to set SCSI result
  nsp32: whitespace cleanup
  nsp32: do not set message byte
  wd33c93: use standard macros to set SCSI result
  wd33c93: translate message byte to host byte
  mesh: use standard macros to set SCSI result
  mesh: translate message to host byte status
  acornscsi: use standard macros to set SCSI result
  acornscsi: remove acornscsi_reportstatus()
  acornscsi: translate message byte to host byte
  aha152x: modify done() to use separate status bytes
  aha152x: do not set message byte when calling scsi_done()
  advansys: do not set message byte in SCSI status
  advansys: use SCSI result accessors
  fas216: translate message to host byte status
  fas216: convert to SCSI Accessors
  fdomain: drop last argument to fdomain_finish_cmd()
  fdomain: translate message to host byte status
  scsi: drop message byte helper
  scsi: kill message byte

 Documentation/scsi/scsi_mid_low_api.rst     |   7 +-
 block/bsg-lib.c                             |   2 +-
 block/bsg.c                                 |   2 +-
 block/scsi_ioctl.c                          |  11 +-
 drivers/ata/libata-scsi.c                   |  28 +-
 drivers/s390/scsi/zfcp_scsi.c               |   5 +-
 drivers/scsi/3w-xxxx.c                      |   2 +-
 drivers/scsi/NCR5380.c                      |  31 +-
 drivers/scsi/advansys.c                     |  11 +-
 drivers/scsi/aha152x.c                      |  33 +-
 drivers/scsi/aic7xxx/aic79xx_osm.c          |  19 +-
 drivers/scsi/aic7xxx/aic7xxx_osm.c          |   1 -
 drivers/scsi/arcmsr/arcmsr_hba.c            |   1 -
 drivers/scsi/arm/acornscsi.c                |  41 +-
 drivers/scsi/arm/fas216.c                   |  24 +-
 drivers/scsi/ch.c                           |   5 +-
 drivers/scsi/constants.c                    |  15 -
 drivers/scsi/cxlflash/superpipe.c           |   3 +-
 drivers/scsi/dc395x.c                       |  76 ++--
 drivers/scsi/device_handler/scsi_dh_alua.c  |   4 -
 drivers/scsi/esp_scsi.c                     |   4 +-
 drivers/scsi/fdomain.c                      |  22 +-
 drivers/scsi/hptiop.c                       |   2 +-
 drivers/scsi/libiscsi.c                     |   5 +-
 drivers/scsi/lpfc/lpfc_scsi.c               |  54 +--
 drivers/scsi/megaraid.c                     |  18 +-
 drivers/scsi/megaraid/megaraid_mbox.c       |  22 +-
 drivers/scsi/megaraid/megaraid_sas_base.c   |   2 -
 drivers/scsi/megaraid/megaraid_sas_fusion.c |   1 -
 drivers/scsi/mesh.c                         |  14 +-
 drivers/scsi/mpt3sas/mpt3sas_scsih.c        |  14 +-
 drivers/scsi/mvumi.c                        |  10 +-
 drivers/scsi/myrb.c                         |  64 +---
 drivers/scsi/myrs.c                         |   9 +-
 drivers/scsi/nsp32.c                        | 397 +++++++++++---------
 drivers/scsi/ps3rom.c                       |   7 +-
 drivers/scsi/qla2xxx/qla_isr.c              |  15 +-
 drivers/scsi/qlogicfas408.c                 | 137 ++++---
 drivers/scsi/scsi.c                         |   9 +-
 drivers/scsi/scsi_debug.c                   |  15 +-
 drivers/scsi/scsi_error.c                   |  22 +-
 drivers/scsi/scsi_ioctl.c                   |   7 +-
 drivers/scsi/scsi_lib.c                     |  48 ++-
 drivers/scsi/scsi_logging.c                 |  10 +-
 drivers/scsi/scsi_scan.c                    |   6 +-
 drivers/scsi/scsi_transport_sas.c           |   9 +-
 drivers/scsi/scsi_transport_spi.c           |   2 +-
 drivers/scsi/sd.c                           |  64 ++--
 drivers/scsi/sd_zbc.c                       |   3 +-
 drivers/scsi/sg.c                           |  11 +-
 drivers/scsi/smartpqi/smartpqi_init.c       |   3 +-
 drivers/scsi/sr.c                           |   4 +-
 drivers/scsi/sr_ioctl.c                     |   6 +-
 drivers/scsi/st.c                           |   8 +-
 drivers/scsi/stex.c                         |   9 +-
 drivers/scsi/sym53c8xx_2/sym_glue.c         |   6 +-
 drivers/scsi/ufs/ufshcd.c                   |   2 +-
 drivers/scsi/virtio_scsi.c                  |   5 +-
 drivers/scsi/vmw_pvscsi.c                   |   6 -
 drivers/scsi/wd33c93.c                      |  48 +--
 drivers/scsi/xen-scsifront.c                |   9 +-
 drivers/target/loopback/tcm_loop.c          |   1 -
 drivers/usb/storage/cypress_atacb.c         |   4 +-
 drivers/xen/xen-scsiback.c                  |  16 +-
 include/scsi/scsi.h                         |  22 +-
 include/scsi/scsi_cmnd.h                    |  33 +-
 include/scsi/sg.h                           |   4 +
 include/trace/events/scsi.h                 |  48 +--
 68 files changed, 706 insertions(+), 852 deletions(-)

-- 
2.29.2


^ permalink raw reply	[flat|nested] 80+ messages in thread

* [PATCH 01/42] st: return error code in st_scsi_execute()
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 20:56   ` Bart Van Assche
  2021-04-21 17:47 ` [PATCH 02/42] scsi_ioctl: return error code when blk_rq_map_kern() fails Hannes Reinecke
                   ` (42 subsequent siblings)
  43 siblings, 1 reply; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

The callers to st_scsi_execute already check for negative
return values, so we can drop the use of DRIVER_ERROR and
return the actual error code.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/st.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 9ca536aae784..23be6447e576 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -551,7 +551,7 @@ static int st_scsi_execute(struct st_request *SRpnt, const unsigned char *cmd,
 			data_direction == DMA_TO_DEVICE ?
 			REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN, 0);
 	if (IS_ERR(req))
-		return DRIVER_ERROR << 24;
+		return PTR_ERR(req);
 	rq = scsi_req(req);
 	req->rq_flags |= RQF_QUIET;
 
@@ -562,7 +562,7 @@ static int st_scsi_execute(struct st_request *SRpnt, const unsigned char *cmd,
 				      GFP_KERNEL);
 		if (err) {
 			blk_put_request(req);
-			return DRIVER_ERROR << 24;
+			return err;
 		}
 	}
 
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 02/42] scsi_ioctl: return error code when blk_rq_map_kern() fails
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 01/42] st: return error code in st_scsi_execute() Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 21:01   ` Bart Van Assche
  2021-04-21 17:47 ` [PATCH 03/42] scsi_dh_alua: do not interpret DRIVER_ERROR Hannes Reinecke
                   ` (41 subsequent siblings)
  43 siblings, 1 reply; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

The callers of sg_scsi_ioctl() already check for negative
return values, so we can drop the usage of DRIVER_ERROR
and return the error from blk_rq_map_kern() instead.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 block/scsi_ioctl.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index 6599bac0a78c..99d58786e0d5 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -488,9 +488,10 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
 		break;
 	}
 
-	if (bytes && blk_rq_map_kern(q, rq, buffer, bytes, GFP_NOIO)) {
-		err = DRIVER_ERROR << 24;
-		goto error;
+	if (bytes) {
+		err = blk_rq_map_kern(q, rq, buffer, bytes, GFP_NOIO);
+		if (err)
+			goto error;
 	}
 
 	blk_execute_rq(disk, rq, 0);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 03/42] scsi_dh_alua: do not interpret DRIVER_ERROR
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 01/42] st: return error code in st_scsi_execute() Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 02/42] scsi_ioctl: return error code when blk_rq_map_kern() fails Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 04/42] scsi: Fixup calling convention for scsi_mode_sense() Hannes Reinecke
                   ` (40 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Remove the special handling for DRIVER_ERROR; if there is an error
we should just fail the command and don't try anything clever.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/device_handler/scsi_dh_alua.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c
index efa8c0381476..d76c3dccb8cc 100644
--- a/drivers/scsi/device_handler/scsi_dh_alua.c
+++ b/drivers/scsi/device_handler/scsi_dh_alua.c
@@ -567,8 +567,6 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)
 				    "%s: rtpg failed, result %d\n",
 				    ALUA_DH_NAME, retval);
 			kfree(buff);
-			if (driver_byte(retval) == DRIVER_ERROR)
-				return SCSI_DH_DEV_TEMP_BUSY;
 			return SCSI_DH_IO;
 		}
 
@@ -795,8 +793,6 @@ static unsigned alua_stpg(struct scsi_device *sdev, struct alua_port_group *pg)
 			sdev_printk(KERN_INFO, sdev,
 				    "%s: stpg failed, result %d",
 				    ALUA_DH_NAME, retval);
-			if (driver_byte(retval) == DRIVER_ERROR)
-				return SCSI_DH_DEV_TEMP_BUSY;
 		} else {
 			sdev_printk(KERN_INFO, sdev, "%s: stpg failed\n",
 				    ALUA_DH_NAME);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 04/42] scsi: Fixup calling convention for scsi_mode_sense()
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (2 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 03/42] scsi_dh_alua: do not interpret DRIVER_ERROR Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 05/42] scsi: stop using DRIVER_ERROR Hannes Reinecke
                   ` (39 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

The description for scsi_mode_sense() claims to return the number
of valid bytes on success, which is not what the code does.
Additionally there is no gain in returning the scsi status, as
everything the callers do is to check against scsi_result_is_good(),
which is what scsi_mode_sense() does already.
So change the calling convention to return a standard error code
on failure, and 0 on success, and adapt the description and all
callers.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/scsi_lib.c           | 10 ++++++----
 drivers/scsi/scsi_transport_sas.c |  9 ++++-----
 drivers/scsi/sd.c                 | 12 ++++++------
 drivers/scsi/sr.c                 |  2 +-
 4 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index d7c0d5a5f263..c532f9390ae3 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2135,9 +2135,7 @@ EXPORT_SYMBOL_GPL(scsi_mode_select);
  *	@sshdr: place to put sense data (or NULL if no sense to be collected).
  *		must be SCSI_SENSE_BUFFERSIZE big.
  *
- *	Returns zero if unsuccessful, or the header offset (either 4
- *	or 8 depending on whether a six or ten byte command was
- *	issued) if successful.
+ *	Returns zero if successful, or a negative error number on failure
  */
 int
 scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
@@ -2190,6 +2188,8 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
 	 * byte as the problem.  MODE_SENSE commands can return
 	 * ILLEGAL REQUEST if the code page isn't supported */
 
+	if (result < 0)
+		return result;
 	if (use_10_for_ms && !scsi_status_is_good(result) &&
 	    driver_byte(result) == DRIVER_SENSE) {
 		if (scsi_sense_valid(sshdr)) {
@@ -2228,13 +2228,15 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
 			data->block_descriptor_length = buffer[3];
 		}
 		data->header_length = header_length;
+		result = 0;
 	} else if ((status_byte(result) == CHECK_CONDITION) &&
 		   scsi_sense_valid(sshdr) &&
 		   sshdr->sense_key == UNIT_ATTENTION && retry_count) {
 		retry_count--;
 		goto retry;
 	}
-
+	if (result > 0)
+		result = -EIO;
 	return result;
 }
 EXPORT_SYMBOL(scsi_mode_sense);
diff --git a/drivers/scsi/scsi_transport_sas.c b/drivers/scsi/scsi_transport_sas.c
index c9abed8429c9..4a96fb05731d 100644
--- a/drivers/scsi/scsi_transport_sas.c
+++ b/drivers/scsi/scsi_transport_sas.c
@@ -1229,16 +1229,15 @@ int sas_read_port_mode_page(struct scsi_device *sdev)
 	char *buffer = kzalloc(BUF_SIZE, GFP_KERNEL), *msdata;
 	struct sas_end_device *rdev = sas_sdev_to_rdev(sdev);
 	struct scsi_mode_data mode_data;
-	int res, error;
+	int error;
 
 	if (!buffer)
 		return -ENOMEM;
 
-	res = scsi_mode_sense(sdev, 1, 0x19, buffer, BUF_SIZE, 30*HZ, 3,
-			      &mode_data, NULL);
+	error = scsi_mode_sense(sdev, 1, 0x19, buffer, BUF_SIZE, 30*HZ, 3,
+				&mode_data, NULL);
 
-	error = -EINVAL;
-	if (!scsi_status_is_good(res))
+	if (error)
 		goto out;
 
 	msdata = buffer +  mode_data.header_length +
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index cb3c37d1e009..2ef2954375f4 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2670,18 +2670,18 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, unsigned char *buffer)
 		 * 5: Illegal Request, Sense Code 24: Invalid field in
 		 * CDB.
 		 */
-		if (!scsi_status_is_good(res))
+		if (res < 0)
 			res = sd_do_mode_sense(sdkp, 0, 0, buffer, 4, &data, NULL);
 
 		/*
 		 * Third attempt: ask 255 bytes, as we did earlier.
 		 */
-		if (!scsi_status_is_good(res))
+		if (res < 0)
 			res = sd_do_mode_sense(sdkp, 0, 0x3F, buffer, 255,
 					       &data, NULL);
 	}
 
-	if (!scsi_status_is_good(res)) {
+	if (res < 0) {
 		sd_first_printk(KERN_WARNING, sdkp,
 			  "Test WP failed, assume Write Enabled\n");
 	} else {
@@ -2742,7 +2742,7 @@ sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer)
 	res = sd_do_mode_sense(sdkp, dbd, modepage, buffer, first_len,
 			&data, &sshdr);
 
-	if (!scsi_status_is_good(res))
+	if (res < 0)
 		goto bad_sense;
 
 	if (!data.header_length) {
@@ -2774,7 +2774,7 @@ sd_read_cache_type(struct scsi_disk *sdkp, unsigned char *buffer)
 		res = sd_do_mode_sense(sdkp, dbd, modepage, buffer, len,
 				&data, &sshdr);
 
-	if (scsi_status_is_good(res)) {
+	if (!res) {
 		int offset = data.header_length + data.block_descriptor_length;
 
 		while (offset < len) {
@@ -2892,7 +2892,7 @@ static void sd_read_app_tag_own(struct scsi_disk *sdkp, unsigned char *buffer)
 	res = scsi_mode_sense(sdp, 1, 0x0a, buffer, 36, SD_TIMEOUT,
 			      sdkp->max_retries, &data, &sshdr);
 
-	if (!scsi_status_is_good(res) || !data.header_length ||
+	if (res < 0 || !data.header_length ||
 	    data.length < 6) {
 		sd_first_printk(KERN_WARNING, sdkp,
 			  "getting Control mode page failed, assume no ATO\n");
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index e4633b84c556..9b2ccf0c9a8c 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -911,7 +911,7 @@ static void get_capabilities(struct scsi_cd *cd)
 	rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, ms_len,
 			     SR_TIMEOUT, 3, &data, NULL);
 
-	if (!scsi_status_is_good(rc) || data.length > ms_len ||
+	if (rc < 0 || data.length > ms_len ||
 	    data.header_length + data.block_descriptor_length > data.length) {
 		/* failed, drive doesn't have capabilities mode page */
 		cd->cdi.speed = 1;
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 05/42] scsi: stop using DRIVER_ERROR
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (3 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 04/42] scsi: Fixup calling convention for scsi_mode_sense() Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 21:30   ` Bart Van Assche
  2021-04-21 17:47 ` [PATCH 06/42] scsi: introduce scsi_build_sense() Hannes Reinecke
                   ` (38 subsequent siblings)
  43 siblings, 1 reply; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Return the actual error code in __scsi_execute() (which, according
to the documentation, should have happened anyway).
And audit all callers to cope with negative return values from
__scsi_execute() and friends.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/ata/libata-scsi.c         |  8 ++++++++
 drivers/scsi/ch.c                 |  3 ++-
 drivers/scsi/cxlflash/superpipe.c |  2 +-
 drivers/scsi/scsi.c               |  2 ++
 drivers/scsi/scsi_ioctl.c         |  4 +++-
 drivers/scsi/scsi_lib.c           | 15 +++++++++------
 drivers/scsi/scsi_scan.c          |  4 ++--
 drivers/scsi/scsi_transport_spi.c |  2 +-
 drivers/scsi/sd.c                 | 15 +++++++++------
 drivers/scsi/sd_zbc.c             |  2 +-
 drivers/scsi/sr_ioctl.c           |  4 ++++
 drivers/scsi/ufs/ufshcd.c         |  2 +-
 drivers/scsi/virtio_scsi.c        |  2 +-
 include/scsi/scsi.h               |  3 +++
 14 files changed, 47 insertions(+), 21 deletions(-)

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 48b8934970f3..c5129b9e3afd 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -409,6 +409,10 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg)
 	cmd_result = scsi_execute(scsidev, scsi_cmd, data_dir, argbuf, argsize,
 				  sensebuf, &sshdr, (10*HZ), 5, 0, 0, NULL);
 
+	if (cmd_result < 0) {
+		rc = cmd_result;
+		goto error;
+	}
 	if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */
 		u8 *desc = sensebuf + 8;
 		cmd_result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */
@@ -490,6 +494,10 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
 	cmd_result = scsi_execute(scsidev, scsi_cmd, DMA_NONE, NULL, 0,
 				sensebuf, &sshdr, (10*HZ), 5, 0, 0, NULL);
 
+	if (cmd_result < 0) {
+		rc = cmd_result;
+		goto error;
+	}
 	if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */
 		u8 *desc = sensebuf + 8;
 		cmd_result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */
diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index cb74ab1ae5a4..0e7d1214c3d8 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -198,7 +198,8 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd, int cmd_len,
 	result = scsi_execute_req(ch->device, cmd, direction, buffer,
 				  buflength, &sshdr, timeout * HZ,
 				  MAX_RETRIES, NULL);
-
+	if (result < 0)
+		return result;
 	if (driver_byte(result) == DRIVER_SENSE) {
 		if (debug)
 			scsi_print_sense_hdr(ch->device, ch->name, &sshdr);
diff --git a/drivers/scsi/cxlflash/superpipe.c b/drivers/scsi/cxlflash/superpipe.c
index ee11ec340654..caa7c5fd233d 100644
--- a/drivers/scsi/cxlflash/superpipe.c
+++ b/drivers/scsi/cxlflash/superpipe.c
@@ -369,7 +369,7 @@ static int read_cap16(struct scsi_device *sdev, struct llun_info *lli)
 		goto out;
 	}
 
-	if (driver_byte(result) == DRIVER_SENSE) {
+	if (result > 0 && driver_byte(result) == DRIVER_SENSE) {
 		result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */
 		if (result & SAM_STAT_CHECK_CONDITION) {
 			switch (sshdr.sense_key) {
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index e9e2f0e15ac8..99dc6ec0b6e5 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -508,6 +508,8 @@ int scsi_report_opcode(struct scsi_device *sdev, unsigned char *buffer,
 	result = scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, buffer, len,
 				  &sshdr, 30 * HZ, 3, NULL);
 
+	if (result < 0)
+		return result;
 	if (result && scsi_sense_valid(&sshdr) &&
 	    sshdr.sense_key == ILLEGAL_REQUEST &&
 	    (sshdr.asc == 0x20 || sshdr.asc == 0x24) && sshdr.ascq == 0x00)
diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c
index 14872c9dc78c..d34e1b41dc71 100644
--- a/drivers/scsi/scsi_ioctl.c
+++ b/drivers/scsi/scsi_ioctl.c
@@ -101,6 +101,8 @@ static int ioctl_internal_command(struct scsi_device *sdev, char *cmd,
 	SCSI_LOG_IOCTL(2, sdev_printk(KERN_INFO, sdev,
 				      "Ioctl returned  0x%x\n", result));
 
+	if (result < 0)
+		goto out;
 	if (driver_byte(result) == DRIVER_SENSE &&
 	    scsi_sense_valid(&sshdr)) {
 		switch (sshdr.sense_key) {
@@ -133,7 +135,7 @@ static int ioctl_internal_command(struct scsi_device *sdev, char *cmd,
 			break;
 		}
 	}
-
+out:
 	SCSI_LOG_IOCTL(2, sdev_printk(KERN_INFO, sdev,
 				      "IOCTL Releasing command\n"));
 	return result;
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index c532f9390ae3..2d9b533ef1ec 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -245,20 +245,23 @@ int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
 {
 	struct request *req;
 	struct scsi_request *rq;
-	int ret = DRIVER_ERROR << 24;
+	int ret;
 
 	req = blk_get_request(sdev->request_queue,
 			data_direction == DMA_TO_DEVICE ?
 			REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN,
 			rq_flags & RQF_PM ? BLK_MQ_REQ_PM : 0);
 	if (IS_ERR(req))
-		return ret;
-	rq = scsi_req(req);
+		return PTR_ERR(req);
 
-	if (bufflen &&	blk_rq_map_kern(sdev->request_queue, req,
-					buffer, bufflen, GFP_NOIO))
-		goto out;
+	rq = scsi_req(req);
 
+	if (bufflen) {
+		ret = blk_rq_map_kern(sdev->request_queue, req,
+				      buffer, bufflen, GFP_NOIO);
+		if (ret)
+			goto out;
+	}
 	rq->cmd_len = COMMAND_SIZE(cmd[0]);
 	memcpy(rq->cmd, cmd, rq->cmd_len);
 	rq->retries = retries;
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 9f1b7f3c650a..493f17bf26f2 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -616,7 +616,7 @@ static int scsi_probe_lun(struct scsi_device *sdev, unsigned char *inq_result,
 				"scsi scan: INQUIRY %s with code 0x%x\n",
 				result ? "failed" : "successful", result));
 
-		if (result) {
+		if (result > 0) {
 			/*
 			 * not-ready to ready transition [asc/ascq=0x28/0x0]
 			 * or power-on, reset [asc/ascq=0x29/0x0], continue.
@@ -631,7 +631,7 @@ static int scsi_probe_lun(struct scsi_device *sdev, unsigned char *inq_result,
 				    (sshdr.ascq == 0))
 					continue;
 			}
-		} else {
+		} else if (result == 0) {
 			/*
 			 * if nothing was transferred, we try
 			 * again. It's a workaround for some USB
diff --git a/drivers/scsi/scsi_transport_spi.c b/drivers/scsi/scsi_transport_spi.c
index c37dd15d16d2..a9bb7ae2fafd 100644
--- a/drivers/scsi/scsi_transport_spi.c
+++ b/drivers/scsi/scsi_transport_spi.c
@@ -127,7 +127,7 @@ static int spi_execute(struct scsi_device *sdev, const void *cmd,
 				      REQ_FAILFAST_TRANSPORT |
 				      REQ_FAILFAST_DRIVER,
 				      RQF_PM, NULL);
-		if (driver_byte(result) != DRIVER_SENSE ||
+		if (result < 0 || driver_byte(result) != DRIVER_SENSE ||
 		    sshdr->sense_key != UNIT_ATTENTION)
 			break;
 	}
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 2ef2954375f4..5733fbee2bae 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1658,7 +1658,7 @@ static unsigned int sd_check_events(struct gendisk *disk, unsigned int clearing)
 					      &sshdr);
 
 		/* failed to execute TUR, assume media not present */
-		if (host_byte(retval)) {
+		if (retval < 0 || host_byte(retval)) {
 			set_media_not_present(sdkp);
 			goto out;
 		}
@@ -1719,6 +1719,9 @@ static int sd_sync_cache(struct scsi_disk *sdkp, struct scsi_sense_hdr *sshdr)
 	if (res) {
 		sd_print_result(sdkp, "Synchronize Cache(10) failed", res);
 
+		if (res < 0)
+			return res;
+
 		if (driver_byte(res) == DRIVER_SENSE)
 			sd_print_sense_hdr(sdkp, sshdr);
 
@@ -1825,7 +1828,7 @@ static int sd_pr_command(struct block_device *bdev, u8 sa,
 	result = scsi_execute_req(sdev, cmd, DMA_TO_DEVICE, &data, sizeof(data),
 			&sshdr, SD_TIMEOUT, sdkp->max_retries, NULL);
 
-	if (driver_byte(result) == DRIVER_SENSE &&
+	if (result > 0 && driver_byte(result) == DRIVER_SENSE &&
 	    scsi_sense_valid(&sshdr)) {
 		sdev_printk(KERN_INFO, sdev, "PR command failed: %d\n", result);
 		scsi_print_sense_hdr(sdev, NULL, &sshdr);
@@ -2177,7 +2180,7 @@ sd_spinup_disk(struct scsi_disk *sdkp)
 			  ((driver_byte(the_result) == DRIVER_SENSE) &&
 			  sense_valid && sshdr.sense_key == UNIT_ATTENTION)));
 
-		if (driver_byte(the_result) != DRIVER_SENSE) {
+		if (the_result < 0 || driver_byte(the_result) != DRIVER_SENSE) {
 			/* no sense, TUR either succeeded or failed
 			 * with a status error */
 			if(!spintime && !scsi_status_is_good(the_result)) {
@@ -2362,7 +2365,7 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,
 		if (media_not_present(sdkp, &sshdr))
 			return -ENODEV;
 
-		if (the_result) {
+		if (the_result > 0) {
 			sense_valid = scsi_sense_valid(&sshdr);
 			if (sense_valid &&
 			    sshdr.sense_key == ILLEGAL_REQUEST &&
@@ -2447,7 +2450,7 @@ static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp,
 		if (media_not_present(sdkp, &sshdr))
 			return -ENODEV;
 
-		if (the_result) {
+		if (the_result > 0) {
 			sense_valid = scsi_sense_valid(&sshdr);
 			if (sense_valid &&
 			    sshdr.sense_key == UNIT_ATTENTION &&
@@ -3591,7 +3594,7 @@ static int sd_start_stop_device(struct scsi_disk *sdkp, int start)
 			SD_TIMEOUT, sdkp->max_retries, 0, RQF_PM, NULL);
 	if (res) {
 		sd_print_result(sdkp, "Start/Stop Unit failed", res);
-		if (driver_byte(res) == DRIVER_SENSE)
+		if (res > 0 && driver_byte(res) == DRIVER_SENSE)
 			sd_print_sense_hdr(sdkp, &sshdr);
 		if (scsi_sense_valid(&sshdr) &&
 			/* 0x3a is medium not present */
diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c
index e45d8d94574c..d4a79fdcfffe 100644
--- a/drivers/scsi/sd_zbc.c
+++ b/drivers/scsi/sd_zbc.c
@@ -116,7 +116,7 @@ static int sd_zbc_do_report_zones(struct scsi_disk *sdkp, unsigned char *buf,
 		sd_printk(KERN_ERR, sdkp,
 			  "REPORT ZONES start lba %llu failed\n", lba);
 		sd_print_result(sdkp, "REPORT ZONES", result);
-		if (driver_byte(result) == DRIVER_SENSE &&
+		if (result > 0 && driver_byte(result) == DRIVER_SENSE &&
 		    scsi_sense_valid(&sshdr))
 			sd_print_sense_hdr(sdkp, &sshdr);
 		return -EIO;
diff --git a/drivers/scsi/sr_ioctl.c b/drivers/scsi/sr_ioctl.c
index 5703f8400b73..a78f2138d784 100644
--- a/drivers/scsi/sr_ioctl.c
+++ b/drivers/scsi/sr_ioctl.c
@@ -205,6 +205,10 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
 			      cgc->timeout, IOCTL_RETRIES, 0, 0, NULL);
 
 	/* Minimal error checking.  Ignore cases we know about, and report the rest. */
+	if (result < 0) {
+		err = result;
+		goto out;
+	}
 	if (driver_byte(result) != 0) {
 		switch (sshdr->sense_key) {
 		case UNIT_ATTENTION:
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 0625da7a42ee..f743434073ac 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -8487,7 +8487,7 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba,
 		sdev_printk(KERN_WARNING, sdp,
 			    "START_STOP failed for power mode: %d, result %x\n",
 			    pwr_mode, ret);
-		if (driver_byte(ret) == DRIVER_SENSE)
+		if (ret > 0 && driver_byte(ret) == DRIVER_SENSE)
 			scsi_print_sense_hdr(sdp, NULL, &sshdr);
 	}
 
diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
index b9c86a7e3b97..1678b6f14af9 100644
--- a/drivers/scsi/virtio_scsi.c
+++ b/drivers/scsi/virtio_scsi.c
@@ -355,7 +355,7 @@ static void virtscsi_rescan_hotunplug(struct virtio_scsi *vscsi)
 		if (result == 0 && inq_result[0] >> 5) {
 			/* PQ indicates the LUN is not attached */
 			scsi_remove_device(sdev);
-		} else if (host_byte(result) == DID_BAD_TARGET) {
+		} else if (result > 0 && host_byte(result) == DID_BAD_TARGET) {
 			/*
 			 * If all LUNs of a virtio-scsi device are unplugged
 			 * it will respond with BAD TARGET on any INQUIRY
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
index 246ced401683..d0a24e55ad63 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -40,6 +40,9 @@ enum scsi_timeouts {
  */
 static inline int scsi_status_is_good(int status)
 {
+	if (status < 0)
+		return false;
+
 	/*
 	 * FIXME: bit0 is listed as reserved in SCSI-2, but is
 	 * significant in SCSI-3.  For now, we follow the SCSI-2
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 06/42] scsi: introduce scsi_build_sense()
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (4 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 05/42] scsi: stop using DRIVER_ERROR Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 07/42] scsi: Kill DRIVER_SENSE Hannes Reinecke
                   ` (37 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Introduce scsi_build_sense() as a wrapper around
scsi_build_sense_buffer() to format the buffer and set
the correct SCSI status.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/ata/libata-scsi.c             |  7 +--
 drivers/s390/scsi/zfcp_scsi.c         |  5 +--
 drivers/scsi/3w-xxxx.c                |  2 +-
 drivers/scsi/libiscsi.c               |  5 +--
 drivers/scsi/lpfc/lpfc_scsi.c         | 54 ++++++++--------------
 drivers/scsi/megaraid.c               |  8 ++--
 drivers/scsi/megaraid/megaraid_mbox.c | 14 +++---
 drivers/scsi/mpt3sas/mpt3sas_scsih.c  | 14 ++----
 drivers/scsi/mvumi.c                  |  5 +--
 drivers/scsi/myrb.c                   | 64 +++++++--------------------
 drivers/scsi/myrs.c                   |  9 +---
 drivers/scsi/ps3rom.c                 |  7 +--
 drivers/scsi/qla2xxx/qla_isr.c        | 15 ++-----
 drivers/scsi/scsi_debug.c             | 11 ++---
 drivers/scsi/scsi_lib.c               | 18 ++++++++
 drivers/scsi/smartpqi/smartpqi_init.c |  3 +-
 drivers/scsi/stex.c                   |  5 +--
 include/scsi/scsi_cmnd.h              |  3 ++
 18 files changed, 85 insertions(+), 164 deletions(-)

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index c5129b9e3afd..10d0ef9e969d 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -196,9 +196,7 @@ void ata_scsi_set_sense(struct ata_device *dev, struct scsi_cmnd *cmd,
 	if (!cmd)
 		return;
 
-	cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
-
-	scsi_build_sense_buffer(d_sense, cmd->sense_buffer, sk, asc, ascq);
+	scsi_build_sense(cmd, d_sense, sk, asc, ascq);
 }
 
 void ata_scsi_set_sense_information(struct ata_device *dev,
@@ -882,8 +880,7 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc)
 		 * ATA PASS-THROUGH INFORMATION AVAILABLE
 		 * Always in descriptor format sense.
 		 */
-		scsi_build_sense_buffer(1, cmd->sense_buffer,
-					RECOVERED_ERROR, 0, 0x1D);
+		scsi_build_sense(cmd, 1, RECOVERED_ERROR, 0, 0x1D);
 	}
 
 	if ((cmd->sense_buffer[0] & 0x7f) >= 0x72) {
diff --git a/drivers/s390/scsi/zfcp_scsi.c b/drivers/s390/scsi/zfcp_scsi.c
index d58bf79892f2..9da9b2b2a580 100644
--- a/drivers/s390/scsi/zfcp_scsi.c
+++ b/drivers/s390/scsi/zfcp_scsi.c
@@ -856,10 +856,7 @@ void zfcp_scsi_set_prot(struct zfcp_adapter *adapter)
  */
 void zfcp_scsi_dif_sense_error(struct scsi_cmnd *scmd, int ascq)
 {
-	scsi_build_sense_buffer(1, scmd->sense_buffer,
-				ILLEGAL_REQUEST, 0x10, ascq);
-	set_driver_byte(scmd, DRIVER_SENSE);
-	scmd->result |= SAM_STAT_CHECK_CONDITION;
+	scsi_build_sense(scmd, 1, ILLEGAL_REQUEST, 0x10, ascq);
 	set_host_byte(scmd, DID_SOFT_ERROR);
 }
 
diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
index a7292883b72b..7a0b4a44395d 100644
--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -1977,7 +1977,7 @@ static int tw_scsi_queue_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_c
 		printk(KERN_NOTICE "3w-xxxx: scsi%d: Unknown scsi opcode: 0x%x\n", tw_dev->host->host_no, *command);
 		tw_dev->state[request_id] = TW_S_COMPLETED;
 		tw_state_request_finish(tw_dev, request_id);
-		scsi_build_sense_buffer(1, SCpnt->sense_buffer, ILLEGAL_REQUEST, 0x20, 0);
+		scsi_build_sense(SCpnt, 1, ILLEGAL_REQUEST, 0x20, 0);
 		done(SCpnt);
 		retval = 0;
 	}
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 7ad11e42306d..3a485ad0204e 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -829,10 +829,7 @@ static void iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
 
 		ascq = session->tt->check_protection(task, &sector);
 		if (ascq) {
-			sc->result = DRIVER_SENSE << 24 |
-				     SAM_STAT_CHECK_CONDITION;
-			scsi_build_sense_buffer(1, sc->sense_buffer,
-						ILLEGAL_REQUEST, 0x10, ascq);
+			scsi_build_sense(sc, 1, ILLEGAL_REQUEST, 0x10, ascq);
 			scsi_set_sense_information(sc->sense_buffer,
 						   SCSI_SENSE_BUFFERSIZE,
 						   sector);
diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index eefbb9b22798..c478f1b45006 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -2869,10 +2869,8 @@ lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
 	}
 out:
 	if (err_type == BGS_GUARD_ERR_MASK) {
-		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
-					0x10, 0x1);
-		cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
-			      SAM_STAT_CHECK_CONDITION;
+		scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x1);
+		set_host_byte(cmd, DID_ABORT);
 		phba->bg_guard_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
 				"9069 BLKGRD: reftag %x grd_tag err %x != %x\n",
@@ -2880,10 +2878,8 @@ lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
 				sum, guard_tag);
 
 	} else if (err_type == BGS_REFTAG_ERR_MASK) {
-		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
-					0x10, 0x3);
-		cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
-			      SAM_STAT_CHECK_CONDITION;
+		scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x3);
+		set_host_byte(cmd, DID_ABORT);
 
 		phba->bg_reftag_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
@@ -2892,10 +2888,8 @@ lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
 				ref_tag, start_ref_tag);
 
 	} else if (err_type == BGS_APPTAG_ERR_MASK) {
-		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
-					0x10, 0x2);
-		cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
-			      SAM_STAT_CHECK_CONDITION;
+		scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x2);
+		set_host_byte(cmd, DID_ABORT);
 
 		phba->bg_apptag_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
@@ -2954,10 +2948,8 @@ lpfc_sli4_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 	if (lpfc_bgs_get_guard_err(bgstat)) {
 		ret = 1;
 
-		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
-					0x10, 0x1);
-		cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
-			      SAM_STAT_CHECK_CONDITION;
+		scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x1);
+		set_host_byte(cmd, DID_ABORT);
 		phba->bg_guard_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
 				"9059 BLKGRD: Guard Tag error in cmd"
@@ -2970,10 +2962,8 @@ lpfc_sli4_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 	if (lpfc_bgs_get_reftag_err(bgstat)) {
 		ret = 1;
 
-		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
-					0x10, 0x3);
-		cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
-			      SAM_STAT_CHECK_CONDITION;
+		scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x3);
+		set_host_byte(cmd, DID_ABORT);
 
 		phba->bg_reftag_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
@@ -2987,10 +2977,8 @@ lpfc_sli4_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 	if (lpfc_bgs_get_apptag_err(bgstat)) {
 		ret = 1;
 
-		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
-					0x10, 0x2);
-		cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
-			      SAM_STAT_CHECK_CONDITION;
+		scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x2);
+		set_host_byte(cmd, DID_ABORT);
 
 		phba->bg_apptag_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
@@ -3100,10 +3088,8 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 	if (lpfc_bgs_get_guard_err(bgstat)) {
 		ret = 1;
 
-		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
-				0x10, 0x1);
-		cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
-			      SAM_STAT_CHECK_CONDITION;
+		scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x1);
+		set_host_byte(cmd, DID_ABORT);
 		phba->bg_guard_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
 				"9055 BLKGRD: Guard Tag error in cmd "
@@ -3116,10 +3102,8 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 	if (lpfc_bgs_get_reftag_err(bgstat)) {
 		ret = 1;
 
-		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
-				0x10, 0x3);
-		cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
-			      SAM_STAT_CHECK_CONDITION;
+		scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x3);
+		set_host_byte(cmd, DID_ABORT);
 
 		phba->bg_reftag_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
@@ -3133,10 +3117,8 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 	if (lpfc_bgs_get_apptag_err(bgstat)) {
 		ret = 1;
 
-		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
-				0x10, 0x2);
-		cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
-			      SAM_STAT_CHECK_CONDITION;
+		scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x2);
+		set_host_byte(cmd, DID_ABORT);
 
 		phba->bg_apptag_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index 80f546976c7e..ae3f32f89381 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -1596,11 +1596,9 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
 					cmd->result = (DRIVER_SENSE << 24) |
 						(DID_OK << 16) |
 						(CHECK_CONDITION << 1);
-				} else {
-					cmd->sense_buffer[0] = 0x70;
-					cmd->sense_buffer[2] = ABORTED_COMMAND;
-					cmd->result |= (CHECK_CONDITION << 1);
-				}
+				} else
+					scsi_build_sense(cmd, 0,
+							 ABORTED_COMMAND, 0, 0);
 			}
 			break;
 
diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
index b1a2d3536add..6a5b844a8499 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -1574,10 +1574,8 @@ megaraid_mbox_build_cmd(adapter_t *adapter, struct scsi_cmnd *scp, int *busy)
 			}
 
 			if (scp->cmnd[1] & MEGA_SCSI_INQ_EVPD) {
-				scp->sense_buffer[0] = 0x70;
-				scp->sense_buffer[2] = ILLEGAL_REQUEST;
-				scp->sense_buffer[12] = MEGA_INVALID_FIELD_IN_CDB;
-				scp->result = CHECK_CONDITION << 1;
+				scsi_build_sense(scp, 0, ILLEGAL_REQUEST,
+						 MEGA_INVALID_FIELD_IN_CDB, 0);
 				return NULL;
 			}
 
@@ -2313,11 +2311,9 @@ megaraid_mbox_dpc(unsigned long devp)
 					scp->result = DRIVER_SENSE << 24 |
 						DID_OK << 16 |
 						CHECK_CONDITION << 1;
-				} else {
-					scp->sense_buffer[0] = 0x70;
-					scp->sense_buffer[2] = ABORTED_COMMAND;
-					scp->result = CHECK_CONDITION << 1;
-				}
+				} else
+					scsi_build_sense(scp, 0,
+							 ABORTED_COMMAND, 0, 0);
 			}
 			break;
 
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index d00aca3c77ce..fbfbf40a3f66 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -5077,10 +5077,8 @@ _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
 		ascq = 0x00;
 		break;
 	}
-	scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
-	    ascq);
-	scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
-	    SAM_STAT_CHECK_CONDITION;
+	scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x10, ascq);
+	set_host_byte(scmd, DID_ABORT);
 }
 
 /**
@@ -5837,12 +5835,8 @@ _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
 		else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
 			mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
 			mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
-			scmd->result = (DRIVER_SENSE << 24) |
-			    SAM_STAT_CHECK_CONDITION;
-			scmd->sense_buffer[0] = 0x70;
-			scmd->sense_buffer[2] = ILLEGAL_REQUEST;
-			scmd->sense_buffer[12] = 0x20;
-			scmd->sense_buffer[13] = 0;
+			scsi_build_sense(scmd, 0, ILLEGAL_REQUEST,
+					 0x20, 0);
 		}
 		break;
 
diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index 9d5743627604..94f706eeb561 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -2068,10 +2068,7 @@ static unsigned char mvumi_build_frame(struct mvumi_hba *mhba,
 	return 0;
 
 error:
-	scmd->result = (DID_OK << 16) | (DRIVER_SENSE << 24) |
-		SAM_STAT_CHECK_CONDITION;
-	scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x24,
-									0);
+	scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x24, 0);
 	return -1;
 }
 
diff --git a/drivers/scsi/myrb.c b/drivers/scsi/myrb.c
index d9c82e211ae7..542ed88ef90d 100644
--- a/drivers/scsi/myrb.c
+++ b/drivers/scsi/myrb.c
@@ -1397,8 +1397,7 @@ myrb_mode_sense(struct myrb_hba *cb, struct scsi_cmnd *scmd,
 static void myrb_request_sense(struct myrb_hba *cb,
 		struct scsi_cmnd *scmd)
 {
-	scsi_build_sense_buffer(0, scmd->sense_buffer,
-				NO_SENSE, 0, 0);
+	scsi_build_sense(scmd, 0, NO_SENSE, 0, 0);
 	scsi_sg_copy_from_buffer(scmd, scmd->sense_buffer,
 				 SCSI_SENSE_BUFFERSIZE);
 }
@@ -1447,10 +1446,7 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost,
 	case INQUIRY:
 		if (scmd->cmnd[1] & 1) {
 			/* Illegal request, invalid field in CDB */
-			scsi_build_sense_buffer(0, scmd->sense_buffer,
-						ILLEGAL_REQUEST, 0x24, 0);
-			scmd->result = (DRIVER_SENSE << 24) |
-				SAM_STAT_CHECK_CONDITION;
+			scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x24, 0);
 		} else {
 			myrb_inquiry(cb, scmd);
 			scmd->result = (DID_OK << 16);
@@ -1465,10 +1461,7 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost,
 		if ((scmd->cmnd[2] & 0x3F) != 0x3F &&
 		    (scmd->cmnd[2] & 0x3F) != 0x08) {
 			/* Illegal request, invalid field in CDB */
-			scsi_build_sense_buffer(0, scmd->sense_buffer,
-						ILLEGAL_REQUEST, 0x24, 0);
-			scmd->result = (DRIVER_SENSE << 24) |
-				SAM_STAT_CHECK_CONDITION;
+			scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x24, 0);
 		} else {
 			myrb_mode_sense(cb, scmd, ldev_info);
 			scmd->result = (DID_OK << 16);
@@ -1479,20 +1472,14 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost,
 		if ((scmd->cmnd[1] & 1) ||
 		    (scmd->cmnd[8] & 1)) {
 			/* Illegal request, invalid field in CDB */
-			scsi_build_sense_buffer(0, scmd->sense_buffer,
-						ILLEGAL_REQUEST, 0x24, 0);
-			scmd->result = (DRIVER_SENSE << 24) |
-				SAM_STAT_CHECK_CONDITION;
+			scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x24, 0);
 			scmd->scsi_done(scmd);
 			return 0;
 		}
 		lba = get_unaligned_be32(&scmd->cmnd[2]);
 		if (lba) {
 			/* Illegal request, invalid field in CDB */
-			scsi_build_sense_buffer(0, scmd->sense_buffer,
-						ILLEGAL_REQUEST, 0x24, 0);
-			scmd->result = (DRIVER_SENSE << 24) |
-				SAM_STAT_CHECK_CONDITION;
+			scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x24, 0);
 			scmd->scsi_done(scmd);
 			return 0;
 		}
@@ -1506,10 +1493,7 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost,
 	case SEND_DIAGNOSTIC:
 		if (scmd->cmnd[1] != 0x04) {
 			/* Illegal request, invalid field in CDB */
-			scsi_build_sense_buffer(0, scmd->sense_buffer,
-						ILLEGAL_REQUEST, 0x24, 0);
-			scmd->result = (DRIVER_SENSE << 24) |
-				SAM_STAT_CHECK_CONDITION;
+			scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x24, 0);
 		} else {
 			/* Assume good status */
 			scmd->result = (DID_OK << 16);
@@ -1519,10 +1503,7 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost,
 	case READ_6:
 		if (ldev_info->state == MYRB_DEVICE_WO) {
 			/* Data protect, attempt to read invalid data */
-			scsi_build_sense_buffer(0, scmd->sense_buffer,
-						DATA_PROTECT, 0x21, 0x06);
-			scmd->result = (DRIVER_SENSE << 24) |
-				SAM_STAT_CHECK_CONDITION;
+			scsi_build_sense(scmd, 0, DATA_PROTECT, 0x21, 0x06);
 			scmd->scsi_done(scmd);
 			return 0;
 		}
@@ -1536,10 +1517,7 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost,
 	case READ_10:
 		if (ldev_info->state == MYRB_DEVICE_WO) {
 			/* Data protect, attempt to read invalid data */
-			scsi_build_sense_buffer(0, scmd->sense_buffer,
-						DATA_PROTECT, 0x21, 0x06);
-			scmd->result = (DRIVER_SENSE << 24) |
-				SAM_STAT_CHECK_CONDITION;
+			scsi_build_sense(scmd, 0, DATA_PROTECT, 0x21, 0x06);
 			scmd->scsi_done(scmd);
 			return 0;
 		}
@@ -1553,10 +1531,7 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost,
 	case READ_12:
 		if (ldev_info->state == MYRB_DEVICE_WO) {
 			/* Data protect, attempt to read invalid data */
-			scsi_build_sense_buffer(0, scmd->sense_buffer,
-						DATA_PROTECT, 0x21, 0x06);
-			scmd->result = (DRIVER_SENSE << 24) |
-				SAM_STAT_CHECK_CONDITION;
+			scsi_build_sense(scmd, 0, DATA_PROTECT, 0x21, 0x06);
 			scmd->scsi_done(scmd);
 			return 0;
 		}
@@ -1569,9 +1544,7 @@ static int myrb_ldev_queuecommand(struct Scsi_Host *shost,
 		break;
 	default:
 		/* Illegal request, invalid opcode */
-		scsi_build_sense_buffer(0, scmd->sense_buffer,
-					ILLEGAL_REQUEST, 0x20, 0);
-		scmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
+		scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x20, 0);
 		scmd->scsi_done(scmd);
 		return 0;
 	}
@@ -2352,25 +2325,19 @@ static void myrb_handle_scsi(struct myrb_hba *cb, struct myrb_cmdblk *cmd_blk,
 			"Bad Data Encountered\n");
 		if (scmd->sc_data_direction == DMA_FROM_DEVICE)
 			/* Unrecovered read error */
-			scsi_build_sense_buffer(0, scmd->sense_buffer,
-						MEDIUM_ERROR, 0x11, 0);
+			scsi_build_sense(scmd, 0, MEDIUM_ERROR, 0x11, 0);
 		else
 			/* Write error */
-			scsi_build_sense_buffer(0, scmd->sense_buffer,
-						MEDIUM_ERROR, 0x0C, 0);
-		scmd->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
+			scsi_build_sense(scmd, 0, MEDIUM_ERROR, 0x0C, 0);
 		break;
 	case MYRB_STATUS_IRRECOVERABLE_DATA_ERROR:
 		scmd_printk(KERN_ERR, scmd, "Irrecoverable Data Error\n");
 		if (scmd->sc_data_direction == DMA_FROM_DEVICE)
 			/* Unrecovered read error, auto-reallocation failed */
-			scsi_build_sense_buffer(0, scmd->sense_buffer,
-						MEDIUM_ERROR, 0x11, 0x04);
+			scsi_build_sense(scmd, 0, MEDIUM_ERROR, 0x11, 0x04);
 		else
 			/* Write error, auto-reallocation failed */
-			scsi_build_sense_buffer(0, scmd->sense_buffer,
-						MEDIUM_ERROR, 0x0C, 0x02);
-		scmd->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
+			scsi_build_sense(scmd, 0, MEDIUM_ERROR, 0x0C, 0x02);
 		break;
 	case MYRB_STATUS_LDRV_NONEXISTENT_OR_OFFLINE:
 		dev_dbg(&scmd->device->sdev_gendev,
@@ -2381,8 +2348,7 @@ static void myrb_handle_scsi(struct myrb_hba *cb, struct myrb_cmdblk *cmd_blk,
 		dev_dbg(&scmd->device->sdev_gendev,
 			    "Attempt to Access Beyond End of Logical Drive");
 		/* Logical block address out of range */
-		scsi_build_sense_buffer(0, scmd->sense_buffer,
-					NOT_READY, 0x21, 0);
+		scsi_build_sense(scmd, 0, NOT_READY, 0x21, 0);
 		break;
 	case MYRB_STATUS_DEVICE_NONRESPONSIVE:
 		dev_dbg(&scmd->device->sdev_gendev, "Device nonresponsive\n");
diff --git a/drivers/scsi/myrs.c b/drivers/scsi/myrs.c
index 3b68c68d1716..26326af23dbc 100644
--- a/drivers/scsi/myrs.c
+++ b/drivers/scsi/myrs.c
@@ -1600,9 +1600,7 @@ static int myrs_queuecommand(struct Scsi_Host *shost,
 
 	switch (scmd->cmnd[0]) {
 	case REPORT_LUNS:
-		scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST,
-					0x20, 0x0);
-		scmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
+		scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x20, 0x0);
 		scmd->scsi_done(scmd);
 		return 0;
 	case MODE_SENSE:
@@ -1612,10 +1610,7 @@ static int myrs_queuecommand(struct Scsi_Host *shost,
 			if ((scmd->cmnd[2] & 0x3F) != 0x3F &&
 			    (scmd->cmnd[2] & 0x3F) != 0x08) {
 				/* Illegal request, invalid field in CDB */
-				scsi_build_sense_buffer(0, scmd->sense_buffer,
-					ILLEGAL_REQUEST, 0x24, 0);
-				scmd->result = (DRIVER_SENSE << 24) |
-					SAM_STAT_CHECK_CONDITION;
+				scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x24, 0);
 			} else {
 				myrs_mode_sense(cs, scmd, ldev_info);
 				scmd->result = (DID_OK << 16);
diff --git a/drivers/scsi/ps3rom.c b/drivers/scsi/ps3rom.c
index ccb5771f1cb7..0f4b99d92f12 100644
--- a/drivers/scsi/ps3rom.c
+++ b/drivers/scsi/ps3rom.c
@@ -234,10 +234,8 @@ static int ps3rom_queuecommand_lck(struct scsi_cmnd *cmd,
 	}
 
 	if (res) {
-		memset(cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
+		scsi_build_sense(cmd, 0, ILLEGAL_REQUEST, 0, 0);
 		cmd->result = res;
-		cmd->sense_buffer[0] = 0x70;
-		cmd->sense_buffer[2] = ILLEGAL_REQUEST;
 		priv->curr_cmd = NULL;
 		cmd->scsi_done(cmd);
 	}
@@ -319,8 +317,7 @@ static irqreturn_t ps3rom_interrupt(int irq, void *data)
 		goto done;
 	}
 
-	scsi_build_sense_buffer(0, cmd->sense_buffer, sense_key, asc, ascq);
-	cmd->result = SAM_STAT_CHECK_CONDITION;
+	scsi_build_sense(cmd, 0, sense_key, asc, ascq);
 
 done:
 	priv->curr_cmd = NULL;
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index 6e8f737a4af3..19fe2c1659d0 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -2694,31 +2694,22 @@ qla2x00_handle_dif_error(srb_t *sp, struct sts_entry_24xx *sts24)
 
 	/* check guard */
 	if (e_guard != a_guard) {
-		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
-		    0x10, 0x1);
-		set_driver_byte(cmd, DRIVER_SENSE);
+		scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x1);
 		set_host_byte(cmd, DID_ABORT);
-		cmd->result |= SAM_STAT_CHECK_CONDITION;
 		return 1;
 	}
 
 	/* check ref tag */
 	if (e_ref_tag != a_ref_tag) {
-		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
-		    0x10, 0x3);
-		set_driver_byte(cmd, DRIVER_SENSE);
+		scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x3);
 		set_host_byte(cmd, DID_ABORT);
-		cmd->result |= SAM_STAT_CHECK_CONDITION;
 		return 1;
 	}
 
 	/* check appl tag */
 	if (e_app_tag != a_app_tag) {
-		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
-		    0x10, 0x2);
-		set_driver_byte(cmd, DRIVER_SENSE);
+		scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x2);
 		set_host_byte(cmd, DID_ABORT);
-		cmd->result |= SAM_STAT_CHECK_CONDITION;
 		return 1;
 	}
 
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 70165be10f00..f7e72d21749a 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -931,7 +931,7 @@ static void mk_sense_invalid_fld(struct scsi_cmnd *scp,
 	}
 	asc = c_d ? INVALID_FIELD_IN_CDB : INVALID_FIELD_IN_PARAM_LIST;
 	memset(sbuff, 0, SCSI_SENSE_BUFFERSIZE);
-	scsi_build_sense_buffer(sdebug_dsense, sbuff, ILLEGAL_REQUEST, asc, 0);
+	scsi_build_sense(scp, sdebug_dsense, ILLEGAL_REQUEST, asc, 0);
 	memset(sks, 0, sizeof(sks));
 	sks[0] = 0x80;
 	if (c_d)
@@ -957,17 +957,14 @@ static void mk_sense_invalid_fld(struct scsi_cmnd *scp,
 
 static void mk_sense_buffer(struct scsi_cmnd *scp, int key, int asc, int asq)
 {
-	unsigned char *sbuff;
-
-	sbuff = scp->sense_buffer;
-	if (!sbuff) {
+	if (!scp->sense_buffer) {
 		sdev_printk(KERN_ERR, scp->device,
 			    "%s: sense_buffer is NULL\n", __func__);
 		return;
 	}
-	memset(sbuff, 0, SCSI_SENSE_BUFFERSIZE);
+	memset(scp->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
 
-	scsi_build_sense_buffer(sdebug_dsense, sbuff, key, asc, asq);
+	scsi_build_sense(scp, sdebug_dsense, key, asc, asq);
 
 	if (sdebug_verbose)
 		sdev_printk(KERN_INFO, scp->device,
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 2d9b533ef1ec..d72f15f6c225 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -3265,3 +3265,21 @@ int scsi_vpd_tpg_id(struct scsi_device *sdev, int *rel_id)
 	return group_id;
 }
 EXPORT_SYMBOL(scsi_vpd_tpg_id);
+
+/**
+ * scsi_build_sense - build sense data for a command
+ * @scmd:	scsi command for which the sense should be formatted
+ * @desc:	Sense format (non-zero == descriptor format,
+ *              0 == fixed format)
+ * @key:	Sense key
+ * @asc:	Additional sense code
+ * @ascq:	Additional sense code qualifier
+ *
+ **/
+void scsi_build_sense(struct scsi_cmnd *scmd, int desc, u8 key, u8 asc, u8 ascq)
+{
+	scsi_build_sense_buffer(desc, scmd->sense_buffer, key, asc, ascq);
+	scmd->result = (DRIVER_SENSE << 24) | (DID_OK << 16) |
+		SAM_STAT_CHECK_CONDITION;
+}
+EXPORT_SYMBOL_GPL(scsi_build_sense);
diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c
index 25c0409e98df..a112d9c3c548 100644
--- a/drivers/scsi/smartpqi/smartpqi_init.c
+++ b/drivers/scsi/smartpqi/smartpqi_init.c
@@ -3088,8 +3088,7 @@ static void pqi_process_aio_io_error(struct pqi_io_request *io_request)
 	}
 
 	if (device_offline && sense_data_length == 0)
-		scsi_build_sense_buffer(0, scmd->sense_buffer, HARDWARE_ERROR,
-			0x3e, 0x1);
+		scsi_build_sense(scmd, 0, HARDWARE_ERROR, 0x3e, 0x1);
 
 	scmd->result = scsi_status;
 	set_host_byte(scmd, host_byte);
diff --git a/drivers/scsi/stex.c b/drivers/scsi/stex.c
index 12471208c7a8..3af2a2d3bfa2 100644
--- a/drivers/scsi/stex.c
+++ b/drivers/scsi/stex.c
@@ -398,11 +398,8 @@ static struct status_msg *stex_get_status(struct st_hba *hba)
 static void stex_invalid_field(struct scsi_cmnd *cmd,
 			       void (*done)(struct scsi_cmnd *))
 {
-	cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
-
 	/* "Invalid field in cdb" */
-	scsi_build_sense_buffer(0, cmd->sense_buffer, ILLEGAL_REQUEST, 0x24,
-				0x0);
+	scsi_build_sense(cmd, 0, ILLEGAL_REQUEST, 0x24, 0x0);
 	done(cmd);
 }
 
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index 83f7e520be48..b3eaf4b74b72 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -342,4 +342,7 @@ static inline unsigned scsi_transfer_length(struct scsi_cmnd *scmd)
 	return xfer_len;
 }
 
+extern void scsi_build_sense(struct scsi_cmnd *scmd, int desc,
+			     u8 key, u8 asc, u8 ascq);
+
 #endif /* _SCSI_SCSI_CMND_H */
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 07/42] scsi: Kill DRIVER_SENSE
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (5 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 06/42] scsi: introduce scsi_build_sense() Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 19:46   ` Douglas Gilbert
  2021-04-21 21:06   ` Bart Van Assche
  2021-04-21 17:47 ` [PATCH 08/42] scsi: do not use DRIVER_INVALID Hannes Reinecke
                   ` (36 subsequent siblings)
  43 siblings, 2 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Replace the check for DRIVER_SENSE with a check for
SAM_STAT_CHECK_CONDITION and audit all callsites to
ensure the SAM status is set correctly.
For backwards compability move the DRIVER_SENSE definition
to sg.h, and update the sg driver to set the DRIVER_SENSE
driver_status whenever SAM_STAT_CHECK_CONDITION is present.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/ata/libata-scsi.c                   | 13 ++------
 drivers/scsi/NCR5380.c                      |  2 +-
 drivers/scsi/advansys.c                     |  2 --
 drivers/scsi/aic7xxx/aic79xx_osm.c          | 19 +++++-------
 drivers/scsi/aic7xxx/aic7xxx_osm.c          |  1 -
 drivers/scsi/arcmsr/arcmsr_hba.c            |  1 -
 drivers/scsi/ch.c                           |  2 +-
 drivers/scsi/cxlflash/superpipe.c           |  3 +-
 drivers/scsi/dc395x.c                       | 13 ++------
 drivers/scsi/esp_scsi.c                     |  4 +--
 drivers/scsi/megaraid.c                     | 10 +++---
 drivers/scsi/megaraid/megaraid_mbox.c       |  8 ++---
 drivers/scsi/megaraid/megaraid_sas_base.c   |  2 --
 drivers/scsi/megaraid/megaraid_sas_fusion.c |  1 -
 drivers/scsi/mvumi.c                        |  1 -
 drivers/scsi/scsi.c                         |  7 -----
 drivers/scsi/scsi_debug.c                   |  4 +--
 drivers/scsi/scsi_ioctl.c                   |  3 +-
 drivers/scsi/scsi_lib.c                     |  9 ++----
 drivers/scsi/scsi_scan.c                    |  2 +-
 drivers/scsi/scsi_transport_spi.c           |  2 +-
 drivers/scsi/sd.c                           | 34 +++++++++++----------
 drivers/scsi/sd_zbc.c                       |  3 +-
 drivers/scsi/sg.c                           |  9 ++++--
 drivers/scsi/stex.c                         |  4 +--
 drivers/scsi/sym53c8xx_2/sym_glue.c         |  6 ++--
 drivers/scsi/ufs/ufshcd.c                   |  2 +-
 drivers/scsi/virtio_scsi.c                  |  3 +-
 drivers/scsi/vmw_pvscsi.c                   |  3 --
 drivers/target/loopback/tcm_loop.c          |  1 -
 drivers/usb/storage/cypress_atacb.c         |  4 +--
 drivers/xen/xen-scsiback.c                  |  2 +-
 include/scsi/sg.h                           |  2 ++
 33 files changed, 68 insertions(+), 114 deletions(-)

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 10d0ef9e969d..e42c23e589ff 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -411,13 +411,12 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg)
 		rc = cmd_result;
 		goto error;
 	}
-	if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */
+	if (scsi_sense_valid(&sshdr)) {/* sense data available */
 		u8 *desc = sensebuf + 8;
-		cmd_result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */
 
 		/* If we set cc then ATA pass-through will cause a
 		 * check condition even if no error. Filter that. */
-		if (cmd_result & SAM_STAT_CHECK_CONDITION) {
+		if (status_byte(cmd_result) == SAM_STAT_CHECK_CONDITION) {
 			if (sshdr.sense_key == RECOVERED_ERROR &&
 			    sshdr.asc == 0 && sshdr.ascq == 0x1d)
 				cmd_result &= ~SAM_STAT_CHECK_CONDITION;
@@ -496,9 +495,8 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
 		rc = cmd_result;
 		goto error;
 	}
-	if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */
+	if (scsi_sense_valid(&sshdr)) {/* sense data available */
 		u8 *desc = sensebuf + 8;
-		cmd_result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */
 
 		/* If we set cc then ATA pass-through will cause a
 		 * check condition even if no error. Filter that. */
@@ -864,8 +862,6 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc)
 
 	memset(sb, 0, SCSI_SENSE_BUFFERSIZE);
 
-	cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
-
 	/*
 	 * Use ata_to_sense_error() to map status register bits
 	 * onto sense key, asc & ascq.
@@ -962,8 +958,6 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *qc)
 
 	memset(sb, 0, SCSI_SENSE_BUFFERSIZE);
 
-	cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
-
 	if (ata_dev_disabled(dev)) {
 		/* Device disabled after error recovery */
 		/* LOGICAL UNIT NOT READY, HARD RESET REQUIRED */
@@ -4202,7 +4196,6 @@ void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd)
 
 	case REQUEST_SENSE:
 		ata_scsi_set_sense(dev, cmd, 0, 0, 0);
-		cmd->result = (DRIVER_SENSE << 24);
 		break;
 
 	/* if we reach this, then writeback caching is disabled,
diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index 2ddbcaa667d1..d7594b794d3c 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -542,7 +542,7 @@ static void complete_cmd(struct Scsi_Host *instance,
 			scsi_eh_restore_cmnd(cmd, &hostdata->ses);
 		} else {
 			scsi_eh_restore_cmnd(cmd, &hostdata->ses);
-			set_driver_byte(cmd, DRIVER_SENSE);
+			set_status_byte(cmd, SAM_STAT_CHECK_CONDITION);
 		}
 		hostdata->sensing = NULL;
 	}
diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c
index e9516de8c18b..77c99fe11c81 100644
--- a/drivers/scsi/advansys.c
+++ b/drivers/scsi/advansys.c
@@ -6009,7 +6009,6 @@ static void adv_isr_callback(ADV_DVC_VAR *adv_dvc_varp, ADV_SCSI_REQ_Q *scsiqp)
 				ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
 				ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
 						  SCSI_SENSE_BUFFERSIZE);
-				set_driver_byte(scp, DRIVER_SENSE);
 			}
 			break;
 
@@ -6760,7 +6759,6 @@ static void asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep)
 				ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
 				ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
 						  SCSI_SENSE_BUFFERSIZE);
-				set_driver_byte(scp, DRIVER_SENSE);
 			}
 			break;
 
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c
index 4f7102f8eeb0..92ea24a075b8 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.c
@@ -1928,7 +1928,7 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
 			memcpy(cmd->sense_buffer,
 			       ahd_get_sense_buf(ahd, scb)
 			       + sense_offset, sense_size);
-			cmd->result |= (DRIVER_SENSE << 24);
+			set_status_byte(cmd, SAM_STAT_CHECK_CONDITION);
 
 #ifdef AHD_DEBUG
 			if (ahd_debug & AHD_SHOW_SENSE) {
@@ -2018,6 +2018,7 @@ ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, struct scsi_cmnd *cmd)
 	int new_status = DID_OK;
 	int do_fallback = 0;
 	int scsi_status;
+	struct scsi_sense_data *sense;
 
 	/*
 	 * Map CAM error codes into Linux Error codes.  We
@@ -2041,18 +2042,12 @@ ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, struct scsi_cmnd *cmd)
 		switch(scsi_status) {
 		case SAM_STAT_COMMAND_TERMINATED:
 		case SAM_STAT_CHECK_CONDITION:
-			if ((cmd->result >> 24) != DRIVER_SENSE) {
+			sense = (struct scsi_sense_data *)
+				cmd->sense_buffer;
+			if (sense->extra_len >= 5 &&
+			    (sense->add_sense_code == 0x47
+			     || sense->add_sense_code == 0x48))
 				do_fallback = 1;
-			} else {
-				struct scsi_sense_data *sense;
-				
-				sense = (struct scsi_sense_data *)
-					cmd->sense_buffer;
-				if (sense->extra_len >= 5 &&
-				    (sense->add_sense_code == 0x47
-				     || sense->add_sense_code == 0x48))
-					do_fallback = 1;
-			}
 			break;
 		default:
 			break;
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c
index d33f5a00bf0b..8b3d472aa3cc 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c
@@ -1838,7 +1838,6 @@ ahc_linux_handle_scsi_status(struct ahc_softc *ahc,
 			if (sense_size < SCSI_SENSE_BUFFERSIZE)
 				memset(&cmd->sense_buffer[sense_size], 0,
 				       SCSI_SENSE_BUFFERSIZE - sense_size);
-			cmd->result |= (DRIVER_SENSE << 24);
 #ifdef AHC_DEBUG
 			if (ahc_debug & AHC_SHOW_SENSE) {
 				int i;
diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index 4b79661275c9..8e4d7d0e649c 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -1335,7 +1335,6 @@ static void arcmsr_report_sense_info(struct CommandControlBlock *ccb)
 		memcpy(sensebuffer, ccb->arcmsr_cdb.SenseData, sense_data_length);
 		sensebuffer->ErrorCode = SCSI_SENSE_CURRENT_ERRORS;
 		sensebuffer->Valid = 1;
-		pcmd->result |= (DRIVER_SENSE << 24);
 	}
 }
 
diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index 0e7d1214c3d8..b8f3d6d96cf3 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -200,7 +200,7 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd, int cmd_len,
 				  MAX_RETRIES, NULL);
 	if (result < 0)
 		return result;
-	if (driver_byte(result) == DRIVER_SENSE) {
+	if (scsi_sense_valid(&sshdr)) {
 		if (debug)
 			scsi_print_sense_hdr(ch->device, ch->name, &sshdr);
 		errno = ch_find_errno(&sshdr);
diff --git a/drivers/scsi/cxlflash/superpipe.c b/drivers/scsi/cxlflash/superpipe.c
index caa7c5fd233d..df0ebabbf387 100644
--- a/drivers/scsi/cxlflash/superpipe.c
+++ b/drivers/scsi/cxlflash/superpipe.c
@@ -369,8 +369,7 @@ static int read_cap16(struct scsi_device *sdev, struct llun_info *lli)
 		goto out;
 	}
 
-	if (result > 0 && driver_byte(result) == DRIVER_SENSE) {
-		result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */
+	if (result > 0 && scsi_sense_valid(&sshdr)) {
 		if (result & SAM_STAT_CHECK_CONDITION) {
 			switch (sshdr.sense_key) {
 			case NO_SENSE:
diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
index be87d5a7583d..a713fe605dda 100644
--- a/drivers/scsi/dc395x.c
+++ b/drivers/scsi/dc395x.c
@@ -3239,16 +3239,9 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb,
 		}
 		dprintkdbg(DBG_0, "srb_done: AUTO_REQSENSE2\n");
 
-		if (srb->total_xfer_length
-		    && srb->total_xfer_length >= cmd->underflow)
-			cmd->result =
-			    MK_RES_LNX(DRIVER_SENSE, DID_OK,
-				       srb->end_message, CHECK_CONDITION);
-		/*SET_RES_DID(cmd->result,DID_OK) */
-		else
-			cmd->result =
-			    MK_RES_LNX(DRIVER_SENSE, DID_OK,
-				       srb->end_message, CHECK_CONDITION);
+		cmd->result =
+		    MK_RES(0, DID_OK,
+			   srb->end_message, SAM_STAT_CHECK_CONDITION);
 
 		goto ckc_e;
 	}
diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c
index 342535ac0570..60e27d7708a4 100644
--- a/drivers/scsi/esp_scsi.c
+++ b/drivers/scsi/esp_scsi.c
@@ -922,9 +922,7 @@ static void esp_cmd_is_done(struct esp *esp, struct esp_cmd_entry *ent,
 		 * saw originally.  Also, report that we are providing
 		 * the sense data.
 		 */
-		cmd->result = ((DRIVER_SENSE << 24) |
-			       (DID_OK << 16) |
-			       (SAM_STAT_CHECK_CONDITION << 0));
+		set_status_byte(cmd, SAM_STAT_CHECK_CONDITION);
 
 		ent->flags &= ~ESP_CMD_FLAG_AUTOSENSE;
 		if (esp_debug & ESP_DEBUG_AUTOSENSE) {
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index ae3f32f89381..c957dddf06e9 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -1583,9 +1583,8 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
 				memcpy(cmd->sense_buffer, pthru->reqsensearea,
 						14);
 
-				cmd->result = (DRIVER_SENSE << 24) |
-					(DID_OK << 16) |
-					(CHECK_CONDITION << 1);
+				cmd->result = (DID_OK << 16) |
+					SAM_STAT_CHECK_CONDITION;
 			}
 			else {
 				if (mbox->m_out.cmd == MEGA_MBOXCMD_EXTPTHRU) {
@@ -1593,9 +1592,8 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
 					memcpy(cmd->sense_buffer,
 						epthru->reqsensearea, 14);
 
-					cmd->result = (DRIVER_SENSE << 24) |
-						(DID_OK << 16) |
-						(CHECK_CONDITION << 1);
+					cmd->result = (DID_OK << 16) |
+						SAM_STAT_CHECK_CONDITION;
 				} else
 					scsi_build_sense(cmd, 0,
 							 ABORTED_COMMAND, 0, 0);
diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
index 6a5b844a8499..2b6138a7c71f 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -2299,8 +2299,7 @@ megaraid_mbox_dpc(unsigned long devp)
 				memcpy(scp->sense_buffer, pthru->reqsensearea,
 						14);
 
-				scp->result = DRIVER_SENSE << 24 |
-					DID_OK << 16 | CHECK_CONDITION << 1;
+				scp->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
 			}
 			else {
 				if (mbox->cmd == MBOXCMD_EXTPTHRU) {
@@ -2308,9 +2307,8 @@ megaraid_mbox_dpc(unsigned long devp)
 					memcpy(scp->sense_buffer,
 						epthru->reqsensearea, 14);
 
-					scp->result = DRIVER_SENSE << 24 |
-						DID_OK << 16 |
-						CHECK_CONDITION << 1;
+					scp->result = DID_OK << 16 |
+						SAM_STAT_CHECK_CONDITION;
 				} else
 					scsi_build_sense(scp, 0,
 							 ABORTED_COMMAND, 0, 0);
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index 4d4e9dbe5193..5c5fae5fc443 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -3617,8 +3617,6 @@ megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd,
 				       SCSI_SENSE_BUFFERSIZE);
 				memcpy(cmd->scmd->sense_buffer, cmd->sense,
 				       hdr->sense_len);
-
-				cmd->scmd->result |= DRIVER_SENSE << 24;
 			}
 
 			break;
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index 2221175ae051..1a4bd75229cf 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -2051,7 +2051,6 @@ map_cmd_status(struct fusion_context *fusion,
 			       SCSI_SENSE_BUFFERSIZE);
 			memcpy(scmd->sense_buffer, sense,
 			       SCSI_SENSE_BUFFERSIZE);
-			scmd->result |= DRIVER_SENSE << 24;
 		}
 
 		/*
diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index 94f706eeb561..f61250545025 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -1317,7 +1317,6 @@ static void mvumi_complete_cmd(struct mvumi_hba *mhba, struct mvumi_cmd *cmd,
 		if (ob_frame->rsp_flag & CL_RSP_FLAG_SENSEDATA) {
 			memcpy(cmd->scmd->sense_buffer, ob_frame->payload,
 				sizeof(struct mvumi_sense_data));
-			scmd->result |=  (DRIVER_SENSE << 24);
 		}
 		break;
 	default:
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 99dc6ec0b6e5..df236dbbf8e0 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -185,13 +185,6 @@ void scsi_finish_command(struct scsi_cmnd *cmd)
 	if (atomic_read(&sdev->device_blocked))
 		atomic_set(&sdev->device_blocked, 0);
 
-	/*
-	 * If we have valid sense information, then some kind of recovery
-	 * must have taken place.  Make a note of this.
-	 */
-	if (SCSI_SENSE_VALID(cmd))
-		cmd->result |= (DRIVER_SENSE << 24);
-
 	SCSI_LOG_MLCOMPLETE(4, sdev_printk(KERN_INFO, sdev,
 				"Notifying upper driver of completion "
 				"(result %x)\n", cmd->result));
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index f7e72d21749a..33fcc356d28e 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -851,10 +851,10 @@ static struct device_driver sdebug_driverfs_driver = {
 };
 
 static const int check_condition_result =
-		(DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
+		(DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
 
 static const int illegal_condition_result =
-	(DRIVER_SENSE << 24) | (DID_ABORT << 16) | SAM_STAT_CHECK_CONDITION;
+	(DID_ABORT << 16) | SAM_STAT_CHECK_CONDITION;
 
 static const int device_qfull_result =
 	(DID_OK << 16) | SAM_STAT_TASK_SET_FULL;
diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c
index d34e1b41dc71..0d13610cd6bf 100644
--- a/drivers/scsi/scsi_ioctl.c
+++ b/drivers/scsi/scsi_ioctl.c
@@ -103,8 +103,7 @@ static int ioctl_internal_command(struct scsi_device *sdev, char *cmd,
 
 	if (result < 0)
 		goto out;
-	if (driver_byte(result) == DRIVER_SENSE &&
-	    scsi_sense_valid(&sshdr)) {
+	if (scsi_sense_valid(&sshdr)) {
 		switch (sshdr.sense_key) {
 		case ILLEGAL_REQUEST:
 			if (cmd[0] == ALLOW_MEDIUM_REMOVAL)
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index d72f15f6c225..cbcfda0abd37 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -627,8 +627,6 @@ static blk_status_t scsi_result_to_blk_status(struct scsi_cmnd *cmd, int result)
 	case DID_OK:
 		/*
 		 * Also check the other bytes than the status byte in result
-		 * to handle the case when a SCSI LLD sets result to
-		 * DRIVER_SENSE << 24 without setting SAM_STAT_CHECK_CONDITION.
 		 */
 		if (scsi_status_is_good(result) && (result & ~0xff) == 0)
 			return BLK_STS_OK;
@@ -824,7 +822,7 @@ static void scsi_io_completion_action(struct scsi_cmnd *cmd, int result)
 			 */
 			if (!level && __ratelimit(&_rs)) {
 				scsi_print_result(cmd, NULL, FAILED);
-				if (driver_byte(result) == DRIVER_SENSE)
+				if (sense_valid)
 					scsi_print_sense(cmd);
 				scsi_print_command(cmd);
 			}
@@ -2194,7 +2192,7 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
 	if (result < 0)
 		return result;
 	if (use_10_for_ms && !scsi_status_is_good(result) &&
-	    driver_byte(result) == DRIVER_SENSE) {
+	    status_byte(result) == SAM_STAT_CHECK_CONDITION) {
 		if (scsi_sense_valid(sshdr)) {
 			if ((sshdr->sense_key == ILLEGAL_REQUEST) &&
 			    (sshdr->asc == 0x20) && (sshdr->ascq == 0)) {
@@ -3279,7 +3277,6 @@ EXPORT_SYMBOL(scsi_vpd_tpg_id);
 void scsi_build_sense(struct scsi_cmnd *scmd, int desc, u8 key, u8 asc, u8 ascq)
 {
 	scsi_build_sense_buffer(desc, scmd->sense_buffer, key, asc, ascq);
-	scmd->result = (DRIVER_SENSE << 24) | (DID_OK << 16) |
-		SAM_STAT_CHECK_CONDITION;
+	scmd->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
 }
 EXPORT_SYMBOL_GPL(scsi_build_sense);
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 493f17bf26f2..3616b36219a0 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -623,7 +623,7 @@ static int scsi_probe_lun(struct scsi_device *sdev, unsigned char *inq_result,
 			 * INQUIRY should not yield UNIT_ATTENTION
 			 * but many buggy devices do so anyway. 
 			 */
-			if (driver_byte(result) == DRIVER_SENSE &&
+			if (status_byte(result) == SAM_STAT_CHECK_CONDITION &&
 			    scsi_sense_valid(&sshdr)) {
 				if ((sshdr.sense_key == UNIT_ATTENTION) &&
 				    ((sshdr.asc == 0x28) ||
diff --git a/drivers/scsi/scsi_transport_spi.c b/drivers/scsi/scsi_transport_spi.c
index a9bb7ae2fafd..5af7a10e9514 100644
--- a/drivers/scsi/scsi_transport_spi.c
+++ b/drivers/scsi/scsi_transport_spi.c
@@ -127,7 +127,7 @@ static int spi_execute(struct scsi_device *sdev, const void *cmd,
 				      REQ_FAILFAST_TRANSPORT |
 				      REQ_FAILFAST_DRIVER,
 				      RQF_PM, NULL);
-		if (result < 0 || driver_byte(result) != DRIVER_SENSE ||
+		if (result < 0 || !scsi_sense_valid(sshdr) ||
 		    sshdr->sense_key != UNIT_ATTENTION)
 			break;
 	}
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 5733fbee2bae..7537c2873efd 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1722,16 +1722,17 @@ static int sd_sync_cache(struct scsi_disk *sdkp, struct scsi_sense_hdr *sshdr)
 		if (res < 0)
 			return res;
 
-		if (driver_byte(res) == DRIVER_SENSE)
+		if (status_byte(res) == SAM_STAT_CHECK_CONDITION &&
+		    scsi_sense_valid(sshdr)) {
 			sd_print_sense_hdr(sdkp, sshdr);
 
-		/* we need to evaluate the error return  */
-		if (scsi_sense_valid(sshdr) &&
-			(sshdr->asc == 0x3a ||	/* medium not present */
-			 sshdr->asc == 0x20 ||	/* invalid command */
-			 (sshdr->asc == 0x74 && sshdr->ascq == 0x71)))	/* drive is password locked */
+			/* we need to evaluate the error return  */
+			if (sshdr->asc == 0x3a ||	/* medium not present */
+			    sshdr->asc == 0x20 ||	/* invalid command */
+			    (sshdr->asc == 0x74 && sshdr->ascq == 0x71))	/* drive is password locked */
 				/* this is no error here */
 				return 0;
+		}
 
 		switch (host_byte(res)) {
 		/* ignore errors due to racing a disconnection */
@@ -1828,7 +1829,7 @@ static int sd_pr_command(struct block_device *bdev, u8 sa,
 	result = scsi_execute_req(sdev, cmd, DMA_TO_DEVICE, &data, sizeof(data),
 			&sshdr, SD_TIMEOUT, sdkp->max_retries, NULL);
 
-	if (result > 0 && driver_byte(result) == DRIVER_SENSE &&
+	if (result > 0 && status_byte(result) == SAM_STAT_CHECK_CONDITION &&
 	    scsi_sense_valid(&sshdr)) {
 		sdev_printk(KERN_INFO, sdev, "PR command failed: %d\n", result);
 		scsi_print_sense_hdr(sdev, NULL, &sshdr);
@@ -2072,7 +2073,7 @@ static int sd_done(struct scsi_cmnd *SCpnt)
 	}
 	sdkp->medium_access_timed_out = 0;
 
-	if (driver_byte(result) != DRIVER_SENSE &&
+	if (status_byte(result) != SAM_STAT_CHECK_CONDITION &&
 	    (!sense_valid || sense_deferred))
 		goto out;
 
@@ -2175,12 +2176,13 @@ sd_spinup_disk(struct scsi_disk *sdkp)
 			if (the_result)
 				sense_valid = scsi_sense_valid(&sshdr);
 			retries++;
-		} while (retries < 3 && 
+		} while (retries < 3 &&
 			 (!scsi_status_is_good(the_result) ||
-			  ((driver_byte(the_result) == DRIVER_SENSE) &&
+			  ((status_byte(the_result) == SAM_STAT_CHECK_CONDITION) &&
 			  sense_valid && sshdr.sense_key == UNIT_ATTENTION)));
 
-		if (the_result < 0 || driver_byte(the_result) != DRIVER_SENSE) {
+		if (the_result < 0 ||
+		    status_byte(the_result) != SAM_STAT_CHECK_CONDITION) {
 			/* no sense, TUR either succeeded or failed
 			 * with a status error */
 			if(!spintime && !scsi_status_is_good(the_result)) {
@@ -2308,7 +2310,7 @@ static void read_capacity_error(struct scsi_disk *sdkp, struct scsi_device *sdp,
 			struct scsi_sense_hdr *sshdr, int sense_valid,
 			int the_result)
 {
-	if (driver_byte(the_result) == DRIVER_SENSE)
+	if (sense_valid)
 		sd_print_sense_hdr(sdkp, sshdr);
 	else
 		sd_printk(KERN_NOTICE, sdkp, "Sense not available.\n");
@@ -3594,12 +3596,12 @@ static int sd_start_stop_device(struct scsi_disk *sdkp, int start)
 			SD_TIMEOUT, sdkp->max_retries, 0, RQF_PM, NULL);
 	if (res) {
 		sd_print_result(sdkp, "Start/Stop Unit failed", res);
-		if (res > 0 && driver_byte(res) == DRIVER_SENSE)
+		if (res > 0 && scsi_sense_valid(&sshdr)) {
 			sd_print_sense_hdr(sdkp, &sshdr);
-		if (scsi_sense_valid(&sshdr) &&
 			/* 0x3a is medium not present */
-			sshdr.asc == 0x3a)
-			res = 0;
+			if (sshdr.asc == 0x3a)
+				res = 0;
+		}
 	}
 
 	/* SCSI error codes must not go to the generic layer */
diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c
index d4a79fdcfffe..186b5ff52c3a 100644
--- a/drivers/scsi/sd_zbc.c
+++ b/drivers/scsi/sd_zbc.c
@@ -116,8 +116,7 @@ static int sd_zbc_do_report_zones(struct scsi_disk *sdkp, unsigned char *buf,
 		sd_printk(KERN_ERR, sdkp,
 			  "REPORT ZONES start lba %llu failed\n", lba);
 		sd_print_result(sdkp, "REPORT ZONES", result);
-		if (result > 0 && driver_byte(result) == DRIVER_SENSE &&
-		    scsi_sense_valid(&sshdr))
+		if (result > 0 && scsi_sense_valid(&sshdr))
 			sd_print_sense_hdr(sdkp, &sshdr);
 		return -EIO;
 	}
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 737cea9d908e..9122d05563d0 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -498,9 +498,11 @@ sg_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos)
 	old_hdr->host_status = hp->host_status;
 	old_hdr->driver_status = hp->driver_status;
 	if ((CHECK_CONDITION & hp->masked_status) ||
-	    (DRIVER_SENSE & hp->driver_status))
+	    (srp->sense_b && (srp->sense_b[0] & 0x70) == 0x70)) {
+		old_hdr->driver_status |= DRIVER_SENSE;
 		memcpy(old_hdr->sense_buffer, srp->sense_b,
 		       sizeof (old_hdr->sense_buffer));
+	}
 	switch (hp->host_status) {
 	/* This setup of 'result' is for backward compatibility and is best
 	   ignored by the user who should use target, host + driver status */
@@ -574,7 +576,7 @@ sg_new_read(Sg_fd * sfp, char __user *buf, size_t count, Sg_request * srp)
 	hp->sb_len_wr = 0;
 	if ((hp->mx_sb_len > 0) && hp->sbp) {
 		if ((CHECK_CONDITION & hp->masked_status) ||
-		    (DRIVER_SENSE & hp->driver_status)) {
+		    (srp->sense_b && (srp->sense_b[0] & 0x70) == 0x70)) {
 			int sb_len = SCSI_SENSE_BUFFERSIZE;
 			sb_len = (hp->mx_sb_len > sb_len) ? sb_len : hp->mx_sb_len;
 			len = 8 + (int) srp->sense_b[7];	/* Additional sense length field */
@@ -582,7 +584,8 @@ sg_new_read(Sg_fd * sfp, char __user *buf, size_t count, Sg_request * srp)
 			if (copy_to_user(hp->sbp, srp->sense_b, len)) {
 				err = -EFAULT;
 				goto err_out;
-			}
+			} else
+				hp->driver_status |= DRIVER_SENSE;
 			hp->sb_len_wr = len;
 		}
 	}
diff --git a/drivers/scsi/stex.c b/drivers/scsi/stex.c
index 3af2a2d3bfa2..73ae97371f09 100644
--- a/drivers/scsi/stex.c
+++ b/drivers/scsi/stex.c
@@ -737,7 +737,7 @@ static void stex_scsi_done(struct st_ccb *ccb)
 			result |= DID_OK << 16;
 			break;
 		case SAM_STAT_CHECK_CONDITION:
-			result |= DRIVER_SENSE << 24;
+			result |= DID_OK << 16;
 			break;
 		case SAM_STAT_BUSY:
 			result |= DID_BUS_BUSY << 16;
@@ -748,7 +748,7 @@ static void stex_scsi_done(struct st_ccb *ccb)
 		}
 	}
 	else if (ccb->srb_status & SRB_SEE_SENSE)
-		result = DRIVER_SENSE << 24 | SAM_STAT_CHECK_CONDITION;
+		result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
 	else switch (ccb->srb_status) {
 		case SRB_STATUS_SELECTION_TIMEOUT:
 			result = DID_NO_CONNECT << 16;
diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c
index d9a045f9858c..16b65fc4405c 100644
--- a/drivers/scsi/sym53c8xx_2/sym_glue.c
+++ b/drivers/scsi/sym53c8xx_2/sym_glue.c
@@ -170,9 +170,8 @@ static int sym_xerr_cam_status(int cam_status, int x_status)
 void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid)
 {
 	struct scsi_cmnd *cmd = cp->cmd;
-	u_int cam_status, scsi_status, drv_status;
+	u_int cam_status, scsi_status;
 
-	drv_status  = 0;
 	cam_status  = DID_OK;
 	scsi_status = cp->ssss_status;
 
@@ -186,7 +185,6 @@ void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid)
 		    cp->xerr_status == 0) {
 			cam_status = sym_xerr_cam_status(DID_OK,
 							 cp->sv_xerr_status);
-			drv_status = DRIVER_SENSE;
 			/*
 			 *  Bounce back the sense data to user.
 			 */
@@ -235,7 +233,7 @@ void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid)
 		cam_status = sym_xerr_cam_status(DID_ERROR, cp->xerr_status);
 	}
 	scsi_set_resid(cmd, resid);
-	cmd->result = (drv_status << 24) | (cam_status << 16) | scsi_status;
+	cmd->result = (cam_status << 16) | scsi_status;
 }
 
 static int sym_scatter(struct sym_hcb *np, struct sym_ccb *cp, struct scsi_cmnd *cmd)
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index f743434073ac..6d5d0f5a56be 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -8487,7 +8487,7 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba,
 		sdev_printk(KERN_WARNING, sdp,
 			    "START_STOP failed for power mode: %d, result %x\n",
 			    pwr_mode, ret);
-		if (ret > 0 && driver_byte(ret) == DRIVER_SENSE)
+		if (ret > 0 && scsi_sense_valid(&sshdr))
 			scsi_print_sense_hdr(sdp, NULL, &sshdr);
 	}
 
diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
index 1678b6f14af9..fd69a03d6137 100644
--- a/drivers/scsi/virtio_scsi.c
+++ b/drivers/scsi/virtio_scsi.c
@@ -161,8 +161,7 @@ static void virtscsi_complete_cmd(struct virtio_scsi *vscsi, void *buf)
 		       min_t(u32,
 			     virtio32_to_cpu(vscsi->vdev, resp->sense_len),
 			     VIRTIO_SCSI_SENSE_SIZE));
-		if (resp->sense_len)
-			set_driver_byte(sc, DRIVER_SENSE);
+		set_status_byte(sc, SAM_STAT_CHECK_CONDITION);
 	}
 
 	sc->scsi_done(sc);
diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c
index 8a79605d9652..f0707eaad9f7 100644
--- a/drivers/scsi/vmw_pvscsi.c
+++ b/drivers/scsi/vmw_pvscsi.c
@@ -576,9 +576,6 @@ static void pvscsi_complete_request(struct pvscsi_adapter *adapter,
 			cmd->result = (DID_RESET << 16);
 		} else {
 			cmd->result = (DID_OK << 16) | sdstat;
-			if (sdstat == SAM_STAT_CHECK_CONDITION &&
-			    cmd->sense_buffer)
-				cmd->result |= (DRIVER_SENSE << 24);
 		}
 	} else
 		switch (btstat) {
diff --git a/drivers/target/loopback/tcm_loop.c b/drivers/target/loopback/tcm_loop.c
index 2687fd7d45db..6d0b0e67e79e 100644
--- a/drivers/target/loopback/tcm_loop.c
+++ b/drivers/target/loopback/tcm_loop.c
@@ -566,7 +566,6 @@ static int tcm_loop_queue_data_or_status(const char *func,
 		memcpy(sc->sense_buffer, se_cmd->sense_buffer,
 				SCSI_SENSE_BUFFERSIZE);
 		sc->result = SAM_STAT_CHECK_CONDITION;
-		set_driver_byte(sc, DRIVER_SENSE);
 	} else
 		sc->result = scsi_status;
 
diff --git a/drivers/usb/storage/cypress_atacb.c b/drivers/usb/storage/cypress_atacb.c
index a6f3267bbef6..ba10ee3585c1 100644
--- a/drivers/usb/storage/cypress_atacb.c
+++ b/drivers/usb/storage/cypress_atacb.c
@@ -221,11 +221,11 @@ static void cypress_atacb_passthrough(struct scsi_cmnd *srb, struct us_data *us)
 		desc[12] = regs[6];  /* device */
 		desc[13] = regs[7];  /* command */
 
-		srb->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
+		srb->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
 	}
 	goto end;
 invalid_fld:
-	srb->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
+	srb->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
 
 	memcpy(srb->sense_buffer,
 			usb_stor_sense_invalidCDB,
diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c
index 55a4763da05e..499b94702e2b 100644
--- a/drivers/xen/xen-scsiback.c
+++ b/drivers/xen/xen-scsiback.c
@@ -1401,7 +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) |
+		pending_req->result = (DID_OK << 16) |
 				      SAM_STAT_CHECK_CONDITION;
 	else
 		pending_req->result = se_cmd->scsi_status;
diff --git a/include/scsi/sg.h b/include/scsi/sg.h
index 7327e12f3373..a90703cf15f4 100644
--- a/include/scsi/sg.h
+++ b/include/scsi/sg.h
@@ -131,6 +131,8 @@ struct compat_sg_io_hdr {
 #define SG_INFO_DIRECT_IO 0x2   /* direct IO requested and performed */
 #define SG_INFO_MIXED_IO 0x4    /* part direct, part indirect IO */
 
+/* Obsolete DRIVER_SENSE setting */
+#define DRIVER_SENSE 0x08
 
 typedef struct sg_scsi_id { /* used by SG_GET_SCSI_ID ioctl() */
     int host_no;        /* as in "scsi<n>" where 'n' is one of 0, 1, 2 etc */
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 08/42] scsi: do not use DRIVER_INVALID
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (6 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 07/42] scsi: Kill DRIVER_SENSE Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 09/42] scsi_error: use DID_TIME_OUT instead of DRIVER_TIMEOUT Hannes Reinecke
                   ` (35 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

There is no point in returning DID_ABORT together with DRIVER_INVALID,
as the caller couldn't care less where the abort originated.
So drop the use of DRIVER_INVALID.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/hptiop.c     | 2 +-
 drivers/scsi/mvumi.c      | 4 ++--
 drivers/scsi/vmw_pvscsi.c | 3 ---
 3 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/hptiop.c b/drivers/scsi/hptiop.c
index db4c7a7ff4dd..61cda7b7624f 100644
--- a/drivers/scsi/hptiop.c
+++ b/drivers/scsi/hptiop.c
@@ -760,7 +760,7 @@ static void hptiop_finish_scsi_req(struct hptiop_hba *hba, u32 tag,
 		goto skip_resid;
 
 	default:
-		scp->result = DRIVER_INVALID << 24 | DID_ABORT << 16;
+		scp->result = DID_ABORT << 16;
 		break;
 	}
 
diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index f61250545025..6bb03d7a254d 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -1320,7 +1320,7 @@ static void mvumi_complete_cmd(struct mvumi_hba *mhba, struct mvumi_cmd *cmd,
 		}
 		break;
 	default:
-		scmd->result |= (DRIVER_INVALID << 24) | (DID_ABORT << 16);
+		scmd->result |= (DID_ABORT << 16);
 		break;
 	}
 
@@ -2127,7 +2127,7 @@ static enum blk_eh_timer_return mvumi_timed_out(struct scsi_cmnd *scmd)
 	else
 		atomic_dec(&mhba->fw_outstanding);
 
-	scmd->result = (DRIVER_INVALID << 24) | (DID_ABORT << 16);
+	scmd->result = (DID_ABORT << 16);
 	scmd->SCp.ptr = NULL;
 	if (scsi_bufflen(scmd)) {
 		dma_unmap_sg(&mhba->pdev->dev, scsi_sglist(scmd),
diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c
index f0707eaad9f7..f57f8bc037d2 100644
--- a/drivers/scsi/vmw_pvscsi.c
+++ b/drivers/scsi/vmw_pvscsi.c
@@ -601,9 +601,6 @@ static void pvscsi_complete_request(struct pvscsi_adapter *adapter,
 		case BTSTAT_LUNMISMATCH:
 		case BTSTAT_TAGREJECT:
 		case BTSTAT_BADMSG:
-			cmd->result = (DRIVER_INVALID << 24);
-			fallthrough;
-
 		case BTSTAT_HAHARDWARE:
 		case BTSTAT_INVPHASE:
 		case BTSTAT_HATIMEOUT:
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 09/42] scsi_error: use DID_TIME_OUT instead of DRIVER_TIMEOUT
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (7 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 08/42] scsi: do not use DRIVER_INVALID Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 10/42] xen-scsiback: use DID_ERROR instead of DRIVER_ERROR Hannes Reinecke
                   ` (34 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Set DID_TIME_OUT instead of DRIVER_TIMEOUT when a command
is finally marked as failed after error recovery.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/scsi_error.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index d8fafe77dbbe..4d0b3353da54 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -2137,10 +2137,10 @@ void scsi_eh_flush_done_q(struct list_head *done_q)
 			/*
 			 * If just we got sense for the device (called
 			 * scsi_eh_get_sense), scmd->result is already
-			 * set, do not set DRIVER_TIMEOUT.
+			 * set, do not set DID_TIME_OUT.
 			 */
 			if (!scmd->result)
-				scmd->result |= (DRIVER_TIMEOUT << 24);
+				scmd->result |= (DID_TIME_OUT << 16);
 			SCSI_LOG_ERROR_RECOVERY(3,
 				scmd_printk(KERN_INFO, scmd,
 					     "%s: flush finish cmd\n",
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 10/42] xen-scsiback: use DID_ERROR instead of DRIVER_ERROR
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (8 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 09/42] scsi_error: use DID_TIME_OUT instead of DRIVER_TIMEOUT Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 11/42] xen-scsifront: compability status handling Hannes Reinecke
                   ` (33 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

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.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/xen/xen-scsiback.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c
index 499b94702e2b..f274e078312e 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;
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 11/42] xen-scsifront: compability status handling
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (9 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 10/42] xen-scsiback: use DID_ERROR instead of DRIVER_ERROR Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 12/42] scsi: Drop the now obsolete driver_byte definitions Hannes Reinecke
                   ` (32 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

The Xen guest might run against arbitrary backends, so the driver
might receive a status with driver_byte set. Map these errors
to DID_ERROR to be consistent with recent changes.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/xen-scsifront.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/xen-scsifront.c b/drivers/scsi/xen-scsifront.c
index 259fc248d06c..fcf4dd70ebc7 100644
--- a/drivers/scsi/xen-scsifront.c
+++ b/drivers/scsi/xen-scsifront.c
@@ -251,6 +251,7 @@ static void scsifront_cdb_cmd_done(struct vscsifrnt_info *info,
 	struct scsi_cmnd *sc;
 	uint32_t id;
 	uint8_t sense_len;
+	int result;
 
 	id = ring_rsp->rqid;
 	shadow = info->shadow[id];
@@ -261,7 +262,13 @@ static void scsifront_cdb_cmd_done(struct vscsifrnt_info *info,
 	scsifront_gnttab_done(info, shadow);
 	scsifront_put_rqid(info, id);
 
-	sc->result = ring_rsp->rslt;
+	result = ring_rsp->rslt;
+	sc->result = 0;
+	if ((result >> 24) & 0xff)
+		set_host_byte(sc, DID_ERROR);
+	else if (host_byte(result))
+		set_host_byte(sc, host_byte(result));
+	set_status_byte(sc, status_byte(result));
 	scsi_set_resid(sc, ring_rsp->residual_len);
 
 	sense_len = min_t(uint8_t, VSCSIIF_SENSE_BUFFERSIZE,
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 12/42] scsi: Drop the now obsolete driver_byte definitions
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (10 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 11/42] xen-scsifront: compability status handling Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 13/42] scsi: add get_{status,host}_byte() accessor function Hannes Reinecke
                   ` (31 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke, Hannes Reinecke

From: Hannes Reinecke <hare@suse.com>

The driver_byte field in the result is now unused, so we can drop
the definitions.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 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(-)

diff --git a/Documentation/scsi/scsi_mid_low_api.rst b/Documentation/scsi/scsi_mid_low_api.rst
index 5bc17d012b25..2c87eaa36296 100644
--- a/Documentation/scsi/scsi_mid_low_api.rst
+++ b/Documentation/scsi/scsi_mid_low_api.rst
@@ -1178,8 +1178,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 bd10922d5cbb..dadc72052a14 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;
 	hdr->info = 0;
 	if (hdr->device_status || hdr->transport_status || hdr->driver_status)
 		hdr->info |= SG_INFO_CHECK;
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index 99d58786e0d5..ab2579467316 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;
 	hdr->info = 0;
 	if (hdr->masked_status || hdr->host_status || hdr->driver_status)
 		hdr->info |= SG_INFO_CHECK;
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 7537c2873efd..681b6b237347 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -3811,15 +3811,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 a78f2138d784..74348ead5b11 100644
--- a/drivers/scsi/sr_ioctl.c
+++ b/drivers/scsi/sr_ioctl.c
@@ -209,7 +209,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 23be6447e576..8ab12d07de31 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 f274e078312e..8efeddd96367 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 d0a24e55ad63..5ed1c256ea94 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -166,20 +166,6 @@ static inline int scsi_is_wlun(u64 lun)
 #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.
  */
@@ -211,12 +197,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 b3eaf4b74b72..a1eb7732aa1b 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -326,10 +326,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 a90703cf15f4..350470298aef 100644
--- a/include/scsi/sg.h
+++ b/include/scsi/sg.h
@@ -133,6 +133,8 @@ struct compat_sg_io_hdr {
 
 /* Obsolete DRIVER_SENSE setting */
 #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<n>" 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))
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 13/42] scsi: add get_{status,host}_byte() accessor function
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (11 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 12/42] scsi: Drop the now obsolete driver_byte definitions Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 21:09   ` Bart Van Assche
  2021-04-21 17:47 ` [PATCH 14/42] scsi: add scsi_result_is_good() Hannes Reinecke
                   ` (30 subsequent siblings)
  43 siblings, 1 reply; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Add accessor functions for the host and status byte.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 include/scsi/scsi_cmnd.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index a1eb7732aa1b..0ac18a7d8ac6 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -316,6 +316,11 @@ static inline void set_status_byte(struct scsi_cmnd *cmd, char status)
 	cmd->result = (cmd->result & 0xffffff00) | status;
 }
 
+static inline unsigned char 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);
@@ -326,6 +331,11 @@ static inline void set_host_byte(struct scsi_cmnd *cmd, char status)
 	cmd->result = (cmd->result & 0xff00ffff) | (status << 16);
 }
 
+static inline unsigned char get_host_byte(struct scsi_cmnd *cmd)
+{
+	return (cmd->result >> 16) & 0xff;
+}
+
 
 static inline unsigned scsi_transfer_length(struct scsi_cmnd *scmd)
 {
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 14/42] scsi: add scsi_result_is_good()
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (12 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 13/42] scsi: add get_{status,host}_byte() accessor function Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 21:10   ` Bart Van Assche
  2021-04-21 17:47 ` [PATCH 15/42] NCR5380: use SCSI result accessors Hannes Reinecke
                   ` (29 subsequent siblings)
  43 siblings, 1 reply; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Add helper to check if the status is 'GOOD', ie if none of the
status bytes are set.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 include/scsi/scsi_cmnd.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index 0ac18a7d8ac6..7089617911e1 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -336,6 +336,10 @@ static inline unsigned char get_host_byte(struct scsi_cmnd *cmd)
 	return (cmd->result >> 16) & 0xff;
 }
 
+static inline bool scsi_result_is_good(struct scsi_cmnd *cmd)
+{
+	return (cmd->result == 0);
+}
 
 static inline unsigned scsi_transfer_length(struct scsi_cmnd *scmd)
 {
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 15/42] NCR5380: use SCSI result accessors
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (13 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 14/42] scsi: add scsi_result_is_good() Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 21:11   ` Bart Van Assche
  2021-04-22  9:36   ` Finn Thain
  2021-04-21 17:47 ` [PATCH 16/42] NCR5380: Fold SCSI message ABORT onto DID_ABORT Hannes Reinecke
                   ` (28 subsequent siblings)
  43 siblings, 2 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Use accessors to set the SCSI result.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/NCR5380.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index d7594b794d3c..855edda9db41 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);
@@ -567,18 +567,19 @@ static int NCR5380_queue_command(struct Scsi_Host *instance,
 	struct NCR5380_cmd *ncmd = scsi_cmd_priv(cmd);
 	unsigned long flags;
 
+	set_host_byte(cmd, DID_OK);
+	set_status_byte(cmd, SAM_STAT_GOOD);
 #if (NDEBUG & NDEBUG_NO_WRITE)
 	switch (cmd->cmnd[0]) {
 	case WRITE_6:
 	case WRITE_10:
 		shost_printk(KERN_DEBUG, instance, "WRITE attempted with NDEBUG_NO_WRITE set\n");
-		cmd->result = (DID_ERROR << 16);
+		set_host_byte(cmd, DID_ERROR);
 		cmd->scsi_done(cmd);
 		return 0;
 	}
 #endif /* (NDEBUG & NDEBUG_NO_WRITE) */
 
-	cmd->result = 0;
 
 	spin_lock_irqsave(&hostdata->lock, flags);
 
@@ -1154,7 +1155,7 @@ static bool NCR5380_select(struct Scsi_Host *instance, struct scsi_cmnd *cmd)
 		if (!hostdata->selecting)
 			return false;
 
-		cmd->result = DID_BAD_TARGET << 16;
+		set_host_byte(cmd, DID_BAD_TARGET);
 		complete_cmd(instance, cmd);
 		dsprintk(NDEBUG_SELECTION, instance,
 			"target did not respond within 250ms\n");
@@ -1203,7 +1204,7 @@ static bool NCR5380_select(struct Scsi_Host *instance, struct scsi_cmnd *cmd)
 	NCR5380_transfer_pio(instance, &phase, &len, &data, 0);
 	if (len) {
 		NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
-		cmd->result = DID_ERROR << 16;
+		set_host_byte(cmd, DID_ERROR);
 		complete_cmd(instance, cmd);
 		dsprintk(NDEBUG_SELECTION, instance, "IDENTIFY message transfer failed\n");
 		ret = false;
@@ -1743,7 +1744,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
 				shost_printk(KERN_DEBUG, instance, "NDEBUG_NO_DATAOUT set, attempted DATAOUT aborted\n");
 				sink = 1;
 				do_abort(instance, 0);
-				cmd->result = DID_ERROR << 16;
+				set_host_byte(cmd, DID_ERROR);
 				complete_cmd(instance, cmd);
 				hostdata->connected = NULL;
 				hostdata->busy[scmd_id(cmd)] &= ~(1 << cmd->device->lun);
@@ -1826,9 +1827,8 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
 					hostdata->connected = NULL;
 					hostdata->busy[scmd_id(cmd)] &= ~(1 << cmd->device->lun);
 
-					cmd->result &= ~0xffff;
-					cmd->result |= cmd->SCp.Status;
-					cmd->result |= cmd->SCp.Message << 8;
+					set_msg_byte(cmd, cmd->SCp.Message);
+					set_status_byte(cmd, cmd->SCp.Status);
 
 					set_resid_from_SCp(cmd);
 
@@ -1980,7 +1980,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
 				if (msgout == ABORT) {
 					hostdata->connected = NULL;
 					hostdata->busy[scmd_id(cmd)] &= ~(1 << cmd->device->lun);
-					cmd->result = DID_ERROR << 16;
+					set_host_byte(cmd, DID_ERROR);
 					complete_cmd(instance, cmd);
 					return;
 				}
@@ -2261,7 +2261,7 @@ static int NCR5380_abort(struct scsi_cmnd *cmd)
 	if (list_del_cmd(&hostdata->unissued, cmd)) {
 		dsprintk(NDEBUG_ABORT, instance,
 		         "abort: removed %p from issue queue\n", cmd);
-		cmd->result = DID_ABORT << 16;
+		set_host_byte(cmd, DID_ABORT);
 		cmd->scsi_done(cmd); /* No tag or busy flag to worry about */
 		goto out;
 	}
@@ -2270,7 +2270,7 @@ static int NCR5380_abort(struct scsi_cmnd *cmd)
 		dsprintk(NDEBUG_ABORT, instance,
 		         "abort: cmd %p == selecting\n", cmd);
 		hostdata->selecting = NULL;
-		cmd->result = DID_ABORT << 16;
+		set_host_byte(cmd, DID_ABORT);
 		complete_cmd(instance, cmd);
 		goto out;
 	}
@@ -2341,7 +2341,7 @@ static void bus_reset_cleanup(struct Scsi_Host *instance)
 	 */
 
 	if (hostdata->selecting) {
-		hostdata->selecting->result = DID_RESET << 16;
+		set_host_byte(hostdata->selecting, DID_RESET);
 		complete_cmd(instance, hostdata->selecting);
 		hostdata->selecting = NULL;
 	}
@@ -2399,7 +2399,7 @@ static int NCR5380_host_reset(struct scsi_cmnd *cmd)
 	list_for_each_entry(ncmd, &hostdata->unissued, list) {
 		struct scsi_cmnd *scmd = NCR5380_to_scmd(ncmd);
 
-		scmd->result = DID_RESET << 16;
+		set_host_byte(scmd, DID_RESET);
 		scmd->scsi_done(scmd);
 	}
 	INIT_LIST_HEAD(&hostdata->unissued);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 16/42] NCR5380: Fold SCSI message ABORT onto DID_ABORT
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (14 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 15/42] NCR5380: use SCSI result accessors Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-22  9:35   ` Finn Thain
  2021-04-21 17:47 ` [PATCH 17/42] scsi: add translate_msg_byte() Hannes Reinecke
                   ` (27 subsequent siblings)
  43 siblings, 1 reply; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

The message byte can take only two values, COMMAND_COMPLETE and ABORT.
So we can easily map ABORT to DID_ABORT and do not set the message byte.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/NCR5380.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index 855edda9db41..76b4dce22e03 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -1827,7 +1827,8 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
 					hostdata->connected = NULL;
 					hostdata->busy[scmd_id(cmd)] &= ~(1 << cmd->device->lun);
 
-					set_msg_byte(cmd, cmd->SCp.Message);
+					if (cmd->SCp.Message == ABORT)
+						set_host_byte(cmd, DID_ABORT);
 					set_status_byte(cmd, cmd->SCp.Status);
 
 					set_resid_from_SCp(cmd);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 17/42] scsi: add translate_msg_byte()
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (15 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 16/42] NCR5380: Fold SCSI message ABORT onto DID_ABORT Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 18/42] dc395: use standard macros to set SCSI result Hannes Reinecke
                   ` (26 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Add helper to convert message byte into a host byte code.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 include/scsi/scsi_cmnd.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index 7089617911e1..a0458f0dba14 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -341,6 +341,23 @@ static inline bool scsi_result_is_good(struct scsi_cmnd *cmd)
 	return (cmd->result == 0);
 }
 
+static inline void translate_msg_byte(struct scsi_cmnd *cmd, u8 msg)
+{
+	switch (msg) {
+	case COMMAND_COMPLETE:
+		break;
+	case ABORT_TASK_SET:
+		set_host_byte(cmd, DID_ABORT);
+		break;
+	case TARGET_RESET:
+		set_host_byte(cmd, DID_RESET);
+		break;
+	default:
+		set_host_byte(cmd, DID_ERROR);
+		break;
+	}
+}
+
 static inline unsigned scsi_transfer_length(struct scsi_cmnd *scmd)
 {
 	unsigned int xfer_len = scmd->sdb.length;
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 18/42] dc395: use standard macros to set SCSI result
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (16 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 17/42] scsi: add translate_msg_byte() Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 22:26   ` Bart Van Assche
  2021-04-21 17:47 ` [PATCH 19/42] dc395: translate message bytes Hannes Reinecke
                   ` (25 subsequent siblings)
  43 siblings, 1 reply; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

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

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/dc395x.c | 72 ++++++++++++++++---------------------------
 1 file changed, 26 insertions(+), 46 deletions(-)

diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
index a713fe605dda..122b64c14b0e 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;
 	}
@@ -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, scsi_get_compat_result(cmd));
 		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


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 19/42] dc395: translate message bytes
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (17 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 18/42] dc395: use standard macros to set SCSI result Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 20/42] qlogicfas408: make ql_pcmd() a void function Hannes Reinecke
                   ` (24 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Drop message byte setting if the host byte is already set, and
translate message bytes into the related host bytes when evaluating
an overrun or underrun.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/dc395x.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
index 122b64c14b0e..b469f4660de2 100644
--- a/drivers/scsi/dc395x.c
+++ b/drivers/scsi/dc395x.c
@@ -3226,7 +3226,6 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb,
 		}
 		dprintkdbg(DBG_0, "srb_done: AUTO_REQSENSE2\n");
 
-		set_msg_byte(cmd, srb->end_message);
 		set_status_byte(cmd, SAM_STAT_CHECK_CONDITION);
 
 		goto ckc_e;
@@ -3260,7 +3259,6 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb,
 		} else {
 			srb->adapter_status = 0;
 			set_host_byte(cmd, DID_ERROR);
-			set_msg_byte(cmd, srb->end_message);
 			set_status_byte(cmd, status);
 		}
 	} else {
@@ -3270,10 +3268,9 @@ 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_msg_byte(cmd, srb->end_message);
+			translate_msg_byte(cmd, srb->end_message);
 		} else if (srb->status & PARITY_ERROR) {
 			set_host_byte(cmd, DID_PARITY);
-			set_msg_byte(cmd, srb->end_message);
 		} else {	/* No error */
 
 			srb->adapter_status = 0;
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 20/42] qlogicfas408: make ql_pcmd() a void function
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (18 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 19/42] dc395: translate message bytes Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 21/42] qlogicfas408: whitespace cleanup Hannes Reinecke
                   ` (23 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Make ql_pcmd() a void function and set the SCSI result directly.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/qlogicfas408.c | 75 ++++++++++++++++++++++++-------------
 1 file changed, 49 insertions(+), 26 deletions(-)

diff --git a/drivers/scsi/qlogicfas408.c b/drivers/scsi/qlogicfas408.c
index 136681ad18a5..a1eabdc7db09 100644
--- a/drivers/scsi/qlogicfas408.c
+++ b/drivers/scsi/qlogicfas408.c
@@ -256,7 +256,7 @@ static void ql_icmd(struct scsi_cmnd *cmd)
  *	Process scsi command - usually after interrupt 
  */
 
-static unsigned int ql_pcmd(struct scsi_cmnd *cmd)
+static void ql_pcmd(struct scsi_cmnd *cmd)
 {
 	unsigned int i, j;
 	unsigned long k;
@@ -274,13 +274,15 @@ static unsigned int ql_pcmd(struct scsi_cmnd *cmd)
 	j = inb(qbase + 6);
 	i = inb(qbase + 5);
 	if (i == 0x20) {
-		return (DID_NO_CONNECT << 16);
+		set_host_byte(cmd, DID_NO_CONNECT);
+		return;
 	}
 	i |= inb(qbase + 5);	/* the 0x10 bit can be set after the 0x08 */
 	if (i != 0x18) {
 		printk(KERN_ERR "Ql:Bad Interrupt status:%02x\n", i);
 		ql_zap(priv);
-		return (DID_BAD_INTR << 16);
+		set_host_byte(cmd, DID_BAD_INTR);
+		return;
 	}
 	j &= 7;			/* j = inb( qbase + 7 ) >> 5; */
 
@@ -293,9 +295,10 @@ static unsigned int ql_pcmd(struct scsi_cmnd *cmd)
 		printk(KERN_ERR "Ql:Bad sequence for command %d, int %02X, cmdleft = %d\n",
 		     j, i, inb(qbase + 7) & 0x1f);
 		ql_zap(priv);
-		return (DID_ERROR << 16);
+		set_host_byte (cmd, DID_ERROR);
+		return;
 	}
-	result = DID_OK;
+
 	if (inb(qbase + 7) & 0x1f)	/* if some bytes in fifo */
 		outb(1, qbase + 3);	/* clear fifo */
 	/* note that request_bufflen is the total xfer size when sg is used */
@@ -314,21 +317,24 @@ static unsigned int ql_pcmd(struct scsi_cmnd *cmd)
 		scsi_for_each_sg(cmd, sg, scsi_sg_count(cmd), i) {
 			if (priv->qabort) {
 				REG0;
-				return ((priv->qabort == 1 ?
-					 DID_ABORT : DID_RESET) << 16);
+				set_host_byte(cmd,
+					      priv->qabort == 1 ?
+					      DID_ABORT : DID_RESET);
 			}
 			buf = sg_virt(sg);
 			if (ql_pdma(priv, phase, buf, sg->length))
 				break;
 		}
 		REG0;
-		rtrc(2)
+		rtrc(2);
 		/*
 		 *	Wait for irq (split into second state of irq handler
 		 *	if this can take time) 
 		 */
-		if ((k = ql_wai(priv)))
-			return (k << 16);
+		if ((k = ql_wai(priv))) {
+			set_host_byte(cmd, k);
+			return;
+		}
 		k = inb(qbase + 5);	/* should be 0x10, bus service */
 	}
 
@@ -344,19 +350,25 @@ static unsigned int ql_pcmd(struct scsi_cmnd *cmd)
 
 	if (time_after_eq(jiffies, k)) {
 		ql_zap(priv);
-		return (DID_TIME_OUT << 16);
+		set_host_byte(cmd, DID_TIME_OUT);
+		return;
 	}
 
 	/* FIXME: timeout ?? */
 	while (inb(qbase + 5))
 		cpu_relax();	/* clear pending ints */
 
-	if (priv->qabort)
-		return ((priv->qabort == 1 ? DID_ABORT : DID_RESET) << 16);
+	if (priv->qabort) {
+		set_host_byte(cmd,
+			      priv->qabort == 1 ? DID_ABORT : DID_RESET);
+		return;
+	}
 
 	outb(0x11, qbase + 3);	/* get status and message */
-	if ((k = ql_wai(priv)))
-		return (k << 16);
+	if ((k = ql_wai(priv))) {
+		set_host_byte(cmd, k);
+		return;
+	}
 	i = inb(qbase + 5);	/* get chip irq stat */
 	j = inb(qbase + 7) & 0x1f;	/* and bytes rec'd */
 	status = inb(qbase + 2);
@@ -368,12 +380,14 @@ static unsigned int ql_pcmd(struct scsi_cmnd *cmd)
 	 */
 	if (!((i == 8 && j == 2) || (i == 0x10 && j == 1))) {
 		printk(KERN_ERR "Ql:Error during status phase, int=%02X, %d bytes recd\n", i, j);
-		result = DID_ERROR;
+		set_host_byte(cmd, DID_ERROR);
 	}
 	outb(0x12, qbase + 3);	/* done, disconnect */
-	rtrc(1)
-	if ((k = ql_wai(priv)))
-		return (k << 16);
+	rtrc(1);
+	if ((k = ql_wai(priv))) {
+		set_host_byte(cmd, k);
+		return;
+	}
 
 	/*
 	 *	Should get bus service interrupt and disconnect interrupt 
@@ -385,12 +399,18 @@ static unsigned int ql_pcmd(struct scsi_cmnd *cmd)
 		cpu_relax();
 		i |= inb(qbase + 5);
 	}
-	rtrc(0)
+	rtrc(0);
 
-	if (priv->qabort)
-		return ((priv->qabort == 1 ? DID_ABORT : DID_RESET) << 16);
-		
-	return (result << 16) | (message << 8) | (status & STATUS_MASK);
+	if (priv->qabort) {
+		set_host_byte(cmd,
+			      priv->qabort == 1 ? DID_ABORT : DID_RESET);
+		return;
+	}
+
+	set_host_byte(cmd, result);
+	set_msg_byte(cmd, message);
+	set_status_byte(cmd, status);
+	return;
 }
 
 /*
@@ -415,7 +435,7 @@ static void ql_ihandl(void *dev_id)
 		return;
 	}
 	icmd = priv->qlcmd;
-	icmd->result = ql_pcmd(icmd);
+	ql_pcmd(icmd);
 	priv->qlcmd = NULL;
 	/*
 	 *	If result is CHECK CONDITION done calls qcommand to request 
@@ -443,8 +463,11 @@ static int qlogicfas408_queuecommand_lck(struct scsi_cmnd *cmd,
 			      void (*done) (struct scsi_cmnd *))
 {
 	struct qlogicfas408_priv *priv = get_priv_by_cmd(cmd);
+
+	set_host_byte(cmd, DID_OK);
+	set_status_byte(cmd, SAM_STAT_GOOD);
 	if (scmd_id(cmd) == priv->qinitid) {
-		cmd->result = DID_BAD_TARGET << 16;
+		set_host_byte(cmd, DID_BAD_TARGET);
 		done(cmd);
 		return 0;
 	}
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 21/42] qlogicfas408: whitespace cleanup
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (19 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 20/42] qlogicfas408: make ql_pcmd() a void function Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 22/42] qlogicfas408: translate message to host byte status Hannes Reinecke
                   ` (22 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/qlogicfas408.c | 61 +++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 30 deletions(-)

diff --git a/drivers/scsi/qlogicfas408.c b/drivers/scsi/qlogicfas408.c
index a1eabdc7db09..86de400ca81a 100644
--- a/drivers/scsi/qlogicfas408.c
+++ b/drivers/scsi/qlogicfas408.c
@@ -4,9 +4,9 @@
    Use at your own risk.  Support Tort Reform so you won't have to read all
    these silly disclaimers.
 
-   Copyright 1994, Tom Zerucha.   
+   Copyright 1994, Tom Zerucha.
    tz@execpc.com
-   
+
    Additional Code, and much appreciated help by
    Michael A. Griffith
    grif@cs.ucr.edu
@@ -22,12 +22,12 @@
 
    Functions as standalone, loadable, and PCMCIA driver, the latter from
    Dave Hinds' PCMCIA package.
-   
+
    Cleaned up 26/10/2002 by Alan Cox <alan@lxorguk.ukuu.org.uk> as part of the 2.5
    SCSI driver cleanup and audit. This driver still needs work on the
    following
-   	-	Non terminating hardware waits
-   	-	Some layering violations with its pcmcia stub
+	-	Non terminating hardware waits
+	-	Some layering violations with its pcmcia stub
 
    Redistributable under terms of the GNU General Public License
 
@@ -92,8 +92,9 @@ static void ql_zap(struct qlogicfas408_priv *priv)
 /*
  *	Do a pseudo-dma tranfer
  */
- 
-static int ql_pdma(struct qlogicfas408_priv *priv, int phase, char *request, int reqlen)
+
+static int ql_pdma(struct qlogicfas408_priv *priv, int phase, char *request,
+		   int reqlen)
 {
 	int j;
 	int qbase = priv->qbase;
@@ -108,7 +109,7 @@ static int ql_pdma(struct qlogicfas408_priv *priv, int phase, char *request, int
 			request += 128;
 		}
 		while (reqlen >= 84 && !(j & 0xc0))	/* 2/3 */
-			if ((j = inb(qbase + 8)) & 4) 
+			if ((j = inb(qbase + 8)) & 4)
 			{
 				insl(qbase + 4, request, 21);
 				reqlen -= 84;
@@ -123,11 +124,11 @@ static int ql_pdma(struct qlogicfas408_priv *priv, int phase, char *request, int
 		/* until both empty and int (or until reclen is 0) */
 		rtrc(7)
 		j = 0;
-		while (reqlen && !((j & 0x10) && (j & 0xc0))) 
+		while (reqlen && !((j & 0x10) && (j & 0xc0)))
 		{
 			/* while bytes to receive and not empty */
 			j &= 0xc0;
-			while (reqlen && !((j = inb(qbase + 8)) & 0x10)) 
+			while (reqlen && !((j = inb(qbase + 8)) & 0x10))
 			{
 				*request++ = inb(qbase + 4);
 				reqlen--;
@@ -161,7 +162,7 @@ static int ql_pdma(struct qlogicfas408_priv *priv, int phase, char *request, int
 		    j = 0;
 		while (reqlen && !((j & 2) && (j & 0xc0))) {
 			/* while bytes to send and not full */
-			while (reqlen && !((j = inb(qbase + 8)) & 2)) 
+			while (reqlen && !((j = inb(qbase + 8)) & 2))
 			{
 				outb(*request++, qbase + 4);
 				reqlen--;
@@ -175,7 +176,7 @@ static int ql_pdma(struct qlogicfas408_priv *priv, int phase, char *request, int
 }
 
 /*
- *	Wait for interrupt flag (polled - not real hardware interrupt) 
+ *	Wait for interrupt flag (polled - not real hardware interrupt)
  */
 
 static int ql_wai(struct qlogicfas408_priv *priv)
@@ -205,14 +206,14 @@ static int ql_wai(struct qlogicfas408_priv *priv)
 }
 
 /*
- *	Initiate scsi command - queueing handler 
+ *	Initiate scsi command - queueing handler
  *	caller must hold host lock
  */
 
 static void ql_icmd(struct scsi_cmnd *cmd)
 {
 	struct qlogicfas408_priv *priv = get_priv_by_cmd(cmd);
-	int 	qbase = priv->qbase;
+	int	qbase = priv->qbase;
 	int	int_type = priv->int_type;
 	unsigned int i;
 
@@ -253,7 +254,7 @@ static void ql_icmd(struct scsi_cmnd *cmd)
 }
 
 /*
- *	Process scsi command - usually after interrupt 
+ *	Process scsi command - usually after interrupt
  */
 
 static void ql_pcmd(struct scsi_cmnd *cmd)
@@ -329,7 +330,7 @@ static void ql_pcmd(struct scsi_cmnd *cmd)
 		rtrc(2);
 		/*
 		 *	Wait for irq (split into second state of irq handler
-		 *	if this can take time) 
+		 *	if this can take time)
 		 */
 		if ((k = ql_wai(priv))) {
 			set_host_byte(cmd, k);
@@ -339,9 +340,9 @@ static void ql_pcmd(struct scsi_cmnd *cmd)
 	}
 
 	/*
-	 *	Enter Status (and Message In) Phase 
+	 *	Enter Status (and Message In) Phase
 	 */
-	 
+
 	k = jiffies + WATCHDOG;
 
 	while (time_before(jiffies, k) && !priv->qabort &&
@@ -375,8 +376,8 @@ static void ql_pcmd(struct scsi_cmnd *cmd)
 	message = inb(qbase + 2);
 
 	/*
-	 *	Should get function complete int if Status and message, else 
-	 *	bus serv if only status 
+	 *	Should get function complete int if Status and message, else
+	 *	bus serv if only status
 	 */
 	if (!((i == 8 && j == 2) || (i == 0x10 && j == 1))) {
 		printk(KERN_ERR "Ql:Error during status phase, int=%02X, %d bytes recd\n", i, j);
@@ -390,9 +391,9 @@ static void ql_pcmd(struct scsi_cmnd *cmd)
 	}
 
 	/*
-	 *	Should get bus service interrupt and disconnect interrupt 
+	 *	Should get bus service interrupt and disconnect interrupt
 	 */
-	 
+
 	i = inb(qbase + 5);	/* should be bus service */
 	while (!priv->qabort && ((i & 0x20) != 0x20)) {
 		barrier();
@@ -414,7 +415,7 @@ static void ql_pcmd(struct scsi_cmnd *cmd)
 }
 
 /*
- *	Interrupt handler 
+ *	Interrupt handler
  */
 
 static void ql_ihandl(void *dev_id)
@@ -438,8 +439,8 @@ static void ql_ihandl(void *dev_id)
 	ql_pcmd(icmd);
 	priv->qlcmd = NULL;
 	/*
-	 *	If result is CHECK CONDITION done calls qcommand to request 
-	 *	sense 
+	 *	If result is CHECK CONDITION done calls qcommand to request
+	 *	sense
 	 */
 	(icmd->scsi_done) (icmd);
 }
@@ -484,8 +485,8 @@ static int qlogicfas408_queuecommand_lck(struct scsi_cmnd *cmd,
 
 DEF_SCSI_QCMD(qlogicfas408_queuecommand)
 
-/* 
- *	Return bios parameters 
+/*
+ *	Return bios parameters
  */
 
 int qlogicfas408_biosparam(struct scsi_device *disk, struct block_device *dev,
@@ -510,7 +511,7 @@ int qlogicfas408_biosparam(struct scsi_device *disk, struct block_device *dev,
 /*
  *	Abort a command in progress
  */
- 
+
 int qlogicfas408_abort(struct scsi_cmnd *cmd)
 {
 	struct qlogicfas408_priv *priv = get_priv_by_cmd(cmd);
@@ -589,9 +590,9 @@ void qlogicfas408_setup(int qbase, int id, int int_type)
 
 int qlogicfas408_detect(int qbase, int int_type)
 {
-        REG1;
+	REG1;
 	return (((inb(qbase + 0xe) ^ inb(qbase + 0xe)) == 7) &&
-	       ((inb(qbase + 0xe) ^ inb(qbase + 0xe)) == 7));		
+		((inb(qbase + 0xe) ^ inb(qbase + 0xe)) == 7));
 }
 
 /*
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 22/42] qlogicfas408: translate message to host byte status
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (20 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 21/42] qlogicfas408: whitespace cleanup Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 23/42] nsp32: use standard macros to set SCSI result Hannes Reinecke
                   ` (21 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Instead of setting the message byte translate it to the appropriate
host byte. As error recovery would return DID_ERROR for any non-zero
message byte the translation doesn't change the error handling.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/qlogicfas408.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/qlogicfas408.c b/drivers/scsi/qlogicfas408.c
index 86de400ca81a..aca76106f111 100644
--- a/drivers/scsi/qlogicfas408.c
+++ b/drivers/scsi/qlogicfas408.c
@@ -409,7 +409,8 @@ static void ql_pcmd(struct scsi_cmnd *cmd)
 	}
 
 	set_host_byte(cmd, result);
-	set_msg_byte(cmd, message);
+	if (result == DID_OK && message != COMMAND_COMPLETE)
+		translate_msg_byte(cmd, message);
 	set_status_byte(cmd, status);
 	return;
 }
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 23/42] nsp32: use standard macros to set SCSI result
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (21 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 22/42] qlogicfas408: translate message to host byte status Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 24/42] nsp32: whitespace cleanup Hannes Reinecke
                   ` (20 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

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 --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");
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 24/42] nsp32: whitespace cleanup
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (22 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 23/42] nsp32: use standard macros to set SCSI result Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 25/42] nsp32: do not set message byte Hannes Reinecke
                   ` (19 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/nsp32.c | 351 +++++++++++++++++++++++--------------------
 1 file changed, 189 insertions(+), 162 deletions(-)

diff --git a/drivers/scsi/nsp32.c b/drivers/scsi/nsp32.c
index 4a12ee577f2a..abecbcefc382 100644
--- a/drivers/scsi/nsp32.c
+++ b/drivers/scsi/nsp32.c
@@ -176,38 +176,40 @@ static nsp32_sync_table nsp32_sync_table_pci[] = {
  * function declaration
  */
 /* module entry point */
-static int         nsp32_probe (struct pci_dev *, const struct pci_device_id *);
-static void        nsp32_remove(struct pci_dev *);
+static int nsp32_probe (struct pci_dev *, const struct pci_device_id *);
+static void nsp32_remove(struct pci_dev *);
 static int  __init init_nsp32  (void);
 static void __exit exit_nsp32  (void);
 
 /* struct struct scsi_host_template */
-static int         nsp32_show_info   (struct seq_file *, struct Scsi_Host *);
+static int	   nsp32_show_info   (struct seq_file *, struct Scsi_Host *);
 
-static int         nsp32_detect      (struct pci_dev *pdev);
-static int         nsp32_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
-static const char *nsp32_info        (struct Scsi_Host *);
-static int         nsp32_release     (struct Scsi_Host *);
+static int	   nsp32_detect      (struct pci_dev *pdev);
+static int	   nsp32_queuecommand(struct Scsi_Host *, struct scsi_cmnd *);
+static const char *nsp32_info	     (struct Scsi_Host *);
+static int	   nsp32_release     (struct Scsi_Host *);
 
 /* SCSI error handler */
-static int         nsp32_eh_abort     (struct scsi_cmnd *);
-static int         nsp32_eh_host_reset(struct scsi_cmnd *);
+static int	   nsp32_eh_abort     (struct scsi_cmnd *);
+static int	   nsp32_eh_host_reset(struct scsi_cmnd *);
 
 /* generate SCSI message */
 static void nsp32_build_identify(struct scsi_cmnd *);
 static void nsp32_build_nop     (struct scsi_cmnd *);
 static void nsp32_build_reject  (struct scsi_cmnd *);
-static void nsp32_build_sdtr    (struct scsi_cmnd *, unsigned char, unsigned char);
+static void nsp32_build_sdtr    (struct scsi_cmnd *, unsigned char,
+				 unsigned char);
 
 /* SCSI message handler */
 static int  nsp32_busfree_occur(struct scsi_cmnd *, unsigned short);
 static void nsp32_msgout_occur (struct scsi_cmnd *);
-static void nsp32_msgin_occur  (struct scsi_cmnd *, unsigned long, unsigned short);
+static void nsp32_msgin_occur  (struct scsi_cmnd *, unsigned long,
+				unsigned short);
 
 static int  nsp32_setup_sg_table    (struct scsi_cmnd *);
 static int  nsp32_selection_autopara(struct scsi_cmnd *);
 static int  nsp32_selection_autoscsi(struct scsi_cmnd *);
-static void nsp32_scsi_done         (struct scsi_cmnd *);
+static void nsp32_scsi_done	    (struct scsi_cmnd *);
 static int  nsp32_arbitration       (struct scsi_cmnd *, unsigned int);
 static int  nsp32_reselection       (struct scsi_cmnd *, unsigned char);
 static void nsp32_adjust_busfree    (struct scsi_cmnd *, unsigned int);
@@ -215,10 +217,13 @@ static void nsp32_restart_autoscsi  (struct scsi_cmnd *, unsigned short);
 
 /* SCSI SDTR */
 static void nsp32_analyze_sdtr       (struct scsi_cmnd *);
-static int  nsp32_search_period_entry(nsp32_hw_data *, nsp32_target *, unsigned char);
-static void nsp32_set_async          (nsp32_hw_data *, nsp32_target *);
-static void nsp32_set_max_sync       (nsp32_hw_data *, nsp32_target *, unsigned char *, unsigned char *);
-static void nsp32_set_sync_entry     (nsp32_hw_data *, nsp32_target *, int, unsigned char);
+static int  nsp32_search_period_entry(nsp32_hw_data *, nsp32_target *,
+				      unsigned char);
+static void nsp32_set_async	     (nsp32_hw_data *, nsp32_target *);
+static void nsp32_set_max_sync       (nsp32_hw_data *, nsp32_target *,
+				      unsigned char *, unsigned char *);
+static void nsp32_set_sync_entry     (nsp32_hw_data *, nsp32_target *,
+				      int, unsigned char);
 
 /* SCSI bus status handler */
 static void nsp32_wait_req    (nsp32_hw_data *, int);
@@ -234,16 +239,16 @@ static irqreturn_t do_nsp32_isr(int, void *);
 static int  nsp32hw_init(nsp32_hw_data *);
 
 /* EEPROM handler */
-static        int  nsp32_getprom_param (nsp32_hw_data *);
-static        int  nsp32_getprom_at24  (nsp32_hw_data *);
-static        int  nsp32_getprom_c16   (nsp32_hw_data *);
-static        void nsp32_prom_start    (nsp32_hw_data *);
-static        void nsp32_prom_stop     (nsp32_hw_data *);
-static        int  nsp32_prom_read     (nsp32_hw_data *, int);
-static        int  nsp32_prom_read_bit (nsp32_hw_data *);
-static        void nsp32_prom_write_bit(nsp32_hw_data *, int);
-static        void nsp32_prom_set      (nsp32_hw_data *, int, int);
-static        int  nsp32_prom_get      (nsp32_hw_data *, int);
+static int  nsp32_getprom_param (nsp32_hw_data *);
+static int  nsp32_getprom_at24  (nsp32_hw_data *);
+static int  nsp32_getprom_c16   (nsp32_hw_data *);
+static void nsp32_prom_start    (nsp32_hw_data *);
+static void nsp32_prom_stop     (nsp32_hw_data *);
+static int  nsp32_prom_read     (nsp32_hw_data *, int);
+static int  nsp32_prom_read_bit (nsp32_hw_data *);
+static void nsp32_prom_write_bit(nsp32_hw_data *, int);
+static void nsp32_prom_set      (nsp32_hw_data *, int, int);
+static int  nsp32_prom_get      (nsp32_hw_data *, int);
 
 /* debug/warning/info message */
 static void nsp32_message (const char *, int, char *, char *, ...);
@@ -356,8 +361,8 @@ static void nsp32_dmessage(const char *func, int line, int mask, char *fmt, ...)
 static void nsp32_build_identify(struct scsi_cmnd *SCpnt)
 {
 	nsp32_hw_data *data = (nsp32_hw_data *)SCpnt->device->host->hostdata;
-	int pos             = data->msgout_len;
-	int mode            = FALSE;
+	int pos		    = data->msgout_len;
+	int mode	    = FALSE;
 
 	/* XXX: Auto DiscPriv detection is progressing... */
 	if (disc_priv == 0) {
@@ -377,7 +382,7 @@ static void nsp32_build_sdtr(struct scsi_cmnd    *SCpnt,
 			     unsigned char offset)
 {
 	nsp32_hw_data *data = (nsp32_hw_data *)SCpnt->device->host->hostdata;
-	int pos             = data->msgout_len;
+	int pos = data->msgout_len;
 
 	data->msgoutbuf[pos] = EXTENDED_MESSAGE;  pos++;
 	data->msgoutbuf[pos] = EXTENDED_SDTR_LEN; pos++;
@@ -394,7 +399,7 @@ static void nsp32_build_sdtr(struct scsi_cmnd    *SCpnt,
 static void nsp32_build_nop(struct scsi_cmnd *SCpnt)
 {
 	nsp32_hw_data *data = (nsp32_hw_data *)SCpnt->device->host->hostdata;
-	int            pos  = data->msgout_len;
+	int pos  = data->msgout_len;
 
 	if (pos != 0) {
 		nsp32_msg(KERN_WARNING,
@@ -412,12 +417,12 @@ static void nsp32_build_nop(struct scsi_cmnd *SCpnt)
 static void nsp32_build_reject(struct scsi_cmnd *SCpnt)
 {
 	nsp32_hw_data *data = (nsp32_hw_data *)SCpnt->device->host->hostdata;
-	int            pos  = data->msgout_len;
+	int pos  = data->msgout_len;
 
 	data->msgoutbuf[pos] = MESSAGE_REJECT; pos++;
 	data->msgout_len = pos;
 }
-	
+
 /*
  * timer
  */
@@ -482,7 +487,7 @@ static int nsp32_selection_autopara(struct scsi_cmnd *SCpnt)
 			 * the sending order of the message is:
 			 *  MCNT 3: MSG#0 -> MSG#1 -> MSG#2
 			 *  MCNT 2:          MSG#1 -> MSG#2
-			 *  MCNT 1:                   MSG#2    
+			 *  MCNT 1:                   MSG#2
 			 */
 			msgout >>= 8;
 			msgout |= ((unsigned int)(data->msgoutbuf[i]) << 24);
@@ -494,7 +499,8 @@ static int nsp32_selection_autopara(struct scsi_cmnd *SCpnt)
 		msgout = 0;
 	}
 
-	// nsp_dbg(NSP32_DEBUG_AUTOSCSI, "sel time out=0x%x\n", nsp32_read2(base, SEL_TIME_OUT));
+	// nsp_dbg(NSP32_DEBUG_AUTOSCSI, "sel time out=0x%x\n",
+	// nsp32_read2(base, SEL_TIME_OUT));
 	// nsp32_write2(base, SEL_TIME_OUT,   SEL_TIMEOUT_TIME);
 
 	/*
@@ -520,10 +526,10 @@ static int nsp32_selection_autopara(struct scsi_cmnd *SCpnt)
 
 	/* command control */
 	param->command_control = cpu_to_le16(CLEAR_CDB_FIFO_POINTER |
-					     AUTOSCSI_START         |
-					     AUTO_MSGIN_00_OR_04    |
-					     AUTO_MSGIN_02          |
-					     AUTO_ATN               );
+					     AUTOSCSI_START |
+					     AUTO_MSGIN_00_OR_04 |
+					     AUTO_MSGIN_02 |
+					     AUTO_ATN );
 
 
 	/* transfer control */
@@ -555,9 +561,9 @@ static int nsp32_selection_autopara(struct scsi_cmnd *SCpnt)
 	/*
 	 * transfer parameter to ASIC
 	 */
-	nsp32_write4(base, SGT_ADR,         data->auto_paddr);
-	nsp32_write2(base, COMMAND_CONTROL, CLEAR_CDB_FIFO_POINTER |
-		                            AUTO_PARAMETER         );
+	nsp32_write4(base, SGT_ADR, data->auto_paddr);
+	nsp32_write2(base, COMMAND_CONTROL,
+		     CLEAR_CDB_FIFO_POINTER | AUTO_PARAMETER );
 
 	/*
 	 * Check arbitration
@@ -599,7 +605,7 @@ static int nsp32_selection_autoscsi(struct scsi_cmnd *SCpnt)
 		set_host_byte(SCpnt, DID_BUS_BUSY);
 		status = 1;
 		goto out;
-        }
+	}
 
 	/*
 	 * clear execph
@@ -616,13 +622,14 @@ static int nsp32_selection_autoscsi(struct scsi_cmnd *SCpnt)
 	 */
 	for (i = 0; i < SCpnt->cmd_len; i++) {
 		nsp32_write1(base, COMMAND_DATA, SCpnt->cmnd[i]);
-        }
+	}
 	nsp32_dbg(NSP32_DEBUG_CDB_CONTENTS, "CDB[0]=[0x%x]", SCpnt->cmnd[0]);
 
 	/*
 	 * set SCSIOUT LATCH(initiator)/TARGET(target) (OR-ed) ID
 	 */
-	nsp32_write1(base, SCSI_OUT_LATCH_TARGET_ID, BIT(host_id) | BIT(target));
+	nsp32_write1(base, SCSI_OUT_LATCH_TARGET_ID,
+		     BIT(host_id) | BIT(target));
 
 	/*
 	 * set SCSI MSGOUT REG
@@ -642,7 +649,7 @@ static int nsp32_selection_autoscsi(struct scsi_cmnd *SCpnt)
 			 * the sending order of the message is:
 			 *  MCNT 3: MSG#0 -> MSG#1 -> MSG#2
 			 *  MCNT 2:          MSG#1 -> MSG#2
-			 *  MCNT 1:                   MSG#2    
+			 *  MCNT 1:                   MSG#2
 			 */
 			msgout >>= 8;
 			msgout |= ((unsigned int)(data->msgoutbuf[i]) << 24);
@@ -662,7 +669,7 @@ static int nsp32_selection_autoscsi(struct scsi_cmnd *SCpnt)
 
 	/*
 	 * set SREQ hazard killer sampling rate
-	 * 
+	 *
 	 * TODO: sample_rate (BASE+0F) is 0 when internal clock = 40MHz.
 	 *      check other internal clock!
 	 */
@@ -687,7 +694,8 @@ static int nsp32_selection_autoscsi(struct scsi_cmnd *SCpnt)
 	nsp32_dbg(NSP32_DEBUG_AUTOSCSI,
 		  "syncreg=0x%x, ackwidth=0x%x, sgtpaddr=0x%x, id=0x%x",
 		  nsp32_read1(base, SYNC_REG), nsp32_read1(base, ACK_WIDTH),
-		  nsp32_read4(base, SGT_ADR), nsp32_read1(base, SCSI_OUT_LATCH_TARGET_ID));
+		  nsp32_read4(base, SGT_ADR),
+		  nsp32_read1(base, SCSI_OUT_LATCH_TARGET_ID));
 	nsp32_dbg(NSP32_DEBUG_AUTOSCSI, "msgout_len=%d, msgout=0x%x",
 		  data->msgout_len, msgout);
 
@@ -716,10 +724,10 @@ static int nsp32_selection_autoscsi(struct scsi_cmnd *SCpnt)
 	 * start AUTO SCSI, kick off arbitration
 	 */
 	command = (CLEAR_CDB_FIFO_POINTER |
-		   AUTOSCSI_START         |
+		   AUTOSCSI_START	  |
 		   AUTO_MSGIN_00_OR_04    |
-		   AUTO_MSGIN_02          |
-		   AUTO_ATN                );
+		   AUTO_MSGIN_02	  |
+		   AUTO_ATN);
 	nsp32_write2(base, COMMAND_CONTROL, command);
 
 	/*
@@ -739,9 +747,9 @@ static int nsp32_selection_autoscsi(struct scsi_cmnd *SCpnt)
 
 /*
  * Arbitration Status Check
- *	
+ *
  * Note: Arbitration counter is waited during ARBIT_GO is not lifting.
- *	 Using udelay(1) consumes CPU time and system time, but 
+ *	 Using udelay(1) consumes CPU time and system time, but
  *	 arbitration delay time is defined minimal 2.4us in SCSI
  *	 specification, thus udelay works as coarse grained wait timer.
  */
@@ -775,7 +783,7 @@ static int nsp32_arbitration(struct scsi_cmnd *SCpnt, unsigned int base)
 		nsp32_dbg(NSP32_DEBUG_AUTOSCSI, "arbit timeout");
 		set_host_byte(SCpnt, DID_NO_CONNECT);
 		status = FALSE;
-        }
+	}
 
 	/*
 	 * clear Arbit
@@ -821,7 +829,8 @@ static int nsp32_reselection(struct scsi_cmnd *SCpnt, unsigned char newlun)
 	 * or current nexus is not existed, unexpected
 	 * reselection is occurred. Send reject message.
 	 */
-	if (newid >= ARRAY_SIZE(data->lunt) || newlun >= ARRAY_SIZE(data->lunt[0])) {
+	if (newid >= ARRAY_SIZE(data->lunt) ||
+	    newlun >= ARRAY_SIZE(data->lunt[0])) {
 		nsp32_msg(KERN_WARNING, "unknown id/lun");
 		return FALSE;
 	} else if(data->lunt[newid][newlun].SCpnt == NULL) {
@@ -875,7 +884,8 @@ static int nsp32_setup_sg_table(struct scsi_cmnd *SCpnt)
 
 			if (le32_to_cpu(sgt[i].len) > 0x10000) {
 				nsp32_msg(KERN_ERR,
-					"can't transfer over 64KB at a time, size=0x%x", le32_to_cpu(sgt[i].len));
+					"can't transfer over 64KB at a time, "
+					"size=0x%lx", le32_to_cpu(sgt[i].len));
 				return FALSE;
 			}
 			nsp32_dbg(NSP32_DEBUG_SGLIST,
@@ -893,7 +903,8 @@ static int nsp32_setup_sg_table(struct scsi_cmnd *SCpnt)
 	return TRUE;
 }
 
-static int nsp32_queuecommand_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
+static int nsp32_queuecommand_lck(struct scsi_cmnd *SCpnt,
+				  void (*done)(struct scsi_cmnd *))
 {
 	nsp32_hw_data *data = (nsp32_hw_data *)SCpnt->device->host->hostdata;
 	nsp32_target *target;
@@ -903,8 +914,9 @@ static int nsp32_queuecommand_lck(struct scsi_cmnd *SCpnt, void (*done)(struct s
 	nsp32_dbg(NSP32_DEBUG_QUEUECOMMAND,
 		  "enter. target: 0x%x LUN: 0x%llx cmnd: 0x%x cmndlen: 0x%x "
 		  "use_sg: 0x%x reqbuf: 0x%lx reqlen: 0x%x",
-		  SCpnt->device->id, SCpnt->device->lun, SCpnt->cmnd[0], SCpnt->cmd_len,
-		  scsi_sg_count(SCpnt), scsi_sglist(SCpnt), scsi_bufflen(SCpnt));
+		  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);
@@ -967,7 +979,7 @@ static int nsp32_queuecommand_lck(struct scsi_cmnd *SCpnt, void (*done)(struct s
 	/* Build IDENTIFY */
 	nsp32_build_identify(SCpnt);
 
-	/* 
+	/*
 	 * If target is the first time to transfer after the reset
 	 * (target don't have SDTR_DONE and SDTR_INITIATOR), sync
 	 * message SDTR is needed to do synchronous transfer.
@@ -1052,9 +1064,9 @@ static int nsp32hw_init(nsp32_hw_data *data)
 		nsp32_index_write2(base, CFG_LATE_CACHE, lc_reg & 0xffff);
 	}
 
-	nsp32_write2(base, IRQ_CONTROL,        IRQ_CONTROL_ALL_IRQ_MASK);
-	nsp32_write2(base, TRANSFER_CONTROL,   0);
-	nsp32_write4(base, BM_CNT,             0);
+	nsp32_write2(base, IRQ_CONTROL, IRQ_CONTROL_ALL_IRQ_MASK);
+	nsp32_write2(base, TRANSFER_CONTROL, 0);
+	nsp32_write4(base, BM_CNT, 0);
 	nsp32_write2(base, SCSI_EXECUTE_PHASE, 0);
 
 	do {
@@ -1082,12 +1094,13 @@ static int nsp32hw_init(nsp32_hw_data *data)
 		  nsp32_index_read1(base, FIFO_EMPTY_SHLD_COUNT));
 
 	nsp32_index_write1(base, CLOCK_DIV, data->clock);
-	nsp32_index_write1(base, BM_CYCLE,  MEMRD_CMD1 | SGT_AUTO_PARA_MEMED_CMD);
+	nsp32_index_write1(base, BM_CYCLE,
+			   MEMRD_CMD1 | SGT_AUTO_PARA_MEMED_CMD);
 	nsp32_write1(base, PARITY_CONTROL, 0);	/* parity check is disable */
 
 	/*
 	 * initialize MISC_WRRD register
-	 * 
+	 *
 	 * Note: Designated parameters is obeyed as following:
 	 *	MISC_SCSI_DIRECTION_DETECTOR_SELECT: It must be set.
 	 *	MISC_MASTER_TERMINATION_SELECT:      It must be set.
@@ -1102,10 +1115,10 @@ static int nsp32hw_init(nsp32_hw_data *data)
 	 */
 	nsp32_index_write2(base, MISC_WR,
 			   (SCSI_DIRECTION_DETECTOR_SELECT |
-			    DELAYED_BMSTART                |
-			    MASTER_TERMINATION_SELECT      |
-			    BMREQ_NEGATE_TIMING_SEL        |
-			    AUTOSEL_TIMING_SEL             |
+			    DELAYED_BMSTART |
+			    MASTER_TERMINATION_SELECT |
+			    BMREQ_NEGATE_TIMING_SEL |
+			    AUTOSEL_TIMING_SEL |
 			    BMSTOP_CHANGE2_NONDATA_PHASE));
 
 	nsp32_index_write1(base, TERM_PWR_CONTROL, 0);
@@ -1126,15 +1139,16 @@ static int nsp32hw_init(nsp32_hw_data *data)
 	 * enable to select designated IRQ (except for
 	 * IRQSELECT_SERR, IRQSELECT_PERR, IRQSELECT_BMCNTERR)
 	 */
-	nsp32_index_write2(base, IRQ_SELECT, IRQSELECT_TIMER_IRQ         |
-			                     IRQSELECT_SCSIRESET_IRQ     |
-			                     IRQSELECT_FIFO_SHLD_IRQ     |
-			                     IRQSELECT_RESELECT_IRQ      |
-			                     IRQSELECT_PHASE_CHANGE_IRQ  |
-			                     IRQSELECT_AUTO_SCSI_SEQ_IRQ |
-			                  //   IRQSELECT_BMCNTERR_IRQ      |
-			                     IRQSELECT_TARGET_ABORT_IRQ  |
-			                     IRQSELECT_MASTER_ABORT_IRQ );
+	nsp32_index_write2(base, IRQ_SELECT,
+			   IRQSELECT_TIMER_IRQ |
+			   IRQSELECT_SCSIRESET_IRQ |
+			   IRQSELECT_FIFO_SHLD_IRQ |
+			   IRQSELECT_RESELECT_IRQ |
+			   IRQSELECT_PHASE_CHANGE_IRQ |
+			   IRQSELECT_AUTO_SCSI_SEQ_IRQ |
+			   //   IRQSELECT_BMCNTERR_IRQ      |
+			   IRQSELECT_TARGET_ABORT_IRQ |
+			   IRQSELECT_MASTER_ABORT_IRQ );
 	nsp32_write2(base, IRQ_CONTROL, 0);
 
 	/* PCI LED off */
@@ -1164,11 +1178,12 @@ static irqreturn_t do_nsp32_isr(int irq, void *dev_id)
 	 * IRQ check, then enable IRQ mask
 	 */
 	irq_stat = nsp32_read2(base, IRQ_STATUS);
-	nsp32_dbg(NSP32_DEBUG_INTR, 
+	nsp32_dbg(NSP32_DEBUG_INTR,
 		  "enter IRQ: %d, IRQstatus: 0x%x", irq, irq_stat);
 	/* is this interrupt comes from Ninja asic? */
 	if ((irq_stat & IRQSTATUS_ANY_IRQ) == 0) {
-		nsp32_dbg(NSP32_DEBUG_INTR, "shared interrupt: irq other 0x%x", irq_stat);
+		nsp32_dbg(NSP32_DEBUG_INTR,
+			  "shared interrupt: irq other 0x%x", irq_stat);
 		goto out2;
 	}
 	handled = 1;
@@ -1208,7 +1223,8 @@ static irqreturn_t do_nsp32_isr(int irq, void *dev_id)
 
 	if (SCpnt == NULL) {
 		nsp32_msg(KERN_WARNING, "SCpnt==NULL this can't be happened");
-		nsp32_msg(KERN_WARNING, "irq_stat=0x%x trans_stat=0x%x", irq_stat, trans_stat);
+		nsp32_msg(KERN_WARNING, "irq_stat=0x%x trans_stat=0x%x",
+			  irq_stat, trans_stat);
 		goto out;
 	}
 
@@ -1266,13 +1282,13 @@ static irqreturn_t do_nsp32_isr(int irq, void *dev_id)
 				  "Data in/out phase processed");
 
 			/* read BMCNT, SGT pointer addr */
-			nsp32_dbg(NSP32_DEBUG_INTR, "BMCNT=0x%lx", 
+			nsp32_dbg(NSP32_DEBUG_INTR, "BMCNT=0x%lx",
 				    nsp32_read4(base, BM_CNT));
-			nsp32_dbg(NSP32_DEBUG_INTR, "addr=0x%lx", 
+			nsp32_dbg(NSP32_DEBUG_INTR, "addr=0x%lx",
 				    nsp32_read4(base, SGT_ADR));
-			nsp32_dbg(NSP32_DEBUG_INTR, "SACK=0x%lx", 
+			nsp32_dbg(NSP32_DEBUG_INTR, "SACK=0x%lx",
 				    nsp32_read4(base, SACK_CNT));
-			nsp32_dbg(NSP32_DEBUG_INTR, "SSACK=0x%lx", 
+			nsp32_dbg(NSP32_DEBUG_INTR, "SSACK=0x%lx",
 				    nsp32_read4(base, SAVED_SACK_CNT));
 
 			scsi_set_resid(SCpnt, 0); /* all data transferred! */
@@ -1307,7 +1323,7 @@ static irqreturn_t do_nsp32_isr(int irq, void *dev_id)
 			 * Read CSB and substitute CSB for SCpnt->result
 			 * to save status phase stutas byte.
 			 * scsi error handler checks host_byte (DID_*:
-			 * low level driver to indicate status), then checks 
+			 * low level driver to indicate status), then checks
 			 * status_byte (SCSI status byte).
 			 */
 			set_status_byte(SCpnt,
@@ -1316,7 +1332,7 @@ static irqreturn_t do_nsp32_isr(int irq, void *dev_id)
 
 		if (auto_stat & ILLEGAL_PHASE) {
 			/* Illegal phase is detected. SACK is not back. */
-			nsp32_msg(KERN_WARNING, 
+			nsp32_msg(KERN_WARNING,
 				  "AUTO SCSI ILLEGAL PHASE OCCUR!!!!");
 
 			/* TODO: currently we don't have any action... bus reset? */
@@ -1369,7 +1385,8 @@ static irqreturn_t do_nsp32_isr(int irq, void *dev_id)
 			break;
 		default:
 			nsp32_dbg(NSP32_DEBUG_INTR, "fifo/other phase");
-			nsp32_dbg(NSP32_DEBUG_INTR, "irq_stat=0x%x trans_stat=0x%x", irq_stat, trans_stat);
+			nsp32_dbg(NSP32_DEBUG_INTR, "irq_stat=0x%x trans_stat=0x%x",
+				  irq_stat, trans_stat);
 			show_busphase(busphase);
 			break;
 		}
@@ -1446,21 +1463,28 @@ static int nsp32_show_info(struct seq_file *m, struct Scsi_Host *host)
 	base = host->io_port;
 
 	seq_puts(m, "NinjaSCSI-32 status\n\n");
-	seq_printf(m, "Driver version:        %s, $Revision: 1.33 $\n", nsp32_release_version);
-	seq_printf(m, "SCSI host No.:         %d\n",		hostno);
-	seq_printf(m, "IRQ:                   %d\n",		host->irq);
-	seq_printf(m, "IO:                    0x%lx-0x%lx\n", host->io_port, host->io_port + host->n_io_port - 1);
-	seq_printf(m, "MMIO(virtual address): 0x%lx-0x%lx\n",	host->base, host->base + data->MmioLength - 1);
-	seq_printf(m, "sg_tablesize:          %d\n",		host->sg_tablesize);
-	seq_printf(m, "Chip revision:         0x%x\n",		(nsp32_read2(base, INDEX_REG) >> 8) & 0xff);
+	seq_printf(m, "Driver version:        %s, $Revision: 1.33 $\n",
+		   nsp32_release_version);
+	seq_printf(m, "SCSI host No.:         %d\n", hostno);
+	seq_printf(m, "IRQ:                   %d\n", host->irq);
+	seq_printf(m, "IO:                    0x%lx-0x%lx\n",
+		   host->io_port, host->io_port + host->n_io_port - 1);
+	seq_printf(m, "MMIO(virtual address): 0x%lx-0x%lx\n",
+		   host->base, host->base + data->MmioLength - 1);
+	seq_printf(m, "sg_tablesize:          %d\n",
+		   host->sg_tablesize);
+	seq_printf(m, "Chip revision:         0x%x\n",
+		   (nsp32_read2(base, INDEX_REG) >> 8) & 0xff);
 
 	mode_reg = nsp32_index_read1(base, CHIP_MODE);
 	model    = data->pci_devid->driver_data;
 
 #ifdef CONFIG_PM
-	seq_printf(m, "Power Management:      %s\n",          (mode_reg & OPTF) ? "yes" : "no");
+	seq_printf(m, "Power Management:      %s\n",
+		   (mode_reg & OPTF) ? "yes" : "no");
 #endif
-	seq_printf(m, "OEM:                   %ld, %s\n",     (mode_reg & (OEM0|OEM1)), nsp32_model[model]);
+	seq_printf(m, "OEM:                   %ld, %s\n",
+		   (mode_reg & (OEM0|OEM1)), nsp32_model[model]);
 
 	spin_lock_irqsave(&(data->Lock), flags);
 	seq_printf(m, "CurrentSC:             0x%p\n\n",      data->CurrentSC);
@@ -1478,7 +1502,7 @@ static int nsp32_show_info(struct seq_file *m, struct Scsi_Host *host)
 		}
 
 		if (data->target[id].sync_flag == SDTR_DONE) {
-			if (data->target[id].period == 0            &&
+			if (data->target[id].period == 0 &&
 			    data->target[id].offset == ASYNC_OFFSET ) {
 				seq_puts(m, "async");
 			} else {
@@ -1520,7 +1544,7 @@ static void nsp32_scsi_done(struct scsi_cmnd *SCpnt)
 	 * clear TRANSFERCONTROL_BM_START
 	 */
 	nsp32_write2(base, TRANSFER_CONTROL, 0);
-	nsp32_write4(base, BM_CNT,           0);
+	nsp32_write4(base, BM_CNT, 0);
 
 	/*
 	 * call scsi_done
@@ -1555,7 +1579,7 @@ static int nsp32_busfree_occur(struct scsi_cmnd *SCpnt, unsigned short execph)
 	nsp32_dbg(NSP32_DEBUG_BUSFREE, "enter execph=0x%x", execph);
 	show_autophase(execph);
 
-	nsp32_write4(base, BM_CNT,           0);
+	nsp32_write4(base, BM_CNT, 0);
 	nsp32_write2(base, TRANSFER_CONTROL, 0);
 
 	/*
@@ -1563,7 +1587,7 @@ static int nsp32_busfree_occur(struct scsi_cmnd *SCpnt, unsigned short execph)
 	 *
 	 * VALID:
 	 *   Save Data Pointer is received. Adjust pointer.
-	 *   
+	 *
 	 * NO-VALID:
 	 *   SCSI-3 says if Save Data Pointer is not received, then we restart
 	 *   processing and we can't adjust any SCSI data pointer in next data
@@ -1576,7 +1600,7 @@ static int nsp32_busfree_occur(struct scsi_cmnd *SCpnt, unsigned short execph)
 		 * Check sack_cnt/saved_sack_cnt, then adjust sg table if
 		 * needed.
 		 */
-		if (!(execph & MSGIN_00_VALID) && 
+		if (!(execph & MSGIN_00_VALID) &&
 		    ((execph & DATA_IN_PHASE) || (execph & DATA_OUT_PHASE))) {
 			unsigned int sacklen, s_sacklen;
 
@@ -1619,7 +1643,7 @@ static int nsp32_busfree_occur(struct scsi_cmnd *SCpnt, unsigned short execph)
 		 * no processing.
 		 */
 	}
-	
+
 	if (execph & MSGIN_03_VALID) {
 		/* MsgIn03 was valid to be processed. No need processing. */
 	}
@@ -1641,7 +1665,7 @@ static int nsp32_busfree_occur(struct scsi_cmnd *SCpnt, unsigned short execph)
 		 * negotiating.
 		 */
 		if (execph & (MSGIN_00_VALID | MSGIN_04_VALID)) {
-			/* 
+			/*
 			 * If valid message is received, then
 			 * negotiation is succeeded.
 			 */
@@ -1669,7 +1693,7 @@ static int nsp32_busfree_occur(struct scsi_cmnd *SCpnt, unsigned short execph)
 
 		SCpnt->SCp.Status  = nsp32_read1(base, SCSI_CSB_IN);
 		SCpnt->SCp.Message = COMMAND_COMPLETE;
-		nsp32_dbg(NSP32_DEBUG_BUSFREE, 
+		nsp32_dbg(NSP32_DEBUG_BUSFREE,
 			  "normal end stat=0x%x resid=0x%x\n",
 			  SCpnt->SCp.Status, scsi_get_resid(SCpnt));
 		set_msg_byte(SCpnt, SCpnt->SCp.Message);
@@ -1681,7 +1705,7 @@ static int nsp32_busfree_occur(struct scsi_cmnd *SCpnt, unsigned short execph)
 		/* MsgIn 04: Disconnect */
 		set_status_byte(SCpnt, nsp32_read1(base, SCSI_CSB_IN));
 		SCpnt->SCp.Message = DISCONNECT;
-		
+
 		nsp32_dbg(NSP32_DEBUG_BUSFREE, "disconnect");
 		return TRUE;
 	} else {
@@ -1707,12 +1731,12 @@ static int nsp32_busfree_occur(struct scsi_cmnd *SCpnt, unsigned short execph)
 static void nsp32_adjust_busfree(struct scsi_cmnd *SCpnt, unsigned int s_sacklen)
 {
 	nsp32_hw_data *data = (nsp32_hw_data *)SCpnt->device->host->hostdata;
-	int                   old_entry = data->cur_entry;
-	int                   new_entry;
-	int                   sg_num = data->cur_lunt->sg_num;
-	nsp32_sgtable *sgt    = data->cur_lunt->sglun->sgt;
-	unsigned int          restlen, sentlen;
-	u32_le                len, addr;
+	int old_entry = data->cur_entry;
+	int new_entry;
+	int sg_num = data->cur_lunt->sg_num;
+	nsp32_sgtable *sgt = data->cur_lunt->sglun->sgt;
+	unsigned int restlen, sentlen;
+	u32_le len, addr;
 
 	nsp32_dbg(NSP32_DEBUG_SGLIST, "old resid=0x%x", scsi_get_resid(SCpnt));
 
@@ -1720,7 +1744,7 @@ static void nsp32_adjust_busfree(struct scsi_cmnd *SCpnt, unsigned int s_sacklen
 	s_sacklen -= le32_to_cpu(sgt[old_entry].addr) & 3;
 
 	/*
-	 * calculate new_entry from sack count and each sgt[].len 
+	 * calculate new_entry from sack count and each sgt[].len
 	 * calculate the byte which is intent to send
 	 */
 	sentlen = 0;
@@ -1738,8 +1762,10 @@ static void nsp32_adjust_busfree(struct scsi_cmnd *SCpnt, unsigned int s_sacklen
 
 	if (sentlen == s_sacklen) {
 		/* XXX: confirm it's ok or not */
-		/* In this case, it's ok because we are at 
-		   the head element of the sg. restlen is correctly calculated. */
+		/* In this case, it's ok because we are at
+		 * the head element of the sg. restlen is correctly
+		 * calculated.
+		 */
 	}
 
 	/* calculate the rest length for transferring */
@@ -1754,7 +1780,7 @@ static void nsp32_adjust_busfree(struct scsi_cmnd *SCpnt, unsigned int s_sacklen
 
 	/* set cur_entry with new_entry */
 	data->cur_entry = new_entry;
- 
+
 	return;
 
  last:
@@ -1782,7 +1808,7 @@ static void nsp32_msgout_occur(struct scsi_cmnd *SCpnt)
 	nsp32_hw_data *data = (nsp32_hw_data *)SCpnt->device->host->hostdata;
 	unsigned int base   = SCpnt->device->host->io_port;
 	int i;
-	
+
 	nsp32_dbg(NSP32_DEBUG_MSGOUTOCCUR,
 		  "enter: msgout_len: 0x%x", data->msgout_len);
 
@@ -1816,10 +1842,10 @@ static void nsp32_msgout_occur(struct scsi_cmnd *SCpnt)
 			//nsp32_restart_autoscsi(SCpnt, command);
 			nsp32_write2(base, COMMAND_CONTROL,
 					 (CLEAR_CDB_FIFO_POINTER |
-					  AUTO_COMMAND_PHASE     |
-					  AUTOSCSI_RESTART       |
-					  AUTO_MSGIN_00_OR_04    |
-					  AUTO_MSGIN_02          ));
+					  AUTO_COMMAND_PHASE |
+					  AUTOSCSI_RESTART |
+					  AUTO_MSGIN_00_OR_04 |
+					  AUTO_MSGIN_02 ));
 		}
 		/*
 		 * Write data with SACK, then wait sack is
@@ -1961,7 +1987,7 @@ static void nsp32_msgin_occur(struct scsi_cmnd     *SCpnt,
 			goto reject;
 		}
 	}
-	
+
 	/*
 	 * processing messages except for IDENTIFY
 	 *
@@ -1977,10 +2003,10 @@ static void nsp32_msgin_occur(struct scsi_cmnd     *SCpnt,
 		 * These messages should not be occurred.
 		 * They should be processed on AutoSCSI sequencer.
 		 */
-		nsp32_msg(KERN_WARNING, 
+		nsp32_msg(KERN_WARNING,
 			   "unexpected message of AutoSCSI MsgIn: 0x%x", msg);
 		break;
-		
+
 	case RESTORE_POINTERS:
 		/*
 		 * AutoMsgIn03 is disabled, and HBA gets this message.
@@ -2006,7 +2032,7 @@ static void nsp32_msgin_occur(struct scsi_cmnd     *SCpnt,
 		/*
 		 * set new sg pointer
 		 */
-		new_sgtp = data->cur_lunt->sglun_paddr + 
+		new_sgtp = data->cur_lunt->sglun_paddr +
 			(data->cur_lunt->cur_entry * sizeof(nsp32_sgtable));
 		nsp32_write4(base, SGT_ADR, new_sgtp);
 
@@ -2017,13 +2043,13 @@ static void nsp32_msgin_occur(struct scsi_cmnd     *SCpnt,
 		 * These messages should not be occurred.
 		 * They should be processed on AutoSCSI sequencer.
 		 */
-		nsp32_msg (KERN_WARNING, 
+		nsp32_msg (KERN_WARNING,
 			   "unexpected message of AutoSCSI MsgIn: SAVE_POINTERS");
-		
+
 		break;
-		
+
 	case MESSAGE_REJECT:
-		/* If previous message_out is sending SDTR, and get 
+		/* If previous message_out is sending SDTR, and get
 		   message_reject from target, SDTR negotiation is failed */
 		if (data->cur_target->sync_flag &
 				(SDTR_INITIATOR | SDTR_TARGET)) {
@@ -2042,7 +2068,7 @@ static void nsp32_msgin_occur(struct scsi_cmnd     *SCpnt,
 	case LINKED_CMD_COMPLETE:
 	case LINKED_FLG_CMD_COMPLETE:
 		/* queue tag is not supported currently */
-		nsp32_msg (KERN_WARNING, 
+		nsp32_msg (KERN_WARNING,
 			   "unsupported message: 0x%x", msgtype);
 		break;
 
@@ -2095,7 +2121,7 @@ static void nsp32_msgin_occur(struct scsi_cmnd     *SCpnt,
 		}
 
 		/*
-		 * Reach here means regular length of each type of 
+		 * Reach here means regular length of each type of
 		 * extended messages.
 		 */
 		switch (data->msginbuf[2]) {
@@ -2130,12 +2156,12 @@ static void nsp32_msgin_occur(struct scsi_cmnd     *SCpnt,
 			goto reject; /* not implemented yet */
 
 			break;
-			
+
 		default:
 			goto reject;
 		}
 		break;
-		
+
 	default:
 		goto reject;
 	}
@@ -2151,7 +2177,7 @@ static void nsp32_msgin_occur(struct scsi_cmnd     *SCpnt,
 		 * AutoSCSI restart, at the same time MsgOutOccur should be
 		 * happened (however, such situation is really possible...?).
 		 */
-		if (data->msgout_len > 0) {	
+		if (data->msgout_len > 0) {
 			nsp32_write4(base, SCSI_MSG_OUT, 0);
 			command |= AUTO_ATN;
 		}
@@ -2193,7 +2219,7 @@ static void nsp32_msgin_occur(struct scsi_cmnd     *SCpnt,
 	return;
 
  reject:
-	nsp32_msg(KERN_WARNING, 
+	nsp32_msg(KERN_WARNING,
 		  "invalid or unsupported MessageIn, rejected. "
 		  "current msg: 0x%x (len: 0x%x), processing msg: 0x%x",
 		  msg, data->msgin_len, msgtype);
@@ -2204,7 +2230,7 @@ static void nsp32_msgin_occur(struct scsi_cmnd     *SCpnt,
 }
 
 /*
- * 
+ *
  */
 static void nsp32_analyze_sdtr(struct scsi_cmnd *SCpnt)
 {
@@ -2220,16 +2246,16 @@ static void nsp32_analyze_sdtr(struct scsi_cmnd *SCpnt)
 	 * If this inititor sent the SDTR message, then target responds SDTR,
 	 * initiator SYNCREG, ACKWIDTH from SDTR parameter.
 	 * Messages are not appropriate, then send back reject message.
-	 * If initiator did not send the SDTR, but target sends SDTR, 
+	 * If initiator did not send the SDTR, but target sends SDTR,
 	 * initiator calculator the appropriate parameter and send back SDTR.
-	 */	
+	 */
 	if (target->sync_flag & SDTR_INITIATOR) {
 		/*
 		 * Initiator sent SDTR, the target responds and
 		 * send back negotiation SDTR.
 		 */
 		nsp32_dbg(NSP32_DEBUG_MSGINOCCUR, "target responds SDTR");
-	
+
 		target->sync_flag &= ~SDTR_INITIATOR;
 		target->sync_flag |= SDTR_DONE;
 
@@ -2243,7 +2269,7 @@ static void nsp32_analyze_sdtr(struct scsi_cmnd *SCpnt)
 			 */
 			goto reject;
 		}
-		
+
 		if (get_offset == ASYNC_OFFSET) {
 			/*
 			 * Negotiation is succeeded, the target want
@@ -2274,7 +2300,7 @@ static void nsp32_analyze_sdtr(struct scsi_cmnd *SCpnt)
 
 		if (entry < 0) {
 			/*
-			 * Target want to use long period which is not 
+			 * Target want to use long period which is not
 			 * acceptable NinjaSCSI-32Bi/UDE.
 			 */
 			goto reject;
@@ -2287,7 +2313,7 @@ static void nsp32_analyze_sdtr(struct scsi_cmnd *SCpnt)
 	} else {
 		/* Target send SDTR to initiator. */
 		nsp32_dbg(NSP32_DEBUG_MSGINOCCUR, "target send SDTR");
-	
+
 		target->sync_flag |= SDTR_INITIATOR;
 
 		/* offset: */
@@ -2451,7 +2477,7 @@ static void nsp32_wait_req(nsp32_hw_data *data, int state)
 	do {
 		bus = nsp32_read1(base, SCSI_BUS_MONITOR);
 		if ((bus & BUSMON_REQ) == req_bit) {
-			nsp32_dbg(NSP32_DEBUG_WAIT, 
+			nsp32_dbg(NSP32_DEBUG_WAIT,
 				  "wait_time: %d", wait_time);
 			return;
 		}
@@ -2611,7 +2637,7 @@ static int nsp32_detect(struct pci_dev *pdev)
 	 */
 
 	/*
-	 * setup DMA 
+	 * setup DMA
 	 */
 	if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)) != 0) {
 		nsp32_msg (KERN_ERR, "failed to set PCI DMA mask");
@@ -2711,7 +2737,7 @@ static int nsp32_detect(struct pci_dev *pdev)
 		goto free_sg_list;
 	}
 
-        /*
+	/*
          * PCI IO register
          */
 	res = request_region(host->io_port, host->n_io_port, "nsp32");
@@ -2720,7 +2746,7 @@ static int nsp32_detect(struct pci_dev *pdev)
 			  "I/O region 0x%x+0x%x is already used",
 			  data->BaseAddress, data->NumAddress);
 		goto free_irq;
-        }
+	}
 
 	ret = scsi_add_host(host, &pdev->dev);
 	if (ret) {
@@ -2744,7 +2770,7 @@ static int nsp32_detect(struct pci_dev *pdev)
  free_autoparam:
 	dma_free_coherent(&pdev->dev, sizeof(nsp32_autoparam),
 			    data->autoparam, data->auto_paddr);
-	
+
  scsi_unregister:
 	scsi_host_put(host);
 
@@ -2811,7 +2837,7 @@ static int nsp32_eh_abort(struct scsi_cmnd *SCpnt)
 	}
 
 	nsp32_write2(base, TRANSFER_CONTROL, 0);
-	nsp32_write2(base, BM_CNT,           0);
+	nsp32_write2(base, BM_CNT, 0);
 
 	set_host_byte(SCpnt, DID_ABORT);
 	nsp32_scsi_done(SCpnt);
@@ -2834,8 +2860,8 @@ static void nsp32_do_bus_reset(nsp32_hw_data *data)
 	 * clear counter
 	 */
 	nsp32_write2(base, TRANSFER_CONTROL, 0);
-	nsp32_write4(base, BM_CNT,           0);
-	nsp32_write4(base, CLR_COUNTER,      CLRCOUNTER_ALLMASK);
+	nsp32_write4(base, BM_CNT, 0);
+	nsp32_write4(base, CLR_COUNTER, CLRCOUNTER_ALLMASK);
 
 	/*
 	 * fall back to asynchronous transfer mode
@@ -2857,7 +2883,7 @@ static void nsp32_do_bus_reset(nsp32_hw_data *data)
 	for(i = 0; i < 5; i++) {
 		intrdat = nsp32_read2(base, IRQ_STATUS); /* dummy read */
 		nsp32_dbg(NSP32_DEBUG_BUSRESET, "irq:1: 0x%x", intrdat);
-        }
+	}
 
 	data->CurrentSC = NULL;
 }
@@ -2868,7 +2894,7 @@ static int nsp32_eh_host_reset(struct scsi_cmnd *SCpnt)
 	unsigned int      base = SCpnt->device->host->io_port;
 	nsp32_hw_data    *data = (nsp32_hw_data *)host->hostdata;
 
-	nsp32_msg(KERN_INFO, "Host Reset");	
+	nsp32_msg(KERN_INFO, "Host Reset");
 	nsp32_dbg(NSP32_DEBUG_BUSRESET, "SCpnt=0x%x", SCpnt);
 
 	spin_lock_irq(SCpnt->device->host->host_lock);
@@ -2943,13 +2969,13 @@ static int nsp32_getprom_param(nsp32_hw_data *data)
  * AT24C01A (Logitec: LHA-600S), AT24C02 (Melco Buffalo: IFC-USLP) data map:
  *
  *   ROMADDR
- *   0x00 - 0x06 :  Device Synchronous Transfer Period (SCSI ID 0 - 6) 
+ *   0x00 - 0x06 :  Device Synchronous Transfer Period (SCSI ID 0 - 6)
  *			Value 0x0: ASYNC, 0x0c: Ultra-20M, 0x19: Fast-10M
  *   0x07        :  HBA Synchronous Transfer Period
  *			Value 0: AutoSync, 1: Manual Setting
  *   0x08 - 0x0f :  Not Used? (0x0)
  *   0x10        :  Bus Termination
- * 			Value 0: Auto[ON], 1: ON, 2: OFF
+ *			Value 0: Auto[ON], 1: ON, 2: OFF
  *   0x11        :  Not Used? (0)
  *   0x12        :  Bus Reset Delay Time (0x03)
  *   0x13        :  Bootable CD Support
@@ -2957,7 +2983,7 @@ static int nsp32_getprom_param(nsp32_hw_data *data)
  *   0x14        :  Device Scan
  *			Bit   7  6  5  4  3  2  1  0
  *			      |  <----------------->
- * 			      |    SCSI ID: Value 0: Skip, 1: YES
+ *			      |    SCSI ID: Value 0: Skip, 1: YES
  *			      |->  Value 0: ALL scan,  Value 1: Manual
  *   0x15 - 0x1b :  Not Used? (0)
  *   0x1c        :  Constant? (0x01) (clock div?)
@@ -3037,7 +3063,7 @@ static int nsp32_getprom_at24(nsp32_hw_data *data)
  * C16 110 (I-O Data: SC-NBD) data map:
  *
  *   ROMADDR
- *   0x00 - 0x06 :  Device Synchronous Transfer Period (SCSI ID 0 - 6) 
+ *   0x00 - 0x06 :  Device Synchronous Transfer Period (SCSI ID 0 - 6)
  *			Value 0x0: 20MB/S, 0x1: 10MB/S, 0x2: 5MB/S, 0x3: ASYNC
  *   0x07        :  0 (HBA Synchronous Transfer Period: Auto Sync)
  *   0x08 - 0x0f :  Not Used? (0x0)
@@ -3045,7 +3071,7 @@ static int nsp32_getprom_at24(nsp32_hw_data *data)
  *			Value 0: PIO, 1: Busmater
  *   0x11        :  Bus Reset Delay Time (0x00-0x20)
  *   0x12        :  Bus Termination
- * 			Value 0: Disable, 1: Enable
+ *			Value 0: Disable, 1: Enable
  *   0x13 - 0x19 :  Disconnection
  *			Value 0: Disable, 1: Enable
  *   0x1a - 0x7c :  Not Used? (0)
@@ -3157,7 +3183,7 @@ static int nsp32_prom_read(nsp32_hw_data *data, int romaddr)
 	for (i = 7; i >= 0; i--) {
 		val += (nsp32_prom_read_bit(data) << i);
 	}
-	
+
 	/* no ack */
 	nsp32_prom_write_bit(data, 1);
 
@@ -3282,7 +3308,8 @@ static int nsp32_resume(struct pci_dev *pdev)
 	nsp32_hw_data    *data = (nsp32_hw_data *)host->hostdata;
 	unsigned short    reg;
 
-	nsp32_msg(KERN_INFO, "pci-resume: pdev=0x%p, slot=%s, host=0x%p", pdev, pci_name(pdev), host);
+	nsp32_msg(KERN_INFO, "pci-resume: pdev=0x%p, slot=%s, host=0x%p",
+		  pdev, pci_name(pdev), host);
 
 	pci_set_power_state(pdev, PCI_D0);
 	pci_enable_wake    (pdev, PCI_D0, 0);
@@ -3317,7 +3344,7 @@ static int nsp32_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 	nsp32_dbg(NSP32_DEBUG_REGISTER, "enter");
 
-        ret = pci_enable_device(pdev);
+	ret = pci_enable_device(pdev);
 	if (ret) {
 		nsp32_msg(KERN_ERR, "failed to enable pci device");
 		return ret;
@@ -3352,7 +3379,7 @@ static void nsp32_remove(struct pci_dev *pdev)
 
 	nsp32_dbg(NSP32_DEBUG_REGISTER, "enter");
 
-        scsi_remove_host(host);
+	scsi_remove_host(host);
 
 	nsp32_release(host);
 
@@ -3365,8 +3392,8 @@ static struct pci_driver nsp32_driver = {
 	.probe		= nsp32_probe,
 	.remove		= nsp32_remove,
 #ifdef CONFIG_PM
-	.suspend	= nsp32_suspend, 
-	.resume		= nsp32_resume, 
+	.suspend	= nsp32_suspend,
+	.resume		= nsp32_resume,
 #endif
 };
 
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 25/42] nsp32: do not set message byte
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (23 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 24/42] nsp32: whitespace cleanup Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 26/42] wd33c93: use standard macros to set SCSI result Hannes Reinecke
                   ` (18 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

The message byte always devolves to COMMAND_COMPLETE, so there
is no point in setting it.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/nsp32.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/nsp32.c b/drivers/scsi/nsp32.c
index abecbcefc382..b75844c76f3a 100644
--- a/drivers/scsi/nsp32.c
+++ b/drivers/scsi/nsp32.c
@@ -1696,7 +1696,6 @@ static int nsp32_busfree_occur(struct scsi_cmnd *SCpnt, unsigned short execph)
 		nsp32_dbg(NSP32_DEBUG_BUSFREE,
 			  "normal end stat=0x%x resid=0x%x\n",
 			  SCpnt->SCp.Status, scsi_get_resid(SCpnt));
-		set_msg_byte(SCpnt, SCpnt->SCp.Message);
 		set_status_byte(SCpnt, SCpnt->SCp.Status);
 		nsp32_scsi_done(SCpnt);
 		/* All operation is done */
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 26/42] wd33c93: use standard macros to set SCSI result
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (24 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 25/42] nsp32: do not set message byte Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 27/42] wd33c93: translate message byte to host byte Hannes Reinecke
                   ` (17 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Use standard macros to set the SCSI result to avoid shift and mask
error.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/wd33c93.c | 45 +++++++++++++++++++++---------------------
 1 file changed, 23 insertions(+), 22 deletions(-)

diff --git a/drivers/scsi/wd33c93.c b/drivers/scsi/wd33c93.c
index a23277bb870e..0a5bb238f001 100644
--- a/drivers/scsi/wd33c93.c
+++ b/drivers/scsi/wd33c93.c
@@ -381,7 +381,8 @@ wd33c93_queuecommand_lck(struct scsi_cmnd *cmd,
  */
 	cmd->host_scribble = NULL;
 	cmd->scsi_done = done;
-	cmd->result = 0;
+	set_host_byte(cmd, DID_OK);
+	set_status_byte(cmd, SAM_STAT_GOOD);
 
 /* We use the Scsi_Pointer structure that's included with each command
  * as a scratchpad (as it's intended to be used!). The handy thing about
@@ -853,7 +854,7 @@ wd33c93_intr(struct Scsi_Host *instance)
 			hostdata->selecting = NULL;
 		}
 
-		cmd->result = DID_NO_CONNECT << 16;
+		set_host_byte(cmd, DID_NO_CONNECT);
 		hostdata->busy[cmd->device->id] &= ~(1 << (cmd->device->lun & 0xff));
 		hostdata->state = S_UNCONNECTED;
 		cmd->scsi_done(cmd);
@@ -1177,12 +1178,11 @@ wd33c93_intr(struct Scsi_Host *instance)
 				cmd->SCp.Status = lun;
 			if (cmd->cmnd[0] == REQUEST_SENSE
 			    && cmd->SCp.Status != SAM_STAT_GOOD)
-				cmd->result =
-				    (cmd->
-				     result & 0x00ffff) | (DID_ERROR << 16);
-			else
-				cmd->result =
-				    cmd->SCp.Status | (cmd->SCp.Message << 8);
+				set_host_byte(cmd, DID_ERROR);
+			else {
+				set_status_byte(cmd, cmd->SCp.Status);
+				set_msg_byte(cmd, cmd->SCp.Message);
+			}
 			cmd->scsi_done(cmd);
 
 /* We are no longer  connected to a target - check to see if
@@ -1262,11 +1262,13 @@ wd33c93_intr(struct Scsi_Host *instance)
 		    hostdata->connected = NULL;
 		hostdata->busy[cmd->device->id] &= ~(1 << (cmd->device->lun & 0xff));
 		hostdata->state = S_UNCONNECTED;
-		if (cmd->cmnd[0] == REQUEST_SENSE && cmd->SCp.Status != SAM_STAT_GOOD)
-			cmd->result =
-			    (cmd->result & 0x00ffff) | (DID_ERROR << 16);
-		else
-			cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
+		if (cmd->cmnd[0] == REQUEST_SENSE &&
+		    cmd->SCp.Status != SAM_STAT_GOOD)
+			set_host_byte(cmd, DID_ERROR);
+		else {
+			set_status_byte(cmd, cmd->SCp.Status);
+			set_msg_byte(cmd, cmd->SCp.Message);
+		}
 		cmd->scsi_done(cmd);
 
 /* We are no longer connected to a target - check to see if
@@ -1297,12 +1299,11 @@ wd33c93_intr(struct Scsi_Host *instance)
 			DB(DB_INTR, printk(":%d", cmd->SCp.Status))
 			    if (cmd->cmnd[0] == REQUEST_SENSE
 				&& cmd->SCp.Status != SAM_STAT_GOOD)
-				cmd->result =
-				    (cmd->
-				     result & 0x00ffff) | (DID_ERROR << 16);
-			else
-				cmd->result =
-				    cmd->SCp.Status | (cmd->SCp.Message << 8);
+				    set_host_byte(cmd, DID_ERROR);
+			    else {
+				    set_status_byte(cmd, cmd->SCp.Status);
+				    set_msg_byte(cmd, cmd->SCp.Message);
+			    }
 			cmd->scsi_done(cmd);
 			break;
 		case S_PRE_TMP_DISC:
@@ -1593,7 +1594,7 @@ wd33c93_host_reset(struct scsi_cmnd * SCpnt)
 	hostdata->outgoing_len = 0;
 
 	reset_wd33c93(instance);
-	SCpnt->result = DID_RESET << 16;
+	set_host_byte(SCpnt, DID_RESET);
 	enable_irq(instance->irq);
 	spin_unlock_irq(instance->host_lock);
 	return SUCCESS;
@@ -1628,7 +1629,7 @@ wd33c93_abort(struct scsi_cmnd * cmd)
 				hostdata->input_Q =
 				    (struct scsi_cmnd *) cmd->host_scribble;
 			cmd->host_scribble = NULL;
-			cmd->result = DID_ABORT << 16;
+			set_host_byte(cmd, DID_ABORT);
 			printk
 			    ("scsi%d: Abort - removing command from input_Q. ",
 			     instance->host_no);
@@ -1702,7 +1703,7 @@ wd33c93_abort(struct scsi_cmnd * cmd)
 		hostdata->busy[cmd->device->id] &= ~(1 << (cmd->device->lun & 0xff));
 		hostdata->connected = NULL;
 		hostdata->state = S_UNCONNECTED;
-		cmd->result = DID_ABORT << 16;
+		set_host_byte(cmd, DID_ABORT);
 
 /*      sti();*/
 		wd33c93_execute(instance);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 27/42] wd33c93: translate message byte to host byte
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (25 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 26/42] wd33c93: use standard macros to set SCSI result Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 28/42] mesh: use standard macros to set SCSI result Hannes Reinecke
                   ` (16 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Instead of setting the message byte translate it to the appropriate
host byte. As error recovery would return DID_ERROR for any non-zero
message byte the translation doesn't change the error handling.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/wd33c93.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/wd33c93.c b/drivers/scsi/wd33c93.c
index 0a5bb238f001..e886e17fbf45 100644
--- a/drivers/scsi/wd33c93.c
+++ b/drivers/scsi/wd33c93.c
@@ -1168,7 +1168,6 @@ wd33c93_intr(struct Scsi_Host *instance)
 		write_wd33c93(regs, WD_SOURCE_ID, SRCID_ER);
 		if (phs == 0x60) {
 			DB(DB_INTR, printk("SX-DONE"))
-			    cmd->SCp.Message = COMMAND_COMPLETE;
 			lun = read_wd33c93(regs, WD_TARGET_LUN);
 			DB(DB_INTR, printk(":%d.%d", cmd->SCp.Status, lun))
 			    hostdata->connected = NULL;
@@ -1180,8 +1179,8 @@ wd33c93_intr(struct Scsi_Host *instance)
 			    && cmd->SCp.Status != SAM_STAT_GOOD)
 				set_host_byte(cmd, DID_ERROR);
 			else {
+				set_host_byte(cmd, DID_OK);
 				set_status_byte(cmd, cmd->SCp.Status);
-				set_msg_byte(cmd, cmd->SCp.Message);
 			}
 			cmd->scsi_done(cmd);
 
@@ -1266,8 +1265,9 @@ wd33c93_intr(struct Scsi_Host *instance)
 		    cmd->SCp.Status != SAM_STAT_GOOD)
 			set_host_byte(cmd, DID_ERROR);
 		else {
+			set_host_byte(cmd, DID_OK);
+			translate_msg_byte(cmd, cmd->SCp.Message);
 			set_status_byte(cmd, cmd->SCp.Status);
-			set_msg_byte(cmd, cmd->SCp.Message);
 		}
 		cmd->scsi_done(cmd);
 
@@ -1301,8 +1301,9 @@ wd33c93_intr(struct Scsi_Host *instance)
 				&& cmd->SCp.Status != SAM_STAT_GOOD)
 				    set_host_byte(cmd, DID_ERROR);
 			    else {
+				    set_host_byte(cmd, DID_OK);
+				    translate_msg_byte(cmd, cmd->SCp.Message);
 				    set_status_byte(cmd, cmd->SCp.Status);
-				    set_msg_byte(cmd, cmd->SCp.Message);
 			    }
 			cmd->scsi_done(cmd);
 			break;
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 28/42] mesh: use standard macros to set SCSI result
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (26 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 27/42] wd33c93: translate message byte to host byte Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 29/42] mesh: translate message to host byte status Hannes Reinecke
                   ` (15 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Use standard macros to set the SCSI result to avoid shift and mask
error.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/mesh.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/mesh.c b/drivers/scsi/mesh.c
index 0a9f4e44ab2c..6052a47b03dc 100644
--- a/drivers/scsi/mesh.c
+++ b/drivers/scsi/mesh.c
@@ -595,12 +595,13 @@ static void mesh_done(struct mesh_state *ms, int start_next)
 	ms->current_req = NULL;
 	tp->current_req = NULL;
 	if (cmd) {
-		cmd->result = (ms->stat << 16) | cmd->SCp.Status;
+		set_host_byte(cmd, ms->stat);
+		set_status_byte(cmd, cmd->SCp.Status);
 		if (ms->stat == DID_OK)
-			cmd->result |= cmd->SCp.Message << 8;
+			set_msg_byte(cmd, cmd->SCp.Message);
 		if (DEBUG_TARGET(cmd)) {
 			printk(KERN_DEBUG "mesh_done: result = %x, data_ptr=%d, buflen=%d\n",
-			       cmd->result, ms->data_ptr, scsi_bufflen(cmd));
+			       scsi_get_compat_result(cmd), ms->data_ptr, scsi_bufflen(cmd));
 #if 0
 			/* needs to use sg? */
 			if ((cmd->cmnd[0] == 0 || cmd->cmnd[0] == 0x12 || cmd->cmnd[0] == 3)
@@ -993,7 +994,7 @@ static void handle_reset(struct mesh_state *ms)
 	for (tgt = 0; tgt < 8; ++tgt) {
 		tp = &ms->tgts[tgt];
 		if ((cmd = tp->current_req) != NULL) {
-			cmd->result = DID_RESET << 16;
+			set_host_byte(cmd, DID_RESET);
 			tp->current_req = NULL;
 			mesh_completed(ms, cmd);
 		}
@@ -1003,7 +1004,7 @@ static void handle_reset(struct mesh_state *ms)
 	ms->current_req = NULL;
 	while ((cmd = ms->request_q) != NULL) {
 		ms->request_q = (struct scsi_cmnd *) cmd->host_scribble;
-		cmd->result = DID_RESET << 16;
+		set_host_byte(cmd, DID_RESET);
 		mesh_completed(ms, cmd);
 	}
 	ms->phase = idle;
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 29/42] mesh: translate message to host byte status
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (27 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 28/42] mesh: use standard macros to set SCSI result Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 30/42] acornscsi: use standard macros to set SCSI result Hannes Reinecke
                   ` (14 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Instead of setting the message byte translate it to a host byte
status. As the error recovery would map it to DID_ERROR anyway
the translation doesn't change the SCSI error handling.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/mesh.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/mesh.c b/drivers/scsi/mesh.c
index 6052a47b03dc..5be587dd75ea 100644
--- a/drivers/scsi/mesh.c
+++ b/drivers/scsi/mesh.c
@@ -597,8 +597,9 @@ static void mesh_done(struct mesh_state *ms, int start_next)
 	if (cmd) {
 		set_host_byte(cmd, ms->stat);
 		set_status_byte(cmd, cmd->SCp.Status);
-		if (ms->stat == DID_OK)
-			set_msg_byte(cmd, cmd->SCp.Message);
+		if (get_host_byte(cmd) == DID_OK &&
+		    cmd->SCp.Message != COMMAND_COMPLETE)
+			translate_msg_byte(cmd, cmd->SCp.Message);
 		if (DEBUG_TARGET(cmd)) {
 			printk(KERN_DEBUG "mesh_done: result = %x, data_ptr=%d, buflen=%d\n",
 			       scsi_get_compat_result(cmd), ms->data_ptr, scsi_bufflen(cmd));
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 30/42] acornscsi: use standard macros to set SCSI result
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (28 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 29/42] mesh: translate message to host byte status Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 31/42] acornscsi: remove acornscsi_reportstatus() Hannes Reinecke
                   ` (13 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Use standard macros to set the SCSI result to avoid shift and mask
error.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/arm/acornscsi.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/arm/acornscsi.c b/drivers/scsi/arm/acornscsi.c
index 248a5bfad153..6a49a75e94ff 100644
--- a/drivers/scsi/arm/acornscsi.c
+++ b/drivers/scsi/arm/acornscsi.c
@@ -794,7 +794,9 @@ static void acornscsi_done(AS_Host *host, struct scsi_cmnd **SCpntp,
 
 	acornscsi_dma_cleanup(host);
 
-	SCpnt->result = result << 16 | host->scsi.SCp.Message << 8 | host->scsi.SCp.Status;
+	set_host_byte(SCpnt, result);
+	set_msg_byte(SCpnt, host->scsi.SCp.Message);
+	set_status_byte(SCpnt, host->scsi.SCp.Status);
 
 	/*
 	 * In theory, this should not happen.  In practice, it seems to.
@@ -844,7 +846,8 @@ static void acornscsi_done(AS_Host *host, struct scsi_cmnd **SCpntp,
 		    default:
 			scmd_printk(KERN_ERR, SCpnt,
 				    "incomplete data transfer detected: "
-				    "result=%08X", SCpnt->result);
+				    "result=%08X",
+				    scsi_get_compat)result(SCpnt));
 			scsi_print_command(SCpnt);
 			acornscsi_dumpdma(host, "done");
 			acornscsi_dumplog(host, SCpnt->device->id);
@@ -2466,11 +2469,14 @@ static int acornscsi_queuecmd_lck(struct scsi_cmnd *SCpnt,
 	return -EINVAL;
     }
 
+    set_host_byte(SCpnt, DID_OK);
+    set_status_byte(SCpnt, SAM_STAT_GOOD);
+
 #if (DEBUG & DEBUG_NO_WRITE)
     if (acornscsi_cmdtype(SCpnt->cmnd[0]) == CMD_WRITE && (NO_WRITE & (1 << SCpnt->device->id))) {
 	printk(KERN_CRIT "scsi%d.%c: WRITE attempted with NO_WRITE flag set\n",
 	    host->host->host_no, '0' + SCpnt->device->id);
-	SCpnt->result = DID_NO_CONNECT << 16;
+	set_host_byte(SCpnt, DID_NO_CONNECT);
 	done(SCpnt);
 	return 0;
     }
@@ -2478,7 +2484,6 @@ static int acornscsi_queuecmd_lck(struct scsi_cmnd *SCpnt,
 
     SCpnt->scsi_done = done;
     SCpnt->host_scribble = NULL;
-    SCpnt->result = 0;
     SCpnt->tag = 0;
     SCpnt->SCp.phase = (int)acornscsi_datadirection(SCpnt->cmnd[0]);
     SCpnt->SCp.sent_command = 0;
@@ -2492,7 +2497,7 @@ static int acornscsi_queuecmd_lck(struct scsi_cmnd *SCpnt,
 	unsigned long flags;
 
 	if (!queue_add_cmd_ordered(&host->queues.issue, SCpnt)) {
-	    SCpnt->result = DID_ERROR << 16;
+		set_host_byte(SCpnt, DID_ERROR);
 	    done(SCpnt);
 	    return 0;
 	}
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 31/42] acornscsi: remove acornscsi_reportstatus()
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (29 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 30/42] acornscsi: use standard macros to set SCSI result Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 32/42] acornscsi: translate message byte to host byte Hannes Reinecke
                   ` (12 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Unused.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/arm/acornscsi.c | 25 -------------------------
 1 file changed, 25 deletions(-)

diff --git a/drivers/scsi/arm/acornscsi.c b/drivers/scsi/arm/acornscsi.c
index 6a49a75e94ff..17590b1053a8 100644
--- a/drivers/scsi/arm/acornscsi.c
+++ b/drivers/scsi/arm/acornscsi.c
@@ -2511,31 +2511,6 @@ static int acornscsi_queuecmd_lck(struct scsi_cmnd *SCpnt,
 
 DEF_SCSI_QCMD(acornscsi_queuecmd)
 
-/*
- * Prototype: void acornscsi_reportstatus(struct scsi_cmnd **SCpntp1, struct scsi_cmnd **SCpntp2, int result)
- * Purpose  : pass a result to *SCpntp1, and check if *SCpntp1 = *SCpntp2
- * Params   : SCpntp1 - pointer to command to return
- *	      SCpntp2 - pointer to command to check
- *	      result  - result to pass back to mid-level done function
- * Returns  : *SCpntp2 = NULL if *SCpntp1 is the same command structure as *SCpntp2.
- */
-static inline void acornscsi_reportstatus(struct scsi_cmnd **SCpntp1,
-					  struct scsi_cmnd **SCpntp2,
-					  int result)
-{
-	struct scsi_cmnd *SCpnt = *SCpntp1;
-
-    if (SCpnt) {
-	*SCpntp1 = NULL;
-
-	SCpnt->result = result;
-	SCpnt->scsi_done(SCpnt);
-    }
-
-    if (SCpnt == *SCpntp2)
-	*SCpntp2 = NULL;
-}
-
 enum res_abort { res_not_running, res_success, res_success_clear, res_snooze };
 
 /*
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 32/42] acornscsi: translate message byte to host byte
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (30 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 31/42] acornscsi: remove acornscsi_reportstatus() Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 33/42] aha152x: modify done() to use separate status bytes Hannes Reinecke
                   ` (11 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Instead of setting the message byte translate it to the appropriate
host byte. As error recovery would return DID_ERROR for any non-zero
message byte the translation doesn't change the error handling.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/arm/acornscsi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/arm/acornscsi.c b/drivers/scsi/arm/acornscsi.c
index 17590b1053a8..784d18077752 100644
--- a/drivers/scsi/arm/acornscsi.c
+++ b/drivers/scsi/arm/acornscsi.c
@@ -795,7 +795,8 @@ static void acornscsi_done(AS_Host *host, struct scsi_cmnd **SCpntp,
 	acornscsi_dma_cleanup(host);
 
 	set_host_byte(SCpnt, result);
-	set_msg_byte(SCpnt, host->scsi.SCp.Message);
+	if (result != DID_OK)
+		translate_msg_byte(SCpnt, host->scsi.SCp.Message);
 	set_status_byte(SCpnt, host->scsi.SCp.Status);
 
 	/*
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 33/42] aha152x: modify done() to use separate status bytes
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (31 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 32/42] acornscsi: translate message byte to host byte Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 34/42] aha152x: do not set message byte when calling scsi_done() Hannes Reinecke
                   ` (10 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Instead of passing in the combined SCSI result value split them
off into separate status, message, and host byte values.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/aha152x.c | 43 ++++++++++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 14 deletions(-)

diff --git a/drivers/scsi/aha152x.c b/drivers/scsi/aha152x.c
index d8e19afa7a14..f59d11f8080a 100644
--- a/drivers/scsi/aha152x.c
+++ b/drivers/scsi/aha152x.c
@@ -619,7 +619,8 @@ static struct {
 static irqreturn_t intr(int irq, void *dev_id);
 static void reset_ports(struct Scsi_Host *shpnt);
 static void aha152x_error(struct Scsi_Host *shpnt, char *msg);
-static void done(struct Scsi_Host *shpnt, int error);
+static void done(struct Scsi_Host *shpnt, unsigned char status_byte,
+		 unsigned char msg_byte, unsigned char host_byte);
 
 /* diagnostics */
 static void show_command(struct scsi_cmnd * ptr);
@@ -1271,7 +1272,8 @@ static int aha152x_biosparam(struct scsi_device *sdev, struct block_device *bdev
  *  Internal done function
  *
  */
-static void done(struct Scsi_Host *shpnt, int error)
+static void done(struct Scsi_Host *shpnt, unsigned char status_byte,
+		 unsigned char msg_byte, unsigned char host_byte)
 {
 	if (CURRENT_SC) {
 		if(DONE_SC)
@@ -1281,7 +1283,9 @@ static void done(struct Scsi_Host *shpnt, int error)
 
 		DONE_SC = CURRENT_SC;
 		CURRENT_SC = NULL;
-		DONE_SC->result = error;
+		DONE_SC->result = status_byte;
+		set_msg_byte(DONE_SC, msg_byte);
+		set_host_byte(DONE_SC, host_byte);
 	} else
 		printk(KERN_ERR "aha152x: done() called outside of command\n");
 }
@@ -1376,13 +1380,16 @@ static void busfree_run(struct Scsi_Host *shpnt)
 
 		if(CURRENT_SC->SCp.phase & completed) {
 			/* target sent COMMAND COMPLETE */
-			done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_OK << 16));
+			done(shpnt, CURRENT_SC->SCp.Status,
+			     CURRENT_SC->SCp.Message, DID_OK);
 
 		} else if(CURRENT_SC->SCp.phase & aborted) {
-			done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_ABORT << 16));
+			done(shpnt, CURRENT_SC->SCp.Status,
+			     CURRENT_SC->SCp.Message, DID_ABORT);
 
 		} else if(CURRENT_SC->SCp.phase & resetted) {
-			done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_RESET << 16));
+			done(shpnt, CURRENT_SC->SCp.Status,
+			     CURRENT_SC->SCp.Message, DID_RESET);
 
 		} else if(CURRENT_SC->SCp.phase & disconnected) {
 			/* target sent DISCONNECT */
@@ -1394,7 +1401,8 @@ static void busfree_run(struct Scsi_Host *shpnt)
 			CURRENT_SC = NULL;
 
 		} else {
-			done(shpnt, DID_ERROR << 16);
+			done(shpnt, SAM_STAT_GOOD,
+			     COMMAND_COMPLETE, DID_ERROR);
 		}
 #if defined(AHA152X_STAT)
 	} else {
@@ -1515,7 +1523,8 @@ static void seldo_run(struct Scsi_Host *shpnt)
 	if (TESTLO(SSTAT0, SELDO)) {
 		scmd_printk(KERN_ERR, CURRENT_SC,
 			    "aha152x: passing bus free condition\n");
-		done(shpnt, DID_NO_CONNECT << 16);
+		done(shpnt, SAM_STAT_GOOD,
+		     COMMAND_COMPLETE, DID_NO_CONNECT);
 		return;
 	}
 
@@ -1552,12 +1561,15 @@ static void selto_run(struct Scsi_Host *shpnt)
 	CURRENT_SC->SCp.phase &= ~selecting;
 
 	if (CURRENT_SC->SCp.phase & aborted)
-		done(shpnt, DID_ABORT << 16);
+		done(shpnt, SAM_STAT_GOOD,
+		     COMMAND_COMPLETE, DID_ABORT);
 	else if (TESTLO(SSTAT0, SELINGO))
-		done(shpnt, DID_BUS_BUSY << 16);
+		done(shpnt, SAM_STAT_GOOD,
+		     COMMAND_COMPLETE, DID_BUS_BUSY);
 	else
 		/* ARBITRATION won, but SELECTION failed */
-		done(shpnt, DID_NO_CONNECT << 16);
+		done(shpnt, SAM_STAT_GOOD,
+		     COMMAND_COMPLETE, DID_NO_CONNECT);
 }
 
 /*
@@ -1891,7 +1903,8 @@ static void cmd_init(struct Scsi_Host *shpnt)
 	if (CURRENT_SC->SCp.sent_command) {
 		scmd_printk(KERN_ERR, CURRENT_SC,
 			    "command already sent\n");
-		done(shpnt, DID_ERROR << 16);
+		done(shpnt, SAM_STAT_GOOD,
+		     COMMAND_COMPLETE, DID_ERROR);
 		return;
 	}
 
@@ -2231,7 +2244,8 @@ static int update_state(struct Scsi_Host *shpnt)
 static void parerr_run(struct Scsi_Host *shpnt)
 {
 	scmd_printk(KERN_ERR, CURRENT_SC, "parity error\n");
-	done(shpnt, DID_PARITY << 16);
+	done(shpnt, SAM_STAT_GOOD,
+	     COMMAND_COMPLETE, DID_PARITY);
 }
 
 /*
@@ -2262,7 +2276,8 @@ static void rsti_run(struct Scsi_Host *shpnt)
 	}
 
 	if(CURRENT_SC && !CURRENT_SC->device->soft_reset)
-		done(shpnt, DID_RESET << 16 );
+		done(shpnt, SAM_STAT_GOOD,
+		     COMMAND_COMPLETE, DID_RESET);
 }
 
 
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 34/42] aha152x: do not set message byte when calling scsi_done()
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (32 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 33/42] aha152x: modify done() to use separate status bytes Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 35/42] advansys: do not set message byte in SCSI status Hannes Reinecke
                   ` (9 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

The done() function is called with a host_byte indicating the
actual error when the message byte is set. As the host byte takes
precedence during error recovery we can drop setting the message
byte if the host byte is set, too.
The only other case is when the host byte is DID_OK, but in that case
the message byte is always COMMAND_COMPLETE (ie 0), so we can drop
it there, too.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/aha152x.c | 42 +++++++++++++++---------------------------
 1 file changed, 15 insertions(+), 27 deletions(-)

diff --git a/drivers/scsi/aha152x.c b/drivers/scsi/aha152x.c
index f59d11f8080a..b13b5c85f3de 100644
--- a/drivers/scsi/aha152x.c
+++ b/drivers/scsi/aha152x.c
@@ -620,7 +620,7 @@ static irqreturn_t intr(int irq, void *dev_id);
 static void reset_ports(struct Scsi_Host *shpnt);
 static void aha152x_error(struct Scsi_Host *shpnt, char *msg);
 static void done(struct Scsi_Host *shpnt, unsigned char status_byte,
-		 unsigned char msg_byte, unsigned char host_byte);
+		 unsigned char host_byte);
 
 /* diagnostics */
 static void show_command(struct scsi_cmnd * ptr);
@@ -1273,7 +1273,7 @@ static int aha152x_biosparam(struct scsi_device *sdev, struct block_device *bdev
  *
  */
 static void done(struct Scsi_Host *shpnt, unsigned char status_byte,
-		 unsigned char msg_byte, unsigned char host_byte)
+		 unsigned char host_byte)
 {
 	if (CURRENT_SC) {
 		if(DONE_SC)
@@ -1283,8 +1283,7 @@ static void done(struct Scsi_Host *shpnt, unsigned char status_byte,
 
 		DONE_SC = CURRENT_SC;
 		CURRENT_SC = NULL;
-		DONE_SC->result = status_byte;
-		set_msg_byte(DONE_SC, msg_byte);
+		set_status_byte(DONE_SC, status_byte);
 		set_host_byte(DONE_SC, host_byte);
 	} else
 		printk(KERN_ERR "aha152x: done() called outside of command\n");
@@ -1380,16 +1379,13 @@ static void busfree_run(struct Scsi_Host *shpnt)
 
 		if(CURRENT_SC->SCp.phase & completed) {
 			/* target sent COMMAND COMPLETE */
-			done(shpnt, CURRENT_SC->SCp.Status,
-			     CURRENT_SC->SCp.Message, DID_OK);
+			done(shpnt, CURRENT_SC->SCp.Status, DID_OK);
 
 		} else if(CURRENT_SC->SCp.phase & aborted) {
-			done(shpnt, CURRENT_SC->SCp.Status,
-			     CURRENT_SC->SCp.Message, DID_ABORT);
+			done(shpnt, CURRENT_SC->SCp.Status, DID_ABORT);
 
 		} else if(CURRENT_SC->SCp.phase & resetted) {
-			done(shpnt, CURRENT_SC->SCp.Status,
-			     CURRENT_SC->SCp.Message, DID_RESET);
+			done(shpnt, CURRENT_SC->SCp.Status, DID_RESET);
 
 		} else if(CURRENT_SC->SCp.phase & disconnected) {
 			/* target sent DISCONNECT */
@@ -1401,8 +1397,7 @@ static void busfree_run(struct Scsi_Host *shpnt)
 			CURRENT_SC = NULL;
 
 		} else {
-			done(shpnt, SAM_STAT_GOOD,
-			     COMMAND_COMPLETE, DID_ERROR);
+			done(shpnt, SAM_STAT_GOOD, DID_ERROR);
 		}
 #if defined(AHA152X_STAT)
 	} else {
@@ -1523,8 +1518,7 @@ static void seldo_run(struct Scsi_Host *shpnt)
 	if (TESTLO(SSTAT0, SELDO)) {
 		scmd_printk(KERN_ERR, CURRENT_SC,
 			    "aha152x: passing bus free condition\n");
-		done(shpnt, SAM_STAT_GOOD,
-		     COMMAND_COMPLETE, DID_NO_CONNECT);
+		done(shpnt, SAM_STAT_GOOD, DID_NO_CONNECT);
 		return;
 	}
 
@@ -1561,15 +1555,12 @@ static void selto_run(struct Scsi_Host *shpnt)
 	CURRENT_SC->SCp.phase &= ~selecting;
 
 	if (CURRENT_SC->SCp.phase & aborted)
-		done(shpnt, SAM_STAT_GOOD,
-		     COMMAND_COMPLETE, DID_ABORT);
+		done(shpnt, SAM_STAT_GOOD, DID_ABORT);
 	else if (TESTLO(SSTAT0, SELINGO))
-		done(shpnt, SAM_STAT_GOOD,
-		     COMMAND_COMPLETE, DID_BUS_BUSY);
+		done(shpnt, SAM_STAT_GOOD, DID_BUS_BUSY);
 	else
 		/* ARBITRATION won, but SELECTION failed */
-		done(shpnt, SAM_STAT_GOOD,
-		     COMMAND_COMPLETE, DID_NO_CONNECT);
+		done(shpnt, SAM_STAT_GOOD, DID_NO_CONNECT);
 }
 
 /*
@@ -1903,8 +1894,7 @@ static void cmd_init(struct Scsi_Host *shpnt)
 	if (CURRENT_SC->SCp.sent_command) {
 		scmd_printk(KERN_ERR, CURRENT_SC,
 			    "command already sent\n");
-		done(shpnt, SAM_STAT_GOOD,
-		     COMMAND_COMPLETE, DID_ERROR);
+		done(shpnt, SAM_STAT_GOOD, DID_ERROR);
 		return;
 	}
 
@@ -2244,8 +2234,7 @@ static int update_state(struct Scsi_Host *shpnt)
 static void parerr_run(struct Scsi_Host *shpnt)
 {
 	scmd_printk(KERN_ERR, CURRENT_SC, "parity error\n");
-	done(shpnt, SAM_STAT_GOOD,
-	     COMMAND_COMPLETE, DID_PARITY);
+	done(shpnt, SAM_STAT_GOOD, DID_PARITY);
 }
 
 /*
@@ -2268,7 +2257,7 @@ static void rsti_run(struct Scsi_Host *shpnt)
 			kfree(ptr->host_scribble);
 			ptr->host_scribble=NULL;
 
-			ptr->result =  DID_RESET << 16;
+			set_host_byte(ptr, DID_RESET);
 			ptr->scsi_done(ptr);
 		}
 
@@ -2276,8 +2265,7 @@ static void rsti_run(struct Scsi_Host *shpnt)
 	}
 
 	if(CURRENT_SC && !CURRENT_SC->device->soft_reset)
-		done(shpnt, SAM_STAT_GOOD,
-		     COMMAND_COMPLETE, DID_RESET);
+		done(shpnt, SAM_STAT_GOOD, DID_RESET);
 }
 
 
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 35/42] advansys: do not set message byte in SCSI status
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (33 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 34/42] aha152x: do not set message byte when calling scsi_done() Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 36/42] advansys: use SCSI result accessors Hannes Reinecke
                   ` (8 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

The host byte in the SCSI status takes precedence during error recovery,
so there is no point in setting the message byte in addition to a host byte
which is not DID_OK.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/advansys.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c
index 77c99fe11c81..28748df36c2f 100644
--- a/drivers/scsi/advansys.c
+++ b/drivers/scsi/advansys.c
@@ -6773,14 +6773,12 @@ static void asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep)
 	case QD_ABORTED_BY_HOST:
 		ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
 		set_status_byte(scp, qdonep->d3.scsi_stat);
-		set_msg_byte(scp, qdonep->d3.scsi_msg);
 		set_host_byte(scp, DID_ABORT);
 		break;
 
 	default:
 		ASC_DBG(1, "done_stat 0x%x\n", qdonep->d3.done_stat);
 		set_status_byte(scp, qdonep->d3.scsi_stat);
-		set_msg_byte(scp, qdonep->d3.scsi_msg);
 		set_host_byte(scp, DID_ERROR);
 		break;
 	}
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 36/42] advansys: use SCSI result accessors
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (34 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 35/42] advansys: do not set message byte in SCSI status Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 37/42] fas216: translate message to host byte status Hannes Reinecke
                   ` (7 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Convert the driver to use SCSI result accessors.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/advansys.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c
index 28748df36c2f..df6add4a2724 100644
--- a/drivers/scsi/advansys.c
+++ b/drivers/scsi/advansys.c
@@ -5980,7 +5980,8 @@ static void adv_isr_callback(ADV_DVC_VAR *adv_dvc_varp, ADV_SCSI_REQ_Q *scsiqp)
 	/*
 	 * 'done_status' contains the command's ending status.
 	 */
-	scp->result = 0;
+	set_host_byte(scp, DID_OK);
+	set_status_byte(scp, SAM_STAT_GOOD);
 	switch (scsiqp->done_status) {
 	case QD_NO_ERROR:
 		ASC_DBG(2, "QD_NO_ERROR\n");
@@ -6731,7 +6732,8 @@ static void asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep)
 	/*
 	 * 'qdonep' contains the command's ending status.
 	 */
-	scp->result = 0;
+	set_host_byte(scp, DID_OK);
+	set_status_byte(scp, SAM_STAT_GOOD);
 	switch (qdonep->d3.done_stat) {
 	case QD_NO_ERROR:
 		ASC_DBG(2, "QD_NO_ERROR\n");
@@ -6760,6 +6762,7 @@ static void asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep)
 				ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
 						  SCSI_SENSE_BUFFERSIZE);
 			}
+			set_status_byte(scp, qdonep->d3.scsi_stat);
 			break;
 
 		default:
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 37/42] fas216: translate message to host byte status
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (35 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 36/42] advansys: use SCSI result accessors Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 38/42] fas216: convert to SCSI Accessors Hannes Reinecke
                   ` (6 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Instead of setting the message byte translate it to the appropriate
host byte. As error recovery would return DID_ERROR for any non-zero
message byte the translation doesn't change the error handling.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/arm/fas216.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/arm/fas216.c b/drivers/scsi/arm/fas216.c
index 2e687ce60753..659bcfe5e2e6 100644
--- a/drivers/scsi/arm/fas216.c
+++ b/drivers/scsi/arm/fas216.c
@@ -2042,8 +2042,10 @@ fas216_std_done(FAS216_Info *info, struct scsi_cmnd *SCpnt, unsigned int result)
 {
 	info->stats.fins += 1;
 
-	SCpnt->result = result << 16 | info->scsi.SCp.Message << 8 |
-			info->scsi.SCp.Status;
+	set_host_byte(SCpnt, result);
+	if (get_host_byte(SCpnt) == DID_OK)
+		translate_msg_byte(SCpnt, info->scsi.SCp.Message);
+	set_status_byte(SCpnt, info->scsi.SCp.Status);
 
 	fas216_log_command(info, LOG_CONNECT, SCpnt,
 		"command complete, result=0x%08x", SCpnt->result);
@@ -2051,8 +2053,7 @@ fas216_std_done(FAS216_Info *info, struct scsi_cmnd *SCpnt, unsigned int result)
 	/*
 	 * If the driver detected an error, we're all done.
 	 */
-	if (host_byte(SCpnt->result) != DID_OK ||
-	    msg_byte(SCpnt->result) != COMMAND_COMPLETE)
+	if (host_byte(SCpnt->result) != DID_OK)
 		goto done;
 
 	/*
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 38/42] fas216: convert to SCSI Accessors
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (36 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 37/42] fas216: translate message to host byte status Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 39/42] fdomain: drop last argument to fdomain_finish_cmd() Hannes Reinecke
                   ` (5 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Use SCSI accessors to avoid referencing result field.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/arm/fas216.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/arm/fas216.c b/drivers/scsi/arm/fas216.c
index 659bcfe5e2e6..0be5366bc38f 100644
--- a/drivers/scsi/arm/fas216.c
+++ b/drivers/scsi/arm/fas216.c
@@ -2048,27 +2048,28 @@ fas216_std_done(FAS216_Info *info, struct scsi_cmnd *SCpnt, unsigned int result)
 	set_status_byte(SCpnt, info->scsi.SCp.Status);
 
 	fas216_log_command(info, LOG_CONNECT, SCpnt,
-		"command complete, result=0x%08x", SCpnt->result);
+		"command complete, result=0x%08x",
+		scsi_get_compat_result(SCpnt));
 
 	/*
 	 * If the driver detected an error, we're all done.
 	 */
-	if (host_byte(SCpnt->result) != DID_OK)
+	if (get_host_byte(SCpnt) != DID_OK)
 		goto done;
 
 	/*
 	 * If the command returned CHECK_CONDITION or COMMAND_TERMINATED
 	 * status, request the sense information.
 	 */
-	if (status_byte(SCpnt->result) == CHECK_CONDITION ||
-	    status_byte(SCpnt->result) == COMMAND_TERMINATED)
+	if (get_status_byte(SCpnt) == SAM_STAT_CHECK_CONDITION ||
+	    get_status_byte(SCpnt) == SAM_STAT_COMMAND_TERMINATED)
 		goto request_sense;
 
 	/*
 	 * If the command did not complete with GOOD status,
 	 * we are all done here.
 	 */
-	if (status_byte(SCpnt->result) != GOOD)
+	if (get_status_byte(SCpnt) != GOOD)
 		goto done;
 
 	/*
@@ -2088,7 +2089,8 @@ fas216_std_done(FAS216_Info *info, struct scsi_cmnd *SCpnt, unsigned int result)
 		default:
 			scmd_printk(KERN_ERR, SCpnt,
 				    "incomplete data transfer detected: res=%08X ptr=%p len=%X\n",
-				    SCpnt->result, info->scsi.SCp.ptr,
+				    scsi_get_compat_result(SCpnt),
+				    info->scsi.SCp.ptr,
 				    info->scsi.SCp.this_residual);
 			scsi_print_command(SCpnt);
 			set_host_byte(SCpnt, DID_ERROR);
@@ -2217,7 +2219,8 @@ static int fas216_queue_command_lck(struct scsi_cmnd *SCpnt,
 
 	SCpnt->scsi_done = done;
 	SCpnt->host_scribble = (void *)fas216_std_done;
-	SCpnt->result = 0;
+	set_host_byte(SCpnt, DID_OK);
+	set_status_byte(SCpnt, SAM_STAT_GOOD);
 
 	init_SCp(SCpnt);
 
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 39/42] fdomain: drop last argument to fdomain_finish_cmd()
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (37 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 38/42] fas216: convert to SCSI Accessors Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 40/42] fdomain: translate message to host byte status Hannes Reinecke
                   ` (4 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Set the SCSI host status before calling fdomein_finish_cmd(),
and drop the last argument to that function.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/fdomain.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/drivers/scsi/fdomain.c b/drivers/scsi/fdomain.c
index 772bdc93930a..294dbfa5c761 100644
--- a/drivers/scsi/fdomain.c
+++ b/drivers/scsi/fdomain.c
@@ -202,11 +202,10 @@ static int fdomain_select(struct Scsi_Host *sh, int target)
 	return 1;
 }
 
-static void fdomain_finish_cmd(struct fdomain *fd, int result)
+static void fdomain_finish_cmd(struct fdomain *fd)
 {
 	outb(0, fd->base + REG_ICTL);
 	fdomain_make_bus_idle(fd);
-	fd->cur_cmd->result = result;
 	fd->cur_cmd->scsi_done(fd->cur_cmd);
 	fd->cur_cmd = NULL;
 }
@@ -273,7 +272,8 @@ static void fdomain_work(struct work_struct *work)
 	if (cmd->SCp.phase & in_arbitration) {
 		status = inb(fd->base + REG_ASTAT);
 		if (!(status & ASTAT_ARB)) {
-			fdomain_finish_cmd(fd, DID_BUS_BUSY << 16);
+			set_host_byte(cmd, DID_BUS_BUSY);
+			fdomain_finish_cmd(fd);
 			goto out;
 		}
 		cmd->SCp.phase = in_selection;
@@ -290,7 +290,8 @@ static void fdomain_work(struct work_struct *work)
 		if (!(status & BSTAT_BSY)) {
 			/* Try again, for slow devices */
 			if (fdomain_select(cmd->device->host, scmd_id(cmd))) {
-				fdomain_finish_cmd(fd, DID_NO_CONNECT << 16);
+				set_host_byte(cmd, DID_NO_CONNECT);
+				fdomain_finish_cmd(fd);
 				goto out;
 			}
 			/* Stop arbitration and enable parity */
@@ -333,7 +334,7 @@ static void fdomain_work(struct work_struct *work)
 			break;
 		case BSTAT_MSG | BSTAT_CMD | BSTAT_IO:	/* MESSAGE IN */
 			cmd->SCp.Message = inb(fd->base + REG_SCSI_DATA);
-			if (!cmd->SCp.Message)
+			if (cmd->SCp.Message == COMMAND_COMPLETE)
 				++done;
 			break;
 		}
@@ -359,9 +360,10 @@ static void fdomain_work(struct work_struct *work)
 		fdomain_read_data(cmd);
 
 	if (done) {
-		fdomain_finish_cmd(fd, (cmd->SCp.Status & 0xff) |
-				   ((cmd->SCp.Message & 0xff) << 8) |
-				   (DID_OK << 16));
+		set_status_byte(cmd, cmd->SCp.Status);
+		set_msg_byte(cmd, cmd->SCp.Message);
+		set_host_byte(cmd, DID_OK);
+		fdomain_finish_cmd(fd);
 	} else {
 		if (cmd->SCp.phase & disconnect) {
 			outb(ICTL_FIFO | ICTL_SEL | ICTL_REQ | FIFO_COUNT,
@@ -439,10 +441,10 @@ static int fdomain_abort(struct scsi_cmnd *cmd)
 
 	fdomain_make_bus_idle(fd);
 	fd->cur_cmd->SCp.phase |= aborted;
-	fd->cur_cmd->result = DID_ABORT << 16;
 
 	/* Aborts are not done well. . . */
-	fdomain_finish_cmd(fd, DID_ABORT << 16);
+	set_host_byte(fd->cur_cmd, DID_ABORT);
+	fdomain_finish_cmd(fd);
 	spin_unlock_irqrestore(sh->host_lock, flags);
 	return SUCCESS;
 }
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 40/42] fdomain: translate message to host byte status
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (38 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 39/42] fdomain: drop last argument to fdomain_finish_cmd() Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 17:47 ` [PATCH 41/42] scsi: drop message byte helper Hannes Reinecke
                   ` (3 subsequent siblings)
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Instead of setting the message byte translate it to the appropriate
host byte. As error recovery would return DID_ERROR for any non-zero
message byte the translation doesn't change the error handling.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/fdomain.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/fdomain.c b/drivers/scsi/fdomain.c
index 294dbfa5c761..2b946cb02693 100644
--- a/drivers/scsi/fdomain.c
+++ b/drivers/scsi/fdomain.c
@@ -361,8 +361,8 @@ static void fdomain_work(struct work_struct *work)
 
 	if (done) {
 		set_status_byte(cmd, cmd->SCp.Status);
-		set_msg_byte(cmd, cmd->SCp.Message);
 		set_host_byte(cmd, DID_OK);
+		translate_msg_byte(cmd, cmd->SCp. Message);
 		fdomain_finish_cmd(fd);
 	} else {
 		if (cmd->SCp.phase & disconnect) {
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 41/42] scsi: drop message byte helper
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (39 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 40/42] fdomain: translate message to host byte status Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 21:14   ` Bart Van Assche
  2021-04-21 17:47 ` [PATCH 42/42] scsi: kill message byte Hannes Reinecke
                   ` (2 subsequent siblings)
  43 siblings, 1 reply; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

The message byte is not unused, so we can drop the helper to set
the message byte and the check for message bytes during error recovery.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 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(-)

diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index ab2579467316..f2159f18626b 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;
 	hdr->info = 0;
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 4d0b3353da54..8eb7abcbf8d1 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 9122d05563d0..658a3538d69b 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 8efeddd96367..68d02f50bb2c 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 5ed1c256ea94..253e0dcd9a17 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -195,11 +195,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 a0458f0dba14..2ac7f7fe4c50 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -321,11 +321,6 @@ static inline unsigned char 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);
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* [PATCH 42/42] scsi: kill message byte
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (40 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 41/42] scsi: drop message byte helper Hannes Reinecke
@ 2021-04-21 17:47 ` Hannes Reinecke
  2021-04-21 20:54 ` [RFC PATCH 00/42] SCSI result cleanup, part 2 Bart Van Assche
  2021-04-21 22:26 ` Bart Van Assche
  43 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 17:47 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi,
	Hannes Reinecke

Remove last vestigies of SCSI status message bytes.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 Documentation/scsi/scsi_mid_low_api.rst |  6 ++---
 include/trace/events/scsi.h             | 33 +------------------------
 2 files changed, 4 insertions(+), 35 deletions(-)

diff --git a/Documentation/scsi/scsi_mid_low_api.rst b/Documentation/scsi/scsi_mid_low_api.rst
index 2c87eaa36296..8728204e2b76 100644
--- a/Documentation/scsi/scsi_mid_low_api.rst
+++ b/Documentation/scsi/scsi_mid_low_api.rst
@@ -1176,9 +1176,9 @@ Members of interest:
                    of 0 implies a successfully completed command (and all
                    data (if any) has been transferred to or from the SCSI
                    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() and host_byte() macros and related constants.
+                   can be viewed as 2 related bytes. The SCSI status value is
+                   in the LSB. See include/scsi/scsi.h status_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/include/trace/events/scsi.h b/include/trace/events/scsi.h
index 428cca71c2ba..370ade0d4093 100644
--- a/include/trace/events/scsi.h
+++ b/include/trace/events/scsi.h
@@ -124,37 +124,6 @@
 		scsi_hostbyte_name(DID_TRANSPORT_DISRUPTED),	\
 		scsi_hostbyte_name(DID_TRANSPORT_FAILFAST))
 
-#define scsi_msgbyte_name(result)	{ result, #result }
-#define show_msgbyte_name(val)					\
-	__print_symbolic(val,					\
-		scsi_msgbyte_name(COMMAND_COMPLETE),		\
-		scsi_msgbyte_name(EXTENDED_MESSAGE),		\
-		scsi_msgbyte_name(SAVE_POINTERS),		\
-		scsi_msgbyte_name(RESTORE_POINTERS),		\
-		scsi_msgbyte_name(DISCONNECT),			\
-		scsi_msgbyte_name(INITIATOR_ERROR),		\
-		scsi_msgbyte_name(ABORT_TASK_SET),		\
-		scsi_msgbyte_name(MESSAGE_REJECT),		\
-		scsi_msgbyte_name(NOP),				\
-		scsi_msgbyte_name(MSG_PARITY_ERROR),		\
-		scsi_msgbyte_name(LINKED_CMD_COMPLETE),		\
-		scsi_msgbyte_name(LINKED_FLG_CMD_COMPLETE),	\
-		scsi_msgbyte_name(TARGET_RESET),		\
-		scsi_msgbyte_name(ABORT_TASK),			\
-		scsi_msgbyte_name(CLEAR_TASK_SET),		\
-		scsi_msgbyte_name(INITIATE_RECOVERY),		\
-		scsi_msgbyte_name(RELEASE_RECOVERY),		\
-		scsi_msgbyte_name(CLEAR_ACA),			\
-		scsi_msgbyte_name(LOGICAL_UNIT_RESET),		\
-		scsi_msgbyte_name(SIMPLE_QUEUE_TAG),		\
-		scsi_msgbyte_name(HEAD_OF_QUEUE_TAG),		\
-		scsi_msgbyte_name(ORDERED_QUEUE_TAG),		\
-		scsi_msgbyte_name(IGNORE_WIDE_RESIDUE),		\
-		scsi_msgbyte_name(ACA),				\
-		scsi_msgbyte_name(QAS_REQUEST),			\
-		scsi_msgbyte_name(BUS_DEVICE_RESET),		\
-		scsi_msgbyte_name(ABORT))
-
 #define scsi_statusbyte_name(result)	{ result, #result }
 #define show_statusbyte_name(val)				\
 	__print_symbolic(val,					\
@@ -316,7 +285,7 @@ DECLARE_EVENT_CLASS(scsi_cmd_done_timeout_template,
 		  __print_hex(__get_dynamic_array(cmnd), __entry->cmd_len),
 		  "DRIVER_OK",
 		  show_hostbyte_name(((__entry->result) >> 16) & 0xff),
-		  show_msgbyte_name(((__entry->result) >> 8) & 0xff),
+		  "COMMAND_COMPLETE",
 		  show_statusbyte_name(__entry->result & 0xff))
 );
 
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 80+ messages in thread

* Re: [PATCH 07/42] scsi: Kill DRIVER_SENSE
  2021-04-21 17:47 ` [PATCH 07/42] scsi: Kill DRIVER_SENSE Hannes Reinecke
@ 2021-04-21 19:46   ` Douglas Gilbert
  2021-04-21 20:07     ` Hannes Reinecke
  2021-04-21 21:06   ` Bart Van Assche
  1 sibling, 1 reply; 80+ messages in thread
From: Douglas Gilbert @ 2021-04-21 19:46 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi

On 2021-04-21 1:47 p.m., Hannes Reinecke wrote:
> Replace the check for DRIVER_SENSE with a check for
> SAM_STAT_CHECK_CONDITION and audit all callsites to
> ensure the SAM status is set correctly.
> For backwards compability move the DRIVER_SENSE definition
> to sg.h, and update the sg driver to set the DRIVER_SENSE
> driver_status whenever SAM_STAT_CHECK_CONDITION is present.

I may have missed it but you probably want to do the same
backwards compatibility DRIVER_SENSE trick for the
ioctl(SG_IO) implemented in block/scsi_ioctl.c . That way
DRIVER_SENSE will appear in the sg_io_hdr::driver_status byte
when check_condition_sense are set for both these cases:
     ioctl(sd_fd, SG_IO, &a_sg_v3_obj)
     ioctl(sg_fd, SG_IO, &a_sg_v3_obj)

And for bsg which uses sg_io_v4 for SCSI commands you set
sg_io_v4::driver_status = 0
in all cases. If check_condition and sense are active, why
not set DRIVER_SENSE for consistency. block/scsi_ioctl.c
includes scsi/sg.h so the DRIVER_SENSE define is visble.

Doug Gilbert

> Signed-off-by: Hannes Reinecke <hare@suse.de>
> ---
>   drivers/ata/libata-scsi.c                   | 13 ++------
>   drivers/scsi/NCR5380.c                      |  2 +-
>   drivers/scsi/advansys.c                     |  2 --
>   drivers/scsi/aic7xxx/aic79xx_osm.c          | 19 +++++-------
>   drivers/scsi/aic7xxx/aic7xxx_osm.c          |  1 -
>   drivers/scsi/arcmsr/arcmsr_hba.c            |  1 -
>   drivers/scsi/ch.c                           |  2 +-
>   drivers/scsi/cxlflash/superpipe.c           |  3 +-
>   drivers/scsi/dc395x.c                       | 13 ++------
>   drivers/scsi/esp_scsi.c                     |  4 +--
>   drivers/scsi/megaraid.c                     | 10 +++---
>   drivers/scsi/megaraid/megaraid_mbox.c       |  8 ++---
>   drivers/scsi/megaraid/megaraid_sas_base.c   |  2 --
>   drivers/scsi/megaraid/megaraid_sas_fusion.c |  1 -
>   drivers/scsi/mvumi.c                        |  1 -
>   drivers/scsi/scsi.c                         |  7 -----
>   drivers/scsi/scsi_debug.c                   |  4 +--
>   drivers/scsi/scsi_ioctl.c                   |  3 +-
>   drivers/scsi/scsi_lib.c                     |  9 ++----
>   drivers/scsi/scsi_scan.c                    |  2 +-
>   drivers/scsi/scsi_transport_spi.c           |  2 +-
>   drivers/scsi/sd.c                           | 34 +++++++++++----------
>   drivers/scsi/sd_zbc.c                       |  3 +-
>   drivers/scsi/sg.c                           |  9 ++++--
>   drivers/scsi/stex.c                         |  4 +--
>   drivers/scsi/sym53c8xx_2/sym_glue.c         |  6 ++--
>   drivers/scsi/ufs/ufshcd.c                   |  2 +-
>   drivers/scsi/virtio_scsi.c                  |  3 +-
>   drivers/scsi/vmw_pvscsi.c                   |  3 --
>   drivers/target/loopback/tcm_loop.c          |  1 -
>   drivers/usb/storage/cypress_atacb.c         |  4 +--
>   drivers/xen/xen-scsiback.c                  |  2 +-
>   include/scsi/sg.h                           |  2 ++
>   33 files changed, 68 insertions(+), 114 deletions(-)
> 

<snip>


> diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
> index 737cea9d908e..9122d05563d0 100644
> --- a/drivers/scsi/sg.c
> +++ b/drivers/scsi/sg.c
> @@ -498,9 +498,11 @@ sg_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos)
>   	old_hdr->host_status = hp->host_status;
>   	old_hdr->driver_status = hp->driver_status;
>   	if ((CHECK_CONDITION & hp->masked_status) ||
> -	    (DRIVER_SENSE & hp->driver_status))
> +	    (srp->sense_b && (srp->sense_b[0] & 0x70) == 0x70)) {
> +		old_hdr->driver_status |= DRIVER_SENSE;
>   		memcpy(old_hdr->sense_buffer, srp->sense_b,
>   		       sizeof (old_hdr->sense_buffer));
> +	}
>   	switch (hp->host_status) {
>   	/* This setup of 'result' is for backward compatibility and is best
>   	   ignored by the user who should use target, host + driver status */
> @@ -574,7 +576,7 @@ sg_new_read(Sg_fd * sfp, char __user *buf, size_t count, Sg_request * srp)
>   	hp->sb_len_wr = 0;
>   	if ((hp->mx_sb_len > 0) && hp->sbp) {
>   		if ((CHECK_CONDITION & hp->masked_status) ||
> -		    (DRIVER_SENSE & hp->driver_status)) {
> +		    (srp->sense_b && (srp->sense_b[0] & 0x70) == 0x70)) {
>   			int sb_len = SCSI_SENSE_BUFFERSIZE;
>   			sb_len = (hp->mx_sb_len > sb_len) ? sb_len : hp->mx_sb_len;
>   			len = 8 + (int) srp->sense_b[7];	/* Additional sense length field */
> @@ -582,7 +584,8 @@ sg_new_read(Sg_fd * sfp, char __user *buf, size_t count, Sg_request * srp)
>   			if (copy_to_user(hp->sbp, srp->sense_b, len)) {
>   				err = -EFAULT;
>   				goto err_out;
> -			}
> +			} else
> +				hp->driver_status |= DRIVER_SENSE;
>   			hp->sb_len_wr = len;
>   		}
>   	}

<snip>

> diff --git a/include/scsi/sg.h b/include/scsi/sg.h
> index 7327e12f3373..a90703cf15f4 100644
> --- a/include/scsi/sg.h
> +++ b/include/scsi/sg.h
> @@ -131,6 +131,8 @@ struct compat_sg_io_hdr {
>   #define SG_INFO_DIRECT_IO 0x2   /* direct IO requested and performed */
>   #define SG_INFO_MIXED_IO 0x4    /* part direct, part indirect IO */
>   
> +/* Obsolete DRIVER_SENSE setting */
> +#define DRIVER_SENSE 0x08
>   
>   typedef struct sg_scsi_id { /* used by SG_GET_SCSI_ID ioctl() */
>       int host_no;        /* as in "scsi<n>" where 'n' is one of 0, 1, 2 etc */
> 


^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 07/42] scsi: Kill DRIVER_SENSE
  2021-04-21 19:46   ` Douglas Gilbert
@ 2021-04-21 20:07     ` Hannes Reinecke
  0 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-21 20:07 UTC (permalink / raw)
  To: dgilbert, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Bart van Assche, linux-scsi

On 4/21/21 9:46 PM, Douglas Gilbert wrote:
> On 2021-04-21 1:47 p.m., Hannes Reinecke wrote:
>> Replace the check for DRIVER_SENSE with a check for
>> SAM_STAT_CHECK_CONDITION and audit all callsites to
>> ensure the SAM status is set correctly.
>> For backwards compability move the DRIVER_SENSE definition
>> to sg.h, and update the sg driver to set the DRIVER_SENSE
>> driver_status whenever SAM_STAT_CHECK_CONDITION is present.
> 
> I may have missed it but you probably want to do the same
> backwards compatibility DRIVER_SENSE trick for the
> ioctl(SG_IO) implemented in block/scsi_ioctl.c . That way
> DRIVER_SENSE will appear in the sg_io_hdr::driver_status byte
> when check_condition_sense are set for both these cases:
>      ioctl(sd_fd, SG_IO, &a_sg_v3_obj)
>      ioctl(sg_fd, SG_IO, &a_sg_v3_obj)
> 
> And for bsg which uses sg_io_v4 for SCSI commands you set
> sg_io_v4::driver_status = 0
> in all cases. If check_condition and sense are active, why
> not set DRIVER_SENSE for consistency. block/scsi_ioctl.c
> includes scsi/sg.h so the DRIVER_SENSE define is visible.
> 
Oh, indeed; I've forgotten it. Will be including it with the
next round.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [RFC PATCH 00/42] SCSI result cleanup, part 2
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (41 preceding siblings ...)
  2021-04-21 17:47 ` [PATCH 42/42] scsi: kill message byte Hannes Reinecke
@ 2021-04-21 20:54 ` Bart Van Assche
  2021-04-21 22:26 ` Bart Van Assche
  43 siblings, 0 replies; 80+ messages in thread
From: Bart Van Assche @ 2021-04-21 20:54 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/21/21 10:47 AM, Hannes Reinecke wrote:
> This patchset is the first part of that, and is intentionally posted
> as an RFC as it directly competes with Barts patchset.

I'm fine with this patch series being merged upstream first.

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 01/42] st: return error code in st_scsi_execute()
  2021-04-21 17:47 ` [PATCH 01/42] st: return error code in st_scsi_execute() Hannes Reinecke
@ 2021-04-21 20:56   ` Bart Van Assche
  0 siblings, 0 replies; 80+ messages in thread
From: Bart Van Assche @ 2021-04-21 20:56 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/21/21 10:47 AM, Hannes Reinecke wrote:
> The callers to st_scsi_execute already check for negative
> return values, so we can drop the use of DRIVER_ERROR and
> return the actual error code.

A nit: I could only find a single caller?

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 02/42] scsi_ioctl: return error code when blk_rq_map_kern() fails
  2021-04-21 17:47 ` [PATCH 02/42] scsi_ioctl: return error code when blk_rq_map_kern() fails Hannes Reinecke
@ 2021-04-21 21:01   ` Bart Van Assche
  2021-04-22  6:29     ` Hannes Reinecke
  0 siblings, 1 reply; 80+ messages in thread
From: Bart Van Assche @ 2021-04-21 21:01 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/21/21 10:47 AM, Hannes Reinecke wrote:
> The callers of sg_scsi_ioctl() already check for negative
> return values, so we can drop the usage of DRIVER_ERROR
> and return the error from blk_rq_map_kern() instead.
> 
> Signed-off-by: Hannes Reinecke <hare@suse.de>
> ---
>   block/scsi_ioctl.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
> index 6599bac0a78c..99d58786e0d5 100644
> --- a/block/scsi_ioctl.c
> +++ b/block/scsi_ioctl.c
> @@ -488,9 +488,10 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
>   		break;
>   	}
>   
> -	if (bytes && blk_rq_map_kern(q, rq, buffer, bytes, GFP_NOIO)) {
> -		err = DRIVER_ERROR << 24;
> -		goto error;
> +	if (bytes) {
> +		err = blk_rq_map_kern(q, rq, buffer, bytes, GFP_NOIO);
> +		if (err)
> +			goto error;
>   	}
>   
>   	blk_execute_rq(disk, rq, 0);

Is this perhaps a backwards-incompatible user space ABI change since the 
sg_scsi_ioctl() return value is reported to user space?

Thanks,

Bart.



^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 07/42] scsi: Kill DRIVER_SENSE
  2021-04-21 17:47 ` [PATCH 07/42] scsi: Kill DRIVER_SENSE Hannes Reinecke
  2021-04-21 19:46   ` Douglas Gilbert
@ 2021-04-21 21:06   ` Bart Van Assche
  2021-04-22  6:31     ` Hannes Reinecke
  1 sibling, 1 reply; 80+ messages in thread
From: Bart Van Assche @ 2021-04-21 21:06 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/21/21 10:47 AM, Hannes Reinecke wrote:
> diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
> index 6a5b844a8499..2b6138a7c71f 100644
> --- a/drivers/scsi/megaraid/megaraid_mbox.c
> +++ b/drivers/scsi/megaraid/megaraid_mbox.c
> @@ -2299,8 +2299,7 @@ megaraid_mbox_dpc(unsigned long devp)
>   				memcpy(scp->sense_buffer, pthru->reqsensearea,
>   						14);
>   
> -				scp->result = DRIVER_SENSE << 24 |
> -					DID_OK << 16 | CHECK_CONDITION << 1;
> +				scp->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
>   			}
>   			else {
>   				if (mbox->cmd == MBOXCMD_EXTPTHRU) {
> @@ -2308,9 +2307,8 @@ megaraid_mbox_dpc(unsigned long devp)
>   					memcpy(scp->sense_buffer,
>   						epthru->reqsensearea, 14);
>   
> -					scp->result = DRIVER_SENSE << 24 |
> -						DID_OK << 16 |
> -						CHECK_CONDITION << 1;
> +					scp->result = DID_OK << 16 |
> +						SAM_STAT_CHECK_CONDITION;
>   				} else
>   					scsi_build_sense(scp, 0,
>   							 ABORTED_COMMAND, 0, 0);

Since DID_OK == 0 I prefer to leave out the 'DID_OK << 16' expressions 
from code that is modified.

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 13/42] scsi: add get_{status,host}_byte() accessor function
  2021-04-21 17:47 ` [PATCH 13/42] scsi: add get_{status,host}_byte() accessor function Hannes Reinecke
@ 2021-04-21 21:09   ` Bart Van Assche
  2021-04-22  6:33     ` Hannes Reinecke
  0 siblings, 1 reply; 80+ messages in thread
From: Bart Van Assche @ 2021-04-21 21:09 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/21/21 10:47 AM, Hannes Reinecke wrote:
> Add accessor functions for the host and status byte.
> 
> Signed-off-by: Hannes Reinecke <hare@suse.de>
> ---
>   include/scsi/scsi_cmnd.h | 10 ++++++++++
>   1 file changed, 10 insertions(+)
> 
> diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
> index a1eb7732aa1b..0ac18a7d8ac6 100644
> --- a/include/scsi/scsi_cmnd.h
> +++ b/include/scsi/scsi_cmnd.h
> @@ -316,6 +316,11 @@ static inline void set_status_byte(struct scsi_cmnd *cmd, char status)
>   	cmd->result = (cmd->result & 0xffffff00) | status;
>   }
>   
> +static inline unsigned char get_status_byte(struct scsi_cmnd *cmd)
> +{
> +	return cmd->result & 0xff;
> +}

So in addition to the status_byte() macro, get_status_byte() is 
introduced? That seems like a potential source of confusion to me.

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 14/42] scsi: add scsi_result_is_good()
  2021-04-21 17:47 ` [PATCH 14/42] scsi: add scsi_result_is_good() Hannes Reinecke
@ 2021-04-21 21:10   ` Bart Van Assche
  2021-04-21 21:58     ` Douglas Gilbert
  2021-04-22  6:34     ` Hannes Reinecke
  0 siblings, 2 replies; 80+ messages in thread
From: Bart Van Assche @ 2021-04-21 21:10 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/21/21 10:47 AM, Hannes Reinecke wrote:
> +static inline bool scsi_result_is_good(struct scsi_cmnd *cmd)
> +{
> +	return (cmd->result == 0);
> +}

Do we really need an inline function to compare an integer with zero? 
How about open-coding this comparison in the callers of this function?

Thanks,

Bart.


^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 15/42] NCR5380: use SCSI result accessors
  2021-04-21 17:47 ` [PATCH 15/42] NCR5380: use SCSI result accessors Hannes Reinecke
@ 2021-04-21 21:11   ` Bart Van Assche
  2021-04-22  6:37     ` Hannes Reinecke
  2021-04-22  9:36   ` Finn Thain
  1 sibling, 1 reply; 80+ messages in thread
From: Bart Van Assche @ 2021-04-21 21:11 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/21/21 10:47 AM, Hannes Reinecke wrote:
> Use accessors to set the SCSI result.
> 
> Signed-off-by: Hannes Reinecke <hare@suse.de>
> ---
>   drivers/scsi/NCR5380.c | 28 ++++++++++++++--------------
>   1 file changed, 14 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
> index d7594b794d3c..855edda9db41 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);

Do all SCSI devices from the nineties report SCSI status values with the 
lower bit set to 0? If so, can the status_byte() macro be removed entirely?

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 41/42] scsi: drop message byte helper
  2021-04-21 17:47 ` [PATCH 41/42] scsi: drop message byte helper Hannes Reinecke
@ 2021-04-21 21:14   ` Bart Van Assche
  2021-04-22  6:37     ` Hannes Reinecke
  0 siblings, 1 reply; 80+ messages in thread
From: Bart Van Assche @ 2021-04-21 21:14 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/21/21 10:47 AM, Hannes Reinecke wrote:
> The message byte is not unused, so we can drop the helper to set
> the message byte and the check for message bytes during error recovery.

not -> now?

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 05/42] scsi: stop using DRIVER_ERROR
  2021-04-21 17:47 ` [PATCH 05/42] scsi: stop using DRIVER_ERROR Hannes Reinecke
@ 2021-04-21 21:30   ` Bart Van Assche
  2021-04-22  8:39     ` Hannes Reinecke
  0 siblings, 1 reply; 80+ messages in thread
From: Bart Van Assche @ 2021-04-21 21:30 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/21/21 10:47 AM, Hannes Reinecke wrote:
> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> index c532f9390ae3..2d9b533ef1ec 100644
> --- a/drivers/scsi/scsi_lib.c
> +++ b/drivers/scsi/scsi_lib.c
> @@ -245,20 +245,23 @@ int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
>   {
>   	struct request *req;
>   	struct scsi_request *rq;
> -	int ret = DRIVER_ERROR << 24;
> +	int ret;
>   
>   	req = blk_get_request(sdev->request_queue,
>   			data_direction == DMA_TO_DEVICE ?
>   			REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN,
>   			rq_flags & RQF_PM ? BLK_MQ_REQ_PM : 0);
>   	if (IS_ERR(req))
> -		return ret;
> -	rq = scsi_req(req);
> +		return PTR_ERR(req);
>   
> -	if (bufflen &&	blk_rq_map_kern(sdev->request_queue, req,
> -					buffer, bufflen, GFP_NOIO))
> -		goto out;
> +	rq = scsi_req(req);
>   
> +	if (bufflen) {
> +		ret = blk_rq_map_kern(sdev->request_queue, req,
> +				      buffer, bufflen, GFP_NOIO);
> +		if (ret)
> +			goto out;
> +	}
>   	rq->cmd_len = COMMAND_SIZE(cmd[0]);
>   	memcpy(rq->cmd, cmd, rq->cmd_len);
>   	rq->retries = retries;

Please mention in the patch description that this change involves a user 
space ABI change. My understanding is that the current behavior of the 
IOC_PR_* ioctls is as follows:
* A value <= 0 is returned for NVMe where 0 represents success and a 
negative value represents failure.
* A value >= 0 is returned for SCSI where 0 represents success and a 
positive value is a four-byte SCSI status code.

This patch changes the behavior for SCSI from returning a value >= 0 
into returning a value that can be negative, zero or positive where only 
the return value 0 represents success.

See also sd_pr_command() in drivers/scsi/sd.c.

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 14/42] scsi: add scsi_result_is_good()
  2021-04-21 21:10   ` Bart Van Assche
@ 2021-04-21 21:58     ` Douglas Gilbert
  2021-04-22  8:42       ` Hannes Reinecke
  2021-04-22  6:34     ` Hannes Reinecke
  1 sibling, 1 reply; 80+ messages in thread
From: Douglas Gilbert @ 2021-04-21 21:58 UTC (permalink / raw)
  To: Bart Van Assche, Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 2021-04-21 5:10 p.m., Bart Van Assche wrote:
> On 4/21/21 10:47 AM, Hannes Reinecke wrote:
>> +static inline bool scsi_result_is_good(struct scsi_cmnd *cmd)
>> +{
>> +    return (cmd->result == 0);
>> +}
> 
> Do we really need an inline function to compare an integer with zero? How about 
> open-coding this comparison in the callers of this function?
> 

Please don't open code it. Please fix it!
Spot the difference:

static inline int scsi_status_is_good(int status)
{
         /*
          * FIXME: bit0 is listed as reserved in SCSI-2, but is
          * significant in SCSI-3.  For now, we follow the SCSI-2
          * behaviour and ignore reserved bits.
          */
         status &= 0xfe;
         return ((status == SAM_STAT_GOOD) ||
                 (status == SAM_STAT_CONDITION_MET) ||
/*   >>>                   ^^^^^^^^^^^^^^^^^^^^^^                <<<        */
                 /* Next two "intermediate" statuses are obsolete in SAM-4 */
                 (status == SAM_STAT_INTERMEDIATE) ||
                 (status == SAM_STAT_INTERMEDIATE_CONDITION_MET) ||
                 /* FIXME: this is obsolete in SAM-3 */
                 (status == SAM_STAT_COMMAND_TERMINATED));
}

In sg3_utils' library I ignore the last three SAM_STATs. Not sure if ignoring
bit 0 is still required.

Without considering SAM_STAT_CONDITION_MET a good status, someone will be
scratching their head wondering why so many PRE-FETCH commands fail.

That command can be used when a sequence of READs to consecutive LBAs is
followed by a different (i.e. non-consecutive) READ. That last READ could
be preceded by PRE-FETCH(new_LBA, IMMED). Assuming there is processing
of the data from the consecutive LBAs to be done, when the time comes
for READ(new_LBA) the probability of its data being in the disk's cache is
increased.

Doug Gilbert

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [RFC PATCH 00/42] SCSI result cleanup, part 2
  2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
                   ` (42 preceding siblings ...)
  2021-04-21 20:54 ` [RFC PATCH 00/42] SCSI result cleanup, part 2 Bart Van Assche
@ 2021-04-21 22:26 ` Bart Van Assche
  2021-04-22  8:49   ` Hannes Reinecke
  43 siblings, 1 reply; 80+ messages in thread
From: Bart Van Assche @ 2021-04-21 22:26 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/21/21 10:47 AM, Hannes Reinecke wrote:
> My plan here is move every driver to use accessors for the
> remaining bytes in the SCSI result, and with that move the
> SCSI result over into two separate values.

This patch series modifies scsi_execute() such that it either returns a 
negative Unix error code or a positive SCSI status value that includes 
the host byte and status byte. I think that a union is a good way to 
model such return values. I'd like to use something similar to the 
scsi_status union from my patch series to model such return values. I 
think that union is also appropriate as a replacement for the 'result' 
member of struct scsi_cmnd.

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 18/42] dc395: use standard macros to set SCSI result
  2021-04-21 17:47 ` [PATCH 18/42] dc395: use standard macros to set SCSI result Hannes Reinecke
@ 2021-04-21 22:26   ` Bart Van Assche
  2021-04-22  8:52     ` Hannes Reinecke
  0 siblings, 1 reply; 80+ messages in thread
From: Bart Van Assche @ 2021-04-21 22:26 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/21/21 10:47 AM, Hannes Reinecke wrote:
> Use standard macros to set the SCSI result and drop the internal ones.

This patch looks almost identical to a patch from my patch series?

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 02/42] scsi_ioctl: return error code when blk_rq_map_kern() fails
  2021-04-21 21:01   ` Bart Van Assche
@ 2021-04-22  6:29     ` Hannes Reinecke
  0 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-22  6:29 UTC (permalink / raw)
  To: Bart Van Assche, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/21/21 11:01 PM, Bart Van Assche wrote:
> On 4/21/21 10:47 AM, Hannes Reinecke wrote:
>> The callers of sg_scsi_ioctl() already check for negative
>> return values, so we can drop the usage of DRIVER_ERROR
>> and return the error from blk_rq_map_kern() instead.
>>
>> Signed-off-by: Hannes Reinecke <hare@suse.de>
>> ---
>>   block/scsi_ioctl.c | 7 ++++---
>>   1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
>> index 6599bac0a78c..99d58786e0d5 100644
>> --- a/block/scsi_ioctl.c
>> +++ b/block/scsi_ioctl.c
>> @@ -488,9 +488,10 @@ int sg_scsi_ioctl(struct request_queue *q, struct 
>> gendisk *disk, fmode_t mode,
>>           break;
>>       }
>> -    if (bytes && blk_rq_map_kern(q, rq, buffer, bytes, GFP_NOIO)) {
>> -        err = DRIVER_ERROR << 24;
>> -        goto error;
>> +    if (bytes) {
>> +        err = blk_rq_map_kern(q, rq, buffer, bytes, GFP_NOIO);
>> +        if (err)
>> +            goto error;
>>       }
>>       blk_execute_rq(disk, rq, 0);
> 
> Is this perhaps a backwards-incompatible user space ABI change since the 
> sg_scsi_ioctl() return value is reported to user space?
> 
Possibly; but we're dealing with semantics here.
All callers to sg_scsi_ioctl() _must_ be prepared to handle negative
values already, so userspace should not break.
We arguably _do_ return a different error here, but experience showed 
that basically no-one checks for driver byte values (except for 
DRIVER_SENSE, that is).
So I don't think it really matters; we do return an error, and for 
userspace it doesn't matter as this command cannot be retried either way.

So while this arguably is a change visible to userspace, I doubt it 
matters in the end.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 07/42] scsi: Kill DRIVER_SENSE
  2021-04-21 21:06   ` Bart Van Assche
@ 2021-04-22  6:31     ` Hannes Reinecke
  2021-04-22 15:46       ` Douglas Gilbert
  0 siblings, 1 reply; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-22  6:31 UTC (permalink / raw)
  To: Bart Van Assche, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/21/21 11:06 PM, Bart Van Assche wrote:
> On 4/21/21 10:47 AM, Hannes Reinecke wrote:
>> diff --git a/drivers/scsi/megaraid/megaraid_mbox.c 
>> b/drivers/scsi/megaraid/megaraid_mbox.c
>> index 6a5b844a8499..2b6138a7c71f 100644
>> --- a/drivers/scsi/megaraid/megaraid_mbox.c
>> +++ b/drivers/scsi/megaraid/megaraid_mbox.c
>> @@ -2299,8 +2299,7 @@ megaraid_mbox_dpc(unsigned long devp)
>>                   memcpy(scp->sense_buffer, pthru->reqsensearea,
>>                           14);
>> -                scp->result = DRIVER_SENSE << 24 |
>> -                    DID_OK << 16 | CHECK_CONDITION << 1;
>> +                scp->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
>>               }
>>               else {
>>                   if (mbox->cmd == MBOXCMD_EXTPTHRU) {
>> @@ -2308,9 +2307,8 @@ megaraid_mbox_dpc(unsigned long devp)
>>                       memcpy(scp->sense_buffer,
>>                           epthru->reqsensearea, 14);
>> -                    scp->result = DRIVER_SENSE << 24 |
>> -                        DID_OK << 16 |
>> -                        CHECK_CONDITION << 1;
>> +                    scp->result = DID_OK << 16 |
>> +                        SAM_STAT_CHECK_CONDITION;
>>                   } else
>>                       scsi_build_sense(scp, 0,
>>                                ABORTED_COMMAND, 0, 0);
> 
> Since DID_OK == 0 I prefer to leave out the 'DID_OK << 16' expressions 
> from code that is modified.
> 
Okay, will do.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 13/42] scsi: add get_{status,host}_byte() accessor function
  2021-04-21 21:09   ` Bart Van Assche
@ 2021-04-22  6:33     ` Hannes Reinecke
  0 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-22  6:33 UTC (permalink / raw)
  To: Bart Van Assche, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/21/21 11:09 PM, Bart Van Assche wrote:
> On 4/21/21 10:47 AM, Hannes Reinecke wrote:
>> Add accessor functions for the host and status byte.
>>
>> Signed-off-by: Hannes Reinecke <hare@suse.de>
>> ---
>>   include/scsi/scsi_cmnd.h | 10 ++++++++++
>>   1 file changed, 10 insertions(+)
>>
>> diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
>> index a1eb7732aa1b..0ac18a7d8ac6 100644
>> --- a/include/scsi/scsi_cmnd.h
>> +++ b/include/scsi/scsi_cmnd.h
>> @@ -316,6 +316,11 @@ static inline void set_status_byte(struct 
>> scsi_cmnd *cmd, char status)
>>       cmd->result = (cmd->result & 0xffffff00) | status;
>>   }
>> +static inline unsigned char get_status_byte(struct scsi_cmnd *cmd)
>> +{
>> +    return cmd->result & 0xff;
>> +}
> 
> So in addition to the status_byte() macro, get_status_byte() is 
> introduced? That seems like a potential source of confusion to me.
> 
The idea is to kill 'status_byte' (and the linux-specific status codes) 
entirely, which then would resolve this ambiguity.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 14/42] scsi: add scsi_result_is_good()
  2021-04-21 21:10   ` Bart Van Assche
  2021-04-21 21:58     ` Douglas Gilbert
@ 2021-04-22  6:34     ` Hannes Reinecke
  1 sibling, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-22  6:34 UTC (permalink / raw)
  To: Bart Van Assche, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/21/21 11:10 PM, Bart Van Assche wrote:
> On 4/21/21 10:47 AM, Hannes Reinecke wrote:
>> +static inline bool scsi_result_is_good(struct scsi_cmnd *cmd)
>> +{
>> +    return (cmd->result == 0);
>> +}
> 
> Do we really need an inline function to compare an integer with zero? 
> How about open-coding this comparison in the callers of this function?
> 
My approach is to avoid direct access to the 'result' field, as the 
definition of which is about to change.

But as this is not part of _this_ patchset I'll drop this patch for the 
next round.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 15/42] NCR5380: use SCSI result accessors
  2021-04-21 21:11   ` Bart Van Assche
@ 2021-04-22  6:37     ` Hannes Reinecke
  2021-04-22 16:10       ` Bart Van Assche
  0 siblings, 1 reply; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-22  6:37 UTC (permalink / raw)
  To: Bart Van Assche, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/21/21 11:11 PM, Bart Van Assche wrote:
> On 4/21/21 10:47 AM, Hannes Reinecke wrote:
>> Use accessors to set the SCSI result.
>>
>> Signed-off-by: Hannes Reinecke <hare@suse.de>
>> ---
>>   drivers/scsi/NCR5380.c | 28 ++++++++++++++--------------
>>   1 file changed, 14 insertions(+), 14 deletions(-)
>>
>> diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
>> index d7594b794d3c..855edda9db41 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);
> 
> Do all SCSI devices from the nineties report SCSI status values with the 
> lower bit set to 0? If so, can the status_byte() macro be removed entirely?
> 
As indicated in the previous reply, yes, that is the plan (removing the 
status_byte() macro). And the drivers will have to report SCSI status 
values with the lower bit cleared, otherwise the linux SCSI status codes 
would never have worked in the first place.

So I'll be adding a new patch for dropping the 'status_byte()' macro in 
the next round.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 41/42] scsi: drop message byte helper
  2021-04-21 21:14   ` Bart Van Assche
@ 2021-04-22  6:37     ` Hannes Reinecke
  0 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-22  6:37 UTC (permalink / raw)
  To: Bart Van Assche, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/21/21 11:14 PM, Bart Van Assche wrote:
> On 4/21/21 10:47 AM, Hannes Reinecke wrote:
>> The message byte is not unused, so we can drop the helper to set
>> the message byte and the check for message bytes during error recovery.
> 
> not -> now?
> 
Why, of course. Will be fixing it.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 05/42] scsi: stop using DRIVER_ERROR
  2021-04-21 21:30   ` Bart Van Assche
@ 2021-04-22  8:39     ` Hannes Reinecke
  0 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-22  8:39 UTC (permalink / raw)
  To: Bart Van Assche, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/21/21 11:30 PM, Bart Van Assche wrote:
> On 4/21/21 10:47 AM, Hannes Reinecke wrote:
>> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
>> index c532f9390ae3..2d9b533ef1ec 100644
>> --- a/drivers/scsi/scsi_lib.c
>> +++ b/drivers/scsi/scsi_lib.c
>> @@ -245,20 +245,23 @@ int __scsi_execute(struct scsi_device *sdev, 
>> const unsigned char *cmd,
>>   {
>>       struct request *req;
>>       struct scsi_request *rq;
>> -    int ret = DRIVER_ERROR << 24;
>> +    int ret;
>>       req = blk_get_request(sdev->request_queue,
>>               data_direction == DMA_TO_DEVICE ?
>>               REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN,
>>               rq_flags & RQF_PM ? BLK_MQ_REQ_PM : 0);
>>       if (IS_ERR(req))
>> -        return ret;
>> -    rq = scsi_req(req);
>> +        return PTR_ERR(req);
>> -    if (bufflen &&    blk_rq_map_kern(sdev->request_queue, req,
>> -                    buffer, bufflen, GFP_NOIO))
>> -        goto out;
>> +    rq = scsi_req(req);
>> +    if (bufflen) {
>> +        ret = blk_rq_map_kern(sdev->request_queue, req,
>> +                      buffer, bufflen, GFP_NOIO);
>> +        if (ret)
>> +            goto out;
>> +    }
>>       rq->cmd_len = COMMAND_SIZE(cmd[0]);
>>       memcpy(rq->cmd, cmd, rq->cmd_len);
>>       rq->retries = retries;
> 
> Please mention in the patch description that this change involves a user 
> space ABI change. My understanding is that the current behavior of the 
> IOC_PR_* ioctls is as follows:
> * A value <= 0 is returned for NVMe where 0 represents success and a 
> negative value represents failure.
> * A value >= 0 is returned for SCSI where 0 represents success and a 
> positive value is a four-byte SCSI status code.
> 
> This patch changes the behavior for SCSI from returning a value >= 0 
> into returning a value that can be negative, zero or positive where only 
> the return value 0 represents success.
> 
> See also sd_pr_command() in drivers/scsi/sd.c.
> 

As indicated: the description for __scsi_execute() explicitly states 
that a negative return value is allowed here.
And all functions calling sd_pr_command() might even now return a 
negative error value, so userspace _must_ be prepared to handle it.

So while we're changing the error we return, the actual impact to 
userspace should be pretty neglible as either error value indicates
a non-retryable failure.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 14/42] scsi: add scsi_result_is_good()
  2021-04-21 21:58     ` Douglas Gilbert
@ 2021-04-22  8:42       ` Hannes Reinecke
  2021-04-22  9:36         ` Finn Thain
  2021-04-22 15:56         ` Douglas Gilbert
  0 siblings, 2 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-22  8:42 UTC (permalink / raw)
  To: dgilbert, Bart Van Assche, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/21/21 11:58 PM, Douglas Gilbert wrote:
> On 2021-04-21 5:10 p.m., Bart Van Assche wrote:
>> On 4/21/21 10:47 AM, Hannes Reinecke wrote:
>>> +static inline bool scsi_result_is_good(struct scsi_cmnd *cmd)
>>> +{
>>> +    return (cmd->result == 0);
>>> +}
>>
>> Do we really need an inline function to compare an integer with zero? 
>> How about open-coding this comparison in the callers of this function?
>>
> 
> Please don't open code it. Please fix it!
> Spot the difference:
> 
> static inline int scsi_status_is_good(int status)
> {
>          /*
>           * FIXME: bit0 is listed as reserved in SCSI-2, but is
>           * significant in SCSI-3.  For now, we follow the SCSI-2
>           * behaviour and ignore reserved bits.
>           */
>          status &= 0xfe;
>          return ((status == SAM_STAT_GOOD) ||
>                  (status == SAM_STAT_CONDITION_MET) ||
> /*   >>>                   ^^^^^^^^^^^^^^^^^^^^^^                
> <<<        */
>                  /* Next two "intermediate" statuses are obsolete in 
> SAM-4 */
>                  (status == SAM_STAT_INTERMEDIATE) ||
>                  (status == SAM_STAT_INTERMEDIATE_CONDITION_MET) ||
>                  /* FIXME: this is obsolete in SAM-3 */
>                  (status == SAM_STAT_COMMAND_TERMINATED));
> }
> 
> In sg3_utils' library I ignore the last three SAM_STATs. Not sure if 
> ignoring
> bit 0 is still required.
> 
> Without considering SAM_STAT_CONDITION_MET a good status, someone will be
> scratching their head wondering why so many PRE-FETCH commands fail.
> 
> That command can be used when a sequence of READs to consecutive LBAs is
> followed by a different (i.e. non-consecutive) READ. That last READ could
> be preceded by PRE-FETCH(new_LBA, IMMED). Assuming there is processing
> of the data from the consecutive LBAs to be done, when the time comes
> for READ(new_LBA) the probability of its data being in the disk's cache is
> increased.
> 
That would be a change in behaviour.
Current code doesn't check for CONDITION_MET, so this change shouldn't 
do it, neither. Idea was that this patchset shouldn't change the current 
behaviour.

While your argument might be valid, it definitely is a different story 
and would need to be address with a different patchset.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [RFC PATCH 00/42] SCSI result cleanup, part 2
  2021-04-21 22:26 ` Bart Van Assche
@ 2021-04-22  8:49   ` Hannes Reinecke
  2021-04-22 16:28     ` Bart Van Assche
  0 siblings, 1 reply; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-22  8:49 UTC (permalink / raw)
  To: Bart Van Assche, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/22/21 12:26 AM, Bart Van Assche wrote:
> On 4/21/21 10:47 AM, Hannes Reinecke wrote:
>> My plan here is move every driver to use accessors for the
>> remaining bytes in the SCSI result, and with that move the
>> SCSI result over into two separate values.
> 
> This patch series modifies scsi_execute() such that it either returns a 
> negative Unix error code or a positive SCSI status value that includes 
> the host byte and status byte. I think that a union is a good way to 
> model such return values. I'd like to use something similar to the 
> scsi_status union from my patch series to model such return values. I 
> think that union is also appropriate as a replacement for the 'result' 
> member of struct scsi_cmnd.
> 
And that was precisely the point of my patchset: do _not_ use driver 
byte nor message byte in the SCSI midlayer.
So the midlayer can be reduced to handling just the host byte and the 
status byte. Whether this is by means of a union or something else 
doesn't really matter; this patchset doesn't prevent any of this from 
happening.

I'm open to discussion on whether we need to expose the original driver 
byte to userspace; I've already attempted to do this for DRIVER_SENSE, 
and if needs be DRIVER_ERROR can be fudged in, too.
But I do think that message byte handling should be killed from the 
midlayer, as it really is SCSI parallel specific and shouldn't be 
exposed to the midlayer at all.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 18/42] dc395: use standard macros to set SCSI result
  2021-04-21 22:26   ` Bart Van Assche
@ 2021-04-22  8:52     ` Hannes Reinecke
  2021-04-22 16:12       ` Bart Van Assche
  0 siblings, 1 reply; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-22  8:52 UTC (permalink / raw)
  To: Bart Van Assche, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/22/21 12:26 AM, Bart Van Assche wrote:
> On 4/21/21 10:47 AM, Hannes Reinecke wrote:
>> Use standard macros to set the SCSI result and drop the internal ones.
> 
> This patch looks almost identical to a patch from my patch series?
> 
That might well be; please do note that this patch is from the previous 
version and is dated January 2021, with a previous version dating back 
to mid-2019. I just didn't check your patchset for duplicates, sorry.

Hence the 'RFC' bit :-)

But if you insist I can fold your patch into this series and drop mine.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@suse.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Felix Imendörffer

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 16/42] NCR5380: Fold SCSI message ABORT onto DID_ABORT
  2021-04-21 17:47 ` [PATCH 16/42] NCR5380: Fold SCSI message ABORT onto DID_ABORT Hannes Reinecke
@ 2021-04-22  9:35   ` Finn Thain
  0 siblings, 0 replies; 80+ messages in thread
From: Finn Thain @ 2021-04-22  9:35 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: Martin K. Petersen, Christoph Hellwig, James Bottomley,
	Bart van Assche, linux-scsi

On Wed, 21 Apr 2021, Hannes Reinecke wrote:

> The message byte can take only two values, COMMAND_COMPLETE and ABORT.
> So we can easily map ABORT to DID_ABORT and do not set the message byte.
> 
> Signed-off-by: Hannes Reinecke <hare@suse.de>
> ---
>  drivers/scsi/NCR5380.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
> index 855edda9db41..76b4dce22e03 100644
> --- a/drivers/scsi/NCR5380.c
> +++ b/drivers/scsi/NCR5380.c
> @@ -1827,7 +1827,8 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
>  					hostdata->connected = NULL;
>  					hostdata->busy[scmd_id(cmd)] &= ~(1 << cmd->device->lun);
>  
> -					set_msg_byte(cmd, cmd->SCp.Message);
> +					if (cmd->SCp.Message == ABORT)
> +						set_host_byte(cmd, DID_ABORT);
>  					set_status_byte(cmd, cmd->SCp.Status);
>  
>  					set_resid_from_SCp(cmd);
> 

Can that be expressed more succinctly? E.g.

                                 switch (tmp) {
                                 case ABORT:
+					set_host_byte(cmd, DID_ABORT);
                                 case COMMAND_COMPLETE:

Should this be folded into the preceding patch?

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 15/42] NCR5380: use SCSI result accessors
  2021-04-21 17:47 ` [PATCH 15/42] NCR5380: use SCSI result accessors Hannes Reinecke
  2021-04-21 21:11   ` Bart Van Assche
@ 2021-04-22  9:36   ` Finn Thain
  1 sibling, 0 replies; 80+ messages in thread
From: Finn Thain @ 2021-04-22  9:36 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: Martin K. Petersen, Christoph Hellwig, James Bottomley,
	Bart van Assche, linux-scsi

On Wed, 21 Apr 2021, Hannes Reinecke wrote:

> Use accessors to set the SCSI result.
> 
> Signed-off-by: Hannes Reinecke <hare@suse.de>
> ---
>  drivers/scsi/NCR5380.c | 28 ++++++++++++++--------------
>  1 file changed, 14 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
> index d7594b794d3c..855edda9db41 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);
> @@ -567,18 +567,19 @@ static int NCR5380_queue_command(struct Scsi_Host *instance,
>  	struct NCR5380_cmd *ncmd = scsi_cmd_priv(cmd);
>  	unsigned long flags;
>  
> +	set_host_byte(cmd, DID_OK);
> +	set_status_byte(cmd, SAM_STAT_GOOD);
>  #if (NDEBUG & NDEBUG_NO_WRITE)
>  	switch (cmd->cmnd[0]) {
>  	case WRITE_6:
>  	case WRITE_10:
>  		shost_printk(KERN_DEBUG, instance, "WRITE attempted with NDEBUG_NO_WRITE set\n");
> -		cmd->result = (DID_ERROR << 16);
> +		set_host_byte(cmd, DID_ERROR);
>  		cmd->scsi_done(cmd);
>  		return 0;
>  	}
>  #endif /* (NDEBUG & NDEBUG_NO_WRITE) */
>  
> -	cmd->result = 0;
>  

Please remove the superfluous blank line.

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 14/42] scsi: add scsi_result_is_good()
  2021-04-22  8:42       ` Hannes Reinecke
@ 2021-04-22  9:36         ` Finn Thain
  2021-04-22 15:56         ` Douglas Gilbert
  1 sibling, 0 replies; 80+ messages in thread
From: Finn Thain @ 2021-04-22  9:36 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: dgilbert, Bart Van Assche, Martin K. Petersen, Christoph Hellwig,
	James Bottomley, linux-scsi

On Thu, 22 Apr 2021, Hannes Reinecke wrote:

> That would be a change in behaviour. Current code doesn't check for 
> CONDITION_MET, so this change shouldn't do it, neither. Idea was that 
> this patchset shouldn't change the current behaviour.
> 
> While your argument might be valid, it definitely is a different story 
> and would need to be address with a different patchset.
> 

As long as you're avoiding behavioural changes, you may need to drop the 
status_byte() change in patch 15/42 from this particular patch set -- 
unless it can be shown (inferred somehow) that drives never set that bit.

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 07/42] scsi: Kill DRIVER_SENSE
  2021-04-22  6:31     ` Hannes Reinecke
@ 2021-04-22 15:46       ` Douglas Gilbert
  0 siblings, 0 replies; 80+ messages in thread
From: Douglas Gilbert @ 2021-04-22 15:46 UTC (permalink / raw)
  To: Hannes Reinecke, Bart Van Assche, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 2021-04-22 2:31 a.m., Hannes Reinecke wrote:
> On 4/21/21 11:06 PM, Bart Van Assche wrote:
>> On 4/21/21 10:47 AM, Hannes Reinecke wrote:
>>> diff --git a/drivers/scsi/megaraid/megaraid_mbox.c 
>>> b/drivers/scsi/megaraid/megaraid_mbox.c
>>> index 6a5b844a8499..2b6138a7c71f 100644
>>> --- a/drivers/scsi/megaraid/megaraid_mbox.c
>>> +++ b/drivers/scsi/megaraid/megaraid_mbox.c
>>> @@ -2299,8 +2299,7 @@ megaraid_mbox_dpc(unsigned long devp)
>>>                   memcpy(scp->sense_buffer, pthru->reqsensearea,
>>>                           14);
>>> -                scp->result = DRIVER_SENSE << 24 |
>>> -                    DID_OK << 16 | CHECK_CONDITION << 1;
>>> +                scp->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
>>>               }
>>>               else {
>>>                   if (mbox->cmd == MBOXCMD_EXTPTHRU) {
>>> @@ -2308,9 +2307,8 @@ megaraid_mbox_dpc(unsigned long devp)
>>>                       memcpy(scp->sense_buffer,
>>>                           epthru->reqsensearea, 14);
>>> -                    scp->result = DRIVER_SENSE << 24 |
>>> -                        DID_OK << 16 |
>>> -                        CHECK_CONDITION << 1;
>>> +                    scp->result = DID_OK << 16 |
>>> +                        SAM_STAT_CHECK_CONDITION;
>>>                   } else
>>>                       scsi_build_sense(scp, 0,
>>>                                ABORTED_COMMAND, 0, 0);
>>
>> Since DID_OK == 0 I prefer to leave out the 'DID_OK << 16' expressions from 
>> code that is modified.
>>
> Okay, will do.
> 

If DID_OK << 16 (and the extra bitwise OR) does not generate any code
then I think it is pretty good inline documentation to show LLDs how
to build the "compound" 32 bit integer in error situations.

If there is no runtime penalty, I would prefer to keep it :-)

Doug Gilbert

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 14/42] scsi: add scsi_result_is_good()
  2021-04-22  8:42       ` Hannes Reinecke
  2021-04-22  9:36         ` Finn Thain
@ 2021-04-22 15:56         ` Douglas Gilbert
  2021-04-22 16:51           ` Douglas Gilbert
  2021-04-22 16:52           ` Bart Van Assche
  1 sibling, 2 replies; 80+ messages in thread
From: Douglas Gilbert @ 2021-04-22 15:56 UTC (permalink / raw)
  To: Hannes Reinecke, Bart Van Assche, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 2021-04-22 4:42 a.m., Hannes Reinecke wrote:
> On 4/21/21 11:58 PM, Douglas Gilbert wrote:
>> On 2021-04-21 5:10 p.m., Bart Van Assche wrote:
>>> On 4/21/21 10:47 AM, Hannes Reinecke wrote:
>>>> +static inline bool scsi_result_is_good(struct scsi_cmnd *cmd)
>>>> +{
>>>> +    return (cmd->result == 0);
>>>> +}
>>>
>>> Do we really need an inline function to compare an integer with zero? How 
>>> about open-coding this comparison in the callers of this function?
>>>
>>
>> Please don't open code it. Please fix it!
>> Spot the difference:
>>
>> static inline int scsi_status_is_good(int status)
>> {
>>          /*
>>           * FIXME: bit0 is listed as reserved in SCSI-2, but is
>>           * significant in SCSI-3.  For now, we follow the SCSI-2
>>           * behaviour and ignore reserved bits.
>>           */
>>          status &= 0xfe;
>>          return ((status == SAM_STAT_GOOD) ||
>>                  (status == SAM_STAT_CONDITION_MET) ||
>> /*   >>>                   ^^^^^^^^^^^^^^^^^^^^^^ <<<        */
>>                  /* Next two "intermediate" statuses are obsolete in SAM-4 */
>>                  (status == SAM_STAT_INTERMEDIATE) ||
>>                  (status == SAM_STAT_INTERMEDIATE_CONDITION_MET) ||
>>                  /* FIXME: this is obsolete in SAM-3 */
>>                  (status == SAM_STAT_COMMAND_TERMINATED));
>> }
>>
>> In sg3_utils' library I ignore the last three SAM_STATs. Not sure if ignoring
>> bit 0 is still required.
>>
>> Without considering SAM_STAT_CONDITION_MET a good status, someone will be
>> scratching their head wondering why so many PRE-FETCH commands fail.
>>
>> That command can be used when a sequence of READs to consecutive LBAs is
>> followed by a different (i.e. non-consecutive) READ. That last READ could
>> be preceded by PRE-FETCH(new_LBA, IMMED). Assuming there is processing
>> of the data from the consecutive LBAs to be done, when the time comes
>> for READ(new_LBA) the probability of its data being in the disk's cache is
>> increased.
>>
> That would be a change in behaviour.
> Current code doesn't check for CONDITION_MET, so this change shouldn't do it, 
> neither. Idea was that this patchset shouldn't change the current behaviour.
> 
> While your argument might be valid, it definitely is a different story and would 
> need to be address with a different patchset.

Okay. May I suggest a "FIX_ME" comment? And again, please don't open code it.

In driver manuals Seagate often list the PRE-FETCH command as optional. As
in: pay us some extra money and we will put it in. That suggests to me some
big OEM likes PRE-FETCH. Where I found it supported in WDC manuals, they
didn't support the IMMED bit which sort of defeats the purpose of it IMO.

Doug Gilbert



^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 15/42] NCR5380: use SCSI result accessors
  2021-04-22  6:37     ` Hannes Reinecke
@ 2021-04-22 16:10       ` Bart Van Assche
  2021-04-26  8:30         ` Hannes Reinecke
  0 siblings, 1 reply; 80+ messages in thread
From: Bart Van Assche @ 2021-04-22 16:10 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/21/21 11:37 PM, Hannes Reinecke wrote:
> On 4/21/21 11:11 PM, Bart Van Assche wrote:
>> Do all SCSI devices from the nineties report SCSI status values with
>> the lower bit set to 0? If so, can the status_byte() macro be removed
>> entirely?
>>
> As indicated in the previous reply, yes, that is the plan (removing the
> status_byte() macro). And the drivers will have to report SCSI status
> values with the lower bit cleared, otherwise the linux SCSI status codes
> would never have worked in the first place.

Please elaborate the above further. My understanding is that SCSI-2
defines bits 0, 6 and 7 of the status byte as reserved while SAM-2
specifies that these bits must be zero for the status codes that also
have been defined in SCSI-2. Is it safe to assume that all SCSI-2
devices set the reserved bits to zero?

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 18/42] dc395: use standard macros to set SCSI result
  2021-04-22  8:52     ` Hannes Reinecke
@ 2021-04-22 16:12       ` Bart Van Assche
  0 siblings, 0 replies; 80+ messages in thread
From: Bart Van Assche @ 2021-04-22 16:12 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/22/21 1:52 AM, Hannes Reinecke wrote:
> On 4/22/21 12:26 AM, Bart Van Assche wrote:
>> On 4/21/21 10:47 AM, Hannes Reinecke wrote:
>>> Use standard macros to set the SCSI result and drop the internal ones.
>>
>> This patch looks almost identical to a patch from my patch series?
>
> That might well be; please do note that this patch is from the previous
> version and is dated January 2021, with a previous version dating back
> to mid-2019. I just didn't check your patchset for duplicates, sorry.
> 
> Hence the 'RFC' bit :-)
> 
> But if you insist I can fold your patch into this series and drop mine.

Since your patch is probably older than mine, feel free to keep your patch.

Thanks,

Bart.


^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [RFC PATCH 00/42] SCSI result cleanup, part 2
  2021-04-22  8:49   ` Hannes Reinecke
@ 2021-04-22 16:28     ` Bart Van Assche
  0 siblings, 0 replies; 80+ messages in thread
From: Bart Van Assche @ 2021-04-22 16:28 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/22/21 1:49 AM, Hannes Reinecke wrote:
> So the midlayer can be reduced to handling just the host byte and the
> status byte. Whether this is by means of a union or something else
> doesn't really matter; this patchset doesn't prevent any of this from
> happening.

Something that is important to mention is that struct scsi_request is
not only used by the SCSI code but also by the IDE code. Changing the
'result' member of struct scsi_request also affects the IDE code.

These are the SCSI and block layer calls in the IDE code that I am aware
of and that assume that a struct scsi_request immediately follows struct
request:
* scsi_req_init().
* scsi_cmd_blk_ioctl().

I have not yet tried to evaluate how much work it would take to split
the code in block/scsi_ioctl.c such that it supports different layouts
for the data that follows struct request for IDE and SCSI.

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 14/42] scsi: add scsi_result_is_good()
  2021-04-22 15:56         ` Douglas Gilbert
@ 2021-04-22 16:51           ` Douglas Gilbert
  2021-04-22 16:52           ` Bart Van Assche
  1 sibling, 0 replies; 80+ messages in thread
From: Douglas Gilbert @ 2021-04-22 16:51 UTC (permalink / raw)
  To: Hannes Reinecke, Bart Van Assche, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 2021-04-22 11:56 a.m., Douglas Gilbert wrote:
> On 2021-04-22 4:42 a.m., Hannes Reinecke wrote:
>> On 4/21/21 11:58 PM, Douglas Gilbert wrote:
>>> On 2021-04-21 5:10 p.m., Bart Van Assche wrote:
>>>> On 4/21/21 10:47 AM, Hannes Reinecke wrote:
>>>>> +static inline bool scsi_result_is_good(struct scsi_cmnd *cmd)
>>>>> +{
>>>>> +    return (cmd->result == 0);
>>>>> +}
>>>>
>>>> Do we really need an inline function to compare an integer with zero? How 
>>>> about open-coding this comparison in the callers of this function?
>>>>
>>>
>>> Please don't open code it. Please fix it!
>>> Spot the difference:
>>>
>>> static inline int scsi_status_is_good(int status)
>>> {
>>>          /*
>>>           * FIXME: bit0 is listed as reserved in SCSI-2, but is
>>>           * significant in SCSI-3.  For now, we follow the SCSI-2
>>>           * behaviour and ignore reserved bits.
>>>           */
>>>          status &= 0xfe;
>>>          return ((status == SAM_STAT_GOOD) ||
>>>                  (status == SAM_STAT_CONDITION_MET) ||
>>> /*   >>>                   ^^^^^^^^^^^^^^^^^^^^^^ <<<        */
>>>                  /* Next two "intermediate" statuses are obsolete in SAM-4 */
>>>                  (status == SAM_STAT_INTERMEDIATE) ||
>>>                  (status == SAM_STAT_INTERMEDIATE_CONDITION_MET) ||
>>>                  /* FIXME: this is obsolete in SAM-3 */
>>>                  (status == SAM_STAT_COMMAND_TERMINATED));
>>> }
>>>
>>> In sg3_utils' library I ignore the last three SAM_STATs. Not sure if ignoring
>>> bit 0 is still required.
>>>
>>> Without considering SAM_STAT_CONDITION_MET a good status, someone will be
>>> scratching their head wondering why so many PRE-FETCH commands fail.
>>>
>>> That command can be used when a sequence of READs to consecutive LBAs is
>>> followed by a different (i.e. non-consecutive) READ. That last READ could
>>> be preceded by PRE-FETCH(new_LBA, IMMED). Assuming there is processing
>>> of the data from the consecutive LBAs to be done, when the time comes
>>> for READ(new_LBA) the probability of its data being in the disk's cache is
>>> increased.
>>>
>> That would be a change in behaviour.
>> Current code doesn't check for CONDITION_MET, so this change shouldn't do it, 
>> neither. Idea was that this patchset shouldn't change the current behaviour.
>>
>> While your argument might be valid, it definitely is a different story and 
>> would need to be address with a different patchset.
> 
> Okay. May I suggest a "FIX_ME" comment? And again, please don't open code it.
> 
> In driver manuals Seagate often list the PRE-FETCH command as optional. As
> in: pay us some extra money and we will put it in. That suggests to me some
> big OEM likes PRE-FETCH. Where I found it supported in WDC manuals, they
> didn't support the IMMED bit which sort of defeats the purpose of it IMO.

And PRE-FETCH has another (sneaky) use. You might think that when a LBA is
unmapped, then if its data is in the cache, it would be removed. So what
does SBC-4 say about reading unmapped LBAs (sbc4r22 4.7.4.4 table 10):
   "user data set to a vendor-specific value that is not obtained from
    any other LBA; and" (... place 0xff bytes in the PI)

Spot the weasel word: _other_ ! So it can read the former data in that
now unmapped LBA. So the second usage of PRE-FETCH is to prevent that.
Even more worryingly, it looks like PRE-FETCH may be needed after a
cryptographic erase (via the SANITIZE command)! SYNCHRONIZE CACHE only
talks about the write side of the cache, not removing stale read data.

Doug Gilbert






^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 14/42] scsi: add scsi_result_is_good()
  2021-04-22 15:56         ` Douglas Gilbert
  2021-04-22 16:51           ` Douglas Gilbert
@ 2021-04-22 16:52           ` Bart Van Assche
  2021-04-22 17:33             ` Douglas Gilbert
  1 sibling, 1 reply; 80+ messages in thread
From: Bart Van Assche @ 2021-04-22 16:52 UTC (permalink / raw)
  To: dgilbert, Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/22/21 8:56 AM, Douglas Gilbert wrote:
> In driver manuals Seagate often list the PRE-FETCH command as optional. As
> in: pay us some extra money and we will put it in. That suggests to me some
> big OEM likes PRE-FETCH. Where I found it supported in WDC manuals, they
> didn't support the IMMED bit which sort of defeats the purpose of it IMO.

Since the sd driver does not submit the PRE-FETCH command, how about
moving support for CONDITION MET into the sg code and treating CONDITION
MET as an error inside the sd, sr and st drivers? I think that would
allow to simplify scsi_status_is_good(). The current definition of that
function is as follows:

static inline int scsi_status_is_good(int status)
{
	/*
	 * FIXME: bit0 is listed as reserved in SCSI-2, but is
	 * significant in SCSI-3.  For now, we follow the SCSI-2
	 * behaviour and ignore reserved bits.
	 */
	status &= 0xfe;
	return ((status == SAM_STAT_GOOD) ||
		(status == SAM_STAT_CONDITION_MET) ||
		/* Next two "intermediate" statuses are obsolete in*/
		/* SAM-4 */
		(status == SAM_STAT_INTERMEDIATE) ||
		(status == SAM_STAT_INTERMEDIATE_CONDITION_MET) ||
		/* FIXME: this is obsolete in SAM-3 */
		(status == SAM_STAT_COMMAND_TERMINATED));
}

Thanks,

Bart.

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 14/42] scsi: add scsi_result_is_good()
  2021-04-22 16:52           ` Bart Van Assche
@ 2021-04-22 17:33             ` Douglas Gilbert
  2021-04-26  8:45               ` Hannes Reinecke
  0 siblings, 1 reply; 80+ messages in thread
From: Douglas Gilbert @ 2021-04-22 17:33 UTC (permalink / raw)
  To: Bart Van Assche, Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 2021-04-22 12:52 p.m., Bart Van Assche wrote:
> On 4/22/21 8:56 AM, Douglas Gilbert wrote:
>> In driver manuals Seagate often list the PRE-FETCH command as optional. As
>> in: pay us some extra money and we will put it in. That suggests to me some
>> big OEM likes PRE-FETCH. Where I found it supported in WDC manuals, they
>> didn't support the IMMED bit which sort of defeats the purpose of it IMO.
> 
> Since the sd driver does not submit the PRE-FETCH command, how about
> moving support for CONDITION MET into the sg code and treating CONDITION
> MET as an error inside the sd, sr and st drivers? I think that would
> allow to simplify scsi_status_is_good(). The current definition of that
> function is as follows:
> 
> static inline int scsi_status_is_good(int status)
> {
> 	/*
> 	 * FIXME: bit0 is listed as reserved in SCSI-2, but is
> 	 * significant in SCSI-3.  For now, we follow the SCSI-2
> 	 * behaviour and ignore reserved bits.
> 	 */
> 	status &= 0xfe;
> 	return ((status == SAM_STAT_GOOD) ||
> 		(status == SAM_STAT_CONDITION_MET) ||
> 		/* Next two "intermediate" statuses are obsolete in*/
> 		/* SAM-4 */
> 		(status == SAM_STAT_INTERMEDIATE) ||
> 		(status == SAM_STAT_INTERMEDIATE_CONDITION_MET) ||
> 		/* FIXME: this is obsolete in SAM-3 */
> 		(status == SAM_STAT_COMMAND_TERMINATED));
> }

The whole stack needs to treat SAM_STAT_CONDITION_MET as a non-error.
However the complex multi-layer return values are represented,
reducing them to a comparison with zero, spread all over the
stack just seems bad software engineering. IMO a predicate function
(i.e. returning bool) is needed.

I would argue that in the right circumstances, the sd driver should
indeed by using PRE-FETCH. It would need help from the upper layers.
It is essentially "read-ahead" in the case where the next LBA
does not follow the last read LBA. A smarter read-ahead ...

Doug Gilbert

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 15/42] NCR5380: use SCSI result accessors
  2021-04-22 16:10       ` Bart Van Assche
@ 2021-04-26  8:30         ` Hannes Reinecke
  0 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-26  8:30 UTC (permalink / raw)
  To: Bart Van Assche, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/22/21 6:10 PM, Bart Van Assche wrote:
> On 4/21/21 11:37 PM, Hannes Reinecke wrote:
>> On 4/21/21 11:11 PM, Bart Van Assche wrote:
>>> Do all SCSI devices from the nineties report SCSI status values with
>>> the lower bit set to 0? If so, can the status_byte() macro be removed
>>> entirely?
>>>
>> As indicated in the previous reply, yes, that is the plan (removing the
>> status_byte() macro). And the drivers will have to report SCSI status
>> values with the lower bit cleared, otherwise the linux SCSI status codes
>> would never have worked in the first place.
> 
> Please elaborate the above further. My understanding is that SCSI-2
> defines bits 0, 6 and 7 of the status byte as reserved while SAM-2
> specifies that these bits must be zero for the status codes that also
> have been defined in SCSI-2. Is it safe to assume that all SCSI-2
> devices set the reserved bits to zero?
> 
Yes. At least we haven't encountered any devices which do.
And are quite unlikely to find any new or unknown SCSI-2 devices, as the
market for SCSI parallel drives is _quite_ small :-)

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		        Kernel Storage Architect
hare@suse.de			               +49 911 74053 688
SUSE Software Solutions Germany GmbH, 90409 Nürnberg
GF: F. Imendörffer, HRB 36809 (AG Nürnberg)

^ permalink raw reply	[flat|nested] 80+ messages in thread

* Re: [PATCH 14/42] scsi: add scsi_result_is_good()
  2021-04-22 17:33             ` Douglas Gilbert
@ 2021-04-26  8:45               ` Hannes Reinecke
  0 siblings, 0 replies; 80+ messages in thread
From: Hannes Reinecke @ 2021-04-26  8:45 UTC (permalink / raw)
  To: dgilbert, Bart Van Assche, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, linux-scsi

On 4/22/21 7:33 PM, Douglas Gilbert wrote:
> On 2021-04-22 12:52 p.m., Bart Van Assche wrote:
>> On 4/22/21 8:56 AM, Douglas Gilbert wrote:
>>> In driver manuals Seagate often list the PRE-FETCH command as
>>> optional. As
>>> in: pay us some extra money and we will put it in. That suggests to
>>> me some
>>> big OEM likes PRE-FETCH. Where I found it supported in WDC manuals, they
>>> didn't support the IMMED bit which sort of defeats the purpose of it
>>> IMO.
>>
>> Since the sd driver does not submit the PRE-FETCH command, how about
>> moving support for CONDITION MET into the sg code and treating CONDITION
>> MET as an error inside the sd, sr and st drivers? I think that would
>> allow to simplify scsi_status_is_good(). The current definition of that
>> function is as follows:
>>
>> static inline int scsi_status_is_good(int status)
>> {
>>     /*
>>      * FIXME: bit0 is listed as reserved in SCSI-2, but is
>>      * significant in SCSI-3.  For now, we follow the SCSI-2
>>      * behaviour and ignore reserved bits.
>>      */
>>     status &= 0xfe;
>>     return ((status == SAM_STAT_GOOD) ||
>>         (status == SAM_STAT_CONDITION_MET) ||
>>         /* Next two "intermediate" statuses are obsolete in*/
>>         /* SAM-4 */
>>         (status == SAM_STAT_INTERMEDIATE) ||
>>         (status == SAM_STAT_INTERMEDIATE_CONDITION_MET) ||
>>         /* FIXME: this is obsolete in SAM-3 */
>>         (status == SAM_STAT_COMMAND_TERMINATED));
>> }
> 
> The whole stack needs to treat SAM_STAT_CONDITION_MET as a non-error.
> However the complex multi-layer return values are represented,
> reducing them to a comparison with zero, spread all over the
> stack just seems bad software engineering. IMO a predicate function
> (i.e. returning bool) is needed.
> 
> I would argue that in the right circumstances, the sd driver should
> indeed by using PRE-FETCH. It would need help from the upper layers.
> It is essentially "read-ahead" in the case where the next LBA
> does not follow the last read LBA. A smarter read-ahead ...
> 
Might, but again not something we should attempt in this patchset.

Using PRE-FETCH might be worthwhile for larger I/O, which we could
easily prepend with a PRE-FETCH command for the entire range.
But then error handling for PRE-FETCH is decidedly tricky, and we might
end up incurring quite some regressions just because we didn't get the
error handling right in the first go.

Worth a shot, but please in another patchset.

The other use-case for using PRE-FETCH after cryptographic erase
definitely is required, but as that's triggered by userspace I would
expect userspace to do it properly, too.

The only valid use-case I see would be for issuing PRE-FETCH after
UNMAP, but that would need to be plugged into the 'discard' machinery,
which is already fragile as hell; I'd rather not attempt that one.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		        Kernel Storage Architect
hare@suse.de			               +49 911 74053 688
SUSE Software Solutions Germany GmbH, 90409 Nürnberg
GF: F. Imendörffer, HRB 36809 (AG Nürnberg)

^ permalink raw reply	[flat|nested] 80+ messages in thread

end of thread, other threads:[~2021-04-26  8:46 UTC | newest]

Thread overview: 80+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-21 17:47 [RFC PATCH 00/42] SCSI result cleanup, part 2 Hannes Reinecke
2021-04-21 17:47 ` [PATCH 01/42] st: return error code in st_scsi_execute() Hannes Reinecke
2021-04-21 20:56   ` Bart Van Assche
2021-04-21 17:47 ` [PATCH 02/42] scsi_ioctl: return error code when blk_rq_map_kern() fails Hannes Reinecke
2021-04-21 21:01   ` Bart Van Assche
2021-04-22  6:29     ` Hannes Reinecke
2021-04-21 17:47 ` [PATCH 03/42] scsi_dh_alua: do not interpret DRIVER_ERROR Hannes Reinecke
2021-04-21 17:47 ` [PATCH 04/42] scsi: Fixup calling convention for scsi_mode_sense() Hannes Reinecke
2021-04-21 17:47 ` [PATCH 05/42] scsi: stop using DRIVER_ERROR Hannes Reinecke
2021-04-21 21:30   ` Bart Van Assche
2021-04-22  8:39     ` Hannes Reinecke
2021-04-21 17:47 ` [PATCH 06/42] scsi: introduce scsi_build_sense() Hannes Reinecke
2021-04-21 17:47 ` [PATCH 07/42] scsi: Kill DRIVER_SENSE Hannes Reinecke
2021-04-21 19:46   ` Douglas Gilbert
2021-04-21 20:07     ` Hannes Reinecke
2021-04-21 21:06   ` Bart Van Assche
2021-04-22  6:31     ` Hannes Reinecke
2021-04-22 15:46       ` Douglas Gilbert
2021-04-21 17:47 ` [PATCH 08/42] scsi: do not use DRIVER_INVALID Hannes Reinecke
2021-04-21 17:47 ` [PATCH 09/42] scsi_error: use DID_TIME_OUT instead of DRIVER_TIMEOUT Hannes Reinecke
2021-04-21 17:47 ` [PATCH 10/42] xen-scsiback: use DID_ERROR instead of DRIVER_ERROR Hannes Reinecke
2021-04-21 17:47 ` [PATCH 11/42] xen-scsifront: compability status handling Hannes Reinecke
2021-04-21 17:47 ` [PATCH 12/42] scsi: Drop the now obsolete driver_byte definitions Hannes Reinecke
2021-04-21 17:47 ` [PATCH 13/42] scsi: add get_{status,host}_byte() accessor function Hannes Reinecke
2021-04-21 21:09   ` Bart Van Assche
2021-04-22  6:33     ` Hannes Reinecke
2021-04-21 17:47 ` [PATCH 14/42] scsi: add scsi_result_is_good() Hannes Reinecke
2021-04-21 21:10   ` Bart Van Assche
2021-04-21 21:58     ` Douglas Gilbert
2021-04-22  8:42       ` Hannes Reinecke
2021-04-22  9:36         ` Finn Thain
2021-04-22 15:56         ` Douglas Gilbert
2021-04-22 16:51           ` Douglas Gilbert
2021-04-22 16:52           ` Bart Van Assche
2021-04-22 17:33             ` Douglas Gilbert
2021-04-26  8:45               ` Hannes Reinecke
2021-04-22  6:34     ` Hannes Reinecke
2021-04-21 17:47 ` [PATCH 15/42] NCR5380: use SCSI result accessors Hannes Reinecke
2021-04-21 21:11   ` Bart Van Assche
2021-04-22  6:37     ` Hannes Reinecke
2021-04-22 16:10       ` Bart Van Assche
2021-04-26  8:30         ` Hannes Reinecke
2021-04-22  9:36   ` Finn Thain
2021-04-21 17:47 ` [PATCH 16/42] NCR5380: Fold SCSI message ABORT onto DID_ABORT Hannes Reinecke
2021-04-22  9:35   ` Finn Thain
2021-04-21 17:47 ` [PATCH 17/42] scsi: add translate_msg_byte() Hannes Reinecke
2021-04-21 17:47 ` [PATCH 18/42] dc395: use standard macros to set SCSI result Hannes Reinecke
2021-04-21 22:26   ` Bart Van Assche
2021-04-22  8:52     ` Hannes Reinecke
2021-04-22 16:12       ` Bart Van Assche
2021-04-21 17:47 ` [PATCH 19/42] dc395: translate message bytes Hannes Reinecke
2021-04-21 17:47 ` [PATCH 20/42] qlogicfas408: make ql_pcmd() a void function Hannes Reinecke
2021-04-21 17:47 ` [PATCH 21/42] qlogicfas408: whitespace cleanup Hannes Reinecke
2021-04-21 17:47 ` [PATCH 22/42] qlogicfas408: translate message to host byte status Hannes Reinecke
2021-04-21 17:47 ` [PATCH 23/42] nsp32: use standard macros to set SCSI result Hannes Reinecke
2021-04-21 17:47 ` [PATCH 24/42] nsp32: whitespace cleanup Hannes Reinecke
2021-04-21 17:47 ` [PATCH 25/42] nsp32: do not set message byte Hannes Reinecke
2021-04-21 17:47 ` [PATCH 26/42] wd33c93: use standard macros to set SCSI result Hannes Reinecke
2021-04-21 17:47 ` [PATCH 27/42] wd33c93: translate message byte to host byte Hannes Reinecke
2021-04-21 17:47 ` [PATCH 28/42] mesh: use standard macros to set SCSI result Hannes Reinecke
2021-04-21 17:47 ` [PATCH 29/42] mesh: translate message to host byte status Hannes Reinecke
2021-04-21 17:47 ` [PATCH 30/42] acornscsi: use standard macros to set SCSI result Hannes Reinecke
2021-04-21 17:47 ` [PATCH 31/42] acornscsi: remove acornscsi_reportstatus() Hannes Reinecke
2021-04-21 17:47 ` [PATCH 32/42] acornscsi: translate message byte to host byte Hannes Reinecke
2021-04-21 17:47 ` [PATCH 33/42] aha152x: modify done() to use separate status bytes Hannes Reinecke
2021-04-21 17:47 ` [PATCH 34/42] aha152x: do not set message byte when calling scsi_done() Hannes Reinecke
2021-04-21 17:47 ` [PATCH 35/42] advansys: do not set message byte in SCSI status Hannes Reinecke
2021-04-21 17:47 ` [PATCH 36/42] advansys: use SCSI result accessors Hannes Reinecke
2021-04-21 17:47 ` [PATCH 37/42] fas216: translate message to host byte status Hannes Reinecke
2021-04-21 17:47 ` [PATCH 38/42] fas216: convert to SCSI Accessors Hannes Reinecke
2021-04-21 17:47 ` [PATCH 39/42] fdomain: drop last argument to fdomain_finish_cmd() Hannes Reinecke
2021-04-21 17:47 ` [PATCH 40/42] fdomain: translate message to host byte status Hannes Reinecke
2021-04-21 17:47 ` [PATCH 41/42] scsi: drop message byte helper Hannes Reinecke
2021-04-21 21:14   ` Bart Van Assche
2021-04-22  6:37     ` Hannes Reinecke
2021-04-21 17:47 ` [PATCH 42/42] scsi: kill message byte Hannes Reinecke
2021-04-21 20:54 ` [RFC PATCH 00/42] SCSI result cleanup, part 2 Bart Van Assche
2021-04-21 22:26 ` Bart Van Assche
2021-04-22  8:49   ` Hannes Reinecke
2021-04-22 16:28     ` Bart Van Assche

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.