]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/linux/netpoll.h
scm: lower SCM_MAX_FD
[net-next-2.6.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;
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
28struct 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
0e34e931 43void netpoll_poll_dev(struct net_device *dev);
1da177e4
LT
44void netpoll_poll(struct netpoll *np);
45void netpoll_send_udp(struct netpoll *np, const char *msg, int len);
0bcc1816 46void netpoll_print_options(struct netpoll *np);
1da177e4 47int netpoll_parse_options(struct netpoll *np, char *opt);
8fdd95ec 48int __netpoll_setup(struct netpoll *np);
1da177e4
LT
49int netpoll_setup(struct netpoll *np);
50int netpoll_trap(void);
51void netpoll_set_trap(int trap);
8fdd95ec 52void __netpoll_cleanup(struct netpoll *np);
1da177e4
LT
53void netpoll_cleanup(struct netpoll *np);
54int __netpoll_rx(struct sk_buff *skb);
c2355e1a
NH
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
5de4a473 62
1da177e4
LT
63
64#ifdef CONFIG_NETPOLL
ffb27362 65static inline bool netpoll_rx(struct sk_buff *skb)
1da177e4 66{
de85d99e 67 struct netpoll_info *npinfo;
fbeec2e1 68 unsigned long flags;
ffb27362 69 bool ret = false;
115c1d6e 70
f0f9deae 71 local_irq_save(flags);
d5f31fbf 72 npinfo = rcu_dereference_bh(skb->dev->npinfo);
de85d99e 73
508e14b4 74 if (!npinfo || (list_empty(&npinfo->rx_np) && !npinfo->rx_flags))
de85d99e 75 goto out;
115c1d6e 76
f0f9deae 77 spin_lock(&npinfo->rx_lock);
d9452e9f
DM
78 /* check rx_flags again with the lock held */
79 if (npinfo->rx_flags && __netpoll_rx(skb))
ffb27362 80 ret = true;
f0f9deae 81 spin_unlock(&npinfo->rx_lock);
fbeec2e1 82
de85d99e 83out:
f0f9deae 84 local_irq_restore(flags);
fbeec2e1 85 return ret;
1da177e4
LT
86}
87
d1c76af9
HX
88static inline int netpoll_rx_on(struct sk_buff *skb)
89{
d5f31fbf 90 struct netpoll_info *npinfo = rcu_dereference_bh(skb->dev->npinfo);
d1c76af9 91
508e14b4 92 return npinfo && (!list_empty(&npinfo->rx_np) || npinfo->rx_flags);
d1c76af9
HX
93}
94
bea3348e 95static inline int netpoll_receive_skb(struct sk_buff *skb)
1da177e4 96{
bea3348e
SH
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
bea3348e
SH
106 if (dev && dev->npinfo) {
107 spin_lock(&napi->poll_lock);
108 napi->poll_owner = smp_processor_id();
109 return napi;
1da177e4 110 }
53fb95d3 111 return NULL;
1da177e4
LT
112}
113
53fb95d3 114static inline void netpoll_poll_unlock(void *have)
1da177e4 115{
bea3348e 116 struct napi_struct *napi = have;
53fb95d3 117
bea3348e
SH
118 if (napi) {
119 napi->poll_owner = -1;
120 spin_unlock(&napi->poll_lock);
1da177e4
LT
121 }
122}
123
c18370f5
HX
124static inline int netpoll_tx_running(struct net_device *dev)
125{
126 return irqs_disabled();
127}
128
1da177e4 129#else
969a6e52 130static inline bool netpoll_rx(struct sk_buff *skb)
bea3348e
SH
131{
132 return 0;
133}
d1c76af9
HX
134static inline int netpoll_rx_on(struct sk_buff *skb)
135{
136 return 0;
137}
bea3348e
SH
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}
c18370f5
HX
152static inline int netpoll_tx_running(struct net_device *dev)
153{
154 return 0;
155}
1da177e4
LT
156#endif
157
158#endif