All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC 00/24] scsi: Revamp result values
@ 2019-10-21  9:52 Hannes Reinecke
  2019-10-21  9:52 ` [PATCH 01/24] aic7xxx,aic79xxx: remove driver-defined SAM status definitions Hannes Reinecke
                   ` (24 more replies)
  0 siblings, 25 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:52 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	linux-scsi, Hannes Reinecke

Hi all,

the 'result' field in the SCSI command is defined as having
4 fields. The top byte is declared as a 'driver_byte', where the
driver can signal some internal status back to the midlayer.
However, there is quite a bit of overlap between the driver_byte
and the host_byte, resulting in the driver_byte being used in
very few places, and mostly in legacy drivers.
Additionally, we have _two_ sets of definitions for the
last byte (status byte), which can specified either in SAM terms
or in the linux-specific terms, which are shifted right by one
from the SAM ones.
Needless to say, the linux-specific ones are declared obsolete
for years now.
And to make the confusion complete, both the status byte and
the driver byte have a byte for a valid sense code, resulting
in quite some confusion which of those bits to check.

This patchset does several things:
- remove the linux-specific status byte definitions, and use
  the SAM values throughout
- replace the driver-byte values with either SAM ones (for sense
  code checking) or host-byte definitions
- remove the driver-byte definitions

As usual, comments and reviews are welcome.

Please note, commit 66cf50e65b18 ("scsi: qla2xxx: fixup incorrect
usage of host_byte") from 5.4/scsi-fixes is a prerequisite for
this patch series.

Hannes Reinecke (24):
  aic7xxx,aic79xxx: remove driver-defined SAM status definitions
  bfa: drop driver-defined SCSI status codes
  wd33c93: use SCSI status
  acornscsi: use standard defines
  scsi: use standard SAM status codes
  scsi: change status_byte() to return the standard SCSI status
  target_core: Fixup target_complete_cmd() usage
  sg: use SAM status definitions and avoid using masked_status
  scsi: Kill obsolete linux-specific status codes
  scsi: introduce set_status_byte()
  advansys: kill driver_defined status byte accessors
  scsi: introduce scsi_build_sense()
  scsi: Kill DRIVER_SENSE
  scsi: Kill DRIVER_HARD
  scsi_error: use DID_TIME_OUT instead of DRIVER_TIMEOUT
  scsi: Kill DRIVER_TIMEOUT
  scsi: do not use DRIVER_INVALID
  st: return error code in st_scsi_execute()
  scsi_ioctl: return error code when blk_map_user() fails
  scsi_dh_alua: do not interpret DRIVER_ERROR
  xen-scsiback: stop using DRIVER_ERROR
  scsi: stop using DRIVER_ERROR
  scsi: Kill DRIVER_MEDIA, DRIVER_SOFT, and DRIVER_BUSY
  scsi: Drop now obsolete driver_byte definitions

 Documentation/scsi/scsi_mid_low_api.txt     |  3 +-
 block/bsg-lib.c                             |  2 +-
 block/bsg.c                                 |  2 +-
 block/scsi_ioctl.c                          |  9 ++--
 drivers/ata/libata-scsi.c                   | 22 +++-----
 drivers/infiniband/ulp/srp/ib_srp.c         |  2 +-
 drivers/message/fusion/mptscsih.c           |  2 +-
 drivers/s390/scsi/zfcp_scsi.c               |  5 +-
 drivers/scsi/3w-9xxx.c                      |  5 +-
 drivers/scsi/3w-sas.c                       |  3 +-
 drivers/scsi/3w-xxxx.c                      |  7 ++-
 drivers/scsi/53c700.c                       |  6 +--
 drivers/scsi/NCR5380.c                      |  4 +-
 drivers/scsi/advansys.c                     | 78 ++++++++---------------------
 drivers/scsi/aic7xxx/aic79xx_core.c         |  8 +--
 drivers/scsi/aic7xxx/aic79xx_osm.c          | 35 ++++++-------
 drivers/scsi/aic7xxx/aic7xxx_core.c         |  6 +--
 drivers/scsi/aic7xxx/aic7xxx_osm.c          | 13 +++--
 drivers/scsi/aic7xxx/aiclib.h               | 15 ------
 drivers/scsi/arcmsr/arcmsr_hba.c            |  5 +-
 drivers/scsi/arm/acornscsi.c                | 24 +++------
 drivers/scsi/arm/fas216.c                   | 10 ++--
 drivers/scsi/bfa/bfa_fc.h                   | 15 ------
 drivers/scsi/bfa/bfa_fcpim.c                |  2 +-
 drivers/scsi/bfa/bfad_im.c                  |  4 +-
 drivers/scsi/ch.c                           |  5 +-
 drivers/scsi/constants.c                    | 15 ------
 drivers/scsi/cxlflash/superpipe.c           | 45 ++++++++---------
 drivers/scsi/dc395x.c                       | 26 +++-------
 drivers/scsi/device_handler/scsi_dh_alua.c  |  4 --
 drivers/scsi/dpt_i2o.c                      |  2 +-
 drivers/scsi/esp_scsi.c                     |  3 +-
 drivers/scsi/gdth.c                         | 12 ++---
 drivers/scsi/hptiop.c                       |  2 +-
 drivers/scsi/libiscsi.c                     |  5 +-
 drivers/scsi/lpfc/lpfc_scsi.c               | 30 +++--------
 drivers/scsi/megaraid.c                     | 22 ++++----
 drivers/scsi/megaraid/megaraid_mbox.c       | 22 ++++----
 drivers/scsi/megaraid/megaraid_sas_base.c   |  3 +-
 drivers/scsi/megaraid/megaraid_sas_fusion.c |  1 -
 drivers/scsi/mpt3sas/mpt3sas_scsih.c        |  8 +--
 drivers/scsi/mvumi.c                        | 16 +++---
 drivers/scsi/myrb.c                         | 61 ++++++----------------
 drivers/scsi/myrs.c                         |  9 +---
 drivers/scsi/ps3rom.c                       |  3 +-
 drivers/scsi/qla2xxx/qla_isr.c              | 15 ++----
 drivers/scsi/scsi.c                         |  8 +--
 drivers/scsi/scsi_debug.c                   | 15 +++---
 drivers/scsi/scsi_error.c                   | 52 +++++++++----------
 drivers/scsi/scsi_ioctl.c                   |  2 +-
 drivers/scsi/scsi_lib.c                     | 44 +++++++++++-----
 drivers/scsi/scsi_logging.c                 | 10 +---
 drivers/scsi/scsi_scan.c                    |  2 +-
 drivers/scsi/scsi_transport_spi.c           |  2 +-
 drivers/scsi/sd.c                           | 42 ++++++++--------
 drivers/scsi/sd_zbc.c                       |  4 +-
 drivers/scsi/sg.c                           | 25 ++++-----
 drivers/scsi/smartpqi/smartpqi_init.c       |  3 +-
 drivers/scsi/sr.c                           |  2 +-
 drivers/scsi/sr_ioctl.c                     |  2 +-
 drivers/scsi/st.c                           |  8 +--
 drivers/scsi/stex.c                         |  9 ++--
 drivers/scsi/sym53c8xx_2/sym_glue.c         |  6 +--
 drivers/scsi/ufs/ufshcd.c                   |  6 +--
 drivers/scsi/virtio_scsi.c                  |  3 +-
 drivers/scsi/vmw_pvscsi.c                   | 21 ++++----
 drivers/scsi/wd33c93.c                      | 21 +++-----
 drivers/target/loopback/tcm_loop.c          |  1 -
 drivers/target/target_core_alua.c           |  6 +--
 drivers/target/target_core_iblock.c         |  2 +-
 drivers/target/target_core_pr.c             |  8 +--
 drivers/target/target_core_sbc.c            | 10 ++--
 drivers/target/target_core_spc.c            | 14 +++---
 drivers/target/target_core_xcopy.c          |  2 +-
 drivers/usb/storage/cypress_atacb.c         |  4 +-
 drivers/xen/xen-scsiback.c                  | 12 ++---
 include/scsi/scsi.h                         | 19 +------
 include/scsi/scsi_cmnd.h                    | 12 +++--
 include/scsi/scsi_proto.h                   | 19 -------
 include/scsi/sg.h                           |  3 +-
 include/trace/events/scsi.h                 | 15 +-----
 81 files changed, 371 insertions(+), 639 deletions(-)

-- 
2.16.4


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

* [PATCH 01/24] aic7xxx,aic79xxx: remove driver-defined SAM status definitions
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
@ 2019-10-21  9:52 ` Hannes Reinecke
  2019-10-21  9:53 ` [PATCH 02/24] bfa: drop driver-defined SCSI status codes Hannes Reinecke
                   ` (23 subsequent siblings)
  24 siblings, 0 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:52 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	linux-scsi, Hannes Reinecke

Replace the driver-defined SAM status definitions with the
standard mid-layer defined ones.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/aic7xxx/aic79xx_core.c |  8 ++++----
 drivers/scsi/aic7xxx/aic79xx_osm.c  | 16 ++++++++--------
 drivers/scsi/aic7xxx/aic7xxx_core.c |  6 +++---
 drivers/scsi/aic7xxx/aic7xxx_osm.c  | 12 ++++++------
 drivers/scsi/aic7xxx/aiclib.h       | 15 ---------------
 5 files changed, 21 insertions(+), 36 deletions(-)

diff --git a/drivers/scsi/aic7xxx/aic79xx_core.c b/drivers/scsi/aic7xxx/aic79xx_core.c
index 7e5044bf05c0..03a9abc7d959 100644
--- a/drivers/scsi/aic7xxx/aic79xx_core.c
+++ b/drivers/scsi/aic7xxx/aic79xx_core.c
@@ -8955,7 +8955,7 @@ ahd_handle_scsi_status(struct ahd_softc *ahd, struct scb *scb)
 					break;
 				}
 			}
-			if (siu->status == SCSI_STATUS_OK)
+			if (siu->status == SAM_STAT_GOOD)
 				ahd_set_transaction_status(scb,
 							   CAM_REQ_CMP_ERR);
 		}
@@ -8969,8 +8969,8 @@ ahd_handle_scsi_status(struct ahd_softc *ahd, struct scb *scb)
 		ahd_done(ahd, scb);
 		break;
 	}
-	case SCSI_STATUS_CMD_TERMINATED:
-	case SCSI_STATUS_CHECK_COND:
+	case SAM_STAT_COMMAND_TERMINATED:
+	case SAM_STAT_CHECK_CONDITION:
 	{
 		struct ahd_devinfo devinfo;
 		struct ahd_dma_seg *sg;
@@ -9060,7 +9060,7 @@ ahd_handle_scsi_status(struct ahd_softc *ahd, struct scb *scb)
 		ahd_queue_scb(ahd, scb);
 		break;
 	}
-	case SCSI_STATUS_OK:
+	case SAM_STAT_GOOD:
 		printk("%s: Interrupted for status of 0???\n",
 		       ahd_name(ahd));
 		/* FALLTHROUGH */
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c
index 57992519384e..72c67e89b911 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.c
@@ -1846,7 +1846,7 @@ ahd_done(struct ahd_softc *ahd, struct scb *scb)
 
 	if (dev->openings == 1
 	 && ahd_get_transaction_status(scb) == CAM_REQ_CMP
-	 && ahd_get_scsi_status(scb) != SCSI_STATUS_QUEUE_FULL)
+	 && ahd_get_scsi_status(scb) != SAM_STAT_TASK_SET_FULL)
 		dev->tag_success_count++;
 	/*
 	 * Some devices deal with temporary internal resource
@@ -1903,8 +1903,8 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
 	switch (ahd_get_scsi_status(scb)) {
 	default:
 		break;
-	case SCSI_STATUS_CHECK_COND:
-	case SCSI_STATUS_CMD_TERMINATED:
+	case SAM_STAT_CHECK_CONDITION:
+	case SAM_STAT_COMMAND_TERMINATED:
 	{
 		struct scsi_cmnd *cmd;
 
@@ -1959,7 +1959,7 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
 		}
 		break;
 	}
-	case SCSI_STATUS_QUEUE_FULL:
+	case SAM_STAT_TASK_SET_FULL:
 		/*
 		 * By the time the core driver has returned this
 		 * command, all other commands that were queued
@@ -2005,7 +2005,7 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
 				dev->last_queuefull_same_count = 0;
 			}
 			ahd_set_transaction_status(scb, CAM_REQUEUE_REQ);
-			ahd_set_scsi_status(scb, SCSI_STATUS_OK);
+			ahd_set_scsi_status(scb, SAM_STAT_GOOD);
 			ahd_platform_set_tags(ahd, sdev, &devinfo,
 				     (dev->flags & AHD_DEV_Q_BASIC)
 				   ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED);
@@ -2019,7 +2019,7 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
 		ahd_platform_set_tags(ahd, sdev, &devinfo,
 			     (dev->flags & AHD_DEV_Q_BASIC)
 			   ? AHD_QUEUE_BASIC : AHD_QUEUE_TAGGED);
-		ahd_set_scsi_status(scb, SCSI_STATUS_BUSY);
+		ahd_set_scsi_status(scb, SAM_STAT_BUSY);
 	}
 }
 
@@ -2051,8 +2051,8 @@ ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, struct scsi_cmnd *cmd)
 		scsi_status = ahd_cmd_get_scsi_status(cmd);
 
 		switch(scsi_status) {
-		case SCSI_STATUS_CMD_TERMINATED:
-		case SCSI_STATUS_CHECK_COND:
+		case SAM_STAT_COMMAND_TERMINATED:
+		case SAM_STAT_CHECK_CONDITION:
 			if ((cmd->result >> 24) != DRIVER_SENSE) {
 				do_fallback = 1;
 			} else {
diff --git a/drivers/scsi/aic7xxx/aic7xxx_core.c b/drivers/scsi/aic7xxx/aic7xxx_core.c
index a9d40d3b90ef..c8d237ccb70d 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_core.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_core.c
@@ -1041,12 +1041,12 @@ ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat)
 		ahc_freeze_scb(scb);
 		ahc_set_scsi_status(scb, hscb->shared_data.status.scsi_status);
 		switch (hscb->shared_data.status.scsi_status) {
-		case SCSI_STATUS_OK:
+		case SAM_STAT_GOOD:
 			printk("%s: Interrupted for status of 0???\n",
 			       ahc_name(ahc));
 			break;
-		case SCSI_STATUS_CMD_TERMINATED:
-		case SCSI_STATUS_CHECK_COND:
+		case SAM_STAT_COMMAND_TERMINATED:
+		case SAM_STAT_CHECK_CONDITION:
 		{
 			struct ahc_dma_seg *sg;
 			struct scsi_sense *sc;
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c
index d5c4a0d23706..a0b444e6209d 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c
@@ -1775,7 +1775,7 @@ ahc_done(struct ahc_softc *ahc, struct scb *scb)
 
 	if (dev->openings == 1
 	 && ahc_get_transaction_status(scb) == CAM_REQ_CMP
-	 && ahc_get_scsi_status(scb) != SCSI_STATUS_QUEUE_FULL)
+	 && ahc_get_scsi_status(scb) != SAM_STAT_TASK_SET_FULL)
 		dev->tag_success_count++;
 	/*
 	 * Some devices deal with temporary internal resource
@@ -1832,8 +1832,8 @@ ahc_linux_handle_scsi_status(struct ahc_softc *ahc,
 	switch (ahc_get_scsi_status(scb)) {
 	default:
 		break;
-	case SCSI_STATUS_CHECK_COND:
-	case SCSI_STATUS_CMD_TERMINATED:
+	case SAM_STAT_CHECK_CONDITION:
+	case SAM_STAT_COMMAND_TERMINATED:
 	{
 		struct scsi_cmnd *cmd;
 
@@ -1871,7 +1871,7 @@ ahc_linux_handle_scsi_status(struct ahc_softc *ahc,
 		}
 		break;
 	}
-	case SCSI_STATUS_QUEUE_FULL:
+	case SAM_STAT_TASK_SET_FULL:
 	{
 		/*
 		 * By the time the core driver has returned this
@@ -1915,7 +1915,7 @@ ahc_linux_handle_scsi_status(struct ahc_softc *ahc,
 				dev->last_queuefull_same_count = 0;
 			}
 			ahc_set_transaction_status(scb, CAM_REQUEUE_REQ);
-			ahc_set_scsi_status(scb, SCSI_STATUS_OK);
+			ahc_set_scsi_status(scb, SAM_STAT_GOOD);
 			ahc_platform_set_tags(ahc, sdev, &devinfo,
 				     (dev->flags & AHC_DEV_Q_BASIC)
 				   ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED);
@@ -1926,7 +1926,7 @@ ahc_linux_handle_scsi_status(struct ahc_softc *ahc,
 		 * as if the target returned BUSY SCSI status.
 		 */
 		dev->openings = 1;
-		ahc_set_scsi_status(scb, SCSI_STATUS_BUSY);
+		ahc_set_scsi_status(scb, SAM_STAT_BUSY);
 		ahc_platform_set_tags(ahc, sdev, &devinfo,
 			     (dev->flags & AHC_DEV_Q_BASIC)
 			   ? AHC_QUEUE_BASIC : AHC_QUEUE_TAGGED);
diff --git a/drivers/scsi/aic7xxx/aiclib.h b/drivers/scsi/aic7xxx/aiclib.h
index f8fd198aafbc..ba08eb3c4e3b 100644
--- a/drivers/scsi/aic7xxx/aiclib.h
+++ b/drivers/scsi/aic7xxx/aiclib.h
@@ -117,21 +117,6 @@ struct scsi_sense_data
 #define SSD_FULL_SIZE sizeof(struct scsi_sense_data)
 };
 
-/*
- * Status Byte
- */
-#define	SCSI_STATUS_OK			0x00
-#define	SCSI_STATUS_CHECK_COND		0x02
-#define	SCSI_STATUS_COND_MET		0x04
-#define	SCSI_STATUS_BUSY		0x08
-#define SCSI_STATUS_INTERMED		0x10
-#define SCSI_STATUS_INTERMED_COND_MET	0x14
-#define SCSI_STATUS_RESERV_CONFLICT	0x18
-#define SCSI_STATUS_CMD_TERMINATED	0x22	/* Obsolete in SAM-2 */
-#define SCSI_STATUS_QUEUE_FULL		0x28
-#define SCSI_STATUS_ACA_ACTIVE		0x30
-#define SCSI_STATUS_TASK_ABORTED	0x40
-
 /************************* Large Disk Handling ********************************/
 static inline int
 aic_sector_div(sector_t capacity, int heads, int sectors)
-- 
2.16.4


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

* [PATCH 02/24] bfa: drop driver-defined SCSI status codes
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
  2019-10-21  9:52 ` [PATCH 01/24] aic7xxx,aic79xxx: remove driver-defined SAM status definitions Hannes Reinecke
@ 2019-10-21  9:53 ` Hannes Reinecke
  2019-10-21  9:53 ` [PATCH 03/24] wd33c93: use SCSI status Hannes Reinecke
                   ` (22 subsequent siblings)
  24 siblings, 0 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:53 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	linux-scsi, Hannes Reinecke

Drop the driver-defined SCSI status code and use the generic ones
instead.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/bfa/bfa_fc.h    | 15 ---------------
 drivers/scsi/bfa/bfa_fcpim.c |  2 +-
 drivers/scsi/bfa/bfad_im.c   |  2 +-
 3 files changed, 2 insertions(+), 17 deletions(-)

diff --git a/drivers/scsi/bfa/bfa_fc.h b/drivers/scsi/bfa/bfa_fc.h
index b00fb2409c50..d536270bbe9f 100644
--- a/drivers/scsi/bfa/bfa_fc.h
+++ b/drivers/scsi/bfa/bfa_fc.h
@@ -33,21 +33,6 @@ struct scsi_cdb_s {
 	u8         scsi_cdb[SCSI_MAX_CDBLEN];
 };
 
-/* ------------------------------------------------------------
- * SCSI status byte values
- * ------------------------------------------------------------
- */
-#define SCSI_STATUS_GOOD                   0x00
-#define SCSI_STATUS_CHECK_CONDITION        0x02
-#define SCSI_STATUS_CONDITION_MET          0x04
-#define SCSI_STATUS_BUSY                   0x08
-#define SCSI_STATUS_INTERMEDIATE           0x10
-#define SCSI_STATUS_ICM                    0x14 /* intermediate condition met */
-#define SCSI_STATUS_RESERVATION_CONFLICT   0x18
-#define SCSI_STATUS_COMMAND_TERMINATED     0x22
-#define SCSI_STATUS_QUEUE_FULL             0x28
-#define SCSI_STATUS_ACA_ACTIVE             0x30
-
 #define SCSI_MAX_ALLOC_LEN      0xFF    /* maximum allocarion length */
 
 /*
diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
index 284baa3b0c8e..997b54f5eb5c 100644
--- a/drivers/scsi/bfa/bfa_fcpim.c
+++ b/drivers/scsi/bfa/bfa_fcpim.c
@@ -2146,7 +2146,7 @@ __bfa_cb_ioim_comp(void *cbarg, bfa_boolean_t complete)
 		/*
 		 * setup sense information, if present
 		 */
-		if ((m->scsi_status == SCSI_STATUS_CHECK_CONDITION) &&
+		if ((m->scsi_status == SAM_STAT_CHECK_CONDITION) &&
 					m->sns_len) {
 			sns_len = m->sns_len;
 			snsinfo = BFA_SNSINFO_FROM_TAG(ioim->fcpim->fcp,
diff --git a/drivers/scsi/bfa/bfad_im.c b/drivers/scsi/bfa/bfad_im.c
index 22f06be2606f..6b5841b1c06e 100644
--- a/drivers/scsi/bfa/bfad_im.c
+++ b/drivers/scsi/bfa/bfad_im.c
@@ -106,7 +106,7 @@ bfa_cb_ioim_good_comp(void *drv, struct bfad_ioim_s *dio)
 	struct bfad_itnim_data_s *itnim_data;
 	struct bfad_itnim_s *itnim;
 
-	cmnd->result = DID_OK << 16 | SCSI_STATUS_GOOD;
+	cmnd->result = DID_OK << 16 | SAM_STAT_GOOD;
 
 	/* Unmap DMA, if host is NULL, it means a scsi passthru cmd */
 	if (cmnd->device->host != NULL)
-- 
2.16.4


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

* [PATCH 03/24] wd33c93: use SCSI status
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
  2019-10-21  9:52 ` [PATCH 01/24] aic7xxx,aic79xxx: remove driver-defined SAM status definitions Hannes Reinecke
  2019-10-21  9:53 ` [PATCH 02/24] bfa: drop driver-defined SCSI status codes Hannes Reinecke
@ 2019-10-21  9:53 ` Hannes Reinecke
  2019-10-21 18:41     ` kbuild test robot
  2019-10-21 23:16   ` Finn Thain
  2019-10-21  9:53 ` [PATCH 04/24] acornscsi: use standard defines Hannes Reinecke
                   ` (21 subsequent siblings)
  24 siblings, 2 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:53 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	linux-scsi, Hannes Reinecke

Use standard SCSI status and drop usage of the linux-specific ones.

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

diff --git a/drivers/scsi/wd33c93.c b/drivers/scsi/wd33c93.c
index f81046f0e68a..98e04a7b9d63 100644
--- a/drivers/scsi/wd33c93.c
+++ b/drivers/scsi/wd33c93.c
@@ -1176,10 +1176,8 @@ wd33c93_intr(struct Scsi_Host *instance)
 			if (cmd->SCp.Status == ILLEGAL_STATUS_BYTE)
 				cmd->SCp.Status = lun;
 			if (cmd->cmnd[0] == REQUEST_SENSE
-			    && cmd->SCp.Status != GOOD)
-				cmd->result =
-				    (cmd->
-				     result & 0x00ffff) | (DID_ERROR << 16);
+			    && cmd->SCp.Status != SAM_STAT_GOOD)
+				set_host_byte(cmd, DID_ERROR);
 			else
 				cmd->result =
 				    cmd->SCp.Status | (cmd->SCp.Message << 8);
@@ -1262,9 +1260,8 @@ 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 != GOOD)
-			cmd->result =
-			    (cmd->result & 0x00ffff) | (DID_ERROR << 16);
+		if (cmd->cmnd[0] == REQUEST_SENSE && cmd->SCp.Status != SAM_STAT_GOOD)
+			set_host_byte(cmd, DID_ERROR);
 		else
 			cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
 		cmd->scsi_done(cmd);
@@ -1294,12 +1291,10 @@ wd33c93_intr(struct Scsi_Host *instance)
 			hostdata->connected = NULL;
 			hostdata->busy[cmd->device->id] &= ~(1 << (cmd->device->lun & 0xff));
 			hostdata->state = S_UNCONNECTED;
-			DB(DB_INTR, printk(":%d", cmd->SCp.Status))
-			    if (cmd->cmnd[0] == REQUEST_SENSE
-				&& cmd->SCp.Status != GOOD)
-				cmd->result =
-				    (cmd->
-				     result & 0x00ffff) | (DID_ERROR << 16);
+			DB(DB_INTR, printk(":%d", cmd->SCp.Status));
+			if (cmd->cmnd[0] == REQUEST_SENSE
+			    && cmd->SCp.Status != SAM_STAT_GOOD)
+				set_host_byte(cmd->result, DID_ERROR);
 			else
 				cmd->result =
 				    cmd->SCp.Status | (cmd->SCp.Message << 8);
-- 
2.16.4


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

* [PATCH 04/24] acornscsi: use standard defines
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
                   ` (2 preceding siblings ...)
  2019-10-21  9:53 ` [PATCH 03/24] wd33c93: use SCSI status Hannes Reinecke
