[v1,1/3] net/mlx5/hws: support dest root table action

Message ID 20230320141229.104748-1-hamdani@nvidia.com (mailing list archive)
State Accepted, archived
Delegated to: Raslan Darawsheh
Headers
Series [v1,1/3] net/mlx5/hws: support dest root table action |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Hamdan Igbaria March 20, 2023, 2:12 p.m. UTC
  Add support for dest root table action creation.
This support will allow to redirect the packets to
the kernel from non root tables.

Signed-off-by: Hamdan Igbaria <hamdani@nvidia.com>
Reviewed-by: Alex Vesker <valex@nvidia.com>
---
 drivers/common/mlx5/linux/meson.build |  2 +
 drivers/common/mlx5/linux/mlx5_glue.c | 28 +++++++++
 drivers/common/mlx5/linux/mlx5_glue.h | 16 +++++
 drivers/net/mlx5/hws/mlx5dr.h         | 19 ++++++
 drivers/net/mlx5/hws/mlx5dr_action.c  | 84 +++++++++++++++++++++++++--
 drivers/net/mlx5/hws/mlx5dr_action.h  |  3 +
 drivers/net/mlx5/hws/mlx5dr_debug.c   |  1 +
 7 files changed, 147 insertions(+), 6 deletions(-)
  

Comments

Matan Azrad May 15, 2023, 8:24 a.m. UTC | #1
From: Hamdan Igbaria
> Add support for dest root table action creation.
> This support will allow to redirect the packets to the kernel from non root
> tables.
> 
> Signed-off-by: Hamdan Igbaria <hamdani@nvidia.com>
> Reviewed-by: Alex Vesker <valex@nvidia.com>
Series-acked-by: Matan Azrad <matan@nvidia.com>
  
Raslan Darawsheh May 24, 2023, 9:01 a.m. UTC | #2
Hi,

> -----Original Message-----
> From: Hamdan Igbaria <hamdani@nvidia.com>
> Sent: Monday, March 20, 2023 4:12 PM
> To: Hamdan Igbaria <hamdani@nvidia.com>; Slava Ovsiienko
> <viacheslavo@nvidia.com>; NBU-Contact-Thomas Monjalon (EXTERNAL)
> <thomas@monjalon.net>; Suanming Mou <suanmingm@nvidia.com>; Matan
> Azrad <matan@nvidia.com>
> Cc: dev@dpdk.org; Ori Kam <orika@nvidia.com>; Alex Vesker
> <valex@nvidia.com>
> Subject: [v1 1/3] net/mlx5/hws: support dest root table action
> 
> Add support for dest root table action creation.
> This support will allow to redirect the packets to the kernel from non root
> tables.
> 
> Signed-off-by: Hamdan Igbaria <hamdani@nvidia.com>
> Reviewed-by: Alex Vesker <valex@nvidia.com>

Series applied to next-net-mlx,

Kindest regards,
Raslan Darawsheh
  

Patch

diff --git a/drivers/common/mlx5/linux/meson.build b/drivers/common/mlx5/linux/meson.build
index 96a6c6c9be..16d7011899 100644
--- a/drivers/common/mlx5/linux/meson.build
+++ b/drivers/common/mlx5/linux/meson.build
@@ -219,6 +219,8 @@  has_sym_args = [
             'ibv_import_device' ],
         [ 'HAVE_MLX5DV_DR_ACTION_CREATE_DEST_ROOT_TABLE', 'infiniband/mlx5dv.h',
             'mlx5dv_dr_action_create_dest_root_table' ],
+        [ 'HAVE_MLX5DV_CREATE_STEERING_ANCHOR', 'infiniband/mlx5dv.h',
+	        'mlx5dv_create_steering_anchor'],
 ]
 if  libmtcr_ul_found
     has_sym_args += [
diff --git a/drivers/common/mlx5/linux/mlx5_glue.c b/drivers/common/mlx5/linux/mlx5_glue.c
index 702eb36b62..3497aa940d 100644
--- a/drivers/common/mlx5/linux/mlx5_glue.c
+++ b/drivers/common/mlx5/linux/mlx5_glue.c
@@ -1548,6 +1548,32 @@  mlx5_glue_dr_create_flow_action_send_to_kernel(void *tbl, uint16_t priority)
 #endif
 }
 
+static struct mlx5dv_steering_anchor *
+mlx5_glue_dv_create_steering_anchor(struct ibv_context *context,
+				    struct mlx5dv_steering_anchor_attr *attr)
+{
+#ifdef HAVE_MLX5DV_CREATE_STEERING_ANCHOR
+	return mlx5dv_create_steering_anchor(context, attr);
+#else
+	(void)context;
+	(void)attr;
+	errno = ENOTSUP;
+	return NULL;
+#endif
+}
+
+static int
+mlx5_glue_dv_destroy_steering_anchor(struct mlx5dv_steering_anchor *sa)
+{
+#ifdef HAVE_MLX5DV_CREATE_STEERING_ANCHOR
+	return mlx5dv_destroy_steering_anchor(sa);
+#else
+	(void)sa;
+	errno = ENOTSUP;
+	return -ENOTSUP;
+#endif
+}
+
 __rte_cache_aligned
 const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue) {
 	.version = MLX5_GLUE_VERSION,
@@ -1685,4 +1711,6 @@  const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue) {
 	.dv_free_pp = mlx5_glue_dv_free_pp,
 	.dr_create_flow_action_send_to_kernel =
 		mlx5_glue_dr_create_flow_action_send_to_kernel,
+	.create_steering_anchor = mlx5_glue_dv_create_steering_anchor,
+	.destroy_steering_anchor = mlx5_glue_dv_destroy_steering_anchor,
 };
