[PATCH 5/9] mlx4: Move the context intialization out of mlx4_query_device_ex()

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

 



When the user calls mlx4_query_device_ex() it should not cause the context
values to be mutated, only the attribute shuld be returned.

Move this code to a dedicated function that is only called during context
setup.

Signed-off-by: Jason Gunthorpe <jgg@xxxxxxxxxx>
---
 providers/mlx4/mlx4.c  | 33 +-------------------------------
 providers/mlx4/mlx4.h  |  1 +
 providers/mlx4/verbs.c | 43 +++++++++++++++++++++++++++++++++++-------
 3 files changed, 38 insertions(+), 39 deletions(-)

diff --git a/providers/mlx4/mlx4.c b/providers/mlx4/mlx4.c
index c4a3c557fea426..619b841d788cb2 100644
--- a/providers/mlx4/mlx4.c
+++ b/providers/mlx4/mlx4.c
@@ -136,28 +136,6 @@ static const struct verbs_context_ops mlx4_ctx_ops = {
 	.free_context = mlx4_free_context,
 };
 
-static int mlx4_map_internal_clock(struct mlx4_device *mdev,
-				   struct ibv_context *ibv_ctx)
-{
-	struct mlx4_context *context = to_mctx(ibv_ctx);
-	void *hca_clock_page;
-
-	hca_clock_page = mmap(NULL, mdev->page_size,
-			      PROT_READ, MAP_SHARED, ibv_ctx->cmd_fd,
-			      mdev->page_size * 3);
-
-	if (hca_clock_page == MAP_FAILED) {
-		fprintf(stderr, PFX
-			"Warning: Timestamp available,\n"
-			"but failed to mmap() hca core clock page.\n");
-		return -1;
-	}
-
-	context->hca_core_clock = hca_clock_page +
-		(context->core_clock.offset & (mdev->page_size - 1));
-	return 0;
-}
-
 static struct verbs_context *mlx4_alloc_context(struct ibv_device *ibdev,
 						  int cmd_fd,
 						  void *private_data)
@@ -170,7 +148,6 @@ static struct verbs_context *mlx4_alloc_context(struct ibv_device *ibdev,
 	__u16				bf_reg_size;
 	struct mlx4_device              *dev = to_mdev(ibdev);
 	struct verbs_context		*verbs_ctx;
-	struct ibv_device_attr_ex	dev_attrs;
 
 	context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx,
 					       RDMA_DRIVER_MLX4);
@@ -242,15 +219,7 @@ static struct verbs_context *mlx4_alloc_context(struct ibv_device *ibdev,
 
 	verbs_set_ops(verbs_ctx, &mlx4_ctx_ops);
 
-	context->hca_core_clock = NULL;
-	memset(&dev_attrs, 0, sizeof(dev_attrs));
-	if (!mlx4_query_device_ex(&verbs_ctx->context, NULL, &dev_attrs,
-				  sizeof(struct ibv_device_attr_ex))) {
-		context->max_qp_wr = dev_attrs.orig_attr.max_qp_wr;
-		context->max_sge = dev_attrs.orig_attr.max_sge;
-		if (context->core_clock.offset_valid)
-			mlx4_map_internal_clock(dev, &verbs_ctx->context);
-	}
+	mlx4_query_device_ctx(dev, context);
 
 	return verbs_ctx;
 
diff --git a/providers/mlx4/mlx4.h b/providers/mlx4/mlx4.h
index 479c39d0a69fc4..3c0787144e7e51 100644
--- a/providers/mlx4/mlx4.h
+++ b/providers/mlx4/mlx4.h
@@ -304,6 +304,7 @@ __be32 *mlx4_alloc_db(struct mlx4_context *context, enum mlx4_db_type type);
 void mlx4_free_db(struct mlx4_context *context, enum mlx4_db_type type,
 		  __be32 *db);
 
+void mlx4_query_device_ctx(struct mlx4_device *mdev, struct mlx4_context *mctx);
 int mlx4_query_device(struct ibv_context *context,
 		       struct ibv_device_attr *attr);
 int mlx4_query_device_ex(struct ibv_context *context,
diff --git a/providers/mlx4/verbs.c b/providers/mlx4/verbs.c
index 512297f2eebac0..4fe5c1d87d6d91 100644
--- a/providers/mlx4/verbs.c
+++ b/providers/mlx4/verbs.c
@@ -38,6 +38,7 @@
 #include <string.h>
 #include <pthread.h>
 #include <errno.h>
+#include <sys/mman.h>
 
 #include <util/mmio.h>
 
@@ -70,7 +71,6 @@ int mlx4_query_device_ex(struct ibv_context *context,
 			 struct ibv_device_attr_ex *attr,
 			 size_t attr_size)
 {
-	struct mlx4_context *mctx = to_mctx(context);
 	struct mlx4_query_device_ex_resp resp = {};
 	struct mlx4_query_device_ex cmd = {};
 	uint64_t raw_fw_ver;
@@ -90,12 +90,6 @@ int mlx4_query_device_ex(struct ibv_context *context,
 	attr->tso_caps.max_tso = resp.tso_caps.max_tso;
 	attr->tso_caps.supported_qpts = resp.tso_caps.supported_qpts;
 
-	if (resp.comp_mask & MLX4_IB_QUERY_DEV_RESP_MASK_CORE_CLOCK_OFFSET) {
-		mctx->core_clock.offset = resp.hca_core_clock_offset;
-		mctx->core_clock.offset_valid = 1;
-	}
-	mctx->max_inl_recv_sz = resp.max_inl_recv_sz;
-
 	major     = (raw_fw_ver >> 32) & 0xffff;
 	minor     = (raw_fw_ver >> 16) & 0xffff;
 	sub_minor = raw_fw_ver & 0xffff;
@@ -106,6 +100,41 @@ int mlx4_query_device_ex(struct ibv_context *context,
 	return 0;
 }
 
+void mlx4_query_device_ctx(struct mlx4_device *mdev, struct mlx4_context *mctx)
+{
+	struct ibv_device_attr_ex device_attr;
+	struct mlx4_query_device_ex_resp resp;
+	size_t resp_size = sizeof(resp);
+
+	if (ibv_cmd_query_device_any(&mctx->ibv_ctx.context, NULL,
+				       &device_attr, sizeof(device_attr),
+				       &resp.ibv_resp, &resp_size))
+		return;
+
+	mctx->max_qp_wr = device_attr.orig_attr.max_qp_wr;
+	mctx->max_sge = device_attr.orig_attr.max_sge;
+	mctx->max_inl_recv_sz = resp.max_inl_recv_sz;
+
+	if (resp.comp_mask & MLX4_IB_QUERY_DEV_RESP_MASK_CORE_CLOCK_OFFSET) {
+		void *hca_clock_page;
+
+		mctx->core_clock.offset = resp.hca_core_clock_offset;
+		mctx->core_clock.offset_valid = 1;
+
+		hca_clock_page =
+			mmap(NULL, mdev->page_size, PROT_READ, MAP_SHARED,
+			     mctx->ibv_ctx.context.cmd_fd, mdev->page_size * 3);
+		if (hca_clock_page != MAP_FAILED)
+			mctx->hca_core_clock =
+				hca_clock_page + (mctx->core_clock.offset &
+						  (mdev->page_size - 1));
+		else
+			fprintf(stderr, PFX
+				"Warning: Timestamp available,\n"
+				"but failed to mmap() hca core clock page.\n");
+	}
+}
+
 static int mlx4_read_clock(struct ibv_context *context, uint64_t *cycles)
 {
 	uint32_t clockhi, clocklo, clockhi1;
-- 
2.29.2





[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