[ofa-general] [PATCH 1 of 5] libmlx4: get needed device params via query_device when creating a ucontext

Jack Morgenstein jackm at dev.mellanox.co.il
Wed Oct 24 09:51:02 PDT 2007


When creating a new user context, query device for
various limits, for use in sanity checks and
other resource limitation needs.
  
Passing needed info back to userspace in this manner is
preferable to breaking the ABI.
    
Signed-off-by: Jack Morgenstein <jackm at dev.mellanox.co.il>

---
Roland,
I use max_qp_wr and max_sge in the second patch in this series,
first to check that the qp capabilities do not exceed the qp limits
which are reported by ibv_query device; and then
to adjust the qp capabilities returned by the kernel, so that the
qp capabilities returned to the caller do not exceed the limits 
which are obtained via ibv_query_device.

I use max_cqe in the third patch as a create_cq sanity check on
the number of cqe's requested.  Performing the check in this way
avoids the need for an ABI increment.

- Jack

diff --git a/src/mlx4.c b/src/mlx4.c
index 95902cd..4a22e74 100644
--- a/src/mlx4.c
+++ b/src/mlx4.c
@@ -109,6 +109,7 @@ static struct ibv_context *mlx4_alloc_context(struct ibv_device *ibdev, int cmd_
 	struct ibv_get_context		cmd;
 	struct mlx4_alloc_ucontext_resp resp;
 	int				i;
+	struct ibv_device_attr		dev_attrs;
 
 	context = malloc(sizeof *context);
 	if (!context)
@@ -170,8 +171,20 @@ static struct ibv_context *mlx4_alloc_context(struct ibv_device *ibdev, int cmd_
 
 	context->ibv_ctx.ops = mlx4_ctx_ops;
 
+	if (mlx4_query_device(&context->ibv_ctx, &dev_attrs))
+		goto query_free;
+
+	context->max_qp_wr = dev_attrs.max_qp_wr;
+	context->max_sge = dev_attrs.max_sge;
+	context->max_cqe = dev_attrs.max_cqe;
+
 	return &context->ibv_ctx;
 
+query_free:
+	munmap(context->uar, to_mdev(ibdev)->page_size);
+	if (context->bf_page)
+		munmap(context->bf_page, to_mdev(ibdev)->page_size);
+
 err_free:
 	free(context);
 	return NULL;
diff --git a/src/mlx4.h b/src/mlx4.h
index deb0f55..09e2bdd 100644
--- a/src/mlx4.h
+++ b/src/mlx4.h
@@ -83,6 +83,20 @@
 
 #define PFX		"mlx4: "
 
+#ifndef max
+#define max(a,b) \
+	({ typeof (a) _a = (a); \
+	   typeof (b) _b = (b); \
+	   _a > _b ? _a : _b; })
+#endif
+
+#ifndef min
+#define min(a,b) \
+	({ typeof (a) _a = (a); \
+	   typeof (b) _b = (b); \
+	   _a < _b ? _a : _b; })
+#endif
+
 enum {
 	MLX4_CQ_ENTRY_SIZE		= 0x20
 };
@@ -166,6 +180,9 @@ struct mlx4_context {
 	int				num_qps;
 	int				qp_table_shift;
 	int				qp_table_mask;
+	int				max_qp_wr;
+	int				max_sge;
+	int				max_cqe;
 
 	struct {
 		struct mlx4_srq       **table;



More information about the general mailing list