drivers/net: Omit check for multicast bit in netdev_for_each_mc_addr
[linux-2.6.git] / drivers / net / sunbmac.c
index 025dcd8..297a424 100644 (file)
@@ -1,7 +1,6 @@
-/* $Id: sunbmac.c,v 1.30 2002/01/15 06:48:55 davem Exp $
- * sunbmac.c: Driver for Sparc BigMAC 100baseT ethernet adapters.
+/* sunbmac.c: Driver for Sparc BigMAC 100baseT ethernet adapters.
  *
- * Copyright (C) 1997, 1998, 1999, 2003 David S. Miller (davem@redhat.com)
+ * Copyright (C) 1997, 1998, 1999, 2003, 2008 David S. Miller (davem@davemloft.net)
  */
 
 #include <linux/module.h>
@@ -12,7 +11,6 @@
 #include <linux/interrupt.h>
 #include <linux/ioport.h>
 #include <linux/in.h>
-#include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/delay.h>
 #include <linux/init.h>
 #include <linux/etherdevice.h>
 #include <linux/skbuff.h>
 #include <linux/bitops.h>
+#include <linux/dma-mapping.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/gfp.h>
 
 #include <asm/auxio.h>
 #include <asm/byteorder.h>
 #include <asm/openprom.h>
 #include <asm/oplib.h>
 #include <asm/pgtable.h>
-#include <asm/sbus.h>
 #include <asm/system.h>
 
 #include "sunbmac.h"
 
-static char version[] __initdata =
-        "sunbmac.c:v2.0 24/Nov/03 David S. Miller (davem@redhat.com)\n";
+#define DRV_NAME       "sunbmac"
+#define DRV_VERSION    "2.1"
+#define DRV_RELDATE    "August 26, 2008"
+#define DRV_AUTHOR     "David S. Miller (davem@davemloft.net)"
+
+static char version[] =
+       DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " " DRV_AUTHOR "\n";
+
+MODULE_VERSION(DRV_VERSION);
+MODULE_AUTHOR(DRV_AUTHOR);
+MODULE_DESCRIPTION("Sun BigMAC 100baseT ethernet driver");
+MODULE_LICENSE("GPL");
 
 #undef DEBUG_PROBE
 #undef DEBUG_TX
@@ -62,8 +73,6 @@ static char version[] __initdata =
 #define DIRQ(x)
 #endif
 
-static struct bigmac *root_bigmac_dev;
-
 #define DEFAULT_JAMSIZE    4 /* Toe jam */
 
 #define QEC_RESET_TRIES 200
