Skip to contentSkip to conversation

Revamp SCSI result values

PATCH In review Hannes Reinecke 6 participants 90 messages Nov 4, 2019 – Nov 20, 2019

Subsystems (43)
Documentation SCSI USB PowerPC +39 more subsystems
lore
Share & tools
lore
#0 lore raw

v3 cover Revamp SCSI result values

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.

Changes to v1:
- Include reviews from Finn Thain et al
- Make sysbot happy

Changes to v2:
- Split patches as suggested by Bart
- more sysbot fixes

Hannes Reinecke (52):
aic7xxx,aic79xxx: remove driver-defined SAM status definitions
bfa: drop driver-defined SCSI status codes
wd33c93: use SCSI status
acornscsi: use standard defines
libata-scsi: use standard SAM status codes
ib_srp: use standard SAM status codes
3w-xxxx: use standard SAM status codes
arcmsr: use standard SAM status codes
dc395x: use standard SAM status codes
megaraid: use standard SAM status codes
megaraid_mboxi: use standard SAM status codes
gdth: use standard SAM status codes
dpt_i2o: use standard SAM status codes
nsp_cs: use standard SAM status codes
nsp32: fixup status handling
dc395: drop private SAM status code definitions
qla4xxx: use standard SAM status definitions
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
initio: use standard SAM status definitions
scsi: Kill obsolete linux-specific status codes
scsi: introduce set_status_byte()
advansys: kill driver_defined status byte accessors
scsi: introduce scsi_build_sense()
libata-scsi: use scsi_build_sense()
zfcp: use scsi_build_sense()
3w-xxxx: use scsi_build_sense()
libiscsi: use scsi_build_sense()
lpfc: use scsi_build_sense()
mpt3sas: use scsi_build_sense()
mvumi: use scsi_build_sense()
myrb: use scsi_build_sense()
myrs: use scsi_build_sense()
ps3rom: use scsi_build_sense()
qla2xxx: use scsi_build_sense()
scsi_debug: use scsi_build_sense()
smartpqi: use scsi_build_sense()
stex: use 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_rq_map_kern() fails
scsi_dh_alua: do not interpret DRIVER_ERROR
3w-9xxx: Kill unreachable code in twa_interrupt()
xen-scsiback: stop using DRIVER_ERROR
scsi: stop using DRIVER_ERROR
scsi: Kill DRIVER_MEDIA, DRIVER_SOFT, and DRIVER_BUSY
scsi: Drop the 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                      |  6 ---
 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                  |  2 +-
 drivers/scsi/ch.c                           |  5 +-
 drivers/scsi/constants.c                    | 15 ------
 drivers/scsi/cxlflash/superpipe.c           | 45 ++++++++---------
 drivers/scsi/dc395x.c                       | 26 +++-------
 drivers/scsi/dc395x.h                       | 16 ------
 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/ibmvscsi/ibmvscsi.c            |  2 +-
 drivers/scsi/initio.c                       |  2 +-
 drivers/scsi/initio.h                       |  5 --
 drivers/scsi/libiscsi.c                     |  5 +-
 drivers/scsi/lpfc/lpfc_scsi.c               | 36 +++++--------
 drivers/scsi/megaraid.c                     | 22 ++++----
 drivers/scsi/megaraid/megaraid_mbox.c       | 22 ++++----
 drivers/scsi/megaraid/megaraid_sas_base.c   |  2 -
 drivers/scsi/megaraid/megaraid_sas_fusion.c |  1 -
 drivers/scsi/mpt3sas/mpt3sas_scsih.c        |  9 ++--
 drivers/scsi/mvumi.c                        | 10 ++--
 drivers/scsi/myrb.c                         | 61 ++++++----------------
 drivers/scsi/myrs.c                         |  9 +---
 drivers/scsi/nsp32.c                        |  2 +-
 drivers/scsi/pcmcia/nsp_cs.c                |  2 +-
 drivers/scsi/ps3rom.c                       |  3 +-
 drivers/scsi/qla2xxx/qla_isr.c              | 15 ++----
 drivers/scsi/qla4xxx/ql4_fw.h               |  1 -
 drivers/scsi/qla4xxx/ql4_isr.c              |  2 +-
 drivers/scsi/scsi.c                         | 11 ++--
 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                           | 28 +++++------
 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                   |  6 ---
 drivers/scsi/wd33c93.c                      |  6 +--
 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                  | 14 +++---
 include/scsi/scsi.h                         | 19 +------
 include/scsi/scsi_cmnd.h                    | 12 +++--
 include/scsi/scsi_proto.h                   | 19 -------
 include/scsi/sg.h                           |  5 +-
 include/trace/events/scsi.h                 | 15 +-----
 88 files changed, 363 insertions(+), 655 deletions(-)
Signature · 1 line
2.16.4
#1 lore raw

PATCH v3 1/52 aic7xxx,aic79xxx: remove driver-defined SAM status definitions

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

---
 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(-)
drivers/scsi/aic7xxx/aic79xx_core.c +4 -4
index 7e5044bf05c0..03a9abc7d959 100644
@@ -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 */
drivers/scsi/aic7xxx/aic79xx_osm.c +8 -8
index 57992519384e..72c67e89b911 100644
@@ -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 {
drivers/scsi/aic7xxx/aic7xxx_core.c +3 -3
index a9d40d3b90ef..c8d237ccb70d 100644
@@ -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;
drivers/scsi/aic7xxx/aic7xxx_osm.c +6 -6
index d5c4a0d23706..a0b444e6209d 100644
@@ -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);
drivers/scsi/aic7xxx/aiclib.h +0 -15
index f8fd198aafbc..ba08eb3c4e3b 100644
@@ -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)
Signature · 1 line
2.16.4
#2 lore raw

PATCH v3 2/52 bfa: drop driver-defined SCSI status codes

In reply to Hannes Reinecke

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

---
 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(-)
drivers/scsi/bfa/bfa_fc.h +0 -15
index b00fb2409c50..d536270bbe9f 100644
@@ -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 */
 
 /*
drivers/scsi/bfa/bfa_fcpim.c +1 -1
index 284baa3b0c8e..997b54f5eb5c 100644
@@ -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,
drivers/scsi/bfa/bfad_im.c +1 -1
index 22f06be2606f..6b5841b1c06e 100644
@@ -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)
Signature · 1 line
2.16.4
#3 lore raw

PATCH v3 3/52 wd33c93: use SCSI status

In reply to Hannes Reinecke

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

---
 drivers/scsi/wd33c93.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/scsi/wd33c93.c +3 -3
index f81046f0e68a..76143a68f55c 100644
@@ -1176,7 +1176,7 @@ 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->SCp.Status != SAM_STAT_GOOD)
 				cmd->result =
 				    (cmd->
 				     result & 0x00ffff) | (DID_ERROR << 16);
@@ -1262,7 +1262,7 @@ 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)
+		if (cmd->cmnd[0] == REQUEST_SENSE && cmd->SCp.Status != SAM_STAT_GOOD)
 			cmd->result =
 			    (cmd->result & 0x00ffff) | (DID_ERROR << 16);
 		else
@@ -1296,7 +1296,7 @@ wd33c93_intr(struct Scsi_Host *instance)
 			hostdata->state = S_UNCONNECTED;
 			DB(DB_INTR, printk(":%d", cmd->SCp.Status))
 			    if (cmd->cmnd[0] == REQUEST_SENSE
-				&& cmd->SCp.Status != GOOD)
+				&& cmd->SCp.Status != SAM_STAT_GOOD)
 				cmd->result =
 				    (cmd->
 				     result & 0x00ffff) | (DID_ERROR << 16);
Signature · 1 line
2.16.4
#4 lore raw

PATCH v3 4/52 acornscsi: use standard defines

In reply to Hannes Reinecke

Use midlayer-defined values and drop the non-existing QUEUE_FULL case; we are checking the SCSI messages in the switch statement, and QUEUE_FULL is a SCSI status hence it can never occur here.

---
 drivers/scsi/arm/acornscsi.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
drivers/scsi/arm/acornscsi.c +2 -12
index ddb52e7ba622..8ceb1663bdb5 100644
@@ -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",
Signature · 1 line
2.16.4
#5 lore raw

PATCH v3 5/52 libata-scsi: use standard SAM status codes

In reply to Hannes Reinecke

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

---
 drivers/ata/libata-scsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ata/libata-scsi.c +1 -1
index 76d0f9de767b..b197d2fbe3f8 100644
@@ -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);
 	}
 
Signature · 1 line
2.16.4
maintainer Reviewed-by on v3 5/52
#6 lore raw

Re: [PATCH 05/52] libata-scsi: use standard SAM status codes

Quoted 2 lines · Hannes Reinecke

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

#7 lore raw

PATCH v3 6/52 ib_srp: use standard SAM status codes

In reply to Hannes Reinecke

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

---
 drivers/infiniband/ulp/srp/ib_srp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/ulp/srp/ib_srp.c +1 -1
index b5960351bec0..4570e3c79ea5 100644
@@ -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;
 	}
 
Signature · 1 line
2.16.4
maintainer Reviewed-by on v3 6/52
#8 lore raw

Re: [PATCH 06/52] ib_srp: use standard SAM status codes

Quoted 2 lines · Hannes Reinecke

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

#9 lore raw

PATCH v3 7/52 3w-xxxx: use standard SAM status codes

In reply to Hannes Reinecke

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

---
 drivers/scsi/3w-xxxx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/3w-xxxx.c +2 -2
index 2b1e0d503020..79eca8f1fd05 100644
@@ -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 */
Signature · 1 line
2.16.4
maintainer Reviewed-by on v3 7/52
#10 lore raw

