2 * Common code for low-level network console, dump, and debugger code
4 * Derived from netconsole, kgdb-over-ethernet, and netdump patches
7 #ifndef _LINUX_NETPOLL_H
8 #define _LINUX_NETPOLL_H
10 #include <linux/netdevice.h>
11 #include <linux/interrupt.h>
12 #include <linux/rcupdate.h>
13 #include <linux/list.h>
24 struct net_device *dev;
25 char dev_name[IFNAMSIZ];
27 void (*rx_hook)(struct netpoll *, int, char *, int);
29 union inet_addr local_ip, remote_ip;
31 u16 local_port, remote_port;
32 u8 remote_mac[ETH_ALEN];
34 struct list_head rx; /* rx_np list element */
43 struct list_head rx_np; /* netpolls that registered an rx_hook */
45 struct sk_buff_head neigh_tx; /* list of neigh requests to reply to */
46 struct sk_buff_head txq;
48 struct delayed_work tx_work;
50 struct netpoll *netpoll;
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)
70 local_irq_save(flags);
71 netpoll_send_skb_on_dev(np, skb, np->dev);
72 local_irq_restore(flags);
78 static inline bool netpoll_rx_on(struct sk_buff *skb)
80 struct netpoll_info *npinfo = rcu_dereference_bh(skb->dev->npinfo);
82 return npinfo && (!list_empty(&npinfo->rx_np) || npinfo->rx_flags);
85 static inline bool netpoll_rx(struct sk_buff *skb)
87 struct netpoll_info *npinfo;
91 local_irq_save(flags);
93 if (!netpoll_rx_on(skb))
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))
101 spin_unlock(&npinfo->rx_lock);
104 local_irq_restore(flags);
108 static inline int netpoll_receive_skb(struct sk_buff *skb)
110 if (!list_empty(&skb->dev->napi_list))
111 return netpoll_rx(skb);
115 static inline void *netpoll_poll_lock(struct napi_struct *napi)
117 struct net_device *dev = napi->dev;
119 if (dev && dev->npinfo) {
120 spin_lock(&napi->poll_lock);
121 napi->poll_owner = smp_processor_id();
127 static inline void netpoll_poll_unlock(void *have)
129 struct napi_struct *napi = have;
132 napi->poll_owner = -1;
133 spin_unlock(&napi->poll_lock);
137 static inline bool netpoll_tx_running(struct net_device *dev)
139 return irqs_disabled();
143 static inline bool netpoll_rx(struct sk_buff *skb)
147 static inline bool netpoll_rx_on(struct sk_buff *skb)
151 static inline int netpoll_receive_skb(struct sk_buff *skb)
155 static inline void *netpoll_poll_lock(struct napi_struct *napi)
159 static inline void netpoll_poll_unlock(void *have)
162 static inline void netpoll_netdev_init(struct net_device *dev)
165 static inline bool netpoll_tx_running(struct net_device *dev)