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