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