blob: 1828900c94118ac959168873a91a6dcd4cb8d4cf [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>
14
Cong Wangb7394d22013-01-07 20:52:39 +000015union inet_addr {
16 __u32 all[4];
17 __be32 ip;
18 __be32 ip6[4];
19 struct in_addr in;
20 struct in6_addr in6;
21};
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023struct netpoll {
24 struct net_device *dev;
Stephen Hemmingerbf6bce72006-10-26 15:46:56 -070025 char dev_name[IFNAMSIZ];
26 const char *name;
Stephen Hemminger5de4a472006-10-26 15:46:55 -070027
Cong Wangb7394d22013-01-07 20:52:39 +000028 union inet_addr local_ip, remote_ip;
29 bool ipv6;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 u16 local_port, remote_port;
Stephen Hemminger09538642007-11-19 19:23:29 -080031 u8 remote_mac[ETH_ALEN];
Daniel Borkmann508e14b2010-01-12 14:27:30 +000032
Neil Horman2cde6ac2013-02-11 10:25:30 +000033 struct work_struct cleanup_work;
Jeff Moyer115c1d62005-06-22 22:05:31 -070034};
35
36struct netpoll_info {
Stephen Hemminger93ec2c72006-10-26 15:46:50 -070037 atomic_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 W. Biederman66b55522014-03-27 15:39:03 -070050extern void netpoll_poll_disable(struct net_device *dev);
51extern void netpoll_poll_enable(struct net_device *dev);
Neil Hormanca99ca12013-02-05 08:05:43 +000052#else
Eric W. Biederman66b55522014-03-27 15:39:03 -070053static inline void netpoll_poll_disable(struct net_device *dev) { return; }
54static inline void netpoll_poll_enable(struct net_device *dev) { return; }
Neil Hormanca99ca12013-02-05 08:05:43 +000055#endif
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057void netpoll_send_udp(struct netpoll *np, const char *msg, int len);
Satyam Sharma0bcc1812007-08-10 15:35:05 -070058void netpoll_print_options(struct netpoll *np);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059int netpoll_parse_options(struct netpoll *np, char *opt);
Eric W. Biedermana8779ec2014-03-27 15:36:38 -070060int __netpoll_setup(struct netpoll *np, struct net_device *ndev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061int netpoll_setup(struct netpoll *np);
Herbert Xu8fdd95e2010-06-10 16:12:48 +000062void __netpoll_cleanup(struct netpoll *np);
Neil Horman2cde6ac2013-02-11 10:25:30 +000063void __netpoll_free_async(struct netpoll *np);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064void netpoll_cleanup(struct netpoll *np);
Neil Hormanc2355e12010-10-13 16:01:49 +000065void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb,
66 struct net_device *dev);
67static inline void netpoll_send_skb(struct netpoll *np, struct sk_buff *skb)
68{
Amerigo Wang28996562012-08-10 01:24:42 +000069 unsigned long flags;
70 local_irq_save(flags);
Neil Hormanc2355e12010-10-13 16:01:49 +000071 netpoll_send_skb_on_dev(np, skb, np->dev);
Amerigo Wang28996562012-08-10 01:24:42 +000072 local_irq_restore(flags);
Neil Hormanc2355e12010-10-13 16:01:49 +000073}
74
Eric W. Biedermane1bd4d32014-03-14 20:50:58 -070075#ifdef CONFIG_NETPOLL
Stephen Hemmingerbea33482007-10-03 16:41:36 -070076static inline void *netpoll_poll_lock(struct napi_struct *napi)
77{
78 struct net_device *dev = napi->dev;
79
Stephen Hemmingerbea33482007-10-03 16:41:36 -070080 if (dev && dev->npinfo) {
Eric Dumazet89c4b442016-11-16 14:54:50 -080081 int owner = smp_processor_id();
82
83 while (cmpxchg(&napi->poll_owner, -1, owner) != -1)
84 cpu_relax();
85
Stephen Hemmingerbea33482007-10-03 16:41:36 -070086 return napi;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 }
Matt Mackall53fb95d2005-08-11 19:27:43 -070088 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
90
Matt Mackall53fb95d2005-08-11 19:27:43 -070091static inline void netpoll_poll_unlock(void *have)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092{
Stephen Hemmingerbea33482007-10-03 16:41:36 -070093 struct napi_struct *napi = have;
Matt Mackall53fb95d2005-08-11 19:27:43 -070094
Eric Dumazet89c4b442016-11-16 14:54:50 -080095 if (napi)
96 smp_store_release(&napi->poll_owner, -1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097}
98
Amerigo Wang77ab8a52012-08-10 01:24:46 +000099static inline bool netpoll_tx_running(struct net_device *dev)
Herbert Xuc18370f2010-06-10 16:12:49 +0000100{
101 return irqs_disabled();
102}
103
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104#else
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700105static inline void *netpoll_poll_lock(struct napi_struct *napi)
106{
107 return NULL;
108}
109static inline void netpoll_poll_unlock(void *have)
110{
111}
112static inline void netpoll_netdev_init(struct net_device *dev)
113{
114}
Amerigo Wang77ab8a52012-08-10 01:24:46 +0000115static inline bool netpoll_tx_running(struct net_device *dev)
Herbert Xuc18370f2010-06-10 16:12:49 +0000116{
Amerigo Wang77ab8a52012-08-10 01:24:46 +0000117 return false;
Herbert Xuc18370f2010-06-10 16:12:49 +0000118}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119#endif
120
121#endif