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