diff mbox series

[rdma-core,3/4] mlx5: Add modify header flow action

Message ID 1536768249-29432-4-git-send-email-yishaih@mellanox.com (mailing list archive)
State Not Applicable
Headers show
Series mlx5: Flow actions to mutate packets | expand

Commit Message

Yishai Hadas Sept. 12, 2018, 4:04 p.m. UTC
From: Mark Bloch <markb@mellanox.com>

Expose a new flow action as DV, modify header. It allows to create a
flow action which mutates packet headers. It can be attached to steering
rules via ibv_create_flow().

Signed-off-by: Mark Bloch <markb@mellanox.com>
Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
---
 debian/ibverbs-providers.symbols |  2 ++
 providers/mlx5/CMakeLists.txt    |  2 +-
 providers/mlx5/libmlx5.map       |  5 +++++
 providers/mlx5/mlx5_api.h        |  3 +++
 providers/mlx5/mlx5dv.h          | 20 ++++++++++++++++++++
 providers/mlx5/verbs.c           | 38 ++++++++++++++++++++++++++++++++++++++
 6 files changed, 69 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/debian/ibverbs-providers.symbols b/debian/ibverbs-providers.symbols
index 11ea417..839a744 100644
--- a/debian/ibverbs-providers.symbols
+++ b/debian/ibverbs-providers.symbols
@@ -12,6 +12,7 @@  libmlx5.so.1 ibverbs-providers #MINVER#
  MLX5_1.4@MLX5_1.4 17
  MLX5_1.5@MLX5_1.5 18
  MLX5_1.6@MLX5_1.6 20
+ MLX5_1.7@MLX5_1.7 21
  mlx5dv_init_obj@MLX5_1.0 13
  mlx5dv_init_obj@MLX5_1.2 15
  mlx5dv_query_device@MLX5_1.0 13
@@ -24,3 +25,4 @@  libmlx5.so.1 ibverbs-providers #MINVER#
  mlx5dv_create_flow_matcher@MLX5_1.6 20
  mlx5dv_destroy_flow_matcher@MLX5_1.6 20
  mlx5dv_create_flow@MLX5_1.6 20
