DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Min Hu (Connor)" <humin29@huawei.com>
To: <dev@dpdk.org>
Cc: <ferruh.yigit@intel.com>, <stephen@networkplumber.org>,
	<bruce.richardson@intel.com>, <jerin.jacob@caviumnetworks.com>
Subject: [dpdk-dev] [PATCH V3  3/3] app/testpmd: add FEC command
Date: Wed, 9 Sep 2020 20:36:34 +0800	[thread overview]
Message-ID: <1599654994-39640-4-git-send-email-humin29@huawei.com> (raw)
In-Reply-To: <1599654994-39640-1-git-send-email-humin29@huawei.com>

This commit adds testpmd capability to query and config FEC
function of device. This includes:
- show FEC capabilities, example:
	testpmd> show port 0 fec capabilities
- show FEC mode, example:
	testpmd> show port 0 fec_mode
- config FEC mode, example:
	testpmd> set port <port_id> 0 <auto|off|rs|baser>

	where:

	auto|off|rs|baser are four kinds of FEC mode which dev
	support according to MAC link speed.

Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
Reviewed-by: Wei Hu (Xavier) <xavier.huwei@huawei.com>
Reviewed-by: Chengwen Feng <fengchengwen@huawei.com>
Reviewed-by: Chengchang Tang <tangchengchang@huawei.com>

----
v2->v3:
adjust the display format of FEC capability.
---
 app/test-pmd/cmdline.c | 219 +++++++++++++++++++++++++++++++++++++++++++++++++
 app/test-pmd/config.c  |  54 ++++++++++++
 app/test-pmd/testpmd.h |   2 +
 3 files changed, 275 insertions(+)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 0a6ed85..072f390 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -19054,6 +19054,222 @@ cmdline_parse_inst_t cmd_show_tx_metadata = {
 	},
 };
 
