Skip to contentSkip to conversation

net/mlx5: add modify field ADD fields support

PATCH In review Suanming Mou 3 participants 11 messages Dec 14, 2023 – Jan 7, 2024 Network drivers

lore
Share & tools
lore
#0 lore raw

cover net/mlx5: add modify field ADD fields support

Before this series, the modify_field ADD operation in mlx5 PMD only allowed sum of immediate value to field.

ADD_FIELD operation allows user to add the src field value to the dest field. Dest field has the sum of src field value and original dst field value.

Suanming Mou (4):
net/mlx5: add TCP/IP length modify field net/mlx5: rename modify copy destination to destination net/mlx5: add modify field action ADD fields support net/mlx5: add modify field action ADD fields validation

 doc/guides/rel_notes/release_24_03.rst |  4 ++
 drivers/common/mlx5/mlx5_prm.h         |  4 ++
 drivers/net/mlx5/mlx5_flow.h           |  2 +-
 drivers/net/mlx5/mlx5_flow_dv.c        | 83 ++++++++++++++++++++------
 drivers/net/mlx5/mlx5_flow_hw.c        | 42 ++++++++++++-
 5 files changed, 112 insertions(+), 23 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/4 net/mlx5: add TCP/IP length modify field

This commit adds TCP data offset, IPv4 total length, IPv4 IHL, IPv6 payload length in modify field operation.

---
 drivers/common/mlx5/mlx5_prm.h  |  4 ++++
 drivers/net/mlx5/mlx5_flow_dv.c | 40 +++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)
drivers/common/mlx5/mlx5_prm.h +4 -0
index 9e22dce6da..0d46ba9c40 100644
@@ -848,6 +848,10 @@ enum mlx5_modification_field {
 	MLX5_MODI_META_REG_C_13 = 0x94,
 	MLX5_MODI_META_REG_C_14 = 0x95,
 	MLX5_MODI_META_REG_C_15 = 0x96,
+	MLX5_MODI_OUT_IPV4_TOTAL_LEN = 0x11D,
+	MLX5_MODI_OUT_IPV6_PAYLOAD_LEN = 0x11E,
+	MLX5_MODI_OUT_IPV4_IHL = 0x11F,
+	MLX5_MODI_OUT_TCP_DATA_OFFSET = 0x120,
 	MLX5_MODI_INVALID = INT_MAX,
 };
 
drivers/net/mlx5/mlx5_flow_dv.c +40 -0
index 115d730317..4e2095dcfe 100644
@@ -1664,6 +1664,16 @@ mlx5_flow_field_id_to_modify_info
 		else
 			info[idx].offset = off_be;
 		break;
+	case RTE_FLOW_FIELD_IPV4_IHL:
+		MLX5_ASSERT(data->offset + width <= 4);
+		off_be = 4 - (data->offset + width);
+		info[idx] = (struct field_modify_info){1, 0,
+					MLX5_MODI_OUT_IPV4_IHL};
+		if (mask)
+			mask[idx] = flow_modify_info_mask_8(width, off_be);
+		else
+			info[idx].offset = off_be;
+		break;
 	case RTE_FLOW_FIELD_IPV4_DSCP:
 		MLX5_ASSERT(data->offset + width <= 6);
 		off_be = 6 - (data->offset + width);
@@ -1674,6 +1684,16 @@ mlx5_flow_field_id_to_modify_info
 		else
 			info[idx].offset = off_be;
 		break;
+	case RTE_FLOW_FIELD_IPV4_TOTAL_LEN:
+		MLX5_ASSERT(data->offset + width <= 16);
+		off_be = 16 - (data->offset + width);
+		info[idx] = (struct field_modify_info){2, 0,
+					MLX5_MODI_OUT_IPV4_TOTAL_LEN};
+		if (mask)
+			mask[idx] = flow_modify_info_mask_16(width, off_be);
+		else
+			info[idx].offset = off_be;
+		break;
 	case RTE_FLOW_FIELD_IPV4_TTL:
 		MLX5_ASSERT(data->offset + width <= 8);
 		off_be = 8 - (data->offset + width);
@@ -1714,6 +1734,16 @@ mlx5_flow_field_id_to_modify_info
 		else
 			info[idx].offset = off_be;
 		break;
