Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
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> | |
53fb95d3 | 12 | #include <linux/rcupdate.h> |
1da177e4 LT |
13 | #include <linux/list.h> |
14 | ||
1da177e4 LT |
15 | struct netpoll { |
16 | struct net_device *dev; | |
0e34e931 | 17 | struct net_device *real_dev; |
bf6bce71 SH |
18 | char dev_name[IFNAMSIZ]; |
19 | const char *name; | |
1da177e4 | 20 | void (*rx_hook)(struct netpoll *, int, char *, int); |
5de4a473 | 21 | |
e7557af5 | 22 | __be32 local_ip, remote_ip; |
1da177e4 | 23 | u16 local_port, remote_port; |
09538641 | 24 | u8 remote_mac[ETH_ALEN]; |
508e14b4 DB |
25 | |
26 | struct list_head rx; /* rx_np list element */ | |
115c1d6e JM |
27 | }; |
28 | ||
29 | struct netpoll_info { | |
93ec2c72 | 30 | atomic_t refcnt; |
508e14b4 | 31 | |
d9452e9f | 32 | int rx_flags; |
fbeec2e1 | 33 | spinlock_t rx_lock; |
508e14b4 DB |
34 | struct list_head rx_np; /* netpolls that registered an rx_hook */ |
35 | ||
068c6e98 | 36 | struct sk_buff_head arp_tx; /* list of arp requests to reply to */ |
b6cd27ed | 37 | struct sk_buff_head txq; |
508e14b4 | 38 | |
6d5aefb8 | 39 | struct delayed_work tx_work; |
0e34e931 WC |
40 | |
41 | struct netpoll *netpoll; | |
1da177e4 LT |
42 | }; |
43 | ||
0e34e931 | 44 | void netpoll_poll_dev(struct net_device *dev); |
1da177e4 LT |
45 | void netpoll_poll(struct netpoll *np); |
46 | void netpoll_send_udp(struct netpoll *np, const char *msg, int len); | |
0bcc1816 | 47 | void netpoll_print_options(struct netpoll *np); |
1da177e4 LT |
48 | int netpoll_parse_options(struct netpoll *np, char *opt); |
49 | int netpoll_setup(struct netpoll *np); | |
50 | int netpoll_trap(void); | |
51 | void netpoll_set_trap(int trap); | |
52 | void netpoll_cleanup(struct netpoll *np); | |
53 | int __netpoll_rx(struct sk_buff *skb); | |
0e34e931 | 54 | void netpoll_send_skb(struct netpoll *np, struct sk_buff *skb); |
5de4a473 | 55 | |
1da177e4 LT |
56 | |
57 | #ifdef CONFIG_NETPOLL | |
ffb27362 | 58 | static inline bool netpoll_rx(struct sk_buff *skb) |
1da177e4 | 59 | { |
115c1d6e | 60 | struct netpoll_info *npinfo = skb->dev->npinfo; |
fbeec2e1 | 61 | unsigned long flags; |
ffb27362 | 62 | bool ret = false; |
115c1d6e | 63 | |
508e14b4 | 64 | if (!npinfo || (list_empty(&npinfo->rx_np) && !npinfo->rx_flags)) |
ffb27362 | 65 | return false; |
115c1d6e | 66 | |
fbeec2e1 | 67 | spin_lock_irqsave(&npinfo->rx_lock, flags); |
d9452e9f DM |
68 | /* check rx_flags again with the lock held */ |
69 | if (npinfo->rx_flags && __netpoll_rx(skb)) | |
ffb27362 | 70 | ret = true; |
fbeec2e1 JM |
71 | spin_unlock_irqrestore(&npinfo->rx_lock, flags); |
72 | ||
73 | return ret; | |
1da177e4 LT |
74 | } |
75 | ||
d1c76af9 HX |
76 | static inline int netpoll_rx_on(struct sk_buff *skb) |
77 | { | |
78 | struct netpoll_info *npinfo = skb->dev->npinfo; | |
79 | ||
508e14b4 | 80 | return npinfo && (!list_empty(&npinfo->rx_np) || npinfo->rx_flags); |
d1c76af9 HX |
81 | } |
82 | ||
bea3348e | 83 | static inline int netpoll_receive_skb(struct sk_buff *skb) |
1da177e4 | 84 | { |
bea3348e SH |
85 | if (!list_empty(&skb->dev->napi_list)) |
86 | return netpoll_rx(skb); | |
87 | return 0; | |
88 | } | |
89 | ||
90 | static inline void *netpoll_poll_lock(struct napi_struct *napi) | |
91 | { | |
92 | struct net_device *dev = napi->dev; | |
93 | ||
53fb95d3 | 94 | rcu_read_lock(); /* deal with race on ->npinfo */ |
bea3348e SH |
95 | if (dev && dev->npinfo) { |
96 | spin_lock(&napi->poll_lock); | |
97 | napi->poll_owner = smp_processor_id(); | |
98 | return napi; | |
1da177e4 | 99 | } |
53fb95d3 | 100 | return NULL; |
1da177e4 LT |
101 | } |
102 | ||
53fb95d3 | 103 | static inline void netpoll_poll_unlock(void *have) |
1da177e4 | 104 | { |
bea3348e | 105 | struct napi_struct *napi = have; |
53fb95d3 | 106 | |
bea3348e SH |
107 | if (napi) { |
108 | napi->poll_owner = -1; | |
109 | spin_unlock(&napi->poll_lock); | |
1da177e4 | 110 | } |
53fb95d3 | 111 | rcu_read_unlock(); |
1da177e4 LT |
112 | } |
113 | ||
114 | #else | |
bea3348e SH |
115 | static inline int netpoll_rx(struct sk_buff *skb) |
116 | { | |
117 | return 0; | |
118 | } | |
d1c76af9 HX |
119 | static inline int netpoll_rx_on(struct sk_buff *skb) |
120 | { | |
121 | return 0; | |
122 | } | |
bea3348e SH |
123 | static inline int netpoll_receive_skb(struct sk_buff *skb) |
124 | { | |
125 | return 0; | |
126 | } | |
127 | static inline void *netpoll_poll_lock(struct napi_struct *napi) | |
128 | { | |
129 | return NULL; | |
130 | } | |
131 | static inline void netpoll_poll_unlock(void *have) | |
132 | { | |
133 | } | |
134 | static inline void netpoll_netdev_init(struct net_device *dev) | |
135 | { | |
136 | } | |
1da177e4 LT |
137 | #endif |
138 | ||
139 | #endif |