b43legacy: Remove deprecated 'qual' from returned RX status
[safe/jmp/linux-2.6] / drivers / net / gianfar.c
index 7fcc3af..f714186 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,230 @@ 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 void gfar_init_rxbdp(struct net_device *dev, struct rxbd8 *bdp,
+                           dma_addr_t buf)
+{
+       struct gfar_private *priv = netdev_priv(dev);
+       u32 lstatus;
+
+       bdp->bufPtr = buf;
+
+       lstatus = BD_LFLAG(RXBD_EMPTY | RXBD_INTERRUPT);
+       if (bdp == priv->rx_bd_base + priv->rx_ring_size - 1)
+               lstatus |= BD_LFLAG(RXBD_WRAP);
+
+       eieio();
+
+       bdp->lstatus = lstatus;
+}
+
+static int gfar_init_bds(struct net_device *ndev)
+{
+       struct gfar_private *priv = netdev_priv(ndev);
+       struct txbd8 *txbdp;
+       struct rxbd8 *rxbdp;
+       int i;
+
+       /* Initialize some variables in our dev structure */
+       priv->num_txbdfree = priv->tx_ring_size;
+       priv->dirty_tx = priv->cur_tx = priv->tx_bd_base;
+       priv->cur_rx = priv->rx_bd_base;
+       priv->skb_curtx = priv->skb_dirtytx = 0;
+       priv->skb_currx = 0;
+
+       /* Initialize Transmit Descriptor Ring */
+       txbdp = priv->tx_bd_base;
+       for (i = 0; i < priv->tx_ring_size; i++) {
+               txbdp->lstatus = 0;
+               txbdp->bufPtr = 0;
+               txbdp++;
+       }
+
+       /* Set the last descriptor in the ring to indicate wrap */
+       txbdp--;
+       txbdp->status |= TXBD_WRAP;
+
+       rxbdp = priv->rx_bd_base;
+       for (i = 0; i < priv->rx_ring_size; i++) {
+               struct sk_buff *skb = priv->rx_skbuff[i];
+
+               if (skb) {
+                       gfar_init_rxbdp(ndev, rxbdp, rxbdp->bufPtr);
+               } else {
+                       skb = gfar_new_skb(ndev);
+                       if (!skb) {
+                               pr_err("%s: Can't allocate RX buffers\n",
+                                      ndev->name);
+                               return -ENOMEM;
+                       }
+                       priv->rx_skbuff[i] = skb;
+
+                       gfar_new_rxbdp(ndev, rxbdp, skb);
+               }
+
+               rxbdp++;
+       }
+
+       return 0;
+}
+
+static int gfar_alloc_skb_resources(struct net_device *ndev)
+{
+       void *vaddr;
+       int i;
+       struct gfar_private *priv = netdev_priv(ndev);
+       struct device *dev = &priv->ofdev->dev;
+
+       /* Allocate memory for the buffer descriptors */
+       vaddr = dma_alloc_coherent(dev,
+                       sizeof(*priv->tx_bd_base) * priv->tx_ring_size +
+                       sizeof(*priv->rx_bd_base) * priv->rx_ring_size,
+                       &priv->tx_bd_dma_base, GFP_KERNEL);
+       if (!vaddr) {
+               if (netif_msg_ifup(priv))
+                       pr_err("%s: Could not allocate buffer descriptors!\n",
+                              ndev->name);
+               return -ENOMEM;
+       }
+
+       priv->tx_bd_base = vaddr;
+
+       /* Start the rx descriptor ring where the tx ring leaves off */
+       vaddr = vaddr + sizeof(*priv->tx_bd_base) * priv->tx_ring_size;
+       priv->rx_bd_base = vaddr;
+
+       /* Setup the skbuff rings */
+       priv->tx_skbuff = kmalloc(sizeof(*priv->tx_skbuff) *
+                                 priv->tx_ring_size, GFP_KERNEL);
+       if (!priv->tx_skbuff) {
+               if (netif_msg_ifup(priv))
+                       pr_err("%s: Could not allocate tx_skbuff\n",
+                              ndev->name);
+               goto cleanup;
+       }
+
+       for (i = 0; i < priv->tx_ring_size; i++)
+               priv->tx_skbuff[i] = NULL;
+
+       priv->rx_skbuff = kmalloc(sizeof(*priv->rx_skbuff) *
+                                 priv->rx_ring_size, GFP_KERNEL);
+       if (!priv->rx_skbuff) {
+               if (netif_msg_ifup(priv))
+                       pr_err("%s: Could not allocate rx_skbuff\n",
+                              ndev->name);
+               goto cleanup;
+       }
+
+       for (i = 0; i < priv->rx_ring_size; i++)
+               priv->rx_skbuff[i] = NULL;
+
+       if (gfar_init_bds(ndev))
+               goto cleanup;
+
+       return 0;
+
+cleanup:
+       free_skb_resources(priv);
+       return -ENOMEM;
+}
+
+static void gfar_init_mac(struct net_device *ndev)
+{
+       struct gfar_private *priv = netdev_priv(ndev);
+       struct gfar __iomem *regs = priv->regs;
+       u32 rctrl = 0;
+       u32 tctrl = 0;
+       u32 attrs = 0;
+
+       /* enet DMA only understands physical addresses */
+       gfar_write(&regs->tbase0, priv->tx_bd_dma_base);
+       gfar_write(&regs->rbase0, priv->tx_bd_dma_base +
+                                 sizeof(*priv->tx_bd_base) *
+                                 priv->tx_ring_size);
+
+       /* Configure the coalescing support */
+       gfar_write(&regs->txic, 0);
+       if (priv->txcoalescing)
+               gfar_write(&regs->txic, priv->txic);
+
+       gfar_write(&regs->rxic, 0);
+       if (priv->rxcoalescing)
+               gfar_write(&regs->rxic, priv->rxic);
+
+       if (priv->rx_csum_enable)
+               rctrl |= RCTRL_CHECKSUMMING;
+
+       if (priv->extended_hash) {
+               rctrl |= RCTRL_EXTHASH;
+
+               gfar_clear_exact_match(ndev);
+               rctrl |= RCTRL_EMEN;
+       }
+
+       if (priv->padding) {
+               rctrl &= ~RCTRL_PAL_MASK;
+               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(&regs->rctrl, rctrl);
+
+       if (ndev->features & NETIF_F_IP_CSUM)
+               tctrl |= TCTRL_INIT_CSUM;
+
+       gfar_write(&regs->tctrl, tctrl);
+
+       /* Set the extraction length and index */
+       attrs = ATTRELI_EL(priv->rx_stash_size) |
+               ATTRELI_EI(priv->rx_stash_index);
+
+       gfar_write(&regs->attreli, attrs);
+
+       /* Start with defaults, and add stashing or locking
+        * depending on the approprate variables */
+       attrs = ATTR_INIT_SETTINGS;
+
+       if (priv->bd_stash_en)
+               attrs |= ATTR_BDSTASH;
+
+       if (priv->rx_stash_size != 0)
+               attrs |= ATTR_BUFSTASH;
+
+       gfar_write(&regs->attr, attrs);
+
+       gfar_write(&regs->fifo_tx_thr, priv->fifo_threshold);
+       gfar_write(&regs->fifo_tx_starve, priv->fifo_starve);
+       gfar_write(&regs->fifo_tx_starve_shutoff, priv->fifo_starve_off);
+}
+
+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 +373,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 +412,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 +465,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, BUS_ID_SIZE, 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, BUS_ID_SIZE, "%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;
 
@@ -296,6 +477,20 @@ err_out:
        return err;
 }
 
