From: Konstantin Taranov <kotaranov@linux.microsoft.com>
To: kotaranov@microsoft.com, snsanghvi@microsoft.com,
longli@microsoft.com, jgg@ziepe.ca, leon@kernel.org
Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH rdma-next 02/10] RDMA/mana: Create and destroy kernel RC QPs
Date: Thu, 1 Oct 2026 11:20:07 -0700 [thread overview]
Message-ID: <20261001182015.1757203-3-kotaranov@linux.microsoft.com> (raw)
In-Reply-To: <20261001182015.1757203-1-kotaranov@linux.microsoft.com>
From: Konstantin Taranov <kotaranov@microsoft.com>
Implement kernel RC QP creation and destruction. This feature requires
extended-WQE and power-of-two-SQ support from the HW.
Signed-off-by: Konstantin Taranov <kotaranov@microsoft.com>
---
drivers/infiniband/hw/mana/main.c | 3 +-
drivers/infiniband/hw/mana/mana_ib.h | 6 ++
drivers/infiniband/hw/mana/qp.c | 145 ++++++++++++++++++++++++++-
3 files changed, 152 insertions(+), 2 deletions(-)
diff --git a/drivers/infiniband/hw/mana/main.c b/drivers/infiniband/hw/mana/main.c
index ceb4ec58023a..fed20197addf 100644
--- a/drivers/infiniband/hw/mana/main.c
+++ b/drivers/infiniband/hw/mana/main.c
@@ -632,7 +632,8 @@ int mana_ib_query_device(struct ib_device *ibdev, struct ib_device_attr *props,
props->max_qp = dev->adapter_caps.max_qp_count;
props->max_qp_wr = dev->adapter_caps.max_qp_wr;
props->device_cap_flags = IB_DEVICE_RC_RNR_NAK_GEN;
- props->max_send_sge = dev->adapter_caps.max_send_sge_count;
+ /* Subtract 1 from max_send_sge to account for the reserved SGE */
+ props->max_send_sge = dev->adapter_caps.max_send_sge_count - 1;
props->max_recv_sge = dev->adapter_caps.max_recv_sge_count;
props->max_sge_rd = dev->adapter_caps.max_recv_sge_count;
props->max_cq = dev->adapter_caps.max_cq_count;
diff --git a/drivers/infiniband/hw/mana/mana_ib.h b/drivers/infiniband/hw/mana/mana_ib.h
index ceb7830b8da1..61af35bf0e40 100644
--- a/drivers/infiniband/hw/mana/mana_ib.h
+++ b/drivers/infiniband/hw/mana/mana_ib.h
@@ -265,6 +265,10 @@ struct mana_ib_qp {
u32 sq_psn;
bool sq_sig_all;
+ /* Serializes receive WR posting. */
+ spinlock_t rq_lock;
+ /* Serializes send and memory-management WR posting. */
+ spinlock_t sq_lock;
/* Serializes QP modification and error-list transitions. */
struct mutex modify_lock;
@@ -272,6 +276,7 @@ struct mana_ib_qp {
struct list_head recv_err_node;
struct shadow_queue shadow_rq;
struct shadow_queue shadow_sq;
+ struct shadow_queue shadow_mmq;
refcount_t refcount;
struct completion free;
@@ -313,6 +318,7 @@ enum mana_ib_adapter_features {
MANA_IB_FEATURE_DEV_COUNTERS_SUPPORT = BIT(5),
MANA_IB_FEATURE_MULTI_PORTS_SUPPORT = BIT(6),
MANA_IB_FEATURE_MSN_IN_WQE_SUPPORT = BIT(7),
+ MANA_IB_FEATURE_EXTENDED_WQE_FORMAT = BIT(9),
MANA_IB_FEATURE_RC_QP_SQ_POW2_SUPPORT = BIT(14),
MANA_IB_FEATURE_MULTI_PORT_GSI_SUPPORT = BIT(15),
};
diff --git a/drivers/infiniband/hw/mana/qp.c b/drivers/infiniband/hw/mana/qp.c
index ae2ebbcc759a..1dc5b078b4ff 100644
--- a/drivers/infiniband/hw/mana/qp.c
+++ b/drivers/infiniband/hw/mana/qp.c
@@ -441,6 +441,32 @@ static u32 mana_ib_queue_size(struct ib_qp_init_attr *attr, u32 queue_type)
queue_size = attr->cap.max_recv_wr *
mana_ib_wqe_size(attr->cap.max_recv_sge, INLINE_OOB_SMALL_SIZE);
break;
+ case IB_QPT_RC:
+ switch (queue_type) {
+ case MANA_RC_SEND_QUEUE_REQUESTER:
+ queue_size = attr->cap.max_send_wr *
+ mana_ib_fixed_wqe_size(attr->cap.max_send_sge,
+ INLINE_OOB_EXTRA_LARGE_SIZE);
+ break;
+ case MANA_RC_SEND_QUEUE_MMQ:
+ queue_size = attr->cap.max_send_wr *
+ mana_ib_wqe_size(1U, INLINE_OOB_EXTRA_LARGE_SIZE);
+ break;
+ case MANA_RC_SEND_QUEUE_RESPONDER:
+ queue_size = MANA_PAGE_SIZE;
+ break;
+ case MANA_RC_RECV_QUEUE_REQUESTER:
+ queue_size = attr->cap.max_send_wr *
+ mana_ib_wqe_size(attr->cap.max_send_sge, INLINE_OOB_SMALL_SIZE);
+ break;
+ case MANA_RC_RECV_QUEUE_RESPONDER:
+ queue_size = attr->cap.max_recv_wr *
+ mana_ib_wqe_size(attr->cap.max_recv_sge, INLINE_OOB_SMALL_SIZE);
+ break;
+ default:
+ return 0;
+ }
+ break;
default:
return 0;
}
@@ -460,6 +486,21 @@ static enum gdma_queue_type mana_ib_queue_type(struct ib_qp_init_attr *attr, u32
else
type = GDMA_RQ;
break;
+ case IB_QPT_RC:
+ switch (queue_type) {
+ case MANA_RC_SEND_QUEUE_REQUESTER:
+ case MANA_RC_SEND_QUEUE_RESPONDER:
+ case MANA_RC_SEND_QUEUE_MMQ:
+ type = GDMA_SQ;
+ break;
+ case MANA_RC_RECV_QUEUE_REQUESTER:
+ case MANA_RC_RECV_QUEUE_RESPONDER:
+ type = GDMA_RQ;
+ break;
+ default:
+ type = GDMA_INVALID_QUEUE;
+ }
+ break;
default:
type = GDMA_INVALID_QUEUE;
}
@@ -779,12 +820,107 @@ destroy_queues:
return err;
}
+static int mana_init_kernel_rc_qp(struct mana_ib_dev *mdev, struct mana_ib_qp *qp,
+ struct ib_qp_init_attr *attr, u64 *flags)
+{
+ u32 wqe_size;
+ int err;
+
+ err = create_shadow_queue(&qp->shadow_rq, attr->cap.max_recv_wr,
+ sizeof(struct shadow_wqe_header));
+ if (err)
+ return err;
+
+ err = create_shadow_queue(&qp->shadow_sq, attr->cap.max_send_wr,
+ sizeof(struct shadow_wqe_header));
+ if (err)
+ goto destroy_rq;
+
+ err = create_shadow_queue(&qp->shadow_mmq, attr->cap.max_send_wr,
+ sizeof(struct shadow_wqe_header));
+ if (err)
+ goto destroy_sq;
+
+ wqe_size = mana_ib_fixed_wqe_size(attr->cap.max_send_sge,
+ INLINE_OOB_EXTRA_LARGE_SIZE);
+ *flags |= MANA_RC_FLAG_FIXED_SIZE_WQE;
+ if (mdev->adapter_caps.feature_flags & MANA_IB_FEATURE_MSN_IN_WQE_SUPPORT)
+ *flags |= MANA_RC_FLAG_MSN_IN_WQE;
+ qp->rc_qp.wqe_size_in_bu = wqe_size / GDMA_WQE_BU_SIZE;
+
+ return 0;
+
+destroy_sq:
+ destroy_shadow_queue(&qp->shadow_sq);
+destroy_rq:
+ destroy_shadow_queue(&qp->shadow_rq);
+ return err;
+}
+
+static int mana_ib_create_rc_qp_kernel(struct ib_qp *ibqp, struct ib_pd *ibpd,
+ struct ib_qp_init_attr *attr)
+{
+ struct mana_ib_dev *mdev = container_of(ibpd->device, struct mana_ib_dev, ib_dev);
+ struct mana_ib_qp *qp = container_of(ibqp, struct mana_ib_qp, ibqp);
+ u32 doorbell = mdev->gdma_dev->doorbell;
+ u32 queue_size;
+ u64 flags = 0;
+ int i, err;
+
+ if (!(mdev->adapter_caps.feature_flags & MANA_IB_FEATURE_EXTENDED_WQE_FORMAT))
+ return -EOPNOTSUPP;
+ if (!(mdev->adapter_caps.feature_flags & MANA_IB_FEATURE_RC_QP_SQ_POW2_SUPPORT))
+ return -EOPNOTSUPP;
+
+ for (i = 0; i < MANA_RC_QUEUE_TYPE_MAX; ++i) {
+ queue_size = mana_ib_queue_size(attr, i);
+ err = mana_ib_create_kernel_queue(mdev, queue_size,
+ mana_ib_queue_type(attr, i),
+ &qp->rc_qp.queues[i]);
+ if (err)
+ goto destroy_queues;
+ }
+
+ err = mana_init_kernel_rc_qp(mdev, qp, attr, &flags);
+ if (err)
+ goto destroy_queues;
+
+ err = mana_ib_gd_create_rc_qp(mdev, qp, attr, doorbell, flags);
+ if (err)
+ goto deinit_queues;
+
+ qp->ibqp.qp_num = qp->rc_qp.queues[MANA_RC_RECV_QUEUE_RESPONDER].id;
+ qp->port = attr->port_num;
+
+ for (i = 0; i < MANA_RC_QUEUE_TYPE_MAX; ++i)
+ qp->rc_qp.queues[i].kmem->id = qp->rc_qp.queues[i].id;
+
+ err = mana_table_store_qp(mdev, qp);
+ if (err)
+ goto destroy_qp;
+
+ return 0;
+
+destroy_qp:
+ mana_ib_gd_destroy_rnic_qp(mdev, qp);
+deinit_queues:
+ destroy_shadow_queue(&qp->shadow_rq);
+ destroy_shadow_queue(&qp->shadow_sq);
+ destroy_shadow_queue(&qp->shadow_mmq);
+destroy_queues:
+ while (i-- > 0)
+ mana_ib_destroy_queue(mdev, &qp->rc_qp.queues[i]);
+ return err;
+}
+
int mana_ib_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attr,
struct ib_udata *udata)
{
struct mana_ib_qp *qp = container_of(ibqp, struct mana_ib_qp, ibqp);
qp->sq_sig_all = attr->sq_sig_type == IB_SIGNAL_ALL_WR;
+ spin_lock_init(&qp->rq_lock);
+ spin_lock_init(&qp->sq_lock);
mutex_init(&qp->modify_lock);
INIT_LIST_HEAD(&qp->send_err_node);
INIT_LIST_HEAD(&qp->recv_err_node);
@@ -798,7 +934,10 @@ int mana_ib_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *attr,
return mana_ib_create_qp_raw(ibqp, ibqp->pd, attr, udata);
case IB_QPT_RC:
- return mana_ib_create_rc_qp(ibqp, ibqp->pd, attr, udata);
+ if (udata)
+ return mana_ib_create_rc_qp(ibqp, ibqp->pd, attr, udata);
+ else
+ return mana_ib_create_rc_qp_kernel(ibqp, ibqp->pd, attr);
case IB_QPT_UC:
return mana_ib_create_uc_qp(ibqp, ibqp->pd, attr, udata);
case IB_QPT_UD:
@@ -1030,7 +1169,11 @@ static int mana_ib_destroy_rc_qp(struct mana_ib_qp *qp, struct ib_udata *udata)
return err;
mana_table_remove_qp(mdev, qp);
+ mana_remove_qp_from_cqs(qp, false);
+ destroy_shadow_queue(&qp->shadow_rq);
+ destroy_shadow_queue(&qp->shadow_sq);
+ destroy_shadow_queue(&qp->shadow_mmq);
/* Ignore return code as there is not much we can do about it.
* The error message is printed inside.
*/
--
2.43.0
next prev parent reply other threads:[~2026-10-01 18:21 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-01 18:20 [PATCH rdma-next 00/10] RDMA/mana_ib: Add kernel RC and fast registration support Konstantin Taranov
2026-10-01 18:20 ` [PATCH rdma-next 01/10] RDMA/mana_ib: Allocate and map fast-registration MRs Konstantin Taranov
2026-10-01 18:20 ` Konstantin Taranov [this message]
2026-10-01 18:20 ` [PATCH rdma-next 03/10] net/mana: Extend GDMA encoding for new RDMA WQEs Konstantin Taranov
2026-10-01 18:20 ` [PATCH rdma-next 04/10] RDMA/mana_ib: Maintain kernel RC QP state Konstantin Taranov
2026-10-01 18:20 ` [PATCH rdma-next 05/10] RDMA/mana_ib: Post receive WRs on kernel RC QPs Konstantin Taranov
2026-10-01 18:20 ` [PATCH rdma-next 06/10] RDMA/mana_ib: Post send and memory-management WRs on " Konstantin Taranov
2026-10-01 18:20 ` [PATCH rdma-next 07/10] RDMA/mana_ib: Poll RC completions using PSN and FSN progress Konstantin Taranov
2026-10-01 18:20 ` [PATCH rdma-next 08/10] RDMA/mana_ib: Flush and notify CQs when kernel QPs enter ERR Konstantin Taranov
2026-10-01 18:20 ` [PATCH rdma-next 09/10] RDMA/mana_ib: Handle error CQEs for RC QPs Konstantin Taranov
2026-10-01 18:20 ` [PATCH rdma-next 10/10] RDMA/mana_ib: Drain kernel receive and send queues Konstantin Taranov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261001182015.1757203-3-kotaranov@linux.microsoft.com \
--to=kotaranov@linux.microsoft.com \
--cc=jgg@ziepe.ca \
--cc=kotaranov@microsoft.com \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=longli@microsoft.com \
--cc=snsanghvi@microsoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®