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 __be32 ip; 19 struct in6_addr in6; 20 }; 21 22 struct netpoll { 23 struct net_device *dev; 24 netdevice_tracker dev_tracker; 25 /* 26 * Either dev_name or dev_mac can be used to specify the local 27 * interface - dev_name is used if it is a nonempty string, else 28 * dev_mac is used. 29 */ 30 char dev_name[IFNAMSIZ]; 31 u8 dev_mac[ETH_ALEN]; 32 const char *name; 33 34 union inet_addr local_ip, remote_ip; 35 bool ipv6; 36 u16 local_port, remote_port; 37 u8 remote_mac[ETH_ALEN]; 38 struct sk_buff_head skb_pool; 39 struct work_struct refill_wq; 40 }; 41 42 #define np_info(np, fmt, ...) \ 43 pr_info("%s: " fmt, np->name, ##__VA_ARGS__) 44 #define np_err(np, fmt, ...) \ 45 pr_err("%s: " fmt, np->name, ##__VA_ARGS__) 46 #define np_notice(np, fmt, ...) \ 47 pr_notice("%s: " fmt, np->name, ##__VA_ARGS__) 48 49 struct netpoll_info { 50 refcount_t refcnt; 51 52 struct semaphore dev_lock; 53 54 struct sk_buff_head txq; 55 56 struct delayed_work tx_work; 57 58 struct rcu_head rcu; 59 }; 60 61 #ifdef CONFIG_NETPOLL 62 void netpoll_poll_dev(struct net_device *dev); 63 void netpoll_poll_disable(struct net_device *dev); 64 void netpoll_poll_enable(struct net_device *dev); 65 #else 66 static inline void netpoll_poll_disable(struct net_device *dev) { return; } 67 static inline void netpoll_poll_enable(struct net_device *dev) { return; } 68 #endif 69 70 int netpoll_send_udp(struct netpoll *np, const char *msg, int len); 71 int __netpoll_setup(struct netpoll *np, struct net_device *ndev); 72 int netpoll_setup(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 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 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 102 static inline bool netpoll_tx_running(struct net_device *dev) 103 { 104 return irqs_disabled(); 105 } 106 107 #else 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 } 115 static inline bool netpoll_tx_running(struct net_device *dev) 116 { 117 return false; 118 } 119 #endif 120 121 #endif 122