]> git.openfabrics.org - ~emulex/tmp/compat/.git/commitdiff
compat: backport init_dummy_netdev
authorHauke Mehrtens <hauke@hauke-m.de>
Tue, 17 Aug 2010 18:32:31 +0000 (20:32 +0200)
committerLuis R. Rodriguez <lrodriguez@atheros.com>
Tue, 17 Aug 2010 22:01:04 +0000 (15:01 -0700)
NETREG_DUMMY is not available for older kernels, it should be set to
something not normal. NETREG_DUMMY is set to 5 in new kernel versions.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
compat/compat-2.6.29.c
include/linux/compat-2.6.29.h

index 2e7e623bede5ac0f5992ffce45d32dff5583b9d5..a2354f9b445647d142cbd708404a261af6fa1873 100644 (file)
@@ -124,6 +124,46 @@ int eth_validate_addr(struct net_device *dev)
 EXPORT_SYMBOL(eth_validate_addr);
 /* Source: net/ethernet/eth.c */
 
+#define NETREG_DUMMY 5
+/**
+ *     init_dummy_netdev       - init a dummy network device for NAPI
+ *     @dev: device to init
+ *
+ *     This takes a network device structure and initialize the minimum
+ *     amount of fields so it can be used to schedule NAPI polls without
+ *     registering a full blown interface. This is to be used by drivers
+ *     that need to tie several hardware interfaces to a single NAPI
+ *     poll scheduler due to HW limitations.
+ */
+int init_dummy_netdev(struct net_device *dev)
+{
+       /* Clear everything. Note we don't initialize spinlocks
+        * are they aren't supposed to be taken by any of the
+        * NAPI code and this dummy netdev is supposed to be
+        * only ever used for NAPI polls
+        */
+       memset(dev, 0, sizeof(struct net_device));
+
+       /* make sure we BUG if trying to hit standard
+        * register/unregister code path
+        */
+       dev->reg_state = NETREG_DUMMY;
+
+       /* initialize the ref count */
+       atomic_set(&dev->refcnt, 1);
+
+       /* NAPI wants this */
+       INIT_LIST_HEAD(&dev->napi_list);
+
+       /* a dummy interface is started by default */
+       set_bit(__LINK_STATE_PRESENT, &dev->state);
+       set_bit(__LINK_STATE_START, &dev->state);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(init_dummy_netdev);
+/* Source: net/core/dev.c */
+
 
 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) */
 
index a1a989c48e3c57b2881aa794a3a6be4c33bc45a7..cce678f724ce4a786cef76f453ce6a09142d3b17 100644 (file)
@@ -274,6 +274,8 @@ static inline struct net *read_pnet(struct net * const *pnet)
 
 #endif
 
+extern int             init_dummy_netdev(struct net_device *dev);
+
 #else
 
 static inline void netdev_attach_ops(struct net_device *dev,