at v6.16 58 kB view raw
1/* SPDX-License-Identifier: GPL-2.0 */ 2/* 3 * ethtool.h: Defines for Linux ethtool. 4 * 5 * Copyright (C) 1998 David S. Miller (davem@redhat.com) 6 * Copyright 2001 Jeff Garzik <jgarzik@pobox.com> 7 * Portions Copyright 2001 Sun Microsystems (thockin@sun.com) 8 * Portions Copyright 2002 Intel (eli.kupermann@intel.com, 9 * christopher.leech@intel.com, 10 * scott.feldman@intel.com) 11 * Portions Copyright (C) Sun Microsystems 2008 12 */ 13#ifndef _LINUX_ETHTOOL_H 14#define _LINUX_ETHTOOL_H 15 16#include <linux/bitmap.h> 17#include <linux/compat.h> 18#include <linux/if_ether.h> 19#include <linux/netlink.h> 20#include <linux/timer_types.h> 21#include <uapi/linux/ethtool.h> 22#include <uapi/linux/ethtool_netlink_generated.h> 23#include <uapi/linux/net_tstamp.h> 24 25#define ETHTOOL_MM_MAX_VERIFY_TIME_MS 128 26#define ETHTOOL_MM_MAX_VERIFY_RETRIES 3 27 28struct compat_ethtool_rx_flow_spec { 29 u32 flow_type; 30 union ethtool_flow_union h_u; 31 struct ethtool_flow_ext h_ext; 32 union ethtool_flow_union m_u; 33 struct ethtool_flow_ext m_ext; 34 compat_u64 ring_cookie; 35 u32 location; 36}; 37 38struct compat_ethtool_rxnfc { 39 u32 cmd; 40 u32 flow_type; 41 compat_u64 data; 42 struct compat_ethtool_rx_flow_spec fs; 43 u32 rule_cnt; 44 u32 rule_locs[]; 45}; 46 47#include <linux/rculist.h> 48 49/** 50 * enum ethtool_phys_id_state - indicator state for physical identification 51 * @ETHTOOL_ID_INACTIVE: Physical ID indicator should be deactivated 52 * @ETHTOOL_ID_ACTIVE: Physical ID indicator should be activated 53 * @ETHTOOL_ID_ON: LED should be turned on (used iff %ETHTOOL_ID_ACTIVE 54 * is not supported) 55 * @ETHTOOL_ID_OFF: LED should be turned off (used iff %ETHTOOL_ID_ACTIVE 56 * is not supported) 57 */ 58enum ethtool_phys_id_state { 59 ETHTOOL_ID_INACTIVE, 60 ETHTOOL_ID_ACTIVE, 61 ETHTOOL_ID_ON, 62 ETHTOOL_ID_OFF 63}; 64 65enum { 66 ETH_RSS_HASH_TOP_BIT, /* Configurable RSS hash function - Toeplitz */ 67 ETH_RSS_HASH_XOR_BIT, /* Configurable RSS hash function - Xor */ 68 ETH_RSS_HASH_CRC32_BIT, /* Configurable RSS hash function - Crc32 */ 69 70 /* 71 * Add your fresh new hash function bits above and remember to update 72 * rss_hash_func_strings[] in ethtool.c 73 */ 74 ETH_RSS_HASH_FUNCS_COUNT 75}; 76 77/** 78 * struct kernel_ethtool_ringparam - RX/TX ring configuration 79 * @rx_buf_len: Current length of buffers on the rx ring. 80 * @tcp_data_split: Scatter packet headers and data to separate buffers 81 * @tx_push: The flag of tx push mode 82 * @rx_push: The flag of rx push mode 83 * @cqe_size: Size of TX/RX completion queue event 84 * @tx_push_buf_len: Size of TX push buffer 85 * @tx_push_buf_max_len: Maximum allowed size of TX push buffer 86 * @hds_thresh: Packet size threshold for header data split (HDS) 87 * @hds_thresh_max: Maximum supported setting for @hds_threshold 88 * 89 */ 90struct kernel_ethtool_ringparam { 91 u32 rx_buf_len; 92 u8 tcp_data_split; 93 u8 tx_push; 94 u8 rx_push; 95 u32 cqe_size; 96 u32 tx_push_buf_len; 97 u32 tx_push_buf_max_len; 98 u32 hds_thresh; 99 u32 hds_thresh_max; 100}; 101 102/** 103 * enum ethtool_supported_ring_param - indicator caps for setting ring params 104 * @ETHTOOL_RING_USE_RX_BUF_LEN: capture for setting rx_buf_len 105 * @ETHTOOL_RING_USE_CQE_SIZE: capture for setting cqe_size 106 * @ETHTOOL_RING_USE_TX_PUSH: capture for setting tx_push 107 * @ETHTOOL_RING_USE_RX_PUSH: capture for setting rx_push 108 * @ETHTOOL_RING_USE_TX_PUSH_BUF_LEN: capture for setting tx_push_buf_len 109 * @ETHTOOL_RING_USE_TCP_DATA_SPLIT: capture for setting tcp_data_split 110 * @ETHTOOL_RING_USE_HDS_THRS: capture for setting header-data-split-thresh 111 */ 112enum ethtool_supported_ring_param { 113 ETHTOOL_RING_USE_RX_BUF_LEN = BIT(0), 114 ETHTOOL_RING_USE_CQE_SIZE = BIT(1), 115 ETHTOOL_RING_USE_TX_PUSH = BIT(2), 116 ETHTOOL_RING_USE_RX_PUSH = BIT(3), 117 ETHTOOL_RING_USE_TX_PUSH_BUF_LEN = BIT(4), 118 ETHTOOL_RING_USE_TCP_DATA_SPLIT = BIT(5), 119 ETHTOOL_RING_USE_HDS_THRS = BIT(6), 120}; 121 122#define __ETH_RSS_HASH_BIT(bit) ((u32)1 << (bit)) 123#define __ETH_RSS_HASH(name) __ETH_RSS_HASH_BIT(ETH_RSS_HASH_##name##_BIT) 124 125#define ETH_RSS_HASH_TOP __ETH_RSS_HASH(TOP) 126#define ETH_RSS_HASH_XOR __ETH_RSS_HASH(XOR) 127#define ETH_RSS_HASH_CRC32 __ETH_RSS_HASH(CRC32) 128 129#define ETH_RSS_HASH_UNKNOWN 0 130#define ETH_RSS_HASH_NO_CHANGE 0 131 132struct net_device; 133struct netlink_ext_ack; 134 135/* Link extended state and substate. */ 136struct ethtool_link_ext_state_info { 137 enum ethtool_link_ext_state link_ext_state; 138 union { 139 enum ethtool_link_ext_substate_autoneg autoneg; 140 enum ethtool_link_ext_substate_link_training link_training; 141 enum ethtool_link_ext_substate_link_logical_mismatch link_logical_mismatch; 142 enum ethtool_link_ext_substate_bad_signal_integrity bad_signal_integrity; 143 enum ethtool_link_ext_substate_cable_issue cable_issue; 144 enum ethtool_link_ext_substate_module module; 145 u32 __link_ext_substate; 146 }; 147}; 148 149struct ethtool_link_ext_stats { 150 /* Custom Linux statistic for PHY level link down events. 151 * In a simpler world it should be equal to netdev->carrier_down_count 152 * unfortunately netdev also counts local reconfigurations which don't 153 * actually take the physical link down, not to mention NC-SI which, 154 * if present, keeps the link up regardless of host state. 155 * This statistic counts when PHY _actually_ went down, or lost link. 156 * 157 * Note that we need u64 for ethtool_stats_init() and comparisons 158 * to ETHTOOL_STAT_NOT_SET, but only u32 is exposed to the user. 159 */ 160 u64 link_down_events; 161}; 162 163/** 164 * ethtool_rxfh_indir_default - get default value for RX flow hash indirection 165 * @index: Index in RX flow hash indirection table 166 * @n_rx_rings: Number of RX rings to use 167 * 168 * This function provides the default policy for RX flow hash indirection. 169 */ 170static inline u32 ethtool_rxfh_indir_default(u32 index, u32 n_rx_rings) 171{ 172 return index % n_rx_rings; 173} 174 175/** 176 * struct ethtool_rxfh_context - a custom RSS context configuration 177 * @indir_size: Number of u32 entries in indirection table 178 * @key_size: Size of hash key, in bytes 179 * @priv_size: Size of driver private data, in bytes 180 * @hfunc: RSS hash function identifier. One of the %ETH_RSS_HASH_* 181 * @input_xfrm: Defines how the input data is transformed. Valid values are one 182 * of %RXH_XFRM_*. 183 * @indir_configured: indir has been specified (at create time or subsequently) 184 * @key_configured: hkey has been specified (at create time or subsequently) 185 */ 186struct ethtool_rxfh_context { 187 u32 indir_size; 188 u32 key_size; 189 u16 priv_size; 190 u8 hfunc; 191 u8 input_xfrm; 192 u8 indir_configured:1; 193 u8 key_configured:1; 194 /* private: driver private data, indirection table, and hash key are 195 * stored sequentially in @data area. Use below helpers to access. 196 */ 197 u32 key_off; 198 u8 data[] __aligned(sizeof(void *)); 199}; 200 201static inline void *ethtool_rxfh_context_priv(struct ethtool_rxfh_context *ctx) 202{ 203 return ctx->data; 204} 205 206static inline u32 *ethtool_rxfh_context_indir(struct ethtool_rxfh_context *ctx) 207{ 208 return (u32 *)(ctx->data + ALIGN(ctx->priv_size, sizeof(u32))); 209} 210 211static inline u8 *ethtool_rxfh_context_key(struct ethtool_rxfh_context *ctx) 212{ 213 return &ctx->data[ctx->key_off]; 214} 215 216void ethtool_rxfh_context_lost(struct net_device *dev, u32 context_id); 217 218struct link_mode_info { 219 int speed; 220 u8 lanes; 221 u8 duplex; 222}; 223 224extern const struct link_mode_info link_mode_params[]; 225 226/* declare a link mode bitmap */ 227#define __ETHTOOL_DECLARE_LINK_MODE_MASK(name) \ 228 DECLARE_BITMAP(name, __ETHTOOL_LINK_MODE_MASK_NBITS) 229 230/* drivers must ignore base.cmd and base.link_mode_masks_nwords 231 * fields, but they are allowed to overwrite them (will be ignored). 232 */ 233struct ethtool_link_ksettings { 234 struct ethtool_link_settings base; 235 struct { 236 __ETHTOOL_DECLARE_LINK_MODE_MASK(supported); 237 __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising); 238 __ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising); 239 } link_modes; 240 u32 lanes; 241}; 242 243/** 244 * ethtool_link_ksettings_zero_link_mode - clear link_ksettings link mode mask 245 * @ptr : pointer to struct ethtool_link_ksettings 246 * @name : one of supported/advertising/lp_advertising 247 */ 248#define ethtool_link_ksettings_zero_link_mode(ptr, name) \ 249 bitmap_zero((ptr)->link_modes.name, __ETHTOOL_LINK_MODE_MASK_NBITS) 250 251/** 252 * ethtool_link_ksettings_add_link_mode - set bit in link_ksettings 253 * link mode mask 254 * @ptr : pointer to struct ethtool_link_ksettings 255 * @name : one of supported/advertising/lp_advertising 256 * @mode : one of the ETHTOOL_LINK_MODE_*_BIT 257 * (not atomic, no bound checking) 258 */ 259#define ethtool_link_ksettings_add_link_mode(ptr, name, mode) \ 260 __set_bit(ETHTOOL_LINK_MODE_ ## mode ## _BIT, (ptr)->link_modes.name) 261 262/** 263 * ethtool_link_ksettings_del_link_mode - clear bit in link_ksettings 264 * link mode mask 265 * @ptr : pointer to struct ethtool_link_ksettings 266 * @name : one of supported/advertising/lp_advertising 267 * @mode : one of the ETHTOOL_LINK_MODE_*_BIT 268 * (not atomic, no bound checking) 269 */ 270#define ethtool_link_ksettings_del_link_mode(ptr, name, mode) \ 271 __clear_bit(ETHTOOL_LINK_MODE_ ## mode ## _BIT, (ptr)->link_modes.name) 272 273/** 274 * ethtool_link_ksettings_test_link_mode - test bit in ksettings link mode mask 275 * @ptr : pointer to struct ethtool_link_ksettings 276 * @name : one of supported/advertising/lp_advertising 277 * @mode : one of the ETHTOOL_LINK_MODE_*_BIT 278 * (not atomic, no bound checking) 279 * 280 * Returns: true/false. 281 */ 282#define ethtool_link_ksettings_test_link_mode(ptr, name, mode) \ 283 test_bit(ETHTOOL_LINK_MODE_ ## mode ## _BIT, (ptr)->link_modes.name) 284 285extern int 286__ethtool_get_link_ksettings(struct net_device *dev, 287 struct ethtool_link_ksettings *link_ksettings); 288 289struct ethtool_keee { 290 __ETHTOOL_DECLARE_LINK_MODE_MASK(supported); 291 __ETHTOOL_DECLARE_LINK_MODE_MASK(advertised); 292 __ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertised); 293 u32 tx_lpi_timer; 294 bool tx_lpi_enabled; 295 bool eee_active; 296 bool eee_enabled; 297}; 298 299struct kernel_ethtool_coalesce { 300 u8 use_cqe_mode_tx; 301 u8 use_cqe_mode_rx; 302 u32 tx_aggr_max_bytes; 303 u32 tx_aggr_max_frames; 304 u32 tx_aggr_time_usecs; 305}; 306 307/** 308 * ethtool_intersect_link_masks - Given two link masks, AND them together 309 * @dst: first mask and where result is stored 310 * @src: second mask to intersect with 311 * 312 * Given two link mode masks, AND them together and save the result in dst. 313 */ 314void ethtool_intersect_link_masks(struct ethtool_link_ksettings *dst, 315 struct ethtool_link_ksettings *src); 316 317void ethtool_convert_legacy_u32_to_link_mode(unsigned long *dst, 318 u32 legacy_u32); 319 320/* return false if src had higher bits set. lower bits always updated. */ 321bool ethtool_convert_link_mode_to_legacy_u32(u32 *legacy_u32, 322 const unsigned long *src); 323 324#define ETHTOOL_COALESCE_RX_USECS BIT(0) 325#define ETHTOOL_COALESCE_RX_MAX_FRAMES BIT(1) 326#define ETHTOOL_COALESCE_RX_USECS_IRQ BIT(2) 327#define ETHTOOL_COALESCE_RX_MAX_FRAMES_IRQ BIT(3) 328#define ETHTOOL_COALESCE_TX_USECS BIT(4) 329#define ETHTOOL_COALESCE_TX_MAX_FRAMES BIT(5) 330#define ETHTOOL_COALESCE_TX_USECS_IRQ BIT(6) 331#define ETHTOOL_COALESCE_TX_MAX_FRAMES_IRQ BIT(7) 332#define ETHTOOL_COALESCE_STATS_BLOCK_USECS BIT(8) 333#define ETHTOOL_COALESCE_USE_ADAPTIVE_RX BIT(9) 334#define ETHTOOL_COALESCE_USE_ADAPTIVE_TX BIT(10) 335#define ETHTOOL_COALESCE_PKT_RATE_LOW BIT(11) 336#define ETHTOOL_COALESCE_RX_USECS_LOW BIT(12) 337#define ETHTOOL_COALESCE_RX_MAX_FRAMES_LOW BIT(13) 338#define ETHTOOL_COALESCE_TX_USECS_LOW BIT(14) 339#define ETHTOOL_COALESCE_TX_MAX_FRAMES_LOW BIT(15) 340#define ETHTOOL_COALESCE_PKT_RATE_HIGH BIT(16) 341#define ETHTOOL_COALESCE_RX_USECS_HIGH BIT(17) 342#define ETHTOOL_COALESCE_RX_MAX_FRAMES_HIGH BIT(18) 343#define ETHTOOL_COALESCE_TX_USECS_HIGH BIT(19) 344#define ETHTOOL_COALESCE_TX_MAX_FRAMES_HIGH BIT(20) 345#define ETHTOOL_COALESCE_RATE_SAMPLE_INTERVAL BIT(21) 346#define ETHTOOL_COALESCE_USE_CQE_RX BIT(22) 347#define ETHTOOL_COALESCE_USE_CQE_TX BIT(23) 348#define ETHTOOL_COALESCE_TX_AGGR_MAX_BYTES BIT(24) 349#define ETHTOOL_COALESCE_TX_AGGR_MAX_FRAMES BIT(25) 350#define ETHTOOL_COALESCE_TX_AGGR_TIME_USECS BIT(26) 351#define ETHTOOL_COALESCE_RX_PROFILE BIT(27) 352#define ETHTOOL_COALESCE_TX_PROFILE BIT(28) 353#define ETHTOOL_COALESCE_ALL_PARAMS GENMASK(28, 0) 354 355#define ETHTOOL_COALESCE_USECS \ 356 (ETHTOOL_COALESCE_RX_USECS | ETHTOOL_COALESCE_TX_USECS) 357#define ETHTOOL_COALESCE_MAX_FRAMES \ 358 (ETHTOOL_COALESCE_RX_MAX_FRAMES | ETHTOOL_COALESCE_TX_MAX_FRAMES) 359#define ETHTOOL_COALESCE_USECS_IRQ \ 360 (ETHTOOL_COALESCE_RX_USECS_IRQ | ETHTOOL_COALESCE_TX_USECS_IRQ) 361#define ETHTOOL_COALESCE_MAX_FRAMES_IRQ \ 362 (ETHTOOL_COALESCE_RX_MAX_FRAMES_IRQ | \ 363 ETHTOOL_COALESCE_TX_MAX_FRAMES_IRQ) 364#define ETHTOOL_COALESCE_USE_ADAPTIVE \ 365 (ETHTOOL_COALESCE_USE_ADAPTIVE_RX | ETHTOOL_COALESCE_USE_ADAPTIVE_TX) 366#define ETHTOOL_COALESCE_USECS_LOW_HIGH \ 367 (ETHTOOL_COALESCE_RX_USECS_LOW | ETHTOOL_COALESCE_TX_USECS_LOW | \ 368 ETHTOOL_COALESCE_RX_USECS_HIGH | ETHTOOL_COALESCE_TX_USECS_HIGH) 369#define ETHTOOL_COALESCE_MAX_FRAMES_LOW_HIGH \ 370 (ETHTOOL_COALESCE_RX_MAX_FRAMES_LOW | \ 371 ETHTOOL_COALESCE_TX_MAX_FRAMES_LOW | \ 372 ETHTOOL_COALESCE_RX_MAX_FRAMES_HIGH | \ 373 ETHTOOL_COALESCE_TX_MAX_FRAMES_HIGH) 374#define ETHTOOL_COALESCE_PKT_RATE_RX_USECS \ 375 (ETHTOOL_COALESCE_USE_ADAPTIVE_RX | \ 376 ETHTOOL_COALESCE_RX_USECS_LOW | ETHTOOL_COALESCE_RX_USECS_HIGH | \ 377 ETHTOOL_COALESCE_PKT_RATE_LOW | ETHTOOL_COALESCE_PKT_RATE_HIGH | \ 378 ETHTOOL_COALESCE_RATE_SAMPLE_INTERVAL) 379#define ETHTOOL_COALESCE_USE_CQE \ 380 (ETHTOOL_COALESCE_USE_CQE_RX | ETHTOOL_COALESCE_USE_CQE_TX) 381#define ETHTOOL_COALESCE_TX_AGGR \ 382 (ETHTOOL_COALESCE_TX_AGGR_MAX_BYTES | \ 383 ETHTOOL_COALESCE_TX_AGGR_MAX_FRAMES | \ 384 ETHTOOL_COALESCE_TX_AGGR_TIME_USECS) 385 386#define ETHTOOL_STAT_NOT_SET (~0ULL) 387 388static inline void ethtool_stats_init(u64 *stats, unsigned int n) 389{ 390 while (n--) 391 stats[n] = ETHTOOL_STAT_NOT_SET; 392} 393 394/* Basic IEEE 802.3 MAC statistics (30.3.1.1.*), not otherwise exposed 395 * via a more targeted API. 396 */ 397struct ethtool_eth_mac_stats { 398 enum ethtool_mac_stats_src src; 399 struct_group(stats, 400 u64 FramesTransmittedOK; 401 u64 SingleCollisionFrames; 402 u64 MultipleCollisionFrames; 403 u64 FramesReceivedOK; 404 u64 FrameCheckSequenceErrors; 405 u64 AlignmentErrors; 406 u64 OctetsTransmittedOK; 407 u64 FramesWithDeferredXmissions; 408 u64 LateCollisions; 409 u64 FramesAbortedDueToXSColls; 410 u64 FramesLostDueToIntMACXmitError; 411 u64 CarrierSenseErrors; 412 u64 OctetsReceivedOK; 413 u64 FramesLostDueToIntMACRcvError; 414 u64 MulticastFramesXmittedOK; 415 u64 BroadcastFramesXmittedOK; 416 u64 FramesWithExcessiveDeferral; 417 u64 MulticastFramesReceivedOK; 418 u64 BroadcastFramesReceivedOK; 419 u64 InRangeLengthErrors; 420 u64 OutOfRangeLengthField; 421 u64 FrameTooLongErrors; 422 ); 423}; 424 425/* Basic IEEE 802.3 PHY statistics (30.3.2.1.*), not otherwise exposed 426 * via a more targeted API. 427 */ 428struct ethtool_eth_phy_stats { 429 enum ethtool_mac_stats_src src; 430 struct_group(stats, 431 u64 SymbolErrorDuringCarrier; 432 ); 433}; 434 435/** 436 * struct ethtool_phy_stats - PHY-level statistics counters 437 * @rx_packets: Total successfully received frames 438 * @rx_bytes: Total successfully received bytes 439 * @rx_errors: Total received frames with errors (e.g., CRC errors) 440 * @tx_packets: Total successfully transmitted frames 441 * @tx_bytes: Total successfully transmitted bytes 442 * @tx_errors: Total transmitted frames with errors 443 * 444 * This structure provides a standardized interface for reporting 445 * PHY-level statistics counters. It is designed to expose statistics 446 * commonly provided by PHYs but not explicitly defined in the IEEE 447 * 802.3 standard. 448 */ 449struct ethtool_phy_stats { 450 u64 rx_packets; 451 u64 rx_bytes; 452 u64 rx_errors; 453 u64 tx_packets; 454 u64 tx_bytes; 455 u64 tx_errors; 456}; 457 458/* Basic IEEE 802.3 MAC Ctrl statistics (30.3.3.*), not otherwise exposed 459 * via a more targeted API. 460 */ 461struct ethtool_eth_ctrl_stats { 462 enum ethtool_mac_stats_src src; 463 struct_group(stats, 464 u64 MACControlFramesTransmitted; 465 u64 MACControlFramesReceived; 466 u64 UnsupportedOpcodesReceived; 467 ); 468}; 469 470/** 471 * struct ethtool_pause_stats - statistics for IEEE 802.3x pause frames 472 * @src: input field denoting whether stats should be queried from the eMAC or 473 * pMAC (if the MM layer is supported). To be ignored otherwise. 474 * @tx_pause_frames: transmitted pause frame count. Reported to user space 475 * as %ETHTOOL_A_PAUSE_STAT_TX_FRAMES. 476 * 477 * Equivalent to `30.3.4.2 aPAUSEMACCtrlFramesTransmitted` 478 * from the standard. 479 * 480 * @rx_pause_frames: received pause frame count. Reported to user space 481 * as %ETHTOOL_A_PAUSE_STAT_RX_FRAMES. Equivalent to: 482 * 483 * Equivalent to `30.3.4.3 aPAUSEMACCtrlFramesReceived` 484 * from the standard. 485 */ 486struct ethtool_pause_stats { 487 enum ethtool_mac_stats_src src; 488 struct_group(stats, 489 u64 tx_pause_frames; 490 u64 rx_pause_frames; 491 ); 492}; 493 494#define ETHTOOL_MAX_LANES 8 495 496/** 497 * struct ethtool_fec_stats - statistics for IEEE 802.3 FEC 498 * @corrected_blocks: number of received blocks corrected by FEC 499 * Reported to user space as %ETHTOOL_A_FEC_STAT_CORRECTED. 500 * 501 * Equivalent to `30.5.1.1.17 aFECCorrectedBlocks` from the standard. 502 * 503 * @uncorrectable_blocks: number of received blocks FEC was not able to correct 504 * Reported to user space as %ETHTOOL_A_FEC_STAT_UNCORR. 505 * 506 * Equivalent to `30.5.1.1.18 aFECUncorrectableBlocks` from the standard. 507 * 508 * @corrected_bits: number of bits corrected by FEC 509 * Similar to @corrected_blocks but counts individual bit changes, 510 * not entire FEC data blocks. This is a non-standard statistic. 511 * Reported to user space as %ETHTOOL_A_FEC_STAT_CORR_BITS. 512 * 513 * For each of the above fields, the two substructure members are: 514 * 515 * - @lanes: per-lane/PCS-instance counts as defined by the standard 516 * - @total: error counts for the entire port, for drivers incapable of reporting 517 * per-lane stats 518 * 519 * Drivers should fill in either only total or per-lane statistics, core 520 * will take care of adding lane values up to produce the total. 521 */ 522struct ethtool_fec_stats { 523 struct ethtool_fec_stat { 524 u64 total; 525 u64 lanes[ETHTOOL_MAX_LANES]; 526 } corrected_blocks, uncorrectable_blocks, corrected_bits; 527}; 528 529/** 530 * struct ethtool_rmon_hist_range - byte range for histogram statistics 531 * @low: low bound of the bucket (inclusive) 532 * @high: high bound of the bucket (inclusive) 533 */ 534struct ethtool_rmon_hist_range { 535 u16 low; 536 u16 high; 537}; 538 539#define ETHTOOL_RMON_HIST_MAX 10 540 541/** 542 * struct ethtool_rmon_stats - selected RMON (RFC 2819) statistics 543 * @src: input field denoting whether stats should be queried from the eMAC or 544 * pMAC (if the MM layer is supported). To be ignored otherwise. 545 * @undersize_pkts: Equivalent to `etherStatsUndersizePkts` from the RFC. 546 * @oversize_pkts: Equivalent to `etherStatsOversizePkts` from the RFC. 547 * @fragments: Equivalent to `etherStatsFragments` from the RFC. 548 * @jabbers: Equivalent to `etherStatsJabbers` from the RFC. 549 * @hist: Packet counter for packet length buckets (e.g. 550 * `etherStatsPkts128to255Octets` from the RFC). 551 * @hist_tx: Tx counters in similar form to @hist, not defined in the RFC. 552 * 553 * Selection of RMON (RFC 2819) statistics which are not exposed via different 554 * APIs, primarily the packet-length-based counters. 555 * Unfortunately different designs choose different buckets beyond 556 * the 1024B mark (jumbo frame teritory), so the definition of the bucket 557 * ranges is left to the driver. 558 */ 559struct ethtool_rmon_stats { 560 enum ethtool_mac_stats_src src; 561 struct_group(stats, 562 u64 undersize_pkts; 563 u64 oversize_pkts; 564 u64 fragments; 565 u64 jabbers; 566 567 u64 hist[ETHTOOL_RMON_HIST_MAX]; 568 u64 hist_tx[ETHTOOL_RMON_HIST_MAX]; 569 ); 570}; 571 572/** 573 * struct ethtool_ts_stats - HW timestamping statistics 574 * @pkts: Number of packets successfully timestamped by the hardware. 575 * @onestep_pkts_unconfirmed: Number of PTP packets with one-step TX 576 * timestamping that were sent, but for which the 577 * device offers no confirmation whether they made 578 * it onto the wire and the timestamp was inserted 579 * in the originTimestamp or correctionField, or 580 * not. 581 * @lost: Number of hardware timestamping requests where the timestamping 582 * information from the hardware never arrived for submission with 583 * the skb. 584 * @err: Number of arbitrary timestamp generation error events that the 585 * hardware encountered, exclusive of @lost statistics. Cases such 586 * as resource exhaustion, unavailability, firmware errors, and 587 * detected illogical timestamp values not submitted with the skb 588 * are inclusive to this counter. 589 */ 590struct ethtool_ts_stats { 591 struct_group(tx_stats, 592 u64 pkts; 593 u64 onestep_pkts_unconfirmed; 594 u64 lost; 595 u64 err; 596 ); 597}; 598 599#define ETH_MODULE_EEPROM_PAGE_LEN 128 600#define ETH_MODULE_MAX_I2C_ADDRESS 0x7f 601 602/** 603 * struct ethtool_module_eeprom - plug-in module EEPROM read / write parameters 604 * @offset: When @offset is 0-127, it is used as an address to the Lower Memory 605 * (@page must be 0). Otherwise, it is used as an address to the 606 * Upper Memory. 607 * @length: Number of bytes to read / write. 608 * @page: Page number. 609 * @bank: Bank number, if supported by EEPROM spec. 610 * @i2c_address: I2C address of a page. Value less than 0x7f expected. Most 611 * EEPROMs use 0x50 or 0x51. 612 * @data: Pointer to buffer with EEPROM data of @length size. 613 */ 614struct ethtool_module_eeprom { 615 u32 offset; 616 u32 length; 617 u8 page; 618 u8 bank; 619 u8 i2c_address; 620 u8 *data; 621}; 622 623/** 624 * struct ethtool_module_power_mode_params - module power mode parameters 625 * @policy: The power mode policy enforced by the host for the plug-in module. 626 * @mode: The operational power mode of the plug-in module. Should be filled by 627 * device drivers on get operations. 628 */ 629struct ethtool_module_power_mode_params { 630 enum ethtool_module_power_mode_policy policy; 631 enum ethtool_module_power_mode mode; 632}; 633 634/** 635 * struct ethtool_mm_state - 802.3 MAC merge layer state 636 * @verify_time: 637 * wait time between verification attempts in ms (according to clause 638 * 30.14.1.6 aMACMergeVerifyTime) 639 * @max_verify_time: 640 * maximum accepted value for the @verify_time variable in set requests 641 * @verify_status: 642 * state of the verification state machine of the MM layer (according to 643 * clause 30.14.1.2 aMACMergeStatusVerify) 644 * @tx_enabled: 645 * set if the MM layer is administratively enabled in the TX direction 646 * (according to clause 30.14.1.3 aMACMergeEnableTx) 647 * @tx_active: 648 * set if the MM layer is enabled in the TX direction, which makes FP 649 * possible (according to 30.14.1.5 aMACMergeStatusTx). This should be 650 * true if MM is enabled, and the verification status is either verified, 651 * or disabled. 652 * @pmac_enabled: 653 * set if the preemptible MAC is powered on and is able to receive 654 * preemptible packets and respond to verification frames. 655 * @verify_enabled: 656 * set if the Verify function of the MM layer (which sends SMD-V 657 * verification requests) is administratively enabled (regardless of 658 * whether it is currently in the ETHTOOL_MM_VERIFY_STATUS_DISABLED state 659 * or not), according to clause 30.14.1.4 aMACMergeVerifyDisableTx (but 660 * using positive rather than negative logic). The device should always 661 * respond to received SMD-V requests as long as @pmac_enabled is set. 662 * @tx_min_frag_size: 663 * the minimum size of non-final mPacket fragments that the link partner 664 * supports receiving, expressed in octets. Compared to the definition 665 * from clause 30.14.1.7 aMACMergeAddFragSize which is expressed in the 666 * range 0 to 3 (requiring a translation to the size in octets according 667 * to the formula 64 * (1 + addFragSize) - 4), a value in a continuous and 668 * unbounded range can be specified here. 669 * @rx_min_frag_size: 670 * the minimum size of non-final mPacket fragments that this device 671 * supports receiving, expressed in octets. 672 */ 673struct ethtool_mm_state { 674 u32 verify_time; 675 u32 max_verify_time; 676 enum ethtool_mm_verify_status verify_status; 677 bool tx_enabled; 678 bool tx_active; 679 bool pmac_enabled; 680 bool verify_enabled; 681 u32 tx_min_frag_size; 682 u32 rx_min_frag_size; 683}; 684 685/** 686 * struct ethtool_mm_cfg - 802.3 MAC merge layer configuration 687 * @verify_time: see struct ethtool_mm_state 688 * @verify_enabled: see struct ethtool_mm_state 689 * @tx_enabled: see struct ethtool_mm_state 690 * @pmac_enabled: see struct ethtool_mm_state 691 * @tx_min_frag_size: see struct ethtool_mm_state 692 */ 693struct ethtool_mm_cfg { 694 u32 verify_time; 695 bool verify_enabled; 696 bool tx_enabled; 697 bool pmac_enabled; 698 u32 tx_min_frag_size; 699}; 700 701/** 702 * struct ethtool_mm_stats - 802.3 MAC merge layer statistics 703 * @MACMergeFrameAssErrorCount: 704 * received MAC frames with reassembly errors 705 * @MACMergeFrameSmdErrorCount: 706 * received MAC frames/fragments rejected due to unknown or incorrect SMD 707 * @MACMergeFrameAssOkCount: 708 * received MAC frames that were successfully reassembled and passed up 709 * @MACMergeFragCountRx: 710 * number of additional correct SMD-C mPackets received due to preemption 711 * @MACMergeFragCountTx: 712 * number of additional mPackets sent due to preemption 713 * @MACMergeHoldCount: 714 * number of times the MM layer entered the HOLD state, which blocks 715 * transmission of preemptible traffic 716 */ 717struct ethtool_mm_stats { 718 u64 MACMergeFrameAssErrorCount; 719 u64 MACMergeFrameSmdErrorCount; 720 u64 MACMergeFrameAssOkCount; 721 u64 MACMergeFragCountRx; 722 u64 MACMergeFragCountTx; 723 u64 MACMergeHoldCount; 724}; 725 726enum ethtool_mmsv_event { 727 ETHTOOL_MMSV_LP_SENT_VERIFY_MPACKET, 728 ETHTOOL_MMSV_LD_SENT_VERIFY_MPACKET, 729 ETHTOOL_MMSV_LP_SENT_RESPONSE_MPACKET, 730}; 731 732/* MAC Merge verification mPacket type */ 733enum ethtool_mpacket { 734 ETHTOOL_MPACKET_VERIFY, 735 ETHTOOL_MPACKET_RESPONSE, 736}; 737 738struct ethtool_mmsv; 739 740/** 741 * struct ethtool_mmsv_ops - Operations for MAC Merge Software Verification 742 * @configure_tx: Driver callback for the event where the preemptible TX 743 * becomes active or inactive. Preemptible traffic 744 * classes must be committed to hardware only while 745 * preemptible TX is active. 746 * @configure_pmac: Driver callback for the event where the pMAC state 747 * changes as result of an administrative setting 748 * (ethtool) or a call to ethtool_mmsv_link_state_handle(). 749 * @send_mpacket: Driver-provided method for sending a Verify or a Response 750 * mPacket. 751 */ 752struct ethtool_mmsv_ops { 753 void (*configure_tx)(struct ethtool_mmsv *mmsv, bool tx_active); 754 void (*configure_pmac)(struct ethtool_mmsv *mmsv, bool pmac_enabled); 755 void (*send_mpacket)(struct ethtool_mmsv *mmsv, enum ethtool_mpacket mpacket); 756}; 757 758/** 759 * struct ethtool_mmsv - MAC Merge Software Verification 760 * @ops: operations for MAC Merge Software Verification 761 * @dev: pointer to net_device structure 762 * @lock: serialize access to MAC Merge state between 763 * ethtool requests and link state updates. 764 * @status: current verification FSM state 765 * @verify_timer: timer for verification in local TX direction 766 * @verify_enabled: indicates if verification is enabled 767 * @verify_retries: number of retries for verification 768 * @pmac_enabled: indicates if the preemptible MAC is enabled 769 * @verify_time: time for verification in milliseconds 770 * @tx_enabled: indicates if transmission is enabled 771 */ 772struct ethtool_mmsv { 773 const struct ethtool_mmsv_ops *ops; 774 struct net_device *dev; 775 spinlock_t lock; 776 enum ethtool_mm_verify_status status; 777 struct timer_list verify_timer; 778 bool verify_enabled; 779 int verify_retries; 780 bool pmac_enabled; 781 u32 verify_time; 782 bool tx_enabled; 783}; 784 785void ethtool_mmsv_stop(struct ethtool_mmsv *mmsv); 786void ethtool_mmsv_link_state_handle(struct ethtool_mmsv *mmsv, bool up); 787void ethtool_mmsv_event_handle(struct ethtool_mmsv *mmsv, 788 enum ethtool_mmsv_event event); 789void ethtool_mmsv_get_mm(struct ethtool_mmsv *mmsv, 790 struct ethtool_mm_state *state); 791void ethtool_mmsv_set_mm(struct ethtool_mmsv *mmsv, struct ethtool_mm_cfg *cfg); 792void ethtool_mmsv_init(struct ethtool_mmsv *mmsv, struct net_device *dev, 793 const struct ethtool_mmsv_ops *ops); 794 795/** 796 * struct ethtool_rxfh_param - RXFH (RSS) parameters 797 * @hfunc: Defines the current RSS hash function used by HW (or to be set to). 798 * Valid values are one of the %ETH_RSS_HASH_*. 799 * @indir_size: On SET, the array size of the user buffer for the 800 * indirection table, which may be zero, or 801 * %ETH_RXFH_INDIR_NO_CHANGE. On GET (read from the driver), 802 * the array size of the hardware indirection table. 803 * @indir: The indirection table of size @indir_size entries. 804 * @key_size: On SET, the array size of the user buffer for the hash key, 805 * which may be zero. On GET (read from the driver), the size of the 806 * hardware hash key. 807 * @key: The hash key of size @key_size bytes. 808 * @rss_context: RSS context identifier. Context 0 is the default for normal 809 * traffic; other contexts can be referenced as the destination for RX flow 810 * classification rules. On SET, %ETH_RXFH_CONTEXT_ALLOC is used 811 * to allocate a new RSS context; on return this field will 812 * contain the ID of the newly allocated context. 813 * @rss_delete: Set to non-ZERO to remove the @rss_context context. 814 * @input_xfrm: Defines how the input data is transformed. Valid values are one 815 * of %RXH_XFRM_*. 816 */ 817struct ethtool_rxfh_param { 818 u8 hfunc; 819 u32 indir_size; 820 u32 *indir; 821 u32 key_size; 822 u8 *key; 823 u32 rss_context; 824 u8 rss_delete; 825 u8 input_xfrm; 826}; 827 828/** 829 * struct kernel_ethtool_ts_info - kernel copy of struct ethtool_ts_info 830 * @cmd: command number = %ETHTOOL_GET_TS_INFO 831 * @so_timestamping: bit mask of the sum of the supported SO_TIMESTAMPING flags 832 * @phc_index: device index of the associated PHC, or -1 if there is none 833 * @phc_qualifier: qualifier of the associated PHC 834 * @phc_source: source device of the associated PHC 835 * @phc_phyindex: index of PHY device source of the associated PHC 836 * @tx_types: bit mask of the supported hwtstamp_tx_types enumeration values 837 * @rx_filters: bit mask of the supported hwtstamp_rx_filters enumeration values 838 */ 839struct kernel_ethtool_ts_info { 840 u32 cmd; 841 u32 so_timestamping; 842 int phc_index; 843 enum hwtstamp_provider_qualifier phc_qualifier; 844 enum hwtstamp_source phc_source; 845 int phc_phyindex; 846 enum hwtstamp_tx_types tx_types; 847 enum hwtstamp_rx_filters rx_filters; 848}; 849 850/** 851 * struct ethtool_ops - optional netdev operations 852 * @supported_input_xfrm: supported types of input xfrm from %RXH_XFRM_*. 853 * @cap_link_lanes_supported: indicates if the driver supports lanes 854 * parameter. 855 * @cap_rss_ctx_supported: indicates if the driver supports RSS 856 * contexts via legacy API, drivers implementing @create_rxfh_context 857 * do not have to set this bit. 858 * @rxfh_per_ctx_key: device supports setting different RSS key for each 859 * additional context. Netlink API should report hfunc, key, and input_xfrm 860 * for every context, not just context 0. 861 * @cap_rss_rxnfc_adds: device supports nonzero ring_cookie in filters with 862 * %FLOW_RSS flag; the queue ID from the filter is added to the value from 863 * the indirection table to determine the delivery queue. 864 * @rxfh_indir_space: max size of RSS indirection tables, if indirection table 865 * size as returned by @get_rxfh_indir_size may change during lifetime 866 * of the device. Leave as 0 if the table size is constant. 867 * @rxfh_key_space: same as @rxfh_indir_space, but for the key. 868 * @rxfh_priv_size: size of the driver private data area the core should 869 * allocate for an RSS context (in &struct ethtool_rxfh_context). 870 * @rxfh_max_num_contexts: maximum (exclusive) supported RSS context ID. 871 * If this is zero then the core may choose any (nonzero) ID, otherwise 872 * the core will only use IDs strictly less than this value, as the 873 * @rss_context argument to @create_rxfh_context and friends. 874 * @supported_coalesce_params: supported types of interrupt coalescing. 875 * @supported_ring_params: supported ring params. 876 * @supported_hwtstamp_qualifiers: bitfield of supported hwtstamp qualifier. 877 * @get_drvinfo: Report driver/device information. Modern drivers no 878 * longer have to implement this callback. Most fields are 879 * correctly filled in by the core using system information, or 880 * populated using other driver operations. 881 * @get_regs_len: Get buffer length required for @get_regs 882 * @get_regs: Get device registers 883 * @get_wol: Report whether Wake-on-Lan is enabled 884 * @set_wol: Turn Wake-on-Lan on or off. Returns a negative error code 885 * or zero. 886 * @get_msglevel: Report driver message level. This should be the value 887 * of the @msg_enable field used by netif logging functions. 888 * @set_msglevel: Set driver message level 889 * @nway_reset: Restart autonegotiation. Returns a negative error code 890 * or zero. 891 * @get_link: Report whether physical link is up. Will only be called if 892 * the netdev is up. Should usually be set to ethtool_op_get_link(), 893 * which uses netif_carrier_ok(). 894 * @get_link_ext_state: Report link extended state. Should set link_ext_state and 895 * link_ext_substate (link_ext_substate of 0 means link_ext_substate is unknown, 896 * do not attach ext_substate attribute to netlink message). If link_ext_state 897 * and link_ext_substate are unknown, return -ENODATA. If not implemented, 898 * link_ext_state and link_ext_substate will not be sent to userspace. 899 * @get_link_ext_stats: Read extra link-related counters. 900 * @get_eeprom_len: Read range of EEPROM addresses for validation of 901 * @get_eeprom and @set_eeprom requests. 902 * Returns 0 if device does not support EEPROM access. 903 * @get_eeprom: Read data from the device EEPROM. 904 * Should fill in the magic field. Don't need to check len for zero 905 * or wraparound. Fill in the data argument with the eeprom values 906 * from offset to offset + len. Update len to the amount read. 907 * Returns an error or zero. 908 * @set_eeprom: Write data to the device EEPROM. 909 * Should validate the magic field. Don't need to check len for zero 910 * or wraparound. Update len to the amount written. Returns an error 911 * or zero. 912 * @get_coalesce: Get interrupt coalescing parameters. Returns a negative 913 * error code or zero. 914 * @set_coalesce: Set interrupt coalescing parameters. Supported coalescing 915 * types should be set in @supported_coalesce_params. 916 * Returns a negative error code or zero. 917 * @get_ringparam: Report ring sizes 918 * @set_ringparam: Set ring sizes. Returns a negative error code or zero. 919 * @get_pause_stats: Report pause frame statistics. Drivers must not zero 920 * statistics which they don't report. The stats structure is initialized 921 * to ETHTOOL_STAT_NOT_SET indicating driver does not report statistics. 922 * @get_pauseparam: Report pause parameters 923 * @set_pauseparam: Set pause parameters. Returns a negative error code 924 * or zero. 925 * @self_test: Run specified self-tests 926 * @get_strings: Return a set of strings that describe the requested objects 927 * @set_phys_id: Identify the physical devices, e.g. by flashing an LED 928 * attached to it. The implementation may update the indicator 929 * asynchronously or synchronously, but in either case it must return 930 * quickly. It is initially called with the argument %ETHTOOL_ID_ACTIVE, 931 * and must either activate asynchronous updates and return zero, return 932 * a negative error or return a positive frequency for synchronous 933 * indication (e.g. 1 for one on/off cycle per second). If it returns 934 * a frequency then it will be called again at intervals with the 935 * argument %ETHTOOL_ID_ON or %ETHTOOL_ID_OFF and should set the state of 936 * the indicator accordingly. Finally, it is called with the argument 937 * %ETHTOOL_ID_INACTIVE and must deactivate the indicator. Returns a 938 * negative error code or zero. 939 * @get_ethtool_stats: Return extended statistics about the device. 940 * This is only useful if the device maintains statistics not 941 * included in &struct rtnl_link_stats64. 942 * @begin: Function to be called before any other operation. Returns a 943 * negative error code or zero. 944 * @complete: Function to be called after any other operation except 945 * @begin. Will be called even if the other operation failed. 946 * @get_priv_flags: Report driver-specific feature flags. 947 * @set_priv_flags: Set driver-specific feature flags. Returns a negative 948 * error code or zero. 949 * @get_sset_count: Get number of strings that @get_strings will write. 950 * @get_rxnfc: Get RX flow classification rules. Returns a negative 951 * error code or zero. 952 * @set_rxnfc: Set RX flow classification rules. Returns a negative 953 * error code or zero. 954 * @flash_device: Write a firmware image to device's flash memory. 955 * Returns a negative error code or zero. 956 * @reset: Reset (part of) the device, as specified by a bitmask of 957 * flags from &enum ethtool_reset_flags. Returns a negative 958 * error code or zero. 959 * @get_rxfh_key_size: Get the size of the RX flow hash key. 960 * Returns zero if not supported for this specific device. 961 * @get_rxfh_indir_size: Get the size of the RX flow hash indirection table. 962 * Returns zero if not supported for this specific device. 963 * @get_rxfh: Get the contents of the RX flow hash indirection table, hash key 964 * and/or hash function. 965 * Returns a negative error code or zero. 966 * @set_rxfh: Set the contents of the RX flow hash indirection table, hash 967 * key, and/or hash function. Arguments which are set to %NULL or zero 968 * will remain unchanged. 969 * Returns a negative error code or zero. An error code must be returned 970 * if at least one unsupported change was requested. 971 * @create_rxfh_context: Create a new RSS context with the specified RX flow 972 * hash indirection table, hash key, and hash function. 973 * The &struct ethtool_rxfh_context for this context is passed in @ctx; 974 * note that the indir table, hkey and hfunc are not yet populated as 975 * of this call. The driver does not need to update these; the core 976 * will do so if this op succeeds. 977 * However, if @rxfh.indir is set to %NULL, the driver must update the 978 * indir table in @ctx with the (default or inherited) table actually in 979 * use; similarly, if @rxfh.key is %NULL, @rxfh.hfunc is 980 * %ETH_RSS_HASH_NO_CHANGE, or @rxfh.input_xfrm is %RXH_XFRM_NO_CHANGE, 981 * the driver should update the corresponding information in @ctx. 982 * If the driver provides this method, it must also provide 983 * @modify_rxfh_context and @remove_rxfh_context. 984 * Returns a negative error code or zero. 985 * @modify_rxfh_context: Reconfigure the specified RSS context. Allows setting 986 * the contents of the RX flow hash indirection table, hash key, and/or 987 * hash function associated with the given context. 988 * Parameters which are set to %NULL or zero will remain unchanged. 989 * The &struct ethtool_rxfh_context for this context is passed in @ctx; 990 * note that it will still contain the *old* settings. The driver does 991 * not need to update these; the core will do so if this op succeeds. 992 * Returns a negative error code or zero. An error code must be returned 993 * if at least one unsupported change was requested. 994 * @remove_rxfh_context: Remove the specified RSS context. 995 * The &struct ethtool_rxfh_context for this context is passed in @ctx. 996 * Returns a negative error code or zero. 997 * @get_channels: Get number of channels. 998 * @set_channels: Set number of channels. Returns a negative error code or 999 * zero. 1000 * @get_dump_flag: Get dump flag indicating current dump length, version, 1001 * and flag of the device. 1002 * @get_dump_data: Get dump data. 1003 * @set_dump: Set dump specific flags to the device. 1004 * @get_ts_info: Get the time stamping and PTP hardware clock capabilities. 1005 * It may be called with RCU, or rtnl or reference on the device. 1006 * Drivers supporting transmit time stamps in software should set this to 1007 * ethtool_op_get_ts_info(). 1008 * @get_ts_stats: Query the device hardware timestamping statistics. Drivers 1009 * must not zero statistics which they don't report. The stats structure 1010 * is initialized to ETHTOOL_STAT_NOT_SET indicating driver does not 1011 * report statistics. 1012 * @get_module_info: Get the size and type of the eeprom contained within 1013 * a plug-in module. 1014 * @get_module_eeprom: Get the eeprom information from the plug-in module 1015 * @get_eee: Get Energy-Efficient (EEE) supported and status. 1016 * @set_eee: Set EEE status (enable/disable) as well as LPI timers. 1017 * @get_tunable: Read the value of a driver / device tunable. 1018 * @set_tunable: Set the value of a driver / device tunable. 1019 * @get_per_queue_coalesce: Get interrupt coalescing parameters per queue. 1020 * It must check that the given queue number is valid. If neither a RX nor 1021 * a TX queue has this number, return -EINVAL. If only a RX queue or a TX 1022 * queue has this number, set the inapplicable fields to ~0 and return 0. 1023 * Returns a negative error code or zero. 1024 * @set_per_queue_coalesce: Set interrupt coalescing parameters per queue. 1025 * It must check that the given queue number is valid. If neither a RX nor 1026 * a TX queue has this number, return -EINVAL. If only a RX queue or a TX 1027 * queue has this number, ignore the inapplicable fields. Supported 1028 * coalescing types should be set in @supported_coalesce_params. 1029 * Returns a negative error code or zero. 1030 * @get_link_ksettings: Get various device settings including Ethernet link 1031 * settings. The %cmd and %link_mode_masks_nwords fields should be 1032 * ignored (use %__ETHTOOL_LINK_MODE_MASK_NBITS instead of the latter), 1033 * any change to them will be overwritten by kernel. Returns a negative 1034 * error code or zero. 1035 * @set_link_ksettings: Set various device settings including Ethernet link 1036 * settings. The %cmd and %link_mode_masks_nwords fields should be 1037 * ignored (use %__ETHTOOL_LINK_MODE_MASK_NBITS instead of the latter), 1038 * any change to them will be overwritten by kernel. Returns a negative 1039 * error code or zero. 1040 * @get_fec_stats: Report FEC statistics. 1041 * Core will sum up per-lane stats to get the total. 1042 * Drivers must not zero statistics which they don't report. The stats 1043 * structure is initialized to ETHTOOL_STAT_NOT_SET indicating driver does 1044 * not report statistics. 1045 * @get_fecparam: Get the network device Forward Error Correction parameters. 1046 * @set_fecparam: Set the network device Forward Error Correction parameters. 1047 * @get_ethtool_phy_stats: Return extended statistics about the PHY device. 1048 * This is only useful if the device maintains PHY statistics and 1049 * cannot use the standard PHY library helpers. 1050 * @get_phy_tunable: Read the value of a PHY tunable. 1051 * @set_phy_tunable: Set the value of a PHY tunable. 1052 * @get_module_eeprom_by_page: Get a region of plug-in module EEPROM data from 1053 * specified page. Returns a negative error code or the amount of bytes 1054 * read. 1055 * @set_module_eeprom_by_page: Write to a region of plug-in module EEPROM, 1056 * from kernel space only. Returns a negative error code or zero. 1057 * @get_eth_phy_stats: Query some of the IEEE 802.3 PHY statistics. 1058 * @get_eth_mac_stats: Query some of the IEEE 802.3 MAC statistics. 1059 * @get_eth_ctrl_stats: Query some of the IEEE 802.3 MAC Ctrl statistics. 1060 * @get_rmon_stats: Query some of the RMON (RFC 2819) statistics. 1061 * Set %ranges to a pointer to zero-terminated array of byte ranges. 1062 * @get_module_power_mode: Get the power mode policy for the plug-in module 1063 * used by the network device and its operational power mode, if 1064 * plugged-in. 1065 * @set_module_power_mode: Set the power mode policy for the plug-in module 1066 * used by the network device. 1067 * @get_mm: Query the 802.3 MAC Merge layer state. 1068 * @set_mm: Set the 802.3 MAC Merge layer parameters. 1069 * @get_mm_stats: Query the 802.3 MAC Merge layer statistics. 1070 * 1071 * All operations are optional (i.e. the function pointer may be set 1072 * to %NULL) and callers must take this into account. Callers must 1073 * hold the RTNL lock. 1074 * 1075 * See the structures used by these operations for further documentation. 1076 * Note that for all operations using a structure ending with a zero- 1077 * length array, the array is allocated separately in the kernel and 1078 * is passed to the driver as an additional parameter. 1079 * 1080 * See &struct net_device and &struct net_device_ops for documentation 1081 * of the generic netdev features interface. 1082 */ 1083struct ethtool_ops { 1084 u32 supported_input_xfrm:8; 1085 u32 cap_link_lanes_supported:1; 1086 u32 cap_rss_ctx_supported:1; 1087 u32 rxfh_per_ctx_key:1; 1088 u32 cap_rss_rxnfc_adds:1; 1089 u32 rxfh_indir_space; 1090 u16 rxfh_key_space; 1091 u16 rxfh_priv_size; 1092 u32 rxfh_max_num_contexts; 1093 u32 supported_coalesce_params; 1094 u32 supported_ring_params; 1095 u32 supported_hwtstamp_qualifiers; 1096 void (*get_drvinfo)(struct net_device *, struct ethtool_drvinfo *); 1097 int (*get_regs_len)(struct net_device *); 1098 void (*get_regs)(struct net_device *, struct ethtool_regs *, void *); 1099 void (*get_wol)(struct net_device *, struct ethtool_wolinfo *); 1100 int (*set_wol)(struct net_device *, struct ethtool_wolinfo *); 1101 u32 (*get_msglevel)(struct net_device *); 1102 void (*set_msglevel)(struct net_device *, u32); 1103 int (*nway_reset)(struct net_device *); 1104 u32 (*get_link)(struct net_device *); 1105 int (*get_link_ext_state)(struct net_device *, 1106 struct ethtool_link_ext_state_info *); 1107 void (*get_link_ext_stats)(struct net_device *dev, 1108 struct ethtool_link_ext_stats *stats); 1109 int (*get_eeprom_len)(struct net_device *); 1110 int (*get_eeprom)(struct net_device *, 1111 struct ethtool_eeprom *, u8 *); 1112 int (*set_eeprom)(struct net_device *, 1113 struct ethtool_eeprom *, u8 *); 1114 int (*get_coalesce)(struct net_device *, 1115 struct ethtool_coalesce *, 1116 struct kernel_ethtool_coalesce *, 1117 struct netlink_ext_ack *); 1118 int (*set_coalesce)(struct net_device *, 1119 struct ethtool_coalesce *, 1120 struct kernel_ethtool_coalesce *, 1121 struct netlink_ext_ack *); 1122 void (*get_ringparam)(struct net_device *, 1123 struct ethtool_ringparam *, 1124 struct kernel_ethtool_ringparam *, 1125 struct netlink_ext_ack *); 1126 int (*set_ringparam)(struct net_device *, 1127 struct ethtool_ringparam *, 1128 struct kernel_ethtool_ringparam *, 1129 struct netlink_ext_ack *); 1130 void (*get_pause_stats)(struct net_device *dev, 1131 struct ethtool_pause_stats *pause_stats); 1132 void (*get_pauseparam)(struct net_device *, 1133 struct ethtool_pauseparam*); 1134 int (*set_pauseparam)(struct net_device *, 1135 struct ethtool_pauseparam*); 1136 void (*self_test)(struct net_device *, struct ethtool_test *, u64 *); 1137 void (*get_strings)(struct net_device *, u32 stringset, u8 *); 1138 int (*set_phys_id)(struct net_device *, enum ethtool_phys_id_state); 1139 void (*get_ethtool_stats)(struct net_device *, 1140 struct ethtool_stats *, u64 *); 1141 int (*begin)(struct net_device *); 1142 void (*complete)(struct net_device *); 1143 u32 (*get_priv_flags)(struct net_device *); 1144 int (*set_priv_flags)(struct net_device *, u32); 1145 int (*get_sset_count)(struct net_device *, int); 1146 int (*get_rxnfc)(struct net_device *, 1147 struct ethtool_rxnfc *, u32 *rule_locs); 1148 int (*set_rxnfc)(struct net_device *, struct ethtool_rxnfc *); 1149 int (*flash_device)(struct net_device *, struct ethtool_flash *); 1150 int (*reset)(struct net_device *, u32 *); 1151 u32 (*get_rxfh_key_size)(struct net_device *); 1152 u32 (*get_rxfh_indir_size)(struct net_device *); 1153 int (*get_rxfh)(struct net_device *, struct ethtool_rxfh_param *); 1154 int (*set_rxfh)(struct net_device *, struct ethtool_rxfh_param *, 1155 struct netlink_ext_ack *extack); 1156 int (*create_rxfh_context)(struct net_device *, 1157 struct ethtool_rxfh_context *ctx, 1158 const struct ethtool_rxfh_param *rxfh, 1159 struct netlink_ext_ack *extack); 1160 int (*modify_rxfh_context)(struct net_device *, 1161 struct ethtool_rxfh_context *ctx, 1162 const struct ethtool_rxfh_param *rxfh, 1163 struct netlink_ext_ack *extack); 1164 int (*remove_rxfh_context)(struct net_device *, 1165 struct ethtool_rxfh_context *ctx, 1166 u32 rss_context, 1167 struct netlink_ext_ack *extack); 1168 void (*get_channels)(struct net_device *, struct ethtool_channels *); 1169 int (*set_channels)(struct net_device *, struct ethtool_channels *); 1170 int (*get_dump_flag)(struct net_device *, struct ethtool_dump *); 1171 int (*get_dump_data)(struct net_device *, 1172 struct ethtool_dump *, void *); 1173 int (*set_dump)(struct net_device *, struct ethtool_dump *); 1174 int (*get_ts_info)(struct net_device *, struct kernel_ethtool_ts_info *); 1175 void (*get_ts_stats)(struct net_device *dev, 1176 struct ethtool_ts_stats *ts_stats); 1177 int (*get_module_info)(struct net_device *, 1178 struct ethtool_modinfo *); 1179 int (*get_module_eeprom)(struct net_device *, 1180 struct ethtool_eeprom *, u8 *); 1181 int (*get_eee)(struct net_device *dev, struct ethtool_keee *eee); 1182 int (*set_eee)(struct net_device *dev, struct ethtool_keee *eee); 1183 int (*get_tunable)(struct net_device *, 1184 const struct ethtool_tunable *, void *); 1185 int (*set_tunable)(struct net_device *, 1186 const struct ethtool_tunable *, const void *); 1187 int (*get_per_queue_coalesce)(struct net_device *, u32, 1188 struct ethtool_coalesce *); 1189 int (*set_per_queue_coalesce)(struct net_device *, u32, 1190 struct ethtool_coalesce *); 1191 int (*get_link_ksettings)(struct net_device *, 1192 struct ethtool_link_ksettings *); 1193 int (*set_link_ksettings)(struct net_device *, 1194 const struct ethtool_link_ksettings *); 1195 void (*get_fec_stats)(struct net_device *dev, 1196 struct ethtool_fec_stats *fec_stats); 1197 int (*get_fecparam)(struct net_device *, 1198 struct ethtool_fecparam *); 1199 int (*set_fecparam)(struct net_device *, 1200 struct ethtool_fecparam *); 1201 void (*get_ethtool_phy_stats)(struct net_device *, 1202 struct ethtool_stats *, u64 *); 1203 int (*get_phy_tunable)(struct net_device *, 1204 const struct ethtool_tunable *, void *); 1205 int (*set_phy_tunable)(struct net_device *, 1206 const struct ethtool_tunable *, const void *); 1207 int (*get_module_eeprom_by_page)(struct net_device *dev, 1208 const struct ethtool_module_eeprom *page, 1209 struct netlink_ext_ack *extack); 1210 int (*set_module_eeprom_by_page)(struct net_device *dev, 1211 const struct ethtool_module_eeprom *page, 1212 struct netlink_ext_ack *extack); 1213 void (*get_eth_phy_stats)(struct net_device *dev, 1214 struct ethtool_eth_phy_stats *phy_stats); 1215 void (*get_eth_mac_stats)(struct net_device *dev, 1216 struct ethtool_eth_mac_stats *mac_stats); 1217 void (*get_eth_ctrl_stats)(struct net_device *dev, 1218 struct ethtool_eth_ctrl_stats *ctrl_stats); 1219 void (*get_rmon_stats)(struct net_device *dev, 1220 struct ethtool_rmon_stats *rmon_stats, 1221 const struct ethtool_rmon_hist_range **ranges); 1222 int (*get_module_power_mode)(struct net_device *dev, 1223 struct ethtool_module_power_mode_params *params, 1224 struct netlink_ext_ack *extack); 1225 int (*set_module_power_mode)(struct net_device *dev, 1226 const struct ethtool_module_power_mode_params *params, 1227 struct netlink_ext_ack *extack); 1228 int (*get_mm)(struct net_device *dev, struct ethtool_mm_state *state); 1229 int (*set_mm)(struct net_device *dev, struct ethtool_mm_cfg *cfg, 1230 struct netlink_ext_ack *extack); 1231 void (*get_mm_stats)(struct net_device *dev, struct ethtool_mm_stats *stats); 1232}; 1233 1234int ethtool_check_ops(const struct ethtool_ops *ops); 1235 1236struct ethtool_rx_flow_rule { 1237 struct flow_rule *rule; 1238 unsigned long priv[]; 1239}; 1240 1241struct ethtool_rx_flow_spec_input { 1242 const struct ethtool_rx_flow_spec *fs; 1243 u32 rss_ctx; 1244}; 1245 1246struct ethtool_rx_flow_rule * 1247ethtool_rx_flow_rule_create(const struct ethtool_rx_flow_spec_input *input); 1248void ethtool_rx_flow_rule_destroy(struct ethtool_rx_flow_rule *rule); 1249 1250bool ethtool_virtdev_validate_cmd(const struct ethtool_link_ksettings *cmd); 1251int ethtool_virtdev_set_link_ksettings(struct net_device *dev, 1252 const struct ethtool_link_ksettings *cmd, 1253 u32 *dev_speed, u8 *dev_duplex); 1254 1255/** 1256 * struct ethtool_netdev_state - per-netdevice state for ethtool features 1257 * @rss_ctx: XArray of custom RSS contexts 1258 * @rss_lock: Protects entries in @rss_ctx. May be taken from 1259 * within RTNL. 1260 * @wol_enabled: Wake-on-LAN is enabled 1261 * @module_fw_flash_in_progress: Module firmware flashing is in progress. 1262 */ 1263struct ethtool_netdev_state { 1264 struct xarray rss_ctx; 1265 struct mutex rss_lock; 1266 unsigned wol_enabled:1; 1267 unsigned module_fw_flash_in_progress:1; 1268}; 1269 1270struct phy_device; 1271struct phy_tdr_config; 1272struct phy_plca_cfg; 1273struct phy_plca_status; 1274 1275/** 1276 * struct ethtool_phy_ops - Optional PHY device options 1277 * @get_sset_count: Get number of strings that @get_strings will write. 1278 * @get_strings: Return a set of strings that describe the requested objects 1279 * @get_stats: Return extended statistics about the PHY device. 1280 * @get_plca_cfg: Return PLCA configuration. 1281 * @set_plca_cfg: Set PLCA configuration. 1282 * @get_plca_status: Get PLCA configuration. 1283 * @start_cable_test: Start a cable test 1284 * @start_cable_test_tdr: Start a Time Domain Reflectometry cable test 1285 * 1286 * All operations are optional (i.e. the function pointer may be set to %NULL) 1287 * and callers must take this into account. Callers must hold the RTNL lock. 1288 */ 1289struct ethtool_phy_ops { 1290 int (*get_sset_count)(struct phy_device *dev); 1291 int (*get_strings)(struct phy_device *dev, u8 *data); 1292 int (*get_stats)(struct phy_device *dev, 1293 struct ethtool_stats *stats, u64 *data); 1294 int (*get_plca_cfg)(struct phy_device *dev, 1295 struct phy_plca_cfg *plca_cfg); 1296 int (*set_plca_cfg)(struct phy_device *dev, 1297 const struct phy_plca_cfg *plca_cfg, 1298 struct netlink_ext_ack *extack); 1299 int (*get_plca_status)(struct phy_device *dev, 1300 struct phy_plca_status *plca_st); 1301 int (*start_cable_test)(struct phy_device *phydev, 1302 struct netlink_ext_ack *extack); 1303 int (*start_cable_test_tdr)(struct phy_device *phydev, 1304 struct netlink_ext_ack *extack, 1305 const struct phy_tdr_config *config); 1306}; 1307 1308/** 1309 * ethtool_set_ethtool_phy_ops - Set the ethtool_phy_ops singleton 1310 * @ops: Ethtool PHY operations to set 1311 */ 1312void ethtool_set_ethtool_phy_ops(const struct ethtool_phy_ops *ops); 1313 1314/** 1315 * ethtool_params_from_link_mode - Derive link parameters from a given link mode 1316 * @link_ksettings: Link parameters to be derived from the link mode 1317 * @link_mode: Link mode 1318 */ 1319void 1320ethtool_params_from_link_mode(struct ethtool_link_ksettings *link_ksettings, 1321 enum ethtool_link_mode_bit_indices link_mode); 1322 1323/** 1324 * ethtool_get_phc_vclocks - Derive phc vclocks information, and caller 1325 * is responsible to free memory of vclock_index 1326 * @dev: pointer to net_device structure 1327 * @vclock_index: pointer to pointer of vclock index 1328 * 1329 * Return: number of phc vclocks 1330 */ 1331int ethtool_get_phc_vclocks(struct net_device *dev, int **vclock_index); 1332 1333/* Some generic methods drivers may use in their ethtool_ops */ 1334u32 ethtool_op_get_link(struct net_device *dev); 1335int ethtool_op_get_ts_info(struct net_device *dev, 1336 struct kernel_ethtool_ts_info *eti); 1337 1338/** 1339 * ethtool_mm_frag_size_add_to_min - Translate (standard) additional fragment 1340 * size expressed as multiplier into (absolute) minimum fragment size 1341 * value expressed in octets 1342 * @val_add: Value of addFragSize multiplier 1343 */ 1344static inline u32 ethtool_mm_frag_size_add_to_min(u32 val_add) 1345{ 1346 return (ETH_ZLEN + ETH_FCS_LEN) * (1 + val_add) - ETH_FCS_LEN; 1347} 1348 1349/** 1350 * ethtool_mm_frag_size_min_to_add - Translate (absolute) minimum fragment size 1351 * expressed in octets into (standard) additional fragment size expressed 1352 * as multiplier 1353 * @val_min: Value of addFragSize variable in octets 1354 * @val_add: Pointer where the standard addFragSize value is to be returned 1355 * @extack: Netlink extended ack 1356 * 1357 * Translate a value in octets to one of 0, 1, 2, 3 according to the reverse 1358 * application of the 802.3 formula 64 * (1 + addFragSize) - 4. To be called 1359 * by drivers which do not support programming the minimum fragment size to a 1360 * continuous range. Returns error on other fragment length values. 1361 */ 1362static inline int ethtool_mm_frag_size_min_to_add(u32 val_min, u32 *val_add, 1363 struct netlink_ext_ack *extack) 1364{ 1365 u32 add_frag_size; 1366 1367 for (add_frag_size = 0; add_frag_size < 4; add_frag_size++) { 1368 if (ethtool_mm_frag_size_add_to_min(add_frag_size) == val_min) { 1369 *val_add = add_frag_size; 1370 return 0; 1371 } 1372 } 1373 1374 NL_SET_ERR_MSG_MOD(extack, 1375 "minFragSize required to be one of 60, 124, 188 or 252"); 1376 return -EINVAL; 1377} 1378 1379/** 1380 * ethtool_get_ts_info_by_layer - Obtains time stamping capabilities from the MAC or PHY layer. 1381 * @dev: pointer to net_device structure 1382 * @info: buffer to hold the result 1383 * Returns: zero on success, non-zero otherwise. 1384 */ 1385int ethtool_get_ts_info_by_layer(struct net_device *dev, 1386 struct kernel_ethtool_ts_info *info); 1387 1388/** 1389 * ethtool_sprintf - Write formatted string to ethtool string data 1390 * @data: Pointer to a pointer to the start of string to update 1391 * @fmt: Format of string to write 1392 * 1393 * Write formatted string to *data. Update *data to point at start of 1394 * next string. 1395 */ 1396extern __printf(2, 3) void ethtool_sprintf(u8 **data, const char *fmt, ...); 1397 1398/** 1399 * ethtool_puts - Write string to ethtool string data 1400 * @data: Pointer to a pointer to the start of string to update 1401 * @str: String to write 1402 * 1403 * Write string to *data without a trailing newline. Update *data 1404 * to point at start of next string. 1405 * 1406 * Prefer this function to ethtool_sprintf() when given only 1407 * two arguments or if @fmt is just "%s". 1408 */ 1409extern void ethtool_puts(u8 **data, const char *str); 1410 1411/** 1412 * ethtool_cpy - Write possibly-not-NUL-terminated string to ethtool string data 1413 * @data: Pointer to a pointer to the start of string to write into 1414 * @str: NUL-byte padded char array of size ETH_GSTRING_LEN to copy from 1415 */ 1416#define ethtool_cpy(data, str) do { \ 1417 BUILD_BUG_ON(sizeof(str) != ETH_GSTRING_LEN); \ 1418 memcpy(*(data), str, ETH_GSTRING_LEN); \ 1419 *(data) += ETH_GSTRING_LEN; \ 1420} while (0) 1421 1422/* Link mode to forced speed capabilities maps */ 1423struct ethtool_forced_speed_map { 1424 u32 speed; 1425 __ETHTOOL_DECLARE_LINK_MODE_MASK(caps); 1426 1427 const u32 *cap_arr; 1428 u32 arr_size; 1429}; 1430 1431#define ETHTOOL_FORCED_SPEED_MAP(prefix, value) \ 1432{ \ 1433 .speed = SPEED_##value, \ 1434 .cap_arr = prefix##_##value, \ 1435 .arr_size = ARRAY_SIZE(prefix##_##value), \ 1436} 1437 1438void 1439ethtool_forced_speed_maps_init(struct ethtool_forced_speed_map *maps, u32 size); 1440#endif /* _LINUX_ETHTOOL_H */