New upstream version 18.02
[deb_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_driverinfo
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::rte_net_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 Ethernet device pause frame configuration according to
158  * parameter attributes desribed by ethtool data structure,
159  * ethtool_pauseparam.
160  *
161  * @param port_id
162  *   The port identifier of the Ethernet device.
163  * @param pause_param
164  *       The pointer of ethtool_coalesce that gets pause frame
165  *       configuration parameters
166  * @return
167  *   - (0) if successful.
168  *   - (-ENOTSUP) if hardware doesn't support.
169  *   - (-ENODEV) if *port_id* invalid.
170  *   - (-EINVAL) if parameters invalid.
171  *   - others depends on the specific operations implementation.
172  */
173 int rte_ethtool_get_pauseparam(uint16_t port_id,
174                                    struct ethtool_pauseparam *pause_param);
175
176 /**
177  * Setting the Ethernet device pause frame configuration according to
178  * parameter attributes desribed by ethtool data structure, ethtool_pauseparam.
179  *
180  * @param port_id
181  *   The port identifier of the Ethernet device.
182  * @param pause_param
183  *       The pointer of ethtool_coalesce that gets ring configuration parameters
184  * @return
185  *   - (0) if successful.
186  *   - (-ENOTSUP) if hardware doesn't support.
187  *   - (-ENODEV) if *port_id* invalid.
188  *   - (-EINVAL) if parameters invalid.
189  *   - others depends on the specific operations implementation.
190  */
191 int rte_ethtool_set_pauseparam(uint16_t port_id,
192                                    struct ethtool_pauseparam *param);
193
194 /**
195  * Start the Ethernet device.
196  *
197  * @param port_id
198  *   The port identifier of the Ethernet device.
199  * @return
200  *   - (0) if successful.
201  *   - (-ENOTSUP) if hardware doesn't support.
202  *   - (-ENODEV) if *port_id* invalid.
203  *   - others depends on the specific operations implementation.
204  */
205 int rte_ethtool_net_open(uint16_t port_id);
206
207 /**
208  * Stop the Ethernet device.
209  *
210  * @param port_id
211  *   The port identifier of the Ethernet device.
212  * @return
213  *   - (0) if successful.
214  *   - (-ENODEV) if *port_id* invalid.
215  */
216 int rte_ethtool_net_stop(uint16_t port_id);
217
218 /**
219  * Get the Ethernet device MAC address.
220  *
221  * @param port_id
222  *   The port identifier of the Ethernet device.
223  * @param addr
224  *       MAC address of the Ethernet device.
225  * @return
226  *   - (0) if successful.
227  *   - (-ENODEV) if *port_id* invalid.
228  */
229 int rte_ethtool_net_get_mac_addr(uint16_t port_id, struct ether_addr *addr);
230
231 /**
232  * Setting the Ethernet device MAC address.
233  *
234  * @param port_id
235  *   The port identifier of the Ethernet device.
236  * @param addr
237  *       The new MAC addr.
238  * @return
239  *   - (0) if successful.
240  *   - (-ENOTSUP) if hardware doesn't support.
241  *   - (-ENODEV) if *port_id* invalid.
242  *   - (-EINVAL) if parameters invalid.
243  *   - others depends on the specific operations implementation.
244  */
245 int rte_ethtool_net_set_mac_addr(uint16_t port_id, struct ether_addr *addr);
246
247 /**
248  * Validate if the provided MAC address is valid unicast address
249  *
250  * @param port_id
251  *   The port identifier of the Ethernet device.
252  * @param addr
253  *       A pointer to a buffer (6-byte, 48bit) for the target MAC address
254  * @return
255  *   - (0) if successful.
256  *   - (-ENOTSUP) if hardware doesn't support.
257  *   - (-ENODEV) if *port_id* invalid.
258  *   - (-EINVAL) if parameters invalid.
259  *   - others depends on the specific operations implementation.
260  */
261 int rte_ethtool_net_validate_addr(uint16_t port_id, struct ether_addr *addr);
262
263 /**
264  * Setting the Ethernet device maximum Tx unit.
265  *
266  * @param port_id
267  *   The port identifier of the Ethernet device.
268  * @param mtu
269  *       New MTU
270  * @return
271  *   - (0) if successful.
272  *   - (-ENOTSUP) if hardware doesn't support.
273  *   - (-ENODEV) if *port_id* invalid.
274  *   - (-EINVAL) if parameters invalid.
275  *   - others depends on the specific operations implementation.
276  */
277 int rte_ethtool_net_change_mtu(uint16_t port_id, int mtu);
278
279 /**
280  * Retrieve the Ethernet device traffic statistics
281  *
282  * @param port_id
283  *   The port identifier of the Ethernet device.
284  * @param stats
285  *       A pointer to struct rte_eth_stats for statistics parameters
286  * @return
287  *   - (0) if successful.
288  *   - (-ENOTSUP) if hardware doesn't support.
289  *   - (-ENODEV) if *port_id* invalid.
290  *   - (-EINVAL) if parameters invalid.
291  *   - others depends on the specific operations implementation.
292  */
293 int rte_ethtool_net_get_stats64(uint16_t port_id, struct rte_eth_stats *stats);
294
295 /**
296  * Update the Ethernet device VLAN filter with new vid
297  *
298  * @param port_id
299  *   The port identifier of the Ethernet device.
300  * @param vid
301  *       A new VLAN id
302  * @return
303  *   - (0) if successful.
304  *   - (-ENOTSUP) if hardware doesn't support.
305  *   - (-ENODEV) if *port_id* invalid.
306  *   - others depends on the specific operations implementation.
307  */
308 int rte_ethtool_net_vlan_rx_add_vid(uint16_t port_id, uint16_t vid);
309
310 /**
311  * Remove VLAN id from Ethernet device.
312  *
313  * @param port_id
314  *   The port identifier of the Ethernet device.
315  * @param vid
316  *       A new VLAN id
317  * @return
318  *   - (0) if successful.
319  *   - (-ENOTSUP) if hardware doesn't support.
320  *   - (-ENODEV) if *port_id* invalid.
321  *   - others depends on the specific operations implementation.
322  */
323 int rte_ethtool_net_vlan_rx_kill_vid(uint16_t port_id, uint16_t vid);
324
325 /**
326  * Setting the Ethernet device rx mode.
327  *
328  * @param port_id
329  *   The port identifier of the Ethernet device.
330  * @return
331  *   - (0) if successful.
332  *   - (-ENOTSUP) if hardware doesn't support.
333  *   - (-ENODEV) if *port_id* invalid.
334  *   - others depends on the specific operations implementation.
335  */
336 int rte_ethtool_net_set_rx_mode(uint16_t port_id);
337
338 /**
339  * Getting ring parameters for Ethernet device.
340  *
341  * @param port_id
342  *   The port identifier of the Ethernet device.
343  * @param ring_param
344  *   Pointer to struct ethrool_ringparam to receive parameters.
345  * @return
346  *   - (0) if successful.
347  *   - (-ENOTSUP) if hardware doesn't support.
348  *   - (-ENODEV) if *port_id* invalid.
349  *   - others depends on the specific operations implementation.
350  * @note
351  *   Only the tx_pending and rx_pending fields of struct ethtool_ringparam
352  *   are used, and the function only gets parameters for queue 0.
353  */
354 int rte_ethtool_get_ringparam(uint16_t port_id,
355         struct ethtool_ringparam *ring_param);
356
357 /**
358  * Setting ring parameters for Ethernet device.
359  *
360  * @param port_id
361  *   The port identifier of the Ethernet device.
362  * @param ring_param
363  *   Pointer to struct ethrool_ringparam with parameters to set.
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  * @note
370  *   Only the tx_pending and rx_pending fields of struct ethtool_ringparam
371  *   are used, and the function only sets parameters for queue 0.
372  */
373 int rte_ethtool_set_ringparam(uint16_t port_id,
374         struct ethtool_ringparam *ring_param);
375
376
377 #ifdef __cplusplus
378 }
379 #endif
380
381 #endif /* _RTE_ETHTOOL_H_ */