xref: /dpdk/examples/ethtool/lib/rte_ethtool.c (revision 001a1c0f98f4e3ac19c26515892e2448a7547c38)
1bda68ab9SRemy Horton /*-
2bda68ab9SRemy Horton  *   BSD LICENSE
3bda68ab9SRemy Horton  *
4bda68ab9SRemy Horton  *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
5bda68ab9SRemy Horton  *   All rights reserved.
6bda68ab9SRemy Horton  *
7bda68ab9SRemy Horton  *   Redistribution and use in source and binary forms, with or without
8bda68ab9SRemy Horton  *   modification, are permitted provided that the following conditions
9bda68ab9SRemy Horton  *   are met:
10bda68ab9SRemy Horton  *
11bda68ab9SRemy Horton  *     * Redistributions of source code must retain the above copyright
12bda68ab9SRemy Horton  *       notice, this list of conditions and the following disclaimer.
13bda68ab9SRemy Horton  *     * Redistributions in binary form must reproduce the above copyright
14bda68ab9SRemy Horton  *       notice, this list of conditions and the following disclaimer in
15bda68ab9SRemy Horton  *       the documentation and/or other materials provided with the
16bda68ab9SRemy Horton  *       distribution.
17bda68ab9SRemy Horton  *     * Neither the name of Intel Corporation nor the names of its
18bda68ab9SRemy Horton  *       contributors may be used to endorse or promote products derived
19bda68ab9SRemy Horton  *       from this software without specific prior written permission.
20bda68ab9SRemy Horton  *
21bda68ab9SRemy Horton  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22bda68ab9SRemy Horton  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23bda68ab9SRemy Horton  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24bda68ab9SRemy Horton  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25bda68ab9SRemy Horton  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26bda68ab9SRemy Horton  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27bda68ab9SRemy Horton  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28bda68ab9SRemy Horton  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29bda68ab9SRemy Horton  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30bda68ab9SRemy Horton  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31bda68ab9SRemy Horton  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32bda68ab9SRemy Horton  */
33bda68ab9SRemy Horton #include <stdio.h>
34bda68ab9SRemy Horton #include <string.h>
35bda68ab9SRemy Horton #include <stdint.h>
36bda68ab9SRemy Horton #include <rte_version.h>
37bda68ab9SRemy Horton #include <rte_ethdev.h>
38bda68ab9SRemy Horton #include <rte_ether.h>
39bda68ab9SRemy Horton #include "rte_ethtool.h"
40bda68ab9SRemy Horton 
41bda68ab9SRemy Horton #define PKTPOOL_SIZE 512
42bda68ab9SRemy Horton #define PKTPOOL_CACHE 32
43bda68ab9SRemy Horton 
44bda68ab9SRemy Horton 
45bda68ab9SRemy Horton int
46bda68ab9SRemy Horton rte_ethtool_get_drvinfo(uint8_t port_id, struct ethtool_drvinfo *drvinfo)
47bda68ab9SRemy Horton {
48bda68ab9SRemy Horton 	struct rte_eth_dev_info dev_info;
49*001a1c0fSZyta Szpak 	struct rte_dev_reg_info reg_info;
50bda68ab9SRemy Horton 	int n;
51bda68ab9SRemy Horton 
52bda68ab9SRemy Horton 	if (drvinfo == NULL)
53bda68ab9SRemy Horton 		return -EINVAL;
54bda68ab9SRemy Horton 
551414dabcSMauricio Vasquez B 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
56bda68ab9SRemy Horton 
57bda68ab9SRemy Horton 	memset(&dev_info, 0, sizeof(dev_info));
58bda68ab9SRemy Horton 	rte_eth_dev_info_get(port_id, &dev_info);
59bda68ab9SRemy Horton 
60bda68ab9SRemy Horton 	snprintf(drvinfo->driver, sizeof(drvinfo->driver), "%s",
61bda68ab9SRemy Horton 		dev_info.driver_name);
62bda68ab9SRemy Horton 	snprintf(drvinfo->version, sizeof(drvinfo->version), "%s",
63bda68ab9SRemy Horton 		rte_version());
64bda68ab9SRemy Horton 	snprintf(drvinfo->bus_info, sizeof(drvinfo->bus_info),
65bda68ab9SRemy Horton 		"%04x:%02x:%02x.%x",
66bda68ab9SRemy Horton 		dev_info.pci_dev->addr.domain, dev_info.pci_dev->addr.bus,
67bda68ab9SRemy Horton 		dev_info.pci_dev->addr.devid, dev_info.pci_dev->addr.function);
68bda68ab9SRemy Horton 
69*001a1c0fSZyta Szpak 	memset(&reg_info, 0, sizeof(reg_info));
70*001a1c0fSZyta Szpak 	rte_eth_dev_get_reg_info(port_id, &reg_info);
71*001a1c0fSZyta Szpak 	n = reg_info.length;
72bda68ab9SRemy Horton 	if (n > 0)
73bda68ab9SRemy Horton 		drvinfo->regdump_len = n;
74bda68ab9SRemy Horton 	else
75bda68ab9SRemy Horton 		drvinfo->regdump_len = 0;
76bda68ab9SRemy Horton 
77bda68ab9SRemy Horton 	n = rte_eth_dev_get_eeprom_length(port_id);
78bda68ab9SRemy Horton 	if (n > 0)
79bda68ab9SRemy Horton 		drvinfo->eedump_len = n;
80bda68ab9SRemy Horton 	else
81bda68ab9SRemy Horton 		drvinfo->eedump_len = 0;
82bda68ab9SRemy Horton 
83bda68ab9SRemy Horton 	drvinfo->n_stats = sizeof(struct rte_eth_stats) / sizeof(uint64_t);
84bda68ab9SRemy Horton 	drvinfo->testinfo_len = 0;
85bda68ab9SRemy Horton 
86bda68ab9SRemy Horton 	return 0;
87bda68ab9SRemy Horton }
88bda68ab9SRemy Horton 
89bda68ab9SRemy Horton int
90bda68ab9SRemy Horton rte_ethtool_get_regs_len(uint8_t port_id)
91bda68ab9SRemy Horton {
92*001a1c0fSZyta Szpak 	struct rte_dev_reg_info reg_info;
93*001a1c0fSZyta Szpak 	int ret;
94bda68ab9SRemy Horton 
95*001a1c0fSZyta Szpak 	memset(&reg_info, 0, sizeof(reg_info));
96*001a1c0fSZyta Szpak 
97*001a1c0fSZyta Szpak 	ret = rte_eth_dev_get_reg_info(port_id, &reg_info);
98*001a1c0fSZyta Szpak 	if (ret)
99*001a1c0fSZyta Szpak 		return ret;
100*001a1c0fSZyta Szpak 
101*001a1c0fSZyta Szpak 	return reg_info.length * reg_info.width;
102bda68ab9SRemy Horton }
103bda68ab9SRemy Horton 
104bda68ab9SRemy Horton int
105bda68ab9SRemy Horton rte_ethtool_get_regs(uint8_t port_id, struct ethtool_regs *regs, void *data)
106bda68ab9SRemy Horton {
107bda68ab9SRemy Horton 	struct rte_dev_reg_info reg_info;
108bda68ab9SRemy Horton 	int status;
109bda68ab9SRemy Horton 
110bda68ab9SRemy Horton 	if (regs == NULL || data == NULL)
111bda68ab9SRemy Horton 		return -EINVAL;
112bda68ab9SRemy Horton 
113bda68ab9SRemy Horton 	reg_info.data = data;
114bda68ab9SRemy Horton 	reg_info.length = 0;
115bda68ab9SRemy Horton 
116bda68ab9SRemy Horton 	status = rte_eth_dev_get_reg_info(port_id, &reg_info);
117bda68ab9SRemy Horton 	if (status)
118bda68ab9SRemy Horton 		return status;
119bda68ab9SRemy Horton 	regs->version = reg_info.version;
120bda68ab9SRemy Horton 
121bda68ab9SRemy Horton 	return 0;
122bda68ab9SRemy Horton }
123bda68ab9SRemy Horton 
124bda68ab9SRemy Horton int
125bda68ab9SRemy Horton rte_ethtool_get_link(uint8_t port_id)
126bda68ab9SRemy Horton {
127bda68ab9SRemy Horton 	struct rte_eth_link link;
128bda68ab9SRemy Horton 
1291414dabcSMauricio Vasquez B 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
130bda68ab9SRemy Horton 	rte_eth_link_get(port_id, &link);
131bda68ab9SRemy Horton 	return link.link_status;
132bda68ab9SRemy Horton }
133bda68ab9SRemy Horton 
134bda68ab9SRemy Horton int
135bda68ab9SRemy Horton rte_ethtool_get_eeprom_len(uint8_t port_id)
136bda68ab9SRemy Horton {
137bda68ab9SRemy Horton 	return rte_eth_dev_get_eeprom_length(port_id);
138bda68ab9SRemy Horton }
139bda68ab9SRemy Horton 
140bda68ab9SRemy Horton int
141bda68ab9SRemy Horton rte_ethtool_get_eeprom(uint8_t port_id, struct ethtool_eeprom *eeprom,
142bda68ab9SRemy Horton 	void *words)
143bda68ab9SRemy Horton {
144bda68ab9SRemy Horton 	struct rte_dev_eeprom_info eeprom_info;
145bda68ab9SRemy Horton 	int status;
146bda68ab9SRemy Horton 
147bda68ab9SRemy Horton 	if (eeprom == NULL || words == NULL)
148bda68ab9SRemy Horton 		return -EINVAL;
149bda68ab9SRemy Horton 
150bda68ab9SRemy Horton 	eeprom_info.offset = eeprom->offset;
151bda68ab9SRemy Horton 	eeprom_info.length = eeprom->len;
152bda68ab9SRemy Horton 	eeprom_info.data = words;
153bda68ab9SRemy Horton 
154bda68ab9SRemy Horton 	status = rte_eth_dev_get_eeprom(port_id, &eeprom_info);
155bda68ab9SRemy Horton 	if (status)
156bda68ab9SRemy Horton 		return status;
157bda68ab9SRemy Horton 
158bda68ab9SRemy Horton 	eeprom->magic = eeprom_info.magic;
159bda68ab9SRemy Horton 
160bda68ab9SRemy Horton 	return 0;
161bda68ab9SRemy Horton }
162bda68ab9SRemy Horton 
163bda68ab9SRemy Horton int
164bda68ab9SRemy Horton rte_ethtool_set_eeprom(uint8_t port_id, struct ethtool_eeprom *eeprom,
165bda68ab9SRemy Horton 	void *words)
166bda68ab9SRemy Horton {
167bda68ab9SRemy Horton 	struct rte_dev_eeprom_info eeprom_info;
168bda68ab9SRemy Horton 	int status;
169bda68ab9SRemy Horton 
170bda68ab9SRemy Horton 	if (eeprom == NULL || words == NULL || eeprom->offset >= eeprom->len)
171bda68ab9SRemy Horton 		return -EINVAL;
172bda68ab9SRemy Horton 
173bda68ab9SRemy Horton 	eeprom_info.offset = eeprom->offset;
174bda68ab9SRemy Horton 	eeprom_info.length = eeprom->len;
175bda68ab9SRemy Horton 	eeprom_info.data = words;
176bda68ab9SRemy Horton 
177bda68ab9SRemy Horton 	status = rte_eth_dev_set_eeprom(port_id, &eeprom_info);
178bda68ab9SRemy Horton 	if (status)
179bda68ab9SRemy Horton 		return status;
180bda68ab9SRemy Horton 
181bda68ab9SRemy Horton 	eeprom->magic = eeprom_info.magic;
182bda68ab9SRemy Horton 
183bda68ab9SRemy Horton 	return 0;
184bda68ab9SRemy Horton }
185bda68ab9SRemy Horton 
186bda68ab9SRemy Horton int
187bda68ab9SRemy Horton rte_ethtool_get_pauseparam(uint8_t port_id,
188bda68ab9SRemy Horton 	struct ethtool_pauseparam *pause_param)
189bda68ab9SRemy Horton {
190bda68ab9SRemy Horton 	struct rte_eth_fc_conf fc_conf;
191bda68ab9SRemy Horton 	int status;
192bda68ab9SRemy Horton 
193bda68ab9SRemy Horton 	if (pause_param == NULL)
194bda68ab9SRemy Horton 		return -EINVAL;
195bda68ab9SRemy Horton 
196bda68ab9SRemy Horton 	status = rte_eth_dev_flow_ctrl_get(port_id, &fc_conf);
197bda68ab9SRemy Horton 	if (status)
198bda68ab9SRemy Horton 		return status;
199bda68ab9SRemy Horton 
200bda68ab9SRemy Horton 	pause_param->tx_pause = 0;
201bda68ab9SRemy Horton 	pause_param->rx_pause = 0;
202bda68ab9SRemy Horton 	switch (fc_conf.mode) {
203bda68ab9SRemy Horton 	case RTE_FC_RX_PAUSE:
204bda68ab9SRemy Horton 		pause_param->rx_pause = 1;
205bda68ab9SRemy Horton 		break;
206bda68ab9SRemy Horton 	case RTE_FC_TX_PAUSE:
207bda68ab9SRemy Horton 		pause_param->tx_pause = 1;
208bda68ab9SRemy Horton 		break;
209bda68ab9SRemy Horton 	case RTE_FC_FULL:
210bda68ab9SRemy Horton 		pause_param->rx_pause = 1;
211bda68ab9SRemy Horton 		pause_param->tx_pause = 1;
212bda68ab9SRemy Horton 	default:
213bda68ab9SRemy Horton 		/* dummy block to avoid compiler warning */
214bda68ab9SRemy Horton 		break;
215bda68ab9SRemy Horton 	}
216bda68ab9SRemy Horton 	pause_param->autoneg = (uint32_t)fc_conf.autoneg;
217bda68ab9SRemy Horton 
218bda68ab9SRemy Horton 	return 0;
219bda68ab9SRemy Horton }
220bda68ab9SRemy Horton 
221bda68ab9SRemy Horton int
222bda68ab9SRemy Horton rte_ethtool_set_pauseparam(uint8_t port_id,
223bda68ab9SRemy Horton 	struct ethtool_pauseparam *pause_param)
224bda68ab9SRemy Horton {
225bda68ab9SRemy Horton 	struct rte_eth_fc_conf fc_conf;
226bda68ab9SRemy Horton 	int status;
227bda68ab9SRemy Horton 
228bda68ab9SRemy Horton 	if (pause_param == NULL)
229bda68ab9SRemy Horton 		return -EINVAL;
230bda68ab9SRemy Horton 
231bda68ab9SRemy Horton 	/*
232bda68ab9SRemy Horton 	 * Read device flow control parameter first since
233bda68ab9SRemy Horton 	 * ethtool set_pauseparam op doesn't have all the information.
234bda68ab9SRemy Horton 	 * as defined in struct rte_eth_fc_conf.
235bda68ab9SRemy Horton 	 * This API requires the device to support both
236bda68ab9SRemy Horton 	 * rte_eth_dev_flow_ctrl_get and rte_eth_dev_flow_ctrl_set, otherwise
237bda68ab9SRemy Horton 	 * return -ENOTSUP
238bda68ab9SRemy Horton 	 */
239bda68ab9SRemy Horton 	status = rte_eth_dev_flow_ctrl_get(port_id, &fc_conf);
240bda68ab9SRemy Horton 	if (status)
241bda68ab9SRemy Horton 		return status;
242bda68ab9SRemy Horton 
243bda68ab9SRemy Horton 	fc_conf.autoneg = (uint8_t)pause_param->autoneg;
244bda68ab9SRemy Horton 
245bda68ab9SRemy Horton 	if (pause_param->tx_pause) {
246bda68ab9SRemy Horton 		if (pause_param->rx_pause)
247bda68ab9SRemy Horton 			fc_conf.mode = RTE_FC_FULL;
248bda68ab9SRemy Horton 		else
249bda68ab9SRemy Horton 			fc_conf.mode = RTE_FC_TX_PAUSE;
250bda68ab9SRemy Horton 	} else {
251bda68ab9SRemy Horton 		if (pause_param->rx_pause)
252bda68ab9SRemy Horton 			fc_conf.mode = RTE_FC_RX_PAUSE;
253bda68ab9SRemy Horton 		else
254bda68ab9SRemy Horton 			fc_conf.mode = RTE_FC_NONE;
255bda68ab9SRemy Horton 	}
256bda68ab9SRemy Horton 
257bda68ab9SRemy Horton 	status = rte_eth_dev_flow_ctrl_set(port_id, &fc_conf);
258bda68ab9SRemy Horton 	if (status)
259bda68ab9SRemy Horton 		return status;
260bda68ab9SRemy Horton 
261bda68ab9SRemy Horton 	return 0;
262bda68ab9SRemy Horton }
263bda68ab9SRemy Horton 
264bda68ab9SRemy Horton int
265bda68ab9SRemy Horton rte_ethtool_net_open(uint8_t port_id)
266bda68ab9SRemy Horton {
267bda68ab9SRemy Horton 	rte_eth_dev_stop(port_id);
268bda68ab9SRemy Horton 
269bda68ab9SRemy Horton 	return rte_eth_dev_start(port_id);
270bda68ab9SRemy Horton }
271bda68ab9SRemy Horton 
272bda68ab9SRemy Horton int
273bda68ab9SRemy Horton rte_ethtool_net_stop(uint8_t port_id)
274bda68ab9SRemy Horton {
2751414dabcSMauricio Vasquez B 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
276bda68ab9SRemy Horton 	rte_eth_dev_stop(port_id);
277bda68ab9SRemy Horton 
278bda68ab9SRemy Horton 	return 0;
279bda68ab9SRemy Horton }
280bda68ab9SRemy Horton 
281bda68ab9SRemy Horton int
282bda68ab9SRemy Horton rte_ethtool_net_get_mac_addr(uint8_t port_id, struct ether_addr *addr)
283bda68ab9SRemy Horton {
2841414dabcSMauricio Vasquez B 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
285bda68ab9SRemy Horton 	if (addr == NULL)
286bda68ab9SRemy Horton 		return -EINVAL;
287bda68ab9SRemy Horton 	rte_eth_macaddr_get(port_id, addr);
288bda68ab9SRemy Horton 
289bda68ab9SRemy Horton 	return 0;
290bda68ab9SRemy Horton }
291bda68ab9SRemy Horton 
292bda68ab9SRemy Horton int
293bda68ab9SRemy Horton rte_ethtool_net_set_mac_addr(uint8_t port_id, struct ether_addr *addr)
294bda68ab9SRemy Horton {
295bda68ab9SRemy Horton 	if (addr == NULL)
296bda68ab9SRemy Horton 		return -EINVAL;
297bda68ab9SRemy Horton 	return rte_eth_dev_default_mac_addr_set(port_id, addr);
298bda68ab9SRemy Horton }
299bda68ab9SRemy Horton 
300bda68ab9SRemy Horton int
301bda68ab9SRemy Horton rte_ethtool_net_validate_addr(uint8_t port_id __rte_unused,
302bda68ab9SRemy Horton 	struct ether_addr *addr)
303bda68ab9SRemy Horton {
304bda68ab9SRemy Horton 	if (addr == NULL)
305bda68ab9SRemy Horton 		return -EINVAL;
306bda68ab9SRemy Horton 	return is_valid_assigned_ether_addr(addr);
307bda68ab9SRemy Horton }
308bda68ab9SRemy Horton 
309bda68ab9SRemy Horton int
310bda68ab9SRemy Horton rte_ethtool_net_change_mtu(uint8_t port_id, int mtu)
311bda68ab9SRemy Horton {
312bda68ab9SRemy Horton 	if (mtu < 0 || mtu > UINT16_MAX)
313bda68ab9SRemy Horton 		return -EINVAL;
314bda68ab9SRemy Horton 	return rte_eth_dev_set_mtu(port_id, (uint16_t)mtu);
315bda68ab9SRemy Horton }
316bda68ab9SRemy Horton 
317bda68ab9SRemy Horton int
318bda68ab9SRemy Horton rte_ethtool_net_get_stats64(uint8_t port_id, struct rte_eth_stats *stats)
319bda68ab9SRemy Horton {
320bda68ab9SRemy Horton 	if (stats == NULL)
321bda68ab9SRemy Horton 		return -EINVAL;
322bda68ab9SRemy Horton 	return rte_eth_stats_get(port_id, stats);
323bda68ab9SRemy Horton }
324bda68ab9SRemy Horton 
325bda68ab9SRemy Horton int
326bda68ab9SRemy Horton rte_ethtool_net_vlan_rx_add_vid(uint8_t port_id, uint16_t vid)
327bda68ab9SRemy Horton {
328bda68ab9SRemy Horton 	return rte_eth_dev_vlan_filter(port_id, vid, 1);
329bda68ab9SRemy Horton }
330bda68ab9SRemy Horton 
331bda68ab9SRemy Horton int
332bda68ab9SRemy Horton rte_ethtool_net_vlan_rx_kill_vid(uint8_t port_id, uint16_t vid)
333bda68ab9SRemy Horton {
334bda68ab9SRemy Horton 	return rte_eth_dev_vlan_filter(port_id, vid, 0);
335bda68ab9SRemy Horton }
336bda68ab9SRemy Horton 
337bda68ab9SRemy Horton /*
338bda68ab9SRemy Horton  * The set_rx_mode provides driver-specific rx mode setting.
339bda68ab9SRemy Horton  * This implementation implements rx mode setting based upon
340bda68ab9SRemy Horton  * ixgbe/igb drivers. Further improvement is to provide a
341bda68ab9SRemy Horton  * callback op field over struct rte_eth_dev::dev_ops so each
342bda68ab9SRemy Horton  * driver can register device-specific implementation
343bda68ab9SRemy Horton  */
344bda68ab9SRemy Horton int
345bda68ab9SRemy Horton rte_ethtool_net_set_rx_mode(uint8_t port_id)
346bda68ab9SRemy Horton {
347bda68ab9SRemy Horton 	uint16_t num_vfs;
348bda68ab9SRemy Horton 	struct rte_eth_dev_info dev_info;
349bda68ab9SRemy Horton 	uint16_t vf;
350bda68ab9SRemy Horton 
351bda68ab9SRemy Horton 	memset(&dev_info, 0, sizeof(dev_info));
352bda68ab9SRemy Horton 	rte_eth_dev_info_get(port_id, &dev_info);
353bda68ab9SRemy Horton 	num_vfs = dev_info.max_vfs;
354bda68ab9SRemy Horton 
355bda68ab9SRemy Horton 	/* Set VF vf_rx_mode, VF unsupport status is discard */
356bda68ab9SRemy Horton 	for (vf = 0; vf < num_vfs; vf++)
357bda68ab9SRemy Horton 		rte_eth_dev_set_vf_rxmode(port_id, vf,
358bda68ab9SRemy Horton 			ETH_VMDQ_ACCEPT_UNTAG, 0);
359bda68ab9SRemy Horton 
360bda68ab9SRemy Horton 	/* Enable Rx vlan filter, VF unspport status is discard */
361bda68ab9SRemy Horton 	rte_eth_dev_set_vlan_offload(port_id, ETH_VLAN_FILTER_MASK);
362bda68ab9SRemy Horton 
363bda68ab9SRemy Horton 	return 0;
364bda68ab9SRemy Horton }
365bda68ab9SRemy Horton 
366bda68ab9SRemy Horton 
367bda68ab9SRemy Horton int
368bda68ab9SRemy Horton rte_ethtool_get_ringparam(uint8_t port_id,
369bda68ab9SRemy Horton 	struct ethtool_ringparam *ring_param)
370bda68ab9SRemy Horton {
371bda68ab9SRemy Horton 	struct rte_eth_dev_info dev_info;
372bda68ab9SRemy Horton 	struct rte_eth_rxq_info rx_qinfo;
373bda68ab9SRemy Horton 	struct rte_eth_txq_info tx_qinfo;
374bda68ab9SRemy Horton 	int stat;
375bda68ab9SRemy Horton 
376bda68ab9SRemy Horton 	if (ring_param == NULL)
377bda68ab9SRemy Horton 		return -EINVAL;
378bda68ab9SRemy Horton 
379bda68ab9SRemy Horton 	rte_eth_dev_info_get(port_id, &dev_info);
380bda68ab9SRemy Horton 
381bda68ab9SRemy Horton 	stat = rte_eth_rx_queue_info_get(port_id, 0, &rx_qinfo);
382bda68ab9SRemy Horton 	if (stat != 0)
383bda68ab9SRemy Horton 		return stat;
384bda68ab9SRemy Horton 
385bda68ab9SRemy Horton 	stat = rte_eth_tx_queue_info_get(port_id, 0, &tx_qinfo);
386bda68ab9SRemy Horton 	if (stat != 0)
387bda68ab9SRemy Horton 		return stat;
388bda68ab9SRemy Horton 
389bda68ab9SRemy Horton 	memset(ring_param, 0, sizeof(*ring_param));
390bda68ab9SRemy Horton 	ring_param->rx_pending = rx_qinfo.nb_desc;
391bda68ab9SRemy Horton 	ring_param->rx_max_pending = dev_info.rx_desc_lim.nb_max;
392bda68ab9SRemy Horton 	ring_param->tx_pending = tx_qinfo.nb_desc;
393bda68ab9SRemy Horton 	ring_param->tx_max_pending = dev_info.tx_desc_lim.nb_max;
394bda68ab9SRemy Horton 
395bda68ab9SRemy Horton 	return 0;
396bda68ab9SRemy Horton }
397bda68ab9SRemy Horton 
398bda68ab9SRemy Horton 
399bda68ab9SRemy Horton int
400bda68ab9SRemy Horton rte_ethtool_set_ringparam(uint8_t port_id,
401bda68ab9SRemy Horton 	struct ethtool_ringparam *ring_param)
402bda68ab9SRemy Horton {
403bda68ab9SRemy Horton 	struct rte_eth_rxq_info rx_qinfo;
404bda68ab9SRemy Horton 	int stat;
405bda68ab9SRemy Horton 
406bda68ab9SRemy Horton 	if (ring_param == NULL)
407bda68ab9SRemy Horton 		return -EINVAL;
408bda68ab9SRemy Horton 
409bda68ab9SRemy Horton 	stat = rte_eth_rx_queue_info_get(port_id, 0, &rx_qinfo);
410bda68ab9SRemy Horton 	if (stat != 0)
411bda68ab9SRemy Horton 		return stat;
412bda68ab9SRemy Horton 
413bda68ab9SRemy Horton 	rte_eth_dev_stop(port_id);
414bda68ab9SRemy Horton 
415bda68ab9SRemy Horton 	stat = rte_eth_tx_queue_setup(port_id, 0, ring_param->tx_pending,
416bda68ab9SRemy Horton 		rte_socket_id(), NULL);
417bda68ab9SRemy Horton 	if (stat != 0)
418bda68ab9SRemy Horton 		return stat;
419bda68ab9SRemy Horton 
420bda68ab9SRemy Horton 	stat = rte_eth_rx_queue_setup(port_id, 0, ring_param->rx_pending,
421bda68ab9SRemy Horton 		rte_socket_id(), NULL, rx_qinfo.mp);
422bda68ab9SRemy Horton 	if (stat != 0)
423bda68ab9SRemy Horton 		return stat;
424bda68ab9SRemy Horton 
425bda68ab9SRemy Horton 	return rte_eth_dev_start(port_id);
426bda68ab9SRemy Horton }
427