1219820SjeffLimit qp resources accepted for ibv_create_qp()
2219820Sjeff    
3219820Sjeffto the limits reported in ib_query_device().
4219820SjeffMake sure that the limits returned to the caller following
5219820Sjeffqp creation also lie within the reported device limits.
6219820Sjeff(OFED 1.3 libmlx4 commit b612592e2c43472895ccc495183aa63980d8e7a5)
7219820Sjeff    
8219820SjeffSigned-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il>
9219820Sjeff
10219820SjeffIndex: libmlx4/src/qp.c
11219820Sjeff===================================================================
12219820Sjeff--- libmlx4.orig/src/qp.c	2008-06-04 08:24:45.000000000 +0300
13219820Sjeff+++ libmlx4/src/qp.c	2008-06-04 08:24:49.000000000 +0300
14219820Sjeff@@ -619,6 +619,7 @@ void mlx4_set_sq_sizes(struct mlx4_qp *q
15219820Sjeff 		       enum ibv_qp_type type)
16219820Sjeff {
17219820Sjeff 	int wqe_size;
18219820Sjeff+	struct mlx4_context *ctx = to_mctx(qp->ibv_qp.context);
19219820Sjeff 
20219820Sjeff 	wqe_size = (1 << qp->sq.wqe_shift) - sizeof (struct mlx4_wqe_ctrl_seg);
21219820Sjeff 	switch (type) {
22219820Sjeff@@ -636,8 +637,9 @@ void mlx4_set_sq_sizes(struct mlx4_qp *q
23219820Sjeff 	}
24219820Sjeff 
25219820Sjeff 	qp->sq.max_gs	     = wqe_size / sizeof (struct mlx4_wqe_data_seg);
26219820Sjeff-	cap->max_send_sge    = qp->sq.max_gs;
27219820Sjeff-	qp->sq.max_post	     = qp->sq.wqe_cnt - qp->sq_spare_wqes;
28219820Sjeff+	cap->max_send_sge    = min(ctx->max_sge, qp->sq.max_gs);
29219820Sjeff+	qp->sq.max_post	     = min(ctx->max_qp_wr,
30219820Sjeff+				   qp->sq.wqe_cnt - qp->sq_spare_wqes);
31219820Sjeff 	cap->max_send_wr     = qp->sq.max_post;
32219820Sjeff 
33219820Sjeff 	/*
34219820SjeffIndex: libmlx4/src/verbs.c
35219820Sjeff===================================================================
36219820Sjeff--- libmlx4.orig/src/verbs.c	2008-06-04 08:24:45.000000000 +0300
37219820Sjeff+++ libmlx4/src/verbs.c	2008-06-04 08:24:49.000000000 +0300
38219820Sjeff@@ -390,12 +390,14 @@ struct ibv_qp *mlx4_create_qp(struct ibv
39219820Sjeff 	struct ibv_create_qp_resp resp;
40219820Sjeff 	struct mlx4_qp		 *qp;
41219820Sjeff 	int			  ret;
42219820Sjeff+	struct mlx4_context	 *context = to_mctx(pd->context);
43219820Sjeff+
44219820Sjeff 
45219820Sjeff 	/* Sanity check QP size before proceeding */
46219820Sjeff-	if (attr->cap.max_send_wr     > 65536 ||
47219820Sjeff-	    attr->cap.max_recv_wr     > 65536 ||
48219820Sjeff-	    attr->cap.max_send_sge    > 64    ||
49219820Sjeff-	    attr->cap.max_recv_sge    > 64    ||
50219820Sjeff+	if (attr->cap.max_send_wr     > context->max_qp_wr ||
51219820Sjeff+	    attr->cap.max_recv_wr     > context->max_qp_wr ||
52219820Sjeff+	    attr->cap.max_send_sge    > context->max_sge   ||
53219820Sjeff+	    attr->cap.max_recv_sge    > context->max_sge   ||
54219820Sjeff 	    attr->cap.max_inline_data > 1024)
55219820Sjeff 		return NULL;
56219820Sjeff 
57219820Sjeff@@ -461,8 +463,14 @@ struct ibv_qp *mlx4_create_qp(struct ibv
58219820Sjeff 		goto err_destroy;
59219820Sjeff 	pthread_mutex_unlock(&to_mctx(pd->context)->qp_table_mutex);
60219820Sjeff 
61219820Sjeff-	qp->rq.wqe_cnt = qp->rq.max_post = attr->cap.max_recv_wr;
62219820Sjeff+	qp->rq.wqe_cnt = attr->cap.max_recv_wr;
63219820Sjeff 	qp->rq.max_gs  = attr->cap.max_recv_sge;
64219820Sjeff+
65219820Sjeff+	/* adjust rq maxima to not exceed reported device maxima */
66219820Sjeff+	attr->cap.max_recv_wr = min(context->max_qp_wr, attr->cap.max_recv_wr);
67219820Sjeff+	attr->cap.max_recv_sge = min(context->max_sge, attr->cap.max_recv_sge);
68219820Sjeff+
69219820Sjeff+	qp->rq.max_post = attr->cap.max_recv_wr;
70219820Sjeff 	mlx4_set_sq_sizes(qp, &attr->cap, attr->qp_type);
71219820Sjeff 
72219820Sjeff 	qp->doorbell_qpn    = htonl(qp->ibv_qp.qp_num << 8);
73