DPDK patches and discussions
 help / color / mirror / Atom feed
From: Chaoyong He <chaoyong.he@corigine.com>
To: dev@dpdk.org
Cc: oss-drivers@corigine.com, Long Wu <long.wu@corigine.com>,
	Chaoyong He <chaoyong.he@corigine.com>
Subject: [PATCH v3 1/2] net/nfp: refactor flow item calculate function arguments
Date: Fri, 30 Aug 2024 19:28:28 +0800	[thread overview]
Message-ID: <20240830112829.2586795-2-chaoyong.he@corigine.com> (raw)
In-Reply-To: <20240830112829.2586795-1-chaoyong.he@corigine.com>

From: Long Wu <long.wu@corigine.com>

Refactor the flow item calculate function, unify the arguments
of item check and calculate function, make the Ethernet item
calculate function more readable.

Signed-off-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Chaoyong He <chaoyong.he@corigine.com>
---
 drivers/net/nfp/flower/nfp_flower_flow.c | 47 +++++++++++++-----------
 1 file changed, 26 insertions(+), 21 deletions(-)

diff --git a/drivers/net/nfp/flower/nfp_flower_flow.c b/drivers/net/nfp/flower/nfp_flower_flow.c
index 0078455658..f24e9cee9c 100644
--- a/drivers/net/nfp/flower/nfp_flower_flow.c
+++ b/drivers/net/nfp/flower/nfp_flower_flow.c
@@ -1044,14 +1044,11 @@ static nfp_flow_key_check_item_fn check_item_fns[] = {
 };
 
 static int
-nfp_flow_key_layers_check_items(const struct rte_flow_item items[])
+nfp_flow_key_layers_check_items(const struct rte_flow_item items[],
+		struct nfp_item_calculate_param *param)
 {
 	int ret;
-	struct nfp_item_flag flag = {};
 	const struct rte_flow_item *item;
-	struct nfp_item_calculate_param param = {
-		.flag = &flag,
-	};
 
 	for (item = items; item->type != RTE_FLOW_ITEM_TYPE_END; ++item) {
 		if (item->type >= RTE_DIM(check_item_fns)) {
@@ -1062,8 +1059,8 @@ nfp_flow_key_layers_check_items(const struct rte_flow_item items[])
 		if (check_item_fns[item->type] == NULL)
 			continue;
 
-		param.item = item;
-		ret = check_item_fns[item->type](&param);
+		param->item = item;
+		ret = check_item_fns[item->type](param);
 		if (ret != 0) {
 			PMD_DRV_LOG(ERR, "Flow item %d check fail", item->type);
 			return ret;
@@ -1081,10 +1078,17 @@ nfp_flow_item_calculate_stub(struct nfp_item_calculate_param *param __rte_unused
 static void
 nfp_flow_item_calculate_eth(struct nfp_item_calculate_param *param)
 {
-	if (param->item->spec != NULL) {
-		param->key_ls->key_layer |= NFP_FLOWER_LAYER_MAC;
-		param->key_ls->key_size += sizeof(struct nfp_flower_mac_mpls);
-	}
+	struct nfp_fl_key_ls *key_ls;
+	const struct rte_flow_item_eth *spec;
+
+	spec = param->item->spec;
+	if (spec == NULL)
+		return;
+
+	key_ls = param->key_ls;
+
+	key_ls->key_layer |= NFP_FLOWER_LAYER_MAC;
+	key_ls->key_size += sizeof(struct nfp_flower_mac_mpls);
 }
 
 static void
@@ -1238,14 +1242,9 @@ static nfp_flow_key_calculate_item_fn item_fns[] = {
 
 static int
 nfp_flow_key_layers_calculate_items(const struct rte_flow_item items[],
-		struct nfp_fl_key_ls *key_ls)
+		struct nfp_item_calculate_param *param)
 {
-	struct nfp_item_flag flag = {};
 	const struct rte_flow_item *item;
-	struct nfp_item_calculate_param param = {
-		.key_ls = key_ls,
-		.flag = &flag,
-	};
 
 	for (item = items; item->type != RTE_FLOW_ITEM_TYPE_END; ++item) {
 		if (item->type >= RTE_DIM(item_fns) || item_fns[item->type] == NULL) {
@@ -1253,8 +1252,8 @@ nfp_flow_key_layers_calculate_items(const struct rte_flow_item items[],
 			return -ERANGE;
 		}
 
-		param.item = item;
-		item_fns[item->type](&param);
+		param->item = item;
+		item_fns[item->type](param);
 	}
 
 	return 0;
@@ -1799,6 +1798,8 @@ nfp_flow_key_layers_calculate(struct rte_eth_dev *dev,
 		struct nfp_fl_key_ls *key_ls)
 {
 	int ret;
+	struct nfp_item_flag flag = {};
+	struct nfp_item_calculate_param param = {};
 
 	key_ls->key_layer_two = 0;
 	key_ls->key_layer = NFP_FLOWER_LAYER_PORT;
@@ -1809,13 +1810,17 @@ nfp_flow_key_layers_calculate(struct rte_eth_dev *dev,
 	key_ls->vlan = 0;
 	key_ls->tun_type = NFP_FL_TUN_NONE;
 
-	ret = nfp_flow_key_layers_check_items(items);
+	param.key_ls = key_ls;
+	param.flag = &flag;
+
+	ret = nfp_flow_key_layers_check_items(items, &param);
 	if (ret != 0) {
 		PMD_DRV_LOG(ERR, "flow items check failed");
 		return ret;
 	}
 
-	ret = nfp_flow_key_layers_calculate_items(items, key_ls);
+	memset(param.flag, 0, sizeof(struct nfp_item_flag));
+	ret = nfp_flow_key_layers_calculate_items(items, &param);
 	if (ret != 0) {
 		PMD_DRV_LOG(ERR, "flow items calculate failed");
 		return ret;
-- 
2.39.1


  reply	other threads:[~2024-08-30 11:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-30  7:13 [PATCH 0/2] Support match flow rule Ethernet type field Chaoyong He
2024-08-30  7:13 ` [PATCH 1/2] net/nfp: refactor flow item calculate function arguments Chaoyong He
2024-08-30  7:13 ` [PATCH 2/2] net/nfp: flow rule supports match Ethernet type Chaoyong He
2024-08-30 11:28 ` [PATCH v3 0/2] Support match flow rule Ethernet type field Chaoyong He
2024-08-30 11:28   ` Chaoyong He [this message]
2024-08-30 11:28   ` [PATCH v3 2/2] net/nfp: flow rule supports match Ethernet type Chaoyong He
2024-09-02 16:48   ` [PATCH v3 0/2] Support match flow rule Ethernet type field 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=20240830112829.2586795-2-chaoyong.he@corigine.com \
    --to=chaoyong.he@corigine.com \
    --cc=dev@dpdk.org \
    --cc=long.wu@corigine.com \
    --cc=oss-drivers@corigine.com \
    /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).