diff mbox series

[rdma-next,v2,5/5] RDMA/mana_ib: implement uapi for creation of rnic cq

Message ID 1714137160-5222-6-git-send-email-kotaranov@linux.microsoft.com (mailing list archive)
State Accepted
Headers show
Series RDMA/mana_ib: Implement RNIC CQs | expand

Commit Message

Konstantin Taranov April 26, 2024, 1:12 p.m. UTC
From: Konstantin Taranov <kotaranov@microsoft.com>

Enable users to create RNIC CQs using a corresponding flag.
With the previous request size, an ethernet CQ is created.
As a response, return ID of the created CQ.

Signed-off-by: Konstantin Taranov <kotaranov@microsoft.com>
---
 drivers/infiniband/hw/mana/cq.c | 55 ++++++++++++++++++++++++++++++---
 include/uapi/rdma/mana-abi.h    | 12 +++++++
 2 files changed, 63 insertions(+), 4 deletions(-)

Comments

Long Li April 29, 2024, 6:08 p.m. UTC | #1
> Subject: [PATCH rdma-next v2 5/5] RDMA/mana_ib: implement uapi for creation
> of rnic cq
> 
> From: Konstantin Taranov <kotaranov@microsoft.com>
> 
> Enable users to create RNIC CQs using a corresponding flag.
> With the previous request size, an ethernet CQ is created.
> As a response, return ID of the created CQ.
> 
> Signed-off-by: Konstantin Taranov <kotaranov@microsoft.com>
> ---
>  drivers/infiniband/hw/mana/cq.c | 55 ++++++++++++++++++++++++++++++---
>  include/uapi/rdma/mana-abi.h    | 12 +++++++
>  2 files changed, 63 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/mana/cq.c b/drivers/infiniband/hw/mana/cq.c
> index 688ffe6..c6a3fd5 100644
> --- a/drivers/infiniband/hw/mana/cq.c
> +++ b/drivers/infiniband/hw/mana/cq.c
> @@ -9,17 +9,22 @@ int mana_ib_create_cq(struct ib_cq *ibcq, const struct
> ib_cq_init_attr *attr,
>  		      struct ib_udata *udata)
>  {
>  	struct mana_ib_cq *cq = container_of(ibcq, struct mana_ib_cq, ibcq);
> +	struct mana_ib_create_cq_resp resp = {};
> +	struct mana_ib_ucontext *mana_ucontext;
>  	struct ib_device *ibdev = ibcq->device;
>  	struct mana_ib_create_cq ucmd = {};
>  	struct mana_ib_dev *mdev;
> +	bool is_rnic_cq;
> +	u32 doorbell;
>  	int err;
> 
>  	mdev = container_of(ibdev, struct mana_ib_dev, ib_dev);
> 
> -	if (udata->inlen < sizeof(ucmd))
> -		return -EINVAL;
> -
>  	cq->comp_vector = attr->comp_vector % ibdev->num_comp_vectors;
> +	cq->cq_handle = INVALID_MANA_HANDLE;
> +
> +	if (udata->inlen < offsetof(struct mana_ib_create_cq, flags))
> +		return -EINVAL;
> 
>  	err = ib_copy_from_udata(&ucmd, udata, min(sizeof(ucmd), udata-
> >inlen));
>  	if (err) {
> @@ -28,7 +33,9 @@ int mana_ib_create_cq(struct ib_cq *ibcq, const struct
> ib_cq_init_attr *attr,
>  		return err;
>  	}
> 
> -	if (attr->cqe > mdev->adapter_caps.max_qp_wr) {
> +	is_rnic_cq = !!(ucmd.flags & MANA_IB_CREATE_RNIC_CQ);
> +
> +	if (!is_rnic_cq && attr->cqe > mdev->adapter_caps.max_qp_wr) {
>  		ibdev_dbg(ibdev, "CQE %d exceeding limit\n", attr->cqe);
>  		return -EINVAL;
>  	}
> @@ -40,7 +47,41 @@ int mana_ib_create_cq(struct ib_cq *ibcq, const struct
> ib_cq_init_attr *attr,
>  		return err;
>  	}
> 
> +	mana_ucontext = rdma_udata_to_drv_context(udata, struct
> mana_ib_ucontext,
> +						  ibucontext);
> +	doorbell = mana_ucontext->doorbell;
> +
> +	if (is_rnic_cq) {
> +		err = mana_ib_gd_create_cq(mdev, cq, doorbell);
> +		if (err) {
> +			ibdev_dbg(ibdev, "Failed to create RNIC cq, %d\n", err);
> +			goto err_destroy_queue;
> +		}
> +
> +		err = mana_ib_install_cq_cb(mdev, cq);
> +		if (err) {
> +			ibdev_dbg(ibdev, "Failed to install cq callback, %d\n",
> err);
> +			goto err_destroy_rnic_cq;
> +		}
> +	}
> +
> +	resp.cqid = cq->queue.id;
> +	err = ib_copy_to_udata(udata, &resp, min(sizeof(resp), udata->outlen));
> +	if (err) {
> +		ibdev_dbg(&mdev->ib_dev, "Failed to copy to udata, %d\n", err);
> +		goto err_remove_cq_cb;
> +	}
> +
>  	return 0;
> +
> +err_remove_cq_cb:
> +	mana_ib_remove_cq_cb(mdev, cq);
> +err_destroy_rnic_cq:
> +	mana_ib_gd_destroy_cq(mdev, cq);
> +err_destroy_queue:
> +	mana_ib_destroy_queue(mdev, &cq->queue);
> +
> +	return err;
>  }
> 
>  int mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata) @@ -52,6
> +93,12 @@ int mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata)
>  	mdev = container_of(ibdev, struct mana_ib_dev, ib_dev);
> 
>  	mana_ib_remove_cq_cb(mdev, cq);
> +
> +	/* Ignore return code as there is not much we can do about it.
> +	 * The error message is printed inside.
> +	 */
> +	mana_ib_gd_destroy_cq(mdev, cq);
> +
>  	mana_ib_destroy_queue(mdev, &cq->queue);
> 
>  	return 0;
> diff --git a/include/uapi/rdma/mana-abi.h b/include/uapi/rdma/mana-abi.h
> index 5fcb31b..2c41cc3 100644
> --- a/include/uapi/rdma/mana-abi.h
> +++ b/include/uapi/rdma/mana-abi.h
> @@ -16,8 +16,20 @@
> 
>  #define MANA_IB_UVERBS_ABI_VERSION 1
> 
> +enum mana_ib_create_cq_flags {
> +	MANA_IB_CREATE_RNIC_CQ	= 1 << 0,
> +};
> +
>  struct mana_ib_create_cq {
>  	__aligned_u64 buf_addr;
> +	__u16	flags;
> +	__u16	reserved0;
> +	__u32	reserved1;
> +};
> +
> +struct mana_ib_create_cq_resp {
> +	__u32 cqid;
> +	__u32 reserved;
>  };
> 
>  struct mana_ib_create_qp {
> --
> 2.43.0

For this review, it will be helpful if you can also post a link to the rdma-core changes.

Long
Konstantin Taranov May 1, 2024, 2:01 p.m. UTC | #2
> 
> For this review, it will be helpful if you can also post a link to the rdma-core
> changes.
> 
> Long

Here is the PR to rdma-core with the changes: https://github.com/linux-rdma/rdma-core/pull/1455
The code was tested in 4 variations (old + new kernels against old + new rdma-cores) to confirm compatibility.

Konstantin
Long Li May 2, 2024, 5:04 p.m. UTC | #3
> Subject: [PATCH rdma-next v2 5/5] RDMA/mana_ib: implement uapi for creation
> of rnic cq
> 
> From: Konstantin Taranov <kotaranov@microsoft.com>
> 
> Enable users to create RNIC CQs using a corresponding flag.
> With the previous request size, an ethernet CQ is created.
> As a response, return ID of the created CQ.
> 
> Signed-off-by: Konstantin Taranov <kotaranov@microsoft.com>

Reviewed-by: Long Li <longli@microsoft.com>

> ---
>  drivers/infiniband/hw/mana/cq.c | 55 ++++++++++++++++++++++++++++++---
>  include/uapi/rdma/mana-abi.h    | 12 +++++++
>  2 files changed, 63 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/mana/cq.c b/drivers/infiniband/hw/mana/cq.c
> index 688ffe6..c6a3fd5 100644
> --- a/drivers/infiniband/hw/mana/cq.c
> +++ b/drivers/infiniband/hw/mana/cq.c
> @@ -9,17 +9,22 @@ int mana_ib_create_cq(struct ib_cq *ibcq, const struct
> ib_cq_init_attr *attr,
>  		      struct ib_udata *udata)
>  {
>  	struct mana_ib_cq *cq = container_of(ibcq, struct mana_ib_cq, ibcq);
> +	struct mana_ib_create_cq_resp resp = {};
> +	struct mana_ib_ucontext *mana_ucontext;
>  	struct ib_device *ibdev = ibcq->device;
>  	struct mana_ib_create_cq ucmd = {};
>  	struct mana_ib_dev *mdev;
> +	bool is_rnic_cq;
> +	u32 doorbell;
>  	int err;
> 
>  	mdev = container_of(ibdev, struct mana_ib_dev, ib_dev);
> 
> -	if (udata->inlen < sizeof(ucmd))
> -		return -EINVAL;
> -
>  	cq->comp_vector = attr->comp_vector % ibdev->num_comp_vectors;
> +	cq->cq_handle = INVALID_MANA_HANDLE;
> +
> +	if (udata->inlen < offsetof(struct mana_ib_create_cq, flags))
> +		return -EINVAL;
> 
>  	err = ib_copy_from_udata(&ucmd, udata, min(sizeof(ucmd), udata-
> >inlen));
>  	if (err) {
> @@ -28,7 +33,9 @@ int mana_ib_create_cq(struct ib_cq *ibcq, const struct
> ib_cq_init_attr *attr,
>  		return err;
>  	}
> 
> -	if (attr->cqe > mdev->adapter_caps.max_qp_wr) {
> +	is_rnic_cq = !!(ucmd.flags & MANA_IB_CREATE_RNIC_CQ);
> +
> +	if (!is_rnic_cq && attr->cqe > mdev->adapter_caps.max_qp_wr) {
>  		ibdev_dbg(ibdev, "CQE %d exceeding limit\n", attr->cqe);
>  		return -EINVAL;
>  	}
> @@ -40,7 +47,41 @@ int mana_ib_create_cq(struct ib_cq *ibcq, const struct
> ib_cq_init_attr *attr,
>  		return err;
>  	}
> 
> +	mana_ucontext = rdma_udata_to_drv_context(udata, struct
> mana_ib_ucontext,
> +						  ibucontext);
> +	doorbell = mana_ucontext->doorbell;
> +
> +	if (is_rnic_cq) {
> +		err = mana_ib_gd_create_cq(mdev, cq, doorbell);
> +		if (err) {
> +			ibdev_dbg(ibdev, "Failed to create RNIC cq, %d\n", err);
> +			goto err_destroy_queue;
> +		}
> +
> +		err = mana_ib_install_cq_cb(mdev, cq);
> +		if (err) {
> +			ibdev_dbg(ibdev, "Failed to install cq callback, %d\n",
> err);
> +			goto err_destroy_rnic_cq;
> +		}
> +	}
> +
> +	resp.cqid = cq->queue.id;
> +	err = ib_copy_to_udata(udata, &resp, min(sizeof(resp), udata->outlen));
> +	if (err) {
> +		ibdev_dbg(&mdev->ib_dev, "Failed to copy to udata, %d\n", err);
> +		goto err_remove_cq_cb;
> +	}
> +
>  	return 0;
> +
> +err_remove_cq_cb:
> +	mana_ib_remove_cq_cb(mdev, cq);
> +err_destroy_rnic_cq:
> +	mana_ib_gd_destroy_cq(mdev, cq);
> +err_destroy_queue:
> +	mana_ib_destroy_queue(mdev, &cq->queue);
> +
> +	return err;
>  }
> 
>  int mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata) @@ -52,6
> +93,12 @@ int mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata)
>  	mdev = container_of(ibdev, struct mana_ib_dev, ib_dev);
> 
>  	mana_ib_remove_cq_cb(mdev, cq);
> +
> +	/* Ignore return code as there is not much we can do about it.
> +	 * The error message is printed inside.
> +	 */
> +	mana_ib_gd_destroy_cq(mdev, cq);
> +
>  	mana_ib_destroy_queue(mdev, &cq->queue);
> 
>  	return 0;
> diff --git a/include/uapi/rdma/mana-abi.h b/include/uapi/rdma/mana-abi.h
> index 5fcb31b..2c41cc3 100644
> --- a/include/uapi/rdma/mana-abi.h
> +++ b/include/uapi/rdma/mana-abi.h
> @@ -16,8 +16,20 @@
> 
>  #define MANA_IB_UVERBS_ABI_VERSION 1
> 
> +enum mana_ib_create_cq_flags {
> +	MANA_IB_CREATE_RNIC_CQ	= 1 << 0,
> +};
> +
>  struct mana_ib_create_cq {
>  	__aligned_u64 buf_addr;
> +	__u16	flags;
> +	__u16	reserved0;
> +	__u32	reserved1;
> +};
> +
> +struct mana_ib_create_cq_resp {
> +	__u32 cqid;
> +	__u32 reserved;
>  };
> 
>  struct mana_ib_create_qp {
> --
> 2.43.0
Long Li May 2, 2024, 5:05 p.m. UTC | #4
> Here is the PR to rdma-core with the changes:
> https://github.co/
> m%2Flinux-rdma%2Frdma-
> core%2Fpull%2F1455&data=05%7C02%7Clongli%40microsoft.com%7C15661647
> 58b54b0d382508dc69e72a37%7C72f988bf86f141af91ab2d7cd011db47%7C1%7
> C0%7C638501688834172236%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLj
> AwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C
> &sdata=lZPsMJvU%2BeoVBajN5HZBNZaADKnwOfROv5OqXL52%2FF4%3D&reser
> ved=0
> The code was tested in 4 variations (old + new kernels against old + new rdma-
> cores) to confirm compatibility.
>
> Konstantin

There are minor issues with rdma-core change. This kernel patch looks good to me.

I have added "Reviewed-by" on this patch.

Long
diff mbox series

Patch

diff --git a/drivers/infiniband/hw/mana/cq.c b/drivers/infiniband/hw/mana/cq.c
index 688ffe6..c6a3fd5 100644
--- a/drivers/infiniband/hw/mana/cq.c
+++ b/drivers/infiniband/hw/mana/cq.c
@@ -9,17 +9,22 @@  int mana_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
 		      struct ib_udata *udata)
 {
 	struct mana_ib_cq *cq = container_of(ibcq, struct mana_ib_cq, ibcq);
+	struct mana_ib_create_cq_resp resp = {};
+	struct mana_ib_ucontext *mana_ucontext;
 	struct ib_device *ibdev = ibcq->device;
 	struct mana_ib_create_cq ucmd = {};
 	struct mana_ib_dev *mdev;
+	bool is_rnic_cq;
+	u32 doorbell;
 	int err;
 
 	mdev = container_of(ibdev, struct mana_ib_dev, ib_dev);
 
-	if (udata->inlen < sizeof(ucmd))
-		return -EINVAL;
-
 	cq->comp_vector = attr->comp_vector % ibdev->num_comp_vectors;
+	cq->cq_handle = INVALID_MANA_HANDLE;
+
+	if (udata->inlen < offsetof(struct mana_ib_create_cq, flags))
+		return -EINVAL;
 
 	err = ib_copy_from_udata(&ucmd, udata, min(sizeof(ucmd), udata->inlen));
 	if (err) {
@@ -28,7 +33,9 @@  int mana_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
 		return err;
 	}
 
-	if (attr->cqe > mdev->adapter_caps.max_qp_wr) {
+	is_rnic_cq = !!(ucmd.flags & MANA_IB_CREATE_RNIC_CQ);
+
+	if (!is_rnic_cq && attr->cqe > mdev->adapter_caps.max_qp_wr) {
 		ibdev_dbg(ibdev, "CQE %d exceeding limit\n", attr->cqe);
 		return -EINVAL;
 	}
@@ -40,7 +47,41 @@  int mana_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
 		return err;
 	}
 
+	mana_ucontext = rdma_udata_to_drv_context(udata, struct mana_ib_ucontext,
+						  ibucontext);
+	doorbell = mana_ucontext->doorbell;
+
+	if (is_rnic_cq) {
+		err = mana_ib_gd_create_cq(mdev, cq, doorbell);
+		if (err) {
+			ibdev_dbg(ibdev, "Failed to create RNIC cq, %d\n", err);
+			goto err_destroy_queue;
+		}
+
+		err = mana_ib_install_cq_cb(mdev, cq);
+		if (err) {
+			ibdev_dbg(ibdev, "Failed to install cq callback, %d\n", err);
+			goto err_destroy_rnic_cq;
+		}
+	}
+
+	resp.cqid = cq->queue.id;
+	err = ib_copy_to_udata(udata, &resp, min(sizeof(resp), udata->outlen));
+	if (err) {
+		ibdev_dbg(&mdev->ib_dev, "Failed to copy to udata, %d\n", err);
+		goto err_remove_cq_cb;
+	}
+
 	return 0;
+
+err_remove_cq_cb:
+	mana_ib_remove_cq_cb(mdev, cq);
+err_destroy_rnic_cq:
+	mana_ib_gd_destroy_cq(mdev, cq);
+err_destroy_queue:
+	mana_ib_destroy_queue(mdev, &cq->queue);
+
+	return err;
 }
 
 int mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata)