@ 2019-10-21  9:53 ` Hannes Reinecke
  2019-10-21  9:53 ` [PATCH 05/24] scsi: use standard SAM status codes Hannes Reinecke
                   ` (20 subsequent siblings)
  24 siblings, 0 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:53 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	linux-scsi, Hannes Reinecke

Use midlayer-defined values and drop the non-existing QUEUE_FULL
case.

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

diff --git a/drivers/scsi/arm/acornscsi.c b/drivers/scsi/arm/acornscsi.c
index d12dd89538df..7e69e481ccac 100644
--- a/drivers/scsi/arm/acornscsi.c
+++ b/drivers/scsi/arm/acornscsi.c
@@ -144,12 +144,6 @@
 #define VER_MINOR 0
 #define VER_PATCH 6
 
-#ifndef ABORT_TAG
-#define ABORT_TAG 0xd
-#else
-#error "Yippee!  ABORT TAG is now defined!  Remove this error!"
-#endif
-
 #ifdef USE_DMAC
 /*
  * DMAC setup parameters
@@ -1490,8 +1484,8 @@ void acornscsi_message(AS_Host *host)
     }
 
     switch (message[0]) {
-    case ABORT:
-    case ABORT_TAG:
+    case ABORT_TASK_SET:
+    case ABORT_TASK:
     case COMMAND_COMPLETE:
 	if (host->scsi.phase != PHASE_STATUSIN) {
 	    printk(KERN_ERR "scsi%d.%c: command complete following non-status in phase?\n",
@@ -1596,10 +1590,6 @@ void acornscsi_message(AS_Host *host)
 	}
 	break;
 
-    case QUEUE_FULL:
-	/* TODO: target queue is full */
-	break;
-
     case SIMPLE_QUEUE_TAG:
 	/* tag queue reconnect... message[1] = queue tag.  Print something to indicate something happened! */
 	printk("scsi%d.%c: reconnect queue tag %02X\n",
-- 
2.16.4


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

* [PATCH 05/24] scsi: use standard SAM status codes
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
                   ` (3 preceding siblings ...)
  2019-10-21  9:53 ` [PATCH 04/24] acornscsi: use standard defines Hannes Reinecke
@ 2019-10-21  9:53 ` Hannes Reinecke
  2019-10-21 23:17   ` Finn Thain
  2019-10-21  9:53 ` [PATCH 06/24] scsi: change status_byte() to return the standard SCSI status Hannes Reinecke
                   ` (19 subsequent siblings)
  24 siblings, 1 reply; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:53 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	linux-scsi, Hannes Reinecke

Use standard SAM status codes and omit the explicit shift to convert
to linus-specific ones.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/ata/libata-scsi.c             |  2 +-
 drivers/infiniband/ulp/srp/ib_srp.c   |  2 +-
 drivers/scsi/3w-9xxx.c                |  5 +++--
 drivers/scsi/3w-sas.c                 |  3 ++-
 drivers/scsi/3w-xxxx.c                |  4 ++--
 drivers/scsi/arcmsr/arcmsr_hba.c      |  4 ++--
 drivers/scsi/bfa/bfad_im.c            |  2 +-
 drivers/scsi/dc395x.c                 | 18 +++++-------------
 drivers/scsi/dpt_i2o.c                |  2 +-
 drivers/scsi/gdth.c                   | 12 ++++++------
 drivers/scsi/megaraid.c               | 10 +++++-----
 drivers/scsi/megaraid/megaraid_mbox.c | 12 ++++++------
 12 files changed, 35 insertions(+), 41 deletions(-)

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 76d0f9de767b..b197d2fbe3f8 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -856,7 +856,7 @@ static struct ata_queued_cmd *ata_scsi_qc_new(struct ata_device *dev,
 		if (cmd->request->rq_flags & RQF_QUIET)
 			qc->flags |= ATA_QCFLAG_QUIET;
 	} else {
-		cmd->result = (DID_OK << 16) | (QUEUE_FULL << 1);
+		cmd->result = (DID_OK << 16) | SAM_STAT_TASK_SET_FULL;
 		cmd->scsi_done(cmd);
 	}
 
diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index b5960351bec0..4570e3c79ea5 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -2404,7 +2404,7 @@ static int srp_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd)
 		 * to reduce queue depth temporarily.
 		 */
 		scmnd->result = len == -ENOMEM ?
-			DID_OK << 16 | QUEUE_FULL << 1 : DID_ERROR << 16;
+			DID_OK << 16 | SAM_STAT_TASK_SET_FULL : DID_ERROR << 16;
 		goto err_iu;
 	}
 
diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index 3337b1e80412..ada77c136f8b 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -1018,7 +1018,8 @@ static int twa_fill_sense(TW_Device_Extension *tw_dev, int request_id, int copy_
 
 	if (copy_sense) {
 		memcpy(tw_dev->srb[request_id]->sense_buffer, full_command_packet->header.sense_data, TW_SENSE_DATA_LENGTH);
-		tw_dev->srb[request_id]->result = (full_command_packet->command.newcommand.status << 1);
+		tw_dev->srb[request_id]->result =
+			full_command_packet->command.newcommand.status;
 		retval = TW_ISR_DONT_RESULT;
 		goto out;
 	}
@@ -1342,7 +1343,7 @@ static irqreturn_t twa_interrupt(int irq, void *dev_instance)
 				/* If error, command failed */
 				if (error == 1) {
 					/* Ask for a host reset */
-					cmd->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
+					cmd->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
 				}
 
 				/* Report residual bytes for single sgl */
diff --git a/drivers/scsi/3w-sas.c b/drivers/scsi/3w-sas.c
index dda6fa857709..d11f62c60877 100644
--- a/drivers/scsi/3w-sas.c
+++ b/drivers/scsi/3w-sas.c
@@ -891,7 +891,8 @@ static int twl_fill_sense(TW_Device_Extension *tw_dev, int i, int request_id, in
 
 	if (copy_sense) {
 		memcpy(tw_dev->srb[request_id]->sense_buffer, header->sense_data, TW_SENSE_DATA_LENGTH);
-		tw_dev->srb[request_id]->result = (full_command_packet->command.newcommand.status << 1);
+		tw_dev->srb[request_id]->result =
+			full_command_packet->command.newcommand.status;
 		goto out;
 	}
 out:
diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
index 2b1e0d503020..79eca8f1fd05 100644
--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -429,7 +429,7 @@ static int tw_decode_sense(TW_Device_Extension *tw_dev, int request_id, int fill
 					/* Additional sense code qualifier */
 					tw_dev->srb[request_id]->sense_buffer[13] = tw_sense_table[i][3];
 
-					tw_dev->srb[request_id]->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
+					tw_dev->srb[request_id]->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
 					return TW_ISR_DONT_RESULT; /* Special case for isr to not over-write result */
 				}
 			}
@@ -2164,7 +2164,7 @@ static irqreturn_t tw_interrupt(int irq, void *dev_instance)
 				/* If error, command failed */
 				if (error == 1) {
 					/* Ask for a host reset */
-					tw_dev->srb[request_id]->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
+					tw_dev->srb[request_id]->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
 				}
 
 				/* Now complete the io */
diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index 88053b15c363..89eda0c79349 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -1271,7 +1271,7 @@ static void arcmsr_report_sense_info(struct CommandControlBlock *ccb)
 
 	struct scsi_cmnd *pcmd = ccb->pcmd;
 	struct SENSE_DATA *sensebuffer = (struct SENSE_DATA *)pcmd->sense_buffer;
-	pcmd->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
+	pcmd->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
 	if (sensebuffer) {
 		int sense_data_length =
 			sizeof(struct SENSE_DATA) < SCSI_SENSE_BUFFERSIZE
@@ -3110,7 +3110,7 @@ static int arcmsr_queue_command_lck(struct scsi_cmnd *cmd,
 	if (!ccb)
 		return SCSI_MLQUEUE_HOST_BUSY;
 	if (arcmsr_build_ccb( acb, ccb, cmd ) == FAILED) {
-		cmd->result = (DID_ERROR << 16) | (RESERVATION_CONFLICT << 1);
+		cmd->result = (DID_ERROR << 16) | SAM_STAT_RESERVATION_CONFLICT;
 		cmd->scsi_done(cmd);
 		return 0;
 	}
diff --git a/drivers/scsi/bfa/bfad_im.c b/drivers/scsi/bfa/bfad_im.c
index 6b5841b1c06e..e3cbe5d20aca 100644
--- a/drivers/scsi/bfa/bfad_im.c
+++ b/drivers/scsi/bfa/bfad_im.c
@@ -150,7 +150,7 @@ bfa_cb_tskim_done(void *bfad, struct bfad_tskim_s *dtsk,
 	struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dtsk;
 	wait_queue_head_t *wq;
 
-	cmnd->SCp.Status |= tsk_status << 1;
+	cmnd->SCp.Status |= tsk_status;
 	set_bit(IO_DONE_BIT, (unsigned long *)&cmnd->SCp.Status);
 	wq = (wait_queue_head_t *) cmnd->SCp.ptr;
 	cmnd->SCp.ptr = NULL;
diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
index 13fbb2eab842..a56893bc681e 100644
--- a/drivers/scsi/dc395x.c
+++ b/drivers/scsi/dc395x.c
@@ -168,7 +168,6 @@
 #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; }
@@ -3228,7 +3227,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:
@@ -3275,22 +3274,15 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb,
 					*((unsigned int *)(cmd->sense_buffer + 3)));
 		}
 
-		if (status == (CHECK_CONDITION << 1)) {
+		if (status == SAM_STAT_CHECK_CONDITION) {
 			cmd->result = DID_BAD_TARGET << 16;
 			goto ckc_e;
 		}
 		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(DRIVER_SENSE, DID_OK,
+			   srb->end_message, SAM_STAT_CHECK_CONDITION);
 
 		goto ckc_e;
 	}
diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
index abc74fd474dc..83576fd694c4 100644
--- a/drivers/scsi/dpt_i2o.c
+++ b/drivers/scsi/dpt_i2o.c
@@ -2656,7 +2656,7 @@ static void adpt_fail_posted_scbs(adpt_hba* pHba)
 		unsigned long flags;
 		spin_lock_irqsave(&d->list_lock, flags);
 		list_for_each_entry(cmd, &d->cmd_list, list) {
-			cmd->result = (DID_OK << 16) | (QUEUE_FULL <<1);
+			cmd->result = (DID_OK << 16) | SAM_STAT_TASK_SET_FULL;
 			cmd->scsi_done(cmd);
 		}
 		spin_unlock_irqrestore(&d->list_lock, flags);
diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index fe03410268e6..d23e277c1b85 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -1677,7 +1677,7 @@ static void gdth_next(gdth_ha_str *ha)
                 memset((char*)nscp->sense_buffer,0,16);
                 nscp->sense_buffer[0] = 0x70;
                 nscp->sense_buffer[2] = NOT_READY;
-                nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
+		nscp->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
                 if (!nscp_cmndinfo->wait_for_completion)
                     nscp_cmndinfo->wait_for_completion++;
                 else
@@ -1722,7 +1722,7 @@ static void gdth_next(gdth_ha_str *ha)
                     memset((char*)nscp->sense_buffer,0,16);
                     nscp->sense_buffer[0] = 0x70;
                     nscp->sense_buffer[2] = UNIT_ATTENTION;
-                    nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
+		    nscp->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
                     if (!nscp_cmndinfo->wait_for_completion)
                         nscp_cmndinfo->wait_for_completion++;
                     else
@@ -1774,7 +1774,7 @@ static void gdth_next(gdth_ha_str *ha)
                     memset((char*)nscp->sense_buffer,0,16);
                     nscp->sense_buffer[0] = 0x70;
                     nscp->sense_buffer[2] = UNIT_ATTENTION;
-                    nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
+		    nscp->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
                     if (!nscp_cmndinfo->wait_for_completion)
                         nscp_cmndinfo->wait_for_completion++;
                     else
@@ -2802,7 +2802,7 @@ static int gdth_sync_event(gdth_ha_str *ha, int service, u8 index,
                 memset((char*)scp->sense_buffer,0,16);
                 scp->sense_buffer[0] = 0x70;
                 scp->sense_buffer[2] = NOT_READY;
-                scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
+		scp->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
             } else if (service == CACHESERVICE) {
                 if (ha->status == S_CACHE_UNKNOWN &&
                     (ha->hdr[t].cluster_type & 
@@ -2812,11 +2812,11 @@ static int gdth_sync_event(gdth_ha_str *ha, int service, u8 index,
                 }
                 memset((char*)scp->sense_buffer,0,16);
                 if (ha->status == (u16)S_CACHE_RESERV) {
-                    scp->result = (DID_OK << 16) | (RESERVATION_CONFLICT << 1);
+                    scp->result = (DID_OK << 16) | SAM_STAT_RESERVATION_CONFLICT;
                 } else {
                     scp->sense_buffer[0] = 0x70;
                     scp->sense_buffer[2] = NOT_READY;
-                    scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
+                    scp->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
                 }
                 if (!cmndinfo->internal_command) {
                     ha->dvr.size = sizeof(ha->dvr.eu.sync);
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index ff6d4aa92421..21e190c38b97 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -1581,7 +1581,7 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
 
 				cmd->result = (DRIVER_SENSE << 24) |
 					(DID_OK << 16) |
-					(CHECK_CONDITION << 1);
+					SAM_STAT_CHECK_CONDITION;
 			}
 			else {
 				if (mbox->m_out.cmd == MEGA_MBOXCMD_EXTPTHRU) {
@@ -1591,11 +1591,11 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
 
 					cmd->result = (DRIVER_SENSE << 24) |
 						(DID_OK << 16) |
-						(CHECK_CONDITION << 1);
+						SAM_STAT_CHECK_CONDITION;
 				} else {
 					cmd->sense_buffer[0] = 0x70;
 					cmd->sense_buffer[2] = ABORTED_COMMAND;
-					cmd->result |= (CHECK_CONDITION << 1);
+					cmd->result |= SAM_STAT_CHECK_CONDITION;
 				}
 			}
 			break;
@@ -1613,7 +1613,7 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
 			 */
 			if( cmd->cmnd[0] == TEST_UNIT_READY ) {
 				cmd->result |= (DID_ERROR << 16) |
-					(RESERVATION_CONFLICT << 1);
+					SAM_STAT_RESERVATION_CONFLICT;
 			}
 			else
 			/*
@@ -1625,7 +1625,7 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
 					 cmd->cmnd[0] == RELEASE) ) {
 
 				cmd->result |= (DID_ERROR << 16) |
-					(RESERVATION_CONFLICT << 1);
+					SAM_STAT_RESERVATION_CONFLICT;
 			}
 			else
 #endif
diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
index f6ac819e6e96..dc58c5ff31e4 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -1577,7 +1577,7 @@ megaraid_mbox_build_cmd(adapter_t *adapter, struct scsi_cmnd *scp, int *busy)
 				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;
+				scp->result = SAM_STAT_CHECK_CONDITION;
 				return NULL;
 			}
 
@@ -2302,7 +2302,7 @@ megaraid_mbox_dpc(unsigned long devp)
 						14);
 
 				scp->result = DRIVER_SENSE << 24 |
-					DID_OK << 16 | CHECK_CONDITION << 1;
+					DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
 			}
 			else {
 				if (mbox->cmd == MBOXCMD_EXTPTHRU) {
@@ -2312,11 +2312,11 @@ megaraid_mbox_dpc(unsigned long devp)
 
 					scp->result = DRIVER_SENSE << 24 |
 						DID_OK << 16 |
-						CHECK_CONDITION << 1;
+						SAM_STAT_CHECK_CONDITION;
 				} else {
 					scp->sense_buffer[0] = 0x70;
 					scp->sense_buffer[2] = ABORTED_COMMAND;
-					scp->result = CHECK_CONDITION << 1;
+					scp->result = SAM_STAT_CHECK_CONDITION;
 				}
 			}
 			break;
@@ -2334,7 +2334,7 @@ megaraid_mbox_dpc(unsigned long devp)
 			 */
 			if (scp->cmnd[0] == TEST_UNIT_READY) {
 				scp->result = DID_ERROR << 16 |
-					RESERVATION_CONFLICT << 1;
+					SAM_STAT_RESERVATION_CONFLICT;
 			}
 			else
 			/*
@@ -2345,7 +2345,7 @@ megaraid_mbox_dpc(unsigned long devp)
 					 scp->cmnd[0] == RELEASE)) {
 
 				scp->result = DID_ERROR << 16 |
-					RESERVATION_CONFLICT << 1;
+					SAM_STAT_RESERVATION_CONFLICT;
 			}
 			else {
 				scp->result = DID_BAD_TARGET << 16 | status;
-- 
2.16.4


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

* [PATCH 06/24] scsi: change status_byte() to return the standard SCSI status
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
                   ` (4 preceding siblings ...)
  2019-10-21  9:53 ` [PATCH 05/24] scsi: use standard SAM status codes Hannes Reinecke
@ 2019-10-21  9:53 ` Hannes Reinecke
  2019-10-22 12:35   ` Steffen Maier
  2019-10-21  9:53 ` [PATCH 07/24] target_core: Fixup target_complete_cmd() usage Hannes Reinecke
                   ` (18 subsequent siblings)
  24 siblings, 1 reply; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:53 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	linux-scsi, Hannes Reinecke

Instead of returning the linux-special status (which is shifted
by 1 to the right) change the status_byte() macro to return the
correct SCSI standard status.
And audit all callers to handle this change.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/53c700.c        |  6 +++---
 drivers/scsi/NCR5380.c       |  2 +-
 drivers/scsi/arm/acornscsi.c | 10 ++++-----
 drivers/scsi/arm/fas216.c    | 10 ++++-----
 drivers/scsi/dc395x.c        |  8 +++-----
 drivers/scsi/scsi.c          |  2 +-
 drivers/scsi/scsi_error.c    | 48 ++++++++++++++++++++++----------------------
 drivers/scsi/scsi_lib.c      |  2 +-
 drivers/scsi/sg.c            |  4 ++--
 include/scsi/scsi.h          |  2 +-
 10 files changed, 46 insertions(+), 48 deletions(-)

diff --git a/drivers/scsi/53c700.c b/drivers/scsi/53c700.c
index 0068963bb933..432f904e8d13 100644
--- a/drivers/scsi/53c700.c
+++ b/drivers/scsi/53c700.c
@@ -954,8 +954,8 @@ process_script_interrupt(__u32 dsps, __u32 dsp, struct scsi_cmnd *SCp,
 						  NCR_700_FINISHED_TAG_NEGOTIATION);
 			
 		/* check for contingent allegiance contitions */
-		if(status_byte(hostdata->status[0]) == CHECK_CONDITION ||
-		   status_byte(hostdata->status[0]) == COMMAND_TERMINATED) {
+		if(status_byte(hostdata->status[0]) == SAM_STAT_CHECK_CONDITION ||
+		   status_byte(hostdata->status[0]) == SAM_STAT_COMMAND_TERMINATED) {
 			struct NCR_700_command_slot *slot =
 				(struct NCR_700_command_slot *)SCp->host_scribble;
 			if(slot->flags == NCR_700_FLAG_AUTOSENSE) {
@@ -1021,7 +1021,7 @@ process_script_interrupt(__u32 dsps, __u32 dsp, struct scsi_cmnd *SCp,
 			// Currently rely on the mid layer evaluation
 			// of the tag queuing capability
 			//
-			//if(status_byte(hostdata->status[0]) == GOOD &&
+			//if(status_byte(hostdata->status[0]) == SAM_STAT_GOOD &&
 			//   SCp->cmnd[0] == INQUIRY && SCp->use_sg == 0) {
 			//	/* Piggy back the tag queueing support
 			//	 * on this command */
diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index 536426f25e86..5559d39a00b7 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -522,7 +522,7 @@ static void complete_cmd(struct Scsi_Host *instance,
 
 	if (hostdata->sensing == cmd) {
 		/* Autosense processing ends here */
-		if (status_byte(cmd->result) != GOOD) {
+		if (status_byte(cmd->result) != SAM_STAT_GOOD) {
 			scsi_eh_restore_cmnd(cmd, &hostdata->ses);
 		} else {
 			scsi_eh_restore_cmnd(cmd, &hostdata->ses);
diff --git a/drivers/scsi/arm/acornscsi.c b/drivers/scsi/arm/acornscsi.c
index 7e69e481ccac..53b857859310 100644
--- a/drivers/scsi/arm/acornscsi.c
+++ b/drivers/scsi/arm/acornscsi.c
@@ -834,11 +834,11 @@ static void acornscsi_done(AS_Host *host, struct scsi_cmnd **SCpntp,
 
 		if (xfer_warn) {
 		    switch (status_byte(SCpnt->result)) {
-		    case CHECK_CONDITION:
-		    case COMMAND_TERMINATED:
-		    case BUSY:
-		    case QUEUE_FULL:
-		    case RESERVATION_CONFLICT:
+		    case SAM_STAT_CHECK_CONDITION:
+		    case SAM_STAT_COMMAND_TERMINATED:
+		    case SAM_STAT_BUSY:
+		    case SAM_STAT_TASK_SET_FULL:
+		    case SAM_STAT_RESERVATION_CONFLICT:
 			break;
 
 		    default:
diff --git a/drivers/scsi/arm/fas216.c b/drivers/scsi/arm/fas216.c
index 6c68c2303638..a860f89de4ae 100644
--- a/drivers/scsi/arm/fas216.c
+++ b/drivers/scsi/arm/fas216.c
@@ -2056,18 +2056,18 @@ fas216_std_done(FAS216_Info *info, struct scsi_cmnd *SCpnt, unsigned int result)
 		goto done;
 
 	/*
-	 * If the command returned CHECK_CONDITION or COMMAND_TERMINATED
-	 * status, request the sense information.
+	 * If the command returned SAM_STAT_CHECK_CONDITION or
+	 * SAM_STAT_COMMAND_TERMINATED status, request the sense information.
 	 */
-	if (status_byte(SCpnt->result) == CHECK_CONDITION ||
-	    status_byte(SCpnt->result) == COMMAND_TERMINATED)
+	if (status_byte(SCpnt->result) == SAM_STAT_CHECK_CONDITION ||
+	    status_byte(SCpnt->result) == 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 (status_byte(SCpnt->result) != SAM_STAT_GOOD)
 		goto done;
 
 	/*
diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
index a56893bc681e..e79db03196f7 100644
--- a/drivers/scsi/dc395x.c
+++ b/drivers/scsi/dc395x.c
@@ -3292,10 +3292,10 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb,
 		/*
 		 * target status..........................
 		 */
-		if (status_byte(status) == CHECK_CONDITION) {
+		if (status_byte(status) == SAM_STAT_CHECK_CONDITION) {
 			request_sense(acb, dcb, srb);
 			return;
-		} else if (status_byte(status) == QUEUE_FULL) {
+		} else if (status_byte(status) == SAM_STAT_TASK_SET_FULL) {
 			tempcnt = (u8)list_size(&dcb->srb_going_list);
 			dprintkl(KERN_INFO, "QUEUE_FULL for dev <%02i-%i> with %i cmnds\n",
 			     dcb->target_id, dcb->target_lun, tempcnt);
@@ -3361,10 +3361,8 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb,
 		    && dir != PCI_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)) {
+		     status_byte(cmd->result) == SAM_STAT_CHECK_CONDITION)) {
 			if (!dcb->init_tcq_flag) {
 				add_dev(acb, dcb, ptr);
 				dcb->init_tcq_flag = 1;
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 4f76841a7038..59443e0184fd 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -158,7 +158,7 @@ void scsi_log_completion(struct scsi_cmnd *cmd, int disposition)
 		    (level > 1)) {
 			scsi_print_result(cmd, "Done", disposition);
 			scsi_print_command(cmd);
-			if (status_byte(cmd->result) == CHECK_CONDITION)
+			if (status_byte(cmd->result) == SAM_STAT_CHECK_CONDITION)
 				scsi_print_sense(cmd);
 			if (level > 3)
 				scmd_printk(KERN_INFO, cmd,
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index ae2fa170f6ad..bfaac355454b 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -732,31 +732,31 @@ static int scsi_eh_completed_normally(struct scsi_cmnd *scmd)
 	 * anything special.
 	 */
 	switch (status_byte(scmd->result)) {
-	case GOOD:
+	case SAM_STAT_GOOD:
 		scsi_handle_queue_ramp_up(scmd->device);
 		/* FALLTHROUGH */
-	case COMMAND_TERMINATED:
+	case SAM_STAT_COMMAND_TERMINATED:
 		return SUCCESS;
-	case CHECK_CONDITION:
+	case SAM_STAT_CHECK_CONDITION:
 		return scsi_check_sense(scmd);
-	case CONDITION_GOOD:
-	case INTERMEDIATE_GOOD:
-	case INTERMEDIATE_C_GOOD:
+	case SAM_STAT_CONDITION_MET:
+	case SAM_STAT_INTERMEDIATE:
+	case SAM_STAT_INTERMEDIATE_CONDITION_MET:
 		/*
 		 * who knows?  FIXME(eric)
 		 */
 		return SUCCESS;
-	case RESERVATION_CONFLICT:
+	case SAM_STAT_RESERVATION_CONFLICT:
 		if (scmd->cmnd[0] == TEST_UNIT_READY)
 			/* it is a success, we probed the device and
 			 * found it */
 			return SUCCESS;
 		/* otherwise, we failed to send the command */
 		return FAILED;
-	case QUEUE_FULL:
+	case SAM_STAT_TASK_SET_FULL:
 		scsi_handle_queue_full(scmd->device);
 		/* fall through */
-	case BUSY:
+	case SAM_STAT_BUSY:
 		return NEEDS_RETRY;
 	default:
 		return FAILED;
@@ -1237,7 +1237,7 @@ int scsi_eh_get_sense(struct list_head *work_q,
 					     current->comm));
 			break;
 		}
-		if (status_byte(scmd->result) != CHECK_CONDITION)
+		if (status_byte(scmd->result) != SAM_STAT_CHECK_CONDITION)
 			/*
 			 * don't request sense if there's no check condition
 			 * status because the error we're processing isn't one
@@ -1735,14 +1735,14 @@ int scsi_noretry_cmd(struct scsi_cmnd *scmd)
 		return (scmd->request->cmd_flags & REQ_FAILFAST_DEV);
 	case DID_ERROR:
 		if (msg_byte(scmd->result) == COMMAND_COMPLETE &&
-		    status_byte(scmd->result) == RESERVATION_CONFLICT)
+		    status_byte(scmd->result) == SAM_STAT_RESERVATION_CONFLICT)
 			return 0;
 		/* fall through */
 	case DID_SOFT_ERROR:
 		return (scmd->request->cmd_flags & REQ_FAILFAST_DRIVER);
 	}
 
-	if (status_byte(scmd->result) != CHECK_CONDITION)
+	if (status_byte(scmd->result) != SAM_STAT_CHECK_CONDITION)
 		return 0;
 
 check_type:
@@ -1846,7 +1846,7 @@ int 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)
+		    status_byte(scmd->result) == SAM_STAT_RESERVATION_CONFLICT)
 			/*
 			 * execute reservation conflict processing code
 			 * lower down
@@ -1884,14 +1884,14 @@ int scsi_decide_disposition(struct scsi_cmnd *scmd)
 	 * check the status byte to see if this indicates anything special.
 	 */
 	switch (status_byte(scmd->result)) {
-	case QUEUE_FULL:
+	case SAM_STAT_TASK_SET_FULL:
 		scsi_handle_queue_full(scmd->device);
 		/*
 		 * the case of trying to send too many commands to a
 		 * tagged queueing device.
 		 */
 		/* FALLTHROUGH */
-	case BUSY:
+	case SAM_STAT_BUSY:
 		/*
 		 * device can't talk to us at the moment.  Should only
 		 * occur (SAM-3) when the task queue is empty, so will cause
@@ -1899,16 +1899,16 @@ int scsi_decide_disposition(struct scsi_cmnd *scmd)
 		 * device.
 		 */
 		return ADD_TO_MLQUEUE;
-	case GOOD:
+	case SAM_STAT_GOOD:
 		if (scmd->cmnd[0] == REPORT_LUNS)
 			scmd->device->sdev_target->expecting_lun_change = 0;
 		scsi_handle_queue_ramp_up(scmd->device);
 		/* FALLTHROUGH */
-	case COMMAND_TERMINATED:
+	case SAM_STAT_COMMAND_TERMINATED:
 		return SUCCESS;
-	case TASK_ABORTED:
+	case SAM_STAT_TASK_ABORTED:
 		goto maybe_retry;
-	case CHECK_CONDITION:
+	case SAM_STAT_CHECK_CONDITION:
 		rtn = scsi_check_sense(scmd);
 		if (rtn == NEEDS_RETRY)
 			goto maybe_retry;
@@ -1917,16 +1917,16 @@ int scsi_decide_disposition(struct scsi_cmnd *scmd)
 		 * to collect the sense and redo the decide
 		 * disposition */
 		return rtn;
-	case CONDITION_GOOD:
-	case INTERMEDIATE_GOOD:
-	case INTERMEDIATE_C_GOOD:
-	case ACA_ACTIVE:
+	case SAM_STAT_CONDITION_MET:
+	case SAM_STAT_INTERMEDIATE:
+	case SAM_STAT_INTERMEDIATE_CONDITION_MET:
+	case SAM_STAT_ACA_ACTIVE:
 		/*
 		 * who knows?  FIXME(eric)
 		 */
 		return SUCCESS;
 
-	case RESERVATION_CONFLICT:
+	case SAM_STAT_RESERVATION_CONFLICT:
 		sdev_printk(KERN_INFO, scmd->device,
 			    "reservation conflict\n");
 		set_host_byte(scmd, DID_NEXUS_FAILURE);
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index dc210b9d4896..a0db8d8766a8 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2180,7 +2180,7 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
 			data->block_descriptor_length = buffer[3];
 		}
 		data->header_length = header_length;
-	} else if ((status_byte(result) == CHECK_CONDITION) &&
+	} else if ((status_byte(result) == SAM_STAT_CHECK_CONDITION) &&
 		   scsi_sense_valid(sshdr) &&
 		   sshdr->sense_key == UNIT_ATTENTION && retry_count) {
 		retry_count--;
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index cce757506383..e88fb3daebcc 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1349,8 +1349,8 @@ sg_rq_end_io(struct request *rq, blk_status_t status)
 	if (0 != result) {
 		struct scsi_sense_hdr sshdr;
 
-		srp->header.status = 0xff & result;
-		srp->header.masked_status = status_byte(result);
+		srp->header.status = status_byte(result);
+		srp->header.masked_status = status_byte(result) >> 1;
 		srp->header.msg_status = msg_byte(result);
 		srp->header.host_status = host_byte(result);
 		srp->header.driver_status = driver_byte(result);
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
index 5339baadc082..de52632c6022 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -207,7 +207,7 @@ static inline int scsi_is_wlun(u64 lun)
  *      host_byte   = set by low-level driver to indicate status.
  *      driver_byte = set by mid-level.
  */
-#define status_byte(result) (((result) >> 1) & 0x7f)
+#define status_byte(result) (((result)) & 0xff)
 #define msg_byte(result)    (((result) >> 8) & 0xff)
 #define host_byte(result)   (((result) >> 16) & 0xff)
 #define driver_byte(result) (((result) >> 24) & 0xff)
-- 
2.16.4


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

* [PATCH 07/24] target_core: Fixup target_complete_cmd() usage
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
                   ` (5 preceding siblings ...)
  2019-10-21  9:53 ` [PATCH 06/24] scsi: change status_byte() to return the standard SCSI status Hannes Reinecke
@ 2019-10-21  9:53 ` Hannes Reinecke
  2019-10-21  9:53 ` [PATCH 08/24] sg: use SAM status definitions and avoid using masked_status Hannes Reinecke
                   ` (17 subsequent siblings)
  24 siblings, 0 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:53 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	linux-scsi, Hannes Reinecke

target_complete_cmd() occasionally still uses the linux-specific
SCSI result values; fix it up to use SAM result values throughout.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/target/target_core_alua.c   |  6 +++---
 drivers/target/target_core_iblock.c |  2 +-
 drivers/target/target_core_pr.c     |  8 ++++----
 drivers/target/target_core_sbc.c    | 10 +++++-----
 drivers/target/target_core_spc.c    | 14 +++++++-------
 drivers/target/target_core_xcopy.c  |  2 +-
 6 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/drivers/target/target_core_alua.c b/drivers/target/target_core_alua.c
index 385e4cf9cfa6..b53b6d7f173e 100644
--- a/drivers/target/target_core_alua.c
+++ b/drivers/target/target_core_alua.c
@@ -123,7 +123,7 @@ target_emulate_report_referrals(struct se_cmd *cmd)
 
 	transport_kunmap_data_sg(cmd);
 
-	target_complete_cmd(cmd, GOOD);
+	target_complete_cmd(cmd, SAM_STAT_GOOD);
 	return 0;
 }
 
@@ -255,7 +255,7 @@ target_emulate_report_target_port_groups(struct se_cmd *cmd)
 	}
 	transport_kunmap_data_sg(cmd);
 
-	target_complete_cmd_with_length(cmd, GOOD, rd_len + 4);
+	target_complete_cmd_with_length(cmd, SAM_STAT_GOOD, rd_len + 4);
 	return 0;
 }
 
@@ -424,7 +424,7 @@ target_emulate_set_target_port_groups(struct se_cmd *cmd)
 out:
 	transport_kunmap_data_sg(cmd);
 	if (!rc)
-		target_complete_cmd(cmd, GOOD);
+		target_complete_cmd(cmd, SAM_STAT_GOOD);
 	return rc;
 }
 
diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c
index 6949ea8bc387..bbafa984226e 100644
--- a/drivers/target/target_core_iblock.c
+++ b/drivers/target/target_core_iblock.c
@@ -436,7 +436,7 @@ iblock_execute_zero_out(struct block_device *bdev, struct se_cmd *cmd)
 	if (ret)
 		return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
 
-	target_complete_cmd(cmd, GOOD);
+	target_complete_cmd(cmd, SAM_STAT_GOOD);
 	return 0;
 }
 
diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index 5e931690e697..4fef561b201c 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -234,7 +234,7 @@ target_scsi2_reservation_release(struct se_cmd *cmd)
 out_unlock:
 	spin_unlock(&dev->dev_reservation_lock);
 out:
-	target_complete_cmd(cmd, GOOD);
+	target_complete_cmd(cmd, SAM_STAT_GOOD);
 	return 0;
 }
 
@@ -297,7 +297,7 @@ target_scsi2_reservation_reserve(struct se_cmd *cmd)
 	spin_unlock(&dev->dev_reservation_lock);
 out:
 	if (!ret)
-		target_complete_cmd(cmd, GOOD);
+		target_complete_cmd(cmd, SAM_STAT_GOOD);
 	return ret;
 }
 
@@ -3680,7 +3680,7 @@ target_scsi3_emulate_pr_out(struct se_cmd *cmd)
 	}
 
 	if (!ret)
-		target_complete_cmd(cmd, GOOD);
+		target_complete_cmd(cmd, SAM_STAT_GOOD);
 	return ret;
 }
 
@@ -4070,7 +4070,7 @@ target_scsi3_emulate_pr_in(struct se_cmd *cmd)
 	}
 
 	if (!ret)
-		target_complete_cmd(cmd, GOOD);
+		target_complete_cmd(cmd, SAM_STAT_GOOD);
 	return ret;
 }
 
diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c
index f1e81886122d..6e45924fb3da 100644
--- a/drivers/target/target_core_sbc.c
+++ b/drivers/target/target_core_sbc.c
@@ -67,7 +67,7 @@ sbc_emulate_readcapacity(struct se_cmd *cmd)
 		transport_kunmap_data_sg(cmd);
 	}
 
-	target_complete_cmd_with_length(cmd, GOOD, 8);
+	target_complete_cmd_with_length(cmd, SAM_STAT_GOOD, 8);
 	return 0;
 }
 
@@ -130,7 +130,7 @@ sbc_emulate_readcapacity_16(struct se_cmd *cmd)
 		transport_kunmap_data_sg(cmd);
 	}
 
-	target_complete_cmd_with_length(cmd, GOOD, 32);
+	target_complete_cmd_with_length(cmd, SAM_STAT_GOOD, 32);
 	return 0;
 }
 
@@ -202,14 +202,14 @@ sbc_execute_write_same_unmap(struct se_cmd *cmd)
 			return ret;
 	}
 
-	target_complete_cmd(cmd, GOOD);
+	target_complete_cmd(cmd, SAM_STAT_GOOD);
 	return 0;
 }
 
 static sense_reason_t
 sbc_emulate_noop(struct se_cmd *cmd)
 {
-	target_complete_cmd(cmd, GOOD);
+	target_complete_cmd(cmd, SAM_STAT_GOOD);
 	return 0;
 }
 
@@ -1214,7 +1214,7 @@ sbc_execute_unmap(struct se_cmd *cmd)
 err:
 	transport_kunmap_data_sg(cmd);
 	if (!ret)
-		target_complete_cmd(cmd, GOOD);
+		target_complete_cmd(cmd, SAM_STAT_GOOD);
 	return ret;
 }
 
diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c
index 6d4cf2643c0a..84f7fefc2998 100644
--- a/drivers/target/target_core_spc.c
+++ b/drivers/target/target_core_spc.c
@@ -754,7 +754,7 @@ spc_emulate_inquiry(struct se_cmd *cmd)
 	kfree(buf);
 
 	if (!ret)
-		target_complete_cmd_with_length(cmd, GOOD, len);
+		target_complete_cmd_with_length(cmd, SAM_STAT_GOOD, len);
 	return ret;
 }
 
@@ -1099,7 +1099,7 @@ static sense_reason_t spc_emulate_modesense(struct se_cmd *cmd)
 		transport_kunmap_data_sg(cmd);
 	}
 
-	target_complete_cmd_with_length(cmd, GOOD, length);
+	target_complete_cmd_with_length(cmd, SAM_STAT_GOOD, length);
 	return 0;
 }
 
@@ -1117,7 +1117,7 @@ static sense_reason_t spc_emulate_modeselect(struct se_cmd *cmd)
 	int i;
 
 	if (!cmd->data_length) {
-		target_complete_cmd(cmd, GOOD);
+		target_complete_cmd(cmd, SAM_STAT_GOOD);
 		return 0;
 	}
 
@@ -1160,7 +1160,7 @@ static sense_reason_t spc_emulate_modeselect(struct se_cmd *cmd)
 	transport_kunmap_data_sg(cmd);
 
 	if (!ret)
-		target_complete_cmd(cmd, GOOD);
+		target_complete_cmd(cmd, SAM_STAT_GOOD);
 	return ret;
 }
 
