smsc95xx: Add module params to read MAC address
[linux-2.6.git] / drivers / net / sunlance.c
index 704301a..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>
@@ -94,6 +93,7 @@ static char lancestr[] = "LANCE";
 #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>
@@ -250,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       */
@@ -265,8 +265,8 @@ struct lance_private {
        char                   *name;
        dma_addr_t              init_block_dvma;
        struct net_device      *dev;              /* Backpointer        */
-       struct of_device       *op;
-       struct of_device       *lebuffer;
+       struct platform_device       *op;
+       struct platform_device       *lebuffer;
        struct timer_list       multicast_timer;
 };
 
@@ -343,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;
@@ -399,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);
@@ -555,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++;
                }
 
@@ -726,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++;
                }
 
@@ -925,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;
@@ -1005,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;
 }
@@ -1056,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);
@@ -1162,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;
 
@@ -1198,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;
@@ -1277,7 +1266,7 @@ static void lance_free_hwresources(struct lance_private *lp)
        if (lp->lregs)
                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]));
@@ -1300,28 +1289,30 @@ static void sparc_lance_get_drvinfo(struct net_device *dev, struct ethtool_drvin
        strcpy(info->version, "2.02");
 }
 
-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 int __devinit sparc_lance_probe_one(struct of_device *op,
-                                          struct of_device *ledma,
-                                          struct of_device *lebuffer)
+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 platform_device *op,
+                                          struct platform_device *ledma,
+                                          struct platform_device *lebuffer)
 {
-       struct device_node *dp = op->node;
+       struct device_node *dp = op->dev.of_node;
        static unsigned version_printed;
        struct lance_private *lp;
        struct net_device *dev;
-       DECLARE_MAC_BUF(mac);
        int    i;
 
        dev = alloc_etherdev(sizeof(struct lance_private) + 8);
@@ -1405,7 +1396,7 @@ static int __devinit sparc_lance_probe_one(struct of_device *op,
 
        lp->burst_sizes = 0;
        if (lp->ledma) {
-               struct device_node *ledma_dp = ledma->node;
+               struct device_node *ledma_dp = ledma->dev.of_node;
                struct device_node *sbus_dp;
                unsigned int sbmask;
                const char *prop;
@@ -1465,15 +1456,11 @@ no_link_test:
 
        lp->dev = dev;
        SET_NETDEV_DEV(dev, &op->dev);
-       dev->open = &lance_open;
-       dev->stop = &lance_close;
-       dev->hard_start_xmit = &lance_start_xmit;
-       dev->tx_timeout = &lance_tx_timeout;
        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 = op->irqs[0];
+       dev->irq = op->archdata.irqs[0];
 
        /* We cannot sleep if the chip is busy during a
         * multicast list update event, because such events
@@ -1482,7 +1469,7 @@ 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");
@@ -1491,8 +1478,8 @@ no_link_test:
 
        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;
 
@@ -1502,10 +1489,10 @@ fail:
        return -ENODEV;
 }
 
-static int __devinit sunlance_sbus_probe(struct of_device *op, const struct of_device_id *match)
+static int __devinit sunlance_sbus_probe(struct platform_device *op)
 {
-       struct of_device *parent = to_of_device(op->dev.parent);
-       struct device_node *parent_dp = parent->node;
+       struct platform_device *parent = to_platform_device(op->dev.parent);
+       struct device_node *parent_dp = parent->dev.of_node;
        int err;
 
        if (!strcmp(parent_dp->name, "ledma")) {
@@ -1518,7 +1505,7 @@ static int __devinit sunlance_sbus_probe(struct of_device *op, const struct of_d
        return err;
 }
 
-static int __devexit sunlance_sbus_remove(struct of_device *op)
+static int __devexit sunlance_sbus_remove(struct platform_device *op)
 {
        struct lance_private *lp = dev_get_drvdata(&op->dev);
        struct net_device *net_dev = lp->dev;
@@ -1543,9 +1530,12 @@ static const 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),
 };
@@ -1554,12 +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, &of_bus_type);
+       return platform_driver_register(&sunlance_sbus_driver);
 }
 
 static void __exit sparc_lance_exit(void)
 {
-       of_unregister_driver(&sunlance_sbus_driver);
+       platform_driver_unregister(&sunlance_sbus_driver);
 }
 
 module_init(sparc_lance_init);