Typo: depricated -> deprecated
[firefly-linux-kernel-4.4.55.git] / drivers / net / natsemi.c
index 6bb48ba809649ca7e3ab940f42ba98ba1f9dc643..953117152bbd61c84022a4d1747d6fce4a1a3104 100644 (file)
@@ -108,7 +108,7 @@ static int full_duplex[MAX_UNITS];
 #define TX_TIMEOUT  (2*HZ)
 
 #define NATSEMI_HW_TIMEOUT     400
-#define NATSEMI_TIMER_FREQ     3*HZ
+#define NATSEMI_TIMER_FREQ     5*HZ
 #define NATSEMI_PG0_NREGS      64
 #define NATSEMI_RFDR_NREGS     8
 #define NATSEMI_PG1_NREGS      4
@@ -560,6 +560,8 @@ struct netdev_private {
        /* address of a sent-in-place packet/buffer, for later free() */
        struct sk_buff *tx_skbuff[TX_RING_SIZE];
        dma_addr_t tx_dma[TX_RING_SIZE];
+       struct net_device *dev;
+       struct napi_struct napi;
        struct net_device_stats stats;
        /* Media monitoring timer */
        struct timer_list timer;
@@ -636,7 +638,7 @@ static void init_registers(struct net_device *dev);
 static int start_tx(struct sk_buff *skb, struct net_device *dev);
 static irqreturn_t intr_handler(int irq, void *dev_instance);
 static void netdev_error(struct net_device *dev, int intr_status);
-static int natsemi_poll(struct net_device *dev, int *budget);
+static int natsemi_poll(struct napi_struct *napi, int budget);
 static void netdev_rx(struct net_device *dev, int *work_done, int work_to_do);
 static void netdev_tx_done(struct net_device *dev);
 static int natsemi_change_mtu(struct net_device *dev, int new_mtu);
@@ -803,6 +805,7 @@ static int __devinit natsemi_probe1 (struct pci_dev *pdev,
        const int pcibar = 1; /* PCI base address register */
        int prev_eedata;
        u32 tmp;
+       DECLARE_MAC_BUF(mac);
 
 /* when built into the kernel, we only print version if device is found */
 #ifndef MODULE
@@ -835,7 +838,6 @@ static int __devinit natsemi_probe1 (struct pci_dev *pdev,
        dev = alloc_etherdev(sizeof (struct netdev_private));
        if (!dev)
                return -ENOMEM;
-       SET_MODULE_OWNER(dev);
        SET_NETDEV_DEV(dev, &pdev->dev);
 
        i = pci_request_regions(pdev, DRV_NAME);
@@ -861,6 +863,7 @@ static int __devinit natsemi_probe1 (struct pci_dev *pdev,
        dev->irq = irq;
 
        np = netdev_priv(dev);
+       netif_napi_add(dev, &np->napi, natsemi_poll, 64);
 
        np->pci_dev = pdev;
        pci_set_drvdata(pdev, dev);
@@ -931,8 +934,6 @@ static int __devinit natsemi_probe1 (struct pci_dev *pdev,
        dev->do_ioctl = &netdev_ioctl;
        dev->tx_timeout = &tx_timeout;
        dev->watchdog_timeo = TX_TIMEOUT;
-       dev->poll = natsemi_poll;
-       dev->weight = 64;
 
 #ifdef CONFIG_NET_POLL_CONTROLLER
        dev->poll_controller = &natsemi_poll_controller;
@@ -958,12 +959,10 @@ static int __devinit natsemi_probe1 (struct pci_dev *pdev,
                goto err_create_file;
 
        if (netif_msg_drv(np)) {
-               printk(KERN_INFO "natsemi %s: %s at %#08lx (%s), ",
-                       dev->name, natsemi_pci_info[chip_idx].name, iostart,
-                       pci_name(np->pci_dev));
-               for (i = 0; i < ETH_ALEN-1; i++)
-                               printk("%02x:", dev->dev_addr[i]);
-               printk("%02x, IRQ %d", dev->dev_addr[i], irq);
+               printk(KERN_INFO "natsemi %s: %s at %#08lx "
+                      "(%s), %s, IRQ %d",
+                      dev->name, natsemi_pci_info[chip_idx].name, iostart,
+                      pci_name(np->pci_dev), print_mac(mac, dev->dev_addr), irq);
                if (dev->if_port == PORT_TP)
                        printk(", port TP.\n");
                else if (np->ignore_phy)
@@ -997,7 +996,7 @@ static int __devinit natsemi_probe1 (struct pci_dev *pdev,
    a delay.  Note that pre-2.0.34 kernels had a cache-alignment bug that
    made udelay() unreliable.
    The old method of using an ISA access as a delay, __SLOW_DOWN_IO__, is
-   depricated.
+   deprecated.
 */
 #define eeprom_delay(ee_addr)  readl(ee_addr)
 
@@ -1554,6 +1553,8 @@ static int netdev_open(struct net_device *dev)
                free_irq(dev->irq, dev);
                return i;
        }
+       napi_enable(&np->napi);
+
        init_ring(dev);
        spin_lock_irq(&np->lock);
        init_registers(dev);
@@ -1575,7 +1576,7 @@ static int netdev_open(struct net_device *dev)
 
        /* Set the timer to check for link beat. */
        init_timer(&np->timer);
-       np->timer.expires = jiffies + NATSEMI_TIMER_FREQ;
+       np->timer.expires = round_jiffies(jiffies + NATSEMI_TIMER_FREQ);
        np->timer.data = (unsigned long)dev;
        np->timer.function = &netdev_timer; /* timer handler */
        add_timer(&np->timer);
@@ -1614,7 +1615,7 @@ static void do_cable_magic(struct net_device *dev)
                 * (these values all come from National)
                 */
                if (!(data & 0x80) || ((data >= 0xd8) && (data <= 0xff))) {
-                       struct netdev_private *np = netdev_priv(dev);
+                       np = netdev_priv(dev);
 
                        /* the bug has been triggered - fix the coefficient */
                        writew(TSTDAT_FIXED, ioaddr + TSTDAT);
@@ -1797,7 +1798,7 @@ static void netdev_timer(unsigned long data)
        struct net_device *dev = (struct net_device *)data;
        struct netdev_private *np = netdev_priv(dev);
        void __iomem * ioaddr = ns_ioaddr(dev);
-       int next_tick = 5*HZ;
+       int next_tick = NATSEMI_TIMER_FREQ;
 
        if (netif_msg_timer(np)) {
                /* DO NOT read the IntrStatus register,
@@ -1855,7 +1856,11 @@ static void netdev_timer(unsigned long data)
                        next_tick = 1;
                }
        }
-       mod_timer(&np->timer, jiffies + next_tick);
+
+       if (next_tick > 1)
+               mod_timer(&np->timer, round_jiffies(jiffies + next_tick));
+       else
+               mod_timer(&np->timer, jiffies + next_tick);
 }
 
 static void dump_ring(struct net_device *dev)
@@ -2200,10 +2205,10 @@ static irqreturn_t intr_handler(int irq, void *dev_instance)
 
        prefetch(&np->rx_skbuff[np->cur_rx % RX_RING_SIZE]);
 
-       if (netif_rx_schedule_prep(dev)) {
+       if (netif_rx_schedule_prep(dev, &np->napi)) {
                /* Disable interrupts and register for poll */
                natsemi_irq_disable(dev);
-               __netif_rx_schedule(dev);
+               __netif_rx_schedule(dev, &np->napi);
        } else
                printk(KERN_WARNING
                       "%s: Ignoring interrupt, status %#08x, mask %#08x.\n",
@@ -2216,12 +2221,11 @@ static irqreturn_t intr_handler(int irq, void *dev_instance)
 /* This is the NAPI poll routine.  As well as the standard RX handling
  * it also handles all other interrupts that the chip might raise.
  */
-static int natsemi_poll(struct net_device *dev, int *budget)
+static int natsemi_poll(struct napi_struct *napi, int budget)
 {
-       struct netdev_private *np = netdev_priv(dev);
+       struct netdev_private *np = container_of(napi, struct netdev_private, napi);
+       struct net_device *dev = np->dev;
        void __iomem * ioaddr = ns_ioaddr(dev);
-
-       int work_to_do = min(*budget, dev->quota);
        int work_done = 0;
 
        do {
@@ -2236,7 +2240,7 @@ static int natsemi_poll(struct net_device *dev, int *budget)
                if (np->intr_status &
                    (IntrRxDone | IntrRxIntr | RxStatusFIFOOver |
                     IntrRxErr | IntrRxOverrun)) {
-                       netdev_rx(dev, &work_done, work_to_do);
+                       netdev_rx(dev, &work_done, budget);
                }
 
                if (np->intr_status &
@@ -2250,16 +2254,13 @@ static int natsemi_poll(struct net_device *dev, int *budget)
                if (np->intr_status & IntrAbnormalSummary)
                        netdev_error(dev, np->intr_status);
 
-               *budget -= work_done;
-               dev->quota -= work_done;
-
-               if (work_done >= work_to_do)
-                       return 1;
+               if (work_done >= budget)
+                       return work_done;
 
                np->intr_status = readl(ioaddr + IntrStatus);
        } while (np->intr_status);
 
-       netif_rx_complete(dev);
+       netif_rx_complete(dev, napi);
 
        /* Reenable interrupts providing nothing is trying to shut
         * the chip down. */
@@ -2268,7 +2269,7 @@ static int natsemi_poll(struct net_device *dev, int *budget)
                natsemi_irq_enable(dev);
        spin_unlock(&np->lock);
 
-       return 0;
+       return work_done;
 }
 
 /* This routine is logically part of the interrupt handler, but separated
@@ -2438,13 +2439,16 @@ static void netdev_error(struct net_device *dev, int intr_status)
                                dev->name);
                }
                np->stats.rx_fifo_errors++;
+               np->stats.rx_errors++;
        }
        /* Hmmmmm, it's not clear how to recover from PCI faults. */
        if (intr_status & IntrPCIErr) {
                printk(KERN_NOTICE "%s: PCI error %#08x\n", dev->name,
                        intr_status & IntrPCIErr);
                np->stats.tx_fifo_errors++;
+               np->stats.tx_errors++;
                np->stats.rx_fifo_errors++;
+               np->stats.rx_errors++;
        }
        spin_unlock(&np->lock);
 }
@@ -2502,8 +2506,8 @@ static void __set_rx_mode(struct net_device *dev)
                memset(mc_filter, 0, sizeof(mc_filter));
                for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
                         i++, mclist = mclist->next) {
-                       int i = (ether_crc(ETH_ALEN, mclist->dmi_addr) >> 23) & 0x1ff;
-                       mc_filter[i/8] |= (1 << (i & 0x07));
+                       int b = (ether_crc(ETH_ALEN, mclist->dmi_addr) >> 23) & 0x1ff;
+                       mc_filter[b/8] |= (1 << (b & 0x07));
                }
                rx_mode = RxFilterEnable | AcceptBroadcast
                        | AcceptMulticast | AcceptMyPhys;
@@ -3155,6 +3159,8 @@ static int netdev_close(struct net_device *dev)
                        dev->name, np->cur_tx, np->dirty_tx,
                        np->cur_rx, np->dirty_rx);
 
+       napi_disable(&np->napi);
+
        /*
         * FIXME: what if someone tries to close a device
         * that is suspended?
@@ -3250,7 +3256,7 @@ static void __devexit natsemi_remove1 (struct pci_dev *pdev)
  *             disable_irq() to enforce synchronization.
  *      * natsemi_poll: checks before reenabling interrupts.  suspend
  *              sets hands_off, disables interrupts and then waits with
- *              netif_poll_disable().
+ *              napi_disable().
  *
  * Interrupts must be disabled, otherwise hands_off can cause irq storms.
  */
@@ -3276,7 +3282,7 @@ static int natsemi_suspend (struct pci_dev *pdev, pm_message_t state)
                spin_unlock_irq(&np->lock);
                enable_irq(dev->irq);
 
-               netif_poll_disable(dev);
+               napi_disable(&np->napi);
 
                /* Update the error counts. */
                __get_stats(dev);
@@ -3308,15 +3314,23 @@ static int natsemi_resume (struct pci_dev *pdev)
 {
        struct net_device *dev = pci_get_drvdata (pdev);
        struct netdev_private *np = netdev_priv(dev);
+       int ret = 0;
 
        rtnl_lock();
        if (netif_device_present(dev))
                goto out;
        if (netif_running(dev)) {
                BUG_ON(!np->hands_off);
-               pci_enable_device(pdev);
+               ret = pci_enable_device(pdev);
+               if (ret < 0) {
+                       dev_err(&pdev->dev,
+                               "pci_enable_device() failed: %d\n", ret);
+                       goto out;
+               }
        /*      pci_power_on(pdev); */
 
+               napi_enable(&np->napi);
+
                natsemi_reset(dev);
                init_ring(dev);
                disable_irq(dev->irq);
@@ -3327,13 +3341,12 @@ static int natsemi_resume (struct pci_dev *pdev)
                spin_unlock_irq(&np->lock);
                enable_irq(dev->irq);
 
-               mod_timer(&np->timer, jiffies + 1*HZ);
+               mod_timer(&np->timer, round_jiffies(jiffies + 1*HZ));
        }
        netif_device_attach(dev);
-       netif_poll_enable(dev);
 out:
        rtnl_unlock();
-       return 0;
+       return ret;
 }
 
 #endif /* CONFIG_PM */