[NET]: Make NAPI polling independent of struct net_device objects.
[deliverable/linux.git] / drivers / net / 8139cp.c
index e8c9f27817b08f9d36c60d6abacf4b6c800e85a1..7f18ca23d9f85a163f42707155d47cb93bfacda2 100644 (file)
@@ -26,7 +26,6 @@
 
        TODO:
        * Test Tx checksumming thoroughly
-       * Implement dev->tx_timeout
 
        Low priority TODO:
        * Complete reset on PciErr
@@ -107,11 +106,6 @@ MODULE_PARM_DESC (multicast_filter_limit, "8139cp: maximum number of filtered mu
 
 #define PFX                    DRV_NAME ": "
 
-#ifndef TRUE
-#define FALSE 0
-#define TRUE (!FALSE)
-#endif
-
 #define CP_DEF_MSG_ENABLE      (NETIF_MSG_DRV          | \
                                 NETIF_MSG_PROBE        | \
                                 NETIF_MSG_LINK)
@@ -340,6 +334,8 @@ struct cp_private {
        spinlock_t              lock;
        u32                     msg_enable;
 
+       struct napi_struct      napi;
+
        struct pci_dev          *pdev;
        u32                     rx_config;
        u16                     cpcmd;
@@ -435,20 +431,12 @@ static void cp_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
 
        spin_lock_irqsave(&cp->lock, flags);
        cp->vlgrp = grp;
-       cp->cpcmd |= RxVlanOn;
-       cpw16(CpCmd, cp->cpcmd);
-       spin_unlock_irqrestore(&cp->lock, flags);
-}
-
-static void cp_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
-{
-       struct cp_private *cp = netdev_priv(dev);
-       unsigned long flags;
+       if (grp)
+               cp->cpcmd |= RxVlanOn;
+       else
+               cp->cpcmd &= ~RxVlanOn;
 
-       spin_lock_irqsave(&cp->lock, flags);
-       cp->cpcmd &= ~RxVlanOn;
        cpw16(CpCmd, cp->cpcmd);
-       vlan_group_set_device(cp->vlgrp, vid, NULL);
        spin_unlock_irqrestore(&cp->lock, flags);
 }
 #endif /* CP_VLAN_TAG_USED */
@@ -515,12 +503,12 @@ static inline unsigned int cp_rx_csum_ok (u32 status)
        return 0;
 }
 
-static int cp_rx_poll (struct net_device *dev, int *budget)
+static int cp_rx_poll(struct napi_struct *napi, int budget)
 {
-       struct cp_private *cp = netdev_priv(dev);
-       unsigned rx_tail = cp->rx_tail;
-       unsigned rx_work = dev->quota;
-       unsigned rx;
+       struct cp_private *cp = container_of(napi, struct cp_private, napi);
+       struct net_device *dev = cp->dev;
+       unsigned int rx_tail = cp->rx_tail;
+       int rx;
 
 rx_status_loop:
        rx = 0;
@@ -602,33 +590,28 @@ rx_next:
                        desc->opts1 = cpu_to_le32(DescOwn | cp->rx_buf_sz);
                rx_tail = NEXT_RX(rx_tail);
 
-               if (!rx_work--)
+               if (rx >= budget)
                        break;
        }
 
        cp->rx_tail = rx_tail;
 
-       dev->quota -= rx;
-       *budget -= rx;
-
        /* if we did not reach work limit, then we're done with
         * this round of polling
         */
-       if (rx_work) {
+       if (rx < budget) {
                unsigned long flags;
 
                if (cpr16(IntrStatus) & cp_rx_intr_mask)
                        goto rx_status_loop;
 
-               local_irq_save(flags);
+               spin_lock_irqsave(&cp->lock, flags);
                cpw16_f(IntrMask, cp_intr_mask);
-               __netif_rx_complete(dev);
-               local_irq_restore(flags);
-
-               return 0;       /* done */
+               __netif_rx_complete(dev, napi);
+               spin_unlock_irqrestore(&cp->lock, flags);
        }
 
-       return 1;               /* not done */
+       return rx;
 }
 
 static irqreturn_t cp_interrupt (int irq, void *dev_instance)
@@ -661,15 +644,15 @@ static irqreturn_t cp_interrupt (int irq, void *dev_instance)
        }
 
        if (status & (RxOK | RxErr | RxEmpty | RxFIFOOvr))
-               if (netif_rx_schedule_prep(dev)) {
+               if (netif_rx_schedule_prep(dev, &cp->napi)) {
                        cpw16_f(IntrMask, cp_norx_intr_mask);
-                       __netif_rx_schedule(dev);
+                       __netif_rx_schedule(dev, &cp->napi);
                }
 
        if (status & (TxOK | TxErr | TxEmpty | SWInt))
                cp_tx(cp);
        if (status & LinkChg)
-               mii_check_media(&cp->mii_if, netif_msg_link(cp), FALSE);
+               mii_check_media(&cp->mii_if, netif_msg_link(cp), false);
 
        spin_unlock(&cp->lock);
 
@@ -1189,6 +1172,8 @@ static int cp_open (struct net_device *dev)
        if (rc)
                return rc;
 
+       napi_enable(&cp->napi);
+
        cp_init_hw(cp);
 
        rc = request_irq(dev->irq, cp_interrupt, IRQF_SHARED, dev->name, dev);
@@ -1196,12 +1181,13 @@ static int cp_open (struct net_device *dev)
                goto err_out_hw;
 
        netif_carrier_off(dev);
-       mii_check_media(&cp->mii_if, netif_msg_link(cp), TRUE);
+       mii_check_media(&cp->mii_if, netif_msg_link(cp), true);
        netif_start_queue(dev);
 
        return 0;
 
 err_out_hw:
+       napi_disable(&cp->napi);
        cp_stop_hw(cp);
        cp_free_rings(cp);
        return rc;
@@ -1212,6 +1198,8 @@ static int cp_close (struct net_device *dev)
        struct cp_private *cp = netdev_priv(dev);
        unsigned long flags;
 
+       napi_disable(&cp->napi);
+
        if (netif_msg_ifdown(cp))
                printk(KERN_DEBUG "%s: disabling interface\n", dev->name);
 
@@ -1231,6 +1219,30 @@ static int cp_close (struct net_device *dev)
        return 0;
 }
 
+static void cp_tx_timeout(struct net_device *dev)
+{
+       struct cp_private *cp = netdev_priv(dev);
+       unsigned long flags;
+       int rc;
+
+       printk(KERN_WARNING "%s: Transmit timeout, status %2x %4x %4x %4x\n",
+              dev->name, cpr8(Cmd), cpr16(CpCmd),
+              cpr16(IntrStatus), cpr16(IntrMask));
+
+       spin_lock_irqsave(&cp->lock, flags);
+
+       cp_stop_hw(cp);
+       cp_clean_rings(cp);
+       rc = cp_init_rings(cp);
+       cp_start_hw(cp);
+
+       netif_wake_queue(dev);
+
+       spin_unlock_irqrestore(&cp->lock, flags);
+
+       return;
+}
+
 #ifdef BROKEN
 static int cp_change_mtu(struct net_device *dev, int new_mtu)
 {
@@ -1568,7 +1580,6 @@ static const struct ethtool_ops cp_ethtool_ops = {
        .set_wol                = cp_set_wol,
        .get_strings            = cp_get_strings,
        .get_ethtool_stats      = cp_get_ethtool_stats,
-       .get_perm_addr          = ethtool_op_get_perm_addr,
        .get_eeprom_len         = cp_get_eeprom_len,
        .get_eeprom             = cp_get_eeprom,
        .set_eeprom             = cp_set_eeprom,
@@ -1812,7 +1823,6 @@ static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
        void __iomem *regs;
        resource_size_t pciaddr;
        unsigned int addr_len, i, pci_using_dac;
-       u8 pci_rev;
 
 #ifndef MODULE
        static int version_printed;
@@ -1820,13 +1830,11 @@ static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
                printk("%s", version);
 #endif
 
-       pci_read_config_byte(pdev, PCI_REVISION_ID, &pci_rev);
-
        if (pdev->vendor == PCI_VENDOR_ID_REALTEK &&
-           pdev->device == PCI_DEVICE_ID_REALTEK_8139 && pci_rev < 0x20) {
+           pdev->device == PCI_DEVICE_ID_REALTEK_8139 && pdev->revision < 0x20) {
                dev_err(&pdev->dev,
                           "This (id %04x:%04x rev %02x) is not an 8139C+ compatible chip\n",
-                          pdev->vendor, pdev->device, pci_rev);
+                          pdev->vendor, pdev->device, pdev->revision);
                dev_err(&pdev->dev, "Try the \"8139too\" driver instead.\n");
                return -ENODEV;
        }
@@ -1927,24 +1935,20 @@ static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
        dev->hard_start_xmit = cp_start_xmit;
        dev->get_stats = cp_get_stats;
        dev->do_ioctl = cp_ioctl;
-       dev->poll = cp_rx_poll;
 #ifdef CONFIG_NET_POLL_CONTROLLER
        dev->poll_controller = cp_poll_controller;
 #endif
-       dev->weight = 16;       /* arbitrary? from NAPI_HOWTO.txt. */
+       netif_napi_add(dev, &cp->napi, cp_rx_poll, 16);
 #ifdef BROKEN
        dev->change_mtu = cp_change_mtu;
 #endif
        dev->ethtool_ops = &cp_ethtool_ops;
-#if 0
        dev->tx_timeout = cp_tx_timeout;
        dev->watchdog_timeo = TX_TIMEOUT;
-#endif
 
 #if CP_VLAN_TAG_USED
        dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
        dev->vlan_rx_register = cp_vlan_rx_register;
-       dev->vlan_rx_kill_vid = cp_vlan_rx_kill_vid;
 #endif
 
        if (pci_using_dac)
@@ -2059,7 +2063,7 @@ static int cp_resume (struct pci_dev *pdev)
 
        spin_lock_irqsave (&cp->lock, flags);
 
-       mii_check_media(&cp->mii_if, netif_msg_link(cp), FALSE);
+       mii_check_media(&cp->mii_if, netif_msg_link(cp), false);
 
        spin_unlock_irqrestore (&cp->lock, flags);
 
This page took 0.028818 seconds and 5 git commands to generate.