Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/roland...
[safe/jmp/linux-2.6] / drivers / net / rionet.c
index df6b738..07eb884 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/delay.h>
 #include <linux/rio.h>
 #include <linux/rio_drv.h>
+#include <linux/slab.h>
 #include <linux/rio_ids.h>
 
 #include <linux/netdevice.h>
@@ -53,7 +54,6 @@ struct rionet_private {
        struct rio_mport *mport;
        struct sk_buff *rx_skb[RIONET_RX_RING_SIZE];
        struct sk_buff *tx_skb[RIONET_TX_RING_SIZE];
-       struct net_device_stats stats;
        int rx_slot;
        int tx_slot;
        int tx_cnt;
@@ -73,12 +73,12 @@ static int rionet_check = 0;
 static int rionet_capable = 1;
 
 /*
- * This is a fast lookup table for for translating TX
+ * This is a fast lookup table for translating TX
  * Ethernet packets into a destination RIO device. It
  * could be made into a hash table to save memory depending
  * on system trade-offs.
  */
-static struct rio_dev *rionet_active[RIO_MAX_ROUTE_ENTRIES];
+static struct rio_dev **rionet_active;
 
 #define is_rionet_capable(pef, src_ops, dst_ops)               \
                        ((pef & RIO_PEF_INB_MBOX) &&            \
@@ -91,17 +91,11 @@ static struct rio_dev *rionet_active[RIO_MAX_ROUTE_ENTRIES];
 #define RIONET_MAC_MATCH(x)    (*(u32 *)x == 0x00010001)
 #define RIONET_GET_DESTID(x)   (*(u16 *)(x + 4))
 
-static struct net_device_stats *rionet_stats(struct net_device *ndev)
-{
-       struct rionet_private *rnet = ndev->priv;
-       return &rnet->stats;
-}
-
 static int rionet_rx_clean(struct net_device *ndev)
 {
        int i;
        int error = 0;
-       struct rionet_private *rnet = ndev->priv;
+       struct rionet_private *rnet = netdev_priv(ndev);
        void *data;
 
        i = rnet->rx_slot;
@@ -120,15 +114,10 @@ static int rionet_rx_clean(struct net_device *ndev)
                error = netif_rx(rnet->rx_skb[i]);
 
                if (error == NET_RX_DROP) {
-                       rnet->stats.rx_dropped++;
-               } else if (error == NET_RX_BAD) {
-                       if (netif_msg_rx_err(rnet))
-                               printk(KERN_WARNING "%s: bad rx packet\n",
-                                      DRV_NAME);
-                       rnet->stats.rx_errors++;
+                       ndev->stats.rx_dropped++;
                } else {
-                       rnet->stats.rx_packets++;
-                       rnet->stats.rx_bytes += RIO_MAX_MSG_SIZE;
+                       ndev->stats.rx_packets++;
+                       ndev->stats.rx_bytes += RIO_MAX_MSG_SIZE;
                }
 
        } while ((i = (i + 1) % RIONET_RX_RING_SIZE) != rnet->rx_slot);
@@ -139,7 +128,7 @@ static int rionet_rx_clean(struct net_device *ndev)
 static void rionet_rx_fill(struct net_device *ndev, int end)
 {
        int i;
-       struct rionet_private *rnet = ndev->priv;
+       struct rionet_private *rnet = netdev_priv(ndev);
 
        i = rnet->rx_slot;
        do {
@@ -158,13 +147,13 @@ static void rionet_rx_fill(struct net_device *ndev, int end)
 static int rionet_queue_tx_msg(struct sk_buff *skb, struct net_device *ndev,
                               struct rio_dev *rdev)
 {
-       struct rionet_private *rnet = ndev->priv;
+       struct rionet_private *rnet = netdev_priv(ndev);
 
        rio_add_outb_message(rnet->mport, rdev, 0, skb->data, skb->len);
        rnet->tx_skb[rnet->tx_slot] = skb;
 
-       rnet->stats.tx_packets++;
-       rnet->stats.tx_bytes += skb->len;
+       ndev->stats.tx_packets++;
+       ndev->stats.tx_bytes += skb->len;
 
        if (++rnet->tx_cnt == RIONET_TX_RING_SIZE)
                netif_stop_queue(ndev);
@@ -182,7 +171,7 @@ static int rionet_queue_tx_msg(struct sk_buff *skb, struct net_device *ndev,
 static int rionet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
 {
        int i;
-       struct rionet_private *rnet = ndev->priv;
+       struct rionet_private *rnet = netdev_priv(ndev);
        struct ethhdr *eth = (struct ethhdr *)skb->data;
        u16 destid;
        unsigned long flags;
@@ -202,7 +191,8 @@ static int rionet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
        }
 
        if (eth->h_dest[0] & 0x01) {
-               for (i = 0; i < RIO_MAX_ROUTE_ENTRIES; i++)
+               for (i = 0; i < RIO_MAX_ROUTE_ENTRIES(rnet->mport->sys_size);
+                               i++)
                        if (rionet_active[i])
                                rionet_queue_tx_msg(skb, ndev,
                                                    rionet_active[i]);
@@ -214,14 +204,14 @@ static int rionet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
 
        spin_unlock_irqrestore(&rnet->tx_lock, flags);
 
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 static void rionet_dbell_event(struct rio_mport *mport, void *dev_id, u16 sid, u16 tid,
                               u16 info)
 {
        struct net_device *ndev = dev_id;
-       struct rionet_private *rnet = ndev->priv;
+       struct rionet_private *rnet = netdev_priv(ndev);
        struct rionet_peer *peer;
 
        if (netif_msg_intr(rnet))
@@ -249,7 +239,7 @@ static void rionet_inb_msg_event(struct rio_mport *mport, void *dev_id, int mbox
 {
        int n;
        struct net_device *ndev = dev_id;
-       struct rionet_private *rnet = (struct rionet_private *)ndev->priv;
+       struct rionet_private *rnet = netdev_priv(ndev);
 
        if (netif_msg_intr(rnet))
                printk(KERN_INFO "%s: inbound message event, mbox %d slot %d\n",
@@ -264,7 +254,7 @@ static void rionet_inb_msg_event(struct rio_mport *mport, void *dev_id, int mbox
 static void rionet_outb_msg_event(struct rio_mport *mport, void *dev_id, int mbox, int slot)
 {
        struct net_device *ndev = dev_id;
-       struct rionet_private *rnet = ndev->priv;
+       struct rionet_private *rnet = netdev_priv(ndev);
 
        spin_lock(&rnet->lock);
 
@@ -293,7 +283,7 @@ static int rionet_open(struct net_device *ndev)
        int i, rc = 0;
        struct rionet_peer *peer, *tmp;
        u32 pwdcsr;
-       struct rionet_private *rnet = ndev->priv;
+       struct rionet_private *rnet = netdev_priv(ndev);
 
        if (netif_msg_ifup(rnet))
                printk(KERN_INFO "%s: open\n", DRV_NAME);
@@ -357,7 +347,7 @@ static int rionet_open(struct net_device *ndev)
 
 static int rionet_close(struct net_device *ndev)
 {
-       struct rionet_private *rnet = (struct rionet_private *)ndev->priv;
+       struct rionet_private *rnet = netdev_priv(ndev);
        struct rionet_peer *peer, *tmp;
        int i;
 
@@ -368,8 +358,7 @@ static int rionet_close(struct net_device *ndev)
        netif_carrier_off(ndev);
 
        for (i = 0; i < RIONET_RX_RING_SIZE; i++)
-               if (rnet->rx_skb[i])
-                       kfree_skb(rnet->rx_skb[i]);
+               kfree_skb(rnet->rx_skb[i]);
 
        list_for_each_entry_safe(peer, tmp, &rionet_peers, node) {
                if (rionet_active[peer->rdev->destid]) {
@@ -392,6 +381,8 @@ static void rionet_remove(struct rio_dev *rdev)
        struct net_device *ndev = NULL;
        struct rionet_peer *peer, *tmp;
 
+       free_pages((unsigned long)rionet_active, rdev->net->hport->sys_size ?
+                                       __ilog2(sizeof(void *)) + 4 : 0);
        unregister_netdev(ndev);
        kfree(ndev);
 
@@ -404,7 +395,7 @@ static void rionet_remove(struct rio_dev *rdev)
 static void rionet_get_drvinfo(struct net_device *ndev,
                               struct ethtool_drvinfo *info)
 {
-       struct rionet_private *rnet = ndev->priv;
+       struct rionet_private *rnet = netdev_priv(ndev);
 
        strcpy(info->driver, DRV_NAME);
        strcpy(info->version, DRV_VERSION);
@@ -414,14 +405,14 @@ static void rionet_get_drvinfo(struct net_device *ndev,
 
 static u32 rionet_get_msglevel(struct net_device *ndev)
 {
-       struct rionet_private *rnet = ndev->priv;
+       struct rionet_private *rnet = netdev_priv(ndev);
 
        return rnet->msg_enable;
 }
 
 static void rionet_set_msglevel(struct net_device *ndev, u32 value)
 {
-       struct rionet_private *rnet = ndev->priv;
+       struct rionet_private *rnet = netdev_priv(ndev);
 
        rnet->msg_enable = value;
 }
@@ -433,6 +424,15 @@ static const struct ethtool_ops rionet_ethtool_ops = {
        .get_link = ethtool_op_get_link,
 };
 
+static const struct net_device_ops rionet_netdev_ops = {
+       .ndo_open               = rionet_open,
+       .ndo_stop               = rionet_close,
+       .ndo_start_xmit         = rionet_start_xmit,
+       .ndo_change_mtu         = eth_change_mtu,
+       .ndo_validate_addr      = eth_validate_addr,
+       .ndo_set_mac_address    = eth_mac_addr,
+};
+
 static int rionet_setup_netdev(struct rio_mport *mport)
 {
        int rc = 0;
@@ -449,8 +449,17 @@ static int rionet_setup_netdev(struct rio_mport *mport)
                goto out;
        }
 
+       rionet_active = (struct rio_dev **)__get_free_pages(GFP_KERNEL,
+                       mport->sys_size ? __ilog2(sizeof(void *)) + 4 : 0);
+       if (!rionet_active) {
+               rc = -ENOMEM;
+               goto out;
+       }
+       memset((void *)rionet_active, 0, sizeof(void *) *
+                               RIO_MAX_ROUTE_ENTRIES(mport->sys_size));
+
        /* Set up private area */
-       rnet = (struct rionet_private *)ndev->priv;
+       rnet = netdev_priv(ndev);
        rnet->mport = mport;
 
        /* Set the default MAC address */
@@ -462,17 +471,11 @@ static int rionet_setup_netdev(struct rio_mport *mport)
        ndev->dev_addr[4] = device_id >> 8;
        ndev->dev_addr[5] = device_id & 0xff;
 
-       /* Fill in the driver function table */
-       ndev->open = &rionet_open;
-       ndev->hard_start_xmit = &rionet_start_xmit;
-       ndev->stop = &rionet_close;
-       ndev->get_stats = &rionet_stats;
+       ndev->netdev_ops = &rionet_netdev_ops;
        ndev->mtu = RIO_MAX_MSG_SIZE - 14;
        ndev->features = NETIF_F_LLTX;
        SET_ETHTOOL_OPS(ndev, &rionet_ethtool_ops);
 
-       SET_MODULE_OWNER(ndev);
-
        spin_lock_init(&rnet->lock);
        spin_lock_init(&rnet->tx_lock);
 
@@ -482,13 +485,12 @@ static int rionet_setup_netdev(struct rio_mport *mport)
        if (rc != 0)
                goto out;
 
-       printk("%s: %s %s Version %s, MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
+       printk("%s: %s %s Version %s, MAC %pM\n",
               ndev->name,
               DRV_NAME,
               DRV_DESC,
               DRV_VERSION,
-              ndev->dev_addr[0], ndev->dev_addr[1], ndev->dev_addr[2],
-              ndev->dev_addr[3], ndev->dev_addr[4], ndev->dev_addr[5]);
+              ndev->dev_addr);
 
       out:
        return rc;