blob: e6a2d72e0dc7a6929d32a2e994f24719e073121e [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
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>
Matt Mackall53fb95d2005-08-11 19:27:43 -070013#include <linux/rcupdate.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/list.h>
Reshetova, Elena433cea42017-06-30 13:08:04 +030015#include <linux/refcount.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Cong Wangb7394d22013-01-07 20:52:39 +000017union inet_addr {
18 __u32 all[4];
19 __be32 ip;
20 __be32 ip6[4];
21 struct in_addr in;
22 struct in6_addr in6;
23};
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025struct netpoll {
26 struct net_device *dev;
Stephen Hemmingerbf6bce72006-10-26 15:46:56 -070027 char dev_name[IFNAMSIZ];
28 const char *name;
Stephen Hemminger5de4a472006-10-26 15:46:55 -070029
Cong Wangb7394d22013-01-07 20:52:39 +000030 union inet_addr local_ip, remote_ip;
31 bool ipv6;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 u16 local_port, remote_port;
Stephen Hemminger09538642007-11-19 19:23:29 -080033 u8 remote_mac[ETH_ALEN];
Jeff Moyer115c1d62005-06-22 22:05:31 -070034};
35
36struct netpoll_info {
Reshetova, Elena433cea42017-06-30 13:08:04 +030037 refcount_t refcnt;
Daniel Borkmann508e14b2010-01-12 14:27:30 +000038
Neil Hormanbd7c4b62013-04-30 05:35:05 +000039 struct semaphore dev_lock;
Daniel Borkmann508e14b2010-01-12 14:27:30 +000040
Stephen Hemmingerb6cd27e2006-10-26 15:46:51 -070041 struct sk_buff_head txq;
Daniel Borkmann508e14b2010-01-12 14:27:30 +000042
David Howells6d5aefb2006-12-05 19:36:26 +000043 struct delayed_work tx_work;
WANG Cong0e34e932010-05-06 00:47:21 -070044
45 struct netpoll *netpoll;
Amerigo Wang38e6bc12012-08-10 01:24:38 +000046 struct rcu_head rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047};
48
Neil Hormanca99ca12013-02-05 08:05:43 +000049#ifdef CONFIG_NETPOLL
Eric Dumazetac3d9dd2018-09-21 15:27:38 -070050void netpoll_poll_dev(struct net_device *dev);
51void netpoll_poll_disable(struct net_device *dev);
52void netpoll_poll_enable(struct net_device *dev);
Neil Hormanca99ca12013-02-05 08:05:43 +000053#else
Eric W. Biederman66b55522014-03-27 15:39:03 -070054static inline void netpoll_poll_disable(struct net_device *dev) { return; }
55static inline void netpoll_poll_enable(struct net_device *dev) { return; }
Neil Hormanca99ca12013-02-05 08:05:43 +000056#endif
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058void netpoll_send_udp(struct netpoll *np, const char *msg, int len);
Satyam Sharma0bcc1812007-08-10 15:35:05 -070059void netpoll_print_options(struct netpoll *np);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060int netpoll_parse_options(struct netpoll *np, char *opt);
Eric W. Biedermana8779ec2014-03-27 15:36:38 -070061int __netpoll_setup(struct netpoll *np, struct net_device *ndev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062int netpoll_setup(struct netpoll *np);
Herbert Xu8fdd95e2010-06-10 16:12:48 +000063void __netpoll_cleanup(struct netpoll *np);
Debabrata Banerjeec9fbd712018-10-18 11:18:26 -040064void __netpoll_free(struct netpoll *np);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065void netpoll_cleanup(struct netpoll *np);
Eric Dumazet1ddabdf2020-05-07 09:32:20 -070066netdev_tx_t netpoll_send_skb(struct netpoll *np, struct sk_buff *skb);
Neil Hormanc2355e12010-10-13 16:01:49 +000067
Eric W. Biedermane1bd4d32014-03-14 20:50:58 -070068#ifdef CONFIG_NETPOLL
Stephen Hemmingerbea33482007-10-03 16:41:36 -070069static inline void *netpoll_poll_lock(struct napi_struct *napi)
70{
71 struct net_device *dev = napi->dev;
72
Stephen Hemmingerbea33482007-10-03 16:41:36 -070073 if (dev && dev->npinfo) {
Eric Dumazet89c4b442016-11-16 14:54:50 -080074 int owner = smp_processor_id();
75
76 while (cmpxchg(&napi->poll_owner, -1, owner) != -1)
77 cpu_relax();
78
Stephen Hemmingerbea33482007-10-03 16:41:36 -070079 return napi;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 }
Matt Mackall53fb95d2005-08-11 19:27:43 -070081 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082}
83
Matt Mackall53fb95d2005-08-11 19:27:43 -070084static inline void netpoll_poll_unlock(void *have)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
Stephen Hemmingerbea33482007-10-03 16:41:36 -070086 struct napi_struct *napi = have;
Matt Mackall53fb95d2005-08-11 19:27:43 -070087
Eric Dumazet89c4b442016-11-16 14:54:50 -080088 if (napi)
89 smp_store_release(&napi->poll_owner, -1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
Amerigo Wang77ab8a52012-08-10 01:24:46 +000092static inline bool netpoll_tx_running(struct net_device *dev)
Herbert Xuc18370f2010-06-10 16:12:49 +000093{
94 return irqs_disabled();
95}
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097#else
Stephen Hemmingerbea33482007-10-03 16:41:36 -070098static inline void *netpoll_poll_lock(struct napi_struct *napi)
99{
100 return NULL;
101}
102static inline void netpoll_poll_unlock(void *have)
103{
104}
Amerigo Wang77ab8a52012-08-10 01:24:46 +0000105static inline bool netpoll_tx_running(struct net_device *dev)
Herbert Xuc18370f2010-06-10 16:12:49 +0000106{
Amerigo Wang77ab8a52012-08-10 01:24:46 +0000107 return false;
Herbert Xuc18370f2010-06-10 16:12:49 +0000108}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#endif
110
111#endif