DPDK patches and discussions
 help / color / mirror / Atom feed
From: Michael Baum <michaelba@nvidia.com>
To: <dev@dpdk.org>
Cc: Matan Azrad <matan@nvidia.com>,
	Dariusz Sosnowski <dsosnowski@nvidia.com>,
	 Raslan Darawsheh <rasland@nvidia.com>,
	Viacheslav Ovsiienko <viacheslavo@nvidia.com>,
	Ori Kam <orika@nvidia.com>, Suanming Mou <suanmingm@nvidia.com>
Subject: [PATCH v1 2/2] net/mlx5: add support to compare random value
Date: Mon, 25 Dec 2023 12:45:34 +0200	[thread overview]
Message-ID: <20231225104534.2420737-3-michaelba@nvidia.com> (raw)
In-Reply-To: <20231225104534.2420737-1-michaelba@nvidia.com>

Add support to use "RTE_FLOW_ITEM_TYPE_COMPARE" with
"RTE_FLOW_FIELD_RAMDOM" as an argument.
The random field is supported only when base is an immediate value,
random field cannot be compared with enother field.

Signed-off-by: Michael Baum <michaelba@nvidia.com>
---
 drivers/net/mlx5/mlx5_flow_hw.c | 70 ++++++++++++++++++++++++---------
 1 file changed, 52 insertions(+), 18 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c
