xref: /linux/include/linux/netdevice.h (revision 207dd12bc195153fe6ca614d8add9ecb0b636270)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
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.
6  *
7  *		Definitions for the Interfaces handler.
8  *
9  * Version:	@(#)dev.h	1.0.10	08/12/93
10  *
11  * Authors:	Ross Biro
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>
18  *
19  *		Moved to /usr/include/linux for NET3
20  */
21 #ifndef _LINUX_NETDEVICE_H
22 #define _LINUX_NETDEVICE_H
23 
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>
31 #include <asm/local.h>
32 
33 #include <linux/percpu.h>
34 #include <linux/rculist.h>
35 #include <linux/workqueue.h>
36 #include <linux/dynamic_queue_limits.h>
37 
38 #include <net/net_namespace.h>
39 #ifdef CONFIG_DCB
40 #include <net/dcbnl.h>
41 #endif
42 #include <net/netprio_cgroup.h>
43 #include <linux/netdev_features.h>
44 #include <linux/neighbour.h>
45 #include <linux/netdevice_xmit.h>
46 #include <uapi/linux/netdevice.h>
47 #include <uapi/linux/if_bonding.h>
48 #include <uapi/linux/pkt_cls.h>
49 #include <uapi/linux/netdev.h>
50 #include <linux/hashtable.h>
51 #include <linux/rbtree.h>
52 #include <net/net_trackers.h>
53 #include <net/net_debug.h>
54 #include <net/dropreason-core.h>
55 #include <net/neighbour_tables.h>
56 
57 struct netpoll_info;
58 struct device;
59 struct ethtool_ops;
60 struct kernel_hwtstamp_config;
61 struct phy_device;
62 struct dsa_port;
63 struct ip_tunnel_parm_kern;
64 struct macsec_context;
65 struct macsec_ops;
66 struct netdev_config;
67 struct netdev_name_node;
68 struct sd_flow_limit;
69 struct sfp_bus;
70 /* 802.11 specific */
71 struct wireless_dev;
72 /* 802.15.4 specific */
73 struct wpan_dev;
74 struct mpls_dev;
75 /* UDP Tunnel offloads */
76 struct udp_tunnel_info;
77 struct udp_tunnel_nic_info;
78 struct udp_tunnel_nic;
79 struct bpf_prog;
80 struct xdp_buff;
81 struct xdp_frame;
82 struct xdp_metadata_ops;
83 struct xdp_md;
84 struct ethtool_netdev_state;
85 struct phy_link_topology;
86 struct hwtstamp_provider;
87 
88 typedef u32 xdp_features_t;
89 
90 void synchronize_net(void);
91 void netdev_set_default_ethtool_ops(struct net_device *dev,
92 				    const struct ethtool_ops *ops);
93 void netdev_sw_irq_coalesce_default_on(struct net_device *dev);
94 
95 /* Backlog congestion levels */
96 #define NET_RX_SUCCESS		0	/* keep 'em coming, baby */
97 #define NET_RX_DROP		1	/* packet dropped */
98 
99 #define MAX_NEST_DEV 8
100 
101 /*
102  * Transmit return codes: transmit return codes originate from three different
103  * namespaces:
104  *
105  * - qdisc return codes
106  * - driver transmit return codes
107  * - errno values
108  *
109  * Drivers are allowed to return any one of those in their hard_start_xmit()
110  * function. Real network devices commonly used with qdiscs should only return
111  * the driver transmit return codes though - when qdiscs are used, the actual
112  * transmission happens asynchronously, so the value is not propagated to
113  * higher layers. Virtual network devices transmit synchronously; in this case
114  * the driver transmit return codes are consumed by dev_queue_xmit(), and all
115  * others are propagated to higher layers.
116  */
117 
118 /* qdisc ->enqueue() return codes. */
119 #define NET_XMIT_SUCCESS	0x00
120 #define NET_XMIT_DROP		0x01	/* skb dropped			*/
121 #define NET_XMIT_CN		0x02	/* congestion notification	*/
122 #define NET_XMIT_MASK		0x0f	/* qdisc flags in net/sch_generic.h */
123 
124 /* NET_XMIT_CN is special. It does not guarantee that this packet is lost. It
125  * indicates that the device will soon be dropping packets, or already drops
126  * some packets of the same priority; prompting us to send less aggressively. */
127 #define net_xmit_eval(e)	((e) == NET_XMIT_CN ? 0 : (e))
128 #define net_xmit_errno(e)	((e) != NET_XMIT_CN ? -ENOBUFS : 0)
129 
130 /* Driver transmit return codes */
131 #define NETDEV_TX_MASK		0xf0
132 
133 enum netdev_tx {
134 	__NETDEV_TX_MIN	 = INT_MIN,	/* make sure enum is signed */
135 	NETDEV_TX_OK	 = 0x00,	/* driver took care of packet */
136 	NETDEV_TX_BUSY	 = 0x10,	/* driver tx path was busy*/
137 };
138 typedef enum netdev_tx netdev_tx_t;
139 
140 /*
141  * Current order: NETDEV_TX_MASK > NET_XMIT_MASK >= 0 is significant;
142  * hard_start_xmit() return < NET_XMIT_MASK means skb was consumed.
143  */
144 static inline bool dev_xmit_complete(int rc)
145 {
146 	/*
147 	 * Positive cases with an skb consumed by a driver:
148 	 * - successful transmission (rc == NETDEV_TX_OK)
149 	 * - error while transmitting (rc < 0)
150 	 * - error while queueing to a different device (rc & NET_XMIT_MASK)
151 	 */
152 	if (likely(rc < NET_XMIT_MASK))
153 		return true;
154 
155 	return false;
156 }
157 
158 /*
159  *	Compute the worst-case header length according to the protocols
160  *	used.
161  */
162 
163 #if defined(CONFIG_HYPERV_NET)
164 # define LL_MAX_HEADER 128
165 #elif defined(CONFIG_WLAN)
166 # if defined(CONFIG_MAC80211_MESH)
167 #  define LL_MAX_HEADER 128
168 # else
169 #  define LL_MAX_HEADER 96
170 # endif
171 #else
172 # define LL_MAX_HEADER 32
173 #endif
174 
175 #if !IS_ENABLED(CONFIG_NET_IPIP) && !IS_ENABLED(CONFIG_NET_IPGRE) && \
176     !IS_ENABLED(CONFIG_IPV6_SIT) && !IS_ENABLED(CONFIG_IPV6_TUNNEL)
177 #define MAX_HEADER LL_MAX_HEADER
178 #else
179 #define MAX_HEADER (LL_MAX_HEADER + 48)
180 #endif
181 
182 /*
183  *	Old network device statistics. Fields are native words
184  *	(unsigned long) so they can be read and written atomically.
185  */
186 
187 #define NET_DEV_STAT(FIELD)			\
188 	union {					\
189 		unsigned long FIELD;		\
190 		atomic_long_t __##FIELD;	\
191 	}
192 
193 struct net_device_stats {
194 	NET_DEV_STAT(rx_packets);
195 	NET_DEV_STAT(tx_packets);
196 	NET_DEV_STAT(rx_bytes);
197 	NET_DEV_STAT(tx_bytes);
198 	NET_DEV_STAT(rx_errors);
199 	NET_DEV_STAT(tx_errors);
200 	NET_DEV_STAT(rx_dropped);
201 	NET_DEV_STAT(tx_dropped);
202 	NET_DEV_STAT(multicast);
203 	NET_DEV_STAT(collisions);
204 	NET_DEV_STAT(rx_length_errors);
205 	NET_DEV_STAT(rx_over_errors);
206 	NET_DEV_STAT(rx_crc_errors);
207 	NET_DEV_STAT(rx_frame_errors);
208 	NET_DEV_STAT(rx_fifo_errors);
209 	NET_DEV_STAT(rx_missed_errors);
210 	NET_DEV_STAT(tx_aborted_errors);
211 	NET_DEV_STAT(tx_carrier_errors);
212 	NET_DEV_STAT(tx_fifo_errors);
213 	NET_DEV_STAT(tx_heartbeat_errors);
214 	NET_DEV_STAT(tx_window_errors);
215 	NET_DEV_STAT(rx_compressed);
216 	NET_DEV_STAT(tx_compressed);
217 };
218 #undef NET_DEV_STAT
219 
220 /* per-cpu stats, allocated on demand.
221  * Try to fit them in a single cache line, for dev_get_stats() sake.
222  */
223 struct net_device_core_stats {
224 	unsigned long	rx_dropped;
225 	unsigned long	tx_dropped;
226 	unsigned long	rx_nohandler;
227 	unsigned long	rx_otherhost_dropped;
228 } __aligned(4 * sizeof(unsigned long));
229 
230 #include <linux/cache.h>
231 #include <linux/skbuff.h>
232 
233 struct neighbour;
234 struct neigh_parms;
235 struct sk_buff;
236 
237 struct netdev_hw_addr {
238 	struct list_head	list;
239 	struct rb_node		node;
240 	unsigned char		addr[MAX_ADDR_LEN];
241 	unsigned char		type;
242 #define NETDEV_HW_ADDR_T_LAN		1
243 #define NETDEV_HW_ADDR_T_SAN		2
244 #define NETDEV_HW_ADDR_T_UNICAST	3
245 #define NETDEV_HW_ADDR_T_MULTICAST	4
246 	bool			global_use;
247 	int			sync_cnt;
248 	int			refcount;
249 	int			synced;
250 	struct rcu_head		rcu_head;
251 };
252 
253 struct netdev_hw_addr_list {
254 	struct list_head	list;
255 	/* Only changed through the __hw_addr_count_* helpers after
256 	 * __hw_addr_init()
257 	 */
258 	int			_count;
259 
260 	/* Auxiliary tree for faster lookup on addition and deletion */
261 	struct rb_root		tree;
262 
263 	/* Set for dev->mc only, the device the list belongs to */
264 	struct net_device	*mc_dev;
265 };
266 
267 #define netdev_hw_addr_list_count(l) ((l)->_count)
268 #define netdev_hw_addr_list_empty(l) (netdev_hw_addr_list_count(l) == 0)
269 #define netdev_hw_addr_list_for_each(ha, l) \
270 	list_for_each_entry(ha, &(l)->list, list)
271 
272 #define netdev_uc_count(dev) netdev_hw_addr_list_count(&(dev)->uc)
273 #define netdev_uc_empty(dev) netdev_hw_addr_list_empty(&(dev)->uc)
274 #define netdev_for_each_uc_addr(ha, dev) \
275 	netdev_hw_addr_list_for_each(ha, &(dev)->uc)
276 #define netdev_for_each_synced_uc_addr(_ha, _dev) \
277 	netdev_for_each_uc_addr((_ha), (_dev)) \
278 		if ((_ha)->sync_cnt)
279 
280 #define netdev_mc_count(dev) netdev_hw_addr_list_count(&(dev)->mc)
281 #define netdev_mc_empty(dev) netdev_hw_addr_list_empty(&(dev)->mc)
282 #define netdev_for_each_mc_addr(ha, dev) \
283 	netdev_hw_addr_list_for_each(ha, &(dev)->mc)
284 #define netdev_for_each_synced_mc_addr(_ha, _dev) \
285 	netdev_for_each_mc_addr((_ha), (_dev)) \
286 		if ((_ha)->sync_cnt)
287 
288 struct hh_cache {
289 	unsigned int	hh_len;
290 	seqlock_t	hh_lock;
291 
292 	/* cached hardware header; allow for machine alignment needs.        */
293 #define HH_DATA_MOD	16
294 #define HH_DATA_OFF(__len) \
295 	(HH_DATA_MOD - (((__len - 1) & (HH_DATA_MOD - 1)) + 1))
296 #define HH_DATA_ALIGN(__len) \
297 	(((__len)+(HH_DATA_MOD-1))&~(HH_DATA_MOD - 1))
298 	unsigned long	hh_data[HH_DATA_ALIGN(LL_MAX_HEADER) / sizeof(long)];
299 };
300 
301 /* Reserve HH_DATA_MOD byte-aligned hard_header_len, but at least that much.
302  * Alternative is:
303  *   dev->hard_header_len ? (dev->hard_header_len +
304  *                           (HH_DATA_MOD - 1)) & ~(HH_DATA_MOD - 1) : 0
305  *
306  * We could use other alignment values, but we must maintain the
307  * relationship HH alignment <= LL alignment.
308  */
309 #define LL_RESERVED_SPACE_EX(dev, hlen) \
310 	((((hlen) + READ_ONCE((dev)->needed_headroom)) \
311 	  & ~(HH_DATA_MOD - 1)) + HH_DATA_MOD)
312 #define LL_RESERVED_SPACE(dev) \
313 	LL_RESERVED_SPACE_EX(dev, (dev)->hard_header_len)
314 #define LL_RESERVED_SPACE_EXTRA(dev,extra) \
315 	((((dev)->hard_header_len + READ_ONCE((dev)->needed_headroom) + (extra)) \
316 	  & ~(HH_DATA_MOD - 1)) + HH_DATA_MOD)
317 
318 struct header_ops {
319 	int	(*create) (struct sk_buff *skb, struct net_device *dev,
320 			   unsigned short type, const void *daddr,
321 			   const void *saddr, unsigned int len);
322 	int	(*parse)(const struct sk_buff *skb,
323 			 const struct net_device *dev,
324 			 unsigned char *haddr);
325 	int	(*cache)(const struct neighbour *neigh, struct hh_cache *hh, __be16 type);
326 	void	(*cache_update)(struct hh_cache *hh,
327 				const struct net_device *dev,
328 				const unsigned char *haddr);
329 	bool	(*validate)(const char *ll_header, unsigned int len);
330 	__be16	(*parse_protocol)(const struct sk_buff *skb);
331 };
332 
333 /* These flag bits are private to the generic network queueing
334  * layer; they may not be explicitly referenced by any other
335  * code.
336  */
337 
338 enum netdev_state_t {
339 	__LINK_STATE_START,
340 	__LINK_STATE_PRESENT,
341 	__LINK_STATE_NOCARRIER,
342 	__LINK_STATE_LINKWATCH_PENDING,
343 	__LINK_STATE_DORMANT,
344 	__LINK_STATE_TESTING,
345 };
346 
347 struct gro_list {
348 	struct list_head	list;
349 	int			count;
350 };
351 
352 /*
353  * size of gro hash buckets, must be <= the number of bits in
354  * gro_node::bitmask
355  */
356 #define GRO_HASH_BUCKETS	8
357 
358 /**
359  * struct gro_node - structure to support Generic Receive Offload
360  * @bitmask: bitmask to indicate used buckets in @hash
361  * @hash: hashtable of pending aggregated skbs, separated by flows
362  * @rx_list: list of pending ``GRO_NORMAL`` skbs
363  * @rx_count: cached current length of @rx_list
364  * @cached_napi_id: napi_struct::napi_id cached for hotpath, 0 for standalone
365  */
366 struct gro_node {
367 	unsigned long		bitmask;
368 	struct gro_list		hash[GRO_HASH_BUCKETS];
369 	struct list_head	rx_list;
370 	u32			rx_count;
371 	u32			cached_napi_id;
372 };
373 
374 /*
375  * Structure for per-NAPI config
376  */
377 struct napi_config {
378 	u64 gro_flush_timeout;
379 	u64 irq_suspend_timeout;
380 	u32 defer_hard_irqs;
381 	cpumask_t affinity_mask;
382 	u8 threaded;
383 	unsigned int napi_id;
384 };
385 
386 /*
387  * Structure for NAPI scheduling similar to tasklet but with weighting
388  */
389 struct napi_struct {
390 	/* This field should be first or softnet_data.backlog needs tweaks. */
391 	unsigned long		state;
392 	/* The poll_list must only be managed by the entity which
393 	 * changes the state of the NAPI_STATE_SCHED bit.  This means
394 	 * whoever atomically sets that bit can add this napi_struct
395 	 * to the per-CPU poll_list, and whoever clears that bit
396 	 * can remove from the list right before clearing the bit.
397 	 */
398 	struct list_head	poll_list;
399 
400 	int			weight;
401 	u32			defer_hard_irqs_count;
402 	int			(*poll)(struct napi_struct *, int);
403 #ifdef CONFIG_NETPOLL
404 	/* CPU actively polling if netpoll is configured */
405 	int			poll_owner;
406 #endif
407 	/* CPU on which NAPI has been scheduled for processing */
408 	int			list_owner;
409 	struct net_device	*dev;
410 	struct sk_buff		*skb;
411 	struct gro_node		gro;
412 	struct hrtimer		timer;
413 	/* all fields past this point are write-protected by netdev_lock */
414 	struct task_struct	*thread;
415 	unsigned long		gro_flush_timeout;
416 	unsigned long		irq_suspend_timeout;
417 	u32			defer_hard_irqs;
418 	/* control-path-only fields follow */
419 	u32			napi_id;
420 	struct list_head	dev_list;
421 	struct hlist_node	napi_hash_node;
422 	int			irq;
423 	struct irq_affinity_notify notify;
424 	int			napi_rmap_idx;
425 	int			index;
426 	struct napi_config	*config;
427 };
428 
429 enum {
430 	NAPI_STATE_SCHED,		/* Poll is scheduled */
431 	NAPI_STATE_MISSED,		/* reschedule a napi */
432 	NAPI_STATE_DISABLE,		/* Disable pending */
433 	NAPI_STATE_NPSVC,		/* Netpoll - don't dequeue from poll_list */
434 	NAPI_STATE_LISTED,		/* NAPI added to system lists */
435 	NAPI_STATE_NO_BUSY_POLL,	/* Do not add in napi_hash, no busy polling */
436 	NAPI_STATE_IN_BUSY_POLL,	/* Do not rearm NAPI interrupt */
437 	NAPI_STATE_PREFER_BUSY_POLL,	/* prefer busy-polling over softirq processing*/
438 	NAPI_STATE_THREADED,		/* The poll is performed inside its own thread*/
439 	NAPI_STATE_SCHED_THREADED,	/* Napi is currently scheduled in threaded mode */
440 	NAPI_STATE_HAS_NOTIFIER,	/* Napi has an IRQ notifier */
441 	NAPI_STATE_THREADED_BUSY_POLL,	/* The threaded NAPI poller will busy poll */
442 	NAPI_STATE_PERCPU,		/* NAPI handler is run per-CPU - incompatible with threaded mode */
443 };
444 
445 enum {
446 	NAPIF_STATE_SCHED		= BIT(NAPI_STATE_SCHED),
447 	NAPIF_STATE_MISSED		= BIT(NAPI_STATE_MISSED),
448 	NAPIF_STATE_DISABLE		= BIT(NAPI_STATE_DISABLE),
449 	NAPIF_STATE_NPSVC		= BIT(NAPI_STATE_NPSVC),
450 	NAPIF_STATE_LISTED		= BIT(NAPI_STATE_LISTED),
451 	NAPIF_STATE_NO_BUSY_POLL	= BIT(NAPI_STATE_NO_BUSY_POLL),
452 	NAPIF_STATE_IN_BUSY_POLL	= BIT(NAPI_STATE_IN_BUSY_POLL),
453 	NAPIF_STATE_PREFER_BUSY_POLL	= BIT(NAPI_STATE_PREFER_BUSY_POLL),
454 	NAPIF_STATE_THREADED		= BIT(NAPI_STATE_THREADED),
455 	NAPIF_STATE_SCHED_THREADED	= BIT(NAPI_STATE_SCHED_THREADED),
456 	NAPIF_STATE_HAS_NOTIFIER	= BIT(NAPI_STATE_HAS_NOTIFIER),
457 	NAPIF_STATE_THREADED_BUSY_POLL	= BIT(NAPI_STATE_THREADED_BUSY_POLL),
458 	NAPIF_STATE_PERCPU		= BIT(NAPI_STATE_PERCPU),
459 };
460 
461 enum gro_result {
462 	GRO_MERGED,
463 	GRO_MERGED_FREE,
464 	GRO_HELD,
465 	GRO_NORMAL,
466 	GRO_CONSUMED,
467 };
468 typedef enum gro_result gro_result_t;
469 
470 /*
471  * enum rx_handler_result - Possible return values for rx_handlers.
472  * @RX_HANDLER_CONSUMED: skb was consumed by rx_handler, do not process it
473  * further.
474  * @RX_HANDLER_ANOTHER: Do another round in receive path. This is indicated in
475  * case skb->dev was changed by rx_handler.
476  * @RX_HANDLER_EXACT: Force exact delivery, no wildcard.
477  * @RX_HANDLER_PASS: Do nothing, pass the skb as if no rx_handler was called.
478  *
479  * rx_handlers are functions called from inside __netif_receive_skb(), to do
480  * special processing of the skb, prior to delivery to protocol handlers.
481  *
482  * Currently, a net_device can only have a single rx_handler registered. Trying
483  * to register a second rx_handler will return -EBUSY.
484  *
485  * To register a rx_handler on a net_device, use netdev_rx_handler_register().
486  * To unregister a rx_handler on a net_device, use
487  * netdev_rx_handler_unregister().
488  *
489  * Upon return, rx_handler is expected to tell __netif_receive_skb() what to
490  * do with the skb.
491  *
492  * If the rx_handler consumed the skb in some way, it should return
493  * RX_HANDLER_CONSUMED. This is appropriate when the rx_handler arranged for
494  * the skb to be delivered in some other way.
495  *
496  * If the rx_handler changed skb->dev, to divert the skb to another
497  * net_device, it should return RX_HANDLER_ANOTHER. The rx_handler for the
498  * new device will be called if it exists.
499  *
500  * If the rx_handler decides the skb should be ignored, it should return
501  * RX_HANDLER_EXACT. The skb will only be delivered to protocol handlers that
502  * are registered on exact device (ptype->dev == skb->dev).
503  *
504  * If the rx_handler didn't change skb->dev, but wants the skb to be normally
505  * delivered, it should return RX_HANDLER_PASS.
506  *
507  * A device without a registered rx_handler will behave as if rx_handler
508  * returned RX_HANDLER_PASS.
509  */
510 
511 enum rx_handler_result {
512 	RX_HANDLER_CONSUMED,
513 	RX_HANDLER_ANOTHER,
514 	RX_HANDLER_EXACT,
515 	RX_HANDLER_PASS,
516 };
517 typedef enum rx_handler_result rx_handler_result_t;
518 typedef rx_handler_result_t rx_handler_func_t(struct sk_buff **pskb);
519 
520 void __napi_schedule(struct napi_struct *n);
521 void __napi_schedule_irqoff(struct napi_struct *n);
522 
523 static inline bool napi_disable_pending(struct napi_struct *n)
524 {
525 	return test_bit(NAPI_STATE_DISABLE, &n->state);
526 }
527 
528 static inline bool napi_prefer_busy_poll(struct napi_struct *n)
529 {
530 	return test_bit(NAPI_STATE_PREFER_BUSY_POLL, &n->state);
531 }
532 
533 /**
534  * napi_is_scheduled - test if NAPI is scheduled
535  * @n: NAPI context
536  *
537  * This check is "best-effort". With no locking implemented,
538  * a NAPI can be scheduled or terminate right after this check
539  * and produce not precise results.
540  *
541  * NAPI_STATE_SCHED is an internal state, napi_is_scheduled
542  * should not be used normally and napi_schedule should be
543  * used instead.
544  *
545  * Use only if the driver really needs to check if a NAPI
546  * is scheduled for example in the context of delayed timer
547  * that can be skipped if a NAPI is already scheduled.
548  *
549  * Return: True if NAPI is scheduled, False otherwise.
550  */
551 static inline bool napi_is_scheduled(struct napi_struct *n)
552 {
553 	return test_bit(NAPI_STATE_SCHED, &n->state);
554 }
555 
556 bool napi_schedule_prep(struct napi_struct *n);
557 
558 /**
559  *	napi_schedule - schedule NAPI poll
560  *	@n: NAPI context
561  *
562  * Schedule NAPI poll routine to be called if it is not already
563  * running.
564  * Return: true if we schedule a NAPI or false if not.
565  * Refer to napi_schedule_prep() for additional reason on why
566  * a NAPI might not be scheduled.
567  */
568 static inline bool napi_schedule(struct napi_struct *n)
569 {
570 	if (napi_schedule_prep(n)) {
571 		__napi_schedule(n);
572 		return true;
573 	}
574 
575 	return false;
576 }
577 
578 /**
579  *	napi_schedule_irqoff - schedule NAPI poll
580  *	@n: NAPI context
581  *
582  * Variant of napi_schedule(), assuming hard irqs are masked.
583  */
584 static inline void napi_schedule_irqoff(struct napi_struct *n)
585 {
586 	if (napi_schedule_prep(n))
587 		__napi_schedule_irqoff(n);
588 }
589 
590 /**
591  * napi_complete_done - NAPI processing complete
592  * @n: NAPI context
593  * @work_done: number of packets processed
594  *
595  * Mark NAPI processing as complete. Should only be called if poll budget
596  * has not been completely consumed.
597  * Prefer over napi_complete().
598  * Return: false if device should avoid rearming interrupts.
599  */
600 bool napi_complete_done(struct napi_struct *n, int work_done);
601 
602 static inline bool napi_complete(struct napi_struct *n)
603 {
604 	return napi_complete_done(n, 0);
605 }
606 
607 void netif_threaded_enable(struct net_device *dev);
608 int dev_set_threaded(struct net_device *dev,
609 		     enum netdev_napi_threaded threaded);
610 
611 void napi_disable(struct napi_struct *n);
612 void napi_disable_locked(struct napi_struct *n);
613 
614 void napi_enable(struct napi_struct *n);
615 void napi_enable_locked(struct napi_struct *n);
616 
617 /**
618  *	napi_synchronize - wait until NAPI is not running
619  *	@n: NAPI context
620  *
621  * Wait until NAPI is done being scheduled on this context.
622  * Waits till any outstanding processing completes but
623  * does not disable future activations.
624  */
625 static inline void napi_synchronize(const struct napi_struct *n)
626 {
627 	if (IS_ENABLED(CONFIG_SMP))
628 		while (test_bit(NAPI_STATE_SCHED, &n->state))
629 			msleep(1);
630 	else
631 		barrier();
632 }
633 
634 /**
635  *	napi_if_scheduled_mark_missed - if napi is running, set the
636  *	NAPIF_STATE_MISSED
637  *	@n: NAPI context
638  *
639  * If napi is running, set the NAPIF_STATE_MISSED, and return true if
640  * NAPI is scheduled.
641  **/
642 static inline bool napi_if_scheduled_mark_missed(struct napi_struct *n)
643 {
644 	unsigned long val, new;
645 
646 	val = READ_ONCE(n->state);
647 	do {
648 		if (val & NAPIF_STATE_DISABLE)
649 			return true;
650 
651 		if (!(val & NAPIF_STATE_SCHED))
652 			return false;
653 
654 		new = val | NAPIF_STATE_MISSED;
655 	} while (!try_cmpxchg(&n->state, &val, new));
656 
657 	return true;
658 }
659 
660 enum netdev_queue_state_t {
661 	__QUEUE_STATE_DRV_XOFF,
662 	__QUEUE_STATE_STACK_XOFF,
663 	__QUEUE_STATE_FROZEN,
664 };
665 
666 #define QUEUE_STATE_DRV_XOFF	(1 << __QUEUE_STATE_DRV_XOFF)
667 #define QUEUE_STATE_STACK_XOFF	(1 << __QUEUE_STATE_STACK_XOFF)
668 #define QUEUE_STATE_FROZEN	(1 << __QUEUE_STATE_FROZEN)
669 
670 #define QUEUE_STATE_ANY_XOFF	(QUEUE_STATE_DRV_XOFF | QUEUE_STATE_STACK_XOFF)
671 #define QUEUE_STATE_ANY_XOFF_OR_FROZEN (QUEUE_STATE_ANY_XOFF | \
672 					QUEUE_STATE_FROZEN)
673 #define QUEUE_STATE_DRV_XOFF_OR_FROZEN (QUEUE_STATE_DRV_XOFF | \
674 					QUEUE_STATE_FROZEN)
675 
676 /*
677  * __QUEUE_STATE_DRV_XOFF is used by drivers to stop the transmit queue.  The
678  * netif_tx_* functions below are used to manipulate this flag.  The
679  * __QUEUE_STATE_STACK_XOFF flag is used by the stack to stop the transmit
680  * queue independently.  The netif_xmit_*stopped functions below are called
681  * to check if the queue has been stopped by the driver or stack (either
682  * of the XOFF bits are set in the state).  Drivers should not need to call
683  * netif_xmit*stopped functions, they should only be using netif_tx_*.
684  */
685 
686 struct netdev_queue {
687 /*
688  * read-mostly part
689  */
690 	struct net_device	*dev;
691 	netdevice_tracker	dev_tracker;
692 
693 	struct Qdisc __rcu	*qdisc;
694 	struct Qdisc __rcu	*qdisc_sleeping;
695 #ifdef CONFIG_SYSFS
696 	struct kobject		kobj;
697 	const struct attribute_group	**groups;
698 #endif
699 	unsigned long		tx_maxrate;
700 	/*
701 	 * Number of TX timeouts for this queue
702 	 * (/sys/class/net/DEV/Q/trans_timeout)
703 	 */
704 	atomic_long_t		trans_timeout;
705 
706 	/* Subordinate device that the queue has been assigned to */
707 	struct net_device	*sb_dev;
708 #ifdef CONFIG_XDP_SOCKETS
709 	/* "ops protected", see comment about net_device::lock */
710 	struct xsk_buff_pool    *pool;
711 #endif
712 
713 /*
714  * write-mostly part
715  */
716 #ifdef CONFIG_BQL
717 	struct dql		dql;
718 #endif
719 	spinlock_t		_xmit_lock ____cacheline_aligned_in_smp;
720 	int			xmit_lock_owner;
721 	/*
722 	 * Time (in jiffies) of last Tx
723 	 */
724 	unsigned long		trans_start;
725 
726 	unsigned long		state;
727 
728 /*
729  * slow- / control-path part
730  */
731 	/* NAPI instance for the queue
732 	 * "ops protected", see comment about net_device::lock
733 	 */
734 	struct napi_struct	*napi;
735 
736 #if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
737 	int			numa_node;
738 #endif
739 } ____cacheline_aligned_in_smp;
740 
741 extern int sysctl_fb_tunnels_only_for_init_net;
742 extern int sysctl_devconf_inherit_init_net;
743 
744 /*
745  * sysctl_fb_tunnels_only_for_init_net == 0 : For all netns
746  *                                     == 1 : For initns only
747  *                                     == 2 : For none.
748  */
749 static inline bool net_has_fallback_tunnels(const struct net *net)
750 {
751 #if IS_ENABLED(CONFIG_SYSCTL)
752 	int fb_tunnels_only_for_init_net = READ_ONCE(sysctl_fb_tunnels_only_for_init_net);
753 
754 	return !fb_tunnels_only_for_init_net ||
755 		(net_eq(net, &init_net) && fb_tunnels_only_for_init_net == 1);
756 #else
757 	return true;
758 #endif
759 }
760 
761 static inline int net_inherit_devconf(void)
762 {
763 #if IS_ENABLED(CONFIG_SYSCTL)
764 	return READ_ONCE(sysctl_devconf_inherit_init_net);
765 #else
766 	return 0;
767 #endif
768 }
769 
770 static inline int netdev_queue_numa_node_read(const struct netdev_queue *q)
771 {
772 #if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
773 	return q->numa_node;
774 #else
775 	return NUMA_NO_NODE;
776 #endif
777 }
778 
779 static inline void netdev_queue_numa_node_write(struct netdev_queue *q, int node)
780 {
781 #if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
782 	q->numa_node = node;
783 #endif
784 }
785 
786 #ifdef CONFIG_RFS_ACCEL
787 bool rps_may_expire_flow(struct net_device *dev, u16 rxq_index, u32 flow_id,
788 			 u16 filter_id);
789 #endif
790 
791 /* XPS map type and offset of the xps map within net_device->xps_maps[]. */
792 enum xps_map_type {
793 	XPS_CPUS = 0,
794 	XPS_RXQS,
795 	XPS_MAPS_MAX,
796 };
797 
798 #ifdef CONFIG_XPS
799 /*
800  * This structure holds an XPS map which can be of variable length.  The
801  * map is an array of queues.
802  */
803 struct xps_map {
804 	unsigned int len;
805 	unsigned int alloc_len;
806 	struct rcu_head rcu;
807 	u16 queues[];
808 };
809 #define XPS_MAP_SIZE(_num) (sizeof(struct xps_map) + ((_num) * sizeof(u16)))
810 #define XPS_MIN_MAP_ALLOC ((L1_CACHE_ALIGN(offsetof(struct xps_map, queues[1])) \
811        - sizeof(struct xps_map)) / sizeof(u16))
812 
813 /*
814  * This structure holds all XPS maps for device.  Maps are indexed by CPU.
815  *
816  * We keep track of the number of cpus/rxqs used when the struct is allocated,
817  * in nr_ids. This will help not accessing out-of-bound memory.
818  *
819  * We keep track of the number of traffic classes used when the struct is
820  * allocated, in num_tc. This will be used to navigate the maps, to ensure we're
821  * not crossing its upper bound, as the original dev->num_tc can be updated in
822  * the meantime.
823  */
824 struct xps_dev_maps {
825 	struct rcu_head rcu;
826 	unsigned int nr_ids;
827 	s16 num_tc;
828 	struct xps_map __rcu *attr_map[]; /* Either CPUs map or RXQs map */
829 };
830 
831 #define XPS_CPU_DEV_MAPS_SIZE(_tcs) (sizeof(struct xps_dev_maps) +	\
832 	(nr_cpu_ids * (_tcs) * sizeof(struct xps_map *)))
833 
834 #define XPS_RXQ_DEV_MAPS_SIZE(_tcs, _rxqs) (sizeof(struct xps_dev_maps) +\
835 	(_rxqs * (_tcs) * sizeof(struct xps_map *)))
836 
837 #endif /* CONFIG_XPS */
838 
839 #define TC_MAX_QUEUE	16
840 #define TC_BITMASK	15
841 /* HW offloaded queuing disciplines txq count and offset maps */
842 struct netdev_tc_txq {
843 	union {
844 		struct {
845 			u16 count;
846 			u16 offset;
847 		};
848 		u32 combined;
849 	};
850 };
851 
852 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
853 /*
854  * This structure is to hold information about the device
855  * configured to run FCoE protocol stack.
856  */
857 struct netdev_fcoe_hbainfo {
858 	char	manufacturer[64];
859 	char	serial_number[64];
860 	char	hardware_version[64];
861 	char	driver_version[64];
862 	char	optionrom_version[64];
863 	char	firmware_version[64];
864 	char	model[256];
865 	char	model_description[256];
866 };
867 #endif
868 
869 #define MAX_PHYS_ITEM_ID_LEN 32
870 
871 /* This structure holds a unique identifier to identify some
872  * physical item (port for example) used by a netdevice.
873  */
874 struct netdev_phys_item_id {
875 	unsigned char id[MAX_PHYS_ITEM_ID_LEN];
876 	unsigned char id_len;
877 };
878 
879 static inline bool netdev_phys_item_id_same(struct netdev_phys_item_id *a,
880 					    struct netdev_phys_item_id *b)
881 {
882 	return a->id_len == b->id_len &&
883 	       memcmp(a->id, b->id, a->id_len) == 0;
884 }
885 
886 typedef u16 (*select_queue_fallback_t)(struct net_device *dev,
887 				       struct sk_buff *skb,
888 				       struct net_device *sb_dev);
889 
890 enum net_device_path_type {
891 	DEV_PATH_ETHERNET = 0,
892 	DEV_PATH_VLAN,
893 	DEV_PATH_BRIDGE,
894 	DEV_PATH_PPPOE,
895 	DEV_PATH_DSA,
896 	DEV_PATH_MTK_WDMA,
897 	DEV_PATH_TUN,
898 	DEV_PATH_IEEE80211,
899 };
900 
901 struct net_device_path {
902 	enum net_device_path_type	type;
903 	const struct net_device		*dev;
904 	union {
905 		struct {
906 			u16		id;
907 			__be16		proto;
908 			u8		h_dest[ETH_ALEN];
909 		} encap;
910 		struct {
911 			struct dst_entry *dst;
912 			union {
913 				struct in_addr	src_v4;
914 				struct in6_addr	src_v6;
915 			};
916 			union {
917 				struct in_addr	dst_v4;
918 				struct in6_addr	dst_v6;
919 			};
920 
921 			u8	inner_proto;
922 			u8	encap_proto;
923 		} tun;
924 		struct {
925 			enum {
926 				DEV_PATH_BR_VLAN_KEEP,
927 				DEV_PATH_BR_VLAN_TAG,
928 				DEV_PATH_BR_VLAN_UNTAG,
929 				DEV_PATH_BR_VLAN_UNTAG_HW,
930 			}		vlan_mode;
931 			u16		vlan_id;
932 			__be16		vlan_proto;
933 		} bridge;
934 		struct {
935 			int port;
936 			u16 proto;
937 		} dsa;
938 		struct {
939 			u8 wdma_idx;
940 			u8 queue;
941 			u16 wcid;
942 			u8 bss;
943 			u8 amsdu;
944 		} mtk_wdma;
945 	};
946 };
947 
948 #define NET_DEVICE_PATH_STACK_MAX	5
949 #define NET_DEVICE_PATH_VLAN_MAX	2
950 
951 struct net_device_path_stack {
952 	int			num_paths;
953 	struct net_device_path	path[NET_DEVICE_PATH_STACK_MAX];
954 };
955 
956 struct net_device_path_ctx {
957 	const struct net_device *dev;
958 	u8			daddr[ETH_ALEN];
959 	__be16			ether_type;
960 
961 	int			num_vlans;
962 	struct {
963 		u16		id;
964 		__be16		proto;
965 	} vlan[NET_DEVICE_PATH_VLAN_MAX];
966 
967 	bool			ieee80211;
968 };
969 
970 enum tc_setup_type {
971 	TC_QUERY_CAPS,
972 	TC_SETUP_QDISC_MQPRIO,
973 	TC_SETUP_CLSU32,
974 	TC_SETUP_CLSFLOWER,
975 	TC_SETUP_CLSMATCHALL,
976 	TC_SETUP_CLSBPF,
977 	TC_SETUP_BLOCK,
978 	TC_SETUP_QDISC_CBS,
979 	TC_SETUP_QDISC_RED,
980 	TC_SETUP_QDISC_PRIO,
981 	TC_SETUP_QDISC_MQ,
982 	TC_SETUP_QDISC_ETF,
983 	TC_SETUP_ROOT_QDISC,
984 	TC_SETUP_QDISC_GRED,
985 	TC_SETUP_QDISC_TAPRIO,
986 	TC_SETUP_FT,
987 	TC_SETUP_QDISC_ETS,
988 	TC_SETUP_QDISC_TBF,
989 	TC_SETUP_QDISC_FIFO,
990 	TC_SETUP_QDISC_HTB,
991 	TC_SETUP_ACT,
992 };
993 
994 /* These structures hold the attributes of bpf state that are being passed
995  * to the netdevice through the bpf op.
996  */
997 enum bpf_netdev_command {
998 	/* Set or clear a bpf program used in the earliest stages of packet
999 	 * rx. The prog will have been loaded as BPF_PROG_TYPE_XDP. The callee
1000 	 * is responsible for calling bpf_prog_put on any old progs that are
1001 	 * stored. In case of error, the callee need not release the new prog
1002 	 * reference, but on success it takes ownership and must bpf_prog_put
1003 	 * when it is no longer used.
1004 	 */
1005 	XDP_SETUP_PROG,
1006 	XDP_SETUP_PROG_HW,
1007 	/* BPF program for offload callbacks, invoked at program load time. */
1008 	BPF_OFFLOAD_MAP_ALLOC,
1009 	BPF_OFFLOAD_MAP_FREE,
1010 	XDP_SETUP_XSK_POOL,
1011 };
1012 
1013 struct bpf_prog_offload_ops;
1014 struct netlink_ext_ack;
1015 struct xdp_umem;
1016 struct xdp_dev_bulk_queue;
1017 struct bpf_xdp_link;
1018 
1019 enum bpf_xdp_mode {
1020 	XDP_MODE_SKB = 0,
1021 	XDP_MODE_DRV = 1,
1022 	XDP_MODE_HW = 2,
1023 	__MAX_XDP_MODE
1024 };
1025 
1026 struct bpf_xdp_entity {
1027 	struct bpf_prog *prog;
1028 	struct bpf_xdp_link *link;
1029 };
1030 
1031 struct netdev_bpf {
1032 	enum bpf_netdev_command command;
1033 	union {
1034 		/* XDP_SETUP_PROG */
1035 		struct {
1036 			u32 flags;
1037 			struct bpf_prog *prog;
1038 			struct netlink_ext_ack *extack;
1039 		};
1040 		/* BPF_OFFLOAD_MAP_ALLOC, BPF_OFFLOAD_MAP_FREE */
1041 		struct {
1042 			struct bpf_offloaded_map *offmap;
1043 		};
1044 		/* XDP_SETUP_XSK_POOL */
1045 		struct {
1046 			struct xsk_buff_pool *pool;
1047 			u16 queue_id;
1048 		} xsk;
1049 	};
1050 };
1051 
1052 /* Flags for ndo_xsk_wakeup. */
1053 #define XDP_WAKEUP_RX (1 << 0)
1054 #define XDP_WAKEUP_TX (1 << 1)
1055 
1056 #ifdef CONFIG_XFRM_OFFLOAD
1057 struct xfrmdev_ops {
1058 	int	(*xdo_dev_state_add)(struct net_device *dev,
1059 				     struct xfrm_state *x,
1060 				     struct netlink_ext_ack *extack);
1061 	void	(*xdo_dev_state_delete)(struct net_device *dev,
1062 					struct xfrm_state *x);
1063 	void	(*xdo_dev_state_free)(struct net_device *dev,
1064 				      struct xfrm_state *x);
1065 	bool	(*xdo_dev_offload_ok) (struct sk_buff *skb,
1066 				       struct xfrm_state *x);
1067 	void	(*xdo_dev_state_advance_esn) (struct xfrm_state *x);
1068 	void	(*xdo_dev_state_update_stats) (struct xfrm_state *x);
1069 	int	(*xdo_dev_policy_add) (struct xfrm_policy *x, struct netlink_ext_ack *extack);
1070 	void	(*xdo_dev_policy_delete) (struct xfrm_policy *x);
1071 	void	(*xdo_dev_policy_free) (struct xfrm_policy *x);
1072 };
1073 #endif
1074 
1075 struct dev_ifalias {
1076 	struct rcu_head rcuhead;
1077 	char ifalias[];
1078 };
1079 
1080 struct devlink;
1081 struct tlsdev_ops;
1082 
1083 struct netdev_net_notifier {
1084 	struct list_head list;
1085 	struct notifier_block *nb;
1086 };
1087 
1088 /*
1089  * This structure defines the management hooks for network devices.
1090  * The following hooks can be defined; unless noted otherwise, they are
1091  * optional and can be filled with a null pointer.
1092  *
1093  * int (*ndo_init)(struct net_device *dev);
1094  *     This function is called once when a network device is registered.
1095  *     The network device can use this for any late stage initialization
1096  *     or semantic validation. It can fail with an error code which will
1097  *     be propagated back to register_netdev.
1098  *
1099  * void (*ndo_uninit)(struct net_device *dev);
1100  *     This function is called when device is unregistered or when registration
1101  *     fails. It is not called if init fails.
1102  *
1103  * int (*ndo_open)(struct net_device *dev);
1104  *     This function is called when a network device transitions to the up
1105  *     state.
1106  *
1107  * int (*ndo_stop)(struct net_device *dev);
1108  *     This function is called when a network device transitions to the down
1109  *     state.
1110  *
1111  * netdev_tx_t (*ndo_start_xmit)(struct sk_buff *skb,
1112  *                               struct net_device *dev);
1113  *	Called when a packet needs to be transmitted.
1114  *	Returns NETDEV_TX_OK.  Can return NETDEV_TX_BUSY, but you should stop
1115  *	the queue before that can happen; it's for obsolete devices and weird
1116  *	corner cases, but the stack really does a non-trivial amount
1117  *	of useless work if you return NETDEV_TX_BUSY.
1118  *	Required; cannot be NULL.
1119  *
1120  * netdev_features_t (*ndo_features_check)(struct sk_buff *skb,
1121  *					   struct net_device *dev
1122  *					   netdev_features_t features);
1123  *	Called by core transmit path to determine if device is capable of
1124  *	performing offload operations on a given packet. This is to give
1125  *	the device an opportunity to implement any restrictions that cannot
1126  *	be otherwise expressed by feature flags. The check is called with
1127  *	the set of features that the stack has calculated and it returns
1128  *	those the driver believes to be appropriate.
1129  *
1130  * u16 (*ndo_select_queue)(struct net_device *dev, struct sk_buff *skb,
1131  *                         struct net_device *sb_dev);
1132  *	Called to decide which queue to use when device supports multiple
1133  *	transmit queues.
1134  *
1135  * void (*ndo_change_rx_flags)(struct net_device *dev, int flags);
1136  *	This function is called to allow device receiver to make
1137  *	changes to configuration when multicast or promiscuous is enabled.
1138  *
1139  * void (*ndo_set_rx_mode)(struct net_device *dev);
1140  *	This function is called device changes address list filtering.
1141  *	If driver handles unicast address filtering, it should set
1142  *	IFF_UNICAST_FLT in its priv_flags.
1143  *	Cannot sleep, called with netif_addr_lock_bh held.
1144  *	Deprecated in favor of ndo_set_rx_mode_async.
1145  *
1146  * int (*ndo_set_rx_mode_async)(struct net_device *dev,
1147  *				struct netdev_hw_addr_list *uc,
1148  *				struct netdev_hw_addr_list *mc);
1149  *	Async version of ndo_set_rx_mode which runs in process context
1150  *	under the netdev instance lock for "ops locked" drivers, or
1151  *	rtnl_lock for all other drivers. The uc/mc parameters
1152  *	are snapshots of the address lists - iterate with
1153  *	netdev_hw_addr_list_for_each(ha, uc). Return 0 on success or a
1154  *	negative errno to request a retry via the core backoff.
1155  *
1156  * void (*ndo_work)(struct net_device *dev, unsigned long events);
1157  *	Run deferred work scheduled with netdev_work_sched(@events).
1158  *	Runs in process context under the netdev instance lock for "ops
1159  *	locked" drivers, or rtnl_lock for all other drivers.
1160  *
1161  * int (*ndo_set_mac_address)(struct net_device *dev, void *addr);
1162  *	This function  is called when the Media Access Control address
1163  *	needs to be changed. If this interface is not defined, the
1164  *	MAC address can not be changed.
1165  *
1166  * int (*ndo_validate_addr)(struct net_device *dev);
1167  *	Test if Media Access Control address is valid for the device.
1168  *
1169  * int (*ndo_siocbond)(struct net_device *dev, struct ifreq *ifr, int cmd);
1170  *	Used by the bonding driver for its device specific ioctls:
1171  *	SIOCBONDENSLAVE, SIOCBONDRELEASE, SIOCBONDSETHWADDR, SIOCBONDCHANGEACTIVE,
1172  *	SIOCBONDSLAVEINFOQUERY, and SIOCBONDINFOQUERY
1173  *
1174  * * int (*ndo_eth_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd);
1175  *	Called for ethernet specific ioctls: SIOCGMIIPHY, SIOCGMIIREG and
1176  *	SIOCSMIIREG.
1177  *
1178  * int (*ndo_set_config)(struct net_device *dev, struct ifmap *map);
1179  *	Used to set network devices bus interface parameters. This interface
1180  *	is retained for legacy reasons; new devices should use the bus
1181  *	interface (PCI) for low level management.
1182  *
1183  * int (*ndo_change_mtu)(struct net_device *dev, int new_mtu);
1184  *	Called when a user wants to change the Maximum Transfer Unit
1185  *	of a device.
1186  *
1187  * void (*ndo_tx_timeout)(struct net_device *dev, unsigned int txqueue);
1188  *	Callback used when the transmitter has not made any progress
1189  *	for dev->watchdog ticks.
1190  *
1191  * void (*ndo_get_stats64)(struct net_device *dev,
1192  *                         struct rtnl_link_stats64 *storage);
1193  * struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
1194  *	Called when a user wants to get the network device usage
1195  *	statistics. Drivers must do one of the following:
1196  *	1. Define @ndo_get_stats64 to fill in a zero-initialised
1197  *	   rtnl_link_stats64 structure passed by the caller.
1198  *	2. Define @ndo_get_stats to update a net_device_stats structure
1199  *	   (which should normally be dev->stats) and return a pointer to
1200  *	   it. The structure may be changed asynchronously only if each
1201  *	   field is written atomically.
1202  *	3. Update dev->stats asynchronously and atomically, and define
1203  *	   neither operation.
1204  *
1205  * bool (*ndo_has_offload_stats)(const struct net_device *dev, int attr_id)
1206  *	Return true if this device supports offload stats of this attr_id.
1207  *
1208  * int (*ndo_get_offload_stats)(int attr_id, const struct net_device *dev,
1209  *	void *attr_data)
1210  *	Get statistics for offload operations by attr_id. Write it into the
1211  *	attr_data pointer.
1212  *
1213  * int (*ndo_vlan_rx_add_vid)(struct net_device *dev, __be16 proto, u16 vid);
1214  *	If device supports VLAN filtering this function is called when a
1215  *	VLAN id is registered.
1216  *
1217  * int (*ndo_vlan_rx_kill_vid)(struct net_device *dev, __be16 proto, u16 vid);
1218  *	If device supports VLAN filtering this function is called when a
1219  *	VLAN id is unregistered.
1220  *
1221  * void (*ndo_poll_controller)(struct net_device *dev);
1222  *
1223  *	SR-IOV management functions.
1224  * int (*ndo_set_vf_mac)(struct net_device *dev, int vf, u8* mac);
1225  * int (*ndo_set_vf_vlan)(struct net_device *dev, int vf, u16 vlan,
1226  *			  u8 qos, __be16 proto);
1227  * int (*ndo_set_vf_rate)(struct net_device *dev, int vf, int min_tx_rate,
1228  *			  int max_tx_rate);
1229  * int (*ndo_set_vf_spoofchk)(struct net_device *dev, int vf, bool setting);
1230  * int (*ndo_set_vf_trust)(struct net_device *dev, int vf, bool setting);
1231  * int (*ndo_get_vf_config)(struct net_device *dev,
1232  *			    int vf, struct ifla_vf_info *ivf);
1233  * int (*ndo_set_vf_link_state)(struct net_device *dev, int vf, int link_state);
1234  * int (*ndo_set_vf_port)(struct net_device *dev, int vf,
1235  *			  struct nlattr *port[]);
1236  *
1237  *      Enable or disable the VF ability to query its RSS Redirection Table and
1238  *      Hash Key. This is needed since on some devices VF share this information
1239  *      with PF and querying it may introduce a theoretical security risk.
1240  * int (*ndo_set_vf_rss_query_en)(struct net_device *dev, int vf, bool setting);
1241  * int (*ndo_get_vf_port)(struct net_device *dev, int vf, struct sk_buff *skb);
1242  * int (*ndo_setup_tc)(struct net_device *dev, enum tc_setup_type type,
1243  *		       void *type_data);
1244  *	Called to setup any 'tc' scheduler, classifier or action on @dev.
1245  *	This is always called from the stack with the rtnl lock held and netif
1246  *	tx queues stopped. This allows the netdevice to perform queue
1247  *	management safely.
1248  *
1249  *	NB: Returning -EOPNOTSUPP for whatever commands means "this qdisc
1250  *	is not offloaded (anymore, offloading may have silently stopped)",
1251  *	and the offloading flag is cleared. Notably, this is also true for
1252  *	dump queries (e.g. TC_*_STATS commands). If the underlying device does
1253  *	not report any statistics but is still offloading, return 0 instead.
1254  *
1255  *	Fiber Channel over Ethernet (FCoE) offload functions.
1256  * int (*ndo_fcoe_enable)(struct net_device *dev);
1257  *	Called when the FCoE protocol stack wants to start using LLD for FCoE
1258  *	so the underlying device can perform whatever needed configuration or
1259  *	initialization to support acceleration of FCoE traffic.
1260  *
1261  * int (*ndo_fcoe_disable)(struct net_device *dev);
1262  *	Called when the FCoE protocol stack wants to stop using LLD for FCoE
1263  *	so the underlying device can perform whatever needed clean-ups to
1264  *	stop supporting acceleration of FCoE traffic.
1265  *
1266  * int (*ndo_fcoe_ddp_setup)(struct net_device *dev, u16 xid,
1267  *			     struct scatterlist *sgl, unsigned int sgc);
1268  *	Called when the FCoE Initiator wants to initialize an I/O that
1269  *	is a possible candidate for Direct Data Placement (DDP). The LLD can
1270  *	perform necessary setup and returns 1 to indicate the device is set up
1271  *	successfully to perform DDP on this I/O, otherwise this returns 0.
1272  *
1273  * int (*ndo_fcoe_ddp_done)(struct net_device *dev,  u16 xid);
1274  *	Called when the FCoE Initiator/Target is done with the DDPed I/O as
1275  *	indicated by the FC exchange id 'xid', so the underlying device can
1276  *	clean up and reuse resources for later DDP requests.
1277  *
1278  * int (*ndo_fcoe_ddp_target)(struct net_device *dev, u16 xid,
1279  *			      struct scatterlist *sgl, unsigned int sgc);
1280  *	Called when the FCoE Target wants to initialize an I/O that
1281  *	is a possible candidate for Direct Data Placement (DDP). The LLD can
1282  *	perform necessary setup and returns 1 to indicate the device is set up
1283  *	successfully to perform DDP on this I/O, otherwise this returns 0.
1284  *
1285  * int (*ndo_fcoe_get_hbainfo)(struct net_device *dev,
1286  *			       struct netdev_fcoe_hbainfo *hbainfo);
1287  *	Called when the FCoE Protocol stack wants information on the underlying
1288  *	device. This information is utilized by the FCoE protocol stack to
1289  *	register attributes with Fiber Channel management service as per the
1290  *	FC-GS Fabric Device Management Information(FDMI) specification.
1291  *
1292  * int (*ndo_fcoe_get_wwn)(struct net_device *dev, u64 *wwn, int type);
1293  *	Called when the underlying device wants to override default World Wide
1294  *	Name (WWN) generation mechanism in FCoE protocol stack to pass its own
1295  *	World Wide Port Name (WWPN) or World Wide Node Name (WWNN) to the FCoE
1296  *	protocol stack to use.
1297  *
1298  *	RFS acceleration.
1299  * int (*ndo_rx_flow_steer)(struct net_device *dev, const struct sk_buff *skb,
1300  *			    u16 rxq_index, u32 flow_id);
1301  *	Set hardware filter for RFS.  rxq_index is the target queue index;
1302  *	flow_id is a flow ID to be passed to rps_may_expire_flow() later.
1303  *	Return the filter ID on success, or a negative error code.
1304  *
1305  *	Slave management functions (for bridge, bonding, etc).
1306  * int (*ndo_add_slave)(struct net_device *dev, struct net_device *slave_dev);
1307  *	Called to make another netdev an underling.
1308  *
1309  * int (*ndo_del_slave)(struct net_device *dev, struct net_device *slave_dev);
1310  *	Called to release previously enslaved netdev.
1311  *
1312  * struct net_device *(*ndo_get_xmit_slave)(struct net_device *dev,
1313  *					    struct sk_buff *skb,
1314  *					    bool all_slaves);
1315  *	Get the xmit slave of master device. If all_slaves is true, function
1316  *	assume all the slaves can transmit.
1317  *
1318  *      Feature/offload setting functions.
1319  * netdev_features_t (*ndo_fix_features)(struct net_device *dev,
1320  *		netdev_features_t features);
1321  *	Adjusts the requested feature flags according to device-specific
1322  *	constraints, and returns the resulting flags. Must not modify
1323  *	the device state.
1324  *
1325  * int (*ndo_set_features)(struct net_device *dev, netdev_features_t features);
1326  *	Called to update device configuration to new features. Passed
1327  *	feature set might be less than what was returned by ndo_fix_features()).
1328  *	Must return >0 or -errno if it changed dev->features itself.
1329  *
1330  * int (*ndo_fdb_add)(struct ndmsg *ndm, struct nlattr *tb[],
1331  *		      struct net_device *dev,
1332  *		      const unsigned char *addr, u16 vid, u16 flags,
1333  *		      bool *notified, struct netlink_ext_ack *extack);
1334  *	Adds an FDB entry to dev for addr.
1335  *	Callee shall set *notified to true if it sent any appropriate
1336  *	notification(s). Otherwise core will send a generic one.
1337  * int (*ndo_fdb_del)(struct ndmsg *ndm, struct nlattr *tb[],
1338  *		      struct net_device *dev,
1339  *		      const unsigned char *addr, u16 vid
1340  *		      bool *notified, struct netlink_ext_ack *extack);
1341  *	Deletes the FDB entry from dev corresponding to addr.
1342  *	Callee shall set *notified to true if it sent any appropriate
1343  *	notification(s). Otherwise core will send a generic one.
1344  * int (*ndo_fdb_del_bulk)(struct nlmsghdr *nlh, struct net_device *dev,
1345  *			   struct netlink_ext_ack *extack);
1346  * int (*ndo_fdb_dump)(struct sk_buff *skb, struct netlink_callback *cb,
1347  *		       struct net_device *dev, struct net_device *filter_dev,
1348  *		       int *idx)
1349  *	Used to add FDB entries to dump requests. Implementers should add
1350  *	entries to skb and update idx with the number of entries.
1351  *
1352  * int (*ndo_mdb_add)(struct net_device *dev, struct nlattr *tb[],
1353  *		      u16 nlmsg_flags, struct netlink_ext_ack *extack);
1354  *	Adds an MDB entry to dev.
1355  * int (*ndo_mdb_del)(struct net_device *dev, struct nlattr *tb[],
1356  *		      struct netlink_ext_ack *extack);
1357  *	Deletes the MDB entry from dev.
1358  * int (*ndo_mdb_del_bulk)(struct net_device *dev, struct nlattr *tb[],
1359  *			   struct netlink_ext_ack *extack);
1360  *	Bulk deletes MDB entries from dev.
1361  * int (*ndo_mdb_dump)(struct net_device *dev, struct sk_buff *skb,
1362  *		       struct netlink_callback *cb);
1363  *	Dumps MDB entries from dev. The first argument (marker) in the netlink
1364  *	callback is used by core rtnetlink code.
1365  *
1366  * int (*ndo_bridge_setlink)(struct net_device *dev, struct nlmsghdr *nlh,
1367  *			     u16 flags, struct netlink_ext_ack *extack)
1368  * int (*ndo_bridge_getlink)(struct sk_buff *skb, u32 pid, u32 seq,
1369  *			     struct net_device *dev, u32 filter_mask,
1370  *			     int nlflags)
1371  * int (*ndo_bridge_dellink)(struct net_device *dev, struct nlmsghdr *nlh,
1372  *			     u16 flags);
1373  *
1374  * int (*ndo_change_carrier)(struct net_device *dev, bool new_carrier);
1375  *	Called to change device carrier. Soft-devices (like dummy, team, etc)
1376  *	which do not represent real hardware may define this to allow their
1377  *	userspace components to manage their virtual carrier state. Devices
1378  *	that determine carrier state from physical hardware properties (eg
1379  *	network cables) or protocol-dependent mechanisms (eg
1380  *	USB_CDC_NOTIFY_NETWORK_CONNECTION) should NOT implement this function.
1381  *
1382  * int (*ndo_get_phys_port_id)(struct net_device *dev,
1383  *			       struct netdev_phys_item_id *ppid);
1384  *	Called to get ID of physical port of this device. If driver does
1385  *	not implement this, it is assumed that the hw is not able to have
1386  *	multiple net devices on single physical port.
1387  *
1388  * int (*ndo_get_port_parent_id)(struct net_device *dev,
1389  *				 struct netdev_phys_item_id *ppid)
1390  *	Called to get the parent ID of the physical port of this device.
1391  *
1392  * void* (*ndo_dfwd_add_station)(struct net_device *pdev,
1393  *				 struct net_device *dev)
1394  *	Called by upper layer devices to accelerate switching or other
1395  *	station functionality into hardware. 'pdev is the lowerdev
1396  *	to use for the offload and 'dev' is the net device that will
1397  *	back the offload. Returns a pointer to the private structure
1398  *	the upper layer will maintain.
1399  * void (*ndo_dfwd_del_station)(struct net_device *pdev, void *priv)
1400  *	Called by upper layer device to delete the station created
1401  *	by 'ndo_dfwd_add_station'. 'pdev' is the net device backing
1402  *	the station and priv is the structure returned by the add
1403  *	operation.
1404  * int (*ndo_set_tx_maxrate)(struct net_device *dev,
1405  *			     int queue_index, u32 maxrate);
1406  *	Called when a user wants to set a max-rate limitation of specific
1407  *	TX queue.
1408  * int (*ndo_get_iflink)(const struct net_device *dev);
1409  *	Called to get the iflink value of this device.
1410  * int (*ndo_fill_metadata_dst)(struct net_device *dev, struct sk_buff *skb);
1411  *	This function is used to get egress tunnel information for given skb.
1412  *	This is useful for retrieving outer tunnel header parameters while
1413  *	sampling packet.
1414  * void (*ndo_set_rx_headroom)(struct net_device *dev, int needed_headroom);
1415  *	This function is used to specify the headroom that the skb must
1416  *	consider when allocation skb during packet reception. Setting
1417  *	appropriate rx headroom value allows avoiding skb head copy on
1418  *	forward. Setting a negative value resets the rx headroom to the
1419  *	default value.
1420  * int (*ndo_bpf)(struct net_device *dev, struct netdev_bpf *bpf);
1421  *	This function is used to set or query state related to XDP on the
1422  *	netdevice and manage BPF offload. See definition of
1423  *	enum bpf_netdev_command for details.
1424  * int (*ndo_xdp_xmit)(struct net_device *dev, int n, struct xdp_frame **xdp,
1425  *			u32 flags);
1426  *	This function is used to submit @n XDP packets for transmit on a
1427  *	netdevice. Returns number of frames successfully transmitted, frames
1428  *	that got dropped are freed/returned via xdp_return_frame().
1429  *	Returns negative number, means general error invoking ndo, meaning
1430  *	no frames were xmit'ed and core-caller will free all frames.
1431  * struct net_device *(*ndo_xdp_get_xmit_slave)(struct net_device *dev,
1432  *					        struct xdp_buff *xdp);
1433  *      Get the xmit slave of master device based on the xdp_buff.
1434  * int (*ndo_xsk_wakeup)(struct net_device *dev, u32 queue_id, u32 flags);
1435  *      This function is used to wake up the softirq, ksoftirqd or kthread
1436  *	responsible for sending and/or receiving packets on a specific
1437  *	queue id bound to an AF_XDP socket. The flags field specifies if
1438  *	only RX, only Tx, or both should be woken up using the flags
1439  *	XDP_WAKEUP_RX and XDP_WAKEUP_TX.
1440  * int (*ndo_tunnel_ctl)(struct net_device *dev, struct ip_tunnel_parm_kern *p,
1441  *			 int cmd);
1442  *	Add, change, delete or get information on an IPv4 tunnel.
1443  * struct net_device *(*ndo_get_peer_dev)(struct net_device *dev);
1444  *	If a device is paired with a peer device, return the peer instance.
1445  *	The caller must be under RCU read context.
1446  * int (*ndo_fill_forward_path)(struct net_device_path_ctx *ctx, struct net_device_path *path);
1447  *     Get the forwarding path to reach the real device from the HW destination address
1448  * ktime_t (*ndo_get_tstamp)(struct net_device *dev,
1449  *			     const struct skb_shared_hwtstamps *hwtstamps,
1450  *			     bool cycles);
1451  *	Get hardware timestamp based on normal/adjustable time or free running
1452  *	cycle counter. This function is required if physical clock supports a
1453  *	free running cycle counter.
1454  *
1455  * int (*ndo_hwtstamp_get)(struct net_device *dev,
1456  *			   struct kernel_hwtstamp_config *kernel_config);
1457  *	Get the currently configured hardware timestamping parameters for the
1458  *	NIC device.
1459  *
1460  * int (*ndo_hwtstamp_set)(struct net_device *dev,
1461  *			   struct kernel_hwtstamp_config *kernel_config,
1462  *			   struct netlink_ext_ack *extack);
1463  *	Change the hardware timestamping parameters for NIC device.
1464  */
1465 struct net_device_ops {
1466 	int			(*ndo_init)(struct net_device *dev);
1467 	void			(*ndo_uninit)(struct net_device *dev);
1468 	int			(*ndo_open)(struct net_device *dev);
1469 	int			(*ndo_stop)(struct net_device *dev);
1470 	netdev_tx_t		(*ndo_start_xmit)(struct sk_buff *skb,
1471 						  struct net_device *dev);
1472 	netdev_features_t	(*ndo_features_check)(struct sk_buff *skb,
1473 						      struct net_device *dev,
1474 						      netdev_features_t features);
1475 	u16			(*ndo_select_queue)(struct net_device *dev,
1476 						    struct sk_buff *skb,
1477 						    struct net_device *sb_dev);
1478 	void			(*ndo_change_rx_flags)(struct net_device *dev,
1479 						       int flags);
1480 	void			(*ndo_set_rx_mode)(struct net_device *dev);
1481 	int			(*ndo_set_rx_mode_async)(
1482 					struct net_device *dev,
1483 					struct netdev_hw_addr_list *uc,
1484 					struct netdev_hw_addr_list *mc);
1485 	void			(*ndo_work)(struct net_device *dev,
1486 					    unsigned long events);
1487 	int			(*ndo_set_mac_address)(struct net_device *dev,
1488 						       void *addr);
1489 	int			(*ndo_validate_addr)(struct net_device *dev);
1490 	int			(*ndo_eth_ioctl)(struct net_device *dev,
1491 						 struct ifreq *ifr, int cmd);
1492 	int			(*ndo_siocbond)(struct net_device *dev,
1493 						struct ifreq *ifr, int cmd);
1494 	int			(*ndo_siocwandev)(struct net_device *dev,
1495 						  struct if_settings *ifs);
1496 	int			(*ndo_siocdevprivate)(struct net_device *dev,
1497 						      struct ifreq *ifr,
1498 						      void __user *data, int cmd);
1499 	int			(*ndo_set_config)(struct net_device *dev,
1500 					          struct ifmap *map);
1501 	int			(*ndo_change_mtu)(struct net_device *dev,
1502 						  int new_mtu);
1503 	int			(*ndo_neigh_setup)(struct net_device *dev,
1504 						   struct neigh_parms *);
1505 	void			(*ndo_tx_timeout) (struct net_device *dev,
1506 						   unsigned int txqueue);
1507 
1508 	void			(*ndo_get_stats64)(struct net_device *dev,
1509 						   struct rtnl_link_stats64 *storage);
1510 	bool			(*ndo_has_offload_stats)(const struct net_device *dev, int attr_id);
1511 	int			(*ndo_get_offload_stats)(int attr_id,
1512 							 const struct net_device *dev,
1513 							 void *attr_data);
1514 	struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
1515 
1516 	int			(*ndo_vlan_rx_add_vid)(struct net_device *dev,
1517 						       __be16 proto, u16 vid);
1518 	int			(*ndo_vlan_rx_kill_vid)(struct net_device *dev,
1519 						        __be16 proto, u16 vid);
1520 #ifdef CONFIG_NET_POLL_CONTROLLER
1521 	void                    (*ndo_poll_controller)(struct net_device *dev);
1522 	int			(*ndo_netpoll_setup)(struct net_device *dev);
1523 	void			(*ndo_netpoll_cleanup)(struct net_device *dev);
1524 #endif
1525 	int			(*ndo_set_vf_mac)(struct net_device *dev,
1526 						  int queue, u8 *mac);
1527 	int			(*ndo_set_vf_vlan)(struct net_device *dev,
1528 						   int queue, u16 vlan,
1529 						   u8 qos, __be16 proto);
1530 	int			(*ndo_set_vf_rate)(struct net_device *dev,
1531 						   int vf, int min_tx_rate,
1532 						   int max_tx_rate);
1533 	int			(*ndo_set_vf_spoofchk)(struct net_device *dev,
1534 						       int vf, bool setting);
1535 	int			(*ndo_set_vf_trust)(struct net_device *dev,
1536 						    int vf, bool setting);
1537 	int			(*ndo_get_vf_config)(struct net_device *dev,
1538 						     int vf,
1539 						     struct ifla_vf_info *ivf);
1540 	int			(*ndo_set_vf_link_state)(struct net_device *dev,
1541 							 int vf, int link_state);
1542 	int			(*ndo_get_vf_stats)(struct net_device *dev,
1543 						    int vf,
1544 						    struct ifla_vf_stats
1545 						    *vf_stats);
1546 	int			(*ndo_set_vf_port)(struct net_device *dev,
1547 						   int vf,
1548 						   struct nlattr *port[]);
1549 	int			(*ndo_get_vf_port)(struct net_device *dev,
1550 						   int vf, struct sk_buff *skb);
1551 	int			(*ndo_get_vf_guid)(struct net_device *dev,
1552 						   int vf,
1553 						   struct ifla_vf_guid *node_guid,
1554 						   struct ifla_vf_guid *port_guid);
1555 	int			(*ndo_set_vf_guid)(struct net_device *dev,
1556 						   int vf, u64 guid,
1557 						   int guid_type);
1558 	int			(*ndo_set_vf_rss_query_en)(
1559 						   struct net_device *dev,
1560 						   int vf, bool setting);
1561 	int			(*ndo_setup_tc)(struct net_device *dev,
1562 						enum tc_setup_type type,
1563 						void *type_data);
1564 #if IS_ENABLED(CONFIG_FCOE)
1565 	int			(*ndo_fcoe_enable)(struct net_device *dev);
1566 	int			(*ndo_fcoe_disable)(struct net_device *dev);
1567 	int			(*ndo_fcoe_ddp_setup)(struct net_device *dev,
1568 						      u16 xid,
1569 						      struct scatterlist *sgl,
1570 						      unsigned int sgc);
1571 	int			(*ndo_fcoe_ddp_done)(struct net_device *dev,
1572 						     u16 xid);
1573 	int			(*ndo_fcoe_ddp_target)(struct net_device *dev,
1574 						       u16 xid,
1575 						       struct scatterlist *sgl,
1576 						       unsigned int sgc);
1577 	int			(*ndo_fcoe_get_hbainfo)(struct net_device *dev,
1578 							struct netdev_fcoe_hbainfo *hbainfo);
1579 #endif
1580 
1581 #if IS_ENABLED(CONFIG_LIBFCOE)
1582 #define NETDEV_FCOE_WWNN 0
1583 #define NETDEV_FCOE_WWPN 1
1584 	int			(*ndo_fcoe_get_wwn)(struct net_device *dev,
1585 						    u64 *wwn, int type);
1586 #endif
1587 
1588 #ifdef CONFIG_RFS_ACCEL
1589 	int			(*ndo_rx_flow_steer)(struct net_device *dev,
1590 						     const struct sk_buff *skb,
1591 						     u16 rxq_index,
1592 						     u32 flow_id);
1593 #endif
1594 	int			(*ndo_add_slave)(struct net_device *dev,
1595 						 struct net_device *slave_dev,
1596 						 struct netlink_ext_ack *extack);
1597 	int			(*ndo_del_slave)(struct net_device *dev,
1598 						 struct net_device *slave_dev);
1599 	struct net_device*	(*ndo_get_xmit_slave)(struct net_device *dev,
1600 						      struct sk_buff *skb,
1601 						      bool all_slaves);
1602 	struct net_device*	(*ndo_sk_get_lower_dev)(struct net_device *dev,
1603 							struct sock *sk);
1604 	netdev_features_t	(*ndo_fix_features)(struct net_device *dev,
1605 						    netdev_features_t features);
1606 	int			(*ndo_set_features)(struct net_device *dev,
1607 						    netdev_features_t features);
1608 	int			(*ndo_neigh_construct)(struct net_device *dev,
1609 						       struct neighbour *n);
1610 	void			(*ndo_neigh_destroy)(struct net_device *dev,
1611 						     struct neighbour *n);
1612 
1613 	int			(*ndo_fdb_add)(struct ndmsg *ndm,
1614 					       struct nlattr *tb[],
1615 					       struct net_device *dev,
1616 					       const unsigned char *addr,
1617 					       u16 vid,
1618 					       u16 flags,
1619 					       bool *notified,
1620 					       struct netlink_ext_ack *extack);
1621 	int			(*ndo_fdb_del)(struct ndmsg *ndm,
1622 					       struct nlattr *tb[],
1623 					       struct net_device *dev,
1624 					       const unsigned char *addr,
1625 					       u16 vid,
1626 					       bool *notified,
1627 					       struct netlink_ext_ack *extack);
1628 	int			(*ndo_fdb_del_bulk)(struct nlmsghdr *nlh,
1629 						    struct net_device *dev,
1630 						    struct netlink_ext_ack *extack);
1631 	int			(*ndo_fdb_dump)(struct sk_buff *skb,
1632 						struct netlink_callback *cb,
1633 						struct net_device *dev,
1634 						struct net_device *filter_dev,
1635 						int *idx);
1636 	int			(*ndo_fdb_get)(struct sk_buff *skb,
1637 					       struct nlattr *tb[],
1638 					       struct net_device *dev,
1639 					       const unsigned char *addr,
1640 					       u16 vid, u32 portid, u32 seq,
1641 					       struct netlink_ext_ack *extack);
1642 	int			(*ndo_mdb_add)(struct net_device *dev,
1643 					       struct nlattr *tb[],
1644 					       u16 nlmsg_flags,
1645 					       struct netlink_ext_ack *extack);
1646 	int			(*ndo_mdb_del)(struct net_device *dev,
1647 					       struct nlattr *tb[],
1648 					       struct netlink_ext_ack *extack);
1649 	int			(*ndo_mdb_del_bulk)(struct net_device *dev,
1650 						    struct nlattr *tb[],
1651 						    struct netlink_ext_ack *extack);
1652 	int			(*ndo_mdb_dump)(struct net_device *dev,
1653 						struct sk_buff *skb,
1654 						struct netlink_callback *cb);
1655 	int			(*ndo_mdb_get)(struct net_device *dev,
1656 					       struct nlattr *tb[], u32 portid,
1657 					       u32 seq,
1658 					       struct netlink_ext_ack *extack);
1659 	int			(*ndo_bridge_setlink)(struct net_device *dev,
1660 						      struct nlmsghdr *nlh,
1661 						      u16 flags,
1662 						      struct netlink_ext_ack *extack);
1663 	int			(*ndo_bridge_getlink)(struct sk_buff *skb,
1664 						      u32 pid, u32 seq,
1665 						      struct net_device *dev,
1666 						      u32 filter_mask,
1667 						      int nlflags);
1668 	int			(*ndo_bridge_dellink)(struct net_device *dev,
1669 						      struct nlmsghdr *nlh,
1670 						      u16 flags);
1671 	int			(*ndo_change_carrier)(struct net_device *dev,
1672 						      bool new_carrier);
1673 	int			(*ndo_get_phys_port_id)(struct net_device *dev,
1674 							struct netdev_phys_item_id *ppid);
1675 	int			(*ndo_get_port_parent_id)(struct net_device *dev,
1676 							  struct netdev_phys_item_id *ppid);
1677 	int			(*ndo_get_phys_port_name)(struct net_device *dev,
1678 							  char *name, size_t len);
1679 	void*			(*ndo_dfwd_add_station)(struct net_device *pdev,
1680 							struct net_device *dev);
1681 	void			(*ndo_dfwd_del_station)(struct net_device *pdev,
1682 							void *priv);
1683 
1684 	int			(*ndo_set_tx_maxrate)(struct net_device *dev,
1685 						      int queue_index,
1686 						      u32 maxrate);
1687 	int			(*ndo_get_iflink)(const struct net_device *dev);
1688 	int			(*ndo_fill_metadata_dst)(struct net_device *dev,
1689 						       struct sk_buff *skb);
1690 	void			(*ndo_set_rx_headroom)(struct net_device *dev,
1691 						       int needed_headroom);
1692 	int			(*ndo_bpf)(struct net_device *dev,
1693 					   struct netdev_bpf *bpf);
1694 	int			(*ndo_xdp_xmit)(struct net_device *dev, int n,
1695 						struct xdp_frame **xdp,
1696 						u32 flags);
1697 	struct net_device *	(*ndo_xdp_get_xmit_slave)(struct net_device *dev,
1698 							  struct xdp_buff *xdp);
1699 	int			(*ndo_xsk_wakeup)(struct net_device *dev,
1700 						  u32 queue_id, u32 flags);
1701 	int			(*ndo_tunnel_ctl)(struct net_device *dev,
1702 						  struct ip_tunnel_parm_kern *p,
1703 						  int cmd);
1704 	struct net_device *	(*ndo_get_peer_dev)(struct net_device *dev);
1705 	int                     (*ndo_fill_forward_path)(struct net_device_path_ctx *ctx,
1706                                                          struct net_device_path *path);
1707 	ktime_t			(*ndo_get_tstamp)(struct net_device *dev,
1708 						  const struct skb_shared_hwtstamps *hwtstamps,
1709 						  bool cycles);
1710 	int			(*ndo_hwtstamp_get)(struct net_device *dev,
1711 						    struct kernel_hwtstamp_config *kernel_config);
1712 	int			(*ndo_hwtstamp_set)(struct net_device *dev,
1713 						    struct kernel_hwtstamp_config *kernel_config,
1714 						    struct netlink_ext_ack *extack);
1715 
1716 #if IS_ENABLED(CONFIG_NET_SHAPER)
1717 	/**
1718 	 * @net_shaper_ops: Device shaping offload operations
1719 	 * see include/net/net_shapers.h
1720 	 */
1721 	const struct net_shaper_ops *net_shaper_ops;
1722 #endif
1723 };
1724 
1725 /**
1726  * enum netdev_priv_flags - &struct net_device priv_flags
1727  *
1728  * These are the &struct net_device, they are only set internally
1729  * by drivers and used in the kernel. These flags are invisible to
1730  * userspace; this means that the order of these flags can change
1731  * during any kernel release.
1732  *
1733  * You should add bitfield booleans after either net_device::priv_flags
1734  * (hotpath) or ::threaded (slowpath) instead of extending these flags.
1735  *
1736  * @IFF_802_1Q_VLAN: 802.1Q VLAN device
1737  * @IFF_EBRIDGE: Ethernet bridging device
1738  * @IFF_BONDING: bonding master or slave
1739  * @IFF_ISATAP: ISATAP interface (RFC4214)
1740  * @IFF_WAN_HDLC: WAN HDLC device
1741  * @IFF_XMIT_DST_RELEASE: dev_hard_start_xmit() is allowed to
1742  *	release skb->dst
1743  * @IFF_DONT_BRIDGE: disallow bridging this ether dev
1744  * @IFF_DISABLE_NETPOLL: disable netpoll at run-time
1745  * @IFF_MACVLAN_PORT: device used as macvlan port
1746  * @IFF_BRIDGE_PORT: device used as bridge port
1747  * @IFF_OVS_DATAPATH: device used as Open vSwitch datapath port
1748  * @IFF_TX_SKB_SHARING: The interface supports sharing skbs on transmit
1749  * @IFF_UNICAST_FLT: Supports unicast filtering
1750  * @IFF_TEAM_PORT: device used as team port
1751  * @IFF_SUPP_NOFCS: device supports sending custom FCS
1752  * @IFF_LIVE_ADDR_CHANGE: device supports hardware address
1753  *	change when it's running
1754  * @IFF_MACVLAN: Macvlan device
1755  * @IFF_XMIT_DST_RELEASE_PERM: IFF_XMIT_DST_RELEASE not taking into account
1756  *	underlying stacked devices
1757  * @IFF_L3MDEV_MASTER: device is an L3 master device
1758  * @IFF_NO_QUEUE: device can run without qdisc attached
1759  * @IFF_OPENVSWITCH: device is a Open vSwitch master
1760  * @IFF_L3MDEV_SLAVE: device is enslaved to an L3 master device
1761  * @IFF_TEAM: device is a team device
1762  * @IFF_PHONY_HEADROOM: the headroom value is controlled by an external
1763  *	entity (i.e. the master device for bridged veth)
1764  * @IFF_MACSEC: device is a MACsec device
1765  * @IFF_NO_RX_HANDLER: device doesn't support the rx_handler hook
1766  * @IFF_FAILOVER: device is a failover master device
1767  * @IFF_FAILOVER_SLAVE: device is lower dev of a failover master device
1768  * @IFF_L3MDEV_RX_HANDLER: only invoke the rx handler of L3 master device
1769  * @IFF_NO_ADDRCONF: prevent ipv6 addrconf
1770  * @IFF_TX_SKB_NO_LINEAR: device/driver is capable of xmitting frames with
1771  *	skb_headlen(skb) == 0 (data starts from frag0)
1772  */
1773 enum netdev_priv_flags {
1774 	IFF_802_1Q_VLAN			= 1<<0,
1775 	IFF_EBRIDGE			= 1<<1,
1776 	IFF_BONDING			= 1<<2,
1777 	IFF_ISATAP			= 1<<3,
1778 	IFF_WAN_HDLC			= 1<<4,
1779 	IFF_XMIT_DST_RELEASE		= 1<<5,
1780 	IFF_DONT_BRIDGE			= 1<<6,
1781 	IFF_DISABLE_NETPOLL		= 1<<7,
1782 	IFF_MACVLAN_PORT		= 1<<8,
1783 	IFF_BRIDGE_PORT			= 1<<9,
1784 	IFF_OVS_DATAPATH		= 1<<10,
1785 	IFF_TX_SKB_SHARING		= 1<<11,
1786 	IFF_UNICAST_FLT			= 1<<12,
1787 	IFF_TEAM_PORT			= 1<<13,
1788 	IFF_SUPP_NOFCS			= 1<<14,
1789 	IFF_LIVE_ADDR_CHANGE		= 1<<15,
1790 	IFF_MACVLAN			= 1<<16,
1791 	IFF_XMIT_DST_RELEASE_PERM	= 1<<17,
1792 	IFF_L3MDEV_MASTER		= 1<<18,
1793 	IFF_NO_QUEUE			= 1<<19,
1794 	IFF_OPENVSWITCH			= 1<<20,
1795 	IFF_L3MDEV_SLAVE		= 1<<21,
1796 	IFF_TEAM			= 1<<22,
1797 	IFF_PHONY_HEADROOM		= 1<<24,
1798 	IFF_MACSEC			= 1<<25,
1799 	IFF_NO_RX_HANDLER		= 1<<26,
1800 	IFF_FAILOVER			= 1<<27,
1801 	IFF_FAILOVER_SLAVE		= 1<<28,
1802 	IFF_L3MDEV_RX_HANDLER		= 1<<29,
1803 	IFF_NO_ADDRCONF			= BIT_ULL(30),
1804 	IFF_TX_SKB_NO_LINEAR		= BIT_ULL(31),
1805 };
1806 
1807 /* Specifies the type of the struct net_device::ml_priv pointer */
1808 enum netdev_ml_priv_type {
1809 	ML_PRIV_NONE,
1810 	ML_PRIV_CAN,
1811 };
1812 
1813 enum netdev_stat_type {
1814 	NETDEV_PCPU_STAT_NONE,
1815 	NETDEV_PCPU_STAT_LSTATS, /* struct pcpu_lstats */
1816 	NETDEV_PCPU_STAT_TSTATS, /* struct pcpu_sw_netstats */
1817 	NETDEV_PCPU_STAT_DSTATS, /* struct pcpu_dstats */
1818 };
1819 
1820 enum netmem_tx_mode {
1821 	NETMEM_TX_NONE,		/* no netmem TX support */
1822 	NETMEM_TX_DMA,		/* DMA-capable netmem TX (real HW) */
1823 	NETMEM_TX_NO_DMA,	/* no DMA, e.g. passthrough for virtual devs */
1824 };
1825 
1826 enum netdev_reg_state {
1827 	NETREG_UNINITIALIZED = 0,
1828 	NETREG_REGISTERED,	/* completed register_netdevice */
1829 	NETREG_UNREGISTERING,	/* called unregister_netdevice */
1830 	NETREG_UNREGISTERED,	/* completed unregister todo */
1831 	NETREG_RELEASED,	/* called free_netdev */
1832 	NETREG_DUMMY,		/* dummy device for NAPI poll */
1833 };
1834 
1835 /**
1836  *	struct net_device - The DEVICE structure.
1837  *
1838  *	Actually, this whole structure is a big mistake.  It mixes I/O
1839  *	data with strictly "high-level" data, and it has to know about
1840  *	almost every data structure used in the INET module.
1841  *
1842  *	@priv_flags:	flags invisible to userspace defined as bits, see
1843  *			enum netdev_priv_flags for the definitions
1844  *	@lltx:		device supports lockless Tx. Deprecated for real HW
1845  *			drivers. Mainly used by logical interfaces, such as
1846  *			bonding and tunnels
1847  *	@netmem_tx:	device netmem TX mode
1848  *	@pacing_offload: enable EDT pacing offload.
1849  *
1850  *	@name:	This is the first field of the "visible" part of this structure
1851  *		(i.e. as seen by users in the "Space.c" file).  It is the name
1852  *		of the interface.
1853  *
1854  *	@name_node:	Name hashlist node
1855  *	@ifalias:	SNMP alias
1856  *	@mem_end:	Shared memory end
1857  *	@mem_start:	Shared memory start
1858  *	@base_addr:	Device I/O address
1859  *	@irq:		Device IRQ number
1860  *
1861  *	@state:		Generic network queuing layer state, see netdev_state_t
1862  *	@dev_list:	The global list of network devices
1863  *	@napi_list:	List entry used for polling NAPI devices
1864  *	@unreg_list:	List entry  when we are unregistering the
1865  *			device; see the function unregister_netdev
1866  *	@unreg_list_net:List entry when we are unregistering the cross-netns
1867  *			device; see the function unregister_netdevice_queue_net()
1868  *	@close_list:	List entry used when we are closing the device
1869  *	@ptype_all:     Device-specific packet handlers for all protocols
1870  *	@ptype_specific: Device-specific, protocol-specific packet handlers
1871  *
1872  *	@adj_list:	Directly linked devices, like slaves for bonding
1873  *	@features:	Currently active device features
1874  *	@hw_features:	User-changeable features
1875  *
1876  *	@wanted_features:	User-requested features
1877  *	@vlan_features:		Mask of features inheritable by VLAN devices
1878  *
1879  *	@hw_enc_features:	Mask of features inherited by encapsulating devices
1880  *				This field indicates what encapsulation
1881  *				offloads the hardware is capable of doing,
1882  *				and drivers will need to set them appropriately.
1883  *
1884  *	@mpls_features:	Mask of features inheritable by MPLS
1885  *	@gso_partial_features: value(s) from NETIF_F_GSO\*
1886  *	@mangleid_features:	Mask of features requiring MANGLEID, will be
1887  *				disabled together with the latter.
1888  *
1889  *	@ifindex:	interface index
1890  *	@group:		The group the device belongs to
1891  *
1892  *	@stats:		Statistics struct, which was left as a legacy, use
1893  *			rtnl_link_stats64 instead
1894  *
1895  *	@core_stats:	core networking counters,
1896  *			do not use this in drivers
1897  *	@carrier_up_count:	Number of times the carrier has been up
1898  *	@carrier_down_count:	Number of times the carrier has been down
1899  *
1900  *	@wireless_handlers:	List of functions to handle Wireless Extensions,
1901  *				instead of ioctl,
1902  *				see <net/iw_handler.h> for details.
1903  *
1904  *	@netdev_ops:	Includes several pointers to callbacks,
1905  *			if one wants to override the ndo_*() functions
1906  *	@xdp_metadata_ops:	Includes pointers to XDP metadata callbacks.
1907  *	@xsk_tx_metadata_ops:	Includes pointers to AF_XDP TX metadata callbacks.
1908  *	@ethtool_ops:	Management operations
1909  *	@l3mdev_ops:	Layer 3 master device operations
1910  *	@ndisc_ops:	Includes callbacks for different IPv6 neighbour
1911  *			discovery handling. Necessary for e.g. 6LoWPAN.
1912  *	@xfrmdev_ops:	Transformation offload operations
1913  *	@tlsdev_ops:	Transport Layer Security offload operations
1914  *	@header_ops:	Includes callbacks for creating,parsing,caching,etc
1915  *			of Layer 2 headers.
1916  *
1917  *	@flags:		Interface flags (a la BSD)
1918  *	@xdp_features:	XDP capability supported by the device
1919  *	@gflags:	Global flags ( kept as legacy )
1920  *	@priv_len:	Size of the ->priv flexible array
1921  *	@priv:		Flexible array containing private data
1922  *	@operstate:	RFC2863 operstate
1923  *	@link_mode:	Mapping policy to operstate
1924  *	@if_port:	Selectable AUI, TP, ...
1925  *	@dma:		DMA channel
1926  *	@mtu:		Interface MTU value
1927  *	@min_mtu:	Interface Minimum MTU value
1928  *	@max_mtu:	Interface Maximum MTU value
1929  *	@type:		Interface hardware type
1930  *	@hard_header_len: Maximum hardware header length.
1931  *	@min_header_len:  Minimum hardware header length
1932  *
1933  *	@needed_headroom: Extra headroom the hardware may need, but not in all
1934  *			  cases can this be guaranteed
1935  *	@needed_tailroom: Extra tailroom the hardware may need, but not in all
1936  *			  cases can this be guaranteed. Some cases also use
1937  *			  LL_MAX_HEADER instead to allocate the skb
1938  *
1939  *	interface address info:
1940  *
1941  * 	@perm_addr:		Permanent hw address
1942  * 	@addr_assign_type:	Hw address assignment type
1943  * 	@addr_len:		Hardware address length
1944  *	@upper_level:		Maximum depth level of upper devices.
1945  *	@lower_level:		Maximum depth level of lower devices.
1946  *	@threaded:		napi threaded state.
1947  *	@neigh_priv_len:	Used in neigh_alloc()
1948  * 	@dev_id:		Used to differentiate devices that share
1949  * 				the same link layer address
1950  * 	@dev_port:		Used to differentiate devices that share
1951  * 				the same function
1952  *	@addr_list_lock:	XXX: need comments on this one
1953  *	@name_assign_type:	network interface name assignment type
1954  *	@uc_promisc:		Counter that indicates promiscuous mode
1955  *				has been enabled due to the need to listen to
1956  *				additional unicast addresses in a device that
1957  *				does not implement ndo_set_rx_mode()
1958  *	@work_node:		List entry for async netdev_work processing
1959  *	@work_tracker:		Refcount tracker for async netdev_work
1960  *	@work_pending:		Driver-defined pending netdev_work, passed to
1961  *				ndo_work() (see netdev_work_sched())
1962  *	@work_core_pending:	Core-defined pending netdev_work (NETDEV_WORK_*)
1963  *	@rx_mode_addr_cache:	Recycled snapshot entries for rx_mode work
1964  *	@rx_mode_retry_timer:	Timer that re-queues rx_mode work after failure
1965  *	@rx_mode_retry_count:	Number of consecutive retries already scheduled
1966  *	@uc:			unicast mac addresses
1967  *	@mc:			multicast mac addresses
1968  *	@dev_addrs:		list of device hw addresses
1969  *	@queues_kset:		Group of all Kobjects in the Tx and RX queues
1970  *	@promiscuity:		Number of times the NIC is told to work in
1971  *				promiscuous mode; if it becomes 0 the NIC will
1972  *				exit promiscuous mode
1973  *	@allmulti:		Counter, enables or disables allmulticast mode
1974  *
1975  *	@vlan_info:	VLAN info
1976  *	@dsa_ptr:	dsa specific data
1977  *	@tipc_ptr:	TIPC specific data
1978  *	@ip_ptr:	IPv4 specific data
1979  *	@ip6_ptr:	IPv6 specific data
1980  *	@ieee80211_ptr:	IEEE 802.11 specific data, assign before registering
1981  *	@ieee802154_ptr: IEEE 802.15.4 low-rate Wireless Personal Area Network
1982  *			 device struct
1983  *	@mpls_ptr:	mpls_dev struct pointer
1984  *	@mctp_ptr:	MCTP specific data
1985  *	@psp_dev:	PSP crypto device registered for this netdev
1986  *
1987  *	@dev_addr:	Hw address (before bcast,
1988  *			because most packets are unicast)
1989  *
1990  *	@_rx:			Array of RX queues
1991  *	@num_rx_queues:		Number of RX queues
1992  *				allocated at register_netdev() time
1993  *	@real_num_rx_queues: 	Number of RX queues currently active in device
1994  *	@xdp_prog:		XDP sockets filter program pointer
1995  *
1996  *	@rx_handler:		handler for received packets
1997  *	@rx_handler_data: 	XXX: need comments on this one
1998  *	@tcx_ingress:		BPF & clsact qdisc specific data for ingress processing
1999  *	@ingress_queue:		XXX: need comments on this one
2000  *	@nf_hooks_ingress:	netfilter hooks executed for ingress packets
2001  *	@broadcast:		hw bcast address
2002  *
2003  *	@rx_cpu_rmap:	CPU reverse-mapping for RX completion interrupts,
2004  *			indexed by RX queue number. Assigned by driver.
2005  *			This must only be set if the ndo_rx_flow_steer
2006  *			operation is defined
2007  *	@index_hlist:		Device index hash chain
2008  *
2009  *	@_tx:			Array of TX queues
2010  *	@num_tx_queues:		Number of TX queues allocated at alloc_netdev_mq() time
2011  *	@real_num_tx_queues: 	Number of TX queues currently active in device
2012  *	@qdisc:			Root qdisc from userspace point of view
2013  *	@tx_queue_len:		Max frames per queue allowed
2014  *	@tx_global_lock: 	XXX: need comments on this one
2015  *	@xdp_bulkq:		XDP device bulk queue
2016  *	@xps_maps:		all CPUs/RXQs maps for XPS device
2017  *
2018  *	@xps_maps:	XXX: need comments on this one
2019  *	@tcx_egress:		BPF & clsact qdisc specific data for egress processing
2020  *	@nf_hooks_egress:	netfilter hooks executed for egress packets
2021  *	@qdisc_hash:		qdisc hash table
2022  *	@watchdog_timeo:	Represents the timeout that is used by
2023  *				the watchdog (see dev_watchdog())
2024  *	@watchdog_lock:		protect watchdog_ref_held
2025  *	@watchdog_ref_held:	True if the watchdog device ref is taken.
2026  *	@watchdog_timer:	List of timers
2027  *
2028  *	@proto_down_reason:	reason a netdev interface is held down
2029  *	@pcpu_refcnt:		Number of references to this device
2030  *	@dev_refcnt:		Number of references to this device
2031  *	@refcnt_tracker:	Tracker directory for tracked references to this device
2032  *	@todo_list:		Delayed register/unregister
2033  *	@link_watch_list:	XXX: need comments on this one
2034  *
2035  *	@reg_state:		Register/unregister state machine
2036  *	@dismantle:		Device is going to be freed
2037  *	@needs_free_netdev:	Should unregister perform free_netdev?
2038  *	@priv_destructor:	Called from unregister
2039  *	@npinfo:		XXX: need comments on this one
2040  * 	@nd_net:		Network namespace this network device is inside
2041  *				protected by @lock
2042  *
2043  * 	@ml_priv:	Mid-layer private
2044  *	@ml_priv_type:  Mid-layer private type
2045  *
2046  *	@pcpu_stat_type:	Type of device statistics which the core should
2047  *				allocate/free: none, lstats, tstats, dstats. none
2048  *				means the driver is handling statistics allocation/
2049  *				freeing internally.
2050  *	@lstats:		Loopback statistics: packets, bytes
2051  *	@tstats:		Tunnel statistics: RX/TX packets, RX/TX bytes
2052  *	@dstats:		Dummy statistics: RX/TX/drop packets, RX/TX bytes
2053  *
2054  *	@garp_port:	GARP
2055  *	@mrp_port:	MRP
2056  *
2057  *	@dm_private:	Drop monitor private
2058  *
2059  *	@dev:		Class/net/name entry
2060  *	@sysfs_groups:	Space for optional device, statistics and wireless
2061  *			sysfs groups
2062  *
2063  *	@sysfs_rx_queue_group:	Space for optional per-rx queue attributes
2064  *	@rtnl_link_ops:	Rtnl_link_ops
2065  *	@stat_ops:	Optional ops for queue-aware statistics
2066  *	@queue_mgmt_ops:	Optional ops for queue management
2067  *
2068  *	@gso_max_size:	Maximum size of generic segmentation offload
2069  *	@tso_max_size:	Device (as in HW) limit on the max TSO request size
2070  *	@gso_max_segs:	Maximum number of segments that can be passed to the
2071  *			NIC for GSO
2072  *	@tso_max_segs:	Device (as in HW) limit on the max TSO segment count
2073  * 	@gso_ipv4_max_size:	Maximum size of generic segmentation offload,
2074  * 				for IPv4.
2075  *
2076  *	@dcbnl_ops:	Data Center Bridging netlink ops
2077  *	@num_tc:	Number of traffic classes in the net device
2078  *	@tc_to_txq:	XXX: need comments on this one
2079  *	@prio_tc_map:	XXX: need comments on this one
2080  *
2081  *	@fcoe_ddp_xid:	Max exchange id for FCoE LRO by ddp
2082  *
2083  *	@priomap:	XXX: need comments on this one
2084  *	@link_topo:	Physical link topology tracking attached PHYs
2085  *	@phydev:	Physical device may attach itself
2086  *			for hardware timestamping
2087  *	@sfp_bus:	attached &struct sfp_bus structure.
2088  *
2089  *	@qdisc_tx_busylock: lockdep class annotating Qdisc->busylock spinlock
2090  *
2091  *	@proto_down:	protocol port state information can be sent to the
2092  *			switch driver and used to set the phys state of the
2093  *			switch port.
2094  *
2095  *	@irq_affinity_auto: driver wants the core to store and re-assign the IRQ
2096  *			    affinity. Set by netif_enable_irq_affinity(), then
2097  *			    the driver must create a persistent napi by
2098  *			    netif_napi_add_config() and finally bind the napi to
2099  *			    IRQ (via netif_napi_set_irq()).
2100  *
2101  *	@rx_cpu_rmap_auto: driver wants the core to manage the ARFS rmap.
2102  *	                   Set by calling netif_enable_cpu_rmap().
2103  *
2104  *	@see_all_hwtstamp_requests: device wants to see calls to
2105  *			ndo_hwtstamp_set() for all timestamp requests
2106  *			regardless of source, even if those aren't
2107  *			HWTSTAMP_SOURCE_NETDEV
2108  *	@change_proto_down: device supports setting carrier via IFLA_PROTO_DOWN
2109  *	@netns_immutable: interface can't change network namespaces
2110  *	@fcoe_mtu:	device supports maximum FCoE MTU, 2158 bytes
2111  *
2112  *	@net_notifier_list:	List of per-net netdev notifier block
2113  *				that follow this device when it is moved
2114  *				to another network namespace.
2115  *
2116  *	@macsec_ops:    MACsec offloading ops
2117  *
2118  *	@udp_tunnel_nic_info:	static structure describing the UDP tunnel
2119  *				offload capabilities of the device
2120  *	@udp_tunnel_nic:	UDP tunnel offload state
2121  *	@ethtool:	ethtool related state
2122  *	@xdp_state:		stores info on attached XDP BPF programs
2123  *
2124  *	@nested_level:	Used as a parameter of spin_lock_nested() of
2125  *			dev->addr_list_lock.
2126  *	@unlink_list:	As netif_addr_lock() can be called recursively,
2127  *			keep a list of interfaces to be deleted.
2128  *	@gro_max_size:	Maximum size of aggregated packet in generic
2129  *			receive offload (GRO)
2130  * 	@gro_ipv4_max_size:	Maximum size of aggregated packet in generic
2131  * 				receive offload (GRO), for IPv4.
2132  *	@xdp_zc_max_segs:	Maximum number of segments supported by AF_XDP
2133  *				zero copy driver
2134  *
2135  *	@dev_addr_shadow:	Copy of @dev_addr to catch direct writes.
2136  *	@linkwatch_dev_tracker:	refcount tracker used by linkwatch.
2137  *	@watchdog_dev_tracker:	refcount tracker used by watchdog.
2138  *	@dev_registered_tracker:	tracker for reference held while
2139  *					registered
2140  *	@offload_xstats_l3:	L3 HW stats for this netdevice.
2141  *
2142  *	@devlink_port:	Pointer to related devlink port structure.
2143  *			Assigned by a driver before netdev registration using
2144  *			SET_NETDEV_DEVLINK_PORT macro. This pointer is static
2145  *			during the time netdevice is registered.
2146  *
2147  *	@dpll_pin: Pointer to the SyncE source pin of a DPLL subsystem,
2148  *		   where the clock is recovered.
2149  *
2150  *	@max_pacing_offload_horizon: max EDT offload horizon in nsec.
2151  *	@napi_config: An array of napi_config structures containing per-NAPI
2152  *		      settings.
2153  *	@num_napi_configs:	number of allocated NAPI config structs,
2154  *		always >= max(num_rx_queues, num_tx_queues).
2155  *	@gro_flush_timeout:	timeout for GRO layer in NAPI
2156  *	@napi_defer_hard_irqs:	If not zero, provides a counter that would
2157  *				allow to avoid NIC hard IRQ, on busy queues.
2158  *
2159  *	@neighbours:	List heads pointing to this device's neighbours'
2160  *			dev_list, one per address-family.
2161  *	@hwprov: Tracks which PTP performs hardware packet time stamping.
2162  *
2163  *	FIXME: cleanup struct net_device such that network protocol info
2164  *	moves out.
2165  */
2166 
2167 struct net_device {
2168 	/* Cacheline organization can be found documented in
2169 	 * Documentation/networking/net_cachelines/net_device.rst.
2170 	 * Please update the document when adding new fields.
2171 	 */
2172 
2173 	/* TX read-mostly hotpath */
2174 	__cacheline_group_begin(net_device_read_tx);
2175 	struct_group(priv_flags_fast,
2176 		unsigned long		priv_flags:32;
2177 		unsigned long		lltx:1;
2178 		unsigned long		netmem_tx:2;
2179 		unsigned long		pacing_offload:1;
2180 	);
2181 	const struct net_device_ops *netdev_ops;
2182 	const struct header_ops *header_ops;
2183 	struct netdev_queue	*_tx;
2184 	netdev_features_t	gso_partial_features;
2185 	unsigned int		real_num_tx_queues;
2186 	unsigned int		gso_max_size;
2187 	unsigned int		gso_ipv4_max_size;
2188 	u16			gso_max_segs;
2189 	s16			num_tc;
2190 	/* Note : dev->mtu is often read without holding a lock.
2191 	 * Writers usually hold RTNL.
2192 	 * It is recommended to use READ_ONCE() to annotate the reads,
2193 	 * and to use WRITE_ONCE() to annotate the writes.
2194 	 */
2195 	unsigned int		mtu;
2196 	unsigned short		needed_headroom;
2197 	struct netdev_tc_txq	tc_to_txq[TC_MAX_QUEUE];
2198 #ifdef CONFIG_XPS
2199 	struct xps_dev_maps __rcu *xps_maps[XPS_MAPS_MAX];
2200 #endif
2201 #ifdef CONFIG_NETFILTER_EGRESS
2202 	struct nf_hook_entries __rcu *nf_hooks_egress;
2203 #endif
2204 #ifdef CONFIG_NET_XGRESS
2205 	struct bpf_mprog_entry __rcu *tcx_egress;
2206 #endif
2207 	__cacheline_group_end(net_device_read_tx);
2208 
2209 	/* TXRX read-mostly hotpath */
2210 	__cacheline_group_begin(net_device_read_txrx);
2211 	union {
2212 		struct pcpu_lstats __percpu		*lstats;
2213 		struct pcpu_sw_netstats __percpu	*tstats;
2214 		struct pcpu_dstats __percpu		*dstats;
2215 	};
2216 	unsigned long		state;
2217 	unsigned int		flags;
2218 	unsigned short		hard_header_len;
2219 	enum netdev_stat_type	pcpu_stat_type:8;
2220 	netdev_features_t	features;
2221 	struct inet6_dev __rcu	*ip6_ptr;
2222 	__cacheline_group_end(net_device_read_txrx);
2223 
2224 	/* RX read-mostly hotpath */
2225 	__cacheline_group_begin(net_device_read_rx);
2226 	struct bpf_prog __rcu	*xdp_prog;
2227 	struct list_head	ptype_specific;
2228 	int			ifindex;
2229 	unsigned int		real_num_rx_queues;
2230 	struct netdev_rx_queue	*_rx;
2231 	unsigned int		gro_max_size;
2232 	unsigned int		gro_ipv4_max_size;
2233 	rx_handler_func_t __rcu	*rx_handler;
2234 	void __rcu		*rx_handler_data;
2235 	possible_net_t			nd_net;
2236 #ifdef CONFIG_NETPOLL
2237 	struct netpoll_info __rcu	*npinfo;
2238 #endif
2239 #ifdef CONFIG_NET_XGRESS
2240 	struct bpf_mprog_entry __rcu *tcx_ingress;
2241 #endif
2242 	__cacheline_group_end(net_device_read_rx);
2243 
2244 	char			name[IFNAMSIZ];
2245 	struct netdev_name_node	*name_node;
2246 	struct dev_ifalias	__rcu *ifalias;
2247 	/*
2248 	 *	I/O specific fields
2249 	 *	FIXME: Merge these and struct ifmap into one
2250 	 */
2251 	unsigned long		mem_end;
2252 	unsigned long		mem_start;
2253 	unsigned long		base_addr;
2254 
2255 	/*
2256 	 *	Some hardware also needs these fields (state,dev_list,
2257 	 *	napi_list,unreg_list,close_list) but they are not
2258 	 *	part of the usual set specified in Space.c.
2259 	 */
2260 
2261 
2262 	struct list_head	dev_list;
2263 	struct list_head	napi_list;
2264 	struct list_head	unreg_list;
2265 #ifdef CONFIG_DEBUG_NET_SMALL_RTNL
2266 	struct list_head	unreg_list_net;
2267 #endif
2268 	struct list_head	close_list;
2269 	struct list_head	ptype_all;
2270 
2271 	struct {
2272 		struct list_head upper;
2273 		struct list_head lower;
2274 	} adj_list;
2275 
2276 	/* Read-mostly cache-line for fast-path access */
2277 	xdp_features_t		xdp_features;
2278 	const struct xdp_metadata_ops *xdp_metadata_ops;
2279 	const struct xsk_tx_metadata_ops *xsk_tx_metadata_ops;
2280 	unsigned short		gflags;
2281 
2282 	unsigned short		needed_tailroom;
2283 
2284 	netdev_features_t	hw_features;
2285 	netdev_features_t	wanted_features;
2286 	netdev_features_t	vlan_features;
2287 	netdev_features_t	hw_enc_features;
2288 	netdev_features_t	mpls_features;
2289 	netdev_features_t	mangleid_features;
2290 
2291 	unsigned int		min_mtu;
2292 	unsigned int		max_mtu;
2293 	unsigned short		type;
2294 	unsigned char		min_header_len;
2295 	unsigned char		name_assign_type;
2296 
2297 	int			group;
2298 
2299 	struct net_device_stats	stats; /* not used by modern drivers */
2300 
2301 	struct net_device_core_stats __percpu *core_stats;
2302 
2303 	/* Stats to monitor link on/off, flapping */
2304 	atomic_t		carrier_up_count;
2305 	atomic_t		carrier_down_count;
2306 
2307 #ifdef CONFIG_WIRELESS_EXT
2308 	const struct iw_handler_def *wireless_handlers;
2309 #endif
2310 	const struct ethtool_ops *ethtool_ops;
2311 #ifdef CONFIG_NET_L3_MASTER_DEV
2312 	const struct l3mdev_ops	*l3mdev_ops;
2313 #endif
2314 #if IS_ENABLED(CONFIG_IPV6)
2315 	const struct ndisc_ops *ndisc_ops;
2316 #endif
2317 
2318 #ifdef CONFIG_XFRM_OFFLOAD
2319 	const struct xfrmdev_ops *xfrmdev_ops;
2320 #endif
2321 
2322 #if IS_ENABLED(CONFIG_TLS_DEVICE)
2323 	const struct tlsdev_ops *tlsdev_ops;
2324 #endif
2325 
2326 	unsigned int		operstate;
2327 	unsigned char		link_mode;
2328 
2329 	unsigned char		if_port;
2330 	unsigned char		dma;
2331 
2332 	/* Interface address info. */
2333 	unsigned char		perm_addr[MAX_ADDR_LEN];
2334 	unsigned char		addr_assign_type;
2335 	unsigned char		addr_len;
2336 	unsigned char		upper_level;
2337 	unsigned char		lower_level;
2338 	u8			threaded;
2339 
2340 	unsigned short		neigh_priv_len;
2341 	unsigned short          dev_id;
2342 	unsigned short          dev_port;
2343 	int			irq;
2344 	u32			priv_len;
2345 
2346 	spinlock_t		addr_list_lock;
2347 
2348 	struct netdev_hw_addr_list	uc;
2349 	struct netdev_hw_addr_list	mc;
2350 	struct netdev_hw_addr_list	dev_addrs;
2351 
2352 #ifdef CONFIG_SYSFS
2353 	struct kset		*queues_kset;
2354 #endif
2355 #ifdef CONFIG_LOCKDEP
2356 	struct list_head	unlink_list;
2357 #endif
2358 	unsigned int		promiscuity;
2359 	unsigned int		allmulti;
2360 	bool			uc_promisc;
2361 	struct list_head	work_node;
2362 	netdevice_tracker	work_tracker;
2363 	unsigned long		work_pending;
2364 	unsigned long		work_core_pending;
2365 	struct netdev_hw_addr_list	rx_mode_addr_cache;
2366 	struct timer_list	rx_mode_retry_timer;
2367 	unsigned int		rx_mode_retry_count;
2368 #ifdef CONFIG_LOCKDEP
2369 	unsigned char		nested_level;
2370 #endif
2371 
2372 
2373 	/* Protocol-specific pointers */
2374 	struct in_device __rcu	*ip_ptr;
2375 	/** @fib_nh_head: nexthops associated with this netdev */
2376 	struct hlist_head	fib_nh_head;
2377 
2378 #if IS_ENABLED(CONFIG_VLAN_8021Q)
2379 	struct vlan_info __rcu	*vlan_info;
2380 #endif
2381 #if IS_ENABLED(CONFIG_NET_DSA)
2382 	struct dsa_port		*dsa_ptr;
2383 #endif
2384 #if IS_ENABLED(CONFIG_TIPC)
2385 	struct tipc_bearer __rcu *tipc_ptr;
2386 #endif
2387 #if IS_ENABLED(CONFIG_CFG80211)
2388 	struct wireless_dev	*ieee80211_ptr;
2389 #endif
2390 #if IS_ENABLED(CONFIG_IEEE802154) || IS_ENABLED(CONFIG_6LOWPAN)
2391 	struct wpan_dev		*ieee802154_ptr;
2392 #endif
2393 #if IS_ENABLED(CONFIG_MPLS_ROUTING)
2394 	struct mpls_dev __rcu	*mpls_ptr;
2395 #endif
2396 #if IS_ENABLED(CONFIG_MCTP)
2397 	struct mctp_dev __rcu	*mctp_ptr;
2398 #endif
2399 #if IS_ENABLED(CONFIG_INET_PSP)
2400 	struct psp_dev __rcu	*psp_dev;
2401 #endif
2402 
2403 /*
2404  * Cache lines mostly used on receive path (including eth_type_trans())
2405  */
2406 	/* Interface address info used in eth_type_trans() */
2407 	const unsigned char	*dev_addr;
2408 
2409 	unsigned int		num_rx_queues;
2410 #define GRO_LEGACY_MAX_SIZE	65536u
2411 /* TCP minimal MSS is 8 (TCP_MIN_GSO_SIZE),
2412  * and shinfo->gso_segs is a 16bit field.
2413  */
2414 #define GRO_MAX_SIZE		(8 * 65535u)
2415 	unsigned int		xdp_zc_max_segs;
2416 	struct netdev_queue __rcu *ingress_queue;
2417 #ifdef CONFIG_NETFILTER_INGRESS
2418 	struct nf_hook_entries __rcu *nf_hooks_ingress;
2419 #endif
2420 
2421 	unsigned char		broadcast[MAX_ADDR_LEN];
2422 #ifdef CONFIG_RFS_ACCEL
2423 	struct cpu_rmap		*rx_cpu_rmap;
2424 #endif
2425 	struct hlist_node	index_hlist;
2426 
2427 /*
2428  * Cache lines mostly used on transmit path
2429  */
2430 	unsigned int		num_tx_queues;
2431 	struct Qdisc __rcu	*qdisc;
2432 	unsigned int		tx_queue_len;
2433 	spinlock_t		tx_global_lock;
2434 
2435 	struct xdp_dev_bulk_queue __percpu *xdp_bulkq;
2436 
2437 #ifdef CONFIG_NET_SCHED
2438 	DECLARE_HASHTABLE	(qdisc_hash, 4);
2439 #endif
2440 	/* These may be needed for future network-power-down code. */
2441 	struct timer_list	watchdog_timer;
2442 	int			watchdog_timeo;
2443 	spinlock_t		watchdog_lock;
2444 	bool			watchdog_ref_held;
2445 
2446 	u32                     proto_down_reason;
2447 
2448 	struct list_head	todo_list;
2449 
2450 #ifdef CONFIG_PCPU_DEV_REFCNT
2451 	int __percpu		*pcpu_refcnt;
2452 #else
2453 	refcount_t		dev_refcnt;
2454 #endif
2455 	struct ref_tracker_dir	refcnt_tracker;
2456 
2457 	struct list_head	link_watch_list;
2458 
2459 	u8 reg_state;
2460 
2461 	bool dismantle;
2462 
2463 	/** @moving_ns: device is changing netns, protected by @lock */
2464 	bool moving_ns;
2465 	/** @rtnl_link_initializing: Device being created, suppress events */
2466 	bool rtnl_link_initializing;
2467 
2468 	bool needs_free_netdev;
2469 	void (*priv_destructor)(struct net_device *dev);
2470 
2471 	/* mid-layer private */
2472 	void				*ml_priv;
2473 	enum netdev_ml_priv_type	ml_priv_type;
2474 
2475 #if IS_ENABLED(CONFIG_GARP)
2476 	struct garp_port __rcu	*garp_port;
2477 #endif
2478 #if IS_ENABLED(CONFIG_MRP)
2479 	struct mrp_port __rcu	*mrp_port;
2480 #endif
2481 #if IS_ENABLED(CONFIG_NET_DROP_MONITOR)
2482 	struct dm_hw_stat_delta __rcu *dm_private;
2483 #endif
2484 	struct device		dev;
2485 	const struct attribute_group *sysfs_groups[5];
2486 	const struct attribute_group *sysfs_rx_queue_group;
2487 
2488 	const struct rtnl_link_ops *rtnl_link_ops;
2489 
2490 	const struct netdev_stat_ops *stat_ops;
2491 
2492 	const struct netdev_queue_mgmt_ops *queue_mgmt_ops;
2493 
2494 	/* for setting kernel sock attribute on TCP connection setup */
2495 #define GSO_MAX_SEGS		65535u
2496 #define GSO_LEGACY_MAX_SIZE	65536u
2497 /* TCP minimal MSS is 8 (TCP_MIN_GSO_SIZE),
2498  * and shinfo->gso_segs is a 16bit field.
2499  */
2500 #define GSO_MAX_SIZE		(8 * GSO_MAX_SEGS)
2501 
2502 #define TSO_LEGACY_MAX_SIZE	65536
2503 #define TSO_MAX_SIZE		UINT_MAX
2504 	unsigned int		tso_max_size;
2505 #define TSO_MAX_SEGS		U16_MAX
2506 	u16			tso_max_segs;
2507 
2508 #ifdef CONFIG_DCB
2509 	const struct dcbnl_rtnl_ops *dcbnl_ops;
2510 #endif
2511 	u8			prio_tc_map[TC_BITMASK + 1];
2512 
2513 #if IS_ENABLED(CONFIG_FCOE)
2514 	unsigned int		fcoe_ddp_xid;
2515 #endif
2516 #if IS_ENABLED(CONFIG_CGROUP_NET_PRIO)
2517 	struct netprio_map __rcu *priomap;
2518 #endif
2519 	struct phy_link_topology	*link_topo;
2520 	struct phy_device	*phydev;
2521 	struct sfp_bus		*sfp_bus;
2522 	struct lock_class_key	*qdisc_tx_busylock;
2523 	bool			proto_down;
2524 	bool			irq_affinity_auto;
2525 	bool			rx_cpu_rmap_auto;
2526 
2527 	/* priv_flags_slow, ungrouped to save space */
2528 	unsigned long		see_all_hwtstamp_requests:1;
2529 	unsigned long		change_proto_down:1;
2530 	unsigned long		netns_immutable:1;
2531 	unsigned long		fcoe_mtu:1;
2532 
2533 	struct list_head	net_notifier_list;
2534 
2535 #if IS_ENABLED(CONFIG_MACSEC)
2536 	/* MACsec management functions */
2537 	const struct macsec_ops *macsec_ops;
2538 #endif
2539 	const struct udp_tunnel_nic_info	*udp_tunnel_nic_info;
2540 	struct udp_tunnel_nic	*udp_tunnel_nic;
2541 
2542 	/** @cfg: net_device queue-related configuration */
2543 	struct netdev_config	*cfg;
2544 	/**
2545 	 * @cfg_pending: same as @cfg but when device is being actively
2546 	 *	reconfigured includes any changes to the configuration
2547 	 *	requested by the user, but which may or may not be rejected.
2548 	 */
2549 	struct netdev_config	*cfg_pending;
2550 	struct ethtool_netdev_state *ethtool;
2551 
2552 	/* protected by rtnl_lock */
2553 	struct bpf_xdp_entity	xdp_state[__MAX_XDP_MODE];
2554 
2555 #ifdef CONFIG_XDP_SOCKETS
2556 	/** @xsk_pools: assigned AF_XDP pools, ops protected */
2557 	struct hlist_head	xsk_pools;
2558 #endif
2559 
2560 	u8 dev_addr_shadow[MAX_ADDR_LEN];
2561 	netdevice_tracker	linkwatch_dev_tracker;
2562 	netdevice_tracker	watchdog_dev_tracker;
2563 	netdevice_tracker	dev_registered_tracker;
2564 	struct rtnl_hw_stats64	*offload_xstats_l3;
2565 
2566 	struct devlink_port	*devlink_port;
2567 
2568 #if IS_ENABLED(CONFIG_DPLL)
2569 	struct dpll_pin	__rcu	*dpll_pin;
2570 #endif
2571 #if IS_ENABLED(CONFIG_PAGE_POOL)
2572 	/** @page_pools: page pools created for this netdevice */
2573 	struct hlist_head	page_pools;
2574 #endif
2575 
2576 	/** @irq_moder: dim parameters used if IS_ENABLED(CONFIG_DIMLIB). */
2577 	struct dim_irq_moder	*irq_moder;
2578 
2579 	u64			max_pacing_offload_horizon;
2580 	struct napi_config	*napi_config;
2581 	u32			num_napi_configs;
2582 	u32			napi_defer_hard_irqs;
2583 	unsigned long		gro_flush_timeout;
2584 
2585 	/**
2586 	 * @up: copy of @state's IFF_UP, but safe to read with just @lock.
2587 	 *	May report false negatives while the device is being opened
2588 	 *	or closed (@lock does not protect .ndo_open, or .ndo_close).
2589 	 */
2590 	bool			up;
2591 
2592 	/**
2593 	 * @request_ops_lock: request the core to run all @netdev_ops and
2594 	 * @ethtool_ops under the @lock.
2595 	 */
2596 	bool			request_ops_lock;
2597 
2598 	/**
2599 	 * @lock: netdev-scope lock, protects a small selection of fields.
2600 	 * Should always be taken using netdev_lock() / netdev_unlock() helpers.
2601 	 * Drivers are free to use it for other protection.
2602 	 *
2603 	 * For the drivers that implement shaper or queue API, the scope
2604 	 * of this lock is expanded to cover most ndo/queue/ethtool/sysfs
2605 	 * operations. Drivers may opt-in to this behavior by setting
2606 	 * @request_ops_lock.
2607 	 *
2608 	 * @lock protection mixes with rtnl_lock in multiple ways, fields are
2609 	 * either:
2610 	 *
2611 	 * - simply protected by the instance @lock;
2612 	 *
2613 	 * - double protected - writers hold both locks, readers hold either;
2614 	 *
2615 	 * - ops protected - protected by the lock held around the NDOs
2616 	 *   and other callbacks, that is the instance lock on devices for
2617 	 *   which netdev_need_ops_lock() returns true, otherwise by rtnl_lock;
2618 	 *
2619 	 * - double ops protected - always protected by rtnl_lock but for
2620 	 *   devices for which netdev_need_ops_lock() returns true - also
2621 	 *   the instance lock.
2622 	 *
2623 	 * Simply protects:
2624 	 *	@gro_flush_timeout, @napi_defer_hard_irqs, @napi_list,
2625 	 *	@net_shaper_hierarchy, @reg_state, @threaded
2626 	 *
2627 	 * Double protects:
2628 	 *	@up, @moving_ns, @nd_net, @xdp_features
2629 	 *
2630 	 * Ops protects:
2631 	 *	@cfg, @cfg_pending, @ethtool, @hwprov
2632 	 *
2633 	 * Double ops protects:
2634 	 *	@real_num_rx_queues, @real_num_tx_queues
2635 	 *
2636 	 * Also protects some fields in:
2637 	 *	struct napi_struct, struct netdev_queue, struct netdev_rx_queue
2638 	 *
2639 	 * Ordering:
2640 	 *
2641 	 * - take after rtnl_lock
2642 	 *
2643 	 * - for the case of netdev queue leasing, the netdev-scope lock is
2644 	 *   taken for both the virtual and the physical device; to prevent
2645 	 *   deadlocks, the virtual device's lock must always be acquired
2646 	 *   before the physical device's (see netdev_nl_queue_create_doit)
2647 	 */
2648 	struct mutex		lock;
2649 
2650 #if IS_ENABLED(CONFIG_NET_SHAPER)
2651 	/**
2652 	 * @net_shaper_hierarchy: data tracking the current shaper status
2653 	 *  see include/net/net_shapers.h
2654 	 */
2655 	struct net_shaper_hierarchy *net_shaper_hierarchy;
2656 #endif
2657 
2658 	struct hlist_head neighbours[NEIGH_NR_TABLES];
2659 
2660 	struct hwtstamp_provider __rcu	*hwprov;
2661 
2662 	u8			priv[] ____cacheline_aligned
2663 				       __counted_by(priv_len);
2664 } ____cacheline_aligned;
2665 #define to_net_dev(d) container_of(d, struct net_device, dev)
2666 
2667 /*
2668  * Driver should use this to assign devlink port instance to a netdevice
2669  * before it registers the netdevice. Therefore devlink_port is static
2670  * during the netdev lifetime after it is registered.
2671  */
2672 #define SET_NETDEV_DEVLINK_PORT(dev, port)			\
2673 ({								\
2674 	WARN_ON((dev)->reg_state != NETREG_UNINITIALIZED);	\
2675 	((dev)->devlink_port = (port));				\
2676 })
2677 
2678 static inline bool netif_elide_gro(const struct net_device *dev)
2679 {
2680 	if (!(dev->features & NETIF_F_GRO) || dev->xdp_prog)
2681 		return true;
2682 	return false;
2683 }
2684 
2685 #define	NETDEV_ALIGN		32
2686 
2687 static inline
2688 int netdev_get_prio_tc_map(const struct net_device *dev, u32 prio)
2689 {
2690 	return READ_ONCE(dev->prio_tc_map[prio & TC_BITMASK]);
2691 }
2692 
2693 static inline
2694 int netdev_set_prio_tc_map(struct net_device *dev, u8 prio, u8 tc)
2695 {
2696 	if (tc >= READ_ONCE(dev->num_tc))
2697 		return -EINVAL;
2698 
2699 	WRITE_ONCE(dev->prio_tc_map[prio & TC_BITMASK], tc & TC_BITMASK);
2700 	return 0;
2701 }
2702 
2703 int netdev_txq_to_tc(struct net_device *dev, unsigned int txq);
2704 void netdev_reset_tc(struct net_device *dev);
2705 int netdev_set_tc_queue(struct net_device *dev, u8 tc, u16 count, u16 offset);
2706 int netdev_set_num_tc(struct net_device *dev, u8 num_tc);
2707 
2708 static inline
2709 int netdev_get_num_tc(const struct net_device *dev)
2710 {
2711 	return READ_ONCE(dev->num_tc);
2712 }
2713 
2714 static inline void net_prefetch(void *p)
2715 {
2716 	prefetch(p);
2717 #if L1_CACHE_BYTES < 128
2718 	prefetch((u8 *)p + L1_CACHE_BYTES);
2719 #endif
2720 }
2721 
2722 static inline void net_prefetchw(void *p)
2723 {
2724 	prefetchw(p);
2725 #if L1_CACHE_BYTES < 128
2726 	prefetchw((u8 *)p + L1_CACHE_BYTES);
2727 #endif
2728 }
2729 
2730 void netdev_unbind_sb_channel(struct net_device *dev,
2731 			      struct net_device *sb_dev);
2732 int netdev_bind_sb_channel_queue(struct net_device *dev,
2733 				 struct net_device *sb_dev,
2734 				 u8 tc, u16 count, u16 offset);
2735 int netdev_set_sb_channel(struct net_device *dev, u16 channel);
2736 static inline int netdev_get_sb_channel(struct net_device *dev)
2737 {
2738 	return max_t(int, -READ_ONCE(dev->num_tc), 0);
2739 }
2740 
2741 static inline
2742 struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev,
2743 					 unsigned int index)
2744 {
2745 	DEBUG_NET_WARN_ON_ONCE(index >= dev->num_tx_queues);
2746 	return &dev->_tx[index];
2747 }
2748 
2749 static inline struct netdev_queue *skb_get_tx_queue(const struct net_device *dev,
2750 						    const struct sk_buff *skb)
2751 {
2752 	return netdev_get_tx_queue(dev, skb_get_queue_mapping(skb));
2753 }
2754 
2755 static inline void netdev_for_each_tx_queue(struct net_device *dev,
2756 					    void (*f)(struct net_device *,
2757 						      struct netdev_queue *,
2758 						      void *),
2759 					    void *arg)
2760 {
2761 	unsigned int i;
2762 
2763 	for (i = 0; i < dev->num_tx_queues; i++)
2764 		f(dev, &dev->_tx[i], arg);
2765 }
2766 
2767 u16 netdev_pick_tx(struct net_device *dev, struct sk_buff *skb,
2768 		     struct net_device *sb_dev);
2769 struct netdev_queue *netdev_core_pick_tx(struct net_device *dev,
2770 					 struct sk_buff *skb,
2771 					 struct net_device *sb_dev);
2772 
2773 /* returns the headroom that the master device needs to take in account
2774  * when forwarding to this dev
2775  */
2776 static inline unsigned netdev_get_fwd_headroom(struct net_device *dev)
2777 {
2778 	return dev->priv_flags & IFF_PHONY_HEADROOM ? 0 : dev->needed_headroom;
2779 }
2780 
2781 static inline void netdev_set_rx_headroom(struct net_device *dev, int new_hr)
2782 {
2783 	if (dev->netdev_ops->ndo_set_rx_headroom)
2784 		dev->netdev_ops->ndo_set_rx_headroom(dev, new_hr);
2785 }
2786 
2787 /* set the device rx headroom to the dev's default */
2788 static inline void netdev_reset_rx_headroom(struct net_device *dev)
2789 {
2790 	netdev_set_rx_headroom(dev, -1);
2791 }
2792 
2793 static inline void *netdev_get_ml_priv(struct net_device *dev,
2794 				       enum netdev_ml_priv_type type)
2795 {
2796 	if (dev->ml_priv_type != type)
2797 		return NULL;
2798 
2799 	return dev->ml_priv;
2800 }
2801 
2802 static inline void netdev_set_ml_priv(struct net_device *dev,
2803 				      void *ml_priv,
2804 				      enum netdev_ml_priv_type type)
2805 {
2806 	WARN(dev->ml_priv_type && dev->ml_priv_type != type,
2807 	     "Overwriting already set ml_priv_type (%u) with different ml_priv_type (%u)!\n",
2808 	     dev->ml_priv_type, type);
2809 	WARN(!dev->ml_priv_type && dev->ml_priv,
2810 	     "Overwriting already set ml_priv and ml_priv_type is ML_PRIV_NONE!\n");
2811 
2812 	dev->ml_priv = ml_priv;
2813 	dev->ml_priv_type = type;
2814 }
2815 
2816 /*
2817  * Net namespace inlines
2818  */
2819 static inline
2820 struct net *dev_net(const struct net_device *dev)
2821 {
2822 	return read_pnet(&dev->nd_net);
2823 }
2824 
2825 static inline
2826 struct net *dev_net_rcu(const struct net_device *dev)
2827 {
2828 	return read_pnet_rcu(&dev->nd_net);
2829 }
2830 
2831 static inline
2832 void dev_net_set(struct net_device *dev, struct net *net)
2833 {
2834 	write_pnet(&dev->nd_net, net);
2835 }
2836 
2837 /**
2838  *	netdev_priv - access network device private data
2839  *	@dev: network device
2840  *
2841  * Get network device private data
2842  */
2843 static inline void *netdev_priv(const struct net_device *dev)
2844 {
2845 	return (void *)dev->priv;
2846 }
2847 
2848 /**
2849  * netdev_from_priv() - get network device from priv
2850  * @priv: network device private data
2851  *
2852  * Returns: net_device to which @priv belongs
2853  */
2854 static inline struct net_device *netdev_from_priv(const void *priv)
2855 {
2856 	/*
2857 	 * When GCC can see that @priv came from netdev_priv(), it can
2858 	 * compute an object size of 0 for the net_device and its members,
2859 	 * which makes FORTIFY_SOURCE fail valid accesses through the result:
2860 	 * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127875
2861 	 */
2862 	OPTIMIZER_HIDE_VAR(priv);
2863 	return container_of(priv, struct net_device, priv);
2864 }
2865 
2866 /* Set the sysfs physical device reference for the network logical device
2867  * if set prior to registration will cause a symlink during initialization.
2868  */
2869 #define SET_NETDEV_DEV(net, pdev)	((net)->dev.parent = (pdev))
2870 
2871 /* Set the sysfs device type for the network logical device to allow
2872  * fine-grained identification of different network device types. For
2873  * example Ethernet, Wireless LAN, Bluetooth, WiMAX etc.
2874  */
2875 #define SET_NETDEV_DEVTYPE(net, devtype)	((net)->dev.type = (devtype))
2876 
2877 void netif_queue_set_napi(struct net_device *dev, unsigned int queue_index,
2878 			  enum netdev_queue_type type,
2879 			  struct napi_struct *napi);
2880 
2881 static inline void netdev_lock(struct net_device *dev)
2882 {
2883 	mutex_lock(&dev->lock);
2884 }
2885 
2886 static inline void netdev_unlock(struct net_device *dev)
2887 {
2888 	mutex_unlock(&dev->lock);
2889 }
2890 /* Additional netdev_lock()-related helpers are in net/netdev_lock.h */
2891 
2892 void netif_napi_set_irq_locked(struct napi_struct *napi, int irq);
2893 
2894 static inline void netif_napi_set_irq(struct napi_struct *napi, int irq)
2895 {
2896 	netdev_lock(napi->dev);
2897 	netif_napi_set_irq_locked(napi, irq);
2898 	netdev_unlock(napi->dev);
2899 }
2900 
2901 /* Default NAPI poll() weight
2902  * Device drivers are strongly advised to not use bigger value
2903  */
2904 #define NAPI_POLL_WEIGHT 64
2905 
2906 void netif_napi_add_weight_locked(struct net_device *dev,
2907 				  struct napi_struct *napi,
2908 				  int (*poll)(struct napi_struct *, int),
2909 				  int weight);
2910 
2911 static inline void
2912 netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi,
2913 		      int (*poll)(struct napi_struct *, int), int weight)
2914 {
2915 	netdev_lock(dev);
2916 	netif_napi_add_weight_locked(dev, napi, poll, weight);
2917 	netdev_unlock(dev);
2918 }
2919 
2920 /**
2921  * netif_napi_add() - initialize a NAPI context
2922  * @dev:  network device
2923  * @napi: NAPI context
2924  * @poll: polling function
2925  *
2926  * netif_napi_add() must be used to initialize a NAPI context prior to calling
2927  * *any* of the other NAPI-related functions.
2928  */
2929 static inline void
2930 netif_napi_add(struct net_device *dev, struct napi_struct *napi,
2931 	       int (*poll)(struct napi_struct *, int))
2932 {
2933 	netif_napi_add_weight(dev, napi, poll, NAPI_POLL_WEIGHT);
2934 }
2935 
2936 static inline void
2937 netif_napi_add_locked(struct net_device *dev, struct napi_struct *napi,
2938 		      int (*poll)(struct napi_struct *, int))
2939 {
2940 	netif_napi_add_weight_locked(dev, napi, poll, NAPI_POLL_WEIGHT);
2941 }
2942 
2943 static inline void
2944 netif_napi_add_tx_weight(struct net_device *dev,
2945 			 struct napi_struct *napi,
2946 			 int (*poll)(struct napi_struct *, int),
2947 			 int weight)
2948 {
2949 	set_bit(NAPI_STATE_NO_BUSY_POLL, &napi->state);
2950 	netif_napi_add_weight(dev, napi, poll, weight);
2951 }
2952 
2953 static inline void
2954 netif_napi_add_config_locked(struct net_device *dev, struct napi_struct *napi,
2955 			     int (*poll)(struct napi_struct *, int), int index)
2956 {
2957 	napi->index = index;
2958 	napi->config = &dev->napi_config[index];
2959 	netif_napi_add_weight_locked(dev, napi, poll, NAPI_POLL_WEIGHT);
2960 }
2961 
2962 /**
2963  * netif_napi_add_config - initialize a NAPI context with persistent config
2964  * @dev: network device
2965  * @napi: NAPI context
2966  * @poll: polling function
2967  * @index: the NAPI index
2968  */
2969 static inline void
2970 netif_napi_add_config(struct net_device *dev, struct napi_struct *napi,
2971 		      int (*poll)(struct napi_struct *, int), int index)
2972 {
2973 	netdev_lock(dev);
2974 	netif_napi_add_config_locked(dev, napi, poll, index);
2975 	netdev_unlock(dev);
2976 }
2977 
2978 /**
2979  * netif_napi_add_tx() - initialize a NAPI context to be used for Tx only
2980  * @dev:  network device
2981  * @napi: NAPI context
2982  * @poll: polling function
2983  *
2984  * This variant of netif_napi_add() should be used from drivers using NAPI
2985  * to exclusively poll a TX queue.
2986  * This will avoid we add it into napi_hash[], thus polluting this hash table.
2987  */
2988 static inline void netif_napi_add_tx(struct net_device *dev,
2989 				     struct napi_struct *napi,
2990 				     int (*poll)(struct napi_struct *, int))
2991 {
2992 	netif_napi_add_tx_weight(dev, napi, poll, NAPI_POLL_WEIGHT);
2993 }
2994 
2995 void __netif_napi_del_locked(struct napi_struct *napi);
2996 
2997 /**
2998  *  __netif_napi_del - remove a NAPI context
2999  *  @napi: NAPI context
3000  *
3001  * Warning: caller must observe RCU grace period before freeing memory
3002  * containing @napi. Drivers might want to call this helper to combine
3003  * all the needed RCU grace periods into a single one.
3004  */
3005 static inline void __netif_napi_del(struct napi_struct *napi)
3006 {
3007 	netdev_lock(napi->dev);
3008 	__netif_napi_del_locked(napi);
3009 	netdev_unlock(napi->dev);
3010 }
3011 
3012 static inline void netif_napi_del_locked(struct napi_struct *napi)
3013 {
3014 	__netif_napi_del_locked(napi);
3015 	synchronize_net();
3016 }
3017 
3018 /**
3019  *  netif_napi_del - remove a NAPI context
3020  *  @napi: NAPI context
3021  *
3022  *  netif_napi_del() removes a NAPI context from the network device NAPI list
3023  */
3024 static inline void netif_napi_del(struct napi_struct *napi)
3025 {
3026 	__netif_napi_del(napi);
3027 	synchronize_net();
3028 }
3029 
3030 int netif_enable_cpu_rmap(struct net_device *dev, unsigned int num_irqs);
3031 void netif_set_affinity_auto(struct net_device *dev);
3032 
3033 struct packet_type {
3034 	__be16			type;	/* This is really htons(ether_type). */
3035 	bool			ignore_outgoing;
3036 	struct net_device	*dev;	/* NULL is wildcarded here	     */
3037 	netdevice_tracker	dev_tracker;
3038 	int			(*func) (struct sk_buff *,
3039 					 struct net_device *,
3040 					 struct packet_type *,
3041 					 struct net_device *);
3042 	void			(*list_func) (struct list_head *,
3043 					      struct packet_type *,
3044 					      struct net_device *);
3045 	bool			(*id_match)(struct packet_type *ptype,
3046 					    struct sock *sk);
3047 	struct net		*af_packet_net;
3048 	void			*af_packet_priv;
3049 	struct list_head	list;
3050 };
3051 
3052 struct offload_callbacks {
3053 	struct sk_buff		*(*gso_segment)(struct sk_buff *skb,
3054 						netdev_features_t features);
3055 	struct sk_buff		*(*gro_receive)(struct list_head *head,
3056 						struct sk_buff *skb);
3057 	int			(*gro_complete)(struct sk_buff *skb, int nhoff);
3058 };
3059 
3060 struct packet_offload {
3061 	__be16			 type;	/* This is really htons(ether_type). */
3062 	u16			 priority;
3063 	struct offload_callbacks callbacks;
3064 	struct list_head	 list;
3065 };
3066 
3067 /* often modified stats are per-CPU, other are shared (netdev->stats) */
3068 struct pcpu_sw_netstats {
3069 	u64_stats_t		rx_packets;
3070 	u64_stats_t		rx_bytes;
3071 	u64_stats_t		tx_packets;
3072 	u64_stats_t		tx_bytes;
3073 	struct u64_stats_sync   syncp;
3074 } __aligned(4 * sizeof(u64));
3075 
3076 struct pcpu_dstats {
3077 	u64_stats_t		rx_packets;
3078 	u64_stats_t		rx_bytes;
3079 	u64_stats_t		tx_packets;
3080 	u64_stats_t		tx_bytes;
3081 	u64_stats_t		rx_drops;
3082 	u64_stats_t		tx_drops;
3083 	struct u64_stats_sync	syncp;
3084 } __aligned(8 * sizeof(u64));
3085 
3086 struct pcpu_lstats {
3087 	u64_stats_t packets;
3088 	u64_stats_t bytes;
3089 	struct u64_stats_sync syncp;
3090 } __aligned(2 * sizeof(u64));
3091 
3092 void dev_lstats_read(struct net_device *dev, u64 *packets, u64 *bytes);
3093 
3094 static inline void dev_sw_netstats_rx_add(struct net_device *dev, unsigned int len)
3095 {
3096 	struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
3097 
3098 	u64_stats_update_begin(&tstats->syncp);
3099 	u64_stats_add(&tstats->rx_bytes, len);
3100 	u64_stats_inc(&tstats->rx_packets);
3101 	u64_stats_update_end(&tstats->syncp);
3102 }
3103 
3104 static inline void dev_sw_netstats_tx_add(struct net_device *dev,
3105 					  unsigned int packets,
3106 					  unsigned int len)
3107 {
3108 	struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
3109 
3110 	u64_stats_update_begin(&tstats->syncp);
3111 	u64_stats_add(&tstats->tx_bytes, len);
3112 	u64_stats_add(&tstats->tx_packets, packets);
3113 	u64_stats_update_end(&tstats->syncp);
3114 }
3115 
3116 static inline void dev_lstats_add(struct net_device *dev, unsigned int len)
3117 {
3118 	struct pcpu_lstats *lstats = this_cpu_ptr(dev->lstats);
3119 
3120 	u64_stats_update_begin(&lstats->syncp);
3121 	u64_stats_add(&lstats->bytes, len);
3122 	u64_stats_inc(&lstats->packets);
3123 	u64_stats_update_end(&lstats->syncp);
3124 }
3125 
3126 static inline void dev_dstats_rx_add(struct net_device *dev,
3127 				     unsigned int len)
3128 {
3129 	struct pcpu_dstats *dstats = this_cpu_ptr(dev->dstats);
3130 
3131 	u64_stats_update_begin(&dstats->syncp);
3132 	u64_stats_inc(&dstats->rx_packets);
3133 	u64_stats_add(&dstats->rx_bytes, len);
3134 	u64_stats_update_end(&dstats->syncp);
3135 }
3136 
3137 static inline void dev_dstats_rx_dropped(struct net_device *dev)
3138 {
3139 	struct pcpu_dstats *dstats = this_cpu_ptr(dev->dstats);
3140 
3141 	u64_stats_update_begin(&dstats->syncp);
3142 	u64_stats_inc(&dstats->rx_drops);
3143 	u64_stats_update_end(&dstats->syncp);
3144 }
3145 
3146 static inline void dev_dstats_rx_dropped_add(struct net_device *dev,
3147 					     unsigned int packets)
3148 {
3149 	struct pcpu_dstats *dstats = this_cpu_ptr(dev->dstats);
3150 
3151 	u64_stats_update_begin(&dstats->syncp);
3152 	u64_stats_add(&dstats->rx_drops, packets);
3153 	u64_stats_update_end(&dstats->syncp);
3154 }
3155 
3156 static inline void dev_dstats_tx_add(struct net_device *dev,
3157 				     unsigned int len)
3158 {
3159 	struct pcpu_dstats *dstats = this_cpu_ptr(dev->dstats);
3160 
3161 	u64_stats_update_begin(&dstats->syncp);
3162 	u64_stats_inc(&dstats->tx_packets);
3163 	u64_stats_add(&dstats->tx_bytes, len);
3164 	u64_stats_update_end(&dstats->syncp);
3165 }
3166 
3167 static inline void dev_dstats_tx_dropped(struct net_device *dev)
3168 {
3169 	struct pcpu_dstats *dstats = this_cpu_ptr(dev->dstats);
3170 
3171 	u64_stats_update_begin(&dstats->syncp);
3172 	u64_stats_inc(&dstats->tx_drops);
3173 	u64_stats_update_end(&dstats->syncp);
3174 }
3175 
3176 #define __netdev_alloc_pcpu_stats(type, gfp)				\
3177 ({									\
3178 	typeof(type) __percpu *pcpu_stats = alloc_percpu_gfp(type, gfp);\
3179 	if (pcpu_stats)	{						\
3180 		int __cpu;						\
3181 		for_each_possible_cpu(__cpu) {				\
3182 			typeof(type) *stat;				\
3183 			stat = per_cpu_ptr(pcpu_stats, __cpu);		\
3184 			u64_stats_init(&stat->syncp);			\
3185 		}							\
3186 	}								\
3187 	pcpu_stats;							\
3188 })
3189 
3190 #define netdev_alloc_pcpu_stats(type)					\
3191 	__netdev_alloc_pcpu_stats(type, GFP_KERNEL)
3192 
3193 #define devm_netdev_alloc_pcpu_stats(dev, type)				\
3194 ({									\
3195 	typeof(type) __percpu *pcpu_stats = devm_alloc_percpu(dev, type);\
3196 	if (pcpu_stats) {						\
3197 		int __cpu;						\
3198 		for_each_possible_cpu(__cpu) {				\
3199 			typeof(type) *stat;				\
3200 			stat = per_cpu_ptr(pcpu_stats, __cpu);		\
3201 			u64_stats_init(&stat->syncp);			\
3202 		}							\
3203 	}								\
3204 	pcpu_stats;							\
3205 })
3206 
3207 enum netdev_lag_tx_type {
3208 	NETDEV_LAG_TX_TYPE_UNKNOWN,
3209 	NETDEV_LAG_TX_TYPE_RANDOM,
3210 	NETDEV_LAG_TX_TYPE_BROADCAST,
3211 	NETDEV_LAG_TX_TYPE_ROUNDROBIN,
3212 	NETDEV_LAG_TX_TYPE_ACTIVEBACKUP,
3213 	NETDEV_LAG_TX_TYPE_HASH,
3214 };
3215 
3216 enum netdev_lag_hash {
3217 	NETDEV_LAG_HASH_NONE,
3218 	NETDEV_LAG_HASH_L2,
3219 	NETDEV_LAG_HASH_L34,
3220 	NETDEV_LAG_HASH_L23,
3221 	NETDEV_LAG_HASH_E23,
3222 	NETDEV_LAG_HASH_E34,
3223 	NETDEV_LAG_HASH_VLAN_SRCMAC,
3224 	NETDEV_LAG_HASH_UNKNOWN,
3225 };
3226 
3227 struct netdev_lag_upper_info {
3228 	enum netdev_lag_tx_type tx_type;
3229 	enum netdev_lag_hash hash_type;
3230 };
3231 
3232 struct netdev_lag_lower_state_info {
3233 	u8 link_up : 1,
3234 	   tx_enabled : 1;
3235 };
3236 
3237 #include <linux/notifier.h>
3238 
3239 /* netdevice notifier chain. Please remember to update netdev_cmd_to_name()
3240  * and the rtnetlink notification exclusion list in rtnetlink_event() when
3241  * adding new types.
3242  */
3243 enum netdev_cmd {
3244 	NETDEV_UP	= 1,	/* For now you can't veto a device up/down */
3245 	NETDEV_DOWN,
3246 	NETDEV_REBOOT,		/* Tell a protocol stack a network interface
3247 				   detected a hardware crash and restarted
3248 				   - we can use this eg to kick tcp sessions
3249 				   once done */
3250 	NETDEV_CHANGE,		/* Notify device state change */
3251 	NETDEV_REGISTER,
3252 	NETDEV_UNREGISTER,
3253 	NETDEV_CHANGEMTU,	/* notify after mtu change happened */
3254 	NETDEV_CHANGEADDR,	/* notify after the address change */
3255 	NETDEV_PRE_CHANGEADDR,	/* notify before the address change */
3256 	NETDEV_GOING_DOWN,
3257 	NETDEV_CHANGENAME,
3258 	NETDEV_FEAT_CHANGE,
3259 	NETDEV_BONDING_FAILOVER,
3260 	NETDEV_PRE_UP,
3261 	NETDEV_PRE_TYPE_CHANGE,
3262 	NETDEV_POST_TYPE_CHANGE,
3263 	NETDEV_POST_INIT,
3264 	NETDEV_PRE_UNINIT,
3265 	NETDEV_RELEASE,
3266 	NETDEV_NOTIFY_PEERS,
3267 	NETDEV_JOIN,
3268 	NETDEV_CHANGEUPPER,
3269 	NETDEV_RESEND_IGMP,
3270 	NETDEV_PRECHANGEMTU,	/* notify before mtu change happened */
3271 	NETDEV_CHANGEINFODATA,
3272 	NETDEV_BONDING_INFO,
3273 	NETDEV_PRECHANGEUPPER,
3274 	NETDEV_CHANGELOWERSTATE,
3275 	NETDEV_UDP_TUNNEL_PUSH_INFO,
3276 	NETDEV_UDP_TUNNEL_DROP_INFO,
3277 	NETDEV_CHANGE_TX_QUEUE_LEN,
3278 	NETDEV_CVLAN_FILTER_PUSH_INFO,
3279 	NETDEV_CVLAN_FILTER_DROP_INFO,
3280 	NETDEV_SVLAN_FILTER_PUSH_INFO,
3281 	NETDEV_SVLAN_FILTER_DROP_INFO,
3282 	NETDEV_OFFLOAD_XSTATS_ENABLE,
3283 	NETDEV_OFFLOAD_XSTATS_DISABLE,
3284 	NETDEV_OFFLOAD_XSTATS_REPORT_USED,
3285 	NETDEV_OFFLOAD_XSTATS_REPORT_DELTA,
3286 	NETDEV_XDP_FEAT_CHANGE,
3287 };
3288 const char *netdev_cmd_to_name(enum netdev_cmd cmd);
3289 
3290 int register_netdevice_notifier(struct notifier_block *nb);
3291 int unregister_netdevice_notifier(struct notifier_block *nb);
3292 int register_netdevice_notifier_net(struct net *net, struct notifier_block *nb);
3293 int unregister_netdevice_notifier_net(struct net *net,
3294 				      struct notifier_block *nb);
3295 int register_netdevice_notifier_dev_net(struct net_device *dev,
3296 					struct notifier_block *nb,
3297 					struct netdev_net_notifier *nn);
3298 int unregister_netdevice_notifier_dev_net(struct net_device *dev,
3299 					  struct notifier_block *nb,
3300 					  struct netdev_net_notifier *nn);
3301 
3302 struct netdev_notifier_info {
3303 	struct net_device	*dev;
3304 	struct netlink_ext_ack	*extack;
3305 };
3306 
3307 struct netdev_notifier_info_ext {
3308 	struct netdev_notifier_info info; /* must be first */
3309 	union {
3310 		u32 mtu;
3311 	} ext;
3312 };
3313 
3314 struct netdev_notifier_change_info {
3315 	struct netdev_notifier_info info; /* must be first */
3316 	unsigned int flags_changed;
3317 };
3318 
3319 struct netdev_notifier_changeupper_info {
3320 	struct netdev_notifier_info info; /* must be first */
3321 	struct net_device *upper_dev; /* new upper dev */
3322 	bool master; /* is upper dev master */
3323 	bool linking; /* is the notification for link or unlink */
3324 	void *upper_info; /* upper dev info */
3325 };
3326 
3327 struct netdev_notifier_changelowerstate_info {
3328 	struct netdev_notifier_info info; /* must be first */
3329 	void *lower_state_info; /* is lower dev state */
3330 };
3331 
3332 struct netdev_notifier_pre_changeaddr_info {
3333 	struct netdev_notifier_info info; /* must be first */
3334 	const unsigned char *dev_addr;
3335 };
3336 
3337 enum netdev_offload_xstats_type {
3338 	NETDEV_OFFLOAD_XSTATS_TYPE_L3 = 1,
3339 };
3340 
3341 struct netdev_notifier_offload_xstats_info {
3342 	struct netdev_notifier_info info; /* must be first */
3343 	enum netdev_offload_xstats_type type;
3344 
3345 	union {
3346 		/* NETDEV_OFFLOAD_XSTATS_REPORT_DELTA */
3347 		struct netdev_notifier_offload_xstats_rd *report_delta;
3348 		/* NETDEV_OFFLOAD_XSTATS_REPORT_USED */
3349 		struct netdev_notifier_offload_xstats_ru *report_used;
3350 	};
3351 };
3352 
3353 int netdev_offload_xstats_enable(struct net_device *dev,
3354 				 enum netdev_offload_xstats_type type,
3355 				 struct netlink_ext_ack *extack);
3356 int netdev_offload_xstats_disable(struct net_device *dev,
3357 				  enum netdev_offload_xstats_type type);
3358 bool netdev_offload_xstats_enabled(const struct net_device *dev,
3359 				   enum netdev_offload_xstats_type type);
3360 int netdev_offload_xstats_get(struct net_device *dev,
3361 			      enum netdev_offload_xstats_type type,
3362 			      struct rtnl_hw_stats64 *stats, bool *used,
3363 			      struct netlink_ext_ack *extack);
3364 void
3365 netdev_offload_xstats_report_delta(struct netdev_notifier_offload_xstats_rd *rd,
3366 				   const struct rtnl_hw_stats64 *stats);
3367 void
3368 netdev_offload_xstats_report_used(struct netdev_notifier_offload_xstats_ru *ru);
3369 void netdev_offload_xstats_push_delta(struct net_device *dev,
3370 				      enum netdev_offload_xstats_type type,
3371 				      const struct rtnl_hw_stats64 *stats);
3372 
3373 static inline void netdev_notifier_info_init(struct netdev_notifier_info *info,
3374 					     struct net_device *dev)
3375 {
3376 	info->dev = dev;
3377 	info->extack = NULL;
3378 }
3379 
3380 static inline struct net_device *
3381 netdev_notifier_info_to_dev(const struct netdev_notifier_info *info)
3382 {
3383 	return info->dev;
3384 }
3385 
3386 static inline struct netlink_ext_ack *
3387 netdev_notifier_info_to_extack(const struct netdev_notifier_info *info)
3388 {
3389 	return info->extack;
3390 }
3391 
3392 int call_netdevice_notifiers(unsigned long val, struct net_device *dev);
3393 int call_netdevice_notifiers_info(unsigned long val,
3394 				  struct netdev_notifier_info *info);
3395 
3396 #define for_each_netdev(net, d)		\
3397 		list_for_each_entry(d, &(net)->dev_base_head, dev_list)
3398 #define for_each_netdev_reverse(net, d)	\
3399 		list_for_each_entry_reverse(d, &(net)->dev_base_head, dev_list)
3400 #define for_each_netdev_rcu(net, d)		\
3401 		list_for_each_entry_rcu(d, &(net)->dev_base_head, dev_list)
3402 #define for_each_netdev_safe(net, d, n)	\
3403 		list_for_each_entry_safe(d, n, &(net)->dev_base_head, dev_list)
3404 #define for_each_netdev_continue(net, d)		\
3405 		list_for_each_entry_continue(d, &(net)->dev_base_head, dev_list)
3406 #define for_each_netdev_continue_reverse(net, d)		\
3407 		list_for_each_entry_continue_reverse(d, &(net)->dev_base_head, \
3408 						     dev_list)
3409 #define for_each_netdev_continue_rcu(net, d)		\
3410 	list_for_each_entry_continue_rcu(d, &(net)->dev_base_head, dev_list)
3411 #define for_each_netdev_in_bond_rcu(bond, slave)	\
3412 		for_each_netdev_rcu(dev_net_rcu(bond), slave)	\
3413 			if (netdev_master_upper_dev_get_rcu(slave) == (bond))
3414 #define net_device_entry(lh)	list_entry(lh, struct net_device, dev_list)
3415 
3416 #define for_each_netdev_dump(net, d, ifindex)				\
3417 	for (; (d = xa_find(&(net)->dev_by_index, &ifindex,		\
3418 			    ULONG_MAX, XA_PRESENT)); ifindex++)
3419 
3420 static inline struct net_device *next_net_device(struct net_device *dev)
3421 {
3422 	struct list_head *lh;
3423 	struct net *net;
3424 
3425 	net = dev_net(dev);
3426 	lh = dev->dev_list.next;
3427 	return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
3428 }
3429 
3430 static inline struct net_device *next_net_device_rcu(struct net_device *dev)
3431 {
3432 	struct list_head *lh;
3433 	struct net *net;
3434 
3435 	net = dev_net(dev);
3436 	lh = rcu_dereference(list_next_rcu(&dev->dev_list));
3437 	return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
3438 }
3439 
3440 static inline struct net_device *first_net_device(struct net *net)
3441 {
3442 	return list_empty(&net->dev_base_head) ? NULL :
3443 		net_device_entry(net->dev_base_head.next);
3444 }
3445 
3446 struct net_device *dev_getbyhwaddr(struct net *net, unsigned short type,
3447 				   const char *hwaddr);
3448 struct net_device *dev_getbyhwaddr_rcu(struct net *net, unsigned short type,
3449 				       const char *hwaddr);
3450 struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type);
3451 void dev_add_pack(struct packet_type *pt);
3452 void dev_remove_pack(struct packet_type *pt);
3453 void __dev_remove_pack(struct packet_type *pt);
3454 void dev_add_offload(struct packet_offload *po);
3455 void dev_remove_offload(struct packet_offload *po);
3456 
3457 int dev_get_iflink(const struct net_device *dev);
3458 int dev_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb);
3459 int dev_fill_forward_path(struct net_device_path_ctx *ctx,
3460 			  struct net_device_path_stack *stack);
3461 void dev_fill_forward_path_release(struct net_device_path_stack *stack);
3462 struct net_device *dev_get_by_name(struct net *net, const char *name);
3463 struct net_device *dev_get_by_name_rcu(struct net *net, const char *name);
3464 struct net_device *__dev_get_by_name(struct net *net, const char *name);
3465 bool netdev_name_in_use(struct net *net, const char *name);
3466 int dev_alloc_name(struct net_device *dev, const char *name);
3467 int netif_open(struct net_device *dev, struct netlink_ext_ack *extack);
3468 int dev_open(struct net_device *dev, struct netlink_ext_ack *extack);
3469 void netif_close(struct net_device *dev);
3470 void dev_close(struct net_device *dev);
3471 void netif_close_many(struct list_head *head, bool unlink);
3472 void netif_disable_lro(struct net_device *dev);
3473 void dev_disable_lro(struct net_device *dev);
3474 int dev_loopback_xmit(struct net *net, struct sock *sk, struct sk_buff *newskb);
3475 u16 dev_pick_tx_zero(struct net_device *dev, struct sk_buff *skb,
3476 		     struct net_device *sb_dev);
3477 
3478 int __dev_queue_xmit(struct sk_buff *skb, struct net_device *sb_dev);
3479 int __dev_direct_xmit(struct sk_buff *skb, u16 queue_id);
3480 
3481 static inline int dev_queue_xmit(struct sk_buff *skb)
3482 {
3483 	return __dev_queue_xmit(skb, NULL);
3484 }
3485 
3486 static inline int dev_queue_xmit_accel(struct sk_buff *skb,
3487 				       struct net_device *sb_dev)
3488 {
3489 	return __dev_queue_xmit(skb, sb_dev);
3490 }
3491 
3492 static inline int dev_direct_xmit(struct sk_buff *skb, u16 queue_id)
3493 {
3494 	int ret;
3495 
3496 	ret = __dev_direct_xmit(skb, queue_id);
3497 	if (!dev_xmit_complete(ret))
3498 		kfree_skb(skb);
3499 	return ret;
3500 }
3501 
3502 int register_netdevice(struct net_device *dev);
3503 void unregister_netdevice_queue(struct net_device *dev, struct list_head *head);
3504 void unregister_netdevice_many(struct list_head *head);
3505 bool unregister_netdevice_queued(const struct net_device *dev);
3506 
3507 static inline void unregister_netdevice(struct net_device *dev)
3508 {
3509 	unregister_netdevice_queue(dev, NULL);
3510 }
3511 
3512 #ifdef CONFIG_DEBUG_NET_SMALL_RTNL
3513 void unregister_netdevice_queue_net(struct net *net, struct net_device *dev,
3514 				    struct list_head *head);
3515 void unregister_netdevice_many_net(struct net *net);
3516 void unregister_netdevice_queue_many_net(struct net *net, struct list_head *head);
3517 #else
3518 static inline void unregister_netdevice_queue_net(struct net *net,
3519 						  struct net_device *dev,
3520 						  struct list_head *head)
3521 {
3522 	unregister_netdevice_queue(dev, head);
3523 }
3524 
3525 static inline void unregister_netdevice_queue_many_net(struct net *net,
3526 						       struct list_head *head)
3527 {
3528 }
3529 #endif
3530 
3531 int netdev_refcnt_read(const struct net_device *dev);
3532 void free_netdev(struct net_device *dev);
3533 
3534 struct net_device *netdev_get_xmit_slave(struct net_device *dev,
3535 					 struct sk_buff *skb,
3536 					 bool all_slaves);
3537 struct net_device *netdev_sk_get_lowest_dev(struct net_device *dev,
3538 					    struct sock *sk);
3539 struct net_device *dev_get_by_index(struct net *net, int ifindex);
3540 struct net_device *__dev_get_by_index(struct net *net, int ifindex);
3541 struct net_device *netdev_get_by_index(struct net *net, int ifindex,
3542 				       netdevice_tracker *tracker, gfp_t gfp);
3543 struct net_device *netdev_get_by_index_lock(struct net *net, int ifindex);
3544 struct net_device *netdev_get_by_name(struct net *net, const char *name,
3545 				      netdevice_tracker *tracker, gfp_t gfp);
3546 struct net_device *netdev_get_by_flags_rcu(struct net *net, netdevice_tracker *tracker,
3547 					   unsigned short flags, unsigned short mask);
3548 struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
3549 void netdev_copy_name(struct net_device *dev, char *name);
3550 
3551 static inline int dev_hard_header(struct sk_buff *skb, struct net_device *dev,
3552 				  unsigned short type,
3553 				  const void *daddr, const void *saddr,
3554 				  unsigned int len)
3555 {
3556 	if (!dev->header_ops || !dev->header_ops->create)
3557 		return 0;
3558 
3559 	return dev->header_ops->create(skb, dev, type, daddr, saddr, len);
3560 }
3561 
3562 static inline int dev_parse_header(const struct sk_buff *skb,
3563 				   unsigned char *haddr)
3564 {
3565 	const struct net_device *dev = skb->dev;
3566 
3567 	if (!dev->header_ops || !dev->header_ops->parse)
3568 		return 0;
3569 	return dev->header_ops->parse(skb, dev, haddr);
3570 }
3571 
3572 static inline __be16 dev_parse_header_protocol(const struct sk_buff *skb)
3573 {
3574 	const struct net_device *dev = skb->dev;
3575 
3576 	if (!dev->header_ops || !dev->header_ops->parse_protocol)
3577 		return 0;
3578 	return dev->header_ops->parse_protocol(skb);
3579 }
3580 
3581 /* ll_header must have at least hard_header_len allocated */
3582 static inline bool dev_validate_header(const struct net_device *dev,
3583 				       char *ll_header, int len)
3584 {
3585 	if (likely(len >= dev->hard_header_len))
3586 		return true;
3587 	if (len < dev->min_header_len)
3588 		return false;
3589 
3590 	if (dev->header_ops && dev->header_ops->validate)
3591 		return dev->header_ops->validate(ll_header, len);
3592 
3593 	return false;
3594 }
3595 
3596 static inline bool dev_has_header(const struct net_device *dev)
3597 {
3598 	return dev->header_ops && dev->header_ops->create;
3599 }
3600 
3601 struct numa_drop_counters {
3602 	atomic_t	drops0 ____cacheline_aligned_in_smp;
3603 	atomic_t	drops1 ____cacheline_aligned_in_smp;
3604 };
3605 
3606 static inline int numa_drop_read(const struct numa_drop_counters *ndc)
3607 {
3608 	return atomic_read(&ndc->drops0) + atomic_read(&ndc->drops1);
3609 }
3610 
3611 static inline void numa_drop_add(struct numa_drop_counters *ndc, int val)
3612 {
3613 	int n = numa_node_id() % 2;
3614 
3615 	if (n)
3616 		atomic_add(val, &ndc->drops1);
3617 	else
3618 		atomic_add(val, &ndc->drops0);
3619 }
3620 
3621 static inline void numa_drop_reset(struct numa_drop_counters *ndc)
3622 {
3623 	atomic_set(&ndc->drops0, 0);
3624 	atomic_set(&ndc->drops1, 0);
3625 }
3626 
3627 /*
3628  * Incoming packets are placed on per-CPU queues
3629  */
3630 struct softnet_data {
3631 	struct list_head	poll_list;
3632 	struct sk_buff_head	process_queue;
3633 	local_lock_t		process_queue_bh_lock;
3634 
3635 	/* stats */
3636 	unsigned int		processed;
3637 	unsigned int		time_squeeze;
3638 #ifdef CONFIG_RPS
3639 	struct softnet_data	*rps_ipi_list;
3640 #endif
3641 
3642 	unsigned int		received_rps;
3643 	bool			in_net_rx_action;
3644 	bool			in_napi_threaded_poll;
3645 
3646 #ifdef CONFIG_NET_FLOW_LIMIT
3647 	struct sd_flow_limit __rcu *flow_limit;
3648 #endif
3649 	struct Qdisc		*output_queue;
3650 	struct Qdisc		**output_queue_tailp;
3651 	struct sk_buff		*completion_queue;
3652 #ifdef CONFIG_XFRM_OFFLOAD
3653 	struct sk_buff_head	xfrm_backlog;
3654 #endif
3655 	/* written and read only by owning cpu: */
3656 	struct netdev_xmit xmit;
3657 #ifdef CONFIG_RPS
3658 	/* input_queue_head should be written by cpu owning this struct,
3659 	 * and only read by other cpus. Worth using a cache line.
3660 	 */
3661 	unsigned int		input_queue_head ____cacheline_aligned_in_smp;
3662 
3663 	/* Elements below can be accessed between CPUs for RPS/RFS */
3664 	call_single_data_t	csd ____cacheline_aligned_in_smp;
3665 	struct softnet_data	*rps_ipi_next;
3666 	unsigned int		cpu;
3667 
3668 	/* We force a cacheline alignment from here, to hold together
3669 	 * input_queue_tail, input_pkt_queue and backlog.state.
3670 	 * We add holes so that backlog.state is the last field
3671 	 * of this cache line.
3672 	 */
3673 	long			pad[3] ____cacheline_aligned_in_smp;
3674 	unsigned int		input_queue_tail;
3675 #endif
3676 	struct sk_buff_head	input_pkt_queue;
3677 
3678 	struct napi_struct	backlog;
3679 
3680 	struct numa_drop_counters drop_counters;
3681 
3682 	int			defer_ipi_scheduled ____cacheline_aligned_in_smp;
3683 	call_single_data_t	defer_csd;
3684 };
3685 
3686 DECLARE_PER_CPU_ALIGNED(struct softnet_data, softnet_data);
3687 
3688 struct page_pool_bh {
3689 	struct page_pool *pool;
3690 	local_lock_t bh_lock;
3691 };
3692 DECLARE_PER_CPU(struct page_pool_bh, system_page_pool);
3693 
3694 #ifdef CONFIG_KASAN
3695 #define XMIT_RECURSION_LIMIT	4
3696 #else
3697 #define XMIT_RECURSION_LIMIT	8
3698 #endif
3699 
3700 #ifndef CONFIG_PREEMPT_RT
3701 static inline int dev_recursion_level(void)
3702 {
3703 	return this_cpu_read(softnet_data.xmit.recursion);
3704 }
3705 
3706 static inline bool dev_xmit_recursion(void)
3707 {
3708 	return unlikely(__this_cpu_read(softnet_data.xmit.recursion) >
3709 			XMIT_RECURSION_LIMIT);
3710 }
3711 
3712 static inline void dev_xmit_recursion_inc(void)
3713 {
3714 	__this_cpu_inc(softnet_data.xmit.recursion);
3715 }
3716 
3717 static inline void dev_xmit_recursion_dec(void)
3718 {
3719 	__this_cpu_dec(softnet_data.xmit.recursion);
3720 }
3721 #else
3722 static inline int dev_recursion_level(void)
3723 {
3724 	return current->net_xmit.recursion;
3725 }
3726 
3727 static inline bool dev_xmit_recursion(void)
3728 {
3729 	return unlikely(current->net_xmit.recursion > XMIT_RECURSION_LIMIT);
3730 }
3731 
3732 static inline void dev_xmit_recursion_inc(void)
3733 {
3734 	current->net_xmit.recursion++;
3735 }
3736 
3737 static inline void dev_xmit_recursion_dec(void)
3738 {
3739 	current->net_xmit.recursion--;
3740 }
3741 #endif
3742 
3743 void __netif_schedule(struct Qdisc *q);
3744 void netif_schedule_queue(struct netdev_queue *txq);
3745 
3746 static inline void netif_tx_schedule_all(struct net_device *dev)
3747 {
3748 	unsigned int i;
3749 
3750 	for (i = 0; i < dev->num_tx_queues; i++)
3751 		netif_schedule_queue(netdev_get_tx_queue(dev, i));
3752 }
3753 
3754 static __always_inline void netif_tx_start_queue(struct netdev_queue *dev_queue)
3755 {
3756 	clear_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
3757 }
3758 
3759 /**
3760  *	netif_start_queue - allow transmit
3761  *	@dev: network device
3762  *
3763  *	Allow upper layers to call the device hard_start_xmit routine.
3764  */
3765 static inline void netif_start_queue(struct net_device *dev)
3766 {
3767 	netif_tx_start_queue(netdev_get_tx_queue(dev, 0));
3768 }
3769 
3770 static inline void netif_tx_start_all_queues(struct net_device *dev)
3771 {
3772 	unsigned int i;
3773 
3774 	for (i = 0; i < dev->num_tx_queues; i++) {
3775 		struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
3776 		netif_tx_start_queue(txq);
3777 	}
3778 }
3779 
3780 void netif_tx_wake_queue(struct netdev_queue *dev_queue);
3781 
3782 /**
3783  *	netif_wake_queue - restart transmit
3784  *	@dev: network device
3785  *
3786  *	Allow upper layers to call the device hard_start_xmit routine.
3787  *	Used for flow control when transmit resources are available.
3788  */
3789 static inline void netif_wake_queue(struct net_device *dev)
3790 {
3791 	netif_tx_wake_queue(netdev_get_tx_queue(dev, 0));
3792 }
3793 
3794 static inline void netif_tx_wake_all_queues(struct net_device *dev)
3795 {
3796 	unsigned int i;
3797 
3798 	for (i = 0; i < dev->num_tx_queues; i++) {
3799 		struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
3800 		netif_tx_wake_queue(txq);
3801 	}
3802 }
3803 
3804 static __always_inline void netif_tx_stop_queue(struct netdev_queue *dev_queue)
3805 {
3806 	/* Paired with READ_ONCE() from dev_watchdog() */
3807 	WRITE_ONCE(dev_queue->trans_start, jiffies);
3808 
3809 	/* This barrier is paired with smp_mb() from dev_watchdog() */
3810 	smp_mb__before_atomic();
3811 
3812 	/* Must be an atomic op see netif_txq_try_stop() */
3813 	set_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
3814 }
3815 
3816 /**
3817  *	netif_stop_queue - stop transmitted packets
3818  *	@dev: network device
3819  *
3820  *	Stop upper layers calling the device hard_start_xmit routine.
3821  *	Used for flow control when transmit resources are unavailable.
3822  */
3823 static inline void netif_stop_queue(struct net_device *dev)
3824 {
3825 	netif_tx_stop_queue(netdev_get_tx_queue(dev, 0));
3826 }
3827 
3828 void netif_tx_stop_all_queues(struct net_device *dev);
3829 
3830 static inline bool netif_tx_queue_stopped(const struct netdev_queue *dev_queue)
3831 {
3832 	return test_bit(__QUEUE_STATE_DRV_XOFF, &dev_queue->state);
3833 }
3834 
3835 /**
3836  *	netif_queue_stopped - test if transmit queue is flowblocked
3837  *	@dev: network device
3838  *
3839  *	Test if transmit queue on device is currently unable to send.
3840  */
3841 static inline bool netif_queue_stopped(const struct net_device *dev)
3842 {
3843 	return netif_tx_queue_stopped(netdev_get_tx_queue(dev, 0));
3844 }
3845 
3846 static inline bool netif_xmit_stopped(const struct netdev_queue *dev_queue)
3847 {
3848 	return dev_queue->state & QUEUE_STATE_ANY_XOFF;
3849 }
3850 
3851 static inline bool
3852 netif_xmit_frozen_or_stopped(const struct netdev_queue *dev_queue)
3853 {
3854 	return dev_queue->state & QUEUE_STATE_ANY_XOFF_OR_FROZEN;
3855 }
3856 
3857 static inline bool
3858 netif_xmit_frozen_or_drv_stopped(const struct netdev_queue *dev_queue)
3859 {
3860 	return dev_queue->state & QUEUE_STATE_DRV_XOFF_OR_FROZEN;
3861 }
3862 
3863 /**
3864  *	netdev_queue_set_dql_min_limit - set dql minimum limit
3865  *	@dev_queue: pointer to transmit queue
3866  *	@min_limit: dql minimum limit
3867  *
3868  * Forces xmit_more() to return true until the minimum threshold
3869  * defined by @min_limit is reached (or until the tx queue is
3870  * empty). Warning: to be use with care, misuse will impact the
3871  * latency.
3872  */
3873 static inline void netdev_queue_set_dql_min_limit(struct netdev_queue *dev_queue,
3874 						  unsigned int min_limit)
3875 {
3876 #ifdef CONFIG_BQL
3877 	dev_queue->dql.min_limit = min_limit;
3878 #endif
3879 }
3880 
3881 static inline int netdev_queue_dql_avail(const struct netdev_queue *txq)
3882 {
3883 #ifdef CONFIG_BQL
3884 	/* Non-BQL migrated drivers will return 0, too. */
3885 	return dql_avail(&txq->dql);
3886 #else
3887 	return 0;
3888 #endif
3889 }
3890 
3891 /**
3892  *	netdev_txq_bql_enqueue_prefetchw - prefetch bql data for write
3893  *	@dev_queue: pointer to transmit queue
3894  *
3895  * BQL enabled drivers might use this helper in their ndo_start_xmit(),
3896  * to give appropriate hint to the CPU.
3897  */
3898 static inline void netdev_txq_bql_enqueue_prefetchw(struct netdev_queue *dev_queue)
3899 {
3900 #ifdef CONFIG_BQL
3901 	prefetchw(&dev_queue->dql.num_queued);
3902 #endif
3903 }
3904 
3905 /**
3906  *	netdev_txq_bql_complete_prefetchw - prefetch bql data for write
3907  *	@dev_queue: pointer to transmit queue
3908  *
3909  * BQL enabled drivers might use this helper in their TX completion path,
3910  * to give appropriate hint to the CPU.
3911  */
3912 static inline void netdev_txq_bql_complete_prefetchw(struct netdev_queue *dev_queue)
3913 {
3914 #ifdef CONFIG_BQL
3915 	prefetchw(&dev_queue->dql.limit);
3916 #endif
3917 }
3918 
3919 /**
3920  *	netdev_tx_sent_queue - report the number of bytes queued to a given tx queue
3921  *	@dev_queue: network device queue
3922  *	@bytes: number of bytes queued to the device queue
3923  *
3924  *	Report the number of bytes queued for sending/completion to the network
3925  *	device hardware queue. @bytes should be a good approximation and should
3926  *	exactly match netdev_completed_queue() @bytes.
3927  *	This is typically called once per packet, from ndo_start_xmit().
3928  */
3929 static inline void netdev_tx_sent_queue(struct netdev_queue *dev_queue,
3930 					unsigned int bytes)
3931 {
3932 #ifdef CONFIG_BQL
3933 	dql_queued(&dev_queue->dql, bytes);
3934 
3935 	if (likely(dql_avail(&dev_queue->dql) >= 0))
3936 		return;
3937 
3938 	/* Paired with READ_ONCE() from dev_watchdog() */
3939 	WRITE_ONCE(dev_queue->trans_start, jiffies);
3940 
3941 	/* This barrier is paired with smp_mb() from dev_watchdog() */
3942 	smp_mb__before_atomic();
3943 
3944 	set_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state);
3945 
3946 	/*
3947 	 * The XOFF flag must be set before checking the dql_avail below,
3948 	 * because in netdev_tx_completed_queue we update the dql_completed
3949 	 * before checking the XOFF flag.
3950 	 */
3951 	smp_mb__after_atomic();
3952 
3953 	/* check again in case another CPU has just made room avail */
3954 	if (unlikely(dql_avail(&dev_queue->dql) >= 0))
3955 		clear_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state);
3956 #endif
3957 }
3958 
3959 /* Variant of netdev_tx_sent_queue() for drivers that are aware
3960  * that they should not test BQL status themselves.
3961  * We do want to change __QUEUE_STATE_STACK_XOFF only for the last
3962  * skb of a batch.
3963  * Returns true if the doorbell must be used to kick the NIC.
3964  */
3965 static inline bool __netdev_tx_sent_queue(struct netdev_queue *dev_queue,
3966 					  unsigned int bytes,
3967 					  bool xmit_more)
3968 {
3969 	if (xmit_more) {
3970 #ifdef CONFIG_BQL
3971 		dql_queued(&dev_queue->dql, bytes);
3972 #endif
3973 		return netif_tx_queue_stopped(dev_queue);
3974 	}
3975 	netdev_tx_sent_queue(dev_queue, bytes);
3976 	return true;
3977 }
3978 
3979 /**
3980  *	netdev_sent_queue - report the number of bytes queued to hardware
3981  *	@dev: network device
3982  *	@bytes: number of bytes queued to the hardware device queue
3983  *
3984  *	Report the number of bytes queued for sending/completion to the network
3985  *	device hardware queue#0. @bytes should be a good approximation and should
3986  *	exactly match netdev_completed_queue() @bytes.
3987  *	This is typically called once per packet, from ndo_start_xmit().
3988  */
3989 static inline void netdev_sent_queue(struct net_device *dev, unsigned int bytes)
3990 {
3991 	netdev_tx_sent_queue(netdev_get_tx_queue(dev, 0), bytes);
3992 }
3993 
3994 static inline bool __netdev_sent_queue(struct net_device *dev,
3995 				       unsigned int bytes,
3996 				       bool xmit_more)
3997 {
3998 	return __netdev_tx_sent_queue(netdev_get_tx_queue(dev, 0), bytes,
3999 				      xmit_more);
4000 }
4001 
4002 /**
4003  *	netdev_tx_completed_queue - report number of packets/bytes at TX completion.
4004  *	@dev_queue: network device queue
4005  *	@pkts: number of packets (currently ignored)
4006  *	@bytes: number of bytes dequeued from the device queue
4007  *
4008  *	Must be called at most once per TX completion round (and not per
4009  *	individual packet), so that BQL can adjust its limits appropriately.
4010  */
4011 static inline void netdev_tx_completed_queue(struct netdev_queue *dev_queue,
4012 					     unsigned int pkts, unsigned int bytes)
4013 {
4014 #ifdef CONFIG_BQL
4015 	if (unlikely(!bytes))
4016 		return;
4017 
4018 	dql_completed(&dev_queue->dql, bytes);
4019 
4020 	/*
4021 	 * Without the memory barrier there is a small possibility that
4022 	 * netdev_tx_sent_queue will miss the update and cause the queue to
4023 	 * be stopped forever
4024 	 */
4025 	smp_mb(); /* NOTE: netdev_txq_completed_mb() assumes this exists */
4026 
4027 	if (unlikely(dql_avail(&dev_queue->dql) < 0))
4028 		return;
4029 
4030 	if (test_and_clear_bit(__QUEUE_STATE_STACK_XOFF, &dev_queue->state))
4031 		netif_schedule_queue(dev_queue);
4032 #endif
4033 }
4034 
4035 /**
4036  * 	netdev_completed_queue - report bytes and packets completed by device
4037  * 	@dev: network device
4038  * 	@pkts: actual number of packets sent over the medium
4039  * 	@bytes: actual number of bytes sent over the medium
4040  *
4041  * 	Report the number of bytes and packets transmitted by the network device
4042  * 	hardware queue over the physical medium, @bytes must exactly match the
4043  * 	@bytes amount passed to netdev_sent_queue()
4044  */
4045 static inline void netdev_completed_queue(struct net_device *dev,
4046 					  unsigned int pkts, unsigned int bytes)
4047 {
4048 	netdev_tx_completed_queue(netdev_get_tx_queue(dev, 0), pkts, bytes);
4049 }
4050 
4051 static inline void netdev_tx_reset_queue(struct netdev_queue *q)
4052 {
4053 #ifdef CONFIG_BQL
4054 	clear_bit(__QUEUE_STATE_STACK_XOFF, &q->state);
4055 	dql_reset(&q->dql);
4056 #endif
4057 }
4058 
4059 /**
4060  * netdev_tx_reset_subqueue - reset the BQL stats and state of a netdev queue
4061  * @dev: network device
4062  * @qid: stack index of the queue to reset
4063  */
4064 static inline void netdev_tx_reset_subqueue(const struct net_device *dev,
4065 					    u32 qid)
4066 {
4067 	netdev_tx_reset_queue(netdev_get_tx_queue(dev, qid));
4068 }
4069 
4070 /**
4071  * 	netdev_reset_queue - reset the packets and bytes count of a network device
4072  * 	@dev_queue: network device
4073  *
4074  * 	Reset the bytes and packet count of a network device and clear the
4075  * 	software flow control OFF bit for this network device
4076  */
4077 static inline void netdev_reset_queue(struct net_device *dev_queue)
4078 {
4079 	netdev_tx_reset_subqueue(dev_queue, 0);
4080 }
4081 
4082 /**
4083  * 	netdev_cap_txqueue - check if selected tx queue exceeds device queues
4084  * 	@dev: network device
4085  * 	@queue_index: given tx queue index
4086  *
4087  * 	Returns 0 if given tx queue index >= number of device tx queues,
4088  * 	otherwise returns the originally passed tx queue index.
4089  */
4090 static inline u16 netdev_cap_txqueue(struct net_device *dev, u16 queue_index)
4091 {
4092 	if (unlikely(queue_index >= dev->real_num_tx_queues)) {
4093 		net_warn_ratelimited("%s selects TX queue %d, but real number of TX queues is %d\n",
4094 				     dev->name, queue_index,
4095 				     dev->real_num_tx_queues);
4096 		return 0;
4097 	}
4098 
4099 	return queue_index;
4100 }
4101 
4102 /**
4103  *	netif_running - test if up
4104  *	@dev: network device
4105  *
4106  *	Test if the device has been brought up.
4107  */
4108 static inline bool netif_running(const struct net_device *dev)
4109 {
4110 	return test_bit(__LINK_STATE_START, &dev->state);
4111 }
4112 
4113 /*
4114  * Routines to manage the subqueues on a device.  We only need start,
4115  * stop, and a check if it's stopped.  All other device management is
4116  * done at the overall netdevice level.
4117  * Also test the device if we're multiqueue.
4118  */
4119 
4120 /**
4121  *	netif_start_subqueue - allow sending packets on subqueue
4122  *	@dev: network device
4123  *	@queue_index: sub queue index
4124  *
4125  * Start individual transmit queue of a device with multiple transmit queues.
4126  */
4127 static inline void netif_start_subqueue(struct net_device *dev, u16 queue_index)
4128 {
4129 	struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
4130 
4131 	netif_tx_start_queue(txq);
4132 }
4133 
4134 /**
4135  *	netif_stop_subqueue - stop sending packets on subqueue
4136  *	@dev: network device
4137  *	@queue_index: sub queue index
4138  *
4139  * Stop individual transmit queue of a device with multiple transmit queues.
4140  */
4141 static inline void netif_stop_subqueue(struct net_device *dev, u16 queue_index)
4142 {
4143 	struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
4144 	netif_tx_stop_queue(txq);
4145 }
4146 
4147 /**
4148  *	__netif_subqueue_stopped - test status of subqueue
4149  *	@dev: network device
4150  *	@queue_index: sub queue index
4151  *
4152  * Check individual transmit queue of a device with multiple transmit queues.
4153  */
4154 static inline bool __netif_subqueue_stopped(const struct net_device *dev,
4155 					    u16 queue_index)
4156 {
4157 	struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
4158 
4159 	return netif_tx_queue_stopped(txq);
4160 }
4161 
4162 /**
4163  *	netif_subqueue_stopped - test status of subqueue
4164  *	@dev: network device
4165  *	@skb: sub queue buffer pointer
4166  *
4167  * Check individual transmit queue of a device with multiple transmit queues.
4168  */
4169 static inline bool netif_subqueue_stopped(const struct net_device *dev,
4170 					  struct sk_buff *skb)
4171 {
4172 	return __netif_subqueue_stopped(dev, skb_get_queue_mapping(skb));
4173 }
4174 
4175 /**
4176  *	netif_wake_subqueue - allow sending packets on subqueue
4177  *	@dev: network device
4178  *	@queue_index: sub queue index
4179  *
4180  * Resume individual transmit queue of a device with multiple transmit queues.
4181  */
4182 static inline void netif_wake_subqueue(struct net_device *dev, u16 queue_index)
4183 {
4184 	struct netdev_queue *txq = netdev_get_tx_queue(dev, queue_index);
4185 
4186 	netif_tx_wake_queue(txq);
4187 }
4188 
4189 #ifdef CONFIG_XPS
4190 int netif_set_xps_queue(struct net_device *dev, const struct cpumask *mask,
4191 			u16 index);
4192 int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask,
4193 			  u16 index, enum xps_map_type type);
4194 
4195 /**
4196  *	netif_attr_test_mask - Test a CPU or Rx queue set in a mask
4197  *	@j: CPU/Rx queue index
4198  *	@mask: bitmask of all cpus/rx queues
4199  *	@nr_bits: number of bits in the bitmask
4200  *
4201  * Test if a CPU or Rx queue index is set in a mask of all CPU/Rx queues.
4202  */
4203 static inline bool netif_attr_test_mask(unsigned long j,
4204 					const unsigned long *mask,
4205 					unsigned int nr_bits)
4206 {
4207 	cpu_max_bits_warn(j, nr_bits);
4208 	return test_bit(j, mask);
4209 }
4210 
4211 /**
4212  *	netif_attr_test_online - Test for online CPU/Rx queue
4213  *	@j: CPU/Rx queue index
4214  *	@online_mask: bitmask for CPUs/Rx queues that are online
4215  *	@nr_bits: number of bits in the bitmask
4216  *
4217  * Returns: true if a CPU/Rx queue is online.
4218  */
4219 static inline bool netif_attr_test_online(unsigned long j,
4220 					  const unsigned long *online_mask,
4221 					  unsigned int nr_bits)
4222 {
4223 	cpu_max_bits_warn(j, nr_bits);
4224 
4225 	if (online_mask)
4226 		return test_bit(j, online_mask);
4227 
4228 	return (j < nr_bits);
4229 }
4230 
4231 /**
4232  *	netif_attrmask_next - get the next CPU/Rx queue in a cpu/Rx queues mask
4233  *	@n: CPU/Rx queue index
4234  *	@srcp: the cpumask/Rx queue mask pointer
4235  *	@nr_bits: number of bits in the bitmask
4236  *
4237  * Returns: next (after n) CPU/Rx queue index in the mask;
4238  * >= nr_bits if no further CPUs/Rx queues set.
4239  */
4240 static inline unsigned int netif_attrmask_next(int n, const unsigned long *srcp,
4241 					       unsigned int nr_bits)
4242 {
4243 	/* -1 is a legal arg here. */
4244 	if (n != -1)
4245 		cpu_max_bits_warn(n, nr_bits);
4246 
4247 	if (srcp)
4248 		return find_next_bit(srcp, nr_bits, n + 1);
4249 
4250 	return n + 1;
4251 }
4252 
4253 /**
4254  *	netif_attrmask_next_and - get the next CPU/Rx queue in \*src1p & \*src2p
4255  *	@n: CPU/Rx queue index
4256  *	@src1p: the first CPUs/Rx queues mask pointer
4257  *	@src2p: the second CPUs/Rx queues mask pointer
4258  *	@nr_bits: number of bits in the bitmask
4259  *
4260  * Returns: next (after n) CPU/Rx queue index set in both masks;
4261  * >= nr_bits if no further CPUs/Rx queues set in both.
4262  */
4263 static inline int netif_attrmask_next_and(int n, const unsigned long *src1p,
4264 					  const unsigned long *src2p,
4265 					  unsigned int nr_bits)
4266 {
4267 	/* -1 is a legal arg here. */
4268 	if (n != -1)
4269 		cpu_max_bits_warn(n, nr_bits);
4270 
4271 	if (src1p && src2p)
4272 		return find_next_and_bit(src1p, src2p, nr_bits, n + 1);
4273 	else if (src1p)
4274 		return find_next_bit(src1p, nr_bits, n + 1);
4275 	else if (src2p)
4276 		return find_next_bit(src2p, nr_bits, n + 1);
4277 
4278 	return n + 1;
4279 }
4280 #else
4281 static inline int netif_set_xps_queue(struct net_device *dev,
4282 				      const struct cpumask *mask,
4283 				      u16 index)
4284 {
4285 	return 0;
4286 }
4287 
4288 static inline int __netif_set_xps_queue(struct net_device *dev,
4289 					const unsigned long *mask,
4290 					u16 index, enum xps_map_type type)
4291 {
4292 	return 0;
4293 }
4294 #endif
4295 
4296 /**
4297  *	netif_is_multiqueue - test if device has multiple transmit queues
4298  *	@dev: network device
4299  *
4300  * Check if device has multiple transmit queues
4301  */
4302 static inline bool netif_is_multiqueue(const struct net_device *dev)
4303 {
4304 	return dev->num_tx_queues > 1;
4305 }
4306 
4307 int netif_set_real_num_tx_queues(struct net_device *dev, unsigned int txq);
4308 int netif_set_real_num_rx_queues(struct net_device *dev, unsigned int rxq);
4309 int netif_set_real_num_queues(struct net_device *dev,
4310 			      unsigned int txq, unsigned int rxq);
4311 
4312 int netif_get_num_default_rss_queues(void);
4313 
4314 void dev_kfree_skb_irq_reason(struct sk_buff *skb, enum skb_drop_reason reason);
4315 void dev_kfree_skb_any_reason(struct sk_buff *skb, enum skb_drop_reason reason);
4316 
4317 /*
4318  * It is not allowed to call kfree_skb() or consume_skb() from hardware
4319  * interrupt context or with hardware interrupts being disabled.
4320  * (in_hardirq() || irqs_disabled())
4321  *
4322  * We provide four helpers that can be used in following contexts :
4323  *
4324  * dev_kfree_skb_irq(skb) when caller drops a packet from irq context,
4325  *  replacing kfree_skb(skb)
4326  *
4327  * dev_consume_skb_irq(skb) when caller consumes a packet from irq context.
4328  *  Typically used in place of consume_skb(skb) in TX completion path
4329  *
4330  * dev_kfree_skb_any(skb) when caller doesn't know its current irq context,
4331  *  replacing kfree_skb(skb)
4332  *
4333  * dev_consume_skb_any(skb) when caller doesn't know its current irq context,
4334  *  and consumed a packet. Used in place of consume_skb(skb)
4335  */
4336 static inline void dev_kfree_skb_irq(struct sk_buff *skb)
4337 {
4338 	dev_kfree_skb_irq_reason(skb, SKB_DROP_REASON_NOT_SPECIFIED);
4339 }
4340 
4341 static inline void dev_consume_skb_irq(struct sk_buff *skb)
4342 {
4343 	dev_kfree_skb_irq_reason(skb, SKB_CONSUMED);
4344 }
4345 
4346 static inline void dev_kfree_skb_any(struct sk_buff *skb)
4347 {
4348 	dev_kfree_skb_any_reason(skb, SKB_DROP_REASON_NOT_SPECIFIED);
4349 }
4350 
4351 static inline void dev_consume_skb_any(struct sk_buff *skb)
4352 {
4353 	dev_kfree_skb_any_reason(skb, SKB_CONSUMED);
4354 }
4355 
4356 u32 bpf_prog_run_generic_xdp(struct sk_buff *skb, struct xdp_buff *xdp,
4357 			     const struct bpf_prog *xdp_prog);
4358 void generic_xdp_tx(struct sk_buff *skb, const struct bpf_prog *xdp_prog);
4359 int do_xdp_generic(const struct bpf_prog *xdp_prog, struct sk_buff **pskb);
4360 int netif_rx(struct sk_buff *skb);
4361 int __netif_rx(struct sk_buff *skb);
4362 
4363 int netif_receive_skb(struct sk_buff *skb);
4364 int netif_receive_skb_core(struct sk_buff *skb);
4365 void netif_receive_skb_list_internal(struct list_head *head);
4366 void netif_receive_skb_list(struct list_head *head);
4367 gro_result_t gro_receive_skb(struct gro_node *gro, struct sk_buff *skb);
4368 
4369 static inline gro_result_t napi_gro_receive(struct napi_struct *napi,
4370 					    struct sk_buff *skb)
4371 {
4372 	return gro_receive_skb(&napi->gro, skb);
4373 }
4374 
4375 struct sk_buff *napi_get_frags(struct napi_struct *napi);
4376 gro_result_t napi_gro_frags(struct napi_struct *napi);
4377 
4378 static inline void napi_free_frags(struct napi_struct *napi)
4379 {
4380 	kfree_skb(napi->skb);
4381 	napi->skb = NULL;
4382 }
4383 
4384 bool netdev_is_rx_handler_busy(struct net_device *dev);
4385 int netdev_rx_handler_register(struct net_device *dev,
4386 			       rx_handler_func_t *rx_handler,
4387 			       void *rx_handler_data);
4388 void netdev_rx_handler_unregister(struct net_device *dev);
4389 
4390 bool dev_valid_name(const char *name);
4391 static inline bool is_socket_ioctl_cmd(unsigned int cmd)
4392 {
4393 	return _IOC_TYPE(cmd) == SOCK_IOC_TYPE;
4394 }
4395 int get_user_ifreq(struct ifreq *ifr, void __user **ifrdata, void __user *arg);
4396 int put_user_ifreq(struct ifreq *ifr, void __user *arg);
4397 int dev_ioctl(struct net *net, unsigned int cmd, struct ifreq *ifr,
4398 		void __user *data, bool *need_copyout);
4399 int dev_ifconf(struct net *net, struct ifconf __user *ifc);
4400 int dev_eth_ioctl(struct net_device *dev,
4401 		  struct ifreq *ifr, unsigned int cmd);
4402 int generic_hwtstamp_get_lower(struct net_device *dev,
4403 			       struct kernel_hwtstamp_config *kernel_cfg);
4404 int generic_hwtstamp_set_lower(struct net_device *dev,
4405 			       struct kernel_hwtstamp_config *kernel_cfg,
4406 			       struct netlink_ext_ack *extack);
4407 int dev_ethtool(struct net *net, struct ifreq *ifr, void __user *userdata);
4408 unsigned int netif_get_flags(const struct net_device *dev);
4409 int __dev_change_flags(struct net_device *dev, unsigned int flags,
4410 		       struct netlink_ext_ack *extack);
4411 int netif_change_flags(struct net_device *dev, unsigned int flags,
4412 		       struct netlink_ext_ack *extack);
4413 int dev_change_flags(struct net_device *dev, unsigned int flags,
4414 		     struct netlink_ext_ack *extack);
4415 int netif_set_alias(struct net_device *dev, const char *alias, size_t len);
4416 int dev_set_alias(struct net_device *, const char *, size_t);
4417 int dev_get_alias(const struct net_device *, char *, size_t);
4418 int __dev_change_net_namespace(struct net_device *dev, struct net *net,
4419 			       const char *pat, int new_ifindex,
4420 			       struct netlink_ext_ack *extack);
4421 int dev_change_net_namespace(struct net_device *dev, struct net *net,
4422 			     const char *pat);
4423 int __netif_set_mtu(struct net_device *dev, int new_mtu);
4424 int netif_set_mtu(struct net_device *dev, int new_mtu);
4425 int dev_set_mtu(struct net_device *, int);
4426 int netif_pre_changeaddr_notify(struct net_device *dev, const char *addr,
4427 				struct netlink_ext_ack *extack);
4428 int netif_set_mac_address(struct net_device *dev, struct sockaddr_storage *ss,
4429 			  struct netlink_ext_ack *extack);
4430 int dev_set_mac_address(struct net_device *dev, struct sockaddr_storage *ss,
4431 			struct netlink_ext_ack *extack);
4432 int dev_set_mac_address_user(struct net_device *dev, struct sockaddr_storage *ss,
4433 			     struct netlink_ext_ack *extack);
4434 int netif_get_mac_address(struct sockaddr *sa, struct net *net, char *dev_name);
4435 int netif_get_port_parent_id(struct net_device *dev,
4436 			     struct netdev_phys_item_id *ppid, bool recurse);
4437 bool netdev_port_same_parent_id(struct net_device *a, struct net_device *b);
4438 
4439 struct sk_buff *validate_xmit_skb_list(struct sk_buff *skb, struct net_device *dev, bool *again);
4440 struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
4441 				    struct netdev_queue *txq, int *ret);
4442 
4443 int bpf_xdp_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
4444 u8 dev_xdp_prog_count(struct net_device *dev);
4445 int netif_xdp_propagate(struct net_device *dev, struct netdev_bpf *bpf);
4446 int dev_xdp_propagate(struct net_device *dev, struct netdev_bpf *bpf);
4447 u8 dev_xdp_sb_prog_count(struct net_device *dev);
4448 u32 dev_xdp_prog_id(struct net_device *dev, enum bpf_xdp_mode mode);
4449 
4450 u32 dev_get_min_mp_channel_count(const struct net_device *dev);
4451 
4452 int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
4453 int dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
4454 int dev_forward_skb_nomtu(struct net_device *dev, struct sk_buff *skb);
4455 bool is_skb_forwardable(const struct net_device *dev,
4456 			const struct sk_buff *skb);
4457 
4458 static __always_inline bool __is_skb_forwardable(const struct net_device *dev,
4459 						 const struct sk_buff *skb,
4460 						 const bool check_mtu)
4461 {
4462 	const u32 vlan_hdr_len = 4; /* VLAN_HLEN */
4463 	unsigned int len;
4464 
4465 	if (!(dev->flags & IFF_UP))
4466 		return false;
4467 
4468 	if (!check_mtu)
4469 		return true;
4470 
4471 	len = dev->mtu + dev->hard_header_len + vlan_hdr_len;
4472 	if (skb->len <= len)
4473 		return true;
4474 
4475 	/* if TSO is enabled, we don't care about the length as the packet
4476 	 * could be forwarded without being segmented before
4477 	 */
4478 	if (skb_is_gso(skb))
4479 		return true;
4480 
4481 	return false;
4482 }
4483 
4484 void netdev_core_stats_inc(struct net_device *dev, u32 offset);
4485 
4486 #define DEV_CORE_STATS_INC(FIELD)						\
4487 static inline void dev_core_stats_##FIELD##_inc(struct net_device *dev)		\
4488 {										\
4489 	netdev_core_stats_inc(dev,						\
4490 			offsetof(struct net_device_core_stats, FIELD));		\
4491 }
4492 DEV_CORE_STATS_INC(rx_dropped)
4493 DEV_CORE_STATS_INC(tx_dropped)
4494 DEV_CORE_STATS_INC(rx_nohandler)
4495 DEV_CORE_STATS_INC(rx_otherhost_dropped)
4496 #undef DEV_CORE_STATS_INC
4497 
4498 static __always_inline int ____dev_forward_skb(struct net_device *dev,
4499 					       struct sk_buff *skb,
4500 					       const bool check_mtu)
4501 {
4502 	if (skb_orphan_frags(skb, GFP_ATOMIC) ||
4503 	    unlikely(!__is_skb_forwardable(dev, skb, check_mtu))) {
4504 		dev_core_stats_rx_dropped_inc(dev);
4505 		kfree_skb(skb);
4506 		return NET_RX_DROP;
4507 	}
4508 
4509 	skb_scrub_packet(skb, !net_eq(dev_net(dev), dev_net(skb->dev)));
4510 	skb->priority = 0;
4511 	return 0;
4512 }
4513 
4514 bool dev_nit_active_rcu(const struct net_device *dev);
4515 static inline bool dev_nit_active(const struct net_device *dev)
4516 {
4517 	bool ret;
4518 
4519 	rcu_read_lock();
4520 	ret = dev_nit_active_rcu(dev);
4521 	rcu_read_unlock();
4522 	return ret;
4523 }
4524 
4525 void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev);
4526 
4527 static inline void __dev_put(struct net_device *dev)
4528 {
4529 	if (dev) {
4530 #ifdef CONFIG_PCPU_DEV_REFCNT
4531 		this_cpu_dec(*dev->pcpu_refcnt);
4532 #else
4533 		refcount_dec(&dev->dev_refcnt);
4534 #endif
4535 	}
4536 }
4537 
4538 static inline void __dev_hold(struct net_device *dev)
4539 {
4540 	if (dev) {
4541 #ifdef CONFIG_PCPU_DEV_REFCNT
4542 		this_cpu_inc(*dev->pcpu_refcnt);
4543 #else
4544 		refcount_inc(&dev->dev_refcnt);
4545 #endif
4546 	}
4547 }
4548 
4549 static inline void __netdev_tracker_alloc(struct net_device *dev,
4550 					  netdevice_tracker *tracker,
4551 					  gfp_t gfp)
4552 {
4553 #ifdef CONFIG_NET_DEV_REFCNT_TRACKER
4554 	ref_tracker_alloc(&dev->refcnt_tracker, tracker, gfp);
4555 #endif
4556 }
4557 
4558 /* netdev_tracker_alloc() can upgrade a prior untracked reference
4559  * taken by dev_get_by_name()/dev_get_by_index() to a tracked one.
4560  */
4561 static inline void netdev_tracker_alloc(struct net_device *dev,
4562 					netdevice_tracker *tracker, gfp_t gfp)
4563 {
4564 #ifdef CONFIG_NET_DEV_REFCNT_TRACKER
4565 	refcount_dec(&dev->refcnt_tracker.no_tracker);
4566 	__netdev_tracker_alloc(dev, tracker, gfp);
4567 #endif
4568 }
4569 
4570 static inline void netdev_tracker_free(struct net_device *dev,
4571 				       netdevice_tracker *tracker)
4572 {
4573 #ifdef CONFIG_NET_DEV_REFCNT_TRACKER
4574 	ref_tracker_free(&dev->refcnt_tracker, tracker);
4575 #endif
4576 }
4577 
4578 static inline void netdev_hold(struct net_device *dev,
4579 			       netdevice_tracker *tracker, gfp_t gfp)
4580 {
4581 	if (dev) {
4582 		__dev_hold(dev);
4583 		__netdev_tracker_alloc(dev, tracker, gfp);
4584 	}
4585 }
4586 
4587 static inline void netdev_put(struct net_device *dev,
4588 			      netdevice_tracker *tracker)
4589 {
4590 	if (dev) {
4591 		netdev_tracker_free(dev, tracker);
4592 		__dev_put(dev);
4593 	}
4594 }
4595 
4596 /**
4597  *	dev_hold - get reference to device
4598  *	@dev: network device
4599  *
4600  * Hold reference to device to keep it from being freed.
4601  * Try using netdev_hold() instead.
4602  */
4603 static inline void dev_hold(struct net_device *dev)
4604 {
4605 	netdev_hold(dev, NULL, GFP_ATOMIC);
4606 }
4607 
4608 /**
4609  *	dev_put - release reference to device
4610  *	@dev: network device
4611  *
4612  * Release reference to device to allow it to be freed.
4613  * Try using netdev_put() instead.
4614  */
4615 static inline void dev_put(struct net_device *dev)
4616 {
4617 	netdev_put(dev, NULL);
4618 }
4619 
4620 DEFINE_FREE(dev_put, struct net_device *, if (_T) dev_put(_T))
4621 
4622 static inline void netdev_ref_replace(struct net_device *odev,
4623 				      struct net_device *ndev,
4624 				      netdevice_tracker *tracker,
4625 				      gfp_t gfp)
4626 {
4627 	if (odev)
4628 		netdev_tracker_free(odev, tracker);
4629 
4630 	__dev_hold(ndev);
4631 	__dev_put(odev);
4632 
4633 	if (ndev)
4634 		__netdev_tracker_alloc(ndev, tracker, gfp);
4635 }
4636 
4637 /* Carrier loss detection, dial on demand. The functions netif_carrier_on
4638  * and _off may be called from IRQ context, but it is caller
4639  * who is responsible for serialization of these calls.
4640  *
4641  * The name carrier is inappropriate, these functions should really be
4642  * called netif_lowerlayer_*() because they represent the state of any
4643  * kind of lower layer not just hardware media.
4644  */
4645 void linkwatch_fire_event(struct net_device *dev);
4646 
4647 /**
4648  * linkwatch_sync_dev - sync linkwatch for the given device
4649  * @dev: network device to sync linkwatch for
4650  *
4651  * Sync linkwatch for the given device, removing it from the
4652  * pending work list (if queued).
4653  */
4654 void linkwatch_sync_dev(struct net_device *dev);
4655 void __linkwatch_sync_dev(struct net_device *dev);
4656 
4657 /**
4658  *	netif_carrier_ok - test if carrier present
4659  *	@dev: network device
4660  *
4661  * Check if carrier is present on device
4662  */
4663 static inline bool netif_carrier_ok(const struct net_device *dev)
4664 {
4665 	return !test_bit(__LINK_STATE_NOCARRIER, &dev->state);
4666 }
4667 
4668 unsigned long dev_trans_start(struct net_device *dev);
4669 
4670 void netdev_watchdog_up(struct net_device *dev);
4671 
4672 void netif_carrier_on(struct net_device *dev);
4673 void netif_carrier_off(struct net_device *dev);
4674 void netif_carrier_event(struct net_device *dev);
4675 
4676 /**
4677  *	netif_dormant_on - mark device as dormant.
4678  *	@dev: network device
4679  *
4680  * Mark device as dormant (as per RFC2863).
4681  *
4682  * The dormant state indicates that the relevant interface is not
4683  * actually in a condition to pass packets (i.e., it is not 'up') but is
4684  * in a "pending" state, waiting for some external event.  For "on-
4685  * demand" interfaces, this new state identifies the situation where the
4686  * interface is waiting for events to place it in the up state.
4687  */
4688 static inline void netif_dormant_on(struct net_device *dev)
4689 {
4690 	if (!test_and_set_bit(__LINK_STATE_DORMANT, &dev->state))
4691 		linkwatch_fire_event(dev);
4692 }
4693 
4694 /**
4695  *	netif_dormant_off - set device as not dormant.
4696  *	@dev: network device
4697  *
4698  * Device is not in dormant state.
4699  */
4700 static inline void netif_dormant_off(struct net_device *dev)
4701 {
4702 	if (test_and_clear_bit(__LINK_STATE_DORMANT, &dev->state))
4703 		linkwatch_fire_event(dev);
4704 }
4705 
4706 /**
4707  *	netif_dormant - test if device is dormant
4708  *	@dev: network device
4709  *
4710  * Check if device is dormant.
4711  */
4712 static inline bool netif_dormant(const struct net_device *dev)
4713 {
4714 	return test_bit(__LINK_STATE_DORMANT, &dev->state);
4715 }
4716 
4717 
4718 /**
4719  *	netif_testing_on - mark device as under test.
4720  *	@dev: network device
4721  *
4722  * Mark device as under test (as per RFC2863).
4723  *
4724  * The testing state indicates that some test(s) must be performed on
4725  * the interface. After completion, of the test, the interface state
4726  * will change to up, dormant, or down, as appropriate.
4727  */
4728 static inline void netif_testing_on(struct net_device *dev)
4729 {
4730 	if (!test_and_set_bit(__LINK_STATE_TESTING, &dev->state))
4731 		linkwatch_fire_event(dev);
4732 }
4733 
4734 /**
4735  *	netif_testing_off - set device as not under test.
4736  *	@dev: network device
4737  *
4738  * Device is not in testing state.
4739  */
4740 static inline void netif_testing_off(struct net_device *dev)
4741 {
4742 	if (test_and_clear_bit(__LINK_STATE_TESTING, &dev->state))
4743 		linkwatch_fire_event(dev);
4744 }
4745 
4746 /**
4747  *	netif_testing - test if device is under test
4748  *	@dev: network device
4749  *
4750  * Check if device is under test
4751  */
4752 static inline bool netif_testing(const struct net_device *dev)
4753 {
4754 	return test_bit(__LINK_STATE_TESTING, &dev->state);
4755 }
4756 
4757 
4758 /**
4759  *	netif_oper_up - test if device is operational
4760  *	@dev: network device
4761  *
4762  * Check if carrier is operational
4763  */
4764 static inline bool netif_oper_up(const struct net_device *dev)
4765 {
4766 	unsigned int operstate = READ_ONCE(dev->operstate);
4767 
4768 	return	operstate == IF_OPER_UP ||
4769 		operstate == IF_OPER_UNKNOWN /* backward compat */;
4770 }
4771 
4772 /**
4773  *	netif_device_present - is device available or removed
4774  *	@dev: network device
4775  *
4776  * Check if device has not been removed from system.
4777  */
4778 static inline bool netif_device_present(const struct net_device *dev)
4779 {
4780 	return test_bit(__LINK_STATE_PRESENT, &dev->state);
4781 }
4782 
4783 void netif_device_detach(struct net_device *dev);
4784 
4785 void netif_device_attach(struct net_device *dev);
4786 
4787 /*
4788  * Network interface message level settings
4789  */
4790 
4791 enum {
4792 	NETIF_MSG_DRV_BIT,
4793 	NETIF_MSG_PROBE_BIT,
4794 	NETIF_MSG_LINK_BIT,
4795 	NETIF_MSG_TIMER_BIT,
4796 	NETIF_MSG_IFDOWN_BIT,
4797 	NETIF_MSG_IFUP_BIT,
4798 	NETIF_MSG_RX_ERR_BIT,
4799 	NETIF_MSG_TX_ERR_BIT,
4800 	NETIF_MSG_TX_QUEUED_BIT,
4801 	NETIF_MSG_INTR_BIT,
4802 	NETIF_MSG_TX_DONE_BIT,
4803 	NETIF_MSG_RX_STATUS_BIT,
4804 	NETIF_MSG_PKTDATA_BIT,
4805 	NETIF_MSG_HW_BIT,
4806 	NETIF_MSG_WOL_BIT,
4807 
4808 	/* When you add a new bit above, update netif_msg_class_names array
4809 	 * in net/ethtool/common.c
4810 	 */
4811 	NETIF_MSG_CLASS_COUNT,
4812 };
4813 /* Both ethtool_ops interface and internal driver implementation use u32 */
4814 static_assert(NETIF_MSG_CLASS_COUNT <= 32);
4815 
4816 #define __NETIF_MSG_BIT(bit)	((u32)1 << (bit))
4817 #define __NETIF_MSG(name)	__NETIF_MSG_BIT(NETIF_MSG_ ## name ## _BIT)
4818 
4819 #define NETIF_MSG_DRV		__NETIF_MSG(DRV)
4820 #define NETIF_MSG_PROBE		__NETIF_MSG(PROBE)
4821 #define NETIF_MSG_LINK		__NETIF_MSG(LINK)
4822 #define NETIF_MSG_TIMER		__NETIF_MSG(TIMER)
4823 #define NETIF_MSG_IFDOWN	__NETIF_MSG(IFDOWN)
4824 #define NETIF_MSG_IFUP		__NETIF_MSG(IFUP)
4825 #define NETIF_MSG_RX_ERR	__NETIF_MSG(RX_ERR)
4826 #define NETIF_MSG_TX_ERR	__NETIF_MSG(TX_ERR)
4827 #define NETIF_MSG_TX_QUEUED	__NETIF_MSG(TX_QUEUED)
4828 #define NETIF_MSG_INTR		__NETIF_MSG(INTR)
4829 #define NETIF_MSG_TX_DONE	__NETIF_MSG(TX_DONE)
4830 #define NETIF_MSG_RX_STATUS	__NETIF_MSG(RX_STATUS)
4831 #define NETIF_MSG_PKTDATA	__NETIF_MSG(PKTDATA)
4832 #define NETIF_MSG_HW		__NETIF_MSG(HW)
4833 #define NETIF_MSG_WOL		__NETIF_MSG(WOL)
4834 
4835 #define netif_msg_drv(p)	((p)->msg_enable & NETIF_MSG_DRV)
4836 #define netif_msg_probe(p)	((p)->msg_enable & NETIF_MSG_PROBE)
4837 #define netif_msg_link(p)	((p)->msg_enable & NETIF_MSG_LINK)
4838 #define netif_msg_timer(p)	((p)->msg_enable & NETIF_MSG_TIMER)
4839 #define netif_msg_ifdown(p)	((p)->msg_enable & NETIF_MSG_IFDOWN)
4840 #define netif_msg_ifup(p)	((p)->msg_enable & NETIF_MSG_IFUP)
4841 #define netif_msg_rx_err(p)	((p)->msg_enable & NETIF_MSG_RX_ERR)
4842 #define netif_msg_tx_err(p)	((p)->msg_enable & NETIF_MSG_TX_ERR)
4843 #define netif_msg_tx_queued(p)	((p)->msg_enable & NETIF_MSG_TX_QUEUED)
4844 #define netif_msg_intr(p)	((p)->msg_enable & NETIF_MSG_INTR)
4845 #define netif_msg_tx_done(p)	((p)->msg_enable & NETIF_MSG_TX_DONE)
4846 #define netif_msg_rx_status(p)	((p)->msg_enable & NETIF_MSG_RX_STATUS)
4847 #define netif_msg_pktdata(p)	((p)->msg_enable & NETIF_MSG_PKTDATA)
4848 #define netif_msg_hw(p)		((p)->msg_enable & NETIF_MSG_HW)
4849 #define netif_msg_wol(p)	((p)->msg_enable & NETIF_MSG_WOL)
4850 
4851 static inline u32 netif_msg_init(int debug_value, int default_msg_enable_bits)
4852 {
4853 	/* use default */
4854 	if (debug_value < 0 || debug_value >= (sizeof(u32) * 8))
4855 		return default_msg_enable_bits;
4856 	if (debug_value == 0)	/* no output */
4857 		return 0;
4858 	/* set low N bits */
4859 	return (1U << debug_value) - 1;
4860 }
4861 
4862 static inline void __netif_tx_lock(struct netdev_queue *txq, int cpu)
4863 {
4864 	spin_lock(&txq->_xmit_lock);
4865 	/* Pairs with READ_ONCE() in netif_tx_owned() */
4866 	WRITE_ONCE(txq->xmit_lock_owner, cpu);
4867 }
4868 
4869 static inline bool __netif_tx_acquire(struct netdev_queue *txq)
4870 {
4871 	__acquire(&txq->_xmit_lock);
4872 	return true;
4873 }
4874 
4875 static inline void __netif_tx_release(struct netdev_queue *txq)
4876 {
4877 	__release(&txq->_xmit_lock);
4878 }
4879 
4880 static inline void __netif_tx_lock_bh(struct netdev_queue *txq)
4881 {
4882 	spin_lock_bh(&txq->_xmit_lock);
4883 	/* Pairs with READ_ONCE() in netif_tx_owned() */
4884 	WRITE_ONCE(txq->xmit_lock_owner, smp_processor_id());
4885 }
4886 
4887 static inline bool __netif_tx_trylock(struct netdev_queue *txq)
4888 {
4889 	bool ok = spin_trylock(&txq->_xmit_lock);
4890 
4891 	if (likely(ok)) {
4892 		/* Pairs with READ_ONCE() in netif_tx_owned() */
4893 		WRITE_ONCE(txq->xmit_lock_owner, smp_processor_id());
4894 	}
4895 	return ok;
4896 }
4897 
4898 static inline void __netif_tx_unlock(struct netdev_queue *txq)
4899 {
4900 	/* Pairs with READ_ONCE() in netif_tx_owned() */
4901 	WRITE_ONCE(txq->xmit_lock_owner, -1);
4902 	spin_unlock(&txq->_xmit_lock);
4903 }
4904 
4905 static inline void __netif_tx_unlock_bh(struct netdev_queue *txq)
4906 {
4907 	/* Pairs with READ_ONCE() in netif_tx_owned() */
4908 	WRITE_ONCE(txq->xmit_lock_owner, -1);
4909 	spin_unlock_bh(&txq->_xmit_lock);
4910 }
4911 
4912 /*
4913  * txq->trans_start can be read locklessly from dev_watchdog()
4914  */
4915 static inline void txq_trans_update(const struct net_device *dev,
4916 				    struct netdev_queue *txq)
4917 {
4918 	if (!dev->lltx)
4919 		WRITE_ONCE(txq->trans_start, jiffies);
4920 }
4921 
4922 static inline void txq_trans_cond_update(struct netdev_queue *txq)
4923 {
4924 	unsigned long now = jiffies;
4925 
4926 	if (READ_ONCE(txq->trans_start) != now)
4927 		WRITE_ONCE(txq->trans_start, now);
4928 }
4929 
4930 /* legacy drivers only, netdev_start_xmit() sets txq->trans_start */
4931 static inline void netif_trans_update(struct net_device *dev)
4932 {
4933 	struct netdev_queue *txq = netdev_get_tx_queue(dev, 0);
4934 
4935 	txq_trans_cond_update(txq);
4936 }
4937 
4938 /**
4939  *	netif_tx_lock - grab network device transmit lock
4940  *	@dev: network device
4941  *
4942  * Get network device transmit lock
4943  */
4944 void netif_tx_lock(struct net_device *dev);
4945 
4946 static inline void netif_tx_lock_bh(struct net_device *dev)
4947 {
4948 	local_bh_disable();
4949 	netif_tx_lock(dev);
4950 }
4951 
4952 void netif_tx_unlock(struct net_device *dev);
4953 
4954 static inline void netif_tx_unlock_bh(struct net_device *dev)
4955 {
4956 	netif_tx_unlock(dev);
4957 	local_bh_enable();
4958 }
4959 
4960 #define HARD_TX_LOCK(dev, txq, cpu) {			\
4961 	if (!(dev)->lltx) {				\
4962 		__netif_tx_lock(txq, cpu);		\
4963 	} else {					\
4964 		__netif_tx_acquire(txq);		\
4965 	}						\
4966 }
4967 
4968 #define HARD_TX_TRYLOCK(dev, txq)			\
4969 	(!(dev)->lltx ?					\
4970 		__netif_tx_trylock(txq) :		\
4971 		__netif_tx_acquire(txq))
4972 
4973 #define HARD_TX_UNLOCK(dev, txq) {			\
4974 	if (!(dev)->lltx) {				\
4975 		__netif_tx_unlock(txq);			\
4976 	} else {					\
4977 		__netif_tx_release(txq);		\
4978 	}						\
4979 }
4980 
4981 static inline void netif_tx_disable(struct net_device *dev)
4982 {
4983 	unsigned int i;
4984 	int cpu;
4985 
4986 	local_bh_disable();
4987 	cpu = smp_processor_id();
4988 	spin_lock(&dev->tx_global_lock);
4989 	for (i = 0; i < dev->num_tx_queues; i++) {
4990 		struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
4991 
4992 		__netif_tx_lock(txq, cpu);
4993 		netif_tx_stop_queue(txq);
4994 		__netif_tx_unlock(txq);
4995 	}
4996 	spin_unlock(&dev->tx_global_lock);
4997 	local_bh_enable();
4998 }
4999 
5000 #ifndef CONFIG_PREEMPT_RT
5001 static inline bool netif_tx_owned(struct netdev_queue *txq, unsigned int cpu)
5002 {
5003 	/* Other cpus might concurrently change txq->xmit_lock_owner
5004 	 * to -1 or to their cpu id, but not to our id.
5005 	 */
5006 	return READ_ONCE(txq->xmit_lock_owner) == cpu;
5007 }
5008 
5009 #else
5010 static inline bool netif_tx_owned(struct netdev_queue *txq, unsigned int cpu)
5011 {
5012 	return rt_mutex_owner(&txq->_xmit_lock.lock) == current;
5013 }
5014 
5015 #endif
5016 
5017 static inline void netif_addr_lock(struct net_device *dev)
5018 {
5019 	unsigned char nest_level = 0;
5020 
5021 #ifdef CONFIG_LOCKDEP
5022 	nest_level = dev->nested_level;
5023 #endif
5024 	spin_lock_nested(&dev->addr_list_lock, nest_level);
5025 }
5026 
5027 static inline void netif_addr_lock_bh(struct net_device *dev)
5028 {
5029 	unsigned char nest_level = 0;
5030 
5031 #ifdef CONFIG_LOCKDEP
5032 	nest_level = dev->nested_level;
5033 #endif
5034 	local_bh_disable();
5035 	spin_lock_nested(&dev->addr_list_lock, nest_level);
5036 }
5037 
5038 static inline void netif_addr_unlock(struct net_device *dev)
5039 {
5040 	spin_unlock(&dev->addr_list_lock);
5041 }
5042 
5043 static inline void netif_addr_unlock_bh(struct net_device *dev)
5044 {
5045 	spin_unlock_bh(&dev->addr_list_lock);
5046 }
5047 
5048 /*
5049  * dev_addrs walker. Should be used only for read access. Call with
5050  * rcu_read_lock held.
5051  */
5052 #define for_each_dev_addr(dev, ha) \
5053 		list_for_each_entry_rcu(ha, &dev->dev_addrs.list, list)
5054 
5055 /* These functions live elsewhere (drivers/net/net_init.c, but related) */
5056 
5057 void ether_setup(struct net_device *dev);
5058 
5059 /* Allocate dummy net_device */
5060 struct net_device *alloc_netdev_dummy(int sizeof_priv);
5061 
5062 /* Support for loadable net-drivers */
5063 struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
5064 				    unsigned char name_assign_type,
5065 				    void (*setup)(struct net_device *),
5066 				    unsigned int txqs, unsigned int rxqs);
5067 #define alloc_netdev(sizeof_priv, name, name_assign_type, setup) \
5068 	alloc_netdev_mqs(sizeof_priv, name, name_assign_type, setup, 1, 1)
5069 
5070 #define alloc_netdev_mq(sizeof_priv, name, name_assign_type, setup, count) \
5071 	alloc_netdev_mqs(sizeof_priv, name, name_assign_type, setup, count, \
5072 			 count)
5073 
5074 int register_netdev(struct net_device *dev);
5075 void unregister_netdev(struct net_device *dev);
5076 
5077 int devm_register_netdev(struct device *dev, struct net_device *ndev);
5078 
5079 /* General hardware address lists handling functions */
5080 int __hw_addr_sync(struct netdev_hw_addr_list *to_list,
5081 		   struct netdev_hw_addr_list *from_list, int addr_len);
5082 int __hw_addr_sync_multiple(struct netdev_hw_addr_list *to_list,
5083 			    struct netdev_hw_addr_list *from_list,
5084 			    int addr_len);
5085 void __hw_addr_unsync(struct netdev_hw_addr_list *to_list,
5086 		      struct netdev_hw_addr_list *from_list, int addr_len);
5087 int __hw_addr_sync_dev(struct netdev_hw_addr_list *list,
5088 		       struct net_device *dev,
5089 		       int (*sync)(struct net_device *, const unsigned char *),
5090 		       int (*unsync)(struct net_device *,
5091 				     const unsigned char *));
5092 int __hw_addr_ref_sync_dev(struct netdev_hw_addr_list *list,
5093 			   struct net_device *dev,
5094 			   int (*sync)(struct net_device *,
5095 				       const unsigned char *, int),
5096 			   int (*unsync)(struct net_device *,
5097 					 const unsigned char *, int));
5098 void __hw_addr_ref_unsync_dev(struct netdev_hw_addr_list *list,
5099 			      struct net_device *dev,
5100 			      int (*unsync)(struct net_device *,
5101 					    const unsigned char *, int));
5102 void __hw_addr_unsync_dev(struct netdev_hw_addr_list *list,
5103 			  struct net_device *dev,
5104 			  int (*unsync)(struct net_device *,
5105 					const unsigned char *));
5106 void __hw_addr_init(struct netdev_hw_addr_list *list);
5107 void __hw_addr_flush(struct netdev_hw_addr_list *list);
5108 int __hw_addr_list_snapshot(struct netdev_hw_addr_list *snap,
5109 			    const struct netdev_hw_addr_list *list,
5110 			    int addr_len, struct netdev_hw_addr_list *cache);
5111 void __hw_addr_list_reconcile(struct netdev_hw_addr_list *real_list,
5112 			      struct netdev_hw_addr_list *work,
5113 			      struct netdev_hw_addr_list *ref, int addr_len,
5114 			      struct netdev_hw_addr_list *cache);
5115 
5116 /* Functions used for device addresses handling */
5117 void dev_addr_mod(struct net_device *dev, unsigned int offset,
5118 		  const void *addr, size_t len);
5119 
5120 static inline void
5121 __dev_addr_set(struct net_device *dev, const void *addr, size_t len)
5122 {
5123 	dev_addr_mod(dev, 0, addr, len);
5124 }
5125 
5126 static inline void dev_addr_set(struct net_device *dev, const u8 *addr)
5127 {
5128 	__dev_addr_set(dev, addr, dev->addr_len);
5129 }
5130 
5131 int dev_addr_add(struct net_device *dev, const unsigned char *addr,
5132 		 unsigned char addr_type);
5133 int dev_addr_del(struct net_device *dev, const unsigned char *addr,
5134 		 unsigned char addr_type);
5135 
5136 /* Functions used for unicast addresses handling */
5137 int dev_uc_add(struct net_device *dev, const unsigned char *addr);
5138 int dev_uc_add_excl(struct net_device *dev, const unsigned char *addr);
5139 int dev_uc_del(struct net_device *dev, const unsigned char *addr);
5140 int dev_uc_sync(struct net_device *to, struct net_device *from);
5141 int dev_uc_sync_multiple(struct net_device *to, struct net_device *from);
5142 void dev_uc_unsync(struct net_device *to, struct net_device *from);
5143 void dev_uc_flush(struct net_device *dev);
5144 void dev_uc_init(struct net_device *dev);
5145 
5146 /**
5147  *  __dev_uc_sync - Synchronize device's unicast list
5148  *  @dev:  device to sync
5149  *  @sync: function to call if address should be added
5150  *  @unsync: function to call if address should be removed
5151  *
5152  *  Add newly added addresses to the interface, and release
5153  *  addresses that have been deleted.
5154  */
5155 static inline int __dev_uc_sync(struct net_device *dev,
5156 				int (*sync)(struct net_device *,
5157 					    const unsigned char *),
5158 				int (*unsync)(struct net_device *,
5159 					      const unsigned char *))
5160 {
5161 	return __hw_addr_sync_dev(&dev->uc, dev, sync, unsync);
5162 }
5163 
5164 /**
5165  *  __dev_uc_unsync - Remove synchronized addresses from device
5166  *  @dev:  device to sync
5167  *  @unsync: function to call if address should be removed
5168  *
5169  *  Remove all addresses that were added to the device by dev_uc_sync().
5170  */
5171 static inline void __dev_uc_unsync(struct net_device *dev,
5172 				   int (*unsync)(struct net_device *,
5173 						 const unsigned char *))
5174 {
5175 	__hw_addr_unsync_dev(&dev->uc, dev, unsync);
5176 }
5177 
5178 /* Functions used for multicast addresses handling */
5179 int dev_mc_add(struct net_device *dev, const unsigned char *addr);
5180 int dev_mc_add_global(struct net_device *dev, const unsigned char *addr);
5181 int dev_mc_add_excl(struct net_device *dev, const unsigned char *addr);
5182 int dev_mc_del(struct net_device *dev, const unsigned char *addr);
5183 int dev_mc_del_global(struct net_device *dev, const unsigned char *addr);
5184 int dev_mc_sync(struct net_device *to, struct net_device *from);
5185 int dev_mc_sync_multiple(struct net_device *to, struct net_device *from);
5186 void dev_mc_unsync(struct net_device *to, struct net_device *from);
5187 void dev_mc_flush(struct net_device *dev);
5188 void dev_mc_init(struct net_device *dev);
5189 int dev_mc_dump(struct sk_buff *skb, struct netlink_callback *cb);
5190 
5191 /**
5192  *  __dev_mc_sync - Synchronize device's multicast list
5193  *  @dev:  device to sync
5194  *  @sync: function to call if address should be added
5195  *  @unsync: function to call if address should be removed
5196  *
5197  *  Add newly added addresses to the interface, and release
5198  *  addresses that have been deleted.
5199  */
5200 static inline int __dev_mc_sync(struct net_device *dev,
5201 				int (*sync)(struct net_device *,
5202 					    const unsigned char *),
5203 				int (*unsync)(struct net_device *,
5204 					      const unsigned char *))
5205 {
5206 	return __hw_addr_sync_dev(&dev->mc, dev, sync, unsync);
5207 }
5208 
5209 /**
5210  *  __dev_mc_unsync - Remove synchronized addresses from device
5211  *  @dev:  device to sync
5212  *  @unsync: function to call if address should be removed
5213  *
5214  *  Remove all addresses that were added to the device by dev_mc_sync().
5215  */
5216 static inline void __dev_mc_unsync(struct net_device *dev,
5217 				   int (*unsync)(struct net_device *,
5218 						 const unsigned char *))
5219 {
5220 	__hw_addr_unsync_dev(&dev->mc, dev, unsync);
5221 }
5222 
5223 /* Functions used for secondary unicast and multicast support */
5224 void dev_set_rx_mode(struct net_device *dev);
5225 void netif_rx_mode_schedule_retry(struct net_device *dev);
5226 int netif_set_promiscuity(struct net_device *dev, int inc);
5227 int dev_set_promiscuity(struct net_device *dev, int inc);
5228 int netif_set_allmulti(struct net_device *dev, int inc, bool notify);
5229 int dev_set_allmulti(struct net_device *dev, int inc);
5230 void netif_state_change(struct net_device *dev);
5231 void netdev_state_change(struct net_device *dev);
5232 void __netdev_notify_peers(struct net_device *dev);
5233 void netdev_notify_peers(struct net_device *dev);
5234 void netdev_features_change(struct net_device *dev);
5235 /* Load a device via the kmod */
5236 void dev_load(struct net *net, const char *name);
5237 struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
5238 					struct rtnl_link_stats64 *storage);
5239 void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64,
5240 			     const struct net_device_stats *netdev_stats);
5241 void dev_fetch_sw_netstats(struct rtnl_link_stats64 *s,
5242 			   const struct pcpu_sw_netstats __percpu *netstats);
5243 void dev_get_tstats64(struct net_device *dev, struct rtnl_link_stats64 *s);
5244 
5245 void netdev_work_sched(struct net_device *dev, unsigned long events);
5246 unsigned long netdev_work_cancel(struct net_device *dev, unsigned long mask);
5247 
5248 enum {
5249 	NESTED_SYNC_IMM_BIT,
5250 	NESTED_SYNC_TODO_BIT,
5251 };
5252 
5253 #define __NESTED_SYNC_BIT(bit)	((u32)1 << (bit))
5254 #define __NESTED_SYNC(name)	__NESTED_SYNC_BIT(NESTED_SYNC_ ## name ## _BIT)
5255 
5256 #define NESTED_SYNC_IMM		__NESTED_SYNC(IMM)
5257 #define NESTED_SYNC_TODO	__NESTED_SYNC(TODO)
5258 
5259 struct netdev_nested_priv {
5260 	unsigned char flags;
5261 	void *data;
5262 };
5263 
5264 bool netdev_has_upper_dev(struct net_device *dev, struct net_device *upper_dev);
5265 struct net_device *netdev_upper_get_next_dev_rcu(struct net_device *dev,
5266 						     struct list_head **iter);
5267 
5268 /* iterate through upper list, must be called under RCU read lock */
5269 #define netdev_for_each_upper_dev_rcu(dev, updev, iter) \
5270 	for (iter = &(dev)->adj_list.upper, \
5271 	     updev = netdev_upper_get_next_dev_rcu(dev, &(iter)); \
5272 	     updev; \
5273 	     updev = netdev_upper_get_next_dev_rcu(dev, &(iter)))
5274 
5275 int netdev_walk_all_upper_dev_rcu(struct net_device *dev,
5276 				  int (*fn)(struct net_device *upper_dev,
5277 					    struct netdev_nested_priv *priv),
5278 				  struct netdev_nested_priv *priv);
5279 
5280 bool netdev_has_upper_dev_all_rcu(struct net_device *dev,
5281 				  struct net_device *upper_dev);
5282 
5283 bool netdev_has_any_upper_dev(struct net_device *dev);
5284 
5285 void *netdev_lower_get_next_private(struct net_device *dev,
5286 				    struct list_head **iter);
5287 void *netdev_lower_get_next_private_rcu(struct net_device *dev,
5288 					struct list_head **iter);
5289 
5290 #define netdev_for_each_lower_private(dev, priv, iter) \
5291 	for (iter = (dev)->adj_list.lower.next, \
5292 	     priv = netdev_lower_get_next_private(dev, &(iter)); \
5293 	     priv; \
5294 	     priv = netdev_lower_get_next_private(dev, &(iter)))
5295 
5296 #define netdev_for_each_lower_private_rcu(dev, priv, iter) \
5297 	for (iter = &(dev)->adj_list.lower, \
5298 	     priv = netdev_lower_get_next_private_rcu(dev, &(iter)); \
5299 	     priv; \
5300 	     priv = netdev_lower_get_next_private_rcu(dev, &(iter)))
5301 
5302 void *netdev_lower_get_next(struct net_device *dev,
5303 				struct list_head **iter);
5304 
5305 #define netdev_for_each_lower_dev(dev, ldev, iter) \
5306 	for (iter = (dev)->adj_list.lower.next, \
5307 	     ldev = netdev_lower_get_next(dev, &(iter)); \
5308 	     ldev; \
5309 	     ldev = netdev_lower_get_next(dev, &(iter)))
5310 
5311 struct net_device *netdev_next_lower_dev_rcu(struct net_device *dev,
5312 					     struct list_head **iter);
5313 int netdev_walk_all_lower_dev(struct net_device *dev,
5314 			      int (*fn)(struct net_device *lower_dev,
5315 					struct netdev_nested_priv *priv),
5316 			      struct netdev_nested_priv *priv);
5317 int netdev_walk_all_lower_dev_rcu(struct net_device *dev,
5318 				  int (*fn)(struct net_device *lower_dev,
5319 					    struct netdev_nested_priv *priv),
5320 				  struct netdev_nested_priv *priv);
5321 
5322 void *netdev_adjacent_get_private(struct list_head *adj_list);
5323 void *netdev_lower_get_first_private_rcu(struct net_device *dev);
5324 struct net_device *netdev_master_upper_dev_get(struct net_device *dev);
5325 struct net_device *netdev_master_upper_dev_get_rcu(struct net_device *dev);
5326 int netdev_upper_dev_link(struct net_device *dev, struct net_device *upper_dev,
5327 			  struct netlink_ext_ack *extack);
5328 int netdev_master_upper_dev_link(struct net_device *dev,
5329 				 struct net_device *upper_dev,
5330 				 void *upper_priv, void *upper_info,
5331 				 struct netlink_ext_ack *extack);
5332 void netdev_upper_dev_unlink(struct net_device *dev,
5333 			     struct net_device *upper_dev);
5334 int netdev_adjacent_change_prepare(struct net_device *old_dev,
5335 				   struct net_device *new_dev,
5336 				   struct net_device *dev,
5337 				   struct netlink_ext_ack *extack);
5338 void netdev_adjacent_change_commit(struct net_device *old_dev,
5339 				   struct net_device *new_dev,
5340 				   struct net_device *dev);
5341 void netdev_adjacent_change_abort(struct net_device *old_dev,
5342 				  struct net_device *new_dev,
5343 				  struct net_device *dev);
5344 void netdev_adjacent_rename_links(struct net_device *dev, char *oldname);
5345 void *netdev_lower_dev_get_private(struct net_device *dev,
5346 				   struct net_device *lower_dev);
5347 void netdev_lower_state_changed(struct net_device *lower_dev,
5348 				void *lower_state_info);
5349 
5350 #define NETDEV_RSS_KEY_LEN 256
5351 void netdev_rss_key_fill(void *buffer, size_t len);
5352 
5353 int skb_checksum_help(struct sk_buff *skb);
5354 int skb_crc32c_csum_help(struct sk_buff *skb);
5355 int skb_csum_hwoffload_help(struct sk_buff *skb,
5356 			    const netdev_features_t features);
5357 
5358 struct netdev_bonding_info {
5359 	ifslave	slave;
5360 	ifbond	master;
5361 };
5362 
5363 struct netdev_notifier_bonding_info {
5364 	struct netdev_notifier_info info; /* must be first */
5365 	struct netdev_bonding_info  bonding_info;
5366 };
5367 
5368 void netdev_bonding_info_change(struct net_device *dev,
5369 				struct netdev_bonding_info *bonding_info);
5370 
5371 #if IS_ENABLED(CONFIG_ETHTOOL_NETLINK)
5372 void ethtool_notify(struct net_device *dev, unsigned int cmd);
5373 #else
5374 static inline void ethtool_notify(struct net_device *dev, unsigned int cmd)
5375 {
5376 }
5377 #endif
5378 
5379 __be16 skb_network_protocol(struct sk_buff *skb, int *depth);
5380 
5381 static inline bool can_checksum_protocol(netdev_features_t features,
5382 					 __be16 protocol)
5383 {
5384 	if (protocol == htons(ETH_P_FCOE))
5385 		return !!(features & NETIF_F_FCOE_CRC);
5386 
5387 	/* Assume this is an IP checksum (not SCTP CRC) */
5388 
5389 	if (features & NETIF_F_HW_CSUM) {
5390 		/* Can checksum everything */
5391 		return true;
5392 	}
5393 
5394 	switch (protocol) {
5395 	case htons(ETH_P_IP):
5396 		return !!(features & NETIF_F_IP_CSUM);
5397 	case htons(ETH_P_IPV6):
5398 		return !!(features & NETIF_F_IPV6_CSUM);
5399 	default:
5400 		return false;
5401 	}
5402 }
5403 
5404 #ifdef CONFIG_BUG
5405 void netdev_rx_csum_fault(struct net_device *dev, struct sk_buff *skb);
5406 #else
5407 static inline void netdev_rx_csum_fault(struct net_device *dev,
5408 					struct sk_buff *skb)
5409 {
5410 }
5411 #endif
5412 /* rx skb timestamps */
5413 void net_enable_timestamp(void);
5414 void net_disable_timestamp(void);
5415 
5416 static inline ktime_t netdev_get_tstamp(struct net_device *dev,
5417 					const struct skb_shared_hwtstamps *hwtstamps,
5418 					bool cycles)
5419 {
5420 	const struct net_device_ops *ops = dev->netdev_ops;
5421 
5422 	if (ops->ndo_get_tstamp)
5423 		return ops->ndo_get_tstamp(dev, hwtstamps, cycles);
5424 
5425 	return hwtstamps->hwtstamp;
5426 }
5427 
5428 #ifndef CONFIG_PREEMPT_RT
5429 static inline void netdev_xmit_set_more(bool more)
5430 {
5431 	__this_cpu_write(softnet_data.xmit.more, more);
5432 }
5433 
5434 static inline bool netdev_xmit_more(void)
5435 {
5436 	return __this_cpu_read(softnet_data.xmit.more);
5437 }
5438 #else
5439 static inline void netdev_xmit_set_more(bool more)
5440 {
5441 	current->net_xmit.more = more;
5442 }
5443 
5444 static inline bool netdev_xmit_more(void)
5445 {
5446 	return current->net_xmit.more;
5447 }
5448 #endif
5449 
5450 static inline netdev_tx_t __netdev_start_xmit(const struct net_device_ops *ops,
5451 					      struct sk_buff *skb, struct net_device *dev,
5452 					      bool more)
5453 {
5454 	netdev_xmit_set_more(more);
5455 	return ops->ndo_start_xmit(skb, dev);
5456 }
5457 
5458 static inline netdev_tx_t netdev_start_xmit(struct sk_buff *skb, struct net_device *dev,
5459 					    struct netdev_queue *txq, bool more)
5460 {
5461 	const struct net_device_ops *ops = dev->netdev_ops;
5462 	netdev_tx_t rc;
5463 
5464 	rc = __netdev_start_xmit(ops, skb, dev, more);
5465 	if (rc == NETDEV_TX_OK)
5466 		txq_trans_update(dev, txq);
5467 
5468 	return rc;
5469 }
5470 
5471 int netdev_class_create_file_ns(const struct class_attribute *class_attr,
5472 				const struct ns_common *ns);
5473 void netdev_class_remove_file_ns(const struct class_attribute *class_attr,
5474 				 const struct ns_common *ns);
5475 
5476 extern const struct kobj_ns_type_operations net_ns_type_operations;
5477 
5478 const char *netdev_drivername(const struct net_device *dev);
5479 
5480 static inline netdev_features_t netdev_intersect_features(netdev_features_t f1,
5481 							  netdev_features_t f2)
5482 {
5483 	if ((f1 ^ f2) & NETIF_F_HW_CSUM) {
5484 		if (f1 & NETIF_F_HW_CSUM)
5485 			f1 |= (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM);
5486 		else
5487 			f2 |= (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM);
5488 	}
5489 
5490 	return f1 & f2;
5491 }
5492 
5493 static inline netdev_features_t netdev_get_wanted_features(
5494 	struct net_device *dev)
5495 {
5496 	return (dev->features & ~dev->hw_features) | dev->wanted_features;
5497 }
5498 netdev_features_t netdev_increment_features(netdev_features_t all,
5499 	netdev_features_t one, netdev_features_t mask);
5500 
5501 /* Allow TSO being used on stacked device :
5502  * Performing the GSO segmentation before last device
5503  * is a performance improvement.
5504  */
5505 static inline netdev_features_t netdev_add_tso_features(netdev_features_t features,
5506 							netdev_features_t mask)
5507 {
5508 	return netdev_increment_features(features, NETIF_F_ALL_TSO |
5509 					 NETIF_F_ALL_FOR_ALL, mask);
5510 }
5511 
5512 int __netdev_update_features(struct net_device *dev);
5513 void netdev_update_features(struct net_device *dev);
5514 void netdev_change_features(struct net_device *dev);
5515 void netdev_compute_master_upper_features(struct net_device *dev, bool update_header);
5516 
5517 void netif_stacked_transfer_operstate(const struct net_device *rootdev,
5518 					struct net_device *dev);
5519 
5520 netdev_features_t passthru_features_check(struct sk_buff *skb,
5521 					  struct net_device *dev,
5522 					  netdev_features_t features);
5523 netdev_features_t __netif_skb_features(struct sk_buff *skb,
5524 				       bool check_gso_limits);
5525 
5526 static inline netdev_features_t netif_skb_features(struct sk_buff *skb)
5527 {
5528 	return __netif_skb_features(skb, true);
5529 }
5530 
5531 void skb_warn_bad_offload(const struct sk_buff *skb);
5532 
5533 static inline bool net_gso_ok(netdev_features_t features, int gso_type)
5534 {
5535 	netdev_features_t feature;
5536 
5537 	if (gso_type & (SKB_GSO_TCP_FIXEDID | SKB_GSO_TCP_FIXEDID_INNER))
5538 		gso_type |= __SKB_GSO_TCP_FIXEDID;
5539 
5540 	feature = ((netdev_features_t)gso_type << NETIF_F_GSO_SHIFT) & NETIF_F_GSO_MASK;
5541 
5542 	/* check flags correspondence */
5543 	BUILD_BUG_ON(SKB_GSO_TCPV4   != (NETIF_F_TSO >> NETIF_F_GSO_SHIFT));
5544 	BUILD_BUG_ON(SKB_GSO_DODGY   != (NETIF_F_GSO_ROBUST >> NETIF_F_GSO_SHIFT));
5545 	BUILD_BUG_ON(SKB_GSO_TCP_ECN != (NETIF_F_TSO_ECN >> NETIF_F_GSO_SHIFT));
5546 	BUILD_BUG_ON(__SKB_GSO_TCP_FIXEDID != (NETIF_F_TSO_MANGLEID >> NETIF_F_GSO_SHIFT));
5547 	BUILD_BUG_ON(SKB_GSO_TCPV6   != (NETIF_F_TSO6 >> NETIF_F_GSO_SHIFT));
5548 	BUILD_BUG_ON(SKB_GSO_FCOE    != (NETIF_F_FSO >> NETIF_F_GSO_SHIFT));
5549 	BUILD_BUG_ON(SKB_GSO_GRE     != (NETIF_F_GSO_GRE >> NETIF_F_GSO_SHIFT));
5550 	BUILD_BUG_ON(SKB_GSO_GRE_CSUM != (NETIF_F_GSO_GRE_CSUM >> NETIF_F_GSO_SHIFT));
5551 	BUILD_BUG_ON(SKB_GSO_IPXIP4  != (NETIF_F_GSO_IPXIP4 >> NETIF_F_GSO_SHIFT));
5552 	BUILD_BUG_ON(SKB_GSO_IPXIP6  != (NETIF_F_GSO_IPXIP6 >> NETIF_F_GSO_SHIFT));
5553 	BUILD_BUG_ON(SKB_GSO_UDP_TUNNEL != (NETIF_F_GSO_UDP_TUNNEL >> NETIF_F_GSO_SHIFT));
5554 	BUILD_BUG_ON(SKB_GSO_UDP_TUNNEL_CSUM != (NETIF_F_GSO_UDP_TUNNEL_CSUM >> NETIF_F_GSO_SHIFT));
5555 	BUILD_BUG_ON(SKB_GSO_PARTIAL != (NETIF_F_GSO_PARTIAL >> NETIF_F_GSO_SHIFT));
5556 	BUILD_BUG_ON(SKB_GSO_TUNNEL_REMCSUM != (NETIF_F_GSO_TUNNEL_REMCSUM >> NETIF_F_GSO_SHIFT));
5557 	BUILD_BUG_ON(SKB_GSO_SCTP    != (NETIF_F_GSO_SCTP >> NETIF_F_GSO_SHIFT));
5558 	BUILD_BUG_ON(SKB_GSO_ESP != (NETIF_F_GSO_ESP >> NETIF_F_GSO_SHIFT));
5559 	BUILD_BUG_ON(SKB_GSO_UDP != (NETIF_F_GSO_UDP >> NETIF_F_GSO_SHIFT));
5560 	BUILD_BUG_ON(SKB_GSO_UDP_L4 != (NETIF_F_GSO_UDP_L4 >> NETIF_F_GSO_SHIFT));
5561 	BUILD_BUG_ON(SKB_GSO_FRAGLIST != (NETIF_F_GSO_FRAGLIST >> NETIF_F_GSO_SHIFT));
5562 	BUILD_BUG_ON(SKB_GSO_TCP_ACCECN !=
5563 		     (NETIF_F_GSO_ACCECN >> NETIF_F_GSO_SHIFT));
5564 
5565 	return (features & feature) == feature;
5566 }
5567 
5568 static inline bool skb_gso_ok(struct sk_buff *skb, netdev_features_t features)
5569 {
5570 	return net_gso_ok(features, skb_shinfo(skb)->gso_type) &&
5571 	       (!skb_has_frag_list(skb) || (features & NETIF_F_FRAGLIST));
5572 }
5573 
5574 static inline bool netif_needs_gso(struct sk_buff *skb,
5575 				   netdev_features_t features)
5576 {
5577 	return skb_is_gso(skb) && (!skb_gso_ok(skb, features) ||
5578 		unlikely((skb->ip_summed != CHECKSUM_PARTIAL) &&
5579 			 (skb->ip_summed != CHECKSUM_UNNECESSARY)));
5580 }
5581 
5582 void netif_set_tso_max_size(struct net_device *dev, unsigned int size);
5583 void netif_set_tso_max_segs(struct net_device *dev, unsigned int segs);
5584 void netif_inherit_tso_max(struct net_device *to,
5585 			   const struct net_device *from);
5586 
5587 static inline unsigned int
5588 netif_get_gro_max_size(const struct net_device *dev, const struct sk_buff *skb)
5589 {
5590 	/* pairs with WRITE_ONCE() in netif_set_gro(_ipv4)_max_size() */
5591 	return skb->protocol == htons(ETH_P_IPV6) ?
5592 	       READ_ONCE(dev->gro_max_size) :
5593 	       READ_ONCE(dev->gro_ipv4_max_size);
5594 }
5595 
5596 static inline bool netif_is_macsec(const struct net_device *dev)
5597 {
5598 	return dev->priv_flags & IFF_MACSEC;
5599 }
5600 
5601 static inline bool netif_is_macvlan(const struct net_device *dev)
5602 {
5603 	return dev->priv_flags & IFF_MACVLAN;
5604 }
5605 
5606 static inline bool netif_is_macvlan_port(const struct net_device *dev)
5607 {
5608 	return dev->priv_flags & IFF_MACVLAN_PORT;
5609 }
5610 
5611 static inline bool netif_is_bond_master(const struct net_device *dev)
5612 {
5613 	return dev->flags & IFF_MASTER && dev->priv_flags & IFF_BONDING;
5614 }
5615 
5616 static inline bool netif_is_bond_slave(const struct net_device *dev)
5617 {
5618 	return dev->flags & IFF_SLAVE && dev->priv_flags & IFF_BONDING;
5619 }
5620 
5621 static inline bool netif_supports_nofcs(struct net_device *dev)
5622 {
5623 	return dev->priv_flags & IFF_SUPP_NOFCS;
5624 }
5625 
5626 static inline bool netif_has_l3_rx_handler(const struct net_device *dev)
5627 {
5628 	return dev->priv_flags & IFF_L3MDEV_RX_HANDLER;
5629 }
5630 
5631 static inline bool netif_is_l3_master(const struct net_device *dev)
5632 {
5633 	return IS_ENABLED(CONFIG_NET_VRF) && (dev->priv_flags & IFF_L3MDEV_MASTER);
5634 }
5635 
5636 static inline bool netif_is_l3_slave(const struct net_device *dev)
5637 {
5638 	return IS_ENABLED(CONFIG_NET_VRF) && (dev->priv_flags & IFF_L3MDEV_SLAVE);
5639 }
5640 
5641 static inline int dev_sdif(const struct net_device *dev)
5642 {
5643 #ifdef CONFIG_NET_L3_MASTER_DEV
5644 	if (netif_is_l3_slave(dev))
5645 		return dev->ifindex;
5646 #endif
5647 	return 0;
5648 }
5649 
5650 static inline bool netif_is_bridge_master(const struct net_device *dev)
5651 {
5652 	return dev->priv_flags & IFF_EBRIDGE;
5653 }
5654 
5655 static inline bool netif_is_bridge_port(const struct net_device *dev)
5656 {
5657 	return dev->priv_flags & IFF_BRIDGE_PORT;
5658 }
5659 
5660 static inline bool netif_is_ovs_master(const struct net_device *dev)
5661 {
5662 	return dev->priv_flags & IFF_OPENVSWITCH;
5663 }
5664 
5665 static inline bool netif_is_ovs_port(const struct net_device *dev)
5666 {
5667 	return dev->priv_flags & IFF_OVS_DATAPATH;
5668 }
5669 
5670 static inline bool netif_is_any_bridge_master(const struct net_device *dev)
5671 {
5672 	return netif_is_bridge_master(dev) || netif_is_ovs_master(dev);
5673 }
5674 
5675 static inline bool netif_is_any_bridge_port(const struct net_device *dev)
5676 {
5677 	return netif_is_bridge_port(dev) || netif_is_ovs_port(dev);
5678 }
5679 
5680 static inline bool netif_is_team_master(const struct net_device *dev)
5681 {
5682 	return dev->priv_flags & IFF_TEAM;
5683 }
5684 
5685 static inline bool netif_is_team_port(const struct net_device *dev)
5686 {
5687 	return dev->priv_flags & IFF_TEAM_PORT;
5688 }
5689 
5690 static inline bool netif_is_lag_master(const struct net_device *dev)
5691 {
5692 	return netif_is_bond_master(dev) || netif_is_team_master(dev);
5693 }
5694 
5695 static inline bool netif_is_lag_port(const struct net_device *dev)
5696 {
5697 	return netif_is_bond_slave(dev) || netif_is_team_port(dev);
5698 }
5699 
5700 bool netif_is_rxfh_configured(const struct net_device *dev);
5701 
5702 static inline bool netif_is_failover(const struct net_device *dev)
5703 {
5704 	return dev->priv_flags & IFF_FAILOVER;
5705 }
5706 
5707 static inline bool netif_is_failover_slave(const struct net_device *dev)
5708 {
5709 	return dev->priv_flags & IFF_FAILOVER_SLAVE;
5710 }
5711 
5712 /* This device needs to keep skb dst for qdisc enqueue or ndo_start_xmit() */
5713 static inline void netif_keep_dst(struct net_device *dev)
5714 {
5715 	dev->priv_flags &= ~(IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM);
5716 }
5717 
5718 /* return true if dev can't cope with mtu frames that need vlan tag insertion */
5719 static inline bool netif_reduces_vlan_mtu(struct net_device *dev)
5720 {
5721 	/* TODO: reserve and use an additional IFF bit, if we get more users */
5722 	return netif_is_macsec(dev);
5723 }
5724 
5725 extern struct pernet_operations __net_initdata loopback_net_ops;
5726 
5727 /* Logging, debugging and troubleshooting/diagnostic helpers. */
5728 
5729 /* netdev_printk helpers, similar to dev_printk */
5730 
5731 static inline const char *netdev_name(const struct net_device *dev)
5732 {
5733 	if (!dev->name[0] || strchr(dev->name, '%'))
5734 		return "(unnamed net_device)";
5735 	return dev->name;
5736 }
5737 
5738 /* Caller holds RTNL, netdev->lock or RCU */
5739 static inline bool netif_is_alive(const struct net_device *dev)
5740 {
5741 	return READ_ONCE(dev->reg_state) <= NETREG_REGISTERED;
5742 }
5743 
5744 static inline const char *netdev_reg_state(const struct net_device *dev)
5745 {
5746 	u8 reg_state = READ_ONCE(dev->reg_state);
5747 
5748 	switch (reg_state) {
5749 	case NETREG_UNINITIALIZED: return " (uninitialized)";
5750 	case NETREG_REGISTERED: return "";
5751 	case NETREG_UNREGISTERING: return " (unregistering)";
5752 	case NETREG_UNREGISTERED: return " (unregistered)";
5753 	case NETREG_RELEASED: return " (released)";
5754 	case NETREG_DUMMY: return " (dummy)";
5755 	}
5756 
5757 	WARN_ONCE(1, "%s: unknown reg_state %d\n", dev->name, reg_state);
5758 	return " (unknown)";
5759 }
5760 
5761 #define MODULE_ALIAS_NETDEV(device) \
5762 	MODULE_ALIAS("netdev-" device)
5763 
5764 /*
5765  * netdev_WARN() acts like dev_printk(), but with the key difference
5766  * of using a WARN/WARN_ON to get the message out, including the
5767  * file/line information and a backtrace.
5768  */
5769 #define netdev_WARN(dev, format, args...)			\
5770 	WARN(1, "netdevice: %s%s: " format, netdev_name(dev),	\
5771 	     netdev_reg_state(dev), ##args)
5772 
5773 #define netdev_WARN_ONCE(dev, format, args...)				\
5774 	WARN_ONCE(1, "netdevice: %s%s: " format, netdev_name(dev),	\
5775 		  netdev_reg_state(dev), ##args)
5776 
5777 /*
5778  *	The list of packet types we will receive (as opposed to discard)
5779  *	and the routines to invoke.
5780  *
5781  *	Why 16. Because with 16 the only overlap we get on a hash of the
5782  *	low nibble of the protocol value is RARP/SNAP/X.25.
5783  *
5784  *		0800	IP
5785  *		0001	802.3
5786  *		0002	AX.25
5787  *		0004	802.2
5788  *		8035	RARP
5789  *		0005	SNAP
5790  *		0805	X.25
5791  *		0806	ARP
5792  *		8137	IPX
5793  *		0009	Localtalk
5794  *		86DD	IPv6
5795  */
5796 #define PTYPE_HASH_SIZE	(16)
5797 #define PTYPE_HASH_MASK	(PTYPE_HASH_SIZE - 1)
5798 
5799 extern struct list_head ptype_base[PTYPE_HASH_SIZE] __read_mostly;
5800 
5801 extern struct net_device *blackhole_netdev;
5802 
5803 /* Note: Avoid these macros in fast path, prefer per-cpu or per-queue counters. */
5804 #define DEV_STATS_INC(DEV, FIELD) atomic_long_inc(&(DEV)->stats.__##FIELD)
5805 #define DEV_STATS_ADD(DEV, FIELD, VAL) 	\
5806 		atomic_long_add((VAL), &(DEV)->stats.__##FIELD)
5807 #define DEV_STATS_READ(DEV, FIELD) atomic_long_read(&(DEV)->stats.__##FIELD)
5808 
5809 #endif	/* _LINUX_NETDEVICE_H */
5810