]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Common code for low-level network console, dump, and debugger code | |
3 | * | |
4 | * Derived from netconsole, kgdb-over-ethernet, and netdump patches | |
5 | */ | |
6 | ||
7 | #ifndef _LINUX_NETPOLL_H | |
8 | #define _LINUX_NETPOLL_H | |
9 | ||
10 | #include <linux/netdevice.h> | |
11 | #include <linux/interrupt.h> | |
53fb95d3 | 12 | #include <linux/rcupdate.h> |
1da177e4 LT |
13 | #include <linux/list.h> |
14 | ||
b7394d24 CW |
15 | union inet_addr { |
16 | __u32 all[4]; | |
17 | __be32 ip; | |
18 | __be32 ip6[4]; | |
19 | struct in_addr in; | |
20 | struct in6_addr in6; | |
21 | }; | |
22 | ||
1da177e4 LT |
23 | struct netpoll { |
24 | struct net_device *dev; | |
bf6bce71 SH |
25 | char dev_name[IFNAMSIZ]; |
26 | const char *name; | |
8fb479a4 AQ |
27 | void (*rx_skb_hook)(struct netpoll *np, int source, struct sk_buff *skb, |
28 | int offset, int len); | |
5de4a473 | 29 | |
b7394d24 CW |
30 | union inet_addr local_ip, remote_ip; |
31 | bool ipv6; | |
1da177e4 | 32 | u16 local_port, remote_port; |
09538641 | 33 | u8 remote_mac[ETH_ALEN]; |
508e14b4 DB |
34 | |
35 | struct list_head rx; /* rx_np list element */ | |
2cde6acd | 36 | struct work_struct cleanup_work; |
115c1d6e JM |
37 | }; |
38 | ||
39 | struct netpoll_info { | |
93ec2c72 | 40 | atomic_t refcnt; |
508e14b4 | 41 | |
fbeec2e1 | 42 | spinlock_t rx_lock; |
bd7c4b60 | 43 | struct semaphore dev_lock; |
8fb479a4 | 44 | struct list_head rx_np; /* netpolls that registered an rx_skb_hook */ |
508e14b4 | 45 | |
b7394d24 | 46 | struct sk_buff_head neigh_tx; /* list of neigh requests to reply to */ |
b6cd27ed | 47 | struct sk_buff_head txq; |
508e14b4 | 48 | |
6d5aefb8 | 49 | struct delayed_work tx_work; |
0e34e931 WC |
50 | |
51 | struct netpoll *netpoll; | |
38e6bc18 | 52 | struct rcu_head rcu; |
1da177e4 LT |
53 | }; |
54 | ||
ca99ca14 | 55 | #ifdef CONFIG_NETPOLL |
da6e378b | 56 | extern void netpoll_rx_disable(struct net_device *dev); |
ca99ca14 NH |
57 | extern void netpoll_rx_enable(struct net_device *dev); |
58 | #else | |
da6e378b | 59 | static inline void netpoll_rx_disable(struct net_device *dev) { return; } |
ca99ca14 NH |
60 | static inline void netpoll_rx_enable(struct net_device *dev) { return; } |
61 | #endif | |
62 | ||
1da177e4 | 63 | void netpoll_send_udp(struct netpoll *np, const char *msg, int len); |
0bcc1816 | 64 | void netpoll_print_options(struct netpoll *np); |
1da177e4 | 65 | int netpoll_parse_options(struct netpoll *np, char *opt); |
47be03a2 | 66 | int __netpoll_setup(struct netpoll *np, struct net_device *ndev, gfp_t gfp); |
1da177e4 | 67 | int netpoll_setup(struct netpoll *np); |
8fdd95ec | 68 | void __netpoll_cleanup(struct netpoll *np); |
2cde6acd | 69 | void __netpoll_free_async(struct netpoll *np); |
1da177e4 | 70 | void netpoll_cleanup(struct netpoll *np); |
57c5d461 | 71 | int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo); |
c2355e1a NH |
72 | void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb, |
73 | struct net_device *dev); | |
74 | static inline void netpoll_send_skb(struct netpoll *np, struct sk_buff *skb) | |
75 | { | |
2899656b AW |
76 | unsigned long flags; |
77 | local_irq_save(flags); | |
c2355e1a | 78 | netpoll_send_skb_on_dev(np, skb, np->dev); |
2899656b | 79 | local_irq_restore(flags); |
c2355e1a NH |
80 | } |
81 | ||
ff607631 | 82 | #ifdef CONFIG_NETPOLL_TRAP |
ad8d4752 EB |
83 | int netpoll_trap(void); |
84 | void netpoll_set_trap(int trap); | |
ff607631 EB |
85 | static inline bool netpoll_rx_processing(struct netpoll_info *npinfo) |
86 | { | |
87 | return !list_empty(&npinfo->rx_np); | |
88 | } | |
89 | #else | |
ad8d4752 EB |
90 | static inline int netpoll_trap(void) |
91 | { | |
92 | return 0; | |
93 | } | |
94 | static inline void netpoll_set_trap(int trap) | |
95 | { | |
96 | } | |
ff607631 EB |
97 | static inline bool netpoll_rx_processing(struct netpoll_info *npinfo) |
98 | { | |
99 | return false; | |
100 | } | |
101 | #endif | |
1da177e4 LT |
102 | |
103 | #ifdef CONFIG_NETPOLL | |
77ab8a54 | 104 | static inline bool netpoll_rx_on(struct sk_buff *skb) |
91fe4a4b AW |
105 | { |
106 | struct netpoll_info *npinfo = rcu_dereference_bh(skb->dev->npinfo); | |
107 | ||
b6bacd55 | 108 | return npinfo && netpoll_rx_processing(npinfo); |
91fe4a4b AW |
109 | } |
110 | ||
ffb27362 | 111 | static inline bool netpoll_rx(struct sk_buff *skb) |
1da177e4 | 112 | { |
de85d99e | 113 | struct netpoll_info *npinfo; |
fbeec2e1 | 114 | unsigned long flags; |
ffb27362 | 115 | bool ret = false; |
115c1d6e | 116 | |
f0f9deae | 117 | local_irq_save(flags); |
de85d99e | 118 | |
91fe4a4b | 119 | if (!netpoll_rx_on(skb)) |
de85d99e | 120 | goto out; |
115c1d6e | 121 | |
91fe4a4b | 122 | npinfo = rcu_dereference_bh(skb->dev->npinfo); |
f0f9deae | 123 | spin_lock(&npinfo->rx_lock); |
ff607631 EB |
124 | /* check rx_processing again with the lock held */ |
125 | if (netpoll_rx_processing(npinfo) && __netpoll_rx(skb, npinfo)) | |
ffb27362 | 126 | ret = true; |
f0f9deae | 127 | spin_unlock(&npinfo->rx_lock); |
fbeec2e1 | 128 | |
de85d99e | 129 | out: |
f0f9deae | 130 | local_irq_restore(flags); |
fbeec2e1 | 131 | return ret; |
1da177e4 LT |
132 | } |
133 | ||
bea3348e | 134 | static inline int netpoll_receive_skb(struct sk_buff *skb) |
1da177e4 | 135 | { |
bea3348e SH |
136 | if (!list_empty(&skb->dev->napi_list)) |
137 | return netpoll_rx(skb); | |
138 | return 0; | |
139 | } | |
140 | ||
141 | static inline void *netpoll_poll_lock(struct napi_struct *napi) | |
142 | { | |
143 | struct net_device *dev = napi->dev; | |
144 | ||
bea3348e SH |
145 | if (dev && dev->npinfo) { |
146 | spin_lock(&napi->poll_lock); | |
147 | napi->poll_owner = smp_processor_id(); | |
148 | return napi; | |
1da177e4 | 149 | } |
53fb95d3 | 150 | return NULL; |
1da177e4 LT |
151 | } |
152 | ||
53fb95d3 | 153 | static inline void netpoll_poll_unlock(void *have) |
1da177e4 | 154 | { |
bea3348e | 155 | struct napi_struct *napi = have; |
53fb95d3 | 156 | |
bea3348e SH |
157 | if (napi) { |
158 | napi->poll_owner = -1; | |
159 | spin_unlock(&napi->poll_lock); | |
1da177e4 LT |
160 | } |
161 | } | |
162 | ||
77ab8a54 | 163 | static inline bool netpoll_tx_running(struct net_device *dev) |
c18370f5 HX |
164 | { |
165 | return irqs_disabled(); | |
166 | } | |
167 | ||
1da177e4 | 168 | #else |
969a6e52 | 169 | static inline bool netpoll_rx(struct sk_buff *skb) |
bea3348e | 170 | { |
77ab8a54 | 171 | return false; |
bea3348e | 172 | } |
77ab8a54 | 173 | static inline bool netpoll_rx_on(struct sk_buff *skb) |
d1c76af9 | 174 | { |
77ab8a54 | 175 | return false; |
d1c76af9 | 176 | } |
bea3348e SH |
177 | static inline int netpoll_receive_skb(struct sk_buff *skb) |
178 | { | |
179 | return 0; | |
180 | } | |
181 | static inline void *netpoll_poll_lock(struct napi_struct *napi) | |
182 | { | |
183 | return NULL; | |
184 | } | |
185 | static inline void netpoll_poll_unlock(void *have) | |
186 | { | |
187 | } | |
188 | static inline void netpoll_netdev_init(struct net_device *dev) | |
189 | { | |
190 | } | |
77ab8a54 | 191 | static inline bool netpoll_tx_running(struct net_device *dev) |
c18370f5 | 192 | { |
77ab8a54 | 193 | return false; |
c18370f5 | 194 | } |
1da177e4 LT |
195 | #endif |
196 | ||
197 | #endif |