4 * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include <rte_version.h>
37 #include <rte_ethdev.h>
38 #include <rte_ether.h>
39 #ifdef RTE_LIBRTE_IXGBE_PMD
40 #include <rte_pmd_ixgbe.h>
42 #include "rte_ethtool.h"
44 #define PKTPOOL_SIZE 512
45 #define PKTPOOL_CACHE 32
49 rte_ethtool_get_drvinfo(uint8_t port_id, struct ethtool_drvinfo *drvinfo)
51 struct rte_eth_dev_info dev_info;
52 struct rte_dev_reg_info reg_info;
59 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
61 ret = rte_eth_dev_fw_version_get(port_id, drvinfo->fw_version,
62 sizeof(drvinfo->fw_version));
64 printf("firmware version get error: (%s)\n", strerror(-ret));
66 printf("Insufficient fw version buffer size, "
67 "the minimum size should be %d\n", ret);
69 memset(&dev_info, 0, sizeof(dev_info));
70 rte_eth_dev_info_get(port_id, &dev_info);
72 snprintf(drvinfo->driver, sizeof(drvinfo->driver), "%s",
73 dev_info.driver_name);
74 snprintf(drvinfo->version, sizeof(drvinfo->version), "%s",
77 snprintf(drvinfo->bus_info, sizeof(drvinfo->bus_info),
79 dev_info.pci_dev->addr.domain,
80 dev_info.pci_dev->addr.bus,
81 dev_info.pci_dev->addr.devid,
82 dev_info.pci_dev->addr.function);
84 snprintf(drvinfo->bus_info, sizeof(drvinfo->bus_info), "N/A");
86 memset(®_info, 0, sizeof(reg_info));
87 rte_eth_dev_get_reg_info(port_id, ®_info);
90 drvinfo->regdump_len = n;
92 drvinfo->regdump_len = 0;
94 n = rte_eth_dev_get_eeprom_length(port_id);
96 drvinfo->eedump_len = n;
98 drvinfo->eedump_len = 0;
100 drvinfo->n_stats = sizeof(struct rte_eth_stats) / sizeof(uint64_t);
101 drvinfo->testinfo_len = 0;
107 rte_ethtool_get_regs_len(uint8_t port_id)
109 struct rte_dev_reg_info reg_info;
112 memset(®_info, 0, sizeof(reg_info));
114 ret = rte_eth_dev_get_reg_info(port_id, ®_info);
118 return reg_info.length * reg_info.width;
122 rte_ethtool_get_regs(uint8_t port_id, struct ethtool_regs *regs, void *data)
124 struct rte_dev_reg_info reg_info;
127 if (regs == NULL || data == NULL)
130 reg_info.data = data;
133 status = rte_eth_dev_get_reg_info(port_id, ®_info);
136 regs->version = reg_info.version;
142 rte_ethtool_get_link(uint8_t port_id)
144 struct rte_eth_link link;
146 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
147 rte_eth_link_get(port_id, &link);
148 return link.link_status;
152 rte_ethtool_get_eeprom_len(uint8_t port_id)
154 return rte_eth_dev_get_eeprom_length(port_id);
158 rte_ethtool_get_eeprom(uint8_t port_id, struct ethtool_eeprom *eeprom,
161 struct rte_dev_eeprom_info eeprom_info;
164 if (eeprom == NULL || words == NULL)
167 eeprom_info.offset = eeprom->offset;
168 eeprom_info.length = eeprom->len;
169 eeprom_info.data = words;
171 status = rte_eth_dev_get_eeprom(port_id, &eeprom_info);
175 eeprom->magic = eeprom_info.magic;
181 rte_ethtool_set_eeprom(uint8_t port_id, struct ethtool_eeprom *eeprom,
184 struct rte_dev_eeprom_info eeprom_info;
187 if (eeprom == NULL || words == NULL || eeprom->offset >= eeprom->len)
190 eeprom_info.offset = eeprom->offset;
191 eeprom_info.length = eeprom->len;
192 eeprom_info.data = words;
194 status = rte_eth_dev_set_eeprom(port_id, &eeprom_info);
198 eeprom->magic = eeprom_info.magic;
204 rte_ethtool_get_pauseparam(uint8_t port_id,
205 struct ethtool_pauseparam *pause_param)
207 struct rte_eth_fc_conf fc_conf;
210 if (pause_param == NULL)
213 status = rte_eth_dev_flow_ctrl_get(port_id, &fc_conf);
217 pause_param->tx_pause = 0;
218 pause_param->rx_pause = 0;
219 switch (fc_conf.mode) {
220 case RTE_FC_RX_PAUSE:
221 pause_param->rx_pause = 1;
223 case RTE_FC_TX_PAUSE:
224 pause_param->tx_pause = 1;
227 pause_param->rx_pause = 1;
228 pause_param->tx_pause = 1;
230 /* dummy block to avoid compiler warning */
233 pause_param->autoneg = (uint32_t)fc_conf.autoneg;
239 rte_ethtool_set_pauseparam(uint8_t port_id,
240 struct ethtool_pauseparam *pause_param)
242 struct rte_eth_fc_conf fc_conf;
245 if (pause_param == NULL)
249 * Read device flow control parameter first since
250 * ethtool set_pauseparam op doesn't have all the information.
251 * as defined in struct rte_eth_fc_conf.
252 * This API requires the device to support both
253 * rte_eth_dev_flow_ctrl_get and rte_eth_dev_flow_ctrl_set, otherwise
256 status = rte_eth_dev_flow_ctrl_get(port_id, &fc_conf);
260 fc_conf.autoneg = (uint8_t)pause_param->autoneg;
262 if (pause_param->tx_pause) {
263 if (pause_param->rx_pause)
264 fc_conf.mode = RTE_FC_FULL;
266 fc_conf.mode = RTE_FC_TX_PAUSE;
268 if (pause_param->rx_pause)
269 fc_conf.mode = RTE_FC_RX_PAUSE;
271 fc_conf.mode = RTE_FC_NONE;
274 status = rte_eth_dev_flow_ctrl_set(port_id, &fc_conf);
282 rte_ethtool_net_open(uint8_t port_id)
284 rte_eth_dev_stop(port_id);
286 return rte_eth_dev_start(port_id);
290 rte_ethtool_net_stop(uint8_t port_id)
292 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
293 rte_eth_dev_stop(port_id);
299 rte_ethtool_net_get_mac_addr(uint8_t port_id, struct ether_addr *addr)
301 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
304 rte_eth_macaddr_get(port_id, addr);
310 rte_ethtool_net_set_mac_addr(uint8_t port_id, struct ether_addr *addr)
314 return rte_eth_dev_default_mac_addr_set(port_id, addr);
318 rte_ethtool_net_validate_addr(uint8_t port_id __rte_unused,
319 struct ether_addr *addr)
323 return is_valid_assigned_ether_addr(addr);
327 rte_ethtool_net_change_mtu(uint8_t port_id, int mtu)
329 if (mtu < 0 || mtu > UINT16_MAX)
331 return rte_eth_dev_set_mtu(port_id, (uint16_t)mtu);
335 rte_ethtool_net_get_stats64(uint8_t port_id, struct rte_eth_stats *stats)
339 return rte_eth_stats_get(port_id, stats);
343 rte_ethtool_net_vlan_rx_add_vid(uint8_t port_id, uint16_t vid)
345 return rte_eth_dev_vlan_filter(port_id, vid, 1);
349 rte_ethtool_net_vlan_rx_kill_vid(uint8_t port_id, uint16_t vid)
351 return rte_eth_dev_vlan_filter(port_id, vid, 0);
355 * The set_rx_mode provides driver-specific rx mode setting.
356 * This implementation implements rx mode setting based upon
357 * ixgbe/igb drivers. Further improvement is to provide a
358 * callback op field over struct rte_eth_dev::dev_ops so each
359 * driver can register device-specific implementation
362 rte_ethtool_net_set_rx_mode(uint8_t port_id)
365 struct rte_eth_dev_info dev_info;
368 memset(&dev_info, 0, sizeof(dev_info));
369 rte_eth_dev_info_get(port_id, &dev_info);
370 num_vfs = dev_info.max_vfs;
372 /* Set VF vf_rx_mode, VF unsupport status is discard */
373 for (vf = 0; vf < num_vfs; vf++) {
374 #ifdef RTE_LIBRTE_IXGBE_PMD
375 rte_pmd_ixgbe_set_vf_rxmode(port_id, vf,
376 ETH_VMDQ_ACCEPT_UNTAG, 0);
380 /* Enable Rx vlan filter, VF unspport status is discard */
381 rte_eth_dev_set_vlan_offload(port_id, ETH_VLAN_FILTER_MASK);
388 rte_ethtool_get_ringparam(uint8_t port_id,
389 struct ethtool_ringparam *ring_param)
391 struct rte_eth_dev_info dev_info;
392 struct rte_eth_rxq_info rx_qinfo;
393 struct rte_eth_txq_info tx_qinfo;
396 if (ring_param == NULL)
399 rte_eth_dev_info_get(port_id, &dev_info);
401 stat = rte_eth_rx_queue_info_get(port_id, 0, &rx_qinfo);
405 stat = rte_eth_tx_queue_info_get(port_id, 0, &tx_qinfo);
409 memset(ring_param, 0, sizeof(*ring_param));
410 ring_param->rx_pending = rx_qinfo.nb_desc;
411 ring_param->rx_max_pending = dev_info.rx_desc_lim.nb_max;
412 ring_param->tx_pending = tx_qinfo.nb_desc;
413 ring_param->tx_max_pending = dev_info.tx_desc_lim.nb_max;
420 rte_ethtool_set_ringparam(uint8_t port_id,
421 struct ethtool_ringparam *ring_param)
423 struct rte_eth_rxq_info rx_qinfo;
426 if (ring_param == NULL)
429 stat = rte_eth_rx_queue_info_get(port_id, 0, &rx_qinfo);
433 rte_eth_dev_stop(port_id);
435 stat = rte_eth_tx_queue_setup(port_id, 0, ring_param->tx_pending,
436 rte_socket_id(), NULL);
440 stat = rte_eth_rx_queue_setup(port_id, 0, ring_param->rx_pending,
441 rte_socket_id(), NULL, rx_qinfo.mp);
445 return rte_eth_dev_start(port_id);