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