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

scsi: NCR5380: Add SCp members to struct NCR5380_cmd

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

Link: https://lore.kernel.org/r/20220218195117.25689-9-bvanassche@acm.org
Cc: Michael Schmitz <schmitzmic@gmail.com>
Cc: Ondrej Zary <linux@zary.sk>
Suggested-by: default avatarBart Van Assche <bvanassche@acm.org>
Signed-off-by: default avatarFinn Thain <fthain@linux-m68k.org>
Signed-off-by: default avatarBart Van Assche <bvanassche@acm.org>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent cd614642
...@@ -84,8 +84,7 @@ ...@@ -84,8 +84,7 @@
* On command termination, the done function will be called as * On command termination, the done function will be called as
* appropriate. * appropriate.
* *
* SCSI pointers are maintained in the SCp field of SCSI command * The command data pointer is initialized after the command is connected
* structures, being initialized after the command is connected
* in NCR5380_select, and set as appropriate in NCR5380_information_transfer. * in NCR5380_select, and set as appropriate in NCR5380_information_transfer.
* Note that in violation of the standard, an implicit SAVE POINTERS operation * 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. * 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 *); ...@@ -145,40 +144,38 @@ static void bus_reset_cleanup(struct Scsi_Host *);
static inline void initialize_SCp(struct scsi_cmnd *cmd) static inline void initialize_SCp(struct scsi_cmnd *cmd)
{ {
/* struct NCR5380_cmd *ncmd = NCR5380_to_ncmd(cmd);
* Initialize the Scsi Pointer field so that all of the commands in the
* various queues are valid.
*/
if (scsi_bufflen(cmd)) { if (scsi_bufflen(cmd)) {
cmd->SCp.buffer = scsi_sglist(cmd); ncmd->buffer = scsi_sglist(cmd);
cmd->SCp.ptr = sg_virt(cmd->SCp.buffer); ncmd->ptr = sg_virt(ncmd->buffer);
cmd->SCp.this_residual = cmd->SCp.buffer->length; ncmd->this_residual = ncmd->buffer->length;
} else { } else {
cmd->SCp.buffer = NULL; ncmd->buffer = NULL;
cmd->SCp.ptr = NULL; ncmd->ptr = NULL;
cmd->SCp.this_residual = 0; ncmd->this_residual = 0;
} }
cmd->SCp.Status = 0; ncmd->status = 0;
cmd->SCp.Message = 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)) { if (!ncmd->this_residual && s && !sg_is_last(s)) {
cmd->SCp.buffer = sg_next(s); ncmd->buffer = sg_next(s);
cmd->SCp.ptr = sg_virt(cmd->SCp.buffer); ncmd->ptr = sg_virt(ncmd->buffer);
cmd->SCp.this_residual = cmd->SCp.buffer->length; ncmd->this_residual = ncmd->buffer->length;
} }
} }
static inline void set_resid_from_SCp(struct scsi_cmnd *cmd) static inline void set_resid_from_SCp(struct scsi_cmnd *cmd)
{ {
int resid = cmd->SCp.this_residual; struct NCR5380_cmd *ncmd = NCR5380_to_ncmd(cmd);
struct scatterlist *s = cmd->SCp.buffer; int resid = ncmd->this_residual;
struct scatterlist *s = ncmd->buffer;
if (s) if (s)
while (!sg_is_last(s)) { while (!sg_is_last(s)) {
...@@ -564,7 +561,7 @@ static int NCR5380_queue_command(struct Scsi_Host *instance, ...@@ -564,7 +561,7 @@ static int NCR5380_queue_command(struct Scsi_Host *instance,
struct scsi_cmnd *cmd) struct scsi_cmnd *cmd)
{ {
struct NCR5380_hostdata *hostdata = shost_priv(instance); 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; unsigned long flags;
#if (NDEBUG & NDEBUG_NO_WRITE) #if (NDEBUG & NDEBUG_NO_WRITE)
...@@ -672,7 +669,7 @@ static struct scsi_cmnd *dequeue_next_cmd(struct Scsi_Host *instance) ...@@ -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) static void requeue_cmd(struct Scsi_Host *instance, struct scsi_cmnd *cmd)
{ {
struct NCR5380_hostdata *hostdata = shost_priv(instance); 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) { if (hostdata->sensing == cmd) {
scsi_eh_restore_cmnd(cmd, &hostdata->ses); scsi_eh_restore_cmnd(cmd, &hostdata->ses);
...@@ -757,6 +754,7 @@ static void NCR5380_main(struct work_struct *work) ...@@ -757,6 +754,7 @@ static void NCR5380_main(struct work_struct *work)
static void NCR5380_dma_complete(struct Scsi_Host *instance) static void NCR5380_dma_complete(struct Scsi_Host *instance)
{ {
struct NCR5380_hostdata *hostdata = shost_priv(instance); struct NCR5380_hostdata *hostdata = shost_priv(instance);
struct NCR5380_cmd *ncmd = NCR5380_to_ncmd(hostdata->connected);
int transferred; int transferred;
unsigned char **data; unsigned char **data;
int *count; int *count;
...@@ -764,7 +762,7 @@ static void NCR5380_dma_complete(struct Scsi_Host *instance) ...@@ -764,7 +762,7 @@ static void NCR5380_dma_complete(struct Scsi_Host *instance)
unsigned char p; unsigned char p;
if (hostdata->read_overruns) { if (hostdata->read_overruns) {
p = hostdata->connected->SCp.phase; p = ncmd->phase;
if (p & SR_IO) { if (p & SR_IO) {
udelay(10); udelay(10);
if ((NCR5380_read(BUS_AND_STATUS_REG) & if ((NCR5380_read(BUS_AND_STATUS_REG) &
...@@ -801,8 +799,8 @@ static void NCR5380_dma_complete(struct Scsi_Host *instance) ...@@ -801,8 +799,8 @@ static void NCR5380_dma_complete(struct Scsi_Host *instance)
transferred = hostdata->dma_len - NCR5380_dma_residual(hostdata); transferred = hostdata->dma_len - NCR5380_dma_residual(hostdata);
hostdata->dma_len = 0; hostdata->dma_len = 0;
data = (unsigned char **)&hostdata->connected->SCp.ptr; data = (unsigned char **)&ncmd->ptr;
count = &hostdata->connected->SCp.this_residual; count = &ncmd->this_residual;
*data += transferred; *data += transferred;
*count -= transferred; *count -= transferred;
...@@ -1498,7 +1496,7 @@ static int NCR5380_transfer_dma(struct Scsi_Host *instance, ...@@ -1498,7 +1496,7 @@ static int NCR5380_transfer_dma(struct Scsi_Host *instance,
return -1; return -1;
} }
hostdata->connected->SCp.phase = p; NCR5380_to_ncmd(hostdata->connected)->phase = p;
if (p & SR_IO) { if (p & SR_IO) {
if (hostdata->read_overruns) if (hostdata->read_overruns)
...@@ -1690,7 +1688,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) ...@@ -1690,7 +1688,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
#endif #endif
while ((cmd = hostdata->connected)) { 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); tmp = NCR5380_read(STATUS_REG);
/* We only have a valid SCSI phase when REQ is asserted */ /* We only have a valid SCSI phase when REQ is asserted */
...@@ -1705,17 +1703,17 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) ...@@ -1705,17 +1703,17 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
sun3_dma_setup_done != cmd) { sun3_dma_setup_done != cmd) {
int count; int count;
advance_sg_buffer(cmd); advance_sg_buffer(ncmd);
count = sun3scsi_dma_xfer_len(hostdata, cmd); count = sun3scsi_dma_xfer_len(hostdata, cmd);
if (count > 0) { if (count > 0) {
if (cmd->sc_data_direction == DMA_TO_DEVICE) if (cmd->sc_data_direction == DMA_TO_DEVICE)
sun3scsi_dma_send_setup(hostdata, sun3scsi_dma_send_setup(hostdata,
cmd->SCp.ptr, count); ncmd->ptr, count);
else else
sun3scsi_dma_recv_setup(hostdata, sun3scsi_dma_recv_setup(hostdata,
cmd->SCp.ptr, count); ncmd->ptr, count);
sun3_dma_setup_done = cmd; sun3_dma_setup_done = cmd;
} }
#ifdef SUN3_SCSI_VME #ifdef SUN3_SCSI_VME
...@@ -1755,11 +1753,11 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) ...@@ -1755,11 +1753,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.
*/ */
advance_sg_buffer(cmd); advance_sg_buffer(ncmd);
dsprintk(NDEBUG_INFORMATION, instance, dsprintk(NDEBUG_INFORMATION, instance,
"this residual %d, sg ents %d\n", "this residual %d, sg ents %d\n",
cmd->SCp.this_residual, ncmd->this_residual,
sg_nents(cmd->SCp.buffer)); sg_nents(ncmd->buffer));
/* /*
* The preferred transfer method is going to be * The preferred transfer method is going to be
...@@ -1778,7 +1776,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) ...@@ -1778,7 +1776,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
if (transfersize > 0) { if (transfersize > 0) {
len = transfersize; len = transfersize;
if (NCR5380_transfer_dma(instance, &phase, if (NCR5380_transfer_dma(instance, &phase,
&len, (unsigned char **)&cmd->SCp.ptr)) { &len, (unsigned char **)&ncmd->ptr)) {
/* /*
* If the watchdog timer fires, all future * If the watchdog timer fires, all future
* accesses to this device will use the * accesses to this device will use the
...@@ -1794,13 +1792,13 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) ...@@ -1794,13 +1792,13 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
/* Transfer a small chunk so that the /* Transfer a small chunk so that the
* irq mode lock is not held too long. * irq mode lock is not held too long.
*/ */
transfersize = min(cmd->SCp.this_residual, transfersize = min(ncmd->this_residual,
NCR5380_PIO_CHUNK_SIZE); NCR5380_PIO_CHUNK_SIZE);
len = transfersize; len = transfersize;
NCR5380_transfer_pio(instance, &phase, &len, NCR5380_transfer_pio(instance, &phase, &len,
(unsigned char **)&cmd->SCp.ptr, (unsigned char **)&ncmd->ptr,
0); 0);
cmd->SCp.this_residual -= transfersize - len; ncmd->this_residual -= transfersize - len;
} }
#ifdef CONFIG_SUN3 #ifdef CONFIG_SUN3
if (sun3_dma_setup_done == cmd) if (sun3_dma_setup_done == cmd)
...@@ -1811,7 +1809,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) ...@@ -1811,7 +1809,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
len = 1; len = 1;
data = &tmp; data = &tmp;
NCR5380_transfer_pio(instance, &phase, &len, &data, 0); NCR5380_transfer_pio(instance, &phase, &len, &data, 0);
cmd->SCp.Message = tmp; ncmd->message = tmp;
switch (tmp) { switch (tmp) {
case ABORT: case ABORT:
...@@ -1828,15 +1826,15 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) ...@@ -1828,15 +1826,15 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
hostdata->connected = NULL; hostdata->connected = NULL;
hostdata->busy[scmd_id(cmd)] &= ~(1 << cmd->device->lun); 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); set_resid_from_SCp(cmd);
if (cmd->cmnd[0] == REQUEST_SENSE) if (cmd->cmnd[0] == REQUEST_SENSE)
complete_cmd(instance, cmd); complete_cmd(instance, cmd);
else { else {
if (cmd->SCp.Status == SAM_STAT_CHECK_CONDITION || if (ncmd->status == SAM_STAT_CHECK_CONDITION ||
cmd->SCp.Status == SAM_STAT_COMMAND_TERMINATED) { ncmd->status == SAM_STAT_COMMAND_TERMINATED) {
dsprintk(NDEBUG_QUEUES, instance, "autosense: adding cmd %p to tail of autosense queue\n", dsprintk(NDEBUG_QUEUES, instance, "autosense: adding cmd %p to tail of autosense queue\n",
cmd); cmd);
list_add_tail(&ncmd->list, list_add_tail(&ncmd->list,
...@@ -2000,7 +1998,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) ...@@ -2000,7 +1998,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
len = 1; len = 1;
data = &tmp; data = &tmp;
NCR5380_transfer_pio(instance, &phase, &len, &data, 0); NCR5380_transfer_pio(instance, &phase, &len, &data, 0);
cmd->SCp.Status = tmp; ncmd->status = tmp;
break; break;
default: default:
shost_printk(KERN_ERR, instance, "unknown phase\n"); shost_printk(KERN_ERR, instance, "unknown phase\n");
...@@ -2153,17 +2151,17 @@ static void NCR5380_reselect(struct Scsi_Host *instance) ...@@ -2153,17 +2151,17 @@ static void NCR5380_reselect(struct Scsi_Host *instance)
if (sun3_dma_setup_done != tmp) { if (sun3_dma_setup_done != tmp) {
int count; int count;
advance_sg_buffer(tmp); advance_sg_buffer(ncmd);
count = sun3scsi_dma_xfer_len(hostdata, tmp); count = sun3scsi_dma_xfer_len(hostdata, tmp);
if (count > 0) { if (count > 0) {
if (tmp->sc_data_direction == DMA_TO_DEVICE) if (tmp->sc_data_direction == DMA_TO_DEVICE)
sun3scsi_dma_send_setup(hostdata, sun3scsi_dma_send_setup(hostdata,
tmp->SCp.ptr, count); ncmd->ptr, count);
else else
sun3scsi_dma_recv_setup(hostdata, sun3scsi_dma_recv_setup(hostdata,
tmp->SCp.ptr, count); ncmd->ptr, count);
sun3_dma_setup_done = tmp; sun3_dma_setup_done = tmp;
} }
} }
...@@ -2206,7 +2204,7 @@ static bool list_del_cmd(struct list_head *haystack, ...@@ -2206,7 +2204,7 @@ static bool list_del_cmd(struct list_head *haystack,
struct scsi_cmnd *needle) struct scsi_cmnd *needle)
{ {
if (list_find_cmd(haystack, 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); list_del(&ncmd->list);
return true; return true;
......
...@@ -227,6 +227,12 @@ struct NCR5380_hostdata { ...@@ -227,6 +227,12 @@ struct NCR5380_hostdata {
}; };
struct NCR5380_cmd { struct NCR5380_cmd {
char *ptr;
int this_residual;
struct scatterlist *buffer;
int status;
int message;
int phase;
struct list_head list; struct list_head list;
}; };
...@@ -240,6 +246,11 @@ static inline struct scsi_cmnd *NCR5380_to_scmd(struct NCR5380_cmd *ncmd_ptr) ...@@ -240,6 +246,11 @@ static inline struct scsi_cmnd *NCR5380_to_scmd(struct NCR5380_cmd *ncmd_ptr)
return ((struct scsi_cmnd *)ncmd_ptr) - 1; 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 #ifndef NDEBUG
#define NDEBUG (0) #define NDEBUG (0)
#endif #endif
......
...@@ -538,7 +538,7 @@ static int falcon_classify_cmd(struct scsi_cmnd *cmd) ...@@ -538,7 +538,7 @@ static int falcon_classify_cmd(struct scsi_cmnd *cmd)
static int atari_scsi_dma_xfer_len(struct NCR5380_hostdata *hostdata, static int atari_scsi_dma_xfer_len(struct NCR5380_hostdata *hostdata,
struct scsi_cmnd *cmd) struct scsi_cmnd *cmd)
{ {
int wanted_len = cmd->SCp.this_residual; int wanted_len = NCR5380_to_ncmd(cmd)->this_residual;
int possible_len, limit; int possible_len, limit;
if (wanted_len < DMA_MIN_SIZE) if (wanted_len < DMA_MIN_SIZE)
...@@ -610,7 +610,7 @@ static int atari_scsi_dma_xfer_len(struct NCR5380_hostdata *hostdata, ...@@ -610,7 +610,7 @@ static int atari_scsi_dma_xfer_len(struct NCR5380_hostdata *hostdata,
} }
/* Last step: apply the hard limit on DMA transfers */ /* 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; STRAM_BUFFER_SIZE : 255*512;
if (possible_len > limit) if (possible_len > limit)
possible_len = limit; possible_len = limit;
......
...@@ -663,7 +663,7 @@ static inline int generic_NCR5380_psend(struct NCR5380_hostdata *hostdata, ...@@ -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, static int generic_NCR5380_dma_xfer_len(struct NCR5380_hostdata *hostdata,
struct scsi_cmnd *cmd) 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) if (hostdata->flags & FLAG_NO_PSEUDO_DMA)
return 0; return 0;
...@@ -675,7 +675,7 @@ static int generic_NCR5380_dma_xfer_len(struct NCR5380_hostdata *hostdata, ...@@ -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 */ /* Limit PDMA send to 512 B to avoid random corruption on DTC3181E */
if (hostdata->board == BOARD_DTC3181E && if (hostdata->board == BOARD_DTC3181E &&
cmd->sc_data_direction == DMA_TO_DEVICE) cmd->sc_data_direction == DMA_TO_DEVICE)
transfersize = min(cmd->SCp.this_residual, 512); transfersize = min(transfersize, 512);
return min(transfersize, DMA_MAX_SIZE); return min(transfersize, DMA_MAX_SIZE);
} }
......
...@@ -404,11 +404,12 @@ static inline int macscsi_pwrite(struct NCR5380_hostdata *hostdata, ...@@ -404,11 +404,12 @@ static inline int macscsi_pwrite(struct NCR5380_hostdata *hostdata,
static int macscsi_dma_xfer_len(struct NCR5380_hostdata *hostdata, static int macscsi_dma_xfer_len(struct NCR5380_hostdata *hostdata,
struct scsi_cmnd *cmd) struct scsi_cmnd *cmd)
{ {
if (hostdata->flags & FLAG_NO_PSEUDO_DMA || int resid = NCR5380_to_ncmd(cmd)->this_residual;
cmd->SCp.this_residual < setup_use_pdma)
if (hostdata->flags & FLAG_NO_PSEUDO_DMA || resid < setup_use_pdma)
return 0; return 0;
return cmd->SCp.this_residual; return resid;
} }
static int macscsi_dma_residual(struct NCR5380_hostdata *hostdata) static int macscsi_dma_residual(struct NCR5380_hostdata *hostdata)
......
...@@ -334,7 +334,7 @@ static int sun3scsi_dma_residual(struct NCR5380_hostdata *hostdata) ...@@ -334,7 +334,7 @@ static int sun3scsi_dma_residual(struct NCR5380_hostdata *hostdata)
static int sun3scsi_dma_xfer_len(struct NCR5380_hostdata *hostdata, static int sun3scsi_dma_xfer_len(struct NCR5380_hostdata *hostdata,
struct scsi_cmnd *cmd) 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))) if (wanted_len < DMA_MIN_SIZE || blk_rq_is_passthrough(scsi_cmd_to_rq(cmd)))
return 0; return 0;
......
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