diff --git a/drivers/common/mlx5/linux/mlx5_glue.h b/drivers/common/mlx5/linux/mlx5_glue.h
index 88aa7430e8..81d6b0aaf9 100644
--- a/drivers/common/mlx5/linux/mlx5_glue.h
+++ b/drivers/common/mlx5/linux/mlx5_glue.h
@@ -148,6 +148,18 @@  struct mlx5dv_var { uint32_t page_id; uint32_t length; off_t mmap_off;
 #define IBV_ACCESS_RELAXED_ORDERING 0
 #endif
 
+#ifndef HAVE_MLX5DV_CREATE_STEERING_ANCHOR
+struct mlx5dv_steering_anchor_attr {
+	uint32_t ft_type;
+	uint16_t priority;
+	uint64_t comp_mask;
+};
+
+struct mlx5dv_steering_anchor {
+	uint32_t id;
+};
+#endif
+
 struct mlx5_glue {
 	const char *version;
 	int (*fork_init)(void);
@@ -392,6 +404,10 @@  struct mlx5_glue {
 			 uint32_t offset, uint32_t flags, uint8_t return_reg_c);
 	void *(*dr_create_flow_action_send_to_kernel)(void *tbl,
 						      uint16_t priority);
+	struct mlx5dv_steering_anchor *(*create_steering_anchor)
+					(struct ibv_context *context,
+					 struct mlx5dv_steering_anchor_attr *attr);
+	int (*destroy_steering_anchor)(struct mlx5dv_steering_anchor *sa);
 };
 
 extern const struct mlx5_glue *mlx5_glue;
diff --git a/drivers/net/mlx5/hws/mlx5dr.h b/drivers/net/mlx5/hws/mlx5dr.h
index 2b02884dc3..c14fef7a6b 100644
--- a/drivers/net/mlx5/hws/mlx5dr.h
+++ b/drivers/net/mlx5/hws/mlx5dr.h
@@ -45,6 +45,7 @@  enum mlx5dr_action_type {
 	MLX5DR_ACTION_TYP_PUSH_VLAN,
 	MLX5DR_ACTION_TYP_ASO_METER,
 	MLX5DR_ACTION_TYP_ASO_CT,
+	MLX5DR_ACTION_TYP_DEST_ROOT_TABLE,
 	MLX5DR_ACTION_TYP_MAX,
 };
 
@@ -565,6 +566,24 @@  mlx5dr_action_create_pop_vlan(struct mlx5dr_context *ctx, uint32_t flags);
 struct mlx5dr_action *
 mlx5dr_action_create_push_vlan(struct mlx5dr_context *ctx, uint32_t flags);
 
+/* Create dest root table, this action will jump to root table according
+ * the given priority.
+ * @param[in] ctx
+ *	The context in which the new action will be created.
+ * @param[in] tbl
+ *	The root table to jump to.
+ * @param[in] priority
+ *	The priority of matcher in the root table to jump to.
+ * @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_dest_root_table(struct mlx5dr_context *ctx,
+				     struct mlx5dr_table *tbl,
+				     uint16_t priority,
+				     uint32_t flags);
+
 /* Destroy direct rule action.
  *
  * @param[in] action
diff --git a/drivers/net/mlx5/hws/mlx5dr_action.c b/drivers/net/mlx5/hws/mlx5dr_action.c
index 2db62635c1..9a408b0a1a 100644
--- a/drivers/net/mlx5/hws/mlx5dr_action.c
+++ b/drivers/net/mlx5/hws/mlx5dr_action.c
@@ -33,7 +33,8 @@  static const uint32_t action_order_arr[MLX5DR_TABLE_TYPE_MAX][MLX5DR_ACTION_TYP_
 		BIT(MLX5DR_ACTION_TYP_FT) |
 		BIT(MLX5DR_ACTION_TYP_MISS) |
 		BIT(MLX5DR_ACTION_TYP_TIR) |
-		BIT(MLX5DR_ACTION_TYP_DROP),
+		BIT(MLX5DR_ACTION_TYP_DROP) |
+		BIT(MLX5DR_ACTION_TYP_DEST_ROOT_TABLE),
 		BIT(MLX5DR_ACTION_TYP_LAST),
 	},
 	[MLX5DR_TABLE_TYPE_NIC_TX] = {
@@ -49,7 +50,8 @@  static const uint32_t action_order_arr[MLX5DR_TABLE_TYPE_MAX][MLX5DR_ACTION_TYP_
 		BIT(MLX5DR_ACTION_TYP_L2_TO_TNL_L3),
 		BIT(MLX5DR_ACTION_TYP_FT) |
 		BIT(MLX5DR_ACTION_TYP_MISS) |
-		BIT(MLX5DR_ACTION_TYP_DROP),
+		BIT(MLX5DR_ACTION_TYP_DROP) |
+		BIT(MLX5DR_ACTION_TYP_DEST_ROOT_TABLE),
 		BIT(MLX5DR_ACTION_TYP_LAST),
 	},
 	[MLX5DR_TABLE_TYPE_FDB] = {
@@ -68,7 +70,8 @@  static const uint32_t action_order_arr[MLX5DR_TABLE_TYPE_MAX][MLX5DR_ACTION_TYP_
 		BIT(MLX5DR_ACTION_TYP_FT) |
 		BIT(MLX5DR_ACTION_TYP_MISS) |
 		BIT(MLX5DR_ACTION_TYP_VPORT) |
-		BIT(MLX5DR_ACTION_TYP_DROP),
+		BIT(MLX5DR_ACTION_TYP_DROP) |
+		BIT(MLX5DR_ACTION_TYP_DEST_ROOT_TABLE),
 		BIT(MLX5DR_ACTION_TYP_LAST),
 	},
 };
@@ -521,6 +524,11 @@  static void mlx5dr_action_fill_stc_attr(struct mlx5dr_action *action,
 		attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
 		attr->dest_table_id = obj->id;
 		break;
+	case MLX5DR_ACTION_TYP_DEST_ROOT_TABLE:
+		attr->action_type = MLX5_IFC_STC_ACTION_TYPE_JUMP_TO_FT;
+		attr->action_offset = MLX5DR_ACTION_OFFSET_HIT;
+		attr->dest_table_id = action->root_tbl.sa->id;
+		break;
 	case MLX5DR_ACTION_TYP_TNL_L2_TO_L2:
 		attr->action_type = MLX5_IFC_STC_ACTION_TYPE_HEADER_REMOVE;
 		attr->action_offset = MLX5DR_ACTION_OFFSET_DW5;
@@ -1172,12 +1180,12 @@  mlx5dr_action_conv_reformat_to_verbs(uint32_t action_type,
 static int
 mlx5dr_action_conv_flags_to_ft_type(uint32_t flags, enum mlx5dv_flow_table_type *ft_type)
 {
-	if (flags & MLX5DR_ACTION_FLAG_ROOT_RX) {
+	if (flags & (MLX5DR_ACTION_FLAG_ROOT_RX | MLX5DR_ACTION_FLAG_HWS_RX)) {
 		*ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_RX;
-	} else if (flags & MLX5DR_ACTION_FLAG_ROOT_TX) {
+	} else if (flags & (MLX5DR_ACTION_FLAG_ROOT_TX | MLX5DR_ACTION_FLAG_HWS_TX)) {
 		*ft_type = MLX5DV_FLOW_TABLE_TYPE_NIC_TX;
 #ifdef HAVE_MLX5DV_FLOW_MATCHER_FT_TYPE
-	} else if (flags & MLX5DR_ACTION_FLAG_ROOT_FDB) {
+	} else if (flags & (MLX5DR_ACTION_FLAG_ROOT_FDB | MLX5DR_ACTION_FLAG_HWS_FDB)) {
 		*ft_type = MLX5DV_FLOW_TABLE_TYPE_FDB;
 #endif
 	} else {
@@ -1633,6 +1641,65 @@  mlx5dr_action_create_modify_header(struct mlx5dr_context *ctx,
 	return NULL;
 }
 
+struct mlx5dr_action *
+mlx5dr_action_create_dest_root_table(struct mlx5dr_context *ctx,
+				     struct mlx5dr_table *tbl,
+				     uint16_t priority,
+				     uint32_t flags)
+{
+	struct mlx5dv_steering_anchor_attr attr = {0};
+	struct mlx5dv_steering_anchor *sa;
+	struct mlx5dr_action *action;
+	int ret;
+
+	if (mlx5dr_action_is_root_flags(flags)) {
+		DR_LOG(ERR, "Action flags must be only non root (HWS)");
+		rte_errno = ENOTSUP;
+		return NULL;
+	}
+
+	if (!mlx5dr_table_is_root(tbl)) {
+		DR_LOG(ERR, "Non root table cannot be set as destination");
+		rte_errno = ENOTSUP;
+		return NULL;
+	}
+
+	if (mlx5dr_context_shared_gvmi_used(ctx)) {
+		DR_LOG(ERR, "Cannot use this action in shared GVMI context");
+		rte_errno = ENOTSUP;
+		return NULL;
+	}
+
+	if (mlx5dr_action_conv_flags_to_ft_type(flags, &attr.ft_type))
+		return NULL;
+
+	attr.priority = priority;
+
+	sa = mlx5_glue->create_steering_anchor(ctx->ibv_ctx, &attr);
+	if (!sa) {
+		DR_LOG(ERR, "Creation of steering anchor failed");
+		return NULL;
+	}
+
+	action = mlx5dr_action_create_generic(ctx, flags, MLX5DR_ACTION_TYP_DEST_ROOT_TABLE);
+	if (!action)
+		goto free_steering_anchor;
+
+	action->root_tbl.sa = sa;
+
+	ret = mlx5dr_action_create_stcs(action, NULL);
+	if (ret)
+		goto free_action;
+
+	return action;
+
+free_action:
+	simple_free(action);
+free_steering_anchor:
+	mlx5_glue->destroy_steering_anchor(sa);
+	return NULL;
+}
+
 static void mlx5dr_action_destroy_hws(struct mlx5dr_action *action)
 {
 	switch (action->type) {
@@ -1652,6 +1719,10 @@  static void mlx5dr_action_destroy_hws(struct mlx5dr_action *action)
 	case MLX5DR_ACTION_TYP_PUSH_VLAN:
 		mlx5dr_action_destroy_stcs(action);
 		break;
+	case MLX5DR_ACTION_TYP_DEST_ROOT_TABLE:
+		mlx5dr_action_destroy_stcs(action);
+		mlx5_glue->destroy_steering_anchor(action->root_tbl.sa);
+		break;
 	case MLX5DR_ACTION_TYP_POP_VLAN:
 		mlx5dr_action_destroy_stcs(action);
 		mlx5dr_action_put_shared_stc(action, MLX5DR_CONTEXT_SHARED_STC_POP);
@@ -2132,6 +2203,7 @@  int mlx5dr_action_template_process(struct mlx5dr_action_template *at)
 		case MLX5DR_ACTION_TYP_DROP:
 		case MLX5DR_ACTION_TYP_TIR:
 		case MLX5DR_ACTION_TYP_FT:
+		case MLX5DR_ACTION_TYP_DEST_ROOT_TABLE:
 		case MLX5DR_ACTION_TYP_VPORT:
 		case MLX5DR_ACTION_TYP_MISS:
 			/* Hit action */
diff --git a/drivers/net/mlx5/hws/mlx5dr_action.h b/drivers/net/mlx5/hws/mlx5dr_action.h
index 17619c0057..a85f3b0139 100644
--- a/drivers/net/mlx5/hws/mlx5dr_action.h
+++ b/drivers/net/mlx5/hws/mlx5dr_action.h
@@ -141,6 +141,9 @@  struct mlx5dr_action {
 				struct {
 					struct mlx5dr_devx_obj *devx_obj;
 				} alias;
+				struct {
+					struct mlx5dv_steering_anchor *sa;
+				} root_tbl;
 			};
 		};
 
diff --git a/drivers/net/mlx5/hws/mlx5dr_debug.c b/drivers/net/mlx5/hws/mlx5dr_debug.c
index 6b32ac4ee6..e29122aa98 100644
--- a/drivers/net/mlx5/hws/mlx5dr_debug.c
+++ b/drivers/net/mlx5/hws/mlx5dr_debug.c
@@ -22,6 +22,7 @@  const char *mlx5dr_debug_action_type_str[] = {
 	[MLX5DR_ACTION_TYP_PUSH_VLAN] = "PUSH_VLAN",
 	[MLX5DR_ACTION_TYP_ASO_METER] = "ASO_METER",
 	[MLX5DR_ACTION_TYP_ASO_CT] = "ASO_CT",
+	[MLX5DR_ACTION_TYP_DEST_ROOT_TABLE] = "DEST_ROOT_TABLE",
 };
 
 static_assert(ARRAY_SIZE(mlx5dr_debug_action_type_str) == MLX5DR_ACTION_TYP_MAX,