[v2,2/2] net/ice: map group to pipeline stage

Message ID 20230911165134.3671218-3-qi.z.zhang@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Qi Zhang
Headers
Series refactor rte_flow |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/intel-Functional success Functional PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS

Commit Message

Qi Zhang Sept. 11, 2023, 4:51 p.m. UTC
  Mapping rte_flow_attr->group to a specific hardware stage.

Group 0 -> switch filter
Group 1 -> acl filter
Group 2 -> fdir filter

For RSS, it will only be selected if there is a RTE_FLOW_ACTION_RSS
action target no queue group and the group ID is ignored.

Since each flow parser will be selected based on the group, there is no
need to maintain a separate 'parser list' or related APIs for
registering/unregistering parsers.

Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
---
 drivers/net/ice/ice_acl_filter.c    |  13 +-
 drivers/net/ice/ice_ethdev.h        |   2 -
 drivers/net/ice/ice_fdir_filter.c   |  19 +--
 drivers/net/ice/ice_generic_flow.c  | 188 +++++++---------------------
 drivers/net/ice/ice_generic_flow.h  |   9 +-
 drivers/net/ice/ice_hash.c          |  19 +--
 drivers/net/ice/ice_switch_filter.c |  13 +-
 7 files changed, 62 insertions(+), 201 deletions(-)
  

Patch

diff --git a/drivers/net/ice/ice_acl_filter.c b/drivers/net/ice/ice_acl_filter.c
index f2ddbd7b9b..d79044732a 100644
--- a/drivers/net/ice/ice_acl_filter.c
+++ b/drivers/net/ice/ice_acl_filter.c
@@ -41,8 +41,6 @@ 
 	ICE_ACL_INSET_ETH_IPV4 | \
 	ICE_INSET_SCTP_SRC_PORT | ICE_INSET_SCTP_DST_PORT)
 
-static struct ice_flow_parser ice_acl_parser;
-
 struct acl_rule {
 	enum ice_fltr_ptype flow_type;
 	uint64_t entry_id[4];
@@ -993,7 +991,6 @@  ice_acl_init(struct ice_adapter *ad)
 	int ret = 0;
 	struct ice_pf *pf = &ad->pf;
 	struct ice_hw *hw = ICE_PF_TO_HW(pf);
-	struct ice_flow_parser *parser = &ice_acl_parser;
 
 	if (!ad->hw.dcf_enabled)
 		return 0;
@@ -1013,11 +1010,7 @@  ice_acl_init(struct ice_adapter *ad)
 	if (ret)
 		return ret;
 
-	ret = ice_acl_prof_init(pf);
-	if (ret)
-		return ret;
-
-	return ice_register_parser(parser, ad);
+	return ice_acl_prof_init(pf);
 }
 
 static void
