From: Jie Hai <haijie1@huawei.com>
To: Thomas Monjalon <thomas@monjalon.net>,
Ferruh Yigit <ferruh.yigit@amd.com>,
Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Cc: <dev@dpdk.org>, <liudongdong3@huawei.com>
Subject: [PATCH v2 12/13] ethdev: support telemetry query FEC info
Date: Wed, 7 Jun 2023 15:42:07 +0800 [thread overview]
Message-ID: <20230607074209.4798-13-haijie1@huawei.com> (raw)
In-Reply-To: <20230607074209.4798-1-haijie1@huawei.com>
This patch supports getting FEC information by telemetry.
The command is like:
--> /ethdev/fec,0
{
"/ethdev/fec": {
"fec_mode": "off",
"fec_capability": {
"10_Gbps": "off auto baser"
}
}
}
Signed-off-by: Jie Hai <haijie1@huawei.com>
---
lib/ethdev/rte_ethdev_telemetry.c | 139 ++++++++++++++++++++++++++++++
1 file changed, 139 insertions(+)
diff --git a/lib/ethdev/rte_ethdev_telemetry.c b/lib/ethdev/rte_ethdev_telemetry.c
index d42901fe57b1..764cf8f203fb 100644
--- a/lib/ethdev/rte_ethdev_telemetry.c
+++ b/lib/ethdev/rte_ethdev_telemetry.c
@@ -11,6 +11,17 @@
#include "ethdev_driver.h"
#include "sff_telemetry.h"
+static const struct {
+ uint32_t capa;
+ const char *name;
+} rte_eth_fec_capa_name[] = {
+ { RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC), "off" },
+ { RTE_ETH_FEC_MODE_CAPA_MASK(AUTO), "auto" },
+ { RTE_ETH_FEC_MODE_CAPA_MASK(BASER), "baser" },
+ { RTE_ETH_FEC_MODE_CAPA_MASK(RS), "rs" },
+ { RTE_ETH_FEC_MODE_CAPA_MASK(LLRS), "llrs" },
+};
+
static int
eth_dev_parse_port_params(const char *params __rte_unused, uint16_t *port_id,
char **end_param, bool has_next)
@@ -783,6 +794,132 @@ eth_dev_handle_port_rss_info(const char *cmd __rte_unused,
return ret;
}
+static const char *
+eth_dev_fec_capa_to_string(uint32_t fec_capa)
+{
+ uint32_t i;
+
+ for (i = 0; i < RTE_DIM(rte_eth_fec_capa_name); i++) {
+ if ((fec_capa & rte_eth_fec_capa_name[i].capa) != 0)
+ return rte_eth_fec_capa_name[i].name;
+ }
+
+ return "unknown";
+}
+
+static void
+eth_dev_fec_capas_to_string(uint32_t fec_capa, char *fec_name, uint32_t len)
+{
+ bool valid = false;
+ size_t count = 0;
+ uint32_t i;
+
+ for (i = 0; i < RTE_DIM(rte_eth_fec_capa_name); i++) {
+ if ((fec_capa & rte_eth_fec_capa_name[i].capa) != 0) {
+ strlcat(fec_name, rte_eth_fec_capa_name[i].name, len);
+ count = strlcat(fec_name, " ", len);
+ valid = true;
+ }
+ }
+
+ if (!valid)
+ count = snprintf(fec_name, len, "unknown ");
+
+ if (count >= len) {
+ RTE_ETHDEV_LOG(WARNING, "FEC capa names may be truncated\n");
+ count = len;
+ }
+
+ fec_name[count - 1] = '\0';
+}
+
+static int
+eth_dev_get_fec_capability(uint16_t port_id, struct rte_tel_data *d)
+{
+ struct rte_eth_fec_capa *speed_fec_capa;
+ char fec_name[RTE_TEL_MAX_STRING_LEN];
+ char speed[RTE_TEL_MAX_STRING_LEN];
+ uint32_t capa_num;
+ uint32_t i, j;
+ int ret;
+
+ ret = rte_eth_fec_get_capability(port_id, NULL, 0);
+ if (ret <= 0)
+ return ret == 0 ? -EINVAL : ret;
+
+ capa_num = ret;
+ speed_fec_capa = calloc(capa_num, sizeof(struct rte_eth_fec_capa));
+ if (speed_fec_capa == NULL)
+ return -ENOMEM;
+
+ ret = rte_eth_fec_get_capability(port_id, speed_fec_capa, capa_num);
+ if (ret <= 0) {
+ ret = ret == 0 ? -EINVAL : ret;
+ goto out;
+ }
+
+ for (i = 0; i < capa_num; i++) {
+ memset(fec_name, 0, RTE_TEL_MAX_STRING_LEN);
+ eth_dev_fec_capas_to_string(speed_fec_capa[i].capa, fec_name,
+ RTE_TEL_MAX_STRING_LEN);
+
+ memset(speed, 0, RTE_TEL_MAX_STRING_LEN);
+ ret = snprintf(speed, RTE_TEL_MAX_STRING_LEN, "%s",
+ rte_eth_link_speed_to_str(speed_fec_capa[i].speed));
+ if (ret < 0)
+ goto out;
+
+ for (j = 0; j < strlen(speed); j++) {
+ if (speed[j] == ' ')
+ speed[j] = '_';
+ }
+
+ rte_tel_data_add_dict_string(d, speed, fec_name);
+ }
+
+out:
+ free(speed_fec_capa);
+ return ret > 0 ? 0 : ret;
+}
+
+static int
+eth_dev_handle_port_fec(const char *cmd __rte_unused,
+ const char *params,
+ struct rte_tel_data *d)
+{
+ struct rte_tel_data *fec_capas;
+ uint32_t fec_mode;
+ uint16_t port_id;
+ char *end_param;
+ int ret;
+
+ ret = eth_dev_parse_port_params(params, &port_id, &end_param, false);
+ if (ret < 0)
+ return ret;
+
+ ret = rte_eth_fec_get(port_id, &fec_mode);
+ if (ret != 0)
+ return ret;
+
+ rte_tel_data_start_dict(d);
+ rte_tel_data_add_dict_string(d, "fec_mode",
+ eth_dev_fec_capa_to_string(fec_mode));
+
+ fec_capas = rte_tel_data_alloc();
+ if (fec_capas == NULL)
+ return -ENOMEM;
+
+ rte_tel_data_start_dict(fec_capas);
+ ret = eth_dev_get_fec_capability(port_id, fec_capas);
+ if (ret != 0) {
+ rte_tel_data_free(fec_capas);
+ return ret;
+ }
+
+ rte_tel_data_add_dict_container(d, "fec_capability", fec_capas, 0);
+ return 0;
+}
+
RTE_INIT(ethdev_init_telemetry)
{
rte_telemetry_register_cmd("/ethdev/list", eth_dev_handle_port_list,
@@ -814,4 +951,6 @@ RTE_INIT(ethdev_init_telemetry)
"Returns DCB info for a port. Parameters: int port_id");
rte_telemetry_register_cmd("/ethdev/rss_info", eth_dev_handle_port_rss_info,
"Returns RSS info for a port. Parameters: int port_id");
+ rte_telemetry_register_cmd("/ethdev/fec", eth_dev_handle_port_fec,
+ "Returns FEC info for a port. Parameters: int port_id");
}
--
2.33.0
next prev parent reply other threads:[~2023-06-07 7:46 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-30 9:05 [PATCH 00/10] support telemetry query ethdev info Jie Hai
2023-05-30 9:05 ` [PATCH 01/10] ethdev: support telemetry query MAC addresses Jie Hai
2023-06-01 14:39 ` Ferruh Yigit
2023-05-30 9:05 ` [PATCH 02/10] ethdev: support RxTx offload display Jie Hai
2023-05-30 9:05 ` [PATCH 03/10] ethdev: support telemetry query flow ctrl info Jie Hai
2023-05-30 9:05 ` [PATCH 04/10] ethdev: support telemetry query Rx queue info Jie Hai
2023-05-30 9:05 ` [PATCH 05/10] ethdev: support telemetry query Tx " Jie Hai
2023-05-30 9:05 ` [PATCH 06/10] ethdev: add firmware version in telemetry info command Jie Hai
2023-05-30 9:05 ` [PATCH 07/10] ethdev: support telemetry query DCB info Jie Hai
2023-05-30 9:05 ` [PATCH 08/10] ethdev: support telemetry query RSS info Jie Hai
2023-05-30 9:05 ` [PATCH 09/10] ethdev: support telemetry query FEC info Jie Hai
2023-05-30 9:05 ` [PATCH 10/10] ethdev: support telemetry query VLAN info Jie Hai
2023-06-01 12:05 ` [PATCH 00/10] support telemetry query ethdev info Ferruh Yigit
2023-06-01 12:23 ` Jie Hai
2023-06-01 14:36 ` Ferruh Yigit
2023-06-05 6:19 ` Jie Hai
2023-06-07 7:41 ` [PATCH v2 00/13] " Jie Hai
2023-06-07 7:41 ` [PATCH v2 01/13] ethdev: fix incorrect argument of calloc Jie Hai
2023-06-07 11:35 ` Ferruh Yigit
2023-06-07 7:41 ` [PATCH v2 02/13] ethdev: extract telemetry codes to a file Jie Hai
2023-06-07 11:37 ` Ferruh Yigit
2023-06-07 7:41 ` [PATCH v2 03/13] ethdev: extract codes parsing port ID as a function Jie Hai
2023-06-07 11:37 ` Ferruh Yigit
2023-06-07 7:41 ` [PATCH v2 04/13] ethdev: support telemetry query MAC addresses Jie Hai
2023-06-07 7:42 ` [PATCH v2 05/13] ethdev: support RxTx offload display Jie Hai
2023-06-07 7:42 ` [PATCH v2 06/13] ethdev: support telemetry query flow ctrl info Jie Hai
2023-06-07 7:42 ` [PATCH v2 07/13] ethdev: support telemetry query Rx queue info Jie Hai
2023-06-07 7:42 ` [PATCH v2 08/13] ethdev: support telemetry query Tx " Jie Hai
2023-06-07 7:42 ` [PATCH v2 09/13] ethdev: add firmware version in telemetry info command Jie Hai
2023-06-07 7:42 ` [PATCH v2 10/13] ethdev: support telemetry query DCB info Jie Hai
2023-06-07 7:42 ` [PATCH v2 11/13] ethdev: support telemetry query RSS info Jie Hai
2023-06-07 14:08 ` Ferruh Yigit
2023-06-07 7:42 ` Jie Hai [this message]
2023-06-07 7:42 ` [PATCH v2 13/13] ethdev: support telemetry query VLAN info Jie Hai
2023-06-07 11:40 ` [PATCH v2 00/13] support telemetry query ethdev info Ferruh Yigit
2023-06-08 2:01 ` Jie Hai
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=20230607074209.4798-13-haijie1@huawei.com \
--to=haijie1@huawei.com \
--cc=andrew.rybchenko@oktetlabs.ru \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@amd.com \
--cc=liudongdong3@huawei.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).