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