app/testpmd: refactor config all RSS command
authorHuisong Li <lihuisong@huawei.com>
Wed, 29 Jun 2022 08:34:47 +0000 (16:34 +0800)
committerFerruh Yigit <ferruh.yigit@xilinx.com>
Wed, 29 Jun 2022 19:40:50 +0000 (21:40 +0200)
The "port config <port_id> rss-hash-key" and "show port <port_id>
rss-hash key" commands both use the 'rss_type_table[]' to get
'rss_types' or the RSS type name. So this patch uses the
'rss_type_table[]' to get the RSS types.  In this way, this command
naturally supports more individual types.

Suggested-by: Ferruh Yigit <ferruh.yigit@xilinx.com>
Signed-off-by: Huisong Li <lihuisong@huawei.com>
Acked-by: Ferruh Yigit <ferruh.yigit@xilinx.com>
app/test-pmd/cmdline.c
app/test-pmd/config.c
app/test-pmd/testpmd.h
doc/guides/testpmd_app_ug/testpmd_funcs.rst

index 0123f4a..b4fe9df 100644 (file)
@@ -693,9 +693,14 @@ static void cmd_help_long_parsed(void *parsed_result,
                        "    Enable or disable packet drop on all RX queues of all ports when no "
                        "receive buffers available.\n\n"
 
-                       "port config all rss (all|default|ip|tcp|udp|sctp|"
-                       "l2-payload|port|vxlan|geneve|nvgre|vxlan-gpe|ecpri|mpls|ipv4-chksum|l2tpv2|"
-                       "none|level-default|level-outer|level-inner|<flowtype_id>)\n"
+                       "port config all rss (all|default|level-default|level-outer|level-inner|"
+                       "ip|tcp|udp|sctp|tunnel|vlan|none|"
+                       "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
+                       "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
+                       "l2-payload|port|vxlan|geneve|nvgre|gtpu|eth|s-vlan|c-vlan|"
+                       "esp|ah|l2tpv3|pfcp|pppoe|ecpri|mpls|ipv4-chksum|l4-chksum|"
+                       "l2tpv2|l3-pre96|l3-pre64|l3-pre56|l3-pre48|l3-pre40|l3-pre32|"
+                       "l2-dst-only|l2-src-only|l4-dst-only|l4-src-only|l3-dst-only|l3-src-only|<rsstype_id>)\n"
                        "    Set the RSS mode.\n\n"
 
                        "port config port-id rss reta (hash,queue)[,(hash,queue)]\n"
@@ -2062,81 +2067,7 @@ cmd_config_rss_parsed(void *parsed_result,
        uint16_t i;
        int ret;
 
-       if (!strcmp(res->value, "all"))
-               rss_conf.rss_hf = RTE_ETH_RSS_ETH | RTE_ETH_RSS_VLAN | RTE_ETH_RSS_IP |
-                       RTE_ETH_RSS_TCP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_SCTP |
-                       RTE_ETH_RSS_L2_PAYLOAD | RTE_ETH_RSS_L2TPV3 | RTE_ETH_RSS_ESP |
-                       RTE_ETH_RSS_AH | RTE_ETH_RSS_PFCP | RTE_ETH_RSS_GTPU |
-                       RTE_ETH_RSS_ECPRI | RTE_ETH_RSS_L2TPV2;
-       else if (!strcmp(res->value, "eth"))
-               rss_conf.rss_hf = RTE_ETH_RSS_ETH;
-       else if (!strcmp(res->value, "vlan"))
-               rss_conf.rss_hf = RTE_ETH_RSS_VLAN;
-       else if (!strcmp(res->value, "ip"))
-               rss_conf.rss_hf = RTE_ETH_RSS_IP;
-       else if (!strcmp(res->value, "udp"))
-               rss_conf.rss_hf = RTE_ETH_RSS_UDP;
-       else if (!strcmp(res->value, "tcp"))
-               rss_conf.rss_hf = RTE_ETH_RSS_TCP;
-       else if (!strcmp(res->value, "sctp"))
-               rss_conf.rss_hf = RTE_ETH_RSS_SCTP;
-       else if (!strcmp(res->value, "l2_payload"))
-               rss_conf.rss_hf = RTE_ETH_RSS_L2_PAYLOAD;
-       else if (!strcmp(res->value, "port"))
-               rss_conf.rss_hf = RTE_ETH_RSS_PORT;
-       else if (!strcmp(res->value, "vxlan"))
-               rss_conf.rss_hf = RTE_ETH_RSS_VXLAN;
-       else if (!strcmp(res->value, "geneve"))
-               rss_conf.rss_hf = RTE_ETH_RSS_GENEVE;
-       else if (!strcmp(res->value, "nvgre"))
-               rss_conf.rss_hf = RTE_ETH_RSS_NVGRE;
-       else if (!strcmp(res->value, "l3-pre32"))
-               rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE32;
-       else if (!strcmp(res->value, "l3-pre40"))
-               rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE40;
-       else if (!strcmp(res->value, "l3-pre48"))
-               rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE48;
-       else if (!strcmp(res->value, "l3-pre56"))
-               rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE56;
-       else if (!strcmp(res->value, "l3-pre64"))
-               rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE64;
-       else if (!strcmp(res->value, "l3-pre96"))
-               rss_conf.rss_hf = RTE_ETH_RSS_L3_PRE96;
-       else if (!strcmp(res->value, "l3-src-only"))
-               rss_conf.rss_hf = RTE_ETH_RSS_L3_SRC_ONLY;
-       else if (!strcmp(res->value, "l3-dst-only"))
-               rss_conf.rss_hf = RTE_ETH_RSS_L3_DST_ONLY;
-       else if (!strcmp(res->value, "l4-src-only"))
-               rss_conf.rss_hf = RTE_ETH_RSS_L4_SRC_ONLY;
-       else if (!strcmp(res->value, "l4-dst-only"))
-               rss_conf.rss_hf = RTE_ETH_RSS_L4_DST_ONLY;
-       else if (!strcmp(res->value, "l2-src-only"))
-               rss_conf.rss_hf = RTE_ETH_RSS_L2_SRC_ONLY;
-       else if (!strcmp(res->value, "l2-dst-only"))
-               rss_conf.rss_hf = RTE_ETH_RSS_L2_DST_ONLY;
-       else if (!strcmp(res->value, "l2tpv3"))
-               rss_conf.rss_hf = RTE_ETH_RSS_L2TPV3;
-       else if (!strcmp(res->value, "esp"))
-               rss_conf.rss_hf = RTE_ETH_RSS_ESP;
-       else if (!strcmp(res->value, "ah"))
-               rss_conf.rss_hf = RTE_ETH_RSS_AH;
-       else if (!strcmp(res->value, "pfcp"))
-               rss_conf.rss_hf = RTE_ETH_RSS_PFCP;
-       else if (!strcmp(res->value, "pppoe"))
-               rss_conf.rss_hf = RTE_ETH_RSS_PPPOE;
-       else if (!strcmp(res->value, "gtpu"))
-               rss_conf.rss_hf = RTE_ETH_RSS_GTPU;
-       else if (!strcmp(res->value, "ecpri"))
-               rss_conf.rss_hf = RTE_ETH_RSS_ECPRI;
-       else if (!strcmp(res->value, "mpls"))
-               rss_conf.rss_hf = RTE_ETH_RSS_MPLS;
-       else if (!strcmp(res->value, "ipv4-chksum"))
-               rss_conf.rss_hf = RTE_ETH_RSS_IPV4_CHKSUM;
-       else if (!strcmp(res->value, "l2tpv2"))
-               rss_conf.rss_hf = RTE_ETH_RSS_L2TPV2;
-       else if (!strcmp(res->value, "none"))
-               rss_conf.rss_hf = 0;
-       else if (!strcmp(res->value, "level-default")) {
+       if (!strcmp(res->value, "level-default")) {
                rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
                rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_PMD_DEFAULT);
        } else if (!strcmp(res->value, "level-outer")) {
@@ -2145,14 +2076,24 @@ cmd_config_rss_parsed(void *parsed_result,
        } else if (!strcmp(res->value, "level-inner")) {
                rss_hf &= (~RTE_ETH_RSS_LEVEL_MASK);
                rss_conf.rss_hf = (rss_hf | RTE_ETH_RSS_LEVEL_INNERMOST);
-       } else if (!strcmp(res->value, "default"))
+       } else if (!strcmp(res->value, "default")) {
                use_default = 1;
-       else if (isdigit(res->value[0]) && atoi(res->value) > 0 &&
-                                               atoi(res->value) < 64)
-               rss_conf.rss_hf = 1ULL << atoi(res->value);
-       else {
-               fprintf(stderr, "Unknown parameter\n");
-               return;
+       } else if (isdigit(res->value[0])) {
+               int value = atoi(res->value);
+               if (value > 0 && value < 64)
+                       rss_conf.rss_hf = 1ULL << (uint8_t)value;
+               else {
+                       fprintf(stderr, "flowtype_id should be greater than 0 and less than 64.\n");
+                       return;
+               }
+       } else if (!strcmp(res->value, "none")) {
+               rss_conf.rss_hf = 0;
+       } else {
+               rss_conf.rss_hf = str_to_rsstypes(res->value);
+               if (rss_conf.rss_hf == 0) {
+                       fprintf(stderr, "Unknown parameter\n");
+                       return;
+               }
        }
        rss_conf.rss_key = NULL;
        /* Update global configuration for RSS types. */
@@ -2203,9 +2144,14 @@ static cmdline_parse_inst_t cmd_config_rss = {
        .f = cmd_config_rss_parsed,
        .data = NULL,
        .help_str = "port config all rss "
-               "all|default|eth|vlan|ip|tcp|udp|sctp|l2-payload|port|vxlan|geneve|"
-               "nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|ecpri|mpls|ipv4-chksum|l2tpv2|"
-               "none|level-default|level-outer|level-inner|<flowtype_id>",
+               "all|default|level-default|level-outer|level-inner|"
+               "ip|tcp|udp|sctp|tunnel|vlan|none|"
+               "ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|"
+               "ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex|"
+               "l2-payload|port|vxlan|geneve|nvgre|gtpu|eth|s-vlan|c-vlan|"
+               "esp|ah|l2tpv3|pfcp|pppoe|ecpri|mpls|ipv4-chksum|l4-chksum|"
+               "l2tpv2|l3-pre96|l3-pre64|l3-pre56|l3-pre48|l3-pre40|l3-pre32|"
+               "l2-dst-only|l2-src-only|l4-dst-only|l4-src-only|l3-dst-only|l3-src-only|<rsstype_id>",
        .tokens = {
                (void *)&cmd_config_rss_port,
                (void *)&cmd_config_rss_keyword,
index a1183ad..a8fd844 100644 (file)
@@ -673,6 +673,19 @@ print_dev_capabilities(uint64_t capabilities)
        }
 }
 
+uint64_t
+str_to_rsstypes(const char *str)
+{
+       uint16_t i;
+
+       for (i = 0; rss_type_table[i].str != NULL; i++) {
+               if (strcmp(rss_type_table[i].str, str) == 0)
+                       return rss_type_table[i].rss_type;
+       }
+
+       return 0;
+}
+
 const char *
 rsstypes_to_str(uint64_t rss_type)
 {
@@ -3856,15 +3869,10 @@ port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key,
 {
        struct rte_eth_rss_conf rss_conf;
        int diag;
-       unsigned int i;
 
        rss_conf.rss_key = NULL;
        rss_conf.rss_key_len = 0;
-       rss_conf.rss_hf = 0;
-       for (i = 0; rss_type_table[i].str; i++) {
-               if (!strcmp(rss_type_table[i].str, rss_type))
-                       rss_conf.rss_hf = rss_type_table[i].rss_type;
-       }
+       rss_conf.rss_hf = str_to_rsstypes(rss_type);
        diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf);
        if (diag == 0) {
                rss_conf.rss_key = hash_key;
index 195488b..2e2987e 100644 (file)
@@ -1199,6 +1199,7 @@ extern int flow_parse(const char *src, void *result, unsigned int size,
                      struct rte_flow_item **pattern,
                      struct rte_flow_action **actions);
 
+uint64_t str_to_rsstypes(const char *str);
 const char *rsstypes_to_str(uint64_t rss_type);
 
 /* For registering driver specific testpmd commands. */
index 9a79ffd..b0bb912 100644 (file)
@@ -2143,8 +2143,15 @@ port config - RSS
 ~~~~~~~~~~~~~~~~~
 
 Set the RSS (Receive Side Scaling) mode on or off::
-
-   testpmd> port config all rss (all|default|eth|vlan|ip|tcp|udp|sctp|l2-payload|port|vxlan|geneve|nvgre|vxlan-gpe|l2tpv3|esp|ah|pfcp|ecpri|mpls|l2tpv2|none)
+   testpmd> port config all rss (all|default|level-default|level-outer|level-inner| \
+                                 ip|tcp|udp|sctp|tunnel|vlan|none| \
+                                 ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other| \
+                                 ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp| \
+                                 ipv6-other|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex| \
+                                 l2-payload|port|vxlan|geneve|nvgre|gtpu|eth|s-vlan|c-vlan| \
+                                 esp|ah|l2tpv3|pfcp|pppoe|ecpri|mpls|ipv4-chksum|l4-chksum| \
+                                 l2tpv2|l3-pre96|l3-pre64|l3-pre56|l3-pre48|l3-pre40|l3-pre32| \
+                                 l2-dst-only|l2-src-only|l4-dst-only|l4-src-only|l3-dst-only|l3-src-only|<rsstype_id>)
 
 RSS is on by default.