From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43]) by dpdk.org (Postfix) with ESMTP id 8F5845593 for ; Wed, 25 Apr 2018 12:02:19 +0200 (CEST) Received: by mail-wm0-f43.google.com with SMTP id w195so6112452wmw.2 for ; Wed, 25 Apr 2018 03:02:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=F0x1wJazy/E7s6jTcEcndsEISCrENaLyoVxZFj4V4ps=; b=wdGSNG6g4cHl0rNpwiwgMhidcf3VAdCcIADaMNvEWibuNx1HC6L3e9nDP6s5XiqpBf 7isGclzyTjGFIvdVBW9aBcYDJaeN7wrSbOESjk/r22I/l9JieHtZLQXWU1CC4ujOT6D0 qQsqQE2p++ufRf+LW6DRa1n02gbWymDvWovpTnWC6Fol9kFQJfwSB0Zmc0J8o3zvhEpV jKkk0mSV5EsM7RPLDpsehnLIgMl3vrjX+4ggiNOCJ2ldSBC2+K78YubRHdAKVGPb2DjN x9sNDqgYfhboK3BVtXemHdIV4pGxBV/9rDxFLUEOnvrrzqxtm2s6sbz+/QRZjqCjqskG cEhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=F0x1wJazy/E7s6jTcEcndsEISCrENaLyoVxZFj4V4ps=; b=Px4z3xpaoOZY505KgrwByQs4+3VgePICPjN9SNQNRjFZEcOVjl4WgMCwPOJC9ectqL iQr/sTuVbZNh6boKaGIR3YInf3BAuosY4mExSf2fv+Kol8iAtEa5PIEXMKFdO+1YWXHq en2jiNjq8JgQ3VUO6LgcDjrC8kgZW7tOe2ES38T/66tdo03cqK31y2Q+xJU9tbbVK8cW vFgGRhXf3QIt6OH/JNVn/XmHBpmJXEkNjYLrhGob6wiEPZuYriOSkfe2xxW+WVRqqdKx wJixF9LkhQCCdguN8v9gglweG+BEBTUM7CtEIeSYhFrKYcxVhfwJgl732TCrD8jRu0d3 wbcg== X-Gm-Message-State: ALQs6tDgH+EY1QA6AACwQPPDUynsRmNXUNA/H0+YoO7Kbk2JyACFiHFk pf8zEQLyrzN5kvjnBh8MFAXgBr2b9WA= X-Google-Smtp-Source: AIpwx48I6pYDYCnzq7xlT9WJMO+LDDur6IsJrTHdaCg73OuZ/FOC5jHbFnud9Tl5jv0M1DXO0pV9MQ== X-Received: by 10.28.125.66 with SMTP id y63mr12451816wmc.121.1524650539115; Wed, 25 Apr 2018 03:02:19 -0700 (PDT) Received: from cougar.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id n143sm14100363wmd.29.2018.04.25.03.02.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Apr 2018 03:02:18 -0700 (PDT) From: Zijie Pan To: dev@dpdk.org Cc: remy.horton@intel.com, ferruh.yigit@intel.com, thomas@monjalon.net, orika@mellanox.com, bruce.richardson@intel.com, pablo.de.lara.guarch@intel.com, radu.nicolau@intel.com, akhil.goyal@nxp.com, tomasz.kantecki@intel.com, john.mcnamara@intel.com, marko.kovacevic@intel.com Date: Wed, 25 Apr 2018 12:01:52 +0200 Message-Id: <1524650515-26659-3-git-send-email-zijie.pan@6wind.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1524650515-26659-1-git-send-email-zijie.pan@6wind.com> References: <1524647624-23005-1-git-send-email-zijie.pan@6wind.com> <1524650515-26659-1-git-send-email-zijie.pan@6wind.com> Subject: [dpdk-dev] [PATCH v6 2/5] examples/ethtool: add a new command module-eeprom X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Apr 2018 10:02:19 -0000 Add a new command "module-eeprom" to get the data of plugin module EEPROM. Signed-off-by: Zijie Pan Acked-by: Remy Horton --- Cc: remy.horton@intel.com Cc: orika@mellanox.com Cc: bruce.richardson@intel.com Cc: pablo.de.lara.guarch@intel.com Cc: radu.nicolau@intel.com Cc: akhil.goyal@nxp.com Cc: tomasz.kantecki@intel.com Cc: john.mcnamara@intel.com Cc: marko.kovacevic@intel.com doc/guides/sample_app_ug/ethtool.rst | 3 ++ examples/ethtool/ethtool-app/ethapp.c | 64 +++++++++++++++++++++++++++++++++ examples/ethtool/lib/Makefile | 1 + examples/ethtool/lib/rte_ethtool.c | 30 ++++++++++++++++ examples/ethtool/lib/rte_ethtool.h | 34 ++++++++++++++++++ 5 files changed, 132 insertions(+) diff --git a/doc/guides/sample_app_ug/ethtool.rst b/doc/guides/sample_app_ug/ethtool.rst index 1b79aca..47e09f6 100644 --- a/doc/guides/sample_app_ug/ethtool.rst +++ b/doc/guides/sample_app_ug/ethtool.rst @@ -44,6 +44,7 @@ they do as as follows: * ``drvinfo``: Print driver info * ``eeprom``: Dump EEPROM to file +* ``module-eeprom``: Dump plugin module EEPROM to file * ``link``: Print port link states * ``macaddr``: Gets/sets MAC address * ``mtu``: Set NIC MTU @@ -97,6 +98,8 @@ the following functions: - ``rte_ethtool_get_eeprom_len()`` - ``rte_ethtool_get_eeprom()`` - ``rte_ethtool_set_eeprom()`` +- ``rte_ethtool_get_module_info()`` +- ``rte_ethtool_get_module_eeprom()`` - ``rte_ethtool_get_pauseparam()`` - ``rte_ethtool_set_pauseparam()`` - ``rte_ethtool_net_open()`` diff --git a/examples/ethtool/ethtool-app/ethapp.c b/examples/ethtool/ethtool-app/ethapp.c index 4d62f4c..a4e64b3 100644 --- a/examples/ethtool/ethtool-app/ethapp.c +++ b/examples/ethtool/ethtool-app/ethapp.c @@ -75,6 +75,9 @@ struct pcmd_intintint_params { /* 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_module_eeprom_token_cmd = + TOKEN_STRING_INITIALIZER(struct pcmd_intstr_params, cmd, + "module-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 = @@ -298,6 +301,54 @@ struct pcmd_intintint_params { static void +pcmd_module_eeprom_callback(void *ptr_params, + __rte_unused struct cmdline *ctx, + __rte_unused void *ptr_data) +{ + struct pcmd_intstr_params *params = ptr_params; + struct ethtool_eeprom info_eeprom; + uint32_t module_info[2]; + 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; + } + + stat = rte_ethtool_get_module_info(params->port, module_info); + if (stat != 0) { + printf("Module EEPROM information read error %i\n", stat); + return; + } + + info_eeprom.len = module_info[1]; + info_eeprom.offset = 0; + + stat = rte_ethtool_get_module_eeprom(params->port, + &info_eeprom, bytes_eeprom); + if (stat != 0) { + printf("Module EEPROM read error %i\n", stat); + return; + } + + fp_eeprom = fopen(params->opt, "wb"); + if (fp_eeprom == NULL) { + printf("Error opening '%s' for writing\n", params->opt); + return; + } + printf("Total plugin module EEPROM length: %i bytes\n", + info_eeprom.len); + if (fwrite(bytes_eeprom, 1, info_eeprom.len, + fp_eeprom) != info_eeprom.len) { + printf("Error writing '%s'\n", params->opt); + } + fclose(fp_eeprom); +} + + +static void pcmd_pause_callback(void *ptr_params, __rte_unused struct cmdline *ctx, void *ptr_data) @@ -664,6 +715,18 @@ static void pcmd_vlan_callback(__rte_unused void *ptr_params, NULL }, }; +cmdline_parse_inst_t pcmd_module_eeprom = { + .f = pcmd_module_eeprom_callback, + .data = NULL, + .help_str = "module-eeprom \n" + " Dump plugin module EEPROM to file", + .tokens = { + (void *)&pcmd_module_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, @@ -816,6 +879,7 @@ static void pcmd_vlan_callback(__rte_unused void *ptr_params, cmdline_parse_ctx_t list_prompt_commands[] = { (cmdline_parse_inst_t *)&pcmd_drvinfo, (cmdline_parse_inst_t *)&pcmd_eeprom, + (cmdline_parse_inst_t *)&pcmd_module_eeprom, (cmdline_parse_inst_t *)&pcmd_link, (cmdline_parse_inst_t *)&pcmd_macaddr_get, (cmdline_parse_inst_t *)&pcmd_macaddr, diff --git a/examples/ethtool/lib/Makefile b/examples/ethtool/lib/Makefile index fbafa6d..2576910 100644 --- a/examples/ethtool/lib/Makefile +++ b/examples/ethtool/lib/Makefile @@ -25,6 +25,7 @@ SRCS-y := rte_ethtool.c CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) +CFLAGS += -DALLOW_EXPERIMENTAL_API ifeq ($(CONFIG_RTE_BUILD_SHARED_LIB),y) ifeq ($(CONFIG_RTE_LIBRTE_IXGBE_PMD),y) diff --git a/examples/ethtool/lib/rte_ethtool.c b/examples/ethtool/lib/rte_ethtool.c index d519a50..e6a2e88 100644 --- a/examples/ethtool/lib/rte_ethtool.c +++ b/examples/ethtool/lib/rte_ethtool.c @@ -178,6 +178,36 @@ } int +rte_ethtool_get_module_info(uint16_t port_id, uint32_t *modinfo) +{ + struct rte_eth_dev_module_info *info; + + info = (struct rte_eth_dev_module_info *)modinfo; + return rte_eth_dev_get_module_info(port_id, info); +} + +int +rte_ethtool_get_module_eeprom(uint16_t port_id, struct ethtool_eeprom *eeprom, + void *words) +{ + struct rte_dev_eeprom_info eeprom_info; + int status; + + if (eeprom == NULL || words == NULL) + return -EINVAL; + + eeprom_info.offset = eeprom->offset; + eeprom_info.length = eeprom->len; + eeprom_info.data = words; + + status = rte_eth_dev_get_module_eeprom(port_id, &eeprom_info); + if (status) + return status; + + return 0; +} + +int rte_ethtool_get_pauseparam(uint16_t port_id, struct ethtool_pauseparam *pause_param) { diff --git a/examples/ethtool/lib/rte_ethtool.h b/examples/ethtool/lib/rte_ethtool.h index c962396..43adc97 100644 --- a/examples/ethtool/lib/rte_ethtool.h +++ b/examples/ethtool/lib/rte_ethtool.h @@ -154,6 +154,40 @@ int rte_ethtool_set_eeprom(uint16_t port_id, struct ethtool_eeprom *eeprom, void *words); /** + * Retrieve the type and size of plugin module EEPROM + * + * @param port_id + * The port identifier of the Ethernet device. + * @param modinfo + * The pointer that provides the type and size of plugin module 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_module_info(uint16_t port_id, uint32_t *modinfo); + +/** + * Retrieve the data of plugin module EEPROM + * + * @param port_id + * The port identifier of the Ethernet device. + * @param eeprom + * The pointer of ethtool_eeprom that provides plugin module eeprom + * offset and length + * @param words + * A buffer that holds data read from plugin module 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_module_eeprom(uint16_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. -- 1.7.10.4