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, Chaoyong He <chaoyong.he@corigine.com>,
	Long Wu <long.wu@corigine.com>,
	Peng Zhang <peng.zhang@corigine.com>
Subject: [PATCH 08/21] net/nfp: support modify IPv4 source address
Date: Wed, 19 Jun 2024 17:13:45 +0800	[thread overview]
Message-ID: <20240619091358.3479247-9-chaoyong.he@corigine.com> (raw)
In-Reply-To: <20240619091358.3479247-1-chaoyong.he@corigine.com>

Add the framework of modify field flow action and the logic of modify
IPv4 source address action.

Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Reviewed-by: Long Wu <long.wu@corigine.com>
Reviewed-by: Peng Zhang <peng.zhang@corigine.com>
---
 doc/guides/nics/features/nfp.ini         |   1 +
 drivers/net/nfp/flower/nfp_flower_flow.c | 172 +++++++++++++++++++++++
 2 files changed, 173 insertions(+)

diff --git a/doc/guides/nics/features/nfp.ini b/doc/guides/nics/features/nfp.ini
index b20049b4f5..5b507cfe94 100644
--- a/doc/guides/nics/features/nfp.ini
+++ b/doc/guides/nics/features/nfp.ini
@@ -51,6 +51,7 @@ drop                 = Y
 jump                 = Y
 mark                 = Y
 meter                = Y
+modify_field         = Y
 of_pop_vlan          = Y
 of_push_vlan         = Y
 of_set_vlan_pcp      = Y
diff --git a/drivers/net/nfp/flower/nfp_flower_flow.c b/drivers/net/nfp/flower/nfp_flower_flow.c
index 95f9e8c2d6..8997d67627 100644
--- a/drivers/net/nfp/flower/nfp_flower_flow.c
+++ b/drivers/net/nfp/flower/nfp_flower_flow.c
@@ -1205,6 +1205,129 @@ nfp_flow_action_calculate_mark(struct nfp_action_calculate_param *param)
 	return 0;
 }
 
