diff options
author | Stephen Hemminger <shemminger@linux-foundation.org> | 2007-10-03 19:41:36 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-10-10 19:47:45 -0400 |
commit | bea3348eef27e6044b6161fd04c3152215f96411 (patch) | |
tree | f0990b263e5ce42505d290a4c346fe990bcd4c33 /include/linux/netpoll.h | |
parent | dde4e47e8fe333a5649a3fa0e7db1fa7c08d6158 (diff) |
[NET]: Make NAPI polling independent of struct net_device objects.
Several devices have multiple independant RX queues per net
device, and some have a single interrupt doorbell for several
queues.
In either case, it's easier to support layouts like that if the
structure representing the poll is independant from the net
device itself.
The signature of the ->poll() call back goes from:
int foo_poll(struct net_device *dev, int *budget)
to
int foo_poll(struct napi_struct *napi, int budget)
The caller is returned the number of RX packets processed (or
the number of "NAPI credits" consumed if you want to get
abstract). The callee no longer messes around bumping
dev->quota, *budget, etc. because that is all handled in the
caller upon return.
The napi_struct is to be embedded in the device driver private data
structures.
Furthermore, it is the driver's responsibility to disable all NAPI
instances in it's ->stop() device close handler. Since the
napi_struct is privatized into the driver's private data structures,
only the driver knows how to get at all of the napi_struct instances
it may have per-device.
With lots of help and suggestions from Rusty Russell, Roland Dreier,
Michael Chan, Jeff Garzik, and Jamal Hadi Salim.
Bug fixes from Thomas Graf, Roland Dreier, Peter Zijlstra,
Joseph Fannin, Scott Wood, Hans J. Koch, and Michael Chan.
[ Ported to current tree and all drivers converted. Integrated
Stephen's follow-on kerneldoc additions, and restored poll_list
handling to the old style to fix mutual exclusion issues. -DaveM ]
Signed-off-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux/netpoll.h')
-rw-r--r-- | include/linux/netpoll.h | 55 |
1 files changed, 41 insertions, 14 deletions
diff --git a/include/linux/netpoll.h b/include/linux/netpoll.h index 29930b71a9aa..08dcc39ec18d 100644 --- a/include/linux/netpoll.h +++ b/include/linux/netpoll.h | |||
@@ -25,8 +25,6 @@ struct netpoll { | |||
25 | 25 | ||
26 | struct netpoll_info { | 26 | struct netpoll_info { |
27 | atomic_t refcnt; | 27 | atomic_t refcnt; |
28 | spinlock_t poll_lock; | ||
29 | int poll_owner; | ||
30 | int rx_flags; | 28 | int rx_flags; |
31 | spinlock_t rx_lock; | 29 | spinlock_t rx_lock; |
32 | struct netpoll *rx_np; /* netpoll that registered an rx_hook */ | 30 | struct netpoll *rx_np; /* netpoll that registered an rx_hook */ |
@@ -64,32 +62,61 @@ static inline int netpoll_rx(struct sk_buff *skb) | |||
64 | return ret; | 62 | return ret; |
65 | } | 63 | } |
66 | 64 | ||
67 | static inline void *netpoll_poll_lock(struct net_device *dev) | 65 | static inline int netpoll_receive_skb(struct sk_buff *skb) |
68 | { | 66 | { |
67 | if (!list_empty(&skb->dev->napi_list)) | ||
68 | return netpoll_rx(skb); | ||
69 | return 0; | ||
70 | } | ||
71 | |||
72 | static inline void *netpoll_poll_lock(struct napi_struct *napi) | ||
73 | { | ||
74 | struct net_device *dev = napi->dev; | ||
75 | |||
69 | rcu_read_lock(); /* deal with race on ->npinfo */ | 76 | rcu_read_lock(); /* deal with race on ->npinfo */ |
70 | if (dev->npinfo) { | 77 | if (dev && dev->npinfo) { |
71 | spin_lock(&dev->npinfo->poll_lock); | 78 | spin_lock(&napi->poll_lock); |
72 | dev->npinfo->poll_owner = smp_processor_id(); | 79 | napi->poll_owner = smp_processor_id(); |
73 | return dev->npinfo; | 80 | return napi; |
74 | } | 81 | } |
75 | return NULL; | 82 | return NULL; |
76 | } | 83 | } |
77 | 84 | ||
78 | static inline void netpoll_poll_unlock(void *have) | 85 | static inline void netpoll_poll_unlock(void *have) |
79 | { | 86 | { |
80 | struct netpoll_info *npi = have; | 87 | struct napi_struct *napi = have; |
81 | 88 | ||
82 | if (npi) { | 89 | if (napi) { |
83 | npi->poll_owner = -1; | 90 | napi->poll_owner = -1; |
84 | spin_unlock(&npi->poll_lock); | 91 | spin_unlock(&napi->poll_lock); |
85 | } | 92 | } |
86 | rcu_read_unlock(); | 93 | rcu_read_unlock(); |
87 | } | 94 | } |
88 | 95 | ||
96 | static inline void netpoll_netdev_init(struct net_device *dev) | ||
97 | { | ||
98 | INIT_LIST_HEAD(&dev->napi_list); | ||
99 | } | ||
100 | |||
89 | #else | 101 | #else |
90 | #define netpoll_rx(a) 0 | 102 | static inline int netpoll_rx(struct sk_buff *skb) |
91 | #define netpoll_poll_lock(a) NULL | 103 | { |
92 | #define netpoll_poll_unlock(a) | 104 | return 0; |
105 | } | ||
106 | static inline int netpoll_receive_skb(struct sk_buff *skb) | ||
107 | { | ||
108 | return 0; | ||
109 | } | ||
110 | static inline void *netpoll_poll_lock(struct napi_struct *napi) | ||
111 | { | ||
112 | return NULL; | ||
113 | } | ||
114 | static inline void netpoll_poll_unlock(void *have) | ||
115 | { | ||
116 | } | ||
117 | static inline void netpoll_netdev_init(struct net_device *dev) | ||
118 | { | ||
119 | } | ||
93 | #endif | 120 | #endif |
94 | 121 | ||
95 | #endif | 122 | #endif |