Re: [PATCH 07/52] 3w-xxxx: use standard SAM status codes

Quoted 2 lines · Hannes Reinecke

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

#12 lore raw

PATCH v3 8/52 arcmsr: use standard SAM status codes

In reply to Hannes Reinecke

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

---
 drivers/scsi/arcmsr/arcmsr_hba.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/arcmsr/arcmsr_hba.c +2 -2
index 88053b15c363..89eda0c79349 100644
@@ -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;
 	}
Signature · 1 line
2.16.4
maintainer Reviewed-by on v3 8/52
#13 lore raw

Re: [PATCH 08/52] arcmsr: use standard SAM status codes

Quoted 2 lines · Hannes Reinecke

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

#14 lore raw

PATCH v3 9/52 dc395x: use standard SAM status codes

In reply to Hannes Reinecke

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

---
 drivers/scsi/dc395x.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
drivers/scsi/dc395x.c +5 -13
index 13fbb2eab842..a56893bc681e 100644
@@ -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;
 	}
Signature · 1 line
2.16.4
maintainer Reviewed-by on v3 9/52
#15 lore raw

Re: [PATCH 09/52] dc395x: use standard SAM status codes

Quoted 2 lines · Hannes Reinecke

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

#16 lore raw

PATCH v3 10/52 megaraid: use standard SAM status codes

In reply to Hannes Reinecke

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

---
 drivers/scsi/megaraid.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/scsi/megaraid.c +5 -5
index ff6d4aa92421..21e190c38b97 100644
@@ -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
Signature · 1 line
2.16.4
maintainer Reviewed-by on v3 10/52
#17 lore raw

Re: [PATCH 10/52] megaraid: use standard SAM status codes

Quoted 2 lines · Hannes Reinecke

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

#18 lore raw

PATCH v3 11/52 megaraid_mboxi: use standard SAM status codes

In reply to Hannes Reinecke

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

---
 drivers/scsi/megaraid/megaraid_mbox.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/scsi/megaraid/megaraid_mbox.c +6 -6
index f6ac819e6e96..dc58c5ff31e4 100644
@@ -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;
Signature · 1 line
2.16.4
maintainer Reviewed-by on v3 11/52
#19 lore raw

Re: [PATCH 11/52] megaraid_mboxi: use standard SAM status codes

Quoted 2 lines · Hannes Reinecke

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

#20 lore raw

PATCH v3 12/52 gdth: use standard SAM status codes

In reply to Hannes Reinecke

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

---
 drivers/scsi/gdth.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/scsi/gdth.c +6 -6
index fe03410268e6..d23e277c1b85 100644
@@ -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);
Signature · 1 line
2.16.4
maintainer Reviewed-by on v3 12/52
#21 lore raw

Re: [PATCH 12/52] gdth: use standard SAM status codes

Quoted 2 lines · Hannes Reinecke

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

#22 lore raw

PATCH v3 13/52 dpt_i2o: use standard SAM status codes

In reply to Hannes Reinecke

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

---
 drivers/scsi/dpt_i2o.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/dpt_i2o.c +1 -1
index abc74fd474dc..83576fd694c4 100644
@@ -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);
Signature · 1 line
2.16.4
maintainer Reviewed-by on v3 13/52
#23 lore raw

Re: [PATCH 13/52] dpt_i2o: use standard SAM status codes

Quoted 2 lines · Hannes Reinecke

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

#24 lore raw

PATCH v3 14/52 nsp_cs: use standard SAM status codes

In reply to Hannes Reinecke

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

---
 drivers/scsi/pcmcia/nsp_cs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/pcmcia/nsp_cs.c +1 -1
