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