@@ -1193,7 +1193,7 @@ static sense_reason_t spc_emulate_request_sense(struct se_cmd *cmd)
 	memcpy(rbuf, buf, min_t(u32, sizeof(buf), cmd->data_length));
 	transport_kunmap_data_sg(cmd);
 
-	target_complete_cmd(cmd, GOOD);
+	target_complete_cmd(cmd, SAM_STAT_GOOD);
 	return 0;
 }
 
@@ -1260,7 +1260,7 @@ sense_reason_t spc_emulate_report_luns(struct se_cmd *cmd)
 		transport_kunmap_data_sg(cmd);
 	}
 
-	target_complete_cmd_with_length(cmd, GOOD, 8 + lun_count * 8);
+	target_complete_cmd_with_length(cmd, SAM_STAT_GOOD, 8 + lun_count * 8);
 	return 0;
 }
 EXPORT_SYMBOL(spc_emulate_report_luns);
@@ -1268,7 +1268,7 @@ EXPORT_SYMBOL(spc_emulate_report_luns);
 static sense_reason_t
 spc_emulate_testunitready(struct se_cmd *cmd)
 {
-	target_complete_cmd(cmd, GOOD);
+	target_complete_cmd(cmd, SAM_STAT_GOOD);
 	return 0;
 }
 
diff --git a/drivers/target/target_core_xcopy.c b/drivers/target/target_core_xcopy.c
index 425c1070de08..30475bf73faf 100644
--- a/drivers/target/target_core_xcopy.c
+++ b/drivers/target/target_core_xcopy.c
@@ -1043,7 +1043,7 @@ static sense_reason_t target_rcr_operating_parameters(struct se_cmd *se_cmd)
 	put_unaligned_be32(42, &p[0]);
 
 	transport_kunmap_data_sg(se_cmd);
-	target_complete_cmd(se_cmd, GOOD);
+	target_complete_cmd(se_cmd, SAM_STAT_GOOD);
 
 	return TCM_NO_SENSE;
 }
-- 
2.16.4


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

* [PATCH 08/24] sg: use SAM status definitions and avoid using masked_status
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
                   ` (6 preceding siblings ...)
  2019-10-21  9:53 ` [PATCH 07/24] target_core: Fixup target_complete_cmd() usage Hannes Reinecke
@ 2019-10-21  9:53 ` Hannes Reinecke
  2019-10-21  9:53 ` [PATCH 09/24] scsi: Kill obsolete linux-specific status codes Hannes Reinecke
                   ` (16 subsequent siblings)
  24 siblings, 0 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:53 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	linux-scsi, Hannes Reinecke

Use standard SAM status definitions and avoid using masked status
values.

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

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index e88fb3daebcc..60ff388d04b9 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -503,7 +503,7 @@ sg_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos)
 	old_hdr->target_status = hp->masked_status;
 	old_hdr->host_status = hp->host_status;
 	old_hdr->driver_status = hp->driver_status;
-	if ((CHECK_CONDITION & hp->masked_status) ||
+	if ((SAM_STAT_CHECK_CONDITION & hp->status) ||
 	    (DRIVER_SENSE & hp->driver_status))
 		memcpy(old_hdr->sense_buffer, srp->sense_b,
 		       sizeof (old_hdr->sense_buffer));
@@ -529,7 +529,7 @@ sg_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos)
 		break;
 	case DID_ERROR:
 		old_hdr->result = (srp->sense_b[0] == 0 && 
-				  hp->masked_status == GOOD) ? 0 : EIO;
+				  hp->status == SAM_STAT_GOOD) ? 0 : EIO;
 		break;
 	default:
 		old_hdr->result = EIO;
@@ -574,7 +574,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) ||
+		if ((SAM_STAT_CHECK_CONDITION & hp->status) ||
 		    (DRIVER_SENSE & hp->driver_status)) {
 			int sb_len = SCSI_SENSE_BUFFERSIZE;
 			sb_len = (hp->mx_sb_len > sb_len) ? sb_len : hp->mx_sb_len;
@@ -587,7 +587,7 @@ sg_new_read(Sg_fd * sfp, char __user *buf, size_t count, Sg_request * srp)
 			hp->sb_len_wr = len;
 		}
 	}
-	if (hp->masked_status || hp->host_status || hp->driver_status)
+	if (hp->status || hp->host_status || hp->driver_status)
 		hp->info |= SG_INFO_CHECK;
 	if (copy_to_user(buf, hp, SZ_SG_IO_HDR)) {
 		err = -EFAULT;
@@ -873,7 +873,7 @@ sg_fill_request_table(Sg_fd *sfp, sg_req_info_t *rinfo)
 			break;
 		rinfo[val].req_state = srp->done + 1;
 		rinfo[val].problem =
-			srp->header.masked_status &
+			srp->header.status &
 			srp->header.host_status &
 			srp->header.driver_status;
 		if (srp->done)
@@ -1355,8 +1355,8 @@ sg_rq_end_io(struct request *rq, blk_status_t status)
 		srp->header.host_status = host_byte(result);
 		srp->header.driver_status = driver_byte(result);
 		if ((sdp->sgdebug > 0) &&
-		    ((CHECK_CONDITION == srp->header.masked_status) ||
-		     (COMMAND_TERMINATED == srp->header.masked_status)))
+		    ((SAM_STAT_CHECK_CONDITION == srp->header.status) ||
+		     (SAM_STAT_COMMAND_TERMINATED == srp->header.status)))
 			__scsi_print_sense(sdp->device, __func__, sense,
 					   SCSI_SENSE_BUFFERSIZE);
 
-- 
2.16.4


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

* [PATCH 09/24] scsi: Kill obsolete linux-specific status codes
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
                   ` (7 preceding siblings ...)
  2019-10-21  9:53 ` [PATCH 08/24] sg: use SAM status definitions and avoid using masked_status Hannes Reinecke
@ 2019-10-21  9:53 ` Hannes Reinecke
  2019-10-21 18:12     ` kbuild test robot
  2019-10-21 18:56     ` kbuild test robot
  2019-10-21  9:53 ` [PATCH 10/24] scsi: introduce set_status_byte() Hannes Reinecke
                   ` (15 subsequent siblings)
  24 siblings, 2 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:53 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	linux-scsi, Hannes Reinecke

After several years it's time to finally kill them.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 include/scsi/scsi_proto.h | 19 -------------------
 1 file changed, 19 deletions(-)

diff --git a/include/scsi/scsi_proto.h b/include/scsi/scsi_proto.h
index c36860111932..660f37ce8721 100644
--- a/include/scsi/scsi_proto.h
+++ b/include/scsi/scsi_proto.h
@@ -202,25 +202,6 @@ struct scsi_varlen_cdb_hdr {
 #define SAM_STAT_ACA_ACTIVE      0x30
 #define SAM_STAT_TASK_ABORTED    0x40
 
-/*
- *  Status codes. These are deprecated as they are shifted 1 bit right
- *  from those found in the SCSI standards. This causes confusion for
- *  applications that are ported to several OSes. Prefer SAM Status codes
- *  above.
- */
-
-#define GOOD                 0x00
-#define CHECK_CONDITION      0x01
-#define CONDITION_GOOD       0x02
-#define BUSY                 0x04
-#define INTERMEDIATE_GOOD    0x08
-#define INTERMEDIATE_C_GOOD  0x0a
-#define RESERVATION_CONFLICT 0x0c
-#define COMMAND_TERMINATED   0x11
-#define QUEUE_FULL           0x14
-#define ACA_ACTIVE           0x18
-#define TASK_ABORTED         0x20
-
 #define STATUS_MASK          0xfe
 
 /*
-- 
2.16.4


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

* [PATCH 10/24] scsi: introduce set_status_byte()
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
                   ` (8 preceding siblings ...)
  2019-10-21  9:53 ` [PATCH 09/24] scsi: Kill obsolete linux-specific status codes Hannes Reinecke
@ 2019-10-21  9:53 ` Hannes Reinecke
  2019-10-21 22:12   ` Finn Thain
  2019-10-21  9:53 ` [PATCH 11/24] advansys: kill driver_defined status byte accessors Hannes Reinecke
                   ` (14 subsequent siblings)
  24 siblings, 1 reply; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:53 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	linux-scsi, Hannes Reinecke

To be in-line with the other set_XX_byte() functions.

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

diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index 91bd749a02f7..6932d91472d5 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -307,6 +307,11 @@ static inline struct scsi_data_buffer *scsi_prot(struct scsi_cmnd *cmd)
 #define scsi_for_each_prot_sg(cmd, sg, nseg, __i)		\
 	for_each_sg(scsi_prot_sglist(cmd), sg, nseg, __i)
 
+static inline void set_status_byte(struct scsi_cmnd *cmd, char status)
+{
+	cmd->result = (cmd->result & 0xffffff00) | status;
+}
+
 static inline void set_msg_byte(struct scsi_cmnd *cmd, char status)
 {
 	cmd->result = (cmd->result & 0xffff00ff) | (status << 8);
-- 
2.16.4


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

* [PATCH 11/24] advansys: kill driver_defined status byte accessors
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
                   ` (9 preceding siblings ...)
  2019-10-21  9:53 ` [PATCH 10/24] scsi: introduce set_status_byte() Hannes Reinecke
@ 2019-10-21  9:53 ` Hannes Reinecke
  2019-10-21 16:37   ` Bart Van Assche
  2019-10-21  9:53 ` [PATCH 12/24] scsi: introduce scsi_build_sense() Hannes Reinecke
                   ` (13 subsequent siblings)
  24 siblings, 1 reply; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:53 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	linux-scsi, Hannes Reinecke

Replace the driver-defined status byte accessors by the
mid-layer defined ones.

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

diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c
index a242a62caaa1..5268b4b92e43 100644
--- a/drivers/scsi/advansys.c
+++ b/drivers/scsi/advansys.c
@@ -2085,12 +2085,6 @@ do { \
 #define ASC_BUSY        0
 #define ASC_ERROR       (-1)
 
-/* struct scsi_cmnd function return codes */
-#define STATUS_BYTE(byte)   (byte)
-#define MSG_BYTE(byte)      ((byte) << 8)
-#define HOST_BYTE(byte)     ((byte) << 16)
-#define DRIVER_BYTE(byte)   ((byte) << 24)
-
 #define ASC_STATS(shost, counter) ASC_STATS_ADD(shost, counter, 1)
 #ifndef ADVANSYS_STATS
 #define ASC_STATS_ADD(shost, counter, count)
@@ -6021,43 +6015,28 @@ 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);
-				/*
-				 * Note: The 'status_byte()' macro used by
-				 * target drivers defined in scsi.h shifts the
-				 * status byte returned by host drivers right
-				 * by 1 bit.  This is why target drivers also
-				 * use right shifted status byte definitions.
-				 * For instance target drivers use
-				 * CHECK_CONDITION, defined to 0x1, instead of
-				 * the SCSI defined check condition value of
-				 * 0x2. Host drivers are supposed to return
-				 * the status byte as it is defined by SCSI.
-				 */
-				scp->result = DRIVER_BYTE(DRIVER_SENSE) |
-				    STATUS_BYTE(scsiqp->scsi_status);
-			} else {
-				scp->result = STATUS_BYTE(scsiqp->scsi_status);
 			}
+			scp->result = status_byte(scsiqp->scsi_status);
 			break;
 
 		default:
 			/* Some other QHSTA error occurred. */
 			ASC_DBG(1, "host_status 0x%x\n", scsiqp->host_status);
-			scp->result = HOST_BYTE(DID_BAD_TARGET);
+			scp->result = host_byte(DID_BAD_TARGET);
 			break;
 		}
 		break;
 
 	case QD_ABORTED_BY_HOST:
 		ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
-		scp->result =
-		    HOST_BYTE(DID_ABORT) | STATUS_BYTE(scsiqp->scsi_status);
+		scp->result = host_byte(DID_ABORT);
+		set_status_byte(scp, scsiqp->scsi_status);
 		break;
 
 	default:
 		ASC_DBG(1, "done_status 0x%x\n", scsiqp->done_status);
-		scp->result =
-		    HOST_BYTE(DID_ERROR) | STATUS_BYTE(scsiqp->scsi_status);
+		scp->result = host_byte(DID_ERROR);
+		set_status_byte(scp, scsiqp->scsi_status);
 		break;
 	}
 
@@ -6789,47 +6768,30 @@ 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);
-				/*
-				 * Note: The 'status_byte()' macro used by
-				 * target drivers defined in scsi.h shifts the
-				 * status byte returned by host drivers right
-				 * by 1 bit.  This is why target drivers also
-				 * use right shifted status byte definitions.
-				 * For instance target drivers use
-				 * CHECK_CONDITION, defined to 0x1, instead of
-				 * the SCSI defined check condition value of
-				 * 0x2. Host drivers are supposed to return
-				 * the status byte as it is defined by SCSI.
-				 */
-				scp->result = DRIVER_BYTE(DRIVER_SENSE) |
-				    STATUS_BYTE(qdonep->d3.scsi_stat);
-			} else {
-				scp->result = STATUS_BYTE(qdonep->d3.scsi_stat);
 			}
+			scp->result = status_byte(qdonep->d3.scsi_stat);
 			break;
 
 		default:
 			/* QHSTA error occurred */
 			ASC_DBG(1, "host_stat 0x%x\n", qdonep->d3.host_stat);
-			scp->result = HOST_BYTE(DID_BAD_TARGET);
+			scp->result = host_byte(DID_BAD_TARGET);
 			break;
 		}
 		break;
 
 	case QD_ABORTED_BY_HOST:
 		ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
-		scp->result =
-		    HOST_BYTE(DID_ABORT) | MSG_BYTE(qdonep->d3.
-						    scsi_msg) |
-		    STATUS_BYTE(qdonep->d3.scsi_stat);
+		scp->result = host_byte(DID_ABORT);
+		set_msg_byte(scp, qdonep->d3.scsi_msg);
+		set_status_byte(scp, qdonep->d3.scsi_stat);
 		break;
 
 	default:
 		ASC_DBG(1, "done_stat 0x%x\n", qdonep->d3.done_stat);
-		scp->result =
-		    HOST_BYTE(DID_ERROR) | MSG_BYTE(qdonep->d3.
-						    scsi_msg) |
-		    STATUS_BYTE(qdonep->d3.scsi_stat);
+		scp->result = host_byte(DID_ERROR);
+		set_msg_byte(scp, qdonep->d3.scsi_msg);
+		set_status_byte(scp, qdonep->d3.scsi_stat);
 		break;
 	}
 
@@ -7568,7 +7530,7 @@ static int asc_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
 				"sg_tablesize %d\n", use_sg,
 				scp->device->host->sg_tablesize);
 			scsi_dma_unmap(scp);
-			scp->result = HOST_BYTE(DID_ERROR);
+			scp->result = host_byte(DID_ERROR);
 			return ASC_ERROR;
 		}
 
@@ -7576,7 +7538,7 @@ static int asc_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
 			use_sg * sizeof(struct asc_sg_list), GFP_ATOMIC);
 		if (!asc_sg_head) {
 			scsi_dma_unmap(scp);
-			scp->result = HOST_BYTE(DID_SOFT_ERROR);
+			scp->result = host_byte(DID_SOFT_ERROR);
 			return ASC_ERROR;
 		}
 
@@ -7819,7 +7781,7 @@ adv_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
 				   "ADV_MAX_SG_LIST %d\n", use_sg,
 				   scp->device->host->sg_tablesize);
 			scsi_dma_unmap(scp);
-			scp->result = HOST_BYTE(DID_ERROR);
+			scp->result = host_byte(DID_ERROR);
 			reqp->cmndp = NULL;
 			scp->host_scribble = NULL;
 
