bfin_mac: convert to net_device_ops
[safe/jmp/linux-2.6] / drivers / net / bmac.c
index 4adfe7b..44d015f 100644 (file)
@@ -18,6 +18,8 @@
 #include <linux/init.h>
 #include <linux/spinlock.h>
 #include <linux/crc32.h>
+#include <linux/bitrev.h>
+#include <linux/ethtool.h>
 #include <asm/prom.h>
 #include <asm/dbdma.h>
 #include <asm/io.h>
@@ -73,7 +75,6 @@ struct bmac_data {
        int tx_fill;
        int tx_empty;
        unsigned char tx_fullup;
-       struct net_device_stats stats;
        struct timer_list tx_timeout;
        int timeout_active;
        int sleeping;
@@ -140,11 +141,9 @@ static unsigned char *bmac_emergency_rxbuf;
        + (N_RX_RING + N_TX_RING + 4) * sizeof(struct dbdma_cmd) \
        + sizeof(struct sk_buff_head))
 
-static unsigned char bitrev(unsigned char b);
 static int bmac_open(struct net_device *dev);
 static int bmac_close(struct net_device *dev);
 static int bmac_transmit_packet(struct sk_buff *skb, struct net_device *dev);
-static struct net_device_stats *bmac_stats(struct net_device *dev);
 static void bmac_set_multicast(struct net_device *dev);
 static void bmac_reset_and_enable(struct net_device *dev);
 static void bmac_start_chip(struct net_device *dev);
@@ -152,9 +151,9 @@ static void bmac_init_chip(struct net_device *dev);
 static void bmac_init_registers(struct net_device *dev);
 static void bmac_enable_and_reset_chip(struct net_device *dev);
 static int bmac_set_address(struct net_device *dev, void *addr);
-static irqreturn_t bmac_misc_intr(int irq, void *dev_id, struct pt_regs *regs);
-static irqreturn_t bmac_txdma_intr(int irq, void *dev_id, struct pt_regs *regs);
-static irqreturn_t bmac_rxdma_intr(int irq, void *dev_id, struct pt_regs *regs);
+static irqreturn_t bmac_misc_intr(int irq, void *dev_id);
+static irqreturn_t bmac_txdma_intr(int irq, void *dev_id);
+static irqreturn_t bmac_rxdma_intr(int irq, void *dev_id);
 static void bmac_set_timeout(struct net_device *dev);
 static void bmac_tx_timeout(unsigned long data);
 static int bmac_output(struct sk_buff *skb, struct net_device *dev);
@@ -586,18 +585,6 @@ bmac_construct_rxbuff(struct sk_buff *skb, volatile struct dbdma_cmd *cp)
                     virt_to_bus(addr), 0);
 }
 
