DPDK patches and discussions
 help / color / mirror / Atom feed
From: Suanming Mou <suanmingm@nvidia.com>
To: Dariusz Sosnowski <dsosnowski@nvidia.com>,
	Viacheslav Ovsiienko <viacheslavo@nvidia.com>,
	Ori Kam <orika@nvidia.com>, Matan Azrad <matan@nvidia.com>
Cc: <dev@dpdk.org>
Subject: [PATCH v2 3/3] net/mlx5: add compare item support
Date: Tue, 19 Dec 2023 09:33:37 +0800	[thread overview]
Message-ID: <20231219013337.531548-4-suanmingm@nvidia.com> (raw)
In-Reply-To: <20231219013337.531548-1-suanmingm@nvidia.com>

The compare item allows adding flow match with comparison
result. This commit adds compare item support to the PMD
code.

Due to HW limitation:
 - Only HWS supported.
 - Only 32-bit comparison is supported.
 - Only single compare flow is supported in the flow table.
 - Only match with compare result between packet fields is
    supported.

Signed-off-by: Suanming Mou <suanmingm@nvidia.com>
---
 doc/guides/nics/features/mlx5.ini      |  1 +
 doc/guides/nics/mlx5.rst               |  7 +++
 doc/guides/rel_notes/release_24_03.rst |  2 +-
 drivers/net/mlx5/mlx5_flow.h           |  3 ++
 drivers/net/mlx5/mlx5_flow_hw.c        | 73 ++++++++++++++++++++++++++
 5 files changed, 85 insertions(+), 1 deletion(-)

diff --git a/doc/guides/nics/features/mlx5.ini b/doc/guides/nics/features/mlx5.ini
index 0739fe9d63..00e9348fc6 100644
--- a/doc/guides/nics/features/mlx5.ini
+++ b/doc/guides/nics/features/mlx5.ini
@@ -56,6 +56,7 @@ Usage doc            = Y
 
 [rte_flow items]
 aggr_affinity        = Y
+compare              = Y
 conntrack            = Y
 ecpri                = Y
 esp                  = Y
diff --git a/doc/guides/nics/mlx5.rst b/doc/guides/nics/mlx5.rst
index 6b52fb93c5..18b40bc22d 100644
--- a/doc/guides/nics/mlx5.rst
+++ b/doc/guides/nics/mlx5.rst
@@ -778,6 +778,13 @@ Limitations
   The flow engine of a process cannot move from active to standby mode
   if preceding active application rules are still present and vice versa.
 
+- Match with compare result item (``RTE_FLOW_ITEM_TYPE_COMPARE``):
+
+  - Only supported in HW steering(``dv_flow_en`` = 2) mode.
+  - Only single flow is supported to the flow table.
+  - Only 32-bit comparison is supported.
+  - Only match with compare result between packet fields is supported.
+
 
 Statistics
 ----------
diff --git a/doc/guides/rel_notes/release_24_03.rst b/doc/guides/rel_notes/release_24_03.rst
index 71ebd67dbd..5693ea4628 100644
--- a/doc/guides/rel_notes/release_24_03.rst
+++ b/doc/guides/rel_notes/release_24_03.rst
@@ -63,7 +63,7 @@ New Features
 * **Updated NVIDIA mlx5 driver.**
 
   * Added support for accumulating from src field to dst field.
-
+  * Added support for comparing result between packet fields or value.
 
 Removed Items
 -------------
diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index 8e2034473c..6698de2a3e 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -277,6 +277,9 @@ enum mlx5_feature_name {
 /* NSH ITEM */
 #define MLX5_FLOW_ITEM_NSH (1ull << 53)
 
+/* COMPARE ITEM */
+#define MLX5_FLOW_ITEM_COMPARE (1ull << 54)
+
 /* Outer Masks. */
 #define MLX5_FLOW_LAYER_OUTER_L3 \
 	(MLX5_FLOW_LAYER_OUTER_L3_IPV4 | MLX5_FLOW_LAYER_OUTER_L3_IPV6)
diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c
index c4a90a3690..82d7fa006f 100644
--- a/drivers/net/mlx5/mlx5_flow_hw.c
+++ b/drivers/net/mlx5/mlx5_flow_hw.c
@@ -426,6 +426,9 @@ flow_hw_matching_item_flags_get(const struct rte_flow_item items[])
 		case RTE_FLOW_ITEM_TYPE_GTP:
 			last_item = MLX5_FLOW_LAYER_GTP;
 			break;
+		case RTE_FLOW_ITEM_TYPE_COMPARE:
+			last_item = MLX5_FLOW_ITEM_COMPARE;
+			break;
 		default:
 			break;
 		}
@@ -4390,6 +4393,8 @@ flow_hw_table_create(struct rte_eth_dev *dev,
 			rte_errno = EINVAL;
 			goto it_error;
 		}
