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