+/* *** show fec capability per port configuration *** */
+struct cmd_show_fec_capability_result {
+	cmdline_fixed_string_t cmd_show;
+	cmdline_fixed_string_t cmd_port;
+	cmdline_fixed_string_t cmd_fec;
+	cmdline_fixed_string_t cmd_keyword;
+	portid_t cmd_pid;
+};
+
+static void
+cmd_show_fec_capability_parsed(void *parsed_result,
+		__rte_unused struct cmdline *cl,
+		__rte_unused void *data)
+{
+	struct cmd_show_fec_capability_result *res = parsed_result;
+	uint8_t fec_cap;
+	int ret;
+
+	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
+		printf("Invalid port id %u\n", res->cmd_pid);
+		return;
+	}
+
+	ret = rte_eth_fec_get_capability(res->cmd_pid, &fec_cap);
+	if (ret == -ENOTSUP) {
+		printf("Function not implemented\n");
+		return;
+	} else if (ret < 0) {
+		printf("Get FEC capability failed\n");
+		return;
+	}
+
+	show_fec_capability(fec_cap);
+}
+
+cmdline_parse_token_string_t cmd_show_fec_capability_show =
+	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
+			cmd_show, "show");
+cmdline_parse_token_string_t cmd_show_fec_capability_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
+			cmd_port, "port");
+cmdline_parse_token_num_t cmd_show_fec_capability_pid =
+	TOKEN_NUM_INITIALIZER(struct cmd_show_fec_capability_result,
+			cmd_pid, UINT16);
+cmdline_parse_token_string_t cmd_show_fec_capability_fec =
+	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
+			cmd_fec, "fec");
+cmdline_parse_token_string_t cmd_show_fec_capability_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_capability_result,
+			cmd_keyword, "capabilities");
+
+cmdline_parse_inst_t cmd_show_capability = {
+	.f = cmd_show_fec_capability_parsed,
+	.data = NULL,
+	.help_str = "show port <port_id> fec capabilities",
+	.tokens = {
+		(void *)&cmd_show_fec_capability_show,
+		(void *)&cmd_show_fec_capability_port,
+		(void *)&cmd_show_fec_capability_pid,
+		(void *)&cmd_show_fec_capability_fec,
+		(void *)&cmd_show_fec_capability_keyword,
+		NULL,
+	},
+};
+
+/* *** show fec mode per port configuration *** */
+struct cmd_show_fec_metadata_result {
+	cmdline_fixed_string_t cmd_show;
+	cmdline_fixed_string_t cmd_port;
+	cmdline_fixed_string_t cmd_keyword;
+	portid_t cmd_pid;
+};
+
+static void
+cmd_show_fec_mode_parsed(void *parsed_result,
+		__rte_unused struct cmdline *cl,
+		__rte_unused void *data)
+{
+#define FEC_NAME_SIZE 16
+	struct cmd_show_fec_metadata_result *res = parsed_result;
+	enum rte_fec_mode mode;
+	char buf[FEC_NAME_SIZE];
+	int ret;
+
+	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
+		printf("Invalid port id %u\n", res->cmd_pid);
+		return;
+	}
+	ret = rte_eth_fec_get(res->cmd_pid, &mode);
+	if (ret == -ENOTSUP) {
+		printf("Function not implemented\n");
+		return;
+	} else if (ret < 0) {
+		printf("Get FEC mode failed\n");
+		return;
+	}
+
+	switch (mode) {
+	case ETH_FEC_NOFEC:
+		strlcpy(buf, "off", sizeof(buf));
+		break;
+	case ETH_FEC_BASER:
+		strlcpy(buf, "baser", sizeof(buf));
+		break;
+	case ETH_FEC_RS:
+		strlcpy(buf, "rs", sizeof(buf));
+		break;
+	case ETH_FEC_AUTO:
+		strlcpy(buf, "auto", sizeof(buf));
+		break;
+	default:
+		return;
+	}
+
+	printf("%s\n", buf);
+}
+
+cmdline_parse_token_string_t cmd_show_fec_mode_show =
+	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
+			cmd_show, "show");
+cmdline_parse_token_string_t cmd_show_fec_mode_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
+			cmd_port, "port");
+cmdline_parse_token_num_t cmd_show_fec_mode_pid =
+	TOKEN_NUM_INITIALIZER(struct cmd_show_fec_metadata_result,
+			cmd_pid, UINT16);
+cmdline_parse_token_string_t cmd_show_fec_mode_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_show_fec_metadata_result,
+			cmd_keyword, "fec_mode");
+
+cmdline_parse_inst_t cmd_show_fec_mode = {
+	.f = cmd_show_fec_mode_parsed,
+	.data = NULL,
+	.help_str = "show port <port_id> fec_mode",
+	.tokens = {
+		(void *)&cmd_show_fec_mode_show,
+		(void *)&cmd_show_fec_mode_port,
+		(void *)&cmd_show_fec_mode_pid,
+		(void *)&cmd_show_fec_mode_keyword,
+		NULL,
+	},
+};
+
+/* *** set fec mode per port configuration *** */
+struct cmd_set_port_fec_mode {
+	cmdline_fixed_string_t set;
+	cmdline_fixed_string_t port;
+	portid_t port_id;
+	cmdline_fixed_string_t fec_mode;
+	cmdline_fixed_string_t fec_value;
+};
+
+/* Common CLI fields for set fec mode */
+cmdline_parse_token_string_t cmd_set_port_fec_mode_set =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_set_port_fec_mode,
+		 set, "set");
+cmdline_parse_token_string_t cmd_set_port_fec_mode_port =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_set_port_fec_mode,
+		 port, "port");
+cmdline_parse_token_num_t cmd_set_port_fec_mode_port_id =
+	TOKEN_NUM_INITIALIZER
+		(struct cmd_set_port_fec_mode,
+		 port_id, UINT16);
+cmdline_parse_token_string_t cmd_set_port_fec_mode_str =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_set_port_fec_mode,
+		 fec_mode, "fec_mode");
+cmdline_parse_token_string_t cmd_set_port_fec_mode_value =
+	TOKEN_STRING_INITIALIZER
+		(struct cmd_set_port_fec_mode,
+		 fec_value, NULL);
+
+static void
+cmd_set_port_fec_mode_parsed(
+	void *parsed_result,
+	__rte_unused struct cmdline *cl,
+	__rte_unused void *data)
+{
+	struct cmd_set_port_fec_mode *res = parsed_result;
+	uint16_t port_id = res->port_id;
+	enum rte_fec_mode mode;
+	int ret;
+
+	ret = parse_fec_mode(res->fec_value, &mode);
+	if (ret < 0) {
+		printf("Unknown fec mode: %s for Port %d", res->fec_value,
+			port_id);
+		return;
+	}
+
+	ret = rte_eth_fec_set(port_id, mode);
+	if (ret == -ENOTSUP) {
+		printf("Function not implemented\n");
+		return;
+	} else if (ret < 0) {
+		printf("Set FEC mode failed\n");
+		return;
+	}
+}
+
+cmdline_parse_inst_t cmd_set_fec_mode = {
+	.f = cmd_set_port_fec_mode_parsed,
+	.data = NULL,
+	.help_str = "set port <port_id> fec_mode <auto|off|rs|baser>",
+	.tokens = {
+		(void *)&cmd_set_port_fec_mode_set,
+		(void *)&cmd_set_port_fec_mode_port,
+		(void *)&cmd_set_port_fec_mode_port_id,
+		(void *)&cmd_set_port_fec_mode_str,
+		(void *)&cmd_set_port_fec_mode_value,
+		NULL,
+	},
+};
+
 /* show port supported ptypes */
 
 /* Common result structure for show port ptypes */
