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