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