Commit f87f47b4 authored by Jeff Garzik's avatar Jeff Garzik Committed by Stephen Hemminger

[netdrvr tc35815] many fixes, major and minor

* s/int/unsigned long/ for 'flags' arg passed to spin_lock_irqsave
* s/unsigned int/unsigned long/ for I/O port addresses
* no need to prevent tc35815_probe from being called multiple times...
  PCI layer will do things properly for us.
* call pci_enable_device before accessing hardware, before obtaining
  irq number, and before obtaining I/O port addresses.
* remove bogus 'if (pdev)' check in PCI API ->probe function
* call SET_M0DULE_OWNER, remove MOD_{INC,DEC}_USE_COUNT
* (cleanup) don't bother casting from a void*
* (cleanup) mark debugging function with #if 0, just like the caller
* Fix many printk statements to indicate that tc_readl() returns
  a long, not an int.
* (cleanup) remove unused tc35815_proc_info function
parent a1b7d53c
...@@ -463,7 +463,6 @@ static void tc35815_set_multicast_list(struct net_device *dev); ...@@ -463,7 +463,6 @@ static void tc35815_set_multicast_list(struct net_device *dev);
static void tc35815_chip_reset(struct net_device *dev); static void tc35815_chip_reset(struct net_device *dev);
static void tc35815_chip_init(struct net_device *dev); static void tc35815_chip_init(struct net_device *dev);
static void tc35815_phy_chip_init(struct net_device *dev); static void tc35815_phy_chip_init(struct net_device *dev);
static int tc35815_proc_info(char *buffer, char **start, off_t offset, int length, int *eof, void *data);
/* A list of all installed tc35815 devices. */ /* A list of all installed tc35815 devices. */
static struct net_device *root_tc35815_dev = NULL; static struct net_device *root_tc35815_dev = NULL;
...@@ -482,48 +481,45 @@ int ...@@ -482,48 +481,45 @@ int
tc35815_probe(struct pci_dev *pdev, tc35815_probe(struct pci_dev *pdev,
const struct pci_device_id *ent) const struct pci_device_id *ent)
{ {
static int called = 0;
int err = 0; int err = 0;
int ret; int ret;
unsigned long pci_memaddr;
unsigned int pci_irq_line;
if (called) printk(KERN_INFO "tc35815_probe: found device %#08x.%#08x\n", ent->vendor, ent->device);
return -ENODEV;
called++;
if (pdev) { err = pci_enable_device(pdev);
unsigned int pci_memaddr; if (err)
unsigned int pci_irq_line; return err;
printk(KERN_INFO "tc35815_probe: found device %#08x.%#08x\n", ent->vendor, ent->device); pci_memaddr = pci_resource_start (pdev, 1);
pci_memaddr = pci_resource_start (pdev, 1); printk(KERN_INFO " pci_memaddr=%#08lx resource_flags=%#08lx\n", pci_memaddr, pci_resource_flags (pdev, 0));
printk(KERN_INFO " pci_memaddr=%#08lx resource_flags=%#08lx\n", pci_memaddr, pci_resource_flags (pdev, 0)); if (!pci_memaddr) {
printk(KERN_WARNING "no PCI MEM resources, aborting\n");
ret = -ENODEV;
goto err_out;
}
pci_irq_line = pdev->irq;
/* irq disabled. */
if (pci_irq_line == 0) {
printk(KERN_WARNING "no PCI irq, aborting\n");
ret = -ENODEV;
goto err_out;
}
if (!pci_memaddr) { ret = tc35815_probe1(pdev, pci_memaddr, pci_irq_line);
printk(KERN_WARNING "no PCI MEM resources, aborting\n"); if (ret)
return -ENODEV; goto err_out;
}
pci_irq_line = pdev->irq;
/* irq disabled. */
if (pci_irq_line == 0) {
printk(KERN_WARNING "no PCI irq, aborting\n");
return -ENODEV;
}
ret = tc35815_probe1(pdev, pci_memaddr, pci_irq_line); pci_set_master(pdev);
if (!ret) { return 0;
if ((err = pci_enable_device(pdev)) < 0) {
printk(KERN_ERR "tc35815_probe: failed to enable device -- err=%d\n", err);
return err;
}
pci_set_master(pdev);
}
return ret; err_out:
} pci_disable_device(pdev);
return -ENODEV; return ret;
} }
static int __devinit tc35815_probe1(struct pci_dev *pdev, unsigned int base_addr, unsigned int irq) static int __devinit tc35815_probe1(struct pci_dev *pdev, unsigned int base_addr, unsigned int irq)
...@@ -604,6 +600,7 @@ static int __devinit tc35815_probe1(struct pci_dev *pdev, unsigned int base_addr ...@@ -604,6 +600,7 @@ static int __devinit tc35815_probe1(struct pci_dev *pdev, unsigned int base_addr
dev->hard_start_xmit = tc35815_send_packet; dev->hard_start_xmit = tc35815_send_packet;
dev->get_stats = tc35815_get_stats; dev->get_stats = tc35815_get_stats;
dev->set_multicast_list = tc35815_set_multicast_list; dev->set_multicast_list = tc35815_set_multicast_list;
SET_MODULE_OWNER(dev);
#if 0 /* XXX called in init_etherdev */ #if 0 /* XXX called in init_etherdev */
/* Fill in the fields of the device structure with ethernet values. */ /* Fill in the fields of the device structure with ethernet values. */
...@@ -617,7 +614,7 @@ static int __devinit tc35815_probe1(struct pci_dev *pdev, unsigned int base_addr ...@@ -617,7 +614,7 @@ static int __devinit tc35815_probe1(struct pci_dev *pdev, unsigned int base_addr
static int static int
tc35815_init_queues(struct net_device *dev) tc35815_init_queues(struct net_device *dev)
{ {
struct tc35815_local *lp = (struct tc35815_local *)dev->priv; struct tc35815_local *lp = dev->priv;
int i; int i;
unsigned long fd_addr; unsigned long fd_addr;
...@@ -702,7 +699,7 @@ tc35815_init_queues(struct net_device *dev) ...@@ -702,7 +699,7 @@ tc35815_init_queues(struct net_device *dev)
static void static void
tc35815_clear_queues(struct net_device *dev) tc35815_clear_queues(struct net_device *dev)
{ {
struct tc35815_local *lp = (struct tc35815_local *)dev->priv; struct tc35815_local *lp = dev->priv;
int i; int i;
for (i = 0; i < TX_FD_NUM; i++) { for (i = 0; i < TX_FD_NUM; i++) {
...@@ -719,7 +716,7 @@ tc35815_clear_queues(struct net_device *dev) ...@@ -719,7 +716,7 @@ tc35815_clear_queues(struct net_device *dev)
static void static void
tc35815_free_queues(struct net_device *dev) tc35815_free_queues(struct net_device *dev)
{ {
struct tc35815_local *lp = (struct tc35815_local *)dev->priv; struct tc35815_local *lp = dev->priv;
int i; int i;
if (lp->tfd_base) { if (lp->tfd_base) {
...@@ -805,7 +802,7 @@ dump_frfd(struct FrFD *fd) ...@@ -805,7 +802,7 @@ dump_frfd(struct FrFD *fd)
static void static void
panic_queues(struct net_device *dev) panic_queues(struct net_device *dev)
{ {
struct tc35815_local *lp = (struct tc35815_local *)dev->priv; struct tc35815_local *lp = dev->priv;
int i; int i;
printk("TxFD base %p, start %d, end %d\n", printk("TxFD base %p, start %d, end %d\n",
...@@ -823,6 +820,7 @@ panic_queues(struct net_device *dev) ...@@ -823,6 +820,7 @@ panic_queues(struct net_device *dev)
panic("%s: Illegal queue state.", dev->name); panic("%s: Illegal queue state.", dev->name);
} }
#if 0
static void print_buf(char *add, int length) static void print_buf(char *add, int length)
{ {
int i; int i;
...@@ -839,6 +837,7 @@ static void print_buf(char *add, int length) ...@@ -839,6 +837,7 @@ static void print_buf(char *add, int length)
} }
printk("\n"); printk("\n");
} }
#endif
static void print_eth(char *add) static void print_eth(char *add)
{ {
...@@ -864,7 +863,7 @@ static void print_eth(char *add) ...@@ -864,7 +863,7 @@ static void print_eth(char *add)
static int static int
tc35815_open(struct net_device *dev) tc35815_open(struct net_device *dev)
{ {
struct tc35815_local *lp = (struct tc35815_local *)dev->priv; struct tc35815_local *lp = dev->priv;
/* /*
* This is used if the interrupt line can turned off (shared). * This is used if the interrupt line can turned off (shared).
* See 3c503.c for an example of selecting the IRQ at config-time. * See 3c503.c for an example of selecting the IRQ at config-time.
...@@ -888,19 +887,17 @@ tc35815_open(struct net_device *dev) ...@@ -888,19 +887,17 @@ tc35815_open(struct net_device *dev)
lp->tbusy = 0; lp->tbusy = 0;
netif_start_queue(dev); netif_start_queue(dev);
MOD_INC_USE_COUNT;
return 0; return 0;
} }
static void tc35815_tx_timeout(struct net_device *dev) static void tc35815_tx_timeout(struct net_device *dev)
{ {
struct tc35815_local *lp = (struct tc35815_local *)dev->priv; struct tc35815_local *lp = dev->priv;
struct tc35815_regs *tr = (struct tc35815_regs *)dev->base_addr; struct tc35815_regs *tr = (struct tc35815_regs *)dev->base_addr;
int flags; unsigned long flags;
spin_lock_irqsave(&lp->lock, flags); spin_lock_irqsave(&lp->lock, flags);
printk(KERN_WARNING "%s: transmit timed out, status %#x\n", printk(KERN_WARNING "%s: transmit timed out, status %#lx\n",
dev->name, tc_readl(&tr->Tx_Stat)); dev->name, tc_readl(&tr->Tx_Stat));
/* Try to restart the adaptor. */ /* Try to restart the adaptor. */
tc35815_chip_reset(dev); tc35815_chip_reset(dev);
...@@ -914,7 +911,7 @@ static void tc35815_tx_timeout(struct net_device *dev) ...@@ -914,7 +911,7 @@ static void tc35815_tx_timeout(struct net_device *dev)
static int tc35815_send_packet(struct sk_buff *skb, struct net_device *dev) static int tc35815_send_packet(struct sk_buff *skb, struct net_device *dev)
{ {
struct tc35815_local *lp = (struct tc35815_local *)dev->priv; struct tc35815_local *lp = dev->priv;
struct tc35815_regs *tr = (struct tc35815_regs *)dev->base_addr; struct tc35815_regs *tr = (struct tc35815_regs *)dev->base_addr;
if (netif_queue_stopped(dev)) { if (netif_queue_stopped(dev)) {
...@@ -925,7 +922,7 @@ static int tc35815_send_packet(struct sk_buff *skb, struct net_device *dev) ...@@ -925,7 +922,7 @@ static int tc35815_send_packet(struct sk_buff *skb, struct net_device *dev)
int tickssofar = jiffies - dev->trans_start; int tickssofar = jiffies - dev->trans_start;
if (tickssofar < 5) if (tickssofar < 5)
return 1; return 1;
printk(KERN_WARNING "%s: transmit timed out, status %#x\n", printk(KERN_WARNING "%s: transmit timed out, status %#lx\n",
dev->name, tc_readl(&tr->Tx_Stat)); dev->name, tc_readl(&tr->Tx_Stat));
/* Try to restart the adaptor. */ /* Try to restart the adaptor. */
tc35815_chip_reset(dev); tc35815_chip_reset(dev);
...@@ -947,7 +944,7 @@ static int tc35815_send_packet(struct sk_buff *skb, struct net_device *dev) ...@@ -947,7 +944,7 @@ static int tc35815_send_packet(struct sk_buff *skb, struct net_device *dev)
short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN; short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
unsigned char *buf = skb->data; unsigned char *buf = skb->data;
struct TxFD *txfd = &lp->tfd_base[lp->tfd_start]; struct TxFD *txfd = &lp->tfd_base[lp->tfd_start];
int flags; unsigned long flags;
lp->stats.tx_bytes += skb->len; lp->stats.tx_bytes += skb->len;
...@@ -1051,7 +1048,7 @@ static irqreturn_t tc35815_interrupt(int irq, void *dev_id, struct pt_regs * reg ...@@ -1051,7 +1048,7 @@ static irqreturn_t tc35815_interrupt(int irq, void *dev_id, struct pt_regs * reg
} }
tr = (struct tc35815_regs*)dev->base_addr; tr = (struct tc35815_regs*)dev->base_addr;
lp = (struct tc35815_local *)dev->priv; lp = dev->priv;
do { do {
status = tc_readl(&tr->Int_Src); status = tc_readl(&tr->Int_Src);
...@@ -1107,7 +1104,7 @@ static irqreturn_t tc35815_interrupt(int irq, void *dev_id, struct pt_regs * reg ...@@ -1107,7 +1104,7 @@ static irqreturn_t tc35815_interrupt(int irq, void *dev_id, struct pt_regs * reg
static void static void
tc35815_rx(struct net_device *dev) tc35815_rx(struct net_device *dev)
{ {
struct tc35815_local *lp = (struct tc35815_local *)dev->priv; struct tc35815_local *lp = dev->priv;
struct tc35815_regs *tr = (struct tc35815_regs*)dev->base_addr; struct tc35815_regs *tr = (struct tc35815_regs*)dev->base_addr;
unsigned int fdctl; unsigned int fdctl;
int i; int i;
...@@ -1157,7 +1154,9 @@ tc35815_rx(struct net_device *dev) ...@@ -1157,7 +1154,9 @@ tc35815_rx(struct net_device *dev)
offset += len; offset += len;
cur_bd++; cur_bd++;
} }
// print_buf(data,pkt_len); #if 0
print_buf(data,pkt_len);
#endif
if (tc35815_debug > 3) if (tc35815_debug > 3)
print_eth(data); print_eth(data);
skb->protocol = eth_type_trans(skb, dev); skb->protocol = eth_type_trans(skb, dev);
...@@ -1247,7 +1246,7 @@ tc35815_rx(struct net_device *dev) ...@@ -1247,7 +1246,7 @@ tc35815_rx(struct net_device *dev)
static void static void
tc35815_check_tx_stat(struct net_device *dev, int status) tc35815_check_tx_stat(struct net_device *dev, int status)
{ {
struct tc35815_local *lp = (struct tc35815_local *)dev->priv; struct tc35815_local *lp = dev->priv;
const char *msg = NULL; const char *msg = NULL;
/* count collisions */ /* count collisions */
...@@ -1304,7 +1303,7 @@ tc35815_check_tx_stat(struct net_device *dev, int status) ...@@ -1304,7 +1303,7 @@ tc35815_check_tx_stat(struct net_device *dev, int status)
static void static void
tc35815_txdone(struct net_device *dev) tc35815_txdone(struct net_device *dev)
{ {
struct tc35815_local *lp = (struct tc35815_local *)dev->priv; struct tc35815_local *lp = dev->priv;
struct tc35815_regs *tr = (struct tc35815_regs*)dev->base_addr; struct tc35815_regs *tr = (struct tc35815_regs*)dev->base_addr;
struct TxFD *txfd; struct TxFD *txfd;
unsigned int fdctl; unsigned int fdctl;
...@@ -1379,7 +1378,7 @@ tc35815_txdone(struct net_device *dev) ...@@ -1379,7 +1378,7 @@ tc35815_txdone(struct net_device *dev)
static int static int
tc35815_close(struct net_device *dev) tc35815_close(struct net_device *dev)
{ {
struct tc35815_local *lp = (struct tc35815_local *)dev->priv; struct tc35815_local *lp = dev->priv;
lp->tbusy = 1; lp->tbusy = 1;
netif_stop_queue(dev); netif_stop_queue(dev);
...@@ -1391,8 +1390,6 @@ tc35815_close(struct net_device *dev) ...@@ -1391,8 +1390,6 @@ tc35815_close(struct net_device *dev)
tc35815_free_queues(dev); tc35815_free_queues(dev);
MOD_DEC_USE_COUNT;
return 0; return 0;
} }
...@@ -1402,7 +1399,7 @@ tc35815_close(struct net_device *dev) ...@@ -1402,7 +1399,7 @@ tc35815_close(struct net_device *dev)
*/ */
static struct net_device_stats *tc35815_get_stats(struct net_device *dev) static struct net_device_stats *tc35815_get_stats(struct net_device *dev)
{ {
struct tc35815_local *lp = (struct tc35815_local *)dev->priv; struct tc35815_local *lp = dev->priv;
struct tc35815_regs *tr = (struct tc35815_regs*)dev->base_addr; struct tc35815_regs *tr = (struct tc35815_regs*)dev->base_addr;
unsigned long flags; unsigned long flags;
...@@ -1456,7 +1453,7 @@ static void tc35815_set_cam_entry(struct tc35815_regs *tr, int index, unsigned c ...@@ -1456,7 +1453,7 @@ static void tc35815_set_cam_entry(struct tc35815_regs *tr, int index, unsigned c
int i; int i;
for (i = cam_index / 4; i < cam_index / 4 + 2; i++) { for (i = cam_index / 4; i < cam_index / 4 + 2; i++) {
tc_writel(i * 4, &tr->CAM_Adr); tc_writel(i * 4, &tr->CAM_Adr);
printk("CAM 0x%x: %08x", printk("CAM 0x%x: %08lx",
i * 4, tc_readl(&tr->CAM_Data)); i * 4, tc_readl(&tr->CAM_Data));
} }
} }
...@@ -1513,9 +1510,9 @@ tc35815_set_multicast_list(struct net_device *dev) ...@@ -1513,9 +1510,9 @@ tc35815_set_multicast_list(struct net_device *dev)
static unsigned long tc_phy_read(struct net_device *dev, struct tc35815_regs *tr, int phy, int phy_reg) static unsigned long tc_phy_read(struct net_device *dev, struct tc35815_regs *tr, int phy, int phy_reg)
{ {
struct tc35815_local *lp = (struct tc35815_local *)dev->priv; struct tc35815_local *lp = dev->priv;
unsigned long data; unsigned long data;
int flags; unsigned long flags;
spin_lock_irqsave(&lp->lock, flags); spin_lock_irqsave(&lp->lock, flags);
...@@ -1529,8 +1526,8 @@ static unsigned long tc_phy_read(struct net_device *dev, struct tc35815_regs *tr ...@@ -1529,8 +1526,8 @@ static unsigned long tc_phy_read(struct net_device *dev, struct tc35815_regs *tr
static void tc_phy_write(struct net_device *dev, unsigned long d, struct tc35815_regs *tr, int phy, int phy_reg) static void tc_phy_write(struct net_device *dev, unsigned long d, struct tc35815_regs *tr, int phy, int phy_reg)
{ {
struct tc35815_local *lp = (struct tc35815_local *)dev->priv; struct tc35815_local *lp = dev->priv;
int flags; unsigned long flags;
spin_lock_irqsave(&lp->lock, flags); spin_lock_irqsave(&lp->lock, flags);
...@@ -1543,7 +1540,7 @@ static void tc_phy_write(struct net_device *dev, unsigned long d, struct tc35815 ...@@ -1543,7 +1540,7 @@ static void tc_phy_write(struct net_device *dev, unsigned long d, struct tc35815
static void tc35815_phy_chip_init(struct net_device *dev) static void tc35815_phy_chip_init(struct net_device *dev)
{ {
struct tc35815_local *lp = (struct tc35815_local *)dev->priv; struct tc35815_local *lp = dev->priv;
struct tc35815_regs *tr = (struct tc35815_regs*)dev->base_addr; struct tc35815_regs *tr = (struct tc35815_regs*)dev->base_addr;
static int first = 1; static int first = 1;
unsigned short ctl; unsigned short ctl;
...@@ -1648,9 +1645,9 @@ static void tc35815_chip_reset(struct net_device *dev) ...@@ -1648,9 +1645,9 @@ static void tc35815_chip_reset(struct net_device *dev)
static void tc35815_chip_init(struct net_device *dev) static void tc35815_chip_init(struct net_device *dev)
{ {
struct tc35815_local *lp = (struct tc35815_local *)dev->priv; struct tc35815_local *lp = dev->priv;
struct tc35815_regs *tr = (struct tc35815_regs*)dev->base_addr; struct tc35815_regs *tr = (struct tc35815_regs*)dev->base_addr;
int flags; unsigned long flags;
unsigned long txctl = TX_CTL_CMD; unsigned long txctl = TX_CTL_CMD;
tc35815_phy_chip_init(dev); tc35815_phy_chip_init(dev);
...@@ -1696,40 +1693,6 @@ static void tc35815_chip_init(struct net_device *dev) ...@@ -1696,40 +1693,6 @@ static void tc35815_chip_init(struct net_device *dev)
spin_unlock_irqrestore(&lp->lock, flags); spin_unlock_irqrestore(&lp->lock, flags);
} }
static int tc35815_proc_info(char *buffer, char **start, off_t offset, int length, int *eof, void *data)
{
int len = 0;
off_t pos = 0;
off_t begin = 0;
struct net_device *dev;
len += sprintf(buffer, "TC35815 statistics:\n");
for (dev = root_tc35815_dev; dev; dev = ((struct tc35815_local *)dev->priv)->next_module) {
struct tc35815_local *lp = (struct tc35815_local *)dev->priv;
len += sprintf(buffer + len,
"%s: tx_ints %d, rx_ints %d, max_tx_qlen %d\n",
dev->name,
lp->lstats.tx_ints,
lp->lstats.rx_ints,
lp->lstats.max_tx_qlen);
pos = begin + len;
if (pos < offset) {
len = 0;
begin = pos;
}
if (pos > offset+length) break;
}
*start = buffer + (offset - begin);
len -= (offset - begin);
if (len > length) len = length;
return len;
}
/* XXX */ /* XXX */
void void
tc35815_killall(void) tc35815_killall(void)
......
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