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