Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/bart/ide-2.6
[safe/jmp/linux-2.6] / drivers / net / fec.c
index bd6983d..682e7f0 100644 (file)
@@ -2,12 +2,6 @@
  * Fast Ethernet Controller (FEC) driver for Motorola MPC8xx.
  * Copyright (c) 1997 Dan Malek (dmalek@jlc.net)
  *
- * This version of the driver is specific to the FADS implementation,
- * since the board contains control registers external to the processor
- * for the control of the LevelOne LXT970 transceiver.  The MPC860T manual
- * describes connections using the internal parallel port I/O, which
- * is basically all of Port D.
- *
  * Right now, I am very wasteful with the buffers.  I allocate memory
  * pages and then divide them into 2K frame buffers.  This way I know I
  * have buffers large enough to hold one frame within one buffer descriptor.
  * Copyright (c) 2001-2005 Greg Ungerer (gerg@snapgear.com)
  *
  * Bug fixes and cleanup by Philippe De Muyter (phdm@macqel.be)
- * Copyright (c) 2004-2005 Macq Electronique SA.
+ * Copyright (c) 2004-2006 Macq Electronique SA.
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/string.h>
 #include <linux/spinlock.h>
 #include <linux/workqueue.h>
 #include <linux/bitops.h>
+#include <linux/io.h>
+#include <linux/irq.h>
+#include <linux/clk.h>
+#include <linux/platform_device.h>
 
-#include <asm/irq.h>
-#include <asm/uaccess.h>
-#include <asm/io.h>
-#include <asm/pgtable.h>
+#include <asm/cacheflush.h>
 
-#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || \
-    defined(CONFIG_M5272) || defined(CONFIG_M528x) || \
-    defined(CONFIG_M520x)
+#ifndef CONFIG_ARCH_MXC
 #include <asm/coldfire.h>
 #include <asm/mcfsim.h>
-#include "fec.h"
-#else
-#include <asm/8xx_immap.h>
-#include <asm/mpc8xx.h>
-#include "commproc.h"
 #endif
 
-#if defined(CONFIG_FEC2)
-#define        FEC_MAX_PORTS   2
+#include "fec.h"
+
+#ifdef CONFIG_ARCH_MXC
+#include <mach/hardware.h>
+#define FEC_ALIGNMENT  0xf
 #else
-#define        FEC_MAX_PORTS   1
+#define FEC_ALIGNMENT  0x3
 #endif
 
 /*
  * Define the fixed address of the FEC hardware.
  */