@@ -19685,6 +19901,9 @@ cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_show_set_raw,
 	(cmdline_parse_inst_t *)&cmd_show_set_raw_all,
 	(cmdline_parse_inst_t *)&cmd_config_tx_dynf_specific,
+	(cmdline_parse_inst_t *)&cmd_show_fec_mode,
+	(cmdline_parse_inst_t *)&cmd_set_fec_mode,
+	(cmdline_parse_inst_t *)&cmd_show_capability,
 	NULL,
 };
 
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 30bee33..6048f19 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -138,6 +138,28 @@ const struct rss_type_info rss_type_table[] = {
 	{ NULL, 0 },
 };
 
+static const struct {
+	enum rte_fec_mode mode;
+	const char *name;
+} fec_mode_name[] = {
+	{
+		.mode = ETH_FEC_NOFEC,
+		.name = "off",
+	},
+	{
+		.mode = ETH_FEC_BASER,
+		.name = "baser",
+	},
+	{
+		.mode = ETH_FEC_RS,
+		.name = "rs",
+	},
+	{
+		.mode = ETH_FEC_AUTO,
+		.name = "auto",
+	},
+};
+
 static void
 print_ethaddr(const char *name, struct rte_ether_addr *eth_addr)
 {
@@ -2967,6 +2989,38 @@ set_tx_pkt_split(const char *name)
 	printf("unknown value: \"%s\"\n", name);
 }
 
