ipv6: Fix endianess warning in ip6_flow_hdr().
[deliverable/linux.git] / include / linux / netpoll.h
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>
12 #include <linux/rcupdate.h>
13 #include <linux/list.h>
14
15 union 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
23 struct netpoll {
24 struct net_device *dev;
25 char dev_name[IFNAMSIZ];
26 const char *name;
27 void (*rx_hook)(struct netpoll *, int, char *, int);
28
29 union inet_addr local_ip, remote_ip;
30 bool ipv6;
31 u16 local_port, remote_port;
32 u8 remote_mac[ETH_ALEN];
33
34 struct list_head rx; /* rx_np list element */
35 struct rcu_head rcu;
36 };
37
38 struct netpoll_info {
39 atomic_t refcnt;
40
41 int rx_flags;
42 spinlock_t rx_lock;
43 struct list_head rx_np; /* netpolls that registered an rx_hook */
44
45 struct sk_buff_head neigh_tx; /* list of neigh requests to reply to */
46 struct sk_buff_head txq;
47
48 struct delayed_work tx_work;
49
50 struct netpoll *netpoll;
51 struct rcu_head rcu;
52 };
53
54 void netpoll_send_udp(struct netpoll *np, const char *msg, int len);
55 void netpoll_print_options(struct netpoll *np);
56 int netpoll_parse_options(struct netpoll *np, char *opt);
57 int __netpoll_setup(struct netpoll *np, struct net_device *ndev, gfp_t gfp);
58 int netpoll_setup(struct netpoll *np);
59 int netpoll_trap(void);
60 void netpoll_set_trap(int trap);
61 void __netpoll_cleanup(struct netpoll *np);
62 void __netpoll_free_rcu(struct netpoll *np);
63 void netpoll_cleanup(struct netpoll *np);
64 int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo);
65 void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb,
66 struct net_device *dev);
67 static inline void netpoll_send_skb(struct netpoll *np, struct sk_buff *skb)
68 {
69 unsigned long flags;
70 local_irq_save(flags);
71 netpoll_send_skb_on_dev(np, skb, np->dev);
72 local_irq_restore(flags);
73 }
74
75
76
77 #ifdef CONFIG_NETPOLL
78 static inline bool netpoll_rx_on(struct sk_buff *skb)
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
85 static inline bool netpoll_rx(struct sk_buff *skb)
86 {
87 struct netpoll_info *npinfo;
88 unsigned long flags;
89 bool ret = false;
90
91 local_irq_save(flags);
92
93 if (!netpoll_rx_on(skb))
94 goto out;
95
96 npinfo = rcu_dereference_bh(skb->dev->npinfo);
97 spin_lock(&npinfo->rx_lock);
98 /* check rx_flags again with the lock held */
99 if (npinfo->rx_flags && __netpoll_rx(skb, npinfo))
100 ret = true;
101 spin_unlock(&npinfo->rx_lock);
102
103 out:
104 local_irq_restore(flags);
105 return ret;
106 }
107
108 static inline int netpoll_receive_skb(struct sk_buff *skb)
109 {
110 if (!list_empty(&skb->dev->napi_list))
111 return netpoll_rx(skb);
112 return 0;
113 }
114
115 static inline void *netpoll_poll_lock(struct napi_struct *napi)
116 {
117 struct net_device *dev = napi->dev;
118
119 if (dev && dev->npinfo) {
120 spin_lock(&napi->poll_lock);
121 napi->poll_owner = smp_processor_id();
122 return napi;
123 }
124 return NULL;
125 }
126
127 static inline void netpoll_poll_unlock(void *have)
128 {
129 struct napi_struct *napi = have;
130
131 if (napi) {
132 napi->poll_owner = -1;
133 spin_unlock(&napi->poll_lock);
134 }
135 }
136
137 static inline bool netpoll_tx_running(struct net_device *dev)
138 {
139 return irqs_disabled();
140 }
141
142 #else
143 static inline bool netpoll_rx(struct sk_buff *skb)
144 {
145 return false;
146 }
147 static inline bool netpoll_rx_on(struct sk_buff *skb)
148 {
149 return false;
150 }
151 static inline int netpoll_receive_skb(struct sk_buff *skb)
152 {
153 return 0;
154 }
155 static inline void *netpoll_poll_lock(struct napi_struct *napi)
156 {
157 return NULL;
158 }
159 static inline void netpoll_poll_unlock(void *have)
160 {
161 }
162 static inline void netpoll_netdev_init(struct net_device *dev)
163 {
164 }
165 static inline bool netpoll_tx_running(struct net_device *dev)
166 {
167 return false;
168 }
169 #endif
170
171 #endif
This page took 0.037228 seconds and 5 git commands to generate.