+static bool
+nfp_flow_field_id_dst_support(enum rte_flow_field_id field)
+{
+	switch (field) {
+	case RTE_FLOW_FIELD_IPV4_SRC:
+		return true;
+	default:
+		break;
+	}
+
+	return false;
+}
+
+static bool
+nfp_flow_field_id_src_support(enum rte_flow_field_id field)
+{
+	return field == RTE_FLOW_FIELD_POINTER ||
+			field == RTE_FLOW_FIELD_VALUE;
+}
+
+static uint32_t
+nfp_flow_field_width(enum rte_flow_field_id field,
+		uint32_t inherit)
+{
+	switch (field) {
+	case RTE_FLOW_FIELD_IPV4_SRC:
+		return 32;
+	case RTE_FLOW_FIELD_POINTER:
+		/* FALLTHROUGH */
+	case RTE_FLOW_FIELD_VALUE:
+		return inherit;
+	default:
+		break;
+	}
+
+	return 0;
+}
+
+static bool
+nfp_flow_is_validate_field_data(const struct rte_flow_field_data *data,
+		uint32_t conf_width,
+		uint32_t data_width)
+{
+	if (data->level != 0) {
+		PMD_DRV_LOG(ERR, "The 'level' is not support");
+		return false;
+	}
+
+	if (data->tag_index != 0) {
+		PMD_DRV_LOG(ERR, "The 'tag_index' is not support");
+		return false;
+	}
+
+	if (data->class_id != 0) {
+		PMD_DRV_LOG(ERR, "The 'class_id' is not support");
+		return false;
+	}
+
+	if (data->offset + conf_width > data_width) {
+		PMD_DRV_LOG(ERR, "The 'offset' value is too big");
+		return false;
+	}
+
+	return true;
+}
+
+static int
+nfp_flow_action_calculate_modify_dispatch(struct nfp_action_calculate_param *param,
+		enum rte_flow_field_id field)
+{
+	switch (field) {
+	case RTE_FLOW_FIELD_IPV4_SRC:
+		return nfp_flow_action_calculate_ipv4_addr(param);
+	default:
+		break;    /* NOTREACHED */
+	}
+
+	return -ENOTSUP;
+}
+
+static int
+nfp_flow_action_calculate_modify(struct nfp_action_calculate_param *param)
+{
+	uint32_t width;
+	uint32_t dst_width;
+	uint32_t src_width;
+	const struct rte_flow_field_data *dst_data;
+	const struct rte_flow_field_data *src_data;
+	const struct rte_flow_action_modify_field *conf;
+
+	conf = param->action->conf;
+	if (conf == NULL)
+		return -EINVAL;
+
+	dst_data = &conf->dst;
+	src_data = &conf->src;
+	if (!nfp_flow_field_id_dst_support(dst_data->field) ||
+			!nfp_flow_field_id_src_support(src_data->field)) {
+		PMD_DRV_LOG(ERR, "Not supported field id");
+		return -EINVAL;
+	}
+
+	width = conf->width;
+	if (width == 0) {
+		PMD_DRV_LOG(ERR, "No bits are required to modify");
+		return -EINVAL;
+	}
+
+	dst_width = nfp_flow_field_width(dst_data->field, 0);
+	src_width = nfp_flow_field_width(src_data->field, dst_width);
+	if (width > dst_width || width > src_width) {
+		PMD_DRV_LOG(ERR, "Cannot modify more bits than the width of a field");
+		return -EINVAL;
+	}
+
+	if (!nfp_flow_is_validate_field_data(dst_data, width, dst_width)) {
+		PMD_DRV_LOG(ERR, "The dest field data has problem");
+		return -EINVAL;
+	}
+
+	return nfp_flow_action_calculate_modify_dispatch(param, dst_data->field);
+}
+
 static nfp_flow_key_calculate_action_fn action_fns[] = {
 	[RTE_FLOW_ACTION_TYPE_VOID]             = nfp_flow_action_calculate_stub,
 	[RTE_FLOW_ACTION_TYPE_DROP]             = nfp_flow_action_calculate_stub,
@@ -1235,6 +1358,7 @@ static nfp_flow_key_calculate_action_fn action_fns[] = {
 	[RTE_FLOW_ACTION_TYPE_CONNTRACK]        = nfp_flow_action_calculate_stub,
 	[RTE_FLOW_ACTION_TYPE_MARK]             = nfp_flow_action_calculate_mark,
 	[RTE_FLOW_ACTION_TYPE_RSS]              = nfp_flow_action_calculate_stub,
+	[RTE_FLOW_ACTION_TYPE_MODIFY_FIELD]     = nfp_flow_action_calculate_modify,
 };
 
 static int
@@ -4104,6 +4228,53 @@ nfp_flow_action_compile_rss(struct nfp_action_compile_param *param)
 	return 0;
 }
 
