GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing codebrowser.dev (truncated) — netdevice.h source code [linux/include/linux/netdevice.h] - Codebrowser

Codebrowser logo
About
Contact
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, <[email protected]>
13 * Corey Minyard <[email protected]>
14 * Donald J. Becker, <[email protected]>
15 * Alan Cox, <[email protected]>
16 * Bjorn Ekwall. <[email protected]>
17 * Pekka Riikonen <[email protected]>
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 /* This field should be first or softnet_data.backlog needs tweaks. */
381 unsigned long state;
382 /* The poll_list must only be managed by the entity which
383 * changes the state of the NAPI_STATE_SCHED bit. This means
384 * whoever atomically sets that bit can add this napi_struct
385 * to the per-CPU poll_list, and whoever clears that bit
386 * can remove from the list right before clearing the bit.
387 */
388 struct list_head poll_list;
389
390 int weight;
391 u32 defer_hard_irqs_count;
392 int (*poll)(struct napi_struct *, int);
393#ifdef CONFIG_NETPOLL
394 /* CPU actively polling if netpoll is configured */
395 int poll_owner;
396#endif
397 /* CPU on which NAPI has been scheduled for processing */
398 int list_owner;
399 struct net_device *dev;
400 struct sk_buff *skb;
401 struct gro_node gro;
402 struct hrtimer timer;
403 /* all fields past this point are write-protected by netdev_lock */
404 struct task_struct *thread;
405 unsigned long gro_flush_timeout;
406 unsigned long irq_suspend_timeout;
407 u32 defer_hard_irqs;
408 /* control-path-only fields follow */
409 u32 napi_id;
410 struct list_head dev_list;
411 struct hlist_node napi_hash_node;
412 int irq;
413 struct irq_affinity_notify notify;
414 int napi_rmap_idx;
415 int index;
416 struct napi_config *config;
417};
418
419enum {
420 NAPI_STATE_SCHED, /* Poll is scheduled */
421 NAPI_STATE_MISSED, /* reschedule a napi */
422 NAPI_STATE_DISABLE, /* Disable pending */
423 NAPI_STATE_NPSVC, /* Netpoll - don't dequeue from poll_list */
424 NAPI_STATE_LISTED, /* NAPI added to system lists */
425 NAPI_STATE_NO_BUSY_POLL, /* Do not add in napi_hash, no busy polling */
426 NAPI_STATE_IN_BUSY_POLL, /* Do not rearm NAPI interrupt */
427 NAPI_STATE_PREFER_BUSY_POLL, /* prefer busy-polling over softirq processing*/
428 NAPI_STATE_THREADED, /* The poll is performed inside its own thread*/
429 NAPI_STATE_SCHED_THREADED, /* Napi is currently scheduled in threaded mode */
430 NAPI_STATE_HAS_NOTIFIER, /* Napi has an IRQ notifier */
431 NAPI_STATE_THREADED_BUSY_POLL, /* The threaded NAPI poller will busy poll */
432};
433
434enum {
435 NAPIF_STATE_SCHED = BIT(NAPI_STATE_SCHED),
436 NAPIF_STATE_MISSED = BIT(NAPI_STATE_MISSED),
437 NAPIF_STATE_DISABLE = BIT(NAPI_STATE_DISABLE),
438 NAPIF_STATE_NPSVC = BIT(NAPI_STATE_NPSVC),
439 NAPIF_STATE_LISTED = BIT(NAPI_STATE_LISTED),
440 NAPIF_STATE_NO_BUSY_POLL = BIT(NAPI_STATE_NO_BUSY_POLL),
441 NAPIF_STATE_IN_BUSY_POLL = BIT(NAPI_STATE_IN_BUSY_POLL),
442 NAPIF_STATE_PREFER_BUSY_POLL = BIT(NAPI_STATE_PREFER_BUSY_POLL),
443 NAPIF_STATE_THREADED = BIT(NAPI_STATE_THREADED),
444 NAPIF_STATE_SCHED_THREADED = BIT(NAPI_STATE_SCHED_THREADED),
445 NAPIF_STATE_HAS_NOTIFIER = BIT(NAPI_STATE_HAS_NOTIFIER),
446 NAPIF_STATE_THREADED_BUSY_POLL = BIT(NAPI_STATE_THREADED_BUSY_POLL),
447};
448
449enum gro_result {
450 GRO_MERGED,
451 GRO_MERGED_FREE,
452 GRO_HELD,
453 GRO_NORMAL,
454 GRO_CONSUMED,
455};
456typedef enum gro_result gro_result_t;
457
458/*
459 * enum rx_handler_result - Possible return values for rx_handlers.
460 * @RX_HANDLER_CONSUMED: skb was consumed by rx_handler, do not process it
461 * further.
462 * @RX_HANDLER_ANOTHER: Do another round in receive path. This is indicated in
463 * case skb->dev was changed by rx_handler.
464 * @RX_HANDLER_EXACT: Force exact delivery, no wildcard.
465 * @RX_HANDLER_PASS: Do nothing, pass the skb as if no rx_handler was called.
466 *
467 * rx_handlers are functions called from inside __netif_receive_skb(), to do
468 * special processing of the skb, prior to delivery to protocol handlers.
469 *
470 * Currently, a net_device can only have a single rx_handler registered. Trying
471 * to register a second rx_handler will return -EBUSY.
472 *
473 * To register a rx_handler on a net_device, use netdev_rx_handler_register().
474 * To unregister a rx_handler on a net_device, use
475 * netdev_rx_handler_unregister().
476 *
477 * Upon return, rx_handler is expected to tell __netif_receive_skb() what to
478 * do with the skb.
479 *
480 * If the rx_handler consumed the skb in some way, it should return
481 * RX_HANDLER_CONSUMED. This is appropriate when the rx_handler arranged for
482 * the skb to be delivered in some other way.
483 *
484 * If the rx_handler changed skb->dev, to divert the skb to another
485 * net_device, it should return RX_HANDLER_ANOTHER. The rx_handler for the
486 * new device will be called if it exists.
487 *
488 * If the rx_handler decides the skb should be ignored, it should return
489 * RX_HANDLER_EXACT. The skb will only be delivered to protocol handlers that
490 * are registered on exact device (ptype->dev == skb->dev).
491 *
492 * If the rx_handler didn't change skb->dev, but wants the skb to be normally
493 * delivered, it should return RX_HANDLER_PASS.
494 *
495 * A device without a registered rx_handler will behave as if rx_handler
496 * returned RX_HANDLER_PASS.
497 */
498
499enum rx_handler_result {
500 RX_HANDLER_CONSUMED,
501 RX_HANDLER_ANOTHER,
502 RX_HANDLER_EXACT,
503 RX_HANDLER_PASS,
504};
505typedef enum rx_handler_result rx_handler_result_t;
506typedef rx_handler_result_t rx_handler_func_t(struct sk_buff **pskb);
507
508void __napi_schedule(struct napi_struct *n);
509void __napi_schedule_irqoff(struct napi_struct *n);
510
511static inline bool napi_disable_pending(struct napi_struct *n)
512{
513 return test_bit(NAPI_STATE_DISABLE, &n->state);
514}
515
516static inline bool napi_prefer_busy_poll(struct napi_struct *n)
517{
518 return test_bit(NAPI_STATE_PREFER_BUSY_POLL, &n->state);
519}
520
521/**
522 * napi_is_scheduled - test if NAPI is scheduled
523 * @n: NAPI context
524 *
525 * This check is "best-effort". With no locking implemented,
526 * a NAPI can be scheduled or terminate right after this check
527 * and produce not precise results.
528 *
529 * NAPI_STATE_SCHED is an internal state, napi_is_scheduled
530 * should not be used normally and napi_schedule should be
531 * used instead.
532 *
533 * Use only if the driver really needs to check if a NAPI
534 * is scheduled for example in the context of delayed timer
535 * that can be skipped if a NAPI is already scheduled.
536 *
537 * Return: True if NAPI is scheduled, False otherwise.
538 */
539static inline bool napi_is_scheduled(struct napi_struct *n)
540{
541 return test_bit(NAPI_STATE_SCHED, &n->state);
542}
543
544bool napi_schedule_prep(struct napi_struct *n);
545
546/**
547 * napi_schedule - schedule NAPI poll
548 * @n: NAPI context
549 *
550 * Schedule NAPI poll routine to be called if it is not already
551 * running.
552 * Return: true if we schedule a NAPI or false if not.
553 * Refer to napi_schedule_prep() for additional reason on why
554 * a NAPI might not be scheduled.
555 */
556static inline bool napi_schedule(struct napi_struct *n)
557{
558 if (napi_schedule_prep(n)) {
559 __napi_schedule(n);
560 return true;
561 }
562
563 return false;
564}
565
566/**
567 * napi_schedule_irqoff - schedule NAPI poll
568 * @n: NAPI context
569 *
570 * Variant of napi_schedule(), assuming hard irqs are masked.
571 */
572static inline void napi_schedule_irqoff(struct napi_struct *n)
573{
574 if (napi_schedule_prep(n))
575 __napi_schedule_irqoff(n);
576}
577
578/**
579 * napi_complete_done - NAPI processing complete
580 * @n: NAPI context
581 * @work_done: number of packets processed
582 *
583 * Mark NAPI processing as complete. Should only be called if poll budget
584 * has not been completely consumed.
585 * Prefer over napi_complete().
586 * Return: false if device should avoid rearming interrupts.
587 */
588bool napi_complete_done(struct napi_struct *n, int work_done);
589
590static inline bool napi_complete(struct napi_struct *n)
591{
592 return napi_complete_done(n, work_done: 0);
593}
594
595void netif_threaded_enable(struct net_device *dev);
596int dev_set_threaded(struct net_device *dev,
597 enum netdev_napi_threaded threaded);
598
599void napi_disable(struct napi_struct *n);
600void napi_disable_locked(struct napi_struct *n);
601
602void napi_enable(struct napi_struct *n);
603void napi_enable_locked(struct napi_struct *n);
604
605/**
606 * napi_synchronize - wait until NAPI is not running
607 * @n: NAPI context
608 *
609 * Wait until NAPI is done being scheduled on this context.
610 * Waits till any outstanding processing completes but
611 * does not disable future activations.
612 */
613static inline void napi_synchronize(const struct napi_struct *n)
614{
615 if (IS_ENABLED(CONFIG_SMP))
616 while (test_bit(NAPI_STATE_SCHED, &n->state))
617 msleep(msecs: 1);
618 else
619 barrier();
620}
621
622/**
623 * napi_if_scheduled_mark_missed - if napi is running, set the
624 * NAPIF_STATE_MISSED
625 * @n: NAPI context
626 *
627 * If napi is running, set the NAPIF_STATE_MISSED, and return true if
628 * NAPI is scheduled.
629 **/
630static inline bool napi_if_scheduled_mark_missed(struct napi_struct *n)
631{
632 unsigned long val, new;
633
634 val = READ_ONCE(n->state);
635 do {
636 if (val & NAPIF_STATE_DISABLE)
637 return true;
638
639 if (!(val & NAPIF_STATE_SCHED))
640 return false;
641
642 new = val | NAPIF_STATE_MISSED;
643 } while (!try_cmpxchg(&n->state, &val, new));
644
645 return true;
646}
647
648enum netdev_queue_state_t {
649 __QUEUE_STATE_DRV_XOFF,
650 __QUEUE_STATE_STACK_XOFF,
651 __QUEUE_STATE_FROZEN,
652};
653
654#define QUEUE_STATE_DRV_XOFF (1 << __QUEUE_STATE_DRV_XOFF)
655#define QUEUE_STATE_STACK_XOFF (1 << __QUEUE_STATE_STACK_XOFF)
656#define QUEUE_STATE_FROZEN (1 << __QUEUE_STATE_FROZEN)
657
658#define QUEUE_STATE_ANY_XOFF (QUEUE_STATE_DRV_XOFF | QUEUE_STATE_STACK_XOFF)
659#define QUEUE_STATE_ANY_XOFF_OR_FROZEN (QUEUE_STATE_ANY_XOFF | \
660 QUEUE_STATE_FROZEN)
661#define QUEUE_STATE_DRV_XOFF_OR_FROZEN (QUEUE_STATE_DRV_XOFF | \
662 QUEUE_STATE_FROZEN)
663
664/*
665 * __QUEUE_STATE_DRV_XOFF is used by drivers to stop the transmit queue. The
666 * netif_tx_* functions below are used to manipulate this flag. The
667 * __QUEUE_STATE_STACK_XOFF flag is used by the stack to stop the transmit
668 * queue independently. The netif_xmit_*stopped functions below are called
669 * to check if the queue has been stopped by the driver or stack (either
670 * of the XOFF bits are set in the state). Drivers should not need to call
671 * netif_xmit*stopped functions, they should only be using netif_tx_*.
672 */
673
674struct netdev_queue {
675/*
676 * read-mostly part
677 */
678 struct net_device *dev;
679 netdevice_tracker dev_tracker;
680
681 struct Qdisc __rcu *qdisc;
682 struct Qdisc __rcu *qdisc_sleeping;
683#ifdef CONFIG_SYSFS
684 struct kobject kobj;
685 const struct attribute_group **groups;
686#endif
687 unsigned long tx_maxrate;
688 /*
689 * Number of TX timeouts for this queue
690 * (/sys/class/net/DEV/Q/trans_timeout)
691 */
692 atomic_long_t trans_timeout;
693
694 /* Subordinate device that the queue has been assigned to */
695 struct net_device *sb_dev;
696#ifdef CONFIG_XDP_SOCKETS
697 /* "ops protected", see comment about net_device::lock */
698 struct xsk_buff_pool *pool;
699#endif
700
701/*
702 * write-mostly part
703 */
704#ifdef CONFIG_BQL
705 struct dql dql;
706#endif
707 spinlock_t _xmit_lock ____cacheline_aligned_in_smp;
708 int xmit_lock_owner;
709 /*
710 * Time (in jiffies) of last Tx
711 */
712 unsigned long trans_start;
713
714 unsigned long state;
715
716/*
717 * slow- / control-path part
718 */
719 /* NAPI instance for the queue
720 * "ops protected", see comment about net_device::lock
721 */
722 struct napi_struct *napi;
723
724#if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
725 int numa_node;
726#endif
727} ____cacheline_aligned_in_smp;
728
729extern int sysctl_fb_tunnels_only_for_init_net;
730extern int sysctl_devconf_inherit_init_net;
731
732/*
733 * sysctl_fb_tunnels_only_for_init_net == 0 : For all netns
734 * == 1 : For initns only
735 * == 2 : For none.
736 */
737static inline bool net_has_fallback_tunnels(const struct net *net)
738{
739#if IS_ENABLED(CONFIG_SYSCTL)
740 int fb_tunnels_only_for_init_net = READ_ONCE(sysctl_fb_tunnels_only_for_init_net);
741
742 return !fb_tunnels_only_for_init_net ||
743 (net_eq(net1: net, net2: &init_net) && fb_tunnels_only_for_init_net == 1);
744#else
745 return true;
746#endif
747}
748
749static inline int net_inherit_devconf(void)
750{
751#if IS_ENABLED(CONFIG_SYSCTL)
752 return READ_ONCE(sysctl_devconf_inherit_init_net);
753#else
754 return 0;
755#endif
756}
757
758static inline int netdev_queue_numa_node_read(const struct netdev_queue *q)
759{
760#if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
761 return q->numa_node;
762#else
763 return NUMA_NO_NODE;
764#endif
765}
766
767static inline void netdev_queue_numa_node_write(struct netdev_queue *q, int node)
768{
769#if defined(CONFIG_XPS) && defined(CONFIG_NUMA)
770 q->numa_node = node;
771#endif
772}
773
774#ifdef CONFIG_RFS_ACCEL
775bool rps_may_expire_flow(struct net_device *dev, u16 rxq_index, u32 flow_id,
776 u16 filter_id);
777#endif
778
779/* XPS map type and offset of the xps map within net_device->xps_maps[]. */
780enum xps_map_type {
781 XPS_CPUS = 0,
782 XPS_RXQS,
783 XPS_MAPS_MAX,
784};
785
786#ifdef CONFIG_XPS
787/*
788 * This structure holds an XPS map which can be of variable length. The
789 * map is an array of queues.
790 */
791struct xps_map {
792 unsigned int len;
793 unsigned int alloc_len;
794 struct rcu_head rcu;
795 u16 queues[];
796};
797#define XPS_MAP_SIZE(_num) (sizeof(struct xps_map) + ((_num) * sizeof(u16)))
798#define XPS_MIN_MAP_ALLOC ((L1_CACHE_ALIGN(offsetof(struct xps_map, queues[1])) \
799 - sizeof(struct xps_map)) / sizeof(u16))
800
801/*
802 * This structure holds all XPS maps for device. Maps are indexed by CPU.
803 *
804 * We keep track of the number of cpus/rxqs used when the struct is allocated,
805 * in nr_ids. This will help not accessing out-of-bound memory.
806 *
807 * We keep track of the number of traffic classes used when the struct is
808 * allocated, in num_tc. This will be used to navigate the maps, to ensure we're
809 * not crossing its upper bound, as the original dev->num_tc can be updated in
810 * the meantime.
811 */
812struct xps_dev_maps {
813 struct rcu_head rcu;
814 unsigned int nr_ids;
815 s16 num_tc;
816 struct xps_map __rcu *attr_map[]; /* Either CPUs map or RXQs map */
817};
818
819#define XPS_CPU_DEV_MAPS_SIZE(_tcs) (sizeof(struct xps_dev_maps) + \
820 (nr_cpu_ids * (_tcs) * sizeof(struct xps_map *)))
821
822#define XPS_RXQ_DEV_MAPS_SIZE(_tcs, _rxqs) (sizeof(struct xps_dev_maps) +\
823 (_rxqs * (_tcs) * sizeof(struct xps_map *)))
824
825#endif /* CONFIG_XPS */
826
827#define TC_MAX_QUEUE 16
828#define TC_BITMASK 15
829/* HW offloaded queuing disciplines txq count and offset maps */
830struct netdev_tc_txq {
831 u16 count;
832 u16 offset;
833};
834
835#if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
836/*
837 * This structure is to hold information about the device
838 * configured to run FCoE protocol stack.
839 */
840struct netdev_fcoe_hbainfo {
841 char manufacturer[64];
842 char serial_number[64];
843 char hardware_version[64];
844 char driver_version[64];
845 char optionrom_version[64];
846 char firmware_version[64];
847 char model[256];
848 char model_description[256];
849};
850#endif
851
852#define MAX_PHYS_ITEM_ID_LEN 32
853
854/* This structure holds a unique identifier to identify some
855 * physical item (port for example) used by a netdevice.
856 */
857struct netdev_phys_item_id {
858 unsigned char id[MAX_PHYS_ITEM_ID_LEN];
859 unsigned char id_len;
860};
861
862static inline bool netdev_phys_item_id_same(struct netdev_phys_item_id *a,
863 struct netdev_phys_item_id *b)
864{
865 return a->id_len == b->id_len &&
866 memcmp(p: a->id, q: b->id, size: a->id_len) == 0;
867}
868
869typedef u16 (*select_queue_fallback_t)(struct net_device *dev,
870 struct sk_buff *skb,
871 struct net_device *sb_dev);
872
873enum net_device_path_type {
874 DEV_PATH_ETHERNET = 0,
875 DEV_PATH_VLAN,
876 DEV_PATH_BRIDGE,
877 DEV_PATH_PPPOE,
878 DEV_PATH_DSA,
879 DEV_PATH_MTK_WDMA,
880 DEV_PATH_TUN,
881};
882
883struct net_device_path {
884 enum net_device_path_type type;
885 const struct net_device *dev;
886 union {
887 struct {
888 u16 id;
889 __be16 proto;
890 u8 h_dest[ETH_ALEN];
891 } encap;
892 struct {
893 union {
894 struct in_addr src_v4;
895 struct in6_addr src_v6;
896 };
897 union {
898 struct in_addr dst_v4;
899 struct in6_addr dst_v6;
900 };
901
902 u8 l3_proto;
903 } tun;
904 struct {
905 enum {
906 DEV_PATH_BR_VLAN_KEEP,
907 DEV_PATH_BR_VLAN_TAG,
908 DEV_PATH_BR_VLAN_UNTAG,
909 DEV_PATH_BR_VLAN_UNTAG_HW,
910 } vlan_mode;
911 u16 vlan_id;
912 __be16 vlan_proto;
913 } bridge;
914 struct {
915 int port;
916 u16 proto;
917 } dsa;
918 struct {
919 u8 wdma_idx;
920 u8 queue;
921 u16 wcid;
922 u8 bss;
923 u8 amsdu;
924 } mtk_wdma;
925 };
926};
927
928#define NET_DEVICE_PATH_STACK_MAX 5
929#define NET_DEVICE_PATH_VLAN_MAX 2
930
931struct net_device_path_stack {
932 int num_paths;
933 struct net_device_path path[NET_DEVICE_PATH_STACK_MAX];
934};
935
936struct net_device_path_ctx {
937 const struct net_device *dev;
938 u8 daddr[ETH_ALEN];
939
940 int num_vlans;
941 struct {
942 u16 id;
943 __be16 proto;
944 } vlan[NET_DEVICE_PATH_VLAN_MAX];
945};
946
947enum tc_setup_type {
948 TC_QUERY_CAPS,
949 TC_SETUP_QDISC_MQPRIO,
950 TC_SETUP_CLSU32,
951 TC_SETUP_CLSFLOWER,
952 TC_SETUP_CLSMATCHALL,
953 TC_SETUP_CLSBPF,
954 TC_SETUP_BLOCK,
955 TC_SETUP_QDISC_CBS,
956 TC_SETUP_QDISC_RED,
957 TC_SETUP_QDISC_PRIO,
958 TC_SETUP_QDISC_MQ,
959 TC_SETUP_QDISC_ETF,
960 TC_SETUP_ROOT_QDISC,
961 TC_SETUP_QDISC_GRED,
962 TC_SETUP_QDISC_TAPRIO,
963 TC_SETUP_FT,
964 TC_SETUP_QDISC_ETS,
965 TC_SETUP_QDISC_TBF,
966 TC_SETUP_QDISC_FIFO,
967 TC_SETUP_QDISC_HTB,
968 TC_SETUP_ACT,
969};
970
971/* These structures hold the attributes of bpf state that are being passed
972 * to the netdevice through the bpf op.
973 */
974enum bpf_netdev_command {
975 /* Set or clear a bpf program used in the earliest stages of packet
976 * rx. The prog will have been loaded as BPF_PROG_TYPE_XDP. The callee
977 * is responsible for calling bpf_prog_put on any old progs that are
978 * stored. In case of error, the callee need not release the new prog
979 * reference, but on success it takes ownership and must bpf_prog_put
980 * when it is no longer used.
981 */
982 XDP_SETUP_PROG,
983 XDP_SETUP_PROG_HW,
984 /* BPF program for offload callbacks, invoked at program load time. */
985 BPF_OFFLOAD_MAP_ALLOC,
986 BPF_OFFLOAD_MAP_FREE,
987 XDP_SETUP_XSK_POOL,
988};
989
990struct bpf_prog_offload_ops;
991struct netlink_ext_ack;
992struct xdp_umem;
993struct xdp_dev_bulk_queue;
994struct bpf_xdp_link;
995
996enum bpf_xdp_mode {
997 XDP_MODE_SKB = 0,
998 XDP_MODE_DRV = 1,
999 XDP_MODE_HW = 2,
1000 __MAX_XDP_MODE
1001};
1002
1003struct bpf_xdp_entity {
1004 struct bpf_prog *prog;
1005 struct bpf_xdp_link *link;
1006};
1007
1008struct netdev_bpf {
1009 enum bpf_netdev_command command;
1010 union {
1011 /* XDP_SETUP_PROG */
1012 struct {
1013 u32 flags;
1014 struct bpf_prog *prog;
1015 struct netlink_ext_ack *extack;
1016 };
1017 /* BPF_OFFLOAD_MAP_ALLOC, BPF_OFFLOAD_MAP_FREE */
1018 struct {
1019 struct bpf_offloaded_map *offmap;
1020 };
1021 /* XDP_SETUP_XSK_POOL */
1022 struct {
1023 struct xsk_buff_pool *pool;
1024 u16 queue_id;
1025 } xsk;
1026 };
1027};
1028
1029/* Flags for ndo_xsk_wakeup. */
1030#define XDP_WAKEUP_RX (1 << 0)
1031#define XDP_WAKEUP_TX (1 << 1)
1032
1033#ifdef CONFIG_XFRM_OFFLOAD
1034struct xfrmdev_ops {
1035 int (*xdo_dev_state_add)(struct net_device *dev,
1036 struct xfrm_state *x,
1037 struct netlink_ext_ack *extack);
1038 void (*xdo_dev_state_delete)(struct net_device *dev,
1039 struct xfrm_state *x);
1040 void (*xdo_dev_state_free)(struct net_device *dev,
1041 struct xfrm_state *x);
1042 bool (*xdo_dev_offload_ok) (struct sk_buff *skb,
1043 struct xfrm_state *x);
1044 void (*xdo_dev_state_advance_esn) (struct xfrm_state *x);
1045 void (*xdo_dev_state_update_stats) (struct xfrm_state *x);
1046 int (*xdo_dev_policy_add) (struct xfrm_policy *x, struct netlink_ext_ack *extack);
1047 void (*xdo_dev_policy_delete) (struct xfrm_policy *x);
1048 void (*xdo_dev_policy_free) (struct xfrm_policy *x);
1049};
1050#endif
1051
1052struct dev_ifalias {
1053 struct rcu_head rcuhead;
1054 char ifalias[];
1055};
1056
1057struct devlink;
1058struct tlsdev_ops;
1059
1060struct netdev_net_notifier {
1061 struct list_head list;
1062 struct notifier_block *nb;
1063};
1064
1065/*
1066 * This structure defines the management hooks for network devices.
1067 * The following hooks can be defined; unless noted otherwise, they are
1068 * optional and can be filled with a null pointer.
1069 *
1070 * int (*ndo_init)(struct net_device *dev);
1071 * This function is called once when a network device is registered.
1072 * The network device can use this for any late stage initialization
1073 * or semantic validation. It can fail with an error code which will
1074 * be propagated back to register_netdev.
1075 *
1076 * void (*ndo_uninit)(struct net_device *dev);
1077 * This function is called when device is unregistered or when registration
1078 * fails. It is not called if init fails.
1079 *
1080 * int (*ndo_open)(struct net_device *dev);
1081 * This function is called when a network device transitions to the up
1082 * state.
1083 *
1084 * int (*ndo_stop)(struct net_device *dev);
1085 * This function is called when a network device transitions to the down
1086 * state.
1087 *
1088 * netdev_tx_t (*ndo_start_xmit)(struct sk_buff *skb,
1089 * struct net_device *dev);
1090 * Called when a packet needs to be transmitted.
1091 * Returns NETDEV_TX_OK. Can return NETDEV_TX_BUSY, but you should stop
1092 * the queue before that can happen; it's for obsolete devices and weird
1093 * corner cases, but the stack really does a non-trivial amount
1094 * of useless work if you return NETDEV_TX_BUSY.
1095 * Required; cannot be NULL.
1096 *
1097 * netdev_features_t (*ndo_features_check)(struct sk_buff *skb,
1098 * struct net_device *dev
1099 * netdev_features_t features);
1100 * Called by core transmit path to determine if device is capable of
1101 * performing offload operations on a given packet. This is to give
1102 * the device an opportunity to implement any restrictions that cannot
1103 * be otherwise expressed by feature flags. The check is called with
1104 * the set of features that the stack has calculated and it returns
1105 * those the driver believes to be appropriate.
1106 *
1107 * u16 (*ndo_select_queue)(struct net_device *dev, struct sk_buff *skb,
1108 * struct net_device *sb_dev);
1109 * Called to decide which queue to use when device supports multiple
1110 * transmit queues.
1111 *
1112 * void (*ndo_change_rx_flags)(struct net_device *dev, int flags);
1113 * This function is called to allow device receiver to make
1114 * changes to configuration when multicast or promiscuous is enabled.
1115 *
1116 * void (*ndo_set_rx_mode)(struct net_device *dev);
1117 * This function is called device changes address list filtering.
1118 * If driver handles unicast address filtering, it should set
1119 * IFF_UNICAST_FLT in its priv_flags.
1120 *
1121 * int (*ndo_set_mac_address)(struct net_device *dev, void *addr);
1122 * This function is called when the Media Access Control address
1123 * needs to be changed. If this interface is not defined, the
1124 * MAC address can not be changed.
1125 *
1126 * int (*ndo_validate_addr)(struct net_device *dev);
1127 * Test if Media Access Control address is valid for the device.
1128 *
1129 * int (*ndo_do_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd);
1130 * Old-style ioctl entry point. This is used internally by the
1131 * ieee802154 subsystem but is no longer called by the device
1132 * ioctl handler.
1133 *
1134 * int (*ndo_siocbond)(struct net_device *dev, struct ifreq *ifr, int cmd);
1135 * Used by the bonding driver for its device specific ioctls:
1136 * SIOCBONDENSLAVE, SIOCBONDRELEASE, SIOCBONDSETHWADDR, SIOCBONDCHANGEACTIVE,
1137 * SIOCBONDSLAVEINFOQUERY, and SIOCBONDINFOQUERY
1138 *
1139 * * int (*ndo_eth_ioctl)(struct net_device *dev, struct ifreq *ifr, int cmd);
1140 * Called for ethernet specific ioctls: SIOCGMIIPHY, SIOCGMIIREG,
1141 * SIOCSMIIREG, SIOCSHWTSTAMP and SIOCGHWTSTAMP.
1142 *
1143 * int (*ndo_set_config)(struct net_device *dev, struct ifmap *map);
1144 * Used to set network devices bus interface parameters. This interface
1145 * is retained for legacy reasons; new devices should use the bus
1146 * interface (PCI) for low level management.
1147 *
1148 * int (*ndo_change_mtu)(struct net_device *dev, int new_mtu);
1149 * Called when a user wants to change the Maximum Transfer Unit
1150 * of a device.
1151 *
1152 * void (*ndo_tx_timeout)(struct net_device *dev, unsigned int txqueue);
1153 * Callback used when the transmitter has not made any progress
1154 * for dev->watchdog ticks.
1155 *
1156 * void (*ndo_get_stats64)(struct net_device *dev,
1157 * struct rtnl_link_stats64 *storage);
1158 * struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
1159 * Called when a user wants to get the network device usage
1160 * statistics. Drivers must do one of the following:
1161 * 1. Define @ndo_get_stats64 to fill in a zero-initialised
1162 * rtnl_link_stats64 structure passed by the caller.
1163 * 2. Define @ndo_get_stats to update a net_device_stats structure
1164 * (which should normally be dev->stats) and return a pointer to
1165 * it. The structure may be changed asynchronously only if each
1166 * field is written atomically.
1167 * 3. Update dev->stats asynchronously and atomically, and define
1168 * neither operation.
1169 *
1170 * bool (*ndo_has_offload_stats)(const struct net_device *dev, int attr_id)
1171 * Return true if this device supports offload stats of this attr_id.
1172 *
1173 * int (*ndo_get_offload_stats)(int attr_id, const struct net_device *dev,
1174 * void *attr_data)
1175 * Get statistics for offload operations by attr_id. Write it into the
1176 * attr_data pointer.
1177 *
1178 * int (*ndo_vlan_rx_add_vid)(struct net_device *dev, __be16 proto, u16 vid);
1179 * If device supports VLAN filtering this function is called when a
1180 * VLAN id is registered.
1181 *
1182 * int (*ndo_vlan_rx_kill_vid)(struct net_device *dev, __be16 proto, u16 vid);
1183 * If device supports VLAN filtering this function is called when a
1184 * VLAN id is unregistered.
1185 *
1186 * void (*ndo_poll_controller)(struct net_device *dev);
1187 *
1188 * SR-IOV management functions.
1189 * int (*ndo_set_vf_mac)(struct net_device *dev, int vf, u8* mac);
1190 * int (*ndo_set_vf_vlan)(struct net_device *dev, int vf, u16 vlan,
1191 * u8 qos, __be16 proto);
1192 * int (*ndo_set_vf_rate)(struct net_device *dev, int vf, int min_tx_rate,
1193 * int max_tx_rate);
1194 * int (*ndo_set_vf_spoofchk)(struct net_device *dev, int vf, bool setting);
1195 * int (*ndo_set_vf_trust)(struct net_device *dev, int vf, bool setting);
1196 * int (*ndo_get_vf_config)(struct net_device *dev,
1197 * int vf, struct ifla_vf_info *ivf);
1198 * int (*ndo_set_vf_link_state)(struct net_device *dev, int vf, int link_state);
1199 * int (*ndo_set_vf_port)(struct net_device *dev, int vf,
1200 * struct nlattr *port[]);
1201 *
1202 * Enable or disable the VF ability to query its RSS Redirection Table and
1203 * Hash Key. This is needed since on some devices VF share this information
1204 * with PF and querying it may introduce a theoretical security risk.
1205 * int (*ndo_set_vf_rss_query_en)(struct net_device *dev, int vf, bool setting);
1206 * int (*ndo_get_vf_port)(struct net_device *dev, int vf, struct sk_buff *skb);
1207 * int (*ndo_setup_tc)(struct net_device *dev, enum tc_setup_type type,
1208 * void *type_data);
1209 * Called to setup any 'tc' scheduler, classifier or action on @dev.
1210 * This is always called from the stack with the rtnl lock held and netif
1211 * tx queues stopped. This allows the netdevice to perform queue
1212 * management safely.
1213 *
1214 * Fiber Channel over Ethernet (FCoE) offload functions.
1215 * int (*ndo_fcoe_enable)(struct net_device *dev);
1216 * Called when the FCoE protocol stack wants to start using LLD for FCoE
1217 * so the underlying device can perform whatever needed configuration or
1218 * initialization to support acceleration of FCoE traffic.
1219 *
1220 * int (*ndo_fcoe_disable)(struct net_device *dev);
1221 * Called when the FCoE protocol stack wants to stop using LLD for FCoE
1222 * so the underlying device can perform whatever needed clean-ups to
1223 * stop supporting acceleration of FCoE traffic.
1224 *
1225 * int (*ndo_fcoe_ddp_setup)(struct net_device *dev, u16 xid,
1226 * struct scatterlist *sgl, unsigned int sgc);
1227 * Called when the FCoE Initiator wants to initialize an I/O that
1228 * is a possible candidate for Direct Data Placement (DDP). The LLD can
1229 * perform necessary setup and returns 1 to indicate the device is set up
1230 * successfully to perform DDP on this I/O, otherwise this returns 0.
1231 *
1232 * int (*ndo_fcoe_ddp_done)(struct net_device *dev, u16 xid);
1233 * Called when the FCoE Initiator/Target is done with the DDPed I/O as
1234 * indicated by the FC exchange id 'xid', so the underlying device can
1235 * clean up and reuse resources for later DDP requests.
1236 *
1237 * int (*ndo_fcoe_ddp_target)(struct net_device *dev, u16 xid,
1238 * struct scatterlist *sgl, unsigned int sgc);
1239 * Called when the FCoE Target wants to initialize an I/O that
1240 * is a possible candidate for Direct Data Placement (DDP). The LLD can
1241 * perform necessary setup and returns 1 to indicate the device is set up
1242 * successfully to perform DDP on this I/O, otherwise this returns 0.
1243 *
1244 * int (*ndo_fcoe_get_hbainfo)(struct net_device *dev,
1245 * struct netdev_fcoe_hbainfo *hbainfo);
1246 * Called when the FCoE Protocol stack wants information on the underlying
1247 * device. This information is utilized by the FCoE protocol stack to
1248 * register attributes with Fiber Channel management service as per the
1249 * FC-GS Fabric Device Management Information(FDMI) specification.
1250 *
1251 * int (*ndo_fcoe_get_wwn)(struct net_device *dev, u64 *wwn, int type);
1252 * Called when the underlying device wants to override default World Wide
1253 * Name (WWN) generation mechanism in FCoE protocol stack to pass its own
1254 * World Wide Port Name (WWPN) or World Wide Node Name (WWNN) to the FCoE
1255 * protocol stack to use.
1256 *
1257 * RFS acceleration.
1258 * int (*ndo_rx_flow_steer)(struct net_device *dev, const struct sk_buff *skb,
1259 * u16 rxq_index, u32 flow_id);
1260 * Set hardware filter for RFS. rxq_index is the target queue index;
1261 * flow_id is a flow ID to be passed to rps_may_expire_flow() later.
1262 * Return the filter ID on success, or a negative error code.
1263 *
1264 * Slave management functions (for bridge, bonding, etc).
1265 * int (*ndo_add_slave)(struct net_device *dev, struct net_device *slave_dev);
1266 * Called to make another netdev an underling.
1267 *
1268 * int (*ndo_del_slave)(struct net_device *dev, struct net_device *slave_dev);
1269 * Called to release previously enslaved netdev.
1270 *
1271 * struct net_device *(*ndo_get_xmit_slave)(struct net_device *dev,
1272 * struct sk_buff *skb,
1273 * bool all_slaves);
1274 * Get the xmit slave of master device. If all_slaves is true, function
1275 * assume all the slaves can transmit.
1276 *
1277 * Feature/offload setting functions.
1278 * netdev_features_t (*ndo_fix_features)(struct net_device *dev,
1279 * netdev_features_t features);
1280 * Adjusts the requested feature flags according to device-specific
1281 * constraints, and returns the resulting flags. Must not modify
1282 * the device state.
1283 *
1284 * int (*ndo_set_features)(struct net_device *dev, netdev_features_t features);
1285 * Called to update device configuration to new features. Passed
1286 * feature set might be less than what was returned by ndo_fix_features()).
1287 * Must return >0 or -errno if it changed dev->features itself.
1288 *
1289 * int (*ndo_fdb_add)(struct ndmsg *ndm, struct nlattr *tb[],
1290 * struct net_device *dev,
1291 * const unsigned char *addr, u16 vid, u16 flags,
1292 * bool *notified, struct netlink_ext_ack *extack);
1293 * Adds an FDB entry to dev for addr.
1294 * Callee shall set *notified to true if it sent any appropriate
1295 * notification(s). Otherwise core will send a generic one.
1296 * int (*ndo_fdb_del)(struct ndmsg *ndm, struct nlattr *tb[],
1297 * struct net_device *dev,
1298 * const unsigned char *addr, u16 vid
1299 * bool *notified, struct netlink_ext_ack *extack);
1300 * Deletes the FDB entry from dev corresponding to addr.
1301 * Callee shall set *notified to true if it sent any appropriate
1302 * notification(s). Otherwise core will send a generic one.
1303 * int (*ndo_fdb_del_bulk)(struct nlmsghdr *nlh, struct net_device *dev,
1304 * struct netlink_ext_ack *extack);
1305 * int (*ndo_fdb_dump)(struct sk_buff *skb, struct netlink_callback *cb,
1306 * struct net_device *dev, struct net_device *filter_dev,
1307 * int *idx)
1308 * Used to add FDB entries to dump requests. Implementers should add
1309 * entries to skb and update idx with the number of entries.
1310 *
1311 * int (*ndo_mdb_add)(struct net_device *dev, struct nlattr *tb[],
1312 * u16 nlmsg_flags, struct netlink_ext_ack *extack);
1313 * Adds an MDB entry to dev.
1314 * int (*ndo_mdb_del)(struct net_device *dev, struct nlattr *tb[],
1315 * struct netlink_ext_ack *extack);
1316 * Deletes the MDB entry from dev.
1317 * int (*ndo_mdb_del_bulk)(struct net_device *dev, struct nlattr *tb[],
1318 * struct netlink_ext_ack *extack);
1319 * Bulk deletes MDB entries from dev.
1320 * int (*ndo_mdb_dump)(struct net_device *dev, struct sk_buff *skb,
1321 * struct netlink_callback *cb);
1322 * Dumps MDB entries from dev. The first argument (marker) in the netlink
1323 * callback is used by core rtnetlink code.
1324 *
1325 * int (*ndo_bridge_setlink)(struct net_device *dev, struct nlmsghdr *nlh,
1326 * u16 flags, struct netlink_ext_ack *extack)
1327 * int (*ndo_bridge_getlink)(struct sk_buff *skb, u32 pid, u32 seq,
1328 * struct net_device *dev, u32 filter_mask,
1329 * int nlflags)
1330 * int (*ndo_bridge_dellink)(struct net_device *dev, struct nlmsghdr *nlh,
1331 * u16 flags);
1332 *
1333 * int (*ndo_change_carrier)(struct net_device *dev, bool new_carrier);
1334 * Called to change device carrier. Soft-devices (like dummy, team, etc)
1335 * which do not represent real hardware may define this to allow their
1336 * userspace components to manage their virtual carrier state. Devices
1337 * that determine carrier state from physical hardware properties (eg
1338 * network cables) or protocol-dependent mechanisms (eg
1339 * USB_CDC_NOTIFY_NETWORK_CONNECTION) should NOT implement this function.
1340 *
1341 * int (*ndo_get_phys_port_id)(struct net_device *dev,
1342 * struct netdev_phys_item_id *ppid);
1343 * Called to get ID of physical port of this device. If driver does
1344 * not implement this, it is assumed that the hw is not able to have
1345 * multiple net devices on single physical port.
1346 *
1347 * int (*ndo_get_port_parent_id)(struct net_device *dev,
1348 * struct netdev_phys_item_id *ppid)
1349 * Called to get the parent ID of the physical port of this device.
1350 *
1351 * void* (*ndo_dfwd_add_station)(struct net_device *pdev,
1352 * struct net_device *dev)
1353 * Called by upper layer devices to accelerate switching or other
1354 * station functionality into hardware. 'pdev is the lowerdev
1355 * to use for the offload and 'dev' is the net device that will
1356 * back the offload. Returns a pointer to the private structure
1357 * the upper layer will maintain.
1358 * void (*ndo_dfwd_del_station)(struct net_device *pdev, void *priv)
1359 * Called by upper layer device to delete the station created
1360 * by 'ndo_dfwd_add_station'. 'pdev' is the net device backing
1361 * the station and priv is the structure returned by the add
1362 * operation.
1363 * int (*ndo_set_tx_maxrate)(struct net_device *dev,
1364 * int queue_index, u32 maxrate);
1365 * Called when a user wants to set a max-rate limitation of specific
1366 * TX queue.
1367 * int (*ndo_get_iflink)(const struct net_device *dev);
1368 * Called to get the iflink value of this device.
1369 * int (*ndo_fill_metadata_dst)(struct net_device *dev, struct sk_buff *skb);
1370 * This function is used to get egress tunnel information for given skb.
1371 * This is useful for retrieving outer tunnel header parameters while
1372 * sampling packet.
1373 * void (*ndo_set_rx_headroom)(struct net_device *dev, int needed_headroom);
1374 * This function is used to specify the headroom that the skb must
1375 * consider when allocation skb during packet reception. Setting
1376 * appropriate rx headroom value allows avoiding skb head copy on
1377 * forward. Setting a negative value resets the rx headroom to the
1378 * default value.
1379 * int (*ndo_bpf)(struct net_device *dev, struct netdev_bpf *bpf);
1380 * This function is used to set or query state related to XDP on the
1381 * netdevice and manage BPF offload. See definition of
1382 * enum bpf_netdev_command for details.
1383 * int (*ndo_xdp_xmit)(struct net_device *dev, int n, struct xdp_frame **xdp,
1384 * u32 flags);
1385 * This function is used to submit @n XDP packets for transmit on a
1386 * netdevice. Returns number of frames successfully transmitted, frames
1387 * that got dropped are freed/returned via xdp_return_frame().
1388 * Returns negative number, means general error invoking ndo, meaning
1389 * no frames were xmit'ed and core-caller will free all frames.
1390 * struct net_device *(*ndo_xdp_get_xmit_slave)(struct net_device *dev,
1391 * struct xdp_buff *xdp);
1392 * Get the xmit slave of master device based on the xdp_buff.
1393 * int (*ndo_xsk_wakeup)(struct net_device *dev, u32 queue_id, u32 flags);
1394 * This function is used to wake up the softirq, ksoftirqd or kthread
1395 * responsible for sending and/or receiving packets on a specific
1396 * queue id bound to an AF_XDP socket. The flags field specifies if
1397 * only RX, only Tx, or both should be woken up using the flags
1398 * XDP_WAKEUP_RX and XDP_WAKEUP_TX.
1399 * int (*ndo_tunnel_ctl)(struct net_device *dev, struct ip_tunnel_parm_kern *p,
1400 * int cmd);
1401 * Add, change, delete or get information on an IPv4 tunnel.
1402 * struct net_device *(*ndo_get_peer_dev)(struct net_device *dev);
1403 * If a device is paired with a peer device, return the peer instance.
1404 * The caller must be under RCU read context.
1405 * int (*ndo_fill_forward_path)(struct net_device_path_ctx *ctx, struct net_device_path *path);
1406 * Get the forwarding path to reach the real device from the HW destination address
1407 * ktime_t (*ndo_get_tstamp)(struct net_device *dev,
1408 * const struct skb_shared_hwtstamps *hwtstamps,
1409 * bool cycles);
1410 * Get hardware timestamp based on normal/adjustable time or free running
1411 * cycle counter. This function is required if physical clock supports a
1412 * free running cycle counter.
1413 *
1414 * int (*ndo_hwtstamp_get)(struct net_device *dev,
1415 * struct kernel_hwtstamp_config *kernel_config);
1416 * Get the currently configured hardware timestamping parameters for the
1417 * NIC device.
1418 *
1419 * int (*ndo_hwtstamp_set)(struct net_device *dev,
1420 * struct kernel_hwtstamp_config *kernel_config,
1421 * struct netlink_ext_ack *extack);
1422 * Change the hardware timestamping parameters for NIC device.
1423 */
1424struct net_device_ops {
1425 int (*ndo_init)(struct net_device *dev);
1426 void (*ndo_uninit)(struct net_device *dev);
1427 int (*ndo_open)(struct net_device *dev);
1428 int (*ndo_stop)(struct net_device *dev);
1429 netdev_tx_t (*ndo_start_xmit)(struct sk_buff *skb,
1430 struct net_device *dev);
1431 netdev_features_t (*ndo_features_check)(struct sk_buff *skb,
1432 struct net_device *dev,
1433 netdev_features_t features);
1434 u16 (*ndo_select_queue)(struct net_device *dev,
1435 struct sk_buff *skb,
1436 struct net_device *sb_dev);
1437 void (*ndo_change_rx_flags)(struct net_device *dev,
1438 int flags);
1439 void (*ndo_set_rx_mode)(struct net_device *dev);
1440 int (*ndo_set_mac_address)(struct net_device *dev,
1441 void *addr);
1442 int (*ndo_validate_addr)(struct net_device *dev);
1443 int (*ndo_do_ioctl)(struct net_device *dev,
1444 struct ifreq *ifr, int cmd);
1445 int (*ndo_eth_ioctl)(struct net_device *dev,
1446 struct ifreq *ifr, int cmd);
1447 int (*ndo_siocbond)(struct net_device *dev,
1448 struct ifreq *ifr, int cmd);
1449 int (*ndo_siocwandev)(struct net_device *dev,
1450 struct if_settings *ifs);
1451 int (*ndo_siocdevprivate)(struct net_device *dev,
1452 struct ifreq *ifr,
1453 void __user *data, int cmd);
1454 int (*ndo_set_config)(struct net_device *dev,
1455 struct ifmap *map);
1456 int (*ndo_change_mtu)(struct net_device *dev,
1457 int new_mtu);
1458 int (*ndo_neigh_setup)(struct net_device *dev,
1459 struct neigh_parms *);
1460 void (*ndo_tx_timeout) (struct net_device *dev,
1461 unsigned int txqueue);
1462
1463 void (*ndo_get_stats64)(struct net_device *dev,
1464 struct rtnl_link_stats64 *storage);
1465 bool (*ndo_has_offload_stats)(const struct net_device *dev, int attr_id);
1466 int (*ndo_get_offload_stats)(int attr_id,
1467 const struct net_device *dev,
1468 void *attr_data);
1469 struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);
1470
1471 int (*ndo_vlan_rx_add_vid)(struct net_device *dev,
1472 __be16 proto, u16 vid);
1473 int (*ndo_vlan_rx_kill_vid)(struct net_device *dev,
1474 __be16 proto, u16 vid);
1475#ifdef CONFIG_NET_POLL_CONTROLLER
1476 void (*ndo_poll_controller)(struct net_device *dev);
1477 int (*ndo_netpoll_setup)(struct net_device *dev);
1478 void (*ndo_netpoll_cleanup)(struct net_device *dev);
1479#endif
1480 int (*ndo_set_vf_mac)(struct net_device *dev,
1481 int queue, u8 *mac);
1482 int (*ndo_set_vf_vlan)(struct net_device *dev,
1483 int queue, u16 vlan,
1484 u8 qos, __be16 proto);
1485 int (*ndo_set_vf_rate)(struct net_device *dev,
1486 int vf, int min_tx_rate,
1487 int max_tx_rate);
1488 int (*ndo_set_vf_spoofchk)(struct net_device *dev,
1489 int vf, bool setting);
1490 int (*ndo_set_vf_trust)(struct net_device *dev,
1491 int vf, bool setting);
1492 int (*ndo_get_vf_config)(struct net_device *dev,
1493 int vf,
1494 struct ifla_vf_info *ivf);
1495 int (*ndo_set_vf_link_state)(struct net_device *dev,
1496 int vf, int link_state);
1497 int (*ndo_get_vf_stats)(struct net_device *dev,
1498 int vf,
1499 struct ifla_vf_stats
1500 *vf_stats);
1501 int (*ndo_set_vf_port)(struct net_device *dev,
1502 int vf,
1503 struct nlattr *port[]);
1504 int (*ndo_get_vf_port)(struct net_device *dev,
1505 int vf, struct sk_buff *skb);
1506 int (*ndo_get_vf_guid)(struct net_device *dev,
1507 int vf,
1508 struct ifla_vf_guid *node_guid,
1509 struct ifla_vf_guid *port_guid);
1510 int (*ndo_set_vf_guid)(struct net_device *dev,
1511 int vf, u64 guid,
1512 int guid_type);
1513 int (*ndo_set_vf_rss_query_en)(
1514 struct net_device *dev,
1515 int vf, bool setting);
1516 int (*ndo_setup_tc)(struct net_device *dev,
1517 enum tc_setup_type type,
1518 void *type_data);
1519#if IS_ENABLED(CONFIG_FCOE)
1520 int (*ndo_fcoe_enable)(struct net_device *dev);
1521 int (*ndo_fcoe_disable)(struct net_device *dev);
1522 int (*ndo_fcoe_ddp_setup)(struct net_device *dev,
1523 u16 xid,
1524 struct scatterlist *sgl,
1525 unsigned int sgc);
1526 int (*ndo_fcoe_ddp_done)(struct net_device *dev,
1527 u16 xid);
1528 int (*ndo_fcoe_ddp_target)(struct net_device *dev,
1529 u16 xid,
1530 struct scatterlist *sgl,
1531 unsigned int sgc);
1532 int (*ndo_fcoe_get_hbainfo)(struct net_device *dev,
1533 struct netdev_fcoe_hbainfo *hbainfo);
1534#endif
1535
1536#if IS_ENABLED(CONFIG_LIBFCOE)
1537#define NETDEV_FCOE_WWNN 0
1538#define NETDEV_FCOE_WWPN 1
1539 int (*ndo_fcoe_get_wwn)(struct net_device *dev,
1540 u64 *wwn, int type);
1541#endif
1542
1543#ifdef CONFIG_RFS_ACCEL
1544 int (*ndo_rx_flow_steer)(struct net_device *dev,
1545 const struct sk_buff *skb,
1546 u16 rxq_index,
1547 u32 flow_id);
1548#endif
1549 int (*ndo_add_slave)(struct net_device *dev,
1550 struct net_device *slave_dev,
1551 struct netlink_ext_ack *extack);
1552 int (*ndo_del_slave)(struct net_device *dev,
1553 struct net_device *slave_dev);
1554 struct net_device* (*ndo_get_xmit_slave)(struct net_device *dev,
1555 struct sk_buff *skb,
1556 bool all_slaves);
1557 struct net_device* (*ndo_sk_get_lower_dev)(struct net_device *dev,
1558 struct sock *sk);
1559 netdev_features_t (*ndo_fix_features)(struct net_device *dev,
1560 netdev_features_t features);
1561 int (*ndo_set_features)(struct net_device *dev,
1562 netdev_features_t features);
1563 int (*ndo_neigh_construct)(struct net_device *dev,
1564 struct neighbour *n);
1565 void (*ndo_neigh_destroy)(struct net_device *dev,
1566 struct neighbour *n);
1567
1568 int (*ndo_fdb_add)(struct ndmsg *ndm,
1569 struct nlattr *tb[],
1570 struct net_device *dev,
1571 const unsigned char *addr,
1572 u16 vid,
1573 u16 flags,
1574 bool *notified,
1575 struct netlink_ext_ack *extack);
1576 int (*ndo_fdb_del)(struct ndmsg *ndm,
1577 struct nlattr *tb[],
1578 struct net_device *dev,
1579 const unsigned char *addr,
1580 u16 vid,
1581 bool *notified,
1582 struct netlink_ext_ack *extack);
1583 int (*ndo_fdb_del_bulk)(struct nlmsghdr *nlh,
1584 struct net_device *dev,
1585 struct netlink_ext_ack *extack);
1586 int (*ndo_fdb_dump)(struct sk_buff *skb,
1587 struct netlink_callback *cb,
1588 struct net_device *dev,
1589 struct net_device *filter_dev,
1590 int *idx);
1591 int (*ndo_fdb_get)(struct sk_buff *skb,
1592 struct nlattr *tb[],
1593 struct net_device *dev,
1594 const unsigned char *addr,
1595 u16 vid, u32 portid, u32 seq,
1596 struct netlink_ext_ack *extack);
1597 int (*ndo_mdb_add)(struct net_device *dev,
1598 struct nlattr *tb[],
1599 u16 nlmsg_flags,
1600 struct netlink_ext_ack *extack);
1601 int (*ndo_mdb_del)(struct net_device *dev,
1602 struct nlattr *tb[],
1603 struct netlink_ext_ack *extack);
1604 int (*ndo_mdb_del_bulk)(struct net_device *dev,
1605 struct nlattr *tb[],
1606 struct netlink_ext_ack *extack);
1607 int (*ndo_mdb_dump)(struct net_device *dev,
1608 struct sk_buff *skb,
1609 struct netlink_callback *cb);
1610 int (*ndo_mdb_get)(struct net_device *dev,
1611 struct nlattr *tb[], u32 portid,
1612 u32 seq,
1613 struct netlink_ext_ack *extack);
1614 int (*ndo_bridge_setlink)(struct net_device *dev,
1615 struct nlmsghdr *nlh,
1616 u16 flags,
1617 struct netlink_ext_ack *extack);
1618 int (*ndo_bridge_getlink)(struct sk_buff *skb,
1619 u32 pid, u32 seq,
1620 struct net_device *dev,
1621 u32 filter_mask,
1622 int nlflags);
1623 int (*ndo_bridge_dellink)(struct net_device *dev,
1624 struct nlmsghdr *nlh,
1625 u16 flags);
1626 int (*ndo_change_carrier)(struct net_device *dev,
1627 bool new_carrier);
1628 int (*ndo_get_phys_port_id)(struct net_device *dev,
1629 struct netdev_phys_item_id *ppid);
1630 int (*ndo_get_port_parent_id)(struct net_device *dev,
1631 struct netdev_phys_item_id *ppid);
1632 int (*ndo_get_phys_port_name)(struct net_device *dev,
1633 char *name, size_t len);
1634 void* (*ndo_dfwd_add_station)(struct net_device *pdev,
1635 struct net_device *dev);
1636 void (*ndo_dfwd_del_station)(struct net_device *pdev,
1637 void *priv);
1638
1639 int (*ndo_set_tx_maxrate)(struct net_device *dev,
1640 int queue_index,
1641 u32 maxrate);
1642 int (*ndo_get_iflink)(const struct net_device *dev);
1643 int (*ndo_fill_metadata_dst)(struct net_device *dev,
1644 struct sk_buff *skb);
1645 void (*ndo_set_rx_headroom)(struct net_device *dev,
1646 int needed_headroom);
1647 int (*ndo_bpf)(struct net_device *dev,
1648 struct netdev_bpf *bpf);
1649 int (*ndo_xdp_xmit)(struct net_device *dev, int n,
1650 struct xdp_frame **xdp,
1651 u32 flags);
1652 struct net_device * (*ndo_xdp_get_xmit_slave)(struct net_device *dev,
1653 struct xdp_buff *xdp);
1654 int (*ndo_xsk_wakeup)(struct net_device *dev,
1655 u32 queue_id, u32 flags);
1656 int (*ndo_tunnel_ctl)(struct net_device *dev,
1657 struct ip_tunnel_parm_kern *p,
1658 int cmd);
1659 struct net_device * (*ndo_get_peer_dev)(struct net_device *dev);
1660 int (*ndo_fill_forward_path)(struct net_device_path_ctx *ctx,
1661 struct net_device_path *path);
1662 ktime_t (*ndo_get_tstamp)(struct net_device *dev,
1663 const struct skb_shared_hwtstamps *hwtstamps,
1664 bool cycles);
1665 int (*ndo_hwtstamp_get)(struct net_device *dev,
1666 struct kernel_hwtstamp_config *kernel_config);
1667 int (*ndo_hwtstamp_set)(struct net_device *dev,
1668 struct kernel_hwtstamp_config *kernel_config,
1669 struct netlink_ext_ack *extack);
1670
1671#if IS_ENABLED(CONFIG_NET_SHAPER)
1672 /**
1673 * @net_shaper_ops: Device shaping offload operations
1674 * see include/net/net_shapers.h
1675 */
1676 const struct net_shaper_ops *net_shaper_ops;
1677#endif
1678};
1679
1680/**
1681 * enum netdev_priv_flags - &struct net_device priv_flags
1682 *
1683 * These are the &struct net_device, they are only set internally
1684 * by drivers and used in the kernel. These flags are invisible to
1685 * userspace; this means that the order of these flags can change
1686 * during any kernel release.
1687 *
1688 * You should add bitfield booleans after either net_device::priv_flags
1689 * (hotpath) or ::threaded (slowpath) instead of extending these flags.
1690 *
1691 * @IFF_802_1Q_VLAN: 802.1Q VLAN device
1692 * @IFF_EBRIDGE: Ethernet bridging device
1693 * @IFF_BONDING: bonding master or slave
1694 * @IFF_ISATAP: ISATAP interface (RFC4214)
1695 * @IFF_WAN_HDLC: WAN HDLC device
1696 * @IFF_XMIT_DST_RELEASE: dev_hard_start_xmit() is allowed to
1697 * release skb->dst
1698 * @IFF_DONT_BRIDGE: disallow bridging this ether dev
1699 * @IFF_DISABLE_NETPOLL: disable netpoll at run-time
1700 * @IFF_MACVLAN_PORT: device used as macvlan port
1701 * @IFF_BRIDGE_PORT: device used as bridge port
1702 * @IFF_OVS_DATAPATH: device used as Open vSwitch datapath port
1703 * @IFF_TX_SKB_SHARING: The interface supports sharing skbs on transmit
1704 * @IFF_UNICAST_FLT: Supports unicast filtering
1705 * @IFF_TEAM_PORT: device used as team port
1706 * @IFF_SUPP_NOFCS: device supports sending custom FCS
1707 * @IFF_LIVE_ADDR_CHANGE: device supports hardware address
1708 * change when it's running
1709 * @IFF_MACVLAN: Macvlan device
1710 * @IFF_XMIT_DST_RELEASE_PERM: IFF_XMIT_DST_RELEASE not taking into account
1711 * underlying stacked devices
1712 * @IFF_L3MDEV_MASTER: device is an L3 master device
1713 * @IFF_NO_QUEUE: device can run without qdisc attached
1714 * @IFF_OPENVSWITCH: device is a Open vSwitch master
1715 * @IFF_L3MDEV_SLAVE: device is enslaved to an L3 master device
1716 * @IFF_TEAM: device is a team device
1717 * @IFF_RXFH_CONFIGURED: device has had Rx Flow indirection table configured
1718 * @IFF_PHONY_HEADROOM: the headroom value is controlled by an external
1719 * entity (i.e. the master device for bridged veth)
1720 * @IFF_MACSEC: device is a MACsec device
1721 * @IFF_NO_RX_HANDLER: device doesn't support the rx_handler hook
1722 * @IFF_FAILOVER: device is a failover master device
1723 * @IFF_FAILOVER_SLAVE: device is lower dev of a failover master device
1724 * @IFF_L3MDEV_RX_HANDLER: only invoke the rx handler of L3 master device
1725 * @IFF_NO_ADDRCONF: prevent ipv6 addrconf
1726 * @IFF_TX_SKB_NO_LINEAR: device/driver is capable of xmitting frames with
1727 * skb_headlen(skb) == 0 (data starts from frag0)
1728 */
1729enum netdev_priv_flags {
1730 IFF_802_1Q_VLAN = 1<<0,
1731 IFF_EBRIDGE = 1<<1,
1732 IFF_BONDING = 1<<2,
1733 IFF_ISATAP = 1<<3,
1734 IFF_WAN_HDLC = 1<<4,
1735 IFF_XMIT_DST_RELEASE = 1<<5,
1736 IFF_DONT_BRIDGE = 1<<6,
1737 IFF_DISABLE_NETPOLL = 1<<7,
1738 IFF_MACVLAN_PORT = 1<<8,
1739 IFF_BRIDGE_PORT = 1<<9,
1740 IFF_OVS_DATAPATH = 1<<10,
1741 IFF_TX_SKB_SHARING = 1<<11,
1742 IFF_UNICAST_FLT = 1<<12,
1743 IFF_TEAM_PORT = 1<<13,
1744 IFF_SUPP_NOFCS = 1<<14,
1745 IFF_LIVE_ADDR_CHANGE = 1<<15,
1746 IFF_MACVLAN = 1<<16,
1747 IFF_XMIT_DST_RELEASE_PERM = 1<<17,
1748 IFF_L3MDEV_MASTER = 1<<18,
1749 IFF_NO_QUEUE = 1<<19,
1750 IFF_OPENVSWITCH = 1<<20,
1751 IFF_L3MDEV_SLAVE = 1<<21,
1752 IFF_TEAM = 1<<22,
1753 IFF_RXFH_CONFIGURED = 1<<23,
1754 IFF_PHONY_HEADROOM = 1<<24,
1755 IFF_MACSEC = 1<<25,
1756 IFF_NO_RX_HANDLER = 1<<26,
1757 IFF_FAILOVER = 1<<27,
1758 IFF_FAILOVER_SLAVE = 1<<28,
1759 IFF_L3MDEV_RX_HANDLER = 1<<29,
1760 IFF_NO_ADDRCONF = BIT_ULL(30),
1761 IFF_TX_SKB_NO_LINEAR = BIT_ULL(31),
1762};
1763
1764/* Specifies the type of the struct net_device::ml_priv pointer */
1765enum netdev_ml_priv_type {
1766 ML_PRIV_NONE,
1767 ML_PRIV_CAN,
1768};
1769
1770enum netdev_stat_type {
1771 NETDEV_PCPU_STAT_NONE,
1772 NETDEV_PCPU_STAT_LSTATS, /* struct pcpu_lstats */
1773 NETDEV_PCPU_STAT_TSTATS, /* struct pcpu_sw_netstats */
1774 NETDEV_PCPU_STAT_DSTATS, /* struct pcpu_dstats */
1775};
1776
1777enum netdev_reg_state {
1778 NETREG_UNINITIALIZED = 0,
1779 NETREG_REGISTERED, /* completed register_netdevice */
1780 NETREG_UNREGISTERING, /* called unregister_netdevice */
1781 NETREG_UNREGISTERED, /* completed unregister todo */
1782 NETREG_RELEASED, /* called free_netdev */
1783 NETREG_DUMMY, /* dummy device for NAPI poll */
1784};
1785
1786/**
1787 * struct net_device - The DEVICE structure.
1788 *
1789 * Actually, this whole structure is a big mistake. It mixes I/O
1790 * data with strictly "high-level" data, and it has to know about
1791 * almost every data structure used in the INET module.
1792 *
1793 * @priv_flags: flags invisible to userspace defined as bits, see
1794 * enum netdev_priv_flags for the definitions
1795 * @lltx: device supports lockless Tx. Deprecated for real HW
1796 * drivers. Mainly used by logical interfaces, such as
1797 * bonding and tunnels
1798 * @netmem_tx: device support netmem_tx.
1799 *
1800 * @name: This is the first field of the "visible" part of this structure
1801 * (i.e. as seen by users in the "Space.c" file). It is the name
1802 * of the interface.
1803 *
1804 * @name_node: Name hashlist node
1805 * @ifalias: SNMP alias
1806 * @mem_end: Shared memory end
1807 * @mem_start: Shared memory start
1808 * @base_addr: Device I/O address
1809 * @irq: Device IRQ number
1810 *
1811 * @state: Generic network queuing layer state, see netdev_state_t
1812 * @dev_list: The global list of network devices
1813 * @napi_list: List entry used for polling NAPI devices
1814 * @unreg_list: List entry when we are unregistering the
1815 * device; see the function unregister_netdev
1816 * @close_list: List entry used when we are closing the device
1817 * @ptype_all: Device-specific packet handlers for all protocols
1818 * @ptype_specific: Device-specific, protocol-specific packet handlers
1819 *
1820 * @adj_list: Directly linked devices, like slaves for bonding
1821 * @features: Currently active device features
1822 * @hw_features: User-changeable features
1823 *
1824 * @wanted_features: User-requested features
1825 * @vlan_features: Mask of features inheritable by VLAN devices
1826 *
1827 * @hw_enc_features: Mask of features inherited by encapsulating devices
1828 * This field indicates what encapsulation
1829 * offloads the hardware is capable of doing,
1830 * and drivers will need to set them appropriately.
1831 *
1832 * @mpls_features: Mask of features inheritable by MPLS
1833 * @gso_partial_features: value(s) from NETIF_F_GSO\*
1834 *
1835 * @ifindex: interface index
1836 * @group: The group the device belongs to
1837 *
1838 * @stats: Statistics struct, which was left as a legacy, use
1839 * rtnl_link_stats64 instead
1840 *
1841 * @core_stats: core networking counters,
1842 * do not use this in drivers
1843 * @carrier_up_count: Number of times the carrier has been up
1844 * @carrier_down_count: Number of times the carrier has been down
1845 *
1846 * @wireless_handlers: List of functions to handle Wireless Extensions,
1847 * instead of ioctl,
1848 * see <net/iw_handler.h> for details.
1849 *
1850 * @netdev_ops: Includes several pointers to callbacks,
1851 * if one wants to override the ndo_*() functions
1852 * @xdp_metadata_ops: Includes pointers to XDP metadata callbacks.
1853 * @xsk_tx_metadata_ops: Includes pointers to AF_XDP TX metadata callbacks.
1854 * @ethtool_ops: Management operations
1855 * @l3mdev_ops: Layer 3 master device operations
1856 * @ndisc_ops: Includes callbacks for different IPv6 neighbour
1857 * discovery handling. Necessary for e.g. 6LoWPAN.
1858 * @xfrmdev_ops: Transformation offload operations
1859 * @tlsdev_ops: Transport Layer Security offload operations
1860 * @header_ops: Includes callbacks for creating,parsing,caching,etc
1861 * of Layer 2 headers.
1862 *
1863 * @flags: Interface flags (a la BSD)
1864 * @xdp_features: XDP capability supported by the device
1865 * @gflags: Global flags ( kept as legacy )
1866 * @priv_len: Size of the ->priv flexible array
1867 * @priv: Flexible array containing private data
1868 * @operstate: RFC2863 operstate
1869 * @link_mode: Mapping policy to operstate
1870 * @if_port: Selectable AUI, TP, ...
1871 * @dma: DMA channel
1872 * @mtu: Interface MTU value
1873 * @min_mtu: Interface Minimum MTU value
1874 * @max_mtu: Interface Maximum MTU value
1875 * @type: Interface hardware type
1876 * @hard_header_len: Maximum hardware header length.
1877 * @min_header_len: Minimum hardware header length
1878 *
1879 * @needed_headroom: Extra headroom the hardware may need, but not in all
1880 * cases can this be guaranteed
1881 * @needed_tailroom: Extra tailroom the hardware may need, but not in all
1882 * cases can this be guaranteed. Some cases also use
1883 * LL_MAX_HEADER instead to allocate the skb
1884 *
1885 * interface address info:
1886 *
1887 * @perm_addr: Permanent hw address
1888 * @addr_assign_type: Hw address assignment type
1889 * @addr_len: Hardware address length
1890 * @upper_level: Maximum depth level of upper devices.
1891 * @lower_level: Maximum depth level of lower devices.
1892 * @threaded: napi threaded state.
1893 * @neigh_priv_len: Used in neigh_alloc()
1894 * @dev_id: Used to differentiate devices that share
1895 * the same link layer address
1896 * @dev_port: Used to differentiate devices that share
1897 * the same function
1898 * @addr_list_lock: XXX: need comments on this one
1899 * @name_assign_type: network interface name assignment type
1900 * @uc_promisc: Counter that indicates promiscuous mode
1901 * has been enabled due to the need to listen to
1902 * additional unicast addresses in a device that
1903 * does not implement ndo_set_rx_mode()
1904 * @uc: unicast mac addresses
1905 * @mc: multicast mac addresses
1906 * @dev_addrs: list of device hw addresses
1907 * @queues_kset: Group of all Kobjects in the Tx and RX queues
1908 * @promiscuity: Number of times the NIC is told to work in
1909 * promiscuous mode; if it becomes 0 the NIC will
1910 * exit promiscuous mode
1911 * @allmulti: Counter, enables or disables allmulticast mode
1912 *
1913 * @vlan_info: VLAN info
1914 * @dsa_ptr: dsa specific data
1915 * @tipc_ptr: TIPC specific data
1916 * @atalk_ptr: AppleTalk link
1917 * @ip_ptr: IPv4 specific data
1918 * @ip6_ptr: IPv6 specific data
1919 * @ax25_ptr: AX.25 specific data
1920 * @ieee80211_ptr: IEEE 802.11 specific data, assign before registering
1921 * @ieee802154_ptr: IEEE 802.15.4 low-rate Wireless Personal Area Network
1922 * device struct
1923 * @mpls_ptr: mpls_dev struct pointer
1924 * @mctp_ptr: MCTP specific data
1925 * @psp_dev: PSP crypto device registered for this netdev
1926 *
1927 * @dev_addr: Hw address (before bcast,
1928 * because most packets are unicast)
1929 *
1930 * @_rx: Array of RX queues
1931 * @num_rx_queues: Number of RX queues
1932 * allocated at register_netdev() time
1933 * @real_num_rx_queues: Number of RX queues currently active in device
1934 * @xdp_prog: XDP sockets filter program pointer
1935 *
1936 * @rx_handler: handler for received packets
1937 * @rx_handler_data: XXX: need comments on this one
1938 * @tcx_ingress: BPF & clsact qdisc specific data for ingress processing
1939 * @ingress_queue: XXX: need comments on this one
1940 * @nf_hooks_ingress: netfilter hooks executed for ingress packets
1941 * @broadcast: hw bcast address
1942 *
1943 * @rx_cpu_rmap: CPU reverse-mapping for RX completion interrupts,
1944 * indexed by RX queue number. Assigned by driver.
1945 * This must only be set if the ndo_rx_flow_steer
1946 * operation is defined
1947 * @index_hlist: Device index hash chain
1948 *
1949 * @_tx: Array of TX queues
1950 * @num_tx_queues: Number of TX queues allocated at alloc_netdev_mq() time
1951 * @real_num_tx_queues: Number of TX queues currently active in device
1952 * @qdisc: Root qdisc from userspace point of view
1953 * @tx_queue_len: Max frames per queue allowed
1954 * @tx_global_lock: XXX: need comments on this one
1955 * @xdp_bulkq: XDP device bulk queue
1956 * @xps_maps: all CPUs/RXQs maps for XPS device
1957 *
1958 * @xps_maps: XXX: need comments on this one
1959 * @tcx_egress: BPF & clsact qdisc specific data for egress processing
1960 * @nf_hooks_egress: netfilter hooks executed for egress packets
1961 * @qdisc_hash: qdisc hash table
1962 * @watchdog_timeo: Represents the timeout that is used by
1963 * the watchdog (see dev_watchdog())
1964 * @watchdog_timer: List of timers
1965 *
1966 * @proto_down_reason: reason a netdev interface is held down
1967 * @pcpu_refcnt: Number of references to this device
1968 * @dev_refcnt: Number of references to this device
1969 * @refcnt_tracker: Tracker directory for tracked references to this device
1970 * @todo_list: Delayed register/unregister
1971 * @link_watch_list: XXX: need comments on this one
1972 *
1973 * @reg_state: Register/unregister state machine
1974 * @dismantle: Device is going to be freed
1975 * @needs_free_netdev: Should unregister perform free_netdev?
1976 * @priv_destructor: Called from unregister
1977 * @npinfo: XXX: need comments on this one
1978 * @nd_net: Network namespace this network device is inside
1979 * protected by @lock
1980 *
1981 * @ml_priv: Mid-layer private
1982 * @ml_priv_type: Mid-layer private type
1983 *
1984 * @pcpu_stat_type: Type of device statistics which the core should
1985 * allocate/free: none, lstats, tstats, dstats. none
1986 * means the driver is handling statistics allocation/
1987 * freeing internally.
1988 * @lstats: Loopback statistics: packets, bytes
1989 * @tstats: Tunnel statistics: RX/TX packets, RX/TX bytes
1990 * @dstats: Dummy statistics: RX/TX/drop packets, RX/TX bytes
1991 *
1992 * @garp_port: GARP
1993 * @mrp_port: MRP
1994 *
1995 * @dm_private: Drop monitor private
1996 *
1997 * @dev: Class/net/name entry
1998 * @sysfs_groups: Space for optional device, statistics and wireless
1999 * sysfs groups
2000 *
2001 * @sysfs_rx_queue_group: Space for optional per-rx queue attributes
2002 * @rtnl_link_ops: Rtnl_link_ops
2003 * @stat_ops: Optional ops for queue-aware statistics
2004 * @queue_mgmt_ops: Optional ops for queue management
2005 *
2006 * @gso_max_size: Maximum size of generic segmentation offload
2007 * @tso_max_size: Device (as in HW) limit on the max TSO request size
2008 * @gso_max_segs: Maximum number of segments that can be passed to the
2009 * NIC for GSO
2010 * @tso_max_segs: Device (as in HW) limit on the max TSO segment count
2011 * @gso_ipv4_max_size: Maximum size of generic segmentation offload,
2012 * for IPv4.
2013 *
2014 * @dcbnl_ops: Data Center Bridging netlink ops
2015 * @num_tc: Number of traffic classes in the net device
2016 * @tc_to_txq: XXX: need comments on this one
2017 * @prio_tc_map: XXX: need comments on this one
2018 *
2019 * @fcoe_ddp_xid: Max exchange id for FCoE LRO by ddp
2020 *
2021 * @priomap: XXX: need comments on this one
2022 * @link_topo: Physical link topology tracking attached PHYs
2023 * @phydev: Physical device may attach itself
2024 * for hardware timestamping
2025 * @sfp_bus: attached &struct sfp_bus structure.
2026 *
2027 * @qdisc_tx_busylock: lockdep class annotating Qdisc->busylock spinlock
2028 *
2029 * @proto_down: protocol port state information can be sent to the
2030 * switch driver and used to set the phys state of the
2031 * switch port.
2032 *
2033 * @irq_affinity_auto: driver wants the core to store and re-assign the IRQ
2034 * affinity. Set by netif_enable_irq_affinity(), then
2035 * the driver must create a persistent napi by
2036 * netif_napi_add_config() and finally bind the napi to
2037 * IRQ (via netif_napi_set_irq()).
2038 *
2039 * @rx_cpu_rmap_auto: driver wants the core to manage the ARFS rmap.
2040 * Set by calling netif_enable_cpu_rmap().
2041 *
2042 * @see_all_hwtstamp_requests: device wants to see calls to
2043 * ndo_hwtstamp_set() for all timestamp requests
2044 * regardless of source, even if those aren't
2045 * HWTSTAMP_SOURCE_NETDEV
2046 * @change_proto_down: device supports setting carrier via IFLA_PROTO_DOWN
2047 * @netns_immutable: interface can't change network namespaces
2048 * @fcoe_mtu: device supports maximum FCoE MTU, 2158 bytes
2049 *
2050 * @net_notifier_list: List of per-net netdev notifier block
2051 * that follow this device when it is moved
2052 * to another network namespace.
2053 *
2054 * @macsec_ops: MACsec offloading ops
2055 *
2056 * @udp_tunnel_nic_info: static structure describing the UDP tunnel
2057 * offload capabilities of the device
2058 * @udp_tunnel_nic: UDP tunnel offload state
2059 * @ethtool: ethtool related state
2060 * @xdp_state: stores info on attached XDP BPF programs
2061 *
2062 * @nested_level: Used as a parameter of spin_lock_nested() of
2063 * dev->addr_list_lock.
2064 * @unlink_list: As netif_addr_lock() can be called recursively,
2065 * keep a list of interfaces to be deleted.
2066 * @gro_max_size: Maximum size of aggregated packet in generic
2067 * receive offload (GRO)
2068 * @gro_ipv4_max_size: Maximum size of aggregated packet in generic
2069 * receive offload (GRO), for IPv4.
2070 * @xdp_zc_max_segs: Maximum number of segments supported by AF_XDP
2071 * zero copy driver
2072 *
2073 * @dev_addr_shadow: Copy of @dev_addr to catch direct writes.
2074 * @linkwatch_dev_tracker: refcount tracker used by linkwatch.
2075 * @watchdog_dev_tracker: refcount tracker used by watchdog.
2076 * @dev_registered_tracker: tracker for reference held while
2077 * registered
2078 * @offload_xstats_l3: L3 HW stats for this netdevice.
2079 *
2080 * @devlink_port: Pointer to related devlink port structure.
2081 * Assigned by a driver before netdev registration using
2082 * SET_NETDEV_DEVLINK_PORT macro. This pointer is static
2083 * during the time netdevice is registered.
2084 *
2085 * @dpll_pin: Pointer to the SyncE source pin of a DPLL subsystem,
2086 * where the clock is recovered.
2087 *
2088 * @max_pacing_offload_horizon: max EDT offload horizon in nsec.
2089 * @napi_config: An array of napi_config structures containing per-NAPI
2090 * settings.
2091 * @num_napi_configs: number of allocated NAPI config structs,
2092 * always >= max(num_rx_queues, num_tx_queues).
2093 * @gro_flush_timeout: timeout for GRO layer in NAPI
2094 * @napi_defer_hard_irqs: If not zero, provides a counter that would
2095 * allow to avoid NIC hard IRQ, on busy queues.
2096 *
2097 * @neighbours: List heads pointing to this device's neighbours'
2098 * dev_list, one per address-family.
2099 * @hwprov: Tracks which PTP performs hardware packet time stamping.
2100 *
2101 * FIXME: cleanup struct net_device such that network protocol info
2102 * moves out.
2103 */
2104
2105struct net_device {
2106 /* Cacheline organization can be found documented in
2107 * Documentation/networking/net_cachelines/net_device.rst.
2108 * Please update the document when adding new fields.
2109 */
2110
2111 /* TX read-mostly hotpath */
2112 __cacheline_group_begin(net_device_read_tx);
2113 struct_group(priv_flags_fast,
2114 unsigned long priv_flags:32;
2115 unsigned long lltx:1;
2116 unsigned long netmem_tx:1;
2117 );
2118 const struct net_device_ops *netdev_ops;
2119 const struct header_ops *header_ops;
2120 struct netdev_queue *_tx;
2121 netdev_features_t gso_partial_features;
2122 unsigned int real_num_tx_queues;
2123 unsigned int gso_max_size;
2124 unsigned int gso_ipv4_max_size;
2125 u16 gso_max_segs;
2126 s16 num_tc;
2127 /* Note : dev->mtu is often read without holding a lock.
2128 * Writers usually hold RTNL.
2129 * It is recommended to use READ_ONCE() to annotate the reads,
2130 * and to use WRITE_ONCE() to annotate the writes.
2131 */
2132 unsigned int mtu;
2133 unsigned short needed_headroom;
2134 struct netdev_tc_txq tc_to_txq[TC_MAX_QUEUE];
2135#ifdef CONFIG_XPS
2136 struct xps_dev_maps __rcu *xps_maps[XPS_MAPS_MAX];
2137#endif
2138#ifdef CONFIG_NETFILTER_EGRESS
2139 struct nf_hook_entries __rcu *nf_hooks_egress;
2140#endif
2141#ifdef CONFIG_NET_XGRESS
2142 struct bpf_mprog_entry __rcu *tcx_egress;
2143#endif
2144 __cacheline_group_end(net_device_read_tx);
2145
2146 /* TXRX read-mostly hotpath */
2147 __cacheline_group_begin(net_device_read_txrx);
2148 union {
2149 struct pcpu_lstats __percpu *lstats;
2150 struct pcpu_sw_netstats __percpu *tstats;
2151 struct pcpu_dstats __percpu *dstats;
2152 };
2153 unsigned long state;
2154 unsigned int flags;
2155 unsigned short hard_header_len;
2156 netdev_features_t features;
2157 struct inet6_dev __rcu *ip6_ptr;
2158 __cacheline_group_end(net_device_read_txrx);
2159
2160 /* RX read-mostly hotpath */
2161 __cacheline_group_begin(net_device_read_rx);
2162 struct bpf_prog __rcu *xdp_prog;
2163 struct list_head ptype_specific;
2164 int ifindex;
2165 unsigned int real_num_rx_queues;
2166 struct netdev_rx_queue *_rx;
2167 unsigned int gro_max_size;
2168 unsigned int gro_ipv4_max_size;
2169 rx_handler_func_t __rcu *rx_handler;
2170 void __rcu *rx_handler_data;
2171 possible_net_t nd_net;
2172#ifdef CONFIG_NETPOLL
2173 struct netpoll_info __rcu *npinfo;
2174#endif
2175#ifdef CONFIG_NET_XGRESS
2176 struct bpf_mprog_entry __rcu *tcx_ingress;
2177#endif
2178 __cacheline_group_end(net_device_read_rx);
2179
2180 char name[IFNAMSIZ];
2181 struct netdev_name_node *name_node;
2182 struct dev_ifalias __rcu *ifalias;
2183 /*
2184 * I/O specific fields
2185 * FIXME: Merge these and struct ifmap into one
2186 */
2187 unsigned long mem_end;
2188 unsigned long mem_start;
2189 unsigned long base_addr;
2190
2191 /*
2192 * Some hardware also needs these fields (state,dev_list,
2193 * napi_list,unreg_list,close_list) but they are not
2194 * part of the usual set specified in Space.c.
2195 */
2196
2197
2198 struct list_head dev_list;
2199 struct list_head napi_list;
2200 struct list_head unreg_list;
2201 struct list_head close_list;
2202 struct list_head ptype_all;
2203
2204 struct {
2205 struct list_head upper;
2206 struct list_head lower;
2207 } adj_list;
2208
2209 /* Read-mostly cache-line for fast-path access */
2210 xdp_features_t xdp_features;
2211 const struct xdp_metadata_ops *xdp_metadata_ops;
2212 const struct xsk_tx_metadata_ops *xsk_tx_metadata_ops;
2213 unsigned short gflags;
2214
2215 unsigned short needed_tailroom;
2216
2217 netdev_features_t hw_features;
2218 netdev_features_t wanted_features;
2219 netdev_features_t vlan_features;
2220 netdev_features_t hw_enc_features;
2221 netdev_features_t mpls_features;
2222
2223 unsigned int min_mtu;
2224 unsigned int max_mtu;
2225 unsigned short type;
2226 unsigned char min_header_len;
2227 unsigned char name_assign_type;
2228
2229 int group;
2230
2231 struct net_device_stats stats; /* not used by modern drivers */
2232
2233 struct net_device_core_stats __percpu *core_stats;
2234
2235 /* Stats to monitor link on/off, flapping */
2236 atomic_t carrier_up_count;
2237 atomic_t carrier_down_count;
2238
2239#ifdef CONFIG_WIRELESS_EXT
2240 const struct iw_handler_def *wireless_handlers;
2241#endif
2242 const struct ethtool_ops *ethtool_ops;
2243#ifdef CONFIG_NET_L3_MASTER_DEV
2244 const struct l3mdev_ops *l3mdev_ops;
2245#endif
2246#if IS_ENABLED(CONFIG_IPV6)
2247 const struct ndisc_ops *ndisc_ops;
2248#endif
2249
2250#ifdef CONFIG_XFRM_OFFLOAD
2251 const struct xfrmdev_ops *xfrmdev_ops;
2252#endif
2253
2254#if IS_ENABLED(CONFIG_TLS_DEVICE)
2255 const struct tlsdev_ops *tlsdev_ops;
2256#endif
2257
2258 unsigned int operstate;
2259 unsigned char link_mode;
2260
2261 unsigned char if_port;
2262 unsigned char dma;
2263
2264 /* Interface address info. */
2265 unsigned char perm_addr[MAX_ADDR_LEN];
2266 unsigned char addr_assign_type;
2267 unsigned char addr_len;
2268 unsigned char upper_level;
2269 unsigned char lower_level;
2270 u8 threaded;
2271
2272 unsigned short neigh_priv_len;
2273 unsigned short dev_id;
2274 unsigned short dev_port;
2275 int irq;
2276 u32 priv_len;
2277
2278 spinlock_t addr_list_lock;
2279
2280 struct netdev_hw_addr_list uc;
2281 struct netdev_hw_addr_list mc;
2282 struct netdev_hw_addr_list dev_addrs;
2283
2284#ifdef CONFIG_SYSFS
2285 struct kset *queues_kset;
2286#endif
2287#ifdef CONFIG_LOCKDEP
2288 struct list_head unlink_list;
2289#endif
2290 unsigned int promiscuity;
2291 unsigned int allmulti;
2292 bool uc_promisc;
2293#ifdef CONFIG_LOCKDEP
2294 unsigned char nested_level;
2295#endif
2296
2297
2298 /* Protocol-specific pointers */
2299 struct in_device __rcu *ip_ptr;
2300 /** @fib_nh_head: nexthops associated with this netdev */
2301 struct hlist_head fib_nh_head;
2302
2303#if IS_ENABLED(CONFIG_VLAN_8021Q)
2304 struct vlan_info __rcu *vlan_info;
2305#endif
2306#if IS_ENABLED(CONFIG_NET_DSA)
2307 struct dsa_port *dsa_ptr;
2308#endif
2309#if IS_ENABLED(CONFIG_TIPC)
2310 struct tipc_bearer __rcu *tipc_ptr;
2311#endif
2312#if IS_ENABLED(CONFIG_ATALK)
2313 void *atalk_ptr;
2314#endif
2315#if IS_ENABLED(CONFIG_AX25)
2316 struct ax25_dev __rcu *ax25_ptr;
2317#endif
2318#if IS_ENABLED(CONFIG_CFG80211)
2319 struct wireless_dev *ieee80211_ptr;
2320#endif
2321#if IS_ENABLED(CONFIG_IEEE802154) || IS_ENABLED(CONFIG_6LOWPAN)
2322 struct wpan_dev *ieee802154_ptr;
2323#endif
2324#if IS_ENABLED(CONFIG_MPLS_ROUTING)
2325 struct mpls_dev __rcu *mpls_ptr;
2326#endif
2327#if IS_ENABLED(CONFIG_MCTP)
2328 struct mctp_dev __rcu *mctp_ptr;
2329#endif
2330#if IS_ENABLED(CONFIG_INET_PSP)
2331 struct psp_dev __rcu *psp_dev;
2332#endif
2333
2334/*
2335 * Cache lines mostly used on receive path (including eth_type_trans())
2336 */
2337 /* Interface address info used in eth_type_trans() */
2338 const unsigned char *dev_addr;
2339
2340 unsigned int num_rx_queues;
2341#define GRO_LEGACY_MAX_SIZE 65536u
2342/* TCP minimal MSS is 8 (TCP_MIN_GSO_SIZE),
2343 * and shinfo->gso_segs is a 16bit field.
2344 */
2345#define GRO_MAX_SIZE (8 * 65535u)
2346 unsigned int xdp_zc_max_segs;
2347 struct netdev_queue __rcu *ingress_queue;
2348#ifdef CONFIG_NETFILTER_INGRESS
2349 struct nf_hook_entries __rcu *nf_hooks_ingress;
2350#endif
2351
2352 unsigned char broadcast[MAX_ADDR_LEN];
2353#ifdef CONFIG_RFS_ACCEL
2354 struct cpu_rmap *rx_cpu_rmap;
2355#endif
2356 struct hlist_node index_hlist;
2357
2358/*
2359 * Cache lines mostly used on transmit path
2360 */
2361 unsigned int num_tx_queues;
2362 struct Qdisc __rcu *qdisc;
2363 unsigned int tx_queue_len;
2364 spinlock_t tx_global_lock;
2365
2366 struct xdp_dev_bulk_queue __percpu *xdp_bulkq;
2367
2368#ifdef CONFIG_NET_SCHED
2369 DECLARE_HASHTABLE (qdisc_hash, 4);
2370#endif
2371 /* These may be needed for future network-power-down code. */
2372 struct timer_list watchdog_timer;
2373 int watchdog_timeo;
2374
2375 u32 proto_down_reason;
2376
2377 struct list_head todo_list;
2378
2379#ifdef CONFIG_PCPU_DEV_REFCNT
2380 int __percpu *pcpu_refcnt;
2381#else
2382 refcount_t dev_refcnt;
2383#endif
2384 struct ref_tracker_dir refcnt_tracker;
2385
2386 struct list_head link_watch_list;
2387
2388 u8 reg_state;
2389
2390 bool dismantle;
2391
2392 /** @moving_ns: device is changing netns, protected by @lock */
2393 bool moving_ns;
2394 /** @rtnl_link_initializing: Device being created, suppress events */
2395 bool rtnl_link_initializing;
2396
2397 bool needs_free_netdev;
2398 void (*priv_destructor)(struct net_device *dev);
2399
2400 /* mid-layer private */
2401 void *ml_priv;
2402 enum netdev_ml_priv_type ml_priv_type;
2403
2404 enum netdev_stat_type pcpu_stat_type:8;
2405
2406#if IS_ENABLED(CONFIG_GARP)
2407 struct garp_port __rcu *garp_port;
2408#endif
2409#if IS_ENABLED(CONFIG_MRP)
2410 struct mrp_port __rcu *mrp_port;
2411#endif
2412#if IS_ENABLED(CONFIG_NET_DROP_MONITOR)
2413 struct dm_hw_stat_delta __rcu *dm_private;
2414#endif
2415 struct device dev;
2416 const struct attribute_group *sysfs_groups[5];
2417 const struct attribute_group *sysfs_rx_queue_group;
2418
2419 const struct rtnl_link_ops *rtnl_link_ops;
2420
2421 const struct netdev_stat_ops *stat_ops;
2422
2423 const struct netdev_queue_mgmt_ops *queue_mgmt_ops;
2424
2425 /* for setting kernel sock attribute on TCP connection setup */
2426#define GSO_MAX_SEGS 65535u
2427#define GSO_LEGACY_MAX_SIZE 65536u
2428/* TCP minimal MSS is 8 (TCP_MIN_GSO_SIZE),
2429 * and shinfo->gso_segs is a 16bit field.
2430 */
2431#define GSO_MAX_SIZE (8 * GSO_MAX_SEGS)
2432
2433#define TSO_LEGACY_MAX_SIZE 65536
2434#define TSO_MAX_SIZE UINT_MAX
2435 unsigned int tso_max_size;
2436#define TSO_MAX_SEGS U16_MAX
2437 u16 tso_max_segs;
2438
2439#ifdef CONFIG_DCB
2440 const struct dcbnl_rtnl_ops *dcbnl_ops;
2441#endif
2442 u8 prio_tc_map[TC_BITMASK + 1];
2443
2444#if IS_ENABLED(CONFIG_FCOE)
2445 unsigned int fcoe_ddp_xid;
2446#endif
2447#if IS_ENABLED(CONFIG_CGROUP_NET_PRIO)
2448 struct netprio_map __rcu *priomap;
2449#endif
2450 struct phy_link_topology *link_topo;
2451 struct phy_device *phydev;
2452 struct sfp_bus *sfp_bus;
2453 struct lock_class_key *qdisc_tx_busylock;
2454 bool proto_down;
2455 bool irq_affinity_auto;
2456 bool rx_cpu_rmap_auto;
2457
2458 /* priv_flags_slow, ungrouped to save space */
2459 unsigned long see_all_hwtstamp_requests:1;
2460 unsigned long change_proto_down:1;
2461 unsigned long netns_immutable:1;
2462 unsigned long fcoe_mtu:1;
2463
2464 struct list_head net_notifier_list;
2465
2466#if IS_ENABLED(CONFIG_MACSEC)
2467 /* MACsec management functions */
2468 const struct macsec_ops *macsec_ops;
2469#endif
2470 const struct udp_tunnel_nic_info *udp_tunnel_nic_info;
2471 struct udp_tunnel_nic *udp_tunnel_nic;
2472
2473 /** @cfg: net_device queue-related configuration */
2474 struct netdev_config *cfg;
2475 /**
2476 * @cfg_pending: same as @cfg but when device is being actively
2477 * reconfigured includes any changes to the configuration
2478 * requested by the user, but which may or may not be rejected.
2479 */
2480 struct netdev_config *cfg_pending;
2481 struct ethtool_netdev_state *ethtool;
2482
2483 /* protected by rtnl_lock */
2484 struct bpf_xdp_entity xdp_state[__MAX_XDP_MODE];
2485
2486 u8 dev_addr_shadow[MAX_ADDR_LEN];
2487 netdevice_tracker linkwatch_dev_tracker;
2488 netdevice_tracker watchdog_dev_tracker;
2489 netdevice_tracker dev_registered_tracker;
2490 struct rtnl_hw_stats64 *offload_xstats_l3;
2491
2492 struct devlink_port *devlink_port;
2493
2494#if IS_ENABLED(CONFIG_DPLL)
2495 struct dpll_pin __rcu *dpll_pin;
2496#endif
2497#if IS_ENABLED(CONFIG_PAGE_POOL)
2498 /** @page_pools: page pools created for this netdevice */
2499 struct hlist_head page_pools;
2500#endif
2501
2502 /** @irq_moder: dim parameters used if IS_ENABLED(CONFIG_DIMLIB). */
2503 struct dim_irq_moder *irq_moder;
2504
2505 u64 max_pacing_offload_horizon;
2506 struct napi_config *napi_config;
2507 u32 num_napi_configs;
2508 u32 napi_defer_hard_irqs;
2509 unsigned long gro_flush_timeout;
2510
2511 /**
2512 * @up: copy of @state's IFF_UP, but safe to read with just @lock.
2513 * May report false negatives while the device is being opened
2514 * or closed (@lock does not protect .ndo_open, or .ndo_close).
2515 */
2516 bool up;
2517
2518 /**
2519 * @request_ops_lock: request the core to run all @netdev_ops and
2520 * @ethtool_ops under the @lock.
2521 */
2522 bool request_ops_lock;
2523
2524 /**
2525 * @lock: netdev-scope lock, protects a small selection of fields.
2526 * Should always be taken using netdev_lock() / netdev_unlock() helpers.
2527 * Drivers are free to use it for other protection.
2528 *
2529 * For the drivers that implement shaper or queue API, the scope
2530 * of this lock is expanded to cover most ndo/queue/ethtool/sysfs
2531 * operations. Drivers may opt-in to this behavior by setting
2532 * @request_ops_lock.
2533 *
2534 * @lock protection mixes with rtnl_lock in multiple ways, fields are
2535 * either:
2536 *
2537 * - simply protected by the instance @lock;
2538 *
2539 * - double protected - writers hold both locks, readers hold either;
2540 *
2541 * - ops protected - protected by the lock held around the NDOs
2542 * and other callbacks, that is the instance lock on devices for
2543 * which netdev_need_ops_lock() returns true, otherwise by rtnl_lock;
2544 *
2545 * - double ops protected - always protected by rtnl_lock but for
2546 * devices for which netdev_need_ops_lock() returns true - also
2547 * the instance lock.
2548 *
2549 * Simply protects:
2550 * @gro_flush_timeout, @napi_defer_hard_irqs, @napi_list,
2551 * @net_shaper_hierarchy, @reg_state, @threaded
2552 *
2553 * Double protects:
2554 * @up, @moving_ns, @nd_net, @xdp_features
2555 *
2556 * Double ops protects:
2557 * @real_num_rx_queues, @real_num_tx_queues
2558 *
2559 * Also protects some fields in:
2560 * struct napi_struct, struct netdev_queue, struct netdev_rx_queue
2561 *
2562 * Ordering: take after rtnl_lock.
2563 */
2564 struct mutex lock;
2565
2566#if IS_ENABLED(CONFIG_NET_SHAPER)
2567 /**
2568 * @net_shaper_hierarchy: data tracking the current shaper status
2569 * see include/net/net_shapers.h
2570 */
2571 struct net_shaper_hierarchy *net_shaper_hierarchy;
2572#endif
2573
2574 struct hlist_head neighbours[NEIGH_NR_TABLES];
2575
2576 struct hwtstamp_provider __rcu *hwprov;
2577
2578 u8 priv[] ____cacheline_aligned
2579 __counted_by(priv_len);
2580} ____cacheline_aligned;
2581#define to_net_dev(d) container_of(d, struct net_device, dev)
2582
2583/*
2584 * Driver should use this to assign devlink port instance to a netdevice
2585 * before it registers the netdevice. Therefore devlink_port is static
2586 * during the netdev lifetime after it is registered.
2587 */
2588#define SET_NETDEV_DEVLINK_PORT(dev, port) \
2589({ \
2590 WARN_ON((dev)->reg_state != NETREG_UNINITIALIZED); \
2591 ((dev)->devlink_port = (port)); \
2592})
2593
2594static inline bool netif_elide_gro(const struct net_device *dev)
2595{
2596 if (!(dev->features & NETIF_F_GRO) || dev->xdp_prog)
2597 return true;
2598 return false;
2599}
2600
2601#define NETDEV_ALIGN 32
2602
2603static inline
2604int netdev_get_prio_tc_map(const struct net_device *dev, u32 prio)
2605{
2606 return dev->prio_tc_map[prio & TC_BITMASK];
2607}
2608
2609static inline
2610int netdev_set_prio_tc_map(struct net_device *dev, u8 prio, u8 tc)
2611{
2612 if (tc >= dev->num_tc)
2613 return -EINVAL;
2614
2615 dev->prio_tc_map[prio & TC_BITMASK] = tc & TC_BITMASK;
2616 return 0;
2617}
2618
2619int netdev_txq_to_tc(struct net_device *dev, unsigned int txq);
2620void netdev_reset_tc(struct net_device *dev);
2621int netdev_set_tc_queue(struct net_device *dev, u8 tc, u16 count, u16 offset);
2622int netdev_set_num_tc(struct net_device *dev, u8 num_tc);
2623
2624static inline
2625int netdev_get_num_tc(struct net_device *dev)
2626{
2627 return dev->num_tc;
2628}
2629
2630static inline void net_prefetch(void *p)
2631{
2632 prefetch(p);
2633#if L1_CACHE_BYTES < 128
2634 prefetch((u8 *)p + L1_CACHE_BYTES);
2635#endif
2636}
2637
2638static inline void net_prefetchw(void *p)
2639{
2640 prefetchw(x: p);
2641#if L1_CACHE_BYTES < 128
2642 prefetchw(x: (u8 *)p + L1_CACHE_BYTES);
2643#endif
2644}
2645
2646void netdev_unbind_sb_channel(struct net_device *dev,
2647 struct net_device *sb_dev);
2648int netdev_bind_sb_channel_queue(struct net_device *dev,
2649 struct net_device *sb_dev,
2650 u8 tc, u16 count, u16 offset);
2651int netdev_set_sb_channel(struct net_device *dev, u16 channel);
2652static inline int netdev_get_sb_channel(struct net_device *dev)
2653{
2654 return max_t(int, -dev->num_tc, 0);
2655}
2656
2657static inline
2658struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev,
2659 unsigned int index)
2660{
2661 DEBUG_NET_WARN_ON_ONCE(index >= dev->num_tx_queues);
2662 return &dev->_tx[index];
2663}
2664
2665static inline struct netdev_queue *skb_get_tx_queue(const struct net_device *dev,
2666 const struct sk_buff *skb)
2667{
2668 return netdev_get_tx_queue(dev, index: skb_get_queue_mapping(skb));
2669}
2670
2671static inline void netdev_for_each_tx_queue(struct net_device *dev,
2672 void (*f)(struct net_device *,
2673 struct netdev_queue *,
2674 void *),
2675 void *arg)
2676{
2677 unsigned int i;
2678
2679 for (i = 0; i < dev->num_tx_queues; i++)
2680 f(dev, &dev->_tx[i], arg);
2681}
2682
2683u16 netdev_pick_tx(struct net_device *dev, struct sk_buff *skb,
2684 struct net_device *sb_dev);
2685struct netdev_queue *netdev_core_pick_tx(struct net_device *dev,
2686 struct sk_buff *skb,
2687 struct net_device *sb_dev);
2688
2689/* returns the headroom that the master device needs to take in account
2690 * when forwarding to this dev
2691 */
2692static inline unsigned netdev_get_fwd_headroom(struct net_device *dev)
2693{
2694 return dev->priv_flags & IFF_PHONY_HEADROOM ? 0 : dev->needed_headroom;
2695}
2696
2697static inline void netdev_set_rx_headroom(struct net_device *dev, int new_hr)
2698{
2699 if (dev->netdev_ops->ndo_set_rx_headroom)
2700 dev->netdev_ops->ndo_set_rx_headroom(dev, new_hr);
2701}
2702
2703/* set the device rx headroom to the dev's default */
2704static inline void netdev_reset_rx_headroom(struct net_device *dev)
2705{
2706 netdev_set_rx_headroom(dev, new_hr: -1);
2707}
2708
2709static inline void *netdev_get_ml_priv(struct net_device *dev,
2710 enum netdev_ml_priv_type type)
2711{
2712 if (dev->ml_priv_type != type)
2713 return NULL;
2714
2715 return dev->ml_priv;
2716}
2717
2718static inline void netdev_set_ml_priv(struct net_device *dev,
2719 void *ml_priv,
2720 enum netdev_ml_priv_type type)
2721{
2722 WARN(dev->ml_priv_type && dev->ml_priv_type != type,
2723 "Overwriting already set ml_priv_type (%u) with different ml_priv_type (%u)!\n",
2724 dev->ml_priv_type, type);
2725 WARN(!dev->ml_priv_type && dev->ml_priv,
2726 "Overwriting already set ml_priv and ml_priv_type is ML_PRIV_NONE!\n");
2727
2728 dev->ml_priv = ml_priv;
2729 dev->ml_priv_type = type;
2730}
2731
2732/*
2733 * Net namespace inlines
2734 */
2735static inline
2736struct net *dev_net(const struct net_device *dev)
2737{
2738 return read_pnet(pnet: &dev->nd_net);
2739}
2740
2741static inline
2742struct net *dev_net_rcu(const struct net_device *dev)
2743{
2744 return read_pnet_rcu(pnet: &dev->nd_net);
2745}
2746
2747static inline
2748void dev_net_set(struct net_device *dev, struct net *net)
2749{
2750 write_pnet(pnet: &dev->nd_net, net);
2751}
2752
2753/**
2754 * netdev_priv - access network device private data
2755 * @dev: network device
2756 *
2757 * Get network device private data
2758 */
2759static inline void *netdev_priv(const struct net_device *dev)
2760{
2761 return (void *)dev->priv;
2762}
2763
2764/* Set the sysfs physical device reference for the network logical device
2765 * if set prior to registration will cause a symlink during initialization.
2766 */
2767#define SET_NETDEV_DEV(net, pdev) ((net)->dev.parent = (pdev))
2768
2769/* Set the sysfs device type for the network logical device to allow
2770 * fine-grained identification of different network device types. For
2771 * example Ethernet, Wireless LAN, Bluetooth, WiMAX etc.
2772 */
2773#define SET_NETDEV_DEVTYPE(net, devtype) ((net)->dev.type = (devtype))
2774
2775void netif_queue_set_napi(struct net_device *dev, unsigned int queue_index,
2776 enum netdev_queue_type type,
2777 struct napi_struct *napi);
2778
2779static inline void netdev_lock(struct net_device *dev)
2780{
2781 mutex_lock(&dev->lock);
2782}
2783
2784static inline void netdev_unlock(struct net_device *dev)
2785{
2786 mutex_unlock(lock: &dev->lock);
2787}
2788/* Additional netdev_lock()-related helpers are in net/netdev_lock.h */
2789
2790void netif_napi_set_irq_locked(struct napi_struct *napi, int irq);
2791
2792static inline void netif_napi_set_irq(struct napi_struct *napi, int irq)
2793{
2794 netdev_lock(dev: napi->dev);
2795 netif_napi_set_irq_locked(napi, irq);
2796 netdev_unlock(dev: napi->dev);
2797}
2798
2799/* Default NAPI poll() weight
2800 * Device drivers are strongly advised to not use bigger value
2801 */
2802#define NAPI_POLL_WEIGHT 64
2803
2804void netif_napi_add_weight_locked(struct net_device *dev,
2805 struct napi_struct *napi,
2806 int (*poll)(struct napi_struct *, int),
2807 int weight);
2808
2809static inline void
2810netif_napi_add_weight(struct net_device *dev, struct napi_struct *napi,
2811 int (*poll)(struct napi_struct *, int), int weight)
2812{
2813 netdev_lock(dev);
2814 netif_napi_add_weight_locked(dev, napi, poll, weight);
2815 netdev_unlock(dev);
2816}
2817
2818/**
2819 * netif_napi_add() - initialize a NAPI context
2820 * @dev: network device
2821 * @napi: NAPI context
2822 * @poll: polling function
2823 *
2824 * netif_napi_add() must be used to initialize a NAPI context prior to calling
2825 * *any* of the other NAPI-related functions.
2826 */
2827static inline void
2828netif_napi_add(struct net_device *dev, struct napi_struct *napi,
2829 int (*poll)(struct napi_struct *, int))
2830{
2831 netif_napi_add_weight(dev, napi, poll, NAPI_POLL_WEIGHT);
2832}
2833
2834static inline void
2835netif_napi_add_locked(struct net_device *dev, struct napi_struct *napi,
2836 int (*poll)(struct napi_struct *, int))
2837{
2838 netif_napi_add_weight_locked(dev, napi, poll, NAPI_POLL_WEIGHT);
2839}
2840
2841static inline void
2842netif_napi_add_tx_weight(struct net_device *dev,
2843 struct napi_struct *napi,
2844 int (*poll)(struct napi_struct *, int),
2845 int weight)
2846{
2847 set_bit(nr: NAPI_STATE_NO_BUSY_POLL, addr: &napi->state);
2848 netif_napi_add_weight(dev, napi, poll, weight);
2849}
2850
2851static inline void
2852netif_napi_add_config_locked(struct net_device *dev, struct napi_struct *napi,
2853 int (*poll)(struct napi_struct *, int), int index)
2854{
2855 napi->index = index;
2856 napi->config = &dev->napi_config[index];
2857 netif_napi_add_weight_locked(dev, napi, poll, NAPI_POLL_WEIGHT);
2858}
2859
2860/**
2861 * netif_napi_add_config - initialize a NAPI context with persistent config
2862 * @dev: network device
2863 * @napi: NAPI context
2864 * @poll: polling function
2865 * @index: the NAPI index
2866 */
2867static inline void
2868netif_napi_add_config(struct net_device *dev, struct napi_struct *napi,
2869 int (*poll)(struct napi_struct *, int), int index)
2870{
2871 netdev_lock(dev);
2872 netif_napi_add_config_locked(dev, napi, poll, index);
2873 netdev_unlock(dev);
2874}
2875
2876/**
2877 * netif_napi_add_tx() - initialize a NAPI context to be used for Tx only
2878 * @dev: network device
2879 * @napi: NAPI context
2880 * @poll: polling function
2881 *
2882 * This variant of netif_napi_add() should be used from drivers using NAPI
2883 * to exclusively poll a TX queue.
2884 * This will avoid we add it into napi_hash[], thus polluting this hash table.
2885 */
2886static inline void netif_napi_add_tx(struct net_device *dev,
2887 struct napi_struct *napi,
2888 int (*poll)(struct napi_struct *, int))
2889{
2890 netif_napi_add_tx_weight(dev, napi, poll, NAPI_POLL_WEIGHT);
2891}
2892
2893void __netif_napi_del_locked(struct napi_struct *napi);
2894
2895/**
2896 * __netif_napi_del - remove a NAPI context
2897 * @napi: NAPI context
2898 *
2899 * Warning: caller must observe RCU grace period before freeing memory
2900 * containing @napi. Drivers might want to call this helper to combine
2901 * all the needed RCU grace periods into a single one.
2902 */
2903static inline void __netif_napi_del(struct napi_struct *napi)
2904{
2905 netdev_lock(dev: napi->dev);
2906 __netif_napi_del_locked(napi);
2907 netdev_unlock(dev: napi->dev);
2908}
2909
2910static inline void netif_napi_del_locked(struct napi_struct *napi)
2911{
2912 __netif_napi_del_locked(napi);
2913 synchronize_net();
2914}
2915
2916/**
2917 * netif_napi_del - remove a NAPI context
2918 * @napi: NAPI context
2919 *
2920 * netif_napi_del() removes a NAPI context from the network device NAPI list
2921 */
2922static inline void netif_napi_del(struct napi_struct *napi)
2923{
2924 __netif_napi_del(napi);
2925 synchronize_net();
2926}
2927
2928int netif_enable_cpu_rmap(struct net_device *dev, unsigned int num_irqs);
2929void netif_set_affinity_auto(struct net_device *dev);
2930
2931struct packet_type {
2932 __be16 type; /* This is really htons(ether_type). */
2933 bool ignore_outgoing;
2934 struct net_device *dev; /* NULL is wildcarded here */
2935 netdevice_tracker dev_tracker;
2936 int (*func) (struct sk_buff *,
2937 struct net_device *,
2938 struct packet_type *,
2939 struct net_device *);
2940 void (*list_func) (struct list_head *,
2941 struct packet_type *,
2942 struct net_device *);
2943 bool (*id_match)(struct packet_type *ptype,
2944 struct sock *sk);
2945 struct net *af_packet_net;
2946 void *af_packet_priv;
2947 struct list_head list;
2948};
2949
2950struct offload_callbacks {
2951 struct sk_buff *(*gso_segment)(struct sk_buff *skb,
2952 netdev_features_t features);
2953 struct sk_buff *(*gro_receive)(struct list_head *head,
2954 struct sk_buff *skb);
2955 int (*gro_complete)(struct sk_buff *skb, int nhoff);
2956};
2957
2958struct packet_offload {
2959 __be16 type; /* This is really htons(ether_type). */
2960 u16 priority;
2961 struct offload_callbacks callbacks;
2962 struct list_head list;
2963};
2964
2965/* often modified stats are per-CPU, other are shared (netdev->stats) */
2966struct pcpu_sw_netstats {
2967 u64_stats_t rx_packets;
2968 u64_stats_t rx_bytes;
2969 u64_stats_t tx_packets;
2970 u64_stats_t tx_bytes;
2971 struct u64_stats_sync syncp;
2972} __aligned(4 * sizeof(u64));
2973
2974struct pcpu_dstats {
2975 u64_stats_t rx_packets;
2976 u64_stats_t rx_bytes;
2977 u64_stats_t tx_packets;
2978 u64_stats_t tx_bytes;
2979 u64_stats_t rx_drops;
2980 u64_stats_t tx_drops;
2981 struct u64_stats_sync syncp;
2982} __aligned(8 * sizeof(u64));
2983
2984struct pcpu_lstats {
2985 u64_stats_t packets;
2986 u64_stats_t bytes;
2987 struct u64_stats_sync syncp;
2988} __aligned(2 * sizeof(u64));
2989
2990void dev_lstats_read(struct net_device *dev, u64 *packets, u64 *bytes);
2991
2992static inline void dev_sw_netstats_rx_add(struct net_device *dev, unsigned int len)
2993{
2994 struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
2995
2996 u64_stats_update_begin(syncp: &tstats->syncp);
2997 u64_stats_add(p: &tstats->rx_bytes, val: len);
2998 u64_stats_inc(p: &tstats->rx_packets);
2999 u64_stats_update_end(syncp: &tstats->syncp);
3000}
3001
3002static inline void dev_sw_netstats_tx_add(struct net_device *dev,
3003 unsigned int packets,
3004 unsigned int len)
3005{
3006 struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
3007
3008 u64_stats_update_begin(syncp: &tstats->syncp);
3009 u64_stats_add(p: &tstats->tx_bytes, val: len);
3010 u64_stats_add(p: &tstats->tx_packets, val: packets);
3011 u64_stats_update_end(syncp: &tstats->syncp);
3012}
3013
3014static inline void dev_lstats_add(struct net_device *dev, unsigned int len)
3015{
3016 struct pcpu_lstats *lstats = this_cpu_ptr(dev->lstats);
3017
3018 u64_stats_update_begin(syncp: &lstats->syncp);
3019 u64_stats_add(p: &lstats->bytes, val: len);
3020 u64_stats_inc(p: &lstats->packets);
3021 u64_stats_update_end(syncp: &lstats->syncp);
3022}
3023
3024static inline void dev_dstats_rx_add(struct net_device *dev,
3025 unsigned int len)
3026{
3027 struct pcpu_dstats *dstats = this_cpu_ptr(dev->dstats);
3028
3029 u64_stats_update_begin(syncp: &dstats->syncp);
3030 u64_stats_inc(p: &dstats->rx_packets);
3031 u64_stats_add(p: &dstats->rx_bytes, val: len);
3032 u64_stats_update_end(syncp: &dstats->syncp);
3033}
3034
3035static inline void dev_dstats_rx_dropped(struct net_device *dev)
3036{
3037 struct pcpu_dstats *dstats = this_cpu_ptr(dev->dstats);
3038
3039 u64_stats_update_begin(syncp: &dstats->syncp);
3040 u64_stats_inc(p: &dstats->rx_drops);
3041 u64_stats_update_end(syncp: &dstats->syncp);
3042}
3043
3044static inline void dev_dstats_rx_dropped_add(struct net_device *dev,
3045 unsigned int packets)
3046{
3047 struct pcpu_dstats *dstats = this_cpu_ptr(dev->dstats);
3048
3049 u64_stats_update_begin(syncp: &dstats->syncp);
3050 u64_stats_add(p: &dstats->rx_drops, val: packets);
3051 u64_stats_update_end(syncp: &dstats->syncp);
3052}
3053
3054static inline void dev_dstats_tx_add(struct net_device *dev,
3055 unsigned int len)
3056{
3057 struct pcpu_dstats *dstats = this_cpu_ptr(dev->dstats);
3058
3059 u64_stats_update_begin(syncp: &dstats->syncp);
3060 u64_stats_inc(p: &dstats->tx_packets);
3061 u64_stats_add(p: &dstats->tx_bytes, val: len);
3062 u64_stats_update_end(syncp: &dstats->syncp);
3063}
3064
3065static inline void dev_dstats_tx_dropped(struct net_device *dev)
3066{
3067 struct pcpu_dstats *dstats = this_cpu_ptr(dev->dstats);
3068
3069 u64_stats_update_begin(syncp: &dstats->syncp);
3070 u64_stats_inc(p: &dstats->tx_drops);
3071 u64_stats_update_end(syncp: &dstats->syncp);
3072}
3073
3074#define __netdev_alloc_pcpu_stats(type, gfp) \
3075({ \
3076 typeof(type) __percpu *pcpu_stats = alloc_percpu_gfp(type, gfp);\
3077 if (pcpu_stats) { \
3078 int __cpu; \
3079 for_each_possible_cpu(__cpu) { \
3080 typeof(type) *stat; \
3081 stat = per_cpu_ptr(pcpu_stats, __cpu); \
3082 u64_stats_init(&stat->syncp); \
3083 } \
3084 } \
3085 pcpu_stats; \
3086})
3087
3088#define netdev_alloc_pcpu_stats(type) \
3089 __netdev_alloc_pcpu_stats(type, GFP_KERNEL)
3090
3091#define devm_netdev_alloc_pcpu_stats(dev, type) \
3092({ \
3093 typeof(type) __percpu *pcpu_stats = devm_alloc_percpu(dev, type);\
3094 if (pcpu_stats) { \
3095 int __cpu; \
3096 for_each_possible_cpu(__cpu) { \
3097 typeof(type) *stat; \
3098 stat = per_cpu_ptr(pcpu_stats, __cpu); \
3099 u64_stats_init(&stat->syncp); \
3100 } \
3101 } \
3102 pcpu_stats; \
3103})
3104
3105enum netdev_lag_tx_type {
3106 NETDEV_LAG_TX_TYPE_UNKNOWN,
3107 NETDEV_LAG_TX_TYPE_RANDOM,
3108 NETDEV_LAG_TX_TYPE_BROADCAST,
3109 NETDEV_LAG_TX_TYPE_ROUNDROBIN,
3110 NETDEV_LAG_TX_TYPE_ACTIVEBACKUP,
3111 NETDEV_LAG_TX_TYPE_HASH,
3112};
3113
3114enum netdev_lag_hash {
3115 NETDEV_LAG_HASH_NONE,
3116 NETDEV_LAG_HASH_L2,
3117 NETDEV_LAG_HASH_L34,
3118 NETDEV_LAG_HASH_L23,
3119 NETDEV_LAG_HASH_E23,
3120 NETDEV_LAG_HASH_E34,
3121 NETDEV_LAG_HASH_VLAN_SRCMAC,
3122 NETDEV_LAG_HASH_UNKNOWN,
3123};
3124
3125struct netdev_lag_upper_info {
3126 enum netdev_lag_tx_type tx_type;
3127 enum netdev_lag_hash hash_type;
3128};
3129
3130struct netdev_lag_lower_state_info {
3131 u8 link_up : 1,
3132 tx_enabled : 1;
3133};
3134
3135#include <linux/notifier.h>
3136
3137/* netdevice notifier chain. Please remember to update netdev_cmd_to_name()
3138 * and the rtnetlink notification exclusion list in rtnetlink_event() when
3139 * adding new types.
3140 */
3141enum netdev_cmd {
3142 NETDEV_UP = 1, /* For now you can't veto a device up/down */
3143 NETDEV_DOWN,
3144 NETDEV_REBOOT, /* Tell a protocol stack a network interface
3145 detected a hardware crash and restarted
3146 - we can use this eg to kick tcp sessions
3147 once done */
3148 NETDEV_CHANGE, /* Notify device state change */
3149 NETDEV_REGISTER,
3150 NETDEV_UNREGISTER,
3151 NETDEV_CHANGEMTU, /* notify after mtu change happened */
3152 NETDEV_CHANGEADDR, /* notify after the address change */
3153 NETDEV_PRE_CHANGEADDR, /* notify before the address change */
3154 NETDEV_GOING_DOWN,
3155 NETDEV_CHANGENAME,
3156 NETDEV_FEAT_CHANGE,
3157 NETDEV_BONDING_FAILOVER,
3158 NETDEV_PRE_UP,
3159 NETDEV_PRE_TYPE_CHANGE,
3160 NETDEV_POST_TYPE_CHANGE,
3161 NETDEV_POST_INIT,
3162 NETDEV_PRE_UNINIT,
3163 NETDEV_RELEASE,
3164 NETDEV_NOTIFY_PEERS,
3165 NETDEV_JOIN,
3166 NETDEV_CHANGEUPPER,
3167 NETDEV_RESEND_IGMP,
3168 NETDEV_PRECHANGEMTU, /* notify before mtu change happened */
3169 NETDEV_CHANGEINFODATA,
3170 NETDEV_BONDING_INFO,
3171 NETDEV_PRECHANGEUPPER,
3172 NETDEV_CHANGELOWERSTATE,
3173 NETDEV_UDP_TUNNEL_PUSH_INFO,
3174 NETDEV_UDP_TUNNEL_DROP_INFO,
3175 NETDEV_CHANGE_TX_QUEUE_LEN,
3176 NETDEV_CVLAN_FILTER_PUSH_INFO,
3177 NETDEV_CVLAN_FILTER_DROP_INFO,
3178 NETDEV_SVLAN_FILTER_PUSH_INFO,
3179 NETDEV_SVLAN_FILTER_DROP_INFO,
3180 NETDEV_OFFLOAD_XSTATS_ENABLE,
3181 NETDEV_OFFLOAD_XSTATS_DISABLE,
3182 NETDEV_OFFLOAD_XSTATS_REPORT_USED,
3183 NETDEV_OFFLOAD_XSTATS_REPORT_DELTA,
3184 NETDEV_XDP_FEAT_CHANGE,
3185};
3186const char *netdev_cmd_to_name(enum netdev_cmd cmd);
3187
3188int register_netdevice_notifier(struct notifier_block *nb);
3189int unregister_netdevice_notifier(struct notifier_block *nb);
3190int register_netdevice_notifier_net(struct net *net, struct notifier_block *nb);
3191int unregister_netdevice_notifier_net(struct net *net,
3192 struct notifier_block *nb);
3193int register_netdevice_notifier_dev_net(struct net_device *dev,
3194 struct notifier_block *nb,
3195 struct netdev_net_notifier *nn);
3196int unregister_netdevice_notifier_dev_net(struct net_device *dev,
3197 struct notifier_block *nb,
3198 struct netdev_net_notifier *nn);
3199
3200struct netdev_notifier_info {
3201 struct net_device *dev;
3202 struct netlink_ext_ack *extack;
3203};
3204
3205struct netdev_notifier_info_ext {
3206 struct netdev_notifier_info info; /* must be first */
3207 union {
3208 u32 mtu;
3209 } ext;
3210};
3211
3212struct netdev_notifier_change_info {
3213 struct netdev_notifier_info info; /* must be first */
3214 unsigned int flags_changed;
3215};
3216
3217struct netdev_notifier_changeupper_info {
3218 struct netdev_notifier_info info; /* must be first */
3219 struct net_device *upper_dev; /* new upper dev */
3220 bool master; /* is upper dev master */
3221 bool linking; /* is the notification for link or unlink */
3222 void *upper_info; /* upper dev info */
3223};
3224
3225struct netdev_notifier_changelowerstate_info {
3226 struct netdev_notifier_info info; /* must be first */
3227 void *lower_state_info; /* is lower dev state */
3228};
3229
3230struct netdev_notifier_pre_changeaddr_info {
3231 struct netdev_notifier_info info; /* must be first */
3232 const unsigned char *dev_addr;
3233};
3234
3235enum netdev_offload_xstats_type {
3236 NETDEV_OFFLOAD_XSTATS_TYPE_L3 = 1,
3237};
3238
3239struct netdev_notifier_offload_xstats_info {
3240 struct netdev_notifier_info info; /* must be first */
3241 enum netdev_offload_xstats_type type;
3242
3243 union {
3244 /* NETDEV_OFFLOAD_XSTATS_REPORT_DELTA */
3245 struct netdev_notifier_offload_xstats_rd *report_delta;
3246 /* NETDEV_OFFLOAD_XSTATS_REPORT_USED */
3247 struct netdev_notifier_offload_xstats_ru *report_used;
3248 };
3249};
3250
3251int netdev_offload_xstats_enable(struct net_device *dev,
3252 enum netdev_offload_xstats_type type,
3253 struct netlink_ext_ack *extack);
3254int netdev_offload_xstats_disable(struct net_device *dev,
3255 enum netdev_offload_xstats_type type);
3256bool netdev_offload_xstats_enabled(const struct net_device *dev,
3257 enum netdev_offload_xstats_type type);
3258int netdev_offload_xstats_get(struct net_device *dev,
3259 enum netdev_offload_xstats_type type,
3260 struct rtnl_hw_stats64 *stats, bool *used,
3261 struct netlink_ext_ack *extack);
3262void
3263netdev_offload_xstats_report_delta(struct netdev_notifier_offload_xstats_rd *rd,
3264 const struct rtnl_hw_stats64 *stats);
3265void
3266netdev_offload_xstats_report_used(struct netdev_notifier_offload_xstats_ru *ru);
3267void netdev_offload_xstats_push_delta(struct net_device *dev,
3268 enum netdev_offload_xstats_type type,
3269 const struct rtnl_hw_stats64 *stats);
3270
3271static inline void netdev_notifier_info_init(struct netdev_notifier_info *info,
3272 struct net_device *dev)
3273{
3274 info->dev = dev;
3275 info->extack = NULL;
3276}
3277
3278static inline struct net_device *
3279netdev_notifier_info_to_dev(const struct netdev_notifier_info *info)
3280{
3281 return info->dev;
3282}
3283
3284static inline struct netlink_ext_ack *
3285netdev_notifier_info_to_extack(const struct netdev_notifier_info *info)
3286{
3287 return info->extack;
3288}
3289
3290int call_netdevice_notifiers(unsigned long val, struct net_device *dev);
3291int call_netdevice_notifiers_info(unsigned long val,
3292 struct netdev_notifier_info *info);
3293
3294#define for_each_netdev(net, d) \
3295 list_for_each_entry(d, &(net)->dev_base_head, dev_list)
3296#define for_each_netdev_reverse(net, d) \
3297 list_for_each_entry_reverse(d, &(net)->dev_base_head, dev_list)
3298#define for_each_netdev_rcu(net, d) \
3299 list_for_each_entry_rcu(d, &(net)->dev_base_head, dev_list)
3300#define for_each_netdev_safe(net, d, n) \
3301 list_for_each_entry_safe(d, n, &(net)->dev_base_head, dev_list)
3302#define for_each_netdev_continue(net, d) \
3303 list_for_each_entry_continue(d, &(net)->dev_base_head, dev_list)
3304#define for_each_netdev_continue_reverse(net, d) \
3305 list_for_each_entry_continue_reverse(d, &(net)->dev_base_head, \
3306 dev_list)
3307#define for_each_netdev_continue_rcu(net, d) \
3308 list_for_each_entry_continue_rcu(d, &(net)->dev_base_head, dev_list)
3309#define for_each_netdev_in_bond_rcu(bond, slave) \
3310 for_each_netdev_rcu(dev_net_rcu(bond), slave) \
3311 if (netdev_master_upper_dev_get_rcu(slave) == (bond))
3312#define net_device_entry(lh) list_entry(lh, struct net_device, dev_list)
3313
3314#define for_each_netdev_dump(net, d, ifindex) \
3315 for (; (d = xa_find(&(net)->dev_by_index, &ifindex, \
3316 ULONG_MAX, XA_PRESENT)); ifindex++)
3317
3318static inline struct net_device *next_net_device(struct net_device *dev)
3319{
3320 struct list_head *lh;
3321 struct net *net;
3322
3323 net = dev_net(dev);
3324 lh = dev->dev_list.next;
3325 return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
3326}
3327
3328static inline struct net_device *next_net_device_rcu(struct net_device *dev)
3329{
3330 struct list_head *lh;
3331 struct net *net;
3332
3333 net = dev_net(dev);
3334 lh = rcu_dereference(list_next_rcu(&dev->dev_list));
3335 return lh == &net->dev_base_head ? NULL : net_device_entry(lh);
3336}
3337
3338static inline struct net_device *first_net_device(struct net *net)
3339{
3340 return list_empty(head: &net->dev_base_head) ? NULL :
3341 net_device_entry(net->dev_base_head.next);
3342}
3343
3344int netdev_boot_setup_check(struct net_device *dev);
3345struct You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.