31cd5ae4ef6c681393b408133d29f6912757329c
[dpdk.git] / examples / ethtool / lib / rte_ethtool.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2015 Intel Corporation
3  */
4
5 #ifndef _RTE_ETHTOOL_H_
6 #define _RTE_ETHTOOL_H_
7
8 /*
9  * This new interface is designed to provide a user-space shim layer for
10  * Ethtool and Netdevice op API.
11  *
12  * rte_ethtool_get_driver:          ethtool_ops::get_drvinfo
13  * rte_ethtool_get_link:            ethtool_ops::get_link
14  * rte_ethtool_get_regs_len:        ethtool_ops::get_regs_len
15  * rte_ethtool_get_regs:            ethtool_ops::get_regs
16  * rte_ethtool_get_eeprom_len:      ethtool_ops::get_eeprom_len
17  * rte_ethtool_get_eeprom:          ethtool_ops::get_eeprom
18  * rte_ethtool_set_eeprom:          ethtool_ops::set_eeprom
19  * rte_ethtool_get_pauseparam:      ethtool_ops::get_pauseparam
20  * rte_ethtool_set_pauseparam:      ethtool_ops::set_pauseparam
21  *
22  * rte_ethtool_net_open:            net_device_ops::ndo_open
23  * rte_ethtool_net_stop:            net_device_ops::ndo_stop
24  * rte_ethtool_net_set_mac_addr:    net_device_ops::ndo_set_mac_address
25  * rte_ethtool_net_validate_addr:   net_device_ops::ndo_validate_addr
26  * rte_ethtool_net_change_mtu:      net_device_ops::ndo_change_mtu
27  * rte_ethtool_net_get_stats64:     net_device_ops::ndo_get_stats64
28  * rte_ethtool_net_vlan_rx_add_vid  net_device_ops::ndo_vlan_rx_add_vid
29  * rte_ethtool_net_vlan_rx_kill_vid net_device_ops::ndo_vlan_rx_kill_vid
30  * rte_ethtool_net_set_rx_mode      net_device_ops::ndo_set_rx_mode
31  *
32  */
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 #include <stdint.h>
38 #include <rte_ethdev.h>
39 #include <linux/ethtool.h>
40
41 /**
42  * Retrieve the Ethernet device driver information according to
43  * attributes described by ethtool data structure, ethtool_drvinfo.
44  *
45  * @param port_id
46  *   The port identifier of the Ethernet device.
47  * @param drvinfo
48  *   A pointer to get driver information
49  * @return
50  *   - (0) if successful.
51  *   - (-ENODEV) if *port_id* invalid.
52  */
53 int rte_ethtool_get_drvinfo(uint16_t port_id, struct ethtool_drvinfo *drvinfo);
54
55 /**
56  * Retrieve the Ethernet device register length in bytes.
57  *
58  * @param port_id
59  *   The port identifier of the Ethernet device.
60  * @return
61  *   - (> 0) # of device registers (in bytes) available for dump
62  *   - (0) no registers available for dump.
63  *   - (-ENOTSUP) if hardware doesn't support.
64  *   - (-ENODEV) if *port_id* invalid.
65  *   - others depends on the specific operations implementation.
66  */
67 int rte_ethtool_get_regs_len(uint16_t port_id);
68
69 /**
70  * Retrieve the Ethernet device register information according to
71  * attributes described by ethtool data structure, ethtool_regs
72  *
73  * @param port_id
74  *   The port identifier of the Ethernet device.
75  * @param reg
76  *   A pointer to ethtool_regs that has register information
77  * @param data
78  *   A pointer to a buffer that is used to retrieve device register content
79  * @return
80  *   - (0) if successful.
81  *   - (-ENOTSUP) if hardware doesn't support.
82  *   - (-ENODEV) if *port_id* invalid.
83  *   - others depends on the specific operations implementation.
84  */
85 int rte_ethtool_get_regs(uint16_t port_id, struct ethtool_regs *regs,
86                             void *data);
87
88 /**
89  * Retrieve the Ethernet device link status
90  *
91  * @param port_id
92  *   The port identifier of the Ethernet device.
93  * @return
94  *   - (1) if link up.
95  *   - (0) if link down.
96  *   - (-ENOTSUP) if hardware doesn't support.
97  *   - (-ENODEV) if *port_id* invalid.
98  *   - (-EINVAL) if parameters invalid.
99  *   - others depends on the specific operations implementation.
100  */
101 int rte_ethtool_get_link(uint16_t port_id);
102
103 /**
104  * Retrieve the Ethernet device EEPROM size
105  *
106  * @param port_id
107  *   The port identifier of the Ethernet device.
108  * @return
109  *       - (> 0) device EEPROM size in bytes
110  *   - (0) device has NO EEPROM
111  *   - (-ENOTSUP) if hardware doesn't support.
112  *   - (-ENODEV) if *port_id* invalid.
113  *   - others depends on the specific operations implementation.
114  */
115 int rte_ethtool_get_eeprom_len(uint16_t port_id);
116
117 /**
118  * Retrieve EEPROM content based upon eeprom range described in ethtool
119  * data structure, ethtool_eeprom
120  *
121  * @param port_id
122  *   The port identifier of the Ethernet device.
123  * @param eeprom
124  *       The pointer of ethtool_eeprom that provides eeprom range
125  * @param words
126  *       A buffer that holds data read from eeprom
127  * @return
128  *   - (0) if successful.
129  *   - (-ENOTSUP) if hardware doesn't support.
130  *   - (-ENODEV) if *port_id* invalid.
131  *   - others depends on the specific operations implementation.
132  */
133 int rte_ethtool_get_eeprom(uint16_t port_id, struct ethtool_eeprom *eeprom,
134                               void *words);
135
136 /**
137  * Setting EEPROM content based upon eeprom range described in ethtool
138  * data structure, ethtool_eeprom
139  *
140  * @param port_id
141  *   The port identifier of the Ethernet device.
142  * @param eeprom
143  *       The pointer of ethtool_eeprom that provides eeprom range
144  * @param words
145  *       A buffer that holds data to be written into eeprom
146  * @return
147  *   - (0) if successful.
148  *   - (-ENOTSUP) if hardware doesn't support.
149  *   - (-ENODEV) if *port_id* invalid.
150  *   - (-EINVAL) if parameters invalid.
151  *   - others depends on the specific operations implementation.
152  */
153 int rte_ethtool_set_eeprom(uint16_t port_id, struct ethtool_eeprom *eeprom,
154                               void *words);
155
156 /**
157  * Retrieve the type and size of plugin module EEPROM
158  *
159  * @param port_id
160  *   The port identifier of the Ethernet device.
161  * @param modinfo
162  *       The pointer that provides the type and size of plugin module EEPROM.
163  * @return
164  *   - (0) if successful.
165  *   - (-ENOTSUP) if hardware doesn't support.
166  *   - (-ENODEV) if *port_id* invalid.
167  *   - others depends on the specific operations implementation.
168  */
169 int rte_ethtool_get_module_info(uint16_t port_id, uint32_t *modinfo);
170
171 /**
172  * Retrieve the data of plugin module EEPROM
173  *
174  * @param port_id
175  *   The port identifier of the Ethernet device.
176  * @param eeprom
177  *       The pointer of ethtool_eeprom that provides plugin module eeprom
178  *   offset and length
179  * @param words
180  *       A buffer that holds data read from plugin module eeprom
181  * @return
182  *   - (0) if successful.
183  *   - (-ENOTSUP) if hardware doesn't support.
184  *   - (-ENODEV) if *port_id* invalid.
185  *   - others depends on the specific operations implementation.
186  */
187 int rte_ethtool_get_module_eeprom(uint16_t port_id,
188                                   struct ethtool_eeprom *eeprom, void *words);
189
190 /**
191  * Retrieve the Ethernet device pause frame configuration according to
192  * parameter attributes desribed by ethtool data structure,
193  * ethtool_pauseparam.
194  *
195  * @param port_id
196  *   The port identifier of the Ethernet device.
197  * @param pause_param
198  *       The pointer of ethtool_coalesce that gets pause frame
199  *       configuration parameters
200  * @return
201  *   - (0) if successful.
202  *   - (-ENOTSUP) if hardware doesn't support.
203  *   - (-ENODEV) if *port_id* invalid.
204  *   - (-EINVAL) if parameters invalid.
205  *   - others depends on the specific operations implementation.
206  */
207 int rte_ethtool_get_pauseparam(uint16_t port_id,
208                                    struct ethtool_pauseparam *pause_param);
209
210 /**
211  * Setting the Ethernet device pause frame configuration according to
212  * parameter attributes desribed by ethtool data structure, ethtool_pauseparam.
213  *
214  * @param port_id
215  *   The port identifier of the Ethernet device.
216  * @param pause_param
217  *       The pointer of ethtool_coalesce that gets ring configuration parameters
218  * @return
219  *   - (0) if successful.
220  *   - (-ENOTSUP) if hardware doesn't support.
221  *   - (-ENODEV) if *port_id* invalid.
222  *   - (-EINVAL) if parameters invalid.
223  *   - others depends on the specific operations implementation.
224  */
225 int rte_ethtool_set_pauseparam(uint16_t port_id,
226                                    struct ethtool_pauseparam *param);
227
228 /**
229  * Start the Ethernet device.
230  *
231  * @param port_id
232  *   The port identifier of the Ethernet device.
233  * @return
234  *   - (0) if successful.
235  *   - (-ENOTSUP) if hardware doesn't support.
236  *   - (-ENODEV) if *port_id* invalid.
237  *   - others depends on the specific operations implementation.
238  */
239 int rte_ethtool_net_open(uint16_t port_id);
240
241 /**
242  * Stop the Ethernet device.
243  *
244  * @param port_id
245  *   The port identifier of the Ethernet device.
246  * @return
247  *   - (0) if successful.
248  *   - (-ENODEV) if *port_id* invalid.
249  */
250 int rte_ethtool_net_stop(uint16_t port_id);
251
252 /**
253  * Get the Ethernet device MAC address.
254  *
255  * @param port_id
256  *   The port identifier of the Ethernet device.
257  * @param addr
258  *       MAC address of the Ethernet device.
259  * @return
260  *   - (0) if successful.
261  *   - (-ENODEV) if *port_id* invalid.
262  */
263 int rte_ethtool_net_get_mac_addr(uint16_t port_id, struct ether_addr *addr);
264
265 /**
266  * Setting the Ethernet device MAC address.
267  *
268  * @param port_id
269  *   The port identifier of the Ethernet device.
270  * @param addr
271  *       The new MAC addr.
272  * @return
273  *   - (0) if successful.
274  *   - (-ENOTSUP) if hardware doesn't support.
275  *   - (-ENODEV) if *port_id* invalid.
276  *   - (-EINVAL) if parameters invalid.
277  *   - others depends on the specific operations implementation.
278  */
279 int rte_ethtool_net_set_mac_addr(uint16_t port_id, struct ether_addr *addr);
280
281 /**
282  * Validate if the provided MAC address is valid unicast address
283  *
284  * @param port_id
285  *   The port identifier of the Ethernet device.
286  * @param addr
287  *       A pointer to a buffer (6-byte, 48bit) for the target MAC address
288  * @return
289  *   - (0) if successful.
290  *   - (-ENOTSUP) if hardware doesn't support.
291  *   - (-ENODEV) if *port_id* invalid.
292  *   - (-EINVAL) if parameters invalid.
293  *   - others depends on the specific operations implementation.
294  */
295 int rte_ethtool_net_validate_addr(uint16_t port_id, struct ether_addr *addr);
296
297 /**
298  * Setting the Ethernet device maximum Tx unit.
299  *
300  * @param port_id
301  *   The port identifier of the Ethernet device.
302  * @param mtu
303  *       New MTU
304  * @return
305  *   - (0) if successful.
306  *   - (-ENOTSUP) if hardware doesn't support.
307  *   - (-ENODEV) if *port_id* invalid.
308  *   - (-EINVAL) if parameters invalid.
309  *   - others depends on the specific operations implementation.
310  */
311 int rte_ethtool_net_change_mtu(uint16_t port_id, int mtu);
312
313 /**
314  * Retrieve the Ethernet device traffic statistics
315  *
316  * @param port_id
317  *   The port identifier of the Ethernet device.
318  * @param stats
319  *       A pointer to struct rte_eth_stats for statistics parameters
320  * @return
321  *   - (0) if successful.
322  *   - (-ENOTSUP) if hardware doesn't support.
323  *   - (-ENODEV) if *port_id* invalid.
324  *   - (-EINVAL) if parameters invalid.
325  *   - others depends on the specific operations implementation.
326  */
327 int rte_ethtool_net_get_stats64(uint16_t port_id, struct rte_eth_stats *stats);
328
329 /**
330  * Update the Ethernet device VLAN filter with new vid
331  *
332  * @param port_id
333  *   The port identifier of the Ethernet device.
334  * @param vid
335  *       A new VLAN id
336  * @return
337  *   - (0) if successful.
338  *   - (-ENOTSUP) if hardware doesn't support.
339  *   - (-ENODEV) if *port_id* invalid.
340  *   - others depends on the specific operations implementation.
341  */
342 int rte_ethtool_net_vlan_rx_add_vid(uint16_t port_id, uint16_t vid);
343
344 /**
345  * Remove VLAN id from Ethernet device.
346  *
347  * @param port_id
348  *   The port identifier of the Ethernet device.
349  * @param vid
350  *       A new VLAN id
351  * @return
352  *   - (0) if successful.
353  *   - (-ENOTSUP) if hardware doesn't support.
354  *   - (-ENODEV) if *port_id* invalid.
355  *   - others depends on the specific operations implementation.
356  */
357 int rte_ethtool_net_vlan_rx_kill_vid(uint16_t port_id, uint16_t vid);
358
359 /**
360  * Setting the Ethernet device rx mode.
361  *
362  * @param port_id
363  *   The port identifier of the Ethernet device.
364  * @return
365  *   - (0) if successful.
366  *   - (-ENOTSUP) if hardware doesn't support.
367  *   - (-ENODEV) if *port_id* invalid.
368  *   - others depends on the specific operations implementation.
369  */
370 int rte_ethtool_net_set_rx_mode(uint16_t port_id);
371
372 /**
373  * Getting ring parameters for Ethernet device.
374  *
375  * @param port_id
376  *   The port identifier of the Ethernet device.
377  * @param ring_param
378  *   Pointer to struct ethrool_ringparam to receive parameters.
379  * @return
380  *   - (0) if successful.
381  *   - (-ENOTSUP) if hardware doesn't support.
382  *   - (-ENODEV) if *port_id* invalid.
383  *   - others depends on the specific operations implementation.
384  * @note
385  *   Only the tx_pending and rx_pending fields of struct ethtool_ringparam
386  *   are used, and the function only gets parameters for queue 0.
387  */
388 int rte_ethtool_get_ringparam(uint16_t port_id,
389         struct ethtool_ringparam *ring_param);
390
391 /**
392  * Setting ring parameters for Ethernet device.
393  *
394  * @param port_id
395  *   The port identifier of the Ethernet device.
396  * @param ring_param
397  *   Pointer to struct ethrool_ringparam with parameters to set.
398  * @return
399  *   - (0) if successful.
400  *   - (-ENOTSUP) if hardware doesn't support.
401  *   - (-ENODEV) if *port_id* invalid.
402  *   - others depends on the specific operations implementation.
403  * @note
404  *   Only the tx_pending and rx_pending fields of struct ethtool_ringparam
405  *   are used, and the function only sets parameters for queue 0.
406  */
407 int rte_ethtool_set_ringparam(uint16_t port_id,
408         struct ethtool_ringparam *ring_param);
409
410
411 #ifdef __cplusplus
412 }
413 #endif
414
415 #endif /* _RTE_ETHTOOL_H_ */