[4/4] net/mlx5: add modify field action ADD fields validation

Message ID 20231214030428.363471-5-suanmingm@nvidia.com (mailing list archive)
State Accepted, archived
Delegated to: Raslan Darawsheh
Headers
Series net/mlx5: add modify field ADD fields support |

Checks

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

Commit Message

Suanming Mou Dec. 14, 2023, 3:04 a.m. UTC
  Due to HW limitation, not all the fields are available as ADD_FIELD
destination.

This commit adds the validation to the destinations.

Signed-off-by: Suanming Mou <suanmingm@nvidia.com>
---
 doc/guides/rel_notes/release_24_03.rst |  4 ++++
 drivers/net/mlx5/mlx5_flow_hw.c        | 32 ++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
  

Comments

Ori Kam Dec. 14, 2023, 11:39 a.m. UTC | #1
Hi Suanming,

> -----Original Message-----
> From: Suanming Mou <suanmingm@nvidia.com>
> Sent: Thursday, December 14, 2023 5:04 AM
> 
> Due to HW limitation, not all the fields are available as ADD_FIELD
> destination.
> 
> This commit adds the validation to the destinations.
> 
> Signed-off-by: Suanming Mou <suanmingm@nvidia.com>
> ---

Acked-by: Ori Kam <orika@nvidia.com>
Best,
Ori
  

Patch

diff --git a/doc/guides/rel_notes/release_24_03.rst b/doc/guides/rel_notes/release_24_03.rst
index e9c9717706..2c0e2930cc 100644
--- a/doc/guides/rel_notes/release_24_03.rst
+++ b/doc/guides/rel_notes/release_24_03.rst
@@ -55,6 +55,10 @@  New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Updated NVIDIA mlx5 driver.**
+
+  * Added support for accumulating from src field to dst field.
+
 
 Removed Items
 -------------
diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c
index d224979ee8..c4a90a3690 100644
--- a/drivers/net/mlx5/mlx5_flow_hw.c
+++ b/drivers/net/mlx5/mlx5_flow_hw.c
@@ -4948,6 +4948,33 @@  flow_hw_modify_field_is_used(const struct rte_flow_action_modify_field *action,
 	return action->src.field == field || action->dst.field == field;
 }
 
+static bool
+flow_hw_modify_field_is_add_dst_valid(const struct rte_flow_action_modify_field *conf)
+{
+	if (conf->operation != RTE_FLOW_MODIFY_ADD)
+		return true;
+	if (conf->src.field == RTE_FLOW_FIELD_POINTER ||
+	    conf->src.field == RTE_FLOW_FIELD_VALUE)
+		return true;
+	switch (conf->dst.field) {
+	case RTE_FLOW_FIELD_IPV4_TTL:
+	case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
+	case RTE_FLOW_FIELD_TCP_SEQ_NUM:
+	case RTE_FLOW_FIELD_TCP_ACK_NUM:
+	case RTE_FLOW_FIELD_TAG:
+	case RTE_FLOW_FIELD_META:
+	case RTE_FLOW_FIELD_FLEX_ITEM:
+	case RTE_FLOW_FIELD_TCP_DATA_OFFSET:
+	case RTE_FLOW_FIELD_IPV4_IHL:
+	case RTE_FLOW_FIELD_IPV4_TOTAL_LEN:
+	case RTE_FLOW_FIELD_IPV6_PAYLOAD_LEN:
+		return true;
+	default:
+		break;
+	}
+	return false;
+}
+
 static int
 flow_hw_validate_action_modify_field(struct rte_eth_dev *dev,
 				     const struct rte_flow_action *action,
@@ -5060,6 +5087,11 @@  flow_hw_validate_action_modify_field(struct rte_eth_dev *dev,
 		return rte_flow_error_set(error, EINVAL,
 				RTE_FLOW_ERROR_TYPE_ACTION, action,
 				"MPLS cannot be used as destination");
+	/* ADD_FIELD is not supported for all the fields. */
+	if (!flow_hw_modify_field_is_add_dst_valid(action_conf))
+		return rte_flow_error_set(error, EINVAL,
+				RTE_FLOW_ERROR_TYPE_ACTION, action,
+				"invalid add_field destination");
 	return 0;
 }
 static int