Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux
[GitHub/mt8127/android_kernel_alcatel_ttab.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
1da177e4 43void netpoll_send_udp(struct netpoll *np, const char *msg, int len);
0bcc1816 44void netpoll_print_options(struct netpoll *np);
1da177e4 45int netpoll_parse_options(struct netpoll *np, char *opt);
30fdd8a0 46int __netpoll_setup(struct netpoll *np, struct net_device *ndev);
1da177e4
LT
47int netpoll_setup(struct netpoll *np);
48int netpoll_trap(void);
49void netpoll_set_trap(int trap);
8fdd95ec 50void __netpoll_cleanup(struct netpoll *np);
1da177e4
LT
51void netpoll_cleanup(struct netpoll *np);
52int __netpoll_rx(struct sk_buff *skb);
c2355e1a
NH
53void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb,
54 struct net_device *dev);
55static inline void netpoll_send_skb(struct netpoll *np, struct sk_buff *skb)
56{
57 netpoll_send_skb_on_dev(np, skb, np->dev);
58}
59
5de4a473 60
1da177e4
LT
61
62#ifdef CONFIG_NETPOLL
ffb27362 63static inline bool netpoll_rx(struct sk_buff *skb)
1da177e4 64{
de85d99e 65 struct netpoll_info *npinfo;
fbeec2e1 66 unsigned long flags;
ffb27362 67 bool ret = false;
115c1d6e 68
f0f9deae 69 local_irq_save(flags);
d5f31fbf 70 npinfo = rcu_dereference_bh(skb->dev->npinfo);
de85d99e 71
508e14b4 72 if (!npinfo || (list_empty(&npinfo->rx_np) && !npinfo->rx_flags))
de85d99e 73 goto out;
115c1d6e 74
f0f9deae 75 spin_lock(&npinfo->rx_lock);
d9452e9f
DM
76 /* check rx_flags again with the lock held */
77 if (npinfo->rx_flags && __netpoll_rx(skb))
ffb27362 78 ret = true;
f0f9deae 79 spin_unlock(&npinfo->rx_lock);
fbeec2e1 80
de85d99e 81out:
f0f9deae 82 local_irq_restore(flags);
fbeec2e1 83 return ret;
1da177e4
LT
84}
85
d1c76af9
HX
86static inline int netpoll_rx_on(struct sk_buff *skb)
87{
d5f31fbf 88 struct netpoll_info *npinfo = rcu_dereference_bh(skb->dev->npinfo);
d1c76af9 89
508e14b4 90 return npinfo && (!list_empty(&npinfo->rx_np) || npinfo->rx_flags);
d1c76af9
HX
91}
92
bea3348e 93static inline int netpoll_receive_skb(struct sk_buff *skb)
1da177e4 94{
bea3348e
SH
95 if (!list_empty(&skb->dev->napi_list))
96 return netpoll_rx(skb);
97 return 0;
98}
99
100static inline void *netpoll_poll_lock(struct napi_struct *napi)
101{
102 struct net_device *dev = napi->dev;
103
bea3348e
SH
104 if (dev && dev->npinfo) {
105 spin_lock(&napi->poll_lock);
106 napi->poll_owner = smp_processor_id();
107 return napi;
1da177e4 108 }
53fb95d3 109 return NULL;
1da177e4
LT
110}
111
53fb95d3 112static inline void netpoll_poll_unlock(void *have)
1da177e4 113{
bea3348e 114 struct napi_struct *napi = have;
53fb95d3 115
bea3348e
SH
116 if (napi) {
117 napi->poll_owner = -1;
118 spin_unlock(&napi->poll_lock);
1da177e4
LT
119 }
120}
121
c18370f5
HX
122static inline int netpoll_tx_running(struct net_device *dev)
123{
124 return irqs_disabled();
125}
126
1da177e4 127#else
969a6e52 128static inline bool netpoll_rx(struct sk_buff *skb)
bea3348e
SH
129{
130 return 0;
131}
d1c76af9
HX
132static inline int netpoll_rx_on(struct sk_buff *skb)
133{
134 return 0;
135}
bea3348e
SH
136static inline int netpoll_receive_skb(struct sk_buff *skb)
137{
138 return 0;
139}
140static inline void *netpoll_poll_lock(struct napi_struct *napi)
141{
142 return NULL;
143}
144static inline void netpoll_poll_unlock(void *have)
145{
146}
147static inline void netpoll_netdev_init(struct net_device *dev)
148{
149}
c18370f5
HX
150static inline int netpoll_tx_running(struct net_device *dev)
151{
152 return 0;
153}
1da177e4
LT
154#endif
155
156#endif