@@ -7831,7 +7793,7 @@ adv_build_req(struct asc_board *boardp, struct scsi_cmnd *scp,
 		ret = adv_get_sglist(boardp, reqp, scsiqp, scp, use_sg);
 		if (ret != ADV_SUCCESS) {
 			scsi_dma_unmap(scp);
-			scp->result = HOST_BYTE(DID_ERROR);
+			scp->result = host_byte(DID_ERROR);
 			reqp->cmndp = NULL;
 			scp->host_scribble = NULL;
 
@@ -8528,13 +8490,13 @@ static int asc_execute_scsi_cmnd(struct scsi_cmnd *scp)
 		scmd_printk(KERN_ERR, scp, "ExeScsiQueue() ASC_ERROR, "
 			"err_code 0x%x\n", err_code);
 		ASC_STATS(scp->device->host, exe_error);
-		scp->result = HOST_BYTE(DID_ERROR);
+		scp->result = host_byte(DID_ERROR);
 		break;
 	default:
 		scmd_printk(KERN_ERR, scp, "ExeScsiQueue() unknown, "
 			"err_code 0x%x\n", err_code);
 		ASC_STATS(scp->device->host, exe_unknown);
-		scp->result = HOST_BYTE(DID_ERROR);
+		scp->result = host_byte(DID_ERROR);
 		break;
 	}
 
-- 
2.16.4


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

* [PATCH 12/24] scsi: introduce scsi_build_sense()
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
                   ` (10 preceding siblings ...)
  2019-10-21  9:53 ` [PATCH 11/24] advansys: kill driver_defined status byte accessors Hannes Reinecke
@ 2019-10-21  9:53 ` Hannes Reinecke
  2019-10-21 23:31   ` Finn Thain
  2019-10-22 12:21   ` Steffen Maier
  2019-10-21  9:53 ` [PATCH 13/24] scsi: Kill DRIVER_SENSE Hannes Reinecke
                   ` (12 subsequent siblings)
  24 siblings, 2 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:53 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	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                |  3 +-
 drivers/scsi/libiscsi.c               |  5 +--
 drivers/scsi/lpfc/lpfc_scsi.c         | 30 ++++-------------
 drivers/scsi/mpt3sas/mpt3sas_scsih.c  |  5 +--
 drivers/scsi/mvumi.c                  |  5 +--
 drivers/scsi/myrb.c                   | 61 ++++++++---------------------------
 drivers/scsi/myrs.c                   |  9 ++----
 drivers/scsi/ps3rom.c                 |  3 +-
 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 ++
 16 files changed, 60 insertions(+), 128 deletions(-)

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index b197d2fbe3f8..0fd3cb8e4e49 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -342,9 +342,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,
@@ -1092,8 +1090,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 e9ded2befa0d..da52d7649f4d 100644
--- a/drivers/s390/scsi/zfcp_scsi.c
+++ b/drivers/s390/scsi/zfcp_scsi.c
@@ -834,10 +834,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 79eca8f1fd05..381723634c13 100644
--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -1981,8 +1981,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);
-			SCpnt->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
-			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 ebd47c0cf9e9..9c85d7902faa 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -813,10 +813,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 f06f63e58596..aa8431fe9c1f 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -2843,10 +2843,7 @@ 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);
 		phba->bg_guard_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
 				"9069 BLKGRD: LBA %lx grd_tag error %x != %x\n",
@@ -2854,10 +2851,7 @@ 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);
 
 		phba->bg_reftag_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
@@ -2866,10 +2860,7 @@ 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);
 
 		phba->bg_apptag_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
@@ -2930,10 +2921,7 @@ 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);
 		phba->bg_guard_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
 				"9055 BLKGRD: Guard Tag error in cmd"
@@ -2946,10 +2934,7 @@ 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);
 
 		phba->bg_reftag_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
@@ -2963,10 +2948,7 @@ 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);
 
 		phba->bg_apptag_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 3f0797e6f941..802b0d39bdf3 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -4619,10 +4619,7 @@ _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);
 }
 
 /**
diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index 8906aceda4c4..645606446bbe 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -2067,10 +2067,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 539ac8ce4fcd..04a75bd0dcb5 100644
--- a/drivers/scsi/myrb.c
+++ b/drivers/scsi/myrb.c
@@ -1449,10 +1449,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);
@@ -1467,10 +1464,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);
@@ -1481,20 +1475,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;
 		}
@@ -1508,10 +1496,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);
@@ -1521,10 +1506,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;
 		}
@@ -1538,10 +1520,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;
 		}
@@ -1555,10 +1534,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;
 		}
@@ -1571,9 +1547,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;
 	}
@@ -2354,25 +2328,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,
@@ -2383,8 +2351,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 eb0dd566330a..70ba289aa24f 100644
--- a/drivers/scsi/myrs.c
+++ b/drivers/scsi/myrs.c
@@ -1602,9 +1602,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:
@@ -1614,10 +1612,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 f75c0b5cd587..63ff9259925a 100644
--- a/drivers/scsi/ps3rom.c
+++ b/drivers/scsi/ps3rom.c
@@ -319,8 +319,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 acef3d73983c..d5c0c57b9d00 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -2232,31 +2232,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 d323523f5f9d..72f10e631ff4 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -779,7 +779,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)
@@ -805,17 +805,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 a0db8d8766a8..2babf6df8066 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -3117,3 +3117,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 7b7ef3acb504..c0bd02613b02 100644
--- a/drivers/scsi/smartpqi/smartpqi_init.c
+++ b/drivers/scsi/smartpqi/smartpqi_init.c
@@ -2874,8 +2874,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 33287b6bdf0e..b02251868cb9 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 6932d91472d5..9b9ca629097d 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -338,4 +338,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.16.4


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

* [PATCH 13/24] scsi: Kill DRIVER_SENSE
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
                   ` (11 preceding siblings ...)
  2019-10-21  9:53 ` [PATCH 12/24] scsi: introduce scsi_build_sense() Hannes Reinecke
@ 2019-10-21  9:53 ` Hannes Reinecke
  2019-10-21 23:44   ` Finn Thain
  2021-06-04  6:40   ` Jiri Slaby
  2019-10-21  9:53 ` [PATCH 14/24] scsi: Kill DRIVER_HARD Hannes Reinecke
                   ` (11 subsequent siblings)
  24 siblings, 2 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:53 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	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.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/ata/libata-scsi.c                   | 13 ++++-----
 drivers/scsi/NCR5380.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                           |  3 +-
 drivers/scsi/constants.c                    |  2 +-
 drivers/scsi/cxlflash/superpipe.c           | 45 ++++++++++++++---------------
 drivers/scsi/dc395x.c                       |  2 +-
 drivers/scsi/esp_scsi.c                     |  3 +-
 drivers/scsi/megaraid.c                     | 14 ++++-----
 drivers/scsi/megaraid/megaraid_mbox.c       | 14 ++++-----
 drivers/scsi/megaraid/megaraid_sas_base.c   |  3 +-
 drivers/scsi/megaraid/megaraid_sas_fusion.c |  1 -
 drivers/scsi/mpt3sas/mpt3sas_scsih.c        |  3 +-
 drivers/scsi/mvumi.c                        |  1 -
 drivers/scsi/scsi.c                         |  4 +--
 drivers/scsi/scsi_debug.c                   |  4 +--
 drivers/scsi/scsi_ioctl.c                   |  2 +-
 drivers/scsi/scsi_lib.c                     | 13 ++++-----
 drivers/scsi/scsi_scan.c                    |  2 +-
 drivers/scsi/scsi_transport_spi.c           |  2 +-
 drivers/scsi/sd.c                           | 33 +++++++++++----------
 drivers/scsi/sg.c                           |  6 ++--
 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/scsi.h                         |  1 -
 include/scsi/sg.h                           |  3 +-
 include/trace/events/scsi.h                 |  3 +-
 35 files changed, 92 insertions(+), 133 deletions(-)

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 0fd3cb8e4e49..6ae0b579a6ca 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -633,13 +633,12 @@ 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 (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;
@@ -714,9 +713,8 @@ 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 (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. */
@@ -1074,7 +1072,7 @@ 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;
+	cmd->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
 
 	/*
 	 * Use ata_to_sense_error() to map status register bits
@@ -1172,7 +1170,7 @@ 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;
+	cmd->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
 
 	if (ata_dev_disabled(dev)) {
 		/* Device disabled after error recovery */
@@ -4480,7 +4478,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 5559d39a00b7..ddeeed02cc8b 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -526,7 +526,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/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c
index 72c67e89b911..0d83184d069c 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.c
@@ -1940,7 +1940,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);
+			cmd->result |= SAM_STAT_CHECK_CONDITION;
 
 #ifdef AHD_DEBUG
 			if (ahd_debug & AHD_SHOW_SENSE) {
@@ -2030,6 +2030,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
@@ -2053,18 +2054,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 a0b444e6209d..1c718cf5083f 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c
@@ -1853,7 +1853,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 89eda0c79349..372aba7f12f3 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -1280,7 +1280,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 5f8153c37f77..380a519b1757 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -199,8 +199,7 @@ 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 (driver_byte(result) == DRIVER_SENSE) {
+	if (status_byte(result) == SAM_STAT_CHECK_CONDITION) {
 		if (debug)
 			scsi_print_sense_hdr(ch->device, ch->name, &sshdr);
 		errno = ch_find_errno(&sshdr);
diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c
index d4c2a2e4c5d4..7809bf618606 100644
--- a/drivers/scsi/constants.c
+++ b/drivers/scsi/constants.c
@@ -408,7 +408,7 @@ static const char * const hostbyte_table[]={
 
 static const char * const driverbyte_table[]={
 "DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT",  "DRIVER_MEDIA", "DRIVER_ERROR",
-"DRIVER_INVALID", "DRIVER_TIMEOUT", "DRIVER_HARD", "DRIVER_SENSE"};
+"DRIVER_INVALID", "DRIVER_TIMEOUT", "DRIVER_HARD"};
 
 const char *scsi_hostbyte_string(int result)
 {
diff --git a/drivers/scsi/cxlflash/superpipe.c b/drivers/scsi/cxlflash/superpipe.c
index 593669ac3669..ee03a2b59b57 100644
--- a/drivers/scsi/cxlflash/superpipe.c
+++ b/drivers/scsi/cxlflash/superpipe.c
@@ -369,33 +369,30 @@ static int read_cap16(struct scsi_device *sdev, struct llun_info *lli)
 		goto out;
 	}
 
-	if (driver_byte(result) == DRIVER_SENSE) {
-		result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */
-		if (result & SAM_STAT_CHECK_CONDITION) {
-			switch (sshdr.sense_key) {
-			case NO_SENSE:
-			case RECOVERED_ERROR:
+	if (result & SAM_STAT_CHECK_CONDITION) {
+		switch (sshdr.sense_key) {
+		case NO_SENSE:
+		case RECOVERED_ERROR:
+			/* fall through */
+		case NOT_READY:
+			result &= ~SAM_STAT_CHECK_CONDITION;
+			break;
+		case UNIT_ATTENTION:
+			switch (sshdr.asc) {
+			case 0x29: /* Power on Reset or Device Reset */
 				/* fall through */
-			case NOT_READY:
-				result &= ~SAM_STAT_CHECK_CONDITION;
-				break;
-			case UNIT_ATTENTION:
-				switch (sshdr.asc) {
-				case 0x29: /* Power on Reset or Device Reset */
-					/* fall through */
-				case 0x2A: /* Device capacity changed */
-				case 0x3F: /* Report LUNs changed */
-					/* Retry the command once more */
-					if (retry_cnt++ < 1) {
-						kfree(cmd_buf);
-						kfree(scsi_cmd);
-						goto retry;
-					}
+			case 0x2A: /* Device capacity changed */
+			case 0x3F: /* Report LUNs changed */
+				/* Retry the command once more */
+				if (retry_cnt++ < 1) {
+					kfree(cmd_buf);
+					kfree(scsi_cmd);
+					goto retry;
 				}
-				break;
-			default:
-				break;
 			}
+			break;
+		default:
+			break;
 		}
 	}
 
diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
index e79db03196f7..d32537d75439 100644
--- a/drivers/scsi/dc395x.c
+++ b/drivers/scsi/dc395x.c
@@ -3281,7 +3281,7 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb,
 		dprintkdbg(DBG_0, "srb_done: AUTO_REQSENSE2\n");
 
 		cmd->result =
-		    MK_RES(DRIVER_SENSE, DID_OK,
+		    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 bb88995a12c7..f32561bbb0b5 100644
--- a/drivers/scsi/esp_scsi.c
+++ b/drivers/scsi/esp_scsi.c
@@ -916,8 +916,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) |
+		cmd->result = ((DID_OK << 16) |
 			       (COMMAND_COMPLETE << 8) |
 			       (SAM_STAT_CHECK_CONDITION << 0));
 
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index 21e190c38b97..007d4f2d371d 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -1579,8 +1579,7 @@ 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) |
+				cmd->result = (DID_OK << 16) |
 					SAM_STAT_CHECK_CONDITION;
 			}
 			else {
@@ -1589,14 +1588,11 @@ 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) |
+					cmd->result = (DID_OK << 16) |
 						SAM_STAT_CHECK_CONDITION;
-				} else {
-					cmd->sense_buffer[0] = 0x70;
-					cmd->sense_buffer[2] = ABORTED_COMMAND;
-					cmd->result |= SAM_STAT_CHECK_CONDITION;
-				}
+				} 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 dc58c5ff31e4..0825e0baa7d1 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -2301,8 +2301,7 @@ megaraid_mbox_dpc(unsigned long devp)
 				memcpy(scp->sense_buffer, pthru->reqsensearea,
 						14);
 
-				scp->result = DRIVER_SENSE << 24 |
-					DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
+				scp->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
 			}
 			else {
 				if (mbox->cmd == MBOXCMD_EXTPTHRU) {
@@ -2310,14 +2309,11 @@ megaraid_mbox_dpc(unsigned long devp)
 					memcpy(scp->sense_buffer,
 						epthru->reqsensearea, 14);
 
-					scp->result = DRIVER_SENSE << 24 |
-						DID_OK << 16 |
+					scp->result = DID_OK << 16 |
 						SAM_STAT_CHECK_CONDITION;
-				} else {
-					scp->sense_buffer[0] = 0x70;
-					scp->sense_buffer[2] = ABORTED_COMMAND;
-					scp->result = SAM_STAT_CHECK_CONDITION;
-				}
+				} else
+					scsi_build_sense(scp, 0,
+							 ABORTED_COMMAND, 0, 0);
 			}
 			break;
 
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index c40fbea06cc5..649f9610ca72 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -1,3 +1,4 @@
+
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  *  Linux MegaRAID driver for SAS based RAID controllers
@@ -3548,8 +3549,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 e301458bcbae..a00449475095 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -1988,7 +1988,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/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 802b0d39bdf3..bb19359a1a06 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -5376,8 +5376,7 @@ _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->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
 			scmd->sense_buffer[0] = 0x70;
 			scmd->sense_buffer[2] = ILLEGAL_REQUEST;
 			scmd->sense_buffer[12] = 0x20;
diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index 645606446bbe..91eb879692c3 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -1316,7 +1316,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 59443e0184fd..d6ecb773c512 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -203,8 +203,8 @@ void scsi_finish_command(struct scsi_cmnd *cmd)
 	 * 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);
+	if (SCSI_SENSE_VALID(cmd) && status_byte(cmd->result) == SAM_STAT_GOOD)
+		set_status_byte(cmd, SAM_STAT_CHECK_CONDITION);
 
 	SCSI_LOG_MLCOMPLETE(4, sdev_printk(KERN_INFO, sdev,
 				"Notifying upper driver of completion "
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 72f10e631ff4..be7036cd4e62 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -708,10 +708,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) | (COMMAND_COMPLETE << 8) | SAM_STAT_TASK_SET_FULL;
diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c
index 57bcd05605bf..70c1eab90710 100644
--- a/drivers/scsi/scsi_ioctl.c
+++ b/drivers/scsi/scsi_ioctl.c
@@ -101,7 +101,7 @@ 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 (driver_byte(result) == DRIVER_SENSE &&
+	if (status_byte(result) == SAM_STAT_CHECK_CONDITION &&
 	    scsi_sense_valid(&sshdr)) {
 		switch (sshdr.sense_key) {
 		case ILLEGAL_REQUEST:
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 2babf6df8066..eac14ecc82dc 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -636,8 +636,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;
@@ -805,7 +803,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 (status_byte(result) == SAM_STAT_CHECK_CONDITION)
 					scsi_print_sense(cmd);
 				scsi_print_command(cmd);
 			}
@@ -2143,11 +2141,11 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
 	 * ILLEGAL REQUEST if the code page isn't supported */
 
 	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)) {
-				/* 
+				/*
 				 * Invalid command operation code
 				 */
 				sdev->use_10_for_ms = 0;
@@ -2156,7 +2154,7 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
 		}
 	}
 
-	if(scsi_status_is_good(result)) {
+	if (scsi_status_is_good(result)) {
 		if (unlikely(buffer[0] == 0x86 && buffer[1] == 0x0b &&
 			     (modepage == 6 || modepage == 8))) {
 			/* Initio breakage? */
@@ -3131,7 +3129,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 058079f915f1..36385f6c5cdc 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -606,7 +606,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 f8661062ef95..9a08a60552a4 100644
--- a/drivers/scsi/scsi_transport_spi.c
+++ b/drivers/scsi/scsi_transport_spi.c
@@ -123,7 +123,7 @@ static int spi_execute(struct scsi_device *sdev, const void *cmd,
 				      REQ_FAILFAST_TRANSPORT |
 				      REQ_FAILFAST_DRIVER,
 				      0, NULL);
-		if (driver_byte(result) != DRIVER_SENSE ||
+		if (status_byte(result) != SAM_STAT_CHECK_CONDITION ||
 		    sshdr->sense_key != UNIT_ATTENTION)
 			break;
 	}
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 326e2877f169..220990183b6b 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1648,16 +1648,17 @@ 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 (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 */
@@ -1751,7 +1752,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, SD_MAX_RETRIES, NULL);
 
-	if (driver_byte(result) == DRIVER_SENSE &&
+	if (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);
@@ -1993,7 +1994,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;
 
@@ -2096,12 +2097,12 @@ 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 (driver_byte(the_result) != DRIVER_SENSE) {
+		if (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)) {
@@ -2227,7 +2228,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 (status_byte(the_result) == SAM_STAT_CHECK_CONDITION)
 		sd_print_sense_hdr(sdkp, sshdr);
 	else
 		sd_printk(KERN_NOTICE, sdkp, "Sense not available.\n");
@@ -3494,12 +3495,12 @@ static int sd_start_stop_device(struct scsi_disk *sdkp, int start)
 			SD_TIMEOUT, SD_MAX_RETRIES, 0, RQF_PM, NULL);
 	if (res) {
 		sd_print_result(sdkp, "Start/Stop Unit failed", res);
-		if (driver_byte(res) == DRIVER_SENSE)
+		if (status_byte(res) == SAM_STAT_CHECK_CONDITION) {
 			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/sg.c b/drivers/scsi/sg.c
index 60ff388d04b9..c85e095be337 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -503,8 +503,7 @@ sg_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos)
 	old_hdr->target_status = hp->masked_status;
 	old_hdr->host_status = hp->host_status;
 	old_hdr->driver_status = hp->driver_status;
-	if ((SAM_STAT_CHECK_CONDITION & hp->status) ||
-	    (DRIVER_SENSE & hp->driver_status))
+	if (SAM_STAT_CHECK_CONDITION & hp->status)
 		memcpy(old_hdr->sense_buffer, srp->sense_b,
 		       sizeof (old_hdr->sense_buffer));
 	switch (hp->host_status) {
@@ -574,8 +573,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 ((SAM_STAT_CHECK_CONDITION & hp->status) ||
-		    (DRIVER_SENSE & hp->driver_status)) {
+		if (SAM_STAT_CHECK_CONDITION & hp->status) {
 			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 */
diff --git a/drivers/scsi/stex.c b/drivers/scsi/stex.c
index b02251868cb9..b7ebc869d30f 100644
--- a/drivers/scsi/stex.c
+++ b/drivers/scsi/stex.c
@@ -735,7 +735,7 @@ static void stex_scsi_done(struct st_ccb *ccb)
 			result |= DID_OK << 16 | COMMAND_COMPLETE << 8;
 			break;
 		case SAM_STAT_CHECK_CONDITION:
-			result |= DRIVER_SENSE << 24;
+			result |= DID_OK << 16;
 			break;
 		case SAM_STAT_BUSY:
 			result |= DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
@@ -746,7 +746,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 | COMMAND_COMPLETE << 8;
diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c
index 2ca018ce796f..e72fc73cdd96 100644
--- a/drivers/scsi/sym53c8xx_2/sym_glue.c
+++ b/drivers/scsi/sym53c8xx_2/sym_glue.c
@@ -174,9 +174,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;
 
@@ -190,7 +189,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.
 			 */
@@ -239,7 +237,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 c28c144d9b4a..e411aadb6da7 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -7600,7 +7600,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 (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 bfec84aacd90..97b980bf145f 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 70008816c91f..74e5ed940952 100644
--- a/drivers/scsi/vmw_pvscsi.c
+++ b/drivers/scsi/vmw_pvscsi.c
@@ -565,9 +565,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 3305b47fdf53..99a88aee1c94 100644
--- a/drivers/target/loopback/tcm_loop.c
+++ b/drivers/target/loopback/tcm_loop.c
@@ -579,7 +579,6 @@ static int tcm_loop_queue_status(struct se_cmd *se_cmd)
 		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 = se_cmd->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 ba0942e481bc..e130b4426c62 100644
--- a/drivers/xen/xen-scsiback.c
+++ b/drivers/xen/xen-scsiback.c
@@ -1431,7 +1431,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/scsi.h b/include/scsi/scsi.h
index de52632c6022..58ce46327bf5 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -173,7 +173,6 @@ static inline int scsi_is_wlun(u64 lun)
 #define DRIVER_INVALID      0x05
 #define DRIVER_TIMEOUT      0x06
 #define DRIVER_HARD         0x07
-#define DRIVER_SENSE	    0x08
 
 /*
  * Internal return values.
diff --git a/include/scsi/sg.h b/include/scsi/sg.h
index f91bcca604e4..8df4f5fb2544 100644
--- a/include/scsi/sg.h
+++ b/include/scsi/sg.h
@@ -234,8 +234,7 @@ struct sg_header
     unsigned int other_flags:10;    /* unused */
     unsigned char sense_buffer[SG_MAX_SENSE]; /* [o] Output in 3 cases:
 	   when target_status is CHECK_CONDITION or
-	   when target_status is COMMAND_TERMINATED or
-	   when (driver_status & DRIVER_SENSE) is true. */
+	   when target_status is COMMAND_TERMINATED */
 };      /* This structure is 36 bytes long on i386 */
 
 
diff --git a/include/trace/events/scsi.h b/include/trace/events/scsi.h
index f624969a4f14..404fbc54bc32 100644
--- a/include/trace/events/scsi.h
+++ b/include/trace/events/scsi.h
@@ -134,8 +134,7 @@
 		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))
+		 scsi_driverbyte_name(DRIVER_HARD))
 
 #define scsi_msgbyte_name(result)	{ result, #result }
 #define show_msgbyte_name(val)					\
-- 
2.16.4


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

* [PATCH 14/24] scsi: Kill DRIVER_HARD
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
                   ` (12 preceding siblings ...)
  2019-10-21  9:53 ` [PATCH 13/24] scsi: Kill DRIVER_SENSE Hannes Reinecke
@ 2019-10-21  9:53 ` Hannes Reinecke
  2019-10-21  9:53 ` [PATCH 15/24] scsi_error: use DID_TIME_OUT instead of DRIVER_TIMEOUT Hannes Reinecke
                   ` (10 subsequent siblings)
  24 siblings, 0 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:53 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	linux-scsi, Hannes Reinecke

Unused.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/constants.c    | 2 +-
 include/scsi/scsi.h         | 1 -
 include/trace/events/scsi.h | 3 +--
 3 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c
index 7809bf618606..b2ba83e6b98d 100644
--- a/drivers/scsi/constants.c
+++ b/drivers/scsi/constants.c
@@ -408,7 +408,7 @@ static const char * const hostbyte_table[]={
 
 static const char * const driverbyte_table[]={
 "DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT",  "DRIVER_MEDIA", "DRIVER_ERROR",
-"DRIVER_INVALID", "DRIVER_TIMEOUT", "DRIVER_HARD"};
+"DRIVER_INVALID", "DRIVER_TIMEOUT"};
 
 const char *scsi_hostbyte_string(int result)
 {
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
index 58ce46327bf5..cf022e08e0b0 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -172,7 +172,6 @@ static inline int scsi_is_wlun(u64 lun)
 
 #define DRIVER_INVALID      0x05
 #define DRIVER_TIMEOUT      0x06
-#define DRIVER_HARD         0x07
 
 /*
  * Internal return values.
diff --git a/include/trace/events/scsi.h b/include/trace/events/scsi.h
index 404fbc54bc32..e15373917d1e 100644
--- a/include/trace/events/scsi.h
+++ b/include/trace/events/scsi.h
@@ -133,8 +133,7 @@
 		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_TIMEOUT))
 
 #define scsi_msgbyte_name(result)	{ result, #result }
 #define show_msgbyte_name(val)					\
-- 
2.16.4


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

* [PATCH 15/24] scsi_error: use DID_TIME_OUT instead of DRIVER_TIMEOUT
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
                   ` (13 preceding siblings ...)
  2019-10-21  9:53 ` [PATCH 14/24] scsi: Kill DRIVER_HARD Hannes Reinecke
@ 2019-10-21  9:53 ` Hannes Reinecke
  2019-10-21  9:53 ` [PATCH 16/24] scsi: Kill DRIVER_TIMEOUT Hannes Reinecke
                   ` (9 subsequent siblings)
  24 siblings, 0 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:53 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	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 bfaac355454b..22893050d574 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -2100,10 +2100,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.16.4


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

* [PATCH 16/24] scsi: Kill DRIVER_TIMEOUT
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
                   ` (14 preceding siblings ...)
  2019-10-21  9:53 ` [PATCH 15/24] scsi_error: use DID_TIME_OUT instead of DRIVER_TIMEOUT Hannes Reinecke
@ 2019-10-21  9:53 ` Hannes Reinecke
  2019-10-21  9:53 ` [PATCH 17/24] scsi: do not use DRIVER_INVALID Hannes Reinecke
                   ` (8 subsequent siblings)
  24 siblings, 0 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:53 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	linux-scsi, Hannes Reinecke

Unused now.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/constants.c    | 2 +-
 include/scsi/scsi.h         | 1 -
 include/trace/events/scsi.h | 3 +--
 3 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c
index b2ba83e6b98d..1780837ea11e 100644
--- a/drivers/scsi/constants.c
+++ b/drivers/scsi/constants.c
@@ -408,7 +408,7 @@ static const char * const hostbyte_table[]={
 
 static const char * const driverbyte_table[]={
 "DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT",  "DRIVER_MEDIA", "DRIVER_ERROR",
-"DRIVER_INVALID", "DRIVER_TIMEOUT"};
+"DRIVER_INVALID"};
 
 const char *scsi_hostbyte_string(int result)
 {
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
index cf022e08e0b0..5cd29d8c7c3b 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -171,7 +171,6 @@ static inline int scsi_is_wlun(u64 lun)
 #define DRIVER_ERROR        0x04
 
 #define DRIVER_INVALID      0x05
-#define DRIVER_TIMEOUT      0x06
 
 /*
  * Internal return values.
diff --git a/include/trace/events/scsi.h b/include/trace/events/scsi.h
index e15373917d1e..a1b4da442c5c 100644
--- a/include/trace/events/scsi.h
+++ b/include/trace/events/scsi.h
@@ -132,8 +132,7 @@
 		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_INVALID))
 
 #define scsi_msgbyte_name(result)	{ result, #result }
 #define show_msgbyte_name(val)					\
-- 
2.16.4


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

* [PATCH 17/24] scsi: do not use DRIVER_INVALID
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
                   ` (15 preceding siblings ...)
  2019-10-21  9:53 ` [PATCH 16/24] scsi: Kill DRIVER_TIMEOUT Hannes Reinecke
@ 2019-10-21  9:53 ` Hannes Reinecke
  2019-10-21  9:53 ` [PATCH 18/24] st: return error code in st_scsi_execute() Hannes Reinecke
                   ` (7 subsequent siblings)
  24 siblings, 0 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:53 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	linux-scsi, Hannes Reinecke

Use DID_ERROR instead of DRIVER_INVALID, as it really doesn't
matter if the driver or the device didn't understand the command.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/constants.c    |  3 +--
 drivers/scsi/hptiop.c       |  2 +-
 drivers/scsi/mvumi.c        | 10 +++++-----
 drivers/scsi/vmw_pvscsi.c   | 18 +++++++++---------
 include/scsi/scsi.h         |  2 --
 include/trace/events/scsi.h |  3 +--
 6 files changed, 17 insertions(+), 21 deletions(-)

diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c
index 1780837ea11e..1cee98534bfd 100644
--- a/drivers/scsi/constants.c
+++ b/drivers/scsi/constants.c
@@ -407,8 +407,7 @@ static const char * const hostbyte_table[]={
 "DID_NEXUS_FAILURE" };
 
 static const char * const driverbyte_table[]={
-"DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT",  "DRIVER_MEDIA", "DRIVER_ERROR",
-"DRIVER_INVALID"};
+"DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT",  "DRIVER_MEDIA", "DRIVER_ERROR"};
 
 const char *scsi_hostbyte_string(int result)
 {
diff --git a/drivers/scsi/hptiop.c b/drivers/scsi/hptiop.c
index 6a2561f26e38..2cfb58c2e175 100644
--- a/drivers/scsi/hptiop.c
+++ b/drivers/scsi/hptiop.c
@@ -761,7 +761,7 @@ static void hptiop_finish_scsi_req(struct hptiop_hba *hba, u32 tag,
 		break;
 
 	default:
-		scp->result = DRIVER_INVALID << 24 | DID_ABORT << 16;
+		scp->result = (DID_ERROR << 16);
 		break;
 	}
 
diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index 91eb879692c3..cbeb1c0e62f2 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -1306,20 +1306,20 @@ static void mvumi_complete_cmd(struct mvumi_hba *mhba, struct mvumi_cmd *cmd,
 
 	switch (ob_frame->req_status) {
 	case SAM_STAT_GOOD:
-		scmd->result |= DID_OK << 16;
+		set_host_byte(scmd, DID_OK);
 		break;
 	case SAM_STAT_BUSY:
-		scmd->result |= DID_BUS_BUSY << 16;
+		set_host_byte(scmd, DID_BUS_BUSY);
 		break;
 	case SAM_STAT_CHECK_CONDITION:
-		scmd->result |= (DID_OK << 16);
+		set_host_byte(scmd, DID_OK);
 		if (ob_frame->rsp_flag & CL_RSP_FLAG_SENSEDATA) {
 			memcpy(cmd->scmd->sense_buffer, ob_frame->payload,
 				sizeof(struct mvumi_sense_data));
 		}
 		break;
 	default:
-		scmd->result |= (DRIVER_INVALID << 24) | (DID_ABORT << 16);
+		set_host_byte(scmd, DID_ABORT);
 		break;
 	}
 
@@ -2126,7 +2126,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 74e5ed940952..e988a8c3fc7f 100644
--- a/drivers/scsi/vmw_pvscsi.c
+++ b/drivers/scsi/vmw_pvscsi.c
@@ -572,25 +572,25 @@ static void pvscsi_complete_request(struct pvscsi_adapter *adapter,
 		case BTSTAT_LINKED_COMMAND_COMPLETED:
 		case BTSTAT_LINKED_COMMAND_COMPLETED_WITH_FLAG:
 			/* If everything went fine, let's move on..  */
-			cmd->result = (DID_OK << 16);
+			set_host_byte(cmd, DID_OK);
 			break;
 
 		case BTSTAT_DATARUN:
 		case BTSTAT_DATA_UNDERRUN:
 			/* Report residual data in underruns */
 			scsi_set_resid(cmd, scsi_bufflen(cmd) - e->dataLen);
-			cmd->result = (DID_ERROR << 16);
+			set_host_byte(cmd, DID_ERROR);
 			break;
 
 		case BTSTAT_SELTIMEO:
 			/* Our emulation returns this for non-connected devs */
-			cmd->result = (DID_BAD_TARGET << 16);
+			set_host_byte(cmd, DID_BAD_TARGET);
 			break;
 
 		case BTSTAT_LUNMISMATCH:
 		case BTSTAT_TAGREJECT:
 		case BTSTAT_BADMSG:
-			cmd->result = (DRIVER_INVALID << 24);
+			cmd->result = 0;
 			/* fall through */
 
 		case BTSTAT_HAHARDWARE:
@@ -601,25 +601,25 @@ static void pvscsi_complete_request(struct pvscsi_adapter *adapter,
 		case BTSTAT_HASOFTWARE:
 		case BTSTAT_BUSFREE:
 		case BTSTAT_SENSFAILED:
-			cmd->result |= (DID_ERROR << 16);
+			set_host_byte(cmd, DID_ERROR);
 			break;
 
 		case BTSTAT_SENTRST:
 		case BTSTAT_RECVRST:
 		case BTSTAT_BUSRESET:
-			cmd->result = (DID_RESET << 16);
+			set_host_byte(cmd, DID_RESET);
 			break;
 
 		case BTSTAT_ABORTQUEUE:
-			cmd->result = (DID_BUS_BUSY << 16);
+			set_host_byte(cmd, DID_BUS_BUSY);
 			break;
 
 		case BTSTAT_SCSIPARITY:
-			cmd->result = (DID_PARITY << 16);
+			set_host_byte(cmd, DID_PARITY);
 			break;
 
 		default:
-			cmd->result = (DID_ERROR << 16);
+			set_host_byte(cmd, DID_ERROR);
 			scmd_printk(KERN_DEBUG, cmd,
 				    "Unknown completion status: 0x%x\n",
 				    btstat);
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
index 5cd29d8c7c3b..57caf1f91673 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -170,8 +170,6 @@ static inline int scsi_is_wlun(u64 lun)
 #define DRIVER_MEDIA        0x03
 #define DRIVER_ERROR        0x04
 
-#define DRIVER_INVALID      0x05
-
 /*
  * Internal return values.
  */
diff --git a/include/trace/events/scsi.h b/include/trace/events/scsi.h
index a1b4da442c5c..83bc7d97a469 100644
--- a/include/trace/events/scsi.h
+++ b/include/trace/events/scsi.h
@@ -131,8 +131,7 @@
 		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_ERROR))
 
 #define scsi_msgbyte_name(result)	{ result, #result }
 #define show_msgbyte_name(val)					\
-- 
2.16.4


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

* [PATCH 18/24] st: return error code in st_scsi_execute()
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
                   ` (16 preceding siblings ...)
  2019-10-21  9:53 ` [PATCH 17/24] scsi: do not use DRIVER_INVALID Hannes Reinecke
@ 2019-10-21  9:53 ` Hannes Reinecke
  2019-10-21 16:41   ` Bart Van Assche
  2019-10-21  9:53 ` [PATCH 19/24] scsi_ioctl: return error code when blk_map_user() fails Hannes Reinecke
                   ` (6 subsequent siblings)
  24 siblings, 1 reply; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:53 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	linux-scsi, Hannes Reinecke

We should return the actual error code in st_scsi_execute(),
avoiding the need to use DRIVER_ERROR.

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 e3266a64a477..5f38369cc62f 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -549,7 +549,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;
 
@@ -560,7 +560,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.16.4


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

* [PATCH 19/24] scsi_ioctl: return error code when blk_map_user() fails
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
                   ` (17 preceding siblings ...)
  2019-10-21  9:53 ` [PATCH 18/24] st: return error code in st_scsi_execute() Hannes Reinecke
@ 2019-10-21  9:53 ` Hannes Reinecke
  2019-10-21 16:44   ` Bart Van Assche
  2019-10-21  9:53 ` [PATCH 20/24] scsi_dh_alua: do not interpret DRIVER_ERROR Hannes Reinecke
                   ` (5 subsequent siblings)
  24 siblings, 1 reply; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:53 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	linux-scsi, Hannes Reinecke

When failing to map the user buffer we should return the actual
error code, avoiding the usage of DRIVER_ERROR.

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 f5e0ad65e86a..1ab1b8d9641c 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -485,9 +485,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(q, disk, rq, 0);
-- 
2.16.4


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

* [PATCH 20/24] scsi_dh_alua: do not interpret DRIVER_ERROR
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
                   ` (18 preceding siblings ...)
  2019-10-21  9:53 ` [PATCH 19/24] scsi_ioctl: return error code when blk_map_user() fails Hannes Reinecke
@ 2019-10-21  9:53 ` Hannes Reinecke
  2019-10-21  9:53 ` [PATCH 21/24] xen-scsiback: stop using DRIVER_ERROR Hannes Reinecke
                   ` (4 subsequent siblings)
  24 siblings, 0 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:53 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	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 4971104b1817..9feea102468b 100644
--- a/drivers/scsi/device_handler/scsi_dh_alua.c
+++ b/drivers/scsi/device_handler/scsi_dh_alua.c
@@ -552,8 +552,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;
 		}
 
@@ -766,8 +764,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.16.4


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

* [PATCH 21/24] xen-scsiback: stop using DRIVER_ERROR
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
                   ` (19 preceding siblings ...)
  2019-10-21  9:53 ` [PATCH 20/24] scsi_dh_alua: do not interpret DRIVER_ERROR Hannes Reinecke
@ 2019-10-21  9:53 ` Hannes Reinecke
  2019-10-21  9:53 ` [PATCH 22/24] scsi: " Hannes Reinecke
                   ` (3 subsequent siblings)
  24 siblings, 0 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:53 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	linux-scsi, Hannes Reinecke

Return DID_ERROR instead of DRIVER_ERROR for internal failures.

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

diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c
index e130b4426c62..6a12c3627098 100644
--- a/drivers/xen/xen-scsiback.c
+++ b/drivers/xen/xen-scsiback.c
@@ -260,10 +260,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 drv=0\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)
@@ -757,7 +757,7 @@ 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,
@@ -770,7 +770,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);
@@ -785,7 +785,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.16.4


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

* [PATCH 22/24] scsi: stop using DRIVER_ERROR
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
                   ` (20 preceding siblings ...)
  2019-10-21  9:53 ` [PATCH 21/24] xen-scsiback: stop using DRIVER_ERROR Hannes Reinecke
@ 2019-10-21  9:53 ` Hannes Reinecke
  2019-10-21  9:53 ` [PATCH 23/24] scsi: Kill DRIVER_MEDIA, DRIVER_SOFT, and DRIVER_BUSY Hannes Reinecke
                   ` (2 subsequent siblings)
  24 siblings, 0 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:53 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	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/scsi/ch.c           |  2 ++
 drivers/scsi/constants.c    |  2 +-
 drivers/scsi/scsi.c         |  2 ++
 drivers/scsi/scsi_lib.c     | 15 +++++++++------
 drivers/scsi/ufs/ufshcd.c   |  4 +---
 include/scsi/scsi.h         |  1 -
 include/trace/events/scsi.h |  3 +--
 7 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index 380a519b1757..173f2c065116 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -199,6 +199,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 (status_byte(result) == SAM_STAT_CHECK_CONDITION) {
 		if (debug)
 			scsi_print_sense_hdr(ch->device, ch->name, &sshdr);
diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c
index 1cee98534bfd..57c544fd8c6b 100644
--- a/drivers/scsi/constants.c
+++ b/drivers/scsi/constants.c
@@ -407,7 +407,7 @@ static const char * const hostbyte_table[]={
 "DID_NEXUS_FAILURE" };
 
 static const char * const driverbyte_table[]={
-"DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT",  "DRIVER_MEDIA", "DRIVER_ERROR"};
+"DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT",  "DRIVER_MEDIA"};
 
 const char *scsi_hostbyte_string(int result)
 {
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index d6ecb773c512..96a204ff5bf4 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -509,6 +509,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_lib.c b/drivers/scsi/scsi_lib.c
index eac14ecc82dc..530d6a6815a1 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -253,19 +253,22 @@ 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, BLK_MQ_REQ_PREEMPT);
 	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/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index e411aadb6da7..87a11289202e 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -7602,9 +7602,7 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba,
 			    pwr_mode, ret);
 		if (scsi_sense_valid(&sshdr))
 			scsi_print_sense_hdr(sdp, NULL, &sshdr);
-	}
-
-	if (!ret)
+	} else
 		hba->curr_dev_pwr_mode = pwr_mode;
 out:
 	scsi_device_put(sdp);
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
index 57caf1f91673..b7960ec46c9c 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -168,7 +168,6 @@ static inline int scsi_is_wlun(u64 lun)
 #define DRIVER_BUSY         0x01
 #define DRIVER_SOFT         0x02
 #define DRIVER_MEDIA        0x03
-#define DRIVER_ERROR        0x04
 
 /*
  * Internal return values.
diff --git a/include/trace/events/scsi.h b/include/trace/events/scsi.h
index 83bc7d97a469..b2d3ce9e3990 100644
--- a/include/trace/events/scsi.h
+++ b/include/trace/events/scsi.h
@@ -130,8 +130,7 @@
 		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_MEDIA))
 
 #define scsi_msgbyte_name(result)	{ result, #result }
 #define show_msgbyte_name(val)					\
-- 
2.16.4


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

* [PATCH 23/24] scsi: Kill DRIVER_MEDIA, DRIVER_SOFT, and DRIVER_BUSY
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
                   ` (21 preceding siblings ...)
  2019-10-21  9:53 ` [PATCH 22/24] scsi: " Hannes Reinecke
@ 2019-10-21  9:53 ` Hannes Reinecke
  2019-10-21  9:53 ` [PATCH 24/24] scsi: Drop now obsolete driver_byte definitions Hannes Reinecke
  2019-10-21 18:32 ` [PATCH RFC 00/24] scsi: Revamp result values Douglas Gilbert
  24 siblings, 0 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:53 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	linux-scsi, Hannes Reinecke

Unused.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/message/fusion/mptscsih.c | 2 +-
 drivers/scsi/constants.c          | 2 +-
 include/scsi/scsi.h               | 8 --------
 include/trace/events/scsi.h       | 5 +----
 4 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
index f0737c57ed5f..0064547cef1a 100644
--- a/drivers/message/fusion/mptscsih.c
+++ b/drivers/message/fusion/mptscsih.c
@@ -703,7 +703,7 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
 		case MPI_IOCSTATUS_BUSY:			/* 0x0002 */
 		case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES:	/* 0x0006 */
 			/* CHECKME!
-			 * Maybe: DRIVER_BUSY | SUGGEST_RETRY | DID_SOFT_ERROR (retry)
+			 * Maybe: SUGGEST_RETRY | DID_SOFT_ERROR (retry)
 			 * But not: DID_BUS_BUSY lest one risk
 			 * killing interrupt handler:-(
 			 */
diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c
index 57c544fd8c6b..be7eacb67841 100644
--- a/drivers/scsi/constants.c
+++ b/drivers/scsi/constants.c
@@ -407,7 +407,7 @@ static const char * const hostbyte_table[]={
 "DID_NEXUS_FAILURE" };
 
 static const char * const driverbyte_table[]={
-"DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT",  "DRIVER_MEDIA"};
+"DRIVER_OK"};
 
 const char *scsi_hostbyte_string(int result)
 {
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
index b7960ec46c9c..d10308651f0a 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -161,14 +161,6 @@ static inline int scsi_is_wlun(u64 lun)
 #define DID_MEDIUM_ERROR  0x13  /* Medium error */
 #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
-
 /*
  * Internal return values.
  */
diff --git a/include/trace/events/scsi.h b/include/trace/events/scsi.h
index b2d3ce9e3990..5984db6996bb 100644
--- a/include/trace/events/scsi.h
+++ b/include/trace/events/scsi.h
@@ -127,10 +127,7 @@
 #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_OK))
 
 #define scsi_msgbyte_name(result)	{ result, #result }
 #define show_msgbyte_name(val)					\
-- 
2.16.4


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

* [PATCH 24/24] scsi: Drop now obsolete driver_byte definitions
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
                   ` (22 preceding siblings ...)
  2019-10-21  9:53 ` [PATCH 23/24] scsi: Kill DRIVER_MEDIA, DRIVER_SOFT, and DRIVER_BUSY Hannes Reinecke
@ 2019-10-21  9:53 ` Hannes Reinecke
  2019-10-21 18:32 ` [PATCH RFC 00/24] scsi: Revamp result values Douglas Gilbert
  24 siblings, 0 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-21  9:53 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	linux-scsi, Hannes Reinecke

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.txt |  3 +--
 block/bsg-lib.c                         |  2 +-
 block/bsg.c                             |  2 +-
 block/scsi_ioctl.c                      |  2 +-
 drivers/scsi/constants.c                | 14 --------------
 drivers/scsi/scsi_logging.c             | 10 ++--------
 drivers/scsi/sd.c                       |  9 ++++-----
 drivers/scsi/sd_zbc.c                   |  4 ++--
 drivers/scsi/sg.c                       |  5 ++---
 drivers/scsi/sr.c                       |  2 +-
 drivers/scsi/sr_ioctl.c                 |  2 +-
 drivers/scsi/st.c                       |  4 ++--
 include/scsi/scsi.h                     |  3 ---
 include/scsi/scsi_cmnd.h                |  4 ----
 include/trace/events/scsi.h             |  7 +------
 15 files changed, 19 insertions(+), 54 deletions(-)

diff --git a/Documentation/scsi/scsi_mid_low_api.txt b/Documentation/scsi/scsi_mid_low_api.txt
index c1dd4939f4ae..ab072fff5fb8 100644
--- a/Documentation/scsi/scsi_mid_low_api.txt
+++ b/Documentation/scsi/scsi_mid_low_api.txt
@@ -1160,8 +1160,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')
                    is set to CHECK_CONDITION (2). When CHECK_CONDITION is
diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 347dda16c2f4..bc0c813b3a99 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 833c44b3d458..dcde05348a48 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 1ab1b8d9641c..b8b9b72fab2a 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -252,7 +252,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 be7eacb67841..924131ea0b11 100644
--- a/drivers/scsi/constants.c
+++ b/drivers/scsi/constants.c
@@ -406,9 +406,6 @@ static const char * const hostbyte_table[]={
 "DID_TRANSPORT_DISRUPTED", "DID_TRANSPORT_FAILFAST", "DID_TARGET_FAILURE",
 "DID_NEXUS_FAILURE" };
 
-static const char * const driverbyte_table[]={
-"DRIVER_OK"};
-
 const char *scsi_hostbyte_string(int result)
 {
 	const char *hb_string = NULL;
@@ -420,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 c91fa3feb930..d0b646430375 100644
--- a/drivers/scsi/scsi_logging.c
+++ b/drivers/scsi/scsi_logging.c
@@ -389,7 +389,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);
@@ -430,13 +429,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 220990183b6b..4599954b7bb0 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -3716,16 +3716,15 @@ static 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/sd_zbc.c b/drivers/scsi/sd_zbc.c
index de4019dc0f0b..d96a2506d965 100644
--- a/drivers/scsi/sd_zbc.c
+++ b/drivers/scsi/sd_zbc.c
@@ -87,9 +87,9 @@ static int sd_zbc_do_report_zones(struct scsi_disk *sdkp, unsigned char *buf,
 				  timeout, SD_MAX_RETRIES, NULL);
 	if (result) {
 		sd_printk(KERN_ERR, sdkp,
-			  "REPORT ZONES lba %llu failed with %d/%d\n",
+			  "REPORT ZONES lba %llu failed with %d/0\n",
 			  (unsigned long long)lba,
-			  host_byte(result), driver_byte(result));
+			  host_byte(result));
 		return -EIO;
 	}
 
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index c85e095be337..cc2806991e5e 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1351,7 +1351,7 @@ sg_rq_end_io(struct request *rq, blk_status_t status)
 		srp->header.masked_status = status_byte(result) >> 1;
 		srp->header.msg_status = msg_byte(result);
 		srp->header.host_status = host_byte(result);
-		srp->header.driver_status = driver_byte(result);
+		srp->header.driver_status = 0;
 		if ((sdp->sgdebug > 0) &&
 		    ((SAM_STAT_CHECK_CONDITION == srp->header.status) ||
 		     (SAM_STAT_COMMAND_TERMINATED == srp->header.status)))
@@ -1359,8 +1359,7 @@ sg_rq_end_io(struct request *rq, blk_status_t status)
 					   SCSI_SENSE_BUFFERSIZE);
 
 		/* Following if statement is a patch supplied by Eric Youngdale */
-		if (driver_byte(result) != 0
-		    && scsi_normalize_sense(sense, SCSI_SENSE_BUFFERSIZE, &sshdr)
+		if (scsi_normalize_sense(sense, SCSI_SENSE_BUFFERSIZE, &sshdr)
 		    && !scsi_sense_is_deferred(&sshdr)
 		    && sshdr.sense_key == UNIT_ATTENTION
 		    && sdp->device->removable) {
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 4664fdf75c0f..05969bb1860c 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -336,7 +336,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 ffcf902da390..02bfbbfb6f03 100644
--- a/drivers/scsi/sr_ioctl.c
+++ b/drivers/scsi/sr_ioctl.c
@@ -205,7 +205,7 @@ 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 (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 5f38369cc62f..9ac262d6ccab 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -388,8 +388,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/include/scsi/scsi.h b/include/scsi/scsi.h
index d10308651f0a..a4b6bc9b6722 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -159,7 +159,6 @@ static inline int scsi_is_wlun(u64 lun)
 				 * paths might yield different results */
 #define DID_ALLOC_FAILURE 0x12  /* Space allocation on the device failed */
 #define DID_MEDIUM_ERROR  0x13  /* Medium error */
-#define DRIVER_OK       0x00	/* Driver status                           */
 
 /*
  * Internal return values.
@@ -191,12 +190,10 @@ static inline int scsi_is_wlun(u64 lun)
  *      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)) & 0xff)
 #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 9b9ca629097d..fe1ac844c114 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -322,10 +322,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/trace/events/scsi.h b/include/trace/events/scsi.h
index 5984db6996bb..428cca71c2ba 100644
--- a/include/trace/events/scsi.h
+++ b/include/trace/events/scsi.h
@@ -124,11 +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))
-
 #define scsi_msgbyte_name(result)	{ result, #result }
 #define show_msgbyte_name(val)					\
 	__print_symbolic(val,					\
@@ -319,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.16.4


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

* Re: [PATCH 11/24] advansys: kill driver_defined status byte accessors
  2019-10-21  9:53 ` [PATCH 11/24] advansys: kill driver_defined status byte accessors Hannes Reinecke
@ 2019-10-21 16:37   ` Bart Van Assche
  2019-10-22  6:25     ` Hannes Reinecke
  0 siblings, 1 reply; 63+ messages in thread
From: Bart Van Assche @ 2019-10-21 16:37 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn, linux-scsi

On 10/21/19 2:53 AM, Hannes Reinecke wrote:
> @@ -6021,43 +6015,28 @@ 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);
> -				/*
> -				 * Note: The 'status_byte()' macro used by
> -				 * target drivers defined in scsi.h shifts the
> -				 * status byte returned by host drivers right
> -				 * by 1 bit.  This is why target drivers also
> -				 * use right shifted status byte definitions.
> -				 * For instance target drivers use
> -				 * CHECK_CONDITION, defined to 0x1, instead of
> -				 * the SCSI defined check condition value of
> -				 * 0x2. Host drivers are supposed to return
> -				 * the status byte as it is defined by SCSI.
> -				 */
> -				scp->result = DRIVER_BYTE(DRIVER_SENSE) |
> -				    STATUS_BYTE(scsiqp->scsi_status);
> -			} else {
> -				scp->result = STATUS_BYTE(scsiqp->scsi_status);
>   			}
> +			scp->result = status_byte(scsiqp->scsi_status);
>   			break;

Did you really want to delete the code that sets DRIVER_SENSE?

> @@ -6789,47 +6768,30 @@ 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);
> -				/*
> -				 * Note: The 'status_byte()' macro used by
> -				 * target drivers defined in scsi.h shifts the
> -				 * status byte returned by host drivers right
> -				 * by 1 bit.  This is why target drivers also
> -				 * use right shifted status byte definitions.
> -				 * For instance target drivers use
> -				 * CHECK_CONDITION, defined to 0x1, instead of
> -				 * the SCSI defined check condition value of
> -				 * 0x2. Host drivers are supposed to return
> -				 * the status byte as it is defined by SCSI.
> -				 */
> -				scp->result = DRIVER_BYTE(DRIVER_SENSE) |
> -				    STATUS_BYTE(qdonep->d3.scsi_stat);
> -			} else {
> -				scp->result = STATUS_BYTE(qdonep->d3.scsi_stat);
>   			}
> +			scp->result = status_byte(qdonep->d3.scsi_stat);
>   			break;

Same comment here: did you really want to delete the code that sets DRIVER_SENSE?

Thanks,

Bart.

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

* Re: [PATCH 18/24] st: return error code in st_scsi_execute()
  2019-10-21  9:53 ` [PATCH 18/24] st: return error code in st_scsi_execute() Hannes Reinecke
@ 2019-10-21 16:41   ` Bart Van Assche
  2019-10-22  6:28     ` Hannes Reinecke
  0 siblings, 1 reply; 63+ messages in thread
From: Bart Van Assche @ 2019-10-21 16:41 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn, linux-scsi

On 10/21/19 2:53 AM, Hannes Reinecke wrote:
> We should return the actual error code in st_scsi_execute(),
> avoiding the need to use DRIVER_ERROR.
> 
> 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 e3266a64a477..5f38369cc62f 100644
> --- a/drivers/scsi/st.c
> +++ b/drivers/scsi/st.c
> @@ -549,7 +549,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;
>   
> @@ -560,7 +560,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;
>   		}
>   	}

The patch description looks confusing to me. Is it perhaps because the 
caller compares the st_scsi_execute() return value with zero and doesn't 
use the return value in any other way that it is fine to return an 
integer error code instead of a SCSI status?

Thanks,

Bart.

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

* Re: [PATCH 19/24] scsi_ioctl: return error code when blk_map_user() fails
  2019-10-21  9:53 ` [PATCH 19/24] scsi_ioctl: return error code when blk_map_user() fails Hannes Reinecke
@ 2019-10-21 16:44   ` Bart Van Assche
  2019-10-22  6:32     ` Hannes Reinecke
  0 siblings, 1 reply; 63+ messages in thread
From: Bart Van Assche @ 2019-10-21 16:44 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn, linux-scsi

On 10/21/19 2:53 AM, Hannes Reinecke wrote:
> When failing to map the user buffer we should return the actual
> error code, avoiding the usage of DRIVER_ERROR.
> 
> 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 f5e0ad65e86a..1ab1b8d9641c 100644
> --- a/block/scsi_ioctl.c
> +++ b/block/scsi_ioctl.c
> @@ -485,9 +485,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(q, disk, rq, 0);

Since sg_scsi_ioctl() is used to implement SCSI_IOCTL_SEND_COMMAND, does 
this patch change the ABI between user space and kernel in a 
backwards-incompatible way?

Thanks,

Bart.


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

* Re: [PATCH 09/24] scsi: Kill obsolete linux-specific status codes
  2019-10-21  9:53 ` [PATCH 09/24] scsi: Kill obsolete linux-specific status codes Hannes Reinecke
@ 2019-10-21 18:12     ` kbuild test robot
  2019-10-21 18:56     ` kbuild test robot
  1 sibling, 0 replies; 63+ messages in thread
From: kbuild test robot @ 2019-10-21 18:12 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: kbuild-all, Martin K. Petersen, Christoph Hellwig,
	James Bottomley, Johannes Thumshirn, linux-scsi, Hannes Reinecke

[-- Attachment #1: Type: text/plain, Size: 5178 bytes --]

Hi Hannes,

I love your patch! Yet something to improve:

[auto build test ERROR on mkp-scsi/for-next]
[cannot apply to v5.4-rc4 next-20191021]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Hannes-Reinecke/scsi-Revamp-result-values/20191022-004918
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: sh-allmodconfig (attached as .config)
compiler: sh4-linux-gcc (GCC) 7.4.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=7.4.0 make.cross ARCH=sh 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/scsi/pcmcia/nsp_cs.c: In function 'nsp_queuecommand_lck':
>> drivers/scsi/pcmcia/nsp_cs.c:226:22: error: 'CHECK_CONDITION' undeclared (first use in this function); did you mean 'SEC_CONVERSION'?
     SCpnt->SCp.Status = CHECK_CONDITION;
                         ^~~~~~~~~~~~~~~
                         SEC_CONVERSION
   drivers/scsi/pcmcia/nsp_cs.c:226:22: note: each undeclared identifier is reported only once for each function it appears in

vim +226 drivers/scsi/pcmcia/nsp_cs.c

^1da177e4c3f41 Linus Torvalds 2005-04-16  221  
^1da177e4c3f41 Linus Torvalds 2005-04-16  222  	show_command(SCpnt);
^1da177e4c3f41 Linus Torvalds 2005-04-16  223  
^1da177e4c3f41 Linus Torvalds 2005-04-16  224  	data->CurrentSC		= SCpnt;
^1da177e4c3f41 Linus Torvalds 2005-04-16  225  
^1da177e4c3f41 Linus Torvalds 2005-04-16 @226  	SCpnt->SCp.Status	= CHECK_CONDITION;
^1da177e4c3f41 Linus Torvalds 2005-04-16  227  	SCpnt->SCp.Message	= 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16  228  	SCpnt->SCp.have_data_in = IO_UNKNOWN;
^1da177e4c3f41 Linus Torvalds 2005-04-16  229  	SCpnt->SCp.sent_command = 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16  230  	SCpnt->SCp.phase	= PH_UNDETERMINED;
040cd23242413a Boaz Harrosh   2007-08-16  231  	scsi_set_resid(SCpnt, scsi_bufflen(SCpnt));
^1da177e4c3f41 Linus Torvalds 2005-04-16  232  
^1da177e4c3f41 Linus Torvalds 2005-04-16  233  	/* setup scratch area
^1da177e4c3f41 Linus Torvalds 2005-04-16  234  	   SCp.ptr		: buffer pointer
^1da177e4c3f41 Linus Torvalds 2005-04-16  235  	   SCp.this_residual	: buffer length
^1da177e4c3f41 Linus Torvalds 2005-04-16  236  	   SCp.buffer		: next buffer
^1da177e4c3f41 Linus Torvalds 2005-04-16  237  	   SCp.buffers_residual : left buffers in list
^1da177e4c3f41 Linus Torvalds 2005-04-16  238  	   SCp.phase		: current state of the command */
040cd23242413a Boaz Harrosh   2007-08-16  239  	if (scsi_bufflen(SCpnt)) {
040cd23242413a Boaz Harrosh   2007-08-16  240  		SCpnt->SCp.buffer	    = scsi_sglist(SCpnt);
^1da177e4c3f41 Linus Torvalds 2005-04-16  241  		SCpnt->SCp.ptr		    = BUFFER_ADDR;
^1da177e4c3f41 Linus Torvalds 2005-04-16  242  		SCpnt->SCp.this_residual    = SCpnt->SCp.buffer->length;
040cd23242413a Boaz Harrosh   2007-08-16  243  		SCpnt->SCp.buffers_residual = scsi_sg_count(SCpnt) - 1;
^1da177e4c3f41 Linus Torvalds 2005-04-16  244  	} else {
040cd23242413a Boaz Harrosh   2007-08-16  245  		SCpnt->SCp.ptr		    = NULL;
040cd23242413a Boaz Harrosh   2007-08-16  246  		SCpnt->SCp.this_residual    = 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16  247  		SCpnt->SCp.buffer	    = NULL;
^1da177e4c3f41 Linus Torvalds 2005-04-16  248  		SCpnt->SCp.buffers_residual = 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16  249  	}
^1da177e4c3f41 Linus Torvalds 2005-04-16  250  
^1da177e4c3f41 Linus Torvalds 2005-04-16  251  	if (nsphw_start_selection(SCpnt) == FALSE) {
^1da177e4c3f41 Linus Torvalds 2005-04-16  252  		nsp_dbg(NSP_DEBUG_QUEUECOMMAND, "selection fail");
^1da177e4c3f41 Linus Torvalds 2005-04-16  253  		SCpnt->result   = DID_BUS_BUSY << 16;
^1da177e4c3f41 Linus Torvalds 2005-04-16  254  		nsp_scsi_done(SCpnt);
^1da177e4c3f41 Linus Torvalds 2005-04-16  255  		return 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16  256  	}
^1da177e4c3f41 Linus Torvalds 2005-04-16  257  
^1da177e4c3f41 Linus Torvalds 2005-04-16  258  
^1da177e4c3f41 Linus Torvalds 2005-04-16  259  	//nsp_dbg(NSP_DEBUG_QUEUECOMMAND, "out");
^1da177e4c3f41 Linus Torvalds 2005-04-16  260  #ifdef NSP_DEBUG
^1da177e4c3f41 Linus Torvalds 2005-04-16  261  	data->CmdId++;
^1da177e4c3f41 Linus Torvalds 2005-04-16  262  #endif
^1da177e4c3f41 Linus Torvalds 2005-04-16  263  	return 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16  264  }
^1da177e4c3f41 Linus Torvalds 2005-04-16  265  

:::::: The code at line 226 was first introduced by commit
:::::: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Linux-2.6.12-rc2

:::::: TO: Linus Torvalds <torvalds@ppc970.osdl.org>
:::::: CC: Linus Torvalds <torvalds@ppc970.osdl.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 52234 bytes --]

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

* Re: [PATCH 09/24] scsi: Kill obsolete linux-specific status codes
@ 2019-10-21 18:12     ` kbuild test robot
  0 siblings, 0 replies; 63+ messages in thread
From: kbuild test robot @ 2019-10-21 18:12 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 5267 bytes --]

Hi Hannes,

I love your patch! Yet something to improve:

[auto build test ERROR on mkp-scsi/for-next]
[cannot apply to v5.4-rc4 next-20191021]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Hannes-Reinecke/scsi-Revamp-result-values/20191022-004918
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: sh-allmodconfig (attached as .config)
compiler: sh4-linux-gcc (GCC) 7.4.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=7.4.0 make.cross ARCH=sh 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/scsi/pcmcia/nsp_cs.c: In function 'nsp_queuecommand_lck':
>> drivers/scsi/pcmcia/nsp_cs.c:226:22: error: 'CHECK_CONDITION' undeclared (first use in this function); did you mean 'SEC_CONVERSION'?
     SCpnt->SCp.Status = CHECK_CONDITION;
                         ^~~~~~~~~~~~~~~
                         SEC_CONVERSION
   drivers/scsi/pcmcia/nsp_cs.c:226:22: note: each undeclared identifier is reported only once for each function it appears in

vim +226 drivers/scsi/pcmcia/nsp_cs.c

^1da177e4c3f41 Linus Torvalds 2005-04-16  221  
^1da177e4c3f41 Linus Torvalds 2005-04-16  222  	show_command(SCpnt);
^1da177e4c3f41 Linus Torvalds 2005-04-16  223  
^1da177e4c3f41 Linus Torvalds 2005-04-16  224  	data->CurrentSC		= SCpnt;
^1da177e4c3f41 Linus Torvalds 2005-04-16  225  
^1da177e4c3f41 Linus Torvalds 2005-04-16 @226  	SCpnt->SCp.Status	= CHECK_CONDITION;
^1da177e4c3f41 Linus Torvalds 2005-04-16  227  	SCpnt->SCp.Message	= 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16  228  	SCpnt->SCp.have_data_in = IO_UNKNOWN;
^1da177e4c3f41 Linus Torvalds 2005-04-16  229  	SCpnt->SCp.sent_command = 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16  230  	SCpnt->SCp.phase	= PH_UNDETERMINED;
040cd23242413a Boaz Harrosh   2007-08-16  231  	scsi_set_resid(SCpnt, scsi_bufflen(SCpnt));
^1da177e4c3f41 Linus Torvalds 2005-04-16  232  
^1da177e4c3f41 Linus Torvalds 2005-04-16  233  	/* setup scratch area
^1da177e4c3f41 Linus Torvalds 2005-04-16  234  	   SCp.ptr		: buffer pointer
^1da177e4c3f41 Linus Torvalds 2005-04-16  235  	   SCp.this_residual	: buffer length
^1da177e4c3f41 Linus Torvalds 2005-04-16  236  	   SCp.buffer		: next buffer
^1da177e4c3f41 Linus Torvalds 2005-04-16  237  	   SCp.buffers_residual : left buffers in list
^1da177e4c3f41 Linus Torvalds 2005-04-16  238  	   SCp.phase		: current state of the command */
040cd23242413a Boaz Harrosh   2007-08-16  239  	if (scsi_bufflen(SCpnt)) {
040cd23242413a Boaz Harrosh   2007-08-16  240  		SCpnt->SCp.buffer	    = scsi_sglist(SCpnt);
^1da177e4c3f41 Linus Torvalds 2005-04-16  241  		SCpnt->SCp.ptr		    = BUFFER_ADDR;
^1da177e4c3f41 Linus Torvalds 2005-04-16  242  		SCpnt->SCp.this_residual    = SCpnt->SCp.buffer->length;
040cd23242413a Boaz Harrosh   2007-08-16  243  		SCpnt->SCp.buffers_residual = scsi_sg_count(SCpnt) - 1;
^1da177e4c3f41 Linus Torvalds 2005-04-16  244  	} else {
040cd23242413a Boaz Harrosh   2007-08-16  245  		SCpnt->SCp.ptr		    = NULL;
040cd23242413a Boaz Harrosh   2007-08-16  246  		SCpnt->SCp.this_residual    = 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16  247  		SCpnt->SCp.buffer	    = NULL;
^1da177e4c3f41 Linus Torvalds 2005-04-16  248  		SCpnt->SCp.buffers_residual = 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16  249  	}
^1da177e4c3f41 Linus Torvalds 2005-04-16  250  
^1da177e4c3f41 Linus Torvalds 2005-04-16  251  	if (nsphw_start_selection(SCpnt) == FALSE) {
^1da177e4c3f41 Linus Torvalds 2005-04-16  252  		nsp_dbg(NSP_DEBUG_QUEUECOMMAND, "selection fail");
^1da177e4c3f41 Linus Torvalds 2005-04-16  253  		SCpnt->result   = DID_BUS_BUSY << 16;
^1da177e4c3f41 Linus Torvalds 2005-04-16  254  		nsp_scsi_done(SCpnt);
^1da177e4c3f41 Linus Torvalds 2005-04-16  255  		return 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16  256  	}
^1da177e4c3f41 Linus Torvalds 2005-04-16  257  
^1da177e4c3f41 Linus Torvalds 2005-04-16  258  
^1da177e4c3f41 Linus Torvalds 2005-04-16  259  	//nsp_dbg(NSP_DEBUG_QUEUECOMMAND, "out");
^1da177e4c3f41 Linus Torvalds 2005-04-16  260  #ifdef NSP_DEBUG
^1da177e4c3f41 Linus Torvalds 2005-04-16  261  	data->CmdId++;
^1da177e4c3f41 Linus Torvalds 2005-04-16  262  #endif
^1da177e4c3f41 Linus Torvalds 2005-04-16  263  	return 0;
^1da177e4c3f41 Linus Torvalds 2005-04-16  264  }
^1da177e4c3f41 Linus Torvalds 2005-04-16  265  

:::::: The code at line 226 was first introduced by commit
:::::: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Linux-2.6.12-rc2

:::::: TO: Linus Torvalds <torvalds@ppc970.osdl.org>
:::::: CC: Linus Torvalds <torvalds@ppc970.osdl.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 52234 bytes --]

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

* Re: [PATCH RFC 00/24] scsi: Revamp result values
  2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
                   ` (23 preceding siblings ...)
  2019-10-21  9:53 ` [PATCH 24/24] scsi: Drop now obsolete driver_byte definitions Hannes Reinecke
@ 2019-10-21 18:32 ` Douglas Gilbert
  2019-10-21 23:20   ` Finn Thain
  2019-10-22  6:24   ` Hannes Reinecke
  24 siblings, 2 replies; 63+ messages in thread
From: Douglas Gilbert @ 2019-10-21 18:32 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn, linux-scsi

On 2019-10-21 5:52 a.m., Hannes Reinecke wrote:
> Hi all,
> 
> the 'result' field in the SCSI command is defined as having
> 4 fields. The top byte is declared as a 'driver_byte', where the
> driver can signal some internal status back to the midlayer.
> However, there is quite a bit of overlap between the driver_byte
> and the host_byte, resulting in the driver_byte being used in
> very few places, and mostly in legacy drivers.
> Additionally, we have _two_ sets of definitions for the
> last byte (status byte), which can specified either in SAM terms
> or in the linux-specific terms, which are shifted right by one
> from the SAM ones.
> Needless to say, the linux-specific ones are declared obsolete
> for years now.
> And to make the confusion complete, both the status byte and
> the driver byte have a byte for a valid sense code, resulting
> in quite some confusion which of those bits to check.
> 
> This patchset does several things:
> - remove the linux-specific status byte definitions, and use
>    the SAM values throughout
> - replace the driver-byte values with either SAM ones (for sense
>    code checking) or host-byte definitions
> - remove the driver-byte definitions

This is a brave change proposal. The masked_status has been tricked
up so it won't break user code. However the driver byte is exposed
by the sg v2, v3 and v4 interfaces which means via bsg device nodes,
sg devices nodes and many other block storage device nodes (e.g.
/dev/sdc and /dev/st1) via:
       ioctl(<storage_dev>, SG_IO, ptr_to_v3_interface) .

So if there is any user space code out there that checks the
driver byte (e.g. 'sg_io_hdr::driver_status & DRIVER_SENSE') do we
have a problem?

If so, we could hack the DRIVER_SENSE case *** by putting it back
for the user space to see when the driver (e.g. sg) knows there
is sense data. What about the other values?

> As usual, comments and reviews are welcome.

It is hard to make an omelette without breaking some eggs.

Doug Gilbert

> Please note, commit 66cf50e65b18 ("scsi: qla2xxx: fixup incorrect
> usage of host_byte") from 5.4/scsi-fixes is a prerequisite for
> this patch series.

<snip>

*** Here is a snippet from sg3_utils library code:

     if ((SAM_STAT_CHECK_CONDITION == scsi_status) ||
         (SAM_STAT_COMMAND_TERMINATED == scsi_status) ||
         (SG_LIB_DRIVER_SENSE == masked_driver_status))
         return sg_err_category_sense(sense_buffer, sb_len);

Due to the logical OR, as long as SAM_STAT_CHECK_CONDITION is set
whenever there is sense, then we don't care about DRIVER_SENSE.

I believe this code comes from the days before auto-sense when say a
READ(6) would fail, send back a CHECK_CONDITION and the host would then
need to issue a REQUEST SENSE command to get the sense data. However
REQUEST SENSE could itself yield a CHECK_CONDITION. Hence DRIVER_SENSE
set, SAM_STAT_CHECK_CONDITION clear could be interpreted as the
initial command failing and the follow-up REQUEST SENSE succeeded; if
they are both set, then both commands failed (e.g. the disk has gone
away).

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

* Re: [PATCH 03/24] wd33c93: use SCSI status
  2019-10-21  9:53 ` [PATCH 03/24] wd33c93: use SCSI status Hannes Reinecke
@ 2019-10-21 18:41     ` kbuild test robot
  2019-10-21 23:16   ` Finn Thain
  1 sibling, 0 replies; 63+ messages in thread
From: kbuild test robot @ 2019-10-21 18:41 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: kbuild-all, Martin K. Petersen, Christoph Hellwig,
	James Bottomley, Johannes Thumshirn, linux-scsi, Hannes Reinecke

[-- Attachment #1: Type: text/plain, Size: 6404 bytes --]

Hi Hannes,

I love your patch! Perhaps something to improve:

[auto build test WARNING on mkp-scsi/for-next]
[also build test WARNING on v5.4-rc4 next-20191021]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Hannes-Reinecke/scsi-Revamp-result-values/20191022-004918
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: m68k-multi_defconfig (attached as .config)
compiler: m68k-linux-gcc (GCC) 7.4.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=7.4.0 make.cross ARCH=m68k 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/scsi/wd33c93.c: In function 'wd33c93_intr':
>> drivers/scsi/wd33c93.c:1297:19: warning: passing argument 1 of 'set_host_byte' makes pointer from integer without a cast [-Wint-conversion]
        set_host_byte(cmd->result, DID_ERROR);
                      ^~~
   In file included from drivers/scsi/wd33c93.c:79:0:
   include/scsi/scsi_cmnd.h:315:20: note: expected 'struct scsi_cmnd *' but argument is of type 'int'
    static inline void set_host_byte(struct scsi_cmnd *cmd, char status)
                       ^~~~~~~~~~~~~

vim +/set_host_byte +1297 drivers/scsi/wd33c93.c

  1200	
  1201		case CSR_SDP:
  1202			DB(DB_INTR, printk("SDP"))
  1203			    hostdata->state = S_RUNNING_LEVEL2;
  1204			write_wd33c93(regs, WD_COMMAND_PHASE, 0x41);
  1205			write_wd33c93_cmd(regs, WD_CMD_SEL_ATN_XFER);
  1206			spin_unlock_irqrestore(&hostdata->lock, flags);
  1207			break;
  1208	
  1209		case CSR_XFER_DONE | PHS_MESS_OUT:
  1210		case CSR_UNEXP | PHS_MESS_OUT:
  1211		case CSR_SRV_REQ | PHS_MESS_OUT:
  1212			DB(DB_INTR, printk("MSG_OUT="))
  1213	
  1214	/* To get here, we've probably requested MESSAGE_OUT and have
  1215	 * already put the correct bytes in outgoing_msg[] and filled
  1216	 * in outgoing_len. We simply send them out to the SCSI bus.
  1217	 * Sometimes we get MESSAGE_OUT phase when we're not expecting
  1218	 * it - like when our SDTR message is rejected by a target. Some
  1219	 * targets send the REJECT before receiving all of the extended
  1220	 * message, and then seem to go back to MESSAGE_OUT for a byte
  1221	 * or two. Not sure why, or if I'm doing something wrong to
  1222	 * cause this to happen. Regardless, it seems that sending
  1223	 * NOP messages in these situations results in no harm and
  1224	 * makes everyone happy.
  1225	 */
  1226			    if (hostdata->outgoing_len == 0) {
  1227				hostdata->outgoing_len = 1;
  1228				hostdata->outgoing_msg[0] = NOP;
  1229			}
  1230			transfer_pio(regs, hostdata->outgoing_msg,
  1231				     hostdata->outgoing_len, DATA_OUT_DIR, hostdata);
  1232			DB(DB_INTR, printk("%02x", hostdata->outgoing_msg[0]))
  1233			    hostdata->outgoing_len = 0;
  1234			hostdata->state = S_CONNECTED;
  1235			spin_unlock_irqrestore(&hostdata->lock, flags);
  1236			break;
  1237	
  1238		case CSR_UNEXP_DISC:
  1239	
  1240	/* I think I've seen this after a request-sense that was in response
  1241	 * to an error condition, but not sure. We certainly need to do
  1242	 * something when we get this interrupt - the question is 'what?'.
  1243	 * Let's think positively, and assume some command has finished
  1244	 * in a legal manner (like a command that provokes a request-sense),
  1245	 * so we treat it as a normal command-complete-disconnect.
  1246	 */
  1247	
  1248	/* Make sure that reselection is enabled at this point - it may
  1249	 * have been turned off for the command that just completed.
  1250	 */
  1251	
  1252			write_wd33c93(regs, WD_SOURCE_ID, SRCID_ER);
  1253			if (cmd == NULL) {
  1254				printk(" - Already disconnected! ");
  1255				hostdata->state = S_UNCONNECTED;
  1256				spin_unlock_irqrestore(&hostdata->lock, flags);
  1257				return;
  1258			}
  1259			DB(DB_INTR, printk("UNEXP_DISC"))
  1260			    hostdata->connected = NULL;
  1261			hostdata->busy[cmd->device->id] &= ~(1 << (cmd->device->lun & 0xff));
  1262			hostdata->state = S_UNCONNECTED;
  1263			if (cmd->cmnd[0] == REQUEST_SENSE && cmd->SCp.Status != SAM_STAT_GOOD)
  1264				set_host_byte(cmd, DID_ERROR);
  1265			else
  1266				cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
  1267			cmd->scsi_done(cmd);
  1268	
  1269	/* We are no longer connected to a target - check to see if
  1270	 * there are commands waiting to be executed.
  1271	 */
  1272			/* look above for comments on scsi_done() */
  1273			spin_unlock_irqrestore(&hostdata->lock, flags);
  1274			wd33c93_execute(instance);
  1275			break;
  1276	
  1277		case CSR_DISC:
  1278	
  1279	/* Make sure that reselection is enabled at this point - it may
  1280	 * have been turned off for the command that just completed.
  1281	 */
  1282	
  1283			write_wd33c93(regs, WD_SOURCE_ID, SRCID_ER);
  1284			DB(DB_INTR, printk("DISC"))
  1285			    if (cmd == NULL) {
  1286				printk(" - Already disconnected! ");
  1287				hostdata->state = S_UNCONNECTED;
  1288			}
  1289			switch (hostdata->state) {
  1290			case S_PRE_CMP_DISC:
  1291				hostdata->connected = NULL;
  1292				hostdata->busy[cmd->device->id] &= ~(1 << (cmd->device->lun & 0xff));
  1293				hostdata->state = S_UNCONNECTED;
  1294				DB(DB_INTR, printk(":%d", cmd->SCp.Status));
  1295				if (cmd->cmnd[0] == REQUEST_SENSE
  1296				    && cmd->SCp.Status != SAM_STAT_GOOD)
> 1297					set_host_byte(cmd->result, DID_ERROR);
  1298				else
  1299					cmd->result =
  1300					    cmd->SCp.Status | (cmd->SCp.Message << 8);
  1301				cmd->scsi_done(cmd);
  1302				break;
  1303			case S_PRE_TMP_DISC:
  1304			case S_RUNNING_LEVEL2:
  1305				cmd->host_scribble = (uchar *) hostdata->disconnected_Q;
  1306				hostdata->disconnected_Q = cmd;
  1307				hostdata->connected = NULL;
  1308				hostdata->state = S_UNCONNECTED;
  1309	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 14917 bytes --]

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

* Re: [PATCH 03/24] wd33c93: use SCSI status
@ 2019-10-21 18:41     ` kbuild test robot
  0 siblings, 0 replies; 63+ messages in thread
From: kbuild test robot @ 2019-10-21 18:41 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 6554 bytes --]

Hi Hannes,

I love your patch! Perhaps something to improve:

[auto build test WARNING on mkp-scsi/for-next]
[also build test WARNING on v5.4-rc4 next-20191021]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Hannes-Reinecke/scsi-Revamp-result-values/20191022-004918
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: m68k-multi_defconfig (attached as .config)
compiler: m68k-linux-gcc (GCC) 7.4.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=7.4.0 make.cross ARCH=m68k 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/scsi/wd33c93.c: In function 'wd33c93_intr':
>> drivers/scsi/wd33c93.c:1297:19: warning: passing argument 1 of 'set_host_byte' makes pointer from integer without a cast [-Wint-conversion]
        set_host_byte(cmd->result, DID_ERROR);
                      ^~~
   In file included from drivers/scsi/wd33c93.c:79:0:
   include/scsi/scsi_cmnd.h:315:20: note: expected 'struct scsi_cmnd *' but argument is of type 'int'
    static inline void set_host_byte(struct scsi_cmnd *cmd, char status)
                       ^~~~~~~~~~~~~

vim +/set_host_byte +1297 drivers/scsi/wd33c93.c

  1200	
  1201		case CSR_SDP:
  1202			DB(DB_INTR, printk("SDP"))
  1203			    hostdata->state = S_RUNNING_LEVEL2;
  1204			write_wd33c93(regs, WD_COMMAND_PHASE, 0x41);
  1205			write_wd33c93_cmd(regs, WD_CMD_SEL_ATN_XFER);
  1206			spin_unlock_irqrestore(&hostdata->lock, flags);
  1207			break;
  1208	
  1209		case CSR_XFER_DONE | PHS_MESS_OUT:
  1210		case CSR_UNEXP | PHS_MESS_OUT:
  1211		case CSR_SRV_REQ | PHS_MESS_OUT:
  1212			DB(DB_INTR, printk("MSG_OUT="))
  1213	
  1214	/* To get here, we've probably requested MESSAGE_OUT and have
  1215	 * already put the correct bytes in outgoing_msg[] and filled
  1216	 * in outgoing_len. We simply send them out to the SCSI bus.
  1217	 * Sometimes we get MESSAGE_OUT phase when we're not expecting
  1218	 * it - like when our SDTR message is rejected by a target. Some
  1219	 * targets send the REJECT before receiving all of the extended
  1220	 * message, and then seem to go back to MESSAGE_OUT for a byte
  1221	 * or two. Not sure why, or if I'm doing something wrong to
  1222	 * cause this to happen. Regardless, it seems that sending
  1223	 * NOP messages in these situations results in no harm and
  1224	 * makes everyone happy.
  1225	 */
  1226			    if (hostdata->outgoing_len == 0) {
  1227				hostdata->outgoing_len = 1;
  1228				hostdata->outgoing_msg[0] = NOP;
  1229			}
  1230			transfer_pio(regs, hostdata->outgoing_msg,
  1231				     hostdata->outgoing_len, DATA_OUT_DIR, hostdata);
  1232			DB(DB_INTR, printk("%02x", hostdata->outgoing_msg[0]))
  1233			    hostdata->outgoing_len = 0;
  1234			hostdata->state = S_CONNECTED;
  1235			spin_unlock_irqrestore(&hostdata->lock, flags);
  1236			break;
  1237	
  1238		case CSR_UNEXP_DISC:
  1239	
  1240	/* I think I've seen this after a request-sense that was in response
  1241	 * to an error condition, but not sure. We certainly need to do
  1242	 * something when we get this interrupt - the question is 'what?'.
  1243	 * Let's think positively, and assume some command has finished
  1244	 * in a legal manner (like a command that provokes a request-sense),
  1245	 * so we treat it as a normal command-complete-disconnect.
  1246	 */
  1247	
  1248	/* Make sure that reselection is enabled at this point - it may
  1249	 * have been turned off for the command that just completed.
  1250	 */
  1251	
  1252			write_wd33c93(regs, WD_SOURCE_ID, SRCID_ER);
  1253			if (cmd == NULL) {
  1254				printk(" - Already disconnected! ");
  1255				hostdata->state = S_UNCONNECTED;
  1256				spin_unlock_irqrestore(&hostdata->lock, flags);
  1257				return;
  1258			}
  1259			DB(DB_INTR, printk("UNEXP_DISC"))
  1260			    hostdata->connected = NULL;
  1261			hostdata->busy[cmd->device->id] &= ~(1 << (cmd->device->lun & 0xff));
  1262			hostdata->state = S_UNCONNECTED;
  1263			if (cmd->cmnd[0] == REQUEST_SENSE && cmd->SCp.Status != SAM_STAT_GOOD)
  1264				set_host_byte(cmd, DID_ERROR);
  1265			else
  1266				cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
  1267			cmd->scsi_done(cmd);
  1268	
  1269	/* We are no longer connected to a target - check to see if
  1270	 * there are commands waiting to be executed.
  1271	 */
  1272			/* look above for comments on scsi_done() */
  1273			spin_unlock_irqrestore(&hostdata->lock, flags);
  1274			wd33c93_execute(instance);
  1275			break;
  1276	
  1277		case CSR_DISC:
  1278	
  1279	/* Make sure that reselection is enabled at this point - it may
  1280	 * have been turned off for the command that just completed.
  1281	 */
  1282	
  1283			write_wd33c93(regs, WD_SOURCE_ID, SRCID_ER);
  1284			DB(DB_INTR, printk("DISC"))
  1285			    if (cmd == NULL) {
  1286				printk(" - Already disconnected! ");
  1287				hostdata->state = S_UNCONNECTED;
  1288			}
  1289			switch (hostdata->state) {
  1290			case S_PRE_CMP_DISC:
  1291				hostdata->connected = NULL;
  1292				hostdata->busy[cmd->device->id] &= ~(1 << (cmd->device->lun & 0xff));
  1293				hostdata->state = S_UNCONNECTED;
  1294				DB(DB_INTR, printk(":%d", cmd->SCp.Status));
  1295				if (cmd->cmnd[0] == REQUEST_SENSE
  1296				    && cmd->SCp.Status != SAM_STAT_GOOD)
> 1297					set_host_byte(cmd->result, DID_ERROR);
  1298				else
  1299					cmd->result =
  1300					    cmd->SCp.Status | (cmd->SCp.Message << 8);
  1301				cmd->scsi_done(cmd);
  1302				break;
  1303			case S_PRE_TMP_DISC:
  1304			case S_RUNNING_LEVEL2:
  1305				cmd->host_scribble = (uchar *) hostdata->disconnected_Q;
  1306				hostdata->disconnected_Q = cmd;
  1307				hostdata->connected = NULL;
  1308				hostdata->state = S_UNCONNECTED;
  1309	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 14917 bytes --]

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

* Re: [PATCH 09/24] scsi: Kill obsolete linux-specific status codes
  2019-10-21  9:53 ` [PATCH 09/24] scsi: Kill obsolete linux-specific status codes Hannes Reinecke
@ 2019-10-21 18:56     ` kbuild test robot
  2019-10-21 18:56     ` kbuild test robot
  1 sibling, 0 replies; 63+ messages in thread
From: kbuild test robot @ 2019-10-21 18:56 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: kbuild-all, Martin K. Petersen, Christoph Hellwig,
	James Bottomley, Johannes Thumshirn, linux-scsi, Hannes Reinecke

[-- Attachment #1: Type: text/plain, Size: 5067 bytes --]

Hi Hannes,

I love your patch! Yet something to improve:

[auto build test ERROR on mkp-scsi/for-next]
[cannot apply to v5.4-rc4 next-20191021]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Hannes-Reinecke/scsi-Revamp-result-values/20191022-004918
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: powerpc-defconfig (attached as .config)
compiler: powerpc64-linux-gcc (GCC) 7.4.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=7.4.0 make.cross ARCH=powerpc 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/scsi/ibmvscsi/ibmvscsi.c: In function 'handle_cmd_rsp':
>> drivers/scsi/ibmvscsi/ibmvscsi.c:989:39: error: 'CHECK_CONDITION' undeclared (first use in this function); did you mean 'H_MR_CONDITION'?
      if (((cmnd->result >> 1) & 0x1f) == CHECK_CONDITION)
                                          ^~~~~~~~~~~~~~~
                                          H_MR_CONDITION
   drivers/scsi/ibmvscsi/ibmvscsi.c:989:39: note: each undeclared identifier is reported only once for each function it appears in

vim +989 drivers/scsi/ibmvscsi/ibmvscsi.c

^1da177e4c3f41 Linus Torvalds  2005-04-16   968  
^1da177e4c3f41 Linus Torvalds  2005-04-16   969  /**
^1da177e4c3f41 Linus Torvalds  2005-04-16   970   * handle_cmd_rsp: -  Handle responses from commands
^1da177e4c3f41 Linus Torvalds  2005-04-16   971   * @evt_struct:	srp_event_struct to be handled
^1da177e4c3f41 Linus Torvalds  2005-04-16   972   *
^1da177e4c3f41 Linus Torvalds  2005-04-16   973   * Used as a callback by when sending scsi cmds.
^1da177e4c3f41 Linus Torvalds  2005-04-16   974   * Gets called by ibmvscsi_handle_crq()
^1da177e4c3f41 Linus Torvalds  2005-04-16   975  */
^1da177e4c3f41 Linus Torvalds  2005-04-16   976  static void handle_cmd_rsp(struct srp_event_struct *evt_struct)
^1da177e4c3f41 Linus Torvalds  2005-04-16   977  {
^1da177e4c3f41 Linus Torvalds  2005-04-16   978  	struct srp_rsp *rsp = &evt_struct->xfer_iu->srp.rsp;
^1da177e4c3f41 Linus Torvalds  2005-04-16   979  	struct scsi_cmnd *cmnd = evt_struct->cmnd;
^1da177e4c3f41 Linus Torvalds  2005-04-16   980  
ef265673434680 FUJITA Tomonori 2006-03-26   981  	if (unlikely(rsp->opcode != SRP_RSP)) {
^1da177e4c3f41 Linus Torvalds  2005-04-16   982  		if (printk_ratelimit())
6c0a60ec52042e Brian King      2007-06-13   983  			dev_warn(evt_struct->hostdata->dev,
15c9274699e8b6 Tyrel Datwyler  2016-12-07   984  				 "bad SRP RSP type %#02x\n", rsp->opcode);
^1da177e4c3f41 Linus Torvalds  2005-04-16   985  	}
^1da177e4c3f41 Linus Torvalds  2005-04-16   986  	
^1da177e4c3f41 Linus Torvalds  2005-04-16   987  	if (cmnd) {
c3a3b55ae80a0d Brian King      2008-04-25   988  		cmnd->result |= rsp->status;
^1da177e4c3f41 Linus Torvalds  2005-04-16  @989  		if (((cmnd->result >> 1) & 0x1f) == CHECK_CONDITION)
^1da177e4c3f41 Linus Torvalds  2005-04-16   990  			memcpy(cmnd->sense_buffer,
ef265673434680 FUJITA Tomonori 2006-03-26   991  			       rsp->data,
72264eb6dbb909 Anton Blanchard 2013-09-03   992  			       be32_to_cpu(rsp->sense_data_len));
^1da177e4c3f41 Linus Torvalds  2005-04-16   993  		unmap_cmd_data(&evt_struct->iu.srp.cmd, 
4dddbc26c3895e James Bottomley 2005-09-06   994  			       evt_struct, 
^1da177e4c3f41 Linus Torvalds  2005-04-16   995  			       evt_struct->hostdata->dev);
^1da177e4c3f41 Linus Torvalds  2005-04-16   996  
ef265673434680 FUJITA Tomonori 2006-03-26   997  		if (rsp->flags & SRP_RSP_FLAG_DOOVER)
72264eb6dbb909 Anton Blanchard 2013-09-03   998  			scsi_set_resid(cmnd,
72264eb6dbb909 Anton Blanchard 2013-09-03   999  				       be32_to_cpu(rsp->data_out_res_cnt));
ef265673434680 FUJITA Tomonori 2006-03-26  1000  		else if (rsp->flags & SRP_RSP_FLAG_DIOVER)
72264eb6dbb909 Anton Blanchard 2013-09-03  1001  			scsi_set_resid(cmnd, be32_to_cpu(rsp->data_in_res_cnt));
^1da177e4c3f41 Linus Torvalds  2005-04-16  1002  	}
^1da177e4c3f41 Linus Torvalds  2005-04-16  1003  
^1da177e4c3f41 Linus Torvalds  2005-04-16  1004  	if (evt_struct->cmnd_done)
^1da177e4c3f41 Linus Torvalds  2005-04-16  1005  		evt_struct->cmnd_done(cmnd);
^1da177e4c3f41 Linus Torvalds  2005-04-16  1006  }
^1da177e4c3f41 Linus Torvalds  2005-04-16  1007  

:::::: The code at line 989 was first introduced by commit
:::::: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Linux-2.6.12-rc2

:::::: TO: Linus Torvalds <torvalds@ppc970.osdl.org>
:::::: CC: Linus Torvalds <torvalds@ppc970.osdl.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 25428 bytes --]

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

* Re: [PATCH 09/24] scsi: Kill obsolete linux-specific status codes
@ 2019-10-21 18:56     ` kbuild test robot
  0 siblings, 0 replies; 63+ messages in thread
From: kbuild test robot @ 2019-10-21 18:56 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 5151 bytes --]

Hi Hannes,

I love your patch! Yet something to improve:

[auto build test ERROR on mkp-scsi/for-next]
[cannot apply to v5.4-rc4 next-20191021]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Hannes-Reinecke/scsi-Revamp-result-values/20191022-004918
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: powerpc-defconfig (attached as .config)
compiler: powerpc64-linux-gcc (GCC) 7.4.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=7.4.0 make.cross ARCH=powerpc 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/scsi/ibmvscsi/ibmvscsi.c: In function 'handle_cmd_rsp':
>> drivers/scsi/ibmvscsi/ibmvscsi.c:989:39: error: 'CHECK_CONDITION' undeclared (first use in this function); did you mean 'H_MR_CONDITION'?
      if (((cmnd->result >> 1) & 0x1f) == CHECK_CONDITION)
                                          ^~~~~~~~~~~~~~~
                                          H_MR_CONDITION
   drivers/scsi/ibmvscsi/ibmvscsi.c:989:39: note: each undeclared identifier is reported only once for each function it appears in

vim +989 drivers/scsi/ibmvscsi/ibmvscsi.c

^1da177e4c3f41 Linus Torvalds  2005-04-16   968  
^1da177e4c3f41 Linus Torvalds  2005-04-16   969  /**
^1da177e4c3f41 Linus Torvalds  2005-04-16   970   * handle_cmd_rsp: -  Handle responses from commands
^1da177e4c3f41 Linus Torvalds  2005-04-16   971   * @evt_struct:	srp_event_struct to be handled
^1da177e4c3f41 Linus Torvalds  2005-04-16   972   *
^1da177e4c3f41 Linus Torvalds  2005-04-16   973   * Used as a callback by when sending scsi cmds.
^1da177e4c3f41 Linus Torvalds  2005-04-16   974   * Gets called by ibmvscsi_handle_crq()
^1da177e4c3f41 Linus Torvalds  2005-04-16   975  */
^1da177e4c3f41 Linus Torvalds  2005-04-16   976  static void handle_cmd_rsp(struct srp_event_struct *evt_struct)
^1da177e4c3f41 Linus Torvalds  2005-04-16   977  {
^1da177e4c3f41 Linus Torvalds  2005-04-16   978  	struct srp_rsp *rsp = &evt_struct->xfer_iu->srp.rsp;
^1da177e4c3f41 Linus Torvalds  2005-04-16   979  	struct scsi_cmnd *cmnd = evt_struct->cmnd;
^1da177e4c3f41 Linus Torvalds  2005-04-16   980  
ef265673434680 FUJITA Tomonori 2006-03-26   981  	if (unlikely(rsp->opcode != SRP_RSP)) {
^1da177e4c3f41 Linus Torvalds  2005-04-16   982  		if (printk_ratelimit())
6c0a60ec52042e Brian King      2007-06-13   983  			dev_warn(evt_struct->hostdata->dev,
15c9274699e8b6 Tyrel Datwyler  2016-12-07   984  				 "bad SRP RSP type %#02x\n", rsp->opcode);
^1da177e4c3f41 Linus Torvalds  2005-04-16   985  	}
^1da177e4c3f41 Linus Torvalds  2005-04-16   986  	
^1da177e4c3f41 Linus Torvalds  2005-04-16   987  	if (cmnd) {
c3a3b55ae80a0d Brian King      2008-04-25   988  		cmnd->result |= rsp->status;
^1da177e4c3f41 Linus Torvalds  2005-04-16  @989  		if (((cmnd->result >> 1) & 0x1f) == CHECK_CONDITION)
^1da177e4c3f41 Linus Torvalds  2005-04-16   990  			memcpy(cmnd->sense_buffer,
ef265673434680 FUJITA Tomonori 2006-03-26   991  			       rsp->data,
72264eb6dbb909 Anton Blanchard 2013-09-03   992  			       be32_to_cpu(rsp->sense_data_len));
^1da177e4c3f41 Linus Torvalds  2005-04-16   993  		unmap_cmd_data(&evt_struct->iu.srp.cmd, 
4dddbc26c3895e James Bottomley 2005-09-06   994  			       evt_struct, 
^1da177e4c3f41 Linus Torvalds  2005-04-16   995  			       evt_struct->hostdata->dev);
^1da177e4c3f41 Linus Torvalds  2005-04-16   996  
ef265673434680 FUJITA Tomonori 2006-03-26   997  		if (rsp->flags & SRP_RSP_FLAG_DOOVER)
72264eb6dbb909 Anton Blanchard 2013-09-03   998  			scsi_set_resid(cmnd,
72264eb6dbb909 Anton Blanchard 2013-09-03   999  				       be32_to_cpu(rsp->data_out_res_cnt));
ef265673434680 FUJITA Tomonori 2006-03-26  1000  		else if (rsp->flags & SRP_RSP_FLAG_DIOVER)
72264eb6dbb909 Anton Blanchard 2013-09-03  1001  			scsi_set_resid(cmnd, be32_to_cpu(rsp->data_in_res_cnt));
^1da177e4c3f41 Linus Torvalds  2005-04-16  1002  	}
^1da177e4c3f41 Linus Torvalds  2005-04-16  1003  
^1da177e4c3f41 Linus Torvalds  2005-04-16  1004  	if (evt_struct->cmnd_done)
^1da177e4c3f41 Linus Torvalds  2005-04-16  1005  		evt_struct->cmnd_done(cmnd);
^1da177e4c3f41 Linus Torvalds  2005-04-16  1006  }
^1da177e4c3f41 Linus Torvalds  2005-04-16  1007  

:::::: The code at line 989 was first introduced by commit
:::::: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Linux-2.6.12-rc2

:::::: TO: Linus Torvalds <torvalds@ppc970.osdl.org>
:::::: CC: Linus Torvalds <torvalds@ppc970.osdl.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 25428 bytes --]

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

* Re: [PATCH 10/24] scsi: introduce set_status_byte()
  2019-10-21  9:53 ` [PATCH 10/24] scsi: introduce set_status_byte() Hannes Reinecke
@ 2019-10-21 22:12   ` Finn Thain
  2019-10-22  5:56     ` Hannes Reinecke
  0 siblings, 1 reply; 63+ messages in thread
From: Finn Thain @ 2019-10-21 22:12 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: Martin K. Petersen, Christoph Hellwig, James Bottomley,
	Johannes Thumshirn, linux-scsi

On Mon, 21 Oct 2019, Hannes Reinecke wrote:

> To be in-line with the other set_XX_byte() functions.
> 
> Signed-off-by: Hannes Reinecke <hare@suse.de>
> ---
>  include/scsi/scsi_cmnd.h | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
> index 91bd749a02f7..6932d91472d5 100644
> --- a/include/scsi/scsi_cmnd.h
> +++ b/include/scsi/scsi_cmnd.h
> @@ -307,6 +307,11 @@ static inline struct scsi_data_buffer *scsi_prot(struct scsi_cmnd *cmd)
>  #define scsi_for_each_prot_sg(cmd, sg, nseg, __i)		\
>  	for_each_sg(scsi_prot_sglist(cmd), sg, nseg, __i)
>  
> +static inline void set_status_byte(struct scsi_cmnd *cmd, char status)
> +{
> +	cmd->result = (cmd->result & 0xffffff00) | status;

Is sign-extension desirable here? Do callers need it?

-- 

> +}
> +
>  static inline void set_msg_byte(struct scsi_cmnd *cmd, char status)
>  {
>  	cmd->result = (cmd->result & 0xffff00ff) | (status << 8);
> 

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

* Re: [PATCH 03/24] wd33c93: use SCSI status
  2019-10-21  9:53 ` [PATCH 03/24] wd33c93: use SCSI status Hannes Reinecke
  2019-10-21 18:41     ` kbuild test robot
@ 2019-10-21 23:16   ` Finn Thain
  2019-10-22  5:59     ` Hannes Reinecke
  1 sibling, 1 reply; 63+ messages in thread
From: Finn Thain @ 2019-10-21 23:16 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: Martin K. Petersen, Christoph Hellwig, James Bottomley,
	Johannes Thumshirn, linux-scsi

On Mon, 21 Oct 2019, Hannes Reinecke wrote:

> Use standard SCSI status and drop usage of the linux-specific ones.
> 
> Signed-off-by: Hannes Reinecke <hare@suse.de>
> ---
>  drivers/scsi/wd33c93.c | 21 ++++++++-------------
>  1 file changed, 8 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/scsi/wd33c93.c b/drivers/scsi/wd33c93.c
> index f81046f0e68a..98e04a7b9d63 100644
> --- a/drivers/scsi/wd33c93.c
> +++ b/drivers/scsi/wd33c93.c
> @@ -1176,10 +1176,8 @@ wd33c93_intr(struct Scsi_Host *instance)
>  			if (cmd->SCp.Status == ILLEGAL_STATUS_BYTE)
>  				cmd->SCp.Status = lun;
>  			if (cmd->cmnd[0] == REQUEST_SENSE
> -			    && cmd->SCp.Status != GOOD)
> -				cmd->result =
> -				    (cmd->
> -				     result & 0x00ffff) | (DID_ERROR << 16);
> +			    && cmd->SCp.Status != SAM_STAT_GOOD)
> +				set_host_byte(cmd, DID_ERROR);

This isn't obviously equivalent. Perhaps the set_host_byte() changes 
should be done in a separate patch to the SAM_STAT_FOO changes (?)

>  			else
>  				cmd->result =
>  				    cmd->SCp.Status | (cmd->SCp.Message << 8);
> @@ -1262,9 +1260,8 @@ 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 != GOOD)
> -			cmd->result =
> -			    (cmd->result & 0x00ffff) | (DID_ERROR << 16);
> +		if (cmd->cmnd[0] == REQUEST_SENSE && cmd->SCp.Status != SAM_STAT_GOOD)
> +			set_host_byte(cmd, DID_ERROR);

Same.

>  		else
>  			cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
>  		cmd->scsi_done(cmd);
> @@ -1294,12 +1291,10 @@ wd33c93_intr(struct Scsi_Host *instance)
>  			hostdata->connected = NULL;
>  			hostdata->busy[cmd->device->id] &= ~(1 << (cmd->device->lun & 0xff));
>  			hostdata->state = S_UNCONNECTED;
> -			DB(DB_INTR, printk(":%d", cmd->SCp.Status))
> -			    if (cmd->cmnd[0] == REQUEST_SENSE
> -				&& cmd->SCp.Status != GOOD)
> -				cmd->result =
> -				    (cmd->
> -				     result & 0x00ffff) | (DID_ERROR << 16);
> +			DB(DB_INTR, printk(":%d", cmd->SCp.Status));
> +			if (cmd->cmnd[0] == REQUEST_SENSE
> +			    && cmd->SCp.Status != SAM_STAT_GOOD)
> +				set_host_byte(cmd->result, DID_ERROR);

Same.

-- 

>  			else
>  				cmd->result =
>  				    cmd->SCp.Status | (cmd->SCp.Message << 8);
> 

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

* Re: [PATCH 05/24] scsi: use standard SAM status codes
  2019-10-21  9:53 ` [PATCH 05/24] scsi: use standard SAM status codes Hannes Reinecke
@ 2019-10-21 23:17   ` Finn Thain
  2019-10-22  6:00     ` Hannes Reinecke
  0 siblings, 1 reply; 63+ messages in thread
From: Finn Thain @ 2019-10-21 23:17 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: Martin K. Petersen, Christoph Hellwig, James Bottomley,
	Johannes Thumshirn, linux-scsi

On Mon, 21 Oct 2019, Hannes Reinecke wrote:

> Use standard SAM status codes and omit the explicit shift to convert
> to linus-specific ones.

"Linux-specific".

-- 

> 
> Signed-off-by: Hannes Reinecke <hare@suse.de>
> ---
>  drivers/ata/libata-scsi.c             |  2 +-
>  drivers/infiniband/ulp/srp/ib_srp.c   |  2 +-
>  drivers/scsi/3w-9xxx.c                |  5 +++--
>  drivers/scsi/3w-sas.c                 |  3 ++-
>  drivers/scsi/3w-xxxx.c                |  4 ++--
>  drivers/scsi/arcmsr/arcmsr_hba.c      |  4 ++--
>  drivers/scsi/bfa/bfad_im.c            |  2 +-
>  drivers/scsi/dc395x.c                 | 18 +++++-------------
>  drivers/scsi/dpt_i2o.c                |  2 +-
>  drivers/scsi/gdth.c                   | 12 ++++++------
>  drivers/scsi/megaraid.c               | 10 +++++-----
>  drivers/scsi/megaraid/megaraid_mbox.c | 12 ++++++------
>  12 files changed, 35 insertions(+), 41 deletions(-)
> 
> diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
> index 76d0f9de767b..b197d2fbe3f8 100644
> --- a/drivers/ata/libata-scsi.c
> +++ b/drivers/ata/libata-scsi.c
> @@ -856,7 +856,7 @@ static struct ata_queued_cmd *ata_scsi_qc_new(struct ata_device *dev,
>  		if (cmd->request->rq_flags & RQF_QUIET)
>  			qc->flags |= ATA_QCFLAG_QUIET;
>  	} else {
> -		cmd->result = (DID_OK << 16) | (QUEUE_FULL << 1);
> +		cmd->result = (DID_OK << 16) | SAM_STAT_TASK_SET_FULL;
>  		cmd->scsi_done(cmd);
>  	}
>  
> diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
> index b5960351bec0..4570e3c79ea5 100644
> --- a/drivers/infiniband/ulp/srp/ib_srp.c
> +++ b/drivers/infiniband/ulp/srp/ib_srp.c
> @@ -2404,7 +2404,7 @@ static int srp_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd)
>  		 * to reduce queue depth temporarily.
>  		 */
>  		scmnd->result = len == -ENOMEM ?
> -			DID_OK << 16 | QUEUE_FULL << 1 : DID_ERROR << 16;
> +			DID_OK << 16 | SAM_STAT_TASK_SET_FULL : DID_ERROR << 16;
>  		goto err_iu;
>  	}
>  
> diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
> index 3337b1e80412..ada77c136f8b 100644
> --- a/drivers/scsi/3w-9xxx.c
> +++ b/drivers/scsi/3w-9xxx.c
> @@ -1018,7 +1018,8 @@ static int twa_fill_sense(TW_Device_Extension *tw_dev, int request_id, int copy_
>  
>  	if (copy_sense) {
>  		memcpy(tw_dev->srb[request_id]->sense_buffer, full_command_packet->header.sense_data, TW_SENSE_DATA_LENGTH);
> -		tw_dev->srb[request_id]->result = (full_command_packet->command.newcommand.status << 1);
> +		tw_dev->srb[request_id]->result =
> +			full_command_packet->command.newcommand.status;
>  		retval = TW_ISR_DONT_RESULT;
>  		goto out;
>  	}
> @@ -1342,7 +1343,7 @@ static irqreturn_t twa_interrupt(int irq, void *dev_instance)
>  				/* If error, command failed */
>  				if (error == 1) {
>  					/* Ask for a host reset */
> -					cmd->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
> +					cmd->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
>  				}
>  
>  				/* Report residual bytes for single sgl */
> diff --git a/drivers/scsi/3w-sas.c b/drivers/scsi/3w-sas.c
> index dda6fa857709..d11f62c60877 100644
> --- a/drivers/scsi/3w-sas.c
> +++ b/drivers/scsi/3w-sas.c
> @@ -891,7 +891,8 @@ static int twl_fill_sense(TW_Device_Extension *tw_dev, int i, int request_id, in
>  
>  	if (copy_sense) {
>  		memcpy(tw_dev->srb[request_id]->sense_buffer, header->sense_data, TW_SENSE_DATA_LENGTH);
> -		tw_dev->srb[request_id]->result = (full_command_packet->command.newcommand.status << 1);
> +		tw_dev->srb[request_id]->result =
> +			full_command_packet->command.newcommand.status;
>  		goto out;
>  	}
>  out:
> diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
> index 2b1e0d503020..79eca8f1fd05 100644
> --- a/drivers/scsi/3w-xxxx.c
> +++ b/drivers/scsi/3w-xxxx.c
> @@ -429,7 +429,7 @@ static int tw_decode_sense(TW_Device_Extension *tw_dev, int request_id, int fill
>  					/* Additional sense code qualifier */
>  					tw_dev->srb[request_id]->sense_buffer[13] = tw_sense_table[i][3];
>  
> -					tw_dev->srb[request_id]->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
> +					tw_dev->srb[request_id]->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
>  					return TW_ISR_DONT_RESULT; /* Special case for isr to not over-write result */
>  				}
>  			}
> @@ -2164,7 +2164,7 @@ static irqreturn_t tw_interrupt(int irq, void *dev_instance)
>  				/* If error, command failed */
>  				if (error == 1) {
>  					/* Ask for a host reset */
> -					tw_dev->srb[request_id]->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
> +					tw_dev->srb[request_id]->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
>  				}
>  
>  				/* Now complete the io */
> diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
> index 88053b15c363..89eda0c79349 100644
> --- a/drivers/scsi/arcmsr/arcmsr_hba.c
> +++ b/drivers/scsi/arcmsr/arcmsr_hba.c
> @@ -1271,7 +1271,7 @@ static void arcmsr_report_sense_info(struct CommandControlBlock *ccb)
>  
>  	struct scsi_cmnd *pcmd = ccb->pcmd;
>  	struct SENSE_DATA *sensebuffer = (struct SENSE_DATA *)pcmd->sense_buffer;
> -	pcmd->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
> +	pcmd->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
>  	if (sensebuffer) {
>  		int sense_data_length =
>  			sizeof(struct SENSE_DATA) < SCSI_SENSE_BUFFERSIZE
> @@ -3110,7 +3110,7 @@ static int arcmsr_queue_command_lck(struct scsi_cmnd *cmd,
>  	if (!ccb)
>  		return SCSI_MLQUEUE_HOST_BUSY;
>  	if (arcmsr_build_ccb( acb, ccb, cmd ) == FAILED) {
> -		cmd->result = (DID_ERROR << 16) | (RESERVATION_CONFLICT << 1);
> +		cmd->result = (DID_ERROR << 16) | SAM_STAT_RESERVATION_CONFLICT;
>  		cmd->scsi_done(cmd);
>  		return 0;
>  	}
> diff --git a/drivers/scsi/bfa/bfad_im.c b/drivers/scsi/bfa/bfad_im.c
> index 6b5841b1c06e..e3cbe5d20aca 100644
> --- a/drivers/scsi/bfa/bfad_im.c
> +++ b/drivers/scsi/bfa/bfad_im.c
> @@ -150,7 +150,7 @@ bfa_cb_tskim_done(void *bfad, struct bfad_tskim_s *dtsk,
>  	struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dtsk;
>  	wait_queue_head_t *wq;
>  
> -	cmnd->SCp.Status |= tsk_status << 1;
> +	cmnd->SCp.Status |= tsk_status;
>  	set_bit(IO_DONE_BIT, (unsigned long *)&cmnd->SCp.Status);
>  	wq = (wait_queue_head_t *) cmnd->SCp.ptr;
>  	cmnd->SCp.ptr = NULL;
> diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
> index 13fbb2eab842..a56893bc681e 100644
> --- a/drivers/scsi/dc395x.c
> +++ b/drivers/scsi/dc395x.c
> @@ -168,7 +168,6 @@
>  #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; }
> @@ -3228,7 +3227,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:
> @@ -3275,22 +3274,15 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb,
>  					*((unsigned int *)(cmd->sense_buffer + 3)));
>  		}
>  
> -		if (status == (CHECK_CONDITION << 1)) {
> +		if (status == SAM_STAT_CHECK_CONDITION) {
>  			cmd->result = DID_BAD_TARGET << 16;
>  			goto ckc_e;
>  		}
>  		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(DRIVER_SENSE, DID_OK,
> +			   srb->end_message, SAM_STAT_CHECK_CONDITION);
>  
>  		goto ckc_e;
>  	}
> diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
> index abc74fd474dc..83576fd694c4 100644
> --- a/drivers/scsi/dpt_i2o.c
> +++ b/drivers/scsi/dpt_i2o.c
> @@ -2656,7 +2656,7 @@ static void adpt_fail_posted_scbs(adpt_hba* pHba)
>  		unsigned long flags;
>  		spin_lock_irqsave(&d->list_lock, flags);
>  		list_for_each_entry(cmd, &d->cmd_list, list) {
> -			cmd->result = (DID_OK << 16) | (QUEUE_FULL <<1);
> +			cmd->result = (DID_OK << 16) | SAM_STAT_TASK_SET_FULL;
>  			cmd->scsi_done(cmd);
>  		}
>  		spin_unlock_irqrestore(&d->list_lock, flags);
> diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
> index fe03410268e6..d23e277c1b85 100644
> --- a/drivers/scsi/gdth.c
> +++ b/drivers/scsi/gdth.c
> @@ -1677,7 +1677,7 @@ static void gdth_next(gdth_ha_str *ha)
>                  memset((char*)nscp->sense_buffer,0,16);
>                  nscp->sense_buffer[0] = 0x70;
>                  nscp->sense_buffer[2] = NOT_READY;
> -                nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
> +		nscp->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
>                  if (!nscp_cmndinfo->wait_for_completion)
>                      nscp_cmndinfo->wait_for_completion++;
>                  else
> @@ -1722,7 +1722,7 @@ static void gdth_next(gdth_ha_str *ha)
>                      memset((char*)nscp->sense_buffer,0,16);
>                      nscp->sense_buffer[0] = 0x70;
>                      nscp->sense_buffer[2] = UNIT_ATTENTION;
> -                    nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
> +		    nscp->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
>                      if (!nscp_cmndinfo->wait_for_completion)
>                          nscp_cmndinfo->wait_for_completion++;
>                      else
> @@ -1774,7 +1774,7 @@ static void gdth_next(gdth_ha_str *ha)
>                      memset((char*)nscp->sense_buffer,0,16);
>                      nscp->sense_buffer[0] = 0x70;
>                      nscp->sense_buffer[2] = UNIT_ATTENTION;
> -                    nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
> +		    nscp->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
>                      if (!nscp_cmndinfo->wait_for_completion)
>                          nscp_cmndinfo->wait_for_completion++;
>                      else
> @@ -2802,7 +2802,7 @@ static int gdth_sync_event(gdth_ha_str *ha, int service, u8 index,
>                  memset((char*)scp->sense_buffer,0,16);
>                  scp->sense_buffer[0] = 0x70;
>                  scp->sense_buffer[2] = NOT_READY;
> -                scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
> +		scp->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
>              } else if (service == CACHESERVICE) {
>                  if (ha->status == S_CACHE_UNKNOWN &&
>                      (ha->hdr[t].cluster_type & 
> @@ -2812,11 +2812,11 @@ static int gdth_sync_event(gdth_ha_str *ha, int service, u8 index,
>                  }
>                  memset((char*)scp->sense_buffer,0,16);
>                  if (ha->status == (u16)S_CACHE_RESERV) {
> -                    scp->result = (DID_OK << 16) | (RESERVATION_CONFLICT << 1);
> +                    scp->result = (DID_OK << 16) | SAM_STAT_RESERVATION_CONFLICT;
>                  } else {
>                      scp->sense_buffer[0] = 0x70;
>                      scp->sense_buffer[2] = NOT_READY;
> -                    scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
> +                    scp->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION;
>                  }
>                  if (!cmndinfo->internal_command) {
>                      ha->dvr.size = sizeof(ha->dvr.eu.sync);
> diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
> index ff6d4aa92421..21e190c38b97 100644
> --- a/drivers/scsi/megaraid.c
> +++ b/drivers/scsi/megaraid.c
> @@ -1581,7 +1581,7 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
>  
>  				cmd->result = (DRIVER_SENSE << 24) |
>  					(DID_OK << 16) |
> -					(CHECK_CONDITION << 1);
> +					SAM_STAT_CHECK_CONDITION;
>  			}
>  			else {
>  				if (mbox->m_out.cmd == MEGA_MBOXCMD_EXTPTHRU) {
> @@ -1591,11 +1591,11 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
>  
>  					cmd->result = (DRIVER_SENSE << 24) |
>  						(DID_OK << 16) |
> -						(CHECK_CONDITION << 1);
> +						SAM_STAT_CHECK_CONDITION;
>  				} else {
>  					cmd->sense_buffer[0] = 0x70;
>  					cmd->sense_buffer[2] = ABORTED_COMMAND;
> -					cmd->result |= (CHECK_CONDITION << 1);
> +					cmd->result |= SAM_STAT_CHECK_CONDITION;
>  				}
>  			}
>  			break;
> @@ -1613,7 +1613,7 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
>  			 */
>  			if( cmd->cmnd[0] == TEST_UNIT_READY ) {
>  				cmd->result |= (DID_ERROR << 16) |
> -					(RESERVATION_CONFLICT << 1);
> +					SAM_STAT_RESERVATION_CONFLICT;
>  			}
>  			else
>  			/*
> @@ -1625,7 +1625,7 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
>  					 cmd->cmnd[0] == RELEASE) ) {
>  
>  				cmd->result |= (DID_ERROR << 16) |
> -					(RESERVATION_CONFLICT << 1);
> +					SAM_STAT_RESERVATION_CONFLICT;
>  			}
>  			else
>  #endif
> diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
> index f6ac819e6e96..dc58c5ff31e4 100644
> --- a/drivers/scsi/megaraid/megaraid_mbox.c
> +++ b/drivers/scsi/megaraid/megaraid_mbox.c
> @@ -1577,7 +1577,7 @@ megaraid_mbox_build_cmd(adapter_t *adapter, struct scsi_cmnd *scp, int *busy)
>  				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;
> +				scp->result = SAM_STAT_CHECK_CONDITION;
>  				return NULL;
>  			}
>  
> @@ -2302,7 +2302,7 @@ megaraid_mbox_dpc(unsigned long devp)
>  						14);
>  
>  				scp->result = DRIVER_SENSE << 24 |
> -					DID_OK << 16 | CHECK_CONDITION << 1;
> +					DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
>  			}
>  			else {
>  				if (mbox->cmd == MBOXCMD_EXTPTHRU) {
> @@ -2312,11 +2312,11 @@ megaraid_mbox_dpc(unsigned long devp)
>  
>  					scp->result = DRIVER_SENSE << 24 |
>  						DID_OK << 16 |
> -						CHECK_CONDITION << 1;
> +						SAM_STAT_CHECK_CONDITION;
>  				} else {
>  					scp->sense_buffer[0] = 0x70;
>  					scp->sense_buffer[2] = ABORTED_COMMAND;
> -					scp->result = CHECK_CONDITION << 1;
> +					scp->result = SAM_STAT_CHECK_CONDITION;
>  				}
>  			}
>  			break;
> @@ -2334,7 +2334,7 @@ megaraid_mbox_dpc(unsigned long devp)
>  			 */
>  			if (scp->cmnd[0] == TEST_UNIT_READY) {
>  				scp->result = DID_ERROR << 16 |
> -					RESERVATION_CONFLICT << 1;
> +					SAM_STAT_RESERVATION_CONFLICT;
>  			}
>  			else
>  			/*
> @@ -2345,7 +2345,7 @@ megaraid_mbox_dpc(unsigned long devp)
>  					 scp->cmnd[0] == RELEASE)) {
>  
>  				scp->result = DID_ERROR << 16 |
> -					RESERVATION_CONFLICT << 1;
> +					SAM_STAT_RESERVATION_CONFLICT;
>  			}
>  			else {
>  				scp->result = DID_BAD_TARGET << 16 | status;
> 

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

* Re: [PATCH RFC 00/24] scsi: Revamp result values
  2019-10-21 18:32 ` [PATCH RFC 00/24] scsi: Revamp result values Douglas Gilbert
@ 2019-10-21 23:20   ` Finn Thain
  2019-10-22  6:24   ` Hannes Reinecke
  1 sibling, 0 replies; 63+ messages in thread
From: Finn Thain @ 2019-10-21 23:20 UTC (permalink / raw)
  To: Douglas Gilbert
  Cc: Hannes Reinecke, Martin K. Petersen, Christoph Hellwig,
	James Bottomley, Johannes Thumshirn, linux-scsi

On Mon, 21 Oct 2019, Douglas Gilbert wrote:

> 
> > As usual, comments and reviews are welcome.
> 
> It is hard to make an omelette without breaking some eggs.
> 

Coccinelle can minimize the breakage; particularly the 
straight-forward conversion of (FOO << 1) to SAM_STAT_BAR.

-- 

> Doug Gilbert
> 

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

* Re: [PATCH 12/24] scsi: introduce scsi_build_sense()
  2019-10-21  9:53 ` [PATCH 12/24] scsi: introduce scsi_build_sense() Hannes Reinecke
@ 2019-10-21 23:31   ` Finn Thain
  2019-10-22  6:02     ` Hannes Reinecke
  2019-10-22 12:21   ` Steffen Maier
  1 sibling, 1 reply; 63+ messages in thread
From: Finn Thain @ 2019-10-21 23:31 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: Martin K. Petersen, Christoph Hellwig, James Bottomley,
	Johannes Thumshirn, linux-scsi


On Mon, 21 Oct 2019, Hannes Reinecke wrote:

> 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                |  3 +-
>  drivers/scsi/libiscsi.c               |  5 +--
>  drivers/scsi/lpfc/lpfc_scsi.c         | 30 ++++-------------
>  drivers/scsi/mpt3sas/mpt3sas_scsih.c  |  5 +--
>  drivers/scsi/mvumi.c                  |  5 +--
>  drivers/scsi/myrb.c                   | 61 ++++++++---------------------------
>  drivers/scsi/myrs.c                   |  9 ++----
>  drivers/scsi/ps3rom.c                 |  3 +-
>  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 ++
>  16 files changed, 60 insertions(+), 128 deletions(-)
> 
> diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
> index b197d2fbe3f8..0fd3cb8e4e49 100644
> --- a/drivers/ata/libata-scsi.c
> +++ b/drivers/ata/libata-scsi.c
> @@ -342,9 +342,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,
> @@ -1092,8 +1090,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 e9ded2befa0d..da52d7649f4d 100644
> --- a/drivers/s390/scsi/zfcp_scsi.c
> +++ b/drivers/s390/scsi/zfcp_scsi.c
> @@ -834,10 +834,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 79eca8f1fd05..381723634c13 100644
> --- a/drivers/scsi/3w-xxxx.c
> +++ b/drivers/scsi/3w-xxxx.c
> @@ -1981,8 +1981,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);
> -			SCpnt->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
> -			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 ebd47c0cf9e9..9c85d7902faa 100644
> --- a/drivers/scsi/libiscsi.c
> +++ b/drivers/scsi/libiscsi.c
> @@ -813,10 +813,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 f06f63e58596..aa8431fe9c1f 100644
> --- a/drivers/scsi/lpfc/lpfc_scsi.c
> +++ b/drivers/scsi/lpfc/lpfc_scsi.c
> @@ -2843,10 +2843,7 @@ 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: LBA %lx grd_tag error %x != %x\n",
> @@ -2854,10 +2851,7 @@ 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);
>  

