Blame view

include/linux/netpoll.h 3.29 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;
0e34e9317   WANG Cong   netpoll: add gene...
16
  	struct net_device *real_dev;
bf6bce71e   Stephen Hemminger   netpoll header cl...
17
18
  	char dev_name[IFNAMSIZ];
  	const char *name;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
  	void (*rx_hook)(struct netpoll *, int, char *, int);
5de4a473b   Stephen Hemminger   netpoll queue cle...
20

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

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

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

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

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

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

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

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

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

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