Skip to content

Commit

Permalink
scsi: wd33c93: Move the SCSI pointer to private command data
Browse files Browse the repository at this point in the history
Set .cmd_size in the SCSI host template instead of using the SCSI pointer
from struct scsi_cmnd. This patch prepares for removal of the SCSI pointer
from struct scsi_cmnd.

Link: https://lore.kernel.org/r/[email protected]
Reviewed-by: Himanshu Madhani <[email protected]>
Signed-off-by: Bart Van Assche <[email protected]>
Signed-off-by: Martin K. Petersen <[email protected]>
  • Loading branch information
bvanassche authored and martinkpetersen committed Feb 23, 2022
1 parent 70d1b92 commit dbb2da5
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 91 deletions.
19 changes: 11 additions & 8 deletions drivers/scsi/a2091.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@ static irqreturn_t a2091_intr(int irq, void *data)

static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
{
struct scsi_pointer *scsi_pointer = WD33C93_scsi_pointer(cmd);
struct Scsi_Host *instance = cmd->device->host;
struct a2091_hostdata *hdata = shost_priv(instance);
struct WD33C93_hostdata *wh = &hdata->wh;
struct a2091_scsiregs *regs = hdata->regs;
unsigned short cntr = CNTR_PDMD | CNTR_INTEN;
unsigned long addr = virt_to_bus(cmd->SCp.ptr);
unsigned long addr = virt_to_bus(scsi_pointer->ptr);

/* don't allow DMA if the physical address is bad */
if (addr & A2091_XFER_MASK) {
wh->dma_bounce_len = (cmd->SCp.this_residual + 511) & ~0x1ff;
wh->dma_bounce_len = (scsi_pointer->this_residual + 511) & ~0x1ff;
wh->dma_bounce_buffer = kmalloc(wh->dma_bounce_len,
GFP_KERNEL);

Expand All @@ -77,8 +78,8 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in)

if (!dir_in) {
/* copy to bounce buffer for a write */
memcpy(wh->dma_bounce_buffer, cmd->SCp.ptr,
cmd->SCp.this_residual);
memcpy(wh->dma_bounce_buffer, scsi_pointer->ptr,
scsi_pointer->this_residual);
}
}

Expand All @@ -96,10 +97,10 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in)