Same.

>  		phba->bg_reftag_err_cnt++;
>  		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
> @@ -2866,10 +2860,7 @@ 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);
>  

Same. 

>  		phba->bg_apptag_err_cnt++;
>  		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
> @@ -2930,10 +2921,7 @@ 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);

Same.

>  		phba->bg_guard_err_cnt++;
>  		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
>  				"9055 BLKGRD: Guard Tag error in cmd"
> @@ -2946,10 +2934,7 @@ 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);
>  

Same.

>  		phba->bg_reftag_err_cnt++;
>  		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
> @@ -2963,10 +2948,7 @@ 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);
>  

Same.

>  		phba->bg_apptag_err_cnt++;
>  		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
> diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
> index 3f0797e6f941..802b0d39bdf3 100644
> --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
> +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
> @@ -4619,10 +4619,7 @@ _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);

Same.

-- 

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

* Re: [PATCH 13/24] scsi: Kill DRIVER_SENSE
  2019-10-21  9:53 ` [PATCH 13/24] scsi: Kill DRIVER_SENSE Hannes Reinecke
@ 2019-10-21 23:44   ` Finn Thain
  2019-10-22  6:10     ` Hannes Reinecke
  2021-06-04  6:40   ` Jiri Slaby
  1 sibling, 1 reply; 63+ messages in thread
