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