reiserfs: add locking around error buffer
[safe/jmp/linux-2.6] / drivers / net / pcnet32.c
index 4eb322e..665a428 100644 (file)
  *************************************************************************/
 
 #define DRV_NAME       "pcnet32"
-#ifdef CONFIG_PCNET32_NAPI
-#define DRV_VERSION    "1.34-NAPI"
-#else
-#define DRV_VERSION    "1.34"
-#endif
-#define DRV_RELDATE    "14.Aug.2007"
+#define DRV_VERSION    "1.35"
+#define DRV_RELDATE    "21.Apr.2008"
 #define PFX            DRV_NAME ": "
 
 static const char *const version =
@@ -329,7 +325,7 @@ static int pcnet32_get_regs_len(struct net_device *dev);
 static void pcnet32_get_regs(struct net_device *dev, struct ethtool_regs *regs,
                             void *ptr);
 static void pcnet32_purge_tx_ring(struct net_device *dev);
-static int pcnet32_alloc_ring(struct net_device *dev, char *name);
+static int pcnet32_alloc_ring(struct net_device *dev, const char *name);
 static void pcnet32_free_ring(struct net_device *dev);
 static void pcnet32_check_media(struct net_device *dev, int verbose);
 
@@ -445,30 +441,24 @@ static struct pcnet32_access pcnet32_dwio = {
 
 static void pcnet32_netif_stop(struct net_device *dev)
 {
-#ifdef CONFIG_PCNET32_NAPI
        struct pcnet32_private *lp = netdev_priv(dev);
-#endif
+
        dev->trans_start = jiffies;
-#ifdef CONFIG_PCNET32_NAPI
        napi_disable(&lp->napi);
-#endif
        netif_tx_disable(dev);
 }
 
 static void pcnet32_netif_start(struct net_device *dev)
 {
-#ifdef CONFIG_PCNET32_NAPI
        struct pcnet32_private *lp = netdev_priv(dev);
        ulong ioaddr = dev->base_addr;
        u16 val;
-#endif
+
        netif_wake_queue(dev);
-#ifdef CONFIG_PCNET32_NAPI
        val = lp->a.read_csr(ioaddr, CSR3);
        val &= 0x00ff;
        lp->a.write_csr(ioaddr, CSR3, val);
        napi_enable(&lp->napi);
-#endif
 }
 
 /*
@@ -911,11 +901,7 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
        rc = 1;                 /* default to fail */
 
        if (netif_running(dev))
-#ifdef CONFIG_PCNET32_NAPI
                pcnet32_netif_stop(dev);
-#else
-               pcnet32_close(dev);
-#endif
 
        spin_lock_irqsave(&lp->lock, flags);
        lp->a.write_csr(ioaddr, CSR0, CSR0_STOP);       /* stop the chip */
@@ -1046,7 +1032,6 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
        x = a->read_bcr(ioaddr, 32);    /* reset internal loopback */
        a->write_bcr(ioaddr, 32, (x & ~0x0002));
 
-#ifdef CONFIG_PCNET32_NAPI
        if (netif_running(dev)) {
                pcnet32_netif_start(dev);
                pcnet32_restart(dev, CSR0_NORMAL);
@@ -1055,16 +1040,6 @@ static int pcnet32_loopback_test(struct net_device *dev, uint64_t * data1)
                lp->a.write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
        }
        spin_unlock_irqrestore(&lp->lock, flags);
-#else
-       if (netif_running(dev)) {
-               spin_unlock_irqrestore(&lp->lock, flags);
-               pcnet32_open(dev);
-       } else {
-               pcnet32_purge_rx_ring(dev);
-               lp->a.write_bcr(ioaddr, 20, 4); /* return to 16bit mode */
-               spin_unlock_irqrestore(&lp->lock, flags);
-       }
-#endif
 
        return (rc);
 }                              /* end pcnet32_loopback_test  */
@@ -1270,12 +1245,7 @@ static void pcnet32_rx_entry(struct net_device *dev,
        }
        dev->stats.rx_bytes += skb->len;
        skb->protocol = eth_type_trans(skb, dev);
-#ifdef CONFIG_PCNET32_NAPI
        netif_receive_skb(skb);
-#else
-       netif_rx(skb);
-#endif
-       dev->last_rx = jiffies;
        dev->stats.rx_packets++;
        return;
 }
@@ -1403,7 +1373,6 @@ static int pcnet32_tx(struct net_device *dev)
        return must_restart;
 }
 
-#ifdef CONFIG_PCNET32_NAPI
 static int pcnet32_poll(struct napi_struct *napi, int budget)
 {
        struct pcnet32_private *lp = container_of(napi, struct pcnet32_private, napi);
@@ -1428,7 +1397,7 @@ static int pcnet32_poll(struct napi_struct *napi, int budget)
        if (work_done < budget) {
                spin_lock_irqsave(&lp->lock, flags);
 
-               __netif_rx_complete(dev, napi);
+               __netif_rx_complete(napi);
 
                /* clear interrupt masks */
                val = lp->a.read_csr(ioaddr, CSR3);
@@ -1442,7 +1411,6 @@ static int pcnet32_poll(struct napi_struct *napi, int budget)
        }
        return work_done;
 }
-#endif
 
 #define PCNET32_REGS_PER_PHY   32
 #define PCNET32_MAX_PHYS       32
@@ -1600,6 +1568,22 @@ pcnet32_probe_pci(struct pci_dev *pdev, const struct pci_device_id *ent)
        return err;
 }
 
+static const struct net_device_ops pcnet32_netdev_ops = {
+       .ndo_open               = pcnet32_open,
+       .ndo_stop               = pcnet32_close,
+       .ndo_start_xmit         = pcnet32_start_xmit,
+       .ndo_tx_timeout         = pcnet32_tx_timeout,
+       .ndo_get_stats          = pcnet32_get_stats,
+       .ndo_set_multicast_list = pcnet32_set_multicast_list,
+       .ndo_do_ioctl           = pcnet32_ioctl,
+       .ndo_change_mtu         = eth_change_mtu,
+       .ndo_set_mac_address    = eth_mac_addr,
+       .ndo_validate_addr      = eth_validate_addr,
+#ifdef CONFIG_NET_POLL_CONTROLLER
+       .ndo_poll_controller    = pcnet32_poll_controller,
+#endif
+};
+
 /* pcnet32_probe1
  *  Called from both pcnet32_probe_vlbus and pcnet_probe_pci.
  *  pdev will be NULL when called from pcnet32_probe_vlbus.
@@ -1778,8 +1762,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
                memset(dev->dev_addr, 0, sizeof(dev->dev_addr));
 
        if (pcnet32_debug & NETIF_MSG_PROBE) {
-               DECLARE_MAC_BUF(mac);
-               printk(" %s", print_mac(mac, dev->dev_addr));
+               printk(" %pM", dev->dev_addr);
 
                /* Version 0x2623 and 0x2624 */
                if (((chip_version + 1) & 0xfffe) == 0x2624) {
@@ -1864,9 +1847,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
        /* napi.weight is used in both the napi and non-napi cases */
        lp->napi.weight = lp->rx_ring_size / 2;
 
-#ifdef CONFIG_PCNET32_NAPI
        netif_napi_add(dev, &lp->napi, pcnet32_poll, lp->rx_ring_size / 2);
-#endif
 
        if (fdx && !(lp->options & PCNET32_PORT_ASEL) &&
            ((cards_found >= MAX_UNITS) || full_duplex[cards_found]))
@@ -1969,20 +1950,10 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
        lp->watchdog_timer.function = (void *)&pcnet32_watchdog;
 
        /* The PCNET32-specific entries in the device structure. */
-       dev->open = &pcnet32_open;
-       dev->hard_start_xmit = &pcnet32_start_xmit;
-       dev->stop = &pcnet32_close;
-       dev->get_stats = &pcnet32_get_stats;
-       dev->set_multicast_list = &pcnet32_set_multicast_list;
-       dev->do_ioctl = &pcnet32_ioctl;
+       dev->netdev_ops = &pcnet32_netdev_ops;
        dev->ethtool_ops = &pcnet32_ethtool_ops;
-       dev->tx_timeout = pcnet32_tx_timeout;
        dev->watchdog_timeo = (5 * HZ);
 
-#ifdef CONFIG_NET_POLL_CONTROLLER
-       dev->poll_controller = pcnet32_poll_controller;
-#endif
-
        /* Fill in the generic fields of the device structure. */
        if (register_netdev(dev))
                goto err_free_ring;
@@ -2006,7 +1977,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
       err_free_ring:
        pcnet32_free_ring(dev);
       err_free_consistent:
-       pci_free_consistent(lp->pci_dev, sizeof(*lp->init_block), 
+       pci_free_consistent(lp->pci_dev, sizeof(*lp->init_block),
                            lp->init_block, lp->init_dma_addr);
       err_free_netdev:
        free_netdev(dev);
@@ -2016,7 +1987,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
 }
 
 /* if any allocation fails, caller must also call pcnet32_free_ring */
-static int pcnet32_alloc_ring(struct net_device *dev, char *name)
+static int pcnet32_alloc_ring(struct net_device *dev, const char *name)
 {
        struct pcnet32_private *lp = netdev_priv(dev);
 
@@ -2297,9 +2268,7 @@ static int pcnet32_open(struct net_device *dev)
                goto err_free_ring;
        }
 
-#ifdef CONFIG_PCNET32_NAPI
        napi_enable(&lp->napi);
-#endif
 
        /* Re-initialize the PCNET32, and start it when done. */
        lp->a.write_csr(ioaddr, 1, (lp->init_dma_addr & 0xffff));
@@ -2313,7 +2282,7 @@ static int pcnet32_open(struct net_device *dev)
        if (lp->chip_version >= PCNET32_79C970A) {
                /* Print the link status and start the watchdog */
                pcnet32_check_media(dev, 1);
-               mod_timer(&(lp->watchdog_timer), PCNET32_WATCHDOG_TIMEOUT);
+               mod_timer(&lp->watchdog_timer, PCNET32_WATCHDOG_TIMEOUT);
        }
 
        i = 0;
@@ -2623,35 +2592,19 @@ pcnet32_interrupt(int irq, void *dev_id)
                                       dev->name, csr0);
                        /* unlike for the lance, there is no restart needed */
                }