index 97416e1dcc5b..8e905fb94fd3 100644
@@ -223,7 +223,7 @@ static int nsp_queuecommand_lck(struct scsi_cmnd *SCpnt,
 
 	data->CurrentSC		= SCpnt;
 
-	SCpnt->SCp.Status	= CHECK_CONDITION;
+	SCpnt->SCp.Status	= SAM_STAT_CHECK_CONDITION;
 	SCpnt->SCp.Message	= 0;
 	SCpnt->SCp.have_data_in = IO_UNKNOWN;
 	SCpnt->SCp.sent_command = 0;
Signature · 1 line
2.16.4
maintainer
#25 lore raw

Re: [PATCH 14/52] nsp_cs: use standard SAM status codes

Quoted 13 lines · Hannes Reinecke

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

---
  drivers/scsi/pcmcia/nsp_cs.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/pcmcia/nsp_cs.c +0 -0
index 97416e1dcc5b..8e905fb94fd3 100644

drivers/scsi/pcmcia/nsp_cs.c static int nsp_queuecommand_lck(struct scsi_cmnd *SCpnt, · line 229

Quoted 8 lines
drivers/scsi/pcmcia/nsp_cs.c +1 -1
@@ -223,7 +223,7 @@ static int nsp_queuecommand_lck(struct scsi_cmnd *SCpnt,
 
  	data->CurrentSC		= SCpnt;
 
-	SCpnt->SCp.Status	= CHECK_CONDITION;
+	SCpnt->SCp.Status	= SAM_STAT_CHECK_CONDITION;
  	SCpnt->SCp.Message	= 0;
  	SCpnt->SCp.have_data_in = IO_UNKNOWN;
  	SCpnt->SCp.sent_command = 0;

It seems like there is a mismatch between the patch description and the patch. The patch description refers to omitting an explicit shift but I don't see that omission in the patch itself?

Bart.

#26 lore raw

PATCH v3 15/52 nsp32: fixup status handling

In reply to Hannes Reinecke

SCp.status is always the SAM-defined status value, not the linux ones. Fixup the one wrong definition.

---
 drivers/scsi/nsp32.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/nsp32.c +1 -1
index b6e04d14292d..e189b50a4267 100644
@@ -935,7 +935,7 @@ static int nsp32_queuecommand_lck(struct scsi_cmnd *SCpnt, void (*done)(struct s
 
 	SCpnt->scsi_done     = done;
 	data->CurrentSC      = SCpnt;
-	SCpnt->SCp.Status    = CHECK_CONDITION;
+	SCpnt->SCp.Status    = SAM_STAT_CHECK_CONDITION;
 	SCpnt->SCp.Message   = 0;
 	scsi_set_resid(SCpnt, scsi_bufflen(SCpnt));
 
Signature · 1 line
2.16.4
#27 lore raw

PATCH v3 16/52 dc395: drop private SAM status code definitions

In reply to Hannes Reinecke

We don't need to duplicate definitions from the common include files.

---
 drivers/scsi/dc395x.h | 16 ----------------
 1 file changed, 16 deletions(-)
drivers/scsi/dc395x.h +0 -16
index 5379a936141a..a7786a6d462e 100644
@@ -156,15 +156,6 @@
 #define H_ABORT				0x0FF
 
 /* SCSI BUS Status byte codes */
-#define SCSI_STAT_GOOD			0x0	/* Good status				*/
-#define SCSI_STAT_CHECKCOND		0x02	/* SCSI Check Condition			*/
-#define SCSI_STAT_CONDMET		0x04	/* Condition Met			*/
-#define SCSI_STAT_BUSY			0x08	/* Target busy status			*/
-#define SCSI_STAT_INTER			0x10	/* Intermediate status			*/
-#define SCSI_STAT_INTERCONDMET		0x14	/* Intermediate condition met		*/
-#define SCSI_STAT_RESCONFLICT		0x18	/* Reservation conflict			*/
-#define SCSI_STAT_CMDTERM		0x22	/* Command Terminated			*/
-#define SCSI_STAT_QUEUEFULL		0x28	/* Queue Full				*/
 #define SCSI_STAT_UNEXP_BUS_F		0xFD	/* Unexpect Bus Free			*/
 #define SCSI_STAT_BUS_RST_DETECT	0xFE	/* Scsi Bus Reset detected		*/
 #define SCSI_STAT_SEL_TIMEOUT		0xFF	/* Selection Time out			*/
@@ -203,13 +194,6 @@
 #define MSG_IDENTIFY			0x80
 #define MSG_HOST_ID			0xC0
 
-/* SCSI STATUS BYTE */
-#define STATUS_GOOD			0x00
-#define CHECK_CONDITION_		0x02
-#define STATUS_BUSY			0x08
-#define STATUS_INTERMEDIATE		0x10
-#define RESERVE_CONFLICT		0x18
-
 /* cmd->result */
 #define STATUS_MASK_			0xFF
 #define MSG_MASK			0xFF00
Signature · 1 line
2.16.4
#29 lore raw

PATCH v3 17/52 qla4xxx: use standard SAM status definitions

In reply to Hannes Reinecke

Use standard SAM status definitions and drop the
driver-defined ones.

---
 drivers/scsi/qla4xxx/ql4_fw.h  | 1 -
 drivers/scsi/qla4xxx/ql4_isr.c | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/qla4xxx/ql4_fw.h +0 -1
index 699575efc9ba..0108deb1fb5c 100644
@@ -1182,7 +1182,6 @@ struct status_entry {
 	uint32_t handle;	/* 04-07 */
 
 	uint8_t scsiStatus;	/* 08 */
-#define SCSI_CHECK_CONDITION		  0x02
 
 	uint8_t iscsiFlags;	/* 09 */
 #define ISCSI_FLAG_RESIDUAL_UNDER	  0x02
drivers/scsi/qla4xxx/ql4_isr.c +1 -1
index d2cd33d8d67f..8944fcc571e2 100644
@@ -183,7 +183,7 @@ static void qla4xxx_status_entry(struct scsi_qla_host *ha,
 
 		cmd->result = DID_OK << 16 | scsi_status;
 
-		if (scsi_status != SCSI_CHECK_CONDITION)
+		if (scsi_status != SAM_STAT_CHECK_CONDITION)
 			break;
 
 		/* Copy Sense Data into sense buffer. */
Signature · 1 line
2.16.4
#31 lore raw

PATCH v3 18/52 scsi: change status_byte() to return the standard SCSI status

In reply to 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.

---
 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/ibmvscsi/ibmvscsi.c |  2 +-
 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 +-
 11 files changed, 47 insertions(+), 49 deletions(-)
drivers/scsi/53c700.c +3 -3
index 0068963bb933..432f904e8d13 100644
@@ -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 */
drivers/scsi/NCR5380.c +1 -1
index 536426f25e86..5559d39a00b7 100644
@@ -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);
drivers/scsi/arm/acornscsi.c +5 -5
index 8ceb1663bdb5..a07413169ec0 100644
@@ -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:
drivers/scsi/arm/fas216.c +5 -5
index 6c68c2303638..a860f89de4ae 100644
@@ -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;
 
 	/*
drivers/scsi/dc395x.c +3 -5
index a56893bc681e..e79db03196f7 100644
@@ -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;
drivers/scsi/ibmvscsi/ibmvscsi.c +1 -1
index 7f66a7783209..73d0dded83fe 100644
@@ -986,7 +986,7 @@ static void handle_cmd_rsp(struct srp_event_struct *evt_struct)
 	
 	if (cmnd) {
 		cmnd->result |= rsp->status;
-		if (((cmnd->result >> 1) & 0x1f) == CHECK_CONDITION)
+		if (status_byte(cmnd->result) == SAM_STAT_CHECK_CONDITION)
 			memcpy(cmnd->sense_buffer,
 			       rsp->data,
 			       be32_to_cpu(rsp->sense_data_len));
drivers/scsi/scsi.c +1 -1
index 4f76841a7038..59443e0184fd 100644
@@ -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,
drivers/scsi/scsi_error.c +24 -24

129 lines not on this page · raw message

drivers/scsi/scsi_lib.c +1 -1
index dc210b9d4896..a0db8d8766a8 100644
@@ -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--;
drivers/scsi/sg.c +2 -2
index cce757506383..e88fb3daebcc 100644
@@ -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);
include/scsi/scsi.h +1 -1
index 5339baadc082..ce8096a99981 100644
@@ -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)
Signature · 1 line
2.16.4
maintainer Reviewed-by on v3 18/52
#32 lore raw

Re: [PATCH 18/52] scsi: change status_byte() to return the standard SCSI status

Quoted 4 lines · 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.

#33 lore raw

PATCH v3 19/52 target_core: Fixup target_complete_cmd() usage

In reply to Hannes Reinecke

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

---
 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(-)
drivers/target/target_core_alua.c +3 -3
index 385e4cf9cfa6..b53b6d7f173e 100644
@@ -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;
 }
 
drivers/target/target_core_iblock.c +1 -1
index 6949ea8bc387..bbafa984226e 100644
@@ -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;
 }
 
drivers/target/target_core_pr.c +4 -4
index 5e931690e697..4fef561b201c 100644
@@ -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;
 }
 
drivers/target/target_core_sbc.c +5 -5
index f1e81886122d..6e45924fb3da 100644
@@ -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;
 }
 
drivers/target/target_core_spc.c +7 -7
index 6d4cf2643c0a..84f7fefc2998 100644
@@ -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;
 }
 
drivers/target/target_core_xcopy.c +1 -1
index 425c1070de08..30475bf73faf 100644
@@ -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;
 }
Signature · 1 line
2.16.4
#34 lore raw

PATCH v3 20/52 sg: use SAM status definitions and avoid using masked_status

In reply to Hannes Reinecke

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

---
 drivers/scsi/sg.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/scsi/sg.c +7 -7
index e88fb3daebcc..60ff388d04b9 100644
@@ -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);
 
Signature · 1 line
2.16.4
maintainer Acked-by on v3 20/52
#35 lore raw

Re: [PATCH 20/52] sg: use SAM status definitions and avoid using masked_status

Quoted 4 lines · Hannes Reinecke

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

Quoted 65 lines
---
  drivers/scsi/sg.c | 14 +++++++-------
  1 file changed, 7 insertions(+), 7 deletions(-)
drivers/scsi/sg.c +7 -7
index e88fb3daebcc..60ff388d04b9 100644
@@ -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);
 
#36 lore raw

PATCH v3 21/52 initio: use standard SAM status definitions

In reply to Hannes Reinecke

Use standard SAM status definitions and drop the
driver-defined ones.

---
 drivers/scsi/initio.c | 2 +-
 drivers/scsi/initio.h | 5 -----
 2 files changed, 1 insertion(+), 6 deletions(-)
drivers/scsi/initio.c +1 -1
index 41fd64c9c8e9..d1430a39fe46 100644
@@ -1077,7 +1077,7 @@ static int tulip_main(struct initio_host * host)
 
 		/* Walk the list of completed SCBs */
 		while ((scb = initio_find_done_scb(host)) != NULL) {	/* find done entry */
-			if (scb->tastat == INI_QUEUE_FULL) {
+			if (scb->tastat == SAM_STAT_TASK_SET_FULL) {
 				host->max_tags[scb->target] =
 				    host->act_tags[scb->target] - 1;
 				scb->tastat = 0;
drivers/scsi/initio.h +0 -5
index 219b901bdc25..61bae14fee9e 100644
@@ -428,11 +428,6 @@ struct scsi_ctrl_blk {
 #define HOST_SCSI_RST   0x1B
 #define HOST_DEV_RST    0x1C
 
-/* Error Codes for SCB_TaStat */
-#define TARGET_CHKCOND  0x02
-#define TARGET_BUSY     0x08
-#define INI_QUEUE_FULL	0x28
-
 /* SCSI MESSAGE */
 #define MSG_COMP        0x00
 #define MSG_EXTEND      0x01
Signature · 1 line
2.16.4
#38 lore raw

PATCH v3 22/52 scsi: Kill obsolete linux-specific status codes

In reply to Hannes Reinecke

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

---
 include/scsi/scsi_proto.h | 19 -------------------
 1 file changed, 19 deletions(-)
include/scsi/scsi_proto.h +0 -19
index c36860111932..660f37ce8721 100644
@@ -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
 
 /*
Signature · 1 line
2.16.4
#40 lore raw

PATCH v3 23/52 scsi: introduce set_status_byte()

In reply to Hannes Reinecke

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

---
 include/scsi/scsi_cmnd.h | 5 +++++
 1 file changed, 5 insertions(+)
include/scsi/scsi_cmnd.h +5 -0
index 91bd749a02f7..6932d91472d5 100644
@@ -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);
Signature · 1 line
2.16.4
#41 lore raw

PATCH v3 24/52 advansys: kill driver_defined status byte accessors

In reply to Hannes Reinecke

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

---
 drivers/scsi/advansys.c | 78 +++++++++++++------------------------------------
 1 file changed, 20 insertions(+), 58 deletions(-)
drivers/scsi/advansys.c +20 -58
index a242a62caaa1..5268b4b92e43 100644
@@ -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;
 	}
 
Signature · 1 line
2.16.4
#42 lore raw

PATCH v3 25/52 scsi: introduce scsi_build_sense()

In reply to Hannes Reinecke

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

---
 drivers/scsi/scsi_lib.c  | 18 ++++++++++++++++++
 include/scsi/scsi_cmnd.h |  3 +++
 2 files changed, 21 insertions(+)
drivers/scsi/scsi_lib.c +18 -0
index a0db8d8766a8..2babf6df8066 100644
@@ -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);
include/scsi/scsi_cmnd.h +3 -0
index 6932d91472d5..9b9ca629097d 100644
@@ -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 */
Signature · 1 line
2.16.4
maintainer Reviewed-by on v3 25/52
#43 lore raw

Re: [PATCH 25/52] scsi: introduce scsi_build_sense()

Quoted 3 lines · Hannes Reinecke

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

#44 lore raw

PATCH v3 26/52 libata-scsi: use scsi_build_sense()

In reply to Hannes Reinecke

Use scsi_build_sense() to format the sense code.

---
 drivers/ata/libata-scsi.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/ata/libata-scsi.c +2 -5
index b197d2fbe3f8..0fd3cb8e4e49 100644
@@ -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) {
Signature · 1 line
2.16.4
#45 lore raw

PATCH v3 27/52 zfcp: use scsi_build_sense()

In reply to Hannes Reinecke

Use scsi_build_sense() to format the sense code.

---
 drivers/s390/scsi/zfcp_scsi.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/s390/scsi/zfcp_scsi.c +1 -4
index 3910d529c15a..120787dfcdca 100644
@@ -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);
 }
 
Signature · 1 line
2.16.4
#47 lore raw

PATCH v3 28/52 3w-xxxx: use scsi_build_sense()

In reply to Hannes Reinecke

Use scsi_build_sense() to format the sense code.

---
 drivers/scsi/3w-xxxx.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/3w-xxxx.c +1 -2
index 79eca8f1fd05..381723634c13 100644
@@ -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;
 	}
Signature · 1 line
2.16.4
#50 lore raw

PATCH v3 29/52 libiscsi: use scsi_build_sense()

In reply to Hannes Reinecke

Use scsi_build_sense() to format the sense code.

---
 drivers/scsi/libiscsi.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/scsi/libiscsi.c +1 -4
index ebd47c0cf9e9..9c85d7902faa 100644
@@ -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);
Signature · 1 line
2.16.4
#52 lore raw

PATCH v3 30/52 lpfc: use scsi_build_sense()

In reply to Hannes Reinecke

Use scsi_build_sense() to format the sense code.

---
 drivers/scsi/lpfc/lpfc_scsi.c | 36 ++++++++++++------------------------
 1 file changed, 12 insertions(+), 24 deletions(-)
drivers/scsi/lpfc/lpfc_scsi.c +12 -24
index 959ef471d758..cd91afd5c101 100644
@@ -2843,10 +2843,8 @@ lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
 	}
 out:
 	if (err_type == BGS_GUARD_ERR_MASK) {
-		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
-					0x10, 0x1);
-		cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
-			      SAM_STAT_CHECK_CONDITION;
+		scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x1);
+		set_host_byte(cmd, DID_ABORT);
 		phba->bg_guard_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
 				"9069 BLKGRD: LBA %lx grd_tag error %x != %x\n",
@@ -2854,10 +2852,8 @@ lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
 				sum, guard_tag);
 
 	} else if (err_type == BGS_REFTAG_ERR_MASK) {
-		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
-					0x10, 0x3);
-		cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
-			      SAM_STAT_CHECK_CONDITION;
+		scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x3);
+		set_host_byte(cmd, DID_ABORT);
 
 		phba->bg_reftag_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
@@ -2866,10 +2862,8 @@ lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd)
 				ref_tag, start_ref_tag);
 
 	} else if (err_type == BGS_APPTAG_ERR_MASK) {
-		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
-					0x10, 0x2);
-		cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
-			      SAM_STAT_CHECK_CONDITION;
+		scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x2);
+		set_host_byte(cmd, DID_ABORT);
 
 		phba->bg_apptag_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