@@ -88,8 +97,8 @@ static int qec_global_reset(void __iomem *gregs)
 
 static void qec_init(struct bigmac *bp)
 {
+       struct platform_device *qec_op = bp->qec_op;
        void __iomem *gregs = bp->gregs;
-       struct sbus_dev *qec_sdev = bp->qec_sdev;
        u8 bsizes = bp->bigmac_bursts;
        u32 regval;
 
@@ -104,13 +113,13 @@ static void qec_init(struct bigmac *bp)
        sbus_writel(GLOB_PSIZE_2048, gregs + GLOB_PSIZE);
 
        /* All of memsize is given to bigmac. */
-       sbus_writel(qec_sdev->reg_addrs[1].reg_size,
+       sbus_writel(resource_size(&qec_op->resource[1]),
                    gregs + GLOB_MSIZE);
 
        /* Half to the transmitter, half to the receiver. */
-       sbus_writel(qec_sdev->reg_addrs[1].reg_size >> 1,
+       sbus_writel(resource_size(&qec_op->resource[1]) >> 1,
                    gregs + GLOB_TSIZE);
-       sbus_writel(qec_sdev->reg_addrs[1].reg_size >> 1,
+       sbus_writel(resource_size(&qec_op->resource[1]) >> 1,
                    gregs + GLOB_RSIZE);
 }
 
@@ -204,7 +213,8 @@ static void bigmac_init_rings(struct bigmac *bp, int from_irq)
 {
        struct bmac_init_block *bb = bp->bmac_block;
        struct net_device *dev = bp->dev;
-       int i, gfp_flags = GFP_KERNEL;
+       int i;
+       gfp_t gfp_flags = GFP_KERNEL;
 
        if (from_irq || in_interrupt())
                gfp_flags = GFP_ATOMIC;
@@ -230,9 +240,10 @@ static void bigmac_init_rings(struct bigmac *bp, int from_irq)
                skb_reserve(skb, 34);
 
                bb->be_rxd[i].rx_addr =
-                       sbus_map_single(bp->bigmac_sdev, skb->data,
-                                       RX_BUF_ALLOC_SIZE - 34,
-                                       SBUS_DMA_FROMDEVICE);
+                       dma_map_single(&bp->bigmac_op->dev,
+                                      skb->data,
+                                      RX_BUF_ALLOC_SIZE - 34,
+                                      DMA_FROM_DEVICE);
                bb->be_rxd[i].rx_flags =
                        (RXD_OWN | ((RX_BUF_ALLOC_SIZE - 34) & RXD_LENGTH));
        }
@@ -351,7 +362,7 @@ static void bigmac_tcvr_write(struct bigmac *bp, void __iomem *tregs,
        default:
                printk(KERN_ERR "bigmac_tcvr_read: Whoops, no known transceiver type.\n");
                return;
-       };
+       }
 
        idle_transceiver(tregs);
        write_tcvr_bit(bp, tregs, 0);
@@ -390,7 +401,7 @@ static unsigned short bigmac_tcvr_read(struct bigmac *bp,
        default:
                printk(KERN_ERR "bigmac_tcvr_read: Whoops, no known transceiver type.\n");
                return 0xffff;
-       };
+       }
 
        idle_transceiver(tregs);
        write_tcvr_bit(bp, tregs, 0);
@@ -480,7 +491,7 @@ static void bigmac_tcvr_init(struct bigmac *bp)
        }
 }
 
-static int bigmac_init(struct bigmac *, int);
+static int bigmac_init_hw(struct bigmac *, int);
 
 static int try_next_permutation(struct bigmac *bp, void __iomem *tregs)
 {
@@ -540,7 +551,7 @@ static void bigmac_timer(unsigned long data)
                                if (ret == -1) {
                                        printk(KERN_ERR "%s: Link down, cable problem?\n",
                                               bp->dev->name);
-                                       ret = bigmac_init(bp, 0);
+                                       ret = bigmac_init_hw(bp, 0);
                                        if (ret) {
                                                printk(KERN_ERR "%s: Error, cannot re-init the "
                                                       "BigMAC.\n", bp->dev->name);
@@ -606,11 +617,11 @@ static void bigmac_begin_auto_negotiation(struct bigmac *bp)
        bp->timer_ticks = 0;
        bp->bigmac_timer.expires = jiffies + (12 * HZ) / 10;
        bp->bigmac_timer.data = (unsigned long) bp;
-       bp->bigmac_timer.function = &bigmac_timer;
+       bp->bigmac_timer.function = bigmac_timer;
        add_timer(&bp->bigmac_timer);
 }
 
-static int bigmac_init(struct bigmac *bp, int from_irq)
+static int bigmac_init_hw(struct bigmac *bp, int from_irq)
 {
        void __iomem *gregs        = bp->gregs;
        void __iomem *cregs        = bp->creg;
@@ -741,7 +752,7 @@ static void bigmac_is_medium_rare(struct bigmac *bp, u32 qec_status, u32 bmac_st
        }
 
        printk(" RESET\n");
-       bigmac_init(bp, 1);
+       bigmac_init_hw(bp, 1);
 }
 
 /* BigMAC transmit complete service routines. */
@@ -767,9 +778,9 @@ static void bigmac_tx(struct bigmac *bp)
                skb = bp->tx_skbs[elem];
                bp->enet_stats.tx_packets++;
                bp->enet_stats.tx_bytes += skb->len;
-               sbus_unmap_single(bp->bigmac_sdev,
-                                 this->tx_addr, skb->len,
-                                 SBUS_DMA_TODEVICE);
+               dma_unmap_single(&bp->bigmac_op->dev,
+                                this->tx_addr, skb->len,
+                                DMA_TO_DEVICE);
 
                DTX(("skb(%p) ", skb));
                bp->tx_skbs[elem] = NULL;
@@ -822,18 +833,19 @@ static void bigmac_rx(struct bigmac *bp)
                                drops++;
                                goto drop_it;
                        }
-                       sbus_unmap_single(bp->bigmac_sdev,
-                                         this->rx_addr,
-                                         RX_BUF_ALLOC_SIZE - 34,
-                                         SBUS_DMA_FROMDEVICE);
+                       dma_unmap_single(&bp->bigmac_op->dev,
+                                        this->rx_addr,
+                                        RX_BUF_ALLOC_SIZE - 34,
+                                        DMA_FROM_DEVICE);
                        bp->rx_skbs[elem] = new_skb;
                        new_skb->dev = bp->dev;
                        skb_put(new_skb, ETH_FRAME_LEN);
                        skb_reserve(new_skb, 34);
-                       this->rx_addr = sbus_map_single(bp->bigmac_sdev,
-                                                       new_skb->data,
-                                                       RX_BUF_ALLOC_SIZE - 34,
-                                                       SBUS_DMA_FROMDEVICE);
+                       this->rx_addr =
+                               dma_map_single(&bp->bigmac_op->dev,
+                                              new_skb->data,
+                                              RX_BUF_ALLOC_SIZE - 34,
+                                              DMA_FROM_DEVICE);
                        this->rx_flags =
                                (RXD_OWN | ((RX_BUF_ALLOC_SIZE - 34) & RXD_LENGTH));
 
@@ -846,16 +858,15 @@ static void bigmac_rx(struct bigmac *bp)
                                drops++;
                                goto drop_it;
                        }
