1When creating a new user context, query device for
2    
3various limits, for use in sanity checks and
4other resource limitation needs.
5    
6Passing needed info back to userspace in this manner is
7preferable to breaking the ABI.
8(OFED 1.3 commit 43ca5e9225658b22ef8180bf0eff4faa7f5940cf)
9    
10Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il>
11
12Index: libmlx4/src/mlx4.c
13===================================================================
14--- libmlx4.orig/src/mlx4.c	2008-06-03 15:45:18.000000000 +0300
15+++ libmlx4/src/mlx4.c	2008-06-04 08:24:10.000000000 +0300
16@@ -104,6 +104,7 @@ static struct ibv_context *mlx4_alloc_co
17 	struct ibv_get_context		cmd;
18 	struct mlx4_alloc_ucontext_resp resp;
19 	int				i;
20+	struct ibv_device_attr		dev_attrs;
21 
22 	context = calloc(1, sizeof *context);
23 	if (!context)
24@@ -156,8 +157,20 @@ static struct ibv_context *mlx4_alloc_co
25 
26 	context->ibv_ctx.ops = mlx4_ctx_ops;
27 
28+	if (mlx4_query_device(&context->ibv_ctx, &dev_attrs))
29+		goto query_free;
30+
31+	context->max_qp_wr = dev_attrs.max_qp_wr;
32+	context->max_sge = dev_attrs.max_sge;
33+	context->max_cqe = dev_attrs.max_cqe;
34+
35 	return &context->ibv_ctx;
36 
37+query_free:
38+	munmap(context->uar, to_mdev(ibdev)->page_size);
39+	if (context->bf_page)
40+		munmap(context->bf_page, to_mdev(ibdev)->page_size);
41+
42 err_free:
43 	free(context);
44 	return NULL;
45Index: libmlx4/src/mlx4.h
46===================================================================
47--- libmlx4.orig/src/mlx4.h	2008-06-03 15:45:18.000000000 +0300
48+++ libmlx4/src/mlx4.h	2008-06-04 08:24:10.000000000 +0300
49@@ -83,6 +83,20 @@
50 
51 #define PFX		"mlx4: "
52 
53+#ifndef max
54+#define max(a,b) \
55+	({ typeof (a) _a = (a); \
56+	   typeof (b) _b = (b); \
57+	   _a > _b ? _a : _b; })
58+#endif
59+
60+#ifndef min
61+#define min(a,b) \
62+	({ typeof (a) _a = (a); \
63+	   typeof (b) _b = (b); \
64+	   _a < _b ? _a : _b; })
65+#endif
66+
67 enum {
68 	MLX4_CQ_ENTRY_SIZE		= 0x20
69 };
70@@ -156,6 +170,9 @@ struct mlx4_context {
71 	int				num_qps;
72 	int				qp_table_shift;
73 	int				qp_table_mask;
74+	int				max_qp_wr;
75+	int				max_sge;
76+	int				max_cqe;
77 
78 	struct mlx4_db_page	       *db_list[MLX4_NUM_DB_TYPE];
79 	pthread_mutex_t			db_list_mutex;
80