DPDK patches and discussions
 help / color / mirror / Atom feed
From: Robin Zhang <robinx.zhang@intel.com>
To: dev@dpdk.org
Cc: thomas@monjalon.net, andrew.rybchenko@oktetlabs.ru,
	kevinx.liu@intel.com, Robin Zhang <robinx.zhang@intel.com>
Subject: [PATCH v8 1/5] ethdev: add telemetry command for module EEPROM
Date: Wed, 25 May 2022 03:14:42 +0000	[thread overview]
Message-ID: <20220525031446.72578-2-robinx.zhang@intel.com> (raw)
In-Reply-To: <20220525031446.72578-1-robinx.zhang@intel.com>

Add a new telemetry command /ethdev/module_eeprom to dump the module
EEPROM of each port. The format of module EEPROM information follows
the SFF(Small Form Factor) Committee specifications.

Signed-off-by: Robin Zhang <robinx.zhang@intel.com>
---
 lib/ethdev/ethdev_sff_telemetry.c | 138 ++++++++++++++++++++++++++++++
 lib/ethdev/ethdev_sff_telemetry.h |  27 ++++++
 lib/ethdev/meson.build            |   1 +
 lib/ethdev/rte_ethdev.c           |   3 +
 4 files changed, 169 insertions(+)
 create mode 100644 lib/ethdev/ethdev_sff_telemetry.c
 create mode 100644 lib/ethdev/ethdev_sff_telemetry.h

