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