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> 11a8d0d473SBruce Richardson #ifdef RTE_NET_IXGBE 12077d223eSBernard Iremonger #include <rte_pmd_ixgbe.h> 13077d223eSBernard Iremonger #endif 14bda68ab9SRemy Horton #include "rte_ethtool.h" 15bda68ab9SRemy Horton 16bda68ab9SRemy Horton #define PKTPOOL_SIZE 512 17bda68ab9SRemy Horton #define PKTPOOL_CACHE 32 18bda68ab9SRemy Horton 19bda68ab9SRemy Horton 20bda68ab9SRemy Horton int 2147523597SZhiyong Yang rte_ethtool_get_drvinfo(uint16_t port_id, struct ethtool_drvinfo *drvinfo) 22bda68ab9SRemy Horton { 23bda68ab9SRemy Horton struct rte_eth_dev_info dev_info; 24001a1c0fSZyta Szpak struct rte_dev_reg_info reg_info; 25bda68ab9SRemy Horton int n; 261e07b4ecSQiming Yang int ret; 27bda68ab9SRemy Horton 28bda68ab9SRemy Horton if (drvinfo == NULL) 29bda68ab9SRemy Horton return -EINVAL; 30bda68ab9SRemy Horton 311414dabcSMauricio Vasquez B RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 32bda68ab9SRemy Horton 331e07b4ecSQiming Yang ret = rte_eth_dev_fw_version_get(port_id, drvinfo->fw_version, 341e07b4ecSQiming Yang sizeof(drvinfo->fw_version)); 351e07b4ecSQiming Yang if (ret < 0) 361e07b4ecSQiming Yang printf("firmware version get error: (%s)\n", strerror(-ret)); 371e07b4ecSQiming Yang else if (ret > 0) 381e07b4ecSQiming Yang printf("Insufficient fw version buffer size, " 3998a7ea33SJerin Jacob "the minimum size should be %d\n", ret); 401e07b4ecSQiming Yang 41089e5ed7SIvan Ilchenko ret = rte_eth_dev_info_get(port_id, &dev_info); 42089e5ed7SIvan Ilchenko if (ret != 0) { 43089e5ed7SIvan Ilchenko printf("Error during getting device (port %u) info: %s\n", 44089e5ed7SIvan Ilchenko port_id, strerror(-ret)); 45089e5ed7SIvan Ilchenko 46089e5ed7SIvan Ilchenko return ret; 47089e5ed7SIvan Ilchenko } 48bda68ab9SRemy Horton 496723c0fcSBruce Richardson strlcpy(drvinfo->driver, dev_info.driver_name, 506723c0fcSBruce Richardson sizeof(drvinfo->driver)); 516723c0fcSBruce Richardson strlcpy(drvinfo->version, rte_version(), sizeof(drvinfo->version)); 52ec5ecd7eSDavid Marchand strlcpy(drvinfo->bus_info, rte_dev_name(dev_info.device), 53d589a8a8SDavid Marchand sizeof(drvinfo->bus_info)); 54bda68ab9SRemy Horton 55001a1c0fSZyta Szpak memset(®_info, 0, sizeof(reg_info)); 56*7d042274SStephen Hemminger if (rte_eth_dev_get_reg_info(port_id, ®_info) == 0) 57*7d042274SStephen Hemminger drvinfo->regdump_len = reg_info.length; 58bda68ab9SRemy Horton else 59bda68ab9SRemy Horton drvinfo->regdump_len = 0; 60bda68ab9SRemy Horton 61bda68ab9SRemy Horton n = rte_eth_dev_get_eeprom_length(port_id); 62bda68ab9SRemy Horton if (n > 0) 63bda68ab9SRemy Horton drvinfo->eedump_len = n; 64bda68ab9SRemy Horton else 65bda68ab9SRemy Horton drvinfo->eedump_len = 0; 66bda68ab9SRemy Horton 67bda68ab9SRemy Horton drvinfo->n_stats = sizeof(struct rte_eth_stats) / sizeof(uint64_t); 68bda68ab9SRemy Horton drvinfo->testinfo_len = 0; 69bda68ab9SRemy Horton 70bda68ab9SRemy Horton return 0; 71bda68ab9SRemy Horton } 72bda68ab9SRemy Horton 73bda68ab9SRemy Horton int 7447523597SZhiyong Yang rte_ethtool_get_regs_len(uint16_t port_id) 75bda68ab9SRemy Horton { 76001a1c0fSZyta Szpak struct rte_dev_reg_info reg_info; 77001a1c0fSZyta Szpak int ret; 78bda68ab9SRemy Horton 79001a1c0fSZyta Szpak memset(®_info, 0, sizeof(reg_info)); 80001a1c0fSZyta Szpak 81001a1c0fSZyta Szpak ret = rte_eth_dev_get_reg_info(port_id, ®_info); 82001a1c0fSZyta Szpak if (ret) 83001a1c0fSZyta Szpak return ret; 84001a1c0fSZyta Szpak 85001a1c0fSZyta Szpak return reg_info.length * reg_info.width; 86bda68ab9SRemy Horton } 87bda68ab9SRemy Horton 88bda68ab9SRemy Horton int 8947523597SZhiyong Yang rte_ethtool_get_regs(uint16_t port_id, struct ethtool_regs *regs, void *data) 90bda68ab9SRemy Horton { 91bda68ab9SRemy Horton struct rte_dev_reg_info reg_info; 92bda68ab9SRemy Horton int status; 93bda68ab9SRemy Horton 94bda68ab9SRemy Horton if (regs == NULL || data == NULL) 95bda68ab9SRemy Horton return -EINVAL; 96bda68ab9SRemy Horton 97bda68ab9SRemy Horton reg_info.data = data; 98bda68ab9SRemy Horton reg_info.length = 0; 99bda68ab9SRemy Horton 100bda68ab9SRemy Horton status = rte_eth_dev_get_reg_info(port_id, ®_info); 101bda68ab9SRemy Horton if (status) 102bda68ab9SRemy Horton return status; 103bda68ab9SRemy Horton regs->version = reg_info.version; 104bda68ab9SRemy Horton 105bda68ab9SRemy Horton return 0; 106bda68ab9SRemy Horton } 107bda68ab9SRemy Horton 108bda68ab9SRemy Horton int 10947523597SZhiyong Yang rte_ethtool_get_link(uint16_t port_id) 110bda68ab9SRemy Horton { 111bda68ab9SRemy Horton struct rte_eth_link link; 11222e5c73bSIgor Romanov int ret; 113bda68ab9SRemy Horton 1141414dabcSMauricio Vasquez B RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 11522e5c73bSIgor Romanov ret = rte_eth_link_get(port_id, &link); 11622e5c73bSIgor Romanov if (ret < 0) 11722e5c73bSIgor Romanov return ret; 11822e5c73bSIgor Romanov 119bda68ab9SRemy Horton return link.link_status; 120bda68ab9SRemy Horton } 121bda68ab9SRemy Horton 122bda68ab9SRemy Horton int 12347523597SZhiyong Yang rte_ethtool_get_eeprom_len(uint16_t port_id) 124bda68ab9SRemy Horton { 125bda68ab9SRemy Horton return rte_eth_dev_get_eeprom_length(port_id); 126bda68ab9SRemy Horton } 127bda68ab9SRemy Horton 128bda68ab9SRemy Horton int 12947523597SZhiyong Yang rte_ethtool_get_eeprom(uint16_t port_id, struct ethtool_eeprom *eeprom, 130bda68ab9SRemy Horton void *words) 131bda68ab9SRemy Horton { 132bda68ab9SRemy Horton struct rte_dev_eeprom_info eeprom_info; 133bda68ab9SRemy Horton int status; 134bda68ab9SRemy Horton 135bda68ab9SRemy Horton if (eeprom == NULL || words == NULL) 136bda68ab9SRemy Horton return -EINVAL; 137bda68ab9SRemy Horton 138bda68ab9SRemy Horton eeprom_info.offset = eeprom->offset; 139bda68ab9SRemy Horton eeprom_info.length = eeprom->len; 140bda68ab9SRemy Horton eeprom_info.data = words; 141bda68ab9SRemy Horton 142bda68ab9SRemy Horton status = rte_eth_dev_get_eeprom(port_id, &eeprom_info); 143bda68ab9SRemy Horton if (status) 144bda68ab9SRemy Horton return status; 145bda68ab9SRemy Horton 146bda68ab9SRemy Horton eeprom->magic = eeprom_info.magic; 147bda68ab9SRemy Horton 148bda68ab9SRemy Horton return 0; 149bda68ab9SRemy Horton } 150bda68ab9SRemy Horton 151bda68ab9SRemy Horton int 15247523597SZhiyong Yang rte_ethtool_set_eeprom(uint16_t port_id, struct ethtool_eeprom *eeprom, 153bda68ab9SRemy Horton void *words) 154bda68ab9SRemy Horton { 155bda68ab9SRemy Horton struct rte_dev_eeprom_info eeprom_info; 156bda68ab9SRemy Horton int status; 157bda68ab9SRemy Horton 158bda68ab9SRemy Horton if (eeprom == NULL || words == NULL || eeprom->offset >= eeprom->len) 159bda68ab9SRemy Horton return -EINVAL; 160bda68ab9SRemy Horton 161bda68ab9SRemy Horton eeprom_info.offset = eeprom->offset; 162bda68ab9SRemy Horton eeprom_info.length = eeprom->len; 163bda68ab9SRemy Horton eeprom_info.data = words; 164bda68ab9SRemy Horton 165bda68ab9SRemy Horton status = rte_eth_dev_set_eeprom(port_id, &eeprom_info); 166bda68ab9SRemy Horton if (status) 167bda68ab9SRemy Horton return status; 168bda68ab9SRemy Horton 169bda68ab9SRemy Horton eeprom->magic = eeprom_info.magic; 170bda68ab9SRemy Horton 171bda68ab9SRemy Horton return 0; 172bda68ab9SRemy Horton } 173bda68ab9SRemy Horton 174bda68ab9SRemy Horton int 17599d8ebcfSZijie Pan rte_ethtool_get_module_info(uint16_t port_id, uint32_t *modinfo) 17699d8ebcfSZijie Pan { 17799d8ebcfSZijie Pan struct rte_eth_dev_module_info *info; 17899d8ebcfSZijie Pan 17999d8ebcfSZijie Pan info = (struct rte_eth_dev_module_info *)modinfo; 18099d8ebcfSZijie Pan return rte_eth_dev_get_module_info(port_id, info); 18199d8ebcfSZijie Pan } 18299d8ebcfSZijie Pan 18399d8ebcfSZijie Pan int 18499d8ebcfSZijie Pan rte_ethtool_get_module_eeprom(uint16_t port_id, struct ethtool_eeprom *eeprom, 18599d8ebcfSZijie Pan void *words) 18699d8ebcfSZijie Pan { 18799d8ebcfSZijie Pan struct rte_dev_eeprom_info eeprom_info; 18899d8ebcfSZijie Pan int status; 18999d8ebcfSZijie Pan 19099d8ebcfSZijie Pan if (eeprom == NULL || words == NULL) 19199d8ebcfSZijie Pan return -EINVAL; 19299d8ebcfSZijie Pan 19399d8ebcfSZijie Pan eeprom_info.offset = eeprom->offset; 19499d8ebcfSZijie Pan eeprom_info.length = eeprom->len; 19599d8ebcfSZijie Pan eeprom_info.data = words; 19699d8ebcfSZijie Pan 19799d8ebcfSZijie Pan status = rte_eth_dev_get_module_eeprom(port_id, &eeprom_info); 19899d8ebcfSZijie Pan if (status) 19999d8ebcfSZijie Pan return status; 20099d8ebcfSZijie Pan 20199d8ebcfSZijie Pan return 0; 20299d8ebcfSZijie Pan } 20399d8ebcfSZijie Pan 20499d8ebcfSZijie Pan int 20547523597SZhiyong Yang rte_ethtool_get_pauseparam(uint16_t port_id, 206bda68ab9SRemy Horton struct ethtool_pauseparam *pause_param) 207bda68ab9SRemy Horton { 208bda68ab9SRemy Horton struct rte_eth_fc_conf fc_conf; 209bda68ab9SRemy Horton int status; 210bda68ab9SRemy Horton 211bda68ab9SRemy Horton if (pause_param == NULL) 212bda68ab9SRemy Horton return -EINVAL; 213bda68ab9SRemy Horton 214bda68ab9SRemy Horton status = rte_eth_dev_flow_ctrl_get(port_id, &fc_conf); 215bda68ab9SRemy Horton if (status) 216bda68ab9SRemy Horton return status; 217bda68ab9SRemy Horton 218bda68ab9SRemy Horton pause_param->tx_pause = 0; 219bda68ab9SRemy Horton pause_param->rx_pause = 0; 220bda68ab9SRemy Horton switch (fc_conf.mode) { 221295968d1SFerruh Yigit case RTE_ETH_FC_RX_PAUSE: 222bda68ab9SRemy Horton pause_param->rx_pause = 1; 223bda68ab9SRemy Horton break; 224295968d1SFerruh Yigit case RTE_ETH_FC_TX_PAUSE: 225bda68ab9SRemy Horton pause_param->tx_pause = 1; 226bda68ab9SRemy Horton break; 227295968d1SFerruh Yigit case RTE_ETH_FC_FULL: 228bda68ab9SRemy Horton pause_param->rx_pause = 1; 229bda68ab9SRemy Horton pause_param->tx_pause = 1; 230bda68ab9SRemy Horton default: 231bda68ab9SRemy Horton /* dummy block to avoid compiler warning */ 232bda68ab9SRemy Horton break; 233bda68ab9SRemy Horton } 234bda68ab9SRemy Horton pause_param->autoneg = (uint32_t)fc_conf.autoneg; 235bda68ab9SRemy Horton 236bda68ab9SRemy Horton return 0; 237bda68ab9SRemy Horton } 238bda68ab9SRemy Horton 239bda68ab9SRemy Horton int 24047523597SZhiyong Yang rte_ethtool_set_pauseparam(uint16_t port_id, 241bda68ab9SRemy Horton struct ethtool_pauseparam *pause_param) 242bda68ab9SRemy Horton { 243bda68ab9SRemy Horton struct rte_eth_fc_conf fc_conf; 244bda68ab9SRemy Horton int status; 245bda68ab9SRemy Horton 246bda68ab9SRemy Horton if (pause_param == NULL) 247bda68ab9SRemy Horton return -EINVAL; 248bda68ab9SRemy Horton 249bda68ab9SRemy Horton /* 250bda68ab9SRemy Horton * Read device flow control parameter first since 251bda68ab9SRemy Horton * ethtool set_pauseparam op doesn't have all the information. 252bda68ab9SRemy Horton * as defined in struct rte_eth_fc_conf. 253bda68ab9SRemy Horton * This API requires the device to support both 254bda68ab9SRemy Horton * rte_eth_dev_flow_ctrl_get and rte_eth_dev_flow_ctrl_set, otherwise 255bda68ab9SRemy Horton * return -ENOTSUP 256bda68ab9SRemy Horton */ 257bda68ab9SRemy Horton status = rte_eth_dev_flow_ctrl_get(port_id, &fc_conf); 258bda68ab9SRemy Horton if (status) 259bda68ab9SRemy Horton return status; 260bda68ab9SRemy Horton 261bda68ab9SRemy Horton fc_conf.autoneg = (uint8_t)pause_param->autoneg; 262bda68ab9SRemy Horton 263bda68ab9SRemy Horton if (pause_param->tx_pause) { 264bda68ab9SRemy Horton if (pause_param->rx_pause) 265295968d1SFerruh Yigit fc_conf.mode = RTE_ETH_FC_FULL; 266bda68ab9SRemy Horton else 267295968d1SFerruh Yigit fc_conf.mode = RTE_ETH_FC_TX_PAUSE; 268bda68ab9SRemy Horton } else { 269bda68ab9SRemy Horton if (pause_param->rx_pause) 270295968d1SFerruh Yigit fc_conf.mode = RTE_ETH_FC_RX_PAUSE; 271bda68ab9SRemy Horton else 272295968d1SFerruh Yigit fc_conf.mode = RTE_ETH_FC_NONE; 273bda68ab9SRemy Horton } 274bda68ab9SRemy Horton 275bda68ab9SRemy Horton status = rte_eth_dev_flow_ctrl_set(port_id, &fc_conf); 276bda68ab9SRemy Horton if (status) 277bda68ab9SRemy Horton return status; 278bda68ab9SRemy Horton 279bda68ab9SRemy Horton return 0; 280bda68ab9SRemy Horton } 281bda68ab9SRemy Horton 282bda68ab9SRemy Horton int 28347523597SZhiyong Yang rte_ethtool_net_open(uint16_t port_id) 284bda68ab9SRemy Horton { 285bda68ab9SRemy Horton return rte_eth_dev_start(port_id); 286bda68ab9SRemy Horton } 287bda68ab9SRemy Horton 288bda68ab9SRemy Horton int 28947523597SZhiyong Yang rte_ethtool_net_stop(uint16_t port_id) 290bda68ab9SRemy Horton { 291b55efbabSIvan Ilchenko return rte_eth_dev_stop(port_id); 292bda68ab9SRemy Horton } 293bda68ab9SRemy Horton 294bda68ab9SRemy Horton int 2956d13ea8eSOlivier Matz rte_ethtool_net_get_mac_addr(uint16_t port_id, struct rte_ether_addr *addr) 296bda68ab9SRemy Horton { 29770febdcfSIgor Romanov int ret; 29870febdcfSIgor Romanov 2991414dabcSMauricio Vasquez B RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 300bda68ab9SRemy Horton if (addr == NULL) 301bda68ab9SRemy Horton return -EINVAL; 30270febdcfSIgor Romanov 30370febdcfSIgor Romanov ret = rte_eth_macaddr_get(port_id, addr); 30470febdcfSIgor Romanov if (ret != 0) 30570febdcfSIgor Romanov return ret; 306bda68ab9SRemy Horton 307bda68ab9SRemy Horton return 0; 308bda68ab9SRemy Horton } 309bda68ab9SRemy Horton 310bda68ab9SRemy Horton int 3116d13ea8eSOlivier Matz rte_ethtool_net_set_mac_addr(uint16_t port_id, struct rte_ether_addr *addr) 312bda68ab9SRemy Horton { 313bda68ab9SRemy Horton if (addr == NULL) 314bda68ab9SRemy Horton return -EINVAL; 315bda68ab9SRemy Horton return rte_eth_dev_default_mac_addr_set(port_id, addr); 316bda68ab9SRemy Horton } 317bda68ab9SRemy Horton 318bda68ab9SRemy Horton int 31947523597SZhiyong Yang rte_ethtool_net_validate_addr(uint16_t port_id __rte_unused, 3206d13ea8eSOlivier Matz struct rte_ether_addr *addr) 321bda68ab9SRemy Horton { 322bda68ab9SRemy Horton if (addr == NULL) 323bda68ab9SRemy Horton return -EINVAL; 324538da7a1SOlivier Matz return rte_is_valid_assigned_ether_addr(addr); 325bda68ab9SRemy Horton } 326bda68ab9SRemy Horton 327bda68ab9SRemy Horton int 32847523597SZhiyong Yang rte_ethtool_net_change_mtu(uint16_t port_id, int mtu) 329bda68ab9SRemy Horton { 330bda68ab9SRemy Horton if (mtu < 0 || mtu > UINT16_MAX) 331bda68ab9SRemy Horton return -EINVAL; 332bda68ab9SRemy Horton return rte_eth_dev_set_mtu(port_id, (uint16_t)mtu); 333bda68ab9SRemy Horton } 334bda68ab9SRemy Horton 335bda68ab9SRemy Horton int 33647523597SZhiyong Yang rte_ethtool_net_get_stats64(uint16_t port_id, struct rte_eth_stats *stats) 337bda68ab9SRemy Horton { 338bda68ab9SRemy Horton if (stats == NULL) 339bda68ab9SRemy Horton return -EINVAL; 340bda68ab9SRemy Horton return rte_eth_stats_get(port_id, stats); 341bda68ab9SRemy Horton } 342bda68ab9SRemy Horton 343bda68ab9SRemy Horton int 34447523597SZhiyong Yang rte_ethtool_net_vlan_rx_add_vid(uint16_t port_id, uint16_t vid) 345bda68ab9SRemy Horton { 346bda68ab9SRemy Horton return rte_eth_dev_vlan_filter(port_id, vid, 1); 347bda68ab9SRemy Horton } 348bda68ab9SRemy Horton 349bda68ab9SRemy Horton int 35047523597SZhiyong Yang rte_ethtool_net_vlan_rx_kill_vid(uint16_t port_id, uint16_t vid) 351bda68ab9SRemy Horton { 352bda68ab9SRemy Horton return rte_eth_dev_vlan_filter(port_id, vid, 0); 353bda68ab9SRemy Horton } 354bda68ab9SRemy Horton 355bda68ab9SRemy Horton /* 356bda68ab9SRemy Horton * The set_rx_mode provides driver-specific rx mode setting. 357bda68ab9SRemy Horton * This implementation implements rx mode setting based upon 358bda68ab9SRemy Horton * ixgbe/igb drivers. Further improvement is to provide a 359bda68ab9SRemy Horton * callback op field over struct rte_eth_dev::dev_ops so each 360bda68ab9SRemy Horton * driver can register device-specific implementation 361bda68ab9SRemy Horton */ 362bda68ab9SRemy Horton int 36347523597SZhiyong Yang rte_ethtool_net_set_rx_mode(uint16_t port_id) 364bda68ab9SRemy Horton { 365bda68ab9SRemy Horton uint16_t num_vfs; 366bda68ab9SRemy Horton struct rte_eth_dev_info dev_info; 367bda68ab9SRemy Horton uint16_t vf; 368089e5ed7SIvan Ilchenko int ret; 369bda68ab9SRemy Horton 370089e5ed7SIvan Ilchenko ret = rte_eth_dev_info_get(port_id, &dev_info); 371089e5ed7SIvan Ilchenko if (ret != 0) 372089e5ed7SIvan Ilchenko return ret; 373089e5ed7SIvan Ilchenko 374bda68ab9SRemy Horton num_vfs = dev_info.max_vfs; 375bda68ab9SRemy Horton 376bda68ab9SRemy Horton /* Set VF vf_rx_mode, VF unsupport status is discard */ 377077d223eSBernard Iremonger for (vf = 0; vf < num_vfs; vf++) { 378a8d0d473SBruce Richardson #ifdef RTE_NET_IXGBE 379077d223eSBernard Iremonger rte_pmd_ixgbe_set_vf_rxmode(port_id, vf, 380295968d1SFerruh Yigit RTE_ETH_VMDQ_ACCEPT_UNTAG, 0); 381077d223eSBernard Iremonger #endif 382077d223eSBernard Iremonger } 383bda68ab9SRemy Horton 3847be78d02SJosh Soref /* Enable Rx vlan filter, VF unsupported status is discard */ 385295968d1SFerruh Yigit ret = rte_eth_dev_set_vlan_offload(port_id, RTE_ETH_VLAN_FILTER_MASK); 386899f6de2SGargi Sau if (ret != 0) 387899f6de2SGargi Sau return ret; 388bda68ab9SRemy Horton 389bda68ab9SRemy Horton return 0; 390bda68ab9SRemy Horton } 391bda68ab9SRemy Horton 392bda68ab9SRemy Horton 393bda68ab9SRemy Horton int 39447523597SZhiyong Yang rte_ethtool_get_ringparam(uint16_t port_id, 395bda68ab9SRemy Horton struct ethtool_ringparam *ring_param) 396bda68ab9SRemy Horton { 397bda68ab9SRemy Horton struct rte_eth_dev_info dev_info; 398bda68ab9SRemy Horton struct rte_eth_rxq_info rx_qinfo; 399bda68ab9SRemy Horton struct rte_eth_txq_info tx_qinfo; 400bda68ab9SRemy Horton int stat; 401089e5ed7SIvan Ilchenko int ret; 402bda68ab9SRemy Horton 403bda68ab9SRemy Horton if (ring_param == NULL) 404bda68ab9SRemy Horton return -EINVAL; 405bda68ab9SRemy Horton 406089e5ed7SIvan Ilchenko ret = rte_eth_dev_info_get(port_id, &dev_info); 407089e5ed7SIvan Ilchenko if (ret != 0) 408089e5ed7SIvan Ilchenko return ret; 409bda68ab9SRemy Horton 410bda68ab9SRemy Horton stat = rte_eth_rx_queue_info_get(port_id, 0, &rx_qinfo); 411bda68ab9SRemy Horton if (stat != 0) 412bda68ab9SRemy Horton return stat; 413bda68ab9SRemy Horton 414bda68ab9SRemy Horton stat = rte_eth_tx_queue_info_get(port_id, 0, &tx_qinfo); 415bda68ab9SRemy Horton if (stat != 0) 416bda68ab9SRemy Horton return stat; 417bda68ab9SRemy Horton 418bda68ab9SRemy Horton memset(ring_param, 0, sizeof(*ring_param)); 419bda68ab9SRemy Horton ring_param->rx_pending = rx_qinfo.nb_desc; 420bda68ab9SRemy Horton ring_param->rx_max_pending = dev_info.rx_desc_lim.nb_max; 421bda68ab9SRemy Horton ring_param->tx_pending = tx_qinfo.nb_desc; 422bda68ab9SRemy Horton ring_param->tx_max_pending = dev_info.tx_desc_lim.nb_max; 423bda68ab9SRemy Horton 424bda68ab9SRemy Horton return 0; 425bda68ab9SRemy Horton } 426bda68ab9SRemy Horton 427bda68ab9SRemy Horton 428bda68ab9SRemy Horton int 42947523597SZhiyong Yang rte_ethtool_set_ringparam(uint16_t port_id, 430bda68ab9SRemy Horton struct ethtool_ringparam *ring_param) 431bda68ab9SRemy Horton { 432bda68ab9SRemy Horton struct rte_eth_rxq_info rx_qinfo; 433bda68ab9SRemy Horton int stat; 434bda68ab9SRemy Horton 435bda68ab9SRemy Horton if (ring_param == NULL) 436bda68ab9SRemy Horton return -EINVAL; 437bda68ab9SRemy Horton 438bda68ab9SRemy Horton stat = rte_eth_rx_queue_info_get(port_id, 0, &rx_qinfo); 439bda68ab9SRemy Horton if (stat != 0) 440bda68ab9SRemy Horton return stat; 441bda68ab9SRemy Horton 442b55efbabSIvan Ilchenko stat = rte_eth_dev_stop(port_id); 443b55efbabSIvan Ilchenko if (stat != 0) 444b55efbabSIvan Ilchenko return stat; 445bda68ab9SRemy Horton 446bda68ab9SRemy Horton stat = rte_eth_tx_queue_setup(port_id, 0, ring_param->tx_pending, 4474199ce15SChengwen Feng rte_eth_dev_socket_id(port_id), NULL); 448bda68ab9SRemy Horton if (stat != 0) 449bda68ab9SRemy Horton return stat; 450bda68ab9SRemy Horton 451bda68ab9SRemy Horton stat = rte_eth_rx_queue_setup(port_id, 0, ring_param->rx_pending, 4524199ce15SChengwen Feng rte_eth_dev_socket_id(port_id), NULL, rx_qinfo.mp); 453bda68ab9SRemy Horton if (stat != 0) 454bda68ab9SRemy Horton return stat; 455bda68ab9SRemy Horton 456bda68ab9SRemy Horton return rte_eth_dev_start(port_id); 457bda68ab9SRemy Horton } 458