diff --git a/lib/ethdev/ethdev_sff_telemetry.c b/lib/ethdev/ethdev_sff_telemetry.c
new file mode 100644
index 0000000000..f756b9643f
--- /dev/null
+++ b/lib/ethdev/ethdev_sff_telemetry.c
@@ -0,0 +1,138 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2022 Intel Corporation
+ */
+
+#include <errno.h>
+
+#include <rte_ethdev.h>
+#include <rte_common.h>
+#include "ethdev_sff_telemetry.h"
+#include "telemetry_data.h"
+
+static void
+sff_port_module_eeprom_parse(uint16_t port_id, struct rte_tel_data *d)
+{
+	struct rte_eth_dev_module_info minfo;
+	struct rte_dev_eeprom_info einfo;
+	int ret;
+
+	if (d == NULL) {
+		RTE_ETHDEV_LOG(ERR, "Dict invalid\n");
+		return;
+	}
+
+	ret = rte_eth_dev_get_module_info(port_id, &minfo);
+	if (ret != 0) {
+		switch (ret) {
+		case -ENODEV:
+			RTE_ETHDEV_LOG(ERR, "port index %d invalid\n", port_id);
+			break;
+		case -ENOTSUP:
+			RTE_ETHDEV_LOG(ERR, "operation not supported by device\n");
+			break;
+		case -EIO:
+			RTE_ETHDEV_LOG(ERR, "device is removed\n");
+			break;
+		default:
+			RTE_ETHDEV_LOG(ERR, "Unable to get port module info, %d\n", ret);
+			break;
+		}
+		return;
+	}
+
+	einfo.offset = 0;
+	einfo.length = minfo.eeprom_len;
+	einfo.data = calloc(1, minfo.eeprom_len);
+	if (einfo.data == NULL) {
+		RTE_ETHDEV_LOG(ERR, "Allocation of port %u eeprom data failed\n", port_id);
+		return;
+	}
+
+	ret = rte_eth_dev_get_module_eeprom(port_id, &einfo);
+	if (ret != 0) {
+		switch (ret) {
+		case -ENODEV:
+			RTE_ETHDEV_LOG(ERR, "port index %d invalid\n", port_id);
+			break;
+		case -ENOTSUP:
+			RTE_ETHDEV_LOG(ERR, "operation not supported by device\n");
+			break;
+		case -EIO:
+			RTE_ETHDEV_LOG(ERR, "device is removed\n");
+			break;
+		default:
+			RTE_ETHDEV_LOG(ERR, "Unable to get port module EEPROM, %d\n", ret);
+			break;
+		}
+		free(einfo.data);
+		return;
+	}
+
+	switch (minfo.type) {
+	/* parsing module EEPROM data base on different module type */
+	default:
+		RTE_ETHDEV_LOG(NOTICE, "Unsupported module type: %u\n", minfo.type);
+		break;
+	}
+
+	free(einfo.data);
+}
+
+void
+ssf_add_dict_string(struct rte_tel_data *d, const char *name_str, const char *value_str)
+{
+	struct tel_dict_entry *e = &d->data.dict[d->data_len];
+
+	if (d->type != RTE_TEL_DICT)
+		return;
+	if (d->data_len >= RTE_TEL_MAX_DICT_ENTRIES) {
+		RTE_ETHDEV_LOG(ERR, "data_len has exceeded the maximum number of inserts\n");
+		return;
+	}
+
+	e->type = RTE_TEL_STRING_VAL;
+	/* append different values for same keys */
+	if (d->data_len > 0) {
+		struct tel_dict_entry *previous = &d->data.dict[d->data_len - 1];
+		if (strcmp(previous->name, name_str) == 0) {
+			strlcat(previous->value.sval, "; ", RTE_TEL_MAX_STRING_LEN);
+			strlcat(previous->value.sval, value_str, RTE_TEL_MAX_STRING_LEN);
+			goto end;
+		}
+	}
+	strlcpy(e->value.sval, value_str, RTE_TEL_MAX_STRING_LEN);
+	strlcpy(e->name, name_str, RTE_TEL_MAX_STRING_LEN);
+	d->data_len++;
+
+end:
+	return;
+}
+
+int
+eth_dev_handle_port_module_eeprom(const char *cmd __rte_unused, const char *params,
+				  struct rte_tel_data *d)
+{
+	char *end_param;
+	int port_id;
+
+	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
+		return -1;
+
+	errno = 0;
+	port_id = strtoul(params, &end_param, 0);
+
+	if (errno != 0) {
+		RTE_ETHDEV_LOG(ERR, "Invalid argument\n");
+		return -1;
+	}
+
+	if (*end_param != '\0')
+		RTE_ETHDEV_LOG(NOTICE,
+			"Extra parameters passed to ethdev telemetry command, ignoring\n");
+
+	rte_tel_data_start_dict(d);
+
+	sff_port_module_eeprom_parse(port_id, d);
+
+	return 0;
+}
diff --git a/lib/ethdev/ethdev_sff_telemetry.h b/lib/ethdev/ethdev_sff_telemetry.h
new file mode 100644
index 0000000000..1fd870e0ef
--- /dev/null
+++ b/lib/ethdev/ethdev_sff_telemetry.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2022 Intel Corporation
+ */
+
+#ifndef _ETHDEV_SFF_TELEMETRY_H_
+#define _ETHDEV_SFF_TELEMETRY_H_
+
+#include <rte_telemetry.h>
+
+#define SFF_ITEM_VAL_COMPOSE_SIZE 64
+
+/* SFF-8079 Optics diagnostics */
+void sff_8079_show_all(const uint8_t *data, struct rte_tel_data *d);
+
+/* SFF-8472 Optics diagnostics */
+void sff_8472_show_all(const uint8_t *data, struct rte_tel_data *d);
+
+/* SFF-8636 Optics diagnostics */
+void sff_8636_show_all(const uint8_t *data, uint32_t eeprom_len, struct rte_tel_data *d);
+
+int eth_dev_handle_port_module_eeprom(const char *cmd __rte_unused,
+				      const char *params,
+				      struct rte_tel_data *d);
+
+void ssf_add_dict_string(struct rte_tel_data *d, const char *name_str, const char *value_str);
+
+#endif /* _ETHDEV_SFF_TELEMETRY_H_ */
diff --git a/lib/ethdev/meson.build b/lib/ethdev/meson.build
index a094585bf7..49c77acb3f 100644
--- a/lib/ethdev/meson.build
+++ b/lib/ethdev/meson.build
@@ -11,6 +11,7 @@ sources = files(
         'rte_flow.c',
         'rte_mtr.c',
         'rte_tm.c',
+        'ethdev_sff_telemetry.c',
 )
 
 headers = files(
diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index 29a3d80466..2b87df1b32 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -39,6 +39,7 @@
 #include "ethdev_driver.h"
 #include "ethdev_profile.h"
 #include "ethdev_private.h"
+#include "ethdev_sff_telemetry.h"
 
 struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
 
@@ -5876,4 +5877,6 @@ RTE_INIT(ethdev_init_telemetry)
 			"Returns the link status for a port. Parameters: int port_id");
 	rte_telemetry_register_cmd("/ethdev/info", eth_dev_handle_port_info,
 			"Returns the device info for a port. Parameters: int port_id");
