]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/linux/netdevice.h
net: napi_hash_del() returns a boolean status
[mirror_ubuntu-artful-kernel.git] / include / linux / netdevice.h
CommitLineData
1da177e4
LT
1/*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * Definitions for the Interfaces handler.
7 *
8 * Version: @(#)dev.h 1.0.10 08/12/93
9 *
02c30a84 10 * Authors: Ross Biro
1da177e4
LT
11 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
12 * Corey Minyard <wf-rch!minyard@relay.EU.net>
13 * Donald J. Becker, <becker@cesdis.gsfc.nasa.gov>
113aa838 14 * Alan Cox, <alan@lxorguk.ukuu.org.uk>
1da177e4
LT
15 * Bjorn Ekwall. <bj0rn@blox.se>
16 * Pekka Riikonen <priikone@poseidon.pspt.fi>
17 *
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version
21 * 2 of the License, or (at your option) any later version.
22 *
23 * Moved to /usr/include/linux for NET3
24 */
25#ifndef _LINUX_NETDEVICE_H
26#define _LINUX_NETDEVICE_H
27
d7fe0f24 28#include <linux/timer.h>
187f1882 29#include <linux/bug.h>
bea3348e 30#include <linux/delay.h>
60063497 31#include <linux/atomic.h>
53511453 32#include <linux/prefetch.h>
1da177e4
LT
33#include <asm/cache.h>
34#include <asm/byteorder.h>
35
1da177e4 36#include <linux/percpu.h>
4d5b78c0 37#include <linux/rculist.h>
db217334 38#include <linux/dmaengine.h>
bea3348e 39#include <linux/workqueue.h>
114cf580 40#include <linux/dynamic_queue_limits.h>
1da177e4 41
b1b67dd4 42#include <linux/ethtool.h>
a050c33f 43#include <net/net_namespace.h>
cf85d08f 44#include <net/dsa.h>
7a6b6f51 45#ifdef CONFIG_DCB
2f90b865
AD
46#include <net/dcbnl.h>
47#endif
5bc1421e 48#include <net/netprio_cgroup.h>
a050c33f 49
a59e2ecb 50#include <linux/netdev_features.h>
77162022 51#include <linux/neighbour.h>
607ca46e 52#include <uapi/linux/netdevice.h>
61bd3857 53#include <uapi/linux/if_bonding.h>
a59e2ecb 54
115c1d6e 55struct netpoll_info;
313162d0 56struct device;
c1f19b51 57struct phy_device;
704232c2
JB
58/* 802.11 specific */
59struct wireless_dev;
98a18b6f
AA
60/* 802.15.4 specific */
61struct wpan_dev;
03c57747 62struct mpls_dev;
1da177e4 63
f629d208
JP
64void netdev_set_default_ethtool_ops(struct net_device *dev,
65 const struct ethtool_ops *ops);
d07d7507 66
9a1654ba
JP
67/* Backlog congestion levels */
68#define NET_RX_SUCCESS 0 /* keep 'em coming, baby */
69#define NET_RX_DROP 1 /* packet dropped */
70
572a9d7b
PM
71/*
72 * Transmit return codes: transmit return codes originate from three different
73 * namespaces:
74 *
75 * - qdisc return codes
76 * - driver transmit return codes
77 * - errno values
78 *
79 * Drivers are allowed to return any one of those in their hard_start_xmit()
80 * function. Real network devices commonly used with qdiscs should only return
81 * the driver transmit return codes though - when qdiscs are used, the actual
82 * transmission happens asynchronously, so the value is not propagated to
83 * higher layers. Virtual network devices transmit synchronously, in this case
84 * the driver transmit return codes are consumed by dev_queue_xmit(), all
85 * others are propagated to higher layers.
86 */
87
88/* qdisc ->enqueue() return codes. */
89#define NET_XMIT_SUCCESS 0x00
9a1654ba
JP
90#define NET_XMIT_DROP 0x01 /* skb dropped */
91#define NET_XMIT_CN 0x02 /* congestion notification */
92#define NET_XMIT_POLICED 0x03 /* skb is shot by police */
93#define NET_XMIT_MASK 0x0f /* qdisc flags in net/sch_generic.h */
1da177e4 94
b9df3cb8
GR
95/* NET_XMIT_CN is special. It does not guarantee that this packet is lost. It
96 * indicates that the device will soon be dropping packets, or already drops
97 * some packets of the same priority; prompting us to send less aggressively. */
572a9d7b 98#define net_xmit_eval(e) ((e) == NET_XMIT_CN ? 0 : (e))
1da177e4
LT
99#define net_xmit_errno(e) ((e) != NET_XMIT_CN ? -ENOBUFS : 0)
100
dc1f8bf6 101/* Driver transmit return codes */
9a1654ba 102#define NETDEV_TX_MASK 0xf0
572a9d7b 103
dc1f8bf6 104enum netdev_tx {
572a9d7b 105 __NETDEV_TX_MIN = INT_MIN, /* make sure enum is signed */
9a1654ba
JP
106 NETDEV_TX_OK = 0x00, /* driver took care of packet */
107 NETDEV_TX_BUSY = 0x10, /* driver tx path was busy*/
108 NETDEV_TX_LOCKED = 0x20, /* driver tx lock was already taken */
dc1f8bf6
SH
109};
110typedef enum netdev_tx netdev_tx_t;
111
9a1654ba
JP
112/*
113 * Current order: NETDEV_TX_MASK > NET_XMIT_MASK >= 0 is significant;
114 * hard_start_xmit() return < NET_XMIT_MASK means skb was consumed.
115 */
116static inline bool dev_xmit_complete(int rc)
117{
118 /*
119 * Positive cases with an skb consumed by a driver:
120 * - successful transmission (rc == NETDEV_TX_OK)
121 * - error while transmitting (rc < 0)
122 * - error while queueing to a different device (rc & NET_XMIT_MASK)
123 */
124 if (likely(rc < NET_XMIT_MASK))
125 return true;
126
127 return false;
128}
129
1da177e4
LT
130/*
131 * Compute the worst case header length according to the protocols
132 * used.
133 */
fe2918b0 134
d11ead75 135#if defined(CONFIG_WLAN) || IS_ENABLED(CONFIG_AX25)
8388e3da
DM
136# if defined(CONFIG_MAC80211_MESH)
137# define LL_MAX_HEADER 128
138# else
139# define LL_MAX_HEADER 96
140# endif
1da177e4 141#else
8388e3da 142# define LL_MAX_HEADER 32
1da177e4
LT
143#endif
144
d11ead75
BH
145#if !IS_ENABLED(CONFIG_NET_IPIP) && !IS_ENABLED(CONFIG_NET_IPGRE) && \
146 !IS_ENABLED(CONFIG_IPV6_SIT) && !IS_ENABLED(CONFIG_IPV6_TUNNEL)
1da177e4
LT
147#define MAX_HEADER LL_MAX_HEADER
148#else
149#define MAX_HEADER (LL_MAX_HEADER + 48)
150#endif
151
152/*
be1f3c2c
BH
153 * Old network device statistics. Fields are native words
154 * (unsigned long) so they can be read and written atomically.
1da177e4 155 */
fe2918b0 156
d94d9fee 157struct net_device_stats {
3cfde79c
BH
158 unsigned long rx_packets;
159 unsigned long tx_packets;
160 unsigned long rx_bytes;
161 unsigned long tx_bytes;
162 unsigned long rx_errors;
163 unsigned long tx_errors;
164 unsigned long rx_dropped;
165 unsigned long tx_dropped;
166 unsigned long multicast;
1da177e4 167 unsigned long collisions;
1da177e4 168 unsigned long rx_length_errors;
3cfde79c
BH
169 unsigned long rx_over_errors;
170 unsigned long rx_crc_errors;
171 unsigned long rx_frame_errors;
172 unsigned long rx_fifo_errors;
173 unsigned long rx_missed_errors;
1da177e4
LT
174 unsigned long tx_aborted_errors;
175 unsigned long tx_carrier_errors;
176 unsigned long tx_fifo_errors;
177 unsigned long tx_heartbeat_errors;
178 unsigned long tx_window_errors;
1da177e4
LT
179 unsigned long rx_compressed;
180 unsigned long tx_compressed;
181};
182
1da177e4
LT
183
184#include <linux/cache.h>
185#include <linux/skbuff.h>
186
adc9300e 187#ifdef CONFIG_RPS
c5905afb
IM
188#include <linux/static_key.h>
189extern struct static_key rps_needed;
adc9300e
ED
190#endif
191
1da177e4
LT
192struct neighbour;
193struct neigh_parms;
194struct sk_buff;
195
f001fde5
JP
196struct netdev_hw_addr {
197 struct list_head list;
198 unsigned char addr[MAX_ADDR_LEN];
199 unsigned char type;
ccffad25
JP
200#define NETDEV_HW_ADDR_T_LAN 1
201#define NETDEV_HW_ADDR_T_SAN 2
202#define NETDEV_HW_ADDR_T_SLAVE 3
203#define NETDEV_HW_ADDR_T_UNICAST 4
22bedad3 204#define NETDEV_HW_ADDR_T_MULTICAST 5
22bedad3 205 bool global_use;
4cd729b0 206 int sync_cnt;
8f8f103d 207 int refcount;
4543fbef 208 int synced;
f001fde5
JP
209 struct rcu_head rcu_head;
210};
211
31278e71
JP
212struct netdev_hw_addr_list {
213 struct list_head list;
214 int count;
215};
216
22bedad3
JP
217#define netdev_hw_addr_list_count(l) ((l)->count)
218#define netdev_hw_addr_list_empty(l) (netdev_hw_addr_list_count(l) == 0)
219#define netdev_hw_addr_list_for_each(ha, l) \
220 list_for_each_entry(ha, &(l)->list, list)
32e7bfc4 221
22bedad3
JP
222#define netdev_uc_count(dev) netdev_hw_addr_list_count(&(dev)->uc)
223#define netdev_uc_empty(dev) netdev_hw_addr_list_empty(&(dev)->uc)
224#define netdev_for_each_uc_addr(ha, dev) \
225 netdev_hw_addr_list_for_each(ha, &(dev)->uc)
6683ece3 226
22bedad3
JP
227#define netdev_mc_count(dev) netdev_hw_addr_list_count(&(dev)->mc)
228#define netdev_mc_empty(dev) netdev_hw_addr_list_empty(&(dev)->mc)
18e225f2 229#define netdev_for_each_mc_addr(ha, dev) \
22bedad3 230 netdev_hw_addr_list_for_each(ha, &(dev)->mc)
6683ece3 231
d94d9fee 232struct hh_cache {
f6b72b62 233 u16 hh_len;
5c25f686 234 u16 __pad;
3644f0ce 235 seqlock_t hh_lock;
1da177e4
LT
236
237 /* cached hardware header; allow for machine alignment needs. */
238#define HH_DATA_MOD 16
239#define HH_DATA_OFF(__len) \
5ba0eac6 240 (HH_DATA_MOD - (((__len - 1) & (HH_DATA_MOD - 1)) + 1))
1da177e4
LT
241#define HH_DATA_ALIGN(__len) \
242 (((__len)+(HH_DATA_MOD-1))&~(HH_DATA_MOD - 1))
243 unsigned long hh_data[HH_DATA_ALIGN(LL_MAX_HEADER) / sizeof(long)];
244};
245
246/* Reserve HH_DATA_MOD byte aligned hard_header_len, but at least that much.
247 * Alternative is:
248 * dev->hard_header_len ? (dev->hard_header_len +
249 * (HH_DATA_MOD - 1)) & ~(HH_DATA_MOD - 1) : 0
250 *
251 * We could use other alignment values, but we must maintain the
252 * relationship HH alignment <= LL alignment.
253 */
254#define LL_RESERVED_SPACE(dev) \
f5184d26 255 ((((dev)->hard_header_len+(dev)->needed_headroom)&~(HH_DATA_MOD - 1)) + HH_DATA_MOD)
1da177e4 256#define LL_RESERVED_SPACE_EXTRA(dev,extra) \
f5184d26 257 ((((dev)->hard_header_len+(dev)->needed_headroom+(extra))&~(HH_DATA_MOD - 1)) + HH_DATA_MOD)
1da177e4 258
3b04ddde
SH
259struct header_ops {
260 int (*create) (struct sk_buff *skb, struct net_device *dev,
261 unsigned short type, const void *daddr,
95c96174 262 const void *saddr, unsigned int len);
3b04ddde 263 int (*parse)(const struct sk_buff *skb, unsigned char *haddr);
e69dd336 264 int (*cache)(const struct neighbour *neigh, struct hh_cache *hh, __be16 type);
3b04ddde
SH
265 void (*cache_update)(struct hh_cache *hh,
266 const struct net_device *dev,
267 const unsigned char *haddr);
268};
269
1da177e4
LT
270/* These flag bits are private to the generic network queueing
271 * layer, they may not be explicitly referenced by any other
272 * code.
273 */
274
d94d9fee 275enum netdev_state_t {
1da177e4
LT
276 __LINK_STATE_START,
277 __LINK_STATE_PRESENT,
1da177e4 278 __LINK_STATE_NOCARRIER,
b00055aa
SR
279 __LINK_STATE_LINKWATCH_PENDING,
280 __LINK_STATE_DORMANT,
1da177e4
LT
281};
282
283
284/*
285 * This structure holds at boot time configured netdevice settings. They
fe2918b0 286 * are then used in the device probing.
1da177e4
LT
287 */
288struct netdev_boot_setup {
289 char name[IFNAMSIZ];
290 struct ifmap map;
291};
292#define NETDEV_BOOT_SETUP_MAX 8
293
f629d208 294int __init netdev_boot_setup(char *str);
1da177e4 295
bea3348e
SH
296/*
297 * Structure for NAPI scheduling similar to tasklet but with weighting
298 */
299struct napi_struct {
300 /* The poll_list must only be managed by the entity which
301 * changes the state of the NAPI_STATE_SCHED bit. This means
302 * whoever atomically sets that bit can add this napi_struct
303 * to the per-cpu poll_list, and whoever clears that bit
304 * can remove from the list right before clearing the bit.
305 */
306 struct list_head poll_list;
307
308 unsigned long state;
309 int weight;
404f7c9e 310 unsigned int gro_count;
bea3348e
SH
311 int (*poll)(struct napi_struct *, int);
312#ifdef CONFIG_NETPOLL
313 spinlock_t poll_lock;
314 int poll_owner;
bea3348e 315#endif
5d38a079 316 struct net_device *dev;
d565b0a1 317 struct sk_buff *gro_list;
5d38a079 318 struct sk_buff *skb;
3b47d303 319 struct hrtimer timer;
404f7c9e 320 struct list_head dev_list;
af12fa6e
ET
321 struct hlist_node napi_hash_node;
322 unsigned int napi_id;
bea3348e
SH
323};
324
d94d9fee 325enum {
bea3348e 326 NAPI_STATE_SCHED, /* Poll is scheduled */
a0a46196 327 NAPI_STATE_DISABLE, /* Disable pending */
7b363e44 328 NAPI_STATE_NPSVC, /* Netpoll - don't dequeue from poll_list */
d64b5e85
ED
329 NAPI_STATE_HASHED, /* In NAPI hash (busy polling possible) */
330 NAPI_STATE_NO_BUSY_POLL,/* Do not add in napi_hash, no busy polling */
bea3348e
SH
331};
332
5b252f0c 333enum gro_result {
d1c76af9
HX
334 GRO_MERGED,
335 GRO_MERGED_FREE,
336 GRO_HELD,
337 GRO_NORMAL,
338 GRO_DROP,
339};
5b252f0c 340typedef enum gro_result gro_result_t;
d1c76af9 341
8a4eb573
JP
342/*
343 * enum rx_handler_result - Possible return values for rx_handlers.
344 * @RX_HANDLER_CONSUMED: skb was consumed by rx_handler, do not process it
345 * further.
346 * @RX_HANDLER_ANOTHER: Do another round in receive path. This is indicated in
347 * case skb->dev was changed by rx_handler.
348 * @RX_HANDLER_EXACT: Force exact delivery, no wildcard.
349 * @RX_HANDLER_PASS: Do nothing, passe the skb as if no rx_handler was called.
350 *
351 * rx_handlers are functions called from inside __netif_receive_skb(), to do
352 * special processing of the skb, prior to delivery to protocol handlers.
353 *
354 * Currently, a net_device can only have a single rx_handler registered. Trying
355 * to register a second rx_handler will return -EBUSY.
356 *
357 * To register a rx_handler on a net_device, use netdev_rx_handler_register().
358 * To unregister a rx_handler on a net_device, use
359 * netdev_rx_handler_unregister().
360 *
361 * Upon return, rx_handler is expected to tell __netif_receive_skb() what to
362 * do with the skb.
363 *
364 * If the rx_handler consumed to skb in some way, it should return
365 * RX_HANDLER_CONSUMED. This is appropriate when the rx_handler arranged for
366 * the skb to be delivered in some other ways.
367 *
368 * If the rx_handler changed skb->dev, to divert the skb to another
369 * net_device, it should return RX_HANDLER_ANOTHER. The rx_handler for the
370 * new device will be called if it exists.
371 *
372 * If the rx_handler consider the skb should be ignored, it should return
373 * RX_HANDLER_EXACT. The skb will only be delivered to protocol handlers that
d93cf068 374 * are registered on exact device (ptype->dev == skb->dev).
8a4eb573
JP
375 *
376 * If the rx_handler didn't changed skb->dev, but want the skb to be normally
377 * delivered, it should return RX_HANDLER_PASS.
378 *
379 * A device without a registered rx_handler will behave as if rx_handler
380 * returned RX_HANDLER_PASS.
381 */
382
383enum rx_handler_result {
384 RX_HANDLER_CONSUMED,
385 RX_HANDLER_ANOTHER,
386 RX_HANDLER_EXACT,
387 RX_HANDLER_PASS,
388};
389typedef enum rx_handler_result rx_handler_result_t;
390typedef rx_handler_result_t rx_handler_func_t(struct sk_buff **pskb);
ab95bfe0 391
f629d208 392void __napi_schedule(struct napi_struct *n);
bc9ad166 393void __napi_schedule_irqoff(struct napi_struct *n);
bea3348e 394
4d29515f 395static inline bool napi_disable_pending(struct napi_struct *n)
a0a46196
DM
396{
397 return test_bit(NAPI_STATE_DISABLE, &n->state);
398}
399
bea3348e
SH
400/**
401 * napi_schedule_prep - check if napi can be scheduled
402 * @n: napi context
403 *
404 * Test if NAPI routine is already running, and if not mark
405 * it as running. This is used as a condition variable
a0a46196
DM
406 * insure only one NAPI poll instance runs. We also make
407 * sure there is no pending NAPI disable.
bea3348e 408 */
4d29515f 409static inline bool napi_schedule_prep(struct napi_struct *n)
bea3348e 410{
a0a46196
DM
411 return !napi_disable_pending(n) &&
412 !test_and_set_bit(NAPI_STATE_SCHED, &n->state);
bea3348e
SH
413}
414
415/**
416 * napi_schedule - schedule NAPI poll
417 * @n: napi context
418 *
419 * Schedule NAPI poll routine to be called if it is not already
420 * running.
421 */
422static inline void napi_schedule(struct napi_struct *n)
423{
424 if (napi_schedule_prep(n))
425 __napi_schedule(n);
426}
427
bc9ad166
ED
428/**
429 * napi_schedule_irqoff - schedule NAPI poll
430 * @n: napi context
431 *
432 * Variant of napi_schedule(), assuming hard irqs are masked.
433 */
434static inline void napi_schedule_irqoff(struct napi_struct *n)
435{
436 if (napi_schedule_prep(n))
437 __napi_schedule_irqoff(n);
438}
439
bfe13f54 440/* Try to reschedule poll. Called by dev->poll() after napi_complete(). */
4d29515f 441static inline bool napi_reschedule(struct napi_struct *napi)
bfe13f54
RD
442{
443 if (napi_schedule_prep(napi)) {
444 __napi_schedule(napi);
4d29515f 445 return true;
bfe13f54 446 }
4d29515f 447 return false;
bfe13f54
RD
448}
449
3b47d303
ED
450void __napi_complete(struct napi_struct *n);
451void napi_complete_done(struct napi_struct *n, int work_done);
bea3348e
SH
452/**
453 * napi_complete - NAPI processing complete
454 * @n: napi context
455 *
456 * Mark NAPI processing as complete.
3b47d303 457 * Consider using napi_complete_done() instead.
bea3348e 458 */
3b47d303
ED
459static inline void napi_complete(struct napi_struct *n)
460{
461 return napi_complete_done(n, 0);
462}
bea3348e 463
af12fa6e
ET
464/**
465 * napi_hash_add - add a NAPI to global hashtable
466 * @napi: napi context
467 *
468 * generate a new napi_id and store a @napi under it in napi_hash
469 */
f629d208 470void napi_hash_add(struct napi_struct *napi);
af12fa6e
ET
471
472/**
473 * napi_hash_del - remove a NAPI from global table
474 * @napi: napi context
475 *
476 * Warning: caller must observe rcu grace period
34cbe27e
ED
477 * before freeing memory containing @napi, if
478 * this function returns true.
af12fa6e 479 */
34cbe27e 480bool napi_hash_del(struct napi_struct *napi);
af12fa6e 481
bea3348e
SH
482/**
483 * napi_disable - prevent NAPI from scheduling
484 * @n: napi context
485 *
486 * Stop NAPI from being scheduled on this context.
487 * Waits till any outstanding processing completes.
488 */
3b47d303 489void napi_disable(struct napi_struct *n);
bea3348e
SH
490
491/**
492 * napi_enable - enable NAPI scheduling
493 * @n: napi context
494 *
495 * Resume NAPI from being scheduled on this context.
496 * Must be paired with napi_disable.
497 */
498static inline void napi_enable(struct napi_struct *n)
499{
500 BUG_ON(!test_bit(NAPI_STATE_SCHED, &n->state));
4e857c58 501 smp_mb__before_atomic();
bea3348e 502 clear_bit(NAPI_STATE_SCHED, &n->state);
2d8bff12 503 clear_bit(NAPI_STATE_NPSVC, &n->state);
bea3348e
SH
504}
505
c264c3de
SH
506#ifdef CONFIG_SMP
507/**
508 * napi_synchronize - wait until NAPI is not running
509 * @n: napi context
510 *
511 * Wait until NAPI is done being scheduled on this context.
512 * Waits till any outstanding processing completes but
513 * does not disable future activations.
514 */
515static inline void napi_synchronize(const struct napi_struct *n)
516{
517 while (test_bit(NAPI_STATE_SCHED, &n->state))
518 msleep(1);
519}
520#else
521# define napi_synchronize(n) barrier()
522#endif
523
d94d9fee 524enum netdev_queue_state_t {
73466498
TH
525 __QUEUE_STATE_DRV_XOFF,
526 __QUEUE_STATE_STACK_XOFF,
c3f26a26 527 __QUEUE_STATE_FROZEN,
79d16385 528};
8e2f1a63
DB
529
530#define QUEUE_STATE_DRV_XOFF (1 << __QUEUE_STATE_DRV_XOFF)
531#define QUEUE_STATE_STACK_XOFF (1 << __QUEUE_STATE_STACK_XOFF)
532#define QUEUE_STATE_FROZEN (1 << __QUEUE_STATE_FROZEN)
533
534#define QUEUE_STATE_ANY_XOFF (QUEUE_STATE_DRV_XOFF | QUEUE_STATE_STACK_XOFF)
535#define QUEUE_STATE_ANY_XOFF_OR_FROZEN (QUEUE_STATE_ANY_XOFF | \
536 QUEUE_STATE_FROZEN)
537#define QUEUE_STATE_DRV_XOFF_OR_FROZEN (QUEUE_STATE_DRV_XOFF | \
538 QUEUE_STATE_FROZEN)
539
73466498
TH
540/*
541 * __QUEUE_STATE_DRV_XOFF is used by drivers to stop the transmit queue. The
542 * netif_tx_* functions below are used to manipulate this flag. The
543 * __QUEUE_STATE_STACK_XOFF flag is used by the stack to stop the transmit
544 * queue independently. The netif_xmit_*stopped functions below are called
545 * to check if the queue has been stopped by the driver or stack (either
546 * of the XOFF bits are set in the state). Drivers should not need to call
547 * netif_xmit*stopped functions, they should only be using netif_tx_*.
548 */
79d16385 549
bb949fbd 550struct netdev_queue {
6a321cb3
ED
551/*
552 * read mostly part
553 */
bb949fbd 554 struct net_device *dev;
46e5da40 555 struct Qdisc __rcu *qdisc;
b0e1e646 556 struct Qdisc *qdisc_sleeping;
ccf5ff69 557#ifdef CONFIG_SYSFS
1d24eb48
TH
558 struct kobject kobj;
559#endif
f2cd2d3e
ED
560#if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
561 int numa_node;
562#endif
6a321cb3
ED
563/*
564 * write mostly part
565 */
566 spinlock_t _xmit_lock ____cacheline_aligned_in_smp;
567 int xmit_lock_owner;
9d21493b
ED
568 /*
569 * please use this field instead of dev->trans_start
570 */
571 unsigned long trans_start;
ccf5ff69 572
573 /*
574 * Number of TX timeouts for this queue
575 * (/sys/class/net/DEV/Q/trans_timeout)
576 */
577 unsigned long trans_timeout;
114cf580
TH
578
579 unsigned long state;
580
581#ifdef CONFIG_BQL
582 struct dql dql;
583#endif
822b3b2e 584 unsigned long tx_maxrate;
e8a0464c 585} ____cacheline_aligned_in_smp;
bb949fbd 586
f2cd2d3e
ED
587static inline int netdev_queue_numa_node_read(const struct netdev_queue *q)
588{
589#if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
590 return q->numa_node;
591#else
b236da69 592 return NUMA_NO_NODE;
f2cd2d3e
ED
593#endif
594}
595
596static inline void netdev_queue_numa_node_write(struct netdev_queue *q, int node)
597{
598#if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
599 q->numa_node = node;
600#endif
601}
602
df334545 603#ifdef CONFIG_RPS
0a9627f2
TH
604/*
605 * This structure holds an RPS map which can be of variable length. The
606 * map is an array of CPUs.
607 */
608struct rps_map {
609 unsigned int len;
610 struct rcu_head rcu;
611 u16 cpus[0];
612};
60b778ce 613#define RPS_MAP_SIZE(_num) (sizeof(struct rps_map) + ((_num) * sizeof(u16)))
0a9627f2 614
fec5e652 615/*
c445477d
BH
616 * The rps_dev_flow structure contains the mapping of a flow to a CPU, the
617 * tail pointer for that CPU's input queue at the time of last enqueue, and
618 * a hardware filter index.
fec5e652
TH
619 */
620struct rps_dev_flow {
621 u16 cpu;
c445477d 622 u16 filter;
fec5e652
TH
623 unsigned int last_qtail;
624};
c445477d 625#define RPS_NO_FILTER 0xffff
fec5e652
TH
626
627/*
628 * The rps_dev_flow_table structure contains a table of flow mappings.
629 */
630struct rps_dev_flow_table {
631 unsigned int mask;
632 struct rcu_head rcu;
fec5e652
TH
633 struct rps_dev_flow flows[0];
634};
635#define RPS_DEV_FLOW_TABLE_SIZE(_num) (sizeof(struct rps_dev_flow_table) + \
60b778ce 636 ((_num) * sizeof(struct rps_dev_flow)))
fec5e652
TH
637
638/*
639 * The rps_sock_flow_table contains mappings of flows to the last CPU
640 * on which they were processed by the application (set in recvmsg).
567e4b79
ED
641 * Each entry is a 32bit value. Upper part is the high order bits
642 * of flow hash, lower part is cpu number.
643 * rps_cpu_mask is used to partition the space, depending on number of
644 * possible cpus : rps_cpu_mask = roundup_pow_of_two(nr_cpu_ids) - 1
645 * For example, if 64 cpus are possible, rps_cpu_mask = 0x3f,
646 * meaning we use 32-6=26 bits for the hash.
fec5e652
TH
647 */
648struct rps_sock_flow_table {
567e4b79 649 u32 mask;
93c1af6c
ED
650
651 u32 ents[0] ____cacheline_aligned_in_smp;
fec5e652 652};
567e4b79 653#define RPS_SOCK_FLOW_TABLE_SIZE(_num) (offsetof(struct rps_sock_flow_table, ents[_num]))
fec5e652
TH
654
655#define RPS_NO_CPU 0xffff
656
567e4b79
ED
657extern u32 rps_cpu_mask;
658extern struct rps_sock_flow_table __rcu *rps_sock_flow_table;
659
fec5e652
TH
660static inline void rps_record_sock_flow(struct rps_sock_flow_table *table,
661 u32 hash)
662{
663 if (table && hash) {
567e4b79
ED
664 unsigned int index = hash & table->mask;
665 u32 val = hash & ~rps_cpu_mask;
fec5e652
TH
666
667 /* We only give a hint, preemption can change cpu under us */
567e4b79 668 val |= raw_smp_processor_id();
fec5e652 669
567e4b79
ED
670 if (table->ents[index] != val)
671 table->ents[index] = val;
fec5e652
TH
672 }
673}
674
c445477d 675#ifdef CONFIG_RFS_ACCEL
f629d208
JP
676bool rps_may_expire_flow(struct net_device *dev, u16 rxq_index, u32 flow_id,
677 u16 filter_id);
c445477d 678#endif
a953be53 679#endif /* CONFIG_RPS */
c445477d 680
0a9627f2
TH
681/* This structure contains an instance of an RX queue. */
682struct netdev_rx_queue {
a953be53 683#ifdef CONFIG_RPS
6e3f7faf
ED
684 struct rps_map __rcu *rps_map;
685 struct rps_dev_flow_table __rcu *rps_flow_table;
a953be53 686#endif
6e3f7faf 687 struct kobject kobj;
fe822240 688 struct net_device *dev;
0a9627f2 689} ____cacheline_aligned_in_smp;
a953be53
MD
690
691/*
692 * RX queue sysfs structures and functions.
693 */
694struct rx_queue_attribute {
695 struct attribute attr;
696 ssize_t (*show)(struct netdev_rx_queue *queue,
697 struct rx_queue_attribute *attr, char *buf);
698 ssize_t (*store)(struct netdev_rx_queue *queue,
699 struct rx_queue_attribute *attr, const char *buf, size_t len);
700};
d314774c 701
bf264145
TH
702#ifdef CONFIG_XPS
703/*
704 * This structure holds an XPS map which can be of variable length. The
705 * map is an array of queues.
706 */
707struct xps_map {
708 unsigned int len;
709 unsigned int alloc_len;
710 struct rcu_head rcu;
711 u16 queues[0];
712};
60b778ce 713#define XPS_MAP_SIZE(_num) (sizeof(struct xps_map) + ((_num) * sizeof(u16)))
c59f419b
HD
714#define XPS_MIN_MAP_ALLOC ((L1_CACHE_ALIGN(offsetof(struct xps_map, queues[1])) \
715 - sizeof(struct xps_map)) / sizeof(u16))
bf264145
TH
716
717/*
718 * This structure holds all XPS maps for device. Maps are indexed by CPU.
719 */
720struct xps_dev_maps {
721 struct rcu_head rcu;
a4177869 722 struct xps_map __rcu *cpu_map[0];
bf264145
TH
723};
724#define XPS_DEV_MAPS_SIZE (sizeof(struct xps_dev_maps) + \
725 (nr_cpu_ids * sizeof(struct xps_map *)))
726#endif /* CONFIG_XPS */
727
4f57c087
JF
728#define TC_MAX_QUEUE 16
729#define TC_BITMASK 15
730/* HW offloaded queuing disciplines txq count and offset maps */
731struct netdev_tc_txq {
732 u16 count;
733 u16 offset;
734};
735
68bad94e
NP
736#if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
737/*
738 * This structure is to hold information about the device
739 * configured to run FCoE protocol stack.
740 */
741struct netdev_fcoe_hbainfo {
742 char manufacturer[64];
743 char serial_number[64];
744 char hardware_version[64];
745 char driver_version[64];
746 char optionrom_version[64];
747 char firmware_version[64];
748 char model[256];
749 char model_description[256];
750};
751#endif
752
02637fce 753#define MAX_PHYS_ITEM_ID_LEN 32
66b52b0d 754
02637fce
JP
755/* This structure holds a unique identifier to identify some
756 * physical item (port for example) used by a netdevice.
66b52b0d 757 */
02637fce
JP
758struct netdev_phys_item_id {
759 unsigned char id[MAX_PHYS_ITEM_ID_LEN];
66b52b0d
JP
760 unsigned char id_len;
761};
762
d754f98b
SF
763static inline bool netdev_phys_item_id_same(struct netdev_phys_item_id *a,
764 struct netdev_phys_item_id *b)
765{
766 return a->id_len == b->id_len &&
767 memcmp(a->id, b->id, a->id_len) == 0;
768}
769
99932d4f
DB
770typedef u16 (*select_queue_fallback_t)(struct net_device *dev,
771 struct sk_buff *skb);
772
d314774c
SH
773/*
774 * This structure defines the management hooks for network devices.
00829823
SH
775 * The following hooks can be defined; unless noted otherwise, they are
776 * optional and can be filled with a null pointer.
d314774c
SH
777 *
778 * int (*ndo_init)(struct net_device *dev);
779 * This function is called once when network device is registered.
780 * The network device can use this to any late stage initializaton
781 * or semantic validattion. It can fail with an error code which will
782 * be propogated back to register_netdev
783 *
784 * void (*ndo_uninit)(struct net_device *dev);
785 * This function is called when device is unregistered or when registration
786 * fails. It is not called if init fails.
787 *
788 * int (*ndo_open)(struct net_device *dev);
789 * This function is called when network device transistions to the up
790 * state.
791 *
792 * int (*ndo_stop)(struct net_device *dev);
793 * This function is called when network device transistions to the down
794 * state.
795 *
dc1f8bf6
SH
796 * netdev_tx_t (*ndo_start_xmit)(struct sk_buff *skb,
797 * struct net_device *dev);
00829823 798 * Called when a packet needs to be transmitted.
e79d8429
RR
799 * Returns NETDEV_TX_OK. Can return NETDEV_TX_BUSY, but you should stop
800 * the queue before that can happen; it's for obsolete devices and weird
801 * corner cases, but the stack really does a non-trivial amount
802 * of useless work if you return NETDEV_TX_BUSY.
dc1f8bf6 803 * (can also return NETDEV_TX_LOCKED iff NETIF_F_LLTX)
00829823
SH
804 * Required can not be NULL.
805 *
f663dd9a 806 * u16 (*ndo_select_queue)(struct net_device *dev, struct sk_buff *skb,
99932d4f 807 * void *accel_priv, select_queue_fallback_t fallback);
00829823
SH
808 * Called to decide which queue to when device supports multiple
809 * transmit queues.
810 *
d314774c
SH
811 * void (*ndo_change_rx_flags)(struct net_device *dev, int flags);
812 * This function is called to allow device receiver to make
813 * changes to configuration when multicast or promiscious is enabled.
814 *
815 * void (*ndo_set_rx_mode)(struct net_device *dev);
816 * This function is called device changes address list filtering.
01789349
JP
817 * If driver handles unicast address filtering, it should set
818 * IFF_UNICAST_FLT to its priv_flags.
d314774c
SH
819 *
820 * int (*ndo_set_mac_address)(struct net_device *dev, void *addr);
821 * This function is called when the Media Access Control address
37b607c5 822 * needs to be changed. If this interface is not defined, the
d314774c
SH
823 * mac address can not be changed.
824 *
825 * int (*ndo_validate_addr)(struct net_device *dev);
826 * Test if Media Access Control address is valid for the device.
827 *
828 * int (*ndo_do_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd);
829 * Called when a user request an ioctl which can't be handled by
830 * the generic interface code. If not defined ioctl's return
831 * not supported error code.
832 *
833 * int (*ndo_set_config)(struct net_device *dev, struct ifmap *map);
834 * Used to set network devices bus interface parameters. This interface
835 * is retained for legacy reason, new devices should use the bus
836 * interface (PCI) for low level management.
837 *
838 * int (*ndo_change_mtu)(struct net_device *dev, int new_mtu);
839 * Called when a user wants to change the Maximum Transfer Unit
840 * of a device. If not defined, any request to change MTU will
841 * will return an error.
842 *
00829823 843 * void (*ndo_tx_timeout)(struct net_device *dev);
d314774c
SH
844 * Callback uses when the transmitter has not made any progress
845 * for dev->watchdog ticks.
846 *
3cfde79c 847 * struct rtnl_link_stats64* (*ndo_get_stats64)(struct net_device *dev,
28172739 848 * struct rtnl_link_stats64 *storage);
d308e38f 849 * struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
d314774c 850 * Called when a user wants to get the network device usage
be1f3c2c 851 * statistics. Drivers must do one of the following:
3cfde79c
BH
852 * 1. Define @ndo_get_stats64 to fill in a zero-initialised
853 * rtnl_link_stats64 structure passed by the caller.
82695d9b 854 * 2. Define @ndo_get_stats to update a net_device_stats structure
be1f3c2c
BH
855 * (which should normally be dev->stats) and return a pointer to
856 * it. The structure may be changed asynchronously only if each
857 * field is written atomically.
858 * 3. Update dev->stats asynchronously and atomically, and define
859 * neither operation.
d314774c 860 *
5d632cb7 861 * int (*ndo_vlan_rx_add_vid)(struct net_device *dev, __be16 proto, u16 vid);
80d5c368
PM
862 * If device support VLAN filtering this function is called when a
863 * VLAN id is registered.
d314774c 864 *
5d632cb7 865 * int (*ndo_vlan_rx_kill_vid)(struct net_device *dev, __be16 proto, u16 vid);
80d5c368
PM
866 * If device support VLAN filtering this function is called when a
867 * VLAN id is unregistered.
d314774c
SH
868 *
869 * void (*ndo_poll_controller)(struct net_device *dev);
95c26df8
WM
870 *
871 * SR-IOV management functions.
872 * int (*ndo_set_vf_mac)(struct net_device *dev, int vf, u8* mac);
873 * int (*ndo_set_vf_vlan)(struct net_device *dev, int vf, u16 vlan, u8 qos);
ed616689
SC
874 * int (*ndo_set_vf_rate)(struct net_device *dev, int vf, int min_tx_rate,
875 * int max_tx_rate);
5f8444a3 876 * int (*ndo_set_vf_spoofchk)(struct net_device *dev, int vf, bool setting);
dd461d6a 877 * int (*ndo_set_vf_trust)(struct net_device *dev, int vf, bool setting);
95c26df8
WM
878 * int (*ndo_get_vf_config)(struct net_device *dev,
879 * int vf, struct ifla_vf_info *ivf);
1d8faf48 880 * int (*ndo_set_vf_link_state)(struct net_device *dev, int vf, int link_state);
57b61080
SF
881 * int (*ndo_set_vf_port)(struct net_device *dev, int vf,
882 * struct nlattr *port[]);
01a3d796
VZ
883 *
884 * Enable or disable the VF ability to query its RSS Redirection Table and
885 * Hash Key. This is needed since on some devices VF share this information
886 * with PF and querying it may adduce a theoretical security risk.
887 * int (*ndo_set_vf_rss_query_en)(struct net_device *dev, int vf, bool setting);
57b61080 888 * int (*ndo_get_vf_port)(struct net_device *dev, int vf, struct sk_buff *skb);
4f57c087
JF
889 * int (*ndo_setup_tc)(struct net_device *dev, u8 tc)
890 * Called to setup 'tc' number of traffic classes in the net device. This
891 * is always called from the stack with the rtnl lock held and netif tx
892 * queues stopped. This allows the netdevice to perform queue management
893 * safely.
c445477d 894 *
e9bce845
YZ
895 * Fiber Channel over Ethernet (FCoE) offload functions.
896 * int (*ndo_fcoe_enable)(struct net_device *dev);
897 * Called when the FCoE protocol stack wants to start using LLD for FCoE
898 * so the underlying device can perform whatever needed configuration or
899 * initialization to support acceleration of FCoE traffic.
900 *
901 * int (*ndo_fcoe_disable)(struct net_device *dev);
902 * Called when the FCoE protocol stack wants to stop using LLD for FCoE
903 * so the underlying device can perform whatever needed clean-ups to
904 * stop supporting acceleration of FCoE traffic.
905 *
906 * int (*ndo_fcoe_ddp_setup)(struct net_device *dev, u16 xid,
907 * struct scatterlist *sgl, unsigned int sgc);
908 * Called when the FCoE Initiator wants to initialize an I/O that
909 * is a possible candidate for Direct Data Placement (DDP). The LLD can
910 * perform necessary setup and returns 1 to indicate the device is set up
911 * successfully to perform DDP on this I/O, otherwise this returns 0.
912 *
913 * int (*ndo_fcoe_ddp_done)(struct net_device *dev, u16 xid);
914 * Called when the FCoE Initiator/Target is done with the DDPed I/O as
915 * indicated by the FC exchange id 'xid', so the underlying device can
916 * clean up and reuse resources for later DDP requests.
917 *
918 * int (*ndo_fcoe_ddp_target)(struct net_device *dev, u16 xid,
919 * struct scatterlist *sgl, unsigned int sgc);
920 * Called when the FCoE Target wants to initialize an I/O that
921 * is a possible candidate for Direct Data Placement (DDP). The LLD can
922 * perform necessary setup and returns 1 to indicate the device is set up
923 * successfully to perform DDP on this I/O, otherwise this returns 0.
924 *
68bad94e
NP
925 * int (*ndo_fcoe_get_hbainfo)(struct net_device *dev,
926 * struct netdev_fcoe_hbainfo *hbainfo);
927 * Called when the FCoE Protocol stack wants information on the underlying
928 * device. This information is utilized by the FCoE protocol stack to
929 * register attributes with Fiber Channel management service as per the
930 * FC-GS Fabric Device Management Information(FDMI) specification.
931 *
e9bce845
YZ
932 * int (*ndo_fcoe_get_wwn)(struct net_device *dev, u64 *wwn, int type);
933 * Called when the underlying device wants to override default World Wide
934 * Name (WWN) generation mechanism in FCoE protocol stack to pass its own
935 * World Wide Port Name (WWPN) or World Wide Node Name (WWNN) to the FCoE
936 * protocol stack to use.
937 *
c445477d
BH
938 * RFS acceleration.
939 * int (*ndo_rx_flow_steer)(struct net_device *dev, const struct sk_buff *skb,
940 * u16 rxq_index, u32 flow_id);
941 * Set hardware filter for RFS. rxq_index is the target queue index;
942 * flow_id is a flow ID to be passed to rps_may_expire_flow() later.
943 * Return the filter ID on success, or a negative error code.
fbaec0ea 944 *
8b98a70c 945 * Slave management functions (for bridge, bonding, etc).
fbaec0ea
JP
946 * int (*ndo_add_slave)(struct net_device *dev, struct net_device *slave_dev);
947 * Called to make another netdev an underling.
948 *
949 * int (*ndo_del_slave)(struct net_device *dev, struct net_device *slave_dev);
950 * Called to release previously enslaved netdev.
5455c699
MM
951 *
952 * Feature/offload setting functions.
c8f44aff
MM
953 * netdev_features_t (*ndo_fix_features)(struct net_device *dev,
954 * netdev_features_t features);
5455c699
MM
955 * Adjusts the requested feature flags according to device-specific
956 * constraints, and returns the resulting flags. Must not modify
957 * the device state.
958 *
c8f44aff 959 * int (*ndo_set_features)(struct net_device *dev, netdev_features_t features);
5455c699
MM
960 * Called to update device configuration to new features. Passed
961 * feature set might be less than what was returned by ndo_fix_features()).
962 * Must return >0 or -errno if it changed dev->features itself.
963 *
edc7d573 964 * int (*ndo_fdb_add)(struct ndmsg *ndm, struct nlattr *tb[],
965 * struct net_device *dev,
f6f6424b 966 * const unsigned char *addr, u16 vid, u16 flags)
77162022 967 * Adds an FDB entry to dev for addr.
1690be63
VY
968 * int (*ndo_fdb_del)(struct ndmsg *ndm, struct nlattr *tb[],
969 * struct net_device *dev,
f6f6424b 970 * const unsigned char *addr, u16 vid)
77162022
JF
971 * Deletes the FDB entry from dev coresponding to addr.
972 * int (*ndo_fdb_dump)(struct sk_buff *skb, struct netlink_callback *cb,
5d5eacb3
JHS
973 * struct net_device *dev, struct net_device *filter_dev,
974 * int idx)
77162022
JF
975 * Used to add FDB entries to dump requests. Implementers should add
976 * entries to skb and update idx with the number of entries.
e5a55a89 977 *
ad41faa8
ND
978 * int (*ndo_bridge_setlink)(struct net_device *dev, struct nlmsghdr *nlh,
979 * u16 flags)
e5a55a89 980 * int (*ndo_bridge_getlink)(struct sk_buff *skb, u32 pid, u32 seq,
46c264da
ND
981 * struct net_device *dev, u32 filter_mask,
982 * int nlflags)
ad41faa8
ND
983 * int (*ndo_bridge_dellink)(struct net_device *dev, struct nlmsghdr *nlh,
984 * u16 flags);
4bf84c35
JP
985 *
986 * int (*ndo_change_carrier)(struct net_device *dev, bool new_carrier);
987 * Called to change device carrier. Soft-devices (like dummy, team, etc)
988 * which do not represent real hardware may define this to allow their
989 * userspace components to manage their virtual carrier state. Devices
990 * that determine carrier state from physical hardware properties (eg
991 * network cables) or protocol-dependent mechanisms (eg
992 * USB_CDC_NOTIFY_NETWORK_CONNECTION) should NOT implement this function.
66b52b0d
JP
993 *
994 * int (*ndo_get_phys_port_id)(struct net_device *dev,
02637fce 995 * struct netdev_phys_item_id *ppid);
66b52b0d
JP
996 * Called to get ID of physical port of this device. If driver does
997 * not implement this, it is assumed that the hw is not able to have
998 * multiple net devices on single physical port.
53cf5275
JG
999 *
1000 * void (*ndo_add_vxlan_port)(struct net_device *dev,
35e42379 1001 * sa_family_t sa_family, __be16 port);
53cf5275
JG
1002 * Called by vxlan to notiy a driver about the UDP port and socket
1003 * address family that vxlan is listnening to. It is called only when
1004 * a new port starts listening. The operation is protected by the
1005 * vxlan_net->sock_lock.
1006 *
1007 * void (*ndo_del_vxlan_port)(struct net_device *dev,
35e42379 1008 * sa_family_t sa_family, __be16 port);
53cf5275
JG
1009 * Called by vxlan to notify the driver about a UDP port and socket
1010 * address family that vxlan is not listening to anymore. The operation
1011 * is protected by the vxlan_net->sock_lock.
a6cc0cfa
JF
1012 *
1013 * void* (*ndo_dfwd_add_station)(struct net_device *pdev,
1014 * struct net_device *dev)
1015 * Called by upper layer devices to accelerate switching or other
1016 * station functionality into hardware. 'pdev is the lowerdev
1017 * to use for the offload and 'dev' is the net device that will
1018 * back the offload. Returns a pointer to the private structure
1019 * the upper layer will maintain.
1020 * void (*ndo_dfwd_del_station)(struct net_device *pdev, void *priv)
1021 * Called by upper layer device to delete the station created
1022 * by 'ndo_dfwd_add_station'. 'pdev' is the net device backing
1023 * the station and priv is the structure returned by the add
1024 * operation.
1025 * netdev_tx_t (*ndo_dfwd_start_xmit)(struct sk_buff *skb,
1026 * struct net_device *dev,
1027 * void *priv);
1028 * Callback to use for xmit over the accelerated station. This
1029 * is used in place of ndo_start_xmit on accelerated net
1030 * devices.
5f35227e
JG
1031 * netdev_features_t (*ndo_features_check) (struct sk_buff *skb,
1032 * struct net_device *dev
1033 * netdev_features_t features);
04ffcb25 1034 * Called by core transmit path to determine if device is capable of
5f35227e
JG
1035 * performing offload operations on a given packet. This is to give
1036 * the device an opportunity to implement any restrictions that cannot
1037 * be otherwise expressed by feature flags. The check is called with
1038 * the set of features that the stack has calculated and it returns
1039 * those the driver believes to be appropriate.
822b3b2e
JF
1040 * int (*ndo_set_tx_maxrate)(struct net_device *dev,
1041 * int queue_index, u32 maxrate);
1042 * Called when a user wants to set a max-rate limitation of specific
1043 * TX queue.
a54acb3a
ND
1044 * int (*ndo_get_iflink)(const struct net_device *dev);
1045 * Called to get the iflink value of this device.
d746d707
AK
1046 * void (*ndo_change_proto_down)(struct net_device *dev,
1047 * bool proto_down);
1048 * This function is used to pass protocol port error state information
1049 * to the switch driver. The switch driver can react to the proto_down
1050 * by doing a phys down on the associated switch port.
fc4099f1
PS
1051 * int (*ndo_fill_metadata_dst)(struct net_device *dev, struct sk_buff *skb);
1052 * This function is used to get egress tunnel information for given skb.
1053 * This is useful for retrieving outer tunnel header parameters while
1054 * sampling packet.
d746d707 1055 *
d314774c
SH
1056 */
1057struct net_device_ops {
1058 int (*ndo_init)(struct net_device *dev);
1059 void (*ndo_uninit)(struct net_device *dev);
1060 int (*ndo_open)(struct net_device *dev);
1061 int (*ndo_stop)(struct net_device *dev);
dc1f8bf6 1062 netdev_tx_t (*ndo_start_xmit) (struct sk_buff *skb,
00829823
SH
1063 struct net_device *dev);
1064 u16 (*ndo_select_queue)(struct net_device *dev,
f663dd9a 1065 struct sk_buff *skb,
99932d4f
DB
1066 void *accel_priv,
1067 select_queue_fallback_t fallback);
d314774c
SH
1068 void (*ndo_change_rx_flags)(struct net_device *dev,
1069 int flags);
d314774c 1070 void (*ndo_set_rx_mode)(struct net_device *dev);
d314774c
SH
1071 int (*ndo_set_mac_address)(struct net_device *dev,
1072 void *addr);
d314774c 1073 int (*ndo_validate_addr)(struct net_device *dev);
d314774c
SH
1074 int (*ndo_do_ioctl)(struct net_device *dev,
1075 struct ifreq *ifr, int cmd);
d314774c
SH
1076 int (*ndo_set_config)(struct net_device *dev,
1077 struct ifmap *map);
00829823
SH
1078 int (*ndo_change_mtu)(struct net_device *dev,
1079 int new_mtu);
1080 int (*ndo_neigh_setup)(struct net_device *dev,
1081 struct neigh_parms *);
d314774c
SH
1082 void (*ndo_tx_timeout) (struct net_device *dev);
1083
28172739
ED
1084 struct rtnl_link_stats64* (*ndo_get_stats64)(struct net_device *dev,
1085 struct rtnl_link_stats64 *storage);
d314774c
SH
1086 struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
1087
8e586137 1088 int (*ndo_vlan_rx_add_vid)(struct net_device *dev,
80d5c368 1089 __be16 proto, u16 vid);
8e586137 1090 int (*ndo_vlan_rx_kill_vid)(struct net_device *dev,
80d5c368 1091 __be16 proto, u16 vid);
d314774c 1092#ifdef CONFIG_NET_POLL_CONTROLLER
d314774c 1093 void (*ndo_poll_controller)(struct net_device *dev);
4247e161 1094 int (*ndo_netpoll_setup)(struct net_device *dev,
a8779ec1 1095 struct netpoll_info *info);
0e34e931 1096 void (*ndo_netpoll_cleanup)(struct net_device *dev);
06021292 1097#endif
e0d1095a 1098#ifdef CONFIG_NET_RX_BUSY_POLL
8b80cda5 1099 int (*ndo_busy_poll)(struct napi_struct *dev);
d314774c 1100#endif
95c26df8
WM
1101 int (*ndo_set_vf_mac)(struct net_device *dev,
1102 int queue, u8 *mac);
1103 int (*ndo_set_vf_vlan)(struct net_device *dev,
1104 int queue, u16 vlan, u8 qos);
ed616689
SC
1105 int (*ndo_set_vf_rate)(struct net_device *dev,
1106 int vf, int min_tx_rate,
1107 int max_tx_rate);
5f8444a3
GR
1108 int (*ndo_set_vf_spoofchk)(struct net_device *dev,
1109 int vf, bool setting);
dd461d6a
HS
1110 int (*ndo_set_vf_trust)(struct net_device *dev,
1111 int vf, bool setting);
95c26df8
WM
1112 int (*ndo_get_vf_config)(struct net_device *dev,
1113 int vf,
1114 struct ifla_vf_info *ivf);
1d8faf48
RE
1115 int (*ndo_set_vf_link_state)(struct net_device *dev,
1116 int vf, int link_state);
3b766cd8
EBE
1117 int (*ndo_get_vf_stats)(struct net_device *dev,
1118 int vf,
1119 struct ifla_vf_stats
1120 *vf_stats);
57b61080
SF
1121 int (*ndo_set_vf_port)(struct net_device *dev,
1122 int vf,
1123 struct nlattr *port[]);
1124 int (*ndo_get_vf_port)(struct net_device *dev,
1125 int vf, struct sk_buff *skb);
01a3d796
VZ
1126 int (*ndo_set_vf_rss_query_en)(
1127 struct net_device *dev,
1128 int vf, bool setting);
4f57c087 1129 int (*ndo_setup_tc)(struct net_device *dev, u8 tc);
d11ead75 1130#if IS_ENABLED(CONFIG_FCOE)
cb454399
YZ
1131 int (*ndo_fcoe_enable)(struct net_device *dev);
1132 int (*ndo_fcoe_disable)(struct net_device *dev);
4d288d57
YZ
1133 int (*ndo_fcoe_ddp_setup)(struct net_device *dev,
1134 u16 xid,
1135 struct scatterlist *sgl,
1136 unsigned int sgc);
1137 int (*ndo_fcoe_ddp_done)(struct net_device *dev,
1138 u16 xid);
6247e086
YZ
1139 int (*ndo_fcoe_ddp_target)(struct net_device *dev,
1140 u16 xid,
1141 struct scatterlist *sgl,
1142 unsigned int sgc);
68bad94e
NP
1143 int (*ndo_fcoe_get_hbainfo)(struct net_device *dev,
1144 struct netdev_fcoe_hbainfo *hbainfo);
3c9c36bc
BPG
1145#endif
1146
d11ead75 1147#if IS_ENABLED(CONFIG_LIBFCOE)
df5c7945
YZ
1148#define NETDEV_FCOE_WWNN 0
1149#define NETDEV_FCOE_WWPN 1
1150 int (*ndo_fcoe_get_wwn)(struct net_device *dev,
1151 u64 *wwn, int type);
4d288d57 1152#endif
3c9c36bc 1153
c445477d
BH
1154#ifdef CONFIG_RFS_ACCEL
1155 int (*ndo_rx_flow_steer)(struct net_device *dev,
1156 const struct sk_buff *skb,
1157 u16 rxq_index,
1158 u32 flow_id);
1159#endif
fbaec0ea
JP
1160 int (*ndo_add_slave)(struct net_device *dev,
1161 struct net_device *slave_dev);
1162 int (*ndo_del_slave)(struct net_device *dev,
1163 struct net_device *slave_dev);
c8f44aff
MM
1164 netdev_features_t (*ndo_fix_features)(struct net_device *dev,
1165 netdev_features_t features);
5455c699 1166 int (*ndo_set_features)(struct net_device *dev,
c8f44aff 1167 netdev_features_t features);
da6a8fa0 1168 int (*ndo_neigh_construct)(struct neighbour *n);
447f2191 1169 void (*ndo_neigh_destroy)(struct neighbour *n);
77162022
JF
1170
1171 int (*ndo_fdb_add)(struct ndmsg *ndm,
edc7d573 1172 struct nlattr *tb[],
77162022 1173 struct net_device *dev,
6b6e2725 1174 const unsigned char *addr,
f6f6424b 1175 u16 vid,
77162022
JF
1176 u16 flags);
1177 int (*ndo_fdb_del)(struct ndmsg *ndm,
1690be63 1178 struct nlattr *tb[],
77162022 1179 struct net_device *dev,
f6f6424b
JP
1180 const unsigned char *addr,
1181 u16 vid);
77162022
JF
1182 int (*ndo_fdb_dump)(struct sk_buff *skb,
1183 struct netlink_callback *cb,
1184 struct net_device *dev,
5d5eacb3 1185 struct net_device *filter_dev,
77162022 1186 int idx);
e5a55a89
JF
1187
1188 int (*ndo_bridge_setlink)(struct net_device *dev,
add511b3
RP
1189 struct nlmsghdr *nlh,
1190 u16 flags);
e5a55a89
JF
1191 int (*ndo_bridge_getlink)(struct sk_buff *skb,
1192 u32 pid, u32 seq,
6cbdceeb 1193 struct net_device *dev,
46c264da
ND
1194 u32 filter_mask,
1195 int nlflags);
407af329 1196 int (*ndo_bridge_dellink)(struct net_device *dev,
add511b3
RP
1197 struct nlmsghdr *nlh,
1198 u16 flags);
4bf84c35
JP
1199 int (*ndo_change_carrier)(struct net_device *dev,
1200 bool new_carrier);
66b52b0d 1201 int (*ndo_get_phys_port_id)(struct net_device *dev,
02637fce 1202 struct netdev_phys_item_id *ppid);
db24a904
DA
1203 int (*ndo_get_phys_port_name)(struct net_device *dev,
1204 char *name, size_t len);
53cf5275
JG
1205 void (*ndo_add_vxlan_port)(struct net_device *dev,
1206 sa_family_t sa_family,
35e42379 1207 __be16 port);
53cf5275
JG
1208 void (*ndo_del_vxlan_port)(struct net_device *dev,
1209 sa_family_t sa_family,
35e42379 1210 __be16 port);
a6cc0cfa
JF
1211
1212 void* (*ndo_dfwd_add_station)(struct net_device *pdev,
1213 struct net_device *dev);
1214 void (*ndo_dfwd_del_station)(struct net_device *pdev,
1215 void *priv);
1216
1217 netdev_tx_t (*ndo_dfwd_start_xmit) (struct sk_buff *skb,
1218 struct net_device *dev,
1219 void *priv);
25175ba5 1220 int (*ndo_get_lock_subclass)(struct net_device *dev);
5f35227e
JG
1221 netdev_features_t (*ndo_features_check) (struct sk_buff *skb,
1222 struct net_device *dev,
1223 netdev_features_t features);
822b3b2e
JF
1224 int (*ndo_set_tx_maxrate)(struct net_device *dev,
1225 int queue_index,
1226 u32 maxrate);
a54acb3a 1227 int (*ndo_get_iflink)(const struct net_device *dev);
d746d707
AK
1228 int (*ndo_change_proto_down)(struct net_device *dev,
1229 bool proto_down);
fc4099f1
PS
1230 int (*ndo_fill_metadata_dst)(struct net_device *dev,
1231 struct sk_buff *skb);
d314774c
SH
1232};
1233
7aa98047
LR
1234/**
1235 * enum net_device_priv_flags - &struct net_device priv_flags
1236 *
1237 * These are the &struct net_device, they are only set internally
1238 * by drivers and used in the kernel. These flags are invisible to
1239 * userspace, this means that the order of these flags can change
1240 * during any kernel release.
1241 *
1242 * You should have a pretty good reason to be extending these flags.
1243 *
1244 * @IFF_802_1Q_VLAN: 802.1Q VLAN device
1245 * @IFF_EBRIDGE: Ethernet bridging device
7aa98047 1246 * @IFF_BONDING: bonding master or slave
7aa98047 1247 * @IFF_ISATAP: ISATAP interface (RFC4214)
7aa98047
LR
1248 * @IFF_WAN_HDLC: WAN HDLC device
1249 * @IFF_XMIT_DST_RELEASE: dev_hard_start_xmit() is allowed to
1250 * release skb->dst
1251 * @IFF_DONT_BRIDGE: disallow bridging this ether dev
1252 * @IFF_DISABLE_NETPOLL: disable netpoll at run-time
1253 * @IFF_MACVLAN_PORT: device used as macvlan port
1254 * @IFF_BRIDGE_PORT: device used as bridge port
1255 * @IFF_OVS_DATAPATH: device used as Open vSwitch datapath port
1256 * @IFF_TX_SKB_SHARING: The interface supports sharing skbs on transmit
1257 * @IFF_UNICAST_FLT: Supports unicast filtering
1258 * @IFF_TEAM_PORT: device used as team port
1259 * @IFF_SUPP_NOFCS: device supports sending custom FCS
1260 * @IFF_LIVE_ADDR_CHANGE: device supports hardware address
1261 * change when it's running
1262 * @IFF_MACVLAN: Macvlan device
007979ea 1263 * @IFF_L3MDEV_MASTER: device is an L3 master device
fa8187c9 1264 * @IFF_NO_QUEUE: device can run without qdisc attached
35d4e172 1265 * @IFF_OPENVSWITCH: device is a Open vSwitch master
fee6d4c7 1266 * @IFF_L3MDEV_SLAVE: device is enslaved to an L3 master device
7aa98047
LR
1267 */
1268enum netdev_priv_flags {
1269 IFF_802_1Q_VLAN = 1<<0,
1270 IFF_EBRIDGE = 1<<1,
0dc1549b
JP
1271 IFF_BONDING = 1<<2,
1272 IFF_ISATAP = 1<<3,
1273 IFF_WAN_HDLC = 1<<4,
1274 IFF_XMIT_DST_RELEASE = 1<<5,
1275 IFF_DONT_BRIDGE = 1<<6,
1276 IFF_DISABLE_NETPOLL = 1<<7,
1277 IFF_MACVLAN_PORT = 1<<8,
1278 IFF_BRIDGE_PORT = 1<<9,
1279 IFF_OVS_DATAPATH = 1<<10,
1280 IFF_TX_SKB_SHARING = 1<<11,
1281 IFF_UNICAST_FLT = 1<<12,
1282 IFF_TEAM_PORT = 1<<13,
1283 IFF_SUPP_NOFCS = 1<<14,
1284 IFF_LIVE_ADDR_CHANGE = 1<<15,
1285 IFF_MACVLAN = 1<<16,
1286 IFF_XMIT_DST_RELEASE_PERM = 1<<17,
1287 IFF_IPVLAN_MASTER = 1<<18,
1288 IFF_IPVLAN_SLAVE = 1<<19,
007979ea 1289 IFF_L3MDEV_MASTER = 1<<20,
0dc1549b
JP
1290 IFF_NO_QUEUE = 1<<21,
1291 IFF_OPENVSWITCH = 1<<22,
fee6d4c7 1292 IFF_L3MDEV_SLAVE = 1<<23,
7aa98047
LR
1293};
1294
1295#define IFF_802_1Q_VLAN IFF_802_1Q_VLAN
1296#define IFF_EBRIDGE IFF_EBRIDGE
7aa98047 1297#define IFF_BONDING IFF_BONDING
7aa98047 1298#define IFF_ISATAP IFF_ISATAP
7aa98047
LR
1299#define IFF_WAN_HDLC IFF_WAN_HDLC
1300#define IFF_XMIT_DST_RELEASE IFF_XMIT_DST_RELEASE
1301#define IFF_DONT_BRIDGE IFF_DONT_BRIDGE
1302#define IFF_DISABLE_NETPOLL IFF_DISABLE_NETPOLL
1303#define IFF_MACVLAN_PORT IFF_MACVLAN_PORT
1304#define IFF_BRIDGE_PORT IFF_BRIDGE_PORT
1305#define IFF_OVS_DATAPATH IFF_OVS_DATAPATH
1306#define IFF_TX_SKB_SHARING IFF_TX_SKB_SHARING
1307#define IFF_UNICAST_FLT IFF_UNICAST_FLT
1308#define IFF_TEAM_PORT IFF_TEAM_PORT
1309#define IFF_SUPP_NOFCS IFF_SUPP_NOFCS
1310#define IFF_LIVE_ADDR_CHANGE IFF_LIVE_ADDR_CHANGE
1311#define IFF_MACVLAN IFF_MACVLAN
02875878 1312#define IFF_XMIT_DST_RELEASE_PERM IFF_XMIT_DST_RELEASE_PERM
2ad7bf36
MB
1313#define IFF_IPVLAN_MASTER IFF_IPVLAN_MASTER
1314#define IFF_IPVLAN_SLAVE IFF_IPVLAN_SLAVE
007979ea 1315#define IFF_L3MDEV_MASTER IFF_L3MDEV_MASTER
fa8187c9 1316#define IFF_NO_QUEUE IFF_NO_QUEUE
35d4e172 1317#define IFF_OPENVSWITCH IFF_OPENVSWITCH
8f25348b 1318#define IFF_L3MDEV_SLAVE IFF_L3MDEV_SLAVE
7aa98047 1319
536721b1
KK
1320/**
1321 * struct net_device - The DEVICE structure.
1322 * Actually, this whole structure is a big mistake. It mixes I/O
1323 * data with strictly "high-level" data, and it has to know about
1324 * almost every data structure used in the INET module.
1325 *
1326 * @name: This is the first field of the "visible" part of this structure
1327 * (i.e. as seen by users in the "Space.c" file). It is the name
1328 * of the interface.
1329 *
1330 * @name_hlist: Device name hash chain, please keep it close to name[]
1331 * @ifalias: SNMP alias
1332 * @mem_end: Shared memory end
1333 * @mem_start: Shared memory start
1334 * @base_addr: Device I/O address
1335 * @irq: Device IRQ number
1336 *
14ffbbb8
TG
1337 * @carrier_changes: Stats to monitor carrier on<->off transitions
1338 *
536721b1
KK
1339 * @state: Generic network queuing layer state, see netdev_state_t
1340 * @dev_list: The global list of network devices
1341 * @napi_list: List entry, that is used for polling napi devices
1342 * @unreg_list: List entry, that is used, when we are unregistering the
1343 * device, see the function unregister_netdev
1344 * @close_list: List entry, that is used, when we are closing the device
1345 *
1346 * @adj_list: Directly linked devices, like slaves for bonding
1347 * @all_adj_list: All linked devices, *including* neighbours
1348 * @features: Currently active device features
1349 * @hw_features: User-changeable features
1350 *
1351 * @wanted_features: User-requested features
1352 * @vlan_features: Mask of features inheritable by VLAN devices
1353 *
1354 * @hw_enc_features: Mask of features inherited by encapsulating devices
1355 * This field indicates what encapsulation
1356 * offloads the hardware is capable of doing,
1357 * and drivers will need to set them appropriately.
1358 *
1359 * @mpls_features: Mask of features inheritable by MPLS
1360 *
1361 * @ifindex: interface index
388069d3 1362 * @group: The group, that the device belongs to
536721b1
KK
1363 *
1364 * @stats: Statistics struct, which was left as a legacy, use
1365 * rtnl_link_stats64 instead
1366 *
1367 * @rx_dropped: Dropped packets by core network,
1368 * do not use this in drivers
1369 * @tx_dropped: Dropped packets by core network,
1370 * do not use this in drivers
1371 *
536721b1
KK
1372 * @wireless_handlers: List of functions to handle Wireless Extensions,
1373 * instead of ioctl,
1374 * see <net/iw_handler.h> for details.
1375 * @wireless_data: Instance data managed by the core of wireless extensions
1376 *
1377 * @netdev_ops: Includes several pointers to callbacks,
1378 * if one wants to override the ndo_*() functions
1379 * @ethtool_ops: Management operations
d476059e 1380 * @header_ops: Includes callbacks for creating,parsing,caching,etc
536721b1
KK
1381 * of Layer 2 headers.
1382 *
1383 * @flags: Interface flags (a la BSD)
1384 * @priv_flags: Like 'flags' but invisible to userspace,
1385 * see if.h for the definitions
1386 * @gflags: Global flags ( kept as legacy )
1387 * @padded: How much padding added by alloc_netdev()
1388 * @operstate: RFC2863 operstate
1389 * @link_mode: Mapping policy to operstate
1390 * @if_port: Selectable AUI, TP, ...
1391 * @dma: DMA channel
1392 * @mtu: Interface MTU value
1393 * @type: Interface hardware type
1394 * @hard_header_len: Hardware header length
1395 *
1396 * @needed_headroom: Extra headroom the hardware may need, but not in all
1397 * cases can this be guaranteed
1398 * @needed_tailroom: Extra tailroom the hardware may need, but not in all
1399 * cases can this be guaranteed. Some cases also use
1400 * LL_MAX_HEADER instead to allocate the skb
1401 *
1402 * interface address info:
1403 *
1404 * @perm_addr: Permanent hw address
1405 * @addr_assign_type: Hw address assignment type
1406 * @addr_len: Hardware address length
1407 * @neigh_priv_len; Used in neigh_alloc(),
1408 * initialized only in atm/clip.c
1409 * @dev_id: Used to differentiate devices that share
1410 * the same link layer address
1411 * @dev_port: Used to differentiate devices that share
1412 * the same function
1413 * @addr_list_lock: XXX: need comments on this one
536721b1
KK
1414 * @uc_promisc: Counter, that indicates, that promiscuous mode
1415 * has been enabled due to the need to listen to
1416 * additional unicast addresses in a device that
1417 * does not implement ndo_set_rx_mode()
14ffbbb8
TG
1418 * @uc: unicast mac addresses
1419 * @mc: multicast mac addresses
1420 * @dev_addrs: list of device hw addresses
1421 * @queues_kset: Group of all Kobjects in the Tx and RX queues
536721b1
KK
1422 * @promiscuity: Number of times, the NIC is told to work in
1423 * Promiscuous mode, if it becomes 0 the NIC will
1424 * exit from working in Promiscuous mode
1425 * @allmulti: Counter, enables or disables allmulticast mode
1426 *
1427 * @vlan_info: VLAN info
1428 * @dsa_ptr: dsa specific data
1429 * @tipc_ptr: TIPC specific data
1430 * @atalk_ptr: AppleTalk link
1431 * @ip_ptr: IPv4 specific data
1432 * @dn_ptr: DECnet specific data
1433 * @ip6_ptr: IPv6 specific data
1434 * @ax25_ptr: AX.25 specific data
1435 * @ieee80211_ptr: IEEE 802.11 specific data, assign before registering
1436 *
1437 * @last_rx: Time of last Rx
1438 * @dev_addr: Hw address (before bcast,
1439 * because most packets are unicast)
1440 *
1441 * @_rx: Array of RX queues
1442 * @num_rx_queues: Number of RX queues
1443 * allocated at register_netdev() time
1444 * @real_num_rx_queues: Number of RX queues currently active in device
1445 *
1446 * @rx_handler: handler for received packets
1447 * @rx_handler_data: XXX: need comments on this one
1448 * @ingress_queue: XXX: need comments on this one
1449 * @broadcast: hw bcast address
1450 *
14ffbbb8
TG
1451 * @rx_cpu_rmap: CPU reverse-mapping for RX completion interrupts,
1452 * indexed by RX queue number. Assigned by driver.
1453 * This must only be set if the ndo_rx_flow_steer
1454 * operation is defined
1455 * @index_hlist: Device index hash chain
1456 *
536721b1
KK
1457 * @_tx: Array of TX queues
1458 * @num_tx_queues: Number of TX queues allocated at alloc_netdev_mq() time
1459 * @real_num_tx_queues: Number of TX queues currently active in device
1460 * @qdisc: Root qdisc from userspace point of view
1461 * @tx_queue_len: Max frames per queue allowed
1462 * @tx_global_lock: XXX: need comments on this one
1463 *
1464 * @xps_maps: XXX: need comments on this one
1465 *
0c4f691f
SF
1466 * @offload_fwd_mark: Offload device fwding mark
1467 *
536721b1
KK
1468 * @trans_start: Time (in jiffies) of last Tx
1469 * @watchdog_timeo: Represents the timeout that is used by
1470 * the watchdog ( see dev_watchdog() )
1471 * @watchdog_timer: List of timers
1472 *
1473 * @pcpu_refcnt: Number of references to this device
1474 * @todo_list: Delayed register/unregister
536721b1
KK
1475 * @link_watch_list: XXX: need comments on this one
1476 *
1477 * @reg_state: Register/unregister state machine
1478 * @dismantle: Device is going to be freed
1479 * @rtnl_link_state: This enum represents the phases of creating
1480 * a new link
1481 *
1482 * @destructor: Called from unregister,
1483 * can be used to call free_netdev
1484 * @npinfo: XXX: need comments on this one
1485 * @nd_net: Network namespace this network device is inside
1486 *
1487 * @ml_priv: Mid-layer private
1488 * @lstats: Loopback statistics
1489 * @tstats: Tunnel statistics
1490 * @dstats: Dummy statistics
1491 * @vstats: Virtual ethernet statistics
1492 *
1493 * @garp_port: GARP
1494 * @mrp_port: MRP
1495 *
1496 * @dev: Class/net/name entry
1497 * @sysfs_groups: Space for optional device, statistics and wireless
1498 * sysfs groups
1499 *
1500 * @sysfs_rx_queue_group: Space for optional per-rx queue attributes
1501 * @rtnl_link_ops: Rtnl_link_ops
1502 *
1503 * @gso_max_size: Maximum size of generic segmentation offload
1504 * @gso_max_segs: Maximum number of segments that can be passed to the
1505 * NIC for GSO
fcbeb976
ED
1506 * @gso_min_segs: Minimum number of segments that can be passed to the
1507 * NIC for GSO
536721b1
KK
1508 *
1509 * @dcbnl_ops: Data Center Bridging netlink ops
1510 * @num_tc: Number of traffic classes in the net device
1511 * @tc_to_txq: XXX: need comments on this one
1512 * @prio_tc_map XXX: need comments on this one
1513 *
1514 * @fcoe_ddp_xid: Max exchange id for FCoE LRO by ddp
1515 *
1516 * @priomap: XXX: need comments on this one
1517 * @phydev: Physical device may attach itself
1518 * for hardware timestamping
1519 *
1520 * @qdisc_tx_busylock: XXX: need comments on this one
1521 *
d746d707
AK
1522 * @proto_down: protocol port state information can be sent to the
1523 * switch driver and used to set the phys state of the
1524 * switch port.
1525 *
1da177e4
LT
1526 * FIXME: cleanup struct net_device such that network protocol info
1527 * moves out.
1528 */
1529
d94d9fee 1530struct net_device {
1da177e4 1531 char name[IFNAMSIZ];
9356b8fc 1532 struct hlist_node name_hlist;
0b815a1a 1533 char *ifalias;
1da177e4
LT
1534 /*
1535 * I/O specific fields
1536 * FIXME: Merge these and struct ifmap into one
1537 */
536721b1
KK
1538 unsigned long mem_end;
1539 unsigned long mem_start;
1540 unsigned long base_addr;
1541 int irq;
1da177e4 1542
14ffbbb8
TG
1543 atomic_t carrier_changes;
1544
1da177e4 1545 /*
536721b1
KK
1546 * Some hardware also needs these fields (state,dev_list,
1547 * napi_list,unreg_list,close_list) but they are not
1da177e4
LT
1548 * part of the usual set specified in Space.c.
1549 */
1550
1da177e4
LT
1551 unsigned long state;
1552
7562f876 1553 struct list_head dev_list;
bea3348e 1554 struct list_head napi_list;
44a0873d 1555 struct list_head unreg_list;
5cde2829 1556 struct list_head close_list;
7866a621
SN
1557 struct list_head ptype_all;
1558 struct list_head ptype_specific;
2f268f12 1559
2f268f12
VF
1560 struct {
1561 struct list_head upper;
1562 struct list_head lower;
1563 } adj_list;
1564
2f268f12
VF
1565 struct {
1566 struct list_head upper;
1567 struct list_head lower;
1568 } all_adj_list;
4c3d5e7b 1569
c8f44aff 1570 netdev_features_t features;
c8f44aff 1571 netdev_features_t hw_features;
c8f44aff 1572 netdev_features_t wanted_features;
c8f44aff 1573 netdev_features_t vlan_features;
6a674e9c 1574 netdev_features_t hw_enc_features;
0d89d203 1575 netdev_features_t mpls_features;
04ed3e74 1576
1da177e4 1577 int ifindex;
7a66bbc9 1578 int group;
1da177e4 1579
c45d286e 1580 struct net_device_stats stats;
015f0688 1581
015f0688
ED
1582 atomic_long_t rx_dropped;
1583 atomic_long_t tx_dropped;
1da177e4 1584
b86e0280 1585#ifdef CONFIG_WIRELESS_EXT
1da177e4 1586 const struct iw_handler_def * wireless_handlers;
1da177e4 1587 struct iw_public_data * wireless_data;
b86e0280 1588#endif
d314774c 1589 const struct net_device_ops *netdev_ops;
76fd8593 1590 const struct ethtool_ops *ethtool_ops;
4170604f 1591#ifdef CONFIG_NET_SWITCHDEV
9d47c0a2 1592 const struct switchdev_ops *switchdev_ops;
4170604f 1593#endif
1b69c6d0
DA
1594#ifdef CONFIG_NET_L3_MASTER_DEV
1595 const struct l3mdev_ops *l3mdev_ops;
1596#endif
1da177e4 1597
3b04ddde
SH
1598 const struct header_ops *header_ops;
1599
536721b1
KK
1600 unsigned int flags;
1601 unsigned int priv_flags;
1602
1da177e4 1603 unsigned short gflags;
536721b1 1604 unsigned short padded;
1da177e4 1605
536721b1
KK
1606 unsigned char operstate;
1607 unsigned char link_mode;
b00055aa 1608
536721b1
KK
1609 unsigned char if_port;
1610 unsigned char dma;
bdc220da 1611
536721b1
KK
1612 unsigned int mtu;
1613 unsigned short type;
1614 unsigned short hard_header_len;
1da177e4 1615
f5184d26
JB
1616 unsigned short needed_headroom;
1617 unsigned short needed_tailroom;
1618
1da177e4 1619 /* Interface address info. */
536721b1
KK
1620 unsigned char perm_addr[MAX_ADDR_LEN];
1621 unsigned char addr_assign_type;
1622 unsigned char addr_len;
a0a9663d 1623 unsigned short neigh_priv_len;
536721b1
KK
1624 unsigned short dev_id;
1625 unsigned short dev_port;
ccffad25 1626 spinlock_t addr_list_lock;
14ffbbb8
TG
1627 unsigned char name_assign_type;
1628 bool uc_promisc;
536721b1
KK
1629 struct netdev_hw_addr_list uc;
1630 struct netdev_hw_addr_list mc;
1631 struct netdev_hw_addr_list dev_addrs;
1632
4c3d5e7b
ED
1633#ifdef CONFIG_SYSFS
1634 struct kset *queues_kset;
1635#endif
9d45abe1
WC
1636 unsigned int promiscuity;
1637 unsigned int allmulti;
1da177e4 1638
1da177e4
LT
1639
1640 /* Protocol specific pointers */
65ac6a5f 1641
d11ead75 1642#if IS_ENABLED(CONFIG_VLAN_8021Q)
536721b1 1643 struct vlan_info __rcu *vlan_info;
65ac6a5f 1644#endif
34a430d7 1645#if IS_ENABLED(CONFIG_NET_DSA)
536721b1 1646 struct dsa_switch_tree *dsa_ptr;
37cb0620
YX
1647#endif
1648#if IS_ENABLED(CONFIG_TIPC)
536721b1 1649 struct tipc_bearer __rcu *tipc_ptr;
91da11f8 1650#endif
536721b1
KK
1651 void *atalk_ptr;
1652 struct in_device __rcu *ip_ptr;
1653 struct dn_dev __rcu *dn_ptr;
1654 struct inet6_dev __rcu *ip6_ptr;
1655 void *ax25_ptr;
1656 struct wireless_dev *ieee80211_ptr;
98a18b6f 1657 struct wpan_dev *ieee802154_ptr;
03c57747
RS
1658#if IS_ENABLED(CONFIG_MPLS_ROUTING)
1659 struct mpls_dev __rcu *mpls_ptr;
1660#endif
1da177e4 1661
9356b8fc 1662/*
cd13539b 1663 * Cache lines mostly used on receive path (including eth_type_trans())
9356b8fc 1664 */
536721b1 1665 unsigned long last_rx;
4dc89133 1666
9356b8fc 1667 /* Interface address info used in eth_type_trans() */
536721b1 1668 unsigned char *dev_addr;
f001fde5 1669
0a9627f2 1670
a953be53 1671#ifdef CONFIG_SYSFS
0a9627f2
TH
1672 struct netdev_rx_queue *_rx;
1673
0a9627f2 1674 unsigned int num_rx_queues;
62fe0b40 1675 unsigned int real_num_rx_queues;
c445477d 1676
df334545 1677#endif
0a9627f2 1678
3b47d303 1679 unsigned long gro_flush_timeout;
61391cde 1680 rx_handler_func_t __rcu *rx_handler;
1681 void __rcu *rx_handler_data;
e8a0464c 1682
4cda01e8 1683#ifdef CONFIG_NET_CLS_ACT
d2788d34
DB
1684 struct tcf_proto __rcu *ingress_cl_list;
1685#endif
24824a09 1686 struct netdev_queue __rcu *ingress_queue;
e687ad60
PN
1687#ifdef CONFIG_NETFILTER_INGRESS
1688 struct list_head nf_hooks_ingress;
1689#endif
d2788d34 1690
536721b1 1691 unsigned char broadcast[MAX_ADDR_LEN];
14ffbbb8
TG
1692#ifdef CONFIG_RFS_ACCEL
1693 struct cpu_rmap *rx_cpu_rmap;
1694#endif
1695 struct hlist_node index_hlist;
cd13539b
ED
1696
1697/*
1698 * Cache lines mostly used on transmit path
1699 */
e8a0464c
DM
1700 struct netdev_queue *_tx ____cacheline_aligned_in_smp;
1701 unsigned int num_tx_queues;
fd2ea0a7 1702 unsigned int real_num_tx_queues;
af356afa 1703 struct Qdisc *qdisc;
536721b1 1704 unsigned long tx_queue_len;
c3f26a26 1705 spinlock_t tx_global_lock;
14ffbbb8 1706 int watchdog_timeo;
cd13539b 1707
bf264145 1708#ifdef CONFIG_XPS
a4177869 1709 struct xps_dev_maps __rcu *xps_maps;
bf264145 1710#endif
1d24eb48 1711
0c4f691f
SF
1712#ifdef CONFIG_NET_SWITCHDEV
1713 u32 offload_fwd_mark;
1714#endif
1715
9356b8fc 1716 /* These may be needed for future network-power-down code. */
9d21493b
ED
1717
1718 /*
1719 * trans_start here is expensive for high speed devices on SMP,
1720 * please use netdev_queue->trans_start instead.
1721 */
536721b1 1722 unsigned long trans_start;
9356b8fc 1723
9356b8fc
ED
1724 struct timer_list watchdog_timer;
1725
29b4433d 1726 int __percpu *pcpu_refcnt;
1da177e4 1727 struct list_head todo_list;
1da177e4 1728
e014debe 1729 struct list_head link_watch_list;
572a103d 1730
1da177e4 1731 enum { NETREG_UNINITIALIZED=0,
b17a7c17 1732 NETREG_REGISTERED, /* completed register_netdevice */
1da177e4
LT
1733 NETREG_UNREGISTERING, /* called unregister_netdevice */
1734 NETREG_UNREGISTERED, /* completed unregister todo */
1735 NETREG_RELEASED, /* called free_netdev */
937f1ba5 1736 NETREG_DUMMY, /* dummy device for NAPI poll */
449f4544
ED
1737 } reg_state:8;
1738
536721b1 1739 bool dismantle;
a2835763
PM
1740
1741 enum {
1742 RTNL_LINK_INITIALIZED,
1743 RTNL_LINK_INITIALIZING,
1744 } rtnl_link_state:16;
1da177e4 1745
d314774c 1746 void (*destructor)(struct net_device *dev);
1da177e4 1747
1da177e4 1748#ifdef CONFIG_NETPOLL
5fbee843 1749 struct netpoll_info __rcu *npinfo;
1da177e4 1750#endif
eae792b7 1751
0c5c9fb5 1752 possible_net_t nd_net;
4a1c5371 1753
4951704b 1754 /* mid-layer private */
a7855c78 1755 union {
536721b1
KK
1756 void *ml_priv;
1757 struct pcpu_lstats __percpu *lstats;
8f84985f 1758 struct pcpu_sw_netstats __percpu *tstats;
536721b1
KK
1759 struct pcpu_dstats __percpu *dstats;
1760 struct pcpu_vstats __percpu *vstats;
a7855c78 1761 };
536721b1 1762
3cc77ec7 1763 struct garp_port __rcu *garp_port;
febf018d 1764 struct mrp_port __rcu *mrp_port;
1da177e4 1765
536721b1 1766 struct device dev;
0c509a6c 1767 const struct attribute_group *sysfs_groups[4];
a953be53 1768 const struct attribute_group *sysfs_rx_queue_group;
38f7b870 1769
38f7b870 1770 const struct rtnl_link_ops *rtnl_link_ops;
f25f4e44 1771
82cc1a7a
PWJ
1772 /* for setting kernel sock attribute on TCP connection setup */
1773#define GSO_MAX_SIZE 65536
1774 unsigned int gso_max_size;
30b678d8
BH
1775#define GSO_MAX_SEGS 65535
1776 u16 gso_max_segs;
fcbeb976 1777 u16 gso_min_segs;
7a6b6f51 1778#ifdef CONFIG_DCB
32953543 1779 const struct dcbnl_rtnl_ops *dcbnl_ops;
2f90b865 1780#endif
4f57c087
JF
1781 u8 num_tc;
1782 struct netdev_tc_txq tc_to_txq[TC_MAX_QUEUE];
1783 u8 prio_tc_map[TC_BITMASK + 1];
2f90b865 1784
d11ead75 1785#if IS_ENABLED(CONFIG_FCOE)
4d288d57 1786 unsigned int fcoe_ddp_xid;
5bc1421e 1787#endif
86f8515f 1788#if IS_ENABLED(CONFIG_CGROUP_NET_PRIO)
5bc1421e 1789 struct netprio_map __rcu *priomap;
4d288d57 1790#endif
c1f19b51 1791 struct phy_device *phydev;
23d3b8bf 1792 struct lock_class_key *qdisc_tx_busylock;
d746d707 1793 bool proto_down;
1da177e4 1794};
43cb76d9 1795#define to_net_dev(d) container_of(d, struct net_device, dev)
1da177e4
LT
1796
1797#define NETDEV_ALIGN 32
1da177e4 1798
4f57c087
JF
1799static inline
1800int netdev_get_prio_tc_map(const struct net_device *dev, u32 prio)
1801{
1802 return dev->prio_tc_map[prio & TC_BITMASK];
1803}
1804
1805static inline
1806int netdev_set_prio_tc_map(struct net_device *dev, u8 prio, u8 tc)
1807{
1808 if (tc >= dev->num_tc)
1809 return -EINVAL;
1810
1811 dev->prio_tc_map[prio & TC_BITMASK] = tc & TC_BITMASK;
1812 return 0;
1813}
1814
1815static inline
1816void netdev_reset_tc(struct net_device *dev)
1817{
1818 dev->num_tc = 0;
1819 memset(dev->tc_to_txq, 0, sizeof(dev->tc_to_txq));
1820 memset(dev->prio_tc_map, 0, sizeof(dev->prio_tc_map));
1821}
1822
1823static inline
1824int netdev_set_tc_queue(struct net_device *dev, u8 tc, u16 count, u16 offset)
1825{
1826 if (tc >= dev->num_tc)
1827 return -EINVAL;
1828
1829 dev->tc_to_txq[tc].count = count;
1830 dev->tc_to_txq[tc].offset = offset;
1831 return 0;
1832}
1833
1834static inline
1835int netdev_set_num_tc(struct net_device *dev, u8 num_tc)
1836{
1837 if (num_tc > TC_MAX_QUEUE)
1838 return -EINVAL;
1839
1840 dev->num_tc = num_tc;
1841 return 0;
1842}
1843
1844static inline
1845int netdev_get_num_tc(struct net_device *dev)
1846{
1847 return dev->num_tc;
1848}
1849
e8a0464c
DM
1850static inline
1851struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev,
1852 unsigned int index)
1853{
1854 return &dev->_tx[index];
1855}
1856
10c51b56
DB
1857static inline struct netdev_queue *skb_get_tx_queue(const struct net_device *dev,
1858 const struct sk_buff *skb)
1859{
1860 return netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
1861}
1862
e8a0464c
DM
1863static inline void netdev_for_each_tx_queue(struct net_device *dev,
1864 void (*f)(struct net_device *,
1865 struct netdev_queue *,
1866 void *),
1867 void *arg)
1868{
1869 unsigned int i;
1870
1871 for (i = 0; i < dev->num_tx_queues; i++)
1872 f(dev, &dev->_tx[i], arg);
1873}
1874
f629d208 1875struct netdev_queue *netdev_pick_tx(struct net_device *dev,
f663dd9a
JW
1876 struct sk_buff *skb,
1877 void *accel_priv);
8c4c49df 1878
c346dca1
YH
1879/*
1880 * Net namespace inlines
1881 */
1882static inline
1883struct net *dev_net(const struct net_device *dev)
1884{
c2d9ba9b 1885 return read_pnet(&dev->nd_net);
c346dca1
YH
1886}
1887
1888static inline
f5aa23fd 1889void dev_net_set(struct net_device *dev, struct net *net)
c346dca1 1890{
0c5c9fb5 1891 write_pnet(&dev->nd_net, net);
c346dca1
YH
1892}
1893
3e8a72d1 1894static inline bool netdev_uses_dsa(struct net_device *dev)
cf85d08f 1895{
3fc88677 1896#if IS_ENABLED(CONFIG_NET_DSA)
5aed85ce
FF
1897 if (dev->dsa_ptr != NULL)
1898 return dsa_uses_tagged_protocol(dev->dsa_ptr);
396138f0 1899#endif
5aed85ce 1900 return false;
396138f0
LB
1901}
1902
bea3348e
SH
1903/**
1904 * netdev_priv - access network device private data
1905 * @dev: network device
1906 *
1907 * Get network device private data
1908 */
6472ce60 1909static inline void *netdev_priv(const struct net_device *dev)
1da177e4 1910{
1ce8e7b5 1911 return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN);
1da177e4
LT
1912}
1913
1da177e4
LT
1914/* Set the sysfs physical device reference for the network logical device
1915 * if set prior to registration will cause a symlink during initialization.
1916 */
43cb76d9 1917#define SET_NETDEV_DEV(net, pdev) ((net)->dev.parent = (pdev))
1da177e4 1918
384912ed 1919/* Set the sysfs device type for the network logical device to allow
3f79410c 1920 * fine-grained identification of different network device types. For
384912ed
MH
1921 * example Ethernet, Wirelss LAN, Bluetooth, WiMAX etc.
1922 */
1923#define SET_NETDEV_DEVTYPE(net, devtype) ((net)->dev.type = (devtype))
1924
82dc3c63
ED
1925/* Default NAPI poll() weight
1926 * Device drivers are strongly advised to not use bigger value
1927 */
1928#define NAPI_POLL_WEIGHT 64
1929
3b582cc1
SH
1930/**
1931 * netif_napi_add - initialize a napi context
1932 * @dev: network device
1933 * @napi: napi context
1934 * @poll: polling function
1935 * @weight: default weight
1936 *
1937 * netif_napi_add() must be used to initialize a napi context prior to calling
1938 * *any* of the other napi related functions.
1939 */
d565b0a1
HX
1940void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
1941 int (*poll)(struct napi_struct *, int), int weight);
bea3348e 1942
d64b5e85
ED
1943/**
1944 * netif_tx_napi_add - initialize a napi context
1945 * @dev: network device
1946 * @napi: napi context
1947 * @poll: polling function
1948 * @weight: default weight
1949 *
1950 * This variant of netif_napi_add() should be used from drivers using NAPI
1951 * to exclusively poll a TX queue.
1952 * This will avoid we add it into napi_hash[], thus polluting this hash table.
1953 */
1954static inline void netif_tx_napi_add(struct net_device *dev,
1955 struct napi_struct *napi,
1956 int (*poll)(struct napi_struct *, int),
1957 int weight)
1958{
1959 set_bit(NAPI_STATE_NO_BUSY_POLL, &napi->state);
1960 netif_napi_add(dev, napi, poll, weight);
1961}
1962
d8156534
AD
1963/**
1964 * netif_napi_del - remove a napi context
1965 * @napi: napi context
1966 *
1967 * netif_napi_del() removes a napi context from the network device napi list
1968 */
d565b0a1
HX
1969void netif_napi_del(struct napi_struct *napi);
1970
1971struct napi_gro_cb {
78a478d0
HX
1972 /* Virtual address of skb_shinfo(skb)->frags[0].page + offset. */
1973 void *frag0;
1974
7489594c
HX
1975 /* Length of frag0. */
1976 unsigned int frag0_len;
1977
86911732
HX
1978 /* This indicates where we are processing relative to skb->data. */
1979 int data_offset;
1980
d565b0a1 1981 /* This is non-zero if the packet cannot be merged with the new skb. */
bf5a755f
JC
1982 u16 flush;
1983
1984 /* Save the IP ID here and check when we get to the transport layer */
1985 u16 flush_id;
d565b0a1
HX
1986
1987 /* Number of segments aggregated. */
2e71a6f8
ED
1988 u16 count;
1989
15e2396d
TH
1990 /* Start offset for remote checksum offload */
1991 u16 gro_remcsum_start;
1992
2e71a6f8
ED
1993 /* jiffies when first packet was created/queued */
1994 unsigned long age;
86347245 1995
afe93325 1996 /* Used in ipv6_gro_receive() and foo-over-udp */
b582ef09
OG
1997 u16 proto;
1998
baa32ff4
TH
1999 /* This is non-zero if the packet may be of the same flow. */
2000 u8 same_flow:1;
2001
b582ef09 2002 /* Used in udp_gro_receive */
573e8fca
TH
2003 u8 udp_mark:1;
2004
2005 /* GRO checksum is valid */
2006 u8 csum_valid:1;
2007
662880f4
TH
2008 /* Number of checksums via CHECKSUM_UNNECESSARY */
2009 u8 csum_cnt:3;
c3c7c254 2010
baa32ff4
TH
2011 /* Free the skb? */
2012 u8 free:2;
2013#define NAPI_GRO_FREE 1
2014#define NAPI_GRO_FREE_STOLEN_HEAD 2
2015
efc98d08
TH
2016 /* Used in foo-over-udp, set in udp[46]_gro_receive */
2017 u8 is_ipv6:1;
2018
baa32ff4
TH
2019 /* 7 bit hole */
2020
bf5a755f
JC
2021 /* used to support CHECKSUM_COMPLETE for tunneling protocols */
2022 __wsum csum;
2023
c3c7c254
ED
2024 /* used in skb_gro_receive() slow path */
2025 struct sk_buff *last;
d565b0a1
HX
2026};
2027
2028#define NAPI_GRO_CB(skb) ((struct napi_gro_cb *)(skb)->cb)
d8156534 2029
1da177e4 2030struct packet_type {
f2ccd8fa
DM
2031 __be16 type; /* This is really htons(ether_type). */
2032 struct net_device *dev; /* NULL is wildcarded here */
2033 int (*func) (struct sk_buff *,
2034 struct net_device *,
2035 struct packet_type *,
2036 struct net_device *);
c0de08d0
EL
2037 bool (*id_match)(struct packet_type *ptype,
2038 struct sock *sk);
1da177e4
LT
2039 void *af_packet_priv;
2040 struct list_head list;
2041};
2042
f191a1d1 2043struct offload_callbacks {
576a30eb 2044 struct sk_buff *(*gso_segment)(struct sk_buff *skb,
c8f44aff 2045 netdev_features_t features);
d565b0a1 2046 struct sk_buff **(*gro_receive)(struct sk_buff **head,
a2b12f3c 2047 struct sk_buff *skb);
299603e8 2048 int (*gro_complete)(struct sk_buff *skb, int nhoff);
f191a1d1
VY
2049};
2050
2051struct packet_offload {
2052 __be16 type; /* This is really htons(ether_type). */
bdef7de4 2053 u16 priority;
f191a1d1
VY
2054 struct offload_callbacks callbacks;
2055 struct list_head list;
1da177e4
LT
2056};
2057
a2b12f3c
TH
2058struct udp_offload;
2059
2060struct udp_offload_callbacks {
2061 struct sk_buff **(*gro_receive)(struct sk_buff **head,
2062 struct sk_buff *skb,
2063 struct udp_offload *uoff);
2064 int (*gro_complete)(struct sk_buff *skb,
2065 int nhoff,
2066 struct udp_offload *uoff);
2067};
2068
b582ef09
OG
2069struct udp_offload {
2070 __be16 port;
afe93325 2071 u8 ipproto;
a2b12f3c 2072 struct udp_offload_callbacks callbacks;
b582ef09
OG
2073};
2074
8f84985f
LR
2075/* often modified stats are per cpu, other are shared (netdev->stats) */
2076struct pcpu_sw_netstats {
2077 u64 rx_packets;
2078 u64 rx_bytes;
2079 u64 tx_packets;
2080 u64 tx_bytes;
2081 struct u64_stats_sync syncp;
2082};
2083
aabc92bb
PNA
2084#define __netdev_alloc_pcpu_stats(type, gfp) \
2085({ \
2086 typeof(type) __percpu *pcpu_stats = alloc_percpu_gfp(type, gfp);\
2087 if (pcpu_stats) { \
2088 int __cpu; \
2089 for_each_possible_cpu(__cpu) { \
2090 typeof(type) *stat; \
2091 stat = per_cpu_ptr(pcpu_stats, __cpu); \
2092 u64_stats_init(&stat->syncp); \
2093 } \
2094 } \
2095 pcpu_stats; \
1c213bd2
WC
2096})
2097
aabc92bb
PNA
2098#define netdev_alloc_pcpu_stats(type) \
2099 __netdev_alloc_pcpu_stats(type, GFP_KERNEL);
2100
1da177e4
LT
2101#include <linux/notifier.h>
2102
dcfe1421
AW
2103/* netdevice notifier chain. Please remember to update the rtnetlink
2104 * notification exclusion list in rtnetlink_event() when adding new
2105 * types.
2106 */
2107#define NETDEV_UP 0x0001 /* For now you can't veto a device up/down */
2108#define NETDEV_DOWN 0x0002
2109#define NETDEV_REBOOT 0x0003 /* Tell a protocol stack a network interface
2110 detected a hardware crash and restarted
2111 - we can use this eg to kick tcp sessions
2112 once done */
2113#define NETDEV_CHANGE 0x0004 /* Notify device state change */
2114#define NETDEV_REGISTER 0x0005
2115#define NETDEV_UNREGISTER 0x0006
1d486bfb 2116#define NETDEV_CHANGEMTU 0x0007 /* notify after mtu change happened */
dcfe1421
AW
2117#define NETDEV_CHANGEADDR 0x0008
2118#define NETDEV_GOING_DOWN 0x0009
2119#define NETDEV_CHANGENAME 0x000A
2120#define NETDEV_FEAT_CHANGE 0x000B
2121#define NETDEV_BONDING_FAILOVER 0x000C
2122#define NETDEV_PRE_UP 0x000D
2123#define NETDEV_PRE_TYPE_CHANGE 0x000E
2124#define NETDEV_POST_TYPE_CHANGE 0x000F
2125#define NETDEV_POST_INIT 0x0010
0115e8e3 2126#define NETDEV_UNREGISTER_FINAL 0x0011
dcfe1421
AW
2127#define NETDEV_RELEASE 0x0012
2128#define NETDEV_NOTIFY_PEERS 0x0013
2129#define NETDEV_JOIN 0x0014
42e52bf9 2130#define NETDEV_CHANGEUPPER 0x0015
4aa5dee4 2131#define NETDEV_RESEND_IGMP 0x0016
1d486bfb 2132#define NETDEV_PRECHANGEMTU 0x0017 /* notify before mtu change happened */
d4261e56 2133#define NETDEV_CHANGEINFODATA 0x0018
61bd3857 2134#define NETDEV_BONDING_INFO 0x0019
573c7ba0 2135#define NETDEV_PRECHANGEUPPER 0x001A
dcfe1421 2136
f629d208
JP
2137int register_netdevice_notifier(struct notifier_block *nb);
2138int unregister_netdevice_notifier(struct notifier_block *nb);
351638e7
JP
2139
2140struct netdev_notifier_info {
2141 struct net_device *dev;
2142};
2143
be9efd36
JP
2144struct netdev_notifier_change_info {
2145 struct netdev_notifier_info info; /* must be first */
2146 unsigned int flags_changed;
2147};
2148
0e4ead9d
JP
2149struct netdev_notifier_changeupper_info {
2150 struct netdev_notifier_info info; /* must be first */
2151 struct net_device *upper_dev; /* new upper dev */
2152 bool master; /* is upper dev master */
2153 bool linking; /* is the nofication for link or unlink */
2154};
2155
75538c2b
CW
2156static inline void netdev_notifier_info_init(struct netdev_notifier_info *info,
2157 struct net_device *dev)
2158{
2159 info->dev = dev;
2160}
2161
351638e7
JP
2162static inline struct net_device *
2163netdev_notifier_info_to_dev(const struct netdev_notifier_info *info)
2164{
2165 return info->dev;
2166}
2167
f629d208 2168int call_netdevice_notifiers(unsigned long val, struct net_device *dev);
dcfe1421
AW
2169
2170
1da177e4
LT
2171extern rwlock_t dev_base_lock; /* Device list lock */
2172
881d966b
EB
2173#define for_each_netdev(net, d) \
2174 list_for_each_entry(d, &(net)->dev_base_head, dev_list)
dcbccbd4
EB
2175#define for_each_netdev_reverse(net, d) \
2176 list_for_each_entry_reverse(d, &(net)->dev_base_head, dev_list)
c6d14c84
ED
2177#define for_each_netdev_rcu(net, d) \
2178 list_for_each_entry_rcu(d, &(net)->dev_base_head, dev_list)
881d966b
EB
2179#define for_each_netdev_safe(net, d, n) \
2180 list_for_each_entry_safe(d, n, &(net)->dev_base_head, dev_list)
2181#define for_each_netdev_continue(net, d) \
2182 list_for_each_entry_continue(d, &(net)->dev_base_head, dev_list)
254245d2 2183#define for_each_netdev_continue_rcu(net, d) \
2184 list_for_each_entry_continue_rcu(d, &(net)->dev_base_head, dev_list)
8a7fbfab 2185#define for_each_netdev_in_bond_rcu(bond, slave) \
2186 for_each_netdev_rcu(&init_net, slave) \
4ccce02e 2187 if (netdev_master_upper_dev_get_rcu(slave) == (bond))
881d966b 2188#define net_device_entry(lh) list_entry(lh, struct net_device, dev_list)
7562f876 2189
a050c33f
DL
2190static inline struct net_device *next_net_device(struct net_device *dev)
2191{
2192 struct list_head *lh;
2193 struct net *net;
2194
c346dca1 2195 net = dev_net(dev);
a050c33f
DL
2196 lh = dev->dev_list.next;
2197 return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
2198}
2199
ce81b76a
ED
2200static inline struct net_device *next_net_device_rcu(struct net_device *dev)
2201{
2202 struct list_head *lh;
2203 struct net *net;
2204
2205 net = dev_net(dev);
ccf43438 2206 lh = rcu_dereference(list_next_rcu(&dev->dev_list));
ce81b76a
ED
2207 return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
2208}
2209
a050c33f
DL
2210static inline struct net_device *first_net_device(struct net *net)
2211{
2212 return list_empty(&net->dev_base_head) ? NULL :
2213 net_device_entry(net->dev_base_head.next);
2214}
7562f876 2215
ccf43438
ED
2216static inline struct net_device *first_net_device_rcu(struct net *net)
2217{
2218 struct list_head *lh = rcu_dereference(list_next_rcu(&net->dev_base_head));
2219
2220 return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
2221}
2222
f629d208
JP
2223int netdev_boot_setup_check(struct net_device *dev);
2224unsigned long netdev_boot_base(const char *prefix, int unit);
2225struct net_device *dev_getbyhwaddr_rcu(struct net *net, unsigned short type,
2226 const char *hwaddr);
2227struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type);
2228struct net_device *__dev_getfirstbyhwtype(struct net *net, unsigned short type);
2229void dev_add_pack(struct packet_type *pt);
2230void dev_remove_pack(struct packet_type *pt);
2231void __dev_remove_pack(struct packet_type *pt);
2232void dev_add_offload(struct packet_offload *po);
2233void dev_remove_offload(struct packet_offload *po);
f629d208 2234
a54acb3a 2235int dev_get_iflink(const struct net_device *dev);
fc4099f1 2236int dev_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb);
6c555490
WC
2237struct net_device *__dev_get_by_flags(struct net *net, unsigned short flags,
2238 unsigned short mask);
f629d208
JP
2239struct net_device *dev_get_by_name(struct net *net, const char *name);
2240struct net_device *dev_get_by_name_rcu(struct net *net, const char *name);
2241struct net_device *__dev_get_by_name(struct net *net, const char *name);
2242int dev_alloc_name(struct net_device *dev, const char *name);
2243int dev_open(struct net_device *dev);
2244int dev_close(struct net_device *dev);
99c4a26a 2245int dev_close_many(struct list_head *head, bool unlink);
f629d208 2246void dev_disable_lro(struct net_device *dev);
0c4b51f0 2247int dev_loopback_xmit(struct net *net, struct sock *sk, struct sk_buff *newskb);
2b4aa3ce 2248int dev_queue_xmit(struct sk_buff *skb);
f663dd9a 2249int dev_queue_xmit_accel(struct sk_buff *skb, void *accel_priv);
f629d208
JP
2250int register_netdevice(struct net_device *dev);
2251void unregister_netdevice_queue(struct net_device *dev, struct list_head *head);
2252void unregister_netdevice_many(struct list_head *head);
44a0873d
ED
2253static inline void unregister_netdevice(struct net_device *dev)
2254{
2255 unregister_netdevice_queue(dev, NULL);
2256}
2257
f629d208
JP
2258int netdev_refcnt_read(const struct net_device *dev);
2259void free_netdev(struct net_device *dev);
74d332c1 2260void netdev_freemem(struct net_device *dev);
f629d208
JP
2261void synchronize_net(void);
2262int init_dummy_netdev(struct net_device *dev);
937f1ba5 2263
f60e5990 2264DECLARE_PER_CPU(int, xmit_recursion);
2265static inline int dev_recursion_level(void)
2266{
2267 return this_cpu_read(xmit_recursion);
2268}
2269
f629d208
JP
2270struct net_device *dev_get_by_index(struct net *net, int ifindex);
2271struct net_device *__dev_get_by_index(struct net *net, int ifindex);
2272struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
2273int netdev_get_name(struct net *net, char *name, int ifindex);
2274int dev_restart(struct net_device *dev);
f629d208 2275int skb_gro_receive(struct sk_buff **head, struct sk_buff *skb);
86911732
HX
2276
2277static inline unsigned int skb_gro_offset(const struct sk_buff *skb)
2278{
2279 return NAPI_GRO_CB(skb)->data_offset;
2280}
2281
2282static inline unsigned int skb_gro_len(const struct sk_buff *skb)
2283{
2284 return skb->len - NAPI_GRO_CB(skb)->data_offset;
2285}
2286
2287static inline void skb_gro_pull(struct sk_buff *skb, unsigned int len)
2288{
2289 NAPI_GRO_CB(skb)->data_offset += len;
2290}
2291
a5b1cf28
HX
2292static inline void *skb_gro_header_fast(struct sk_buff *skb,
2293 unsigned int offset)
86911732 2294{
a5b1cf28
HX
2295 return NAPI_GRO_CB(skb)->frag0 + offset;
2296}
78a478d0 2297
a5b1cf28
HX
2298static inline int skb_gro_header_hard(struct sk_buff *skb, unsigned int hlen)
2299{
2300 return NAPI_GRO_CB(skb)->frag0_len < hlen;
2301}
78a478d0 2302
a5b1cf28
HX
2303static inline void *skb_gro_header_slow(struct sk_buff *skb, unsigned int hlen,
2304 unsigned int offset)
2305{
17dd759c
HX
2306 if (!pskb_may_pull(skb, hlen))
2307 return NULL;
2308
a5b1cf28
HX
2309 NAPI_GRO_CB(skb)->frag0 = NULL;
2310 NAPI_GRO_CB(skb)->frag0_len = 0;
17dd759c 2311 return skb->data + offset;
86911732 2312}
1da177e4 2313
36e7b1b8
HX
2314static inline void *skb_gro_network_header(struct sk_buff *skb)
2315{
78d3fd0b
HX
2316 return (NAPI_GRO_CB(skb)->frag0 ?: skb->data) +
2317 skb_network_offset(skb);
36e7b1b8
HX
2318}
2319
bf5a755f
JC
2320static inline void skb_gro_postpull_rcsum(struct sk_buff *skb,
2321 const void *start, unsigned int len)
2322{
573e8fca 2323 if (NAPI_GRO_CB(skb)->csum_valid)
bf5a755f
JC
2324 NAPI_GRO_CB(skb)->csum = csum_sub(NAPI_GRO_CB(skb)->csum,
2325 csum_partial(start, len, 0));
2326}
2327
573e8fca
TH
2328/* GRO checksum functions. These are logical equivalents of the normal
2329 * checksum functions (in skbuff.h) except that they operate on the GRO
2330 * offsets and fields in sk_buff.
2331 */
2332
2333__sum16 __skb_gro_checksum_complete(struct sk_buff *skb);
2334
15e2396d
TH
2335static inline bool skb_at_gro_remcsum_start(struct sk_buff *skb)
2336{
b7fe10e5 2337 return (NAPI_GRO_CB(skb)->gro_remcsum_start == skb_gro_offset(skb));
15e2396d
TH
2338}
2339
573e8fca
TH
2340static inline bool __skb_gro_checksum_validate_needed(struct sk_buff *skb,
2341 bool zero_okay,
2342 __sum16 check)
2343{
6edec0e6
TH
2344 return ((skb->ip_summed != CHECKSUM_PARTIAL ||
2345 skb_checksum_start_offset(skb) <
2346 skb_gro_offset(skb)) &&
15e2396d 2347 !skb_at_gro_remcsum_start(skb) &&
662880f4 2348 NAPI_GRO_CB(skb)->csum_cnt == 0 &&
573e8fca
TH
2349 (!zero_okay || check));
2350}
2351
2352static inline __sum16 __skb_gro_checksum_validate_complete(struct sk_buff *skb,
2353 __wsum psum)
2354{
2355 if (NAPI_GRO_CB(skb)->csum_valid &&
2356 !csum_fold(csum_add(psum, NAPI_GRO_CB(skb)->csum)))
2357 return 0;
2358
2359 NAPI_GRO_CB(skb)->csum = psum;
2360
2361 return __skb_gro_checksum_complete(skb);
2362}
2363
573e8fca
TH
2364static inline void skb_gro_incr_csum_unnecessary(struct sk_buff *skb)
2365{
662880f4
TH
2366 if (NAPI_GRO_CB(skb)->csum_cnt > 0) {
2367 /* Consume a checksum from CHECKSUM_UNNECESSARY */
2368 NAPI_GRO_CB(skb)->csum_cnt--;
2369 } else {
2370 /* Update skb for CHECKSUM_UNNECESSARY and csum_level when we
2371 * verified a new top level checksum or an encapsulated one
2372 * during GRO. This saves work if we fallback to normal path.
2373 */
2374 __skb_incr_checksum_unnecessary(skb);
573e8fca
TH
2375 }
2376}
2377
2378#define __skb_gro_checksum_validate(skb, proto, zero_okay, check, \
2379 compute_pseudo) \
2380({ \
2381 __sum16 __ret = 0; \
2382 if (__skb_gro_checksum_validate_needed(skb, zero_okay, check)) \
2383 __ret = __skb_gro_checksum_validate_complete(skb, \
2384 compute_pseudo(skb, proto)); \
5a212329
TH
2385 if (__ret) \
2386 __skb_mark_checksum_bad(skb); \
2387 else \
573e8fca
TH
2388 skb_gro_incr_csum_unnecessary(skb); \
2389 __ret; \
2390})
2391
2392#define skb_gro_checksum_validate(skb, proto, compute_pseudo) \
2393 __skb_gro_checksum_validate(skb, proto, false, 0, compute_pseudo)
2394
2395#define skb_gro_checksum_validate_zero_check(skb, proto, check, \
2396 compute_pseudo) \
2397 __skb_gro_checksum_validate(skb, proto, true, check, compute_pseudo)
2398
2399#define skb_gro_checksum_simple_validate(skb) \
2400 __skb_gro_checksum_validate(skb, 0, false, 0, null_compute_pseudo)
2401
d96535a1
TH
2402static inline bool __skb_gro_checksum_convert_check(struct sk_buff *skb)
2403{
2404 return (NAPI_GRO_CB(skb)->csum_cnt == 0 &&
2405 !NAPI_GRO_CB(skb)->csum_valid);
2406}
2407
2408static inline void __skb_gro_checksum_convert(struct sk_buff *skb,
2409 __sum16 check, __wsum pseudo)
2410{
2411 NAPI_GRO_CB(skb)->csum = ~pseudo;
2412 NAPI_GRO_CB(skb)->csum_valid = 1;
2413}
2414
2415#define skb_gro_checksum_try_convert(skb, proto, check, compute_pseudo) \
2416do { \
2417 if (__skb_gro_checksum_convert_check(skb)) \
2418 __skb_gro_checksum_convert(skb, check, \
2419 compute_pseudo(skb, proto)); \
2420} while (0)
2421
26c4f7da
TH
2422struct gro_remcsum {
2423 int offset;
2424 __wsum delta;
2425};
2426
2427static inline void skb_gro_remcsum_init(struct gro_remcsum *grc)
2428{
846cd667 2429 grc->offset = 0;
26c4f7da
TH
2430 grc->delta = 0;
2431}
2432
b7fe10e5
TH
2433static inline void *skb_gro_remcsum_process(struct sk_buff *skb, void *ptr,
2434 unsigned int off, size_t hdrlen,
2435 int start, int offset,
2436 struct gro_remcsum *grc,
2437 bool nopartial)
dcdc8994
TH
2438{
2439 __wsum delta;
b7fe10e5 2440 size_t plen = hdrlen + max_t(size_t, offset + sizeof(u16), start);
dcdc8994
TH
2441
2442 BUG_ON(!NAPI_GRO_CB(skb)->csum_valid);
2443
15e2396d 2444 if (!nopartial) {
b7fe10e5
TH
2445 NAPI_GRO_CB(skb)->gro_remcsum_start = off + hdrlen + start;
2446 return ptr;
2447 }
2448
2449 ptr = skb_gro_header_fast(skb, off);
2450 if (skb_gro_header_hard(skb, off + plen)) {
2451 ptr = skb_gro_header_slow(skb, off + plen, off);
2452 if (!ptr)
2453 return NULL;
15e2396d
TH
2454 }
2455
b7fe10e5
TH
2456 delta = remcsum_adjust(ptr + hdrlen, NAPI_GRO_CB(skb)->csum,
2457 start, offset);
dcdc8994
TH
2458
2459 /* Adjust skb->csum since we changed the packet */
dcdc8994 2460 NAPI_GRO_CB(skb)->csum = csum_add(NAPI_GRO_CB(skb)->csum, delta);
26c4f7da 2461
b7fe10e5 2462 grc->offset = off + hdrlen + offset;
26c4f7da 2463 grc->delta = delta;
b7fe10e5
TH
2464
2465 return ptr;
dcdc8994
TH
2466}
2467
26c4f7da
TH
2468static inline void skb_gro_remcsum_cleanup(struct sk_buff *skb,
2469 struct gro_remcsum *grc)
2470{
b7fe10e5
TH
2471 void *ptr;
2472 size_t plen = grc->offset + sizeof(u16);
2473
26c4f7da
TH
2474 if (!grc->delta)
2475 return;
2476
b7fe10e5
TH
2477 ptr = skb_gro_header_fast(skb, grc->offset);
2478 if (skb_gro_header_hard(skb, grc->offset + sizeof(u16))) {
2479 ptr = skb_gro_header_slow(skb, plen, grc->offset);
2480 if (!ptr)
2481 return;
2482 }
2483
2484 remcsum_unadjust((__sum16 *)ptr, grc->delta);
26c4f7da 2485}
dcdc8994 2486
0c4e8581
SH
2487static inline int dev_hard_header(struct sk_buff *skb, struct net_device *dev,
2488 unsigned short type,
3b04ddde 2489 const void *daddr, const void *saddr,
95c96174 2490 unsigned int len)
0c4e8581 2491{
f1ecfd5d 2492 if (!dev->header_ops || !dev->header_ops->create)
0c4e8581 2493 return 0;
3b04ddde
SH
2494
2495 return dev->header_ops->create(skb, dev, type, daddr, saddr, len);
0c4e8581
SH
2496}
2497
b95cce35
SH
2498static inline int dev_parse_header(const struct sk_buff *skb,
2499 unsigned char *haddr)
2500{
2501 const struct net_device *dev = skb->dev;
2502
1b83336b 2503 if (!dev->header_ops || !dev->header_ops->parse)
b95cce35 2504 return 0;
3b04ddde 2505 return dev->header_ops->parse(skb, haddr);
b95cce35
SH
2506}
2507
1da177e4 2508typedef int gifconf_func_t(struct net_device * dev, char __user * bufptr, int len);
f629d208 2509int register_gifconf(unsigned int family, gifconf_func_t *gifconf);
1da177e4
LT
2510static inline int unregister_gifconf(unsigned int family)
2511{
2512 return register_gifconf(family, NULL);
2513}
2514
99bbc707 2515#ifdef CONFIG_NET_FLOW_LIMIT
5f121b9a 2516#define FLOW_LIMIT_HISTORY (1 << 7) /* must be ^2 and !overflow buckets */
99bbc707
WB
2517struct sd_flow_limit {
2518 u64 count;
2519 unsigned int num_buckets;
2520 unsigned int history_head;
2521 u16 history[FLOW_LIMIT_HISTORY];
2522 u8 buckets[];
2523};
2524
2525extern int netdev_flow_limit_table_len;
2526#endif /* CONFIG_NET_FLOW_LIMIT */
2527
1da177e4 2528/*
88751275 2529 * Incoming packets are placed on per-cpu queues
1da177e4 2530 */
d94d9fee 2531struct softnet_data {
1da177e4 2532 struct list_head poll_list;
6e7676c1 2533 struct sk_buff_head process_queue;
1da177e4 2534
dee42870 2535 /* stats */
cd7b5396
DM
2536 unsigned int processed;
2537 unsigned int time_squeeze;
2538 unsigned int cpu_collision;
2539 unsigned int received_rps;
fd793d89 2540#ifdef CONFIG_RPS
88751275 2541 struct softnet_data *rps_ipi_list;
4cdb1e2e
ED
2542#endif
2543#ifdef CONFIG_NET_FLOW_LIMIT
2544 struct sd_flow_limit __rcu *flow_limit;
2545#endif
2546 struct Qdisc *output_queue;
2547 struct Qdisc **output_queue_tailp;
2548 struct sk_buff *completion_queue;
88751275 2549
4cdb1e2e 2550#ifdef CONFIG_RPS
88751275 2551 /* Elements below can be accessed between CPUs for RPS */
0a9627f2 2552 struct call_single_data csd ____cacheline_aligned_in_smp;
88751275
ED
2553 struct softnet_data *rps_ipi_next;
2554 unsigned int cpu;
fec5e652 2555 unsigned int input_queue_head;
76cc8b13 2556 unsigned int input_queue_tail;
1e94d72f 2557#endif
95c96174 2558 unsigned int dropped;
0a9627f2 2559 struct sk_buff_head input_pkt_queue;
bea3348e 2560 struct napi_struct backlog;
99bbc707 2561
1da177e4
LT
2562};
2563
76cc8b13 2564static inline void input_queue_head_incr(struct softnet_data *sd)
fec5e652
TH
2565{
2566#ifdef CONFIG_RPS
76cc8b13
TH
2567 sd->input_queue_head++;
2568#endif
2569}
2570
2571static inline void input_queue_tail_incr_save(struct softnet_data *sd,
2572 unsigned int *qtail)
2573{
2574#ifdef CONFIG_RPS
2575 *qtail = ++sd->input_queue_tail;
fec5e652
TH
2576#endif
2577}
2578
0a9627f2 2579DECLARE_PER_CPU_ALIGNED(struct softnet_data, softnet_data);
1da177e4 2580
f629d208 2581void __netif_schedule(struct Qdisc *q);
46e5da40 2582void netif_schedule_queue(struct netdev_queue *txq);
86d804e1 2583
fd2ea0a7
DM
2584static inline void netif_tx_schedule_all(struct net_device *dev)
2585{
2586 unsigned int i;
2587
2588 for (i = 0; i < dev->num_tx_queues; i++)
2589 netif_schedule_queue(netdev_get_tx_queue(dev, i));
2590}
2591
d29f749e
DJ
2592static inline void netif_tx_start_queue(struct netdev_queue *dev_queue)
2593{
73466498 2594 clear_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
d29f749e
DJ
2595}
2596
bea3348e
SH
2597/**
2598 * netif_start_queue - allow transmit
2599 * @dev: network device
2600 *
2601 * Allow upper layers to call the device hard_start_xmit routine.
2602 */
1da177e4
LT
2603static inline void netif_start_queue(struct net_device *dev)
2604{
e8a0464c 2605 netif_tx_start_queue(netdev_get_tx_queue(dev, 0));
1da177e4
LT
2606}
2607
fd2ea0a7
DM
2608static inline void netif_tx_start_all_queues(struct net_device *dev)
2609{
2610 unsigned int i;
2611
2612 for (i = 0; i < dev->num_tx_queues; i++) {
2613 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
2614 netif_tx_start_queue(txq);
2615 }
2616}
2617
46e5da40 2618void netif_tx_wake_queue(struct netdev_queue *dev_queue);
79d16385 2619
d29f749e
DJ
2620/**
2621 * netif_wake_queue - restart transmit
2622 * @dev: network device
2623 *
2624 * Allow upper layers to call the device hard_start_xmit routine.
2625 * Used for flow control when transmit resources are available.
2626 */
79d16385
DM
2627static inline void netif_wake_queue(struct net_device *dev)
2628{
e8a0464c 2629 netif_tx_wake_queue(netdev_get_tx_queue(dev, 0));
1da177e4
LT
2630}
2631
fd2ea0a7
DM
2632static inline void netif_tx_wake_all_queues(struct net_device *dev)
2633{
2634 unsigned int i;
2635
2636 for (i = 0; i < dev->num_tx_queues; i++) {
2637 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
2638 netif_tx_wake_queue(txq);
2639 }
2640}
2641
d29f749e
DJ
2642static inline void netif_tx_stop_queue(struct netdev_queue *dev_queue)
2643{
73466498 2644 set_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
d29f749e
DJ
2645}
2646
bea3348e
SH
2647/**
2648 * netif_stop_queue - stop transmitted packets
2649 * @dev: network device
2650 *
2651 * Stop upper layers calling the device hard_start_xmit routine.
2652 * Used for flow control when transmit resources are unavailable.
2653 */
1da177e4
LT
2654static inline void netif_stop_queue(struct net_device *dev)
2655{
e8a0464c 2656 netif_tx_stop_queue(netdev_get_tx_queue(dev, 0));
1da177e4
LT
2657}
2658
a2029240 2659void netif_tx_stop_all_queues(struct net_device *dev);
fd2ea0a7 2660
4d29515f 2661static inline bool netif_tx_queue_stopped(const struct netdev_queue *dev_queue)
d29f749e 2662{
73466498 2663 return test_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
d29f749e
DJ
2664}
2665
bea3348e
SH
2666/**
2667 * netif_queue_stopped - test if transmit queue is flowblocked
2668 * @dev: network device
2669 *
2670 * Test if transmit queue on device is currently unable to send.
2671 */
4d29515f 2672static inline bool netif_queue_stopped(const struct net_device *dev)
1da177e4 2673{
e8a0464c 2674 return netif_tx_queue_stopped(netdev_get_tx_queue(dev, 0));
1da177e4
LT
2675}
2676
4d29515f 2677static inline bool netif_xmit_stopped(const struct netdev_queue *dev_queue)
c3f26a26 2678{
73466498
TH
2679 return dev_queue->state & QUEUE_STATE_ANY_XOFF;
2680}
2681
8e2f1a63
DB
2682static inline bool
2683netif_xmit_frozen_or_stopped(const struct netdev_queue *dev_queue)
73466498
TH
2684{
2685 return dev_queue->state & QUEUE_STATE_ANY_XOFF_OR_FROZEN;
2686}
2687
8e2f1a63
DB
2688static inline bool
2689netif_xmit_frozen_or_drv_stopped(const struct netdev_queue *dev_queue)
2690{
2691 return dev_queue->state & QUEUE_STATE_DRV_XOFF_OR_FROZEN;
2692}
2693
53511453
ED
2694/**
2695 * netdev_txq_bql_enqueue_prefetchw - prefetch bql data for write
2696 * @dev_queue: pointer to transmit queue
2697 *
2698 * BQL enabled drivers might use this helper in their ndo_start_xmit(),
2699 * to give appropriate hint to the cpu.
2700 */
2701static inline void netdev_txq_bql_enqueue_prefetchw(struct netdev_queue *dev_queue)
2702{
2703#ifdef CONFIG_BQL
2704 prefetchw(&dev_queue->dql.num_queued);
2705#endif
2706}
2707
2708/**
2709 * netdev_txq_bql_complete_prefetchw - prefetch bql data for write
2710 * @dev_queue: pointer to transmit queue
2711 *
2712 * BQL enabled drivers might use this helper in their TX completion path,
2713 * to give appropriate hint to the cpu.
2714 */
2715static inline void netdev_txq_bql_complete_prefetchw(struct netdev_queue *dev_queue)
2716{
2717#ifdef CONFIG_BQL
2718 prefetchw(&dev_queue->dql.limit);
2719#endif
2720}
2721
c5d67bd7
TH
2722static inline void netdev_tx_sent_queue(struct netdev_queue *dev_queue,
2723 unsigned int bytes)
2724{
114cf580
TH
2725#ifdef CONFIG_BQL
2726 dql_queued(&dev_queue->dql, bytes);
b37c0fbe
AD
2727
2728 if (likely(dql_avail(&dev_queue->dql) >= 0))
2729 return;
2730
2731 set_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state);
2732
2733 /*
2734 * The XOFF flag must be set before checking the dql_avail below,
2735 * because in netdev_tx_completed_queue we update the dql_completed
2736 * before checking the XOFF flag.
2737 */
2738 smp_mb();
2739
2740 /* check again in case another CPU has just made room avail */
2741 if (unlikely(dql_avail(&dev_queue->dql) >= 0))
2742 clear_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state);
114cf580 2743#endif
c5d67bd7
TH
2744}
2745
0042d0c8
FF
2746/**
2747 * netdev_sent_queue - report the number of bytes queued to hardware
2748 * @dev: network device
2749 * @bytes: number of bytes queued to the hardware device queue
2750 *
2751 * Report the number of bytes queued for sending/completion to the network
2752 * device hardware queue. @bytes should be a good approximation and should
2753 * exactly match netdev_completed_queue() @bytes
2754 */
c5d67bd7
TH
2755static inline void netdev_sent_queue(struct net_device *dev, unsigned int bytes)
2756{
2757 netdev_tx_sent_queue(netdev_get_tx_queue(dev, 0), bytes);
2758}
2759
2760static inline void netdev_tx_completed_queue(struct netdev_queue *dev_queue,
95c96174 2761 unsigned int pkts, unsigned int bytes)
c5d67bd7 2762{
114cf580 2763#ifdef CONFIG_BQL
b37c0fbe
AD
2764 if (unlikely(!bytes))
2765 return;
2766
2767 dql_completed(&dev_queue->dql, bytes);
2768
2769 /*
2770 * Without the memory barrier there is a small possiblity that
2771 * netdev_tx_sent_queue will miss the update and cause the queue to
2772 * be stopped forever
2773 */
2774 smp_mb();
2775
2776 if (dql_avail(&dev_queue->dql) < 0)
2777 return;
2778
2779 if (test_and_clear_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state))
2780 netif_schedule_queue(dev_queue);
114cf580 2781#endif
c5d67bd7
TH
2782}
2783
0042d0c8
FF
2784/**
2785 * netdev_completed_queue - report bytes and packets completed by device
2786 * @dev: network device
2787 * @pkts: actual number of packets sent over the medium
2788 * @bytes: actual number of bytes sent over the medium
2789 *
2790 * Report the number of bytes and packets transmitted by the network device
2791 * hardware queue over the physical medium, @bytes must exactly match the
2792 * @bytes amount passed to netdev_sent_queue()
2793 */
c5d67bd7 2794static inline void netdev_completed_queue(struct net_device *dev,
95c96174 2795 unsigned int pkts, unsigned int bytes)
c5d67bd7
TH
2796{
2797 netdev_tx_completed_queue(netdev_get_tx_queue(dev, 0), pkts, bytes);
2798}
2799
2800static inline void netdev_tx_reset_queue(struct netdev_queue *q)
2801{
114cf580 2802#ifdef CONFIG_BQL
5c490354 2803 clear_bit(__QUEUE_STATE_STACK_XOFF, &q->state);
114cf580
TH
2804 dql_reset(&q->dql);
2805#endif
c5d67bd7
TH
2806}
2807
0042d0c8
FF
2808/**
2809 * netdev_reset_queue - reset the packets and bytes count of a network device
2810 * @dev_queue: network device
2811 *
2812 * Reset the bytes and packet count of a network device and clear the
2813 * software flow control OFF bit for this network device
2814 */
c5d67bd7
TH
2815static inline void netdev_reset_queue(struct net_device *dev_queue)
2816{
2817 netdev_tx_reset_queue(netdev_get_tx_queue(dev_queue, 0));
c3f26a26
DM
2818}
2819
b9507bda
DB
2820/**
2821 * netdev_cap_txqueue - check if selected tx queue exceeds device queues
2822 * @dev: network device
2823 * @queue_index: given tx queue index
2824 *
2825 * Returns 0 if given tx queue index >= number of device tx queues,
2826 * otherwise returns the originally passed tx queue index.
2827 */
2828static inline u16 netdev_cap_txqueue(struct net_device *dev, u16 queue_index)
2829{
2830 if (unlikely(queue_index >= dev->real_num_tx_queues)) {
2831 net_warn_ratelimited("%s selects TX queue %d, but real number of TX queues is %d\n",
2832 dev->name, queue_index,
2833 dev->real_num_tx_queues);
2834 return 0;
2835 }
2836
2837 return queue_index;
2838}
2839
bea3348e
SH
2840/**
2841 * netif_running - test if up
2842 * @dev: network device
2843 *
2844 * Test if the device has been brought up.
2845 */
4d29515f 2846static inline bool netif_running(const struct net_device *dev)
1da177e4
LT
2847{
2848 return test_bit(__LINK_STATE_START, &dev->state);
2849}
2850
f25f4e44
PWJ
2851/*
2852 * Routines to manage the subqueues on a device. We only need start
2853 * stop, and a check if it's stopped. All other device management is
2854 * done at the overall netdevice level.
2855 * Also test the device if we're multiqueue.
2856 */
bea3348e
SH
2857
2858/**
2859 * netif_start_subqueue - allow sending packets on subqueue
2860 * @dev: network device
2861 * @queue_index: sub queue index
2862 *
2863 * Start individual transmit queue of a device with multiple transmit queues.
2864 */
f25f4e44
PWJ
2865static inline void netif_start_subqueue(struct net_device *dev, u16 queue_index)
2866{
fd2ea0a7 2867 struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
7b3d3e4f
KK
2868
2869 netif_tx_start_queue(txq);
f25f4e44
PWJ
2870}
2871
bea3348e
SH
2872/**
2873 * netif_stop_subqueue - stop sending packets on subqueue
2874 * @dev: network device
2875 * @queue_index: sub queue index
2876 *
2877 * Stop individual transmit queue of a device with multiple transmit queues.
2878 */
f25f4e44
PWJ
2879static inline void netif_stop_subqueue(struct net_device *dev, u16 queue_index)
2880{
fd2ea0a7 2881 struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
7b3d3e4f 2882 netif_tx_stop_queue(txq);
f25f4e44
PWJ
2883}
2884
bea3348e
SH
2885/**
2886 * netif_subqueue_stopped - test status of subqueue
2887 * @dev: network device
2888 * @queue_index: sub queue index
2889 *
2890 * Check individual transmit queue of a device with multiple transmit queues.
2891 */
4d29515f
DM
2892static inline bool __netif_subqueue_stopped(const struct net_device *dev,
2893 u16 queue_index)
f25f4e44 2894{
fd2ea0a7 2895 struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
7b3d3e4f
KK
2896
2897 return netif_tx_queue_stopped(txq);
f25f4e44
PWJ
2898}
2899
4d29515f
DM
2900static inline bool netif_subqueue_stopped(const struct net_device *dev,
2901 struct sk_buff *skb)
668f895a
PE
2902{
2903 return __netif_subqueue_stopped(dev, skb_get_queue_mapping(skb));
2904}
bea3348e 2905
46e5da40 2906void netif_wake_subqueue(struct net_device *dev, u16 queue_index);
f25f4e44 2907
537c00de 2908#ifdef CONFIG_XPS
53af53ae 2909int netif_set_xps_queue(struct net_device *dev, const struct cpumask *mask,
f629d208 2910 u16 index);
537c00de
AD
2911#else
2912static inline int netif_set_xps_queue(struct net_device *dev,
3573540c 2913 const struct cpumask *mask,
537c00de
AD
2914 u16 index)
2915{
2916 return 0;
2917}
2918#endif
2919
5605c762
JP
2920u16 __skb_tx_hash(const struct net_device *dev, struct sk_buff *skb,
2921 unsigned int num_tx_queues);
2922
a3d22a68
VZ
2923/*
2924 * Returns a Tx hash for the given packet when dev->real_num_tx_queues is used
2925 * as a distribution range limit for the returned value.
2926 */
2927static inline u16 skb_tx_hash(const struct net_device *dev,
0e001614 2928 struct sk_buff *skb)
a3d22a68
VZ
2929{
2930 return __skb_tx_hash(dev, skb, dev->real_num_tx_queues);
2931}
2932
bea3348e
SH
2933/**
2934 * netif_is_multiqueue - test if device has multiple transmit queues
2935 * @dev: network device
2936 *
2937 * Check if device has multiple transmit queues
bea3348e 2938 */
4d29515f 2939static inline bool netif_is_multiqueue(const struct net_device *dev)
f25f4e44 2940{
a02cec21 2941 return dev->num_tx_queues > 1;
f25f4e44 2942}
1da177e4 2943
f629d208 2944int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq);
f0796d5c 2945
a953be53 2946#ifdef CONFIG_SYSFS
f629d208 2947int netif_set_real_num_rx_queues(struct net_device *dev, unsigned int rxq);
62fe0b40
BH
2948#else
2949static inline int netif_set_real_num_rx_queues(struct net_device *dev,
2950 unsigned int rxq)
2951{
2952 return 0;
2953}
2954#endif
2955
a953be53
MD
2956#ifdef CONFIG_SYSFS
2957static inline unsigned int get_netdev_rx_queue_index(
2958 struct netdev_rx_queue *queue)
2959{
2960 struct net_device *dev = queue->dev;
2961 int index = queue - dev->_rx;
2962
2963 BUG_ON(index >= dev->num_rx_queues);
2964 return index;
2965}
2966#endif
2967
16917b87 2968#define DEFAULT_MAX_NUM_RSS_QUEUES (8)
f629d208 2969int netif_get_num_default_rss_queues(void);
16917b87 2970
e6247027
ED
2971enum skb_free_reason {
2972 SKB_REASON_CONSUMED,
2973 SKB_REASON_DROPPED,
2974};
2975
2976void __dev_kfree_skb_irq(struct sk_buff *skb, enum skb_free_reason reason);
2977void __dev_kfree_skb_any(struct sk_buff *skb, enum skb_free_reason reason);
1da177e4 2978
e6247027
ED
2979/*
2980 * It is not allowed to call kfree_skb() or consume_skb() from hardware
2981 * interrupt context or with hardware interrupts being disabled.
2982 * (in_irq() || irqs_disabled())
2983 *
2984 * We provide four helpers that can be used in following contexts :
2985 *
2986 * dev_kfree_skb_irq(skb) when caller drops a packet from irq context,
2987 * replacing kfree_skb(skb)
2988 *
2989 * dev_consume_skb_irq(skb) when caller consumes a packet from irq context.
2990 * Typically used in place of consume_skb(skb) in TX completion path
2991 *
2992 * dev_kfree_skb_any(skb) when caller doesn't know its current irq context,
2993 * replacing kfree_skb(skb)
2994 *
2995 * dev_consume_skb_any(skb) when caller doesn't know its current irq context,
2996 * and consumed a packet. Used in place of consume_skb(skb)
1da177e4 2997 */
e6247027
ED
2998static inline void dev_kfree_skb_irq(struct sk_buff *skb)
2999{
3000 __dev_kfree_skb_irq(skb, SKB_REASON_DROPPED);
3001}
3002
3003static inline void dev_consume_skb_irq(struct sk_buff *skb)
3004{
3005 __dev_kfree_skb_irq(skb, SKB_REASON_CONSUMED);
3006}
3007
3008static inline void dev_kfree_skb_any(struct sk_buff *skb)
3009{
3010 __dev_kfree_skb_any(skb, SKB_REASON_DROPPED);
3011}
3012
3013static inline void dev_consume_skb_any(struct sk_buff *skb)
3014{
3015 __dev_kfree_skb_any(skb, SKB_REASON_CONSUMED);
3016}
1da177e4 3017
f629d208
JP
3018int netif_rx(struct sk_buff *skb);
3019int netif_rx_ni(struct sk_buff *skb);
04eb4489 3020int netif_receive_skb(struct sk_buff *skb);
f629d208
JP
3021gro_result_t napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb);
3022void napi_gro_flush(struct napi_struct *napi, bool flush_old);
3023struct sk_buff *napi_get_frags(struct napi_struct *napi);
3024gro_result_t napi_gro_frags(struct napi_struct *napi);
bf5a755f
JC
3025struct packet_offload *gro_find_receive_by_type(__be16 type);
3026struct packet_offload *gro_find_complete_by_type(__be16 type);
76620aaf
HX
3027
3028static inline void napi_free_frags(struct napi_struct *napi)
3029{
3030 kfree_skb(napi->skb);
3031 napi->skb = NULL;
3032}
3033
f629d208
JP
3034int netdev_rx_handler_register(struct net_device *dev,
3035 rx_handler_func_t *rx_handler,
3036 void *rx_handler_data);
3037void netdev_rx_handler_unregister(struct net_device *dev);
3038
3039bool dev_valid_name(const char *name);
3040int dev_ioctl(struct net *net, unsigned int cmd, void __user *);
3041int dev_ethtool(struct net *net, struct ifreq *);
3042unsigned int dev_get_flags(const struct net_device *);
3043int __dev_change_flags(struct net_device *, unsigned int flags);
3044int dev_change_flags(struct net_device *, unsigned int);
cb178190
DM
3045void __dev_notify_flags(struct net_device *, unsigned int old_flags,
3046 unsigned int gchanges);
f629d208
JP
3047int dev_change_name(struct net_device *, const char *);
3048int dev_set_alias(struct net_device *, const char *, size_t);
3049int dev_change_net_namespace(struct net_device *, struct net *, const char *);
3050int dev_set_mtu(struct net_device *, int);
3051void dev_set_group(struct net_device *, int);
3052int dev_set_mac_address(struct net_device *, struct sockaddr *);
3053int dev_change_carrier(struct net_device *, bool new_carrier);
3054int dev_get_phys_port_id(struct net_device *dev,
02637fce 3055 struct netdev_phys_item_id *ppid);
db24a904
DA
3056int dev_get_phys_port_name(struct net_device *dev,
3057 char *name, size_t len);
d746d707 3058int dev_change_proto_down(struct net_device *dev, bool proto_down);
55a93b3e 3059struct sk_buff *validate_xmit_skb_list(struct sk_buff *skb, struct net_device *dev);
ce93718f
DM
3060struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
3061 struct netdev_queue *txq, int *ret);
a0265d28 3062int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
f629d208 3063int dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
1ee481fb 3064bool is_skb_forwardable(struct net_device *dev, struct sk_buff *skb);
1da177e4 3065
20380731 3066extern int netdev_budget;
1da177e4
LT
3067
3068/* Called by rtnetlink.c:rtnl_unlock() */
f629d208 3069void netdev_run_todo(void);
1da177e4 3070
bea3348e
SH
3071/**
3072 * dev_put - release reference to device
3073 * @dev: network device
3074 *
9ef4429b 3075 * Release reference to device to allow it to be freed.
bea3348e 3076 */
1da177e4
LT
3077static inline void dev_put(struct net_device *dev)
3078{
933393f5 3079 this_cpu_dec(*dev->pcpu_refcnt);
1da177e4
LT
3080}
3081
bea3348e
SH
3082/**
3083 * dev_hold - get reference to device
3084 * @dev: network device
3085 *
9ef4429b 3086 * Hold reference to device to keep it from being freed.
bea3348e 3087 */
15333061
SH
3088static inline void dev_hold(struct net_device *dev)
3089{
933393f5 3090 this_cpu_inc(*dev->pcpu_refcnt);
15333061 3091}
1da177e4
LT
3092
3093/* Carrier loss detection, dial on demand. The functions netif_carrier_on
3094 * and _off may be called from IRQ context, but it is caller
3095 * who is responsible for serialization of these calls.
b00055aa
SR
3096 *
3097 * The name carrier is inappropriate, these functions should really be
3098 * called netif_lowerlayer_*() because they represent the state of any
3099 * kind of lower layer not just hardware media.
1da177e4
LT
3100 */
3101
f629d208
JP
3102void linkwatch_init_dev(struct net_device *dev);
3103void linkwatch_fire_event(struct net_device *dev);
3104void linkwatch_forget_dev(struct net_device *dev);
1da177e4 3105
bea3348e
SH
3106/**
3107 * netif_carrier_ok - test if carrier present
3108 * @dev: network device
3109 *
3110 * Check if carrier is present on device
3111 */
4d29515f 3112static inline bool netif_carrier_ok(const struct net_device *dev)
1da177e4
LT
3113{
3114 return !test_bit(__LINK_STATE_NOCARRIER, &dev->state);
3115}
3116
f629d208 3117unsigned long dev_trans_start(struct net_device *dev);
9d21493b 3118
f629d208 3119void __netdev_watchdog_up(struct net_device *dev);
1da177e4 3120
f629d208 3121void netif_carrier_on(struct net_device *dev);
1da177e4 3122
f629d208 3123void netif_carrier_off(struct net_device *dev);
1da177e4 3124
bea3348e
SH
3125/**
3126 * netif_dormant_on - mark device as dormant.
3127 * @dev: network device
3128 *
3129 * Mark device as dormant (as per RFC2863).
3130 *
3131 * The dormant state indicates that the relevant interface is not
3132 * actually in a condition to pass packets (i.e., it is not 'up') but is
3133 * in a "pending" state, waiting for some external event. For "on-
3134 * demand" interfaces, this new state identifies the situation where the
3135 * interface is waiting for events to place it in the up state.
3136 *
3137 */
b00055aa
SR
3138static inline void netif_dormant_on(struct net_device *dev)
3139{
3140 if (!test_and_set_bit(__LINK_STATE_DORMANT, &dev->state))
3141 linkwatch_fire_event(dev);
3142}
3143
bea3348e
SH
3144/**
3145 * netif_dormant_off - set device as not dormant.
3146 * @dev: network device
3147 *
3148 * Device is not in dormant state.
3149 */
b00055aa
SR
3150static inline void netif_dormant_off(struct net_device *dev)
3151{
3152 if (test_and_clear_bit(__LINK_STATE_DORMANT, &dev->state))
3153 linkwatch_fire_event(dev);
3154}
3155
bea3348e
SH
3156/**
3157 * netif_dormant - test if carrier present
3158 * @dev: network device
3159 *
3160 * Check if carrier is present on device
3161 */
4d29515f 3162static inline bool netif_dormant(const struct net_device *dev)
b00055aa
SR
3163{
3164 return test_bit(__LINK_STATE_DORMANT, &dev->state);
3165}
3166
3167
bea3348e
SH
3168/**
3169 * netif_oper_up - test if device is operational
3170 * @dev: network device
3171 *
3172 * Check if carrier is operational
3173 */
4d29515f 3174static inline bool netif_oper_up(const struct net_device *dev)
d94d9fee 3175{
b00055aa
SR
3176 return (dev->operstate == IF_OPER_UP ||
3177 dev->operstate == IF_OPER_UNKNOWN /* backward compat */);
3178}
3179
bea3348e
SH
3180/**
3181 * netif_device_present - is device available or removed
3182 * @dev: network device
3183 *
3184 * Check if device has not been removed from system.
3185 */
4d29515f 3186static inline bool netif_device_present(struct net_device *dev)
1da177e4
LT
3187{
3188 return test_bit(__LINK_STATE_PRESENT, &dev->state);
3189}
3190
f629d208 3191void netif_device_detach(struct net_device *dev);
1da177e4 3192
f629d208 3193void netif_device_attach(struct net_device *dev);
1da177e4
LT
3194
3195/*
3196 * Network interface message level settings
3197 */
1da177e4
LT
3198
3199enum {
3200 NETIF_MSG_DRV = 0x0001,
3201 NETIF_MSG_PROBE = 0x0002,
3202 NETIF_MSG_LINK = 0x0004,
3203 NETIF_MSG_TIMER = 0x0008,
3204 NETIF_MSG_IFDOWN = 0x0010,
3205 NETIF_MSG_IFUP = 0x0020,
3206 NETIF_MSG_RX_ERR = 0x0040,
3207 NETIF_MSG_TX_ERR = 0x0080,
3208 NETIF_MSG_TX_QUEUED = 0x0100,
3209 NETIF_MSG_INTR = 0x0200,
3210 NETIF_MSG_TX_DONE = 0x0400,
3211 NETIF_MSG_RX_STATUS = 0x0800,
3212 NETIF_MSG_PKTDATA = 0x1000,
3213 NETIF_MSG_HW = 0x2000,
3214 NETIF_MSG_WOL = 0x4000,
3215};
3216
3217#define netif_msg_drv(p) ((p)->msg_enable & NETIF_MSG_DRV)
3218#define netif_msg_probe(p) ((p)->msg_enable & NETIF_MSG_PROBE)
3219#define netif_msg_link(p) ((p)->msg_enable & NETIF_MSG_LINK)
3220#define netif_msg_timer(p) ((p)->msg_enable & NETIF_MSG_TIMER)
3221#define netif_msg_ifdown(p) ((p)->msg_enable & NETIF_MSG_IFDOWN)
3222#define netif_msg_ifup(p) ((p)->msg_enable & NETIF_MSG_IFUP)
3223#define netif_msg_rx_err(p) ((p)->msg_enable & NETIF_MSG_RX_ERR)
3224#define netif_msg_tx_err(p) ((p)->msg_enable & NETIF_MSG_TX_ERR)
3225#define netif_msg_tx_queued(p) ((p)->msg_enable & NETIF_MSG_TX_QUEUED)
3226#define netif_msg_intr(p) ((p)->msg_enable & NETIF_MSG_INTR)
3227#define netif_msg_tx_done(p) ((p)->msg_enable & NETIF_MSG_TX_DONE)
3228#define netif_msg_rx_status(p) ((p)->msg_enable & NETIF_MSG_RX_STATUS)
3229#define netif_msg_pktdata(p) ((p)->msg_enable & NETIF_MSG_PKTDATA)
3230#define netif_msg_hw(p) ((p)->msg_enable & NETIF_MSG_HW)
3231#define netif_msg_wol(p) ((p)->msg_enable & NETIF_MSG_WOL)
3232
3233static inline u32 netif_msg_init(int debug_value, int default_msg_enable_bits)
3234{
3235 /* use default */
3236 if (debug_value < 0 || debug_value >= (sizeof(u32) * 8))
3237 return default_msg_enable_bits;
3238 if (debug_value == 0) /* no output */
3239 return 0;
3240 /* set low N bits */
3241 return (1 << debug_value) - 1;
3242}
3243
c773e847 3244static inline void __netif_tx_lock(struct netdev_queue *txq, int cpu)
932ff279 3245{
c773e847
DM
3246 spin_lock(&txq->_xmit_lock);
3247 txq->xmit_lock_owner = cpu;
22dd7495
JHS
3248}
3249
fd2ea0a7
DM
3250static inline void __netif_tx_lock_bh(struct netdev_queue *txq)
3251{
3252 spin_lock_bh(&txq->_xmit_lock);
3253 txq->xmit_lock_owner = smp_processor_id();
3254}
3255
4d29515f 3256static inline bool __netif_tx_trylock(struct netdev_queue *txq)
c3f26a26 3257{
4d29515f 3258 bool ok = spin_trylock(&txq->_xmit_lock);
c3f26a26
DM
3259 if (likely(ok))
3260 txq->xmit_lock_owner = smp_processor_id();
3261 return ok;
3262}
3263
3264static inline void __netif_tx_unlock(struct netdev_queue *txq)
3265{
3266 txq->xmit_lock_owner = -1;
3267 spin_unlock(&txq->_xmit_lock);
3268}
3269
3270static inline void __netif_tx_unlock_bh(struct netdev_queue *txq)
3271{
3272 txq->xmit_lock_owner = -1;
3273 spin_unlock_bh(&txq->_xmit_lock);
3274}
3275
08baf561
ED
3276static inline void txq_trans_update(struct netdev_queue *txq)
3277{
3278 if (txq->xmit_lock_owner != -1)
3279 txq->trans_start = jiffies;
3280}
3281
d29f749e
DJ
3282/**
3283 * netif_tx_lock - grab network device transmit lock
3284 * @dev: network device
d29f749e
DJ
3285 *
3286 * Get network device transmit lock
3287 */
22dd7495
JHS
3288static inline void netif_tx_lock(struct net_device *dev)
3289{
e8a0464c 3290 unsigned int i;
c3f26a26 3291 int cpu;
c773e847 3292
c3f26a26
DM
3293 spin_lock(&dev->tx_global_lock);
3294 cpu = smp_processor_id();
e8a0464c
DM
3295 for (i = 0; i < dev->num_tx_queues; i++) {
3296 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
c3f26a26
DM
3297
3298 /* We are the only thread of execution doing a
3299 * freeze, but we have to grab the _xmit_lock in
3300 * order to synchronize with threads which are in
3301 * the ->hard_start_xmit() handler and already
3302 * checked the frozen bit.
3303 */
e8a0464c 3304 __netif_tx_lock(txq, cpu);
c3f26a26
DM
3305 set_bit(__QUEUE_STATE_FROZEN, &txq->state);
3306 __netif_tx_unlock(txq);
e8a0464c 3307 }
932ff279
HX
3308}
3309
3310static inline void netif_tx_lock_bh(struct net_device *dev)
3311{
e8a0464c
DM
3312 local_bh_disable();
3313 netif_tx_lock(dev);
932ff279
HX
3314}
3315
932ff279
HX
3316static inline void netif_tx_unlock(struct net_device *dev)
3317{
e8a0464c
DM
3318 unsigned int i;
3319
3320 for (i = 0; i < dev->num_tx_queues; i++) {
3321 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
c773e847 3322
c3f26a26
DM
3323 /* No need to grab the _xmit_lock here. If the
3324 * queue is not stopped for another reason, we
3325 * force a schedule.
3326 */
3327 clear_bit(__QUEUE_STATE_FROZEN, &txq->state);
7b3d3e4f 3328 netif_schedule_queue(txq);
c3f26a26
DM
3329 }
3330 spin_unlock(&dev->tx_global_lock);
932ff279
HX
3331}
3332
3333static inline void netif_tx_unlock_bh(struct net_device *dev)
3334{
e8a0464c
DM
3335 netif_tx_unlock(dev);
3336 local_bh_enable();
932ff279
HX
3337}
3338
c773e847 3339#define HARD_TX_LOCK(dev, txq, cpu) { \
22dd7495 3340 if ((dev->features & NETIF_F_LLTX) == 0) { \
c773e847 3341 __netif_tx_lock(txq, cpu); \
22dd7495
JHS
3342 } \
3343}
3344
5efeac44
EB
3345#define HARD_TX_TRYLOCK(dev, txq) \
3346 (((dev->features & NETIF_F_LLTX) == 0) ? \
3347 __netif_tx_trylock(txq) : \
3348 true )
3349
c773e847 3350#define HARD_TX_UNLOCK(dev, txq) { \
22dd7495 3351 if ((dev->features & NETIF_F_LLTX) == 0) { \
c773e847 3352 __netif_tx_unlock(txq); \
22dd7495
JHS
3353 } \
3354}
3355
1da177e4
LT
3356static inline void netif_tx_disable(struct net_device *dev)
3357{
fd2ea0a7 3358 unsigned int i;
c3f26a26 3359 int cpu;
fd2ea0a7 3360
c3f26a26
DM
3361 local_bh_disable();
3362 cpu = smp_processor_id();
fd2ea0a7
DM
3363 for (i = 0; i < dev->num_tx_queues; i++) {
3364 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
c3f26a26
DM
3365
3366 __netif_tx_lock(txq, cpu);
fd2ea0a7 3367 netif_tx_stop_queue(txq);
c3f26a26 3368 __netif_tx_unlock(txq);
fd2ea0a7 3369 }
c3f26a26 3370 local_bh_enable();
1da177e4
LT
3371}
3372
e308a5d8
DM
3373static inline void netif_addr_lock(struct net_device *dev)
3374{
3375 spin_lock(&dev->addr_list_lock);
3376}
3377
2429f7ac
JP
3378static inline void netif_addr_lock_nested(struct net_device *dev)
3379{
25175ba5
VY
3380 int subclass = SINGLE_DEPTH_NESTING;
3381
3382 if (dev->netdev_ops->ndo_get_lock_subclass)
3383 subclass = dev->netdev_ops->ndo_get_lock_subclass(dev);
3384
3385 spin_lock_nested(&dev->addr_list_lock, subclass);
2429f7ac
JP
3386}
3387
e308a5d8
DM
3388static inline void netif_addr_lock_bh(struct net_device *dev)
3389{
3390 spin_lock_bh(&dev->addr_list_lock);
3391}
3392
3393static inline void netif_addr_unlock(struct net_device *dev)
3394{
3395 spin_unlock(&dev->addr_list_lock);
3396}
3397
3398static inline void netif_addr_unlock_bh(struct net_device *dev)
3399{
3400 spin_unlock_bh(&dev->addr_list_lock);
3401}
3402
f001fde5 3403/*
31278e71 3404 * dev_addrs walker. Should be used only for read access. Call with
f001fde5
JP
3405 * rcu_read_lock held.
3406 */
3407#define for_each_dev_addr(dev, ha) \
31278e71 3408 list_for_each_entry_rcu(ha, &dev->dev_addrs.list, list)
f001fde5 3409
1da177e4
LT
3410/* These functions live elsewhere (drivers/net/net_init.c, but related) */
3411
f629d208 3412void ether_setup(struct net_device *dev);
1da177e4
LT
3413
3414/* Support for loadable net-drivers */
f629d208 3415struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
c835a677 3416 unsigned char name_assign_type,
f629d208
JP
3417 void (*setup)(struct net_device *),
3418 unsigned int txqs, unsigned int rxqs);
c835a677
TG
3419#define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \
3420 alloc_netdev_mqs(sizeof_priv, name, name_assign_type, setup, 1, 1)
36909ea4 3421
c835a677
TG
3422#define alloc_netdev_mq(sizeof_priv, name, name_assign_type, setup, count) \
3423 alloc_netdev_mqs(sizeof_priv, name, name_assign_type, setup, count, \
3424 count)
36909ea4 3425
f629d208
JP
3426int register_netdev(struct net_device *dev);
3427void unregister_netdev(struct net_device *dev);
f001fde5 3428
22bedad3 3429/* General hardware address lists handling functions */
f629d208
JP
3430int __hw_addr_sync(struct netdev_hw_addr_list *to_list,
3431 struct netdev_hw_addr_list *from_list, int addr_len);
3432void __hw_addr_unsync(struct netdev_hw_addr_list *to_list,
3433 struct netdev_hw_addr_list *from_list, int addr_len);
670e5b8e
AD
3434int __hw_addr_sync_dev(struct netdev_hw_addr_list *list,
3435 struct net_device *dev,
3436 int (*sync)(struct net_device *, const unsigned char *),
3437 int (*unsync)(struct net_device *,
3438 const unsigned char *));
3439void __hw_addr_unsync_dev(struct netdev_hw_addr_list *list,
3440 struct net_device *dev,
3441 int (*unsync)(struct net_device *,
3442 const unsigned char *));
f629d208 3443void __hw_addr_init(struct netdev_hw_addr_list *list);
22bedad3 3444
f001fde5 3445/* Functions used for device addresses handling */
f629d208
JP
3446int dev_addr_add(struct net_device *dev, const unsigned char *addr,
3447 unsigned char addr_type);
3448int dev_addr_del(struct net_device *dev, const unsigned char *addr,
3449 unsigned char addr_type);
f629d208
JP
3450void dev_addr_flush(struct net_device *dev);
3451int dev_addr_init(struct net_device *dev);
a748ee24
JP
3452
3453/* Functions used for unicast addresses handling */
f629d208
JP
3454int dev_uc_add(struct net_device *dev, const unsigned char *addr);
3455int dev_uc_add_excl(struct net_device *dev, const unsigned char *addr);
3456int dev_uc_del(struct net_device *dev, const unsigned char *addr);
3457int dev_uc_sync(struct net_device *to, struct net_device *from);
3458int dev_uc_sync_multiple(struct net_device *to, struct net_device *from);
3459void dev_uc_unsync(struct net_device *to, struct net_device *from);
3460void dev_uc_flush(struct net_device *dev);
3461void dev_uc_init(struct net_device *dev);
f001fde5 3462
670e5b8e
AD
3463/**
3464 * __dev_uc_sync - Synchonize device's unicast list
3465 * @dev: device to sync
3466 * @sync: function to call if address should be added
3467 * @unsync: function to call if address should be removed
3468 *
3469 * Add newly added addresses to the interface, and release
3470 * addresses that have been deleted.
3471 **/
3472static inline int __dev_uc_sync(struct net_device *dev,
3473 int (*sync)(struct net_device *,
3474 const unsigned char *),
3475 int (*unsync)(struct net_device *,
3476 const unsigned char *))
3477{
3478 return __hw_addr_sync_dev(&dev->uc, dev, sync, unsync);
3479}
3480
3481/**
e793c0f7 3482 * __dev_uc_unsync - Remove synchronized addresses from device
670e5b8e
AD
3483 * @dev: device to sync
3484 * @unsync: function to call if address should be removed
3485 *
3486 * Remove all addresses that were added to the device by dev_uc_sync().
3487 **/
3488static inline void __dev_uc_unsync(struct net_device *dev,
3489 int (*unsync)(struct net_device *,
3490 const unsigned char *))
3491{
3492 __hw_addr_unsync_dev(&dev->uc, dev, unsync);
3493}
3494
22bedad3 3495/* Functions used for multicast addresses handling */
f629d208
JP
3496int dev_mc_add(struct net_device *dev, const unsigned char *addr);
3497int dev_mc_add_global(struct net_device *dev, const unsigned char *addr);
3498int dev_mc_add_excl(struct net_device *dev, const unsigned char *addr);
3499int dev_mc_del(struct net_device *dev, const unsigned char *addr);
3500int dev_mc_del_global(struct net_device *dev, const unsigned char *addr);
3501int dev_mc_sync(struct net_device *to, struct net_device *from);
3502int dev_mc_sync_multiple(struct net_device *to, struct net_device *from);
3503void dev_mc_unsync(struct net_device *to, struct net_device *from);
3504void dev_mc_flush(struct net_device *dev);
3505void dev_mc_init(struct net_device *dev);
f001fde5 3506
670e5b8e
AD
3507/**
3508 * __dev_mc_sync - Synchonize device's multicast list
3509 * @dev: device to sync
3510 * @sync: function to call if address should be added
3511 * @unsync: function to call if address should be removed
3512 *
3513 * Add newly added addresses to the interface, and release
3514 * addresses that have been deleted.
3515 **/
3516static inline int __dev_mc_sync(struct net_device *dev,
3517 int (*sync)(struct net_device *,
3518 const unsigned char *),
3519 int (*unsync)(struct net_device *,
3520 const unsigned char *))
3521{
3522 return __hw_addr_sync_dev(&dev->mc, dev, sync, unsync);
3523}
3524
3525/**
e793c0f7 3526 * __dev_mc_unsync - Remove synchronized addresses from device
670e5b8e
AD
3527 * @dev: device to sync
3528 * @unsync: function to call if address should be removed
3529 *
3530 * Remove all addresses that were added to the device by dev_mc_sync().
3531 **/
3532static inline void __dev_mc_unsync(struct net_device *dev,
3533 int (*unsync)(struct net_device *,
3534 const unsigned char *))
3535{
3536 __hw_addr_unsync_dev(&dev->mc, dev, unsync);
3537}
3538
4417da66 3539/* Functions used for secondary unicast and multicast support */
f629d208
JP
3540void dev_set_rx_mode(struct net_device *dev);
3541void __dev_set_rx_mode(struct net_device *dev);
3542int dev_set_promiscuity(struct net_device *dev, int inc);
3543int dev_set_allmulti(struct net_device *dev, int inc);
3544void netdev_state_change(struct net_device *dev);
3545void netdev_notify_peers(struct net_device *dev);
3546void netdev_features_change(struct net_device *dev);
1da177e4 3547/* Load a device via the kmod */
f629d208
JP
3548void dev_load(struct net *net, const char *name);
3549struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
3550 struct rtnl_link_stats64 *storage);
3551void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64,
3552 const struct net_device_stats *netdev_stats);
eeda3fd6 3553
1da177e4 3554extern int netdev_max_backlog;
3b098e2d 3555extern int netdev_tstamp_prequeue;
1da177e4 3556extern int weight_p;
0a14842f 3557extern int bpf_jit_enable;
9ff162a8 3558
f629d208 3559bool netdev_has_upper_dev(struct net_device *dev, struct net_device *upper_dev);
44a40855
VY
3560struct net_device *netdev_upper_get_next_dev_rcu(struct net_device *dev,
3561 struct list_head **iter);
f629d208
JP
3562struct net_device *netdev_all_upper_get_next_dev_rcu(struct net_device *dev,
3563 struct list_head **iter);
8b5be856 3564
44a40855
VY
3565/* iterate through upper list, must be called under RCU read lock */
3566#define netdev_for_each_upper_dev_rcu(dev, updev, iter) \
3567 for (iter = &(dev)->adj_list.upper, \
3568 updev = netdev_upper_get_next_dev_rcu(dev, &(iter)); \
3569 updev; \
3570 updev = netdev_upper_get_next_dev_rcu(dev, &(iter)))
3571
8b5be856 3572/* iterate through upper list, must be called under RCU read lock */
2f268f12
VF
3573#define netdev_for_each_all_upper_dev_rcu(dev, updev, iter) \
3574 for (iter = &(dev)->all_adj_list.upper, \
3575 updev = netdev_all_upper_get_next_dev_rcu(dev, &(iter)); \
3576 updev; \
3577 updev = netdev_all_upper_get_next_dev_rcu(dev, &(iter)))
8b5be856 3578
f629d208
JP
3579void *netdev_lower_get_next_private(struct net_device *dev,
3580 struct list_head **iter);
3581void *netdev_lower_get_next_private_rcu(struct net_device *dev,
3582 struct list_head **iter);
31088a11
VF
3583
3584#define netdev_for_each_lower_private(dev, priv, iter) \
3585 for (iter = (dev)->adj_list.lower.next, \
3586 priv = netdev_lower_get_next_private(dev, &(iter)); \
3587 priv; \
3588 priv = netdev_lower_get_next_private(dev, &(iter)))
3589
3590#define netdev_for_each_lower_private_rcu(dev, priv, iter) \
3591 for (iter = &(dev)->adj_list.lower, \
3592 priv = netdev_lower_get_next_private_rcu(dev, &(iter)); \
3593 priv; \
3594 priv = netdev_lower_get_next_private_rcu(dev, &(iter)))
3595
4085ebe8
VY
3596void *netdev_lower_get_next(struct net_device *dev,
3597 struct list_head **iter);
3598#define netdev_for_each_lower_dev(dev, ldev, iter) \
3599 for (iter = &(dev)->adj_list.lower, \
3600 ldev = netdev_lower_get_next(dev, &(iter)); \
3601 ldev; \
3602 ldev = netdev_lower_get_next(dev, &(iter)))
3603
f629d208 3604void *netdev_adjacent_get_private(struct list_head *adj_list);
e001bfad 3605void *netdev_lower_get_first_private_rcu(struct net_device *dev);
f629d208
JP
3606struct net_device *netdev_master_upper_dev_get(struct net_device *dev);
3607struct net_device *netdev_master_upper_dev_get_rcu(struct net_device *dev);
3608int netdev_upper_dev_link(struct net_device *dev, struct net_device *upper_dev);
3609int netdev_master_upper_dev_link(struct net_device *dev,
9ff162a8 3610 struct net_device *upper_dev);
f629d208
JP
3611int netdev_master_upper_dev_link_private(struct net_device *dev,
3612 struct net_device *upper_dev,
3613 void *private);
3614void netdev_upper_dev_unlink(struct net_device *dev,
3615 struct net_device *upper_dev);
5bb025fa 3616void netdev_adjacent_rename_links(struct net_device *dev, char *oldname);
f629d208
JP
3617void *netdev_lower_dev_get_private(struct net_device *dev,
3618 struct net_device *lower_dev);
960fb622
ED
3619
3620/* RSS keys are 40 or 52 bytes long */
3621#define NETDEV_RSS_KEY_LEN 52
3622extern u8 netdev_rss_key[NETDEV_RSS_KEY_LEN];
3623void netdev_rss_key_fill(void *buffer, size_t len);
3624
4085ebe8
VY
3625int dev_get_nest_level(struct net_device *dev,
3626 bool (*type_check)(struct net_device *dev));
f629d208
JP
3627int skb_checksum_help(struct sk_buff *skb);
3628struct sk_buff *__skb_gso_segment(struct sk_buff *skb,
3629 netdev_features_t features, bool tx_path);
3630struct sk_buff *skb_mac_gso_segment(struct sk_buff *skb,
3631 netdev_features_t features);
12b0004d 3632
61bd3857
MS
3633struct netdev_bonding_info {
3634 ifslave slave;
3635 ifbond master;
3636};
3637
3638struct netdev_notifier_bonding_info {
3639 struct netdev_notifier_info info; /* must be first */
3640 struct netdev_bonding_info bonding_info;
3641};
3642
3643void netdev_bonding_info_change(struct net_device *dev,
3644 struct netdev_bonding_info *bonding_info);
3645
12b0004d
CW
3646static inline
3647struct sk_buff *skb_gso_segment(struct sk_buff *skb, netdev_features_t features)
3648{
3649 return __skb_gso_segment(skb, features, true);
3650}
53d6471c 3651__be16 skb_network_protocol(struct sk_buff *skb, int *depth);
ec5f0615
PS
3652
3653static inline bool can_checksum_protocol(netdev_features_t features,
3654 __be16 protocol)
3655{
3656 return ((features & NETIF_F_GEN_CSUM) ||
3657 ((features & NETIF_F_V4_CSUM) &&
3658 protocol == htons(ETH_P_IP)) ||
3659 ((features & NETIF_F_V6_CSUM) &&
3660 protocol == htons(ETH_P_IPV6)) ||
3661 ((features & NETIF_F_FCOE_CRC) &&
3662 protocol == htons(ETH_P_FCOE)));
3663}
12b0004d 3664
fb286bb2 3665#ifdef CONFIG_BUG
f629d208 3666void netdev_rx_csum_fault(struct net_device *dev);
fb286bb2
HX
3667#else
3668static inline void netdev_rx_csum_fault(struct net_device *dev)
3669{
3670}
3671#endif
1da177e4 3672/* rx skb timestamps */
f629d208
JP
3673void net_enable_timestamp(void);
3674void net_disable_timestamp(void);
1da177e4 3675
20380731 3676#ifdef CONFIG_PROC_FS
f629d208 3677int __init dev_proc_init(void);
900ff8c6
CW
3678#else
3679#define dev_proc_init() 0
20380731
ACM
3680#endif
3681
4798248e 3682static inline netdev_tx_t __netdev_start_xmit(const struct net_device_ops *ops,
fa2dbdc2
DM
3683 struct sk_buff *skb, struct net_device *dev,
3684 bool more)
4798248e 3685{
fa2dbdc2 3686 skb->xmit_more = more ? 1 : 0;
0b725a2c 3687 return ops->ndo_start_xmit(skb, dev);
4798248e
DM
3688}
3689
10b3ad8c 3690static inline netdev_tx_t netdev_start_xmit(struct sk_buff *skb, struct net_device *dev,
fa2dbdc2 3691 struct netdev_queue *txq, bool more)
4798248e
DM
3692{
3693 const struct net_device_ops *ops = dev->netdev_ops;
10b3ad8c 3694 int rc;
4798248e 3695
fa2dbdc2 3696 rc = __netdev_start_xmit(ops, skb, dev, more);
10b3ad8c
DM
3697 if (rc == NETDEV_TX_OK)
3698 txq_trans_update(txq);
3699
3700 return rc;
4798248e
DM
3701}
3702
42a2d923
LT
3703int netdev_class_create_file_ns(struct class_attribute *class_attr,
3704 const void *ns);
3705void netdev_class_remove_file_ns(struct class_attribute *class_attr,
3706 const void *ns);
58292cbe
TH
3707
3708static inline int netdev_class_create_file(struct class_attribute *class_attr)
3709{
3710 return netdev_class_create_file_ns(class_attr, NULL);
3711}
3712
3713static inline void netdev_class_remove_file(struct class_attribute *class_attr)
3714{
3715 netdev_class_remove_file_ns(class_attr, NULL);
3716}
b8a9787e 3717
04600794
JB
3718extern struct kobj_ns_type_operations net_ns_type_operations;
3719
f629d208 3720const char *netdev_drivername(const struct net_device *dev);
6579e57b 3721
f629d208 3722void linkwatch_run_queue(void);
20380731 3723
da08143b
MK
3724static inline netdev_features_t netdev_intersect_features(netdev_features_t f1,
3725 netdev_features_t f2)
3726{
3727 if (f1 & NETIF_F_GEN_CSUM)
3728 f1 |= (NETIF_F_ALL_CSUM & ~NETIF_F_GEN_CSUM);
3729 if (f2 & NETIF_F_GEN_CSUM)
3730 f2 |= (NETIF_F_ALL_CSUM & ~NETIF_F_GEN_CSUM);
3731 f1 &= f2;
3732 if (f1 & NETIF_F_GEN_CSUM)
3733 f1 &= ~(NETIF_F_ALL_CSUM & ~NETIF_F_GEN_CSUM);
3734
3735 return f1;
3736}
3737
c8f44aff
MM
3738static inline netdev_features_t netdev_get_wanted_features(
3739 struct net_device *dev)
5455c699
MM
3740{
3741 return (dev->features & ~dev->hw_features) | dev->wanted_features;
3742}
c8f44aff
MM
3743netdev_features_t netdev_increment_features(netdev_features_t all,
3744 netdev_features_t one, netdev_features_t mask);
b0ce3508
ED
3745
3746/* Allow TSO being used on stacked device :
3747 * Performing the GSO segmentation before last device
3748 * is a performance improvement.
3749 */
3750static inline netdev_features_t netdev_add_tso_features(netdev_features_t features,
3751 netdev_features_t mask)
3752{
3753 return netdev_increment_features(features, NETIF_F_ALL_TSO, mask);
3754}
3755
6cb6a27c 3756int __netdev_update_features(struct net_device *dev);
5455c699 3757void netdev_update_features(struct net_device *dev);
afe12cc8 3758void netdev_change_features(struct net_device *dev);
7f353bf2 3759
fc4a7489
PM
3760void netif_stacked_transfer_operstate(const struct net_device *rootdev,
3761 struct net_device *dev);
3762
e38f3025
TM
3763netdev_features_t passthru_features_check(struct sk_buff *skb,
3764 struct net_device *dev,
3765 netdev_features_t features);
c1e756bf 3766netdev_features_t netif_skb_features(struct sk_buff *skb);
58e998c6 3767
4d29515f 3768static inline bool net_gso_ok(netdev_features_t features, int gso_type)
576a30eb 3769{
c8f44aff 3770 netdev_features_t feature = gso_type << NETIF_F_GSO_SHIFT;
0345e186
MM
3771
3772 /* check flags correspondence */
3773 BUILD_BUG_ON(SKB_GSO_TCPV4 != (NETIF_F_TSO >> NETIF_F_GSO_SHIFT));
3774 BUILD_BUG_ON(SKB_GSO_UDP != (NETIF_F_UFO >> NETIF_F_GSO_SHIFT));
3775 BUILD_BUG_ON(SKB_GSO_DODGY != (NETIF_F_GSO_ROBUST >> NETIF_F_GSO_SHIFT));
3776 BUILD_BUG_ON(SKB_GSO_TCP_ECN != (NETIF_F_TSO_ECN >> NETIF_F_GSO_SHIFT));
3777 BUILD_BUG_ON(SKB_GSO_TCPV6 != (NETIF_F_TSO6 >> NETIF_F_GSO_SHIFT));
3778 BUILD_BUG_ON(SKB_GSO_FCOE != (NETIF_F_FSO >> NETIF_F_GSO_SHIFT));
4b28252c
TH
3779 BUILD_BUG_ON(SKB_GSO_GRE != (NETIF_F_GSO_GRE >> NETIF_F_GSO_SHIFT));
3780 BUILD_BUG_ON(SKB_GSO_GRE_CSUM != (NETIF_F_GSO_GRE_CSUM >> NETIF_F_GSO_SHIFT));
3781 BUILD_BUG_ON(SKB_GSO_IPIP != (NETIF_F_GSO_IPIP >> NETIF_F_GSO_SHIFT));
3782 BUILD_BUG_ON(SKB_GSO_SIT != (NETIF_F_GSO_SIT >> NETIF_F_GSO_SHIFT));
3783 BUILD_BUG_ON(SKB_GSO_UDP_TUNNEL != (NETIF_F_GSO_UDP_TUNNEL >> NETIF_F_GSO_SHIFT));
3784 BUILD_BUG_ON(SKB_GSO_UDP_TUNNEL_CSUM != (NETIF_F_GSO_UDP_TUNNEL_CSUM >> NETIF_F_GSO_SHIFT));
e585f236 3785 BUILD_BUG_ON(SKB_GSO_TUNNEL_REMCSUM != (NETIF_F_GSO_TUNNEL_REMCSUM >> NETIF_F_GSO_SHIFT));
0345e186 3786
d6b4991a 3787 return (features & feature) == feature;
576a30eb
HX
3788}
3789
4d29515f 3790static inline bool skb_gso_ok(struct sk_buff *skb, netdev_features_t features)
bcd76111 3791{
278b2513 3792 return net_gso_ok(features, skb_shinfo(skb)->gso_type) &&
21dc3301 3793 (!skb_has_frag_list(skb) || (features & NETIF_F_FRAGLIST));
bcd76111
HX
3794}
3795
8b86a61d 3796static inline bool netif_needs_gso(struct sk_buff *skb,
4d29515f 3797 netdev_features_t features)
7967168c 3798{
fc741216 3799 return skb_is_gso(skb) && (!skb_gso_ok(skb, features) ||
cdbee74c
YZ
3800 unlikely((skb->ip_summed != CHECKSUM_PARTIAL) &&
3801 (skb->ip_summed != CHECKSUM_UNNECESSARY)));
7967168c
HX
3802}
3803
82cc1a7a
PWJ
3804static inline void netif_set_gso_max_size(struct net_device *dev,
3805 unsigned int size)
3806{
3807 dev->gso_max_size = size;
3808}
3809
7a7ffbab
WCC
3810static inline void skb_gso_error_unwind(struct sk_buff *skb, __be16 protocol,
3811 int pulled_hlen, u16 mac_offset,
3812 int mac_len)
3813{
3814 skb->protocol = protocol;
3815 skb->encapsulation = 1;
3816 skb_push(skb, pulled_hlen);
3817 skb_reset_transport_header(skb);
3818 skb->mac_header = mac_offset;
3819 skb->network_header = skb->mac_header + mac_len;
3820 skb->mac_len = mac_len;
3821}
3822
a6cc0cfa
JF
3823static inline bool netif_is_macvlan(struct net_device *dev)
3824{
3825 return dev->priv_flags & IFF_MACVLAN;
3826}
3827
2f33e7d5
MB
3828static inline bool netif_is_macvlan_port(struct net_device *dev)
3829{
3830 return dev->priv_flags & IFF_MACVLAN_PORT;
3831}
3832
5933fea7
MB
3833static inline bool netif_is_ipvlan(struct net_device *dev)
3834{
3835 return dev->priv_flags & IFF_IPVLAN_SLAVE;
3836}
3837
3838static inline bool netif_is_ipvlan_port(struct net_device *dev)
3839{
3840 return dev->priv_flags & IFF_IPVLAN_MASTER;
3841}
3842
8a7fbfab 3843static inline bool netif_is_bond_master(struct net_device *dev)
3844{
3845 return dev->flags & IFF_MASTER && dev->priv_flags & IFF_BONDING;
3846}
3847
4d29515f 3848static inline bool netif_is_bond_slave(struct net_device *dev)
1765a575
JP
3849{
3850 return dev->flags & IFF_SLAVE && dev->priv_flags & IFF_BONDING;
3851}
3852
3bdc0eba
BG
3853static inline bool netif_supports_nofcs(struct net_device *dev)
3854{
3855 return dev->priv_flags & IFF_SUPP_NOFCS;
3856}
3857
007979ea 3858static inline bool netif_is_l3_master(const struct net_device *dev)
4e3c8992 3859{
007979ea 3860 return dev->priv_flags & IFF_L3MDEV_MASTER;
4e3c8992
DA
3861}
3862
fee6d4c7
DA
3863static inline bool netif_is_l3_slave(const struct net_device *dev)
3864{
3865 return dev->priv_flags & IFF_L3MDEV_SLAVE;
3866}
3867
0894ae3f
JP
3868static inline bool netif_is_bridge_master(const struct net_device *dev)
3869{
3870 return dev->priv_flags & IFF_EBRIDGE;
3871}
3872
28f9ee22
VY
3873static inline bool netif_is_bridge_port(const struct net_device *dev)
3874{
3875 return dev->priv_flags & IFF_BRIDGE_PORT;
3876}
3877
35d4e172
JP
3878static inline bool netif_is_ovs_master(const struct net_device *dev)
3879{
3880 return dev->priv_flags & IFF_OPENVSWITCH;
3881}
3882
02875878
ED
3883/* This device needs to keep skb dst for qdisc enqueue or ndo_start_xmit() */
3884static inline void netif_keep_dst(struct net_device *dev)
3885{
3886 dev->priv_flags &= ~(IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM);
3887}
3888
505d4f73 3889extern struct pernet_operations __net_initdata loopback_net_ops;
b1b67dd4 3890
571ba423
JP
3891/* Logging, debugging and troubleshooting/diagnostic helpers. */
3892
3893/* netdev_printk helpers, similar to dev_printk */
3894
3895static inline const char *netdev_name(const struct net_device *dev)
3896{
c6f854d5
VF
3897 if (!dev->name[0] || strchr(dev->name, '%'))
3898 return "(unnamed net_device)";
571ba423
JP
3899 return dev->name;
3900}
3901
ccc7f496
VF
3902static inline const char *netdev_reg_state(const struct net_device *dev)
3903{
3904 switch (dev->reg_state) {
3905 case NETREG_UNINITIALIZED: return " (uninitialized)";
3906 case NETREG_REGISTERED: return "";
3907 case NETREG_UNREGISTERING: return " (unregistering)";
3908 case NETREG_UNREGISTERED: return " (unregistered)";
3909 case NETREG_RELEASED: return " (released)";
3910 case NETREG_DUMMY: return " (dummy)";
3911 }
3912
3913 WARN_ONCE(1, "%s: unknown reg_state %d\n", dev->name, dev->reg_state);
3914 return " (unknown)";
3915}
3916
f629d208 3917__printf(3, 4)
6ea754eb
JP
3918void netdev_printk(const char *level, const struct net_device *dev,
3919 const char *format, ...);
f629d208 3920__printf(2, 3)
6ea754eb 3921void netdev_emerg(const struct net_device *dev, const char *format, ...);
f629d208 3922__printf(2, 3)
6ea754eb 3923void netdev_alert(const struct net_device *dev, const char *format, ...);
f629d208 3924__printf(2, 3)
6ea754eb 3925void netdev_crit(const struct net_device *dev, const char *format, ...);
f629d208 3926__printf(2, 3)
6ea754eb 3927void netdev_err(const struct net_device *dev, const char *format, ...);
f629d208 3928__printf(2, 3)
6ea754eb 3929void netdev_warn(const struct net_device *dev, const char *format, ...);
f629d208 3930__printf(2, 3)
6ea754eb 3931void netdev_notice(const struct net_device *dev, const char *format, ...);
f629d208 3932__printf(2, 3)
6ea754eb 3933void netdev_info(const struct net_device *dev, const char *format, ...);
571ba423 3934
8909c9ad
VK
3935#define MODULE_ALIAS_NETDEV(device) \
3936 MODULE_ALIAS("netdev-" device)
3937
b558c96f 3938#if defined(CONFIG_DYNAMIC_DEBUG)
571ba423
JP
3939#define netdev_dbg(__dev, format, args...) \
3940do { \
ffa10cb4 3941 dynamic_netdev_dbg(__dev, format, ##args); \
571ba423 3942} while (0)
b558c96f
JC
3943#elif defined(DEBUG)
3944#define netdev_dbg(__dev, format, args...) \
3945 netdev_printk(KERN_DEBUG, __dev, format, ##args)
571ba423
JP
3946#else
3947#define netdev_dbg(__dev, format, args...) \
3948({ \
3949 if (0) \
3950 netdev_printk(KERN_DEBUG, __dev, format, ##args); \
571ba423
JP
3951})
3952#endif
3953
3954#if defined(VERBOSE_DEBUG)
3955#define netdev_vdbg netdev_dbg
3956#else
3957
3958#define netdev_vdbg(dev, format, args...) \
3959({ \
3960 if (0) \
3961 netdev_printk(KERN_DEBUG, dev, format, ##args); \
3962 0; \
3963})
3964#endif
3965
3966/*
3967 * netdev_WARN() acts like dev_printk(), but with the key difference
3968 * of using a WARN/WARN_ON to get the message out, including the
3969 * file/line information and a backtrace.
3970 */
3971#define netdev_WARN(dev, format, args...) \
ccc7f496
VF
3972 WARN(1, "netdevice: %s%s\n" format, netdev_name(dev), \
3973 netdev_reg_state(dev), ##args)
571ba423 3974
b3d95c5c
JP
3975/* netif printk helpers, similar to netdev_printk */
3976
3977#define netif_printk(priv, type, level, dev, fmt, args...) \
3978do { \
3979 if (netif_msg_##type(priv)) \
3980 netdev_printk(level, (dev), fmt, ##args); \
3981} while (0)
3982
f45f4321
JP
3983#define netif_level(level, priv, type, dev, fmt, args...) \
3984do { \
3985 if (netif_msg_##type(priv)) \
3986 netdev_##level(dev, fmt, ##args); \
3987} while (0)
3988
b3d95c5c 3989#define netif_emerg(priv, type, dev, fmt, args...) \
f45f4321 3990 netif_level(emerg, priv, type, dev, fmt, ##args)
b3d95c5c 3991#define netif_alert(priv, type, dev, fmt, args...) \
f45f4321 3992 netif_level(alert, priv, type, dev, fmt, ##args)
b3d95c5c 3993#define netif_crit(priv, type, dev, fmt, args...) \
f45f4321 3994 netif_level(crit, priv, type, dev, fmt, ##args)
b3d95c5c 3995#define netif_err(priv, type, dev, fmt, args...) \
f45f4321 3996 netif_level(err, priv, type, dev, fmt, ##args)
b3d95c5c 3997#define netif_warn(priv, type, dev, fmt, args...) \
f45f4321 3998 netif_level(warn, priv, type, dev, fmt, ##args)
b3d95c5c 3999#define netif_notice(priv, type, dev, fmt, args...) \
f45f4321 4000 netif_level(notice, priv, type, dev, fmt, ##args)
b3d95c5c 4001#define netif_info(priv, type, dev, fmt, args...) \
f45f4321 4002 netif_level(info, priv, type, dev, fmt, ##args)
b3d95c5c 4003
0053ea9c 4004#if defined(CONFIG_DYNAMIC_DEBUG)
b3d95c5c
JP
4005#define netif_dbg(priv, type, netdev, format, args...) \
4006do { \
4007 if (netif_msg_##type(priv)) \
b5fb0a03 4008 dynamic_netdev_dbg(netdev, format, ##args); \
b3d95c5c 4009} while (0)
0053ea9c
JP
4010#elif defined(DEBUG)
4011#define netif_dbg(priv, type, dev, format, args...) \
4012 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args)
b3d95c5c
JP
4013#else
4014#define netif_dbg(priv, type, dev, format, args...) \
4015({ \
4016 if (0) \
4017 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \
4018 0; \
4019})
4020#endif
4021
4022#if defined(VERBOSE_DEBUG)
bcfcc450 4023#define netif_vdbg netif_dbg
b3d95c5c
JP
4024#else
4025#define netif_vdbg(priv, type, dev, format, args...) \
4026({ \
4027 if (0) \
a4ed89cb 4028 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \
b3d95c5c
JP
4029 0; \
4030})
4031#endif
571ba423 4032
900ff8c6
CW
4033/*
4034 * The list of packet types we will receive (as opposed to discard)
4035 * and the routines to invoke.
4036 *
4037 * Why 16. Because with 16 the only overlap we get on a hash of the
4038 * low nibble of the protocol value is RARP/SNAP/X.25.
4039 *
4040 * NOTE: That is no longer true with the addition of VLAN tags. Not
4041 * sure which should go first, but I bet it won't make much
4042 * difference if we are running VLANs. The good news is that
4043 * this protocol won't be in the list unless compiled in, so
4044 * the average user (w/out VLANs) will not be adversely affected.
4045 * --BLG
4046 *
4047 * 0800 IP
4048 * 8100 802.1Q VLAN
4049 * 0001 802.3
4050 * 0002 AX.25
4051 * 0004 802.2
4052 * 8035 RARP
4053 * 0005 SNAP
4054 * 0805 X.25
4055 * 0806 ARP
4056 * 8137 IPX
4057 * 0009 Localtalk
4058 * 86DD IPv6
4059 */
4060#define PTYPE_HASH_SIZE (16)
4061#define PTYPE_HASH_MASK (PTYPE_HASH_SIZE - 1)
4062
385a154c 4063#endif /* _LINUX_NETDEVICE_H */