@@ -1040,10 +1033,8 @@  ice_acl_uninit(struct ice_adapter *ad)
 {
 	struct ice_pf *pf = &ad->pf;
 	struct ice_hw *hw = ICE_PF_TO_HW(pf);
-	struct ice_flow_parser *parser = &ice_acl_parser;
 
 	if (ad->hw.dcf_enabled) {
-		ice_unregister_parser(parser, ad);
 		ice_deinit_acl(pf);
 		ice_acl_prof_free(hw);
 	}
@@ -1059,7 +1050,7 @@  ice_flow_engine ice_acl_engine = {
 	.type = ICE_FLOW_ENGINE_ACL,
 };
 
-static struct
+struct
 ice_flow_parser ice_acl_parser = {
 	.engine = &ice_acl_engine,
 	.array = ice_acl_pattern,
diff --git a/drivers/net/ice/ice_ethdev.h b/drivers/net/ice/ice_ethdev.h
index 1f88becd19..abe6dcdc23 100644
--- a/drivers/net/ice/ice_ethdev.h
+++ b/drivers/net/ice/ice_ethdev.h
@@ -541,8 +541,6 @@  struct ice_pf {
 	bool adapter_stopped;
 	struct ice_flow_list flow_list;
 	rte_spinlock_t flow_ops_lock;
-	struct ice_parser_list rss_parser_list;
-	struct ice_parser_list dist_parser_list;
 	bool init_link_up;
 	uint64_t old_rx_bytes;
 	uint64_t old_tx_bytes;
diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index e9ee5a57d6..9ce243cc9c 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -137,8 +137,6 @@  static struct ice_pattern_match_item ice_fdir_pattern_list[] = {
 	{pattern_eth_ipv6_gtpu_eh,			ICE_FDIR_INSET_IPV6_GTPU_EH,	ICE_FDIR_INSET_IPV6_GTPU_EH,	ICE_INSET_NONE},
 };
 
-static struct ice_flow_parser ice_fdir_parser;
-
 static int
 ice_fdir_is_tunnel_profile(enum ice_fdir_tunnel_type tunnel_type);
 
@@ -1147,34 +1145,21 @@  static int
 ice_fdir_init(struct ice_adapter *ad)
 {
 	struct ice_pf *pf = &ad->pf;
-	struct ice_flow_parser *parser;
-	int ret;
 
 	if (ad->hw.dcf_enabled)
 		return 0;
 
-	ret = ice_fdir_setup(pf);
-	if (ret)
-		return ret;
-
-	parser = &ice_fdir_parser;
-
-	return ice_register_parser(parser, ad);
+	return ice_fdir_setup(pf);
 }
 
 static void
 ice_fdir_uninit(struct ice_adapter *ad)
 {
-	struct ice_flow_parser *parser;
 	struct ice_pf *pf = &ad->pf;
 
 	if (ad->hw.dcf_enabled)
 		return;
 
-	parser = &ice_fdir_parser;
-
-	ice_unregister_parser(parser, ad);
-
 	ice_fdir_teardown(pf);
 }
 
@@ -2510,7 +2495,7 @@  ice_fdir_parse(struct ice_adapter *ad,
 	return ret;
 }
 
-static struct ice_flow_parser ice_fdir_parser = {
+struct ice_flow_parser ice_fdir_parser = {
 	.engine = &ice_fdir_engine,
 	.array = ice_fdir_pattern_list,
 	.array_len = RTE_DIM(ice_fdir_pattern_list),
diff --git a/drivers/net/ice/ice_generic_flow.c b/drivers/net/ice/ice_generic_flow.c
index 6695457bbd..e71e060653 100644
--- a/drivers/net/ice/ice_generic_flow.c
+++ b/drivers/net/ice/ice_generic_flow.c
@@ -1797,7 +1797,7 @@  enum rte_flow_item_type pattern_eth_ipv6_pfcp[] = {
 
 typedef struct ice_flow_engine * (*parse_engine_t)(struct ice_adapter *ad,
 		struct rte_flow *flow,
-		struct ice_parser_list *parser_list,
+		struct ice_flow_parser *parser,
 		uint32_t priority,
 		const struct rte_flow_item pattern[],
 		const struct rte_flow_action actions[],
@@ -1818,8 +1818,6 @@  ice_flow_init(struct ice_adapter *ad)
 	struct ice_flow_engine *engine;
 
 	TAILQ_INIT(&pf->flow_list);
-	TAILQ_INIT(&pf->rss_parser_list);
-	TAILQ_INIT(&pf->dist_parser_list);
 	rte_spinlock_init(&pf->flow_ops_lock);
 
 	if (ice_parser_create(&ad->hw, &ad->psr) != ICE_SUCCESS)
@@ -1860,7 +1858,6 @@  ice_flow_uninit(struct ice_adapter *ad)
 	struct ice_pf *pf = &ad->pf;
 	struct ice_flow_engine *engine;
 	struct rte_flow *p_flow;
-	struct ice_flow_parser_node *p_parser;
 	void *temp;
 
 	RTE_TAILQ_FOREACH_SAFE(engine, &engine_list, node, temp) {
@@ -1881,117 +1878,12 @@  ice_flow_uninit(struct ice_adapter *ad)
 		rte_free(p_flow);
 	}
 
-	/* Cleanup parser list */
-	while ((p_parser = TAILQ_FIRST(&pf->rss_parser_list))) {
-		TAILQ_REMOVE(&pf->rss_parser_list, p_parser, node);
-		rte_free(p_parser);
-	}
-
-	while ((p_parser = TAILQ_FIRST(&pf->dist_parser_list))) {
-		TAILQ_REMOVE(&pf->dist_parser_list, p_parser, node);
-		rte_free(p_parser);
-	}
-
 	if (ad->psr != NULL) {
 		ice_parser_destroy(ad->psr);
 		ad->psr = NULL;
 	}
 }
 
-static struct ice_parser_list *
-ice_get_parser_list(struct ice_flow_parser *parser,
-		struct ice_adapter *ad)
-{
-	struct ice_parser_list *list;
-	struct ice_pf *pf = &ad->pf;
-
-	switch (parser->stage) {
-	case ICE_FLOW_STAGE_RSS:
-		list = &pf->rss_parser_list;
-		break;
-	case ICE_FLOW_STAGE_DISTRIBUTOR:
-		list = &pf->dist_parser_list;
-		break;
-	default:
-		return NULL;
-	}
-
-	return list;
-}
-
-int
-ice_register_parser(struct ice_flow_parser *parser,
-		struct ice_adapter *ad)
-{
-	struct ice_parser_list *list;
-	struct ice_flow_parser_node *parser_node;
-	struct ice_flow_parser_node *existing_node;
-	void *temp;
-
-	parser_node = rte_zmalloc("ice_parser", sizeof(*parser_node), 0);
-	if (parser_node == NULL) {
-		PMD_DRV_LOG(ERR, "Failed to allocate memory.");
-		return -ENOMEM;
-	}
-	parser_node->parser = parser;
-
-	list = ice_get_parser_list(parser, ad);
-	if (list == NULL)
-		return -EINVAL;
-
-	if (parser->engine->type == ICE_FLOW_ENGINE_SWITCH) {
-		RTE_TAILQ_FOREACH_SAFE(existing_node, list,
-				       node, temp) {
-			if (existing_node->parser->engine->type ==
-			    ICE_FLOW_ENGINE_ACL) {
-				TAILQ_INSERT_AFTER(list, existing_node,
-						   parser_node, node);
-				goto DONE;
-			}
-		}
-		TAILQ_INSERT_HEAD(list, parser_node, node);
-	} else if (parser->engine->type == ICE_FLOW_ENGINE_FDIR) {
-		RTE_TAILQ_FOREACH_SAFE(existing_node, list,
-				       node, temp) {
-			if (existing_node->parser->engine->type ==
-			    ICE_FLOW_ENGINE_SWITCH) {
-				TAILQ_INSERT_AFTER(list, existing_node,
-						   parser_node, node);
-				goto DONE;
-			}
-		}
-		TAILQ_INSERT_HEAD(list, parser_node, node);
-	} else if (parser->engine->type == ICE_FLOW_ENGINE_HASH) {
-		TAILQ_INSERT_TAIL(list, parser_node, node);
-	} else if (parser->engine->type == ICE_FLOW_ENGINE_ACL) {
-		TAILQ_INSERT_HEAD(list, parser_node, node);
-	} else {
-		return -EINVAL;
-	}
-DONE:
-	return 0;
-}
-
-void
-ice_unregister_parser(struct ice_flow_parser *parser,
-		struct ice_adapter *ad)
-{
-	struct ice_parser_list *list;
-	struct ice_flow_parser_node *p_parser;
-	void *temp;
-
-	list = ice_get_parser_list(parser, ad);
-	if (list == NULL)
-		return;
-
-	RTE_TAILQ_FOREACH_SAFE(p_parser, list, node, temp) {
-		if (p_parser->parser->engine->type == parser->engine->type) {
-			TAILQ_REMOVE(list, p_parser, node);
-			rte_free(p_parser);
-		}
-	}
-}
-
 static int
 ice_flow_valid_attr(const struct rte_flow_attr *attr,
 		    struct rte_flow_error *error)
@@ -2299,61 +2191,65 @@  ice_search_pattern_match_item(struct ice_adapter *ad,
 static struct ice_flow_engine *
 ice_parse_engine_create(struct ice_adapter *ad,
 		struct rte_flow *flow,
-		struct ice_parser_list *parser_list,
+		struct ice_flow_parser *parser,
 		uint32_t priority,
 		const struct rte_flow_item pattern[],
 		const struct rte_flow_action actions[],
 		struct rte_flow_error *error)
 {
 	struct ice_flow_engine *engine = NULL;
-	struct ice_flow_parser_node *parser_node;
 	void *meta = NULL;
-	void *temp;
-
-	RTE_TAILQ_FOREACH_SAFE(parser_node, parser_list, node, temp) {
-		int ret;
+	int ret;
 
-		if (parser_node->parser->parse_pattern_action(ad,
-				parser_node->parser->array,
-				parser_node->parser->array_len,
-				pattern, actions, priority, &meta, error) < 0)
-			continue;
+	if (parser->parse_pattern_action(ad,
+					 parser->array,
+					 parser->array_len,
+					 pattern, actions, priority, &meta, error) < 0)
+		return NULL;
 
-		engine = parser_node->parser->engine;
-		RTE_ASSERT(engine->create != NULL);
-		ret = engine->create(ad, flow, meta, error);
-		if (ret == 0)
-			return engine;
-		else if (ret == -EEXIST)
-			return NULL;
-	}
+	engine = parser->engine;
+	RTE_ASSERT(engine->create != NULL);
+	ret = engine->create(ad, flow, meta, error);
+	if (ret == 0)
+		return engine;
+	else if (ret == -EEXIST)
+		return NULL;
 	return NULL;
 }
 
 static struct ice_flow_engine *
 ice_parse_engine_validate(struct ice_adapter *ad,
 		struct rte_flow *flow __rte_unused,
-		struct ice_parser_list *parser_list,
+		struct ice_flow_parser *parser,
 		uint32_t priority,
 		const struct rte_flow_item pattern[],
 		const struct rte_flow_action actions[],
 		struct rte_flow_error *error)
 {
-	struct ice_flow_engine *engine = NULL;
-	struct ice_flow_parser_node *parser_node;
-	void *temp;
 
-	RTE_TAILQ_FOREACH_SAFE(parser_node, parser_list, node, temp) {
-		if (parser_node->parser->parse_pattern_action(ad,
-				parser_node->parser->array,
-				parser_node->parser->array_len,
-				pattern, actions, priority, NULL, error) < 0)
-			continue;
+	if (parser->parse_pattern_action(ad,
+					 parser->array,
+					 parser->array_len,
+					 pattern, actions, priority, NULL, error) < 0)
+		return NULL;
+
+	return parser->engine;
+}
 
-		engine = parser_node->parser->engine;
-		break;
+static struct ice_flow_parser *get_flow_parser(bool dcf_enabled, uint32_t group)
+{
+	switch (group) {
+	case 0:
+		return &ice_switch_parser;
+	/* only dcf support ACL */
+	case 1:
+		return dcf_enabled ? &ice_acl_parser : NULL;
+	/* dcf don't support FDIR */
+	case 2:
+		return dcf_enabled ? NULL : &ice_fdir_parser;
+	default:
+		return NULL;
 	}
-	return engine;
 }
 
 static int
@@ -2369,7 +2265,7 @@  ice_flow_process_filter(struct rte_eth_dev *dev,
 	int ret = ICE_ERR_NOT_SUPPORTED;
 	struct ice_adapter *ad =
 		ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
-	struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+	struct ice_flow_parser *parser;
 
 	if (!pattern) {
 		rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_NUM,
@@ -2395,12 +2291,16 @@  ice_flow_process_filter(struct rte_eth_dev *dev,
 	if (ret)
 		return ret;
 
-	*engine = ice_parse_engine(ad, flow, &pf->rss_parser_list,
+	*engine = ice_parse_engine(ad, flow, &ice_hash_parser,
 			attr->priority, pattern, actions, error);
 	if (*engine != NULL)
 		return 0;
 
-	*engine = ice_parse_engine(ad, flow, &pf->dist_parser_list,
+	parser = get_flow_parser(ad->hw.dcf_enabled, attr->group);
+	if (parser == NULL)
+		return -EINVAL;
+
+	*engine = ice_parse_engine(ad, flow, parser,
 				   attr->priority, pattern, actions, error);
 	if (*engine == NULL)
 		return -EINVAL;
diff --git a/drivers/net/ice/ice_generic_flow.h b/drivers/net/ice/ice_generic_flow.h
index 471f255bd6..391d615b9a 100644
--- a/drivers/net/ice/ice_generic_flow.h
+++ b/drivers/net/ice/ice_generic_flow.h
@@ -515,10 +515,6 @@  struct ice_flow_parser_node {
 void ice_register_flow_engine(struct ice_flow_engine *engine);
 int ice_flow_init(struct ice_adapter *ad);
 void ice_flow_uninit(struct ice_adapter *ad);
-int ice_register_parser(struct ice_flow_parser *parser,
-		struct ice_adapter *ad);
-void ice_unregister_parser(struct ice_flow_parser *parser,
-		struct ice_adapter *ad);
 struct ice_pattern_match_item *
 ice_search_pattern_match_item(struct ice_adapter *ad,
 			      const struct rte_flow_item pattern[],
@@ -528,4 +524,9 @@  ice_search_pattern_match_item(struct ice_adapter *ad,
 int
 ice_flow_redirect(struct ice_adapter *ad,
 		  struct ice_flow_redirect *rd);
+
+extern struct ice_flow_parser ice_switch_parser;
+extern struct ice_flow_parser ice_acl_parser;
+extern struct ice_flow_parser ice_fdir_parser;
+extern struct ice_flow_parser ice_hash_parser;
 #endif
diff --git a/drivers/net/ice/ice_hash.c b/drivers/net/ice/ice_hash.c
index e36e7da2b5..f923641533 100644
--- a/drivers/net/ice/ice_hash.c
+++ b/drivers/net/ice/ice_hash.c
@@ -572,7 +572,7 @@  static struct ice_flow_engine ice_hash_engine = {
 };
 
 /* Register parser for os package. */
-static struct ice_flow_parser ice_hash_parser = {
+struct ice_flow_parser ice_hash_parser = {
 	.engine = &ice_hash_engine,
 	.array = ice_hash_pattern_list,
 	.array_len = RTE_DIM(ice_hash_pattern_list),
@@ -587,16 +587,9 @@  RTE_INIT(ice_hash_engine_init)
 }
 
 static int
-ice_hash_init(struct ice_adapter *ad)
+ice_hash_init(struct ice_adapter *ad __rte_unused)
 {
-	struct ice_flow_parser *parser = NULL;
-
-	if (ad->hw.dcf_enabled)
-		return 0;
-
-	parser = &ice_hash_parser;
-
-	return ice_register_parser(parser, ad);
+	return 0;
 }
 
 static int
@@ -1442,12 +1435,8 @@  ice_hash_destroy(struct ice_adapter *ad,
 }
 
 static void
-ice_hash_uninit(struct ice_adapter *ad)
+ice_hash_uninit(struct ice_adapter *ad __rte_unused)
 {
-	if (ad->hw.dcf_enabled)
-		return;
-
-	ice_unregister_parser(&ice_hash_parser, ad);
 }
 
 static void
diff --git a/drivers/net/ice/ice_switch_filter.c b/drivers/net/ice/ice_switch_filter.c
index 88d599068f..8f29326762 100644
--- a/drivers/net/ice/ice_switch_filter.c
+++ b/drivers/net/ice/ice_switch_filter.c
@@ -201,8 +201,6 @@  struct ice_switch_filter_conf {
 	struct ice_adv_rule_info rule_info;
 };
 
-static struct ice_flow_parser ice_switch_dist_parser;
-
 static struct
 ice_pattern_match_item ice_switch_pattern_dist_list[] = {
 	{pattern_any,					ICE_INSET_NONE,				ICE_INSET_NONE,				ICE_INSET_NONE},
@@ -2052,15 +2050,14 @@  ice_switch_redirect(struct ice_adapter *ad,
 }
 
 static int
-ice_switch_init(struct ice_adapter *ad)
+ice_switch_init(struct ice_adapter *ad __rte_unused)
 {
-	return ice_register_parser(&ice_switch_dist_parser, ad);
+	return 0;
 }
 
 static void
-ice_switch_uninit(struct ice_adapter *ad)
+ice_switch_uninit(struct ice_adapter *ad __rte_unused)
 {
-	ice_unregister_parser(&ice_switch_dist_parser, ad);
 }
 
 static struct
@@ -2075,8 +2072,8 @@  ice_flow_engine ice_switch_engine = {
 	.type = ICE_FLOW_ENGINE_SWITCH,
 };
 
-static struct
-ice_flow_parser ice_switch_dist_parser = {
+struct
+ice_flow_parser ice_switch_parser = {
 	.engine = &ice_switch_engine,
 	.array = ice_switch_pattern_dist_list,
 	.array_len = RTE_DIM(ice_switch_pattern_dist_list),