@@ -52,6 +93,12 @@  int mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata)
 	mdev = container_of(ibdev, struct mana_ib_dev, ib_dev);
 
 	mana_ib_remove_cq_cb(mdev, cq);
+
+	/* Ignore return code as there is not much we can do about it.
+	 * The error message is printed inside.
+	 */
+	mana_ib_gd_destroy_cq(mdev, cq);
+
 	mana_ib_destroy_queue(mdev, &cq->queue);
 
 	return 0;
diff --git a/include/uapi/rdma/mana-abi.h b/include/uapi/rdma/mana-abi.h
index 5fcb31b..2c41cc3 100644
--- a/include/uapi/rdma/mana-abi.h
+++ b/include/uapi/rdma/mana-abi.h
@@ -16,8 +16,20 @@ 
 
 #define MANA_IB_UVERBS_ABI_VERSION 1
 
+enum mana_ib_create_cq_flags {
+	MANA_IB_CREATE_RNIC_CQ	= 1 << 0,
+};
+
 struct mana_ib_create_cq {
 	__aligned_u64 buf_addr;
+	__u16	flags;
+	__u16	reserved0;
+	__u32	reserved1;
+};
+
+struct mana_ib_create_cq_resp {
+	__u32 cqid;
+	__u32 reserved;
 };
 
 struct mana_ib_create_qp {