-                       copy_skb->dev = bp->dev;
                        skb_reserve(copy_skb, 2);
                        skb_put(copy_skb, len);
-                       sbus_dma_sync_single_for_cpu(bp->bigmac_sdev,
-                                                    this->rx_addr, len,
-                                                    SBUS_DMA_FROMDEVICE);
-                       eth_copy_and_sum(copy_skb, (unsigned char *)skb->data, len, 0);
-                       sbus_dma_sync_single_for_device(bp->bigmac_sdev,
-                                                       this->rx_addr, len,
-                                                       SBUS_DMA_FROMDEVICE);
+                       dma_sync_single_for_cpu(&bp->bigmac_op->dev,
+                                               this->rx_addr, len,
+                                               DMA_FROM_DEVICE);
+                       skb_copy_to_linear_data(copy_skb, (unsigned char *)skb->data, len);
+                       dma_sync_single_for_device(&bp->bigmac_op->dev,
+                                                  this->rx_addr, len,
+                                                  DMA_FROM_DEVICE);
 
                        /* Reuse original ring buffer. */
                        this->rx_flags =
@@ -867,7 +878,6 @@ static void bigmac_rx(struct bigmac *bp)
                /* No checksums done by the BigMAC ;-( */
                skb->protocol = eth_type_trans(skb, bp->dev);
                netif_rx(skb);
-               bp->dev->last_rx = jiffies;
                bp->enet_stats.rx_packets++;
                bp->enet_stats.rx_bytes += len;
        next:
@@ -879,7 +889,7 @@ static void bigmac_rx(struct bigmac *bp)
                printk(KERN_NOTICE "%s: Memory squeeze, deferring packet.\n", bp->dev->name);
 }
 