index a944a9b5b0..d472f83909 100644
--- a/drivers/net/mlx5/mlx5_flow_hw.c
+++ b/drivers/net/mlx5/mlx5_flow_hw.c
@@ -6643,18 +6643,55 @@ 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)
+static int
+flow_hw_item_compare_field_validate(enum rte_flow_field_id arg_field,
+				    enum rte_flow_field_id base_field,
+				    struct rte_flow_error *error)
 {
-	switch (field) {
+	switch (arg_field) {
+	case RTE_FLOW_FIELD_TAG:
+	case RTE_FLOW_FIELD_META:
+		break;
+	case RTE_FLOW_FIELD_RANDOM:
+		if (base_field == RTE_FLOW_FIELD_VALUE)
+			return 0;
+		return rte_flow_error_set(error, EINVAL,
+					  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					  NULL,
+					  "compare random is supported only with immediate value");
+	default:
+		return rte_flow_error_set(error, ENOTSUP,
+					  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					  NULL,
+					  "compare item argument field is not supported");
+	}
+	switch (base_field) {
 	case RTE_FLOW_FIELD_TAG:
 	case RTE_FLOW_FIELD_META:
 	case RTE_FLOW_FIELD_VALUE:
-		return true;
+		break;
+	default:
+		return rte_flow_error_set(error, ENOTSUP,
+					  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+					  NULL,
+					  "compare item base field is not supported");
+	}
+	return 0;
+}
+
+static inline uint32_t
+flow_hw_item_compare_width_supported(enum rte_flow_field_id field)
+{
+	switch (field) {
+	case RTE_FLOW_FIELD_TAG:
+	case RTE_FLOW_FIELD_META:
+		return 32;
+	case RTE_FLOW_FIELD_RANDOM:
+		return 16;
 	default:
 		break;
 	}
-	return false;
+	return 0;
 }
 
 static int
@@ -6663,6 +6700,7 @@ flow_hw_validate_item_compare(const struct rte_flow_item *item,
 {
 	const struct rte_flow_item_compare *comp_m = item->mask;
 	const struct rte_flow_item_compare *comp_v = item->spec;
+	int ret;
 
 	if (unlikely(!comp_m))
 		return rte_flow_error_set(error, EINVAL,
@@ -6674,19 +6712,13 @@ flow_hw_validate_item_compare(const struct rte_flow_item *item,
 				   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");
+	ret = flow_hw_item_compare_field_validate(comp_m->a.field,
+						  comp_m->b.field, error);
+	if (ret < 0)
+		return ret;
 	if (comp_v) {
+		uint32_t width;
+
 		if (comp_v->operation != comp_m->operation ||
 		    comp_v->a.field != comp_m->a.field ||
 		    comp_v->b.field != comp_m->b.field)
@@ -6694,7 +6726,9 @@ flow_hw_validate_item_compare(const struct rte_flow_item *item,
 					   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 					   NULL,
 					   "compare item spec/mask not matching");
-		if ((comp_v->width & comp_m->width) != 32)
+		width = flow_hw_item_compare_width_supported(comp_v->a.field);
+		MLX5_ASSERT(width > 0);
+		if ((comp_v->width & comp_m->width) != width)
 			return rte_flow_error_set(error, EINVAL,
 					   RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 					   NULL,
-- 
2.25.1


  parent reply	other threads:[~2023-12-25 10:45 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-25 10:45 [PATCH v1 0/2] net/mlx5: add random compare support Michael Baum
2023-12-25 10:45 ` [PATCH v1 1/2] net/mlx5/hws: add support for compare matcher Michael Baum
2023-12-25 10:45 ` Michael Baum [this message]
2024-01-28 10:22 ` [PATCH v2 0/2] net/mlx5: add random compare support Michael Baum
2024-01-28 10:22   ` [PATCH v2 1/2] net/mlx5/hws: add support for compare matcher Michael Baum
2024-01-28 10:22   ` [PATCH v2 2/2] net/mlx5: add support to compare random value Michael Baum
2024-01-29 13:44   ` [PATCH v3 0/2] net/mlx5: add random compare support Michael Baum
2024-01-29 13:44     ` [PATCH v3 1/2] net/mlx5/hws: add support for compare matcher Michael Baum
2024-01-29 13:44     ` [PATCH v3 2/2] net/mlx5: add support to compare random value Michael Baum
2024-02-07 16:14     ` [PATCH v4 0/2] net/mlx5: add random compare support Michael Baum
2024-02-07 16:14       ` [PATCH v4 1/2] net/mlx5/hws: add support for compare matcher Michael Baum
2024-02-07 16:14       ` [PATCH v4 2/2] net/mlx5: add support to compare random value Michael Baum
2024-02-14  7:30       ` [PATCH v5 0/3] net/mlx5: add compare item support Michael Baum
2024-02-14  7:30         ` [PATCH v5 1/3] net/mlx5/hws: add support for compare matcher Michael Baum
2024-02-19  3:00           ` Suanming Mou
2024-02-14  7:30         ` [PATCH v5 2/3] net/mlx5: add support to compare random value Michael Baum
2024-02-19  3:00           ` Suanming Mou
2024-02-14  7:30         ` [PATCH v5 3/3] net/mlx5/hws: add compare ESP sequence number support Michael Baum
2024-02-19  2:59           ` Suanming Mou
2024-02-19  7:21             ` Michael Baum
2024-02-19  7:37               ` Suanming Mou
2024-02-26 13:03         ` [PATCH v6 0/3] net/mlx5: add compare item support Michael Baum
2024-02-26 13:03           ` [PATCH v6 1/3] net/mlx5/hws: add support for compare matcher Michael Baum
2024-02-26 13:03           ` [PATCH v6 2/3] net/mlx5: add support to compare random value Michael Baum
2024-02-26 13:03           ` [PATCH v6 3/3] net/mlx5/hws: add compare ESP sequence number support Michael Baum
2024-02-26 13:18           ` [PATCH v7 0/3] net/mlx5: add compare item support Michael Baum
2024-02-26 13:18             ` [PATCH v7 1/3] net/mlx5/hws: add support for compare matcher Michael Baum
2024-02-26 13:18             ` [PATCH v7 2/3] net/mlx5: add support to compare random value Michael Baum
2024-02-26 13:18             ` [PATCH v7 3/3] net/mlx5/hws: add compare ESP sequence number support Michael Baum
2024-02-27  9:08             ` [PATCH v7 0/3] net/mlx5: add compare item support Raslan Darawsheh

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=20231225104534.2420737-3-michaelba@nvidia.com \
    --to=michaelba@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=dsosnowski@nvidia.com \
    --cc=matan@nvidia.com \
    --cc=orika@nvidia.com \
    --cc=rasland@nvidia.com \
    --cc=suanmingm@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).