4 * Copyright(c) 2010-2015 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 #include "rte_ethtool.h"
41 #define PKTPOOL_SIZE 512
42 #define PKTPOOL_CACHE 32
46 rte_ethtool_get_drvinfo(uint8_t port_id, struct ethtool_drvinfo *drvinfo)
48 struct rte_eth_dev_info dev_info;
49 struct rte_dev_reg_info reg_info;
55 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
57 memset(&dev_info, 0, sizeof(dev_info));
58 rte_eth_dev_info_get(port_id, &dev_info);
60 snprintf(drvinfo->driver, sizeof(drvinfo->driver), "%s",
61 dev_info.driver_name);
62 snprintf(drvinfo->version, sizeof(drvinfo->version), "%s",
65 snprintf(drvinfo->bus_info, sizeof(drvinfo->bus_info),
67 dev_info.pci_dev->addr.domain,
68 dev_info.pci_dev->addr.bus,
69 dev_info.pci_dev->addr.devid,
70 dev_info.pci_dev->addr.function);
72 snprintf(drvinfo->bus_info, sizeof(drvinfo->bus_info), "N/A");
74 memset(®_info, 0, sizeof(reg_info));
75 rte_eth_dev_get_reg_info(port_id, ®_info);
78 drvinfo->regdump_len = n;
80 drvinfo->regdump_len = 0;
82 n = rte_eth_dev_get_eeprom_length(port_id);
84 drvinfo->eedump_len = n;
86 drvinfo->eedump_len = 0;
88 drvinfo->n_stats = sizeof(struct rte_eth_stats) / sizeof(uint64_t);
89 drvinfo->testinfo_len = 0;
95 rte_ethtool_get_regs_len(uint8_t port_id)
97 struct rte_dev_reg_info reg_info;
100 memset(®_info, 0, sizeof(reg_info));
102 ret = rte_eth_dev_get_reg_info(port_id, ®_info);
106 return reg_info.length * reg_info.width;
110 rte_ethtool_get_regs(uint8_t port_id, struct ethtool_regs *regs, void *data)
112 struct rte_dev_reg_info reg_info;
115 if (regs == NULL || data == NULL)
118 reg_info.data = data;
121 status = rte_eth_dev_get_reg_info(port_id, ®_info);
124 regs->version = reg_info.version;
130 rte_ethtool_get_link(uint8_t port_id)
132 struct rte_eth_link link;
134 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
135 rte_eth_link_get(port_id, &link);
136 return link.link_status;
140 rte_ethtool_get_eeprom_len(uint8_t port_id)
142 return rte_eth_dev_get_eeprom_length(port_id);
146 rte_ethtool_get_eeprom(uint8_t port_id, struct ethtool_eeprom *eeprom,
149 struct rte_dev_eeprom_info eeprom_info;
152 if (eeprom == NULL || words == NULL)
155 eeprom_info.offset = eeprom->offset;
156 eeprom_info.length = eeprom->len;
157 eeprom_info.data = words;
159 status = rte_eth_dev_get_eeprom(port_id, &eeprom_info);
163 eeprom->magic = eeprom_info.magic;
169 rte_ethtool_set_eeprom(uint8_t port_id, struct ethtool_eeprom *eeprom,
172 struct rte_dev_eeprom_info eeprom_info;
175 if (eeprom == NULL || words == NULL || eeprom->offset >= eeprom->len)
178 eeprom_info.offset = eeprom->offset;
179 eeprom_info.length = eeprom->len;
180 eeprom_info.data = words;
182 status = rte_eth_dev_set_eeprom(port_id, &eeprom_info);
186 eeprom->magic = eeprom_info.magic;
192 rte_ethtool_get_pauseparam(uint8_t port_id,
193 struct ethtool_pauseparam *pause_param)
195 struct rte_eth_fc_conf fc_conf;
198 if (pause_param == NULL)
201 status = rte_eth_dev_flow_ctrl_get(port_id, &fc_conf);
205 pause_param->tx_pause = 0;
206 pause_param->rx_pause = 0;
207 switch (fc_conf.mode) {
208 case RTE_FC_RX_PAUSE:
209 pause_param->rx_pause = 1;
211 case RTE_FC_TX_PAUSE:
212 pause_param->tx_pause = 1;
215 pause_param->rx_pause = 1;
216 pause_param->tx_pause = 1;
218 /* dummy block to avoid compiler warning */
221 pause_param->autoneg = (uint32_t)fc_conf.autoneg;
227 rte_ethtool_set_pauseparam(uint8_t port_id,
228 struct ethtool_pauseparam *pause_param)
230 struct rte_eth_fc_conf fc_conf;
233 if (pause_param == NULL)
237 * Read device flow control parameter first since
238 * ethtool set_pauseparam op doesn't have all the information.
239 * as defined in struct rte_eth_fc_conf.
240 * This API requires the device to support both
241 * rte_eth_dev_flow_ctrl_get and rte_eth_dev_flow_ctrl_set, otherwise
244 status = rte_eth_dev_flow_ctrl_get(port_id, &fc_conf);
248 fc_conf.autoneg = (uint8_t)pause_param->autoneg;
250 if (pause_param->tx_pause) {
251 if (pause_param->rx_pause)
252 fc_conf.mode = RTE_FC_FULL;
254 fc_conf.mode = RTE_FC_TX_PAUSE;
256 if (pause_param->rx_pause)
257 fc_conf.mode = RTE_FC_RX_PAUSE;
259 fc_conf.mode = RTE_FC_NONE;
262 status = rte_eth_dev_flow_ctrl_set(port_id, &fc_conf);
270 rte_ethtool_net_open(uint8_t port_id)
272 rte_eth_dev_stop(port_id);
274 return rte_eth_dev_start(port_id);
278 rte_ethtool_net_stop(uint8_t port_id)
280 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
281 rte_eth_dev_stop(port_id);
287 rte_ethtool_net_get_mac_addr(uint8_t port_id, struct ether_addr *addr)
289 RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
292 rte_eth_macaddr_get(port_id, addr);
298 rte_ethtool_net_set_mac_addr(uint8_t port_id, struct ether_addr *addr)
302 return rte_eth_dev_default_mac_addr_set(port_id, addr);
306 rte_ethtool_net_validate_addr(uint8_t port_id __rte_unused,
307 struct ether_addr *addr)
311 return is_valid_assigned_ether_addr(addr);
315 rte_ethtool_net_change_mtu(uint8_t port_id, int mtu)
317 if (mtu < 0 || mtu > UINT16_MAX)
319 return rte_eth_dev_set_mtu(port_id, (uint16_t)mtu);
323 rte_ethtool_net_get_stats64(uint8_t port_id, struct rte_eth_stats *stats)
327 return rte_eth_stats_get(port_id, stats);
331 rte_ethtool_net_vlan_rx_add_vid(uint8_t port_id, uint16_t vid)
333 return rte_eth_dev_vlan_filter(port_id, vid, 1);
337 rte_ethtool_net_vlan_rx_kill_vid(uint8_t port_id, uint16_t vid)
339 return rte_eth_dev_vlan_filter(port_id, vid, 0);
343 * The set_rx_mode provides driver-specific rx mode setting.
344 * This implementation implements rx mode setting based upon
345 * ixgbe/igb drivers. Further improvement is to provide a
346 * callback op field over struct rte_eth_dev::dev_ops so each
347 * driver can register device-specific implementation
350 rte_ethtool_net_set_rx_mode(uint8_t port_id)
353 struct rte_eth_dev_info dev_info;
356 memset(&dev_info, 0, sizeof(dev_info));
357 rte_eth_dev_info_get(port_id, &dev_info);
358 num_vfs = dev_info.max_vfs;
360 /* Set VF vf_rx_mode, VF unsupport status is discard */
361 for (vf = 0; vf < num_vfs; vf++)
362 rte_eth_dev_set_vf_rxmode(port_id, vf,
363 ETH_VMDQ_ACCEPT_UNTAG, 0);
365 /* Enable Rx vlan filter, VF unspport status is discard */
366 rte_eth_dev_set_vlan_offload(port_id, ETH_VLAN_FILTER_MASK);
373 rte_ethtool_get_ringparam(uint8_t port_id,
374 struct ethtool_ringparam *ring_param)
376 struct rte_eth_dev_info dev_info;
377 struct rte_eth_rxq_info rx_qinfo;
378 struct rte_eth_txq_info tx_qinfo;
381 if (ring_param == NULL)
384 rte_eth_dev_info_get(port_id, &dev_info);
386 stat = rte_eth_rx_queue_info_get(port_id, 0, &rx_qinfo);
390 stat = rte_eth_tx_queue_info_get(port_id, 0, &tx_qinfo);
394 memset(ring_param, 0, sizeof(*ring_param));
395 ring_param->rx_pending = rx_qinfo.nb_desc;
396 ring_param->rx_max_pending = dev_info.rx_desc_lim.nb_max;
397 ring_param->tx_pending = tx_qinfo.nb_desc;
398 ring_param->tx_max_pending = dev_info.tx_desc_lim.nb_max;
405 rte_ethtool_set_ringparam(uint8_t port_id,
406 struct ethtool_ringparam *ring_param)
408 struct rte_eth_rxq_info rx_qinfo;
411 if (ring_param == NULL)
414 stat = rte_eth_rx_queue_info_get(port_id, 0, &rx_qinfo);
418 rte_eth_dev_stop(port_id);
420 stat = rte_eth_tx_queue_setup(port_id, 0, ring_param->tx_pending,
421 rte_socket_id(), NULL);
425 stat = rte_eth_rx_queue_setup(port_id, 0, ring_param->rx_pending,
426 rte_socket_id(), NULL, rx_qinfo.mp);
430 return rte_eth_dev_start(port_id);