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