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