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