mbox series

[v4,00/50] Remove the SCSI pointer from struct scsi_cmnd

Message ID 20220216210233.28774-1-bvanassche@acm.org
Headers show
Series Remove the SCSI pointer from struct scsi_cmnd | expand

Message

Bart Van Assche Feb. 16, 2022, 9:01 p.m. UTC
Hi Martin,

The size of struct scsi_cmnd matters for embedded devices. One of the
largest members of that structure is the SCSI pointer. That structure is
relevant for SCSI-II drivers but not for modern SCSI drivers. Hence this
patch series that removes the SCSI pointer from struct scsi_cmnd and moves
it into driver-private command data.

Please consider this patch series for kernel v5.18.

Thanks,

Bart.

Changes compared to v3:
- Split the libfc patch into three patches (libfc, bnx2fc, qedf). Removed the
  libfc private command information and also the status information from the
  bnx2fc and qedf private command data.
- Removed the following statement from libfc_host_alloc():
    WARN_ON_ONCE(sht->cmd_size < sizeof(struct libfc_cmd_priv));

Changes compared to v2:
- Split the ips and nsp_cs patches at the start of this series such that there
  is only one change in each patch.
- Changed the return type of ips_release() from 'int' into 'void' since the
  value returned by that function is not used.
- Remove duplicate <scsi/scsi.h> include directives.
- Use struct scsi_pointer directly instead of wrapping it inside another
  structure for drivers that do not use host_scribble as requested by Hannes.
- Updated the error messages that refer to the SCp.ptr member if that member
  is removed by this patch series.
- Removed WARN_ON_ONCE(sht->cmd_size < sizeof(struct iscsi_cmd)) from
  iscsi_host_alloc() and removed struct iscsi_cmd from the qla4xxx private data
  as requested by Mike.
- Changed 'cmd - 1' into a container_of() expression in megaraid.h (Hannes).
- Removed a cast from the mvsas driver (John).
- Modified the comment in include/scsi/scsi_cmnd.h in the last patch (John).

Changes compared to v1:
- Removed BUILD_BUG_ON(sizeof(...) > sizeof(struct scsi_pointer)) statements.
- Added two void casts in front of I/O statements as requested by Johannes.
- Improved source code formatting in the aha152x driver.
- Restored the DID_OK constant in a SCSI result expression.
- Updated Reviewed-by tags.

