1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
7 #include <rte_version.h>
8 #include <rte_ethdev.h>
10 #include <rte_bus_pci.h>
11 #ifdef RTE_LIBRTE_IXGBE_PMD
12 #include <rte_pmd_ixgbe.h>
14 #include "rte_ethtool.h"
16 #define PKTPOOL_SIZE 512
17 #define PKTPOOL_CACHE 32
21 rte_ethtool_get_drvinfo(uint16_t port_id, struct ethtool_drvinfo *drvinfo)
23 struct rte_eth_dev_info dev_info;
24 struct rte_dev_reg_info reg_info;
31 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
33 ret = rte_eth_dev_fw_version_get(port_id, drvinfo->fw_version,
34 sizeof(drvinfo->fw_version));
36 printf("firmware version get error: (%s)\n", strerror(-ret));
38 printf("Insufficient fw version buffer size, "
39 "the minimum size should be %d\n", ret);
41 memset(&dev_info, 0, sizeof(dev_info));
42 rte_eth_dev_info_get(port_id, &dev_info);
44 snprintf(drvinfo->driver, sizeof(drvinfo->driver), "%s",
45 dev_info.driver_name);
46 snprintf(drvinfo->version, sizeof(drvinfo->version), "%s",
48 /* TODO: replace bus_info by rte_devargs.name */
50 snprintf(drvinfo->bus_info, sizeof(drvinfo->bus_info),
52 dev_info.pci_dev->addr.domain,
53 dev_info.pci_dev->addr.bus,
54 dev_info.pci_dev->addr.devid,
55 dev_info.pci_dev->addr.function);
57 snprintf(drvinfo->bus_info, sizeof(drvinfo->bus_info), "N/A");
59 memset(®_info, 0, sizeof(reg_info));
60 rte_eth_dev_get_reg_info(port_id, ®_info);
63 drvinfo->regdump_len = n;
65 drvinfo->regdump_len = 0;
67 n = rte_eth_dev_get_eeprom_length(port_id);
69 drvinfo->eedump_len = n;
71 drvinfo->eedump_len = 0;
73 drvinfo->n_stats = sizeof(struct rte_eth_stats) / sizeof(uint64_t);
74 drvinfo->testinfo_len = 0;
80 rte_ethtool_get_regs_len(uint16_t port_id)
82 struct rte_dev_reg_info reg_info;
85 memset(®_info, 0, sizeof(reg_info));
87 ret = rte_eth_dev_get_reg_info(port_id, ®_info);
91 return reg_info.length * reg_info.width;
95 rte_ethtool_get_regs(uint16_t port_id, struct ethtool_regs *regs, void *data)
97 struct rte_dev_reg_info reg_info;
100 if (regs == NULL || data == NULL)
103 reg_info.data = data;
106 status = rte_eth_dev_get_reg_info(port_id, ®_info);
109 regs->version = reg_info.version;
115 rte_ethtool_get_link(uint16_t port_id)
117 struct rte_eth_link link;
119 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
120 rte_eth_link_get(port_id, &link);
121 return link.link_status;
125 rte_ethtool_get_eeprom_len(uint16_t port_id)
127 return rte_eth_dev_get_eeprom_length(port_id);
131 rte_ethtool_get_eeprom(uint16_t port_id, struct ethtool_eeprom *eeprom,
134 struct rte_dev_eeprom_info eeprom_info;
137 if (eeprom == NULL || words == NULL)
140 eeprom_info.offset = eeprom->offset;
141 eeprom_info.length = eeprom->len;
142 eeprom_info.data = words;
144 status = rte_eth_dev_get_eeprom(port_id, &eeprom_info);
148 eeprom->magic = eeprom_info.magic;
154 rte_ethtool_set_eeprom(uint16_t port_id, struct ethtool_eeprom *eeprom,
157 struct rte_dev_eeprom_info eeprom_info;
160 if (eeprom == NULL || words == NULL || eeprom->offset >= eeprom->len)
163 eeprom_info.offset = eeprom->offset;
164 eeprom_info.length = eeprom->len;
165 eeprom_info.data = words;
167 status = rte_eth_dev_set_eeprom(port_id, &eeprom_info);
171 eeprom->magic = eeprom_info.magic;
177 rte_ethtool_get_pauseparam(uint16_t port_id,
178 struct ethtool_pauseparam *pause_param)
180 struct rte_eth_fc_conf fc_conf;
183 if (pause_param == NULL)
186 status = rte_eth_dev_flow_ctrl_get(port_id, &fc_conf);
190 pause_param->tx_pause = 0;
191 pause_param->rx_pause = 0;
192 switch (fc_conf.mode) {
193 case RTE_FC_RX_PAUSE:
194 pause_param->rx_pause = 1;
196 case RTE_FC_TX_PAUSE:
197 pause_param->tx_pause = 1;
200 pause_param->rx_pause = 1;
201 pause_param->tx_pause = 1;
203 /* dummy block to avoid compiler warning */
206 pause_param->autoneg = (uint32_t)fc_conf.autoneg;
212 rte_ethtool_set_pauseparam(uint16_t port_id,
213 struct ethtool_pauseparam *pause_param)
215 struct rte_eth_fc_conf fc_conf;
218 if (pause_param == NULL)
222 * Read device flow control parameter first since
223 * ethtool set_pauseparam op doesn't have all the information.
224 * as defined in struct rte_eth_fc_conf.
225 * This API requires the device to support both
226 * rte_eth_dev_flow_ctrl_get and rte_eth_dev_flow_ctrl_set, otherwise
229 status = rte_eth_dev_flow_ctrl_get(port_id, &fc_conf);
233 fc_conf.autoneg = (uint8_t)pause_param->autoneg;
235 if (pause_param->tx_pause) {
236 if (pause_param->rx_pause)
237 fc_conf.mode = RTE_FC_FULL;
239 fc_conf.mode = RTE_FC_TX_PAUSE;
241 if (pause_param->rx_pause)
242 fc_conf.mode = RTE_FC_RX_PAUSE;
244 fc_conf.mode = RTE_FC_NONE;
247 status = rte_eth_dev_flow_ctrl_set(port_id, &fc_conf);
255 rte_ethtool_net_open(uint16_t port_id)
257 rte_eth_dev_stop(port_id);
259 return rte_eth_dev_start(port_id);
263 rte_ethtool_net_stop(uint16_t port_id)
265 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
266 rte_eth_dev_stop(port_id);
272 rte_ethtool_net_get_mac_addr(uint16_t port_id, struct ether_addr *addr)
274 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
277 rte_eth_macaddr_get(port_id, addr);
283 rte_ethtool_net_set_mac_addr(uint16_t port_id, struct ether_addr *addr)
287 return rte_eth_dev_default_mac_addr_set(port_id, addr);
291 rte_ethtool_net_validate_addr(uint16_t port_id __rte_unused,
292 struct ether_addr *addr)
296 return is_valid_assigned_ether_addr(addr);
300 rte_ethtool_net_change_mtu(uint16_t port_id, int mtu)
302 if (mtu < 0 || mtu > UINT16_MAX)
304 return rte_eth_dev_set_mtu(port_id, (uint16_t)mtu);
308 rte_ethtool_net_get_stats64(uint16_t port_id, struct rte_eth_stats *stats)
312 return rte_eth_stats_get(port_id, stats);
316 rte_ethtool_net_vlan_rx_add_vid(uint16_t port_id, uint16_t vid)
318 return rte_eth_dev_vlan_filter(port_id, vid, 1);
322 rte_ethtool_net_vlan_rx_kill_vid(uint16_t port_id, uint16_t vid)
324 return rte_eth_dev_vlan_filter(port_id, vid, 0);
328 * The set_rx_mode provides driver-specific rx mode setting.
329 * This implementation implements rx mode setting based upon
330 * ixgbe/igb drivers. Further improvement is to provide a
331 * callback op field over struct rte_eth_dev::dev_ops so each
332 * driver can register device-specific implementation
335 rte_ethtool_net_set_rx_mode(uint16_t port_id)
338 struct rte_eth_dev_info dev_info;
341 memset(&dev_info, 0, sizeof(dev_info));
342 rte_eth_dev_info_get(port_id, &dev_info);
343 num_vfs = dev_info.max_vfs;
345 /* Set VF vf_rx_mode, VF unsupport status is discard */
346 for (vf = 0; vf < num_vfs; vf++) {
347 #ifdef RTE_LIBRTE_IXGBE_PMD
348 rte_pmd_ixgbe_set_vf_rxmode(port_id, vf,
349 ETH_VMDQ_ACCEPT_UNTAG, 0);
353 /* Enable Rx vlan filter, VF unspport status is discard */
354 rte_eth_dev_set_vlan_offload(port_id, ETH_VLAN_FILTER_MASK);
361 rte_ethtool_get_ringparam(uint16_t port_id,
362 struct ethtool_ringparam *ring_param)
364 struct rte_eth_dev_info dev_info;
365 struct rte_eth_rxq_info rx_qinfo;
366 struct rte_eth_txq_info tx_qinfo;
369 if (ring_param == NULL)
372 rte_eth_dev_info_get(port_id, &dev_info);
374 stat = rte_eth_rx_queue_info_get(port_id, 0, &rx_qinfo);
378 stat = rte_eth_tx_queue_info_get(port_id, 0, &tx_qinfo);
382 memset(ring_param, 0, sizeof(*ring_param));
383 ring_param->rx_pending = rx_qinfo.nb_desc;
384 ring_param->rx_max_pending = dev_info.rx_desc_lim.nb_max;
385 ring_param->tx_pending = tx_qinfo.nb_desc;
386 ring_param->tx_max_pending = dev_info.tx_desc_lim.nb_max;
393 rte_ethtool_set_ringparam(uint16_t port_id,
394 struct ethtool_ringparam *ring_param)
396 struct rte_eth_rxq_info rx_qinfo;
399 if (ring_param == NULL)
402 stat = rte_eth_rx_queue_info_get(port_id, 0, &rx_qinfo);
406 rte_eth_dev_stop(port_id);
408 stat = rte_eth_tx_queue_setup(port_id, 0, ring_param->tx_pending,
409 rte_socket_id(), NULL);
413 stat = rte_eth_rx_queue_setup(port_id, 0, ring_param->rx_pending,
414 rte_socket_id(), NULL, rx_qinfo.mp);
418 return rte_eth_dev_start(port_id);