[PATCH rdma-core 2/2] mlx5: Enable allocating a DEVX context

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

 



Introduce mlx5dv_open_device() API to Enable allocating a DEVX context.

Signed-off-by: Yishai Hadas <yishaih@xxxxxxxxxxxx>
---
 debian/ibverbs-providers.symbols           |  1 +
 providers/mlx5/libmlx5.map                 |  1 +
 providers/mlx5/man/CMakeLists.txt          |  1 +
 providers/mlx5/man/mlx5dv_open_device.3.md | 57 ++++++++++++++++++++++++++++++
 providers/mlx5/mlx5.c                      | 21 ++++++++++-
 providers/mlx5/mlx5dv.h                    | 12 +++++++
 6 files changed, 92 insertions(+), 1 deletion(-)
 create mode 100644 providers/mlx5/man/mlx5dv_open_device.3.md

diff --git a/debian/ibverbs-providers.symbols b/debian/ibverbs-providers.symbols
index 98b4e16..23b0bbf 100644
--- a/debian/ibverbs-providers.symbols
+++ b/debian/ibverbs-providers.symbols
@@ -27,3 +27,4 @@ libmlx5.so.1 ibverbs-providers #MINVER#
  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
+ mlx5dv_open_device@MLX5_1.7 21
diff --git a/providers/mlx5/libmlx5.map b/providers/mlx5/libmlx5.map
index ca697b4..a178af6 100644
--- a/providers/mlx5/libmlx5.map
+++ b/providers/mlx5/libmlx5.map
@@ -45,4 +45,5 @@ MLX5_1.7 {
 	global:
 		mlx5dv_create_flow_action_modify_header;
 		mlx5dv_create_flow_action_packet_reformat;
+		mlx5dv_open_device;
 } MLX5_1.6;
diff --git a/providers/mlx5/man/CMakeLists.txt b/providers/mlx5/man/CMakeLists.txt
index e6f69b5..502bbd4 100644
--- a/providers/mlx5/man/CMakeLists.txt
+++ b/providers/mlx5/man/CMakeLists.txt
@@ -4,6 +4,7 @@ rdma_man_pages(
   mlx5dv_flow_action_esp.3.md
   mlx5dv_get_clock_info.3
   mlx5dv_init_obj.3
+  mlx5dv_open_device.3.md
   mlx5dv_query_device.3
   mlx5dv_ts_to_ns.3
   mlx5dv.7
diff --git a/providers/mlx5/man/mlx5dv_open_device.3.md b/providers/mlx5/man/mlx5dv_open_device.3.md
new file mode 100644
index 0000000..8a5876b
--- /dev/null
+++ b/providers/mlx5/man/mlx5dv_open_device.3.md
@@ -0,0 +1,57 @@
+---
+layout: page
+title: mlx5dv_open_device
+section: 3
+tagline: Verbs
+---
+
+# NAME
+
+mlx5dv_open_device - Open an RDMA device context for the mlx5 provider
+
+# SYNOPSIS
+
+```c
+#include <infiniband/mlx5dv.h>
+
+struct ibv_context *
+mlx5dv_open_device(struct ibv_device *device, struct mlx5dv_context_attr *attr);
+```
+
+# DESCRIPTION
+
+Open an RDMA device context with specific mlx5 provider attributes.
+
+# ARGUMENTS
+
+*device*
+:	RDMA device to open.
+
+## *attr* argument
+
+```c
+struct mlx5dv_context_attr {
+        uint32_t flags;
+        uint64_t comp_mask;
+};
+```
+
+*flags*
+:       A bitwise OR of the various values described below.
+
+        *MLX5DV_CONTEXT_FLAGS_DEVX*:
+        Allocate a DEVX context
+
+*comp_mask*
+:       Bitmask specifying what fields in the structure are valid
+
+# RETURN VALUE
+Returns a pointer to the allocated device context, or NULL if the request fails.
+
+# SEE ALSO
+
+*ibv_open_device(3)*
+
+# AUTHOR
+
+Yishai Hadas <yishaih@xxxxxxxxxxxx>
diff --git a/providers/mlx5/mlx5.c b/providers/mlx5/mlx5.c
index 766b61f..57e56c6 100644
--- a/providers/mlx5/mlx5.c
+++ b/providers/mlx5/mlx5.c
@@ -1000,6 +1000,12 @@ static void adjust_uar_info(struct mlx5_device *mdev,
 	context->num_uars_per_page = resp.num_uars_per_page;
 }
 
+struct ibv_context *
+mlx5dv_open_device(struct ibv_device *device, struct mlx5dv_context_attr *attr)
+{
+	return verbs_open_device(device, attr);
+}
+
 static struct verbs_context *mlx5_alloc_context(struct ibv_device *ibdev,
 						int cmd_fd,
 						void *vendor_attr)
@@ -1020,9 +1026,12 @@ static struct verbs_context *mlx5_alloc_context(struct ibv_device *ibdev,
 	int				k;
 	int				bfi;
 	int				num_sys_page_map;
+	struct mlx5dv_context_attr	*ctx_attr = vendor_attr;
 
-	if (vendor_attr)
+	if (ctx_attr && ctx_attr->comp_mask) {
+		errno = EINVAL;
 		return NULL;
+	}
 
 	context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx,
 					       RDMA_DRIVER_MLX5);
@@ -1063,6 +1072,16 @@ static struct verbs_context *mlx5_alloc_context(struct ibv_device *ibdev,
 	req.num_low_latency_bfregs = low_lat_uuars;
 	req.max_cqe_version = MLX5_CQE_VERSION_V1;
 	req.lib_caps |= MLX5_LIB_CAP_4K_UAR;
+	if (ctx_attr && ctx_attr->flags) {
+
+		if (!check_comp_mask(ctx_attr->flags,
+				     MLX5DV_CONTEXT_FLAGS_DEVX)) {
+			errno = EINVAL;
+			goto err_free;
+		}
+
+		req.flags = MLX5_IB_ALLOC_UCTX_DEVX;
+	}
 
 	if (mlx5_cmd_get_context(context, &req, sizeof(req), &resp,
 				 sizeof(resp)))
diff --git a/providers/mlx5/mlx5dv.h b/providers/mlx5/mlx5dv.h
index bb9aaaa..69af319 100644
--- a/providers/mlx5/mlx5dv.h
+++ b/providers/mlx5/mlx5dv.h
@@ -996,6 +996,18 @@ static inline uint64_t mlx5dv_ts_to_ns(struct mlx5dv_clock_info *clock_info,
 	return nsec;
 }
 
+enum mlx5dv_context_attr_flags {
+	MLX5DV_CONTEXT_FLAGS_DEVX = 1 << 0,
+};
+
+struct mlx5dv_context_attr {
+	uint32_t flags; /* Use enum mlx5dv_context_attr_flags */
+	uint64_t comp_mask;
+};
+
+struct ibv_context *
+mlx5dv_open_device(struct ibv_device *device, struct mlx5dv_context_attr *attr);
+
 #ifdef __cplusplus
 }
 #endif
-- 
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