[2/3] app/testpmd: remove duplicated flow type to string table

Message ID 20220525173736.3394787-2-ferruh.yigit@xilinx.com (mailing list archive)
State Changes Requested, archived
Delegated to: Andrew Rybchenko
Headers
Series [1/3] app/testpmd: fix displaying RSS info |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Ferruh Yigit May 25, 2022, 5:37 p.m. UTC
  Flow type table has two instance, one is used for flow type to string
conversion, and other is used for string to flow type conversion.
And tables are diverged by time.

Unifying tables to prevent maintaining two different tables.

Note: made 'flowtype_to_str()' non-static to prevent build error for the
case PMDs using it disables. Making function generic, not for some PMDs.

Signed-off-by: Ferruh Yigit <ferruh.yigit@xilinx.com>
---
Cc: Kirill Rybalchenko <kirill.rybalchenko@intel.com>
---
 app/test-pmd/cmdline.c | 41 +-------------------
 app/test-pmd/config.c  | 87 +++++++++++++++++++++++++-----------------
 app/test-pmd/testpmd.h |  2 +
 3 files changed, 55 insertions(+), 75 deletions(-)
  

Patch

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index d8900a0d0704..becb3d772fad 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -10572,45 +10572,6 @@  do { \
 
 #ifdef RTE_NET_I40E
 
-static uint16_t
-str2flowtype(char *string)
-{
-	uint8_t i = 0;
-	static const struct {
-		char str[32];
-		uint16_t type;
-	} flowtype_str[] = {
-		{"raw", RTE_ETH_FLOW_RAW},
-		{"ipv4", RTE_ETH_FLOW_IPV4},
-		{"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
-		{"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
-		{"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
-		{"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
-		{"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
-		{"ipv6", RTE_ETH_FLOW_IPV6},
-		{"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
-		{"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
-		{"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
-		{"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
-		{"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
-		{"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
-		{"ipv6-ex", RTE_ETH_FLOW_IPV6_EX},
-		{"ipv6-tcp-ex", RTE_ETH_FLOW_IPV6_TCP_EX},
-		{"ipv6-udp-ex", RTE_ETH_FLOW_IPV6_UDP_EX},
-		{"gtpu", RTE_ETH_FLOW_GTPU},
-	};
-
-	for (i = 0; i < RTE_DIM(flowtype_str); i++) {
-		if (!strcmp(flowtype_str[i].str, string))
-			return flowtype_str[i].type;
-	}
-
-	if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64)
-		return (uint16_t)atoi(string);
-
-	return RTE_ETH_FLOW_UNKNOWN;
-}
-
 /* *** deal with flow director filter *** */
 struct cmd_flow_director_result {
 	cmdline_fixed_string_t flow_director_filter;
@@ -10639,7 +10600,7 @@  cmd_flow_director_filter_parsed(void *parsed_result,
 	struct rte_pmd_i40e_flow_type_mapping
 			mapping[RTE_PMD_I40E_FLOW_TYPE_MAX];
 	struct rte_pmd_i40e_pkt_template_conf conf;
-	uint16_t flow_type = str2flowtype(res->flow_type);
+	uint16_t flow_type = str_to_flowtype(res->flow_type);
 	uint16_t i, port = res->port_id;
 	uint8_t add;
 
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index c353d224ef06..47de5b6d9458 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -66,8 +66,6 @@ 
 
 #define NS_PER_SEC 1E9
 
-static char *flowtype_to_str(uint16_t flow_type);
-
 static const struct {
 	enum tx_pkt_split split;
 	const char *name;
@@ -5640,40 +5638,39 @@  set_record_burst_stats(uint8_t on_off)
 	record_burst_stats = on_off;
 }
 
-static char*
+static const struct {
+	char str[32];
+	uint16_t ftype;
+} flowtype_str_table[] = {
+	{"raw", RTE_ETH_FLOW_RAW},
+	{"ipv4", RTE_ETH_FLOW_IPV4},
+	{"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
+	{"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
+	{"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
+	{"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
+	{"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
+	{"ipv6", RTE_ETH_FLOW_IPV6},
+	{"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
+	{"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
+	{"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
+	{"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
+	{"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
+	{"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
+	{"ipv6-ex", RTE_ETH_FLOW_IPV6_EX},
+	{"ipv6-tcp-ex", RTE_ETH_FLOW_IPV6_TCP_EX},
+	{"ipv6-udp-ex", RTE_ETH_FLOW_IPV6_UDP_EX},
+	{"port", RTE_ETH_FLOW_PORT},
+	{"vxlan", RTE_ETH_FLOW_VXLAN},
+	{"geneve", RTE_ETH_FLOW_GENEVE},
+	{"nvgre", RTE_ETH_FLOW_NVGRE},
+	{"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
+	{"gtpu", RTE_ETH_FLOW_GTPU},
+};
+
+const char*
 flowtype_to_str(uint16_t flow_type)
 {
-	struct flow_type_info {
-		char str[32];
-		uint16_t ftype;
-	};
-
 	uint8_t i;
-	static struct flow_type_info flowtype_str_table[] = {
-		{"raw", RTE_ETH_FLOW_RAW},
-		{"ipv4", RTE_ETH_FLOW_IPV4},
-		{"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4},
-		{"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP},
-		{"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP},
-		{"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP},
-		{"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER},
-		{"ipv6", RTE_ETH_FLOW_IPV6},
-		{"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6},
-		{"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP},
-		{"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP},
-		{"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP},
-		{"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER},
-		{"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD},
-		{"ipv6-ex", RTE_ETH_FLOW_IPV6_EX},
-		{"ipv6-tcp-ex", RTE_ETH_FLOW_IPV6_TCP_EX},
-		{"ipv6-udp-ex", RTE_ETH_FLOW_IPV6_UDP_EX},
-		{"port", RTE_ETH_FLOW_PORT},
-		{"vxlan", RTE_ETH_FLOW_VXLAN},
-		{"geneve", RTE_ETH_FLOW_GENEVE},
-		{"nvgre", RTE_ETH_FLOW_NVGRE},
-		{"vxlan-gpe", RTE_ETH_FLOW_VXLAN_GPE},
-		{"gtpu", RTE_ETH_FLOW_GTPU},
-	};
 
 	for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
 		if (flowtype_str_table[i].ftype == flow_type)
@@ -5683,6 +5680,26 @@  flowtype_to_str(uint16_t flow_type)
 	return NULL;
 }
 
+uint16_t
+str_to_flowtype(const char *string)
+{
+	uint8_t i;
+
+	for (i = 0; i < RTE_DIM(flowtype_str_table); i++) {
+		if (!strcmp(flowtype_str_table[i].str, string))
+			return flowtype_str_table[i].ftype;
+	}
+
+	if (isdigit(string[0])) {
+		int val = atoi(string);
+
+		if (val > 0 && val < 64)
+			return (uint16_t)val;
+	}
+
+	return RTE_ETH_FLOW_UNKNOWN;
+}
+
 #if defined(RTE_NET_I40E) || defined(RTE_NET_IXGBE)
 
 static inline void
@@ -5749,7 +5766,7 @@  print_fdir_flex_mask(struct rte_eth_fdir_flex_conf *flex_conf, uint32_t num)
 {
 	struct rte_eth_fdir_flex_mask *mask;
 	uint32_t i, j;
-	char *p;
+	const char *p;
 
 	for (i = 0; i < flex_conf->nb_flexmasks; i++) {
 		mask = &flex_conf->flex_mask[i];
@@ -5765,7 +5782,7 @@  static inline void
 print_fdir_flow_type(uint32_t flow_types_mask)
 {
 	int i;
-	char *p;
+	const char *p;
 
 	for (i = RTE_ETH_FLOW_UNKNOWN; i < RTE_ETH_FLOW_MAX; i++) {
 		if (!(flow_types_mask & (1 << i)))
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 203311bcc29e..5ca297215514 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -1086,6 +1086,8 @@  void fdir_set_flex_payload(portid_t port_id,
 void port_rss_reta_info(portid_t port_id,
 			struct rte_eth_rss_reta_entry64 *reta_conf,
 			uint16_t nb_entries);
+uint16_t str_to_flowtype(const char *string);
+const char *flowtype_to_str(uint16_t flow_type);
 
 void set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on);