smsc95xx: Add module params to read MAC address
[linux-2.6.git] / drivers / net / sunlance.c
index 6575888..06f2d43 100644 (file)
@@ -78,7 +78,6 @@ static char lancestr[] = "LANCE";
 #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>
@@ -92,6 +91,9 @@ static char lancestr[] = "LANCE";
 #include <linux/ethtool.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/system.h>
 #include <asm/io.h>
@@ -99,7 +101,6 @@ static char lancestr[] = "LANCE";
 #include <asm/pgtable.h>
 #include <asm/byteorder.h>     /* Used by the checksum routines */
 #include <asm/idprom.h>
-#include <asm/sbus.h>
 #include <asm/prom.h>
 #include <asm/auxio.h>         /* For tpe-link-test? setting */
 #include <asm/irq.h>
@@ -249,7 +250,7 @@ struct lance_private {
        int             rx_new, tx_new;
        int             rx_old, tx_old;
 
-       struct of_device *ledma;        /* If set this points to ledma  */
+       struct platform_device *ledma;  /* If set this points to ledma  */
        char            tpe;            /* cable-selection is TPE       */
        char            auto_select;    /* cable-selection by carrier   */
        char            burst_sizes;    /* ledma SBus burst sizes       */
@@ -264,7 +265,8 @@ struct lance_private {
        char                   *name;
        dma_addr_t              init_block_dvma;
        struct net_device      *dev;              /* Backpointer        */
-       struct sbus_dev        *sdev;
+       struct platform_device       *op;
+       struct platform_device       *lebuffer;
        struct timer_list       multicast_timer;
 };
 
@@ -341,7 +343,7 @@ static void lance_init_ring_dvma(struct net_device *dev)
        ib->phys_addr [5] = dev->dev_addr [4];
 
        /* Setup the Tx ring entries */
-       for (i = 0; i <= TX_RING_SIZE; i++) {
+       for (i = 0; i < TX_RING_SIZE; i++) {
                leptr = LANCE_ADDR(aib + libbuff_offset(tx_buf, i));
                ib->btx_ring [i].tmd0      = leptr;
                ib->btx_ring [i].tmd1_hadr = leptr >> 16;
@@ -397,7 +399,7 @@ static void lance_init_ring_pio(struct net_device *dev)
        sbus_writeb(dev->dev_addr[4], &ib->phys_addr[5]);
 
        /* Setup the Tx ring entries */
-       for (i = 0; i <= TX_RING_SIZE; i++) {
+       for (i = 0; i < TX_RING_SIZE; i++) {
                leptr = libbuff_offset(tx_buf, i);
                sbus_writew(leptr,      &ib->btx_ring [i].tmd0);
                sbus_writeb(leptr >> 16,&ib->btx_ring [i].tmd1_hadr);
@@ -553,7 +555,6 @@ static void lance_rx_dvma(struct net_device *dev)
                                         len);
                        skb->protocol = eth_type_trans(skb, dev);
                        netif_rx(skb);
-                       dev->last_rx = jiffies;
                        dev->stats.rx_packets++;
                }
 
@@ -724,7 +725,6 @@ static void lance_rx_pio(struct net_device *dev)
                        lance_piocopy_to_skb(skb, &(ib->rx_buf[entry][0]), len);
                        skb->protocol = eth_type_trans(skb, dev);
                        netif_rx(skb);
-                       dev->last_rx = jiffies;
                        dev->stats.rx_packets++;
                }
 
@@ -923,7 +923,7 @@ static int lance_open(struct net_device *dev)
 
        STOP_LANCE(lp);
 
-       if (request_irq(dev->irq, &lance_interrupt, IRQF_SHARED,
+       if (request_irq(dev->irq, lance_interrupt, IRQF_SHARED,
                        lancestr, (void *) dev)) {
                printk(KERN_ERR "Lance: Can't get irq %d\n", dev->irq);
                return -EAGAIN;
@@ -1003,7 +1003,7 @@ static int lance_reset(struct net_device *dev)
        }
        lp->init_ring(dev);
        load_csrs(lp);
-       dev->trans_start = jiffies;
+       dev->trans_start = jiffies; /* prevent tx timeout */
        status = init_restart_lance(lp);
        return status;
 }
@@ -1054,7 +1054,7 @@ static void lance_piocopy_from_skb(void __iomem *dest, unsigned char *src, int l
                }
                src = (char *) p16;
                break;
-       };
+       }
        if (len >= 2) {
                u16 val = src[0] << 8 | src[1];
                sbus_writew(val, piobuf);
@@ -1160,19 +1160,16 @@ static int lance_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
        spin_unlock_irq(&lp->lock);
 
-       dev->trans_start = jiffies;
        dev_kfree_skb(skb);
 
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 /* taken from the depca driver */
 static void lance_load_multicast(struct net_device *dev)
 {
        struct lance_private *lp = netdev_priv(dev);
-       struct dev_mc_list *dmi = dev->mc_list;
-       char *addrs;
-       int i;
+       struct netdev_hw_addr *ha;
        u32 crc;
        u32 val;
 
@@ -1196,14 +1193,8 @@ static void lance_load_multicast(struct net_device *dev)
                return;
 
        /* Add addresses */
-       for (i = 0; i < dev->mc_count; i++) {
-               addrs = dmi->dmi_addr;
-               dmi   = dmi->next;
-
-               /* multicast address? */
-               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 = crc >> 26;
                if (lp->pio_buffer) {
                        struct lance_init_block __iomem *ib = lp->init_block_iomem;
@@ -1273,18 +1264,18 @@ static void lance_set_multicast_retry(unsigned long _opaque)
 static void lance_free_hwresources(struct lance_private *lp)
 {
        if (lp->lregs)
-               sbus_iounmap(lp->lregs, LANCE_REG_SIZE);
+               of_iounmap(&lp->op->resource[0], lp->lregs, LANCE_REG_SIZE);
        if (lp->dregs) {
-               struct of_device *ledma = lp->ledma;
+               struct platform_device *ledma = lp->ledma;
 
                of_iounmap(&ledma->resource[0], lp->dregs,
                           resource_size(&ledma->resource[0]));
        }
        if (lp->init_block_iomem) {
-               sbus_iounmap(lp->init_block_iomem,
-                            sizeof(struct lance_init_block));
+               of_iounmap(&lp->lebuffer->resource[0], lp->init_block_iomem,
+                          sizeof(struct lance_init_block));
        } else if (lp->init_block_mem) {
-               dma_free_coherent(&lp->sdev->ofdev.dev,
+               dma_free_coherent(&lp->op->dev,
                                  sizeof(struct lance_init_block),
                                  lp->init_block_mem,
                                  lp->init_block_dvma);
@@ -1294,37 +1285,35 @@ static void lance_free_hwresources(struct lance_private *lp)
 /* Ethtool support... */
 static void sparc_lance_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
 {
-       struct lance_private *lp = netdev_priv(dev);
-
        strcpy(info->driver, "sunlance");
        strcpy(info->version, "2.02");
-       sprintf(info->bus_info, "SBUS:%d",
-               lp->sdev->slot);
-}
-
-static u32 sparc_lance_get_link(struct net_device *dev)
-{
-       /* We really do not keep track of this, but this
-        * is better than not reporting anything at all.
-        */
-       return 1;
 }
 
 static const struct ethtool_ops sparc_lance_ethtool_ops = {
        .get_drvinfo            = sparc_lance_get_drvinfo,
-       .get_link               = sparc_lance_get_link,
+       .get_link               = ethtool_op_get_link,
+};
+
+static const struct net_device_ops sparc_lance_ops = {
+       .ndo_open               = lance_open,
+       .ndo_stop               = lance_close,
+       .ndo_start_xmit         = lance_start_xmit,
+       .ndo_set_multicast_list = lance_set_multicast,
+       .ndo_tx_timeout         = lance_tx_timeout,
+       .ndo_change_mtu         = eth_change_mtu,
+       .ndo_set_mac_address    = eth_mac_addr,
+       .ndo_validate_addr      = eth_validate_addr,
 };
 
-static int __devinit sparc_lance_probe_one(struct sbus_dev *sdev,
-                                          struct of_device *ledma,
-                                          struct sbus_dev *lebuffer)
+static int __devinit sparc_lance_probe_one(struct platform_device *op,
+                                          struct platform_device *ledma,
+                                          struct platform_device *lebuffer)
 {
+       struct device_node *dp = op->dev.of_node;
        static unsigned version_printed;
-       struct device_node *dp = sdev->ofdev.node;
-       struct net_device *dev;
        struct lance_private *lp;
+       struct net_device *dev;
        int    i;
-       DECLARE_MAC_BUF(mac);
 
        dev = alloc_etherdev(sizeof(struct lance_private) + 8);
        if (!dev)
@@ -1345,8 +1334,8 @@ static int __devinit sparc_lance_probe_one(struct sbus_dev *sdev,
                dev->dev_addr[i] = idprom->id_ethaddr[i];
 
        /* Get the IO region */
-       lp->lregs = sbus_ioremap(&sdev->resource[0], 0,
-                                LANCE_REG_SIZE, lancestr);
+       lp->lregs = of_ioremap(&op->resource[0], 0,
+                              LANCE_REG_SIZE, lancestr);
        if (!lp->lregs) {
                printk(KERN_ERR "SunLance: Cannot map registers.\n");
                goto fail;
@@ -1364,7 +1353,8 @@ static int __devinit sparc_lance_probe_one(struct sbus_dev *sdev,
                }
        }
 
-       lp->sdev = sdev;
+       lp->op = op;
+       lp->lebuffer = lebuffer;
        if (lebuffer) {
                /* sanity check */
                if (lebuffer->resource[0].start & 7) {
@@ -1372,8 +1362,8 @@ static int __devinit sparc_lance_probe_one(struct sbus_dev *sdev,
                        goto fail;
                }
                lp->init_block_iomem =
-                       sbus_ioremap(&lebuffer->resource[0], 0,
-                                    sizeof(struct lance_init_block), "lebuffer");
+                       of_ioremap(&lebuffer->resource[0], 0,
+                                  sizeof(struct lance_init_block), "lebuffer");
                if (!lp->init_block_iomem) {
                        printk(KERN_ERR "SunLance: Cannot map PIO buffer.\n");
                        goto fail;
@@ -1385,10 +1375,10 @@ static int __devinit sparc_lance_probe_one(struct sbus_dev *sdev,
                lp->tx = lance_tx_pio;
        } else {
                lp->init_block_mem =
-                       dma_alloc_coherent(&sdev->ofdev.dev,
+                       dma_alloc_coherent(&op->dev,
                                           sizeof(struct lance_init_block),
                                           &lp->init_block_dvma, GFP_ATOMIC);
-               if (!lp->init_block_mem || lp->init_block_dvma == 0) {
+               if (!lp->init_block_mem) {
                        printk(KERN_ERR "SunLance: Cannot allocate consistent DMA memory.\n");
                        goto fail;
                }
@@ -1406,9 +1396,10 @@ static int __devinit sparc_lance_probe_one(struct sbus_dev *sdev,
 
        lp->burst_sizes = 0;
        if (lp->ledma) {
-               struct device_node *ledma_dp = ledma->node;
-               const char *prop;
+               struct device_node *ledma_dp = ledma->dev.of_node;
+               struct device_node *sbus_dp;
                unsigned int sbmask;
+               const char *prop;
                u32 csr;
 
                /* Find burst-size property for ledma */
@@ -1416,7 +1407,8 @@ static int __devinit sparc_lance_probe_one(struct sbus_dev *sdev,
                                                        "burst-sizes", 0);
 
                /* ledma may be capable of fast bursts, but sbus may not. */
-               sbmask = of_getintprop_default(ledma_dp, "burst-sizes",
+               sbus_dp = ledma_dp->parent;
+               sbmask = of_getintprop_default(sbus_dp, "burst-sizes",
                                               DMA_BURSTBITS);
                lp->burst_sizes &= sbmask;
 
@@ -1463,18 +1455,12 @@ no_link_test:
                lp->dregs = NULL;
 
        lp->dev = dev;
-       SET_NETDEV_DEV(dev, &sdev->ofdev.dev);
-       dev->open = &lance_open;
-       dev->stop = &lance_close;
-       dev->hard_start_xmit = &lance_start_xmit;
-       dev->tx_timeout = &lance_tx_timeout;
+       SET_NETDEV_DEV(dev, &op->dev);
        dev->watchdog_timeo = 5*HZ;
-       dev->set_multicast_list = &lance_set_multicast;
        dev->ethtool_ops = &sparc_lance_ethtool_ops;
+       dev->netdev_ops = &sparc_lance_ops;
 
-       dev->irq = sdev->irqs[0];
-
-       dev->dma = 0;
+       dev->irq = op->archdata.irqs[0];
 
        /* We cannot sleep if the chip is busy during a
         * multicast list update event, because such events
@@ -1483,17 +1469,17 @@ no_link_test:
         */
        init_timer(&lp->multicast_timer);
        lp->multicast_timer.data = (unsigned long) dev;
-       lp->multicast_timer.function = &lance_set_multicast_retry;
+       lp->multicast_timer.function = lance_set_multicast_retry;
 
        if (register_netdev(dev)) {
                printk(KERN_ERR "SunLance: Cannot register device.\n");
                goto fail;
        }
 
-       dev_set_drvdata(&sdev->ofdev.dev, lp);
+       dev_set_drvdata(&op->dev, lp);
 
-       printk(KERN_INFO "%s: LANCE %s\n",
-              dev->name, print_mac(mac, dev->dev_addr));
+       printk(KERN_INFO "%s: LANCE %pM\n",
+              dev->name, dev->dev_addr);
 
        return 0;
 
@@ -1503,68 +1489,25 @@ fail:
        return -ENODEV;
 }
 
-#ifdef CONFIG_SUN4
-
-#include <asm/sun4paddr.h>
-#include <asm/machines.h>
-
-/* Find all the lance cards on the system and initialize them */
-static struct sbus_dev sun4_sdev;
-static int __devinit sparc_lance_init(void)
-{
-       if ((idprom->id_machtype == (SM_SUN4|SM_4_330)) ||
-           (idprom->id_machtype == (SM_SUN4|SM_4_470))) {
-               memset(&sun4_sdev, 0, sizeof(struct sbus_dev));
-               sun4_sdev.reg_addrs[0].phys_addr = sun4_eth_physaddr;
-               sun4_sdev.irqs[0] = 6;
-               return sparc_lance_probe_one(&sun4_sdev, NULL, NULL);
-       }
-       return -ENODEV;
-}
-
-static int __exit sunlance_sun4_remove(void)
-{
-       struct lance_private *lp = dev_get_drvdata(&sun4_sdev.ofdev.dev);
-       struct net_device *net_dev = lp->dev;
-
-       unregister_netdev(net_dev);
-
-       lance_free_hwresources(lp);
-
-       free_netdev(net_dev);
-
-       dev_set_drvdata(&sun4_sdev.ofdev.dev, NULL);
-
-       return 0;
-}
-
-#else /* !CONFIG_SUN4 */
-
-static int __devinit sunlance_sbus_probe(struct of_device *dev, const struct of_device_id *match)
+static int __devinit sunlance_sbus_probe(struct platform_device *op)
 {
-       struct sbus_dev *sdev = to_sbus_device(&dev->dev);
+       struct platform_device *parent = to_platform_device(op->dev.parent);
+       struct device_node *parent_dp = parent->dev.of_node;
        int err;
 
-       if (sdev->parent) {
-               struct device_node *parent_node = sdev->parent->ofdev.node;
-               struct of_device *parent;
-
-               parent = of_find_device_by_node(parent_node);
-               if (parent && !strcmp(parent->node->name, "ledma")) {
-                       err = sparc_lance_probe_one(sdev, parent, NULL);
-               } else if (parent && !strcmp(parent->node->name, "lebuffer")) {
-                       err = sparc_lance_probe_one(sdev, NULL, to_sbus_device(&parent->dev));
-               } else
-                       err = sparc_lance_probe_one(sdev, NULL, NULL);
+       if (!strcmp(parent_dp->name, "ledma")) {
+               err = sparc_lance_probe_one(op, parent, NULL);
+       } else if (!strcmp(parent_dp->name, "lebuffer")) {
+               err = sparc_lance_probe_one(op, NULL, parent);
        } else
-               err = sparc_lance_probe_one(sdev, NULL, NULL);
+               err = sparc_lance_probe_one(op, NULL, NULL);
 
        return err;
 }
 
-static int __devexit sunlance_sbus_remove(struct of_device *dev)
+static int __devexit sunlance_sbus_remove(struct platform_device *op)
 {
-       struct lance_private *lp = dev_get_drvdata(&dev->dev);
+       struct lance_private *lp = dev_get_drvdata(&op->dev);
        struct net_device *net_dev = lp->dev;
 
        unregister_netdev(net_dev);
@@ -1573,12 +1516,12 @@ static int __devexit sunlance_sbus_remove(struct of_device *dev)
 
        free_netdev(net_dev);
 
-       dev_set_drvdata(&dev->dev, NULL);
+       dev_set_drvdata(&op->dev, NULL);
 
        return 0;
 }
 
-static struct of_device_id sunlance_sbus_match[] = {
+static const struct of_device_id sunlance_sbus_match[] = {
        {
                .name = "le",
        },
@@ -1587,9 +1530,12 @@ static struct of_device_id sunlance_sbus_match[] = {
 
 MODULE_DEVICE_TABLE(of, sunlance_sbus_match);
 
-static struct of_platform_driver sunlance_sbus_driver = {
-       .name           = "sunlance",
-       .match_table    = sunlance_sbus_match,
+static struct platform_driver sunlance_sbus_driver = {
+       .driver = {
+               .name = "sunlance",
+               .owner = THIS_MODULE,
+               .of_match_table = sunlance_sbus_match,
+       },
        .probe          = sunlance_sbus_probe,
        .remove         = __devexit_p(sunlance_sbus_remove),
 };
@@ -1598,17 +1544,12 @@ static struct of_platform_driver sunlance_sbus_driver = {
 /* Find all the lance cards on the system and initialize them */
 static int __init sparc_lance_init(void)
 {
-       return of_register_driver(&sunlance_sbus_driver, &sbus_bus_type);
+       return platform_driver_register(&sunlance_sbus_driver);
 }
-#endif /* !CONFIG_SUN4 */
 
 static void __exit sparc_lance_exit(void)
 {
-#ifdef CONFIG_SUN4
-       sunlance_sun4_remove();
-#else
-       of_unregister_driver(&sunlance_sbus_driver);
-#endif
+       platform_driver_unregister(&sunlance_sbus_driver);
 }
 
 module_init(sparc_lance_init);