@@ -2930,10 +2924,8 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 	if (lpfc_bgs_get_guard_err(bgstat)) {
 		ret = 1;
 
-		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
-				0x10, 0x1);
-		cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
-			      SAM_STAT_CHECK_CONDITION;
+		scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x1);
+		set_host_byte(cmd, DID_ABORT);
 		phba->bg_guard_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
 				"9055 BLKGRD: Guard Tag error in cmd"
@@ -2946,10 +2938,8 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 	if (lpfc_bgs_get_reftag_err(bgstat)) {
 		ret = 1;
 
-		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
-				0x10, 0x3);
-		cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
-			      SAM_STAT_CHECK_CONDITION;
+		scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x3);
+		set_host_byte(cmd, DID_ABORT);
 
 		phba->bg_reftag_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
@@ -2963,10 +2953,8 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_io_buf *lpfc_cmd,
 	if (lpfc_bgs_get_apptag_err(bgstat)) {
 		ret = 1;
 
-		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
-				0x10, 0x2);
-		cmd->result = DRIVER_SENSE << 24 | DID_ABORT << 16 |
-			      SAM_STAT_CHECK_CONDITION;
+		scsi_build_sense(cmd, 1, ILLEGAL_REQUEST, 0x10, 0x2);
+		set_host_byte(cmd, DID_ABORT);
 
 		phba->bg_apptag_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