+	case RTE_FLOW_FIELD_IPV6_PAYLOAD_LEN:
+		MLX5_ASSERT(data->offset + width <= 16);
+		off_be = 16 - (data->offset + width);
+		info[idx] = (struct field_modify_info){2, 0,
+					MLX5_MODI_OUT_IPV6_PAYLOAD_LEN};
+		if (mask)
+			mask[idx] = flow_modify_info_mask_16(width, off_be);
+		else
+			info[idx].offset = off_be;
+		break;
 	case RTE_FLOW_FIELD_IPV6_HOPLIMIT:
 		MLX5_ASSERT(data->offset + width <= 8);
 		off_be = 8 - (data->offset + width);
@@ -1860,6 +1890,16 @@ mlx5_flow_field_id_to_modify_info
 		else
 			info[idx].offset = off_be;
 		break;
+	case RTE_FLOW_FIELD_TCP_DATA_OFFSET:
+		MLX5_ASSERT(data->offset + width <= 4);
+		off_be = 4 - (data->offset + width);
+		info[idx] = (struct field_modify_info){1, 0,
+					MLX5_MODI_OUT_TCP_DATA_OFFSET};
+		if (mask)
+			mask[idx] = flow_modify_info_mask_8(width, off_be);
+		else
+			info[idx].offset = off_be;
+		break;
 	case RTE_FLOW_FIELD_UDP_PORT_SRC:
 		MLX5_ASSERT(data->offset + width <= 16);
 		off_be = 16 - (data->offset + width);
Signature · 1 line
2.34.1
Acked-by on v1 1/4
#3 lore raw

RE: [PATCH 1/4] net/mlx5: add TCP/IP length modify field

In reply to Suanming Mou

Hi Suanming

Quoted 9 lines

-----Original Message-----
From: Suanming Mou <[email protected]>
Sent: Thursday, December 14, 2023 5:04 AM
To: Dariusz Sosnowski <[email protected]>; Slava Ovsiienko <[email protected]>; Ori Kam <[email protected]>; Matan Azrad <[email protected]>
Cc: [email protected]; Raslan Darawsheh <[email protected]>
Subject: [PATCH 1/4] net/mlx5: add TCP/IP length modify field

Quoted 5 lines

This commit adds TCP data offset, IPv4 total length, IPv4 IHL, IPv6 payload length in modify field operation.

---

Best,
Ori

#4 lore raw

PATCH 2/4 net/mlx5: rename modify copy destination to destination

In reply to Suanming Mou

In the mlx5_flow_field_id_to_modify_info() function, for the coming new ADD_FILED operation will also use that dcopy as ADD_FIELD's destination.

This commit renames the dcopy to dest which makes things much clearer.

---
 drivers/net/mlx5/mlx5_flow.h    |  2 +-
 drivers/net/mlx5/mlx5_flow_dv.c | 34 +++++++++++++++++----------------
 2 files changed, 19 insertions(+), 17 deletions(-)
drivers/net/mlx5/mlx5_flow.h +1 -1
index 6dde9de688..120609c595 100644
@@ -2834,7 +2834,7 @@ void mlx5_flow_field_id_to_modify_info
 		 const struct rte_flow_attr *attr, struct rte_flow_error *error);
 int flow_dv_convert_modify_action(struct rte_flow_item *item,
 			      struct field_modify_info *field,
-			      struct field_modify_info *dcopy,
+			      struct field_modify_info *dest,
 			      struct mlx5_flow_dv_modify_hdr_resource *resource,
 			      uint32_t type, struct rte_flow_error *error);
 