+/* Ioctl MII Interface */
+static int gfar_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
+{
+       struct gfar_private *priv = netdev_priv(dev);
+
+       if (!netif_running(dev))
+               return -EINVAL;
+
+       if (!priv->phydev)
+               return -ENODEV;
+
+       return phy_mii_ioctl(priv->phydev, if_mii(rq), cmd);
+}
+
 /* Set up the ethernet device structure, private data,
  * and anything else we need before we start */
 static int gfar_probe(struct of_device *ofdev,
@@ -304,7 +499,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;
 
@@ -315,8 +509,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);
 
@@ -337,6 +533,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);
 
@@ -352,19 +551,11 @@ 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;
 
        if (priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM) {
@@ -375,11 +566,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;
@@ -407,7 +595,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;
@@ -448,6 +636,9 @@ static int gfar_probe(struct of_device *ofdev,
                goto register_fail;
        }
 
+       device_init_wakeup(&dev->dev,
+               priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET);
+
        /* fill out IRQ number and name fields */
        len_devname = strlen(dev->name);
        strncpy(&priv->int_name_tx[0], dev->name, len_devname);
@@ -482,6 +673,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;
 }
@@ -490,32 +685,39 @@ 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;
 }
 
 #ifdef CONFIG_PM
-static int gfar_suspend(struct of_device *ofdev, pm_message_t state)
+
+static int gfar_suspend(struct device *dev)
 {
-       struct gfar_private *priv = dev_get_drvdata(&ofdev->dev);
-       struct net_device *dev = priv->dev;
+       struct gfar_private *priv = dev_get_drvdata(dev);
+       struct net_device *ndev = priv->ndev;
        unsigned long flags;
        u32 tempval;
 
        int magic_packet = priv->wol_en &&
                (priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET);
 
-       netif_device_detach(dev);
+       netif_device_detach(ndev);
 
-       if (netif_running(dev)) {
+       if (netif_running(ndev)) {
                spin_lock_irqsave(&priv->txlock, flags);
                spin_lock(&priv->rxlock);
 
-               gfar_halt_nodisable(dev);
+               gfar_halt_nodisable(ndev);
 
                /* Disable Tx, and Rx if wake-on-LAN is disabled. */
                tempval = gfar_read(&priv->regs->maccfg1);
@@ -548,17 +750,17 @@ static int gfar_suspend(struct of_device *ofdev, pm_message_t state)
        return 0;
 }
 
-static int gfar_resume(struct of_device *ofdev)
+static int gfar_resume(struct device *dev)
 {
-       struct gfar_private *priv = dev_get_drvdata(&ofdev->dev);
-       struct net_device *dev = priv->dev;
+       struct gfar_private *priv = dev_get_drvdata(dev);
+       struct net_device *ndev = priv->ndev;
        unsigned long flags;
        u32 tempval;
        int magic_packet = priv->wol_en &&
                (priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET);
 
-       if (!netif_running(dev)) {
-               netif_device_attach(dev);
+       if (!netif_running(ndev)) {
+               netif_device_attach(ndev);
                return 0;
        }
 
@@ -576,20 +778,71 @@ static int gfar_resume(struct of_device *ofdev)
        tempval &= ~MACCFG2_MPEN;
        gfar_write(&priv->regs->maccfg2, tempval);
 
-       gfar_start(dev);
+       gfar_start(ndev);
 
        spin_unlock(&priv->rxlock);
        spin_unlock_irqrestore(&priv->txlock, flags);
 
-       netif_device_attach(dev);
+       netif_device_attach(ndev);
+
+       napi_enable(&priv->napi);
+
+       return 0;
+}
+
+static int gfar_restore(struct device *dev)
+{
+       struct gfar_private *priv = dev_get_drvdata(dev);
+       struct net_device *ndev = priv->ndev;
+
+       if (!netif_running(ndev))
+               return 0;
+
+       gfar_init_bds(ndev);
+       init_registers(ndev);
+       gfar_set_mac_address(ndev);
+       gfar_init_mac(ndev);
+       gfar_start(ndev);
+
+       priv->oldlink = 0;
+       priv->oldspeed = 0;
+       priv->oldduplex = -1;
+
+       if (priv->phydev)
+               phy_start(priv->phydev);
 
+       netif_device_attach(ndev);
        napi_enable(&priv->napi);
 
        return 0;
 }
+
+static struct dev_pm_ops gfar_pm_ops = {
+       .suspend = gfar_suspend,
+       .resume = gfar_resume,
+       .freeze = gfar_suspend,
+       .thaw = gfar_resume,
+       .restore = gfar_restore,
+};
+
+#define GFAR_PM_OPS (&gfar_pm_ops)
+
+static int gfar_legacy_suspend(struct of_device *ofdev, pm_message_t state)
+{
+       return gfar_suspend(&ofdev->dev);
+}
+
+static int gfar_legacy_resume(struct of_device *ofdev)
+{
+       return gfar_resume(&ofdev->dev);
+}
+
 #else
-#define gfar_suspend NULL
-#define gfar_resume NULL
+
+#define GFAR_PM_OPS NULL
+#define gfar_legacy_suspend NULL
+#define gfar_legacy_resume NULL
+
 #endif
 
 /* Reads the controller's registers to determine what interface
@@ -643,7 +896,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;
@@ -652,21 +904,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;
 }
@@ -683,10 +936,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->tbi_node) {
+               dev_warn(&dev->dev, "error: SGMII mode requires that the "
+                                   "device tree specify a tbi-handle\n");
+               return;
+       }
 
-       if (!priv->tbiphy) {
-               printk(KERN_WARNING "SGMII mode requires that the device "
-                               "tree specify a tbi-handle\n");
+       tbiphy = of_phy_find_device(priv->tbi_node);
+       if (!tbiphy) {
+               dev_err(&dev->dev, "error: Could not get TBI device\n");
                return;
        }
 
@@ -696,17 +956,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);
 }
 
@@ -800,7 +1060,6 @@ void gfar_halt(struct net_device *dev)
 void stop_gfar(struct net_device *dev)
 {
        struct gfar_private *priv = netdev_priv(dev);
-       struct gfar __iomem *regs = priv->regs;
        unsigned long flags;
 
        phy_stop(priv->phydev);
@@ -820,22 +1079,17 @@ 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,
-                       sizeof(struct txbd8)*priv->tx_ring_size
-                       + sizeof(struct rxbd8)*priv->rx_ring_size,
-                       priv->tx_bd_base,
-                       gfar_read(&regs->tbase0));
 }
 
 /* If there are any tx skbs or rx skbs still around, free them.
  * Then free tx_skbuff and rx_skbuff */
 static void free_skb_resources(struct gfar_private *priv)
 {
+       struct device *dev = &priv->ofdev->dev;
        struct rxbd8 *rxbdp;
        struct txbd8 *txbdp;
        int i, j;
@@ -843,16 +1097,19 @@ static void free_skb_resources(struct gfar_private *priv)
        /* Go through all the buffer descriptors and free their data buffers */
        txbdp = priv->tx_bd_base;
 
+       if (!priv->tx_skbuff)
+               goto skip_tx_skbuff;
+
        for (i = 0; i < priv->tx_ring_size; i++) {
                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++;
@@ -861,30 +1118,33 @@ static void free_skb_resources(struct gfar_private *priv)
        }
 
        kfree(priv->tx_skbuff);
+skip_tx_skbuff:
 
        rxbdp = priv->rx_bd_base;
 
-       /* rx_skbuff is not guaranteed to be allocated, so only
-        * free it and its contents if it is allocated */
-       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,
-                                               priv->rx_buffer_size,
-                                               DMA_FROM_DEVICE);
-
-                               dev_kfree_skb_any(priv->rx_skbuff[i]);
-                               priv->rx_skbuff[i] = NULL;
-                       }
-
-                       rxbdp->lstatus = 0;
-                       rxbdp->bufPtr = 0;
+       if (!priv->rx_skbuff)
+               goto skip_rx_skbuff;
 
-                       rxbdp++;
+       for (i = 0; i < priv->rx_ring_size; i++) {
+               if (priv->rx_skbuff[i]) {
+                       dma_unmap_single(&priv->ofdev->dev, rxbdp->bufPtr,
+                                        priv->rx_buffer_size,
+                                       DMA_FROM_DEVICE);
+                       dev_kfree_skb_any(priv->rx_skbuff[i]);
+                       priv->rx_skbuff[i] = NULL;
                }
 
-               kfree(priv->rx_skbuff);
+               rxbdp->lstatus = 0;
+               rxbdp->bufPtr = 0;
+               rxbdp++;
        }
+
+       kfree(priv->rx_skbuff);
+skip_rx_skbuff:
+
+       dma_free_coherent(dev, sizeof(*txbdp) * priv->tx_ring_size +
+                              sizeof(*rxbdp) * priv->rx_ring_size,
+                         priv->tx_bd_base, priv->tx_bd_dma_base);
 }
 
 void gfar_start(struct net_device *dev)
@@ -919,240 +1179,75 @@ void gfar_start(struct net_device *dev)
 }
 
 /* Bring the controller up and running */
