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

Jack Morgenstein jackm at mellanox.co.il
Sun Oct 2 02:17:38 PDT 2005


Return an error if requested number of cq entries exceeds HCA max (IB Spec 11.2.6.1).

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           = 0xffff; /* driver override */
 
 	/* 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