+ mlx5dv_create_flow_action_modify_header@MLX5_1.7 21
diff --git a/providers/mlx5/CMakeLists.txt b/providers/mlx5/CMakeLists.txt
index 4a0f88b..1d0961c 100644
--- a/providers/mlx5/CMakeLists.txt
+++ b/providers/mlx5/CMakeLists.txt
@@ -11,7 +11,7 @@  if (MLX5_MW_DEBUG)
 endif()
 
 rdma_shared_provider(mlx5 libmlx5.map
-  1 1.6.${PACKAGE_VERSION}
+  1 1.7.${PACKAGE_VERSION}
   buf.c
   cq.c
   dbrec.c
diff --git a/providers/mlx5/libmlx5.map b/providers/mlx5/libmlx5.map
index 7501fa7..80d5654 100644
--- a/providers/mlx5/libmlx5.map
+++ b/providers/mlx5/libmlx5.map
@@ -40,3 +40,8 @@  MLX5_1.6 {
 		mlx5dv_destroy_flow_matcher;
 		mlx5dv_create_flow;
 } MLX5_1.5;
+
+MLX5_1.7 {
+	global:
+		mlx5dv_create_flow_action_modify_header;
+} MLX5_1.6;
diff --git a/providers/mlx5/mlx5_api.h b/providers/mlx5/mlx5_api.h
index b87f897..8373b12 100644
--- a/providers/mlx5/mlx5_api.h
+++ b/providers/mlx5/mlx5_api.h
@@ -37,5 +37,8 @@ 
 
 #define mlx5dv_flow_action_flags			mlx5_ib_uapi_flow_action_flags
 #define MLX5DV_FLOW_ACTION_FLAGS_REQUIRE_METADATA	MLX5_IB_UAPI_FLOW_ACTION_FLAGS_REQUIRE_METADATA
+#define mlx5dv_flow_table_type				mlx5_ib_uapi_flow_table_type
+#define MLX5DV_FLOW_TABLE_TYPE_NIC_RX			MLX5_IB_UAPI_FLOW_TABLE_TYPE_NIC_RX
+#define MLX5DV_FLOW_TABLE_TYPE_NIC_TX			MLX5_IB_UAPI_FLOW_TABLE_TYPE_NIC_TX
 
 #endif
diff --git a/providers/mlx5/mlx5dv.h b/providers/mlx5/mlx5dv.h
index b592029..bee29e0 100644
--- a/providers/mlx5/mlx5dv.h
+++ b/providers/mlx5/mlx5dv.h
@@ -245,6 +245,26 @@  struct ibv_flow_action *mlx5dv_create_flow_action_esp(struct ibv_context *ctx,
 						      struct mlx5dv_flow_action_esp *mlx5_attr);
 
 /*
+ * mlx5dv_create_flow_action_modify_header - Create a flow action which mutates
+ * a packet. The flow action can be attached to steering rules via
+ * ibv_create_flow().
+ *
+ * @ctx: RDMA device context to create the action on.
+ * @actions_sz: The size of *actions* buffer in bytes.
+ * @actions: A buffer which contains modify actions provided in device spec
+ *	     format.
+ * @ft_type: Defines the flow table type to which the modify
+ *	     header action will be attached.
+ *
+ * Return a valid ibv_flow_action if successful, NULL otherwise.
+ */
+struct ibv_flow_action *
+mlx5dv_create_flow_action_modify_header(struct ibv_context *ctx,
+					size_t actions_sz,
+					uint64_t actions[],
+					enum mlx5dv_flow_table_type ft_type);
+
+/*
  * Most device capabilities are exported by ibv_query_device(...),
  * but there is HW device-specific information which is important
  * for data-path, but isn't provided.
diff --git a/providers/mlx5/verbs.c b/providers/mlx5/verbs.c
index ff40029..1e61f44 100644
--- a/providers/mlx5/verbs.c
+++ b/providers/mlx5/verbs.c
@@ -3317,6 +3317,44 @@  int mlx5_modify_flow_action_esp(struct ibv_flow_action *action,
 	return ibv_cmd_modify_flow_action_esp(vaction, attr, NULL);
 }
 
+struct ibv_flow_action *mlx5dv_create_flow_action_modify_header(struct ibv_context *ctx,
+								size_t actions_sz,
+								uint64_t actions[],
+								enum mlx5dv_flow_table_type ft_type)
+{
+	DECLARE_COMMAND_BUFFER(cmd, UVERBS_OBJECT_FLOW_ACTION,
+			       MLX5_IB_METHOD_FLOW_ACTION_CREATE_MODIFY_HEADER,
+			       3);
+	struct ib_uverbs_attr *handle = fill_attr_out_obj(cmd,
+							  MLX5_IB_ATTR_CREATE_MODIFY_HEADER_HANDLE);
+	struct verbs_flow_action *action;
+	int ret;
+
+	fill_attr_in(cmd, MLX5_IB_ATTR_CREATE_MODIFY_HEADER_ACTIONS_PRM,
+		     actions, actions_sz);
+	fill_attr_const_in(cmd, MLX5_IB_ATTR_CREATE_MODIFY_HEADER_FT_TYPE,
+			   ft_type);
+
+	action = calloc(1, sizeof(*action));
+	if (!action) {
+		errno = ENOMEM;
+		return NULL;
+	}
+
+	ret = execute_ioctl(ctx, cmd);
+	if (ret) {
+		free(action);
+		return NULL;
+	}
+
+	action->action.context = ctx;
+	action->type = IBV_FLOW_ACTION_UNSPECIFIED;
+	action->handle = read_attr_obj(MLX5_IB_ATTR_CREATE_MODIFY_HEADER_HANDLE,
+				       handle);
+
+	return &action->action;
+}
+
 int mlx5_destroy_flow_action(struct ibv_flow_action *action)
 {
 	struct verbs_flow_action *vaction =