Bart Van Assche (50):
  scsi: ips: Remove an unreachable statement
  scsi: ips: Change the return type of ips_release() into 'void'
  scsi: ips: Use true and false instead of TRUE and FALSE
  scsi: nsp_cs: Change the return type of two functions into 'void'
  scsi: nsp_cs: Use true and false instead of TRUE and FALSE
  scsi: Remove drivers/scsi/scsi.h
  scsi: NCR5380: Remove the NCR5380_CMD_SIZE macro
  scsi: NCR5380: Introduce the NCR5380_cmd_priv() function
  scsi: NCR5380: Move the SCSI pointer to private command data
  scsi: arm: Rename arm/scsi.h into arm/arm_scsi.h
  scsi: arm: Move the SCSI pointer to private command data
  scsi: 53c700: Stop clearing SCSI pointer fields
  scsi: aacraid: Move the SCSI pointer to private command data
  scsi: advansys: Move the SCSI pointer to private command data
  scsi: aha1542: Remove a set-but-not-used array
  scsi: aha152x: Move the SCSI pointer to private command data
  scsi: bfa: Stop using the SCSI pointer
  scsi: csio: Stop using the SCSI pointer
  scsi: dc395x: Stop using the SCSI pointer
  scsi: esp_scsi: Stop using the SCSI pointer
  scsi: fdomain: Move the SCSI pointer to private command data
  scsi: fnic: Fix a tracing statement
  scsi: fnic: Stop using the SCSI pointer
  scsi: hptiop: Stop using the SCSI pointer
  scsi: imm: Move the SCSI pointer to private command data
  scsi: iscsi: Stop using the SCSI pointer
  scsi: initio: Stop using the SCSI pointer
  scsi: libfc: Stop using the SCSI pointer
  scsi: bnx2fc: Stop using the SCSI pointer
  scsi: qedf: Stop using the SCSI pointer
  scsi: mac53c94: Fix a set-but-not-used compiler warning
  scsi: mac53c94: Move the SCSI pointer to private command data
  scsi: megaraid: Stop using the SCSI pointer
  scsi: megasas: Stop using the SCSI pointer
  scsi: mesh: Move the SCSI pointer to private command data
  scsi: mvsas: Fix a set-but-not-used warning
  scsi: mvumi: Stop using the SCSI pointer
  scsi: nsp32: Stop using the SCSI pointer
  scsi: nsp_cs: Move the SCSI pointer to private command data
  scsi: sym53c500_cs: Move the SCSI pointer to private command data
  scsi: ppa: Move the SCSI pointer to private command data
  scsi: qla1280: Move the SCSI pointer to private command data
  scsi: qla2xxx: Stop using the SCSI pointer
  scsi: smartpqi: Stop using the SCSI pointer
  scsi: sym53c8xx_2: Move the SCSI pointer to private command data
  scsi: usb: Stop using the SCSI pointer
  scsi: wd719x: Stop using the SCSI pointer
  scsi: wd33c93: Move the SCSI pointer to private command data
  scsi: zalon: Stop using the SCSI pointer
  scsi: core: Remove struct scsi_pointer from struct scsi_cmnd

 drivers/infiniband/ulp/iser/iscsi_iser.c    |   1 +
 drivers/scsi/53c700.c                       |   2 -
 drivers/scsi/NCR5380.c                      |  97 ++++---
 drivers/scsi/NCR5380.h                      |   6 +-
 drivers/scsi/a2091.c                        |  25 +-
 drivers/scsi/a3000.c                        |  25 +-
 drivers/scsi/aacraid/aachba.c               |  43 +--
 drivers/scsi/aacraid/aacraid.h              |  24 +-
 drivers/scsi/aacraid/comminit.c             |   2 +-
 drivers/scsi/aacraid/linit.c                |  21 +-
 drivers/scsi/advansys.c                     |  22 +-
 drivers/scsi/aha152x.c                      | 268 ++++++++++--------
 drivers/scsi/aha1542.c                      |   3 +-
 drivers/scsi/aha1740.c                      |   6 +-
 drivers/scsi/arm/acornscsi.c                |  28 +-
 drivers/scsi/arm/{scsi.h => arm_scsi.h}     |  37 ++-
 drivers/scsi/arm/arxescsi.c                 |   6 +-
 drivers/scsi/arm/cumana_1.c                 |   2 +-
 drivers/scsi/arm/cumana_2.c                 |   8 +-
 drivers/scsi/arm/eesox.c                    |   8 +-
 drivers/scsi/arm/fas216.c                   |  36 ++-
 drivers/scsi/arm/fas216.h                   |   4 +
 drivers/scsi/arm/oak.c                      |   2 +-
 drivers/scsi/arm/powertec.c                 |   8 +-
 drivers/scsi/arm/queue.c                    |   6 +-
 drivers/scsi/atari_scsi.c                   |   9 +-
 drivers/scsi/be2iscsi/be_main.c             |   3 +-
 drivers/scsi/bfa/bfad_im.c                  |  27 +-
 drivers/scsi/bfa/bfad_im.h                  |  16 ++
 drivers/scsi/bnx2fc/bnx2fc.h                |   9 +-
 drivers/scsi/bnx2fc/bnx2fc_fcoe.c           |   1 +
 drivers/scsi/bnx2fc/bnx2fc_io.c             |  23 +-
 drivers/scsi/bnx2i/bnx2i_iscsi.c            |   1 +
 drivers/scsi/csiostor/csio_scsi.c           |  20 +-
 drivers/scsi/csiostor/csio_scsi.h           |  10 +
 drivers/scsi/cxgbi/cxgb3i/cxgb3i.c          |   1 +
 drivers/scsi/cxgbi/cxgb4i/cxgb4i.c          |   1 +
 drivers/scsi/dc395x.c                       |   3 -
 drivers/scsi/dmx3191d.c                     |   2 +-
 drivers/scsi/esp_scsi.c                     |   4 +-
 drivers/scsi/esp_scsi.h                     |   3 +-
 drivers/scsi/fcoe/fcoe.c                    |   1 +
 drivers/scsi/fdomain.c                      |  64 +++--
 drivers/scsi/fnic/fnic.h                    |  27 +-
 drivers/scsi/fnic/fnic_main.c               |   1 +
 drivers/scsi/fnic/fnic_scsi.c               | 289 ++++++++++----------
 drivers/scsi/g_NCR5380.c                    |   8 +-
 drivers/scsi/gvp11.c                        |  25 +-
 drivers/scsi/hptiop.c                       |   1 +
 drivers/scsi/hptiop.h                       |   4 +-
 drivers/scsi/imm.c                          |  88 +++---
 drivers/scsi/imm.h                          |   5 +
 drivers/scsi/initio.c                       |  14 +-
 drivers/scsi/initio.h                       |   9 +
 drivers/scsi/ips.c                          |  52 ++--
 drivers/scsi/iscsi_tcp.c                    |   1 +
 drivers/scsi/libfc/fc_fcp.c                 |  26 +-
 drivers/scsi/libiscsi.c                     |  20 +-
 drivers/scsi/mac53c94.c                     |  27 +-
 drivers/scsi/mac53c94.h                     |  11 +
 drivers/scsi/mac_scsi.c                     |   9 +-
 drivers/scsi/megaraid.c                     |  21 +-
 drivers/scsi/megaraid.h                     |  23 +-
 drivers/scsi/megaraid/megaraid_sas.h        |  12 +
 drivers/scsi/megaraid/megaraid_sas_base.c   |   8 +-
 drivers/scsi/megaraid/megaraid_sas_fusion.c |  15 +-
 drivers/scsi/mesh.c                         |  20 +-
 drivers/scsi/mesh.h                         |  11 +
 drivers/scsi/mvme147.c                      |  16 +-
 drivers/scsi/mvsas/mv_init.c                |   6 +-
 drivers/scsi/mvumi.c                        |   9 +-
 drivers/scsi/mvumi.h                        |   9 +
 drivers/scsi/ncr53c8xx.c                    |  22 +-
 drivers/scsi/ncr53c8xx.h                    |   6 +
 drivers/scsi/nsp32.c                        |  20 +-
 drivers/scsi/nsp32.h                        |   9 +
 drivers/scsi/pcmcia/aha152x_stub.c          |   9 +-
 drivers/scsi/pcmcia/nsp_cs.c                | 246 +++++++++--------
 drivers/scsi/pcmcia/nsp_cs.h                |   8 +-
 drivers/scsi/pcmcia/nsp_debug.c             |   2 +-
 drivers/scsi/pcmcia/qlogic_stub.c           |   9 +-
 drivers/scsi/pcmcia/sym53c500_cs.c          |  47 ++--
 drivers/scsi/ppa.c                          |  75 ++---
 drivers/scsi/qedf/qedf.h                    |  10 +-
 drivers/scsi/qedf/qedf_io.c                 |  25 +-
 drivers/scsi/qedf/qedf_main.c               |   3 +-
 drivers/scsi/qedi/qedi_fw.c                 |   4 +-
 drivers/scsi/qedi/qedi_iscsi.c              |   1 +
 drivers/scsi/qla1280.c                      |  21 +-
 drivers/scsi/qla1280.h                      |   3 +-
 drivers/scsi/qla2xxx/qla_def.h              |   2 -
 drivers/scsi/qla2xxx/qla_os.c               |  13 +-
 drivers/scsi/qla4xxx/ql4_def.h              |  16 +-
 drivers/scsi/qla4xxx/ql4_os.c               |  13 +-
 drivers/scsi/qlogicfas.c                    |   6 +-
 drivers/scsi/qlogicfas408.c                 |   6 +-
 drivers/scsi/scsi.h                         |  46 ----
 drivers/scsi/sg.c                           |   8 +-
 drivers/scsi/sgiwd93.c                      |  24 +-
 drivers/scsi/smartpqi/smartpqi_init.c       |  14 +-
 drivers/scsi/sun3_scsi.c                    |   6 +-
 drivers/scsi/sym53c8xx_2/sym_glue.c         |   4 +-
 drivers/scsi/wd33c93.c                      | 119 ++++----
 drivers/scsi/wd33c93.h                      |   4 +
 drivers/scsi/wd719x.c                       |  12 +-
 drivers/scsi/wd719x.h                       |   1 +
 drivers/scsi/zalon.c                        |   1 +
 drivers/usb/image/microtek.c                |   8 +-
 drivers/usb/storage/debug.c                 |   1 -
 drivers/usb/storage/uas.c                   |  43 ++-
 include/scsi/libfc.h                        |   9 +
 include/scsi/libiscsi.h                     |  12 +
 include/scsi/scsi_cmnd.h                    |  14 +-
 113 files changed, 1484 insertions(+), 1073 deletions(-)
 rename drivers/scsi/arm/{scsi.h => arm_scsi.h} (75%)
 delete mode 100644 drivers/scsi/scsi.h

Comments

Hannes Reinecke Feb. 17, 2022, 7:05 a.m. UTC | #1
On 2/16/22 22:02, Bart Van Assche wrote:
> Move the fc_fcp_pkt pointer, the residual length and the SCSI status into
> the new data structure libfc_cmd_priv. This patch prepares for removal of
> the SCSI pointer from struct scsi_cmnd.
> 
> The user of the libfc data path functions have been identified as follows:
> $ git grep -lw fc_queuecommand | grep -v scsi/libfc/
> drivers/scsi/fcoe/fcoe.c
> 
> Cc: Hannes Reinecke <hare@suse.de>
> Cc: Saurav Kashyap <skashyap@marvell.com>
> Cc: Javed Hasan <jhasan@marvell.com>
> Reviewed-by: Himanshu Madhani <himanshu.madhani@oracle.com>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
>   drivers/scsi/fcoe/fcoe.c    |  1 +
>   drivers/scsi/libfc/fc_fcp.c | 26 +++++++++++---------------
>   include/scsi/libfc.h        |  9 +++++++++
>   3 files changed, 21 insertions(+), 15 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
Hannes Reinecke Feb. 17, 2022, 7:06 a.m. UTC | #2
On 2/16/22 22:02, Bart Van Assche wrote:
> Set .cmd_size in the SCSI host template instead of using the SCSI pointer
> from struct scsi_cmnd. Remove the CMD_SCSI_STATUS() assignment because the
> assigned value is not used.
> 
> This patch prepares for removal of the SCSI pointer from struct scsi_cmnd.
> 
> Cc: Hannes Reinecke <hare@suse.de>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
>   drivers/scsi/qedf/qedf.h      | 10 +++++++++-
>   drivers/scsi/qedf/qedf_io.c   | 25 ++++++++++++-------------
>   drivers/scsi/qedf/qedf_main.c |  3 ++-
>   3 files changed, 23 insertions(+), 15 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
Finn Thain Feb. 18, 2022, 12:45 a.m. UTC | #3
Hi Bart,

On Wed, 16 Feb 2022, Bart Van Assche wrote:

> ...
>   scsi: NCR5380: Introduce the NCR5380_cmd_priv() function
>   scsi: NCR5380: Move the SCSI pointer to private command data

Please replace those two patches with the one below. This one is better 
because it adds less source code, adds less scsi_cmnd private data, 
updates an overlooked comment, avoids anything like "struct scsi_pointer" 
and doesn't shadow any local variables.

From: Finn Thain <fthain@linux-m68k.org>
Subject: scsi: NCR5380: Add SCp members to struct NCR5380_cmd

This is necessary for the eventual removal of SCp from struct scsi_cmnd.

Cc: Michael Schmitz <schmitzmic@gmail.com>
Cc: Ondrej Zary <linux@zary.sk>
Suggested-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Finn Thain <fthain@linux-m68k.org>
---
 drivers/scsi/NCR5380.c    | 94 +++++++++++++++++++--------------------
 drivers/scsi/NCR5380.h    | 11 +++++
 drivers/scsi/atari_scsi.c |  4 +-
 drivers/scsi/g_NCR5380.c  |  4 +-
 drivers/scsi/mac_scsi.c   |  7 +--
 drivers/scsi/sun3_scsi.c  |  2 +-
 6 files changed, 66 insertions(+), 56 deletions(-)

diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index 55af3e245a92..dece7d9eb4d3 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -84,8 +84,7 @@
  * On command termination, the done function will be called as
  * appropriate.
  *
- * SCSI pointers are maintained in the SCp field of SCSI command
- * structures, being initialized after the command is connected
+ * The command data pointer is initialized after the command is connected
  * in NCR5380_select, and set as appropriate in NCR5380_information_transfer.
  * Note that in violation of the standard, an implicit SAVE POINTERS operation
  * is done, since some BROKEN disks fail to issue an explicit SAVE POINTERS.
@@ -145,40 +144,38 @@ static void bus_reset_cleanup(struct Scsi_Host *);
 
 static inline void initialize_SCp(struct scsi_cmnd *cmd)
 {
-	/*
-	 * Initialize the Scsi Pointer field so that all of the commands in the
-	 * various queues are valid.
-	 */
+	struct NCR5380_cmd *ncmd = NCR5380_to_ncmd(cmd);
 
 	if (scsi_bufflen(cmd)) {
-		cmd->SCp.buffer = scsi_sglist(cmd);
-		cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
-		cmd->SCp.this_residual = cmd->SCp.buffer->length;
+		ncmd->buffer = scsi_sglist(cmd);
+		ncmd->ptr = sg_virt(ncmd->buffer);
+		ncmd->this_residual = ncmd->buffer->length;
 	} else {
-		cmd->SCp.buffer = NULL;
-		cmd->SCp.ptr = NULL;
-		cmd->SCp.this_residual = 0;
+		ncmd->buffer = NULL;
+		ncmd->ptr = NULL;
+		ncmd->this_residual = 0;
 	}
 
-	cmd->SCp.Status = 0;
-	cmd->SCp.Message = 0;
+	ncmd->status = 0;
+	ncmd->message = 0;
 }
 
-static inline void advance_sg_buffer(struct scsi_cmnd *cmd)
+static inline void advance_sg_buffer(struct NCR5380_cmd *ncmd)
 {
-	struct scatterlist *s = cmd->SCp.buffer;
+	struct scatterlist *s = ncmd->buffer;
 
-	if (!cmd->SCp.this_residual && s && !sg_is_last(s)) {
-		cmd->SCp.buffer = sg_next(s);
-		cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
-		cmd->SCp.this_residual = cmd->SCp.buffer->length;
+	if (!ncmd->this_residual && s && !sg_is_last(s)) {
+		ncmd->buffer = sg_next(s);
+		ncmd->ptr = sg_virt(ncmd->buffer);
+		ncmd->this_residual = ncmd->buffer->length;
 	}
 }
 
 static inline void set_resid_from_SCp(struct scsi_cmnd *cmd)
 {
-	int resid = cmd->SCp.this_residual;
-	struct scatterlist *s = cmd->SCp.buffer;
+	struct NCR5380_cmd *ncmd = NCR5380_to_ncmd(cmd);
+	int resid = ncmd->this_residual;
+	struct scatterlist *s = ncmd->buffer;
 
 	if (s)
 		while (!sg_is_last(s)) {
@@ -564,7 +561,7 @@ static int NCR5380_queue_command(struct Scsi_Host *instance,
                                  struct scsi_cmnd *cmd)
 {
 	struct NCR5380_hostdata *hostdata = shost_priv(instance);
-	struct NCR5380_cmd *ncmd = scsi_cmd_priv(cmd);
+	struct NCR5380_cmd *ncmd = NCR5380_to_ncmd(cmd);
 	unsigned long flags;
 
 #if (NDEBUG & NDEBUG_NO_WRITE)
@@ -672,7 +669,7 @@ static struct scsi_cmnd *dequeue_next_cmd(struct Scsi_Host *instance)
 static void requeue_cmd(struct Scsi_Host *instance, struct scsi_cmnd *cmd)
 {
 	struct NCR5380_hostdata *hostdata = shost_priv(instance);
-	struct NCR5380_cmd *ncmd = scsi_cmd_priv(cmd);
+	struct NCR5380_cmd *ncmd = NCR5380_to_ncmd(cmd);
 
 	if (hostdata->sensing == cmd) {
 		scsi_eh_restore_cmnd(cmd, &hostdata->ses);
@@ -757,6 +754,7 @@ static void NCR5380_main(struct work_struct *work)
 static void NCR5380_dma_complete(struct Scsi_Host *instance)
 {
 	struct NCR5380_hostdata *hostdata = shost_priv(instance);
+	struct NCR5380_cmd *ncmd = NCR5380_to_ncmd(hostdata->connected);
 	int transferred;
 	unsigned char **data;
 	int *count;
@@ -764,7 +762,7 @@ static void NCR5380_dma_complete(struct Scsi_Host *instance)
 	unsigned char p;
 
 	if (hostdata->read_overruns) {
-		p = hostdata->connected->SCp.phase;
+		p = ncmd->phase;
 		if (p & SR_IO) {
 			udelay(10);
 			if ((NCR5380_read(BUS_AND_STATUS_REG) &
@@ -801,8 +799,8 @@ static void NCR5380_dma_complete(struct Scsi_Host *instance)
 	transferred = hostdata->dma_len - NCR5380_dma_residual(hostdata);
 	hostdata->dma_len = 0;
 
-	data = (unsigned char **)&hostdata->connected->SCp.ptr;
-	count = &hostdata->connected->SCp.this_residual;
+	data = (unsigned char **)&ncmd->ptr;
+	count = &ncmd->this_residual;
 	*data += transferred;
 	*count -= transferred;
 
@@ -1498,7 +1496,7 @@ static int NCR5380_transfer_dma(struct Scsi_Host *instance,
 		return -1;
 	}
 
-	hostdata->connected->SCp.phase = p;
+	NCR5380_to_ncmd(hostdata->connected)->phase = p;
 
 	if (p & SR_IO) {
 		if (hostdata->read_overruns)
@@ -1690,7 +1688,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
 #endif
 
 	while ((cmd = hostdata->connected)) {
-		struct NCR5380_cmd *ncmd = scsi_cmd_priv(cmd);
+		struct NCR5380_cmd *ncmd = NCR5380_to_ncmd(cmd);
 
 		tmp = NCR5380_read(STATUS_REG);
 		/* We only have a valid SCSI phase when REQ is asserted */
@@ -1705,17 +1703,17 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
 			    sun3_dma_setup_done != cmd) {
 				int count;
 
-				advance_sg_buffer(cmd);
+				advance_sg_buffer(ncmd);
 
 				count = sun3scsi_dma_xfer_len(hostdata, cmd);
 
 				if (count > 0) {
 					if (cmd->sc_data_direction == DMA_TO_DEVICE)
 						sun3scsi_dma_send_setup(hostdata,
-						                        cmd->SCp.ptr, count);
+									ncmd->ptr, count);
 					else
 						sun3scsi_dma_recv_setup(hostdata,
-						                        cmd->SCp.ptr, count);
+									ncmd->ptr, count);
 					sun3_dma_setup_done = cmd;
 				}
 #ifdef SUN3_SCSI_VME
@@ -1755,11 +1753,11 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
 				 * scatter-gather list, move onto the next one.
 				 */
 
-				advance_sg_buffer(cmd);
+				advance_sg_buffer(ncmd);
 				dsprintk(NDEBUG_INFORMATION, instance,
 					"this residual %d, sg ents %d\n",
-					cmd->SCp.this_residual,
-					sg_nents(cmd->SCp.buffer));
+					ncmd->this_residual,
+					sg_nents(ncmd->buffer));
 
 				/*
 				 * The preferred transfer method is going to be
@@ -1778,7 +1776,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
 				if (transfersize > 0) {
 					len = transfersize;
 					if (NCR5380_transfer_dma(instance, &phase,
-					    &len, (unsigned char **)&cmd->SCp.ptr)) {
+					    &len, (unsigned char **)&ncmd->ptr)) {
 						/*
 						 * If the watchdog timer fires, all future
 						 * accesses to this device will use the
@@ -1794,13 +1792,13 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
 					/* Transfer a small chunk so that the
 					 * irq mode lock is not held too long.
 					 */
-					transfersize = min(cmd->SCp.this_residual,
+					transfersize = min(ncmd->this_residual,
 							   NCR5380_PIO_CHUNK_SIZE);
 					len = transfersize;
 					NCR5380_transfer_pio(instance, &phase, &len,
-					                     (unsigned char **)&cmd->SCp.ptr,
+							     (unsigned char **)&ncmd->ptr,
 							     0);
-					cmd->SCp.this_residual -= transfersize - len;
+					ncmd->this_residual -= transfersize - len;
 				}
 #ifdef CONFIG_SUN3
 				if (sun3_dma_setup_done == cmd)
@@ -1811,7 +1809,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
 				len = 1;
 				data = &tmp;
 				NCR5380_transfer_pio(instance, &phase, &len, &data, 0);
-				cmd->SCp.Message = tmp;
+				ncmd->message = tmp;
 
 				switch (tmp) {
 				case ABORT:
@@ -1828,15 +1826,15 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
 					hostdata->connected = NULL;
 					hostdata->busy[scmd_id(cmd)] &= ~(1 << cmd->device->lun);
 
-					set_status_byte(cmd, cmd->SCp.Status);
+					set_status_byte(cmd, ncmd->status);
 
 					set_resid_from_SCp(cmd);
 
 					if (cmd->cmnd[0] == REQUEST_SENSE)
 						complete_cmd(instance, cmd);
 					else {
-						if (cmd->SCp.Status == SAM_STAT_CHECK_CONDITION ||
-						    cmd->SCp.Status == SAM_STAT_COMMAND_TERMINATED) {
+						if (ncmd->status == SAM_STAT_CHECK_CONDITION ||
+						    ncmd->status == SAM_STAT_COMMAND_TERMINATED) {
 							dsprintk(NDEBUG_QUEUES, instance, "autosense: adding cmd %p to tail of autosense queue\n",
 							         cmd);
 							list_add_tail(&ncmd->list,
@@ -2000,7 +1998,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
 				len = 1;
 				data = &tmp;
 				NCR5380_transfer_pio(instance, &phase, &len, &data, 0);
-				cmd->SCp.Status = tmp;
+				ncmd->status = tmp;
 				break;
 			default:
 				shost_printk(KERN_ERR, instance, "unknown phase\n");
@@ -2153,17 +2151,17 @@ static void NCR5380_reselect(struct Scsi_Host *instance)
 	if (sun3_dma_setup_done != tmp) {
 		int count;
 
-		advance_sg_buffer(tmp);
+		advance_sg_buffer(ncmd);
 
 		count = sun3scsi_dma_xfer_len(hostdata, tmp);
 
 		if (count > 0) {
 			if (tmp->sc_data_direction == DMA_TO_DEVICE)
 				sun3scsi_dma_send_setup(hostdata,
-				                        tmp->SCp.ptr, count);
+							ncmd->ptr, count);
 			else
 				sun3scsi_dma_recv_setup(hostdata,
-				                        tmp->SCp.ptr, count);
+							ncmd->ptr, count);
 			sun3_dma_setup_done = tmp;
 		}
 	}
@@ -2206,7 +2204,7 @@ static bool list_del_cmd(struct list_head *haystack,
                          struct scsi_cmnd *needle)
 {
 	if (list_find_cmd(haystack, needle)) {
-		struct NCR5380_cmd *ncmd = scsi_cmd_priv(needle);
+		struct NCR5380_cmd *ncmd = NCR5380_to_ncmd(needle);
 
 		list_del(&ncmd->list);
 		return true;
diff --git a/drivers/scsi/NCR5380.h b/drivers/scsi/NCR5380.h
index 845bd2423e66..8dc2be4212dc 100644
--- a/drivers/scsi/NCR5380.h
+++ b/drivers/scsi/NCR5380.h
@@ -227,6 +227,12 @@ struct NCR5380_hostdata {
 };
 
 struct NCR5380_cmd {
+	char *ptr;
+	int this_residual;
+	struct scatterlist *buffer;
+	int status;
+	int message;
+	int phase;
 	struct list_head list;
 };
 
@@ -240,6 +246,11 @@ static inline struct scsi_cmnd *NCR5380_to_scmd(struct NCR5380_cmd *ncmd_ptr)
 	return ((struct scsi_cmnd *)ncmd_ptr) - 1;
 }
 
+static inline struct NCR5380_cmd *NCR5380_to_ncmd(struct scsi_cmnd *cmd)
+{
+	return scsi_cmd_priv(cmd);
+}
+
 #ifndef NDEBUG
 #define NDEBUG (0)
 #endif
diff --git a/drivers/scsi/atari_scsi.c b/drivers/scsi/atari_scsi.c
index e9d0d99abc86..d401cf27113a 100644
--- a/drivers/scsi/atari_scsi.c
+++ b/drivers/scsi/atari_scsi.c
@@ -538,7 +538,7 @@ static int falcon_classify_cmd(struct scsi_cmnd *cmd)
 static int atari_scsi_dma_xfer_len(struct NCR5380_hostdata *hostdata,
                                    struct scsi_cmnd *cmd)
 {
-	int wanted_len = cmd->SCp.this_residual;
+	int wanted_len = NCR5380_to_ncmd(cmd)->this_residual;
 	int possible_len, limit;
 
 	if (wanted_len < DMA_MIN_SIZE)
@@ -610,7 +610,7 @@ static int atari_scsi_dma_xfer_len(struct NCR5380_hostdata *hostdata,
 	}
 
 	/* Last step: apply the hard limit on DMA transfers */
-	limit = (atari_dma_buffer && !STRAM_ADDR(virt_to_phys(cmd->SCp.ptr))) ?
+	limit = (atari_dma_buffer && !STRAM_ADDR(virt_to_phys(NCR5380_to_ncmd(cmd)->ptr))) ?
 		    STRAM_BUFFER_SIZE : 255*512;
 	if (possible_len > limit)
 		possible_len = limit;
diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
index 5923f86a384e..0c768e7d06b9 100644
--- a/drivers/scsi/g_NCR5380.c
+++ b/drivers/scsi/g_NCR5380.c
@@ -663,7 +663,7 @@ static inline int generic_NCR5380_psend(struct NCR5380_hostdata *hostdata,
 static int generic_NCR5380_dma_xfer_len(struct NCR5380_hostdata *hostdata,
                                         struct scsi_cmnd *cmd)
 {
-	int transfersize = cmd->SCp.this_residual;
+	int transfersize = NCR5380_to_ncmd(cmd)->this_residual;
 
 	if (hostdata->flags & FLAG_NO_PSEUDO_DMA)
 		return 0;
@@ -675,7 +675,7 @@ static int generic_NCR5380_dma_xfer_len(struct NCR5380_hostdata *hostdata,
 	/* Limit PDMA send to 512 B to avoid random corruption on DTC3181E */
 	if (hostdata->board == BOARD_DTC3181E &&
 	    cmd->sc_data_direction == DMA_TO_DEVICE)
-		transfersize = min(cmd->SCp.this_residual, 512);
+		transfersize = min(transfersize, 512);
 
 	return min(transfersize, DMA_MAX_SIZE);
 }
diff --git a/drivers/scsi/mac_scsi.c b/drivers/scsi/mac_scsi.c
index 71d493a0bb43..2e511697fce3 100644
--- a/drivers/scsi/mac_scsi.c
+++ b/drivers/scsi/mac_scsi.c
@@ -404,11 +404,12 @@ static inline int macscsi_pwrite(struct NCR5380_hostdata *hostdata,
 static int macscsi_dma_xfer_len(struct NCR5380_hostdata *hostdata,
                                 struct scsi_cmnd *cmd)
 {
-	if (hostdata->flags & FLAG_NO_PSEUDO_DMA ||
-	    cmd->SCp.this_residual < setup_use_pdma)
+	int resid = NCR5380_to_ncmd(cmd)->this_residual;
+
+	if (hostdata->flags & FLAG_NO_PSEUDO_DMA || resid < setup_use_pdma)
 		return 0;
 
-	return cmd->SCp.this_residual;
+	return resid;
 }
 
 static int macscsi_dma_residual(struct NCR5380_hostdata *hostdata)
diff --git a/drivers/scsi/sun3_scsi.c b/drivers/scsi/sun3_scsi.c
index 82a253270c3b..abf229b847a1 100644
--- a/drivers/scsi/sun3_scsi.c
+++ b/drivers/scsi/sun3_scsi.c
@@ -334,7 +334,7 @@ static int sun3scsi_dma_residual(struct NCR5380_hostdata *hostdata)
 static int sun3scsi_dma_xfer_len(struct NCR5380_hostdata *hostdata,
                                  struct scsi_cmnd *cmd)
 {
-	int wanted_len = cmd->SCp.this_residual;
+	int wanted_len = NCR5380_to_ncmd(cmd)->this_residual;
 
 	if (wanted_len < DMA_MIN_SIZE || blk_rq_is_passthrough(scsi_cmd_to_rq(cmd)))
 		return 0;
Bart Van Assche Feb. 18, 2022, 7:43 p.m. UTC | #4
On 2/17/22 16:45, Finn Thain wrote:
> On Wed, 16 Feb 2022, Bart Van Assche wrote:
>>    scsi: NCR5380: Introduce the NCR5380_cmd_priv() function
>>    scsi: NCR5380: Move the SCSI pointer to private command data
> 
> Please replace those two patches with the one below. This one is better
> because it adds less source code, adds less scsi_cmnd private data,
> updates an overlooked comment, avoids anything like "struct scsi_pointer"
> and doesn't shadow any local variables.

Thanks Finn for having written and shared this patch. I will replace the 
two patches mentioned above as requested.

Bart.