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