+static int
+nfp_flow_action_compile_modify_dispatch(struct nfp_action_compile_param *param,
+		enum rte_flow_field_id field)
+{
+	switch (field) {
+	case RTE_FLOW_FIELD_IPV4_SRC:
+		return nfp_flow_action_compile_ipv4_src(param);
+	default:
+		break;    /* NOTREACHED */
+	}
+
+	return -ENOTSUP;
+}
+
+static int
+nfp_flow_action_compile_modify(struct nfp_action_compile_param *param)
+{
+	int ret;
+	struct rte_flow_action action = {};
+	const struct rte_flow_action *action_old;
+	const struct rte_flow_action_modify_field *conf;
+
+	conf = param->action->conf;
+
+	if (conf->src.field == RTE_FLOW_FIELD_POINTER) {
+		action.conf = conf->src.pvalue;
+	} else if (conf->src.field == RTE_FLOW_FIELD_VALUE) {
+		action.conf = (void *)(uintptr_t)&conf->src.value;
+	} else {
+		PMD_DRV_LOG(ERR, "The SRC field of flow modify is not right");
+		return -EINVAL;
+	}
+
+	/* Store the old action pointer */
+	action_old = param->action;
+
+	param->action = &action;
+	ret = nfp_flow_action_compile_modify_dispatch(param, conf->dst.field);
+	if (ret != 0)
+		PMD_DRV_LOG(ERR, "Something wrong when modify dispatch");
+
+	/* Reload the old action pointer */
+	param->action = action_old;
+
+	return ret;
+}
+
 static nfp_flow_action_compile_fn action_compile_fns[] = {
 	[RTE_FLOW_ACTION_TYPE_VOID]             = nfp_flow_action_compile_stub,
 	[RTE_FLOW_ACTION_TYPE_DROP]             = nfp_flow_action_compile_drop,
@@ -4134,6 +4305,7 @@ static nfp_flow_action_compile_fn action_compile_fns[] = {
 	[RTE_FLOW_ACTION_TYPE_CONNTRACK]        = nfp_flow_action_compile_stub,
 	[RTE_FLOW_ACTION_TYPE_MARK]             = nfp_flow_action_compile_mark,
 	[RTE_FLOW_ACTION_TYPE_RSS]              = nfp_flow_action_compile_rss,
+	[RTE_FLOW_ACTION_TYPE_MODIFY_FIELD]     = nfp_flow_action_compile_modify,
 };
 
 static int
-- 
2.39.1


  parent reply	other threads:[~2024-06-19  9:16 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-19  9:13 [PATCH 00/21] support modify field flow action Chaoyong He
2024-06-19  9:13 ` [PATCH 01/21] net/nfp: fix IPv6 TTL and DSCP " Chaoyong He
2024-06-19  9:13 ` [PATCH 02/21] net/nfp: pack parameters of flow item function Chaoyong He
2024-06-19  9:13 ` [PATCH 03/21] net/nfp: pack various flags of flow action Chaoyong He
2024-06-19  9:13 ` [PATCH 04/21] net/nfp: refactor flow action calculate function Chaoyong He
2024-06-19  9:13 ` [PATCH 05/21] net/nfp: refactor flow action compile function Chaoyong He
2024-06-19  9:13 ` [PATCH 06/21] net/nfp: pack various flags of flow item Chaoyong He
2024-06-19  9:13 ` [PATCH 07/21] net/nfp: refactor flow item calculate function Chaoyong He
2024-06-19  9:13 ` Chaoyong He [this message]
2024-06-19  9:13 ` [PATCH 09/21] net/nfp: support modify IPv4 dest address Chaoyong He
2024-06-19  9:13 ` [PATCH 10/21] net/nfp: support modify IPv6 source address Chaoyong He
2024-06-19  9:13 ` [PATCH 11/21] net/nfp: support modify IPv6 dest address Chaoyong He
2024-06-19  9:13 ` [PATCH 12/21] net/nfp: support modify TCP source port Chaoyong He
2024-06-19  9:13 ` [PATCH 13/21] net/nfp: support modify TCP dest port Chaoyong He
2024-06-19  9:13 ` [PATCH 14/21] net/nfp: support modify UDP source port Chaoyong He
2024-06-19  9:13 ` [PATCH 15/21] net/nfp: support modify UDP dest port Chaoyong He
2024-06-19  9:13 ` [PATCH 16/21] net/nfp: support modify IPv4 TTL Chaoyong He
2024-06-19  9:13 ` [PATCH 17/21] net/nfp: support modify IPv6 hop limit Chaoyong He
2024-06-19  9:13 ` [PATCH 18/21] net/nfp: support modify MAC source address Chaoyong He
2024-06-19  9:13 ` [PATCH 19/21] net/nfp: support modify MAC dest address Chaoyong He
2024-06-19  9:13 ` [PATCH 20/21] net/nfp: support modify IPv4 DSCP Chaoyong He
2024-06-19  9:13 ` [PATCH 21/21] net/nfp: support modify IPv6 DSCP Chaoyong He

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=20240619091358.3479247-9-chaoyong.he@corigine.com \
    --to=chaoyong.he@corigine.com \
    --cc=dev@dpdk.org \
    --cc=long.wu@corigine.com \
    --cc=oss-drivers@corigine.com \
    --cc=peng.zhang@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).