Skip to content

Commit

Permalink
can: sja1000: stop misusing member base_addr of struct net_device
Browse files Browse the repository at this point in the history
As discussed on the netdev mailing list, the member "base_addr" of
"struct net_device" should not be (mis)used to store the virtual
address to the SJA1000 register area. According to David Miller,
it's only use is to allow ISA and similar primitive bus devices to
have their I/O ports changed via ifconfig. The virtual address is
now stored in the private data structure of the SJA1000 device and
the callback functions use "struct sja1000_priv" instead of the
unneeded "struct net_device".

Signed-off-by: Wolfgang Grandegger <wg@grandegger.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Wolfgang Grandegger authored and David S. Miller committed Jun 1, 2009
1 parent 128ced8 commit 255a915
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 98 deletions.
36 changes: 15 additions & 21 deletions drivers/net/can/sja1000/ems_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,21 @@ MODULE_DEVICE_TABLE(pci, ems_pci_tbl);
*/
static u8 ems_pci_readb(struct ems_pci_card *card, unsigned int port)
{
return readb((void __iomem *)card->base_addr
+ (port * EMS_PCI_PORT_BYTES));
return readb(card->base_addr + (port * EMS_PCI_PORT_BYTES));
}

static u8 ems_pci_read_reg(const struct net_device *dev, int port)
static u8 ems_pci_read_reg(const struct sja1000_priv *priv, int port)
{
return readb((void __iomem *)dev->base_addr
+ (port * EMS_PCI_PORT_BYTES));
return readb(priv->reg_base + (port * EMS_PCI_PORT_BYTES));
}

static void ems_pci_write_reg(const struct net_device *dev, int port, u8 val)
static void ems_pci_write_reg(const struct sja1000_priv *priv, int port, u8 val)
{
writeb(val, (void __iomem *)dev->base_addr
+ (port * EMS_PCI_PORT_BYTES));
writeb(val, priv->reg_base + (port * EMS_PCI_PORT_BYTES));
}

static void ems_pci_post_irq(const struct net_device *dev)
static void ems_pci_post_irq(const struct sja1000_priv *priv)
{
struct sja1000_priv *priv = netdev_priv(dev);
struct ems_pci_card *card = (struct ems_pci_card *)priv->priv;

/* reset int flag of pita */
Expand All @@ -129,17 +125,17 @@ static void ems_pci_post_irq(const struct net_device *dev)
* Check if a CAN controller is present at the specified location
* by trying to set 'em into the PeliCAN mode
*/
static inline int ems_pci_check_chan(struct net_device *dev)
static inline int ems_pci_check_chan(const struct sja1000_priv *priv)
{
unsigned char res;

/* Make sure SJA1000 is in reset mode */
ems_pci_write_reg(dev, REG_MOD, 1);
ems_pci_write_reg(priv, REG_MOD, 1);

ems_pci_write_reg(dev, REG_CDR, CDR_PELICAN);
ems_pci_write_reg(priv, REG_CDR, CDR_PELICAN);

/* read reset-values */
res = ems_pci_read_reg(dev, REG_CDR);
res = ems_pci_read_reg(priv, REG_CDR);

if (res == CDR_PELICAN)
return 1;
Expand Down Expand Up @@ -257,12 +253,11 @@ static int __devinit ems_pci_add_card(struct pci_dev *pdev,
priv->irq_flags = IRQF_SHARED;

dev->irq = pdev->irq;
dev->base_addr = (unsigned long)(card->base_addr
+ EMS_PCI_CAN_BASE_OFFSET
+ (i * EMS_PCI_CAN_CTRL_SIZE));
priv->reg_base = card->base_addr + EMS_PCI_CAN_BASE_OFFSET
+ (i * EMS_PCI_CAN_CTRL_SIZE);

/* Check if channel is present */
if (ems_pci_check_chan(dev)) {
if (ems_pci_check_chan(priv)) {
priv->read_reg = ems_pci_read_reg;
priv->write_reg = ems_pci_write_reg;
priv->post_irq = ems_pci_post_irq;
Expand All @@ -286,9 +281,8 @@ static int __devinit ems_pci_add_card(struct pci_dev *pdev,

card->channels++;

dev_info(&pdev->dev, "Channel #%d at %#lX, irq %d\n",
i + 1, dev->base_addr,
dev->irq);
dev_info(&pdev->dev, "Channel #%d at 0x%p, irq %d\n",
i + 1, priv->reg_base, dev->irq);
} else {
free_sja1000dev(dev);
}
Expand Down
21 changes: 11 additions & 10 deletions drivers/net/can/sja1000/kvaser_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,15 @@ static struct pci_device_id kvaser_pci_tbl[] = {

MODULE_DEVICE_TABLE(pci, kvaser_pci_tbl);

static u8 kvaser_pci_read_reg(const struct net_device *dev, int port)
static u8 kvaser_pci_read_reg(const struct sja1000_priv *priv, int port)
{
return ioread8((void __iomem *)(dev->base_addr + port));
return ioread8(priv->reg_base + port);
}

static void kvaser_pci_write_reg(const struct net_device *dev, int port, u8 val)
static void kvaser_pci_write_reg(const struct sja1000_priv *priv,
int port, u8 val)
{
iowrite8(val, (void __iomem *)(dev->base_addr + port));
iowrite8(val, priv->reg_base + port);
}

static void kvaser_pci_disable_irq(struct net_device *dev)
Expand Down Expand Up @@ -199,7 +200,7 @@ static void kvaser_pci_del_chan(struct net_device *dev)
}
unregister_sja1000dev(dev);

pci_iounmap(board->pci_dev, (void __iomem *)dev->base_addr);
pci_iounmap(board->pci_dev, priv->reg_base);
pci_iounmap(board->pci_dev, board->conf_addr);
pci_iounmap(board->pci_dev, board->res_addr);

Expand All @@ -210,7 +211,7 @@ static int kvaser_pci_add_chan(struct pci_dev *pdev, int channel,
struct net_device **master_dev,
void __iomem *conf_addr,
void __iomem *res_addr,
unsigned long base_addr)
void __iomem *base_addr)
{
struct net_device *dev;
struct sja1000_priv *priv;
Expand Down Expand Up @@ -252,7 +253,7 @@ static int kvaser_pci_add_chan(struct pci_dev *pdev, int channel,
board->xilinx_ver = master_board->xilinx_ver;
}

dev->base_addr = base_addr + channel * KVASER_PCI_PORT_BYTES;
priv->reg_base = base_addr + channel * KVASER_PCI_PORT_BYTES;

priv->read_reg = kvaser_pci_read_reg;
priv->write_reg = kvaser_pci_write_reg;
Expand All @@ -267,8 +268,8 @@ static int kvaser_pci_add_chan(struct pci_dev *pdev, int channel,

init_step = 4;

dev_info(&pdev->dev, "base_addr=%#lx conf_addr=%p irq=%d\n",
dev->base_addr, board->conf_addr, dev->irq);
dev_info(&pdev->dev, "reg_base=%p conf_addr=%p irq=%d\n",
priv->reg_base, board->conf_addr, dev->irq);

SET_NETDEV_DEV(dev, &pdev->dev);

Expand Down Expand Up @@ -343,7 +344,7 @@ static int __devinit kvaser_pci_init_one(struct pci_dev *pdev,
for (i = 0; i < no_channels; i++) {
err = kvaser_pci_add_chan(pdev, i, &master_dev,
conf_addr, res_addr,
(unsigned long)base_addr);
base_addr);
if (err)
goto failure_cleanup;
}
Expand Down
Loading

0 comments on commit 255a915

Please sign in to comment.