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; | |
1da177e4 | 27 | void (*rx_hook)(struct netpoll *, int, char *, int); |
5de4a473 | 28 | |
b7394d24 CW |
29 | union inet_addr local_ip, remote_ip; |
30 | bool ipv6; | |
1da177e4 | 31 | u16 local_port, remote_port; |
09538641 | 32 | u8 remote_mac[ETH_ALEN]; |
508e14b4 DB |
33 | |
34 | struct list_head rx; /* rx_np list element */ | |
2cde6acd | 35 | struct work_struct cleanup_work; |
115c1d6e JM |
36 | }; |
37 | ||
38 | struct netpoll_info { | |
93ec2c72 | 39 | atomic_t refcnt; |
508e14b4 | 40 | |
ca99ca14 | 41 | unsigned long rx_flags; |
fbeec2e1 | 42 | spinlock_t rx_lock; |
ca99ca14 | 43 | struct mutex dev_lock; |
508e14b4 DB |
44 | struct list_head rx_np; /* netpolls that registered an rx_hook */ |
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 NH |
55 | #ifdef CONFIG_NETPOLL |
56 | extern int netpoll_rx_disable(struct net_device *dev); | |
57 | extern void netpoll_rx_enable(struct net_device *dev); | |
58 | #else | |
59 | static inline int netpoll_rx_disable(struct net_device *dev) { return 0; } | |
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 LT |
67 | int netpoll_setup(struct netpoll *np); |
68 | int netpoll_trap(void); | |
69 | void netpoll_set_trap(int trap); | |
8fdd95ec | 70 | void __netpoll_cleanup(struct netpoll *np); |
2cde6acd | 71 | void __netpoll_free_async(struct netpoll *np); |
1da177e4 | 72 | void netpoll_cleanup(struct netpoll *np); |
57c5d461 | 73 | int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo); |
c2355e1a NH |
74 | void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb, |
75 | struct net_device *dev); | |
76 | static inline void netpoll_send_skb(struct netpoll *np, struct sk_buff *skb) | |
77 | { | |
2899656b AW |
78 | unsigned long flags; |
79 | local_irq_save(flags); | |
c2355e1a | 80 | netpoll_send_skb_on_dev(np, skb, np->dev); |
2899656b | 81 | local_irq_restore(flags); |
c2355e1a NH |
82 | } |
83 | ||
5de4a473 | 84 | |
1da177e4 LT |
85 | |
86 | #ifdef CONFIG_NETPOLL | |
77ab8a54 | 87 | static inline bool netpoll_rx_on(struct sk_buff *skb) |
91fe4a4b AW |
88 | { |
89 | struct netpoll_info *npinfo = rcu_dereference_bh(skb->dev->npinfo); | |
90 | ||
91 | return npinfo && (!list_empty(&npinfo->rx_np) || npinfo->rx_flags); | |
92 | } | |
93 | ||
ffb27362 | 94 | static inline bool netpoll_rx(struct sk_buff *skb) |
1da177e4 | 95 | { |
de85d99e | 96 | struct netpoll_info *npinfo; |
fbeec2e1 | 97 | unsigned long flags; |
ffb27362 | 98 | bool ret = false; |
115c1d6e | 99 | |
f0f9deae | 100 | local_irq_save(flags); |
de85d99e | 101 | |
91fe4a4b | 102 | if (!netpoll_rx_on(skb)) |
de85d99e | 103 | goto out; |
115c1d6e | 104 | |
91fe4a4b | 105 | npinfo = rcu_dereference_bh(skb->dev->npinfo); |
f0f9deae | 106 | spin_lock(&npinfo->rx_lock); |
d9452e9f | 107 | /* check rx_flags again with the lock held */ |
57c5d461 | 108 | if (npinfo->rx_flags && __netpoll_rx(skb, npinfo)) |
ffb27362 | 109 | ret = true; |
f0f9deae | 110 | spin_unlock(&npinfo->rx_lock); |
fbeec2e1 | 111 | |
de85d99e | 112 | out: |
f0f9deae | 113 | local_irq_restore(flags); |
fbeec2e1 | 114 | return ret; |
1da177e4 LT |
115 | } |
116 | ||
bea3348e | 117 | static inline int netpoll_receive_skb(struct sk_buff *skb) |
1da177e4 | 118 | { |
bea3348e SH |
119 | if (!list_empty(&skb->dev->napi_list)) |
120 | return netpoll_rx(skb); | |
121 | return 0; | |
122 | } | |
123 | ||
124 | static inline void *netpoll_poll_lock(struct napi_struct *napi) | |
125 | { | |
126 | struct net_device *dev = napi->dev; | |
127 | ||
bea3348e SH |
128 | if (dev && dev->npinfo) { |
129 | spin_lock(&napi->poll_lock); | |
130 | napi->poll_owner = smp_processor_id(); | |
131 | return napi; | |
1da177e4 | 132 | } |
53fb95d3 | 133 | return NULL; |
1da177e4 LT |
134 | } |
135 | ||
53fb95d3 | 136 | static inline void netpoll_poll_unlock(void *have) |
1da177e4 | 137 | { |
bea3348e | 138 | struct napi_struct *napi = have; |
53fb95d3 | 139 | |
bea3348e SH |
140 | if (napi) { |
141 | napi->poll_owner = -1; | |
142 | spin_unlock(&napi->poll_lock); | |
1da177e4 LT |
143 | } |
144 | } | |
145 | ||
77ab8a54 | 146 | static inline bool netpoll_tx_running(struct net_device *dev) |
c18370f5 HX |
147 | { |
148 | return irqs_disabled(); | |
149 | } | |
150 | ||
1da177e4 | 151 | #else |
969a6e52 | 152 | static inline bool netpoll_rx(struct sk_buff *skb) |
bea3348e | 153 | { |
77ab8a54 | 154 | return false; |
bea3348e | 155 | } |
77ab8a54 | 156 | static inline bool netpoll_rx_on(struct sk_buff *skb) |
d1c76af9 | 157 | { |
77ab8a54 | 158 | return false; |
d1c76af9 | 159 | } |
bea3348e SH |
160 | static inline int netpoll_receive_skb(struct sk_buff *skb) |
161 | { | |
162 | return 0; | |
163 | } | |
164 | static inline void *netpoll_poll_lock(struct napi_struct *napi) | |
165 | { | |
166 | return NULL; | |
167 | } | |
168 | static inline void netpoll_poll_unlock(void *have) | |
169 | { | |
170 | } | |
171 | static inline void netpoll_netdev_init(struct net_device *dev) | |
172 | { | |
173 | } | |
77ab8a54 | 174 | static inline bool netpoll_tx_running(struct net_device *dev) |
c18370f5 | 175 | { |
77ab8a54 | 176 | return false; |
c18370f5 | 177 | } |
1da177e4 LT |
178 | #endif |
179 | ||
180 | #endif |