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 */
41 unsigned long rx_flags;
43 struct mutex dev_lock;
44 struct list_head rx_np; /* netpolls that registered an rx_hook */
46 struct sk_buff_head neigh_tx; /* list of neigh requests to reply to */
47 struct sk_buff_head txq;
49 struct delayed_work tx_work;
51 struct netpoll *netpoll;
56 extern int netpoll_rx_disable(struct net_device *dev);
57 extern void netpoll_rx_enable(struct net_device *dev);
59 static inline int netpoll_rx_disable(struct net_device *dev) { return 0; }
60 static inline void netpoll_rx_enable(struct net_device *dev) { return; }
63 void netpoll_send_udp(struct netpoll *np, const char *msg, int len);
64 void netpoll_print_options(struct netpoll *np);
65 int netpoll_parse_options(struct netpoll *np, char *opt);
66 int __netpoll_setup(struct netpoll *np, struct net_device *ndev, gfp_t gfp);
67 int netpoll_setup(struct netpoll *np);
68 int netpoll_trap(void);
69 void netpoll_set_trap(int trap);
70 void __netpoll_cleanup(struct netpoll *np);
71 void __netpoll_free_rcu(struct netpoll *np);
72 void netpoll_cleanup(struct netpoll *np);
73 int __netpoll_rx(struct sk_buff *skb, struct netpoll_info *npinfo);
74 void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb,
75 struct net_device *dev);
76 static inline void netpoll_send_skb(struct netpoll *np, struct sk_buff *skb)
79 local_irq_save(flags);
80 netpoll_send_skb_on_dev(np, skb, np->dev);
81 local_irq_restore(flags);
87 static inline bool netpoll_rx_on(struct sk_buff *skb)
89 struct netpoll_info *npinfo = rcu_dereference_bh(skb->dev->npinfo);
91 return npinfo && (!list_empty(&npinfo->rx_np) || npinfo->rx_flags);
94 static inline bool netpoll_rx(struct sk_buff *skb)
96 struct netpoll_info *npinfo;
100 local_irq_save(flags);
102 if (!netpoll_rx_on(skb))
105 npinfo = rcu_dereference_bh(skb->dev->npinfo);
106 spin_lock(&npinfo->rx_lock);
107 /* check rx_flags again with the lock held */
108 if (npinfo->rx_flags && __netpoll_rx(skb, npinfo))
110 spin_unlock(&npinfo->rx_lock);
113 local_irq_restore(flags);
117 static inline int netpoll_receive_skb(struct sk_buff *skb)
119 if (!list_empty(&skb->dev->napi_list))
120 return netpoll_rx(skb);
124 static inline void *netpoll_poll_lock(struct napi_struct *napi)
126 struct net_device *dev = napi->dev;
128 if (dev && dev->npinfo) {
129 spin_lock(&napi->poll_lock);
130 napi->poll_owner = smp_processor_id();
136 static inline void netpoll_poll_unlock(void *have)
138 struct napi_struct *napi = have;
141 napi->poll_owner = -1;
142 spin_unlock(&napi->poll_lock);
146 static inline bool netpoll_tx_running(struct net_device *dev)
148 return irqs_disabled();
152 static inline bool netpoll_rx(struct sk_buff *skb)
156 static inline bool netpoll_rx_on(struct sk_buff *skb)
160 static inline int netpoll_receive_skb(struct sk_buff *skb)
164 static inline void *netpoll_poll_lock(struct napi_struct *napi)
168 static inline void netpoll_poll_unlock(void *have)
171 static inline void netpoll_netdev_init(struct net_device *dev)
174 static inline bool netpoll_tx_running(struct net_device *dev)