+		if (item_templates[i]->item_flags & MLX5_FLOW_ITEM_COMPARE)
+			matcher_attr.mode = MLX5DR_MATCHER_RESOURCE_MODE_HTABLE;
 		ret = __atomic_fetch_add(&item_templates[i]->refcnt, 1,
 					 __ATOMIC_RELAXED) + 1;
 		if (ret <= 1) {
@@ -6670,6 +6675,66 @@ flow_hw_prepend_item(const struct rte_flow_item *items,
 	return copied_items;
 }
 
+static inline bool
+flow_hw_item_compare_field_supported(enum rte_flow_field_id field)
+{
+	switch (field) {
+	case RTE_FLOW_FIELD_TAG:
+	case RTE_FLOW_FIELD_META:
+	case RTE_FLOW_FIELD_VALUE:
+		return true;
+	default:
+		break;
+	}
+	return false;
+}
+
+static int
+flow_hw_validate_item_compare(const struct rte_flow_item *item,
+			      struct rte_flow_error *error)
+{
+	const struct rte_flow_item_compare *comp_m = item->mask;
+	const struct rte_flow_item_compare *comp_v = item->spec;
+
+	if (unlikely(!comp_m))
+		return rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				   NULL,
+				   "compare item mask is missing");
+	if (comp_m->width != UINT32_MAX)
+		return rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				   NULL,
+				   "compare item only support full mask");
+	if (!flow_hw_item_compare_field_supported(comp_m->a.field) ||
+	    !flow_hw_item_compare_field_supported(comp_m->b.field))
+		return rte_flow_error_set(error, ENOTSUP,
+				   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				   NULL,
+				   "compare item field not support");
+	if (comp_m->a.field == RTE_FLOW_FIELD_VALUE &&
+	    comp_m->b.field == RTE_FLOW_FIELD_VALUE)
+		return rte_flow_error_set(error, EINVAL,
+				   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				   NULL,
+				   "compare between value is not valid");
+	if (comp_v) {
+		if (comp_v->operation != comp_m->operation ||
+		    comp_v->a.field != comp_m->a.field ||
+		    comp_v->b.field != comp_m->b.field)
+			return rte_flow_error_set(error, EINVAL,
+					   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					   NULL,
+					   "compare item spec/mask not matching");
+		if ((comp_v->width & comp_m->width) != 32)
+			return rte_flow_error_set(error, EINVAL,
+					   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					   NULL,
+					   "compare item only support full mask");
+	}
+	return 0;
+}
+
 static int
 flow_hw_pattern_validate(struct rte_eth_dev *dev,
 			 const struct rte_flow_pattern_template_attr *attr,
@@ -6680,6 +6745,7 @@ flow_hw_pattern_validate(struct rte_eth_dev *dev,
 	int i, tag_idx;
 	bool items_end = false;
 	uint32_t tag_bitmap = 0;
+	int ret;
 
 	if (!attr->ingress && !attr->egress && !attr->transfer)
 		return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ATTR, NULL,
@@ -6817,6 +6883,13 @@ flow_hw_pattern_validate(struct rte_eth_dev *dev,
 							  " attribute");
 			break;
 		}
+		case RTE_FLOW_ITEM_TYPE_COMPARE:
+		{
+			ret = flow_hw_validate_item_compare(&items[i], error);
+			if (ret)
+				return ret;
+			break;
+		}
 		case RTE_FLOW_ITEM_TYPE_VOID:
 		case RTE_FLOW_ITEM_TYPE_ETH:
 		case RTE_FLOW_ITEM_TYPE_VLAN:
-- 
2.34.1


  parent reply	other threads:[~2023-12-19  1:34 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-14  3:12 [PATCH 0/2] ethdev: add RTE_FLOW_ITEM_TYPE_COMPARE Suanming Mou
2023-12-14  3:12 ` [PATCH 1/2] " Suanming Mou
2023-12-14  3:12 ` [PATCH 2/2] net/mlx5: add compare item support Suanming Mou
2023-12-19  1:33 ` [PATCH v2 0/3] [PATCH 0/2] ethdev: add RTE_FLOW_ITEM_TYPE_COMPARE Suanming Mou
2023-12-19  1:33   ` [PATCH v2 1/3] ethdev: rename action modify field data structure Suanming Mou
2024-01-09 14:07     ` Ori Kam
2024-01-12  8:03       ` Andrew Rybchenko
2023-12-19  1:33   ` [PATCH v2 2/3] ethdev: add compare item Suanming Mou
2024-01-09 14:26     ` Ori Kam
2024-01-12  8:11     ` Andrew Rybchenko
2024-01-15  8:14       ` Suanming Mou
2023-12-19  1:33   ` Suanming Mou [this message]
2024-01-09 14:28     ` [PATCH v2 3/3] net/mlx5: add compare item support Ori Kam
2024-01-15  9:13   ` [PATCH v3 0/3] ethdev: add RTE_FLOW_ITEM_TYPE_COMPARE Suanming Mou
2024-01-15  9:13     ` [PATCH v3 1/3] ethdev: rename action modify field data structure Suanming Mou
2024-01-30 17:19       ` Ferruh Yigit
2024-01-31  2:57         ` Suanming Mou
2024-02-01 10:56           ` Ferruh Yigit
2024-02-01 11:09             ` Suanming Mou
2024-02-01 11:20               ` Ferruh Yigit
2024-02-01 11:39                 ` Suanming Mou
2024-01-15  9:13     ` [PATCH v3 2/3] ethdev: add compare item Suanming Mou
2024-01-30 17:33       ` Ferruh Yigit
2024-01-31  2:47         ` Suanming Mou
2024-01-31 15:56           ` Ori Kam
2024-01-31 16:46             ` Ferruh Yigit
2024-01-31 17:43               ` Ori Kam
2024-01-31 17:54                 ` Ferruh Yigit
2024-02-01  6:51                   ` Ori Kam
2024-02-01  0:31               ` Suanming Mou
2024-01-15  9:13     ` [PATCH v3 3/3] net/mlx5: add compare item support Suanming Mou
2024-02-01  2:30 ` [PATCH v4 0/3] ethdev: add RTE_FLOW_ITEM_TYPE_COMPARE Suanming Mou
2024-02-01  2:30   ` [PATCH v4 1/3] ethdev: rename action modify field data structure Suanming Mou
2024-02-01  2:30   ` [PATCH v4 2/3] ethdev: add compare item Suanming Mou
2024-02-01  2:30   ` [PATCH v4 3/3] net/mlx5: add compare item support Suanming Mou
2024-02-01 12:29 ` [PATCH v5 0/3] ethdev: add RTE_FLOW_ITEM_TYPE_COMPARE Suanming Mou
2024-02-01 12:29   ` [PATCH v5 1/3] ethdev: rename action modify field data structure Suanming Mou
2024-02-01 18:57     ` Ferruh Yigit
2024-02-01 12:29   ` [PATCH v5 2/3] ethdev: add compare item Suanming Mou
2024-02-01 18:57     ` Ferruh Yigit
2024-02-01 12:29   ` [PATCH v5 3/3] net/mlx5: add compare item support Suanming Mou
2024-02-01 18:57     ` Ferruh Yigit
2024-02-01 18:56   ` [PATCH v5 0/3] ethdev: add RTE_FLOW_ITEM_TYPE_COMPARE Ferruh Yigit
2024-02-02  0:32     ` Suanming Mou
2024-02-02  0:42 ` [PATCH v6 " Suanming Mou
2024-02-02  0:42   ` [PATCH v6 1/3] ethdev: rename action modify field data structure Suanming Mou
2024-02-05 11:23     ` Thomas Monjalon
2024-02-05 11:49       ` Suanming Mou
2024-02-05 12:39         ` Thomas Monjalon
2024-02-05 12:53           ` Suanming Mou
2024-02-02  0:42   ` [PATCH v6 2/3] ethdev: add compare item Suanming Mou
2024-02-05 13:00     ` Thomas Monjalon
2024-02-05 13:28       ` Suanming Mou
2024-02-05 14:09         ` Thomas Monjalon
2024-02-06  1:26           ` Suanming Mou
2024-02-02  0:42   ` [PATCH v6 3/3] net/mlx5: add compare item support Suanming Mou
2024-02-06  2:06 ` [PATCH v7 0/4] ethdev: add RTE_FLOW_ITEM_TYPE_COMPARE Suanming Mou
2024-02-06  2:06   ` [PATCH v7 1/4] ethdev: rename action modify field data structure Suanming Mou
2024-02-06 21:23     ` Ferruh Yigit
2024-02-06  2:06   ` [PATCH v7 2/4] ethdev: move flow field data structures Suanming Mou
2024-02-06 21:23     ` Ferruh Yigit
2024-02-06  2:06   ` [PATCH v7 3/4] ethdev: add compare item Suanming Mou
2024-02-06 21:24     ` Ferruh Yigit
2024-02-06  2:06   ` [PATCH v7 4/4] net/mlx5: add compare item support Suanming Mou
2024-02-06 21:23     ` Ferruh Yigit
2024-02-06 21:24   ` [PATCH v7 0/4] ethdev: add RTE_FLOW_ITEM_TYPE_COMPARE 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=20231219013337.531548-4-suanmingm@nvidia.com \
    --to=suanmingm@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=dsosnowski@nvidia.com \
    --cc=matan@nvidia.com \
    --cc=orika@nvidia.com \
    --cc=viacheslavo@nvidia.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).