1Limit qp resources accepted for ibv_create_qp()
2    
3to the limits reported in ib_query_device().
4Make sure that the limits returned to the caller following
5qp creation also lie within the reported device limits.
6(OFED 1.3 libmlx4 commit b612592e2c43472895ccc495183aa63980d8e7a5)
7    
8Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il>
9
10Index: libmlx4/src/qp.c
11===================================================================
12--- libmlx4.orig/src/qp.c	2008-06-04 08:24:45.000000000 +0300
13+++ libmlx4/src/qp.c	2008-06-04 08:24:49.000000000 +0300
14@@ -619,6 +619,7 @@ void mlx4_set_sq_sizes(struct mlx4_qp *q
15 		       enum ibv_qp_type type)
16 {
17 	int wqe_size;
18+	struct mlx4_context *ctx = to_mctx(qp->ibv_qp.context);
19 
20 	wqe_size = (1 << qp->sq.wqe_shift) - sizeof (struct mlx4_wqe_ctrl_seg);
21 	switch (type) {
22@@ -636,8 +637,9 @@ void mlx4_set_sq_sizes(struct mlx4_qp *q
23 	}
24 
25 	qp->sq.max_gs	     = wqe_size / sizeof (struct mlx4_wqe_data_seg);
26-	cap->max_send_sge    = qp->sq.max_gs;
27-	qp->sq.max_post	     = qp->sq.wqe_cnt - qp->sq_spare_wqes;
28+	cap->max_send_sge    = min(ctx->max_sge, qp->sq.max_gs);
29+	qp->sq.max_post	     = min(ctx->max_qp_wr,
30+				   qp->sq.wqe_cnt - qp->sq_spare_wqes);
31 	cap->max_send_wr     = qp->sq.max_post;
32 
33 	/*
34Index: libmlx4/src/verbs.c
35===================================================================
36--- libmlx4.orig/src/verbs.c	2008-06-04 08:24:45.000000000 +0300
37+++ libmlx4/src/verbs.c	2008-06-04 08:24:49.000000000 +0300
38@@ -390,12 +390,14 @@ struct ibv_qp *mlx4_create_qp(struct ibv
39 	struct ibv_create_qp_resp resp;
40 	struct mlx4_qp		 *qp;
41 	int			  ret;
42+	struct mlx4_context	 *context = to_mctx(pd->context);
43+
44 
45 	/* Sanity check QP size before proceeding */
46-	if (attr->cap.max_send_wr     > 65536 ||
47-	    attr->cap.max_recv_wr     > 65536 ||
48-	    attr->cap.max_send_sge    > 64    ||
49-	    attr->cap.max_recv_sge    > 64    ||
50+	if (attr->cap.max_send_wr     > context->max_qp_wr ||
51+	    attr->cap.max_recv_wr     > context->max_qp_wr ||
52+	    attr->cap.max_send_sge    > context->max_sge   ||
53+	    attr->cap.max_recv_sge    > context->max_sge   ||
54 	    attr->cap.max_inline_data > 1024)
55 		return NULL;
56 
57@@ -461,8 +463,14 @@ struct ibv_qp *mlx4_create_qp(struct ibv
58 		goto err_destroy;
59 	pthread_mutex_unlock(&to_mctx(pd->context)->qp_table_mutex);
60 
61-	qp->rq.wqe_cnt = qp->rq.max_post = attr->cap.max_recv_wr;
62+	qp->rq.wqe_cnt = attr->cap.max_recv_wr;
63 	qp->rq.max_gs  = attr->cap.max_recv_sge;
64+
65+	/* adjust rq maxima to not exceed reported device maxima */
66+	attr->cap.max_recv_wr = min(context->max_qp_wr, attr->cap.max_recv_wr);
67+	attr->cap.max_recv_sge = min(context->max_sge, attr->cap.max_recv_sge);
68+
69+	qp->rq.max_post = attr->cap.max_recv_wr;
70 	mlx4_set_sq_sizes(qp, &attr->cap, attr->qp_type);
71 
72 	qp->doorbell_qpn    = htonl(qp->ibv_qp.qp_num << 8);
73