Signature · 1 line
2.16.4
#53 lore raw

PATCH v3 31/52 mpt3sas: use scsi_build_sense()

In reply to Hannes Reinecke

Use scsi_build_sense() to format the sense code.

---
 drivers/scsi/mpt3sas/mpt3sas_scsih.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/scsi/mpt3sas/mpt3sas_scsih.c +2 -4
index a038be8a0e90..6477fb84ac60 100644
@@ -4619,10 +4619,8 @@ _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
 		ascq = 0x00;
 		break;
 	}
-	scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
-	    ascq);
-	scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
-	    SAM_STAT_CHECK_CONDITION;
+	scsi_build_sense(scmd, 0, ILLEGAL_REQUEST, 0x10, ascq);
+	set_host_byte(scmd, DID_ABORT);
 }
 
 /**
Signature · 1 line
2.16.4
#54 lore raw

PATCH v3 32/52 mvumi: use scsi_build_sense()

In reply to Hannes Reinecke

Use scsi_build_sense() to format the sense code.

---
 drivers/scsi/mvumi.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/scsi/mvumi.c +1 -4
index 8906aceda4c4..645606446bbe 100644
@@ -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;
 }
 
Signature · 1 line
2.16.4
#56 lore raw

PATCH v3 33/52 myrb: use scsi_build_sense()

In reply to Hannes Reinecke

Use scsi_build_sense() to format the sense code.

---
 drivers/scsi/myrb.c | 61 ++++++++++++-----------------------------------------
 1 file changed, 14 insertions(+), 47 deletions(-)
drivers/scsi/myrb.c +14 -47
index 539ac8ce4fcd..04a75bd0dcb5 100644
@@ -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");
Signature · 1 line
2.16.4
#57 lore raw

PATCH v3 34/52 myrs: use scsi_build_sense()

In reply to Hannes Reinecke

Use scsi_build_sense() to format the sense code.

---
 drivers/scsi/myrs.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/scsi/myrs.c +2 -7
index eb0dd566330a..70ba289aa24f 100644
@@ -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);
Signature · 1 line
2.16.4
#59 lore raw

PATCH v3 35/52 ps3rom: use scsi_build_sense()

In reply to Hannes Reinecke

Use scsi_build_sense() to format the sense code.

---
 drivers/scsi/ps3rom.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/ps3rom.c +1 -2
index f75c0b5cd587..63ff9259925a 100644
@@ -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;
Signature · 1 line
2.16.4
#60 lore raw

PATCH v3 36/52 qla2xxx: use scsi_build_sense()

In reply to Hannes Reinecke

Use scsi_build_sense() to format the sense code.

---
 drivers/scsi/qla2xxx/qla_isr.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)
drivers/scsi/qla2xxx/qla_isr.c +3 -12
index acef3d73983c..d5c0c57b9d00 100644
@@ -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;
 	}
 
Signature · 1 line
2.16.4
#62 lore raw

PATCH v3 37/52 scsi_debug: use scsi_build_sense()

In reply to Hannes Reinecke

Use scsi_build_sense() to format the sense code.

---
 drivers/scsi/scsi_debug.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/scsi/scsi_debug.c +4 -7
index d323523f5f9d..72f10e631ff4 100644
@@ -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,
Signature · 1 line
2.16.4
maintainer Acked-by on v3 37/52
#63 lore raw

Re: [PATCH 37/52] scsi_debug: use scsi_build_sense()

Quoted 3 lines · Hannes Reinecke

Use scsi_build_sense() to format the sense code.

Quoted 39 lines
---
  drivers/scsi/scsi_debug.c | 11 ++++-------
  1 file changed, 4 insertions(+), 7 deletions(-)
drivers/scsi/scsi_debug.c +4 -7
index d323523f5f9d..72f10e631ff4 100644
@@ -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,
#64 lore raw

PATCH v3 38/52 smartpqi: use scsi_build_sense()

In reply to Hannes Reinecke

Use scsi_build_sense() to format the sense code.

---
 drivers/scsi/smartpqi/smartpqi_init.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/smartpqi/smartpqi_init.c +1 -2
index 7b7ef3acb504..c0bd02613b02 100644
@@ -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);
Signature · 1 line
2.16.4
#65 lore raw

PATCH v3 39/52 stex: use scsi_build_sense()

In reply to Hannes Reinecke

Use scsi_build_sense() to format the sense code.

---
 drivers/scsi/stex.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/scsi/stex.c +1 -4
index 33287b6bdf0e..b02251868cb9 100644
@@ -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);
 }
 
Signature · 1 line
2.16.4
#67 lore raw

PATCH v3 40/52 scsi: Kill DRIVER_SENSE

In reply to Hannes Reinecke

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

---
 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   |  2 --
 drivers/scsi/megaraid/megaraid_sas_fusion.c |  1 -
 drivers/scsi/mpt3sas/mpt3sas_scsih.c        |  3 +-
 drivers/scsi/mvumi.c                        |  1 -
 drivers/scsi/scsi.c                         |  7 -----
 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                           |  9 +++---
 drivers/scsi/stex.c                         |  4 +--
 drivers/scsi/sym53c8xx_2/sym_glue.c         |  6 ++--
 drivers/scsi/ufs/ufshcd.c                   |  2 +-
 drivers/scsi/virtio_scsi.c                  |  3 +-
 drivers/scsi/vmw_pvscsi.c                   |  3 --
 drivers/target/loopback/tcm_loop.c          |  1 -
 drivers/usb/storage/cypress_atacb.c         |  4 +--
 drivers/xen/xen-scsiback.c                  |  2 +-
 include/scsi/scsi.h                         |  1 -
 include/scsi/sg.h                           |  5 ++--
 include/trace/events/scsi.h                 |  3 +-
 35 files changed, 94 insertions(+), 138 deletions(-)
drivers/ata/libata-scsi.c +5 -8
index 0fd3cb8e4e49..6ae0b579a6ca 100644
@@ -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,
drivers/scsi/NCR5380.c +1 -1
index 5559d39a00b7..ddeeed02cc8b 100644
@@ -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;
 	}
drivers/scsi/aic7xxx/aic79xx_osm.c +7 -12
index 72c67e89b911..0d83184d069c 100644
@@ -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;
drivers/scsi/aic7xxx/aic7xxx_osm.c +0 -1
index a0b444e6209d..1c718cf5083f 100644
@@ -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;
drivers/scsi/arcmsr/arcmsr_hba.c +0 -1
index 89eda0c79349..372aba7f12f3 100644
@@ -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);
 	}
 }
 
drivers/scsi/ch.c +1 -2
index 5f8153c37f77..380a519b1757 100644
@@ -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);
drivers/scsi/constants.c +1 -1
index d4c2a2e4c5d4..7809bf618606 100644
@@ -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)
 {
drivers/scsi/cxlflash/superpipe.c +21 -24

54 lines not on this page · raw message

drivers/scsi/dc395x.c +1 -1
index e79db03196f7..d32537d75439 100644
@@ -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;
drivers/scsi/esp_scsi.c +1 -2
index bb88995a12c7..f32561bbb0b5 100644
@@ -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));
 
drivers/scsi/megaraid.c +5 -9
index 21e190c38b97..007d4f2d371d 100644
@@ -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;
 
drivers/scsi/megaraid/megaraid_mbox.c +5 -9
index dc58c5ff31e4..0825e0baa7d1 100644
@@ -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;
 
drivers/scsi/megaraid/megaraid_sas_base.c +0 -2
index c40fbea06cc5..9e683c876641 100644
@@ -3548,8 +3548,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;
drivers/scsi/megaraid/megaraid_sas_fusion.c +0 -1
index e301458bcbae..a00449475095 100644
@@ -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;
 		}
 
 		/*
drivers/scsi/mpt3sas/mpt3sas_scsih.c +1 -2
index 6477fb84ac60..27f9d66a7d53 100644
@@ -5377,8 +5377,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;
drivers/scsi/mvumi.c +0 -1
index 645606446bbe..91eb879692c3 100644
@@ -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:
drivers/scsi/scsi.c +0 -7
index 59443e0184fd..b977ea651d12 100644
@@ -199,13 +199,6 @@ void scsi_finish_command(struct scsi_cmnd *cmd)
 	if (atomic_read(&sdev->device_blocked))
 		atomic_set(&sdev->device_blocked, 0);
 
-	/*
-	 * If we have valid sense information, then some kind of recovery
-	 * must have taken place.  Make a note of this.
-	 */
-	if (SCSI_SENSE_VALID(cmd))
-		cmd->result |= (DRIVER_SENSE << 24);
-
 	SCSI_LOG_MLCOMPLETE(4, sdev_printk(KERN_INFO, sdev,
 				"Notifying upper driver of completion "
 				"(result %x)\n", cmd->result));