From: Finn Thain @ 2019-10-21 23:44 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: Martin K. Petersen, Christoph Hellwig, James Bottomley,
	Johannes Thumshirn, linux-scsi


> diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
> index c40fbea06cc5..649f9610ca72 100644
> --- a/drivers/scsi/megaraid/megaraid_sas_base.c
> +++ b/drivers/scsi/megaraid/megaraid_sas_base.c
> @@ -1,3 +1,4 @@
> +
>  // SPDX-License-Identifier: GPL-2.0-or-later
>  /*
>   *  Linux MegaRAID driver for SAS based RAID controllers

Typo?

> index 59443e0184fd..d6ecb773c512 100644
> --- a/drivers/scsi/scsi.c
> +++ b/drivers/scsi/scsi.c
> @@ -203,8 +203,8 @@ void scsi_finish_command(struct scsi_cmnd *cmd)
>  	 * 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);
> +	if (SCSI_SENSE_VALID(cmd) && status_byte(cmd->result) == SAM_STAT_GOOD)
> +		set_status_byte(cmd, SAM_STAT_CHECK_CONDITION);

This means that a REQUEST SENSE command can never result in SAM_STAT_GOOD, 
right? Are there implications for higher layers?

-- 

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

* Re: [PATCH 10/24] scsi: introduce set_status_byte()
  2019-10-21 22:12   ` Finn Thain
@ 2019-10-22  5:56     ` Hannes Reinecke
  0 siblings, 0 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-22  5:56 UTC (permalink / raw)
  To: Finn Thain
  Cc: Martin K. Petersen, Christoph Hellwig, James Bottomley,
	Johannes Thumshirn, linux-scsi

On 10/22/19 12:12 AM, Finn Thain wrote:
> On Mon, 21 Oct 2019, Hannes Reinecke wrote:
> 
>> To be in-line with the other set_XX_byte() functions.
>>
>> Signed-off-by: Hannes Reinecke <hare@suse.de>
>> ---
>>  include/scsi/scsi_cmnd.h | 5 +++++
>>  1 file changed, 5 insertions(+)
>>
>> diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
>> index 91bd749a02f7..6932d91472d5 100644
>> --- a/include/scsi/scsi_cmnd.h
>> +++ b/include/scsi/scsi_cmnd.h
>> @@ -307,6 +307,11 @@ static inline struct scsi_data_buffer *scsi_prot(struct scsi_cmnd *cmd)
>>  #define scsi_for_each_prot_sg(cmd, sg, nseg, __i)		\
>>  	for_each_sg(scsi_prot_sglist(cmd), sg, nseg, __i)
>>  
>> +static inline void set_status_byte(struct scsi_cmnd *cmd, char status)
>> +{
>> +	cmd->result = (cmd->result & 0xffffff00) | status;
> 
> Is sign-extension desirable here? Do callers need it?
> 
It'll be a theoretical issue, as a status value with the top bit set
would be invalid anyway.
But for consistencies sake I'll make it an unsigned char in the next
iteration.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		      Teamlead Storage & Networking
hare@suse.de			                  +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 247165 (AG München), GF: Felix Imendörffer

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

* Re: [PATCH 03/24] wd33c93: use SCSI status
  2019-10-21 23:16   ` Finn Thain
@ 2019-10-22  5:59     ` Hannes Reinecke
  0 siblings, 0 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-22  5:59 UTC (permalink / raw)
  To: Finn Thain
  Cc: Martin K. Petersen, Christoph Hellwig, James Bottomley,
	Johannes Thumshirn, linux-scsi

On 10/22/19 1:16 AM, Finn Thain wrote:
> On Mon, 21 Oct 2019, Hannes Reinecke wrote:
> 
>> Use standard SCSI status and drop usage of the linux-specific ones.
>>
>> Signed-off-by: Hannes Reinecke <hare@suse.de>
>> ---
>>  drivers/scsi/wd33c93.c | 21 ++++++++-------------
>>  1 file changed, 8 insertions(+), 13 deletions(-)
>>
>> diff --git a/drivers/scsi/wd33c93.c b/drivers/scsi/wd33c93.c
>> index f81046f0e68a..98e04a7b9d63 100644
>> --- a/drivers/scsi/wd33c93.c
>> +++ b/drivers/scsi/wd33c93.c
>> @@ -1176,10 +1176,8 @@ wd33c93_intr(struct Scsi_Host *instance)
>>  			if (cmd->SCp.Status == ILLEGAL_STATUS_BYTE)
>>  				cmd->SCp.Status = lun;
>>  			if (cmd->cmnd[0] == REQUEST_SENSE
>> -			    && cmd->SCp.Status != GOOD)
>> -				cmd->result =
>> -				    (cmd->
>> -				     result & 0x00ffff) | (DID_ERROR << 16);
>> +			    && cmd->SCp.Status != SAM_STAT_GOOD)
>> +				set_host_byte(cmd, DID_ERROR);
> 
> This isn't obviously equivalent. Perhaps the set_host_byte() changes 
> should be done in a separate patch to the SAM_STAT_FOO changes (?)
> 
Yes, indeed.
Will be fixing it up in the next round.

>>  			else
>>  				cmd->result =
>>  				    cmd->SCp.Status | (cmd->SCp.Message << 8);
>> @@ -1262,9 +1260,8 @@ 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 != GOOD)
>> -			cmd->result =
>> -			    (cmd->result & 0x00ffff) | (DID_ERROR << 16);
>> +		if (cmd->cmnd[0] == REQUEST_SENSE && cmd->SCp.Status != SAM_STAT_GOOD)
>> +			set_host_byte(cmd, DID_ERROR);
> 
> Same.
> 
>>  		else
>>  			cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
>>  		cmd->scsi_done(cmd);
>> @@ -1294,12 +1291,10 @@ wd33c93_intr(struct Scsi_Host *instance)
>>  			hostdata->connected = NULL;
>>  			hostdata->busy[cmd->device->id] &= ~(1 << (cmd->device->lun & 0xff));
>>  			hostdata->state = S_UNCONNECTED;
>> -			DB(DB_INTR, printk(":%d", cmd->SCp.Status))
>> -			    if (cmd->cmnd[0] == REQUEST_SENSE
>> -				&& cmd->SCp.Status != GOOD)
>> -				cmd->result =
>> -				    (cmd->
>> -				     result & 0x00ffff) | (DID_ERROR << 16);
>> +			DB(DB_INTR, printk(":%d", cmd->SCp.Status));
>> +			if (cmd->cmnd[0] == REQUEST_SENSE
>> +			    && cmd->SCp.Status != SAM_STAT_GOOD)
>> +				set_host_byte(cmd->result, DID_ERROR);
> 
> Same.
> 
Cheers,

Hannes
-- 
Dr. Hannes Reinecke		      Teamlead Storage & Networking
hare@suse.de			                  +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 247165 (AG München), GF: Felix Imendörffer

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

* Re: [PATCH 05/24] scsi: use standard SAM status codes
  2019-10-21 23:17   ` Finn Thain
@ 2019-10-22  6:00     ` Hannes Reinecke
  0 siblings, 0 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-22  6:00 UTC (permalink / raw)
  To: Finn Thain
  Cc: Martin K. Petersen, Christoph Hellwig, James Bottomley,
	Johannes Thumshirn, linux-scsi

On 10/22/19 1:17 AM, Finn Thain wrote:
> On Mon, 21 Oct 2019, Hannes Reinecke wrote:
> 
>> Use standard SAM status codes and omit the explicit shift to convert
>> to linus-specific ones.
> 
> "Linux-specific".
> 
Indeed, it was Linus who did that :-)
Will be fixing it up.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		      Teamlead Storage & Networking
hare@suse.de			                  +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 247165 (AG München), GF: Felix Imendörffer

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

* Re: [PATCH 12/24] scsi: introduce scsi_build_sense()
  2019-10-21 23:31   ` Finn Thain
@ 2019-10-22  6:02     ` Hannes Reinecke
  0 siblings, 0 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-22  6:02 UTC (permalink / raw)
  To: Finn Thain
  Cc: Martin K. Petersen, Christoph Hellwig, James Bottomley,
	Johannes Thumshirn, linux-scsi

On 10/22/19 1:31 AM, Finn Thain wrote:
> 
> On Mon, 21 Oct 2019, Hannes Reinecke wrote:
> 
>> 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                |  3 +-
>>  drivers/scsi/libiscsi.c               |  5 +--
>>  drivers/scsi/lpfc/lpfc_scsi.c         | 30 ++++-------------
>>  drivers/scsi/mpt3sas/mpt3sas_scsih.c  |  5 +--
>>  drivers/scsi/mvumi.c                  |  5 +--
>>  drivers/scsi/myrb.c                   | 61 ++++++++---------------------------
>>  drivers/scsi/myrs.c                   |  9 ++----
>>  drivers/scsi/ps3rom.c                 |  3 +-
>>  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 ++
>>  16 files changed, 60 insertions(+), 128 deletions(-)
>>
>> diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
>> index b197d2fbe3f8..0fd3cb8e4e49 100644
>> --- a/drivers/ata/libata-scsi.c
>> +++ b/drivers/ata/libata-scsi.c
>> @@ -342,9 +342,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,
>> @@ -1092,8 +1090,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 e9ded2befa0d..da52d7649f4d 100644
>> --- a/drivers/s390/scsi/zfcp_scsi.c
>> +++ b/drivers/s390/scsi/zfcp_scsi.c
>> @@ -834,10 +834,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 79eca8f1fd05..381723634c13 100644
>> --- a/drivers/scsi/3w-xxxx.c
>> +++ b/drivers/scsi/3w-xxxx.c
>> @@ -1981,8 +1981,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);
>> -			SCpnt->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
>> -			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 ebd47c0cf9e9..9c85d7902faa 100644
>> --- a/drivers/scsi/libiscsi.c
>> +++ b/drivers/scsi/libiscsi.c
>> @@ -813,10 +813,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 f06f63e58596..aa8431fe9c1f 100644
>> --- a/drivers/scsi/lpfc/lpfc_scsi.c
>> +++ b/drivers/scsi/lpfc/lpfc_scsi.c
>> @@ -2843,10 +2843,7 @@ 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_apptag_err_cnt++;
>>  		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
>> diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
>> index 3f0797e6f941..802b0d39bdf3 100644
>> --- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
>> +++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
>> @@ -4619,10 +4619,7 @@ _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);
> 
> Same.
> 
And while you are correct that it should introduce set_host_byte() here,
too, the larger issue here is that setting DID_ABORT will obliterate any
sense code we set; in scsi_decide_dispostion() the sense code is never
evaluated if DID_ABORT is set.
But indeed, that should be a separate patch, and possibly even a
separate discussion.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		      Teamlead Storage & Networking
hare@suse.de			                  +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 247165 (AG München), GF: Felix Imendörffer

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

* Re: [PATCH 13/24] scsi: Kill DRIVER_SENSE
  2019-10-21 23:44   ` Finn Thain
@ 2019-10-22  6:10     ` Hannes Reinecke
  0 siblings, 0 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-22  6:10 UTC (permalink / raw)
  To: Finn Thain
  Cc: Martin K. Petersen, Christoph Hellwig, James Bottomley,
	Johannes Thumshirn, linux-scsi

On 10/22/19 1:44 AM, Finn Thain wrote:
> 
>> diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
>> index c40fbea06cc5..649f9610ca72 100644
>> --- a/drivers/scsi/megaraid/megaraid_sas_base.c
>> +++ b/drivers/scsi/megaraid/megaraid_sas_base.c
>> @@ -1,3 +1,4 @@
>> +
>>  // SPDX-License-Identifier: GPL-2.0-or-later
>>  /*
>>   *  Linux MegaRAID driver for SAS based RAID controllers
> 
> Typo?
> 
Indeed. Will fix it up.

>> index 59443e0184fd..d6ecb773c512 100644
>> --- a/drivers/scsi/scsi.c
>> +++ b/drivers/scsi/scsi.c
>> @@ -203,8 +203,8 @@ void scsi_finish_command(struct scsi_cmnd *cmd)
>>  	 * 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);
>> +	if (SCSI_SENSE_VALID(cmd) && status_byte(cmd->result) == SAM_STAT_GOOD)
>> +		set_status_byte(cmd, SAM_STAT_CHECK_CONDITION);
> 
> This means that a REQUEST SENSE command can never result in SAM_STAT_GOOD, 
> right? Are there implications for higher layers?
> 
Hmm. Blasted REQUEST SENSE.
Indeed a REQUEST SENSE command should never return with CHECK_CONDITION.
But then a REQUEST SENSE command returns with the sense code in the
payload, which equally is not something which is expected.

I'll be having a look here.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		      Teamlead Storage & Networking
hare@suse.de			                  +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 247165 (AG München), GF: Felix Imendörffer

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

* Re: [PATCH RFC 00/24] scsi: Revamp result values
  2019-10-21 18:32 ` [PATCH RFC 00/24] scsi: Revamp result values Douglas Gilbert
  2019-10-21 23:20   ` Finn Thain
@ 2019-10-22  6:24   ` Hannes Reinecke
  1 sibling, 0 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-22  6:24 UTC (permalink / raw)
  To: dgilbert, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn, linux-scsi

On 10/21/19 8:32 PM, Douglas Gilbert wrote:
> On 2019-10-21 5:52 a.m., Hannes Reinecke wrote:
>> Hi all,
>>
>> the 'result' field in the SCSI command is defined as having
>> 4 fields. The top byte is declared as a 'driver_byte', where the
>> driver can signal some internal status back to the midlayer.
>> However, there is quite a bit of overlap between the driver_byte
>> and the host_byte, resulting in the driver_byte being used in
>> very few places, and mostly in legacy drivers.
>> Additionally, we have _two_ sets of definitions for the
>> last byte (status byte), which can specified either in SAM terms
>> or in the linux-specific terms, which are shifted right by one
>> from the SAM ones.
>> Needless to say, the linux-specific ones are declared obsolete
>> for years now.
>> And to make the confusion complete, both the status byte and
>> the driver byte have a byte for a valid sense code, resulting
>> in quite some confusion which of those bits to check.
>>
>> This patchset does several things:
>> - remove the linux-specific status byte definitions, and use
>>    the SAM values throughout
>> - replace the driver-byte values with either SAM ones (for sense
>>    code checking) or host-byte definitions
>> - remove the driver-byte definitions
> 
> This is a brave change proposal. The masked_status has been tricked
> up so it won't break user code. However the driver byte is exposed
> by the sg v2, v3 and v4 interfaces which means via bsg device nodes,
> sg devices nodes and many other block storage device nodes (e.g.
> /dev/sdc and /dev/st1) via:
>       ioctl(<storage_dev>, SG_IO, ptr_to_v3_interface) .
> 
> So if there is any user space code out there that checks the
> driver byte (e.g. 'sg_io_hdr::driver_status & DRIVER_SENSE') do we
> have a problem?
> 
> If so, we could hack the DRIVER_SENSE case *** by putting it back
> for the user space to see when the driver (e.g. sg) knows there
> is sense data. What about the other values?
> 
>> As usual, comments and reviews are welcome.
> 
> It is hard to make an omelette without breaking some eggs.
> 
> Doug Gilbert
> 
>> Please note, commit 66cf50e65b18 ("scsi: qla2xxx: fixup incorrect
>> usage of host_byte") from 5.4/scsi-fixes is a prerequisite for
>> this patch series.
> 
> <snip>
> 
> *** Here is a snippet from sg3_utils library code:
> 
>     if ((SAM_STAT_CHECK_CONDITION == scsi_status) ||
>         (SAM_STAT_COMMAND_TERMINATED == scsi_status) ||
>         (SG_LIB_DRIVER_SENSE == masked_driver_status))
>         return sg_err_category_sense(sense_buffer, sb_len);
> 
> Due to the logical OR, as long as SAM_STAT_CHECK_CONDITION is set
> whenever there is sense, then we don't care about DRIVER_SENSE.
> 
> I believe this code comes from the days before auto-sense when say a
> READ(6) would fail, send back a CHECK_CONDITION and the host would then
> need to issue a REQUEST SENSE command to get the sense data. However
> REQUEST SENSE could itself yield a CHECK_CONDITION. Hence DRIVER_SENSE
> set, SAM_STAT_CHECK_CONDITION clear could be interpreted as the
> initial command failing and the follow-up REQUEST SENSE succeeded; if
> they are both set, then both commands failed (e.g. the disk has gone
> away).
Well, the easier explanation is that not every driver sets DRIVER_SENSE;
some do, some don't, relying on CHECK_CONDITION here.

Which also means that any code relying on DRIVER_SENSE alone would break
even today.
So really I don't think this should break anything; but if the consensus
is that we need to fake DRIVER_SENSE for userland ABI stability so be it.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		      Teamlead Storage & Networking
hare@suse.de			                  +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 247165 (AG München), GF: Felix Imendörffer

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

* Re: [PATCH 11/24] advansys: kill driver_defined status byte accessors
  2019-10-21 16:37   ` Bart Van Assche
@ 2019-10-22  6:25     ` Hannes Reinecke
  0 siblings, 0 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-22  6:25 UTC (permalink / raw)
  To: Bart Van Assche, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn, linux-scsi

On 10/21/19 6:37 PM, Bart Van Assche wrote:
> On 10/21/19 2:53 AM, Hannes Reinecke wrote:
>> @@ -6021,43 +6015,28 @@ 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);
>> -                /*
>> -                 * Note: The 'status_byte()' macro used by
>> -                 * target drivers defined in scsi.h shifts the
>> -                 * status byte returned by host drivers right
>> -                 * by 1 bit.  This is why target drivers also
>> -                 * use right shifted status byte definitions.
>> -                 * For instance target drivers use
>> -                 * CHECK_CONDITION, defined to 0x1, instead of
>> -                 * the SCSI defined check condition value of
>> -                 * 0x2. Host drivers are supposed to return
>> -                 * the status byte as it is defined by SCSI.
>> -                 */
>> -                scp->result = DRIVER_BYTE(DRIVER_SENSE) |
>> -                    STATUS_BYTE(scsiqp->scsi_status);
>> -            } else {
>> -                scp->result = STATUS_BYTE(scsiqp->scsi_status);
>>               }
>> +            scp->result = status_byte(scsiqp->scsi_status);
>>               break;
> 
> Did you really want to delete the code that sets DRIVER_SENSE?
> 
Yes. SAM_STAT_CHECK_CONDITION is already set, and the whole point of
this patchset was to drop the DRIVER_SENSE usage.

