netpoll: Add ndo_netpoll_setup
[linux-2.6-block.git] / include / linux / netpoll.h
CommitLineData
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
15struct netpoll {
16 struct net_device *dev;
0e34e931 17 struct net_device *real_dev;
bf6bce71
SH
18 char dev_name[IFNAMSIZ];
19 const char *name;
1da177e4 20 void (*rx_hook)(struct netpoll *, int, char *, int);
5de4a473 21
e7557af5 22 __be32 local_ip, remote_ip;
1da177e4 23 u16 local_port, remote_port;
09538641 24 u8 remote_mac[ETH_ALEN];
508e14b4
DB
25
26 struct list_head rx; /* rx_np list element */
115c1d6e
JM
27};
28
29struct 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;
1da177e4
LT
42};
43
0e34e931 44void netpoll_poll_dev(struct net_device *dev);
1da177e4
LT
45void netpoll_poll(struct netpoll *np);
46void netpoll_send_udp(struct netpoll *np, const char *msg, int len);
0bcc1816 47void netpoll_print_options(struct netpoll *np);
1da177e4
LT
48int netpoll_parse_options(struct netpoll *np, char *opt);
49int netpoll_setup(struct netpoll *np);
50int netpoll_trap(void);
51void netpoll_set_trap(int trap);
52void netpoll_cleanup(struct netpoll *np);
53int __netpoll_rx(struct sk_buff *skb);
0e34e931 54void netpoll_send_skb(struct netpoll *np, struct sk_buff *skb);
5de4a473 55
1da177e4
LT
56
57#ifdef CONFIG_NETPOLL
ffb27362 58static inline bool netpoll_rx(struct sk_buff *skb)
1da177e4 59{
de85d99e 60 struct netpoll_info *npinfo;
fbeec2e1 61 unsigned long flags;
ffb27362 62 bool ret = false;
115c1d6e 63
de85d99e
HX
64 rcu_read_lock_bh();
65 npinfo = rcu_dereference(skb->dev->npinfo);
66
508e14b4 67 if (!npinfo || (list_empty(&npinfo->rx_np) && !npinfo->rx_flags))
de85d99e 68 goto out;
115c1d6e 69
fbeec2e1 70 spin_lock_irqsave(&npinfo->rx_lock, flags);
d9452e9f
DM
71 /* check rx_flags again with the lock held */
72 if (npinfo->rx_flags && __netpoll_rx(skb))
ffb27362 73 ret = true;
fbeec2e1
JM
74 spin_unlock_irqrestore(&npinfo->rx_lock, flags);
75
de85d99e
HX
76out:
77 rcu_read_unlock_bh();
fbeec2e1 78 return ret;
1da177e4
LT
79}
80
d1c76af9
HX
81static inline int netpoll_rx_on(struct sk_buff *skb)
82{
de85d99e 83 struct netpoll_info *npinfo = rcu_dereference(skb->dev->npinfo);
d1c76af9 84
508e14b4 85 return npinfo && (!list_empty(&npinfo->rx_np) || npinfo->rx_flags);
d1c76af9
HX
86}
87
bea3348e 88static inline int netpoll_receive_skb(struct sk_buff *skb)
1da177e4 89{
bea3348e
SH
90 if (!list_empty(&skb->dev->napi_list))
91 return netpoll_rx(skb);
92 return 0;
93}
94
95static inline void *netpoll_poll_lock(struct napi_struct *napi)
96{
97 struct net_device *dev = napi->dev;
98
bea3348e
SH
99 if (dev && dev->npinfo) {
100 spin_lock(&napi->poll_lock);
101 napi->poll_owner = smp_processor_id();
102 return napi;
1da177e4 103 }
53fb95d3 104 return NULL;
1da177e4
LT
105}
106
53fb95d3 107static inline void netpoll_poll_unlock(void *have)
1da177e4 108{
bea3348e 109 struct napi_struct *napi = have;
53fb95d3 110
bea3348e
SH
111 if (napi) {
112 napi->poll_owner = -1;
113 spin_unlock(&napi->poll_lock);
1da177e4
LT
114 }
115}
116
117#else
bea3348e
SH
118static inline int netpoll_rx(struct sk_buff *skb)
119{
120 return 0;
121}
d1c76af9
HX
122static inline int netpoll_rx_on(struct sk_buff *skb)
123{
124 return 0;
125}
bea3348e
SH
126static inline int netpoll_receive_skb(struct sk_buff *skb)
127{
128 return 0;
129}
130static inline void *netpoll_poll_lock(struct napi_struct *napi)
131{
132 return NULL;
133}
134static inline void netpoll_poll_unlock(void *have)
135{
136}
137static inline void netpoll_netdev_init(struct net_device *dev)
138{
139}
1da177e4
LT
140#endif
141
142#endif