+	rte_telemetry_register_cmd("/ethdev/module_eeprom", eth_dev_handle_port_module_eeprom,
+			"Returns module EEPROM info with SFF specs. Parameters: int port_id");
 }
-- 
2.25.1


  reply	other threads:[~2022-05-25  3:20 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-15 10:18 [PATCH] app/testpmd: format dump information of " Robin Zhang
2022-02-15 13:28 ` Ferruh Yigit
2022-02-15 15:07   ` Thomas Monjalon
2022-02-16  2:26     ` Zhang, RobinX
2022-02-16  8:03       ` David Marchand
2022-02-16  8:45         ` Thomas Monjalon
2022-02-16  9:30           ` Bruce Richardson
2022-02-16  9:41             ` David Marchand
2022-02-16 10:02               ` Bruce Richardson
2022-02-16 10:15                 ` David Marchand
2022-04-08 10:23 ` [PATCH v2] common/sff_module: add telemetry command to dump " Robin Zhang
2022-04-08 10:33   ` Bruce Richardson
2022-04-08 10:55     ` Zhang, RobinX
2022-04-08 11:00       ` Bruce Richardson
2022-04-08 11:20         ` Zhang, RobinX
2022-04-08 11:26           ` Bruce Richardson
2022-04-11  8:13             ` Zhang, RobinX
2022-04-11  9:13               ` Bruce Richardson
2022-04-13 12:13                 ` Thomas Monjalon
2022-04-14  7:41                   ` David Marchand
2022-04-20  7:00 ` [PATCH v3 0/5] add telemetry command for show " Robin Zhang
2022-04-20  7:00   ` [PATCH v3 1/5] ethdev: add telemetry command for " Robin Zhang
2022-04-20  9:16     ` Andrew Rybchenko
2022-04-20  7:00   ` [PATCH v3 2/5] ethdev: common utilities for different SFF specs Robin Zhang
2022-04-20  7:00   ` [PATCH v3 3/5] ethdev: format module EEPROM for SFF-8079 Robin Zhang
2022-04-20  7:00   ` [PATCH v3 4/5] ethdev: format module EEPROM for SFF-8472 Robin Zhang
2022-04-20  7:00   ` [PATCH v3 5/5] ethdev: format module EEPROM for SFF-8636 Robin Zhang
2022-04-20  8:49   ` [PATCH v3 0/5] add telemetry command for show module EEPROM Morten Brørup
2022-04-25  5:34 ` [PATCH v4 " Robin Zhang
2022-04-25  5:34   ` [PATCH v4 1/5] ethdev: add telemetry command for " Robin Zhang
2022-04-25  5:34   ` [PATCH v4 2/5] ethdev: common utilities for different SFF specs Robin Zhang
2022-04-25  5:34   ` [PATCH v4 3/5] ethdev: format module EEPROM for SFF-8079 Robin Zhang
2022-04-25  5:34   ` [PATCH v4 4/5] ethdev: format module EEPROM for SFF-8472 Robin Zhang
2022-04-25  5:34   ` [PATCH v4 5/5] ethdev: format module EEPROM for SFF-8636 Robin Zhang
2022-04-26  2:43 ` [PATCH v5 0/5] add telemetry command for show module EEPROM Robin Zhang
2022-04-26  2:43   ` [PATCH v5 1/5] ethdev: add telemetry command for " Robin Zhang
2022-05-04 10:16     ` Andrew Rybchenko
2022-04-26  2:43   ` [PATCH v5 2/5] ethdev: common utilities for different SFF specs Robin Zhang
2022-04-26  2:43   ` [PATCH v5 3/5] ethdev: format module EEPROM for SFF-8079 Robin Zhang
2022-04-26  2:43   ` [PATCH v5 4/5] ethdev: format module EEPROM for SFF-8472 Robin Zhang
2022-04-26  2:43   ` [PATCH v5 5/5] ethdev: format module EEPROM for SFF-8636 Robin Zhang
2022-05-04  8:13   ` [PATCH v5 0/5] add telemetry command for show module EEPROM Andrew Rybchenko
2022-05-11  2:14   ` [PATCH v6 " Robin Zhang
2022-05-11  2:14     ` [PATCH v6 1/5] ethdev: add telemetry command for " Robin Zhang
2022-05-11  2:14     ` [PATCH v6 2/5] ethdev: common utilities for different SFF specs Robin Zhang
2022-05-11  2:14     ` [PATCH v6 3/5] ethdev: format module EEPROM for SFF-8079 Robin Zhang
2022-05-11  2:14     ` [PATCH v6 4/5] ethdev: format module EEPROM for SFF-8472 Robin Zhang
2022-05-19  8:33       ` Andrew Rybchenko
2022-05-11  2:14     ` [PATCH v6 5/5] ethdev: format module EEPROM for SFF-8636 Robin Zhang
2022-05-24  6:24     ` [PATCH v7 0/5] add telemetry command for show module EEPROM Robin Zhang
2022-05-24  6:24       ` [PATCH v7 1/5] ethdev: add telemetry command for " Robin Zhang
2022-05-24  6:24       ` [PATCH v7 2/5] ethdev: common utilities for different SFF specs Robin Zhang
2022-05-24  6:24       ` [PATCH v7 3/5] ethdev: format module EEPROM for SFF-8079 Robin Zhang
2022-05-24  6:24       ` [PATCH v7 4/5] ethdev: format module EEPROM for SFF-8472 Robin Zhang
2022-05-24  6:24       ` [PATCH v7 5/5] ethdev: format module EEPROM for SFF-8636 Robin Zhang
2022-05-24  9:03         ` David Marchand
2022-05-25  2:43           ` Zhang, RobinX
2022-05-25  3:14       ` [PATCH v8 0/5] add telemetry command for show module EEPROM Robin Zhang
2022-05-25  3:14         ` Robin Zhang [this message]
2022-05-25  9:24           ` [PATCH v8 1/5] ethdev: add telemetry command for " Andrew Rybchenko
2022-05-25  3:14         ` [PATCH v8 2/5] ethdev: common utilities for different SFF specs Robin Zhang
2022-05-25  8:51           ` Andrew Rybchenko
2022-05-25  9:40           ` Andrew Rybchenko
2022-05-25  3:14         ` [PATCH v8 3/5] ethdev: format module EEPROM for SFF-8079 Robin Zhang
2022-05-25  9:55           ` Andrew Rybchenko
2022-05-25  3:14         ` [PATCH v8 4/5] ethdev: format module EEPROM for SFF-8472 Robin Zhang
2022-05-25 11:58           ` Andrew Rybchenko
2022-05-25  3:14         ` [PATCH v8 5/5] ethdev: format module EEPROM for SFF-8636 Robin Zhang
2022-05-25  9:01           ` Andrew Rybchenko
2022-05-25 12:01           ` Andrew Rybchenko
2022-05-26  7:32         ` [PATCH v9 0/5] add telemetry command for show module EEPROM Robin Zhang
2022-05-26  7:32           ` [PATCH v9 1/5] ethdev: add telemetry command for " Robin Zhang
2022-05-26  7:32           ` [PATCH v9 2/5] ethdev: add common code for different SFF specs Robin Zhang
2022-05-26  7:32           ` [PATCH v9 3/5] ethdev: support SFF-8079 module information telemetry Robin Zhang
2022-05-26  7:32           ` [PATCH v9 4/5] ethdev: support SFF-8472 " Robin Zhang
2022-05-26  7:32           ` [PATCH v9 5/5] ethdev: support SFF-8636 " Robin Zhang
2022-05-31 14:43           ` [PATCH v9 0/5] add telemetry command for show module EEPROM Andrew Rybchenko

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=20220525031446.72578-2-robinx.zhang@intel.com \
    --to=robinx.zhang@intel.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=kevinx.liu@intel.com \
    --cc=thomas@monjalon.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).