xref: /dpdk/examples/ethtool/lib/rte_ethtool.c (revision c752998b5e2eb5c827ffbecc5bd03ea28b14314f)
1bda68ab9SRemy Horton /*-
2bda68ab9SRemy Horton  *   BSD LICENSE
3bda68ab9SRemy Horton  *
4077d223eSBernard Iremonger  *   Copyright(c) 2010-2016 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>
3917fd714eSThomas Monjalon #include <rte_pci.h>
40*c752998bSGaetan Rivet #include <rte_bus_pci.h>
41077d223eSBernard Iremonger #ifdef RTE_LIBRTE_IXGBE_PMD
42077d223eSBernard Iremonger #include <rte_pmd_ixgbe.h>
43077d223eSBernard Iremonger #endif
44bda68ab9SRemy Horton #include "rte_ethtool.h"
45bda68ab9SRemy Horton 
46bda68ab9SRemy Horton #define PKTPOOL_SIZE 512
47bda68ab9SRemy Horton #define PKTPOOL_CACHE 32
48bda68ab9SRemy Horton 
49bda68ab9SRemy Horton 
50bda68ab9SRemy Horton int
5147523597SZhiyong Yang rte_ethtool_get_drvinfo(uint16_t port_id, struct ethtool_drvinfo *drvinfo)
52bda68ab9SRemy Horton {
53bda68ab9SRemy Horton 	struct rte_eth_dev_info dev_info;
54001a1c0fSZyta Szpak 	struct rte_dev_reg_info reg_info;
55bda68ab9SRemy Horton 	int n;
561e07b4ecSQiming Yang 	int ret;
57bda68ab9SRemy Horton 
58bda68ab9SRemy Horton 	if (drvinfo == NULL)
59bda68ab9SRemy Horton 		return -EINVAL;
60bda68ab9SRemy Horton 
611414dabcSMauricio Vasquez B 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
62bda68ab9SRemy Horton 
631e07b4ecSQiming Yang 	ret = rte_eth_dev_fw_version_get(port_id, drvinfo->fw_version,
641e07b4ecSQiming Yang 			      sizeof(drvinfo->fw_version));
651e07b4ecSQiming Yang 	if (ret < 0)
661e07b4ecSQiming Yang 		printf("firmware version get error: (%s)\n", strerror(-ret));
671e07b4ecSQiming Yang 	else if (ret > 0)
681e07b4ecSQiming Yang 		printf("Insufficient fw version buffer size, "
6998a7ea33SJerin Jacob 		       "the minimum size should be %d\n", ret);
701e07b4ecSQiming Yang 
71bda68ab9SRemy Horton 	memset(&dev_info, 0, sizeof(dev_info));
72bda68ab9SRemy Horton 	rte_eth_dev_info_get(port_id, &dev_info);
73bda68ab9SRemy Horton 
74bda68ab9SRemy Horton 	snprintf(drvinfo->driver, sizeof(drvinfo->driver), "%s",
75bda68ab9SRemy Horton 		dev_info.driver_name);
76bda68ab9SRemy Horton 	snprintf(drvinfo->version, sizeof(drvinfo->version), "%s",
77bda68ab9SRemy Horton 		rte_version());
7817fd714eSThomas Monjalon 	/* TODO: replace bus_info by rte_devargs.name */
796c66be9aSRemy Horton 	if (dev_info.pci_dev)
80bda68ab9SRemy Horton 		snprintf(drvinfo->bus_info, sizeof(drvinfo->bus_info),
81bda68ab9SRemy Horton 			"%04x:%02x:%02x.%x",
826c66be9aSRemy Horton 			dev_info.pci_dev->addr.domain,
836c66be9aSRemy Horton 			dev_info.pci_dev->addr.bus,
846c66be9aSRemy Horton 			dev_info.pci_dev->addr.devid,
856c66be9aSRemy Horton 			dev_info.pci_dev->addr.function);
866c66be9aSRemy Horton 	else
876c66be9aSRemy Horton 		snprintf(drvinfo->bus_info, sizeof(drvinfo->bus_info), "N/A");
88bda68ab9SRemy Horton 
89001a1c0fSZyta Szpak 	memset(&reg_info, 0, sizeof(reg_info));
90001a1c0fSZyta Szpak 	rte_eth_dev_get_reg_info(port_id, &reg_info);
91001a1c0fSZyta Szpak 	n = reg_info.length;
92bda68ab9SRemy Horton 	if (n > 0)
93bda68ab9SRemy Horton 		drvinfo->regdump_len = n;
94bda68ab9SRemy Horton 	else
95bda68ab9SRemy Horton 		drvinfo->regdump_len = 0;
96bda68ab9SRemy Horton 
97bda68ab9SRemy Horton 	n = rte_eth_dev_get_eeprom_length(port_id);
98bda68ab9SRemy Horton 	if (n > 0)
99bda68ab9SRemy Horton 		drvinfo->eedump_len = n;
100bda68ab9SRemy Horton 	else
101bda68ab9SRemy Horton 		drvinfo->eedump_len = 0;
102bda68ab9SRemy Horton 
103bda68ab9SRemy Horton 	drvinfo->n_stats = sizeof(struct rte_eth_stats) / sizeof(uint64_t);
104bda68ab9SRemy Horton 	drvinfo->testinfo_len = 0;
105bda68ab9SRemy Horton 
106bda68ab9SRemy Horton 	return 0;
107bda68ab9SRemy Horton }
108bda68ab9SRemy Horton 
109bda68ab9SRemy Horton int
11047523597SZhiyong Yang rte_ethtool_get_regs_len(uint16_t port_id)
111bda68ab9SRemy Horton {
112001a1c0fSZyta Szpak 	struct rte_dev_reg_info reg_info;
113001a1c0fSZyta Szpak 	int ret;
114bda68ab9SRemy Horton 
115001a1c0fSZyta Szpak 	memset(&reg_info, 0, sizeof(reg_info));
116001a1c0fSZyta Szpak 
117001a1c0fSZyta Szpak 	ret = rte_eth_dev_get_reg_info(port_id, &reg_info);
118001a1c0fSZyta Szpak 	if (ret)
119001a1c0fSZyta Szpak 		return ret;
120001a1c0fSZyta Szpak 
121001a1c0fSZyta Szpak 	return reg_info.length * reg_info.width;
122bda68ab9SRemy Horton }
123bda68ab9SRemy Horton 
124bda68ab9SRemy Horton int
12547523597SZhiyong Yang rte_ethtool_get_regs(uint16_t port_id, struct ethtool_regs *regs, void *data)
126bda68ab9SRemy Horton {
127bda68ab9SRemy Horton 	struct rte_dev_reg_info reg_info;
128bda68ab9SRemy Horton 	int status;
129bda68ab9SRemy Horton 
130bda68ab9SRemy Horton 	if (regs == NULL || data == NULL)
131bda68ab9SRemy Horton 		return -EINVAL;
132bda68ab9SRemy Horton 
133bda68ab9SRemy Horton 	reg_info.data = data;
134bda68ab9SRemy Horton 	reg_info.length = 0;
135bda68ab9SRemy Horton 
136bda68ab9SRemy Horton 	status = rte_eth_dev_get_reg_info(port_id, &reg_info);
137bda68ab9SRemy Horton 	if (status)
138bda68ab9SRemy Horton 		return status;
139bda68ab9SRemy Horton 	regs->version = reg_info.version;
140bda68ab9SRemy Horton 
141bda68ab9SRemy Horton 	return 0;
142bda68ab9SRemy Horton }
143bda68ab9SRemy Horton 
144bda68ab9SRemy Horton int
14547523597SZhiyong Yang rte_ethtool_get_link(uint16_t port_id)
146bda68ab9SRemy Horton {
147bda68ab9SRemy Horton 	struct rte_eth_link link;
148bda68ab9SRemy Horton 
1491414dabcSMauricio Vasquez B 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
150bda68ab9SRemy Horton 	rte_eth_link_get(port_id, &link);
151bda68ab9SRemy Horton 	return link.link_status;
152bda68ab9SRemy Horton }
153bda68ab9SRemy Horton 
154bda68ab9SRemy Horton int
15547523597SZhiyong Yang rte_ethtool_get_eeprom_len(uint16_t port_id)
156bda68ab9SRemy Horton {
157bda68ab9SRemy Horton 	return rte_eth_dev_get_eeprom_length(port_id);
158bda68ab9SRemy Horton }
159bda68ab9SRemy Horton 
160bda68ab9SRemy Horton int
16147523597SZhiyong Yang rte_ethtool_get_eeprom(uint16_t port_id, struct ethtool_eeprom *eeprom,
162bda68ab9SRemy Horton 	void *words)
163bda68ab9SRemy Horton {
164bda68ab9SRemy Horton 	struct rte_dev_eeprom_info eeprom_info;
165bda68ab9SRemy Horton 	int status;
166bda68ab9SRemy Horton 
167bda68ab9SRemy Horton 	if (eeprom == NULL || words == NULL)
168bda68ab9SRemy Horton 		return -EINVAL;
169bda68ab9SRemy Horton 
170bda68ab9SRemy Horton 	eeprom_info.offset = eeprom->offset;
171bda68ab9SRemy Horton 	eeprom_info.length = eeprom->len;
172bda68ab9SRemy Horton 	eeprom_info.data = words;
173bda68ab9SRemy Horton 
174bda68ab9SRemy Horton 	status = rte_eth_dev_get_eeprom(port_id, &eeprom_info);
175bda68ab9SRemy Horton 	if (status)
176bda68ab9SRemy Horton 		return status;
177bda68ab9SRemy Horton 
178bda68ab9SRemy Horton 	eeprom->magic = eeprom_info.magic;
179bda68ab9SRemy Horton 
180bda68ab9SRemy Horton 	return 0;
181bda68ab9SRemy Horton }
182bda68ab9SRemy Horton 
183bda68ab9SRemy Horton int
18447523597SZhiyong Yang rte_ethtool_set_eeprom(uint16_t port_id, struct ethtool_eeprom *eeprom,
185bda68ab9SRemy Horton 	void *words)
186bda68ab9SRemy Horton {
187bda68ab9SRemy Horton 	struct rte_dev_eeprom_info eeprom_info;
188bda68ab9SRemy Horton 	int status;
189bda68ab9SRemy Horton 
190bda68ab9SRemy Horton 	if (eeprom == NULL || words == NULL || eeprom->offset >= eeprom->len)
191bda68ab9SRemy Horton 		return -EINVAL;
192bda68ab9SRemy Horton 
193bda68ab9SRemy Horton 	eeprom_info.offset = eeprom->offset;
194bda68ab9SRemy Horton 	eeprom_info.length = eeprom->len;
195bda68ab9SRemy Horton 	eeprom_info.data = words;
196bda68ab9SRemy Horton 
197bda68ab9SRemy Horton 	status = rte_eth_dev_set_eeprom(port_id, &eeprom_info);
198bda68ab9SRemy Horton 	if (status)
199bda68ab9SRemy Horton 		return status;
200bda68ab9SRemy Horton 
201bda68ab9SRemy Horton 	eeprom->magic = eeprom_info.magic;
202bda68ab9SRemy Horton 
203bda68ab9SRemy Horton 	return 0;
204bda68ab9SRemy Horton }
205bda68ab9SRemy Horton 
206bda68ab9SRemy Horton int
20747523597SZhiyong Yang rte_ethtool_get_pauseparam(uint16_t port_id,
208bda68ab9SRemy Horton 	struct ethtool_pauseparam *pause_param)
209bda68ab9SRemy Horton {
210bda68ab9SRemy Horton 	struct rte_eth_fc_conf fc_conf;
211bda68ab9SRemy Horton 	int status;
212bda68ab9SRemy Horton 
213bda68ab9SRemy Horton 	if (pause_param == NULL)
214bda68ab9SRemy Horton 		return -EINVAL;
215bda68ab9SRemy Horton 
216bda68ab9SRemy Horton 	status = rte_eth_dev_flow_ctrl_get(port_id, &fc_conf);
217bda68ab9SRemy Horton 	if (status)
218bda68ab9SRemy Horton 		return status;
219bda68ab9SRemy Horton 
220bda68ab9SRemy Horton 	pause_param->tx_pause = 0;
221bda68ab9SRemy Horton 	pause_param->rx_pause = 0;
222bda68ab9SRemy Horton 	switch (fc_conf.mode) {
223bda68ab9SRemy Horton 	case RTE_FC_RX_PAUSE:
224bda68ab9SRemy Horton 		pause_param->rx_pause = 1;
225bda68ab9SRemy Horton 		break;
226bda68ab9SRemy Horton 	case RTE_FC_TX_PAUSE:
227bda68ab9SRemy Horton 		pause_param->tx_pause = 1;
228bda68ab9SRemy Horton 		break;
229bda68ab9SRemy Horton 	case RTE_FC_FULL:
230bda68ab9SRemy Horton 		pause_param->rx_pause = 1;
231bda68ab9SRemy Horton 		pause_param->tx_pause = 1;
232bda68ab9SRemy Horton 	default:
233bda68ab9SRemy Horton 		/* dummy block to avoid compiler warning */
234bda68ab9SRemy Horton 		break;
235bda68ab9SRemy Horton 	}
236bda68ab9SRemy Horton 	pause_param->autoneg = (uint32_t)fc_conf.autoneg;
237bda68ab9SRemy Horton 
238bda68ab9SRemy Horton 	return 0;
239bda68ab9SRemy Horton }
240bda68ab9SRemy Horton 
241bda68ab9SRemy Horton int
24247523597SZhiyong Yang rte_ethtool_set_pauseparam(uint16_t port_id,
243bda68ab9SRemy Horton 	struct ethtool_pauseparam *pause_param)
244bda68ab9SRemy Horton {
245bda68ab9SRemy Horton 	struct rte_eth_fc_conf fc_conf;
246bda68ab9SRemy Horton 	int status;
247bda68ab9SRemy Horton 
248bda68ab9SRemy Horton 	if (pause_param == NULL)
249bda68ab9SRemy Horton 		return -EINVAL;
250bda68ab9SRemy Horton 
251bda68ab9SRemy Horton 	/*
252bda68ab9SRemy Horton 	 * Read device flow control parameter first since
253bda68ab9SRemy Horton 	 * ethtool set_pauseparam op doesn't have all the information.
254bda68ab9SRemy Horton 	 * as defined in struct rte_eth_fc_conf.
255bda68ab9SRemy Horton 	 * This API requires the device to support both
256bda68ab9SRemy Horton 	 * rte_eth_dev_flow_ctrl_get and rte_eth_dev_flow_ctrl_set, otherwise
257bda68ab9SRemy Horton 	 * return -ENOTSUP
258bda68ab9SRemy Horton 	 */
259bda68ab9SRemy Horton 	status = rte_eth_dev_flow_ctrl_get(port_id, &fc_conf);
260bda68ab9SRemy Horton 	if (status)
261bda68ab9SRemy Horton 		return status;
262bda68ab9SRemy Horton 
263bda68ab9SRemy Horton 	fc_conf.autoneg = (uint8_t)pause_param->autoneg;
264bda68ab9SRemy Horton 
265bda68ab9SRemy Horton 	if (pause_param->tx_pause) {
266bda68ab9SRemy Horton 		if (pause_param->rx_pause)
267bda68ab9SRemy Horton 			fc_conf.mode = RTE_FC_FULL;
268bda68ab9SRemy Horton 		else
269bda68ab9SRemy Horton 			fc_conf.mode = RTE_FC_TX_PAUSE;
270bda68ab9SRemy Horton 	} else {
271bda68ab9SRemy Horton 		if (pause_param->rx_pause)
272bda68ab9SRemy Horton 			fc_conf.mode = RTE_FC_RX_PAUSE;
273bda68ab9SRemy Horton 		else
274bda68ab9SRemy Horton 			fc_conf.mode = RTE_FC_NONE;
275bda68ab9SRemy Horton 	}
276bda68ab9SRemy Horton 
277bda68ab9SRemy Horton 	status = rte_eth_dev_flow_ctrl_set(port_id, &fc_conf);
278bda68ab9SRemy Horton 	if (status)
279bda68ab9SRemy Horton 		return status;
280bda68ab9SRemy Horton 
281bda68ab9SRemy Horton 	return 0;
282bda68ab9SRemy Horton }
283bda68ab9SRemy Horton 
284bda68ab9SRemy Horton int
28547523597SZhiyong Yang rte_ethtool_net_open(uint16_t port_id)
286bda68ab9SRemy Horton {
287bda68ab9SRemy Horton 	rte_eth_dev_stop(port_id);
288bda68ab9SRemy Horton 
289bda68ab9SRemy Horton 	return rte_eth_dev_start(port_id);
290bda68ab9SRemy Horton }
291bda68ab9SRemy Horton 
292bda68ab9SRemy Horton int
29347523597SZhiyong Yang rte_ethtool_net_stop(uint16_t port_id)
294bda68ab9SRemy Horton {
2951414dabcSMauricio Vasquez B 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
296bda68ab9SRemy Horton 	rte_eth_dev_stop(port_id);
297bda68ab9SRemy Horton 
298bda68ab9SRemy Horton 	return 0;
299bda68ab9SRemy Horton }
300bda68ab9SRemy Horton 
301bda68ab9SRemy Horton int
30247523597SZhiyong Yang rte_ethtool_net_get_mac_addr(uint16_t port_id, struct ether_addr *addr)
303bda68ab9SRemy Horton {
3041414dabcSMauricio Vasquez B 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
305bda68ab9SRemy Horton 	if (addr == NULL)
306bda68ab9SRemy Horton 		return -EINVAL;
307bda68ab9SRemy Horton 	rte_eth_macaddr_get(port_id, addr);
308bda68ab9SRemy Horton 
309bda68ab9SRemy Horton 	return 0;
310bda68ab9SRemy Horton }
311bda68ab9SRemy Horton 
312bda68ab9SRemy Horton int
31347523597SZhiyong Yang rte_ethtool_net_set_mac_addr(uint16_t port_id, struct ether_addr *addr)
314bda68ab9SRemy Horton {
315bda68ab9SRemy Horton 	if (addr == NULL)
316bda68ab9SRemy Horton 		return -EINVAL;
317bda68ab9SRemy Horton 	return rte_eth_dev_default_mac_addr_set(port_id, addr);
318bda68ab9SRemy Horton }
319bda68ab9SRemy Horton 
320bda68ab9SRemy Horton int
32147523597SZhiyong Yang rte_ethtool_net_validate_addr(uint16_t port_id __rte_unused,
322bda68ab9SRemy Horton 	struct ether_addr *addr)
323bda68ab9SRemy Horton {
324bda68ab9SRemy Horton 	if (addr == NULL)
325bda68ab9SRemy Horton 		return -EINVAL;
326bda68ab9SRemy Horton 	return is_valid_assigned_ether_addr(addr);
327bda68ab9SRemy Horton }
328bda68ab9SRemy Horton 
329bda68ab9SRemy Horton int
33047523597SZhiyong Yang rte_ethtool_net_change_mtu(uint16_t port_id, int mtu)
331bda68ab9SRemy Horton {
332bda68ab9SRemy Horton 	if (mtu < 0 || mtu > UINT16_MAX)
333bda68ab9SRemy Horton 		return -EINVAL;
334bda68ab9SRemy Horton 	return rte_eth_dev_set_mtu(port_id, (uint16_t)mtu);
335bda68ab9SRemy Horton }
336bda68ab9SRemy Horton 
337bda68ab9SRemy Horton int
33847523597SZhiyong Yang rte_ethtool_net_get_stats64(uint16_t port_id, struct rte_eth_stats *stats)
339bda68ab9SRemy Horton {
340bda68ab9SRemy Horton 	if (stats == NULL)
341bda68ab9SRemy Horton 		return -EINVAL;
342bda68ab9SRemy Horton 	return rte_eth_stats_get(port_id, stats);
343bda68ab9SRemy Horton }
344bda68ab9SRemy Horton 
345bda68ab9SRemy Horton int
34647523597SZhiyong Yang rte_ethtool_net_vlan_rx_add_vid(uint16_t port_id, uint16_t vid)
347bda68ab9SRemy Horton {
348bda68ab9SRemy Horton 	return rte_eth_dev_vlan_filter(port_id, vid, 1);
349bda68ab9SRemy Horton }
350bda68ab9SRemy Horton 
351bda68ab9SRemy Horton int
35247523597SZhiyong Yang rte_ethtool_net_vlan_rx_kill_vid(uint16_t port_id, uint16_t vid)
353bda68ab9SRemy Horton {
354bda68ab9SRemy Horton 	return rte_eth_dev_vlan_filter(port_id, vid, 0);
355bda68ab9SRemy Horton }
356bda68ab9SRemy Horton 
357bda68ab9SRemy Horton /*
358bda68ab9SRemy Horton  * The set_rx_mode provides driver-specific rx mode setting.
359bda68ab9SRemy Horton  * This implementation implements rx mode setting based upon
360bda68ab9SRemy Horton  * ixgbe/igb drivers. Further improvement is to provide a
361bda68ab9SRemy Horton  * callback op field over struct rte_eth_dev::dev_ops so each
362bda68ab9SRemy Horton  * driver can register device-specific implementation
363bda68ab9SRemy Horton  */
364bda68ab9SRemy Horton int
36547523597SZhiyong Yang rte_ethtool_net_set_rx_mode(uint16_t port_id)
366bda68ab9SRemy Horton {
367bda68ab9SRemy Horton 	uint16_t num_vfs;
368bda68ab9SRemy Horton 	struct rte_eth_dev_info dev_info;
369bda68ab9SRemy Horton 	uint16_t vf;
370bda68ab9SRemy Horton 
371bda68ab9SRemy Horton 	memset(&dev_info, 0, sizeof(dev_info));
372bda68ab9SRemy Horton 	rte_eth_dev_info_get(port_id, &dev_info);
373bda68ab9SRemy Horton 	num_vfs = dev_info.max_vfs;
374bda68ab9SRemy Horton 
375bda68ab9SRemy Horton 	/* Set VF vf_rx_mode, VF unsupport status is discard */
376077d223eSBernard Iremonger 	for (vf = 0; vf < num_vfs; vf++) {
377077d223eSBernard Iremonger #ifdef RTE_LIBRTE_IXGBE_PMD
378077d223eSBernard Iremonger 		rte_pmd_ixgbe_set_vf_rxmode(port_id, vf,
379bda68ab9SRemy Horton 			ETH_VMDQ_ACCEPT_UNTAG, 0);
380077d223eSBernard Iremonger #endif
381077d223eSBernard Iremonger 	}
382bda68ab9SRemy Horton 
383bda68ab9SRemy Horton 	/* Enable Rx vlan filter, VF unspport status is discard */
384bda68ab9SRemy Horton 	rte_eth_dev_set_vlan_offload(port_id, ETH_VLAN_FILTER_MASK);
385bda68ab9SRemy Horton 
386bda68ab9SRemy Horton 	return 0;
387bda68ab9SRemy Horton }
388bda68ab9SRemy Horton 
389bda68ab9SRemy Horton 
390bda68ab9SRemy Horton int
39147523597SZhiyong Yang rte_ethtool_get_ringparam(uint16_t port_id,
392bda68ab9SRemy Horton 	struct ethtool_ringparam *ring_param)
393bda68ab9SRemy Horton {
394bda68ab9SRemy Horton 	struct rte_eth_dev_info dev_info;
395bda68ab9SRemy Horton 	struct rte_eth_rxq_info rx_qinfo;
396bda68ab9SRemy Horton 	struct rte_eth_txq_info tx_qinfo;
397bda68ab9SRemy Horton 	int stat;
398bda68ab9SRemy Horton 
399bda68ab9SRemy Horton 	if (ring_param == NULL)
400bda68ab9SRemy Horton 		return -EINVAL;
401bda68ab9SRemy Horton 
402bda68ab9SRemy Horton 	rte_eth_dev_info_get(port_id, &dev_info);
403bda68ab9SRemy Horton 
404bda68ab9SRemy Horton 	stat = rte_eth_rx_queue_info_get(port_id, 0, &rx_qinfo);
405bda68ab9SRemy Horton 	if (stat != 0)
406bda68ab9SRemy Horton 		return stat;
407bda68ab9SRemy Horton 
408bda68ab9SRemy Horton 	stat = rte_eth_tx_queue_info_get(port_id, 0, &tx_qinfo);
409bda68ab9SRemy Horton 	if (stat != 0)
410bda68ab9SRemy Horton 		return stat;
411bda68ab9SRemy Horton 
412bda68ab9SRemy Horton 	memset(ring_param, 0, sizeof(*ring_param));
413bda68ab9SRemy Horton 	ring_param->rx_pending = rx_qinfo.nb_desc;
414bda68ab9SRemy Horton 	ring_param->rx_max_pending = dev_info.rx_desc_lim.nb_max;
415bda68ab9SRemy Horton 	ring_param->tx_pending = tx_qinfo.nb_desc;
416bda68ab9SRemy Horton 	ring_param->tx_max_pending = dev_info.tx_desc_lim.nb_max;
417bda68ab9SRemy Horton 
418bda68ab9SRemy Horton 	return 0;
419bda68ab9SRemy Horton }
420bda68ab9SRemy Horton 
421bda68ab9SRemy Horton 
422bda68ab9SRemy Horton int
42347523597SZhiyong Yang rte_ethtool_set_ringparam(uint16_t port_id,
424bda68ab9SRemy Horton 	struct ethtool_ringparam *ring_param)
425bda68ab9SRemy Horton {
426bda68ab9SRemy Horton 	struct rte_eth_rxq_info rx_qinfo;
427bda68ab9SRemy Horton 	int stat;
428bda68ab9SRemy Horton 
429bda68ab9SRemy Horton 	if (ring_param == NULL)
430bda68ab9SRemy Horton 		return -EINVAL;
431bda68ab9SRemy Horton 
432bda68ab9SRemy Horton 	stat = rte_eth_rx_queue_info_get(port_id, 0, &rx_qinfo);
433bda68ab9SRemy Horton 	if (stat != 0)
434bda68ab9SRemy Horton 		return stat;
435bda68ab9SRemy Horton 
436bda68ab9SRemy Horton 	rte_eth_dev_stop(port_id);
437bda68ab9SRemy Horton 
438bda68ab9SRemy Horton 	stat = rte_eth_tx_queue_setup(port_id, 0, ring_param->tx_pending,
439bda68ab9SRemy Horton 		rte_socket_id(), NULL);
440bda68ab9SRemy Horton 	if (stat != 0)
441bda68ab9SRemy Horton 		return stat;
442bda68ab9SRemy Horton 
443bda68ab9SRemy Horton 	stat = rte_eth_rx_queue_setup(port_id, 0, ring_param->rx_pending,
444bda68ab9SRemy Horton 		rte_socket_id(), NULL, rx_qinfo.mp);
445bda68ab9SRemy Horton 	if (stat != 0)
446bda68ab9SRemy Horton 		return stat;
447bda68ab9SRemy Horton 
448bda68ab9SRemy Horton 	return rte_eth_dev_start(port_id);
449bda68ab9SRemy Horton }
450