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