if (dir_in) {
/* invalidate any cache */
cache_clear(addr, cmd->SCp.this_residual);
cache_clear(addr, scsi_pointer->this_residual);
} else {
/* push any dirty cache */
cache_push(addr, cmd->SCp.this_residual);
cache_push(addr, scsi_pointer->this_residual);
}
/* start DMA */
regs->ST_DMA = 1;
Expand All @@ -111,6 +112,7 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
int status)
{
struct scsi_pointer *scsi_pointer = WD33C93_scsi_pointer(SCpnt);
struct a2091_hostdata *hdata = shost_priv(instance);
struct WD33C93_hostdata *wh = &hdata->wh;
struct a2091_scsiregs *regs = hdata->regs;
Expand Down Expand Up @@ -143,8 +145,8 @@ static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
/* copy from a bounce buffer, if necessary */
if (status && wh->dma_bounce_buffer) {
if (wh->dma_dir)
memcpy(SCpnt->SCp.ptr, wh->dma_bounce_buffer,
SCpnt->SCp.this_residual);
memcpy(scsi_pointer->ptr, wh->dma_bounce_buffer,
scsi_pointer->this_residual);
kfree(wh->dma_bounce_buffer);
wh->dma_bounce_buffer = NULL;
wh->dma_bounce_len = 0;
Expand All @@ -165,6 +167,7 @@ static struct scsi_host_template a2091_scsi_template = {
.sg_tablesize = SG_ALL,
.cmd_per_lun = CMD_PER_LUN,
.dma_boundary = PAGE_SIZE - 1,
.cmd_size = sizeof(struct scsi_pointer),
};

static int a2091_probe(struct zorro_dev *z, const struct zorro_device_id *ent)
Expand Down
19 changes: 11 additions & 8 deletions drivers/scsi/a3000.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ static irqreturn_t a3000_intr(int irq, void *data)

static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
{
struct scsi_pointer *scsi_pointer = WD33C93_scsi_pointer(cmd);
struct Scsi_Host *instance = cmd->device->host;
struct a3000_hostdata *hdata = shost_priv(instance);
struct WD33C93_hostdata *wh = &hdata->wh;
struct a3000_scsiregs *regs = hdata->regs;
unsigned short cntr = CNTR_PDMD | CNTR_INTEN;
unsigned long addr = virt_to_bus(cmd->SCp.ptr);
unsigned long addr = virt_to_bus(scsi_pointer->ptr);

/*
* if the physical address has the wrong alignment, or if
Expand All @@ -62,7 +63,7 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
* buffer
*/
if (addr & A3000_XFER_MASK) {
wh->dma_bounce_len = (cmd->SCp.this_residual + 511) & ~0x1ff;
wh->dma_bounce_len = (scsi_pointer->this_residual + 511) & ~0x1ff;
wh->dma_bounce_buffer = kmalloc(wh->dma_bounce_len,
GFP_KERNEL);

Expand All @@ -74,8 +75,8 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in)

if (!dir_in) {
/* copy to bounce buffer for a write */
memcpy(wh->dma_bounce_buffer, cmd->SCp.ptr,
cmd->SCp.this_residual);
memcpy(wh->dma_bounce_buffer, scsi_pointer->ptr,
scsi_pointer->this_residual);
}

addr = virt_to_bus(wh->dma_bounce_buffer);
Expand All @@ -95,10 +96,10 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in)

if (dir_in) {
/* invalidate any cache */
cache_clear(addr, cmd->SCp.this_residual);
cache_clear(addr, scsi_pointer->this_residual);
} else {
/* push any dirty cache */
cache_push(addr, cmd->SCp.this_residual);
cache_push(addr, scsi_pointer->this_residual);
}

/* start DMA */
Expand All @@ -113,6 +114,7 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
int status)
{
struct scsi_pointer *scsi_pointer = WD33C93_scsi_pointer(SCpnt);
struct a3000_hostdata *hdata = shost_priv(instance);
struct WD33C93_hostdata *wh = &hdata->wh;
struct a3000_scsiregs *regs = hdata->regs;
Expand Down Expand Up @@ -153,8 +155,8 @@ static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
if (status && wh->dma_bounce_buffer) {
if (SCpnt) {
if (wh->dma_dir && SCpnt)
memcpy(SCpnt->SCp.ptr, wh->dma_bounce_buffer,
SCpnt->SCp.this_residual);
memcpy(scsi_pointer->ptr, wh->dma_bounce_buffer,
scsi_pointer->this_residual);
kfree(wh->dma_bounce_buffer);
wh->dma_bounce_buffer = NULL;
wh->dma_bounce_len = 0;
Expand All @@ -179,6 +181,7 @@ static struct scsi_host_template amiga_a3000_scsi_template = {
.this_id = 7,
.sg_tablesize = SG_ALL,
.cmd_per_lun = CMD_PER_LUN,
.cmd_size = sizeof(struct scsi_pointer),
};

static int __init amiga_a3000_scsi_probe(struct platform_device *pdev)
Expand Down
19 changes: 11 additions & 8 deletions drivers/scsi/gvp11.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,19 @@ void gvp11_setup(char *str, int *ints)

static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
{
struct scsi_pointer *scsi_pointer = WD33C93_scsi_pointer(cmd);
struct Scsi_Host *instance = cmd->device->host;
struct gvp11_hostdata *hdata = shost_priv(instance);
struct WD33C93_hostdata *wh = &hdata->wh;
struct gvp11_scsiregs *regs = hdata->regs;
unsigned short cntr = GVP11_DMAC_INT_ENABLE;
unsigned long addr = virt_to_bus(cmd->SCp.ptr);
unsigned long addr = virt_to_bus(scsi_pointer->ptr);
int bank_mask;
static int scsi_alloc_out_of_range = 0;

/* use bounce buffer if the physical address is bad */
if (addr & wh->dma_xfer_mask) {
wh->dma_bounce_len = (cmd->SCp.this_residual + 511) & ~0x1ff;
wh->dma_bounce_len = (scsi_pointer->this_residual + 511) & ~0x1ff;

if (!scsi_alloc_out_of_range) {
wh->dma_bounce_buffer =
Expand Down Expand Up @@ -113,8 +114,8 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in)

if (!dir_in) {
/* copy to bounce buffer for a write */
memcpy(wh->dma_bounce_buffer, cmd->SCp.ptr,
cmd->SCp.this_residual);
memcpy(wh->dma_bounce_buffer, scsi_pointer->ptr,
scsi_pointer->this_residual);
}
}

Expand All @@ -130,10 +131,10 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in)

if (dir_in) {
/* invalidate any cache */
cache_clear(addr, cmd->SCp.this_residual);
cache_clear(addr, scsi_pointer->this_residual);
} else {
/* push any dirty cache */
cache_push(addr, cmd->SCp.this_residual);
cache_push(addr, scsi_pointer->this_residual);
}

bank_mask = (~wh->dma_xfer_mask >> 18) & 0x01c0;
Expand All @@ -150,6 +151,7 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
int status)
{
struct scsi_pointer *scsi_pointer = WD33C93_scsi_pointer(SCpnt);
struct gvp11_hostdata *hdata = shost_priv(instance);
struct WD33C93_hostdata *wh = &hdata->wh;
struct gvp11_scsiregs *regs = hdata->regs;
Expand All @@ -162,8 +164,8 @@ static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
/* copy from a bounce buffer, if necessary */
if (status && wh->dma_bounce_buffer) {
if (wh->dma_dir && SCpnt)
memcpy(SCpnt->SCp.ptr, wh->dma_bounce_buffer,
SCpnt->SCp.this_residual);
memcpy(scsi_pointer->ptr, wh->dma_bounce_buffer,
scsi_pointer->this_residual);

if (wh->dma_buffer_pool == BUF_SCSI_ALLOCED)
kfree(wh->dma_bounce_buffer);
Expand All @@ -189,6 +191,7 @@ static struct scsi_host_template gvp11_scsi_template = {
.sg_tablesize = SG_ALL,
.cmd_per_lun = CMD_PER_LUN,
.dma_boundary = PAGE_SIZE - 1,
.cmd_size = sizeof(struct scsi_pointer),
};

static int check_wd33c93(struct gvp11_scsiregs *regs)
Expand Down
10 changes: 6 additions & 4 deletions drivers/scsi/mvme147.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ static irqreturn_t mvme147_intr(int irq, void *data)

static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
{
struct scsi_pointer *scsi_pointer = WD33C93_scsi_pointer(cmd);
struct Scsi_Host *instance = cmd->device->host;
struct WD33C93_hostdata *hdata = shost_priv(instance);
unsigned char flags = 0x01;
unsigned long addr = virt_to_bus(cmd->SCp.ptr);
unsigned long addr = virt_to_bus(scsi_pointer->ptr);

/* setup dma direction */
if (!dir_in)
Expand All @@ -47,14 +48,14 @@ static int dma_setup(struct scsi_cmnd *cmd, int dir_in)

if (dir_in) {
/* invalidate any cache */
cache_clear(addr, cmd->SCp.this_residual);
cache_clear(addr, scsi_pointer->this_residual);
} else {
/* push any dirty cache */
cache_push(addr, cmd->SCp.this_residual);
cache_push(addr, scsi_pointer->this_residual);
}

/* start DMA */
m147_pcc->dma_bcr = cmd->SCp.this_residual | (1 << 24);
m147_pcc->dma_bcr = scsi_pointer->this_residual | (1 << 24);
m147_pcc->dma_dadr = addr;
m147_pcc->dma_cntrl = flags;

Expand All @@ -81,6 +82,7 @@ static struct scsi_host_template mvme147_host_template = {
.this_id = 7,
.sg_tablesize = SG_ALL,
.cmd_per_lun = CMD_PER_LUN,
.cmd_size = sizeof(struct scsi_pointer),
};

static struct Scsi_Host *mvme147_shost;
Expand Down
18 changes: 11 additions & 7 deletions drivers/scsi/sgiwd93.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ static irqreturn_t sgiwd93_intr(int irq, void *dev_id)
static inline
void fill_hpc_entries(struct ip22_hostdata *hd, struct scsi_cmnd *cmd, int din)
{
unsigned long len = cmd->SCp.this_residual;
void *addr = cmd->SCp.ptr;
struct scsi_pointer *scsi_pointer = WD33C93_scsi_pointer(cmd);
unsigned long len = scsi_pointer->this_residual;
void *addr = scsi_pointer->ptr;
dma_addr_t physaddr;
unsigned long count;
struct hpc_chunk *hcp;

physaddr = dma_map_single(hd->dev, addr, len, DMA_DIR(din));
cmd->SCp.dma_handle = physaddr;
scsi_pointer->dma_handle = physaddr;
hcp = hd->cpu;

while (len) {
Expand Down Expand Up @@ -106,6 +107,7 @@ void fill_hpc_entries(struct ip22_hostdata *hd, struct scsi_cmnd *cmd, int din)

static int dma_setup(struct scsi_cmnd *cmd, int datainp)
{
struct scsi_pointer *scsi_pointer = WD33C93_scsi_pointer(cmd);
struct ip22_hostdata *hdata = host_to_hostdata(cmd->device->host);
struct hpc3_scsiregs *hregs =
(struct hpc3_scsiregs *) cmd->device->host->base;
Expand All @@ -120,7 +122,7 @@ static int dma_setup(struct scsi_cmnd *cmd, int datainp)
* obvious). IMHO a better fix would be, not to do these dma setups
* in the first place.
*/
if (cmd->SCp.ptr == NULL || cmd->SCp.this_residual == 0)
if (scsi_pointer->ptr == NULL || scsi_pointer->this_residual == 0)
return 1;

fill_hpc_entries(hdata, cmd, datainp);
Expand All @@ -140,13 +142,14 @@ static int dma_setup(struct scsi_cmnd *cmd, int datainp)
static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
int status)
{
struct scsi_pointer *scsi_pointer = WD33C93_scsi_pointer(SCpnt);
struct ip22_hostdata *hdata = host_to_hostdata(instance);
struct hpc3_scsiregs *hregs;

if (!SCpnt)
return;

if (SCpnt->SCp.ptr == NULL || SCpnt->SCp.this_residual == 0)
if (scsi_pointer->ptr == NULL || scsi_pointer->this_residual == 0)
return;

hregs = (struct hpc3_scsiregs *) SCpnt->device->host->base;
Expand All @@ -160,8 +163,8 @@ static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
barrier();
}
hregs->ctrl = 0;
dma_unmap_single(hdata->dev, SCpnt->SCp.dma_handle,
SCpnt->SCp.this_residual,
dma_unmap_single(hdata->dev, scsi_pointer->dma_handle,
scsi_pointer->this_residual,
DMA_DIR(hdata->wh.dma_dir));

pr_debug("\n");
Expand Down Expand Up @@ -213,6 +216,7 @@ static struct scsi_host_template sgiwd93_template = {
.sg_tablesize = SG_ALL,
.cmd_per_lun = 8,
.dma_boundary = PAGE_SIZE - 1,
.cmd_size = sizeof(struct scsi_pointer),
};

static int sgiwd93_probe(struct platform_device *pdev)
Expand Down
Loading

0 comments on commit dbb2da5

Please sign in to comment.