xref: /linux/include/linux/netpoll.h (revision 5fa5ae60)
1b2441318SGreg 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;
27*5fa5ae60SEric Dumazet 	netdevice_tracker dev_tracker;
28bf6bce71SStephen Hemminger 	char dev_name[IFNAMSIZ];
29bf6bce71SStephen Hemminger 	const char *name;
305de4a473SStephen Hemminger 
31b7394d24SCong Wang 	union inet_addr local_ip, remote_ip;
32b7394d24SCong Wang 	bool ipv6;
331da177e4SLinus Torvalds 	u16 local_port, remote_port;
3409538641SStephen Hemminger 	u8 remote_mac[ETH_ALEN];
35115c1d6eSJeff Moyer };
36115c1d6eSJeff Moyer 
37115c1d6eSJeff Moyer struct netpoll_info {
38433cea4dSReshetova, Elena 	refcount_t refcnt;
39508e14b4SDaniel Borkmann 
40bd7c4b60SNeil Horman 	struct semaphore dev_lock;
41508e14b4SDaniel Borkmann 
42b6cd27edSStephen Hemminger 	struct sk_buff_head txq;
43508e14b4SDaniel Borkmann 
446d5aefb8SDavid Howells 	struct delayed_work tx_work;
450e34e931SWANG Cong 
460e34e931SWANG Cong 	struct netpoll *netpoll;
4738e6bc18SAmerigo Wang 	struct rcu_head rcu;
481da177e4SLinus Torvalds };
491da177e4SLinus Torvalds 
50ca99ca14SNeil Horman #ifdef CONFIG_NETPOLL
51ac3d9dd0SEric Dumazet void netpoll_poll_dev(struct net_device *dev);
52ac3d9dd0SEric Dumazet void netpoll_poll_disable(struct net_device *dev);
53ac3d9dd0SEric Dumazet void netpoll_poll_enable(struct net_device *dev);
54ca99ca14SNeil Horman #else
netpoll_poll_disable(struct net_device * dev)5566b5552fSEric W. Biederman static inline void netpoll_poll_disable(struct net_device *dev) { return; }
netpoll_poll_enable(struct net_device * dev)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);
65c9fbd71fSDebabrata Banerjee void __netpoll_free(struct netpoll *np);
661da177e4SLinus Torvalds void netpoll_cleanup(struct netpoll *np);
671ddabdfaSEric Dumazet netdev_tx_t netpoll_send_skb(struct netpoll *np, struct sk_buff *skb);
68c2355e1aSNeil Horman 
69e1bd4d3dSEric W. Biederman #ifdef CONFIG_NETPOLL
netpoll_poll_lock(struct napi_struct * napi)70bea3348eSStephen Hemminger static inline void *netpoll_poll_lock(struct napi_struct *napi)
71bea3348eSStephen Hemminger {
72bea3348eSStephen Hemminger 	struct net_device *dev = napi->dev;
73bea3348eSStephen Hemminger 
74bea3348eSStephen Hemminger 	if (dev && dev->npinfo) {
7589c4b442SEric Dumazet 		int owner = smp_processor_id();
7689c4b442SEric Dumazet 
7789c4b442SEric Dumazet 		while (cmpxchg(&napi->poll_owner, -1, owner) != -1)
7889c4b442SEric Dumazet 			cpu_relax();
7989c4b442SEric Dumazet 
80bea3348eSStephen Hemminger 		return napi;
811da177e4SLinus Torvalds 	}
8253fb95d3SMatt Mackall 	return NULL;
831da177e4SLinus Torvalds }
841da177e4SLinus Torvalds 
netpoll_poll_unlock(void * have)8553fb95d3SMatt Mackall static inline void netpoll_poll_unlock(void *have)
861da177e4SLinus Torvalds {
87bea3348eSStephen Hemminger 	struct napi_struct *napi = have;
8853fb95d3SMatt Mackall 
8989c4b442SEric Dumazet 	if (napi)
9089c4b442SEric Dumazet 		smp_store_release(&napi->poll_owner, -1);
911da177e4SLinus Torvalds }
921da177e4SLinus Torvalds 
netpoll_tx_running(struct net_device * dev)9377ab8a54SAmerigo Wang static inline bool netpoll_tx_running(struct net_device *dev)
94c18370f5SHerbert Xu {
95c18370f5SHerbert Xu 	return irqs_disabled();
96c18370f5SHerbert Xu }
97c18370f5SHerbert Xu 
981da177e4SLinus Torvalds #else
netpoll_poll_lock(struct napi_struct * napi)99bea3348eSStephen Hemminger static inline void *netpoll_poll_lock(struct napi_struct *napi)
100bea3348eSStephen Hemminger {
101bea3348eSStephen Hemminger 	return NULL;
102bea3348eSStephen Hemminger }
netpoll_poll_unlock(void * have)103bea3348eSStephen Hemminger static inline void netpoll_poll_unlock(void *have)
104bea3348eSStephen Hemminger {
105bea3348eSStephen Hemminger }
netpoll_tx_running(struct net_device * dev)10677ab8a54SAmerigo Wang static inline bool netpoll_tx_running(struct net_device *dev)
107c18370f5SHerbert Xu {
10877ab8a54SAmerigo Wang 	return false;
109c18370f5SHerbert Xu }
1101da177e4SLinus Torvalds #endif
1111da177e4SLinus Torvalds 
1121da177e4SLinus Torvalds #endif
113