Merge branch 'sched-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[deliverable/linux.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
b7394d24
CW
15union inet_addr {
16 __u32 all[4];
17 __be32 ip;
18 __be32 ip6[4];
19 struct in_addr in;
20 struct in6_addr in6;
21};
22
1da177e4
LT
23struct netpoll {
24 struct net_device *dev;
bf6bce71
SH
25 char dev_name[IFNAMSIZ];
26 const char *name;
8fb479a4
AQ
27 void (*rx_skb_hook)(struct netpoll *np, int source, struct sk_buff *skb,
28 int offset, int len);
5de4a473 29
b7394d24
CW
30 union inet_addr local_ip, remote_ip;
31 bool ipv6;
1da177e4 32 u16 local_port, remote_port;
09538641 33 u8 remote_mac[ETH_ALEN];
508e14b4
DB
34
35 struct list_head rx; /* rx_np list element */
2cde6acd 36 struct work_struct cleanup_work;
115c1d6e
JM
37};
38
39struct netpoll_info {
93ec2c72 40 atomic_t refcnt;
508e14b4 41
ca99ca14 42 unsigned long rx_flags;
fbeec2e1 43 spinlock_t rx_lock;
bd7c4b60 44 struct semaphore dev_lock;
8fb479a4 45 struct list_head rx_np; /* netpolls that registered an rx_skb_hook */
508e14b4 46
b7394d24 47 struct sk_buff_head neigh_tx; /* list of neigh requests to reply to */
b6cd27ed 48 struct sk_buff_head txq;
508e14b4 49
6d5aefb8 50 struct delayed_work tx_work;
0e34e931
WC
51
52 struct netpoll *netpoll;
38e6bc18 53 struct rcu_head rcu;
1da177e4
LT
54};
55
ca99ca14 56#ifdef CONFIG_NETPOLL
da6e378b 57extern void netpoll_rx_disable(struct net_device *dev);
ca99ca14
NH
58extern void netpoll_rx_enable(struct net_device *dev);
59#else
da6e378b 60static inline void netpoll_rx_disable(struct net_device *dev) { return; }
ca99ca14
NH
61static inline void netpoll_rx_enable(struct net_device *dev) { return; }
62#endif
63
1da177e4 64void netpoll_send_udp(struct netpoll *np, const char *msg, int len);
0bcc1816 65void netpoll_print_options(struct netpoll *np);
1da177e4 66int netpoll_parse_options(struct netpoll *np, char *opt);
47be03a2 67int __netpoll_setup(struct netpoll *np, struct net_device *ndev, gfp_t gfp);
1da177e4
LT
68int netpoll_setup(struct netpoll *np);
69int netpoll_trap(void);
70void netpoll_set_trap(int trap);
8fdd95ec 71void __netpoll_cleanup(struct netpoll *np);
2cde6acd 72void __netpoll_free_async(struct netpoll *np);
1da177e4 73void netpoll_cleanup(struct netpoll *np);
57c5d461 74int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo);
c2355e1a
NH
75void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb,
76 struct net_device *dev);
77static inline void netpoll_send_skb(struct netpoll *np, struct sk_buff *skb)
78{
2899656b
AW
79 unsigned long flags;
80 local_irq_save(flags);
c2355e1a 81 netpoll_send_skb_on_dev(np, skb, np->dev);
2899656b 82 local_irq_restore(flags);
c2355e1a
NH
83}
84
5de4a473 85
1da177e4
LT
86
87#ifdef CONFIG_NETPOLL
77ab8a54 88static inline bool netpoll_rx_on(struct sk_buff *skb)
91fe4a4b
AW
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
ffb27362 95static inline bool netpoll_rx(struct sk_buff *skb)
1da177e4 96{
de85d99e 97 struct netpoll_info *npinfo;
fbeec2e1 98 unsigned long flags;
ffb27362 99 bool ret = false;
115c1d6e 100
f0f9deae 101 local_irq_save(flags);
de85d99e 102
91fe4a4b 103 if (!netpoll_rx_on(skb))
de85d99e 104 goto out;
115c1d6e 105
91fe4a4b 106 npinfo = rcu_dereference_bh(skb->dev->npinfo);
f0f9deae 107 spin_lock(&npinfo->rx_lock);
d9452e9f 108 /* check rx_flags again with the lock held */
57c5d461 109 if (npinfo->rx_flags && __netpoll_rx(skb, npinfo))
ffb27362 110 ret = true;
f0f9deae 111 spin_unlock(&npinfo->rx_lock);
fbeec2e1 112
de85d99e 113out:
f0f9deae 114 local_irq_restore(flags);
fbeec2e1 115 return ret;
1da177e4
LT
116}
117
bea3348e 118static inline int netpoll_receive_skb(struct sk_buff *skb)
1da177e4 119{
bea3348e
SH
120 if (!list_empty(&skb->dev->napi_list))
121 return netpoll_rx(skb);
122 return 0;
123}
124
125static inline void *netpoll_poll_lock(struct napi_struct *napi)
126{
127 struct net_device *dev = napi->dev;
128
bea3348e
SH
129 if (dev && dev->npinfo) {
130 spin_lock(&napi->poll_lock);
131 napi->poll_owner = smp_processor_id();
132 return napi;
1da177e4 133 }
53fb95d3 134 return NULL;
1da177e4
LT
135}
136
53fb95d3 137static inline void netpoll_poll_unlock(void *have)
1da177e4 138{
bea3348e 139 struct napi_struct *napi = have;
53fb95d3 140
bea3348e
SH
141 if (napi) {
142 napi->poll_owner = -1;
143 spin_unlock(&napi->poll_lock);
1da177e4
LT
144 }
145}
146
77ab8a54 147static inline bool netpoll_tx_running(struct net_device *dev)
c18370f5
HX
148{
149 return irqs_disabled();
150}
151
1da177e4 152#else
969a6e52 153static inline bool netpoll_rx(struct sk_buff *skb)
bea3348e 154{
77ab8a54 155 return false;
bea3348e 156}
77ab8a54 157static inline bool netpoll_rx_on(struct sk_buff *skb)
d1c76af9 158{
77ab8a54 159 return false;
d1c76af9 160}
bea3348e
SH
161static inline int netpoll_receive_skb(struct sk_buff *skb)
162{
163 return 0;
164}
165static inline void *netpoll_poll_lock(struct napi_struct *napi)
166{
167 return NULL;
168}
169static inline void netpoll_poll_unlock(void *have)
170{
171}
172static inline void netpoll_netdev_init(struct net_device *dev)
173{
174}
77ab8a54 175static inline bool netpoll_tx_running(struct net_device *dev)
c18370f5 176{
77ab8a54 177 return false;
c18370f5 178}
1da177e4
LT
179#endif
180
181#endif
This page took 1.09083 seconds and 5 git commands to generate.