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