[PATCH rdma-core 4/4] mlx5: Add packet reformat flow action

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Mark Bloch <markb@xxxxxxxxxxxx>

A new DV is used to expose the creation of a packet reformat context.
It can be used to do decap/encap of packets. It can be attached to steering
flow rules via ibv_create_flow().

Signed-off-by: Mark Bloch <markb@xxxxxxxxxxxx>
Signed-off-by: Yishai Hadas <yishaih@xxxxxxxxxxxx>
---
 debian/ibverbs-providers.symbols                   |  1 +
 providers/mlx5/libmlx5.map                         |  1 +
 providers/mlx5/man/CMakeLists.txt                  |  1 +
 .../man/mlx5dv_flow_action_packet_reformat.3.md    | 63 ++++++++++++++++++++++
 providers/mlx5/mlx5_api.h                          |  5 ++
 providers/mlx5/mlx5dv.h                            | 10 ++++
 providers/mlx5/verbs.c                             | 50 +++++++++++++++++
 7 files changed, 131 insertions(+)
 create mode 100644 providers/mlx5/man/mlx5dv_flow_action_packet_reformat.3.md

diff --git a/debian/ibverbs-providers.symbols b/debian/ibverbs-providers.symbols
index 839a744..98b4e16 100644
--- a/debian/ibverbs-providers.symbols
+++ b/debian/ibverbs-providers.symbols
@@ -26,3 +26,4 @@ libmlx5.so.1 ibverbs-providers #MINVER#
  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
