Blame view
include/linux/netpoll.h
3.29 KB
1da177e4c
|
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
|
12 |
#include <linux/rcupdate.h> |
1da177e4c
|
13 |
#include <linux/list.h> |
1da177e4c
|
14 15 |
struct netpoll { struct net_device *dev; |
0e34e9317
|
16 |
struct net_device *real_dev; |
bf6bce71e
|
17 18 |
char dev_name[IFNAMSIZ]; const char *name; |
1da177e4c
|
19 |
void (*rx_hook)(struct netpoll *, int, char *, int); |
5de4a473b
|
20 |
|
e7557af56
|
21 |
__be32 local_ip, remote_ip; |
1da177e4c
|
22 |
u16 local_port, remote_port; |
095386416
|
23 |
u8 remote_mac[ETH_ALEN]; |
508e14b4a
|
24 25 |
struct list_head rx; /* rx_np list element */ |
115c1d6e6
|
26 27 28 |
}; struct netpoll_info { |
93ec2c723
|
29 |
atomic_t refcnt; |
508e14b4a
|
30 |
|
d9452e9f8
|
31 |
int rx_flags; |
fbeec2e15
|
32 |
spinlock_t rx_lock; |
508e14b4a
|
33 |
struct list_head rx_np; /* netpolls that registered an rx_hook */ |
068c6e98b
|
34 |
struct sk_buff_head arp_tx; /* list of arp requests to reply to */ |
b6cd27ed3
|
35 |
struct sk_buff_head txq; |
508e14b4a
|
36 |
|
6d5aefb8e
|
37 |
struct delayed_work tx_work; |
0e34e9317
|
38 39 |
struct netpoll *netpoll; |
1da177e4c
|
40 |
}; |
0e34e9317
|
41 |
void netpoll_poll_dev(struct net_device *dev); |
1da177e4c
|
42 43 |
void netpoll_poll(struct netpoll *np); void netpoll_send_udp(struct netpoll *np, const char *msg, int len); |
0bcc18161
|
44 |
void netpoll_print_options(struct netpoll *np); |
1da177e4c
|
45 |
int netpoll_parse_options(struct netpoll *np, char *opt); |
8fdd95ec1
|
46 |
int __netpoll_setup(struct netpoll *np); |
1da177e4c
|
47 48 49 |
int netpoll_setup(struct netpoll *np); int netpoll_trap(void); void netpoll_set_trap(int trap); |
8fdd95ec1
|
50 |
void __netpoll_cleanup(struct netpoll *np); |
1da177e4c
|
51 52 |
void netpoll_cleanup(struct netpoll *np); int __netpoll_rx(struct sk_buff *skb); |
0e34e9317
|
53 |
void netpoll_send_skb(struct netpoll *np, struct sk_buff *skb); |
5de4a473b
|
54 |
|
1da177e4c
|
55 56 |
#ifdef CONFIG_NETPOLL |
ffb273623
|
57 |
static inline bool netpoll_rx(struct sk_buff *skb) |
1da177e4c
|
58 |
{ |
de85d99eb
|
59 |
struct netpoll_info *npinfo; |
fbeec2e15
|
60 |
unsigned long flags; |
ffb273623
|
61 |
bool ret = false; |
115c1d6e6
|
62 |
|
f0f9deae9
|
63 |
local_irq_save(flags); |
d5f31fbfd
|
64 |
npinfo = rcu_dereference_bh(skb->dev->npinfo); |
de85d99eb
|
65 |
|
508e14b4a
|
66 |
if (!npinfo || (list_empty(&npinfo->rx_np) && !npinfo->rx_flags)) |
de85d99eb
|
67 |
goto out; |
115c1d6e6
|
68 |
|
f0f9deae9
|
69 |
spin_lock(&npinfo->rx_lock); |
d9452e9f8
|
70 71 |
/* check rx_flags again with the lock held */ if (npinfo->rx_flags && __netpoll_rx(skb)) |
ffb273623
|
72 |
ret = true; |
f0f9deae9
|
73 |
spin_unlock(&npinfo->rx_lock); |
fbeec2e15
|
74 |
|
de85d99eb
|
75 |
out: |
f0f9deae9
|
76 |
local_irq_restore(flags); |
fbeec2e15
|
77 |
return ret; |
1da177e4c
|
78 |
} |
d1c76af9e
|
79 80 |
static inline int netpoll_rx_on(struct sk_buff *skb) { |
d5f31fbfd
|
81 |
struct netpoll_info *npinfo = rcu_dereference_bh(skb->dev->npinfo); |
d1c76af9e
|
82 |
|
508e14b4a
|
83 |
return npinfo && (!list_empty(&npinfo->rx_np) || npinfo->rx_flags); |
d1c76af9e
|
84 |
} |
bea3348ee
|
85 |
static inline int netpoll_receive_skb(struct sk_buff *skb) |
1da177e4c
|
86 |
{ |
bea3348ee
|
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
|
95 96 97 98 |
if (dev && dev->npinfo) { spin_lock(&napi->poll_lock); napi->poll_owner = smp_processor_id(); return napi; |
1da177e4c
|
99 |
} |
53fb95d3c
|
100 |
return NULL; |
1da177e4c
|
101 |
} |
53fb95d3c
|
102 |
static inline void netpoll_poll_unlock(void *have) |
1da177e4c
|
103 |
{ |
bea3348ee
|
104 |
struct napi_struct *napi = have; |
53fb95d3c
|
105 |
|
bea3348ee
|
106 107 108 |
if (napi) { napi->poll_owner = -1; spin_unlock(&napi->poll_lock); |
1da177e4c
|
109 110 |
} } |
c18370f5b
|
111 112 113 114 |
static inline int netpoll_tx_running(struct net_device *dev) { return irqs_disabled(); } |
1da177e4c
|
115 |
#else |
969a6e521
|
116 |
static inline bool netpoll_rx(struct sk_buff *skb) |
bea3348ee
|
117 118 119 |
{ return 0; } |
d1c76af9e
|
120 121 122 123 |
static inline int netpoll_rx_on(struct sk_buff *skb) { return 0; } |
bea3348ee
|
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
|
138 139 140 141 |
static inline int netpoll_tx_running(struct net_device *dev) { return 0; } |
1da177e4c
|
142 143 144 |
#endif #endif |