at v6.17 2.8 kB view raw
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 17union inet_addr { 18 __be32 ip; 19 struct in6_addr in6; 20}; 21 22struct 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 49struct 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 netpoll *netpoll; 59 struct rcu_head rcu; 60}; 61 62#ifdef CONFIG_NETPOLL 63void netpoll_poll_dev(struct net_device *dev); 64void netpoll_poll_disable(struct net_device *dev); 65void netpoll_poll_enable(struct net_device *dev); 66#else 67static inline void netpoll_poll_disable(struct net_device *dev) { return; } 68static inline void netpoll_poll_enable(struct net_device *dev) { return; } 69#endif 70 71int netpoll_send_udp(struct netpoll *np, const char *msg, int len); 72int __netpoll_setup(struct netpoll *np, struct net_device *ndev); 73int netpoll_setup(struct netpoll *np); 74void __netpoll_free(struct netpoll *np); 75void netpoll_cleanup(struct netpoll *np); 76void do_netpoll_cleanup(struct netpoll *np); 77netdev_tx_t netpoll_send_skb(struct netpoll *np, struct sk_buff *skb); 78 79#ifdef CONFIG_NETPOLL 80static inline void *netpoll_poll_lock(struct napi_struct *napi) 81{ 82 struct net_device *dev = napi->dev; 83 84 if (dev && rcu_access_pointer(dev->npinfo)) { 85 int owner = smp_processor_id(); 86 87 while (cmpxchg(&napi->poll_owner, -1, owner) != -1) 88 cpu_relax(); 89 90 return napi; 91 } 92 return NULL; 93} 94 95static inline void netpoll_poll_unlock(void *have) 96{ 97 struct napi_struct *napi = have; 98 99 if (napi) 100 smp_store_release(&napi->poll_owner, -1); 101} 102 103static inline bool netpoll_tx_running(struct net_device *dev) 104{ 105 return irqs_disabled(); 106} 107 108#else 109static inline void *netpoll_poll_lock(struct napi_struct *napi) 110{ 111 return NULL; 112} 113static inline void netpoll_poll_unlock(void *have) 114{ 115} 116static inline bool netpoll_tx_running(struct net_device *dev) 117{ 118 return false; 119} 120#endif 121 122#endif