>> @@ -6789,47 +6768,30 @@ 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);
>> -                /*
>> -                 * Note: The 'status_byte()' macro used by
>> -                 * target drivers defined in scsi.h shifts the
>> -                 * status byte returned by host drivers right
>> -                 * by 1 bit.  This is why target drivers also
>> -                 * use right shifted status byte definitions.
>> -                 * For instance target drivers use
>> -                 * CHECK_CONDITION, defined to 0x1, instead of
>> -                 * the SCSI defined check condition value of
>> -                 * 0x2. Host drivers are supposed to return
>> -                 * the status byte as it is defined by SCSI.
>> -                 */
>> -                scp->result = DRIVER_BYTE(DRIVER_SENSE) |
>> -                    STATUS_BYTE(qdonep->d3.scsi_stat);
>> -            } else {
>> -                scp->result = STATUS_BYTE(qdonep->d3.scsi_stat);
>>               }
>> +            scp->result = status_byte(qdonep->d3.scsi_stat);
>>               break;
> 
> Same comment here: did you really want to delete the code that sets
> DRIVER_SENSE?
> 
See above: yes.
That was kinda the point of this patchset.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		      Teamlead Storage & Networking
hare@suse.de			                  +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 247165 (AG München), GF: Felix Imendörffer

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

* Re: [PATCH 18/24] st: return error code in st_scsi_execute()
  2019-10-21 16:41   ` Bart Van Assche
@ 2019-10-22  6:28     ` Hannes Reinecke
  2019-10-22 14:54       ` Bart Van Assche
  0 siblings, 1 reply; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-22  6:28 UTC (permalink / raw)
  To: Bart Van Assche, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn, linux-scsi

On 10/21/19 6:41 PM, Bart Van Assche wrote:
> On 10/21/19 2:53 AM, Hannes Reinecke wrote:
>> We should return the actual error code in st_scsi_execute(),
>> avoiding the need to use DRIVER_ERROR.
>>
>> 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 e3266a64a477..5f38369cc62f 100644
>> --- a/drivers/scsi/st.c
>> +++ b/drivers/scsi/st.c
>> @@ -549,7 +549,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;
>>   @@ -560,7 +560,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;
>>           }
>>       }
> 
> The patch description looks confusing to me. Is it perhaps because the
> caller compares the st_scsi_execute() return value with zero and doesn't
> use the return value in any other way that it is fine to return an
> integer error code instead of a SCSI status?
> 
Yes. The caller does:

	ret = st_scsi_execute(SRpnt, cmd, direction, NULL, bytes, timeout,
			      retries);
	if (ret) {
		/* could not allocate the buffer or request was too large */
		(STp->buffer)->syscall_result = (-EBUSY);
		(STp->buffer)->last_SRpnt = NULL;

So it's immaterial _what_ we return here as long as it's non-zero.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		      Teamlead Storage & Networking
hare@suse.de			                  +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 247165 (AG München), GF: Felix Imendörffer

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

* Re: [PATCH 19/24] scsi_ioctl: return error code when blk_map_user() fails
  2019-10-21 16:44   ` Bart Van Assche