drivers/scsi/scsi_debug.c +2 -2
index 72f10e631ff4..be7036cd4e62 100644
@@ -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;
drivers/scsi/scsi_ioctl.c +1 -1
index 57bcd05605bf..70c1eab90710 100644
@@ -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:
drivers/scsi/scsi_lib.c +5 -8
index 2babf6df8066..eac14ecc82dc 100644
@@ -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);
drivers/scsi/scsi_scan.c +1 -1
index 058079f915f1..36385f6c5cdc 100644
@@ -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) ||
drivers/scsi/scsi_transport_spi.c +1 -1
index f8661062ef95..9a08a60552a4 100644
@@ -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;
 	}
drivers/scsi/sd.c +17 -16
index 326e2877f169..220990183b6b 100644
@@ -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 */
drivers/scsi/sg.c +5 -4
index 60ff388d04b9..c6f5e0a8d271 100644
@@ -503,10 +503,11 @@ 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) {
+		old_hdr->driver_status |= DRIVER_SENSE;
 		memcpy(old_hdr->sense_buffer, srp->sense_b,
 		       sizeof (old_hdr->sense_buffer));
+	}
 	switch (hp->host_status) {
 	/* This setup of 'result' is for backward compatibility and is best
 	   ignored by the user who should use target, host + driver status */
@@ -574,8 +575,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 */
@@ -585,6 +585,7 @@ sg_new_read(Sg_fd * sfp, char __user *buf, size_t count, Sg_request * srp)
 				goto err_out;
 			}
 			hp->sb_len_wr = len;
+			hp->driver_status |= DRIVER_SENSE;
 		}
 	}
 	if (hp->status || hp->host_status || hp->driver_status)
drivers/scsi/stex.c +2 -2
index b02251868cb9..b7ebc869d30f 100644
@@ -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;
drivers/scsi/sym53c8xx_2/sym_glue.c +2 -4
index 2ca018ce796f..e72fc73cdd96 100644
@@ -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)
drivers/scsi/ufs/ufshcd.c +1 -1
index c28c144d9b4a..e411aadb6da7 100644
@@ -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);
 	}
 
drivers/scsi/virtio_scsi.c +1 -2
index bfec84aacd90..97b980bf145f 100644
@@ -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);
drivers/scsi/vmw_pvscsi.c +0 -3
index 70008816c91f..74e5ed940952 100644
@@ -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) {
drivers/target/loopback/tcm_loop.c +0 -1
index 3305b47fdf53..99a88aee1c94 100644
@@ -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;
 
drivers/usb/storage/cypress_atacb.c +2 -2
index a6f3267bbef6..ba10ee3585c1 100644
@@ -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,
drivers/xen/xen-scsiback.c +1 -1
index ba0942e481bc..e130b4426c62 100644
@@ -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;
include/scsi/scsi.h +0 -1
index ce8096a99981..f68c234dd3e8 100644
@@ -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.
include/scsi/sg.h +3 -2
index f91bcca604e4..28ba4f6a7a35 100644
@@ -101,6 +101,8 @@ typedef struct sg_io_hdr
 #define SG_INFO_DIRECT_IO 0x2   /* direct IO requested and performed */
 #define SG_INFO_MIXED_IO 0x4    /* part direct, part indirect IO */
 
+/* Old linux DRIVER_SENSE setting */
+#define DRIVER_SENSE 0x08
 
 typedef struct sg_scsi_id { /* used by SG_GET_SCSI_ID ioctl() */
     int host_no;        /* as in "scsi<n>" where 'n' is one of 0, 1, 2 etc */
@@ -234,8 +236,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 */
 
 
include/trace/events/scsi.h +1 -2
index f624969a4f14..404fbc54bc32 100644
@@ -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)					\
Signature · 1 line
2.16.4
#68 lore raw

Re: [PATCH 40/52] scsi: Kill DRIVER_SENSE

Quoted 55 lines · Hannes Reinecke

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

---
 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   |  2 --
 drivers/scsi/megaraid/megaraid_sas_fusion.c |  1 -
 drivers/scsi/mpt3sas/mpt3sas_scsih.c        |  3 +-
 drivers/scsi/mvumi.c                        |  1 -
 drivers/scsi/scsi.c                         |  7 -----
 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                           |  9 +++---
 drivers/scsi/stex.c                         |  4 +--
 drivers/scsi/sym53c8xx_2/sym_glue.c         |  6 ++--
 drivers/scsi/ufs/ufshcd.c                   |  2 +-
 drivers/scsi/virtio_scsi.c                  |  3 +-
 drivers/scsi/vmw_pvscsi.c                   |  3 --
 drivers/target/loopback/tcm_loop.c          |  1 -
 drivers/usb/storage/cypress_atacb.c         |  4 +--
 drivers/xen/xen-scsiback.c                  |  2 +-
 include/scsi/scsi.h                         |  1 -
 include/scsi/sg.h                           |  5 ++--
 include/trace/events/scsi.h                 |  3 +-
 35 files changed, 94 insertions(+), 138 deletions(-)
(quoted diff) +0 -0
 	}
drivers/scsi/aic7xxx/aic79xx_osm.c +0 -0
index 72c67e89b911..0d83184d069c 100644

drivers/scsi/aic7xxx/aic79xx_osm.c ahd_linux_handle_scsi_status(struct ahd_softc · line 1944

Quoted 6 lines
drivers/scsi/aic7xxx/aic79xx_osm.c +1 -1
@@ -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;

Perhaps you should consider using set_status_byte() here, too?

Regards,
Martin

#69 lore raw

PATCH v3 41/52 scsi: Kill DRIVER_HARD

In reply to Hannes Reinecke

Unused.

---
 drivers/scsi/constants.c    | 2 +-
 include/scsi/scsi.h         | 1 -
 include/trace/events/scsi.h | 3 +--
 3 files changed, 2 insertions(+), 4 deletions(-)
drivers/scsi/constants.c +1 -1
index 7809bf618606..b2ba83e6b98d 100644
@@ -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)
 {
include/scsi/scsi.h +0 -1
index f68c234dd3e8..407e188a0aae 100644
@@ -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.
include/trace/events/scsi.h +1 -2
index 404fbc54bc32..e15373917d1e 100644
@@ -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)					\
Signature · 1 line
2.16.4
#70 lore raw

PATCH v3 42/52 scsi_error: use DID_TIME_OUT instead of DRIVER_TIMEOUT

In reply to Hannes Reinecke

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

---
 drivers/scsi/scsi_error.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/scsi_error.c +2 -2
index bfaac355454b..22893050d574 100644
@@ -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",
Signature · 1 line
2.16.4
#71 lore raw

PATCH v3 43/52 scsi: Kill DRIVER_TIMEOUT

In reply to Hannes Reinecke

Unused now.

---
 drivers/scsi/constants.c    | 2 +-
 include/scsi/scsi.h         | 1 -
 include/trace/events/scsi.h | 3 +--
 3 files changed, 2 insertions(+), 4 deletions(-)