+int
+parse_fec_mode(const char *name, enum rte_fec_mode *mode)
+{
+	uint8_t i;
+
+	for (i = 0; i < RTE_DIM(fec_mode_name); i++) {
+		if (strcmp(fec_mode_name[i].name, name) == 0) {
+			*mode = fec_mode_name[i].mode;
+			return 0;
+		}
+	}
+	return -1;
+}
+
+void
+show_fec_capability(uint8_t fec_cap)
+{
+	uint8_t i;
+
+	if (fec_cap == 0) {
+		printf("FEC is not supported\n");
+		return;
+	}
+
+	printf("FEC capabilities: ");
+	for (i = ETH_FEC_BASER; i <= ETH_FEC_AUTO; i++) {
+		if (fec_cap & 1U << i)
+			printf("%s ", fec_mode_name[i].name);
+	}
+	printf("\n");
+}
+
 void
 show_tx_pkt_segments(void)
 {
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 25a12b1..7ab91ad 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -778,6 +778,8 @@ void show_tx_pkt_segments(void);
 void set_tx_pkt_times(unsigned int *tx_times);
 void show_tx_pkt_times(void);
 void set_tx_pkt_split(const char *name);
+int parse_fec_mode(const char *name, enum rte_fec_mode *mode);
+void show_fec_capability(uint8_t fec_cap);
 void set_nb_pkt_per_burst(uint16_t pkt_burst);
 char *list_pkt_forwarding_modes(void);
 char *list_pkt_forwarding_retry_modes(void);
-- 
2.7.4


  parent reply	other threads:[~2020-09-09 12:39 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-31  3:41 [dpdk-dev] [RFC 1/2] Description: lib/ethdev: change data type in tc_rxq and tc_txq Min Hu(Connor)
2020-08-31  3:41 ` [dpdk-dev] [RFC 2/2] Description: dpdk: fix compiling errors for more than 256 per-queue statistics Min Hu(Connor)
2020-09-01  1:33 ` [dpdk-dev] [RFC 1/2] ethdev: change data type in TC rxq and TC txq Min Hu (Connor)
2020-09-01  1:33   ` [dpdk-dev] [RFC 2/2] ethdev: fix compiling errors for per-queue statistics Min Hu (Connor)
2020-09-01  2:23     ` Stephen Hemminger
2020-09-01 11:52   ` [dpdk-dev] [PATCH 0/4] ethdev: change the queue ID type Min Hu (Connor)
2020-09-01 11:52     ` [dpdk-dev] [PATCH 1/4] ethdev: change data type in TC rxq and TC txq Min Hu (Connor)
2020-09-04 11:32       ` [dpdk-dev] [PATCH V2 0/4] ethdev: change the queue ID type Min Hu (Connor)
2020-09-04 11:32         ` [dpdk-dev] [PATCH V2 1/4] ethdev: fix compiling errors for per-queue statistics Min Hu (Connor)
2020-09-04 18:04           ` Ferruh Yigit
2020-09-04 18:31           ` Ferruh Yigit
2020-09-05 16:51             ` Thomas Monjalon
2020-09-23  2:31             ` Min Hu (Connor)
2020-09-23  9:18               ` Ferruh Yigit
2020-09-25  8:58                 ` Min Hu (Connor)
2020-09-25  9:36                   ` Ferruh Yigit
2020-09-23 12:59           ` [dpdk-dev] [PATCH V3 0/4] change data type in TC queue Min Hu (Connor)
2020-09-23 12:59             ` [dpdk-dev] [PATCH V3 1/4] dpdk: fix compiling errors for per-queue statistics Min Hu (Connor)
2020-09-23 13:00             ` [dpdk-dev] [PATCH V3 2/4] ethdev: change data type in TC rxq and TC txq Min Hu (Connor)
2020-09-23 13:00             ` [dpdk-dev] [PATCH V3 3/4] doc: announce modified field in DCB TC queue mapping Min Hu (Connor)
2020-09-23 13:00             ` [dpdk-dev] [PATCH V3 4/4] doc: announce modified in queue stats mapping API Min Hu (Connor)
2020-09-25  9:41             ` [dpdk-dev] [PATCH V3 0/4] change data type in TC queue Ferruh Yigit
2020-09-04 11:32         ` [dpdk-dev] [PATCH V2 2/4] ethdev: change data type in TC rxq and TC txq Min Hu (Connor)
2020-09-04 11:32         ` [dpdk-dev] [PATCH V2 3/4] doc: announce modified field in DCB TC queue mapping Min Hu (Connor)
2020-09-04 11:32         ` [dpdk-dev] [PATCH V2 4/4] doc: announce modified field in ethdev API Min Hu (Connor)
2020-09-04 14:33         ` [dpdk-dev] [PATCH V2 0/4] ethdev: change the queue ID type Ferruh Yigit
2020-09-09 12:36       ` [dpdk-dev] [PATCH V3 0/3] add FEC support Min Hu (Connor)
2020-09-09 12:36         ` [dpdk-dev] [PATCH V3 1/3] ethdev: introduce FEC API Min Hu (Connor)
2020-09-09 12:36         ` [dpdk-dev] [PATCH V3 2/3] net/hns3: support FEC Min Hu (Connor)
2020-09-09 12:36         ` Min Hu (Connor) [this message]
2020-09-01 11:52     ` [dpdk-dev] [PATCH 2/4] ethdev: fix compiling errors for per-queue statistics Min Hu (Connor)
2020-09-01 16:17       ` Ferruh Yigit
2020-09-01 11:52     ` [dpdk-dev] [PATCH 3/4] doc: announce modified field in DCB TC queue mapping Min Hu (Connor)
2020-09-01 11:52     ` [dpdk-dev] [PATCH 4/4] doc: announce modified field in ethdev API Min Hu (Connor)
2020-09-01 16:14     ` [dpdk-dev] [PATCH 0/4] ethdev: change the queue ID type Ferruh Yigit
2020-09-25 12:51 ` [dpdk-dev] [PATCH V4 0/2] change data type in TC queue Min Hu (Connor)
2020-09-25 12:51   ` [dpdk-dev] [PATCH V4 1/2] dpdk: resolve compiling errors for per-queue stats Min Hu (Connor)
2020-09-25 12:51   ` [dpdk-dev] [PATCH V4 2/2] ethdev: change data type in TC rxq and TC txq Min Hu (Connor)
2020-09-25 13:14   ` [dpdk-dev] [PATCH V4 0/2] change data type in TC queue Ferruh Yigit
2020-09-27  3:16 ` [dpdk-dev] [PATCH V5 " Min Hu (Connor)
2020-09-27  3:16   ` [dpdk-dev] [PATCH V5 1/2] dpdk: resolve compiling errors for per-queue stats Min Hu (Connor)
2020-09-28  8:59     ` Ferruh Yigit
2020-09-28  9:16       ` [dpdk-dev] [dpdk-techboard] " Thomas Monjalon
2020-09-28 12:00         ` Ananyev, Konstantin
2020-09-28 13:47         ` Min Hu (Connor)
2020-09-28 15:35           ` Thomas Monjalon
2020-09-28 13:53         ` Ferruh Yigit
2020-09-28 15:24           ` Thomas Monjalon
2020-09-28 15:43             ` Stephen Hemminger
2020-10-05 12:23               ` Ferruh Yigit
2020-10-06  8:33                 ` Olivier Matz
2020-10-09 20:32                   ` Ferruh Yigit
2020-10-10  8:09                     ` Thomas Monjalon
2020-10-12 17:02                       ` Ferruh Yigit
2020-09-29  4:49           ` Min Hu (Connor)
2020-09-29  9:33             ` Thomas Monjalon
2020-09-29 13:46               ` Min Hu (Connor)
2020-09-28 11:52       ` Ananyev, Konstantin
2020-09-30  8:34       ` [dpdk-dev] " Kinsella, Ray
2020-09-27  3:16   ` [dpdk-dev] [PATCH V5 2/2] ethdev: change data type in TC rxq and TC txq Min Hu (Connor)
2020-09-28  9:04     ` Ferruh Yigit
2020-09-28  9:21       ` [dpdk-dev] [dpdk-techboard] " Thomas Monjalon
2020-10-05 12:26         ` Ferruh Yigit
2020-10-06 12:04           ` Ferruh Yigit

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=1599654994-39640-4-git-send-email-humin29@huawei.com \
    --to=humin29@huawei.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=jerin.jacob@caviumnetworks.com \
    --cc=stephen@networkplumber.org \
    /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).