headers: remove sched.h from interrupt.h
[safe/jmp/linux-2.6] / drivers / net / pcnet32.c
index ca8c0e0..c1b3f09 100644 (file)
@@ -31,6 +31,7 @@ static const char *const version =
 
 #include <linux/module.h>
 #include <linux/kernel.h>
+#include <linux/sched.h>
 #include <linux/string.h>
 #include <linux/errno.h>
 #include <linux/ioport.h>
@@ -303,7 +304,8 @@ static int pcnet32_probe_pci(struct pci_dev *, const struct pci_device_id *);
 static int pcnet32_probe1(unsigned long, int, struct pci_dev *);
 static int pcnet32_open(struct net_device *);
 static int pcnet32_init_ring(struct net_device *);
-static int pcnet32_start_xmit(struct sk_buff *, struct net_device *);
+static netdev_tx_t pcnet32_start_xmit(struct sk_buff *,
+                                     struct net_device *);
 static void pcnet32_tx_timeout(struct net_device *dev);
 static irqreturn_t pcnet32_interrupt(int, void *);
 static int pcnet32_close(struct net_device *);
@@ -485,7 +487,7 @@ static void pcnet32_realloc_tx_ring(struct net_device *dev,
                                           &new_ring_dma_addr);
        if (new_tx_ring == NULL) {
                if (netif_msg_drv(lp))
-                       printk("\n" KERN_ERR
+                       printk(KERN_ERR
                               "%s: Consistent memory allocation failed.\n",
                               dev->name);
                return;
@@ -496,7 +498,7 @@ static void pcnet32_realloc_tx_ring(struct net_device *dev,
                                GFP_ATOMIC);
        if (!new_dma_addr_list) {
                if (netif_msg_drv(lp))
-                       printk("\n" KERN_ERR
+                       printk(KERN_ERR
                               "%s: Memory allocation failed.\n", dev->name);
                goto free_new_tx_ring;
        }
@@ -505,7 +507,7 @@ static void pcnet32_realloc_tx_ring(struct net_device *dev,
                                GFP_ATOMIC);
        if (!new_skb_list) {
                if (netif_msg_drv(lp))
-                       printk("\n" KERN_ERR
+                       printk(KERN_ERR
                               "%s: Memory allocation failed.\n", dev->name);
                goto free_new_lists;
        }
@@ -563,7 +565,7 @@ static void pcnet32_realloc_rx_ring(struct net_device *dev,
                                           &new_ring_dma_addr);
        if (new_rx_ring == NULL) {
                if (netif_msg_drv(lp))
-                       printk("\n" KERN_ERR
+                       printk(KERN_ERR
                               "%s: Consistent memory allocation failed.\n",
                               dev->name);
                return;
@@ -574,7 +576,7 @@ static void pcnet32_realloc_rx_ring(struct net_device *dev,
                                GFP_ATOMIC);
        if (!new_dma_addr_list) {
                if (netif_msg_drv(lp))
-                       printk("\n" KERN_ERR
+                       printk(KERN_ERR
                               "%s: Memory allocation failed.\n", dev->name);
                goto free_new_rx_ring;
        }
@@ -583,7 +585,7 @@ static void pcnet32_realloc_rx_ring(struct net_device *dev,
                                GFP_ATOMIC);
        if (!new_skb_list) {
                if (netif_msg_drv(lp))
-                       printk("\n" KERN_ERR
+                       printk(KERN_ERR
                               "%s: Memory allocation failed.\n", dev->name);
                goto free_new_lists;
        }
@@ -1227,7 +1229,6 @@ static void pcnet32_rx_entry(struct net_device *dev,
                dev->stats.rx_dropped++;
                return;
        }
-       skb->dev = dev;
        if (!rx_in_place) {
                skb_reserve(skb, NET_IP_ALIGN);
                skb_put(skb, pkt_len);  /* Make room */
@@ -1246,7 +1247,6 @@ static void pcnet32_rx_entry(struct net_device *dev,
        dev->stats.rx_bytes += skb->len;
        skb->protocol = eth_type_trans(skb, dev);
        netif_receive_skb(skb);
-       dev->last_rx = jiffies;
        dev->stats.rx_packets++;
        return;
 }
@@ -1398,7 +1398,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);
+               __napi_complete(napi);
 
                /* clear interrupt masks */
                val = lp->a.read_csr(ioaddr, CSR3);
@@ -1407,7 +1407,7 @@ static int pcnet32_poll(struct napi_struct *napi, int budget)
 
                /* Set interrupt enable. */
                lp->a.write_csr(ioaddr, CSR0, CSR0_INTEN);
-               mmiowb();
+
                spin_unlock_irqrestore(&lp->lock, flags);
        }
        return work_done;
@@ -1569,6 +1569,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.
@@ -1597,8 +1613,11 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
                if (pcnet32_dwio_read_csr(ioaddr, 0) == 4
                    && pcnet32_dwio_check(ioaddr)) {
                        a = &pcnet32_dwio;
-               } else
+               } else {
+                       if (pcnet32_debug & NETIF_MSG_PROBE)
+                               printk(KERN_ERR PFX "No access methods\n");
                        goto err_release_region;
+               }
        }
 
        chip_version =
@@ -1705,7 +1724,9 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
                ret = -ENOMEM;
                goto err_release_region;
        }
-       SET_NETDEV_DEV(dev, &pdev->dev);
+
+       if (pdev)
+               SET_NETDEV_DEV(dev, &pdev->dev);
 
        if (pcnet32_debug & NETIF_MSG_PROBE)
                printk(KERN_INFO PFX "%s at %#3lx,", chipname, ioaddr);
@@ -1747,44 +1768,43 @@ 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) {
                        i = a->read_csr(ioaddr, 80) & 0x0C00;   /* Check tx_start_pt */
-                       printk("\n" KERN_INFO "    tx_start_pt(0x%04x):", i);
+                       printk(KERN_INFO "    tx_start_pt(0x%04x):", i);
                        switch (i >> 10) {
                        case 0:
-                               printk("  20 bytes,");
+                               printk(KERN_CONT "  20 bytes,");
                                break;
                        case 1:
-                               printk("  64 bytes,");
+                               printk(KERN_CONT "  64 bytes,");
                                break;
                        case 2:
-                               printk(" 128 bytes,");
+                               printk(KERN_CONT " 128 bytes,");
                                break;
                        case 3:
-                               printk("~220 bytes,");
+                               printk(KERN_CONT "~220 bytes,");
                                break;
                        }
                        i = a->read_bcr(ioaddr, 18);    /* Check Burst/Bus control */
-                       printk(" BCR18(%x):", i & 0xffff);
+                       printk(KERN_CONT " BCR18(%x):", i & 0xffff);
                        if (i & (1 << 5))
-                               printk("BurstWrEn ");
+                               printk(KERN_CONT "BurstWrEn ");
                        if (i & (1 << 6))
-                               printk("BurstRdEn ");
+                               printk(KERN_CONT "BurstRdEn ");
                        if (i & (1 << 7))
-                               printk("DWordIO ");
+                               printk(KERN_CONT "DWordIO ");
                        if (i & (1 << 11))
-                               printk("NoUFlow ");
+                               printk(KERN_CONT "NoUFlow ");
                        i = a->read_bcr(ioaddr, 25);
-                       printk("\n" KERN_INFO "    SRAMSIZE=0x%04x,", i << 8);
+                       printk(KERN_INFO "    SRAMSIZE=0x%04x,", i << 8);
                        i = a->read_bcr(ioaddr, 26);
-                       printk(" SRAM_BND=0x%04x,", i << 8);
+                       printk(KERN_CONT " SRAM_BND=0x%04x,", i << 8);
                        i = a->read_bcr(ioaddr, 27);
                        if (i & (1 << 14))
-                               printk("LowLatRx");
+                               printk(KERN_CONT "LowLatRx");
                }
        }
 
@@ -1805,7 +1825,6 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
 
        spin_lock_init(&lp->lock);
 
-       SET_NETDEV_DEV(dev, &pdev->dev);
        lp->name = chipname;
        lp->shared_irq = shared;
        lp->tx_ring_size = TX_RING_SIZE;        /* default tx ring size */
@@ -1822,7 +1841,7 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
        lp->chip_version = chip_version;
        lp->msg_enable = pcnet32_debug;
        if ((cards_found >= MAX_UNITS)
-           || (options[cards_found] > sizeof(options_mapping)))
+           || (options[cards_found] >= sizeof(options_mapping)))
                lp->options = PCNET32_PORT_ASEL;
        else
                lp->options = options_mapping[options[cards_found]];
@@ -1839,12 +1858,6 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
            ((cards_found >= MAX_UNITS) || full_duplex[cards_found]))
                lp->options |= PCNET32_PORT_FD;
 
-       if (!a) {
-               if (pcnet32_debug & NETIF_MSG_PROBE)
-                       printk(KERN_ERR PFX "No access methods\n");
-               ret = -ENODEV;
-               goto err_free_consistent;
-       }
        lp->a = *a;
 
        /* prior to register_netdev, dev->name is not yet correct */
@@ -1936,20 +1949,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;
@@ -1970,14 +1973,13 @@ pcnet32_probe1(unsigned long ioaddr, int shared, struct pci_dev *pdev)
 
        return 0;
 
-      err_free_ring:
+err_free_ring:
        pcnet32_free_ring(dev);
-      err_free_consistent:
        pci_free_consistent(lp->pci_dev, sizeof(*lp->init_block),
                            lp->init_block, lp->init_dma_addr);
-      err_free_netdev:
+err_free_netdev:
        free_netdev(dev);
-      err_release_region:
+err_release_region:
        release_region(ioaddr, PCNET32_TOTAL_SIZE);
        return ret;
 }
@@ -1993,7 +1995,7 @@ static int pcnet32_alloc_ring(struct net_device *dev, const char *name)
                                           &lp->tx_ring_dma_addr);
        if (lp->tx_ring == NULL) {
                if (netif_msg_drv(lp))
-                       printk("\n" KERN_ERR PFX
+                       printk(KERN_ERR PFX
                               "%s: Consistent memory allocation failed.\n",
                               name);
                return -ENOMEM;
@@ -2005,7 +2007,7 @@ static int pcnet32_alloc_ring(struct net_device *dev, const char *name)
                                           &lp->rx_ring_dma_addr);
        if (lp->rx_ring == NULL) {
                if (netif_msg_drv(lp))
-                       printk("\n" KERN_ERR PFX
+                       printk(KERN_ERR PFX
                               "%s: Consistent memory allocation failed.\n",
                               name);
                return -ENOMEM;
@@ -2015,7 +2017,7 @@ static int pcnet32_alloc_ring(struct net_device *dev, const char *name)
                                  GFP_ATOMIC);
        if (!lp->tx_dma_addr) {
                if (netif_msg_drv(lp))
-                       printk("\n" KERN_ERR PFX
+                       printk(KERN_ERR PFX
                               "%s: Memory allocation failed.\n", name);
                return -ENOMEM;
        }
@@ -2024,7 +2026,7 @@ static int pcnet32_alloc_ring(struct net_device *dev, const char *name)
                                  GFP_ATOMIC);
        if (!lp->rx_dma_addr) {
                if (netif_msg_drv(lp))
-                       printk("\n" KERN_ERR PFX
+                       printk(KERN_ERR PFX
                               "%s: Memory allocation failed.\n", name);
                return -ENOMEM;
        }
@@ -2033,7 +2035,7 @@ static int pcnet32_alloc_ring(struct net_device *dev, const char *name)
                                GFP_ATOMIC);
        if (!lp->tx_skbuff) {
                if (netif_msg_drv(lp))
-                       printk("\n" KERN_ERR PFX
+                       printk(KERN_ERR PFX
                               "%s: Memory allocation failed.\n", name);
                return -ENOMEM;
        }
@@ -2042,7 +2044,7 @@ static int pcnet32_alloc_ring(struct net_device *dev, const char *name)
                                GFP_ATOMIC);
        if (!lp->rx_skbuff) {
                if (netif_msg_drv(lp))
-                       printk("\n" KERN_ERR PFX
+                       printk(KERN_ERR PFX
                               "%s: Memory allocation failed.\n", name);
                return -ENOMEM;
        }
@@ -2086,6 +2088,7 @@ static void pcnet32_free_ring(struct net_device *dev)
 static int pcnet32_open(struct net_device *dev)
 {
        struct pcnet32_private *lp = netdev_priv(dev);
+       struct pci_dev *pdev = lp->pci_dev;
        unsigned long ioaddr = dev->base_addr;
        u16 val;
        int i;
@@ -2146,9 +2149,9 @@ static int pcnet32_open(struct net_device *dev)
        lp->a.write_csr(ioaddr, 124, val);
 
        /* Allied Telesyn AT 2700/2701 FX are 100Mbit only and do not negotiate */
-       if (lp->pci_dev->subsystem_vendor == PCI_VENDOR_ID_AT &&
-           (lp->pci_dev->subsystem_device == PCI_SUBDEVICE_ID_AT_2700FX ||
-            lp->pci_dev->subsystem_device == PCI_SUBDEVICE_ID_AT_2701FX)) {
+       if (pdev && pdev->subsystem_vendor == PCI_VENDOR_ID_AT &&
+           (pdev->subsystem_device == PCI_SUBDEVICE_ID_AT_2700FX ||
+            pdev->subsystem_device == PCI_SUBDEVICE_ID_AT_2701FX)) {
                if (lp->options & PCNET32_PORT_ASEL) {
                        lp->options = PCNET32_PORT_FD | PCNET32_PORT_100;
                        if (netif_msg_link(lp))
@@ -2278,7 +2281,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;
@@ -2480,7 +2483,8 @@ static void pcnet32_tx_timeout(struct net_device *dev)
        spin_unlock_irqrestore(&lp->lock, flags);
 }
 
-static int pcnet32_start_xmit(struct sk_buff *skb, struct net_device *dev)
+static netdev_tx_t pcnet32_start_xmit(struct sk_buff *skb,
+                                     struct net_device *dev)
 {
        struct pcnet32_private *lp = netdev_priv(dev);
        unsigned long ioaddr = dev->base_addr;
@@ -2533,7 +2537,7 @@ static int pcnet32_start_xmit(struct sk_buff *skb, struct net_device *dev)
                netif_stop_queue(dev);
        }
        spin_unlock_irqrestore(&lp->lock, flags);
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 /* The PCNET32 interrupt handler. */
@@ -2588,14 +2592,14 @@ pcnet32_interrupt(int irq, void *dev_id)
                                       dev->name, csr0);
                        /* unlike for the lance, there is no restart needed */
                }
-               if (netif_rx_schedule_prep(dev, &lp->napi)) {
+               if (napi_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);
+
+                       __napi_schedule(&lp->napi);
                        break;
                }
                csr0 = lp->a.read_csr(ioaddr, CSR0);
@@ -2913,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)