From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1F5D2A04C8; Fri, 18 Sep 2020 22:36:17 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C1A781DB38; Fri, 18 Sep 2020 22:36:15 +0200 (CEST) Received: from mail-ot1-f66.google.com (mail-ot1-f66.google.com [209.85.210.66]) by dpdk.org (Postfix) with ESMTP id 86E031DB28 for ; Fri, 18 Sep 2020 22:36:13 +0200 (CEST) Received: by mail-ot1-f66.google.com with SMTP id y5so6596413otg.5 for ; Fri, 18 Sep 2020 13:36:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+O5CajBsA6w3Ed8ZO4ETCgJ9jwNK2snJjVyuykiln5Q=; b=Eh/gDBpAlQDfiVWqa3zD0xjlO4OLI+Dfqb9bSD5iKOP9paZXecqqDdzWtyAYolB5dU 8m3b3L0+eLz/ZcuQnSECKt6n/rlo5WhWJ3PhRoqOO8djVDSJ9n1tHCFMa33hRoRWQf07 reGXPQN5X+Uh2CU4lK+Tg7qwJqpPXoL2NZy9U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+O5CajBsA6w3Ed8ZO4ETCgJ9jwNK2snJjVyuykiln5Q=; b=qXxeNC4TPFj7bsZtd6DxXr6RgYtWm/7Lqe1ab6k7W7rtDxl/8AHPSzgR2eOHcsoKOK CEBxR3+80IYJGlWqepMLXlpUjtsUBX/7JCwTgjmlzVN/eBbiyJ7cBLksgzMUhmIMi5IY c5SlluKoLY6u2D2UIjc1DMvLeSrUDkQCMiaXGwNcXaEayTjlsl1imIeSwvossYJS7Pla aaEf1tyAOAB2PXUQAupP/mEAdVqDpGuEzFX7v/vAgDs3SzkyQ5AtcvDYD+jcHjhnUpvs 3VhTc7s8W5hzQuEvdFhhedq2wJfzuPlSP/IsBHJXXOG/gNAJTkosZaQg5Y3ERMso0Ksg 86bw== X-Gm-Message-State: AOAM531fFreGmorWABI/EMnEzGlEUrD9r5VYS0TbzKN+mveaZ4eNtzC5 W2Sh56ud3FeE5fq58+YxDrEywXfNxII9CY0mOgpQlQ== X-Google-Smtp-Source: ABdhPJzDbPaMwjmtYgccstTXeuBJdXt70AuTkHolDME5ImOoWztozdZWwlhDMSrqvALsyIl0FT05Ewz3o/XVBFFMFqI= X-Received: by 2002:a9d:ae7:: with SMTP id 94mr25284693otq.283.1600461372572; Fri, 18 Sep 2020 13:36:12 -0700 (PDT) MIME-Version: 1.0 References: <1599534347-20430-1-git-send-email-humin29@huawei.com> <1600429707-6879-1-git-send-email-humin29@huawei.com> <1600429707-6879-4-git-send-email-humin29@huawei.com> In-Reply-To: <1600429707-6879-4-git-send-email-humin29@huawei.com> From: Ajit Khaparde Date: Fri, 18 Sep 2020 13:35:56 -0700 Message-ID: To: "Min Hu (Connor)" Cc: dpdk-dev , "Ananyev, Konstantin" , Thomas Monjalon , Andrew Rybchenko , Ferruh Yigit , linuxarm@huawei.com Content-Type: text/plain; charset="UTF-8" Subject: Re: [dpdk-dev] [PATCH V7 3/3] app/testpmd: add FEC command X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On Fri, Sep 18, 2020 at 4:51 AM Min Hu (Connor) wrote: > > 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 0 > > 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) > Reviewed-by: Wei Hu (Xavier) > Reviewed-by: Chengwen Feng > Reviewed-by: Chengchang Tang Acked-by: Ajit Khaparde > --- > v6->v7: > used RTE_DIM(fec_mode_name) instead of RTE_ETH_FEC_NUM > > --- > v5->v6: > fixed code styles according to DPDK coding style. > added _eth prefix. > > --- > v4->v5: > Add RTE_ prefix for public FEC mode enum. > > --- > v3->v4: > adjust the display format of FEC mode > > --- > 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..96da9aa 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; > + uint32_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 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_eth_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 RTE_ETH_FEC_NOFEC: > + strlcpy(buf, "off", sizeof(buf)); > + break; > + case RTE_ETH_FEC_BASER: > + strlcpy(buf, "baser", sizeof(buf)); > + break; > + case RTE_ETH_FEC_RS: > + strlcpy(buf, "rs", sizeof(buf)); > + break; > + case RTE_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 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_eth_fec_mode mode; > + int ret; > + > + ret = parse_fec_mode(res->fec_value, &mode); > + if (ret < 0) { > + printf("Unknown fec mode: %s for Port %d\n", 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 fec_mode ", > + .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..e35d61a 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_eth_fec_mode mode; > + const char *name; > +} fec_mode_name[] = { > + { > + .mode = RTE_ETH_FEC_NOFEC, > + .name = "off", > + }, > + { > + .mode = RTE_ETH_FEC_BASER, > + .name = "baser", > + }, > + { > + .mode = RTE_ETH_FEC_RS, > + .name = "rs", > + }, > + { > + .mode = RTE_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_eth_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(uint32_t fec_cap) > +{ > + uint32_t i; > + > + if (fec_cap == 0) { > + printf("FEC is not supported\n"); > + return; > + } > + > + printf("FEC capabilities: "); > + for (i = RTE_ETH_FEC_BASER; i < RTE_DIM(fec_mode_name); i++) { > + if (fec_cap & RTE_ETH_FEC_MODE_TO_CAPA(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..3be56e8 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_eth_fec_mode *mode); > +void show_fec_capability(uint32_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 >