drivers/net/mlx5/mlx5_flow_dv.c +18 -16
index 4e2095dcfe..272dbca00f 100644
@@ -363,8 +363,10 @@ mlx5_update_vlan_vid_pcp(const struct rte_flow_action *action,
  *     For MLX5_MODIFICATION_TYPE_SET specifies destination field.
  *     For MLX5_MODIFICATION_TYPE_ADD specifies destination field.
  *     For MLX5_MODIFICATION_TYPE_COPY specifies source field.
- * @param[in] dcopy
- *   Destination field info for MLX5_MODIFICATION_TYPE_COPY in @type.
+ *     For MLX5_MODIFICATION_TYPE_ADD_FIELD specifies source field.
+ * @param[in] dest
+ *   Destination field info for MLX5_MODIFICATION_TYPE_COPY and
+ *   MLX5_MODIFICATION_TYPE_ADD_FIELD in @type.
  *   Negative offset value sets the same offset as source offset.
  *   size field is ignored, value is taken from source field.
  * @param[in,out] resource
@@ -380,7 +382,7 @@ mlx5_update_vlan_vid_pcp(const struct rte_flow_action *action,
 int
 flow_dv_convert_modify_action(struct rte_flow_item *item,
 			      struct field_modify_info *field,
-			      struct field_modify_info *dcopy,
+			      struct field_modify_info *dest,
 			      struct mlx5_flow_dv_modify_hdr_resource *resource,
 			      uint32_t type, struct rte_flow_error *error)
 {
@@ -401,7 +403,7 @@ flow_dv_convert_modify_action(struct rte_flow_item *item,
 		uint32_t mask;
 		uint32_t data;
 		bool next_field = true;
-		bool next_dcopy = true;
+		bool next_dest = true;
 
 		if (i >= MLX5_MAX_MODIFY_NUM)
 			return rte_flow_error_set(error, EINVAL,
@@ -432,20 +434,20 @@ flow_dv_convert_modify_action(struct rte_flow_item *item,
 				0 : size_b,
 		};
 		if (type == MLX5_MODIFICATION_TYPE_COPY) {
-			MLX5_ASSERT(dcopy);
-			actions[i].dst_field = dcopy->id;
+			MLX5_ASSERT(dest);
+			actions[i].dst_field = dest->id;
 			actions[i].dst_offset =
-				(int)dcopy->offset < 0 ? off_b : dcopy->offset;
+				(int)dest->offset < 0 ? off_b : dest->offset;
 			/* Convert entire record to big-endian format. */
 			actions[i].data1 = rte_cpu_to_be_32(actions[i].data1);
 			/*
 			 * Destination field overflow. Copy leftovers of
 			 * a source field to the next destination field.
 			 */
-			if ((size_b > dcopy->size * CHAR_BIT - dcopy->offset) &&
-			    dcopy->size != 0) {
+			if ((size_b > dest->size * CHAR_BIT - dest->offset) &&
+			    dest->size != 0) {
 				actions[i].length =
-					dcopy->size * CHAR_BIT - dcopy->offset;
+					dest->size * CHAR_BIT - dest->offset;
 				carry_b += actions[i].length;
 				next_field = false;
 			} else {
@@ -455,12 +457,12 @@ flow_dv_convert_modify_action(struct rte_flow_item *item,
 			 * Not enough bits in a source filed to fill a
 			 * destination field. Switch to the next source.
 			 */
-			if ((size_b < dcopy->size * CHAR_BIT - dcopy->offset) &&
+			if ((size_b < dest->size * CHAR_BIT - dest->offset) &&
 			    ((size_b == field->size * CHAR_BIT - off_b) ||
 			     field->is_flex)) {
 				actions[i].length = size_b;
-				dcopy->offset += actions[i].length;
-				next_dcopy = false;
+				dest->offset += actions[i].length;
+				next_dest = false;
 			}
 		} else {
 			MLX5_ASSERT(item->spec);
@@ -475,11 +477,11 @@ flow_dv_convert_modify_action(struct rte_flow_item *item,
 		/* Convert entire record to expected big-endian format. */
 		actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
 		if ((type != MLX5_MODIFICATION_TYPE_COPY ||
-		     dcopy->id != (enum mlx5_modification_field)UINT32_MAX) &&
+		     dest->id != (enum mlx5_modification_field)UINT32_MAX) &&
 		    field->id != (enum mlx5_modification_field)UINT32_MAX)
 			++i;
-		if (next_dcopy && type == MLX5_MODIFICATION_TYPE_COPY)
-			++dcopy;
+		if (next_dest && type == MLX5_MODIFICATION_TYPE_COPY)
+			++dest;
 		if (next_field)
 			++field;
 	} while (field->size);
Signature · 1 line
2.34.1
Acked-by on v1 2/4
#5 lore raw

RE: [PATCH 2/4] net/mlx5: rename modify copy destination to destination

Hi Suanming

Quoted 5 lines

-----Original Message-----
From: Suanming Mou <[email protected]>
Sent: Thursday, December 14, 2023 5:04 AM
Subject: [PATCH 2/4] net/mlx5: rename modify copy destination to destination

Quoted 8 lines

In the mlx5_flow_field_id_to_modify_info() function, for the coming new ADD_FILED operation will also use that dcopy as ADD_FIELD's destination.

This commit renames the dcopy to dest which makes things much clearer.

---

Best,
Ori

#6 lore raw

PATCH 3/4 net/mlx5: add modify field action ADD fields support

In reply to Suanming Mou

ADD_FIELD operation allows user to add the src field value to the dest field. Dest field has the sum of src field value and original dst field value.

---
 drivers/net/mlx5/mlx5_flow_dv.c | 11 +++++++----
 drivers/net/mlx5/mlx5_flow_hw.c | 10 +++++++---
 2 files changed, 14 insertions(+), 7 deletions(-)
drivers/net/mlx5/mlx5_flow_dv.c +7 -4
index 272dbca00f..1c3d557d4a 100644
@@ -389,6 +389,7 @@ flow_dv_convert_modify_action(struct rte_flow_item *item,
 	uint32_t i = resource->actions_num;
 	struct mlx5_modification_cmd *actions = resource->actions;
 	uint32_t carry_b = 0;
+	bool to_dest;
 
 	/*
 	 * The item and mask are provided in big-endian format.
@@ -397,6 +398,8 @@ flow_dv_convert_modify_action(struct rte_flow_item *item,
 	 */
 	MLX5_ASSERT(item->mask);
 	MLX5_ASSERT(field->size);
+	to_dest = type == MLX5_MODIFICATION_TYPE_COPY ||
+		  type == MLX5_MODIFICATION_TYPE_ADD_FIELD;
 	do {
 		uint32_t size_b;
 		uint32_t off_b;
@@ -416,7 +419,7 @@ flow_dv_convert_modify_action(struct rte_flow_item *item,
 			++field;
 			continue;
 		}
-		if (type == MLX5_MODIFICATION_TYPE_COPY && field->is_flex) {
+		if (to_dest && field->is_flex) {
 			off_b = 32 - field->shift + carry_b - field->size * CHAR_BIT;
 			size_b = field->size * CHAR_BIT - carry_b;
 		} else {
@@ -433,7 +436,7 @@ flow_dv_convert_modify_action(struct rte_flow_item *item,
 			.length = (size_b == sizeof(uint32_t) * CHAR_BIT) ?
 				0 : size_b,
 		};
-		if (type == MLX5_MODIFICATION_TYPE_COPY) {
+		if (to_dest) {
 			MLX5_ASSERT(dest);
 			actions[i].dst_field = dest->id;
 			actions[i].dst_offset =
@@ -476,11 +479,11 @@ flow_dv_convert_modify_action(struct rte_flow_item *item,
 		}
 		/* Convert entire record to expected big-endian format. */
 		actions[i].data0 = rte_cpu_to_be_32(actions[i].data0);
-		if ((type != MLX5_MODIFICATION_TYPE_COPY ||
+		if ((!to_dest ||
 		     dest->id != (enum mlx5_modification_field)UINT32_MAX) &&
 		    field->id != (enum mlx5_modification_field)UINT32_MAX)
 			++i;
-		if (next_dest && type == MLX5_MODIFICATION_TYPE_COPY)
+		if (next_dest && to_dest)
 			++dest;
 		if (next_field)
 			++field;
drivers/net/mlx5/mlx5_flow_hw.c +7 -3
index da873ae2e2..d224979ee8 100644
@@ -1102,7 +1102,8 @@ flow_hw_should_insert_nop(const struct mlx5_hw_modify_header_action *mhdr,
 		if (last_type == MLX5_MODIFICATION_TYPE_SET ||
 		    last_type == MLX5_MODIFICATION_TYPE_ADD)
 			should_insert = new_cmd.field == last_cmd.field;
-		else if (last_type == MLX5_MODIFICATION_TYPE_COPY)
+		else if (last_type == MLX5_MODIFICATION_TYPE_COPY ||
+			 last_type == MLX5_MODIFICATION_TYPE_ADD_FIELD)
 			should_insert = new_cmd.field == last_cmd.dst_field;
 		else if (last_type == MLX5_MODIFICATION_TYPE_NOP)
 			should_insert = false;
@@ -1110,11 +1111,13 @@ flow_hw_should_insert_nop(const struct mlx5_hw_modify_header_action *mhdr,
 			MLX5_ASSERT(false); /* Other types are not supported. */
 		break;
 	case MLX5_MODIFICATION_TYPE_COPY:
+	case MLX5_MODIFICATION_TYPE_ADD_FIELD:
 		if (last_type == MLX5_MODIFICATION_TYPE_SET ||
 		    last_type == MLX5_MODIFICATION_TYPE_ADD)
 			should_insert = (new_cmd.field == last_cmd.field ||
 					 new_cmd.dst_field == last_cmd.field);
-		else if (last_type == MLX5_MODIFICATION_TYPE_COPY)
+		else if (last_type == MLX5_MODIFICATION_TYPE_COPY ||
+			 last_type == MLX5_MODIFICATION_TYPE_ADD_FIELD)
 			should_insert = (new_cmd.field == last_cmd.dst_field ||
 					 new_cmd.dst_field == last_cmd.dst_field);
 		else if (last_type == MLX5_MODIFICATION_TYPE_NOP)
@@ -1264,7 +1267,8 @@ flow_hw_modify_field_compile(struct rte_eth_dev *dev,
 			item.spec = &value;
 		}
 	} else {
-		type = MLX5_MODIFICATION_TYPE_COPY;
+		type = conf->operation == RTE_FLOW_MODIFY_SET ?
+		       MLX5_MODIFICATION_TYPE_COPY : MLX5_MODIFICATION_TYPE_ADD_FIELD;
 		/* For COPY fill the destination field (dcopy) without mask. */
 		mlx5_flow_field_id_to_modify_info(&conf->dst, dcopy, NULL,
 						  conf->width, dev,
Signature · 1 line
2.34.1
Acked-by on v1 3/4
#7 lore raw

RE: [PATCH 3/4] net/mlx5: add modify field action ADD fields support

Hi Suanming,

Quoted 11 lines

-----Original Message-----
From: Suanming Mou <[email protected]>
Sent: Thursday, December 14, 2023 5:04 AM
Subject: [PATCH 3/4] net/mlx5: add modify field action ADD fields support

ADD_FIELD operation allows user to add the src field value to the dest field. Dest field has the sum of src field value and original dst field value.

---

Best,
Ori

#8 lore raw

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

In reply to Suanming Mou

Due to HW limitation, not all the fields are available as ADD_FIELD destination.

This commit adds the validation to the destinations.

---
 doc/guides/rel_notes/release_24_03.rst |  4 ++++
 drivers/net/mlx5/mlx5_flow_hw.c        | 32 ++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
doc/guides/rel_notes/release_24_03.rst +4 -0
index e9c9717706..2c0e2930cc 100644
@@ -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
 -------------
drivers/net/mlx5/mlx5_flow_hw.c +32 -0
index d224979ee8..c4a90a3690 100644
@@ -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
Signature · 1 line
2.34.1
Acked-by on v1 4/4
#9 lore raw

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

Hi Suanming,

Quoted 11 lines

-----Original Message-----
From: Suanming Mou <[email protected]>
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.

---

Best,
Ori

#10 lore raw
In reply to Suanming Mou

Hi,

Quoted 26 lines

-----Original Message-----
From: Suanming Mou <[email protected]>
Sent: Thursday, December 14, 2023 5:04 AM
Cc: [email protected]; Raslan Darawsheh <[email protected]>
Subject: [PATCH 0/4] net/mlx5: add modify field ADD fields support

Before this series, the modify_field ADD operation in mlx5 PMD only allowed sum of immediate value to field.

ADD_FIELD operation allows user to add the src field value to the dest field. Dest field has the sum of src field value and original dst field value.

Suanming Mou (4):
net/mlx5: add TCP/IP length modify field net/mlx5: rename modify copy destination to destination net/mlx5: add modify field action ADD fields support net/mlx5: add modify field action ADD fields validation

 doc/guides/rel_notes/release_24_03.rst |  4 ++
 drivers/common/mlx5/mlx5_prm.h         |  4 ++
 drivers/net/mlx5/mlx5_flow.h           |  2 +-
 drivers/net/mlx5/mlx5_flow_dv.c        | 83 ++++++++++++++++++++------
 drivers/net/mlx5/mlx5_flow_hw.c        | 42 ++++++++++++-
 5 files changed, 112 insertions(+), 23 deletions(-)
Quoted 2 lines

--
2.34.1

Series applied to next-net-mlx,

Kindest regards
Raslan Darawsheh