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