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