1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Common code for low-level network console, dump, and debugger code
4 *
5 * Derived from netconsole, kgdb-over-ethernet, and netdump patches
6 */
7
8 #ifndef _LINUX_NETPOLL_H
9 #define _LINUX_NETPOLL_H
10
11 #include <linux/netdevice.h>
12 #include <linux/interrupt.h>
13 #include <linux/rcupdate.h>
14 #include <linux/list.h>
15 #include <linux/refcount.h>
16
17 union inet_addr {
18 __u32 all[4];
19 __be32 ip;
20 __be32 ip6[4];
21 struct in_addr in;
22 struct in6_addr in6;
23 };
24
25 struct netpoll {
26 struct net_device *dev;
27 netdevice_tracker dev_tracker;
28 /*
29 * Either dev_name or dev_mac can be used to specify the local
30 * interface - dev_name is used if it is a nonempty string, else
31 * dev_mac is used.
32 */
33 char dev_name[IFNAMSIZ];
34 u8 dev_mac[ETH_ALEN];
35 const char *name;
36
37 union inet_addr local_ip, remote_ip;
38 bool ipv6;
39 u16 local_port, remote_port;
40 u8 remote_mac[ETH_ALEN];
41 struct sk_buff_head skb_pool;
42 struct work_struct refill_wq;
43 };
44
45 struct netpoll_info {
46 refcount_t refcnt;
47
48 struct semaphore dev_lock;
49
50 struct sk_buff_head txq;
51
52 struct delayed_work tx_work;
53
54 struct netpoll *netpoll;
55 struct rcu_head rcu;
56 };
57
58 #ifdef CONFIG_NETPOLL
59 void netpoll_poll_dev(struct net_device *dev);
60 void netpoll_poll_disable(struct net_device *dev);
61 void netpoll_poll_enable(struct net_device *dev);
62 #else
netpoll_poll_disable(struct net_device * dev)63 static inline void netpoll_poll_disable(struct net_device *dev) { return; }
netpoll_poll_enable(struct net_device * dev)64 static inline void netpoll_poll_enable(struct net_device *dev) { return; }
65 #endif
66
67 int netpoll_send_udp(struct netpoll *np, const char *msg, int len);
68 void netpoll_print_options(struct netpoll *np);
69 int netpoll_parse_options(struct netpoll *np, char *opt);
70 int __netpoll_setup(struct netpoll *np, struct net_device *ndev);
71 int netpoll_setup(struct netpoll *np);
72 void __netpoll_cleanup(struct netpoll *np);
73 void __netpoll_free(struct netpoll *np);
74 void netpoll_cleanup(struct netpoll *np);
75 void do_netpoll_cleanup(struct netpoll *np);
76 netdev_tx_t netpoll_send_skb(struct netpoll *np, struct sk_buff *skb);
77
78 #ifdef CONFIG_NETPOLL
netpoll_poll_lock(struct napi_struct * napi)79 static inline void *netpoll_poll_lock(struct napi_struct *napi)
80 {
81 struct net_device *dev = napi->dev;
82
83 if (dev && rcu_access_pointer(dev->npinfo)) {
84 int owner = smp_processor_id();
85
86 while (cmpxchg(&napi->poll_owner, -1, owner) != -1)
87 cpu_relax();
88
89 return napi;
90 }
91 return NULL;
92 }
93
netpoll_poll_unlock(void * have)94 static inline void netpoll_poll_unlock(void *have)
95 {
96 struct napi_struct *napi = have;
97
98 if (napi)
99 smp_store_release(&napi->poll_owner, -1);
100 }
101
netpoll_tx_running(struct net_device * dev)102 static inline bool netpoll_tx_running(struct net_device *dev)
103 {
104 return irqs_disabled();
105 }
106
107 #else
netpoll_poll_lock(struct napi_struct * napi)108 static inline void *netpoll_poll_lock(struct napi_struct *napi)
109 {
110 return NULL;
111 }
netpoll_poll_unlock(void * have)112 static inline void netpoll_poll_unlock(void *have)
113 {
114 }
netpoll_tx_running(struct net_device * dev)115 static inline bool netpoll_tx_running(struct net_device *dev)
116 {
117 return false;
118 }
119 #endif
120
121 #endif
122