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