Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
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> | |
53fb95d3 | 13 | #include <linux/rcupdate.h> |
1da177e4 | 14 | #include <linux/list.h> |
433cea4d | 15 | #include <linux/refcount.h> |
1da177e4 | 16 | |
b7394d24 CW |
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 | ||
1da177e4 LT |
25 | struct netpoll { |
26 | struct net_device *dev; | |
5fa5ae60 | 27 | netdevice_tracker dev_tracker; |
f8a10bed US |
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 | */ | |
bf6bce71 | 33 | char dev_name[IFNAMSIZ]; |
f8a10bed | 34 | u8 dev_mac[ETH_ALEN]; |
bf6bce71 | 35 | const char *name; |
5de4a473 | 36 | |
b7394d24 CW |
37 | union inet_addr local_ip, remote_ip; |
38 | bool ipv6; | |
1da177e4 | 39 | u16 local_port, remote_port; |
09538641 | 40 | u8 remote_mac[ETH_ALEN]; |
221a9c1d | 41 | struct sk_buff_head skb_pool; |
248f6571 | 42 | struct work_struct refill_wq; |
115c1d6e JM |
43 | }; |
44 | ||
45 | struct netpoll_info { | |
433cea4d | 46 | refcount_t refcnt; |
508e14b4 | 47 | |
bd7c4b60 | 48 | struct semaphore dev_lock; |
508e14b4 | 49 | |
b6cd27ed | 50 | struct sk_buff_head txq; |
508e14b4 | 51 | |
6d5aefb8 | 52 | struct delayed_work tx_work; |
0e34e931 WC |
53 | |
54 | struct netpoll *netpoll; | |
38e6bc18 | 55 | struct rcu_head rcu; |
1da177e4 LT |
56 | }; |
57 | ||
ca99ca14 | 58 | #ifdef CONFIG_NETPOLL |
ac3d9dd0 ED |
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); | |
ca99ca14 | 62 | #else |
66b5552f EB |
63 | static inline void netpoll_poll_disable(struct net_device *dev) { return; } |
64 | static inline void netpoll_poll_enable(struct net_device *dev) { return; } | |
ca99ca14 NH |
65 | #endif |
66 | ||
a61b19f4 | 67 | int netpoll_send_udp(struct netpoll *np, const char *msg, int len); |
0bcc1816 | 68 | void netpoll_print_options(struct netpoll *np); |
1da177e4 | 69 | int netpoll_parse_options(struct netpoll *np, char *opt); |
a8779ec1 | 70 | int __netpoll_setup(struct netpoll *np, struct net_device *ndev); |
1da177e4 | 71 | int netpoll_setup(struct netpoll *np); |
8fdd95ec | 72 | void __netpoll_cleanup(struct netpoll *np); |
c9fbd71f | 73 | void __netpoll_free(struct netpoll *np); |
1da177e4 | 74 | void netpoll_cleanup(struct netpoll *np); |
1ef33652 | 75 | void do_netpoll_cleanup(struct netpoll *np); |
1ddabdfa | 76 | netdev_tx_t netpoll_send_skb(struct netpoll *np, struct sk_buff *skb); |
c2355e1a | 77 | |
e1bd4d3d | 78 | #ifdef CONFIG_NETPOLL |
bea3348e SH |
79 | static inline void *netpoll_poll_lock(struct napi_struct *napi) |
80 | { | |
81 | struct net_device *dev = napi->dev; | |
82 | ||
a57d5a72 | 83 | if (dev && rcu_access_pointer(dev->npinfo)) { |
89c4b442 ED |
84 | int owner = smp_processor_id(); |
85 | ||
86 | while (cmpxchg(&napi->poll_owner, -1, owner) != -1) | |
87 | cpu_relax(); | |
88 | ||
bea3348e | 89 | return napi; |
1da177e4 | 90 | } |
53fb95d3 | 91 | return NULL; |
1da177e4 LT |
92 | } |
93 | ||
53fb95d3 | 94 | static inline void netpoll_poll_unlock(void *have) |
1da177e4 | 95 | { |
bea3348e | 96 | struct napi_struct *napi = have; |
53fb95d3 | 97 | |
89c4b442 ED |
98 | if (napi) |
99 | smp_store_release(&napi->poll_owner, -1); | |
1da177e4 LT |
100 | } |
101 | ||
77ab8a54 | 102 | static inline bool netpoll_tx_running(struct net_device *dev) |
c18370f5 HX |
103 | { |
104 | return irqs_disabled(); | |
105 | } | |
106 | ||
1da177e4 | 107 | #else |
bea3348e SH |
108 | static inline void *netpoll_poll_lock(struct napi_struct *napi) |
109 | { | |
110 | return NULL; | |
111 | } | |
112 | static inline void netpoll_poll_unlock(void *have) | |
113 | { | |
114 | } | |
77ab8a54 | 115 | static inline bool netpoll_tx_running(struct net_device *dev) |
c18370f5 | 116 | { |
77ab8a54 | 117 | return false; |
c18370f5 | 118 | } |
1da177e4 LT |
119 | #endif |
120 | ||
121 | #endif |