xref: /linux-6.15/include/linux/ethtool.h (revision 514dcf78)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * ethtool.h: Defines for Linux ethtool.
4  *
5  * Copyright (C) 1998 David S. Miller ([email protected])
6  * Copyright 2001 Jeff Garzik <[email protected]>
7  * Portions Copyright 2001 Sun Microsystems ([email protected])
8  * Portions Copyright 2002 Intel ([email protected],
9  *                                [email protected],
10  *                                [email protected])
11  * Portions Copyright (C) Sun Microsystems 2008
12  */
13 #ifndef _LINUX_ETHTOOL_H
14 #define _LINUX_ETHTOOL_H
15 
16 #include <linux/bitmap.h>
17 #include <linux/compat.h>
18 #include <linux/if_ether.h>
19 #include <linux/netlink.h>
20 #include <uapi/linux/ethtool.h>
21 #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  */
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 
189 static inline void *ethtool_rxfh_context_priv(struct ethtool_rxfh_context *ctx)
190 {
191 	return ctx->data;
192 }
193 
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 
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 
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 /**
416  * struct ethtool_phy_stats - PHY-level statistics counters
417  * @rx_packets: Total successfully received frames
418  * @rx_bytes: Total successfully received bytes
419  * @rx_errors: Total received frames with errors (e.g., CRC errors)
420  * @tx_packets: Total successfully transmitted frames
421  * @tx_bytes: Total successfully transmitted bytes
422  * @tx_errors: Total transmitted frames with errors
423  *
424  * This structure provides a standardized interface for reporting
425  * PHY-level statistics counters. It is designed to expose statistics
426  * commonly provided by PHYs but not explicitly defined in the IEEE
427  * 802.3 standard.
428  */
429 struct ethtool_phy_stats {
430 	u64 rx_packets;
431 	u64 rx_bytes;
432 	u64 rx_errors;
433 	u64 tx_packets;
434 	u64 tx_bytes;
435 	u64 tx_errors;
436 };
437 
438 /* Basic IEEE 802.3 MAC Ctrl statistics (30.3.3.*), not otherwise exposed
439  * via a more targeted API.
440  */
441 struct ethtool_eth_ctrl_stats {
442 	enum ethtool_mac_stats_src src;
443 	struct_group(stats,
444 		u64 MACControlFramesTransmitted;
445 		u64 MACControlFramesReceived;
446 		u64 UnsupportedOpcodesReceived;
447 	);
448 };
449 
450 /**
451  * struct ethtool_pause_stats - statistics for IEEE 802.3x pause frames
452  * @src: input field denoting whether stats should be queried from the eMAC or
453  *	pMAC (if the MM layer is supported). To be ignored otherwise.
454  * @tx_pause_frames: transmitted pause frame count. Reported to user space
455  *	as %ETHTOOL_A_PAUSE_STAT_TX_FRAMES.
456  *
457  *	Equivalent to `30.3.4.2 aPAUSEMACCtrlFramesTransmitted`
458  *	from the standard.
459  *
460  * @rx_pause_frames: received pause frame count. Reported to user space
461  *	as %ETHTOOL_A_PAUSE_STAT_RX_FRAMES. Equivalent to:
462  *
463  *	Equivalent to `30.3.4.3 aPAUSEMACCtrlFramesReceived`
464  *	from the standard.
465  */
466 struct ethtool_pause_stats {
467 	enum ethtool_mac_stats_src src;
468 	struct_group(stats,
469 		u64 tx_pause_frames;
470 		u64 rx_pause_frames;
471 	);
472 };
473 
474 #define ETHTOOL_MAX_LANES	8
475 
476 /**
477  * struct ethtool_fec_stats - statistics for IEEE 802.3 FEC
478  * @corrected_blocks: number of received blocks corrected by FEC
479  *	Reported to user space as %ETHTOOL_A_FEC_STAT_CORRECTED.
480  *
481  *	Equivalent to `30.5.1.1.17 aFECCorrectedBlocks` from the standard.
482  *
483  * @uncorrectable_blocks: number of received blocks FEC was not able to correct
484  *	Reported to user space as %ETHTOOL_A_FEC_STAT_UNCORR.
485  *
486  *	Equivalent to `30.5.1.1.18 aFECUncorrectableBlocks` from the standard.
487  *
488  * @corrected_bits: number of bits corrected by FEC
489  *	Similar to @corrected_blocks but counts individual bit changes,
490  *	not entire FEC data blocks. This is a non-standard statistic.
491  *	Reported to user space as %ETHTOOL_A_FEC_STAT_CORR_BITS.
492  *
493  * For each of the above fields, the two substructure members are:
494  *
495  * - @lanes: per-lane/PCS-instance counts as defined by the standard
496  * - @total: error counts for the entire port, for drivers incapable of reporting
497  *	per-lane stats
498  *
499  * Drivers should fill in either only total or per-lane statistics, core
500  * will take care of adding lane values up to produce the total.
501  */
502 struct ethtool_fec_stats {
503 	struct ethtool_fec_stat {
504 		u64 total;
505 		u64 lanes[ETHTOOL_MAX_LANES];
506 	} corrected_blocks, uncorrectable_blocks, corrected_bits;
507 };
508 
509 /**
510  * struct ethtool_rmon_hist_range - byte range for histogram statistics
511  * @low: low bound of the bucket (inclusive)
512  * @high: high bound of the bucket (inclusive)
513  */
514 struct ethtool_rmon_hist_range {
515 	u16 low;
516 	u16 high;
517 };
518 
519 #define ETHTOOL_RMON_HIST_MAX	10
520 
521 /**
522  * struct ethtool_rmon_stats - selected RMON (RFC 2819) statistics
523  * @src: input field denoting whether stats should be queried from the eMAC or
524  *	pMAC (if the MM layer is supported). To be ignored otherwise.
525  * @undersize_pkts: Equivalent to `etherStatsUndersizePkts` from the RFC.
526  * @oversize_pkts: Equivalent to `etherStatsOversizePkts` from the RFC.
527  * @fragments: Equivalent to `etherStatsFragments` from the RFC.
528  * @jabbers: Equivalent to `etherStatsJabbers` from the RFC.
529  * @hist: Packet counter for packet length buckets (e.g.
530  *	`etherStatsPkts128to255Octets` from the RFC).
531  * @hist_tx: Tx counters in similar form to @hist, not defined in the RFC.
532  *
533  * Selection of RMON (RFC 2819) statistics which are not exposed via different
534  * APIs, primarily the packet-length-based counters.
535  * Unfortunately different designs choose different buckets beyond
536  * the 1024B mark (jumbo frame teritory), so the definition of the bucket
537  * ranges is left to the driver.
538  */
539 struct ethtool_rmon_stats {
540 	enum ethtool_mac_stats_src src;
541 	struct_group(stats,
542 		u64 undersize_pkts;
543 		u64 oversize_pkts;
544 		u64 fragments;
545 		u64 jabbers;
546 
547 		u64 hist[ETHTOOL_RMON_HIST_MAX];
548 		u64 hist_tx[ETHTOOL_RMON_HIST_MAX];
549 	);
550 };
551 
552 /**
553  * struct ethtool_ts_stats - HW timestamping statistics
554  * @pkts: Number of packets successfully timestamped by the hardware.
555  * @lost: Number of hardware timestamping requests where the timestamping
556  *	information from the hardware never arrived for submission with
557  *	the skb.
558  * @err: Number of arbitrary timestamp generation error events that the
559  *	hardware encountered, exclusive of @lost statistics. Cases such
560  *	as resource exhaustion, unavailability, firmware errors, and
561  *	detected illogical timestamp values not submitted with the skb
562  *	are inclusive to this counter.
563  */
564 struct ethtool_ts_stats {
565 	struct_group(tx_stats,
566 		u64 pkts;
567 		u64 lost;
568 		u64 err;
569 	);
570 };
571 
572 #define ETH_MODULE_EEPROM_PAGE_LEN	128
573 #define ETH_MODULE_MAX_I2C_ADDRESS	0x7f
574 
575 /**
576  * struct ethtool_module_eeprom - plug-in module EEPROM read / write parameters
577  * @offset: When @offset is 0-127, it is used as an address to the Lower Memory
578  *	(@page must be 0). Otherwise, it is used as an address to the
579  *	Upper Memory.
580  * @length: Number of bytes to read / write.
581  * @page: Page number.
582  * @bank: Bank number, if supported by EEPROM spec.
583  * @i2c_address: I2C address of a page. Value less than 0x7f expected. Most
584  *	EEPROMs use 0x50 or 0x51.
585  * @data: Pointer to buffer with EEPROM data of @length size.
586  */
587 struct ethtool_module_eeprom {
588 	u32	offset;
589 	u32	length;
590 	u8	page;
591 	u8	bank;
592 	u8	i2c_address;
593 	u8	*data;
594 };
595 
596 /**
597  * struct ethtool_module_power_mode_params - module power mode parameters
598  * @policy: The power mode policy enforced by the host for the plug-in module.
599  * @mode: The operational power mode of the plug-in module. Should be filled by
600  *	device drivers on get operations.
601  */
602 struct ethtool_module_power_mode_params {
603 	enum ethtool_module_power_mode_policy policy;
604 	enum ethtool_module_power_mode mode;
605 };
606 
607 /**
608  * struct ethtool_mm_state - 802.3 MAC merge layer state
609  * @verify_time:
610  *	wait time between verification attempts in ms (according to clause
611  *	30.14.1.6 aMACMergeVerifyTime)
612  * @max_verify_time:
613  *	maximum accepted value for the @verify_time variable in set requests
614  * @verify_status:
615  *	state of the verification state machine of the MM layer (according to
616  *	clause 30.14.1.2 aMACMergeStatusVerify)
617  * @tx_enabled:
618  *	set if the MM layer is administratively enabled in the TX direction
619  *	(according to clause 30.14.1.3 aMACMergeEnableTx)
620  * @tx_active:
621  *	set if the MM layer is enabled in the TX direction, which makes FP
622  *	possible (according to 30.14.1.5 aMACMergeStatusTx). This should be
623  *	true if MM is enabled, and the verification status is either verified,
624  *	or disabled.
625  * @pmac_enabled:
626  *	set if the preemptible MAC is powered on and is able to receive
627  *	preemptible packets and respond to verification frames.
628  * @verify_enabled:
629  *	set if the Verify function of the MM layer (which sends SMD-V
630  *	verification requests) is administratively enabled (regardless of
631  *	whether it is currently in the ETHTOOL_MM_VERIFY_STATUS_DISABLED state
632  *	or not), according to clause 30.14.1.4 aMACMergeVerifyDisableTx (but
633  *	using positive rather than negative logic). The device should always
634  *	respond to received SMD-V requests as long as @pmac_enabled is set.
635  * @tx_min_frag_size:
636  *	the minimum size of non-final mPacket fragments that the link partner
637  *	supports receiving, expressed in octets. Compared to the definition
638  *	from clause 30.14.1.7 aMACMergeAddFragSize which is expressed in the
639  *	range 0 to 3 (requiring a translation to the size in octets according
640  *	to the formula 64 * (1 + addFragSize) - 4), a value in a continuous and
641  *	unbounded range can be specified here.
642  * @rx_min_frag_size:
643  *	the minimum size of non-final mPacket fragments that this device
644  *	supports receiving, expressed in octets.
645  */
646 struct ethtool_mm_state {
647 	u32 verify_time;
648 	u32 max_verify_time;
649 	enum ethtool_mm_verify_status verify_status;
650 	bool tx_enabled;
651 	bool tx_active;
652 	bool pmac_enabled;
653 	bool verify_enabled;
654 	u32 tx_min_frag_size;
655 	u32 rx_min_frag_size;
656 };
657 
658 /**
659  * struct ethtool_mm_cfg - 802.3 MAC merge layer configuration
660  * @verify_time: see struct ethtool_mm_state
661  * @verify_enabled: see struct ethtool_mm_state
662  * @tx_enabled: see struct ethtool_mm_state
663  * @pmac_enabled: see struct ethtool_mm_state
664  * @tx_min_frag_size: see struct ethtool_mm_state
665  */
666 struct ethtool_mm_cfg {
667 	u32 verify_time;
668 	bool verify_enabled;
669 	bool tx_enabled;
670 	bool pmac_enabled;
671 	u32 tx_min_frag_size;
672 };
673 
674 /**
675  * struct ethtool_mm_stats - 802.3 MAC merge layer statistics
676  * @MACMergeFrameAssErrorCount:
677  *	received MAC frames with reassembly errors
678  * @MACMergeFrameSmdErrorCount:
679  *	received MAC frames/fragments rejected due to unknown or incorrect SMD
680  * @MACMergeFrameAssOkCount:
681  *	received MAC frames that were successfully reassembled and passed up
682  * @MACMergeFragCountRx:
683  *	number of additional correct SMD-C mPackets received due to preemption
684  * @MACMergeFragCountTx:
685  *	number of additional mPackets sent due to preemption
686  * @MACMergeHoldCount:
687  *	number of times the MM layer entered the HOLD state, which blocks
688  *	transmission of preemptible traffic
689  */
690 struct ethtool_mm_stats {
691 	u64 MACMergeFrameAssErrorCount;
692 	u64 MACMergeFrameSmdErrorCount;
693 	u64 MACMergeFrameAssOkCount;
694 	u64 MACMergeFragCountRx;
695 	u64 MACMergeFragCountTx;
696 	u64 MACMergeHoldCount;
697 };
698 
699 /**
700  * struct ethtool_rxfh_param - RXFH (RSS) parameters
701  * @hfunc: Defines the current RSS hash function used by HW (or to be set to).
702  *	Valid values are one of the %ETH_RSS_HASH_*.
703  * @indir_size: On SET, the array size of the user buffer for the
704  *	indirection table, which may be zero, or
705  *	%ETH_RXFH_INDIR_NO_CHANGE.  On GET (read from the driver),
706  *	the array size of the hardware indirection table.
707  * @indir: The indirection table of size @indir_size entries.
708  * @key_size: On SET, the array size of the user buffer for the hash key,
709  *	which may be zero.  On GET (read from the driver), the size of the
710  *	hardware hash key.
711  * @key: The hash key of size @key_size bytes.
712  * @rss_context: RSS context identifier.  Context 0 is the default for normal
713  *	traffic; other contexts can be referenced as the destination for RX flow
714  *	classification rules.  On SET, %ETH_RXFH_CONTEXT_ALLOC is used
715  *	to allocate a new RSS context; on return this field will
716  *	contain the ID of the newly allocated context.
717  * @rss_delete: Set to non-ZERO to remove the @rss_context context.
718  * @input_xfrm: Defines how the input data is transformed. Valid values are one
719  *	of %RXH_XFRM_*.
720  */
721 struct ethtool_rxfh_param {
722 	u8	hfunc;
723 	u32	indir_size;
724 	u32	*indir;
725 	u32	key_size;
726 	u8	*key;
727 	u32	rss_context;
728 	u8	rss_delete;
729 	u8	input_xfrm;
730 };
731 
732 /**
733  * struct kernel_ethtool_ts_info - kernel copy of struct ethtool_ts_info
734  * @cmd: command number = %ETHTOOL_GET_TS_INFO
735  * @so_timestamping: bit mask of the sum of the supported SO_TIMESTAMPING flags
736  * @phc_index: device index of the associated PHC, or -1 if there is none
737  * @phc_qualifier: qualifier of the associated PHC
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_provider_qualifier phc_qualifier;
746 	enum hwtstamp_tx_types tx_types;
747 	enum hwtstamp_rx_filters rx_filters;
748 };
749 
750 /**
751  * struct ethtool_ops - optional netdev operations
752  * @cap_link_lanes_supported: indicates if the driver supports lanes
753  *	parameter.
754  * @cap_rss_ctx_supported: indicates if the driver supports RSS
755  *	contexts via legacy API, drivers implementing @create_rxfh_context
756  *	do not have to set this bit.
757  * @cap_rss_sym_xor_supported: indicates if the driver supports symmetric-xor
758  *	RSS.
759  * @rxfh_per_ctx_key: device supports setting different RSS key for each
760  *	additional context. Netlink API should report hfunc, key, and input_xfrm
761  *	for every context, not just context 0.
762  * @cap_rss_rxnfc_adds: device supports nonzero ring_cookie in filters with
763  *	%FLOW_RSS flag; the queue ID from the filter is added to the value from
764  *	the indirection table to determine the delivery queue.
765  * @rxfh_indir_space: max size of RSS indirection tables, if indirection table
766  *	size as returned by @get_rxfh_indir_size may change during lifetime
767  *	of the device. Leave as 0 if the table size is constant.
768  * @rxfh_key_space: same as @rxfh_indir_space, but for the key.
769  * @rxfh_priv_size: size of the driver private data area the core should
770  *	allocate for an RSS context (in &struct ethtool_rxfh_context).
771  * @rxfh_max_num_contexts: maximum (exclusive) supported RSS context ID.
772  *	If this is zero then the core may choose any (nonzero) ID, otherwise
773  *	the core will only use IDs strictly less than this value, as the
774  *	@rss_context argument to @create_rxfh_context and friends.
775  * @supported_coalesce_params: supported types of interrupt coalescing.
776  * @supported_ring_params: supported ring params.
777  * @supported_hwtstamp_qualifiers: bitfield of supported hwtstamp qualifier.
778  * @get_drvinfo: Report driver/device information. Modern drivers no
779  *	longer have to implement this callback. Most fields are
780  *	correctly filled in by the core using system information, or
781  *	populated using other driver operations.
782  * @get_regs_len: Get buffer length required for @get_regs
783  * @get_regs: Get device registers
784  * @get_wol: Report whether Wake-on-Lan is enabled
785  * @set_wol: Turn Wake-on-Lan on or off.  Returns a negative error code
786  *	or zero.
787  * @get_msglevel: Report driver message level.  This should be the value
788  *	of the @msg_enable field used by netif logging functions.
789  * @set_msglevel: Set driver message level
790  * @nway_reset: Restart autonegotiation.  Returns a negative error code
791  *	or zero.
792  * @get_link: Report whether physical link is up.  Will only be called if
793  *	the netdev is up.  Should usually be set to ethtool_op_get_link(),
794  *	which uses netif_carrier_ok().
795  * @get_link_ext_state: Report link extended state. Should set link_ext_state and
796  *	link_ext_substate (link_ext_substate of 0 means link_ext_substate is unknown,
797  *	do not attach ext_substate attribute to netlink message). If link_ext_state
798  *	and link_ext_substate are unknown, return -ENODATA. If not implemented,
799  *	link_ext_state and link_ext_substate will not be sent to userspace.
800  * @get_link_ext_stats: Read extra link-related counters.
801  * @get_eeprom_len: Read range of EEPROM addresses for validation of
802  *	@get_eeprom and @set_eeprom requests.
803  *	Returns 0 if device does not support EEPROM access.
804  * @get_eeprom: Read data from the device EEPROM.
805  *	Should fill in the magic field.  Don't need to check len for zero
806  *	or wraparound.  Fill in the data argument with the eeprom values
807  *	from offset to offset + len.  Update len to the amount read.
808  *	Returns an error or zero.
809  * @set_eeprom: Write data to the device EEPROM.
810  *	Should validate the magic field.  Don't need to check len for zero
811  *	or wraparound.  Update len to the amount written.  Returns an error
812  *	or zero.
813  * @get_coalesce: Get interrupt coalescing parameters.  Returns a negative
814  *	error code or zero.
815  * @set_coalesce: Set interrupt coalescing parameters.  Supported coalescing
816  *	types should be set in @supported_coalesce_params.
817  *	Returns a negative error code or zero.
818  * @get_ringparam: Report ring sizes
819  * @set_ringparam: Set ring sizes.  Returns a negative error code or zero.
820  * @get_pause_stats: Report pause frame statistics. Drivers must not zero
821  *	statistics which they don't report. The stats structure is initialized
822  *	to ETHTOOL_STAT_NOT_SET indicating driver does not report statistics.
823  * @get_pauseparam: Report pause parameters
824  * @set_pauseparam: Set pause parameters.  Returns a negative error code
825  *	or zero.
826  * @self_test: Run specified self-tests
827  * @get_strings: Return a set of strings that describe the requested objects
828  * @set_phys_id: Identify the physical devices, e.g. by flashing an LED
829  *	attached to it.  The implementation may update the indicator
830  *	asynchronously or synchronously, but in either case it must return
831  *	quickly.  It is initially called with the argument %ETHTOOL_ID_ACTIVE,
832  *	and must either activate asynchronous updates and return zero, return
833  *	a negative error or return a positive frequency for synchronous
834  *	indication (e.g. 1 for one on/off cycle per second).  If it returns
835  *	a frequency then it will be called again at intervals with the
836  *	argument %ETHTOOL_ID_ON or %ETHTOOL_ID_OFF and should set the state of
837  *	the indicator accordingly.  Finally, it is called with the argument
838  *	%ETHTOOL_ID_INACTIVE and must deactivate the indicator.  Returns a
839  *	negative error code or zero.
840  * @get_ethtool_stats: Return extended statistics about the device.
841  *	This is only useful if the device maintains statistics not
842  *	included in &struct rtnl_link_stats64.
843  * @begin: Function to be called before any other operation.  Returns a
844  *	negative error code or zero.
845  * @complete: Function to be called after any other operation except
846  *	@begin.  Will be called even if the other operation failed.
847  * @get_priv_flags: Report driver-specific feature flags.
848  * @set_priv_flags: Set driver-specific feature flags.  Returns a negative
849  *	error code or zero.
850  * @get_sset_count: Get number of strings that @get_strings will write.
851  * @get_rxnfc: Get RX flow classification rules.  Returns a negative
852  *	error code or zero.
853  * @set_rxnfc: Set RX flow classification rules.  Returns a negative
854  *	error code or zero.
855  * @flash_device: Write a firmware image to device's flash memory.
856  *	Returns a negative error code or zero.
857  * @reset: Reset (part of) the device, as specified by a bitmask of
858  *	flags from &enum ethtool_reset_flags.  Returns a negative
859  *	error code or zero.
860  * @get_rxfh_key_size: Get the size of the RX flow hash key.
861  *	Returns zero if not supported for this specific device.
862  * @get_rxfh_indir_size: Get the size of the RX flow hash indirection table.
863  *	Returns zero if not supported for this specific device.
864  * @get_rxfh: Get the contents of the RX flow hash indirection table, hash key
865  *	and/or hash function.
866  *	Returns a negative error code or zero.
867  * @set_rxfh: Set the contents of the RX flow hash indirection table, hash
868  *	key, and/or hash function.  Arguments which are set to %NULL or zero
869  *	will remain unchanged.
870  *	Returns a negative error code or zero. An error code must be returned
871  *	if at least one unsupported change was requested.
872  * @create_rxfh_context: Create a new RSS context with the specified RX flow
873  *	hash indirection table, hash key, and hash function.
874  *	The &struct ethtool_rxfh_context for this context is passed in @ctx;
875  *	note that the indir table, hkey and hfunc are not yet populated as
876  *	of this call.  The driver does not need to update these; the core
877  *	will do so if this op succeeds.
878  *	However, if @rxfh.indir is set to %NULL, the driver must update the
879  *	indir table in @ctx with the (default or inherited) table actually in
880  *	use; similarly, if @rxfh.key is %NULL, @rxfh.hfunc is
881  *	%ETH_RSS_HASH_NO_CHANGE, or @rxfh.input_xfrm is %RXH_XFRM_NO_CHANGE,
882  *	the driver should update the corresponding information in @ctx.
883  *	If the driver provides this method, it must also provide
884  *	@modify_rxfh_context and @remove_rxfh_context.
885  *	Returns a negative error code or zero.
886  * @modify_rxfh_context: Reconfigure the specified RSS context.  Allows setting
887  *	the contents of the RX flow hash indirection table, hash key, and/or
888  *	hash function associated with the given context.
889  *	Parameters which are set to %NULL or zero will remain unchanged.
890  *	The &struct ethtool_rxfh_context for this context is passed in @ctx;
891  *	note that it will still contain the *old* settings.  The driver does
892  *	not need to update these; the core will do so if this op succeeds.
893  *	Returns a negative error code or zero. An error code must be returned
894  *	if at least one unsupported change was requested.
895  * @remove_rxfh_context: Remove the specified RSS context.
896  *	The &struct ethtool_rxfh_context for this context is passed in @ctx.
897  *	Returns a negative error code or zero.
898  * @get_channels: Get number of channels.
899  * @set_channels: Set number of channels.  Returns a negative error code or
900  *	zero.
901  * @get_dump_flag: Get dump flag indicating current dump length, version,
902  * 		   and flag of the device.
903  * @get_dump_data: Get dump data.
904  * @set_dump: Set dump specific flags to the device.
905  * @get_ts_info: Get the time stamping and PTP hardware clock capabilities.
906  *	It may be called with RCU, or rtnl or reference on the device.
907  *	Drivers supporting transmit time stamps in software should set this to
908  *	ethtool_op_get_ts_info(). Drivers must not zero statistics which they
909  *	don't report. The stats	structure is initialized to ETHTOOL_STAT_NOT_SET
910  *	indicating driver does not report statistics.
911  * @get_ts_stats: Query the device hardware timestamping statistics.
912  * @get_module_info: Get the size and type of the eeprom contained within
913  *	a plug-in module.
914  * @get_module_eeprom: Get the eeprom information from the plug-in module
915  * @get_eee: Get Energy-Efficient (EEE) supported and status.
916  * @set_eee: Set EEE status (enable/disable) as well as LPI timers.
917  * @get_tunable: Read the value of a driver / device tunable.
918  * @set_tunable: Set the value of a driver / device tunable.
919  * @get_per_queue_coalesce: Get interrupt coalescing parameters per queue.
920  *	It must check that the given queue number is valid. If neither a RX nor
921  *	a TX queue has this number, return -EINVAL. If only a RX queue or a TX
922  *	queue has this number, set the inapplicable fields to ~0 and return 0.
923  *	Returns a negative error code or zero.
924  * @set_per_queue_coalesce: Set interrupt coalescing parameters per queue.
925  *	It must check that the given queue number is valid. If neither a RX nor
926  *	a TX queue has this number, return -EINVAL. If only a RX queue or a TX
927  *	queue has this number, ignore the inapplicable fields. Supported
928  *	coalescing types should be set in @supported_coalesce_params.
929  *	Returns a negative error code or zero.
930  * @get_link_ksettings: Get various device settings including Ethernet link
931  *	settings. The %cmd and %link_mode_masks_nwords fields should be
932  *	ignored (use %__ETHTOOL_LINK_MODE_MASK_NBITS instead of the latter),
933  *	any change to them will be overwritten by kernel. Returns a negative
934  *	error code or zero.
935  * @set_link_ksettings: Set various device settings including Ethernet link
936  *	settings. The %cmd and %link_mode_masks_nwords fields should be
937  *	ignored (use %__ETHTOOL_LINK_MODE_MASK_NBITS instead of the latter),
938  *	any change to them will be overwritten by kernel. Returns a negative
939  *	error code or zero.
940  * @get_fec_stats: Report FEC statistics.
941  *	Core will sum up per-lane stats to get the total.
942  *	Drivers must not zero statistics which they don't report. The stats
943  *	structure is initialized to ETHTOOL_STAT_NOT_SET indicating driver does
944  *	not report statistics.
945  * @get_fecparam: Get the network device Forward Error Correction parameters.
946  * @set_fecparam: Set the network device Forward Error Correction parameters.
947  * @get_ethtool_phy_stats: Return extended statistics about the PHY device.
948  *	This is only useful if the device maintains PHY statistics and
949  *	cannot use the standard PHY library helpers.
950  * @get_phy_tunable: Read the value of a PHY tunable.
951  * @set_phy_tunable: Set the value of a PHY tunable.
952  * @get_module_eeprom_by_page: Get a region of plug-in module EEPROM data from
953  *	specified page. Returns a negative error code or the amount of bytes
954  *	read.
955  * @set_module_eeprom_by_page: Write to a region of plug-in module EEPROM,
956  *	from kernel space only. Returns a negative error code or zero.
957  * @get_eth_phy_stats: Query some of the IEEE 802.3 PHY statistics.
958  * @get_eth_mac_stats: Query some of the IEEE 802.3 MAC statistics.
959  * @get_eth_ctrl_stats: Query some of the IEEE 802.3 MAC Ctrl statistics.
960  * @get_rmon_stats: Query some of the RMON (RFC 2819) statistics.
961  *	Set %ranges to a pointer to zero-terminated array of byte ranges.
962  * @get_module_power_mode: Get the power mode policy for the plug-in module
963  *	used by the network device and its operational power mode, if
964  *	plugged-in.
965  * @set_module_power_mode: Set the power mode policy for the plug-in module
966  *	used by the network device.
967  * @get_mm: Query the 802.3 MAC Merge layer state.
968  * @set_mm: Set the 802.3 MAC Merge layer parameters.
969  * @get_mm_stats: Query the 802.3 MAC Merge layer statistics.
970  *
971  * All operations are optional (i.e. the function pointer may be set
972  * to %NULL) and callers must take this into account.  Callers must
973  * hold the RTNL lock.
974  *
975  * See the structures used by these operations for further documentation.
976  * Note that for all operations using a structure ending with a zero-
977  * length array, the array is allocated separately in the kernel and
978  * is passed to the driver as an additional parameter.
979  *
980  * See &struct net_device and &struct net_device_ops for documentation
981  * of the generic netdev features interface.
982  */
983 struct ethtool_ops {
984 	u32     cap_link_lanes_supported:1;
985 	u32     cap_rss_ctx_supported:1;
986 	u32	cap_rss_sym_xor_supported:1;
987 	u32	rxfh_per_ctx_key:1;
988 	u32	cap_rss_rxnfc_adds:1;
989 	u32	rxfh_indir_space;
990 	u16	rxfh_key_space;
991 	u16	rxfh_priv_size;
992 	u32	rxfh_max_num_contexts;
993 	u32	supported_coalesce_params;
994 	u32	supported_ring_params;
995 	u32	supported_hwtstamp_qualifiers;
996 	void	(*get_drvinfo)(struct net_device *, struct ethtool_drvinfo *);
997 	int	(*get_regs_len)(struct net_device *);
998 	void	(*get_regs)(struct net_device *, struct ethtool_regs *, void *);
999 	void	(*get_wol)(struct net_device *, struct ethtool_wolinfo *);
1000 	int	(*set_wol)(struct net_device *, struct ethtool_wolinfo *);
1001 	u32	(*get_msglevel)(struct net_device *);
1002 	void	(*set_msglevel)(struct net_device *, u32);
1003 	int	(*nway_reset)(struct net_device *);
1004 	u32	(*get_link)(struct net_device *);
1005 	int	(*get_link_ext_state)(struct net_device *,
1006 				      struct ethtool_link_ext_state_info *);
1007 	void	(*get_link_ext_stats)(struct net_device *dev,
1008 				      struct ethtool_link_ext_stats *stats);
1009 	int	(*get_eeprom_len)(struct net_device *);
1010 	int	(*get_eeprom)(struct net_device *,
1011 			      struct ethtool_eeprom *, u8 *);
1012 	int	(*set_eeprom)(struct net_device *,
1013 			      struct ethtool_eeprom *, u8 *);
1014 	int	(*get_coalesce)(struct net_device *,
1015 				struct ethtool_coalesce *,
1016 				struct kernel_ethtool_coalesce *,
1017 				struct netlink_ext_ack *);
1018 	int	(*set_coalesce)(struct net_device *,
1019 				struct ethtool_coalesce *,
1020 				struct kernel_ethtool_coalesce *,
1021 				struct netlink_ext_ack *);
1022 	void	(*get_ringparam)(struct net_device *,
1023 				 struct ethtool_ringparam *,
1024 				 struct kernel_ethtool_ringparam *,
1025 				 struct netlink_ext_ack *);
1026 	int	(*set_ringparam)(struct net_device *,
1027 				 struct ethtool_ringparam *,
1028 				 struct kernel_ethtool_ringparam *,
1029 				 struct netlink_ext_ack *);
1030 	void	(*get_pause_stats)(struct net_device *dev,
1031 				   struct ethtool_pause_stats *pause_stats);
1032 	void	(*get_pauseparam)(struct net_device *,
1033 				  struct ethtool_pauseparam*);
1034 	int	(*set_pauseparam)(struct net_device *,
1035 				  struct ethtool_pauseparam*);
1036 	void	(*self_test)(struct net_device *, struct ethtool_test *, u64 *);
1037 	void	(*get_strings)(struct net_device *, u32 stringset, u8 *);
1038 	int	(*set_phys_id)(struct net_device *, enum ethtool_phys_id_state);
1039 	void	(*get_ethtool_stats)(struct net_device *,
1040 				     struct ethtool_stats *, u64 *);
1041 	int	(*begin)(struct net_device *);
1042 	void	(*complete)(struct net_device *);
1043 	u32	(*get_priv_flags)(struct net_device *);
1044 	int	(*set_priv_flags)(struct net_device *, u32);
1045 	int	(*get_sset_count)(struct net_device *, int);
1046 	int	(*get_rxnfc)(struct net_device *,
1047 			     struct ethtool_rxnfc *, u32 *rule_locs);
1048 	int	(*set_rxnfc)(struct net_device *, struct ethtool_rxnfc *);
1049 	int	(*flash_device)(struct net_device *, struct ethtool_flash *);
1050 	int	(*reset)(struct net_device *, u32 *);
1051 	u32	(*get_rxfh_key_size)(struct net_device *);
1052 	u32	(*get_rxfh_indir_size)(struct net_device *);
1053 	int	(*get_rxfh)(struct net_device *, struct ethtool_rxfh_param *);
1054 	int	(*set_rxfh)(struct net_device *, struct ethtool_rxfh_param *,
1055 			    struct netlink_ext_ack *extack);
1056 	int	(*create_rxfh_context)(struct net_device *,
1057 				       struct ethtool_rxfh_context *ctx,
1058 				       const struct ethtool_rxfh_param *rxfh,
1059 				       struct netlink_ext_ack *extack);
1060 	int	(*modify_rxfh_context)(struct net_device *,
1061 				       struct ethtool_rxfh_context *ctx,
1062 				       const struct ethtool_rxfh_param *rxfh,
1063 				       struct netlink_ext_ack *extack);
1064 	int	(*remove_rxfh_context)(struct net_device *,
1065 				       struct ethtool_rxfh_context *ctx,
1066 				       u32 rss_context,
1067 				       struct netlink_ext_ack *extack);
1068 	void	(*get_channels)(struct net_device *, struct ethtool_channels *);
1069 	int	(*set_channels)(struct net_device *, struct ethtool_channels *);
1070 	int	(*get_dump_flag)(struct net_device *, struct ethtool_dump *);
1071 	int	(*get_dump_data)(struct net_device *,
1072 				 struct ethtool_dump *, void *);
1073 	int	(*set_dump)(struct net_device *, struct ethtool_dump *);
1074 	int	(*get_ts_info)(struct net_device *, struct kernel_ethtool_ts_info *);
1075 	void	(*get_ts_stats)(struct net_device *dev,
1076 				struct ethtool_ts_stats *ts_stats);
1077 	int     (*get_module_info)(struct net_device *,
1078 				   struct ethtool_modinfo *);
1079 	int     (*get_module_eeprom)(struct net_device *,
1080 				     struct ethtool_eeprom *, u8 *);
1081 	int	(*get_eee)(struct net_device *dev, struct ethtool_keee *eee);
1082 	int	(*set_eee)(struct net_device *dev, struct ethtool_keee *eee);
1083 	int	(*get_tunable)(struct net_device *,
1084 			       const struct ethtool_tunable *, void *);
1085 	int	(*set_tunable)(struct net_device *,
1086 			       const struct ethtool_tunable *, const void *);
1087 	int	(*get_per_queue_coalesce)(struct net_device *, u32,
1088 					  struct ethtool_coalesce *);
1089 	int	(*set_per_queue_coalesce)(struct net_device *, u32,
1090 					  struct ethtool_coalesce *);
1091 	int	(*get_link_ksettings)(struct net_device *,
1092 				      struct ethtool_link_ksettings *);
1093 	int	(*set_link_ksettings)(struct net_device *,
1094 				      const struct ethtool_link_ksettings *);
1095 	void	(*get_fec_stats)(struct net_device *dev,
1096 				 struct ethtool_fec_stats *fec_stats);
1097 	int	(*get_fecparam)(struct net_device *,
1098 				      struct ethtool_fecparam *);
1099 	int	(*set_fecparam)(struct net_device *,
1100 				      struct ethtool_fecparam *);
1101 	void	(*get_ethtool_phy_stats)(struct net_device *,
1102 					 struct ethtool_stats *, u64 *);
1103 	int	(*get_phy_tunable)(struct net_device *,
1104 				   const struct ethtool_tunable *, void *);
1105 	int	(*set_phy_tunable)(struct net_device *,
1106 				   const struct ethtool_tunable *, const void *);
1107 	int	(*get_module_eeprom_by_page)(struct net_device *dev,
1108 					     const struct ethtool_module_eeprom *page,
1109 					     struct netlink_ext_ack *extack);
1110 	int	(*set_module_eeprom_by_page)(struct net_device *dev,
1111 					     const struct ethtool_module_eeprom *page,
1112 					     struct netlink_ext_ack *extack);
1113 	void	(*get_eth_phy_stats)(struct net_device *dev,
1114 				     struct ethtool_eth_phy_stats *phy_stats);
1115 	void	(*get_eth_mac_stats)(struct net_device *dev,
1116 				     struct ethtool_eth_mac_stats *mac_stats);
1117 	void	(*get_eth_ctrl_stats)(struct net_device *dev,
1118 				      struct ethtool_eth_ctrl_stats *ctrl_stats);
1119 	void	(*get_rmon_stats)(struct net_device *dev,
1120 				  struct ethtool_rmon_stats *rmon_stats,
1121 				  const struct ethtool_rmon_hist_range **ranges);
1122 	int	(*get_module_power_mode)(struct net_device *dev,
1123 					 struct ethtool_module_power_mode_params *params,
1124 					 struct netlink_ext_ack *extack);
1125 	int	(*set_module_power_mode)(struct net_device *dev,
1126 					 const struct ethtool_module_power_mode_params *params,
1127 					 struct netlink_ext_ack *extack);
1128 	int	(*get_mm)(struct net_device *dev, struct ethtool_mm_state *state);
1129 	int	(*set_mm)(struct net_device *dev, struct ethtool_mm_cfg *cfg,
1130 			  struct netlink_ext_ack *extack);
1131 	void	(*get_mm_stats)(struct net_device *dev, struct ethtool_mm_stats *stats);
1132 };
1133 
1134 int ethtool_check_ops(const struct ethtool_ops *ops);
1135 
1136 struct ethtool_rx_flow_rule {
1137 	struct flow_rule	*rule;
1138 	unsigned long		priv[];
1139 };
1140 
1141 struct ethtool_rx_flow_spec_input {
1142 	const struct ethtool_rx_flow_spec	*fs;
1143 	u32					rss_ctx;
1144 };
1145 
1146 struct ethtool_rx_flow_rule *
1147 ethtool_rx_flow_rule_create(const struct ethtool_rx_flow_spec_input *input);
1148 void ethtool_rx_flow_rule_destroy(struct ethtool_rx_flow_rule *rule);
1149 
1150 bool ethtool_virtdev_validate_cmd(const struct ethtool_link_ksettings *cmd);
1151 int ethtool_virtdev_set_link_ksettings(struct net_device *dev,
1152 				       const struct ethtool_link_ksettings *cmd,
1153 				       u32 *dev_speed, u8 *dev_duplex);
1154 
1155 /**
1156  * struct ethtool_netdev_state - per-netdevice state for ethtool features
1157  * @rss_ctx:		XArray of custom RSS contexts
1158  * @rss_lock:		Protects entries in @rss_ctx.  May be taken from
1159  *			within RTNL.
1160  * @wol_enabled:	Wake-on-LAN is enabled
1161  * @module_fw_flash_in_progress: Module firmware flashing is in progress.
1162  */
1163 struct ethtool_netdev_state {
1164 	struct xarray		rss_ctx;
1165 	struct mutex		rss_lock;
1166 	unsigned		wol_enabled:1;
1167 	unsigned		module_fw_flash_in_progress:1;
1168 };
1169 
1170 struct phy_device;
1171 struct phy_tdr_config;
1172 struct phy_plca_cfg;
1173 struct phy_plca_status;
1174 
1175 /**
1176  * struct ethtool_phy_ops - Optional PHY device options
1177  * @get_sset_count: Get number of strings that @get_strings will write.
1178  * @get_strings: Return a set of strings that describe the requested objects
1179  * @get_stats: Return extended statistics about the PHY device.
1180  * @get_plca_cfg: Return PLCA configuration.
1181  * @set_plca_cfg: Set PLCA configuration.
1182  * @get_plca_status: Get PLCA configuration.
1183  * @start_cable_test: Start a cable test
1184  * @start_cable_test_tdr: Start a Time Domain Reflectometry cable test
1185  *
1186  * All operations are optional (i.e. the function pointer may be set to %NULL)
1187  * and callers must take this into account. Callers must hold the RTNL lock.
1188  */
1189 struct ethtool_phy_ops {
1190 	int (*get_sset_count)(struct phy_device *dev);
1191 	int (*get_strings)(struct phy_device *dev, u8 *data);
1192 	int (*get_stats)(struct phy_device *dev,
1193 			 struct ethtool_stats *stats, u64 *data);
1194 	int (*get_plca_cfg)(struct phy_device *dev,
1195 			    struct phy_plca_cfg *plca_cfg);
1196 	int (*set_plca_cfg)(struct phy_device *dev,
1197 			    const struct phy_plca_cfg *plca_cfg,
1198 			    struct netlink_ext_ack *extack);
1199 	int (*get_plca_status)(struct phy_device *dev,
1200 			       struct phy_plca_status *plca_st);
1201 	int (*start_cable_test)(struct phy_device *phydev,
1202 				struct netlink_ext_ack *extack);
1203 	int (*start_cable_test_tdr)(struct phy_device *phydev,
1204 				    struct netlink_ext_ack *extack,
1205 				    const struct phy_tdr_config *config);
1206 };
1207 
1208 /**
1209  * ethtool_set_ethtool_phy_ops - Set the ethtool_phy_ops singleton
1210  * @ops: Ethtool PHY operations to set
1211  */
1212 void ethtool_set_ethtool_phy_ops(const struct ethtool_phy_ops *ops);
1213 
1214 /**
1215  * ethtool_params_from_link_mode - Derive link parameters from a given link mode
1216  * @link_ksettings: Link parameters to be derived from the link mode
1217  * @link_mode: Link mode
1218  */
1219 void
1220 ethtool_params_from_link_mode(struct ethtool_link_ksettings *link_ksettings,
1221 			      enum ethtool_link_mode_bit_indices link_mode);
1222 
1223 /**
1224  * ethtool_get_phc_vclocks - Derive phc vclocks information, and caller
1225  *                           is responsible to free memory of vclock_index
1226  * @dev: pointer to net_device structure
1227  * @vclock_index: pointer to pointer of vclock index
1228  *
1229  * Return: number of phc vclocks
1230  */
1231 int ethtool_get_phc_vclocks(struct net_device *dev, int **vclock_index);
1232 
1233 /* Some generic methods drivers may use in their ethtool_ops */
1234 u32 ethtool_op_get_link(struct net_device *dev);
1235 int ethtool_op_get_ts_info(struct net_device *dev,
1236 			   struct kernel_ethtool_ts_info *eti);
1237 
1238 /**
1239  * ethtool_mm_frag_size_add_to_min - Translate (standard) additional fragment
1240  *	size expressed as multiplier into (absolute) minimum fragment size
1241  *	value expressed in octets
1242  * @val_add: Value of addFragSize multiplier
1243  */
1244 static inline u32 ethtool_mm_frag_size_add_to_min(u32 val_add)
1245 {
1246 	return (ETH_ZLEN + ETH_FCS_LEN) * (1 + val_add) - ETH_FCS_LEN;
1247 }
1248 
1249 /**
1250  * ethtool_mm_frag_size_min_to_add - Translate (absolute) minimum fragment size
1251  *	expressed in octets into (standard) additional fragment size expressed
1252  *	as multiplier
1253  * @val_min: Value of addFragSize variable in octets
1254  * @val_add: Pointer where the standard addFragSize value is to be returned
1255  * @extack: Netlink extended ack
1256  *
1257  * Translate a value in octets to one of 0, 1, 2, 3 according to the reverse
1258  * application of the 802.3 formula 64 * (1 + addFragSize) - 4. To be called
1259  * by drivers which do not support programming the minimum fragment size to a
1260  * continuous range. Returns error on other fragment length values.
1261  */
1262 static inline int ethtool_mm_frag_size_min_to_add(u32 val_min, u32 *val_add,
1263 						  struct netlink_ext_ack *extack)
1264 {
1265 	u32 add_frag_size;
1266 
1267 	for (add_frag_size = 0; add_frag_size < 4; add_frag_size++) {
1268 		if (ethtool_mm_frag_size_add_to_min(add_frag_size) == val_min) {
1269 			*val_add = add_frag_size;
1270 			return 0;
1271 		}
1272 	}
1273 
1274 	NL_SET_ERR_MSG_MOD(extack,
1275 			   "minFragSize required to be one of 60, 124, 188 or 252");
1276 	return -EINVAL;
1277 }
1278 
1279 /**
1280  * ethtool_get_ts_info_by_layer - Obtains time stamping capabilities from the MAC or PHY layer.
1281  * @dev: pointer to net_device structure
1282  * @info: buffer to hold the result
1283  * Returns: zero on success, non-zero otherwise.
1284  */
1285 int ethtool_get_ts_info_by_layer(struct net_device *dev,
1286 				 struct kernel_ethtool_ts_info *info);
1287 
1288 /**
1289  * ethtool_sprintf - Write formatted string to ethtool string data
1290  * @data: Pointer to a pointer to the start of string to update
1291  * @fmt: Format of string to write
1292  *
1293  * Write formatted string to *data. Update *data to point at start of
1294  * next string.
1295  */
1296 extern __printf(2, 3) void ethtool_sprintf(u8 **data, const char *fmt, ...);
1297 
1298 /**
1299  * ethtool_puts - Write string to ethtool string data
1300  * @data: Pointer to a pointer to the start of string to update
1301  * @str: String to write
1302  *
1303  * Write string to *data without a trailing newline. Update *data
1304  * to point at start of next string.
1305  *
1306  * Prefer this function to ethtool_sprintf() when given only
1307  * two arguments or if @fmt is just "%s".
1308  */
1309 extern void ethtool_puts(u8 **data, const char *str);
1310 
1311 /* Link mode to forced speed capabilities maps */
1312 struct ethtool_forced_speed_map {
1313 	u32		speed;
1314 	__ETHTOOL_DECLARE_LINK_MODE_MASK(caps);
1315 
1316 	const u32	*cap_arr;
1317 	u32		arr_size;
1318 };
1319 
1320 #define ETHTOOL_FORCED_SPEED_MAP(prefix, value)				\
1321 {									\
1322 	.speed		= SPEED_##value,				\
1323 	.cap_arr	= prefix##_##value,				\
1324 	.arr_size	= ARRAY_SIZE(prefix##_##value),			\
1325 }
1326 
1327 void
1328 ethtool_forced_speed_maps_init(struct ethtool_forced_speed_map *maps, u32 size);
1329 
1330 /* C33 PSE extended state and substate. */
1331 struct ethtool_c33_pse_ext_state_info {
1332 	enum ethtool_c33_pse_ext_state c33_pse_ext_state;
1333 	union {
1334 		enum ethtool_c33_pse_ext_substate_error_condition error_condition;
1335 		enum ethtool_c33_pse_ext_substate_mr_pse_enable mr_pse_enable;
1336 		enum ethtool_c33_pse_ext_substate_option_detect_ted option_detect_ted;
1337 		enum ethtool_c33_pse_ext_substate_option_vport_lim option_vport_lim;
1338 		enum ethtool_c33_pse_ext_substate_ovld_detected ovld_detected;
1339 		enum ethtool_c33_pse_ext_substate_power_not_available power_not_available;
1340 		enum ethtool_c33_pse_ext_substate_short_detected short_detected;
1341 		u32 __c33_pse_ext_substate;
1342 	};
1343 };
1344 
1345 struct ethtool_c33_pse_pw_limit_range {
1346 	u32 min;
1347 	u32 max;
1348 };
1349 #endif /* _LINUX_ETHTOOL_H */
1350