Skip to contentSkip to conversation

net/mlx5/hws: split the root rule creation and destruction

PATCH Superseded Maayan Kashani 1 participant 3 messages Jun 3, 2024 1 message not in the archive

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#1 lore raw

PATCH v2 2/34 net/mlx5/hws: split the root rule creation and destruction

In reply to a message not in the archive

From: Yevgeny Kliteynik <[email protected]>

Split the root rule creation/destruction into two stages:
- do the job (create/destroy rule)
- generate completion

Completion generation is required for the usual HWS API. The create/destroy functions that don't generate completion are exposed in header file and will be used by the coming backward-compatible API.

---
 drivers/net/mlx5/hws/mlx5dr_rule.c | 49 +++++++++++++++++++++---------
 drivers/net/mlx5/hws/mlx5dr_rule.h |  7 +++++
 2 files changed, 42 insertions(+), 14 deletions(-)
drivers/net/mlx5/hws/mlx5dr_rule.c +35 -14
index 171a0bff38..550f00a4c1 100644
@@ -680,15 +680,12 @@ static int mlx5dr_rule_destroy_hws(struct mlx5dr_rule *rule,
 	return 0;
 }
 
-static int mlx5dr_rule_create_root(struct mlx5dr_rule *rule,
-				   struct mlx5dr_rule_attr *rule_attr,
-				   const struct rte_flow_item items[],
-				   uint8_t at_idx,
-				   struct mlx5dr_rule_action rule_actions[])
+int mlx5dr_rule_create_root_no_comp(struct mlx5dr_rule *rule,
+				    const struct rte_flow_item items[],
+				    uint8_t num_actions,
+				    struct mlx5dr_rule_action rule_actions[])
 {
 	struct mlx5dv_flow_matcher *dv_matcher = rule->matcher->dv_matcher;
-	uint8_t num_actions = rule->matcher->at[at_idx].num_actions;
-	struct mlx5dr_context *ctx = rule->matcher->tbl->ctx;
 	struct mlx5dv_flow_match_parameters *value;
 	struct mlx5_flow_attr flow_attr = {0};
 	struct mlx5dv_flow_action_attr *attr;
@@ -750,9 +747,6 @@ static int mlx5dr_rule_create_root(struct mlx5dr_rule *rule,
 						    num_actions,
 						    attr);
 
-	mlx5dr_rule_gen_comp(&ctx->send_queue[rule_attr->queue_id], rule, !rule->flow,
-			     rule_attr->user_data, MLX5DR_RULE_STATUS_CREATED);
-
 	simple_free(value);
 	simple_free(attr);
 
@@ -766,14 +760,41 @@ static int mlx5dr_rule_create_root(struct mlx5dr_rule *rule,
 	return rte_errno;
 }
 
+static int mlx5dr_rule_create_root(struct mlx5dr_rule *rule,
+				   struct mlx5dr_rule_attr *rule_attr,
+				   const struct rte_flow_item items[],
+				   uint8_t num_actions,
+				   struct mlx5dr_rule_action rule_actions[])
+{
+	struct mlx5dr_context *ctx = rule->matcher->tbl->ctx;
+	int ret;
+
+	ret = mlx5dr_rule_create_root_no_comp(rule, items,
+					      num_actions, rule_actions);
+	if (ret)
+		return rte_errno;
+
+	mlx5dr_rule_gen_comp(&ctx->send_queue[rule_attr->queue_id], rule, !rule->flow,
+			     rule_attr->user_data, MLX5DR_RULE_STATUS_CREATED);
+
+	return 0;
+}
+
+int mlx5dr_rule_destroy_root_no_comp(struct mlx5dr_rule *rule)
+{
+	if (rule->flow)
+		return ibv_destroy_flow(rule->flow);
+
+	return 0;
+}
+
 static int mlx5dr_rule_destroy_root(struct mlx5dr_rule *rule,
 				    struct mlx5dr_rule_attr *attr)
 {
 	struct mlx5dr_context *ctx = rule->matcher->tbl->ctx;
-	int err = 0;
+	int err;
 
-	if (rule->flow)
-		err = ibv_destroy_flow(rule->flow);
+	err = mlx5dr_rule_destroy_root_no_comp(rule);
 
 	mlx5dr_rule_gen_comp(&ctx->send_queue[attr->queue_id], rule, err,
 			     attr->user_data, MLX5DR_RULE_STATUS_DELETED);
@@ -970,7 +991,7 @@ int mlx5dr_rule_create(struct mlx5dr_matcher *matcher,
 		ret = mlx5dr_rule_create_root(rule_handle,
 					      attr,
 					      items,
-					      at_idx,
+					      matcher->at[at_idx].num_actions,
 					      rule_actions);
 	else
 		ret = mlx5dr_rule_create_hws(rule_handle,
drivers/net/mlx5/hws/mlx5dr_rule.h +7 -0
index dffaec1c0f..bc542eb543 100644
@@ -74,4 +74,11 @@ int mlx5dr_rule_move_hws_add(struct mlx5dr_rule *rule,
 
 bool mlx5dr_rule_move_in_progress(struct mlx5dr_rule *rule);
 
+int mlx5dr_rule_create_root_no_comp(struct mlx5dr_rule *rule,
+				    const struct rte_flow_item items[],
+				    uint8_t num_actions,
+				    struct mlx5dr_rule_action rule_actions[]);
+
+int mlx5dr_rule_destroy_root_no_comp(struct mlx5dr_rule *rule);
+
 #endif /* MLX5DR_RULE_H_ */
Signature · 1 line
2.25.1
#2 lore raw

PATCH v2 3/34 net/mlx5/hws: add support for action type LAST

From: Yevgeny Kliteynik <[email protected]>

Add support for MLX5DR_ACTION_TYP_LAST action type.

---
 drivers/net/mlx5/hws/mlx5dr.h        | 12 ++++++++++++
 drivers/net/mlx5/hws/mlx5dr_action.c |  9 +++++++++
 2 files changed, 21 insertions(+)
drivers/net/mlx5/hws/mlx5dr.h +12 -0
index 86cd4f1db5..5ceb1a7b4b 100644
@@ -677,6 +677,18 @@ struct mlx5dr_action *
 mlx5dr_action_create_tag(struct mlx5dr_context *ctx,
 			 uint32_t flags);
 
+/* Create direct rule LAST action.
+ *
+ * @param[in] ctx
+ *	The context in which the new action will be created.
+ * @param[in] flags
+ *	Action creation flags. (enum mlx5dr_action_flags)
+ * @return pointer to mlx5dr_action on success NULL otherwise.
+ */
+struct mlx5dr_action *
+mlx5dr_action_create_last(struct mlx5dr_context *ctx,
+			  uint32_t flags);
+
 /* Create direct rule counter action.
  *
  * @param[in] ctx
drivers/net/mlx5/hws/mlx5dr_action.c +9 -0
index 562fb5cbb4..90f2f17bd0 100644
@@ -1319,6 +1319,13 @@ mlx5dr_action_create_tag(struct mlx5dr_context *ctx,
 	return NULL;
 }
 
+struct mlx5dr_action *
+mlx5dr_action_create_last(struct mlx5dr_context *ctx,
+			  uint32_t flags)
+{
+	return mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_LAST);
+}
+
 static struct mlx5dr_action *
 mlx5dr_action_create_aso(struct mlx5dr_context *ctx,
 			 enum mlx5dr_action_type action_type,
@@ -3005,6 +3012,8 @@ static void mlx5dr_action_destroy_hws(struct mlx5dr_action *action)
 		for (i = 0; i < MLX5DR_ACTION_NAT64_STAGES; i++)
 			mlx5dr_action_destroy(action->nat64.stages[i]);
 		break;
+	case MLX5DR_ACTION_TYP_LAST:
+		break;
 	}
 }
 
Signature · 1 line
2.25.1
#3 lore raw

PATCH v2 4/34 net/mlx5/hws: add support for backward-compatible API

In reply to Maayan Kashani

From: Yevgeny Kliteynik <[email protected]>

HWS API is very different from SWS and has limitations:
- Queue based async insertion/deletion
- Doesn’t handle complex rules
- Requires the user to specify fixed matcher size – no rehash
- Requires the user to specify action combination on matcher creation
- Matching fields are passed using items and not FW/PRM format

These problems need to be solved in order to support HWS with the old rte_flow API.

This patch adds backward-compatible (BWC) HWS API to allow for the use of HWS in rte_flow and support the existing template-based API alongside with the rte_flow API.

The new BWC API comprises mainly of the following four functions:
- mlx5dr_bwc_matcher_create
- mlx5dr_bwc_matcher_destroy
- mlx5dr_bwc_rule_create
- mlx5dr_bwc_rule_destroy

Notes:
- To enable BWC API support, need to turn on 'bwc' flag in context attributes when calling mlx5dr_context_open()
- BWC functions use their own queues
- BWC functions provide synchronous API - they add/remove rule and poll for completion
- BWC functions handle all the required matchers and rules allocations
- For non-root tables, BWC functions use matcher resize and matcher attach action template features

---
 drivers/net/mlx5/hws/meson.build       |   1 +
 drivers/net/mlx5/hws/mlx5dr.h          |  75 +++
 drivers/net/mlx5/hws/mlx5dr_bwc.c      | 898 +++++++++++++++++++++++++
 drivers/net/mlx5/hws/mlx5dr_bwc.h      |  34 +
 drivers/net/mlx5/hws/mlx5dr_context.c  |   3 +
 drivers/net/mlx5/hws/mlx5dr_context.h  |   7 +
 drivers/net/mlx5/hws/mlx5dr_internal.h |   1 +
 drivers/net/mlx5/hws/mlx5dr_send.c     |  43 +-
 8 files changed, 1061 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/mlx5/hws/mlx5dr_bwc.c
 create mode 100644 drivers/net/mlx5/hws/mlx5dr_bwc.h
drivers/net/mlx5/hws/meson.build +1 -0
index bbcc628557..859a87fb85 100644
@@ -20,4 +20,5 @@ sources += files(
         'mlx5dr_debug.c',
         'mlx5dr_pat_arg.c',
         'mlx5dr_crc32.c',
+        'mlx5dr_bwc.c',
 )
drivers/net/mlx5/hws/mlx5dr.h +75 -0

85 lines not on this page · raw message

drivers/net/mlx5/hws/mlx5dr_bwc.c new file +898 -0

898 lines not on this page · raw message

drivers/net/mlx5/hws/mlx5dr_bwc.h new file +34 -0
new file mode 100644
index 0000000000..648443861b
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2023 NVIDIA Corporation & Affiliates
+ */
+
+#ifndef MLX5DR_BWC_H_
+#define MLX5DR_BWC_H_
+
+#define MLX5DR_BWC_MATCHER_INIT_SIZE_LOG 1
+#define MLX5DR_BWC_MATCHER_SIZE_LOG_STEP 1
+#define MLX5DR_BWC_MATCHER_REHASH_PERCENT_TH 70
+#define MLX5DR_BWC_MATCHER_REHASH_BURST_TH 32
+#define MLX5DR_BWC_MATCHER_REHASH_QUEUE_SZ 256
+#define MLX5DR_BWC_MATCHER_ATTACH_AT_NUM 255
+
+struct mlx5dr_bwc_matcher {
+	struct mlx5dr_matcher *matcher;
+	struct mlx5dr_match_template *mt;
+	struct mlx5dr_action_template *at[MLX5DR_BWC_MATCHER_ATTACH_AT_NUM];
+	uint8_t num_of_at;
+	uint32_t priority;
+	uint8_t size_log;
+	RTE_ATOMIC(uint32_t)num_of_rules; /* atomically accessed */
+	LIST_HEAD(rule_head, mlx5dr_bwc_rule) * rules;
+};
+
+struct mlx5dr_bwc_rule {
+	struct mlx5dr_bwc_matcher *bwc_matcher;
+	struct mlx5dr_rule *rule;
+	struct rte_flow_item *flow_items;
+	uint16_t bwc_queue_idx;
+	LIST_ENTRY(mlx5dr_bwc_rule) next;
+};
+
+#endif /* MLX5DR_BWC_H_ */
drivers/net/mlx5/hws/mlx5dr_context.c +3 -0
index 7f120b3b1b..db5e72927a 100644
@@ -176,6 +176,9 @@ static int mlx5dr_context_init_hws(struct mlx5dr_context *ctx,
 	if (ret)
 		goto uninit_pd;
 
+	if (attr->bwc)
+		ctx->flags |= MLX5DR_CONTEXT_FLAG_BWC_SUPPORT;
+
 	ret = mlx5dr_send_queues_open(ctx, attr->queues, attr->queue_size);
 	if (ret)
 		goto pools_uninit;
drivers/net/mlx5/hws/mlx5dr_context.h +7 -0
index f476c2308c..7678232ecc 100644
@@ -8,6 +8,7 @@
 enum mlx5dr_context_flags {
 	MLX5DR_CONTEXT_FLAG_HWS_SUPPORT = 1 << 0,
 	MLX5DR_CONTEXT_FLAG_PRIVATE_PD = 1 << 1,
+	MLX5DR_CONTEXT_FLAG_BWC_SUPPORT = 1 << 2,
 };
 
 enum mlx5dr_context_shared_stc_type {
@@ -44,6 +45,7 @@ struct mlx5dr_context {
 	enum mlx5dr_context_flags flags;
 	struct mlx5dr_send_engine *send_queue;
 	size_t queues;
+	rte_spinlock_t *bwc_send_queue_locks;
 	LIST_HEAD(table_head, mlx5dr_table) head;
 };
 
@@ -52,6 +54,11 @@ static inline bool mlx5dr_context_shared_gvmi_used(struct mlx5dr_context *ctx)
 	return ctx->local_ibv_ctx ? true : false;
 }
 
+static inline bool mlx5dr_context_bwc_supported(struct mlx5dr_context *ctx)
+{
+	return ctx->flags & MLX5DR_CONTEXT_FLAG_BWC_SUPPORT;
+}
+
 static inline struct ibv_context *
 mlx5dr_context_get_local_ibv(struct mlx5dr_context *ctx)
 {
drivers/net/mlx5/hws/mlx5dr_internal.h +1 -0
index b9efdc4a9a..2abc516b5e 100644
@@ -39,6 +39,7 @@
 #include "mlx5dr_debug.h"
 #include "mlx5dr_pat_arg.h"
 #include "mlx5dr_crc32.h"
+#include "mlx5dr_bwc.h"
 
 #define W_SIZE		2
 #define DW_SIZE		4
drivers/net/mlx5/hws/mlx5dr_send.c +42 -1

68 lines not on this page · raw message

Signature · 1 line
2.25.1