+ mlx5dv_create_flow_action_packet_reformat@MLX5_1.7 21
diff --git a/providers/mlx5/libmlx5.map b/providers/mlx5/libmlx5.map
index 80d5654..ca697b4 100644
--- a/providers/mlx5/libmlx5.map
+++ b/providers/mlx5/libmlx5.map
@@ -44,4 +44,5 @@ MLX5_1.6 {
 MLX5_1.7 {
 	global:
 		mlx5dv_create_flow_action_modify_header;
+		mlx5dv_create_flow_action_packet_reformat;
 } MLX5_1.6;
diff --git a/providers/mlx5/man/CMakeLists.txt b/providers/mlx5/man/CMakeLists.txt
index cdc7115..420975c 100644
--- a/providers/mlx5/man/CMakeLists.txt
+++ b/providers/mlx5/man/CMakeLists.txt
@@ -1,5 +1,6 @@
 rdma_man_pages(
   mlx5dv_flow_action_esp.3.md
+  mlx5dv_flow_action_packet_reformat.3.md
   mlx5dv_get_clock_info.3
   mlx5dv_init_obj.3
   mlx5dv_query_device.3
diff --git a/providers/mlx5/man/mlx5dv_flow_action_packet_reformat.3.md b/providers/mlx5/man/mlx5dv_flow_action_packet_reformat.3.md
new file mode 100644
index 0000000..099fd89
--- /dev/null
+++ b/providers/mlx5/man/mlx5dv_flow_action_packet_reformat.3.md
@@ -0,0 +1,63 @@
+
+---
+layout: page
+title: mlx5dv_flow_action_packet_reformat
+section: 3
+tagline: Verbs
+---
+
+# NAME
+
+mlx5dv_flow_action_packet_reformat - Flow action reformat packet for mlx5 provider
+
+# SYNOPSIS
+
+```c
+#include <infiniband/mlx5dv.h>
+
+struct ibv_flow_action *
+mlx5dv_create_flow_action_packet_reformat(struct ibv_context *ctx,
+					  size_t data_sz,
+					  void *data,
+					  enum mlx5dv_flow_action_packet_reformat_type reformat_type,
+					  enum mlx5dv_flow_table_type ft_type)
+```
+
+# DESCRIPTION
+
+Create a packet reformat flow steering action.
+It allows to add/remove packet headers.
+
+# ARGUMENTS
+*ctx*
+:       RDMA device context to create the action on.
+
+*data_sz*
+:       The size of *data* buffer.
+
+*data*
+:       A buffer which contains headers in case the actions requires them.
+
+*reformat_type*
+:       The reformat type to be create. Use enum mlx5dv_flow_action_packet_reformat_type.
+	MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2: Decap a generic L2
+	tunneled packet upto inner L2.
+
+	MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL: Generic encap, *data*
+		should contain the encapsulating headers.
+
+	MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2: Will do decap where
+		the inner packet starts from L3. *data* should be MAC or MAC + vlan (14 or 18 bytes) to be
+		appended to the packet after the decap action.
+
+	MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL: Will do encap where is
+		L2 of the original packet will not be included. *data* should be the encapsulating header.
+
+*ft_type*
+:       It defines the flow table type to which the packet reformat action
+	will be attached.
+
+# SEE ALSO
+
+*ibv_create_flow(3)* *ibv_create_flow_action(3)*
+
diff --git a/providers/mlx5/mlx5_api.h b/providers/mlx5/mlx5_api.h
index 8373b12..bc5de06 100644
--- a/providers/mlx5/mlx5_api.h
+++ b/providers/mlx5/mlx5_api.h
@@ -40,5 +40,10 @@
 #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
+#define mlx5dv_flow_action_packet_reformat_type		mlx5_ib_uapi_flow_action_packet_reformat_type
+#define MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2  MLX5_IB_UAPI_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TUNNEL_TO_L2
+#define MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL MLX5_IB_UAPI_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L2_TUNNEL
+#define MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2 MLX5_IB_UAPI_FLOW_ACTION_PACKET_REFORMAT_TYPE_L3_TUNNEL_TO_L2
+#define MLX5DV_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL MLX5_IB_UAPI_FLOW_ACTION_PACKET_REFORMAT_TYPE_L2_TO_L3_TUNNEL
 
 #endif
diff --git a/providers/mlx5/mlx5dv.h b/providers/mlx5/mlx5dv.h
index bee29e0..bb9aaaa 100644
--- a/providers/mlx5/mlx5dv.h
+++ b/providers/mlx5/mlx5dv.h
@@ -265,6 +265,16 @@ mlx5dv_create_flow_action_modify_header(struct ibv_context *ctx,
 					enum mlx5dv_flow_table_type ft_type);
 
 /*
+ * mlx5dv_create_flow_action_packet_reformat - Create flow action which can
+ * encap/decap packets.
+ */
+struct ibv_flow_action *
+mlx5dv_create_flow_action_packet_reformat(struct ibv_context *ctx,
+					  size_t data_sz,
+					  void *data,
+					  enum mlx5dv_flow_action_packet_reformat_type reformat_type,
+					  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 1e61f44..de731ce 100644
--- a/providers/mlx5/verbs.c
+++ b/providers/mlx5/verbs.c
@@ -3355,6 +3355,56 @@ struct ibv_flow_action *mlx5dv_create_flow_action_modify_header(struct ibv_conte
 	return &action->action;
 }
 
+struct ibv_flow_action *
+mlx5dv_create_flow_action_packet_reformat(struct ibv_context *ctx,
+					  size_t data_sz,
+					  void *data,
+					  enum mlx5dv_flow_action_packet_reformat_type reformat_type,
+					  enum mlx5dv_flow_table_type ft_type)
+{
+	DECLARE_COMMAND_BUFFER(cmd, UVERBS_OBJECT_FLOW_ACTION,
+			       MLX5_IB_METHOD_FLOW_ACTION_CREATE_PACKET_REFORMAT, 4);
+	struct ib_uverbs_attr *handle = fill_attr_out_obj(cmd,
+							  MLX5_IB_ATTR_CREATE_PACKET_REFORMAT_HANDLE);
+	struct verbs_flow_action *action;
+	int ret;
+
+	if ((!data && data_sz) || (data && !data_sz)) {
+		errno = EINVAL;
+		return NULL;
+	}
+
+	if (data && data_sz)
+		fill_attr_in(cmd,
+			     MLX5_IB_ATTR_CREATE_PACKET_REFORMAT_DATA_BUF,
+			     data, data_sz);
+
+	fill_attr_const_in(cmd, MLX5_IB_ATTR_CREATE_PACKET_REFORMAT_TYPE,
+			   reformat_type);
+
+	fill_attr_const_in(cmd, MLX5_IB_ATTR_CREATE_PACKET_REFORMAT_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_PACKET_REFORMAT_HANDLE,
+				       handle);
+
+	return &action->action;
+}
+
 int mlx5_destroy_flow_action(struct ibv_flow_action *action)
 {
 	struct verbs_flow_action *vaction =
-- 
1.8.3.1




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux