sky2: fix sky2_link_down copy/paste comment error
[safe/jmp/linux-2.6] / drivers / net / gianfar.c
index 4d2ca49..5bf31f1 100644 (file)
@@ -75,6 +75,7 @@
 #include <linux/if_vlan.h>
 #include <linux/spinlock.h>
 #include <linux/mm.h>
+#include <linux/of_mdio.h>
 #include <linux/of_platform.h>
 #include <linux/ip.h>
 #include <linux/tcp.h>
@@ -93,7 +94,7 @@
 #include <linux/of.h>
 
 #include "gianfar.h"
-#include "gianfar_mii.h"
+#include "fsl_pq_mdio.h"
 
 #define TX_TIMEOUT      (1*HZ)
 #undef BRIEF_GFAR_ERRORS
@@ -140,13 +141,28 @@ static void gfar_halt_nodisable(struct net_device *dev);
 void gfar_start(struct net_device *dev);
 static void gfar_clear_exact_match(struct net_device *dev);
 static void gfar_set_mac_for_addr(struct net_device *dev, int num, u8 *addr);
-
-extern const struct ethtool_ops gfar_ethtool_ops;
+static int gfar_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
 
 MODULE_AUTHOR("Freescale Semiconductor, Inc");
 MODULE_DESCRIPTION("Gianfar Ethernet Driver");
 MODULE_LICENSE("GPL");
 
+static const struct net_device_ops gfar_netdev_ops = {
+       .ndo_open = gfar_enet_open,
+       .ndo_start_xmit = gfar_start_xmit,
+       .ndo_stop = gfar_close,
+       .ndo_change_mtu = gfar_change_mtu,
+       .ndo_set_multicast_list = gfar_set_multi,
+       .ndo_tx_timeout = gfar_timeout,
+       .ndo_do_ioctl = gfar_ioctl,
+       .ndo_vlan_rx_register = gfar_vlan_rx_register,
+       .ndo_set_mac_address = eth_mac_addr,
+       .ndo_validate_addr = eth_validate_addr,
+#ifdef CONFIG_NET_POLL_CONTROLLER
+       .ndo_poll_controller = gfar_netpoll,
+#endif
+};
+
 /* Returns 1 if incoming frames use an FCB */
 static inline int gfar_uses_fcb(struct gfar_private *priv)
 {
@@ -155,17 +171,16 @@ static inline int gfar_uses_fcb(struct gfar_private *priv)
 
 static int gfar_of_init(struct net_device *dev)
 {
-       struct device_node *phy, *mdio;
-       const unsigned int *id;
        const char *model;
        const char *ctype;
        const void *mac_addr;
-       const phandle *ph;
        u64 addr, size;
        int err = 0;
        struct gfar_private *priv = netdev_priv(dev);
        struct device_node *np = priv->node;
-       char bus_name[MII_BUS_ID_SIZE];
+       const u32 *stash;
+       const u32 *stash_len;
+       const u32 *stash_idx;
 
        if (!np || !of_device_is_available(np))
                return -ENODEV;
@@ -195,6 +210,26 @@ static int gfar_of_init(struct net_device *dev)
                }
        }
 
+       stash = of_get_property(np, "bd-stash", NULL);
+
+       if(stash) {
+               priv->device_flags |= FSL_GIANFAR_DEV_HAS_BD_STASHING;
+               priv->bd_stash_en = 1;
+       }
+
+       stash_len = of_get_property(np, "rx-stash-len", NULL);
+
+       if (stash_len)
+               priv->rx_stash_size = *stash_len;
+
+       stash_idx = of_get_property(np, "rx-stash-idx", NULL);
+
+       if (stash_idx)
+               priv->rx_stash_index = *stash_idx;
+
+       if (stash_len || stash_idx)
+               priv->device_flags |= FSL_GIANFAR_DEV_HAS_BUF_STASHING;
+
        mac_addr = of_get_mac_address(np);
        if (mac_addr)
                memcpy(dev->dev_addr, mac_addr, MAC_ADDR_LEN);
@@ -228,66 +263,10 @@ static int gfar_of_init(struct net_device *dev)
        if (of_get_property(np, "fsl,magic-packet", NULL))
                priv->device_flags |= FSL_GIANFAR_DEV_HAS_MAGIC_PACKET;
 
