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 #include <linux/ip.h> 17 #include <linux/udp.h> 18 19 struct netpoll { 20 struct net_device *dev; 21 netdevice_tracker dev_tracker; 22 /* 23 * Either dev_name or dev_mac can be used to specify the local 24 * interface - dev_name is used if it is a nonempty string, else 25 * dev_mac is used. 26 */ 27 char dev_name[IFNAMSIZ]; 28 u8 dev_mac[ETH_ALEN]; 29 const char *name; 30 }; 31 32 #define np_info(np, fmt, ...) \ 33 pr_info("%s: " fmt, np->name, ##__VA_ARGS__) 34 #define np_err(np, fmt, ...) \ 35 pr_err("%s: " fmt, np->name, ##__VA_ARGS__) 36 #define np_notice(np, fmt, ...) \ 37 pr_notice("%s: " fmt, np->name, ##__VA_ARGS__) 38 39 struct netpoll_info { 40 refcount_t refcnt; 41 42 struct semaphore dev_lock; 43 44 struct sk_buff_head txq; 45 46 struct delayed_work tx_work; 47 48 struct rcu_head rcu; 49 }; 50 51 #ifdef CONFIG_NETPOLL 52 void netpoll_poll_dev(struct net_device *dev); 53 void netpoll_poll_disable(struct net_device *dev); 54 void netpoll_poll_enable(struct net_device *dev); 55 #else 56 static inline void netpoll_poll_disable(struct net_device *dev) { return; } 57 static inline void netpoll_poll_enable(struct net_device *dev) { return; } 58 #endif 59 60 int __netpoll_setup(struct netpoll *np, struct net_device *ndev); 61 void __netpoll_free(struct netpoll *np); 62 void netpoll_cleanup(struct netpoll *np); 63 void do_netpoll_cleanup(struct netpoll *np); 64 netdev_tx_t netpoll_send_skb(struct netpoll *np, struct sk_buff *skb); 65 void netpoll_zap_completion_queue(void); 66 unsigned int netpoll_get_carrier_timeout(void); 67 68 #ifdef CONFIG_NETPOLL 69 static inline void *netpoll_poll_lock(struct napi_struct *napi) 70 { 71 struct net_device *dev = napi->dev; 72 73 if (dev && rcu_access_pointer(dev->npinfo)) { 74 int owner = smp_processor_id(); 75 76 while (cmpxchg(&napi->poll_owner, -1, owner) != -1) 77 cpu_relax(); 78 79 return napi; 80 } 81 return NULL; 82 } 83 84 static inline void netpoll_poll_unlock(void *have) 85 { 86 struct napi_struct *napi = have; 87 88 if (napi) 89 smp_store_release(&napi->poll_owner, -1); 90 } 91 92 static inline bool netpoll_tx_running(struct net_device *dev) 93 { 94 return irqs_disabled(); 95 } 96 97 #else 98 static inline void *netpoll_poll_lock(struct napi_struct *napi) 99 { 100 return NULL; 101 } 102 static inline void netpoll_poll_unlock(void *have) 103 { 104 } 105 static inline bool netpoll_tx_running(struct net_device *dev) 106 { 107 return false; 108 } 109 #endif 110 111 #endif 112