Skip to content

Commit

Permalink
[PATCH] Pass struct dev pointer to dma_cache_sync()
Browse files Browse the repository at this point in the history
Pass struct dev pointer to dma_cache_sync()

dma_cache_sync() is ill-designed in that it does not have a struct device
pointer argument which makes proper support for systems that consist of a
mix of coherent and non-coherent DMA devices hard.  Change dma_cache_sync
to take a struct device pointer as first argument and fix all its callers
to pass it.

Signed-off-by: Ralf Baechle <[email protected]>
Cc: James Bottomley <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Greg KH <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
ralfbaechle authored and Linus Torvalds committed Dec 7, 2006
1 parent f67637e commit d3fa72e
Show file tree
Hide file tree
Showing 27 changed files with 137 additions and 126 deletions.
2 changes: 1 addition & 1 deletion Documentation/DMA-API.txt
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ anything like this. You must also be extra careful about accessing
memory you intend to sync partially.

void
dma_cache_sync(void *vaddr, size_t size,
dma_cache_sync(struct device *dev, void *vaddr, size_t size,
enum dma_data_direction direction)

Do a partial sync of memory that was allocated by
Expand Down
2 changes: 1 addition & 1 deletion arch/avr32/mm/dma-coherent.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <asm/addrspace.h>
#include <asm/cacheflush.h>

void dma_cache_sync(void *vaddr, size_t size, int direction)
void dma_cache_sync(struct device *dev, void *vaddr, size_t size, int direction)
{
/*
* No need to sync an uncached area
Expand Down
2 changes: 1 addition & 1 deletion arch/mips/mm/dma-coherent.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ int dma_is_consistent(struct device *dev, dma_addr_t dma_addr)

EXPORT_SYMBOL(dma_is_consistent);

void dma_cache_sync(void *vaddr, size_t size,
void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
enum dma_data_direction direction)
{
BUG_ON(direction == DMA_NONE);
Expand Down
2 changes: 1 addition & 1 deletion arch/mips/mm/dma-ip27.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ int dma_is_consistent(struct device *dev, dma_addr_t dma_addr)

EXPORT_SYMBOL(dma_is_consistent);

void dma_cache_sync(void *vaddr, size_t size,
void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
enum dma_data_direction direction)
{
BUG_ON(direction == DMA_NONE);
Expand Down
3 changes: 2 additions & 1 deletion arch/mips/mm/dma-ip32.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ int dma_is_consistent(struct device *dev, dma_addr_t dma_addr)

EXPORT_SYMBOL(dma_is_consistent);

void dma_cache_sync(void *vaddr, size_t size, enum dma_data_direction direction)
void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
enum dma_data_direction direction)
{
if (direction == DMA_NONE)
return;
Expand Down
3 changes: 2 additions & 1 deletion arch/mips/mm/dma-noncoherent.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ int dma_is_consistent(struct device *dev, dma_addr_t dma_addr)

EXPORT_SYMBOL(dma_is_consistent);

void dma_cache_sync(void *vaddr, size_t size, enum dma_data_direction direction)
void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
enum dma_data_direction direction)
{
if (direction == DMA_NONE)
return;
Expand Down
94 changes: 47 additions & 47 deletions drivers/net/lasi_82596.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@
#define DEB(x,y) if (i596_debug & (x)) { y; }


#define CHECK_WBACK(addr,len) \
do { dma_cache_sync((void *)addr, len, DMA_TO_DEVICE); } while (0)
#define CHECK_WBACK(priv, addr,len) \
do { dma_cache_sync((priv)->dev, (void *)addr, len, DMA_TO_DEVICE); } while (0)

#define CHECK_INV(addr,len) \
do { dma_cache_sync((void *)addr, len, DMA_FROM_DEVICE); } while(0)
#define CHECK_INV(priv, addr,len) \
do { dma_cache_sync((priv)->dev, (void *)addr, len, DMA_FROM_DEVICE); } while(0)

#define CHECK_WBACK_INV(addr,len) \
do { dma_cache_sync((void *)addr, len, DMA_BIDIRECTIONAL); } while (0)
#define CHECK_WBACK_INV(priv, addr,len) \
do { dma_cache_sync((priv)->dev, (void *)addr, len, DMA_BIDIRECTIONAL); } while (0)


#define PA_I82596_RESET 0 /* Offsets relative to LASI-LAN-Addr.*/
Expand Down Expand Up @@ -449,10 +449,10 @@ static inline void MPU_PORT(struct net_device *dev, int c, dma_addr_t x)

static inline int wait_istat(struct net_device *dev, struct i596_private *lp, int delcnt, char *str)
{
CHECK_INV(&(lp->iscp), sizeof(struct i596_iscp));
CHECK_INV(lp, &(lp->iscp), sizeof(struct i596_iscp));
while (--delcnt && lp->iscp.stat) {
udelay(10);
CHECK_INV(&(lp->iscp), sizeof(struct i596_iscp));
CHECK_INV(lp, &(lp->iscp), sizeof(struct i596_iscp));
}
if (!delcnt) {
printk("%s: %s, iscp.stat %04x, didn't clear\n",
Expand All @@ -466,10 +466,10 @@ static inline int wait_istat(struct net_device *dev, struct i596_private *lp, in

static inline int wait_cmd(struct net_device *dev, struct i596_private *lp, int delcnt, char *str)
{
CHECK_INV(&(lp->scb), sizeof(struct i596_scb));
CHECK_INV(lp, &(lp->scb), sizeof(struct i596_scb));
while (--delcnt && lp->scb.command) {
udelay(10);
CHECK_INV(&(lp->scb), sizeof(struct i596_scb));
CHECK_INV(lp, &(lp->scb), sizeof(struct i596_scb));
}
if (!delcnt) {
printk("%s: %s, status %4.4x, cmd %4.4x.\n",
Expand Down Expand Up @@ -522,7 +522,7 @@ static void i596_display_data(struct net_device *dev)
rbd, rbd->count, rbd->b_next, rbd->b_data, rbd->size);
rbd = rbd->v_next;
} while (rbd != lp->rbd_head);
CHECK_INV(lp, sizeof(struct i596_private));
CHECK_INV(lp, lp, sizeof(struct i596_private));
}


Expand Down Expand Up @@ -592,7 +592,7 @@ static inline void init_rx_bufs(struct net_device *dev)
rfd->b_next = WSWAPrfd(virt_to_dma(lp,lp->rfds));
rfd->cmd = CMD_EOL|CMD_FLEX;

CHECK_WBACK_INV(lp, sizeof(struct i596_private));
CHECK_WBACK_INV(lp, lp, sizeof(struct i596_private));
}

static inline void remove_rx_bufs(struct net_device *dev)
Expand Down Expand Up @@ -629,7 +629,7 @@ static void rebuild_rx_bufs(struct net_device *dev)
lp->rbd_head = lp->rbds;
lp->rfds[0].rbd = WSWAPrbd(virt_to_dma(lp,lp->rbds));

CHECK_WBACK_INV(lp, sizeof(struct i596_private));
CHECK_WBACK_INV(lp, lp, sizeof(struct i596_private));
}


Expand Down Expand Up @@ -663,8 +663,8 @@ static int init_i596_mem(struct net_device *dev)

DEB(DEB_INIT, printk("%s: starting i82596.\n", dev->name));

CHECK_WBACK(&(lp->scp), sizeof(struct i596_scp));
CHECK_WBACK(&(lp->iscp), sizeof(struct i596_iscp));
CHECK_WBACK(lp, &(lp->scp), sizeof(struct i596_scp));
CHECK_WBACK(lp, &(lp->iscp), sizeof(struct i596_iscp));

MPU_PORT(dev, PORT_ALTSCP, virt_to_dma(lp,&lp->scp));

Expand All @@ -678,25 +678,25 @@ static int init_i596_mem(struct net_device *dev)
rebuild_rx_bufs(dev);

lp->scb.command = 0;
CHECK_WBACK(&(lp->scb), sizeof(struct i596_scb));
CHECK_WBACK(lp, &(lp->scb), sizeof(struct i596_scb));

enable_irq(dev->irq); /* enable IRQs from LAN */

DEB(DEB_INIT, printk("%s: queuing CmdConfigure\n", dev->name));
memcpy(lp->cf_cmd.i596_config, init_setup, 14);
lp->cf_cmd.cmd.command = CmdConfigure;
CHECK_WBACK(&(lp->cf_cmd), sizeof(struct cf_cmd));
CHECK_WBACK(lp, &(lp->cf_cmd), sizeof(struct cf_cmd));
i596_add_cmd(dev, &lp->cf_cmd.cmd);

DEB(DEB_INIT, printk("%s: queuing CmdSASetup\n", dev->name));
memcpy(lp->sa_cmd.eth_addr, dev->dev_addr, 6);
lp->sa_cmd.cmd.command = CmdSASetup;
CHECK_WBACK(&(lp->sa_cmd), sizeof(struct sa_cmd));
CHECK_WBACK(lp, &(lp->sa_cmd), sizeof(struct sa_cmd));
i596_add_cmd(dev, &lp->sa_cmd.cmd);

DEB(DEB_INIT, printk("%s: queuing CmdTDR\n", dev->name));
lp->tdr_cmd.cmd.command = CmdTDR;
CHECK_WBACK(&(lp->tdr_cmd), sizeof(struct tdr_cmd));
CHECK_WBACK(lp, &(lp->tdr_cmd), sizeof(struct tdr_cmd));
i596_add_cmd(dev, &lp->tdr_cmd.cmd);

spin_lock_irqsave (&lp->lock, flags);
Expand All @@ -708,7 +708,7 @@ static int init_i596_mem(struct net_device *dev)
DEB(DEB_INIT, printk("%s: Issuing RX_START\n", dev->name));
lp->scb.command = RX_START;
lp->scb.rfd = WSWAPrfd(virt_to_dma(lp,lp->rfds));
CHECK_WBACK(&(lp->scb), sizeof(struct i596_scb));
CHECK_WBACK(lp, &(lp->scb), sizeof(struct i596_scb));

CA(dev);

Expand Down Expand Up @@ -740,13 +740,13 @@ static inline int i596_rx(struct net_device *dev)

rfd = lp->rfd_head; /* Ref next frame to check */

CHECK_INV(rfd, sizeof(struct i596_rfd));
CHECK_INV(lp, rfd, sizeof(struct i596_rfd));
while ((rfd->stat) & STAT_C) { /* Loop while complete frames */
if (rfd->rbd == I596_NULL)
rbd = NULL;
else if (rfd->rbd == lp->rbd_head->b_addr) {
rbd = lp->rbd_head;
CHECK_INV(rbd, sizeof(struct i596_rbd));
CHECK_INV(lp, rbd, sizeof(struct i596_rbd));
}
else {
printk("%s: rbd chain broken!\n", dev->name);
Expand Down Expand Up @@ -790,7 +790,7 @@ static inline int i596_rx(struct net_device *dev)
dma_addr = dma_map_single(lp->dev, newskb->data, PKT_BUF_SZ, DMA_FROM_DEVICE);
rbd->v_data = newskb->data;
rbd->b_data = WSWAPchar(dma_addr);
CHECK_WBACK_INV(rbd, sizeof(struct i596_rbd));
CHECK_WBACK_INV(lp, rbd, sizeof(struct i596_rbd));
}
else
skb = dev_alloc_skb(pkt_len + 2);
Expand Down Expand Up @@ -842,7 +842,7 @@ static inline int i596_rx(struct net_device *dev)
if (rbd != NULL && (rbd->count & 0x4000)) {
rbd->count = 0;
lp->rbd_head = rbd->v_next;
CHECK_WBACK_INV(rbd, sizeof(struct i596_rbd));
CHECK_WBACK_INV(lp, rbd, sizeof(struct i596_rbd));
}

/* Tidy the frame descriptor, marking it as end of list */
Expand All @@ -860,10 +860,10 @@ static inline int i596_rx(struct net_device *dev)

lp->scb.rfd = rfd->b_next;
lp->rfd_head = rfd->v_next;
CHECK_WBACK_INV(rfd->v_prev, sizeof(struct i596_rfd));
CHECK_WBACK_INV(rfd, sizeof(struct i596_rfd));
CHECK_WBACK_INV(lp, rfd->v_prev, sizeof(struct i596_rfd));
CHECK_WBACK_INV(lp, rfd, sizeof(struct i596_rfd));
rfd = lp->rfd_head;
CHECK_INV(rfd, sizeof(struct i596_rfd));
CHECK_INV(lp, rfd, sizeof(struct i596_rfd));
}

DEB(DEB_RXFRAME, printk("frames %d\n", frames));
Expand Down Expand Up @@ -902,12 +902,12 @@ static inline void i596_cleanup_cmd(struct net_device *dev, struct i596_private
ptr->v_next = NULL;
ptr->b_next = I596_NULL;
}
CHECK_WBACK_INV(ptr, sizeof(struct i596_cmd));
CHECK_WBACK_INV(lp, ptr, sizeof(struct i596_cmd));
}

wait_cmd(dev, lp, 100, "i596_cleanup_cmd timed out");
lp->scb.cmd = I596_NULL;
CHECK_WBACK(&(lp->scb), sizeof(struct i596_scb));
CHECK_WBACK(lp, &(lp->scb), sizeof(struct i596_scb));
}


Expand All @@ -925,7 +925,7 @@ static inline void i596_reset(struct net_device *dev, struct i596_private *lp)

/* FIXME: this command might cause an lpmc */
lp->scb.command = CUC_ABORT | RX_ABORT;
CHECK_WBACK(&(lp->scb), sizeof(struct i596_scb));
CHECK_WBACK(lp, &(lp->scb), sizeof(struct i596_scb));
CA(dev);

/* wait for shutdown */
Expand All @@ -951,20 +951,20 @@ static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd)
cmd->command |= (CMD_EOL | CMD_INTR);
cmd->v_next = NULL;
cmd->b_next = I596_NULL;
CHECK_WBACK(cmd, sizeof(struct i596_cmd));
CHECK_WBACK(lp, cmd, sizeof(struct i596_cmd));

spin_lock_irqsave (&lp->lock, flags);

if (lp->cmd_head != NULL) {
lp->cmd_tail->v_next = cmd;
lp->cmd_tail->b_next = WSWAPcmd(virt_to_dma(lp,&cmd->status));
CHECK_WBACK(lp->cmd_tail, sizeof(struct i596_cmd));
CHECK_WBACK(lp, lp->cmd_tail, sizeof(struct i596_cmd));
} else {
lp->cmd_head = cmd;
wait_cmd(dev, lp, 100, "i596_add_cmd timed out");
lp->scb.cmd = WSWAPcmd(virt_to_dma(lp,&cmd->status));
lp->scb.command = CUC_START;
CHECK_WBACK(&(lp->scb), sizeof(struct i596_scb));
CHECK_WBACK(lp, &(lp->scb), sizeof(struct i596_scb));
CA(dev);
}
lp->cmd_tail = cmd;
Expand Down Expand Up @@ -998,12 +998,12 @@ static int i596_test(struct net_device *dev)
data = virt_to_dma(lp,tint);

tint[1] = -1;
CHECK_WBACK(tint,PAGE_SIZE);
CHECK_WBACK(lp, tint, PAGE_SIZE);

MPU_PORT(dev, 1, data);

for(data = 1000000; data; data--) {
CHECK_INV(tint,PAGE_SIZE);
CHECK_INV(lp, tint, PAGE_SIZE);
if(tint[1] != -1)
break;

Expand Down Expand Up @@ -1061,7 +1061,7 @@ static void i596_tx_timeout (struct net_device *dev)
/* Issue a channel attention signal */
DEB(DEB_ERRORS, printk("Kicking board.\n"));
lp->scb.command = CUC_START | RX_START;
CHECK_WBACK_INV(&(lp->scb), sizeof(struct i596_scb));
CHECK_WBACK_INV(lp, &(lp->scb), sizeof(struct i596_scb));
CA (dev);
lp->last_restart = lp->stats.tx_packets;
}
Expand Down Expand Up @@ -1118,8 +1118,8 @@ static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev)
tbd->data = WSWAPchar(tx_cmd->dma_addr);

