xref: /dpdk/examples/ethtool/lib/rte_ethtool.c (revision 6723c0fc7207ca4416822b170b1485a78aa47c7c)
13998e2a0SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
23998e2a0SBruce Richardson  * Copyright(c) 2010-2016 Intel Corporation
3bda68ab9SRemy Horton  */
4bda68ab9SRemy Horton #include <stdio.h>
5bda68ab9SRemy Horton #include <string.h>
6bda68ab9SRemy Horton #include <stdint.h>
7*6723c0fcSBruce Richardson #include <rte_string_fns.h>
8bda68ab9SRemy Horton #include <rte_version.h>
9bda68ab9SRemy Horton #include <rte_ethdev.h>
10bda68ab9SRemy Horton #include <rte_ether.h>
11c752998bSGaetan Rivet #include <rte_bus_pci.h>
12077d223eSBernard Iremonger #ifdef RTE_LIBRTE_IXGBE_PMD
13077d223eSBernard Iremonger #include <rte_pmd_ixgbe.h>
14077d223eSBernard Iremonger #endif
15bda68ab9SRemy Horton #include "rte_ethtool.h"
16bda68ab9SRemy Horton 
17bda68ab9SRemy Horton #define PKTPOOL_SIZE 512
18bda68ab9SRemy Horton #define PKTPOOL_CACHE 32
19bda68ab9SRemy Horton 
20bda68ab9SRemy Horton 
21bda68ab9SRemy Horton int
2247523597SZhiyong Yang rte_ethtool_get_drvinfo(uint16_t port_id, struct ethtool_drvinfo *drvinfo)
23bda68ab9SRemy Horton {
24bda68ab9SRemy Horton 	struct rte_eth_dev_info dev_info;
25001a1c0fSZyta Szpak 	struct rte_dev_reg_info reg_info;
26cd8c7c7cSFerruh Yigit 	const struct rte_pci_device *pci_dev;
27cd8c7c7cSFerruh Yigit 	const struct rte_bus *bus = NULL;
28bda68ab9SRemy Horton 	int n;
291e07b4ecSQiming Yang 	int ret;
30bda68ab9SRemy Horton 
31bda68ab9SRemy Horton 	if (drvinfo == NULL)
32bda68ab9SRemy Horton 		return -EINVAL;
33bda68ab9SRemy Horton 
341414dabcSMauricio Vasquez B 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
35bda68ab9SRemy Horton 
361e07b4ecSQiming Yang 	ret = rte_eth_dev_fw_version_get(port_id, drvinfo->fw_version,
371e07b4ecSQiming Yang 			      sizeof(drvinfo->fw_version));
381e07b4ecSQiming Yang 	if (ret < 0)
391e07b4ecSQiming Yang 		printf("firmware version get error: (%s)\n", strerror(-ret));
401e07b4ecSQiming Yang 	else if (ret > 0)
411e07b4ecSQiming Yang 		printf("Insufficient fw version buffer size, "
4298a7ea33SJerin Jacob 		       "the minimum size should be %d\n", ret);
431e07b4ecSQiming Yang 
44bda68ab9SRemy Horton 	memset(&dev_info, 0, sizeof(dev_info));
45bda68ab9SRemy Horton 	rte_eth_dev_info_get(port_id, &dev_info);
46bda68ab9SRemy Horton 
47*6723c0fcSBruce Richardson 	strlcpy(drvinfo->driver, dev_info.driver_name,
48*6723c0fcSBruce Richardson 		sizeof(drvinfo->driver));
49*6723c0fcSBruce Richardson 	strlcpy(drvinfo->version, rte_version(), sizeof(drvinfo->version));
5017fd714eSThomas Monjalon 	/* TODO: replace bus_info by rte_devargs.name */
51cd8c7c7cSFerruh Yigit 	if (dev_info.device)
52cd8c7c7cSFerruh Yigit 		bus = rte_bus_find_by_device(dev_info.device);
53cd8c7c7cSFerruh Yigit 	if (bus && !strcmp(bus->name, "pci")) {
54cd8c7c7cSFerruh Yigit 		pci_dev = RTE_DEV_TO_PCI(dev_info.device);
55bda68ab9SRemy Horton 		snprintf(drvinfo->bus_info, sizeof(drvinfo->bus_info),
56bda68ab9SRemy Horton 			"%04x:%02x:%02x.%x",
57cd8c7c7cSFerruh Yigit 			pci_dev->addr.domain, pci_dev->addr.bus,
58cd8c7c7cSFerruh Yigit 			pci_dev->addr.devid, pci_dev->addr.function);
59cd8c7c7cSFerruh Yigit 	} else {
606c66be9aSRemy Horton 		snprintf(drvinfo->bus_info, sizeof(drvinfo->bus_info), "N/A");
61cd8c7c7cSFerruh Yigit 	}
62bda68ab9SRemy Horton 
63001a1c0fSZyta Szpak 	memset(&reg_info, 0, sizeof(reg_info));
64001a1c0fSZyta Szpak 	rte_eth_dev_get_reg_info(port_id, &reg_info);
65001a1c0fSZyta Szpak 	n = reg_info.length;
66bda68ab9SRemy Horton 	if (n > 0)
67bda68ab9SRemy Horton 		drvinfo->regdump_len = n;
68bda68ab9SRemy Horton 	else
69bda68ab9SRemy Horton 		drvinfo->regdump_len = 0;
70bda68ab9SRemy Horton 
71bda68ab9SRemy Horton 	n = rte_eth_dev_get_eeprom_length(port_id);
72bda68ab9SRemy Horton 	if (n > 0)
73bda68ab9SRemy Horton 		drvinfo->eedump_len = n;
74bda68ab9SRemy Horton 	else
75bda68ab9SRemy Horton 		drvinfo->eedump_len = 0;
76bda68ab9SRemy Horton 
77bda68ab9SRemy Horton 	drvinfo->n_stats = sizeof(struct rte_eth_stats) / sizeof(uint64_t);
78bda68ab9SRemy Horton 	drvinfo->testinfo_len = 0;
79bda68ab9SRemy Horton 
80bda68ab9SRemy Horton 	return 0;
81bda68ab9SRemy Horton }
82bda68ab9SRemy Horton 
83bda68ab9SRemy Horton int
8447523597SZhiyong Yang rte_ethtool_get_regs_len(uint16_t port_id)
85bda68ab9SRemy Horton {
86001a1c0fSZyta Szpak 	struct rte_dev_reg_info reg_info;
87001a1c0fSZyta Szpak 	int ret;
88bda68ab9SRemy Horton 
89001a1c0fSZyta Szpak 	memset(&reg_info, 0, sizeof(reg_info));
90001a1c0fSZyta Szpak 
91001a1c0fSZyta Szpak 	ret = rte_eth_dev_get_reg_info(port_id, &reg_info);
92001a1c0fSZyta Szpak 	if (ret)
93001a1c0fSZyta Szpak 		return ret;
94001a1c0fSZyta Szpak 
95001a1c0fSZyta Szpak 	return reg_info.length * reg_info.width;
96bda68ab9SRemy Horton }
97bda68ab9SRemy Horton 
98bda68ab9SRemy Horton int
9947523597SZhiyong Yang rte_ethtool_get_regs(uint16_t port_id, struct ethtool_regs *regs, void *data)
100bda68ab9SRemy Horton {
101bda68ab9SRemy Horton 	struct rte_dev_reg_info reg_info;
102bda68ab9SRemy Horton 	int status;
103bda68ab9SRemy Horton 
104bda68ab9SRemy Horton 	if (regs == NULL || data == NULL)
105bda68ab9SRemy Horton 		return -EINVAL;
106bda68ab9SRemy Horton 
107bda68ab9SRemy Horton 	reg_info.data = data;
108bda68ab9SRemy Horton 	reg_info.length = 0;
109bda68ab9SRemy Horton 
110bda68ab9SRemy Horton 	status = rte_eth_dev_get_reg_info(port_id, &reg_info);
111bda68ab9SRemy Horton 	if (status)
112bda68ab9SRemy Horton 		return status;
113bda68ab9SRemy Horton 	regs->version = reg_info.version;
114bda68ab9SRemy Horton 
115bda68ab9SRemy Horton 	return 0;
116bda68ab9SRemy Horton }
117bda68ab9SRemy Horton 
118bda68ab9SRemy Horton int
11947523597SZhiyong Yang rte_ethtool_get_link(uint16_t port_id)
120bda68ab9SRemy Horton {
121bda68ab9SRemy Horton 	struct rte_eth_link link;
122bda68ab9SRemy Horton 
1231414dabcSMauricio Vasquez B 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
124bda68ab9SRemy Horton 	rte_eth_link_get(port_id, &link);
125bda68ab9SRemy Horton 	return link.link_status;
126bda68ab9SRemy Horton }
127bda68ab9SRemy Horton 
128bda68ab9SRemy Horton int
12947523597SZhiyong Yang rte_ethtool_get_eeprom_len(uint16_t port_id)
130bda68ab9SRemy Horton {
131bda68ab9SRemy Horton 	return rte_eth_dev_get_eeprom_length(port_id);
132bda68ab9SRemy Horton }
133bda68ab9SRemy Horton 
134bda68ab9SRemy Horton int
13547523597SZhiyong Yang rte_ethtool_get_eeprom(uint16_t port_id, struct ethtool_eeprom *eeprom,
136bda68ab9SRemy Horton 	void *words)
137bda68ab9SRemy Horton {
138bda68ab9SRemy Horton 	struct rte_dev_eeprom_info eeprom_info;
139bda68ab9SRemy Horton 	int status;
140bda68ab9SRemy Horton 
141bda68ab9SRemy Horton 	if (eeprom == NULL || words == NULL)
142bda68ab9SRemy Horton 		return -EINVAL;
143bda68ab9SRemy Horton 
144bda68ab9SRemy Horton 	eeprom_info.offset = eeprom->offset;
145bda68ab9SRemy Horton 	eeprom_info.length = eeprom->len;
146bda68ab9SRemy Horton 	eeprom_info.data = words;
147bda68ab9SRemy Horton 
148bda68ab9SRemy Horton 	status = rte_eth_dev_get_eeprom(port_id, &eeprom_info);
149bda68ab9SRemy Horton 	if (status)
150bda68ab9SRemy Horton 		return status;
151bda68ab9SRemy Horton 
152bda68ab9SRemy Horton 	eeprom->magic = eeprom_info.magic;
153bda68ab9SRemy Horton 
154bda68ab9SRemy Horton 	return 0;
155bda68ab9SRemy Horton }
156bda68ab9SRemy Horton 
157bda68ab9SRemy Horton int
15847523597SZhiyong Yang rte_ethtool_set_eeprom(uint16_t port_id, struct ethtool_eeprom *eeprom,
159bda68ab9SRemy Horton 	void *words)
160bda68ab9SRemy Horton {
161bda68ab9SRemy Horton 	struct rte_dev_eeprom_info eeprom_info;
162bda68ab9SRemy Horton 	int status;
163bda68ab9SRemy Horton 
164bda68ab9SRemy Horton 	if (eeprom == NULL || words == NULL || eeprom->offset >= eeprom->len)
165bda68ab9SRemy Horton 		return -EINVAL;
166bda68ab9SRemy Horton 
167bda68ab9SRemy Horton 	eeprom_info.offset = eeprom->offset;
168bda68ab9SRemy Horton 	eeprom_info.length = eeprom->len;
169bda68ab9SRemy Horton 	eeprom_info.data = words;
170bda68ab9SRemy Horton 
171bda68ab9SRemy Horton 	status = rte_eth_dev_set_eeprom(port_id, &eeprom_info);
172bda68ab9SRemy Horton 	if (status)
173bda68ab9SRemy Horton 		return status;
174bda68ab9SRemy Horton 
175bda68ab9SRemy Horton 	eeprom->magic = eeprom_info.magic;
176bda68ab9SRemy Horton 
177bda68ab9SRemy Horton 	return 0;
178bda68ab9SRemy Horton }
179bda68ab9SRemy Horton 
180bda68ab9SRemy Horton int
18199d8ebcfSZijie Pan rte_ethtool_get_module_info(uint16_t port_id, uint32_t *modinfo)
18299d8ebcfSZijie Pan {
18399d8ebcfSZijie Pan 	struct rte_eth_dev_module_info *info;
18499d8ebcfSZijie Pan 
18599d8ebcfSZijie Pan 	info = (struct rte_eth_dev_module_info *)modinfo;
18699d8ebcfSZijie Pan 	return rte_eth_dev_get_module_info(port_id, info);
18799d8ebcfSZijie Pan }
18899d8ebcfSZijie Pan 
18999d8ebcfSZijie Pan int
19099d8ebcfSZijie Pan rte_ethtool_get_module_eeprom(uint16_t port_id, struct ethtool_eeprom *eeprom,
19199d8ebcfSZijie Pan 	void *words)
19299d8ebcfSZijie Pan {
19399d8ebcfSZijie Pan 	struct rte_dev_eeprom_info eeprom_info;
19499d8ebcfSZijie Pan 	int status;
19599d8ebcfSZijie Pan 
19699d8ebcfSZijie Pan 	if (eeprom == NULL || words == NULL)
19799d8ebcfSZijie Pan 		return -EINVAL;
19899d8ebcfSZijie Pan 
19999d8ebcfSZijie Pan 	eeprom_info.offset = eeprom->offset;
20099d8ebcfSZijie Pan 	eeprom_info.length = eeprom->len;
20199d8ebcfSZijie Pan 	eeprom_info.data = words;
20299d8ebcfSZijie Pan 
20399d8ebcfSZijie Pan 	status = rte_eth_dev_get_module_eeprom(port_id, &eeprom_info);
20499d8ebcfSZijie Pan 	if (status)
20599d8ebcfSZijie Pan 		return status;
20699d8ebcfSZijie Pan 
20799d8ebcfSZijie Pan 	return 0;
20899d8ebcfSZijie Pan }
20999d8ebcfSZijie Pan 
21099d8ebcfSZijie Pan int
21147523597SZhiyong Yang rte_ethtool_get_pauseparam(uint16_t port_id,
212bda68ab9SRemy Horton 	struct ethtool_pauseparam *pause_param)
213bda68ab9SRemy Horton {
214bda68ab9SRemy Horton 	struct rte_eth_fc_conf fc_conf;
215bda68ab9SRemy Horton 	int status;
216bda68ab9SRemy Horton 
217bda68ab9SRemy Horton 	if (pause_param == NULL)
218bda68ab9SRemy Horton 		return -EINVAL;
219bda68ab9SRemy Horton 
220bda68ab9SRemy Horton 	status = rte_eth_dev_flow_ctrl_get(port_id, &fc_conf);
221bda68ab9SRemy Horton 	if (status)
222bda68ab9SRemy Horton 		return status;
223bda68ab9SRemy Horton 
224bda68ab9SRemy Horton 	pause_param->tx_pause = 0;
225bda68ab9SRemy Horton 	pause_param->rx_pause = 0;
226bda68ab9SRemy Horton 	switch (fc_conf.mode) {
227bda68ab9SRemy Horton 	case RTE_FC_RX_PAUSE:
228bda68ab9SRemy Horton 		pause_param->rx_pause = 1;
229bda68ab9SRemy Horton 		break;
230bda68ab9SRemy Horton 	case RTE_FC_TX_PAUSE:
231bda68ab9SRemy Horton 		pause_param->tx_pause = 1;
232bda68ab9SRemy Horton 		break;
233bda68ab9SRemy Horton 	case RTE_FC_FULL:
234bda68ab9SRemy Horton 		pause_param->rx_pause = 1;
235bda68ab9SRemy Horton 		pause_param->tx_pause = 1;
236bda68ab9SRemy Horton 	default:
237bda68ab9SRemy Horton 		/* dummy block to avoid compiler warning */
238bda68ab9SRemy Horton 		break;
239bda68ab9SRemy Horton 	}
240bda68ab9SRemy Horton 	pause_param->autoneg = (uint32_t)fc_conf.autoneg;
241bda68ab9SRemy Horton 
242bda68ab9SRemy Horton 	return 0;
243bda68ab9SRemy Horton }
244bda68ab9SRemy Horton 
245bda68ab9SRemy Horton int
24647523597SZhiyong Yang rte_ethtool_set_pauseparam(uint16_t port_id,
247bda68ab9SRemy Horton 	struct ethtool_pauseparam *pause_param)
248bda68ab9SRemy Horton {
249bda68ab9SRemy Horton 	struct rte_eth_fc_conf fc_conf;
250bda68ab9SRemy Horton 	int status;
251bda68ab9SRemy Horton 
252bda68ab9SRemy Horton 	if (pause_param == NULL)
253bda68ab9SRemy Horton 		return -EINVAL;
254bda68ab9SRemy Horton 
255bda68ab9SRemy Horton 	/*
256bda68ab9SRemy Horton 	 * Read device flow control parameter first since
257bda68ab9SRemy Horton 	 * ethtool set_pauseparam op doesn't have all the information.
258bda68ab9SRemy Horton 	 * as defined in struct rte_eth_fc_conf.
259bda68ab9SRemy Horton 	 * This API requires the device to support both
260bda68ab9SRemy Horton 	 * rte_eth_dev_flow_ctrl_get and rte_eth_dev_flow_ctrl_set, otherwise
261bda68ab9SRemy Horton 	 * return -ENOTSUP
262bda68ab9SRemy Horton 	 */
263bda68ab9SRemy Horton 	status = rte_eth_dev_flow_ctrl_get(port_id, &fc_conf);
264bda68ab9SRemy Horton 	if (status)
265bda68ab9SRemy Horton 		return status;
266bda68ab9SRemy Horton 
267bda68ab9SRemy Horton 	fc_conf.autoneg = (uint8_t)pause_param->autoneg;
268bda68ab9SRemy Horton 
269bda68ab9SRemy Horton 	if (pause_param->tx_pause) {
270bda68ab9SRemy Horton 		if (pause_param->rx_pause)
271bda68ab9SRemy Horton 			fc_conf.mode = RTE_FC_FULL;
272bda68ab9SRemy Horton 		else
273bda68ab9SRemy Horton 			fc_conf.mode = RTE_FC_TX_PAUSE;
274bda68ab9SRemy Horton 	} else {
275bda68ab9SRemy Horton 		if (pause_param->rx_pause)
276bda68ab9SRemy Horton 			fc_conf.mode = RTE_FC_RX_PAUSE;
277bda68ab9SRemy Horton 		else
278bda68ab9SRemy Horton 			fc_conf.mode = RTE_FC_NONE;
279bda68ab9SRemy Horton 	}
280bda68ab9SRemy Horton 
281bda68ab9SRemy Horton 	status = rte_eth_dev_flow_ctrl_set(port_id, &fc_conf);
282bda68ab9SRemy Horton 	if (status)
283bda68ab9SRemy Horton 		return status;
284bda68ab9SRemy Horton 
285bda68ab9SRemy Horton 	return 0;
286bda68ab9SRemy Horton }
287bda68ab9SRemy Horton 
288bda68ab9SRemy Horton int
28947523597SZhiyong Yang rte_ethtool_net_open(uint16_t port_id)
290bda68ab9SRemy Horton {
291bda68ab9SRemy Horton 	rte_eth_dev_stop(port_id);
292bda68ab9SRemy Horton 
293bda68ab9SRemy Horton 	return rte_eth_dev_start(port_id);
294bda68ab9SRemy Horton }
295bda68ab9SRemy Horton 
296bda68ab9SRemy Horton int
29747523597SZhiyong Yang rte_ethtool_net_stop(uint16_t port_id)
298bda68ab9SRemy Horton {
2991414dabcSMauricio Vasquez B 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
300bda68ab9SRemy Horton 	rte_eth_dev_stop(port_id);
301bda68ab9SRemy Horton 
302bda68ab9SRemy Horton 	return 0;
303bda68ab9SRemy Horton }
304bda68ab9SRemy Horton 
305bda68ab9SRemy Horton int
30647523597SZhiyong Yang rte_ethtool_net_get_mac_addr(uint16_t port_id, struct ether_addr *addr)
307bda68ab9SRemy Horton {
3081414dabcSMauricio Vasquez B 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
309bda68ab9SRemy Horton 	if (addr == NULL)
310bda68ab9SRemy Horton 		return -EINVAL;
311bda68ab9SRemy Horton 	rte_eth_macaddr_get(port_id, addr);
312bda68ab9SRemy Horton 
313bda68ab9SRemy Horton 	return 0;
314bda68ab9SRemy Horton }
315bda68ab9SRemy Horton 
316bda68ab9SRemy Horton int
31747523597SZhiyong Yang rte_ethtool_net_set_mac_addr(uint16_t port_id, struct ether_addr *addr)
318bda68ab9SRemy Horton {
319bda68ab9SRemy Horton 	if (addr == NULL)
320bda68ab9SRemy Horton 		return -EINVAL;
321bda68ab9SRemy Horton 	return rte_eth_dev_default_mac_addr_set(port_id, addr);
322bda68ab9SRemy Horton }
323bda68ab9SRemy Horton 
324bda68ab9SRemy Horton int
32547523597SZhiyong Yang rte_ethtool_net_validate_addr(uint16_t port_id __rte_unused,
326bda68ab9SRemy Horton 	struct ether_addr *addr)
327bda68ab9SRemy Horton {
328bda68ab9SRemy Horton 	if (addr == NULL)
329bda68ab9SRemy Horton 		return -EINVAL;
330bda68ab9SRemy Horton 	return is_valid_assigned_ether_addr(addr);
331bda68ab9SRemy Horton }
332bda68ab9SRemy Horton 
333bda68ab9SRemy Horton int
33447523597SZhiyong Yang rte_ethtool_net_change_mtu(uint16_t port_id, int mtu)
335bda68ab9SRemy Horton {
336bda68ab9SRemy Horton 	if (mtu < 0 || mtu > UINT16_MAX)
337bda68ab9SRemy Horton 		return -EINVAL;
338bda68ab9SRemy Horton 	return rte_eth_dev_set_mtu(port_id, (uint16_t)mtu);
339bda68ab9SRemy Horton }
340bda68ab9SRemy Horton 
341bda68ab9SRemy Horton int
34247523597SZhiyong Yang rte_ethtool_net_get_stats64(uint16_t port_id, struct rte_eth_stats *stats)
343bda68ab9SRemy Horton {
344bda68ab9SRemy Horton 	if (stats == NULL)
345bda68ab9SRemy Horton 		return -EINVAL;
346bda68ab9SRemy Horton 	return rte_eth_stats_get(port_id, stats);
347bda68ab9SRemy Horton }
348bda68ab9SRemy Horton 
349bda68ab9SRemy Horton int
35047523597SZhiyong Yang rte_ethtool_net_vlan_rx_add_vid(uint16_t port_id, uint16_t vid)
351bda68ab9SRemy Horton {
352bda68ab9SRemy Horton 	return rte_eth_dev_vlan_filter(port_id, vid, 1);
353bda68ab9SRemy Horton }
354bda68ab9SRemy Horton 
355bda68ab9SRemy Horton int
35647523597SZhiyong Yang rte_ethtool_net_vlan_rx_kill_vid(uint16_t port_id, uint16_t vid)
357bda68ab9SRemy Horton {
358bda68ab9SRemy Horton 	return rte_eth_dev_vlan_filter(port_id, vid, 0);
359bda68ab9SRemy Horton }
360bda68ab9SRemy Horton 
361bda68ab9SRemy Horton /*
362bda68ab9SRemy Horton  * The set_rx_mode provides driver-specific rx mode setting.
363bda68ab9SRemy Horton  * This implementation implements rx mode setting based upon
364bda68ab9SRemy Horton  * ixgbe/igb drivers. Further improvement is to provide a
365bda68ab9SRemy Horton  * callback op field over struct rte_eth_dev::dev_ops so each
366bda68ab9SRemy Horton  * driver can register device-specific implementation
367bda68ab9SRemy Horton  */
368bda68ab9SRemy Horton int
36947523597SZhiyong Yang rte_ethtool_net_set_rx_mode(uint16_t port_id)
370bda68ab9SRemy Horton {
371bda68ab9SRemy Horton 	uint16_t num_vfs;
372bda68ab9SRemy Horton 	struct rte_eth_dev_info dev_info;
373bda68ab9SRemy Horton 	uint16_t vf;
374bda68ab9SRemy Horton 
375bda68ab9SRemy Horton 	memset(&dev_info, 0, sizeof(dev_info));
376bda68ab9SRemy Horton 	rte_eth_dev_info_get(port_id, &dev_info);
377bda68ab9SRemy Horton 	num_vfs = dev_info.max_vfs;
378bda68ab9SRemy Horton 
379bda68ab9SRemy Horton 	/* Set VF vf_rx_mode, VF unsupport status is discard */
380077d223eSBernard Iremonger 	for (vf = 0; vf < num_vfs; vf++) {
381077d223eSBernard Iremonger #ifdef RTE_LIBRTE_IXGBE_PMD
382077d223eSBernard Iremonger 		rte_pmd_ixgbe_set_vf_rxmode(port_id, vf,
383bda68ab9SRemy Horton 			ETH_VMDQ_ACCEPT_UNTAG, 0);
384077d223eSBernard Iremonger #endif
385077d223eSBernard Iremonger 	}
386bda68ab9SRemy Horton 
387bda68ab9SRemy Horton 	/* Enable Rx vlan filter, VF unspport status is discard */
388bda68ab9SRemy Horton 	rte_eth_dev_set_vlan_offload(port_id, ETH_VLAN_FILTER_MASK);
389bda68ab9SRemy Horton 
390bda68ab9SRemy Horton 	return 0;
391bda68ab9SRemy Horton }
392bda68ab9SRemy Horton 
393bda68ab9SRemy Horton 
394bda68ab9SRemy Horton int
39547523597SZhiyong Yang rte_ethtool_get_ringparam(uint16_t port_id,
396bda68ab9SRemy Horton 	struct ethtool_ringparam *ring_param)
397bda68ab9SRemy Horton {
398bda68ab9SRemy Horton 	struct rte_eth_dev_info dev_info;
399bda68ab9SRemy Horton 	struct rte_eth_rxq_info rx_qinfo;
400bda68ab9SRemy Horton 	struct rte_eth_txq_info tx_qinfo;
401bda68ab9SRemy Horton 	int stat;
402bda68ab9SRemy Horton 
403bda68ab9SRemy Horton 	if (ring_param == NULL)
404bda68ab9SRemy Horton 		return -EINVAL;
405bda68ab9SRemy Horton 
406bda68ab9SRemy Horton 	rte_eth_dev_info_get(port_id, &dev_info);
407bda68ab9SRemy Horton 
408bda68ab9SRemy Horton 	stat = rte_eth_rx_queue_info_get(port_id, 0, &rx_qinfo);
409bda68ab9SRemy Horton 	if (stat != 0)
410bda68ab9SRemy Horton 		return stat;
411bda68ab9SRemy Horton 
412bda68ab9SRemy Horton 	stat = rte_eth_tx_queue_info_get(port_id, 0, &tx_qinfo);
413bda68ab9SRemy Horton 	if (stat != 0)
414bda68ab9SRemy Horton 		return stat;
415bda68ab9SRemy Horton 
416bda68ab9SRemy Horton 	memset(ring_param, 0, sizeof(*ring_param));
417bda68ab9SRemy Horton 	ring_param->rx_pending = rx_qinfo.nb_desc;
418bda68ab9SRemy Horton 	ring_param->rx_max_pending = dev_info.rx_desc_lim.nb_max;
419bda68ab9SRemy Horton 	ring_param->tx_pending = tx_qinfo.nb_desc;
420bda68ab9SRemy Horton 	ring_param->tx_max_pending = dev_info.tx_desc_lim.nb_max;
421bda68ab9SRemy Horton 
422bda68ab9SRemy Horton 	return 0;
423bda68ab9SRemy Horton }
424bda68ab9SRemy Horton 
425bda68ab9SRemy Horton 
426bda68ab9SRemy Horton int
42747523597SZhiyong Yang rte_ethtool_set_ringparam(uint16_t port_id,
428bda68ab9SRemy Horton 	struct ethtool_ringparam *ring_param)
429bda68ab9SRemy Horton {
430bda68ab9SRemy Horton 	struct rte_eth_rxq_info rx_qinfo;
431bda68ab9SRemy Horton 	int stat;
432bda68ab9SRemy Horton 
433bda68ab9SRemy Horton 	if (ring_param == NULL)
434bda68ab9SRemy Horton 		return -EINVAL;
435bda68ab9SRemy Horton 
436bda68ab9SRemy Horton 	stat = rte_eth_rx_queue_info_get(port_id, 0, &rx_qinfo);
437bda68ab9SRemy Horton 	if (stat != 0)
438bda68ab9SRemy Horton 		return stat;
439bda68ab9SRemy Horton 
440bda68ab9SRemy Horton 	rte_eth_dev_stop(port_id);
441bda68ab9SRemy Horton 
442bda68ab9SRemy Horton 	stat = rte_eth_tx_queue_setup(port_id, 0, ring_param->tx_pending,
443bda68ab9SRemy Horton 		rte_socket_id(), NULL);
444bda68ab9SRemy Horton 	if (stat != 0)
445bda68ab9SRemy Horton 		return stat;
446bda68ab9SRemy Horton 
447bda68ab9SRemy Horton 	stat = rte_eth_rx_queue_setup(port_id, 0, ring_param->rx_pending,
448bda68ab9SRemy Horton 		rte_socket_id(), NULL, rx_qinfo.mp);
449bda68ab9SRemy Horton 	if (stat != 0)
450bda68ab9SRemy Horton 		return stat;
451bda68ab9SRemy Horton 
452bda68ab9SRemy Horton 	return rte_eth_dev_start(port_id);
453bda68ab9SRemy Horton }
454