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