[openib-general] Re: [PATCH] mthca: when creating a cq, check that requested cqes does not exceed HCA max

Jack Morgenstein jackm at mellanox.co.il
Sun Oct 9 01:44:55 PDT 2005


Hi,
I'm proposing a better fix.  see below.

On Mon, Oct 03, 2005 at 06:13:51PM +0200, Roland Dreier wrote:
> Seems reasonable.  However, looking back at the chip documentation, it
> seems that the max CQEs should really be 0x1ffff rather than 0xffff as
> I had it.  Can you confirm?
> 
> Thanks,
>   Roland
--------------------------------------------------
Best to take the actual max cqes from QUERY_DEV_LIMS -- new patch below.
The "- 1" is there because the cq needs one spare cqe (circular list logic).

Jack


Signed-off-by: Jack Morgenstein <jackm at mellanox.co.il>

Index: linux-kernel/infiniband/hw/mthca/mthca_dev.h
===================================================================
--- linux-kernel/infiniband/hw/mthca/mthca_dev.h	(revision 3632)
+++ linux-kernel/infiniband/hw/mthca/mthca_dev.h	(working copy)
@@ -134,6 +134,7 @@
 	int      num_eecs;
 	int      reserved_eecs;
 	int      num_cqs;
+	int      max_cqes;
 	int      reserved_cqs;
 	int      num_eqs;
 	int      reserved_eqs;
Index: linux-kernel/infiniband/hw/mthca/mthca_main.c
===================================================================
--- linux-kernel/infiniband/hw/mthca/mthca_main.c	(revision 3632)
+++ linux-kernel/infiniband/hw/mthca/mthca_main.c	(working copy)
@@ -173,6 +173,7 @@
 	mdev->limits.reserved_pds       = dev_lim->reserved_pds;
 	mdev->limits.port_width_cap     = dev_lim->max_port_width;
 	mdev->limits.flags              = dev_lim->flags;
+	mdev->limits.max_cqes           = dev_lim->max_cq_sz - 1;
 
 	/* IB_DEVICE_RESIZE_MAX_WR not supported by driver.
 	   May be doable since hardware supports it for SRQ.
Index: linux-kernel/infiniband/hw/mthca/mthca_provider.c
===================================================================
--- linux-kernel/infiniband/hw/mthca/mthca_provider.c	(revision 3632)
+++ linux-kernel/infiniband/hw/mthca/mthca_provider.c	(working copy)
@@ -93,7 +93,7 @@
 	props->max_qp_wr           = 0xffff;
 	props->max_sge             = mdev->limits.max_sg;
 	props->max_cq              = mdev->limits.num_cqs - mdev->limits.reserved_cqs;
-	props->max_cqe             = 0xffff;
+	props->max_cqe             = mdev->limits.max_cqes;
 	props->max_mr              = mdev->limits.num_mpts - mdev->limits.reserved_mrws;
 	props->max_pd              = mdev->limits.num_pds - mdev->limits.reserved_pds;
 	props->max_qp_rd_atom      = 1 << mdev->qp_table.rdb_shift;
@@ -639,7 +639,11 @@
 	struct mthca_cq *cq;
 	int nent;
 	int err;
+	struct mthca_dev* mdev = to_mdev(ibdev);
 
+	if (mdev->limits.max_cqes < entries || entries < 0)
+		return ERR_PTR(-EINVAL);
+	
 	if (context) {
 		if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd))
 			return ERR_PTR(-EFAULT);



More information about the general mailing list