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