From patchwork Mon Mar 12 04:17:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zijie Pan X-Patchwork-Id: 36060 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 04189A49B; Tue, 13 Mar 2018 13:55:57 +0100 (CET) Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by dpdk.org (Postfix) with ESMTP id 1E07B2BF2 for ; Mon, 12 Mar 2018 05:17:56 +0100 (CET) Received: by mail-wm0-f68.google.com with SMTP id h21so13706918wmd.1 for ; Sun, 11 Mar 2018 21:17:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=PxDzLt8flMFlDEl5aJTptBNF4UfZNZBPykofQhVxTMk=; b=CMXiBpQ4YCBz3y7gUhNOA3uoRUOBud//nSyFsswWFNM1VWz6S80BFOIxjyPjzg0rAm V0xN3utZtVtIgIYv9psm+bfyap2ioDxXGurmF+hrNYeWsDuT14YhDd+G9c615ixZjoL/ AMlYosu+9qURDUHJewKqyWDM317PqyISUZUAFu0zSUou4lG4QCI/nl1eGiVvmrAGzx29 FJEwDBKn8qu1zPxv+hFSw0MsAlRQ3TRLMgJLPFSYkBzTVYYcFaZTElf4oAy5e+DPXmnd iPXTYVUj5FdnamF2E3oH0Go8gl4TvgMuvcaFNjNl2s3DVcy4hF9ilteR9TDFm1o1Edqa E9wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=PxDzLt8flMFlDEl5aJTptBNF4UfZNZBPykofQhVxTMk=; b=bmmz4RAC3t2SRTwmFEGf3x+Lunch9m2T/eaIcs9mpxOmoJGYy9Tu0t+zadGHgJ5K+M QFjaKwaYtD+UZB+I7w/UQk4cOIgjAMz7+epSC5QMo4TCrZmQi+UBPRah9u3gPCXnhGqu G+twy5DXxn6UlxQPC6GnmsRGISCu0GHrAx5kGKZZQh6s7Kwevn9/iOhdFPKig5YS/nTS DpPli8dltInBgKqCVbSvg6eWVfy1U1ukA2+L71ugvSrHydQrmjV0waGutQF5rqs0qyNg /M2HLPyZJs77hfSbvjy9lxxzhSG8JsQja4qBe0q9RQFOH/40bq6UHdFP7UnwfM4yMVYr yVGA== X-Gm-Message-State: AElRT7HjDYhF2Gt+b9cDqmRBt/r2jBJt1kDx8uQcKTOk8Ik8SHwAscbM AI0xBmF4tDsdJy5ecrHhd0DVhpOy X-Google-Smtp-Source: AG47ELu0F4xKbTvU+fylp5AqrfpYymVymFPV3/2i3Ey+MCPAuGq0tcwyt0ndazhMsO5Q0pWhhNn/Vg== X-Received: by 10.28.61.65 with SMTP id k62mr4692589wma.140.1520828275553; Sun, 11 Mar 2018 21:17:55 -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 t91sm13113866wrc.21.2018.03.11.21.17.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Mar 2018 21:17:55 -0700 (PDT) From: Zijie Pan To: dev@dpdk.org Date: Mon, 12 Mar 2018 05:17:20 +0100 Message-Id: <1520828243-25191-3-git-send-email-zijie.pan@6wind.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1520828243-25191-1-git-send-email-zijie.pan@6wind.com> References: <1520828243-25191-1-git-send-email-zijie.pan@6wind.com> X-Mailman-Approved-At: Tue, 13 Mar 2018 13:55:53 +0100 Subject: [dpdk-dev] [PATCH 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add a new command "module-eeprom" to get the data of plugin module EEPROM. Signed-off-by: Zijie Pan Reviewed-by: Remy Horton --- doc/guides/sample_app_ug/ethtool.rst | 2 ++ examples/ethtool/ethtool-app/ethapp.c | 61 +++++++++++++++++++++++++++++++++ examples/ethtool/lib/rte_ethtool.c | 30 ++++++++++++++++ examples/ethtool/lib/rte_ethtool.h | 34 ++++++++++++++++++ 4 files changed, 127 insertions(+) diff --git a/doc/guides/sample_app_ug/ethtool.rst b/doc/guides/sample_app_ug/ethtool.rst index 1b79aca..028b8e9 100644 --- a/doc/guides/sample_app_ug/ethtool.rst +++ b/doc/guides/sample_app_ug/ethtool.rst @@ -97,6 +97,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 0c3f1f6..93779c4 100644 --- a/examples/ethtool/ethtool-app/ethapp.c +++ b/examples/ethtool/ethtool-app/ethapp.c @@ -75,6 +75,8 @@ 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 +300,52 @@ 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("Plug-in module EEPROM 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 || module_info[1] <= 0) { + printf("Plug-in 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 +712,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 +876,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/rte_ethtool.c b/examples/ethtool/lib/rte_ethtool.c index 90dfbb7..36c81d4 100644 --- a/examples/ethtool/lib/rte_ethtool.c +++ b/examples/ethtool/lib/rte_ethtool.c @@ -174,6 +174,36 @@ } int +rte_ethtool_get_module_info(uint16_t port_id, uint32_t *modinfo) +{ + struct rte_dev_module_info *info; + + info = (struct rte_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.