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