blob: 27c0aaa22cb0f146c87b4e0abe6191fc7f1bbc8f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Common code for low-level network console, dump, and debugger code
3 *
4 * Derived from netconsole, kgdb-over-ethernet, and netdump patches
5 */
6
7#ifndef _LINUX_NETPOLL_H
8#define _LINUX_NETPOLL_H
9
10#include <linux/netdevice.h>
11#include <linux/interrupt.h>
Matt Mackall53fb95d2005-08-11 19:27:43 -070012#include <linux/rcupdate.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/list.h>
Reshetova, Elena433cea42017-06-30 13:08:04 +030014#include <linux/refcount.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Cong Wangb7394d22013-01-07 20:52:39 +000016union inet_addr {
17 __u32 all[4];
18 __be32 ip;
19 __be32 ip6[4];
20 struct in_addr in;
21 struct in6_addr in6;
22};
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024struct netpoll {
25 struct net_device *dev;
Stephen Hemmingerbf6bce72006-10-26 15:46:56 -070026 char dev_name[IFNAMSIZ];
27 const char *name;
Stephen Hemminger5de4a472006-10-26 15:46:55 -070028
Cong Wangb7394d22013-01-07 20:52:39 +000029 union inet_addr local_ip, remote_ip;
30 bool ipv6;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 u16 local_port, remote_port;
Stephen Hemminger09538642007-11-19 19:23:29 -080032 u8 remote_mac[ETH_ALEN];
Daniel Borkmann508e14b2010-01-12 14:27:30 +000033
Neil Horman2cde6ac2013-02-11 10:25:30 +000034 struct work_struct cleanup_work;
Jeff Moyer115c1d62005-06-22 22:05:31 -070035};
36
37struct netpoll_info {
Reshetova, Elena433cea42017-06-30 13:08:04 +030038 refcount_t refcnt;
Daniel Borkmann508e14b2010-01-12 14:27:30 +000039
Neil Hormanbd7c4b62013-04-30 05:35:05 +000040 struct semaphore dev_lock;
Daniel Borkmann508e14b2010-01-12 14:27:30 +000041
Stephen Hemmingerb6cd27e2006-10-26 15:46:51 -070042 struct sk_buff_head txq;
Daniel Borkmann508e14b2010-01-12 14:27:30 +000043
David Howells6d5aefb2006-12-05 19:36:26 +000044 struct delayed_work tx_work;
WANG Cong0e34e932010-05-06 00:47:21 -070045
46 struct netpoll *netpoll;
Amerigo Wang38e6bc12012-08-10 01:24:38 +000047 struct rcu_head rcu;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048};
49
Neil Hormanca99ca12013-02-05 08:05:43 +000050#ifdef CONFIG_NETPOLL
Eric W. Biederman66b55522014-03-27 15:39:03 -070051extern void netpoll_poll_disable(struct net_device *dev);
52extern void 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);
Neil Horman2cde6ac2013-02-11 10:25:30 +000064void __netpoll_free_async(struct netpoll *np);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065void netpoll_cleanup(struct netpoll *np);
Neil Hormanc2355e12010-10-13 16:01:49 +000066void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb,
67 struct net_device *dev);
68static inline void netpoll_send_skb(struct netpoll *np, struct sk_buff *skb)
69{
Amerigo Wang28996562012-08-10 01:24:42 +000070 unsigned long flags;
71 local_irq_save(flags);
Neil Hormanc2355e12010-10-13 16:01:49 +000072 netpoll_send_skb_on_dev(np, skb, np->dev);
Amerigo Wang28996562012-08-10 01:24:42 +000073 local_irq_restore(flags);
Neil Hormanc2355e12010-10-13 16:01:49 +000074}
75
Eric W. Biedermane1bd4d32014-03-14 20:50:58 -070076#ifdef CONFIG_NETPOLL
Stephen Hemmingerbea33482007-10-03 16:41:36 -070077static inline void *netpoll_poll_lock(struct napi_struct *napi)
78{
79 struct net_device *dev = napi->dev;
80
Stephen Hemmingerbea33482007-10-03 16:41:36 -070081 if (dev && dev->npinfo) {
Eric Dumazet89c4b442016-11-16 14:54:50 -080082 int owner = smp_processor_id();
83
84 while (cmpxchg(&napi->poll_owner, -1, owner) != -1)
85 cpu_relax();
86
Stephen Hemmingerbea33482007-10-03 16:41:36 -070087 return napi;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 }
Matt Mackall53fb95d2005-08-11 19:27:43 -070089 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
Matt Mackall53fb95d2005-08-11 19:27:43 -070092static inline void netpoll_poll_unlock(void *have)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
Stephen Hemmingerbea33482007-10-03 16:41:36 -070094 struct napi_struct *napi = have;
Matt Mackall53fb95d2005-08-11 19:27:43 -070095
Eric Dumazet89c4b442016-11-16 14:54:50 -080096 if (napi)
97 smp_store_release(&napi->poll_owner, -1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098}
99
Amerigo Wang77ab8a52012-08-10 01:24:46 +0000100static inline bool netpoll_tx_running(struct net_device *dev)
Herbert Xuc18370f2010-06-10 16:12:49 +0000101{
102 return irqs_disabled();
103}
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105#else
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700106static inline void *netpoll_poll_lock(struct napi_struct *napi)
107{
108 return NULL;
109}
110static inline void netpoll_poll_unlock(void *have)
111{
112}
113static inline void netpoll_netdev_init(struct net_device *dev)
114{
115}
Amerigo Wang77ab8a52012-08-10 01:24:46 +0000116static inline bool netpoll_tx_running(struct net_device *dev)
Herbert Xuc18370f2010-06-10 16:12:49 +0000117{
Amerigo Wang77ab8a52012-08-10 01:24:46 +0000118 return false;
Herbert Xuc18370f2010-06-10 16:12:49 +0000119}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120#endif
121
122#endif