From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5BC50A0557; Thu, 26 May 2022 09:39:38 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4F55C427EC; Thu, 26 May 2022 09:39:33 +0200 (CEST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mails.dpdk.org (Postfix) with ESMTP id C4A2A40DF7 for ; Thu, 26 May 2022 09:39:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1653550771; x=1685086771; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Tc6pKc2qJb8C/PDLQI+h/gbQ89TRMdBl+zI2Rkeq/oE=; b=QjBFKjc16BpOPoXeFoh0BOj4/u2poP7zV8HfULRiJQRYZ+7IFi5LkCD/ Q0Kfw0XMMadnr6Ukn5DTVxZacIrJPjAmKCNWVZy/246JwlapdtZUrarxJ IKTOZcgfoo4UYA8U/6DMg79WuH1NbCICNolIevg4WVtPhaBu327oijQqi UVzjBl/FpoVtItcEkti95UirVTACLBCW+mIwoiA8bHVR2YiJ3+XOhPak6 N24mptvPoo3HFjj5i/tyZg/17VCTi3qiap/UKrTl5Nq/q7jD/Ny61pTUo RvtUIlG0kkpRU2uBjYWZGoFSpjr1uOnLtmiPEiwTrrLC8/tCQs3Uhr1DG Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10358"; a="272885316" X-IronPort-AV: E=Sophos;i="5.91,252,1647327600"; d="scan'208";a="272885316" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2022 00:39:23 -0700 X-IronPort-AV: E=Sophos;i="5.91,252,1647327600"; d="scan'208";a="549441832" Received: from intel-cd-odc-robin.cd.intel.com ([10.240.178.142]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2022 00:39:21 -0700 From: Robin Zhang To: dev@dpdk.org Cc: thomas@monjalon.net, andrew.rybchenko@oktetlabs.ru, kevinx.liu@intel.com, Robin Zhang Subject: [PATCH v9 1/5] ethdev: add telemetry command for module EEPROM Date: Thu, 26 May 2022 07:32:11 +0000 Message-Id: <20220526073215.428410-2-robinx.zhang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220526073215.428410-1-robinx.zhang@intel.com> References: <20220525031446.72578-1-robinx.zhang@intel.com> <20220526073215.428410-1-robinx.zhang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 Signed-off-by: Kevin Liu --- devtools/words-case.txt | 1 + lib/ethdev/meson.build | 1 + lib/ethdev/rte_ethdev.c | 3 + lib/ethdev/sff_telemetry.c | 139 +++++++++++++++++++++++++++++++++++++ lib/ethdev/sff_telemetry.h | 27 +++++++ 5 files changed, 171 insertions(+) create mode 100644 lib/ethdev/sff_telemetry.c create mode 100644 lib/ethdev/sff_telemetry.h diff --git a/devtools/words-case.txt b/devtools/words-case.txt index bc33470532..2f1753bdc8 100644 --- a/devtools/words-case.txt +++ b/devtools/words-case.txt @@ -76,6 +76,7 @@ RSS RVU Rx SCTP +SFF SMP SoC SQ diff --git a/lib/ethdev/meson.build b/lib/ethdev/meson.build index a094585bf7..6a14d0b402 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', + 'sff_telemetry.c', ) headers = files( diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index 29a3d80466..56814d2e54 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 "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"); } diff --git a/lib/ethdev/sff_telemetry.c b/lib/ethdev/sff_telemetry.c new file mode 100644 index 0000000000..7da4385223 --- /dev/null +++ b/lib/ethdev/sff_telemetry.c @@ -0,0 +1,139 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2022 Intel Corporation + */ + +#include + +#include "rte_ethdev.h" +#include +#include "sff_telemetry.h" +#include + +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, %d\n", errno); + return -1; + } + + if (*end_param != '\0') + RTE_ETHDEV_LOG(NOTICE, + "Extra parameters [%s] passed to ethdev telemetry command, ignoring\n", + end_param); + + rte_tel_data_start_dict(d); + + sff_port_module_eeprom_parse(port_id, d); + + return 0; +} diff --git a/lib/ethdev/sff_telemetry.h b/lib/ethdev/sff_telemetry.h new file mode 100644 index 0000000000..1fd870e0ef --- /dev/null +++ b/lib/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 + +#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_ */ -- 2.25.1