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