1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * INET An implementation of the TCP/IP protocol suite for the LINUX
4 * operating system. INET is implemented using the BSD Socket
5 * interface as the means of communication with the user level.
7 * Definitions for the Interfaces handler.
9 * Version: @(#)dev.h 1.0.10 08/12/93
12 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
13 * Corey Minyard <wf-rch!minyard@relay.EU.net>
14 * Donald J. Becker, <becker@cesdis.gsfc.nasa.gov>
15 * Alan Cox, <alan@lxorguk.ukuu.org.uk>
16 * Bjorn Ekwall. <bj0rn@blox.se>
17 * Pekka Riikonen <priikone@poseidon.pspt.fi>
19 * Moved to /usr/include/linux for NET3
21 #ifndef _LINUX_NETDEVICE_H
22 #define _LINUX_NETDEVICE_H
24 #include <linux/timer.h>
25 #include <linux/bug.h>
26 #include <linux/delay.h>
27 #include <linux/atomic.h>
28 #include <linux/prefetch.h>
29 #include <asm/cache.h>
30 #include <asm/byteorder.h>
32 #include <linux/percpu.h>
33 #include <linux/rculist.h>
34 #include <linux/workqueue.h>
35 #include <linux/dynamic_queue_limits.h>
37 #include <net/net_namespace.h>
39 #include <net/dcbnl.h>
41 #include <net/netprio_cgroup.h>
44 #include <linux/netdev_features.h>
45 #include <linux/neighbour.h>
46 #include <uapi/linux/netdevice.h>
47 #include <uapi/linux/if_bonding.h>
48 #include <uapi/linux/pkt_cls.h>
49 #include <linux/hashtable.h>
50 #include <linux/rbtree.h>
57 struct ip_tunnel_parm;
58 struct macsec_context;
64 /* 802.15.4 specific */
67 /* UDP Tunnel offloads */
68 struct udp_tunnel_info;
69 struct udp_tunnel_nic_info;
70 struct udp_tunnel_nic;
74 void synchronize_net(void);
75 void netdev_set_default_ethtool_ops(struct net_device *dev,
76 const struct ethtool_ops *ops);
78 /* Backlog congestion levels */
79 #define NET_RX_SUCCESS 0 /* keep 'em coming, baby */
80 #define NET_RX_DROP 1 /* packet dropped */
82 #define MAX_NEST_DEV 8
85 * Transmit return codes: transmit return codes originate from three different
88 * - qdisc return codes
89 * - driver transmit return codes
92 * Drivers are allowed to return any one of those in their hard_start_xmit()
93 * function. Real network devices commonly used with qdiscs should only return
94 * the driver transmit return codes though - when qdiscs are used, the actual
95 * transmission happens asynchronously, so the value is not propagated to
96 * higher layers. Virtual network devices transmit synchronously; in this case
97 * the driver transmit return codes are consumed by dev_queue_xmit(), and all
98 * others are propagated to higher layers.
101 /* qdisc ->enqueue() return codes. */
102 #define NET_XMIT_SUCCESS 0x00
103 #define NET_XMIT_DROP 0x01 /* skb dropped */
104 #define NET_XMIT_CN 0x02 /* congestion notification */
105 #define NET_XMIT_MASK 0x0f /* qdisc flags in net/sch_generic.h */
107 /* NET_XMIT_CN is special. It does not guarantee that this packet is lost. It
108 * indicates that the device will soon be dropping packets, or already drops
109 * some packets of the same priority; prompting us to send less aggressively. */
110 #define net_xmit_eval(e) ((e) == NET_XMIT_CN ? 0 : (e))
111 #define net_xmit_errno(e) ((e) != NET_XMIT_CN ? -ENOBUFS : 0)
113 /* Driver transmit return codes */
114 #define NETDEV_TX_MASK 0xf0
117 __NETDEV_TX_MIN = INT_MIN, /* make sure enum is signed */
118 NETDEV_TX_OK = 0x00, /* driver took care of packet */
119 NETDEV_TX_BUSY = 0x10, /* driver tx path was busy*/
121 typedef enum netdev_tx netdev_tx_t;
124 * Current order: NETDEV_TX_MASK > NET_XMIT_MASK >= 0 is significant;
125 * hard_start_xmit() return < NET_XMIT_MASK means skb was consumed.
127 static inline bool dev_xmit_complete(int rc)
130 * Positive cases with an skb consumed by a driver:
131 * - successful transmission (rc == NETDEV_TX_OK)
132 * - error while transmitting (rc < 0)
133 * - error while queueing to a different device (rc & NET_XMIT_MASK)
135 if (likely(rc < NET_XMIT_MASK))
142 * Compute the worst-case header length according to the protocols
146 #if defined(CONFIG_HYPERV_NET)
147 # define LL_MAX_HEADER 128
148 #elif defined(CONFIG_WLAN) || IS_ENABLED(CONFIG_AX25)
149 # if defined(CONFIG_MAC80211_MESH)
150 # define LL_MAX_HEADER 128
152 # define LL_MAX_HEADER 96
155 # define LL_MAX_HEADER 32
158 #if !IS_ENABLED(CONFIG_NET_IPIP) && !IS_ENABLED(CONFIG_NET_IPGRE) && \
159 !IS_ENABLED(CONFIG_IPV6_SIT) && !IS_ENABLED(CONFIG_IPV6_TUNNEL)
160 #define MAX_HEADER LL_MAX_HEADER
162 #define MAX_HEADER (LL_MAX_HEADER + 48)
166 * Old network device statistics. Fields are native words
167 * (unsigned long) so they can be read and written atomically.
170 #define NET_DEV_STAT(FIELD) \
172 unsigned long FIELD; \
173 atomic_long_t __##FIELD; \
176 struct net_device_stats {
177 NET_DEV_STAT(rx_packets);
178 NET_DEV_STAT(tx_packets);
179 NET_DEV_STAT(rx_bytes);
180 NET_DEV_STAT(tx_bytes);
181 NET_DEV_STAT(rx_errors);
182 NET_DEV_STAT(tx_errors);
183 NET_DEV_STAT(rx_dropped);
184 NET_DEV_STAT(tx_dropped);
185 NET_DEV_STAT(multicast);
186 NET_DEV_STAT(collisions);
187 NET_DEV_STAT(rx_length_errors);
188 NET_DEV_STAT(rx_over_errors);
189 NET_DEV_STAT(rx_crc_errors);
190 NET_DEV_STAT(rx_frame_errors);
191 NET_DEV_STAT(rx_fifo_errors);
192 NET_DEV_STAT(rx_missed_errors);
193 NET_DEV_STAT(tx_aborted_errors);
194 NET_DEV_STAT(tx_carrier_errors);
195 NET_DEV_STAT(tx_fifo_errors);
196 NET_DEV_STAT(tx_heartbeat_errors);
197 NET_DEV_STAT(tx_window_errors);
198 NET_DEV_STAT(rx_compressed);
199 NET_DEV_STAT(tx_compressed);
204 #include <linux/cache.h>
205 #include <linux/skbuff.h>
208 #include <linux/static_key.h>
209 extern struct static_key_false rps_needed;
210 extern struct static_key_false rfs_needed;
217 struct netdev_hw_addr {
218 struct list_head list;
220 unsigned char addr[MAX_ADDR_LEN];
222 #define NETDEV_HW_ADDR_T_LAN 1
223 #define NETDEV_HW_ADDR_T_SAN 2
224 #define NETDEV_HW_ADDR_T_UNICAST 3
225 #define NETDEV_HW_ADDR_T_MULTICAST 4
230 struct rcu_head rcu_head;
233 struct netdev_hw_addr_list {
234 struct list_head list;
237 /* Auxiliary tree for faster lookup on addition and deletion */
241 #define netdev_hw_addr_list_count(l) ((l)->count)
242 #define netdev_hw_addr_list_empty(l) (netdev_hw_addr_list_count(l) == 0)
243 #define netdev_hw_addr_list_for_each(ha, l) \
244 list_for_each_entry(ha, &(l)->list, list)
246 #define netdev_uc_count(dev) netdev_hw_addr_list_count(&(dev)->uc)
247 #define netdev_uc_empty(dev) netdev_hw_addr_list_empty(&(dev)->uc)
248 #define netdev_for_each_uc_addr(ha, dev) \
249 netdev_hw_addr_list_for_each(ha, &(dev)->uc)
251 #define netdev_mc_count(dev) netdev_hw_addr_list_count(&(dev)->mc)
252 #define netdev_mc_empty(dev) netdev_hw_addr_list_empty(&(dev)->mc)
253 #define netdev_for_each_mc_addr(ha, dev) \
254 netdev_hw_addr_list_for_each(ha, &(dev)->mc)
260 /* cached hardware header; allow for machine alignment needs. */
261 #define HH_DATA_MOD 16
262 #define HH_DATA_OFF(__len) \
263 (HH_DATA_MOD - (((__len - 1) & (HH_DATA_MOD - 1)) + 1))
264 #define HH_DATA_ALIGN(__len) \
265 (((__len)+(HH_DATA_MOD-1))&~(HH_DATA_MOD - 1))
266 unsigned long hh_data[HH_DATA_ALIGN(LL_MAX_HEADER) / sizeof(long)];
269 /* Reserve HH_DATA_MOD byte-aligned hard_header_len, but at least that much.
271 * dev->hard_header_len ? (dev->hard_header_len +
272 * (HH_DATA_MOD - 1)) & ~(HH_DATA_MOD - 1) : 0
274 * We could use other alignment values, but we must maintain the
275 * relationship HH alignment <= LL alignment.
277 #define LL_RESERVED_SPACE(dev) \
278 ((((dev)->hard_header_len + READ_ONCE((dev)->needed_headroom)) \
279 & ~(HH_DATA_MOD - 1)) + HH_DATA_MOD)
280 #define LL_RESERVED_SPACE_EXTRA(dev,extra) \
281 ((((dev)->hard_header_len + READ_ONCE((dev)->needed_headroom) + (extra)) \
282 & ~(HH_DATA_MOD - 1)) + HH_DATA_MOD)
285 int (*create) (struct sk_buff *skb, struct net_device *dev,
286 unsigned short type, const void *daddr,
287 const void *saddr, unsigned int len);
288 int (*parse)(const struct sk_buff *skb, unsigned char *haddr);
289 int (*cache)(const struct neighbour *neigh, struct hh_cache *hh, __be16 type);
290 void (*cache_update)(struct hh_cache *hh,
291 const struct net_device *dev,
292 const unsigned char *haddr);
293 bool (*validate)(const char *ll_header, unsigned int len);
294 __be16 (*parse_protocol)(const struct sk_buff *skb);
297 /* These flag bits are private to the generic network queueing
298 * layer; they may not be explicitly referenced by any other
302 enum netdev_state_t {
304 __LINK_STATE_PRESENT,
305 __LINK_STATE_NOCARRIER,
306 __LINK_STATE_LINKWATCH_PENDING,
307 __LINK_STATE_DORMANT,
308 __LINK_STATE_TESTING,
313 struct list_head list;
318 * size of gro hash buckets, must less than bit number of
319 * napi_struct::gro_bitmask
321 #define GRO_HASH_BUCKETS 8
324 * Structure for NAPI scheduling similar to tasklet but with weighting
327 /* The poll_list must only be managed by the entity which
328 * changes the state of the NAPI_STATE_SCHED bit. This means
329 * whoever atomically sets that bit can add this napi_struct
330 * to the per-CPU poll_list, and whoever clears that bit
331 * can remove from the list right before clearing the bit.
333 struct list_head poll_list;
337 int defer_hard_irqs_count;
338 unsigned long gro_bitmask;
339 int (*poll)(struct napi_struct *, int);
340 #ifdef CONFIG_NETPOLL
343 struct net_device *dev;
344 struct gro_list gro_hash[GRO_HASH_BUCKETS];
346 struct list_head rx_list; /* Pending GRO_NORMAL skbs */
347 int rx_count; /* length of rx_list */
348 struct hrtimer timer;
349 struct list_head dev_list;
350 struct hlist_node napi_hash_node;
351 unsigned int napi_id;
352 struct task_struct *thread;
356 NAPI_STATE_SCHED, /* Poll is scheduled */
357 NAPI_STATE_MISSED, /* reschedule a napi */
358 NAPI_STATE_DISABLE, /* Disable pending */
359 NAPI_STATE_NPSVC, /* Netpoll - don't dequeue from poll_list */
360 NAPI_STATE_LISTED, /* NAPI added to system lists */
361 NAPI_STATE_NO_BUSY_POLL, /* Do not add in napi_hash, no busy polling */
362 NAPI_STATE_IN_BUSY_POLL, /* sk_busy_loop() owns this NAPI */
363 NAPI_STATE_PREFER_BUSY_POLL, /* prefer busy-polling over softirq processing*/
364 NAPI_STATE_THREADED, /* The poll is performed inside its own thread*/
365 NAPI_STATE_SCHED_THREADED, /* Napi is currently scheduled in threaded mode */
369 NAPIF_STATE_SCHED = BIT(NAPI_STATE_SCHED),
370 NAPIF_STATE_MISSED = BIT(NAPI_STATE_MISSED),
371 NAPIF_STATE_DISABLE = BIT(NAPI_STATE_DISABLE),
372 NAPIF_STATE_NPSVC = BIT(NAPI_STATE_NPSVC),
373 NAPIF_STATE_LISTED = BIT(NAPI_STATE_LISTED),
374 NAPIF_STATE_NO_BUSY_POLL = BIT(NAPI_STATE_NO_BUSY_POLL),
375 NAPIF_STATE_IN_BUSY_POLL = BIT(NAPI_STATE_IN_BUSY_POLL),
376 NAPIF_STATE_PREFER_BUSY_POLL = BIT(NAPI_STATE_PREFER_BUSY_POLL),
377 NAPIF_STATE_THREADED = BIT(NAPI_STATE_THREADED),
378 NAPIF_STATE_SCHED_THREADED = BIT(NAPI_STATE_SCHED_THREADED),
388 typedef enum gro_result gro_result_t;
391 * enum rx_handler_result - Possible return values for rx_handlers.
392 * @RX_HANDLER_CONSUMED: skb was consumed by rx_handler, do not process it
394 * @RX_HANDLER_ANOTHER: Do another round in receive path. This is indicated in
395 * case skb->dev was changed by rx_handler.
396 * @RX_HANDLER_EXACT: Force exact delivery, no wildcard.
397 * @RX_HANDLER_PASS: Do nothing, pass the skb as if no rx_handler was called.
399 * rx_handlers are functions called from inside __netif_receive_skb(), to do
400 * special processing of the skb, prior to delivery to protocol handlers.
402 * Currently, a net_device can only have a single rx_handler registered. Trying
403 * to register a second rx_handler will return -EBUSY.
405 * To register a rx_handler on a net_device, use netdev_rx_handler_register().
406 * To unregister a rx_handler on a net_device, use
407 * netdev_rx_handler_unregister().
409 * Upon return, rx_handler is expected to tell __netif_receive_skb() what to
412 * If the rx_handler consumed the skb in some way, it should return
413 * RX_HANDLER_CONSUMED. This is appropriate when the rx_handler arranged for
414 * the skb to be delivered in some other way.
416 * If the rx_handler changed skb->dev, to divert the skb to another
417 * net_device, it should return RX_HANDLER_ANOTHER. The rx_handler for the
418 * new device will be called if it exists.
420 * If the rx_handler decides the skb should be ignored, it should return
421 * RX_HANDLER_EXACT. The skb will only be delivered to protocol handlers that
422 * are registered on exact device (ptype->dev == skb->dev).
424 * If the rx_handler didn't change skb->dev, but wants the skb to be normally
425 * delivered, it should return RX_HANDLER_PASS.
427 * A device without a registered rx_handler will behave as if rx_handler
428 * returned RX_HANDLER_PASS.
431 enum rx_handler_result {
437 typedef enum rx_handler_result rx_handler_result_t;
438 typedef rx_handler_result_t rx_handler_func_t(struct sk_buff **pskb);
440 void __napi_schedule(struct napi_struct *n);
441 void __napi_schedule_irqoff(struct napi_struct *n);
443 static inline bool napi_disable_pending(struct napi_struct *n)
445 return test_bit(NAPI_STATE_DISABLE, &n->state);
448 static inline bool napi_prefer_busy_poll(struct napi_struct *n)
450 return test_bit(NAPI_STATE_PREFER_BUSY_POLL, &n->state);
453 bool napi_schedule_prep(struct napi_struct *n);
456 * napi_schedule - schedule NAPI poll
459 * Schedule NAPI poll routine to be called if it is not already
462 static inline void napi_schedule(struct napi_struct *n)
464 if (napi_schedule_prep(n))
469 * napi_schedule_irqoff - schedule NAPI poll
472 * Variant of napi_schedule(), assuming hard irqs are masked.
474 static inline void napi_schedule_irqoff(struct napi_struct *n)
476 if (napi_schedule_prep(n))
477 __napi_schedule_irqoff(n);
480 /* Try to reschedule poll. Called by dev->poll() after napi_complete(). */
481 static inline bool napi_reschedule(struct napi_struct *napi)
483 if (napi_schedule_prep(napi)) {
484 __napi_schedule(napi);
490 bool napi_complete_done(struct napi_struct *n, int work_done);
492 * napi_complete - NAPI processing complete
495 * Mark NAPI processing as complete.
496 * Consider using napi_complete_done() instead.
497 * Return false if device should avoid rearming interrupts.
499 static inline bool napi_complete(struct napi_struct *n)
501 return napi_complete_done(n, 0);
504 int dev_set_threaded(struct net_device *dev, bool threaded);
507 * napi_disable - prevent NAPI from scheduling
510 * Stop NAPI from being scheduled on this context.
511 * Waits till any outstanding processing completes.
513 void napi_disable(struct napi_struct *n);
515 void napi_enable(struct napi_struct *n);
518 * napi_synchronize - wait until NAPI is not running
521 * Wait until NAPI is done being scheduled on this context.
522 * Waits till any outstanding processing completes but
523 * does not disable future activations.
525 static inline void napi_synchronize(const struct napi_struct *n)
527 if (IS_ENABLED(CONFIG_SMP))
528 while (test_bit(NAPI_STATE_SCHED, &n->state))
535 * napi_if_scheduled_mark_missed - if napi is running, set the
539 * If napi is running, set the NAPIF_STATE_MISSED, and return true if
542 static inline bool napi_if_scheduled_mark_missed(struct napi_struct *n)
544 unsigned long val, new;
547 val = READ_ONCE(n->state);
548 if (val & NAPIF_STATE_DISABLE)
551 if (!(val & NAPIF_STATE_SCHED))
554 new = val | NAPIF_STATE_MISSED;
555 } while (cmpxchg(&n->state, val, new) != val);
560 enum netdev_queue_state_t {
561 __QUEUE_STATE_DRV_XOFF,
562 __QUEUE_STATE_STACK_XOFF,
563 __QUEUE_STATE_FROZEN,
566 #define QUEUE_STATE_DRV_XOFF (1 << __QUEUE_STATE_DRV_XOFF)
567 #define QUEUE_STATE_STACK_XOFF (1 << __QUEUE_STATE_STACK_XOFF)
568 #define QUEUE_STATE_FROZEN (1 << __QUEUE_STATE_FROZEN)
570 #define QUEUE_STATE_ANY_XOFF (QUEUE_STATE_DRV_XOFF | QUEUE_STATE_STACK_XOFF)
571 #define QUEUE_STATE_ANY_XOFF_OR_FROZEN (QUEUE_STATE_ANY_XOFF | \
573 #define QUEUE_STATE_DRV_XOFF_OR_FROZEN (QUEUE_STATE_DRV_XOFF | \
577 * __QUEUE_STATE_DRV_XOFF is used by drivers to stop the transmit queue. The
578 * netif_tx_* functions below are used to manipulate this flag. The
579 * __QUEUE_STATE_STACK_XOFF flag is used by the stack to stop the transmit
580 * queue independently. The netif_xmit_*stopped functions below are called
581 * to check if the queue has been stopped by the driver or stack (either
582 * of the XOFF bits are set in the state). Drivers should not need to call
583 * netif_xmit*stopped functions, they should only be using netif_tx_*.
586 struct netdev_queue {
590 struct net_device *dev;
591 struct Qdisc __rcu *qdisc;
592 struct Qdisc *qdisc_sleeping;
596 #if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
599 unsigned long tx_maxrate;
601 * Number of TX timeouts for this queue
602 * (/sys/class/net/DEV/Q/trans_timeout)
604 unsigned long trans_timeout;
606 /* Subordinate device that the queue has been assigned to */
607 struct net_device *sb_dev;
608 #ifdef CONFIG_XDP_SOCKETS
609 struct xsk_buff_pool *pool;
614 spinlock_t _xmit_lock ____cacheline_aligned_in_smp;
617 * Time (in jiffies) of last Tx
619 unsigned long trans_start;
626 } ____cacheline_aligned_in_smp;
628 extern int sysctl_fb_tunnels_only_for_init_net;
629 extern int sysctl_devconf_inherit_init_net;
632 * sysctl_fb_tunnels_only_for_init_net == 0 : For all netns
633 * == 1 : For initns only
636 static inline bool net_has_fallback_tunnels(const struct net *net)
638 #if IS_ENABLED(CONFIG_SYSCTL)
639 int fb_tunnels_only_for_init_net = READ_ONCE(sysctl_fb_tunnels_only_for_init_net);
641 return !fb_tunnels_only_for_init_net ||
642 (net_eq(net, &init_net) && fb_tunnels_only_for_init_net == 1);
648 static inline int net_inherit_devconf(void)
650 #if IS_ENABLED(CONFIG_SYSCTL)
651 return READ_ONCE(sysctl_devconf_inherit_init_net);
657 static inline int netdev_queue_numa_node_read(const struct netdev_queue *q)
659 #if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
666 static inline void netdev_queue_numa_node_write(struct netdev_queue *q, int node)
668 #if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
675 * This structure holds an RPS map which can be of variable length. The
676 * map is an array of CPUs.
683 #define RPS_MAP_SIZE(_num) (sizeof(struct rps_map) + ((_num) * sizeof(u16)))
686 * The rps_dev_flow structure contains the mapping of a flow to a CPU, the
687 * tail pointer for that CPU's input queue at the time of last enqueue, and
688 * a hardware filter index.
690 struct rps_dev_flow {
693 unsigned int last_qtail;
695 #define RPS_NO_FILTER 0xffff
698 * The rps_dev_flow_table structure contains a table of flow mappings.
700 struct rps_dev_flow_table {
703 struct rps_dev_flow flows[];
705 #define RPS_DEV_FLOW_TABLE_SIZE(_num) (sizeof(struct rps_dev_flow_table) + \
706 ((_num) * sizeof(struct rps_dev_flow)))
709 * The rps_sock_flow_table contains mappings of flows to the last CPU
710 * on which they were processed by the application (set in recvmsg).
711 * Each entry is a 32bit value. Upper part is the high-order bits
712 * of flow hash, lower part is CPU number.
713 * rps_cpu_mask is used to partition the space, depending on number of
714 * possible CPUs : rps_cpu_mask = roundup_pow_of_two(nr_cpu_ids) - 1
715 * For example, if 64 CPUs are possible, rps_cpu_mask = 0x3f,
716 * meaning we use 32-6=26 bits for the hash.
718 struct rps_sock_flow_table {
721 u32 ents[] ____cacheline_aligned_in_smp;
723 #define RPS_SOCK_FLOW_TABLE_SIZE(_num) (offsetof(struct rps_sock_flow_table, ents[_num]))
725 #define RPS_NO_CPU 0xffff
727 extern u32 rps_cpu_mask;
728 extern struct rps_sock_flow_table __rcu *rps_sock_flow_table;
730 static inline void rps_record_sock_flow(struct rps_sock_flow_table *table,
734 unsigned int index = hash & table->mask;
735 u32 val = hash & ~rps_cpu_mask;
737 /* We only give a hint, preemption can change CPU under us */
738 val |= raw_smp_processor_id();
740 /* The following WRITE_ONCE() is paired with the READ_ONCE()
741 * here, and another one in get_rps_cpu().
743 if (READ_ONCE(table->ents[index]) != val)
744 WRITE_ONCE(table->ents[index], val);
748 #ifdef CONFIG_RFS_ACCEL
749 bool rps_may_expire_flow(struct net_device *dev, u16 rxq_index, u32 flow_id,
752 #endif /* CONFIG_RPS */
754 /* This structure contains an instance of an RX queue. */
755 struct netdev_rx_queue {
756 struct xdp_rxq_info xdp_rxq;
758 struct rps_map __rcu *rps_map;
759 struct rps_dev_flow_table __rcu *rps_flow_table;
762 struct net_device *dev;
763 #ifdef CONFIG_XDP_SOCKETS
764 struct xsk_buff_pool *pool;
766 } ____cacheline_aligned_in_smp;
769 * RX queue sysfs structures and functions.
771 struct rx_queue_attribute {
772 struct attribute attr;
773 ssize_t (*show)(struct netdev_rx_queue *queue, char *buf);
774 ssize_t (*store)(struct netdev_rx_queue *queue,
775 const char *buf, size_t len);
778 /* XPS map type and offset of the xps map within net_device->xps_maps[]. */
787 * This structure holds an XPS map which can be of variable length. The
788 * map is an array of queues.
792 unsigned int alloc_len;
796 #define XPS_MAP_SIZE(_num) (sizeof(struct xps_map) + ((_num) * sizeof(u16)))
797 #define XPS_MIN_MAP_ALLOC ((L1_CACHE_ALIGN(offsetof(struct xps_map, queues[1])) \
798 - sizeof(struct xps_map)) / sizeof(u16))
801 * This structure holds all XPS maps for device. Maps are indexed by CPU.
803 * We keep track of the number of cpus/rxqs used when the struct is allocated,
804 * in nr_ids. This will help not accessing out-of-bound memory.
806 * We keep track of the number of traffic classes used when the struct is
807 * allocated, in num_tc. This will be used to navigate the maps, to ensure we're
808 * not crossing its upper bound, as the original dev->num_tc can be updated in
811 struct xps_dev_maps {
815 struct xps_map __rcu *attr_map[]; /* Either CPUs map or RXQs map */
818 #define XPS_CPU_DEV_MAPS_SIZE(_tcs) (sizeof(struct xps_dev_maps) + \
819 (nr_cpu_ids * (_tcs) * sizeof(struct xps_map *)))
821 #define XPS_RXQ_DEV_MAPS_SIZE(_tcs, _rxqs) (sizeof(struct xps_dev_maps) +\
822 (_rxqs * (_tcs) * sizeof(struct xps_map *)))
824 #endif /* CONFIG_XPS */
826 #define TC_MAX_QUEUE 16
827 #define TC_BITMASK 15
828 /* HW offloaded queuing disciplines txq count and offset maps */
829 struct netdev_tc_txq {
834 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
836 * This structure is to hold information about the device
837 * configured to run FCoE protocol stack.
839 struct netdev_fcoe_hbainfo {
840 char manufacturer[64];
841 char serial_number[64];
842 char hardware_version[64];
843 char driver_version[64];
844 char optionrom_version[64];
845 char firmware_version[64];
847 char model_description[256];
851 #define MAX_PHYS_ITEM_ID_LEN 32
853 /* This structure holds a unique identifier to identify some
854 * physical item (port for example) used by a netdevice.
856 struct netdev_phys_item_id {
857 unsigned char id[MAX_PHYS_ITEM_ID_LEN];
858 unsigned char id_len;
861 static inline bool netdev_phys_item_id_same(struct netdev_phys_item_id *a,
862 struct netdev_phys_item_id *b)
864 return a->id_len == b->id_len &&
865 memcmp(a->id, b->id, a->id_len) == 0;
868 typedef u16 (*select_queue_fallback_t)(struct net_device *dev,
870 struct net_device *sb_dev);
872 enum net_device_path_type {
873 DEV_PATH_ETHERNET = 0,
880 struct net_device_path {
881 enum net_device_path_type type;
882 const struct net_device *dev;
891 DEV_PATH_BR_VLAN_KEEP,
892 DEV_PATH_BR_VLAN_TAG,
893 DEV_PATH_BR_VLAN_UNTAG,
894 DEV_PATH_BR_VLAN_UNTAG_HW,
906 #define NET_DEVICE_PATH_STACK_MAX 5
907 #define NET_DEVICE_PATH_VLAN_MAX 2
909 struct net_device_path_stack {
911 struct net_device_path path[NET_DEVICE_PATH_STACK_MAX];
914 struct net_device_path_ctx {
915 const struct net_device *dev;
922 } vlan[NET_DEVICE_PATH_VLAN_MAX];
926 TC_SETUP_QDISC_MQPRIO,
929 TC_SETUP_CLSMATCHALL,
939 TC_SETUP_QDISC_TAPRIO,
947 /* These structures hold the attributes of bpf state that are being passed
948 * to the netdevice through the bpf op.
950 enum bpf_netdev_command {
951 /* Set or clear a bpf program used in the earliest stages of packet
952 * rx. The prog will have been loaded as BPF_PROG_TYPE_XDP. The callee
953 * is responsible for calling bpf_prog_put on any old progs that are
954 * stored. In case of error, the callee need not release the new prog
955 * reference, but on success it takes ownership and must bpf_prog_put
956 * when it is no longer used.
960 /* BPF program for offload callbacks, invoked at program load time. */
961 BPF_OFFLOAD_MAP_ALLOC,
962 BPF_OFFLOAD_MAP_FREE,
966 struct bpf_prog_offload_ops;
967 struct netlink_ext_ack;
969 struct xdp_dev_bulk_queue;
979 struct bpf_xdp_entity {
980 struct bpf_prog *prog;
981 struct bpf_xdp_link *link;
985 enum bpf_netdev_command command;
990 struct bpf_prog *prog;
991 struct netlink_ext_ack *extack;
993 /* BPF_OFFLOAD_MAP_ALLOC, BPF_OFFLOAD_MAP_FREE */
995 struct bpf_offloaded_map *offmap;
997 /* XDP_SETUP_XSK_POOL */
999 struct xsk_buff_pool *pool;
1005 /* Flags for ndo_xsk_wakeup. */
1006 #define XDP_WAKEUP_RX (1 << 0)
1007 #define XDP_WAKEUP_TX (1 << 1)
1009 #ifdef CONFIG_XFRM_OFFLOAD
1010 struct xfrmdev_ops {
1011 int (*xdo_dev_state_add) (struct xfrm_state *x);
1012 void (*xdo_dev_state_delete) (struct xfrm_state *x);
1013 void (*xdo_dev_state_free) (struct xfrm_state *x);
1014 bool (*xdo_dev_offload_ok) (struct sk_buff *skb,
1015 struct xfrm_state *x);
1016 void (*xdo_dev_state_advance_esn) (struct xfrm_state *x);
1020 struct dev_ifalias {
1021 struct rcu_head rcuhead;
1028 struct netdev_name_node {
1029 struct hlist_node hlist;
1030 struct list_head list;
1031 struct net_device *dev;
1035 int netdev_name_node_alt_create(struct net_device *dev, const char *name);
1036 int netdev_name_node_alt_destroy(struct net_device *dev, const char *name);
1038 struct netdev_net_notifier {
1039 struct list_head list;
1040 struct notifier_block *nb;
1044 * This structure defines the management hooks for network devices.
1045 * The following hooks can be defined; unless noted otherwise, they are
1046 * optional and can be filled with a null pointer.
1048 * int (*ndo_init)(struct net_device *dev);
1049 * This function is called once when a network device is registered.
1050 * The network device can use this for any late stage initialization
1051 * or semantic validation. It can fail with an error code which will
1052 * be propagated back to register_netdev.
1054 * void (*ndo_uninit)(struct net_device *dev);
1055 * This function is called when device is unregistered or when registration
1056 * fails. It is not called if init fails.
1058 * int (*ndo_open)(struct net_device *dev);
1059 * This function is called when a network device transitions to the up
1062 * int (*ndo_stop)(struct net_device *dev);
1063 * This function is called when a network device transitions to the down
1066 * netdev_tx_t (*ndo_start_xmit)(struct sk_buff *skb,
1067 * struct net_device *dev);
1068 * Called when a packet needs to be transmitted.
1069 * Returns NETDEV_TX_OK. Can return NETDEV_TX_BUSY, but you should stop
1070 * the queue before that can happen; it's for obsolete devices and weird
1071 * corner cases, but the stack really does a non-trivial amount
1072 * of useless work if you return NETDEV_TX_BUSY.
1073 * Required; cannot be NULL.
1075 * netdev_features_t (*ndo_features_check)(struct sk_buff *skb,
1076 * struct net_device *dev
1077 * netdev_features_t features);
1078 * Called by core transmit path to determine if device is capable of
1079 * performing offload operations on a given packet. This is to give
1080 * the device an opportunity to implement any restrictions that cannot
1081 * be otherwise expressed by feature flags. The check is called with
1082 * the set of features that the stack has calculated and it returns
1083 * those the driver believes to be appropriate.
1085 * u16 (*ndo_select_queue)(struct net_device *dev, struct sk_buff *skb,
1086 * struct net_device *sb_dev);
1087 * Called to decide which queue to use when device supports multiple
1090 * void (*ndo_change_rx_flags)(struct net_device *dev, int flags);
1091 * This function is called to allow device receiver to make
1092 * changes to configuration when multicast or promiscuous is enabled.
1094 * void (*ndo_set_rx_mode)(struct net_device *dev);
1095 * This function is called device changes address list filtering.
1096 * If driver handles unicast address filtering, it should set
1097 * IFF_UNICAST_FLT in its priv_flags.
1099 * int (*ndo_set_mac_address)(struct net_device *dev, void *addr);
1100 * This function is called when the Media Access Control address
1101 * needs to be changed. If this interface is not defined, the
1102 * MAC address can not be changed.
1104 * int (*ndo_validate_addr)(struct net_device *dev);
1105 * Test if Media Access Control address is valid for the device.
1107 * int (*ndo_do_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd);
1108 * Old-style ioctl entry point. This is used internally by the
1109 * appletalk and ieee802154 subsystems but is no longer called by
1110 * the device ioctl handler.
1112 * int (*ndo_siocbond)(struct net_device *dev, struct ifreq *ifr, int cmd);
1113 * Used by the bonding driver for its device specific ioctls:
1114 * SIOCBONDENSLAVE, SIOCBONDRELEASE, SIOCBONDSETHWADDR, SIOCBONDCHANGEACTIVE,
1115 * SIOCBONDSLAVEINFOQUERY, and SIOCBONDINFOQUERY
1117 * * int (*ndo_eth_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd);
1118 * Called for ethernet specific ioctls: SIOCGMIIPHY, SIOCGMIIREG,
1119 * SIOCSMIIREG, SIOCSHWTSTAMP and SIOCGHWTSTAMP.
1121 * int (*ndo_set_config)(struct net_device *dev, struct ifmap *map);
1122 * Used to set network devices bus interface parameters. This interface
1123 * is retained for legacy reasons; new devices should use the bus
1124 * interface (PCI) for low level management.
1126 * int (*ndo_change_mtu)(struct net_device *dev, int new_mtu);
1127 * Called when a user wants to change the Maximum Transfer Unit
1130 * void (*ndo_tx_timeout)(struct net_device *dev, unsigned int txqueue);
1131 * Callback used when the transmitter has not made any progress
1132 * for dev->watchdog ticks.
1134 * void (*ndo_get_stats64)(struct net_device *dev,
1135 * struct rtnl_link_stats64 *storage);
1136 * struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
1137 * Called when a user wants to get the network device usage
1138 * statistics. Drivers must do one of the following:
1139 * 1. Define @ndo_get_stats64 to fill in a zero-initialised
1140 * rtnl_link_stats64 structure passed by the caller.
1141 * 2. Define @ndo_get_stats to update a net_device_stats structure
1142 * (which should normally be dev->stats) and return a pointer to
1143 * it. The structure may be changed asynchronously only if each
1144 * field is written atomically.
1145 * 3. Update dev->stats asynchronously and atomically, and define
1146 * neither operation.
1148 * bool (*ndo_has_offload_stats)(const struct net_device *dev, int attr_id)
1149 * Return true if this device supports offload stats of this attr_id.
1151 * int (*ndo_get_offload_stats)(int attr_id, const struct net_device *dev,
1153 * Get statistics for offload operations by attr_id. Write it into the
1154 * attr_data pointer.
1156 * int (*ndo_vlan_rx_add_vid)(struct net_device *dev, __be16 proto, u16 vid);
1157 * If device supports VLAN filtering this function is called when a
1158 * VLAN id is registered.
1160 * int (*ndo_vlan_rx_kill_vid)(struct net_device *dev, __be16 proto, u16 vid);
1161 * If device supports VLAN filtering this function is called when a
1162 * VLAN id is unregistered.
1164 * void (*ndo_poll_controller)(struct net_device *dev);
1166 * SR-IOV management functions.
1167 * int (*ndo_set_vf_mac)(struct net_device *dev, int vf, u8* mac);
1168 * int (*ndo_set_vf_vlan)(struct net_device *dev, int vf, u16 vlan,
1169 * u8 qos, __be16 proto);
1170 * int (*ndo_set_vf_rate)(struct net_device *dev, int vf, int min_tx_rate,
1172 * int (*ndo_set_vf_spoofchk)(struct net_device *dev, int vf, bool setting);
1173 * int (*ndo_set_vf_trust)(struct net_device *dev, int vf, bool setting);
1174 * int (*ndo_get_vf_config)(struct net_device *dev,
1175 * int vf, struct ifla_vf_info *ivf);
1176 * int (*ndo_set_vf_link_state)(struct net_device *dev, int vf, int link_state);
1177 * int (*ndo_set_vf_port)(struct net_device *dev, int vf,
1178 * struct nlattr *port[]);
1180 * Enable or disable the VF ability to query its RSS Redirection Table and
1181 * Hash Key. This is needed since on some devices VF share this information
1182 * with PF and querying it may introduce a theoretical security risk.
1183 * int (*ndo_set_vf_rss_query_en)(struct net_device *dev, int vf, bool setting);
1184 * int (*ndo_get_vf_port)(struct net_device *dev, int vf, struct sk_buff *skb);
1185 * int (*ndo_setup_tc)(struct net_device *dev, enum tc_setup_type type,
1187 * Called to setup any 'tc' scheduler, classifier or action on @dev.
1188 * This is always called from the stack with the rtnl lock held and netif
1189 * tx queues stopped. This allows the netdevice to perform queue
1190 * management safely.
1192 * Fiber Channel over Ethernet (FCoE) offload functions.
1193 * int (*ndo_fcoe_enable)(struct net_device *dev);
1194 * Called when the FCoE protocol stack wants to start using LLD for FCoE
1195 * so the underlying device can perform whatever needed configuration or
1196 * initialization to support acceleration of FCoE traffic.
1198 * int (*ndo_fcoe_disable)(struct net_device *dev);
1199 * Called when the FCoE protocol stack wants to stop using LLD for FCoE
1200 * so the underlying device can perform whatever needed clean-ups to
1201 * stop supporting acceleration of FCoE traffic.
1203 * int (*ndo_fcoe_ddp_setup)(struct net_device *dev, u16 xid,
1204 * struct scatterlist *sgl, unsigned int sgc);
1205 * Called when the FCoE Initiator wants to initialize an I/O that
1206 * is a possible candidate for Direct Data Placement (DDP). The LLD can
1207 * perform necessary setup and returns 1 to indicate the device is set up
1208 * successfully to perform DDP on this I/O, otherwise this returns 0.
1210 * int (*ndo_fcoe_ddp_done)(struct net_device *dev, u16 xid);
1211 * Called when the FCoE Initiator/Target is done with the DDPed I/O as
1212 * indicated by the FC exchange id 'xid', so the underlying device can
1213 * clean up and reuse resources for later DDP requests.
1215 * int (*ndo_fcoe_ddp_target)(struct net_device *dev, u16 xid,
1216 * struct scatterlist *sgl, unsigned int sgc);
1217 * Called when the FCoE Target wants to initialize an I/O that
1218 * is a possible candidate for Direct Data Placement (DDP). The LLD can
1219 * perform necessary setup and returns 1 to indicate the device is set up
1220 * successfully to perform DDP on this I/O, otherwise this returns 0.
1222 * int (*ndo_fcoe_get_hbainfo)(struct net_device *dev,
1223 * struct netdev_fcoe_hbainfo *hbainfo);
1224 * Called when the FCoE Protocol stack wants information on the underlying
1225 * device. This information is utilized by the FCoE protocol stack to
1226 * register attributes with Fiber Channel management service as per the
1227 * FC-GS Fabric Device Management Information(FDMI) specification.
1229 * int (*ndo_fcoe_get_wwn)(struct net_device *dev, u64 *wwn, int type);
1230 * Called when the underlying device wants to override default World Wide
1231 * Name (WWN) generation mechanism in FCoE protocol stack to pass its own
1232 * World Wide Port Name (WWPN) or World Wide Node Name (WWNN) to the FCoE
1233 * protocol stack to use.
1236 * int (*ndo_rx_flow_steer)(struct net_device *dev, const struct sk_buff *skb,
1237 * u16 rxq_index, u32 flow_id);
1238 * Set hardware filter for RFS. rxq_index is the target queue index;
1239 * flow_id is a flow ID to be passed to rps_may_expire_flow() later.
1240 * Return the filter ID on success, or a negative error code.
1242 * Slave management functions (for bridge, bonding, etc).
1243 * int (*ndo_add_slave)(struct net_device *dev, struct net_device *slave_dev);
1244 * Called to make another netdev an underling.
1246 * int (*ndo_del_slave)(struct net_device *dev, struct net_device *slave_dev);
1247 * Called to release previously enslaved netdev.
1249 * struct net_device *(*ndo_get_xmit_slave)(struct net_device *dev,
1250 * struct sk_buff *skb,
1252 * Get the xmit slave of master device. If all_slaves is true, function
1253 * assume all the slaves can transmit.
1255 * Feature/offload setting functions.
1256 * netdev_features_t (*ndo_fix_features)(struct net_device *dev,
1257 * netdev_features_t features);
1258 * Adjusts the requested feature flags according to device-specific
1259 * constraints, and returns the resulting flags. Must not modify
1262 * int (*ndo_set_features)(struct net_device *dev, netdev_features_t features);
1263 * Called to update device configuration to new features. Passed
1264 * feature set might be less than what was returned by ndo_fix_features()).
1265 * Must return >0 or -errno if it changed dev->features itself.
1267 * int (*ndo_fdb_add)(struct ndmsg *ndm, struct nlattr *tb[],
1268 * struct net_device *dev,
1269 * const unsigned char *addr, u16 vid, u16 flags,
1270 * struct netlink_ext_ack *extack);
1271 * Adds an FDB entry to dev for addr.
1272 * int (*ndo_fdb_del)(struct ndmsg *ndm, struct nlattr *tb[],
1273 * struct net_device *dev,
1274 * const unsigned char *addr, u16 vid)
1275 * Deletes the FDB entry from dev coresponding to addr.
1276 * int (*ndo_fdb_dump)(struct sk_buff *skb, struct netlink_callback *cb,
1277 * struct net_device *dev, struct net_device *filter_dev,
1279 * Used to add FDB entries to dump requests. Implementers should add
1280 * entries to skb and update idx with the number of entries.
1282 * int (*ndo_bridge_setlink)(struct net_device *dev, struct nlmsghdr *nlh,
1283 * u16 flags, struct netlink_ext_ack *extack)
1284 * int (*ndo_bridge_getlink)(struct sk_buff *skb, u32 pid, u32 seq,
1285 * struct net_device *dev, u32 filter_mask,
1287 * int (*ndo_bridge_dellink)(struct net_device *dev, struct nlmsghdr *nlh,
1290 * int (*ndo_change_carrier)(struct net_device *dev, bool new_carrier);
1291 * Called to change device carrier. Soft-devices (like dummy, team, etc)
1292 * which do not represent real hardware may define this to allow their
1293 * userspace components to manage their virtual carrier state. Devices
1294 * that determine carrier state from physical hardware properties (eg
1295 * network cables) or protocol-dependent mechanisms (eg
1296 * USB_CDC_NOTIFY_NETWORK_CONNECTION) should NOT implement this function.
1298 * int (*ndo_get_phys_port_id)(struct net_device *dev,
1299 * struct netdev_phys_item_id *ppid);
1300 * Called to get ID of physical port of this device. If driver does
1301 * not implement this, it is assumed that the hw is not able to have
1302 * multiple net devices on single physical port.
1304 * int (*ndo_get_port_parent_id)(struct net_device *dev,
1305 * struct netdev_phys_item_id *ppid)
1306 * Called to get the parent ID of the physical port of this device.
1308 * void* (*ndo_dfwd_add_station)(struct net_device *pdev,
1309 * struct net_device *dev)
1310 * Called by upper layer devices to accelerate switching or other
1311 * station functionality into hardware. 'pdev is the lowerdev
1312 * to use for the offload and 'dev' is the net device that will
1313 * back the offload. Returns a pointer to the private structure
1314 * the upper layer will maintain.
1315 * void (*ndo_dfwd_del_station)(struct net_device *pdev, void *priv)
1316 * Called by upper layer device to delete the station created
1317 * by 'ndo_dfwd_add_station'. 'pdev' is the net device backing
1318 * the station and priv is the structure returned by the add
1320 * int (*ndo_set_tx_maxrate)(struct net_device *dev,
1321 * int queue_index, u32 maxrate);
1322 * Called when a user wants to set a max-rate limitation of specific
1324 * int (*ndo_get_iflink)(const struct net_device *dev);
1325 * Called to get the iflink value of this device.
1326 * void (*ndo_change_proto_down)(struct net_device *dev,
1328 * This function is used to pass protocol port error state information
1329 * to the switch driver. The switch driver can react to the proto_down
1330 * by doing a phys down on the associated switch port.
1331 * int (*ndo_fill_metadata_dst)(struct net_device *dev, struct sk_buff *skb);
1332 * This function is used to get egress tunnel information for given skb.
1333 * This is useful for retrieving outer tunnel header parameters while
1335 * void (*ndo_set_rx_headroom)(struct net_device *dev, int needed_headroom);
1336 * This function is used to specify the headroom that the skb must
1337 * consider when allocation skb during packet reception. Setting
1338 * appropriate rx headroom value allows avoiding skb head copy on
1339 * forward. Setting a negative value resets the rx headroom to the
1341 * int (*ndo_bpf)(struct net_device *dev, struct netdev_bpf *bpf);
1342 * This function is used to set or query state related to XDP on the
1343 * netdevice and manage BPF offload. See definition of
1344 * enum bpf_netdev_command for details.
1345 * int (*ndo_xdp_xmit)(struct net_device *dev, int n, struct xdp_frame **xdp,
1347 * This function is used to submit @n XDP packets for transmit on a
1348 * netdevice. Returns number of frames successfully transmitted, frames
1349 * that got dropped are freed/returned via xdp_return_frame().
1350 * Returns negative number, means general error invoking ndo, meaning
1351 * no frames were xmit'ed and core-caller will free all frames.
1352 * struct net_device *(*ndo_xdp_get_xmit_slave)(struct net_device *dev,
1353 * struct xdp_buff *xdp);
1354 * Get the xmit slave of master device based on the xdp_buff.
1355 * int (*ndo_xsk_wakeup)(struct net_device *dev, u32 queue_id, u32 flags);
1356 * This function is used to wake up the softirq, ksoftirqd or kthread
1357 * responsible for sending and/or receiving packets on a specific
1358 * queue id bound to an AF_XDP socket. The flags field specifies if
1359 * only RX, only Tx, or both should be woken up using the flags
1360 * XDP_WAKEUP_RX and XDP_WAKEUP_TX.
1361 * struct devlink_port *(*ndo_get_devlink_port)(struct net_device *dev);
1362 * Get devlink port instance associated with a given netdev.
1363 * Called with a reference on the netdevice and devlink locks only,
1364 * rtnl_lock is not held.
1365 * int (*ndo_tunnel_ctl)(struct net_device *dev, struct ip_tunnel_parm *p,
1367 * Add, change, delete or get information on an IPv4 tunnel.
1368 * struct net_device *(*ndo_get_peer_dev)(struct net_device *dev);
1369 * If a device is paired with a peer device, return the peer instance.
1370 * The caller must be under RCU read context.
1371 * int (*ndo_fill_forward_path)(struct net_device_path_ctx *ctx, struct net_device_path *path);
1372 * Get the forwarding path to reach the real device from the HW destination address
1374 struct net_device_ops {
1375 int (*ndo_init)(struct net_device *dev);
1376 void (*ndo_uninit)(struct net_device *dev);
1377 int (*ndo_open)(struct net_device *dev);
1378 int (*ndo_stop)(struct net_device *dev);
1379 netdev_tx_t (*ndo_start_xmit)(struct sk_buff *skb,
1380 struct net_device *dev);
1381 netdev_features_t (*ndo_features_check)(struct sk_buff *skb,
1382 struct net_device *dev,
1383 netdev_features_t features);
1384 u16 (*ndo_select_queue)(struct net_device *dev,
1385 struct sk_buff *skb,
1386 struct net_device *sb_dev);
1387 void (*ndo_change_rx_flags)(struct net_device *dev,
1389 void (*ndo_set_rx_mode)(struct net_device *dev);
1390 int (*ndo_set_mac_address)(struct net_device *dev,
1392 int (*ndo_validate_addr)(struct net_device *dev);
1393 int (*ndo_do_ioctl)(struct net_device *dev,
1394 struct ifreq *ifr, int cmd);
1395 int (*ndo_eth_ioctl)(struct net_device *dev,
1396 struct ifreq *ifr, int cmd);
1397 int (*ndo_siocbond)(struct net_device *dev,
1398 struct ifreq *ifr, int cmd);
1399 int (*ndo_siocwandev)(struct net_device *dev,
1400 struct if_settings *ifs);
1401 int (*ndo_siocdevprivate)(struct net_device *dev,
1403 void __user *data, int cmd);
1404 int (*ndo_set_config)(struct net_device *dev,
1406 int (*ndo_change_mtu)(struct net_device *dev,
1408 int (*ndo_neigh_setup)(struct net_device *dev,
1409 struct neigh_parms *);
1410 void (*ndo_tx_timeout) (struct net_device *dev,
1411 unsigned int txqueue);
1413 void (*ndo_get_stats64)(struct net_device *dev,
1414 struct rtnl_link_stats64 *storage);
1415 bool (*ndo_has_offload_stats)(const struct net_device *dev, int attr_id);
1416 int (*ndo_get_offload_stats)(int attr_id,
1417 const struct net_device *dev,
1419 struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
1421 int (*ndo_vlan_rx_add_vid)(struct net_device *dev,
1422 __be16 proto, u16 vid);
1423 int (*ndo_vlan_rx_kill_vid)(struct net_device *dev,
1424 __be16 proto, u16 vid);
1425 #ifdef CONFIG_NET_POLL_CONTROLLER
1426 void (*ndo_poll_controller)(struct net_device *dev);
1427 int (*ndo_netpoll_setup)(struct net_device *dev,
1428 struct netpoll_info *info);
1429 void (*ndo_netpoll_cleanup)(struct net_device *dev);
1431 int (*ndo_set_vf_mac)(struct net_device *dev,
1432 int queue, u8 *mac);
1433 int (*ndo_set_vf_vlan)(struct net_device *dev,
1434 int queue, u16 vlan,
1435 u8 qos, __be16 proto);
1436 int (*ndo_set_vf_rate)(struct net_device *dev,
1437 int vf, int min_tx_rate,
1439 int (*ndo_set_vf_spoofchk)(struct net_device *dev,
1440 int vf, bool setting);
1441 int (*ndo_set_vf_trust)(struct net_device *dev,
1442 int vf, bool setting);
1443 int (*ndo_get_vf_config)(struct net_device *dev,
1445 struct ifla_vf_info *ivf);
1446 int (*ndo_set_vf_link_state)(struct net_device *dev,
1447 int vf, int link_state);
1448 int (*ndo_get_vf_stats)(struct net_device *dev,
1450 struct ifla_vf_stats
1452 int (*ndo_set_vf_port)(struct net_device *dev,
1454 struct nlattr *port[]);
1455 int (*ndo_get_vf_port)(struct net_device *dev,
1456 int vf, struct sk_buff *skb);
1457 int (*ndo_get_vf_guid)(struct net_device *dev,
1459 struct ifla_vf_guid *node_guid,
1460 struct ifla_vf_guid *port_guid);
1461 int (*ndo_set_vf_guid)(struct net_device *dev,
1464 int (*ndo_set_vf_rss_query_en)(
1465 struct net_device *dev,
1466 int vf, bool setting);
1467 int (*ndo_setup_tc)(struct net_device *dev,
1468 enum tc_setup_type type,
1470 #if IS_ENABLED(CONFIG_FCOE)
1471 int (*ndo_fcoe_enable)(struct net_device *dev);
1472 int (*ndo_fcoe_disable)(struct net_device *dev);
1473 int (*ndo_fcoe_ddp_setup)(struct net_device *dev,
1475 struct scatterlist *sgl,
1477 int (*ndo_fcoe_ddp_done)(struct net_device *dev,
1479 int (*ndo_fcoe_ddp_target)(struct net_device *dev,
1481 struct scatterlist *sgl,
1483 int (*ndo_fcoe_get_hbainfo)(struct net_device *dev,
1484 struct netdev_fcoe_hbainfo *hbainfo);
1487 #if IS_ENABLED(CONFIG_LIBFCOE)
1488 #define NETDEV_FCOE_WWNN 0
1489 #define NETDEV_FCOE_WWPN 1
1490 int (*ndo_fcoe_get_wwn)(struct net_device *dev,
1491 u64 *wwn, int type);
1494 #ifdef CONFIG_RFS_ACCEL
1495 int (*ndo_rx_flow_steer)(struct net_device *dev,
1496 const struct sk_buff *skb,
1500 int (*ndo_add_slave)(struct net_device *dev,
1501 struct net_device *slave_dev,
1502 struct netlink_ext_ack *extack);
1503 int (*ndo_del_slave)(struct net_device *dev,
1504 struct net_device *slave_dev);
1505 struct net_device* (*ndo_get_xmit_slave)(struct net_device *dev,
1506 struct sk_buff *skb,
1508 struct net_device* (*ndo_sk_get_lower_dev)(struct net_device *dev,
1510 netdev_features_t (*ndo_fix_features)(struct net_device *dev,
1511 netdev_features_t features);
1512 int (*ndo_set_features)(struct net_device *dev,
1513 netdev_features_t features);
1514 int (*ndo_neigh_construct)(struct net_device *dev,
1515 struct neighbour *n);
1516 void (*ndo_neigh_destroy)(struct net_device *dev,
1517 struct neighbour *n);
1519 int (*ndo_fdb_add)(struct ndmsg *ndm,
1520 struct nlattr *tb[],
1521 struct net_device *dev,
1522 const unsigned char *addr,
1525 struct netlink_ext_ack *extack);
1526 int (*ndo_fdb_del)(struct ndmsg *ndm,
1527 struct nlattr *tb[],
1528 struct net_device *dev,
1529 const unsigned char *addr,
1531 int (*ndo_fdb_dump)(struct sk_buff *skb,
1532 struct netlink_callback *cb,
1533 struct net_device *dev,
1534 struct net_device *filter_dev,
1536 int (*ndo_fdb_get)(struct sk_buff *skb,
1537 struct nlattr *tb[],
1538 struct net_device *dev,
1539 const unsigned char *addr,
1540 u16 vid, u32 portid, u32 seq,
1541 struct netlink_ext_ack *extack);
1542 int (*ndo_bridge_setlink)(struct net_device *dev,
1543 struct nlmsghdr *nlh,
1545 struct netlink_ext_ack *extack);
1546 int (*ndo_bridge_getlink)(struct sk_buff *skb,
1548 struct net_device *dev,
1551 int (*ndo_bridge_dellink)(struct net_device *dev,
1552 struct nlmsghdr *nlh,
1554 int (*ndo_change_carrier)(struct net_device *dev,
1556 int (*ndo_get_phys_port_id)(struct net_device *dev,
1557 struct netdev_phys_item_id *ppid);
1558 int (*ndo_get_port_parent_id)(struct net_device *dev,
1559 struct netdev_phys_item_id *ppid);
1560 int (*ndo_get_phys_port_name)(struct net_device *dev,
1561 char *name, size_t len);
1562 void* (*ndo_dfwd_add_station)(struct net_device *pdev,
1563 struct net_device *dev);
1564 void (*ndo_dfwd_del_station)(struct net_device *pdev,
1567 int (*ndo_set_tx_maxrate)(struct net_device *dev,
1570 int (*ndo_get_iflink)(const struct net_device *dev);
1571 int (*ndo_change_proto_down)(struct net_device *dev,
1573 int (*ndo_fill_metadata_dst)(struct net_device *dev,
1574 struct sk_buff *skb);
1575 void (*ndo_set_rx_headroom)(struct net_device *dev,
1576 int needed_headroom);
1577 int (*ndo_bpf)(struct net_device *dev,
1578 struct netdev_bpf *bpf);
1579 int (*ndo_xdp_xmit)(struct net_device *dev, int n,
1580 struct xdp_frame **xdp,
1582 struct net_device * (*ndo_xdp_get_xmit_slave)(struct net_device *dev,
1583 struct xdp_buff *xdp);
1584 int (*ndo_xsk_wakeup)(struct net_device *dev,
1585 u32 queue_id, u32 flags);
1586 struct devlink_port * (*ndo_get_devlink_port)(struct net_device *dev);
1587 int (*ndo_tunnel_ctl)(struct net_device *dev,
1588 struct ip_tunnel_parm *p, int cmd);
1589 struct net_device * (*ndo_get_peer_dev)(struct net_device *dev);
1590 int (*ndo_fill_forward_path)(struct net_device_path_ctx *ctx,
1591 struct net_device_path *path);
1595 * enum netdev_priv_flags - &struct net_device priv_flags
1597 * These are the &struct net_device, they are only set internally
1598 * by drivers and used in the kernel. These flags are invisible to
1599 * userspace; this means that the order of these flags can change
1600 * during any kernel release.
1602 * You should have a pretty good reason to be extending these flags.
1604 * @IFF_802_1Q_VLAN: 802.1Q VLAN device
1605 * @IFF_EBRIDGE: Ethernet bridging device
1606 * @IFF_BONDING: bonding master or slave
1607 * @IFF_ISATAP: ISATAP interface (RFC4214)
1608 * @IFF_WAN_HDLC: WAN HDLC device
1609 * @IFF_XMIT_DST_RELEASE: dev_hard_start_xmit() is allowed to
1611 * @IFF_DONT_BRIDGE: disallow bridging this ether dev
1612 * @IFF_DISABLE_NETPOLL: disable netpoll at run-time
1613 * @IFF_MACVLAN_PORT: device used as macvlan port
1614 * @IFF_BRIDGE_PORT: device used as bridge port
1615 * @IFF_OVS_DATAPATH: device used as Open vSwitch datapath port
1616 * @IFF_TX_SKB_SHARING: The interface supports sharing skbs on transmit
1617 * @IFF_UNICAST_FLT: Supports unicast filtering
1618 * @IFF_TEAM_PORT: device used as team port
1619 * @IFF_SUPP_NOFCS: device supports sending custom FCS
1620 * @IFF_LIVE_ADDR_CHANGE: device supports hardware address
1621 * change when it's running
1622 * @IFF_MACVLAN: Macvlan device
1623 * @IFF_XMIT_DST_RELEASE_PERM: IFF_XMIT_DST_RELEASE not taking into account
1624 * underlying stacked devices
1625 * @IFF_L3MDEV_MASTER: device is an L3 master device
1626 * @IFF_NO_QUEUE: device can run without qdisc attached
1627 * @IFF_OPENVSWITCH: device is a Open vSwitch master
1628 * @IFF_L3MDEV_SLAVE: device is enslaved to an L3 master device
1629 * @IFF_TEAM: device is a team device
1630 * @IFF_RXFH_CONFIGURED: device has had Rx Flow indirection table configured
1631 * @IFF_PHONY_HEADROOM: the headroom value is controlled by an external
1632 * entity (i.e. the master device for bridged veth)
1633 * @IFF_MACSEC: device is a MACsec device
1634 * @IFF_NO_RX_HANDLER: device doesn't support the rx_handler hook
1635 * @IFF_FAILOVER: device is a failover master device
1636 * @IFF_FAILOVER_SLAVE: device is lower dev of a failover master device
1637 * @IFF_L3MDEV_RX_HANDLER: only invoke the rx handler of L3 master device
1638 * @IFF_LIVE_RENAME_OK: rename is allowed while device is up and running
1639 * @IFF_TX_SKB_NO_LINEAR: device/driver is capable of xmitting frames with
1640 * skb_headlen(skb) == 0 (data starts from frag0)
1642 enum netdev_priv_flags {
1643 IFF_802_1Q_VLAN = 1<<0,
1647 IFF_WAN_HDLC = 1<<4,
1648 IFF_XMIT_DST_RELEASE = 1<<5,
1649 IFF_DONT_BRIDGE = 1<<6,
1650 IFF_DISABLE_NETPOLL = 1<<7,
1651 IFF_MACVLAN_PORT = 1<<8,
1652 IFF_BRIDGE_PORT = 1<<9,
1653 IFF_OVS_DATAPATH = 1<<10,
1654 IFF_TX_SKB_SHARING = 1<<11,
1655 IFF_UNICAST_FLT = 1<<12,
1656 IFF_TEAM_PORT = 1<<13,
1657 IFF_SUPP_NOFCS = 1<<14,
1658 IFF_LIVE_ADDR_CHANGE = 1<<15,
1659 IFF_MACVLAN = 1<<16,
1660 IFF_XMIT_DST_RELEASE_PERM = 1<<17,
1661 IFF_L3MDEV_MASTER = 1<<18,
1662 IFF_NO_QUEUE = 1<<19,
1663 IFF_OPENVSWITCH = 1<<20,
1664 IFF_L3MDEV_SLAVE = 1<<21,
1666 IFF_RXFH_CONFIGURED = 1<<23,
1667 IFF_PHONY_HEADROOM = 1<<24,
1669 IFF_NO_RX_HANDLER = 1<<26,
1670 IFF_FAILOVER = 1<<27,
1671 IFF_FAILOVER_SLAVE = 1<<28,
1672 IFF_L3MDEV_RX_HANDLER = 1<<29,
1673 IFF_LIVE_RENAME_OK = 1<<30,
1674 IFF_TX_SKB_NO_LINEAR = BIT_ULL(31),
1677 #define IFF_802_1Q_VLAN IFF_802_1Q_VLAN
1678 #define IFF_EBRIDGE IFF_EBRIDGE
1679 #define IFF_BONDING IFF_BONDING
1680 #define IFF_ISATAP IFF_ISATAP
1681 #define IFF_WAN_HDLC IFF_WAN_HDLC
1682 #define IFF_XMIT_DST_RELEASE IFF_XMIT_DST_RELEASE
1683 #define IFF_DONT_BRIDGE IFF_DONT_BRIDGE
1684 #define IFF_DISABLE_NETPOLL IFF_DISABLE_NETPOLL
1685 #define IFF_MACVLAN_PORT IFF_MACVLAN_PORT
1686 #define IFF_BRIDGE_PORT IFF_BRIDGE_PORT
1687 #define IFF_OVS_DATAPATH IFF_OVS_DATAPATH
1688 #define IFF_TX_SKB_SHARING IFF_TX_SKB_SHARING
1689 #define IFF_UNICAST_FLT IFF_UNICAST_FLT
1690 #define IFF_TEAM_PORT IFF_TEAM_PORT
1691 #define IFF_SUPP_NOFCS IFF_SUPP_NOFCS
1692 #define IFF_LIVE_ADDR_CHANGE IFF_LIVE_ADDR_CHANGE
1693 #define IFF_MACVLAN IFF_MACVLAN
1694 #define IFF_XMIT_DST_RELEASE_PERM IFF_XMIT_DST_RELEASE_PERM
1695 #define IFF_L3MDEV_MASTER IFF_L3MDEV_MASTER
1696 #define IFF_NO_QUEUE IFF_NO_QUEUE
1697 #define IFF_OPENVSWITCH IFF_OPENVSWITCH
1698 #define IFF_L3MDEV_SLAVE IFF_L3MDEV_SLAVE
1699 #define IFF_TEAM IFF_TEAM
1700 #define IFF_RXFH_CONFIGURED IFF_RXFH_CONFIGURED
1701 #define IFF_PHONY_HEADROOM IFF_PHONY_HEADROOM
1702 #define IFF_MACSEC IFF_MACSEC
1703 #define IFF_NO_RX_HANDLER IFF_NO_RX_HANDLER
1704 #define IFF_FAILOVER IFF_FAILOVER
1705 #define IFF_FAILOVER_SLAVE IFF_FAILOVER_SLAVE
1706 #define IFF_L3MDEV_RX_HANDLER IFF_L3MDEV_RX_HANDLER
1707 #define IFF_LIVE_RENAME_OK IFF_LIVE_RENAME_OK
1708 #define IFF_TX_SKB_NO_LINEAR IFF_TX_SKB_NO_LINEAR
1710 /* Specifies the type of the struct net_device::ml_priv pointer */
1711 enum netdev_ml_priv_type {
1717 * struct net_device - The DEVICE structure.
1719 * Actually, this whole structure is a big mistake. It mixes I/O
1720 * data with strictly "high-level" data, and it has to know about
1721 * almost every data structure used in the INET module.
1723 * @name: This is the first field of the "visible" part of this structure
1724 * (i.e. as seen by users in the "Space.c" file). It is the name
1727 * @name_node: Name hashlist node
1728 * @ifalias: SNMP alias
1729 * @mem_end: Shared memory end
1730 * @mem_start: Shared memory start
1731 * @base_addr: Device I/O address
1732 * @irq: Device IRQ number
1734 * @state: Generic network queuing layer state, see netdev_state_t
1735 * @dev_list: The global list of network devices
1736 * @napi_list: List entry used for polling NAPI devices
1737 * @unreg_list: List entry when we are unregistering the
1738 * device; see the function unregister_netdev
1739 * @close_list: List entry used when we are closing the device
1740 * @ptype_all: Device-specific packet handlers for all protocols
1741 * @ptype_specific: Device-specific, protocol-specific packet handlers
1743 * @adj_list: Directly linked devices, like slaves for bonding
1744 * @features: Currently active device features
1745 * @hw_features: User-changeable features
1747 * @wanted_features: User-requested features
1748 * @vlan_features: Mask of features inheritable by VLAN devices
1750 * @hw_enc_features: Mask of features inherited by encapsulating devices
1751 * This field indicates what encapsulation
1752 * offloads the hardware is capable of doing,
1753 * and drivers will need to set them appropriately.
1755 * @mpls_features: Mask of features inheritable by MPLS
1756 * @gso_partial_features: value(s) from NETIF_F_GSO\*
1758 * @ifindex: interface index
1759 * @group: The group the device belongs to
1761 * @stats: Statistics struct, which was left as a legacy, use
1762 * rtnl_link_stats64 instead
1764 * @rx_dropped: Dropped packets by core network,
1765 * do not use this in drivers
1766 * @tx_dropped: Dropped packets by core network,
1767 * do not use this in drivers
1768 * @rx_nohandler: nohandler dropped packets by core network on
1769 * inactive devices, do not use this in drivers
1770 * @carrier_up_count: Number of times the carrier has been up
1771 * @carrier_down_count: Number of times the carrier has been down
1773 * @wireless_handlers: List of functions to handle Wireless Extensions,
1775 * see <net/iw_handler.h> for details.
1776 * @wireless_data: Instance data managed by the core of wireless extensions
1778 * @netdev_ops: Includes several pointers to callbacks,
1779 * if one wants to override the ndo_*() functions
1780 * @ethtool_ops: Management operations
1781 * @l3mdev_ops: Layer 3 master device operations
1782 * @ndisc_ops: Includes callbacks for different IPv6 neighbour
1783 * discovery handling. Necessary for e.g. 6LoWPAN.
1784 * @xfrmdev_ops: Transformation offload operations
1785 * @tlsdev_ops: Transport Layer Security offload operations
1786 * @header_ops: Includes callbacks for creating,parsing,caching,etc
1787 * of Layer 2 headers.
1789 * @flags: Interface flags (a la BSD)
1790 * @priv_flags: Like 'flags' but invisible to userspace,
1791 * see if.h for the definitions
1792 * @gflags: Global flags ( kept as legacy )
1793 * @padded: How much padding added by alloc_netdev()
1794 * @operstate: RFC2863 operstate
1795 * @link_mode: Mapping policy to operstate
1796 * @if_port: Selectable AUI, TP, ...
1798 * @mtu: Interface MTU value
1799 * @min_mtu: Interface Minimum MTU value
1800 * @max_mtu: Interface Maximum MTU value
1801 * @type: Interface hardware type
1802 * @hard_header_len: Maximum hardware header length.
1803 * @min_header_len: Minimum hardware header length
1805 * @needed_headroom: Extra headroom the hardware may need, but not in all
1806 * cases can this be guaranteed
1807 * @needed_tailroom: Extra tailroom the hardware may need, but not in all
1808 * cases can this be guaranteed. Some cases also use
1809 * LL_MAX_HEADER instead to allocate the skb
1811 * interface address info:
1813 * @perm_addr: Permanent hw address
1814 * @addr_assign_type: Hw address assignment type
1815 * @addr_len: Hardware address length
1816 * @upper_level: Maximum depth level of upper devices.
1817 * @lower_level: Maximum depth level of lower devices.
1818 * @neigh_priv_len: Used in neigh_alloc()
1819 * @dev_id: Used to differentiate devices that share
1820 * the same link layer address
1821 * @dev_port: Used to differentiate devices that share
1823 * @addr_list_lock: XXX: need comments on this one
1824 * @name_assign_type: network interface name assignment type
1825 * @uc_promisc: Counter that indicates promiscuous mode
1826 * has been enabled due to the need to listen to
1827 * additional unicast addresses in a device that
1828 * does not implement ndo_set_rx_mode()
1829 * @uc: unicast mac addresses
1830 * @mc: multicast mac addresses
1831 * @dev_addrs: list of device hw addresses
1832 * @queues_kset: Group of all Kobjects in the Tx and RX queues
1833 * @promiscuity: Number of times the NIC is told to work in
1834 * promiscuous mode; if it becomes 0 the NIC will
1835 * exit promiscuous mode
1836 * @allmulti: Counter, enables or disables allmulticast mode
1838 * @vlan_info: VLAN info
1839 * @dsa_ptr: dsa specific data
1840 * @tipc_ptr: TIPC specific data
1841 * @atalk_ptr: AppleTalk link
1842 * @ip_ptr: IPv4 specific data
1843 * @ip6_ptr: IPv6 specific data
1844 * @ax25_ptr: AX.25 specific data
1845 * @ieee80211_ptr: IEEE 802.11 specific data, assign before registering
1846 * @ieee802154_ptr: IEEE 802.15.4 low-rate Wireless Personal Area Network
1848 * @mpls_ptr: mpls_dev struct pointer
1849 * @mctp_ptr: MCTP specific data
1851 * @dev_addr: Hw address (before bcast,
1852 * because most packets are unicast)
1854 * @_rx: Array of RX queues
1855 * @num_rx_queues: Number of RX queues
1856 * allocated at register_netdev() time
1857 * @real_num_rx_queues: Number of RX queues currently active in device
1858 * @xdp_prog: XDP sockets filter program pointer
1859 * @gro_flush_timeout: timeout for GRO layer in NAPI
1860 * @napi_defer_hard_irqs: If not zero, provides a counter that would
1861 * allow to avoid NIC hard IRQ, on busy queues.
1863 * @rx_handler: handler for received packets
1864 * @rx_handler_data: XXX: need comments on this one
1865 * @miniq_ingress: ingress/clsact qdisc specific data for
1866 * ingress processing
1867 * @ingress_queue: XXX: need comments on this one
1868 * @nf_hooks_ingress: netfilter hooks executed for ingress packets
1869 * @broadcast: hw bcast address
1871 * @rx_cpu_rmap: CPU reverse-mapping for RX completion interrupts,
1872 * indexed by RX queue number. Assigned by driver.
1873 * This must only be set if the ndo_rx_flow_steer
1874 * operation is defined
1875 * @index_hlist: Device index hash chain
1877 * @_tx: Array of TX queues
1878 * @num_tx_queues: Number of TX queues allocated at alloc_netdev_mq() time
1879 * @real_num_tx_queues: Number of TX queues currently active in device
1880 * @qdisc: Root qdisc from userspace point of view
1881 * @tx_queue_len: Max frames per queue allowed
1882 * @tx_global_lock: XXX: need comments on this one
1883 * @xdp_bulkq: XDP device bulk queue
1884 * @xps_maps: all CPUs/RXQs maps for XPS device
1886 * @xps_maps: XXX: need comments on this one
1887 * @miniq_egress: clsact qdisc specific data for
1889 * @qdisc_hash: qdisc hash table
1890 * @watchdog_timeo: Represents the timeout that is used by
1891 * the watchdog (see dev_watchdog())
1892 * @watchdog_timer: List of timers
1894 * @proto_down_reason: reason a netdev interface is held down
1895 * @pcpu_refcnt: Number of references to this device
1896 * @dev_refcnt: Number of references to this device
1897 * @todo_list: Delayed register/unregister
1898 * @link_watch_list: XXX: need comments on this one
1900 * @reg_state: Register/unregister state machine
1901 * @dismantle: Device is going to be freed
1902 * @rtnl_link_state: This enum represents the phases of creating
1905 * @needs_free_netdev: Should unregister perform free_netdev?
1906 * @priv_destructor: Called from unregister
1907 * @npinfo: XXX: need comments on this one
1908 * @nd_net: Network namespace this network device is inside
1910 * @ml_priv: Mid-layer private
1911 * @ml_priv_type: Mid-layer private type
1912 * @lstats: Loopback statistics
1913 * @tstats: Tunnel statistics
1914 * @dstats: Dummy statistics
1915 * @vstats: Virtual ethernet statistics
1920 * @dev: Class/net/name entry
1921 * @sysfs_groups: Space for optional device, statistics and wireless
1924 * @sysfs_rx_queue_group: Space for optional per-rx queue attributes
1925 * @rtnl_link_ops: Rtnl_link_ops
1927 * @gso_max_size: Maximum size of generic segmentation offload
1928 * @gso_max_segs: Maximum number of segments that can be passed to the
1931 * @dcbnl_ops: Data Center Bridging netlink ops
1932 * @num_tc: Number of traffic classes in the net device
1933 * @tc_to_txq: XXX: need comments on this one
1934 * @prio_tc_map: XXX: need comments on this one
1936 * @fcoe_ddp_xid: Max exchange id for FCoE LRO by ddp
1938 * @priomap: XXX: need comments on this one
1939 * @phydev: Physical device may attach itself
1940 * for hardware timestamping
1941 * @sfp_bus: attached &struct sfp_bus structure.
1943 * @qdisc_tx_busylock: lockdep class annotating Qdisc->busylock spinlock
1944 * @qdisc_running_key: lockdep class annotating Qdisc->running seqcount
1946 * @proto_down: protocol port state information can be sent to the
1947 * switch driver and used to set the phys state of the
1950 * @wol_enabled: Wake-on-LAN is enabled
1952 * @threaded: napi threaded mode is enabled
1954 * @net_notifier_list: List of per-net netdev notifier block
1955 * that follow this device when it is moved
1956 * to another network namespace.
1958 * @macsec_ops: MACsec offloading ops
1960 * @udp_tunnel_nic_info: static structure describing the UDP tunnel
1961 * offload capabilities of the device
1962 * @udp_tunnel_nic: UDP tunnel offload state
1963 * @xdp_state: stores info on attached XDP BPF programs
1965 * @nested_level: Used as as a parameter of spin_lock_nested() of
1966 * dev->addr_list_lock.
1967 * @unlink_list: As netif_addr_lock() can be called recursively,
1968 * keep a list of interfaces to be deleted.
1970 * FIXME: cleanup struct net_device such that network protocol info
1975 char name[IFNAMSIZ];
1976 struct netdev_name_node *name_node;
1977 struct dev_ifalias __rcu *ifalias;
1979 * I/O specific fields
1980 * FIXME: Merge these and struct ifmap into one
1982 unsigned long mem_end;
1983 unsigned long mem_start;
1984 unsigned long base_addr;
1987 * Some hardware also needs these fields (state,dev_list,
1988 * napi_list,unreg_list,close_list) but they are not
1989 * part of the usual set specified in Space.c.
1992 unsigned long state;
1994 struct list_head dev_list;
1995 struct list_head napi_list;
1996 struct list_head unreg_list;
1997 struct list_head close_list;
1998 struct list_head ptype_all;
1999 struct list_head ptype_specific;
2002 struct list_head upper;
2003 struct list_head lower;
2006 /* Read-mostly cache-line for fast-path access */
2008 unsigned int priv_flags;
2009 const struct net_device_ops *netdev_ops;
2011 unsigned short gflags;
2012 unsigned short hard_header_len;
2014 /* Note : dev->mtu is often read without holding a lock.
2015 * Writers usually hold RTNL.
2016 * It is recommended to use READ_ONCE() to annotate the reads,
2017 * and to use WRITE_ONCE() to annotate the writes.
2020 unsigned short needed_headroom;
2021 unsigned short needed_tailroom;
2023 netdev_features_t features;
2024 netdev_features_t hw_features;
2025 netdev_features_t wanted_features;
2026 netdev_features_t vlan_features;
2027 netdev_features_t hw_enc_features;
2028 netdev_features_t mpls_features;
2029 netdev_features_t gso_partial_features;
2031 unsigned int min_mtu;
2032 unsigned int max_mtu;
2033 unsigned short type;
2034 unsigned char min_header_len;
2035 unsigned char name_assign_type;
2039 struct net_device_stats stats; /* not used by modern drivers */
2041 atomic_long_t rx_dropped;
2042 atomic_long_t tx_dropped;
2043 atomic_long_t rx_nohandler;
2045 /* Stats to monitor link on/off, flapping */
2046 atomic_t carrier_up_count;
2047 atomic_t carrier_down_count;
2049 #ifdef CONFIG_WIRELESS_EXT
2050 const struct iw_handler_def *wireless_handlers;
2051 struct iw_public_data *wireless_data;
2053 const struct ethtool_ops *ethtool_ops;
2054 #ifdef CONFIG_NET_L3_MASTER_DEV
2055 const struct l3mdev_ops *l3mdev_ops;
2057 #if IS_ENABLED(CONFIG_IPV6)
2058 const struct ndisc_ops *ndisc_ops;
2061 #ifdef CONFIG_XFRM_OFFLOAD
2062 const struct xfrmdev_ops *xfrmdev_ops;
2065 #if IS_ENABLED(CONFIG_TLS_DEVICE)
2066 const struct tlsdev_ops *tlsdev_ops;
2069 const struct header_ops *header_ops;
2071 unsigned char operstate;
2072 unsigned char link_mode;
2074 unsigned char if_port;
2077 /* Interface address info. */
2078 unsigned char perm_addr[MAX_ADDR_LEN];
2079 unsigned char addr_assign_type;
2080 unsigned char addr_len;
2081 unsigned char upper_level;
2082 unsigned char lower_level;
2084 unsigned short neigh_priv_len;
2085 unsigned short dev_id;
2086 unsigned short dev_port;
2087 unsigned short padded;
2089 spinlock_t addr_list_lock;
2092 struct netdev_hw_addr_list uc;
2093 struct netdev_hw_addr_list mc;
2094 struct netdev_hw_addr_list dev_addrs;
2097 struct kset *queues_kset;
2099 #ifdef CONFIG_LOCKDEP
2100 struct list_head unlink_list;
2102 unsigned int promiscuity;
2103 unsigned int allmulti;
2105 #ifdef CONFIG_LOCKDEP
2106 unsigned char nested_level;
2110 /* Protocol-specific pointers */
2112 #if IS_ENABLED(CONFIG_VLAN_8021Q)
2113 struct vlan_info __rcu *vlan_info;
2115 #if IS_ENABLED(CONFIG_NET_DSA)
2116 struct dsa_port *dsa_ptr;
2118 #if IS_ENABLED(CONFIG_TIPC)
2119 struct tipc_bearer __rcu *tipc_ptr;
2121 #if IS_ENABLED(CONFIG_IRDA) || IS_ENABLED(CONFIG_ATALK)
2124 struct in_device __rcu *ip_ptr;
2125 struct inet6_dev __rcu *ip6_ptr;
2126 #if IS_ENABLED(CONFIG_AX25)
2129 struct wireless_dev *ieee80211_ptr;
2130 struct wpan_dev *ieee802154_ptr;
2131 #if IS_ENABLED(CONFIG_MPLS_ROUTING)
2132 struct mpls_dev __rcu *mpls_ptr;
2134 #if IS_ENABLED(CONFIG_MCTP)
2135 struct mctp_dev __rcu *mctp_ptr;
2139 * Cache lines mostly used on receive path (including eth_type_trans())
2141 /* Interface address info used in eth_type_trans() */
2142 unsigned char *dev_addr;
2144 struct netdev_rx_queue *_rx;
2145 unsigned int num_rx_queues;
2146 unsigned int real_num_rx_queues;
2148 struct bpf_prog __rcu *xdp_prog;
2149 unsigned long gro_flush_timeout;
2150 int napi_defer_hard_irqs;
2151 rx_handler_func_t __rcu *rx_handler;
2152 void __rcu *rx_handler_data;
2154 #ifdef CONFIG_NET_CLS_ACT
2155 struct mini_Qdisc __rcu *miniq_ingress;
2157 struct netdev_queue __rcu *ingress_queue;
2158 #ifdef CONFIG_NETFILTER_INGRESS
2159 struct nf_hook_entries __rcu *nf_hooks_ingress;
2162 unsigned char broadcast[MAX_ADDR_LEN];
2163 #ifdef CONFIG_RFS_ACCEL
2164 struct cpu_rmap *rx_cpu_rmap;
2166 struct hlist_node index_hlist;
2169 * Cache lines mostly used on transmit path
2171 struct netdev_queue *_tx ____cacheline_aligned_in_smp;
2172 unsigned int num_tx_queues;
2173 unsigned int real_num_tx_queues;
2174 struct Qdisc __rcu *qdisc;
2175 unsigned int tx_queue_len;
2176 spinlock_t tx_global_lock;
2178 struct xdp_dev_bulk_queue __percpu *xdp_bulkq;
2181 struct xps_dev_maps __rcu *xps_maps[XPS_MAPS_MAX];
2183 #ifdef CONFIG_NET_CLS_ACT
2184 struct mini_Qdisc __rcu *miniq_egress;
2187 #ifdef CONFIG_NET_SCHED
2188 DECLARE_HASHTABLE (qdisc_hash, 4);
2190 /* These may be needed for future network-power-down code. */
2191 struct timer_list watchdog_timer;
2194 u32 proto_down_reason;
2196 struct list_head todo_list;
2198 #ifdef CONFIG_PCPU_DEV_REFCNT
2199 int __percpu *pcpu_refcnt;
2201 refcount_t dev_refcnt;
2204 struct list_head link_watch_list;
2206 enum { NETREG_UNINITIALIZED=0,
2207 NETREG_REGISTERED, /* completed register_netdevice */
2208 NETREG_UNREGISTERING, /* called unregister_netdevice */
2209 NETREG_UNREGISTERED, /* completed unregister todo */
2210 NETREG_RELEASED, /* called free_netdev */
2211 NETREG_DUMMY, /* dummy device for NAPI poll */
2217 RTNL_LINK_INITIALIZED,
2218 RTNL_LINK_INITIALIZING,
2219 } rtnl_link_state:16;
2221 bool needs_free_netdev;
2222 void (*priv_destructor)(struct net_device *dev);
2224 #ifdef CONFIG_NETPOLL
2225 struct netpoll_info __rcu *npinfo;
2228 possible_net_t nd_net;
2230 /* mid-layer private */
2232 enum netdev_ml_priv_type ml_priv_type;
2235 struct pcpu_lstats __percpu *lstats;
2236 struct pcpu_sw_netstats __percpu *tstats;
2237 struct pcpu_dstats __percpu *dstats;
2240 #if IS_ENABLED(CONFIG_GARP)
2241 struct garp_port __rcu *garp_port;
2243 #if IS_ENABLED(CONFIG_MRP)
2244 struct mrp_port __rcu *mrp_port;
2248 const struct attribute_group *sysfs_groups[4];
2249 const struct attribute_group *sysfs_rx_queue_group;
2251 const struct rtnl_link_ops *rtnl_link_ops;
2253 /* for setting kernel sock attribute on TCP connection setup */
2254 #define GSO_MAX_SIZE 65536
2255 unsigned int gso_max_size;
2256 #define GSO_MAX_SEGS 65535
2260 const struct dcbnl_rtnl_ops *dcbnl_ops;
2263 struct netdev_tc_txq tc_to_txq[TC_MAX_QUEUE];
2264 u8 prio_tc_map[TC_BITMASK + 1];
2266 #if IS_ENABLED(CONFIG_FCOE)
2267 unsigned int fcoe_ddp_xid;
2269 #if IS_ENABLED(CONFIG_CGROUP_NET_PRIO)
2270 struct netprio_map __rcu *priomap;
2272 struct phy_device *phydev;
2273 struct sfp_bus *sfp_bus;
2274 struct lock_class_key *qdisc_tx_busylock;
2275 struct lock_class_key *qdisc_running_key;
2277 unsigned wol_enabled:1;
2278 unsigned threaded:1;
2280 struct list_head net_notifier_list;
2282 #if IS_ENABLED(CONFIG_MACSEC)
2283 /* MACsec management functions */
2284 const struct macsec_ops *macsec_ops;
2286 const struct udp_tunnel_nic_info *udp_tunnel_nic_info;
2287 struct udp_tunnel_nic *udp_tunnel_nic;
2289 /* protected by rtnl_lock */
2290 struct bpf_xdp_entity xdp_state[__MAX_XDP_MODE];
2292 #define to_net_dev(d) container_of(d, struct net_device, dev)
2294 static inline bool netif_elide_gro(const struct net_device *dev)
2296 if (!(dev->features & NETIF_F_GRO) || dev->xdp_prog)
2301 #define NETDEV_ALIGN 32
2304 int netdev_get_prio_tc_map(const struct net_device *dev, u32 prio)
2306 return dev->prio_tc_map[prio & TC_BITMASK];
2310 int netdev_set_prio_tc_map(struct net_device *dev, u8 prio, u8 tc)
2312 if (tc >= dev->num_tc)
2315 dev->prio_tc_map[prio & TC_BITMASK] = tc & TC_BITMASK;
2319 int netdev_txq_to_tc(struct net_device *dev, unsigned int txq);
2320 void netdev_reset_tc(struct net_device *dev);
2321 int netdev_set_tc_queue(struct net_device *dev, u8 tc, u16 count, u16 offset);
2322 int netdev_set_num_tc(struct net_device *dev, u8 num_tc);
2325 int netdev_get_num_tc(struct net_device *dev)
2330 static inline void net_prefetch(void *p)
2333 #if L1_CACHE_BYTES < 128
2334 prefetch((u8 *)p + L1_CACHE_BYTES);
2338 static inline void net_prefetchw(void *p)
2341 #if L1_CACHE_BYTES < 128
2342 prefetchw((u8 *)p + L1_CACHE_BYTES);
2346 void netdev_unbind_sb_channel(struct net_device *dev,
2347 struct net_device *sb_dev);
2348 int netdev_bind_sb_channel_queue(struct net_device *dev,
2349 struct net_device *sb_dev,
2350 u8 tc, u16 count, u16 offset);
2351 int netdev_set_sb_channel(struct net_device *dev, u16 channel);
2352 static inline int netdev_get_sb_channel(struct net_device *dev)
2354 return max_t(int, -dev->num_tc, 0);
2358 struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev,
2361 return &dev->_tx[index];
2364 static inline struct netdev_queue *skb_get_tx_queue(const struct net_device *dev,
2365 const struct sk_buff *skb)
2367 return netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
2370 static inline void netdev_for_each_tx_queue(struct net_device *dev,
2371 void (*f)(struct net_device *,
2372 struct netdev_queue *,
2378 for (i = 0; i < dev->num_tx_queues; i++)
2379 f(dev, &dev->_tx[i], arg);
2382 #define netdev_lockdep_set_classes(dev) \
2384 static struct lock_class_key qdisc_tx_busylock_key; \
2385 static struct lock_class_key qdisc_running_key; \
2386 static struct lock_class_key qdisc_xmit_lock_key; \
2387 static struct lock_class_key dev_addr_list_lock_key; \
2390 (dev)->qdisc_tx_busylock = &qdisc_tx_busylock_key; \
2391 (dev)->qdisc_running_key = &qdisc_running_key; \
2392 lockdep_set_class(&(dev)->addr_list_lock, \
2393 &dev_addr_list_lock_key); \
2394 for (i = 0; i < (dev)->num_tx_queues; i++) \
2395 lockdep_set_class(&(dev)->_tx[i]._xmit_lock, \
2396 &qdisc_xmit_lock_key); \
2399 u16 netdev_pick_tx(struct net_device *dev, struct sk_buff *skb,
2400 struct net_device *sb_dev);
2401 struct netdev_queue *netdev_core_pick_tx(struct net_device *dev,
2402 struct sk_buff *skb,
2403 struct net_device *sb_dev);
2405 /* returns the headroom that the master device needs to take in account
2406 * when forwarding to this dev
2408 static inline unsigned netdev_get_fwd_headroom(struct net_device *dev)
2410 return dev->priv_flags & IFF_PHONY_HEADROOM ? 0 : dev->needed_headroom;
2413 static inline void netdev_set_rx_headroom(struct net_device *dev, int new_hr)
2415 if (dev->netdev_ops->ndo_set_rx_headroom)
2416 dev->netdev_ops->ndo_set_rx_headroom(dev, new_hr);
2419 /* set the device rx headroom to the dev's default */
2420 static inline void netdev_reset_rx_headroom(struct net_device *dev)
2422 netdev_set_rx_headroom(dev, -1);
2425 static inline void *netdev_get_ml_priv(struct net_device *dev,
2426 enum netdev_ml_priv_type type)
2428 if (dev->ml_priv_type != type)
2431 return dev->ml_priv;
2434 static inline void netdev_set_ml_priv(struct net_device *dev,
2436 enum netdev_ml_priv_type type)
2438 WARN(dev->ml_priv_type && dev->ml_priv_type != type,
2439 "Overwriting already set ml_priv_type (%u) with different ml_priv_type (%u)!\n",
2440 dev->ml_priv_type, type);
2441 WARN(!dev->ml_priv_type && dev->ml_priv,
2442 "Overwriting already set ml_priv and ml_priv_type is ML_PRIV_NONE!\n");
2444 dev->ml_priv = ml_priv;
2445 dev->ml_priv_type = type;
2449 * Net namespace inlines
2452 struct net *dev_net(const struct net_device *dev)
2454 return read_pnet(&dev->nd_net);
2458 void dev_net_set(struct net_device *dev, struct net *net)
2460 write_pnet(&dev->nd_net, net);
2464 * netdev_priv - access network device private data
2465 * @dev: network device
2467 * Get network device private data
2469 static inline void *netdev_priv(const struct net_device *dev)
2471 return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN);
2474 /* Set the sysfs physical device reference for the network logical device
2475 * if set prior to registration will cause a symlink during initialization.
2477 #define SET_NETDEV_DEV(net, pdev) ((net)->dev.parent = (pdev))
2479 /* Set the sysfs device type for the network logical device to allow
2480 * fine-grained identification of different network device types. For
2481 * example Ethernet, Wireless LAN, Bluetooth, WiMAX etc.
2483 #define SET_NETDEV_DEVTYPE(net, devtype) ((net)->dev.type = (devtype))
2485 /* Default NAPI poll() weight
2486 * Device drivers are strongly advised to not use bigger value
2488 #define NAPI_POLL_WEIGHT 64
2491 * netif_napi_add - initialize a NAPI context
2492 * @dev: network device
2493 * @napi: NAPI context
2494 * @poll: polling function
2495 * @weight: default weight
2497 * netif_napi_add() must be used to initialize a NAPI context prior to calling
2498 * *any* of the other NAPI-related functions.
2500 void netif_napi_add(struct net_device *dev, struct napi_struct *napi,
2501 int (*poll)(struct napi_struct *, int), int weight);
2504 * netif_tx_napi_add - initialize a NAPI context
2505 * @dev: network device
2506 * @napi: NAPI context
2507 * @poll: polling function
2508 * @weight: default weight
2510 * This variant of netif_napi_add() should be used from drivers using NAPI
2511 * to exclusively poll a TX queue.
2512 * This will avoid we add it into napi_hash[], thus polluting this hash table.
2514 static inline void netif_tx_napi_add(struct net_device *dev,
2515 struct napi_struct *napi,
2516 int (*poll)(struct napi_struct *, int),
2519 set_bit(NAPI_STATE_NO_BUSY_POLL, &napi->state);
2520 netif_napi_add(dev, napi, poll, weight);
2524 * __netif_napi_del - remove a NAPI context
2525 * @napi: NAPI context
2527 * Warning: caller must observe RCU grace period before freeing memory
2528 * containing @napi. Drivers might want to call this helper to combine
2529 * all the needed RCU grace periods into a single one.
2531 void __netif_napi_del(struct napi_struct *napi);
2534 * netif_napi_del - remove a NAPI context
2535 * @napi: NAPI context
2537 * netif_napi_del() removes a NAPI context from the network device NAPI list
2539 static inline void netif_napi_del(struct napi_struct *napi)
2541 __netif_napi_del(napi);
2545 struct napi_gro_cb {
2546 /* Virtual address of skb_shinfo(skb)->frags[0].page + offset. */
2549 /* Length of frag0. */
2550 unsigned int frag0_len;
2552 /* This indicates where we are processing relative to skb->data. */
2555 /* This is non-zero if the packet cannot be merged with the new skb. */
2558 /* Save the IP ID here and check when we get to the transport layer */
2561 /* Number of segments aggregated. */
2564 /* Start offset for remote checksum offload */
2565 u16 gro_remcsum_start;
2567 /* jiffies when first packet was created/queued */
2570 /* Used in ipv6_gro_receive() and foo-over-udp */
2573 /* This is non-zero if the packet may be of the same flow. */
2576 /* Used in tunnel GRO receive */
2579 /* GRO checksum is valid */
2582 /* Number of checksums via CHECKSUM_UNNECESSARY */
2587 #define NAPI_GRO_FREE 1
2588 #define NAPI_GRO_FREE_STOLEN_HEAD 2
2590 /* Used in foo-over-udp, set in udp[46]_gro_receive */
2593 /* Used in GRE, set in fou/gue_gro_receive */
2596 /* Used to determine if flush_id can be ignored */
2599 /* Number of gro_receive callbacks this packet already went through */
2600 u8 recursion_counter:4;
2602 /* GRO is done by frag_list pointer chaining. */
2605 /* used to support CHECKSUM_COMPLETE for tunneling protocols */
2608 /* used in skb_gro_receive() slow path */
2609 struct sk_buff *last;
2612 #define NAPI_GRO_CB(skb) ((struct napi_gro_cb *)(skb)->cb)
2614 #define GRO_RECURSION_LIMIT 15
2615 static inline int gro_recursion_inc_test(struct sk_buff *skb)
2617 return ++NAPI_GRO_CB(skb)->recursion_counter == GRO_RECURSION_LIMIT;
2620 typedef struct sk_buff *(*gro_receive_t)(struct list_head *, struct sk_buff *);
2621 static inline struct sk_buff *call_gro_receive(gro_receive_t cb,
2622 struct list_head *head,
2623 struct sk_buff *skb)
2625 if (unlikely(gro_recursion_inc_test(skb))) {
2626 NAPI_GRO_CB(skb)->flush |= 1;
2630 return cb(head, skb);
2633 typedef struct sk_buff *(*gro_receive_sk_t)(struct sock *, struct list_head *,
2635 static inline struct sk_buff *call_gro_receive_sk(gro_receive_sk_t cb,
2637 struct list_head *head,
2638 struct sk_buff *skb)
2640 if (unlikely(gro_recursion_inc_test(skb))) {
2641 NAPI_GRO_CB(skb)->flush |= 1;
2645 return cb(sk, head, skb);
2648 struct packet_type {
2649 __be16 type; /* This is really htons(ether_type). */
2650 bool ignore_outgoing;
2651 struct net_device *dev; /* NULL is wildcarded here */
2652 int (*func) (struct sk_buff *,
2653 struct net_device *,
2654 struct packet_type *,
2655 struct net_device *);
2656 void (*list_func) (struct list_head *,
2657 struct packet_type *,
2658 struct net_device *);
2659 bool (*id_match)(struct packet_type *ptype,
2661 struct net *af_packet_net;
2662 void *af_packet_priv;
2663 struct list_head list;
2666 struct offload_callbacks {
2667 struct sk_buff *(*gso_segment)(struct sk_buff *skb,
2668 netdev_features_t features);
2669 struct sk_buff *(*gro_receive)(struct list_head *head,
2670 struct sk_buff *skb);
2671 int (*gro_complete)(struct sk_buff *skb, int nhoff);
2674 struct packet_offload {
2675 __be16 type; /* This is really htons(ether_type). */
2677 struct offload_callbacks callbacks;
2678 struct list_head list;
2681 /* often modified stats are per-CPU, other are shared (netdev->stats) */
2682 struct pcpu_sw_netstats {
2687 struct u64_stats_sync syncp;
2688 } __aligned(4 * sizeof(u64));
2690 struct pcpu_lstats {
2691 u64_stats_t packets;
2693 struct u64_stats_sync syncp;
2694 } __aligned(2 * sizeof(u64));
2696 void dev_lstats_read(struct net_device *dev, u64 *packets, u64 *bytes);
2698 static inline void dev_sw_netstats_rx_add(struct net_device *dev, unsigned int len)
2700 struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
2702 u64_stats_update_begin(&tstats->syncp);
2703 tstats->rx_bytes += len;
2704 tstats->rx_packets++;
2705 u64_stats_update_end(&tstats->syncp);
2708 static inline void dev_sw_netstats_tx_add(struct net_device *dev,
2709 unsigned int packets,
2712 struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
2714 u64_stats_update_begin(&tstats->syncp);
2715 tstats->tx_bytes += len;
2716 tstats->tx_packets += packets;
2717 u64_stats_update_end(&tstats->syncp);
2720 static inline void dev_lstats_add(struct net_device *dev, unsigned int len)
2722 struct pcpu_lstats *lstats = this_cpu_ptr(dev->lstats);
2724 u64_stats_update_begin(&lstats->syncp);
2725 u64_stats_add(&lstats->bytes, len);
2726 u64_stats_inc(&lstats->packets);
2727 u64_stats_update_end(&lstats->syncp);
2730 #define __netdev_alloc_pcpu_stats(type, gfp) \
2732 typeof(type) __percpu *pcpu_stats = alloc_percpu_gfp(type, gfp);\
2735 for_each_possible_cpu(__cpu) { \
2736 typeof(type) *stat; \
2737 stat = per_cpu_ptr(pcpu_stats, __cpu); \
2738 u64_stats_init(&stat->syncp); \
2744 #define netdev_alloc_pcpu_stats(type) \
2745 __netdev_alloc_pcpu_stats(type, GFP_KERNEL)
2747 #define devm_netdev_alloc_pcpu_stats(dev, type) \
2749 typeof(type) __percpu *pcpu_stats = devm_alloc_percpu(dev, type);\
2752 for_each_possible_cpu(__cpu) { \
2753 typeof(type) *stat; \
2754 stat = per_cpu_ptr(pcpu_stats, __cpu); \
2755 u64_stats_init(&stat->syncp); \
2761 enum netdev_lag_tx_type {
2762 NETDEV_LAG_TX_TYPE_UNKNOWN,
2763 NETDEV_LAG_TX_TYPE_RANDOM,
2764 NETDEV_LAG_TX_TYPE_BROADCAST,
2765 NETDEV_LAG_TX_TYPE_ROUNDROBIN,
2766 NETDEV_LAG_TX_TYPE_ACTIVEBACKUP,
2767 NETDEV_LAG_TX_TYPE_HASH,
2770 enum netdev_lag_hash {
2771 NETDEV_LAG_HASH_NONE,
2773 NETDEV_LAG_HASH_L34,
2774 NETDEV_LAG_HASH_L23,
2775 NETDEV_LAG_HASH_E23,
2776 NETDEV_LAG_HASH_E34,
2777 NETDEV_LAG_HASH_VLAN_SRCMAC,
2778 NETDEV_LAG_HASH_UNKNOWN,
2781 struct netdev_lag_upper_info {
2782 enum netdev_lag_tx_type tx_type;
2783 enum netdev_lag_hash hash_type;
2786 struct netdev_lag_lower_state_info {
2791 #include <linux/notifier.h>
2793 /* netdevice notifier chain. Please remember to update netdev_cmd_to_name()
2794 * and the rtnetlink notification exclusion list in rtnetlink_event() when
2798 NETDEV_UP = 1, /* For now you can't veto a device up/down */
2800 NETDEV_REBOOT, /* Tell a protocol stack a network interface
2801 detected a hardware crash and restarted
2802 - we can use this eg to kick tcp sessions
2804 NETDEV_CHANGE, /* Notify device state change */
2807 NETDEV_CHANGEMTU, /* notify after mtu change happened */
2808 NETDEV_CHANGEADDR, /* notify after the address change */
2809 NETDEV_PRE_CHANGEADDR, /* notify before the address change */
2813 NETDEV_BONDING_FAILOVER,
2815 NETDEV_PRE_TYPE_CHANGE,
2816 NETDEV_POST_TYPE_CHANGE,
2819 NETDEV_NOTIFY_PEERS,
2823 NETDEV_PRECHANGEMTU, /* notify before mtu change happened */
2824 NETDEV_CHANGEINFODATA,
2825 NETDEV_BONDING_INFO,
2826 NETDEV_PRECHANGEUPPER,
2827 NETDEV_CHANGELOWERSTATE,
2828 NETDEV_UDP_TUNNEL_PUSH_INFO,
2829 NETDEV_UDP_TUNNEL_DROP_INFO,
2830 NETDEV_CHANGE_TX_QUEUE_LEN,
2831 NETDEV_CVLAN_FILTER_PUSH_INFO,
2832 NETDEV_CVLAN_FILTER_DROP_INFO,
2833 NETDEV_SVLAN_FILTER_PUSH_INFO,
2834 NETDEV_SVLAN_FILTER_DROP_INFO,
2836 const char *netdev_cmd_to_name(enum netdev_cmd cmd);
2838 int register_netdevice_notifier(struct notifier_block *nb);
2839 int unregister_netdevice_notifier(struct notifier_block *nb);
2840 int register_netdevice_notifier_net(struct net *net, struct notifier_block *nb);
2841 int unregister_netdevice_notifier_net(struct net *net,
2842 struct notifier_block *nb);
2843 int register_netdevice_notifier_dev_net(struct net_device *dev,
2844 struct notifier_block *nb,
2845 struct netdev_net_notifier *nn);
2846 int unregister_netdevice_notifier_dev_net(struct net_device *dev,
2847 struct notifier_block *nb,
2848 struct netdev_net_notifier *nn);
2850 struct netdev_notifier_info {
2851 struct net_device *dev;
2852 struct netlink_ext_ack *extack;
2855 struct netdev_notifier_info_ext {
2856 struct netdev_notifier_info info; /* must be first */
2862 struct netdev_notifier_change_info {
2863 struct netdev_notifier_info info; /* must be first */
2864 unsigned int flags_changed;
2867 struct netdev_notifier_changeupper_info {
2868 struct netdev_notifier_info info; /* must be first */
2869 struct net_device *upper_dev; /* new upper dev */
2870 bool master; /* is upper dev master */
2871 bool linking; /* is the notification for link or unlink */
2872 void *upper_info; /* upper dev info */
2875 struct netdev_notifier_changelowerstate_info {
2876 struct netdev_notifier_info info; /* must be first */
2877 void *lower_state_info; /* is lower dev state */
2880 struct netdev_notifier_pre_changeaddr_info {
2881 struct netdev_notifier_info info; /* must be first */
2882 const unsigned char *dev_addr;
2885 static inline void netdev_notifier_info_init(struct netdev_notifier_info *info,
2886 struct net_device *dev)
2889 info->extack = NULL;
2892 static inline struct net_device *
2893 netdev_notifier_info_to_dev(const struct netdev_notifier_info *info)
2898 static inline struct netlink_ext_ack *
2899 netdev_notifier_info_to_extack(const struct netdev_notifier_info *info)
2901 return info->extack;
2904 int call_netdevice_notifiers(unsigned long val, struct net_device *dev);
2907 extern rwlock_t dev_base_lock; /* Device list lock */
2909 #define for_each_netdev(net, d) \
2910 list_for_each_entry(d, &(net)->dev_base_head, dev_list)
2911 #define for_each_netdev_reverse(net, d) \
2912 list_for_each_entry_reverse(d, &(net)->dev_base_head, dev_list)
2913 #define for_each_netdev_rcu(net, d) \
2914 list_for_each_entry_rcu(d, &(net)->dev_base_head, dev_list)
2915 #define for_each_netdev_safe(net, d, n) \
2916 list_for_each_entry_safe(d, n, &(net)->dev_base_head, dev_list)
2917 #define for_each_netdev_continue(net, d) \
2918 list_for_each_entry_continue(d, &(net)->dev_base_head, dev_list)
2919 #define for_each_netdev_continue_reverse(net, d) \
2920 list_for_each_entry_continue_reverse(d, &(net)->dev_base_head, \
2922 #define for_each_netdev_continue_rcu(net, d) \
2923 list_for_each_entry_continue_rcu(d, &(net)->dev_base_head, dev_list)
2924 #define for_each_netdev_in_bond_rcu(bond, slave) \
2925 for_each_netdev_rcu(&init_net, slave) \
2926 if (netdev_master_upper_dev_get_rcu(slave) == (bond))
2927 #define net_device_entry(lh) list_entry(lh, struct net_device, dev_list)
2929 static inline struct net_device *next_net_device(struct net_device *dev)
2931 struct list_head *lh;
2935 lh = dev->dev_list.next;
2936 return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
2939 static inline struct net_device *next_net_device_rcu(struct net_device *dev)
2941 struct list_head *lh;
2945 lh = rcu_dereference(list_next_rcu(&dev->dev_list));
2946 return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
2949 static inline struct net_device *first_net_device(struct net *net)
2951 return list_empty(&net->dev_base_head) ? NULL :
2952 net_device_entry(net->dev_base_head.next);
2955 static inline struct net_device *first_net_device_rcu(struct net *net)
2957 struct list_head *lh = rcu_dereference(list_next_rcu(&net->dev_base_head));
2959 return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
2962 int netdev_boot_setup_check(struct net_device *dev);
2963 struct net_device *dev_getbyhwaddr_rcu(struct net *net, unsigned short type,
2964 const char *hwaddr);
2965 struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type);
2966 void dev_add_pack(struct packet_type *pt);
2967 void dev_remove_pack(struct packet_type *pt);
2968 void __dev_remove_pack(struct packet_type *pt);
2969 void dev_add_offload(struct packet_offload *po);
2970 void dev_remove_offload(struct packet_offload *po);
2972 int dev_get_iflink(const struct net_device *dev);
2973 int dev_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb);
2974 int dev_fill_forward_path(const struct net_device *dev, const u8 *daddr,
2975 struct net_device_path_stack *stack);
2976 struct net_device *__dev_get_by_flags(struct net *net, unsigned short flags,
2977 unsigned short mask);
2978 struct net_device *dev_get_by_name(struct net *net, const char *name);
2979 struct net_device *dev_get_by_name_rcu(struct net *net, const char *name);
2980 struct net_device *__dev_get_by_name(struct net *net, const char *name);
2981 int dev_alloc_name(struct net_device *dev, const char *name);
2982 int dev_open(struct net_device *dev, struct netlink_ext_ack *extack);
2983 void dev_close(struct net_device *dev);
2984 void dev_close_many(struct list_head *head, bool unlink);
2985 void dev_disable_lro(struct net_device *dev);
2986 int dev_loopback_xmit(struct net *net, struct sock *sk, struct sk_buff *newskb);
2987 u16 dev_pick_tx_zero(struct net_device *dev, struct sk_buff *skb,
2988 struct net_device *sb_dev);
2989 u16 dev_pick_tx_cpu_id(struct net_device *dev, struct sk_buff *skb,
2990 struct net_device *sb_dev);
2992 int dev_queue_xmit(struct sk_buff *skb);
2993 int dev_queue_xmit_accel(struct sk_buff *skb, struct net_device *sb_dev);
2994 int __dev_direct_xmit(struct sk_buff *skb, u16 queue_id);
2996 static inline int dev_direct_xmit(struct sk_buff *skb, u16 queue_id)
3000 ret = __dev_direct_xmit(skb, queue_id);
3001 if (!dev_xmit_complete(ret))
3006 int register_netdevice(struct net_device *dev);
3007 void unregister_netdevice_queue(struct net_device *dev, struct list_head *head);
3008 void unregister_netdevice_many(struct list_head *head);
3009 static inline void unregister_netdevice(struct net_device *dev)
3011 unregister_netdevice_queue(dev, NULL);
3014 int netdev_refcnt_read(const struct net_device *dev);
3015 void free_netdev(struct net_device *dev);
3016 void netdev_freemem(struct net_device *dev);
3017 int init_dummy_netdev(struct net_device *dev);
3019 struct net_device *netdev_get_xmit_slave(struct net_device *dev,
3020 struct sk_buff *skb,
3022 struct net_device *netdev_sk_get_lowest_dev(struct net_device *dev,
3024 struct net_device *dev_get_by_index(struct net *net, int ifindex);
3025 struct net_device *__dev_get_by_index(struct net *net, int ifindex);
3026 struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
3027 struct net_device *dev_get_by_napi_id(unsigned int napi_id);
3028 int netdev_get_name(struct net *net, char *name, int ifindex);
3029 int dev_restart(struct net_device *dev);
3030 int skb_gro_receive(struct sk_buff *p, struct sk_buff *skb);
3031 int skb_gro_receive_list(struct sk_buff *p, struct sk_buff *skb);
3033 static inline unsigned int skb_gro_offset(const struct sk_buff *skb)
3035 return NAPI_GRO_CB(skb)->data_offset;
3038 static inline unsigned int skb_gro_len(const struct sk_buff *skb)
3040 return skb->len - NAPI_GRO_CB(skb)->data_offset;
3043 static inline void skb_gro_pull(struct sk_buff *skb, unsigned int len)
3045 NAPI_GRO_CB(skb)->data_offset += len;
3048 static inline void *skb_gro_header_fast(struct sk_buff *skb,
3049 unsigned int offset)
3051 return NAPI_GRO_CB(skb)->frag0 + offset;
3054 static inline int skb_gro_header_hard(struct sk_buff *skb, unsigned int hlen)
3056 return NAPI_GRO_CB(skb)->frag0_len < hlen;
3059 static inline void skb_gro_frag0_invalidate(struct sk_buff *skb)
3061 NAPI_GRO_CB(skb)->frag0 = NULL;
3062 NAPI_GRO_CB(skb)->frag0_len = 0;
3065 static inline void *skb_gro_header_slow(struct sk_buff *skb, unsigned int hlen,
3066 unsigned int offset)
3068 if (!pskb_may_pull(skb, hlen))
3071 skb_gro_frag0_invalidate(skb);
3072 return skb->data + offset;
3075 static inline void *skb_gro_network_header(struct sk_buff *skb)
3077 return (NAPI_GRO_CB(skb)->frag0 ?: skb->data) +
3078 skb_network_offset(skb);
3081 static inline void skb_gro_postpull_rcsum(struct sk_buff *skb,
3082 const void *start, unsigned int len)
3084 if (NAPI_GRO_CB(skb)->csum_valid)
3085 NAPI_GRO_CB(skb)->csum = csum_sub(NAPI_GRO_CB(skb)->csum,
3086 csum_partial(start, len, 0));
3089 /* GRO checksum functions. These are logical equivalents of the normal
3090 * checksum functions (in skbuff.h) except that they operate on the GRO
3091 * offsets and fields in sk_buff.
3094 __sum16 __skb_gro_checksum_complete(struct sk_buff *skb);
3096 static inline bool skb_at_gro_remcsum_start(struct sk_buff *skb)
3098 return (NAPI_GRO_CB(skb)->gro_remcsum_start == skb_gro_offset(skb));
3101 static inline bool __skb_gro_checksum_validate_needed(struct sk_buff *skb,
3105 return ((skb->ip_summed != CHECKSUM_PARTIAL ||
3106 skb_checksum_start_offset(skb) <
3107 skb_gro_offset(skb)) &&
3108 !skb_at_gro_remcsum_start(skb) &&
3109 NAPI_GRO_CB(skb)->csum_cnt == 0 &&
3110 (!zero_okay || check));
3113 static inline __sum16 __skb_gro_checksum_validate_complete(struct sk_buff *skb,
3116 if (NAPI_GRO_CB(skb)->csum_valid &&
3117 !csum_fold(csum_add(psum, NAPI_GRO_CB(skb)->csum)))
3120 NAPI_GRO_CB(skb)->csum = psum;
3122 return __skb_gro_checksum_complete(skb);
3125 static inline void skb_gro_incr_csum_unnecessary(struct sk_buff *skb)
3127 if (NAPI_GRO_CB(skb)->csum_cnt > 0) {
3128 /* Consume a checksum from CHECKSUM_UNNECESSARY */
3129 NAPI_GRO_CB(skb)->csum_cnt--;
3131 /* Update skb for CHECKSUM_UNNECESSARY and csum_level when we
3132 * verified a new top level checksum or an encapsulated one
3133 * during GRO. This saves work if we fallback to normal path.
3135 __skb_incr_checksum_unnecessary(skb);
3139 #define __skb_gro_checksum_validate(skb, proto, zero_okay, check, \
3142 __sum16 __ret = 0; \
3143 if (__skb_gro_checksum_validate_needed(skb, zero_okay, check)) \
3144 __ret = __skb_gro_checksum_validate_complete(skb, \
3145 compute_pseudo(skb, proto)); \
3147 skb_gro_incr_csum_unnecessary(skb); \
3151 #define skb_gro_checksum_validate(skb, proto, compute_pseudo) \
3152 __skb_gro_checksum_validate(skb, proto, false, 0, compute_pseudo)
3154 #define skb_gro_checksum_validate_zero_check(skb, proto, check, \
3156 __skb_gro_checksum_validate(skb, proto, true, check, compute_pseudo)
3158 #define skb_gro_checksum_simple_validate(skb) \
3159 __skb_gro_checksum_validate(skb, 0, false, 0, null_compute_pseudo)
3161 static inline bool __skb_gro_checksum_convert_check(struct sk_buff *skb)
3163 return (NAPI_GRO_CB(skb)->csum_cnt == 0 &&
3164 !NAPI_GRO_CB(skb)->csum_valid);
3167 static inline void __skb_gro_checksum_convert(struct sk_buff *skb,
3170 NAPI_GRO_CB(skb)->csum = ~pseudo;
3171 NAPI_GRO_CB(skb)->csum_valid = 1;
3174 #define skb_gro_checksum_try_convert(skb, proto, compute_pseudo) \
3176 if (__skb_gro_checksum_convert_check(skb)) \
3177 __skb_gro_checksum_convert(skb, \
3178 compute_pseudo(skb, proto)); \
3181 struct gro_remcsum {
3186 static inline void skb_gro_remcsum_init(struct gro_remcsum *grc)
3192 static inline void *skb_gro_remcsum_process(struct sk_buff *skb, void *ptr,
3193 unsigned int off, size_t hdrlen,
3194 int start, int offset,
3195 struct gro_remcsum *grc,
3199 size_t plen = hdrlen + max_t(size_t, offset + sizeof(u16), start);
3201 BUG_ON(!NAPI_GRO_CB(skb)->csum_valid);
3204 NAPI_GRO_CB(skb)->gro_remcsum_start = off + hdrlen + start;
3208 ptr = skb_gro_header_fast(skb, off);
3209 if (skb_gro_header_hard(skb, off + plen)) {
3210 ptr = skb_gro_header_slow(skb, off + plen, off);
3215 delta = remcsum_adjust(ptr + hdrlen, NAPI_GRO_CB(skb)->csum,
3218 /* Adjust skb->csum since we changed the packet */
3219 NAPI_GRO_CB(skb)->csum = csum_add(NAPI_GRO_CB(skb)->csum, delta);
3221 grc->offset = off + hdrlen + offset;
3227 static inline void skb_gro_remcsum_cleanup(struct sk_buff *skb,
3228 struct gro_remcsum *grc)
3231 size_t plen = grc->offset + sizeof(u16);
3236 ptr = skb_gro_header_fast(skb, grc->offset);
3237 if (skb_gro_header_hard(skb, grc->offset + sizeof(u16))) {
3238 ptr = skb_gro_header_slow(skb, plen, grc->offset);
3243 remcsum_unadjust((__sum16 *)ptr, grc->delta);
3246 #ifdef CONFIG_XFRM_OFFLOAD
3247 static inline void skb_gro_flush_final(struct sk_buff *skb, struct sk_buff *pp, int flush)
3249 if (PTR_ERR(pp) != -EINPROGRESS)
3250 NAPI_GRO_CB(skb)->flush |= flush;
3252 static inline void skb_gro_flush_final_remcsum(struct sk_buff *skb,
3255 struct gro_remcsum *grc)
3257 if (PTR_ERR(pp) != -EINPROGRESS) {
3258 NAPI_GRO_CB(skb)->flush |= flush;
3259 skb_gro_remcsum_cleanup(skb, grc);
3260 skb->remcsum_offload = 0;
3264 static inline void skb_gro_flush_final(struct sk_buff *skb, struct sk_buff *pp, int flush)
3266 NAPI_GRO_CB(skb)->flush |= flush;
3268 static inline void skb_gro_flush_final_remcsum(struct sk_buff *skb,
3271 struct gro_remcsum *grc)
3273 NAPI_GRO_CB(skb)->flush |= flush;
3274 skb_gro_remcsum_cleanup(skb, grc);
3275 skb->remcsum_offload = 0;
3279 static inline int dev_hard_header(struct sk_buff *skb, struct net_device *dev,
3280 unsigned short type,
3281 const void *daddr, const void *saddr,
3284 if (!dev->header_ops || !dev->header_ops->create)
3287 return dev->header_ops->create(skb, dev, type, daddr, saddr, len);
3290 static inline int dev_parse_header(const struct sk_buff *skb,
3291 unsigned char *haddr)
3293 const struct net_device *dev = skb->dev;
3295 if (!dev->header_ops || !dev->header_ops->parse)
3297 return dev->header_ops->parse(skb, haddr);
3300 static inline __be16 dev_parse_header_protocol(const struct sk_buff *skb)
3302 const struct net_device *dev = skb->dev;
3304 if (!dev->header_ops || !dev->header_ops->parse_protocol)
3306 return dev->header_ops->parse_protocol(skb);
3309 /* ll_header must have at least hard_header_len allocated */
3310 static inline bool dev_validate_header(const struct net_device *dev,
3311 char *ll_header, int len)
3313 if (likely(len >= dev->hard_header_len))
3315 if (len < dev->min_header_len)
3318 if (capable(CAP_SYS_RAWIO)) {
3319 memset(ll_header + len, 0, dev->hard_header_len - len);
3323 if (dev->header_ops && dev->header_ops->validate)
3324 return dev->header_ops->validate(ll_header, len);
3329 static inline bool dev_has_header(const struct net_device *dev)
3331 return dev->header_ops && dev->header_ops->create;
3334 #ifdef CONFIG_NET_FLOW_LIMIT
3335 #define FLOW_LIMIT_HISTORY (1 << 7) /* must be ^2 and !overflow buckets */
3336 struct sd_flow_limit {
3338 unsigned int num_buckets;
3339 unsigned int history_head;
3340 u16 history[FLOW_LIMIT_HISTORY];
3344 extern int netdev_flow_limit_table_len;
3345 #endif /* CONFIG_NET_FLOW_LIMIT */
3348 * Incoming packets are placed on per-CPU queues
3350 struct softnet_data {
3351 struct list_head poll_list;
3352 struct sk_buff_head process_queue;
3355 unsigned int processed;
3356 unsigned int time_squeeze;
3357 unsigned int received_rps;
3359 struct softnet_data *rps_ipi_list;
3361 #ifdef CONFIG_NET_FLOW_LIMIT
3362 struct sd_flow_limit __rcu *flow_limit;
3364 struct Qdisc *output_queue;
3365 struct Qdisc **output_queue_tailp;
3366 struct sk_buff *completion_queue;
3367 #ifdef CONFIG_XFRM_OFFLOAD
3368 struct sk_buff_head xfrm_backlog;
3370 /* written and read only by owning cpu: */
3376 /* input_queue_head should be written by cpu owning this struct,
3377 * and only read by other cpus. Worth using a cache line.
3379 unsigned int input_queue_head ____cacheline_aligned_in_smp;
3381 /* Elements below can be accessed between CPUs for RPS/RFS */
3382 call_single_data_t csd ____cacheline_aligned_in_smp;
3383 struct softnet_data *rps_ipi_next;
3385 unsigned int input_queue_tail;
3387 unsigned int dropped;
3388 struct sk_buff_head input_pkt_queue;
3389 struct napi_struct backlog;
3393 static inline void input_queue_head_incr(struct softnet_data *sd)
3396 sd->input_queue_head++;
3400 static inline void input_queue_tail_incr_save(struct softnet_data *sd,
3401 unsigned int *qtail)
3404 *qtail = ++sd->input_queue_tail;
3408 DECLARE_PER_CPU_ALIGNED(struct softnet_data, softnet_data);
3410 static inline int dev_recursion_level(void)
3412 return this_cpu_read(softnet_data.xmit.recursion);
3415 #define XMIT_RECURSION_LIMIT 8
3416 static inline bool dev_xmit_recursion(void)
3418 return unlikely(__this_cpu_read(softnet_data.xmit.recursion) >
3419 XMIT_RECURSION_LIMIT);
3422 static inline void dev_xmit_recursion_inc(void)
3424 __this_cpu_inc(softnet_data.xmit.recursion);
3427 static inline void dev_xmit_recursion_dec(void)
3429 __this_cpu_dec(softnet_data.xmit.recursion);
3432 void __netif_schedule(struct Qdisc *q);
3433 void netif_schedule_queue(struct netdev_queue *txq);
3435 static inline void netif_tx_schedule_all(struct net_device *dev)
3439 for (i = 0; i < dev->num_tx_queues; i++)
3440 netif_schedule_queue(netdev_get_tx_queue(dev, i));
3443 static __always_inline void netif_tx_start_queue(struct netdev_queue *dev_queue)
3445 clear_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
3449 * netif_start_queue - allow transmit
3450 * @dev: network device
3452 * Allow upper layers to call the device hard_start_xmit routine.
3454 static inline void netif_start_queue(struct net_device *dev)
3456 netif_tx_start_queue(netdev_get_tx_queue(dev, 0));
3459 static inline void netif_tx_start_all_queues(struct net_device *dev)
3463 for (i = 0; i < dev->num_tx_queues; i++) {
3464 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
3465 netif_tx_start_queue(txq);
3469 void netif_tx_wake_queue(struct netdev_queue *dev_queue);
3472 * netif_wake_queue - restart transmit
3473 * @dev: network device
3475 * Allow upper layers to call the device hard_start_xmit routine.
3476 * Used for flow control when transmit resources are available.
3478 static inline void netif_wake_queue(struct net_device *dev)
3480 netif_tx_wake_queue(netdev_get_tx_queue(dev, 0));
3483 static inline void netif_tx_wake_all_queues(struct net_device *dev)
3487 for (i = 0; i < dev->num_tx_queues; i++) {
3488 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
3489 netif_tx_wake_queue(txq);
3493 static __always_inline void netif_tx_stop_queue(struct netdev_queue *dev_queue)
3495 set_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
3499 * netif_stop_queue - stop transmitted packets
3500 * @dev: network device
3502 * Stop upper layers calling the device hard_start_xmit routine.
3503 * Used for flow control when transmit resources are unavailable.
3505 static inline void netif_stop_queue(struct net_device *dev)
3507 netif_tx_stop_queue(netdev_get_tx_queue(dev, 0));
3510 void netif_tx_stop_all_queues(struct net_device *dev);
3512 static inline bool netif_tx_queue_stopped(const struct netdev_queue *dev_queue)
3514 return test_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
3518 * netif_queue_stopped - test if transmit queue is flowblocked
3519 * @dev: network device
3521 * Test if transmit queue on device is currently unable to send.
3523 static inline bool netif_queue_stopped(const struct net_device *dev)
3525 return netif_tx_queue_stopped(netdev_get_tx_queue(dev, 0));
3528 static inline bool netif_xmit_stopped(const struct netdev_queue *dev_queue)
3530 return dev_queue->state & QUEUE_STATE_ANY_XOFF;
3534 netif_xmit_frozen_or_stopped(const struct netdev_queue *dev_queue)
3536 return dev_queue->state & QUEUE_STATE_ANY_XOFF_OR_FROZEN;
3540 netif_xmit_frozen_or_drv_stopped(const struct netdev_queue *dev_queue)
3542 return dev_queue->state & QUEUE_STATE_DRV_XOFF_OR_FROZEN;
3546 * netdev_queue_set_dql_min_limit - set dql minimum limit
3547 * @dev_queue: pointer to transmit queue
3548 * @min_limit: dql minimum limit
3550 * Forces xmit_more() to return true until the minimum threshold
3551 * defined by @min_limit is reached (or until the tx queue is
3552 * empty). Warning: to be use with care, misuse will impact the
3555 static inline void netdev_queue_set_dql_min_limit(struct netdev_queue *dev_queue,
3556 unsigned int min_limit)
3559 dev_queue->dql.min_limit = min_limit;
3564 * netdev_txq_bql_enqueue_prefetchw - prefetch bql data for write
3565 * @dev_queue: pointer to transmit queue
3567 * BQL enabled drivers might use this helper in their ndo_start_xmit(),
3568 * to give appropriate hint to the CPU.
3570 static inline void netdev_txq_bql_enqueue_prefetchw(struct netdev_queue *dev_queue)
3573 prefetchw(&dev_queue->dql.num_queued);
3578 * netdev_txq_bql_complete_prefetchw - prefetch bql data for write
3579 * @dev_queue: pointer to transmit queue
3581 * BQL enabled drivers might use this helper in their TX completion path,
3582 * to give appropriate hint to the CPU.
3584 static inline void netdev_txq_bql_complete_prefetchw(struct netdev_queue *dev_queue)
3587 prefetchw(&dev_queue->dql.limit);
3591 static inline void netdev_tx_sent_queue(struct netdev_queue *dev_queue,
3595 dql_queued(&dev_queue->dql, bytes);
3597 if (likely(dql_avail(&dev_queue->dql) >= 0))
3600 set_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state);
3603 * The XOFF flag must be set before checking the dql_avail below,
3604 * because in netdev_tx_completed_queue we update the dql_completed
3605 * before checking the XOFF flag.
3609 /* check again in case another CPU has just made room avail */
3610 if (unlikely(dql_avail(&dev_queue->dql) >= 0))
3611 clear_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state);
3615 /* Variant of netdev_tx_sent_queue() for drivers that are aware
3616 * that they should not test BQL status themselves.
3617 * We do want to change __QUEUE_STATE_STACK_XOFF only for the last
3619 * Returns true if the doorbell must be used to kick the NIC.
3621 static inline bool __netdev_tx_sent_queue(struct netdev_queue *dev_queue,
3627 dql_queued(&dev_queue->dql, bytes);
3629 return netif_tx_queue_stopped(dev_queue);
3631 netdev_tx_sent_queue(dev_queue, bytes);
3636 * netdev_sent_queue - report the number of bytes queued to hardware
3637 * @dev: network device
3638 * @bytes: number of bytes queued to the hardware device queue
3640 * Report the number of bytes queued for sending/completion to the network
3641 * device hardware queue. @bytes should be a good approximation and should
3642 * exactly match netdev_completed_queue() @bytes
3644 static inline void netdev_sent_queue(struct net_device *dev, unsigned int bytes)
3646 netdev_tx_sent_queue(netdev_get_tx_queue(dev, 0), bytes);
3649 static inline bool __netdev_sent_queue(struct net_device *dev,
3653 return __netdev_tx_sent_queue(netdev_get_tx_queue(dev, 0), bytes,
3657 static inline void netdev_tx_completed_queue(struct netdev_queue *dev_queue,
3658 unsigned int pkts, unsigned int bytes)
3661 if (unlikely(!bytes))
3664 dql_completed(&dev_queue->dql, bytes);
3667 * Without the memory barrier there is a small possiblity that
3668 * netdev_tx_sent_queue will miss the update and cause the queue to
3669 * be stopped forever
3673 if (unlikely(dql_avail(&dev_queue->dql) < 0))
3676 if (test_and_clear_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state))
3677 netif_schedule_queue(dev_queue);
3682 * netdev_completed_queue - report bytes and packets completed by device
3683 * @dev: network device
3684 * @pkts: actual number of packets sent over the medium
3685 * @bytes: actual number of bytes sent over the medium
3687 * Report the number of bytes and packets transmitted by the network device
3688 * hardware queue over the physical medium, @bytes must exactly match the
3689 * @bytes amount passed to netdev_sent_queue()
3691 static inline void netdev_completed_queue(struct net_device *dev,
3692 unsigned int pkts, unsigned int bytes)
3694 netdev_tx_completed_queue(netdev_get_tx_queue(dev, 0), pkts, bytes);
3697 static inline void netdev_tx_reset_queue(struct netdev_queue *q)
3700 clear_bit(__QUEUE_STATE_STACK_XOFF, &q->state);
3706 * netdev_reset_queue - reset the packets and bytes count of a network device
3707 * @dev_queue: network device
3709 * Reset the bytes and packet count of a network device and clear the
3710 * software flow control OFF bit for this network device
3712 static inline void netdev_reset_queue(struct net_device *dev_queue)
3714 netdev_tx_reset_queue(netdev_get_tx_queue(dev_queue, 0));
3718 * netdev_cap_txqueue - check if selected tx queue exceeds device queues
3719 * @dev: network device
3720 * @queue_index: given tx queue index
3722 * Returns 0 if given tx queue index >= number of device tx queues,
3723 * otherwise returns the originally passed tx queue index.
3725 static inline u16 netdev_cap_txqueue(struct net_device *dev, u16 queue_index)
3727 if (unlikely(queue_index >= dev->real_num_tx_queues)) {
3728 net_warn_ratelimited("%s selects TX queue %d, but real number of TX queues is %d\n",
3729 dev->name, queue_index,
3730 dev->real_num_tx_queues);
3738 * netif_running - test if up
3739 * @dev: network device
3741 * Test if the device has been brought up.
3743 static inline bool netif_running(const struct net_device *dev)
3745 return test_bit(__LINK_STATE_START, &dev->state);
3749 * Routines to manage the subqueues on a device. We only need start,
3750 * stop, and a check if it's stopped. All other device management is
3751 * done at the overall netdevice level.
3752 * Also test the device if we're multiqueue.
3756 * netif_start_subqueue - allow sending packets on subqueue
3757 * @dev: network device
3758 * @queue_index: sub queue index
3760 * Start individual transmit queue of a device with multiple transmit queues.
3762 static inline void netif_start_subqueue(struct net_device *dev, u16 queue_index)
3764 struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
3766 netif_tx_start_queue(txq);
3770 * netif_stop_subqueue - stop sending packets on subqueue
3771 * @dev: network device
3772 * @queue_index: sub queue index
3774 * Stop individual transmit queue of a device with multiple transmit queues.
3776 static inline void netif_stop_subqueue(struct net_device *dev, u16 queue_index)
3778 struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
3779 netif_tx_stop_queue(txq);
3783 * __netif_subqueue_stopped - test status of subqueue
3784 * @dev: network device
3785 * @queue_index: sub queue index
3787 * Check individual transmit queue of a device with multiple transmit queues.
3789 static inline bool __netif_subqueue_stopped(const struct net_device *dev,
3792 struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
3794 return netif_tx_queue_stopped(txq);
3798 * netif_subqueue_stopped - test status of subqueue
3799 * @dev: network device
3800 * @skb: sub queue buffer pointer
3802 * Check individual transmit queue of a device with multiple transmit queues.
3804 static inline bool netif_subqueue_stopped(const struct net_device *dev,
3805 struct sk_buff *skb)
3807 return __netif_subqueue_stopped(dev, skb_get_queue_mapping(skb));
3811 * netif_wake_subqueue - allow sending packets on subqueue
3812 * @dev: network device
3813 * @queue_index: sub queue index
3815 * Resume individual transmit queue of a device with multiple transmit queues.
3817 static inline void netif_wake_subqueue(struct net_device *dev, u16 queue_index)
3819 struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
3821 netif_tx_wake_queue(txq);
3825 int netif_set_xps_queue(struct net_device *dev, const struct cpumask *mask,
3827 int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask,
3828 u16 index, enum xps_map_type type);
3831 * netif_attr_test_mask - Test a CPU or Rx queue set in a mask
3832 * @j: CPU/Rx queue index
3833 * @mask: bitmask of all cpus/rx queues
3834 * @nr_bits: number of bits in the bitmask
3836 * Test if a CPU or Rx queue index is set in a mask of all CPU/Rx queues.
3838 static inline bool netif_attr_test_mask(unsigned long j,
3839 const unsigned long *mask,
3840 unsigned int nr_bits)
3842 cpu_max_bits_warn(j, nr_bits);
3843 return test_bit(j, mask);
3847 * netif_attr_test_online - Test for online CPU/Rx queue
3848 * @j: CPU/Rx queue index
3849 * @online_mask: bitmask for CPUs/Rx queues that are online
3850 * @nr_bits: number of bits in the bitmask
3852 * Returns true if a CPU/Rx queue is online.
3854 static inline bool netif_attr_test_online(unsigned long j,
3855 const unsigned long *online_mask,
3856 unsigned int nr_bits)
3858 cpu_max_bits_warn(j, nr_bits);
3861 return test_bit(j, online_mask);
3863 return (j < nr_bits);
3867 * netif_attrmask_next - get the next CPU/Rx queue in a cpu/Rx queues mask
3868 * @n: CPU/Rx queue index
3869 * @srcp: the cpumask/Rx queue mask pointer
3870 * @nr_bits: number of bits in the bitmask
3872 * Returns >= nr_bits if no further CPUs/Rx queues set.
3874 static inline unsigned int netif_attrmask_next(int n, const unsigned long *srcp,
3875 unsigned int nr_bits)
3877 /* -1 is a legal arg here. */
3879 cpu_max_bits_warn(n, nr_bits);
3882 return find_next_bit(srcp, nr_bits, n + 1);
3888 * netif_attrmask_next_and - get the next CPU/Rx queue in \*src1p & \*src2p
3889 * @n: CPU/Rx queue index
3890 * @src1p: the first CPUs/Rx queues mask pointer
3891 * @src2p: the second CPUs/Rx queues mask pointer
3892 * @nr_bits: number of bits in the bitmask
3894 * Returns >= nr_bits if no further CPUs/Rx queues set in both.
3896 static inline int netif_attrmask_next_and(int n, const unsigned long *src1p,
3897 const unsigned long *src2p,
3898 unsigned int nr_bits)
3900 /* -1 is a legal arg here. */
3902 cpu_max_bits_warn(n, nr_bits);
3905 return find_next_and_bit(src1p, src2p, nr_bits, n + 1);
3907 return find_next_bit(src1p, nr_bits, n + 1);
3909 return find_next_bit(src2p, nr_bits, n + 1);
3914 static inline int netif_set_xps_queue(struct net_device *dev,
3915 const struct cpumask *mask,
3921 static inline int __netif_set_xps_queue(struct net_device *dev,
3922 const unsigned long *mask,
3923 u16 index, enum xps_map_type type)
3930 * netif_is_multiqueue - test if device has multiple transmit queues
3931 * @dev: network device
3933 * Check if device has multiple transmit queues
3935 static inline bool netif_is_multiqueue(const struct net_device *dev)
3937 return dev->num_tx_queues > 1;
3940 int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq);
3943 int netif_set_real_num_rx_queues(struct net_device *dev, unsigned int rxq);
3945 static inline int netif_set_real_num_rx_queues(struct net_device *dev,
3948 dev->real_num_rx_queues = rxqs;
3952 int netif_set_real_num_queues(struct net_device *dev,
3953 unsigned int txq, unsigned int rxq);
3955 static inline struct netdev_rx_queue *
3956 __netif_get_rx_queue(struct net_device *dev, unsigned int rxq)
3958 return dev->_rx + rxq;
3962 static inline unsigned int get_netdev_rx_queue_index(
3963 struct netdev_rx_queue *queue)
3965 struct net_device *dev = queue->dev;
3966 int index = queue - dev->_rx;
3968 BUG_ON(index >= dev->num_rx_queues);
3973 #define DEFAULT_MAX_NUM_RSS_QUEUES (8)
3974 int netif_get_num_default_rss_queues(void);
3976 enum skb_free_reason {
3977 SKB_REASON_CONSUMED,
3981 void __dev_kfree_skb_irq(struct sk_buff *skb, enum skb_free_reason reason);
3982 void __dev_kfree_skb_any(struct sk_buff *skb, enum skb_free_reason reason);
3985 * It is not allowed to call kfree_skb() or consume_skb() from hardware
3986 * interrupt context or with hardware interrupts being disabled.
3987 * (in_hardirq() || irqs_disabled())
3989 * We provide four helpers that can be used in following contexts :
3991 * dev_kfree_skb_irq(skb) when caller drops a packet from irq context,
3992 * replacing kfree_skb(skb)
3994 * dev_consume_skb_irq(skb) when caller consumes a packet from irq context.
3995 * Typically used in place of consume_skb(skb) in TX completion path
3997 * dev_kfree_skb_any(skb) when caller doesn't know its current irq context,
3998 * replacing kfree_skb(skb)
4000 * dev_consume_skb_any(skb) when caller doesn't know its current irq context,
4001 * and consumed a packet. Used in place of consume_skb(skb)
4003 static inline void dev_kfree_skb_irq(struct sk_buff *skb)
4005 __dev_kfree_skb_irq(skb, SKB_REASON_DROPPED);
4008 static inline void dev_consume_skb_irq(struct sk_buff *skb)
4010 __dev_kfree_skb_irq(skb, SKB_REASON_CONSUMED);
4013 static inline void dev_kfree_skb_any(struct sk_buff *skb)
4015 __dev_kfree_skb_any(skb, SKB_REASON_DROPPED);
4018 static inline void dev_consume_skb_any(struct sk_buff *skb)
4020 __dev_kfree_skb_any(skb, SKB_REASON_CONSUMED);
4023 u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp,
4024 struct bpf_prog *xdp_prog);
4025 void generic_xdp_tx(struct sk_buff *skb, struct bpf_prog *xdp_prog);
4026 int do_xdp_generic(struct bpf_prog *xdp_prog, struct sk_buff *skb);
4027 int netif_rx(struct sk_buff *skb);
4028 int netif_rx_ni(struct sk_buff *skb);
4029 int netif_rx_any_context(struct sk_buff *skb);
4030 int netif_receive_skb(struct sk_buff *skb);
4031 int netif_receive_skb_core(struct sk_buff *skb);
4032 void netif_receive_skb_list(struct list_head *head);
4033 gro_result_t napi_gro_receive(struct napi_struct *napi, struct sk_buff *skb);
4034 void napi_gro_flush(struct napi_struct *napi, bool flush_old);
4035 struct sk_buff *napi_get_frags(struct napi_struct *napi);
4036 gro_result_t napi_gro_frags(struct napi_struct *napi);
4037 struct packet_offload *gro_find_receive_by_type(__be16 type);
4038 struct packet_offload *gro_find_complete_by_type(__be16 type);
4040 static inline void napi_free_frags(struct napi_struct *napi)
4042 kfree_skb(napi->skb);
4046 bool netdev_is_rx_handler_busy(struct net_device *dev);
4047 int netdev_rx_handler_register(struct net_device *dev,
4048 rx_handler_func_t *rx_handler,
4049 void *rx_handler_data);
4050 void netdev_rx_handler_unregister(struct net_device *dev);
4052 bool dev_valid_name(const char *name);
4053 static inline bool is_socket_ioctl_cmd(unsigned int cmd)
4055 return _IOC_TYPE(cmd) == SOCK_IOC_TYPE;
4057 int get_user_ifreq(struct ifreq *ifr, void __user **ifrdata, void __user *arg);
4058 int put_user_ifreq(struct ifreq *ifr, void __user *arg);
4059 int dev_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr,
4060 void __user *data, bool *need_copyout);
4061 int dev_ifconf(struct net *net, struct ifconf __user *ifc);
4062 int dev_ethtool(struct net *net, struct ifreq *ifr, void __user *userdata);
4063 unsigned int dev_get_flags(const struct net_device *);
4064 int __dev_change_flags(struct net_device *dev, unsigned int flags,
4065 struct netlink_ext_ack *extack);
4066 int dev_change_flags(struct net_device *dev, unsigned int flags,
4067 struct netlink_ext_ack *extack);
4068 void __dev_notify_flags(struct net_device *, unsigned int old_flags,
4069 unsigned int gchanges);
4070 int dev_change_name(struct net_device *, const char *);
4071 int dev_set_alias(struct net_device *, const char *, size_t);
4072 int dev_get_alias(const struct net_device *, char *, size_t);
4073 int __dev_change_net_namespace(struct net_device *dev, struct net *net,
4074 const char *pat, int new_ifindex);
4076 int dev_change_net_namespace(struct net_device *dev, struct net *net,
4079 return __dev_change_net_namespace(dev, net, pat, 0);
4081 int __dev_set_mtu(struct net_device *, int);
4082 int dev_validate_mtu(struct net_device *dev, int mtu,
4083 struct netlink_ext_ack *extack);
4084 int dev_set_mtu_ext(struct net_device *dev, int mtu,
4085 struct netlink_ext_ack *extack);
4086 int dev_set_mtu(struct net_device *, int);
4087 int dev_change_tx_queue_len(struct net_device *, unsigned long);
4088 void dev_set_group(struct net_device *, int);
4089 int dev_pre_changeaddr_notify(struct net_device *dev, const char *addr,
4090 struct netlink_ext_ack *extack);
4091 int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa,
4092 struct netlink_ext_ack *extack);
4093 int dev_set_mac_address_user(struct net_device *dev, struct sockaddr *sa,
4094 struct netlink_ext_ack *extack);
4095 int dev_get_mac_address(struct sockaddr *sa, struct net *net, char *dev_name);
4096 int dev_change_carrier(struct net_device *, bool new_carrier);
4097 int dev_get_phys_port_id(struct net_device *dev,
4098 struct netdev_phys_item_id *ppid);
4099 int dev_get_phys_port_name(struct net_device *dev,
4100 char *name, size_t len);
4101 int dev_get_port_parent_id(struct net_device *dev,
4102 struct netdev_phys_item_id *ppid, bool recurse);
4103 bool netdev_port_same_parent_id(struct net_device *a, struct net_device *b);
4104 int dev_change_proto_down(struct net_device *dev, bool proto_down);
4105 int dev_change_proto_down_generic(struct net_device *dev, bool proto_down);
4106 void dev_change_proto_down_reason(struct net_device *dev, unsigned long mask,
4108 struct sk_buff *validate_xmit_skb_list(struct sk_buff *skb, struct net_device *dev, bool *again);
4109 struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
4110 struct netdev_queue *txq, int *ret);
4112 typedef int (*bpf_op_t)(struct net_device *dev, struct netdev_bpf *bpf);
4113 int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
4114 int fd, int expected_fd, u32 flags);
4115 int bpf_xdp_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
4116 u8 dev_xdp_prog_count(struct net_device *dev);
4117 u32 dev_xdp_prog_id(struct net_device *dev, enum bpf_xdp_mode mode);
4119 int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
4120 int dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
4121 int dev_forward_skb_nomtu(struct net_device *dev, struct sk_buff *skb);
4122 bool is_skb_forwardable(const struct net_device *dev,
4123 const struct sk_buff *skb);
4125 static __always_inline bool __is_skb_forwardable(const struct net_device *dev,
4126 const struct sk_buff *skb,
4127 const bool check_mtu)
4129 const u32 vlan_hdr_len = 4; /* VLAN_HLEN */
4132 if (!(dev->flags & IFF_UP))
4138 len = dev->mtu + dev->hard_header_len + vlan_hdr_len;
4139 if (skb->len <= len)
4142 /* if TSO is enabled, we don't care about the length as the packet
4143 * could be forwarded without being segmented before
4145 if (skb_is_gso(skb))
4151 static __always_inline int ____dev_forward_skb(struct net_device *dev,
4152 struct sk_buff *skb,
4153 const bool check_mtu)
4155 if (skb_orphan_frags(skb, GFP_ATOMIC) ||
4156 unlikely(!__is_skb_forwardable(dev, skb, check_mtu))) {
4157 atomic_long_inc(&dev->rx_dropped);
4162 skb_scrub_packet(skb, !net_eq(dev_net(dev), dev_net(skb->dev)));
4167 bool dev_nit_active(struct net_device *dev);
4168 void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev);
4170 extern int netdev_budget;
4171 extern unsigned int netdev_budget_usecs;
4173 /* Called by rtnetlink.c:rtnl_unlock() */
4174 void netdev_run_todo(void);
4177 * dev_put - release reference to device
4178 * @dev: network device
4180 * Release reference to device to allow it to be freed.
4182 static inline void dev_put(struct net_device *dev)
4185 #ifdef CONFIG_PCPU_DEV_REFCNT
4186 this_cpu_dec(*dev->pcpu_refcnt);
4188 refcount_dec(&dev->dev_refcnt);
4194 * dev_hold - get reference to device
4195 * @dev: network device
4197 * Hold reference to device to keep it from being freed.
4199 static inline void dev_hold(struct net_device *dev)
4202 #ifdef CONFIG_PCPU_DEV_REFCNT
4203 this_cpu_inc(*dev->pcpu_refcnt);
4205 refcount_inc(&dev->dev_refcnt);
4210 /* Carrier loss detection, dial on demand. The functions netif_carrier_on
4211 * and _off may be called from IRQ context, but it is caller
4212 * who is responsible for serialization of these calls.
4214 * The name carrier is inappropriate, these functions should really be
4215 * called netif_lowerlayer_*() because they represent the state of any
4216 * kind of lower layer not just hardware media.
4219 void linkwatch_init_dev(struct net_device *dev);
4220 void linkwatch_fire_event(struct net_device *dev);
4221 void linkwatch_forget_dev(struct net_device *dev);
4224 * netif_carrier_ok - test if carrier present
4225 * @dev: network device
4227 * Check if carrier is present on device
4229 static inline bool netif_carrier_ok(const struct net_device *dev)
4231 return !test_bit(__LINK_STATE_NOCARRIER, &dev->state);
4234 unsigned long dev_trans_start(struct net_device *dev);
4236 void __netdev_watchdog_up(struct net_device *dev);
4238 void netif_carrier_on(struct net_device *dev);
4239 void netif_carrier_off(struct net_device *dev);
4240 void netif_carrier_event(struct net_device *dev);
4243 * netif_dormant_on - mark device as dormant.
4244 * @dev: network device
4246 * Mark device as dormant (as per RFC2863).
4248 * The dormant state indicates that the relevant interface is not
4249 * actually in a condition to pass packets (i.e., it is not 'up') but is
4250 * in a "pending" state, waiting for some external event. For "on-
4251 * demand" interfaces, this new state identifies the situation where the
4252 * interface is waiting for events to place it in the up state.
4254 static inline void netif_dormant_on(struct net_device *dev)
4256 if (!test_and_set_bit(__LINK_STATE_DORMANT, &dev->state))
4257 linkwatch_fire_event(dev);
4261 * netif_dormant_off - set device as not dormant.
4262 * @dev: network device
4264 * Device is not in dormant state.
4266 static inline void netif_dormant_off(struct net_device *dev)
4268 if (test_and_clear_bit(__LINK_STATE_DORMANT, &dev->state))
4269 linkwatch_fire_event(dev);
4273 * netif_dormant - test if device is dormant
4274 * @dev: network device
4276 * Check if device is dormant.
4278 static inline bool netif_dormant(const struct net_device *dev)
4280 return test_bit(__LINK_STATE_DORMANT, &dev->state);
4285 * netif_testing_on - mark device as under test.
4286 * @dev: network device
4288 * Mark device as under test (as per RFC2863).
4290 * The testing state indicates that some test(s) must be performed on
4291 * the interface. After completion, of the test, the interface state
4292 * will change to up, dormant, or down, as appropriate.
4294 static inline void netif_testing_on(struct net_device *dev)
4296 if (!test_and_set_bit(__LINK_STATE_TESTING, &dev->state))
4297 linkwatch_fire_event(dev);
4301 * netif_testing_off - set device as not under test.
4302 * @dev: network device
4304 * Device is not in testing state.
4306 static inline void netif_testing_off(struct net_device *dev)
4308 if (test_and_clear_bit(__LINK_STATE_TESTING, &dev->state))
4309 linkwatch_fire_event(dev);
4313 * netif_testing - test if device is under test
4314 * @dev: network device
4316 * Check if device is under test
4318 static inline bool netif_testing(const struct net_device *dev)
4320 return test_bit(__LINK_STATE_TESTING, &dev->state);
4325 * netif_oper_up - test if device is operational
4326 * @dev: network device
4328 * Check if carrier is operational
4330 static inline bool netif_oper_up(const struct net_device *dev)
4332 return (dev->operstate == IF_OPER_UP ||
4333 dev->operstate == IF_OPER_UNKNOWN /* backward compat */);
4337 * netif_device_present - is device available or removed
4338 * @dev: network device
4340 * Check if device has not been removed from system.
4342 static inline bool netif_device_present(const struct net_device *dev)
4344 return test_bit(__LINK_STATE_PRESENT, &dev->state);
4347 void netif_device_detach(struct net_device *dev);
4349 void netif_device_attach(struct net_device *dev);
4352 * Network interface message level settings
4357 NETIF_MSG_PROBE_BIT,
4359 NETIF_MSG_TIMER_BIT,
4360 NETIF_MSG_IFDOWN_BIT,
4362 NETIF_MSG_RX_ERR_BIT,
4363 NETIF_MSG_TX_ERR_BIT,
4364 NETIF_MSG_TX_QUEUED_BIT,
4366 NETIF_MSG_TX_DONE_BIT,
4367 NETIF_MSG_RX_STATUS_BIT,
4368 NETIF_MSG_PKTDATA_BIT,
4372 /* When you add a new bit above, update netif_msg_class_names array
4373 * in net/ethtool/common.c
4375 NETIF_MSG_CLASS_COUNT,
4377 /* Both ethtool_ops interface and internal driver implementation use u32 */
4378 static_assert(NETIF_MSG_CLASS_COUNT <= 32);
4380 #define __NETIF_MSG_BIT(bit) ((u32)1 << (bit))
4381 #define __NETIF_MSG(name) __NETIF_MSG_BIT(NETIF_MSG_ ## name ## _BIT)
4383 #define NETIF_MSG_DRV __NETIF_MSG(DRV)
4384 #define NETIF_MSG_PROBE __NETIF_MSG(PROBE)
4385 #define NETIF_MSG_LINK __NETIF_MSG(LINK)
4386 #define NETIF_MSG_TIMER __NETIF_MSG(TIMER)
4387 #define NETIF_MSG_IFDOWN __NETIF_MSG(IFDOWN)
4388 #define NETIF_MSG_IFUP __NETIF_MSG(IFUP)
4389 #define NETIF_MSG_RX_ERR __NETIF_MSG(RX_ERR)
4390 #define NETIF_MSG_TX_ERR __NETIF_MSG(TX_ERR)
4391 #define NETIF_MSG_TX_QUEUED __NETIF_MSG(TX_QUEUED)
4392 #define NETIF_MSG_INTR __NETIF_MSG(INTR)
4393 #define NETIF_MSG_TX_DONE __NETIF_MSG(TX_DONE)
4394 #define NETIF_MSG_RX_STATUS __NETIF_MSG(RX_STATUS)
4395 #define NETIF_MSG_PKTDATA __NETIF_MSG(PKTDATA)
4396 #define NETIF_MSG_HW __NETIF_MSG(HW)
4397 #define NETIF_MSG_WOL __NETIF_MSG(WOL)
4399 #define netif_msg_drv(p) ((p)->msg_enable & NETIF_MSG_DRV)
4400 #define netif_msg_probe(p) ((p)->msg_enable & NETIF_MSG_PROBE)
4401 #define netif_msg_link(p) ((p)->msg_enable & NETIF_MSG_LINK)
4402 #define netif_msg_timer(p) ((p)->msg_enable & NETIF_MSG_TIMER)
4403 #define netif_msg_ifdown(p) ((p)->msg_enable & NETIF_MSG_IFDOWN)
4404 #define netif_msg_ifup(p) ((p)->msg_enable & NETIF_MSG_IFUP)
4405 #define netif_msg_rx_err(p) ((p)->msg_enable & NETIF_MSG_RX_ERR)
4406 #define netif_msg_tx_err(p) ((p)->msg_enable & NETIF_MSG_TX_ERR)
4407 #define netif_msg_tx_queued(p) ((p)->msg_enable & NETIF_MSG_TX_QUEUED)
4408 #define netif_msg_intr(p) ((p)->msg_enable & NETIF_MSG_INTR)
4409 #define netif_msg_tx_done(p) ((p)->msg_enable & NETIF_MSG_TX_DONE)
4410 #define netif_msg_rx_status(p) ((p)->msg_enable & NETIF_MSG_RX_STATUS)
4411 #define netif_msg_pktdata(p) ((p)->msg_enable & NETIF_MSG_PKTDATA)
4412 #define netif_msg_hw(p) ((p)->msg_enable & NETIF_MSG_HW)
4413 #define netif_msg_wol(p) ((p)->msg_enable & NETIF_MSG_WOL)
4415 static inline u32 netif_msg_init(int debug_value, int default_msg_enable_bits)
4418 if (debug_value < 0 || debug_value >= (sizeof(u32) * 8))
4419 return default_msg_enable_bits;
4420 if (debug_value == 0) /* no output */
4422 /* set low N bits */
4423 return (1U << debug_value) - 1;
4426 static inline void __netif_tx_lock(struct netdev_queue *txq, int cpu)
4428 spin_lock(&txq->_xmit_lock);
4429 /* Pairs with READ_ONCE() in __dev_queue_xmit() */
4430 WRITE_ONCE(txq->xmit_lock_owner, cpu);
4433 static inline bool __netif_tx_acquire(struct netdev_queue *txq)
4435 __acquire(&txq->_xmit_lock);
4439 static inline void __netif_tx_release(struct netdev_queue *txq)
4441 __release(&txq->_xmit_lock);
4444 static inline void __netif_tx_lock_bh(struct netdev_queue *txq)
4446 spin_lock_bh(&txq->_xmit_lock);
4447 /* Pairs with READ_ONCE() in __dev_queue_xmit() */
4448 WRITE_ONCE(txq->xmit_lock_owner, smp_processor_id());
4451 static inline bool __netif_tx_trylock(struct netdev_queue *txq)
4453 bool ok = spin_trylock(&txq->_xmit_lock);
4456 /* Pairs with READ_ONCE() in __dev_queue_xmit() */
4457 WRITE_ONCE(txq->xmit_lock_owner, smp_processor_id());
4462 static inline void __netif_tx_unlock(struct netdev_queue *txq)
4464 /* Pairs with READ_ONCE() in __dev_queue_xmit() */
4465 WRITE_ONCE(txq->xmit_lock_owner, -1);
4466 spin_unlock(&txq->_xmit_lock);
4469 static inline void __netif_tx_unlock_bh(struct netdev_queue *txq)
4471 /* Pairs with READ_ONCE() in __dev_queue_xmit() */
4472 WRITE_ONCE(txq->xmit_lock_owner, -1);
4473 spin_unlock_bh(&txq->_xmit_lock);
4476 static inline void txq_trans_update(struct netdev_queue *txq)
4478 if (txq->xmit_lock_owner != -1)
4479 txq->trans_start = jiffies;
4482 /* legacy drivers only, netdev_start_xmit() sets txq->trans_start */
4483 static inline void netif_trans_update(struct net_device *dev)
4485 struct netdev_queue *txq = netdev_get_tx_queue(dev, 0);
4487 if (txq->trans_start != jiffies)
4488 txq->trans_start = jiffies;
4492 * netif_tx_lock - grab network device transmit lock
4493 * @dev: network device
4495 * Get network device transmit lock
4497 static inline void netif_tx_lock(struct net_device *dev)
4502 spin_lock(&dev->tx_global_lock);
4503 cpu = smp_processor_id();
4504 for (i = 0; i < dev->num_tx_queues; i++) {
4505 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
4507 /* We are the only thread of execution doing a
4508 * freeze, but we have to grab the _xmit_lock in
4509 * order to synchronize with threads which are in
4510 * the ->hard_start_xmit() handler and already
4511 * checked the frozen bit.
4513 __netif_tx_lock(txq, cpu);
4514 set_bit(__QUEUE_STATE_FROZEN, &txq->state);
4515 __netif_tx_unlock(txq);
4519 static inline void netif_tx_lock_bh(struct net_device *dev)
4525 static inline void netif_tx_unlock(struct net_device *dev)
4529 for (i = 0; i < dev->num_tx_queues; i++) {
4530 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
4532 /* No need to grab the _xmit_lock here. If the
4533 * queue is not stopped for another reason, we
4536 clear_bit(__QUEUE_STATE_FROZEN, &txq->state);
4537 netif_schedule_queue(txq);
4539 spin_unlock(&dev->tx_global_lock);
4542 static inline void netif_tx_unlock_bh(struct net_device *dev)
4544 netif_tx_unlock(dev);
4548 #define HARD_TX_LOCK(dev, txq, cpu) { \
4549 if ((dev->features & NETIF_F_LLTX) == 0) { \
4550 __netif_tx_lock(txq, cpu); \
4552 __netif_tx_acquire(txq); \
4556 #define HARD_TX_TRYLOCK(dev, txq) \
4557 (((dev->features & NETIF_F_LLTX) == 0) ? \
4558 __netif_tx_trylock(txq) : \
4559 __netif_tx_acquire(txq))
4561 #define HARD_TX_UNLOCK(dev, txq) { \
4562 if ((dev->features & NETIF_F_LLTX) == 0) { \
4563 __netif_tx_unlock(txq); \
4565 __netif_tx_release(txq); \
4569 static inline void netif_tx_disable(struct net_device *dev)
4575 cpu = smp_processor_id();
4576 spin_lock(&dev->tx_global_lock);
4577 for (i = 0; i < dev->num_tx_queues; i++) {
4578 struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
4580 __netif_tx_lock(txq, cpu);
4581 netif_tx_stop_queue(txq);
4582 __netif_tx_unlock(txq);
4584 spin_unlock(&dev->tx_global_lock);
4588 static inline void netif_addr_lock(struct net_device *dev)
4590 unsigned char nest_level = 0;
4592 #ifdef CONFIG_LOCKDEP
4593 nest_level = dev->nested_level;
4595 spin_lock_nested(&dev->addr_list_lock, nest_level);
4598 static inline void netif_addr_lock_bh(struct net_device *dev)
4600 unsigned char nest_level = 0;
4602 #ifdef CONFIG_LOCKDEP
4603 nest_level = dev->nested_level;
4606 spin_lock_nested(&dev->addr_list_lock, nest_level);
4609 static inline void netif_addr_unlock(struct net_device *dev)
4611 spin_unlock(&dev->addr_list_lock);
4614 static inline void netif_addr_unlock_bh(struct net_device *dev)
4616 spin_unlock_bh(&dev->addr_list_lock);
4620 * dev_addrs walker. Should be used only for read access. Call with
4621 * rcu_read_lock held.
4623 #define for_each_dev_addr(dev, ha) \
4624 list_for_each_entry_rcu(ha, &dev->dev_addrs.list, list)
4626 /* These functions live elsewhere (drivers/net/net_init.c, but related) */
4628 void ether_setup(struct net_device *dev);
4630 /* Support for loadable net-drivers */
4631 struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
4632 unsigned char name_assign_type,
4633 void (*setup)(struct net_device *),
4634 unsigned int txqs, unsigned int rxqs);
4635 #define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \
4636 alloc_netdev_mqs(sizeof_priv, name, name_assign_type, setup, 1, 1)
4638 #define alloc_netdev_mq(sizeof_priv, name, name_assign_type, setup, count) \
4639 alloc_netdev_mqs(sizeof_priv, name, name_assign_type, setup, count, \
4642 int register_netdev(struct net_device *dev);
4643 void unregister_netdev(struct net_device *dev);
4645 int devm_register_netdev(struct device *dev, struct net_device *ndev);
4647 /* General hardware address lists handling functions */
4648 int __hw_addr_sync(struct netdev_hw_addr_list *to_list,
4649 struct netdev_hw_addr_list *from_list, int addr_len);
4650 void __hw_addr_unsync(struct netdev_hw_addr_list *to_list,
4651 struct netdev_hw_addr_list *from_list, int addr_len);
4652 int __hw_addr_sync_dev(struct netdev_hw_addr_list *list,
4653 struct net_device *dev,
4654 int (*sync)(struct net_device *, const unsigned char *),
4655 int (*unsync)(struct net_device *,
4656 const unsigned char *));
4657 int __hw_addr_ref_sync_dev(struct netdev_hw_addr_list *list,
4658 struct net_device *dev,
4659 int (*sync)(struct net_device *,
4660 const unsigned char *, int),
4661 int (*unsync)(struct net_device *,
4662 const unsigned char *, int));
4663 void __hw_addr_ref_unsync_dev(struct netdev_hw_addr_list *list,
4664 struct net_device *dev,
4665 int (*unsync)(struct net_device *,
4666 const unsigned char *, int));
4667 void __hw_addr_unsync_dev(struct netdev_hw_addr_list *list,
4668 struct net_device *dev,
4669 int (*unsync)(struct net_device *,
4670 const unsigned char *));
4671 void __hw_addr_init(struct netdev_hw_addr_list *list);
4673 /* Functions used for device addresses handling */
4675 __dev_addr_set(struct net_device *dev, const u8 *addr, size_t len)
4677 memcpy(dev->dev_addr, addr, len);
4680 static inline void dev_addr_set(struct net_device *dev, const u8 *addr)
4682 __dev_addr_set(dev, addr, dev->addr_len);
4686 dev_addr_mod(struct net_device *dev, unsigned int offset,
4687 const u8 *addr, size_t len)
4689 memcpy(&dev->dev_addr[offset], addr, len);
4692 int dev_addr_add(struct net_device *dev, const unsigned char *addr,
4693 unsigned char addr_type);
4694 int dev_addr_del(struct net_device *dev, const unsigned char *addr,
4695 unsigned char addr_type);
4696 void dev_addr_flush(struct net_device *dev);
4697 int dev_addr_init(struct net_device *dev);
4699 /* Functions used for unicast addresses handling */
4700 int dev_uc_add(struct net_device *dev, const unsigned char *addr);
4701 int dev_uc_add_excl(struct net_device *dev, const unsigned char *addr);
4702 int dev_uc_del(struct net_device *dev, const unsigned char *addr);
4703 int dev_uc_sync(struct net_device *to, struct net_device *from);
4704 int dev_uc_sync_multiple(struct net_device *to, struct net_device *from);
4705 void dev_uc_unsync(struct net_device *to, struct net_device *from);
4706 void dev_uc_flush(struct net_device *dev);
4707 void dev_uc_init(struct net_device *dev);
4710 * __dev_uc_sync - Synchonize device's unicast list
4711 * @dev: device to sync
4712 * @sync: function to call if address should be added
4713 * @unsync: function to call if address should be removed
4715 * Add newly added addresses to the interface, and release
4716 * addresses that have been deleted.
4718 static inline int __dev_uc_sync(struct net_device *dev,
4719 int (*sync)(struct net_device *,
4720 const unsigned char *),
4721 int (*unsync)(struct net_device *,
4722 const unsigned char *))
4724 return __hw_addr_sync_dev(&dev->uc, dev, sync, unsync);
4728 * __dev_uc_unsync - Remove synchronized addresses from device
4729 * @dev: device to sync
4730 * @unsync: function to call if address should be removed
4732 * Remove all addresses that were added to the device by dev_uc_sync().
4734 static inline void __dev_uc_unsync(struct net_device *dev,
4735 int (*unsync)(struct net_device *,
4736 const unsigned char *))
4738 __hw_addr_unsync_dev(&dev->uc, dev, unsync);
4741 /* Functions used for multicast addresses handling */
4742 int dev_mc_add(struct net_device *dev, const unsigned char *addr);
4743 int dev_mc_add_global(struct net_device *dev, const unsigned char *addr);
4744 int dev_mc_add_excl(struct net_device *dev, const unsigned char *addr);
4745 int dev_mc_del(struct net_device *dev, const unsigned char *addr);
4746 int dev_mc_del_global(struct net_device *dev, const unsigned char *addr);
4747 int dev_mc_sync(struct net_device *to, struct net_device *from);
4748 int dev_mc_sync_multiple(struct net_device *to, struct net_device *from);
4749 void dev_mc_unsync(struct net_device *to, struct net_device *from);
4750 void dev_mc_flush(struct net_device *dev);
4751 void dev_mc_init(struct net_device *dev);
4754 * __dev_mc_sync - Synchonize device's multicast list
4755 * @dev: device to sync
4756 * @sync: function to call if address should be added
4757 * @unsync: function to call if address should be removed
4759 * Add newly added addresses to the interface, and release
4760 * addresses that have been deleted.
4762 static inline int __dev_mc_sync(struct net_device *dev,
4763 int (*sync)(struct net_device *,
4764 const unsigned char *),
4765 int (*unsync)(struct net_device *,
4766 const unsigned char *))
4768 return __hw_addr_sync_dev(&dev->mc, dev, sync, unsync);
4772 * __dev_mc_unsync - Remove synchronized addresses from device
4773 * @dev: device to sync
4774 * @unsync: function to call if address should be removed
4776 * Remove all addresses that were added to the device by dev_mc_sync().
4778 static inline void __dev_mc_unsync(struct net_device *dev,
4779 int (*unsync)(struct net_device *,
4780 const unsigned char *))
4782 __hw_addr_unsync_dev(&dev->mc, dev, unsync);
4785 /* Functions used for secondary unicast and multicast support */
4786 void dev_set_rx_mode(struct net_device *dev);
4787 void __dev_set_rx_mode(struct net_device *dev);
4788 int dev_set_promiscuity(struct net_device *dev, int inc);
4789 int dev_set_allmulti(struct net_device *dev, int inc);
4790 void netdev_state_change(struct net_device *dev);
4791 void __netdev_notify_peers(struct net_device *dev);
4792 void netdev_notify_peers(struct net_device *dev);
4793 void netdev_features_change(struct net_device *dev);
4794 /* Load a device via the kmod */
4795 void dev_load(struct net *net, const char *name);
4796 struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
4797 struct rtnl_link_stats64 *storage);
4798 void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64,
4799 const struct net_device_stats *netdev_stats);
4800 void dev_fetch_sw_netstats(struct rtnl_link_stats64 *s,
4801 const struct pcpu_sw_netstats __percpu *netstats);
4802 void dev_get_tstats64(struct net_device *dev, struct rtnl_link_stats64 *s);
4804 extern int netdev_max_backlog;
4805 extern int netdev_tstamp_prequeue;
4806 extern int netdev_unregister_timeout_secs;
4807 extern int weight_p;
4808 extern int dev_weight_rx_bias;
4809 extern int dev_weight_tx_bias;
4810 extern int dev_rx_weight;
4811 extern int dev_tx_weight;
4812 extern int gro_normal_batch;
4815 NESTED_SYNC_IMM_BIT,
4816 NESTED_SYNC_TODO_BIT,
4819 #define __NESTED_SYNC_BIT(bit) ((u32)1 << (bit))
4820 #define __NESTED_SYNC(name) __NESTED_SYNC_BIT(NESTED_SYNC_ ## name ## _BIT)
4822 #define NESTED_SYNC_IMM __NESTED_SYNC(IMM)
4823 #define NESTED_SYNC_TODO __NESTED_SYNC(TODO)
4825 struct netdev_nested_priv {
4826 unsigned char flags;
4830 bool netdev_has_upper_dev(struct net_device *dev, struct net_device *upper_dev);
4831 struct net_device *netdev_upper_get_next_dev_rcu(struct net_device *dev,
4832 struct list_head **iter);
4833 struct net_device *netdev_all_upper_get_next_dev_rcu(struct net_device *dev,
4834 struct list_head **iter);
4836 #ifdef CONFIG_LOCKDEP
4837 static LIST_HEAD(net_unlink_list);
4839 static inline void net_unlink_todo(struct net_device *dev)
4841 if (list_empty(&dev->unlink_list))
4842 list_add_tail(&dev->unlink_list, &net_unlink_list);
4846 /* iterate through upper list, must be called under RCU read lock */
4847 #define netdev_for_each_upper_dev_rcu(dev, updev, iter) \
4848 for (iter = &(dev)->adj_list.upper, \
4849 updev = netdev_upper_get_next_dev_rcu(dev, &(iter)); \
4851 updev = netdev_upper_get_next_dev_rcu(dev, &(iter)))
4853 int netdev_walk_all_upper_dev_rcu(struct net_device *dev,
4854 int (*fn)(struct net_device *upper_dev,
4855 struct netdev_nested_priv *priv),
4856 struct netdev_nested_priv *priv);
4858 bool netdev_has_upper_dev_all_rcu(struct net_device *dev,
4859 struct net_device *upper_dev);
4861 bool netdev_has_any_upper_dev(struct net_device *dev);
4863 void *netdev_lower_get_next_private(struct net_device *dev,
4864 struct list_head **iter);
4865 void *netdev_lower_get_next_private_rcu(struct net_device *dev,
4866 struct list_head **iter);
4868 #define netdev_for_each_lower_private(dev, priv, iter) \
4869 for (iter = (dev)->adj_list.lower.next, \
4870 priv = netdev_lower_get_next_private(dev, &(iter)); \
4872 priv = netdev_lower_get_next_private(dev, &(iter)))
4874 #define netdev_for_each_lower_private_rcu(dev, priv, iter) \
4875 for (iter = &(dev)->adj_list.lower, \
4876 priv = netdev_lower_get_next_private_rcu(dev, &(iter)); \
4878 priv = netdev_lower_get_next_private_rcu(dev, &(iter)))
4880 void *netdev_lower_get_next(struct net_device *dev,
4881 struct list_head **iter);
4883 #define netdev_for_each_lower_dev(dev, ldev, iter) \
4884 for (iter = (dev)->adj_list.lower.next, \
4885 ldev = netdev_lower_get_next(dev, &(iter)); \
4887 ldev = netdev_lower_get_next(dev, &(iter)))
4889 struct net_device *netdev_next_lower_dev_rcu(struct net_device *dev,
4890 struct list_head **iter);
4891 int netdev_walk_all_lower_dev(struct net_device *dev,
4892 int (*fn)(struct net_device *lower_dev,
4893 struct netdev_nested_priv *priv),
4894 struct netdev_nested_priv *priv);
4895 int netdev_walk_all_lower_dev_rcu(struct net_device *dev,
4896 int (*fn)(struct net_device *lower_dev,
4897 struct netdev_nested_priv *priv),
4898 struct netdev_nested_priv *priv);
4900 void *netdev_adjacent_get_private(struct list_head *adj_list);
4901 void *netdev_lower_get_first_private_rcu(struct net_device *dev);
4902 struct net_device *netdev_master_upper_dev_get(struct net_device *dev);
4903 struct net_device *netdev_master_upper_dev_get_rcu(struct net_device *dev);
4904 int netdev_upper_dev_link(struct net_device *dev, struct net_device *upper_dev,
4905 struct netlink_ext_ack *extack);
4906 int netdev_master_upper_dev_link(struct net_device *dev,
4907 struct net_device *upper_dev,
4908 void *upper_priv, void *upper_info,
4909 struct netlink_ext_ack *extack);
4910 void netdev_upper_dev_unlink(struct net_device *dev,
4911 struct net_device *upper_dev);
4912 int netdev_adjacent_change_prepare(struct net_device *old_dev,
4913 struct net_device *new_dev,
4914 struct net_device *dev,
4915 struct netlink_ext_ack *extack);
4916 void netdev_adjacent_change_commit(struct net_device *old_dev,
4917 struct net_device *new_dev,
4918 struct net_device *dev);
4919 void netdev_adjacent_change_abort(struct net_device *old_dev,
4920 struct net_device *new_dev,
4921 struct net_device *dev);
4922 void netdev_adjacent_rename_links(struct net_device *dev, char *oldname);
4923 void *netdev_lower_dev_get_private(struct net_device *dev,
4924 struct net_device *lower_dev);
4925 void netdev_lower_state_changed(struct net_device *lower_dev,
4926 void *lower_state_info);
4928 /* RSS keys are 40 or 52 bytes long */
4929 #define NETDEV_RSS_KEY_LEN 52
4930 extern u8 netdev_rss_key[NETDEV_RSS_KEY_LEN] __read_mostly;
4931 void netdev_rss_key_fill(void *buffer, size_t len);
4933 int skb_checksum_help(struct sk_buff *skb);
4934 int skb_crc32c_csum_help(struct sk_buff *skb);
4935 int skb_csum_hwoffload_help(struct sk_buff *skb,
4936 const netdev_features_t features);
4938 struct sk_buff *__skb_gso_segment(struct sk_buff *skb,
4939 netdev_features_t features, bool tx_path);
4940 struct sk_buff *skb_mac_gso_segment(struct sk_buff *skb,
4941 netdev_features_t features);
4943 struct netdev_bonding_info {
4948 struct netdev_notifier_bonding_info {
4949 struct netdev_notifier_info info; /* must be first */
4950 struct netdev_bonding_info bonding_info;
4953 void netdev_bonding_info_change(struct net_device *dev,
4954 struct netdev_bonding_info *bonding_info);
4956 #if IS_ENABLED(CONFIG_ETHTOOL_NETLINK)
4957 void ethtool_notify(struct net_device *dev, unsigned int cmd, const void *data);
4959 static inline void ethtool_notify(struct net_device *dev, unsigned int cmd,
4966 struct sk_buff *skb_gso_segment(struct sk_buff *skb, netdev_features_t features)
4968 return __skb_gso_segment(skb, features, true);
4970 __be16 skb_network_protocol(struct sk_buff *skb, int *depth);
4972 static inline bool can_checksum_protocol(netdev_features_t features,
4975 if (protocol == htons(ETH_P_FCOE))
4976 return !!(features & NETIF_F_FCOE_CRC);
4978 /* Assume this is an IP checksum (not SCTP CRC) */
4980 if (features & NETIF_F_HW_CSUM) {
4981 /* Can checksum everything */
4986 case htons(ETH_P_IP):
4987 return !!(features & NETIF_F_IP_CSUM);
4988 case htons(ETH_P_IPV6):
4989 return !!(features & NETIF_F_IPV6_CSUM);
4996 void netdev_rx_csum_fault(struct net_device *dev, struct sk_buff *skb);
4998 static inline void netdev_rx_csum_fault(struct net_device *dev,
4999 struct sk_buff *skb)
5003 /* rx skb timestamps */
5004 void net_enable_timestamp(void);
5005 void net_disable_timestamp(void);
5007 #ifdef CONFIG_PROC_FS
5008 int __init dev_proc_init(void);
5010 #define dev_proc_init() 0
5013 static inline netdev_tx_t __netdev_start_xmit(const struct net_device_ops *ops,
5014 struct sk_buff *skb, struct net_device *dev,
5017 __this_cpu_write(softnet_data.xmit.more, more);
5018 return ops->ndo_start_xmit(skb, dev);
5021 static inline bool netdev_xmit_more(void)
5023 return __this_cpu_read(softnet_data.xmit.more);
5026 static inline netdev_tx_t netdev_start_xmit(struct sk_buff *skb, struct net_device *dev,
5027 struct netdev_queue *txq, bool more)
5029 const struct net_device_ops *ops = dev->netdev_ops;
5032 rc = __netdev_start_xmit(ops, skb, dev, more);
5033 if (rc == NETDEV_TX_OK)
5034 txq_trans_update(txq);
5039 int netdev_class_create_file_ns(const struct class_attribute *class_attr,
5041 void netdev_class_remove_file_ns(const struct class_attribute *class_attr,
5044 extern const struct kobj_ns_type_operations net_ns_type_operations;
5046 const char *netdev_drivername(const struct net_device *dev);
5048 void linkwatch_run_queue(void);
5050 static inline netdev_features_t netdev_intersect_features(netdev_features_t f1,
5051 netdev_features_t f2)
5053 if ((f1 ^ f2) & NETIF_F_HW_CSUM) {
5054 if (f1 & NETIF_F_HW_CSUM)
5055 f1 |= (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM);
5057 f2 |= (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM);
5063 static inline netdev_features_t netdev_get_wanted_features(
5064 struct net_device *dev)
5066 return (dev->features & ~dev->hw_features) | dev->wanted_features;
5068 netdev_features_t netdev_increment_features(netdev_features_t all,
5069 netdev_features_t one, netdev_features_t mask);
5071 /* Allow TSO being used on stacked device :
5072 * Performing the GSO segmentation before last device
5073 * is a performance improvement.
5075 static inline netdev_features_t netdev_add_tso_features(netdev_features_t features,
5076 netdev_features_t mask)
5078 return netdev_increment_features(features, NETIF_F_ALL_TSO, mask);
5081 int __netdev_update_features(struct net_device *dev);
5082 void netdev_update_features(struct net_device *dev);
5083 void netdev_change_features(struct net_device *dev);
5085 void netif_stacked_transfer_operstate(const struct net_device *rootdev,
5086 struct net_device *dev);
5088 netdev_features_t passthru_features_check(struct sk_buff *skb,
5089 struct net_device *dev,
5090 netdev_features_t features);
5091 netdev_features_t netif_skb_features(struct sk_buff *skb);
5093 static inline bool net_gso_ok(netdev_features_t features, int gso_type)
5095 netdev_features_t feature = (netdev_features_t)gso_type << NETIF_F_GSO_SHIFT;
5097 /* check flags correspondence */
5098 BUILD_BUG_ON(SKB_GSO_TCPV4 != (NETIF_F_TSO >> NETIF_F_GSO_SHIFT));
5099 BUILD_BUG_ON(SKB_GSO_DODGY != (NETIF_F_GSO_ROBUST >> NETIF_F_GSO_SHIFT));
5100 BUILD_BUG_ON(SKB_GSO_TCP_ECN != (NETIF_F_TSO_ECN >> NETIF_F_GSO_SHIFT));
5101 BUILD_BUG_ON(SKB_GSO_TCP_FIXEDID != (NETIF_F_TSO_MANGLEID >> NETIF_F_GSO_SHIFT));
5102 BUILD_BUG_ON(SKB_GSO_TCPV6 != (NETIF_F_TSO6 >> NETIF_F_GSO_SHIFT));
5103 BUILD_BUG_ON(SKB_GSO_FCOE != (NETIF_F_FSO >> NETIF_F_GSO_SHIFT));
5104 BUILD_BUG_ON(SKB_GSO_GRE != (NETIF_F_GSO_GRE >> NETIF_F_GSO_SHIFT));
5105 BUILD_BUG_ON(SKB_GSO_GRE_CSUM != (NETIF_F_GSO_GRE_CSUM >> NETIF_F_GSO_SHIFT));
5106 BUILD_BUG_ON(SKB_GSO_IPXIP4 != (NETIF_F_GSO_IPXIP4 >> NETIF_F_GSO_SHIFT));
5107 BUILD_BUG_ON(SKB_GSO_IPXIP6 != (NETIF_F_GSO_IPXIP6 >> NETIF_F_GSO_SHIFT));
5108 BUILD_BUG_ON(SKB_GSO_UDP_TUNNEL != (NETIF_F_GSO_UDP_TUNNEL >> NETIF_F_GSO_SHIFT));
5109 BUILD_BUG_ON(SKB_GSO_UDP_TUNNEL_CSUM != (NETIF_F_GSO_UDP_TUNNEL_CSUM >> NETIF_F_GSO_SHIFT));
5110 BUILD_BUG_ON(SKB_GSO_PARTIAL != (NETIF_F_GSO_PARTIAL >> NETIF_F_GSO_SHIFT));
5111 BUILD_BUG_ON(SKB_GSO_TUNNEL_REMCSUM != (NETIF_F_GSO_TUNNEL_REMCSUM >> NETIF_F_GSO_SHIFT));
5112 BUILD_BUG_ON(SKB_GSO_SCTP != (NETIF_F_GSO_SCTP >> NETIF_F_GSO_SHIFT));
5113 BUILD_BUG_ON(SKB_GSO_ESP != (NETIF_F_GSO_ESP >> NETIF_F_GSO_SHIFT));
5114 BUILD_BUG_ON(SKB_GSO_UDP != (NETIF_F_GSO_UDP >> NETIF_F_GSO_SHIFT));
5115 BUILD_BUG_ON(SKB_GSO_UDP_L4 != (NETIF_F_GSO_UDP_L4 >> NETIF_F_GSO_SHIFT));
5116 BUILD_BUG_ON(SKB_GSO_FRAGLIST != (NETIF_F_GSO_FRAGLIST >> NETIF_F_GSO_SHIFT));
5118 return (features & feature) == feature;
5121 static inline bool skb_gso_ok(struct sk_buff *skb, netdev_features_t features)
5123 return net_gso_ok(features, skb_shinfo(skb)->gso_type) &&
5124 (!skb_has_frag_list(skb) || (features & NETIF_F_FRAGLIST));
5127 static inline bool netif_needs_gso(struct sk_buff *skb,
5128 netdev_features_t features)
5130 return skb_is_gso(skb) && (!skb_gso_ok(skb, features) ||
5131 unlikely((skb->ip_summed != CHECKSUM_PARTIAL) &&
5132 (skb->ip_summed != CHECKSUM_UNNECESSARY)));
5135 static inline void netif_set_gso_max_size(struct net_device *dev,
5138 dev->gso_max_size = size;
5141 static inline void skb_gso_error_unwind(struct sk_buff *skb, __be16 protocol,
5142 int pulled_hlen, u16 mac_offset,
5145 skb->protocol = protocol;
5146 skb->encapsulation = 1;
5147 skb_push(skb, pulled_hlen);
5148 skb_reset_transport_header(skb);
5149 skb->mac_header = mac_offset;
5150 skb->network_header = skb->mac_header + mac_len;
5151 skb->mac_len = mac_len;
5154 static inline bool netif_is_macsec(const struct net_device *dev)
5156 return dev->priv_flags & IFF_MACSEC;
5159 static inline bool netif_is_macvlan(const struct net_device *dev)
5161 return dev->priv_flags & IFF_MACVLAN;
5164 static inline bool netif_is_macvlan_port(const struct net_device *dev)
5166 return dev->priv_flags & IFF_MACVLAN_PORT;
5169 static inline bool netif_is_bond_master(const struct net_device *dev)
5171 return dev->flags & IFF_MASTER && dev->priv_flags & IFF_BONDING;
5174 static inline bool netif_is_bond_slave(const struct net_device *dev)
5176 return dev->flags & IFF_SLAVE && dev->priv_flags & IFF_BONDING;
5179 static inline bool netif_supports_nofcs(struct net_device *dev)
5181 return dev->priv_flags & IFF_SUPP_NOFCS;
5184 static inline bool netif_has_l3_rx_handler(const struct net_device *dev)
5186 return dev->priv_flags & IFF_L3MDEV_RX_HANDLER;
5189 static inline bool netif_is_l3_master(const struct net_device *dev)
5191 return dev->priv_flags & IFF_L3MDEV_MASTER;
5194 static inline bool netif_is_l3_slave(const struct net_device *dev)
5196 return dev->priv_flags & IFF_L3MDEV_SLAVE;
5199 static inline int dev_sdif(const struct net_device *dev)
5201 #ifdef CONFIG_NET_L3_MASTER_DEV
5202 if (netif_is_l3_slave(dev))
5203 return dev->ifindex;
5208 static inline bool netif_is_bridge_master(const struct net_device *dev)
5210 return dev->priv_flags & IFF_EBRIDGE;
5213 static inline bool netif_is_bridge_port(const struct net_device *dev)
5215 return dev->priv_flags & IFF_BRIDGE_PORT;
5218 static inline bool netif_is_ovs_master(const struct net_device *dev)
5220 return dev->priv_flags & IFF_OPENVSWITCH;
5223 static inline bool netif_is_ovs_port(const struct net_device *dev)
5225 return dev->priv_flags & IFF_OVS_DATAPATH;
5228 static inline bool netif_is_any_bridge_port(const struct net_device *dev)
5230 return netif_is_bridge_port(dev) || netif_is_ovs_port(dev);
5233 static inline bool netif_is_team_master(const struct net_device *dev)
5235 return dev->priv_flags & IFF_TEAM;
5238 static inline bool netif_is_team_port(const struct net_device *dev)
5240 return dev->priv_flags & IFF_TEAM_PORT;
5243 static inline bool netif_is_lag_master(const struct net_device *dev)
5245 return netif_is_bond_master(dev) || netif_is_team_master(dev);
5248 static inline bool netif_is_lag_port(const struct net_device *dev)
5250 return netif_is_bond_slave(dev) || netif_is_team_port(dev);
5253 static inline bool netif_is_rxfh_configured(const struct net_device *dev)
5255 return dev->priv_flags & IFF_RXFH_CONFIGURED;
5258 static inline bool netif_is_failover(const struct net_device *dev)
5260 return dev->priv_flags & IFF_FAILOVER;
5263 static inline bool netif_is_failover_slave(const struct net_device *dev)
5265 return dev->priv_flags & IFF_FAILOVER_SLAVE;
5268 /* This device needs to keep skb dst for qdisc enqueue or ndo_start_xmit() */
5269 static inline void netif_keep_dst(struct net_device *dev)
5271 dev->priv_flags &= ~(IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM);
5274 /* return true if dev can't cope with mtu frames that need vlan tag insertion */
5275 static inline bool netif_reduces_vlan_mtu(struct net_device *dev)
5277 /* TODO: reserve and use an additional IFF bit, if we get more users */
5278 return dev->priv_flags & IFF_MACSEC;
5281 extern struct pernet_operations __net_initdata loopback_net_ops;
5283 /* Logging, debugging and troubleshooting/diagnostic helpers. */
5285 /* netdev_printk helpers, similar to dev_printk */
5287 static inline const char *netdev_name(const struct net_device *dev)
5289 if (!dev->name[0] || strchr(dev->name, '%'))
5290 return "(unnamed net_device)";
5294 static inline bool netdev_unregistering(const struct net_device *dev)
5296 return dev->reg_state == NETREG_UNREGISTERING;
5299 static inline const char *netdev_reg_state(const struct net_device *dev)
5301 switch (dev->reg_state) {
5302 case NETREG_UNINITIALIZED: return " (uninitialized)";
5303 case NETREG_REGISTERED: return "";
5304 case NETREG_UNREGISTERING: return " (unregistering)";
5305 case NETREG_UNREGISTERED: return " (unregistered)";
5306 case NETREG_RELEASED: return " (released)";
5307 case NETREG_DUMMY: return " (dummy)";
5310 WARN_ONCE(1, "%s: unknown reg_state %d\n", dev->name, dev->reg_state);
5311 return " (unknown)";
5314 __printf(3, 4) __cold
5315 void netdev_printk(const char *level, const struct net_device *dev,
5316 const char *format, ...);
5317 __printf(2, 3) __cold
5318 void netdev_emerg(const struct net_device *dev, const char *format, ...);
5319 __printf(2, 3) __cold
5320 void netdev_alert(const struct net_device *dev, const char *format, ...);
5321 __printf(2, 3) __cold
5322 void netdev_crit(const struct net_device *dev, const char *format, ...);
5323 __printf(2, 3) __cold
5324 void netdev_err(const struct net_device *dev, const char *format, ...);
5325 __printf(2, 3) __cold
5326 void netdev_warn(const struct net_device *dev, const char *format, ...);
5327 __printf(2, 3) __cold
5328 void netdev_notice(const struct net_device *dev, const char *format, ...);
5329 __printf(2, 3) __cold
5330 void netdev_info(const struct net_device *dev, const char *format, ...);
5332 #define netdev_level_once(level, dev, fmt, ...) \
5334 static bool __print_once __read_mostly; \
5336 if (!__print_once) { \
5337 __print_once = true; \
5338 netdev_printk(level, dev, fmt, ##__VA_ARGS__); \
5342 #define netdev_emerg_once(dev, fmt, ...) \
5343 netdev_level_once(KERN_EMERG, dev, fmt, ##__VA_ARGS__)
5344 #define netdev_alert_once(dev, fmt, ...) \
5345 netdev_level_once(KERN_ALERT, dev, fmt, ##__VA_ARGS__)
5346 #define netdev_crit_once(dev, fmt, ...) \
5347 netdev_level_once(KERN_CRIT, dev, fmt, ##__VA_ARGS__)
5348 #define netdev_err_once(dev, fmt, ...) \
5349 netdev_level_once(KERN_ERR, dev, fmt, ##__VA_ARGS__)
5350 #define netdev_warn_once(dev, fmt, ...) \
5351 netdev_level_once(KERN_WARNING, dev, fmt, ##__VA_ARGS__)
5352 #define netdev_notice_once(dev, fmt, ...) \
5353 netdev_level_once(KERN_NOTICE, dev, fmt, ##__VA_ARGS__)
5354 #define netdev_info_once(dev, fmt, ...) \
5355 netdev_level_once(KERN_INFO, dev, fmt, ##__VA_ARGS__)
5357 #define MODULE_ALIAS_NETDEV(device) \
5358 MODULE_ALIAS("netdev-" device)
5360 #if defined(CONFIG_DYNAMIC_DEBUG) || \
5361 (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
5362 #define netdev_dbg(__dev, format, args...) \
5364 dynamic_netdev_dbg(__dev, format, ##args); \
5366 #elif defined(DEBUG)
5367 #define netdev_dbg(__dev, format, args...) \
5368 netdev_printk(KERN_DEBUG, __dev, format, ##args)
5370 #define netdev_dbg(__dev, format, args...) \
5373 netdev_printk(KERN_DEBUG, __dev, format, ##args); \
5377 #if defined(VERBOSE_DEBUG)
5378 #define netdev_vdbg netdev_dbg
5381 #define netdev_vdbg(dev, format, args...) \
5384 netdev_printk(KERN_DEBUG, dev, format, ##args); \
5390 * netdev_WARN() acts like dev_printk(), but with the key difference
5391 * of using a WARN/WARN_ON to get the message out, including the
5392 * file/line information and a backtrace.
5394 #define netdev_WARN(dev, format, args...) \
5395 WARN(1, "netdevice: %s%s: " format, netdev_name(dev), \
5396 netdev_reg_state(dev), ##args)
5398 #define netdev_WARN_ONCE(dev, format, args...) \
5399 WARN_ONCE(1, "netdevice: %s%s: " format, netdev_name(dev), \
5400 netdev_reg_state(dev), ##args)
5402 /* netif printk helpers, similar to netdev_printk */
5404 #define netif_printk(priv, type, level, dev, fmt, args...) \
5406 if (netif_msg_##type(priv)) \
5407 netdev_printk(level, (dev), fmt, ##args); \
5410 #define netif_level(level, priv, type, dev, fmt, args...) \
5412 if (netif_msg_##type(priv)) \
5413 netdev_##level(dev, fmt, ##args); \
5416 #define netif_emerg(priv, type, dev, fmt, args...) \
5417 netif_level(emerg, priv, type, dev, fmt, ##args)
5418 #define netif_alert(priv, type, dev, fmt, args...) \
5419 netif_level(alert, priv, type, dev, fmt, ##args)
5420 #define netif_crit(priv, type, dev, fmt, args...) \
5421 netif_level(crit, priv, type, dev, fmt, ##args)
5422 #define netif_err(priv, type, dev, fmt, args...) \
5423 netif_level(err, priv, type, dev, fmt, ##args)
5424 #define netif_warn(priv, type, dev, fmt, args...) \
5425 netif_level(warn, priv, type, dev, fmt, ##args)
5426 #define netif_notice(priv, type, dev, fmt, args...) \
5427 netif_level(notice, priv, type, dev, fmt, ##args)
5428 #define netif_info(priv, type, dev, fmt, args...) \
5429 netif_level(info, priv, type, dev, fmt, ##args)
5431 #if defined(CONFIG_DYNAMIC_DEBUG) || \
5432 (defined(CONFIG_DYNAMIC_DEBUG_CORE) && defined(DYNAMIC_DEBUG_MODULE))
5433 #define netif_dbg(priv, type, netdev, format, args...) \
5435 if (netif_msg_##type(priv)) \
5436 dynamic_netdev_dbg(netdev, format, ##args); \
5438 #elif defined(DEBUG)
5439 #define netif_dbg(priv, type, dev, format, args...) \
5440 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args)
5442 #define netif_dbg(priv, type, dev, format, args...) \
5445 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \
5450 /* if @cond then downgrade to debug, else print at @level */
5451 #define netif_cond_dbg(priv, type, netdev, cond, level, fmt, args...) \
5454 netif_dbg(priv, type, netdev, fmt, ##args); \
5456 netif_ ## level(priv, type, netdev, fmt, ##args); \
5459 #if defined(VERBOSE_DEBUG)
5460 #define netif_vdbg netif_dbg
5462 #define netif_vdbg(priv, type, dev, format, args...) \
5465 netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \
5471 * The list of packet types we will receive (as opposed to discard)
5472 * and the routines to invoke.
5474 * Why 16. Because with 16 the only overlap we get on a hash of the
5475 * low nibble of the protocol value is RARP/SNAP/X.25.
5489 #define PTYPE_HASH_SIZE (16)
5490 #define PTYPE_HASH_MASK (PTYPE_HASH_SIZE - 1)
5492 extern struct list_head ptype_all __read_mostly;
5493 extern struct list_head ptype_base[PTYPE_HASH_SIZE] __read_mostly;
5495 extern struct net_device *blackhole_netdev;
5497 /* Note: Avoid these macros in fast path, prefer per-cpu or per-queue counters. */
5498 #define DEV_STATS_INC(DEV, FIELD) atomic_long_inc(&(DEV)->stats.__##FIELD)
5499 #define DEV_STATS_ADD(DEV, FIELD, VAL) \
5500 atomic_long_add((VAL), &(DEV)->stats.__##FIELD)
5502 #endif /* _LINUX_NETDEVICE_H */