@ 2019-10-22  6:32     ` Hannes Reinecke
  0 siblings, 0 replies; 63+ messages in thread
From: Hannes Reinecke @ 2019-10-22  6:32 UTC (permalink / raw)
  To: Bart Van Assche, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn, linux-scsi

On 10/21/19 6:44 PM, Bart Van Assche wrote:
> On 10/21/19 2:53 AM, Hannes Reinecke wrote:
>> When failing to map the user buffer we should return the actual
>> error code, avoiding the usage of DRIVER_ERROR.
>>
>> 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 f5e0ad65e86a..1ab1b8d9641c 100644
>> --- a/block/scsi_ioctl.c
>> +++ b/block/scsi_ioctl.c
>> @@ -485,9 +485,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(q, disk, rq, 0);
> 
> Since sg_scsi_ioctl() is used to implement SCSI_IOCTL_SEND_COMMAND, does
> this patch change the ABI between user space and kernel in a
> backwards-incompatible way?
> 
Not really. We do change the return code, but sg_scsi_ioctl() already
returns negative POSIX error numbers on failure. And, in fact, this
position is the _only_ possible case where we return something else than
either an errno or a SCSI status. Which arguably is an error even in the
current code.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		      Teamlead Storage & Networking
hare@suse.de			                  +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 247165 (AG München), GF: Felix Imendörffer

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

* Re: [PATCH 12/24] scsi: introduce scsi_build_sense()
  2019-10-21  9:53 ` [PATCH 12/24] scsi: introduce scsi_build_sense() Hannes Reinecke
  2019-10-21 23:31   ` Finn Thain
@ 2019-10-22 12:21   ` Steffen Maier
  1 sibling, 0 replies; 63+ messages in thread
From: Steffen Maier @ 2019-10-22 12:21 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn,
	linux-scsi, Benjamin Block, linux-s390

On 10/21/19 11:53 AM, Hannes Reinecke wrote:
> 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/s390/scsi/zfcp_scsi.c         |  5 +--

>   16 files changed, 60 insertions(+), 128 deletions(-)

> diff --git a/drivers/s390/scsi/zfcp_scsi.c b/drivers/s390/scsi/zfcp_scsi.c
> index e9ded2befa0d..da52d7649f4d 100644
> --- a/drivers/s390/scsi/zfcp_scsi.c
> +++ b/drivers/s390/scsi/zfcp_scsi.c
> @@ -834,10 +834,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);
>   }
> 

looks like a non-functional change for zfcp, so for this part:

Acked-by: Steffen Maier <maier@linux.ibm.com> # for zfcp

> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> index a0db8d8766a8..2babf6df8066 100644
> --- a/drivers/scsi/scsi_lib.c
> +++ b/drivers/scsi/scsi_lib.c
> @@ -3117,3 +3117,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

minor: I suppose kdoc&sphnix parse and render it correctly? Because 
Documentation/doc-guide/kernel-doc.rst says the format for function kdoc has 
"()" as function name suffix:
+ * 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)

Looks like this has already been like that. Not sure if this patch set touches 
every user of scsi_build_sense{_buffer}(). It would be nice to have meaningful 
identifiers for values passed to @desc, e.g. something like the following 
instead of "magic" zero and non-zero:

enum scsi_sense_format {
	SCSI_SENSE_FIXED = 0,
	SCSI_SENSE_DESCRIPTOR
};

> + * @key:	Sense key
> + * @asc:	Additional sense code
> + * @ascq:	Additional sense code qualifier
> + *
> + **/

minor:

+ */

[no double star at kdoc end?]

> +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;

While this is scsi_lib and thus "internal" helper code, I wonder if this should 
nonetheless use the helper functions to access and build scmd->result in order 
to have the error-prone bit shifts in only one central place?:

	scmd->result = SAM_STAT_CHECK_CONDITION;
	set_driver_byte(scmd, DRIVER_SENSE);
	set_host_byte(scmd, DID_OK);
	

> +}
> +EXPORT_SYMBOL_GPL(scsi_build_sense);

> diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
> index 6932d91472d5..9b9ca629097d 100644
> --- a/include/scsi/scsi_cmnd.h
> +++ b/include/scsi/scsi_cmnd.h
> @@ -338,4 +338,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 */
> 


-- 
Mit freundlichen Gruessen / Kind regards
Steffen Maier

Linux on IBM Z Development

https://www.ibm.com/privacy/us/en/
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Matthias Hartmann
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294

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

* Re: [PATCH 06/24] scsi: change status_byte() to return the standard SCSI status
  2019-10-21  9:53 ` [PATCH 06/24] scsi: change status_byte() to return the standard SCSI status Hannes Reinecke
@ 2019-10-22 12:35   ` Steffen Maier
  0 siblings, 0 replies; 63+ messages in thread
From: Steffen Maier @ 2019-10-22 12:35 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn, linux-scsi

On 10/21/19 11:53 AM, Hannes Reinecke wrote:
> Instead of returning the linux-special status (which is shifted
> by 1 to the right) change the status_byte() macro to return the
> correct SCSI standard status.
> And audit all callers to handle this change.
> 
> Signed-off-by: Hannes Reinecke <hare@suse.de>
> ---
>   drivers/scsi/53c700.c        |  6 +++---
>   drivers/scsi/NCR5380.c       |  2 +-
>   drivers/scsi/arm/acornscsi.c | 10 ++++-----
>   drivers/scsi/arm/fas216.c    | 10 ++++-----
>   drivers/scsi/dc395x.c        |  8 +++-----
>   drivers/scsi/scsi.c          |  2 +-
>   drivers/scsi/scsi_error.c    | 48 ++++++++++++++++++++++----------------------
>   drivers/scsi/scsi_lib.c      |  2 +-
>   drivers/scsi/sg.c            |  4 ++--
>   include/scsi/scsi.h          |  2 +-
>   10 files changed, 46 insertions(+), 48 deletions(-)
> diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
> index 5339baadc082..de52632c6022 100644
> --- a/include/scsi/scsi.h
> +++ b/include/scsi/scsi.h
> @@ -207,7 +207,7 @@ static inline int scsi_is_wlun(u64 lun)
>    *      host_byte   = set by low-level driver to indicate status.
>    *      driver_byte = set by mid-level.
>    */
> -#define status_byte(result) (((result) >> 1) & 0x7f)
> +#define status_byte(result) (((result)) & 0xff)

drop the now unnecessary additional parentheses pair around (result)?:

+#define status_byte(result) ((result) & 0xff)

>   #define msg_byte(result)    (((result) >> 8) & 0xff)
>   #define host_byte(result)   (((result) >> 16) & 0xff)
>   #define driver_byte(result) (((result) >> 24) & 0xff)
> 


-- 
Mit freundlichen Gruessen / Kind regards
Steffen Maier

Linux on IBM Z Development

https://www.ibm.com/privacy/us/en/
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Matthias Hartmann
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294


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

* Re: [PATCH 18/24] st: return error code in st_scsi_execute()
  2019-10-22  6:28     ` Hannes Reinecke
@ 2019-10-22 14:54       ` Bart Van Assche
  0 siblings, 0 replies; 63+ messages in thread
From: Bart Van Assche @ 2019-10-22 14:54 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn, linux-scsi

On 2019-10-21 23:28, Hannes Reinecke wrote:
> On 10/21/19 6:41 PM, Bart Van Assche wrote:
>> On 10/21/19 2:53 AM, Hannes Reinecke wrote:
>>> We should return the actual error code in st_scsi_execute(),
>>> avoiding the need to use DRIVER_ERROR.
>>>
>>> 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 e3266a64a477..5f38369cc62f 100644
>>> --- a/drivers/scsi/st.c
>>> +++ b/drivers/scsi/st.c
>>> @@ -549,7 +549,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;
>>>   @@ -560,7 +560,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;
>>>           }
>>>       }
>>
>> The patch description looks confusing to me. Is it perhaps because the
>> caller compares the st_scsi_execute() return value with zero and doesn't
>> use the return value in any other way that it is fine to return an
>> integer error code instead of a SCSI status?
>>
> Yes. The caller does:
> 
> 	ret = st_scsi_execute(SRpnt, cmd, direction, NULL, bytes, timeout,
> 			      retries);
> 	if (ret) {
> 		/* could not allocate the buffer or request was too large */
> 		(STp->buffer)->syscall_result = (-EBUSY);
> 		(STp->buffer)->last_SRpnt = NULL;
> 
> So it's immaterial _what_ we return here as long as it's non-zero.

Please make this clear in the patch description. I think that will make
this patch easier to review.

Thanks,

Bart.

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

* Re: [PATCH 13/24] scsi: Kill DRIVER_SENSE
  2019-10-21  9:53 ` [PATCH 13/24] scsi: Kill DRIVER_SENSE Hannes Reinecke
  2019-10-21 23:44   ` Finn Thain
@ 2021-06-04  6:40   ` Jiri Slaby
  2021-06-07 12:21     ` Hannes Reinecke
  1 sibling, 1 reply; 63+ messages in thread
From: Jiri Slaby @ 2021-06-04  6:40 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn, linux-scsi

Hi,

On 21. 10. 19, 11:53, 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.
> 
> Signed-off-by: Hannes Reinecke <hare@suse.de>
> ---
...
>   drivers/scsi/virtio_scsi.c                  |  3 +-

A bisection says that this patch breaks virto_scsi for me. The (virtual) 
disk is not found by the kernel.

GOOD:
scsi 0:0:0:0: Direct-Access     QEMU     QEMU HARDDISK    2.5+ PQ: 0 ANSI: 5

BAD:
scsi 0:0:0:0: Power-on or device reset occurred

I cannot revert the patch on the top of -next as there are conflicts...

Any ideas?

thanks,
-- 
js
suse labs

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

* Re: [PATCH 13/24] scsi: Kill DRIVER_SENSE
  2021-06-04  6:40   ` Jiri Slaby
@ 2021-06-07 12:21     ` Hannes Reinecke
  2021-06-07 12:30       ` Martin K. Petersen
  0 siblings, 1 reply; 63+ messages in thread
From: Hannes Reinecke @ 2021-06-07 12:21 UTC (permalink / raw)
  To: Jiri Slaby, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn, linux-scsi

On 6/4/21 8:40 AM, Jiri Slaby wrote:
> Hi,
> 
> On 21. 10. 19, 11:53, 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.
>>
>> Signed-off-by: Hannes Reinecke <hare@suse.de>
>> ---
> ...
>>   drivers/scsi/virtio_scsi.c                  |  3 +-
> 
> A bisection says that this patch breaks virto_scsi for me. The (virtual)
> disk is not found by the kernel.
> 
> GOOD:
> scsi 0:0:0:0: Direct-Access     QEMU     QEMU HARDDISK    2.5+ PQ: 0
> ANSI: 5
> 
> BAD:
> scsi 0:0:0:0: Power-on or device reset occurred
> 
> I cannot revert the patch on the top of -next as there are conflicts...
> 
> Any ideas?
> Can you enable SCSI logging via

scsi.scsi_logging_level=216

on the kernel commandline and send me the output?

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] 63+ messages in thread

* Re: [PATCH 13/24] scsi: Kill DRIVER_SENSE
  2021-06-07 12:21     ` Hannes Reinecke
@ 2021-06-07 12:30       ` Martin K. Petersen
  2021-06-07 13:02         ` Hannes Reinecke
  0 siblings, 1 reply; 63+ messages in thread
From: Martin K. Petersen @ 2021-06-07 12:30 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: Jiri Slaby, Martin K. Petersen, Christoph Hellwig,
	James Bottomley, Johannes Thumshirn, linux-scsi


Hannes,

>> Any ideas?

>> Can you enable SCSI logging via
>
> scsi.scsi_logging_level=216
>
> on the kernel commandline and send me the output?

You now effectively set SAM_STAT_CHECK_CONDITION if the scsi_cmnd has a
sense buffer.

The original code only set DRIVER_SENSE if the adapter response actually
contained sense information:

@@ -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);
        }

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* Re: [PATCH 13/24] scsi: Kill DRIVER_SENSE
  2021-06-07 12:30       ` Martin K. Petersen
@ 2021-06-07 13:02         ` Hannes Reinecke
  2021-06-10 10:52           ` Jiri Slaby
  0 siblings, 1 reply; 63+ messages in thread
From: Hannes Reinecke @ 2021-06-07 13:02 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Jiri Slaby, Christoph Hellwig, James Bottomley,
	Johannes Thumshirn, linux-scsi

On 6/7/21 2:30 PM, Martin K. Petersen wrote:
> 
> Hannes,
> 
>>> Any ideas?
> 
>>> Can you enable SCSI logging via
>>
>> scsi.scsi_logging_level=216
>>
>> on the kernel commandline and send me the output?
> 
> You now effectively set SAM_STAT_CHECK_CONDITION if the scsi_cmnd has a
> sense buffer.
> 
> The original code only set DRIVER_SENSE if the adapter response actually
> contained sense information:
> 
> @@ -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);
>         }
> 
Oh, I know. But we're checking for a valid sense code during scanning:

			if (scsi_status_is_check_condition(result) &&
			    scsi_sense_valid(&sshdr)) {

so if that makes a difference it would mean that the virtio driver has
some stale sense data which then gets copied over.
Anyway.
Can you test with this patch?

diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
index fd69a03d6137..0cb1182fd734 100644
--- a/drivers/scsi/virtio_scsi.c
+++ b/drivers/scsi/virtio_scsi.c
@@ -161,7 +161,8 @@ 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));
-               set_status_byte(sc, SAM_STAT_CHECK_CONDITION);
+               if (resp->sense_len)
+                       set_status_byte(sc, SAM_STAT_CHECK_CONDITION);
        }

        sc->scsi_done(sc);

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 related	[flat|nested] 63+ messages in thread

* Re: [PATCH 13/24] scsi: Kill DRIVER_SENSE
  2021-06-07 13:02         ` Hannes Reinecke
@ 2021-06-10 10:52           ` Jiri Slaby
  2021-06-10 14:01             ` Hannes Reinecke
  0 siblings, 1 reply; 63+ messages in thread
From: Jiri Slaby @ 2021-06-10 10:52 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn, linux-scsi

On 07. 06. 21, 15:02, Hannes Reinecke wrote:
> On 6/7/21 2:30 PM, Martin K. Petersen wrote:
>>
>> Hannes,
>>
>>>> Any ideas?
>>
>>>> Can you enable SCSI logging via
>>>
>>> scsi.scsi_logging_level=216
>>>
>>> on the kernel commandline and send me the output?
>>
>> You now effectively set SAM_STAT_CHECK_CONDITION if the scsi_cmnd has a
>> sense buffer.
>>
>> The original code only set DRIVER_SENSE if the adapter response actually
>> contained sense information:
>>
>> @@ -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);
>>          }
>>
> Oh, I know. But we're checking for a valid sense code during scanning:
> 
> 			if (scsi_status_is_check_condition(result) &&
> 			    scsi_sense_valid(&sshdr)) {
> 
> so if that makes a difference it would mean that the virtio driver has
> some stale sense data which then gets copied over.
> Anyway.
> Can you test with this patch?

Yes, that boots, but is somehow sloooow (hard to tell what is causing this).

Anyway, the new print is still there with the patch:
[   11.549986] sd 0:0:0:0: Power-on or device reset occurred


> diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
> index fd69a03d6137..0cb1182fd734 100644
> --- a/drivers/scsi/virtio_scsi.c
> +++ b/drivers/scsi/virtio_scsi.c
> @@ -161,7 +161,8 @@ 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));
> -               set_status_byte(sc, SAM_STAT_CHECK_CONDITION);
> +               if (resp->sense_len)
> +                       set_status_byte(sc, SAM_STAT_CHECK_CONDITION);
>          }
> 
>          sc->scsi_done(sc);
> 


thanks,
-- 
js
suse labs

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

* Re: [PATCH 13/24] scsi: Kill DRIVER_SENSE
  2021-06-10 10:52           ` Jiri Slaby
@ 2021-06-10 14:01             ` Hannes Reinecke
  2021-06-11  4:50               ` Jiri Slaby
  0 siblings, 1 reply; 63+ messages in thread
From: Hannes Reinecke @ 2021-06-10 14:01 UTC (permalink / raw)
  To: Jiri Slaby, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn, linux-scsi

[-- Attachment #1: Type: text/plain, Size: 2033 bytes --]

On 6/10/21 12:52 PM, Jiri Slaby wrote:
> On 07. 06. 21, 15:02, Hannes Reinecke wrote:
>> On 6/7/21 2:30 PM, Martin K. Petersen wrote:
>>>
>>> Hannes,
>>>
>>>>> Any ideas?
>>>
>>>>> Can you enable SCSI logging via
>>>>
>>>> scsi.scsi_logging_level=216
>>>>
>>>> on the kernel commandline and send me the output?
>>>
>>> You now effectively set SAM_STAT_CHECK_CONDITION if the scsi_cmnd has a
>>> sense buffer.
>>>
>>> The original code only set DRIVER_SENSE if the adapter response actually
>>> contained sense information:
>>>
>>> @@ -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);
>>>          }
>>>
>> Oh, I know. But we're checking for a valid sense code during scanning:
>>
>>             if (scsi_status_is_check_condition(result) &&
>>                 scsi_sense_valid(&sshdr)) {
>>
>> so if that makes a difference it would mean that the virtio driver has
>> some stale sense data which then gets copied over.
>> Anyway.
>> Can you test with this patch?
> 
> Yes, that boots, but is somehow sloooow (hard to tell what is causing
> this).
> 
> Anyway, the new print is still there with the patch:
> [   11.549986] sd 0:0:0:0: Power-on or device reset occurred
> 
> Cool; one step further.
Can you check if the attached patch helps, too?

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)

[-- Attachment #2: 0002-scsi-do-not-assume-CHECK_CONDITION-is-set-for-valid-.patch --]
[-- Type: text/x-patch, Size: 2519 bytes --]

From f60b3ab985a555cd623b77f6da95cb094da08d2a Mon Sep 17 00:00:00 2001
From: Hannes Reinecke <hare@suse.de>
Date: Thu, 10 Jun 2021 15:46:56 +0200
Subject: [PATCH 2/2] scsi: do not assume CHECK_CONDITION is set for valid
 sense code

While the standard implies that a sense code should be returned in
response to CHECK CONDITION status, it _might_ be returned on other
status codes, too.
At least, that's what the original code assumed. So it's arguably
wrong to assume we only will have a valid sense code when CHECK
CONDITION is set.

Fixes: 464a00c9e0ad ("scsi: core: Kill DRIVER_SENSE")
Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 drivers/scsi/sd.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 20739072f21a..821bbcfe68c9 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1722,8 +1722,7 @@ static int sd_sync_cache(struct scsi_disk *sdkp, struct scsi_sense_hdr *sshdr)
 		if (res < 0)
 			return res;
 
-		if (scsi_status_is_check_condition(res) &&
-		    scsi_sense_valid(sshdr)) {
+		if (scsi_sense_valid(sshdr)) {
 			sd_print_sense_hdr(sdkp, sshdr);
 
 			/* we need to evaluate the error return  */
@@ -1829,10 +1828,10 @@ 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 (scsi_status_is_check_condition(result) &&
-	    scsi_sense_valid(&sshdr)) {
+	if (result) {
 		sdev_printk(KERN_INFO, sdev, "PR command failed: %d\n", result);
-		scsi_print_sense_hdr(sdev, NULL, &sshdr);
+		if (scsi_sense_valid(&sshdr))
+			scsi_print_sense_hdr(sdev, NULL, &sshdr);
 	}
 
 	return result;
@@ -2073,7 +2072,7 @@ static int sd_done(struct scsi_cmnd *SCpnt)
 	}
 	sdkp->medium_access_timed_out = 0;
 
-	if (!scsi_status_is_check_condition(result) &&
+	if (result &&
 	    (!sense_valid || sense_deferred))
 		goto out;
 
@@ -2178,10 +2177,9 @@ sd_spinup_disk(struct scsi_disk *sdkp)
 			retries++;
 		} while (retries < 3 &&
 			 (!scsi_status_is_good(the_result) ||
-			  (scsi_status_is_check_condition(the_result) &&
-			  sense_valid && sshdr.sense_key == UNIT_ATTENTION)));
+			  (sense_valid && sshdr.sense_key == UNIT_ATTENTION)));
 
-		if (!scsi_status_is_check_condition(the_result)) {
+		if (the_result < 0 || !sense_valid) {
 			/* no sense, TUR either succeeded or failed
 			 * with a status error */
 			if(!spintime && !scsi_status_is_good(the_result)) {
-- 
2.26.2


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

* Re: [PATCH 13/24] scsi: Kill DRIVER_SENSE
  2021-06-10 14:01             ` Hannes Reinecke
@ 2021-06-11  4:50               ` Jiri Slaby
  2021-06-11  7:38                 ` Hannes Reinecke
  0 siblings, 1 reply; 63+ messages in thread
From: Jiri Slaby @ 2021-06-11  4:50 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn, linux-scsi

On 10. 06. 21, 16:01, Hannes Reinecke wrote:
>>> Can you test with this patch?
>>
>> Yes, that boots, but is somehow sloooow (hard to tell what is causing
>> this).
>>
>> Anyway, the new print is still there with the patch:
>> [   11.549986] sd 0:0:0:0: Power-on or device reset occurred
>>
>> Cool; one step further.
> Can you check if the attached patch helps, too?

No, this doesn't boot:
[   20.293526] scsi host0: Virtio SCSI HBA
[   22.236517] scsi 0:0:0:0: Power-on or device reset occurred
[   22.237986] scsi 0:0:0:0: Power-on or device reset occurred

thanks,
-- 
js
suse labs

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

* Re: [PATCH 13/24] scsi: Kill DRIVER_SENSE
  2021-06-11  4:50               ` Jiri Slaby
@ 2021-06-11  7:38                 ` Hannes Reinecke
  2021-06-14  6:29                   ` Jiri Slaby
  2021-06-14  7:20                   ` Jiri Slaby
  0 siblings, 2 replies; 63+ messages in thread
From: Hannes Reinecke @ 2021-06-11  7:38 UTC (permalink / raw)
  To: Jiri Slaby, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn, linux-scsi

On 6/11/21 6:50 AM, Jiri Slaby wrote:
> On 10. 06. 21, 16:01, Hannes Reinecke wrote:
>>>> Can you test with this patch?
>>>
>>> Yes, that boots, but is somehow sloooow (hard to tell what is causing
>>> this).
>>>
>>> Anyway, the new print is still there with the patch:
>>> [   11.549986] sd 0:0:0:0: Power-on or device reset occurred
>>>
>>> Cool; one step further.
>> Can you check if the attached patch helps, too?
> 
> No, this doesn't boot:
> [   20.293526] scsi host0: Virtio SCSI HBA
> [   22.236517] scsi 0:0:0:0: Power-on or device reset occurred
> [   22.237986] scsi 0:0:0:0: Power-on or device reset occurred
> 
Ok, thought so.
So it's really looks like the virtio driver is copying stale sense data.

Next try:
Can you take the patch from the mailing list (virtio_scsi: do not 
overwrite SCSI status), and enable SCSI logging level eg via

  scsi.scsi_logging_level=216

on the kernel command line.
That should give us some hint why it's so slow.

Alternatively: which configuration do you use?
Maybe I can reproduce it here locally ...

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] 63+ messages in thread

* Re: [PATCH 13/24] scsi: Kill DRIVER_SENSE
  2021-06-11  7:38                 ` Hannes Reinecke
@ 2021-06-14  6:29                   ` Jiri Slaby
  2021-06-14  7:20                   ` Jiri Slaby
  1 sibling, 0 replies; 63+ messages in thread
From: Jiri Slaby @ 2021-06-14  6:29 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn, linux-scsi

On 11. 06. 21, 9:38, Hannes Reinecke wrote:
> Alternatively: which configuration do you use?
> Maybe I can reproduce it here locally ...

It's quite easy:
qemu-img create /tmp/dr.img 1G

qemu-kvm -smp 4 -m 2G -drive file=/tmp/dr.img,if=none,id=hd,format=raw 
-device virtio-scsi-pci,id=scsi -device scsi-hd,drive=hd -serial stdio 
-kernel /path/to/bzImage -append 'console=ttyS0' -nographic -monitor none

Either sda appears or not... Assuming virtio_scsi and sd are built in.

thanks,
-- 
js
suse labs

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

* Re: [PATCH 13/24] scsi: Kill DRIVER_SENSE
  2021-06-11  7:38                 ` Hannes Reinecke
  2021-06-14  6:29                   ` Jiri Slaby
@ 2021-06-14  7:20                   ` Jiri Slaby
  1 sibling, 0 replies; 63+ messages in thread
From: Jiri Slaby @ 2021-06-14  7:20 UTC (permalink / raw)
  To: Hannes Reinecke, Martin K. Petersen
  Cc: Christoph Hellwig, James Bottomley, Johannes Thumshirn, linux-scsi

On 11. 06. 21, 9:38, Hannes Reinecke wrote:
> Next try:
> Can you take the patch from the mailing list (virtio_scsi: do not 
> overwrite SCSI status),

That (20210610135833.46663-1-hare@suse.de for reference) works fine for me:
[    3.173255] scsi host0: Virtio SCSI HBA
[    3.183529] scsi 0:0:0:0: Direct-Access     QEMU     QEMU HARDDISK 
  2.5+ PQ: 0 ANSI: 5
[    3.220967] sd 0:0:0:0: Power-on or device reset occurred
[    3.226150] sd 0:0:0:0: [sda] 20971520 512-byte logical blocks: (10.7 
GB/10.0 GiB)
[    3.230889] sd 0:0:0:0: [sda] Write Protect is off
[    3.232772] sd 0:0:0:0: [sda] Mode Sense: 63 00 00 08
[    3.233633] sd 0:0:0:0: [sda] Write cache: enabled, read cache: 
enabled, doesn't support DPO or FUA
[    3.239478]  sda: sda1 sda2
[    3.243752] sd 0:0:0:0: [sda] Attached SCSI disk

thanks,
-- 
js
suse labs

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

end of thread, other threads:[~2021-06-14  7:20 UTC | newest]

Thread overview: 63+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-21  9:52 [PATCH RFC 00/24] scsi: Revamp result values Hannes Reinecke
2019-10-21  9:52 ` [PATCH 01/24] aic7xxx,aic79xxx: remove driver-defined SAM status definitions Hannes Reinecke
2019-10-21  9:53 ` [PATCH 02/24] bfa: drop driver-defined SCSI status codes Hannes Reinecke
2019-10-21  9:53 ` [PATCH 03/24] wd33c93: use SCSI status Hannes Reinecke
2019-10-21 18:41   ` kbuild test robot
2019-10-21 18:41     ` kbuild test robot
2019-10-21 23:16   ` Finn Thain
2019-10-22  5:59     ` Hannes Reinecke
2019-10-21  9:53 ` [PATCH 04/24] acornscsi: use standard defines Hannes Reinecke
2019-10-21  9:53 ` [PATCH 05/24] scsi: use standard SAM status codes Hannes Reinecke
2019-10-21 23:17   ` Finn Thain
2019-10-22  6:00     ` Hannes Reinecke
2019-10-21  9:53 ` [PATCH 06/24] scsi: change status_byte() to return the standard SCSI status Hannes Reinecke
2019-10-22 12:35   ` Steffen Maier
2019-10-21  9:53 ` [PATCH 07/24] target_core: Fixup target_complete_cmd() usage Hannes Reinecke
2019-10-21  9:53 ` [PATCH 08/24] sg: use SAM status definitions and avoid using masked_status Hannes Reinecke
2019-10-21  9:53 ` [PATCH 09/24] scsi: Kill obsolete linux-specific status codes Hannes Reinecke
2019-10-21 18:12   ` kbuild test robot
2019-10-21 18:12     ` kbuild test robot
2019-10-21 18:56   ` kbuild test robot
2019-10-21 18:56     ` kbuild test robot
2019-10-21  9:53 ` [PATCH 10/24] scsi: introduce set_status_byte() Hannes Reinecke
2019-10-21 22:12   ` Finn Thain
2019-10-22  5:56     ` Hannes Reinecke
2019-10-21  9:53 ` [PATCH 11/24] advansys: kill driver_defined status byte accessors Hannes Reinecke
2019-10-21 16:37   ` Bart Van Assche
2019-10-22  6:25     ` Hannes Reinecke
2019-10-21  9:53 ` [PATCH 12/24] scsi: introduce scsi_build_sense() Hannes Reinecke
2019-10-21 23:31   ` Finn Thain
2019-10-22  6:02     ` Hannes Reinecke
2019-10-22 12:21   ` Steffen Maier
2019-10-21  9:53 ` [PATCH 13/24] scsi: Kill DRIVER_SENSE Hannes Reinecke
2019-10-21 23:44   ` Finn Thain
2019-10-22  6:10     ` Hannes Reinecke
2021-06-04  6:40   ` Jiri Slaby
2021-06-07 12:21     ` Hannes Reinecke
2021-06-07 12:30       ` Martin K. Petersen
2021-06-07 13:02         ` Hannes Reinecke
2021-06-10 10:52           ` Jiri Slaby
2021-06-10 14:01             ` Hannes Reinecke
2021-06-11  4:50               ` Jiri Slaby
2021-06-11  7:38                 ` Hannes Reinecke
2021-06-14  6:29                   ` Jiri Slaby
2021-06-14  7:20                   ` Jiri Slaby
2019-10-21  9:53 ` [PATCH 14/24] scsi: Kill DRIVER_HARD Hannes Reinecke
2019-10-21  9:53 ` [PATCH 15/24] scsi_error: use DID_TIME_OUT instead of DRIVER_TIMEOUT Hannes Reinecke
2019-10-21  9:53 ` [PATCH 16/24] scsi: Kill DRIVER_TIMEOUT Hannes Reinecke
2019-10-21  9:53 ` [PATCH 17/24] scsi: do not use DRIVER_INVALID Hannes Reinecke
2019-10-21  9:53 ` [PATCH 18/24] st: return error code in st_scsi_execute() Hannes Reinecke
2019-10-21 16:41   ` Bart Van Assche
2019-10-22  6:28     ` Hannes Reinecke
2019-10-22 14:54       ` Bart Van Assche
2019-10-21  9:53 ` [PATCH 19/24] scsi_ioctl: return error code when blk_map_user() fails Hannes Reinecke
2019-10-21 16:44   ` Bart Van Assche
2019-10-22  6:32     ` Hannes Reinecke
2019-10-21  9:53 ` [PATCH 20/24] scsi_dh_alua: do not interpret DRIVER_ERROR Hannes Reinecke
2019-10-21  9:53 ` [PATCH 21/24] xen-scsiback: stop using DRIVER_ERROR Hannes Reinecke
2019-10-21  9:53 ` [PATCH 22/24] scsi: " Hannes Reinecke
2019-10-21  9:53 ` [PATCH 23/24] scsi: Kill DRIVER_MEDIA, DRIVER_SOFT, and DRIVER_BUSY Hannes Reinecke
2019-10-21  9:53 ` [PATCH 24/24] scsi: Drop now obsolete driver_byte definitions Hannes Reinecke
2019-10-21 18:32 ` [PATCH RFC 00/24] scsi: Revamp result values Douglas Gilbert
2019-10-21 23:20   ` Finn Thain
2019-10-22  6:24   ` Hannes Reinecke

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.