drivers/scsi/constants.c +1 -1
index b2ba83e6b98d..1780837ea11e 100644
@@ -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)
 {
include/scsi/scsi.h +0 -1
index 407e188a0aae..274cc9e77634 100644
@@ -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.
include/trace/events/scsi.h +1 -2
index e15373917d1e..a1b4da442c5c 100644
@@ -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)					\
Signature · 1 line
2.16.4
#72 lore raw

PATCH v3 44/52 scsi: do not use DRIVER_INVALID

In reply to 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.

---
 drivers/scsi/constants.c    | 3 +--
 drivers/scsi/hptiop.c       | 2 +-
 drivers/scsi/mvumi.c        | 4 ++--
 drivers/scsi/vmw_pvscsi.c   | 3 ---
 include/scsi/scsi.h         | 2 --
 include/trace/events/scsi.h | 3 +--
 6 files changed, 5 insertions(+), 12 deletions(-)
drivers/scsi/constants.c +1 -2
index 1780837ea11e..1cee98534bfd 100644
@@ -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)
 {
drivers/scsi/hptiop.c +1 -1
index 6a2561f26e38..e940d297fb96 100644
@@ -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_ABORT << 16);
 		break;
 	}
 
drivers/scsi/mvumi.c +2 -2
index 91eb879692c3..c53e74e796d8 100644
@@ -1319,7 +1319,7 @@ static void mvumi_complete_cmd(struct mvumi_hba *mhba, struct mvumi_cmd *cmd,
 		}
 		break;
 	default:
-		scmd->result |= (DRIVER_INVALID << 24) | (DID_ABORT << 16);
+		scmd->result |= (DID_ABORT << 16);
 		break;
 	}
 
@@ -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),
drivers/scsi/vmw_pvscsi.c +0 -3
index 74e5ed940952..76ed02f4920b 100644
@@ -590,9 +590,6 @@ static void pvscsi_complete_request(struct pvscsi_adapter *adapter,
 		case BTSTAT_LUNMISMATCH:
 		case BTSTAT_TAGREJECT:
 		case BTSTAT_BADMSG:
-			cmd->result = (DRIVER_INVALID << 24);
-			/* fall through */
-
 		case BTSTAT_HAHARDWARE:
 		case BTSTAT_INVPHASE:
 		case BTSTAT_HATIMEOUT:
include/scsi/scsi.h +0 -2
index 274cc9e77634..4afb5e8a0a58 100644
@@ -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.
  */
include/trace/events/scsi.h +1 -2
index a1b4da442c5c..83bc7d97a469 100644
@@ -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)					\
Signature · 1 line
2.16.4
#73 lore raw

PATCH v3 45/52 st: return error code in st_scsi_execute()

In reply to Hannes Reinecke

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

---
 drivers/scsi/st.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/st.c +2 -2
index e3266a64a477..5f38369cc62f 100644
@@ -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;
 		}
 	}
 
Signature · 1 line
2.16.4
#74 lore raw

PATCH v3 46/52 scsi_ioctl: return error code when blk_rq_map_kern() fails

In reply to Hannes Reinecke

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

---
 block/scsi_ioctl.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
block/scsi_ioctl.c +4 -3
index f5e0ad65e86a..1ab1b8d9641c 100644
@@ -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);
Signature · 1 line
2.16.4
#75 lore raw

PATCH v3 47/52 scsi_dh_alua: do not interpret DRIVER_ERROR

In reply to 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.

---
 drivers/scsi/device_handler/scsi_dh_alua.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/scsi/device_handler/scsi_dh_alua.c +0 -4
index 4971104b1817..9feea102468b 100644
@@ -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);
Signature · 1 line
2.16.4
#76 lore raw

PATCH v3 48/52 3w-9xxx: Kill unreachable code in twa_interrupt()

In reply to Hannes Reinecke

twa_fill_sense() can never return '1', so the check is pointless.

---
 drivers/scsi/3w-9xxx.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/scsi/3w-9xxx.c +0 -6
index 3337b1e80412..b275ce3b0fbd 100644
@@ -1339,12 +1339,6 @@ static irqreturn_t twa_interrupt(int irq, void *dev_instance)
 					cmd->result = (DID_OK << 16);
 				}
 
-				/* If error, command failed */
-				if (error == 1) {
-					/* Ask for a host reset */
-					cmd->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
-				}
-
 				/* Report residual bytes for single sgl */
 				if ((scsi_sg_count(cmd) <= 1) && (full_command_packet->command.newcommand.status == 0)) {
 					if (full_command_packet->command.newcommand.sg_list[0].length < scsi_bufflen(tw_dev->srb[request_id]))
Signature · 1 line
2.16.4
maintainer Acked-by on v3 48/52
#77 lore raw

Re: [PATCH 48/52] 3w-9xxx: Kill unreachable code in twa_interrupt()

Quoted 26 lines · Hannes Reinecke

twa_fill_sense() can never return '1', so the check is pointless.

---
 drivers/scsi/3w-9xxx.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/scsi/3w-9xxx.c +0 -7
index 3337b1e80412..b275ce3b0fbd 100644
@@ -1339,12 +1339,6 @@ static irqreturn_t twa_interrupt(int irq, void *dev_instance)
                                        cmd->result = (DID_OK << 16);
                                }
 
-                               /* If error, command failed */
-                               if (error == 1) {
-                                       /* Ask for a host reset */
-                                       cmd->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
-                               }
-
                                /* Report residual bytes for single sgl */
                                if ((scsi_sg_count(cmd) <= 1) && (full_command_packet->command.newcommand.status == 0)) {
                                        if (full_command_packet->command.newcommand.sg_list[0].length < scsi_bufflen(tw_dev->srb[request_id]))
--
Quoted 2 lines

2.16.4

#78 lore raw

PATCH v3 49/52 xen-scsiback: stop using DRIVER_ERROR

In reply to Hannes Reinecke

Always return SCSI host byte errors and drop the usage of DRIVER_ERROR status.
This also fixes an issue where we would return a host byte value interpreted as a driver byte.

---
 drivers/xen/xen-scsiback.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/xen/xen-scsiback.c +6 -6
index e130b4426c62..8e93b7113b26 100644
@@ -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=00\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,10 +757,10 @@ static int scsiback_do_cmd_fn(struct vscsibk_info *info)
 				result = DID_NO_CONNECT;
 				break;
 			default:
-				result = DRIVER_ERROR;
+				result = DID_ERROR;
 				break;
 			}
-			scsiback_send_response(info, NULL, result << 24, 0,
+			scsiback_send_response(info, NULL, result << 16, 0,
 					       ring_req.rqid);
 			return 1;
 		}
@@ -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;
Signature · 1 line
2.16.4
#79 lore raw

PATCH v3 50/52 scsi: stop using DRIVER_ERROR

In reply to 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.

---
 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(-)
drivers/scsi/ch.c +2 -0
index 380a519b1757..173f2c065116 100644
@@ -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);
drivers/scsi/constants.c +1 -1
index 1cee98534bfd..57c544fd8c6b 100644
@@ -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)
 {
drivers/scsi/scsi.c +2 -0
index b977ea651d12..de7f218c0923 100644
@@ -502,6 +502,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)
drivers/scsi/scsi_lib.c +9 -6
index eac14ecc82dc..530d6a6815a1 100644
@@ -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;
drivers/scsi/ufs/ufshcd.c +1 -3
index e411aadb6da7..87a11289202e 100644
@@ -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);
include/scsi/scsi.h +0 -1
index 4afb5e8a0a58..af9f9ed5321e 100644
@@ -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.
include/trace/events/scsi.h +1 -2
index 83bc7d97a469..b2d3ce9e3990 100644
@@ -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)					\
Signature · 1 line
2.16.4
#80 lore raw

PATCH v3 51/52 scsi: Kill DRIVER_MEDIA, DRIVER_SOFT, and DRIVER_BUSY

In reply to Hannes Reinecke

Unused.

---
 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(-)
