Blame view

include/linux/netpoll.h 3.34 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
  /*
   * Common code for low-level network console, dump, and debugger code
   *
   * Derived from netconsole, kgdb-over-ethernet, and netdump patches
   */
  
  #ifndef _LINUX_NETPOLL_H
  #define _LINUX_NETPOLL_H
  
  #include <linux/netdevice.h>
  #include <linux/interrupt.h>
53fb95d3c   Matt Mackall   [NETPOLL]: fix in...
12
  #include <linux/rcupdate.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
  #include <linux/list.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
14
15
  struct netpoll {
  	struct net_device *dev;
bf6bce71e   Stephen Hemminger   netpoll header cl...
16
17
  	char dev_name[IFNAMSIZ];
  	const char *name;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
18
  	void (*rx_hook)(struct netpoll *, int, char *, int);
5de4a473b   Stephen Hemminger   netpoll queue cle...
19

e7557af56   Harvey Harrison   netpoll: store lo...
20
  	__be32 local_ip, remote_ip;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
  	u16 local_port, remote_port;
095386416   Stephen Hemminger   [NETPOLL]: no nee...
22
  	u8 remote_mac[ETH_ALEN];
508e14b4a   Daniel Borkmann   netpoll: allow ex...
23
24
  
  	struct list_head rx; /* rx_np list element */
115c1d6e6   Jeff Moyer   [NETPOLL]: Introd...
25
26
27
  };
  
  struct netpoll_info {
93ec2c723   Stephen Hemminger   netpoll info leak
28
  	atomic_t refcnt;
508e14b4a   Daniel Borkmann   netpoll: allow ex...
29

d9452e9f8   David S. Miller   [NETPOLL]: Revert...
30
  	int rx_flags;
fbeec2e15   Jeff Moyer   [NETPOLL]: allow ...
31
  	spinlock_t rx_lock;
508e14b4a   Daniel Borkmann   netpoll: allow ex...
32
  	struct list_head rx_np; /* netpolls that registered an rx_hook */
068c6e98b   Neil Horman   [NET] netpoll: br...
33
  	struct sk_buff_head arp_tx; /* list of arp requests to reply to */
b6cd27ed3   Stephen Hemminger   netpoll per devic...
34
  	struct sk_buff_head txq;
508e14b4a   Daniel Borkmann   netpoll: allow ex...
35

6d5aefb8e   David Howells   WorkQueue: Fix up...
36
  	struct delayed_work tx_work;
0e34e9317   WANG Cong   netpoll: add gene...
37
38
  
  	struct netpoll *netpoll;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
39
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
  void netpoll_send_udp(struct netpoll *np, const char *msg, int len);
0bcc18161   Satyam Sharma   [NET] netconsole:...
41
  void netpoll_print_options(struct netpoll *np);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
  int netpoll_parse_options(struct netpoll *np, char *opt);
8fdd95ec1   Herbert Xu   netpoll: Allow ne...
43
  int __netpoll_setup(struct netpoll *np);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
45
46
  int netpoll_setup(struct netpoll *np);
  int netpoll_trap(void);
  void netpoll_set_trap(int trap);
8fdd95ec1   Herbert Xu   netpoll: Allow ne...
47
  void __netpoll_cleanup(struct netpoll *np);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
48
49
  void netpoll_cleanup(struct netpoll *np);
  int __netpoll_rx(struct sk_buff *skb);
c2355e1ab   Neil Horman   bonding: Fix bond...
50
51
52
53
54
55
  void netpoll_send_skb_on_dev(struct netpoll *np, struct sk_buff *skb,
  			     struct net_device *dev);
  static inline void netpoll_send_skb(struct netpoll *np, struct sk_buff *skb)
  {
  	netpoll_send_skb_on_dev(np, skb, np->dev);
  }
5de4a473b   Stephen Hemminger   netpoll queue cle...
56

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
57
58
  
  #ifdef CONFIG_NETPOLL
ffb273623   David S. Miller   netpoll: Use 'boo...
59
  static inline bool netpoll_rx(struct sk_buff *skb)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
60
  {
de85d99eb   Herbert Xu   netpoll: Fix RCU ...
61
  	struct netpoll_info *npinfo;
fbeec2e15   Jeff Moyer   [NETPOLL]: allow ...
62
  	unsigned long flags;
ffb273623   David S. Miller   netpoll: Use 'boo...
63
  	bool ret = false;
115c1d6e6   Jeff Moyer   [NETPOLL]: Introd...
64

f0f9deae9   Herbert Xu   netpoll: Disable ...
65
  	local_irq_save(flags);
d5f31fbfd   Herbert Xu   netpoll: Use corr...
66
  	npinfo = rcu_dereference_bh(skb->dev->npinfo);
de85d99eb   Herbert Xu   netpoll: Fix RCU ...
67

508e14b4a   Daniel Borkmann   netpoll: allow ex...
68
  	if (!npinfo || (list_empty(&npinfo->rx_np) && !npinfo->rx_flags))
de85d99eb   Herbert Xu   netpoll: Fix RCU ...
69
  		goto out;
115c1d6e6   Jeff Moyer   [NETPOLL]: Introd...
70

f0f9deae9   Herbert Xu   netpoll: Disable ...
71
  	spin_lock(&npinfo->rx_lock);
d9452e9f8   David S. Miller   [NETPOLL]: Revert...
72
73
  	/* check rx_flags again with the lock held */
  	if (npinfo->rx_flags && __netpoll_rx(skb))
ffb273623   David S. Miller   netpoll: Use 'boo...
74
  		ret = true;
f0f9deae9   Herbert Xu   netpoll: Disable ...
75
  	spin_unlock(&npinfo->rx_lock);
fbeec2e15   Jeff Moyer   [NETPOLL]: allow ...
76

de85d99eb   Herbert Xu   netpoll: Fix RCU ...
77
  out:
f0f9deae9   Herbert Xu   netpoll: Disable ...
78
  	local_irq_restore(flags);
fbeec2e15   Jeff Moyer   [NETPOLL]: allow ...
79
  	return ret;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
80
  }
d1c76af9e   Herbert Xu   GRO: Move netpoll...
81
82
  static inline int netpoll_rx_on(struct sk_buff *skb)
  {
d5f31fbfd   Herbert Xu   netpoll: Use corr...
83
  	struct netpoll_info *npinfo = rcu_dereference_bh(skb->dev->npinfo);
d1c76af9e   Herbert Xu   GRO: Move netpoll...
84

508e14b4a   Daniel Borkmann   netpoll: allow ex...
85
  	return npinfo && (!list_empty(&npinfo->rx_np) || npinfo->rx_flags);
d1c76af9e   Herbert Xu   GRO: Move netpoll...
86
  }
bea3348ee   Stephen Hemminger   [NET]: Make NAPI ...
87
  static inline int netpoll_receive_skb(struct sk_buff *skb)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
88
  {
bea3348ee   Stephen Hemminger   [NET]: Make NAPI ...
89
90
91
92
93
94
95
96
  	if (!list_empty(&skb->dev->napi_list))
  		return netpoll_rx(skb);
  	return 0;
  }
  
  static inline void *netpoll_poll_lock(struct napi_struct *napi)
  {
  	struct net_device *dev = napi->dev;
bea3348ee   Stephen Hemminger   [NET]: Make NAPI ...
97
98
99
100
  	if (dev && dev->npinfo) {
  		spin_lock(&napi->poll_lock);
  		napi->poll_owner = smp_processor_id();
  		return napi;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
101
  	}
53fb95d3c   Matt Mackall   [NETPOLL]: fix in...
102
  	return NULL;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
103
  }
53fb95d3c   Matt Mackall   [NETPOLL]: fix in...
104
  static inline void netpoll_poll_unlock(void *have)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
105
  {
bea3348ee   Stephen Hemminger   [NET]: Make NAPI ...
106
  	struct napi_struct *napi = have;
53fb95d3c   Matt Mackall   [NETPOLL]: fix in...
107

bea3348ee   Stephen Hemminger   [NET]: Make NAPI ...
108
109
110
  	if (napi) {
  		napi->poll_owner = -1;
  		spin_unlock(&napi->poll_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
111
112
  	}
  }
c18370f5b   Herbert Xu   netpoll: Add netp...
113
114
115
116
  static inline int netpoll_tx_running(struct net_device *dev)
  {
  	return irqs_disabled();
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
117
  #else
969a6e521   John W. Linville   net: make netpoll...
118
  static inline bool netpoll_rx(struct sk_buff *skb)
bea3348ee   Stephen Hemminger   [NET]: Make NAPI ...
119
120
121
  {
  	return 0;
  }
d1c76af9e   Herbert Xu   GRO: Move netpoll...
122
123
124
125
  static inline int netpoll_rx_on(struct sk_buff *skb)
  {
  	return 0;
  }
bea3348ee   Stephen Hemminger   [NET]: Make NAPI ...
126
127
128
129
130
131
132
133
134
135
136
137
138
139
  static inline int netpoll_receive_skb(struct sk_buff *skb)
  {
  	return 0;
  }
  static inline void *netpoll_poll_lock(struct napi_struct *napi)
  {
  	return NULL;
  }
  static inline void netpoll_poll_unlock(void *have)
  {
  }
  static inline void netpoll_netdev_init(struct net_device *dev)
  {
  }
c18370f5b   Herbert Xu   netpoll: Add netp...
140
141
142
143
  static inline int netpoll_tx_running(struct net_device *dev)
  {
  	return 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
144
145
146
  #endif
  
  #endif