xref: /dpdk/examples/ethtool/lib/rte_ethtool.c (revision 7be78d02)
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>
76723c0fcSBruce 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>
12a8d0d473SBruce Richardson #ifdef RTE_NET_IXGBE
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
rte_ethtool_get_drvinfo(uint16_t port_id,struct ethtool_drvinfo * drvinfo)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 
44089e5ed7SIvan Ilchenko 	ret = rte_eth_dev_info_get(port_id, &dev_info);
45089e5ed7SIvan Ilchenko 	if (ret != 0) {
46089e5ed7SIvan Ilchenko 		printf("Error during getting device (port %u) info: %s\n",
47089e5ed7SIvan Ilchenko 		       port_id, strerror(-ret));
48089e5ed7SIvan Ilchenko 
49089e5ed7SIvan Ilchenko 		return ret;
50089e5ed7SIvan Ilchenko 	}
51bda68ab9SRemy Horton 
526723c0fcSBruce Richardson 	strlcpy(drvinfo->driver, dev_info.driver_name,
536723c0fcSBruce Richardson 		sizeof(drvinfo->driver));
546723c0fcSBruce Richardson 	strlcpy(drvinfo->version, rte_version(), sizeof(drvinfo->version));
5517fd714eSThomas Monjalon 	/* TODO: replace bus_info by rte_devargs.name */
56cd8c7c7cSFerruh Yigit 	if (dev_info.device)
57cd8c7c7cSFerruh Yigit 		bus = rte_bus_find_by_device(dev_info.device);
58cd8c7c7cSFerruh Yigit 	if (bus && !strcmp(bus->name, "pci")) {
59cd8c7c7cSFerruh Yigit 		pci_dev = RTE_DEV_TO_PCI(dev_info.device);
60bda68ab9SRemy Horton 		snprintf(drvinfo->bus_info, sizeof(drvinfo->bus_info),
61bda68ab9SRemy Horton 			"%04x:%02x:%02x.%x",
62cd8c7c7cSFerruh Yigit 			pci_dev->addr.domain, pci_dev->addr.bus,
63cd8c7c7cSFerruh Yigit 			pci_dev->addr.devid, pci_dev->addr.function);
64cd8c7c7cSFerruh Yigit 	} else {
656c66be9aSRemy Horton 		snprintf(drvinfo->bus_info, sizeof(drvinfo->bus_info), "N/A");
66cd8c7c7cSFerruh Yigit 	}
67bda68ab9SRemy Horton 
68001a1c0fSZyta Szpak 	memset(&reg_info, 0, sizeof(reg_info));
69001a1c0fSZyta Szpak 	rte_eth_dev_get_reg_info(port_id, &reg_info);
70001a1c0fSZyta Szpak 	n = reg_info.length;
71bda68ab9SRemy Horton 	if (n > 0)
72bda68ab9SRemy Horton 		drvinfo->regdump_len = n;
73bda68ab9SRemy Horton 	else
74bda68ab9SRemy Horton 		drvinfo->regdump_len = 0;
75bda68ab9SRemy Horton 
76bda68ab9SRemy Horton 	n = rte_eth_dev_get_eeprom_length(port_id);
77bda68ab9SRemy Horton 	if (n > 0)
78bda68ab9SRemy Horton 		drvinfo->eedump_len = n;
79bda68ab9SRemy Horton 	else
80bda68ab9SRemy Horton 		drvinfo->eedump_len = 0;
81bda68ab9SRemy Horton 
82bda68ab9SRemy Horton 	drvinfo->n_stats = sizeof(struct rte_eth_stats) / sizeof(uint64_t);
83bda68ab9SRemy Horton 	drvinfo->testinfo_len = 0;
84bda68ab9SRemy Horton 
85bda68ab9SRemy Horton 	return 0;
86bda68ab9SRemy Horton }
87bda68ab9SRemy Horton 
88bda68ab9SRemy Horton int
rte_ethtool_get_regs_len(uint16_t port_id)8947523597SZhiyong Yang rte_ethtool_get_regs_len(uint16_t port_id)
90bda68ab9SRemy Horton {
91001a1c0fSZyta Szpak 	struct rte_dev_reg_info reg_info;
92001a1c0fSZyta Szpak 	int ret;
93bda68ab9SRemy Horton 
94001a1c0fSZyta Szpak 	memset(&reg_info, 0, sizeof(reg_info));
95001a1c0fSZyta Szpak 
96001a1c0fSZyta Szpak 	ret = rte_eth_dev_get_reg_info(port_id, &reg_info);
97001a1c0fSZyta Szpak 	if (ret)
98001a1c0fSZyta Szpak 		return ret;
99001a1c0fSZyta Szpak 
100001a1c0fSZyta Szpak 	return reg_info.length * reg_info.width;
101bda68ab9SRemy Horton }
102bda68ab9SRemy Horton 
103bda68ab9SRemy Horton int
rte_ethtool_get_regs(uint16_t port_id,struct ethtool_regs * regs,void * data)10447523597SZhiyong Yang rte_ethtool_get_regs(uint16_t port_id, struct ethtool_regs *regs, void *data)
105bda68ab9SRemy Horton {
106bda68ab9SRemy Horton 	struct rte_dev_reg_info reg_info;
107bda68ab9SRemy Horton 	int status;
108bda68ab9SRemy Horton 
109bda68ab9SRemy Horton 	if (regs == NULL || data == NULL)
110bda68ab9SRemy Horton 		return -EINVAL;
111bda68ab9SRemy Horton 
112bda68ab9SRemy Horton 	reg_info.data = data;
113bda68ab9SRemy Horton 	reg_info.length = 0;
114bda68ab9SRemy Horton 
115bda68ab9SRemy Horton 	status = rte_eth_dev_get_reg_info(port_id, &reg_info);
116bda68ab9SRemy Horton 	if (status)
117bda68ab9SRemy Horton 		return status;
118bda68ab9SRemy Horton 	regs->version = reg_info.version;
119bda68ab9SRemy Horton 
120bda68ab9SRemy Horton 	return 0;
121bda68ab9SRemy Horton }
122bda68ab9SRemy Horton 
123bda68ab9SRemy Horton int
rte_ethtool_get_link(uint16_t port_id)12447523597SZhiyong Yang rte_ethtool_get_link(uint16_t port_id)
125bda68ab9SRemy Horton {
126bda68ab9SRemy Horton 	struct rte_eth_link link;
12722e5c73bSIgor Romanov 	int ret;
128bda68ab9SRemy Horton 
1291414dabcSMauricio Vasquez B 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
13022e5c73bSIgor Romanov 	ret = rte_eth_link_get(port_id, &link);
13122e5c73bSIgor Romanov 	if (ret < 0)
13222e5c73bSIgor Romanov 		return ret;
13322e5c73bSIgor Romanov 
134bda68ab9SRemy Horton 	return link.link_status;
135bda68ab9SRemy Horton }
136bda68ab9SRemy Horton 
137bda68ab9SRemy Horton int
rte_ethtool_get_eeprom_len(uint16_t port_id)13847523597SZhiyong Yang rte_ethtool_get_eeprom_len(uint16_t port_id)
139bda68ab9SRemy Horton {
140bda68ab9SRemy Horton 	return rte_eth_dev_get_eeprom_length(port_id);
141bda68ab9SRemy Horton }
142bda68ab9SRemy Horton 
143bda68ab9SRemy Horton int
rte_ethtool_get_eeprom(uint16_t port_id,struct ethtool_eeprom * eeprom,void * words)14447523597SZhiyong Yang rte_ethtool_get_eeprom(uint16_t port_id, struct ethtool_eeprom *eeprom,
145bda68ab9SRemy Horton 	void *words)
146bda68ab9SRemy Horton {
147bda68ab9SRemy Horton 	struct rte_dev_eeprom_info eeprom_info;
148bda68ab9SRemy Horton 	int status;
149bda68ab9SRemy Horton 
150bda68ab9SRemy Horton 	if (eeprom == NULL || words == NULL)
151bda68ab9SRemy Horton 		return -EINVAL;
152bda68ab9SRemy Horton 
153bda68ab9SRemy Horton 	eeprom_info.offset = eeprom->offset;
154bda68ab9SRemy Horton 	eeprom_info.length = eeprom->len;
155bda68ab9SRemy Horton 	eeprom_info.data = words;
156bda68ab9SRemy Horton 
157bda68ab9SRemy Horton 	status = rte_eth_dev_get_eeprom(port_id, &eeprom_info);
158bda68ab9SRemy Horton 	if (status)
159bda68ab9SRemy Horton 		return status;
160bda68ab9SRemy Horton 
161bda68ab9SRemy Horton 	eeprom->magic = eeprom_info.magic;
162bda68ab9SRemy Horton 
163bda68ab9SRemy Horton 	return 0;
164bda68ab9SRemy Horton }
165bda68ab9SRemy Horton 
166bda68ab9SRemy Horton int
rte_ethtool_set_eeprom(uint16_t port_id,struct ethtool_eeprom * eeprom,void * words)16747523597SZhiyong Yang rte_ethtool_set_eeprom(uint16_t port_id, struct ethtool_eeprom *eeprom,
168bda68ab9SRemy Horton 	void *words)
169bda68ab9SRemy Horton {
170bda68ab9SRemy Horton 	struct rte_dev_eeprom_info eeprom_info;
171bda68ab9SRemy Horton 	int status;
172bda68ab9SRemy Horton 
173bda68ab9SRemy Horton 	if (eeprom == NULL || words == NULL || eeprom->offset >= eeprom->len)
174bda68ab9SRemy Horton 		return -EINVAL;
175bda68ab9SRemy Horton 
176bda68ab9SRemy Horton 	eeprom_info.offset = eeprom->offset;
177bda68ab9SRemy Horton 	eeprom_info.length = eeprom->len;
178bda68ab9SRemy Horton 	eeprom_info.data = words;
179bda68ab9SRemy Horton 
180bda68ab9SRemy Horton 	status = rte_eth_dev_set_eeprom(port_id, &eeprom_info);
181bda68ab9SRemy Horton 	if (status)
182bda68ab9SRemy Horton 		return status;
183bda68ab9SRemy Horton 
184bda68ab9SRemy Horton 	eeprom->magic = eeprom_info.magic;
185bda68ab9SRemy Horton 
186bda68ab9SRemy Horton 	return 0;
187bda68ab9SRemy Horton }
188bda68ab9SRemy Horton 
189bda68ab9SRemy Horton int
rte_ethtool_get_module_info(uint16_t port_id,uint32_t * modinfo)19099d8ebcfSZijie Pan rte_ethtool_get_module_info(uint16_t port_id, uint32_t *modinfo)
19199d8ebcfSZijie Pan {
19299d8ebcfSZijie Pan 	struct rte_eth_dev_module_info *info;
19399d8ebcfSZijie Pan 
19499d8ebcfSZijie Pan 	info = (struct rte_eth_dev_module_info *)modinfo;
19599d8ebcfSZijie Pan 	return rte_eth_dev_get_module_info(port_id, info);
19699d8ebcfSZijie Pan }
19799d8ebcfSZijie Pan 
19899d8ebcfSZijie Pan int
rte_ethtool_get_module_eeprom(uint16_t port_id,struct ethtool_eeprom * eeprom,void * words)19999d8ebcfSZijie Pan rte_ethtool_get_module_eeprom(uint16_t port_id, struct ethtool_eeprom *eeprom,
20099d8ebcfSZijie Pan 	void *words)
20199d8ebcfSZijie Pan {
20299d8ebcfSZijie Pan 	struct rte_dev_eeprom_info eeprom_info;
20399d8ebcfSZijie Pan 	int status;
20499d8ebcfSZijie Pan 
20599d8ebcfSZijie Pan 	if (eeprom == NULL || words == NULL)
20699d8ebcfSZijie Pan 		return -EINVAL;
20799d8ebcfSZijie Pan 
20899d8ebcfSZijie Pan 	eeprom_info.offset = eeprom->offset;
20999d8ebcfSZijie Pan 	eeprom_info.length = eeprom->len;
21099d8ebcfSZijie Pan 	eeprom_info.data = words;
21199d8ebcfSZijie Pan 
21299d8ebcfSZijie Pan 	status = rte_eth_dev_get_module_eeprom(port_id, &eeprom_info);
21399d8ebcfSZijie Pan 	if (status)
21499d8ebcfSZijie Pan 		return status;
21599d8ebcfSZijie Pan 
21699d8ebcfSZijie Pan 	return 0;
21799d8ebcfSZijie Pan }
21899d8ebcfSZijie Pan 
21999d8ebcfSZijie Pan int
rte_ethtool_get_pauseparam(uint16_t port_id,struct ethtool_pauseparam * pause_param)22047523597SZhiyong Yang rte_ethtool_get_pauseparam(uint16_t port_id,
221bda68ab9SRemy Horton 	struct ethtool_pauseparam *pause_param)
222bda68ab9SRemy Horton {
223bda68ab9SRemy Horton 	struct rte_eth_fc_conf fc_conf;
224bda68ab9SRemy Horton 	int status;
225bda68ab9SRemy Horton 
226bda68ab9SRemy Horton 	if (pause_param == NULL)
227bda68ab9SRemy Horton 		return -EINVAL;
228bda68ab9SRemy Horton 
229bda68ab9SRemy Horton 	status = rte_eth_dev_flow_ctrl_get(port_id, &fc_conf);
230bda68ab9SRemy Horton 	if (status)
231bda68ab9SRemy Horton 		return status;
232bda68ab9SRemy Horton 
233bda68ab9SRemy Horton 	pause_param->tx_pause = 0;
234bda68ab9SRemy Horton 	pause_param->rx_pause = 0;
235bda68ab9SRemy Horton 	switch (fc_conf.mode) {
236295968d1SFerruh Yigit 	case RTE_ETH_FC_RX_PAUSE:
237bda68ab9SRemy Horton 		pause_param->rx_pause = 1;
238bda68ab9SRemy Horton 		break;
239295968d1SFerruh Yigit 	case RTE_ETH_FC_TX_PAUSE:
240bda68ab9SRemy Horton 		pause_param->tx_pause = 1;
241bda68ab9SRemy Horton 		break;
242295968d1SFerruh Yigit 	case RTE_ETH_FC_FULL:
243bda68ab9SRemy Horton 		pause_param->rx_pause = 1;
244bda68ab9SRemy Horton 		pause_param->tx_pause = 1;
245bda68ab9SRemy Horton 	default:
246bda68ab9SRemy Horton 		/* dummy block to avoid compiler warning */
247bda68ab9SRemy Horton 		break;
248bda68ab9SRemy Horton 	}
249bda68ab9SRemy Horton 	pause_param->autoneg = (uint32_t)fc_conf.autoneg;
250bda68ab9SRemy Horton 
251bda68ab9SRemy Horton 	return 0;
252bda68ab9SRemy Horton }
253bda68ab9SRemy Horton 
254bda68ab9SRemy Horton int
rte_ethtool_set_pauseparam(uint16_t port_id,struct ethtool_pauseparam * pause_param)25547523597SZhiyong Yang rte_ethtool_set_pauseparam(uint16_t port_id,
256bda68ab9SRemy Horton 	struct ethtool_pauseparam *pause_param)
257bda68ab9SRemy Horton {
258bda68ab9SRemy Horton 	struct rte_eth_fc_conf fc_conf;
259bda68ab9SRemy Horton 	int status;
260bda68ab9SRemy Horton 
261bda68ab9SRemy Horton 	if (pause_param == NULL)
262bda68ab9SRemy Horton 		return -EINVAL;
263bda68ab9SRemy Horton 
264bda68ab9SRemy Horton 	/*
265bda68ab9SRemy Horton 	 * Read device flow control parameter first since
266bda68ab9SRemy Horton 	 * ethtool set_pauseparam op doesn't have all the information.
267bda68ab9SRemy Horton 	 * as defined in struct rte_eth_fc_conf.
268bda68ab9SRemy Horton 	 * This API requires the device to support both
269bda68ab9SRemy Horton 	 * rte_eth_dev_flow_ctrl_get and rte_eth_dev_flow_ctrl_set, otherwise
270bda68ab9SRemy Horton 	 * return -ENOTSUP
271bda68ab9SRemy Horton 	 */
272bda68ab9SRemy Horton 	status = rte_eth_dev_flow_ctrl_get(port_id, &fc_conf);
273bda68ab9SRemy Horton 	if (status)
274bda68ab9SRemy Horton 		return status;
275bda68ab9SRemy Horton 
276bda68ab9SRemy Horton 	fc_conf.autoneg = (uint8_t)pause_param->autoneg;
277bda68ab9SRemy Horton 
278bda68ab9SRemy Horton 	if (pause_param->tx_pause) {
279bda68ab9SRemy Horton 		if (pause_param->rx_pause)
280295968d1SFerruh Yigit 			fc_conf.mode = RTE_ETH_FC_FULL;
281bda68ab9SRemy Horton 		else
282295968d1SFerruh Yigit 			fc_conf.mode = RTE_ETH_FC_TX_PAUSE;
283bda68ab9SRemy Horton 	} else {
284bda68ab9SRemy Horton 		if (pause_param->rx_pause)
285295968d1SFerruh Yigit 			fc_conf.mode = RTE_ETH_FC_RX_PAUSE;
286bda68ab9SRemy Horton 		else
287295968d1SFerruh Yigit 			fc_conf.mode = RTE_ETH_FC_NONE;
288bda68ab9SRemy Horton 	}
289bda68ab9SRemy Horton 
290bda68ab9SRemy Horton 	status = rte_eth_dev_flow_ctrl_set(port_id, &fc_conf);
291bda68ab9SRemy Horton 	if (status)
292bda68ab9SRemy Horton 		return status;
293bda68ab9SRemy Horton 
294bda68ab9SRemy Horton 	return 0;
295bda68ab9SRemy Horton }
296bda68ab9SRemy Horton 
297bda68ab9SRemy Horton int
rte_ethtool_net_open(uint16_t port_id)29847523597SZhiyong Yang rte_ethtool_net_open(uint16_t port_id)
299bda68ab9SRemy Horton {
300b55efbabSIvan Ilchenko 	int ret;
301b55efbabSIvan Ilchenko 
302b55efbabSIvan Ilchenko 	ret = rte_eth_dev_stop(port_id);
303b55efbabSIvan Ilchenko 	if (ret != 0)
304b55efbabSIvan Ilchenko 		return ret;
305bda68ab9SRemy Horton 
306bda68ab9SRemy Horton 	return rte_eth_dev_start(port_id);
307bda68ab9SRemy Horton }
308bda68ab9SRemy Horton 
309bda68ab9SRemy Horton int
rte_ethtool_net_stop(uint16_t port_id)31047523597SZhiyong Yang rte_ethtool_net_stop(uint16_t port_id)
311bda68ab9SRemy Horton {
312b55efbabSIvan Ilchenko 	return rte_eth_dev_stop(port_id);
313bda68ab9SRemy Horton }
314bda68ab9SRemy Horton 
315bda68ab9SRemy Horton int
rte_ethtool_net_get_mac_addr(uint16_t port_id,struct rte_ether_addr * addr)3166d13ea8eSOlivier Matz rte_ethtool_net_get_mac_addr(uint16_t port_id, struct rte_ether_addr *addr)
317bda68ab9SRemy Horton {
31870febdcfSIgor Romanov 	int ret;
31970febdcfSIgor Romanov 
3201414dabcSMauricio Vasquez B 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
321bda68ab9SRemy Horton 	if (addr == NULL)
322bda68ab9SRemy Horton 		return -EINVAL;
32370febdcfSIgor Romanov 
32470febdcfSIgor Romanov 	ret = rte_eth_macaddr_get(port_id, addr);
32570febdcfSIgor Romanov 	if (ret != 0)
32670febdcfSIgor Romanov 		return ret;
327bda68ab9SRemy Horton 
328bda68ab9SRemy Horton 	return 0;
329bda68ab9SRemy Horton }
330bda68ab9SRemy Horton 
331bda68ab9SRemy Horton int
rte_ethtool_net_set_mac_addr(uint16_t port_id,struct rte_ether_addr * addr)3326d13ea8eSOlivier Matz rte_ethtool_net_set_mac_addr(uint16_t port_id, struct rte_ether_addr *addr)
333bda68ab9SRemy Horton {
334bda68ab9SRemy Horton 	if (addr == NULL)
335bda68ab9SRemy Horton 		return -EINVAL;
336bda68ab9SRemy Horton 	return rte_eth_dev_default_mac_addr_set(port_id, addr);
337bda68ab9SRemy Horton }
338bda68ab9SRemy Horton 
339bda68ab9SRemy Horton int
rte_ethtool_net_validate_addr(uint16_t port_id __rte_unused,struct rte_ether_addr * addr)34047523597SZhiyong Yang rte_ethtool_net_validate_addr(uint16_t port_id __rte_unused,
3416d13ea8eSOlivier Matz 	struct rte_ether_addr *addr)
342bda68ab9SRemy Horton {
343bda68ab9SRemy Horton 	if (addr == NULL)
344bda68ab9SRemy Horton 		return -EINVAL;
345538da7a1SOlivier Matz 	return rte_is_valid_assigned_ether_addr(addr);
346bda68ab9SRemy Horton }
347bda68ab9SRemy Horton 
348bda68ab9SRemy Horton int
rte_ethtool_net_change_mtu(uint16_t port_id,int mtu)34947523597SZhiyong Yang rte_ethtool_net_change_mtu(uint16_t port_id, int mtu)
350bda68ab9SRemy Horton {
351bda68ab9SRemy Horton 	if (mtu < 0 || mtu > UINT16_MAX)
352bda68ab9SRemy Horton 		return -EINVAL;
353bda68ab9SRemy Horton 	return rte_eth_dev_set_mtu(port_id, (uint16_t)mtu);
354bda68ab9SRemy Horton }
355bda68ab9SRemy Horton 
356bda68ab9SRemy Horton int
rte_ethtool_net_get_stats64(uint16_t port_id,struct rte_eth_stats * stats)35747523597SZhiyong Yang rte_ethtool_net_get_stats64(uint16_t port_id, struct rte_eth_stats *stats)
358bda68ab9SRemy Horton {
359bda68ab9SRemy Horton 	if (stats == NULL)
360bda68ab9SRemy Horton 		return -EINVAL;
361bda68ab9SRemy Horton 	return rte_eth_stats_get(port_id, stats);
362bda68ab9SRemy Horton }
363bda68ab9SRemy Horton 
364bda68ab9SRemy Horton int
rte_ethtool_net_vlan_rx_add_vid(uint16_t port_id,uint16_t vid)36547523597SZhiyong Yang rte_ethtool_net_vlan_rx_add_vid(uint16_t port_id, uint16_t vid)
366bda68ab9SRemy Horton {
367bda68ab9SRemy Horton 	return rte_eth_dev_vlan_filter(port_id, vid, 1);
368bda68ab9SRemy Horton }
369bda68ab9SRemy Horton 
370bda68ab9SRemy Horton int
rte_ethtool_net_vlan_rx_kill_vid(uint16_t port_id,uint16_t vid)37147523597SZhiyong Yang rte_ethtool_net_vlan_rx_kill_vid(uint16_t port_id, uint16_t vid)
372bda68ab9SRemy Horton {
373bda68ab9SRemy Horton 	return rte_eth_dev_vlan_filter(port_id, vid, 0);
374bda68ab9SRemy Horton }
375bda68ab9SRemy Horton 
376bda68ab9SRemy Horton /*
377bda68ab9SRemy Horton  * The set_rx_mode provides driver-specific rx mode setting.
378bda68ab9SRemy Horton  * This implementation implements rx mode setting based upon
379bda68ab9SRemy Horton  * ixgbe/igb drivers. Further improvement is to provide a
380bda68ab9SRemy Horton  * callback op field over struct rte_eth_dev::dev_ops so each
381bda68ab9SRemy Horton  * driver can register device-specific implementation
382bda68ab9SRemy Horton  */
383bda68ab9SRemy Horton int
rte_ethtool_net_set_rx_mode(uint16_t port_id)38447523597SZhiyong Yang rte_ethtool_net_set_rx_mode(uint16_t port_id)
385bda68ab9SRemy Horton {
386bda68ab9SRemy Horton 	uint16_t num_vfs;
387bda68ab9SRemy Horton 	struct rte_eth_dev_info dev_info;
388bda68ab9SRemy Horton 	uint16_t vf;
389089e5ed7SIvan Ilchenko 	int ret;
390bda68ab9SRemy Horton 
391089e5ed7SIvan Ilchenko 	ret = rte_eth_dev_info_get(port_id, &dev_info);
392089e5ed7SIvan Ilchenko 	if (ret != 0)
393089e5ed7SIvan Ilchenko 		return ret;
394089e5ed7SIvan Ilchenko 
395bda68ab9SRemy Horton 	num_vfs = dev_info.max_vfs;
396bda68ab9SRemy Horton 
397bda68ab9SRemy Horton 	/* Set VF vf_rx_mode, VF unsupport status is discard */
398077d223eSBernard Iremonger 	for (vf = 0; vf < num_vfs; vf++) {
399a8d0d473SBruce Richardson #ifdef RTE_NET_IXGBE
400077d223eSBernard Iremonger 		rte_pmd_ixgbe_set_vf_rxmode(port_id, vf,
401295968d1SFerruh Yigit 			RTE_ETH_VMDQ_ACCEPT_UNTAG, 0);
402077d223eSBernard Iremonger #endif
403077d223eSBernard Iremonger 	}
404bda68ab9SRemy Horton 
405*7be78d02SJosh Soref 	/* Enable Rx vlan filter, VF unsupported status is discard */
406295968d1SFerruh Yigit 	ret = rte_eth_dev_set_vlan_offload(port_id, RTE_ETH_VLAN_FILTER_MASK);
407899f6de2SGargi Sau 	if (ret != 0)
408899f6de2SGargi Sau 		return ret;
409bda68ab9SRemy Horton 
410bda68ab9SRemy Horton 	return 0;
411bda68ab9SRemy Horton }
412bda68ab9SRemy Horton 
413bda68ab9SRemy Horton 
414bda68ab9SRemy Horton int
rte_ethtool_get_ringparam(uint16_t port_id,struct ethtool_ringparam * ring_param)41547523597SZhiyong Yang rte_ethtool_get_ringparam(uint16_t port_id,
416bda68ab9SRemy Horton 	struct ethtool_ringparam *ring_param)
417bda68ab9SRemy Horton {
418bda68ab9SRemy Horton 	struct rte_eth_dev_info dev_info;
419bda68ab9SRemy Horton 	struct rte_eth_rxq_info rx_qinfo;
420bda68ab9SRemy Horton 	struct rte_eth_txq_info tx_qinfo;
421bda68ab9SRemy Horton 	int stat;
422089e5ed7SIvan Ilchenko 	int ret;
423bda68ab9SRemy Horton 
424bda68ab9SRemy Horton 	if (ring_param == NULL)
425bda68ab9SRemy Horton 		return -EINVAL;
426bda68ab9SRemy Horton 
427089e5ed7SIvan Ilchenko 	ret = rte_eth_dev_info_get(port_id, &dev_info);
428089e5ed7SIvan Ilchenko 	if (ret != 0)
429089e5ed7SIvan Ilchenko 		return ret;
430bda68ab9SRemy Horton 
431bda68ab9SRemy Horton 	stat = rte_eth_rx_queue_info_get(port_id, 0, &rx_qinfo);
432bda68ab9SRemy Horton 	if (stat != 0)
433bda68ab9SRemy Horton 		return stat;
434bda68ab9SRemy Horton 
435bda68ab9SRemy Horton 	stat = rte_eth_tx_queue_info_get(port_id, 0, &tx_qinfo);
436bda68ab9SRemy Horton 	if (stat != 0)
437bda68ab9SRemy Horton 		return stat;
438bda68ab9SRemy Horton 
439bda68ab9SRemy Horton 	memset(ring_param, 0, sizeof(*ring_param));
440bda68ab9SRemy Horton 	ring_param->rx_pending = rx_qinfo.nb_desc;
441bda68ab9SRemy Horton 	ring_param->rx_max_pending = dev_info.rx_desc_lim.nb_max;
442bda68ab9SRemy Horton 	ring_param->tx_pending = tx_qinfo.nb_desc;
443bda68ab9SRemy Horton 	ring_param->tx_max_pending = dev_info.tx_desc_lim.nb_max;
444bda68ab9SRemy Horton 
445bda68ab9SRemy Horton 	return 0;
446bda68ab9SRemy Horton }
447bda68ab9SRemy Horton 
448bda68ab9SRemy Horton 
449bda68ab9SRemy Horton int
rte_ethtool_set_ringparam(uint16_t port_id,struct ethtool_ringparam * ring_param)45047523597SZhiyong Yang rte_ethtool_set_ringparam(uint16_t port_id,
451bda68ab9SRemy Horton 	struct ethtool_ringparam *ring_param)
452bda68ab9SRemy Horton {
453bda68ab9SRemy Horton 	struct rte_eth_rxq_info rx_qinfo;
454bda68ab9SRemy Horton 	int stat;
455bda68ab9SRemy Horton 
456bda68ab9SRemy Horton 	if (ring_param == NULL)
457bda68ab9SRemy Horton 		return -EINVAL;
458bda68ab9SRemy Horton 
459bda68ab9SRemy Horton 	stat = rte_eth_rx_queue_info_get(port_id, 0, &rx_qinfo);
460bda68ab9SRemy Horton 	if (stat != 0)
461bda68ab9SRemy Horton 		return stat;
462bda68ab9SRemy Horton 
463b55efbabSIvan Ilchenko 	stat = rte_eth_dev_stop(port_id);
464b55efbabSIvan Ilchenko 	if (stat != 0)
465b55efbabSIvan Ilchenko 		return stat;
466bda68ab9SRemy Horton 
467bda68ab9SRemy Horton 	stat = rte_eth_tx_queue_setup(port_id, 0, ring_param->tx_pending,
4684199ce15SChengwen Feng 		rte_eth_dev_socket_id(port_id), NULL);
469bda68ab9SRemy Horton 	if (stat != 0)
470bda68ab9SRemy Horton 		return stat;
471bda68ab9SRemy Horton 
472bda68ab9SRemy Horton 	stat = rte_eth_rx_queue_setup(port_id, 0, ring_param->rx_pending,
4734199ce15SChengwen Feng 		rte_eth_dev_socket_id(port_id), NULL, rx_qinfo.mp);
474bda68ab9SRemy Horton 	if (stat != 0)
475bda68ab9SRemy Horton 		return stat;
476bda68ab9SRemy Horton 
477bda68ab9SRemy Horton 	return rte_eth_dev_start(port_id);
478bda68ab9SRemy Horton }
479