Commit 0e9fdd2b authored by Finn Thain's avatar Finn Thain Committed by Martin K. Petersen

scsi: NCR5380: use sg helper to iterate over scatterlist

Unlike the legacy I/O path, scsi-mq preallocates a large array to hold
the scatterlist for each request. This static allocation can consume
substantial amounts of memory on modern controllers which support a
large number of concurrently outstanding requests.

To facilitate a switch to a smaller static allocation combined with a
dynamic allocation for requests that need it, we need to make sure all
SCSI drivers handle chained scatterlists correctly.

Convert remaining drivers that directly dereference the scatterlist
array to using the iterator functions.

[mkp: clarified commit message]

Cc: Michael Schmitz <schmitzmic@gmail.com>
Reviewed-by: default avatarMichael Schmitz <schmitzmic@gmail.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarBart Van Assche <bvanassche@acm.org>
Signed-off-by: default avatarFinn Thain <fthain@telegraphics.com.au>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent c3c0fd9b
...@@ -149,12 +149,10 @@ static inline void initialize_SCp(struct scsi_cmnd *cmd) ...@@ -149,12 +149,10 @@ static inline void initialize_SCp(struct scsi_cmnd *cmd)
if (scsi_bufflen(cmd)) { if (scsi_bufflen(cmd)) {
cmd->SCp.buffer = scsi_sglist(cmd); cmd->SCp.buffer = scsi_sglist(cmd);
cmd->SCp.buffers_residual = scsi_sg_count(cmd) - 1;
cmd->SCp.ptr = sg_virt(cmd->SCp.buffer); cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
cmd->SCp.this_residual = cmd->SCp.buffer->length; cmd->SCp.this_residual = cmd->SCp.buffer->length;
} else { } else {
cmd->SCp.buffer = NULL; cmd->SCp.buffer = NULL;
cmd->SCp.buffers_residual = 0;
cmd->SCp.ptr = NULL; cmd->SCp.ptr = NULL;
cmd->SCp.this_residual = 0; cmd->SCp.this_residual = 0;
} }
...@@ -163,6 +161,17 @@ static inline void initialize_SCp(struct scsi_cmnd *cmd) ...@@ -163,6 +161,17 @@ static inline void initialize_SCp(struct scsi_cmnd *cmd)
cmd->SCp.Message = 0; cmd->SCp.Message = 0;
} }
static inline void advance_sg_buffer(struct scsi_cmnd *cmd)
{
struct scatterlist *s = cmd->SCp.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;
}
}
/** /**
* NCR5380_poll_politely2 - wait for two chip register values * NCR5380_poll_politely2 - wait for two chip register values
* @hostdata: host private data * @hostdata: host private data
...@@ -1672,12 +1681,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) ...@@ -1672,12 +1681,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
sun3_dma_setup_done != cmd) { sun3_dma_setup_done != cmd) {
int count; int count;
if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) { advance_sg_buffer(cmd);
++cmd->SCp.buffer;
--cmd->SCp.buffers_residual;
cmd->SCp.this_residual = cmd->SCp.buffer->length;
cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
}
count = sun3scsi_dma_xfer_len(hostdata, cmd); count = sun3scsi_dma_xfer_len(hostdata, cmd);
...@@ -1727,15 +1731,11 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) ...@@ -1727,15 +1731,11 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
* scatter-gather list, move onto the next one. * scatter-gather list, move onto the next one.
*/ */
if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) { advance_sg_buffer(cmd);
++cmd->SCp.buffer; dsprintk(NDEBUG_INFORMATION, instance,
--cmd->SCp.buffers_residual; "this residual %d, sg ents %d\n",
cmd->SCp.this_residual = cmd->SCp.buffer->length;
cmd->SCp.ptr = sg_virt(cmd->SCp.buffer);
dsprintk(NDEBUG_INFORMATION, instance, "%d bytes and %d buffers left\n",
cmd->SCp.this_residual, cmd->SCp.this_residual,
cmd->SCp.buffers_residual); sg_nents(cmd->SCp.buffer));
}
/* /*
* The preferred transfer method is going to be * The preferred transfer method is going to be
...@@ -2136,12 +2136,7 @@ static void NCR5380_reselect(struct Scsi_Host *instance) ...@@ -2136,12 +2136,7 @@ static void NCR5380_reselect(struct Scsi_Host *instance)
if (sun3_dma_setup_done != tmp) { if (sun3_dma_setup_done != tmp) {
int count; int count;
if (!tmp->SCp.this_residual && tmp->SCp.buffers_residual) { advance_sg_buffer(tmp);
++tmp->SCp.buffer;
--tmp->SCp.buffers_residual;
tmp->SCp.this_residual = tmp->SCp.buffer->length;
tmp->SCp.ptr = sg_virt(tmp->SCp.buffer);
}
count = sun3scsi_dma_xfer_len(hostdata, tmp); count = sun3scsi_dma_xfer_len(hostdata, tmp);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment