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