Clean up duplicate includes in drivers/net/
[cascardo/linux.git] / drivers / net / fs_enet / fs_enet-main.c
index 4a05c14..5dc89d5 100644 (file)
@@ -24,7 +24,6 @@
 #include <linux/ioport.h>
 #include <linux/slab.h>
 #include <linux/interrupt.h>
-#include <linux/pci.h>
 #include <linux/init.h>
 #include <linux/delay.h>
 #include <linux/netdevice.h>
@@ -39,8 +38,6 @@
 #include <linux/phy.h>
 
 #include <linux/vmalloc.h>
-#include <asm/pgtable.h>
-
 #include <asm/pgtable.h>
 #include <asm/irq.h>
 #include <asm/uaccess.h>
@@ -71,18 +68,16 @@ static void fs_set_multicast_list(struct net_device *dev)
 }
 
 /* NAPI receive function */
-static int fs_enet_rx_napi(struct net_device *dev, int *budget)
+static int fs_enet_rx_napi(struct napi_struct *napi, int budget)
 {
-       struct fs_enet_private *fep = netdev_priv(dev);
+       struct fs_enet_private *fep = container_of(napi, struct fs_enet_private, napi);
+       struct net_device *dev = to_net_dev(fep->dev);
        const struct fs_platform_info *fpi = fep->fpi;
        cbd_t *bdp;
        struct sk_buff *skb, *skbn, *skbt;
        int received = 0;
        u16 pkt_len, sc;
        int curidx;
-       int rx_work_limit = 0;  /* pacify gcc */
-
-       rx_work_limit = min(dev->quota, *budget);
 
        if (!netif_running(dev))
                return 0;
@@ -97,7 +92,6 @@ static int fs_enet_rx_napi(struct net_device *dev, int *budget)
        (*fep->ops->napi_clear_rx_event)(dev);
 
        while (((sc = CBDR_SC(bdp)) & BD_ENET_RX_EMPTY) == 0) {
-
                curidx = bdp - fep->rx_bd_base;
 
                /*
@@ -137,11 +131,6 @@ static int fs_enet_rx_napi(struct net_device *dev, int *budget)
                        skbn = skb;
 
                } else {
-
-                       /* napi, got packet but no quota */
-                       if (--rx_work_limit < 0)
-                               break;
-
                        skb = fep->rx_skbuff[curidx];
 
                        dma_unmap_single(fep->dev, CBDR_BUFADDR(bdp),
@@ -160,7 +149,8 @@ static int fs_enet_rx_napi(struct net_device *dev, int *budget)
                                skbn = dev_alloc_skb(pkt_len + 2);
                                if (skbn != NULL) {
                                        skb_reserve(skbn, 2);   /* align IP header */
-                                       memcpy(skbn->data, skb->data, pkt_len);
+                                       skb_copy_from_linear_data(skb,
+                                                     skbn->data, pkt_len);
                                        /* swap */
                                        skbt = skb;
                                        skb = skbn;
@@ -170,7 +160,6 @@ static int fs_enet_rx_napi(struct net_device *dev, int *budget)
                                skbn = dev_alloc_skb(ENET_RX_FRSIZE);
 
                        if (skbn != NULL) {
-                               skb->dev = dev;
                                skb_put(skb, pkt_len);  /* Make room */
                                skb->protocol = eth_type_trans(skb, dev);
                                received++;
@@ -200,22 +189,19 @@ static int fs_enet_rx_napi(struct net_device *dev, int *budget)
                        bdp = fep->rx_bd_base;
 
                (*fep->ops->rx_bd_done)(dev);
+
+               if (received >= budget)
+                       break;
        }
 
        fep->cur_rx = bdp;
 
-       dev->quota -= received;
-       *budget -= received;
-
-       if (rx_work_limit < 0)
-               return 1;       /* not done */
-
-       /* done */
-       netif_rx_complete(dev);
-
-       (*fep->ops->napi_enable_rx)(dev);
-
-       return 0;
+       if (received >= budget) {
+               /* done */
+               netif_rx_complete(dev, napi);
+               (*fep->ops->napi_enable_rx)(dev);
+       }
+       return received;
 }
 
 /* non NAPI receive function */
@@ -294,7 +280,8 @@ static int fs_enet_rx_non_napi(struct net_device *dev)
                                skbn = dev_alloc_skb(pkt_len + 2);
                                if (skbn != NULL) {
                                        skb_reserve(skbn, 2);   /* align IP header */
-                                       memcpy(skbn->data, skb->data, pkt_len);
+                                       skb_copy_from_linear_data(skb,
+                                                     skbn->data, pkt_len);
                                        /* swap */
                                        skbt = skb;
                                        skb = skbn;
@@ -304,7 +291,6 @@ static int fs_enet_rx_non_napi(struct net_device *dev)
                                skbn = dev_alloc_skb(ENET_RX_FRSIZE);
 
                        if (skbn != NULL) {
-                               skb->dev = dev;
                                skb_put(skb, pkt_len);  /* Make room */
                                skb->protocol = eth_type_trans(skb, dev);
                                received++;
@@ -471,7 +457,7 @@ fs_enet_interrupt(int irq, void *dev_id)
                        if (!fpi->use_napi)
                                fs_enet_rx_non_napi(dev);
                        else {
-                               napi_ok = netif_rx_schedule_prep(dev);
+                               napi_ok = napi_schedule_prep(&fep->napi);
 
                                (*fep->ops->napi_disable_rx)(dev);
                                (*fep->ops->clear_int_events)(dev, fep->ev_napi_rx);
@@ -479,7 +465,7 @@ fs_enet_interrupt(int irq, void *dev_id)
                                /* NOTE: it is possible for FCCs in NAPI mode    */
                                /* to submit a spurious interrupt while in poll  */
                                if (napi_ok)
-                                       __netif_rx_schedule(dev);
+                                       __netif_rx_schedule(dev, &fep->napi);
                        }
                }
 
@@ -516,7 +502,6 @@ void fs_init_bds(struct net_device *dev)
                        break;
                }
                fep->rx_skbuff[i] = skb;
-               skb->dev = dev;
                CBDW_BUFADDR(bdp,
                        dma_map_single(fep->dev, skb->data,
                                L1_CACHE_ALIGN(PKT_MAXBUF_SIZE),
@@ -801,18 +786,22 @@ static int fs_enet_open(struct net_device *dev)
        int r;
        int err;
 
+       napi_enable(&fep->napi);
+
        /* Install our interrupt handler. */
        r = fs_request_irq(dev, fep->interrupt, "fs_enet-mac", fs_enet_interrupt);
        if (r != 0) {
                printk(KERN_ERR DRV_MODULE_NAME
                       ": %s Could not allocate FS_ENET IRQ!", dev->name);
+               napi_disable(&fep->napi);
                return -EINVAL;
        }
 
        err = fs_init_phy(dev);
-       if(err)
+       if(err) {
+               napi_disable(&fep->napi);
                return err;
-
+       }
        phy_start(fep->phydev);
 
        return 0;
@@ -825,6 +814,7 @@ static int fs_enet_close(struct net_device *dev)
 
        netif_stop_queue(dev);
        netif_carrier_off(dev);
+       napi_disable(&fep->napi);
        phy_stop(fep->phydev);
 
        spin_lock_irqsave(&fep->lock, flags);
@@ -1049,10 +1039,9 @@ static struct net_device *fs_init_instance(struct device *dev,
        ndev->stop = fs_enet_close;
        ndev->get_stats = fs_enet_get_stats;
        ndev->set_multicast_list = fs_set_multicast_list;
-       if (fpi->use_napi) {
-               ndev->poll = fs_enet_rx_napi;
-               ndev->weight = fpi->napi_weight;
-       }
+       netif_napi_add(ndev, &fep->napi,
+                      fs_enet_rx_napi, fpi->napi_weight);
+
        ndev->ethtool_ops = &fs_ethtool_ops;
        ndev->do_ioctl = fs_ioctl;