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