Commit bf26414510103448ad3dc069c7422462f03ea3d7
Committed by
David S. Miller
1 parent
8fa9208e30
Exists in
master
and in
7 other branches
xps: Add CONFIG_XPS
This patch adds XPS_CONFIG option to enable and disable XPS. This is done in the same manner as RPS_CONFIG. This is also fixes build failure in XPS code when SMP is not enabled. Signed-off-by: Tom Herbert <therbert@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 5 changed files with 73 additions and 43 deletions Inline Diff
include/linux/netdevice.h
1 | /* | 1 | /* |
2 | * INET An implementation of the TCP/IP protocol suite for the LINUX | 2 | * INET An implementation of the TCP/IP protocol suite for the LINUX |
3 | * operating system. INET is implemented using the BSD Socket | 3 | * operating system. INET is implemented using the BSD Socket |
4 | * interface as the means of communication with the user level. | 4 | * interface as the means of communication with the user level. |
5 | * | 5 | * |
6 | * Definitions for the Interfaces handler. | 6 | * Definitions for the Interfaces handler. |
7 | * | 7 | * |
8 | * Version: @(#)dev.h 1.0.10 08/12/93 | 8 | * Version: @(#)dev.h 1.0.10 08/12/93 |
9 | * | 9 | * |
10 | * Authors: Ross Biro | 10 | * Authors: Ross Biro |
11 | * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> | 11 | * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> |
12 | * Corey Minyard <wf-rch!minyard@relay.EU.net> | 12 | * Corey Minyard <wf-rch!minyard@relay.EU.net> |
13 | * Donald J. Becker, <becker@cesdis.gsfc.nasa.gov> | 13 | * Donald J. Becker, <becker@cesdis.gsfc.nasa.gov> |
14 | * Alan Cox, <alan@lxorguk.ukuu.org.uk> | 14 | * Alan Cox, <alan@lxorguk.ukuu.org.uk> |
15 | * Bjorn Ekwall. <bj0rn@blox.se> | 15 | * Bjorn Ekwall. <bj0rn@blox.se> |
16 | * Pekka Riikonen <priikone@poseidon.pspt.fi> | 16 | * Pekka Riikonen <priikone@poseidon.pspt.fi> |
17 | * | 17 | * |
18 | * This program is free software; you can redistribute it and/or | 18 | * This program is free software; you can redistribute it and/or |
19 | * modify it under the terms of the GNU General Public License | 19 | * modify it under the terms of the GNU General Public License |
20 | * as published by the Free Software Foundation; either version | 20 | * as published by the Free Software Foundation; either version |
21 | * 2 of the License, or (at your option) any later version. | 21 | * 2 of the License, or (at your option) any later version. |
22 | * | 22 | * |
23 | * Moved to /usr/include/linux for NET3 | 23 | * Moved to /usr/include/linux for NET3 |
24 | */ | 24 | */ |
25 | #ifndef _LINUX_NETDEVICE_H | 25 | #ifndef _LINUX_NETDEVICE_H |
26 | #define _LINUX_NETDEVICE_H | 26 | #define _LINUX_NETDEVICE_H |
27 | 27 | ||
28 | #include <linux/if.h> | 28 | #include <linux/if.h> |
29 | #include <linux/if_ether.h> | 29 | #include <linux/if_ether.h> |
30 | #include <linux/if_packet.h> | 30 | #include <linux/if_packet.h> |
31 | #include <linux/if_link.h> | 31 | #include <linux/if_link.h> |
32 | 32 | ||
33 | #ifdef __KERNEL__ | 33 | #ifdef __KERNEL__ |
34 | #include <linux/pm_qos_params.h> | 34 | #include <linux/pm_qos_params.h> |
35 | #include <linux/timer.h> | 35 | #include <linux/timer.h> |
36 | #include <linux/delay.h> | 36 | #include <linux/delay.h> |
37 | #include <linux/mm.h> | 37 | #include <linux/mm.h> |
38 | #include <asm/atomic.h> | 38 | #include <asm/atomic.h> |
39 | #include <asm/cache.h> | 39 | #include <asm/cache.h> |
40 | #include <asm/byteorder.h> | 40 | #include <asm/byteorder.h> |
41 | 41 | ||
42 | #include <linux/device.h> | 42 | #include <linux/device.h> |
43 | #include <linux/percpu.h> | 43 | #include <linux/percpu.h> |
44 | #include <linux/rculist.h> | 44 | #include <linux/rculist.h> |
45 | #include <linux/dmaengine.h> | 45 | #include <linux/dmaengine.h> |
46 | #include <linux/workqueue.h> | 46 | #include <linux/workqueue.h> |
47 | 47 | ||
48 | #include <linux/ethtool.h> | 48 | #include <linux/ethtool.h> |
49 | #include <net/net_namespace.h> | 49 | #include <net/net_namespace.h> |
50 | #include <net/dsa.h> | 50 | #include <net/dsa.h> |
51 | #ifdef CONFIG_DCB | 51 | #ifdef CONFIG_DCB |
52 | #include <net/dcbnl.h> | 52 | #include <net/dcbnl.h> |
53 | #endif | 53 | #endif |
54 | 54 | ||
55 | struct vlan_group; | 55 | struct vlan_group; |
56 | struct netpoll_info; | 56 | struct netpoll_info; |
57 | struct phy_device; | 57 | struct phy_device; |
58 | /* 802.11 specific */ | 58 | /* 802.11 specific */ |
59 | struct wireless_dev; | 59 | struct wireless_dev; |
60 | /* source back-compat hooks */ | 60 | /* source back-compat hooks */ |
61 | #define SET_ETHTOOL_OPS(netdev,ops) \ | 61 | #define SET_ETHTOOL_OPS(netdev,ops) \ |
62 | ( (netdev)->ethtool_ops = (ops) ) | 62 | ( (netdev)->ethtool_ops = (ops) ) |
63 | 63 | ||
64 | #define HAVE_ALLOC_NETDEV /* feature macro: alloc_xxxdev | 64 | #define HAVE_ALLOC_NETDEV /* feature macro: alloc_xxxdev |
65 | functions are available. */ | 65 | functions are available. */ |
66 | #define HAVE_FREE_NETDEV /* free_netdev() */ | 66 | #define HAVE_FREE_NETDEV /* free_netdev() */ |
67 | #define HAVE_NETDEV_PRIV /* netdev_priv() */ | 67 | #define HAVE_NETDEV_PRIV /* netdev_priv() */ |
68 | 68 | ||
69 | /* hardware address assignment types */ | 69 | /* hardware address assignment types */ |
70 | #define NET_ADDR_PERM 0 /* address is permanent (default) */ | 70 | #define NET_ADDR_PERM 0 /* address is permanent (default) */ |
71 | #define NET_ADDR_RANDOM 1 /* address is generated randomly */ | 71 | #define NET_ADDR_RANDOM 1 /* address is generated randomly */ |
72 | #define NET_ADDR_STOLEN 2 /* address is stolen from other device */ | 72 | #define NET_ADDR_STOLEN 2 /* address is stolen from other device */ |
73 | 73 | ||
74 | /* Backlog congestion levels */ | 74 | /* Backlog congestion levels */ |
75 | #define NET_RX_SUCCESS 0 /* keep 'em coming, baby */ | 75 | #define NET_RX_SUCCESS 0 /* keep 'em coming, baby */ |
76 | #define NET_RX_DROP 1 /* packet dropped */ | 76 | #define NET_RX_DROP 1 /* packet dropped */ |
77 | 77 | ||
78 | /* | 78 | /* |
79 | * Transmit return codes: transmit return codes originate from three different | 79 | * Transmit return codes: transmit return codes originate from three different |
80 | * namespaces: | 80 | * namespaces: |
81 | * | 81 | * |
82 | * - qdisc return codes | 82 | * - qdisc return codes |
83 | * - driver transmit return codes | 83 | * - driver transmit return codes |
84 | * - errno values | 84 | * - errno values |
85 | * | 85 | * |
86 | * Drivers are allowed to return any one of those in their hard_start_xmit() | 86 | * Drivers are allowed to return any one of those in their hard_start_xmit() |
87 | * function. Real network devices commonly used with qdiscs should only return | 87 | * function. Real network devices commonly used with qdiscs should only return |
88 | * the driver transmit return codes though - when qdiscs are used, the actual | 88 | * the driver transmit return codes though - when qdiscs are used, the actual |
89 | * transmission happens asynchronously, so the value is not propagated to | 89 | * transmission happens asynchronously, so the value is not propagated to |
90 | * higher layers. Virtual network devices transmit synchronously, in this case | 90 | * higher layers. Virtual network devices transmit synchronously, in this case |
91 | * the driver transmit return codes are consumed by dev_queue_xmit(), all | 91 | * the driver transmit return codes are consumed by dev_queue_xmit(), all |
92 | * others are propagated to higher layers. | 92 | * others are propagated to higher layers. |
93 | */ | 93 | */ |
94 | 94 | ||
95 | /* qdisc ->enqueue() return codes. */ | 95 | /* qdisc ->enqueue() return codes. */ |
96 | #define NET_XMIT_SUCCESS 0x00 | 96 | #define NET_XMIT_SUCCESS 0x00 |
97 | #define NET_XMIT_DROP 0x01 /* skb dropped */ | 97 | #define NET_XMIT_DROP 0x01 /* skb dropped */ |
98 | #define NET_XMIT_CN 0x02 /* congestion notification */ | 98 | #define NET_XMIT_CN 0x02 /* congestion notification */ |
99 | #define NET_XMIT_POLICED 0x03 /* skb is shot by police */ | 99 | #define NET_XMIT_POLICED 0x03 /* skb is shot by police */ |
100 | #define NET_XMIT_MASK 0x0f /* qdisc flags in net/sch_generic.h */ | 100 | #define NET_XMIT_MASK 0x0f /* qdisc flags in net/sch_generic.h */ |
101 | 101 | ||
102 | /* NET_XMIT_CN is special. It does not guarantee that this packet is lost. It | 102 | /* NET_XMIT_CN is special. It does not guarantee that this packet is lost. It |
103 | * indicates that the device will soon be dropping packets, or already drops | 103 | * indicates that the device will soon be dropping packets, or already drops |
104 | * some packets of the same priority; prompting us to send less aggressively. */ | 104 | * some packets of the same priority; prompting us to send less aggressively. */ |
105 | #define net_xmit_eval(e) ((e) == NET_XMIT_CN ? 0 : (e)) | 105 | #define net_xmit_eval(e) ((e) == NET_XMIT_CN ? 0 : (e)) |
106 | #define net_xmit_errno(e) ((e) != NET_XMIT_CN ? -ENOBUFS : 0) | 106 | #define net_xmit_errno(e) ((e) != NET_XMIT_CN ? -ENOBUFS : 0) |
107 | 107 | ||
108 | /* Driver transmit return codes */ | 108 | /* Driver transmit return codes */ |
109 | #define NETDEV_TX_MASK 0xf0 | 109 | #define NETDEV_TX_MASK 0xf0 |
110 | 110 | ||
111 | enum netdev_tx { | 111 | enum netdev_tx { |
112 | __NETDEV_TX_MIN = INT_MIN, /* make sure enum is signed */ | 112 | __NETDEV_TX_MIN = INT_MIN, /* make sure enum is signed */ |
113 | NETDEV_TX_OK = 0x00, /* driver took care of packet */ | 113 | NETDEV_TX_OK = 0x00, /* driver took care of packet */ |
114 | NETDEV_TX_BUSY = 0x10, /* driver tx path was busy*/ | 114 | NETDEV_TX_BUSY = 0x10, /* driver tx path was busy*/ |
115 | NETDEV_TX_LOCKED = 0x20, /* driver tx lock was already taken */ | 115 | NETDEV_TX_LOCKED = 0x20, /* driver tx lock was already taken */ |
116 | }; | 116 | }; |
117 | typedef enum netdev_tx netdev_tx_t; | 117 | typedef enum netdev_tx netdev_tx_t; |
118 | 118 | ||
119 | /* | 119 | /* |
120 | * Current order: NETDEV_TX_MASK > NET_XMIT_MASK >= 0 is significant; | 120 | * Current order: NETDEV_TX_MASK > NET_XMIT_MASK >= 0 is significant; |
121 | * hard_start_xmit() return < NET_XMIT_MASK means skb was consumed. | 121 | * hard_start_xmit() return < NET_XMIT_MASK means skb was consumed. |
122 | */ | 122 | */ |
123 | static inline bool dev_xmit_complete(int rc) | 123 | static inline bool dev_xmit_complete(int rc) |
124 | { | 124 | { |
125 | /* | 125 | /* |
126 | * Positive cases with an skb consumed by a driver: | 126 | * Positive cases with an skb consumed by a driver: |
127 | * - successful transmission (rc == NETDEV_TX_OK) | 127 | * - successful transmission (rc == NETDEV_TX_OK) |
128 | * - error while transmitting (rc < 0) | 128 | * - error while transmitting (rc < 0) |
129 | * - error while queueing to a different device (rc & NET_XMIT_MASK) | 129 | * - error while queueing to a different device (rc & NET_XMIT_MASK) |
130 | */ | 130 | */ |
131 | if (likely(rc < NET_XMIT_MASK)) | 131 | if (likely(rc < NET_XMIT_MASK)) |
132 | return true; | 132 | return true; |
133 | 133 | ||
134 | return false; | 134 | return false; |
135 | } | 135 | } |
136 | 136 | ||
137 | #endif | 137 | #endif |
138 | 138 | ||
139 | #define MAX_ADDR_LEN 32 /* Largest hardware address length */ | 139 | #define MAX_ADDR_LEN 32 /* Largest hardware address length */ |
140 | 140 | ||
141 | #ifdef __KERNEL__ | 141 | #ifdef __KERNEL__ |
142 | /* | 142 | /* |
143 | * Compute the worst case header length according to the protocols | 143 | * Compute the worst case header length according to the protocols |
144 | * used. | 144 | * used. |
145 | */ | 145 | */ |
146 | 146 | ||
147 | #if defined(CONFIG_WLAN) || defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE) | 147 | #if defined(CONFIG_WLAN) || defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE) |
148 | # if defined(CONFIG_MAC80211_MESH) | 148 | # if defined(CONFIG_MAC80211_MESH) |
149 | # define LL_MAX_HEADER 128 | 149 | # define LL_MAX_HEADER 128 |
150 | # else | 150 | # else |
151 | # define LL_MAX_HEADER 96 | 151 | # define LL_MAX_HEADER 96 |
152 | # endif | 152 | # endif |
153 | #elif defined(CONFIG_TR) || defined(CONFIG_TR_MODULE) | 153 | #elif defined(CONFIG_TR) || defined(CONFIG_TR_MODULE) |
154 | # define LL_MAX_HEADER 48 | 154 | # define LL_MAX_HEADER 48 |
155 | #else | 155 | #else |
156 | # define LL_MAX_HEADER 32 | 156 | # define LL_MAX_HEADER 32 |
157 | #endif | 157 | #endif |
158 | 158 | ||
159 | #if !defined(CONFIG_NET_IPIP) && !defined(CONFIG_NET_IPIP_MODULE) && \ | 159 | #if !defined(CONFIG_NET_IPIP) && !defined(CONFIG_NET_IPIP_MODULE) && \ |
160 | !defined(CONFIG_NET_IPGRE) && !defined(CONFIG_NET_IPGRE_MODULE) && \ | 160 | !defined(CONFIG_NET_IPGRE) && !defined(CONFIG_NET_IPGRE_MODULE) && \ |
161 | !defined(CONFIG_IPV6_SIT) && !defined(CONFIG_IPV6_SIT_MODULE) && \ | 161 | !defined(CONFIG_IPV6_SIT) && !defined(CONFIG_IPV6_SIT_MODULE) && \ |
162 | !defined(CONFIG_IPV6_TUNNEL) && !defined(CONFIG_IPV6_TUNNEL_MODULE) | 162 | !defined(CONFIG_IPV6_TUNNEL) && !defined(CONFIG_IPV6_TUNNEL_MODULE) |
163 | #define MAX_HEADER LL_MAX_HEADER | 163 | #define MAX_HEADER LL_MAX_HEADER |
164 | #else | 164 | #else |
165 | #define MAX_HEADER (LL_MAX_HEADER + 48) | 165 | #define MAX_HEADER (LL_MAX_HEADER + 48) |
166 | #endif | 166 | #endif |
167 | 167 | ||
168 | /* | 168 | /* |
169 | * Old network device statistics. Fields are native words | 169 | * Old network device statistics. Fields are native words |
170 | * (unsigned long) so they can be read and written atomically. | 170 | * (unsigned long) so they can be read and written atomically. |
171 | */ | 171 | */ |
172 | 172 | ||
173 | struct net_device_stats { | 173 | struct net_device_stats { |
174 | unsigned long rx_packets; | 174 | unsigned long rx_packets; |
175 | unsigned long tx_packets; | 175 | unsigned long tx_packets; |
176 | unsigned long rx_bytes; | 176 | unsigned long rx_bytes; |
177 | unsigned long tx_bytes; | 177 | unsigned long tx_bytes; |
178 | unsigned long rx_errors; | 178 | unsigned long rx_errors; |
179 | unsigned long tx_errors; | 179 | unsigned long tx_errors; |
180 | unsigned long rx_dropped; | 180 | unsigned long rx_dropped; |
181 | unsigned long tx_dropped; | 181 | unsigned long tx_dropped; |
182 | unsigned long multicast; | 182 | unsigned long multicast; |
183 | unsigned long collisions; | 183 | unsigned long collisions; |
184 | unsigned long rx_length_errors; | 184 | unsigned long rx_length_errors; |
185 | unsigned long rx_over_errors; | 185 | unsigned long rx_over_errors; |
186 | unsigned long rx_crc_errors; | 186 | unsigned long rx_crc_errors; |
187 | unsigned long rx_frame_errors; | 187 | unsigned long rx_frame_errors; |
188 | unsigned long rx_fifo_errors; | 188 | unsigned long rx_fifo_errors; |
189 | unsigned long rx_missed_errors; | 189 | unsigned long rx_missed_errors; |
190 | unsigned long tx_aborted_errors; | 190 | unsigned long tx_aborted_errors; |
191 | unsigned long tx_carrier_errors; | 191 | unsigned long tx_carrier_errors; |
192 | unsigned long tx_fifo_errors; | 192 | unsigned long tx_fifo_errors; |
193 | unsigned long tx_heartbeat_errors; | 193 | unsigned long tx_heartbeat_errors; |
194 | unsigned long tx_window_errors; | 194 | unsigned long tx_window_errors; |
195 | unsigned long rx_compressed; | 195 | unsigned long rx_compressed; |
196 | unsigned long tx_compressed; | 196 | unsigned long tx_compressed; |
197 | }; | 197 | }; |
198 | 198 | ||
199 | #endif /* __KERNEL__ */ | 199 | #endif /* __KERNEL__ */ |
200 | 200 | ||
201 | 201 | ||
202 | /* Media selection options. */ | 202 | /* Media selection options. */ |
203 | enum { | 203 | enum { |
204 | IF_PORT_UNKNOWN = 0, | 204 | IF_PORT_UNKNOWN = 0, |
205 | IF_PORT_10BASE2, | 205 | IF_PORT_10BASE2, |
206 | IF_PORT_10BASET, | 206 | IF_PORT_10BASET, |
207 | IF_PORT_AUI, | 207 | IF_PORT_AUI, |
208 | IF_PORT_100BASET, | 208 | IF_PORT_100BASET, |
209 | IF_PORT_100BASETX, | 209 | IF_PORT_100BASETX, |
210 | IF_PORT_100BASEFX | 210 | IF_PORT_100BASEFX |
211 | }; | 211 | }; |
212 | 212 | ||
213 | #ifdef __KERNEL__ | 213 | #ifdef __KERNEL__ |
214 | 214 | ||
215 | #include <linux/cache.h> | 215 | #include <linux/cache.h> |
216 | #include <linux/skbuff.h> | 216 | #include <linux/skbuff.h> |
217 | 217 | ||
218 | struct neighbour; | 218 | struct neighbour; |
219 | struct neigh_parms; | 219 | struct neigh_parms; |
220 | struct sk_buff; | 220 | struct sk_buff; |
221 | 221 | ||
222 | struct netdev_hw_addr { | 222 | struct netdev_hw_addr { |
223 | struct list_head list; | 223 | struct list_head list; |
224 | unsigned char addr[MAX_ADDR_LEN]; | 224 | unsigned char addr[MAX_ADDR_LEN]; |
225 | unsigned char type; | 225 | unsigned char type; |
226 | #define NETDEV_HW_ADDR_T_LAN 1 | 226 | #define NETDEV_HW_ADDR_T_LAN 1 |
227 | #define NETDEV_HW_ADDR_T_SAN 2 | 227 | #define NETDEV_HW_ADDR_T_SAN 2 |
228 | #define NETDEV_HW_ADDR_T_SLAVE 3 | 228 | #define NETDEV_HW_ADDR_T_SLAVE 3 |
229 | #define NETDEV_HW_ADDR_T_UNICAST 4 | 229 | #define NETDEV_HW_ADDR_T_UNICAST 4 |
230 | #define NETDEV_HW_ADDR_T_MULTICAST 5 | 230 | #define NETDEV_HW_ADDR_T_MULTICAST 5 |
231 | bool synced; | 231 | bool synced; |
232 | bool global_use; | 232 | bool global_use; |
233 | int refcount; | 233 | int refcount; |
234 | struct rcu_head rcu_head; | 234 | struct rcu_head rcu_head; |
235 | }; | 235 | }; |
236 | 236 | ||
237 | struct netdev_hw_addr_list { | 237 | struct netdev_hw_addr_list { |
238 | struct list_head list; | 238 | struct list_head list; |
239 | int count; | 239 | int count; |
240 | }; | 240 | }; |
241 | 241 | ||
242 | #define netdev_hw_addr_list_count(l) ((l)->count) | 242 | #define netdev_hw_addr_list_count(l) ((l)->count) |
243 | #define netdev_hw_addr_list_empty(l) (netdev_hw_addr_list_count(l) == 0) | 243 | #define netdev_hw_addr_list_empty(l) (netdev_hw_addr_list_count(l) == 0) |
244 | #define netdev_hw_addr_list_for_each(ha, l) \ | 244 | #define netdev_hw_addr_list_for_each(ha, l) \ |
245 | list_for_each_entry(ha, &(l)->list, list) | 245 | list_for_each_entry(ha, &(l)->list, list) |
246 | 246 | ||
247 | #define netdev_uc_count(dev) netdev_hw_addr_list_count(&(dev)->uc) | 247 | #define netdev_uc_count(dev) netdev_hw_addr_list_count(&(dev)->uc) |
248 | #define netdev_uc_empty(dev) netdev_hw_addr_list_empty(&(dev)->uc) | 248 | #define netdev_uc_empty(dev) netdev_hw_addr_list_empty(&(dev)->uc) |
249 | #define netdev_for_each_uc_addr(ha, dev) \ | 249 | #define netdev_for_each_uc_addr(ha, dev) \ |
250 | netdev_hw_addr_list_for_each(ha, &(dev)->uc) | 250 | netdev_hw_addr_list_for_each(ha, &(dev)->uc) |
251 | 251 | ||
252 | #define netdev_mc_count(dev) netdev_hw_addr_list_count(&(dev)->mc) | 252 | #define netdev_mc_count(dev) netdev_hw_addr_list_count(&(dev)->mc) |
253 | #define netdev_mc_empty(dev) netdev_hw_addr_list_empty(&(dev)->mc) | 253 | #define netdev_mc_empty(dev) netdev_hw_addr_list_empty(&(dev)->mc) |
254 | #define netdev_for_each_mc_addr(ha, dev) \ | 254 | #define netdev_for_each_mc_addr(ha, dev) \ |
255 | netdev_hw_addr_list_for_each(ha, &(dev)->mc) | 255 | netdev_hw_addr_list_for_each(ha, &(dev)->mc) |
256 | 256 | ||
257 | struct hh_cache { | 257 | struct hh_cache { |
258 | struct hh_cache *hh_next; /* Next entry */ | 258 | struct hh_cache *hh_next; /* Next entry */ |
259 | atomic_t hh_refcnt; /* number of users */ | 259 | atomic_t hh_refcnt; /* number of users */ |
260 | /* | 260 | /* |
261 | * We want hh_output, hh_len, hh_lock and hh_data be a in a separate | 261 | * We want hh_output, hh_len, hh_lock and hh_data be a in a separate |
262 | * cache line on SMP. | 262 | * cache line on SMP. |
263 | * They are mostly read, but hh_refcnt may be changed quite frequently, | 263 | * They are mostly read, but hh_refcnt may be changed quite frequently, |
264 | * incurring cache line ping pongs. | 264 | * incurring cache line ping pongs. |
265 | */ | 265 | */ |
266 | __be16 hh_type ____cacheline_aligned_in_smp; | 266 | __be16 hh_type ____cacheline_aligned_in_smp; |
267 | /* protocol identifier, f.e ETH_P_IP | 267 | /* protocol identifier, f.e ETH_P_IP |
268 | * NOTE: For VLANs, this will be the | 268 | * NOTE: For VLANs, this will be the |
269 | * encapuslated type. --BLG | 269 | * encapuslated type. --BLG |
270 | */ | 270 | */ |
271 | u16 hh_len; /* length of header */ | 271 | u16 hh_len; /* length of header */ |
272 | int (*hh_output)(struct sk_buff *skb); | 272 | int (*hh_output)(struct sk_buff *skb); |
273 | seqlock_t hh_lock; | 273 | seqlock_t hh_lock; |
274 | 274 | ||
275 | /* cached hardware header; allow for machine alignment needs. */ | 275 | /* cached hardware header; allow for machine alignment needs. */ |
276 | #define HH_DATA_MOD 16 | 276 | #define HH_DATA_MOD 16 |
277 | #define HH_DATA_OFF(__len) \ | 277 | #define HH_DATA_OFF(__len) \ |
278 | (HH_DATA_MOD - (((__len - 1) & (HH_DATA_MOD - 1)) + 1)) | 278 | (HH_DATA_MOD - (((__len - 1) & (HH_DATA_MOD - 1)) + 1)) |
279 | #define HH_DATA_ALIGN(__len) \ | 279 | #define HH_DATA_ALIGN(__len) \ |
280 | (((__len)+(HH_DATA_MOD-1))&~(HH_DATA_MOD - 1)) | 280 | (((__len)+(HH_DATA_MOD-1))&~(HH_DATA_MOD - 1)) |
281 | unsigned long hh_data[HH_DATA_ALIGN(LL_MAX_HEADER) / sizeof(long)]; | 281 | unsigned long hh_data[HH_DATA_ALIGN(LL_MAX_HEADER) / sizeof(long)]; |
282 | }; | 282 | }; |
283 | 283 | ||
284 | static inline void hh_cache_put(struct hh_cache *hh) | 284 | static inline void hh_cache_put(struct hh_cache *hh) |
285 | { | 285 | { |
286 | if (atomic_dec_and_test(&hh->hh_refcnt)) | 286 | if (atomic_dec_and_test(&hh->hh_refcnt)) |
287 | kfree(hh); | 287 | kfree(hh); |
288 | } | 288 | } |
289 | 289 | ||
290 | /* Reserve HH_DATA_MOD byte aligned hard_header_len, but at least that much. | 290 | /* Reserve HH_DATA_MOD byte aligned hard_header_len, but at least that much. |
291 | * Alternative is: | 291 | * Alternative is: |
292 | * dev->hard_header_len ? (dev->hard_header_len + | 292 | * dev->hard_header_len ? (dev->hard_header_len + |
293 | * (HH_DATA_MOD - 1)) & ~(HH_DATA_MOD - 1) : 0 | 293 | * (HH_DATA_MOD - 1)) & ~(HH_DATA_MOD - 1) : 0 |
294 | * | 294 | * |
295 | * We could use other alignment values, but we must maintain the | 295 | * We could use other alignment values, but we must maintain the |
296 | * relationship HH alignment <= LL alignment. | 296 | * relationship HH alignment <= LL alignment. |
297 | * | 297 | * |
298 | * LL_ALLOCATED_SPACE also takes into account the tailroom the device | 298 | * LL_ALLOCATED_SPACE also takes into account the tailroom the device |
299 | * may need. | 299 | * may need. |
300 | */ | 300 | */ |
301 | #define LL_RESERVED_SPACE(dev) \ | 301 | #define LL_RESERVED_SPACE(dev) \ |
302 | ((((dev)->hard_header_len+(dev)->needed_headroom)&~(HH_DATA_MOD - 1)) + HH_DATA_MOD) | 302 | ((((dev)->hard_header_len+(dev)->needed_headroom)&~(HH_DATA_MOD - 1)) + HH_DATA_MOD) |
303 | #define LL_RESERVED_SPACE_EXTRA(dev,extra) \ | 303 | #define LL_RESERVED_SPACE_EXTRA(dev,extra) \ |
304 | ((((dev)->hard_header_len+(dev)->needed_headroom+(extra))&~(HH_DATA_MOD - 1)) + HH_DATA_MOD) | 304 | ((((dev)->hard_header_len+(dev)->needed_headroom+(extra))&~(HH_DATA_MOD - 1)) + HH_DATA_MOD) |
305 | #define LL_ALLOCATED_SPACE(dev) \ | 305 | #define LL_ALLOCATED_SPACE(dev) \ |
306 | ((((dev)->hard_header_len+(dev)->needed_headroom+(dev)->needed_tailroom)&~(HH_DATA_MOD - 1)) + HH_DATA_MOD) | 306 | ((((dev)->hard_header_len+(dev)->needed_headroom+(dev)->needed_tailroom)&~(HH_DATA_MOD - 1)) + HH_DATA_MOD) |
307 | 307 | ||
308 | struct header_ops { | 308 | struct header_ops { |
309 | int (*create) (struct sk_buff *skb, struct net_device *dev, | 309 | int (*create) (struct sk_buff *skb, struct net_device *dev, |
310 | unsigned short type, const void *daddr, | 310 | unsigned short type, const void *daddr, |
311 | const void *saddr, unsigned len); | 311 | const void *saddr, unsigned len); |
312 | int (*parse)(const struct sk_buff *skb, unsigned char *haddr); | 312 | int (*parse)(const struct sk_buff *skb, unsigned char *haddr); |
313 | int (*rebuild)(struct sk_buff *skb); | 313 | int (*rebuild)(struct sk_buff *skb); |
314 | #define HAVE_HEADER_CACHE | 314 | #define HAVE_HEADER_CACHE |
315 | int (*cache)(const struct neighbour *neigh, struct hh_cache *hh); | 315 | int (*cache)(const struct neighbour *neigh, struct hh_cache *hh); |
316 | void (*cache_update)(struct hh_cache *hh, | 316 | void (*cache_update)(struct hh_cache *hh, |
317 | const struct net_device *dev, | 317 | const struct net_device *dev, |
318 | const unsigned char *haddr); | 318 | const unsigned char *haddr); |
319 | }; | 319 | }; |
320 | 320 | ||
321 | /* These flag bits are private to the generic network queueing | 321 | /* These flag bits are private to the generic network queueing |
322 | * layer, they may not be explicitly referenced by any other | 322 | * layer, they may not be explicitly referenced by any other |
323 | * code. | 323 | * code. |
324 | */ | 324 | */ |
325 | 325 | ||
326 | enum netdev_state_t { | 326 | enum netdev_state_t { |
327 | __LINK_STATE_START, | 327 | __LINK_STATE_START, |
328 | __LINK_STATE_PRESENT, | 328 | __LINK_STATE_PRESENT, |
329 | __LINK_STATE_NOCARRIER, | 329 | __LINK_STATE_NOCARRIER, |
330 | __LINK_STATE_LINKWATCH_PENDING, | 330 | __LINK_STATE_LINKWATCH_PENDING, |
331 | __LINK_STATE_DORMANT, | 331 | __LINK_STATE_DORMANT, |
332 | }; | 332 | }; |
333 | 333 | ||
334 | 334 | ||
335 | /* | 335 | /* |
336 | * This structure holds at boot time configured netdevice settings. They | 336 | * This structure holds at boot time configured netdevice settings. They |
337 | * are then used in the device probing. | 337 | * are then used in the device probing. |
338 | */ | 338 | */ |
339 | struct netdev_boot_setup { | 339 | struct netdev_boot_setup { |
340 | char name[IFNAMSIZ]; | 340 | char name[IFNAMSIZ]; |
341 | struct ifmap map; | 341 | struct ifmap map; |
342 | }; | 342 | }; |
343 | #define NETDEV_BOOT_SETUP_MAX 8 | 343 | #define NETDEV_BOOT_SETUP_MAX 8 |
344 | 344 | ||
345 | extern int __init netdev_boot_setup(char *str); | 345 | extern int __init netdev_boot_setup(char *str); |
346 | 346 | ||
347 | /* | 347 | /* |
348 | * Structure for NAPI scheduling similar to tasklet but with weighting | 348 | * Structure for NAPI scheduling similar to tasklet but with weighting |
349 | */ | 349 | */ |
350 | struct napi_struct { | 350 | struct napi_struct { |
351 | /* The poll_list must only be managed by the entity which | 351 | /* The poll_list must only be managed by the entity which |
352 | * changes the state of the NAPI_STATE_SCHED bit. This means | 352 | * changes the state of the NAPI_STATE_SCHED bit. This means |
353 | * whoever atomically sets that bit can add this napi_struct | 353 | * whoever atomically sets that bit can add this napi_struct |
354 | * to the per-cpu poll_list, and whoever clears that bit | 354 | * to the per-cpu poll_list, and whoever clears that bit |
355 | * can remove from the list right before clearing the bit. | 355 | * can remove from the list right before clearing the bit. |
356 | */ | 356 | */ |
357 | struct list_head poll_list; | 357 | struct list_head poll_list; |
358 | 358 | ||
359 | unsigned long state; | 359 | unsigned long state; |
360 | int weight; | 360 | int weight; |
361 | int (*poll)(struct napi_struct *, int); | 361 | int (*poll)(struct napi_struct *, int); |
362 | #ifdef CONFIG_NETPOLL | 362 | #ifdef CONFIG_NETPOLL |
363 | spinlock_t poll_lock; | 363 | spinlock_t poll_lock; |
364 | int poll_owner; | 364 | int poll_owner; |
365 | #endif | 365 | #endif |
366 | 366 | ||
367 | unsigned int gro_count; | 367 | unsigned int gro_count; |
368 | 368 | ||
369 | struct net_device *dev; | 369 | struct net_device *dev; |
370 | struct list_head dev_list; | 370 | struct list_head dev_list; |
371 | struct sk_buff *gro_list; | 371 | struct sk_buff *gro_list; |
372 | struct sk_buff *skb; | 372 | struct sk_buff *skb; |
373 | }; | 373 | }; |
374 | 374 | ||
375 | enum { | 375 | enum { |
376 | NAPI_STATE_SCHED, /* Poll is scheduled */ | 376 | NAPI_STATE_SCHED, /* Poll is scheduled */ |
377 | NAPI_STATE_DISABLE, /* Disable pending */ | 377 | NAPI_STATE_DISABLE, /* Disable pending */ |
378 | NAPI_STATE_NPSVC, /* Netpoll - don't dequeue from poll_list */ | 378 | NAPI_STATE_NPSVC, /* Netpoll - don't dequeue from poll_list */ |
379 | }; | 379 | }; |
380 | 380 | ||
381 | enum gro_result { | 381 | enum gro_result { |
382 | GRO_MERGED, | 382 | GRO_MERGED, |
383 | GRO_MERGED_FREE, | 383 | GRO_MERGED_FREE, |
384 | GRO_HELD, | 384 | GRO_HELD, |
385 | GRO_NORMAL, | 385 | GRO_NORMAL, |
386 | GRO_DROP, | 386 | GRO_DROP, |
387 | }; | 387 | }; |
388 | typedef enum gro_result gro_result_t; | 388 | typedef enum gro_result gro_result_t; |
389 | 389 | ||
390 | typedef struct sk_buff *rx_handler_func_t(struct sk_buff *skb); | 390 | typedef struct sk_buff *rx_handler_func_t(struct sk_buff *skb); |
391 | 391 | ||
392 | extern void __napi_schedule(struct napi_struct *n); | 392 | extern void __napi_schedule(struct napi_struct *n); |
393 | 393 | ||
394 | static inline int napi_disable_pending(struct napi_struct *n) | 394 | static inline int napi_disable_pending(struct napi_struct *n) |
395 | { | 395 | { |
396 | return test_bit(NAPI_STATE_DISABLE, &n->state); | 396 | return test_bit(NAPI_STATE_DISABLE, &n->state); |
397 | } | 397 | } |
398 | 398 | ||
399 | /** | 399 | /** |
400 | * napi_schedule_prep - check if napi can be scheduled | 400 | * napi_schedule_prep - check if napi can be scheduled |
401 | * @n: napi context | 401 | * @n: napi context |
402 | * | 402 | * |
403 | * Test if NAPI routine is already running, and if not mark | 403 | * Test if NAPI routine is already running, and if not mark |
404 | * it as running. This is used as a condition variable | 404 | * it as running. This is used as a condition variable |
405 | * insure only one NAPI poll instance runs. We also make | 405 | * insure only one NAPI poll instance runs. We also make |
406 | * sure there is no pending NAPI disable. | 406 | * sure there is no pending NAPI disable. |
407 | */ | 407 | */ |
408 | static inline int napi_schedule_prep(struct napi_struct *n) | 408 | static inline int napi_schedule_prep(struct napi_struct *n) |
409 | { | 409 | { |
410 | return !napi_disable_pending(n) && | 410 | return !napi_disable_pending(n) && |
411 | !test_and_set_bit(NAPI_STATE_SCHED, &n->state); | 411 | !test_and_set_bit(NAPI_STATE_SCHED, &n->state); |
412 | } | 412 | } |
413 | 413 | ||
414 | /** | 414 | /** |
415 | * napi_schedule - schedule NAPI poll | 415 | * napi_schedule - schedule NAPI poll |
416 | * @n: napi context | 416 | * @n: napi context |
417 | * | 417 | * |
418 | * Schedule NAPI poll routine to be called if it is not already | 418 | * Schedule NAPI poll routine to be called if it is not already |
419 | * running. | 419 | * running. |
420 | */ | 420 | */ |
421 | static inline void napi_schedule(struct napi_struct *n) | 421 | static inline void napi_schedule(struct napi_struct *n) |
422 | { | 422 | { |
423 | if (napi_schedule_prep(n)) | 423 | if (napi_schedule_prep(n)) |
424 | __napi_schedule(n); | 424 | __napi_schedule(n); |
425 | } | 425 | } |
426 | 426 | ||
427 | /* Try to reschedule poll. Called by dev->poll() after napi_complete(). */ | 427 | /* Try to reschedule poll. Called by dev->poll() after napi_complete(). */ |
428 | static inline int napi_reschedule(struct napi_struct *napi) | 428 | static inline int napi_reschedule(struct napi_struct *napi) |
429 | { | 429 | { |
430 | if (napi_schedule_prep(napi)) { | 430 | if (napi_schedule_prep(napi)) { |
431 | __napi_schedule(napi); | 431 | __napi_schedule(napi); |
432 | return 1; | 432 | return 1; |
433 | } | 433 | } |
434 | return 0; | 434 | return 0; |
435 | } | 435 | } |
436 | 436 | ||
437 | /** | 437 | /** |
438 | * napi_complete - NAPI processing complete | 438 | * napi_complete - NAPI processing complete |
439 | * @n: napi context | 439 | * @n: napi context |
440 | * | 440 | * |
441 | * Mark NAPI processing as complete. | 441 | * Mark NAPI processing as complete. |
442 | */ | 442 | */ |
443 | extern void __napi_complete(struct napi_struct *n); | 443 | extern void __napi_complete(struct napi_struct *n); |
444 | extern void napi_complete(struct napi_struct *n); | 444 | extern void napi_complete(struct napi_struct *n); |
445 | 445 | ||
446 | /** | 446 | /** |
447 | * napi_disable - prevent NAPI from scheduling | 447 | * napi_disable - prevent NAPI from scheduling |
448 | * @n: napi context | 448 | * @n: napi context |
449 | * | 449 | * |
450 | * Stop NAPI from being scheduled on this context. | 450 | * Stop NAPI from being scheduled on this context. |
451 | * Waits till any outstanding processing completes. | 451 | * Waits till any outstanding processing completes. |
452 | */ | 452 | */ |
453 | static inline void napi_disable(struct napi_struct *n) | 453 | static inline void napi_disable(struct napi_struct *n) |
454 | { | 454 | { |
455 | set_bit(NAPI_STATE_DISABLE, &n->state); | 455 | set_bit(NAPI_STATE_DISABLE, &n->state); |
456 | while (test_and_set_bit(NAPI_STATE_SCHED, &n->state)) | 456 | while (test_and_set_bit(NAPI_STATE_SCHED, &n->state)) |
457 | msleep(1); | 457 | msleep(1); |
458 | clear_bit(NAPI_STATE_DISABLE, &n->state); | 458 | clear_bit(NAPI_STATE_DISABLE, &n->state); |
459 | } | 459 | } |
460 | 460 | ||
461 | /** | 461 | /** |
462 | * napi_enable - enable NAPI scheduling | 462 | * napi_enable - enable NAPI scheduling |
463 | * @n: napi context | 463 | * @n: napi context |
464 | * | 464 | * |
465 | * Resume NAPI from being scheduled on this context. | 465 | * Resume NAPI from being scheduled on this context. |
466 | * Must be paired with napi_disable. | 466 | * Must be paired with napi_disable. |
467 | */ | 467 | */ |
468 | static inline void napi_enable(struct napi_struct *n) | 468 | static inline void napi_enable(struct napi_struct *n) |
469 | { | 469 | { |
470 | BUG_ON(!test_bit(NAPI_STATE_SCHED, &n->state)); | 470 | BUG_ON(!test_bit(NAPI_STATE_SCHED, &n->state)); |
471 | smp_mb__before_clear_bit(); | 471 | smp_mb__before_clear_bit(); |
472 | clear_bit(NAPI_STATE_SCHED, &n->state); | 472 | clear_bit(NAPI_STATE_SCHED, &n->state); |
473 | } | 473 | } |
474 | 474 | ||
475 | #ifdef CONFIG_SMP | 475 | #ifdef CONFIG_SMP |
476 | /** | 476 | /** |
477 | * napi_synchronize - wait until NAPI is not running | 477 | * napi_synchronize - wait until NAPI is not running |
478 | * @n: napi context | 478 | * @n: napi context |
479 | * | 479 | * |
480 | * Wait until NAPI is done being scheduled on this context. | 480 | * Wait until NAPI is done being scheduled on this context. |
481 | * Waits till any outstanding processing completes but | 481 | * Waits till any outstanding processing completes but |
482 | * does not disable future activations. | 482 | * does not disable future activations. |
483 | */ | 483 | */ |
484 | static inline void napi_synchronize(const struct napi_struct *n) | 484 | static inline void napi_synchronize(const struct napi_struct *n) |
485 | { | 485 | { |
486 | while (test_bit(NAPI_STATE_SCHED, &n->state)) | 486 | while (test_bit(NAPI_STATE_SCHED, &n->state)) |
487 | msleep(1); | 487 | msleep(1); |
488 | } | 488 | } |
489 | #else | 489 | #else |
490 | # define napi_synchronize(n) barrier() | 490 | # define napi_synchronize(n) barrier() |
491 | #endif | 491 | #endif |
492 | 492 | ||
493 | enum netdev_queue_state_t { | 493 | enum netdev_queue_state_t { |
494 | __QUEUE_STATE_XOFF, | 494 | __QUEUE_STATE_XOFF, |
495 | __QUEUE_STATE_FROZEN, | 495 | __QUEUE_STATE_FROZEN, |
496 | #define QUEUE_STATE_XOFF_OR_FROZEN ((1 << __QUEUE_STATE_XOFF) | \ | 496 | #define QUEUE_STATE_XOFF_OR_FROZEN ((1 << __QUEUE_STATE_XOFF) | \ |
497 | (1 << __QUEUE_STATE_FROZEN)) | 497 | (1 << __QUEUE_STATE_FROZEN)) |
498 | }; | 498 | }; |
499 | 499 | ||
500 | struct netdev_queue { | 500 | struct netdev_queue { |
501 | /* | 501 | /* |
502 | * read mostly part | 502 | * read mostly part |
503 | */ | 503 | */ |
504 | struct net_device *dev; | 504 | struct net_device *dev; |
505 | struct Qdisc *qdisc; | 505 | struct Qdisc *qdisc; |
506 | unsigned long state; | 506 | unsigned long state; |
507 | struct Qdisc *qdisc_sleeping; | 507 | struct Qdisc *qdisc_sleeping; |
508 | #ifdef CONFIG_RPS | 508 | #ifdef CONFIG_RPS |
509 | struct kobject kobj; | 509 | struct kobject kobj; |
510 | #endif | 510 | #endif |
511 | 511 | ||
512 | /* | 512 | /* |
513 | * write mostly part | 513 | * write mostly part |
514 | */ | 514 | */ |
515 | spinlock_t _xmit_lock ____cacheline_aligned_in_smp; | 515 | spinlock_t _xmit_lock ____cacheline_aligned_in_smp; |
516 | int xmit_lock_owner; | 516 | int xmit_lock_owner; |
517 | /* | 517 | /* |
518 | * please use this field instead of dev->trans_start | 518 | * please use this field instead of dev->trans_start |
519 | */ | 519 | */ |
520 | unsigned long trans_start; | 520 | unsigned long trans_start; |
521 | u64 tx_bytes; | 521 | u64 tx_bytes; |
522 | u64 tx_packets; | 522 | u64 tx_packets; |
523 | u64 tx_dropped; | 523 | u64 tx_dropped; |
524 | } ____cacheline_aligned_in_smp; | 524 | } ____cacheline_aligned_in_smp; |
525 | 525 | ||
526 | #ifdef CONFIG_RPS | 526 | #ifdef CONFIG_RPS |
527 | /* | 527 | /* |
528 | * This structure holds an RPS map which can be of variable length. The | 528 | * This structure holds an RPS map which can be of variable length. The |
529 | * map is an array of CPUs. | 529 | * map is an array of CPUs. |
530 | */ | 530 | */ |
531 | struct rps_map { | 531 | struct rps_map { |
532 | unsigned int len; | 532 | unsigned int len; |
533 | struct rcu_head rcu; | 533 | struct rcu_head rcu; |
534 | u16 cpus[0]; | 534 | u16 cpus[0]; |
535 | }; | 535 | }; |
536 | #define RPS_MAP_SIZE(_num) (sizeof(struct rps_map) + (_num * sizeof(u16))) | 536 | #define RPS_MAP_SIZE(_num) (sizeof(struct rps_map) + (_num * sizeof(u16))) |
537 | 537 | ||
538 | /* | 538 | /* |
539 | * This structure holds an XPS map which can be of variable length. The | ||
540 | * map is an array of queues. | ||
541 | */ | ||
542 | struct xps_map { | ||
543 | unsigned int len; | ||
544 | unsigned int alloc_len; | ||
545 | struct rcu_head rcu; | ||
546 | u16 queues[0]; | ||
547 | }; | ||
548 | #define XPS_MAP_SIZE(_num) (sizeof(struct xps_map) + (_num * sizeof(u16))) | ||
549 | #define XPS_MIN_MAP_ALLOC ((L1_CACHE_BYTES - sizeof(struct xps_map)) \ | ||
550 | / sizeof(u16)) | ||
551 | |||
552 | /* | ||
553 | * This structure holds all XPS maps for device. Maps are indexed by CPU. | ||
554 | */ | ||
555 | struct xps_dev_maps { | ||
556 | struct rcu_head rcu; | ||
557 | struct xps_map *cpu_map[0]; | ||
558 | }; | ||
559 | #define XPS_DEV_MAPS_SIZE (sizeof(struct xps_dev_maps) + \ | ||
560 | (nr_cpu_ids * sizeof(struct xps_map *))) | ||
561 | |||
562 | /* | ||
563 | * The rps_dev_flow structure contains the mapping of a flow to a CPU and the | 539 | * The rps_dev_flow structure contains the mapping of a flow to a CPU and the |
564 | * tail pointer for that CPU's input queue at the time of last enqueue. | 540 | * tail pointer for that CPU's input queue at the time of last enqueue. |
565 | */ | 541 | */ |
566 | struct rps_dev_flow { | 542 | struct rps_dev_flow { |
567 | u16 cpu; | 543 | u16 cpu; |
568 | u16 fill; | 544 | u16 fill; |
569 | unsigned int last_qtail; | 545 | unsigned int last_qtail; |
570 | }; | 546 | }; |
571 | 547 | ||
572 | /* | 548 | /* |
573 | * The rps_dev_flow_table structure contains a table of flow mappings. | 549 | * The rps_dev_flow_table structure contains a table of flow mappings. |
574 | */ | 550 | */ |
575 | struct rps_dev_flow_table { | 551 | struct rps_dev_flow_table { |
576 | unsigned int mask; | 552 | unsigned int mask; |
577 | struct rcu_head rcu; | 553 | struct rcu_head rcu; |
578 | struct work_struct free_work; | 554 | struct work_struct free_work; |
579 | struct rps_dev_flow flows[0]; | 555 | struct rps_dev_flow flows[0]; |
580 | }; | 556 | }; |
581 | #define RPS_DEV_FLOW_TABLE_SIZE(_num) (sizeof(struct rps_dev_flow_table) + \ | 557 | #define RPS_DEV_FLOW_TABLE_SIZE(_num) (sizeof(struct rps_dev_flow_table) + \ |
582 | (_num * sizeof(struct rps_dev_flow))) | 558 | (_num * sizeof(struct rps_dev_flow))) |
583 | 559 | ||
584 | /* | 560 | /* |
585 | * The rps_sock_flow_table contains mappings of flows to the last CPU | 561 | * The rps_sock_flow_table contains mappings of flows to the last CPU |
586 | * on which they were processed by the application (set in recvmsg). | 562 | * on which they were processed by the application (set in recvmsg). |
587 | */ | 563 | */ |
588 | struct rps_sock_flow_table { | 564 | struct rps_sock_flow_table { |
589 | unsigned int mask; | 565 | unsigned int mask; |
590 | u16 ents[0]; | 566 | u16 ents[0]; |
591 | }; | 567 | }; |
592 | #define RPS_SOCK_FLOW_TABLE_SIZE(_num) (sizeof(struct rps_sock_flow_table) + \ | 568 | #define RPS_SOCK_FLOW_TABLE_SIZE(_num) (sizeof(struct rps_sock_flow_table) + \ |
593 | (_num * sizeof(u16))) | 569 | (_num * sizeof(u16))) |
594 | 570 | ||
595 | #define RPS_NO_CPU 0xffff | 571 | #define RPS_NO_CPU 0xffff |
596 | 572 | ||
597 | static inline void rps_record_sock_flow(struct rps_sock_flow_table *table, | 573 | static inline void rps_record_sock_flow(struct rps_sock_flow_table *table, |
598 | u32 hash) | 574 | u32 hash) |
599 | { | 575 | { |
600 | if (table && hash) { | 576 | if (table && hash) { |
601 | unsigned int cpu, index = hash & table->mask; | 577 | unsigned int cpu, index = hash & table->mask; |
602 | 578 | ||
603 | /* We only give a hint, preemption can change cpu under us */ | 579 | /* We only give a hint, preemption can change cpu under us */ |
604 | cpu = raw_smp_processor_id(); | 580 | cpu = raw_smp_processor_id(); |
605 | 581 | ||
606 | if (table->ents[index] != cpu) | 582 | if (table->ents[index] != cpu) |
607 | table->ents[index] = cpu; | 583 | table->ents[index] = cpu; |
608 | } | 584 | } |
609 | } | 585 | } |
610 | 586 | ||
611 | static inline void rps_reset_sock_flow(struct rps_sock_flow_table *table, | 587 | static inline void rps_reset_sock_flow(struct rps_sock_flow_table *table, |
612 | u32 hash) | 588 | u32 hash) |
613 | { | 589 | { |
614 | if (table && hash) | 590 | if (table && hash) |
615 | table->ents[hash & table->mask] = RPS_NO_CPU; | 591 | table->ents[hash & table->mask] = RPS_NO_CPU; |
616 | } | 592 | } |
617 | 593 | ||
618 | extern struct rps_sock_flow_table __rcu *rps_sock_flow_table; | 594 | extern struct rps_sock_flow_table __rcu *rps_sock_flow_table; |
619 | 595 | ||
620 | /* This structure contains an instance of an RX queue. */ | 596 | /* This structure contains an instance of an RX queue. */ |
621 | struct netdev_rx_queue { | 597 | struct netdev_rx_queue { |
622 | struct rps_map __rcu *rps_map; | 598 | struct rps_map __rcu *rps_map; |
623 | struct rps_dev_flow_table __rcu *rps_flow_table; | 599 | struct rps_dev_flow_table __rcu *rps_flow_table; |
624 | struct kobject kobj; | 600 | struct kobject kobj; |
625 | struct net_device *dev; | 601 | struct net_device *dev; |
626 | } ____cacheline_aligned_in_smp; | 602 | } ____cacheline_aligned_in_smp; |
627 | #endif /* CONFIG_RPS */ | 603 | #endif /* CONFIG_RPS */ |
628 | 604 | ||
605 | #ifdef CONFIG_XPS | ||
629 | /* | 606 | /* |
607 | * This structure holds an XPS map which can be of variable length. The | ||
608 | * map is an array of queues. | ||
609 | */ | ||
610 | struct xps_map { | ||
611 | unsigned int len; | ||
612 | unsigned int alloc_len; | ||
613 | struct rcu_head rcu; | ||
614 | u16 queues[0]; | ||
615 | }; | ||
616 | #define XPS_MAP_SIZE(_num) (sizeof(struct xps_map) + (_num * sizeof(u16))) | ||
617 | #define XPS_MIN_MAP_ALLOC ((L1_CACHE_BYTES - sizeof(struct xps_map)) \ | ||
618 | / sizeof(u16)) | ||
619 | |||
620 | /* | ||
621 | * This structure holds all XPS maps for device. Maps are indexed by CPU. | ||
622 | */ | ||
623 | struct xps_dev_maps { | ||
624 | struct rcu_head rcu; | ||
625 | struct xps_map *cpu_map[0]; | ||
626 | }; | ||
627 | #define XPS_DEV_MAPS_SIZE (sizeof(struct xps_dev_maps) + \ | ||
628 | (nr_cpu_ids * sizeof(struct xps_map *))) | ||
629 | #endif /* CONFIG_XPS */ | ||
630 | |||
631 | /* | ||
630 | * This structure defines the management hooks for network devices. | 632 | * This structure defines the management hooks for network devices. |
631 | * The following hooks can be defined; unless noted otherwise, they are | 633 | * The following hooks can be defined; unless noted otherwise, they are |
632 | * optional and can be filled with a null pointer. | 634 | * optional and can be filled with a null pointer. |
633 | * | 635 | * |
634 | * int (*ndo_init)(struct net_device *dev); | 636 | * int (*ndo_init)(struct net_device *dev); |
635 | * This function is called once when network device is registered. | 637 | * This function is called once when network device is registered. |
636 | * The network device can use this to any late stage initializaton | 638 | * The network device can use this to any late stage initializaton |
637 | * or semantic validattion. It can fail with an error code which will | 639 | * or semantic validattion. It can fail with an error code which will |
638 | * be propogated back to register_netdev | 640 | * be propogated back to register_netdev |
639 | * | 641 | * |
640 | * void (*ndo_uninit)(struct net_device *dev); | 642 | * void (*ndo_uninit)(struct net_device *dev); |
641 | * This function is called when device is unregistered or when registration | 643 | * This function is called when device is unregistered or when registration |
642 | * fails. It is not called if init fails. | 644 | * fails. It is not called if init fails. |
643 | * | 645 | * |
644 | * int (*ndo_open)(struct net_device *dev); | 646 | * int (*ndo_open)(struct net_device *dev); |
645 | * This function is called when network device transistions to the up | 647 | * This function is called when network device transistions to the up |
646 | * state. | 648 | * state. |
647 | * | 649 | * |
648 | * int (*ndo_stop)(struct net_device *dev); | 650 | * int (*ndo_stop)(struct net_device *dev); |
649 | * This function is called when network device transistions to the down | 651 | * This function is called when network device transistions to the down |
650 | * state. | 652 | * state. |
651 | * | 653 | * |
652 | * netdev_tx_t (*ndo_start_xmit)(struct sk_buff *skb, | 654 | * netdev_tx_t (*ndo_start_xmit)(struct sk_buff *skb, |
653 | * struct net_device *dev); | 655 | * struct net_device *dev); |
654 | * Called when a packet needs to be transmitted. | 656 | * Called when a packet needs to be transmitted. |
655 | * Must return NETDEV_TX_OK , NETDEV_TX_BUSY. | 657 | * Must return NETDEV_TX_OK , NETDEV_TX_BUSY. |
656 | * (can also return NETDEV_TX_LOCKED iff NETIF_F_LLTX) | 658 | * (can also return NETDEV_TX_LOCKED iff NETIF_F_LLTX) |
657 | * Required can not be NULL. | 659 | * Required can not be NULL. |
658 | * | 660 | * |
659 | * u16 (*ndo_select_queue)(struct net_device *dev, struct sk_buff *skb); | 661 | * u16 (*ndo_select_queue)(struct net_device *dev, struct sk_buff *skb); |
660 | * Called to decide which queue to when device supports multiple | 662 | * Called to decide which queue to when device supports multiple |
661 | * transmit queues. | 663 | * transmit queues. |
662 | * | 664 | * |
663 | * void (*ndo_change_rx_flags)(struct net_device *dev, int flags); | 665 | * void (*ndo_change_rx_flags)(struct net_device *dev, int flags); |
664 | * This function is called to allow device receiver to make | 666 | * This function is called to allow device receiver to make |
665 | * changes to configuration when multicast or promiscious is enabled. | 667 | * changes to configuration when multicast or promiscious is enabled. |
666 | * | 668 | * |
667 | * void (*ndo_set_rx_mode)(struct net_device *dev); | 669 | * void (*ndo_set_rx_mode)(struct net_device *dev); |
668 | * This function is called device changes address list filtering. | 670 | * This function is called device changes address list filtering. |
669 | * | 671 | * |
670 | * void (*ndo_set_multicast_list)(struct net_device *dev); | 672 | * void (*ndo_set_multicast_list)(struct net_device *dev); |
671 | * This function is called when the multicast address list changes. | 673 | * This function is called when the multicast address list changes. |
672 | * | 674 | * |
673 | * int (*ndo_set_mac_address)(struct net_device *dev, void *addr); | 675 | * int (*ndo_set_mac_address)(struct net_device *dev, void *addr); |
674 | * This function is called when the Media Access Control address | 676 | * This function is called when the Media Access Control address |
675 | * needs to be changed. If this interface is not defined, the | 677 | * needs to be changed. If this interface is not defined, the |
676 | * mac address can not be changed. | 678 | * mac address can not be changed. |
677 | * | 679 | * |
678 | * int (*ndo_validate_addr)(struct net_device *dev); | 680 | * int (*ndo_validate_addr)(struct net_device *dev); |
679 | * Test if Media Access Control address is valid for the device. | 681 | * Test if Media Access Control address is valid for the device. |
680 | * | 682 | * |
681 | * int (*ndo_do_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd); | 683 | * int (*ndo_do_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd); |
682 | * Called when a user request an ioctl which can't be handled by | 684 | * Called when a user request an ioctl which can't be handled by |
683 | * the generic interface code. If not defined ioctl's return | 685 | * the generic interface code. If not defined ioctl's return |
684 | * not supported error code. | 686 | * not supported error code. |
685 | * | 687 | * |
686 | * int (*ndo_set_config)(struct net_device *dev, struct ifmap *map); | 688 | * int (*ndo_set_config)(struct net_device *dev, struct ifmap *map); |
687 | * Used to set network devices bus interface parameters. This interface | 689 | * Used to set network devices bus interface parameters. This interface |
688 | * is retained for legacy reason, new devices should use the bus | 690 | * is retained for legacy reason, new devices should use the bus |
689 | * interface (PCI) for low level management. | 691 | * interface (PCI) for low level management. |
690 | * | 692 | * |
691 | * int (*ndo_change_mtu)(struct net_device *dev, int new_mtu); | 693 | * int (*ndo_change_mtu)(struct net_device *dev, int new_mtu); |
692 | * Called when a user wants to change the Maximum Transfer Unit | 694 | * Called when a user wants to change the Maximum Transfer Unit |
693 | * of a device. If not defined, any request to change MTU will | 695 | * of a device. If not defined, any request to change MTU will |
694 | * will return an error. | 696 | * will return an error. |
695 | * | 697 | * |
696 | * void (*ndo_tx_timeout)(struct net_device *dev); | 698 | * void (*ndo_tx_timeout)(struct net_device *dev); |
697 | * Callback uses when the transmitter has not made any progress | 699 | * Callback uses when the transmitter has not made any progress |
698 | * for dev->watchdog ticks. | 700 | * for dev->watchdog ticks. |
699 | * | 701 | * |
700 | * struct rtnl_link_stats64* (*ndo_get_stats64)(struct net_device *dev, | 702 | * struct rtnl_link_stats64* (*ndo_get_stats64)(struct net_device *dev, |
701 | * struct rtnl_link_stats64 *storage); | 703 | * struct rtnl_link_stats64 *storage); |
702 | * struct net_device_stats* (*ndo_get_stats)(struct net_device *dev); | 704 | * struct net_device_stats* (*ndo_get_stats)(struct net_device *dev); |
703 | * Called when a user wants to get the network device usage | 705 | * Called when a user wants to get the network device usage |
704 | * statistics. Drivers must do one of the following: | 706 | * statistics. Drivers must do one of the following: |
705 | * 1. Define @ndo_get_stats64 to fill in a zero-initialised | 707 | * 1. Define @ndo_get_stats64 to fill in a zero-initialised |
706 | * rtnl_link_stats64 structure passed by the caller. | 708 | * rtnl_link_stats64 structure passed by the caller. |
707 | * 2. Define @ndo_get_stats to update a net_device_stats structure | 709 | * 2. Define @ndo_get_stats to update a net_device_stats structure |
708 | * (which should normally be dev->stats) and return a pointer to | 710 | * (which should normally be dev->stats) and return a pointer to |
709 | * it. The structure may be changed asynchronously only if each | 711 | * it. The structure may be changed asynchronously only if each |
710 | * field is written atomically. | 712 | * field is written atomically. |
711 | * 3. Update dev->stats asynchronously and atomically, and define | 713 | * 3. Update dev->stats asynchronously and atomically, and define |
712 | * neither operation. | 714 | * neither operation. |
713 | * | 715 | * |
714 | * void (*ndo_vlan_rx_register)(struct net_device *dev, struct vlan_group *grp); | 716 | * void (*ndo_vlan_rx_register)(struct net_device *dev, struct vlan_group *grp); |
715 | * If device support VLAN receive accleration | 717 | * If device support VLAN receive accleration |
716 | * (ie. dev->features & NETIF_F_HW_VLAN_RX), then this function is called | 718 | * (ie. dev->features & NETIF_F_HW_VLAN_RX), then this function is called |
717 | * when vlan groups for the device changes. Note: grp is NULL | 719 | * when vlan groups for the device changes. Note: grp is NULL |
718 | * if no vlan's groups are being used. | 720 | * if no vlan's groups are being used. |
719 | * | 721 | * |
720 | * void (*ndo_vlan_rx_add_vid)(struct net_device *dev, unsigned short vid); | 722 | * void (*ndo_vlan_rx_add_vid)(struct net_device *dev, unsigned short vid); |
721 | * If device support VLAN filtering (dev->features & NETIF_F_HW_VLAN_FILTER) | 723 | * If device support VLAN filtering (dev->features & NETIF_F_HW_VLAN_FILTER) |
722 | * this function is called when a VLAN id is registered. | 724 | * this function is called when a VLAN id is registered. |
723 | * | 725 | * |
724 | * void (*ndo_vlan_rx_kill_vid)(struct net_device *dev, unsigned short vid); | 726 | * void (*ndo_vlan_rx_kill_vid)(struct net_device *dev, unsigned short vid); |
725 | * If device support VLAN filtering (dev->features & NETIF_F_HW_VLAN_FILTER) | 727 | * If device support VLAN filtering (dev->features & NETIF_F_HW_VLAN_FILTER) |
726 | * this function is called when a VLAN id is unregistered. | 728 | * this function is called when a VLAN id is unregistered. |
727 | * | 729 | * |
728 | * void (*ndo_poll_controller)(struct net_device *dev); | 730 | * void (*ndo_poll_controller)(struct net_device *dev); |
729 | * | 731 | * |
730 | * SR-IOV management functions. | 732 | * SR-IOV management functions. |
731 | * int (*ndo_set_vf_mac)(struct net_device *dev, int vf, u8* mac); | 733 | * int (*ndo_set_vf_mac)(struct net_device *dev, int vf, u8* mac); |
732 | * int (*ndo_set_vf_vlan)(struct net_device *dev, int vf, u16 vlan, u8 qos); | 734 | * int (*ndo_set_vf_vlan)(struct net_device *dev, int vf, u16 vlan, u8 qos); |
733 | * int (*ndo_set_vf_tx_rate)(struct net_device *dev, int vf, int rate); | 735 | * int (*ndo_set_vf_tx_rate)(struct net_device *dev, int vf, int rate); |
734 | * int (*ndo_get_vf_config)(struct net_device *dev, | 736 | * int (*ndo_get_vf_config)(struct net_device *dev, |
735 | * int vf, struct ifla_vf_info *ivf); | 737 | * int vf, struct ifla_vf_info *ivf); |
736 | * int (*ndo_set_vf_port)(struct net_device *dev, int vf, | 738 | * int (*ndo_set_vf_port)(struct net_device *dev, int vf, |
737 | * struct nlattr *port[]); | 739 | * struct nlattr *port[]); |
738 | * int (*ndo_get_vf_port)(struct net_device *dev, int vf, struct sk_buff *skb); | 740 | * int (*ndo_get_vf_port)(struct net_device *dev, int vf, struct sk_buff *skb); |
739 | */ | 741 | */ |
740 | #define HAVE_NET_DEVICE_OPS | 742 | #define HAVE_NET_DEVICE_OPS |
741 | struct net_device_ops { | 743 | struct net_device_ops { |
742 | int (*ndo_init)(struct net_device *dev); | 744 | int (*ndo_init)(struct net_device *dev); |
743 | void (*ndo_uninit)(struct net_device *dev); | 745 | void (*ndo_uninit)(struct net_device *dev); |
744 | int (*ndo_open)(struct net_device *dev); | 746 | int (*ndo_open)(struct net_device *dev); |
745 | int (*ndo_stop)(struct net_device *dev); | 747 | int (*ndo_stop)(struct net_device *dev); |
746 | netdev_tx_t (*ndo_start_xmit) (struct sk_buff *skb, | 748 | netdev_tx_t (*ndo_start_xmit) (struct sk_buff *skb, |
747 | struct net_device *dev); | 749 | struct net_device *dev); |
748 | u16 (*ndo_select_queue)(struct net_device *dev, | 750 | u16 (*ndo_select_queue)(struct net_device *dev, |
749 | struct sk_buff *skb); | 751 | struct sk_buff *skb); |
750 | void (*ndo_change_rx_flags)(struct net_device *dev, | 752 | void (*ndo_change_rx_flags)(struct net_device *dev, |
751 | int flags); | 753 | int flags); |
752 | void (*ndo_set_rx_mode)(struct net_device *dev); | 754 | void (*ndo_set_rx_mode)(struct net_device *dev); |
753 | void (*ndo_set_multicast_list)(struct net_device *dev); | 755 | void (*ndo_set_multicast_list)(struct net_device *dev); |
754 | int (*ndo_set_mac_address)(struct net_device *dev, | 756 | int (*ndo_set_mac_address)(struct net_device *dev, |
755 | void *addr); | 757 | void *addr); |
756 | int (*ndo_validate_addr)(struct net_device *dev); | 758 | int (*ndo_validate_addr)(struct net_device *dev); |
757 | int (*ndo_do_ioctl)(struct net_device *dev, | 759 | int (*ndo_do_ioctl)(struct net_device *dev, |
758 | struct ifreq *ifr, int cmd); | 760 | struct ifreq *ifr, int cmd); |
759 | int (*ndo_set_config)(struct net_device *dev, | 761 | int (*ndo_set_config)(struct net_device *dev, |
760 | struct ifmap *map); | 762 | struct ifmap *map); |
761 | int (*ndo_change_mtu)(struct net_device *dev, | 763 | int (*ndo_change_mtu)(struct net_device *dev, |
762 | int new_mtu); | 764 | int new_mtu); |
763 | int (*ndo_neigh_setup)(struct net_device *dev, | 765 | int (*ndo_neigh_setup)(struct net_device *dev, |
764 | struct neigh_parms *); | 766 | struct neigh_parms *); |
765 | void (*ndo_tx_timeout) (struct net_device *dev); | 767 | void (*ndo_tx_timeout) (struct net_device *dev); |
766 | 768 | ||
767 | struct rtnl_link_stats64* (*ndo_get_stats64)(struct net_device *dev, | 769 | struct rtnl_link_stats64* (*ndo_get_stats64)(struct net_device *dev, |
768 | struct rtnl_link_stats64 *storage); | 770 | struct rtnl_link_stats64 *storage); |
769 | struct net_device_stats* (*ndo_get_stats)(struct net_device *dev); | 771 | struct net_device_stats* (*ndo_get_stats)(struct net_device *dev); |
770 | 772 | ||
771 | void (*ndo_vlan_rx_register)(struct net_device *dev, | 773 | void (*ndo_vlan_rx_register)(struct net_device *dev, |
772 | struct vlan_group *grp); | 774 | struct vlan_group *grp); |
773 | void (*ndo_vlan_rx_add_vid)(struct net_device *dev, | 775 | void (*ndo_vlan_rx_add_vid)(struct net_device *dev, |
774 | unsigned short vid); | 776 | unsigned short vid); |
775 | void (*ndo_vlan_rx_kill_vid)(struct net_device *dev, | 777 | void (*ndo_vlan_rx_kill_vid)(struct net_device *dev, |
776 | unsigned short vid); | 778 | unsigned short vid); |
777 | #ifdef CONFIG_NET_POLL_CONTROLLER | 779 | #ifdef CONFIG_NET_POLL_CONTROLLER |
778 | void (*ndo_poll_controller)(struct net_device *dev); | 780 | void (*ndo_poll_controller)(struct net_device *dev); |
779 | int (*ndo_netpoll_setup)(struct net_device *dev, | 781 | int (*ndo_netpoll_setup)(struct net_device *dev, |
780 | struct netpoll_info *info); | 782 | struct netpoll_info *info); |
781 | void (*ndo_netpoll_cleanup)(struct net_device *dev); | 783 | void (*ndo_netpoll_cleanup)(struct net_device *dev); |
782 | #endif | 784 | #endif |
783 | int (*ndo_set_vf_mac)(struct net_device *dev, | 785 | int (*ndo_set_vf_mac)(struct net_device *dev, |
784 | int queue, u8 *mac); | 786 | int queue, u8 *mac); |
785 | int (*ndo_set_vf_vlan)(struct net_device *dev, | 787 | int (*ndo_set_vf_vlan)(struct net_device *dev, |
786 | int queue, u16 vlan, u8 qos); | 788 | int queue, u16 vlan, u8 qos); |
787 | int (*ndo_set_vf_tx_rate)(struct net_device *dev, | 789 | int (*ndo_set_vf_tx_rate)(struct net_device *dev, |
788 | int vf, int rate); | 790 | int vf, int rate); |
789 | int (*ndo_get_vf_config)(struct net_device *dev, | 791 | int (*ndo_get_vf_config)(struct net_device *dev, |
790 | int vf, | 792 | int vf, |
791 | struct ifla_vf_info *ivf); | 793 | struct ifla_vf_info *ivf); |
792 | int (*ndo_set_vf_port)(struct net_device *dev, | 794 | int (*ndo_set_vf_port)(struct net_device *dev, |
793 | int vf, | 795 | int vf, |
794 | struct nlattr *port[]); | 796 | struct nlattr *port[]); |
795 | int (*ndo_get_vf_port)(struct net_device *dev, | 797 | int (*ndo_get_vf_port)(struct net_device *dev, |
796 | int vf, struct sk_buff *skb); | 798 | int vf, struct sk_buff *skb); |
797 | #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE) | 799 | #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE) |
798 | int (*ndo_fcoe_enable)(struct net_device *dev); | 800 | int (*ndo_fcoe_enable)(struct net_device *dev); |
799 | int (*ndo_fcoe_disable)(struct net_device *dev); | 801 | int (*ndo_fcoe_disable)(struct net_device *dev); |
800 | int (*ndo_fcoe_ddp_setup)(struct net_device *dev, | 802 | int (*ndo_fcoe_ddp_setup)(struct net_device *dev, |
801 | u16 xid, | 803 | u16 xid, |
802 | struct scatterlist *sgl, | 804 | struct scatterlist *sgl, |
803 | unsigned int sgc); | 805 | unsigned int sgc); |
804 | int (*ndo_fcoe_ddp_done)(struct net_device *dev, | 806 | int (*ndo_fcoe_ddp_done)(struct net_device *dev, |
805 | u16 xid); | 807 | u16 xid); |
806 | #define NETDEV_FCOE_WWNN 0 | 808 | #define NETDEV_FCOE_WWNN 0 |
807 | #define NETDEV_FCOE_WWPN 1 | 809 | #define NETDEV_FCOE_WWPN 1 |
808 | int (*ndo_fcoe_get_wwn)(struct net_device *dev, | 810 | int (*ndo_fcoe_get_wwn)(struct net_device *dev, |
809 | u64 *wwn, int type); | 811 | u64 *wwn, int type); |
810 | #endif | 812 | #endif |
811 | }; | 813 | }; |
812 | 814 | ||
813 | /* | 815 | /* |
814 | * The DEVICE structure. | 816 | * The DEVICE structure. |
815 | * Actually, this whole structure is a big mistake. It mixes I/O | 817 | * Actually, this whole structure is a big mistake. It mixes I/O |
816 | * data with strictly "high-level" data, and it has to know about | 818 | * data with strictly "high-level" data, and it has to know about |
817 | * almost every data structure used in the INET module. | 819 | * almost every data structure used in the INET module. |
818 | * | 820 | * |
819 | * FIXME: cleanup struct net_device such that network protocol info | 821 | * FIXME: cleanup struct net_device such that network protocol info |
820 | * moves out. | 822 | * moves out. |
821 | */ | 823 | */ |
822 | 824 | ||
823 | struct net_device { | 825 | struct net_device { |
824 | 826 | ||
825 | /* | 827 | /* |
826 | * This is the first field of the "visible" part of this structure | 828 | * This is the first field of the "visible" part of this structure |
827 | * (i.e. as seen by users in the "Space.c" file). It is the name | 829 | * (i.e. as seen by users in the "Space.c" file). It is the name |
828 | * of the interface. | 830 | * of the interface. |
829 | */ | 831 | */ |
830 | char name[IFNAMSIZ]; | 832 | char name[IFNAMSIZ]; |
831 | 833 | ||
832 | struct pm_qos_request_list pm_qos_req; | 834 | struct pm_qos_request_list pm_qos_req; |
833 | 835 | ||
834 | /* device name hash chain */ | 836 | /* device name hash chain */ |
835 | struct hlist_node name_hlist; | 837 | struct hlist_node name_hlist; |
836 | /* snmp alias */ | 838 | /* snmp alias */ |
837 | char *ifalias; | 839 | char *ifalias; |
838 | 840 | ||
839 | /* | 841 | /* |
840 | * I/O specific fields | 842 | * I/O specific fields |
841 | * FIXME: Merge these and struct ifmap into one | 843 | * FIXME: Merge these and struct ifmap into one |
842 | */ | 844 | */ |
843 | unsigned long mem_end; /* shared mem end */ | 845 | unsigned long mem_end; /* shared mem end */ |
844 | unsigned long mem_start; /* shared mem start */ | 846 | unsigned long mem_start; /* shared mem start */ |
845 | unsigned long base_addr; /* device I/O address */ | 847 | unsigned long base_addr; /* device I/O address */ |
846 | unsigned int irq; /* device IRQ number */ | 848 | unsigned int irq; /* device IRQ number */ |
847 | 849 | ||
848 | /* | 850 | /* |
849 | * Some hardware also needs these fields, but they are not | 851 | * Some hardware also needs these fields, but they are not |
850 | * part of the usual set specified in Space.c. | 852 | * part of the usual set specified in Space.c. |
851 | */ | 853 | */ |
852 | 854 | ||
853 | unsigned char if_port; /* Selectable AUI, TP,..*/ | 855 | unsigned char if_port; /* Selectable AUI, TP,..*/ |
854 | unsigned char dma; /* DMA channel */ | 856 | unsigned char dma; /* DMA channel */ |
855 | 857 | ||
856 | unsigned long state; | 858 | unsigned long state; |
857 | 859 | ||
858 | struct list_head dev_list; | 860 | struct list_head dev_list; |
859 | struct list_head napi_list; | 861 | struct list_head napi_list; |
860 | struct list_head unreg_list; | 862 | struct list_head unreg_list; |
861 | 863 | ||
862 | /* Net device features */ | 864 | /* Net device features */ |
863 | unsigned long features; | 865 | unsigned long features; |
864 | #define NETIF_F_SG 1 /* Scatter/gather IO. */ | 866 | #define NETIF_F_SG 1 /* Scatter/gather IO. */ |
865 | #define NETIF_F_IP_CSUM 2 /* Can checksum TCP/UDP over IPv4. */ | 867 | #define NETIF_F_IP_CSUM 2 /* Can checksum TCP/UDP over IPv4. */ |
866 | #define NETIF_F_NO_CSUM 4 /* Does not require checksum. F.e. loopack. */ | 868 | #define NETIF_F_NO_CSUM 4 /* Does not require checksum. F.e. loopack. */ |
867 | #define NETIF_F_HW_CSUM 8 /* Can checksum all the packets. */ | 869 | #define NETIF_F_HW_CSUM 8 /* Can checksum all the packets. */ |
868 | #define NETIF_F_IPV6_CSUM 16 /* Can checksum TCP/UDP over IPV6 */ | 870 | #define NETIF_F_IPV6_CSUM 16 /* Can checksum TCP/UDP over IPV6 */ |
869 | #define NETIF_F_HIGHDMA 32 /* Can DMA to high memory. */ | 871 | #define NETIF_F_HIGHDMA 32 /* Can DMA to high memory. */ |
870 | #define NETIF_F_FRAGLIST 64 /* Scatter/gather IO. */ | 872 | #define NETIF_F_FRAGLIST 64 /* Scatter/gather IO. */ |
871 | #define NETIF_F_HW_VLAN_TX 128 /* Transmit VLAN hw acceleration */ | 873 | #define NETIF_F_HW_VLAN_TX 128 /* Transmit VLAN hw acceleration */ |
872 | #define NETIF_F_HW_VLAN_RX 256 /* Receive VLAN hw acceleration */ | 874 | #define NETIF_F_HW_VLAN_RX 256 /* Receive VLAN hw acceleration */ |
873 | #define NETIF_F_HW_VLAN_FILTER 512 /* Receive filtering on VLAN */ | 875 | #define NETIF_F_HW_VLAN_FILTER 512 /* Receive filtering on VLAN */ |
874 | #define NETIF_F_VLAN_CHALLENGED 1024 /* Device cannot handle VLAN packets */ | 876 | #define NETIF_F_VLAN_CHALLENGED 1024 /* Device cannot handle VLAN packets */ |
875 | #define NETIF_F_GSO 2048 /* Enable software GSO. */ | 877 | #define NETIF_F_GSO 2048 /* Enable software GSO. */ |
876 | #define NETIF_F_LLTX 4096 /* LockLess TX - deprecated. Please */ | 878 | #define NETIF_F_LLTX 4096 /* LockLess TX - deprecated. Please */ |
877 | /* do not use LLTX in new drivers */ | 879 | /* do not use LLTX in new drivers */ |
878 | #define NETIF_F_NETNS_LOCAL 8192 /* Does not change network namespaces */ | 880 | #define NETIF_F_NETNS_LOCAL 8192 /* Does not change network namespaces */ |
879 | #define NETIF_F_GRO 16384 /* Generic receive offload */ | 881 | #define NETIF_F_GRO 16384 /* Generic receive offload */ |
880 | #define NETIF_F_LRO 32768 /* large receive offload */ | 882 | #define NETIF_F_LRO 32768 /* large receive offload */ |
881 | 883 | ||
882 | /* the GSO_MASK reserves bits 16 through 23 */ | 884 | /* the GSO_MASK reserves bits 16 through 23 */ |
883 | #define NETIF_F_FCOE_CRC (1 << 24) /* FCoE CRC32 */ | 885 | #define NETIF_F_FCOE_CRC (1 << 24) /* FCoE CRC32 */ |
884 | #define NETIF_F_SCTP_CSUM (1 << 25) /* SCTP checksum offload */ | 886 | #define NETIF_F_SCTP_CSUM (1 << 25) /* SCTP checksum offload */ |
885 | #define NETIF_F_FCOE_MTU (1 << 26) /* Supports max FCoE MTU, 2158 bytes*/ | 887 | #define NETIF_F_FCOE_MTU (1 << 26) /* Supports max FCoE MTU, 2158 bytes*/ |
886 | #define NETIF_F_NTUPLE (1 << 27) /* N-tuple filters supported */ | 888 | #define NETIF_F_NTUPLE (1 << 27) /* N-tuple filters supported */ |
887 | #define NETIF_F_RXHASH (1 << 28) /* Receive hashing offload */ | 889 | #define NETIF_F_RXHASH (1 << 28) /* Receive hashing offload */ |
888 | 890 | ||
889 | /* Segmentation offload features */ | 891 | /* Segmentation offload features */ |
890 | #define NETIF_F_GSO_SHIFT 16 | 892 | #define NETIF_F_GSO_SHIFT 16 |
891 | #define NETIF_F_GSO_MASK 0x00ff0000 | 893 | #define NETIF_F_GSO_MASK 0x00ff0000 |
892 | #define NETIF_F_TSO (SKB_GSO_TCPV4 << NETIF_F_GSO_SHIFT) | 894 | #define NETIF_F_TSO (SKB_GSO_TCPV4 << NETIF_F_GSO_SHIFT) |
893 | #define NETIF_F_UFO (SKB_GSO_UDP << NETIF_F_GSO_SHIFT) | 895 | #define NETIF_F_UFO (SKB_GSO_UDP << NETIF_F_GSO_SHIFT) |
894 | #define NETIF_F_GSO_ROBUST (SKB_GSO_DODGY << NETIF_F_GSO_SHIFT) | 896 | #define NETIF_F_GSO_ROBUST (SKB_GSO_DODGY << NETIF_F_GSO_SHIFT) |
895 | #define NETIF_F_TSO_ECN (SKB_GSO_TCP_ECN << NETIF_F_GSO_SHIFT) | 897 | #define NETIF_F_TSO_ECN (SKB_GSO_TCP_ECN << NETIF_F_GSO_SHIFT) |
896 | #define NETIF_F_TSO6 (SKB_GSO_TCPV6 << NETIF_F_GSO_SHIFT) | 898 | #define NETIF_F_TSO6 (SKB_GSO_TCPV6 << NETIF_F_GSO_SHIFT) |
897 | #define NETIF_F_FSO (SKB_GSO_FCOE << NETIF_F_GSO_SHIFT) | 899 | #define NETIF_F_FSO (SKB_GSO_FCOE << NETIF_F_GSO_SHIFT) |
898 | 900 | ||
899 | /* List of features with software fallbacks. */ | 901 | /* List of features with software fallbacks. */ |
900 | #define NETIF_F_GSO_SOFTWARE (NETIF_F_TSO | NETIF_F_TSO_ECN | \ | 902 | #define NETIF_F_GSO_SOFTWARE (NETIF_F_TSO | NETIF_F_TSO_ECN | \ |
901 | NETIF_F_TSO6 | NETIF_F_UFO) | 903 | NETIF_F_TSO6 | NETIF_F_UFO) |
902 | 904 | ||
903 | 905 | ||
904 | #define NETIF_F_GEN_CSUM (NETIF_F_NO_CSUM | NETIF_F_HW_CSUM) | 906 | #define NETIF_F_GEN_CSUM (NETIF_F_NO_CSUM | NETIF_F_HW_CSUM) |
905 | #define NETIF_F_V4_CSUM (NETIF_F_GEN_CSUM | NETIF_F_IP_CSUM) | 907 | #define NETIF_F_V4_CSUM (NETIF_F_GEN_CSUM | NETIF_F_IP_CSUM) |
906 | #define NETIF_F_V6_CSUM (NETIF_F_GEN_CSUM | NETIF_F_IPV6_CSUM) | 908 | #define NETIF_F_V6_CSUM (NETIF_F_GEN_CSUM | NETIF_F_IPV6_CSUM) |
907 | #define NETIF_F_ALL_CSUM (NETIF_F_V4_CSUM | NETIF_F_V6_CSUM) | 909 | #define NETIF_F_ALL_CSUM (NETIF_F_V4_CSUM | NETIF_F_V6_CSUM) |
908 | 910 | ||
909 | /* | 911 | /* |
910 | * If one device supports one of these features, then enable them | 912 | * If one device supports one of these features, then enable them |
911 | * for all in netdev_increment_features. | 913 | * for all in netdev_increment_features. |
912 | */ | 914 | */ |
913 | #define NETIF_F_ONE_FOR_ALL (NETIF_F_GSO_SOFTWARE | NETIF_F_GSO_ROBUST | \ | 915 | #define NETIF_F_ONE_FOR_ALL (NETIF_F_GSO_SOFTWARE | NETIF_F_GSO_ROBUST | \ |
914 | NETIF_F_SG | NETIF_F_HIGHDMA | \ | 916 | NETIF_F_SG | NETIF_F_HIGHDMA | \ |
915 | NETIF_F_FRAGLIST) | 917 | NETIF_F_FRAGLIST) |
916 | 918 | ||
917 | /* Interface index. Unique device identifier */ | 919 | /* Interface index. Unique device identifier */ |
918 | int ifindex; | 920 | int ifindex; |
919 | int iflink; | 921 | int iflink; |
920 | 922 | ||
921 | struct net_device_stats stats; | 923 | struct net_device_stats stats; |
922 | atomic_long_t rx_dropped; /* dropped packets by core network | 924 | atomic_long_t rx_dropped; /* dropped packets by core network |
923 | * Do not use this in drivers. | 925 | * Do not use this in drivers. |
924 | */ | 926 | */ |
925 | 927 | ||
926 | #ifdef CONFIG_WIRELESS_EXT | 928 | #ifdef CONFIG_WIRELESS_EXT |
927 | /* List of functions to handle Wireless Extensions (instead of ioctl). | 929 | /* List of functions to handle Wireless Extensions (instead of ioctl). |
928 | * See <net/iw_handler.h> for details. Jean II */ | 930 | * See <net/iw_handler.h> for details. Jean II */ |
929 | const struct iw_handler_def * wireless_handlers; | 931 | const struct iw_handler_def * wireless_handlers; |
930 | /* Instance data managed by the core of Wireless Extensions. */ | 932 | /* Instance data managed by the core of Wireless Extensions. */ |
931 | struct iw_public_data * wireless_data; | 933 | struct iw_public_data * wireless_data; |
932 | #endif | 934 | #endif |
933 | /* Management operations */ | 935 | /* Management operations */ |
934 | const struct net_device_ops *netdev_ops; | 936 | const struct net_device_ops *netdev_ops; |
935 | const struct ethtool_ops *ethtool_ops; | 937 | const struct ethtool_ops *ethtool_ops; |
936 | 938 | ||
937 | /* Hardware header description */ | 939 | /* Hardware header description */ |
938 | const struct header_ops *header_ops; | 940 | const struct header_ops *header_ops; |
939 | 941 | ||
940 | unsigned int flags; /* interface flags (a la BSD) */ | 942 | unsigned int flags; /* interface flags (a la BSD) */ |
941 | unsigned short gflags; | 943 | unsigned short gflags; |
942 | unsigned int priv_flags; /* Like 'flags' but invisible to userspace. */ | 944 | unsigned int priv_flags; /* Like 'flags' but invisible to userspace. */ |
943 | unsigned short padded; /* How much padding added by alloc_netdev() */ | 945 | unsigned short padded; /* How much padding added by alloc_netdev() */ |
944 | 946 | ||
945 | unsigned char operstate; /* RFC2863 operstate */ | 947 | unsigned char operstate; /* RFC2863 operstate */ |
946 | unsigned char link_mode; /* mapping policy to operstate */ | 948 | unsigned char link_mode; /* mapping policy to operstate */ |
947 | 949 | ||
948 | unsigned int mtu; /* interface MTU value */ | 950 | unsigned int mtu; /* interface MTU value */ |
949 | unsigned short type; /* interface hardware type */ | 951 | unsigned short type; /* interface hardware type */ |
950 | unsigned short hard_header_len; /* hardware hdr length */ | 952 | unsigned short hard_header_len; /* hardware hdr length */ |
951 | 953 | ||
952 | /* extra head- and tailroom the hardware may need, but not in all cases | 954 | /* extra head- and tailroom the hardware may need, but not in all cases |
953 | * can this be guaranteed, especially tailroom. Some cases also use | 955 | * can this be guaranteed, especially tailroom. Some cases also use |
954 | * LL_MAX_HEADER instead to allocate the skb. | 956 | * LL_MAX_HEADER instead to allocate the skb. |
955 | */ | 957 | */ |
956 | unsigned short needed_headroom; | 958 | unsigned short needed_headroom; |
957 | unsigned short needed_tailroom; | 959 | unsigned short needed_tailroom; |
958 | 960 | ||
959 | /* Interface address info. */ | 961 | /* Interface address info. */ |
960 | unsigned char perm_addr[MAX_ADDR_LEN]; /* permanent hw address */ | 962 | unsigned char perm_addr[MAX_ADDR_LEN]; /* permanent hw address */ |
961 | unsigned char addr_assign_type; /* hw address assignment type */ | 963 | unsigned char addr_assign_type; /* hw address assignment type */ |
962 | unsigned char addr_len; /* hardware address length */ | 964 | unsigned char addr_len; /* hardware address length */ |
963 | unsigned short dev_id; /* for shared network cards */ | 965 | unsigned short dev_id; /* for shared network cards */ |
964 | 966 | ||
965 | spinlock_t addr_list_lock; | 967 | spinlock_t addr_list_lock; |
966 | struct netdev_hw_addr_list uc; /* Unicast mac addresses */ | 968 | struct netdev_hw_addr_list uc; /* Unicast mac addresses */ |
967 | struct netdev_hw_addr_list mc; /* Multicast mac addresses */ | 969 | struct netdev_hw_addr_list mc; /* Multicast mac addresses */ |
968 | int uc_promisc; | 970 | int uc_promisc; |
969 | unsigned int promiscuity; | 971 | unsigned int promiscuity; |
970 | unsigned int allmulti; | 972 | unsigned int allmulti; |
971 | 973 | ||
972 | 974 | ||
973 | /* Protocol specific pointers */ | 975 | /* Protocol specific pointers */ |
974 | 976 | ||
975 | #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) | 977 | #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) |
976 | struct vlan_group __rcu *vlgrp; /* VLAN group */ | 978 | struct vlan_group __rcu *vlgrp; /* VLAN group */ |
977 | #endif | 979 | #endif |
978 | #ifdef CONFIG_NET_DSA | 980 | #ifdef CONFIG_NET_DSA |
979 | void *dsa_ptr; /* dsa specific data */ | 981 | void *dsa_ptr; /* dsa specific data */ |
980 | #endif | 982 | #endif |
981 | void *atalk_ptr; /* AppleTalk link */ | 983 | void *atalk_ptr; /* AppleTalk link */ |
982 | struct in_device __rcu *ip_ptr; /* IPv4 specific data */ | 984 | struct in_device __rcu *ip_ptr; /* IPv4 specific data */ |
983 | struct dn_dev __rcu *dn_ptr; /* DECnet specific data */ | 985 | struct dn_dev __rcu *dn_ptr; /* DECnet specific data */ |
984 | struct inet6_dev __rcu *ip6_ptr; /* IPv6 specific data */ | 986 | struct inet6_dev __rcu *ip6_ptr; /* IPv6 specific data */ |
985 | void *ec_ptr; /* Econet specific data */ | 987 | void *ec_ptr; /* Econet specific data */ |
986 | void *ax25_ptr; /* AX.25 specific data */ | 988 | void *ax25_ptr; /* AX.25 specific data */ |
987 | struct wireless_dev *ieee80211_ptr; /* IEEE 802.11 specific data, | 989 | struct wireless_dev *ieee80211_ptr; /* IEEE 802.11 specific data, |
988 | assign before registering */ | 990 | assign before registering */ |
989 | 991 | ||
990 | /* | 992 | /* |
991 | * Cache lines mostly used on receive path (including eth_type_trans()) | 993 | * Cache lines mostly used on receive path (including eth_type_trans()) |
992 | */ | 994 | */ |
993 | unsigned long last_rx; /* Time of last Rx | 995 | unsigned long last_rx; /* Time of last Rx |
994 | * This should not be set in | 996 | * This should not be set in |
995 | * drivers, unless really needed, | 997 | * drivers, unless really needed, |
996 | * because network stack (bonding) | 998 | * because network stack (bonding) |
997 | * use it if/when necessary, to | 999 | * use it if/when necessary, to |
998 | * avoid dirtying this cache line. | 1000 | * avoid dirtying this cache line. |
999 | */ | 1001 | */ |
1000 | 1002 | ||
1001 | struct net_device *master; /* Pointer to master device of a group, | 1003 | struct net_device *master; /* Pointer to master device of a group, |
1002 | * which this device is member of. | 1004 | * which this device is member of. |
1003 | */ | 1005 | */ |
1004 | 1006 | ||
1005 | /* Interface address info used in eth_type_trans() */ | 1007 | /* Interface address info used in eth_type_trans() */ |
1006 | unsigned char *dev_addr; /* hw address, (before bcast | 1008 | unsigned char *dev_addr; /* hw address, (before bcast |
1007 | because most packets are | 1009 | because most packets are |
1008 | unicast) */ | 1010 | unicast) */ |
1009 | 1011 | ||
1010 | struct netdev_hw_addr_list dev_addrs; /* list of device | 1012 | struct netdev_hw_addr_list dev_addrs; /* list of device |
1011 | hw addresses */ | 1013 | hw addresses */ |
1012 | 1014 | ||
1013 | unsigned char broadcast[MAX_ADDR_LEN]; /* hw bcast add */ | 1015 | unsigned char broadcast[MAX_ADDR_LEN]; /* hw bcast add */ |
1014 | 1016 | ||
1015 | #ifdef CONFIG_RPS | 1017 | #ifdef CONFIG_RPS |
1016 | struct kset *queues_kset; | 1018 | struct kset *queues_kset; |
1017 | 1019 | ||
1018 | struct netdev_rx_queue *_rx; | 1020 | struct netdev_rx_queue *_rx; |
1019 | 1021 | ||
1020 | /* Number of RX queues allocated at register_netdev() time */ | 1022 | /* Number of RX queues allocated at register_netdev() time */ |
1021 | unsigned int num_rx_queues; | 1023 | unsigned int num_rx_queues; |
1022 | 1024 | ||
1023 | /* Number of RX queues currently active in device */ | 1025 | /* Number of RX queues currently active in device */ |
1024 | unsigned int real_num_rx_queues; | 1026 | unsigned int real_num_rx_queues; |
1025 | #endif | 1027 | #endif |
1026 | 1028 | ||
1027 | rx_handler_func_t __rcu *rx_handler; | 1029 | rx_handler_func_t __rcu *rx_handler; |
1028 | void __rcu *rx_handler_data; | 1030 | void __rcu *rx_handler_data; |
1029 | 1031 | ||
1030 | struct netdev_queue __rcu *ingress_queue; | 1032 | struct netdev_queue __rcu *ingress_queue; |
1031 | 1033 | ||
1032 | /* | 1034 | /* |
1033 | * Cache lines mostly used on transmit path | 1035 | * Cache lines mostly used on transmit path |
1034 | */ | 1036 | */ |
1035 | struct netdev_queue *_tx ____cacheline_aligned_in_smp; | 1037 | struct netdev_queue *_tx ____cacheline_aligned_in_smp; |
1036 | 1038 | ||
1037 | /* Number of TX queues allocated at alloc_netdev_mq() time */ | 1039 | /* Number of TX queues allocated at alloc_netdev_mq() time */ |
1038 | unsigned int num_tx_queues; | 1040 | unsigned int num_tx_queues; |
1039 | 1041 | ||
1040 | /* Number of TX queues currently active in device */ | 1042 | /* Number of TX queues currently active in device */ |
1041 | unsigned int real_num_tx_queues; | 1043 | unsigned int real_num_tx_queues; |
1042 | 1044 | ||
1043 | /* root qdisc from userspace point of view */ | 1045 | /* root qdisc from userspace point of view */ |
1044 | struct Qdisc *qdisc; | 1046 | struct Qdisc *qdisc; |
1045 | 1047 | ||
1046 | unsigned long tx_queue_len; /* Max frames per queue allowed */ | 1048 | unsigned long tx_queue_len; /* Max frames per queue allowed */ |
1047 | spinlock_t tx_global_lock; | 1049 | spinlock_t tx_global_lock; |
1048 | 1050 | ||
1051 | #ifdef CONFIG_XPS | ||
1049 | struct xps_dev_maps *xps_maps; | 1052 | struct xps_dev_maps *xps_maps; |
1053 | #endif | ||
1050 | 1054 | ||
1051 | /* These may be needed for future network-power-down code. */ | 1055 | /* These may be needed for future network-power-down code. */ |
1052 | 1056 | ||
1053 | /* | 1057 | /* |
1054 | * trans_start here is expensive for high speed devices on SMP, | 1058 | * trans_start here is expensive for high speed devices on SMP, |
1055 | * please use netdev_queue->trans_start instead. | 1059 | * please use netdev_queue->trans_start instead. |
1056 | */ | 1060 | */ |
1057 | unsigned long trans_start; /* Time (in jiffies) of last Tx */ | 1061 | unsigned long trans_start; /* Time (in jiffies) of last Tx */ |
1058 | 1062 | ||
1059 | int watchdog_timeo; /* used by dev_watchdog() */ | 1063 | int watchdog_timeo; /* used by dev_watchdog() */ |
1060 | struct timer_list watchdog_timer; | 1064 | struct timer_list watchdog_timer; |
1061 | 1065 | ||
1062 | /* Number of references to this device */ | 1066 | /* Number of references to this device */ |
1063 | int __percpu *pcpu_refcnt; | 1067 | int __percpu *pcpu_refcnt; |
1064 | 1068 | ||
1065 | /* delayed register/unregister */ | 1069 | /* delayed register/unregister */ |
1066 | struct list_head todo_list; | 1070 | struct list_head todo_list; |
1067 | /* device index hash chain */ | 1071 | /* device index hash chain */ |
1068 | struct hlist_node index_hlist; | 1072 | struct hlist_node index_hlist; |
1069 | 1073 | ||
1070 | struct list_head link_watch_list; | 1074 | struct list_head link_watch_list; |
1071 | 1075 | ||
1072 | /* register/unregister state machine */ | 1076 | /* register/unregister state machine */ |
1073 | enum { NETREG_UNINITIALIZED=0, | 1077 | enum { NETREG_UNINITIALIZED=0, |
1074 | NETREG_REGISTERED, /* completed register_netdevice */ | 1078 | NETREG_REGISTERED, /* completed register_netdevice */ |
1075 | NETREG_UNREGISTERING, /* called unregister_netdevice */ | 1079 | NETREG_UNREGISTERING, /* called unregister_netdevice */ |
1076 | NETREG_UNREGISTERED, /* completed unregister todo */ | 1080 | NETREG_UNREGISTERED, /* completed unregister todo */ |
1077 | NETREG_RELEASED, /* called free_netdev */ | 1081 | NETREG_RELEASED, /* called free_netdev */ |
1078 | NETREG_DUMMY, /* dummy device for NAPI poll */ | 1082 | NETREG_DUMMY, /* dummy device for NAPI poll */ |
1079 | } reg_state:16; | 1083 | } reg_state:16; |
1080 | 1084 | ||
1081 | enum { | 1085 | enum { |
1082 | RTNL_LINK_INITIALIZED, | 1086 | RTNL_LINK_INITIALIZED, |
1083 | RTNL_LINK_INITIALIZING, | 1087 | RTNL_LINK_INITIALIZING, |
1084 | } rtnl_link_state:16; | 1088 | } rtnl_link_state:16; |
1085 | 1089 | ||
1086 | /* Called from unregister, can be used to call free_netdev */ | 1090 | /* Called from unregister, can be used to call free_netdev */ |
1087 | void (*destructor)(struct net_device *dev); | 1091 | void (*destructor)(struct net_device *dev); |
1088 | 1092 | ||
1089 | #ifdef CONFIG_NETPOLL | 1093 | #ifdef CONFIG_NETPOLL |
1090 | struct netpoll_info *npinfo; | 1094 | struct netpoll_info *npinfo; |
1091 | #endif | 1095 | #endif |
1092 | 1096 | ||
1093 | #ifdef CONFIG_NET_NS | 1097 | #ifdef CONFIG_NET_NS |
1094 | /* Network namespace this network device is inside */ | 1098 | /* Network namespace this network device is inside */ |
1095 | struct net *nd_net; | 1099 | struct net *nd_net; |
1096 | #endif | 1100 | #endif |
1097 | 1101 | ||
1098 | /* mid-layer private */ | 1102 | /* mid-layer private */ |
1099 | union { | 1103 | union { |
1100 | void *ml_priv; | 1104 | void *ml_priv; |
1101 | struct pcpu_lstats __percpu *lstats; /* loopback stats */ | 1105 | struct pcpu_lstats __percpu *lstats; /* loopback stats */ |
1102 | struct pcpu_tstats __percpu *tstats; /* tunnel stats */ | 1106 | struct pcpu_tstats __percpu *tstats; /* tunnel stats */ |
1103 | struct pcpu_dstats __percpu *dstats; /* dummy stats */ | 1107 | struct pcpu_dstats __percpu *dstats; /* dummy stats */ |
1104 | }; | 1108 | }; |
1105 | /* GARP */ | 1109 | /* GARP */ |
1106 | struct garp_port __rcu *garp_port; | 1110 | struct garp_port __rcu *garp_port; |
1107 | 1111 | ||
1108 | /* class/net/name entry */ | 1112 | /* class/net/name entry */ |
1109 | struct device dev; | 1113 | struct device dev; |
1110 | /* space for optional device, statistics, and wireless sysfs groups */ | 1114 | /* space for optional device, statistics, and wireless sysfs groups */ |
1111 | const struct attribute_group *sysfs_groups[4]; | 1115 | const struct attribute_group *sysfs_groups[4]; |
1112 | 1116 | ||
1113 | /* rtnetlink link ops */ | 1117 | /* rtnetlink link ops */ |
1114 | const struct rtnl_link_ops *rtnl_link_ops; | 1118 | const struct rtnl_link_ops *rtnl_link_ops; |
1115 | 1119 | ||
1116 | /* VLAN feature mask */ | 1120 | /* VLAN feature mask */ |
1117 | unsigned long vlan_features; | 1121 | unsigned long vlan_features; |
1118 | 1122 | ||
1119 | /* for setting kernel sock attribute on TCP connection setup */ | 1123 | /* for setting kernel sock attribute on TCP connection setup */ |
1120 | #define GSO_MAX_SIZE 65536 | 1124 | #define GSO_MAX_SIZE 65536 |
1121 | unsigned int gso_max_size; | 1125 | unsigned int gso_max_size; |
1122 | 1126 | ||
1123 | #ifdef CONFIG_DCB | 1127 | #ifdef CONFIG_DCB |
1124 | /* Data Center Bridging netlink ops */ | 1128 | /* Data Center Bridging netlink ops */ |
1125 | const struct dcbnl_rtnl_ops *dcbnl_ops; | 1129 | const struct dcbnl_rtnl_ops *dcbnl_ops; |
1126 | #endif | 1130 | #endif |
1127 | 1131 | ||
1128 | #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE) | 1132 | #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE) |
1129 | /* max exchange id for FCoE LRO by ddp */ | 1133 | /* max exchange id for FCoE LRO by ddp */ |
1130 | unsigned int fcoe_ddp_xid; | 1134 | unsigned int fcoe_ddp_xid; |
1131 | #endif | 1135 | #endif |
1132 | /* n-tuple filter list attached to this device */ | 1136 | /* n-tuple filter list attached to this device */ |
1133 | struct ethtool_rx_ntuple_list ethtool_ntuple_list; | 1137 | struct ethtool_rx_ntuple_list ethtool_ntuple_list; |
1134 | 1138 | ||
1135 | /* phy device may attach itself for hardware timestamping */ | 1139 | /* phy device may attach itself for hardware timestamping */ |
1136 | struct phy_device *phydev; | 1140 | struct phy_device *phydev; |
1137 | }; | 1141 | }; |
1138 | #define to_net_dev(d) container_of(d, struct net_device, dev) | 1142 | #define to_net_dev(d) container_of(d, struct net_device, dev) |
1139 | 1143 | ||
1140 | #define NETDEV_ALIGN 32 | 1144 | #define NETDEV_ALIGN 32 |
1141 | 1145 | ||
1142 | static inline | 1146 | static inline |
1143 | struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev, | 1147 | struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev, |
1144 | unsigned int index) | 1148 | unsigned int index) |
1145 | { | 1149 | { |
1146 | return &dev->_tx[index]; | 1150 | return &dev->_tx[index]; |
1147 | } | 1151 | } |
1148 | 1152 | ||
1149 | static inline void netdev_for_each_tx_queue(struct net_device *dev, | 1153 | static inline void netdev_for_each_tx_queue(struct net_device *dev, |
1150 | void (*f)(struct net_device *, | 1154 | void (*f)(struct net_device *, |
1151 | struct netdev_queue *, | 1155 | struct netdev_queue *, |
1152 | void *), | 1156 | void *), |
1153 | void *arg) | 1157 | void *arg) |
1154 | { | 1158 | { |
1155 | unsigned int i; | 1159 | unsigned int i; |
1156 | 1160 | ||
1157 | for (i = 0; i < dev->num_tx_queues; i++) | 1161 | for (i = 0; i < dev->num_tx_queues; i++) |
1158 | f(dev, &dev->_tx[i], arg); | 1162 | f(dev, &dev->_tx[i], arg); |
1159 | } | 1163 | } |
1160 | 1164 | ||
1161 | /* | 1165 | /* |
1162 | * Net namespace inlines | 1166 | * Net namespace inlines |
1163 | */ | 1167 | */ |
1164 | static inline | 1168 | static inline |
1165 | struct net *dev_net(const struct net_device *dev) | 1169 | struct net *dev_net(const struct net_device *dev) |
1166 | { | 1170 | { |
1167 | return read_pnet(&dev->nd_net); | 1171 | return read_pnet(&dev->nd_net); |
1168 | } | 1172 | } |
1169 | 1173 | ||
1170 | static inline | 1174 | static inline |
1171 | void dev_net_set(struct net_device *dev, struct net *net) | 1175 | void dev_net_set(struct net_device *dev, struct net *net) |
1172 | { | 1176 | { |
1173 | #ifdef CONFIG_NET_NS | 1177 | #ifdef CONFIG_NET_NS |
1174 | release_net(dev->nd_net); | 1178 | release_net(dev->nd_net); |
1175 | dev->nd_net = hold_net(net); | 1179 | dev->nd_net = hold_net(net); |
1176 | #endif | 1180 | #endif |
1177 | } | 1181 | } |
1178 | 1182 | ||
1179 | static inline bool netdev_uses_dsa_tags(struct net_device *dev) | 1183 | static inline bool netdev_uses_dsa_tags(struct net_device *dev) |
1180 | { | 1184 | { |
1181 | #ifdef CONFIG_NET_DSA_TAG_DSA | 1185 | #ifdef CONFIG_NET_DSA_TAG_DSA |
1182 | if (dev->dsa_ptr != NULL) | 1186 | if (dev->dsa_ptr != NULL) |
1183 | return dsa_uses_dsa_tags(dev->dsa_ptr); | 1187 | return dsa_uses_dsa_tags(dev->dsa_ptr); |
1184 | #endif | 1188 | #endif |
1185 | 1189 | ||
1186 | return 0; | 1190 | return 0; |
1187 | } | 1191 | } |
1188 | 1192 | ||
1189 | #ifndef CONFIG_NET_NS | 1193 | #ifndef CONFIG_NET_NS |
1190 | static inline void skb_set_dev(struct sk_buff *skb, struct net_device *dev) | 1194 | static inline void skb_set_dev(struct sk_buff *skb, struct net_device *dev) |
1191 | { | 1195 | { |
1192 | skb->dev = dev; | 1196 | skb->dev = dev; |
1193 | } | 1197 | } |
1194 | #else /* CONFIG_NET_NS */ | 1198 | #else /* CONFIG_NET_NS */ |
1195 | void skb_set_dev(struct sk_buff *skb, struct net_device *dev); | 1199 | void skb_set_dev(struct sk_buff *skb, struct net_device *dev); |
1196 | #endif | 1200 | #endif |
1197 | 1201 | ||
1198 | static inline bool netdev_uses_trailer_tags(struct net_device *dev) | 1202 | static inline bool netdev_uses_trailer_tags(struct net_device *dev) |
1199 | { | 1203 | { |
1200 | #ifdef CONFIG_NET_DSA_TAG_TRAILER | 1204 | #ifdef CONFIG_NET_DSA_TAG_TRAILER |
1201 | if (dev->dsa_ptr != NULL) | 1205 | if (dev->dsa_ptr != NULL) |
1202 | return dsa_uses_trailer_tags(dev->dsa_ptr); | 1206 | return dsa_uses_trailer_tags(dev->dsa_ptr); |
1203 | #endif | 1207 | #endif |
1204 | 1208 | ||
1205 | return 0; | 1209 | return 0; |
1206 | } | 1210 | } |
1207 | 1211 | ||
1208 | /** | 1212 | /** |
1209 | * netdev_priv - access network device private data | 1213 | * netdev_priv - access network device private data |
1210 | * @dev: network device | 1214 | * @dev: network device |
1211 | * | 1215 | * |
1212 | * Get network device private data | 1216 | * Get network device private data |
1213 | */ | 1217 | */ |
1214 | static inline void *netdev_priv(const struct net_device *dev) | 1218 | static inline void *netdev_priv(const struct net_device *dev) |
1215 | { | 1219 | { |
1216 | return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN); | 1220 | return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN); |
1217 | } | 1221 | } |
1218 | 1222 | ||
1219 | /* Set the sysfs physical device reference for the network logical device | 1223 | /* Set the sysfs physical device reference for the network logical device |
1220 | * if set prior to registration will cause a symlink during initialization. | 1224 | * if set prior to registration will cause a symlink during initialization. |
1221 | */ | 1225 | */ |
1222 | #define SET_NETDEV_DEV(net, pdev) ((net)->dev.parent = (pdev)) | 1226 | #define SET_NETDEV_DEV(net, pdev) ((net)->dev.parent = (pdev)) |
1223 | 1227 | ||
1224 | /* Set the sysfs device type for the network logical device to allow | 1228 | /* Set the sysfs device type for the network logical device to allow |
1225 | * fin grained indentification of different network device types. For | 1229 | * fin grained indentification of different network device types. For |
1226 | * example Ethernet, Wirelss LAN, Bluetooth, WiMAX etc. | 1230 | * example Ethernet, Wirelss LAN, Bluetooth, WiMAX etc. |
1227 | */ | 1231 | */ |
1228 | #define SET_NETDEV_DEVTYPE(net, devtype) ((net)->dev.type = (devtype)) | 1232 | #define SET_NETDEV_DEVTYPE(net, devtype) ((net)->dev.type = (devtype)) |
1229 | 1233 | ||
1230 | /** | 1234 | /** |
1231 | * netif_napi_add - initialize a napi context | 1235 | * netif_napi_add - initialize a napi context |
1232 | * @dev: network device | 1236 | * @dev: network device |
1233 | * @napi: napi context | 1237 | * @napi: napi context |
1234 | * @poll: polling function | 1238 | * @poll: polling function |
1235 | * @weight: default weight | 1239 | * @weight: default weight |
1236 | * | 1240 | * |
1237 | * netif_napi_add() must be used to initialize a napi context prior to calling | 1241 | * netif_napi_add() must be used to initialize a napi context prior to calling |
1238 | * *any* of the other napi related functions. | 1242 | * *any* of the other napi related functions. |
1239 | */ | 1243 | */ |
1240 | void netif_napi_add(struct net_device *dev, struct napi_struct *napi, | 1244 | void netif_napi_add(struct net_device *dev, struct napi_struct *napi, |
1241 | int (*poll)(struct napi_struct *, int), int weight); | 1245 | int (*poll)(struct napi_struct *, int), int weight); |
1242 | 1246 | ||
1243 | /** | 1247 | /** |
1244 | * netif_napi_del - remove a napi context | 1248 | * netif_napi_del - remove a napi context |
1245 | * @napi: napi context | 1249 | * @napi: napi context |
1246 | * | 1250 | * |
1247 | * netif_napi_del() removes a napi context from the network device napi list | 1251 | * netif_napi_del() removes a napi context from the network device napi list |
1248 | */ | 1252 | */ |
1249 | void netif_napi_del(struct napi_struct *napi); | 1253 | void netif_napi_del(struct napi_struct *napi); |
1250 | 1254 | ||
1251 | struct napi_gro_cb { | 1255 | struct napi_gro_cb { |
1252 | /* Virtual address of skb_shinfo(skb)->frags[0].page + offset. */ | 1256 | /* Virtual address of skb_shinfo(skb)->frags[0].page + offset. */ |
1253 | void *frag0; | 1257 | void *frag0; |
1254 | 1258 | ||
1255 | /* Length of frag0. */ | 1259 | /* Length of frag0. */ |
1256 | unsigned int frag0_len; | 1260 | unsigned int frag0_len; |
1257 | 1261 | ||
1258 | /* This indicates where we are processing relative to skb->data. */ | 1262 | /* This indicates where we are processing relative to skb->data. */ |
1259 | int data_offset; | 1263 | int data_offset; |
1260 | 1264 | ||
1261 | /* This is non-zero if the packet may be of the same flow. */ | 1265 | /* This is non-zero if the packet may be of the same flow. */ |
1262 | int same_flow; | 1266 | int same_flow; |
1263 | 1267 | ||
1264 | /* This is non-zero if the packet cannot be merged with the new skb. */ | 1268 | /* This is non-zero if the packet cannot be merged with the new skb. */ |
1265 | int flush; | 1269 | int flush; |
1266 | 1270 | ||
1267 | /* Number of segments aggregated. */ | 1271 | /* Number of segments aggregated. */ |
1268 | int count; | 1272 | int count; |
1269 | 1273 | ||
1270 | /* Free the skb? */ | 1274 | /* Free the skb? */ |
1271 | int free; | 1275 | int free; |
1272 | }; | 1276 | }; |
1273 | 1277 | ||
1274 | #define NAPI_GRO_CB(skb) ((struct napi_gro_cb *)(skb)->cb) | 1278 | #define NAPI_GRO_CB(skb) ((struct napi_gro_cb *)(skb)->cb) |
1275 | 1279 | ||
1276 | struct packet_type { | 1280 | struct packet_type { |
1277 | __be16 type; /* This is really htons(ether_type). */ | 1281 | __be16 type; /* This is really htons(ether_type). */ |
1278 | struct net_device *dev; /* NULL is wildcarded here */ | 1282 | struct net_device *dev; /* NULL is wildcarded here */ |
1279 | int (*func) (struct sk_buff *, | 1283 | int (*func) (struct sk_buff *, |
1280 | struct net_device *, | 1284 | struct net_device *, |
1281 | struct packet_type *, | 1285 | struct packet_type *, |
1282 | struct net_device *); | 1286 | struct net_device *); |
1283 | struct sk_buff *(*gso_segment)(struct sk_buff *skb, | 1287 | struct sk_buff *(*gso_segment)(struct sk_buff *skb, |
1284 | int features); | 1288 | int features); |
1285 | int (*gso_send_check)(struct sk_buff *skb); | 1289 | int (*gso_send_check)(struct sk_buff *skb); |
1286 | struct sk_buff **(*gro_receive)(struct sk_buff **head, | 1290 | struct sk_buff **(*gro_receive)(struct sk_buff **head, |
1287 | struct sk_buff *skb); | 1291 | struct sk_buff *skb); |
1288 | int (*gro_complete)(struct sk_buff *skb); | 1292 | int (*gro_complete)(struct sk_buff *skb); |
1289 | void *af_packet_priv; | 1293 | void *af_packet_priv; |
1290 | struct list_head list; | 1294 | struct list_head list; |
1291 | }; | 1295 | }; |
1292 | 1296 | ||
1293 | #include <linux/interrupt.h> | 1297 | #include <linux/interrupt.h> |
1294 | #include <linux/notifier.h> | 1298 | #include <linux/notifier.h> |
1295 | 1299 | ||
1296 | extern rwlock_t dev_base_lock; /* Device list lock */ | 1300 | extern rwlock_t dev_base_lock; /* Device list lock */ |
1297 | 1301 | ||
1298 | 1302 | ||
1299 | #define for_each_netdev(net, d) \ | 1303 | #define for_each_netdev(net, d) \ |
1300 | list_for_each_entry(d, &(net)->dev_base_head, dev_list) | 1304 | list_for_each_entry(d, &(net)->dev_base_head, dev_list) |
1301 | #define for_each_netdev_reverse(net, d) \ | 1305 | #define for_each_netdev_reverse(net, d) \ |
1302 | list_for_each_entry_reverse(d, &(net)->dev_base_head, dev_list) | 1306 | list_for_each_entry_reverse(d, &(net)->dev_base_head, dev_list) |
1303 | #define for_each_netdev_rcu(net, d) \ | 1307 | #define for_each_netdev_rcu(net, d) \ |
1304 | list_for_each_entry_rcu(d, &(net)->dev_base_head, dev_list) | 1308 | list_for_each_entry_rcu(d, &(net)->dev_base_head, dev_list) |
1305 | #define for_each_netdev_safe(net, d, n) \ | 1309 | #define for_each_netdev_safe(net, d, n) \ |
1306 | list_for_each_entry_safe(d, n, &(net)->dev_base_head, dev_list) | 1310 | list_for_each_entry_safe(d, n, &(net)->dev_base_head, dev_list) |
1307 | #define for_each_netdev_continue(net, d) \ | 1311 | #define for_each_netdev_continue(net, d) \ |
1308 | list_for_each_entry_continue(d, &(net)->dev_base_head, dev_list) | 1312 | list_for_each_entry_continue(d, &(net)->dev_base_head, dev_list) |
1309 | #define for_each_netdev_continue_rcu(net, d) \ | 1313 | #define for_each_netdev_continue_rcu(net, d) \ |
1310 | list_for_each_entry_continue_rcu(d, &(net)->dev_base_head, dev_list) | 1314 | list_for_each_entry_continue_rcu(d, &(net)->dev_base_head, dev_list) |
1311 | #define net_device_entry(lh) list_entry(lh, struct net_device, dev_list) | 1315 | #define net_device_entry(lh) list_entry(lh, struct net_device, dev_list) |
1312 | 1316 | ||
1313 | static inline struct net_device *next_net_device(struct net_device *dev) | 1317 | static inline struct net_device *next_net_device(struct net_device *dev) |
1314 | { | 1318 | { |
1315 | struct list_head *lh; | 1319 | struct list_head *lh; |
1316 | struct net *net; | 1320 | struct net *net; |
1317 | 1321 | ||
1318 | net = dev_net(dev); | 1322 | net = dev_net(dev); |
1319 | lh = dev->dev_list.next; | 1323 | lh = dev->dev_list.next; |
1320 | return lh == &net->dev_base_head ? NULL : net_device_entry(lh); | 1324 | return lh == &net->dev_base_head ? NULL : net_device_entry(lh); |
1321 | } | 1325 | } |
1322 | 1326 | ||
1323 | static inline struct net_device *next_net_device_rcu(struct net_device *dev) | 1327 | static inline struct net_device *next_net_device_rcu(struct net_device *dev) |
1324 | { | 1328 | { |
1325 | struct list_head *lh; | 1329 | struct list_head *lh; |
1326 | struct net *net; | 1330 | struct net *net; |
1327 | 1331 | ||
1328 | net = dev_net(dev); | 1332 | net = dev_net(dev); |
1329 | lh = rcu_dereference(dev->dev_list.next); | 1333 | lh = rcu_dereference(dev->dev_list.next); |
1330 | return lh == &net->dev_base_head ? NULL : net_device_entry(lh); | 1334 | return lh == &net->dev_base_head ? NULL : net_device_entry(lh); |
1331 | } | 1335 | } |
1332 | 1336 | ||
1333 | static inline struct net_device *first_net_device(struct net *net) | 1337 | static inline struct net_device *first_net_device(struct net *net) |
1334 | { | 1338 | { |
1335 | return list_empty(&net->dev_base_head) ? NULL : | 1339 | return list_empty(&net->dev_base_head) ? NULL : |
1336 | net_device_entry(net->dev_base_head.next); | 1340 | net_device_entry(net->dev_base_head.next); |
1337 | } | 1341 | } |
1338 | 1342 | ||
1339 | extern int netdev_boot_setup_check(struct net_device *dev); | 1343 | extern int netdev_boot_setup_check(struct net_device *dev); |
1340 | extern unsigned long netdev_boot_base(const char *prefix, int unit); | 1344 | extern unsigned long netdev_boot_base(const char *prefix, int unit); |
1341 | extern struct net_device *dev_getbyhwaddr(struct net *net, unsigned short type, char *hwaddr); | 1345 | extern struct net_device *dev_getbyhwaddr(struct net *net, unsigned short type, char *hwaddr); |
1342 | extern struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type); | 1346 | extern struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type); |
1343 | extern struct net_device *__dev_getfirstbyhwtype(struct net *net, unsigned short type); | 1347 | extern struct net_device *__dev_getfirstbyhwtype(struct net *net, unsigned short type); |
1344 | extern void dev_add_pack(struct packet_type *pt); | 1348 | extern void dev_add_pack(struct packet_type *pt); |
1345 | extern void dev_remove_pack(struct packet_type *pt); | 1349 | extern void dev_remove_pack(struct packet_type *pt); |
1346 | extern void __dev_remove_pack(struct packet_type *pt); | 1350 | extern void __dev_remove_pack(struct packet_type *pt); |
1347 | 1351 | ||
1348 | extern struct net_device *dev_get_by_flags_rcu(struct net *net, unsigned short flags, | 1352 | extern struct net_device *dev_get_by_flags_rcu(struct net *net, unsigned short flags, |
1349 | unsigned short mask); | 1353 | unsigned short mask); |
1350 | extern struct net_device *dev_get_by_name(struct net *net, const char *name); | 1354 | extern struct net_device *dev_get_by_name(struct net *net, const char *name); |
1351 | extern struct net_device *dev_get_by_name_rcu(struct net *net, const char *name); | 1355 | extern struct net_device *dev_get_by_name_rcu(struct net *net, const char *name); |
1352 | extern struct net_device *__dev_get_by_name(struct net *net, const char *name); | 1356 | extern struct net_device *__dev_get_by_name(struct net *net, const char *name); |
1353 | extern int dev_alloc_name(struct net_device *dev, const char *name); | 1357 | extern int dev_alloc_name(struct net_device *dev, const char *name); |
1354 | extern int dev_open(struct net_device *dev); | 1358 | extern int dev_open(struct net_device *dev); |
1355 | extern int dev_close(struct net_device *dev); | 1359 | extern int dev_close(struct net_device *dev); |
1356 | extern void dev_disable_lro(struct net_device *dev); | 1360 | extern void dev_disable_lro(struct net_device *dev); |
1357 | extern int dev_queue_xmit(struct sk_buff *skb); | 1361 | extern int dev_queue_xmit(struct sk_buff *skb); |
1358 | extern int register_netdevice(struct net_device *dev); | 1362 | extern int register_netdevice(struct net_device *dev); |
1359 | extern void unregister_netdevice_queue(struct net_device *dev, | 1363 | extern void unregister_netdevice_queue(struct net_device *dev, |
1360 | struct list_head *head); | 1364 | struct list_head *head); |
1361 | extern void unregister_netdevice_many(struct list_head *head); | 1365 | extern void unregister_netdevice_many(struct list_head *head); |
1362 | static inline void unregister_netdevice(struct net_device *dev) | 1366 | static inline void unregister_netdevice(struct net_device *dev) |
1363 | { | 1367 | { |
1364 | unregister_netdevice_queue(dev, NULL); | 1368 | unregister_netdevice_queue(dev, NULL); |
1365 | } | 1369 | } |
1366 | 1370 | ||
1367 | extern int netdev_refcnt_read(const struct net_device *dev); | 1371 | extern int netdev_refcnt_read(const struct net_device *dev); |
1368 | extern void free_netdev(struct net_device *dev); | 1372 | extern void free_netdev(struct net_device *dev); |
1369 | extern void synchronize_net(void); | 1373 | extern void synchronize_net(void); |
1370 | extern int register_netdevice_notifier(struct notifier_block *nb); | 1374 | extern int register_netdevice_notifier(struct notifier_block *nb); |
1371 | extern int unregister_netdevice_notifier(struct notifier_block *nb); | 1375 | extern int unregister_netdevice_notifier(struct notifier_block *nb); |
1372 | extern int init_dummy_netdev(struct net_device *dev); | 1376 | extern int init_dummy_netdev(struct net_device *dev); |
1373 | extern void netdev_resync_ops(struct net_device *dev); | 1377 | extern void netdev_resync_ops(struct net_device *dev); |
1374 | 1378 | ||
1375 | extern int call_netdevice_notifiers(unsigned long val, struct net_device *dev); | 1379 | extern int call_netdevice_notifiers(unsigned long val, struct net_device *dev); |
1376 | extern struct net_device *dev_get_by_index(struct net *net, int ifindex); | 1380 | extern struct net_device *dev_get_by_index(struct net *net, int ifindex); |
1377 | extern struct net_device *__dev_get_by_index(struct net *net, int ifindex); | 1381 | extern struct net_device *__dev_get_by_index(struct net *net, int ifindex); |
1378 | extern struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex); | 1382 | extern struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex); |
1379 | extern int dev_restart(struct net_device *dev); | 1383 | extern int dev_restart(struct net_device *dev); |
1380 | #ifdef CONFIG_NETPOLL_TRAP | 1384 | #ifdef CONFIG_NETPOLL_TRAP |
1381 | extern int netpoll_trap(void); | 1385 | extern int netpoll_trap(void); |
1382 | #endif | 1386 | #endif |
1383 | extern int skb_gro_receive(struct sk_buff **head, | 1387 | extern int skb_gro_receive(struct sk_buff **head, |
1384 | struct sk_buff *skb); | 1388 | struct sk_buff *skb); |
1385 | extern void skb_gro_reset_offset(struct sk_buff *skb); | 1389 | extern void skb_gro_reset_offset(struct sk_buff *skb); |
1386 | 1390 | ||
1387 | static inline unsigned int skb_gro_offset(const struct sk_buff *skb) | 1391 | static inline unsigned int skb_gro_offset(const struct sk_buff *skb) |
1388 | { | 1392 | { |
1389 | return NAPI_GRO_CB(skb)->data_offset; | 1393 | return NAPI_GRO_CB(skb)->data_offset; |
1390 | } | 1394 | } |
1391 | 1395 | ||
1392 | static inline unsigned int skb_gro_len(const struct sk_buff *skb) | 1396 | static inline unsigned int skb_gro_len(const struct sk_buff *skb) |
1393 | { | 1397 | { |
1394 | return skb->len - NAPI_GRO_CB(skb)->data_offset; | 1398 | return skb->len - NAPI_GRO_CB(skb)->data_offset; |
1395 | } | 1399 | } |
1396 | 1400 | ||
1397 | static inline void skb_gro_pull(struct sk_buff *skb, unsigned int len) | 1401 | static inline void skb_gro_pull(struct sk_buff *skb, unsigned int len) |
1398 | { | 1402 | { |
1399 | NAPI_GRO_CB(skb)->data_offset += len; | 1403 | NAPI_GRO_CB(skb)->data_offset += len; |
1400 | } | 1404 | } |
1401 | 1405 | ||
1402 | static inline void *skb_gro_header_fast(struct sk_buff *skb, | 1406 | static inline void *skb_gro_header_fast(struct sk_buff *skb, |
1403 | unsigned int offset) | 1407 | unsigned int offset) |
1404 | { | 1408 | { |
1405 | return NAPI_GRO_CB(skb)->frag0 + offset; | 1409 | return NAPI_GRO_CB(skb)->frag0 + offset; |
1406 | } | 1410 | } |
1407 | 1411 | ||
1408 | static inline int skb_gro_header_hard(struct sk_buff *skb, unsigned int hlen) | 1412 | static inline int skb_gro_header_hard(struct sk_buff *skb, unsigned int hlen) |
1409 | { | 1413 | { |
1410 | return NAPI_GRO_CB(skb)->frag0_len < hlen; | 1414 | return NAPI_GRO_CB(skb)->frag0_len < hlen; |
1411 | } | 1415 | } |
1412 | 1416 | ||
1413 | static inline void *skb_gro_header_slow(struct sk_buff *skb, unsigned int hlen, | 1417 | static inline void *skb_gro_header_slow(struct sk_buff *skb, unsigned int hlen, |
1414 | unsigned int offset) | 1418 | unsigned int offset) |
1415 | { | 1419 | { |
1416 | NAPI_GRO_CB(skb)->frag0 = NULL; | 1420 | NAPI_GRO_CB(skb)->frag0 = NULL; |
1417 | NAPI_GRO_CB(skb)->frag0_len = 0; | 1421 | NAPI_GRO_CB(skb)->frag0_len = 0; |
1418 | return pskb_may_pull(skb, hlen) ? skb->data + offset : NULL; | 1422 | return pskb_may_pull(skb, hlen) ? skb->data + offset : NULL; |
1419 | } | 1423 | } |
1420 | 1424 | ||
1421 | static inline void *skb_gro_mac_header(struct sk_buff *skb) | 1425 | static inline void *skb_gro_mac_header(struct sk_buff *skb) |
1422 | { | 1426 | { |
1423 | return NAPI_GRO_CB(skb)->frag0 ?: skb_mac_header(skb); | 1427 | return NAPI_GRO_CB(skb)->frag0 ?: skb_mac_header(skb); |
1424 | } | 1428 | } |
1425 | 1429 | ||
1426 | static inline void *skb_gro_network_header(struct sk_buff *skb) | 1430 | static inline void *skb_gro_network_header(struct sk_buff *skb) |
1427 | { | 1431 | { |
1428 | return (NAPI_GRO_CB(skb)->frag0 ?: skb->data) + | 1432 | return (NAPI_GRO_CB(skb)->frag0 ?: skb->data) + |
1429 | skb_network_offset(skb); | 1433 | skb_network_offset(skb); |
1430 | } | 1434 | } |
1431 | 1435 | ||
1432 | static inline int dev_hard_header(struct sk_buff *skb, struct net_device *dev, | 1436 | static inline int dev_hard_header(struct sk_buff *skb, struct net_device *dev, |
1433 | unsigned short type, | 1437 | unsigned short type, |
1434 | const void *daddr, const void *saddr, | 1438 | const void *daddr, const void *saddr, |
1435 | unsigned len) | 1439 | unsigned len) |
1436 | { | 1440 | { |
1437 | if (!dev->header_ops || !dev->header_ops->create) | 1441 | if (!dev->header_ops || !dev->header_ops->create) |
1438 | return 0; | 1442 | return 0; |
1439 | 1443 | ||
1440 | return dev->header_ops->create(skb, dev, type, daddr, saddr, len); | 1444 | return dev->header_ops->create(skb, dev, type, daddr, saddr, len); |
1441 | } | 1445 | } |
1442 | 1446 | ||
1443 | static inline int dev_parse_header(const struct sk_buff *skb, | 1447 | static inline int dev_parse_header(const struct sk_buff *skb, |
1444 | unsigned char *haddr) | 1448 | unsigned char *haddr) |
1445 | { | 1449 | { |
1446 | const struct net_device *dev = skb->dev; | 1450 | const struct net_device *dev = skb->dev; |
1447 | 1451 | ||
1448 | if (!dev->header_ops || !dev->header_ops->parse) | 1452 | if (!dev->header_ops || !dev->header_ops->parse) |
1449 | return 0; | 1453 | return 0; |
1450 | return dev->header_ops->parse(skb, haddr); | 1454 | return dev->header_ops->parse(skb, haddr); |
1451 | } | 1455 | } |
1452 | 1456 | ||
1453 | typedef int gifconf_func_t(struct net_device * dev, char __user * bufptr, int len); | 1457 | typedef int gifconf_func_t(struct net_device * dev, char __user * bufptr, int len); |
1454 | extern int register_gifconf(unsigned int family, gifconf_func_t * gifconf); | 1458 | extern int register_gifconf(unsigned int family, gifconf_func_t * gifconf); |
1455 | static inline int unregister_gifconf(unsigned int family) | 1459 | static inline int unregister_gifconf(unsigned int family) |
1456 | { | 1460 | { |
1457 | return register_gifconf(family, NULL); | 1461 | return register_gifconf(family, NULL); |
1458 | } | 1462 | } |
1459 | 1463 | ||
1460 | /* | 1464 | /* |
1461 | * Incoming packets are placed on per-cpu queues | 1465 | * Incoming packets are placed on per-cpu queues |
1462 | */ | 1466 | */ |
1463 | struct softnet_data { | 1467 | struct softnet_data { |
1464 | struct Qdisc *output_queue; | 1468 | struct Qdisc *output_queue; |
1465 | struct Qdisc **output_queue_tailp; | 1469 | struct Qdisc **output_queue_tailp; |
1466 | struct list_head poll_list; | 1470 | struct list_head poll_list; |
1467 | struct sk_buff *completion_queue; | 1471 | struct sk_buff *completion_queue; |
1468 | struct sk_buff_head process_queue; | 1472 | struct sk_buff_head process_queue; |
1469 | 1473 | ||
1470 | /* stats */ | 1474 | /* stats */ |
1471 | unsigned int processed; | 1475 | unsigned int processed; |
1472 | unsigned int time_squeeze; | 1476 | unsigned int time_squeeze; |
1473 | unsigned int cpu_collision; | 1477 | unsigned int cpu_collision; |
1474 | unsigned int received_rps; | 1478 | unsigned int received_rps; |
1475 | 1479 | ||
1476 | #ifdef CONFIG_RPS | 1480 | #ifdef CONFIG_RPS |
1477 | struct softnet_data *rps_ipi_list; | 1481 | struct softnet_data *rps_ipi_list; |
1478 | 1482 | ||
1479 | /* Elements below can be accessed between CPUs for RPS */ | 1483 | /* Elements below can be accessed between CPUs for RPS */ |
1480 | struct call_single_data csd ____cacheline_aligned_in_smp; | 1484 | struct call_single_data csd ____cacheline_aligned_in_smp; |
1481 | struct softnet_data *rps_ipi_next; | 1485 | struct softnet_data *rps_ipi_next; |
1482 | unsigned int cpu; | 1486 | unsigned int cpu; |
1483 | unsigned int input_queue_head; | 1487 | unsigned int input_queue_head; |
1484 | unsigned int input_queue_tail; | 1488 | unsigned int input_queue_tail; |
1485 | #endif | 1489 | #endif |
1486 | unsigned dropped; | 1490 | unsigned dropped; |
1487 | struct sk_buff_head input_pkt_queue; | 1491 | struct sk_buff_head input_pkt_queue; |
1488 | struct napi_struct backlog; | 1492 | struct napi_struct backlog; |
1489 | }; | 1493 | }; |
1490 | 1494 | ||
1491 | static inline void input_queue_head_incr(struct softnet_data *sd) | 1495 | static inline void input_queue_head_incr(struct softnet_data *sd) |
1492 | { | 1496 | { |
1493 | #ifdef CONFIG_RPS | 1497 | #ifdef CONFIG_RPS |
1494 | sd->input_queue_head++; | 1498 | sd->input_queue_head++; |
1495 | #endif | 1499 | #endif |
1496 | } | 1500 | } |
1497 | 1501 | ||
1498 | static inline void input_queue_tail_incr_save(struct softnet_data *sd, | 1502 | static inline void input_queue_tail_incr_save(struct softnet_data *sd, |
1499 | unsigned int *qtail) | 1503 | unsigned int *qtail) |
1500 | { | 1504 | { |
1501 | #ifdef CONFIG_RPS | 1505 | #ifdef CONFIG_RPS |
1502 | *qtail = ++sd->input_queue_tail; | 1506 | *qtail = ++sd->input_queue_tail; |
1503 | #endif | 1507 | #endif |
1504 | } | 1508 | } |
1505 | 1509 | ||
1506 | DECLARE_PER_CPU_ALIGNED(struct softnet_data, softnet_data); | 1510 | DECLARE_PER_CPU_ALIGNED(struct softnet_data, softnet_data); |
1507 | 1511 | ||
1508 | #define HAVE_NETIF_QUEUE | 1512 | #define HAVE_NETIF_QUEUE |
1509 | 1513 | ||
1510 | extern void __netif_schedule(struct Qdisc *q); | 1514 | extern void __netif_schedule(struct Qdisc *q); |
1511 | 1515 | ||
1512 | static inline void netif_schedule_queue(struct netdev_queue *txq) | 1516 | static inline void netif_schedule_queue(struct netdev_queue *txq) |
1513 | { | 1517 | { |
1514 | if (!test_bit(__QUEUE_STATE_XOFF, &txq->state)) | 1518 | if (!test_bit(__QUEUE_STATE_XOFF, &txq->state)) |
1515 | __netif_schedule(txq->qdisc); | 1519 | __netif_schedule(txq->qdisc); |
1516 | } | 1520 | } |
1517 | 1521 | ||
1518 | static inline void netif_tx_schedule_all(struct net_device *dev) | 1522 | static inline void netif_tx_schedule_all(struct net_device *dev) |
1519 | { | 1523 | { |
1520 | unsigned int i; | 1524 | unsigned int i; |
1521 | 1525 | ||
1522 | for (i = 0; i < dev->num_tx_queues; i++) | 1526 | for (i = 0; i < dev->num_tx_queues; i++) |
1523 | netif_schedule_queue(netdev_get_tx_queue(dev, i)); | 1527 | netif_schedule_queue(netdev_get_tx_queue(dev, i)); |
1524 | } | 1528 | } |
1525 | 1529 | ||
1526 | static inline void netif_tx_start_queue(struct netdev_queue *dev_queue) | 1530 | static inline void netif_tx_start_queue(struct netdev_queue *dev_queue) |
1527 | { | 1531 | { |
1528 | clear_bit(__QUEUE_STATE_XOFF, &dev_queue->state); | 1532 | clear_bit(__QUEUE_STATE_XOFF, &dev_queue->state); |
1529 | } | 1533 | } |
1530 | 1534 | ||
1531 | /** | 1535 | /** |
1532 | * netif_start_queue - allow transmit | 1536 | * netif_start_queue - allow transmit |
1533 | * @dev: network device | 1537 | * @dev: network device |
1534 | * | 1538 | * |
1535 | * Allow upper layers to call the device hard_start_xmit routine. | 1539 | * Allow upper layers to call the device hard_start_xmit routine. |
1536 | */ | 1540 | */ |
1537 | static inline void netif_start_queue(struct net_device *dev) | 1541 | static inline void netif_start_queue(struct net_device *dev) |
1538 | { | 1542 | { |
1539 | netif_tx_start_queue(netdev_get_tx_queue(dev, 0)); | 1543 | netif_tx_start_queue(netdev_get_tx_queue(dev, 0)); |
1540 | } | 1544 | } |
1541 | 1545 | ||
1542 | static inline void netif_tx_start_all_queues(struct net_device *dev) | 1546 | static inline void netif_tx_start_all_queues(struct net_device *dev) |
1543 | { | 1547 | { |
1544 | unsigned int i; | 1548 | unsigned int i; |
1545 | 1549 | ||
1546 | for (i = 0; i < dev->num_tx_queues; i++) { | 1550 | for (i = 0; i < dev->num_tx_queues; i++) { |
1547 | struct netdev_queue *txq = netdev_get_tx_queue(dev, i); | 1551 | struct netdev_queue *txq = netdev_get_tx_queue(dev, i); |
1548 | netif_tx_start_queue(txq); | 1552 | netif_tx_start_queue(txq); |
1549 | } | 1553 | } |
1550 | } | 1554 | } |
1551 | 1555 | ||
1552 | static inline void netif_tx_wake_queue(struct netdev_queue *dev_queue) | 1556 | static inline void netif_tx_wake_queue(struct netdev_queue *dev_queue) |
1553 | { | 1557 | { |
1554 | #ifdef CONFIG_NETPOLL_TRAP | 1558 | #ifdef CONFIG_NETPOLL_TRAP |
1555 | if (netpoll_trap()) { | 1559 | if (netpoll_trap()) { |
1556 | netif_tx_start_queue(dev_queue); | 1560 | netif_tx_start_queue(dev_queue); |
1557 | return; | 1561 | return; |
1558 | } | 1562 | } |
1559 | #endif | 1563 | #endif |
1560 | if (test_and_clear_bit(__QUEUE_STATE_XOFF, &dev_queue->state)) | 1564 | if (test_and_clear_bit(__QUEUE_STATE_XOFF, &dev_queue->state)) |
1561 | __netif_schedule(dev_queue->qdisc); | 1565 | __netif_schedule(dev_queue->qdisc); |
1562 | } | 1566 | } |
1563 | 1567 | ||
1564 | /** | 1568 | /** |
1565 | * netif_wake_queue - restart transmit | 1569 | * netif_wake_queue - restart transmit |
1566 | * @dev: network device | 1570 | * @dev: network device |
1567 | * | 1571 | * |
1568 | * Allow upper layers to call the device hard_start_xmit routine. | 1572 | * Allow upper layers to call the device hard_start_xmit routine. |
1569 | * Used for flow control when transmit resources are available. | 1573 | * Used for flow control when transmit resources are available. |
1570 | */ | 1574 | */ |
1571 | static inline void netif_wake_queue(struct net_device *dev) | 1575 | static inline void netif_wake_queue(struct net_device *dev) |
1572 | { | 1576 | { |
1573 | netif_tx_wake_queue(netdev_get_tx_queue(dev, 0)); | 1577 | netif_tx_wake_queue(netdev_get_tx_queue(dev, 0)); |
1574 | } | 1578 | } |
1575 | 1579 | ||
1576 | static inline void netif_tx_wake_all_queues(struct net_device *dev) | 1580 | static inline void netif_tx_wake_all_queues(struct net_device *dev) |
1577 | { | 1581 | { |
1578 | unsigned int i; | 1582 | unsigned int i; |
1579 | 1583 | ||
1580 | for (i = 0; i < dev->num_tx_queues; i++) { | 1584 | for (i = 0; i < dev->num_tx_queues; i++) { |
1581 | struct netdev_queue *txq = netdev_get_tx_queue(dev, i); | 1585 | struct netdev_queue *txq = netdev_get_tx_queue(dev, i); |
1582 | netif_tx_wake_queue(txq); | 1586 | netif_tx_wake_queue(txq); |
1583 | } | 1587 | } |
1584 | } | 1588 | } |
1585 | 1589 | ||
1586 | static inline void netif_tx_stop_queue(struct netdev_queue *dev_queue) | 1590 | static inline void netif_tx_stop_queue(struct netdev_queue *dev_queue) |
1587 | { | 1591 | { |
1588 | if (WARN_ON(!dev_queue)) { | 1592 | if (WARN_ON(!dev_queue)) { |
1589 | printk(KERN_INFO "netif_stop_queue() cannot be called before " | 1593 | printk(KERN_INFO "netif_stop_queue() cannot be called before " |
1590 | "register_netdev()"); | 1594 | "register_netdev()"); |
1591 | return; | 1595 | return; |
1592 | } | 1596 | } |
1593 | set_bit(__QUEUE_STATE_XOFF, &dev_queue->state); | 1597 | set_bit(__QUEUE_STATE_XOFF, &dev_queue->state); |
1594 | } | 1598 | } |
1595 | 1599 | ||
1596 | /** | 1600 | /** |
1597 | * netif_stop_queue - stop transmitted packets | 1601 | * netif_stop_queue - stop transmitted packets |
1598 | * @dev: network device | 1602 | * @dev: network device |
1599 | * | 1603 | * |
1600 | * Stop upper layers calling the device hard_start_xmit routine. | 1604 | * Stop upper layers calling the device hard_start_xmit routine. |
1601 | * Used for flow control when transmit resources are unavailable. | 1605 | * Used for flow control when transmit resources are unavailable. |
1602 | */ | 1606 | */ |
1603 | static inline void netif_stop_queue(struct net_device *dev) | 1607 | static inline void netif_stop_queue(struct net_device *dev) |
1604 | { | 1608 | { |
1605 | netif_tx_stop_queue(netdev_get_tx_queue(dev, 0)); | 1609 | netif_tx_stop_queue(netdev_get_tx_queue(dev, 0)); |
1606 | } | 1610 | } |
1607 | 1611 | ||
1608 | static inline void netif_tx_stop_all_queues(struct net_device *dev) | 1612 | static inline void netif_tx_stop_all_queues(struct net_device *dev) |
1609 | { | 1613 | { |
1610 | unsigned int i; | 1614 | unsigned int i; |
1611 | 1615 | ||
1612 | for (i = 0; i < dev->num_tx_queues; i++) { | 1616 | for (i = 0; i < dev->num_tx_queues; i++) { |
1613 | struct netdev_queue *txq = netdev_get_tx_queue(dev, i); | 1617 | struct netdev_queue *txq = netdev_get_tx_queue(dev, i); |
1614 | netif_tx_stop_queue(txq); | 1618 | netif_tx_stop_queue(txq); |
1615 | } | 1619 | } |
1616 | } | 1620 | } |
1617 | 1621 | ||
1618 | static inline int netif_tx_queue_stopped(const struct netdev_queue *dev_queue) | 1622 | static inline int netif_tx_queue_stopped(const struct netdev_queue *dev_queue) |
1619 | { | 1623 | { |
1620 | return test_bit(__QUEUE_STATE_XOFF, &dev_queue->state); | 1624 | return test_bit(__QUEUE_STATE_XOFF, &dev_queue->state); |
1621 | } | 1625 | } |
1622 | 1626 | ||
1623 | /** | 1627 | /** |
1624 | * netif_queue_stopped - test if transmit queue is flowblocked | 1628 | * netif_queue_stopped - test if transmit queue is flowblocked |
1625 | * @dev: network device | 1629 | * @dev: network device |
1626 | * | 1630 | * |
1627 | * Test if transmit queue on device is currently unable to send. | 1631 | * Test if transmit queue on device is currently unable to send. |
1628 | */ | 1632 | */ |
1629 | static inline int netif_queue_stopped(const struct net_device *dev) | 1633 | static inline int netif_queue_stopped(const struct net_device *dev) |
1630 | { | 1634 | { |
1631 | return netif_tx_queue_stopped(netdev_get_tx_queue(dev, 0)); | 1635 | return netif_tx_queue_stopped(netdev_get_tx_queue(dev, 0)); |
1632 | } | 1636 | } |
1633 | 1637 | ||
1634 | static inline int netif_tx_queue_frozen_or_stopped(const struct netdev_queue *dev_queue) | 1638 | static inline int netif_tx_queue_frozen_or_stopped(const struct netdev_queue *dev_queue) |
1635 | { | 1639 | { |
1636 | return dev_queue->state & QUEUE_STATE_XOFF_OR_FROZEN; | 1640 | return dev_queue->state & QUEUE_STATE_XOFF_OR_FROZEN; |
1637 | } | 1641 | } |
1638 | 1642 | ||
1639 | /** | 1643 | /** |
1640 | * netif_running - test if up | 1644 | * netif_running - test if up |
1641 | * @dev: network device | 1645 | * @dev: network device |
1642 | * | 1646 | * |
1643 | * Test if the device has been brought up. | 1647 | * Test if the device has been brought up. |
1644 | */ | 1648 | */ |
1645 | static inline int netif_running(const struct net_device *dev) | 1649 | static inline int netif_running(const struct net_device *dev) |
1646 | { | 1650 | { |
1647 | return test_bit(__LINK_STATE_START, &dev->state); | 1651 | return test_bit(__LINK_STATE_START, &dev->state); |
1648 | } | 1652 | } |
1649 | 1653 | ||
1650 | /* | 1654 | /* |
1651 | * Routines to manage the subqueues on a device. We only need start | 1655 | * Routines to manage the subqueues on a device. We only need start |
1652 | * stop, and a check if it's stopped. All other device management is | 1656 | * stop, and a check if it's stopped. All other device management is |
1653 | * done at the overall netdevice level. | 1657 | * done at the overall netdevice level. |
1654 | * Also test the device if we're multiqueue. | 1658 | * Also test the device if we're multiqueue. |
1655 | */ | 1659 | */ |
1656 | 1660 | ||
1657 | /** | 1661 | /** |
1658 | * netif_start_subqueue - allow sending packets on subqueue | 1662 | * netif_start_subqueue - allow sending packets on subqueue |
1659 | * @dev: network device | 1663 | * @dev: network device |
1660 | * @queue_index: sub queue index | 1664 | * @queue_index: sub queue index |
1661 | * | 1665 | * |
1662 | * Start individual transmit queue of a device with multiple transmit queues. | 1666 | * Start individual transmit queue of a device with multiple transmit queues. |
1663 | */ | 1667 | */ |
1664 | static inline void netif_start_subqueue(struct net_device *dev, u16 queue_index) | 1668 | static inline void netif_start_subqueue(struct net_device *dev, u16 queue_index) |
1665 | { | 1669 | { |
1666 | struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index); | 1670 | struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index); |
1667 | 1671 | ||
1668 | netif_tx_start_queue(txq); | 1672 | netif_tx_start_queue(txq); |
1669 | } | 1673 | } |
1670 | 1674 | ||
1671 | /** | 1675 | /** |
1672 | * netif_stop_subqueue - stop sending packets on subqueue | 1676 | * netif_stop_subqueue - stop sending packets on subqueue |
1673 | * @dev: network device | 1677 | * @dev: network device |
1674 | * @queue_index: sub queue index | 1678 | * @queue_index: sub queue index |
1675 | * | 1679 | * |
1676 | * Stop individual transmit queue of a device with multiple transmit queues. | 1680 | * Stop individual transmit queue of a device with multiple transmit queues. |
1677 | */ | 1681 | */ |
1678 | static inline void netif_stop_subqueue(struct net_device *dev, u16 queue_index) | 1682 | static inline void netif_stop_subqueue(struct net_device *dev, u16 queue_index) |
1679 | { | 1683 | { |
1680 | struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index); | 1684 | struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index); |
1681 | #ifdef CONFIG_NETPOLL_TRAP | 1685 | #ifdef CONFIG_NETPOLL_TRAP |
1682 | if (netpoll_trap()) | 1686 | if (netpoll_trap()) |
1683 | return; | 1687 | return; |
1684 | #endif | 1688 | #endif |
1685 | netif_tx_stop_queue(txq); | 1689 | netif_tx_stop_queue(txq); |
1686 | } | 1690 | } |
1687 | 1691 | ||
1688 | /** | 1692 | /** |
1689 | * netif_subqueue_stopped - test status of subqueue | 1693 | * netif_subqueue_stopped - test status of subqueue |
1690 | * @dev: network device | 1694 | * @dev: network device |
1691 | * @queue_index: sub queue index | 1695 | * @queue_index: sub queue index |
1692 | * | 1696 | * |
1693 | * Check individual transmit queue of a device with multiple transmit queues. | 1697 | * Check individual transmit queue of a device with multiple transmit queues. |
1694 | */ | 1698 | */ |
1695 | static inline int __netif_subqueue_stopped(const struct net_device *dev, | 1699 | static inline int __netif_subqueue_stopped(const struct net_device *dev, |
1696 | u16 queue_index) | 1700 | u16 queue_index) |
1697 | { | 1701 | { |
1698 | struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index); | 1702 | struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index); |
1699 | 1703 | ||
1700 | return netif_tx_queue_stopped(txq); | 1704 | return netif_tx_queue_stopped(txq); |
1701 | } | 1705 | } |
1702 | 1706 | ||
1703 | static inline int netif_subqueue_stopped(const struct net_device *dev, | 1707 | static inline int netif_subqueue_stopped(const struct net_device *dev, |
1704 | struct sk_buff *skb) | 1708 | struct sk_buff *skb) |
1705 | { | 1709 | { |
1706 | return __netif_subqueue_stopped(dev, skb_get_queue_mapping(skb)); | 1710 | return __netif_subqueue_stopped(dev, skb_get_queue_mapping(skb)); |
1707 | } | 1711 | } |
1708 | 1712 | ||
1709 | /** | 1713 | /** |
1710 | * netif_wake_subqueue - allow sending packets on subqueue | 1714 | * netif_wake_subqueue - allow sending packets on subqueue |
1711 | * @dev: network device | 1715 | * @dev: network device |
1712 | * @queue_index: sub queue index | 1716 | * @queue_index: sub queue index |
1713 | * | 1717 | * |
1714 | * Resume individual transmit queue of a device with multiple transmit queues. | 1718 | * Resume individual transmit queue of a device with multiple transmit queues. |
1715 | */ | 1719 | */ |
1716 | static inline void netif_wake_subqueue(struct net_device *dev, u16 queue_index) | 1720 | static inline void netif_wake_subqueue(struct net_device *dev, u16 queue_index) |
1717 | { | 1721 | { |
1718 | struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index); | 1722 | struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index); |
1719 | #ifdef CONFIG_NETPOLL_TRAP | 1723 | #ifdef CONFIG_NETPOLL_TRAP |
1720 | if (netpoll_trap()) | 1724 | if (netpoll_trap()) |
1721 | return; | 1725 | return; |
1722 | #endif | 1726 | #endif |
1723 | if (test_and_clear_bit(__QUEUE_STATE_XOFF, &txq->state)) | 1727 | if (test_and_clear_bit(__QUEUE_STATE_XOFF, &txq->state)) |
1724 | __netif_schedule(txq->qdisc); | 1728 | __netif_schedule(txq->qdisc); |
1725 | } | 1729 | } |
1726 | 1730 | ||
1727 | /** | 1731 | /** |
1728 | * netif_is_multiqueue - test if device has multiple transmit queues | 1732 | * netif_is_multiqueue - test if device has multiple transmit queues |
1729 | * @dev: network device | 1733 | * @dev: network device |
1730 | * | 1734 | * |
1731 | * Check if device has multiple transmit queues | 1735 | * Check if device has multiple transmit queues |
1732 | */ | 1736 | */ |
1733 | static inline int netif_is_multiqueue(const struct net_device *dev) | 1737 | static inline int netif_is_multiqueue(const struct net_device *dev) |
1734 | { | 1738 | { |
1735 | return dev->num_tx_queues > 1; | 1739 | return dev->num_tx_queues > 1; |
1736 | } | 1740 | } |
1737 | 1741 | ||
1738 | extern int netif_set_real_num_tx_queues(struct net_device *dev, | 1742 | extern int netif_set_real_num_tx_queues(struct net_device *dev, |
1739 | unsigned int txq); | 1743 | unsigned int txq); |
1740 | 1744 | ||
1741 | #ifdef CONFIG_RPS | 1745 | #ifdef CONFIG_RPS |
1742 | extern int netif_set_real_num_rx_queues(struct net_device *dev, | 1746 | extern int netif_set_real_num_rx_queues(struct net_device *dev, |
1743 | unsigned int rxq); | 1747 | unsigned int rxq); |
1744 | #else | 1748 | #else |
1745 | static inline int netif_set_real_num_rx_queues(struct net_device *dev, | 1749 | static inline int netif_set_real_num_rx_queues(struct net_device *dev, |
1746 | unsigned int rxq) | 1750 | unsigned int rxq) |
1747 | { | 1751 | { |
1748 | return 0; | 1752 | return 0; |
1749 | } | 1753 | } |
1750 | #endif | 1754 | #endif |
1751 | 1755 | ||
1752 | static inline int netif_copy_real_num_queues(struct net_device *to_dev, | 1756 | static inline int netif_copy_real_num_queues(struct net_device *to_dev, |
1753 | const struct net_device *from_dev) | 1757 | const struct net_device *from_dev) |
1754 | { | 1758 | { |
1755 | netif_set_real_num_tx_queues(to_dev, from_dev->real_num_tx_queues); | 1759 | netif_set_real_num_tx_queues(to_dev, from_dev->real_num_tx_queues); |
1756 | #ifdef CONFIG_RPS | 1760 | #ifdef CONFIG_RPS |
1757 | return netif_set_real_num_rx_queues(to_dev, | 1761 | return netif_set_real_num_rx_queues(to_dev, |
1758 | from_dev->real_num_rx_queues); | 1762 | from_dev->real_num_rx_queues); |
1759 | #else | 1763 | #else |
1760 | return 0; | 1764 | return 0; |
1761 | #endif | 1765 | #endif |
1762 | } | 1766 | } |
1763 | 1767 | ||
1764 | /* Use this variant when it is known for sure that it | 1768 | /* Use this variant when it is known for sure that it |
1765 | * is executing from hardware interrupt context or with hardware interrupts | 1769 | * is executing from hardware interrupt context or with hardware interrupts |
1766 | * disabled. | 1770 | * disabled. |
1767 | */ | 1771 | */ |
1768 | extern void dev_kfree_skb_irq(struct sk_buff *skb); | 1772 | extern void dev_kfree_skb_irq(struct sk_buff *skb); |
1769 | 1773 | ||
1770 | /* Use this variant in places where it could be invoked | 1774 | /* Use this variant in places where it could be invoked |
1771 | * from either hardware interrupt or other context, with hardware interrupts | 1775 | * from either hardware interrupt or other context, with hardware interrupts |
1772 | * either disabled or enabled. | 1776 | * either disabled or enabled. |
1773 | */ | 1777 | */ |
1774 | extern void dev_kfree_skb_any(struct sk_buff *skb); | 1778 | extern void dev_kfree_skb_any(struct sk_buff *skb); |
1775 | 1779 | ||
1776 | #define HAVE_NETIF_RX 1 | 1780 | #define HAVE_NETIF_RX 1 |
1777 | extern int netif_rx(struct sk_buff *skb); | 1781 | extern int netif_rx(struct sk_buff *skb); |
1778 | extern int netif_rx_ni(struct sk_buff *skb); | 1782 | extern int netif_rx_ni(struct sk_buff *skb); |
1779 | #define HAVE_NETIF_RECEIVE_SKB 1 | 1783 | #define HAVE_NETIF_RECEIVE_SKB 1 |
1780 | extern int netif_receive_skb(struct sk_buff *skb); | 1784 | extern int netif_receive_skb(struct sk_buff *skb); |
1781 | extern gro_result_t dev_gro_receive(struct napi_struct *napi, | 1785 | extern gro_result_t dev_gro_receive(struct napi_struct *napi, |
1782 | struct sk_buff *skb); | 1786 | struct sk_buff *skb); |
1783 | extern gro_result_t napi_skb_finish(gro_result_t ret, struct sk_buff *skb); | 1787 | extern gro_result_t napi_skb_finish(gro_result_t ret, struct sk_buff *skb); |
1784 | extern gro_result_t napi_gro_receive(struct napi_struct *napi, | 1788 | extern gro_result_t napi_gro_receive(struct napi_struct *napi, |
1785 | struct sk_buff *skb); | 1789 | struct sk_buff *skb); |
1786 | extern void napi_gro_flush(struct napi_struct *napi); | 1790 | extern void napi_gro_flush(struct napi_struct *napi); |
1787 | extern struct sk_buff * napi_get_frags(struct napi_struct *napi); | 1791 | extern struct sk_buff * napi_get_frags(struct napi_struct *napi); |
1788 | extern gro_result_t napi_frags_finish(struct napi_struct *napi, | 1792 | extern gro_result_t napi_frags_finish(struct napi_struct *napi, |
1789 | struct sk_buff *skb, | 1793 | struct sk_buff *skb, |
1790 | gro_result_t ret); | 1794 | gro_result_t ret); |
1791 | extern struct sk_buff * napi_frags_skb(struct napi_struct *napi); | 1795 | extern struct sk_buff * napi_frags_skb(struct napi_struct *napi); |
1792 | extern gro_result_t napi_gro_frags(struct napi_struct *napi); | 1796 | extern gro_result_t napi_gro_frags(struct napi_struct *napi); |
1793 | 1797 | ||
1794 | static inline void napi_free_frags(struct napi_struct *napi) | 1798 | static inline void napi_free_frags(struct napi_struct *napi) |
1795 | { | 1799 | { |
1796 | kfree_skb(napi->skb); | 1800 | kfree_skb(napi->skb); |
1797 | napi->skb = NULL; | 1801 | napi->skb = NULL; |
1798 | } | 1802 | } |
1799 | 1803 | ||
1800 | extern int netdev_rx_handler_register(struct net_device *dev, | 1804 | extern int netdev_rx_handler_register(struct net_device *dev, |
1801 | rx_handler_func_t *rx_handler, | 1805 | rx_handler_func_t *rx_handler, |
1802 | void *rx_handler_data); | 1806 | void *rx_handler_data); |
1803 | extern void netdev_rx_handler_unregister(struct net_device *dev); | 1807 | extern void netdev_rx_handler_unregister(struct net_device *dev); |
1804 | 1808 | ||
1805 | extern int dev_valid_name(const char *name); | 1809 | extern int dev_valid_name(const char *name); |
1806 | extern int dev_ioctl(struct net *net, unsigned int cmd, void __user *); | 1810 | extern int dev_ioctl(struct net *net, unsigned int cmd, void __user *); |
1807 | extern int dev_ethtool(struct net *net, struct ifreq *); | 1811 | extern int dev_ethtool(struct net *net, struct ifreq *); |
1808 | extern unsigned dev_get_flags(const struct net_device *); | 1812 | extern unsigned dev_get_flags(const struct net_device *); |
1809 | extern int __dev_change_flags(struct net_device *, unsigned int flags); | 1813 | extern int __dev_change_flags(struct net_device *, unsigned int flags); |
1810 | extern int dev_change_flags(struct net_device *, unsigned); | 1814 | extern int dev_change_flags(struct net_device *, unsigned); |
1811 | extern void __dev_notify_flags(struct net_device *, unsigned int old_flags); | 1815 | extern void __dev_notify_flags(struct net_device *, unsigned int old_flags); |
1812 | extern int dev_change_name(struct net_device *, const char *); | 1816 | extern int dev_change_name(struct net_device *, const char *); |
1813 | extern int dev_set_alias(struct net_device *, const char *, size_t); | 1817 | extern int dev_set_alias(struct net_device *, const char *, size_t); |
1814 | extern int dev_change_net_namespace(struct net_device *, | 1818 | extern int dev_change_net_namespace(struct net_device *, |
1815 | struct net *, const char *); | 1819 | struct net *, const char *); |
1816 | extern int dev_set_mtu(struct net_device *, int); | 1820 | extern int dev_set_mtu(struct net_device *, int); |
1817 | extern int dev_set_mac_address(struct net_device *, | 1821 | extern int dev_set_mac_address(struct net_device *, |
1818 | struct sockaddr *); | 1822 | struct sockaddr *); |
1819 | extern int dev_hard_start_xmit(struct sk_buff *skb, | 1823 | extern int dev_hard_start_xmit(struct sk_buff *skb, |
1820 | struct net_device *dev, | 1824 | struct net_device *dev, |
1821 | struct netdev_queue *txq); | 1825 | struct netdev_queue *txq); |
1822 | extern int dev_forward_skb(struct net_device *dev, | 1826 | extern int dev_forward_skb(struct net_device *dev, |
1823 | struct sk_buff *skb); | 1827 | struct sk_buff *skb); |
1824 | 1828 | ||
1825 | extern int netdev_budget; | 1829 | extern int netdev_budget; |
1826 | 1830 | ||
1827 | /* Called by rtnetlink.c:rtnl_unlock() */ | 1831 | /* Called by rtnetlink.c:rtnl_unlock() */ |
1828 | extern void netdev_run_todo(void); | 1832 | extern void netdev_run_todo(void); |
1829 | 1833 | ||
1830 | /** | 1834 | /** |
1831 | * dev_put - release reference to device | 1835 | * dev_put - release reference to device |
1832 | * @dev: network device | 1836 | * @dev: network device |
1833 | * | 1837 | * |
1834 | * Release reference to device to allow it to be freed. | 1838 | * Release reference to device to allow it to be freed. |
1835 | */ | 1839 | */ |
1836 | static inline void dev_put(struct net_device *dev) | 1840 | static inline void dev_put(struct net_device *dev) |
1837 | { | 1841 | { |
1838 | irqsafe_cpu_dec(*dev->pcpu_refcnt); | 1842 | irqsafe_cpu_dec(*dev->pcpu_refcnt); |
1839 | } | 1843 | } |
1840 | 1844 | ||
1841 | /** | 1845 | /** |
1842 | * dev_hold - get reference to device | 1846 | * dev_hold - get reference to device |
1843 | * @dev: network device | 1847 | * @dev: network device |
1844 | * | 1848 | * |
1845 | * Hold reference to device to keep it from being freed. | 1849 | * Hold reference to device to keep it from being freed. |
1846 | */ | 1850 | */ |
1847 | static inline void dev_hold(struct net_device *dev) | 1851 | static inline void dev_hold(struct net_device *dev) |
1848 | { | 1852 | { |
1849 | irqsafe_cpu_inc(*dev->pcpu_refcnt); | 1853 | irqsafe_cpu_inc(*dev->pcpu_refcnt); |
1850 | } | 1854 | } |
1851 | 1855 | ||
1852 | /* Carrier loss detection, dial on demand. The functions netif_carrier_on | 1856 | /* Carrier loss detection, dial on demand. The functions netif_carrier_on |
1853 | * and _off may be called from IRQ context, but it is caller | 1857 | * and _off may be called from IRQ context, but it is caller |
1854 | * who is responsible for serialization of these calls. | 1858 | * who is responsible for serialization of these calls. |
1855 | * | 1859 | * |
1856 | * The name carrier is inappropriate, these functions should really be | 1860 | * The name carrier is inappropriate, these functions should really be |
1857 | * called netif_lowerlayer_*() because they represent the state of any | 1861 | * called netif_lowerlayer_*() because they represent the state of any |
1858 | * kind of lower layer not just hardware media. | 1862 | * kind of lower layer not just hardware media. |
1859 | */ | 1863 | */ |
1860 | 1864 | ||
1861 | extern void linkwatch_fire_event(struct net_device *dev); | 1865 | extern void linkwatch_fire_event(struct net_device *dev); |
1862 | extern void linkwatch_forget_dev(struct net_device *dev); | 1866 | extern void linkwatch_forget_dev(struct net_device *dev); |
1863 | 1867 | ||
1864 | /** | 1868 | /** |
1865 | * netif_carrier_ok - test if carrier present | 1869 | * netif_carrier_ok - test if carrier present |
1866 | * @dev: network device | 1870 | * @dev: network device |
1867 | * | 1871 | * |
1868 | * Check if carrier is present on device | 1872 | * Check if carrier is present on device |
1869 | */ | 1873 | */ |
1870 | static inline int netif_carrier_ok(const struct net_device *dev) | 1874 | static inline int netif_carrier_ok(const struct net_device *dev) |
1871 | { | 1875 | { |
1872 | return !test_bit(__LINK_STATE_NOCARRIER, &dev->state); | 1876 | return !test_bit(__LINK_STATE_NOCARRIER, &dev->state); |
1873 | } | 1877 | } |
1874 | 1878 | ||
1875 | extern unsigned long dev_trans_start(struct net_device *dev); | 1879 | extern unsigned long dev_trans_start(struct net_device *dev); |
1876 | 1880 | ||
1877 | extern void __netdev_watchdog_up(struct net_device *dev); | 1881 | extern void __netdev_watchdog_up(struct net_device *dev); |
1878 | 1882 | ||
1879 | extern void netif_carrier_on(struct net_device *dev); | 1883 | extern void netif_carrier_on(struct net_device *dev); |
1880 | 1884 | ||
1881 | extern void netif_carrier_off(struct net_device *dev); | 1885 | extern void netif_carrier_off(struct net_device *dev); |
1882 | 1886 | ||
1883 | extern void netif_notify_peers(struct net_device *dev); | 1887 | extern void netif_notify_peers(struct net_device *dev); |
1884 | 1888 | ||
1885 | /** | 1889 | /** |
1886 | * netif_dormant_on - mark device as dormant. | 1890 | * netif_dormant_on - mark device as dormant. |
1887 | * @dev: network device | 1891 | * @dev: network device |
1888 | * | 1892 | * |
1889 | * Mark device as dormant (as per RFC2863). | 1893 | * Mark device as dormant (as per RFC2863). |
1890 | * | 1894 | * |
1891 | * The dormant state indicates that the relevant interface is not | 1895 | * The dormant state indicates that the relevant interface is not |
1892 | * actually in a condition to pass packets (i.e., it is not 'up') but is | 1896 | * actually in a condition to pass packets (i.e., it is not 'up') but is |
1893 | * in a "pending" state, waiting for some external event. For "on- | 1897 | * in a "pending" state, waiting for some external event. For "on- |
1894 | * demand" interfaces, this new state identifies the situation where the | 1898 | * demand" interfaces, this new state identifies the situation where the |
1895 | * interface is waiting for events to place it in the up state. | 1899 | * interface is waiting for events to place it in the up state. |
1896 | * | 1900 | * |
1897 | */ | 1901 | */ |
1898 | static inline void netif_dormant_on(struct net_device *dev) | 1902 | static inline void netif_dormant_on(struct net_device *dev) |
1899 | { | 1903 | { |
1900 | if (!test_and_set_bit(__LINK_STATE_DORMANT, &dev->state)) | 1904 | if (!test_and_set_bit(__LINK_STATE_DORMANT, &dev->state)) |
1901 | linkwatch_fire_event(dev); | 1905 | linkwatch_fire_event(dev); |
1902 | } | 1906 | } |
1903 | 1907 | ||
1904 | /** | 1908 | /** |
1905 | * netif_dormant_off - set device as not dormant. | 1909 | * netif_dormant_off - set device as not dormant. |
1906 | * @dev: network device | 1910 | * @dev: network device |
1907 | * | 1911 | * |
1908 | * Device is not in dormant state. | 1912 | * Device is not in dormant state. |
1909 | */ | 1913 | */ |
1910 | static inline void netif_dormant_off(struct net_device *dev) | 1914 | static inline void netif_dormant_off(struct net_device *dev) |
1911 | { | 1915 | { |
1912 | if (test_and_clear_bit(__LINK_STATE_DORMANT, &dev->state)) | 1916 | if (test_and_clear_bit(__LINK_STATE_DORMANT, &dev->state)) |
1913 | linkwatch_fire_event(dev); | 1917 | linkwatch_fire_event(dev); |
1914 | } | 1918 | } |
1915 | 1919 | ||
1916 | /** | 1920 | /** |
1917 | * netif_dormant - test if carrier present | 1921 | * netif_dormant - test if carrier present |
1918 | * @dev: network device | 1922 | * @dev: network device |
1919 | * | 1923 | * |
1920 | * Check if carrier is present on device | 1924 | * Check if carrier is present on device |
1921 | */ | 1925 | */ |
1922 | static inline int netif_dormant(const struct net_device *dev) | 1926 | static inline int netif_dormant(const struct net_device *dev) |
1923 | { | 1927 | { |
1924 | return test_bit(__LINK_STATE_DORMANT, &dev->state); | 1928 | return test_bit(__LINK_STATE_DORMANT, &dev->state); |
1925 | } | 1929 | } |
1926 | 1930 | ||
1927 | 1931 | ||
1928 | /** | 1932 | /** |
1929 | * netif_oper_up - test if device is operational | 1933 | * netif_oper_up - test if device is operational |
1930 | * @dev: network device | 1934 | * @dev: network device |
1931 | * | 1935 | * |
1932 | * Check if carrier is operational | 1936 | * Check if carrier is operational |
1933 | */ | 1937 | */ |
1934 | static inline int netif_oper_up(const struct net_device *dev) | 1938 | static inline int netif_oper_up(const struct net_device *dev) |
1935 | { | 1939 | { |
1936 | return (dev->operstate == IF_OPER_UP || | 1940 | return (dev->operstate == IF_OPER_UP || |
1937 | dev->operstate == IF_OPER_UNKNOWN /* backward compat */); | 1941 | dev->operstate == IF_OPER_UNKNOWN /* backward compat */); |
1938 | } | 1942 | } |
1939 | 1943 | ||
1940 | /** | 1944 | /** |
1941 | * netif_device_present - is device available or removed | 1945 | * netif_device_present - is device available or removed |
1942 | * @dev: network device | 1946 | * @dev: network device |
1943 | * | 1947 | * |
1944 | * Check if device has not been removed from system. | 1948 | * Check if device has not been removed from system. |
1945 | */ | 1949 | */ |
1946 | static inline int netif_device_present(struct net_device *dev) | 1950 | static inline int netif_device_present(struct net_device *dev) |
1947 | { | 1951 | { |
1948 | return test_bit(__LINK_STATE_PRESENT, &dev->state); | 1952 | return test_bit(__LINK_STATE_PRESENT, &dev->state); |
1949 | } | 1953 | } |
1950 | 1954 | ||
1951 | extern void netif_device_detach(struct net_device *dev); | 1955 | extern void netif_device_detach(struct net_device *dev); |
1952 | 1956 | ||
1953 | extern void netif_device_attach(struct net_device *dev); | 1957 | extern void netif_device_attach(struct net_device *dev); |
1954 | 1958 | ||
1955 | /* | 1959 | /* |
1956 | * Network interface message level settings | 1960 | * Network interface message level settings |
1957 | */ | 1961 | */ |
1958 | #define HAVE_NETIF_MSG 1 | 1962 | #define HAVE_NETIF_MSG 1 |
1959 | 1963 | ||
1960 | enum { | 1964 | enum { |
1961 | NETIF_MSG_DRV = 0x0001, | 1965 | NETIF_MSG_DRV = 0x0001, |
1962 | NETIF_MSG_PROBE = 0x0002, | 1966 | NETIF_MSG_PROBE = 0x0002, |
1963 | NETIF_MSG_LINK = 0x0004, | 1967 | NETIF_MSG_LINK = 0x0004, |
1964 | NETIF_MSG_TIMER = 0x0008, | 1968 | NETIF_MSG_TIMER = 0x0008, |
1965 | NETIF_MSG_IFDOWN = 0x0010, | 1969 | NETIF_MSG_IFDOWN = 0x0010, |
1966 | NETIF_MSG_IFUP = 0x0020, | 1970 | NETIF_MSG_IFUP = 0x0020, |
1967 | NETIF_MSG_RX_ERR = 0x0040, | 1971 | NETIF_MSG_RX_ERR = 0x0040, |
1968 | NETIF_MSG_TX_ERR = 0x0080, | 1972 | NETIF_MSG_TX_ERR = 0x0080, |
1969 | NETIF_MSG_TX_QUEUED = 0x0100, | 1973 | NETIF_MSG_TX_QUEUED = 0x0100, |
1970 | NETIF_MSG_INTR = 0x0200, | 1974 | NETIF_MSG_INTR = 0x0200, |
1971 | NETIF_MSG_TX_DONE = 0x0400, | 1975 | NETIF_MSG_TX_DONE = 0x0400, |
1972 | NETIF_MSG_RX_STATUS = 0x0800, | 1976 | NETIF_MSG_RX_STATUS = 0x0800, |
1973 | NETIF_MSG_PKTDATA = 0x1000, | 1977 | NETIF_MSG_PKTDATA = 0x1000, |
1974 | NETIF_MSG_HW = 0x2000, | 1978 | NETIF_MSG_HW = 0x2000, |
1975 | NETIF_MSG_WOL = 0x4000, | 1979 | NETIF_MSG_WOL = 0x4000, |
1976 | }; | 1980 | }; |
1977 | 1981 | ||
1978 | #define netif_msg_drv(p) ((p)->msg_enable & NETIF_MSG_DRV) | 1982 | #define netif_msg_drv(p) ((p)->msg_enable & NETIF_MSG_DRV) |
1979 | #define netif_msg_probe(p) ((p)->msg_enable & NETIF_MSG_PROBE) | 1983 | #define netif_msg_probe(p) ((p)->msg_enable & NETIF_MSG_PROBE) |
1980 | #define netif_msg_link(p) ((p)->msg_enable & NETIF_MSG_LINK) | 1984 | #define netif_msg_link(p) ((p)->msg_enable & NETIF_MSG_LINK) |
1981 | #define netif_msg_timer(p) ((p)->msg_enable & NETIF_MSG_TIMER) | 1985 | #define netif_msg_timer(p) ((p)->msg_enable & NETIF_MSG_TIMER) |
1982 | #define netif_msg_ifdown(p) ((p)->msg_enable & NETIF_MSG_IFDOWN) | 1986 | #define netif_msg_ifdown(p) ((p)->msg_enable & NETIF_MSG_IFDOWN) |
1983 | #define netif_msg_ifup(p) ((p)->msg_enable & NETIF_MSG_IFUP) | 1987 | #define netif_msg_ifup(p) ((p)->msg_enable & NETIF_MSG_IFUP) |
1984 | #define netif_msg_rx_err(p) ((p)->msg_enable & NETIF_MSG_RX_ERR) | 1988 | #define netif_msg_rx_err(p) ((p)->msg_enable & NETIF_MSG_RX_ERR) |
1985 | #define netif_msg_tx_err(p) ((p)->msg_enable & NETIF_MSG_TX_ERR) | 1989 | #define netif_msg_tx_err(p) ((p)->msg_enable & NETIF_MSG_TX_ERR) |
1986 | #define netif_msg_tx_queued(p) ((p)->msg_enable & NETIF_MSG_TX_QUEUED) | 1990 | #define netif_msg_tx_queued(p) ((p)->msg_enable & NETIF_MSG_TX_QUEUED) |
1987 | #define netif_msg_intr(p) ((p)->msg_enable & NETIF_MSG_INTR) | 1991 | #define netif_msg_intr(p) ((p)->msg_enable & NETIF_MSG_INTR) |
1988 | #define netif_msg_tx_done(p) ((p)->msg_enable & NETIF_MSG_TX_DONE) | 1992 | #define netif_msg_tx_done(p) ((p)->msg_enable & NETIF_MSG_TX_DONE) |
1989 | #define netif_msg_rx_status(p) ((p)->msg_enable & NETIF_MSG_RX_STATUS) | 1993 | #define netif_msg_rx_status(p) ((p)->msg_enable & NETIF_MSG_RX_STATUS) |
1990 | #define netif_msg_pktdata(p) ((p)->msg_enable & NETIF_MSG_PKTDATA) | 1994 | #define netif_msg_pktdata(p) ((p)->msg_enable & NETIF_MSG_PKTDATA) |
1991 | #define netif_msg_hw(p) ((p)->msg_enable & NETIF_MSG_HW) | 1995 | #define netif_msg_hw(p) ((p)->msg_enable & NETIF_MSG_HW) |
1992 | #define netif_msg_wol(p) ((p)->msg_enable & NETIF_MSG_WOL) | 1996 | #define netif_msg_wol(p) ((p)->msg_enable & NETIF_MSG_WOL) |
1993 | 1997 | ||
1994 | static inline u32 netif_msg_init(int debug_value, int default_msg_enable_bits) | 1998 | static inline u32 netif_msg_init(int debug_value, int default_msg_enable_bits) |
1995 | { | 1999 | { |
1996 | /* use default */ | 2000 | /* use default */ |
1997 | if (debug_value < 0 || debug_value >= (sizeof(u32) * 8)) | 2001 | if (debug_value < 0 || debug_value >= (sizeof(u32) * 8)) |
1998 | return default_msg_enable_bits; | 2002 | return default_msg_enable_bits; |
1999 | if (debug_value == 0) /* no output */ | 2003 | if (debug_value == 0) /* no output */ |
2000 | return 0; | 2004 | return 0; |
2001 | /* set low N bits */ | 2005 | /* set low N bits */ |
2002 | return (1 << debug_value) - 1; | 2006 | return (1 << debug_value) - 1; |
2003 | } | 2007 | } |
2004 | 2008 | ||
2005 | static inline void __netif_tx_lock(struct netdev_queue *txq, int cpu) | 2009 | static inline void __netif_tx_lock(struct netdev_queue *txq, int cpu) |
2006 | { | 2010 | { |
2007 | spin_lock(&txq->_xmit_lock); | 2011 | spin_lock(&txq->_xmit_lock); |
2008 | txq->xmit_lock_owner = cpu; | 2012 | txq->xmit_lock_owner = cpu; |
2009 | } | 2013 | } |
2010 | 2014 | ||
2011 | static inline void __netif_tx_lock_bh(struct netdev_queue *txq) | 2015 | static inline void __netif_tx_lock_bh(struct netdev_queue *txq) |
2012 | { | 2016 | { |
2013 | spin_lock_bh(&txq->_xmit_lock); | 2017 | spin_lock_bh(&txq->_xmit_lock); |
2014 | txq->xmit_lock_owner = smp_processor_id(); | 2018 | txq->xmit_lock_owner = smp_processor_id(); |
2015 | } | 2019 | } |
2016 | 2020 | ||
2017 | static inline int __netif_tx_trylock(struct netdev_queue *txq) | 2021 | static inline int __netif_tx_trylock(struct netdev_queue *txq) |
2018 | { | 2022 | { |
2019 | int ok = spin_trylock(&txq->_xmit_lock); | 2023 | int ok = spin_trylock(&txq->_xmit_lock); |
2020 | if (likely(ok)) | 2024 | if (likely(ok)) |
2021 | txq->xmit_lock_owner = smp_processor_id(); | 2025 | txq->xmit_lock_owner = smp_processor_id(); |
2022 | return ok; | 2026 | return ok; |
2023 | } | 2027 | } |
2024 | 2028 | ||
2025 | static inline void __netif_tx_unlock(struct netdev_queue *txq) | 2029 | static inline void __netif_tx_unlock(struct netdev_queue *txq) |
2026 | { | 2030 | { |
2027 | txq->xmit_lock_owner = -1; | 2031 | txq->xmit_lock_owner = -1; |
2028 | spin_unlock(&txq->_xmit_lock); | 2032 | spin_unlock(&txq->_xmit_lock); |
2029 | } | 2033 | } |
2030 | 2034 | ||
2031 | static inline void __netif_tx_unlock_bh(struct netdev_queue *txq) | 2035 | static inline void __netif_tx_unlock_bh(struct netdev_queue *txq) |
2032 | { | 2036 | { |
2033 | txq->xmit_lock_owner = -1; | 2037 | txq->xmit_lock_owner = -1; |
2034 | spin_unlock_bh(&txq->_xmit_lock); | 2038 | spin_unlock_bh(&txq->_xmit_lock); |
2035 | } | 2039 | } |
2036 | 2040 | ||
2037 | static inline void txq_trans_update(struct netdev_queue *txq) | 2041 | static inline void txq_trans_update(struct netdev_queue *txq) |
2038 | { | 2042 | { |
2039 | if (txq->xmit_lock_owner != -1) | 2043 | if (txq->xmit_lock_owner != -1) |
2040 | txq->trans_start = jiffies; | 2044 | txq->trans_start = jiffies; |
2041 | } | 2045 | } |
2042 | 2046 | ||
2043 | /** | 2047 | /** |
2044 | * netif_tx_lock - grab network device transmit lock | 2048 | * netif_tx_lock - grab network device transmit lock |
2045 | * @dev: network device | 2049 | * @dev: network device |
2046 | * | 2050 | * |
2047 | * Get network device transmit lock | 2051 | * Get network device transmit lock |
2048 | */ | 2052 | */ |
2049 | static inline void netif_tx_lock(struct net_device *dev) | 2053 | static inline void netif_tx_lock(struct net_device *dev) |
2050 | { | 2054 | { |
2051 | unsigned int i; | 2055 | unsigned int i; |
2052 | int cpu; | 2056 | int cpu; |
2053 | 2057 | ||
2054 | spin_lock(&dev->tx_global_lock); | 2058 | spin_lock(&dev->tx_global_lock); |
2055 | cpu = smp_processor_id(); | 2059 | cpu = smp_processor_id(); |
2056 | for (i = 0; i < dev->num_tx_queues; i++) { | 2060 | for (i = 0; i < dev->num_tx_queues; i++) { |
2057 | struct netdev_queue *txq = netdev_get_tx_queue(dev, i); | 2061 | struct netdev_queue *txq = netdev_get_tx_queue(dev, i); |
2058 | 2062 | ||
2059 | /* We are the only thread of execution doing a | 2063 | /* We are the only thread of execution doing a |
2060 | * freeze, but we have to grab the _xmit_lock in | 2064 | * freeze, but we have to grab the _xmit_lock in |
2061 | * order to synchronize with threads which are in | 2065 | * order to synchronize with threads which are in |
2062 | * the ->hard_start_xmit() handler and already | 2066 | * the ->hard_start_xmit() handler and already |
2063 | * checked the frozen bit. | 2067 | * checked the frozen bit. |
2064 | */ | 2068 | */ |
2065 | __netif_tx_lock(txq, cpu); | 2069 | __netif_tx_lock(txq, cpu); |
2066 | set_bit(__QUEUE_STATE_FROZEN, &txq->state); | 2070 | set_bit(__QUEUE_STATE_FROZEN, &txq->state); |
2067 | __netif_tx_unlock(txq); | 2071 | __netif_tx_unlock(txq); |
2068 | } | 2072 | } |
2069 | } | 2073 | } |
2070 | 2074 | ||
2071 | static inline void netif_tx_lock_bh(struct net_device *dev) | 2075 | static inline void netif_tx_lock_bh(struct net_device *dev) |
2072 | { | 2076 | { |
2073 | local_bh_disable(); | 2077 | local_bh_disable(); |
2074 | netif_tx_lock(dev); | 2078 | netif_tx_lock(dev); |
2075 | } | 2079 | } |
2076 | 2080 | ||
2077 | static inline void netif_tx_unlock(struct net_device *dev) | 2081 | static inline void netif_tx_unlock(struct net_device *dev) |
2078 | { | 2082 | { |
2079 | unsigned int i; | 2083 | unsigned int i; |
2080 | 2084 | ||
2081 | for (i = 0; i < dev->num_tx_queues; i++) { | 2085 | for (i = 0; i < dev->num_tx_queues; i++) { |
2082 | struct netdev_queue *txq = netdev_get_tx_queue(dev, i); | 2086 | struct netdev_queue *txq = netdev_get_tx_queue(dev, i); |
2083 | 2087 | ||
2084 | /* No need to grab the _xmit_lock here. If the | 2088 | /* No need to grab the _xmit_lock here. If the |
2085 | * queue is not stopped for another reason, we | 2089 | * queue is not stopped for another reason, we |
2086 | * force a schedule. | 2090 | * force a schedule. |
2087 | */ | 2091 | */ |
2088 | clear_bit(__QUEUE_STATE_FROZEN, &txq->state); | 2092 | clear_bit(__QUEUE_STATE_FROZEN, &txq->state); |
2089 | netif_schedule_queue(txq); | 2093 | netif_schedule_queue(txq); |
2090 | } | 2094 | } |
2091 | spin_unlock(&dev->tx_global_lock); | 2095 | spin_unlock(&dev->tx_global_lock); |
2092 | } | 2096 | } |
2093 | 2097 | ||
2094 | static inline void netif_tx_unlock_bh(struct net_device *dev) | 2098 | static inline void netif_tx_unlock_bh(struct net_device *dev) |
2095 | { | 2099 | { |
2096 | netif_tx_unlock(dev); | 2100 | netif_tx_unlock(dev); |
2097 | local_bh_enable(); | 2101 | local_bh_enable(); |
2098 | } | 2102 | } |
2099 | 2103 | ||
2100 | #define HARD_TX_LOCK(dev, txq, cpu) { \ | 2104 | #define HARD_TX_LOCK(dev, txq, cpu) { \ |
2101 | if ((dev->features & NETIF_F_LLTX) == 0) { \ | 2105 | if ((dev->features & NETIF_F_LLTX) == 0) { \ |
2102 | __netif_tx_lock(txq, cpu); \ | 2106 | __netif_tx_lock(txq, cpu); \ |
2103 | } \ | 2107 | } \ |
2104 | } | 2108 | } |
2105 | 2109 | ||
2106 | #define HARD_TX_UNLOCK(dev, txq) { \ | 2110 | #define HARD_TX_UNLOCK(dev, txq) { \ |
2107 | if ((dev->features & NETIF_F_LLTX) == 0) { \ | 2111 | if ((dev->features & NETIF_F_LLTX) == 0) { \ |
2108 | __netif_tx_unlock(txq); \ | 2112 | __netif_tx_unlock(txq); \ |
2109 | } \ | 2113 | } \ |
2110 | } | 2114 | } |
2111 | 2115 | ||
2112 | static inline void netif_tx_disable(struct net_device *dev) | 2116 | static inline void netif_tx_disable(struct net_device *dev) |
2113 | { | 2117 | { |
2114 | unsigned int i; | 2118 | unsigned int i; |
2115 | int cpu; | 2119 | int cpu; |
2116 | 2120 | ||
2117 | local_bh_disable(); | 2121 | local_bh_disable(); |
2118 | cpu = smp_processor_id(); | 2122 | cpu = smp_processor_id(); |
2119 | for (i = 0; i < dev->num_tx_queues; i++) { | 2123 | for (i = 0; i < dev->num_tx_queues; i++) { |
2120 | struct netdev_queue *txq = netdev_get_tx_queue(dev, i); | 2124 | struct netdev_queue *txq = netdev_get_tx_queue(dev, i); |
2121 | 2125 | ||
2122 | __netif_tx_lock(txq, cpu); | 2126 | __netif_tx_lock(txq, cpu); |
2123 | netif_tx_stop_queue(txq); | 2127 | netif_tx_stop_queue(txq); |
2124 | __netif_tx_unlock(txq); | 2128 | __netif_tx_unlock(txq); |
2125 | } | 2129 | } |
2126 | local_bh_enable(); | 2130 | local_bh_enable(); |
2127 | } | 2131 | } |
2128 | 2132 | ||
2129 | static inline void netif_addr_lock(struct net_device *dev) | 2133 | static inline void netif_addr_lock(struct net_device *dev) |
2130 | { | 2134 | { |
2131 | spin_lock(&dev->addr_list_lock); | 2135 | spin_lock(&dev->addr_list_lock); |
2132 | } | 2136 | } |
2133 | 2137 | ||
2134 | static inline void netif_addr_lock_bh(struct net_device *dev) | 2138 | static inline void netif_addr_lock_bh(struct net_device *dev) |
2135 | { | 2139 | { |
2136 | spin_lock_bh(&dev->addr_list_lock); | 2140 | spin_lock_bh(&dev->addr_list_lock); |
2137 | } | 2141 | } |
2138 | 2142 | ||
2139 | static inline void netif_addr_unlock(struct net_device *dev) | 2143 | static inline void netif_addr_unlock(struct net_device *dev) |
2140 | { | 2144 | { |
2141 | spin_unlock(&dev->addr_list_lock); | 2145 | spin_unlock(&dev->addr_list_lock); |
2142 | } | 2146 | } |
2143 | 2147 | ||
2144 | static inline void netif_addr_unlock_bh(struct net_device *dev) | 2148 | static inline void netif_addr_unlock_bh(struct net_device *dev) |
2145 | { | 2149 | { |
2146 | spin_unlock_bh(&dev->addr_list_lock); | 2150 | spin_unlock_bh(&dev->addr_list_lock); |
2147 | } | 2151 | } |
2148 | 2152 | ||
2149 | /* | 2153 | /* |
2150 | * dev_addrs walker. Should be used only for read access. Call with | 2154 | * dev_addrs walker. Should be used only for read access. Call with |
2151 | * rcu_read_lock held. | 2155 | * rcu_read_lock held. |
2152 | */ | 2156 | */ |
2153 | #define for_each_dev_addr(dev, ha) \ | 2157 | #define for_each_dev_addr(dev, ha) \ |
2154 | list_for_each_entry_rcu(ha, &dev->dev_addrs.list, list) | 2158 | list_for_each_entry_rcu(ha, &dev->dev_addrs.list, list) |
2155 | 2159 | ||
2156 | /* These functions live elsewhere (drivers/net/net_init.c, but related) */ | 2160 | /* These functions live elsewhere (drivers/net/net_init.c, but related) */ |
2157 | 2161 | ||
2158 | extern void ether_setup(struct net_device *dev); | 2162 | extern void ether_setup(struct net_device *dev); |
2159 | 2163 | ||
2160 | /* Support for loadable net-drivers */ | 2164 | /* Support for loadable net-drivers */ |
2161 | extern struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name, | 2165 | extern struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name, |
2162 | void (*setup)(struct net_device *), | 2166 | void (*setup)(struct net_device *), |
2163 | unsigned int queue_count); | 2167 | unsigned int queue_count); |
2164 | #define alloc_netdev(sizeof_priv, name, setup) \ | 2168 | #define alloc_netdev(sizeof_priv, name, setup) \ |
2165 | alloc_netdev_mq(sizeof_priv, name, setup, 1) | 2169 | alloc_netdev_mq(sizeof_priv, name, setup, 1) |
2166 | extern int register_netdev(struct net_device *dev); | 2170 | extern int register_netdev(struct net_device *dev); |
2167 | extern void unregister_netdev(struct net_device *dev); | 2171 | extern void unregister_netdev(struct net_device *dev); |
2168 | 2172 | ||
2169 | /* General hardware address lists handling functions */ | 2173 | /* General hardware address lists handling functions */ |
2170 | extern int __hw_addr_add_multiple(struct netdev_hw_addr_list *to_list, | 2174 | extern int __hw_addr_add_multiple(struct netdev_hw_addr_list *to_list, |
2171 | struct netdev_hw_addr_list *from_list, | 2175 | struct netdev_hw_addr_list *from_list, |
2172 | int addr_len, unsigned char addr_type); | 2176 | int addr_len, unsigned char addr_type); |
2173 | extern void __hw_addr_del_multiple(struct netdev_hw_addr_list *to_list, | 2177 | extern void __hw_addr_del_multiple(struct netdev_hw_addr_list *to_list, |
2174 | struct netdev_hw_addr_list *from_list, | 2178 | struct netdev_hw_addr_list *from_list, |
2175 | int addr_len, unsigned char addr_type); | 2179 | int addr_len, unsigned char addr_type); |
2176 | extern int __hw_addr_sync(struct netdev_hw_addr_list *to_list, | 2180 | extern int __hw_addr_sync(struct netdev_hw_addr_list *to_list, |
2177 | struct netdev_hw_addr_list *from_list, | 2181 | struct netdev_hw_addr_list *from_list, |
2178 | int addr_len); | 2182 | int addr_len); |
2179 | extern void __hw_addr_unsync(struct netdev_hw_addr_list *to_list, | 2183 | extern void __hw_addr_unsync(struct netdev_hw_addr_list *to_list, |
2180 | struct netdev_hw_addr_list *from_list, | 2184 | struct netdev_hw_addr_list *from_list, |
2181 | int addr_len); | 2185 | int addr_len); |
2182 | extern void __hw_addr_flush(struct netdev_hw_addr_list *list); | 2186 | extern void __hw_addr_flush(struct netdev_hw_addr_list *list); |
2183 | extern void __hw_addr_init(struct netdev_hw_addr_list *list); | 2187 | extern void __hw_addr_init(struct netdev_hw_addr_list *list); |
2184 | 2188 | ||
2185 | /* Functions used for device addresses handling */ | 2189 | /* Functions used for device addresses handling */ |
2186 | extern int dev_addr_add(struct net_device *dev, unsigned char *addr, | 2190 | extern int dev_addr_add(struct net_device *dev, unsigned char *addr, |
2187 | unsigned char addr_type); | 2191 | unsigned char addr_type); |
2188 | extern int dev_addr_del(struct net_device *dev, unsigned char *addr, | 2192 | extern int dev_addr_del(struct net_device *dev, unsigned char *addr, |
2189 | unsigned char addr_type); | 2193 | unsigned char addr_type); |
2190 | extern int dev_addr_add_multiple(struct net_device *to_dev, | 2194 | extern int dev_addr_add_multiple(struct net_device *to_dev, |
2191 | struct net_device *from_dev, | 2195 | struct net_device *from_dev, |
2192 | unsigned char addr_type); | 2196 | unsigned char addr_type); |
2193 | extern int dev_addr_del_multiple(struct net_device *to_dev, | 2197 | extern int dev_addr_del_multiple(struct net_device *to_dev, |
2194 | struct net_device *from_dev, | 2198 | struct net_device *from_dev, |
2195 | unsigned char addr_type); | 2199 | unsigned char addr_type); |
2196 | extern void dev_addr_flush(struct net_device *dev); | 2200 | extern void dev_addr_flush(struct net_device *dev); |
2197 | extern int dev_addr_init(struct net_device *dev); | 2201 | extern int dev_addr_init(struct net_device *dev); |
2198 | 2202 | ||
2199 | /* Functions used for unicast addresses handling */ | 2203 | /* Functions used for unicast addresses handling */ |
2200 | extern int dev_uc_add(struct net_device *dev, unsigned char *addr); | 2204 | extern int dev_uc_add(struct net_device *dev, unsigned char *addr); |
2201 | extern int dev_uc_del(struct net_device *dev, unsigned char *addr); | 2205 | extern int dev_uc_del(struct net_device *dev, unsigned char *addr); |
2202 | extern int dev_uc_sync(struct net_device *to, struct net_device *from); | 2206 | extern int dev_uc_sync(struct net_device *to, struct net_device *from); |
2203 | extern void dev_uc_unsync(struct net_device *to, struct net_device *from); | 2207 | extern void dev_uc_unsync(struct net_device *to, struct net_device *from); |
2204 | extern void dev_uc_flush(struct net_device *dev); | 2208 | extern void dev_uc_flush(struct net_device *dev); |
2205 | extern void dev_uc_init(struct net_device *dev); | 2209 | extern void dev_uc_init(struct net_device *dev); |
2206 | 2210 | ||
2207 | /* Functions used for multicast addresses handling */ | 2211 | /* Functions used for multicast addresses handling */ |
2208 | extern int dev_mc_add(struct net_device *dev, unsigned char *addr); | 2212 | extern int dev_mc_add(struct net_device *dev, unsigned char *addr); |
2209 | extern int dev_mc_add_global(struct net_device *dev, unsigned char *addr); | 2213 | extern int dev_mc_add_global(struct net_device *dev, unsigned char *addr); |
2210 | extern int dev_mc_del(struct net_device *dev, unsigned char *addr); | 2214 | extern int dev_mc_del(struct net_device *dev, unsigned char *addr); |
2211 | extern int dev_mc_del_global(struct net_device *dev, unsigned char *addr); | 2215 | extern int dev_mc_del_global(struct net_device *dev, unsigned char *addr); |
2212 | extern int dev_mc_sync(struct net_device *to, struct net_device *from); | 2216 | extern int dev_mc_sync(struct net_device *to, struct net_device *from); |
2213 | extern void dev_mc_unsync(struct net_device *to, struct net_device *from); | 2217 | extern void dev_mc_unsync(struct net_device *to, struct net_device *from); |
2214 | extern void dev_mc_flush(struct net_device *dev); | 2218 | extern void dev_mc_flush(struct net_device *dev); |
2215 | extern void dev_mc_init(struct net_device *dev); | 2219 | extern void dev_mc_init(struct net_device *dev); |
2216 | 2220 | ||
2217 | /* Functions used for secondary unicast and multicast support */ | 2221 | /* Functions used for secondary unicast and multicast support */ |
2218 | extern void dev_set_rx_mode(struct net_device *dev); | 2222 | extern void dev_set_rx_mode(struct net_device *dev); |
2219 | extern void __dev_set_rx_mode(struct net_device *dev); | 2223 | extern void __dev_set_rx_mode(struct net_device *dev); |
2220 | extern int dev_set_promiscuity(struct net_device *dev, int inc); | 2224 | extern int dev_set_promiscuity(struct net_device *dev, int inc); |
2221 | extern int dev_set_allmulti(struct net_device *dev, int inc); | 2225 | extern int dev_set_allmulti(struct net_device *dev, int inc); |
2222 | extern void netdev_state_change(struct net_device *dev); | 2226 | extern void netdev_state_change(struct net_device *dev); |
2223 | extern int netdev_bonding_change(struct net_device *dev, | 2227 | extern int netdev_bonding_change(struct net_device *dev, |
2224 | unsigned long event); | 2228 | unsigned long event); |
2225 | extern void netdev_features_change(struct net_device *dev); | 2229 | extern void netdev_features_change(struct net_device *dev); |
2226 | /* Load a device via the kmod */ | 2230 | /* Load a device via the kmod */ |
2227 | extern void dev_load(struct net *net, const char *name); | 2231 | extern void dev_load(struct net *net, const char *name); |
2228 | extern void dev_mcast_init(void); | 2232 | extern void dev_mcast_init(void); |
2229 | extern struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev, | 2233 | extern struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev, |
2230 | struct rtnl_link_stats64 *storage); | 2234 | struct rtnl_link_stats64 *storage); |
2231 | extern void dev_txq_stats_fold(const struct net_device *dev, | 2235 | extern void dev_txq_stats_fold(const struct net_device *dev, |
2232 | struct rtnl_link_stats64 *stats); | 2236 | struct rtnl_link_stats64 *stats); |
2233 | 2237 | ||
2234 | extern int netdev_max_backlog; | 2238 | extern int netdev_max_backlog; |
2235 | extern int netdev_tstamp_prequeue; | 2239 | extern int netdev_tstamp_prequeue; |
2236 | extern int weight_p; | 2240 | extern int weight_p; |
2237 | extern int netdev_set_master(struct net_device *dev, struct net_device *master); | 2241 | extern int netdev_set_master(struct net_device *dev, struct net_device *master); |
2238 | extern int skb_checksum_help(struct sk_buff *skb); | 2242 | extern int skb_checksum_help(struct sk_buff *skb); |
2239 | extern struct sk_buff *skb_gso_segment(struct sk_buff *skb, int features); | 2243 | extern struct sk_buff *skb_gso_segment(struct sk_buff *skb, int features); |
2240 | #ifdef CONFIG_BUG | 2244 | #ifdef CONFIG_BUG |
2241 | extern void netdev_rx_csum_fault(struct net_device *dev); | 2245 | extern void netdev_rx_csum_fault(struct net_device *dev); |
2242 | #else | 2246 | #else |
2243 | static inline void netdev_rx_csum_fault(struct net_device *dev) | 2247 | static inline void netdev_rx_csum_fault(struct net_device *dev) |
2244 | { | 2248 | { |
2245 | } | 2249 | } |
2246 | #endif | 2250 | #endif |
2247 | /* rx skb timestamps */ | 2251 | /* rx skb timestamps */ |
2248 | extern void net_enable_timestamp(void); | 2252 | extern void net_enable_timestamp(void); |
2249 | extern void net_disable_timestamp(void); | 2253 | extern void net_disable_timestamp(void); |
2250 | 2254 | ||
2251 | #ifdef CONFIG_PROC_FS | 2255 | #ifdef CONFIG_PROC_FS |
2252 | extern void *dev_seq_start(struct seq_file *seq, loff_t *pos); | 2256 | extern void *dev_seq_start(struct seq_file *seq, loff_t *pos); |
2253 | extern void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos); | 2257 | extern void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos); |
2254 | extern void dev_seq_stop(struct seq_file *seq, void *v); | 2258 | extern void dev_seq_stop(struct seq_file *seq, void *v); |
2255 | #endif | 2259 | #endif |
2256 | 2260 | ||
2257 | extern int netdev_class_create_file(struct class_attribute *class_attr); | 2261 | extern int netdev_class_create_file(struct class_attribute *class_attr); |
2258 | extern void netdev_class_remove_file(struct class_attribute *class_attr); | 2262 | extern void netdev_class_remove_file(struct class_attribute *class_attr); |
2259 | 2263 | ||
2260 | extern struct kobj_ns_type_operations net_ns_type_operations; | 2264 | extern struct kobj_ns_type_operations net_ns_type_operations; |
2261 | 2265 | ||
2262 | extern char *netdev_drivername(const struct net_device *dev, char *buffer, int len); | 2266 | extern char *netdev_drivername(const struct net_device *dev, char *buffer, int len); |
2263 | 2267 | ||
2264 | extern void linkwatch_run_queue(void); | 2268 | extern void linkwatch_run_queue(void); |
2265 | 2269 | ||
2266 | unsigned long netdev_increment_features(unsigned long all, unsigned long one, | 2270 | unsigned long netdev_increment_features(unsigned long all, unsigned long one, |
2267 | unsigned long mask); | 2271 | unsigned long mask); |
2268 | unsigned long netdev_fix_features(unsigned long features, const char *name); | 2272 | unsigned long netdev_fix_features(unsigned long features, const char *name); |
2269 | 2273 | ||
2270 | void netif_stacked_transfer_operstate(const struct net_device *rootdev, | 2274 | void netif_stacked_transfer_operstate(const struct net_device *rootdev, |
2271 | struct net_device *dev); | 2275 | struct net_device *dev); |
2272 | 2276 | ||
2273 | int netif_get_vlan_features(struct sk_buff *skb, struct net_device *dev); | 2277 | int netif_get_vlan_features(struct sk_buff *skb, struct net_device *dev); |
2274 | 2278 | ||
2275 | static inline int net_gso_ok(int features, int gso_type) | 2279 | static inline int net_gso_ok(int features, int gso_type) |
2276 | { | 2280 | { |
2277 | int feature = gso_type << NETIF_F_GSO_SHIFT; | 2281 | int feature = gso_type << NETIF_F_GSO_SHIFT; |
2278 | return (features & feature) == feature; | 2282 | return (features & feature) == feature; |
2279 | } | 2283 | } |
2280 | 2284 | ||
2281 | static inline int skb_gso_ok(struct sk_buff *skb, int features) | 2285 | static inline int skb_gso_ok(struct sk_buff *skb, int features) |
2282 | { | 2286 | { |
2283 | return net_gso_ok(features, skb_shinfo(skb)->gso_type) && | 2287 | return net_gso_ok(features, skb_shinfo(skb)->gso_type) && |
2284 | (!skb_has_frag_list(skb) || (features & NETIF_F_FRAGLIST)); | 2288 | (!skb_has_frag_list(skb) || (features & NETIF_F_FRAGLIST)); |
2285 | } | 2289 | } |
2286 | 2290 | ||
2287 | static inline int netif_needs_gso(struct net_device *dev, struct sk_buff *skb) | 2291 | static inline int netif_needs_gso(struct net_device *dev, struct sk_buff *skb) |
2288 | { | 2292 | { |
2289 | if (skb_is_gso(skb)) { | 2293 | if (skb_is_gso(skb)) { |
2290 | int features = netif_get_vlan_features(skb, dev); | 2294 | int features = netif_get_vlan_features(skb, dev); |
2291 | 2295 | ||
2292 | return (!skb_gso_ok(skb, features) || | 2296 | return (!skb_gso_ok(skb, features) || |
2293 | unlikely(skb->ip_summed != CHECKSUM_PARTIAL)); | 2297 | unlikely(skb->ip_summed != CHECKSUM_PARTIAL)); |
2294 | } | 2298 | } |
2295 | 2299 | ||
2296 | return 0; | 2300 | return 0; |
2297 | } | 2301 | } |
2298 | 2302 | ||
2299 | static inline void netif_set_gso_max_size(struct net_device *dev, | 2303 | static inline void netif_set_gso_max_size(struct net_device *dev, |
2300 | unsigned int size) | 2304 | unsigned int size) |
2301 | { | 2305 | { |
2302 | dev->gso_max_size = size; | 2306 | dev->gso_max_size = size; |
2303 | } | 2307 | } |
2304 | 2308 | ||
2305 | extern int __skb_bond_should_drop(struct sk_buff *skb, | 2309 | extern int __skb_bond_should_drop(struct sk_buff *skb, |
2306 | struct net_device *master); | 2310 | struct net_device *master); |
2307 | 2311 | ||
2308 | static inline int skb_bond_should_drop(struct sk_buff *skb, | 2312 | static inline int skb_bond_should_drop(struct sk_buff *skb, |
2309 | struct net_device *master) | 2313 | struct net_device *master) |
2310 | { | 2314 | { |
2311 | if (master) | 2315 | if (master) |
2312 | return __skb_bond_should_drop(skb, master); | 2316 | return __skb_bond_should_drop(skb, master); |
2313 | return 0; | 2317 | return 0; |
2314 | } | 2318 | } |
2315 | 2319 | ||
2316 | extern struct pernet_operations __net_initdata loopback_net_ops; | 2320 | extern struct pernet_operations __net_initdata loopback_net_ops; |
2317 | 2321 | ||
2318 | static inline int dev_ethtool_get_settings(struct net_device *dev, | 2322 | static inline int dev_ethtool_get_settings(struct net_device *dev, |
2319 | struct ethtool_cmd *cmd) | 2323 | struct ethtool_cmd *cmd) |
2320 | { | 2324 | { |
2321 | if (!dev->ethtool_ops || !dev->ethtool_ops->get_settings) | 2325 | if (!dev->ethtool_ops || !dev->ethtool_ops->get_settings) |
2322 | return -EOPNOTSUPP; | 2326 | return -EOPNOTSUPP; |
2323 | return dev->ethtool_ops->get_settings(dev, cmd); | 2327 | return dev->ethtool_ops->get_settings(dev, cmd); |
2324 | } | 2328 | } |
2325 | 2329 | ||
2326 | static inline u32 dev_ethtool_get_rx_csum(struct net_device *dev) | 2330 | static inline u32 dev_ethtool_get_rx_csum(struct net_device *dev) |
2327 | { | 2331 | { |
2328 | if (!dev->ethtool_ops || !dev->ethtool_ops->get_rx_csum) | 2332 | if (!dev->ethtool_ops || !dev->ethtool_ops->get_rx_csum) |
2329 | return 0; | 2333 | return 0; |
2330 | return dev->ethtool_ops->get_rx_csum(dev); | 2334 | return dev->ethtool_ops->get_rx_csum(dev); |
2331 | } | 2335 | } |
2332 | 2336 | ||
2333 | static inline u32 dev_ethtool_get_flags(struct net_device *dev) | 2337 | static inline u32 dev_ethtool_get_flags(struct net_device *dev) |
2334 | { | 2338 | { |
2335 | if (!dev->ethtool_ops || !dev->ethtool_ops->get_flags) | 2339 | if (!dev->ethtool_ops || !dev->ethtool_ops->get_flags) |
2336 | return 0; | 2340 | return 0; |
2337 | return dev->ethtool_ops->get_flags(dev); | 2341 | return dev->ethtool_ops->get_flags(dev); |
2338 | } | 2342 | } |
2339 | 2343 | ||
2340 | /* Logging, debugging and troubleshooting/diagnostic helpers. */ | 2344 | /* Logging, debugging and troubleshooting/diagnostic helpers. */ |
2341 | 2345 | ||
2342 | /* netdev_printk helpers, similar to dev_printk */ | 2346 | /* netdev_printk helpers, similar to dev_printk */ |
2343 | 2347 | ||
2344 | static inline const char *netdev_name(const struct net_device *dev) | 2348 | static inline const char *netdev_name(const struct net_device *dev) |
2345 | { | 2349 | { |
2346 | if (dev->reg_state != NETREG_REGISTERED) | 2350 | if (dev->reg_state != NETREG_REGISTERED) |
2347 | return "(unregistered net_device)"; | 2351 | return "(unregistered net_device)"; |
2348 | return dev->name; | 2352 | return dev->name; |
2349 | } | 2353 | } |
2350 | 2354 | ||
2351 | extern int netdev_printk(const char *level, const struct net_device *dev, | 2355 | extern int netdev_printk(const char *level, const struct net_device *dev, |
2352 | const char *format, ...) | 2356 | const char *format, ...) |
2353 | __attribute__ ((format (printf, 3, 4))); | 2357 | __attribute__ ((format (printf, 3, 4))); |
2354 | extern int netdev_emerg(const struct net_device *dev, const char *format, ...) | 2358 | extern int netdev_emerg(const struct net_device *dev, const char *format, ...) |
2355 | __attribute__ ((format (printf, 2, 3))); | 2359 | __attribute__ ((format (printf, 2, 3))); |
2356 | extern int netdev_alert(const struct net_device *dev, const char *format, ...) | 2360 | extern int netdev_alert(const struct net_device *dev, const char *format, ...) |
2357 | __attribute__ ((format (printf, 2, 3))); | 2361 | __attribute__ ((format (printf, 2, 3))); |
2358 | extern int netdev_crit(const struct net_device *dev, const char *format, ...) | 2362 | extern int netdev_crit(const struct net_device *dev, const char *format, ...) |
2359 | __attribute__ ((format (printf, 2, 3))); | 2363 | __attribute__ ((format (printf, 2, 3))); |
2360 | extern int netdev_err(const struct net_device *dev, const char *format, ...) | 2364 | extern int netdev_err(const struct net_device *dev, const char *format, ...) |
2361 | __attribute__ ((format (printf, 2, 3))); | 2365 | __attribute__ ((format (printf, 2, 3))); |
2362 | extern int netdev_warn(const struct net_device *dev, const char *format, ...) | 2366 | extern int netdev_warn(const struct net_device *dev, const char *format, ...) |
2363 | __attribute__ ((format (printf, 2, 3))); | 2367 | __attribute__ ((format (printf, 2, 3))); |
2364 | extern int netdev_notice(const struct net_device *dev, const char *format, ...) | 2368 | extern int netdev_notice(const struct net_device *dev, const char *format, ...) |
2365 | __attribute__ ((format (printf, 2, 3))); | 2369 | __attribute__ ((format (printf, 2, 3))); |
2366 | extern int netdev_info(const struct net_device *dev, const char *format, ...) | 2370 | extern int netdev_info(const struct net_device *dev, const char *format, ...) |
2367 | __attribute__ ((format (printf, 2, 3))); | 2371 | __attribute__ ((format (printf, 2, 3))); |
2368 | 2372 | ||
2369 | #if defined(DEBUG) | 2373 | #if defined(DEBUG) |
2370 | #define netdev_dbg(__dev, format, args...) \ | 2374 | #define netdev_dbg(__dev, format, args...) \ |
2371 | netdev_printk(KERN_DEBUG, __dev, format, ##args) | 2375 | netdev_printk(KERN_DEBUG, __dev, format, ##args) |
2372 | #elif defined(CONFIG_DYNAMIC_DEBUG) | 2376 | #elif defined(CONFIG_DYNAMIC_DEBUG) |
2373 | #define netdev_dbg(__dev, format, args...) \ | 2377 | #define netdev_dbg(__dev, format, args...) \ |
2374 | do { \ | 2378 | do { \ |
2375 | dynamic_dev_dbg((__dev)->dev.parent, "%s: " format, \ | 2379 | dynamic_dev_dbg((__dev)->dev.parent, "%s: " format, \ |
2376 | netdev_name(__dev), ##args); \ | 2380 | netdev_name(__dev), ##args); \ |
2377 | } while (0) | 2381 | } while (0) |
2378 | #else | 2382 | #else |
2379 | #define netdev_dbg(__dev, format, args...) \ | 2383 | #define netdev_dbg(__dev, format, args...) \ |
2380 | ({ \ | 2384 | ({ \ |
2381 | if (0) \ | 2385 | if (0) \ |
2382 | netdev_printk(KERN_DEBUG, __dev, format, ##args); \ | 2386 | netdev_printk(KERN_DEBUG, __dev, format, ##args); \ |
2383 | 0; \ | 2387 | 0; \ |
2384 | }) | 2388 | }) |
2385 | #endif | 2389 | #endif |
2386 | 2390 | ||
2387 | #if defined(VERBOSE_DEBUG) | 2391 | #if defined(VERBOSE_DEBUG) |
2388 | #define netdev_vdbg netdev_dbg | 2392 | #define netdev_vdbg netdev_dbg |
2389 | #else | 2393 | #else |
2390 | 2394 | ||
2391 | #define netdev_vdbg(dev, format, args...) \ | 2395 | #define netdev_vdbg(dev, format, args...) \ |
2392 | ({ \ | 2396 | ({ \ |
2393 | if (0) \ | 2397 | if (0) \ |
2394 | netdev_printk(KERN_DEBUG, dev, format, ##args); \ | 2398 | netdev_printk(KERN_DEBUG, dev, format, ##args); \ |
2395 | 0; \ | 2399 | 0; \ |
2396 | }) | 2400 | }) |
2397 | #endif | 2401 | #endif |
2398 | 2402 | ||
2399 | /* | 2403 | /* |
2400 | * netdev_WARN() acts like dev_printk(), but with the key difference | 2404 | * netdev_WARN() acts like dev_printk(), but with the key difference |
2401 | * of using a WARN/WARN_ON to get the message out, including the | 2405 | * of using a WARN/WARN_ON to get the message out, including the |
2402 | * file/line information and a backtrace. | 2406 | * file/line information and a backtrace. |
2403 | */ | 2407 | */ |
2404 | #define netdev_WARN(dev, format, args...) \ | 2408 | #define netdev_WARN(dev, format, args...) \ |
2405 | WARN(1, "netdevice: %s\n" format, netdev_name(dev), ##args); | 2409 | WARN(1, "netdevice: %s\n" format, netdev_name(dev), ##args); |
2406 | 2410 | ||
2407 | /* netif printk helpers, similar to netdev_printk */ | 2411 | /* netif printk helpers, similar to netdev_printk */ |
2408 | 2412 | ||
2409 | #define netif_printk(priv, type, level, dev, fmt, args...) \ | 2413 | #define netif_printk(priv, type, level, dev, fmt, args...) \ |
2410 | do { \ | 2414 | do { \ |
2411 | if (netif_msg_##type(priv)) \ | 2415 | if (netif_msg_##type(priv)) \ |
2412 | netdev_printk(level, (dev), fmt, ##args); \ | 2416 | netdev_printk(level, (dev), fmt, ##args); \ |
2413 | } while (0) | 2417 | } while (0) |
2414 | 2418 | ||
2415 | #define netif_level(level, priv, type, dev, fmt, args...) \ | 2419 | #define netif_level(level, priv, type, dev, fmt, args...) \ |
2416 | do { \ | 2420 | do { \ |
2417 | if (netif_msg_##type(priv)) \ | 2421 | if (netif_msg_##type(priv)) \ |
2418 | netdev_##level(dev, fmt, ##args); \ | 2422 | netdev_##level(dev, fmt, ##args); \ |
2419 | } while (0) | 2423 | } while (0) |
2420 | 2424 | ||
2421 | #define netif_emerg(priv, type, dev, fmt, args...) \ | 2425 | #define netif_emerg(priv, type, dev, fmt, args...) \ |
2422 | netif_level(emerg, priv, type, dev, fmt, ##args) | 2426 | netif_level(emerg, priv, type, dev, fmt, ##args) |
2423 | #define netif_alert(priv, type, dev, fmt, args...) \ | 2427 | #define netif_alert(priv, type, dev, fmt, args...) \ |
2424 | netif_level(alert, priv, type, dev, fmt, ##args) | 2428 | netif_level(alert, priv, type, dev, fmt, ##args) |
2425 | #define netif_crit(priv, type, dev, fmt, args...) \ | 2429 | #define netif_crit(priv, type, dev, fmt, args...) \ |
2426 | netif_level(crit, priv, type, dev, fmt, ##args) | 2430 | netif_level(crit, priv, type, dev, fmt, ##args) |
2427 | #define netif_err(priv, type, dev, fmt, args...) \ | 2431 | #define netif_err(priv, type, dev, fmt, args...) \ |
2428 | netif_level(err, priv, type, dev, fmt, ##args) | 2432 | netif_level(err, priv, type, dev, fmt, ##args) |
2429 | #define netif_warn(priv, type, dev, fmt, args...) \ | 2433 | #define netif_warn(priv, type, dev, fmt, args...) \ |
2430 | netif_level(warn, priv, type, dev, fmt, ##args) | 2434 | netif_level(warn, priv, type, dev, fmt, ##args) |
2431 | #define netif_notice(priv, type, dev, fmt, args...) \ | 2435 | #define netif_notice(priv, type, dev, fmt, args...) \ |
2432 | netif_level(notice, priv, type, dev, fmt, ##args) | 2436 | netif_level(notice, priv, type, dev, fmt, ##args) |
2433 | #define netif_info(priv, type, dev, fmt, args...) \ | 2437 | #define netif_info(priv, type, dev, fmt, args...) \ |
2434 | netif_level(info, priv, type, dev, fmt, ##args) | 2438 | netif_level(info, priv, type, dev, fmt, ##args) |
2435 | 2439 | ||
2436 | #if defined(DEBUG) | 2440 | #if defined(DEBUG) |
2437 | #define netif_dbg(priv, type, dev, format, args...) \ | 2441 | #define netif_dbg(priv, type, dev, format, args...) \ |
2438 | netif_printk(priv, type, KERN_DEBUG, dev, format, ##args) | 2442 | netif_printk(priv, type, KERN_DEBUG, dev, format, ##args) |
2439 | #elif defined(CONFIG_DYNAMIC_DEBUG) | 2443 | #elif defined(CONFIG_DYNAMIC_DEBUG) |
2440 | #define netif_dbg(priv, type, netdev, format, args...) \ | 2444 | #define netif_dbg(priv, type, netdev, format, args...) \ |
2441 | do { \ | 2445 | do { \ |
2442 | if (netif_msg_##type(priv)) \ | 2446 | if (netif_msg_##type(priv)) \ |
2443 | dynamic_dev_dbg((netdev)->dev.parent, \ | 2447 | dynamic_dev_dbg((netdev)->dev.parent, \ |
2444 | "%s: " format, \ | 2448 | "%s: " format, \ |
2445 | netdev_name(netdev), ##args); \ | 2449 | netdev_name(netdev), ##args); \ |
2446 | } while (0) | 2450 | } while (0) |
net/Kconfig
1 | # | 1 | # |
2 | # Network configuration | 2 | # Network configuration |
3 | # | 3 | # |
4 | 4 | ||
5 | menuconfig NET | 5 | menuconfig NET |
6 | bool "Networking support" | 6 | bool "Networking support" |
7 | select NLATTR | 7 | select NLATTR |
8 | ---help--- | 8 | ---help--- |
9 | Unless you really know what you are doing, you should say Y here. | 9 | Unless you really know what you are doing, you should say Y here. |
10 | The reason is that some programs need kernel networking support even | 10 | The reason is that some programs need kernel networking support even |
11 | when running on a stand-alone machine that isn't connected to any | 11 | when running on a stand-alone machine that isn't connected to any |
12 | other computer. | 12 | other computer. |
13 | 13 | ||
14 | If you are upgrading from an older kernel, you | 14 | If you are upgrading from an older kernel, you |
15 | should consider updating your networking tools too because changes | 15 | should consider updating your networking tools too because changes |
16 | in the kernel and the tools often go hand in hand. The tools are | 16 | in the kernel and the tools often go hand in hand. The tools are |
17 | contained in the package net-tools, the location and version number | 17 | contained in the package net-tools, the location and version number |
18 | of which are given in <file:Documentation/Changes>. | 18 | of which are given in <file:Documentation/Changes>. |
19 | 19 | ||
20 | For a general introduction to Linux networking, it is highly | 20 | For a general introduction to Linux networking, it is highly |
21 | recommended to read the NET-HOWTO, available from | 21 | recommended to read the NET-HOWTO, available from |
22 | <http://www.tldp.org/docs.html#howto>. | 22 | <http://www.tldp.org/docs.html#howto>. |
23 | 23 | ||
24 | if NET | 24 | if NET |
25 | 25 | ||
26 | config WANT_COMPAT_NETLINK_MESSAGES | 26 | config WANT_COMPAT_NETLINK_MESSAGES |
27 | bool | 27 | bool |
28 | help | 28 | help |
29 | This option can be selected by other options that need compat | 29 | This option can be selected by other options that need compat |
30 | netlink messages. | 30 | netlink messages. |
31 | 31 | ||
32 | config COMPAT_NETLINK_MESSAGES | 32 | config COMPAT_NETLINK_MESSAGES |
33 | def_bool y | 33 | def_bool y |
34 | depends on COMPAT | 34 | depends on COMPAT |
35 | depends on WEXT_CORE || WANT_COMPAT_NETLINK_MESSAGES | 35 | depends on WEXT_CORE || WANT_COMPAT_NETLINK_MESSAGES |
36 | help | 36 | help |
37 | This option makes it possible to send different netlink messages | 37 | This option makes it possible to send different netlink messages |
38 | to tasks depending on whether the task is a compat task or not. To | 38 | to tasks depending on whether the task is a compat task or not. To |
39 | achieve this, you need to set skb_shinfo(skb)->frag_list to the | 39 | achieve this, you need to set skb_shinfo(skb)->frag_list to the |
40 | compat skb before sending the skb, the netlink code will sort out | 40 | compat skb before sending the skb, the netlink code will sort out |
41 | which message to actually pass to the task. | 41 | which message to actually pass to the task. |
42 | 42 | ||
43 | Newly written code should NEVER need this option but do | 43 | Newly written code should NEVER need this option but do |
44 | compat-independent messages instead! | 44 | compat-independent messages instead! |
45 | 45 | ||
46 | menu "Networking options" | 46 | menu "Networking options" |
47 | 47 | ||
48 | source "net/packet/Kconfig" | 48 | source "net/packet/Kconfig" |
49 | source "net/unix/Kconfig" | 49 | source "net/unix/Kconfig" |
50 | source "net/xfrm/Kconfig" | 50 | source "net/xfrm/Kconfig" |
51 | source "net/iucv/Kconfig" | 51 | source "net/iucv/Kconfig" |
52 | 52 | ||
53 | config INET | 53 | config INET |
54 | bool "TCP/IP networking" | 54 | bool "TCP/IP networking" |
55 | ---help--- | 55 | ---help--- |
56 | These are the protocols used on the Internet and on most local | 56 | These are the protocols used on the Internet and on most local |
57 | Ethernets. It is highly recommended to say Y here (this will enlarge | 57 | Ethernets. It is highly recommended to say Y here (this will enlarge |
58 | your kernel by about 400 KB), since some programs (e.g. the X window | 58 | your kernel by about 400 KB), since some programs (e.g. the X window |
59 | system) use TCP/IP even if your machine is not connected to any | 59 | system) use TCP/IP even if your machine is not connected to any |
60 | other computer. You will get the so-called loopback device which | 60 | other computer. You will get the so-called loopback device which |
61 | allows you to ping yourself (great fun, that!). | 61 | allows you to ping yourself (great fun, that!). |
62 | 62 | ||
63 | For an excellent introduction to Linux networking, please read the | 63 | For an excellent introduction to Linux networking, please read the |
64 | Linux Networking HOWTO, available from | 64 | Linux Networking HOWTO, available from |
65 | <http://www.tldp.org/docs.html#howto>. | 65 | <http://www.tldp.org/docs.html#howto>. |
66 | 66 | ||
67 | If you say Y here and also to "/proc file system support" and | 67 | If you say Y here and also to "/proc file system support" and |
68 | "Sysctl support" below, you can change various aspects of the | 68 | "Sysctl support" below, you can change various aspects of the |
69 | behavior of the TCP/IP code by writing to the (virtual) files in | 69 | behavior of the TCP/IP code by writing to the (virtual) files in |
70 | /proc/sys/net/ipv4/*; the options are explained in the file | 70 | /proc/sys/net/ipv4/*; the options are explained in the file |
71 | <file:Documentation/networking/ip-sysctl.txt>. | 71 | <file:Documentation/networking/ip-sysctl.txt>. |
72 | 72 | ||
73 | Short answer: say Y. | 73 | Short answer: say Y. |
74 | 74 | ||
75 | if INET | 75 | if INET |
76 | source "net/ipv4/Kconfig" | 76 | source "net/ipv4/Kconfig" |
77 | source "net/ipv6/Kconfig" | 77 | source "net/ipv6/Kconfig" |
78 | source "net/netlabel/Kconfig" | 78 | source "net/netlabel/Kconfig" |
79 | 79 | ||
80 | endif # if INET | 80 | endif # if INET |
81 | 81 | ||
82 | config NETWORK_SECMARK | 82 | config NETWORK_SECMARK |
83 | bool "Security Marking" | 83 | bool "Security Marking" |
84 | help | 84 | help |
85 | This enables security marking of network packets, similar | 85 | This enables security marking of network packets, similar |
86 | to nfmark, but designated for security purposes. | 86 | to nfmark, but designated for security purposes. |
87 | If you are unsure how to answer this question, answer N. | 87 | If you are unsure how to answer this question, answer N. |
88 | 88 | ||
89 | config NETWORK_PHY_TIMESTAMPING | 89 | config NETWORK_PHY_TIMESTAMPING |
90 | bool "Timestamping in PHY devices" | 90 | bool "Timestamping in PHY devices" |
91 | depends on EXPERIMENTAL | 91 | depends on EXPERIMENTAL |
92 | help | 92 | help |
93 | This allows timestamping of network packets by PHYs with | 93 | This allows timestamping of network packets by PHYs with |
94 | hardware timestamping capabilities. This option adds some | 94 | hardware timestamping capabilities. This option adds some |
95 | overhead in the transmit and receive paths. | 95 | overhead in the transmit and receive paths. |
96 | 96 | ||
97 | If you are unsure how to answer this question, answer N. | 97 | If you are unsure how to answer this question, answer N. |
98 | 98 | ||
99 | menuconfig NETFILTER | 99 | menuconfig NETFILTER |
100 | bool "Network packet filtering framework (Netfilter)" | 100 | bool "Network packet filtering framework (Netfilter)" |
101 | ---help--- | 101 | ---help--- |
102 | Netfilter is a framework for filtering and mangling network packets | 102 | Netfilter is a framework for filtering and mangling network packets |
103 | that pass through your Linux box. | 103 | that pass through your Linux box. |
104 | 104 | ||
105 | The most common use of packet filtering is to run your Linux box as | 105 | The most common use of packet filtering is to run your Linux box as |
106 | a firewall protecting a local network from the Internet. The type of | 106 | a firewall protecting a local network from the Internet. The type of |
107 | firewall provided by this kernel support is called a "packet | 107 | firewall provided by this kernel support is called a "packet |
108 | filter", which means that it can reject individual network packets | 108 | filter", which means that it can reject individual network packets |
109 | based on type, source, destination etc. The other kind of firewall, | 109 | based on type, source, destination etc. The other kind of firewall, |
110 | a "proxy-based" one, is more secure but more intrusive and more | 110 | a "proxy-based" one, is more secure but more intrusive and more |
111 | bothersome to set up; it inspects the network traffic much more | 111 | bothersome to set up; it inspects the network traffic much more |
112 | closely, modifies it and has knowledge about the higher level | 112 | closely, modifies it and has knowledge about the higher level |
113 | protocols, which a packet filter lacks. Moreover, proxy-based | 113 | protocols, which a packet filter lacks. Moreover, proxy-based |
114 | firewalls often require changes to the programs running on the local | 114 | firewalls often require changes to the programs running on the local |
115 | clients. Proxy-based firewalls don't need support by the kernel, but | 115 | clients. Proxy-based firewalls don't need support by the kernel, but |
116 | they are often combined with a packet filter, which only works if | 116 | they are often combined with a packet filter, which only works if |
117 | you say Y here. | 117 | you say Y here. |
118 | 118 | ||
119 | You should also say Y here if you intend to use your Linux box as | 119 | You should also say Y here if you intend to use your Linux box as |
120 | the gateway to the Internet for a local network of machines without | 120 | the gateway to the Internet for a local network of machines without |
121 | globally valid IP addresses. This is called "masquerading": if one | 121 | globally valid IP addresses. This is called "masquerading": if one |
122 | of the computers on your local network wants to send something to | 122 | of the computers on your local network wants to send something to |
123 | the outside, your box can "masquerade" as that computer, i.e. it | 123 | the outside, your box can "masquerade" as that computer, i.e. it |
124 | forwards the traffic to the intended outside destination, but | 124 | forwards the traffic to the intended outside destination, but |
125 | modifies the packets to make it look like they came from the | 125 | modifies the packets to make it look like they came from the |
126 | firewall box itself. It works both ways: if the outside host | 126 | firewall box itself. It works both ways: if the outside host |
127 | replies, the Linux box will silently forward the traffic to the | 127 | replies, the Linux box will silently forward the traffic to the |
128 | correct local computer. This way, the computers on your local net | 128 | correct local computer. This way, the computers on your local net |
129 | are completely invisible to the outside world, even though they can | 129 | are completely invisible to the outside world, even though they can |
130 | reach the outside and can receive replies. It is even possible to | 130 | reach the outside and can receive replies. It is even possible to |
131 | run globally visible servers from within a masqueraded local network | 131 | run globally visible servers from within a masqueraded local network |
132 | using a mechanism called portforwarding. Masquerading is also often | 132 | using a mechanism called portforwarding. Masquerading is also often |
133 | called NAT (Network Address Translation). | 133 | called NAT (Network Address Translation). |
134 | 134 | ||
135 | Another use of Netfilter is in transparent proxying: if a machine on | 135 | Another use of Netfilter is in transparent proxying: if a machine on |
136 | the local network tries to connect to an outside host, your Linux | 136 | the local network tries to connect to an outside host, your Linux |
137 | box can transparently forward the traffic to a local server, | 137 | box can transparently forward the traffic to a local server, |
138 | typically a caching proxy server. | 138 | typically a caching proxy server. |
139 | 139 | ||
140 | Yet another use of Netfilter is building a bridging firewall. Using | 140 | Yet another use of Netfilter is building a bridging firewall. Using |
141 | a bridge with Network packet filtering enabled makes iptables "see" | 141 | a bridge with Network packet filtering enabled makes iptables "see" |
142 | the bridged traffic. For filtering on the lower network and Ethernet | 142 | the bridged traffic. For filtering on the lower network and Ethernet |
143 | protocols over the bridge, use ebtables (under bridge netfilter | 143 | protocols over the bridge, use ebtables (under bridge netfilter |
144 | configuration). | 144 | configuration). |
145 | 145 | ||
146 | Various modules exist for netfilter which replace the previous | 146 | Various modules exist for netfilter which replace the previous |
147 | masquerading (ipmasqadm), packet filtering (ipchains), transparent | 147 | masquerading (ipmasqadm), packet filtering (ipchains), transparent |
148 | proxying, and portforwarding mechanisms. Please see | 148 | proxying, and portforwarding mechanisms. Please see |
149 | <file:Documentation/Changes> under "iptables" for the location of | 149 | <file:Documentation/Changes> under "iptables" for the location of |
150 | these packages. | 150 | these packages. |
151 | 151 | ||
152 | if NETFILTER | 152 | if NETFILTER |
153 | 153 | ||
154 | config NETFILTER_DEBUG | 154 | config NETFILTER_DEBUG |
155 | bool "Network packet filtering debugging" | 155 | bool "Network packet filtering debugging" |
156 | depends on NETFILTER | 156 | depends on NETFILTER |
157 | help | 157 | help |
158 | You can say Y here if you want to get additional messages useful in | 158 | You can say Y here if you want to get additional messages useful in |
159 | debugging the netfilter code. | 159 | debugging the netfilter code. |
160 | 160 | ||
161 | config NETFILTER_ADVANCED | 161 | config NETFILTER_ADVANCED |
162 | bool "Advanced netfilter configuration" | 162 | bool "Advanced netfilter configuration" |
163 | depends on NETFILTER | 163 | depends on NETFILTER |
164 | default y | 164 | default y |
165 | help | 165 | help |
166 | If you say Y here you can select between all the netfilter modules. | 166 | If you say Y here you can select between all the netfilter modules. |
167 | If you say N the more unusual ones will not be shown and the | 167 | If you say N the more unusual ones will not be shown and the |
168 | basic ones needed by most people will default to 'M'. | 168 | basic ones needed by most people will default to 'M'. |
169 | 169 | ||
170 | If unsure, say Y. | 170 | If unsure, say Y. |
171 | 171 | ||
172 | config BRIDGE_NETFILTER | 172 | config BRIDGE_NETFILTER |
173 | bool "Bridged IP/ARP packets filtering" | 173 | bool "Bridged IP/ARP packets filtering" |
174 | depends on BRIDGE && NETFILTER && INET | 174 | depends on BRIDGE && NETFILTER && INET |
175 | depends on NETFILTER_ADVANCED | 175 | depends on NETFILTER_ADVANCED |
176 | default y | 176 | default y |
177 | ---help--- | 177 | ---help--- |
178 | Enabling this option will let arptables resp. iptables see bridged | 178 | Enabling this option will let arptables resp. iptables see bridged |
179 | ARP resp. IP traffic. If you want a bridging firewall, you probably | 179 | ARP resp. IP traffic. If you want a bridging firewall, you probably |
180 | want this option enabled. | 180 | want this option enabled. |
181 | Enabling or disabling this option doesn't enable or disable | 181 | Enabling or disabling this option doesn't enable or disable |
182 | ebtables. | 182 | ebtables. |
183 | 183 | ||
184 | If unsure, say N. | 184 | If unsure, say N. |
185 | 185 | ||
186 | source "net/netfilter/Kconfig" | 186 | source "net/netfilter/Kconfig" |
187 | source "net/ipv4/netfilter/Kconfig" | 187 | source "net/ipv4/netfilter/Kconfig" |
188 | source "net/ipv6/netfilter/Kconfig" | 188 | source "net/ipv6/netfilter/Kconfig" |
189 | source "net/decnet/netfilter/Kconfig" | 189 | source "net/decnet/netfilter/Kconfig" |
190 | source "net/bridge/netfilter/Kconfig" | 190 | source "net/bridge/netfilter/Kconfig" |
191 | 191 | ||
192 | endif | 192 | endif |
193 | 193 | ||
194 | source "net/dccp/Kconfig" | 194 | source "net/dccp/Kconfig" |
195 | source "net/sctp/Kconfig" | 195 | source "net/sctp/Kconfig" |
196 | source "net/rds/Kconfig" | 196 | source "net/rds/Kconfig" |
197 | source "net/tipc/Kconfig" | 197 | source "net/tipc/Kconfig" |
198 | source "net/atm/Kconfig" | 198 | source "net/atm/Kconfig" |
199 | source "net/l2tp/Kconfig" | 199 | source "net/l2tp/Kconfig" |
200 | source "net/802/Kconfig" | 200 | source "net/802/Kconfig" |
201 | source "net/bridge/Kconfig" | 201 | source "net/bridge/Kconfig" |
202 | source "net/dsa/Kconfig" | 202 | source "net/dsa/Kconfig" |
203 | source "net/8021q/Kconfig" | 203 | source "net/8021q/Kconfig" |
204 | source "net/decnet/Kconfig" | 204 | source "net/decnet/Kconfig" |
205 | source "net/llc/Kconfig" | 205 | source "net/llc/Kconfig" |
206 | source "net/ipx/Kconfig" | 206 | source "net/ipx/Kconfig" |
207 | source "drivers/net/appletalk/Kconfig" | 207 | source "drivers/net/appletalk/Kconfig" |
208 | source "net/x25/Kconfig" | 208 | source "net/x25/Kconfig" |
209 | source "net/lapb/Kconfig" | 209 | source "net/lapb/Kconfig" |
210 | source "net/econet/Kconfig" | 210 | source "net/econet/Kconfig" |
211 | source "net/wanrouter/Kconfig" | 211 | source "net/wanrouter/Kconfig" |
212 | source "net/phonet/Kconfig" | 212 | source "net/phonet/Kconfig" |
213 | source "net/ieee802154/Kconfig" | 213 | source "net/ieee802154/Kconfig" |
214 | source "net/sched/Kconfig" | 214 | source "net/sched/Kconfig" |
215 | source "net/dcb/Kconfig" | 215 | source "net/dcb/Kconfig" |
216 | source "net/dns_resolver/Kconfig" | 216 | source "net/dns_resolver/Kconfig" |
217 | 217 | ||
218 | config RPS | 218 | config RPS |
219 | boolean | 219 | boolean |
220 | depends on SMP && SYSFS && USE_GENERIC_SMP_HELPERS | 220 | depends on SMP && SYSFS && USE_GENERIC_SMP_HELPERS |
221 | default y | 221 | default y |
222 | 222 | ||
223 | config XPS | ||
224 | boolean | ||
225 | depends on SMP && SYSFS && USE_GENERIC_SMP_HELPERS | ||
226 | default y | ||
227 | |||
223 | menu "Network testing" | 228 | menu "Network testing" |
224 | 229 | ||
225 | config NET_PKTGEN | 230 | config NET_PKTGEN |
226 | tristate "Packet Generator (USE WITH CAUTION)" | 231 | tristate "Packet Generator (USE WITH CAUTION)" |
227 | depends on PROC_FS | 232 | depends on PROC_FS |
228 | ---help--- | 233 | ---help--- |
229 | This module will inject preconfigured packets, at a configurable | 234 | This module will inject preconfigured packets, at a configurable |
230 | rate, out of a given interface. It is used for network interface | 235 | rate, out of a given interface. It is used for network interface |
231 | stress testing and performance analysis. If you don't understand | 236 | stress testing and performance analysis. If you don't understand |
232 | what was just said, you don't need it: say N. | 237 | what was just said, you don't need it: say N. |
233 | 238 | ||
234 | Documentation on how to use the packet generator can be found | 239 | Documentation on how to use the packet generator can be found |
235 | at <file:Documentation/networking/pktgen.txt>. | 240 | at <file:Documentation/networking/pktgen.txt>. |
236 | 241 | ||
237 | To compile this code as a module, choose M here: the | 242 | To compile this code as a module, choose M here: the |
238 | module will be called pktgen. | 243 | module will be called pktgen. |
239 | 244 | ||
240 | config NET_TCPPROBE | 245 | config NET_TCPPROBE |
241 | tristate "TCP connection probing" | 246 | tristate "TCP connection probing" |
242 | depends on INET && EXPERIMENTAL && PROC_FS && KPROBES | 247 | depends on INET && EXPERIMENTAL && PROC_FS && KPROBES |
243 | ---help--- | 248 | ---help--- |
244 | This module allows for capturing the changes to TCP connection | 249 | This module allows for capturing the changes to TCP connection |
245 | state in response to incoming packets. It is used for debugging | 250 | state in response to incoming packets. It is used for debugging |
246 | TCP congestion avoidance modules. If you don't understand | 251 | TCP congestion avoidance modules. If you don't understand |
247 | what was just said, you don't need it: say N. | 252 | what was just said, you don't need it: say N. |
248 | 253 | ||
249 | Documentation on how to use TCP connection probing can be found | 254 | Documentation on how to use TCP connection probing can be found |
250 | at http://linux-net.osdl.org/index.php/TcpProbe | 255 | at http://linux-net.osdl.org/index.php/TcpProbe |
251 | 256 | ||
252 | To compile this code as a module, choose M here: the | 257 | To compile this code as a module, choose M here: the |
253 | module will be called tcp_probe. | 258 | module will be called tcp_probe. |
254 | 259 | ||
255 | config NET_DROP_MONITOR | 260 | config NET_DROP_MONITOR |
256 | boolean "Network packet drop alerting service" | 261 | boolean "Network packet drop alerting service" |
257 | depends on INET && EXPERIMENTAL && TRACEPOINTS | 262 | depends on INET && EXPERIMENTAL && TRACEPOINTS |
258 | ---help--- | 263 | ---help--- |
259 | This feature provides an alerting service to userspace in the | 264 | This feature provides an alerting service to userspace in the |
260 | event that packets are discarded in the network stack. Alerts | 265 | event that packets are discarded in the network stack. Alerts |
261 | are broadcast via netlink socket to any listening user space | 266 | are broadcast via netlink socket to any listening user space |
262 | process. If you don't need network drop alerts, or if you are ok | 267 | process. If you don't need network drop alerts, or if you are ok |
263 | just checking the various proc files and other utilities for | 268 | just checking the various proc files and other utilities for |
264 | drop statistics, say N here. | 269 | drop statistics, say N here. |
265 | 270 | ||
266 | endmenu | 271 | endmenu |
267 | 272 | ||
268 | endmenu | 273 | endmenu |
269 | 274 | ||
270 | source "net/ax25/Kconfig" | 275 | source "net/ax25/Kconfig" |
271 | source "net/can/Kconfig" | 276 | source "net/can/Kconfig" |
272 | source "net/irda/Kconfig" | 277 | source "net/irda/Kconfig" |
273 | source "net/bluetooth/Kconfig" | 278 | source "net/bluetooth/Kconfig" |
274 | source "net/rxrpc/Kconfig" | 279 | source "net/rxrpc/Kconfig" |
275 | 280 | ||
276 | config FIB_RULES | 281 | config FIB_RULES |
277 | bool | 282 | bool |
278 | 283 | ||
279 | menuconfig WIRELESS | 284 | menuconfig WIRELESS |
280 | bool "Wireless" | 285 | bool "Wireless" |
281 | depends on !S390 | 286 | depends on !S390 |
282 | default y | 287 | default y |
283 | 288 | ||
284 | if WIRELESS | 289 | if WIRELESS |
285 | 290 | ||
286 | source "net/wireless/Kconfig" | 291 | source "net/wireless/Kconfig" |
287 | source "net/mac80211/Kconfig" | 292 | source "net/mac80211/Kconfig" |
288 | 293 | ||
289 | endif # WIRELESS | 294 | endif # WIRELESS |
290 | 295 | ||
291 | source "net/wimax/Kconfig" | 296 | source "net/wimax/Kconfig" |
292 | 297 | ||
293 | source "net/rfkill/Kconfig" | 298 | source "net/rfkill/Kconfig" |
294 | source "net/9p/Kconfig" | 299 | source "net/9p/Kconfig" |
295 | source "net/caif/Kconfig" | 300 | source "net/caif/Kconfig" |
296 | source "net/ceph/Kconfig" | 301 | source "net/ceph/Kconfig" |
297 | 302 | ||
298 | 303 | ||
299 | endif # if NET | 304 | endif # if NET |
300 | 305 |
net/core/dev.c
1 | /* | 1 | /* |
2 | * NET3 Protocol independent device support routines. | 2 | * NET3 Protocol independent device support routines. |
3 | * | 3 | * |
4 | * This program is free software; you can redistribute it and/or | 4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU General Public License | 5 | * modify it under the terms of the GNU General Public License |
6 | * as published by the Free Software Foundation; either version | 6 | * as published by the Free Software Foundation; either version |
7 | * 2 of the License, or (at your option) any later version. | 7 | * 2 of the License, or (at your option) any later version. |
8 | * | 8 | * |
9 | * Derived from the non IP parts of dev.c 1.0.19 | 9 | * Derived from the non IP parts of dev.c 1.0.19 |
10 | * Authors: Ross Biro | 10 | * Authors: Ross Biro |
11 | * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> | 11 | * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> |
12 | * Mark Evans, <evansmp@uhura.aston.ac.uk> | 12 | * Mark Evans, <evansmp@uhura.aston.ac.uk> |
13 | * | 13 | * |
14 | * Additional Authors: | 14 | * Additional Authors: |
15 | * Florian la Roche <rzsfl@rz.uni-sb.de> | 15 | * Florian la Roche <rzsfl@rz.uni-sb.de> |
16 | * Alan Cox <gw4pts@gw4pts.ampr.org> | 16 | * Alan Cox <gw4pts@gw4pts.ampr.org> |
17 | * David Hinds <dahinds@users.sourceforge.net> | 17 | * David Hinds <dahinds@users.sourceforge.net> |
18 | * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru> | 18 | * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru> |
19 | * Adam Sulmicki <adam@cfar.umd.edu> | 19 | * Adam Sulmicki <adam@cfar.umd.edu> |
20 | * Pekka Riikonen <priikone@poesidon.pspt.fi> | 20 | * Pekka Riikonen <priikone@poesidon.pspt.fi> |
21 | * | 21 | * |
22 | * Changes: | 22 | * Changes: |
23 | * D.J. Barrow : Fixed bug where dev->refcnt gets set | 23 | * D.J. Barrow : Fixed bug where dev->refcnt gets set |
24 | * to 2 if register_netdev gets called | 24 | * to 2 if register_netdev gets called |
25 | * before net_dev_init & also removed a | 25 | * before net_dev_init & also removed a |
26 | * few lines of code in the process. | 26 | * few lines of code in the process. |
27 | * Alan Cox : device private ioctl copies fields back. | 27 | * Alan Cox : device private ioctl copies fields back. |
28 | * Alan Cox : Transmit queue code does relevant | 28 | * Alan Cox : Transmit queue code does relevant |
29 | * stunts to keep the queue safe. | 29 | * stunts to keep the queue safe. |
30 | * Alan Cox : Fixed double lock. | 30 | * Alan Cox : Fixed double lock. |
31 | * Alan Cox : Fixed promisc NULL pointer trap | 31 | * Alan Cox : Fixed promisc NULL pointer trap |
32 | * ???????? : Support the full private ioctl range | 32 | * ???????? : Support the full private ioctl range |
33 | * Alan Cox : Moved ioctl permission check into | 33 | * Alan Cox : Moved ioctl permission check into |
34 | * drivers | 34 | * drivers |
35 | * Tim Kordas : SIOCADDMULTI/SIOCDELMULTI | 35 | * Tim Kordas : SIOCADDMULTI/SIOCDELMULTI |
36 | * Alan Cox : 100 backlog just doesn't cut it when | 36 | * Alan Cox : 100 backlog just doesn't cut it when |
37 | * you start doing multicast video 8) | 37 | * you start doing multicast video 8) |
38 | * Alan Cox : Rewrote net_bh and list manager. | 38 | * Alan Cox : Rewrote net_bh and list manager. |
39 | * Alan Cox : Fix ETH_P_ALL echoback lengths. | 39 | * Alan Cox : Fix ETH_P_ALL echoback lengths. |
40 | * Alan Cox : Took out transmit every packet pass | 40 | * Alan Cox : Took out transmit every packet pass |
41 | * Saved a few bytes in the ioctl handler | 41 | * Saved a few bytes in the ioctl handler |
42 | * Alan Cox : Network driver sets packet type before | 42 | * Alan Cox : Network driver sets packet type before |
43 | * calling netif_rx. Saves a function | 43 | * calling netif_rx. Saves a function |
44 | * call a packet. | 44 | * call a packet. |
45 | * Alan Cox : Hashed net_bh() | 45 | * Alan Cox : Hashed net_bh() |
46 | * Richard Kooijman: Timestamp fixes. | 46 | * Richard Kooijman: Timestamp fixes. |
47 | * Alan Cox : Wrong field in SIOCGIFDSTADDR | 47 | * Alan Cox : Wrong field in SIOCGIFDSTADDR |
48 | * Alan Cox : Device lock protection. | 48 | * Alan Cox : Device lock protection. |
49 | * Alan Cox : Fixed nasty side effect of device close | 49 | * Alan Cox : Fixed nasty side effect of device close |
50 | * changes. | 50 | * changes. |
51 | * Rudi Cilibrasi : Pass the right thing to | 51 | * Rudi Cilibrasi : Pass the right thing to |
52 | * set_mac_address() | 52 | * set_mac_address() |
53 | * Dave Miller : 32bit quantity for the device lock to | 53 | * Dave Miller : 32bit quantity for the device lock to |
54 | * make it work out on a Sparc. | 54 | * make it work out on a Sparc. |
55 | * Bjorn Ekwall : Added KERNELD hack. | 55 | * Bjorn Ekwall : Added KERNELD hack. |
56 | * Alan Cox : Cleaned up the backlog initialise. | 56 | * Alan Cox : Cleaned up the backlog initialise. |
57 | * Craig Metz : SIOCGIFCONF fix if space for under | 57 | * Craig Metz : SIOCGIFCONF fix if space for under |
58 | * 1 device. | 58 | * 1 device. |
59 | * Thomas Bogendoerfer : Return ENODEV for dev_open, if there | 59 | * Thomas Bogendoerfer : Return ENODEV for dev_open, if there |
60 | * is no device open function. | 60 | * is no device open function. |
61 | * Andi Kleen : Fix error reporting for SIOCGIFCONF | 61 | * Andi Kleen : Fix error reporting for SIOCGIFCONF |
62 | * Michael Chastain : Fix signed/unsigned for SIOCGIFCONF | 62 | * Michael Chastain : Fix signed/unsigned for SIOCGIFCONF |
63 | * Cyrus Durgin : Cleaned for KMOD | 63 | * Cyrus Durgin : Cleaned for KMOD |
64 | * Adam Sulmicki : Bug Fix : Network Device Unload | 64 | * Adam Sulmicki : Bug Fix : Network Device Unload |
65 | * A network device unload needs to purge | 65 | * A network device unload needs to purge |
66 | * the backlog queue. | 66 | * the backlog queue. |
67 | * Paul Rusty Russell : SIOCSIFNAME | 67 | * Paul Rusty Russell : SIOCSIFNAME |
68 | * Pekka Riikonen : Netdev boot-time settings code | 68 | * Pekka Riikonen : Netdev boot-time settings code |
69 | * Andrew Morton : Make unregister_netdevice wait | 69 | * Andrew Morton : Make unregister_netdevice wait |
70 | * indefinitely on dev->refcnt | 70 | * indefinitely on dev->refcnt |
71 | * J Hadi Salim : - Backlog queue sampling | 71 | * J Hadi Salim : - Backlog queue sampling |
72 | * - netif_rx() feedback | 72 | * - netif_rx() feedback |
73 | */ | 73 | */ |
74 | 74 | ||
75 | #include <asm/uaccess.h> | 75 | #include <asm/uaccess.h> |
76 | #include <asm/system.h> | 76 | #include <asm/system.h> |
77 | #include <linux/bitops.h> | 77 | #include <linux/bitops.h> |
78 | #include <linux/capability.h> | 78 | #include <linux/capability.h> |
79 | #include <linux/cpu.h> | 79 | #include <linux/cpu.h> |
80 | #include <linux/types.h> | 80 | #include <linux/types.h> |
81 | #include <linux/kernel.h> | 81 | #include <linux/kernel.h> |
82 | #include <linux/hash.h> | 82 | #include <linux/hash.h> |
83 | #include <linux/slab.h> | 83 | #include <linux/slab.h> |
84 | #include <linux/sched.h> | 84 | #include <linux/sched.h> |
85 | #include <linux/mutex.h> | 85 | #include <linux/mutex.h> |
86 | #include <linux/string.h> | 86 | #include <linux/string.h> |
87 | #include <linux/mm.h> | 87 | #include <linux/mm.h> |
88 | #include <linux/socket.h> | 88 | #include <linux/socket.h> |
89 | #include <linux/sockios.h> | 89 | #include <linux/sockios.h> |
90 | #include <linux/errno.h> | 90 | #include <linux/errno.h> |
91 | #include <linux/interrupt.h> | 91 | #include <linux/interrupt.h> |
92 | #include <linux/if_ether.h> | 92 | #include <linux/if_ether.h> |
93 | #include <linux/netdevice.h> | 93 | #include <linux/netdevice.h> |
94 | #include <linux/etherdevice.h> | 94 | #include <linux/etherdevice.h> |
95 | #include <linux/ethtool.h> | 95 | #include <linux/ethtool.h> |
96 | #include <linux/notifier.h> | 96 | #include <linux/notifier.h> |
97 | #include <linux/skbuff.h> | 97 | #include <linux/skbuff.h> |
98 | #include <net/net_namespace.h> | 98 | #include <net/net_namespace.h> |
99 | #include <net/sock.h> | 99 | #include <net/sock.h> |
100 | #include <linux/rtnetlink.h> | 100 | #include <linux/rtnetlink.h> |
101 | #include <linux/proc_fs.h> | 101 | #include <linux/proc_fs.h> |
102 | #include <linux/seq_file.h> | 102 | #include <linux/seq_file.h> |
103 | #include <linux/stat.h> | 103 | #include <linux/stat.h> |
104 | #include <net/dst.h> | 104 | #include <net/dst.h> |
105 | #include <net/pkt_sched.h> | 105 | #include <net/pkt_sched.h> |
106 | #include <net/checksum.h> | 106 | #include <net/checksum.h> |
107 | #include <net/xfrm.h> | 107 | #include <net/xfrm.h> |
108 | #include <linux/highmem.h> | 108 | #include <linux/highmem.h> |
109 | #include <linux/init.h> | 109 | #include <linux/init.h> |
110 | #include <linux/kmod.h> | 110 | #include <linux/kmod.h> |
111 | #include <linux/module.h> | 111 | #include <linux/module.h> |
112 | #include <linux/netpoll.h> | 112 | #include <linux/netpoll.h> |
113 | #include <linux/rcupdate.h> | 113 | #include <linux/rcupdate.h> |
114 | #include <linux/delay.h> | 114 | #include <linux/delay.h> |
115 | #include <net/wext.h> | 115 | #include <net/wext.h> |
116 | #include <net/iw_handler.h> | 116 | #include <net/iw_handler.h> |
117 | #include <asm/current.h> | 117 | #include <asm/current.h> |
118 | #include <linux/audit.h> | 118 | #include <linux/audit.h> |
119 | #include <linux/dmaengine.h> | 119 | #include <linux/dmaengine.h> |
120 | #include <linux/err.h> | 120 | #include <linux/err.h> |
121 | #include <linux/ctype.h> | 121 | #include <linux/ctype.h> |
122 | #include <linux/if_arp.h> | 122 | #include <linux/if_arp.h> |
123 | #include <linux/if_vlan.h> | 123 | #include <linux/if_vlan.h> |
124 | #include <linux/ip.h> | 124 | #include <linux/ip.h> |
125 | #include <net/ip.h> | 125 | #include <net/ip.h> |
126 | #include <linux/ipv6.h> | 126 | #include <linux/ipv6.h> |
127 | #include <linux/in.h> | 127 | #include <linux/in.h> |
128 | #include <linux/jhash.h> | 128 | #include <linux/jhash.h> |
129 | #include <linux/random.h> | 129 | #include <linux/random.h> |
130 | #include <trace/events/napi.h> | 130 | #include <trace/events/napi.h> |
131 | #include <trace/events/net.h> | 131 | #include <trace/events/net.h> |
132 | #include <trace/events/skb.h> | 132 | #include <trace/events/skb.h> |
133 | #include <linux/pci.h> | 133 | #include <linux/pci.h> |
134 | #include <linux/inetdevice.h> | 134 | #include <linux/inetdevice.h> |
135 | 135 | ||
136 | #include "net-sysfs.h" | 136 | #include "net-sysfs.h" |
137 | 137 | ||
138 | /* Instead of increasing this, you should create a hash table. */ | 138 | /* Instead of increasing this, you should create a hash table. */ |
139 | #define MAX_GRO_SKBS 8 | 139 | #define MAX_GRO_SKBS 8 |
140 | 140 | ||
141 | /* This should be increased if a protocol with a bigger head is added. */ | 141 | /* This should be increased if a protocol with a bigger head is added. */ |
142 | #define GRO_MAX_HEAD (MAX_HEADER + 128) | 142 | #define GRO_MAX_HEAD (MAX_HEADER + 128) |
143 | 143 | ||
144 | /* | 144 | /* |
145 | * The list of packet types we will receive (as opposed to discard) | 145 | * The list of packet types we will receive (as opposed to discard) |
146 | * and the routines to invoke. | 146 | * and the routines to invoke. |
147 | * | 147 | * |
148 | * Why 16. Because with 16 the only overlap we get on a hash of the | 148 | * Why 16. Because with 16 the only overlap we get on a hash of the |
149 | * low nibble of the protocol value is RARP/SNAP/X.25. | 149 | * low nibble of the protocol value is RARP/SNAP/X.25. |
150 | * | 150 | * |
151 | * NOTE: That is no longer true with the addition of VLAN tags. Not | 151 | * NOTE: That is no longer true with the addition of VLAN tags. Not |
152 | * sure which should go first, but I bet it won't make much | 152 | * sure which should go first, but I bet it won't make much |
153 | * difference if we are running VLANs. The good news is that | 153 | * difference if we are running VLANs. The good news is that |
154 | * this protocol won't be in the list unless compiled in, so | 154 | * this protocol won't be in the list unless compiled in, so |
155 | * the average user (w/out VLANs) will not be adversely affected. | 155 | * the average user (w/out VLANs) will not be adversely affected. |
156 | * --BLG | 156 | * --BLG |
157 | * | 157 | * |
158 | * 0800 IP | 158 | * 0800 IP |
159 | * 8100 802.1Q VLAN | 159 | * 8100 802.1Q VLAN |
160 | * 0001 802.3 | 160 | * 0001 802.3 |
161 | * 0002 AX.25 | 161 | * 0002 AX.25 |
162 | * 0004 802.2 | 162 | * 0004 802.2 |
163 | * 8035 RARP | 163 | * 8035 RARP |
164 | * 0005 SNAP | 164 | * 0005 SNAP |
165 | * 0805 X.25 | 165 | * 0805 X.25 |
166 | * 0806 ARP | 166 | * 0806 ARP |
167 | * 8137 IPX | 167 | * 8137 IPX |
168 | * 0009 Localtalk | 168 | * 0009 Localtalk |
169 | * 86DD IPv6 | 169 | * 86DD IPv6 |
170 | */ | 170 | */ |
171 | 171 | ||
172 | #define PTYPE_HASH_SIZE (16) | 172 | #define PTYPE_HASH_SIZE (16) |
173 | #define PTYPE_HASH_MASK (PTYPE_HASH_SIZE - 1) | 173 | #define PTYPE_HASH_MASK (PTYPE_HASH_SIZE - 1) |
174 | 174 | ||
175 | static DEFINE_SPINLOCK(ptype_lock); | 175 | static DEFINE_SPINLOCK(ptype_lock); |
176 | static struct list_head ptype_base[PTYPE_HASH_SIZE] __read_mostly; | 176 | static struct list_head ptype_base[PTYPE_HASH_SIZE] __read_mostly; |
177 | static struct list_head ptype_all __read_mostly; /* Taps */ | 177 | static struct list_head ptype_all __read_mostly; /* Taps */ |
178 | 178 | ||
179 | /* | 179 | /* |
180 | * The @dev_base_head list is protected by @dev_base_lock and the rtnl | 180 | * The @dev_base_head list is protected by @dev_base_lock and the rtnl |
181 | * semaphore. | 181 | * semaphore. |
182 | * | 182 | * |
183 | * Pure readers hold dev_base_lock for reading, or rcu_read_lock() | 183 | * Pure readers hold dev_base_lock for reading, or rcu_read_lock() |
184 | * | 184 | * |
185 | * Writers must hold the rtnl semaphore while they loop through the | 185 | * Writers must hold the rtnl semaphore while they loop through the |
186 | * dev_base_head list, and hold dev_base_lock for writing when they do the | 186 | * dev_base_head list, and hold dev_base_lock for writing when they do the |
187 | * actual updates. This allows pure readers to access the list even | 187 | * actual updates. This allows pure readers to access the list even |
188 | * while a writer is preparing to update it. | 188 | * while a writer is preparing to update it. |
189 | * | 189 | * |
190 | * To put it another way, dev_base_lock is held for writing only to | 190 | * To put it another way, dev_base_lock is held for writing only to |
191 | * protect against pure readers; the rtnl semaphore provides the | 191 | * protect against pure readers; the rtnl semaphore provides the |
192 | * protection against other writers. | 192 | * protection against other writers. |
193 | * | 193 | * |
194 | * See, for example usages, register_netdevice() and | 194 | * See, for example usages, register_netdevice() and |
195 | * unregister_netdevice(), which must be called with the rtnl | 195 | * unregister_netdevice(), which must be called with the rtnl |
196 | * semaphore held. | 196 | * semaphore held. |
197 | */ | 197 | */ |
198 | DEFINE_RWLOCK(dev_base_lock); | 198 | DEFINE_RWLOCK(dev_base_lock); |
199 | EXPORT_SYMBOL(dev_base_lock); | 199 | EXPORT_SYMBOL(dev_base_lock); |
200 | 200 | ||
201 | static inline struct hlist_head *dev_name_hash(struct net *net, const char *name) | 201 | static inline struct hlist_head *dev_name_hash(struct net *net, const char *name) |
202 | { | 202 | { |
203 | unsigned hash = full_name_hash(name, strnlen(name, IFNAMSIZ)); | 203 | unsigned hash = full_name_hash(name, strnlen(name, IFNAMSIZ)); |
204 | return &net->dev_name_head[hash_32(hash, NETDEV_HASHBITS)]; | 204 | return &net->dev_name_head[hash_32(hash, NETDEV_HASHBITS)]; |
205 | } | 205 | } |
206 | 206 | ||
207 | static inline struct hlist_head *dev_index_hash(struct net *net, int ifindex) | 207 | static inline struct hlist_head *dev_index_hash(struct net *net, int ifindex) |
208 | { | 208 | { |
209 | return &net->dev_index_head[ifindex & (NETDEV_HASHENTRIES - 1)]; | 209 | return &net->dev_index_head[ifindex & (NETDEV_HASHENTRIES - 1)]; |
210 | } | 210 | } |
211 | 211 | ||
212 | static inline void rps_lock(struct softnet_data *sd) | 212 | static inline void rps_lock(struct softnet_data *sd) |
213 | { | 213 | { |
214 | #ifdef CONFIG_RPS | 214 | #ifdef CONFIG_RPS |
215 | spin_lock(&sd->input_pkt_queue.lock); | 215 | spin_lock(&sd->input_pkt_queue.lock); |
216 | #endif | 216 | #endif |
217 | } | 217 | } |
218 | 218 | ||
219 | static inline void rps_unlock(struct softnet_data *sd) | 219 | static inline void rps_unlock(struct softnet_data *sd) |
220 | { | 220 | { |
221 | #ifdef CONFIG_RPS | 221 | #ifdef CONFIG_RPS |
222 | spin_unlock(&sd->input_pkt_queue.lock); | 222 | spin_unlock(&sd->input_pkt_queue.lock); |
223 | #endif | 223 | #endif |
224 | } | 224 | } |
225 | 225 | ||
226 | /* Device list insertion */ | 226 | /* Device list insertion */ |
227 | static int list_netdevice(struct net_device *dev) | 227 | static int list_netdevice(struct net_device *dev) |
228 | { | 228 | { |
229 | struct net *net = dev_net(dev); | 229 | struct net *net = dev_net(dev); |
230 | 230 | ||
231 | ASSERT_RTNL(); | 231 | ASSERT_RTNL(); |
232 | 232 | ||
233 | write_lock_bh(&dev_base_lock); | 233 | write_lock_bh(&dev_base_lock); |
234 | list_add_tail_rcu(&dev->dev_list, &net->dev_base_head); | 234 | list_add_tail_rcu(&dev->dev_list, &net->dev_base_head); |
235 | hlist_add_head_rcu(&dev->name_hlist, dev_name_hash(net, dev->name)); | 235 | hlist_add_head_rcu(&dev->name_hlist, dev_name_hash(net, dev->name)); |
236 | hlist_add_head_rcu(&dev->index_hlist, | 236 | hlist_add_head_rcu(&dev->index_hlist, |
237 | dev_index_hash(net, dev->ifindex)); | 237 | dev_index_hash(net, dev->ifindex)); |
238 | write_unlock_bh(&dev_base_lock); | 238 | write_unlock_bh(&dev_base_lock); |
239 | return 0; | 239 | return 0; |
240 | } | 240 | } |
241 | 241 | ||
242 | /* Device list removal | 242 | /* Device list removal |
243 | * caller must respect a RCU grace period before freeing/reusing dev | 243 | * caller must respect a RCU grace period before freeing/reusing dev |
244 | */ | 244 | */ |
245 | static void unlist_netdevice(struct net_device *dev) | 245 | static void unlist_netdevice(struct net_device *dev) |
246 | { | 246 | { |
247 | ASSERT_RTNL(); | 247 | ASSERT_RTNL(); |
248 | 248 | ||
249 | /* Unlink dev from the device chain */ | 249 | /* Unlink dev from the device chain */ |
250 | write_lock_bh(&dev_base_lock); | 250 | write_lock_bh(&dev_base_lock); |
251 | list_del_rcu(&dev->dev_list); | 251 | list_del_rcu(&dev->dev_list); |
252 | hlist_del_rcu(&dev->name_hlist); | 252 | hlist_del_rcu(&dev->name_hlist); |
253 | hlist_del_rcu(&dev->index_hlist); | 253 | hlist_del_rcu(&dev->index_hlist); |
254 | write_unlock_bh(&dev_base_lock); | 254 | write_unlock_bh(&dev_base_lock); |
255 | } | 255 | } |
256 | 256 | ||
257 | /* | 257 | /* |
258 | * Our notifier list | 258 | * Our notifier list |
259 | */ | 259 | */ |
260 | 260 | ||
261 | static RAW_NOTIFIER_HEAD(netdev_chain); | 261 | static RAW_NOTIFIER_HEAD(netdev_chain); |
262 | 262 | ||
263 | /* | 263 | /* |
264 | * Device drivers call our routines to queue packets here. We empty the | 264 | * Device drivers call our routines to queue packets here. We empty the |
265 | * queue in the local softnet handler. | 265 | * queue in the local softnet handler. |
266 | */ | 266 | */ |
267 | 267 | ||
268 | DEFINE_PER_CPU_ALIGNED(struct softnet_data, softnet_data); | 268 | DEFINE_PER_CPU_ALIGNED(struct softnet_data, softnet_data); |
269 | EXPORT_PER_CPU_SYMBOL(softnet_data); | 269 | EXPORT_PER_CPU_SYMBOL(softnet_data); |
270 | 270 | ||
271 | #ifdef CONFIG_LOCKDEP | 271 | #ifdef CONFIG_LOCKDEP |
272 | /* | 272 | /* |
273 | * register_netdevice() inits txq->_xmit_lock and sets lockdep class | 273 | * register_netdevice() inits txq->_xmit_lock and sets lockdep class |
274 | * according to dev->type | 274 | * according to dev->type |
275 | */ | 275 | */ |
276 | static const unsigned short netdev_lock_type[] = | 276 | static const unsigned short netdev_lock_type[] = |
277 | {ARPHRD_NETROM, ARPHRD_ETHER, ARPHRD_EETHER, ARPHRD_AX25, | 277 | {ARPHRD_NETROM, ARPHRD_ETHER, ARPHRD_EETHER, ARPHRD_AX25, |
278 | ARPHRD_PRONET, ARPHRD_CHAOS, ARPHRD_IEEE802, ARPHRD_ARCNET, | 278 | ARPHRD_PRONET, ARPHRD_CHAOS, ARPHRD_IEEE802, ARPHRD_ARCNET, |
279 | ARPHRD_APPLETLK, ARPHRD_DLCI, ARPHRD_ATM, ARPHRD_METRICOM, | 279 | ARPHRD_APPLETLK, ARPHRD_DLCI, ARPHRD_ATM, ARPHRD_METRICOM, |
280 | ARPHRD_IEEE1394, ARPHRD_EUI64, ARPHRD_INFINIBAND, ARPHRD_SLIP, | 280 | ARPHRD_IEEE1394, ARPHRD_EUI64, ARPHRD_INFINIBAND, ARPHRD_SLIP, |
281 | ARPHRD_CSLIP, ARPHRD_SLIP6, ARPHRD_CSLIP6, ARPHRD_RSRVD, | 281 | ARPHRD_CSLIP, ARPHRD_SLIP6, ARPHRD_CSLIP6, ARPHRD_RSRVD, |
282 | ARPHRD_ADAPT, ARPHRD_ROSE, ARPHRD_X25, ARPHRD_HWX25, | 282 | ARPHRD_ADAPT, ARPHRD_ROSE, ARPHRD_X25, ARPHRD_HWX25, |
283 | ARPHRD_PPP, ARPHRD_CISCO, ARPHRD_LAPB, ARPHRD_DDCMP, | 283 | ARPHRD_PPP, ARPHRD_CISCO, ARPHRD_LAPB, ARPHRD_DDCMP, |
284 | ARPHRD_RAWHDLC, ARPHRD_TUNNEL, ARPHRD_TUNNEL6, ARPHRD_FRAD, | 284 | ARPHRD_RAWHDLC, ARPHRD_TUNNEL, ARPHRD_TUNNEL6, ARPHRD_FRAD, |
285 | ARPHRD_SKIP, ARPHRD_LOOPBACK, ARPHRD_LOCALTLK, ARPHRD_FDDI, | 285 | ARPHRD_SKIP, ARPHRD_LOOPBACK, ARPHRD_LOCALTLK, ARPHRD_FDDI, |
286 | ARPHRD_BIF, ARPHRD_SIT, ARPHRD_IPDDP, ARPHRD_IPGRE, | 286 | ARPHRD_BIF, ARPHRD_SIT, ARPHRD_IPDDP, ARPHRD_IPGRE, |
287 | ARPHRD_PIMREG, ARPHRD_HIPPI, ARPHRD_ASH, ARPHRD_ECONET, | 287 | ARPHRD_PIMREG, ARPHRD_HIPPI, ARPHRD_ASH, ARPHRD_ECONET, |
288 | ARPHRD_IRDA, ARPHRD_FCPP, ARPHRD_FCAL, ARPHRD_FCPL, | 288 | ARPHRD_IRDA, ARPHRD_FCPP, ARPHRD_FCAL, ARPHRD_FCPL, |
289 | ARPHRD_FCFABRIC, ARPHRD_IEEE802_TR, ARPHRD_IEEE80211, | 289 | ARPHRD_FCFABRIC, ARPHRD_IEEE802_TR, ARPHRD_IEEE80211, |
290 | ARPHRD_IEEE80211_PRISM, ARPHRD_IEEE80211_RADIOTAP, ARPHRD_PHONET, | 290 | ARPHRD_IEEE80211_PRISM, ARPHRD_IEEE80211_RADIOTAP, ARPHRD_PHONET, |
291 | ARPHRD_PHONET_PIPE, ARPHRD_IEEE802154, | 291 | ARPHRD_PHONET_PIPE, ARPHRD_IEEE802154, |
292 | ARPHRD_VOID, ARPHRD_NONE}; | 292 | ARPHRD_VOID, ARPHRD_NONE}; |
293 | 293 | ||
294 | static const char *const netdev_lock_name[] = | 294 | static const char *const netdev_lock_name[] = |
295 | {"_xmit_NETROM", "_xmit_ETHER", "_xmit_EETHER", "_xmit_AX25", | 295 | {"_xmit_NETROM", "_xmit_ETHER", "_xmit_EETHER", "_xmit_AX25", |
296 | "_xmit_PRONET", "_xmit_CHAOS", "_xmit_IEEE802", "_xmit_ARCNET", | 296 | "_xmit_PRONET", "_xmit_CHAOS", "_xmit_IEEE802", "_xmit_ARCNET", |
297 | "_xmit_APPLETLK", "_xmit_DLCI", "_xmit_ATM", "_xmit_METRICOM", | 297 | "_xmit_APPLETLK", "_xmit_DLCI", "_xmit_ATM", "_xmit_METRICOM", |
298 | "_xmit_IEEE1394", "_xmit_EUI64", "_xmit_INFINIBAND", "_xmit_SLIP", | 298 | "_xmit_IEEE1394", "_xmit_EUI64", "_xmit_INFINIBAND", "_xmit_SLIP", |
299 | "_xmit_CSLIP", "_xmit_SLIP6", "_xmit_CSLIP6", "_xmit_RSRVD", | 299 | "_xmit_CSLIP", "_xmit_SLIP6", "_xmit_CSLIP6", "_xmit_RSRVD", |
300 | "_xmit_ADAPT", "_xmit_ROSE", "_xmit_X25", "_xmit_HWX25", | 300 | "_xmit_ADAPT", "_xmit_ROSE", "_xmit_X25", "_xmit_HWX25", |
301 | "_xmit_PPP", "_xmit_CISCO", "_xmit_LAPB", "_xmit_DDCMP", | 301 | "_xmit_PPP", "_xmit_CISCO", "_xmit_LAPB", "_xmit_DDCMP", |
302 | "_xmit_RAWHDLC", "_xmit_TUNNEL", "_xmit_TUNNEL6", "_xmit_FRAD", | 302 | "_xmit_RAWHDLC", "_xmit_TUNNEL", "_xmit_TUNNEL6", "_xmit_FRAD", |
303 | "_xmit_SKIP", "_xmit_LOOPBACK", "_xmit_LOCALTLK", "_xmit_FDDI", | 303 | "_xmit_SKIP", "_xmit_LOOPBACK", "_xmit_LOCALTLK", "_xmit_FDDI", |
304 | "_xmit_BIF", "_xmit_SIT", "_xmit_IPDDP", "_xmit_IPGRE", | 304 | "_xmit_BIF", "_xmit_SIT", "_xmit_IPDDP", "_xmit_IPGRE", |
305 | "_xmit_PIMREG", "_xmit_HIPPI", "_xmit_ASH", "_xmit_ECONET", | 305 | "_xmit_PIMREG", "_xmit_HIPPI", "_xmit_ASH", "_xmit_ECONET", |
306 | "_xmit_IRDA", "_xmit_FCPP", "_xmit_FCAL", "_xmit_FCPL", | 306 | "_xmit_IRDA", "_xmit_FCPP", "_xmit_FCAL", "_xmit_FCPL", |
307 | "_xmit_FCFABRIC", "_xmit_IEEE802_TR", "_xmit_IEEE80211", | 307 | "_xmit_FCFABRIC", "_xmit_IEEE802_TR", "_xmit_IEEE80211", |
308 | "_xmit_IEEE80211_PRISM", "_xmit_IEEE80211_RADIOTAP", "_xmit_PHONET", | 308 | "_xmit_IEEE80211_PRISM", "_xmit_IEEE80211_RADIOTAP", "_xmit_PHONET", |
309 | "_xmit_PHONET_PIPE", "_xmit_IEEE802154", | 309 | "_xmit_PHONET_PIPE", "_xmit_IEEE802154", |
310 | "_xmit_VOID", "_xmit_NONE"}; | 310 | "_xmit_VOID", "_xmit_NONE"}; |
311 | 311 | ||
312 | static struct lock_class_key netdev_xmit_lock_key[ARRAY_SIZE(netdev_lock_type)]; | 312 | static struct lock_class_key netdev_xmit_lock_key[ARRAY_SIZE(netdev_lock_type)]; |
313 | static struct lock_class_key netdev_addr_lock_key[ARRAY_SIZE(netdev_lock_type)]; | 313 | static struct lock_class_key netdev_addr_lock_key[ARRAY_SIZE(netdev_lock_type)]; |
314 | 314 | ||
315 | static inline unsigned short netdev_lock_pos(unsigned short dev_type) | 315 | static inline unsigned short netdev_lock_pos(unsigned short dev_type) |
316 | { | 316 | { |
317 | int i; | 317 | int i; |
318 | 318 | ||
319 | for (i = 0; i < ARRAY_SIZE(netdev_lock_type); i++) | 319 | for (i = 0; i < ARRAY_SIZE(netdev_lock_type); i++) |
320 | if (netdev_lock_type[i] == dev_type) | 320 | if (netdev_lock_type[i] == dev_type) |
321 | return i; | 321 | return i; |
322 | /* the last key is used by default */ | 322 | /* the last key is used by default */ |
323 | return ARRAY_SIZE(netdev_lock_type) - 1; | 323 | return ARRAY_SIZE(netdev_lock_type) - 1; |
324 | } | 324 | } |
325 | 325 | ||
326 | static inline void netdev_set_xmit_lockdep_class(spinlock_t *lock, | 326 | static inline void netdev_set_xmit_lockdep_class(spinlock_t *lock, |
327 | unsigned short dev_type) | 327 | unsigned short dev_type) |
328 | { | 328 | { |
329 | int i; | 329 | int i; |
330 | 330 | ||
331 | i = netdev_lock_pos(dev_type); | 331 | i = netdev_lock_pos(dev_type); |
332 | lockdep_set_class_and_name(lock, &netdev_xmit_lock_key[i], | 332 | lockdep_set_class_and_name(lock, &netdev_xmit_lock_key[i], |
333 | netdev_lock_name[i]); | 333 | netdev_lock_name[i]); |
334 | } | 334 | } |
335 | 335 | ||
336 | static inline void netdev_set_addr_lockdep_class(struct net_device *dev) | 336 | static inline void netdev_set_addr_lockdep_class(struct net_device *dev) |
337 | { | 337 | { |
338 | int i; | 338 | int i; |
339 | 339 | ||
340 | i = netdev_lock_pos(dev->type); | 340 | i = netdev_lock_pos(dev->type); |
341 | lockdep_set_class_and_name(&dev->addr_list_lock, | 341 | lockdep_set_class_and_name(&dev->addr_list_lock, |
342 | &netdev_addr_lock_key[i], | 342 | &netdev_addr_lock_key[i], |
343 | netdev_lock_name[i]); | 343 | netdev_lock_name[i]); |
344 | } | 344 | } |
345 | #else | 345 | #else |
346 | static inline void netdev_set_xmit_lockdep_class(spinlock_t *lock, | 346 | static inline void netdev_set_xmit_lockdep_class(spinlock_t *lock, |
347 | unsigned short dev_type) | 347 | unsigned short dev_type) |
348 | { | 348 | { |
349 | } | 349 | } |
350 | static inline void netdev_set_addr_lockdep_class(struct net_device *dev) | 350 | static inline void netdev_set_addr_lockdep_class(struct net_device *dev) |
351 | { | 351 | { |
352 | } | 352 | } |
353 | #endif | 353 | #endif |
354 | 354 | ||
355 | /******************************************************************************* | 355 | /******************************************************************************* |
356 | 356 | ||
357 | Protocol management and registration routines | 357 | Protocol management and registration routines |
358 | 358 | ||
359 | *******************************************************************************/ | 359 | *******************************************************************************/ |
360 | 360 | ||
361 | /* | 361 | /* |
362 | * Add a protocol ID to the list. Now that the input handler is | 362 | * Add a protocol ID to the list. Now that the input handler is |
363 | * smarter we can dispense with all the messy stuff that used to be | 363 | * smarter we can dispense with all the messy stuff that used to be |
364 | * here. | 364 | * here. |
365 | * | 365 | * |
366 | * BEWARE!!! Protocol handlers, mangling input packets, | 366 | * BEWARE!!! Protocol handlers, mangling input packets, |
367 | * MUST BE last in hash buckets and checking protocol handlers | 367 | * MUST BE last in hash buckets and checking protocol handlers |
368 | * MUST start from promiscuous ptype_all chain in net_bh. | 368 | * MUST start from promiscuous ptype_all chain in net_bh. |
369 | * It is true now, do not change it. | 369 | * It is true now, do not change it. |
370 | * Explanation follows: if protocol handler, mangling packet, will | 370 | * Explanation follows: if protocol handler, mangling packet, will |
371 | * be the first on list, it is not able to sense, that packet | 371 | * be the first on list, it is not able to sense, that packet |
372 | * is cloned and should be copied-on-write, so that it will | 372 | * is cloned and should be copied-on-write, so that it will |
373 | * change it and subsequent readers will get broken packet. | 373 | * change it and subsequent readers will get broken packet. |
374 | * --ANK (980803) | 374 | * --ANK (980803) |
375 | */ | 375 | */ |
376 | 376 | ||
377 | static inline struct list_head *ptype_head(const struct packet_type *pt) | 377 | static inline struct list_head *ptype_head(const struct packet_type *pt) |
378 | { | 378 | { |
379 | if (pt->type == htons(ETH_P_ALL)) | 379 | if (pt->type == htons(ETH_P_ALL)) |
380 | return &ptype_all; | 380 | return &ptype_all; |
381 | else | 381 | else |
382 | return &ptype_base[ntohs(pt->type) & PTYPE_HASH_MASK]; | 382 | return &ptype_base[ntohs(pt->type) & PTYPE_HASH_MASK]; |
383 | } | 383 | } |
384 | 384 | ||
385 | /** | 385 | /** |
386 | * dev_add_pack - add packet handler | 386 | * dev_add_pack - add packet handler |
387 | * @pt: packet type declaration | 387 | * @pt: packet type declaration |
388 | * | 388 | * |
389 | * Add a protocol handler to the networking stack. The passed &packet_type | 389 | * Add a protocol handler to the networking stack. The passed &packet_type |
390 | * is linked into kernel lists and may not be freed until it has been | 390 | * is linked into kernel lists and may not be freed until it has been |
391 | * removed from the kernel lists. | 391 | * removed from the kernel lists. |
392 | * | 392 | * |
393 | * This call does not sleep therefore it can not | 393 | * This call does not sleep therefore it can not |
394 | * guarantee all CPU's that are in middle of receiving packets | 394 | * guarantee all CPU's that are in middle of receiving packets |
395 | * will see the new packet type (until the next received packet). | 395 | * will see the new packet type (until the next received packet). |
396 | */ | 396 | */ |
397 | 397 | ||
398 | void dev_add_pack(struct packet_type *pt) | 398 | void dev_add_pack(struct packet_type *pt) |
399 | { | 399 | { |
400 | struct list_head *head = ptype_head(pt); | 400 | struct list_head *head = ptype_head(pt); |
401 | 401 | ||
402 | spin_lock(&ptype_lock); | 402 | spin_lock(&ptype_lock); |
403 | list_add_rcu(&pt->list, head); | 403 | list_add_rcu(&pt->list, head); |
404 | spin_unlock(&ptype_lock); | 404 | spin_unlock(&ptype_lock); |
405 | } | 405 | } |
406 | EXPORT_SYMBOL(dev_add_pack); | 406 | EXPORT_SYMBOL(dev_add_pack); |
407 | 407 | ||
408 | /** | 408 | /** |
409 | * __dev_remove_pack - remove packet handler | 409 | * __dev_remove_pack - remove packet handler |
410 | * @pt: packet type declaration | 410 | * @pt: packet type declaration |
411 | * | 411 | * |
412 | * Remove a protocol handler that was previously added to the kernel | 412 | * Remove a protocol handler that was previously added to the kernel |
413 | * protocol handlers by dev_add_pack(). The passed &packet_type is removed | 413 | * protocol handlers by dev_add_pack(). The passed &packet_type is removed |
414 | * from the kernel lists and can be freed or reused once this function | 414 | * from the kernel lists and can be freed or reused once this function |
415 | * returns. | 415 | * returns. |
416 | * | 416 | * |
417 | * The packet type might still be in use by receivers | 417 | * The packet type might still be in use by receivers |
418 | * and must not be freed until after all the CPU's have gone | 418 | * and must not be freed until after all the CPU's have gone |
419 | * through a quiescent state. | 419 | * through a quiescent state. |
420 | */ | 420 | */ |
421 | void __dev_remove_pack(struct packet_type *pt) | 421 | void __dev_remove_pack(struct packet_type *pt) |
422 | { | 422 | { |
423 | struct list_head *head = ptype_head(pt); | 423 | struct list_head *head = ptype_head(pt); |
424 | struct packet_type *pt1; | 424 | struct packet_type *pt1; |
425 | 425 | ||
426 | spin_lock(&ptype_lock); | 426 | spin_lock(&ptype_lock); |
427 | 427 | ||
428 | list_for_each_entry(pt1, head, list) { | 428 | list_for_each_entry(pt1, head, list) { |
429 | if (pt == pt1) { | 429 | if (pt == pt1) { |
430 | list_del_rcu(&pt->list); | 430 | list_del_rcu(&pt->list); |
431 | goto out; | 431 | goto out; |
432 | } | 432 | } |
433 | } | 433 | } |
434 | 434 | ||
435 | printk(KERN_WARNING "dev_remove_pack: %p not found.\n", pt); | 435 | printk(KERN_WARNING "dev_remove_pack: %p not found.\n", pt); |
436 | out: | 436 | out: |
437 | spin_unlock(&ptype_lock); | 437 | spin_unlock(&ptype_lock); |
438 | } | 438 | } |
439 | EXPORT_SYMBOL(__dev_remove_pack); | 439 | EXPORT_SYMBOL(__dev_remove_pack); |
440 | 440 | ||
441 | /** | 441 | /** |
442 | * dev_remove_pack - remove packet handler | 442 | * dev_remove_pack - remove packet handler |
443 | * @pt: packet type declaration | 443 | * @pt: packet type declaration |
444 | * | 444 | * |
445 | * Remove a protocol handler that was previously added to the kernel | 445 | * Remove a protocol handler that was previously added to the kernel |
446 | * protocol handlers by dev_add_pack(). The passed &packet_type is removed | 446 | * protocol handlers by dev_add_pack(). The passed &packet_type is removed |
447 | * from the kernel lists and can be freed or reused once this function | 447 | * from the kernel lists and can be freed or reused once this function |
448 | * returns. | 448 | * returns. |
449 | * | 449 | * |
450 | * This call sleeps to guarantee that no CPU is looking at the packet | 450 | * This call sleeps to guarantee that no CPU is looking at the packet |
451 | * type after return. | 451 | * type after return. |
452 | */ | 452 | */ |
453 | void dev_remove_pack(struct packet_type *pt) | 453 | void dev_remove_pack(struct packet_type *pt) |
454 | { | 454 | { |
455 | __dev_remove_pack(pt); | 455 | __dev_remove_pack(pt); |
456 | 456 | ||
457 | synchronize_net(); | 457 | synchronize_net(); |
458 | } | 458 | } |
459 | EXPORT_SYMBOL(dev_remove_pack); | 459 | EXPORT_SYMBOL(dev_remove_pack); |
460 | 460 | ||
461 | /****************************************************************************** | 461 | /****************************************************************************** |
462 | 462 | ||
463 | Device Boot-time Settings Routines | 463 | Device Boot-time Settings Routines |
464 | 464 | ||
465 | *******************************************************************************/ | 465 | *******************************************************************************/ |
466 | 466 | ||
467 | /* Boot time configuration table */ | 467 | /* Boot time configuration table */ |
468 | static struct netdev_boot_setup dev_boot_setup[NETDEV_BOOT_SETUP_MAX]; | 468 | static struct netdev_boot_setup dev_boot_setup[NETDEV_BOOT_SETUP_MAX]; |
469 | 469 | ||
470 | /** | 470 | /** |
471 | * netdev_boot_setup_add - add new setup entry | 471 | * netdev_boot_setup_add - add new setup entry |
472 | * @name: name of the device | 472 | * @name: name of the device |
473 | * @map: configured settings for the device | 473 | * @map: configured settings for the device |
474 | * | 474 | * |
475 | * Adds new setup entry to the dev_boot_setup list. The function | 475 | * Adds new setup entry to the dev_boot_setup list. The function |
476 | * returns 0 on error and 1 on success. This is a generic routine to | 476 | * returns 0 on error and 1 on success. This is a generic routine to |
477 | * all netdevices. | 477 | * all netdevices. |
478 | */ | 478 | */ |
479 | static int netdev_boot_setup_add(char *name, struct ifmap *map) | 479 | static int netdev_boot_setup_add(char *name, struct ifmap *map) |
480 | { | 480 | { |
481 | struct netdev_boot_setup *s; | 481 | struct netdev_boot_setup *s; |
482 | int i; | 482 | int i; |
483 | 483 | ||
484 | s = dev_boot_setup; | 484 | s = dev_boot_setup; |
485 | for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) { | 485 | for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) { |
486 | if (s[i].name[0] == '\0' || s[i].name[0] == ' ') { | 486 | if (s[i].name[0] == '\0' || s[i].name[0] == ' ') { |
487 | memset(s[i].name, 0, sizeof(s[i].name)); | 487 | memset(s[i].name, 0, sizeof(s[i].name)); |
488 | strlcpy(s[i].name, name, IFNAMSIZ); | 488 | strlcpy(s[i].name, name, IFNAMSIZ); |
489 | memcpy(&s[i].map, map, sizeof(s[i].map)); | 489 | memcpy(&s[i].map, map, sizeof(s[i].map)); |
490 | break; | 490 | break; |
491 | } | 491 | } |
492 | } | 492 | } |
493 | 493 | ||
494 | return i >= NETDEV_BOOT_SETUP_MAX ? 0 : 1; | 494 | return i >= NETDEV_BOOT_SETUP_MAX ? 0 : 1; |
495 | } | 495 | } |
496 | 496 | ||
497 | /** | 497 | /** |
498 | * netdev_boot_setup_check - check boot time settings | 498 | * netdev_boot_setup_check - check boot time settings |
499 | * @dev: the netdevice | 499 | * @dev: the netdevice |
500 | * | 500 | * |
501 | * Check boot time settings for the device. | 501 | * Check boot time settings for the device. |
502 | * The found settings are set for the device to be used | 502 | * The found settings are set for the device to be used |
503 | * later in the device probing. | 503 | * later in the device probing. |
504 | * Returns 0 if no settings found, 1 if they are. | 504 | * Returns 0 if no settings found, 1 if they are. |
505 | */ | 505 | */ |
506 | int netdev_boot_setup_check(struct net_device *dev) | 506 | int netdev_boot_setup_check(struct net_device *dev) |
507 | { | 507 | { |
508 | struct netdev_boot_setup *s = dev_boot_setup; | 508 | struct netdev_boot_setup *s = dev_boot_setup; |
509 | int i; | 509 | int i; |
510 | 510 | ||
511 | for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) { | 511 | for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) { |
512 | if (s[i].name[0] != '\0' && s[i].name[0] != ' ' && | 512 | if (s[i].name[0] != '\0' && s[i].name[0] != ' ' && |
513 | !strcmp(dev->name, s[i].name)) { | 513 | !strcmp(dev->name, s[i].name)) { |
514 | dev->irq = s[i].map.irq; | 514 | dev->irq = s[i].map.irq; |
515 | dev->base_addr = s[i].map.base_addr; | 515 | dev->base_addr = s[i].map.base_addr; |
516 | dev->mem_start = s[i].map.mem_start; | 516 | dev->mem_start = s[i].map.mem_start; |
517 | dev->mem_end = s[i].map.mem_end; | 517 | dev->mem_end = s[i].map.mem_end; |
518 | return 1; | 518 | return 1; |
519 | } | 519 | } |
520 | } | 520 | } |
521 | return 0; | 521 | return 0; |
522 | } | 522 | } |
523 | EXPORT_SYMBOL(netdev_boot_setup_check); | 523 | EXPORT_SYMBOL(netdev_boot_setup_check); |
524 | 524 | ||
525 | 525 | ||
526 | /** | 526 | /** |
527 | * netdev_boot_base - get address from boot time settings | 527 | * netdev_boot_base - get address from boot time settings |
528 | * @prefix: prefix for network device | 528 | * @prefix: prefix for network device |
529 | * @unit: id for network device | 529 | * @unit: id for network device |
530 | * | 530 | * |
531 | * Check boot time settings for the base address of device. | 531 | * Check boot time settings for the base address of device. |
532 | * The found settings are set for the device to be used | 532 | * The found settings are set for the device to be used |
533 | * later in the device probing. | 533 | * later in the device probing. |
534 | * Returns 0 if no settings found. | 534 | * Returns 0 if no settings found. |
535 | */ | 535 | */ |
536 | unsigned long netdev_boot_base(const char *prefix, int unit) | 536 | unsigned long netdev_boot_base(const char *prefix, int unit) |
537 | { | 537 | { |
538 | const struct netdev_boot_setup *s = dev_boot_setup; | 538 | const struct netdev_boot_setup *s = dev_boot_setup; |
539 | char name[IFNAMSIZ]; | 539 | char name[IFNAMSIZ]; |
540 | int i; | 540 | int i; |
541 | 541 | ||
542 | sprintf(name, "%s%d", prefix, unit); | 542 | sprintf(name, "%s%d", prefix, unit); |
543 | 543 | ||
544 | /* | 544 | /* |
545 | * If device already registered then return base of 1 | 545 | * If device already registered then return base of 1 |
546 | * to indicate not to probe for this interface | 546 | * to indicate not to probe for this interface |
547 | */ | 547 | */ |
548 | if (__dev_get_by_name(&init_net, name)) | 548 | if (__dev_get_by_name(&init_net, name)) |
549 | return 1; | 549 | return 1; |
550 | 550 | ||
551 | for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) | 551 | for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) |
552 | if (!strcmp(name, s[i].name)) | 552 | if (!strcmp(name, s[i].name)) |
553 | return s[i].map.base_addr; | 553 | return s[i].map.base_addr; |
554 | return 0; | 554 | return 0; |
555 | } | 555 | } |
556 | 556 | ||
557 | /* | 557 | /* |
558 | * Saves at boot time configured settings for any netdevice. | 558 | * Saves at boot time configured settings for any netdevice. |
559 | */ | 559 | */ |
560 | int __init netdev_boot_setup(char *str) | 560 | int __init netdev_boot_setup(char *str) |
561 | { | 561 | { |
562 | int ints[5]; | 562 | int ints[5]; |
563 | struct ifmap map; | 563 | struct ifmap map; |
564 | 564 | ||
565 | str = get_options(str, ARRAY_SIZE(ints), ints); | 565 | str = get_options(str, ARRAY_SIZE(ints), ints); |
566 | if (!str || !*str) | 566 | if (!str || !*str) |
567 | return 0; | 567 | return 0; |
568 | 568 | ||
569 | /* Save settings */ | 569 | /* Save settings */ |
570 | memset(&map, 0, sizeof(map)); | 570 | memset(&map, 0, sizeof(map)); |
571 | if (ints[0] > 0) | 571 | if (ints[0] > 0) |
572 | map.irq = ints[1]; | 572 | map.irq = ints[1]; |
573 | if (ints[0] > 1) | 573 | if (ints[0] > 1) |
574 | map.base_addr = ints[2]; | 574 | map.base_addr = ints[2]; |
575 | if (ints[0] > 2) | 575 | if (ints[0] > 2) |
576 | map.mem_start = ints[3]; | 576 | map.mem_start = ints[3]; |
577 | if (ints[0] > 3) | 577 | if (ints[0] > 3) |
578 | map.mem_end = ints[4]; | 578 | map.mem_end = ints[4]; |
579 | 579 | ||
580 | /* Add new entry to the list */ | 580 | /* Add new entry to the list */ |
581 | return netdev_boot_setup_add(str, &map); | 581 | return netdev_boot_setup_add(str, &map); |
582 | } | 582 | } |
583 | 583 | ||
584 | __setup("netdev=", netdev_boot_setup); | 584 | __setup("netdev=", netdev_boot_setup); |
585 | 585 | ||
586 | /******************************************************************************* | 586 | /******************************************************************************* |
587 | 587 | ||
588 | Device Interface Subroutines | 588 | Device Interface Subroutines |
589 | 589 | ||
590 | *******************************************************************************/ | 590 | *******************************************************************************/ |
591 | 591 | ||
592 | /** | 592 | /** |
593 | * __dev_get_by_name - find a device by its name | 593 | * __dev_get_by_name - find a device by its name |
594 | * @net: the applicable net namespace | 594 | * @net: the applicable net namespace |
595 | * @name: name to find | 595 | * @name: name to find |
596 | * | 596 | * |
597 | * Find an interface by name. Must be called under RTNL semaphore | 597 | * Find an interface by name. Must be called under RTNL semaphore |
598 | * or @dev_base_lock. If the name is found a pointer to the device | 598 | * or @dev_base_lock. If the name is found a pointer to the device |
599 | * is returned. If the name is not found then %NULL is returned. The | 599 | * is returned. If the name is not found then %NULL is returned. The |
600 | * reference counters are not incremented so the caller must be | 600 | * reference counters are not incremented so the caller must be |
601 | * careful with locks. | 601 | * careful with locks. |
602 | */ | 602 | */ |
603 | 603 | ||
604 | struct net_device *__dev_get_by_name(struct net *net, const char *name) | 604 | struct net_device *__dev_get_by_name(struct net *net, const char *name) |
605 | { | 605 | { |
606 | struct hlist_node *p; | 606 | struct hlist_node *p; |
607 | struct net_device *dev; | 607 | struct net_device *dev; |
608 | struct hlist_head *head = dev_name_hash(net, name); | 608 | struct hlist_head *head = dev_name_hash(net, name); |
609 | 609 | ||
610 | hlist_for_each_entry(dev, p, head, name_hlist) | 610 | hlist_for_each_entry(dev, p, head, name_hlist) |
611 | if (!strncmp(dev->name, name, IFNAMSIZ)) | 611 | if (!strncmp(dev->name, name, IFNAMSIZ)) |
612 | return dev; | 612 | return dev; |
613 | 613 | ||
614 | return NULL; | 614 | return NULL; |
615 | } | 615 | } |
616 | EXPORT_SYMBOL(__dev_get_by_name); | 616 | EXPORT_SYMBOL(__dev_get_by_name); |
617 | 617 | ||
618 | /** | 618 | /** |
619 | * dev_get_by_name_rcu - find a device by its name | 619 | * dev_get_by_name_rcu - find a device by its name |
620 | * @net: the applicable net namespace | 620 | * @net: the applicable net namespace |
621 | * @name: name to find | 621 | * @name: name to find |
622 | * | 622 | * |
623 | * Find an interface by name. | 623 | * Find an interface by name. |
624 | * If the name is found a pointer to the device is returned. | 624 | * If the name is found a pointer to the device is returned. |
625 | * If the name is not found then %NULL is returned. | 625 | * If the name is not found then %NULL is returned. |
626 | * The reference counters are not incremented so the caller must be | 626 | * The reference counters are not incremented so the caller must be |
627 | * careful with locks. The caller must hold RCU lock. | 627 | * careful with locks. The caller must hold RCU lock. |
628 | */ | 628 | */ |
629 | 629 | ||
630 | struct net_device *dev_get_by_name_rcu(struct net *net, const char *name) | 630 | struct net_device *dev_get_by_name_rcu(struct net *net, const char *name) |
631 | { | 631 | { |
632 | struct hlist_node *p; | 632 | struct hlist_node *p; |
633 | struct net_device *dev; | 633 | struct net_device *dev; |
634 | struct hlist_head *head = dev_name_hash(net, name); | 634 | struct hlist_head *head = dev_name_hash(net, name); |
635 | 635 | ||
636 | hlist_for_each_entry_rcu(dev, p, head, name_hlist) | 636 | hlist_for_each_entry_rcu(dev, p, head, name_hlist) |
637 | if (!strncmp(dev->name, name, IFNAMSIZ)) | 637 | if (!strncmp(dev->name, name, IFNAMSIZ)) |
638 | return dev; | 638 | return dev; |
639 | 639 | ||
640 | return NULL; | 640 | return NULL; |
641 | } | 641 | } |
642 | EXPORT_SYMBOL(dev_get_by_name_rcu); | 642 | EXPORT_SYMBOL(dev_get_by_name_rcu); |
643 | 643 | ||
644 | /** | 644 | /** |
645 | * dev_get_by_name - find a device by its name | 645 | * dev_get_by_name - find a device by its name |
646 | * @net: the applicable net namespace | 646 | * @net: the applicable net namespace |
647 | * @name: name to find | 647 | * @name: name to find |
648 | * | 648 | * |
649 | * Find an interface by name. This can be called from any | 649 | * Find an interface by name. This can be called from any |
650 | * context and does its own locking. The returned handle has | 650 | * context and does its own locking. The returned handle has |
651 | * the usage count incremented and the caller must use dev_put() to | 651 | * the usage count incremented and the caller must use dev_put() to |
652 | * release it when it is no longer needed. %NULL is returned if no | 652 | * release it when it is no longer needed. %NULL is returned if no |
653 | * matching device is found. | 653 | * matching device is found. |
654 | */ | 654 | */ |
655 | 655 | ||
656 | struct net_device *dev_get_by_name(struct net *net, const char *name) | 656 | struct net_device *dev_get_by_name(struct net *net, const char *name) |
657 | { | 657 | { |
658 | struct net_device *dev; | 658 | struct net_device *dev; |
659 | 659 | ||
660 | rcu_read_lock(); | 660 | rcu_read_lock(); |
661 | dev = dev_get_by_name_rcu(net, name); | 661 | dev = dev_get_by_name_rcu(net, name); |
662 | if (dev) | 662 | if (dev) |
663 | dev_hold(dev); | 663 | dev_hold(dev); |
664 | rcu_read_unlock(); | 664 | rcu_read_unlock(); |
665 | return dev; | 665 | return dev; |
666 | } | 666 | } |
667 | EXPORT_SYMBOL(dev_get_by_name); | 667 | EXPORT_SYMBOL(dev_get_by_name); |
668 | 668 | ||
669 | /** | 669 | /** |
670 | * __dev_get_by_index - find a device by its ifindex | 670 | * __dev_get_by_index - find a device by its ifindex |
671 | * @net: the applicable net namespace | 671 | * @net: the applicable net namespace |
672 | * @ifindex: index of device | 672 | * @ifindex: index of device |
673 | * | 673 | * |
674 | * Search for an interface by index. Returns %NULL if the device | 674 | * Search for an interface by index. Returns %NULL if the device |
675 | * is not found or a pointer to the device. The device has not | 675 | * is not found or a pointer to the device. The device has not |
676 | * had its reference counter increased so the caller must be careful | 676 | * had its reference counter increased so the caller must be careful |
677 | * about locking. The caller must hold either the RTNL semaphore | 677 | * about locking. The caller must hold either the RTNL semaphore |
678 | * or @dev_base_lock. | 678 | * or @dev_base_lock. |
679 | */ | 679 | */ |
680 | 680 | ||
681 | struct net_device *__dev_get_by_index(struct net *net, int ifindex) | 681 | struct net_device *__dev_get_by_index(struct net *net, int ifindex) |
682 | { | 682 | { |
683 | struct hlist_node *p; | 683 | struct hlist_node *p; |
684 | struct net_device *dev; | 684 | struct net_device *dev; |
685 | struct hlist_head *head = dev_index_hash(net, ifindex); | 685 | struct hlist_head *head = dev_index_hash(net, ifindex); |
686 | 686 | ||
687 | hlist_for_each_entry(dev, p, head, index_hlist) | 687 | hlist_for_each_entry(dev, p, head, index_hlist) |
688 | if (dev->ifindex == ifindex) | 688 | if (dev->ifindex == ifindex) |
689 | return dev; | 689 | return dev; |
690 | 690 | ||
691 | return NULL; | 691 | return NULL; |
692 | } | 692 | } |
693 | EXPORT_SYMBOL(__dev_get_by_index); | 693 | EXPORT_SYMBOL(__dev_get_by_index); |
694 | 694 | ||
695 | /** | 695 | /** |
696 | * dev_get_by_index_rcu - find a device by its ifindex | 696 | * dev_get_by_index_rcu - find a device by its ifindex |
697 | * @net: the applicable net namespace | 697 | * @net: the applicable net namespace |
698 | * @ifindex: index of device | 698 | * @ifindex: index of device |
699 | * | 699 | * |
700 | * Search for an interface by index. Returns %NULL if the device | 700 | * Search for an interface by index. Returns %NULL if the device |
701 | * is not found or a pointer to the device. The device has not | 701 | * is not found or a pointer to the device. The device has not |
702 | * had its reference counter increased so the caller must be careful | 702 | * had its reference counter increased so the caller must be careful |
703 | * about locking. The caller must hold RCU lock. | 703 | * about locking. The caller must hold RCU lock. |
704 | */ | 704 | */ |
705 | 705 | ||
706 | struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex) | 706 | struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex) |
707 | { | 707 | { |
708 | struct hlist_node *p; | 708 | struct hlist_node *p; |
709 | struct net_device *dev; | 709 | struct net_device *dev; |
710 | struct hlist_head *head = dev_index_hash(net, ifindex); | 710 | struct hlist_head *head = dev_index_hash(net, ifindex); |
711 | 711 | ||
712 | hlist_for_each_entry_rcu(dev, p, head, index_hlist) | 712 | hlist_for_each_entry_rcu(dev, p, head, index_hlist) |
713 | if (dev->ifindex == ifindex) | 713 | if (dev->ifindex == ifindex) |
714 | return dev; | 714 | return dev; |
715 | 715 | ||
716 | return NULL; | 716 | return NULL; |
717 | } | 717 | } |
718 | EXPORT_SYMBOL(dev_get_by_index_rcu); | 718 | EXPORT_SYMBOL(dev_get_by_index_rcu); |
719 | 719 | ||
720 | 720 | ||
721 | /** | 721 | /** |
722 | * dev_get_by_index - find a device by its ifindex | 722 | * dev_get_by_index - find a device by its ifindex |
723 | * @net: the applicable net namespace | 723 | * @net: the applicable net namespace |
724 | * @ifindex: index of device | 724 | * @ifindex: index of device |
725 | * | 725 | * |
726 | * Search for an interface by index. Returns NULL if the device | 726 | * Search for an interface by index. Returns NULL if the device |
727 | * is not found or a pointer to the device. The device returned has | 727 | * is not found or a pointer to the device. The device returned has |
728 | * had a reference added and the pointer is safe until the user calls | 728 | * had a reference added and the pointer is safe until the user calls |
729 | * dev_put to indicate they have finished with it. | 729 | * dev_put to indicate they have finished with it. |
730 | */ | 730 | */ |
731 | 731 | ||
732 | struct net_device *dev_get_by_index(struct net *net, int ifindex) | 732 | struct net_device *dev_get_by_index(struct net *net, int ifindex) |
733 | { | 733 | { |
734 | struct net_device *dev; | 734 | struct net_device *dev; |
735 | 735 | ||
736 | rcu_read_lock(); | 736 | rcu_read_lock(); |
737 | dev = dev_get_by_index_rcu(net, ifindex); | 737 | dev = dev_get_by_index_rcu(net, ifindex); |
738 | if (dev) | 738 | if (dev) |
739 | dev_hold(dev); | 739 | dev_hold(dev); |
740 | rcu_read_unlock(); | 740 | rcu_read_unlock(); |
741 | return dev; | 741 | return dev; |
742 | } | 742 | } |
743 | EXPORT_SYMBOL(dev_get_by_index); | 743 | EXPORT_SYMBOL(dev_get_by_index); |
744 | 744 | ||
745 | /** | 745 | /** |
746 | * dev_getbyhwaddr - find a device by its hardware address | 746 | * dev_getbyhwaddr - find a device by its hardware address |
747 | * @net: the applicable net namespace | 747 | * @net: the applicable net namespace |
748 | * @type: media type of device | 748 | * @type: media type of device |
749 | * @ha: hardware address | 749 | * @ha: hardware address |
750 | * | 750 | * |
751 | * Search for an interface by MAC address. Returns NULL if the device | 751 | * Search for an interface by MAC address. Returns NULL if the device |
752 | * is not found or a pointer to the device. The caller must hold the | 752 | * is not found or a pointer to the device. The caller must hold the |
753 | * rtnl semaphore. The returned device has not had its ref count increased | 753 | * rtnl semaphore. The returned device has not had its ref count increased |
754 | * and the caller must therefore be careful about locking | 754 | * and the caller must therefore be careful about locking |
755 | * | 755 | * |
756 | * BUGS: | 756 | * BUGS: |
757 | * If the API was consistent this would be __dev_get_by_hwaddr | 757 | * If the API was consistent this would be __dev_get_by_hwaddr |
758 | */ | 758 | */ |
759 | 759 | ||
760 | struct net_device *dev_getbyhwaddr(struct net *net, unsigned short type, char *ha) | 760 | struct net_device *dev_getbyhwaddr(struct net *net, unsigned short type, char *ha) |
761 | { | 761 | { |
762 | struct net_device *dev; | 762 | struct net_device *dev; |
763 | 763 | ||
764 | ASSERT_RTNL(); | 764 | ASSERT_RTNL(); |
765 | 765 | ||
766 | for_each_netdev(net, dev) | 766 | for_each_netdev(net, dev) |
767 | if (dev->type == type && | 767 | if (dev->type == type && |
768 | !memcmp(dev->dev_addr, ha, dev->addr_len)) | 768 | !memcmp(dev->dev_addr, ha, dev->addr_len)) |
769 | return dev; | 769 | return dev; |
770 | 770 | ||
771 | return NULL; | 771 | return NULL; |
772 | } | 772 | } |
773 | EXPORT_SYMBOL(dev_getbyhwaddr); | 773 | EXPORT_SYMBOL(dev_getbyhwaddr); |
774 | 774 | ||
775 | struct net_device *__dev_getfirstbyhwtype(struct net *net, unsigned short type) | 775 | struct net_device *__dev_getfirstbyhwtype(struct net *net, unsigned short type) |
776 | { | 776 | { |
777 | struct net_device *dev; | 777 | struct net_device *dev; |
778 | 778 | ||
779 | ASSERT_RTNL(); | 779 | ASSERT_RTNL(); |
780 | for_each_netdev(net, dev) | 780 | for_each_netdev(net, dev) |
781 | if (dev->type == type) | 781 | if (dev->type == type) |
782 | return dev; | 782 | return dev; |
783 | 783 | ||
784 | return NULL; | 784 | return NULL; |
785 | } | 785 | } |
786 | EXPORT_SYMBOL(__dev_getfirstbyhwtype); | 786 | EXPORT_SYMBOL(__dev_getfirstbyhwtype); |
787 | 787 | ||
788 | struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type) | 788 | struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type) |
789 | { | 789 | { |
790 | struct net_device *dev, *ret = NULL; | 790 | struct net_device *dev, *ret = NULL; |
791 | 791 | ||
792 | rcu_read_lock(); | 792 | rcu_read_lock(); |
793 | for_each_netdev_rcu(net, dev) | 793 | for_each_netdev_rcu(net, dev) |
794 | if (dev->type == type) { | 794 | if (dev->type == type) { |
795 | dev_hold(dev); | 795 | dev_hold(dev); |
796 | ret = dev; | 796 | ret = dev; |
797 | break; | 797 | break; |
798 | } | 798 | } |
799 | rcu_read_unlock(); | 799 | rcu_read_unlock(); |
800 | return ret; | 800 | return ret; |
801 | } | 801 | } |
802 | EXPORT_SYMBOL(dev_getfirstbyhwtype); | 802 | EXPORT_SYMBOL(dev_getfirstbyhwtype); |
803 | 803 | ||
804 | /** | 804 | /** |
805 | * dev_get_by_flags_rcu - find any device with given flags | 805 | * dev_get_by_flags_rcu - find any device with given flags |
806 | * @net: the applicable net namespace | 806 | * @net: the applicable net namespace |
807 | * @if_flags: IFF_* values | 807 | * @if_flags: IFF_* values |
808 | * @mask: bitmask of bits in if_flags to check | 808 | * @mask: bitmask of bits in if_flags to check |
809 | * | 809 | * |
810 | * Search for any interface with the given flags. Returns NULL if a device | 810 | * Search for any interface with the given flags. Returns NULL if a device |
811 | * is not found or a pointer to the device. Must be called inside | 811 | * is not found or a pointer to the device. Must be called inside |
812 | * rcu_read_lock(), and result refcount is unchanged. | 812 | * rcu_read_lock(), and result refcount is unchanged. |
813 | */ | 813 | */ |
814 | 814 | ||
815 | struct net_device *dev_get_by_flags_rcu(struct net *net, unsigned short if_flags, | 815 | struct net_device *dev_get_by_flags_rcu(struct net *net, unsigned short if_flags, |
816 | unsigned short mask) | 816 | unsigned short mask) |
817 | { | 817 | { |
818 | struct net_device *dev, *ret; | 818 | struct net_device *dev, *ret; |
819 | 819 | ||
820 | ret = NULL; | 820 | ret = NULL; |
821 | for_each_netdev_rcu(net, dev) { | 821 | for_each_netdev_rcu(net, dev) { |
822 | if (((dev->flags ^ if_flags) & mask) == 0) { | 822 | if (((dev->flags ^ if_flags) & mask) == 0) { |
823 | ret = dev; | 823 | ret = dev; |
824 | break; | 824 | break; |
825 | } | 825 | } |
826 | } | 826 | } |
827 | return ret; | 827 | return ret; |
828 | } | 828 | } |
829 | EXPORT_SYMBOL(dev_get_by_flags_rcu); | 829 | EXPORT_SYMBOL(dev_get_by_flags_rcu); |
830 | 830 | ||
831 | /** | 831 | /** |
832 | * dev_valid_name - check if name is okay for network device | 832 | * dev_valid_name - check if name is okay for network device |
833 | * @name: name string | 833 | * @name: name string |
834 | * | 834 | * |
835 | * Network device names need to be valid file names to | 835 | * Network device names need to be valid file names to |
836 | * to allow sysfs to work. We also disallow any kind of | 836 | * to allow sysfs to work. We also disallow any kind of |
837 | * whitespace. | 837 | * whitespace. |
838 | */ | 838 | */ |
839 | int dev_valid_name(const char *name) | 839 | int dev_valid_name(const char *name) |
840 | { | 840 | { |
841 | if (*name == '\0') | 841 | if (*name == '\0') |
842 | return 0; | 842 | return 0; |
843 | if (strlen(name) >= IFNAMSIZ) | 843 | if (strlen(name) >= IFNAMSIZ) |
844 | return 0; | 844 | return 0; |
845 | if (!strcmp(name, ".") || !strcmp(name, "..")) | 845 | if (!strcmp(name, ".") || !strcmp(name, "..")) |
846 | return 0; | 846 | return 0; |
847 | 847 | ||
848 | while (*name) { | 848 | while (*name) { |
849 | if (*name == '/' || isspace(*name)) | 849 | if (*name == '/' || isspace(*name)) |
850 | return 0; | 850 | return 0; |
851 | name++; | 851 | name++; |
852 | } | 852 | } |
853 | return 1; | 853 | return 1; |
854 | } | 854 | } |
855 | EXPORT_SYMBOL(dev_valid_name); | 855 | EXPORT_SYMBOL(dev_valid_name); |
856 | 856 | ||
857 | /** | 857 | /** |
858 | * __dev_alloc_name - allocate a name for a device | 858 | * __dev_alloc_name - allocate a name for a device |
859 | * @net: network namespace to allocate the device name in | 859 | * @net: network namespace to allocate the device name in |
860 | * @name: name format string | 860 | * @name: name format string |
861 | * @buf: scratch buffer and result name string | 861 | * @buf: scratch buffer and result name string |
862 | * | 862 | * |
863 | * Passed a format string - eg "lt%d" it will try and find a suitable | 863 | * Passed a format string - eg "lt%d" it will try and find a suitable |
864 | * id. It scans list of devices to build up a free map, then chooses | 864 | * id. It scans list of devices to build up a free map, then chooses |
865 | * the first empty slot. The caller must hold the dev_base or rtnl lock | 865 | * the first empty slot. The caller must hold the dev_base or rtnl lock |
866 | * while allocating the name and adding the device in order to avoid | 866 | * while allocating the name and adding the device in order to avoid |
867 | * duplicates. | 867 | * duplicates. |
868 | * Limited to bits_per_byte * page size devices (ie 32K on most platforms). | 868 | * Limited to bits_per_byte * page size devices (ie 32K on most platforms). |
869 | * Returns the number of the unit assigned or a negative errno code. | 869 | * Returns the number of the unit assigned or a negative errno code. |
870 | */ | 870 | */ |
871 | 871 | ||
872 | static int __dev_alloc_name(struct net *net, const char *name, char *buf) | 872 | static int __dev_alloc_name(struct net *net, const char *name, char *buf) |
873 | { | 873 | { |
874 | int i = 0; | 874 | int i = 0; |
875 | const char *p; | 875 | const char *p; |
876 | const int max_netdevices = 8*PAGE_SIZE; | 876 | const int max_netdevices = 8*PAGE_SIZE; |
877 | unsigned long *inuse; | 877 | unsigned long *inuse; |
878 | struct net_device *d; | 878 | struct net_device *d; |
879 | 879 | ||
880 | p = strnchr(name, IFNAMSIZ-1, '%'); | 880 | p = strnchr(name, IFNAMSIZ-1, '%'); |
881 | if (p) { | 881 | if (p) { |
882 | /* | 882 | /* |
883 | * Verify the string as this thing may have come from | 883 | * Verify the string as this thing may have come from |
884 | * the user. There must be either one "%d" and no other "%" | 884 | * the user. There must be either one "%d" and no other "%" |
885 | * characters. | 885 | * characters. |
886 | */ | 886 | */ |
887 | if (p[1] != 'd' || strchr(p + 2, '%')) | 887 | if (p[1] != 'd' || strchr(p + 2, '%')) |
888 | return -EINVAL; | 888 | return -EINVAL; |
889 | 889 | ||
890 | /* Use one page as a bit array of possible slots */ | 890 | /* Use one page as a bit array of possible slots */ |
891 | inuse = (unsigned long *) get_zeroed_page(GFP_ATOMIC); | 891 | inuse = (unsigned long *) get_zeroed_page(GFP_ATOMIC); |
892 | if (!inuse) | 892 | if (!inuse) |
893 | return -ENOMEM; | 893 | return -ENOMEM; |
894 | 894 | ||
895 | for_each_netdev(net, d) { | 895 | for_each_netdev(net, d) { |
896 | if (!sscanf(d->name, name, &i)) | 896 | if (!sscanf(d->name, name, &i)) |
897 | continue; | 897 | continue; |
898 | if (i < 0 || i >= max_netdevices) | 898 | if (i < 0 || i >= max_netdevices) |
899 | continue; | 899 | continue; |
900 | 900 | ||
901 | /* avoid cases where sscanf is not exact inverse of printf */ | 901 | /* avoid cases where sscanf is not exact inverse of printf */ |
902 | snprintf(buf, IFNAMSIZ, name, i); | 902 | snprintf(buf, IFNAMSIZ, name, i); |
903 | if (!strncmp(buf, d->name, IFNAMSIZ)) | 903 | if (!strncmp(buf, d->name, IFNAMSIZ)) |
904 | set_bit(i, inuse); | 904 | set_bit(i, inuse); |
905 | } | 905 | } |
906 | 906 | ||
907 | i = find_first_zero_bit(inuse, max_netdevices); | 907 | i = find_first_zero_bit(inuse, max_netdevices); |
908 | free_page((unsigned long) inuse); | 908 | free_page((unsigned long) inuse); |
909 | } | 909 | } |
910 | 910 | ||
911 | if (buf != name) | 911 | if (buf != name) |
912 | snprintf(buf, IFNAMSIZ, name, i); | 912 | snprintf(buf, IFNAMSIZ, name, i); |
913 | if (!__dev_get_by_name(net, buf)) | 913 | if (!__dev_get_by_name(net, buf)) |
914 | return i; | 914 | return i; |
915 | 915 | ||
916 | /* It is possible to run out of possible slots | 916 | /* It is possible to run out of possible slots |
917 | * when the name is long and there isn't enough space left | 917 | * when the name is long and there isn't enough space left |
918 | * for the digits, or if all bits are used. | 918 | * for the digits, or if all bits are used. |
919 | */ | 919 | */ |
920 | return -ENFILE; | 920 | return -ENFILE; |
921 | } | 921 | } |
922 | 922 | ||
923 | /** | 923 | /** |
924 | * dev_alloc_name - allocate a name for a device | 924 | * dev_alloc_name - allocate a name for a device |
925 | * @dev: device | 925 | * @dev: device |
926 | * @name: name format string | 926 | * @name: name format string |
927 | * | 927 | * |
928 | * Passed a format string - eg "lt%d" it will try and find a suitable | 928 | * Passed a format string - eg "lt%d" it will try and find a suitable |
929 | * id. It scans list of devices to build up a free map, then chooses | 929 | * id. It scans list of devices to build up a free map, then chooses |
930 | * the first empty slot. The caller must hold the dev_base or rtnl lock | 930 | * the first empty slot. The caller must hold the dev_base or rtnl lock |
931 | * while allocating the name and adding the device in order to avoid | 931 | * while allocating the name and adding the device in order to avoid |
932 | * duplicates. | 932 | * duplicates. |
933 | * Limited to bits_per_byte * page size devices (ie 32K on most platforms). | 933 | * Limited to bits_per_byte * page size devices (ie 32K on most platforms). |
934 | * Returns the number of the unit assigned or a negative errno code. | 934 | * Returns the number of the unit assigned or a negative errno code. |
935 | */ | 935 | */ |
936 | 936 | ||
937 | int dev_alloc_name(struct net_device *dev, const char *name) | 937 | int dev_alloc_name(struct net_device *dev, const char *name) |
938 | { | 938 | { |
939 | char buf[IFNAMSIZ]; | 939 | char buf[IFNAMSIZ]; |
940 | struct net *net; | 940 | struct net *net; |
941 | int ret; | 941 | int ret; |
942 | 942 | ||
943 | BUG_ON(!dev_net(dev)); | 943 | BUG_ON(!dev_net(dev)); |
944 | net = dev_net(dev); | 944 | net = dev_net(dev); |
945 | ret = __dev_alloc_name(net, name, buf); | 945 | ret = __dev_alloc_name(net, name, buf); |
946 | if (ret >= 0) | 946 | if (ret >= 0) |
947 | strlcpy(dev->name, buf, IFNAMSIZ); | 947 | strlcpy(dev->name, buf, IFNAMSIZ); |
948 | return ret; | 948 | return ret; |
949 | } | 949 | } |
950 | EXPORT_SYMBOL(dev_alloc_name); | 950 | EXPORT_SYMBOL(dev_alloc_name); |
951 | 951 | ||
952 | static int dev_get_valid_name(struct net_device *dev, const char *name, bool fmt) | 952 | static int dev_get_valid_name(struct net_device *dev, const char *name, bool fmt) |
953 | { | 953 | { |
954 | struct net *net; | 954 | struct net *net; |
955 | 955 | ||
956 | BUG_ON(!dev_net(dev)); | 956 | BUG_ON(!dev_net(dev)); |
957 | net = dev_net(dev); | 957 | net = dev_net(dev); |
958 | 958 | ||
959 | if (!dev_valid_name(name)) | 959 | if (!dev_valid_name(name)) |
960 | return -EINVAL; | 960 | return -EINVAL; |
961 | 961 | ||
962 | if (fmt && strchr(name, '%')) | 962 | if (fmt && strchr(name, '%')) |
963 | return dev_alloc_name(dev, name); | 963 | return dev_alloc_name(dev, name); |
964 | else if (__dev_get_by_name(net, name)) | 964 | else if (__dev_get_by_name(net, name)) |
965 | return -EEXIST; | 965 | return -EEXIST; |
966 | else if (dev->name != name) | 966 | else if (dev->name != name) |
967 | strlcpy(dev->name, name, IFNAMSIZ); | 967 | strlcpy(dev->name, name, IFNAMSIZ); |
968 | 968 | ||
969 | return 0; | 969 | return 0; |
970 | } | 970 | } |
971 | 971 | ||
972 | /** | 972 | /** |
973 | * dev_change_name - change name of a device | 973 | * dev_change_name - change name of a device |
974 | * @dev: device | 974 | * @dev: device |
975 | * @newname: name (or format string) must be at least IFNAMSIZ | 975 | * @newname: name (or format string) must be at least IFNAMSIZ |
976 | * | 976 | * |
977 | * Change name of a device, can pass format strings "eth%d". | 977 | * Change name of a device, can pass format strings "eth%d". |
978 | * for wildcarding. | 978 | * for wildcarding. |
979 | */ | 979 | */ |
980 | int dev_change_name(struct net_device *dev, const char *newname) | 980 | int dev_change_name(struct net_device *dev, const char *newname) |
981 | { | 981 | { |
982 | char oldname[IFNAMSIZ]; | 982 | char oldname[IFNAMSIZ]; |
983 | int err = 0; | 983 | int err = 0; |
984 | int ret; | 984 | int ret; |
985 | struct net *net; | 985 | struct net *net; |
986 | 986 | ||
987 | ASSERT_RTNL(); | 987 | ASSERT_RTNL(); |
988 | BUG_ON(!dev_net(dev)); | 988 | BUG_ON(!dev_net(dev)); |
989 | 989 | ||
990 | net = dev_net(dev); | 990 | net = dev_net(dev); |
991 | if (dev->flags & IFF_UP) | 991 | if (dev->flags & IFF_UP) |
992 | return -EBUSY; | 992 | return -EBUSY; |
993 | 993 | ||
994 | if (strncmp(newname, dev->name, IFNAMSIZ) == 0) | 994 | if (strncmp(newname, dev->name, IFNAMSIZ) == 0) |
995 | return 0; | 995 | return 0; |
996 | 996 | ||
997 | memcpy(oldname, dev->name, IFNAMSIZ); | 997 | memcpy(oldname, dev->name, IFNAMSIZ); |
998 | 998 | ||
999 | err = dev_get_valid_name(dev, newname, 1); | 999 | err = dev_get_valid_name(dev, newname, 1); |
1000 | if (err < 0) | 1000 | if (err < 0) |
1001 | return err; | 1001 | return err; |
1002 | 1002 | ||
1003 | rollback: | 1003 | rollback: |
1004 | ret = device_rename(&dev->dev, dev->name); | 1004 | ret = device_rename(&dev->dev, dev->name); |
1005 | if (ret) { | 1005 | if (ret) { |
1006 | memcpy(dev->name, oldname, IFNAMSIZ); | 1006 | memcpy(dev->name, oldname, IFNAMSIZ); |
1007 | return ret; | 1007 | return ret; |
1008 | } | 1008 | } |
1009 | 1009 | ||
1010 | write_lock_bh(&dev_base_lock); | 1010 | write_lock_bh(&dev_base_lock); |
1011 | hlist_del(&dev->name_hlist); | 1011 | hlist_del(&dev->name_hlist); |
1012 | write_unlock_bh(&dev_base_lock); | 1012 | write_unlock_bh(&dev_base_lock); |
1013 | 1013 | ||
1014 | synchronize_rcu(); | 1014 | synchronize_rcu(); |
1015 | 1015 | ||
1016 | write_lock_bh(&dev_base_lock); | 1016 | write_lock_bh(&dev_base_lock); |
1017 | hlist_add_head_rcu(&dev->name_hlist, dev_name_hash(net, dev->name)); | 1017 | hlist_add_head_rcu(&dev->name_hlist, dev_name_hash(net, dev->name)); |
1018 | write_unlock_bh(&dev_base_lock); | 1018 | write_unlock_bh(&dev_base_lock); |
1019 | 1019 | ||
1020 | ret = call_netdevice_notifiers(NETDEV_CHANGENAME, dev); | 1020 | ret = call_netdevice_notifiers(NETDEV_CHANGENAME, dev); |
1021 | ret = notifier_to_errno(ret); | 1021 | ret = notifier_to_errno(ret); |
1022 | 1022 | ||
1023 | if (ret) { | 1023 | if (ret) { |
1024 | /* err >= 0 after dev_alloc_name() or stores the first errno */ | 1024 | /* err >= 0 after dev_alloc_name() or stores the first errno */ |
1025 | if (err >= 0) { | 1025 | if (err >= 0) { |
1026 | err = ret; | 1026 | err = ret; |
1027 | memcpy(dev->name, oldname, IFNAMSIZ); | 1027 | memcpy(dev->name, oldname, IFNAMSIZ); |
1028 | goto rollback; | 1028 | goto rollback; |
1029 | } else { | 1029 | } else { |
1030 | printk(KERN_ERR | 1030 | printk(KERN_ERR |
1031 | "%s: name change rollback failed: %d.\n", | 1031 | "%s: name change rollback failed: %d.\n", |
1032 | dev->name, ret); | 1032 | dev->name, ret); |
1033 | } | 1033 | } |
1034 | } | 1034 | } |
1035 | 1035 | ||
1036 | return err; | 1036 | return err; |
1037 | } | 1037 | } |
1038 | 1038 | ||
1039 | /** | 1039 | /** |
1040 | * dev_set_alias - change ifalias of a device | 1040 | * dev_set_alias - change ifalias of a device |
1041 | * @dev: device | 1041 | * @dev: device |
1042 | * @alias: name up to IFALIASZ | 1042 | * @alias: name up to IFALIASZ |
1043 | * @len: limit of bytes to copy from info | 1043 | * @len: limit of bytes to copy from info |
1044 | * | 1044 | * |
1045 | * Set ifalias for a device, | 1045 | * Set ifalias for a device, |
1046 | */ | 1046 | */ |
1047 | int dev_set_alias(struct net_device *dev, const char *alias, size_t len) | 1047 | int dev_set_alias(struct net_device *dev, const char *alias, size_t len) |
1048 | { | 1048 | { |
1049 | ASSERT_RTNL(); | 1049 | ASSERT_RTNL(); |
1050 | 1050 | ||
1051 | if (len >= IFALIASZ) | 1051 | if (len >= IFALIASZ) |
1052 | return -EINVAL; | 1052 | return -EINVAL; |
1053 | 1053 | ||
1054 | if (!len) { | 1054 | if (!len) { |
1055 | if (dev->ifalias) { | 1055 | if (dev->ifalias) { |
1056 | kfree(dev->ifalias); | 1056 | kfree(dev->ifalias); |
1057 | dev->ifalias = NULL; | 1057 | dev->ifalias = NULL; |
1058 | } | 1058 | } |
1059 | return 0; | 1059 | return 0; |
1060 | } | 1060 | } |
1061 | 1061 | ||
1062 | dev->ifalias = krealloc(dev->ifalias, len + 1, GFP_KERNEL); | 1062 | dev->ifalias = krealloc(dev->ifalias, len + 1, GFP_KERNEL); |
1063 | if (!dev->ifalias) | 1063 | if (!dev->ifalias) |
1064 | return -ENOMEM; | 1064 | return -ENOMEM; |
1065 | 1065 | ||
1066 | strlcpy(dev->ifalias, alias, len+1); | 1066 | strlcpy(dev->ifalias, alias, len+1); |
1067 | return len; | 1067 | return len; |
1068 | } | 1068 | } |
1069 | 1069 | ||
1070 | 1070 | ||
1071 | /** | 1071 | /** |
1072 | * netdev_features_change - device changes features | 1072 | * netdev_features_change - device changes features |
1073 | * @dev: device to cause notification | 1073 | * @dev: device to cause notification |
1074 | * | 1074 | * |
1075 | * Called to indicate a device has changed features. | 1075 | * Called to indicate a device has changed features. |
1076 | */ | 1076 | */ |
1077 | void netdev_features_change(struct net_device *dev) | 1077 | void netdev_features_change(struct net_device *dev) |
1078 | { | 1078 | { |
1079 | call_netdevice_notifiers(NETDEV_FEAT_CHANGE, dev); | 1079 | call_netdevice_notifiers(NETDEV_FEAT_CHANGE, dev); |
1080 | } | 1080 | } |
1081 | EXPORT_SYMBOL(netdev_features_change); | 1081 | EXPORT_SYMBOL(netdev_features_change); |
1082 | 1082 | ||
1083 | /** | 1083 | /** |
1084 | * netdev_state_change - device changes state | 1084 | * netdev_state_change - device changes state |
1085 | * @dev: device to cause notification | 1085 | * @dev: device to cause notification |
1086 | * | 1086 | * |
1087 | * Called to indicate a device has changed state. This function calls | 1087 | * Called to indicate a device has changed state. This function calls |
1088 | * the notifier chains for netdev_chain and sends a NEWLINK message | 1088 | * the notifier chains for netdev_chain and sends a NEWLINK message |
1089 | * to the routing socket. | 1089 | * to the routing socket. |
1090 | */ | 1090 | */ |
1091 | void netdev_state_change(struct net_device *dev) | 1091 | void netdev_state_change(struct net_device *dev) |
1092 | { | 1092 | { |
1093 | if (dev->flags & IFF_UP) { | 1093 | if (dev->flags & IFF_UP) { |
1094 | call_netdevice_notifiers(NETDEV_CHANGE, dev); | 1094 | call_netdevice_notifiers(NETDEV_CHANGE, dev); |
1095 | rtmsg_ifinfo(RTM_NEWLINK, dev, 0); | 1095 | rtmsg_ifinfo(RTM_NEWLINK, dev, 0); |
1096 | } | 1096 | } |
1097 | } | 1097 | } |
1098 | EXPORT_SYMBOL(netdev_state_change); | 1098 | EXPORT_SYMBOL(netdev_state_change); |
1099 | 1099 | ||
1100 | int netdev_bonding_change(struct net_device *dev, unsigned long event) | 1100 | int netdev_bonding_change(struct net_device *dev, unsigned long event) |
1101 | { | 1101 | { |
1102 | return call_netdevice_notifiers(event, dev); | 1102 | return call_netdevice_notifiers(event, dev); |
1103 | } | 1103 | } |
1104 | EXPORT_SYMBOL(netdev_bonding_change); | 1104 | EXPORT_SYMBOL(netdev_bonding_change); |
1105 | 1105 | ||
1106 | /** | 1106 | /** |
1107 | * dev_load - load a network module | 1107 | * dev_load - load a network module |
1108 | * @net: the applicable net namespace | 1108 | * @net: the applicable net namespace |
1109 | * @name: name of interface | 1109 | * @name: name of interface |
1110 | * | 1110 | * |
1111 | * If a network interface is not present and the process has suitable | 1111 | * If a network interface is not present and the process has suitable |
1112 | * privileges this function loads the module. If module loading is not | 1112 | * privileges this function loads the module. If module loading is not |
1113 | * available in this kernel then it becomes a nop. | 1113 | * available in this kernel then it becomes a nop. |
1114 | */ | 1114 | */ |
1115 | 1115 | ||
1116 | void dev_load(struct net *net, const char *name) | 1116 | void dev_load(struct net *net, const char *name) |
1117 | { | 1117 | { |
1118 | struct net_device *dev; | 1118 | struct net_device *dev; |
1119 | 1119 | ||
1120 | rcu_read_lock(); | 1120 | rcu_read_lock(); |
1121 | dev = dev_get_by_name_rcu(net, name); | 1121 | dev = dev_get_by_name_rcu(net, name); |
1122 | rcu_read_unlock(); | 1122 | rcu_read_unlock(); |
1123 | 1123 | ||
1124 | if (!dev && capable(CAP_NET_ADMIN)) | 1124 | if (!dev && capable(CAP_NET_ADMIN)) |
1125 | request_module("%s", name); | 1125 | request_module("%s", name); |
1126 | } | 1126 | } |
1127 | EXPORT_SYMBOL(dev_load); | 1127 | EXPORT_SYMBOL(dev_load); |
1128 | 1128 | ||
1129 | static int __dev_open(struct net_device *dev) | 1129 | static int __dev_open(struct net_device *dev) |
1130 | { | 1130 | { |
1131 | const struct net_device_ops *ops = dev->netdev_ops; | 1131 | const struct net_device_ops *ops = dev->netdev_ops; |
1132 | int ret; | 1132 | int ret; |
1133 | 1133 | ||
1134 | ASSERT_RTNL(); | 1134 | ASSERT_RTNL(); |
1135 | 1135 | ||
1136 | /* | 1136 | /* |
1137 | * Is it even present? | 1137 | * Is it even present? |
1138 | */ | 1138 | */ |
1139 | if (!netif_device_present(dev)) | 1139 | if (!netif_device_present(dev)) |
1140 | return -ENODEV; | 1140 | return -ENODEV; |
1141 | 1141 | ||
1142 | ret = call_netdevice_notifiers(NETDEV_PRE_UP, dev); | 1142 | ret = call_netdevice_notifiers(NETDEV_PRE_UP, dev); |
1143 | ret = notifier_to_errno(ret); | 1143 | ret = notifier_to_errno(ret); |
1144 | if (ret) | 1144 | if (ret) |
1145 | return ret; | 1145 | return ret; |
1146 | 1146 | ||
1147 | /* | 1147 | /* |
1148 | * Call device private open method | 1148 | * Call device private open method |
1149 | */ | 1149 | */ |
1150 | set_bit(__LINK_STATE_START, &dev->state); | 1150 | set_bit(__LINK_STATE_START, &dev->state); |
1151 | 1151 | ||
1152 | if (ops->ndo_validate_addr) | 1152 | if (ops->ndo_validate_addr) |
1153 | ret = ops->ndo_validate_addr(dev); | 1153 | ret = ops->ndo_validate_addr(dev); |
1154 | 1154 | ||
1155 | if (!ret && ops->ndo_open) | 1155 | if (!ret && ops->ndo_open) |
1156 | ret = ops->ndo_open(dev); | 1156 | ret = ops->ndo_open(dev); |
1157 | 1157 | ||
1158 | /* | 1158 | /* |
1159 | * If it went open OK then: | 1159 | * If it went open OK then: |
1160 | */ | 1160 | */ |
1161 | 1161 | ||
1162 | if (ret) | 1162 | if (ret) |
1163 | clear_bit(__LINK_STATE_START, &dev->state); | 1163 | clear_bit(__LINK_STATE_START, &dev->state); |
1164 | else { | 1164 | else { |
1165 | /* | 1165 | /* |
1166 | * Set the flags. | 1166 | * Set the flags. |
1167 | */ | 1167 | */ |
1168 | dev->flags |= IFF_UP; | 1168 | dev->flags |= IFF_UP; |
1169 | 1169 | ||
1170 | /* | 1170 | /* |
1171 | * Enable NET_DMA | 1171 | * Enable NET_DMA |
1172 | */ | 1172 | */ |
1173 | net_dmaengine_get(); | 1173 | net_dmaengine_get(); |
1174 | 1174 | ||
1175 | /* | 1175 | /* |
1176 | * Initialize multicasting status | 1176 | * Initialize multicasting status |
1177 | */ | 1177 | */ |
1178 | dev_set_rx_mode(dev); | 1178 | dev_set_rx_mode(dev); |
1179 | 1179 | ||
1180 | /* | 1180 | /* |
1181 | * Wakeup transmit queue engine | 1181 | * Wakeup transmit queue engine |
1182 | */ | 1182 | */ |
1183 | dev_activate(dev); | 1183 | dev_activate(dev); |
1184 | } | 1184 | } |
1185 | 1185 | ||
1186 | return ret; | 1186 | return ret; |
1187 | } | 1187 | } |
1188 | 1188 | ||
1189 | /** | 1189 | /** |
1190 | * dev_open - prepare an interface for use. | 1190 | * dev_open - prepare an interface for use. |
1191 | * @dev: device to open | 1191 | * @dev: device to open |
1192 | * | 1192 | * |
1193 | * Takes a device from down to up state. The device's private open | 1193 | * Takes a device from down to up state. The device's private open |
1194 | * function is invoked and then the multicast lists are loaded. Finally | 1194 | * function is invoked and then the multicast lists are loaded. Finally |
1195 | * the device is moved into the up state and a %NETDEV_UP message is | 1195 | * the device is moved into the up state and a %NETDEV_UP message is |
1196 | * sent to the netdev notifier chain. | 1196 | * sent to the netdev notifier chain. |
1197 | * | 1197 | * |
1198 | * Calling this function on an active interface is a nop. On a failure | 1198 | * Calling this function on an active interface is a nop. On a failure |
1199 | * a negative errno code is returned. | 1199 | * a negative errno code is returned. |
1200 | */ | 1200 | */ |
1201 | int dev_open(struct net_device *dev) | 1201 | int dev_open(struct net_device *dev) |
1202 | { | 1202 | { |
1203 | int ret; | 1203 | int ret; |
1204 | 1204 | ||
1205 | /* | 1205 | /* |
1206 | * Is it already up? | 1206 | * Is it already up? |
1207 | */ | 1207 | */ |
1208 | if (dev->flags & IFF_UP) | 1208 | if (dev->flags & IFF_UP) |
1209 | return 0; | 1209 | return 0; |
1210 | 1210 | ||
1211 | /* | 1211 | /* |
1212 | * Open device | 1212 | * Open device |
1213 | */ | 1213 | */ |
1214 | ret = __dev_open(dev); | 1214 | ret = __dev_open(dev); |
1215 | if (ret < 0) | 1215 | if (ret < 0) |
1216 | return ret; | 1216 | return ret; |
1217 | 1217 | ||
1218 | /* | 1218 | /* |
1219 | * ... and announce new interface. | 1219 | * ... and announce new interface. |
1220 | */ | 1220 | */ |
1221 | rtmsg_ifinfo(RTM_NEWLINK, dev, IFF_UP|IFF_RUNNING); | 1221 | rtmsg_ifinfo(RTM_NEWLINK, dev, IFF_UP|IFF_RUNNING); |
1222 | call_netdevice_notifiers(NETDEV_UP, dev); | 1222 | call_netdevice_notifiers(NETDEV_UP, dev); |
1223 | 1223 | ||
1224 | return ret; | 1224 | return ret; |
1225 | } | 1225 | } |
1226 | EXPORT_SYMBOL(dev_open); | 1226 | EXPORT_SYMBOL(dev_open); |
1227 | 1227 | ||
1228 | static int __dev_close(struct net_device *dev) | 1228 | static int __dev_close(struct net_device *dev) |
1229 | { | 1229 | { |
1230 | const struct net_device_ops *ops = dev->netdev_ops; | 1230 | const struct net_device_ops *ops = dev->netdev_ops; |
1231 | 1231 | ||
1232 | ASSERT_RTNL(); | 1232 | ASSERT_RTNL(); |
1233 | might_sleep(); | 1233 | might_sleep(); |
1234 | 1234 | ||
1235 | /* | 1235 | /* |
1236 | * Tell people we are going down, so that they can | 1236 | * Tell people we are going down, so that they can |
1237 | * prepare to death, when device is still operating. | 1237 | * prepare to death, when device is still operating. |
1238 | */ | 1238 | */ |
1239 | call_netdevice_notifiers(NETDEV_GOING_DOWN, dev); | 1239 | call_netdevice_notifiers(NETDEV_GOING_DOWN, dev); |
1240 | 1240 | ||
1241 | clear_bit(__LINK_STATE_START, &dev->state); | 1241 | clear_bit(__LINK_STATE_START, &dev->state); |
1242 | 1242 | ||
1243 | /* Synchronize to scheduled poll. We cannot touch poll list, | 1243 | /* Synchronize to scheduled poll. We cannot touch poll list, |
1244 | * it can be even on different cpu. So just clear netif_running(). | 1244 | * it can be even on different cpu. So just clear netif_running(). |
1245 | * | 1245 | * |
1246 | * dev->stop() will invoke napi_disable() on all of it's | 1246 | * dev->stop() will invoke napi_disable() on all of it's |
1247 | * napi_struct instances on this device. | 1247 | * napi_struct instances on this device. |
1248 | */ | 1248 | */ |
1249 | smp_mb__after_clear_bit(); /* Commit netif_running(). */ | 1249 | smp_mb__after_clear_bit(); /* Commit netif_running(). */ |
1250 | 1250 | ||
1251 | dev_deactivate(dev); | 1251 | dev_deactivate(dev); |
1252 | 1252 | ||
1253 | /* | 1253 | /* |
1254 | * Call the device specific close. This cannot fail. | 1254 | * Call the device specific close. This cannot fail. |
1255 | * Only if device is UP | 1255 | * Only if device is UP |
1256 | * | 1256 | * |
1257 | * We allow it to be called even after a DETACH hot-plug | 1257 | * We allow it to be called even after a DETACH hot-plug |
1258 | * event. | 1258 | * event. |
1259 | */ | 1259 | */ |
1260 | if (ops->ndo_stop) | 1260 | if (ops->ndo_stop) |
1261 | ops->ndo_stop(dev); | 1261 | ops->ndo_stop(dev); |
1262 | 1262 | ||
1263 | /* | 1263 | /* |
1264 | * Device is now down. | 1264 | * Device is now down. |
1265 | */ | 1265 | */ |
1266 | 1266 | ||
1267 | dev->flags &= ~IFF_UP; | 1267 | dev->flags &= ~IFF_UP; |
1268 | 1268 | ||
1269 | /* | 1269 | /* |
1270 | * Shutdown NET_DMA | 1270 | * Shutdown NET_DMA |
1271 | */ | 1271 | */ |
1272 | net_dmaengine_put(); | 1272 | net_dmaengine_put(); |
1273 | 1273 | ||
1274 | return 0; | 1274 | return 0; |
1275 | } | 1275 | } |
1276 | 1276 | ||
1277 | /** | 1277 | /** |
1278 | * dev_close - shutdown an interface. | 1278 | * dev_close - shutdown an interface. |
1279 | * @dev: device to shutdown | 1279 | * @dev: device to shutdown |
1280 | * | 1280 | * |
1281 | * This function moves an active device into down state. A | 1281 | * This function moves an active device into down state. A |
1282 | * %NETDEV_GOING_DOWN is sent to the netdev notifier chain. The device | 1282 | * %NETDEV_GOING_DOWN is sent to the netdev notifier chain. The device |
1283 | * is then deactivated and finally a %NETDEV_DOWN is sent to the notifier | 1283 | * is then deactivated and finally a %NETDEV_DOWN is sent to the notifier |
1284 | * chain. | 1284 | * chain. |
1285 | */ | 1285 | */ |
1286 | int dev_close(struct net_device *dev) | 1286 | int dev_close(struct net_device *dev) |
1287 | { | 1287 | { |
1288 | if (!(dev->flags & IFF_UP)) | 1288 | if (!(dev->flags & IFF_UP)) |
1289 | return 0; | 1289 | return 0; |
1290 | 1290 | ||
1291 | __dev_close(dev); | 1291 | __dev_close(dev); |
1292 | 1292 | ||
1293 | /* | 1293 | /* |
1294 | * Tell people we are down | 1294 | * Tell people we are down |
1295 | */ | 1295 | */ |
1296 | rtmsg_ifinfo(RTM_NEWLINK, dev, IFF_UP|IFF_RUNNING); | 1296 | rtmsg_ifinfo(RTM_NEWLINK, dev, IFF_UP|IFF_RUNNING); |
1297 | call_netdevice_notifiers(NETDEV_DOWN, dev); | 1297 | call_netdevice_notifiers(NETDEV_DOWN, dev); |
1298 | 1298 | ||
1299 | return 0; | 1299 | return 0; |
1300 | } | 1300 | } |
1301 | EXPORT_SYMBOL(dev_close); | 1301 | EXPORT_SYMBOL(dev_close); |
1302 | 1302 | ||
1303 | 1303 | ||
1304 | /** | 1304 | /** |
1305 | * dev_disable_lro - disable Large Receive Offload on a device | 1305 | * dev_disable_lro - disable Large Receive Offload on a device |
1306 | * @dev: device | 1306 | * @dev: device |
1307 | * | 1307 | * |
1308 | * Disable Large Receive Offload (LRO) on a net device. Must be | 1308 | * Disable Large Receive Offload (LRO) on a net device. Must be |
1309 | * called under RTNL. This is needed if received packets may be | 1309 | * called under RTNL. This is needed if received packets may be |
1310 | * forwarded to another interface. | 1310 | * forwarded to another interface. |
1311 | */ | 1311 | */ |
1312 | void dev_disable_lro(struct net_device *dev) | 1312 | void dev_disable_lro(struct net_device *dev) |
1313 | { | 1313 | { |
1314 | if (dev->ethtool_ops && dev->ethtool_ops->get_flags && | 1314 | if (dev->ethtool_ops && dev->ethtool_ops->get_flags && |
1315 | dev->ethtool_ops->set_flags) { | 1315 | dev->ethtool_ops->set_flags) { |
1316 | u32 flags = dev->ethtool_ops->get_flags(dev); | 1316 | u32 flags = dev->ethtool_ops->get_flags(dev); |
1317 | if (flags & ETH_FLAG_LRO) { | 1317 | if (flags & ETH_FLAG_LRO) { |
1318 | flags &= ~ETH_FLAG_LRO; | 1318 | flags &= ~ETH_FLAG_LRO; |
1319 | dev->ethtool_ops->set_flags(dev, flags); | 1319 | dev->ethtool_ops->set_flags(dev, flags); |
1320 | } | 1320 | } |
1321 | } | 1321 | } |
1322 | WARN_ON(dev->features & NETIF_F_LRO); | 1322 | WARN_ON(dev->features & NETIF_F_LRO); |
1323 | } | 1323 | } |
1324 | EXPORT_SYMBOL(dev_disable_lro); | 1324 | EXPORT_SYMBOL(dev_disable_lro); |
1325 | 1325 | ||
1326 | 1326 | ||
1327 | static int dev_boot_phase = 1; | 1327 | static int dev_boot_phase = 1; |
1328 | 1328 | ||
1329 | /* | 1329 | /* |
1330 | * Device change register/unregister. These are not inline or static | 1330 | * Device change register/unregister. These are not inline or static |
1331 | * as we export them to the world. | 1331 | * as we export them to the world. |
1332 | */ | 1332 | */ |
1333 | 1333 | ||
1334 | /** | 1334 | /** |
1335 | * register_netdevice_notifier - register a network notifier block | 1335 | * register_netdevice_notifier - register a network notifier block |
1336 | * @nb: notifier | 1336 | * @nb: notifier |
1337 | * | 1337 | * |
1338 | * Register a notifier to be called when network device events occur. | 1338 | * Register a notifier to be called when network device events occur. |
1339 | * The notifier passed is linked into the kernel structures and must | 1339 | * The notifier passed is linked into the kernel structures and must |
1340 | * not be reused until it has been unregistered. A negative errno code | 1340 | * not be reused until it has been unregistered. A negative errno code |
1341 | * is returned on a failure. | 1341 | * is returned on a failure. |
1342 | * | 1342 | * |
1343 | * When registered all registration and up events are replayed | 1343 | * When registered all registration and up events are replayed |
1344 | * to the new notifier to allow device to have a race free | 1344 | * to the new notifier to allow device to have a race free |
1345 | * view of the network device list. | 1345 | * view of the network device list. |
1346 | */ | 1346 | */ |
1347 | 1347 | ||
1348 | int register_netdevice_notifier(struct notifier_block *nb) | 1348 | int register_netdevice_notifier(struct notifier_block *nb) |
1349 | { | 1349 | { |
1350 | struct net_device *dev; | 1350 | struct net_device *dev; |
1351 | struct net_device *last; | 1351 | struct net_device *last; |
1352 | struct net *net; | 1352 | struct net *net; |
1353 | int err; | 1353 | int err; |
1354 | 1354 | ||
1355 | rtnl_lock(); | 1355 | rtnl_lock(); |
1356 | err = raw_notifier_chain_register(&netdev_chain, nb); | 1356 | err = raw_notifier_chain_register(&netdev_chain, nb); |
1357 | if (err) | 1357 | if (err) |
1358 | goto unlock; | 1358 | goto unlock; |
1359 | if (dev_boot_phase) | 1359 | if (dev_boot_phase) |
1360 | goto unlock; | 1360 | goto unlock; |
1361 | for_each_net(net) { | 1361 | for_each_net(net) { |
1362 | for_each_netdev(net, dev) { | 1362 | for_each_netdev(net, dev) { |
1363 | err = nb->notifier_call(nb, NETDEV_REGISTER, dev); | 1363 | err = nb->notifier_call(nb, NETDEV_REGISTER, dev); |
1364 | err = notifier_to_errno(err); | 1364 | err = notifier_to_errno(err); |
1365 | if (err) | 1365 | if (err) |
1366 | goto rollback; | 1366 | goto rollback; |
1367 | 1367 | ||
1368 | if (!(dev->flags & IFF_UP)) | 1368 | if (!(dev->flags & IFF_UP)) |
1369 | continue; | 1369 | continue; |
1370 | 1370 | ||
1371 | nb->notifier_call(nb, NETDEV_UP, dev); | 1371 | nb->notifier_call(nb, NETDEV_UP, dev); |
1372 | } | 1372 | } |
1373 | } | 1373 | } |
1374 | 1374 | ||
1375 | unlock: | 1375 | unlock: |
1376 | rtnl_unlock(); | 1376 | rtnl_unlock(); |
1377 | return err; | 1377 | return err; |
1378 | 1378 | ||
1379 | rollback: | 1379 | rollback: |
1380 | last = dev; | 1380 | last = dev; |
1381 | for_each_net(net) { | 1381 | for_each_net(net) { |
1382 | for_each_netdev(net, dev) { | 1382 | for_each_netdev(net, dev) { |
1383 | if (dev == last) | 1383 | if (dev == last) |
1384 | break; | 1384 | break; |
1385 | 1385 | ||
1386 | if (dev->flags & IFF_UP) { | 1386 | if (dev->flags & IFF_UP) { |
1387 | nb->notifier_call(nb, NETDEV_GOING_DOWN, dev); | 1387 | nb->notifier_call(nb, NETDEV_GOING_DOWN, dev); |
1388 | nb->notifier_call(nb, NETDEV_DOWN, dev); | 1388 | nb->notifier_call(nb, NETDEV_DOWN, dev); |
1389 | } | 1389 | } |
1390 | nb->notifier_call(nb, NETDEV_UNREGISTER, dev); | 1390 | nb->notifier_call(nb, NETDEV_UNREGISTER, dev); |
1391 | nb->notifier_call(nb, NETDEV_UNREGISTER_BATCH, dev); | 1391 | nb->notifier_call(nb, NETDEV_UNREGISTER_BATCH, dev); |
1392 | } | 1392 | } |
1393 | } | 1393 | } |
1394 | 1394 | ||
1395 | raw_notifier_chain_unregister(&netdev_chain, nb); | 1395 | raw_notifier_chain_unregister(&netdev_chain, nb); |
1396 | goto unlock; | 1396 | goto unlock; |
1397 | } | 1397 | } |
1398 | EXPORT_SYMBOL(register_netdevice_notifier); | 1398 | EXPORT_SYMBOL(register_netdevice_notifier); |
1399 | 1399 | ||
1400 | /** | 1400 | /** |
1401 | * unregister_netdevice_notifier - unregister a network notifier block | 1401 | * unregister_netdevice_notifier - unregister a network notifier block |
1402 | * @nb: notifier | 1402 | * @nb: notifier |
1403 | * | 1403 | * |
1404 | * Unregister a notifier previously registered by | 1404 | * Unregister a notifier previously registered by |
1405 | * register_netdevice_notifier(). The notifier is unlinked into the | 1405 | * register_netdevice_notifier(). The notifier is unlinked into the |
1406 | * kernel structures and may then be reused. A negative errno code | 1406 | * kernel structures and may then be reused. A negative errno code |
1407 | * is returned on a failure. | 1407 | * is returned on a failure. |
1408 | */ | 1408 | */ |
1409 | 1409 | ||
1410 | int unregister_netdevice_notifier(struct notifier_block *nb) | 1410 | int unregister_netdevice_notifier(struct notifier_block *nb) |
1411 | { | 1411 | { |
1412 | int err; | 1412 | int err; |
1413 | 1413 | ||
1414 | rtnl_lock(); | 1414 | rtnl_lock(); |
1415 | err = raw_notifier_chain_unregister(&netdev_chain, nb); | 1415 | err = raw_notifier_chain_unregister(&netdev_chain, nb); |
1416 | rtnl_unlock(); | 1416 | rtnl_unlock(); |
1417 | return err; | 1417 | return err; |
1418 | } | 1418 | } |
1419 | EXPORT_SYMBOL(unregister_netdevice_notifier); | 1419 | EXPORT_SYMBOL(unregister_netdevice_notifier); |
1420 | 1420 | ||
1421 | /** | 1421 | /** |
1422 | * call_netdevice_notifiers - call all network notifier blocks | 1422 | * call_netdevice_notifiers - call all network notifier blocks |
1423 | * @val: value passed unmodified to notifier function | 1423 | * @val: value passed unmodified to notifier function |
1424 | * @dev: net_device pointer passed unmodified to notifier function | 1424 | * @dev: net_device pointer passed unmodified to notifier function |
1425 | * | 1425 | * |
1426 | * Call all network notifier blocks. Parameters and return value | 1426 | * Call all network notifier blocks. Parameters and return value |
1427 | * are as for raw_notifier_call_chain(). | 1427 | * are as for raw_notifier_call_chain(). |
1428 | */ | 1428 | */ |
1429 | 1429 | ||
1430 | int call_netdevice_notifiers(unsigned long val, struct net_device *dev) | 1430 | int call_netdevice_notifiers(unsigned long val, struct net_device *dev) |
1431 | { | 1431 | { |
1432 | ASSERT_RTNL(); | 1432 | ASSERT_RTNL(); |
1433 | return raw_notifier_call_chain(&netdev_chain, val, dev); | 1433 | return raw_notifier_call_chain(&netdev_chain, val, dev); |
1434 | } | 1434 | } |
1435 | 1435 | ||
1436 | /* When > 0 there are consumers of rx skb time stamps */ | 1436 | /* When > 0 there are consumers of rx skb time stamps */ |
1437 | static atomic_t netstamp_needed = ATOMIC_INIT(0); | 1437 | static atomic_t netstamp_needed = ATOMIC_INIT(0); |
1438 | 1438 | ||
1439 | void net_enable_timestamp(void) | 1439 | void net_enable_timestamp(void) |
1440 | { | 1440 | { |
1441 | atomic_inc(&netstamp_needed); | 1441 | atomic_inc(&netstamp_needed); |
1442 | } | 1442 | } |
1443 | EXPORT_SYMBOL(net_enable_timestamp); | 1443 | EXPORT_SYMBOL(net_enable_timestamp); |
1444 | 1444 | ||
1445 | void net_disable_timestamp(void) | 1445 | void net_disable_timestamp(void) |
1446 | { | 1446 | { |
1447 | atomic_dec(&netstamp_needed); | 1447 | atomic_dec(&netstamp_needed); |
1448 | } | 1448 | } |
1449 | EXPORT_SYMBOL(net_disable_timestamp); | 1449 | EXPORT_SYMBOL(net_disable_timestamp); |
1450 | 1450 | ||
1451 | static inline void net_timestamp_set(struct sk_buff *skb) | 1451 | static inline void net_timestamp_set(struct sk_buff *skb) |
1452 | { | 1452 | { |
1453 | if (atomic_read(&netstamp_needed)) | 1453 | if (atomic_read(&netstamp_needed)) |
1454 | __net_timestamp(skb); | 1454 | __net_timestamp(skb); |
1455 | else | 1455 | else |
1456 | skb->tstamp.tv64 = 0; | 1456 | skb->tstamp.tv64 = 0; |
1457 | } | 1457 | } |
1458 | 1458 | ||
1459 | static inline void net_timestamp_check(struct sk_buff *skb) | 1459 | static inline void net_timestamp_check(struct sk_buff *skb) |
1460 | { | 1460 | { |
1461 | if (!skb->tstamp.tv64 && atomic_read(&netstamp_needed)) | 1461 | if (!skb->tstamp.tv64 && atomic_read(&netstamp_needed)) |
1462 | __net_timestamp(skb); | 1462 | __net_timestamp(skb); |
1463 | } | 1463 | } |
1464 | 1464 | ||
1465 | /** | 1465 | /** |
1466 | * dev_forward_skb - loopback an skb to another netif | 1466 | * dev_forward_skb - loopback an skb to another netif |
1467 | * | 1467 | * |
1468 | * @dev: destination network device | 1468 | * @dev: destination network device |
1469 | * @skb: buffer to forward | 1469 | * @skb: buffer to forward |
1470 | * | 1470 | * |
1471 | * return values: | 1471 | * return values: |
1472 | * NET_RX_SUCCESS (no congestion) | 1472 | * NET_RX_SUCCESS (no congestion) |
1473 | * NET_RX_DROP (packet was dropped, but freed) | 1473 | * NET_RX_DROP (packet was dropped, but freed) |
1474 | * | 1474 | * |
1475 | * dev_forward_skb can be used for injecting an skb from the | 1475 | * dev_forward_skb can be used for injecting an skb from the |
1476 | * start_xmit function of one device into the receive queue | 1476 | * start_xmit function of one device into the receive queue |
1477 | * of another device. | 1477 | * of another device. |
1478 | * | 1478 | * |
1479 | * The receiving device may be in another namespace, so | 1479 | * The receiving device may be in another namespace, so |
1480 | * we have to clear all information in the skb that could | 1480 | * we have to clear all information in the skb that could |
1481 | * impact namespace isolation. | 1481 | * impact namespace isolation. |
1482 | */ | 1482 | */ |
1483 | int dev_forward_skb(struct net_device *dev, struct sk_buff *skb) | 1483 | int dev_forward_skb(struct net_device *dev, struct sk_buff *skb) |
1484 | { | 1484 | { |
1485 | skb_orphan(skb); | 1485 | skb_orphan(skb); |
1486 | nf_reset(skb); | 1486 | nf_reset(skb); |
1487 | 1487 | ||
1488 | if (unlikely(!(dev->flags & IFF_UP) || | 1488 | if (unlikely(!(dev->flags & IFF_UP) || |
1489 | (skb->len > (dev->mtu + dev->hard_header_len + VLAN_HLEN)))) { | 1489 | (skb->len > (dev->mtu + dev->hard_header_len + VLAN_HLEN)))) { |
1490 | atomic_long_inc(&dev->rx_dropped); | 1490 | atomic_long_inc(&dev->rx_dropped); |
1491 | kfree_skb(skb); | 1491 | kfree_skb(skb); |
1492 | return NET_RX_DROP; | 1492 | return NET_RX_DROP; |
1493 | } | 1493 | } |
1494 | skb_set_dev(skb, dev); | 1494 | skb_set_dev(skb, dev); |
1495 | skb->tstamp.tv64 = 0; | 1495 | skb->tstamp.tv64 = 0; |
1496 | skb->pkt_type = PACKET_HOST; | 1496 | skb->pkt_type = PACKET_HOST; |
1497 | skb->protocol = eth_type_trans(skb, dev); | 1497 | skb->protocol = eth_type_trans(skb, dev); |
1498 | return netif_rx(skb); | 1498 | return netif_rx(skb); |
1499 | } | 1499 | } |
1500 | EXPORT_SYMBOL_GPL(dev_forward_skb); | 1500 | EXPORT_SYMBOL_GPL(dev_forward_skb); |
1501 | 1501 | ||
1502 | /* | 1502 | /* |
1503 | * Support routine. Sends outgoing frames to any network | 1503 | * Support routine. Sends outgoing frames to any network |
1504 | * taps currently in use. | 1504 | * taps currently in use. |
1505 | */ | 1505 | */ |
1506 | 1506 | ||
1507 | static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev) | 1507 | static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev) |
1508 | { | 1508 | { |
1509 | struct packet_type *ptype; | 1509 | struct packet_type *ptype; |
1510 | 1510 | ||
1511 | #ifdef CONFIG_NET_CLS_ACT | 1511 | #ifdef CONFIG_NET_CLS_ACT |
1512 | if (!(skb->tstamp.tv64 && (G_TC_FROM(skb->tc_verd) & AT_INGRESS))) | 1512 | if (!(skb->tstamp.tv64 && (G_TC_FROM(skb->tc_verd) & AT_INGRESS))) |
1513 | net_timestamp_set(skb); | 1513 | net_timestamp_set(skb); |
1514 | #else | 1514 | #else |
1515 | net_timestamp_set(skb); | 1515 | net_timestamp_set(skb); |
1516 | #endif | 1516 | #endif |
1517 | 1517 | ||
1518 | rcu_read_lock(); | 1518 | rcu_read_lock(); |
1519 | list_for_each_entry_rcu(ptype, &ptype_all, list) { | 1519 | list_for_each_entry_rcu(ptype, &ptype_all, list) { |
1520 | /* Never send packets back to the socket | 1520 | /* Never send packets back to the socket |
1521 | * they originated from - MvS (miquels@drinkel.ow.org) | 1521 | * they originated from - MvS (miquels@drinkel.ow.org) |
1522 | */ | 1522 | */ |
1523 | if ((ptype->dev == dev || !ptype->dev) && | 1523 | if ((ptype->dev == dev || !ptype->dev) && |
1524 | (ptype->af_packet_priv == NULL || | 1524 | (ptype->af_packet_priv == NULL || |
1525 | (struct sock *)ptype->af_packet_priv != skb->sk)) { | 1525 | (struct sock *)ptype->af_packet_priv != skb->sk)) { |
1526 | struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); | 1526 | struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC); |
1527 | if (!skb2) | 1527 | if (!skb2) |
1528 | break; | 1528 | break; |
1529 | 1529 | ||
1530 | /* skb->nh should be correctly | 1530 | /* skb->nh should be correctly |
1531 | set by sender, so that the second statement is | 1531 | set by sender, so that the second statement is |
1532 | just protection against buggy protocols. | 1532 | just protection against buggy protocols. |
1533 | */ | 1533 | */ |
1534 | skb_reset_mac_header(skb2); | 1534 | skb_reset_mac_header(skb2); |
1535 | 1535 | ||
1536 | if (skb_network_header(skb2) < skb2->data || | 1536 | if (skb_network_header(skb2) < skb2->data || |
1537 | skb2->network_header > skb2->tail) { | 1537 | skb2->network_header > skb2->tail) { |
1538 | if (net_ratelimit()) | 1538 | if (net_ratelimit()) |
1539 | printk(KERN_CRIT "protocol %04x is " | 1539 | printk(KERN_CRIT "protocol %04x is " |
1540 | "buggy, dev %s\n", | 1540 | "buggy, dev %s\n", |
1541 | ntohs(skb2->protocol), | 1541 | ntohs(skb2->protocol), |
1542 | dev->name); | 1542 | dev->name); |
1543 | skb_reset_network_header(skb2); | 1543 | skb_reset_network_header(skb2); |
1544 | } | 1544 | } |
1545 | 1545 | ||
1546 | skb2->transport_header = skb2->network_header; | 1546 | skb2->transport_header = skb2->network_header; |
1547 | skb2->pkt_type = PACKET_OUTGOING; | 1547 | skb2->pkt_type = PACKET_OUTGOING; |
1548 | ptype->func(skb2, skb->dev, ptype, skb->dev); | 1548 | ptype->func(skb2, skb->dev, ptype, skb->dev); |
1549 | } | 1549 | } |
1550 | } | 1550 | } |
1551 | rcu_read_unlock(); | 1551 | rcu_read_unlock(); |
1552 | } | 1552 | } |
1553 | 1553 | ||
1554 | /* | 1554 | /* |
1555 | * Routine to help set real_num_tx_queues. To avoid skbs mapped to queues | 1555 | * Routine to help set real_num_tx_queues. To avoid skbs mapped to queues |
1556 | * greater then real_num_tx_queues stale skbs on the qdisc must be flushed. | 1556 | * greater then real_num_tx_queues stale skbs on the qdisc must be flushed. |
1557 | */ | 1557 | */ |
1558 | int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq) | 1558 | int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq) |
1559 | { | 1559 | { |
1560 | int rc; | 1560 | int rc; |
1561 | 1561 | ||
1562 | if (txq < 1 || txq > dev->num_tx_queues) | 1562 | if (txq < 1 || txq > dev->num_tx_queues) |
1563 | return -EINVAL; | 1563 | return -EINVAL; |
1564 | 1564 | ||
1565 | if (dev->reg_state == NETREG_REGISTERED) { | 1565 | if (dev->reg_state == NETREG_REGISTERED) { |
1566 | ASSERT_RTNL(); | 1566 | ASSERT_RTNL(); |
1567 | 1567 | ||
1568 | rc = netdev_queue_update_kobjects(dev, dev->real_num_tx_queues, | 1568 | rc = netdev_queue_update_kobjects(dev, dev->real_num_tx_queues, |
1569 | txq); | 1569 | txq); |
1570 | if (rc) | ||
1571 | return rc; | ||
1572 | |||
1570 | if (txq < dev->real_num_tx_queues) | 1573 | if (txq < dev->real_num_tx_queues) |
1571 | qdisc_reset_all_tx_gt(dev, txq); | 1574 | qdisc_reset_all_tx_gt(dev, txq); |
1572 | } | 1575 | } |
1573 | 1576 | ||
1574 | dev->real_num_tx_queues = txq; | 1577 | dev->real_num_tx_queues = txq; |
1575 | return 0; | 1578 | return 0; |
1576 | } | 1579 | } |
1577 | EXPORT_SYMBOL(netif_set_real_num_tx_queues); | 1580 | EXPORT_SYMBOL(netif_set_real_num_tx_queues); |
1578 | 1581 | ||
1579 | #ifdef CONFIG_RPS | 1582 | #ifdef CONFIG_RPS |
1580 | /** | 1583 | /** |
1581 | * netif_set_real_num_rx_queues - set actual number of RX queues used | 1584 | * netif_set_real_num_rx_queues - set actual number of RX queues used |
1582 | * @dev: Network device | 1585 | * @dev: Network device |
1583 | * @rxq: Actual number of RX queues | 1586 | * @rxq: Actual number of RX queues |
1584 | * | 1587 | * |
1585 | * This must be called either with the rtnl_lock held or before | 1588 | * This must be called either with the rtnl_lock held or before |
1586 | * registration of the net device. Returns 0 on success, or a | 1589 | * registration of the net device. Returns 0 on success, or a |
1587 | * negative error code. If called before registration, it always | 1590 | * negative error code. If called before registration, it always |
1588 | * succeeds. | 1591 | * succeeds. |
1589 | */ | 1592 | */ |
1590 | int netif_set_real_num_rx_queues(struct net_device *dev, unsigned int rxq) | 1593 | int netif_set_real_num_rx_queues(struct net_device *dev, unsigned int rxq) |
1591 | { | 1594 | { |
1592 | int rc; | 1595 | int rc; |
1593 | 1596 | ||
1594 | if (rxq < 1 || rxq > dev->num_rx_queues) | 1597 | if (rxq < 1 || rxq > dev->num_rx_queues) |
1595 | return -EINVAL; | 1598 | return -EINVAL; |
1596 | 1599 | ||
1597 | if (dev->reg_state == NETREG_REGISTERED) { | 1600 | if (dev->reg_state == NETREG_REGISTERED) { |
1598 | ASSERT_RTNL(); | 1601 | ASSERT_RTNL(); |
1599 | 1602 | ||
1600 | rc = net_rx_queue_update_kobjects(dev, dev->real_num_rx_queues, | 1603 | rc = net_rx_queue_update_kobjects(dev, dev->real_num_rx_queues, |
1601 | rxq); | 1604 | rxq); |
1602 | if (rc) | 1605 | if (rc) |
1603 | return rc; | 1606 | return rc; |
1604 | } | 1607 | } |
1605 | 1608 | ||
1606 | dev->real_num_rx_queues = rxq; | 1609 | dev->real_num_rx_queues = rxq; |
1607 | return 0; | 1610 | return 0; |
1608 | } | 1611 | } |
1609 | EXPORT_SYMBOL(netif_set_real_num_rx_queues); | 1612 | EXPORT_SYMBOL(netif_set_real_num_rx_queues); |
1610 | #endif | 1613 | #endif |
1611 | 1614 | ||
1612 | static inline void __netif_reschedule(struct Qdisc *q) | 1615 | static inline void __netif_reschedule(struct Qdisc *q) |
1613 | { | 1616 | { |
1614 | struct softnet_data *sd; | 1617 | struct softnet_data *sd; |
1615 | unsigned long flags; | 1618 | unsigned long flags; |
1616 | 1619 | ||
1617 | local_irq_save(flags); | 1620 | local_irq_save(flags); |
1618 | sd = &__get_cpu_var(softnet_data); | 1621 | sd = &__get_cpu_var(softnet_data); |
1619 | q->next_sched = NULL; | 1622 | q->next_sched = NULL; |
1620 | *sd->output_queue_tailp = q; | 1623 | *sd->output_queue_tailp = q; |
1621 | sd->output_queue_tailp = &q->next_sched; | 1624 | sd->output_queue_tailp = &q->next_sched; |
1622 | raise_softirq_irqoff(NET_TX_SOFTIRQ); | 1625 | raise_softirq_irqoff(NET_TX_SOFTIRQ); |
1623 | local_irq_restore(flags); | 1626 | local_irq_restore(flags); |
1624 | } | 1627 | } |
1625 | 1628 | ||
1626 | void __netif_schedule(struct Qdisc *q) | 1629 | void __netif_schedule(struct Qdisc *q) |
1627 | { | 1630 | { |
1628 | if (!test_and_set_bit(__QDISC_STATE_SCHED, &q->state)) | 1631 | if (!test_and_set_bit(__QDISC_STATE_SCHED, &q->state)) |
1629 | __netif_reschedule(q); | 1632 | __netif_reschedule(q); |
1630 | } | 1633 | } |
1631 | EXPORT_SYMBOL(__netif_schedule); | 1634 | EXPORT_SYMBOL(__netif_schedule); |
1632 | 1635 | ||
1633 | void dev_kfree_skb_irq(struct sk_buff *skb) | 1636 | void dev_kfree_skb_irq(struct sk_buff *skb) |
1634 | { | 1637 | { |
1635 | if (atomic_dec_and_test(&skb->users)) { | 1638 | if (atomic_dec_and_test(&skb->users)) { |
1636 | struct softnet_data *sd; | 1639 | struct softnet_data *sd; |
1637 | unsigned long flags; | 1640 | unsigned long flags; |
1638 | 1641 | ||
1639 | local_irq_save(flags); | 1642 | local_irq_save(flags); |
1640 | sd = &__get_cpu_var(softnet_data); | 1643 | sd = &__get_cpu_var(softnet_data); |
1641 | skb->next = sd->completion_queue; | 1644 | skb->next = sd->completion_queue; |
1642 | sd->completion_queue = skb; | 1645 | sd->completion_queue = skb; |
1643 | raise_softirq_irqoff(NET_TX_SOFTIRQ); | 1646 | raise_softirq_irqoff(NET_TX_SOFTIRQ); |
1644 | local_irq_restore(flags); | 1647 | local_irq_restore(flags); |
1645 | } | 1648 | } |
1646 | } | 1649 | } |
1647 | EXPORT_SYMBOL(dev_kfree_skb_irq); | 1650 | EXPORT_SYMBOL(dev_kfree_skb_irq); |
1648 | 1651 | ||
1649 | void dev_kfree_skb_any(struct sk_buff *skb) | 1652 | void dev_kfree_skb_any(struct sk_buff *skb) |
1650 | { | 1653 | { |
1651 | if (in_irq() || irqs_disabled()) | 1654 | if (in_irq() || irqs_disabled()) |
1652 | dev_kfree_skb_irq(skb); | 1655 | dev_kfree_skb_irq(skb); |
1653 | else | 1656 | else |
1654 | dev_kfree_skb(skb); | 1657 | dev_kfree_skb(skb); |
1655 | } | 1658 | } |
1656 | EXPORT_SYMBOL(dev_kfree_skb_any); | 1659 | EXPORT_SYMBOL(dev_kfree_skb_any); |
1657 | 1660 | ||
1658 | 1661 | ||
1659 | /** | 1662 | /** |
1660 | * netif_device_detach - mark device as removed | 1663 | * netif_device_detach - mark device as removed |
1661 | * @dev: network device | 1664 | * @dev: network device |
1662 | * | 1665 | * |
1663 | * Mark device as removed from system and therefore no longer available. | 1666 | * Mark device as removed from system and therefore no longer available. |
1664 | */ | 1667 | */ |
1665 | void netif_device_detach(struct net_device *dev) | 1668 | void netif_device_detach(struct net_device *dev) |
1666 | { | 1669 | { |
1667 | if (test_and_clear_bit(__LINK_STATE_PRESENT, &dev->state) && | 1670 | if (test_and_clear_bit(__LINK_STATE_PRESENT, &dev->state) && |
1668 | netif_running(dev)) { | 1671 | netif_running(dev)) { |
1669 | netif_tx_stop_all_queues(dev); | 1672 | netif_tx_stop_all_queues(dev); |
1670 | } | 1673 | } |
1671 | } | 1674 | } |
1672 | EXPORT_SYMBOL(netif_device_detach); | 1675 | EXPORT_SYMBOL(netif_device_detach); |
1673 | 1676 | ||
1674 | /** | 1677 | /** |
1675 | * netif_device_attach - mark device as attached | 1678 | * netif_device_attach - mark device as attached |
1676 | * @dev: network device | 1679 | * @dev: network device |
1677 | * | 1680 | * |
1678 | * Mark device as attached from system and restart if needed. | 1681 | * Mark device as attached from system and restart if needed. |
1679 | */ | 1682 | */ |
1680 | void netif_device_attach(struct net_device *dev) | 1683 | void netif_device_attach(struct net_device *dev) |
1681 | { | 1684 | { |
1682 | if (!test_and_set_bit(__LINK_STATE_PRESENT, &dev->state) && | 1685 | if (!test_and_set_bit(__LINK_STATE_PRESENT, &dev->state) && |
1683 | netif_running(dev)) { | 1686 | netif_running(dev)) { |
1684 | netif_tx_wake_all_queues(dev); | 1687 | netif_tx_wake_all_queues(dev); |
1685 | __netdev_watchdog_up(dev); | 1688 | __netdev_watchdog_up(dev); |
1686 | } | 1689 | } |
1687 | } | 1690 | } |
1688 | EXPORT_SYMBOL(netif_device_attach); | 1691 | EXPORT_SYMBOL(netif_device_attach); |
1689 | 1692 | ||
1690 | static bool can_checksum_protocol(unsigned long features, __be16 protocol) | 1693 | static bool can_checksum_protocol(unsigned long features, __be16 protocol) |
1691 | { | 1694 | { |
1692 | return ((features & NETIF_F_NO_CSUM) || | 1695 | return ((features & NETIF_F_NO_CSUM) || |
1693 | ((features & NETIF_F_V4_CSUM) && | 1696 | ((features & NETIF_F_V4_CSUM) && |
1694 | protocol == htons(ETH_P_IP)) || | 1697 | protocol == htons(ETH_P_IP)) || |
1695 | ((features & NETIF_F_V6_CSUM) && | 1698 | ((features & NETIF_F_V6_CSUM) && |
1696 | protocol == htons(ETH_P_IPV6)) || | 1699 | protocol == htons(ETH_P_IPV6)) || |
1697 | ((features & NETIF_F_FCOE_CRC) && | 1700 | ((features & NETIF_F_FCOE_CRC) && |
1698 | protocol == htons(ETH_P_FCOE))); | 1701 | protocol == htons(ETH_P_FCOE))); |
1699 | } | 1702 | } |
1700 | 1703 | ||
1701 | static bool dev_can_checksum(struct net_device *dev, struct sk_buff *skb) | 1704 | static bool dev_can_checksum(struct net_device *dev, struct sk_buff *skb) |
1702 | { | 1705 | { |
1703 | __be16 protocol = skb->protocol; | 1706 | __be16 protocol = skb->protocol; |
1704 | int features = dev->features; | 1707 | int features = dev->features; |
1705 | 1708 | ||
1706 | if (vlan_tx_tag_present(skb)) { | 1709 | if (vlan_tx_tag_present(skb)) { |
1707 | features &= dev->vlan_features; | 1710 | features &= dev->vlan_features; |
1708 | } else if (protocol == htons(ETH_P_8021Q)) { | 1711 | } else if (protocol == htons(ETH_P_8021Q)) { |
1709 | struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data; | 1712 | struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data; |
1710 | protocol = veh->h_vlan_encapsulated_proto; | 1713 | protocol = veh->h_vlan_encapsulated_proto; |
1711 | features &= dev->vlan_features; | 1714 | features &= dev->vlan_features; |
1712 | } | 1715 | } |
1713 | 1716 | ||
1714 | return can_checksum_protocol(features, protocol); | 1717 | return can_checksum_protocol(features, protocol); |
1715 | } | 1718 | } |
1716 | 1719 | ||
1717 | /** | 1720 | /** |
1718 | * skb_dev_set -- assign a new device to a buffer | 1721 | * skb_dev_set -- assign a new device to a buffer |
1719 | * @skb: buffer for the new device | 1722 | * @skb: buffer for the new device |
1720 | * @dev: network device | 1723 | * @dev: network device |
1721 | * | 1724 | * |
1722 | * If an skb is owned by a device already, we have to reset | 1725 | * If an skb is owned by a device already, we have to reset |
1723 | * all data private to the namespace a device belongs to | 1726 | * all data private to the namespace a device belongs to |
1724 | * before assigning it a new device. | 1727 | * before assigning it a new device. |
1725 | */ | 1728 | */ |
1726 | #ifdef CONFIG_NET_NS | 1729 | #ifdef CONFIG_NET_NS |
1727 | void skb_set_dev(struct sk_buff *skb, struct net_device *dev) | 1730 | void skb_set_dev(struct sk_buff *skb, struct net_device *dev) |
1728 | { | 1731 | { |
1729 | skb_dst_drop(skb); | 1732 | skb_dst_drop(skb); |
1730 | if (skb->dev && !net_eq(dev_net(skb->dev), dev_net(dev))) { | 1733 | if (skb->dev && !net_eq(dev_net(skb->dev), dev_net(dev))) { |
1731 | secpath_reset(skb); | 1734 | secpath_reset(skb); |
1732 | nf_reset(skb); | 1735 | nf_reset(skb); |
1733 | skb_init_secmark(skb); | 1736 | skb_init_secmark(skb); |
1734 | skb->mark = 0; | 1737 | skb->mark = 0; |
1735 | skb->priority = 0; | 1738 | skb->priority = 0; |
1736 | skb->nf_trace = 0; | 1739 | skb->nf_trace = 0; |
1737 | skb->ipvs_property = 0; | 1740 | skb->ipvs_property = 0; |
1738 | #ifdef CONFIG_NET_SCHED | 1741 | #ifdef CONFIG_NET_SCHED |
1739 | skb->tc_index = 0; | 1742 | skb->tc_index = 0; |
1740 | #endif | 1743 | #endif |
1741 | } | 1744 | } |
1742 | skb->dev = dev; | 1745 | skb->dev = dev; |
1743 | } | 1746 | } |
1744 | EXPORT_SYMBOL(skb_set_dev); | 1747 | EXPORT_SYMBOL(skb_set_dev); |
1745 | #endif /* CONFIG_NET_NS */ | 1748 | #endif /* CONFIG_NET_NS */ |
1746 | 1749 | ||
1747 | /* | 1750 | /* |
1748 | * Invalidate hardware checksum when packet is to be mangled, and | 1751 | * Invalidate hardware checksum when packet is to be mangled, and |
1749 | * complete checksum manually on outgoing path. | 1752 | * complete checksum manually on outgoing path. |
1750 | */ | 1753 | */ |
1751 | int skb_checksum_help(struct sk_buff *skb) | 1754 | int skb_checksum_help(struct sk_buff *skb) |
1752 | { | 1755 | { |
1753 | __wsum csum; | 1756 | __wsum csum; |
1754 | int ret = 0, offset; | 1757 | int ret = 0, offset; |
1755 | 1758 | ||
1756 | if (skb->ip_summed == CHECKSUM_COMPLETE) | 1759 | if (skb->ip_summed == CHECKSUM_COMPLETE) |
1757 | goto out_set_summed; | 1760 | goto out_set_summed; |
1758 | 1761 | ||
1759 | if (unlikely(skb_shinfo(skb)->gso_size)) { | 1762 | if (unlikely(skb_shinfo(skb)->gso_size)) { |
1760 | /* Let GSO fix up the checksum. */ | 1763 | /* Let GSO fix up the checksum. */ |
1761 | goto out_set_summed; | 1764 | goto out_set_summed; |
1762 | } | 1765 | } |
1763 | 1766 | ||
1764 | offset = skb->csum_start - skb_headroom(skb); | 1767 | offset = skb->csum_start - skb_headroom(skb); |
1765 | BUG_ON(offset >= skb_headlen(skb)); | 1768 | BUG_ON(offset >= skb_headlen(skb)); |
1766 | csum = skb_checksum(skb, offset, skb->len - offset, 0); | 1769 | csum = skb_checksum(skb, offset, skb->len - offset, 0); |
1767 | 1770 | ||
1768 | offset += skb->csum_offset; | 1771 | offset += skb->csum_offset; |
1769 | BUG_ON(offset + sizeof(__sum16) > skb_headlen(skb)); | 1772 | BUG_ON(offset + sizeof(__sum16) > skb_headlen(skb)); |
1770 | 1773 | ||
1771 | if (skb_cloned(skb) && | 1774 | if (skb_cloned(skb) && |
1772 | !skb_clone_writable(skb, offset + sizeof(__sum16))) { | 1775 | !skb_clone_writable(skb, offset + sizeof(__sum16))) { |
1773 | ret = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); | 1776 | ret = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
1774 | if (ret) | 1777 | if (ret) |
1775 | goto out; | 1778 | goto out; |
1776 | } | 1779 | } |
1777 | 1780 | ||
1778 | *(__sum16 *)(skb->data + offset) = csum_fold(csum); | 1781 | *(__sum16 *)(skb->data + offset) = csum_fold(csum); |
1779 | out_set_summed: | 1782 | out_set_summed: |
1780 | skb->ip_summed = CHECKSUM_NONE; | 1783 | skb->ip_summed = CHECKSUM_NONE; |
1781 | out: | 1784 | out: |
1782 | return ret; | 1785 | return ret; |
1783 | } | 1786 | } |
1784 | EXPORT_SYMBOL(skb_checksum_help); | 1787 | EXPORT_SYMBOL(skb_checksum_help); |
1785 | 1788 | ||
1786 | /** | 1789 | /** |
1787 | * skb_gso_segment - Perform segmentation on skb. | 1790 | * skb_gso_segment - Perform segmentation on skb. |
1788 | * @skb: buffer to segment | 1791 | * @skb: buffer to segment |
1789 | * @features: features for the output path (see dev->features) | 1792 | * @features: features for the output path (see dev->features) |
1790 | * | 1793 | * |
1791 | * This function segments the given skb and returns a list of segments. | 1794 | * This function segments the given skb and returns a list of segments. |
1792 | * | 1795 | * |
1793 | * It may return NULL if the skb requires no segmentation. This is | 1796 | * It may return NULL if the skb requires no segmentation. This is |
1794 | * only possible when GSO is used for verifying header integrity. | 1797 | * only possible when GSO is used for verifying header integrity. |
1795 | */ | 1798 | */ |
1796 | struct sk_buff *skb_gso_segment(struct sk_buff *skb, int features) | 1799 | struct sk_buff *skb_gso_segment(struct sk_buff *skb, int features) |
1797 | { | 1800 | { |
1798 | struct sk_buff *segs = ERR_PTR(-EPROTONOSUPPORT); | 1801 | struct sk_buff *segs = ERR_PTR(-EPROTONOSUPPORT); |
1799 | struct packet_type *ptype; | 1802 | struct packet_type *ptype; |
1800 | __be16 type = skb->protocol; | 1803 | __be16 type = skb->protocol; |
1801 | int vlan_depth = ETH_HLEN; | 1804 | int vlan_depth = ETH_HLEN; |
1802 | int err; | 1805 | int err; |
1803 | 1806 | ||
1804 | while (type == htons(ETH_P_8021Q)) { | 1807 | while (type == htons(ETH_P_8021Q)) { |
1805 | struct vlan_hdr *vh; | 1808 | struct vlan_hdr *vh; |
1806 | 1809 | ||
1807 | if (unlikely(!pskb_may_pull(skb, vlan_depth + VLAN_HLEN))) | 1810 | if (unlikely(!pskb_may_pull(skb, vlan_depth + VLAN_HLEN))) |
1808 | return ERR_PTR(-EINVAL); | 1811 | return ERR_PTR(-EINVAL); |
1809 | 1812 | ||
1810 | vh = (struct vlan_hdr *)(skb->data + vlan_depth); | 1813 | vh = (struct vlan_hdr *)(skb->data + vlan_depth); |
1811 | type = vh->h_vlan_encapsulated_proto; | 1814 | type = vh->h_vlan_encapsulated_proto; |
1812 | vlan_depth += VLAN_HLEN; | 1815 | vlan_depth += VLAN_HLEN; |
1813 | } | 1816 | } |
1814 | 1817 | ||
1815 | skb_reset_mac_header(skb); | 1818 | skb_reset_mac_header(skb); |
1816 | skb->mac_len = skb->network_header - skb->mac_header; | 1819 | skb->mac_len = skb->network_header - skb->mac_header; |
1817 | __skb_pull(skb, skb->mac_len); | 1820 | __skb_pull(skb, skb->mac_len); |
1818 | 1821 | ||
1819 | if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) { | 1822 | if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) { |
1820 | struct net_device *dev = skb->dev; | 1823 | struct net_device *dev = skb->dev; |
1821 | struct ethtool_drvinfo info = {}; | 1824 | struct ethtool_drvinfo info = {}; |
1822 | 1825 | ||
1823 | if (dev && dev->ethtool_ops && dev->ethtool_ops->get_drvinfo) | 1826 | if (dev && dev->ethtool_ops && dev->ethtool_ops->get_drvinfo) |
1824 | dev->ethtool_ops->get_drvinfo(dev, &info); | 1827 | dev->ethtool_ops->get_drvinfo(dev, &info); |
1825 | 1828 | ||
1826 | WARN(1, "%s: caps=(0x%lx, 0x%lx) len=%d data_len=%d ip_summed=%d\n", | 1829 | WARN(1, "%s: caps=(0x%lx, 0x%lx) len=%d data_len=%d ip_summed=%d\n", |
1827 | info.driver, dev ? dev->features : 0L, | 1830 | info.driver, dev ? dev->features : 0L, |
1828 | skb->sk ? skb->sk->sk_route_caps : 0L, | 1831 | skb->sk ? skb->sk->sk_route_caps : 0L, |
1829 | skb->len, skb->data_len, skb->ip_summed); | 1832 | skb->len, skb->data_len, skb->ip_summed); |
1830 | 1833 | ||
1831 | if (skb_header_cloned(skb) && | 1834 | if (skb_header_cloned(skb) && |
1832 | (err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC))) | 1835 | (err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC))) |
1833 | return ERR_PTR(err); | 1836 | return ERR_PTR(err); |
1834 | } | 1837 | } |
1835 | 1838 | ||
1836 | rcu_read_lock(); | 1839 | rcu_read_lock(); |
1837 | list_for_each_entry_rcu(ptype, | 1840 | list_for_each_entry_rcu(ptype, |
1838 | &ptype_base[ntohs(type) & PTYPE_HASH_MASK], list) { | 1841 | &ptype_base[ntohs(type) & PTYPE_HASH_MASK], list) { |
1839 | if (ptype->type == type && !ptype->dev && ptype->gso_segment) { | 1842 | if (ptype->type == type && !ptype->dev && ptype->gso_segment) { |
1840 | if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) { | 1843 | if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) { |
1841 | err = ptype->gso_send_check(skb); | 1844 | err = ptype->gso_send_check(skb); |
1842 | segs = ERR_PTR(err); | 1845 | segs = ERR_PTR(err); |
1843 | if (err || skb_gso_ok(skb, features)) | 1846 | if (err || skb_gso_ok(skb, features)) |
1844 | break; | 1847 | break; |
1845 | __skb_push(skb, (skb->data - | 1848 | __skb_push(skb, (skb->data - |
1846 | skb_network_header(skb))); | 1849 | skb_network_header(skb))); |
1847 | } | 1850 | } |
1848 | segs = ptype->gso_segment(skb, features); | 1851 | segs = ptype->gso_segment(skb, features); |
1849 | break; | 1852 | break; |
1850 | } | 1853 | } |
1851 | } | 1854 | } |
1852 | rcu_read_unlock(); | 1855 | rcu_read_unlock(); |
1853 | 1856 | ||
1854 | __skb_push(skb, skb->data - skb_mac_header(skb)); | 1857 | __skb_push(skb, skb->data - skb_mac_header(skb)); |
1855 | 1858 | ||
1856 | return segs; | 1859 | return segs; |
1857 | } | 1860 | } |
1858 | EXPORT_SYMBOL(skb_gso_segment); | 1861 | EXPORT_SYMBOL(skb_gso_segment); |
1859 | 1862 | ||
1860 | /* Take action when hardware reception checksum errors are detected. */ | 1863 | /* Take action when hardware reception checksum errors are detected. */ |
1861 | #ifdef CONFIG_BUG | 1864 | #ifdef CONFIG_BUG |
1862 | void netdev_rx_csum_fault(struct net_device *dev) | 1865 | void netdev_rx_csum_fault(struct net_device *dev) |
1863 | { | 1866 | { |
1864 | if (net_ratelimit()) { | 1867 | if (net_ratelimit()) { |
1865 | printk(KERN_ERR "%s: hw csum failure.\n", | 1868 | printk(KERN_ERR "%s: hw csum failure.\n", |
1866 | dev ? dev->name : "<unknown>"); | 1869 | dev ? dev->name : "<unknown>"); |
1867 | dump_stack(); | 1870 | dump_stack(); |
1868 | } | 1871 | } |
1869 | } | 1872 | } |
1870 | EXPORT_SYMBOL(netdev_rx_csum_fault); | 1873 | EXPORT_SYMBOL(netdev_rx_csum_fault); |
1871 | #endif | 1874 | #endif |
1872 | 1875 | ||
1873 | /* Actually, we should eliminate this check as soon as we know, that: | 1876 | /* Actually, we should eliminate this check as soon as we know, that: |
1874 | * 1. IOMMU is present and allows to map all the memory. | 1877 | * 1. IOMMU is present and allows to map all the memory. |
1875 | * 2. No high memory really exists on this machine. | 1878 | * 2. No high memory really exists on this machine. |
1876 | */ | 1879 | */ |
1877 | 1880 | ||
1878 | static int illegal_highdma(struct net_device *dev, struct sk_buff *skb) | 1881 | static int illegal_highdma(struct net_device *dev, struct sk_buff *skb) |
1879 | { | 1882 | { |
1880 | #ifdef CONFIG_HIGHMEM | 1883 | #ifdef CONFIG_HIGHMEM |
1881 | int i; | 1884 | int i; |
1882 | if (!(dev->features & NETIF_F_HIGHDMA)) { | 1885 | if (!(dev->features & NETIF_F_HIGHDMA)) { |
1883 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) | 1886 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) |
1884 | if (PageHighMem(skb_shinfo(skb)->frags[i].page)) | 1887 | if (PageHighMem(skb_shinfo(skb)->frags[i].page)) |
1885 | return 1; | 1888 | return 1; |
1886 | } | 1889 | } |
1887 | 1890 | ||
1888 | if (PCI_DMA_BUS_IS_PHYS) { | 1891 | if (PCI_DMA_BUS_IS_PHYS) { |
1889 | struct device *pdev = dev->dev.parent; | 1892 | struct device *pdev = dev->dev.parent; |
1890 | 1893 | ||
1891 | if (!pdev) | 1894 | if (!pdev) |
1892 | return 0; | 1895 | return 0; |
1893 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { | 1896 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
1894 | dma_addr_t addr = page_to_phys(skb_shinfo(skb)->frags[i].page); | 1897 | dma_addr_t addr = page_to_phys(skb_shinfo(skb)->frags[i].page); |
1895 | if (!pdev->dma_mask || addr + PAGE_SIZE - 1 > *pdev->dma_mask) | 1898 | if (!pdev->dma_mask || addr + PAGE_SIZE - 1 > *pdev->dma_mask) |
1896 | return 1; | 1899 | return 1; |
1897 | } | 1900 | } |
1898 | } | 1901 | } |
1899 | #endif | 1902 | #endif |
1900 | return 0; | 1903 | return 0; |
1901 | } | 1904 | } |
1902 | 1905 | ||
1903 | struct dev_gso_cb { | 1906 | struct dev_gso_cb { |
1904 | void (*destructor)(struct sk_buff *skb); | 1907 | void (*destructor)(struct sk_buff *skb); |
1905 | }; | 1908 | }; |
1906 | 1909 | ||
1907 | #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb) | 1910 | #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb) |
1908 | 1911 | ||
1909 | static void dev_gso_skb_destructor(struct sk_buff *skb) | 1912 | static void dev_gso_skb_destructor(struct sk_buff *skb) |
1910 | { | 1913 | { |
1911 | struct dev_gso_cb *cb; | 1914 | struct dev_gso_cb *cb; |
1912 | 1915 | ||
1913 | do { | 1916 | do { |
1914 | struct sk_buff *nskb = skb->next; | 1917 | struct sk_buff *nskb = skb->next; |
1915 | 1918 | ||
1916 | skb->next = nskb->next; | 1919 | skb->next = nskb->next; |
1917 | nskb->next = NULL; | 1920 | nskb->next = NULL; |
1918 | kfree_skb(nskb); | 1921 | kfree_skb(nskb); |
1919 | } while (skb->next); | 1922 | } while (skb->next); |
1920 | 1923 | ||
1921 | cb = DEV_GSO_CB(skb); | 1924 | cb = DEV_GSO_CB(skb); |
1922 | if (cb->destructor) | 1925 | if (cb->destructor) |
1923 | cb->destructor(skb); | 1926 | cb->destructor(skb); |
1924 | } | 1927 | } |
1925 | 1928 | ||
1926 | /** | 1929 | /** |
1927 | * dev_gso_segment - Perform emulated hardware segmentation on skb. | 1930 | * dev_gso_segment - Perform emulated hardware segmentation on skb. |
1928 | * @skb: buffer to segment | 1931 | * @skb: buffer to segment |
1929 | * | 1932 | * |
1930 | * This function segments the given skb and stores the list of segments | 1933 | * This function segments the given skb and stores the list of segments |
1931 | * in skb->next. | 1934 | * in skb->next. |
1932 | */ | 1935 | */ |
1933 | static int dev_gso_segment(struct sk_buff *skb) | 1936 | static int dev_gso_segment(struct sk_buff *skb) |
1934 | { | 1937 | { |
1935 | struct net_device *dev = skb->dev; | 1938 | struct net_device *dev = skb->dev; |
1936 | struct sk_buff *segs; | 1939 | struct sk_buff *segs; |
1937 | int features = dev->features & ~(illegal_highdma(dev, skb) ? | 1940 | int features = dev->features & ~(illegal_highdma(dev, skb) ? |
1938 | NETIF_F_SG : 0); | 1941 | NETIF_F_SG : 0); |
1939 | 1942 | ||
1940 | segs = skb_gso_segment(skb, features); | 1943 | segs = skb_gso_segment(skb, features); |
1941 | 1944 | ||
1942 | /* Verifying header integrity only. */ | 1945 | /* Verifying header integrity only. */ |
1943 | if (!segs) | 1946 | if (!segs) |
1944 | return 0; | 1947 | return 0; |
1945 | 1948 | ||
1946 | if (IS_ERR(segs)) | 1949 | if (IS_ERR(segs)) |
1947 | return PTR_ERR(segs); | 1950 | return PTR_ERR(segs); |
1948 | 1951 | ||
1949 | skb->next = segs; | 1952 | skb->next = segs; |
1950 | DEV_GSO_CB(skb)->destructor = skb->destructor; | 1953 | DEV_GSO_CB(skb)->destructor = skb->destructor; |
1951 | skb->destructor = dev_gso_skb_destructor; | 1954 | skb->destructor = dev_gso_skb_destructor; |
1952 | 1955 | ||
1953 | return 0; | 1956 | return 0; |
1954 | } | 1957 | } |
1955 | 1958 | ||
1956 | /* | 1959 | /* |
1957 | * Try to orphan skb early, right before transmission by the device. | 1960 | * Try to orphan skb early, right before transmission by the device. |
1958 | * We cannot orphan skb if tx timestamp is requested or the sk-reference | 1961 | * We cannot orphan skb if tx timestamp is requested or the sk-reference |
1959 | * is needed on driver level for other reasons, e.g. see net/can/raw.c | 1962 | * is needed on driver level for other reasons, e.g. see net/can/raw.c |
1960 | */ | 1963 | */ |
1961 | static inline void skb_orphan_try(struct sk_buff *skb) | 1964 | static inline void skb_orphan_try(struct sk_buff *skb) |
1962 | { | 1965 | { |
1963 | struct sock *sk = skb->sk; | 1966 | struct sock *sk = skb->sk; |
1964 | 1967 | ||
1965 | if (sk && !skb_shinfo(skb)->tx_flags) { | 1968 | if (sk && !skb_shinfo(skb)->tx_flags) { |
1966 | /* skb_tx_hash() wont be able to get sk. | 1969 | /* skb_tx_hash() wont be able to get sk. |
1967 | * We copy sk_hash into skb->rxhash | 1970 | * We copy sk_hash into skb->rxhash |
1968 | */ | 1971 | */ |
1969 | if (!skb->rxhash) | 1972 | if (!skb->rxhash) |
1970 | skb->rxhash = sk->sk_hash; | 1973 | skb->rxhash = sk->sk_hash; |
1971 | skb_orphan(skb); | 1974 | skb_orphan(skb); |
1972 | } | 1975 | } |
1973 | } | 1976 | } |
1974 | 1977 | ||
1975 | int netif_get_vlan_features(struct sk_buff *skb, struct net_device *dev) | 1978 | int netif_get_vlan_features(struct sk_buff *skb, struct net_device *dev) |
1976 | { | 1979 | { |
1977 | __be16 protocol = skb->protocol; | 1980 | __be16 protocol = skb->protocol; |
1978 | 1981 | ||
1979 | if (protocol == htons(ETH_P_8021Q)) { | 1982 | if (protocol == htons(ETH_P_8021Q)) { |
1980 | struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data; | 1983 | struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data; |
1981 | protocol = veh->h_vlan_encapsulated_proto; | 1984 | protocol = veh->h_vlan_encapsulated_proto; |
1982 | } else if (!skb->vlan_tci) | 1985 | } else if (!skb->vlan_tci) |
1983 | return dev->features; | 1986 | return dev->features; |
1984 | 1987 | ||
1985 | if (protocol != htons(ETH_P_8021Q)) | 1988 | if (protocol != htons(ETH_P_8021Q)) |
1986 | return dev->features & dev->vlan_features; | 1989 | return dev->features & dev->vlan_features; |
1987 | else | 1990 | else |
1988 | return 0; | 1991 | return 0; |
1989 | } | 1992 | } |
1990 | EXPORT_SYMBOL(netif_get_vlan_features); | 1993 | EXPORT_SYMBOL(netif_get_vlan_features); |
1991 | 1994 | ||
1992 | /* | 1995 | /* |
1993 | * Returns true if either: | 1996 | * Returns true if either: |
1994 | * 1. skb has frag_list and the device doesn't support FRAGLIST, or | 1997 | * 1. skb has frag_list and the device doesn't support FRAGLIST, or |
1995 | * 2. skb is fragmented and the device does not support SG, or if | 1998 | * 2. skb is fragmented and the device does not support SG, or if |
1996 | * at least one of fragments is in highmem and device does not | 1999 | * at least one of fragments is in highmem and device does not |
1997 | * support DMA from it. | 2000 | * support DMA from it. |
1998 | */ | 2001 | */ |
1999 | static inline int skb_needs_linearize(struct sk_buff *skb, | 2002 | static inline int skb_needs_linearize(struct sk_buff *skb, |
2000 | struct net_device *dev) | 2003 | struct net_device *dev) |
2001 | { | 2004 | { |
2002 | if (skb_is_nonlinear(skb)) { | 2005 | if (skb_is_nonlinear(skb)) { |
2003 | int features = dev->features; | 2006 | int features = dev->features; |
2004 | 2007 | ||
2005 | if (vlan_tx_tag_present(skb)) | 2008 | if (vlan_tx_tag_present(skb)) |
2006 | features &= dev->vlan_features; | 2009 | features &= dev->vlan_features; |
2007 | 2010 | ||
2008 | return (skb_has_frag_list(skb) && | 2011 | return (skb_has_frag_list(skb) && |
2009 | !(features & NETIF_F_FRAGLIST)) || | 2012 | !(features & NETIF_F_FRAGLIST)) || |
2010 | (skb_shinfo(skb)->nr_frags && | 2013 | (skb_shinfo(skb)->nr_frags && |
2011 | (!(features & NETIF_F_SG) || | 2014 | (!(features & NETIF_F_SG) || |
2012 | illegal_highdma(dev, skb))); | 2015 | illegal_highdma(dev, skb))); |
2013 | } | 2016 | } |
2014 | 2017 | ||
2015 | return 0; | 2018 | return 0; |
2016 | } | 2019 | } |
2017 | 2020 | ||
2018 | int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev, | 2021 | int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev, |
2019 | struct netdev_queue *txq) | 2022 | struct netdev_queue *txq) |
2020 | { | 2023 | { |
2021 | const struct net_device_ops *ops = dev->netdev_ops; | 2024 | const struct net_device_ops *ops = dev->netdev_ops; |
2022 | int rc = NETDEV_TX_OK; | 2025 | int rc = NETDEV_TX_OK; |
2023 | 2026 | ||
2024 | if (likely(!skb->next)) { | 2027 | if (likely(!skb->next)) { |
2025 | if (!list_empty(&ptype_all)) | 2028 | if (!list_empty(&ptype_all)) |
2026 | dev_queue_xmit_nit(skb, dev); | 2029 | dev_queue_xmit_nit(skb, dev); |
2027 | 2030 | ||
2028 | /* | 2031 | /* |
2029 | * If device doesnt need skb->dst, release it right now while | 2032 | * If device doesnt need skb->dst, release it right now while |
2030 | * its hot in this cpu cache | 2033 | * its hot in this cpu cache |
2031 | */ | 2034 | */ |
2032 | if (dev->priv_flags & IFF_XMIT_DST_RELEASE) | 2035 | if (dev->priv_flags & IFF_XMIT_DST_RELEASE) |
2033 | skb_dst_drop(skb); | 2036 | skb_dst_drop(skb); |
2034 | 2037 | ||
2035 | skb_orphan_try(skb); | 2038 | skb_orphan_try(skb); |
2036 | 2039 | ||
2037 | if (vlan_tx_tag_present(skb) && | 2040 | if (vlan_tx_tag_present(skb) && |
2038 | !(dev->features & NETIF_F_HW_VLAN_TX)) { | 2041 | !(dev->features & NETIF_F_HW_VLAN_TX)) { |
2039 | skb = __vlan_put_tag(skb, vlan_tx_tag_get(skb)); | 2042 | skb = __vlan_put_tag(skb, vlan_tx_tag_get(skb)); |
2040 | if (unlikely(!skb)) | 2043 | if (unlikely(!skb)) |
2041 | goto out; | 2044 | goto out; |
2042 | 2045 | ||
2043 | skb->vlan_tci = 0; | 2046 | skb->vlan_tci = 0; |
2044 | } | 2047 | } |
2045 | 2048 | ||
2046 | if (netif_needs_gso(dev, skb)) { | 2049 | if (netif_needs_gso(dev, skb)) { |
2047 | if (unlikely(dev_gso_segment(skb))) | 2050 | if (unlikely(dev_gso_segment(skb))) |
2048 | goto out_kfree_skb; | 2051 | goto out_kfree_skb; |
2049 | if (skb->next) | 2052 | if (skb->next) |
2050 | goto gso; | 2053 | goto gso; |
2051 | } else { | 2054 | } else { |
2052 | if (skb_needs_linearize(skb, dev) && | 2055 | if (skb_needs_linearize(skb, dev) && |
2053 | __skb_linearize(skb)) | 2056 | __skb_linearize(skb)) |
2054 | goto out_kfree_skb; | 2057 | goto out_kfree_skb; |
2055 | 2058 | ||
2056 | /* If packet is not checksummed and device does not | 2059 | /* If packet is not checksummed and device does not |
2057 | * support checksumming for this protocol, complete | 2060 | * support checksumming for this protocol, complete |
2058 | * checksumming here. | 2061 | * checksumming here. |
2059 | */ | 2062 | */ |
2060 | if (skb->ip_summed == CHECKSUM_PARTIAL) { | 2063 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
2061 | skb_set_transport_header(skb, skb->csum_start - | 2064 | skb_set_transport_header(skb, skb->csum_start - |
2062 | skb_headroom(skb)); | 2065 | skb_headroom(skb)); |
2063 | if (!dev_can_checksum(dev, skb) && | 2066 | if (!dev_can_checksum(dev, skb) && |
2064 | skb_checksum_help(skb)) | 2067 | skb_checksum_help(skb)) |
2065 | goto out_kfree_skb; | 2068 | goto out_kfree_skb; |
2066 | } | 2069 | } |
2067 | } | 2070 | } |
2068 | 2071 | ||
2069 | rc = ops->ndo_start_xmit(skb, dev); | 2072 | rc = ops->ndo_start_xmit(skb, dev); |
2070 | trace_net_dev_xmit(skb, rc); | 2073 | trace_net_dev_xmit(skb, rc); |
2071 | if (rc == NETDEV_TX_OK) | 2074 | if (rc == NETDEV_TX_OK) |
2072 | txq_trans_update(txq); | 2075 | txq_trans_update(txq); |
2073 | return rc; | 2076 | return rc; |
2074 | } | 2077 | } |
2075 | 2078 | ||
2076 | gso: | 2079 | gso: |
2077 | do { | 2080 | do { |
2078 | struct sk_buff *nskb = skb->next; | 2081 | struct sk_buff *nskb = skb->next; |
2079 | 2082 | ||
2080 | skb->next = nskb->next; | 2083 | skb->next = nskb->next; |
2081 | nskb->next = NULL; | 2084 | nskb->next = NULL; |
2082 | 2085 | ||
2083 | /* | 2086 | /* |
2084 | * If device doesnt need nskb->dst, release it right now while | 2087 | * If device doesnt need nskb->dst, release it right now while |
2085 | * its hot in this cpu cache | 2088 | * its hot in this cpu cache |
2086 | */ | 2089 | */ |
2087 | if (dev->priv_flags & IFF_XMIT_DST_RELEASE) | 2090 | if (dev->priv_flags & IFF_XMIT_DST_RELEASE) |
2088 | skb_dst_drop(nskb); | 2091 | skb_dst_drop(nskb); |
2089 | 2092 | ||
2090 | rc = ops->ndo_start_xmit(nskb, dev); | 2093 | rc = ops->ndo_start_xmit(nskb, dev); |
2091 | trace_net_dev_xmit(nskb, rc); | 2094 | trace_net_dev_xmit(nskb, rc); |
2092 | if (unlikely(rc != NETDEV_TX_OK)) { | 2095 | if (unlikely(rc != NETDEV_TX_OK)) { |
2093 | if (rc & ~NETDEV_TX_MASK) | 2096 | if (rc & ~NETDEV_TX_MASK) |
2094 | goto out_kfree_gso_skb; | 2097 | goto out_kfree_gso_skb; |
2095 | nskb->next = skb->next; | 2098 | nskb->next = skb->next; |
2096 | skb->next = nskb; | 2099 | skb->next = nskb; |
2097 | return rc; | 2100 | return rc; |
2098 | } | 2101 | } |
2099 | txq_trans_update(txq); | 2102 | txq_trans_update(txq); |
2100 | if (unlikely(netif_tx_queue_stopped(txq) && skb->next)) | 2103 | if (unlikely(netif_tx_queue_stopped(txq) && skb->next)) |
2101 | return NETDEV_TX_BUSY; | 2104 | return NETDEV_TX_BUSY; |
2102 | } while (skb->next); | 2105 | } while (skb->next); |
2103 | 2106 | ||
2104 | out_kfree_gso_skb: | 2107 | out_kfree_gso_skb: |
2105 | if (likely(skb->next == NULL)) | 2108 | if (likely(skb->next == NULL)) |
2106 | skb->destructor = DEV_GSO_CB(skb)->destructor; | 2109 | skb->destructor = DEV_GSO_CB(skb)->destructor; |
2107 | out_kfree_skb: | 2110 | out_kfree_skb: |
2108 | kfree_skb(skb); | 2111 | kfree_skb(skb); |
2109 | out: | 2112 | out: |
2110 | return rc; | 2113 | return rc; |
2111 | } | 2114 | } |
2112 | 2115 | ||
2113 | static u32 hashrnd __read_mostly; | 2116 | static u32 hashrnd __read_mostly; |
2114 | 2117 | ||
2115 | u16 skb_tx_hash(const struct net_device *dev, const struct sk_buff *skb) | 2118 | u16 skb_tx_hash(const struct net_device *dev, const struct sk_buff *skb) |
2116 | { | 2119 | { |
2117 | u32 hash; | 2120 | u32 hash; |
2118 | 2121 | ||
2119 | if (skb_rx_queue_recorded(skb)) { | 2122 | if (skb_rx_queue_recorded(skb)) { |
2120 | hash = skb_get_rx_queue(skb); | 2123 | hash = skb_get_rx_queue(skb); |
2121 | while (unlikely(hash >= dev->real_num_tx_queues)) | 2124 | while (unlikely(hash >= dev->real_num_tx_queues)) |
2122 | hash -= dev->real_num_tx_queues; | 2125 | hash -= dev->real_num_tx_queues; |
2123 | return hash; | 2126 | return hash; |
2124 | } | 2127 | } |
2125 | 2128 | ||
2126 | if (skb->sk && skb->sk->sk_hash) | 2129 | if (skb->sk && skb->sk->sk_hash) |
2127 | hash = skb->sk->sk_hash; | 2130 | hash = skb->sk->sk_hash; |
2128 | else | 2131 | else |
2129 | hash = (__force u16) skb->protocol ^ skb->rxhash; | 2132 | hash = (__force u16) skb->protocol ^ skb->rxhash; |
2130 | hash = jhash_1word(hash, hashrnd); | 2133 | hash = jhash_1word(hash, hashrnd); |
2131 | 2134 | ||
2132 | return (u16) (((u64) hash * dev->real_num_tx_queues) >> 32); | 2135 | return (u16) (((u64) hash * dev->real_num_tx_queues) >> 32); |
2133 | } | 2136 | } |
2134 | EXPORT_SYMBOL(skb_tx_hash); | 2137 | EXPORT_SYMBOL(skb_tx_hash); |
2135 | 2138 | ||
2136 | static inline u16 dev_cap_txqueue(struct net_device *dev, u16 queue_index) | 2139 | static inline u16 dev_cap_txqueue(struct net_device *dev, u16 queue_index) |
2137 | { | 2140 | { |
2138 | if (unlikely(queue_index >= dev->real_num_tx_queues)) { | 2141 | if (unlikely(queue_index >= dev->real_num_tx_queues)) { |
2139 | if (net_ratelimit()) { | 2142 | if (net_ratelimit()) { |
2140 | pr_warning("%s selects TX queue %d, but " | 2143 | pr_warning("%s selects TX queue %d, but " |
2141 | "real number of TX queues is %d\n", | 2144 | "real number of TX queues is %d\n", |
2142 | dev->name, queue_index, dev->real_num_tx_queues); | 2145 | dev->name, queue_index, dev->real_num_tx_queues); |
2143 | } | 2146 | } |
2144 | return 0; | 2147 | return 0; |
2145 | } | 2148 | } |
2146 | return queue_index; | 2149 | return queue_index; |
2147 | } | 2150 | } |
2148 | 2151 | ||
2149 | static inline int get_xps_queue(struct net_device *dev, struct sk_buff *skb) | 2152 | static inline int get_xps_queue(struct net_device *dev, struct sk_buff *skb) |
2150 | { | 2153 | { |
2151 | #ifdef CONFIG_RPS | 2154 | #ifdef CONFIG_XPS |
2152 | struct xps_dev_maps *dev_maps; | 2155 | struct xps_dev_maps *dev_maps; |
2153 | struct xps_map *map; | 2156 | struct xps_map *map; |
2154 | int queue_index = -1; | 2157 | int queue_index = -1; |
2155 | 2158 | ||
2156 | rcu_read_lock(); | 2159 | rcu_read_lock(); |
2157 | dev_maps = rcu_dereference(dev->xps_maps); | 2160 | dev_maps = rcu_dereference(dev->xps_maps); |
2158 | if (dev_maps) { | 2161 | if (dev_maps) { |
2159 | map = rcu_dereference( | 2162 | map = rcu_dereference( |
2160 | dev_maps->cpu_map[raw_smp_processor_id()]); | 2163 | dev_maps->cpu_map[raw_smp_processor_id()]); |
2161 | if (map) { | 2164 | if (map) { |
2162 | if (map->len == 1) | 2165 | if (map->len == 1) |
2163 | queue_index = map->queues[0]; | 2166 | queue_index = map->queues[0]; |
2164 | else { | 2167 | else { |
2165 | u32 hash; | 2168 | u32 hash; |
2166 | if (skb->sk && skb->sk->sk_hash) | 2169 | if (skb->sk && skb->sk->sk_hash) |
2167 | hash = skb->sk->sk_hash; | 2170 | hash = skb->sk->sk_hash; |
2168 | else | 2171 | else |
2169 | hash = (__force u16) skb->protocol ^ | 2172 | hash = (__force u16) skb->protocol ^ |
2170 | skb->rxhash; | 2173 | skb->rxhash; |
2171 | hash = jhash_1word(hash, hashrnd); | 2174 | hash = jhash_1word(hash, hashrnd); |
2172 | queue_index = map->queues[ | 2175 | queue_index = map->queues[ |
2173 | ((u64)hash * map->len) >> 32]; | 2176 | ((u64)hash * map->len) >> 32]; |
2174 | } | 2177 | } |
2175 | if (unlikely(queue_index >= dev->real_num_tx_queues)) | 2178 | if (unlikely(queue_index >= dev->real_num_tx_queues)) |
2176 | queue_index = -1; | 2179 | queue_index = -1; |
2177 | } | 2180 | } |
2178 | } | 2181 | } |
2179 | rcu_read_unlock(); | 2182 | rcu_read_unlock(); |
2180 | 2183 | ||
2181 | return queue_index; | 2184 | return queue_index; |
2182 | #else | 2185 | #else |
2183 | return -1; | 2186 | return -1; |
2184 | #endif | 2187 | #endif |
2185 | } | 2188 | } |
2186 | 2189 | ||
2187 | static struct netdev_queue *dev_pick_tx(struct net_device *dev, | 2190 | static struct netdev_queue *dev_pick_tx(struct net_device *dev, |
2188 | struct sk_buff *skb) | 2191 | struct sk_buff *skb) |
2189 | { | 2192 | { |
2190 | int queue_index; | 2193 | int queue_index; |
2191 | const struct net_device_ops *ops = dev->netdev_ops; | 2194 | const struct net_device_ops *ops = dev->netdev_ops; |
2192 | 2195 | ||
2193 | if (dev->real_num_tx_queues == 1) | 2196 | if (dev->real_num_tx_queues == 1) |
2194 | queue_index = 0; | 2197 | queue_index = 0; |
2195 | else if (ops->ndo_select_queue) { | 2198 | else if (ops->ndo_select_queue) { |
2196 | queue_index = ops->ndo_select_queue(dev, skb); | 2199 | queue_index = ops->ndo_select_queue(dev, skb); |
2197 | queue_index = dev_cap_txqueue(dev, queue_index); | 2200 | queue_index = dev_cap_txqueue(dev, queue_index); |
2198 | } else { | 2201 | } else { |
2199 | struct sock *sk = skb->sk; | 2202 | struct sock *sk = skb->sk; |
2200 | queue_index = sk_tx_queue_get(sk); | 2203 | queue_index = sk_tx_queue_get(sk); |
2201 | 2204 | ||
2202 | if (queue_index < 0 || skb->ooo_okay || | 2205 | if (queue_index < 0 || skb->ooo_okay || |
2203 | queue_index >= dev->real_num_tx_queues) { | 2206 | queue_index >= dev->real_num_tx_queues) { |
2204 | int old_index = queue_index; | 2207 | int old_index = queue_index; |
2205 | 2208 | ||
2206 | queue_index = get_xps_queue(dev, skb); | 2209 | queue_index = get_xps_queue(dev, skb); |
2207 | if (queue_index < 0) | 2210 | if (queue_index < 0) |
2208 | queue_index = skb_tx_hash(dev, skb); | 2211 | queue_index = skb_tx_hash(dev, skb); |
2209 | 2212 | ||
2210 | if (queue_index != old_index && sk) { | 2213 | if (queue_index != old_index && sk) { |
2211 | struct dst_entry *dst = | 2214 | struct dst_entry *dst = |
2212 | rcu_dereference_check(sk->sk_dst_cache, 1); | 2215 | rcu_dereference_check(sk->sk_dst_cache, 1); |
2213 | 2216 | ||
2214 | if (dst && skb_dst(skb) == dst) | 2217 | if (dst && skb_dst(skb) == dst) |
2215 | sk_tx_queue_set(sk, queue_index); | 2218 | sk_tx_queue_set(sk, queue_index); |
2216 | } | 2219 | } |
2217 | } | 2220 | } |
2218 | } | 2221 | } |
2219 | 2222 | ||
2220 | skb_set_queue_mapping(skb, queue_index); | 2223 | skb_set_queue_mapping(skb, queue_index); |
2221 | return netdev_get_tx_queue(dev, queue_index); | 2224 | return netdev_get_tx_queue(dev, queue_index); |
2222 | } | 2225 | } |
2223 | 2226 | ||
2224 | static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q, | 2227 | static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q, |
2225 | struct net_device *dev, | 2228 | struct net_device *dev, |
2226 | struct netdev_queue *txq) | 2229 | struct netdev_queue *txq) |
2227 | { | 2230 | { |
2228 | spinlock_t *root_lock = qdisc_lock(q); | 2231 | spinlock_t *root_lock = qdisc_lock(q); |
2229 | bool contended = qdisc_is_running(q); | 2232 | bool contended = qdisc_is_running(q); |
2230 | int rc; | 2233 | int rc; |
2231 | 2234 | ||
2232 | /* | 2235 | /* |
2233 | * Heuristic to force contended enqueues to serialize on a | 2236 | * Heuristic to force contended enqueues to serialize on a |
2234 | * separate lock before trying to get qdisc main lock. | 2237 | * separate lock before trying to get qdisc main lock. |
2235 | * This permits __QDISC_STATE_RUNNING owner to get the lock more often | 2238 | * This permits __QDISC_STATE_RUNNING owner to get the lock more often |
2236 | * and dequeue packets faster. | 2239 | * and dequeue packets faster. |
2237 | */ | 2240 | */ |
2238 | if (unlikely(contended)) | 2241 | if (unlikely(contended)) |
2239 | spin_lock(&q->busylock); | 2242 | spin_lock(&q->busylock); |
2240 | 2243 | ||
2241 | spin_lock(root_lock); | 2244 | spin_lock(root_lock); |
2242 | if (unlikely(test_bit(__QDISC_STATE_DEACTIVATED, &q->state))) { | 2245 | if (unlikely(test_bit(__QDISC_STATE_DEACTIVATED, &q->state))) { |
2243 | kfree_skb(skb); | 2246 | kfree_skb(skb); |
2244 | rc = NET_XMIT_DROP; | 2247 | rc = NET_XMIT_DROP; |
2245 | } else if ((q->flags & TCQ_F_CAN_BYPASS) && !qdisc_qlen(q) && | 2248 | } else if ((q->flags & TCQ_F_CAN_BYPASS) && !qdisc_qlen(q) && |
2246 | qdisc_run_begin(q)) { | 2249 | qdisc_run_begin(q)) { |
2247 | /* | 2250 | /* |
2248 | * This is a work-conserving queue; there are no old skbs | 2251 | * This is a work-conserving queue; there are no old skbs |
2249 | * waiting to be sent out; and the qdisc is not running - | 2252 | * waiting to be sent out; and the qdisc is not running - |
2250 | * xmit the skb directly. | 2253 | * xmit the skb directly. |
2251 | */ | 2254 | */ |
2252 | if (!(dev->priv_flags & IFF_XMIT_DST_RELEASE)) | 2255 | if (!(dev->priv_flags & IFF_XMIT_DST_RELEASE)) |
2253 | skb_dst_force(skb); | 2256 | skb_dst_force(skb); |
2254 | __qdisc_update_bstats(q, skb->len); | 2257 | __qdisc_update_bstats(q, skb->len); |
2255 | if (sch_direct_xmit(skb, q, dev, txq, root_lock)) { | 2258 | if (sch_direct_xmit(skb, q, dev, txq, root_lock)) { |
2256 | if (unlikely(contended)) { | 2259 | if (unlikely(contended)) { |
2257 | spin_unlock(&q->busylock); | 2260 | spin_unlock(&q->busylock); |
2258 | contended = false; | 2261 | contended = false; |
2259 | } | 2262 | } |
2260 | __qdisc_run(q); | 2263 | __qdisc_run(q); |
2261 | } else | 2264 | } else |
2262 | qdisc_run_end(q); | 2265 | qdisc_run_end(q); |
2263 | 2266 | ||
2264 | rc = NET_XMIT_SUCCESS; | 2267 | rc = NET_XMIT_SUCCESS; |
2265 | } else { | 2268 | } else { |
2266 | skb_dst_force(skb); | 2269 | skb_dst_force(skb); |
2267 | rc = qdisc_enqueue_root(skb, q); | 2270 | rc = qdisc_enqueue_root(skb, q); |
2268 | if (qdisc_run_begin(q)) { | 2271 | if (qdisc_run_begin(q)) { |
2269 | if (unlikely(contended)) { | 2272 | if (unlikely(contended)) { |
2270 | spin_unlock(&q->busylock); | 2273 | spin_unlock(&q->busylock); |
2271 | contended = false; | 2274 | contended = false; |
2272 | } | 2275 | } |
2273 | __qdisc_run(q); | 2276 | __qdisc_run(q); |
2274 | } | 2277 | } |
2275 | } | 2278 | } |
2276 | spin_unlock(root_lock); | 2279 | spin_unlock(root_lock); |
2277 | if (unlikely(contended)) | 2280 | if (unlikely(contended)) |
2278 | spin_unlock(&q->busylock); | 2281 | spin_unlock(&q->busylock); |
2279 | return rc; | 2282 | return rc; |
2280 | } | 2283 | } |
2281 | 2284 | ||
2282 | static DEFINE_PER_CPU(int, xmit_recursion); | 2285 | static DEFINE_PER_CPU(int, xmit_recursion); |
2283 | #define RECURSION_LIMIT 10 | 2286 | #define RECURSION_LIMIT 10 |
2284 | 2287 | ||
2285 | /** | 2288 | /** |
2286 | * dev_queue_xmit - transmit a buffer | 2289 | * dev_queue_xmit - transmit a buffer |
2287 | * @skb: buffer to transmit | 2290 | * @skb: buffer to transmit |
2288 | * | 2291 | * |
2289 | * Queue a buffer for transmission to a network device. The caller must | 2292 | * Queue a buffer for transmission to a network device. The caller must |
2290 | * have set the device and priority and built the buffer before calling | 2293 | * have set the device and priority and built the buffer before calling |
2291 | * this function. The function can be called from an interrupt. | 2294 | * this function. The function can be called from an interrupt. |
2292 | * | 2295 | * |
2293 | * A negative errno code is returned on a failure. A success does not | 2296 | * A negative errno code is returned on a failure. A success does not |
2294 | * guarantee the frame will be transmitted as it may be dropped due | 2297 | * guarantee the frame will be transmitted as it may be dropped due |
2295 | * to congestion or traffic shaping. | 2298 | * to congestion or traffic shaping. |
2296 | * | 2299 | * |
2297 | * ----------------------------------------------------------------------------------- | 2300 | * ----------------------------------------------------------------------------------- |
2298 | * I notice this method can also return errors from the queue disciplines, | 2301 | * I notice this method can also return errors from the queue disciplines, |
2299 | * including NET_XMIT_DROP, which is a positive value. So, errors can also | 2302 | * including NET_XMIT_DROP, which is a positive value. So, errors can also |
2300 | * be positive. | 2303 | * be positive. |
2301 | * | 2304 | * |
2302 | * Regardless of the return value, the skb is consumed, so it is currently | 2305 | * Regardless of the return value, the skb is consumed, so it is currently |
2303 | * difficult to retry a send to this method. (You can bump the ref count | 2306 | * difficult to retry a send to this method. (You can bump the ref count |
2304 | * before sending to hold a reference for retry if you are careful.) | 2307 | * before sending to hold a reference for retry if you are careful.) |
2305 | * | 2308 | * |
2306 | * When calling this method, interrupts MUST be enabled. This is because | 2309 | * When calling this method, interrupts MUST be enabled. This is because |
2307 | * the BH enable code must have IRQs enabled so that it will not deadlock. | 2310 | * the BH enable code must have IRQs enabled so that it will not deadlock. |
2308 | * --BLG | 2311 | * --BLG |
2309 | */ | 2312 | */ |
2310 | int dev_queue_xmit(struct sk_buff *skb) | 2313 | int dev_queue_xmit(struct sk_buff *skb) |
2311 | { | 2314 | { |
2312 | struct net_device *dev = skb->dev; | 2315 | struct net_device *dev = skb->dev; |
2313 | struct netdev_queue *txq; | 2316 | struct netdev_queue *txq; |
2314 | struct Qdisc *q; | 2317 | struct Qdisc *q; |
2315 | int rc = -ENOMEM; | 2318 | int rc = -ENOMEM; |
2316 | 2319 | ||
2317 | /* Disable soft irqs for various locks below. Also | 2320 | /* Disable soft irqs for various locks below. Also |
2318 | * stops preemption for RCU. | 2321 | * stops preemption for RCU. |
2319 | */ | 2322 | */ |
2320 | rcu_read_lock_bh(); | 2323 | rcu_read_lock_bh(); |
2321 | 2324 | ||
2322 | txq = dev_pick_tx(dev, skb); | 2325 | txq = dev_pick_tx(dev, skb); |
2323 | q = rcu_dereference_bh(txq->qdisc); | 2326 | q = rcu_dereference_bh(txq->qdisc); |
2324 | 2327 | ||
2325 | #ifdef CONFIG_NET_CLS_ACT | 2328 | #ifdef CONFIG_NET_CLS_ACT |
2326 | skb->tc_verd = SET_TC_AT(skb->tc_verd, AT_EGRESS); | 2329 | skb->tc_verd = SET_TC_AT(skb->tc_verd, AT_EGRESS); |
2327 | #endif | 2330 | #endif |
2328 | trace_net_dev_queue(skb); | 2331 | trace_net_dev_queue(skb); |
2329 | if (q->enqueue) { | 2332 | if (q->enqueue) { |
2330 | rc = __dev_xmit_skb(skb, q, dev, txq); | 2333 | rc = __dev_xmit_skb(skb, q, dev, txq); |
2331 | goto out; | 2334 | goto out; |
2332 | } | 2335 | } |
2333 | 2336 | ||
2334 | /* The device has no queue. Common case for software devices: | 2337 | /* The device has no queue. Common case for software devices: |
2335 | loopback, all the sorts of tunnels... | 2338 | loopback, all the sorts of tunnels... |
2336 | 2339 | ||
2337 | Really, it is unlikely that netif_tx_lock protection is necessary | 2340 | Really, it is unlikely that netif_tx_lock protection is necessary |
2338 | here. (f.e. loopback and IP tunnels are clean ignoring statistics | 2341 | here. (f.e. loopback and IP tunnels are clean ignoring statistics |
2339 | counters.) | 2342 | counters.) |
2340 | However, it is possible, that they rely on protection | 2343 | However, it is possible, that they rely on protection |
2341 | made by us here. | 2344 | made by us here. |
2342 | 2345 | ||
2343 | Check this and shot the lock. It is not prone from deadlocks. | 2346 | Check this and shot the lock. It is not prone from deadlocks. |
2344 | Either shot noqueue qdisc, it is even simpler 8) | 2347 | Either shot noqueue qdisc, it is even simpler 8) |
2345 | */ | 2348 | */ |
2346 | if (dev->flags & IFF_UP) { | 2349 | if (dev->flags & IFF_UP) { |
2347 | int cpu = smp_processor_id(); /* ok because BHs are off */ | 2350 | int cpu = smp_processor_id(); /* ok because BHs are off */ |
2348 | 2351 | ||
2349 | if (txq->xmit_lock_owner != cpu) { | 2352 | if (txq->xmit_lock_owner != cpu) { |
2350 | 2353 | ||
2351 | if (__this_cpu_read(xmit_recursion) > RECURSION_LIMIT) | 2354 | if (__this_cpu_read(xmit_recursion) > RECURSION_LIMIT) |
2352 | goto recursion_alert; | 2355 | goto recursion_alert; |
2353 | 2356 | ||
2354 | HARD_TX_LOCK(dev, txq, cpu); | 2357 | HARD_TX_LOCK(dev, txq, cpu); |
2355 | 2358 | ||
2356 | if (!netif_tx_queue_stopped(txq)) { | 2359 | if (!netif_tx_queue_stopped(txq)) { |
2357 | __this_cpu_inc(xmit_recursion); | 2360 | __this_cpu_inc(xmit_recursion); |
2358 | rc = dev_hard_start_xmit(skb, dev, txq); | 2361 | rc = dev_hard_start_xmit(skb, dev, txq); |
2359 | __this_cpu_dec(xmit_recursion); | 2362 | __this_cpu_dec(xmit_recursion); |
2360 | if (dev_xmit_complete(rc)) { | 2363 | if (dev_xmit_complete(rc)) { |
2361 | HARD_TX_UNLOCK(dev, txq); | 2364 | HARD_TX_UNLOCK(dev, txq); |
2362 | goto out; | 2365 | goto out; |
2363 | } | 2366 | } |
2364 | } | 2367 | } |
2365 | HARD_TX_UNLOCK(dev, txq); | 2368 | HARD_TX_UNLOCK(dev, txq); |
2366 | if (net_ratelimit()) | 2369 | if (net_ratelimit()) |
2367 | printk(KERN_CRIT "Virtual device %s asks to " | 2370 | printk(KERN_CRIT "Virtual device %s asks to " |
2368 | "queue packet!\n", dev->name); | 2371 | "queue packet!\n", dev->name); |
2369 | } else { | 2372 | } else { |
2370 | /* Recursion is detected! It is possible, | 2373 | /* Recursion is detected! It is possible, |
2371 | * unfortunately | 2374 | * unfortunately |
2372 | */ | 2375 | */ |
2373 | recursion_alert: | 2376 | recursion_alert: |
2374 | if (net_ratelimit()) | 2377 | if (net_ratelimit()) |
2375 | printk(KERN_CRIT "Dead loop on virtual device " | 2378 | printk(KERN_CRIT "Dead loop on virtual device " |
2376 | "%s, fix it urgently!\n", dev->name); | 2379 | "%s, fix it urgently!\n", dev->name); |
2377 | } | 2380 | } |
2378 | } | 2381 | } |
2379 | 2382 | ||
2380 | rc = -ENETDOWN; | 2383 | rc = -ENETDOWN; |
2381 | rcu_read_unlock_bh(); | 2384 | rcu_read_unlock_bh(); |
2382 | 2385 | ||
2383 | kfree_skb(skb); | 2386 | kfree_skb(skb); |
2384 | return rc; | 2387 | return rc; |
2385 | out: | 2388 | out: |
2386 | rcu_read_unlock_bh(); | 2389 | rcu_read_unlock_bh(); |
2387 | return rc; | 2390 | return rc; |
2388 | } | 2391 | } |
2389 | EXPORT_SYMBOL(dev_queue_xmit); | 2392 | EXPORT_SYMBOL(dev_queue_xmit); |
2390 | 2393 | ||
2391 | 2394 | ||
2392 | /*======================================================================= | 2395 | /*======================================================================= |
2393 | Receiver routines | 2396 | Receiver routines |
2394 | =======================================================================*/ | 2397 | =======================================================================*/ |
2395 | 2398 | ||
2396 | int netdev_max_backlog __read_mostly = 1000; | 2399 | int netdev_max_backlog __read_mostly = 1000; |
2397 | int netdev_tstamp_prequeue __read_mostly = 1; | 2400 | int netdev_tstamp_prequeue __read_mostly = 1; |
2398 | int netdev_budget __read_mostly = 300; | 2401 | int netdev_budget __read_mostly = 300; |
2399 | int weight_p __read_mostly = 64; /* old backlog weight */ | 2402 | int weight_p __read_mostly = 64; /* old backlog weight */ |
2400 | 2403 | ||
2401 | /* Called with irq disabled */ | 2404 | /* Called with irq disabled */ |
2402 | static inline void ____napi_schedule(struct softnet_data *sd, | 2405 | static inline void ____napi_schedule(struct softnet_data *sd, |
2403 | struct napi_struct *napi) | 2406 | struct napi_struct *napi) |
2404 | { | 2407 | { |
2405 | list_add_tail(&napi->poll_list, &sd->poll_list); | 2408 | list_add_tail(&napi->poll_list, &sd->poll_list); |
2406 | __raise_softirq_irqoff(NET_RX_SOFTIRQ); | 2409 | __raise_softirq_irqoff(NET_RX_SOFTIRQ); |
2407 | } | 2410 | } |
2408 | 2411 | ||
2409 | /* | 2412 | /* |
2410 | * __skb_get_rxhash: calculate a flow hash based on src/dst addresses | 2413 | * __skb_get_rxhash: calculate a flow hash based on src/dst addresses |
2411 | * and src/dst port numbers. Returns a non-zero hash number on success | 2414 | * and src/dst port numbers. Returns a non-zero hash number on success |
2412 | * and 0 on failure. | 2415 | * and 0 on failure. |
2413 | */ | 2416 | */ |
2414 | __u32 __skb_get_rxhash(struct sk_buff *skb) | 2417 | __u32 __skb_get_rxhash(struct sk_buff *skb) |
2415 | { | 2418 | { |
2416 | int nhoff, hash = 0, poff; | 2419 | int nhoff, hash = 0, poff; |
2417 | struct ipv6hdr *ip6; | 2420 | struct ipv6hdr *ip6; |
2418 | struct iphdr *ip; | 2421 | struct iphdr *ip; |
2419 | u8 ip_proto; | 2422 | u8 ip_proto; |
2420 | u32 addr1, addr2, ihl; | 2423 | u32 addr1, addr2, ihl; |
2421 | union { | 2424 | union { |
2422 | u32 v32; | 2425 | u32 v32; |
2423 | u16 v16[2]; | 2426 | u16 v16[2]; |
2424 | } ports; | 2427 | } ports; |
2425 | 2428 | ||
2426 | nhoff = skb_network_offset(skb); | 2429 | nhoff = skb_network_offset(skb); |
2427 | 2430 | ||
2428 | switch (skb->protocol) { | 2431 | switch (skb->protocol) { |
2429 | case __constant_htons(ETH_P_IP): | 2432 | case __constant_htons(ETH_P_IP): |
2430 | if (!pskb_may_pull(skb, sizeof(*ip) + nhoff)) | 2433 | if (!pskb_may_pull(skb, sizeof(*ip) + nhoff)) |
2431 | goto done; | 2434 | goto done; |
2432 | 2435 | ||
2433 | ip = (struct iphdr *) (skb->data + nhoff); | 2436 | ip = (struct iphdr *) (skb->data + nhoff); |
2434 | if (ip->frag_off & htons(IP_MF | IP_OFFSET)) | 2437 | if (ip->frag_off & htons(IP_MF | IP_OFFSET)) |
2435 | ip_proto = 0; | 2438 | ip_proto = 0; |
2436 | else | 2439 | else |
2437 | ip_proto = ip->protocol; | 2440 | ip_proto = ip->protocol; |
2438 | addr1 = (__force u32) ip->saddr; | 2441 | addr1 = (__force u32) ip->saddr; |
2439 | addr2 = (__force u32) ip->daddr; | 2442 | addr2 = (__force u32) ip->daddr; |
2440 | ihl = ip->ihl; | 2443 | ihl = ip->ihl; |
2441 | break; | 2444 | break; |
2442 | case __constant_htons(ETH_P_IPV6): | 2445 | case __constant_htons(ETH_P_IPV6): |
2443 | if (!pskb_may_pull(skb, sizeof(*ip6) + nhoff)) | 2446 | if (!pskb_may_pull(skb, sizeof(*ip6) + nhoff)) |
2444 | goto done; | 2447 | goto done; |
2445 | 2448 | ||
2446 | ip6 = (struct ipv6hdr *) (skb->data + nhoff); | 2449 | ip6 = (struct ipv6hdr *) (skb->data + nhoff); |
2447 | ip_proto = ip6->nexthdr; | 2450 | ip_proto = ip6->nexthdr; |
2448 | addr1 = (__force u32) ip6->saddr.s6_addr32[3]; | 2451 | addr1 = (__force u32) ip6->saddr.s6_addr32[3]; |
2449 | addr2 = (__force u32) ip6->daddr.s6_addr32[3]; | 2452 | addr2 = (__force u32) ip6->daddr.s6_addr32[3]; |
2450 | ihl = (40 >> 2); | 2453 | ihl = (40 >> 2); |
2451 | break; | 2454 | break; |
2452 | default: | 2455 | default: |
2453 | goto done; | 2456 | goto done; |
2454 | } | 2457 | } |
2455 | 2458 | ||
2456 | ports.v32 = 0; | 2459 | ports.v32 = 0; |
2457 | poff = proto_ports_offset(ip_proto); | 2460 | poff = proto_ports_offset(ip_proto); |
2458 | if (poff >= 0) { | 2461 | if (poff >= 0) { |
2459 | nhoff += ihl * 4 + poff; | 2462 | nhoff += ihl * 4 + poff; |
2460 | if (pskb_may_pull(skb, nhoff + 4)) { | 2463 | if (pskb_may_pull(skb, nhoff + 4)) { |
2461 | ports.v32 = * (__force u32 *) (skb->data + nhoff); | 2464 | ports.v32 = * (__force u32 *) (skb->data + nhoff); |
2462 | if (ports.v16[1] < ports.v16[0]) | 2465 | if (ports.v16[1] < ports.v16[0]) |
2463 | swap(ports.v16[0], ports.v16[1]); | 2466 | swap(ports.v16[0], ports.v16[1]); |
2464 | } | 2467 | } |
2465 | } | 2468 | } |
2466 | 2469 | ||
2467 | /* get a consistent hash (same value on both flow directions) */ | 2470 | /* get a consistent hash (same value on both flow directions) */ |
2468 | if (addr2 < addr1) | 2471 | if (addr2 < addr1) |
2469 | swap(addr1, addr2); | 2472 | swap(addr1, addr2); |
2470 | 2473 | ||
2471 | hash = jhash_3words(addr1, addr2, ports.v32, hashrnd); | 2474 | hash = jhash_3words(addr1, addr2, ports.v32, hashrnd); |
2472 | if (!hash) | 2475 | if (!hash) |
2473 | hash = 1; | 2476 | hash = 1; |
2474 | 2477 | ||
2475 | done: | 2478 | done: |
2476 | return hash; | 2479 | return hash; |
2477 | } | 2480 | } |
2478 | EXPORT_SYMBOL(__skb_get_rxhash); | 2481 | EXPORT_SYMBOL(__skb_get_rxhash); |
2479 | 2482 | ||
2480 | #ifdef CONFIG_RPS | 2483 | #ifdef CONFIG_RPS |
2481 | 2484 | ||
2482 | /* One global table that all flow-based protocols share. */ | 2485 | /* One global table that all flow-based protocols share. */ |
2483 | struct rps_sock_flow_table __rcu *rps_sock_flow_table __read_mostly; | 2486 | struct rps_sock_flow_table __rcu *rps_sock_flow_table __read_mostly; |
2484 | EXPORT_SYMBOL(rps_sock_flow_table); | 2487 | EXPORT_SYMBOL(rps_sock_flow_table); |
2485 | 2488 | ||
2486 | /* | 2489 | /* |
2487 | * get_rps_cpu is called from netif_receive_skb and returns the target | 2490 | * get_rps_cpu is called from netif_receive_skb and returns the target |
2488 | * CPU from the RPS map of the receiving queue for a given skb. | 2491 | * CPU from the RPS map of the receiving queue for a given skb. |
2489 | * rcu_read_lock must be held on entry. | 2492 | * rcu_read_lock must be held on entry. |
2490 | */ | 2493 | */ |
2491 | static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb, | 2494 | static int get_rps_cpu(struct net_device *dev, struct sk_buff *skb, |
2492 | struct rps_dev_flow **rflowp) | 2495 | struct rps_dev_flow **rflowp) |
2493 | { | 2496 | { |
2494 | struct netdev_rx_queue *rxqueue; | 2497 | struct netdev_rx_queue *rxqueue; |
2495 | struct rps_map *map; | 2498 | struct rps_map *map; |
2496 | struct rps_dev_flow_table *flow_table; | 2499 | struct rps_dev_flow_table *flow_table; |
2497 | struct rps_sock_flow_table *sock_flow_table; | 2500 | struct rps_sock_flow_table *sock_flow_table; |
2498 | int cpu = -1; | 2501 | int cpu = -1; |
2499 | u16 tcpu; | 2502 | u16 tcpu; |
2500 | 2503 | ||
2501 | if (skb_rx_queue_recorded(skb)) { | 2504 | if (skb_rx_queue_recorded(skb)) { |
2502 | u16 index = skb_get_rx_queue(skb); | 2505 | u16 index = skb_get_rx_queue(skb); |
2503 | if (unlikely(index >= dev->real_num_rx_queues)) { | 2506 | if (unlikely(index >= dev->real_num_rx_queues)) { |
2504 | WARN_ONCE(dev->real_num_rx_queues > 1, | 2507 | WARN_ONCE(dev->real_num_rx_queues > 1, |
2505 | "%s received packet on queue %u, but number " | 2508 | "%s received packet on queue %u, but number " |
2506 | "of RX queues is %u\n", | 2509 | "of RX queues is %u\n", |
2507 | dev->name, index, dev->real_num_rx_queues); | 2510 | dev->name, index, dev->real_num_rx_queues); |
2508 | goto done; | 2511 | goto done; |
2509 | } | 2512 | } |
2510 | rxqueue = dev->_rx + index; | 2513 | rxqueue = dev->_rx + index; |
2511 | } else | 2514 | } else |
2512 | rxqueue = dev->_rx; | 2515 | rxqueue = dev->_rx; |
2513 | 2516 | ||
2514 | map = rcu_dereference(rxqueue->rps_map); | 2517 | map = rcu_dereference(rxqueue->rps_map); |
2515 | if (map) { | 2518 | if (map) { |
2516 | if (map->len == 1) { | 2519 | if (map->len == 1) { |
2517 | tcpu = map->cpus[0]; | 2520 | tcpu = map->cpus[0]; |
2518 | if (cpu_online(tcpu)) | 2521 | if (cpu_online(tcpu)) |
2519 | cpu = tcpu; | 2522 | cpu = tcpu; |
2520 | goto done; | 2523 | goto done; |
2521 | } | 2524 | } |
2522 | } else if (!rcu_dereference_raw(rxqueue->rps_flow_table)) { | 2525 | } else if (!rcu_dereference_raw(rxqueue->rps_flow_table)) { |
2523 | goto done; | 2526 | goto done; |
2524 | } | 2527 | } |
2525 | 2528 | ||
2526 | skb_reset_network_header(skb); | 2529 | skb_reset_network_header(skb); |
2527 | if (!skb_get_rxhash(skb)) | 2530 | if (!skb_get_rxhash(skb)) |
2528 | goto done; | 2531 | goto done; |
2529 | 2532 | ||
2530 | flow_table = rcu_dereference(rxqueue->rps_flow_table); | 2533 | flow_table = rcu_dereference(rxqueue->rps_flow_table); |
2531 | sock_flow_table = rcu_dereference(rps_sock_flow_table); | 2534 | sock_flow_table = rcu_dereference(rps_sock_flow_table); |
2532 | if (flow_table && sock_flow_table) { | 2535 | if (flow_table && sock_flow_table) { |
2533 | u16 next_cpu; | 2536 | u16 next_cpu; |
2534 | struct rps_dev_flow *rflow; | 2537 | struct rps_dev_flow *rflow; |
2535 | 2538 | ||
2536 | rflow = &flow_table->flows[skb->rxhash & flow_table->mask]; | 2539 | rflow = &flow_table->flows[skb->rxhash & flow_table->mask]; |
2537 | tcpu = rflow->cpu; | 2540 | tcpu = rflow->cpu; |
2538 | 2541 | ||
2539 | next_cpu = sock_flow_table->ents[skb->rxhash & | 2542 | next_cpu = sock_flow_table->ents[skb->rxhash & |
2540 | sock_flow_table->mask]; | 2543 | sock_flow_table->mask]; |
2541 | 2544 | ||
2542 | /* | 2545 | /* |
2543 | * If the desired CPU (where last recvmsg was done) is | 2546 | * If the desired CPU (where last recvmsg was done) is |
2544 | * different from current CPU (one in the rx-queue flow | 2547 | * different from current CPU (one in the rx-queue flow |
2545 | * table entry), switch if one of the following holds: | 2548 | * table entry), switch if one of the following holds: |
2546 | * - Current CPU is unset (equal to RPS_NO_CPU). | 2549 | * - Current CPU is unset (equal to RPS_NO_CPU). |
2547 | * - Current CPU is offline. | 2550 | * - Current CPU is offline. |
2548 | * - The current CPU's queue tail has advanced beyond the | 2551 | * - The current CPU's queue tail has advanced beyond the |
2549 | * last packet that was enqueued using this table entry. | 2552 | * last packet that was enqueued using this table entry. |
2550 | * This guarantees that all previous packets for the flow | 2553 | * This guarantees that all previous packets for the flow |
2551 | * have been dequeued, thus preserving in order delivery. | 2554 | * have been dequeued, thus preserving in order delivery. |
2552 | */ | 2555 | */ |
2553 | if (unlikely(tcpu != next_cpu) && | 2556 | if (unlikely(tcpu != next_cpu) && |
2554 | (tcpu == RPS_NO_CPU || !cpu_online(tcpu) || | 2557 | (tcpu == RPS_NO_CPU || !cpu_online(tcpu) || |
2555 | ((int)(per_cpu(softnet_data, tcpu).input_queue_head - | 2558 | ((int)(per_cpu(softnet_data, tcpu).input_queue_head - |
2556 | rflow->last_qtail)) >= 0)) { | 2559 | rflow->last_qtail)) >= 0)) { |
2557 | tcpu = rflow->cpu = next_cpu; | 2560 | tcpu = rflow->cpu = next_cpu; |
2558 | if (tcpu != RPS_NO_CPU) | 2561 | if (tcpu != RPS_NO_CPU) |
2559 | rflow->last_qtail = per_cpu(softnet_data, | 2562 | rflow->last_qtail = per_cpu(softnet_data, |
2560 | tcpu).input_queue_head; | 2563 | tcpu).input_queue_head; |
2561 | } | 2564 | } |
2562 | if (tcpu != RPS_NO_CPU && cpu_online(tcpu)) { | 2565 | if (tcpu != RPS_NO_CPU && cpu_online(tcpu)) { |
2563 | *rflowp = rflow; | 2566 | *rflowp = rflow; |
2564 | cpu = tcpu; | 2567 | cpu = tcpu; |
2565 | goto done; | 2568 | goto done; |
2566 | } | 2569 | } |
2567 | } | 2570 | } |
2568 | 2571 | ||
2569 | if (map) { | 2572 | if (map) { |
2570 | tcpu = map->cpus[((u64) skb->rxhash * map->len) >> 32]; | 2573 | tcpu = map->cpus[((u64) skb->rxhash * map->len) >> 32]; |
2571 | 2574 | ||
2572 | if (cpu_online(tcpu)) { | 2575 | if (cpu_online(tcpu)) { |
2573 | cpu = tcpu; | 2576 | cpu = tcpu; |
2574 | goto done; | 2577 | goto done; |
2575 | } | 2578 | } |
2576 | } | 2579 | } |
2577 | 2580 | ||
2578 | done: | 2581 | done: |
2579 | return cpu; | 2582 | return cpu; |
2580 | } | 2583 | } |
2581 | 2584 | ||
2582 | /* Called from hardirq (IPI) context */ | 2585 | /* Called from hardirq (IPI) context */ |
2583 | static void rps_trigger_softirq(void *data) | 2586 | static void rps_trigger_softirq(void *data) |
2584 | { | 2587 | { |
2585 | struct softnet_data *sd = data; | 2588 | struct softnet_data *sd = data; |
2586 | 2589 | ||
2587 | ____napi_schedule(sd, &sd->backlog); | 2590 | ____napi_schedule(sd, &sd->backlog); |
2588 | sd->received_rps++; | 2591 | sd->received_rps++; |
2589 | } | 2592 | } |
2590 | 2593 | ||
2591 | #endif /* CONFIG_RPS */ | 2594 | #endif /* CONFIG_RPS */ |
2592 | 2595 | ||
2593 | /* | 2596 | /* |
2594 | * Check if this softnet_data structure is another cpu one | 2597 | * Check if this softnet_data structure is another cpu one |
2595 | * If yes, queue it to our IPI list and return 1 | 2598 | * If yes, queue it to our IPI list and return 1 |
2596 | * If no, return 0 | 2599 | * If no, return 0 |
2597 | */ | 2600 | */ |
2598 | static int rps_ipi_queued(struct softnet_data *sd) | 2601 | static int rps_ipi_queued(struct softnet_data *sd) |
2599 | { | 2602 | { |
2600 | #ifdef CONFIG_RPS | 2603 | #ifdef CONFIG_RPS |
2601 | struct softnet_data *mysd = &__get_cpu_var(softnet_data); | 2604 | struct softnet_data *mysd = &__get_cpu_var(softnet_data); |
2602 | 2605 | ||
2603 | if (sd != mysd) { | 2606 | if (sd != mysd) { |
2604 | sd->rps_ipi_next = mysd->rps_ipi_list; | 2607 | sd->rps_ipi_next = mysd->rps_ipi_list; |
2605 | mysd->rps_ipi_list = sd; | 2608 | mysd->rps_ipi_list = sd; |
2606 | 2609 | ||
2607 | __raise_softirq_irqoff(NET_RX_SOFTIRQ); | 2610 | __raise_softirq_irqoff(NET_RX_SOFTIRQ); |
2608 | return 1; | 2611 | return 1; |
2609 | } | 2612 | } |
2610 | #endif /* CONFIG_RPS */ | 2613 | #endif /* CONFIG_RPS */ |
2611 | return 0; | 2614 | return 0; |
2612 | } | 2615 | } |
2613 | 2616 | ||
2614 | /* | 2617 | /* |
2615 | * enqueue_to_backlog is called to queue an skb to a per CPU backlog | 2618 | * enqueue_to_backlog is called to queue an skb to a per CPU backlog |
2616 | * queue (may be a remote CPU queue). | 2619 | * queue (may be a remote CPU queue). |
2617 | */ | 2620 | */ |
2618 | static int enqueue_to_backlog(struct sk_buff *skb, int cpu, | 2621 | static int enqueue_to_backlog(struct sk_buff *skb, int cpu, |
2619 | unsigned int *qtail) | 2622 | unsigned int *qtail) |
2620 | { | 2623 | { |
2621 | struct softnet_data *sd; | 2624 | struct softnet_data *sd; |
2622 | unsigned long flags; | 2625 | unsigned long flags; |
2623 | 2626 | ||
2624 | sd = &per_cpu(softnet_data, cpu); | 2627 | sd = &per_cpu(softnet_data, cpu); |
2625 | 2628 | ||
2626 | local_irq_save(flags); | 2629 | local_irq_save(flags); |
2627 | 2630 | ||
2628 | rps_lock(sd); | 2631 | rps_lock(sd); |
2629 | if (skb_queue_len(&sd->input_pkt_queue) <= netdev_max_backlog) { | 2632 | if (skb_queue_len(&sd->input_pkt_queue) <= netdev_max_backlog) { |
2630 | if (skb_queue_len(&sd->input_pkt_queue)) { | 2633 | if (skb_queue_len(&sd->input_pkt_queue)) { |
2631 | enqueue: | 2634 | enqueue: |
2632 | __skb_queue_tail(&sd->input_pkt_queue, skb); | 2635 | __skb_queue_tail(&sd->input_pkt_queue, skb); |
2633 | input_queue_tail_incr_save(sd, qtail); | 2636 | input_queue_tail_incr_save(sd, qtail); |
2634 | rps_unlock(sd); | 2637 | rps_unlock(sd); |
2635 | local_irq_restore(flags); | 2638 | local_irq_restore(flags); |
2636 | return NET_RX_SUCCESS; | 2639 | return NET_RX_SUCCESS; |
2637 | } | 2640 | } |
2638 | 2641 | ||
2639 | /* Schedule NAPI for backlog device | 2642 | /* Schedule NAPI for backlog device |
2640 | * We can use non atomic operation since we own the queue lock | 2643 | * We can use non atomic operation since we own the queue lock |
2641 | */ | 2644 | */ |
2642 | if (!__test_and_set_bit(NAPI_STATE_SCHED, &sd->backlog.state)) { | 2645 | if (!__test_and_set_bit(NAPI_STATE_SCHED, &sd->backlog.state)) { |
2643 | if (!rps_ipi_queued(sd)) | 2646 | if (!rps_ipi_queued(sd)) |
2644 | ____napi_schedule(sd, &sd->backlog); | 2647 | ____napi_schedule(sd, &sd->backlog); |
2645 | } | 2648 | } |
2646 | goto enqueue; | 2649 | goto enqueue; |
2647 | } | 2650 | } |
2648 | 2651 | ||
2649 | sd->dropped++; | 2652 | sd->dropped++; |
2650 | rps_unlock(sd); | 2653 | rps_unlock(sd); |
2651 | 2654 | ||
2652 | local_irq_restore(flags); | 2655 | local_irq_restore(flags); |
2653 | 2656 | ||
2654 | atomic_long_inc(&skb->dev->rx_dropped); | 2657 | atomic_long_inc(&skb->dev->rx_dropped); |
2655 | kfree_skb(skb); | 2658 | kfree_skb(skb); |
2656 | return NET_RX_DROP; | 2659 | return NET_RX_DROP; |
2657 | } | 2660 | } |
2658 | 2661 | ||
2659 | /** | 2662 | /** |
2660 | * netif_rx - post buffer to the network code | 2663 | * netif_rx - post buffer to the network code |
2661 | * @skb: buffer to post | 2664 | * @skb: buffer to post |
2662 | * | 2665 | * |
2663 | * This function receives a packet from a device driver and queues it for | 2666 | * This function receives a packet from a device driver and queues it for |
2664 | * the upper (protocol) levels to process. It always succeeds. The buffer | 2667 | * the upper (protocol) levels to process. It always succeeds. The buffer |
2665 | * may be dropped during processing for congestion control or by the | 2668 | * may be dropped during processing for congestion control or by the |
2666 | * protocol layers. | 2669 | * protocol layers. |
2667 | * | 2670 | * |
2668 | * return values: | 2671 | * return values: |
2669 | * NET_RX_SUCCESS (no congestion) | 2672 | * NET_RX_SUCCESS (no congestion) |
2670 | * NET_RX_DROP (packet was dropped) | 2673 | * NET_RX_DROP (packet was dropped) |
2671 | * | 2674 | * |
2672 | */ | 2675 | */ |
2673 | 2676 | ||
2674 | int netif_rx(struct sk_buff *skb) | 2677 | int netif_rx(struct sk_buff *skb) |
2675 | { | 2678 | { |
2676 | int ret; | 2679 | int ret; |
2677 | 2680 | ||
2678 | /* if netpoll wants it, pretend we never saw it */ | 2681 | /* if netpoll wants it, pretend we never saw it */ |
2679 | if (netpoll_rx(skb)) | 2682 | if (netpoll_rx(skb)) |
2680 | return NET_RX_DROP; | 2683 | return NET_RX_DROP; |
2681 | 2684 | ||
2682 | if (netdev_tstamp_prequeue) | 2685 | if (netdev_tstamp_prequeue) |
2683 | net_timestamp_check(skb); | 2686 | net_timestamp_check(skb); |
2684 | 2687 | ||
2685 | trace_netif_rx(skb); | 2688 | trace_netif_rx(skb); |
2686 | #ifdef CONFIG_RPS | 2689 | #ifdef CONFIG_RPS |
2687 | { | 2690 | { |
2688 | struct rps_dev_flow voidflow, *rflow = &voidflow; | 2691 | struct rps_dev_flow voidflow, *rflow = &voidflow; |
2689 | int cpu; | 2692 | int cpu; |
2690 | 2693 | ||
2691 | preempt_disable(); | 2694 | preempt_disable(); |
2692 | rcu_read_lock(); | 2695 | rcu_read_lock(); |
2693 | 2696 | ||
2694 | cpu = get_rps_cpu(skb->dev, skb, &rflow); | 2697 | cpu = get_rps_cpu(skb->dev, skb, &rflow); |
2695 | if (cpu < 0) | 2698 | if (cpu < 0) |
2696 | cpu = smp_processor_id(); | 2699 | cpu = smp_processor_id(); |
2697 | 2700 | ||
2698 | ret = enqueue_to_backlog(skb, cpu, &rflow->last_qtail); | 2701 | ret = enqueue_to_backlog(skb, cpu, &rflow->last_qtail); |
2699 | 2702 | ||
2700 | rcu_read_unlock(); | 2703 | rcu_read_unlock(); |
2701 | preempt_enable(); | 2704 | preempt_enable(); |
2702 | } | 2705 | } |
2703 | #else | 2706 | #else |
2704 | { | 2707 | { |
2705 | unsigned int qtail; | 2708 | unsigned int qtail; |
2706 | ret = enqueue_to_backlog(skb, get_cpu(), &qtail); | 2709 | ret = enqueue_to_backlog(skb, get_cpu(), &qtail); |
2707 | put_cpu(); | 2710 | put_cpu(); |
2708 | } | 2711 | } |
2709 | #endif | 2712 | #endif |
2710 | return ret; | 2713 | return ret; |
2711 | } | 2714 | } |
2712 | EXPORT_SYMBOL(netif_rx); | 2715 | EXPORT_SYMBOL(netif_rx); |
2713 | 2716 | ||
2714 | int netif_rx_ni(struct sk_buff *skb) | 2717 | int netif_rx_ni(struct sk_buff *skb) |
2715 | { | 2718 | { |
2716 | int err; | 2719 | int err; |
2717 | 2720 | ||
2718 | preempt_disable(); | 2721 | preempt_disable(); |
2719 | err = netif_rx(skb); | 2722 | err = netif_rx(skb); |
2720 | if (local_softirq_pending()) | 2723 | if (local_softirq_pending()) |
2721 | do_softirq(); | 2724 | do_softirq(); |
2722 | preempt_enable(); | 2725 | preempt_enable(); |
2723 | 2726 | ||
2724 | return err; | 2727 | return err; |
2725 | } | 2728 | } |
2726 | EXPORT_SYMBOL(netif_rx_ni); | 2729 | EXPORT_SYMBOL(netif_rx_ni); |
2727 | 2730 | ||
2728 | static void net_tx_action(struct softirq_action *h) | 2731 | static void net_tx_action(struct softirq_action *h) |
2729 | { | 2732 | { |
2730 | struct softnet_data *sd = &__get_cpu_var(softnet_data); | 2733 | struct softnet_data *sd = &__get_cpu_var(softnet_data); |
2731 | 2734 | ||
2732 | if (sd->completion_queue) { | 2735 | if (sd->completion_queue) { |
2733 | struct sk_buff *clist; | 2736 | struct sk_buff *clist; |
2734 | 2737 | ||
2735 | local_irq_disable(); | 2738 | local_irq_disable(); |
2736 | clist = sd->completion_queue; | 2739 | clist = sd->completion_queue; |
2737 | sd->completion_queue = NULL; | 2740 | sd->completion_queue = NULL; |
2738 | local_irq_enable(); | 2741 | local_irq_enable(); |
2739 | 2742 | ||
2740 | while (clist) { | 2743 | while (clist) { |
2741 | struct sk_buff *skb = clist; | 2744 | struct sk_buff *skb = clist; |
2742 | clist = clist->next; | 2745 | clist = clist->next; |
2743 | 2746 | ||
2744 | WARN_ON(atomic_read(&skb->users)); | 2747 | WARN_ON(atomic_read(&skb->users)); |
2745 | trace_kfree_skb(skb, net_tx_action); | 2748 | trace_kfree_skb(skb, net_tx_action); |
2746 | __kfree_skb(skb); | 2749 | __kfree_skb(skb); |
2747 | } | 2750 | } |
2748 | } | 2751 | } |
2749 | 2752 | ||
2750 | if (sd->output_queue) { | 2753 | if (sd->output_queue) { |
2751 | struct Qdisc *head; | 2754 | struct Qdisc *head; |
2752 | 2755 | ||
2753 | local_irq_disable(); | 2756 | local_irq_disable(); |
2754 | head = sd->output_queue; | 2757 | head = sd->output_queue; |
2755 | sd->output_queue = NULL; | 2758 | sd->output_queue = NULL; |
2756 | sd->output_queue_tailp = &sd->output_queue; | 2759 | sd->output_queue_tailp = &sd->output_queue; |
2757 | local_irq_enable(); | 2760 | local_irq_enable(); |
2758 | 2761 | ||
2759 | while (head) { | 2762 | while (head) { |
2760 | struct Qdisc *q = head; | 2763 | struct Qdisc *q = head; |
2761 | spinlock_t *root_lock; | 2764 | spinlock_t *root_lock; |
2762 | 2765 | ||
2763 | head = head->next_sched; | 2766 | head = head->next_sched; |
2764 | 2767 | ||
2765 | root_lock = qdisc_lock(q); | 2768 | root_lock = qdisc_lock(q); |
2766 | if (spin_trylock(root_lock)) { | 2769 | if (spin_trylock(root_lock)) { |
2767 | smp_mb__before_clear_bit(); | 2770 | smp_mb__before_clear_bit(); |
2768 | clear_bit(__QDISC_STATE_SCHED, | 2771 | clear_bit(__QDISC_STATE_SCHED, |
2769 | &q->state); | 2772 | &q->state); |
2770 | qdisc_run(q); | 2773 | qdisc_run(q); |
2771 | spin_unlock(root_lock); | 2774 | spin_unlock(root_lock); |
2772 | } else { | 2775 | } else { |
2773 | if (!test_bit(__QDISC_STATE_DEACTIVATED, | 2776 | if (!test_bit(__QDISC_STATE_DEACTIVATED, |
2774 | &q->state)) { | 2777 | &q->state)) { |
2775 | __netif_reschedule(q); | 2778 | __netif_reschedule(q); |
2776 | } else { | 2779 | } else { |
2777 | smp_mb__before_clear_bit(); | 2780 | smp_mb__before_clear_bit(); |
2778 | clear_bit(__QDISC_STATE_SCHED, | 2781 | clear_bit(__QDISC_STATE_SCHED, |
2779 | &q->state); | 2782 | &q->state); |
2780 | } | 2783 | } |
2781 | } | 2784 | } |
2782 | } | 2785 | } |
2783 | } | 2786 | } |
2784 | } | 2787 | } |
2785 | 2788 | ||
2786 | static inline int deliver_skb(struct sk_buff *skb, | 2789 | static inline int deliver_skb(struct sk_buff *skb, |
2787 | struct packet_type *pt_prev, | 2790 | struct packet_type *pt_prev, |
2788 | struct net_device *orig_dev) | 2791 | struct net_device *orig_dev) |
2789 | { | 2792 | { |
2790 | atomic_inc(&skb->users); | 2793 | atomic_inc(&skb->users); |
2791 | return pt_prev->func(skb, skb->dev, pt_prev, orig_dev); | 2794 | return pt_prev->func(skb, skb->dev, pt_prev, orig_dev); |
2792 | } | 2795 | } |
2793 | 2796 | ||
2794 | #if (defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)) && \ | 2797 | #if (defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)) && \ |
2795 | (defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)) | 2798 | (defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)) |
2796 | /* This hook is defined here for ATM LANE */ | 2799 | /* This hook is defined here for ATM LANE */ |
2797 | int (*br_fdb_test_addr_hook)(struct net_device *dev, | 2800 | int (*br_fdb_test_addr_hook)(struct net_device *dev, |
2798 | unsigned char *addr) __read_mostly; | 2801 | unsigned char *addr) __read_mostly; |
2799 | EXPORT_SYMBOL_GPL(br_fdb_test_addr_hook); | 2802 | EXPORT_SYMBOL_GPL(br_fdb_test_addr_hook); |
2800 | #endif | 2803 | #endif |
2801 | 2804 | ||
2802 | #ifdef CONFIG_NET_CLS_ACT | 2805 | #ifdef CONFIG_NET_CLS_ACT |
2803 | /* TODO: Maybe we should just force sch_ingress to be compiled in | 2806 | /* TODO: Maybe we should just force sch_ingress to be compiled in |
2804 | * when CONFIG_NET_CLS_ACT is? otherwise some useless instructions | 2807 | * when CONFIG_NET_CLS_ACT is? otherwise some useless instructions |
2805 | * a compare and 2 stores extra right now if we dont have it on | 2808 | * a compare and 2 stores extra right now if we dont have it on |
2806 | * but have CONFIG_NET_CLS_ACT | 2809 | * but have CONFIG_NET_CLS_ACT |
2807 | * NOTE: This doesnt stop any functionality; if you dont have | 2810 | * NOTE: This doesnt stop any functionality; if you dont have |
2808 | * the ingress scheduler, you just cant add policies on ingress. | 2811 | * the ingress scheduler, you just cant add policies on ingress. |
2809 | * | 2812 | * |
2810 | */ | 2813 | */ |
2811 | static int ing_filter(struct sk_buff *skb, struct netdev_queue *rxq) | 2814 | static int ing_filter(struct sk_buff *skb, struct netdev_queue *rxq) |
2812 | { | 2815 | { |
2813 | struct net_device *dev = skb->dev; | 2816 | struct net_device *dev = skb->dev; |
2814 | u32 ttl = G_TC_RTTL(skb->tc_verd); | 2817 | u32 ttl = G_TC_RTTL(skb->tc_verd); |
2815 | int result = TC_ACT_OK; | 2818 | int result = TC_ACT_OK; |
2816 | struct Qdisc *q; | 2819 | struct Qdisc *q; |
2817 | 2820 | ||
2818 | if (unlikely(MAX_RED_LOOP < ttl++)) { | 2821 | if (unlikely(MAX_RED_LOOP < ttl++)) { |
2819 | if (net_ratelimit()) | 2822 | if (net_ratelimit()) |
2820 | pr_warning( "Redir loop detected Dropping packet (%d->%d)\n", | 2823 | pr_warning( "Redir loop detected Dropping packet (%d->%d)\n", |
2821 | skb->skb_iif, dev->ifindex); | 2824 | skb->skb_iif, dev->ifindex); |
2822 | return TC_ACT_SHOT; | 2825 | return TC_ACT_SHOT; |
2823 | } | 2826 | } |
2824 | 2827 | ||
2825 | skb->tc_verd = SET_TC_RTTL(skb->tc_verd, ttl); | 2828 | skb->tc_verd = SET_TC_RTTL(skb->tc_verd, ttl); |
2826 | skb->tc_verd = SET_TC_AT(skb->tc_verd, AT_INGRESS); | 2829 | skb->tc_verd = SET_TC_AT(skb->tc_verd, AT_INGRESS); |
2827 | 2830 | ||
2828 | q = rxq->qdisc; | 2831 | q = rxq->qdisc; |
2829 | if (q != &noop_qdisc) { | 2832 | if (q != &noop_qdisc) { |
2830 | spin_lock(qdisc_lock(q)); | 2833 | spin_lock(qdisc_lock(q)); |
2831 | if (likely(!test_bit(__QDISC_STATE_DEACTIVATED, &q->state))) | 2834 | if (likely(!test_bit(__QDISC_STATE_DEACTIVATED, &q->state))) |
2832 | result = qdisc_enqueue_root(skb, q); | 2835 | result = qdisc_enqueue_root(skb, q); |
2833 | spin_unlock(qdisc_lock(q)); | 2836 | spin_unlock(qdisc_lock(q)); |
2834 | } | 2837 | } |
2835 | 2838 | ||
2836 | return result; | 2839 | return result; |
2837 | } | 2840 | } |
2838 | 2841 | ||
2839 | static inline struct sk_buff *handle_ing(struct sk_buff *skb, | 2842 | static inline struct sk_buff *handle_ing(struct sk_buff *skb, |
2840 | struct packet_type **pt_prev, | 2843 | struct packet_type **pt_prev, |
2841 | int *ret, struct net_device *orig_dev) | 2844 | int *ret, struct net_device *orig_dev) |
2842 | { | 2845 | { |
2843 | struct netdev_queue *rxq = rcu_dereference(skb->dev->ingress_queue); | 2846 | struct netdev_queue *rxq = rcu_dereference(skb->dev->ingress_queue); |
2844 | 2847 | ||
2845 | if (!rxq || rxq->qdisc == &noop_qdisc) | 2848 | if (!rxq || rxq->qdisc == &noop_qdisc) |
2846 | goto out; | 2849 | goto out; |
2847 | 2850 | ||
2848 | if (*pt_prev) { | 2851 | if (*pt_prev) { |
2849 | *ret = deliver_skb(skb, *pt_prev, orig_dev); | 2852 | *ret = deliver_skb(skb, *pt_prev, orig_dev); |
2850 | *pt_prev = NULL; | 2853 | *pt_prev = NULL; |
2851 | } | 2854 | } |
2852 | 2855 | ||
2853 | switch (ing_filter(skb, rxq)) { | 2856 | switch (ing_filter(skb, rxq)) { |
2854 | case TC_ACT_SHOT: | 2857 | case TC_ACT_SHOT: |
2855 | case TC_ACT_STOLEN: | 2858 | case TC_ACT_STOLEN: |
2856 | kfree_skb(skb); | 2859 | kfree_skb(skb); |
2857 | return NULL; | 2860 | return NULL; |
2858 | } | 2861 | } |
2859 | 2862 | ||
2860 | out: | 2863 | out: |
2861 | skb->tc_verd = 0; | 2864 | skb->tc_verd = 0; |
2862 | return skb; | 2865 | return skb; |
2863 | } | 2866 | } |
2864 | #endif | 2867 | #endif |
2865 | 2868 | ||
2866 | /** | 2869 | /** |
2867 | * netdev_rx_handler_register - register receive handler | 2870 | * netdev_rx_handler_register - register receive handler |
2868 | * @dev: device to register a handler for | 2871 | * @dev: device to register a handler for |
2869 | * @rx_handler: receive handler to register | 2872 | * @rx_handler: receive handler to register |
2870 | * @rx_handler_data: data pointer that is used by rx handler | 2873 | * @rx_handler_data: data pointer that is used by rx handler |
2871 | * | 2874 | * |
2872 | * Register a receive hander for a device. This handler will then be | 2875 | * Register a receive hander for a device. This handler will then be |
2873 | * called from __netif_receive_skb. A negative errno code is returned | 2876 | * called from __netif_receive_skb. A negative errno code is returned |
2874 | * on a failure. | 2877 | * on a failure. |
2875 | * | 2878 | * |
2876 | * The caller must hold the rtnl_mutex. | 2879 | * The caller must hold the rtnl_mutex. |
2877 | */ | 2880 | */ |
2878 | int netdev_rx_handler_register(struct net_device *dev, | 2881 | int netdev_rx_handler_register(struct net_device *dev, |
2879 | rx_handler_func_t *rx_handler, | 2882 | rx_handler_func_t *rx_handler, |
2880 | void *rx_handler_data) | 2883 | void *rx_handler_data) |
2881 | { | 2884 | { |
2882 | ASSERT_RTNL(); | 2885 | ASSERT_RTNL(); |
2883 | 2886 | ||
2884 | if (dev->rx_handler) | 2887 | if (dev->rx_handler) |
2885 | return -EBUSY; | 2888 | return -EBUSY; |
2886 | 2889 | ||
2887 | rcu_assign_pointer(dev->rx_handler_data, rx_handler_data); | 2890 | rcu_assign_pointer(dev->rx_handler_data, rx_handler_data); |
2888 | rcu_assign_pointer(dev->rx_handler, rx_handler); | 2891 | rcu_assign_pointer(dev->rx_handler, rx_handler); |
2889 | 2892 | ||
2890 | return 0; | 2893 | return 0; |
2891 | } | 2894 | } |
2892 | EXPORT_SYMBOL_GPL(netdev_rx_handler_register); | 2895 | EXPORT_SYMBOL_GPL(netdev_rx_handler_register); |
2893 | 2896 | ||
2894 | /** | 2897 | /** |
2895 | * netdev_rx_handler_unregister - unregister receive handler | 2898 | * netdev_rx_handler_unregister - unregister receive handler |
2896 | * @dev: device to unregister a handler from | 2899 | * @dev: device to unregister a handler from |
2897 | * | 2900 | * |
2898 | * Unregister a receive hander from a device. | 2901 | * Unregister a receive hander from a device. |
2899 | * | 2902 | * |
2900 | * The caller must hold the rtnl_mutex. | 2903 | * The caller must hold the rtnl_mutex. |
2901 | */ | 2904 | */ |
2902 | void netdev_rx_handler_unregister(struct net_device *dev) | 2905 | void netdev_rx_handler_unregister(struct net_device *dev) |
2903 | { | 2906 | { |
2904 | 2907 | ||
2905 | ASSERT_RTNL(); | 2908 | ASSERT_RTNL(); |
2906 | rcu_assign_pointer(dev->rx_handler, NULL); | 2909 | rcu_assign_pointer(dev->rx_handler, NULL); |
2907 | rcu_assign_pointer(dev->rx_handler_data, NULL); | 2910 | rcu_assign_pointer(dev->rx_handler_data, NULL); |
2908 | } | 2911 | } |
2909 | EXPORT_SYMBOL_GPL(netdev_rx_handler_unregister); | 2912 | EXPORT_SYMBOL_GPL(netdev_rx_handler_unregister); |
2910 | 2913 | ||
2911 | static inline void skb_bond_set_mac_by_master(struct sk_buff *skb, | 2914 | static inline void skb_bond_set_mac_by_master(struct sk_buff *skb, |
2912 | struct net_device *master) | 2915 | struct net_device *master) |
2913 | { | 2916 | { |
2914 | if (skb->pkt_type == PACKET_HOST) { | 2917 | if (skb->pkt_type == PACKET_HOST) { |
2915 | u16 *dest = (u16 *) eth_hdr(skb)->h_dest; | 2918 | u16 *dest = (u16 *) eth_hdr(skb)->h_dest; |
2916 | 2919 | ||
2917 | memcpy(dest, master->dev_addr, ETH_ALEN); | 2920 | memcpy(dest, master->dev_addr, ETH_ALEN); |
2918 | } | 2921 | } |
2919 | } | 2922 | } |
2920 | 2923 | ||
2921 | /* On bonding slaves other than the currently active slave, suppress | 2924 | /* On bonding slaves other than the currently active slave, suppress |
2922 | * duplicates except for 802.3ad ETH_P_SLOW, alb non-mcast/bcast, and | 2925 | * duplicates except for 802.3ad ETH_P_SLOW, alb non-mcast/bcast, and |
2923 | * ARP on active-backup slaves with arp_validate enabled. | 2926 | * ARP on active-backup slaves with arp_validate enabled. |
2924 | */ | 2927 | */ |
2925 | int __skb_bond_should_drop(struct sk_buff *skb, struct net_device *master) | 2928 | int __skb_bond_should_drop(struct sk_buff *skb, struct net_device *master) |
2926 | { | 2929 | { |
2927 | struct net_device *dev = skb->dev; | 2930 | struct net_device *dev = skb->dev; |
2928 | 2931 | ||
2929 | if (master->priv_flags & IFF_MASTER_ARPMON) | 2932 | if (master->priv_flags & IFF_MASTER_ARPMON) |
2930 | dev->last_rx = jiffies; | 2933 | dev->last_rx = jiffies; |
2931 | 2934 | ||
2932 | if ((master->priv_flags & IFF_MASTER_ALB) && | 2935 | if ((master->priv_flags & IFF_MASTER_ALB) && |
2933 | (master->priv_flags & IFF_BRIDGE_PORT)) { | 2936 | (master->priv_flags & IFF_BRIDGE_PORT)) { |
2934 | /* Do address unmangle. The local destination address | 2937 | /* Do address unmangle. The local destination address |
2935 | * will be always the one master has. Provides the right | 2938 | * will be always the one master has. Provides the right |
2936 | * functionality in a bridge. | 2939 | * functionality in a bridge. |
2937 | */ | 2940 | */ |
2938 | skb_bond_set_mac_by_master(skb, master); | 2941 | skb_bond_set_mac_by_master(skb, master); |
2939 | } | 2942 | } |
2940 | 2943 | ||
2941 | if (dev->priv_flags & IFF_SLAVE_INACTIVE) { | 2944 | if (dev->priv_flags & IFF_SLAVE_INACTIVE) { |
2942 | if ((dev->priv_flags & IFF_SLAVE_NEEDARP) && | 2945 | if ((dev->priv_flags & IFF_SLAVE_NEEDARP) && |
2943 | skb->protocol == __cpu_to_be16(ETH_P_ARP)) | 2946 | skb->protocol == __cpu_to_be16(ETH_P_ARP)) |
2944 | return 0; | 2947 | return 0; |
2945 | 2948 | ||
2946 | if (master->priv_flags & IFF_MASTER_ALB) { | 2949 | if (master->priv_flags & IFF_MASTER_ALB) { |
2947 | if (skb->pkt_type != PACKET_BROADCAST && | 2950 | if (skb->pkt_type != PACKET_BROADCAST && |
2948 | skb->pkt_type != PACKET_MULTICAST) | 2951 | skb->pkt_type != PACKET_MULTICAST) |
2949 | return 0; | 2952 | return 0; |
2950 | } | 2953 | } |
2951 | if (master->priv_flags & IFF_MASTER_8023AD && | 2954 | if (master->priv_flags & IFF_MASTER_8023AD && |
2952 | skb->protocol == __cpu_to_be16(ETH_P_SLOW)) | 2955 | skb->protocol == __cpu_to_be16(ETH_P_SLOW)) |
2953 | return 0; | 2956 | return 0; |
2954 | 2957 | ||
2955 | return 1; | 2958 | return 1; |
2956 | } | 2959 | } |
2957 | return 0; | 2960 | return 0; |
2958 | } | 2961 | } |
2959 | EXPORT_SYMBOL(__skb_bond_should_drop); | 2962 | EXPORT_SYMBOL(__skb_bond_should_drop); |
2960 | 2963 | ||
2961 | static int __netif_receive_skb(struct sk_buff *skb) | 2964 | static int __netif_receive_skb(struct sk_buff *skb) |
2962 | { | 2965 | { |
2963 | struct packet_type *ptype, *pt_prev; | 2966 | struct packet_type *ptype, *pt_prev; |
2964 | rx_handler_func_t *rx_handler; | 2967 | rx_handler_func_t *rx_handler; |
2965 | struct net_device *orig_dev; | 2968 | struct net_device *orig_dev; |
2966 | struct net_device *master; | 2969 | struct net_device *master; |
2967 | struct net_device *null_or_orig; | 2970 | struct net_device *null_or_orig; |
2968 | struct net_device *orig_or_bond; | 2971 | struct net_device *orig_or_bond; |
2969 | int ret = NET_RX_DROP; | 2972 | int ret = NET_RX_DROP; |
2970 | __be16 type; | 2973 | __be16 type; |
2971 | 2974 | ||
2972 | if (!netdev_tstamp_prequeue) | 2975 | if (!netdev_tstamp_prequeue) |
2973 | net_timestamp_check(skb); | 2976 | net_timestamp_check(skb); |
2974 | 2977 | ||
2975 | trace_netif_receive_skb(skb); | 2978 | trace_netif_receive_skb(skb); |
2976 | 2979 | ||
2977 | /* if we've gotten here through NAPI, check netpoll */ | 2980 | /* if we've gotten here through NAPI, check netpoll */ |
2978 | if (netpoll_receive_skb(skb)) | 2981 | if (netpoll_receive_skb(skb)) |
2979 | return NET_RX_DROP; | 2982 | return NET_RX_DROP; |
2980 | 2983 | ||
2981 | if (!skb->skb_iif) | 2984 | if (!skb->skb_iif) |
2982 | skb->skb_iif = skb->dev->ifindex; | 2985 | skb->skb_iif = skb->dev->ifindex; |
2983 | 2986 | ||
2984 | /* | 2987 | /* |
2985 | * bonding note: skbs received on inactive slaves should only | 2988 | * bonding note: skbs received on inactive slaves should only |
2986 | * be delivered to pkt handlers that are exact matches. Also | 2989 | * be delivered to pkt handlers that are exact matches. Also |
2987 | * the deliver_no_wcard flag will be set. If packet handlers | 2990 | * the deliver_no_wcard flag will be set. If packet handlers |
2988 | * are sensitive to duplicate packets these skbs will need to | 2991 | * are sensitive to duplicate packets these skbs will need to |
2989 | * be dropped at the handler. | 2992 | * be dropped at the handler. |
2990 | */ | 2993 | */ |
2991 | null_or_orig = NULL; | 2994 | null_or_orig = NULL; |
2992 | orig_dev = skb->dev; | 2995 | orig_dev = skb->dev; |
2993 | master = ACCESS_ONCE(orig_dev->master); | 2996 | master = ACCESS_ONCE(orig_dev->master); |
2994 | if (skb->deliver_no_wcard) | 2997 | if (skb->deliver_no_wcard) |
2995 | null_or_orig = orig_dev; | 2998 | null_or_orig = orig_dev; |
2996 | else if (master) { | 2999 | else if (master) { |
2997 | if (skb_bond_should_drop(skb, master)) { | 3000 | if (skb_bond_should_drop(skb, master)) { |
2998 | skb->deliver_no_wcard = 1; | 3001 | skb->deliver_no_wcard = 1; |
2999 | null_or_orig = orig_dev; /* deliver only exact match */ | 3002 | null_or_orig = orig_dev; /* deliver only exact match */ |
3000 | } else | 3003 | } else |
3001 | skb->dev = master; | 3004 | skb->dev = master; |
3002 | } | 3005 | } |
3003 | 3006 | ||
3004 | __this_cpu_inc(softnet_data.processed); | 3007 | __this_cpu_inc(softnet_data.processed); |
3005 | skb_reset_network_header(skb); | 3008 | skb_reset_network_header(skb); |
3006 | skb_reset_transport_header(skb); | 3009 | skb_reset_transport_header(skb); |
3007 | skb->mac_len = skb->network_header - skb->mac_header; | 3010 | skb->mac_len = skb->network_header - skb->mac_header; |
3008 | 3011 | ||
3009 | pt_prev = NULL; | 3012 | pt_prev = NULL; |
3010 | 3013 | ||
3011 | rcu_read_lock(); | 3014 | rcu_read_lock(); |
3012 | 3015 | ||
3013 | #ifdef CONFIG_NET_CLS_ACT | 3016 | #ifdef CONFIG_NET_CLS_ACT |
3014 | if (skb->tc_verd & TC_NCLS) { | 3017 | if (skb->tc_verd & TC_NCLS) { |
3015 | skb->tc_verd = CLR_TC_NCLS(skb->tc_verd); | 3018 | skb->tc_verd = CLR_TC_NCLS(skb->tc_verd); |
3016 | goto ncls; | 3019 | goto ncls; |
3017 | } | 3020 | } |
3018 | #endif | 3021 | #endif |
3019 | 3022 | ||
3020 | list_for_each_entry_rcu(ptype, &ptype_all, list) { | 3023 | list_for_each_entry_rcu(ptype, &ptype_all, list) { |
3021 | if (ptype->dev == null_or_orig || ptype->dev == skb->dev || | 3024 | if (ptype->dev == null_or_orig || ptype->dev == skb->dev || |
3022 | ptype->dev == orig_dev) { | 3025 | ptype->dev == orig_dev) { |
3023 | if (pt_prev) | 3026 | if (pt_prev) |
3024 | ret = deliver_skb(skb, pt_prev, orig_dev); | 3027 | ret = deliver_skb(skb, pt_prev, orig_dev); |
3025 | pt_prev = ptype; | 3028 | pt_prev = ptype; |
3026 | } | 3029 | } |
3027 | } | 3030 | } |
3028 | 3031 | ||
3029 | #ifdef CONFIG_NET_CLS_ACT | 3032 | #ifdef CONFIG_NET_CLS_ACT |
3030 | skb = handle_ing(skb, &pt_prev, &ret, orig_dev); | 3033 | skb = handle_ing(skb, &pt_prev, &ret, orig_dev); |
3031 | if (!skb) | 3034 | if (!skb) |
3032 | goto out; | 3035 | goto out; |
3033 | ncls: | 3036 | ncls: |
3034 | #endif | 3037 | #endif |
3035 | 3038 | ||
3036 | /* Handle special case of bridge or macvlan */ | 3039 | /* Handle special case of bridge or macvlan */ |
3037 | rx_handler = rcu_dereference(skb->dev->rx_handler); | 3040 | rx_handler = rcu_dereference(skb->dev->rx_handler); |
3038 | if (rx_handler) { | 3041 | if (rx_handler) { |
3039 | if (pt_prev) { | 3042 | if (pt_prev) { |
3040 | ret = deliver_skb(skb, pt_prev, orig_dev); | 3043 | ret = deliver_skb(skb, pt_prev, orig_dev); |
3041 | pt_prev = NULL; | 3044 | pt_prev = NULL; |
3042 | } | 3045 | } |
3043 | skb = rx_handler(skb); | 3046 | skb = rx_handler(skb); |
3044 | if (!skb) | 3047 | if (!skb) |
3045 | goto out; | 3048 | goto out; |
3046 | } | 3049 | } |
3047 | 3050 | ||
3048 | if (vlan_tx_tag_present(skb)) { | 3051 | if (vlan_tx_tag_present(skb)) { |
3049 | if (pt_prev) { | 3052 | if (pt_prev) { |
3050 | ret = deliver_skb(skb, pt_prev, orig_dev); | 3053 | ret = deliver_skb(skb, pt_prev, orig_dev); |
3051 | pt_prev = NULL; | 3054 | pt_prev = NULL; |
3052 | } | 3055 | } |
3053 | if (vlan_hwaccel_do_receive(&skb)) { | 3056 | if (vlan_hwaccel_do_receive(&skb)) { |
3054 | ret = __netif_receive_skb(skb); | 3057 | ret = __netif_receive_skb(skb); |
3055 | goto out; | 3058 | goto out; |
3056 | } else if (unlikely(!skb)) | 3059 | } else if (unlikely(!skb)) |
3057 | goto out; | 3060 | goto out; |
3058 | } | 3061 | } |
3059 | 3062 | ||
3060 | /* | 3063 | /* |
3061 | * Make sure frames received on VLAN interfaces stacked on | 3064 | * Make sure frames received on VLAN interfaces stacked on |
3062 | * bonding interfaces still make their way to any base bonding | 3065 | * bonding interfaces still make their way to any base bonding |
3063 | * device that may have registered for a specific ptype. The | 3066 | * device that may have registered for a specific ptype. The |
3064 | * handler may have to adjust skb->dev and orig_dev. | 3067 | * handler may have to adjust skb->dev and orig_dev. |
3065 | */ | 3068 | */ |
3066 | orig_or_bond = orig_dev; | 3069 | orig_or_bond = orig_dev; |
3067 | if ((skb->dev->priv_flags & IFF_802_1Q_VLAN) && | 3070 | if ((skb->dev->priv_flags & IFF_802_1Q_VLAN) && |
3068 | (vlan_dev_real_dev(skb->dev)->priv_flags & IFF_BONDING)) { | 3071 | (vlan_dev_real_dev(skb->dev)->priv_flags & IFF_BONDING)) { |
3069 | orig_or_bond = vlan_dev_real_dev(skb->dev); | 3072 | orig_or_bond = vlan_dev_real_dev(skb->dev); |
3070 | } | 3073 | } |
3071 | 3074 | ||
3072 | type = skb->protocol; | 3075 | type = skb->protocol; |
3073 | list_for_each_entry_rcu(ptype, | 3076 | list_for_each_entry_rcu(ptype, |
3074 | &ptype_base[ntohs(type) & PTYPE_HASH_MASK], list) { | 3077 | &ptype_base[ntohs(type) & PTYPE_HASH_MASK], list) { |
3075 | if (ptype->type == type && (ptype->dev == null_or_orig || | 3078 | if (ptype->type == type && (ptype->dev == null_or_orig || |
3076 | ptype->dev == skb->dev || ptype->dev == orig_dev || | 3079 | ptype->dev == skb->dev || ptype->dev == orig_dev || |
3077 | ptype->dev == orig_or_bond)) { | 3080 | ptype->dev == orig_or_bond)) { |
3078 | if (pt_prev) | 3081 | if (pt_prev) |
3079 | ret = deliver_skb(skb, pt_prev, orig_dev); | 3082 | ret = deliver_skb(skb, pt_prev, orig_dev); |
3080 | pt_prev = ptype; | 3083 | pt_prev = ptype; |
3081 | } | 3084 | } |
3082 | } | 3085 | } |
3083 | 3086 | ||
3084 | if (pt_prev) { | 3087 | if (pt_prev) { |
3085 | ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev); | 3088 | ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev); |
3086 | } else { | 3089 | } else { |
3087 | atomic_long_inc(&skb->dev->rx_dropped); | 3090 | atomic_long_inc(&skb->dev->rx_dropped); |
3088 | kfree_skb(skb); | 3091 | kfree_skb(skb); |
3089 | /* Jamal, now you will not able to escape explaining | 3092 | /* Jamal, now you will not able to escape explaining |
3090 | * me how you were going to use this. :-) | 3093 | * me how you were going to use this. :-) |
3091 | */ | 3094 | */ |
3092 | ret = NET_RX_DROP; | 3095 | ret = NET_RX_DROP; |
3093 | } | 3096 | } |
3094 | 3097 | ||
3095 | out: | 3098 | out: |
3096 | rcu_read_unlock(); | 3099 | rcu_read_unlock(); |
3097 | return ret; | 3100 | return ret; |
3098 | } | 3101 | } |
3099 | 3102 | ||
3100 | /** | 3103 | /** |
3101 | * netif_receive_skb - process receive buffer from network | 3104 | * netif_receive_skb - process receive buffer from network |
3102 | * @skb: buffer to process | 3105 | * @skb: buffer to process |
3103 | * | 3106 | * |
3104 | * netif_receive_skb() is the main receive data processing function. | 3107 | * netif_receive_skb() is the main receive data processing function. |
3105 | * It always succeeds. The buffer may be dropped during processing | 3108 | * It always succeeds. The buffer may be dropped during processing |
3106 | * for congestion control or by the protocol layers. | 3109 | * for congestion control or by the protocol layers. |
3107 | * | 3110 | * |
3108 | * This function may only be called from softirq context and interrupts | 3111 | * This function may only be called from softirq context and interrupts |
3109 | * should be enabled. | 3112 | * should be enabled. |
3110 | * | 3113 | * |
3111 | * Return values (usually ignored): | 3114 | * Return values (usually ignored): |
3112 | * NET_RX_SUCCESS: no congestion | 3115 | * NET_RX_SUCCESS: no congestion |
3113 | * NET_RX_DROP: packet was dropped | 3116 | * NET_RX_DROP: packet was dropped |
3114 | */ | 3117 | */ |
3115 | int netif_receive_skb(struct sk_buff *skb) | 3118 | int netif_receive_skb(struct sk_buff *skb) |
3116 | { | 3119 | { |
3117 | if (netdev_tstamp_prequeue) | 3120 | if (netdev_tstamp_prequeue) |
3118 | net_timestamp_check(skb); | 3121 | net_timestamp_check(skb); |
3119 | 3122 | ||
3120 | if (skb_defer_rx_timestamp(skb)) | 3123 | if (skb_defer_rx_timestamp(skb)) |
3121 | return NET_RX_SUCCESS; | 3124 | return NET_RX_SUCCESS; |
3122 | 3125 | ||
3123 | #ifdef CONFIG_RPS | 3126 | #ifdef CONFIG_RPS |
3124 | { | 3127 | { |
3125 | struct rps_dev_flow voidflow, *rflow = &voidflow; | 3128 | struct rps_dev_flow voidflow, *rflow = &voidflow; |
3126 | int cpu, ret; | 3129 | int cpu, ret; |
3127 | 3130 | ||
3128 | rcu_read_lock(); | 3131 | rcu_read_lock(); |
3129 | 3132 | ||
3130 | cpu = get_rps_cpu(skb->dev, skb, &rflow); | 3133 | cpu = get_rps_cpu(skb->dev, skb, &rflow); |
3131 | 3134 | ||
3132 | if (cpu >= 0) { | 3135 | if (cpu >= 0) { |
3133 | ret = enqueue_to_backlog(skb, cpu, &rflow->last_qtail); | 3136 | ret = enqueue_to_backlog(skb, cpu, &rflow->last_qtail); |
3134 | rcu_read_unlock(); | 3137 | rcu_read_unlock(); |
3135 | } else { | 3138 | } else { |
3136 | rcu_read_unlock(); | 3139 | rcu_read_unlock(); |
3137 | ret = __netif_receive_skb(skb); | 3140 | ret = __netif_receive_skb(skb); |
3138 | } | 3141 | } |
3139 | 3142 | ||
3140 | return ret; | 3143 | return ret; |
3141 | } | 3144 | } |
3142 | #else | 3145 | #else |
3143 | return __netif_receive_skb(skb); | 3146 | return __netif_receive_skb(skb); |
3144 | #endif | 3147 | #endif |
3145 | } | 3148 | } |
3146 | EXPORT_SYMBOL(netif_receive_skb); | 3149 | EXPORT_SYMBOL(netif_receive_skb); |
3147 | 3150 | ||
3148 | /* Network device is going away, flush any packets still pending | 3151 | /* Network device is going away, flush any packets still pending |
3149 | * Called with irqs disabled. | 3152 | * Called with irqs disabled. |
3150 | */ | 3153 | */ |
3151 | static void flush_backlog(void *arg) | 3154 | static void flush_backlog(void *arg) |
3152 | { | 3155 | { |
3153 | struct net_device *dev = arg; | 3156 | struct net_device *dev = arg; |
3154 | struct softnet_data *sd = &__get_cpu_var(softnet_data); | 3157 | struct softnet_data *sd = &__get_cpu_var(softnet_data); |
3155 | struct sk_buff *skb, *tmp; | 3158 | struct sk_buff *skb, *tmp; |
3156 | 3159 | ||
3157 | rps_lock(sd); | 3160 | rps_lock(sd); |
3158 | skb_queue_walk_safe(&sd->input_pkt_queue, skb, tmp) { | 3161 | skb_queue_walk_safe(&sd->input_pkt_queue, skb, tmp) { |
3159 | if (skb->dev == dev) { | 3162 | if (skb->dev == dev) { |
3160 | __skb_unlink(skb, &sd->input_pkt_queue); | 3163 | __skb_unlink(skb, &sd->input_pkt_queue); |
3161 | kfree_skb(skb); | 3164 | kfree_skb(skb); |
3162 | input_queue_head_incr(sd); | 3165 | input_queue_head_incr(sd); |
3163 | } | 3166 | } |
3164 | } | 3167 | } |
3165 | rps_unlock(sd); | 3168 | rps_unlock(sd); |
3166 | 3169 | ||
3167 | skb_queue_walk_safe(&sd->process_queue, skb, tmp) { | 3170 | skb_queue_walk_safe(&sd->process_queue, skb, tmp) { |
3168 | if (skb->dev == dev) { | 3171 | if (skb->dev == dev) { |
3169 | __skb_unlink(skb, &sd->process_queue); | 3172 | __skb_unlink(skb, &sd->process_queue); |
3170 | kfree_skb(skb); | 3173 | kfree_skb(skb); |
3171 | input_queue_head_incr(sd); | 3174 | input_queue_head_incr(sd); |
3172 | } | 3175 | } |
3173 | } | 3176 | } |
3174 | } | 3177 | } |
3175 | 3178 | ||
3176 | static int napi_gro_complete(struct sk_buff *skb) | 3179 | static int napi_gro_complete(struct sk_buff *skb) |
3177 | { | 3180 | { |
3178 | struct packet_type *ptype; | 3181 | struct packet_type *ptype; |
3179 | __be16 type = skb->protocol; | 3182 | __be16 type = skb->protocol; |
3180 | struct list_head *head = &ptype_base[ntohs(type) & PTYPE_HASH_MASK]; | 3183 | struct list_head *head = &ptype_base[ntohs(type) & PTYPE_HASH_MASK]; |
3181 | int err = -ENOENT; | 3184 | int err = -ENOENT; |
3182 | 3185 | ||
3183 | if (NAPI_GRO_CB(skb)->count == 1) { | 3186 | if (NAPI_GRO_CB(skb)->count == 1) { |
3184 | skb_shinfo(skb)->gso_size = 0; | 3187 | skb_shinfo(skb)->gso_size = 0; |
3185 | goto out; | 3188 | goto out; |
3186 | } | 3189 | } |
3187 | 3190 | ||
3188 | rcu_read_lock(); | 3191 | rcu_read_lock(); |
3189 | list_for_each_entry_rcu(ptype, head, list) { | 3192 | list_for_each_entry_rcu(ptype, head, list) { |
3190 | if (ptype->type != type || ptype->dev || !ptype->gro_complete) | 3193 | if (ptype->type != type || ptype->dev || !ptype->gro_complete) |
3191 | continue; | 3194 | continue; |
3192 | 3195 | ||
3193 | err = ptype->gro_complete(skb); | 3196 | err = ptype->gro_complete(skb); |
3194 | break; | 3197 | break; |
3195 | } | 3198 | } |
3196 | rcu_read_unlock(); | 3199 | rcu_read_unlock(); |
3197 | 3200 | ||
3198 | if (err) { | 3201 | if (err) { |
3199 | WARN_ON(&ptype->list == head); | 3202 | WARN_ON(&ptype->list == head); |
3200 | kfree_skb(skb); | 3203 | kfree_skb(skb); |
3201 | return NET_RX_SUCCESS; | 3204 | return NET_RX_SUCCESS; |
3202 | } | 3205 | } |
3203 | 3206 | ||
3204 | out: | 3207 | out: |
3205 | return netif_receive_skb(skb); | 3208 | return netif_receive_skb(skb); |
3206 | } | 3209 | } |
3207 | 3210 | ||
3208 | inline void napi_gro_flush(struct napi_struct *napi) | 3211 | inline void napi_gro_flush(struct napi_struct *napi) |
3209 | { | 3212 | { |
3210 | struct sk_buff *skb, *next; | 3213 | struct sk_buff *skb, *next; |
3211 | 3214 | ||
3212 | for (skb = napi->gro_list; skb; skb = next) { | 3215 | for (skb = napi->gro_list; skb; skb = next) { |
3213 | next = skb->next; | 3216 | next = skb->next; |
3214 | skb->next = NULL; | 3217 | skb->next = NULL; |
3215 | napi_gro_complete(skb); | 3218 | napi_gro_complete(skb); |
3216 | } | 3219 | } |
3217 | 3220 | ||
3218 | napi->gro_count = 0; | 3221 | napi->gro_count = 0; |
3219 | napi->gro_list = NULL; | 3222 | napi->gro_list = NULL; |
3220 | } | 3223 | } |
3221 | EXPORT_SYMBOL(napi_gro_flush); | 3224 | EXPORT_SYMBOL(napi_gro_flush); |
3222 | 3225 | ||
3223 | enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff *skb) | 3226 | enum gro_result dev_gro_receive(struct napi_struct *napi, struct sk_buff *skb) |
3224 | { | 3227 | { |
3225 | struct sk_buff **pp = NULL; | 3228 | struct sk_buff **pp = NULL; |
3226 | struct packet_type *ptype; | 3229 | struct packet_type *ptype; |
3227 | __be16 type = skb->protocol; | 3230 | __be16 type = skb->protocol; |
3228 | struct list_head *head = &ptype_base[ntohs(type) & PTYPE_HASH_MASK]; | 3231 | struct list_head *head = &ptype_base[ntohs(type) & PTYPE_HASH_MASK]; |
3229 | int same_flow; | 3232 | int same_flow; |
3230 | int mac_len; | 3233 | int mac_len; |
3231 | enum gro_result ret; | 3234 | enum gro_result ret; |
3232 | 3235 | ||
3233 | if (!(skb->dev->features & NETIF_F_GRO) || netpoll_rx_on(skb)) | 3236 | if (!(skb->dev->features & NETIF_F_GRO) || netpoll_rx_on(skb)) |
3234 | goto normal; | 3237 | goto normal; |
3235 | 3238 | ||
3236 | if (skb_is_gso(skb) || skb_has_frag_list(skb)) | 3239 | if (skb_is_gso(skb) || skb_has_frag_list(skb)) |
3237 | goto normal; | 3240 | goto normal; |
3238 | 3241 | ||
3239 | rcu_read_lock(); | 3242 | rcu_read_lock(); |
3240 | list_for_each_entry_rcu(ptype, head, list) { | 3243 | list_for_each_entry_rcu(ptype, head, list) { |
3241 | if (ptype->type != type || ptype->dev || !ptype->gro_receive) | 3244 | if (ptype->type != type || ptype->dev || !ptype->gro_receive) |
3242 | continue; | 3245 | continue; |
3243 | 3246 | ||
3244 | skb_set_network_header(skb, skb_gro_offset(skb)); | 3247 | skb_set_network_header(skb, skb_gro_offset(skb)); |
3245 | mac_len = skb->network_header - skb->mac_header; | 3248 | mac_len = skb->network_header - skb->mac_header; |
3246 | skb->mac_len = mac_len; | 3249 | skb->mac_len = mac_len; |
3247 | NAPI_GRO_CB(skb)->same_flow = 0; | 3250 | NAPI_GRO_CB(skb)->same_flow = 0; |
3248 | NAPI_GRO_CB(skb)->flush = 0; | 3251 | NAPI_GRO_CB(skb)->flush = 0; |
3249 | NAPI_GRO_CB(skb)->free = 0; | 3252 | NAPI_GRO_CB(skb)->free = 0; |
3250 | 3253 | ||
3251 | pp = ptype->gro_receive(&napi->gro_list, skb); | 3254 | pp = ptype->gro_receive(&napi->gro_list, skb); |
3252 | break; | 3255 | break; |
3253 | } | 3256 | } |
3254 | rcu_read_unlock(); | 3257 | rcu_read_unlock(); |
3255 | 3258 | ||
3256 | if (&ptype->list == head) | 3259 | if (&ptype->list == head) |
3257 | goto normal; | 3260 | goto normal; |
3258 | 3261 | ||
3259 | same_flow = NAPI_GRO_CB(skb)->same_flow; | 3262 | same_flow = NAPI_GRO_CB(skb)->same_flow; |
3260 | ret = NAPI_GRO_CB(skb)->free ? GRO_MERGED_FREE : GRO_MERGED; | 3263 | ret = NAPI_GRO_CB(skb)->free ? GRO_MERGED_FREE : GRO_MERGED; |
3261 | 3264 | ||
3262 | if (pp) { | 3265 | if (pp) { |
3263 | struct sk_buff *nskb = *pp; | 3266 | struct sk_buff *nskb = *pp; |
3264 | 3267 | ||
3265 | *pp = nskb->next; | 3268 | *pp = nskb->next; |
3266 | nskb->next = NULL; | 3269 | nskb->next = NULL; |
3267 | napi_gro_complete(nskb); | 3270 | napi_gro_complete(nskb); |
3268 | napi->gro_count--; | 3271 | napi->gro_count--; |
3269 | } | 3272 | } |
3270 | 3273 | ||
3271 | if (same_flow) | 3274 | if (same_flow) |
3272 | goto ok; | 3275 | goto ok; |
3273 | 3276 | ||
3274 | if (NAPI_GRO_CB(skb)->flush || napi->gro_count >= MAX_GRO_SKBS) | 3277 | if (NAPI_GRO_CB(skb)->flush || napi->gro_count >= MAX_GRO_SKBS) |
3275 | goto normal; | 3278 | goto normal; |
3276 | 3279 | ||
3277 | napi->gro_count++; | 3280 | napi->gro_count++; |
3278 | NAPI_GRO_CB(skb)->count = 1; | 3281 | NAPI_GRO_CB(skb)->count = 1; |
3279 | skb_shinfo(skb)->gso_size = skb_gro_len(skb); | 3282 | skb_shinfo(skb)->gso_size = skb_gro_len(skb); |
3280 | skb->next = napi->gro_list; | 3283 | skb->next = napi->gro_list; |
3281 | napi->gro_list = skb; | 3284 | napi->gro_list = skb; |
3282 | ret = GRO_HELD; | 3285 | ret = GRO_HELD; |
3283 | 3286 | ||
3284 | pull: | 3287 | pull: |
3285 | if (skb_headlen(skb) < skb_gro_offset(skb)) { | 3288 | if (skb_headlen(skb) < skb_gro_offset(skb)) { |
3286 | int grow = skb_gro_offset(skb) - skb_headlen(skb); | 3289 | int grow = skb_gro_offset(skb) - skb_headlen(skb); |
3287 | 3290 | ||
3288 | BUG_ON(skb->end - skb->tail < grow); | 3291 | BUG_ON(skb->end - skb->tail < grow); |
3289 | 3292 | ||
3290 | memcpy(skb_tail_pointer(skb), NAPI_GRO_CB(skb)->frag0, grow); | 3293 | memcpy(skb_tail_pointer(skb), NAPI_GRO_CB(skb)->frag0, grow); |
3291 | 3294 | ||
3292 | skb->tail += grow; | 3295 | skb->tail += grow; |
3293 | skb->data_len -= grow; | 3296 | skb->data_len -= grow; |
3294 | 3297 | ||
3295 | skb_shinfo(skb)->frags[0].page_offset += grow; | 3298 | skb_shinfo(skb)->frags[0].page_offset += grow; |
3296 | skb_shinfo(skb)->frags[0].size -= grow; | 3299 | skb_shinfo(skb)->frags[0].size -= grow; |
3297 | 3300 | ||
3298 | if (unlikely(!skb_shinfo(skb)->frags[0].size)) { | 3301 | if (unlikely(!skb_shinfo(skb)->frags[0].size)) { |
3299 | put_page(skb_shinfo(skb)->frags[0].page); | 3302 | put_page(skb_shinfo(skb)->frags[0].page); |
3300 | memmove(skb_shinfo(skb)->frags, | 3303 | memmove(skb_shinfo(skb)->frags, |
3301 | skb_shinfo(skb)->frags + 1, | 3304 | skb_shinfo(skb)->frags + 1, |
3302 | --skb_shinfo(skb)->nr_frags * sizeof(skb_frag_t)); | 3305 | --skb_shinfo(skb)->nr_frags * sizeof(skb_frag_t)); |
3303 | } | 3306 | } |
3304 | } | 3307 | } |
3305 | 3308 | ||
3306 | ok: | 3309 | ok: |
3307 | return ret; | 3310 | return ret; |
3308 | 3311 | ||
3309 | normal: | 3312 | normal: |
3310 | ret = GRO_NORMAL; | 3313 | ret = GRO_NORMAL; |
3311 | goto pull; | 3314 | goto pull; |
3312 | } | 3315 | } |
3313 | EXPORT_SYMBOL(dev_gro_receive); | 3316 | EXPORT_SYMBOL(dev_gro_receive); |
3314 | 3317 | ||
3315 | static inline gro_result_t | 3318 | static inline gro_result_t |
3316 | __napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb) | 3319 | __napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb) |
3317 | { | 3320 | { |
3318 | struct sk_buff *p; | 3321 | struct sk_buff *p; |
3319 | 3322 | ||
3320 | for (p = napi->gro_list; p; p = p->next) { | 3323 | for (p = napi->gro_list; p; p = p->next) { |
3321 | unsigned long diffs; | 3324 | unsigned long diffs; |
3322 | 3325 | ||
3323 | diffs = (unsigned long)p->dev ^ (unsigned long)skb->dev; | 3326 | diffs = (unsigned long)p->dev ^ (unsigned long)skb->dev; |
3324 | diffs |= p->vlan_tci ^ skb->vlan_tci; | 3327 | diffs |= p->vlan_tci ^ skb->vlan_tci; |
3325 | diffs |= compare_ether_header(skb_mac_header(p), | 3328 | diffs |= compare_ether_header(skb_mac_header(p), |
3326 | skb_gro_mac_header(skb)); | 3329 | skb_gro_mac_header(skb)); |
3327 | NAPI_GRO_CB(p)->same_flow = !diffs; | 3330 | NAPI_GRO_CB(p)->same_flow = !diffs; |
3328 | NAPI_GRO_CB(p)->flush = 0; | 3331 | NAPI_GRO_CB(p)->flush = 0; |
3329 | } | 3332 | } |
3330 | 3333 | ||
3331 | return dev_gro_receive(napi, skb); | 3334 | return dev_gro_receive(napi, skb); |
3332 | } | 3335 | } |
3333 | 3336 | ||
3334 | gro_result_t napi_skb_finish(gro_result_t ret, struct sk_buff *skb) | 3337 | gro_result_t napi_skb_finish(gro_result_t ret, struct sk_buff *skb) |
3335 | { | 3338 | { |
3336 | switch (ret) { | 3339 | switch (ret) { |
3337 | case GRO_NORMAL: | 3340 | case GRO_NORMAL: |
3338 | if (netif_receive_skb(skb)) | 3341 | if (netif_receive_skb(skb)) |
3339 | ret = GRO_DROP; | 3342 | ret = GRO_DROP; |
3340 | break; | 3343 | break; |
3341 | 3344 | ||
3342 | case GRO_DROP: | 3345 | case GRO_DROP: |
3343 | case GRO_MERGED_FREE: | 3346 | case GRO_MERGED_FREE: |
3344 | kfree_skb(skb); | 3347 | kfree_skb(skb); |
3345 | break; | 3348 | break; |
3346 | 3349 | ||
3347 | case GRO_HELD: | 3350 | case GRO_HELD: |
3348 | case GRO_MERGED: | 3351 | case GRO_MERGED: |
3349 | break; | 3352 | break; |
3350 | } | 3353 | } |
3351 | 3354 | ||
3352 | return ret; | 3355 | return ret; |
3353 | } | 3356 | } |
3354 | EXPORT_SYMBOL(napi_skb_finish); | 3357 | EXPORT_SYMBOL(napi_skb_finish); |
3355 | 3358 | ||
3356 | void skb_gro_reset_offset(struct sk_buff *skb) | 3359 | void skb_gro_reset_offset(struct sk_buff *skb) |
3357 | { | 3360 | { |
3358 | NAPI_GRO_CB(skb)->data_offset = 0; | 3361 | NAPI_GRO_CB(skb)->data_offset = 0; |
3359 | NAPI_GRO_CB(skb)->frag0 = NULL; | 3362 | NAPI_GRO_CB(skb)->frag0 = NULL; |
3360 | NAPI_GRO_CB(skb)->frag0_len = 0; | 3363 | NAPI_GRO_CB(skb)->frag0_len = 0; |
3361 | 3364 | ||
3362 | if (skb->mac_header == skb->tail && | 3365 | if (skb->mac_header == skb->tail && |
3363 | !PageHighMem(skb_shinfo(skb)->frags[0].page)) { | 3366 | !PageHighMem(skb_shinfo(skb)->frags[0].page)) { |
3364 | NAPI_GRO_CB(skb)->frag0 = | 3367 | NAPI_GRO_CB(skb)->frag0 = |
3365 | page_address(skb_shinfo(skb)->frags[0].page) + | 3368 | page_address(skb_shinfo(skb)->frags[0].page) + |
3366 | skb_shinfo(skb)->frags[0].page_offset; | 3369 | skb_shinfo(skb)->frags[0].page_offset; |
3367 | NAPI_GRO_CB(skb)->frag0_len = skb_shinfo(skb)->frags[0].size; | 3370 | NAPI_GRO_CB(skb)->frag0_len = skb_shinfo(skb)->frags[0].size; |
3368 | } | 3371 | } |
3369 | } | 3372 | } |
3370 | EXPORT_SYMBOL(skb_gro_reset_offset); | 3373 | EXPORT_SYMBOL(skb_gro_reset_offset); |
3371 | 3374 | ||
3372 | gro_result_t napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb) | 3375 | gro_result_t napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb) |
3373 | { | 3376 | { |
3374 | skb_gro_reset_offset(skb); | 3377 | skb_gro_reset_offset(skb); |
3375 | 3378 | ||
3376 | return napi_skb_finish(__napi_gro_receive(napi, skb), skb); | 3379 | return napi_skb_finish(__napi_gro_receive(napi, skb), skb); |
3377 | } | 3380 | } |
3378 | EXPORT_SYMBOL(napi_gro_receive); | 3381 | EXPORT_SYMBOL(napi_gro_receive); |
3379 | 3382 | ||
3380 | static void napi_reuse_skb(struct napi_struct *napi, struct sk_buff *skb) | 3383 | static void napi_reuse_skb(struct napi_struct *napi, struct sk_buff *skb) |
3381 | { | 3384 | { |
3382 | __skb_pull(skb, skb_headlen(skb)); | 3385 | __skb_pull(skb, skb_headlen(skb)); |
3383 | skb_reserve(skb, NET_IP_ALIGN - skb_headroom(skb)); | 3386 | skb_reserve(skb, NET_IP_ALIGN - skb_headroom(skb)); |
3384 | skb->vlan_tci = 0; | 3387 | skb->vlan_tci = 0; |
3385 | 3388 | ||
3386 | napi->skb = skb; | 3389 | napi->skb = skb; |
3387 | } | 3390 | } |
3388 | 3391 | ||
3389 | struct sk_buff *napi_get_frags(struct napi_struct *napi) | 3392 | struct sk_buff *napi_get_frags(struct napi_struct *napi) |
3390 | { | 3393 | { |
3391 | struct sk_buff *skb = napi->skb; | 3394 | struct sk_buff *skb = napi->skb; |
3392 | 3395 | ||
3393 | if (!skb) { | 3396 | if (!skb) { |
3394 | skb = netdev_alloc_skb_ip_align(napi->dev, GRO_MAX_HEAD); | 3397 | skb = netdev_alloc_skb_ip_align(napi->dev, GRO_MAX_HEAD); |
3395 | if (skb) | 3398 | if (skb) |
3396 | napi->skb = skb; | 3399 | napi->skb = skb; |
3397 | } | 3400 | } |
3398 | return skb; | 3401 | return skb; |
3399 | } | 3402 | } |
3400 | EXPORT_SYMBOL(napi_get_frags); | 3403 | EXPORT_SYMBOL(napi_get_frags); |
3401 | 3404 | ||
3402 | gro_result_t napi_frags_finish(struct napi_struct *napi, struct sk_buff *skb, | 3405 | gro_result_t napi_frags_finish(struct napi_struct *napi, struct sk_buff *skb, |
3403 | gro_result_t ret) | 3406 | gro_result_t ret) |
3404 | { | 3407 | { |
3405 | switch (ret) { | 3408 | switch (ret) { |
3406 | case GRO_NORMAL: | 3409 | case GRO_NORMAL: |
3407 | case GRO_HELD: | 3410 | case GRO_HELD: |
3408 | skb->protocol = eth_type_trans(skb, skb->dev); | 3411 | skb->protocol = eth_type_trans(skb, skb->dev); |
3409 | 3412 | ||
3410 | if (ret == GRO_HELD) | 3413 | if (ret == GRO_HELD) |
3411 | skb_gro_pull(skb, -ETH_HLEN); | 3414 | skb_gro_pull(skb, -ETH_HLEN); |
3412 | else if (netif_receive_skb(skb)) | 3415 | else if (netif_receive_skb(skb)) |
3413 | ret = GRO_DROP; | 3416 | ret = GRO_DROP; |
3414 | break; | 3417 | break; |
3415 | 3418 | ||
3416 | case GRO_DROP: | 3419 | case GRO_DROP: |
3417 | case GRO_MERGED_FREE: | 3420 | case GRO_MERGED_FREE: |
3418 | napi_reuse_skb(napi, skb); | 3421 | napi_reuse_skb(napi, skb); |
3419 | break; | 3422 | break; |
3420 | 3423 | ||
3421 | case GRO_MERGED: | 3424 | case GRO_MERGED: |
3422 | break; | 3425 | break; |
3423 | } | 3426 | } |
3424 | 3427 | ||
3425 | return ret; | 3428 | return ret; |
3426 | } | 3429 | } |
3427 | EXPORT_SYMBOL(napi_frags_finish); | 3430 | EXPORT_SYMBOL(napi_frags_finish); |
3428 | 3431 | ||
3429 | struct sk_buff *napi_frags_skb(struct napi_struct *napi) | 3432 | struct sk_buff *napi_frags_skb(struct napi_struct *napi) |
3430 | { | 3433 | { |
3431 | struct sk_buff *skb = napi->skb; | 3434 | struct sk_buff *skb = napi->skb; |
3432 | struct ethhdr *eth; | 3435 | struct ethhdr *eth; |
3433 | unsigned int hlen; | 3436 | unsigned int hlen; |
3434 | unsigned int off; | 3437 | unsigned int off; |
3435 | 3438 | ||
3436 | napi->skb = NULL; | 3439 | napi->skb = NULL; |
3437 | 3440 | ||
3438 | skb_reset_mac_header(skb); | 3441 | skb_reset_mac_header(skb); |
3439 | skb_gro_reset_offset(skb); | 3442 | skb_gro_reset_offset(skb); |
3440 | 3443 | ||
3441 | off = skb_gro_offset(skb); | 3444 | off = skb_gro_offset(skb); |
3442 | hlen = off + sizeof(*eth); | 3445 | hlen = off + sizeof(*eth); |
3443 | eth = skb_gro_header_fast(skb, off); | 3446 | eth = skb_gro_header_fast(skb, off); |
3444 | if (skb_gro_header_hard(skb, hlen)) { | 3447 | if (skb_gro_header_hard(skb, hlen)) { |
3445 | eth = skb_gro_header_slow(skb, hlen, off); | 3448 | eth = skb_gro_header_slow(skb, hlen, off); |
3446 | if (unlikely(!eth)) { | 3449 | if (unlikely(!eth)) { |
3447 | napi_reuse_skb(napi, skb); | 3450 | napi_reuse_skb(napi, skb); |
3448 | skb = NULL; | 3451 | skb = NULL; |
3449 | goto out; | 3452 | goto out; |
3450 | } | 3453 | } |
3451 | } | 3454 | } |
3452 | 3455 | ||
3453 | skb_gro_pull(skb, sizeof(*eth)); | 3456 | skb_gro_pull(skb, sizeof(*eth)); |
3454 | 3457 | ||
3455 | /* | 3458 | /* |
3456 | * This works because the only protocols we care about don't require | 3459 | * This works because the only protocols we care about don't require |
3457 | * special handling. We'll fix it up properly at the end. | 3460 | * special handling. We'll fix it up properly at the end. |
3458 | */ | 3461 | */ |
3459 | skb->protocol = eth->h_proto; | 3462 | skb->protocol = eth->h_proto; |
3460 | 3463 | ||
3461 | out: | 3464 | out: |
3462 | return skb; | 3465 | return skb; |
3463 | } | 3466 | } |
3464 | EXPORT_SYMBOL(napi_frags_skb); | 3467 | EXPORT_SYMBOL(napi_frags_skb); |
3465 | 3468 | ||
3466 | gro_result_t napi_gro_frags(struct napi_struct *napi) | 3469 | gro_result_t napi_gro_frags(struct napi_struct *napi) |
3467 | { | 3470 | { |
3468 | struct sk_buff *skb = napi_frags_skb(napi); | 3471 | struct sk_buff *skb = napi_frags_skb(napi); |
3469 | 3472 | ||
3470 | if (!skb) | 3473 | if (!skb) |
3471 | return GRO_DROP; | 3474 | return GRO_DROP; |
3472 | 3475 | ||
3473 | return napi_frags_finish(napi, skb, __napi_gro_receive(napi, skb)); | 3476 | return napi_frags_finish(napi, skb, __napi_gro_receive(napi, skb)); |
3474 | } | 3477 | } |
3475 | EXPORT_SYMBOL(napi_gro_frags); | 3478 | EXPORT_SYMBOL(napi_gro_frags); |
3476 | 3479 | ||
3477 | /* | 3480 | /* |
3478 | * net_rps_action sends any pending IPI's for rps. | 3481 | * net_rps_action sends any pending IPI's for rps. |
3479 | * Note: called with local irq disabled, but exits with local irq enabled. | 3482 | * Note: called with local irq disabled, but exits with local irq enabled. |
3480 | */ | 3483 | */ |
3481 | static void net_rps_action_and_irq_enable(struct softnet_data *sd) | 3484 | static void net_rps_action_and_irq_enable(struct softnet_data *sd) |
3482 | { | 3485 | { |
3483 | #ifdef CONFIG_RPS | 3486 | #ifdef CONFIG_RPS |
3484 | struct softnet_data *remsd = sd->rps_ipi_list; | 3487 | struct softnet_data *remsd = sd->rps_ipi_list; |
3485 | 3488 | ||
3486 | if (remsd) { | 3489 | if (remsd) { |
3487 | sd->rps_ipi_list = NULL; | 3490 | sd->rps_ipi_list = NULL; |
3488 | 3491 | ||
3489 | local_irq_enable(); | 3492 | local_irq_enable(); |
3490 | 3493 | ||
3491 | /* Send pending IPI's to kick RPS processing on remote cpus. */ | 3494 | /* Send pending IPI's to kick RPS processing on remote cpus. */ |
3492 | while (remsd) { | 3495 | while (remsd) { |
3493 | struct softnet_data *next = remsd->rps_ipi_next; | 3496 | struct softnet_data *next = remsd->rps_ipi_next; |
3494 | 3497 | ||
3495 | if (cpu_online(remsd->cpu)) | 3498 | if (cpu_online(remsd->cpu)) |
3496 | __smp_call_function_single(remsd->cpu, | 3499 | __smp_call_function_single(remsd->cpu, |
3497 | &remsd->csd, 0); | 3500 | &remsd->csd, 0); |
3498 | remsd = next; | 3501 | remsd = next; |
3499 | } | 3502 | } |
3500 | } else | 3503 | } else |
3501 | #endif | 3504 | #endif |
3502 | local_irq_enable(); | 3505 | local_irq_enable(); |
3503 | } | 3506 | } |
3504 | 3507 | ||
3505 | static int process_backlog(struct napi_struct *napi, int quota) | 3508 | static int process_backlog(struct napi_struct *napi, int quota) |
3506 | { | 3509 | { |
3507 | int work = 0; | 3510 | int work = 0; |
3508 | struct softnet_data *sd = container_of(napi, struct softnet_data, backlog); | 3511 | struct softnet_data *sd = container_of(napi, struct softnet_data, backlog); |
3509 | 3512 | ||
3510 | #ifdef CONFIG_RPS | 3513 | #ifdef CONFIG_RPS |
3511 | /* Check if we have pending ipi, its better to send them now, | 3514 | /* Check if we have pending ipi, its better to send them now, |
3512 | * not waiting net_rx_action() end. | 3515 | * not waiting net_rx_action() end. |
3513 | */ | 3516 | */ |
3514 | if (sd->rps_ipi_list) { | 3517 | if (sd->rps_ipi_list) { |
3515 | local_irq_disable(); | 3518 | local_irq_disable(); |
3516 | net_rps_action_and_irq_enable(sd); | 3519 | net_rps_action_and_irq_enable(sd); |
3517 | } | 3520 | } |
3518 | #endif | 3521 | #endif |
3519 | napi->weight = weight_p; | 3522 | napi->weight = weight_p; |
3520 | local_irq_disable(); | 3523 | local_irq_disable(); |
3521 | while (work < quota) { | 3524 | while (work < quota) { |
3522 | struct sk_buff *skb; | 3525 | struct sk_buff *skb; |
3523 | unsigned int qlen; | 3526 | unsigned int qlen; |
3524 | 3527 | ||
3525 | while ((skb = __skb_dequeue(&sd->process_queue))) { | 3528 | while ((skb = __skb_dequeue(&sd->process_queue))) { |
3526 | local_irq_enable(); | 3529 | local_irq_enable(); |
3527 | __netif_receive_skb(skb); | 3530 | __netif_receive_skb(skb); |
3528 | local_irq_disable(); | 3531 | local_irq_disable(); |
3529 | input_queue_head_incr(sd); | 3532 | input_queue_head_incr(sd); |
3530 | if (++work >= quota) { | 3533 | if (++work >= quota) { |
3531 | local_irq_enable(); | 3534 | local_irq_enable(); |
3532 | return work; | 3535 | return work; |
3533 | } | 3536 | } |
3534 | } | 3537 | } |
3535 | 3538 | ||
3536 | rps_lock(sd); | 3539 | rps_lock(sd); |
3537 | qlen = skb_queue_len(&sd->input_pkt_queue); | 3540 | qlen = skb_queue_len(&sd->input_pkt_queue); |
3538 | if (qlen) | 3541 | if (qlen) |
3539 | skb_queue_splice_tail_init(&sd->input_pkt_queue, | 3542 | skb_queue_splice_tail_init(&sd->input_pkt_queue, |
3540 | &sd->process_queue); | 3543 | &sd->process_queue); |
3541 | 3544 | ||
3542 | if (qlen < quota - work) { | 3545 | if (qlen < quota - work) { |
3543 | /* | 3546 | /* |
3544 | * Inline a custom version of __napi_complete(). | 3547 | * Inline a custom version of __napi_complete(). |
3545 | * only current cpu owns and manipulates this napi, | 3548 | * only current cpu owns and manipulates this napi, |
3546 | * and NAPI_STATE_SCHED is the only possible flag set on backlog. | 3549 | * and NAPI_STATE_SCHED is the only possible flag set on backlog. |
3547 | * we can use a plain write instead of clear_bit(), | 3550 | * we can use a plain write instead of clear_bit(), |
3548 | * and we dont need an smp_mb() memory barrier. | 3551 | * and we dont need an smp_mb() memory barrier. |
3549 | */ | 3552 | */ |
3550 | list_del(&napi->poll_list); | 3553 | list_del(&napi->poll_list); |
3551 | napi->state = 0; | 3554 | napi->state = 0; |
3552 | 3555 | ||
3553 | quota = work + qlen; | 3556 | quota = work + qlen; |
3554 | } | 3557 | } |
3555 | rps_unlock(sd); | 3558 | rps_unlock(sd); |
3556 | } | 3559 | } |
3557 | local_irq_enable(); | 3560 | local_irq_enable(); |
3558 | 3561 | ||
3559 | return work; | 3562 | return work; |
3560 | } | 3563 | } |
3561 | 3564 | ||
3562 | /** | 3565 | /** |
3563 | * __napi_schedule - schedule for receive | 3566 | * __napi_schedule - schedule for receive |
3564 | * @n: entry to schedule | 3567 | * @n: entry to schedule |
3565 | * | 3568 | * |
3566 | * The entry's receive function will be scheduled to run | 3569 | * The entry's receive function will be scheduled to run |
3567 | */ | 3570 | */ |
3568 | void __napi_schedule(struct napi_struct *n) | 3571 | void __napi_schedule(struct napi_struct *n) |
3569 | { | 3572 | { |
3570 | unsigned long flags; | 3573 | unsigned long flags; |
3571 | 3574 | ||
3572 | local_irq_save(flags); | 3575 | local_irq_save(flags); |
3573 | ____napi_schedule(&__get_cpu_var(softnet_data), n); | 3576 | ____napi_schedule(&__get_cpu_var(softnet_data), n); |
3574 | local_irq_restore(flags); | 3577 | local_irq_restore(flags); |
3575 | } | 3578 | } |
3576 | EXPORT_SYMBOL(__napi_schedule); | 3579 | EXPORT_SYMBOL(__napi_schedule); |
3577 | 3580 | ||
3578 | void __napi_complete(struct napi_struct *n) | 3581 | void __napi_complete(struct napi_struct *n) |
3579 | { | 3582 | { |
3580 | BUG_ON(!test_bit(NAPI_STATE_SCHED, &n->state)); | 3583 | BUG_ON(!test_bit(NAPI_STATE_SCHED, &n->state)); |
3581 | BUG_ON(n->gro_list); | 3584 | BUG_ON(n->gro_list); |
3582 | 3585 | ||
3583 | list_del(&n->poll_list); | 3586 | list_del(&n->poll_list); |
3584 | smp_mb__before_clear_bit(); | 3587 | smp_mb__before_clear_bit(); |
3585 | clear_bit(NAPI_STATE_SCHED, &n->state); | 3588 | clear_bit(NAPI_STATE_SCHED, &n->state); |
3586 | } | 3589 | } |
3587 | EXPORT_SYMBOL(__napi_complete); | 3590 | EXPORT_SYMBOL(__napi_complete); |
3588 | 3591 | ||
3589 | void napi_complete(struct napi_struct *n) | 3592 | void napi_complete(struct napi_struct *n) |
3590 | { | 3593 | { |
3591 | unsigned long flags; | 3594 | unsigned long flags; |
3592 | 3595 | ||
3593 | /* | 3596 | /* |
3594 | * don't let napi dequeue from the cpu poll list | 3597 | * don't let napi dequeue from the cpu poll list |
3595 | * just in case its running on a different cpu | 3598 | * just in case its running on a different cpu |
3596 | */ | 3599 | */ |
3597 | if (unlikely(test_bit(NAPI_STATE_NPSVC, &n->state))) | 3600 | if (unlikely(test_bit(NAPI_STATE_NPSVC, &n->state))) |
3598 | return; | 3601 | return; |
3599 | 3602 | ||
3600 | napi_gro_flush(n); | 3603 | napi_gro_flush(n); |
3601 | local_irq_save(flags); | 3604 | local_irq_save(flags); |
3602 | __napi_complete(n); | 3605 | __napi_complete(n); |
3603 | local_irq_restore(flags); | 3606 | local_irq_restore(flags); |
3604 | } | 3607 | } |
3605 | EXPORT_SYMBOL(napi_complete); | 3608 | EXPORT_SYMBOL(napi_complete); |
3606 | 3609 | ||
3607 | void netif_napi_add(struct net_device *dev, struct napi_struct *napi, | 3610 | void netif_napi_add(struct net_device *dev, struct napi_struct *napi, |
3608 | int (*poll)(struct napi_struct *, int), int weight) | 3611 | int (*poll)(struct napi_struct *, int), int weight) |
3609 | { | 3612 | { |
3610 | INIT_LIST_HEAD(&napi->poll_list); | 3613 | INIT_LIST_HEAD(&napi->poll_list); |
3611 | napi->gro_count = 0; | 3614 | napi->gro_count = 0; |
3612 | napi->gro_list = NULL; | 3615 | napi->gro_list = NULL; |
3613 | napi->skb = NULL; | 3616 | napi->skb = NULL; |
3614 | napi->poll = poll; | 3617 | napi->poll = poll; |
3615 | napi->weight = weight; | 3618 | napi->weight = weight; |
3616 | list_add(&napi->dev_list, &dev->napi_list); | 3619 | list_add(&napi->dev_list, &dev->napi_list); |
3617 | napi->dev = dev; | 3620 | napi->dev = dev; |
3618 | #ifdef CONFIG_NETPOLL | 3621 | #ifdef CONFIG_NETPOLL |
3619 | spin_lock_init(&napi->poll_lock); | 3622 | spin_lock_init(&napi->poll_lock); |
3620 | napi->poll_owner = -1; | 3623 | napi->poll_owner = -1; |
3621 | #endif | 3624 | #endif |
3622 | set_bit(NAPI_STATE_SCHED, &napi->state); | 3625 | set_bit(NAPI_STATE_SCHED, &napi->state); |
3623 | } | 3626 | } |
3624 | EXPORT_SYMBOL(netif_napi_add); | 3627 | EXPORT_SYMBOL(netif_napi_add); |
3625 | 3628 | ||
3626 | void netif_napi_del(struct napi_struct *napi) | 3629 | void netif_napi_del(struct napi_struct *napi) |
3627 | { | 3630 | { |
3628 | struct sk_buff *skb, *next; | 3631 | struct sk_buff *skb, *next; |
3629 | 3632 | ||
3630 | list_del_init(&napi->dev_list); | 3633 | list_del_init(&napi->dev_list); |
3631 | napi_free_frags(napi); | 3634 | napi_free_frags(napi); |
3632 | 3635 | ||
3633 | for (skb = napi->gro_list; skb; skb = next) { | 3636 | for (skb = napi->gro_list; skb; skb = next) { |
3634 | next = skb->next; | 3637 | next = skb->next; |
3635 | skb->next = NULL; | 3638 | skb->next = NULL; |
3636 | kfree_skb(skb); | 3639 | kfree_skb(skb); |
3637 | } | 3640 | } |
3638 | 3641 | ||
3639 | napi->gro_list = NULL; | 3642 | napi->gro_list = NULL; |
3640 | napi->gro_count = 0; | 3643 | napi->gro_count = 0; |
3641 | } | 3644 | } |
3642 | EXPORT_SYMBOL(netif_napi_del); | 3645 | EXPORT_SYMBOL(netif_napi_del); |
3643 | 3646 | ||
3644 | static void net_rx_action(struct softirq_action *h) | 3647 | static void net_rx_action(struct softirq_action *h) |
3645 | { | 3648 | { |
3646 | struct softnet_data *sd = &__get_cpu_var(softnet_data); | 3649 | struct softnet_data *sd = &__get_cpu_var(softnet_data); |
3647 | unsigned long time_limit = jiffies + 2; | 3650 | unsigned long time_limit = jiffies + 2; |
3648 | int budget = netdev_budget; | 3651 | int budget = netdev_budget; |
3649 | void *have; | 3652 | void *have; |
3650 | 3653 | ||
3651 | local_irq_disable(); | 3654 | local_irq_disable(); |
3652 | 3655 | ||
3653 | while (!list_empty(&sd->poll_list)) { | 3656 | while (!list_empty(&sd->poll_list)) { |
3654 | struct napi_struct *n; | 3657 | struct napi_struct *n; |
3655 | int work, weight; | 3658 | int work, weight; |
3656 | 3659 | ||
3657 | /* If softirq window is exhuasted then punt. | 3660 | /* If softirq window is exhuasted then punt. |
3658 | * Allow this to run for 2 jiffies since which will allow | 3661 | * Allow this to run for 2 jiffies since which will allow |
3659 | * an average latency of 1.5/HZ. | 3662 | * an average latency of 1.5/HZ. |
3660 | */ | 3663 | */ |
3661 | if (unlikely(budget <= 0 || time_after(jiffies, time_limit))) | 3664 | if (unlikely(budget <= 0 || time_after(jiffies, time_limit))) |
3662 | goto softnet_break; | 3665 | goto softnet_break; |
3663 | 3666 | ||
3664 | local_irq_enable(); | 3667 | local_irq_enable(); |
3665 | 3668 | ||
3666 | /* Even though interrupts have been re-enabled, this | 3669 | /* Even though interrupts have been re-enabled, this |
3667 | * access is safe because interrupts can only add new | 3670 | * access is safe because interrupts can only add new |
3668 | * entries to the tail of this list, and only ->poll() | 3671 | * entries to the tail of this list, and only ->poll() |
3669 | * calls can remove this head entry from the list. | 3672 | * calls can remove this head entry from the list. |
3670 | */ | 3673 | */ |
3671 | n = list_first_entry(&sd->poll_list, struct napi_struct, poll_list); | 3674 | n = list_first_entry(&sd->poll_list, struct napi_struct, poll_list); |
3672 | 3675 | ||
3673 | have = netpoll_poll_lock(n); | 3676 | have = netpoll_poll_lock(n); |
3674 | 3677 | ||
3675 | weight = n->weight; | 3678 | weight = n->weight; |
3676 | 3679 | ||
3677 | /* This NAPI_STATE_SCHED test is for avoiding a race | 3680 | /* This NAPI_STATE_SCHED test is for avoiding a race |
3678 | * with netpoll's poll_napi(). Only the entity which | 3681 | * with netpoll's poll_napi(). Only the entity which |
3679 | * obtains the lock and sees NAPI_STATE_SCHED set will | 3682 | * obtains the lock and sees NAPI_STATE_SCHED set will |
3680 | * actually make the ->poll() call. Therefore we avoid | 3683 | * actually make the ->poll() call. Therefore we avoid |
3681 | * accidently calling ->poll() when NAPI is not scheduled. | 3684 | * accidently calling ->poll() when NAPI is not scheduled. |
3682 | */ | 3685 | */ |
3683 | work = 0; | 3686 | work = 0; |
3684 | if (test_bit(NAPI_STATE_SCHED, &n->state)) { | 3687 | if (test_bit(NAPI_STATE_SCHED, &n->state)) { |
3685 | work = n->poll(n, weight); | 3688 | work = n->poll(n, weight); |
3686 | trace_napi_poll(n); | 3689 | trace_napi_poll(n); |
3687 | } | 3690 | } |
3688 | 3691 | ||
3689 | WARN_ON_ONCE(work > weight); | 3692 | WARN_ON_ONCE(work > weight); |
3690 | 3693 | ||
3691 | budget -= work; | 3694 | budget -= work; |
3692 | 3695 | ||
3693 | local_irq_disable(); | 3696 | local_irq_disable(); |
3694 | 3697 | ||
3695 | /* Drivers must not modify the NAPI state if they | 3698 | /* Drivers must not modify the NAPI state if they |
3696 | * consume the entire weight. In such cases this code | 3699 | * consume the entire weight. In such cases this code |
3697 | * still "owns" the NAPI instance and therefore can | 3700 | * still "owns" the NAPI instance and therefore can |
3698 | * move the instance around on the list at-will. | 3701 | * move the instance around on the list at-will. |
3699 | */ | 3702 | */ |
3700 | if (unlikely(work == weight)) { | 3703 | if (unlikely(work == weight)) { |
3701 | if (unlikely(napi_disable_pending(n))) { | 3704 | if (unlikely(napi_disable_pending(n))) { |
3702 | local_irq_enable(); | 3705 | local_irq_enable(); |
3703 | napi_complete(n); | 3706 | napi_complete(n); |
3704 | local_irq_disable(); | 3707 | local_irq_disable(); |
3705 | } else | 3708 | } else |
3706 | list_move_tail(&n->poll_list, &sd->poll_list); | 3709 | list_move_tail(&n->poll_list, &sd->poll_list); |
3707 | } | 3710 | } |
3708 | 3711 | ||
3709 | netpoll_poll_unlock(have); | 3712 | netpoll_poll_unlock(have); |
3710 | } | 3713 | } |
3711 | out: | 3714 | out: |
3712 | net_rps_action_and_irq_enable(sd); | 3715 | net_rps_action_and_irq_enable(sd); |
3713 | 3716 | ||
3714 | #ifdef CONFIG_NET_DMA | 3717 | #ifdef CONFIG_NET_DMA |
3715 | /* | 3718 | /* |
3716 | * There may not be any more sk_buffs coming right now, so push | 3719 | * There may not be any more sk_buffs coming right now, so push |
3717 | * any pending DMA copies to hardware | 3720 | * any pending DMA copies to hardware |
3718 | */ | 3721 | */ |
3719 | dma_issue_pending_all(); | 3722 | dma_issue_pending_all(); |
3720 | #endif | 3723 | #endif |
3721 | 3724 | ||
3722 | return; | 3725 | return; |
3723 | 3726 | ||
3724 | softnet_break: | 3727 | softnet_break: |
3725 | sd->time_squeeze++; | 3728 | sd->time_squeeze++; |
3726 | __raise_softirq_irqoff(NET_RX_SOFTIRQ); | 3729 | __raise_softirq_irqoff(NET_RX_SOFTIRQ); |
3727 | goto out; | 3730 | goto out; |
3728 | } | 3731 | } |
3729 | 3732 | ||
3730 | static gifconf_func_t *gifconf_list[NPROTO]; | 3733 | static gifconf_func_t *gifconf_list[NPROTO]; |
3731 | 3734 | ||
3732 | /** | 3735 | /** |
3733 | * register_gifconf - register a SIOCGIF handler | 3736 | * register_gifconf - register a SIOCGIF handler |
3734 | * @family: Address family | 3737 | * @family: Address family |
3735 | * @gifconf: Function handler | 3738 | * @gifconf: Function handler |
3736 | * | 3739 | * |
3737 | * Register protocol dependent address dumping routines. The handler | 3740 | * Register protocol dependent address dumping routines. The handler |
3738 | * that is passed must not be freed or reused until it has been replaced | 3741 | * that is passed must not be freed or reused until it has been replaced |
3739 | * by another handler. | 3742 | * by another handler. |
3740 | */ | 3743 | */ |
3741 | int register_gifconf(unsigned int family, gifconf_func_t *gifconf) | 3744 | int register_gifconf(unsigned int family, gifconf_func_t *gifconf) |
3742 | { | 3745 | { |
3743 | if (family >= NPROTO) | 3746 | if (family >= NPROTO) |
3744 | return -EINVAL; | 3747 | return -EINVAL; |
3745 | gifconf_list[family] = gifconf; | 3748 | gifconf_list[family] = gifconf; |
3746 | return 0; | 3749 | return 0; |
3747 | } | 3750 | } |
3748 | EXPORT_SYMBOL(register_gifconf); | 3751 | EXPORT_SYMBOL(register_gifconf); |
3749 | 3752 | ||
3750 | 3753 | ||
3751 | /* | 3754 | /* |
3752 | * Map an interface index to its name (SIOCGIFNAME) | 3755 | * Map an interface index to its name (SIOCGIFNAME) |
3753 | */ | 3756 | */ |
3754 | 3757 | ||
3755 | /* | 3758 | /* |
3756 | * We need this ioctl for efficient implementation of the | 3759 | * We need this ioctl for efficient implementation of the |
3757 | * if_indextoname() function required by the IPv6 API. Without | 3760 | * if_indextoname() function required by the IPv6 API. Without |
3758 | * it, we would have to search all the interfaces to find a | 3761 | * it, we would have to search all the interfaces to find a |
3759 | * match. --pb | 3762 | * match. --pb |
3760 | */ | 3763 | */ |
3761 | 3764 | ||
3762 | static int dev_ifname(struct net *net, struct ifreq __user *arg) | 3765 | static int dev_ifname(struct net *net, struct ifreq __user *arg) |
3763 | { | 3766 | { |
3764 | struct net_device *dev; | 3767 | struct net_device *dev; |
3765 | struct ifreq ifr; | 3768 | struct ifreq ifr; |
3766 | 3769 | ||
3767 | /* | 3770 | /* |
3768 | * Fetch the caller's info block. | 3771 | * Fetch the caller's info block. |
3769 | */ | 3772 | */ |
3770 | 3773 | ||
3771 | if (copy_from_user(&ifr, arg, sizeof(struct ifreq))) | 3774 | if (copy_from_user(&ifr, arg, sizeof(struct ifreq))) |
3772 | return -EFAULT; | 3775 | return -EFAULT; |
3773 | 3776 | ||
3774 | rcu_read_lock(); | 3777 | rcu_read_lock(); |
3775 | dev = dev_get_by_index_rcu(net, ifr.ifr_ifindex); | 3778 | dev = dev_get_by_index_rcu(net, ifr.ifr_ifindex); |
3776 | if (!dev) { | 3779 | if (!dev) { |
3777 | rcu_read_unlock(); | 3780 | rcu_read_unlock(); |
3778 | return -ENODEV; | 3781 | return -ENODEV; |
3779 | } | 3782 | } |
3780 | 3783 | ||
3781 | strcpy(ifr.ifr_name, dev->name); | 3784 | strcpy(ifr.ifr_name, dev->name); |
3782 | rcu_read_unlock(); | 3785 | rcu_read_unlock(); |
3783 | 3786 | ||
3784 | if (copy_to_user(arg, &ifr, sizeof(struct ifreq))) | 3787 | if (copy_to_user(arg, &ifr, sizeof(struct ifreq))) |
3785 | return -EFAULT; | 3788 | return -EFAULT; |
3786 | return 0; | 3789 | return 0; |
3787 | } | 3790 | } |
3788 | 3791 | ||
3789 | /* | 3792 | /* |
3790 | * Perform a SIOCGIFCONF call. This structure will change | 3793 | * Perform a SIOCGIFCONF call. This structure will change |
3791 | * size eventually, and there is nothing I can do about it. | 3794 | * size eventually, and there is nothing I can do about it. |
3792 | * Thus we will need a 'compatibility mode'. | 3795 | * Thus we will need a 'compatibility mode'. |
3793 | */ | 3796 | */ |
3794 | 3797 | ||
3795 | static int dev_ifconf(struct net *net, char __user *arg) | 3798 | static int dev_ifconf(struct net *net, char __user *arg) |
3796 | { | 3799 | { |
3797 | struct ifconf ifc; | 3800 | struct ifconf ifc; |
3798 | struct net_device *dev; | 3801 | struct net_device *dev; |
3799 | char __user *pos; | 3802 | char __user *pos; |
3800 | int len; | 3803 | int len; |
3801 | int total; | 3804 | int total; |
3802 | int i; | 3805 | int i; |
3803 | 3806 | ||
3804 | /* | 3807 | /* |
3805 | * Fetch the caller's info block. | 3808 | * Fetch the caller's info block. |
3806 | */ | 3809 | */ |
3807 | 3810 | ||
3808 | if (copy_from_user(&ifc, arg, sizeof(struct ifconf))) | 3811 | if (copy_from_user(&ifc, arg, sizeof(struct ifconf))) |
3809 | return -EFAULT; | 3812 | return -EFAULT; |
3810 | 3813 | ||
3811 | pos = ifc.ifc_buf; | 3814 | pos = ifc.ifc_buf; |
3812 | len = ifc.ifc_len; | 3815 | len = ifc.ifc_len; |
3813 | 3816 | ||
3814 | /* | 3817 | /* |
3815 | * Loop over the interfaces, and write an info block for each. | 3818 | * Loop over the interfaces, and write an info block for each. |
3816 | */ | 3819 | */ |
3817 | 3820 | ||
3818 | total = 0; | 3821 | total = 0; |
3819 | for_each_netdev(net, dev) { | 3822 | for_each_netdev(net, dev) { |
3820 | for (i = 0; i < NPROTO; i++) { | 3823 | for (i = 0; i < NPROTO; i++) { |
3821 | if (gifconf_list[i]) { | 3824 | if (gifconf_list[i]) { |
3822 | int done; | 3825 | int done; |
3823 | if (!pos) | 3826 | if (!pos) |
3824 | done = gifconf_list[i](dev, NULL, 0); | 3827 | done = gifconf_list[i](dev, NULL, 0); |
3825 | else | 3828 | else |
3826 | done = gifconf_list[i](dev, pos + total, | 3829 | done = gifconf_list[i](dev, pos + total, |
3827 | len - total); | 3830 | len - total); |
3828 | if (done < 0) | 3831 | if (done < 0) |
3829 | return -EFAULT; | 3832 | return -EFAULT; |
3830 | total += done; | 3833 | total += done; |
3831 | } | 3834 | } |
3832 | } | 3835 | } |
3833 | } | 3836 | } |
3834 | 3837 | ||
3835 | /* | 3838 | /* |
3836 | * All done. Write the updated control block back to the caller. | 3839 | * All done. Write the updated control block back to the caller. |
3837 | */ | 3840 | */ |
3838 | ifc.ifc_len = total; | 3841 | ifc.ifc_len = total; |
3839 | 3842 | ||
3840 | /* | 3843 | /* |
3841 | * Both BSD and Solaris return 0 here, so we do too. | 3844 | * Both BSD and Solaris return 0 here, so we do too. |
3842 | */ | 3845 | */ |
3843 | return copy_to_user(arg, &ifc, sizeof(struct ifconf)) ? -EFAULT : 0; | 3846 | return copy_to_user(arg, &ifc, sizeof(struct ifconf)) ? -EFAULT : 0; |
3844 | } | 3847 | } |
3845 | 3848 | ||
3846 | #ifdef CONFIG_PROC_FS | 3849 | #ifdef CONFIG_PROC_FS |
3847 | /* | 3850 | /* |
3848 | * This is invoked by the /proc filesystem handler to display a device | 3851 | * This is invoked by the /proc filesystem handler to display a device |
3849 | * in detail. | 3852 | * in detail. |
3850 | */ | 3853 | */ |
3851 | void *dev_seq_start(struct seq_file *seq, loff_t *pos) | 3854 | void *dev_seq_start(struct seq_file *seq, loff_t *pos) |
3852 | __acquires(RCU) | 3855 | __acquires(RCU) |
3853 | { | 3856 | { |
3854 | struct net *net = seq_file_net(seq); | 3857 | struct net *net = seq_file_net(seq); |
3855 | loff_t off; | 3858 | loff_t off; |
3856 | struct net_device *dev; | 3859 | struct net_device *dev; |
3857 | 3860 | ||
3858 | rcu_read_lock(); | 3861 | rcu_read_lock(); |
3859 | if (!*pos) | 3862 | if (!*pos) |
3860 | return SEQ_START_TOKEN; | 3863 | return SEQ_START_TOKEN; |
3861 | 3864 | ||
3862 | off = 1; | 3865 | off = 1; |
3863 | for_each_netdev_rcu(net, dev) | 3866 | for_each_netdev_rcu(net, dev) |
3864 | if (off++ == *pos) | 3867 | if (off++ == *pos) |
3865 | return dev; | 3868 | return dev; |
3866 | 3869 | ||
3867 | return NULL; | 3870 | return NULL; |
3868 | } | 3871 | } |
3869 | 3872 | ||
3870 | void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos) | 3873 | void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
3871 | { | 3874 | { |
3872 | struct net_device *dev = (v == SEQ_START_TOKEN) ? | 3875 | struct net_device *dev = (v == SEQ_START_TOKEN) ? |
3873 | first_net_device(seq_file_net(seq)) : | 3876 | first_net_device(seq_file_net(seq)) : |
3874 | next_net_device((struct net_device *)v); | 3877 | next_net_device((struct net_device *)v); |
3875 | 3878 | ||
3876 | ++*pos; | 3879 | ++*pos; |
3877 | return rcu_dereference(dev); | 3880 | return rcu_dereference(dev); |
3878 | } | 3881 | } |
3879 | 3882 | ||
3880 | void dev_seq_stop(struct seq_file *seq, void *v) | 3883 | void dev_seq_stop(struct seq_file *seq, void *v) |
3881 | __releases(RCU) | 3884 | __releases(RCU) |
3882 | { | 3885 | { |
3883 | rcu_read_unlock(); | 3886 | rcu_read_unlock(); |
3884 | } | 3887 | } |
3885 | 3888 | ||
3886 | static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev) | 3889 | static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev) |
3887 | { | 3890 | { |
3888 | struct rtnl_link_stats64 temp; | 3891 | struct rtnl_link_stats64 temp; |
3889 | const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp); | 3892 | const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp); |
3890 | 3893 | ||
3891 | seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu " | 3894 | seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu " |
3892 | "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n", | 3895 | "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n", |
3893 | dev->name, stats->rx_bytes, stats->rx_packets, | 3896 | dev->name, stats->rx_bytes, stats->rx_packets, |
3894 | stats->rx_errors, | 3897 | stats->rx_errors, |
3895 | stats->rx_dropped + stats->rx_missed_errors, | 3898 | stats->rx_dropped + stats->rx_missed_errors, |
3896 | stats->rx_fifo_errors, | 3899 | stats->rx_fifo_errors, |
3897 | stats->rx_length_errors + stats->rx_over_errors + | 3900 | stats->rx_length_errors + stats->rx_over_errors + |
3898 | stats->rx_crc_errors + stats->rx_frame_errors, | 3901 | stats->rx_crc_errors + stats->rx_frame_errors, |
3899 | stats->rx_compressed, stats->multicast, | 3902 | stats->rx_compressed, stats->multicast, |
3900 | stats->tx_bytes, stats->tx_packets, | 3903 | stats->tx_bytes, stats->tx_packets, |
3901 | stats->tx_errors, stats->tx_dropped, | 3904 | stats->tx_errors, stats->tx_dropped, |
3902 | stats->tx_fifo_errors, stats->collisions, | 3905 | stats->tx_fifo_errors, stats->collisions, |
3903 | stats->tx_carrier_errors + | 3906 | stats->tx_carrier_errors + |
3904 | stats->tx_aborted_errors + | 3907 | stats->tx_aborted_errors + |
3905 | stats->tx_window_errors + | 3908 | stats->tx_window_errors + |
3906 | stats->tx_heartbeat_errors, | 3909 | stats->tx_heartbeat_errors, |
3907 | stats->tx_compressed); | 3910 | stats->tx_compressed); |
3908 | } | 3911 | } |
3909 | 3912 | ||
3910 | /* | 3913 | /* |
3911 | * Called from the PROCfs module. This now uses the new arbitrary sized | 3914 | * Called from the PROCfs module. This now uses the new arbitrary sized |
3912 | * /proc/net interface to create /proc/net/dev | 3915 | * /proc/net interface to create /proc/net/dev |
3913 | */ | 3916 | */ |
3914 | static int dev_seq_show(struct seq_file *seq, void *v) | 3917 | static int dev_seq_show(struct seq_file *seq, void *v) |
3915 | { | 3918 | { |
3916 | if (v == SEQ_START_TOKEN) | 3919 | if (v == SEQ_START_TOKEN) |
3917 | seq_puts(seq, "Inter-| Receive " | 3920 | seq_puts(seq, "Inter-| Receive " |
3918 | " | Transmit\n" | 3921 | " | Transmit\n" |
3919 | " face |bytes packets errs drop fifo frame " | 3922 | " face |bytes packets errs drop fifo frame " |
3920 | "compressed multicast|bytes packets errs " | 3923 | "compressed multicast|bytes packets errs " |
3921 | "drop fifo colls carrier compressed\n"); | 3924 | "drop fifo colls carrier compressed\n"); |
3922 | else | 3925 | else |
3923 | dev_seq_printf_stats(seq, v); | 3926 | dev_seq_printf_stats(seq, v); |
3924 | return 0; | 3927 | return 0; |
3925 | } | 3928 | } |
3926 | 3929 | ||
3927 | static struct softnet_data *softnet_get_online(loff_t *pos) | 3930 | static struct softnet_data *softnet_get_online(loff_t *pos) |
3928 | { | 3931 | { |
3929 | struct softnet_data *sd = NULL; | 3932 | struct softnet_data *sd = NULL; |
3930 | 3933 | ||
3931 | while (*pos < nr_cpu_ids) | 3934 | while (*pos < nr_cpu_ids) |
3932 | if (cpu_online(*pos)) { | 3935 | if (cpu_online(*pos)) { |
3933 | sd = &per_cpu(softnet_data, *pos); | 3936 | sd = &per_cpu(softnet_data, *pos); |
3934 | break; | 3937 | break; |
3935 | } else | 3938 | } else |
3936 | ++*pos; | 3939 | ++*pos; |
3937 | return sd; | 3940 | return sd; |
3938 | } | 3941 | } |
3939 | 3942 | ||
3940 | static void *softnet_seq_start(struct seq_file *seq, loff_t *pos) | 3943 | static void *softnet_seq_start(struct seq_file *seq, loff_t *pos) |
3941 | { | 3944 | { |
3942 | return softnet_get_online(pos); | 3945 | return softnet_get_online(pos); |
3943 | } | 3946 | } |
3944 | 3947 | ||
3945 | static void *softnet_seq_next(struct seq_file *seq, void *v, loff_t *pos) | 3948 | static void *softnet_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
3946 | { | 3949 | { |
3947 | ++*pos; | 3950 | ++*pos; |
3948 | return softnet_get_online(pos); | 3951 | return softnet_get_online(pos); |
3949 | } | 3952 | } |
3950 | 3953 | ||
3951 | static void softnet_seq_stop(struct seq_file *seq, void *v) | 3954 | static void softnet_seq_stop(struct seq_file *seq, void *v) |
3952 | { | 3955 | { |
3953 | } | 3956 | } |
3954 | 3957 | ||
3955 | static int softnet_seq_show(struct seq_file *seq, void *v) | 3958 | static int softnet_seq_show(struct seq_file *seq, void *v) |
3956 | { | 3959 | { |
3957 | struct softnet_data *sd = v; | 3960 | struct softnet_data *sd = v; |
3958 | 3961 | ||
3959 | seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x %08x %08x\n", | 3962 | seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x %08x %08x\n", |
3960 | sd->processed, sd->dropped, sd->time_squeeze, 0, | 3963 | sd->processed, sd->dropped, sd->time_squeeze, 0, |
3961 | 0, 0, 0, 0, /* was fastroute */ | 3964 | 0, 0, 0, 0, /* was fastroute */ |
3962 | sd->cpu_collision, sd->received_rps); | 3965 | sd->cpu_collision, sd->received_rps); |
3963 | return 0; | 3966 | return 0; |
3964 | } | 3967 | } |
3965 | 3968 | ||
3966 | static const struct seq_operations dev_seq_ops = { | 3969 | static const struct seq_operations dev_seq_ops = { |
3967 | .start = dev_seq_start, | 3970 | .start = dev_seq_start, |
3968 | .next = dev_seq_next, | 3971 | .next = dev_seq_next, |
3969 | .stop = dev_seq_stop, | 3972 | .stop = dev_seq_stop, |
3970 | .show = dev_seq_show, | 3973 | .show = dev_seq_show, |
3971 | }; | 3974 | }; |
3972 | 3975 | ||
3973 | static int dev_seq_open(struct inode *inode, struct file *file) | 3976 | static int dev_seq_open(struct inode *inode, struct file *file) |
3974 | { | 3977 | { |
3975 | return seq_open_net(inode, file, &dev_seq_ops, | 3978 | return seq_open_net(inode, file, &dev_seq_ops, |
3976 | sizeof(struct seq_net_private)); | 3979 | sizeof(struct seq_net_private)); |
3977 | } | 3980 | } |
3978 | 3981 | ||
3979 | static const struct file_operations dev_seq_fops = { | 3982 | static const struct file_operations dev_seq_fops = { |
3980 | .owner = THIS_MODULE, | 3983 | .owner = THIS_MODULE, |
3981 | .open = dev_seq_open, | 3984 | .open = dev_seq_open, |
3982 | .read = seq_read, | 3985 | .read = seq_read, |
3983 | .llseek = seq_lseek, | 3986 | .llseek = seq_lseek, |
3984 | .release = seq_release_net, | 3987 | .release = seq_release_net, |
3985 | }; | 3988 | }; |
3986 | 3989 | ||
3987 | static const struct seq_operations softnet_seq_ops = { | 3990 | static const struct seq_operations softnet_seq_ops = { |
3988 | .start = softnet_seq_start, | 3991 | .start = softnet_seq_start, |
3989 | .next = softnet_seq_next, | 3992 | .next = softnet_seq_next, |
3990 | .stop = softnet_seq_stop, | 3993 | .stop = softnet_seq_stop, |
3991 | .show = softnet_seq_show, | 3994 | .show = softnet_seq_show, |
3992 | }; | 3995 | }; |
3993 | 3996 | ||
3994 | static int softnet_seq_open(struct inode *inode, struct file *file) | 3997 | static int softnet_seq_open(struct inode *inode, struct file *file) |
3995 | { | 3998 | { |
3996 | return seq_open(file, &softnet_seq_ops); | 3999 | return seq_open(file, &softnet_seq_ops); |
3997 | } | 4000 | } |
3998 | 4001 | ||
3999 | static const struct file_operations softnet_seq_fops = { | 4002 | static const struct file_operations softnet_seq_fops = { |
4000 | .owner = THIS_MODULE, | 4003 | .owner = THIS_MODULE, |
4001 | .open = softnet_seq_open, | 4004 | .open = softnet_seq_open, |
4002 | .read = seq_read, | 4005 | .read = seq_read, |
4003 | .llseek = seq_lseek, | 4006 | .llseek = seq_lseek, |
4004 | .release = seq_release, | 4007 | .release = seq_release, |
4005 | }; | 4008 | }; |
4006 | 4009 | ||
4007 | static void *ptype_get_idx(loff_t pos) | 4010 | static void *ptype_get_idx(loff_t pos) |
4008 | { | 4011 | { |
4009 | struct packet_type *pt = NULL; | 4012 | struct packet_type *pt = NULL; |
4010 | loff_t i = 0; | 4013 | loff_t i = 0; |
4011 | int t; | 4014 | int t; |
4012 | 4015 | ||
4013 | list_for_each_entry_rcu(pt, &ptype_all, list) { | 4016 | list_for_each_entry_rcu(pt, &ptype_all, list) { |
4014 | if (i == pos) | 4017 | if (i == pos) |
4015 | return pt; | 4018 | return pt; |
4016 | ++i; | 4019 | ++i; |
4017 | } | 4020 | } |
4018 | 4021 | ||
4019 | for (t = 0; t < PTYPE_HASH_SIZE; t++) { | 4022 | for (t = 0; t < PTYPE_HASH_SIZE; t++) { |
4020 | list_for_each_entry_rcu(pt, &ptype_base[t], list) { | 4023 | list_for_each_entry_rcu(pt, &ptype_base[t], list) { |
4021 | if (i == pos) | 4024 | if (i == pos) |
4022 | return pt; | 4025 | return pt; |
4023 | ++i; | 4026 | ++i; |
4024 | } | 4027 | } |
4025 | } | 4028 | } |
4026 | return NULL; | 4029 | return NULL; |
4027 | } | 4030 | } |
4028 | 4031 | ||
4029 | static void *ptype_seq_start(struct seq_file *seq, loff_t *pos) | 4032 | static void *ptype_seq_start(struct seq_file *seq, loff_t *pos) |
4030 | __acquires(RCU) | 4033 | __acquires(RCU) |
4031 | { | 4034 | { |
4032 | rcu_read_lock(); | 4035 | rcu_read_lock(); |
4033 | return *pos ? ptype_get_idx(*pos - 1) : SEQ_START_TOKEN; | 4036 | return *pos ? ptype_get_idx(*pos - 1) : SEQ_START_TOKEN; |
4034 | } | 4037 | } |
4035 | 4038 | ||
4036 | static void *ptype_seq_next(struct seq_file *seq, void *v, loff_t *pos) | 4039 | static void *ptype_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
4037 | { | 4040 | { |
4038 | struct packet_type *pt; | 4041 | struct packet_type *pt; |
4039 | struct list_head *nxt; | 4042 | struct list_head *nxt; |
4040 | int hash; | 4043 | int hash; |
4041 | 4044 | ||
4042 | ++*pos; | 4045 | ++*pos; |
4043 | if (v == SEQ_START_TOKEN) | 4046 | if (v == SEQ_START_TOKEN) |
4044 | return ptype_get_idx(0); | 4047 | return ptype_get_idx(0); |
4045 | 4048 | ||
4046 | pt = v; | 4049 | pt = v; |
4047 | nxt = pt->list.next; | 4050 | nxt = pt->list.next; |
4048 | if (pt->type == htons(ETH_P_ALL)) { | 4051 | if (pt->type == htons(ETH_P_ALL)) { |
4049 | if (nxt != &ptype_all) | 4052 | if (nxt != &ptype_all) |
4050 | goto found; | 4053 | goto found; |
4051 | hash = 0; | 4054 | hash = 0; |
4052 | nxt = ptype_base[0].next; | 4055 | nxt = ptype_base[0].next; |
4053 | } else | 4056 | } else |
4054 | hash = ntohs(pt->type) & PTYPE_HASH_MASK; | 4057 | hash = ntohs(pt->type) & PTYPE_HASH_MASK; |
4055 | 4058 | ||
4056 | while (nxt == &ptype_base[hash]) { | 4059 | while (nxt == &ptype_base[hash]) { |
4057 | if (++hash >= PTYPE_HASH_SIZE) | 4060 | if (++hash >= PTYPE_HASH_SIZE) |
4058 | return NULL; | 4061 | return NULL; |
4059 | nxt = ptype_base[hash].next; | 4062 | nxt = ptype_base[hash].next; |
4060 | } | 4063 | } |
4061 | found: | 4064 | found: |
4062 | return list_entry(nxt, struct packet_type, list); | 4065 | return list_entry(nxt, struct packet_type, list); |
4063 | } | 4066 | } |
4064 | 4067 | ||
4065 | static void ptype_seq_stop(struct seq_file *seq, void *v) | 4068 | static void ptype_seq_stop(struct seq_file *seq, void *v) |
4066 | __releases(RCU) | 4069 | __releases(RCU) |
4067 | { | 4070 | { |
4068 | rcu_read_unlock(); | 4071 | rcu_read_unlock(); |
4069 | } | 4072 | } |
4070 | 4073 | ||
4071 | static int ptype_seq_show(struct seq_file *seq, void *v) | 4074 | static int ptype_seq_show(struct seq_file *seq, void *v) |
4072 | { | 4075 | { |
4073 | struct packet_type *pt = v; | 4076 | struct packet_type *pt = v; |
4074 | 4077 | ||
4075 | if (v == SEQ_START_TOKEN) | 4078 | if (v == SEQ_START_TOKEN) |
4076 | seq_puts(seq, "Type Device Function\n"); | 4079 | seq_puts(seq, "Type Device Function\n"); |
4077 | else if (pt->dev == NULL || dev_net(pt->dev) == seq_file_net(seq)) { | 4080 | else if (pt->dev == NULL || dev_net(pt->dev) == seq_file_net(seq)) { |
4078 | if (pt->type == htons(ETH_P_ALL)) | 4081 | if (pt->type == htons(ETH_P_ALL)) |
4079 | seq_puts(seq, "ALL "); | 4082 | seq_puts(seq, "ALL "); |
4080 | else | 4083 | else |
4081 | seq_printf(seq, "%04x", ntohs(pt->type)); | 4084 | seq_printf(seq, "%04x", ntohs(pt->type)); |
4082 | 4085 | ||
4083 | seq_printf(seq, " %-8s %pF\n", | 4086 | seq_printf(seq, " %-8s %pF\n", |
4084 | pt->dev ? pt->dev->name : "", pt->func); | 4087 | pt->dev ? pt->dev->name : "", pt->func); |
4085 | } | 4088 | } |
4086 | 4089 | ||
4087 | return 0; | 4090 | return 0; |
4088 | } | 4091 | } |
4089 | 4092 | ||
4090 | static const struct seq_operations ptype_seq_ops = { | 4093 | static const struct seq_operations ptype_seq_ops = { |
4091 | .start = ptype_seq_start, | 4094 | .start = ptype_seq_start, |
4092 | .next = ptype_seq_next, | 4095 | .next = ptype_seq_next, |
4093 | .stop = ptype_seq_stop, | 4096 | .stop = ptype_seq_stop, |
4094 | .show = ptype_seq_show, | 4097 | .show = ptype_seq_show, |
4095 | }; | 4098 | }; |
4096 | 4099 | ||
4097 | static int ptype_seq_open(struct inode *inode, struct file *file) | 4100 | static int ptype_seq_open(struct inode *inode, struct file *file) |
4098 | { | 4101 | { |
4099 | return seq_open_net(inode, file, &ptype_seq_ops, | 4102 | return seq_open_net(inode, file, &ptype_seq_ops, |
4100 | sizeof(struct seq_net_private)); | 4103 | sizeof(struct seq_net_private)); |
4101 | } | 4104 | } |
4102 | 4105 | ||
4103 | static const struct file_operations ptype_seq_fops = { | 4106 | static const struct file_operations ptype_seq_fops = { |
4104 | .owner = THIS_MODULE, | 4107 | .owner = THIS_MODULE, |
4105 | .open = ptype_seq_open, | 4108 | .open = ptype_seq_open, |
4106 | .read = seq_read, | 4109 | .read = seq_read, |
4107 | .llseek = seq_lseek, | 4110 | .llseek = seq_lseek, |
4108 | .release = seq_release_net, | 4111 | .release = seq_release_net, |
4109 | }; | 4112 | }; |
4110 | 4113 | ||
4111 | 4114 | ||
4112 | static int __net_init dev_proc_net_init(struct net *net) | 4115 | static int __net_init dev_proc_net_init(struct net *net) |
4113 | { | 4116 | { |
4114 | int rc = -ENOMEM; | 4117 | int rc = -ENOMEM; |
4115 | 4118 | ||
4116 | if (!proc_net_fops_create(net, "dev", S_IRUGO, &dev_seq_fops)) | 4119 | if (!proc_net_fops_create(net, "dev", S_IRUGO, &dev_seq_fops)) |
4117 | goto out; | 4120 | goto out; |
4118 | if (!proc_net_fops_create(net, "softnet_stat", S_IRUGO, &softnet_seq_fops)) | 4121 | if (!proc_net_fops_create(net, "softnet_stat", S_IRUGO, &softnet_seq_fops)) |
4119 | goto out_dev; | 4122 | goto out_dev; |
4120 | if (!proc_net_fops_create(net, "ptype", S_IRUGO, &ptype_seq_fops)) | 4123 | if (!proc_net_fops_create(net, "ptype", S_IRUGO, &ptype_seq_fops)) |
4121 | goto out_softnet; | 4124 | goto out_softnet; |
4122 | 4125 | ||
4123 | if (wext_proc_init(net)) | 4126 | if (wext_proc_init(net)) |
4124 | goto out_ptype; | 4127 | goto out_ptype; |
4125 | rc = 0; | 4128 | rc = 0; |
4126 | out: | 4129 | out: |
4127 | return rc; | 4130 | return rc; |
4128 | out_ptype: | 4131 | out_ptype: |
4129 | proc_net_remove(net, "ptype"); | 4132 | proc_net_remove(net, "ptype"); |
4130 | out_softnet: | 4133 | out_softnet: |
4131 | proc_net_remove(net, "softnet_stat"); | 4134 | proc_net_remove(net, "softnet_stat"); |
4132 | out_dev: | 4135 | out_dev: |
4133 | proc_net_remove(net, "dev"); | 4136 | proc_net_remove(net, "dev"); |
4134 | goto out; | 4137 | goto out; |
4135 | } | 4138 | } |
4136 | 4139 | ||
4137 | static void __net_exit dev_proc_net_exit(struct net *net) | 4140 | static void __net_exit dev_proc_net_exit(struct net *net) |
4138 | { | 4141 | { |
4139 | wext_proc_exit(net); | 4142 | wext_proc_exit(net); |
4140 | 4143 | ||
4141 | proc_net_remove(net, "ptype"); | 4144 | proc_net_remove(net, "ptype"); |
4142 | proc_net_remove(net, "softnet_stat"); | 4145 | proc_net_remove(net, "softnet_stat"); |
4143 | proc_net_remove(net, "dev"); | 4146 | proc_net_remove(net, "dev"); |
4144 | } | 4147 | } |
4145 | 4148 | ||
4146 | static struct pernet_operations __net_initdata dev_proc_ops = { | 4149 | static struct pernet_operations __net_initdata dev_proc_ops = { |
4147 | .init = dev_proc_net_init, | 4150 | .init = dev_proc_net_init, |
4148 | .exit = dev_proc_net_exit, | 4151 | .exit = dev_proc_net_exit, |
4149 | }; | 4152 | }; |
4150 | 4153 | ||
4151 | static int __init dev_proc_init(void) | 4154 | static int __init dev_proc_init(void) |
4152 | { | 4155 | { |
4153 | return register_pernet_subsys(&dev_proc_ops); | 4156 | return register_pernet_subsys(&dev_proc_ops); |
4154 | } | 4157 | } |
4155 | #else | 4158 | #else |
4156 | #define dev_proc_init() 0 | 4159 | #define dev_proc_init() 0 |
4157 | #endif /* CONFIG_PROC_FS */ | 4160 | #endif /* CONFIG_PROC_FS */ |
4158 | 4161 | ||
4159 | 4162 | ||
4160 | /** | 4163 | /** |
4161 | * netdev_set_master - set up master/slave pair | 4164 | * netdev_set_master - set up master/slave pair |
4162 | * @slave: slave device | 4165 | * @slave: slave device |
4163 | * @master: new master device | 4166 | * @master: new master device |
4164 | * | 4167 | * |
4165 | * Changes the master device of the slave. Pass %NULL to break the | 4168 | * Changes the master device of the slave. Pass %NULL to break the |
4166 | * bonding. The caller must hold the RTNL semaphore. On a failure | 4169 | * bonding. The caller must hold the RTNL semaphore. On a failure |
4167 | * a negative errno code is returned. On success the reference counts | 4170 | * a negative errno code is returned. On success the reference counts |
4168 | * are adjusted, %RTM_NEWLINK is sent to the routing socket and the | 4171 | * are adjusted, %RTM_NEWLINK is sent to the routing socket and the |
4169 | * function returns zero. | 4172 | * function returns zero. |
4170 | */ | 4173 | */ |
4171 | int netdev_set_master(struct net_device *slave, struct net_device *master) | 4174 | int netdev_set_master(struct net_device *slave, struct net_device *master) |
4172 | { | 4175 | { |
4173 | struct net_device *old = slave->master; | 4176 | struct net_device *old = slave->master; |
4174 | 4177 | ||
4175 | ASSERT_RTNL(); | 4178 | ASSERT_RTNL(); |
4176 | 4179 | ||
4177 | if (master) { | 4180 | if (master) { |
4178 | if (old) | 4181 | if (old) |
4179 | return -EBUSY; | 4182 | return -EBUSY; |
4180 | dev_hold(master); | 4183 | dev_hold(master); |
4181 | } | 4184 | } |
4182 | 4185 | ||
4183 | slave->master = master; | 4186 | slave->master = master; |
4184 | 4187 | ||
4185 | if (old) { | 4188 | if (old) { |
4186 | synchronize_net(); | 4189 | synchronize_net(); |
4187 | dev_put(old); | 4190 | dev_put(old); |
4188 | } | 4191 | } |
4189 | if (master) | 4192 | if (master) |
4190 | slave->flags |= IFF_SLAVE; | 4193 | slave->flags |= IFF_SLAVE; |
4191 | else | 4194 | else |
4192 | slave->flags &= ~IFF_SLAVE; | 4195 | slave->flags &= ~IFF_SLAVE; |
4193 | 4196 | ||
4194 | rtmsg_ifinfo(RTM_NEWLINK, slave, IFF_SLAVE); | 4197 | rtmsg_ifinfo(RTM_NEWLINK, slave, IFF_SLAVE); |
4195 | return 0; | 4198 | return 0; |
4196 | } | 4199 | } |
4197 | EXPORT_SYMBOL(netdev_set_master); | 4200 | EXPORT_SYMBOL(netdev_set_master); |
4198 | 4201 | ||
4199 | static void dev_change_rx_flags(struct net_device *dev, int flags) | 4202 | static void dev_change_rx_flags(struct net_device *dev, int flags) |
4200 | { | 4203 | { |
4201 | const struct net_device_ops *ops = dev->netdev_ops; | 4204 | const struct net_device_ops *ops = dev->netdev_ops; |
4202 | 4205 | ||
4203 | if ((dev->flags & IFF_UP) && ops->ndo_change_rx_flags) | 4206 | if ((dev->flags & IFF_UP) && ops->ndo_change_rx_flags) |
4204 | ops->ndo_change_rx_flags(dev, flags); | 4207 | ops->ndo_change_rx_flags(dev, flags); |
4205 | } | 4208 | } |
4206 | 4209 | ||
4207 | static int __dev_set_promiscuity(struct net_device *dev, int inc) | 4210 | static int __dev_set_promiscuity(struct net_device *dev, int inc) |
4208 | { | 4211 | { |
4209 | unsigned short old_flags = dev->flags; | 4212 | unsigned short old_flags = dev->flags; |
4210 | uid_t uid; | 4213 | uid_t uid; |
4211 | gid_t gid; | 4214 | gid_t gid; |
4212 | 4215 | ||
4213 | ASSERT_RTNL(); | 4216 | ASSERT_RTNL(); |
4214 | 4217 | ||
4215 | dev->flags |= IFF_PROMISC; | 4218 | dev->flags |= IFF_PROMISC; |
4216 | dev->promiscuity += inc; | 4219 | dev->promiscuity += inc; |
4217 | if (dev->promiscuity == 0) { | 4220 | if (dev->promiscuity == 0) { |
4218 | /* | 4221 | /* |
4219 | * Avoid overflow. | 4222 | * Avoid overflow. |
4220 | * If inc causes overflow, untouch promisc and return error. | 4223 | * If inc causes overflow, untouch promisc and return error. |
4221 | */ | 4224 | */ |
4222 | if (inc < 0) | 4225 | if (inc < 0) |
4223 | dev->flags &= ~IFF_PROMISC; | 4226 | dev->flags &= ~IFF_PROMISC; |
4224 | else { | 4227 | else { |
4225 | dev->promiscuity -= inc; | 4228 | dev->promiscuity -= inc; |
4226 | printk(KERN_WARNING "%s: promiscuity touches roof, " | 4229 | printk(KERN_WARNING "%s: promiscuity touches roof, " |
4227 | "set promiscuity failed, promiscuity feature " | 4230 | "set promiscuity failed, promiscuity feature " |
4228 | "of device might be broken.\n", dev->name); | 4231 | "of device might be broken.\n", dev->name); |
4229 | return -EOVERFLOW; | 4232 | return -EOVERFLOW; |
4230 | } | 4233 | } |
4231 | } | 4234 | } |
4232 | if (dev->flags != old_flags) { | 4235 | if (dev->flags != old_flags) { |
4233 | printk(KERN_INFO "device %s %s promiscuous mode\n", | 4236 | printk(KERN_INFO "device %s %s promiscuous mode\n", |
4234 | dev->name, (dev->flags & IFF_PROMISC) ? "entered" : | 4237 | dev->name, (dev->flags & IFF_PROMISC) ? "entered" : |
4235 | "left"); | 4238 | "left"); |
4236 | if (audit_enabled) { | 4239 | if (audit_enabled) { |
4237 | current_uid_gid(&uid, &gid); | 4240 | current_uid_gid(&uid, &gid); |
4238 | audit_log(current->audit_context, GFP_ATOMIC, | 4241 | audit_log(current->audit_context, GFP_ATOMIC, |
4239 | AUDIT_ANOM_PROMISCUOUS, | 4242 | AUDIT_ANOM_PROMISCUOUS, |
4240 | "dev=%s prom=%d old_prom=%d auid=%u uid=%u gid=%u ses=%u", | 4243 | "dev=%s prom=%d old_prom=%d auid=%u uid=%u gid=%u ses=%u", |
4241 | dev->name, (dev->flags & IFF_PROMISC), | 4244 | dev->name, (dev->flags & IFF_PROMISC), |
4242 | (old_flags & IFF_PROMISC), | 4245 | (old_flags & IFF_PROMISC), |
4243 | audit_get_loginuid(current), | 4246 | audit_get_loginuid(current), |
4244 | uid, gid, | 4247 | uid, gid, |
4245 | audit_get_sessionid(current)); | 4248 | audit_get_sessionid(current)); |
4246 | } | 4249 | } |
4247 | 4250 | ||
4248 | dev_change_rx_flags(dev, IFF_PROMISC); | 4251 | dev_change_rx_flags(dev, IFF_PROMISC); |
4249 | } | 4252 | } |
4250 | return 0; | 4253 | return 0; |
4251 | } | 4254 | } |
4252 | 4255 | ||
4253 | /** | 4256 | /** |
4254 | * dev_set_promiscuity - update promiscuity count on a device | 4257 | * dev_set_promiscuity - update promiscuity count on a device |
4255 | * @dev: device | 4258 | * @dev: device |
4256 | * @inc: modifier | 4259 | * @inc: modifier |
4257 | * | 4260 | * |
4258 | * Add or remove promiscuity from a device. While the count in the device | 4261 | * Add or remove promiscuity from a device. While the count in the device |
4259 | * remains above zero the interface remains promiscuous. Once it hits zero | 4262 | * remains above zero the interface remains promiscuous. Once it hits zero |
4260 | * the device reverts back to normal filtering operation. A negative inc | 4263 | * the device reverts back to normal filtering operation. A negative inc |
4261 | * value is used to drop promiscuity on the device. | 4264 | * value is used to drop promiscuity on the device. |
4262 | * Return 0 if successful or a negative errno code on error. | 4265 | * Return 0 if successful or a negative errno code on error. |
4263 | */ | 4266 | */ |
4264 | int dev_set_promiscuity(struct net_device *dev, int inc) | 4267 | int dev_set_promiscuity(struct net_device *dev, int inc) |
4265 | { | 4268 | { |
4266 | unsigned short old_flags = dev->flags; | 4269 | unsigned short old_flags = dev->flags; |
4267 | int err; | 4270 | int err; |
4268 | 4271 | ||
4269 | err = __dev_set_promiscuity(dev, inc); | 4272 | err = __dev_set_promiscuity(dev, inc); |
4270 | if (err < 0) | 4273 | if (err < 0) |
4271 | return err; | 4274 | return err; |
4272 | if (dev->flags != old_flags) | 4275 | if (dev->flags != old_flags) |
4273 | dev_set_rx_mode(dev); | 4276 | dev_set_rx_mode(dev); |
4274 | return err; | 4277 | return err; |
4275 | } | 4278 | } |
4276 | EXPORT_SYMBOL(dev_set_promiscuity); | 4279 | EXPORT_SYMBOL(dev_set_promiscuity); |
4277 | 4280 | ||
4278 | /** | 4281 | /** |
4279 | * dev_set_allmulti - update allmulti count on a device | 4282 | * dev_set_allmulti - update allmulti count on a device |
4280 | * @dev: device | 4283 | * @dev: device |
4281 | * @inc: modifier | 4284 | * @inc: modifier |
4282 | * | 4285 | * |
4283 | * Add or remove reception of all multicast frames to a device. While the | 4286 | * Add or remove reception of all multicast frames to a device. While the |
4284 | * count in the device remains above zero the interface remains listening | 4287 | * count in the device remains above zero the interface remains listening |
4285 | * to all interfaces. Once it hits zero the device reverts back to normal | 4288 | * to all interfaces. Once it hits zero the device reverts back to normal |
4286 | * filtering operation. A negative @inc value is used to drop the counter | 4289 | * filtering operation. A negative @inc value is used to drop the counter |
4287 | * when releasing a resource needing all multicasts. | 4290 | * when releasing a resource needing all multicasts. |
4288 | * Return 0 if successful or a negative errno code on error. | 4291 | * Return 0 if successful or a negative errno code on error. |
4289 | */ | 4292 | */ |
4290 | 4293 | ||
4291 | int dev_set_allmulti(struct net_device *dev, int inc) | 4294 | int dev_set_allmulti(struct net_device *dev, int inc) |
4292 | { | 4295 | { |
4293 | unsigned short old_flags = dev->flags; | 4296 | unsigned short old_flags = dev->flags; |
4294 | 4297 | ||
4295 | ASSERT_RTNL(); | 4298 | ASSERT_RTNL(); |
4296 | 4299 | ||
4297 | dev->flags |= IFF_ALLMULTI; | 4300 | dev->flags |= IFF_ALLMULTI; |
4298 | dev->allmulti += inc; | 4301 | dev->allmulti += inc; |
4299 | if (dev->allmulti == 0) { | 4302 | if (dev->allmulti == 0) { |
4300 | /* | 4303 | /* |
4301 | * Avoid overflow. | 4304 | * Avoid overflow. |
4302 | * If inc causes overflow, untouch allmulti and return error. | 4305 | * If inc causes overflow, untouch allmulti and return error. |
4303 | */ | 4306 | */ |
4304 | if (inc < 0) | 4307 | if (inc < 0) |
4305 | dev->flags &= ~IFF_ALLMULTI; | 4308 | dev->flags &= ~IFF_ALLMULTI; |
4306 | else { | 4309 | else { |
4307 | dev->allmulti -= inc; | 4310 | dev->allmulti -= inc; |
4308 | printk(KERN_WARNING "%s: allmulti touches roof, " | 4311 | printk(KERN_WARNING "%s: allmulti touches roof, " |
4309 | "set allmulti failed, allmulti feature of " | 4312 | "set allmulti failed, allmulti feature of " |
4310 | "device might be broken.\n", dev->name); | 4313 | "device might be broken.\n", dev->name); |
4311 | return -EOVERFLOW; | 4314 | return -EOVERFLOW; |
4312 | } | 4315 | } |
4313 | } | 4316 | } |
4314 | if (dev->flags ^ old_flags) { | 4317 | if (dev->flags ^ old_flags) { |
4315 | dev_change_rx_flags(dev, IFF_ALLMULTI); | 4318 | dev_change_rx_flags(dev, IFF_ALLMULTI); |
4316 | dev_set_rx_mode(dev); | 4319 | dev_set_rx_mode(dev); |
4317 | } | 4320 | } |
4318 | return 0; | 4321 | return 0; |
4319 | } | 4322 | } |
4320 | EXPORT_SYMBOL(dev_set_allmulti); | 4323 | EXPORT_SYMBOL(dev_set_allmulti); |
4321 | 4324 | ||
4322 | /* | 4325 | /* |
4323 | * Upload unicast and multicast address lists to device and | 4326 | * Upload unicast and multicast address lists to device and |
4324 | * configure RX filtering. When the device doesn't support unicast | 4327 | * configure RX filtering. When the device doesn't support unicast |
4325 | * filtering it is put in promiscuous mode while unicast addresses | 4328 | * filtering it is put in promiscuous mode while unicast addresses |
4326 | * are present. | 4329 | * are present. |
4327 | */ | 4330 | */ |
4328 | void __dev_set_rx_mode(struct net_device *dev) | 4331 | void __dev_set_rx_mode(struct net_device *dev) |
4329 | { | 4332 | { |
4330 | const struct net_device_ops *ops = dev->netdev_ops; | 4333 | const struct net_device_ops *ops = dev->netdev_ops; |
4331 | 4334 | ||
4332 | /* dev_open will call this function so the list will stay sane. */ | 4335 | /* dev_open will call this function so the list will stay sane. */ |
4333 | if (!(dev->flags&IFF_UP)) | 4336 | if (!(dev->flags&IFF_UP)) |
4334 | return; | 4337 | return; |
4335 | 4338 | ||
4336 | if (!netif_device_present(dev)) | 4339 | if (!netif_device_present(dev)) |
4337 | return; | 4340 | return; |
4338 | 4341 | ||
4339 | if (ops->ndo_set_rx_mode) | 4342 | if (ops->ndo_set_rx_mode) |
4340 | ops->ndo_set_rx_mode(dev); | 4343 | ops->ndo_set_rx_mode(dev); |
4341 | else { | 4344 | else { |
4342 | /* Unicast addresses changes may only happen under the rtnl, | 4345 | /* Unicast addresses changes may only happen under the rtnl, |
4343 | * therefore calling __dev_set_promiscuity here is safe. | 4346 | * therefore calling __dev_set_promiscuity here is safe. |
4344 | */ | 4347 | */ |
4345 | if (!netdev_uc_empty(dev) && !dev->uc_promisc) { | 4348 | if (!netdev_uc_empty(dev) && !dev->uc_promisc) { |
4346 | __dev_set_promiscuity(dev, 1); | 4349 | __dev_set_promiscuity(dev, 1); |
4347 | dev->uc_promisc = 1; | 4350 | dev->uc_promisc = 1; |
4348 | } else if (netdev_uc_empty(dev) && dev->uc_promisc) { | 4351 | } else if (netdev_uc_empty(dev) && dev->uc_promisc) { |
4349 | __dev_set_promiscuity(dev, -1); | 4352 | __dev_set_promiscuity(dev, -1); |
4350 | dev->uc_promisc = 0; | 4353 | dev->uc_promisc = 0; |
4351 | } | 4354 | } |
4352 | 4355 | ||
4353 | if (ops->ndo_set_multicast_list) | 4356 | if (ops->ndo_set_multicast_list) |
4354 | ops->ndo_set_multicast_list(dev); | 4357 | ops->ndo_set_multicast_list(dev); |
4355 | } | 4358 | } |
4356 | } | 4359 | } |
4357 | 4360 | ||
4358 | void dev_set_rx_mode(struct net_device *dev) | 4361 | void dev_set_rx_mode(struct net_device *dev) |
4359 | { | 4362 | { |
4360 | netif_addr_lock_bh(dev); | 4363 | netif_addr_lock_bh(dev); |
4361 | __dev_set_rx_mode(dev); | 4364 | __dev_set_rx_mode(dev); |
4362 | netif_addr_unlock_bh(dev); | 4365 | netif_addr_unlock_bh(dev); |
4363 | } | 4366 | } |
4364 | 4367 | ||
4365 | /** | 4368 | /** |
4366 | * dev_get_flags - get flags reported to userspace | 4369 | * dev_get_flags - get flags reported to userspace |
4367 | * @dev: device | 4370 | * @dev: device |
4368 | * | 4371 | * |
4369 | * Get the combination of flag bits exported through APIs to userspace. | 4372 | * Get the combination of flag bits exported through APIs to userspace. |
4370 | */ | 4373 | */ |
4371 | unsigned dev_get_flags(const struct net_device *dev) | 4374 | unsigned dev_get_flags(const struct net_device *dev) |
4372 | { | 4375 | { |
4373 | unsigned flags; | 4376 | unsigned flags; |
4374 | 4377 | ||
4375 | flags = (dev->flags & ~(IFF_PROMISC | | 4378 | flags = (dev->flags & ~(IFF_PROMISC | |
4376 | IFF_ALLMULTI | | 4379 | IFF_ALLMULTI | |
4377 | IFF_RUNNING | | 4380 | IFF_RUNNING | |
4378 | IFF_LOWER_UP | | 4381 | IFF_LOWER_UP | |
4379 | IFF_DORMANT)) | | 4382 | IFF_DORMANT)) | |
4380 | (dev->gflags & (IFF_PROMISC | | 4383 | (dev->gflags & (IFF_PROMISC | |
4381 | IFF_ALLMULTI)); | 4384 | IFF_ALLMULTI)); |
4382 | 4385 | ||
4383 | if (netif_running(dev)) { | 4386 | if (netif_running(dev)) { |
4384 | if (netif_oper_up(dev)) | 4387 | if (netif_oper_up(dev)) |
4385 | flags |= IFF_RUNNING; | 4388 | flags |= IFF_RUNNING; |
4386 | if (netif_carrier_ok(dev)) | 4389 | if (netif_carrier_ok(dev)) |
4387 | flags |= IFF_LOWER_UP; | 4390 | flags |= IFF_LOWER_UP; |
4388 | if (netif_dormant(dev)) | 4391 | if (netif_dormant(dev)) |
4389 | flags |= IFF_DORMANT; | 4392 | flags |= IFF_DORMANT; |
4390 | } | 4393 | } |
4391 | 4394 | ||
4392 | return flags; | 4395 | return flags; |
4393 | } | 4396 | } |
4394 | EXPORT_SYMBOL(dev_get_flags); | 4397 | EXPORT_SYMBOL(dev_get_flags); |
4395 | 4398 | ||
4396 | int __dev_change_flags(struct net_device *dev, unsigned int flags) | 4399 | int __dev_change_flags(struct net_device *dev, unsigned int flags) |
4397 | { | 4400 | { |
4398 | int old_flags = dev->flags; | 4401 | int old_flags = dev->flags; |
4399 | int ret; | 4402 | int ret; |
4400 | 4403 | ||
4401 | ASSERT_RTNL(); | 4404 | ASSERT_RTNL(); |
4402 | 4405 | ||
4403 | /* | 4406 | /* |
4404 | * Set the flags on our device. | 4407 | * Set the flags on our device. |
4405 | */ | 4408 | */ |
4406 | 4409 | ||
4407 | dev->flags = (flags & (IFF_DEBUG | IFF_NOTRAILERS | IFF_NOARP | | 4410 | dev->flags = (flags & (IFF_DEBUG | IFF_NOTRAILERS | IFF_NOARP | |
4408 | IFF_DYNAMIC | IFF_MULTICAST | IFF_PORTSEL | | 4411 | IFF_DYNAMIC | IFF_MULTICAST | IFF_PORTSEL | |
4409 | IFF_AUTOMEDIA)) | | 4412 | IFF_AUTOMEDIA)) | |
4410 | (dev->flags & (IFF_UP | IFF_VOLATILE | IFF_PROMISC | | 4413 | (dev->flags & (IFF_UP | IFF_VOLATILE | IFF_PROMISC | |
4411 | IFF_ALLMULTI)); | 4414 | IFF_ALLMULTI)); |
4412 | 4415 | ||
4413 | /* | 4416 | /* |
4414 | * Load in the correct multicast list now the flags have changed. | 4417 | * Load in the correct multicast list now the flags have changed. |
4415 | */ | 4418 | */ |
4416 | 4419 | ||
4417 | if ((old_flags ^ flags) & IFF_MULTICAST) | 4420 | if ((old_flags ^ flags) & IFF_MULTICAST) |
4418 | dev_change_rx_flags(dev, IFF_MULTICAST); | 4421 | dev_change_rx_flags(dev, IFF_MULTICAST); |
4419 | 4422 | ||
4420 | dev_set_rx_mode(dev); | 4423 | dev_set_rx_mode(dev); |
4421 | 4424 | ||
4422 | /* | 4425 | /* |
4423 | * Have we downed the interface. We handle IFF_UP ourselves | 4426 | * Have we downed the interface. We handle IFF_UP ourselves |
4424 | * according to user attempts to set it, rather than blindly | 4427 | * according to user attempts to set it, rather than blindly |
4425 | * setting it. | 4428 | * setting it. |
4426 | */ | 4429 | */ |
4427 | 4430 | ||
4428 | ret = 0; | 4431 | ret = 0; |
4429 | if ((old_flags ^ flags) & IFF_UP) { /* Bit is different ? */ | 4432 | if ((old_flags ^ flags) & IFF_UP) { /* Bit is different ? */ |
4430 | ret = ((old_flags & IFF_UP) ? __dev_close : __dev_open)(dev); | 4433 | ret = ((old_flags & IFF_UP) ? __dev_close : __dev_open)(dev); |
4431 | 4434 | ||
4432 | if (!ret) | 4435 | if (!ret) |
4433 | dev_set_rx_mode(dev); | 4436 | dev_set_rx_mode(dev); |
4434 | } | 4437 | } |
4435 | 4438 | ||
4436 | if ((flags ^ dev->gflags) & IFF_PROMISC) { | 4439 | if ((flags ^ dev->gflags) & IFF_PROMISC) { |
4437 | int inc = (flags & IFF_PROMISC) ? 1 : -1; | 4440 | int inc = (flags & IFF_PROMISC) ? 1 : -1; |
4438 | 4441 | ||
4439 | dev->gflags ^= IFF_PROMISC; | 4442 | dev->gflags ^= IFF_PROMISC; |
4440 | dev_set_promiscuity(dev, inc); | 4443 | dev_set_promiscuity(dev, inc); |
4441 | } | 4444 | } |
4442 | 4445 | ||
4443 | /* NOTE: order of synchronization of IFF_PROMISC and IFF_ALLMULTI | 4446 | /* NOTE: order of synchronization of IFF_PROMISC and IFF_ALLMULTI |
4444 | is important. Some (broken) drivers set IFF_PROMISC, when | 4447 | is important. Some (broken) drivers set IFF_PROMISC, when |
4445 | IFF_ALLMULTI is requested not asking us and not reporting. | 4448 | IFF_ALLMULTI is requested not asking us and not reporting. |
4446 | */ | 4449 | */ |
4447 | if ((flags ^ dev->gflags) & IFF_ALLMULTI) { | 4450 | if ((flags ^ dev->gflags) & IFF_ALLMULTI) { |
4448 | int inc = (flags & IFF_ALLMULTI) ? 1 : -1; | 4451 | int inc = (flags & IFF_ALLMULTI) ? 1 : -1; |
4449 | 4452 | ||
4450 | dev->gflags ^= IFF_ALLMULTI; | 4453 | dev->gflags ^= IFF_ALLMULTI; |
4451 | dev_set_allmulti(dev, inc); | 4454 | dev_set_allmulti(dev, inc); |
4452 | } | 4455 | } |
4453 | 4456 | ||
4454 | return ret; | 4457 | return ret; |
4455 | } | 4458 | } |
4456 | 4459 | ||
4457 | void __dev_notify_flags(struct net_device *dev, unsigned int old_flags) | 4460 | void __dev_notify_flags(struct net_device *dev, unsigned int old_flags) |
4458 | { | 4461 | { |
4459 | unsigned int changes = dev->flags ^ old_flags; | 4462 | unsigned int changes = dev->flags ^ old_flags; |
4460 | 4463 | ||
4461 | if (changes & IFF_UP) { | 4464 | if (changes & IFF_UP) { |
4462 | if (dev->flags & IFF_UP) | 4465 | if (dev->flags & IFF_UP) |
4463 | call_netdevice_notifiers(NETDEV_UP, dev); | 4466 | call_netdevice_notifiers(NETDEV_UP, dev); |
4464 | else | 4467 | else |
4465 | call_netdevice_notifiers(NETDEV_DOWN, dev); | 4468 | call_netdevice_notifiers(NETDEV_DOWN, dev); |
4466 | } | 4469 | } |
4467 | 4470 | ||
4468 | if (dev->flags & IFF_UP && | 4471 | if (dev->flags & IFF_UP && |
4469 | (changes & ~(IFF_UP | IFF_PROMISC | IFF_ALLMULTI | IFF_VOLATILE))) | 4472 | (changes & ~(IFF_UP | IFF_PROMISC | IFF_ALLMULTI | IFF_VOLATILE))) |
4470 | call_netdevice_notifiers(NETDEV_CHANGE, dev); | 4473 | call_netdevice_notifiers(NETDEV_CHANGE, dev); |
4471 | } | 4474 | } |
4472 | 4475 | ||
4473 | /** | 4476 | /** |
4474 | * dev_change_flags - change device settings | 4477 | * dev_change_flags - change device settings |
4475 | * @dev: device | 4478 | * @dev: device |
4476 | * @flags: device state flags | 4479 | * @flags: device state flags |
4477 | * | 4480 | * |
4478 | * Change settings on device based state flags. The flags are | 4481 | * Change settings on device based state flags. The flags are |
4479 | * in the userspace exported format. | 4482 | * in the userspace exported format. |
4480 | */ | 4483 | */ |
4481 | int dev_change_flags(struct net_device *dev, unsigned flags) | 4484 | int dev_change_flags(struct net_device *dev, unsigned flags) |
4482 | { | 4485 | { |
4483 | int ret, changes; | 4486 | int ret, changes; |
4484 | int old_flags = dev->flags; | 4487 | int old_flags = dev->flags; |
4485 | 4488 | ||
4486 | ret = __dev_change_flags(dev, flags); | 4489 | ret = __dev_change_flags(dev, flags); |
4487 | if (ret < 0) | 4490 | if (ret < 0) |
4488 | return ret; | 4491 | return ret; |
4489 | 4492 | ||
4490 | changes = old_flags ^ dev->flags; | 4493 | changes = old_flags ^ dev->flags; |
4491 | if (changes) | 4494 | if (changes) |
4492 | rtmsg_ifinfo(RTM_NEWLINK, dev, changes); | 4495 | rtmsg_ifinfo(RTM_NEWLINK, dev, changes); |
4493 | 4496 | ||
4494 | __dev_notify_flags(dev, old_flags); | 4497 | __dev_notify_flags(dev, old_flags); |
4495 | return ret; | 4498 | return ret; |
4496 | } | 4499 | } |
4497 | EXPORT_SYMBOL(dev_change_flags); | 4500 | EXPORT_SYMBOL(dev_change_flags); |
4498 | 4501 | ||
4499 | /** | 4502 | /** |
4500 | * dev_set_mtu - Change maximum transfer unit | 4503 | * dev_set_mtu - Change maximum transfer unit |
4501 | * @dev: device | 4504 | * @dev: device |
4502 | * @new_mtu: new transfer unit | 4505 | * @new_mtu: new transfer unit |
4503 | * | 4506 | * |
4504 | * Change the maximum transfer size of the network device. | 4507 | * Change the maximum transfer size of the network device. |
4505 | */ | 4508 | */ |
4506 | int dev_set_mtu(struct net_device *dev, int new_mtu) | 4509 | int dev_set_mtu(struct net_device *dev, int new_mtu) |
4507 | { | 4510 | { |
4508 | const struct net_device_ops *ops = dev->netdev_ops; | 4511 | const struct net_device_ops *ops = dev->netdev_ops; |
4509 | int err; | 4512 | int err; |
4510 | 4513 | ||
4511 | if (new_mtu == dev->mtu) | 4514 | if (new_mtu == dev->mtu) |
4512 | return 0; | 4515 | return 0; |
4513 | 4516 | ||
4514 | /* MTU must be positive. */ | 4517 | /* MTU must be positive. */ |
4515 | if (new_mtu < 0) | 4518 | if (new_mtu < 0) |
4516 | return -EINVAL; | 4519 | return -EINVAL; |
4517 | 4520 | ||
4518 | if (!netif_device_present(dev)) | 4521 | if (!netif_device_present(dev)) |
4519 | return -ENODEV; | 4522 | return -ENODEV; |
4520 | 4523 | ||
4521 | err = 0; | 4524 | err = 0; |
4522 | if (ops->ndo_change_mtu) | 4525 | if (ops->ndo_change_mtu) |
4523 | err = ops->ndo_change_mtu(dev, new_mtu); | 4526 | err = ops->ndo_change_mtu(dev, new_mtu); |
4524 | else | 4527 | else |
4525 | dev->mtu = new_mtu; | 4528 | dev->mtu = new_mtu; |
4526 | 4529 | ||
4527 | if (!err && dev->flags & IFF_UP) | 4530 | if (!err && dev->flags & IFF_UP) |
4528 | call_netdevice_notifiers(NETDEV_CHANGEMTU, dev); | 4531 | call_netdevice_notifiers(NETDEV_CHANGEMTU, dev); |
4529 | return err; | 4532 | return err; |
4530 | } | 4533 | } |
4531 | EXPORT_SYMBOL(dev_set_mtu); | 4534 | EXPORT_SYMBOL(dev_set_mtu); |
4532 | 4535 | ||
4533 | /** | 4536 | /** |
4534 | * dev_set_mac_address - Change Media Access Control Address | 4537 | * dev_set_mac_address - Change Media Access Control Address |
4535 | * @dev: device | 4538 | * @dev: device |
4536 | * @sa: new address | 4539 | * @sa: new address |
4537 | * | 4540 | * |
4538 | * Change the hardware (MAC) address of the device | 4541 | * Change the hardware (MAC) address of the device |
4539 | */ | 4542 | */ |
4540 | int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa) | 4543 | int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa) |
4541 | { | 4544 | { |
4542 | const struct net_device_ops *ops = dev->netdev_ops; | 4545 | const struct net_device_ops *ops = dev->netdev_ops; |
4543 | int err; | 4546 | int err; |
4544 | 4547 | ||
4545 | if (!ops->ndo_set_mac_address) | 4548 | if (!ops->ndo_set_mac_address) |
4546 | return -EOPNOTSUPP; | 4549 | return -EOPNOTSUPP; |
4547 | if (sa->sa_family != dev->type) | 4550 | if (sa->sa_family != dev->type) |
4548 | return -EINVAL; | 4551 | return -EINVAL; |
4549 | if (!netif_device_present(dev)) | 4552 | if (!netif_device_present(dev)) |
4550 | return -ENODEV; | 4553 | return -ENODEV; |
4551 | err = ops->ndo_set_mac_address(dev, sa); | 4554 | err = ops->ndo_set_mac_address(dev, sa); |
4552 | if (!err) | 4555 | if (!err) |
4553 | call_netdevice_notifiers(NETDEV_CHANGEADDR, dev); | 4556 | call_netdevice_notifiers(NETDEV_CHANGEADDR, dev); |
4554 | return err; | 4557 | return err; |
4555 | } | 4558 | } |
4556 | EXPORT_SYMBOL(dev_set_mac_address); | 4559 | EXPORT_SYMBOL(dev_set_mac_address); |
4557 | 4560 | ||
4558 | /* | 4561 | /* |
4559 | * Perform the SIOCxIFxxx calls, inside rcu_read_lock() | 4562 | * Perform the SIOCxIFxxx calls, inside rcu_read_lock() |
4560 | */ | 4563 | */ |
4561 | static int dev_ifsioc_locked(struct net *net, struct ifreq *ifr, unsigned int cmd) | 4564 | static int dev_ifsioc_locked(struct net *net, struct ifreq *ifr, unsigned int cmd) |
4562 | { | 4565 | { |
4563 | int err; | 4566 | int err; |
4564 | struct net_device *dev = dev_get_by_name_rcu(net, ifr->ifr_name); | 4567 | struct net_device *dev = dev_get_by_name_rcu(net, ifr->ifr_name); |
4565 | 4568 | ||
4566 | if (!dev) | 4569 | if (!dev) |
4567 | return -ENODEV; | 4570 | return -ENODEV; |
4568 | 4571 | ||
4569 | switch (cmd) { | 4572 | switch (cmd) { |
4570 | case SIOCGIFFLAGS: /* Get interface flags */ | 4573 | case SIOCGIFFLAGS: /* Get interface flags */ |
4571 | ifr->ifr_flags = (short) dev_get_flags(dev); | 4574 | ifr->ifr_flags = (short) dev_get_flags(dev); |
4572 | return 0; | 4575 | return 0; |
4573 | 4576 | ||
4574 | case SIOCGIFMETRIC: /* Get the metric on the interface | 4577 | case SIOCGIFMETRIC: /* Get the metric on the interface |
4575 | (currently unused) */ | 4578 | (currently unused) */ |
4576 | ifr->ifr_metric = 0; | 4579 | ifr->ifr_metric = 0; |
4577 | return 0; | 4580 | return 0; |
4578 | 4581 | ||
4579 | case SIOCGIFMTU: /* Get the MTU of a device */ | 4582 | case SIOCGIFMTU: /* Get the MTU of a device */ |
4580 | ifr->ifr_mtu = dev->mtu; | 4583 | ifr->ifr_mtu = dev->mtu; |
4581 | return 0; | 4584 | return 0; |
4582 | 4585 | ||
4583 | case SIOCGIFHWADDR: | 4586 | case SIOCGIFHWADDR: |
4584 | if (!dev->addr_len) | 4587 | if (!dev->addr_len) |
4585 | memset(ifr->ifr_hwaddr.sa_data, 0, sizeof ifr->ifr_hwaddr.sa_data); | 4588 | memset(ifr->ifr_hwaddr.sa_data, 0, sizeof ifr->ifr_hwaddr.sa_data); |
4586 | else | 4589 | else |
4587 | memcpy(ifr->ifr_hwaddr.sa_data, dev->dev_addr, | 4590 | memcpy(ifr->ifr_hwaddr.sa_data, dev->dev_addr, |
4588 | min(sizeof ifr->ifr_hwaddr.sa_data, (size_t) dev->addr_len)); | 4591 | min(sizeof ifr->ifr_hwaddr.sa_data, (size_t) dev->addr_len)); |
4589 | ifr->ifr_hwaddr.sa_family = dev->type; | 4592 | ifr->ifr_hwaddr.sa_family = dev->type; |
4590 | return 0; | 4593 | return 0; |
4591 | 4594 | ||
4592 | case SIOCGIFSLAVE: | 4595 | case SIOCGIFSLAVE: |
4593 | err = -EINVAL; | 4596 | err = -EINVAL; |
4594 | break; | 4597 | break; |
4595 | 4598 | ||
4596 | case SIOCGIFMAP: | 4599 | case SIOCGIFMAP: |
4597 | ifr->ifr_map.mem_start = dev->mem_start; | 4600 | ifr->ifr_map.mem_start = dev->mem_start; |
4598 | ifr->ifr_map.mem_end = dev->mem_end; | 4601 | ifr->ifr_map.mem_end = dev->mem_end; |
4599 | ifr->ifr_map.base_addr = dev->base_addr; | 4602 | ifr->ifr_map.base_addr = dev->base_addr; |
4600 | ifr->ifr_map.irq = dev->irq; | 4603 | ifr->ifr_map.irq = dev->irq; |
4601 | ifr->ifr_map.dma = dev->dma; | 4604 | ifr->ifr_map.dma = dev->dma; |
4602 | ifr->ifr_map.port = dev->if_port; | 4605 | ifr->ifr_map.port = dev->if_port; |
4603 | return 0; | 4606 | return 0; |
4604 | 4607 | ||
4605 | case SIOCGIFINDEX: | 4608 | case SIOCGIFINDEX: |
4606 | ifr->ifr_ifindex = dev->ifindex; | 4609 | ifr->ifr_ifindex = dev->ifindex; |
4607 | return 0; | 4610 | return 0; |
4608 | 4611 | ||
4609 | case SIOCGIFTXQLEN: | 4612 | case SIOCGIFTXQLEN: |
4610 | ifr->ifr_qlen = dev->tx_queue_len; | 4613 | ifr->ifr_qlen = dev->tx_queue_len; |
4611 | return 0; | 4614 | return 0; |
4612 | 4615 | ||
4613 | default: | 4616 | default: |
4614 | /* dev_ioctl() should ensure this case | 4617 | /* dev_ioctl() should ensure this case |
4615 | * is never reached | 4618 | * is never reached |
4616 | */ | 4619 | */ |
4617 | WARN_ON(1); | 4620 | WARN_ON(1); |
4618 | err = -EINVAL; | 4621 | err = -EINVAL; |
4619 | break; | 4622 | break; |
4620 | 4623 | ||
4621 | } | 4624 | } |
4622 | return err; | 4625 | return err; |
4623 | } | 4626 | } |
4624 | 4627 | ||
4625 | /* | 4628 | /* |
4626 | * Perform the SIOCxIFxxx calls, inside rtnl_lock() | 4629 | * Perform the SIOCxIFxxx calls, inside rtnl_lock() |
4627 | */ | 4630 | */ |
4628 | static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd) | 4631 | static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd) |
4629 | { | 4632 | { |
4630 | int err; | 4633 | int err; |
4631 | struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name); | 4634 | struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name); |
4632 | const struct net_device_ops *ops; | 4635 | const struct net_device_ops *ops; |
4633 | 4636 | ||
4634 | if (!dev) | 4637 | if (!dev) |
4635 | return -ENODEV; | 4638 | return -ENODEV; |
4636 | 4639 | ||
4637 | ops = dev->netdev_ops; | 4640 | ops = dev->netdev_ops; |
4638 | 4641 | ||
4639 | switch (cmd) { | 4642 | switch (cmd) { |
4640 | case SIOCSIFFLAGS: /* Set interface flags */ | 4643 | case SIOCSIFFLAGS: /* Set interface flags */ |
4641 | return dev_change_flags(dev, ifr->ifr_flags); | 4644 | return dev_change_flags(dev, ifr->ifr_flags); |
4642 | 4645 | ||
4643 | case SIOCSIFMETRIC: /* Set the metric on the interface | 4646 | case SIOCSIFMETRIC: /* Set the metric on the interface |
4644 | (currently unused) */ | 4647 | (currently unused) */ |
4645 | return -EOPNOTSUPP; | 4648 | return -EOPNOTSUPP; |
4646 | 4649 | ||
4647 | case SIOCSIFMTU: /* Set the MTU of a device */ | 4650 | case SIOCSIFMTU: /* Set the MTU of a device */ |
4648 | return dev_set_mtu(dev, ifr->ifr_mtu); | 4651 | return dev_set_mtu(dev, ifr->ifr_mtu); |
4649 | 4652 | ||
4650 | case SIOCSIFHWADDR: | 4653 | case SIOCSIFHWADDR: |
4651 | return dev_set_mac_address(dev, &ifr->ifr_hwaddr); | 4654 | return dev_set_mac_address(dev, &ifr->ifr_hwaddr); |
4652 | 4655 | ||
4653 | case SIOCSIFHWBROADCAST: | 4656 | case SIOCSIFHWBROADCAST: |
4654 | if (ifr->ifr_hwaddr.sa_family != dev->type) | 4657 | if (ifr->ifr_hwaddr.sa_family != dev->type) |
4655 | return -EINVAL; | 4658 | return -EINVAL; |
4656 | memcpy(dev->broadcast, ifr->ifr_hwaddr.sa_data, | 4659 | memcpy(dev->broadcast, ifr->ifr_hwaddr.sa_data, |
4657 | min(sizeof ifr->ifr_hwaddr.sa_data, (size_t) dev->addr_len)); | 4660 | min(sizeof ifr->ifr_hwaddr.sa_data, (size_t) dev->addr_len)); |
4658 | call_netdevice_notifiers(NETDEV_CHANGEADDR, dev); | 4661 | call_netdevice_notifiers(NETDEV_CHANGEADDR, dev); |
4659 | return 0; | 4662 | return 0; |
4660 | 4663 | ||
4661 | case SIOCSIFMAP: | 4664 | case SIOCSIFMAP: |
4662 | if (ops->ndo_set_config) { | 4665 | if (ops->ndo_set_config) { |
4663 | if (!netif_device_present(dev)) | 4666 | if (!netif_device_present(dev)) |
4664 | return -ENODEV; | 4667 | return -ENODEV; |
4665 | return ops->ndo_set_config(dev, &ifr->ifr_map); | 4668 | return ops->ndo_set_config(dev, &ifr->ifr_map); |
4666 | } | 4669 | } |
4667 | return -EOPNOTSUPP; | 4670 | return -EOPNOTSUPP; |
4668 | 4671 | ||
4669 | case SIOCADDMULTI: | 4672 | case SIOCADDMULTI: |
4670 | if ((!ops->ndo_set_multicast_list && !ops->ndo_set_rx_mode) || | 4673 | if ((!ops->ndo_set_multicast_list && !ops->ndo_set_rx_mode) || |
4671 | ifr->ifr_hwaddr.sa_family != AF_UNSPEC) | 4674 | ifr->ifr_hwaddr.sa_family != AF_UNSPEC) |
4672 | return -EINVAL; | 4675 | return -EINVAL; |
4673 | if (!netif_device_present(dev)) | 4676 | if (!netif_device_present(dev)) |
4674 | return -ENODEV; | 4677 | return -ENODEV; |
4675 | return dev_mc_add_global(dev, ifr->ifr_hwaddr.sa_data); | 4678 | return dev_mc_add_global(dev, ifr->ifr_hwaddr.sa_data); |
4676 | 4679 | ||
4677 | case SIOCDELMULTI: | 4680 | case SIOCDELMULTI: |
4678 | if ((!ops->ndo_set_multicast_list && !ops->ndo_set_rx_mode) || | 4681 | if ((!ops->ndo_set_multicast_list && !ops->ndo_set_rx_mode) || |
4679 | ifr->ifr_hwaddr.sa_family != AF_UNSPEC) | 4682 | ifr->ifr_hwaddr.sa_family != AF_UNSPEC) |
4680 | return -EINVAL; | 4683 | return -EINVAL; |
4681 | if (!netif_device_present(dev)) | 4684 | if (!netif_device_present(dev)) |
4682 | return -ENODEV; | 4685 | return -ENODEV; |
4683 | return dev_mc_del_global(dev, ifr->ifr_hwaddr.sa_data); | 4686 | return dev_mc_del_global(dev, ifr->ifr_hwaddr.sa_data); |
4684 | 4687 | ||
4685 | case SIOCSIFTXQLEN: | 4688 | case SIOCSIFTXQLEN: |
4686 | if (ifr->ifr_qlen < 0) | 4689 | if (ifr->ifr_qlen < 0) |
4687 | return -EINVAL; | 4690 | return -EINVAL; |
4688 | dev->tx_queue_len = ifr->ifr_qlen; | 4691 | dev->tx_queue_len = ifr->ifr_qlen; |
4689 | return 0; | 4692 | return 0; |
4690 | 4693 | ||
4691 | case SIOCSIFNAME: | 4694 | case SIOCSIFNAME: |
4692 | ifr->ifr_newname[IFNAMSIZ-1] = '\0'; | 4695 | ifr->ifr_newname[IFNAMSIZ-1] = '\0'; |
4693 | return dev_change_name(dev, ifr->ifr_newname); | 4696 | return dev_change_name(dev, ifr->ifr_newname); |
4694 | 4697 | ||
4695 | /* | 4698 | /* |
4696 | * Unknown or private ioctl | 4699 | * Unknown or private ioctl |
4697 | */ | 4700 | */ |
4698 | default: | 4701 | default: |
4699 | if ((cmd >= SIOCDEVPRIVATE && | 4702 | if ((cmd >= SIOCDEVPRIVATE && |
4700 | cmd <= SIOCDEVPRIVATE + 15) || | 4703 | cmd <= SIOCDEVPRIVATE + 15) || |
4701 | cmd == SIOCBONDENSLAVE || | 4704 | cmd == SIOCBONDENSLAVE || |
4702 | cmd == SIOCBONDRELEASE || | 4705 | cmd == SIOCBONDRELEASE || |
4703 | cmd == SIOCBONDSETHWADDR || | 4706 | cmd == SIOCBONDSETHWADDR || |
4704 | cmd == SIOCBONDSLAVEINFOQUERY || | 4707 | cmd == SIOCBONDSLAVEINFOQUERY || |
4705 | cmd == SIOCBONDINFOQUERY || | 4708 | cmd == SIOCBONDINFOQUERY || |
4706 | cmd == SIOCBONDCHANGEACTIVE || | 4709 | cmd == SIOCBONDCHANGEACTIVE || |
4707 | cmd == SIOCGMIIPHY || | 4710 | cmd == SIOCGMIIPHY || |
4708 | cmd == SIOCGMIIREG || | 4711 | cmd == SIOCGMIIREG || |
4709 | cmd == SIOCSMIIREG || | 4712 | cmd == SIOCSMIIREG || |
4710 | cmd == SIOCBRADDIF || | 4713 | cmd == SIOCBRADDIF || |
4711 | cmd == SIOCBRDELIF || | 4714 | cmd == SIOCBRDELIF || |
4712 | cmd == SIOCSHWTSTAMP || | 4715 | cmd == SIOCSHWTSTAMP || |
4713 | cmd == SIOCWANDEV) { | 4716 | cmd == SIOCWANDEV) { |
4714 | err = -EOPNOTSUPP; | 4717 | err = -EOPNOTSUPP; |
4715 | if (ops->ndo_do_ioctl) { | 4718 | if (ops->ndo_do_ioctl) { |
4716 | if (netif_device_present(dev)) | 4719 | if (netif_device_present(dev)) |
4717 | err = ops->ndo_do_ioctl(dev, ifr, cmd); | 4720 | err = ops->ndo_do_ioctl(dev, ifr, cmd); |
4718 | else | 4721 | else |
4719 | err = -ENODEV; | 4722 | err = -ENODEV; |
4720 | } | 4723 | } |
4721 | } else | 4724 | } else |
4722 | err = -EINVAL; | 4725 | err = -EINVAL; |
4723 | 4726 | ||
4724 | } | 4727 | } |
4725 | return err; | 4728 | return err; |
4726 | } | 4729 | } |
4727 | 4730 | ||
4728 | /* | 4731 | /* |
4729 | * This function handles all "interface"-type I/O control requests. The actual | 4732 | * This function handles all "interface"-type I/O control requests. The actual |
4730 | * 'doing' part of this is dev_ifsioc above. | 4733 | * 'doing' part of this is dev_ifsioc above. |
4731 | */ | 4734 | */ |
4732 | 4735 | ||
4733 | /** | 4736 | /** |
4734 | * dev_ioctl - network device ioctl | 4737 | * dev_ioctl - network device ioctl |
4735 | * @net: the applicable net namespace | 4738 | * @net: the applicable net namespace |
4736 | * @cmd: command to issue | 4739 | * @cmd: command to issue |
4737 | * @arg: pointer to a struct ifreq in user space | 4740 | * @arg: pointer to a struct ifreq in user space |
4738 | * | 4741 | * |
4739 | * Issue ioctl functions to devices. This is normally called by the | 4742 | * Issue ioctl functions to devices. This is normally called by the |
4740 | * user space syscall interfaces but can sometimes be useful for | 4743 | * user space syscall interfaces but can sometimes be useful for |
4741 | * other purposes. The return value is the return from the syscall if | 4744 | * other purposes. The return value is the return from the syscall if |
4742 | * positive or a negative errno code on error. | 4745 | * positive or a negative errno code on error. |
4743 | */ | 4746 | */ |
4744 | 4747 | ||
4745 | int dev_ioctl(struct net *net, unsigned int cmd, void __user *arg) | 4748 | int dev_ioctl(struct net *net, unsigned int cmd, void __user *arg) |
4746 | { | 4749 | { |
4747 | struct ifreq ifr; | 4750 | struct ifreq ifr; |
4748 | int ret; | 4751 | int ret; |
4749 | char *colon; | 4752 | char *colon; |
4750 | 4753 | ||
4751 | /* One special case: SIOCGIFCONF takes ifconf argument | 4754 | /* One special case: SIOCGIFCONF takes ifconf argument |
4752 | and requires shared lock, because it sleeps writing | 4755 | and requires shared lock, because it sleeps writing |
4753 | to user space. | 4756 | to user space. |
4754 | */ | 4757 | */ |
4755 | 4758 | ||
4756 | if (cmd == SIOCGIFCONF) { | 4759 | if (cmd == SIOCGIFCONF) { |
4757 | rtnl_lock(); | 4760 | rtnl_lock(); |
4758 | ret = dev_ifconf(net, (char __user *) arg); | 4761 | ret = dev_ifconf(net, (char __user *) arg); |
4759 | rtnl_unlock(); | 4762 | rtnl_unlock(); |
4760 | return ret; | 4763 | return ret; |
4761 | } | 4764 | } |
4762 | if (cmd == SIOCGIFNAME) | 4765 | if (cmd == SIOCGIFNAME) |
4763 | return dev_ifname(net, (struct ifreq __user *)arg); | 4766 | return dev_ifname(net, (struct ifreq __user *)arg); |
4764 | 4767 | ||
4765 | if (copy_from_user(&ifr, arg, sizeof(struct ifreq))) | 4768 | if (copy_from_user(&ifr, arg, sizeof(struct ifreq))) |
4766 | return -EFAULT; | 4769 | return -EFAULT; |
4767 | 4770 | ||
4768 | ifr.ifr_name[IFNAMSIZ-1] = 0; | 4771 | ifr.ifr_name[IFNAMSIZ-1] = 0; |
4769 | 4772 | ||
4770 | colon = strchr(ifr.ifr_name, ':'); | 4773 | colon = strchr(ifr.ifr_name, ':'); |
4771 | if (colon) | 4774 | if (colon) |
4772 | *colon = 0; | 4775 | *colon = 0; |
4773 | 4776 | ||
4774 | /* | 4777 | /* |
4775 | * See which interface the caller is talking about. | 4778 | * See which interface the caller is talking about. |
4776 | */ | 4779 | */ |
4777 | 4780 | ||
4778 | switch (cmd) { | 4781 | switch (cmd) { |
4779 | /* | 4782 | /* |
4780 | * These ioctl calls: | 4783 | * These ioctl calls: |
4781 | * - can be done by all. | 4784 | * - can be done by all. |
4782 | * - atomic and do not require locking. | 4785 | * - atomic and do not require locking. |
4783 | * - return a value | 4786 | * - return a value |
4784 | */ | 4787 | */ |
4785 | case SIOCGIFFLAGS: | 4788 | case SIOCGIFFLAGS: |
4786 | case SIOCGIFMETRIC: | 4789 | case SIOCGIFMETRIC: |
4787 | case SIOCGIFMTU: | 4790 | case SIOCGIFMTU: |
4788 | case SIOCGIFHWADDR: | 4791 | case SIOCGIFHWADDR: |
4789 | case SIOCGIFSLAVE: | 4792 | case SIOCGIFSLAVE: |
4790 | case SIOCGIFMAP: | 4793 | case SIOCGIFMAP: |
4791 | case SIOCGIFINDEX: | 4794 | case SIOCGIFINDEX: |
4792 | case SIOCGIFTXQLEN: | 4795 | case SIOCGIFTXQLEN: |
4793 | dev_load(net, ifr.ifr_name); | 4796 | dev_load(net, ifr.ifr_name); |
4794 | rcu_read_lock(); | 4797 | rcu_read_lock(); |
4795 | ret = dev_ifsioc_locked(net, &ifr, cmd); | 4798 | ret = dev_ifsioc_locked(net, &ifr, cmd); |
4796 | rcu_read_unlock(); | 4799 | rcu_read_unlock(); |
4797 | if (!ret) { | 4800 | if (!ret) { |
4798 | if (colon) | 4801 | if (colon) |
4799 | *colon = ':'; | 4802 | *colon = ':'; |
4800 | if (copy_to_user(arg, &ifr, | 4803 | if (copy_to_user(arg, &ifr, |
4801 | sizeof(struct ifreq))) | 4804 | sizeof(struct ifreq))) |
4802 | ret = -EFAULT; | 4805 | ret = -EFAULT; |
4803 | } | 4806 | } |
4804 | return ret; | 4807 | return ret; |
4805 | 4808 | ||
4806 | case SIOCETHTOOL: | 4809 | case SIOCETHTOOL: |
4807 | dev_load(net, ifr.ifr_name); | 4810 | dev_load(net, ifr.ifr_name); |
4808 | rtnl_lock(); | 4811 | rtnl_lock(); |
4809 | ret = dev_ethtool(net, &ifr); | 4812 | ret = dev_ethtool(net, &ifr); |
4810 | rtnl_unlock(); | 4813 | rtnl_unlock(); |
4811 | if (!ret) { | 4814 | if (!ret) { |
4812 | if (colon) | 4815 | if (colon) |
4813 | *colon = ':'; | 4816 | *colon = ':'; |
4814 | if (copy_to_user(arg, &ifr, | 4817 | if (copy_to_user(arg, &ifr, |
4815 | sizeof(struct ifreq))) | 4818 | sizeof(struct ifreq))) |
4816 | ret = -EFAULT; | 4819 | ret = -EFAULT; |
4817 | } | 4820 | } |
4818 | return ret; | 4821 | return ret; |
4819 | 4822 | ||
4820 | /* | 4823 | /* |
4821 | * These ioctl calls: | 4824 | * These ioctl calls: |
4822 | * - require superuser power. | 4825 | * - require superuser power. |
4823 | * - require strict serialization. | 4826 | * - require strict serialization. |
4824 | * - return a value | 4827 | * - return a value |
4825 | */ | 4828 | */ |
4826 | case SIOCGMIIPHY: | 4829 | case SIOCGMIIPHY: |
4827 | case SIOCGMIIREG: | 4830 | case SIOCGMIIREG: |
4828 | case SIOCSIFNAME: | 4831 | case SIOCSIFNAME: |
4829 | if (!capable(CAP_NET_ADMIN)) | 4832 | if (!capable(CAP_NET_ADMIN)) |
4830 | return -EPERM; | 4833 | return -EPERM; |
4831 | dev_load(net, ifr.ifr_name); | 4834 | dev_load(net, ifr.ifr_name); |
4832 | rtnl_lock(); | 4835 | rtnl_lock(); |
4833 | ret = dev_ifsioc(net, &ifr, cmd); | 4836 | ret = dev_ifsioc(net, &ifr, cmd); |
4834 | rtnl_unlock(); | 4837 | rtnl_unlock(); |
4835 | if (!ret) { | 4838 | if (!ret) { |
4836 | if (colon) | 4839 | if (colon) |
4837 | *colon = ':'; | 4840 | *colon = ':'; |
4838 | if (copy_to_user(arg, &ifr, | 4841 | if (copy_to_user(arg, &ifr, |
4839 | sizeof(struct ifreq))) | 4842 | sizeof(struct ifreq))) |
4840 | ret = -EFAULT; | 4843 | ret = -EFAULT; |
4841 | } | 4844 | } |
4842 | return ret; | 4845 | return ret; |
4843 | 4846 | ||
4844 | /* | 4847 | /* |
4845 | * These ioctl calls: | 4848 | * These ioctl calls: |
4846 | * - require superuser power. | 4849 | * - require superuser power. |
4847 | * - require strict serialization. | 4850 | * - require strict serialization. |
4848 | * - do not return a value | 4851 | * - do not return a value |
4849 | */ | 4852 | */ |
4850 | case SIOCSIFFLAGS: | 4853 | case SIOCSIFFLAGS: |
4851 | case SIOCSIFMETRIC: | 4854 | case SIOCSIFMETRIC: |
4852 | case SIOCSIFMTU: | 4855 | case SIOCSIFMTU: |
4853 | case SIOCSIFMAP: | 4856 | case SIOCSIFMAP: |
4854 | case SIOCSIFHWADDR: | 4857 | case SIOCSIFHWADDR: |
4855 | case SIOCSIFSLAVE: | 4858 | case SIOCSIFSLAVE: |
4856 | case SIOCADDMULTI: | 4859 | case SIOCADDMULTI: |
4857 | case SIOCDELMULTI: | 4860 | case SIOCDELMULTI: |
4858 | case SIOCSIFHWBROADCAST: | 4861 | case SIOCSIFHWBROADCAST: |
4859 | case SIOCSIFTXQLEN: | 4862 | case SIOCSIFTXQLEN: |
4860 | case SIOCSMIIREG: | 4863 | case SIOCSMIIREG: |
4861 | case SIOCBONDENSLAVE: | 4864 | case SIOCBONDENSLAVE: |
4862 | case SIOCBONDRELEASE: | 4865 | case SIOCBONDRELEASE: |
4863 | case SIOCBONDSETHWADDR: | 4866 | case SIOCBONDSETHWADDR: |
4864 | case SIOCBONDCHANGEACTIVE: | 4867 | case SIOCBONDCHANGEACTIVE: |
4865 | case SIOCBRADDIF: | 4868 | case SIOCBRADDIF: |
4866 | case SIOCBRDELIF: | 4869 | case SIOCBRDELIF: |
4867 | case SIOCSHWTSTAMP: | 4870 | case SIOCSHWTSTAMP: |
4868 | if (!capable(CAP_NET_ADMIN)) | 4871 | if (!capable(CAP_NET_ADMIN)) |
4869 | return -EPERM; | 4872 | return -EPERM; |
4870 | /* fall through */ | 4873 | /* fall through */ |
4871 | case SIOCBONDSLAVEINFOQUERY: | 4874 | case SIOCBONDSLAVEINFOQUERY: |
4872 | case SIOCBONDINFOQUERY: | 4875 | case SIOCBONDINFOQUERY: |
4873 | dev_load(net, ifr.ifr_name); | 4876 | dev_load(net, ifr.ifr_name); |
4874 | rtnl_lock(); | 4877 | rtnl_lock(); |
4875 | ret = dev_ifsioc(net, &ifr, cmd); | 4878 | ret = dev_ifsioc(net, &ifr, cmd); |
4876 | rtnl_unlock(); | 4879 | rtnl_unlock(); |
4877 | return ret; | 4880 | return ret; |
4878 | 4881 | ||
4879 | case SIOCGIFMEM: | 4882 | case SIOCGIFMEM: |
4880 | /* Get the per device memory space. We can add this but | 4883 | /* Get the per device memory space. We can add this but |
4881 | * currently do not support it */ | 4884 | * currently do not support it */ |
4882 | case SIOCSIFMEM: | 4885 | case SIOCSIFMEM: |
4883 | /* Set the per device memory buffer space. | 4886 | /* Set the per device memory buffer space. |
4884 | * Not applicable in our case */ | 4887 | * Not applicable in our case */ |
4885 | case SIOCSIFLINK: | 4888 | case SIOCSIFLINK: |
4886 | return -EINVAL; | 4889 | return -EINVAL; |
4887 | 4890 | ||
4888 | /* | 4891 | /* |
4889 | * Unknown or private ioctl. | 4892 | * Unknown or private ioctl. |
4890 | */ | 4893 | */ |
4891 | default: | 4894 | default: |
4892 | if (cmd == SIOCWANDEV || | 4895 | if (cmd == SIOCWANDEV || |
4893 | (cmd >= SIOCDEVPRIVATE && | 4896 | (cmd >= SIOCDEVPRIVATE && |
4894 | cmd <= SIOCDEVPRIVATE + 15)) { | 4897 | cmd <= SIOCDEVPRIVATE + 15)) { |
4895 | dev_load(net, ifr.ifr_name); | 4898 | dev_load(net, ifr.ifr_name); |
4896 | rtnl_lock(); | 4899 | rtnl_lock(); |
4897 | ret = dev_ifsioc(net, &ifr, cmd); | 4900 | ret = dev_ifsioc(net, &ifr, cmd); |
4898 | rtnl_unlock(); | 4901 | rtnl_unlock(); |
4899 | if (!ret && copy_to_user(arg, &ifr, | 4902 | if (!ret && copy_to_user(arg, &ifr, |
4900 | sizeof(struct ifreq))) | 4903 | sizeof(struct ifreq))) |
4901 | ret = -EFAULT; | 4904 | ret = -EFAULT; |
4902 | return ret; | 4905 | return ret; |
4903 | } | 4906 | } |
4904 | /* Take care of Wireless Extensions */ | 4907 | /* Take care of Wireless Extensions */ |
4905 | if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) | 4908 | if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) |
4906 | return wext_handle_ioctl(net, &ifr, cmd, arg); | 4909 | return wext_handle_ioctl(net, &ifr, cmd, arg); |
4907 | return -EINVAL; | 4910 | return -EINVAL; |
4908 | } | 4911 | } |
4909 | } | 4912 | } |
4910 | 4913 | ||
4911 | 4914 | ||
4912 | /** | 4915 | /** |
4913 | * dev_new_index - allocate an ifindex | 4916 | * dev_new_index - allocate an ifindex |
4914 | * @net: the applicable net namespace | 4917 | * @net: the applicable net namespace |
4915 | * | 4918 | * |
4916 | * Returns a suitable unique value for a new device interface | 4919 | * Returns a suitable unique value for a new device interface |
4917 | * number. The caller must hold the rtnl semaphore or the | 4920 | * number. The caller must hold the rtnl semaphore or the |
4918 | * dev_base_lock to be sure it remains unique. | 4921 | * dev_base_lock to be sure it remains unique. |
4919 | */ | 4922 | */ |
4920 | static int dev_new_index(struct net *net) | 4923 | static int dev_new_index(struct net *net) |
4921 | { | 4924 | { |
4922 | static int ifindex; | 4925 | static int ifindex; |
4923 | for (;;) { | 4926 | for (;;) { |
4924 | if (++ifindex <= 0) | 4927 | if (++ifindex <= 0) |
4925 | ifindex = 1; | 4928 | ifindex = 1; |
4926 | if (!__dev_get_by_index(net, ifindex)) | 4929 | if (!__dev_get_by_index(net, ifindex)) |
4927 | return ifindex; | 4930 | return ifindex; |
4928 | } | 4931 | } |
4929 | } | 4932 | } |
4930 | 4933 | ||
4931 | /* Delayed registration/unregisteration */ | 4934 | /* Delayed registration/unregisteration */ |
4932 | static LIST_HEAD(net_todo_list); | 4935 | static LIST_HEAD(net_todo_list); |
4933 | 4936 | ||
4934 | static void net_set_todo(struct net_device *dev) | 4937 | static void net_set_todo(struct net_device *dev) |
4935 | { | 4938 | { |
4936 | list_add_tail(&dev->todo_list, &net_todo_list); | 4939 | list_add_tail(&dev->todo_list, &net_todo_list); |
4937 | } | 4940 | } |
4938 | 4941 | ||
4939 | static void rollback_registered_many(struct list_head *head) | 4942 | static void rollback_registered_many(struct list_head *head) |
4940 | { | 4943 | { |
4941 | struct net_device *dev, *tmp; | 4944 | struct net_device *dev, *tmp; |
4942 | 4945 | ||
4943 | BUG_ON(dev_boot_phase); | 4946 | BUG_ON(dev_boot_phase); |
4944 | ASSERT_RTNL(); | 4947 | ASSERT_RTNL(); |
4945 | 4948 | ||
4946 | list_for_each_entry_safe(dev, tmp, head, unreg_list) { | 4949 | list_for_each_entry_safe(dev, tmp, head, unreg_list) { |
4947 | /* Some devices call without registering | 4950 | /* Some devices call without registering |
4948 | * for initialization unwind. Remove those | 4951 | * for initialization unwind. Remove those |
4949 | * devices and proceed with the remaining. | 4952 | * devices and proceed with the remaining. |
4950 | */ | 4953 | */ |
4951 | if (dev->reg_state == NETREG_UNINITIALIZED) { | 4954 | if (dev->reg_state == NETREG_UNINITIALIZED) { |
4952 | pr_debug("unregister_netdevice: device %s/%p never " | 4955 | pr_debug("unregister_netdevice: device %s/%p never " |
4953 | "was registered\n", dev->name, dev); | 4956 | "was registered\n", dev->name, dev); |
4954 | 4957 | ||
4955 | WARN_ON(1); | 4958 | WARN_ON(1); |
4956 | list_del(&dev->unreg_list); | 4959 | list_del(&dev->unreg_list); |
4957 | continue; | 4960 | continue; |
4958 | } | 4961 | } |
4959 | 4962 | ||
4960 | BUG_ON(dev->reg_state != NETREG_REGISTERED); | 4963 | BUG_ON(dev->reg_state != NETREG_REGISTERED); |
4961 | 4964 | ||
4962 | /* If device is running, close it first. */ | 4965 | /* If device is running, close it first. */ |
4963 | dev_close(dev); | 4966 | dev_close(dev); |
4964 | 4967 | ||
4965 | /* And unlink it from device chain. */ | 4968 | /* And unlink it from device chain. */ |
4966 | unlist_netdevice(dev); | 4969 | unlist_netdevice(dev); |
4967 | 4970 | ||
4968 | dev->reg_state = NETREG_UNREGISTERING; | 4971 | dev->reg_state = NETREG_UNREGISTERING; |
4969 | } | 4972 | } |
4970 | 4973 | ||
4971 | synchronize_net(); | 4974 | synchronize_net(); |
4972 | 4975 | ||
4973 | list_for_each_entry(dev, head, unreg_list) { | 4976 | list_for_each_entry(dev, head, unreg_list) { |
4974 | /* Shutdown queueing discipline. */ | 4977 | /* Shutdown queueing discipline. */ |
4975 | dev_shutdown(dev); | 4978 | dev_shutdown(dev); |
4976 | 4979 | ||
4977 | 4980 | ||
4978 | /* Notify protocols, that we are about to destroy | 4981 | /* Notify protocols, that we are about to destroy |
4979 | this device. They should clean all the things. | 4982 | this device. They should clean all the things. |
4980 | */ | 4983 | */ |
4981 | call_netdevice_notifiers(NETDEV_UNREGISTER, dev); | 4984 | call_netdevice_notifiers(NETDEV_UNREGISTER, dev); |
4982 | 4985 | ||
4983 | if (!dev->rtnl_link_ops || | 4986 | if (!dev->rtnl_link_ops || |
4984 | dev->rtnl_link_state == RTNL_LINK_INITIALIZED) | 4987 | dev->rtnl_link_state == RTNL_LINK_INITIALIZED) |
4985 | rtmsg_ifinfo(RTM_DELLINK, dev, ~0U); | 4988 | rtmsg_ifinfo(RTM_DELLINK, dev, ~0U); |
4986 | 4989 | ||
4987 | /* | 4990 | /* |
4988 | * Flush the unicast and multicast chains | 4991 | * Flush the unicast and multicast chains |
4989 | */ | 4992 | */ |
4990 | dev_uc_flush(dev); | 4993 | dev_uc_flush(dev); |
4991 | dev_mc_flush(dev); | 4994 | dev_mc_flush(dev); |
4992 | 4995 | ||
4993 | if (dev->netdev_ops->ndo_uninit) | 4996 | if (dev->netdev_ops->ndo_uninit) |
4994 | dev->netdev_ops->ndo_uninit(dev); | 4997 | dev->netdev_ops->ndo_uninit(dev); |
4995 | 4998 | ||
4996 | /* Notifier chain MUST detach us from master device. */ | 4999 | /* Notifier chain MUST detach us from master device. */ |
4997 | WARN_ON(dev->master); | 5000 | WARN_ON(dev->master); |
4998 | 5001 | ||
4999 | /* Remove entries from kobject tree */ | 5002 | /* Remove entries from kobject tree */ |
5000 | netdev_unregister_kobject(dev); | 5003 | netdev_unregister_kobject(dev); |
5001 | } | 5004 | } |
5002 | 5005 | ||
5003 | /* Process any work delayed until the end of the batch */ | 5006 | /* Process any work delayed until the end of the batch */ |
5004 | dev = list_first_entry(head, struct net_device, unreg_list); | 5007 | dev = list_first_entry(head, struct net_device, unreg_list); |
5005 | call_netdevice_notifiers(NETDEV_UNREGISTER_BATCH, dev); | 5008 | call_netdevice_notifiers(NETDEV_UNREGISTER_BATCH, dev); |
5006 | 5009 | ||
5007 | rcu_barrier(); | 5010 | rcu_barrier(); |
5008 | 5011 | ||
5009 | list_for_each_entry(dev, head, unreg_list) | 5012 | list_for_each_entry(dev, head, unreg_list) |
5010 | dev_put(dev); | 5013 | dev_put(dev); |
5011 | } | 5014 | } |
5012 | 5015 | ||
5013 | static void rollback_registered(struct net_device *dev) | 5016 | static void rollback_registered(struct net_device *dev) |
5014 | { | 5017 | { |
5015 | LIST_HEAD(single); | 5018 | LIST_HEAD(single); |
5016 | 5019 | ||
5017 | list_add(&dev->unreg_list, &single); | 5020 | list_add(&dev->unreg_list, &single); |
5018 | rollback_registered_many(&single); | 5021 | rollback_registered_many(&single); |
5019 | } | 5022 | } |
5020 | 5023 | ||
5021 | unsigned long netdev_fix_features(unsigned long features, const char *name) | 5024 | unsigned long netdev_fix_features(unsigned long features, const char *name) |
5022 | { | 5025 | { |
5023 | /* Fix illegal SG+CSUM combinations. */ | 5026 | /* Fix illegal SG+CSUM combinations. */ |
5024 | if ((features & NETIF_F_SG) && | 5027 | if ((features & NETIF_F_SG) && |
5025 | !(features & NETIF_F_ALL_CSUM)) { | 5028 | !(features & NETIF_F_ALL_CSUM)) { |
5026 | if (name) | 5029 | if (name) |
5027 | printk(KERN_NOTICE "%s: Dropping NETIF_F_SG since no " | 5030 | printk(KERN_NOTICE "%s: Dropping NETIF_F_SG since no " |
5028 | "checksum feature.\n", name); | 5031 | "checksum feature.\n", name); |
5029 | features &= ~NETIF_F_SG; | 5032 | features &= ~NETIF_F_SG; |
5030 | } | 5033 | } |
5031 | 5034 | ||
5032 | /* TSO requires that SG is present as well. */ | 5035 | /* TSO requires that SG is present as well. */ |
5033 | if ((features & NETIF_F_TSO) && !(features & NETIF_F_SG)) { | 5036 | if ((features & NETIF_F_TSO) && !(features & NETIF_F_SG)) { |
5034 | if (name) | 5037 | if (name) |
5035 | printk(KERN_NOTICE "%s: Dropping NETIF_F_TSO since no " | 5038 | printk(KERN_NOTICE "%s: Dropping NETIF_F_TSO since no " |
5036 | "SG feature.\n", name); | 5039 | "SG feature.\n", name); |
5037 | features &= ~NETIF_F_TSO; | 5040 | features &= ~NETIF_F_TSO; |
5038 | } | 5041 | } |
5039 | 5042 | ||
5040 | if (features & NETIF_F_UFO) { | 5043 | if (features & NETIF_F_UFO) { |
5041 | if (!(features & NETIF_F_GEN_CSUM)) { | 5044 | if (!(features & NETIF_F_GEN_CSUM)) { |
5042 | if (name) | 5045 | if (name) |
5043 | printk(KERN_ERR "%s: Dropping NETIF_F_UFO " | 5046 | printk(KERN_ERR "%s: Dropping NETIF_F_UFO " |
5044 | "since no NETIF_F_HW_CSUM feature.\n", | 5047 | "since no NETIF_F_HW_CSUM feature.\n", |
5045 | name); | 5048 | name); |
5046 | features &= ~NETIF_F_UFO; | 5049 | features &= ~NETIF_F_UFO; |
5047 | } | 5050 | } |
5048 | 5051 | ||
5049 | if (!(features & NETIF_F_SG)) { | 5052 | if (!(features & NETIF_F_SG)) { |
5050 | if (name) | 5053 | if (name) |
5051 | printk(KERN_ERR "%s: Dropping NETIF_F_UFO " | 5054 | printk(KERN_ERR "%s: Dropping NETIF_F_UFO " |
5052 | "since no NETIF_F_SG feature.\n", name); | 5055 | "since no NETIF_F_SG feature.\n", name); |
5053 | features &= ~NETIF_F_UFO; | 5056 | features &= ~NETIF_F_UFO; |
5054 | } | 5057 | } |
5055 | } | 5058 | } |
5056 | 5059 | ||
5057 | return features; | 5060 | return features; |
5058 | } | 5061 | } |
5059 | EXPORT_SYMBOL(netdev_fix_features); | 5062 | EXPORT_SYMBOL(netdev_fix_features); |
5060 | 5063 | ||
5061 | /** | 5064 | /** |
5062 | * netif_stacked_transfer_operstate - transfer operstate | 5065 | * netif_stacked_transfer_operstate - transfer operstate |
5063 | * @rootdev: the root or lower level device to transfer state from | 5066 | * @rootdev: the root or lower level device to transfer state from |
5064 | * @dev: the device to transfer operstate to | 5067 | * @dev: the device to transfer operstate to |
5065 | * | 5068 | * |
5066 | * Transfer operational state from root to device. This is normally | 5069 | * Transfer operational state from root to device. This is normally |
5067 | * called when a stacking relationship exists between the root | 5070 | * called when a stacking relationship exists between the root |
5068 | * device and the device(a leaf device). | 5071 | * device and the device(a leaf device). |
5069 | */ | 5072 | */ |
5070 | void netif_stacked_transfer_operstate(const struct net_device *rootdev, | 5073 | void netif_stacked_transfer_operstate(const struct net_device *rootdev, |
5071 | struct net_device *dev) | 5074 | struct net_device *dev) |
5072 | { | 5075 | { |
5073 | if (rootdev->operstate == IF_OPER_DORMANT) | 5076 | if (rootdev->operstate == IF_OPER_DORMANT) |
5074 | netif_dormant_on(dev); | 5077 | netif_dormant_on(dev); |
5075 | else | 5078 | else |
5076 | netif_dormant_off(dev); | 5079 | netif_dormant_off(dev); |
5077 | 5080 | ||
5078 | if (netif_carrier_ok(rootdev)) { | 5081 | if (netif_carrier_ok(rootdev)) { |
5079 | if (!netif_carrier_ok(dev)) | 5082 | if (!netif_carrier_ok(dev)) |
5080 | netif_carrier_on(dev); | 5083 | netif_carrier_on(dev); |
5081 | } else { | 5084 | } else { |
5082 | if (netif_carrier_ok(dev)) | 5085 | if (netif_carrier_ok(dev)) |
5083 | netif_carrier_off(dev); | 5086 | netif_carrier_off(dev); |
5084 | } | 5087 | } |
5085 | } | 5088 | } |
5086 | EXPORT_SYMBOL(netif_stacked_transfer_operstate); | 5089 | EXPORT_SYMBOL(netif_stacked_transfer_operstate); |
5087 | 5090 | ||
5091 | #ifdef CONFIG_RPS | ||
5088 | static int netif_alloc_rx_queues(struct net_device *dev) | 5092 | static int netif_alloc_rx_queues(struct net_device *dev) |
5089 | { | 5093 | { |
5090 | #ifdef CONFIG_RPS | ||
5091 | unsigned int i, count = dev->num_rx_queues; | 5094 | unsigned int i, count = dev->num_rx_queues; |
5092 | struct netdev_rx_queue *rx; | 5095 | struct netdev_rx_queue *rx; |
5093 | 5096 | ||
5094 | BUG_ON(count < 1); | 5097 | BUG_ON(count < 1); |
5095 | 5098 | ||
5096 | rx = kcalloc(count, sizeof(struct netdev_rx_queue), GFP_KERNEL); | 5099 | rx = kcalloc(count, sizeof(struct netdev_rx_queue), GFP_KERNEL); |
5097 | if (!rx) { | 5100 | if (!rx) { |
5098 | pr_err("netdev: Unable to allocate %u rx queues.\n", count); | 5101 | pr_err("netdev: Unable to allocate %u rx queues.\n", count); |
5099 | return -ENOMEM; | 5102 | return -ENOMEM; |
5100 | } | 5103 | } |
5101 | dev->_rx = rx; | 5104 | dev->_rx = rx; |
5102 | 5105 | ||
5103 | for (i = 0; i < count; i++) | 5106 | for (i = 0; i < count; i++) |
5104 | rx[i].dev = dev; | 5107 | rx[i].dev = dev; |
5105 | #endif | ||
5106 | return 0; | 5108 | return 0; |
5107 | } | 5109 | } |
5110 | #endif | ||
5108 | 5111 | ||
5109 | static int netif_alloc_netdev_queues(struct net_device *dev) | 5112 | static int netif_alloc_netdev_queues(struct net_device *dev) |
5110 | { | 5113 | { |
5111 | unsigned int count = dev->num_tx_queues; | 5114 | unsigned int count = dev->num_tx_queues; |
5112 | struct netdev_queue *tx; | 5115 | struct netdev_queue *tx; |
5113 | int i; | 5116 | int i; |
5114 | 5117 | ||
5115 | BUG_ON(count < 1); | 5118 | BUG_ON(count < 1); |
5116 | 5119 | ||
5117 | tx = kcalloc(count, sizeof(struct netdev_queue), GFP_KERNEL); | 5120 | tx = kcalloc(count, sizeof(struct netdev_queue), GFP_KERNEL); |
5118 | if (!tx) { | 5121 | if (!tx) { |
5119 | pr_err("netdev: Unable to allocate %u tx queues.\n", | 5122 | pr_err("netdev: Unable to allocate %u tx queues.\n", |
5120 | count); | 5123 | count); |
5121 | return -ENOMEM; | 5124 | return -ENOMEM; |
5122 | } | 5125 | } |
5123 | dev->_tx = tx; | 5126 | dev->_tx = tx; |
5124 | 5127 | ||
5125 | for (i = 0; i < count; i++) | 5128 | for (i = 0; i < count; i++) |
5126 | tx[i].dev = dev; | 5129 | tx[i].dev = dev; |
5127 | 5130 | ||
5128 | return 0; | 5131 | return 0; |
5129 | } | 5132 | } |
5130 | 5133 | ||
5131 | static void netdev_init_one_queue(struct net_device *dev, | 5134 | static void netdev_init_one_queue(struct net_device *dev, |
5132 | struct netdev_queue *queue, | 5135 | struct netdev_queue *queue, |
5133 | void *_unused) | 5136 | void *_unused) |
5134 | { | 5137 | { |
5135 | /* Initialize queue lock */ | 5138 | /* Initialize queue lock */ |
5136 | spin_lock_init(&queue->_xmit_lock); | 5139 | spin_lock_init(&queue->_xmit_lock); |
5137 | netdev_set_xmit_lockdep_class(&queue->_xmit_lock, dev->type); | 5140 | netdev_set_xmit_lockdep_class(&queue->_xmit_lock, dev->type); |
5138 | queue->xmit_lock_owner = -1; | 5141 | queue->xmit_lock_owner = -1; |
5139 | } | 5142 | } |
5140 | 5143 | ||
5141 | static void netdev_init_queues(struct net_device *dev) | 5144 | static void netdev_init_queues(struct net_device *dev) |
5142 | { | 5145 | { |
5143 | netdev_for_each_tx_queue(dev, netdev_init_one_queue, NULL); | 5146 | netdev_for_each_tx_queue(dev, netdev_init_one_queue, NULL); |
5144 | spin_lock_init(&dev->tx_global_lock); | 5147 | spin_lock_init(&dev->tx_global_lock); |
5145 | } | 5148 | } |
5146 | 5149 | ||
5147 | /** | 5150 | /** |
5148 | * register_netdevice - register a network device | 5151 | * register_netdevice - register a network device |
5149 | * @dev: device to register | 5152 | * @dev: device to register |
5150 | * | 5153 | * |
5151 | * Take a completed network device structure and add it to the kernel | 5154 | * Take a completed network device structure and add it to the kernel |
5152 | * interfaces. A %NETDEV_REGISTER message is sent to the netdev notifier | 5155 | * interfaces. A %NETDEV_REGISTER message is sent to the netdev notifier |
5153 | * chain. 0 is returned on success. A negative errno code is returned | 5156 | * chain. 0 is returned on success. A negative errno code is returned |
5154 | * on a failure to set up the device, or if the name is a duplicate. | 5157 | * on a failure to set up the device, or if the name is a duplicate. |
5155 | * | 5158 | * |
5156 | * Callers must hold the rtnl semaphore. You may want | 5159 | * Callers must hold the rtnl semaphore. You may want |
5157 | * register_netdev() instead of this. | 5160 | * register_netdev() instead of this. |
5158 | * | 5161 | * |
5159 | * BUGS: | 5162 | * BUGS: |
5160 | * The locking appears insufficient to guarantee two parallel registers | 5163 | * The locking appears insufficient to guarantee two parallel registers |
5161 | * will not get the same name. | 5164 | * will not get the same name. |
5162 | */ | 5165 | */ |
5163 | 5166 | ||
5164 | int register_netdevice(struct net_device *dev) | 5167 | int register_netdevice(struct net_device *dev) |
5165 | { | 5168 | { |
5166 | int ret; | 5169 | int ret; |
5167 | struct net *net = dev_net(dev); | 5170 | struct net *net = dev_net(dev); |
5168 | 5171 | ||
5169 | BUG_ON(dev_boot_phase); | 5172 | BUG_ON(dev_boot_phase); |
5170 | ASSERT_RTNL(); | 5173 | ASSERT_RTNL(); |
5171 | 5174 | ||
5172 | might_sleep(); | 5175 | might_sleep(); |
5173 | 5176 | ||
5174 | /* When net_device's are persistent, this will be fatal. */ | 5177 | /* When net_device's are persistent, this will be fatal. */ |
5175 | BUG_ON(dev->reg_state != NETREG_UNINITIALIZED); | 5178 | BUG_ON(dev->reg_state != NETREG_UNINITIALIZED); |
5176 | BUG_ON(!net); | 5179 | BUG_ON(!net); |
5177 | 5180 | ||
5178 | spin_lock_init(&dev->addr_list_lock); | 5181 | spin_lock_init(&dev->addr_list_lock); |
5179 | netdev_set_addr_lockdep_class(dev); | 5182 | netdev_set_addr_lockdep_class(dev); |
5180 | 5183 | ||
5181 | dev->iflink = -1; | 5184 | dev->iflink = -1; |
5182 | 5185 | ||
5183 | netdev_init_queues(dev); | 5186 | netdev_init_queues(dev); |
5184 | 5187 | ||
5185 | /* Init, if this function is available */ | 5188 | /* Init, if this function is available */ |
5186 | if (dev->netdev_ops->ndo_init) { | 5189 | if (dev->netdev_ops->ndo_init) { |
5187 | ret = dev->netdev_ops->ndo_init(dev); | 5190 | ret = dev->netdev_ops->ndo_init(dev); |
5188 | if (ret) { | 5191 | if (ret) { |
5189 | if (ret > 0) | 5192 | if (ret > 0) |
5190 | ret = -EIO; | 5193 | ret = -EIO; |
5191 | goto out; | 5194 | goto out; |
5192 | } | 5195 | } |
5193 | } | 5196 | } |
5194 | 5197 | ||
5195 | ret = dev_get_valid_name(dev, dev->name, 0); | 5198 | ret = dev_get_valid_name(dev, dev->name, 0); |
5196 | if (ret) | 5199 | if (ret) |
5197 | goto err_uninit; | 5200 | goto err_uninit; |
5198 | 5201 | ||
5199 | dev->ifindex = dev_new_index(net); | 5202 | dev->ifindex = dev_new_index(net); |
5200 | if (dev->iflink == -1) | 5203 | if (dev->iflink == -1) |
5201 | dev->iflink = dev->ifindex; | 5204 | dev->iflink = dev->ifindex; |
5202 | 5205 | ||
5203 | /* Fix illegal checksum combinations */ | 5206 | /* Fix illegal checksum combinations */ |
5204 | if ((dev->features & NETIF_F_HW_CSUM) && | 5207 | if ((dev->features & NETIF_F_HW_CSUM) && |
5205 | (dev->features & (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))) { | 5208 | (dev->features & (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))) { |
5206 | printk(KERN_NOTICE "%s: mixed HW and IP checksum settings.\n", | 5209 | printk(KERN_NOTICE "%s: mixed HW and IP checksum settings.\n", |
5207 | dev->name); | 5210 | dev->name); |
5208 | dev->features &= ~(NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM); | 5211 | dev->features &= ~(NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM); |
5209 | } | 5212 | } |
5210 | 5213 | ||
5211 | if ((dev->features & NETIF_F_NO_CSUM) && | 5214 | if ((dev->features & NETIF_F_NO_CSUM) && |
5212 | (dev->features & (NETIF_F_HW_CSUM|NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))) { | 5215 | (dev->features & (NETIF_F_HW_CSUM|NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))) { |
5213 | printk(KERN_NOTICE "%s: mixed no checksumming and other settings.\n", | 5216 | printk(KERN_NOTICE "%s: mixed no checksumming and other settings.\n", |
5214 | dev->name); | 5217 | dev->name); |
5215 | dev->features &= ~(NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM|NETIF_F_HW_CSUM); | 5218 | dev->features &= ~(NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM|NETIF_F_HW_CSUM); |
5216 | } | 5219 | } |
5217 | 5220 | ||
5218 | dev->features = netdev_fix_features(dev->features, dev->name); | 5221 | dev->features = netdev_fix_features(dev->features, dev->name); |
5219 | 5222 | ||
5220 | /* Enable software GSO if SG is supported. */ | 5223 | /* Enable software GSO if SG is supported. */ |
5221 | if (dev->features & NETIF_F_SG) | 5224 | if (dev->features & NETIF_F_SG) |
5222 | dev->features |= NETIF_F_GSO; | 5225 | dev->features |= NETIF_F_GSO; |
5223 | 5226 | ||
5224 | /* Enable GRO and NETIF_F_HIGHDMA for vlans by default, | 5227 | /* Enable GRO and NETIF_F_HIGHDMA for vlans by default, |
5225 | * vlan_dev_init() will do the dev->features check, so these features | 5228 | * vlan_dev_init() will do the dev->features check, so these features |
5226 | * are enabled only if supported by underlying device. | 5229 | * are enabled only if supported by underlying device. |
5227 | */ | 5230 | */ |
5228 | dev->vlan_features |= (NETIF_F_GRO | NETIF_F_HIGHDMA); | 5231 | dev->vlan_features |= (NETIF_F_GRO | NETIF_F_HIGHDMA); |
5229 | 5232 | ||
5230 | ret = call_netdevice_notifiers(NETDEV_POST_INIT, dev); | 5233 | ret = call_netdevice_notifiers(NETDEV_POST_INIT, dev); |
5231 | ret = notifier_to_errno(ret); | 5234 | ret = notifier_to_errno(ret); |
5232 | if (ret) | 5235 | if (ret) |
5233 | goto err_uninit; | 5236 | goto err_uninit; |
5234 | 5237 | ||
5235 | ret = netdev_register_kobject(dev); | 5238 | ret = netdev_register_kobject(dev); |
5236 | if (ret) | 5239 | if (ret) |
5237 | goto err_uninit; | 5240 | goto err_uninit; |
5238 | dev->reg_state = NETREG_REGISTERED; | 5241 | dev->reg_state = NETREG_REGISTERED; |
5239 | 5242 | ||
5240 | /* | 5243 | /* |
5241 | * Default initial state at registry is that the | 5244 | * Default initial state at registry is that the |
5242 | * device is present. | 5245 | * device is present. |
5243 | */ | 5246 | */ |
5244 | 5247 | ||
5245 | set_bit(__LINK_STATE_PRESENT, &dev->state); | 5248 | set_bit(__LINK_STATE_PRESENT, &dev->state); |
5246 | 5249 | ||
5247 | dev_init_scheduler(dev); | 5250 | dev_init_scheduler(dev); |
5248 | dev_hold(dev); | 5251 | dev_hold(dev); |
5249 | list_netdevice(dev); | 5252 | list_netdevice(dev); |
5250 | 5253 | ||
5251 | /* Notify protocols, that a new device appeared. */ | 5254 | /* Notify protocols, that a new device appeared. */ |
5252 | ret = call_netdevice_notifiers(NETDEV_REGISTER, dev); | 5255 | ret = call_netdevice_notifiers(NETDEV_REGISTER, dev); |
5253 | ret = notifier_to_errno(ret); | 5256 | ret = notifier_to_errno(ret); |
5254 | if (ret) { | 5257 | if (ret) { |
5255 | rollback_registered(dev); | 5258 | rollback_registered(dev); |
5256 | dev->reg_state = NETREG_UNREGISTERED; | 5259 | dev->reg_state = NETREG_UNREGISTERED; |
5257 | } | 5260 | } |
5258 | /* | 5261 | /* |
5259 | * Prevent userspace races by waiting until the network | 5262 | * Prevent userspace races by waiting until the network |
5260 | * device is fully setup before sending notifications. | 5263 | * device is fully setup before sending notifications. |
5261 | */ | 5264 | */ |
5262 | if (!dev->rtnl_link_ops || | 5265 | if (!dev->rtnl_link_ops || |
5263 | dev->rtnl_link_state == RTNL_LINK_INITIALIZED) | 5266 | dev->rtnl_link_state == RTNL_LINK_INITIALIZED) |
5264 | rtmsg_ifinfo(RTM_NEWLINK, dev, ~0U); | 5267 | rtmsg_ifinfo(RTM_NEWLINK, dev, ~0U); |
5265 | 5268 | ||
5266 | out: | 5269 | out: |
5267 | return ret; | 5270 | return ret; |
5268 | 5271 | ||
5269 | err_uninit: | 5272 | err_uninit: |
5270 | if (dev->netdev_ops->ndo_uninit) | 5273 | if (dev->netdev_ops->ndo_uninit) |
5271 | dev->netdev_ops->ndo_uninit(dev); | 5274 | dev->netdev_ops->ndo_uninit(dev); |
5272 | goto out; | 5275 | goto out; |
5273 | } | 5276 | } |
5274 | EXPORT_SYMBOL(register_netdevice); | 5277 | EXPORT_SYMBOL(register_netdevice); |
5275 | 5278 | ||
5276 | /** | 5279 | /** |
5277 | * init_dummy_netdev - init a dummy network device for NAPI | 5280 | * init_dummy_netdev - init a dummy network device for NAPI |
5278 | * @dev: device to init | 5281 | * @dev: device to init |
5279 | * | 5282 | * |
5280 | * This takes a network device structure and initialize the minimum | 5283 | * This takes a network device structure and initialize the minimum |
5281 | * amount of fields so it can be used to schedule NAPI polls without | 5284 | * amount of fields so it can be used to schedule NAPI polls without |
5282 | * registering a full blown interface. This is to be used by drivers | 5285 | * registering a full blown interface. This is to be used by drivers |
5283 | * that need to tie several hardware interfaces to a single NAPI | 5286 | * that need to tie several hardware interfaces to a single NAPI |
5284 | * poll scheduler due to HW limitations. | 5287 | * poll scheduler due to HW limitations. |
5285 | */ | 5288 | */ |
5286 | int init_dummy_netdev(struct net_device *dev) | 5289 | int init_dummy_netdev(struct net_device *dev) |
5287 | { | 5290 | { |
5288 | /* Clear everything. Note we don't initialize spinlocks | 5291 | /* Clear everything. Note we don't initialize spinlocks |
5289 | * are they aren't supposed to be taken by any of the | 5292 | * are they aren't supposed to be taken by any of the |
5290 | * NAPI code and this dummy netdev is supposed to be | 5293 | * NAPI code and this dummy netdev is supposed to be |
5291 | * only ever used for NAPI polls | 5294 | * only ever used for NAPI polls |
5292 | */ | 5295 | */ |
5293 | memset(dev, 0, sizeof(struct net_device)); | 5296 | memset(dev, 0, sizeof(struct net_device)); |
5294 | 5297 | ||
5295 | /* make sure we BUG if trying to hit standard | 5298 | /* make sure we BUG if trying to hit standard |
5296 | * register/unregister code path | 5299 | * register/unregister code path |
5297 | */ | 5300 | */ |
5298 | dev->reg_state = NETREG_DUMMY; | 5301 | dev->reg_state = NETREG_DUMMY; |
5299 | 5302 | ||
5300 | /* NAPI wants this */ | 5303 | /* NAPI wants this */ |
5301 | INIT_LIST_HEAD(&dev->napi_list); | 5304 | INIT_LIST_HEAD(&dev->napi_list); |
5302 | 5305 | ||
5303 | /* a dummy interface is started by default */ | 5306 | /* a dummy interface is started by default */ |
5304 | set_bit(__LINK_STATE_PRESENT, &dev->state); | 5307 | set_bit(__LINK_STATE_PRESENT, &dev->state); |
5305 | set_bit(__LINK_STATE_START, &dev->state); | 5308 | set_bit(__LINK_STATE_START, &dev->state); |
5306 | 5309 | ||
5307 | /* Note : We dont allocate pcpu_refcnt for dummy devices, | 5310 | /* Note : We dont allocate pcpu_refcnt for dummy devices, |
5308 | * because users of this 'device' dont need to change | 5311 | * because users of this 'device' dont need to change |
5309 | * its refcount. | 5312 | * its refcount. |
5310 | */ | 5313 | */ |
5311 | 5314 | ||
5312 | return 0; | 5315 | return 0; |
5313 | } | 5316 | } |
5314 | EXPORT_SYMBOL_GPL(init_dummy_netdev); | 5317 | EXPORT_SYMBOL_GPL(init_dummy_netdev); |
5315 | 5318 | ||
5316 | 5319 | ||
5317 | /** | 5320 | /** |
5318 | * register_netdev - register a network device | 5321 | * register_netdev - register a network device |
5319 | * @dev: device to register | 5322 | * @dev: device to register |
5320 | * | 5323 | * |
5321 | * Take a completed network device structure and add it to the kernel | 5324 | * Take a completed network device structure and add it to the kernel |
5322 | * interfaces. A %NETDEV_REGISTER message is sent to the netdev notifier | 5325 | * interfaces. A %NETDEV_REGISTER message is sent to the netdev notifier |
5323 | * chain. 0 is returned on success. A negative errno code is returned | 5326 | * chain. 0 is returned on success. A negative errno code is returned |
5324 | * on a failure to set up the device, or if the name is a duplicate. | 5327 | * on a failure to set up the device, or if the name is a duplicate. |
5325 | * | 5328 | * |
5326 | * This is a wrapper around register_netdevice that takes the rtnl semaphore | 5329 | * This is a wrapper around register_netdevice that takes the rtnl semaphore |
5327 | * and expands the device name if you passed a format string to | 5330 | * and expands the device name if you passed a format string to |
5328 | * alloc_netdev. | 5331 | * alloc_netdev. |
5329 | */ | 5332 | */ |
5330 | int register_netdev(struct net_device *dev) | 5333 | int register_netdev(struct net_device *dev) |
5331 | { | 5334 | { |
5332 | int err; | 5335 | int err; |
5333 | 5336 | ||
5334 | rtnl_lock(); | 5337 | rtnl_lock(); |
5335 | 5338 | ||
5336 | /* | 5339 | /* |
5337 | * If the name is a format string the caller wants us to do a | 5340 | * If the name is a format string the caller wants us to do a |
5338 | * name allocation. | 5341 | * name allocation. |
5339 | */ | 5342 | */ |
5340 | if (strchr(dev->name, '%')) { | 5343 | if (strchr(dev->name, '%')) { |
5341 | err = dev_alloc_name(dev, dev->name); | 5344 | err = dev_alloc_name(dev, dev->name); |
5342 | if (err < 0) | 5345 | if (err < 0) |
5343 | goto out; | 5346 | goto out; |
5344 | } | 5347 | } |
5345 | 5348 | ||
5346 | err = register_netdevice(dev); | 5349 | err = register_netdevice(dev); |
5347 | out: | 5350 | out: |
5348 | rtnl_unlock(); | 5351 | rtnl_unlock(); |
5349 | return err; | 5352 | return err; |
5350 | } | 5353 | } |
5351 | EXPORT_SYMBOL(register_netdev); | 5354 | EXPORT_SYMBOL(register_netdev); |
5352 | 5355 | ||
5353 | int netdev_refcnt_read(const struct net_device *dev) | 5356 | int netdev_refcnt_read(const struct net_device *dev) |
5354 | { | 5357 | { |
5355 | int i, refcnt = 0; | 5358 | int i, refcnt = 0; |
5356 | 5359 | ||
5357 | for_each_possible_cpu(i) | 5360 | for_each_possible_cpu(i) |
5358 | refcnt += *per_cpu_ptr(dev->pcpu_refcnt, i); | 5361 | refcnt += *per_cpu_ptr(dev->pcpu_refcnt, i); |
5359 | return refcnt; | 5362 | return refcnt; |
5360 | } | 5363 | } |
5361 | EXPORT_SYMBOL(netdev_refcnt_read); | 5364 | EXPORT_SYMBOL(netdev_refcnt_read); |
5362 | 5365 | ||
5363 | /* | 5366 | /* |
5364 | * netdev_wait_allrefs - wait until all references are gone. | 5367 | * netdev_wait_allrefs - wait until all references are gone. |
5365 | * | 5368 | * |
5366 | * This is called when unregistering network devices. | 5369 | * This is called when unregistering network devices. |
5367 | * | 5370 | * |
5368 | * Any protocol or device that holds a reference should register | 5371 | * Any protocol or device that holds a reference should register |
5369 | * for netdevice notification, and cleanup and put back the | 5372 | * for netdevice notification, and cleanup and put back the |
5370 | * reference if they receive an UNREGISTER event. | 5373 | * reference if they receive an UNREGISTER event. |
5371 | * We can get stuck here if buggy protocols don't correctly | 5374 | * We can get stuck here if buggy protocols don't correctly |
5372 | * call dev_put. | 5375 | * call dev_put. |
5373 | */ | 5376 | */ |
5374 | static void netdev_wait_allrefs(struct net_device *dev) | 5377 | static void netdev_wait_allrefs(struct net_device *dev) |
5375 | { | 5378 | { |
5376 | unsigned long rebroadcast_time, warning_time; | 5379 | unsigned long rebroadcast_time, warning_time; |
5377 | int refcnt; | 5380 | int refcnt; |
5378 | 5381 | ||
5379 | linkwatch_forget_dev(dev); | 5382 | linkwatch_forget_dev(dev); |
5380 | 5383 | ||
5381 | rebroadcast_time = warning_time = jiffies; | 5384 | rebroadcast_time = warning_time = jiffies; |
5382 | refcnt = netdev_refcnt_read(dev); | 5385 | refcnt = netdev_refcnt_read(dev); |
5383 | 5386 | ||
5384 | while (refcnt != 0) { | 5387 | while (refcnt != 0) { |
5385 | if (time_after(jiffies, rebroadcast_time + 1 * HZ)) { | 5388 | if (time_after(jiffies, rebroadcast_time + 1 * HZ)) { |
5386 | rtnl_lock(); | 5389 | rtnl_lock(); |
5387 | 5390 | ||
5388 | /* Rebroadcast unregister notification */ | 5391 | /* Rebroadcast unregister notification */ |
5389 | call_netdevice_notifiers(NETDEV_UNREGISTER, dev); | 5392 | call_netdevice_notifiers(NETDEV_UNREGISTER, dev); |
5390 | /* don't resend NETDEV_UNREGISTER_BATCH, _BATCH users | 5393 | /* don't resend NETDEV_UNREGISTER_BATCH, _BATCH users |
5391 | * should have already handle it the first time */ | 5394 | * should have already handle it the first time */ |
5392 | 5395 | ||
5393 | if (test_bit(__LINK_STATE_LINKWATCH_PENDING, | 5396 | if (test_bit(__LINK_STATE_LINKWATCH_PENDING, |
5394 | &dev->state)) { | 5397 | &dev->state)) { |
5395 | /* We must not have linkwatch events | 5398 | /* We must not have linkwatch events |
5396 | * pending on unregister. If this | 5399 | * pending on unregister. If this |
5397 | * happens, we simply run the queue | 5400 | * happens, we simply run the queue |
5398 | * unscheduled, resulting in a noop | 5401 | * unscheduled, resulting in a noop |
5399 | * for this device. | 5402 | * for this device. |
5400 | */ | 5403 | */ |
5401 | linkwatch_run_queue(); | 5404 | linkwatch_run_queue(); |
5402 | } | 5405 | } |
5403 | 5406 | ||
5404 | __rtnl_unlock(); | 5407 | __rtnl_unlock(); |
5405 | 5408 | ||
5406 | rebroadcast_time = jiffies; | 5409 | rebroadcast_time = jiffies; |
5407 | } | 5410 | } |
5408 | 5411 | ||
5409 | msleep(250); | 5412 | msleep(250); |
5410 | 5413 | ||
5411 | refcnt = netdev_refcnt_read(dev); | 5414 | refcnt = netdev_refcnt_read(dev); |
5412 | 5415 | ||
5413 | if (time_after(jiffies, warning_time + 10 * HZ)) { | 5416 | if (time_after(jiffies, warning_time + 10 * HZ)) { |
5414 | printk(KERN_EMERG "unregister_netdevice: " | 5417 | printk(KERN_EMERG "unregister_netdevice: " |
5415 | "waiting for %s to become free. Usage " | 5418 | "waiting for %s to become free. Usage " |
5416 | "count = %d\n", | 5419 | "count = %d\n", |
5417 | dev->name, refcnt); | 5420 | dev->name, refcnt); |
5418 | warning_time = jiffies; | 5421 | warning_time = jiffies; |
5419 | } | 5422 | } |
5420 | } | 5423 | } |
5421 | } | 5424 | } |
5422 | 5425 | ||
5423 | /* The sequence is: | 5426 | /* The sequence is: |
5424 | * | 5427 | * |
5425 | * rtnl_lock(); | 5428 | * rtnl_lock(); |
5426 | * ... | 5429 | * ... |
5427 | * register_netdevice(x1); | 5430 | * register_netdevice(x1); |
5428 | * register_netdevice(x2); | 5431 | * register_netdevice(x2); |
5429 | * ... | 5432 | * ... |
5430 | * unregister_netdevice(y1); | 5433 | * unregister_netdevice(y1); |
5431 | * unregister_netdevice(y2); | 5434 | * unregister_netdevice(y2); |
5432 | * ... | 5435 | * ... |
5433 | * rtnl_unlock(); | 5436 | * rtnl_unlock(); |
5434 | * free_netdev(y1); | 5437 | * free_netdev(y1); |
5435 | * free_netdev(y2); | 5438 | * free_netdev(y2); |
5436 | * | 5439 | * |
5437 | * We are invoked by rtnl_unlock(). | 5440 | * We are invoked by rtnl_unlock(). |
5438 | * This allows us to deal with problems: | 5441 | * This allows us to deal with problems: |
5439 | * 1) We can delete sysfs objects which invoke hotplug | 5442 | * 1) We can delete sysfs objects which invoke hotplug |
5440 | * without deadlocking with linkwatch via keventd. | 5443 | * without deadlocking with linkwatch via keventd. |
5441 | * 2) Since we run with the RTNL semaphore not held, we can sleep | 5444 | * 2) Since we run with the RTNL semaphore not held, we can sleep |
5442 | * safely in order to wait for the netdev refcnt to drop to zero. | 5445 | * safely in order to wait for the netdev refcnt to drop to zero. |
5443 | * | 5446 | * |
5444 | * We must not return until all unregister events added during | 5447 | * We must not return until all unregister events added during |
5445 | * the interval the lock was held have been completed. | 5448 | * the interval the lock was held have been completed. |
5446 | */ | 5449 | */ |
5447 | void netdev_run_todo(void) | 5450 | void netdev_run_todo(void) |
5448 | { | 5451 | { |
5449 | struct list_head list; | 5452 | struct list_head list; |
5450 | 5453 | ||
5451 | /* Snapshot list, allow later requests */ | 5454 | /* Snapshot list, allow later requests */ |
5452 | list_replace_init(&net_todo_list, &list); | 5455 | list_replace_init(&net_todo_list, &list); |
5453 | 5456 | ||
5454 | __rtnl_unlock(); | 5457 | __rtnl_unlock(); |
5455 | 5458 | ||
5456 | while (!list_empty(&list)) { | 5459 | while (!list_empty(&list)) { |
5457 | struct net_device *dev | 5460 | struct net_device *dev |
5458 | = list_first_entry(&list, struct net_device, todo_list); | 5461 | = list_first_entry(&list, struct net_device, todo_list); |
5459 | list_del(&dev->todo_list); | 5462 | list_del(&dev->todo_list); |
5460 | 5463 | ||
5461 | if (unlikely(dev->reg_state != NETREG_UNREGISTERING)) { | 5464 | if (unlikely(dev->reg_state != NETREG_UNREGISTERING)) { |
5462 | printk(KERN_ERR "network todo '%s' but state %d\n", | 5465 | printk(KERN_ERR "network todo '%s' but state %d\n", |
5463 | dev->name, dev->reg_state); | 5466 | dev->name, dev->reg_state); |
5464 | dump_stack(); | 5467 | dump_stack(); |
5465 | continue; | 5468 | continue; |
5466 | } | 5469 | } |
5467 | 5470 | ||
5468 | dev->reg_state = NETREG_UNREGISTERED; | 5471 | dev->reg_state = NETREG_UNREGISTERED; |
5469 | 5472 | ||
5470 | on_each_cpu(flush_backlog, dev, 1); | 5473 | on_each_cpu(flush_backlog, dev, 1); |
5471 | 5474 | ||
5472 | netdev_wait_allrefs(dev); | 5475 | netdev_wait_allrefs(dev); |
5473 | 5476 | ||
5474 | /* paranoia */ | 5477 | /* paranoia */ |
5475 | BUG_ON(netdev_refcnt_read(dev)); | 5478 | BUG_ON(netdev_refcnt_read(dev)); |
5476 | WARN_ON(rcu_dereference_raw(dev->ip_ptr)); | 5479 | WARN_ON(rcu_dereference_raw(dev->ip_ptr)); |
5477 | WARN_ON(rcu_dereference_raw(dev->ip6_ptr)); | 5480 | WARN_ON(rcu_dereference_raw(dev->ip6_ptr)); |
5478 | WARN_ON(dev->dn_ptr); | 5481 | WARN_ON(dev->dn_ptr); |
5479 | 5482 | ||
5480 | if (dev->destructor) | 5483 | if (dev->destructor) |
5481 | dev->destructor(dev); | 5484 | dev->destructor(dev); |
5482 | 5485 | ||
5483 | /* Free network device */ | 5486 | /* Free network device */ |
5484 | kobject_put(&dev->dev.kobj); | 5487 | kobject_put(&dev->dev.kobj); |
5485 | } | 5488 | } |
5486 | } | 5489 | } |
5487 | 5490 | ||
5488 | /** | 5491 | /** |
5489 | * dev_txq_stats_fold - fold tx_queues stats | 5492 | * dev_txq_stats_fold - fold tx_queues stats |
5490 | * @dev: device to get statistics from | 5493 | * @dev: device to get statistics from |
5491 | * @stats: struct rtnl_link_stats64 to hold results | 5494 | * @stats: struct rtnl_link_stats64 to hold results |
5492 | */ | 5495 | */ |
5493 | void dev_txq_stats_fold(const struct net_device *dev, | 5496 | void dev_txq_stats_fold(const struct net_device *dev, |
5494 | struct rtnl_link_stats64 *stats) | 5497 | struct rtnl_link_stats64 *stats) |
5495 | { | 5498 | { |
5496 | u64 tx_bytes = 0, tx_packets = 0, tx_dropped = 0; | 5499 | u64 tx_bytes = 0, tx_packets = 0, tx_dropped = 0; |
5497 | unsigned int i; | 5500 | unsigned int i; |
5498 | struct netdev_queue *txq; | 5501 | struct netdev_queue *txq; |
5499 | 5502 | ||
5500 | for (i = 0; i < dev->num_tx_queues; i++) { | 5503 | for (i = 0; i < dev->num_tx_queues; i++) { |
5501 | txq = netdev_get_tx_queue(dev, i); | 5504 | txq = netdev_get_tx_queue(dev, i); |
5502 | spin_lock_bh(&txq->_xmit_lock); | 5505 | spin_lock_bh(&txq->_xmit_lock); |
5503 | tx_bytes += txq->tx_bytes; | 5506 | tx_bytes += txq->tx_bytes; |
5504 | tx_packets += txq->tx_packets; | 5507 | tx_packets += txq->tx_packets; |
5505 | tx_dropped += txq->tx_dropped; | 5508 | tx_dropped += txq->tx_dropped; |
5506 | spin_unlock_bh(&txq->_xmit_lock); | 5509 | spin_unlock_bh(&txq->_xmit_lock); |
5507 | } | 5510 | } |
5508 | if (tx_bytes || tx_packets || tx_dropped) { | 5511 | if (tx_bytes || tx_packets || tx_dropped) { |
5509 | stats->tx_bytes = tx_bytes; | 5512 | stats->tx_bytes = tx_bytes; |
5510 | stats->tx_packets = tx_packets; | 5513 | stats->tx_packets = tx_packets; |
5511 | stats->tx_dropped = tx_dropped; | 5514 | stats->tx_dropped = tx_dropped; |
5512 | } | 5515 | } |
5513 | } | 5516 | } |
5514 | EXPORT_SYMBOL(dev_txq_stats_fold); | 5517 | EXPORT_SYMBOL(dev_txq_stats_fold); |
5515 | 5518 | ||
5516 | /* Convert net_device_stats to rtnl_link_stats64. They have the same | 5519 | /* Convert net_device_stats to rtnl_link_stats64. They have the same |
5517 | * fields in the same order, with only the type differing. | 5520 | * fields in the same order, with only the type differing. |
5518 | */ | 5521 | */ |
5519 | static void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64, | 5522 | static void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64, |
5520 | const struct net_device_stats *netdev_stats) | 5523 | const struct net_device_stats *netdev_stats) |
5521 | { | 5524 | { |
5522 | #if BITS_PER_LONG == 64 | 5525 | #if BITS_PER_LONG == 64 |
5523 | BUILD_BUG_ON(sizeof(*stats64) != sizeof(*netdev_stats)); | 5526 | BUILD_BUG_ON(sizeof(*stats64) != sizeof(*netdev_stats)); |
5524 | memcpy(stats64, netdev_stats, sizeof(*stats64)); | 5527 | memcpy(stats64, netdev_stats, sizeof(*stats64)); |
5525 | #else | 5528 | #else |
5526 | size_t i, n = sizeof(*stats64) / sizeof(u64); | 5529 | size_t i, n = sizeof(*stats64) / sizeof(u64); |
5527 | const unsigned long *src = (const unsigned long *)netdev_stats; | 5530 | const unsigned long *src = (const unsigned long *)netdev_stats; |
5528 | u64 *dst = (u64 *)stats64; | 5531 | u64 *dst = (u64 *)stats64; |
5529 | 5532 | ||
5530 | BUILD_BUG_ON(sizeof(*netdev_stats) / sizeof(unsigned long) != | 5533 | BUILD_BUG_ON(sizeof(*netdev_stats) / sizeof(unsigned long) != |
5531 | sizeof(*stats64) / sizeof(u64)); | 5534 | sizeof(*stats64) / sizeof(u64)); |
5532 | for (i = 0; i < n; i++) | 5535 | for (i = 0; i < n; i++) |
5533 | dst[i] = src[i]; | 5536 | dst[i] = src[i]; |
5534 | #endif | 5537 | #endif |
5535 | } | 5538 | } |
5536 | 5539 | ||
5537 | /** | 5540 | /** |
5538 | * dev_get_stats - get network device statistics | 5541 | * dev_get_stats - get network device statistics |
5539 | * @dev: device to get statistics from | 5542 | * @dev: device to get statistics from |
5540 | * @storage: place to store stats | 5543 | * @storage: place to store stats |
5541 | * | 5544 | * |
5542 | * Get network statistics from device. Return @storage. | 5545 | * Get network statistics from device. Return @storage. |
5543 | * The device driver may provide its own method by setting | 5546 | * The device driver may provide its own method by setting |
5544 | * dev->netdev_ops->get_stats64 or dev->netdev_ops->get_stats; | 5547 | * dev->netdev_ops->get_stats64 or dev->netdev_ops->get_stats; |
5545 | * otherwise the internal statistics structure is used. | 5548 | * otherwise the internal statistics structure is used. |
5546 | */ | 5549 | */ |
5547 | struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev, | 5550 | struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev, |
5548 | struct rtnl_link_stats64 *storage) | 5551 | struct rtnl_link_stats64 *storage) |
5549 | { | 5552 | { |
5550 | const struct net_device_ops *ops = dev->netdev_ops; | 5553 | const struct net_device_ops *ops = dev->netdev_ops; |
5551 | 5554 | ||
5552 | if (ops->ndo_get_stats64) { | 5555 | if (ops->ndo_get_stats64) { |
5553 | memset(storage, 0, sizeof(*storage)); | 5556 | memset(storage, 0, sizeof(*storage)); |
5554 | ops->ndo_get_stats64(dev, storage); | 5557 | ops->ndo_get_stats64(dev, storage); |
5555 | } else if (ops->ndo_get_stats) { | 5558 | } else if (ops->ndo_get_stats) { |
5556 | netdev_stats_to_stats64(storage, ops->ndo_get_stats(dev)); | 5559 | netdev_stats_to_stats64(storage, ops->ndo_get_stats(dev)); |
5557 | } else { | 5560 | } else { |
5558 | netdev_stats_to_stats64(storage, &dev->stats); | 5561 | netdev_stats_to_stats64(storage, &dev->stats); |
5559 | dev_txq_stats_fold(dev, storage); | 5562 | dev_txq_stats_fold(dev, storage); |
5560 | } | 5563 | } |
5561 | storage->rx_dropped += atomic_long_read(&dev->rx_dropped); | 5564 | storage->rx_dropped += atomic_long_read(&dev->rx_dropped); |
5562 | return storage; | 5565 | return storage; |
5563 | } | 5566 | } |
5564 | EXPORT_SYMBOL(dev_get_stats); | 5567 | EXPORT_SYMBOL(dev_get_stats); |
5565 | 5568 | ||
5566 | struct netdev_queue *dev_ingress_queue_create(struct net_device *dev) | 5569 | struct netdev_queue *dev_ingress_queue_create(struct net_device *dev) |
5567 | { | 5570 | { |
5568 | struct netdev_queue *queue = dev_ingress_queue(dev); | 5571 | struct netdev_queue *queue = dev_ingress_queue(dev); |
5569 | 5572 | ||
5570 | #ifdef CONFIG_NET_CLS_ACT | 5573 | #ifdef CONFIG_NET_CLS_ACT |
5571 | if (queue) | 5574 | if (queue) |
5572 | return queue; | 5575 | return queue; |
5573 | queue = kzalloc(sizeof(*queue), GFP_KERNEL); | 5576 | queue = kzalloc(sizeof(*queue), GFP_KERNEL); |
5574 | if (!queue) | 5577 | if (!queue) |
5575 | return NULL; | 5578 | return NULL; |
5576 | netdev_init_one_queue(dev, queue, NULL); | 5579 | netdev_init_one_queue(dev, queue, NULL); |
5577 | queue->qdisc = &noop_qdisc; | 5580 | queue->qdisc = &noop_qdisc; |
5578 | queue->qdisc_sleeping = &noop_qdisc; | 5581 | queue->qdisc_sleeping = &noop_qdisc; |
5579 | rcu_assign_pointer(dev->ingress_queue, queue); | 5582 | rcu_assign_pointer(dev->ingress_queue, queue); |
5580 | #endif | 5583 | #endif |
5581 | return queue; | 5584 | return queue; |
5582 | } | 5585 | } |
5583 | 5586 | ||
5584 | /** | 5587 | /** |
5585 | * alloc_netdev_mq - allocate network device | 5588 | * alloc_netdev_mq - allocate network device |
5586 | * @sizeof_priv: size of private data to allocate space for | 5589 | * @sizeof_priv: size of private data to allocate space for |
5587 | * @name: device name format string | 5590 | * @name: device name format string |
5588 | * @setup: callback to initialize device | 5591 | * @setup: callback to initialize device |
5589 | * @queue_count: the number of subqueues to allocate | 5592 | * @queue_count: the number of subqueues to allocate |
5590 | * | 5593 | * |
5591 | * Allocates a struct net_device with private data area for driver use | 5594 | * Allocates a struct net_device with private data area for driver use |
5592 | * and performs basic initialization. Also allocates subquue structs | 5595 | * and performs basic initialization. Also allocates subquue structs |
5593 | * for each queue on the device at the end of the netdevice. | 5596 | * for each queue on the device at the end of the netdevice. |
5594 | */ | 5597 | */ |
5595 | struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name, | 5598 | struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name, |
5596 | void (*setup)(struct net_device *), unsigned int queue_count) | 5599 | void (*setup)(struct net_device *), unsigned int queue_count) |
5597 | { | 5600 | { |
5598 | struct net_device *dev; | 5601 | struct net_device *dev; |
5599 | size_t alloc_size; | 5602 | size_t alloc_size; |
5600 | struct net_device *p; | 5603 | struct net_device *p; |
5601 | 5604 | ||
5602 | BUG_ON(strlen(name) >= sizeof(dev->name)); | 5605 | BUG_ON(strlen(name) >= sizeof(dev->name)); |
5603 | 5606 | ||
5604 | if (queue_count < 1) { | 5607 | if (queue_count < 1) { |
5605 | pr_err("alloc_netdev: Unable to allocate device " | 5608 | pr_err("alloc_netdev: Unable to allocate device " |
5606 | "with zero queues.\n"); | 5609 | "with zero queues.\n"); |
5607 | return NULL; | 5610 | return NULL; |
5608 | } | 5611 | } |
5609 | 5612 | ||
5610 | alloc_size = sizeof(struct net_device); | 5613 | alloc_size = sizeof(struct net_device); |
5611 | if (sizeof_priv) { | 5614 | if (sizeof_priv) { |
5612 | /* ensure 32-byte alignment of private area */ | 5615 | /* ensure 32-byte alignment of private area */ |
5613 | alloc_size = ALIGN(alloc_size, NETDEV_ALIGN); | 5616 | alloc_size = ALIGN(alloc_size, NETDEV_ALIGN); |
5614 | alloc_size += sizeof_priv; | 5617 | alloc_size += sizeof_priv; |
5615 | } | 5618 | } |
5616 | /* ensure 32-byte alignment of whole construct */ | 5619 | /* ensure 32-byte alignment of whole construct */ |
5617 | alloc_size += NETDEV_ALIGN - 1; | 5620 | alloc_size += NETDEV_ALIGN - 1; |
5618 | 5621 | ||
5619 | p = kzalloc(alloc_size, GFP_KERNEL); | 5622 | p = kzalloc(alloc_size, GFP_KERNEL); |
5620 | if (!p) { | 5623 | if (!p) { |
5621 | printk(KERN_ERR "alloc_netdev: Unable to allocate device.\n"); | 5624 | printk(KERN_ERR "alloc_netdev: Unable to allocate device.\n"); |
5622 | return NULL; | 5625 | return NULL; |
5623 | } | 5626 | } |
5624 | 5627 | ||
5625 | dev = PTR_ALIGN(p, NETDEV_ALIGN); | 5628 | dev = PTR_ALIGN(p, NETDEV_ALIGN); |
5626 | dev->padded = (char *)dev - (char *)p; | 5629 | dev->padded = (char *)dev - (char *)p; |
5627 | 5630 | ||
5628 | dev->pcpu_refcnt = alloc_percpu(int); | 5631 | dev->pcpu_refcnt = alloc_percpu(int); |
5629 | if (!dev->pcpu_refcnt) | 5632 | if (!dev->pcpu_refcnt) |
5630 | goto free_p; | 5633 | goto free_p; |
5631 | 5634 | ||
5632 | if (dev_addr_init(dev)) | 5635 | if (dev_addr_init(dev)) |
5633 | goto free_pcpu; | 5636 | goto free_pcpu; |
5634 | 5637 | ||
5635 | dev_mc_init(dev); | 5638 | dev_mc_init(dev); |
5636 | dev_uc_init(dev); | 5639 | dev_uc_init(dev); |
5637 | 5640 | ||
5638 | dev_net_set(dev, &init_net); | 5641 | dev_net_set(dev, &init_net); |
5639 | 5642 | ||
5640 | dev->num_tx_queues = queue_count; | 5643 | dev->num_tx_queues = queue_count; |
5641 | dev->real_num_tx_queues = queue_count; | 5644 | dev->real_num_tx_queues = queue_count; |
5642 | if (netif_alloc_netdev_queues(dev)) | 5645 | if (netif_alloc_netdev_queues(dev)) |
5643 | goto free_pcpu; | 5646 | goto free_pcpu; |
5644 | 5647 | ||
5645 | #ifdef CONFIG_RPS | 5648 | #ifdef CONFIG_RPS |
5646 | dev->num_rx_queues = queue_count; | 5649 | dev->num_rx_queues = queue_count; |
5647 | dev->real_num_rx_queues = queue_count; | 5650 | dev->real_num_rx_queues = queue_count; |
5648 | if (netif_alloc_rx_queues(dev)) | 5651 | if (netif_alloc_rx_queues(dev)) |
5649 | goto free_pcpu; | 5652 | goto free_pcpu; |
5650 | #endif | 5653 | #endif |
5651 | 5654 | ||
5652 | dev->gso_max_size = GSO_MAX_SIZE; | 5655 | dev->gso_max_size = GSO_MAX_SIZE; |
5653 | 5656 | ||
5654 | INIT_LIST_HEAD(&dev->ethtool_ntuple_list.list); | 5657 | INIT_LIST_HEAD(&dev->ethtool_ntuple_list.list); |
5655 | dev->ethtool_ntuple_list.count = 0; | 5658 | dev->ethtool_ntuple_list.count = 0; |
5656 | INIT_LIST_HEAD(&dev->napi_list); | 5659 | INIT_LIST_HEAD(&dev->napi_list); |
5657 | INIT_LIST_HEAD(&dev->unreg_list); | 5660 | INIT_LIST_HEAD(&dev->unreg_list); |
5658 | INIT_LIST_HEAD(&dev->link_watch_list); | 5661 | INIT_LIST_HEAD(&dev->link_watch_list); |
5659 | dev->priv_flags = IFF_XMIT_DST_RELEASE; | 5662 | dev->priv_flags = IFF_XMIT_DST_RELEASE; |
5660 | setup(dev); | 5663 | setup(dev); |
5661 | strcpy(dev->name, name); | 5664 | strcpy(dev->name, name); |
5662 | return dev; | 5665 | return dev; |
5663 | 5666 | ||
5664 | free_pcpu: | 5667 | free_pcpu: |
5665 | free_percpu(dev->pcpu_refcnt); | 5668 | free_percpu(dev->pcpu_refcnt); |
5666 | kfree(dev->_tx); | 5669 | kfree(dev->_tx); |
5667 | #ifdef CONFIG_RPS | 5670 | #ifdef CONFIG_RPS |
5668 | kfree(dev->_rx); | 5671 | kfree(dev->_rx); |
5669 | #endif | 5672 | #endif |
5670 | 5673 | ||
5671 | free_p: | 5674 | free_p: |
5672 | kfree(p); | 5675 | kfree(p); |
5673 | return NULL; | 5676 | return NULL; |
5674 | } | 5677 | } |
5675 | EXPORT_SYMBOL(alloc_netdev_mq); | 5678 | EXPORT_SYMBOL(alloc_netdev_mq); |
5676 | 5679 | ||
5677 | /** | 5680 | /** |
5678 | * free_netdev - free network device | 5681 | * free_netdev - free network device |
5679 | * @dev: device | 5682 | * @dev: device |
5680 | * | 5683 | * |
5681 | * This function does the last stage of destroying an allocated device | 5684 | * This function does the last stage of destroying an allocated device |
5682 | * interface. The reference to the device object is released. | 5685 | * interface. The reference to the device object is released. |
5683 | * If this is the last reference then it will be freed. | 5686 | * If this is the last reference then it will be freed. |
5684 | */ | 5687 | */ |
5685 | void free_netdev(struct net_device *dev) | 5688 | void free_netdev(struct net_device *dev) |
5686 | { | 5689 | { |
5687 | struct napi_struct *p, *n; | 5690 | struct napi_struct *p, *n; |
5688 | 5691 | ||
5689 | release_net(dev_net(dev)); | 5692 | release_net(dev_net(dev)); |
5690 | 5693 | ||
5691 | kfree(dev->_tx); | 5694 | kfree(dev->_tx); |
5692 | #ifdef CONFIG_RPS | 5695 | #ifdef CONFIG_RPS |
5693 | kfree(dev->_rx); | 5696 | kfree(dev->_rx); |
5694 | #endif | 5697 | #endif |
5695 | 5698 | ||
5696 | kfree(rcu_dereference_raw(dev->ingress_queue)); | 5699 | kfree(rcu_dereference_raw(dev->ingress_queue)); |
5697 | 5700 | ||
5698 | /* Flush device addresses */ | 5701 | /* Flush device addresses */ |
5699 | dev_addr_flush(dev); | 5702 | dev_addr_flush(dev); |
5700 | 5703 | ||
5701 | /* Clear ethtool n-tuple list */ | 5704 | /* Clear ethtool n-tuple list */ |
5702 | ethtool_ntuple_flush(dev); | 5705 | ethtool_ntuple_flush(dev); |
5703 | 5706 | ||
5704 | list_for_each_entry_safe(p, n, &dev->napi_list, dev_list) | 5707 | list_for_each_entry_safe(p, n, &dev->napi_list, dev_list) |
5705 | netif_napi_del(p); | 5708 | netif_napi_del(p); |
5706 | 5709 | ||
5707 | free_percpu(dev->pcpu_refcnt); | 5710 | free_percpu(dev->pcpu_refcnt); |
5708 | dev->pcpu_refcnt = NULL; | 5711 | dev->pcpu_refcnt = NULL; |
5709 | 5712 | ||
5710 | /* Compatibility with error handling in drivers */ | 5713 | /* Compatibility with error handling in drivers */ |
5711 | if (dev->reg_state == NETREG_UNINITIALIZED) { | 5714 | if (dev->reg_state == NETREG_UNINITIALIZED) { |
5712 | kfree((char *)dev - dev->padded); | 5715 | kfree((char *)dev - dev->padded); |
5713 | return; | 5716 | return; |
5714 | } | 5717 | } |
5715 | 5718 | ||
5716 | BUG_ON(dev->reg_state != NETREG_UNREGISTERED); | 5719 | BUG_ON(dev->reg_state != NETREG_UNREGISTERED); |
5717 | dev->reg_state = NETREG_RELEASED; | 5720 | dev->reg_state = NETREG_RELEASED; |
5718 | 5721 | ||
5719 | /* will free via device release */ | 5722 | /* will free via device release */ |
5720 | put_device(&dev->dev); | 5723 | put_device(&dev->dev); |
5721 | } | 5724 | } |
5722 | EXPORT_SYMBOL(free_netdev); | 5725 | EXPORT_SYMBOL(free_netdev); |
5723 | 5726 | ||
5724 | /** | 5727 | /** |
5725 | * synchronize_net - Synchronize with packet receive processing | 5728 | * synchronize_net - Synchronize with packet receive processing |
5726 | * | 5729 | * |
5727 | * Wait for packets currently being received to be done. | 5730 | * Wait for packets currently being received to be done. |
5728 | * Does not block later packets from starting. | 5731 | * Does not block later packets from starting. |
5729 | */ | 5732 | */ |
5730 | void synchronize_net(void) | 5733 | void synchronize_net(void) |
5731 | { | 5734 | { |
5732 | might_sleep(); | 5735 | might_sleep(); |
5733 | synchronize_rcu(); | 5736 | synchronize_rcu(); |
5734 | } | 5737 | } |
5735 | EXPORT_SYMBOL(synchronize_net); | 5738 | EXPORT_SYMBOL(synchronize_net); |
5736 | 5739 | ||
5737 | /** | 5740 | /** |
5738 | * unregister_netdevice_queue - remove device from the kernel | 5741 | * unregister_netdevice_queue - remove device from the kernel |
5739 | * @dev: device | 5742 | * @dev: device |
5740 | * @head: list | 5743 | * @head: list |
5741 | * | 5744 | * |
5742 | * This function shuts down a device interface and removes it | 5745 | * This function shuts down a device interface and removes it |
5743 | * from the kernel tables. | 5746 | * from the kernel tables. |
5744 | * If head not NULL, device is queued to be unregistered later. | 5747 | * If head not NULL, device is queued to be unregistered later. |
5745 | * | 5748 | * |
5746 | * Callers must hold the rtnl semaphore. You may want | 5749 | * Callers must hold the rtnl semaphore. You may want |
5747 | * unregister_netdev() instead of this. | 5750 | * unregister_netdev() instead of this. |
5748 | */ | 5751 | */ |
5749 | 5752 | ||
5750 | void unregister_netdevice_queue(struct net_device *dev, struct list_head *head) | 5753 | void unregister_netdevice_queue(struct net_device *dev, struct list_head *head) |
5751 | { | 5754 | { |
5752 | ASSERT_RTNL(); | 5755 | ASSERT_RTNL(); |
5753 | 5756 | ||
5754 | if (head) { | 5757 | if (head) { |
5755 | list_move_tail(&dev->unreg_list, head); | 5758 | list_move_tail(&dev->unreg_list, head); |
5756 | } else { | 5759 | } else { |
5757 | rollback_registered(dev); | 5760 | rollback_registered(dev); |
5758 | /* Finish processing unregister after unlock */ | 5761 | /* Finish processing unregister after unlock */ |
5759 | net_set_todo(dev); | 5762 | net_set_todo(dev); |
5760 | } | 5763 | } |
5761 | } | 5764 | } |
5762 | EXPORT_SYMBOL(unregister_netdevice_queue); | 5765 | EXPORT_SYMBOL(unregister_netdevice_queue); |
5763 | 5766 | ||
5764 | /** | 5767 | /** |
5765 | * unregister_netdevice_many - unregister many devices | 5768 | * unregister_netdevice_many - unregister many devices |
5766 | * @head: list of devices | 5769 | * @head: list of devices |
5767 | */ | 5770 | */ |
5768 | void unregister_netdevice_many(struct list_head *head) | 5771 | void unregister_netdevice_many(struct list_head *head) |
5769 | { | 5772 | { |
5770 | struct net_device *dev; | 5773 | struct net_device *dev; |
5771 | 5774 | ||
5772 | if (!list_empty(head)) { | 5775 | if (!list_empty(head)) { |
5773 | rollback_registered_many(head); | 5776 | rollback_registered_many(head); |
5774 | list_for_each_entry(dev, head, unreg_list) | 5777 | list_for_each_entry(dev, head, unreg_list) |
5775 | net_set_todo(dev); | 5778 | net_set_todo(dev); |
5776 | } | 5779 | } |
5777 | } | 5780 | } |
5778 | EXPORT_SYMBOL(unregister_netdevice_many); | 5781 | EXPORT_SYMBOL(unregister_netdevice_many); |
5779 | 5782 | ||
5780 | /** | 5783 | /** |
5781 | * unregister_netdev - remove device from the kernel | 5784 | * unregister_netdev - remove device from the kernel |
5782 | * @dev: device | 5785 | * @dev: device |
5783 | * | 5786 | * |
5784 | * This function shuts down a device interface and removes it | 5787 | * This function shuts down a device interface and removes it |
5785 | * from the kernel tables. | 5788 | * from the kernel tables. |
5786 | * | 5789 | * |
5787 | * This is just a wrapper for unregister_netdevice that takes | 5790 | * This is just a wrapper for unregister_netdevice that takes |
5788 | * the rtnl semaphore. In general you want to use this and not | 5791 | * the rtnl semaphore. In general you want to use this and not |
5789 | * unregister_netdevice. | 5792 | * unregister_netdevice. |
5790 | */ | 5793 | */ |
5791 | void unregister_netdev(struct net_device *dev) | 5794 | void unregister_netdev(struct net_device *dev) |
5792 | { | 5795 | { |
5793 | rtnl_lock(); | 5796 | rtnl_lock(); |
5794 | unregister_netdevice(dev); | 5797 | unregister_netdevice(dev); |
5795 | rtnl_unlock(); | 5798 | rtnl_unlock(); |
5796 | } | 5799 | } |
5797 | EXPORT_SYMBOL(unregister_netdev); | 5800 | EXPORT_SYMBOL(unregister_netdev); |
5798 | 5801 | ||
5799 | /** | 5802 | /** |
5800 | * dev_change_net_namespace - move device to different nethost namespace | 5803 | * dev_change_net_namespace - move device to different nethost namespace |
5801 | * @dev: device | 5804 | * @dev: device |
5802 | * @net: network namespace | 5805 | * @net: network namespace |
5803 | * @pat: If not NULL name pattern to try if the current device name | 5806 | * @pat: If not NULL name pattern to try if the current device name |
5804 | * is already taken in the destination network namespace. | 5807 | * is already taken in the destination network namespace. |
5805 | * | 5808 | * |
5806 | * This function shuts down a device interface and moves it | 5809 | * This function shuts down a device interface and moves it |
5807 | * to a new network namespace. On success 0 is returned, on | 5810 | * to a new network namespace. On success 0 is returned, on |
5808 | * a failure a netagive errno code is returned. | 5811 | * a failure a netagive errno code is returned. |
5809 | * | 5812 | * |
5810 | * Callers must hold the rtnl semaphore. | 5813 | * Callers must hold the rtnl semaphore. |
5811 | */ | 5814 | */ |
5812 | 5815 | ||
5813 | int dev_change_net_namespace(struct net_device *dev, struct net *net, const char *pat) | 5816 | int dev_change_net_namespace(struct net_device *dev, struct net *net, const char *pat) |
5814 | { | 5817 | { |
5815 | int err; | 5818 | int err; |
5816 | 5819 | ||
5817 | ASSERT_RTNL(); | 5820 | ASSERT_RTNL(); |
5818 | 5821 | ||
5819 | /* Don't allow namespace local devices to be moved. */ | 5822 | /* Don't allow namespace local devices to be moved. */ |
5820 | err = -EINVAL; | 5823 | err = -EINVAL; |
5821 | if (dev->features & NETIF_F_NETNS_LOCAL) | 5824 | if (dev->features & NETIF_F_NETNS_LOCAL) |
5822 | goto out; | 5825 | goto out; |
5823 | 5826 | ||
5824 | /* Ensure the device has been registrered */ | 5827 | /* Ensure the device has been registrered */ |
5825 | err = -EINVAL; | 5828 | err = -EINVAL; |
5826 | if (dev->reg_state != NETREG_REGISTERED) | 5829 | if (dev->reg_state != NETREG_REGISTERED) |
5827 | goto out; | 5830 | goto out; |
5828 | 5831 | ||
5829 | /* Get out if there is nothing todo */ | 5832 | /* Get out if there is nothing todo */ |
5830 | err = 0; | 5833 | err = 0; |
5831 | if (net_eq(dev_net(dev), net)) | 5834 | if (net_eq(dev_net(dev), net)) |
5832 | goto out; | 5835 | goto out; |
5833 | 5836 | ||
5834 | /* Pick the destination device name, and ensure | 5837 | /* Pick the destination device name, and ensure |
5835 | * we can use it in the destination network namespace. | 5838 | * we can use it in the destination network namespace. |
5836 | */ | 5839 | */ |
5837 | err = -EEXIST; | 5840 | err = -EEXIST; |
5838 | if (__dev_get_by_name(net, dev->name)) { | 5841 | if (__dev_get_by_name(net, dev->name)) { |
5839 | /* We get here if we can't use the current device name */ | 5842 | /* We get here if we can't use the current device name */ |
5840 | if (!pat) | 5843 | if (!pat) |
5841 | goto out; | 5844 | goto out; |
5842 | if (dev_get_valid_name(dev, pat, 1)) | 5845 | if (dev_get_valid_name(dev, pat, 1)) |
5843 | goto out; | 5846 | goto out; |
5844 | } | 5847 | } |
5845 | 5848 | ||
5846 | /* | 5849 | /* |
5847 | * And now a mini version of register_netdevice unregister_netdevice. | 5850 | * And now a mini version of register_netdevice unregister_netdevice. |
5848 | */ | 5851 | */ |
5849 | 5852 | ||
5850 | /* If device is running close it first. */ | 5853 | /* If device is running close it first. */ |
5851 | dev_close(dev); | 5854 | dev_close(dev); |
5852 | 5855 | ||
5853 | /* And unlink it from device chain */ | 5856 | /* And unlink it from device chain */ |
5854 | err = -ENODEV; | 5857 | err = -ENODEV; |
5855 | unlist_netdevice(dev); | 5858 | unlist_netdevice(dev); |
5856 | 5859 | ||
5857 | synchronize_net(); | 5860 | synchronize_net(); |
5858 | 5861 | ||
5859 | /* Shutdown queueing discipline. */ | 5862 | /* Shutdown queueing discipline. */ |
5860 | dev_shutdown(dev); | 5863 | dev_shutdown(dev); |
5861 | 5864 | ||
5862 | /* Notify protocols, that we are about to destroy | 5865 | /* Notify protocols, that we are about to destroy |
5863 | this device. They should clean all the things. | 5866 | this device. They should clean all the things. |
5864 | 5867 | ||
5865 | Note that dev->reg_state stays at NETREG_REGISTERED. | 5868 | Note that dev->reg_state stays at NETREG_REGISTERED. |
5866 | This is wanted because this way 8021q and macvlan know | 5869 | This is wanted because this way 8021q and macvlan know |
5867 | the device is just moving and can keep their slaves up. | 5870 | the device is just moving and can keep their slaves up. |
5868 | */ | 5871 | */ |
5869 | call_netdevice_notifiers(NETDEV_UNREGISTER, dev); | 5872 | call_netdevice_notifiers(NETDEV_UNREGISTER, dev); |
5870 | call_netdevice_notifiers(NETDEV_UNREGISTER_BATCH, dev); | 5873 | call_netdevice_notifiers(NETDEV_UNREGISTER_BATCH, dev); |
5871 | 5874 | ||
5872 | /* | 5875 | /* |
5873 | * Flush the unicast and multicast chains | 5876 | * Flush the unicast and multicast chains |
5874 | */ | 5877 | */ |
5875 | dev_uc_flush(dev); | 5878 | dev_uc_flush(dev); |
5876 | dev_mc_flush(dev); | 5879 | dev_mc_flush(dev); |
5877 | 5880 | ||
5878 | /* Actually switch the network namespace */ | 5881 | /* Actually switch the network namespace */ |
5879 | dev_net_set(dev, net); | 5882 | dev_net_set(dev, net); |
5880 | 5883 | ||
5881 | /* If there is an ifindex conflict assign a new one */ | 5884 | /* If there is an ifindex conflict assign a new one */ |
5882 | if (__dev_get_by_index(net, dev->ifindex)) { | 5885 | if (__dev_get_by_index(net, dev->ifindex)) { |
5883 | int iflink = (dev->iflink == dev->ifindex); | 5886 | int iflink = (dev->iflink == dev->ifindex); |
5884 | dev->ifindex = dev_new_index(net); | 5887 | dev->ifindex = dev_new_index(net); |
5885 | if (iflink) | 5888 | if (iflink) |
5886 | dev->iflink = dev->ifindex; | 5889 | dev->iflink = dev->ifindex; |
5887 | } | 5890 | } |
5888 | 5891 | ||
5889 | /* Fixup kobjects */ | 5892 | /* Fixup kobjects */ |
5890 | err = device_rename(&dev->dev, dev->name); | 5893 | err = device_rename(&dev->dev, dev->name); |
5891 | WARN_ON(err); | 5894 | WARN_ON(err); |
5892 | 5895 | ||
5893 | /* Add the device back in the hashes */ | 5896 | /* Add the device back in the hashes */ |
5894 | list_netdevice(dev); | 5897 | list_netdevice(dev); |
5895 | 5898 | ||
5896 | /* Notify protocols, that a new device appeared. */ | 5899 | /* Notify protocols, that a new device appeared. */ |
5897 | call_netdevice_notifiers(NETDEV_REGISTER, dev); | 5900 | call_netdevice_notifiers(NETDEV_REGISTER, dev); |
5898 | 5901 | ||
5899 | /* | 5902 | /* |
5900 | * Prevent userspace races by waiting until the network | 5903 | * Prevent userspace races by waiting until the network |
5901 | * device is fully setup before sending notifications. | 5904 | * device is fully setup before sending notifications. |
5902 | */ | 5905 | */ |
5903 | rtmsg_ifinfo(RTM_NEWLINK, dev, ~0U); | 5906 | rtmsg_ifinfo(RTM_NEWLINK, dev, ~0U); |
5904 | 5907 | ||
5905 | synchronize_net(); | 5908 | synchronize_net(); |
5906 | err = 0; | 5909 | err = 0; |
5907 | out: | 5910 | out: |
5908 | return err; | 5911 | return err; |
5909 | } | 5912 | } |
5910 | EXPORT_SYMBOL_GPL(dev_change_net_namespace); | 5913 | EXPORT_SYMBOL_GPL(dev_change_net_namespace); |
5911 | 5914 | ||
5912 | static int dev_cpu_callback(struct notifier_block *nfb, | 5915 | static int dev_cpu_callback(struct notifier_block *nfb, |
5913 | unsigned long action, | 5916 | unsigned long action, |
5914 | void *ocpu) | 5917 | void *ocpu) |
5915 | { | 5918 | { |
5916 | struct sk_buff **list_skb; | 5919 | struct sk_buff **list_skb; |
5917 | struct sk_buff *skb; | 5920 | struct sk_buff *skb; |
5918 | unsigned int cpu, oldcpu = (unsigned long)ocpu; | 5921 | unsigned int cpu, oldcpu = (unsigned long)ocpu; |
5919 | struct softnet_data *sd, *oldsd; | 5922 | struct softnet_data *sd, *oldsd; |
5920 | 5923 | ||
5921 | if (action != CPU_DEAD && action != CPU_DEAD_FROZEN) | 5924 | if (action != CPU_DEAD && action != CPU_DEAD_FROZEN) |
5922 | return NOTIFY_OK; | 5925 | return NOTIFY_OK; |
5923 | 5926 | ||
5924 | local_irq_disable(); | 5927 | local_irq_disable(); |
5925 | cpu = smp_processor_id(); | 5928 | cpu = smp_processor_id(); |
5926 | sd = &per_cpu(softnet_data, cpu); | 5929 | sd = &per_cpu(softnet_data, cpu); |
5927 | oldsd = &per_cpu(softnet_data, oldcpu); | 5930 | oldsd = &per_cpu(softnet_data, oldcpu); |
5928 | 5931 | ||
5929 | /* Find end of our completion_queue. */ | 5932 | /* Find end of our completion_queue. */ |
5930 | list_skb = &sd->completion_queue; | 5933 | list_skb = &sd->completion_queue; |
5931 | while (*list_skb) | 5934 | while (*list_skb) |
5932 | list_skb = &(*list_skb)->next; | 5935 | list_skb = &(*list_skb)->next; |
5933 | /* Append completion queue from offline CPU. */ | 5936 | /* Append completion queue from offline CPU. */ |
5934 | *list_skb = oldsd->completion_queue; | 5937 | *list_skb = oldsd->completion_queue; |
5935 | oldsd->completion_queue = NULL; | 5938 | oldsd->completion_queue = NULL; |
5936 | 5939 | ||
5937 | /* Append output queue from offline CPU. */ | 5940 | /* Append output queue from offline CPU. */ |
5938 | if (oldsd->output_queue) { | 5941 | if (oldsd->output_queue) { |
5939 | *sd->output_queue_tailp = oldsd->output_queue; | 5942 | *sd->output_queue_tailp = oldsd->output_queue; |
5940 | sd->output_queue_tailp = oldsd->output_queue_tailp; | 5943 | sd->output_queue_tailp = oldsd->output_queue_tailp; |
5941 | oldsd->output_queue = NULL; | 5944 | oldsd->output_queue = NULL; |
5942 | oldsd->output_queue_tailp = &oldsd->output_queue; | 5945 | oldsd->output_queue_tailp = &oldsd->output_queue; |
5943 | } | 5946 | } |
5944 | 5947 | ||
5945 | raise_softirq_irqoff(NET_TX_SOFTIRQ); | 5948 | raise_softirq_irqoff(NET_TX_SOFTIRQ); |
5946 | local_irq_enable(); | 5949 | local_irq_enable(); |
5947 | 5950 | ||
5948 | /* Process offline CPU's input_pkt_queue */ | 5951 | /* Process offline CPU's input_pkt_queue */ |
5949 | while ((skb = __skb_dequeue(&oldsd->process_queue))) { | 5952 | while ((skb = __skb_dequeue(&oldsd->process_queue))) { |
5950 | netif_rx(skb); | 5953 | netif_rx(skb); |
5951 | input_queue_head_incr(oldsd); | 5954 | input_queue_head_incr(oldsd); |
5952 | } | 5955 | } |
5953 | while ((skb = __skb_dequeue(&oldsd->input_pkt_queue))) { | 5956 | while ((skb = __skb_dequeue(&oldsd->input_pkt_queue))) { |
5954 | netif_rx(skb); | 5957 | netif_rx(skb); |
5955 | input_queue_head_incr(oldsd); | 5958 | input_queue_head_incr(oldsd); |
5956 | } | 5959 | } |
5957 | 5960 | ||
5958 | return NOTIFY_OK; | 5961 | return NOTIFY_OK; |
5959 | } | 5962 | } |
5960 | 5963 | ||
5961 | 5964 | ||
5962 | /** | 5965 | /** |
5963 | * netdev_increment_features - increment feature set by one | 5966 | * netdev_increment_features - increment feature set by one |
5964 | * @all: current feature set | 5967 | * @all: current feature set |
5965 | * @one: new feature set | 5968 | * @one: new feature set |
5966 | * @mask: mask feature set | 5969 | * @mask: mask feature set |
5967 | * | 5970 | * |
5968 | * Computes a new feature set after adding a device with feature set | 5971 | * Computes a new feature set after adding a device with feature set |
5969 | * @one to the master device with current feature set @all. Will not | 5972 | * @one to the master device with current feature set @all. Will not |
5970 | * enable anything that is off in @mask. Returns the new feature set. | 5973 | * enable anything that is off in @mask. Returns the new feature set. |
5971 | */ | 5974 | */ |
5972 | unsigned long netdev_increment_features(unsigned long all, unsigned long one, | 5975 | unsigned long netdev_increment_features(unsigned long all, unsigned long one, |
5973 | unsigned long mask) | 5976 | unsigned long mask) |
5974 | { | 5977 | { |
5975 | /* If device needs checksumming, downgrade to it. */ | 5978 | /* If device needs checksumming, downgrade to it. */ |
5976 | if (all & NETIF_F_NO_CSUM && !(one & NETIF_F_NO_CSUM)) | 5979 | if (all & NETIF_F_NO_CSUM && !(one & NETIF_F_NO_CSUM)) |
5977 | all ^= NETIF_F_NO_CSUM | (one & NETIF_F_ALL_CSUM); | 5980 | all ^= NETIF_F_NO_CSUM | (one & NETIF_F_ALL_CSUM); |
5978 | else if (mask & NETIF_F_ALL_CSUM) { | 5981 | else if (mask & NETIF_F_ALL_CSUM) { |
5979 | /* If one device supports v4/v6 checksumming, set for all. */ | 5982 | /* If one device supports v4/v6 checksumming, set for all. */ |
5980 | if (one & (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM) && | 5983 | if (one & (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM) && |
5981 | !(all & NETIF_F_GEN_CSUM)) { | 5984 | !(all & NETIF_F_GEN_CSUM)) { |
5982 | all &= ~NETIF_F_ALL_CSUM; | 5985 | all &= ~NETIF_F_ALL_CSUM; |
5983 | all |= one & (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM); | 5986 | all |= one & (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM); |
5984 | } | 5987 | } |
5985 | 5988 | ||
5986 | /* If one device supports hw checksumming, set for all. */ | 5989 | /* If one device supports hw checksumming, set for all. */ |
5987 | if (one & NETIF_F_GEN_CSUM && !(all & NETIF_F_GEN_CSUM)) { | 5990 | if (one & NETIF_F_GEN_CSUM && !(all & NETIF_F_GEN_CSUM)) { |
5988 | all &= ~NETIF_F_ALL_CSUM; | 5991 | all &= ~NETIF_F_ALL_CSUM; |
5989 | all |= NETIF_F_HW_CSUM; | 5992 | all |= NETIF_F_HW_CSUM; |
5990 | } | 5993 | } |
5991 | } | 5994 | } |
5992 | 5995 | ||
5993 | one |= NETIF_F_ALL_CSUM; | 5996 | one |= NETIF_F_ALL_CSUM; |
5994 | 5997 | ||
5995 | one |= all & NETIF_F_ONE_FOR_ALL; | 5998 | one |= all & NETIF_F_ONE_FOR_ALL; |
5996 | all &= one | NETIF_F_LLTX | NETIF_F_GSO | NETIF_F_UFO; | 5999 | all &= one | NETIF_F_LLTX | NETIF_F_GSO | NETIF_F_UFO; |
5997 | all |= one & mask & NETIF_F_ONE_FOR_ALL; | 6000 | all |= one & mask & NETIF_F_ONE_FOR_ALL; |
5998 | 6001 | ||
5999 | return all; | 6002 | return all; |
6000 | } | 6003 | } |
6001 | EXPORT_SYMBOL(netdev_increment_features); | 6004 | EXPORT_SYMBOL(netdev_increment_features); |
6002 | 6005 | ||
6003 | static struct hlist_head *netdev_create_hash(void) | 6006 | static struct hlist_head *netdev_create_hash(void) |
6004 | { | 6007 | { |
6005 | int i; | 6008 | int i; |
6006 | struct hlist_head *hash; | 6009 | struct hlist_head *hash; |
6007 | 6010 | ||
6008 | hash = kmalloc(sizeof(*hash) * NETDEV_HASHENTRIES, GFP_KERNEL); | 6011 | hash = kmalloc(sizeof(*hash) * NETDEV_HASHENTRIES, GFP_KERNEL); |
6009 | if (hash != NULL) | 6012 | if (hash != NULL) |
6010 | for (i = 0; i < NETDEV_HASHENTRIES; i++) | 6013 | for (i = 0; i < NETDEV_HASHENTRIES; i++) |
6011 | INIT_HLIST_HEAD(&hash[i]); | 6014 | INIT_HLIST_HEAD(&hash[i]); |
6012 | 6015 | ||
6013 | return hash; | 6016 | return hash; |
6014 | } | 6017 | } |
6015 | 6018 | ||
6016 | /* Initialize per network namespace state */ | 6019 | /* Initialize per network namespace state */ |
6017 | static int __net_init netdev_init(struct net *net) | 6020 | static int __net_init netdev_init(struct net *net) |
6018 | { | 6021 | { |
6019 | INIT_LIST_HEAD(&net->dev_base_head); | 6022 | INIT_LIST_HEAD(&net->dev_base_head); |
6020 | 6023 | ||
6021 | net->dev_name_head = netdev_create_hash(); | 6024 | net->dev_name_head = netdev_create_hash(); |
6022 | if (net->dev_name_head == NULL) | 6025 | if (net->dev_name_head == NULL) |
6023 | goto err_name; | 6026 | goto err_name; |
6024 | 6027 | ||
6025 | net->dev_index_head = netdev_create_hash(); | 6028 | net->dev_index_head = netdev_create_hash(); |
6026 | if (net->dev_index_head == NULL) | 6029 | if (net->dev_index_head == NULL) |
6027 | goto err_idx; | 6030 | goto err_idx; |
6028 | 6031 | ||
6029 | return 0; | 6032 | return 0; |
6030 | 6033 | ||
6031 | err_idx: | 6034 | err_idx: |
6032 | kfree(net->dev_name_head); | 6035 | kfree(net->dev_name_head); |
6033 | err_name: | 6036 | err_name: |
6034 | return -ENOMEM; | 6037 | return -ENOMEM; |
6035 | } | 6038 | } |
6036 | 6039 | ||
6037 | /** | 6040 | /** |
6038 | * netdev_drivername - network driver for the device | 6041 | * netdev_drivername - network driver for the device |
6039 | * @dev: network device | 6042 | * @dev: network device |
6040 | * @buffer: buffer for resulting name | 6043 | * @buffer: buffer for resulting name |
6041 | * @len: size of buffer | 6044 | * @len: size of buffer |
6042 | * | 6045 | * |
6043 | * Determine network driver for device. | 6046 | * Determine network driver for device. |
6044 | */ | 6047 | */ |
6045 | char *netdev_drivername(const struct net_device *dev, char *buffer, int len) | 6048 | char *netdev_drivername(const struct net_device *dev, char *buffer, int len) |
6046 | { | 6049 | { |
6047 | const struct device_driver *driver; | 6050 | const struct device_driver *driver; |
6048 | const struct device *parent; | 6051 | const struct device *parent; |
6049 | 6052 | ||
6050 | if (len <= 0 || !buffer) | 6053 | if (len <= 0 || !buffer) |
6051 | return buffer; | 6054 | return buffer; |
6052 | buffer[0] = 0; | 6055 | buffer[0] = 0; |
6053 | 6056 | ||
6054 | parent = dev->dev.parent; | 6057 | parent = dev->dev.parent; |
6055 | 6058 | ||
6056 | if (!parent) | 6059 | if (!parent) |
6057 | return buffer; | 6060 | return buffer; |
6058 | 6061 | ||
6059 | driver = parent->driver; | 6062 | driver = parent->driver; |
6060 | if (driver && driver->name) | 6063 | if (driver && driver->name) |
6061 | strlcpy(buffer, driver->name, len); | 6064 | strlcpy(buffer, driver->name, len); |
6062 | return buffer; | 6065 | return buffer; |
6063 | } | 6066 | } |
6064 | 6067 | ||
6065 | static int __netdev_printk(const char *level, const struct net_device *dev, | 6068 | static int __netdev_printk(const char *level, const struct net_device *dev, |
6066 | struct va_format *vaf) | 6069 | struct va_format *vaf) |
6067 | { | 6070 | { |
6068 | int r; | 6071 | int r; |
6069 | 6072 | ||
6070 | if (dev && dev->dev.parent) | 6073 | if (dev && dev->dev.parent) |
6071 | r = dev_printk(level, dev->dev.parent, "%s: %pV", | 6074 | r = dev_printk(level, dev->dev.parent, "%s: %pV", |
6072 | netdev_name(dev), vaf); | 6075 | netdev_name(dev), vaf); |
6073 | else if (dev) | 6076 | else if (dev) |
6074 | r = printk("%s%s: %pV", level, netdev_name(dev), vaf); | 6077 | r = printk("%s%s: %pV", level, netdev_name(dev), vaf); |
6075 | else | 6078 | else |
6076 | r = printk("%s(NULL net_device): %pV", level, vaf); | 6079 | r = printk("%s(NULL net_device): %pV", level, vaf); |
6077 | 6080 | ||
6078 | return r; | 6081 | return r; |
6079 | } | 6082 | } |
6080 | 6083 | ||
6081 | int netdev_printk(const char *level, const struct net_device *dev, | 6084 | int netdev_printk(const char *level, const struct net_device *dev, |
6082 | const char *format, ...) | 6085 | const char *format, ...) |
6083 | { | 6086 | { |
6084 | struct va_format vaf; | 6087 | struct va_format vaf; |
6085 | va_list args; | 6088 | va_list args; |
6086 | int r; | 6089 | int r; |
6087 | 6090 | ||
6088 | va_start(args, format); | 6091 | va_start(args, format); |
6089 | 6092 | ||
6090 | vaf.fmt = format; | 6093 | vaf.fmt = format; |
6091 | vaf.va = &args; | 6094 | vaf.va = &args; |
6092 | 6095 | ||
6093 | r = __netdev_printk(level, dev, &vaf); | 6096 | r = __netdev_printk(level, dev, &vaf); |
6094 | va_end(args); | 6097 | va_end(args); |
6095 | 6098 | ||
6096 | return r; | 6099 | return r; |
6097 | } | 6100 | } |
6098 | EXPORT_SYMBOL(netdev_printk); | 6101 | EXPORT_SYMBOL(netdev_printk); |
6099 | 6102 | ||
6100 | #define define_netdev_printk_level(func, level) \ | 6103 | #define define_netdev_printk_level(func, level) \ |
6101 | int func(const struct net_device *dev, const char *fmt, ...) \ | 6104 | int func(const struct net_device *dev, const char *fmt, ...) \ |
6102 | { \ | 6105 | { \ |
6103 | int r; \ | 6106 | int r; \ |
6104 | struct va_format vaf; \ | 6107 | struct va_format vaf; \ |
6105 | va_list args; \ | 6108 | va_list args; \ |
6106 | \ | 6109 | \ |
6107 | va_start(args, fmt); \ | 6110 | va_start(args, fmt); \ |
6108 | \ | 6111 | \ |
6109 | vaf.fmt = fmt; \ | 6112 | vaf.fmt = fmt; \ |
6110 | vaf.va = &args; \ | 6113 | vaf.va = &args; \ |
6111 | \ | 6114 | \ |
6112 | r = __netdev_printk(level, dev, &vaf); \ | 6115 | r = __netdev_printk(level, dev, &vaf); \ |
6113 | va_end(args); \ | 6116 | va_end(args); \ |
6114 | \ | 6117 | \ |
6115 | return r; \ | 6118 | return r; \ |
6116 | } \ | 6119 | } \ |
6117 | EXPORT_SYMBOL(func); | 6120 | EXPORT_SYMBOL(func); |
6118 | 6121 | ||
6119 | define_netdev_printk_level(netdev_emerg, KERN_EMERG); | 6122 | define_netdev_printk_level(netdev_emerg, KERN_EMERG); |
6120 | define_netdev_printk_level(netdev_alert, KERN_ALERT); | 6123 | define_netdev_printk_level(netdev_alert, KERN_ALERT); |
6121 | define_netdev_printk_level(netdev_crit, KERN_CRIT); | 6124 | define_netdev_printk_level(netdev_crit, KERN_CRIT); |
6122 | define_netdev_printk_level(netdev_err, KERN_ERR); | 6125 | define_netdev_printk_level(netdev_err, KERN_ERR); |
6123 | define_netdev_printk_level(netdev_warn, KERN_WARNING); | 6126 | define_netdev_printk_level(netdev_warn, KERN_WARNING); |
6124 | define_netdev_printk_level(netdev_notice, KERN_NOTICE); | 6127 | define_netdev_printk_level(netdev_notice, KERN_NOTICE); |
6125 | define_netdev_printk_level(netdev_info, KERN_INFO); | 6128 | define_netdev_printk_level(netdev_info, KERN_INFO); |
6126 | 6129 | ||
6127 | static void __net_exit netdev_exit(struct net *net) | 6130 | static void __net_exit netdev_exit(struct net *net) |
6128 | { | 6131 | { |
6129 | kfree(net->dev_name_head); | 6132 | kfree(net->dev_name_head); |
6130 | kfree(net->dev_index_head); | 6133 | kfree(net->dev_index_head); |
6131 | } | 6134 | } |
6132 | 6135 | ||
6133 | static struct pernet_operations __net_initdata netdev_net_ops = { | 6136 | static struct pernet_operations __net_initdata netdev_net_ops = { |
6134 | .init = netdev_init, | 6137 | .init = netdev_init, |
6135 | .exit = netdev_exit, | 6138 | .exit = netdev_exit, |
6136 | }; | 6139 | }; |
6137 | 6140 | ||
6138 | static void __net_exit default_device_exit(struct net *net) | 6141 | static void __net_exit default_device_exit(struct net *net) |
6139 | { | 6142 | { |
6140 | struct net_device *dev, *aux; | 6143 | struct net_device *dev, *aux; |
6141 | /* | 6144 | /* |
6142 | * Push all migratable network devices back to the | 6145 | * Push all migratable network devices back to the |
6143 | * initial network namespace | 6146 | * initial network namespace |
6144 | */ | 6147 | */ |
6145 | rtnl_lock(); | 6148 | rtnl_lock(); |
6146 | for_each_netdev_safe(net, dev, aux) { | 6149 | for_each_netdev_safe(net, dev, aux) { |
6147 | int err; | 6150 | int err; |
6148 | char fb_name[IFNAMSIZ]; | 6151 | char fb_name[IFNAMSIZ]; |
6149 | 6152 | ||
6150 | /* Ignore unmoveable devices (i.e. loopback) */ | 6153 | /* Ignore unmoveable devices (i.e. loopback) */ |
6151 | if (dev->features & NETIF_F_NETNS_LOCAL) | 6154 | if (dev->features & NETIF_F_NETNS_LOCAL) |
6152 | continue; | 6155 | continue; |
6153 | 6156 | ||
6154 | /* Leave virtual devices for the generic cleanup */ | 6157 | /* Leave virtual devices for the generic cleanup */ |
6155 | if (dev->rtnl_link_ops) | 6158 | if (dev->rtnl_link_ops) |
6156 | continue; | 6159 | continue; |
6157 | 6160 | ||
6158 | /* Push remaing network devices to init_net */ | 6161 | /* Push remaing network devices to init_net */ |
6159 | snprintf(fb_name, IFNAMSIZ, "dev%d", dev->ifindex); | 6162 | snprintf(fb_name, IFNAMSIZ, "dev%d", dev->ifindex); |
6160 | err = dev_change_net_namespace(dev, &init_net, fb_name); | 6163 | err = dev_change_net_namespace(dev, &init_net, fb_name); |
6161 | if (err) { | 6164 | if (err) { |
6162 | printk(KERN_EMERG "%s: failed to move %s to init_net: %d\n", | 6165 | printk(KERN_EMERG "%s: failed to move %s to init_net: %d\n", |
6163 | __func__, dev->name, err); | 6166 | __func__, dev->name, err); |
6164 | BUG(); | 6167 | BUG(); |
6165 | } | 6168 | } |
6166 | } | 6169 | } |
6167 | rtnl_unlock(); | 6170 | rtnl_unlock(); |
6168 | } | 6171 | } |
6169 | 6172 | ||
6170 | static void __net_exit default_device_exit_batch(struct list_head *net_list) | 6173 | static void __net_exit default_device_exit_batch(struct list_head *net_list) |
6171 | { | 6174 | { |
6172 | /* At exit all network devices most be removed from a network | 6175 | /* At exit all network devices most be removed from a network |
6173 | * namespace. Do this in the reverse order of registeration. | 6176 | * namespace. Do this in the reverse order of registeration. |
6174 | * Do this across as many network namespaces as possible to | 6177 | * Do this across as many network namespaces as possible to |
6175 | * improve batching efficiency. | 6178 | * improve batching efficiency. |
6176 | */ | 6179 | */ |
6177 | struct net_device *dev; | 6180 | struct net_device *dev; |
6178 | struct net *net; | 6181 | struct net *net; |
6179 | LIST_HEAD(dev_kill_list); | 6182 | LIST_HEAD(dev_kill_list); |
6180 | 6183 | ||
6181 | rtnl_lock(); | 6184 | rtnl_lock(); |
6182 | list_for_each_entry(net, net_list, exit_list) { | 6185 | list_for_each_entry(net, net_list, exit_list) { |
6183 | for_each_netdev_reverse(net, dev) { | 6186 | for_each_netdev_reverse(net, dev) { |
6184 | if (dev->rtnl_link_ops) | 6187 | if (dev->rtnl_link_ops) |
6185 | dev->rtnl_link_ops->dellink(dev, &dev_kill_list); | 6188 | dev->rtnl_link_ops->dellink(dev, &dev_kill_list); |
6186 | else | 6189 | else |
6187 | unregister_netdevice_queue(dev, &dev_kill_list); | 6190 | unregister_netdevice_queue(dev, &dev_kill_list); |
6188 | } | 6191 | } |
6189 | } | 6192 | } |
6190 | unregister_netdevice_many(&dev_kill_list); | 6193 | unregister_netdevice_many(&dev_kill_list); |
6191 | rtnl_unlock(); | 6194 | rtnl_unlock(); |
6192 | } | 6195 | } |
6193 | 6196 | ||
6194 | static struct pernet_operations __net_initdata default_device_ops = { | 6197 | static struct pernet_operations __net_initdata default_device_ops = { |
6195 | .exit = default_device_exit, | 6198 | .exit = default_device_exit, |
6196 | .exit_batch = default_device_exit_batch, | 6199 | .exit_batch = default_device_exit_batch, |
6197 | }; | 6200 | }; |
6198 | 6201 | ||
6199 | /* | 6202 | /* |
6200 | * Initialize the DEV module. At boot time this walks the device list and | 6203 | * Initialize the DEV module. At boot time this walks the device list and |
6201 | * unhooks any devices that fail to initialise (normally hardware not | 6204 | * unhooks any devices that fail to initialise (normally hardware not |
6202 | * present) and leaves us with a valid list of present and active devices. | 6205 | * present) and leaves us with a valid list of present and active devices. |
6203 | * | 6206 | * |
6204 | */ | 6207 | */ |
6205 | 6208 | ||
6206 | /* | 6209 | /* |
6207 | * This is called single threaded during boot, so no need | 6210 | * This is called single threaded during boot, so no need |
6208 | * to take the rtnl semaphore. | 6211 | * to take the rtnl semaphore. |
6209 | */ | 6212 | */ |
6210 | static int __init net_dev_init(void) | 6213 | static int __init net_dev_init(void) |
6211 | { | 6214 | { |
6212 | int i, rc = -ENOMEM; | 6215 | int i, rc = -ENOMEM; |
6213 | 6216 | ||
6214 | BUG_ON(!dev_boot_phase); | 6217 | BUG_ON(!dev_boot_phase); |
6215 | 6218 | ||
6216 | if (dev_proc_init()) | 6219 | if (dev_proc_init()) |
6217 | goto out; | 6220 | goto out; |
6218 | 6221 | ||
6219 | if (netdev_kobject_init()) | 6222 | if (netdev_kobject_init()) |
6220 | goto out; | 6223 | goto out; |
6221 | 6224 | ||
6222 | INIT_LIST_HEAD(&ptype_all); | 6225 | INIT_LIST_HEAD(&ptype_all); |
6223 | for (i = 0; i < PTYPE_HASH_SIZE; i++) | 6226 | for (i = 0; i < PTYPE_HASH_SIZE; i++) |
6224 | INIT_LIST_HEAD(&ptype_base[i]); | 6227 | INIT_LIST_HEAD(&ptype_base[i]); |
6225 | 6228 | ||
6226 | if (register_pernet_subsys(&netdev_net_ops)) | 6229 | if (register_pernet_subsys(&netdev_net_ops)) |
6227 | goto out; | 6230 | goto out; |
6228 | 6231 | ||
6229 | /* | 6232 | /* |
6230 | * Initialise the packet receive queues. | 6233 | * Initialise the packet receive queues. |
6231 | */ | 6234 | */ |
6232 | 6235 | ||
6233 | for_each_possible_cpu(i) { | 6236 | for_each_possible_cpu(i) { |
6234 | struct softnet_data *sd = &per_cpu(softnet_data, i); | 6237 | struct softnet_data *sd = &per_cpu(softnet_data, i); |
6235 | 6238 | ||
6236 | memset(sd, 0, sizeof(*sd)); | 6239 | memset(sd, 0, sizeof(*sd)); |
6237 | skb_queue_head_init(&sd->input_pkt_queue); | 6240 | skb_queue_head_init(&sd->input_pkt_queue); |
6238 | skb_queue_head_init(&sd->process_queue); | 6241 | skb_queue_head_init(&sd->process_queue); |
6239 | sd->completion_queue = NULL; | 6242 | sd->completion_queue = NULL; |
6240 | INIT_LIST_HEAD(&sd->poll_list); | 6243 | INIT_LIST_HEAD(&sd->poll_list); |
6241 | sd->output_queue = NULL; | 6244 | sd->output_queue = NULL; |
6242 | sd->output_queue_tailp = &sd->output_queue; | 6245 | sd->output_queue_tailp = &sd->output_queue; |
6243 | #ifdef CONFIG_RPS | 6246 | #ifdef CONFIG_RPS |
6244 | sd->csd.func = rps_trigger_softirq; | 6247 | sd->csd.func = rps_trigger_softirq; |
6245 | sd->csd.info = sd; | 6248 | sd->csd.info = sd; |
6246 | sd->csd.flags = 0; | 6249 | sd->csd.flags = 0; |
6247 | sd->cpu = i; | 6250 | sd->cpu = i; |
6248 | #endif | 6251 | #endif |
6249 | 6252 | ||
6250 | sd->backlog.poll = process_backlog; | 6253 | sd->backlog.poll = process_backlog; |
6251 | sd->backlog.weight = weight_p; | 6254 | sd->backlog.weight = weight_p; |
6252 | sd->backlog.gro_list = NULL; | 6255 | sd->backlog.gro_list = NULL; |
6253 | sd->backlog.gro_count = 0; | 6256 | sd->backlog.gro_count = 0; |
6254 | } | 6257 | } |
6255 | 6258 | ||
6256 | dev_boot_phase = 0; | 6259 | dev_boot_phase = 0; |
6257 | 6260 | ||
6258 | /* The loopback device is special if any other network devices | 6261 | /* The loopback device is special if any other network devices |
6259 | * is present in a network namespace the loopback device must | 6262 | * is present in a network namespace the loopback device must |
6260 | * be present. Since we now dynamically allocate and free the | 6263 | * be present. Since we now dynamically allocate and free the |
6261 | * loopback device ensure this invariant is maintained by | 6264 | * loopback device ensure this invariant is maintained by |
6262 | * keeping the loopback device as the first device on the | 6265 | * keeping the loopback device as the first device on the |
6263 | * list of network devices. Ensuring the loopback devices | 6266 | * list of network devices. Ensuring the loopback devices |
6264 | * is the first device that appears and the last network device | 6267 | * is the first device that appears and the last network device |
6265 | * that disappears. | 6268 | * that disappears. |
6266 | */ | 6269 | */ |
6267 | if (register_pernet_device(&loopback_net_ops)) | 6270 | if (register_pernet_device(&loopback_net_ops)) |
6268 | goto out; | 6271 | goto out; |
6269 | 6272 | ||
6270 | if (register_pernet_device(&default_device_ops)) | 6273 | if (register_pernet_device(&default_device_ops)) |
6271 | goto out; | 6274 | goto out; |
6272 | 6275 | ||
6273 | open_softirq(NET_TX_SOFTIRQ, net_tx_action); | 6276 | open_softirq(NET_TX_SOFTIRQ, net_tx_action); |
6274 | open_softirq(NET_RX_SOFTIRQ, net_rx_action); | 6277 | open_softirq(NET_RX_SOFTIRQ, net_rx_action); |
6275 | 6278 | ||
6276 | hotcpu_notifier(dev_cpu_callback, 0); | 6279 | hotcpu_notifier(dev_cpu_callback, 0); |
6277 | dst_init(); | 6280 | dst_init(); |
6278 | dev_mcast_init(); | 6281 | dev_mcast_init(); |
6279 | rc = 0; | 6282 | rc = 0; |
6280 | out: | 6283 | out: |
6281 | return rc; | 6284 | return rc; |
6282 | } | 6285 | } |
6283 | 6286 | ||
6284 | subsys_initcall(net_dev_init); | 6287 | subsys_initcall(net_dev_init); |
6285 | 6288 | ||
6286 | static int __init initialize_hashrnd(void) | 6289 | static int __init initialize_hashrnd(void) |
6287 | { | 6290 | { |
6288 | get_random_bytes(&hashrnd, sizeof(hashrnd)); | 6291 | get_random_bytes(&hashrnd, sizeof(hashrnd)); |
6289 | return 0; | 6292 | return 0; |
6290 | } | 6293 | } |
6291 | 6294 | ||
6292 | late_initcall_sync(initialize_hashrnd); | 6295 | late_initcall_sync(initialize_hashrnd); |
net/core/net-sysfs.c
1 | /* | 1 | /* |
2 | * net-sysfs.c - network device class and attributes | 2 | * net-sysfs.c - network device class and attributes |
3 | * | 3 | * |
4 | * Copyright (c) 2003 Stephen Hemminger <shemminger@osdl.org> | 4 | * Copyright (c) 2003 Stephen Hemminger <shemminger@osdl.org> |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or | 6 | * This program is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU General Public License | 7 | * modify it under the terms of the GNU General Public License |
8 | * as published by the Free Software Foundation; either version | 8 | * as published by the Free Software Foundation; either version |
9 | * 2 of the License, or (at your option) any later version. | 9 | * 2 of the License, or (at your option) any later version. |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/capability.h> | 12 | #include <linux/capability.h> |
13 | #include <linux/kernel.h> | 13 | #include <linux/kernel.h> |
14 | #include <linux/netdevice.h> | 14 | #include <linux/netdevice.h> |
15 | #include <linux/if_arp.h> | 15 | #include <linux/if_arp.h> |
16 | #include <linux/slab.h> | 16 | #include <linux/slab.h> |
17 | #include <linux/nsproxy.h> | 17 | #include <linux/nsproxy.h> |
18 | #include <net/sock.h> | 18 | #include <net/sock.h> |
19 | #include <net/net_namespace.h> | 19 | #include <net/net_namespace.h> |
20 | #include <linux/rtnetlink.h> | 20 | #include <linux/rtnetlink.h> |
21 | #include <linux/wireless.h> | 21 | #include <linux/wireless.h> |
22 | #include <linux/vmalloc.h> | 22 | #include <linux/vmalloc.h> |
23 | #include <net/wext.h> | 23 | #include <net/wext.h> |
24 | 24 | ||
25 | #include "net-sysfs.h" | 25 | #include "net-sysfs.h" |
26 | 26 | ||
27 | #ifdef CONFIG_SYSFS | 27 | #ifdef CONFIG_SYSFS |
28 | static const char fmt_hex[] = "%#x\n"; | 28 | static const char fmt_hex[] = "%#x\n"; |
29 | static const char fmt_long_hex[] = "%#lx\n"; | 29 | static const char fmt_long_hex[] = "%#lx\n"; |
30 | static const char fmt_dec[] = "%d\n"; | 30 | static const char fmt_dec[] = "%d\n"; |
31 | static const char fmt_ulong[] = "%lu\n"; | 31 | static const char fmt_ulong[] = "%lu\n"; |
32 | static const char fmt_u64[] = "%llu\n"; | 32 | static const char fmt_u64[] = "%llu\n"; |
33 | 33 | ||
34 | static inline int dev_isalive(const struct net_device *dev) | 34 | static inline int dev_isalive(const struct net_device *dev) |
35 | { | 35 | { |
36 | return dev->reg_state <= NETREG_REGISTERED; | 36 | return dev->reg_state <= NETREG_REGISTERED; |
37 | } | 37 | } |
38 | 38 | ||
39 | /* use same locking rules as GIF* ioctl's */ | 39 | /* use same locking rules as GIF* ioctl's */ |
40 | static ssize_t netdev_show(const struct device *dev, | 40 | static ssize_t netdev_show(const struct device *dev, |
41 | struct device_attribute *attr, char *buf, | 41 | struct device_attribute *attr, char *buf, |
42 | ssize_t (*format)(const struct net_device *, char *)) | 42 | ssize_t (*format)(const struct net_device *, char *)) |
43 | { | 43 | { |
44 | struct net_device *net = to_net_dev(dev); | 44 | struct net_device *net = to_net_dev(dev); |
45 | ssize_t ret = -EINVAL; | 45 | ssize_t ret = -EINVAL; |
46 | 46 | ||
47 | read_lock(&dev_base_lock); | 47 | read_lock(&dev_base_lock); |
48 | if (dev_isalive(net)) | 48 | if (dev_isalive(net)) |
49 | ret = (*format)(net, buf); | 49 | ret = (*format)(net, buf); |
50 | read_unlock(&dev_base_lock); | 50 | read_unlock(&dev_base_lock); |
51 | 51 | ||
52 | return ret; | 52 | return ret; |
53 | } | 53 | } |
54 | 54 | ||
55 | /* generate a show function for simple field */ | 55 | /* generate a show function for simple field */ |
56 | #define NETDEVICE_SHOW(field, format_string) \ | 56 | #define NETDEVICE_SHOW(field, format_string) \ |
57 | static ssize_t format_##field(const struct net_device *net, char *buf) \ | 57 | static ssize_t format_##field(const struct net_device *net, char *buf) \ |
58 | { \ | 58 | { \ |
59 | return sprintf(buf, format_string, net->field); \ | 59 | return sprintf(buf, format_string, net->field); \ |
60 | } \ | 60 | } \ |
61 | static ssize_t show_##field(struct device *dev, \ | 61 | static ssize_t show_##field(struct device *dev, \ |
62 | struct device_attribute *attr, char *buf) \ | 62 | struct device_attribute *attr, char *buf) \ |
63 | { \ | 63 | { \ |
64 | return netdev_show(dev, attr, buf, format_##field); \ | 64 | return netdev_show(dev, attr, buf, format_##field); \ |
65 | } | 65 | } |
66 | 66 | ||
67 | 67 | ||
68 | /* use same locking and permission rules as SIF* ioctl's */ | 68 | /* use same locking and permission rules as SIF* ioctl's */ |
69 | static ssize_t netdev_store(struct device *dev, struct device_attribute *attr, | 69 | static ssize_t netdev_store(struct device *dev, struct device_attribute *attr, |
70 | const char *buf, size_t len, | 70 | const char *buf, size_t len, |
71 | int (*set)(struct net_device *, unsigned long)) | 71 | int (*set)(struct net_device *, unsigned long)) |
72 | { | 72 | { |
73 | struct net_device *net = to_net_dev(dev); | 73 | struct net_device *net = to_net_dev(dev); |
74 | char *endp; | 74 | char *endp; |
75 | unsigned long new; | 75 | unsigned long new; |
76 | int ret = -EINVAL; | 76 | int ret = -EINVAL; |
77 | 77 | ||
78 | if (!capable(CAP_NET_ADMIN)) | 78 | if (!capable(CAP_NET_ADMIN)) |
79 | return -EPERM; | 79 | return -EPERM; |
80 | 80 | ||
81 | new = simple_strtoul(buf, &endp, 0); | 81 | new = simple_strtoul(buf, &endp, 0); |
82 | if (endp == buf) | 82 | if (endp == buf) |
83 | goto err; | 83 | goto err; |
84 | 84 | ||
85 | if (!rtnl_trylock()) | 85 | if (!rtnl_trylock()) |
86 | return restart_syscall(); | 86 | return restart_syscall(); |
87 | 87 | ||
88 | if (dev_isalive(net)) { | 88 | if (dev_isalive(net)) { |
89 | if ((ret = (*set)(net, new)) == 0) | 89 | if ((ret = (*set)(net, new)) == 0) |
90 | ret = len; | 90 | ret = len; |
91 | } | 91 | } |
92 | rtnl_unlock(); | 92 | rtnl_unlock(); |
93 | err: | 93 | err: |
94 | return ret; | 94 | return ret; |
95 | } | 95 | } |
96 | 96 | ||
97 | NETDEVICE_SHOW(dev_id, fmt_hex); | 97 | NETDEVICE_SHOW(dev_id, fmt_hex); |
98 | NETDEVICE_SHOW(addr_assign_type, fmt_dec); | 98 | NETDEVICE_SHOW(addr_assign_type, fmt_dec); |
99 | NETDEVICE_SHOW(addr_len, fmt_dec); | 99 | NETDEVICE_SHOW(addr_len, fmt_dec); |
100 | NETDEVICE_SHOW(iflink, fmt_dec); | 100 | NETDEVICE_SHOW(iflink, fmt_dec); |
101 | NETDEVICE_SHOW(ifindex, fmt_dec); | 101 | NETDEVICE_SHOW(ifindex, fmt_dec); |
102 | NETDEVICE_SHOW(features, fmt_long_hex); | 102 | NETDEVICE_SHOW(features, fmt_long_hex); |
103 | NETDEVICE_SHOW(type, fmt_dec); | 103 | NETDEVICE_SHOW(type, fmt_dec); |
104 | NETDEVICE_SHOW(link_mode, fmt_dec); | 104 | NETDEVICE_SHOW(link_mode, fmt_dec); |
105 | 105 | ||
106 | /* use same locking rules as GIFHWADDR ioctl's */ | 106 | /* use same locking rules as GIFHWADDR ioctl's */ |
107 | static ssize_t show_address(struct device *dev, struct device_attribute *attr, | 107 | static ssize_t show_address(struct device *dev, struct device_attribute *attr, |
108 | char *buf) | 108 | char *buf) |
109 | { | 109 | { |
110 | struct net_device *net = to_net_dev(dev); | 110 | struct net_device *net = to_net_dev(dev); |
111 | ssize_t ret = -EINVAL; | 111 | ssize_t ret = -EINVAL; |
112 | 112 | ||
113 | read_lock(&dev_base_lock); | 113 | read_lock(&dev_base_lock); |
114 | if (dev_isalive(net)) | 114 | if (dev_isalive(net)) |
115 | ret = sysfs_format_mac(buf, net->dev_addr, net->addr_len); | 115 | ret = sysfs_format_mac(buf, net->dev_addr, net->addr_len); |
116 | read_unlock(&dev_base_lock); | 116 | read_unlock(&dev_base_lock); |
117 | return ret; | 117 | return ret; |
118 | } | 118 | } |
119 | 119 | ||
120 | static ssize_t show_broadcast(struct device *dev, | 120 | static ssize_t show_broadcast(struct device *dev, |
121 | struct device_attribute *attr, char *buf) | 121 | struct device_attribute *attr, char *buf) |
122 | { | 122 | { |
123 | struct net_device *net = to_net_dev(dev); | 123 | struct net_device *net = to_net_dev(dev); |
124 | if (dev_isalive(net)) | 124 | if (dev_isalive(net)) |
125 | return sysfs_format_mac(buf, net->broadcast, net->addr_len); | 125 | return sysfs_format_mac(buf, net->broadcast, net->addr_len); |
126 | return -EINVAL; | 126 | return -EINVAL; |
127 | } | 127 | } |
128 | 128 | ||
129 | static ssize_t show_carrier(struct device *dev, | 129 | static ssize_t show_carrier(struct device *dev, |
130 | struct device_attribute *attr, char *buf) | 130 | struct device_attribute *attr, char *buf) |
131 | { | 131 | { |
132 | struct net_device *netdev = to_net_dev(dev); | 132 | struct net_device *netdev = to_net_dev(dev); |
133 | if (netif_running(netdev)) { | 133 | if (netif_running(netdev)) { |
134 | return sprintf(buf, fmt_dec, !!netif_carrier_ok(netdev)); | 134 | return sprintf(buf, fmt_dec, !!netif_carrier_ok(netdev)); |
135 | } | 135 | } |
136 | return -EINVAL; | 136 | return -EINVAL; |
137 | } | 137 | } |
138 | 138 | ||
139 | static ssize_t show_speed(struct device *dev, | 139 | static ssize_t show_speed(struct device *dev, |
140 | struct device_attribute *attr, char *buf) | 140 | struct device_attribute *attr, char *buf) |
141 | { | 141 | { |
142 | struct net_device *netdev = to_net_dev(dev); | 142 | struct net_device *netdev = to_net_dev(dev); |
143 | int ret = -EINVAL; | 143 | int ret = -EINVAL; |
144 | 144 | ||
145 | if (!rtnl_trylock()) | 145 | if (!rtnl_trylock()) |
146 | return restart_syscall(); | 146 | return restart_syscall(); |
147 | 147 | ||
148 | if (netif_running(netdev) && | 148 | if (netif_running(netdev) && |
149 | netdev->ethtool_ops && | 149 | netdev->ethtool_ops && |
150 | netdev->ethtool_ops->get_settings) { | 150 | netdev->ethtool_ops->get_settings) { |
151 | struct ethtool_cmd cmd = { ETHTOOL_GSET }; | 151 | struct ethtool_cmd cmd = { ETHTOOL_GSET }; |
152 | 152 | ||
153 | if (!netdev->ethtool_ops->get_settings(netdev, &cmd)) | 153 | if (!netdev->ethtool_ops->get_settings(netdev, &cmd)) |
154 | ret = sprintf(buf, fmt_dec, ethtool_cmd_speed(&cmd)); | 154 | ret = sprintf(buf, fmt_dec, ethtool_cmd_speed(&cmd)); |
155 | } | 155 | } |
156 | rtnl_unlock(); | 156 | rtnl_unlock(); |
157 | return ret; | 157 | return ret; |
158 | } | 158 | } |
159 | 159 | ||
160 | static ssize_t show_duplex(struct device *dev, | 160 | static ssize_t show_duplex(struct device *dev, |
161 | struct device_attribute *attr, char *buf) | 161 | struct device_attribute *attr, char *buf) |
162 | { | 162 | { |
163 | struct net_device *netdev = to_net_dev(dev); | 163 | struct net_device *netdev = to_net_dev(dev); |
164 | int ret = -EINVAL; | 164 | int ret = -EINVAL; |
165 | 165 | ||
166 | if (!rtnl_trylock()) | 166 | if (!rtnl_trylock()) |
167 | return restart_syscall(); | 167 | return restart_syscall(); |
168 | 168 | ||
169 | if (netif_running(netdev) && | 169 | if (netif_running(netdev) && |
170 | netdev->ethtool_ops && | 170 | netdev->ethtool_ops && |
171 | netdev->ethtool_ops->get_settings) { | 171 | netdev->ethtool_ops->get_settings) { |
172 | struct ethtool_cmd cmd = { ETHTOOL_GSET }; | 172 | struct ethtool_cmd cmd = { ETHTOOL_GSET }; |
173 | 173 | ||
174 | if (!netdev->ethtool_ops->get_settings(netdev, &cmd)) | 174 | if (!netdev->ethtool_ops->get_settings(netdev, &cmd)) |
175 | ret = sprintf(buf, "%s\n", cmd.duplex ? "full" : "half"); | 175 | ret = sprintf(buf, "%s\n", cmd.duplex ? "full" : "half"); |
176 | } | 176 | } |
177 | rtnl_unlock(); | 177 | rtnl_unlock(); |
178 | return ret; | 178 | return ret; |
179 | } | 179 | } |
180 | 180 | ||
181 | static ssize_t show_dormant(struct device *dev, | 181 | static ssize_t show_dormant(struct device *dev, |
182 | struct device_attribute *attr, char *buf) | 182 | struct device_attribute *attr, char *buf) |
183 | { | 183 | { |
184 | struct net_device *netdev = to_net_dev(dev); | 184 | struct net_device *netdev = to_net_dev(dev); |
185 | 185 | ||
186 | if (netif_running(netdev)) | 186 | if (netif_running(netdev)) |
187 | return sprintf(buf, fmt_dec, !!netif_dormant(netdev)); | 187 | return sprintf(buf, fmt_dec, !!netif_dormant(netdev)); |
188 | 188 | ||
189 | return -EINVAL; | 189 | return -EINVAL; |
190 | } | 190 | } |
191 | 191 | ||
192 | static const char *const operstates[] = { | 192 | static const char *const operstates[] = { |
193 | "unknown", | 193 | "unknown", |
194 | "notpresent", /* currently unused */ | 194 | "notpresent", /* currently unused */ |
195 | "down", | 195 | "down", |
196 | "lowerlayerdown", | 196 | "lowerlayerdown", |
197 | "testing", /* currently unused */ | 197 | "testing", /* currently unused */ |
198 | "dormant", | 198 | "dormant", |
199 | "up" | 199 | "up" |
200 | }; | 200 | }; |
201 | 201 | ||
202 | static ssize_t show_operstate(struct device *dev, | 202 | static ssize_t show_operstate(struct device *dev, |
203 | struct device_attribute *attr, char *buf) | 203 | struct device_attribute *attr, char *buf) |
204 | { | 204 | { |
205 | const struct net_device *netdev = to_net_dev(dev); | 205 | const struct net_device *netdev = to_net_dev(dev); |
206 | unsigned char operstate; | 206 | unsigned char operstate; |
207 | 207 | ||
208 | read_lock(&dev_base_lock); | 208 | read_lock(&dev_base_lock); |
209 | operstate = netdev->operstate; | 209 | operstate = netdev->operstate; |
210 | if (!netif_running(netdev)) | 210 | if (!netif_running(netdev)) |
211 | operstate = IF_OPER_DOWN; | 211 | operstate = IF_OPER_DOWN; |
212 | read_unlock(&dev_base_lock); | 212 | read_unlock(&dev_base_lock); |
213 | 213 | ||
214 | if (operstate >= ARRAY_SIZE(operstates)) | 214 | if (operstate >= ARRAY_SIZE(operstates)) |
215 | return -EINVAL; /* should not happen */ | 215 | return -EINVAL; /* should not happen */ |
216 | 216 | ||
217 | return sprintf(buf, "%s\n", operstates[operstate]); | 217 | return sprintf(buf, "%s\n", operstates[operstate]); |
218 | } | 218 | } |
219 | 219 | ||
220 | /* read-write attributes */ | 220 | /* read-write attributes */ |
221 | NETDEVICE_SHOW(mtu, fmt_dec); | 221 | NETDEVICE_SHOW(mtu, fmt_dec); |
222 | 222 | ||
223 | static int change_mtu(struct net_device *net, unsigned long new_mtu) | 223 | static int change_mtu(struct net_device *net, unsigned long new_mtu) |
224 | { | 224 | { |
225 | return dev_set_mtu(net, (int) new_mtu); | 225 | return dev_set_mtu(net, (int) new_mtu); |
226 | } | 226 | } |
227 | 227 | ||
228 | static ssize_t store_mtu(struct device *dev, struct device_attribute *attr, | 228 | static ssize_t store_mtu(struct device *dev, struct device_attribute *attr, |
229 | const char *buf, size_t len) | 229 | const char *buf, size_t len) |
230 | { | 230 | { |
231 | return netdev_store(dev, attr, buf, len, change_mtu); | 231 | return netdev_store(dev, attr, buf, len, change_mtu); |
232 | } | 232 | } |
233 | 233 | ||
234 | NETDEVICE_SHOW(flags, fmt_hex); | 234 | NETDEVICE_SHOW(flags, fmt_hex); |
235 | 235 | ||
236 | static int change_flags(struct net_device *net, unsigned long new_flags) | 236 | static int change_flags(struct net_device *net, unsigned long new_flags) |
237 | { | 237 | { |
238 | return dev_change_flags(net, (unsigned) new_flags); | 238 | return dev_change_flags(net, (unsigned) new_flags); |
239 | } | 239 | } |
240 | 240 | ||
241 | static ssize_t store_flags(struct device *dev, struct device_attribute *attr, | 241 | static ssize_t store_flags(struct device *dev, struct device_attribute *attr, |
242 | const char *buf, size_t len) | 242 | const char *buf, size_t len) |
243 | { | 243 | { |
244 | return netdev_store(dev, attr, buf, len, change_flags); | 244 | return netdev_store(dev, attr, buf, len, change_flags); |
245 | } | 245 | } |
246 | 246 | ||
247 | NETDEVICE_SHOW(tx_queue_len, fmt_ulong); | 247 | NETDEVICE_SHOW(tx_queue_len, fmt_ulong); |
248 | 248 | ||
249 | static int change_tx_queue_len(struct net_device *net, unsigned long new_len) | 249 | static int change_tx_queue_len(struct net_device *net, unsigned long new_len) |
250 | { | 250 | { |
251 | net->tx_queue_len = new_len; | 251 | net->tx_queue_len = new_len; |
252 | return 0; | 252 | return 0; |
253 | } | 253 | } |
254 | 254 | ||
255 | static ssize_t store_tx_queue_len(struct device *dev, | 255 | static ssize_t store_tx_queue_len(struct device *dev, |
256 | struct device_attribute *attr, | 256 | struct device_attribute *attr, |
257 | const char *buf, size_t len) | 257 | const char *buf, size_t len) |
258 | { | 258 | { |
259 | return netdev_store(dev, attr, buf, len, change_tx_queue_len); | 259 | return netdev_store(dev, attr, buf, len, change_tx_queue_len); |
260 | } | 260 | } |
261 | 261 | ||
262 | static ssize_t store_ifalias(struct device *dev, struct device_attribute *attr, | 262 | static ssize_t store_ifalias(struct device *dev, struct device_attribute *attr, |
263 | const char *buf, size_t len) | 263 | const char *buf, size_t len) |
264 | { | 264 | { |
265 | struct net_device *netdev = to_net_dev(dev); | 265 | struct net_device *netdev = to_net_dev(dev); |
266 | size_t count = len; | 266 | size_t count = len; |
267 | ssize_t ret; | 267 | ssize_t ret; |
268 | 268 | ||
269 | if (!capable(CAP_NET_ADMIN)) | 269 | if (!capable(CAP_NET_ADMIN)) |
270 | return -EPERM; | 270 | return -EPERM; |
271 | 271 | ||
272 | /* ignore trailing newline */ | 272 | /* ignore trailing newline */ |
273 | if (len > 0 && buf[len - 1] == '\n') | 273 | if (len > 0 && buf[len - 1] == '\n') |
274 | --count; | 274 | --count; |
275 | 275 | ||
276 | if (!rtnl_trylock()) | 276 | if (!rtnl_trylock()) |
277 | return restart_syscall(); | 277 | return restart_syscall(); |
278 | ret = dev_set_alias(netdev, buf, count); | 278 | ret = dev_set_alias(netdev, buf, count); |
279 | rtnl_unlock(); | 279 | rtnl_unlock(); |
280 | 280 | ||
281 | return ret < 0 ? ret : len; | 281 | return ret < 0 ? ret : len; |
282 | } | 282 | } |
283 | 283 | ||
284 | static ssize_t show_ifalias(struct device *dev, | 284 | static ssize_t show_ifalias(struct device *dev, |
285 | struct device_attribute *attr, char *buf) | 285 | struct device_attribute *attr, char *buf) |
286 | { | 286 | { |
287 | const struct net_device *netdev = to_net_dev(dev); | 287 | const struct net_device *netdev = to_net_dev(dev); |
288 | ssize_t ret = 0; | 288 | ssize_t ret = 0; |
289 | 289 | ||
290 | if (!rtnl_trylock()) | 290 | if (!rtnl_trylock()) |
291 | return restart_syscall(); | 291 | return restart_syscall(); |
292 | if (netdev->ifalias) | 292 | if (netdev->ifalias) |
293 | ret = sprintf(buf, "%s\n", netdev->ifalias); | 293 | ret = sprintf(buf, "%s\n", netdev->ifalias); |
294 | rtnl_unlock(); | 294 | rtnl_unlock(); |
295 | return ret; | 295 | return ret; |
296 | } | 296 | } |
297 | 297 | ||
298 | static struct device_attribute net_class_attributes[] = { | 298 | static struct device_attribute net_class_attributes[] = { |
299 | __ATTR(addr_assign_type, S_IRUGO, show_addr_assign_type, NULL), | 299 | __ATTR(addr_assign_type, S_IRUGO, show_addr_assign_type, NULL), |
300 | __ATTR(addr_len, S_IRUGO, show_addr_len, NULL), | 300 | __ATTR(addr_len, S_IRUGO, show_addr_len, NULL), |
301 | __ATTR(dev_id, S_IRUGO, show_dev_id, NULL), | 301 | __ATTR(dev_id, S_IRUGO, show_dev_id, NULL), |
302 | __ATTR(ifalias, S_IRUGO | S_IWUSR, show_ifalias, store_ifalias), | 302 | __ATTR(ifalias, S_IRUGO | S_IWUSR, show_ifalias, store_ifalias), |
303 | __ATTR(iflink, S_IRUGO, show_iflink, NULL), | 303 | __ATTR(iflink, S_IRUGO, show_iflink, NULL), |
304 | __ATTR(ifindex, S_IRUGO, show_ifindex, NULL), | 304 | __ATTR(ifindex, S_IRUGO, show_ifindex, NULL), |
305 | __ATTR(features, S_IRUGO, show_features, NULL), | 305 | __ATTR(features, S_IRUGO, show_features, NULL), |
306 | __ATTR(type, S_IRUGO, show_type, NULL), | 306 | __ATTR(type, S_IRUGO, show_type, NULL), |
307 | __ATTR(link_mode, S_IRUGO, show_link_mode, NULL), | 307 | __ATTR(link_mode, S_IRUGO, show_link_mode, NULL), |
308 | __ATTR(address, S_IRUGO, show_address, NULL), | 308 | __ATTR(address, S_IRUGO, show_address, NULL), |
309 | __ATTR(broadcast, S_IRUGO, show_broadcast, NULL), | 309 | __ATTR(broadcast, S_IRUGO, show_broadcast, NULL), |
310 | __ATTR(carrier, S_IRUGO, show_carrier, NULL), | 310 | __ATTR(carrier, S_IRUGO, show_carrier, NULL), |
311 | __ATTR(speed, S_IRUGO, show_speed, NULL), | 311 | __ATTR(speed, S_IRUGO, show_speed, NULL), |
312 | __ATTR(duplex, S_IRUGO, show_duplex, NULL), | 312 | __ATTR(duplex, S_IRUGO, show_duplex, NULL), |
313 | __ATTR(dormant, S_IRUGO, show_dormant, NULL), | 313 | __ATTR(dormant, S_IRUGO, show_dormant, NULL), |
314 | __ATTR(operstate, S_IRUGO, show_operstate, NULL), | 314 | __ATTR(operstate, S_IRUGO, show_operstate, NULL), |
315 | __ATTR(mtu, S_IRUGO | S_IWUSR, show_mtu, store_mtu), | 315 | __ATTR(mtu, S_IRUGO | S_IWUSR, show_mtu, store_mtu), |
316 | __ATTR(flags, S_IRUGO | S_IWUSR, show_flags, store_flags), | 316 | __ATTR(flags, S_IRUGO | S_IWUSR, show_flags, store_flags), |
317 | __ATTR(tx_queue_len, S_IRUGO | S_IWUSR, show_tx_queue_len, | 317 | __ATTR(tx_queue_len, S_IRUGO | S_IWUSR, show_tx_queue_len, |
318 | store_tx_queue_len), | 318 | store_tx_queue_len), |
319 | {} | 319 | {} |
320 | }; | 320 | }; |
321 | 321 | ||
322 | /* Show a given an attribute in the statistics group */ | 322 | /* Show a given an attribute in the statistics group */ |
323 | static ssize_t netstat_show(const struct device *d, | 323 | static ssize_t netstat_show(const struct device *d, |
324 | struct device_attribute *attr, char *buf, | 324 | struct device_attribute *attr, char *buf, |
325 | unsigned long offset) | 325 | unsigned long offset) |
326 | { | 326 | { |
327 | struct net_device *dev = to_net_dev(d); | 327 | struct net_device *dev = to_net_dev(d); |
328 | ssize_t ret = -EINVAL; | 328 | ssize_t ret = -EINVAL; |
329 | 329 | ||
330 | WARN_ON(offset > sizeof(struct rtnl_link_stats64) || | 330 | WARN_ON(offset > sizeof(struct rtnl_link_stats64) || |
331 | offset % sizeof(u64) != 0); | 331 | offset % sizeof(u64) != 0); |
332 | 332 | ||
333 | read_lock(&dev_base_lock); | 333 | read_lock(&dev_base_lock); |
334 | if (dev_isalive(dev)) { | 334 | if (dev_isalive(dev)) { |
335 | struct rtnl_link_stats64 temp; | 335 | struct rtnl_link_stats64 temp; |
336 | const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp); | 336 | const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp); |
337 | 337 | ||
338 | ret = sprintf(buf, fmt_u64, *(u64 *)(((u8 *) stats) + offset)); | 338 | ret = sprintf(buf, fmt_u64, *(u64 *)(((u8 *) stats) + offset)); |
339 | } | 339 | } |
340 | read_unlock(&dev_base_lock); | 340 | read_unlock(&dev_base_lock); |
341 | return ret; | 341 | return ret; |
342 | } | 342 | } |
343 | 343 | ||
344 | /* generate a read-only statistics attribute */ | 344 | /* generate a read-only statistics attribute */ |
345 | #define NETSTAT_ENTRY(name) \ | 345 | #define NETSTAT_ENTRY(name) \ |
346 | static ssize_t show_##name(struct device *d, \ | 346 | static ssize_t show_##name(struct device *d, \ |
347 | struct device_attribute *attr, char *buf) \ | 347 | struct device_attribute *attr, char *buf) \ |
348 | { \ | 348 | { \ |
349 | return netstat_show(d, attr, buf, \ | 349 | return netstat_show(d, attr, buf, \ |
350 | offsetof(struct rtnl_link_stats64, name)); \ | 350 | offsetof(struct rtnl_link_stats64, name)); \ |
351 | } \ | 351 | } \ |
352 | static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL) | 352 | static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL) |
353 | 353 | ||
354 | NETSTAT_ENTRY(rx_packets); | 354 | NETSTAT_ENTRY(rx_packets); |
355 | NETSTAT_ENTRY(tx_packets); | 355 | NETSTAT_ENTRY(tx_packets); |
356 | NETSTAT_ENTRY(rx_bytes); | 356 | NETSTAT_ENTRY(rx_bytes); |
357 | NETSTAT_ENTRY(tx_bytes); | 357 | NETSTAT_ENTRY(tx_bytes); |
358 | NETSTAT_ENTRY(rx_errors); | 358 | NETSTAT_ENTRY(rx_errors); |
359 | NETSTAT_ENTRY(tx_errors); | 359 | NETSTAT_ENTRY(tx_errors); |
360 | NETSTAT_ENTRY(rx_dropped); | 360 | NETSTAT_ENTRY(rx_dropped); |
361 | NETSTAT_ENTRY(tx_dropped); | 361 | NETSTAT_ENTRY(tx_dropped); |
362 | NETSTAT_ENTRY(multicast); | 362 | NETSTAT_ENTRY(multicast); |
363 | NETSTAT_ENTRY(collisions); | 363 | NETSTAT_ENTRY(collisions); |
364 | NETSTAT_ENTRY(rx_length_errors); | 364 | NETSTAT_ENTRY(rx_length_errors); |
365 | NETSTAT_ENTRY(rx_over_errors); | 365 | NETSTAT_ENTRY(rx_over_errors); |
366 | NETSTAT_ENTRY(rx_crc_errors); | 366 | NETSTAT_ENTRY(rx_crc_errors); |
367 | NETSTAT_ENTRY(rx_frame_errors); | 367 | NETSTAT_ENTRY(rx_frame_errors); |
368 | NETSTAT_ENTRY(rx_fifo_errors); | 368 | NETSTAT_ENTRY(rx_fifo_errors); |
369 | NETSTAT_ENTRY(rx_missed_errors); | 369 | NETSTAT_ENTRY(rx_missed_errors); |
370 | NETSTAT_ENTRY(tx_aborted_errors); | 370 | NETSTAT_ENTRY(tx_aborted_errors); |
371 | NETSTAT_ENTRY(tx_carrier_errors); | 371 | NETSTAT_ENTRY(tx_carrier_errors); |
372 | NETSTAT_ENTRY(tx_fifo_errors); | 372 | NETSTAT_ENTRY(tx_fifo_errors); |
373 | NETSTAT_ENTRY(tx_heartbeat_errors); | 373 | NETSTAT_ENTRY(tx_heartbeat_errors); |
374 | NETSTAT_ENTRY(tx_window_errors); | 374 | NETSTAT_ENTRY(tx_window_errors); |
375 | NETSTAT_ENTRY(rx_compressed); | 375 | NETSTAT_ENTRY(rx_compressed); |
376 | NETSTAT_ENTRY(tx_compressed); | 376 | NETSTAT_ENTRY(tx_compressed); |
377 | 377 | ||
378 | static struct attribute *netstat_attrs[] = { | 378 | static struct attribute *netstat_attrs[] = { |
379 | &dev_attr_rx_packets.attr, | 379 | &dev_attr_rx_packets.attr, |
380 | &dev_attr_tx_packets.attr, | 380 | &dev_attr_tx_packets.attr, |
381 | &dev_attr_rx_bytes.attr, | 381 | &dev_attr_rx_bytes.attr, |
382 | &dev_attr_tx_bytes.attr, | 382 | &dev_attr_tx_bytes.attr, |
383 | &dev_attr_rx_errors.attr, | 383 | &dev_attr_rx_errors.attr, |
384 | &dev_attr_tx_errors.attr, | 384 | &dev_attr_tx_errors.attr, |
385 | &dev_attr_rx_dropped.attr, | 385 | &dev_attr_rx_dropped.attr, |
386 | &dev_attr_tx_dropped.attr, | 386 | &dev_attr_tx_dropped.attr, |
387 | &dev_attr_multicast.attr, | 387 | &dev_attr_multicast.attr, |
388 | &dev_attr_collisions.attr, | 388 | &dev_attr_collisions.attr, |
389 | &dev_attr_rx_length_errors.attr, | 389 | &dev_attr_rx_length_errors.attr, |
390 | &dev_attr_rx_over_errors.attr, | 390 | &dev_attr_rx_over_errors.attr, |
391 | &dev_attr_rx_crc_errors.attr, | 391 | &dev_attr_rx_crc_errors.attr, |
392 | &dev_attr_rx_frame_errors.attr, | 392 | &dev_attr_rx_frame_errors.attr, |
393 | &dev_attr_rx_fifo_errors.attr, | 393 | &dev_attr_rx_fifo_errors.attr, |
394 | &dev_attr_rx_missed_errors.attr, | 394 | &dev_attr_rx_missed_errors.attr, |
395 | &dev_attr_tx_aborted_errors.attr, | 395 | &dev_attr_tx_aborted_errors.attr, |
396 | &dev_attr_tx_carrier_errors.attr, | 396 | &dev_attr_tx_carrier_errors.attr, |
397 | &dev_attr_tx_fifo_errors.attr, | 397 | &dev_attr_tx_fifo_errors.attr, |
398 | &dev_attr_tx_heartbeat_errors.attr, | 398 | &dev_attr_tx_heartbeat_errors.attr, |
399 | &dev_attr_tx_window_errors.attr, | 399 | &dev_attr_tx_window_errors.attr, |
400 | &dev_attr_rx_compressed.attr, | 400 | &dev_attr_rx_compressed.attr, |
401 | &dev_attr_tx_compressed.attr, | 401 | &dev_attr_tx_compressed.attr, |
402 | NULL | 402 | NULL |
403 | }; | 403 | }; |
404 | 404 | ||
405 | 405 | ||
406 | static struct attribute_group netstat_group = { | 406 | static struct attribute_group netstat_group = { |
407 | .name = "statistics", | 407 | .name = "statistics", |
408 | .attrs = netstat_attrs, | 408 | .attrs = netstat_attrs, |
409 | }; | 409 | }; |
410 | 410 | ||
411 | #ifdef CONFIG_WIRELESS_EXT_SYSFS | 411 | #ifdef CONFIG_WIRELESS_EXT_SYSFS |
412 | /* helper function that does all the locking etc for wireless stats */ | 412 | /* helper function that does all the locking etc for wireless stats */ |
413 | static ssize_t wireless_show(struct device *d, char *buf, | 413 | static ssize_t wireless_show(struct device *d, char *buf, |
414 | ssize_t (*format)(const struct iw_statistics *, | 414 | ssize_t (*format)(const struct iw_statistics *, |
415 | char *)) | 415 | char *)) |
416 | { | 416 | { |
417 | struct net_device *dev = to_net_dev(d); | 417 | struct net_device *dev = to_net_dev(d); |
418 | const struct iw_statistics *iw; | 418 | const struct iw_statistics *iw; |
419 | ssize_t ret = -EINVAL; | 419 | ssize_t ret = -EINVAL; |
420 | 420 | ||
421 | if (!rtnl_trylock()) | 421 | if (!rtnl_trylock()) |
422 | return restart_syscall(); | 422 | return restart_syscall(); |
423 | if (dev_isalive(dev)) { | 423 | if (dev_isalive(dev)) { |
424 | iw = get_wireless_stats(dev); | 424 | iw = get_wireless_stats(dev); |
425 | if (iw) | 425 | if (iw) |
426 | ret = (*format)(iw, buf); | 426 | ret = (*format)(iw, buf); |
427 | } | 427 | } |
428 | rtnl_unlock(); | 428 | rtnl_unlock(); |
429 | 429 | ||
430 | return ret; | 430 | return ret; |
431 | } | 431 | } |
432 | 432 | ||
433 | /* show function template for wireless fields */ | 433 | /* show function template for wireless fields */ |
434 | #define WIRELESS_SHOW(name, field, format_string) \ | 434 | #define WIRELESS_SHOW(name, field, format_string) \ |
435 | static ssize_t format_iw_##name(const struct iw_statistics *iw, char *buf) \ | 435 | static ssize_t format_iw_##name(const struct iw_statistics *iw, char *buf) \ |
436 | { \ | 436 | { \ |
437 | return sprintf(buf, format_string, iw->field); \ | 437 | return sprintf(buf, format_string, iw->field); \ |
438 | } \ | 438 | } \ |
439 | static ssize_t show_iw_##name(struct device *d, \ | 439 | static ssize_t show_iw_##name(struct device *d, \ |
440 | struct device_attribute *attr, char *buf) \ | 440 | struct device_attribute *attr, char *buf) \ |
441 | { \ | 441 | { \ |
442 | return wireless_show(d, buf, format_iw_##name); \ | 442 | return wireless_show(d, buf, format_iw_##name); \ |
443 | } \ | 443 | } \ |
444 | static DEVICE_ATTR(name, S_IRUGO, show_iw_##name, NULL) | 444 | static DEVICE_ATTR(name, S_IRUGO, show_iw_##name, NULL) |
445 | 445 | ||
446 | WIRELESS_SHOW(status, status, fmt_hex); | 446 | WIRELESS_SHOW(status, status, fmt_hex); |
447 | WIRELESS_SHOW(link, qual.qual, fmt_dec); | 447 | WIRELESS_SHOW(link, qual.qual, fmt_dec); |
448 | WIRELESS_SHOW(level, qual.level, fmt_dec); | 448 | WIRELESS_SHOW(level, qual.level, fmt_dec); |
449 | WIRELESS_SHOW(noise, qual.noise, fmt_dec); | 449 | WIRELESS_SHOW(noise, qual.noise, fmt_dec); |
450 | WIRELESS_SHOW(nwid, discard.nwid, fmt_dec); | 450 | WIRELESS_SHOW(nwid, discard.nwid, fmt_dec); |
451 | WIRELESS_SHOW(crypt, discard.code, fmt_dec); | 451 | WIRELESS_SHOW(crypt, discard.code, fmt_dec); |
452 | WIRELESS_SHOW(fragment, discard.fragment, fmt_dec); | 452 | WIRELESS_SHOW(fragment, discard.fragment, fmt_dec); |
453 | WIRELESS_SHOW(misc, discard.misc, fmt_dec); | 453 | WIRELESS_SHOW(misc, discard.misc, fmt_dec); |
454 | WIRELESS_SHOW(retries, discard.retries, fmt_dec); | 454 | WIRELESS_SHOW(retries, discard.retries, fmt_dec); |
455 | WIRELESS_SHOW(beacon, miss.beacon, fmt_dec); | 455 | WIRELESS_SHOW(beacon, miss.beacon, fmt_dec); |
456 | 456 | ||
457 | static struct attribute *wireless_attrs[] = { | 457 | static struct attribute *wireless_attrs[] = { |
458 | &dev_attr_status.attr, | 458 | &dev_attr_status.attr, |
459 | &dev_attr_link.attr, | 459 | &dev_attr_link.attr, |
460 | &dev_attr_level.attr, | 460 | &dev_attr_level.attr, |
461 | &dev_attr_noise.attr, | 461 | &dev_attr_noise.attr, |
462 | &dev_attr_nwid.attr, | 462 | &dev_attr_nwid.attr, |
463 | &dev_attr_crypt.attr, | 463 | &dev_attr_crypt.attr, |
464 | &dev_attr_fragment.attr, | 464 | &dev_attr_fragment.attr, |
465 | &dev_attr_retries.attr, | 465 | &dev_attr_retries.attr, |
466 | &dev_attr_misc.attr, | 466 | &dev_attr_misc.attr, |
467 | &dev_attr_beacon.attr, | 467 | &dev_attr_beacon.attr, |
468 | NULL | 468 | NULL |
469 | }; | 469 | }; |
470 | 470 | ||
471 | static struct attribute_group wireless_group = { | 471 | static struct attribute_group wireless_group = { |
472 | .name = "wireless", | 472 | .name = "wireless", |
473 | .attrs = wireless_attrs, | 473 | .attrs = wireless_attrs, |
474 | }; | 474 | }; |
475 | #endif | 475 | #endif |
476 | #endif /* CONFIG_SYSFS */ | 476 | #endif /* CONFIG_SYSFS */ |
477 | 477 | ||
478 | #ifdef CONFIG_RPS | 478 | #ifdef CONFIG_RPS |
479 | /* | 479 | /* |
480 | * RX queue sysfs structures and functions. | 480 | * RX queue sysfs structures and functions. |
481 | */ | 481 | */ |
482 | struct rx_queue_attribute { | 482 | struct rx_queue_attribute { |
483 | struct attribute attr; | 483 | struct attribute attr; |
484 | ssize_t (*show)(struct netdev_rx_queue *queue, | 484 | ssize_t (*show)(struct netdev_rx_queue *queue, |
485 | struct rx_queue_attribute *attr, char *buf); | 485 | struct rx_queue_attribute *attr, char *buf); |
486 | ssize_t (*store)(struct netdev_rx_queue *queue, | 486 | ssize_t (*store)(struct netdev_rx_queue *queue, |
487 | struct rx_queue_attribute *attr, const char *buf, size_t len); | 487 | struct rx_queue_attribute *attr, const char *buf, size_t len); |
488 | }; | 488 | }; |
489 | #define to_rx_queue_attr(_attr) container_of(_attr, \ | 489 | #define to_rx_queue_attr(_attr) container_of(_attr, \ |
490 | struct rx_queue_attribute, attr) | 490 | struct rx_queue_attribute, attr) |
491 | 491 | ||
492 | #define to_rx_queue(obj) container_of(obj, struct netdev_rx_queue, kobj) | 492 | #define to_rx_queue(obj) container_of(obj, struct netdev_rx_queue, kobj) |
493 | 493 | ||
494 | static ssize_t rx_queue_attr_show(struct kobject *kobj, struct attribute *attr, | 494 | static ssize_t rx_queue_attr_show(struct kobject *kobj, struct attribute *attr, |
495 | char *buf) | 495 | char *buf) |
496 | { | 496 | { |
497 | struct rx_queue_attribute *attribute = to_rx_queue_attr(attr); | 497 | struct rx_queue_attribute *attribute = to_rx_queue_attr(attr); |
498 | struct netdev_rx_queue *queue = to_rx_queue(kobj); | 498 | struct netdev_rx_queue *queue = to_rx_queue(kobj); |
499 | 499 | ||
500 | if (!attribute->show) | 500 | if (!attribute->show) |
501 | return -EIO; | 501 | return -EIO; |
502 | 502 | ||
503 | return attribute->show(queue, attribute, buf); | 503 | return attribute->show(queue, attribute, buf); |
504 | } | 504 | } |
505 | 505 | ||
506 | static ssize_t rx_queue_attr_store(struct kobject *kobj, struct attribute *attr, | 506 | static ssize_t rx_queue_attr_store(struct kobject *kobj, struct attribute *attr, |
507 | const char *buf, size_t count) | 507 | const char *buf, size_t count) |
508 | { | 508 | { |
509 | struct rx_queue_attribute *attribute = to_rx_queue_attr(attr); | 509 | struct rx_queue_attribute *attribute = to_rx_queue_attr(attr); |
510 | struct netdev_rx_queue *queue = to_rx_queue(kobj); | 510 | struct netdev_rx_queue *queue = to_rx_queue(kobj); |
511 | 511 | ||
512 | if (!attribute->store) | 512 | if (!attribute->store) |
513 | return -EIO; | 513 | return -EIO; |
514 | 514 | ||
515 | return attribute->store(queue, attribute, buf, count); | 515 | return attribute->store(queue, attribute, buf, count); |
516 | } | 516 | } |
517 | 517 | ||
518 | static const struct sysfs_ops rx_queue_sysfs_ops = { | 518 | static const struct sysfs_ops rx_queue_sysfs_ops = { |
519 | .show = rx_queue_attr_show, | 519 | .show = rx_queue_attr_show, |
520 | .store = rx_queue_attr_store, | 520 | .store = rx_queue_attr_store, |
521 | }; | 521 | }; |
522 | 522 | ||
523 | static ssize_t show_rps_map(struct netdev_rx_queue *queue, | 523 | static ssize_t show_rps_map(struct netdev_rx_queue *queue, |
524 | struct rx_queue_attribute *attribute, char *buf) | 524 | struct rx_queue_attribute *attribute, char *buf) |
525 | { | 525 | { |
526 | struct rps_map *map; | 526 | struct rps_map *map; |
527 | cpumask_var_t mask; | 527 | cpumask_var_t mask; |
528 | size_t len = 0; | 528 | size_t len = 0; |
529 | int i; | 529 | int i; |
530 | 530 | ||
531 | if (!zalloc_cpumask_var(&mask, GFP_KERNEL)) | 531 | if (!zalloc_cpumask_var(&mask, GFP_KERNEL)) |
532 | return -ENOMEM; | 532 | return -ENOMEM; |
533 | 533 | ||
534 | rcu_read_lock(); | 534 | rcu_read_lock(); |
535 | map = rcu_dereference(queue->rps_map); | 535 | map = rcu_dereference(queue->rps_map); |
536 | if (map) | 536 | if (map) |
537 | for (i = 0; i < map->len; i++) | 537 | for (i = 0; i < map->len; i++) |
538 | cpumask_set_cpu(map->cpus[i], mask); | 538 | cpumask_set_cpu(map->cpus[i], mask); |
539 | 539 | ||
540 | len += cpumask_scnprintf(buf + len, PAGE_SIZE, mask); | 540 | len += cpumask_scnprintf(buf + len, PAGE_SIZE, mask); |
541 | if (PAGE_SIZE - len < 3) { | 541 | if (PAGE_SIZE - len < 3) { |
542 | rcu_read_unlock(); | 542 | rcu_read_unlock(); |
543 | free_cpumask_var(mask); | 543 | free_cpumask_var(mask); |
544 | return -EINVAL; | 544 | return -EINVAL; |
545 | } | 545 | } |
546 | rcu_read_unlock(); | 546 | rcu_read_unlock(); |
547 | 547 | ||
548 | free_cpumask_var(mask); | 548 | free_cpumask_var(mask); |
549 | len += sprintf(buf + len, "\n"); | 549 | len += sprintf(buf + len, "\n"); |
550 | return len; | 550 | return len; |
551 | } | 551 | } |
552 | 552 | ||
553 | static void rps_map_release(struct rcu_head *rcu) | 553 | static void rps_map_release(struct rcu_head *rcu) |
554 | { | 554 | { |
555 | struct rps_map *map = container_of(rcu, struct rps_map, rcu); | 555 | struct rps_map *map = container_of(rcu, struct rps_map, rcu); |
556 | 556 | ||
557 | kfree(map); | 557 | kfree(map); |
558 | } | 558 | } |
559 | 559 | ||
560 | static ssize_t store_rps_map(struct netdev_rx_queue *queue, | 560 | static ssize_t store_rps_map(struct netdev_rx_queue *queue, |
561 | struct rx_queue_attribute *attribute, | 561 | struct rx_queue_attribute *attribute, |
562 | const char *buf, size_t len) | 562 | const char *buf, size_t len) |
563 | { | 563 | { |
564 | struct rps_map *old_map, *map; | 564 | struct rps_map *old_map, *map; |
565 | cpumask_var_t mask; | 565 | cpumask_var_t mask; |
566 | int err, cpu, i; | 566 | int err, cpu, i; |
567 | static DEFINE_SPINLOCK(rps_map_lock); | 567 | static DEFINE_SPINLOCK(rps_map_lock); |
568 | 568 | ||
569 | if (!capable(CAP_NET_ADMIN)) | 569 | if (!capable(CAP_NET_ADMIN)) |
570 | return -EPERM; | 570 | return -EPERM; |
571 | 571 | ||
572 | if (!alloc_cpumask_var(&mask, GFP_KERNEL)) | 572 | if (!alloc_cpumask_var(&mask, GFP_KERNEL)) |
573 | return -ENOMEM; | 573 | return -ENOMEM; |
574 | 574 | ||
575 | err = bitmap_parse(buf, len, cpumask_bits(mask), nr_cpumask_bits); | 575 | err = bitmap_parse(buf, len, cpumask_bits(mask), nr_cpumask_bits); |
576 | if (err) { | 576 | if (err) { |
577 | free_cpumask_var(mask); | 577 | free_cpumask_var(mask); |
578 | return err; | 578 | return err; |
579 | } | 579 | } |
580 | 580 | ||
581 | map = kzalloc(max_t(unsigned, | 581 | map = kzalloc(max_t(unsigned, |
582 | RPS_MAP_SIZE(cpumask_weight(mask)), L1_CACHE_BYTES), | 582 | RPS_MAP_SIZE(cpumask_weight(mask)), L1_CACHE_BYTES), |
583 | GFP_KERNEL); | 583 | GFP_KERNEL); |
584 | if (!map) { | 584 | if (!map) { |
585 | free_cpumask_var(mask); | 585 | free_cpumask_var(mask); |
586 | return -ENOMEM; | 586 | return -ENOMEM; |
587 | } | 587 | } |
588 | 588 | ||
589 | i = 0; | 589 | i = 0; |
590 | for_each_cpu_and(cpu, mask, cpu_online_mask) | 590 | for_each_cpu_and(cpu, mask, cpu_online_mask) |
591 | map->cpus[i++] = cpu; | 591 | map->cpus[i++] = cpu; |
592 | 592 | ||
593 | if (i) | 593 | if (i) |
594 | map->len = i; | 594 | map->len = i; |
595 | else { | 595 | else { |
596 | kfree(map); | 596 | kfree(map); |
597 | map = NULL; | 597 | map = NULL; |
598 | } | 598 | } |
599 | 599 | ||
600 | spin_lock(&rps_map_lock); | 600 | spin_lock(&rps_map_lock); |
601 | old_map = rcu_dereference_protected(queue->rps_map, | 601 | old_map = rcu_dereference_protected(queue->rps_map, |
602 | lockdep_is_held(&rps_map_lock)); | 602 | lockdep_is_held(&rps_map_lock)); |
603 | rcu_assign_pointer(queue->rps_map, map); | 603 | rcu_assign_pointer(queue->rps_map, map); |
604 | spin_unlock(&rps_map_lock); | 604 | spin_unlock(&rps_map_lock); |
605 | 605 | ||
606 | if (old_map) | 606 | if (old_map) |
607 | call_rcu(&old_map->rcu, rps_map_release); | 607 | call_rcu(&old_map->rcu, rps_map_release); |
608 | 608 | ||
609 | free_cpumask_var(mask); | 609 | free_cpumask_var(mask); |
610 | return len; | 610 | return len; |
611 | } | 611 | } |
612 | 612 | ||
613 | static ssize_t show_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue, | 613 | static ssize_t show_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue, |
614 | struct rx_queue_attribute *attr, | 614 | struct rx_queue_attribute *attr, |
615 | char *buf) | 615 | char *buf) |
616 | { | 616 | { |
617 | struct rps_dev_flow_table *flow_table; | 617 | struct rps_dev_flow_table *flow_table; |
618 | unsigned int val = 0; | 618 | unsigned int val = 0; |
619 | 619 | ||
620 | rcu_read_lock(); | 620 | rcu_read_lock(); |
621 | flow_table = rcu_dereference(queue->rps_flow_table); | 621 | flow_table = rcu_dereference(queue->rps_flow_table); |
622 | if (flow_table) | 622 | if (flow_table) |
623 | val = flow_table->mask + 1; | 623 | val = flow_table->mask + 1; |
624 | rcu_read_unlock(); | 624 | rcu_read_unlock(); |
625 | 625 | ||
626 | return sprintf(buf, "%u\n", val); | 626 | return sprintf(buf, "%u\n", val); |
627 | } | 627 | } |
628 | 628 | ||
629 | static void rps_dev_flow_table_release_work(struct work_struct *work) | 629 | static void rps_dev_flow_table_release_work(struct work_struct *work) |
630 | { | 630 | { |
631 | struct rps_dev_flow_table *table = container_of(work, | 631 | struct rps_dev_flow_table *table = container_of(work, |
632 | struct rps_dev_flow_table, free_work); | 632 | struct rps_dev_flow_table, free_work); |
633 | 633 | ||
634 | vfree(table); | 634 | vfree(table); |
635 | } | 635 | } |
636 | 636 | ||
637 | static void rps_dev_flow_table_release(struct rcu_head *rcu) | 637 | static void rps_dev_flow_table_release(struct rcu_head *rcu) |
638 | { | 638 | { |
639 | struct rps_dev_flow_table *table = container_of(rcu, | 639 | struct rps_dev_flow_table *table = container_of(rcu, |
640 | struct rps_dev_flow_table, rcu); | 640 | struct rps_dev_flow_table, rcu); |
641 | 641 | ||
642 | INIT_WORK(&table->free_work, rps_dev_flow_table_release_work); | 642 | INIT_WORK(&table->free_work, rps_dev_flow_table_release_work); |
643 | schedule_work(&table->free_work); | 643 | schedule_work(&table->free_work); |
644 | } | 644 | } |
645 | 645 | ||
646 | static ssize_t store_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue, | 646 | static ssize_t store_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue, |
647 | struct rx_queue_attribute *attr, | 647 | struct rx_queue_attribute *attr, |
648 | const char *buf, size_t len) | 648 | const char *buf, size_t len) |
649 | { | 649 | { |
650 | unsigned int count; | 650 | unsigned int count; |
651 | char *endp; | 651 | char *endp; |
652 | struct rps_dev_flow_table *table, *old_table; | 652 | struct rps_dev_flow_table *table, *old_table; |
653 | static DEFINE_SPINLOCK(rps_dev_flow_lock); | 653 | static DEFINE_SPINLOCK(rps_dev_flow_lock); |
654 | 654 | ||
655 | if (!capable(CAP_NET_ADMIN)) | 655 | if (!capable(CAP_NET_ADMIN)) |
656 | return -EPERM; | 656 | return -EPERM; |
657 | 657 | ||
658 | count = simple_strtoul(buf, &endp, 0); | 658 | count = simple_strtoul(buf, &endp, 0); |
659 | if (endp == buf) | 659 | if (endp == buf) |
660 | return -EINVAL; | 660 | return -EINVAL; |
661 | 661 | ||
662 | if (count) { | 662 | if (count) { |
663 | int i; | 663 | int i; |
664 | 664 | ||
665 | if (count > 1<<30) { | 665 | if (count > 1<<30) { |
666 | /* Enforce a limit to prevent overflow */ | 666 | /* Enforce a limit to prevent overflow */ |
667 | return -EINVAL; | 667 | return -EINVAL; |
668 | } | 668 | } |
669 | count = roundup_pow_of_two(count); | 669 | count = roundup_pow_of_two(count); |
670 | table = vmalloc(RPS_DEV_FLOW_TABLE_SIZE(count)); | 670 | table = vmalloc(RPS_DEV_FLOW_TABLE_SIZE(count)); |
671 | if (!table) | 671 | if (!table) |
672 | return -ENOMEM; | 672 | return -ENOMEM; |
673 | 673 | ||
674 | table->mask = count - 1; | 674 | table->mask = count - 1; |
675 | for (i = 0; i < count; i++) | 675 | for (i = 0; i < count; i++) |
676 | table->flows[i].cpu = RPS_NO_CPU; | 676 | table->flows[i].cpu = RPS_NO_CPU; |
677 | } else | 677 | } else |
678 | table = NULL; | 678 | table = NULL; |
679 | 679 | ||
680 | spin_lock(&rps_dev_flow_lock); | 680 | spin_lock(&rps_dev_flow_lock); |
681 | old_table = rcu_dereference_protected(queue->rps_flow_table, | 681 | old_table = rcu_dereference_protected(queue->rps_flow_table, |
682 | lockdep_is_held(&rps_dev_flow_lock)); | 682 | lockdep_is_held(&rps_dev_flow_lock)); |
683 | rcu_assign_pointer(queue->rps_flow_table, table); | 683 | rcu_assign_pointer(queue->rps_flow_table, table); |
684 | spin_unlock(&rps_dev_flow_lock); | 684 | spin_unlock(&rps_dev_flow_lock); |
685 | 685 | ||
686 | if (old_table) | 686 | if (old_table) |
687 | call_rcu(&old_table->rcu, rps_dev_flow_table_release); | 687 | call_rcu(&old_table->rcu, rps_dev_flow_table_release); |
688 | 688 | ||
689 | return len; | 689 | return len; |
690 | } | 690 | } |
691 | 691 | ||
692 | static struct rx_queue_attribute rps_cpus_attribute = | 692 | static struct rx_queue_attribute rps_cpus_attribute = |
693 | __ATTR(rps_cpus, S_IRUGO | S_IWUSR, show_rps_map, store_rps_map); | 693 | __ATTR(rps_cpus, S_IRUGO | S_IWUSR, show_rps_map, store_rps_map); |
694 | 694 | ||
695 | 695 | ||
696 | static struct rx_queue_attribute rps_dev_flow_table_cnt_attribute = | 696 | static struct rx_queue_attribute rps_dev_flow_table_cnt_attribute = |
697 | __ATTR(rps_flow_cnt, S_IRUGO | S_IWUSR, | 697 | __ATTR(rps_flow_cnt, S_IRUGO | S_IWUSR, |
698 | show_rps_dev_flow_table_cnt, store_rps_dev_flow_table_cnt); | 698 | show_rps_dev_flow_table_cnt, store_rps_dev_flow_table_cnt); |
699 | 699 | ||
700 | static struct attribute *rx_queue_default_attrs[] = { | 700 | static struct attribute *rx_queue_default_attrs[] = { |
701 | &rps_cpus_attribute.attr, | 701 | &rps_cpus_attribute.attr, |
702 | &rps_dev_flow_table_cnt_attribute.attr, | 702 | &rps_dev_flow_table_cnt_attribute.attr, |
703 | NULL | 703 | NULL |
704 | }; | 704 | }; |
705 | 705 | ||
706 | static void rx_queue_release(struct kobject *kobj) | 706 | static void rx_queue_release(struct kobject *kobj) |
707 | { | 707 | { |
708 | struct netdev_rx_queue *queue = to_rx_queue(kobj); | 708 | struct netdev_rx_queue *queue = to_rx_queue(kobj); |
709 | struct rps_map *map; | 709 | struct rps_map *map; |
710 | struct rps_dev_flow_table *flow_table; | 710 | struct rps_dev_flow_table *flow_table; |
711 | 711 | ||
712 | 712 | ||
713 | map = rcu_dereference_raw(queue->rps_map); | 713 | map = rcu_dereference_raw(queue->rps_map); |
714 | if (map) { | 714 | if (map) { |
715 | RCU_INIT_POINTER(queue->rps_map, NULL); | 715 | RCU_INIT_POINTER(queue->rps_map, NULL); |
716 | call_rcu(&map->rcu, rps_map_release); | 716 | call_rcu(&map->rcu, rps_map_release); |
717 | } | 717 | } |
718 | 718 | ||
719 | flow_table = rcu_dereference_raw(queue->rps_flow_table); | 719 | flow_table = rcu_dereference_raw(queue->rps_flow_table); |
720 | if (flow_table) { | 720 | if (flow_table) { |
721 | RCU_INIT_POINTER(queue->rps_flow_table, NULL); | 721 | RCU_INIT_POINTER(queue->rps_flow_table, NULL); |
722 | call_rcu(&flow_table->rcu, rps_dev_flow_table_release); | 722 | call_rcu(&flow_table->rcu, rps_dev_flow_table_release); |
723 | } | 723 | } |
724 | 724 | ||
725 | memset(kobj, 0, sizeof(*kobj)); | 725 | memset(kobj, 0, sizeof(*kobj)); |
726 | dev_put(queue->dev); | 726 | dev_put(queue->dev); |
727 | } | 727 | } |
728 | 728 | ||
729 | static struct kobj_type rx_queue_ktype = { | 729 | static struct kobj_type rx_queue_ktype = { |
730 | .sysfs_ops = &rx_queue_sysfs_ops, | 730 | .sysfs_ops = &rx_queue_sysfs_ops, |
731 | .release = rx_queue_release, | 731 | .release = rx_queue_release, |
732 | .default_attrs = rx_queue_default_attrs, | 732 | .default_attrs = rx_queue_default_attrs, |
733 | }; | 733 | }; |
734 | 734 | ||
735 | static int rx_queue_add_kobject(struct net_device *net, int index) | 735 | static int rx_queue_add_kobject(struct net_device *net, int index) |
736 | { | 736 | { |
737 | struct netdev_rx_queue *queue = net->_rx + index; | 737 | struct netdev_rx_queue *queue = net->_rx + index; |
738 | struct kobject *kobj = &queue->kobj; | 738 | struct kobject *kobj = &queue->kobj; |
739 | int error = 0; | 739 | int error = 0; |
740 | 740 | ||
741 | kobj->kset = net->queues_kset; | 741 | kobj->kset = net->queues_kset; |
742 | error = kobject_init_and_add(kobj, &rx_queue_ktype, NULL, | 742 | error = kobject_init_and_add(kobj, &rx_queue_ktype, NULL, |
743 | "rx-%u", index); | 743 | "rx-%u", index); |
744 | if (error) { | 744 | if (error) { |
745 | kobject_put(kobj); | 745 | kobject_put(kobj); |
746 | return error; | 746 | return error; |
747 | } | 747 | } |
748 | 748 | ||
749 | kobject_uevent(kobj, KOBJ_ADD); | 749 | kobject_uevent(kobj, KOBJ_ADD); |
750 | dev_hold(queue->dev); | 750 | dev_hold(queue->dev); |
751 | 751 | ||
752 | return error; | 752 | return error; |
753 | } | 753 | } |
754 | #endif /* CONFIG_RPS */ | ||
754 | 755 | ||
755 | int | 756 | int |
756 | net_rx_queue_update_kobjects(struct net_device *net, int old_num, int new_num) | 757 | net_rx_queue_update_kobjects(struct net_device *net, int old_num, int new_num) |
757 | { | 758 | { |
759 | #ifdef CONFIG_RPS | ||
758 | int i; | 760 | int i; |
759 | int error = 0; | 761 | int error = 0; |
760 | 762 | ||
761 | for (i = old_num; i < new_num; i++) { | 763 | for (i = old_num; i < new_num; i++) { |
762 | error = rx_queue_add_kobject(net, i); | 764 | error = rx_queue_add_kobject(net, i); |
763 | if (error) { | 765 | if (error) { |
764 | new_num = old_num; | 766 | new_num = old_num; |
765 | break; | 767 | break; |
766 | } | 768 | } |
767 | } | 769 | } |
768 | 770 | ||
769 | while (--i >= new_num) | 771 | while (--i >= new_num) |
770 | kobject_put(&net->_rx[i].kobj); | 772 | kobject_put(&net->_rx[i].kobj); |
771 | 773 | ||
772 | return error; | 774 | return error; |
775 | #else | ||
776 | return 0; | ||
777 | #endif | ||
773 | } | 778 | } |
774 | 779 | ||
780 | #ifdef CONFIG_XPS | ||
775 | /* | 781 | /* |
776 | * netdev_queue sysfs structures and functions. | 782 | * netdev_queue sysfs structures and functions. |
777 | */ | 783 | */ |
778 | struct netdev_queue_attribute { | 784 | struct netdev_queue_attribute { |
779 | struct attribute attr; | 785 | struct attribute attr; |
780 | ssize_t (*show)(struct netdev_queue *queue, | 786 | ssize_t (*show)(struct netdev_queue *queue, |
781 | struct netdev_queue_attribute *attr, char *buf); | 787 | struct netdev_queue_attribute *attr, char *buf); |
782 | ssize_t (*store)(struct netdev_queue *queue, | 788 | ssize_t (*store)(struct netdev_queue *queue, |
783 | struct netdev_queue_attribute *attr, const char *buf, size_t len); | 789 | struct netdev_queue_attribute *attr, const char *buf, size_t len); |
784 | }; | 790 | }; |
785 | #define to_netdev_queue_attr(_attr) container_of(_attr, \ | 791 | #define to_netdev_queue_attr(_attr) container_of(_attr, \ |
786 | struct netdev_queue_attribute, attr) | 792 | struct netdev_queue_attribute, attr) |
787 | 793 | ||
788 | #define to_netdev_queue(obj) container_of(obj, struct netdev_queue, kobj) | 794 | #define to_netdev_queue(obj) container_of(obj, struct netdev_queue, kobj) |
789 | 795 | ||
790 | static ssize_t netdev_queue_attr_show(struct kobject *kobj, | 796 | static ssize_t netdev_queue_attr_show(struct kobject *kobj, |
791 | struct attribute *attr, char *buf) | 797 | struct attribute *attr, char *buf) |
792 | { | 798 | { |
793 | struct netdev_queue_attribute *attribute = to_netdev_queue_attr(attr); | 799 | struct netdev_queue_attribute *attribute = to_netdev_queue_attr(attr); |
794 | struct netdev_queue *queue = to_netdev_queue(kobj); | 800 | struct netdev_queue *queue = to_netdev_queue(kobj); |
795 | 801 | ||
796 | if (!attribute->show) | 802 | if (!attribute->show) |
797 | return -EIO; | 803 | return -EIO; |
798 | 804 | ||
799 | return attribute->show(queue, attribute, buf); | 805 | return attribute->show(queue, attribute, buf); |
800 | } | 806 | } |
801 | 807 | ||
802 | static ssize_t netdev_queue_attr_store(struct kobject *kobj, | 808 | static ssize_t netdev_queue_attr_store(struct kobject *kobj, |
803 | struct attribute *attr, | 809 | struct attribute *attr, |
804 | const char *buf, size_t count) | 810 | const char *buf, size_t count) |
805 | { | 811 | { |
806 | struct netdev_queue_attribute *attribute = to_netdev_queue_attr(attr); | 812 | struct netdev_queue_attribute *attribute = to_netdev_queue_attr(attr); |
807 | struct netdev_queue *queue = to_netdev_queue(kobj); | 813 | struct netdev_queue *queue = to_netdev_queue(kobj); |
808 | 814 | ||
809 | if (!attribute->store) | 815 | if (!attribute->store) |
810 | return -EIO; | 816 | return -EIO; |
811 | 817 | ||
812 | return attribute->store(queue, attribute, buf, count); | 818 | return attribute->store(queue, attribute, buf, count); |
813 | } | 819 | } |
814 | 820 | ||
815 | static const struct sysfs_ops netdev_queue_sysfs_ops = { | 821 | static const struct sysfs_ops netdev_queue_sysfs_ops = { |
816 | .show = netdev_queue_attr_show, | 822 | .show = netdev_queue_attr_show, |
817 | .store = netdev_queue_attr_store, | 823 | .store = netdev_queue_attr_store, |
818 | }; | 824 | }; |
819 | 825 | ||
820 | static inline unsigned int get_netdev_queue_index(struct netdev_queue *queue) | 826 | static inline unsigned int get_netdev_queue_index(struct netdev_queue *queue) |
821 | { | 827 | { |
822 | struct net_device *dev = queue->dev; | 828 | struct net_device *dev = queue->dev; |
823 | int i; | 829 | int i; |
824 | 830 | ||
825 | for (i = 0; i < dev->num_tx_queues; i++) | 831 | for (i = 0; i < dev->num_tx_queues; i++) |
826 | if (queue == &dev->_tx[i]) | 832 | if (queue == &dev->_tx[i]) |
827 | break; | 833 | break; |
828 | 834 | ||
829 | BUG_ON(i >= dev->num_tx_queues); | 835 | BUG_ON(i >= dev->num_tx_queues); |
830 | 836 | ||
831 | return i; | 837 | return i; |
832 | } | 838 | } |
833 | 839 | ||
834 | 840 | ||
835 | static ssize_t show_xps_map(struct netdev_queue *queue, | 841 | static ssize_t show_xps_map(struct netdev_queue *queue, |
836 | struct netdev_queue_attribute *attribute, char *buf) | 842 | struct netdev_queue_attribute *attribute, char *buf) |
837 | { | 843 | { |
838 | struct net_device *dev = queue->dev; | 844 | struct net_device *dev = queue->dev; |
839 | struct xps_dev_maps *dev_maps; | 845 | struct xps_dev_maps *dev_maps; |
840 | cpumask_var_t mask; | 846 | cpumask_var_t mask; |
841 | unsigned long index; | 847 | unsigned long index; |
842 | size_t len = 0; | 848 | size_t len = 0; |
843 | int i; | 849 | int i; |
844 | 850 | ||
845 | if (!zalloc_cpumask_var(&mask, GFP_KERNEL)) | 851 | if (!zalloc_cpumask_var(&mask, GFP_KERNEL)) |
846 | return -ENOMEM; | 852 | return -ENOMEM; |
847 | 853 | ||
848 | index = get_netdev_queue_index(queue); | 854 | index = get_netdev_queue_index(queue); |
849 | 855 | ||
850 | rcu_read_lock(); | 856 | rcu_read_lock(); |
851 | dev_maps = rcu_dereference(dev->xps_maps); | 857 | dev_maps = rcu_dereference(dev->xps_maps); |
852 | if (dev_maps) { | 858 | if (dev_maps) { |
853 | for_each_possible_cpu(i) { | 859 | for_each_possible_cpu(i) { |
854 | struct xps_map *map = | 860 | struct xps_map *map = |
855 | rcu_dereference(dev_maps->cpu_map[i]); | 861 | rcu_dereference(dev_maps->cpu_map[i]); |
856 | if (map) { | 862 | if (map) { |
857 | int j; | 863 | int j; |
858 | for (j = 0; j < map->len; j++) { | 864 | for (j = 0; j < map->len; j++) { |
859 | if (map->queues[j] == index) { | 865 | if (map->queues[j] == index) { |
860 | cpumask_set_cpu(i, mask); | 866 | cpumask_set_cpu(i, mask); |
861 | break; | 867 | break; |
862 | } | 868 | } |
863 | } | 869 | } |
864 | } | 870 | } |
865 | } | 871 | } |
866 | } | 872 | } |
867 | rcu_read_unlock(); | 873 | rcu_read_unlock(); |
868 | 874 | ||
869 | len += cpumask_scnprintf(buf + len, PAGE_SIZE, mask); | 875 | len += cpumask_scnprintf(buf + len, PAGE_SIZE, mask); |
870 | if (PAGE_SIZE - len < 3) { | 876 | if (PAGE_SIZE - len < 3) { |
871 | free_cpumask_var(mask); | 877 | free_cpumask_var(mask); |
872 | return -EINVAL; | 878 | return -EINVAL; |
873 | } | 879 | } |
874 | 880 | ||
875 | free_cpumask_var(mask); | 881 | free_cpumask_var(mask); |
876 | len += sprintf(buf + len, "\n"); | 882 | len += sprintf(buf + len, "\n"); |
877 | return len; | 883 | return len; |
878 | } | 884 | } |
879 | 885 | ||
880 | static void xps_map_release(struct rcu_head *rcu) | 886 | static void xps_map_release(struct rcu_head *rcu) |
881 | { | 887 | { |
882 | struct xps_map *map = container_of(rcu, struct xps_map, rcu); | 888 | struct xps_map *map = container_of(rcu, struct xps_map, rcu); |
883 | 889 | ||
884 | kfree(map); | 890 | kfree(map); |
885 | } | 891 | } |
886 | 892 | ||
887 | static void xps_dev_maps_release(struct rcu_head *rcu) | 893 | static void xps_dev_maps_release(struct rcu_head *rcu) |
888 | { | 894 | { |
889 | struct xps_dev_maps *dev_maps = | 895 | struct xps_dev_maps *dev_maps = |
890 | container_of(rcu, struct xps_dev_maps, rcu); | 896 | container_of(rcu, struct xps_dev_maps, rcu); |
891 | 897 | ||
892 | kfree(dev_maps); | 898 | kfree(dev_maps); |
893 | } | 899 | } |
894 | 900 | ||
895 | static DEFINE_MUTEX(xps_map_mutex); | 901 | static DEFINE_MUTEX(xps_map_mutex); |
896 | 902 | ||
897 | static ssize_t store_xps_map(struct netdev_queue *queue, | 903 | static ssize_t store_xps_map(struct netdev_queue *queue, |
898 | struct netdev_queue_attribute *attribute, | 904 | struct netdev_queue_attribute *attribute, |
899 | const char *buf, size_t len) | 905 | const char *buf, size_t len) |
900 | { | 906 | { |
901 | struct net_device *dev = queue->dev; | 907 | struct net_device *dev = queue->dev; |
902 | cpumask_var_t mask; | 908 | cpumask_var_t mask; |
903 | int err, i, cpu, pos, map_len, alloc_len, need_set; | 909 | int err, i, cpu, pos, map_len, alloc_len, need_set; |
904 | unsigned long index; | 910 | unsigned long index; |
905 | struct xps_map *map, *new_map; | 911 | struct xps_map *map, *new_map; |
906 | struct xps_dev_maps *dev_maps, *new_dev_maps; | 912 | struct xps_dev_maps *dev_maps, *new_dev_maps; |
907 | int nonempty = 0; | 913 | int nonempty = 0; |
908 | 914 | ||
909 | if (!capable(CAP_NET_ADMIN)) | 915 | if (!capable(CAP_NET_ADMIN)) |
910 | return -EPERM; | 916 | return -EPERM; |
911 | 917 | ||
912 | if (!alloc_cpumask_var(&mask, GFP_KERNEL)) | 918 | if (!alloc_cpumask_var(&mask, GFP_KERNEL)) |
913 | return -ENOMEM; | 919 | return -ENOMEM; |
914 | 920 | ||
915 | index = get_netdev_queue_index(queue); | 921 | index = get_netdev_queue_index(queue); |
916 | 922 | ||
917 | err = bitmap_parse(buf, len, cpumask_bits(mask), nr_cpumask_bits); | 923 | err = bitmap_parse(buf, len, cpumask_bits(mask), nr_cpumask_bits); |
918 | if (err) { | 924 | if (err) { |
919 | free_cpumask_var(mask); | 925 | free_cpumask_var(mask); |
920 | return err; | 926 | return err; |
921 | } | 927 | } |
922 | 928 | ||
923 | new_dev_maps = kzalloc(max_t(unsigned, | 929 | new_dev_maps = kzalloc(max_t(unsigned, |
924 | XPS_DEV_MAPS_SIZE, L1_CACHE_BYTES), GFP_KERNEL); | 930 | XPS_DEV_MAPS_SIZE, L1_CACHE_BYTES), GFP_KERNEL); |
925 | if (!new_dev_maps) { | 931 | if (!new_dev_maps) { |
926 | free_cpumask_var(mask); | 932 | free_cpumask_var(mask); |
927 | return -ENOMEM; | 933 | return -ENOMEM; |
928 | } | 934 | } |
929 | 935 | ||
930 | mutex_lock(&xps_map_mutex); | 936 | mutex_lock(&xps_map_mutex); |
931 | 937 | ||
932 | dev_maps = dev->xps_maps; | 938 | dev_maps = dev->xps_maps; |
933 | 939 | ||
934 | for_each_possible_cpu(cpu) { | 940 | for_each_possible_cpu(cpu) { |
935 | new_map = map = dev_maps ? dev_maps->cpu_map[cpu] : NULL; | 941 | new_map = map = dev_maps ? dev_maps->cpu_map[cpu] : NULL; |
936 | 942 | ||
937 | if (map) { | 943 | if (map) { |
938 | for (pos = 0; pos < map->len; pos++) | 944 | for (pos = 0; pos < map->len; pos++) |
939 | if (map->queues[pos] == index) | 945 | if (map->queues[pos] == index) |
940 | break; | 946 | break; |
941 | map_len = map->len; | 947 | map_len = map->len; |
942 | alloc_len = map->alloc_len; | 948 | alloc_len = map->alloc_len; |
943 | } else | 949 | } else |
944 | pos = map_len = alloc_len = 0; | 950 | pos = map_len = alloc_len = 0; |
945 | 951 | ||
946 | need_set = cpu_isset(cpu, *mask) && cpu_online(cpu); | 952 | need_set = cpu_isset(cpu, *mask) && cpu_online(cpu); |
947 | 953 | ||
948 | if (need_set && pos >= map_len) { | 954 | if (need_set && pos >= map_len) { |
949 | /* Need to add queue to this CPU's map */ | 955 | /* Need to add queue to this CPU's map */ |
950 | if (map_len >= alloc_len) { | 956 | if (map_len >= alloc_len) { |
951 | alloc_len = alloc_len ? | 957 | alloc_len = alloc_len ? |
952 | 2 * alloc_len : XPS_MIN_MAP_ALLOC; | 958 | 2 * alloc_len : XPS_MIN_MAP_ALLOC; |
953 | new_map = kzalloc(XPS_MAP_SIZE(alloc_len), | 959 | new_map = kzalloc(XPS_MAP_SIZE(alloc_len), |
954 | GFP_KERNEL); | 960 | GFP_KERNEL); |
955 | if (!new_map) | 961 | if (!new_map) |
956 | goto error; | 962 | goto error; |
957 | new_map->alloc_len = alloc_len; | 963 | new_map->alloc_len = alloc_len; |
958 | for (i = 0; i < map_len; i++) | 964 | for (i = 0; i < map_len; i++) |
959 | new_map->queues[i] = map->queues[i]; | 965 | new_map->queues[i] = map->queues[i]; |
960 | new_map->len = map_len; | 966 | new_map->len = map_len; |
961 | } | 967 | } |
962 | new_map->queues[new_map->len++] = index; | 968 | new_map->queues[new_map->len++] = index; |
963 | } else if (!need_set && pos < map_len) { | 969 | } else if (!need_set && pos < map_len) { |
964 | /* Need to remove queue from this CPU's map */ | 970 | /* Need to remove queue from this CPU's map */ |
965 | if (map_len > 1) | 971 | if (map_len > 1) |
966 | new_map->queues[pos] = | 972 | new_map->queues[pos] = |
967 | new_map->queues[--new_map->len]; | 973 | new_map->queues[--new_map->len]; |
968 | else | 974 | else |
969 | new_map = NULL; | 975 | new_map = NULL; |
970 | } | 976 | } |
971 | new_dev_maps->cpu_map[cpu] = new_map; | 977 | new_dev_maps->cpu_map[cpu] = new_map; |
972 | } | 978 | } |
973 | 979 | ||
974 | /* Cleanup old maps */ | 980 | /* Cleanup old maps */ |
975 | for_each_possible_cpu(cpu) { | 981 | for_each_possible_cpu(cpu) { |
976 | map = dev_maps ? dev_maps->cpu_map[cpu] : NULL; | 982 | map = dev_maps ? dev_maps->cpu_map[cpu] : NULL; |
977 | if (map && new_dev_maps->cpu_map[cpu] != map) | 983 | if (map && new_dev_maps->cpu_map[cpu] != map) |
978 | call_rcu(&map->rcu, xps_map_release); | 984 | call_rcu(&map->rcu, xps_map_release); |
979 | if (new_dev_maps->cpu_map[cpu]) | 985 | if (new_dev_maps->cpu_map[cpu]) |
980 | nonempty = 1; | 986 | nonempty = 1; |
981 | } | 987 | } |
982 | 988 | ||
983 | if (nonempty) | 989 | if (nonempty) |
984 | rcu_assign_pointer(dev->xps_maps, new_dev_maps); | 990 | rcu_assign_pointer(dev->xps_maps, new_dev_maps); |
985 | else { | 991 | else { |
986 | kfree(new_dev_maps); | 992 | kfree(new_dev_maps); |
987 | rcu_assign_pointer(dev->xps_maps, NULL); | 993 | rcu_assign_pointer(dev->xps_maps, NULL); |
988 | } | 994 | } |
989 | 995 | ||
990 | if (dev_maps) | 996 | if (dev_maps) |
991 | call_rcu(&dev_maps->rcu, xps_dev_maps_release); | 997 | call_rcu(&dev_maps->rcu, xps_dev_maps_release); |
992 | 998 | ||
993 | mutex_unlock(&xps_map_mutex); | 999 | mutex_unlock(&xps_map_mutex); |
994 | 1000 | ||
995 | free_cpumask_var(mask); | 1001 | free_cpumask_var(mask); |
996 | return len; | 1002 | return len; |
997 | 1003 | ||
998 | error: | 1004 | error: |
999 | mutex_unlock(&xps_map_mutex); | 1005 | mutex_unlock(&xps_map_mutex); |
1000 | 1006 | ||
1001 | if (new_dev_maps) | 1007 | if (new_dev_maps) |
1002 | for_each_possible_cpu(i) | 1008 | for_each_possible_cpu(i) |
1003 | kfree(new_dev_maps->cpu_map[i]); | 1009 | kfree(new_dev_maps->cpu_map[i]); |
1004 | kfree(new_dev_maps); | 1010 | kfree(new_dev_maps); |
1005 | free_cpumask_var(mask); | 1011 | free_cpumask_var(mask); |
1006 | return -ENOMEM; | 1012 | return -ENOMEM; |
1007 | } | 1013 | } |
1008 | 1014 | ||
1009 | static struct netdev_queue_attribute xps_cpus_attribute = | 1015 | static struct netdev_queue_attribute xps_cpus_attribute = |
1010 | __ATTR(xps_cpus, S_IRUGO | S_IWUSR, show_xps_map, store_xps_map); | 1016 | __ATTR(xps_cpus, S_IRUGO | S_IWUSR, show_xps_map, store_xps_map); |
1011 | 1017 | ||
1012 | static struct attribute *netdev_queue_default_attrs[] = { | 1018 | static struct attribute *netdev_queue_default_attrs[] = { |
1013 | &xps_cpus_attribute.attr, | 1019 | &xps_cpus_attribute.attr, |
1014 | NULL | 1020 | NULL |
1015 | }; | 1021 | }; |
1016 | 1022 | ||
1017 | static void netdev_queue_release(struct kobject *kobj) | 1023 | static void netdev_queue_release(struct kobject *kobj) |
1018 | { | 1024 | { |
1019 | struct netdev_queue *queue = to_netdev_queue(kobj); | 1025 | struct netdev_queue *queue = to_netdev_queue(kobj); |
1020 | struct net_device *dev = queue->dev; | 1026 | struct net_device *dev = queue->dev; |
1021 | struct xps_dev_maps *dev_maps; | 1027 | struct xps_dev_maps *dev_maps; |
1022 | struct xps_map *map; | 1028 | struct xps_map *map; |
1023 | unsigned long index; | 1029 | unsigned long index; |
1024 | int i, pos, nonempty = 0; | 1030 | int i, pos, nonempty = 0; |
1025 | 1031 | ||
1026 | index = get_netdev_queue_index(queue); | 1032 | index = get_netdev_queue_index(queue); |
1027 | 1033 | ||
1028 | mutex_lock(&xps_map_mutex); | 1034 | mutex_lock(&xps_map_mutex); |
1029 | dev_maps = dev->xps_maps; | 1035 | dev_maps = dev->xps_maps; |
1030 | 1036 | ||
1031 | if (dev_maps) { | 1037 | if (dev_maps) { |
1032 | for_each_possible_cpu(i) { | 1038 | for_each_possible_cpu(i) { |
1033 | map = dev_maps->cpu_map[i]; | 1039 | map = dev_maps->cpu_map[i]; |
1034 | if (!map) | 1040 | if (!map) |
1035 | continue; | 1041 | continue; |
1036 | 1042 | ||
1037 | for (pos = 0; pos < map->len; pos++) | 1043 | for (pos = 0; pos < map->len; pos++) |
1038 | if (map->queues[pos] == index) | 1044 | if (map->queues[pos] == index) |
1039 | break; | 1045 | break; |
1040 | 1046 | ||
1041 | if (pos < map->len) { | 1047 | if (pos < map->len) { |
1042 | if (map->len > 1) | 1048 | if (map->len > 1) |
1043 | map->queues[pos] = | 1049 | map->queues[pos] = |
1044 | map->queues[--map->len]; | 1050 | map->queues[--map->len]; |
1045 | else { | 1051 | else { |
1046 | RCU_INIT_POINTER(dev_maps->cpu_map[i], | 1052 | RCU_INIT_POINTER(dev_maps->cpu_map[i], |
1047 | NULL); | 1053 | NULL); |
1048 | call_rcu(&map->rcu, xps_map_release); | 1054 | call_rcu(&map->rcu, xps_map_release); |
1049 | map = NULL; | 1055 | map = NULL; |
1050 | } | 1056 | } |
1051 | } | 1057 | } |
1052 | if (map) | 1058 | if (map) |
1053 | nonempty = 1; | 1059 | nonempty = 1; |
1054 | } | 1060 | } |
1055 | 1061 | ||
1056 | if (!nonempty) { | 1062 | if (!nonempty) { |
1057 | RCU_INIT_POINTER(dev->xps_maps, NULL); | 1063 | RCU_INIT_POINTER(dev->xps_maps, NULL); |
1058 | call_rcu(&dev_maps->rcu, xps_dev_maps_release); | 1064 | call_rcu(&dev_maps->rcu, xps_dev_maps_release); |
1059 | } | 1065 | } |
1060 | } | 1066 | } |
1061 | 1067 | ||
1062 | mutex_unlock(&xps_map_mutex); | 1068 | mutex_unlock(&xps_map_mutex); |
1063 | 1069 | ||
1064 | memset(kobj, 0, sizeof(*kobj)); | 1070 | memset(kobj, 0, sizeof(*kobj)); |
1065 | dev_put(queue->dev); | 1071 | dev_put(queue->dev); |
1066 | } | 1072 | } |
1067 | 1073 | ||
1068 | static struct kobj_type netdev_queue_ktype = { | 1074 | static struct kobj_type netdev_queue_ktype = { |
1069 | .sysfs_ops = &netdev_queue_sysfs_ops, | 1075 | .sysfs_ops = &netdev_queue_sysfs_ops, |
1070 | .release = netdev_queue_release, | 1076 | .release = netdev_queue_release, |
1071 | .default_attrs = netdev_queue_default_attrs, | 1077 | .default_attrs = netdev_queue_default_attrs, |
1072 | }; | 1078 | }; |
1073 | 1079 | ||
1074 | static int netdev_queue_add_kobject(struct net_device *net, int index) | 1080 | static int netdev_queue_add_kobject(struct net_device *net, int index) |
1075 | { | 1081 | { |
1076 | struct netdev_queue *queue = net->_tx + index; | 1082 | struct netdev_queue *queue = net->_tx + index; |
1077 | struct kobject *kobj = &queue->kobj; | 1083 | struct kobject *kobj = &queue->kobj; |
1078 | int error = 0; | 1084 | int error = 0; |
1079 | 1085 | ||
1080 | kobj->kset = net->queues_kset; | 1086 | kobj->kset = net->queues_kset; |
1081 | error = kobject_init_and_add(kobj, &netdev_queue_ktype, NULL, | 1087 | error = kobject_init_and_add(kobj, &netdev_queue_ktype, NULL, |
1082 | "tx-%u", index); | 1088 | "tx-%u", index); |
1083 | if (error) { | 1089 | if (error) { |
1084 | kobject_put(kobj); | 1090 | kobject_put(kobj); |
1085 | return error; | 1091 | return error; |
1086 | } | 1092 | } |
1087 | 1093 | ||
1088 | kobject_uevent(kobj, KOBJ_ADD); | 1094 | kobject_uevent(kobj, KOBJ_ADD); |
1089 | dev_hold(queue->dev); | 1095 | dev_hold(queue->dev); |
1090 | 1096 | ||
1091 | return error; | 1097 | return error; |
1092 | } | 1098 | } |
1099 | #endif /* CONFIG_XPS */ | ||
1093 | 1100 | ||
1094 | int | 1101 | int |
1095 | netdev_queue_update_kobjects(struct net_device *net, int old_num, int new_num) | 1102 | netdev_queue_update_kobjects(struct net_device *net, int old_num, int new_num) |
1096 | { | 1103 | { |
1104 | #ifdef CONFIG_XPS | ||
1097 | int i; | 1105 | int i; |
1098 | int error = 0; | 1106 | int error = 0; |
1099 | 1107 | ||
1100 | for (i = old_num; i < new_num; i++) { | 1108 | for (i = old_num; i < new_num; i++) { |
1101 | error = netdev_queue_add_kobject(net, i); | 1109 | error = netdev_queue_add_kobject(net, i); |
1102 | if (error) { | 1110 | if (error) { |
1103 | new_num = old_num; | 1111 | new_num = old_num; |
1104 | break; | 1112 | break; |
1105 | } | 1113 | } |
1106 | } | 1114 | } |
1107 | 1115 | ||
1108 | while (--i >= new_num) | 1116 | while (--i >= new_num) |
1109 | kobject_put(&net->_tx[i].kobj); | 1117 | kobject_put(&net->_tx[i].kobj); |
1110 | 1118 | ||
1111 | return error; | 1119 | return error; |
1120 | #else | ||
1121 | return 0; | ||
1122 | #endif | ||
1112 | } | 1123 | } |
1113 | 1124 | ||
1114 | static int register_queue_kobjects(struct net_device *net) | 1125 | static int register_queue_kobjects(struct net_device *net) |
1115 | { | 1126 | { |
1116 | int error = 0, txq = 0, rxq = 0; | 1127 | int error = 0, txq = 0, rxq = 0, real_rx = 0, real_tx = 0; |
1117 | 1128 | ||
1129 | #if defined(CONFIG_RPS) || defined(CONFIG_XPS) | ||
1118 | net->queues_kset = kset_create_and_add("queues", | 1130 | net->queues_kset = kset_create_and_add("queues", |
1119 | NULL, &net->dev.kobj); | 1131 | NULL, &net->dev.kobj); |
1120 | if (!net->queues_kset) | 1132 | if (!net->queues_kset) |
1121 | return -ENOMEM; | 1133 | return -ENOMEM; |
1134 | #endif | ||
1122 | 1135 | ||
1123 | error = net_rx_queue_update_kobjects(net, 0, net->real_num_rx_queues); | 1136 | #ifdef CONFIG_RPS |
1137 | real_rx = net->real_num_rx_queues; | ||
1138 | #endif | ||
1139 | real_tx = net->real_num_tx_queues; | ||
1140 | |||
1141 | error = net_rx_queue_update_kobjects(net, 0, real_rx); | ||
1124 | if (error) | 1142 | if (error) |
1125 | goto error; | 1143 | goto error; |
1126 | rxq = net->real_num_rx_queues; | 1144 | rxq = real_rx; |
1127 | 1145 | ||
1128 | error = netdev_queue_update_kobjects(net, 0, | 1146 | error = netdev_queue_update_kobjects(net, 0, real_tx); |
1129 | net->real_num_tx_queues); | ||
1130 | if (error) | 1147 | if (error) |
1131 | goto error; | 1148 | goto error; |
1132 | txq = net->real_num_tx_queues; | 1149 | txq = real_tx; |
1133 | 1150 | ||
1134 | return 0; | 1151 | return 0; |
1135 | 1152 | ||
1136 | error: | 1153 | error: |
1137 | netdev_queue_update_kobjects(net, txq, 0); | 1154 | netdev_queue_update_kobjects(net, txq, 0); |
1138 | net_rx_queue_update_kobjects(net, rxq, 0); | 1155 | net_rx_queue_update_kobjects(net, rxq, 0); |
1139 | return error; | 1156 | return error; |
1140 | } | 1157 | } |
1141 | 1158 | ||
1142 | static void remove_queue_kobjects(struct net_device *net) | 1159 | static void remove_queue_kobjects(struct net_device *net) |
1143 | { | 1160 | { |
1144 | net_rx_queue_update_kobjects(net, net->real_num_rx_queues, 0); | 1161 | int real_rx = 0, real_tx = 0; |
1145 | netdev_queue_update_kobjects(net, net->real_num_tx_queues, 0); | 1162 | |
1163 | #ifdef CONFIG_RPS | ||
1164 | real_rx = net->real_num_rx_queues; | ||
1165 | #endif | ||
1166 | real_tx = net->real_num_tx_queues; | ||
1167 | |||
1168 | net_rx_queue_update_kobjects(net, real_rx, 0); | ||
1169 | netdev_queue_update_kobjects(net, real_tx, 0); | ||
1170 | #if defined(CONFIG_RPS) || defined(CONFIG_XPS) | ||
1146 | kset_unregister(net->queues_kset); | 1171 | kset_unregister(net->queues_kset); |
1172 | #endif | ||
1147 | } | 1173 | } |
1148 | #endif /* CONFIG_RPS */ | ||
1149 | 1174 | ||
1150 | static const void *net_current_ns(void) | 1175 | static const void *net_current_ns(void) |
1151 | { | 1176 | { |
1152 | return current->nsproxy->net_ns; | 1177 | return current->nsproxy->net_ns; |
1153 | } | 1178 | } |
1154 | 1179 | ||
1155 | static const void *net_initial_ns(void) | 1180 | static const void *net_initial_ns(void) |
1156 | { | 1181 | { |
1157 | return &init_net; | 1182 | return &init_net; |
1158 | } | 1183 | } |
1159 | 1184 | ||
1160 | static const void *net_netlink_ns(struct sock *sk) | 1185 | static const void *net_netlink_ns(struct sock *sk) |
1161 | { | 1186 | { |
1162 | return sock_net(sk); | 1187 | return sock_net(sk); |
1163 | } | 1188 | } |
1164 | 1189 | ||
1165 | struct kobj_ns_type_operations net_ns_type_operations = { | 1190 | struct kobj_ns_type_operations net_ns_type_operations = { |
1166 | .type = KOBJ_NS_TYPE_NET, | 1191 | .type = KOBJ_NS_TYPE_NET, |
1167 | .current_ns = net_current_ns, | 1192 | .current_ns = net_current_ns, |
1168 | .netlink_ns = net_netlink_ns, | 1193 | .netlink_ns = net_netlink_ns, |
1169 | .initial_ns = net_initial_ns, | 1194 | .initial_ns = net_initial_ns, |
1170 | }; | 1195 | }; |
1171 | EXPORT_SYMBOL_GPL(net_ns_type_operations); | 1196 | EXPORT_SYMBOL_GPL(net_ns_type_operations); |
1172 | 1197 | ||
1173 | static void net_kobj_ns_exit(struct net *net) | 1198 | static void net_kobj_ns_exit(struct net *net) |
1174 | { | 1199 | { |
1175 | kobj_ns_exit(KOBJ_NS_TYPE_NET, net); | 1200 | kobj_ns_exit(KOBJ_NS_TYPE_NET, net); |
1176 | } | 1201 | } |
1177 | 1202 | ||
1178 | static struct pernet_operations kobj_net_ops = { | 1203 | static struct pernet_operations kobj_net_ops = { |
1179 | .exit = net_kobj_ns_exit, | 1204 | .exit = net_kobj_ns_exit, |
1180 | }; | 1205 | }; |
1181 | 1206 | ||
1182 | 1207 | ||
1183 | #ifdef CONFIG_HOTPLUG | 1208 | #ifdef CONFIG_HOTPLUG |
1184 | static int netdev_uevent(struct device *d, struct kobj_uevent_env *env) | 1209 | static int netdev_uevent(struct device *d, struct kobj_uevent_env *env) |
1185 | { | 1210 | { |
1186 | struct net_device *dev = to_net_dev(d); | 1211 | struct net_device *dev = to_net_dev(d); |
1187 | int retval; | 1212 | int retval; |
1188 | 1213 | ||
1189 | /* pass interface to uevent. */ | 1214 | /* pass interface to uevent. */ |
1190 | retval = add_uevent_var(env, "INTERFACE=%s", dev->name); | 1215 | retval = add_uevent_var(env, "INTERFACE=%s", dev->name); |
1191 | if (retval) | 1216 | if (retval) |
1192 | goto exit; | 1217 | goto exit; |
1193 | 1218 | ||
1194 | /* pass ifindex to uevent. | 1219 | /* pass ifindex to uevent. |
1195 | * ifindex is useful as it won't change (interface name may change) | 1220 | * ifindex is useful as it won't change (interface name may change) |
1196 | * and is what RtNetlink uses natively. */ | 1221 | * and is what RtNetlink uses natively. */ |
1197 | retval = add_uevent_var(env, "IFINDEX=%d", dev->ifindex); | 1222 | retval = add_uevent_var(env, "IFINDEX=%d", dev->ifindex); |
1198 | 1223 | ||
1199 | exit: | 1224 | exit: |
1200 | return retval; | 1225 | return retval; |
1201 | } | 1226 | } |
1202 | #endif | 1227 | #endif |
1203 | 1228 | ||
1204 | /* | 1229 | /* |
1205 | * netdev_release -- destroy and free a dead device. | 1230 | * netdev_release -- destroy and free a dead device. |
1206 | * Called when last reference to device kobject is gone. | 1231 | * Called when last reference to device kobject is gone. |
1207 | */ | 1232 | */ |
1208 | static void netdev_release(struct device *d) | 1233 | static void netdev_release(struct device *d) |
1209 | { | 1234 | { |
1210 | struct net_device *dev = to_net_dev(d); | 1235 | struct net_device *dev = to_net_dev(d); |
1211 | 1236 | ||
1212 | BUG_ON(dev->reg_state != NETREG_RELEASED); | 1237 | BUG_ON(dev->reg_state != NETREG_RELEASED); |
1213 | 1238 | ||
1214 | kfree(dev->ifalias); | 1239 | kfree(dev->ifalias); |
1215 | kfree((char *)dev - dev->padded); | 1240 | kfree((char *)dev - dev->padded); |
1216 | } | 1241 | } |
1217 | 1242 | ||
1218 | static const void *net_namespace(struct device *d) | 1243 | static const void *net_namespace(struct device *d) |
1219 | { | 1244 | { |
1220 | struct net_device *dev; | 1245 | struct net_device *dev; |
1221 | dev = container_of(d, struct net_device, dev); | 1246 | dev = container_of(d, struct net_device, dev); |
1222 | return dev_net(dev); | 1247 | return dev_net(dev); |
1223 | } | 1248 | } |
1224 | 1249 | ||
1225 | static struct class net_class = { | 1250 | static struct class net_class = { |
1226 | .name = "net", | 1251 | .name = "net", |
1227 | .dev_release = netdev_release, | 1252 | .dev_release = netdev_release, |
1228 | #ifdef CONFIG_SYSFS | 1253 | #ifdef CONFIG_SYSFS |
1229 | .dev_attrs = net_class_attributes, | 1254 | .dev_attrs = net_class_attributes, |
1230 | #endif /* CONFIG_SYSFS */ | 1255 | #endif /* CONFIG_SYSFS */ |
1231 | #ifdef CONFIG_HOTPLUG | 1256 | #ifdef CONFIG_HOTPLUG |
1232 | .dev_uevent = netdev_uevent, | 1257 | .dev_uevent = netdev_uevent, |
1233 | #endif | 1258 | #endif |
1234 | .ns_type = &net_ns_type_operations, | 1259 | .ns_type = &net_ns_type_operations, |
1235 | .namespace = net_namespace, | 1260 | .namespace = net_namespace, |
1236 | }; | 1261 | }; |
1237 | 1262 | ||
1238 | /* Delete sysfs entries but hold kobject reference until after all | 1263 | /* Delete sysfs entries but hold kobject reference until after all |
1239 | * netdev references are gone. | 1264 | * netdev references are gone. |
1240 | */ | 1265 | */ |
1241 | void netdev_unregister_kobject(struct net_device * net) | 1266 | void netdev_unregister_kobject(struct net_device * net) |
1242 | { | 1267 | { |
1243 | struct device *dev = &(net->dev); | 1268 | struct device *dev = &(net->dev); |
1244 | 1269 | ||
1245 | kobject_get(&dev->kobj); | 1270 | kobject_get(&dev->kobj); |
1246 | 1271 | ||
1247 | #ifdef CONFIG_RPS | ||
1248 | remove_queue_kobjects(net); | 1272 | remove_queue_kobjects(net); |
1249 | #endif | ||
1250 | 1273 | ||
1251 | device_del(dev); | 1274 | device_del(dev); |
1252 | } | 1275 | } |
1253 | 1276 | ||
1254 | /* Create sysfs entries for network device. */ | 1277 | /* Create sysfs entries for network device. */ |
1255 | int netdev_register_kobject(struct net_device *net) | 1278 | int netdev_register_kobject(struct net_device *net) |
1256 | { | 1279 | { |
1257 | struct device *dev = &(net->dev); | 1280 | struct device *dev = &(net->dev); |
1258 | const struct attribute_group **groups = net->sysfs_groups; | 1281 | const struct attribute_group **groups = net->sysfs_groups; |
1259 | int error = 0; | 1282 | int error = 0; |
1260 | 1283 | ||
1261 | device_initialize(dev); | 1284 | device_initialize(dev); |
1262 | dev->class = &net_class; | 1285 | dev->class = &net_class; |
1263 | dev->platform_data = net; | 1286 | dev->platform_data = net; |
1264 | dev->groups = groups; | 1287 | dev->groups = groups; |
1265 | 1288 | ||
1266 | dev_set_name(dev, "%s", net->name); | 1289 | dev_set_name(dev, "%s", net->name); |
1267 | 1290 | ||
1268 | #ifdef CONFIG_SYSFS | 1291 | #ifdef CONFIG_SYSFS |
1269 | /* Allow for a device specific group */ | 1292 | /* Allow for a device specific group */ |
1270 | if (*groups) | 1293 | if (*groups) |
1271 | groups++; | 1294 | groups++; |
1272 | 1295 | ||
1273 | *groups++ = &netstat_group; | 1296 | *groups++ = &netstat_group; |
1274 | #ifdef CONFIG_WIRELESS_EXT_SYSFS | 1297 | #ifdef CONFIG_WIRELESS_EXT_SYSFS |
1275 | if (net->ieee80211_ptr) | 1298 | if (net->ieee80211_ptr) |
1276 | *groups++ = &wireless_group; | 1299 | *groups++ = &wireless_group; |
1277 | #ifdef CONFIG_WIRELESS_EXT | 1300 | #ifdef CONFIG_WIRELESS_EXT |
1278 | else if (net->wireless_handlers) | 1301 | else if (net->wireless_handlers) |
1279 | *groups++ = &wireless_group; | 1302 | *groups++ = &wireless_group; |
1280 | #endif | 1303 | #endif |
1281 | #endif | 1304 | #endif |
1282 | #endif /* CONFIG_SYSFS */ | 1305 | #endif /* CONFIG_SYSFS */ |
1283 | 1306 | ||
1284 | error = device_add(dev); | 1307 | error = device_add(dev); |
1285 | if (error) | 1308 | if (error) |
1286 | return error; | 1309 | return error; |
1287 | 1310 | ||
1288 | #ifdef CONFIG_RPS | ||
1289 | error = register_queue_kobjects(net); | 1311 | error = register_queue_kobjects(net); |
1290 | if (error) { | 1312 | if (error) { |
1291 | device_del(dev); | 1313 | device_del(dev); |
1292 | return error; | 1314 | return error; |
1293 | } | 1315 | } |
1294 | #endif | ||
1295 | 1316 | ||
1296 | return error; | 1317 | return error; |
1297 | } | 1318 | } |
1298 | 1319 | ||
1299 | int netdev_class_create_file(struct class_attribute *class_attr) | 1320 | int netdev_class_create_file(struct class_attribute *class_attr) |
1300 | { | 1321 | { |
1301 | return class_create_file(&net_class, class_attr); | 1322 | return class_create_file(&net_class, class_attr); |
1302 | } | 1323 | } |
1303 | EXPORT_SYMBOL(netdev_class_create_file); | 1324 | EXPORT_SYMBOL(netdev_class_create_file); |
1304 | 1325 | ||
1305 | void netdev_class_remove_file(struct class_attribute *class_attr) | 1326 | void netdev_class_remove_file(struct class_attribute *class_attr) |
1306 | { | 1327 | { |
1307 | class_remove_file(&net_class, class_attr); | 1328 | class_remove_file(&net_class, class_attr); |
1308 | } | 1329 | } |
1309 | EXPORT_SYMBOL(netdev_class_remove_file); | 1330 | EXPORT_SYMBOL(netdev_class_remove_file); |
1310 | 1331 | ||
1311 | int netdev_kobject_init(void) | 1332 | int netdev_kobject_init(void) |
net/core/net-sysfs.h
1 | #ifndef __NET_SYSFS_H__ | 1 | #ifndef __NET_SYSFS_H__ |
2 | #define __NET_SYSFS_H__ | 2 | #define __NET_SYSFS_H__ |
3 | 3 | ||
4 | int netdev_kobject_init(void); | 4 | int netdev_kobject_init(void); |
5 | int netdev_register_kobject(struct net_device *); | 5 | int netdev_register_kobject(struct net_device *); |
6 | void netdev_unregister_kobject(struct net_device *); | 6 | void netdev_unregister_kobject(struct net_device *); |
7 | #ifdef CONFIG_RPS | ||
8 | int net_rx_queue_update_kobjects(struct net_device *, int old_num, int new_num); | 7 | int net_rx_queue_update_kobjects(struct net_device *, int old_num, int new_num); |
9 | int netdev_queue_update_kobjects(struct net_device *net, | 8 | int netdev_queue_update_kobjects(struct net_device *net, |
10 | int old_num, int new_num); | 9 | int old_num, int new_num); |
11 | |||
12 | #endif | ||
13 | 10 | ||
14 | #endif | 11 | #endif |
15 | 12 |