DEB(DEB_TXADDR,print_eth(skb->data, "tx-queued"));
CHECK_WBACK_INV(tx_cmd, sizeof(struct tx_cmd));
CHECK_WBACK_INV(tbd, sizeof(struct i596_tbd));
CHECK_WBACK_INV(lp, tx_cmd, sizeof(struct tx_cmd));
CHECK_WBACK_INV(lp, tbd, sizeof(struct i596_tbd));
i596_add_cmd(dev, &tx_cmd->cmd);

lp->stats.tx_packets++;
Expand Down Expand Up @@ -1228,7 +1228,7 @@ static int __devinit i82596_probe(struct net_device *dev,
lp->dma_addr = dma_addr;
lp->dev = gen_dev;

CHECK_WBACK_INV(dev->mem_start, sizeof(struct i596_private));
CHECK_WBACK_INV(lp, dev->mem_start, sizeof(struct i596_private));

i = register_netdev(dev);
if (i) {
Expand Down Expand Up @@ -1295,7 +1295,7 @@ static irqreturn_t i596_interrupt(int irq, void *dev_id)
DEB(DEB_INTS, printk("%s: i596 interrupt command unit inactive %x.\n", dev->name, status & 0x0700));

while (lp->cmd_head != NULL) {
CHECK_INV(lp->cmd_head, sizeof(struct i596_cmd));
CHECK_INV(lp, lp->cmd_head, sizeof(struct i596_cmd));
if (!(lp->cmd_head->status & STAT_C))
break;

Expand Down Expand Up @@ -1358,7 +1358,7 @@ static irqreturn_t i596_interrupt(int irq, void *dev_id)
}
ptr->v_next = NULL;
ptr->b_next = I596_NULL;
CHECK_WBACK(ptr, sizeof(struct i596_cmd));
CHECK_WBACK(lp, ptr, sizeof(struct i596_cmd));
lp->last_cmd = jiffies;
}

Expand All @@ -1372,13 +1372,13 @@ static irqreturn_t i596_interrupt(int irq, void *dev_id)

ptr->command &= 0x1fff;
ptr = ptr->v_next;
CHECK_WBACK_INV(prev, sizeof(struct i596_cmd));
CHECK_WBACK_INV(lp, prev, sizeof(struct i596_cmd));
}

