All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zijie Pan <zijie.pan@6wind.com>
To: dev@dpdk.org
Cc: remy.horton@intel.com, 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
Subject: [PATCH v2 2/5] examples/ethtool: add a new command module-eeprom
Date: Fri, 16 Mar 2018 10:41:21 +0100	[thread overview]
Message-ID: <1521193281-25141-1-git-send-email-zijie.pan@6wind.com> (raw)
In-Reply-To: <1520828243-25191-3-git-send-email-zijie.pan@6wind.com>

Add a new command "module-eeprom" to get the data of plugin
module EEPROM.

Signed-off-by: Zijie Pan <zijie.pan@6wind.com>
---
 doc/guides/sample_app_ug/ethtool.rst  |    2 ++
 examples/ethtool/ethtool-app/ethapp.c |   64 +++++++++++++++++++++++++++++++++
 examples/ethtool/lib/rte_ethtool.c    |   30 ++++++++++++++++
 examples/ethtool/lib/rte_ethtool.h    |   34 ++++++++++++++++++
 4 files changed, 130 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..c37b7c3 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 <port_id> <filename>\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/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.
-- 
1.7.10.4

  parent reply	other threads:[~2018-03-16  9:42 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-12  4:17 [PATCH 0/5] Patches to get the information and data of EEPROM Zijie Pan
2018-03-12  4:17 ` [PATCH 1/5] ethdev: add access to eeprom Zijie Pan
2018-03-13 14:51   ` Remy Horton
2018-03-16  9:38   ` [PATCH v2 " Zijie Pan
2018-03-16  9:59     ` Remy Horton
2018-03-12  4:17 ` [PATCH 2/5] examples/ethtool: add a new command module-eeprom Zijie Pan
2018-03-13 14:46   ` Remy Horton
2018-03-16  9:41   ` Zijie Pan [this message]
2018-03-16  9:59     ` [PATCH v2 " Remy Horton
2018-03-12  4:17 ` [PATCH 3/5] net/ixgbe: add module EEPROM callbacks for ixgbe Zijie Pan
2018-03-13 14:46   ` Remy Horton
2018-03-16  9:42   ` [PATCH v2 " Zijie Pan
2018-03-16 10:08     ` Remy Horton
2018-03-12  4:17 ` [PATCH 4/5] net/e1000: add module EEPROM callbacks for e1000 Zijie Pan
2018-03-16  9:42   ` [PATCH v2 " Zijie Pan
2018-03-12  4:17 ` [PATCH 5/5] net/i40e: add module EEPROM callbacks for i40e Zijie Pan
2018-03-16  9:42   ` [PATCH v2 " Zijie Pan
2018-03-13 15:19 ` [PATCH 0/5] Patches to get the information and data of EEPROM Remy Horton
2018-03-16  9:36 ` [PATCH v2 0/5] " Zijie Pan
2018-03-21 11:06   ` [PATCH v3 " Zijie Pan
2018-03-21 11:06     ` [PATCH v3 1/5] ethdev: add access to eeprom Zijie Pan
2018-04-19 13:34       ` Ferruh Yigit
2018-04-22 21:13       ` Thomas Monjalon
2018-03-21 11:06     ` [PATCH v3 2/5] examples/ethtool: add a new command module-eeprom Zijie Pan
2018-03-21 11:06     ` [PATCH v3 3/5] net/ixgbe: add module EEPROM callbacks for ixgbe Zijie Pan
2018-03-21 11:06     ` [PATCH v3 4/5] net/e1000: add module EEPROM callbacks for e1000 Zijie Pan
2018-03-21 11:06     ` [PATCH v3 5/5] net/i40e: add module EEPROM callbacks for i40e Zijie Pan
2018-04-19 13:36     ` [PATCH v3 0/5] get the information and data of EEPROM Ferruh Yigit
2018-04-19 14:17       ` Remy Horton
2018-04-24 10:17     ` [PATCH v4 " Zijie Pan
2018-04-24 10:17       ` [PATCH v4 1/5] ethdev: add access to eeprom Zijie Pan
2018-04-24 10:25         ` Thomas Monjalon
2018-04-25  8:21           ` Zijie Pan
2018-04-25  8:31             ` Thomas Monjalon
2018-04-24 10:17       ` [PATCH v4 2/5] examples/ethtool: add a new command module-eeprom Zijie Pan
2018-04-24 10:17       ` [PATCH v4 3/5] net/ixgbe: add module EEPROM callbacks for ixgbe Zijie Pan
2018-04-24 10:17       ` [PATCH v4 4/5] net/e1000: add module EEPROM callbacks for e1000 Zijie Pan
2018-04-24 10:17       ` [PATCH v4 5/5] net/i40e: add module EEPROM callbacks for i40e Zijie Pan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1521193281-25141-1-git-send-email-zijie.pan@6wind.com \
    --to=zijie.pan@6wind.com \
    --cc=akhil.goyal@nxp.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=john.mcnamara@intel.com \
    --cc=marko.kovacevic@intel.com \
    --cc=orika@mellanox.com \
    --cc=pablo.de.lara.guarch@intel.com \
    --cc=radu.nicolau@intel.com \
    --cc=remy.horton@intel.com \
    --cc=tomasz.kantecki@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.