-static unsigned int fec_hw[] = {
 #if defined(CONFIG_M5272)
-       (MCF_MBAR + 0x840),
-#elif defined(CONFIG_M527x)
-       (MCF_MBAR + 0x1000),
-       (MCF_MBAR + 0x1800),
-#elif defined(CONFIG_M523x) || defined(CONFIG_M528x)
-       (MCF_MBAR + 0x1000),
-#elif defined(CONFIG_M520x)
-       (MCF_MBAR+0x30000),
-#else
-       &(((immap_t *)IMAP_ADDR)->im_cpm.cp_fec),
-#endif
-};
+#define HAVE_mii_link_interrupt
 
 static unsigned char   fec_mac_default[] = {
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -97,8 +75,6 @@ static unsigned char  fec_mac_default[] = {
 #define        FEC_FLASHMAC    0xf0006006
 #elif defined(CONFIG_GILBARCONAP) || defined(CONFIG_SCALES)
 #define        FEC_FLASHMAC    0xf0006000
-#elif defined (CONFIG_MTD_KeyTechnology)
-#define        FEC_FLASHMAC    0xffe04000
 #elif defined(CONFIG_CANCam)
 #define        FEC_FLASHMAC    0xf0020000
 #elif defined (CONFIG_M5272C3)
@@ -108,6 +84,7 @@ static unsigned char fec_mac_default[] = {
 #else
 #define        FEC_FLASHMAC    0
 #endif
+#endif /* CONFIG_M5272 */
 
 /* Forward declarations of some structures to support different PHYs
 */
@@ -143,7 +120,7 @@ typedef struct {
 #define TX_RING_MOD_MASK       15      /*   for this to work */
 
 #if (((RX_RING_SIZE + TX_RING_SIZE) * 8) > PAGE_SIZE)
-#error "FEC: descriptor ring size contants too large"
+#error "FEC: descriptor ring size constants too large"
 #endif
 
 /* Interrupt events/masks.
@@ -167,12 +144,12 @@ typedef struct {
 
 
 /*
- * The 5270/5271/5280/5282 RX control register also contains maximum frame
+ * The 5270/5271/5280/5282/532x RX control register also contains maximum frame
  * size bits. Other FEC hardware does not, so we need to take that into
  * account when setting it.
  */
 #if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
-    defined(CONFIG_M520x)
+    defined(CONFIG_M520x) || defined(CONFIG_M532x) || defined(CONFIG_ARCH_MXC)
 #define        OPT_FRAME_SIZE  (PKT_MAXBUF_SIZE << 16)
 #else
 #define        OPT_FRAME_SIZE  0
@@ -190,6 +167,10 @@ struct fec_enet_private {
        /* Hardware registers of the FEC device */
        volatile fec_t  *hwp;
 
+       struct net_device *netdev;
+
+       struct clk *clk;
+
        /* The saved address of a sent-in-place packet/buffer, for skfree(). */
        unsigned char *tx_bounce[TX_RING_SIZE];
        struct  sk_buff* tx_skbuff[TX_RING_SIZE];
@@ -198,13 +179,16 @@ struct fec_enet_private {
 
        /* CPM dual port RAM relative addresses.
        */
+       dma_addr_t      bd_dma;
        cbd_t   *rx_bd_base;            /* Address of Rx and Tx buffers. */
        cbd_t   *tx_bd_base;
        cbd_t   *cur_rx, *cur_tx;               /* The next free ring entry */
        cbd_t   *dirty_tx;      /* The ring entries to be free()ed. */
-       struct  net_device_stats stats;
        uint    tx_full;
-       spinlock_t lock;
+       /* hold while accessing the HW like ringbuffer for tx/rx but not MAC */
+       spinlock_t hw_lock;
+       /* hold while accessing the mii_list_t() elements */
+       spinlock_t mii_lock;
 
        uint    phy_id;
        uint    phy_id_done;
@@ -228,11 +212,10 @@ struct fec_enet_private {
 static int fec_enet_open(struct net_device *dev);
 static int fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev);
 static void fec_enet_mii(struct net_device *dev);
-static irqreturn_t fec_enet_interrupt(int irq, void * dev_id, struct pt_regs * regs);
+static irqreturn_t fec_enet_interrupt(int irq, void * dev_id);
 static void fec_enet_tx(struct net_device *dev);
 static void fec_enet_rx(struct net_device *dev);
 static int fec_enet_close(struct net_device *dev);
-static struct net_device_stats *fec_enet_get_stats(struct net_device *dev);
 static void set_multicast_list(struct net_device *dev);
 static void fec_restart(struct net_device *dev, int duplex);
 static void fec_stop(struct net_device *dev);
@@ -255,7 +238,7 @@ static mii_list_t   *mii_free;
 static mii_list_t      *mii_head;
 static mii_list_t      *mii_tail;
 
-static int     mii_queue(struct net_device *dev, int request, 
+static int     mii_queue(struct net_device *dev, int request,
                                void (*func)(uint, struct net_device *));
 
 /* Make MII read/write commands for the FEC.
@@ -276,7 +259,7 @@ static int  mii_queue(struct net_device *dev, int request,
 #define MII_REG_SR          1  /* Status Register                          */
 #define MII_REG_PHYIR1      2  /* PHY Identification Register 1            */
 #define MII_REG_PHYIR2      3  /* PHY Identification Register 2            */
-#define MII_REG_ANAR        4  /* A-N Advertisement Register               */ 
+#define MII_REG_ANAR        4  /* A-N Advertisement Register               */
 #define MII_REG_ANLPAR      5  /* A-N Link Partner Ability Register        */
 #define MII_REG_ANER        6  /* A-N Expansion Register                   */
 #define MII_REG_ANNPTR      7  /* A-N Next Page Transmit Register          */
@@ -288,18 +271,18 @@ static int        mii_queue(struct net_device *dev, int request,
 #define PHY_CONF_LOOP  0x0002  /* 1 loopback mode enabled */
 #define PHY_CONF_SPMASK        0x00f0  /* mask for speed */
 #define PHY_CONF_10HDX 0x0010  /* 10 Mbit half duplex supported */
-#define PHY_CONF_10FDX 0x0020  /* 10 Mbit full duplex supported */ 
+#define PHY_CONF_10FDX 0x0020  /* 10 Mbit full duplex supported */
 #define PHY_CONF_100HDX        0x0040  /* 100 Mbit half duplex supported */
-#define PHY_CONF_100FDX        0x0080  /* 100 Mbit full duplex supported */ 
+#define PHY_CONF_100FDX        0x0080  /* 100 Mbit full duplex supported */
 
 #define PHY_STAT_LINK  0x0100  /* 1 up - 0 down */
 #define PHY_STAT_FAULT 0x0200  /* 1 remote fault */
 #define PHY_STAT_ANC   0x0400  /* 1 auto-negotiation complete  */
 #define PHY_STAT_SPMASK        0xf000  /* mask for speed */
 #define PHY_STAT_10HDX 0x1000  /* 10 Mbit half duplex selected */
-#define PHY_STAT_10FDX 0x2000  /* 10 Mbit full duplex selected */ 
+#define PHY_STAT_10FDX 0x2000  /* 10 Mbit full duplex selected */
 #define PHY_STAT_100HDX        0x4000  /* 100 Mbit half duplex selected */
-#define PHY_STAT_100FDX        0x8000  /* 100 Mbit full duplex selected */ 
+#define PHY_STAT_100FDX        0x8000  /* 100 Mbit full duplex selected */
 
 
 static int
@@ -308,6 +291,8 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
        struct fec_enet_private *fep;
        volatile fec_t  *fecp;
        volatile cbd_t  *bdp;
+       unsigned short  status;
+       unsigned long flags;
 
        fep = netdev_priv(dev);
        fecp = (volatile fec_t*)dev->base_addr;
@@ -317,22 +302,25 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
                return 1;
        }
 
+       spin_lock_irqsave(&fep->hw_lock, flags);
        /* Fill in a Tx ring entry */
        bdp = fep->cur_tx;
 
+       status = bdp->cbd_sc;
 #ifndef final_version
-       if (bdp->cbd_sc & BD_ENET_TX_READY) {
+       if (status & BD_ENET_TX_READY) {
                /* Ooops.  All transmit buffers are full.  Bail out.
                 * This should not happen, since dev->tbusy should be set.
                 */
                printk("%s: tx queue full!.\n", dev->name);
+               spin_unlock_irqrestore(&fep->hw_lock, flags);
                return 1;
        }
 #endif
 
        /* Clear all of the status flags.
         */
-       bdp->cbd_sc &= ~BD_ENET_TX_STATS;
+       status &= ~BD_ENET_TX_STATS;
 
        /* Set buffer length and buffer pointer.
        */
@@ -344,10 +332,10 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
         *      4-byte boundaries. Use bounce buffers to copy data
         *      and get it aligned. Ugh.
         */
-       if (bdp->cbd_bufaddr & 0x3) {
+       if (bdp->cbd_bufaddr & FEC_ALIGNMENT) {
                unsigned int index;
                index = bdp - fep->tx_bd_base;
-               memcpy(fep->tx_bounce[index], (void *) bdp->cbd_bufaddr, bdp->cbd_datlen);
+               memcpy(fep->tx_bounce[index], (void *)skb->data, skb->len);
                bdp->cbd_bufaddr = __pa(fep->tx_bounce[index]);
        }
 
@@ -355,32 +343,31 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
        */
        fep->tx_skbuff[fep->skb_cur] = skb;
 
-       fep->stats.tx_bytes += skb->len;
+       dev->stats.tx_bytes += skb->len;
        fep->skb_cur = (fep->skb_cur+1) & TX_RING_MOD_MASK;
-       
+
        /* Push the data cache so the CPM does not get stale memory
         * data.
         */
-       flush_dcache_range((unsigned long)skb->data,
-                          (unsigned long)skb->data + skb->len);
+       dma_sync_single(NULL, bdp->cbd_bufaddr,
+                       bdp->cbd_datlen, DMA_TO_DEVICE);
 
-       spin_lock_irq(&fep->lock);
-
-       /* Send it on its way.  Tell FEC its ready, interrupt when done,
-        * its the last BD of the frame, and to put the CRC on the end.
+       /* Send it on its way.  Tell FEC it's ready, interrupt when done,
+        * it's the last BD of the frame, and to put the CRC on the end.
         */
 
-       bdp->cbd_sc |= (BD_ENET_TX_READY | BD_ENET_TX_INTR
+       status |= (BD_ENET_TX_READY | BD_ENET_TX_INTR
                        | BD_ENET_TX_LAST | BD_ENET_TX_TC);
+       bdp->cbd_sc = status;
 
        dev->trans_start = jiffies;
 
        /* Trigger transmission start */
-       fecp->fec_x_des_active = 0x01000000;
+       fecp->fec_x_des_active = 0;
 
        /* If this was the last BD in the ring, start at the beginning again.
        */
-       if (bdp->cbd_sc & BD_ENET_TX_WRAP) {
+       if (status & BD_ENET_TX_WRAP) {
                bdp = fep->tx_bd_base;
        } else {
                bdp++;
@@ -393,7 +380,7 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
        fep->cur_tx = (cbd_t *)bdp;
 
-       spin_unlock_irq(&fep->lock);
+       spin_unlock_irqrestore(&fep->hw_lock, flags);
 
        return 0;
 }
@@ -404,7 +391,7 @@ fec_timeout(struct net_device *dev)
        struct fec_enet_private *fep = netdev_priv(dev);
 
        printk("%s: transmit timed out.\n", dev->name);
-       fep->stats.tx_errors++;
+       dev->stats.tx_errors++;
 #ifndef final_version
        {
        int     i;
@@ -418,7 +405,7 @@ fec_timeout(struct net_device *dev)
        bdp = fep->tx_bd_base;
        printk(" tx: %u buffers\n",  TX_RING_SIZE);
        for (i = 0 ; i < TX_RING_SIZE; i++) {
-               printk("  %08x: %04x %04x %08x\n", 
+               printk("  %08x: %04x %04x %08x\n",
                       (uint) bdp,
                       bdp->cbd_sc,
                       bdp->cbd_datlen,
@@ -446,24 +433,25 @@ fec_timeout(struct net_device *dev)
  * This is called from the MPC core interrupt.
  */
 static irqreturn_t
-fec_enet_interrupt(int irq, void * dev_id, struct pt_regs * regs)
+fec_enet_interrupt(int irq, void * dev_id)
 {
        struct  net_device *dev = dev_id;
        volatile fec_t  *fecp;
        uint    int_events;
-       int handled = 0;
+       irqreturn_t ret = IRQ_NONE;
 
        fecp = (volatile fec_t*)dev->base_addr;
 
        /* Get the interrupt events that caused us to be here.
        */
-       while ((int_events = fecp->fec_ievent) != 0) {
+       do {
+               int_events = fecp->fec_ievent;
                fecp->fec_ievent = int_events;
 
                /* Handle receive event in its own function.
                 */
                if (int_events & FEC_ENET_RXF) {
-                       handled = 1;
+                       ret = IRQ_HANDLED;
                        fec_enet_rx(dev);
                }
 
@@ -472,17 +460,18 @@ fec_enet_interrupt(int irq, void * dev_id, struct pt_regs * regs)
                   them as part of the transmit process.
                */
                if (int_events & FEC_ENET_TXF) {
-                       handled = 1;
+                       ret = IRQ_HANDLED;
                        fec_enet_tx(dev);
                }
 
                if (int_events & FEC_ENET_MII) {
-                       handled = 1;
+                       ret = IRQ_HANDLED;
                        fec_enet_mii(dev);
                }
-       
-       }
-       return IRQ_RETVAL(handled);
+
+       } while (int_events);
+
+       return ret;
 }
 
 
@@ -491,58 +480,59 @@ fec_enet_tx(struct net_device *dev)
 {
        struct  fec_enet_private *fep;
        volatile cbd_t  *bdp;
+       unsigned short status;
        struct  sk_buff *skb;
 
        fep = netdev_priv(dev);
-       spin_lock(&fep->lock);
+       spin_lock_irq(&fep->hw_lock);
        bdp = fep->dirty_tx;
 
-       while ((bdp->cbd_sc&BD_ENET_TX_READY) == 0) {
+       while (((status = bdp->cbd_sc) & BD_ENET_TX_READY) == 0) {
                if (bdp == fep->cur_tx && fep->tx_full == 0) break;
 
                skb = fep->tx_skbuff[fep->skb_dirty];
                /* Check for errors. */
-               if (bdp->cbd_sc & (BD_ENET_TX_HB | BD_ENET_TX_LC |
+               if (status & (BD_ENET_TX_HB | BD_ENET_TX_LC |
                                   BD_ENET_TX_RL | BD_ENET_TX_UN |
                                   BD_ENET_TX_CSL)) {
-                       fep->stats.tx_errors++;
-                       if (bdp->cbd_sc & BD_ENET_TX_HB)  /* No heartbeat */
-                               fep->stats.tx_heartbeat_errors++;
-                       if (bdp->cbd_sc & BD_ENET_TX_LC)  /* Late collision */
-                               fep->stats.tx_window_errors++;
-                       if (bdp->cbd_sc & BD_ENET_TX_RL)  /* Retrans limit */
-                               fep->stats.tx_aborted_errors++;
-                       if (bdp->cbd_sc & BD_ENET_TX_UN)  /* Underrun */
-                               fep->stats.tx_fifo_errors++;
-                       if (bdp->cbd_sc & BD_ENET_TX_CSL) /* Carrier lost */
-                               fep->stats.tx_carrier_errors++;
+                       dev->stats.tx_errors++;
+                       if (status & BD_ENET_TX_HB)  /* No heartbeat */
+                               dev->stats.tx_heartbeat_errors++;
+                       if (status & BD_ENET_TX_LC)  /* Late collision */
+                               dev->stats.tx_window_errors++;
+                       if (status & BD_ENET_TX_RL)  /* Retrans limit */
+                               dev->stats.tx_aborted_errors++;
+                       if (status & BD_ENET_TX_UN)  /* Underrun */
+                               dev->stats.tx_fifo_errors++;
+                       if (status & BD_ENET_TX_CSL) /* Carrier lost */
+                               dev->stats.tx_carrier_errors++;
                } else {
-                       fep->stats.tx_packets++;
+                       dev->stats.tx_packets++;
                }
 
 #ifndef final_version
-               if (bdp->cbd_sc & BD_ENET_TX_READY)
+               if (status & BD_ENET_TX_READY)
                        printk("HEY! Enet xmit interrupt and TX_READY.\n");
 #endif
                /* Deferred means some collisions occurred during transmit,
                 * but we eventually sent the packet OK.
                 */
-               if (bdp->cbd_sc & BD_ENET_TX_DEF)
-                       fep->stats.collisions++;
-           
+               if (status & BD_ENET_TX_DEF)
+                       dev->stats.collisions++;
+
                /* Free the sk buffer associated with this last transmit.
                 */
                dev_kfree_skb_any(skb);
                fep->tx_skbuff[fep->skb_dirty] = NULL;
                fep->skb_dirty = (fep->skb_dirty + 1) & TX_RING_MOD_MASK;
-           
+
                /* Update pointer to next buffer descriptor to be transmitted.
                 */
-               if (bdp->cbd_sc & BD_ENET_TX_WRAP)
+               if (status & BD_ENET_TX_WRAP)
                        bdp = fep->tx_bd_base;
                else
                        bdp++;
-           
+
                /* Since we have freed up a buffer, the ring is no longer
                 * full.
                 */
@@ -553,7 +543,7 @@ fec_enet_tx(struct net_device *dev)
                }
        }
        fep->dirty_tx = (cbd_t *)bdp;
-       spin_unlock(&fep->lock);
+       spin_unlock_irq(&fep->hw_lock);
 }
 
 
@@ -568,25 +558,32 @@ fec_enet_rx(struct net_device *dev)
        struct  fec_enet_private *fep;
        volatile fec_t  *fecp;
        volatile cbd_t *bdp;
+       unsigned short status;
        struct  sk_buff *skb;
        ushort  pkt_len;
        __u8 *data;
 
+#ifdef CONFIG_M532x
+       flush_cache_all();
+#endif
+
        fep = netdev_priv(dev);
        fecp = (volatile fec_t*)dev->base_addr;
 
+       spin_lock_irq(&fep->hw_lock);
+
        /* First, grab all of the stats for the incoming packet.
         * These get messed up if we get called due to a busy condition.
         */
        bdp = fep->cur_rx;
 
-while (!(bdp->cbd_sc & BD_ENET_RX_EMPTY)) {
+while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) {
 
 #ifndef final_version
        /* Since we have allocated space to hold a complete frame,
         * the last indicator should be set.
         */
-       if ((bdp->cbd_sc & BD_ENET_RX_LAST) == 0)
+       if ((status & BD_ENET_RX_LAST) == 0)
                printk("FEC ENET: rcv is not +last\n");
 #endif
 
@@ -594,38 +591,41 @@ while (!(bdp->cbd_sc & BD_ENET_RX_EMPTY)) {
                goto rx_processing_done;
 
        /* Check for errors. */
-       if (bdp->cbd_sc & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO |
+       if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH | BD_ENET_RX_NO |
                           BD_ENET_RX_CR | BD_ENET_RX_OV)) {
-               fep->stats.rx_errors++;       
-               if (bdp->cbd_sc & (BD_ENET_RX_LG | BD_ENET_RX_SH)) {
+               dev->stats.rx_errors++;
+               if (status & (BD_ENET_RX_LG | BD_ENET_RX_SH)) {
                /* Frame too long or too short. */
-                       fep->stats.rx_length_errors++;
+                       dev->stats.rx_length_errors++;
                }
-               if (bdp->cbd_sc & BD_ENET_RX_NO)        /* Frame alignment */
-                       fep->stats.rx_frame_errors++;
-               if (bdp->cbd_sc & BD_ENET_RX_CR)        /* CRC Error */
-                       fep->stats.rx_crc_errors++;
-               if (bdp->cbd_sc & BD_ENET_RX_OV)        /* FIFO overrun */
-                       fep->stats.rx_crc_errors++;
+               if (status & BD_ENET_RX_NO)     /* Frame alignment */
+                       dev->stats.rx_frame_errors++;
+               if (status & BD_ENET_RX_CR)     /* CRC Error */
+                       dev->stats.rx_crc_errors++;
+               if (status & BD_ENET_RX_OV)     /* FIFO overrun */
+                       dev->stats.rx_fifo_errors++;
        }
 
        /* Report late collisions as a frame error.
         * On this error, the BD is closed, but we don't know what we
         * have in the buffer.  So, just drop this frame on the floor.
         */
-       if (bdp->cbd_sc & BD_ENET_RX_CL) {
-               fep->stats.rx_errors++;
-               fep->stats.rx_frame_errors++;
+       if (status & BD_ENET_RX_CL) {
+               dev->stats.rx_errors++;
+               dev->stats.rx_frame_errors++;
                goto rx_processing_done;
        }
 
        /* Process the incoming frame.
         */
-       fep->stats.rx_packets++;
+       dev->stats.rx_packets++;
        pkt_len = bdp->cbd_datlen;
-       fep->stats.rx_bytes += pkt_len;
+       dev->stats.rx_bytes += pkt_len;
        data = (__u8*)__va(bdp->cbd_bufaddr);
 
+       dma_sync_single(NULL, (unsigned long)__pa(data),
+                       pkt_len - 4, DMA_FROM_DEVICE);
+
        /* This does 16 byte alignment, exactly what we need.
         * The packet length includes FCS, but we don't want to
         * include that when passing upstream as it messes up
@@ -635,13 +635,10 @@ while (!(bdp->cbd_sc & BD_ENET_RX_EMPTY)) {
 
        if (skb == NULL) {
                printk("%s: Memory squeeze, dropping packet.\n", dev->name);
-               fep->stats.rx_dropped++;
+               dev->stats.rx_dropped++;
        } else {
-               skb->dev = dev;
                skb_put(skb,pkt_len-4); /* Make room */
-               eth_copy_and_sum(skb,
-                                (unsigned char *)__va(bdp->cbd_bufaddr),
-                                pkt_len-4, 0);
+               skb_copy_to_linear_data(skb, data, pkt_len-4);
                skb->protocol=eth_type_trans(skb,dev);
                netif_rx(skb);
        }
@@ -649,27 +646,28 @@ while (!(bdp->cbd_sc & BD_ENET_RX_EMPTY)) {
 
        /* Clear the status flags for this buffer.
        */
-       bdp->cbd_sc &= ~BD_ENET_RX_STATS;
+       status &= ~BD_ENET_RX_STATS;
 
        /* Mark the buffer empty.
        */
-       bdp->cbd_sc |= BD_ENET_RX_EMPTY;
+       status |= BD_ENET_RX_EMPTY;
+       bdp->cbd_sc = status;
 
        /* Update BD pointer to next entry.
        */
-       if (bdp->cbd_sc & BD_ENET_RX_WRAP)
+       if (status & BD_ENET_RX_WRAP)
                bdp = fep->rx_bd_base;
        else
                bdp++;
-       
+
 #if 1
        /* Doing this here will keep the FEC running while we process
         * incoming frames.  On a heavily loaded network, we should be
         * able to keep up at the expense of system resources.
         */
-       fecp->fec_r_des_active = 0x01000000;
+       fecp->fec_r_des_active = 0;
 #endif
-   } /* while (!(bdp->cbd_sc & BD_ENET_RX_EMPTY)) */
+   } /* while (!((status = bdp->cbd_sc) & BD_ENET_RX_EMPTY)) */
        fep->cur_rx = (cbd_t *)bdp;
 
 #if 0
@@ -680,11 +678,14 @@ while (!(bdp->cbd_sc & BD_ENET_RX_EMPTY)) {
         * our way back to the interrupt return only to come right back
         * here.
         */
-       fecp->fec_r_des_active = 0x01000000;
+       fecp->fec_r_des_active = 0;
 #endif
+
+       spin_unlock_irq(&fep->hw_lock);
 }
 
 
+/* called from interrupt context */
 static void
 fec_enet_mii(struct net_device *dev)
 {
@@ -694,12 +695,14 @@ fec_enet_mii(struct net_device *dev)
        uint            mii_reg;
 
        fep = netdev_priv(dev);
+       spin_lock_irq(&fep->mii_lock);
+
        ep = fep->hwp;
        mii_reg = ep->fec_mii_data;
-       
+
        if ((mip = mii_head) == NULL) {
                printk("MII and no head!\n");
-               return;
+               goto unlock;
        }
 
        if (mip->mii_func != NULL)
@@ -711,6 +714,9 @@ fec_enet_mii(struct net_device *dev)
 
        if ((mip = mii_head) != NULL)
                ep->fec_mii_data = mip->mii_regval;
+
+unlock:
+       spin_unlock_irq(&fep->mii_lock);
 }
 
 static int
@@ -724,13 +730,11 @@ mii_queue(struct net_device *dev, int regval, void (*func)(uint, struct net_devi
        /* Add PHY address to register command.
        */
        fep = netdev_priv(dev);
-       regval |= fep->phy_addr << 23;
+       spin_lock_irqsave(&fep->mii_lock, flags);
 
+       regval |= fep->phy_addr << 23;
        retval = 0;
 
-       save_flags(flags);
-       cli();
-
        if ((mip = mii_free) != NULL) {
                mii_free = mip->mii_next;
                mip->mii_regval = regval;
@@ -739,31 +743,25 @@ mii_queue(struct net_device *dev, int regval, void (*func)(uint, struct net_devi
                if (mii_head) {
                        mii_tail->mii_next = mip;
                        mii_tail = mip;
-               }
-               else {
+               } else {
                        mii_head = mii_tail = mip;
                        fep->hwp->fec_mii_data = regval;
                }
-       }
-       else {
+       } else {
                retval = 1;
        }
 
-       restore_flags(flags);
-
-       return(retval);
+       spin_unlock_irqrestore(&fep->mii_lock, flags);
+       return retval;
 }
 
 static void mii_do_cmd(struct net_device *dev, const phy_cmd_t *c)
 {
-       int k;
-
        if(!c)
                return;
 
-       for(k = 0; (c+k)->mii_data != mk_mii_end; k++) {
-               mii_queue(dev, (c+k)->mii_data, (c+k)->funct);
-       }
+       for (; c->mii_data != mk_mii_end; c++)
+               mii_queue(dev, c->mii_data, c->funct);
 }
 
 static void mii_parse_sr(uint mii_reg, struct net_device *dev)
@@ -780,7 +778,6 @@ static void mii_parse_sr(uint mii_reg, struct net_device *dev)
                status |= PHY_STAT_FAULT;
        if (mii_reg & 0x0020)
                status |= PHY_STAT_ANC;
-
        *s = status;
 }
 
@@ -872,14 +869,14 @@ static phy_cmd_t const phy_cmd_lxt970_shutdown[] = { /* disable interrupts */
                { mk_mii_end, }
        };
 static phy_info_t const phy_info_lxt970 = {
-       .id = 0x07810000, 
+       .id = 0x07810000,
        .name = "LXT970",
        .config = phy_cmd_lxt970_config,
        .startup = phy_cmd_lxt970_startup,
        .ack_int = phy_cmd_lxt970_ack_int,
        .shutdown = phy_cmd_lxt970_shutdown
 };
-       
+
 /* ------------------------------------------------------------------------- */
 /* The Level one LXT971 is used on some of my custom boards                  */
 
@@ -892,7 +889,7 @@ static phy_info_t const phy_info_lxt970 = {
 #define MII_LXT971_LCR       20  /* LED Control Register      */
 #define MII_LXT971_TCR       30  /* Transmit Control Register */
 
-/* 
+/*
  * I had some nice ideas of running the MDIO faster...
  * The 971 should support 8MHz and I tried it, but things acted really
  * weird, so 2.5 MHz ought to be enough for anyone...
@@ -930,9 +927,9 @@ static void mii_parse_lxt971_sr2(uint mii_reg, struct net_device *dev)
 
        *s = status;
 }
-       
+
 static phy_cmd_t const phy_cmd_lxt971_config[] = {
-               /* limit to 10MBit because my prototype board 
+               /* limit to 10MBit because my prototype board
                 * doesn't work with 100. */
                { mk_mii_read(MII_REG_CR), mii_parse_cr },
                { mk_mii_read(MII_REG_ANAR), mii_parse_anar },
@@ -946,7 +943,7 @@ static phy_cmd_t const phy_cmd_lxt971_startup[] = {  /* enable interrupts */
                /* Somehow does the 971 tell me that the link is down
                 * the first read after power-up.
                 * read here to get a valid value in ack_int */
-               { mk_mii_read(MII_REG_SR), mii_parse_sr }, 
+               { mk_mii_read(MII_REG_SR), mii_parse_sr },
                { mk_mii_end, }
        };
 static phy_cmd_t const phy_cmd_lxt971_ack_int[] = {
@@ -962,7 +959,7 @@ static phy_cmd_t const phy_cmd_lxt971_shutdown[] = { /* disable interrupts */
                { mk_mii_end, }
        };
 static phy_info_t const phy_info_lxt971 = {
-       .id = 0x0001378e, 
+       .id = 0x0001378e,
        .name = "LXT971",
        .config = phy_cmd_lxt971_config,
        .startup = phy_cmd_lxt971_startup,
@@ -1001,7 +998,7 @@ static void mii_parse_qs6612_pcr(uint mii_reg, struct net_device *dev)
 }
 
 static phy_cmd_t const phy_cmd_qs6612_config[] = {
-               /* The PHY powers up isolated on the RPX, 
+               /* The PHY powers up isolated on the RPX,
                 * so send a command to allow operation.
                 */
                { mk_mii_write(MII_QS6612_PCR, 0x0dc0), NULL },
@@ -1031,7 +1028,7 @@ static phy_cmd_t const phy_cmd_qs6612_shutdown[] = { /* disable interrupts */
                { mk_mii_end, }
        };
 static phy_info_t const phy_info_qs6612 = {
-       .id = 0x00181440, 
+       .id = 0x00181440,
        .name = "QS6612",
        .config = phy_cmd_qs6612_config,
        .startup = phy_cmd_qs6612_startup,
@@ -1079,7 +1076,7 @@ static phy_cmd_t const phy_cmd_am79c874_config[] = {
 static phy_cmd_t const phy_cmd_am79c874_startup[] = {  /* enable interrupts */
                { mk_mii_write(MII_AM79C874_ICSR, 0xff00), NULL },
                { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
-               { mk_mii_read(MII_REG_SR), mii_parse_sr }, 
+               { mk_mii_read(MII_REG_SR), mii_parse_sr },
                { mk_mii_end, }
        };
 static phy_cmd_t const phy_cmd_am79c874_ack_int[] = {
@@ -1110,7 +1107,7 @@ static phy_info_t const phy_info_am79c874 = {
 /* register definitions for the 8721 */
 
 #define MII_KS8721BL_RXERCR    21
-#define MII_KS8721BL_ICSR      22
+#define MII_KS8721BL_ICSR      27
 #define        MII_KS8721BL_PHYCR      31
 
 static phy_cmd_t const phy_cmd_ks8721bl_config[] = {
@@ -1121,7 +1118,7 @@ static phy_cmd_t const phy_cmd_ks8721bl_config[] = {
 static phy_cmd_t const phy_cmd_ks8721bl_startup[] = {  /* enable interrupts */
                { mk_mii_write(MII_KS8721BL_ICSR, 0xff00), NULL },
                { mk_mii_write(MII_REG_CR, 0x1200), NULL }, /* autonegotiate */
-               { mk_mii_read(MII_REG_SR), mii_parse_sr }, 
+               { mk_mii_read(MII_REG_SR), mii_parse_sr },
                { mk_mii_end, }
        };
 static phy_cmd_t const phy_cmd_ks8721bl_ack_int[] = {
@@ -1136,7 +1133,7 @@ static phy_cmd_t const phy_cmd_ks8721bl_shutdown[] = { /* disable interrupts */
                { mk_mii_end, }
        };
 static phy_info_t const phy_info_ks8721bl = {
-       .id = 0x00022161, 
+       .id = 0x00022161,
        .name = "KS8721BL",
        .config = phy_cmd_ks8721bl_config,
        .startup = phy_cmd_ks8721bl_startup,
@@ -1151,7 +1148,7 @@ static phy_info_t const phy_info_ks8721bl = {
 
 static void mii_parse_dp8384x_sr2(uint mii_reg, struct net_device *dev)
 {
-       struct fec_enet_private *fep = dev->priv;
+       struct fec_enet_private *fep = netdev_priv(dev);
        volatile uint *s = &(fep->phy_status);
 
        *s &= ~(PHY_STAT_SPMASK | PHY_STAT_LINK | PHY_STAT_ANC);
@@ -1216,108 +1213,24 @@ static phy_info_t const * const phy_info[] = {
 };
 
 /* ------------------------------------------------------------------------- */
-
-#ifdef CONFIG_RPXCLASSIC
-static void
-mii_link_interrupt(void *dev_id);
-#else
+#ifdef HAVE_mii_link_interrupt
 static irqreturn_t
-mii_link_interrupt(int irq, void * dev_id, struct pt_regs * regs);
-#endif
-
-#if defined(CONFIG_M5272)
+mii_link_interrupt(int irq, void * dev_id);
 
 /*
- *     Code specific to Coldfire 5272 setup.
+ *     This is specific to the MII interrupt setup of the M5272EVB.
  */
-static void __inline__ fec_request_intrs(struct net_device *dev)
-{
-       volatile unsigned long *icrp;
-       static const struct idesc {
-               char *name;
-               unsigned short irq;
-               irqreturn_t (*handler)(int, void *, struct pt_regs *);
-       } *idp, id[] = {
-               { "fec(RX)", 86, fec_enet_interrupt },
-               { "fec(TX)", 87, fec_enet_interrupt },
-               { "fec(OTHER)", 88, fec_enet_interrupt },
-               { "fec(MII)", 66, mii_link_interrupt },
-               { NULL },
-       };
-
-       /* Setup interrupt handlers. */
-       for (idp = id; idp->name; idp++) {
-               if (request_irq(idp->irq, idp->handler, 0, idp->name, dev) != 0)
-                       printk("FEC: Could not allocate %s IRQ(%d)!\n", idp->name, idp->irq);
-       }
-
-       /* Unmask interrupt at ColdFire 5272 SIM */
-       icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR3);
-       *icrp = 0x00000ddd;
-       icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR1);
-       *icrp = (*icrp & 0x70777777) | 0x0d000000;
-}
-
-static void __inline__ fec_set_mii(struct net_device *dev, struct fec_enet_private *fep)
-{
-       volatile fec_t *fecp;
-
-       fecp = fep->hwp;
-       fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x04;
-       fecp->fec_x_cntrl = 0x00;
-
-       /*
-        * Set MII speed to 2.5 MHz
-        * See 5272 manual section 11.5.8: MSCR
-        */
-       fep->phy_speed = ((((MCF_CLK / 4) / (2500000 / 10)) + 5) / 10) * 2;
-       fecp->fec_mii_speed = fep->phy_speed;
-
-       fec_restart(dev, 0);
-}
-
-static void __inline__ fec_get_mac(struct net_device *dev)
-{
-       struct fec_enet_private *fep = netdev_priv(dev);
-       volatile fec_t *fecp;
-       unsigned char *iap, tmpaddr[ETH_ALEN];
-
-       fecp = fep->hwp;
-
-       if (FEC_FLASHMAC) {
-               /*
-                * Get MAC address from FLASH.
-                * If it is all 1's or 0's, use the default.
-                */
-               iap = (unsigned char *)FEC_FLASHMAC;
-               if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) &&
-                   (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0))
-                       iap = fec_mac_default;
-               if ((iap[0] == 0xff) && (iap[1] == 0xff) && (iap[2] == 0xff) &&
-                   (iap[3] == 0xff) && (iap[4] == 0xff) && (iap[5] == 0xff))
-                       iap = fec_mac_default;
-       } else {
-               *((unsigned long *) &tmpaddr[0]) = fecp->fec_addr_low;
-               *((unsigned short *) &tmpaddr[4]) = (fecp->fec_addr_high >> 16);
-               iap = &tmpaddr[0];
-       }
-
-       memcpy(dev->dev_addr, iap, ETH_ALEN);
-
-       /* Adjust MAC if using default MAC address */
-       if (iap == fec_mac_default)
-                dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index;
-}
-
-static void __inline__ fec_enable_phy_intr(void)
+static void __inline__ fec_request_mii_intr(struct net_device *dev)
 {
+       if (request_irq(66, mii_link_interrupt, IRQF_DISABLED, "fec(MII)", dev) != 0)
+               printk("FEC: Could not allocate fec(MII) IRQ(66)!\n");
 }
 
 static void __inline__ fec_disable_phy_intr(void)
 {
        volatile unsigned long *icrp;
        icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR1);
-       *icrp = (*icrp & 0x70777777) | 0x08000000;
+       *icrp = 0x08000000;
 }
 
 static void __inline__ fec_phy_ack_intr(void)
@@ -1325,113 +1238,11 @@ static void __inline__ fec_phy_ack_intr(void)
        volatile unsigned long *icrp;
        /* Acknowledge the interrupt */
        icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR1);
-       *icrp = (*icrp & 0x77777777) | 0x08000000;
+       *icrp = 0x0d000000;
 }
-
-static void __inline__ fec_localhw_setup(void)
-{
-}
-
-/*
- *     Do not need to make region uncached on 5272.
- */
-static void __inline__ fec_uncache(unsigned long addr)
-{
-}
-
-/* ------------------------------------------------------------------------- */
-
-#elif defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x)
-
-/*
- *     Code specific to Coldfire 5230/5231/5232/5234/5235,
- *     the 5270/5271/5274/5275 and 5280/5282 setups.
- */
-static void __inline__ fec_request_intrs(struct net_device *dev)
-{
-       struct fec_enet_private *fep;
-       int b;
-       static const struct idesc {
-               char *name;
-               unsigned short irq;
-       } *idp, id[] = {
-               { "fec(TXF)", 23 },
-               { "fec(TXB)", 24 },
-               { "fec(TXFIFO)", 25 },
-               { "fec(TXCR)", 26 },
-               { "fec(RXF)", 27 },
-               { "fec(RXB)", 28 },
-               { "fec(MII)", 29 },
-               { "fec(LC)", 30 },
-               { "fec(HBERR)", 31 },
-               { "fec(GRA)", 32 },
-               { "fec(EBERR)", 33 },
-               { "fec(BABT)", 34 },
-               { "fec(BABR)", 35 },
-               { NULL },
-       };
-
-       fep = netdev_priv(dev);
-       b = (fep->index) ? 128 : 64;
-
-       /* Setup interrupt handlers. */
-       for (idp = id; idp->name; idp++) {
-               if (request_irq(b+idp->irq, fec_enet_interrupt, 0, idp->name, dev) != 0)
-                       printk("FEC: Could not allocate %s IRQ(%d)!\n", idp->name, b+idp->irq);
-       }
-
-       /* Unmask interrupts at ColdFire 5280/5282 interrupt controller */
-       {
-               volatile unsigned char  *icrp;
-               volatile unsigned long  *imrp;
-               int i;
-
-               b = (fep->index) ? MCFICM_INTC1 : MCFICM_INTC0;
-               icrp = (volatile unsigned char *) (MCF_IPSBAR + b +
-                       MCFINTC_ICR0);
-               for (i = 23; (i < 36); i++)
-                       icrp[i] = 0x23;
-
-               imrp = (volatile unsigned long *) (MCF_IPSBAR + b +
-                       MCFINTC_IMRH);
-               *imrp &= ~0x0000000f;
-               imrp = (volatile unsigned long *) (MCF_IPSBAR + b +
-                       MCFINTC_IMRL);
-               *imrp &= ~0xff800001;
-       }
-
-#if defined(CONFIG_M528x)
-       /* Set up gpio outputs for MII lines */
-       {
-               volatile u16 *gpio_paspar;
-               volatile u8 *gpio_pehlpar;
-  
-               gpio_paspar = (volatile u16 *) (MCF_IPSBAR + 0x100056);
-               gpio_pehlpar = (volatile u16 *) (MCF_IPSBAR + 0x100058);
-               *gpio_paspar |= 0x0f00;
-               *gpio_pehlpar = 0xc0;
-       }
 #endif
-}
-
-static void __inline__ fec_set_mii(struct net_device *dev, struct fec_enet_private *fep)
-{
-       volatile fec_t *fecp;
-
-       fecp = fep->hwp;
-       fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x04;
-       fecp->fec_x_cntrl = 0x00;
-
-       /*
-        * Set MII speed to 2.5 MHz
-        * See 5282 manual section 17.5.4.7: MSCR
-        */
-       fep->phy_speed = ((((MCF_CLK / 2) / (2500000 / 10)) + 5) / 10) * 2;
-       fecp->fec_mii_speed = fep->phy_speed;
-
-       fec_restart(dev, 0);
-}
 
+#ifdef CONFIG_M5272
 static void __inline__ fec_get_mac(struct net_device *dev)
 {
        struct fec_enet_private *fep = netdev_priv(dev);
@@ -1445,7 +1256,7 @@ static void __inline__ fec_get_mac(struct net_device *dev)
                 * Get MAC address from FLASH.
                 * If it is all 1's or 0's, use the default.
                 */
-               iap = FEC_FLASHMAC;
+               iap = (unsigned char *)FEC_FLASHMAC;
                if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) &&
                    (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0))
                        iap = fec_mac_default;
@@ -1462,277 +1273,8 @@ static void __inline__ fec_get_mac(struct net_device *dev)
 
        /* Adjust MAC if using default MAC address */
        if (iap == fec_mac_default)
-               dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index;
-}
-
-static void __inline__ fec_enable_phy_intr(void)
-{
-}
-
-static void __inline__ fec_disable_phy_intr(void)
-{
-}
-
-static void __inline__ fec_phy_ack_intr(void)
-{
-}
-
-static void __inline__ fec_localhw_setup(void)
-{
-}
-
-/*
- *     Do not need to make region uncached on 5272.
- */
-static void __inline__ fec_uncache(unsigned long addr)
-{
-}
-
-/* ------------------------------------------------------------------------- */
-
-#elif defined(CONFIG_M520x)
-
-/*
- *     Code specific to Coldfire 520x
- */
-static void __inline__ fec_request_intrs(struct net_device *dev)
-{
-       struct fec_enet_private *fep;
-       int b;
-       static const struct idesc {
-               char *name;
-               unsigned short irq;
-       } *idp, id[] = {
-               { "fec(TXF)", 23 },
-               { "fec(TXB)", 24 },
-               { "fec(TXFIFO)", 25 },
-               { "fec(TXCR)", 26 },
-               { "fec(RXF)", 27 },
-               { "fec(RXB)", 28 },
-               { "fec(MII)", 29 },
-               { "fec(LC)", 30 },
-               { "fec(HBERR)", 31 },
-               { "fec(GRA)", 32 },
-               { "fec(EBERR)", 33 },
-               { "fec(BABT)", 34 },
-               { "fec(BABR)", 35 },
-               { NULL },
-       };
-
-       fep = netdev_priv(dev);
-       b = 64 + 13;
-
-       /* Setup interrupt handlers. */
-       for (idp = id; idp->name; idp++) {
-               if (request_irq(b+idp->irq,fec_enet_interrupt,0,idp->name,dev)!=0)
-                       printk("FEC: Could not allocate %s IRQ(%d)!\n", idp->name, b+idp->irq);
-       }
-
-       /* Unmask interrupts at ColdFire interrupt controller */
-       {
-               volatile unsigned char  *icrp;
-               volatile unsigned long  *imrp;
-
-               icrp = (volatile unsigned char *) (MCF_IPSBAR + MCFICM_INTC0 +
-                       MCFINTC_ICR0);
-               for (b = 36; (b < 49); b++)
-                       icrp[b] = 0x04;
-               imrp = (volatile unsigned long *) (MCF_IPSBAR + MCFICM_INTC0 +
-                       MCFINTC_IMRH);
-               *imrp &= ~0x0001FFF0;
-       }
-       *(volatile unsigned char *)(MCF_IPSBAR + MCF_GPIO_PAR_FEC) |= 0xf0;
-       *(volatile unsigned char *)(MCF_IPSBAR + MCF_GPIO_PAR_FECI2C) |= 0x0f;
-}
-
-static void __inline__ fec_set_mii(struct net_device *dev, struct fec_enet_private *fep)
-{
-       volatile fec_t *fecp;
-
-       fecp = fep->hwp;
-       fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x04;
-       fecp->fec_x_cntrl = 0x00;
-
-       /*
-        * Set MII speed to 2.5 MHz
-        * See 5282 manual section 17.5.4.7: MSCR
-        */
-       fep->phy_speed = ((((MCF_CLK / 2) / (2500000 / 10)) + 5) / 10) * 2;
-       fecp->fec_mii_speed = fep->phy_speed;
-
-       fec_restart(dev, 0);
-}
-
-static void __inline__ fec_get_mac(struct net_device *dev)
-{
-       struct fec_enet_private *fep = netdev_priv(dev);
-       volatile fec_t *fecp;
-       unsigned char *iap, tmpaddr[ETH_ALEN];
-
-       fecp = fep->hwp;
-
-       if (FEC_FLASHMAC) {
-               /*
-                * Get MAC address from FLASH.
-                * If it is all 1's or 0's, use the default.
-                */
-               iap = FEC_FLASHMAC;
-               if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) &&
-                  (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0))
-                       iap = fec_mac_default;
-               if ((iap[0] == 0xff) && (iap[1] == 0xff) && (iap[2] == 0xff) &&
-                  (iap[3] == 0xff) && (iap[4] == 0xff) && (iap[5] == 0xff))
-                       iap = fec_mac_default;
-       } else {
-               *((unsigned long *) &tmpaddr[0]) = fecp->fec_addr_low;
-               *((unsigned short *) &tmpaddr[4]) = (fecp->fec_addr_high >> 16);
-               iap = &tmpaddr[0];
-       }
-
-       memcpy(dev->dev_addr, iap, ETH_ALEN);
-
-       /* Adjust MAC if using default MAC address */
-       if (iap == fec_mac_default)
-               dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index;
-}
-
-static void __inline__ fec_enable_phy_intr(void)
-{
-}
-
-static void __inline__ fec_disable_phy_intr(void)
-{
-}
-
-static void __inline__ fec_phy_ack_intr(void)
-{
-}
-
-static void __inline__ fec_localhw_setup(void)
-{
-}
-
-static void __inline__ fec_uncache(unsigned long addr)
-{
-}
-
-/* ------------------------------------------------------------------------- */
-
-#else
-
-/*
- *     Code specific to the MPC860T setup.
- */
-static void __inline__ fec_request_intrs(struct net_device *dev)
-{
-       volatile immap_t *immap;
-
-       immap = (immap_t *)IMAP_ADDR;   /* pointer to internal registers */
-
-       if (request_8xxirq(FEC_INTERRUPT, fec_enet_interrupt, 0, "fec", dev) != 0)
-               panic("Could not allocate FEC IRQ!");
-
-#ifdef CONFIG_RPXCLASSIC
-       /* Make Port C, bit 15 an input that causes interrupts.
-       */
-       immap->im_ioport.iop_pcpar &= ~0x0001;
-       immap->im_ioport.iop_pcdir &= ~0x0001;
-       immap->im_ioport.iop_pcso &= ~0x0001;
-       immap->im_ioport.iop_pcint |= 0x0001;
-       cpm_install_handler(CPMVEC_PIO_PC15, mii_link_interrupt, dev);
-
-       /* Make LEDS reflect Link status.
-       */
-       *((uint *) RPX_CSR_ADDR) &= ~BCSR2_FETHLEDMODE;
-#endif
-#ifdef CONFIG_FADS
-       if (request_8xxirq(SIU_IRQ2, mii_link_interrupt, 0, "mii", dev) != 0)
-               panic("Could not allocate MII IRQ!");
-#endif
-}
-
-static void __inline__ fec_get_mac(struct net_device *dev)
-{
-       bd_t *bd;
-
-       bd = (bd_t *)__res;
-       memcpy(dev->dev_addr, bd->bi_enetaddr, ETH_ALEN);
-
-#ifdef CONFIG_RPXCLASSIC
-       /* The Embedded Planet boards have only one MAC address in
-        * the EEPROM, but can have two Ethernet ports.  For the
-        * FEC port, we create another address by setting one of
-        * the address bits above something that would have (up to
-        * now) been allocated.
-        */
-       dev->dev_adrd[3] |= 0x80;
-#endif
-}
-
-static void __inline__ fec_set_mii(struct net_device *dev, struct fec_enet_private *fep)
-{
-       extern uint _get_IMMR(void);
-       volatile immap_t *immap;
-       volatile fec_t *fecp;
-
-       fecp = fep->hwp;
-       immap = (immap_t *)IMAP_ADDR;   /* pointer to internal registers */
-
-       /* Configure all of port D for MII.
-       */
-       immap->im_ioport.iop_pdpar = 0x1fff;
-
-       /* Bits moved from Rev. D onward.
-       */
-       if ((_get_IMMR() & 0xffff) < 0x0501)
-               immap->im_ioport.iop_pddir = 0x1c58;    /* Pre rev. D */
-       else
-               immap->im_ioport.iop_pddir = 0x1fff;    /* Rev. D and later */
-       
-       /* Set MII speed to 2.5 MHz
-       */
-       fecp->fec_mii_speed = fep->phy_speed = 
-               ((bd->bi_busfreq * 1000000) / 2500000) & 0x7e;
-}
-
-static void __inline__ fec_enable_phy_intr(void)
-{
-       volatile fec_t *fecp;
-
-       fecp = fep->hwp;
-
-       /* Enable MII command finished interrupt 
-       */
-       fecp->fec_ivec = (FEC_INTERRUPT/2) << 29;
-}
-
-static void __inline__ fec_disable_phy_intr(void)
-{
-}
-
-static void __inline__ fec_phy_ack_intr(void)
-{
-}
-
-static void __inline__ fec_localhw_setup(void)
-{
-       volatile fec_t *fecp;
-
-       fecp = fep->hwp;
-       fecp->fec_r_hash = PKT_MAXBUF_SIZE;
-       /* Enable big endian and don't care about SDMA FC.
-       */
-       fecp->fec_fun_code = 0x78000000;
-}
-
-static void __inline__ fec_uncache(unsigned long addr)
-{
-       pte_t *pte;
-       pte = va_to_pte(mem_addr);
-       pte_val(*pte) |= _PAGE_NO_CACHE;
-       flush_tlb_page(init_mm.mmap, mem_addr);
+                dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->index;
 }
-
 #endif
 
 /* ------------------------------------------------------------------------- */
@@ -1773,9 +1315,10 @@ static void mii_display_status(struct net_device *dev)
        printk(".\n");
 }
 
-static void mii_display_config(struct net_device *dev)
+static void mii_display_config(struct work_struct *work)
 {
-       struct fec_enet_private *fep = netdev_priv(dev);
+       struct fec_enet_private *fep = container_of(work, struct fec_enet_private, phy_task);
+       struct net_device *dev = fep->netdev;
        uint status = fep->phy_status;
 
        /*
@@ -1803,15 +1346,16 @@ static void mii_display_config(struct net_device *dev)
 
        if (status & PHY_CONF_LOOP)
                printk(", loopback enabled");
-       
+
        printk(".\n");
 
        fep->sequence_done = 1;
 }
 
-static void mii_relink(struct net_device *dev)
+static void mii_relink(struct work_struct *work)
 {
-       struct fec_enet_private *fep = netdev_priv(dev);
+       struct fec_enet_private *fep = container_of(work, struct fec_enet_private, phy_task);
+       struct net_device *dev = fep->netdev;
        int duplex;
 
        /*
@@ -1825,12 +1369,11 @@ static void mii_relink(struct net_device *dev)
 
        if (fep->link) {
                duplex = 0;
-               if (fep->phy_status 
+               if (fep->phy_status
                    & (PHY_STAT_100FDX | PHY_STAT_10FDX))
                        duplex = 1;
                fec_restart(dev, duplex);
-       }
-       else
+       } else
                fec_stop(dev);
 
 #if 0
@@ -1855,7 +1398,7 @@ static void mii_queue_relink(uint mii_reg, struct net_device *dev)
                return;
 
        fep->mii_phy_task_queued = 1;
-       INIT_WORK(&fep->phy_task, (void*)mii_relink, dev);
+       INIT_WORK(&fep->phy_task, mii_relink);
        schedule_work(&fep->phy_task);
 }
 
@@ -1868,7 +1411,7 @@ static void mii_queue_config(uint mii_reg, struct net_device *dev)
                return;
 
        fep->mii_phy_task_queued = 1;
-       INIT_WORK(&fep->phy_task, (void*)mii_display_config, dev);
+       INIT_WORK(&fep->phy_task, mii_display_config);
        schedule_work(&fep->phy_task);
 }
 
@@ -1902,7 +1445,7 @@ mii_discover_phy3(uint mii_reg, struct net_device *dev)
                printk(" -- %s\n", phy_info[i]->name);
        else
                printk(" -- unknown PHY!\n");
-      
+
        fep->phy = phy_info[i];
        fep->phy_id_done = 1;
 }
@@ -1922,14 +1465,13 @@ mii_discover_phy(uint mii_reg, struct net_device *dev)
 
        if (fep->phy_addr < 32) {
                if ((phytype = (mii_reg & 0xffff)) != 0xffff && phytype != 0) {
-                       
+
                        /* Got first part of ID, now get remainder.
                        */
                        fep->phy_id = phytype << 16;
                        mii_queue(dev, mk_mii_read(MII_REG_PHYIR2),
                                                        mii_discover_phy3);
-               }
-               else {
+               } else {
                        fep->phy_addr++;
                        mii_queue(dev, mk_mii_read(MII_REG_PHYIR1),
                                                        mii_discover_phy);
@@ -1938,19 +1480,17 @@ mii_discover_phy(uint mii_reg, struct net_device *dev)
                printk("FEC: No PHY device found.\n");
                /* Disable external MII interface */
                fecp->fec_mii_speed = fep->phy_speed = 0;
+#ifdef HAVE_mii_link_interrupt
                fec_disable_phy_intr();
+#endif
        }
 }
 
 /* This interrupt occurs when the PHY detects a link change.
 */
-#ifdef CONFIG_RPXCLASSIC
-static void
-mii_link_interrupt(void *dev_id)
-#else
+#ifdef HAVE_mii_link_interrupt
 static irqreturn_t
-mii_link_interrupt(int irq, void * dev_id, struct pt_regs * regs)
-#endif
+mii_link_interrupt(int irq, void * dev_id)
 {
        struct  net_device *dev = dev_id;
        struct fec_enet_private *fep = netdev_priv(dev);
@@ -1966,6 +1506,7 @@ mii_link_interrupt(int irq, void * dev_id, struct pt_regs * regs)
 
        return IRQ_HANDLED;
 }
+#endif
 
 static int
 fec_enet_open(struct net_device *dev)
@@ -1985,9 +1526,12 @@ fec_enet_open(struct net_device *dev)
                mii_do_cmd(dev, fep->phy->config);
                mii_do_cmd(dev, phy_cmd_config);  /* display configuration */
 
-               /* FIXME: use netif_carrier_{on,off} ; this polls
-                * until link is up which is wrong...  could be
-                * 30 seconds or more we are trapped in here. -jgarzik
+               /* Poll until the PHY tells us its configuration
+                * (not link state).
+                * Request is initiated by mii_do_cmd above, but answer
+                * comes by interrupt.
+                * This should take about 25 usec per register at 2.5 MHz,
+                * and we read approximately 5 registers.
                 */
                while(!fep->sequence_done)
                        schedule();
@@ -2024,13 +1568,6 @@ fec_enet_close(struct net_device *dev)
        return 0;
 }
 
-static struct net_device_stats *fec_enet_get_stats(struct net_device *dev)
-{
-       struct fec_enet_private *fep = netdev_priv(dev);
-
-       return &fep->stats;
-}
-
 /* Set or clear the multicast filter for this adaptor.
  * Skeleton taken from sunlance driver.
  * The CPM Ethernet implementation allows Multicast as well as individual
@@ -2056,8 +1593,6 @@ static void set_multicast_list(struct net_device *dev)
        ep = fep->hwp;
 
        if (dev->flags&IFF_PROMISC) {
-               /* Log any net taps. */
-               printk("%s: Promiscuous mode enabled.\n", dev->name);
                ep->fec_r_cntrl |= 0x0008;
        } else {
 
@@ -2067,14 +1602,14 @@ static void set_multicast_list(struct net_device *dev)
                        /* Catch all multicast addresses, so set the
                         * filter to all 1's.
                         */
-                       ep->fec_hash_table_high = 0xffffffff;
-                       ep->fec_hash_table_low = 0xffffffff;
+                       ep->fec_grp_hash_table_high = 0xffffffff;
+                       ep->fec_grp_hash_table_low = 0xffffffff;
                } else {
                        /* Clear filter and add the addresses in hash register.
                        */
-                       ep->fec_hash_table_high = 0;
-                       ep->fec_hash_table_low = 0;
-            
+                       ep->fec_grp_hash_table_high = 0;
+                       ep->fec_grp_hash_table_low = 0;
+
                        dmi = dev->mc_list;
 
                        for (j = 0; j < dev->mc_count; j++, dmi = dmi->next)
@@ -2083,7 +1618,7 @@ static void set_multicast_list(struct net_device *dev)
                                */
                                if (!(dmi->dmi_addr[0] & 1))
                                        continue;
-                       
+
                                /* calculate crc32 value of mac address
                                */
                                crc = 0xffffffff;
@@ -2102,11 +1637,11 @@ static void set_multicast_list(struct net_device *dev)
                                   which point to specific bit in he hash registers
                                */
                                hash = (crc >> (32 - HASH_BITS)) & 0x3f;
-                       
+
                                if (hash > 31)
-                                       ep->fec_hash_table_high |= 1 << (hash - 32);
+                                       ep->fec_grp_hash_table_high |= 1 << (hash - 32);
                                else
-                                       ep->fec_hash_table_low |= 1 << hash;
+                                       ep->fec_grp_hash_table_low |= 1 << hash;
                        }
                }
        }
@@ -2129,12 +1664,12 @@ fec_set_mac_address(struct net_device *dev)
 
 }
 
-/* Initialize the FEC Ethernet on 860T (or ColdFire 5272).
- */
  /*
   * XXX:  We need to clean up on failure exits here.
+  *
+  * index is only used in legacy code
   */
-int __init fec_enet_init(struct net_device *dev)
+int __init fec_enet_init(struct net_device *dev, int index)
 {
        struct fec_enet_private *fep = netdev_priv(dev);
        unsigned long   mem_addr;
@@ -2142,44 +1677,50 @@ int __init fec_enet_init(struct net_device *dev)
        cbd_t           *cbd_base;
        volatile fec_t  *fecp;
        int             i, j;
-       static int      index = 0;
-
-       /* Only allow us to be probed once. */
-       if (index >= FEC_MAX_PORTS)
-               return -ENXIO;
 
        /* Allocate memory for buffer descriptors.
        */
-       mem_addr = __get_free_page(GFP_KERNEL);
+       mem_addr = (unsigned long)dma_alloc_coherent(NULL, PAGE_SIZE,
+                       &fep->bd_dma, GFP_KERNEL);
        if (mem_addr == 0) {
                printk("FEC: allocate descriptor memory failed?\n");
                return -ENOMEM;
        }
 
+       spin_lock_init(&fep->hw_lock);
+       spin_lock_init(&fep->mii_lock);
+
        /* Create an Ethernet device instance.
        */
-       fecp = (volatile fec_t *) fec_hw[index];
+       fecp = (volatile fec_t *)dev->base_addr;
 
        fep->index = index;
        fep->hwp = fecp;
+       fep->netdev = dev;
 
        /* Whack a reset.  We should wait for this.
        */
        fecp->fec_ecntrl = 1;
        udelay(10);
 
-       /* Set the Ethernet address.  If using multiple Enets on the 8xx,
-        * this needs some work to get unique addresses.
-        *
-        * This is our default MAC address unless the user changes
-        * it via eth_mac_addr (our dev->set_mac_addr handler).
-        */
+       /* Set the Ethernet address */
+#ifdef CONFIG_M5272
        fec_get_mac(dev);
+#else
+       {
+               unsigned long l;
+               l = fecp->fec_addr_low;
+               dev->dev_addr[0] = (unsigned char)((l & 0xFF000000) >> 24);
+               dev->dev_addr[1] = (unsigned char)((l & 0x00FF0000) >> 16);
+               dev->dev_addr[2] = (unsigned char)((l & 0x0000FF00) >> 8);
+               dev->dev_addr[3] = (unsigned char)((l & 0x000000FF) >> 0);
+               l = fecp->fec_addr_high;
+               dev->dev_addr[4] = (unsigned char)((l & 0xFF000000) >> 24);
+               dev->dev_addr[5] = (unsigned char)((l & 0x00FF0000) >> 16);
+       }
+#endif
 
        cbd_base = (cbd_t *)mem_addr;
-       /* XXX: missing check for allocation failure */
-
-       fec_uncache(mem_addr);
 
        /* Set receive and transmit descriptor base.
        */
@@ -2201,8 +1742,6 @@ int __init fec_enet_init(struct net_device *dev)
                mem_addr = __get_free_page(GFP_KERNEL);
                /* XXX: missing check for allocation failure */
 
-               fec_uncache(mem_addr);
-
                /* Initialize the BD for every fragment in the page.
                */
                for (j=0; j<FEC_ENET_RX_FRPPG; j++) {
@@ -2245,25 +1784,23 @@ int __init fec_enet_init(struct net_device *dev)
 
        /* Set receive and transmit descriptor base.
        */
-       fecp->fec_r_des_start = __pa((uint)(fep->rx_bd_base));
-       fecp->fec_x_des_start = __pa((uint)(fep->tx_bd_base));
+       fecp->fec_r_des_start = fep->bd_dma;
+       fecp->fec_x_des_start = (unsigned long)fep->bd_dma + sizeof(cbd_t)
+                               * RX_RING_SIZE;
 
-       /* Install our interrupt handlers. This varies depending on
-        * the architecture.
-       */
-       fec_request_intrs(dev);
+#ifdef HAVE_mii_link_interrupt
+       fec_request_mii_intr(dev);
+#endif
 
-       /* Clear and enable interrupts */
-       fecp->fec_ievent = 0xffc00000;
-       fecp->fec_imask = (FEC_ENET_TXF | FEC_ENET_TXB |
-               FEC_ENET_RXF | FEC_ENET_RXB | FEC_ENET_MII);
-       fecp->fec_hash_table_high = 0;
-       fecp->fec_hash_table_low = 0;
+       fecp->fec_grp_hash_table_high = 0;
+       fecp->fec_grp_hash_table_low = 0;
        fecp->fec_r_buff_size = PKT_MAXBLR_SIZE;
        fecp->fec_ecntrl = 2;
-       fecp->fec_r_des_active = 0x01000000;
-
-       dev->base_addr = (unsigned long)fecp;
+       fecp->fec_r_des_active = 0;
+#ifndef CONFIG_M5272
+       fecp->fec_hash_table_high = 0;
+       fecp->fec_hash_table_low = 0;
+#endif
 
        /* The FEC Ethernet specific entries in the device structure. */
        dev->open = fec_enet_open;
@@ -2271,7 +1808,6 @@ int __init fec_enet_init(struct net_device *dev)
        dev->tx_timeout = fec_timeout;
        dev->watchdog_timeo = TX_TIMEOUT;
        dev->stop = fec_enet_close;
-       dev->get_stats = fec_enet_get_stats;
        dev->set_multicast_list = set_multicast_list;
 
        for (i=0; i<NMII-1; i++)
@@ -2279,7 +1815,20 @@ int __init fec_enet_init(struct net_device *dev)
        mii_free = mii_cmds;
 
        /* setup MII interface */
-       fec_set_mii(dev, fep);
+       fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x04;
+       fecp->fec_x_cntrl = 0x00;
+
+       /*
+        * Set MII speed to 2.5 MHz
+        */
+       fep->phy_speed = ((((clk_get_rate(fep->clk) / 2 + 4999999)
+                                       / 2500000) / 2) & 0x3F) << 1;
+       fecp->fec_mii_speed = fep->phy_speed;
+       fec_restart(dev, 0);
+
+       /* Clear and enable interrupts */
+       fecp->fec_ievent = 0xffc00000;
+       fecp->fec_imask = (FEC_ENET_TXF | FEC_ENET_RXF | FEC_ENET_MII);
 
        /* Queue up command to detect the PHY and initialize the
         * remainder of the interface.
@@ -2288,7 +1837,6 @@ int __init fec_enet_init(struct net_device *dev)
        fep->phy_addr = 0;
        mii_queue(dev, mk_mii_read(MII_REG_PHYIR1), mii_discover_phy);
 
-       index++;
        return 0;
 }
 
@@ -2312,15 +1860,9 @@ fec_restart(struct net_device *dev, int duplex)
        fecp->fec_ecntrl = 1;
        udelay(10);
 
-       /* Enable interrupts we wish to service.
-       */
-       fecp->fec_imask = (FEC_ENET_TXF | FEC_ENET_TXB |
-                               FEC_ENET_RXF | FEC_ENET_RXB | FEC_ENET_MII);
-
        /* Clear any outstanding interrupt.
        */
        fecp->fec_ievent = 0xffc00000;
-       fec_enable_phy_intr();
 
        /* Set station address.
        */
@@ -2328,19 +1870,18 @@ fec_restart(struct net_device *dev, int duplex)
 
        /* Reset all multicast.
        */
-       fecp->fec_hash_table_high = 0;
-       fecp->fec_hash_table_low = 0;
+       fecp->fec_grp_hash_table_high = 0;
+       fecp->fec_grp_hash_table_low = 0;
 
        /* Set maximum receive buffer size.
        */
        fecp->fec_r_buff_size = PKT_MAXBLR_SIZE;
 
-       fec_localhw_setup();
-
        /* Set receive and transmit descriptor base.
        */
-       fecp->fec_r_des_start = __pa((uint)(fep->rx_bd_base));
-       fecp->fec_x_des_start = __pa((uint)(fep->tx_bd_base));
+       fecp->fec_r_des_start = fep->bd_dma;
+       fecp->fec_x_des_start = (unsigned long)fep->bd_dma + sizeof(cbd_t)
+                               * RX_RING_SIZE;
 
        fep->dirty_tx = fep->cur_tx = fep->tx_bd_base;
        fep->cur_rx = fep->rx_bd_base;
@@ -2393,8 +1934,7 @@ fec_restart(struct net_device *dev, int duplex)
        if (duplex) {
                fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x04;/* MII enable */
                fecp->fec_x_cntrl = 0x04;                 /* FD enable */
-       }
-       else {
+       } else {
                /* MII enable|No Rcv on Xmit */
                fecp->fec_r_cntrl = OPT_FRAME_SIZE | 0x06;
                fecp->fec_x_cntrl = 0x00;
@@ -2408,7 +1948,11 @@ fec_restart(struct net_device *dev, int duplex)
        /* And last, enable the transmit and receive processing.
        */
        fecp->fec_ecntrl = 2;
-       fecp->fec_r_des_active = 0x01000000;
+       fecp->fec_r_des_active = 0;
+
+       /* Enable interrupts we wish to service.
+       */
+       fecp->fec_imask = (FEC_ENET_TXF | FEC_ENET_RXF | FEC_ENET_MII);
 }
 
 static void
@@ -2420,9 +1964,16 @@ fec_stop(struct net_device *dev)
        fep = netdev_priv(dev);
        fecp = fep->hwp;
 
-       fecp->fec_x_cntrl = 0x01;       /* Graceful transmit stop */
-
-       while(!(fecp->fec_ievent & FEC_ENET_GRA));
+       /*
+       ** We cannot expect a graceful transmit stop without link !!!
+       */
+       if (fep->link)
+               {
+               fecp->fec_x_cntrl = 0x01;       /* Graceful transmit stop */
+               udelay(10);
+               if (!(fecp->fec_ievent & FEC_ENET_GRA))
+                       printk("fec_stop : Graceful transmit stop did not complete !\n");
+               }
 
        /* Whack a reset.  We should wait for this.
        */
@@ -2432,42 +1983,171 @@ fec_stop(struct net_device *dev)
        /* Clear outstanding MII command interrupts.
        */
        fecp->fec_ievent = FEC_ENET_MII;
-       fec_enable_phy_intr();
 
        fecp->fec_imask = FEC_ENET_MII;
        fecp->fec_mii_speed = fep->phy_speed;
 }
 
-static int __init fec_enet_module_init(void)
+static int __devinit
+fec_probe(struct platform_device *pdev)
 {
-       struct net_device *dev;
-       int i, j, err;
-
-       printk("FEC ENET Version 0.2\n");
-
-       for (i = 0; (i < FEC_MAX_PORTS); i++) {
-               dev = alloc_etherdev(sizeof(struct fec_enet_private));
-               if (!dev)
-                       return -ENOMEM;
-               err = fec_enet_init(dev);
-               if (err) {
-                       free_netdev(dev);
-                       continue;
+       struct fec_enet_private *fep;
+       struct net_device *ndev;
+       int i, irq, ret = 0;
+       struct resource *r;
+
+       r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!r)
+               return -ENXIO;
+
+       r = request_mem_region(r->start, resource_size(r), pdev->name);
+       if (!r)
+               return -EBUSY;
+
+       /* Init network device */
+       ndev = alloc_etherdev(sizeof(struct fec_enet_private));
+       if (!ndev)
+               return -ENOMEM;
+
+       SET_NETDEV_DEV(ndev, &pdev->dev);
+
+       /* setup board info structure */
+       fep = netdev_priv(ndev);
+       memset(fep, 0, sizeof(*fep));
+
+       ndev->base_addr = (unsigned long)ioremap(r->start, resource_size(r));
+
+       if (!ndev->base_addr) {
+               ret = -ENOMEM;
+               goto failed_ioremap;
+       }
+
+       platform_set_drvdata(pdev, ndev);
+
+       /* This device has up to three irqs on some platforms */
+       for (i = 0; i < 3; i++) {
+               irq = platform_get_irq(pdev, i);
+               if (i && irq < 0)
+                       break;
+               ret = request_irq(irq, fec_enet_interrupt, IRQF_DISABLED, pdev->name, ndev);
+               if (ret) {
+                       while (i >= 0) {
+                               irq = platform_get_irq(pdev, i);
+                               free_irq(irq, ndev);
+                               i--;
+                       }
+                       goto failed_irq;
                }
-               if (register_netdev(dev) != 0) {
-                       /* XXX: missing cleanup here */
-                       free_netdev(dev);
-                       return -EIO;
+       }
+
+       fep->clk = clk_get(&pdev->dev, "fec_clk");
+       if (IS_ERR(fep->clk)) {
+               ret = PTR_ERR(fep->clk);
+               goto failed_clk;
+       }
+       clk_enable(fep->clk);
+
+       ret = fec_enet_init(ndev, 0);
+       if (ret)
+               goto failed_init;
+
+       ret = register_netdev(ndev);
+       if (ret)
+               goto failed_register;
+
+       return 0;
+
+failed_register:
+failed_init:
+       clk_disable(fep->clk);
+       clk_put(fep->clk);
+failed_clk:
+       for (i = 0; i < 3; i++) {
+               irq = platform_get_irq(pdev, i);
+               if (irq > 0)
+                       free_irq(irq, ndev);
+       }
+failed_irq:
+       iounmap((void __iomem *)ndev->base_addr);
+failed_ioremap:
+       free_netdev(ndev);
+
+       return ret;
+}
+
+static int __devexit
+fec_drv_remove(struct platform_device *pdev)
+{
+       struct net_device *ndev = platform_get_drvdata(pdev);
+       struct fec_enet_private *fep = netdev_priv(ndev);
+
+       platform_set_drvdata(pdev, NULL);
+
+       fec_stop(ndev);
+       clk_disable(fep->clk);
+       clk_put(fep->clk);
+       iounmap((void __iomem *)ndev->base_addr);
+       unregister_netdev(ndev);
+       free_netdev(ndev);
+       return 0;
+}
+
+static int
+fec_suspend(struct platform_device *dev, pm_message_t state)
+{
+       struct net_device *ndev = platform_get_drvdata(dev);
+       struct fec_enet_private *fep;
+
+       if (ndev) {
+               fep = netdev_priv(ndev);
+               if (netif_running(ndev)) {
+                       netif_device_detach(ndev);
+                       fec_stop(ndev);
                }
+       }
+       return 0;
+}
 
-               printk("%s: ethernet ", dev->name);
-               for (j = 0; (j < 5); j++)
-                       printk("%02x:", dev->dev_addr[j]);
-               printk("%02x\n", dev->dev_addr[5]);
+static int
+fec_resume(struct platform_device *dev)
+{
+       struct net_device *ndev = platform_get_drvdata(dev);
+
+       if (ndev) {
+               if (netif_running(ndev)) {
+                       fec_enet_init(ndev, 0);
+                       netif_device_attach(ndev);
+               }
        }
        return 0;
 }
 
+static struct platform_driver fec_driver = {
+       .driver = {
+               .name    = "fec",
+               .owner   = THIS_MODULE,
+       },
+       .probe   = fec_probe,
+       .remove  = __devexit_p(fec_drv_remove),
+       .suspend = fec_suspend,
+       .resume  = fec_resume,
+};
+
+static int __init
+fec_enet_module_init(void)
+{
+       printk(KERN_INFO "FEC Ethernet Driver\n");
+
+       return platform_driver_register(&fec_driver);
+}
+
+static void __exit
+fec_enet_cleanup(void)
+{
+       platform_driver_unregister(&fec_driver);
+}
+
+module_exit(fec_enet_cleanup);
 module_init(fec_enet_module_init);
 
 MODULE_LICENSE("GPL");