1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * ethtool.h: Defines for Linux ethtool.
4  *
5  * Copyright (C) 1998 David S. Miller (davem@redhat.com)
6  * Copyright 2001 Jeff Garzik <jgarzik@pobox.com>
7  * Portions Copyright 2001 Sun Microsystems (thockin@sun.com)
8  * Portions Copyright 2002 Intel (eli.kupermann@intel.com,
9  *                                christopher.leech@intel.com,
10  *                                scott.feldman@intel.com)
11  * Portions Copyright (C) Sun Microsystems 2008
12  */
13 #ifndef _LINUX_ETHTOOL_H
14 #define _LINUX_ETHTOOL_H
15 
16 #include <linux/bitmap.h>
17 #include <linux/compat.h>
18 #include <uapi/linux/ethtool.h>
19 
20 #ifdef CONFIG_COMPAT
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 #endif /* CONFIG_COMPAT */
42 
43 #include <linux/rculist.h>
44 
45 /**
46  * enum ethtool_phys_id_state - indicator state for physical identification
47  * @ETHTOOL_ID_INACTIVE: Physical ID indicator should be deactivated
48  * @ETHTOOL_ID_ACTIVE: Physical ID indicator should be activated
49  * @ETHTOOL_ID_ON: LED should be turned on (used iff %ETHTOOL_ID_ACTIVE
50  *	is not supported)
51  * @ETHTOOL_ID_OFF: LED should be turned off (used iff %ETHTOOL_ID_ACTIVE
52  *	is not supported)
53  */
54 enum ethtool_phys_id_state {
55 	ETHTOOL_ID_INACTIVE,
56 	ETHTOOL_ID_ACTIVE,
57 	ETHTOOL_ID_ON,
58 	ETHTOOL_ID_OFF
59 };
60 
61 enum {
62 	ETH_RSS_HASH_TOP_BIT, /* Configurable RSS hash function - Toeplitz */
63 	ETH_RSS_HASH_XOR_BIT, /* Configurable RSS hash function - Xor */
64 	ETH_RSS_HASH_CRC32_BIT, /* Configurable RSS hash function - Crc32 */
65 
66 	/*
67 	 * Add your fresh new hash function bits above and remember to update
68 	 * rss_hash_func_strings[] in ethtool.c
69 	 */
70 	ETH_RSS_HASH_FUNCS_COUNT
71 };
72 
73 #define __ETH_RSS_HASH_BIT(bit)	((u32)1 << (bit))
74 #define __ETH_RSS_HASH(name)	__ETH_RSS_HASH_BIT(ETH_RSS_HASH_##name##_BIT)
75 
76 #define ETH_RSS_HASH_TOP	__ETH_RSS_HASH(TOP)
77 #define ETH_RSS_HASH_XOR	__ETH_RSS_HASH(XOR)
78 #define ETH_RSS_HASH_CRC32	__ETH_RSS_HASH(CRC32)
79 
80 #define ETH_RSS_HASH_UNKNOWN	0
81 #define ETH_RSS_HASH_NO_CHANGE	0
82 
83 struct net_device;
84 struct netlink_ext_ack;
85 
86 /* Some generic methods drivers may use in their ethtool_ops */
87 u32 ethtool_op_get_link(struct net_device *dev);
88 int ethtool_op_get_ts_info(struct net_device *dev, struct ethtool_ts_info *eti);
89 
90 
91 /* Link extended state and substate. */
92 struct ethtool_link_ext_state_info {
93 	enum ethtool_link_ext_state link_ext_state;
94 	union {
95 		enum ethtool_link_ext_substate_autoneg autoneg;
96 		enum ethtool_link_ext_substate_link_training link_training;
97 		enum ethtool_link_ext_substate_link_logical_mismatch link_logical_mismatch;
98 		enum ethtool_link_ext_substate_bad_signal_integrity bad_signal_integrity;
99 		enum ethtool_link_ext_substate_cable_issue cable_issue;
100 		u8 __link_ext_substate;
101 	};
102 };
103 
104 /**
105  * ethtool_rxfh_indir_default - get default value for RX flow hash indirection
106  * @index: Index in RX flow hash indirection table
107  * @n_rx_rings: Number of RX rings to use
108  *
109  * This function provides the default policy for RX flow hash indirection.
110  */
ethtool_rxfh_indir_default(u32 index,u32 n_rx_rings)111 static inline u32 ethtool_rxfh_indir_default(u32 index, u32 n_rx_rings)
112 {
113 	return index % n_rx_rings;
114 }
115 
116 /* declare a link mode bitmap */
117 #define __ETHTOOL_DECLARE_LINK_MODE_MASK(name)		\
118 	DECLARE_BITMAP(name, __ETHTOOL_LINK_MODE_MASK_NBITS)
119 
120 /* drivers must ignore base.cmd and base.link_mode_masks_nwords
121  * fields, but they are allowed to overwrite them (will be ignored).
122  */
123 struct ethtool_link_ksettings {
124 	struct ethtool_link_settings base;
125 	struct {
126 		__ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
127 		__ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
128 		__ETHTOOL_DECLARE_LINK_MODE_MASK(lp_advertising);
129 	} link_modes;
130 	u32	lanes;
131 };
132 
133 /**
134  * ethtool_link_ksettings_zero_link_mode - clear link_ksettings link mode mask
135  *   @ptr : pointer to struct ethtool_link_ksettings
136  *   @name : one of supported/advertising/lp_advertising
137  */
138 #define ethtool_link_ksettings_zero_link_mode(ptr, name)		\
139 	bitmap_zero((ptr)->link_modes.name, __ETHTOOL_LINK_MODE_MASK_NBITS)
140 
141 /**
142  * ethtool_link_ksettings_add_link_mode - set bit in link_ksettings
143  * link mode mask
144  *   @ptr : pointer to struct ethtool_link_ksettings
145  *   @name : one of supported/advertising/lp_advertising
146  *   @mode : one of the ETHTOOL_LINK_MODE_*_BIT
147  * (not atomic, no bound checking)
148  */
149 #define ethtool_link_ksettings_add_link_mode(ptr, name, mode)		\
150 	__set_bit(ETHTOOL_LINK_MODE_ ## mode ## _BIT, (ptr)->link_modes.name)
151 
152 /**
153  * ethtool_link_ksettings_del_link_mode - clear bit in link_ksettings
154  * link mode mask
155  *   @ptr : pointer to struct ethtool_link_ksettings
156  *   @name : one of supported/advertising/lp_advertising
157  *   @mode : one of the ETHTOOL_LINK_MODE_*_BIT
158  * (not atomic, no bound checking)
159  */
160 #define ethtool_link_ksettings_del_link_mode(ptr, name, mode)		\
161 	__clear_bit(ETHTOOL_LINK_MODE_ ## mode ## _BIT, (ptr)->link_modes.name)
162 
163 /**
164  * ethtool_link_ksettings_test_link_mode - test bit in ksettings link mode mask
165  *   @ptr : pointer to struct ethtool_link_ksettings
166  *   @name : one of supported/advertising/lp_advertising
167  *   @mode : one of the ETHTOOL_LINK_MODE_*_BIT
168  * (not atomic, no bound checking)
169  *
170  * Returns true/false.
171  */
172 #define ethtool_link_ksettings_test_link_mode(ptr, name, mode)		\
173 	test_bit(ETHTOOL_LINK_MODE_ ## mode ## _BIT, (ptr)->link_modes.name)
174 
175 extern int
176 __ethtool_get_link_ksettings(struct net_device *dev,
177 			     struct ethtool_link_ksettings *link_ksettings);
178 
179 /**
180  * ethtool_intersect_link_masks - Given two link masks, AND them together
181  * @dst: first mask and where result is stored
182  * @src: second mask to intersect with
183  *
184  * Given two link mode masks, AND them together and save the result in dst.
185  */
186 void ethtool_intersect_link_masks(struct ethtool_link_ksettings *dst,
187 				  struct ethtool_link_ksettings *src);
188 
189 void ethtool_convert_legacy_u32_to_link_mode(unsigned long *dst,
190 					     u32 legacy_u32);
191 
192 /* return false if src had higher bits set. lower bits always updated. */
193 bool ethtool_convert_link_mode_to_legacy_u32(u32 *legacy_u32,
194 				     const unsigned long *src);
195 
196 #define ETHTOOL_COALESCE_RX_USECS		BIT(0)
197 #define ETHTOOL_COALESCE_RX_MAX_FRAMES		BIT(1)
198 #define ETHTOOL_COALESCE_RX_USECS_IRQ		BIT(2)
199 #define ETHTOOL_COALESCE_RX_MAX_FRAMES_IRQ	BIT(3)
200 #define ETHTOOL_COALESCE_TX_USECS		BIT(4)
201 #define ETHTOOL_COALESCE_TX_MAX_FRAMES		BIT(5)
202 #define ETHTOOL_COALESCE_TX_USECS_IRQ		BIT(6)
203 #define ETHTOOL_COALESCE_TX_MAX_FRAMES_IRQ	BIT(7)
204 #define ETHTOOL_COALESCE_STATS_BLOCK_USECS	BIT(8)
205 #define ETHTOOL_COALESCE_USE_ADAPTIVE_RX	BIT(9)
206 #define ETHTOOL_COALESCE_USE_ADAPTIVE_TX	BIT(10)
207 #define ETHTOOL_COALESCE_PKT_RATE_LOW		BIT(11)
208 #define ETHTOOL_COALESCE_RX_USECS_LOW		BIT(12)
209 #define ETHTOOL_COALESCE_RX_MAX_FRAMES_LOW	BIT(13)
210 #define ETHTOOL_COALESCE_TX_USECS_LOW		BIT(14)
211 #define ETHTOOL_COALESCE_TX_MAX_FRAMES_LOW	BIT(15)
212 #define ETHTOOL_COALESCE_PKT_RATE_HIGH		BIT(16)
213 #define ETHTOOL_COALESCE_RX_USECS_HIGH		BIT(17)
214 #define ETHTOOL_COALESCE_RX_MAX_FRAMES_HIGH	BIT(18)
215 #define ETHTOOL_COALESCE_TX_USECS_HIGH		BIT(19)
216 #define ETHTOOL_COALESCE_TX_MAX_FRAMES_HIGH	BIT(20)
217 #define ETHTOOL_COALESCE_RATE_SAMPLE_INTERVAL	BIT(21)
218 #define ETHTOOL_COALESCE_ALL_PARAMS		GENMASK(21, 0)
219 
220 #define ETHTOOL_COALESCE_USECS						\
221 	(ETHTOOL_COALESCE_RX_USECS | ETHTOOL_COALESCE_TX_USECS)
222 #define ETHTOOL_COALESCE_MAX_FRAMES					\
223 	(ETHTOOL_COALESCE_RX_MAX_FRAMES | ETHTOOL_COALESCE_TX_MAX_FRAMES)
224 #define ETHTOOL_COALESCE_USECS_IRQ					\
225 	(ETHTOOL_COALESCE_RX_USECS_IRQ | ETHTOOL_COALESCE_TX_USECS_IRQ)
226 #define ETHTOOL_COALESCE_MAX_FRAMES_IRQ		\
227 	(ETHTOOL_COALESCE_RX_MAX_FRAMES_IRQ |	\
228 	 ETHTOOL_COALESCE_TX_MAX_FRAMES_IRQ)
229 #define ETHTOOL_COALESCE_USE_ADAPTIVE					\
230 	(ETHTOOL_COALESCE_USE_ADAPTIVE_RX | ETHTOOL_COALESCE_USE_ADAPTIVE_TX)
231 #define ETHTOOL_COALESCE_USECS_LOW_HIGH					\
232 	(ETHTOOL_COALESCE_RX_USECS_LOW | ETHTOOL_COALESCE_TX_USECS_LOW | \
233 	 ETHTOOL_COALESCE_RX_USECS_HIGH | ETHTOOL_COALESCE_TX_USECS_HIGH)
234 #define ETHTOOL_COALESCE_MAX_FRAMES_LOW_HIGH	\
235 	(ETHTOOL_COALESCE_RX_MAX_FRAMES_LOW |	\
236 	 ETHTOOL_COALESCE_TX_MAX_FRAMES_LOW |	\
237 	 ETHTOOL_COALESCE_RX_MAX_FRAMES_HIGH |	\
238 	 ETHTOOL_COALESCE_TX_MAX_FRAMES_HIGH)
239 #define ETHTOOL_COALESCE_PKT_RATE_RX_USECS				\
240 	(ETHTOOL_COALESCE_USE_ADAPTIVE_RX |				\
241 	 ETHTOOL_COALESCE_RX_USECS_LOW | ETHTOOL_COALESCE_RX_USECS_HIGH | \
242 	 ETHTOOL_COALESCE_PKT_RATE_LOW | ETHTOOL_COALESCE_PKT_RATE_HIGH | \
243 	 ETHTOOL_COALESCE_RATE_SAMPLE_INTERVAL)
244 
245 #define ETHTOOL_STAT_NOT_SET	(~0ULL)
246 
ethtool_stats_init(u64 * stats,unsigned int n)247 static inline void ethtool_stats_init(u64 *stats, unsigned int n)
248 {
249 	while (n--)
250 		stats[n] = ETHTOOL_STAT_NOT_SET;
251 }
252 
253 /* Basic IEEE 802.3 MAC statistics (30.3.1.1.*), not otherwise exposed
254  * via a more targeted API.
255  */
256 struct ethtool_eth_mac_stats {
257 	u64 FramesTransmittedOK;
258 	u64 SingleCollisionFrames;
259 	u64 MultipleCollisionFrames;
260 	u64 FramesReceivedOK;
261 	u64 FrameCheckSequenceErrors;
262 	u64 AlignmentErrors;
263 	u64 OctetsTransmittedOK;
264 	u64 FramesWithDeferredXmissions;
265 	u64 LateCollisions;
266 	u64 FramesAbortedDueToXSColls;
267 	u64 FramesLostDueToIntMACXmitError;
268 	u64 CarrierSenseErrors;
269 	u64 OctetsReceivedOK;
270 	u64 FramesLostDueToIntMACRcvError;
271 	u64 MulticastFramesXmittedOK;
272 	u64 BroadcastFramesXmittedOK;
273 	u64 FramesWithExcessiveDeferral;
274 	u64 MulticastFramesReceivedOK;
275 	u64 BroadcastFramesReceivedOK;
276 	u64 InRangeLengthErrors;
277 	u64 OutOfRangeLengthField;
278 	u64 FrameTooLongErrors;
279 };
280 
281 /* Basic IEEE 802.3 PHY statistics (30.3.2.1.*), not otherwise exposed
282  * via a more targeted API.
283  */
284 struct ethtool_eth_phy_stats {
285 	u64 SymbolErrorDuringCarrier;
286 };
287 
288 /* Basic IEEE 802.3 MAC Ctrl statistics (30.3.3.*), not otherwise exposed
289  * via a more targeted API.
290  */
291 struct ethtool_eth_ctrl_stats {
292 	u64 MACControlFramesTransmitted;
293 	u64 MACControlFramesReceived;
294 	u64 UnsupportedOpcodesReceived;
295 };
296 
297 /**
298  * struct ethtool_pause_stats - statistics for IEEE 802.3x pause frames
299  * @tx_pause_frames: transmitted pause frame count. Reported to user space
300  *	as %ETHTOOL_A_PAUSE_STAT_TX_FRAMES.
301  *
302  *	Equivalent to `30.3.4.2 aPAUSEMACCtrlFramesTransmitted`
303  *	from the standard.
304  *
305  * @rx_pause_frames: received pause frame count. Reported to user space
306  *	as %ETHTOOL_A_PAUSE_STAT_RX_FRAMES. Equivalent to:
307  *
308  *	Equivalent to `30.3.4.3 aPAUSEMACCtrlFramesReceived`
309  *	from the standard.
310  */
311 struct ethtool_pause_stats {
312 	u64 tx_pause_frames;
313 	u64 rx_pause_frames;
314 };
315 
316 #define ETHTOOL_MAX_LANES	8
317 
318 /**
319  * struct ethtool_fec_stats - statistics for IEEE 802.3 FEC
320  * @corrected_blocks: number of received blocks corrected by FEC
321  *	Reported to user space as %ETHTOOL_A_FEC_STAT_CORRECTED.
322  *
323  *	Equivalent to `30.5.1.1.17 aFECCorrectedBlocks` from the standard.
324  *
325  * @uncorrectable_blocks: number of received blocks FEC was not able to correct
326  *	Reported to user space as %ETHTOOL_A_FEC_STAT_UNCORR.
327  *
328  *	Equivalent to `30.5.1.1.18 aFECUncorrectableBlocks` from the standard.
329  *
330  * @corrected_bits: number of bits corrected by FEC
331  *	Similar to @corrected_blocks but counts individual bit changes,
332  *	not entire FEC data blocks. This is a non-standard statistic.
333  *	Reported to user space as %ETHTOOL_A_FEC_STAT_CORR_BITS.
334  *
335  * @lane: per-lane/PCS-instance counts as defined by the standard
336  * @total: error counts for the entire port, for drivers incapable of reporting
337  *	per-lane stats
338  *
339  * Drivers should fill in either only total or per-lane statistics, core
340  * will take care of adding lane values up to produce the total.
341  */
342 struct ethtool_fec_stats {
343 	struct ethtool_fec_stat {
344 		u64 total;
345 		u64 lanes[ETHTOOL_MAX_LANES];
346 	} corrected_blocks, uncorrectable_blocks, corrected_bits;
347 };
348 
349 /**
350  * struct ethtool_rmon_hist_range - byte range for histogram statistics
351  * @low: low bound of the bucket (inclusive)
352  * @high: high bound of the bucket (inclusive)
353  */
354 struct ethtool_rmon_hist_range {
355 	u16 low;
356 	u16 high;
357 };
358 
359 #define ETHTOOL_RMON_HIST_MAX	10
360 
361 /**
362  * struct ethtool_rmon_stats - selected RMON (RFC 2819) statistics
363  * @undersize_pkts: Equivalent to `etherStatsUndersizePkts` from the RFC.
364  * @oversize_pkts: Equivalent to `etherStatsOversizePkts` from the RFC.
365  * @fragments: Equivalent to `etherStatsFragments` from the RFC.
366  * @jabbers: Equivalent to `etherStatsJabbers` from the RFC.
367  * @hist: Packet counter for packet length buckets (e.g.
368  *	`etherStatsPkts128to255Octets` from the RFC).
369  * @hist_tx: Tx counters in similar form to @hist, not defined in the RFC.
370  *
371  * Selection of RMON (RFC 2819) statistics which are not exposed via different
372  * APIs, primarily the packet-length-based counters.
373  * Unfortunately different designs choose different buckets beyond
374  * the 1024B mark (jumbo frame teritory), so the definition of the bucket
375  * ranges is left to the driver.
376  */
377 struct ethtool_rmon_stats {
378 	u64 undersize_pkts;
379 	u64 oversize_pkts;
380 	u64 fragments;
381 	u64 jabbers;
382 
383 	u64 hist[ETHTOOL_RMON_HIST_MAX];
384 	u64 hist_tx[ETHTOOL_RMON_HIST_MAX];
385 };
386 
387 #define ETH_MODULE_EEPROM_PAGE_LEN	128
388 #define ETH_MODULE_MAX_I2C_ADDRESS	0x7f
389 
390 /**
391  * struct ethtool_module_eeprom - EEPROM dump from specified page
392  * @offset: Offset within the specified EEPROM page to begin read, in bytes.
393  * @length: Number of bytes to read.
394  * @page: Page number to read from.
395  * @bank: Page bank number to read from, if applicable by EEPROM spec.
396  * @i2c_address: I2C address of a page. Value less than 0x7f expected. Most
397  *	EEPROMs use 0x50 or 0x51.
398  * @data: Pointer to buffer with EEPROM data of @length size.
399  *
400  * This can be used to manage pages during EEPROM dump in ethtool and pass
401  * required information to the driver.
402  */
403 struct ethtool_module_eeprom {
404 	__u32	offset;
405 	__u32	length;
406 	__u8	page;
407 	__u8	bank;
408 	__u8	i2c_address;
409 	__u8	*data;
410 };
411 
412 /**
413  * struct ethtool_ops - optional netdev operations
414  * @cap_link_lanes_supported: indicates if the driver supports lanes
415  *	parameter.
416  * @supported_coalesce_params: supported types of interrupt coalescing.
417  * @get_drvinfo: Report driver/device information.  Should only set the
418  *	@driver, @version, @fw_version and @bus_info fields.  If not
419  *	implemented, the @driver and @bus_info fields will be filled in
420  *	according to the netdev's parent device.
421  * @get_regs_len: Get buffer length required for @get_regs
422  * @get_regs: Get device registers
423  * @get_wol: Report whether Wake-on-Lan is enabled
424  * @set_wol: Turn Wake-on-Lan on or off.  Returns a negative error code
425  *	or zero.
426  * @get_msglevel: Report driver message level.  This should be the value
427  *	of the @msg_enable field used by netif logging functions.
428  * @set_msglevel: Set driver message level
429  * @nway_reset: Restart autonegotiation.  Returns a negative error code
430  *	or zero.
431  * @get_link: Report whether physical link is up.  Will only be called if
432  *	the netdev is up.  Should usually be set to ethtool_op_get_link(),
433  *	which uses netif_carrier_ok().
434  * @get_link_ext_state: Report link extended state. Should set link_ext_state and
435  *	link_ext_substate (link_ext_substate of 0 means link_ext_substate is unknown,
436  *	do not attach ext_substate attribute to netlink message). If link_ext_state
437  *	and link_ext_substate are unknown, return -ENODATA. If not implemented,
438  *	link_ext_state and link_ext_substate will not be sent to userspace.
439  * @get_eeprom_len: Read range of EEPROM addresses for validation of
440  *	@get_eeprom and @set_eeprom requests.
441  *	Returns 0 if device does not support EEPROM access.
442  * @get_eeprom: Read data from the device EEPROM.
443  *	Should fill in the magic field.  Don't need to check len for zero
444  *	or wraparound.  Fill in the data argument with the eeprom values
445  *	from offset to offset + len.  Update len to the amount read.
446  *	Returns an error or zero.
447  * @set_eeprom: Write data to the device EEPROM.
448  *	Should validate the magic field.  Don't need to check len for zero
449  *	or wraparound.  Update len to the amount written.  Returns an error
450  *	or zero.
451  * @get_coalesce: Get interrupt coalescing parameters.  Returns a negative
452  *	error code or zero.
453  * @set_coalesce: Set interrupt coalescing parameters.  Supported coalescing
454  *	types should be set in @supported_coalesce_params.
455  *	Returns a negative error code or zero.
456  * @get_ringparam: Report ring sizes
457  * @set_ringparam: Set ring sizes.  Returns a negative error code or zero.
458  * @get_pause_stats: Report pause frame statistics. Drivers must not zero
459  *	statistics which they don't report. The stats structure is initialized
460  *	to ETHTOOL_STAT_NOT_SET indicating driver does not report statistics.
461  * @get_pauseparam: Report pause parameters
462  * @set_pauseparam: Set pause parameters.  Returns a negative error code
463  *	or zero.
464  * @self_test: Run specified self-tests
465  * @get_strings: Return a set of strings that describe the requested objects
466  * @set_phys_id: Identify the physical devices, e.g. by flashing an LED
467  *	attached to it.  The implementation may update the indicator
468  *	asynchronously or synchronously, but in either case it must return
469  *	quickly.  It is initially called with the argument %ETHTOOL_ID_ACTIVE,
470  *	and must either activate asynchronous updates and return zero, return
471  *	a negative error or return a positive frequency for synchronous
472  *	indication (e.g. 1 for one on/off cycle per second).  If it returns
473  *	a frequency then it will be called again at intervals with the
474  *	argument %ETHTOOL_ID_ON or %ETHTOOL_ID_OFF and should set the state of
475  *	the indicator accordingly.  Finally, it is called with the argument
476  *	%ETHTOOL_ID_INACTIVE and must deactivate the indicator.  Returns a
477  *	negative error code or zero.
478  * @get_ethtool_stats: Return extended statistics about the device.
479  *	This is only useful if the device maintains statistics not
480  *	included in &struct rtnl_link_stats64.
481  * @begin: Function to be called before any other operation.  Returns a
482  *	negative error code or zero.
483  * @complete: Function to be called after any other operation except
484  *	@begin.  Will be called even if the other operation failed.
485  * @get_priv_flags: Report driver-specific feature flags.
486  * @set_priv_flags: Set driver-specific feature flags.  Returns a negative
487  *	error code or zero.
488  * @get_sset_count: Get number of strings that @get_strings will write.
489  * @get_rxnfc: Get RX flow classification rules.  Returns a negative
490  *	error code or zero.
491  * @set_rxnfc: Set RX flow classification rules.  Returns a negative
492  *	error code or zero.
493  * @flash_device: Write a firmware image to device's flash memory.
494  *	Returns a negative error code or zero.
495  * @reset: Reset (part of) the device, as specified by a bitmask of
496  *	flags from &enum ethtool_reset_flags.  Returns a negative
497  *	error code or zero.
498  * @get_rxfh_key_size: Get the size of the RX flow hash key.
499  *	Returns zero if not supported for this specific device.
500  * @get_rxfh_indir_size: Get the size of the RX flow hash indirection table.
501  *	Returns zero if not supported for this specific device.
502  * @get_rxfh: Get the contents of the RX flow hash indirection table, hash key
503  *	and/or hash function.
504  *	Returns a negative error code or zero.
505  * @set_rxfh: Set the contents of the RX flow hash indirection table, hash
506  *	key, and/or hash function.  Arguments which are set to %NULL or zero
507  *	will remain unchanged.
508  *	Returns a negative error code or zero. An error code must be returned
509  *	if at least one unsupported change was requested.
510  * @get_rxfh_context: Get the contents of the RX flow hash indirection table,
511  *	hash key, and/or hash function assiciated to the given rss context.
512  *	Returns a negative error code or zero.
513  * @set_rxfh_context: Create, remove and configure RSS contexts. Allows setting
514  *	the contents of the RX flow hash indirection table, hash key, and/or
515  *	hash function associated to the given context. Arguments which are set
516  *	to %NULL or zero will remain unchanged.
517  *	Returns a negative error code or zero. An error code must be returned
518  *	if at least one unsupported change was requested.
519  * @get_channels: Get number of channels.
520  * @set_channels: Set number of channels.  Returns a negative error code or
521  *	zero.
522  * @get_dump_flag: Get dump flag indicating current dump length, version,
523  * 		   and flag of the device.
524  * @get_dump_data: Get dump data.
525  * @set_dump: Set dump specific flags to the device.
526  * @get_ts_info: Get the time stamping and PTP hardware clock capabilities.
527  *	Drivers supporting transmit time stamps in software should set this to
528  *	ethtool_op_get_ts_info().
529  * @get_module_info: Get the size and type of the eeprom contained within
530  *	a plug-in module.
531  * @get_module_eeprom: Get the eeprom information from the plug-in module
532  * @get_eee: Get Energy-Efficient (EEE) supported and status.
533  * @set_eee: Set EEE status (enable/disable) as well as LPI timers.
534  * @get_tunable: Read the value of a driver / device tunable.
535  * @set_tunable: Set the value of a driver / device tunable.
536  * @get_per_queue_coalesce: Get interrupt coalescing parameters per queue.
537  *	It must check that the given queue number is valid. If neither a RX nor
538  *	a TX queue has this number, return -EINVAL. If only a RX queue or a TX
539  *	queue has this number, set the inapplicable fields to ~0 and return 0.
540  *	Returns a negative error code or zero.
541  * @set_per_queue_coalesce: Set interrupt coalescing parameters per queue.
542  *	It must check that the given queue number is valid. If neither a RX nor
543  *	a TX queue has this number, return -EINVAL. If only a RX queue or a TX
544  *	queue has this number, ignore the inapplicable fields. Supported
545  *	coalescing types should be set in @supported_coalesce_params.
546  *	Returns a negative error code or zero.
547  * @get_link_ksettings: Get various device settings including Ethernet link
548  *	settings. The %cmd and %link_mode_masks_nwords fields should be
549  *	ignored (use %__ETHTOOL_LINK_MODE_MASK_NBITS instead of the latter),
550  *	any change to them will be overwritten by kernel. Returns a negative
551  *	error code or zero.
552  * @set_link_ksettings: Set various device settings including Ethernet link
553  *	settings. The %cmd and %link_mode_masks_nwords fields should be
554  *	ignored (use %__ETHTOOL_LINK_MODE_MASK_NBITS instead of the latter),
555  *	any change to them will be overwritten by kernel. Returns a negative
556  *	error code or zero.
557  * @get_fec_stats: Report FEC statistics.
558  *	Core will sum up per-lane stats to get the total.
559  *	Drivers must not zero statistics which they don't report. The stats
560  *	structure is initialized to ETHTOOL_STAT_NOT_SET indicating driver does
561  *	not report statistics.
562  * @get_fecparam: Get the network device Forward Error Correction parameters.
563  * @set_fecparam: Set the network device Forward Error Correction parameters.
564  * @get_ethtool_phy_stats: Return extended statistics about the PHY device.
565  *	This is only useful if the device maintains PHY statistics and
566  *	cannot use the standard PHY library helpers.
567  * @get_phy_tunable: Read the value of a PHY tunable.
568  * @set_phy_tunable: Set the value of a PHY tunable.
569  * @get_module_eeprom_by_page: Get a region of plug-in module EEPROM data from
570  *	specified page. Returns a negative error code or the amount of bytes
571  *	read.
572  * @get_eth_phy_stats: Query some of the IEEE 802.3 PHY statistics.
573  * @get_eth_mac_stats: Query some of the IEEE 802.3 MAC statistics.
574  * @get_eth_ctrl_stats: Query some of the IEEE 802.3 MAC Ctrl statistics.
575  * @get_rmon_stats: Query some of the RMON (RFC 2819) statistics.
576  *	Set %ranges to a pointer to zero-terminated array of byte ranges.
577  *
578  * All operations are optional (i.e. the function pointer may be set
579  * to %NULL) and callers must take this into account.  Callers must
580  * hold the RTNL lock.
581  *
582  * See the structures used by these operations for further documentation.
583  * Note that for all operations using a structure ending with a zero-
584  * length array, the array is allocated separately in the kernel and
585  * is passed to the driver as an additional parameter.
586  *
587  * See &struct net_device and &struct net_device_ops for documentation
588  * of the generic netdev features interface.
589  */
590 struct ethtool_ops {
591 	u32     cap_link_lanes_supported:1;
592 	u32	supported_coalesce_params;
593 	void	(*get_drvinfo)(struct net_device *, struct ethtool_drvinfo *);
594 	int	(*get_regs_len)(struct net_device *);
595 	void	(*get_regs)(struct net_device *, struct ethtool_regs *, void *);
596 	void	(*get_wol)(struct net_device *, struct ethtool_wolinfo *);
597 	int	(*set_wol)(struct net_device *, struct ethtool_wolinfo *);
598 	u32	(*get_msglevel)(struct net_device *);
599 	void	(*set_msglevel)(struct net_device *, u32);
600 	int	(*nway_reset)(struct net_device *);
601 	u32	(*get_link)(struct net_device *);
602 	int	(*get_link_ext_state)(struct net_device *,
603 				      struct ethtool_link_ext_state_info *);
604 	int	(*get_eeprom_len)(struct net_device *);
605 	int	(*get_eeprom)(struct net_device *,
606 			      struct ethtool_eeprom *, u8 *);
607 	int	(*set_eeprom)(struct net_device *,
608 			      struct ethtool_eeprom *, u8 *);
609 	int	(*get_coalesce)(struct net_device *, struct ethtool_coalesce *);
610 	int	(*set_coalesce)(struct net_device *, struct ethtool_coalesce *);
611 	void	(*get_ringparam)(struct net_device *,
612 				 struct ethtool_ringparam *);
613 	int	(*set_ringparam)(struct net_device *,
614 				 struct ethtool_ringparam *);
615 	void	(*get_pause_stats)(struct net_device *dev,
616 				   struct ethtool_pause_stats *pause_stats);
617 	void	(*get_pauseparam)(struct net_device *,
618 				  struct ethtool_pauseparam*);
619 	int	(*set_pauseparam)(struct net_device *,
620 				  struct ethtool_pauseparam*);
621 	void	(*self_test)(struct net_device *, struct ethtool_test *, u64 *);
622 	void	(*get_strings)(struct net_device *, u32 stringset, u8 *);
623 	int	(*set_phys_id)(struct net_device *, enum ethtool_phys_id_state);
624 	void	(*get_ethtool_stats)(struct net_device *,
625 				     struct ethtool_stats *, u64 *);
626 	int	(*begin)(struct net_device *);
627 	void	(*complete)(struct net_device *);
628 	u32	(*get_priv_flags)(struct net_device *);
629 	int	(*set_priv_flags)(struct net_device *, u32);
630 	int	(*get_sset_count)(struct net_device *, int);
631 	int	(*get_rxnfc)(struct net_device *,
632 			     struct ethtool_rxnfc *, u32 *rule_locs);
633 	int	(*set_rxnfc)(struct net_device *, struct ethtool_rxnfc *);
634 	int	(*flash_device)(struct net_device *, struct ethtool_flash *);
635 	int	(*reset)(struct net_device *, u32 *);
636 	u32	(*get_rxfh_key_size)(struct net_device *);
637 	u32	(*get_rxfh_indir_size)(struct net_device *);
638 	int	(*get_rxfh)(struct net_device *, u32 *indir, u8 *key,
639 			    u8 *hfunc);
640 	int	(*set_rxfh)(struct net_device *, const u32 *indir,
641 			    const u8 *key, const u8 hfunc);
642 	int	(*get_rxfh_context)(struct net_device *, u32 *indir, u8 *key,
643 				    u8 *hfunc, u32 rss_context);
644 	int	(*set_rxfh_context)(struct net_device *, const u32 *indir,
645 				    const u8 *key, const u8 hfunc,
646 				    u32 *rss_context, bool delete);
647 	void	(*get_channels)(struct net_device *, struct ethtool_channels *);
648 	int	(*set_channels)(struct net_device *, struct ethtool_channels *);
649 	int	(*get_dump_flag)(struct net_device *, struct ethtool_dump *);
650 	int	(*get_dump_data)(struct net_device *,
651 				 struct ethtool_dump *, void *);
652 	int	(*set_dump)(struct net_device *, struct ethtool_dump *);
653 	int	(*get_ts_info)(struct net_device *, struct ethtool_ts_info *);
654 	int     (*get_module_info)(struct net_device *,
655 				   struct ethtool_modinfo *);
656 	int     (*get_module_eeprom)(struct net_device *,
657 				     struct ethtool_eeprom *, u8 *);
658 	int	(*get_eee)(struct net_device *, struct ethtool_eee *);
659 	int	(*set_eee)(struct net_device *, struct ethtool_eee *);
660 	int	(*get_tunable)(struct net_device *,
661 			       const struct ethtool_tunable *, void *);
662 	int	(*set_tunable)(struct net_device *,
663 			       const struct ethtool_tunable *, const void *);
664 	int	(*get_per_queue_coalesce)(struct net_device *, u32,
665 					  struct ethtool_coalesce *);
666 	int	(*set_per_queue_coalesce)(struct net_device *, u32,
667 					  struct ethtool_coalesce *);
668 	int	(*get_link_ksettings)(struct net_device *,
669 				      struct ethtool_link_ksettings *);
670 	int	(*set_link_ksettings)(struct net_device *,
671 				      const struct ethtool_link_ksettings *);
672 	void	(*get_fec_stats)(struct net_device *dev,
673 				 struct ethtool_fec_stats *fec_stats);
674 	int	(*get_fecparam)(struct net_device *,
675 				      struct ethtool_fecparam *);
676 	int	(*set_fecparam)(struct net_device *,
677 				      struct ethtool_fecparam *);
678 	void	(*get_ethtool_phy_stats)(struct net_device *,
679 					 struct ethtool_stats *, u64 *);
680 	int	(*get_phy_tunable)(struct net_device *,
681 				   const struct ethtool_tunable *, void *);
682 	int	(*set_phy_tunable)(struct net_device *,
683 				   const struct ethtool_tunable *, const void *);
684 	int	(*get_module_eeprom_by_page)(struct net_device *dev,
685 					     const struct ethtool_module_eeprom *page,
686 					     struct netlink_ext_ack *extack);
687 	void	(*get_eth_phy_stats)(struct net_device *dev,
688 				     struct ethtool_eth_phy_stats *phy_stats);
689 	void	(*get_eth_mac_stats)(struct net_device *dev,
690 				     struct ethtool_eth_mac_stats *mac_stats);
691 	void	(*get_eth_ctrl_stats)(struct net_device *dev,
692 				      struct ethtool_eth_ctrl_stats *ctrl_stats);
693 	void	(*get_rmon_stats)(struct net_device *dev,
694 				  struct ethtool_rmon_stats *rmon_stats,
695 				  const struct ethtool_rmon_hist_range **ranges);
696 };
697 
698 int ethtool_check_ops(const struct ethtool_ops *ops);
699 
700 struct ethtool_rx_flow_rule {
701 	struct flow_rule	*rule;
702 	unsigned long		priv[];
703 };
704 
705 struct ethtool_rx_flow_spec_input {
706 	const struct ethtool_rx_flow_spec	*fs;
707 	u32					rss_ctx;
708 };
709 
710 struct ethtool_rx_flow_rule *
711 ethtool_rx_flow_rule_create(const struct ethtool_rx_flow_spec_input *input);
712 void ethtool_rx_flow_rule_destroy(struct ethtool_rx_flow_rule *rule);
713 
714 bool ethtool_virtdev_validate_cmd(const struct ethtool_link_ksettings *cmd);
715 int ethtool_virtdev_set_link_ksettings(struct net_device *dev,
716 				       const struct ethtool_link_ksettings *cmd,
717 				       u32 *dev_speed, u8 *dev_duplex);
718 
719 struct phy_device;
720 struct phy_tdr_config;
721 
722 /**
723  * struct ethtool_phy_ops - Optional PHY device options
724  * @get_sset_count: Get number of strings that @get_strings will write.
725  * @get_strings: Return a set of strings that describe the requested objects
726  * @get_stats: Return extended statistics about the PHY device.
727  * @start_cable_test: Start a cable test
728  * @start_cable_test_tdr: Start a Time Domain Reflectometry cable test
729  *
730  * All operations are optional (i.e. the function pointer may be set to %NULL)
731  * and callers must take this into account. Callers must hold the RTNL lock.
732  */
733 struct ethtool_phy_ops {
734 	int (*get_sset_count)(struct phy_device *dev);
735 	int (*get_strings)(struct phy_device *dev, u8 *data);
736 	int (*get_stats)(struct phy_device *dev,
737 			 struct ethtool_stats *stats, u64 *data);
738 	int (*start_cable_test)(struct phy_device *phydev,
739 				struct netlink_ext_ack *extack);
740 	int (*start_cable_test_tdr)(struct phy_device *phydev,
741 				    struct netlink_ext_ack *extack,
742 				    const struct phy_tdr_config *config);
743 };
744 
745 /**
746  * ethtool_set_ethtool_phy_ops - Set the ethtool_phy_ops singleton
747  * @ops: Ethtool PHY operations to set
748  */
749 void ethtool_set_ethtool_phy_ops(const struct ethtool_phy_ops *ops);
750 
751 /**
752  * ethtool_params_from_link_mode - Derive link parameters from a given link mode
753  * @link_ksettings: Link parameters to be derived from the link mode
754  * @link_mode: Link mode
755  */
756 void
757 ethtool_params_from_link_mode(struct ethtool_link_ksettings *link_ksettings,
758 			      enum ethtool_link_mode_bit_indices link_mode);
759 
760 /**
761  * ethtool_sprintf - Write formatted string to ethtool string data
762  * @data: Pointer to start of string to update
763  * @fmt: Format of string to write
764  *
765  * Write formatted string to data. Update data to point at start of
766  * next string.
767  */
768 extern __printf(2, 3) void ethtool_sprintf(u8 **data, const char *fmt, ...);
769 #endif /* _LINUX_ETHTOOL_H */
770