[openib-general] [PATCH 2/5] [RFC] mthca kernel changes for resize CQ

Roland Dreier rolandd at cisco.com
Thu Jan 26 11:23:32 PST 2006


mthca kernel changes to handle resizing userspace CQs.

---

--- infiniband/hw/mthca/mthca_user.h	(revision 5179)
+++ infiniband/hw/mthca/mthca_user.h	(working copy)
@@ -75,6 +75,11 @@ struct mthca_create_cq_resp {
 	__u32 reserved;
 };
 
+struct mthca_resize_cq {
+	__u32 lkey;
+	__u32 reserved;
+};
+
 struct mthca_create_srq {
 	__u32 lkey;
 	__u32 db_index;
--- infiniband/hw/mthca/mthca_provider.c	(revision 5179)
+++ infiniband/hw/mthca/mthca_provider.c	(working copy)
@@ -707,6 +707,35 @@ err_unmap_set:
 	return ERR_PTR(err);
 }
 
+static int mthca_resize_cq(struct ib_cq *cq, int entries, struct ib_udata *udata)
+{
+	struct mthca_resize_cq ucmd;
+	u8 status;
+	int ret;
+
+	if (!udata)
+		return -ENOSYS;
+
+	if (entries < 1 || entries > to_mdev(cq->device)->limits.max_cqes)
+		return -EINVAL;
+
+	if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd))
+		return -EFAULT;
+
+	entries = roundup_pow_of_two(entries + 1);
+
+	ret = mthca_RESIZE_CQ(to_mdev(cq->device), to_mcq(cq)->cqn,
+			      ucmd.lkey, long_log2(entries), &status);
+	if (ret)
+		return ret;
+	if (status)
+		return -EINVAL;
+
+	cq->cqe = entries - 1;
+
+	return 0;
+}
+
 static int mthca_destroy_cq(struct ib_cq *cq)
 {
 	if (cq->uobject) {
@@ -1113,6 +1142,7 @@ int mthca_register_device(struct mthca_d
 		(1ull << IB_USER_VERBS_CMD_DEREG_MR)		|
 		(1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL)	|
 		(1ull << IB_USER_VERBS_CMD_CREATE_CQ)		|
+		(1ull << IB_USER_VERBS_CMD_RESIZE_CQ)		|
 		(1ull << IB_USER_VERBS_CMD_DESTROY_CQ)		|
 		(1ull << IB_USER_VERBS_CMD_CREATE_QP)		|
 		(1ull << IB_USER_VERBS_CMD_MODIFY_QP)		|
@@ -1154,6 +1184,7 @@ int mthca_register_device(struct mthca_d
 	dev->ib_dev.modify_qp            = mthca_modify_qp;
 	dev->ib_dev.destroy_qp           = mthca_destroy_qp;
 	dev->ib_dev.create_cq            = mthca_create_cq;
+	dev->ib_dev.resize_cq            = mthca_resize_cq;
 	dev->ib_dev.destroy_cq           = mthca_destroy_cq;
 	dev->ib_dev.poll_cq              = mthca_poll_cq;
 	dev->ib_dev.get_dma_mr           = mthca_get_dma_mr;
--- infiniband/hw/mthca/mthca_cmd.c	(revision 5179)
+++ infiniband/hw/mthca/mthca_cmd.c	(working copy)
@@ -1517,6 +1517,37 @@ int mthca_HW2SW_CQ(struct mthca_dev *dev
 			     CMD_TIME_CLASS_A, status);
 }
 
+int mthca_RESIZE_CQ(struct mthca_dev *dev, int cq_num, u32 lkey, u8 log_size,
+		    u8 *status)
+{
+	struct mthca_mailbox *mailbox;
+	__be32 *inbox;
+	int err;
+
+#define RESIZE_CQ_IN_SIZE		0x40
+#define RESIZE_CQ_LOG_SIZE_OFFSET	0x0c
+#define RESIZE_CQ_LKEY_OFFSET		0x1c
+
+	mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
+	if (IS_ERR(mailbox))
+		return PTR_ERR(mailbox);
+	inbox = mailbox->buf;
+
+	memset(inbox, 0, RESIZE_CQ_IN_SIZE);
+	/*
+	 * Leave start address fields zeroed out -- mthca assumes that
+	 * MRs for CQs always start at virtual address 0.
+	 */
+	MTHCA_PUT(inbox, log_size, RESIZE_CQ_LOG_SIZE_OFFSET);
+	MTHCA_PUT(inbox, lkey,     RESIZE_CQ_LKEY_OFFSET);
+
+	err = mthca_cmd(dev, mailbox->dma, cq_num, 1, CMD_RESIZE_CQ,
+			CMD_TIME_CLASS_B, status);
+
+	mthca_free_mailbox(dev, mailbox);
+	return err;
+}
+
 int mthca_SW2HW_SRQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
 		    int srq_num, u8 *status)
 {
--- infiniband/hw/mthca/mthca_cmd.h	(revision 5179)
+++ infiniband/hw/mthca/mthca_cmd.h	(working copy)
@@ -298,6 +298,8 @@ int mthca_SW2HW_CQ(struct mthca_dev *dev
 		   int cq_num, u8 *status);
 int mthca_HW2SW_CQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
 		   int cq_num, u8 *status);
+int mthca_RESIZE_CQ(struct mthca_dev *dev, int cq_num, u32 lkey, u8 log_size,
+		    u8 *status);
 int mthca_SW2HW_SRQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
 		    int srq_num, u8 *status);
 int mthca_HW2SW_SRQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,



More information about the general mailing list