[ofa-general] [PATCH 2/2] IB/mlx4_ib: fix SRQ buffer allocation

Eli Cohen eli at mellanox.co.il
Wed Jun 6 05:40:21 PDT 2007


Fix receive buffer allocation for SRQ QPs.
Add checks to validate HW requirements when configuring
QPs.

Signed-off-by: Eli Cohen <eli at mellanox.co.il>

---

diff --git a/drivers/infiniband/hw/mlx4/qp.c b/drivers/infiniband/hw/mlx4/qp.c
index dc137de..0117cf9 100644
--- a/drivers/infiniband/hw/mlx4/qp.c
+++ b/drivers/infiniband/hw/mlx4/qp.c
@@ -188,14 +188,27 @@ static int send_wqe_overhead(enum ib_qp_type type)
 	}
 }
 
-static int set_rq_size(struct mlx4_ib_dev *dev, struct ib_qp_cap *cap,
-		       struct mlx4_ib_qp *qp)
+static int set_rq_size(struct mlx4_ib_dev *dev, struct ib_qp_init_attr *init_attr,
+		       struct mlx4_ib_qp *qp, int kernel)
 {
+	struct ib_qp_cap *cap = &init_attr->cap;
+
 	/* Sanity check RQ size before proceeding */
 	if (cap->max_recv_wr  > dev->dev->caps.max_wqes  ||
 	    cap->max_recv_sge > dev->dev->caps.max_rq_sg)
 		return -EINVAL;
 
+	if (init_attr->srq) {
+		if (cap->max_recv_wr)
+			return -EINVAL;
+	}
+	else if (!cap->max_recv_wr) {
+		if (kernel)
+			cap->max_recv_wr = 1;
+		else
+			return -EINVAL;
+	}
+
 	qp->rq.max = cap->max_recv_wr ? roundup_pow_of_two(cap->max_recv_wr) : 0;
 
 	qp->rq.wqe_shift = ilog2(roundup_pow_of_two(cap->max_recv_sge *
@@ -257,6 +270,10 @@ static int set_kernel_sq_size(struct mlx4_ib_dev *dev, struct ib_qp_cap *cap,
 static int set_user_sq_size(struct mlx4_ib_qp *qp,
 			    struct mlx4_ib_create_qp *ucmd)
 {
+	/* Sanity check for SQ size */
+	if (ucmd->log_sq_bb_count > 15 || ucmd->log_sq_stride > 11)
+		return -EINVAL;
+
 	qp->sq.max       = 1 << ucmd->log_sq_bb_count;
 	qp->sq.wqe_shift = ucmd->log_sq_stride;
 
@@ -285,7 +302,7 @@ static int create_qp_common(struct mlx4_ib_dev *dev, struct ib_pd *pd,
 	qp->sq.head	    = 0;
 	qp->sq.tail	    = 0;
 
-	err = set_rq_size(dev, &init_attr->cap, qp);
+	err = set_rq_size(dev, init_attr, qp, pd->uobject ? 0 : 1);
 	if (err)
 		goto err;
 
@@ -733,9 +750,10 @@ static int __mlx4_ib_modify_qp(struct ib_qp *ibqp,
 		context->mtu_msgmax = (attr->path_mtu << 5) | 31;
 	}
 
-	if (qp->rq.max)
+	if (qp->rq.max) {
 		context->rq_size_stride = ilog2(qp->rq.max) << 3;
-	context->rq_size_stride |= qp->rq.wqe_shift - 4;
+		context->rq_size_stride |= qp->rq.wqe_shift - 4;
+	}
 
 	if (qp->sq.max)
 		context->sq_size_stride = ilog2(qp->sq.max) << 3;




More information about the general mailing list