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