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