-       ph = of_get_property(np, "phy-handle", NULL);
-       if (ph == NULL) {
-               u32 *fixed_link;
-
-               fixed_link = (u32 *)of_get_property(np, "fixed-link", NULL);
-               if (!fixed_link) {
-                       err = -ENODEV;
-                       goto err_out;
-               }
-
-               snprintf(priv->phy_bus_id, sizeof(priv->phy_bus_id),
-                               PHY_ID_FMT, "0", fixed_link[0]);
-       } else {
-               phy = of_find_node_by_phandle(*ph);
-
-               if (phy == NULL) {
-                       err = -ENODEV;
-                       goto err_out;
-               }
-
-               mdio = of_get_parent(phy);
-
-               id = of_get_property(phy, "reg", NULL);
-
-               of_node_put(phy);
-               of_node_put(mdio);
-
-               gfar_mdio_bus_name(bus_name, mdio);
-               snprintf(priv->phy_bus_id, sizeof(priv->phy_bus_id), "%s:%02x",
-                               bus_name, *id);
-       }
+       priv->phy_node = of_parse_phandle(np, "phy-handle", 0);
 
        /* Find the TBI PHY.  If it's not there, we don't support SGMII */
-       ph = of_get_property(np, "tbi-handle", NULL);
-       if (ph) {
-               struct device_node *tbi = of_find_node_by_phandle(*ph);
-               struct of_device *ofdev;
-               struct mii_bus *bus;
-
-               if (!tbi)
-                       return 0;
-
-               mdio = of_get_parent(tbi);
-               if (!mdio)
-                       return 0;
-
-               ofdev = of_find_device_by_node(mdio);
-
-               of_node_put(mdio);
-
-               id = of_get_property(tbi, "reg", NULL);
-               if (!id)
-                       return 0;
-
-               of_node_put(tbi);
-
-               bus = dev_get_drvdata(&ofdev->dev);
-
-               priv->tbiphy = bus->phy_map[*id];
-       }
+       priv->tbi_node = of_parse_phandle(np, "tbi-handle", 0);
 
        return 0;
 
@@ -318,7 +297,6 @@ static int gfar_probe(struct of_device *ofdev,
        u32 tempval;
        struct net_device *dev = NULL;
        struct gfar_private *priv = NULL;
-       DECLARE_MAC_BUF(mac);
        int err = 0;
        int len_devname;
 
@@ -329,8 +307,10 @@ static int gfar_probe(struct of_device *ofdev,
                return -ENOMEM;
 
        priv = netdev_priv(dev);
-       priv->dev = dev;
+       priv->ndev = dev;
+       priv->ofdev = ofdev;
        priv->node = ofdev->node;
+       SET_NETDEV_DEV(dev, &ofdev->dev);
 
        err = gfar_of_init(dev);
 
@@ -351,6 +331,9 @@ static int gfar_probe(struct of_device *ofdev,
        /* Reset MAC layer */
        gfar_write(&priv->regs->maccfg1, MACCFG1_SOFT_RESET);
 
+       /* We need to delay at least 3 TX clocks */
+       udelay(2);
+
        tempval = (MACCFG1_TX_FLOW | MACCFG1_RX_FLOW);
        gfar_write(&priv->regs->maccfg1, tempval);
 
@@ -366,21 +349,12 @@ static int gfar_probe(struct of_device *ofdev,
        SET_NETDEV_DEV(dev, &ofdev->dev);
 
        /* Fill in the dev structure */
-       dev->open = gfar_enet_open;
-       dev->hard_start_xmit = gfar_start_xmit;
-       dev->tx_timeout = gfar_timeout;
        dev->watchdog_timeo = TX_TIMEOUT;
        netif_napi_add(dev, &priv->napi, gfar_poll, GFAR_DEV_WEIGHT);
-#ifdef CONFIG_NET_POLL_CONTROLLER
-       dev->poll_controller = gfar_netpoll;
-#endif
-       dev->stop = gfar_close;
-       dev->change_mtu = gfar_change_mtu;
        dev->mtu = 1500;
-       dev->set_multicast_list = gfar_set_multi;
 
+       dev->netdev_ops = &gfar_netdev_ops;
        dev->ethtool_ops = &gfar_ethtool_ops;
-       dev->do_ioctl = gfar_ioctl;
 
        if (priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM) {
                priv->rx_csum_enable = 1;
@@ -390,11 +364,8 @@ static int gfar_probe(struct of_device *ofdev,
 
        priv->vlgrp = NULL;
 
-       if (priv->device_flags & FSL_GIANFAR_DEV_HAS_VLAN) {
-               dev->vlan_rx_register = gfar_vlan_rx_register;
-
+       if (priv->device_flags & FSL_GIANFAR_DEV_HAS_VLAN)
                dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
-       }
 
        if (priv->device_flags & FSL_GIANFAR_DEV_HAS_EXTENDED_HASH) {
                priv->extended_hash = 1;
@@ -422,7 +393,7 @@ static int gfar_probe(struct of_device *ofdev,
                priv->hash_width = 8;
 
                priv->hash_regs[0] = &priv->regs->gaddr0;
-                priv->hash_regs[1] = &priv->regs->gaddr1;
+               priv->hash_regs[1] = &priv->regs->gaddr1;
                priv->hash_regs[2] = &priv->regs->gaddr2;
                priv->hash_regs[3] = &priv->regs->gaddr3;
                priv->hash_regs[4] = &priv->regs->gaddr4;
@@ -500,6 +471,10 @@ static int gfar_probe(struct of_device *ofdev,
 register_fail:
        iounmap(priv->regs);
 regs_fail:
+       if (priv->phy_node)
+               of_node_put(priv->phy_node);
+       if (priv->tbi_node)
+               of_node_put(priv->tbi_node);
        free_netdev(dev);
        return err;
 }
@@ -508,10 +483,16 @@ static int gfar_remove(struct of_device *ofdev)
 {
        struct gfar_private *priv = dev_get_drvdata(&ofdev->dev);
 
+       if (priv->phy_node)
+               of_node_put(priv->phy_node);
+       if (priv->tbi_node)
+               of_node_put(priv->tbi_node);
+
        dev_set_drvdata(&ofdev->dev, NULL);
 
+       unregister_netdev(priv->ndev);
        iounmap(priv->regs);
-       free_netdev(priv->dev);
+       free_netdev(priv->ndev);
 
        return 0;
 }
@@ -520,7 +501,7 @@ static int gfar_remove(struct of_device *ofdev)
 static int gfar_suspend(struct of_device *ofdev, pm_message_t state)
 {
        struct gfar_private *priv = dev_get_drvdata(&ofdev->dev);
-       struct net_device *dev = priv->dev;
+       struct net_device *dev = priv->ndev;
        unsigned long flags;
        u32 tempval;
 
@@ -569,7 +550,7 @@ static int gfar_suspend(struct of_device *ofdev, pm_message_t state)
 static int gfar_resume(struct of_device *ofdev)
 {
        struct gfar_private *priv = dev_get_drvdata(&ofdev->dev);
-       struct net_device *dev = priv->dev;
+       struct net_device *dev = priv->ndev;
        unsigned long flags;
        u32 tempval;
        int magic_packet = priv->wol_en &&
@@ -661,7 +642,6 @@ static int init_phy(struct net_device *dev)
        uint gigabit_support =
                priv->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT ?
                SUPPORTED_1000baseT_Full : 0;
-       struct phy_device *phydev;
        phy_interface_t interface;
 
        priv->oldlink = 0;
@@ -670,21 +650,22 @@ static int init_phy(struct net_device *dev)
 
        interface = gfar_get_interface(dev);
 
-       phydev = phy_connect(dev, priv->phy_bus_id, &adjust_link, 0, interface);
+       priv->phydev = of_phy_connect(dev, priv->phy_node, &adjust_link, 0,
+                                     interface);
+       if (!priv->phydev)
+               priv->phydev = of_phy_connect_fixed_link(dev, &adjust_link,
+                                                        interface);
+       if (!priv->phydev) {
+               dev_err(&dev->dev, "could not attach to PHY\n");
+               return -ENODEV;
+       }
 
        if (interface == PHY_INTERFACE_MODE_SGMII)
                gfar_configure_serdes(dev);
 
-       if (IS_ERR(phydev)) {
-               printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
-               return PTR_ERR(phydev);
-       }
-
        /* Remove any features not supported by the controller */
-       phydev->supported &= (GFAR_SUPPORTED | gigabit_support);
-       phydev->advertising = phydev->supported;
-
-       priv->phydev = phydev;
+       priv->phydev->supported &= (GFAR_SUPPORTED | gigabit_support);
+       priv->phydev->advertising = priv->phydev->supported;
 
        return 0;
 }
@@ -701,10 +682,17 @@ static int init_phy(struct net_device *dev)
 static void gfar_configure_serdes(struct net_device *dev)
 {
        struct gfar_private *priv = netdev_priv(dev);
+       struct phy_device *tbiphy;
 
-       if (!priv->tbiphy) {
-               printk(KERN_WARNING "SGMII mode requires that the device "
-                               "tree specify a tbi-handle\n");
+       if (!priv->tbi_node) {
+               dev_warn(&dev->dev, "error: SGMII mode requires that the "
+                                   "device tree specify a tbi-handle\n");
+               return;
+       }
+
+       tbiphy = of_phy_find_device(priv->tbi_node);
+       if (!tbiphy) {
+               dev_err(&dev->dev, "error: Could not get TBI device\n");
                return;
        }
 
@@ -714,17 +702,17 @@ static void gfar_configure_serdes(struct net_device *dev)
         * everything for us?  Resetting it takes the link down and requires
         * several seconds for it to come back.
         */
-       if (phy_read(priv->tbiphy, MII_BMSR) & BMSR_LSTATUS)
+       if (phy_read(tbiphy, MII_BMSR) & BMSR_LSTATUS)
                return;
 
        /* Single clk mode, mii mode off(for serdes communication) */
-       phy_write(priv->tbiphy, MII_TBICON, TBICON_CLK_SELECT);
+       phy_write(tbiphy, MII_TBICON, TBICON_CLK_SELECT);
 
-       phy_write(priv->tbiphy, MII_ADVERTISE,
+       phy_write(tbiphy, MII_ADVERTISE,
                        ADVERTISE_1000XFULL | ADVERTISE_1000XPAUSE |
                        ADVERTISE_1000XPSE_ASYM);
 
-       phy_write(priv->tbiphy, MII_BMCR, BMCR_ANENABLE |
+       phy_write(tbiphy, MII_BMCR, BMCR_ANENABLE |
                        BMCR_ANRESTART | BMCR_FULLDPLX | BMCR_SPEED1000);
 }
 
@@ -838,12 +826,12 @@ void stop_gfar(struct net_device *dev)
                free_irq(priv->interruptTransmit, dev);
                free_irq(priv->interruptReceive, dev);
        } else {
-               free_irq(priv->interruptTransmit, dev);
+               free_irq(priv->interruptTransmit, dev);
        }
 
        free_skb_resources(priv);
 
-       dma_free_coherent(&dev->dev,
+       dma_free_coherent(&priv->ofdev->dev,
                        sizeof(struct txbd8)*priv->tx_ring_size
                        + sizeof(struct rxbd8)*priv->rx_ring_size,
                        priv->tx_bd_base,
@@ -865,12 +853,12 @@ static void free_skb_resources(struct gfar_private *priv)
                if (!priv->tx_skbuff[i])
                        continue;
 
-               dma_unmap_single(&priv->dev->dev, txbdp->bufPtr,
+               dma_unmap_single(&priv->ofdev->dev, txbdp->bufPtr,
                                txbdp->length, DMA_TO_DEVICE);
                txbdp->lstatus = 0;
                for (j = 0; j < skb_shinfo(priv->tx_skbuff[i])->nr_frags; j++) {
                        txbdp++;
-                       dma_unmap_page(&priv->dev->dev, txbdp->bufPtr,
+                       dma_unmap_page(&priv->ofdev->dev, txbdp->bufPtr,
                                        txbdp->length, DMA_TO_DEVICE);
                }
                txbdp++;
@@ -887,7 +875,7 @@ static void free_skb_resources(struct gfar_private *priv)
        if(priv->rx_skbuff != NULL) {
                for (i = 0; i < priv->rx_ring_size; i++) {
                        if (priv->rx_skbuff[i]) {
-                               dma_unmap_single(&priv->dev->dev, rxbdp->bufPtr,
+                               dma_unmap_single(&priv->ofdev->dev, rxbdp->bufPtr,
                                                priv->rx_buffer_size,
                                                DMA_FROM_DEVICE);
 
@@ -948,12 +936,13 @@ int startup_gfar(struct net_device *dev)
        struct gfar __iomem *regs = priv->regs;
        int err = 0;
        u32 rctrl = 0;
+       u32 tctrl = 0;
        u32 attrs = 0;
 
        gfar_write(&regs->imask, IMASK_INIT_CLEAR);
 
        /* Allocate memory for the buffer descriptors */
-       vaddr = (unsigned long) dma_alloc_coherent(&dev->dev,
+       vaddr = (unsigned long) dma_alloc_coherent(&priv->ofdev->dev,
                        sizeof (struct txbd8) * priv->tx_ring_size +
                        sizeof (struct rxbd8) * priv->rx_ring_size,
                        &addr, GFP_KERNEL);
@@ -1123,11 +1112,19 @@ int startup_gfar(struct net_device *dev)
                rctrl |= RCTRL_PADDING(priv->padding);
        }
 
+       /* keep vlan related bits if it's enabled */
+       if (priv->vlgrp) {
+               rctrl |= RCTRL_VLEX | RCTRL_PRSDEP_INIT;
+               tctrl |= TCTRL_VLINS;
+       }
+
        /* Init rctrl based on our settings */
        gfar_write(&priv->regs->rctrl, rctrl);
 
        if (dev->features & NETIF_F_IP_CSUM)
-               gfar_write(&priv->regs->tctrl, TCTRL_INIT_CSUM);
+               tctrl |= TCTRL_INIT_CSUM;
+
+       gfar_write(&priv->regs->tctrl, tctrl);
 
        /* Set the extraction length and index */
        attrs = ATTRELI_EL(priv->rx_stash_size) |
@@ -1165,7 +1162,7 @@ err_rxalloc_fail:
 rx_skb_fail:
        free_skb_resources(priv);
 tx_skb_fail:
-       dma_free_coherent(&dev->dev,
+       dma_free_coherent(&priv->ofdev->dev,
                        sizeof(struct txbd8)*priv->tx_ring_size
                        + sizeof(struct rxbd8)*priv->rx_ring_size,
                        priv->tx_bd_base,
@@ -1183,6 +1180,8 @@ static int gfar_enet_open(struct net_device *dev)
 
        napi_enable(&priv->napi);
 
+       skb_queue_head_init(&priv->rx_recycle);
+
        /* Initialize a bunch of registers */
        init_registers(dev);
 
@@ -1210,9 +1209,9 @@ static int gfar_enet_open(struct net_device *dev)
 
 static inline struct txfcb *gfar_add_fcb(struct sk_buff *skb)
 {
-       struct txfcb *fcb = (struct txfcb *)skb_push (skb, GMAC_FCB_LEN);
+       struct txfcb *fcb = (struct txfcb *)skb_push(skb, GMAC_FCB_LEN);
 
-       cacheable_memzero(fcb, GMAC_FCB_LEN);
+       memset(fcb, 0, GMAC_FCB_LEN);
 
        return fcb;
 }
@@ -1280,13 +1279,29 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
        base = priv->tx_bd_base;
 
+       /* make space for additional header when fcb is needed */
+       if (((skb->ip_summed == CHECKSUM_PARTIAL) ||
+                       (priv->vlgrp && vlan_tx_tag_present(skb))) &&
+                       (skb_headroom(skb) < GMAC_FCB_LEN)) {
+               struct sk_buff *skb_new;
+
+               skb_new = skb_realloc_headroom(skb, GMAC_FCB_LEN);
+               if (!skb_new) {
+                       dev->stats.tx_errors++;
+                       kfree_skb(skb);
+                       return NETDEV_TX_OK;
+               }
+               kfree_skb(skb);
+               skb = skb_new;
+       }
+
        /* total number of fragments in the SKB */
        nr_frags = skb_shinfo(skb)->nr_frags;
 
        spin_lock_irqsave(&priv->txlock, flags);
 
        /* check if there is space to queue this packet */
-       if (nr_frags > priv->num_txbdfree) {
+       if ((nr_frags+1) > priv->num_txbdfree) {
                /* no space, stop the queue */
                netif_stop_queue(dev);
                dev->stats.tx_fifo_errors++;
@@ -1316,7 +1331,7 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
                        if (i == nr_frags - 1)
                                lstatus |= BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT);
 
-                       bufaddr = dma_map_page(&dev->dev,
+                       bufaddr = dma_map_page(&priv->ofdev->dev,
                                        skb_shinfo(skb)->frags[i].page,
                                        skb_shinfo(skb)->frags[i].page_offset,
                                        length,
@@ -1348,7 +1363,7 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
        /* setup the TxBD length and buffer pointer for the first BD */
        priv->tx_skbuff[priv->skb_curtx] = skb;
-       txbdp_start->bufPtr = dma_map_single(&dev->dev, skb->data,
+       txbdp_start->bufPtr = dma_map_single(&priv->ofdev->dev, skb->data,
                        skb_headlen(skb), DMA_TO_DEVICE);
 
        lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | skb_headlen(skb);
@@ -1391,7 +1406,7 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
        /* Unlock priv */
        spin_unlock_irqrestore(&priv->txlock, flags);
 
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 /* Stops the kernel queue, and halts the controller */
@@ -1401,6 +1416,7 @@ static int gfar_close(struct net_device *dev)
 
        napi_disable(&priv->napi);
 
+       skb_queue_purge(&priv->rx_recycle);
        cancel_work_sync(&priv->reset_task);
        stop_gfar(dev);
 
@@ -1443,7 +1459,6 @@ static void gfar_vlan_rx_register(struct net_device *dev,
 
                /* Enable VLAN tag extraction */
                tempval = gfar_read(&priv->regs->rctrl);
-               tempval |= RCTRL_VLEX;
                tempval |= (RCTRL_VLEX | RCTRL_PRSDEP_INIT);
                gfar_write(&priv->regs->rctrl, tempval);
        } else {
@@ -1533,11 +1548,13 @@ static void gfar_reset_task(struct work_struct *work)
 {
        struct gfar_private *priv = container_of(work, struct gfar_private,
                        reset_task);
-       struct net_device *dev = priv->dev;
+       struct net_device *dev = priv->ndev;
 
        if (dev->flags & IFF_UP) {
+               netif_stop_queue(dev);
                stop_gfar(dev);
                startup_gfar(dev);
+               netif_start_queue(dev);
        }
 
        netif_tx_schedule_all(dev);
@@ -1580,7 +1597,7 @@ static int gfar_clean_tx_ring(struct net_device *dev)
                                (lstatus & BD_LENGTH_MASK))
                        break;
 
-               dma_unmap_single(&dev->dev,
+               dma_unmap_single(&priv->ofdev->dev,
                                bdp->bufPtr,
                                bdp->length,
                                DMA_TO_DEVICE);
@@ -1589,7 +1606,7 @@ static int gfar_clean_tx_ring(struct net_device *dev)
                bdp = next_txbd(bdp, base, tx_ring_size);
 
                for (i = 0; i < frags; i++) {
-                       dma_unmap_page(&dev->dev,
+                       dma_unmap_page(&priv->ofdev->dev,
                                        bdp->bufPtr,
                                        bdp->length,
                                        DMA_TO_DEVICE);
@@ -1597,7 +1614,17 @@ static int gfar_clean_tx_ring(struct net_device *dev)
                        bdp = next_txbd(bdp, base, tx_ring_size);
                }
 
-               dev_kfree_skb_any(skb);
+               /*
+                * If there's room in the queue (limit it to rx_buffer_size)
+                * we add this skb back into the pool, if it's the right size
+                */
+               if (skb_queue_len(&priv->rx_recycle) < priv->rx_ring_size &&
+                               skb_recycle_check(skb, priv->rx_buffer_size +
+                                       RXBUF_ALIGNMENT))
+                       __skb_queue_head(&priv->rx_recycle, skb);
+               else
+                       dev_kfree_skb_any(skb);
+
                priv->tx_skbuff[skb_dirtytx] = NULL;
 
                skb_dirtytx = (skb_dirtytx + 1) &
@@ -1631,6 +1658,12 @@ static void gfar_schedule_cleanup(struct net_device *dev)
        if (napi_schedule_prep(&priv->napi)) {
                gfar_write(&priv->regs->imask, IMASK_RTX_DISABLED);
                __napi_schedule(&priv->napi);
+       } else {
+               /*
+                * Clear IEVENT, so interrupts aren't called again
+                * because of the packets that have already arrived.
+                */
+               gfar_write(&priv->regs->ievent, IEVENT_RTX_MASK);
        }
 
        spin_unlock(&priv->rxlock);
@@ -1650,7 +1683,7 @@ static void gfar_new_rxbdp(struct net_device *dev, struct rxbd8 *bdp,
        struct gfar_private *priv = netdev_priv(dev);
        u32 lstatus;
 
-       bdp->bufPtr = dma_map_single(&dev->dev, skb->data,
+       bdp->bufPtr = dma_map_single(&priv->ofdev->dev, skb->data,
                        priv->rx_buffer_size, DMA_FROM_DEVICE);
 
        lstatus = BD_LFLAG(RXBD_EMPTY | RXBD_INTERRUPT);
@@ -1670,8 +1703,10 @@ struct sk_buff * gfar_new_skb(struct net_device *dev)
        struct gfar_private *priv = netdev_priv(dev);
        struct sk_buff *skb = NULL;
 
-       /* We have to allocate the skb, so keep trying till we succeed */
-       skb = netdev_alloc_skb(dev, priv->rx_buffer_size + RXBUF_ALIGNMENT);
+       skb = __skb_dequeue(&priv->rx_recycle);
+       if (!skb)
+               skb = netdev_alloc_skb(dev,
+                               priv->rx_buffer_size + RXBUF_ALIGNMENT);
 
        if (!skb)
                return NULL;
@@ -1808,7 +1843,7 @@ int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit)
 
                skb = priv->rx_skbuff[priv->skb_currx];
 
-               dma_unmap_single(&priv->dev->dev, bdp->bufPtr,
+               dma_unmap_single(&priv->ofdev->dev, bdp->bufPtr,
                                priv->rx_buffer_size, DMA_FROM_DEVICE);
 
                /* We drop the frame if we failed to allocate a new buffer */
@@ -1818,8 +1853,17 @@ int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit)
 
                        if (unlikely(!newskb))
                                newskb = skb;
-                       else if (skb)
-                               dev_kfree_skb_any(skb);
+                       else if (skb) {
+                               /*
+                                * We need to reset ->data to what it
+                                * was before gfar_new_skb() re-aligned
+                                * it to an RXBUF_ALIGNMENT boundary
+                                * before we put the skb back on the
+                                * recycle list.
+                                */
+                               skb->data = skb->head + NET_SKB_PAD;
+                               __skb_queue_head(&priv->rx_recycle, skb);
+                       }
                } else {
                        /* Increment the number of packets */
                        dev->stats.rx_packets++;
@@ -1831,6 +1875,8 @@ int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit)
                                skb_put(skb, pkt_len);
                                dev->stats.rx_bytes += pkt_len;
 
+                               if (in_irq() || irqs_disabled())
+                                       printk("Interrupt problem!\n");
                                gfar_process_frame(dev, skb, amount_pull);
 
                        } else {
@@ -1866,7 +1912,7 @@ int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit)
 static int gfar_poll(struct napi_struct *napi, int budget)
 {
        struct gfar_private *priv = container_of(napi, struct gfar_private, napi);
-       struct net_device *dev = priv->dev;
+       struct net_device *dev = priv->ndev;
        int tx_cleaned = 0;
        int rx_cleaned = 0;
        unsigned long flags;
@@ -2279,9 +2325,6 @@ static irqreturn_t gfar_error(int irq, void *dev_id)
        return IRQ_HANDLED;
 }
 
-/* work with hotplug and coldplug */
-MODULE_ALIAS("platform:fsl-gianfar");
-
 static struct of_device_id gfar_match[] =
 {
        {
@@ -2290,6 +2333,7 @@ static struct of_device_id gfar_match[] =
        },
        {},
 };
+MODULE_DEVICE_TABLE(of, gfar_match);
 
 /* Structure for a device driver */
 static struct of_platform_driver gfar_driver = {
@@ -2304,23 +2348,12 @@ static struct of_platform_driver gfar_driver = {
 
 static int __init gfar_init(void)
 {
-       int err = gfar_mdio_init();
-
-       if (err)
-               return err;
-
-       err = of_register_platform_driver(&gfar_driver);
-
-       if (err)
-               gfar_mdio_exit();
-
-       return err;
+       return of_register_platform_driver(&gfar_driver);
 }
 
 static void __exit gfar_exit(void)
 {
        of_unregister_platform_driver(&gfar_driver);
-       gfar_mdio_exit();
 }
 
 module_init(gfar_init);