-/* Bit-reverse one byte of an ethernet hardware address. */
-static unsigned char
-bitrev(unsigned char b)
-{
-       int d = 0, i;
-
-       for (i = 0; i < 8; ++i, b >>= 1)
-               d = (d << 1) | (b & 1);
-       return d;
-}
-
-
 static void
 bmac_init_tx_ring(struct bmac_data *bp)
 {
@@ -679,7 +666,7 @@ static int bmac_transmit_packet(struct sk_buff *skb, struct net_device *dev)
        bp->tx_bufs[bp->tx_fill] = skb;
        bp->tx_fill = i;
 
-       bp->stats.tx_bytes += skb->len;
+       dev->stats.tx_bytes += skb->len;
 
        dbdma_continue(td);
 
@@ -688,7 +675,7 @@ static int bmac_transmit_packet(struct sk_buff *skb, struct net_device *dev)
 
 static int rxintcount;
 
-static irqreturn_t bmac_rxdma_intr(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t bmac_rxdma_intr(int irq, void *dev_id)
 {
        struct net_device *dev = (struct net_device *) dev_id;
        struct bmac_data *bp = netdev_priv(dev);
@@ -718,8 +705,8 @@ static irqreturn_t bmac_rxdma_intr(int irq, void *dev_id, struct pt_regs *regs)
                nb = RX_BUFLEN - residual - 2;
                if (nb < (ETHERMINPACKET - ETHERCRC)) {
                        skb = NULL;
-                       bp->stats.rx_length_errors++;
-                       bp->stats.rx_errors++;
+                       dev->stats.rx_length_errors++;
+                       dev->stats.rx_errors++;
                } else {
                        skb = bp->rx_bufs[i];
                        bp->rx_bufs[i] = NULL;
@@ -727,16 +714,13 @@ static irqreturn_t bmac_rxdma_intr(int irq, void *dev_id, struct pt_regs *regs)
                if (skb != NULL) {
                        nb -= ETHERCRC;
                        skb_put(skb, nb);
-                       skb->dev = dev;
                        skb->protocol = eth_type_trans(skb, dev);
                        netif_rx(skb);
-                       dev->last_rx = jiffies;
-                       ++bp->stats.rx_packets;
-                       bp->stats.rx_bytes += nb;
+                       ++dev->stats.rx_packets;
+                       dev->stats.rx_bytes += nb;
                } else {
-                       ++bp->stats.rx_dropped;
+                       ++dev->stats.rx_dropped;
                }
-               dev->last_rx = jiffies;
                if ((skb = bp->rx_bufs[i]) == NULL) {
                        bp->rx_bufs[i] = skb = dev_alloc_skb(RX_BUFLEN+2);
                        if (skb != NULL)
@@ -765,7 +749,7 @@ static irqreturn_t bmac_rxdma_intr(int irq, void *dev_id, struct pt_regs *regs)
 
 static int txintcount;
 
-static irqreturn_t bmac_txdma_intr(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t bmac_txdma_intr(int irq, void *dev_id)
 {
        struct net_device *dev = (struct net_device *) dev_id;
        struct bmac_data *bp = netdev_priv(dev);
@@ -797,7 +781,7 @@ static irqreturn_t bmac_txdma_intr(int irq, void *dev_id, struct pt_regs *regs)
                }
 
                if (bp->tx_bufs[bp->tx_empty]) {
-                       ++bp->stats.tx_packets;
+                       ++dev->stats.tx_packets;
                        dev_kfree_skb_irq(bp->tx_bufs[bp->tx_empty]);
                }
                bp->tx_bufs[bp->tx_empty] = NULL;
@@ -819,13 +803,6 @@ static irqreturn_t bmac_txdma_intr(int irq, void *dev_id, struct pt_regs *regs)
        return IRQ_HANDLED;
 }
 
-static struct net_device_stats *bmac_stats(struct net_device *dev)
-{
-       struct bmac_data *p = netdev_priv(dev);
-
-       return &p->stats;
-}
-
 #ifndef SUNHME_MULTICAST
 /* Real fast bit-reversal algorithm, 6-bit values */
 static int reverse6[64] = {
@@ -1082,27 +1059,26 @@ static void bmac_set_multicast(struct net_device *dev)
 
 static int miscintcount;
 
-static irqreturn_t bmac_misc_intr(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t bmac_misc_intr(int irq, void *dev_id)
 {
        struct net_device *dev = (struct net_device *) dev_id;
-       struct bmac_data *bp = netdev_priv(dev);
        unsigned int status = bmread(dev, STATUS);
        if (miscintcount++ < 10) {
                XXDEBUG(("bmac_misc_intr\n"));
        }
        /* XXDEBUG(("bmac_misc_intr, status=%#08x\n", status)); */
-       /*     bmac_txdma_intr_inner(irq, dev_id, regs); */
-       /*   if (status & FrameReceived) bp->stats.rx_dropped++; */
-       if (status & RxErrorMask) bp->stats.rx_errors++;
-       if (status & RxCRCCntExp) bp->stats.rx_crc_errors++;
-       if (status & RxLenCntExp) bp->stats.rx_length_errors++;
-       if (status & RxOverFlow) bp->stats.rx_over_errors++;
-       if (status & RxAlignCntExp) bp->stats.rx_frame_errors++;
-
-       /*   if (status & FrameSent) bp->stats.tx_dropped++; */
-       if (status & TxErrorMask) bp->stats.tx_errors++;
-       if (status & TxUnderrun) bp->stats.tx_fifo_errors++;
-       if (status & TxNormalCollExp) bp->stats.collisions++;
+       /*     bmac_txdma_intr_inner(irq, dev_id); */
+       /*   if (status & FrameReceived) dev->stats.rx_dropped++; */
+       if (status & RxErrorMask) dev->stats.rx_errors++;
+       if (status & RxCRCCntExp) dev->stats.rx_crc_errors++;
+       if (status & RxLenCntExp) dev->stats.rx_length_errors++;
+       if (status & RxOverFlow) dev->stats.rx_over_errors++;
+       if (status & RxAlignCntExp) dev->stats.rx_frame_errors++;
+
+       /*   if (status & FrameSent) dev->stats.tx_dropped++; */
+       if (status & TxErrorMask) dev->stats.tx_errors++;
+       if (status & TxUnderrun) dev->stats.tx_fifo_errors++;
+       if (status & TxNormalCollExp) dev->stats.collisions++;
        return IRQ_HANDLED;
 }
 
@@ -1224,8 +1200,8 @@ bmac_get_station_address(struct net_device *dev, unsigned char *ea)
                {
                        reset_and_select_srom(dev);
                        data = read_srom(dev, i + EnetAddressOffset/2, SROMAddressBits);
-                       ea[2*i]   = bitrev(data & 0x0ff);
-                       ea[2*i+1] = bitrev((data >> 8) & 0x0ff);
+                       ea[2*i]   = bitrev8(data & 0x0ff);
+                       ea[2*i+1] = bitrev8((data >> 8) & 0x0ff);
                }
 }
 
@@ -1259,6 +1235,17 @@ static void bmac_reset_and_enable(struct net_device *dev)
        }
        spin_unlock_irqrestore(&bp->lock, flags);
 }
+static void bmac_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
+{
+       struct bmac_data *bp = netdev_priv(dev);
+       strcpy(info->driver, "bmac");
+       strcpy(info->bus_info, dev_name(&bp->mdev->ofdev.dev));
+}
+
+static const struct ethtool_ops bmac_ethtool_ops = {
+       .get_drvinfo            = bmac_get_drvinfo,
+       .get_link               = ethtool_op_get_link,
+};
 
 static int __devinit bmac_probe(struct macio_dev *mdev, const struct of_device_id *match)
 {
@@ -1273,9 +1260,10 @@ static int __devinit bmac_probe(struct macio_dev *mdev, const struct of_device_i
                printk(KERN_ERR "BMAC: can't use, need 3 addrs and 3 intrs\n");
                return -ENODEV;
        }
-       prop_addr = get_property(macio_get_of_node(mdev), "mac-address", NULL);
+       prop_addr = of_get_property(macio_get_of_node(mdev),
+                       "mac-address", NULL);
        if (prop_addr == NULL) {
-               prop_addr = get_property(macio_get_of_node(mdev),
+               prop_addr = of_get_property(macio_get_of_node(mdev),
                                "local-mac-address", NULL);
                if (prop_addr == NULL) {
                        printk(KERN_ERR "BMAC: Can't get mac-address\n");
@@ -1291,7 +1279,6 @@ static int __devinit bmac_probe(struct macio_dev *mdev, const struct of_device_i
        }
 
        bp = netdev_priv(dev);
-       SET_MODULE_OWNER(dev);
        SET_NETDEV_DEV(dev, &mdev->ofdev.dev);
        macio_set_drvdata(mdev, dev);
 
@@ -1315,7 +1302,7 @@ static int __devinit bmac_probe(struct macio_dev *mdev, const struct of_device_i
 
        rev = addr[0] == 0 && addr[1] == 0xA0;
        for (j = 0; j < 6; ++j)
-               dev->dev_addr[j] = rev? bitrev(addr[j]): addr[j];
+               dev->dev_addr[j] = rev ? bitrev8(addr[j]): addr[j];
 
        /* Enable chip without interrupts for now */
        bmac_enable_and_reset_chip(dev);
@@ -1323,8 +1310,8 @@ static int __devinit bmac_probe(struct macio_dev *mdev, const struct of_device_i
 
        dev->open = bmac_open;
        dev->stop = bmac_close;
+       dev->ethtool_ops = &bmac_ethtool_ops;
        dev->hard_start_xmit = bmac_output;
-       dev->get_stats = bmac_stats;
        dev->set_multicast_list = bmac_set_multicast;
        dev->set_mac_address = bmac_set_address;
 
@@ -1377,9 +1364,8 @@ static int __devinit bmac_probe(struct macio_dev *mdev, const struct of_device_i
                goto err_out_irq2;
        }
 
-       printk(KERN_INFO "%s: BMAC%s at", dev->name, (is_bmac_plus? "+": ""));
-       for (j = 0; j < 6; ++j)
-               printk("%c%.2x", (j? ':': ' '), dev->dev_addr[j]);
+       printk(KERN_INFO "%s: BMAC%s at %pM",
+              dev->name, (is_bmac_plus ? "+" : ""), dev->dev_addr);
        XXDEBUG((", base_addr=%#0lx", dev->base_addr));
        printk("\n");
 
@@ -1542,7 +1528,7 @@ static void bmac_tx_timeout(unsigned long data)
        XXDEBUG((KERN_DEBUG "bmac: tx empty=%d fill=%d fullup=%d\n",
                 bp->tx_empty, bp->tx_fill, bp->tx_fullup));
        i = bp->tx_empty;
-       ++bp->stats.tx_errors;
+       ++dev->stats.tx_errors;
        if (i != bp->tx_fill) {
                dev_kfree_skb(bp->tx_bufs[i]);
                bp->tx_bufs[i] = NULL;