1
2
3
4
5
6
7#ifndef _LINUX_NETPOLL_H
8#define _LINUX_NETPOLL_H
9
10#include <linux/netdevice.h>
11#include <linux/interrupt.h>
12#include <linux/rcupdate.h>
13#include <linux/list.h>
14
15struct netpoll {
16 struct net_device *dev;
17 char dev_name[IFNAMSIZ];
18 const char *name;
19 void (*rx_hook)(struct netpoll *, int, char *, int);
20
21 __be32 local_ip, remote_ip;
22 u16 local_port, remote_port;
23 u8 remote_mac[ETH_ALEN];
24
25 struct list_head rx;
26};
27
28struct netpoll_info {
29 atomic_t refcnt;
30
31 int rx_flags;
32 spinlock_t rx_lock;
33 struct list_head rx_np;
34
35 struct sk_buff_head arp_tx;
36 struct sk_buff_head txq;
37
38 struct delayed_work tx_work;
39
40 struct netpoll *netpoll;
41};
42
43void netpoll_poll_dev(struct net_device *dev);
44void netpoll_poll(struct netpoll *np);
45void netpoll_send_udp(struct netpoll *np, const char *msg, int len);
46void netpoll_print_options(struct netpoll *np);
47int netpoll_parse_options(struct netpoll *np, char *opt);
48int __netpoll_setup(struct netpoll *np);
49int netpoll_setup(struct netpoll *np);
50int netpoll_trap(void);
51void netpoll_set_trap(int trap);
52void __netpoll_cleanup(struct netpoll *np);
53void netpoll_cleanup(struct netpoll *np);
54int __netpoll_rx(struct sk_buff *skb);
55void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb,
56 struct net_device *dev);
57static inline void netpoll_send_skb(struct netpoll *np, struct sk_buff *skb)
58{
59 netpoll_send_skb_on_dev(np, skb, np->dev);
60}
61
62
63
64#ifdef CONFIG_NETPOLL
65static inline bool netpoll_rx(struct sk_buff *skb)
66{
67 struct netpoll_info *npinfo;
68 unsigned long flags;
69 bool ret = false;
70
71 local_irq_save(flags);
72 npinfo = rcu_dereference_bh(skb->dev->npinfo);
73
74 if (!npinfo || (list_empty(&npinfo->rx_np) && !npinfo->rx_flags))
75 goto out;
76
77 spin_lock(&npinfo->rx_lock);
78
79 if (npinfo->rx_flags && __netpoll_rx(skb))
80 ret = true;
81 spin_unlock(&npinfo->rx_lock);
82
83out:
84 local_irq_restore(flags);
85 return ret;
86}
87
88static inline int netpoll_rx_on(struct sk_buff *skb)
89{
90 struct netpoll_info *npinfo = rcu_dereference_bh(skb->dev->npinfo);
91
92 return npinfo && (!list_empty(&npinfo->rx_np) || npinfo->rx_flags);
93}
94
95static inline int netpoll_receive_skb(struct sk_buff *skb)
96{
97 if (!list_empty(&skb->dev->napi_list))
98 return netpoll_rx(skb);
99 return 0;
100}
101
102static inline void *netpoll_poll_lock(struct napi_struct *napi)
103{
104 struct net_device *dev = napi->dev;
105
106 if (dev && dev->npinfo) {
107 spin_lock(&napi->poll_lock);
108 napi->poll_owner = smp_processor_id();
109 return napi;
110 }
111 return NULL;
112}
113
114static inline void netpoll_poll_unlock(void *have)
115{
116 struct napi_struct *napi = have;
117
118 if (napi) {
119 napi->poll_owner = -1;
120 spin_unlock(&napi->poll_lock);
121 }
122}
123
124static inline int netpoll_tx_running(struct net_device *dev)
125{
126 return irqs_disabled();
127}
128
129#else
130static inline bool netpoll_rx(struct sk_buff *skb)
131{
132 return 0;
133}
134static inline int netpoll_rx_on(struct sk_buff *skb)
135{
136 return 0;
137}
138static inline int netpoll_receive_skb(struct sk_buff *skb)
139{
140 return 0;
141}
142static inline void *netpoll_poll_lock(struct napi_struct *napi)
143{
144 return NULL;
145}
146static inline void netpoll_poll_unlock(void *have)
147{
148}
149static inline void netpoll_netdev_init(struct net_device *dev)
150{
151}
152static inline int netpoll_tx_running(struct net_device *dev)
153{
154 return 0;
155}
156#endif
157
158#endif
159