]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/net/ifb.c
netxen: Load firmware during probe, dma watchdog fix.
[linux-2.6-omap-h63xx.git] / drivers / net / ifb.c
index 819945e3b33095bfde56e38a205dcd1f1e1c66bd..f5c3598e59afd928d89085e841e45b62fc6c9b92 100644 (file)
 #include <linux/etherdevice.h>
 #include <linux/init.h>
 #include <linux/moduleparam.h>
-#include <linux/list.h>
 #include <net/pkt_sched.h>
 
 #define TX_TIMEOUT  (2*HZ)
 
 #define TX_Q_LIMIT    32
 struct ifb_private {
-       struct list_head        list;
-       struct net_device       *dev;
        struct net_device_stats stats;
        struct tasklet_struct   ifb_tasklet;
        int     tasklet_pending;
@@ -139,13 +136,14 @@ resched:
 
 }
 
-static void __init ifb_setup(struct net_device *dev)
+static void ifb_setup(struct net_device *dev)
 {
        /* Initialize the device structure. */
        dev->get_stats = ifb_get_stats;
        dev->hard_start_xmit = ifb_xmit;
        dev->open = &ifb_open;
        dev->stop = &ifb_close;
+       dev->destructor = free_netdev;
 
        /* Fill in device structure with ethernet-generic values. */
        ether_setup(dev);
@@ -200,12 +198,6 @@ static struct net_device_stats *ifb_get_stats(struct net_device *dev)
        return stats;
 }
 
-static LIST_HEAD(ifbs);
-
-/* Number of ifb devices to be set up by this module. */
-module_param(numifbs, int, 0);
-MODULE_PARM_DESC(numifbs, "Number of ifb devices");
-
 static int ifb_close(struct net_device *dev)
 {
        struct ifb_private *dp = netdev_priv(dev);
@@ -229,10 +221,31 @@ static int ifb_open(struct net_device *dev)
        return 0;
 }
 
+static int ifb_validate(struct nlattr *tb[], struct nlattr *data[])
+{
+       if (tb[IFLA_ADDRESS]) {
+               if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
+                       return -EINVAL;
+               if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
+                       return -EADDRNOTAVAIL;
+       }
+       return 0;
+}
+
+static struct rtnl_link_ops ifb_link_ops __read_mostly = {
+       .kind           = "ifb",
+       .priv_size      = sizeof(struct ifb_private),
+       .setup          = ifb_setup,
+       .validate       = ifb_validate,
+};
+
+/* Number of ifb devices to be set up by this module. */
+module_param(numifbs, int, 0);
+MODULE_PARM_DESC(numifbs, "Number of ifb devices");
+
 static int __init ifb_init_one(int index)
 {
        struct net_device *dev_ifb;
-       struct ifb_private *priv;
        int err;
 
        dev_ifb = alloc_netdev(sizeof(struct ifb_private),
@@ -241,51 +254,44 @@ static int __init ifb_init_one(int index)
        if (!dev_ifb)
                return -ENOMEM;
 
-       if ((err = register_netdev(dev_ifb))) {
-               free_netdev(dev_ifb);
-               dev_ifb = NULL;
-       } else {
-               priv = netdev_priv(dev_ifb);
-               priv->dev = dev_ifb;
-               list_add_tail(&priv->list, &ifbs);
-       }
-
-       return err;
-}
+       err = dev_alloc_name(dev_ifb, dev_ifb->name);
+       if (err < 0)
+               goto err;
 
-static void ifb_free_one(struct net_device *dev)
-{
-       struct ifb_private *priv = netdev_priv(dev);
+       dev_ifb->rtnl_link_ops = &ifb_link_ops;
+       err = register_netdevice(dev_ifb);
+       if (err < 0)
+               goto err;
+       return 0;
 
-       list_del(&priv->list);
-       unregister_netdev(dev);
-       free_netdev(dev);
+err:
+       free_netdev(dev_ifb);
+       return err;
 }
 
 static int __init ifb_init_module(void)
 {
-       struct ifb_private *priv, *next;
-       int i, err = 0;
+       int i, err;
+
+       rtnl_lock();
+       err = __rtnl_link_register(&ifb_link_ops);
 
        for (i = 0; i < numifbs && !err; i++)
                err = ifb_init_one(i);
-       if (err) {
-               list_for_each_entry_safe(priv, next, &ifbs, list)
-                       ifb_free_one(priv->dev);
-       }
+       if (err)
+               __rtnl_link_unregister(&ifb_link_ops);
+       rtnl_unlock();
 
        return err;
 }
 
 static void __exit ifb_cleanup_module(void)
 {
-       struct ifb_private *priv, *next;
-
-       list_for_each_entry_safe(priv, next, &ifbs, list)
-               ifb_free_one(priv->dev);
+       rtnl_link_unregister(&ifb_link_ops);
 }
 
 module_init(ifb_init_module);
 module_exit(ifb_cleanup_module);
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Jamal Hadi Salim");
+MODULE_ALIAS_RTNL_LINK("ifb");