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 | ||
1da177e4 LT |
15 | struct netpoll { |
16 | struct net_device *dev; | |
bf6bce71 SH |
17 | char dev_name[IFNAMSIZ]; |
18 | const char *name; | |
1da177e4 | 19 | void (*rx_hook)(struct netpoll *, int, char *, int); |
5de4a473 | 20 | |
e7557af5 | 21 | __be32 local_ip, remote_ip; |
1da177e4 | 22 | u16 local_port, remote_port; |
09538641 | 23 | u8 remote_mac[ETH_ALEN]; |
508e14b4 DB |
24 | |
25 | struct list_head rx; /* rx_np list element */ | |
38e6bc18 | 26 | struct rcu_head rcu; |
115c1d6e JM |
27 | }; |
28 | ||
29 | struct netpoll_info { | |
93ec2c72 | 30 | atomic_t refcnt; |
508e14b4 | 31 | |
d9452e9f | 32 | int rx_flags; |
fbeec2e1 | 33 | spinlock_t rx_lock; |
508e14b4 DB |
34 | struct list_head rx_np; /* netpolls that registered an rx_hook */ |
35 | ||
068c6e98 | 36 | struct sk_buff_head arp_tx; /* list of arp requests to reply to */ |
b6cd27ed | 37 | struct sk_buff_head txq; |
508e14b4 | 38 | |
6d5aefb8 | 39 | struct delayed_work tx_work; |
0e34e931 WC |
40 | |
41 | struct netpoll *netpoll; | |
38e6bc18 | 42 | struct rcu_head rcu; |
1da177e4 LT |
43 | }; |
44 | ||
1da177e4 | 45 | void netpoll_send_udp(struct netpoll *np, const char *msg, int len); |
0bcc1816 | 46 | void netpoll_print_options(struct netpoll *np); |
1da177e4 | 47 | int netpoll_parse_options(struct netpoll *np, char *opt); |
47be03a2 | 48 | int __netpoll_setup(struct netpoll *np, struct net_device *ndev, gfp_t gfp); |
1da177e4 LT |
49 | int netpoll_setup(struct netpoll *np); |
50 | int netpoll_trap(void); | |
51 | void netpoll_set_trap(int trap); | |
8fdd95ec | 52 | void __netpoll_cleanup(struct netpoll *np); |
38e6bc18 | 53 | void __netpoll_free_rcu(struct netpoll *np); |
1da177e4 | 54 | void netpoll_cleanup(struct netpoll *np); |
57c5d461 | 55 | int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo); |
c2355e1a NH |
56 | void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb, |
57 | struct net_device *dev); | |
58 | static inline void netpoll_send_skb(struct netpoll *np, struct sk_buff *skb) | |
59 | { | |
2899656b AW |
60 | unsigned long flags; |
61 | local_irq_save(flags); | |
c2355e1a | 62 | netpoll_send_skb_on_dev(np, skb, np->dev); |
2899656b | 63 | local_irq_restore(flags); |
c2355e1a NH |
64 | } |
65 | ||
5de4a473 | 66 | |
1da177e4 LT |
67 | |
68 | #ifdef CONFIG_NETPOLL | |
77ab8a54 | 69 | static inline bool netpoll_rx_on(struct sk_buff *skb) |
91fe4a4b AW |
70 | { |
71 | struct netpoll_info *npinfo = rcu_dereference_bh(skb->dev->npinfo); | |
72 | ||
73 | return npinfo && (!list_empty(&npinfo->rx_np) || npinfo->rx_flags); | |
74 | } | |
75 | ||
ffb27362 | 76 | static inline bool netpoll_rx(struct sk_buff *skb) |
1da177e4 | 77 | { |
de85d99e | 78 | struct netpoll_info *npinfo; |
fbeec2e1 | 79 | unsigned long flags; |
ffb27362 | 80 | bool ret = false; |
115c1d6e | 81 | |
f0f9deae | 82 | local_irq_save(flags); |
de85d99e | 83 | |
91fe4a4b | 84 | if (!netpoll_rx_on(skb)) |
de85d99e | 85 | goto out; |
115c1d6e | 86 | |
91fe4a4b | 87 | npinfo = rcu_dereference_bh(skb->dev->npinfo); |
f0f9deae | 88 | spin_lock(&npinfo->rx_lock); |
d9452e9f | 89 | /* check rx_flags again with the lock held */ |
57c5d461 | 90 | if (npinfo->rx_flags && __netpoll_rx(skb, npinfo)) |
ffb27362 | 91 | ret = true; |
f0f9deae | 92 | spin_unlock(&npinfo->rx_lock); |
fbeec2e1 | 93 | |
de85d99e | 94 | out: |
f0f9deae | 95 | local_irq_restore(flags); |
fbeec2e1 | 96 | return ret; |
1da177e4 LT |
97 | } |
98 | ||
bea3348e | 99 | static inline int netpoll_receive_skb(struct sk_buff *skb) |
1da177e4 | 100 | { |
bea3348e SH |
101 | if (!list_empty(&skb->dev->napi_list)) |
102 | return netpoll_rx(skb); | |
103 | return 0; | |
104 | } | |
105 | ||
106 | static inline void *netpoll_poll_lock(struct napi_struct *napi) | |
107 | { | |
108 | struct net_device *dev = napi->dev; | |
109 | ||
bea3348e SH |
110 | if (dev && dev->npinfo) { |
111 | spin_lock(&napi->poll_lock); | |
112 | napi->poll_owner = smp_processor_id(); | |
113 | return napi; | |
1da177e4 | 114 | } |
53fb95d3 | 115 | return NULL; |
1da177e4 LT |
116 | } |
117 | ||
53fb95d3 | 118 | static inline void netpoll_poll_unlock(void *have) |
1da177e4 | 119 | { |
bea3348e | 120 | struct napi_struct *napi = have; |
53fb95d3 | 121 | |
bea3348e SH |
122 | if (napi) { |
123 | napi->poll_owner = -1; | |
124 | spin_unlock(&napi->poll_lock); | |
1da177e4 LT |
125 | } |
126 | } | |
127 | ||
77ab8a54 | 128 | static inline bool netpoll_tx_running(struct net_device *dev) |
c18370f5 HX |
129 | { |
130 | return irqs_disabled(); | |
131 | } | |
132 | ||
1da177e4 | 133 | #else |
969a6e52 | 134 | static inline bool netpoll_rx(struct sk_buff *skb) |
bea3348e | 135 | { |
77ab8a54 | 136 | return false; |
bea3348e | 137 | } |
77ab8a54 | 138 | static inline bool netpoll_rx_on(struct sk_buff *skb) |
d1c76af9 | 139 | { |
77ab8a54 | 140 | return false; |
d1c76af9 | 141 | } |
bea3348e SH |
142 | static inline int netpoll_receive_skb(struct sk_buff *skb) |
143 | { | |
144 | return 0; | |
145 | } | |
146 | static inline void *netpoll_poll_lock(struct napi_struct *napi) | |
147 | { | |
148 | return NULL; | |
149 | } | |
150 | static inline void netpoll_poll_unlock(void *have) | |
151 | { | |
152 | } | |
153 | static inline void netpoll_netdev_init(struct net_device *dev) | |
154 | { | |
155 | } | |
77ab8a54 | 156 | static inline bool netpoll_tx_running(struct net_device *dev) |
c18370f5 | 157 | { |
77ab8a54 | 158 | return false; |
c18370f5 | 159 | } |
1da177e4 LT |
160 | #endif |
161 | ||
162 | #endif |