From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 084868D91 for ; Wed, 30 Sep 2015 08:18:56 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP; 29 Sep 2015 23:18:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,611,1437462000"; d="scan'208";a="816032267" Received: from rhorton-mobl.ger.corp.intel.com (HELO localhost.ir.intel.com) ([163.33.229.80]) by orsmga002.jf.intel.com with ESMTP; 29 Sep 2015 23:18:55 -0700 From: Remy Horton To: dev@dpdk.org Date: Wed, 30 Sep 2015 07:18:49 +0100 Message-Id: <1443593929-1804-3-git-send-email-remy.horton@intel.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1443593929-1804-1-git-send-email-remy.horton@intel.com> References: <1443593929-1804-1-git-send-email-remy.horton@intel.com> Subject: [dpdk-dev] [PATCH v1 2/2] User-space ethtool sample application X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Sep 2015 06:18:58 -0000 Further enhancements to the userspace ethtool implementation that was submitted in 2.1 and packaged as a self-contained sample application. Implements an internal rte_ethtool shim layer based on rte_ethdev API, along with a command prompt driven demonstration application. Signed-off-by: Remy Horton --- examples/l2fwd/Makefile | 2 +- examples/l2fwd/ethapp.c | 792 +++++++++++++++++++++++++++++++++++++++++++ examples/l2fwd/ethapp.h | 38 +++ examples/l2fwd/main.c | 19 +- examples/l2fwd/rte_ethtool.c | 354 +++++++++++++++++++ examples/l2fwd/rte_ethtool.h | 371 ++++++++++++++++++++ 6 files changed, 1570 insertions(+), 6 deletions(-) create mode 100644 examples/l2fwd/ethapp.c create mode 100644 examples/l2fwd/ethapp.h create mode 100644 examples/l2fwd/rte_ethtool.c create mode 100644 examples/l2fwd/rte_ethtool.h diff --git a/examples/l2fwd/Makefile b/examples/l2fwd/Makefile index 78feeeb..90e7512 100644 --- a/examples/l2fwd/Makefile +++ b/examples/l2fwd/Makefile @@ -42,7 +42,7 @@ include $(RTE_SDK)/mk/rte.vars.mk APP = l2fwd # all source are stored in SRCS-y -SRCS-y := main.c +SRCS-y := main.c ethapp.c rte_ethtool.c CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) diff --git a/examples/l2fwd/ethapp.c b/examples/l2fwd/ethapp.c new file mode 100644 index 0000000..90e0399 --- /dev/null +++ b/examples/l2fwd/ethapp.c @@ -0,0 +1,792 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2015 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include + +#include "rte_ethtool.h" +#include "ethapp.h" + +#define EEPROM_DUMP_CHUNKSIZE 1024 + + +struct pcmd_get_params { + cmdline_fixed_string_t cmd; +}; +struct pcmd_int_params { + cmdline_fixed_string_t cmd; + uint16_t port; +}; +struct pcmd_intstr_params { + cmdline_fixed_string_t cmd; + uint16_t port; + cmdline_fixed_string_t opt; +}; +struct pcmd_intmac_params { + cmdline_fixed_string_t cmd; + uint16_t port; + struct ether_addr mac; +}; +struct pcmd_str_params { + cmdline_fixed_string_t cmd; + cmdline_fixed_string_t opt; +}; +struct pcmd_vlan_params { + cmdline_fixed_string_t cmd; + uint16_t port; + cmdline_fixed_string_t mode; + uint16_t vid; +}; + + +/* Parameter-less commands */ +cmdline_parse_token_string_t pcmd_quit_token_cmd = + TOKEN_STRING_INITIALIZER(struct pcmd_get_params, cmd, "quit"); +cmdline_parse_token_string_t pcmd_stats_token_cmd = + TOKEN_STRING_INITIALIZER(struct pcmd_get_params, cmd, "stats"); +cmdline_parse_token_string_t pcmd_drvinfo_token_cmd = + TOKEN_STRING_INITIALIZER(struct pcmd_get_params, cmd, "drvinfo"); +cmdline_parse_token_string_t pcmd_link_token_cmd = + TOKEN_STRING_INITIALIZER(struct pcmd_get_params, cmd, "link"); + +/* Commands taking just port id */ +cmdline_parse_token_string_t pcmd_open_token_cmd = + TOKEN_STRING_INITIALIZER(struct pcmd_int_params, cmd, "open"); +cmdline_parse_token_string_t pcmd_stop_token_cmd = + TOKEN_STRING_INITIALIZER(struct pcmd_int_params, cmd, "stop"); +cmdline_parse_token_string_t pcmd_rxmode_token_cmd = + TOKEN_STRING_INITIALIZER(struct pcmd_int_params, cmd, "rxmode"); +cmdline_parse_token_string_t pcmd_portstats_token_cmd = + TOKEN_STRING_INITIALIZER(struct pcmd_int_params, cmd, "portstats"); + +cmdline_parse_token_num_t pcmd_int_token_port = + TOKEN_NUM_INITIALIZER(struct pcmd_int_params, port, UINT16); + +/* Commands taking port id and string */ +cmdline_parse_token_string_t pcmd_eeprom_token_cmd = + TOKEN_STRING_INITIALIZER(struct pcmd_intstr_params, cmd, "eeprom"); +cmdline_parse_token_string_t pcmd_mtu_token_cmd = + TOKEN_STRING_INITIALIZER(struct pcmd_intstr_params, cmd, "mtu"); +cmdline_parse_token_string_t pcmd_regs_token_cmd = + TOKEN_STRING_INITIALIZER(struct pcmd_intstr_params, cmd, "regs"); + +cmdline_parse_token_num_t pcmd_intstr_token_port = + TOKEN_NUM_INITIALIZER(struct pcmd_intstr_params, port, UINT16); +cmdline_parse_token_string_t pcmd_intstr_token_opt = + TOKEN_STRING_INITIALIZER(struct pcmd_intstr_params, opt, NULL); + +/* Commands taking port id and a MAC address string */ +cmdline_parse_token_string_t pcmd_macaddr_token_cmd = + TOKEN_STRING_INITIALIZER(struct pcmd_intmac_params, cmd, "macaddr"); +cmdline_parse_token_num_t pcmd_intmac_token_port = + TOKEN_NUM_INITIALIZER(struct pcmd_intmac_params, port, UINT16); +cmdline_parse_token_etheraddr_t pcmd_intmac_token_mac = + TOKEN_ETHERADDR_INITIALIZER(struct pcmd_intmac_params, mac); + +/* Command taking just a MAC address */ +cmdline_parse_token_string_t pcmd_validate_token_cmd = + TOKEN_STRING_INITIALIZER(struct pcmd_intmac_params, cmd, "validate"); + +/* Pause commands */ +cmdline_parse_token_string_t pcmd_pause_token_cmd = + TOKEN_STRING_INITIALIZER(struct pcmd_intstr_params, cmd, "pause"); +cmdline_parse_token_num_t pcmd_pause_token_port = + TOKEN_NUM_INITIALIZER(struct pcmd_intstr_params, port, UINT16); +cmdline_parse_token_string_t pcmd_pause_token_opt = + TOKEN_STRING_INITIALIZER(struct pcmd_intstr_params, + opt, "all#tx#rx#none"); + +/* VLAN commands */ +cmdline_parse_token_string_t pcmd_vlan_token_cmd = + TOKEN_STRING_INITIALIZER(struct pcmd_vlan_params, cmd, "vlan"); +cmdline_parse_token_num_t pcmd_vlan_token_port = + TOKEN_NUM_INITIALIZER(struct pcmd_vlan_params, port, UINT16); +cmdline_parse_token_string_t pcmd_vlan_token_mode = + TOKEN_STRING_INITIALIZER(struct pcmd_vlan_params, mode, "add#del"); +cmdline_parse_token_num_t pcmd_vlan_token_vid = + TOKEN_NUM_INITIALIZER(struct pcmd_vlan_params, vid, UINT16); + + +static void +pcmd_quit_callback(__attribute__((unused)) void *ptr_params, + struct cmdline *ctx, + __attribute__((unused)) void *ptr_data) +{ + cmdline_quit(ctx); +} + + +static void +pcmd_stats_callback(__attribute__((unused)) void *ptr_params, + __attribute__((unused)) struct cmdline *ctx, + __attribute__((unused)) void *ptr_data) +{ + print_stats(); +} + + +static void +pcmd_drvinfo_callback(__attribute__((unused)) void *ptr_params, + __attribute__((unused)) struct cmdline *ctx, + __attribute__((unused)) void *ptr_data) +{ + struct ethtool_drvinfo info; + int id_port; + + for (id_port = 0; id_port < rte_eth_dev_count(); id_port++) { + if (rte_ethtool_get_drvinfo(id_port, &info)) { + printf("Error getting info for port %i\n", id_port); + return; + } + printf("Port %i driver: %s (ver: %s)\n", + id_port, info.driver, info.version + ); + } +} + + +static void +pcmd_link_callback(__attribute__((unused)) void *ptr_params, + __attribute__((unused)) struct cmdline *ctx, + __attribute__((unused)) void *ptr_data) +{ + int num_ports = rte_eth_dev_count(); + int id_port, stat_port; + + for (id_port = 0; id_port < num_ports; id_port++) { + if (!rte_eth_dev_is_valid_port(id_port)) + continue; + stat_port = rte_ethtool_get_link(id_port); + switch (stat_port) { + case 0: + printf("Port %i: Down\n", id_port); + break; + case 1: + printf("Port %i: Up\n", id_port); + break; + default: + printf("Port %i: Error getting link status\n", + id_port + ); + break; + } + } + printf("\n"); +} + + +static void +pcmd_regs_callback(void *ptr_params, + __attribute__((unused)) struct cmdline *ctx, + __attribute__((unused)) void *ptr_data) +{ + struct pcmd_intstr_params *params = ptr_params; + int len_regs; + struct ethtool_regs regs; + unsigned char *buf_data; + FILE *fp_regs; + + if (!rte_eth_dev_is_valid_port(params->port)) { + printf("Error: Invalid port number %i\n", params->port); + return; + } + len_regs = rte_ethtool_get_regs_len(params->port); + if (len_regs > 0) { + printf("Port %i: %i bytes\n", params->port, len_regs); + buf_data = malloc(len_regs); + if (buf_data == NULL) { + printf("Error allocating %i bytes for buffer\n", + len_regs); + return; + } + if (!rte_ethtool_get_regs(params->port, ®s, buf_data)) { + fp_regs = fopen(params->opt, "wb"); + if (fp_regs == NULL) { + printf("Error opening '%s' for writing\n", + params->opt); + } else { + if ((int)fwrite(buf_data, + 1, len_regs, + fp_regs) != len_regs) + printf("Error writing '%s'\n", + params->opt); + fclose(fp_regs); + } + } + free(buf_data); + } else if (len_regs == -ENOTSUP) + printf("Port %i: Operation not supported\n", params->port); + else + printf("Port %i: Error getting registers\n", params->port); +} + + +static void +pcmd_eeprom_callback(void *ptr_params, + __attribute__((unused)) struct cmdline *ctx, + __attribute__((unused)) void *ptr_data) +{ + struct pcmd_intstr_params *params = ptr_params; + struct ethtool_eeprom info_eeprom; + int len_eeprom; + int pos_eeprom; + int stat; + unsigned char bytes_eeprom[EEPROM_DUMP_CHUNKSIZE]; + FILE *fp_eeprom; + + if (!rte_eth_dev_is_valid_port(params->port)) { + printf("Error: Invalid port number %i\n", params->port); + return; + } + len_eeprom = rte_ethtool_get_eeprom_len(params->port); + if (len_eeprom > 0) { + fp_eeprom = fopen(params->opt, "wb"); + if (fp_eeprom == NULL) { + printf("Error opening '%s' for writing\n", + params->opt); + return; + } + printf("Total EEPROM length: %i bytes\n", len_eeprom); + info_eeprom.len = EEPROM_DUMP_CHUNKSIZE; + for (pos_eeprom = 0; + pos_eeprom < len_eeprom; + pos_eeprom += EEPROM_DUMP_CHUNKSIZE) { + info_eeprom.offset = pos_eeprom; + if (pos_eeprom + EEPROM_DUMP_CHUNKSIZE > len_eeprom) + info_eeprom.len = len_eeprom - pos_eeprom; + else + info_eeprom.len = EEPROM_DUMP_CHUNKSIZE; + stat = rte_ethtool_get_eeprom( + params->port, &info_eeprom, bytes_eeprom + ); + if (stat != 0) { + printf("EEPROM read error %i\n", stat); + break; + } + if (fwrite(bytes_eeprom, + 1, info_eeprom.len, + fp_eeprom) != info_eeprom.len) { + printf("Error writing '%s'\n", params->opt); + break; + } + } + fclose(fp_eeprom); + } else if (len_eeprom == 0) + printf("Port %i: Device does not have EEPROM\n", params->port); + else if (len_eeprom == -ENOTSUP) + printf("Port %i: Operation not supported\n", params->port); + else + printf("Port %i: Error getting EEPROM\n", params->port); +} + + +static void +pcmd_pause_callback(void *ptr_params, + __attribute__((unused)) struct cmdline *ctx, + void *ptr_data) +{ + struct pcmd_intstr_params *params = ptr_params; + struct ethtool_pauseparam info; + int stat; + + if (!rte_eth_dev_is_valid_port(params->port)) { + printf("Error: Invalid port number %i\n", params->port); + return; + } + if (ptr_data != NULL) { + stat = rte_ethtool_get_pauseparam(params->port, &info); + } else { + if (strcasecmp("all", params->opt) == 0) { + info.tx_pause = 1; + info.rx_pause = 1; + } else if (strcasecmp("tx", params->opt) == 0) { + info.tx_pause = 1; + info.rx_pause = 0; + } else if (strcasecmp("rx", params->opt) == 0) { + info.tx_pause = 0; + info.rx_pause = 1; + } else { + info.tx_pause = 0; + info.rx_pause = 0; + } + stat = rte_ethtool_set_pauseparam(params->port, &info); + } + if (stat == 0) { + if (info.rx_pause && info.tx_pause) + printf("Port %i: Tx & Rx Paused\n", params->port); + else if (info.rx_pause) + printf("Port %i: Rx Paused\n", params->port); + else if (info.tx_pause) + printf("Port %i: Tx Paused\n", params->port); + else + printf("Port %i: Tx & Rx not paused\n", params->port); + } else if (stat == -ENOTSUP) + printf("Port %i: Operation not supported\n", params->port); + else + printf("Port %i: Error %i\n", params->port, stat); +} + + +static void +pcmd_open_callback(__attribute__((unused)) void *ptr_params, + __attribute__((unused)) struct cmdline *ctx, + __attribute__((unused)) void *ptr_data) +{ + struct pcmd_int_params *params = ptr_params; + int stat; + + if (!rte_eth_dev_is_valid_port(params->port)) { + printf("Error: Invalid port number %i\n", params->port); + return; + } + stat = rte_ethtool_net_open(params->port); + if (stat == 0) + return; + else if (stat == -ENOTSUP) + printf("Port %i: Operation not supported\n", params->port); + else + printf("Port %i: Error opening device\n", params->port); +} + +static void +pcmd_stop_callback(__attribute__((unused)) void *ptr_params, + __attribute__((unused)) struct cmdline *ctx, + __attribute__((unused)) void *ptr_data) +{ + struct pcmd_int_params *params = ptr_params; + int stat; + + if (!rte_eth_dev_is_valid_port(params->port)) { + printf("Error: Invalid port number %i\n", params->port); + return; + } + stat = rte_ethtool_net_stop(params->port); + if (stat == 0) + return; + else if (stat == -ENOTSUP) + printf("Port %i: Operation not supported\n", params->port); + else + printf("Port %i: Error stopping device\n", params->port); +} + + +static void +pcmd_rxmode_callback(void *ptr_params, + __attribute__((unused)) struct cmdline *ctx, + __attribute__((unused)) void *ptr_data) +{ + struct pcmd_intstr_params *params = ptr_params; + int stat; + + if (!rte_eth_dev_is_valid_port(params->port)) { + printf("Error: Invalid port number %i\n", params->port); + return; + } + stat = rte_ethtool_net_set_rx_mode(params->port); + if (stat == 0) + return; + else if (stat == -ENOTSUP) + printf("Port %i: Operation not supported\n", params->port); + else + printf("Port %i: Error setting rx mode\n", params->port); +} + + +static void +pcmd_macaddr_callback(void *ptr_params, + __attribute__((unused)) struct cmdline *ctx, + void *ptr_data) +{ + struct pcmd_intmac_params *params = ptr_params; + struct ether_addr mac_addr; + int stat; + + stat = 0; + if (!rte_eth_dev_is_valid_port(params->port)) { + printf("Error: Invalid port number %i\n", params->port); + return; + } + if (ptr_data != NULL) { + stat = rte_ethtool_net_set_mac_addr(params->port, + ¶ms->mac); + if (stat == 0) { + printf("MAC address changed\n"); + return; + } + } else { + stat = rte_ethtool_net_get_mac_addr(params->port, &mac_addr); + if (stat == 0) { + printf( + "Port %i MAC Address: %02x:%02x:%02x:%02x:%02x:%02x\n", + params->port, + mac_addr.addr_bytes[0], + mac_addr.addr_bytes[1], + mac_addr.addr_bytes[2], + mac_addr.addr_bytes[3], + mac_addr.addr_bytes[4], + mac_addr.addr_bytes[5]); + return; + } + } + if (stat == 0) + return; + else if (stat == -ENOTSUP) + printf("Port %i: Operation not supported\n", params->port); + else + printf("Port %i: Error %i\n", params->port, stat); +} + +static void +pcmd_mtu_callback(void *ptr_params, + __attribute__((unused)) struct cmdline *ctx, + __attribute__((unused)) void *ptr_data) +{ + struct pcmd_intstr_params *params = ptr_params; + int stat; + int new_mtu; + char *ptr_parse_end; + + if (!rte_eth_dev_is_valid_port(params->port)) { + printf("Error: Invalid port number %i\n", params->port); + return; + } + new_mtu = atoi(params->opt); + new_mtu = strtoul(params->opt, &ptr_parse_end, 10); + if (*ptr_parse_end != '\0' || + new_mtu < ETHER_MIN_MTU || + new_mtu > ETHER_MAX_VLAN_FRAME_LEN) { + printf("Port %i: Invalid MTU value\n", params->port); + return; + } + stat = rte_ethtool_net_change_mtu(params->port, new_mtu); + if (stat == 0) + printf("Port %i: MTU set to %i\n", params->port, new_mtu); + else if (stat == -ENOTSUP) + printf("Port %i: Operation not supported\n", params->port); + else + printf("Port %i: Error setting MTU\n", params->port); +} + + + +static void pcmd_portstats_callback(__attribute__((unused)) void *ptr_params, + __attribute__((unused)) struct cmdline *ctx, + __attribute__((unused)) void *ptr_data) +{ + struct pcmd_int_params *params = ptr_params; + struct rte_eth_stats stat_info; + int stat; + + if (!rte_eth_dev_is_valid_port(params->port)) { + printf("Error: Invalid port number %i\n", params->port); + return; + } + stat = rte_ethtool_net_get_stats64(params->port, &stat_info); + if (stat == 0) { + /* Most of rte_eth_stats is deprecated.. */ + printf("Port %i stats\n", params->port); + printf(" In: %" PRIu64 " (%" PRIu64 " bytes)\n" + " Out: %"PRIu64" (%"PRIu64 " bytes)\n" + " Err: %"PRIu64"\n", + stat_info.ipackets, + stat_info.ibytes, + stat_info.opackets, + stat_info.obytes, + stat_info.ierrors+stat_info.oerrors + ); + } else if (stat == -ENOTSUP) + printf("Port %i: Operation not supported\n", params->port); + else + printf("Port %i: Error fetching statistics\n", params->port); +} + + +static void pcmd_validate_callback(void *ptr_params, + __attribute__((unused)) struct cmdline *ctx, + __attribute__((unused)) void *ptr_data) +{ + struct pcmd_intmac_params *params = ptr_params; + + if (rte_ethtool_net_validate_addr(0, ¶ms->mac)) + printf("Address is unicast\n"); + else + printf("Address is not unicast\n"); +} + + +static void pcmd_vlan_callback(__attribute__((unused)) void *ptr_params, + __attribute__((unused)) struct cmdline *ctx, + __attribute__((unused)) void *ptr_data) +{ + struct pcmd_vlan_params *params = ptr_params; + int stat; + + if (!rte_eth_dev_is_valid_port(params->port)) { + printf("Error: Invalid port number %i\n", params->port); + return; + } + stat = 0; + + if (strcasecmp("add", params->mode) == 0) { + stat = rte_ethtool_net_vlan_rx_add_vid( + params->port, params->vid + ); + if (stat == 0) + printf("VLAN vid %i added\n", params->vid); + + } else if (strcasecmp("del", params->mode) == 0) { + stat = rte_ethtool_net_vlan_rx_kill_vid( + params->port, params->vid + ); + if (stat == 0) + printf("VLAN vid %i removed\n", params->vid); + } else { + /* Should not happen! */ + printf("Error: Bad mode %s\n", params->mode); + } + if (stat == -ENOTSUP) + printf("Port %i: Operation not supported\n", params->port); + else if (stat == -ENOSYS) + printf("Port %i: VLAN filtering disabled\n", params->port); + else if (stat != 0) + printf("Port %i: Error changing VLAN setup (code %i)\n", + params->port, -stat); +} + + +cmdline_parse_inst_t pcmd_quit = { + .f = pcmd_quit_callback, + .data = NULL, + .help_str = "quit\n Exit program", + .tokens = {(void *)&pcmd_quit_token_cmd, NULL}, +}; +cmdline_parse_inst_t pcmd_stats = { + .f = pcmd_stats_callback, + .data = NULL, + .help_str = "stats\n Print l2fwd stats", + .tokens = {(void *)&pcmd_stats_token_cmd, NULL}, +}; +cmdline_parse_inst_t pcmd_drvinfo = { + .f = pcmd_drvinfo_callback, + .data = NULL, + .help_str = "drvinfo\n Print driver info", + .tokens = {(void *)&pcmd_drvinfo_token_cmd, NULL}, +}; +cmdline_parse_inst_t pcmd_link = { + .f = pcmd_link_callback, + .data = NULL, + .help_str = "link\n Print port link states", + .tokens = {(void *)&pcmd_link_token_cmd, NULL}, +}; +cmdline_parse_inst_t pcmd_regs = { + .f = pcmd_regs_callback, + .data = NULL, + .help_str = "regs \n" + " Dump port register(s) to file", + .tokens = { + (void *)&pcmd_regs_token_cmd, + (void *)&pcmd_intstr_token_port, + (void *)&pcmd_intstr_token_opt, + NULL + }, +}; +cmdline_parse_inst_t pcmd_eeprom = { + .f = pcmd_eeprom_callback, + .data = NULL, + .help_str = "eeprom \n Dump EEPROM to file", + .tokens = { + (void *)&pcmd_eeprom_token_cmd, + (void *)&pcmd_intstr_token_port, + (void *)&pcmd_intstr_token_opt, + NULL + }, +}; +cmdline_parse_inst_t pcmd_pause_noopt = { + .f = pcmd_pause_callback, + .data = (void *)0x01, + .help_str = "pause \n Print port pause state", + .tokens = { + (void *)&pcmd_pause_token_cmd, + (void *)&pcmd_pause_token_port, + NULL + }, +}; +cmdline_parse_inst_t pcmd_pause = { + .f = pcmd_pause_callback, + .data = NULL, + .help_str = + "pause \n Pause/unpause port", + .tokens = { + (void *)&pcmd_pause_token_cmd, + (void *)&pcmd_pause_token_port, + (void *)&pcmd_pause_token_opt, + NULL + }, +}; +cmdline_parse_inst_t pcmd_open = { + .f = pcmd_open_callback, + .data = NULL, + .help_str = "open \n Open port", + .tokens = { + (void *)&pcmd_open_token_cmd, + (void *)&pcmd_int_token_port, + NULL + }, +}; +cmdline_parse_inst_t pcmd_stop = { + .f = pcmd_stop_callback, + .data = NULL, + .help_str = "stop \n Stop port", + .tokens = { + (void *)&pcmd_stop_token_cmd, + (void *)&pcmd_int_token_port, + NULL + }, +}; +cmdline_parse_inst_t pcmd_rxmode = { + .f = pcmd_rxmode_callback, + .data = NULL, + .help_str = "rxmode \n Toggle port Rx mode", + .tokens = { + (void *)&pcmd_rxmode_token_cmd, + (void *)&pcmd_int_token_port, + NULL + }, +}; +cmdline_parse_inst_t pcmd_macaddr_get = { + .f = pcmd_macaddr_callback, + .data = NULL, + .help_str = "macaddr \n" + " Get MAC address", + .tokens = { + (void *)&pcmd_macaddr_token_cmd, + (void *)&pcmd_intstr_token_port, + NULL + }, +}; +cmdline_parse_inst_t pcmd_macaddr = { + .f = pcmd_macaddr_callback, + .data = (void *)0x01, + .help_str = + "macaddr \n" + " Set MAC address", + .tokens = { + (void *)&pcmd_macaddr_token_cmd, + (void *)&pcmd_intmac_token_port, + (void *)&pcmd_intmac_token_mac, + NULL + }, +}; +cmdline_parse_inst_t pcmd_mtu = { + .f = pcmd_mtu_callback, + .data = NULL, + .help_str = "mtu \n" + " Change MTU", + .tokens = { + (void *)&pcmd_mtu_token_cmd, + (void *)&pcmd_intstr_token_port, + (void *)&pcmd_intstr_token_opt, + NULL + }, +}; +cmdline_parse_inst_t pcmd_portstats = { + .f = pcmd_portstats_callback, + .data = NULL, + .help_str = "portstats \n" + " Print port eth statistics", + .tokens = { + (void *)&pcmd_portstats_token_cmd, + (void *)&pcmd_int_token_port, + NULL + }, +}; +cmdline_parse_inst_t pcmd_validate = { + .f = pcmd_validate_callback, + .data = NULL, + .help_str = "validate \n" + " Check that MAC address is valid unicast address", + .tokens = { + (void *)&pcmd_validate_token_cmd, + (void *)&pcmd_intmac_token_mac, + NULL + }, +}; +cmdline_parse_inst_t pcmd_vlan = { + .f = pcmd_vlan_callback, + .data = NULL, + .help_str = "vlan \n" + " Add/remove VLAN id", + .tokens = { + (void *)&pcmd_vlan_token_cmd, + (void *)&pcmd_vlan_token_port, + (void *)&pcmd_vlan_token_mode, + (void *)&pcmd_vlan_token_vid, + NULL + }, +}; + + +cmdline_parse_ctx_t list_prompt_commands[] = { + (cmdline_parse_inst_t *)&pcmd_drvinfo, + (cmdline_parse_inst_t *)&pcmd_eeprom, + (cmdline_parse_inst_t *)&pcmd_link, + (cmdline_parse_inst_t *)&pcmd_macaddr_get, + (cmdline_parse_inst_t *)&pcmd_macaddr, + (cmdline_parse_inst_t *)&pcmd_mtu, + (cmdline_parse_inst_t *)&pcmd_open, + (cmdline_parse_inst_t *)&pcmd_pause_noopt, + (cmdline_parse_inst_t *)&pcmd_pause, + (cmdline_parse_inst_t *)&pcmd_portstats, + (cmdline_parse_inst_t *)&pcmd_regs, + (cmdline_parse_inst_t *)&pcmd_rxmode, + (cmdline_parse_inst_t *)&pcmd_stats, + (cmdline_parse_inst_t *)&pcmd_stop, + (cmdline_parse_inst_t *)&pcmd_validate, + (cmdline_parse_inst_t *)&pcmd_vlan, + (cmdline_parse_inst_t *)&pcmd_quit, + NULL +}; + + +void ethapp_main(void) +{ + struct cmdline *ctx_cmdline; + + ctx_cmdline = cmdline_stdin_new(list_prompt_commands, "EthApp> "); + cmdline_interact(ctx_cmdline); + cmdline_stdin_exit(ctx_cmdline); +} diff --git a/examples/l2fwd/ethapp.h b/examples/l2fwd/ethapp.h new file mode 100644 index 0000000..045922b --- /dev/null +++ b/examples/l2fwd/ethapp.h @@ -0,0 +1,38 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2015 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +void ethapp_main(void); +void print_stats(void); + + diff --git a/examples/l2fwd/main.c b/examples/l2fwd/main.c index 2f0841d..82698f0 100644 --- a/examples/l2fwd/main.c +++ b/examples/l2fwd/main.c @@ -68,6 +68,8 @@ #include #include +#include "ethapp.h" + #define RTE_LOGTYPE_L2FWD RTE_LOGTYPE_USER1 #define NB_MBUF 8192 @@ -94,6 +96,8 @@ static uint32_t l2fwd_dst_ports[RTE_MAX_ETHPORTS]; static unsigned int l2fwd_rx_queue_per_lcore = 1; +static int l2fwd_main_running = 1; + struct mbuf_table { unsigned len; struct rte_mbuf *m_table[MAX_PKT_BURST]; @@ -138,9 +142,8 @@ struct l2fwd_port_statistics port_statistics[RTE_MAX_ETHPORTS]; #define MAX_TIMER_PERIOD 86400 /* 1 day max */ static int64_t timer_period = 10 * TIMER_MILLISECOND * 1000; /* default period is 10 seconds */ - /* Print out statistics on packets dropped */ -static void +void print_stats(void) { uint64_t total_packets_dropped, total_packets_tx, total_packets_rx; @@ -284,7 +287,7 @@ l2fwd_main_loop(void) portid); } - while (1) { + while (l2fwd_main_running) { cur_tsc = rte_rdtsc(); @@ -603,7 +606,8 @@ main(int argc, char **argv) l2fwd_dst_ports[last_port] = last_port; } - rx_lcore_id = 0; + /* Note: core id 0 (master) reserved for ethapp */ + rx_lcore_id = 1; qconf = NULL; /* Initialize the port/queue configuration of each logical core */ @@ -706,7 +710,12 @@ main(int argc, char **argv) check_all_ports_link_status(nb_ports, l2fwd_enabled_port_mask); /* launch per-lcore init on every lcore */ - rte_eal_mp_remote_launch(l2fwd_launch_one_lcore, NULL, CALL_MASTER); + rte_eal_mp_remote_launch(l2fwd_launch_one_lcore, NULL, SKIP_MASTER); + + /* launch ethtool sample on master core */ + ethapp_main(); + + l2fwd_main_running = 0; RTE_LCORE_FOREACH_SLAVE(lcore_id) { if (rte_eal_wait_lcore(lcore_id) < 0) return -1; diff --git a/examples/l2fwd/rte_ethtool.c b/examples/l2fwd/rte_ethtool.c new file mode 100644 index 0000000..183fb20 --- /dev/null +++ b/examples/l2fwd/rte_ethtool.c @@ -0,0 +1,354 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2010-2015 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include +#include +#include +#include +#include +#include "rte_ethtool.h" + +int +rte_ethtool_get_drvinfo(uint8_t port_id, struct ethtool_drvinfo *drvinfo) +{ + struct rte_eth_dev_info dev_info; + int n; + + if (drvinfo == NULL) + return -EINVAL; + + if (!rte_eth_dev_is_valid_port(port_id)) + return -ENODEV; + + memset(&dev_info, 0, sizeof(dev_info)); + rte_eth_dev_info_get(port_id, &dev_info); + + snprintf(drvinfo->driver, sizeof(drvinfo->driver), "%s", + dev_info.driver_name); + snprintf(drvinfo->version, sizeof(drvinfo->version), "%s", + rte_version()); + snprintf(drvinfo->bus_info, sizeof(drvinfo->bus_info), + "%04x:%02x:%02x.%x", + dev_info.pci_dev->addr.domain, dev_info.pci_dev->addr.bus, + dev_info.pci_dev->addr.devid, dev_info.pci_dev->addr.function); + + n = rte_eth_dev_get_reg_length(port_id); + if (n > 0) + drvinfo->regdump_len = n; + else + drvinfo->regdump_len = 0; + + n = rte_eth_dev_get_eeprom_length(port_id); + if (n > 0) + drvinfo->eedump_len = n; + else + drvinfo->eedump_len = 0; + + drvinfo->n_stats = sizeof(struct rte_eth_stats) / sizeof(uint64_t); + drvinfo->testinfo_len = 0; + + return 0; +} + +int +rte_ethtool_get_regs_len(uint8_t port_id) +{ + int count_regs; + + count_regs = rte_eth_dev_get_reg_length(port_id); + if (count_regs > 0) + return count_regs * sizeof(uint32_t); + return count_regs; +} + +int +rte_ethtool_get_regs(uint8_t port_id, struct ethtool_regs *regs, void *data) +{ + struct rte_dev_reg_info reg_info; + int status; + + if (regs == NULL || data == NULL) + return -EINVAL; + + reg_info.data = data; + reg_info.length = 0; + + status = rte_eth_dev_get_reg_info(port_id, ®_info); + if (status) + return status; + regs->version = reg_info.version; + + return 0; +} + +int +rte_ethtool_get_link(uint8_t port_id) +{ + struct rte_eth_link link; + + if (!rte_eth_dev_is_valid_port(port_id)) + return -ENODEV; + rte_eth_link_get(port_id, &link); + return link.link_status; +} + +int +rte_ethtool_get_eeprom_len(uint8_t port_id) +{ + return rte_eth_dev_get_eeprom_length(port_id); +} + +int +rte_ethtool_get_eeprom(uint8_t port_id, struct ethtool_eeprom *eeprom, + void *words) +{ + struct rte_dev_eeprom_info eeprom_info; + int status; + + if (eeprom == NULL || words == NULL || eeprom->offset >= eeprom->len) + return -EINVAL; + + eeprom_info.offset = eeprom->offset; + eeprom_info.length = eeprom->len; + eeprom_info.data = words; + + status = rte_eth_dev_get_eeprom(port_id, &eeprom_info); + if (status) + return status; + + eeprom->magic = eeprom_info.magic; + + return 0; +} + +int +rte_ethtool_set_eeprom(uint8_t port_id, struct ethtool_eeprom *eeprom, + void *words) +{ + struct rte_dev_eeprom_info eeprom_info; + int status; + + if (eeprom == NULL || words == NULL || eeprom->offset >= eeprom->len) + return -EINVAL; + + eeprom_info.offset = eeprom->offset; + eeprom_info.length = eeprom->len; + eeprom_info.data = words; + + status = rte_eth_dev_set_eeprom(port_id, &eeprom_info); + if (status) + return status; + + eeprom->magic = eeprom_info.magic; + + return 0; +} + +int +rte_ethtool_get_pauseparam(uint8_t port_id, + struct ethtool_pauseparam *pause_param) +{ + struct rte_eth_fc_conf fc_conf; + int status; + + if (pause_param == NULL) + return -EINVAL; + + status = rte_eth_dev_flow_ctrl_get(port_id, &fc_conf); + if (status) + return status; + + pause_param->tx_pause = 0; + pause_param->rx_pause = 0; + switch (fc_conf.mode) { + case RTE_FC_RX_PAUSE: + pause_param->rx_pause = 1; + break; + case RTE_FC_TX_PAUSE: + pause_param->tx_pause = 1; + break; + case RTE_FC_FULL: + pause_param->rx_pause = 1; + pause_param->tx_pause = 1; + default: + /* dummy block to avoid compiler warning */ + break; + } + pause_param->autoneg = (uint32_t)fc_conf.autoneg; + + return 0; +} + +int +rte_ethtool_set_pauseparam(uint8_t port_id, + struct ethtool_pauseparam *pause_param) +{ + struct rte_eth_fc_conf fc_conf; + int status; + + if (pause_param == NULL) + return -EINVAL; + + /* + * Read device flow control parameter first since + * ethtool set_pauseparam op doesn't have all the information. + * as defined in struct rte_eth_fc_conf. + * This API requires the device to support both + * rte_eth_dev_flow_ctrl_get and rte_eth_dev_flow_ctrl_set, otherwise + * return -ENOTSUP + */ + status = rte_eth_dev_flow_ctrl_get(port_id, &fc_conf); + if (status) + return status; + + fc_conf.autoneg = (uint8_t)pause_param->autoneg; + + if (pause_param->tx_pause) { + if (pause_param->rx_pause) + fc_conf.mode = RTE_FC_FULL; + else + fc_conf.mode = RTE_FC_TX_PAUSE; + } else { + if (pause_param->rx_pause) + fc_conf.mode = RTE_FC_RX_PAUSE; + else + fc_conf.mode = RTE_FC_NONE; + } + + status = rte_eth_dev_flow_ctrl_set(port_id, &fc_conf); + if (status) + return status; + + return 0; +} + +int +rte_ethtool_net_open(uint8_t port_id) +{ + rte_eth_dev_stop(port_id); + + return rte_eth_dev_start(port_id); +} + +int +rte_ethtool_net_stop(uint8_t port_id) +{ + if (!rte_eth_dev_is_valid_port(port_id)) + return -ENODEV; + rte_eth_dev_stop(port_id); + + return 0; +} + +int +rte_ethtool_net_get_mac_addr(uint8_t port_id, struct ether_addr *addr) +{ + if (!rte_eth_dev_is_valid_port(port_id)) + return -ENODEV; + if (addr == NULL) + return -EINVAL; + rte_eth_macaddr_get(port_id, addr); + + return 0; +} + +int +rte_ethtool_net_set_mac_addr(uint8_t port_id, struct ether_addr *addr) +{ + if (addr == NULL) + return -EINVAL; + return rte_eth_dev_default_mac_addr_set(port_id, addr); +} + +int +rte_ethtool_net_validate_addr(uint8_t port_id __rte_unused, + struct ether_addr *addr) +{ + if (addr == NULL) + return -EINVAL; + return is_valid_assigned_ether_addr(addr); +} + +int +rte_ethtool_net_change_mtu(uint8_t port_id, int mtu) +{ + return rte_eth_dev_set_mtu(port_id, (uint16_t)mtu); +} + +int +rte_ethtool_net_get_stats64(uint8_t port_id, struct rte_eth_stats *stats) +{ + if (stats == NULL) + return -EINVAL; + return rte_eth_stats_get(port_id, stats); +} + +int +rte_ethtool_net_vlan_rx_add_vid(uint8_t port_id, uint16_t vid) +{ + return rte_eth_dev_vlan_filter(port_id, vid, 1); +} + +int +rte_ethtool_net_vlan_rx_kill_vid(uint8_t port_id, uint16_t vid) +{ + return rte_eth_dev_vlan_filter(port_id, vid, 0); +} + +/* + * The set_rx_mode provides driver-specific rx mode setting. + * This implementation implements rx mode setting based upon + * ixgbe/igb drivers. Further improvement is to provide a + * callback op field over struct rte_eth_dev::dev_ops so each + * driver can register device-specific implementation + */ +int +rte_ethtool_net_set_rx_mode(uint8_t port_id) +{ + uint16_t num_vfs; + struct rte_eth_dev_info dev_info; + uint16_t vf; + + memset(&dev_info, 0, sizeof(dev_info)); + rte_eth_dev_info_get(port_id, &dev_info); + num_vfs = dev_info.max_vfs; + + /* Set VF vf_rx_mode, VF unsupport status is discard */ + for (vf = 0; vf < num_vfs; vf++) + rte_eth_dev_set_vf_rxmode(port_id, vf, + ETH_VMDQ_ACCEPT_UNTAG, 1); + + /* Enable Rx vlan filter, VF unspport status is discard */ + rte_eth_dev_set_vlan_offload(port_id, ETH_VLAN_FILTER_MASK); + + return 0; +} diff --git a/examples/l2fwd/rte_ethtool.h b/examples/l2fwd/rte_ethtool.h new file mode 100644 index 0000000..f5852e7 --- /dev/null +++ b/examples/l2fwd/rte_ethtool.h @@ -0,0 +1,371 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2010-2015 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _RTE_ETHTOOL_H_ +#define _RTE_ETHTOOL_H_ + +/* + * This new interface is designed to provide a user-space shim layer for + * Ethtool and Netdevice op API. + * + * rte_ethtool_get_driver: ethtool_ops::get_driverinfo + * rte_ethtool_get_link: ethtool_ops::get_link + * rte_ethtool_get_regs_len: ethtool_ops::get_regs_len + * rte_ethtool_get_regs: ethtool_ops::get_regs + * rte_ethtool_get_eeprom_len: ethtool_ops::get_eeprom_len + * rte_ethtool_get_eeprom: ethtool_ops::get_eeprom + * rte_ethtool_set_eeprom: ethtool_ops::set_eeprom + * rte_ethtool_get_pauseparam: ethtool_ops::get_pauseparam + * rte_ethtool_set_pauseparam: ethtool_ops::set_pauseparam + * + * rte_ethtool_net_open: net_device_ops::ndo_open + * rte_ethtool_net_stop: net_device_ops::ndo_stop + * rte_ethtool_net_set_mac_addr: net_device_ops::ndo_set_mac_address + * rte_ethtool_net_validate_addr: net_device_ops::ndo_validate_addr + * rte_ethtool_net_change_mtu: net_device_ops::rte_net_change_mtu + * rte_ethtool_net_get_stats64: net_device_ops::ndo_get_stats64 + * rte_ethtool_net_vlan_rx_add_vid net_device_ops::ndo_vlan_rx_add_vid + * rte_ethtool_net_vlan_rx_kill_vid net_device_ops::ndo_vlan_rx_kill_vid + * rte_ethtool_net_set_rx_mode net_device_ops::ndo_set_rx_mode + * + */ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +/** + * Retrieve the Ethernet device driver information according to + * attributes described by ethtool data structure, ethtool_drvinfo. + * + * @param port_id + * The port identifier of the Ethernet device. + * @param drvinfo + * A pointer to get driver information + * @return + * - (0) if successful. + * - (-ENODEV) if *port_id* invalid. + */ +int rte_ethtool_get_drvinfo(uint8_t port_id, struct ethtool_drvinfo *drvinfo); + +/** + * Retrieve the Ethernet device register length in bytes. + * + * @param port_id + * The port identifier of the Ethernet device. + * @return + * - (> 0) # of device registers (in bytes) available for dump + * - (0) no registers available for dump. + * - (-ENOTSUP) if hardware doesn't support. + * - (-ENODEV) if *port_id* invalid. + * - others depends on the specific operations implementation. + */ +int rte_ethtool_get_regs_len(uint8_t port_id); + +/** + * Retrieve the Ethernet device register information according to + * attributes described by ethtool data structure, ethtool_regs + * + * @param port_id + * The port identifier of the Ethernet device. + * @param reg + * A pointer to ethtool_regs that has register information + * @param data + * A pointer to a buffer that is used to retrieve device register content + * @return + * - (0) if successful. + * - (-ENOTSUP) if hardware doesn't support. + * - (-ENODEV) if *port_id* invalid. + * - others depends on the specific operations implementation. + */ +int rte_ethtool_get_regs(uint8_t port_id, struct ethtool_regs *regs, + void *data); + +/** + * Retrieve the Ethernet device link status + * + * @param port_id + * The port identifier of the Ethernet device. + * @return + * - (1) if link up. + * - (0) if link down. + * - (-ENOTSUP) if hardware doesn't support. + * - (-ENODEV) if *port_id* invalid. + * - (-EINVAL) if parameters invalid. + * - others depends on the specific operations implementation. + */ +int rte_ethtool_get_link(uint8_t port_id); + +/** + * Retrieve the Ethernet device EEPROM size + * + * @param port_id + * The port identifier of the Ethernet device. + * @return + * - (> 0) device EEPROM size in bytes + * - (0) device has NO EEPROM + * - (-ENOTSUP) if hardware doesn't support. + * - (-ENODEV) if *port_id* invalid. + * - others depends on the specific operations implementation. + */ +int rte_ethtool_get_eeprom_len(uint8_t port_id); + +/** + * Retrieve EEPROM content based upon eeprom range described in ethtool + * data structure, ethtool_eeprom + * + * @param port_id + * The port identifier of the Ethernet device. + * @param eeprom + * The pointer of ethtool_eeprom that provides eeprom range + * @param words + * A buffer that holds data read from eeprom + * @return + * - (0) if successful. + * - (-ENOTSUP) if hardware doesn't support. + * - (-ENODEV) if *port_id* invalid. + * - others depends on the specific operations implementation. + */ +int rte_ethtool_get_eeprom(uint8_t port_id, struct ethtool_eeprom *eeprom, + void *words); + +/** + * Setting EEPROM content based upon eeprom range described in ethtool + * data structure, ethtool_eeprom + * + * @param port_id + * The port identifier of the Ethernet device. + * @param eeprom + * The pointer of ethtool_eeprom that provides eeprom range + * @param words + * A buffer that holds data to be written into eeprom + * @return + * - (0) if successful. + * - (-ENOTSUP) if hardware doesn't support. + * - (-ENODEV) if *port_id* invalid. + * - (-EINVAL) if parameters invalid. + * - others depends on the specific operations implementation. + */ +int rte_ethtool_set_eeprom(uint8_t port_id, struct ethtool_eeprom *eeprom, + void *words); + +/** + * Retrieve the Ethernet device pause frame configuration according to + * parameter attributes desribed by ethtool data structure, + * ethtool_pauseparam. + * + * @param port_id + * The port identifier of the Ethernet device. + * @param pause_param + * The pointer of ethtool_coalesce that gets pause frame + * configuration parameters + * @return + * - (0) if successful. + * - (-ENOTSUP) if hardware doesn't support. + * - (-ENODEV) if *port_id* invalid. + * - (-EINVAL) if parameters invalid. + * - others depends on the specific operations implementation. + */ +int rte_ethtool_get_pauseparam(uint8_t port_id, + struct ethtool_pauseparam *pause_param); + +/** + * Setting the Ethernet device pause frame configuration according to + * parameter attributes desribed by ethtool data structure, ethtool_pauseparam. + * + * @param port_id + * The port identifier of the Ethernet device. + * @param pause_param + * The pointer of ethtool_coalesce that gets ring configuration parameters + * @return + * - (0) if successful. + * - (-ENOTSUP) if hardware doesn't support. + * - (-ENODEV) if *port_id* invalid. + * - (-EINVAL) if parameters invalid. + * - others depends on the specific operations implementation. + */ +int rte_ethtool_set_pauseparam(uint8_t port_id, + struct ethtool_pauseparam *param); + +/** + * Start the Ethernet device. + * + * @param port_id + * The port identifier of the Ethernet device. + * @return + * - (0) if successful. + * - (-ENOTSUP) if hardware doesn't support. + * - (-ENODEV) if *port_id* invalid. + * - others depends on the specific operations implementation. + */ +int rte_ethtool_net_open(uint8_t port_id); + +/** + * Stop the Ethernet device. + * + * @param port_id + * The port identifier of the Ethernet device. + * @return + * - (0) if successful. + * - (-ENODEV) if *port_id* invalid. + */ +int rte_ethtool_net_stop(uint8_t port_id); + +/** + * Get the Ethernet device MAC address. + * + * @param port_id + * The port identifier of the Ethernet device. + * @param addr + * MAC address of the Ethernet device. + * @return + * - (0) if successful. + * - (-ENODEV) if *port_id* invalid. + */ +int rte_ethtool_net_get_mac_addr(uint8_t port_id, struct ether_addr *addr); + +/** + * Setting the Ethernet device MAC address. + * + * @param port_id + * The port identifier of the Ethernet device. + * @param addr + * The new MAC addr. + * @return + * - (0) if successful. + * - (-ENOTSUP) if hardware doesn't support. + * - (-ENODEV) if *port_id* invalid. + * - (-EINVAL) if parameters invalid. + * - others depends on the specific operations implementation. + */ +int rte_ethtool_net_set_mac_addr(uint8_t port_id, struct ether_addr *addr); + +/** + * Validate if the provided MAC address is valid unicast address + * + * @param port_id + * The port identifier of the Ethernet device. + * @param addr + * A pointer to a buffer (6-byte, 48bit) for the target MAC address + * @return + * - (0) if successful. + * - (-ENOTSUP) if hardware doesn't support. + * - (-ENODEV) if *port_id* invalid. + * - (-EINVAL) if parameters invalid. + * - others depends on the specific operations implementation. + */ +int rte_ethtool_net_validate_addr(uint8_t port_id, struct ether_addr *addr); + +/** + * Setting the Ethernet device maximum Tx unit. + * + * @param port_id + * The port identifier of the Ethernet device. + * @param mtu + * New MTU + * @return + * - (0) if successful. + * - (-ENOTSUP) if hardware doesn't support. + * - (-ENODEV) if *port_id* invalid. + * - (-EINVAL) if parameters invalid. + * - others depends on the specific operations implementation. + */ +int rte_ethtool_net_change_mtu(uint8_t port_id, int mtu); + +/** + * Retrieve the Ethernet device traffic statistics + * + * @param port_id + * The port identifier of the Ethernet device. + * @param stats + * A pointer to struct rte_eth_stats for statistics parameters + * @return + * - (0) if successful. + * - (-ENOTSUP) if hardware doesn't support. + * - (-ENODEV) if *port_id* invalid. + * - (-EINVAL) if parameters invalid. + * - others depends on the specific operations implementation. + */ +int rte_ethtool_net_get_stats64(uint8_t port_id, struct rte_eth_stats *stats); + +/** + * Update the Ethernet device VLAN filter with new vid + * + * @param port_id + * The port identifier of the Ethernet device. + * @param vid + * A new VLAN id + * @return + * - (0) if successful. + * - (-ENOTSUP) if hardware doesn't support. + * - (-ENODEV) if *port_id* invalid. + * - others depends on the specific operations implementation. + */ +int rte_ethtool_net_vlan_rx_add_vid(uint8_t port_id, uint16_t vid); + +/** + * Remove VLAN id from Ethernet device. + * + * @param port_id + * The port identifier of the Ethernet device. + * @param vid + * A new VLAN id + * @return + * - (0) if successful. + * - (-ENOTSUP) if hardware doesn't support. + * - (-ENODEV) if *port_id* invalid. + * - others depends on the specific operations implementation. + */ +int rte_ethtool_net_vlan_rx_kill_vid(uint8_t port_id, uint16_t vid); + +/** + * Setting the Ethernet device rx mode. + * + * @param port_id + * The port identifier of the Ethernet device. + * @return + * - (0) if successful. + * - (-ENOTSUP) if hardware doesn't support. + * - (-ENODEV) if *port_id* invalid. + * - others depends on the specific operations implementation. + */ +int rte_ethtool_net_set_rx_mode(uint8_t port_id); + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_ETHTOOL_H_ */ -- 1.9.3