if ((lp->cmd_head != NULL))
ack_cmd |= CUC_START;
lp->scb.cmd = WSWAPcmd(virt_to_dma(lp,&lp->cmd_head->status));
CHECK_WBACK_INV(&lp->scb, sizeof(struct i596_scb));
CHECK_WBACK_INV(lp, &lp->scb, sizeof(struct i596_scb));
}
if ((status & 0x1000) || (status & 0x4000)) {
if ((status & 0x4000))
Expand All @@ -1397,7 +1397,7 @@ static irqreturn_t i596_interrupt(int irq, void *dev_id)
}
wait_cmd(dev, lp, 100, "i596 interrupt, timeout");
lp->scb.command = ack_cmd;
CHECK_WBACK(&lp->scb, sizeof(struct i596_scb));
CHECK_WBACK(lp, &lp->scb, sizeof(struct i596_scb));

/* DANGER: I suspect that some kind of interrupt
acknowledgement aside from acking the 82596 might be needed
Expand Down Expand Up @@ -1426,7 +1426,7 @@ static int i596_close(struct net_device *dev)

wait_cmd(dev, lp, 100, "close1 timed out");
lp->scb.command = CUC_ABORT | RX_ABORT;
CHECK_WBACK(&lp->scb, sizeof(struct i596_scb));
CHECK_WBACK(lp, &lp->scb, sizeof(struct i596_scb));

CA(dev);

Expand Down Expand Up @@ -1486,7 +1486,7 @@ static void set_multicast_list(struct net_device *dev)
dev->name);
else {
lp->cf_cmd.cmd.command = CmdConfigure;
CHECK_WBACK_INV(&lp->cf_cmd, sizeof(struct cf_cmd));
CHECK_WBACK_INV(lp, &lp->cf_cmd, sizeof(struct cf_cmd));
i596_add_cmd(dev, &lp->cf_cmd.cmd);
}
}
Expand Down Expand Up @@ -1514,7 +1514,7 @@ static void set_multicast_list(struct net_device *dev)
DEB(DEB_MULTI, printk("%s: Adding address %02x:%02x:%02x:%02x:%02x:%02x\n",
dev->name, cp[0],cp[1],cp[2],cp[3],cp[4],cp[5]));
}
CHECK_WBACK_INV(&lp->mc_cmd, sizeof(struct mc_cmd));
CHECK_WBACK_INV(lp, &lp->mc_cmd, sizeof(struct mc_cmd));
i596_add_cmd(dev, &cmd->cmd);
}
}
Expand Down
Loading

0 comments on commit d3fa72e

Please sign in to comment.