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