-static irqreturn_t bigmac_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t bigmac_interrupt(int irq, void *dev_id)
 {
        struct bigmac *bp = (struct bigmac *) dev_id;
        u32 qec_status, bmac_status;
@@ -906,16 +916,16 @@ static irqreturn_t bigmac_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 
 static int bigmac_open(struct net_device *dev)
 {
-       struct bigmac *bp = (struct bigmac *) dev->priv;
+       struct bigmac *bp = netdev_priv(dev);
        int ret;
 
-       ret = request_irq(dev->irq, &bigmac_interrupt, SA_SHIRQ, dev->name, bp);
+       ret = request_irq(dev->irq, bigmac_interrupt, IRQF_SHARED, dev->name, bp);
        if (ret) {
                printk(KERN_ERR "BIGMAC: Can't order irq %d to go.\n", dev->irq);
                return ret;
        }
        init_timer(&bp->bigmac_timer);
-       ret = bigmac_init(bp, 0);
+       ret = bigmac_init_hw(bp, 0);
        if (ret)
                free_irq(dev->irq, bp);
        return ret;
@@ -923,7 +933,7 @@ static int bigmac_open(struct net_device *dev)
 
 static int bigmac_close(struct net_device *dev)
 {
-       struct bigmac *bp = (struct bigmac *) dev->priv;
+       struct bigmac *bp = netdev_priv(dev);
 
        del_timer(&bp->bigmac_timer);
        bp->timer_state = asleep;
@@ -937,21 +947,22 @@ static int bigmac_close(struct net_device *dev)
 
 static void bigmac_tx_timeout(struct net_device *dev)
 {
-       struct bigmac *bp = (struct bigmac *) dev->priv;
+       struct bigmac *bp = netdev_priv(dev);
 
-       bigmac_init(bp, 0);
+       bigmac_init_hw(bp, 0);
        netif_wake_queue(dev);
 }
 
 /* Put a packet on the wire. */
 static int bigmac_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
-       struct bigmac *bp = (struct bigmac *) dev->priv;
+       struct bigmac *bp = netdev_priv(dev);
        int len, entry;
        u32 mapping;
 
        len = skb->len;
-       mapping = sbus_map_single(bp->bigmac_sdev, skb->data, len, SBUS_DMA_TODEVICE);
+       mapping = dma_map_single(&bp->bigmac_op->dev, skb->data,
+                                len, DMA_TO_DEVICE);
 
        /* Avoid a race... */
        spin_lock_irq(&bp->lock);
@@ -971,14 +982,12 @@ static int bigmac_start_xmit(struct sk_buff *skb, struct net_device *dev)
        sbus_writel(CREG_CTRL_TWAKEUP, bp->creg + CREG_CTRL);
 
 
-       dev->trans_start = jiffies;
-
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 static struct net_device_stats *bigmac_get_stats(struct net_device *dev)
 {
-       struct bigmac *bp = (struct bigmac *) dev->priv;
+       struct bigmac *bp = netdev_priv(dev);
 
        bigmac_get_counters(bp, bp->bregs);
        return &bp->enet_stats;
@@ -986,10 +995,9 @@ static struct net_device_stats *bigmac_get_stats(struct net_device *dev)
 
 static void bigmac_set_multicast(struct net_device *dev)
 {
-       struct bigmac *bp = (struct bigmac *) dev->priv;
+       struct bigmac *bp = netdev_priv(dev);
        void __iomem *bregs = bp->bregs;
-       struct dev_mc_list *dmi = dev->mc_list;
-       char *addrs;
+       struct netdev_hw_addr *ha;
        int i;
        u32 tmp, crc;
 
@@ -1002,7 +1010,7 @@ static void bigmac_set_multicast(struct net_device *dev)
        while ((sbus_readl(bregs + BMAC_RXCFG) & BIGMAC_RXCFG_ENABLE) != 0)
                udelay(20);
 
-       if ((dev->flags & IFF_ALLMULTI) || (dev->mc_count > 64)) {
+       if ((dev->flags & IFF_ALLMULTI) || (netdev_mc_count(dev) > 64)) {
                sbus_writel(0xffff, bregs + BMAC_HTABLE0);
                sbus_writel(0xffff, bregs + BMAC_HTABLE1);
                sbus_writel(0xffff, bregs + BMAC_HTABLE2);
@@ -1017,14 +1025,8 @@ static void bigmac_set_multicast(struct net_device *dev)
                for (i = 0; i < 4; i++)
                        hash_table[i] = 0;
 
-               for (i = 0; i < dev->mc_count; i++) {
-                       addrs = dmi->dmi_addr;
-                       dmi = dmi->next;
-
-                       if (!(*addrs & 1))
-                               continue;
-
-                       crc = ether_crc_le(6, addrs);
+               netdev_for_each_mc_addr(ha, dev) {
+                       crc = ether_crc_le(6, ha->addr);
                        crc >>= 26;
                        hash_table[crc >> 4] |= 1 << (crc & 0xf);
                }
@@ -1043,17 +1045,13 @@ static void bigmac_set_multicast(struct net_device *dev)
 /* Ethtool support... */
 static void bigmac_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
 {
-       struct bigmac *bp = dev->priv;
-
        strcpy(info->driver, "sunbmac");
        strcpy(info->version, "2.0");
-       sprintf(info->bus_info, "SBUS:%d",
-               bp->qec_sdev->slot);
 }
 
 static u32 bigmac_get_link(struct net_device *dev)
 {
-       struct bigmac *bp = dev->priv;
+       struct bigmac *bp = netdev_priv(dev);
 
        spin_lock_irq(&bp->lock);
        bp->sw_bmsr = bigmac_tcvr_read(bp, bp->tregs, BIGMAC_BMSR);
@@ -1062,52 +1060,55 @@ static u32 bigmac_get_link(struct net_device *dev)
        return (bp->sw_bmsr & BMSR_LSTATUS);
 }
 
-static struct ethtool_ops bigmac_ethtool_ops = {
+static const struct ethtool_ops bigmac_ethtool_ops = {
        .get_drvinfo            = bigmac_get_drvinfo,
        .get_link               = bigmac_get_link,
 };
 
-static int __init bigmac_ether_init(struct sbus_dev *qec_sdev)
+static const struct net_device_ops bigmac_ops = {
+       .ndo_open               = bigmac_open,
+       .ndo_stop               = bigmac_close,
+       .ndo_start_xmit         = bigmac_start_xmit,
+       .ndo_get_stats          = bigmac_get_stats,
+       .ndo_set_multicast_list = bigmac_set_multicast,
+       .ndo_tx_timeout         = bigmac_tx_timeout,
+       .ndo_change_mtu         = eth_change_mtu,
+       .ndo_set_mac_address    = eth_mac_addr,
+       .ndo_validate_addr      = eth_validate_addr,
+};
+
+static int __devinit bigmac_ether_init(struct platform_device *op,
+                                      struct platform_device *qec_op)
 {
-       struct net_device *dev;
        static int version_printed;
-       struct bigmac *bp;
+       struct net_device *dev;
        u8 bsizes, bsizes_more;
+       struct bigmac *bp;
        int i;
 
        /* Get a new device struct for this interface. */
        dev = alloc_etherdev(sizeof(struct bigmac));
        if (!dev)
                return -ENOMEM;
-       SET_MODULE_OWNER(dev);
 
        if (version_printed++ == 0)
                printk(KERN_INFO "%s", version);
 
-       dev->base_addr = (long) qec_sdev;
        for (i = 0; i < 6; i++)
                dev->dev_addr[i] = idprom->id_ethaddr[i];
 
        /* Setup softc, with backpointers to QEC and BigMAC SBUS device structs. */
-       bp = dev->priv;
-       bp->qec_sdev = qec_sdev;
-       bp->bigmac_sdev = qec_sdev->child;
+       bp = netdev_priv(dev);
+       bp->qec_op = qec_op;
+       bp->bigmac_op = op;
 
-       spin_lock_init(&bp->lock);
+       SET_NETDEV_DEV(dev, &op->dev);
 
-       /* Verify the registers we expect, are actually there. */
-       if ((bp->bigmac_sdev->num_registers != 3) ||
-          (bp->qec_sdev->num_registers != 2)) {
-               printk(KERN_ERR "BIGMAC: Device does not have 2 and 3 regs, it has %d and %d.\n",
-                      bp->qec_sdev->num_registers,
-                      bp->bigmac_sdev->num_registers);
-               printk(KERN_ERR "BIGMAC: Would you like that for here or to go?\n");
-               goto fail_and_cleanup;
-       }
+       spin_lock_init(&bp->lock);
 
        /* Map in QEC global control registers. */
-       bp->gregs = sbus_ioremap(&bp->qec_sdev->resource[0], 0,
-                                GLOB_REG_SIZE, "BigMAC QEC GLobal Regs");
+       bp->gregs = of_ioremap(&qec_op->resource[0], 0,
+                              GLOB_REG_SIZE, "BigMAC QEC GLobal Regs");
        if (!bp->gregs) {
                printk(KERN_ERR "BIGMAC: Cannot map QEC global registers.\n");
                goto fail_and_cleanup;
@@ -1124,13 +1125,8 @@ static int __init bigmac_ether_init(struct sbus_dev *qec_sdev)
                goto fail_and_cleanup;
 
        /* Get supported SBUS burst sizes. */
-       bsizes = prom_getintdefault(bp->qec_sdev->prom_node,
-                                   "burst-sizes",
-                                   0xff);
-
-       bsizes_more = prom_getintdefault(bp->qec_sdev->bus->prom_node,
-                                        "burst-sizes",
-                                        0xff);
+       bsizes = of_getintprop_default(qec_op->dev.of_node, "burst-sizes", 0xff);
+       bsizes_more = of_getintprop_default(qec_op->dev.of_node, "burst-sizes", 0xff);
 
        bsizes &= 0xff;
        if (bsizes_more != 0xff)
@@ -1144,16 +1140,16 @@ static int __init bigmac_ether_init(struct sbus_dev *qec_sdev)
        qec_init(bp);
 
        /* Map in the BigMAC channel registers. */
-       bp->creg = sbus_ioremap(&bp->bigmac_sdev->resource[0], 0,
-                               CREG_REG_SIZE, "BigMAC QEC Channel Regs");
+       bp->creg = of_ioremap(&op->resource[0], 0,
+                             CREG_REG_SIZE, "BigMAC QEC Channel Regs");
        if (!bp->creg) {
                printk(KERN_ERR "BIGMAC: Cannot map QEC channel registers.\n");
                goto fail_and_cleanup;
        }
 
        /* Map in the BigMAC control registers. */
-       bp->bregs = sbus_ioremap(&bp->bigmac_sdev->resource[1], 0,
-                                BMAC_REG_SIZE, "BigMAC Primary Regs");
+       bp->bregs = of_ioremap(&op->resource[1], 0,
+                              BMAC_REG_SIZE, "BigMAC Primary Regs");
        if (!bp->bregs) {
                printk(KERN_ERR "BIGMAC: Cannot map BigMAC primary registers.\n");
                goto fail_and_cleanup;
@@ -1162,8 +1158,8 @@ static int __init bigmac_ether_init(struct sbus_dev *qec_sdev)
        /* Map in the BigMAC transceiver registers, this is how you poke at
         * the BigMAC's PHY.
         */
-       bp->tregs = sbus_ioremap(&bp->bigmac_sdev->resource[2], 0,
-                                TCVR_REG_SIZE, "BigMAC Transceiver Regs");
+       bp->tregs = of_ioremap(&op->resource[2], 0,
+                              TCVR_REG_SIZE, "BigMAC Transceiver Regs");
        if (!bp->tregs) {
                printk(KERN_ERR "BIGMAC: Cannot map BigMAC transceiver registers.\n");
                goto fail_and_cleanup;
@@ -1173,17 +1169,17 @@ static int __init bigmac_ether_init(struct sbus_dev *qec_sdev)
        bigmac_stop(bp);
 
        /* Allocate transmit/receive descriptor DVMA block. */
-       bp->bmac_block = sbus_alloc_consistent(bp->bigmac_sdev,
-                                              PAGE_SIZE,
-                                              &bp->bblock_dvma);
+       bp->bmac_block = dma_alloc_coherent(&bp->bigmac_op->dev,
+                                           PAGE_SIZE,
+                                           &bp->bblock_dvma, GFP_ATOMIC);
        if (bp->bmac_block == NULL || bp->bblock_dvma == 0) {
                printk(KERN_ERR "BIGMAC: Cannot allocate consistent DMA.\n");
                goto fail_and_cleanup;
        }
 
        /* Get the board revision of this BigMAC. */
-       bp->board_rev = prom_getintdefault(bp->bigmac_sdev->prom_node,
-                                          "board-version", 1);
+       bp->board_rev = of_getintprop_default(bp->bigmac_op->dev.of_node,
+                                             "board-version", 1);
 
        /* Init auto-negotiation timer state. */
        init_timer(&bp->bigmac_timer);
@@ -1194,20 +1190,12 @@ static int __init bigmac_ether_init(struct sbus_dev *qec_sdev)
        bp->dev = dev;
 
        /* Set links to our BigMAC open and close routines. */
-       dev->open = &bigmac_open;
-       dev->stop = &bigmac_close;
-       dev->hard_start_xmit = &bigmac_start_xmit;
        dev->ethtool_ops = &bigmac_ethtool_ops;
-
-       /* Set links to BigMAC statistic and multi-cast loading code. */
-       dev->get_stats = &bigmac_get_stats;
-       dev->set_multicast_list = &bigmac_set_multicast;
-
-       dev->tx_timeout = &bigmac_tx_timeout;
+       dev->netdev_ops = &bigmac_ops;
        dev->watchdog_timeo = 5*HZ;
 
        /* Finish net device registration. */
-       dev->irq = bp->bigmac_sdev->irqs[0];
+       dev->irq = bp->bigmac_op->archdata.irqs[0];
        dev->dma = 0;
 
        if (register_netdev(dev)) {
@@ -1215,17 +1203,10 @@ static int __init bigmac_ether_init(struct sbus_dev *qec_sdev)
                goto fail_and_cleanup;
        }
 
-       /* Put us into the list of instances attached for later driver
-        * exit.
-        */
-       bp->next_module = root_bigmac_dev;
-       root_bigmac_dev = bp;
+       dev_set_drvdata(&bp->bigmac_op->dev, bp);
 
-       printk(KERN_INFO "%s: BigMAC 100baseT Ethernet ", dev->name);
-       for (i = 0; i < 6; i++)
-               printk("%2.2x%c", dev->dev_addr[i],
-                      i == 5 ? ' ' : ':');
-       printk("\n");
+       printk(KERN_INFO "%s: BigMAC 100baseT Ethernet %pM\n",
+              dev->name, dev->dev_addr);
 
        return 0;
 
@@ -1233,92 +1214,93 @@ fail_and_cleanup:
        /* Something went wrong, undo whatever we did so far. */
        /* Free register mappings if any. */
        if (bp->gregs)
-               sbus_iounmap(bp->gregs, GLOB_REG_SIZE);
+               of_iounmap(&qec_op->resource[0], bp->gregs, GLOB_REG_SIZE);
        if (bp->creg)
-               sbus_iounmap(bp->creg, CREG_REG_SIZE);
+               of_iounmap(&op->resource[0], bp->creg, CREG_REG_SIZE);
        if (bp->bregs)
-               sbus_iounmap(bp->bregs, BMAC_REG_SIZE);
+               of_iounmap(&op->resource[1], bp->bregs, BMAC_REG_SIZE);
        if (bp->tregs)
-               sbus_iounmap(bp->tregs, TCVR_REG_SIZE);
+               of_iounmap(&op->resource[2], bp->tregs, TCVR_REG_SIZE);
 
        if (bp->bmac_block)
-               sbus_free_consistent(bp->bigmac_sdev,
-                                    PAGE_SIZE,
-                                    bp->bmac_block,
-                                    bp->bblock_dvma);
+               dma_free_coherent(&bp->bigmac_op->dev,
+                                 PAGE_SIZE,
+                                 bp->bmac_block,
+                                 bp->bblock_dvma);
 
-       /* This also frees the co-located 'dev->priv' */
+       /* This also frees the co-located private data */
        free_netdev(dev);
        return -ENODEV;
 }
 
-/* QEC can be the parent of either QuadEthernet or
- * a BigMAC.  We want the latter.
+/* QEC can be the parent of either QuadEthernet or a BigMAC.  We want
+ * the latter.
  */
-static int __init bigmac_match(struct sbus_dev *sdev)
+static int __devinit bigmac_sbus_probe(struct platform_device *op)
 {
-       struct sbus_dev *child = sdev->child;
+       struct device *parent = op->dev.parent;
+       struct platform_device *qec_op;
 
-       if (strcmp(sdev->prom_name, "qec") != 0)
-               return 0;
+       qec_op = to_platform_device(parent);
 
-       if (child == NULL)
-               return 0;
+       return bigmac_ether_init(op, qec_op);
+}
 
-       if (strcmp(child->prom_name, "be") != 0)
-               return 0;
+static int __devexit bigmac_sbus_remove(struct platform_device *op)
+{
+       struct bigmac *bp = dev_get_drvdata(&op->dev);
+       struct device *parent = op->dev.parent;
+       struct net_device *net_dev = bp->dev;
+       struct platform_device *qec_op;
+
+       qec_op = to_platform_device(parent);
+
+       unregister_netdev(net_dev);
+
+       of_iounmap(&qec_op->resource[0], bp->gregs, GLOB_REG_SIZE);
+       of_iounmap(&op->resource[0], bp->creg, CREG_REG_SIZE);
+       of_iounmap(&op->resource[1], bp->bregs, BMAC_REG_SIZE);
+       of_iounmap(&op->resource[2], bp->tregs, TCVR_REG_SIZE);
+       dma_free_coherent(&op->dev,
+                         PAGE_SIZE,
+                         bp->bmac_block,
+                         bp->bblock_dvma);
+
+       free_netdev(net_dev);
+
+       dev_set_drvdata(&op->dev, NULL);
 
-       return 1;
+       return 0;
 }
 
-static int __init bigmac_probe(void)
+static const struct of_device_id bigmac_sbus_match[] = {
+       {
+               .name = "be",
+       },
+       {},
+};
+
+MODULE_DEVICE_TABLE(of, bigmac_sbus_match);
+
+static struct platform_driver bigmac_sbus_driver = {
+       .driver = {
+               .name = "sunbmac",
+               .owner = THIS_MODULE,
+               .of_match_table = bigmac_sbus_match,
+       },
+       .probe          = bigmac_sbus_probe,
+       .remove         = __devexit_p(bigmac_sbus_remove),
+};
+
+static int __init bigmac_init(void)
 {
-       struct sbus_bus *sbus;
-       struct sbus_dev *sdev = NULL;
-       static int called;
-       int cards = 0, v;
-
-       root_bigmac_dev = NULL;
-
-       if (called)
-               return -ENODEV;
-       called++;
-
-       for_each_sbus(sbus) {
-               for_each_sbusdev(sdev, sbus) {
-                       if (bigmac_match(sdev)) {
-                               cards++;
-                               if ((v = bigmac_ether_init(sdev)))
-                                       return v;
-                       }
-               }
-       }
-       if (!cards)
-               return -ENODEV;
-       return 0;
+       return platform_driver_register(&bigmac_sbus_driver);
 }
 
-static void __exit bigmac_cleanup(void)
+static void __exit bigmac_exit(void)
 {
-       while (root_bigmac_dev) {
-               struct bigmac *bp = root_bigmac_dev;
-               struct bigmac *bp_nxt = root_bigmac_dev->next_module;
-
-               sbus_iounmap(bp->gregs, GLOB_REG_SIZE);
-               sbus_iounmap(bp->creg, CREG_REG_SIZE);
-               sbus_iounmap(bp->bregs, BMAC_REG_SIZE);
-               sbus_iounmap(bp->tregs, TCVR_REG_SIZE);
-               sbus_free_consistent(bp->bigmac_sdev,
-                                    PAGE_SIZE,
-                                    bp->bmac_block,
-                                    bp->bblock_dvma);
-
-               unregister_netdev(bp->dev);
-               free_netdev(bp->dev);
-               root_bigmac_dev = bp_nxt;
-       }
+       platform_driver_unregister(&bigmac_sbus_driver);
 }
 
-module_init(bigmac_probe);
-module_exit(bigmac_cleanup);
-MODULE_LICENSE("GPL");
+module_init(bigmac_init);
+module_exit(bigmac_exit);