1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * Common code for low-level network console, dump, and debugger code 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Derived from netconsole, kgdb-over-ethernet, and netdump patches 61da177e4SLinus Torvalds */ 71da177e4SLinus Torvalds 81da177e4SLinus Torvalds #ifndef _LINUX_NETPOLL_H 91da177e4SLinus Torvalds #define _LINUX_NETPOLL_H 101da177e4SLinus Torvalds 111da177e4SLinus Torvalds #include <linux/netdevice.h> 121da177e4SLinus Torvalds #include <linux/interrupt.h> 1353fb95d3SMatt Mackall #include <linux/rcupdate.h> 141da177e4SLinus Torvalds #include <linux/list.h> 15433cea4dSReshetova, Elena #include <linux/refcount.h> 161da177e4SLinus Torvalds 17b7394d24SCong Wang union inet_addr { 18b7394d24SCong Wang __u32 all[4]; 19b7394d24SCong Wang __be32 ip; 20b7394d24SCong Wang __be32 ip6[4]; 21b7394d24SCong Wang struct in_addr in; 22b7394d24SCong Wang struct in6_addr in6; 23b7394d24SCong Wang }; 24b7394d24SCong Wang 251da177e4SLinus Torvalds struct netpoll { 261da177e4SLinus Torvalds struct net_device *dev; 27bf6bce71SStephen Hemminger char dev_name[IFNAMSIZ]; 28bf6bce71SStephen Hemminger const char *name; 295de4a473SStephen Hemminger 30b7394d24SCong Wang union inet_addr local_ip, remote_ip; 31b7394d24SCong Wang bool ipv6; 321da177e4SLinus Torvalds u16 local_port, remote_port; 3309538641SStephen Hemminger u8 remote_mac[ETH_ALEN]; 34508e14b4SDaniel Borkmann 352cde6acdSNeil Horman struct work_struct cleanup_work; 36115c1d6eSJeff Moyer }; 37115c1d6eSJeff Moyer 38115c1d6eSJeff Moyer struct netpoll_info { 39433cea4dSReshetova, Elena refcount_t refcnt; 40508e14b4SDaniel Borkmann 41bd7c4b60SNeil Horman struct semaphore dev_lock; 42508e14b4SDaniel Borkmann 43b6cd27edSStephen Hemminger struct sk_buff_head txq; 44508e14b4SDaniel Borkmann 456d5aefb8SDavid Howells struct delayed_work tx_work; 460e34e931SWANG Cong 470e34e931SWANG Cong struct netpoll *netpoll; 4838e6bc18SAmerigo Wang struct rcu_head rcu; 491da177e4SLinus Torvalds }; 501da177e4SLinus Torvalds 51ca99ca14SNeil Horman #ifdef CONFIG_NETPOLL 5266b5552fSEric W. Biederman extern void netpoll_poll_disable(struct net_device *dev); 5366b5552fSEric W. Biederman extern void netpoll_poll_enable(struct net_device *dev); 54ca99ca14SNeil Horman #else 5566b5552fSEric W. Biederman static inline void netpoll_poll_disable(struct net_device *dev) { return; } 5666b5552fSEric W. Biederman static inline void netpoll_poll_enable(struct net_device *dev) { return; } 57ca99ca14SNeil Horman #endif 58ca99ca14SNeil Horman 591da177e4SLinus Torvalds void netpoll_send_udp(struct netpoll *np, const char *msg, int len); 600bcc1816SSatyam Sharma void netpoll_print_options(struct netpoll *np); 611da177e4SLinus Torvalds int netpoll_parse_options(struct netpoll *np, char *opt); 62a8779ec1SEric W. Biederman int __netpoll_setup(struct netpoll *np, struct net_device *ndev); 631da177e4SLinus Torvalds int netpoll_setup(struct netpoll *np); 648fdd95ecSHerbert Xu void __netpoll_cleanup(struct netpoll *np); 652cde6acdSNeil Horman void __netpoll_free_async(struct netpoll *np); 661da177e4SLinus Torvalds void netpoll_cleanup(struct netpoll *np); 67c2355e1aSNeil Horman void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb, 68c2355e1aSNeil Horman struct net_device *dev); 69c2355e1aSNeil Horman static inline void netpoll_send_skb(struct netpoll *np, struct sk_buff *skb) 70c2355e1aSNeil Horman { 712899656bSAmerigo Wang unsigned long flags; 722899656bSAmerigo Wang local_irq_save(flags); 73c2355e1aSNeil Horman netpoll_send_skb_on_dev(np, skb, np->dev); 742899656bSAmerigo Wang local_irq_restore(flags); 75c2355e1aSNeil Horman } 76c2355e1aSNeil Horman 77e1bd4d3dSEric W. Biederman #ifdef CONFIG_NETPOLL 78bea3348eSStephen Hemminger static inline void *netpoll_poll_lock(struct napi_struct *napi) 79bea3348eSStephen Hemminger { 80bea3348eSStephen Hemminger struct net_device *dev = napi->dev; 81bea3348eSStephen Hemminger 82bea3348eSStephen Hemminger if (dev && dev->npinfo) { 8389c4b442SEric Dumazet int owner = smp_processor_id(); 8489c4b442SEric Dumazet 8589c4b442SEric Dumazet while (cmpxchg(&napi->poll_owner, -1, owner) != -1) 8689c4b442SEric Dumazet cpu_relax(); 8789c4b442SEric Dumazet 88bea3348eSStephen Hemminger return napi; 891da177e4SLinus Torvalds } 9053fb95d3SMatt Mackall return NULL; 911da177e4SLinus Torvalds } 921da177e4SLinus Torvalds 9353fb95d3SMatt Mackall static inline void netpoll_poll_unlock(void *have) 941da177e4SLinus Torvalds { 95bea3348eSStephen Hemminger struct napi_struct *napi = have; 9653fb95d3SMatt Mackall 9789c4b442SEric Dumazet if (napi) 9889c4b442SEric Dumazet smp_store_release(&napi->poll_owner, -1); 991da177e4SLinus Torvalds } 1001da177e4SLinus Torvalds 10177ab8a54SAmerigo Wang static inline bool netpoll_tx_running(struct net_device *dev) 102c18370f5SHerbert Xu { 103c18370f5SHerbert Xu return irqs_disabled(); 104c18370f5SHerbert Xu } 105c18370f5SHerbert Xu 1061da177e4SLinus Torvalds #else 107bea3348eSStephen Hemminger static inline void *netpoll_poll_lock(struct napi_struct *napi) 108bea3348eSStephen Hemminger { 109bea3348eSStephen Hemminger return NULL; 110bea3348eSStephen Hemminger } 111bea3348eSStephen Hemminger static inline void netpoll_poll_unlock(void *have) 112bea3348eSStephen Hemminger { 113bea3348eSStephen Hemminger } 114bea3348eSStephen Hemminger static inline void netpoll_netdev_init(struct net_device *dev) 115bea3348eSStephen Hemminger { 116bea3348eSStephen Hemminger } 11777ab8a54SAmerigo Wang static inline bool netpoll_tx_running(struct net_device *dev) 118c18370f5SHerbert Xu { 11977ab8a54SAmerigo Wang return false; 120c18370f5SHerbert Xu } 1211da177e4SLinus Torvalds #endif 1221da177e4SLinus Torvalds 1231da177e4SLinus Torvalds #endif 124