-int startup_gfar(struct net_device *dev)
+int startup_gfar(struct net_device *ndev)
 {
-       struct txbd8 *txbdp;
-       struct rxbd8 *rxbdp;
-       dma_addr_t addr = 0;
-       unsigned long vaddr;
-       int i;
-       struct gfar_private *priv = netdev_priv(dev);
+       struct gfar_private *priv = netdev_priv(ndev);
        struct gfar __iomem *regs = priv->regs;
-       int err = 0;
-       u32 rctrl = 0;
-       u32 attrs = 0;
+       int err;
 
        gfar_write(&regs->imask, IMASK_INIT_CLEAR);
 
-       /* Allocate memory for the buffer descriptors */
-       vaddr = (unsigned long) dma_alloc_coherent(&dev->dev,
-                       sizeof (struct txbd8) * priv->tx_ring_size +
-                       sizeof (struct rxbd8) * priv->rx_ring_size,
-                       &addr, GFP_KERNEL);
-
-       if (vaddr == 0) {
-               if (netif_msg_ifup(priv))
-                       printk(KERN_ERR "%s: Could not allocate buffer descriptors!\n",
-                                       dev->name);
-               return -ENOMEM;
-       }
-
-       priv->tx_bd_base = (struct txbd8 *) vaddr;
-
-       /* enet DMA only understands physical addresses */
-       gfar_write(&regs->tbase0, addr);
-
-       /* Start the rx descriptor ring where the tx ring leaves off */
-       addr = addr + sizeof (struct txbd8) * priv->tx_ring_size;
-       vaddr = vaddr + sizeof (struct txbd8) * priv->tx_ring_size;
-       priv->rx_bd_base = (struct rxbd8 *) vaddr;
-       gfar_write(&regs->rbase0, addr);
-
-       /* Setup the skbuff rings */
-       priv->tx_skbuff =
-           (struct sk_buff **) kmalloc(sizeof (struct sk_buff *) *
-                                       priv->tx_ring_size, GFP_KERNEL);
-
-       if (NULL == priv->tx_skbuff) {
-               if (netif_msg_ifup(priv))
-                       printk(KERN_ERR "%s: Could not allocate tx_skbuff\n",
-                                       dev->name);
-               err = -ENOMEM;
-               goto tx_skb_fail;
-       }
-
-       for (i = 0; i < priv->tx_ring_size; i++)
-               priv->tx_skbuff[i] = NULL;
-
-       priv->rx_skbuff =
-           (struct sk_buff **) kmalloc(sizeof (struct sk_buff *) *
-                                       priv->rx_ring_size, GFP_KERNEL);
-
-       if (NULL == priv->rx_skbuff) {
-               if (netif_msg_ifup(priv))
-                       printk(KERN_ERR "%s: Could not allocate rx_skbuff\n",
-                                       dev->name);
-               err = -ENOMEM;
-               goto rx_skb_fail;
-       }
-
-       for (i = 0; i < priv->rx_ring_size; i++)
-               priv->rx_skbuff[i] = NULL;
-
-       /* Initialize some variables in our dev structure */
-       priv->num_txbdfree = priv->tx_ring_size;
-       priv->dirty_tx = priv->cur_tx = priv->tx_bd_base;
-       priv->cur_rx = priv->rx_bd_base;
-       priv->skb_curtx = priv->skb_dirtytx = 0;
-       priv->skb_currx = 0;
-
-       /* Initialize Transmit Descriptor Ring */
-       txbdp = priv->tx_bd_base;
-       for (i = 0; i < priv->tx_ring_size; i++) {
-               txbdp->lstatus = 0;
-               txbdp->bufPtr = 0;
-               txbdp++;
-       }
-
-       /* Set the last descriptor in the ring to indicate wrap */
-       txbdp--;
-       txbdp->status |= TXBD_WRAP;
-
-       rxbdp = priv->rx_bd_base;
-       for (i = 0; i < priv->rx_ring_size; i++) {
-               struct sk_buff *skb;
-
-               skb = gfar_new_skb(dev);
-
-               if (!skb) {
-                       printk(KERN_ERR "%s: Can't allocate RX buffers\n",
-                                       dev->name);
-
-                       goto err_rxalloc_fail;
-               }
-
-               priv->rx_skbuff[i] = skb;
-
-               gfar_new_rxbdp(dev, rxbdp, skb);
-
-               rxbdp++;
-       }
+       err = gfar_alloc_skb_resources(ndev);
+       if (err)
+               return err;
 
-       /* Set the last descriptor in the ring to wrap */
-       rxbdp--;
-       rxbdp->status |= RXBD_WRAP;
+       gfar_init_mac(ndev);
 
        /* If the device has multiple interrupts, register for
         * them.  Otherwise, only register for the one */
        if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
                /* Install our interrupt handlers for Error,
                 * Transmit, and Receive */
-               if (request_irq(priv->interruptError, gfar_error,
-                               0, priv->int_name_er, dev) < 0) {
+               err = request_irq(priv->interruptError, gfar_error, 0,
+                                 priv->int_name_er, ndev);
+               if (err) {
                        if (netif_msg_intr(priv))
-                               printk(KERN_ERR "%s: Can't get IRQ %d\n",
-                                       dev->name, priv->interruptError);
-
-                       err = -1;
+                               pr_err("%s: Can't get IRQ %d\n", ndev->name,
+                                      priv->interruptError);
                        goto err_irq_fail;
                }
 
-               if (request_irq(priv->interruptTransmit, gfar_transmit,
-                               0, priv->int_name_tx, dev) < 0) {
+               err = request_irq(priv->interruptTransmit, gfar_transmit, 0,
+                                 priv->int_name_tx, ndev);
+               if (err) {
                        if (netif_msg_intr(priv))
-                               printk(KERN_ERR "%s: Can't get IRQ %d\n",
-                                       dev->name, priv->interruptTransmit);
-
-                       err = -1;
-
+                               pr_err("%s: Can't get IRQ %d\n", ndev->name,
+                                      priv->interruptTransmit);
                        goto tx_irq_fail;
                }
 
-               if (request_irq(priv->interruptReceive, gfar_receive,
-                               0, priv->int_name_rx, dev) < 0) {
+               err = request_irq(priv->interruptReceive, gfar_receive, 0,
+                                 priv->int_name_rx, ndev);
+               if (err) {
                        if (netif_msg_intr(priv))
-                               printk(KERN_ERR "%s: Can't get IRQ %d (receive0)\n",
-                                               dev->name, priv->interruptReceive);
-
-                       err = -1;
+                               pr_err("%s: Can't get IRQ %d (receive0)\n",
+                                      ndev->name, priv->interruptReceive);
                        goto rx_irq_fail;
                }
        } else {
-               if (request_irq(priv->interruptTransmit, gfar_interrupt,
-                               0, priv->int_name_tx, dev) < 0) {
+               err = request_irq(priv->interruptTransmit, gfar_interrupt,
+                               0, priv->int_name_tx, ndev);
+               if (err) {
                        if (netif_msg_intr(priv))
-                               printk(KERN_ERR "%s: Can't get IRQ %d\n",
-                                       dev->name, priv->interruptTransmit);
-
-                       err = -1;
+                               pr_err("%s: Can't get IRQ %d\n", ndev->name,
+                                      priv->interruptTransmit);
                        goto err_irq_fail;
                }
        }
 
-       phy_start(priv->phydev);
-
-       /* Configure the coalescing support */
-       gfar_write(&regs->txic, 0);
-       if (priv->txcoalescing)
-               gfar_write(&regs->txic, priv->txic);
-
-       gfar_write(&regs->rxic, 0);
-       if (priv->rxcoalescing)
-               gfar_write(&regs->rxic, priv->rxic);
-
-       if (priv->rx_csum_enable)
-               rctrl |= RCTRL_CHECKSUMMING;
-
-       if (priv->extended_hash) {
-               rctrl |= RCTRL_EXTHASH;
-
-               gfar_clear_exact_match(dev);
-               rctrl |= RCTRL_EMEN;
-       }
-
-       if (priv->padding) {
-               rctrl &= ~RCTRL_PAL_MASK;
-               rctrl |= RCTRL_PADDING(priv->padding);
-       }
-
-       /* 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);
-
-       /* Set the extraction length and index */
-       attrs = ATTRELI_EL(priv->rx_stash_size) |
-               ATTRELI_EI(priv->rx_stash_index);
-
-       gfar_write(&priv->regs->attreli, attrs);
-
-       /* Start with defaults, and add stashing or locking
-        * depending on the approprate variables */
-       attrs = ATTR_INIT_SETTINGS;
-
-       if (priv->bd_stash_en)
-               attrs |= ATTR_BDSTASH;
-
-       if (priv->rx_stash_size != 0)
-               attrs |= ATTR_BUFSTASH;
-
-       gfar_write(&priv->regs->attr, attrs);
-
-       gfar_write(&priv->regs->fifo_tx_thr, priv->fifo_threshold);
-       gfar_write(&priv->regs->fifo_tx_starve, priv->fifo_starve);
-       gfar_write(&priv->regs->fifo_tx_starve_shutoff, priv->fifo_starve_off);
-
        /* Start the controller */
-       gfar_start(dev);
+       gfar_start(ndev);
+
+       phy_start(priv->phydev);
 
        return 0;
 
 rx_irq_fail:
-       free_irq(priv->interruptTransmit, dev);
+       free_irq(priv->interruptTransmit, ndev);
 tx_irq_fail:
-       free_irq(priv->interruptError, dev);
+       free_irq(priv->interruptError, ndev);
 err_irq_fail:
-err_rxalloc_fail:
-rx_skb_fail:
        free_skb_resources(priv);
-tx_skb_fail:
-       dma_free_coherent(&dev->dev,
-                       sizeof(struct txbd8)*priv->tx_ring_size
-                       + sizeof(struct rxbd8)*priv->rx_ring_size,
-                       priv->tx_bd_base,
-                       gfar_read(&regs->tbase0));
-
        return err;
 }
 
@@ -1165,6 +1260,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);
 
@@ -1185,14 +1282,16 @@ static int gfar_enet_open(struct net_device *dev)
 
        netif_start_queue(dev);
 
+       device_set_wakeup_enable(&dev->dev, priv->wol_en);
+
        return err;
 }
 
 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;
 }