drivers/message/fusion/mptscsih.c +1 -1
index f0737c57ed5f..0064547cef1a 100644
@@ -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:-(
 			 */
drivers/scsi/constants.c +1 -1
index 57c544fd8c6b..be7eacb67841 100644
@@ -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)
 {
include/scsi/scsi.h +0 -8
index af9f9ed5321e..acd0b2182db1 100644
@@ -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.
  */
include/trace/events/scsi.h +1 -4
index b2d3ce9e3990..5984db6996bb 100644
@@ -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)					\
Signature · 1 line
2.16.4
#81 lore raw

PATCH v3 52/52 scsi: Drop the now obsolete driver_byte definitions

In reply to Hannes Reinecke

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

---
 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(-)
Documentation/scsi/scsi_mid_low_api.txt +1 -2
index c1dd4939f4ae..ab072fff5fb8 100644
@@ -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
block/bsg-lib.c +1 -1
index 347dda16c2f4..bc0c813b3a99 100644
@@ -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;
block/bsg.c +1 -1
index 833c44b3d458..dcde05348a48 100644
@@ -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;
block/scsi_ioctl.c +1 -1
index 1ab1b8d9641c..b8b9b72fab2a 100644
@@ -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;
drivers/scsi/constants.c +0 -14
index be7eacb67841..924131ea0b11 100644
@@ -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),
drivers/scsi/scsi_logging.c +2 -8
index c91fa3feb930..d0b646430375 100644
@@ -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);
drivers/scsi/sd.c +4 -5
index 220990183b6b..4599954b7bb0 100644
@@ -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");
 }
 
drivers/scsi/sd_zbc.c +2 -2
index de4019dc0f0b..d96a2506d965 100644
@@ -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;
 	}
 
drivers/scsi/sg.c +2 -3
index c6f5e0a8d271..7c5d3c25ccea 100644
@@ -1354,7 +1354,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)))
@@ -1362,8 +1362,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) {
drivers/scsi/sr.c +1 -1
index 4664fdf75c0f..05969bb1860c 100644
@@ -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:
drivers/scsi/sr_ioctl.c +1 -1
index ffcf902da390..02bfbbfb6f03 100644
@@ -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;
drivers/scsi/st.c +2 -2
index 5f38369cc62f..9ac262d6ccab 100644
@@ -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 &&
include/scsi/scsi.h +0 -3
index acd0b2182db1..39ae398d98a9 100644
@@ -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)
include/scsi/scsi_cmnd.h +0 -4
index 9b9ca629097d..fe1ac844c114 100644
@@ -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)
 {
include/trace/events/scsi.h +1 -6
index 5984db6996bb..428cca71c2ba 100644
@@ -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))
Signature · 1 line
2.16.4
#82 lore raw

Re: [PATCH 52/52] scsi: Drop the now obsolete driver_byte definitions

Quoted 13 lines · Hannes Reinecke

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

---
 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 ++--
Quoted 9 lines
 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(-)

While I generally like this change, the driver byte is part of the sg_io user space API, and used in sg3_utils and multipath-tools (in particular, DRIVER_SENSE), and likely in other user space tools as well. Can we simply ditch it without adding some compatibility code to sg and bsg?

Thanks,
Martin

#83 lore raw

Re: [PATCH 52/52] scsi: Drop the now obsolete driver_byte definitions

Quoted 24 lines · Martin Wilck
Quoted 13 lines · Hannes Reinecke

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

---
 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 ++--
Quoted 9 lines
 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(-)
Quoted 6 lines

While I generally like this change, the driver byte is part of the sg_io user space API, and used in sg3_utils and multipath-tools (in particular, DRIVER_SENSE), and likely in other user space tools as well. Can we simply ditch it without adding some compatibility code to sg and bsg?

Why, but I did...
sg and bsg should report to userland exactly the same values as before; or at least that was the plan.

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke		      Teamlead Storage & Networking
[email protected]			                  +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 247165 (AG München), GF: Felix Imendörffer
#84 lore raw

Re: [PATCH 52/52] scsi: Drop the now obsolete driver_byte definitions

Quoted 9 lines · Hannes Reinecke
Quoted 8 lines · Martin Wilck

While I generally like this change, the driver byte is part of the sg_io user space API, and used in sg3_utils and multipath-tools (in particular, DRIVER_SENSE), and likely in other user space tools as well. Can we simply ditch it without adding some compatibility code to
sg and bsg?

Quoted 4 lines

Why, but I did...
sg and bsg should report to userland exactly the same values as before;
or at least that was the plan.

I am sorry, I overlooked that part in sg.c where you set DRIVER_SENSE. It's the only DRIVER_xyz code that you set though. Is that sufficient?

In bsg.c, I just see

@@ -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;
	hdr->driver_status = 0;

To me that looks as if userspace might get a different result as before. Similar in bsg_lib.c. I may be overlooking something again, but not being familiar with the bsg driver, I thought I'd better ask.

(Nitpick: your change obsoletes the check for hdr->driver_status two lines below).

Thanks
Martin

#85 lore raw

Re: [PATCH 52/52] scsi: Drop the now obsolete driver_byte definitions

Quoted 31 lines · Martin Wilck
Quoted 9 lines · Hannes Reinecke
Quoted 8 lines · Martin Wilck

While I generally like this change, the driver byte is part of the sg_io user space API, and used in sg3_utils and multipath-tools (in particular, DRIVER_SENSE), and likely in other user space tools as well. Can we simply ditch it without adding some compatibility code to
sg and bsg?

Quoted 4 lines

Why, but I did...
sg and bsg should report to userland exactly the same values as before;
or at least that was the plan.

I am sorry, I overlooked that part in sg.c where you set DRIVER_SENSE. It's the only DRIVER_xyz code that you set though. Is that sufficient?

In bsg.c, I just see

block/bsg.c +1 -1
@@ -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;
	hdr->driver_status = 0;
Quoted 4 lines

To me that looks as if userspace might get a different result as before. Similar in bsg_lib.c. I may be overlooking something again, but not being familiar with the bsg driver, I thought I'd better ask.

For bsg the driver status was never set, so while in theory any of the DRIVER_XXX values could be returned, they were never set. So that change is valid.

Quoted 3 lines

(Nitpick: your change obsoletes the check for hdr->driver_status two lines below).

Sure, can do.

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke		      Teamlead Storage & Networking
[email protected]			                  +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 247165 (AG München), GF: Felix Imendörffer
#86 lore raw
In reply to Hannes Reinecke
Quoted 25 lines · 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

Quoted 6 lines

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.

Martin, ping?

I've got another patchset queued for splitting off the 'result' field, which kinda depends on this one...

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke		      Teamlead Storage & Networking
[email protected]			                  +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 247165 (AG München), GF: Felix Imendörffer
#87 lore raw

Hi Hannes,

Quoted 4 lines

Martin, ping?

I've got another patchset queued for splitting off the 'result' field, which kinda depends on this one...

It's a pretty big and intrusive change. And even though we (somewhat unexpectedly) got another week, I still think it's too risky for 5.5.

I plan on merging it first thing when the queue for 5.6 opens.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#88 lore raw
Quoted 5 lines · Martin K. Petersen

Hi Hannes,

Quoted 2 lines

Martin, ping?

Quoted 8 lines
Quoted 2 lines

I've got another patchset queued for splitting off the 'result' field, which kinda depends on this one...

It's a pretty big and intrusive change. And even though we (somewhat unexpectedly) got another week, I still think it's too risky for 5.5.

I plan on merging it first thing when the queue for 5.6 opens.

Sure. Just wanted to know if it's worth playing around with the next round of patches (splitting off 'result', thus ending a history of shifting status bytes into wrong places :-)

Thanks for the heads-up.

Should I do a respin for 5.5?

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke		      Teamlead Storage & Networking
[email protected]			                  +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 247165 (AG München), GF: Felix Imendörffer
#89 lore raw

Hannes,

Quoted 1 line

Should I do a respin for 5.5?

I suggest you rebase on top of -rc1 once it's out. If you want a bit more eyes on the series before then, just post on top of current scsi-queue.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering