diff mbox series

[05/44] NCR5380: Move the SCSI pointer to private command data

Message ID 20220128221909.8141-6-bvanassche@acm.org
State Superseded
Headers show
Series Remove the SCSI pointer from struct scsi_cmnd | expand

Commit Message

Bart Van Assche Jan. 28, 2022, 10:18 p.m. UTC
Move the SCSI pointer into the NCR5380 private command data instead of
using the SCSI pointer from struct scsi_cmnd. This patch prepares for
removal of the SCSI pointer from struct scsi_cmnd.

Cc: Finn Thain <fthain@telegraphics.com.au>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Ondrej Zary <linux@rainbow-software.org>
Cc: Michael Schmitz <schmitzmic@gmail.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/scsi/NCR5380.c    | 83 +++++++++++++++++++++++----------------
 drivers/scsi/NCR5380.h    |  8 ++++
 drivers/scsi/atari_scsi.c |  6 ++-
 drivers/scsi/g_NCR5380.c  |  5 ++-
 drivers/scsi/mac_scsi.c   |  6 ++-
 drivers/scsi/sun3_scsi.c  |  3 +-
 6 files changed, 70 insertions(+), 41 deletions(-)

Comments

Johannes Thumshirn Jan. 31, 2022, 10:04 a.m. UTC | #1
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Finn Thain Jan. 31, 2022, 10:39 p.m. UTC | #2
On Fri, 28 Jan 2022, Bart Van Assche wrote:

> diff --git a/drivers/scsi/NCR5380.h b/drivers/scsi/NCR5380.h
> index 845bd2423e66..adaf131aea4d 100644
> --- a/drivers/scsi/NCR5380.h
> +++ b/drivers/scsi/NCR5380.h
> @@ -227,9 +227,17 @@ struct NCR5380_hostdata {
>  };
>  
>  struct NCR5380_cmd {
> +	struct scsi_pointer scsi_pointer;
>  	struct list_head list;
>  };
>  
> +static inline struct scsi_pointer *NCR5380_scsi_pointer(struct scsi_cmnd *cmd)
> +{
> +	struct NCR5380_cmd *ncmd = scsi_cmd_priv(cmd);
> +
> +	return &ncmd->scsi_pointer;
> +}
> +
>  #define NCR5380_PIO_CHUNK_SIZE		256
>  
>  /* Time limit (ms) to poll registers when IRQs are disabled, e.g. during PDMA */

I think this patch series is a good idea but poorly executed.

Firstly, scsi_pointer has long been the name of a struct. It's confusing 
to see that name re-used for variables and functions. Moreover, it was 
always a lousy name (for anything).

Regarding code style, this is legacy code i.e. it pre-dates the ban on 
mixed letter case. (I'm using the word legacy after the dictionary 
definition and not as a kind of weasel word intended to mean deprecated.)

Mixed case names like "BAZ5000_cmd" would be frowned upon for new code but 
this is not new code. So why not just use the name SCp for variables which 
serve the same purpose that the SCp struct did?

IOW, I would prefer to read the following, because SCp presumably means 
"Scsi Command Private data" whereas "scsi_pointer" means nothing to me.

--- a/drivers/scsi/NCR5380.h
+++ b/drivers/scsi/NCR5380.h
@@ -227,9 +227,17 @@ struct NCR5380_hostdata {
 };
   
 struct NCR5380_cmd {
+     struct scsi_pointer SCp;
      struct list_head list;
 };
   
+static inline struct scsi_pointer *NCR5380_to_SCp(struct scsi_cmnd *cmd)
+{
+     struct NCR5380_cmd *ncmd = scsi_cmd_priv(cmd);
+     
+     return &ncmd->SCp;
+}
+ 
 #define NCR5380_PIO_CHUNK_SIZE               256
 
 /* Time limit (ms) to poll registers when IRQs are disabled, e.g. during PDMA */
diff --git a/drivers/scsi/atari_scsi.c b/drivers/scsi/atari_scsi.c
index e9d0d99abc86..61fd3244a4ce 100644
--- a/drivers/scsi/atari_scsi.c
+++ b/drivers/scsi/atari_scsi.c
@@ -538,7 +538,8 @@ 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;
+       struct scsi_pointer *SCp = NCR5380_to_SCp(cmd);
+       int wanted_len = SCp->this_residual;
        int possible_len, limit;
 
        if (wanted_len < DMA_MIN_SIZE)
@@ -610,7 +611,8 @@ 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(SCp->ptr))) ?
                    STRAM_BUFFER_SIZE : 255*512;
        if (possible_len > limit)
                possible_len = limit;
Bart Van Assche Jan. 31, 2022, 11:36 p.m. UTC | #3
On 1/31/22 14:39, Finn Thain wrote:
> Regarding code style, this is legacy code i.e. it pre-dates the ban on
> mixed letter case. (I'm using the word legacy after the dictionary
> definition and not as a kind of weasel word intended to mean deprecated.)
> 
> Mixed case names like "BAZ5000_cmd" would be frowned upon for new code but
> this is not new code. So why not just use the name SCp for variables which
> serve the same purpose that the SCp struct did?
> 
> IOW, I would prefer to read the following, because SCp presumably means
> "Scsi Command Private data" whereas "scsi_pointer" means nothing to me.

Changing the struct member name "scsi_pointer" back into "SCp" in this 
driver is fine with me. In case this wouldn't be clear: I think the name 
"SCSI pointer" refers to a section in the SCSI-II standard. From the 
SCSI-II standard: "6.4 SCSI pointers
Consider the system shown in figure 17 in which an initiator and target 
communicate on the SCSI bus in order to execute an I/O process. The SCSI 
architecture provides for a set of three pointers for each I/O process, 
called the saved pointers. The set of three pointers consist of one for 
the command, one for the data, and one for the status. When an I/O 
process becomes active, its three saved pointers are copied into the 
initiator’s set of three current pointers. There is only one set of 
current pointers in each initiator. The current pointers point to the 
next command, data, or status byte to be transferred between the 
initiator’s memory and the target. The saved and current pointers reside 
in the initiator. The saved command pointer always points to the start 
of the command descriptor block (see 7.2) for the I/O process. The saved 
status pointer always points to the start of the status area for the I/O 
process. The saved data pointer points to the start of the data area 
until the target sends a SAVE DATA POINTER message (see 6.6.20) for the 
I/O process."

I think the above quote shows that the contents of struct scsi_pointer 
has been derived directly from the SCSI-II specification.

Thanks,

Bart.
Finn Thain Feb. 1, 2022, 12:11 a.m. UTC | #4
On Mon, 31 Jan 2022, Bart Van Assche wrote:

> On 1/31/22 14:39, Finn Thain wrote:
> > Regarding code style, this is legacy code i.e. it pre-dates the ban on
> > mixed letter case. (I'm using the word legacy after the dictionary
> > definition and not as a kind of weasel word intended to mean deprecated.)
> > 
> > Mixed case names like "BAZ5000_cmd" would be frowned upon for new code but
> > this is not new code. So why not just use the name SCp for variables which
> > serve the same purpose that the SCp struct did?
> > 
> > IOW, I would prefer to read the following, because SCp presumably means
> > "Scsi Command Private data" whereas "scsi_pointer" means nothing to me.
> 
> Changing the struct member name "scsi_pointer" back into "SCp" in this driver
> is fine with me. In case this wouldn't be clear: I think the name "SCSI
> pointer" refers to a section in the SCSI-II standard. From the SCSI-II
> standard: "6.4 SCSI pointers
> Consider the system shown in figure 17 in which an initiator and target
> communicate on the SCSI bus in order to execute an I/O process. The SCSI
> architecture provides for a set of three pointers for each I/O process, called
> the saved pointers. The set of three pointers consist of one for the command,
> one for the data, and one for the status. When an I/O process becomes active,
> its three saved pointers are copied into the initiator’s set of three current
> pointers. There is only one set of current pointers in each initiator. The
> current pointers point to the next command, data, or status byte to be
> transferred between the initiator’s memory and the target. The saved and
> current pointers reside in the initiator. The saved command pointer always
> points to the start of the command descriptor block (see 7.2) for the I/O
> process. The saved status pointer always points to the start of the status
> area for the I/O process. The saved data pointer points to the start of the
> data area until the target sends a SAVE DATA POINTER message (see 6.6.20) for
> the I/O process."
> 
> I think the above quote shows that the contents of struct scsi_pointer has
> been derived directly from the SCSI-II specification.
> 

But only acornscsi.c and fas216.c actually use the SCp.ptr field in the 
way that you describe.

While I agree that struct scsi_pointer was probably somehow intended to 
mean "saved data pointer", that just proves my point as to the poor choice 
of name.

Anyway, I'm not interested in bikeshedding variable names. I'll let the 
maintainer make the call rather than attempt to veto these patches.
diff mbox series

Patch

diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index 55af3e245a92..73c1b2ec6214 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -145,40 +145,44 @@  static void bus_reset_cleanup(struct Scsi_Host *);
 
 static inline void initialize_SCp(struct scsi_cmnd *cmd)
 {
+	struct scsi_pointer *scsi_pointer = NCR5380_scsi_pointer(cmd);
+
 	/*
 	 * Initialize the Scsi Pointer field so that all of the commands in the
 	 * various queues are valid.
 	 */
 
 	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;
+		scsi_pointer->buffer = scsi_sglist(cmd);
+		scsi_pointer->ptr = sg_virt(scsi_pointer->buffer);
+		scsi_pointer->this_residual = scsi_pointer->buffer->length;
 	} else {
-		cmd->SCp.buffer = NULL;
-		cmd->SCp.ptr = NULL;
-		cmd->SCp.this_residual = 0;
+		scsi_pointer->buffer = NULL;
+		scsi_pointer->ptr = NULL;
+		scsi_pointer->this_residual = 0;
 	}
 
-	cmd->SCp.Status = 0;
-	cmd->SCp.Message = 0;
+	scsi_pointer->Status = 0;
+	scsi_pointer->Message = 0;
 }
 
 static inline void advance_sg_buffer(struct scsi_cmnd *cmd)
 {
-	struct scatterlist *s = cmd->SCp.buffer;
+	struct scsi_pointer *scsi_pointer = NCR5380_scsi_pointer(cmd);
+	struct scatterlist *s = scsi_pointer->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 (!scsi_pointer->this_residual && s && !sg_is_last(s)) {
+		scsi_pointer->buffer = sg_next(s);
+		scsi_pointer->ptr = sg_virt(scsi_pointer->buffer);
+		scsi_pointer->this_residual = scsi_pointer->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 scsi_pointer *scsi_pointer = NCR5380_scsi_pointer(cmd);
+	int resid = scsi_pointer->this_residual;
+	struct scatterlist *s = scsi_pointer->buffer;
 
 	if (s)
 		while (!sg_is_last(s)) {
@@ -757,6 +761,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 scsi_pointer *scsi_pointer;
 	int transferred;
 	unsigned char **data;
 	int *count;
@@ -764,7 +769,10 @@  static void NCR5380_dma_complete(struct Scsi_Host *instance)
 	unsigned char p;
 
 	if (hostdata->read_overruns) {
-		p = hostdata->connected->SCp.phase;
+		struct scsi_pointer *scsi_pointer =
+			NCR5380_scsi_pointer(hostdata->connected);
+
+		p = scsi_pointer->phase;
 		if (p & SR_IO) {
 			udelay(10);
 			if ((NCR5380_read(BUS_AND_STATUS_REG) &
@@ -801,8 +809,9 @@  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;
+	scsi_pointer = NCR5380_scsi_pointer(hostdata->connected);
+	data = (unsigned char **)&scsi_pointer->ptr;
+	count = &scsi_pointer->this_residual;
 	*data += transferred;
 	*count -= transferred;
 
@@ -1487,6 +1496,8 @@  static int NCR5380_transfer_dma(struct Scsi_Host *instance,
 				unsigned char **data)
 {
 	struct NCR5380_hostdata *hostdata = shost_priv(instance);
+	struct scsi_pointer *scsi_pointer =
+		NCR5380_scsi_pointer(hostdata->connected);
 	int c = *count;
 	unsigned char p = *phase;
 	unsigned char *d = *data;
@@ -1498,7 +1509,7 @@  static int NCR5380_transfer_dma(struct Scsi_Host *instance,
 		return -1;
 	}
 
-	hostdata->connected->SCp.phase = p;
+	scsi_pointer->phase = p;
 
 	if (p & SR_IO) {
 		if (hostdata->read_overruns)
@@ -1691,6 +1702,7 @@  static void NCR5380_information_transfer(struct Scsi_Host *instance)
 
 	while ((cmd = hostdata->connected)) {
 		struct NCR5380_cmd *ncmd = scsi_cmd_priv(cmd);
+		struct scsi_pointer *scsi_pointer = &ncmd->scsi_pointer;
 
 		tmp = NCR5380_read(STATUS_REG);
 		/* We only have a valid SCSI phase when REQ is asserted */
@@ -1712,10 +1724,10 @@  static void NCR5380_information_transfer(struct Scsi_Host *instance)
 				if (count > 0) {
 					if (cmd->sc_data_direction == DMA_TO_DEVICE)
 						sun3scsi_dma_send_setup(hostdata,
-						                        cmd->SCp.ptr, count);
+						                        scsi_pointer->ptr, count);
 					else
 						sun3scsi_dma_recv_setup(hostdata,
-						                        cmd->SCp.ptr, count);
+						                        scsi_pointer->ptr, count);
 					sun3_dma_setup_done = cmd;
 				}
 #ifdef SUN3_SCSI_VME
@@ -1758,8 +1770,8 @@  static void NCR5380_information_transfer(struct Scsi_Host *instance)
 				advance_sg_buffer(cmd);
 				dsprintk(NDEBUG_INFORMATION, instance,
 					"this residual %d, sg ents %d\n",
-					cmd->SCp.this_residual,
-					sg_nents(cmd->SCp.buffer));
+					scsi_pointer->this_residual,
+					sg_nents(scsi_pointer->buffer));
 
 				/*
 				 * The preferred transfer method is going to be
@@ -1778,7 +1790,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 **)&scsi_pointer->ptr)) {
 						/*
 						 * If the watchdog timer fires, all future
 						 * accesses to this device will use the
@@ -1794,13 +1806,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(scsi_pointer->this_residual,
 							   NCR5380_PIO_CHUNK_SIZE);
 					len = transfersize;
 					NCR5380_transfer_pio(instance, &phase, &len,
-					                     (unsigned char **)&cmd->SCp.ptr,
+					                     (unsigned char **)&scsi_pointer->ptr,
 							     0);
-					cmd->SCp.this_residual -= transfersize - len;
+					scsi_pointer->this_residual -= transfersize - len;
 				}
 #ifdef CONFIG_SUN3
 				if (sun3_dma_setup_done == cmd)
@@ -1811,7 +1823,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;
+				scsi_pointer->Message = tmp;
 
 				switch (tmp) {
 				case ABORT:
@@ -1828,15 +1840,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, scsi_pointer->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 (scsi_pointer->Status == SAM_STAT_CHECK_CONDITION ||
+						    scsi_pointer->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 +2012,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;
+				scsi_pointer->Status = tmp;
 				break;
 			default:
 				shost_printk(KERN_ERR, instance, "unknown phase\n");
@@ -2151,6 +2163,7 @@  static void NCR5380_reselect(struct Scsi_Host *instance)
 
 #ifdef CONFIG_SUN3
 	if (sun3_dma_setup_done != tmp) {
+		struct scsi_pointer *scsi_pointer = NCR5380_scsi_pointer(tmp);
 		int count;
 
 		advance_sg_buffer(tmp);
@@ -2160,10 +2173,12 @@  static void NCR5380_reselect(struct Scsi_Host *instance)
 		if (count > 0) {
 			if (tmp->sc_data_direction == DMA_TO_DEVICE)
 				sun3scsi_dma_send_setup(hostdata,
-				                        tmp->SCp.ptr, count);
+				                        scsi_pointer->ptr,
+							count);
 			else
 				sun3scsi_dma_recv_setup(hostdata,
-				                        tmp->SCp.ptr, count);
+				                        scsi_pointer->ptr,
+							count);
 			sun3_dma_setup_done = tmp;
 		}
 	}
diff --git a/drivers/scsi/NCR5380.h b/drivers/scsi/NCR5380.h
index 845bd2423e66..adaf131aea4d 100644
--- a/drivers/scsi/NCR5380.h
+++ b/drivers/scsi/NCR5380.h
@@ -227,9 +227,17 @@  struct NCR5380_hostdata {
 };
 
 struct NCR5380_cmd {
+	struct scsi_pointer scsi_pointer;
 	struct list_head list;
 };
 
+static inline struct scsi_pointer *NCR5380_scsi_pointer(struct scsi_cmnd *cmd)
+{
+	struct NCR5380_cmd *ncmd = scsi_cmd_priv(cmd);
+
+	return &ncmd->scsi_pointer;
+}
+
 #define NCR5380_PIO_CHUNK_SIZE		256
 
 /* Time limit (ms) to poll registers when IRQs are disabled, e.g. during PDMA */
diff --git a/drivers/scsi/atari_scsi.c b/drivers/scsi/atari_scsi.c
index e9d0d99abc86..61fd3244a4ce 100644
--- a/drivers/scsi/atari_scsi.c
+++ b/drivers/scsi/atari_scsi.c
@@ -538,7 +538,8 @@  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;
+	struct scsi_pointer *scsi_pointer = NCR5380_scsi_pointer(cmd);
+	int wanted_len = scsi_pointer->this_residual;
 	int possible_len, limit;
 
 	if (wanted_len < DMA_MIN_SIZE)
@@ -610,7 +611,8 @@  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(scsi_pointer->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..fb39a656fd15 100644
--- a/drivers/scsi/g_NCR5380.c
+++ b/drivers/scsi/g_NCR5380.c
@@ -663,7 +663,8 @@  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;
+	struct scsi_pointer *scsi_pointer = NCR5380_scsi_pointer(cmd);
+	int transfersize = scsi_pointer->this_residual;
 
 	if (hostdata->flags & FLAG_NO_PSEUDO_DMA)
 		return 0;
@@ -675,7 +676,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(scsi_pointer->this_residual, 512);
 
 	return min(transfersize, DMA_MAX_SIZE);
 }
diff --git a/drivers/scsi/mac_scsi.c b/drivers/scsi/mac_scsi.c
index 71d493a0bb43..f31da6106b72 100644
--- a/drivers/scsi/mac_scsi.c
+++ b/drivers/scsi/mac_scsi.c
@@ -404,11 +404,13 @@  static inline int macscsi_pwrite(struct NCR5380_hostdata *hostdata,
 static int macscsi_dma_xfer_len(struct NCR5380_hostdata *hostdata,
                                 struct scsi_cmnd *cmd)
 {
+	struct scsi_pointer *scsi_pointer = NCR5380_scsi_pointer(cmd);
+
 	if (hostdata->flags & FLAG_NO_PSEUDO_DMA ||
-	    cmd->SCp.this_residual < setup_use_pdma)
+	    scsi_pointer->this_residual < setup_use_pdma)
 		return 0;
 
-	return cmd->SCp.this_residual;
+	return scsi_pointer->this_residual;
 }
 
 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..50cbffbf2dd1 100644
--- a/drivers/scsi/sun3_scsi.c
+++ b/drivers/scsi/sun3_scsi.c
@@ -334,7 +334,8 @@  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;
+	struct scsi_pointer *scsi_pointer = NCR5380_scsi_pointer(cmd);
+	int wanted_len = scsi_pointer->this_residual;
 
 	if (wanted_len < DMA_MIN_SIZE || blk_rq_is_passthrough(scsi_cmd_to_rq(cmd)))
 		return 0;