-#ifdef CONFIG_PCNET32_NAPI
-               if (netif_rx_schedule_prep(dev, &lp->napi)) {
+               if (netif_rx_schedule_prep(&lp->napi)) {
                        u16 val;
                        /* set interrupt masks */
                        val = lp->a.read_csr(ioaddr, CSR3);
                        val |= 0x5f00;
                        lp->a.write_csr(ioaddr, CSR3, val);
                        mmiowb();
-                       __netif_rx_schedule(dev, &lp->napi);
+                       __netif_rx_schedule(&lp->napi);
                        break;
                }
-#else
-               pcnet32_rx(dev, lp->napi.weight);
-               if (pcnet32_tx(dev)) {
-                       /* reset the chip to clear the error condition, then restart */
-                       lp->a.reset(ioaddr);
-                       lp->a.write_csr(ioaddr, CSR4, 0x0915); /* auto tx pad */
-                       pcnet32_restart(dev, CSR0_START);
-                       netif_wake_queue(dev);
-               }
-#endif
                csr0 = lp->a.read_csr(ioaddr, CSR0);
        }
 
-#ifndef CONFIG_PCNET32_NAPI
-       /* Set interrupt enable. */
-       lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN);
-#endif
-
        if (netif_msg_intr(lp))
                printk(KERN_DEBUG "%s: exiting interrupt, csr0=%#4.4x.\n",
                       dev->name, lp->a.read_csr(ioaddr, CSR0));
@@ -2670,9 +2623,7 @@ static int pcnet32_close(struct net_device *dev)
        del_timer_sync(&lp->watchdog_timer);
 
        netif_stop_queue(dev);
-#ifdef CONFIG_PCNET32_NAPI
        napi_disable(&lp->napi);
-#endif
 
        spin_lock_irqsave(&lp->lock, flags);
 
@@ -2966,7 +2917,7 @@ static void pcnet32_watchdog(struct net_device *dev)
        pcnet32_check_media(dev, 0);
        spin_unlock_irqrestore(&lp->lock, flags);
 
-       mod_timer(&(lp->watchdog_timer), PCNET32_WATCHDOG_TIMEOUT);
+       mod_timer(&lp->watchdog_timer, round_jiffies(PCNET32_WATCHDOG_TIMEOUT));
 }
 
 static int pcnet32_pm_suspend(struct pci_dev *pdev, pm_message_t state)
@@ -3006,7 +2957,7 @@ static void __devexit pcnet32_remove_one(struct pci_dev *pdev)
                unregister_netdev(dev);
                pcnet32_free_ring(dev);
                release_region(dev->base_addr, PCNET32_TOTAL_SIZE);
-               pci_free_consistent(lp->pci_dev, sizeof(*lp->init_block), 
+               pci_free_consistent(lp->pci_dev, sizeof(*lp->init_block),
                                    lp->init_block, lp->init_dma_addr);
                free_netdev(dev);
                pci_disable_device(pdev);
@@ -3089,7 +3040,7 @@ static void __exit pcnet32_cleanup_module(void)
                unregister_netdev(pcnet32_dev);
                pcnet32_free_ring(pcnet32_dev);
                release_region(pcnet32_dev->base_addr, PCNET32_TOTAL_SIZE);
-               pci_free_consistent(lp->pci_dev, sizeof(*lp->init_block), 
+               pci_free_consistent(lp->pci_dev, sizeof(*lp->init_block),
                                    lp->init_block, lp->init_dma_addr);
                free_netdev(pcnet32_dev);
                pcnet32_dev = next_dev;