@@ -1260,13 +1359,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++;
@@ -1296,7 +1411,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,
@@ -1328,7 +1443,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);
@@ -1371,7 +1486,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 */
@@ -1381,6 +1496,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);
 
@@ -1408,15 +1524,11 @@ static void gfar_vlan_rx_register(struct net_device *dev,
 {
        struct gfar_private *priv = netdev_priv(dev);
        unsigned long flags;
-       struct vlan_group *old_grp;
        u32 tempval;
 
        spin_lock_irqsave(&priv->rxlock, flags);
 
-       old_grp = priv->vlgrp;
-
-       if (old_grp == grp)
-               return;
+       priv->vlgrp = grp;
 
        if (grp) {
                /* Enable VLAN tag insertion */
@@ -1427,7 +1539,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 {
@@ -1517,11 +1628,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);
@@ -1564,7 +1677,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);
@@ -1573,7 +1686,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);
@@ -1581,7 +1694,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) &
@@ -1607,10 +1730,24 @@ static int gfar_clean_tx_ring(struct net_device *dev)
 static void gfar_schedule_cleanup(struct net_device *dev)
 {
        struct gfar_private *priv = netdev_priv(dev);
-       if (netif_rx_schedule_prep(&priv->napi)) {
+       unsigned long flags;
+
+       spin_lock_irqsave(&priv->txlock, flags);
+       spin_lock(&priv->rxlock);
+
+       if (napi_schedule_prep(&priv->napi)) {
                gfar_write(&priv->regs->imask, IMASK_RTX_DISABLED);
-               __netif_rx_schedule(&priv->napi);
+               __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);
+       spin_unlock_irqrestore(&priv->txlock, flags);
 }
 
 /* Interrupt Handler for Transmit complete */
@@ -1624,19 +1761,11 @@ static void gfar_new_rxbdp(struct net_device *dev, struct rxbd8 *bdp,
                struct sk_buff *skb)
 {
        struct gfar_private *priv = netdev_priv(dev);
-       u32 lstatus;
-
-       bdp->bufPtr = dma_map_single(&dev->dev, skb->data,
-                       priv->rx_buffer_size, DMA_FROM_DEVICE);
+       dma_addr_t buf;
 
-       lstatus = BD_LFLAG(RXBD_EMPTY | RXBD_INTERRUPT);
-
-       if (bdp == priv->rx_bd_base + priv->rx_ring_size - 1)
-               lstatus |= BD_LFLAG(RXBD_WRAP);
-
-       eieio();
-
-       bdp->lstatus = lstatus;
+       buf = dma_map_single(&priv->ofdev->dev, skb->data,
+                            priv->rx_buffer_size, DMA_FROM_DEVICE);
+       gfar_init_rxbdp(dev, bdp, buf);
 }
 
 
@@ -1646,8 +1775,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;
@@ -1784,7 +1915,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 */
@@ -1794,8 +1925,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++;
@@ -1807,6 +1947,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 {
@@ -1842,7 +1984,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;
@@ -1863,7 +2005,7 @@ static int gfar_poll(struct napi_struct *napi, int budget)
                return budget;
 
        if (rx_cleaned < budget) {
-               netif_rx_complete(napi);
+               napi_complete(napi);
 
                /* Clear the halt bit in RSTAT */
                gfar_write(&priv->regs->rstat, RSTAT_CLEAR_RHALT);
@@ -2255,9 +2397,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[] =
 {
        {
@@ -2266,6 +2405,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 = {
@@ -2274,29 +2414,19 @@ static struct of_platform_driver gfar_driver = {
 
        .probe = gfar_probe,
        .remove = gfar_remove,
-       .suspend = gfar_suspend,
-       .resume = gfar_resume,
+       .suspend = gfar_legacy_suspend,
+       .resume = gfar_legacy_resume,
+       .driver.pm = GFAR_PM_OPS,
 };
 
 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);