From patchwork Thu Apr 18 16:52:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Taranov X-Patchwork-Id: 13635131 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 73662171648; Thu, 18 Apr 2024 16:52:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713459132; cv=none; b=pdnMfKDRut+ZjBFst9FFSB11IX0kCVsF6J8+ggKDE6QM/kc3/eh0NlMlUI65O3Uz1UA6QwMlWuH6o7Vlnb5uUjiPspk0i9dEMowBxw/Q4FT+PausYEplm2pdX61ad4mPU9TnKjMM38qUr//N7Cisy5L1jgroXTLH4KjeateEykg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713459132; c=relaxed/simple; bh=/0uuLjjYWxSxyb5NnVn+FuSGipT7WnI35hM/uEhelXE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=aVMW2bn+Pz9ju3FH3suoAPhrV1bVWRK1wCBybBaOHfBU4Iy+R2cYQ0PEB9I2A16qqxmyesWt6kBfd6syzsGZMWzKMPBUB2cfrP3hHy389CU+Hd+zlPdbYN3Nlmyu/wq5ge1Dyo7IsjWFovQPjfYPPy60YAbOQ0cR/jBSTe4lR2w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=GANkhwYJ; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="GANkhwYJ" Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 2984920FD8CD; Thu, 18 Apr 2024 09:52:11 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2984920FD8CD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1713459131; bh=tAsZJIj2Of05p989qQAkdOWhFJMrfd7SNYTDHemiUHk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GANkhwYJ0GkY+gLzPtqLD9B8+RN6oUeJHrLt6gxBTWT4eYW2fmFe1hrh6qH2qfios VbKl+rdXoX/bzpJIn0+D58z88BlaF6elWGQ16eLuyfUiDOwU71vMLfqkuRbYo4cDi5 mlgfTft+VN/W/XOVLzG7niJj6gHalGXsOyiFNNJU= From: Konstantin Taranov To: kotaranov@microsoft.com, sharmaajay@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 1/6] RDMA/mana_ib: create EQs for RNIC CQs Date: Thu, 18 Apr 2024 09:52:00 -0700 Message-Id: <1713459125-14914-2-git-send-email-kotaranov@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1713459125-14914-1-git-send-email-kotaranov@linux.microsoft.com> References: <1713459125-14914-1-git-send-email-kotaranov@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: From: Konstantin Taranov Create EQs within mana_ib device. Such EQs are required for creation of RNIC CQs. Signed-off-by: Konstantin Taranov Reviewed-by: Long Li --- drivers/infiniband/hw/mana/main.c | 34 ++++++++++++++++++++++++++-- drivers/infiniband/hw/mana/mana_ib.h | 1 + 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/hw/mana/main.c b/drivers/infiniband/hw/mana/main.c index f540147..546d059 100644 --- a/drivers/infiniband/hw/mana/main.c +++ b/drivers/infiniband/hw/mana/main.c @@ -658,7 +658,7 @@ int mana_ib_create_eqs(struct mana_ib_dev *mdev) { struct gdma_context *gc = mdev_to_gc(mdev); struct gdma_queue_spec spec = {}; - int err; + int err, i; spec.type = GDMA_EQ; spec.monitor_avl_buf = false; @@ -672,12 +672,42 @@ int mana_ib_create_eqs(struct mana_ib_dev *mdev) if (err) return err; + mdev->eqs = kcalloc(mdev->ib_dev.num_comp_vectors, sizeof(struct gdma_queue *), + GFP_KERNEL); + if (!mdev->eqs) { + err = -ENOMEM; + goto destroy_fatal_eq; + } + + for (i = 0; i < mdev->ib_dev.num_comp_vectors; i++) { + spec.eq.msix_index = (i + 1) % gc->num_msix_usable; + err = mana_gd_create_mana_eq(mdev->gdma_dev, &spec, &mdev->eqs[i]); + if (err) + goto destroy_eqs; + } + return 0; + +destroy_eqs: + while (i-- > 0) + mana_gd_destroy_queue(gc, mdev->eqs[i]); + kfree(mdev->eqs); +destroy_fatal_eq: + mana_gd_destroy_queue(gc, mdev->fatal_err_eq); + return err; } void mana_ib_destroy_eqs(struct mana_ib_dev *mdev) { - mana_gd_destroy_queue(mdev_to_gc(mdev), mdev->fatal_err_eq); + struct gdma_context *gc = mdev_to_gc(mdev); + int i; + + mana_gd_destroy_queue(gc, mdev->fatal_err_eq); + + for (i = 0; i < mdev->ib_dev.num_comp_vectors; i++) + mana_gd_destroy_queue(gc, mdev->eqs[i]); + + kfree(mdev->eqs); } int mana_ib_gd_create_rnic_adapter(struct mana_ib_dev *mdev) diff --git a/drivers/infiniband/hw/mana/mana_ib.h b/drivers/infiniband/hw/mana/mana_ib.h index 4c1240d..bfcf6df 100644 --- a/drivers/infiniband/hw/mana/mana_ib.h +++ b/drivers/infiniband/hw/mana/mana_ib.h @@ -56,6 +56,7 @@ struct mana_ib_dev { struct gdma_dev *gdma_dev; mana_handle_t adapter_handle; struct gdma_queue *fatal_err_eq; + struct gdma_queue **eqs; struct mana_ib_adapter_caps adapter_caps; }; From patchwork Thu Apr 18 16:52:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Taranov X-Patchwork-Id: 13635133 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9D79F17164F; Thu, 18 Apr 2024 16:52:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713459133; cv=none; b=iDkgf3E0TjDSr+sJtyf7qDjczD8hROEKwV6TetGAl2fE6bviggcyYI4J8aaqlPFWaoa4WwhOx5pMurXFZvLAluP+T6m06LQhAMYA1p3fTIyE8/MRtDglVtkkdCjDWp0c8LK1K1itZIabJwKy4Z6EBXDKJ8SX/j8+ZXE4fWGWdXs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713459133; c=relaxed/simple; bh=eGl22bN3sDPHTKQTqPGNG/XBa8noOeTscdYq+gxGN88=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=YSD1Tl5Ik86GGEdqw/SWeugqUKQYkhPGDBzARHDjXJ8REurmyk//sn0YhiSwH4lUVjySBankMI7I8j369+pSigDXyCfo6AbmkReO+io0U2Ru6B0x5f7NOMmhj+jx57SyX0kAX8GyTl/Zd/NrDQfPkbElouZ5E89NN1RUi731oYM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=lEuBRP4U; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="lEuBRP4U" Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 41C9320FD8D1; Thu, 18 Apr 2024 09:52:11 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 41C9320FD8D1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1713459131; bh=hW1hRjKkPzEkVWGy2zrvO80fJcfsyQm699uyvoQcmL4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lEuBRP4U8MitxLQbiMTvzvPLCIZ5zrDUmI/j8AYuzw1bCwHjIKkLzACdo5Qf8XXFu i3eGB8CUP0EEq0VmHQv4jMvI+kLDgmcNst4wQIQR73y3Lru/xpgE47hZTNMxf+WndE yc8RmfiaxycJtvN3P2A7RlhVyRhWkD7AyI/OBD0A= From: Konstantin Taranov To: kotaranov@microsoft.com, sharmaajay@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 2/6] RDMA/mana_ib: create and destroy RNIC cqs Date: Thu, 18 Apr 2024 09:52:01 -0700 Message-Id: <1713459125-14914-3-git-send-email-kotaranov@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1713459125-14914-1-git-send-email-kotaranov@linux.microsoft.com> References: <1713459125-14914-1-git-send-email-kotaranov@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: From: Konstantin Taranov Implement RNIC requests for creation and destruction of RNIC CQs. Signed-off-by: Konstantin Taranov Reviewed-by: Long Li --- drivers/infiniband/hw/mana/main.c | 54 ++++++++++++++++++++++++++++ drivers/infiniband/hw/mana/mana_ib.h | 32 +++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/drivers/infiniband/hw/mana/main.c b/drivers/infiniband/hw/mana/main.c index 546d059..2a41135 100644 --- a/drivers/infiniband/hw/mana/main.c +++ b/drivers/infiniband/hw/mana/main.c @@ -834,3 +834,57 @@ int mana_ib_gd_config_mac(struct mana_ib_dev *mdev, enum mana_ib_addr_op op, u8 return 0; } + +int mana_ib_gd_create_cq(struct mana_ib_dev *mdev, struct mana_ib_cq *cq, u32 doorbell) +{ + struct gdma_context *gc = mdev_to_gc(mdev); + struct mana_rnic_create_cq_resp resp = {}; + struct mana_rnic_create_cq_req req = {}; + int err; + + mana_gd_init_req_hdr(&req.hdr, MANA_IB_CREATE_CQ, sizeof(req), sizeof(resp)); + req.hdr.dev_id = gc->mana_ib.dev_id; + req.adapter = mdev->adapter_handle; + req.gdma_region = cq->queue.gdma_region; + req.eq_id = mdev->eqs[cq->comp_vector]->id; + req.doorbell_page = doorbell; + + err = mana_gd_send_request(gc, sizeof(req), &req, sizeof(resp), &resp); + + if (err) { + ibdev_err(&mdev->ib_dev, "Failed to create cq err %d", err); + return err; + } + + cq->queue.id = resp.cq_id; + cq->cq_handle = resp.cq_handle; + /* The GDMA region is now owned by the CQ handle */ + cq->queue.gdma_region = GDMA_INVALID_DMA_REGION; + + return 0; +} + +int mana_ib_gd_destroy_cq(struct mana_ib_dev *mdev, struct mana_ib_cq *cq) +{ + struct gdma_context *gc = mdev_to_gc(mdev); + struct mana_rnic_destroy_cq_resp resp = {}; + struct mana_rnic_destroy_cq_req req = {}; + int err; + + if (cq->cq_handle == INVALID_MANA_HANDLE) + return 0; + + mana_gd_init_req_hdr(&req.hdr, MANA_IB_DESTROY_CQ, sizeof(req), sizeof(resp)); + req.hdr.dev_id = gc->mana_ib.dev_id; + req.adapter = mdev->adapter_handle; + req.cq_handle = cq->cq_handle; + + err = mana_gd_send_request(gc, sizeof(req), &req, sizeof(resp), &resp); + + if (err) { + ibdev_err(&mdev->ib_dev, "Failed to destroy cq err %d", err); + return err; + } + + return 0; +} diff --git a/drivers/infiniband/hw/mana/mana_ib.h b/drivers/infiniband/hw/mana/mana_ib.h index bfcf6df..9162f29 100644 --- a/drivers/infiniband/hw/mana/mana_ib.h +++ b/drivers/infiniband/hw/mana/mana_ib.h @@ -92,6 +92,7 @@ struct mana_ib_cq { struct mana_ib_queue queue; int cqe; u32 comp_vector; + mana_handle_t cq_handle; }; struct mana_ib_qp { @@ -119,6 +120,8 @@ enum mana_ib_command_code { MANA_IB_DESTROY_ADAPTER = 0x30003, MANA_IB_CONFIG_IP_ADDR = 0x30004, MANA_IB_CONFIG_MAC_ADDR = 0x30005, + MANA_IB_CREATE_CQ = 0x30008, + MANA_IB_DESTROY_CQ = 0x30009, }; struct mana_ib_query_adapter_caps_req { @@ -202,6 +205,31 @@ struct mana_rnic_config_mac_addr_resp { struct gdma_resp_hdr hdr; }; /* HW Data */ +struct mana_rnic_create_cq_req { + struct gdma_req_hdr hdr; + mana_handle_t adapter; + u64 gdma_region; + u32 eq_id; + u32 doorbell_page; +}; /* HW Data */ + +struct mana_rnic_create_cq_resp { + struct gdma_resp_hdr hdr; + mana_handle_t cq_handle; + u32 cq_id; + u32 reserved; +}; /* HW Data */ + +struct mana_rnic_destroy_cq_req { + struct gdma_req_hdr hdr; + mana_handle_t adapter; + mana_handle_t cq_handle; +}; /* HW Data */ + +struct mana_rnic_destroy_cq_resp { + struct gdma_resp_hdr hdr; +}; /* HW Data */ + static inline struct gdma_context *mdev_to_gc(struct mana_ib_dev *mdev) { return mdev->gdma_dev->gdma_context; @@ -321,4 +349,8 @@ int mana_ib_gd_add_gid(const struct ib_gid_attr *attr, void **context); int mana_ib_gd_del_gid(const struct ib_gid_attr *attr, void **context); int mana_ib_gd_config_mac(struct mana_ib_dev *mdev, enum mana_ib_addr_op op, u8 *mac); + +int mana_ib_gd_create_cq(struct mana_ib_dev *mdev, struct mana_ib_cq *cq, u32 doorbell); + +int mana_ib_gd_destroy_cq(struct mana_ib_dev *mdev, struct mana_ib_cq *cq); #endif From patchwork Thu Apr 18 16:52:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Taranov X-Patchwork-Id: 13635132 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A9556171651; Thu, 18 Apr 2024 16:52:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713459133; cv=none; b=D6AQQtJrzR1eUFci0Q9aF2LbJxP3yXJjsWm0YMniJfAqsowKg3J9KkWr4qmr8uOUvsrAszVaidZFSkAfXY3PGpojKPOerFh78GnBV+h6Weanp8t0t4T9dx98FzMxHNgT4LokrSWQRPTe79t8kbo0ZHlshqheKMXkHQvJtc+3boo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713459133; c=relaxed/simple; bh=66ULFsYlF4+P/zd59wyz8wFV4wTbmXZtbpdURsGbB9c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=dY2gjca0zGPmXxapDK3zD5I6Ggrx3DGM2P5eJ+ILIyu60/LrLa0Uztbamq1oVfab/Vx7fLSPII4GihdP1MU8qYLHYmSckjlGlDf3dZlRQB7equ8UzSlqatKziKsqwdshE9ICorpo7AcvI+Onq3vwJbaa3DjTl69WW+ecjSwq7wY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=BNagOu2l; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="BNagOu2l" Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 59E6F20FD8D9; Thu, 18 Apr 2024 09:52:11 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 59E6F20FD8D9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1713459131; bh=aDAn/WfFY23tx012r1yhsWoDE/LbuHpjESH/aHdeOFw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BNagOu2lGE5nLOHAV/VW7C/iH6LJL9PXdUN4qc1RCqrTRwhSviJCh9vvVBbd1QWoj RY/vsWQMCCrfTesxn00JAhYZDRYK086ptwJjB92l46+dGSiFWPbtY3Debkr4OU58q/ lLN1ZHaXoJiZVAHGuUqFXfU/xk22lql/hhyDuucM= From: Konstantin Taranov To: kotaranov@microsoft.com, sharmaajay@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 3/6] RDMA/mana_ib: replace duplicate cqe with buf_size Date: Thu, 18 Apr 2024 09:52:02 -0700 Message-Id: <1713459125-14914-4-git-send-email-kotaranov@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1713459125-14914-1-git-send-email-kotaranov@linux.microsoft.com> References: <1713459125-14914-1-git-send-email-kotaranov@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: From: Konstantin Taranov Replace cqe with buf_size in struct mana_ib_cq. The cqe field is already present in struct ib_cq and can be accessed there. The buf_size field is required for mana RNIC CQs. Signed-off-by: Konstantin Taranov --- drivers/infiniband/hw/mana/cq.c | 4 ++-- drivers/infiniband/hw/mana/mana_ib.h | 2 +- drivers/infiniband/hw/mana/qp.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/infiniband/hw/mana/cq.c b/drivers/infiniband/hw/mana/cq.c index dc931b9..0467ee8 100644 --- a/drivers/infiniband/hw/mana/cq.c +++ b/drivers/infiniband/hw/mana/cq.c @@ -33,8 +33,8 @@ int mana_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, return -EINVAL; } - cq->cqe = attr->cqe; - err = mana_ib_create_queue(mdev, ucmd.buf_addr, cq->cqe * COMP_ENTRY_SIZE, &cq->queue); + cq->buf_size = attr->cqe * COMP_ENTRY_SIZE; + err = mana_ib_create_queue(mdev, ucmd.buf_addr, cq->buf_size, &cq->queue); if (err) { ibdev_dbg(ibdev, "Failed to create queue for create cq, %d\n", err); return err; diff --git a/drivers/infiniband/hw/mana/mana_ib.h b/drivers/infiniband/hw/mana/mana_ib.h index 9162f29..9c07021 100644 --- a/drivers/infiniband/hw/mana/mana_ib.h +++ b/drivers/infiniband/hw/mana/mana_ib.h @@ -90,7 +90,7 @@ struct mana_ib_mr { struct mana_ib_cq { struct ib_cq ibcq; struct mana_ib_queue queue; - int cqe; + u32 buf_size; u32 comp_vector; mana_handle_t cq_handle; }; diff --git a/drivers/infiniband/hw/mana/qp.c b/drivers/infiniband/hw/mana/qp.c index 280e85a..c4fb8b4 100644 --- a/drivers/infiniband/hw/mana/qp.c +++ b/drivers/infiniband/hw/mana/qp.c @@ -196,7 +196,7 @@ static int mana_ib_create_qp_rss(struct ib_qp *ibqp, struct ib_pd *pd, wq_spec.queue_size = wq->wq_buf_size; cq_spec.gdma_region = cq->queue.gdma_region; - cq_spec.queue_size = cq->cqe * COMP_ENTRY_SIZE; + cq_spec.queue_size = cq->buf_size; cq_spec.modr_ctx_id = 0; eq = &mpc->ac->eqs[cq->comp_vector]; cq_spec.attached_eq = eq->eq->id; @@ -355,7 +355,7 @@ static int mana_ib_create_qp_raw(struct ib_qp *ibqp, struct ib_pd *ibpd, wq_spec.queue_size = ucmd.sq_buf_size; cq_spec.gdma_region = send_cq->queue.gdma_region; - cq_spec.queue_size = send_cq->cqe * COMP_ENTRY_SIZE; + cq_spec.queue_size = send_cq->buf_size; cq_spec.modr_ctx_id = 0; eq_vec = send_cq->comp_vector; eq = &mpc->ac->eqs[eq_vec]; From patchwork Thu Apr 18 16:52:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Taranov X-Patchwork-Id: 13635134 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D5C87171653; Thu, 18 Apr 2024 16:52:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713459133; cv=none; b=T4cWROiVqYRafvAM3LhQHqIz10r5/KossauZYTX7wDLuxQnR0hFx+iDU7R/U1RtWxGygvPQDZi+rfZHscnGaACWGSxF6Wa747QWPWBhtN9Y3MFeu0A+yWXaUlCZCxAyJZGXx2L8qiV3jeRwaVEVpEOee1JmFr8WjYdzrhpXFmxU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713459133; c=relaxed/simple; bh=AYlUEqB21YfxQ2P7BzSsTllrC2taqWdyUY1X+23xLk8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=fKLBSBtLyjZY6TC9VDArBse01AEqzHw9eu6BrT2arA6Q4TyW45JMcthKnZPOnKnvte86z8gL7g7ATiHNDJOD7sHafvqdtbEI9q4wTuYAnDW183w63DfvMXKoHdG9B8wmpbdct17sGCIO8wjmJF7+yoEvKC17y9orJAU53FQIf5Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=ZD085CwF; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="ZD085CwF" Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 7232820FD8E1; Thu, 18 Apr 2024 09:52:11 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7232820FD8E1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1713459131; bh=re9gWjtsan98p476rpHxm6H6zqpS2UjxW7+iOlaeMF8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZD085CwFL300tTyoe/3E3gJPuoboJwWh6xDJPiRNlboDpmGAnl48HXfol2ph1uwx1 AL64AYHDwXRvAJPajihOt4Gpeu51y81GwgjSd3yVr4D9z0OFyc6MBq9pUxfxoQZ/F5 ph5ydbne2ufrxannuwi1luMthld/jH4Pr/og5Kgw= From: Konstantin Taranov To: kotaranov@microsoft.com, sharmaajay@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 4/6] RDMA/mana_ib: introduce a helper to remove cq callbacks Date: Thu, 18 Apr 2024 09:52:03 -0700 Message-Id: <1713459125-14914-5-git-send-email-kotaranov@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1713459125-14914-1-git-send-email-kotaranov@linux.microsoft.com> References: <1713459125-14914-1-git-send-email-kotaranov@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: From: Konstantin Taranov Intoduce the mana_ib_remove_cq_cb helper to remove cq callbacks. The helper removes code duplicates. Signed-off-by: Konstantin Taranov --- drivers/infiniband/hw/mana/cq.c | 19 ++++++++++++------- drivers/infiniband/hw/mana/mana_ib.h | 1 + drivers/infiniband/hw/mana/qp.c | 26 ++++---------------------- 3 files changed, 17 insertions(+), 29 deletions(-) diff --git a/drivers/infiniband/hw/mana/cq.c b/drivers/infiniband/hw/mana/cq.c index 0467ee8..6c3bb8c 100644 --- a/drivers/infiniband/hw/mana/cq.c +++ b/drivers/infiniband/hw/mana/cq.c @@ -48,16 +48,10 @@ int mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata) struct mana_ib_cq *cq = container_of(ibcq, struct mana_ib_cq, ibcq); struct ib_device *ibdev = ibcq->device; struct mana_ib_dev *mdev; - struct gdma_context *gc; mdev = container_of(ibdev, struct mana_ib_dev, ib_dev); - gc = mdev_to_gc(mdev); - - if (cq->queue.id != INVALID_QUEUE_ID) { - kfree(gc->cq_table[cq->queue.id]); - gc->cq_table[cq->queue.id] = NULL; - } + mana_ib_remove_cq_cb(mdev, cq); mana_ib_destroy_queue(mdev, &cq->queue); return 0; @@ -89,3 +83,14 @@ int mana_ib_install_cq_cb(struct mana_ib_dev *mdev, struct mana_ib_cq *cq) gc->cq_table[cq->queue.id] = gdma_cq; return 0; } + +void mana_ib_remove_cq_cb(struct mana_ib_dev *mdev, struct mana_ib_cq *cq) +{ + struct gdma_context *gc = mdev_to_gc(mdev); + + if (cq->queue.id >= gc->max_num_cqs) + return; + + kfree(gc->cq_table[cq->queue.id]); + gc->cq_table[cq->queue.id] = NULL; +} diff --git a/drivers/infiniband/hw/mana/mana_ib.h b/drivers/infiniband/hw/mana/mana_ib.h index 9c07021..6c19f4f 100644 --- a/drivers/infiniband/hw/mana/mana_ib.h +++ b/drivers/infiniband/hw/mana/mana_ib.h @@ -255,6 +255,7 @@ static inline void copy_in_reverse(u8 *dst, const u8 *src, u32 size) } int mana_ib_install_cq_cb(struct mana_ib_dev *mdev, struct mana_ib_cq *cq); +void mana_ib_remove_cq_cb(struct mana_ib_dev *mdev, struct mana_ib_cq *cq); int mana_ib_create_zero_offset_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem, mana_handle_t *gdma_region); diff --git a/drivers/infiniband/hw/mana/qp.c b/drivers/infiniband/hw/mana/qp.c index c4fb8b4..169b286 100644 --- a/drivers/infiniband/hw/mana/qp.c +++ b/drivers/infiniband/hw/mana/qp.c @@ -95,11 +95,9 @@ static int mana_ib_create_qp_rss(struct ib_qp *ibqp, struct ib_pd *pd, struct mana_ib_qp *qp = container_of(ibqp, struct mana_ib_qp, ibqp); struct mana_ib_dev *mdev = container_of(pd->device, struct mana_ib_dev, ib_dev); - struct gdma_context *gc = mdev_to_gc(mdev); struct ib_rwq_ind_table *ind_tbl = attr->rwq_ind_tbl; struct mana_ib_create_qp_rss_resp resp = {}; struct mana_ib_create_qp_rss ucmd = {}; - struct gdma_queue **gdma_cq_allocated; mana_handle_t *mana_ind_table; struct mana_port_context *mpc; unsigned int ind_tbl_size; @@ -173,13 +171,6 @@ static int mana_ib_create_qp_rss(struct ib_qp *ibqp, struct ib_pd *pd, goto fail; } - gdma_cq_allocated = kcalloc(ind_tbl_size, sizeof(*gdma_cq_allocated), - GFP_KERNEL); - if (!gdma_cq_allocated) { - ret = -ENOMEM; - goto fail; - } - qp->port = port; for (i = 0; i < ind_tbl_size; i++) { @@ -229,8 +220,6 @@ static int mana_ib_create_qp_rss(struct ib_qp *ibqp, struct ib_pd *pd, ret = mana_ib_install_cq_cb(mdev, cq); if (ret) goto fail; - - gdma_cq_allocated[i] = gc->cq_table[cq->queue.id]; } resp.num_entries = i; @@ -250,7 +239,6 @@ static int mana_ib_create_qp_rss(struct ib_qp *ibqp, struct ib_pd *pd, goto fail; } - kfree(gdma_cq_allocated); kfree(mana_ind_table); return 0; @@ -262,13 +250,10 @@ fail: wq = container_of(ibwq, struct mana_ib_wq, ibwq); cq = container_of(ibcq, struct mana_ib_cq, ibcq); - gc->cq_table[cq->queue.id] = NULL; - kfree(gdma_cq_allocated[i]); - + mana_ib_remove_cq_cb(mdev, cq); mana_destroy_wq_obj(mpc, GDMA_RQ, wq->rx_object); } - kfree(gdma_cq_allocated); kfree(mana_ind_table); return ret; @@ -287,10 +272,8 @@ static int mana_ib_create_qp_raw(struct ib_qp *ibqp, struct ib_pd *ibpd, struct mana_ib_ucontext *mana_ucontext = rdma_udata_to_drv_context(udata, struct mana_ib_ucontext, ibucontext); - struct gdma_context *gc = mdev_to_gc(mdev); struct mana_ib_create_qp_resp resp = {}; struct mana_ib_create_qp ucmd = {}; - struct gdma_queue *gdma_cq = NULL; struct mana_obj_spec wq_spec = {}; struct mana_obj_spec cq_spec = {}; struct mana_port_context *mpc; @@ -395,14 +378,13 @@ static int mana_ib_create_qp_raw(struct ib_qp *ibqp, struct ib_pd *ibpd, ibdev_dbg(&mdev->ib_dev, "Failed copy udata for create qp-raw, %d\n", err); - goto err_release_gdma_cq; + goto err_remove_cq_cb; } return 0; -err_release_gdma_cq: - kfree(gdma_cq); - gc->cq_table[send_cq->queue.id] = NULL; +err_remove_cq_cb: + mana_ib_remove_cq_cb(mdev, send_cq); err_destroy_wq_obj: mana_destroy_wq_obj(mpc, GDMA_SQ, qp->qp_handle); From patchwork Thu Apr 18 16:52:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Taranov X-Patchwork-Id: 13635135 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E8114171E48; Thu, 18 Apr 2024 16:52:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713459134; cv=none; b=jbf6zsvsksrXDTKLUIzTkhAJNsogx3sZo7seDhgnEN8F/Y62aiMW5LaHTf6x9AmV2KXwZ5LF4hxubOMgd7plNyGFH4qz35OwwQHZRZp7yLnegF1h1SHevt938vIxXD4ZDJfmqvIjIjJiw/r1IuhVqkxITFqyccR5svA1qNHbn0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713459134; c=relaxed/simple; bh=8VcU7ok/r82OU+vZIxsUsvhZaWe+LK6zJdpDqotEYWU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=EAGqJpcySOuGL/CkJybB/pKv+MQ4c4WM4uKkc9gg1MC9EQwIRCQ7pmJbfak7CTP8N1Q6xMAzOfyBSuWvxq59lh7iWEyBTqzRt/Iz9rrX/mo2hmd1liALtTyVOVYkGz0HLeSGGwbUgip+T2GxTDwyytsLZYgpKFnwt3G5R0RtL9U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=S8gSEAbP; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="S8gSEAbP" Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id 8B5A920FD8ED; Thu, 18 Apr 2024 09:52:11 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 8B5A920FD8ED DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1713459131; bh=/x44WfF5SQjqBQwqGks3DVpPDx/QzjlIKoFfU1B3cvY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S8gSEAbP7oFx+NXohcWbfbRDEZnrNibtPJo/tafCfJDOu8lxWfIdQRXsklDU6SH++ lr1jGiv6YQLHwZOtyntrpeh6m7vaZxToEJb5wMEio3qQWX+leeI079OwDmTWdBXkcq t67gKLE9aCPiRqH47oGrfZQ3fQ9MZ+MFaZZkriyc= From: Konstantin Taranov To: kotaranov@microsoft.com, sharmaajay@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 5/6] RDMA/mana_ib: boundary check before installing cq callbacks Date: Thu, 18 Apr 2024 09:52:04 -0700 Message-Id: <1713459125-14914-6-git-send-email-kotaranov@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1713459125-14914-1-git-send-email-kotaranov@linux.microsoft.com> References: <1713459125-14914-1-git-send-email-kotaranov@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: From: Konstantin Taranov Add a boundary check inside mana_ib_install_cq_cb to prevent index overflow. Fixes: 2a31c5a7e0d8 ("RDMA/mana_ib: Introduce mana_ib_install_cq_cb helper function") Signed-off-by: Konstantin Taranov Reviewed-by: Long Li --- drivers/infiniband/hw/mana/cq.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/infiniband/hw/mana/cq.c b/drivers/infiniband/hw/mana/cq.c index 6c3bb8c..8323085 100644 --- a/drivers/infiniband/hw/mana/cq.c +++ b/drivers/infiniband/hw/mana/cq.c @@ -70,6 +70,8 @@ int mana_ib_install_cq_cb(struct mana_ib_dev *mdev, struct mana_ib_cq *cq) struct gdma_context *gc = mdev_to_gc(mdev); struct gdma_queue *gdma_cq; + if (cq->queue.id >= gc->max_num_cqs) + return -EINVAL; /* Create CQ table entry */ WARN_ON(gc->cq_table[cq->queue.id]); gdma_cq = kzalloc(sizeof(*gdma_cq), GFP_KERNEL); From patchwork Thu Apr 18 16:52:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konstantin Taranov X-Patchwork-Id: 13635136 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E815D171E4D; Thu, 18 Apr 2024 16:52:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=13.77.154.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713459134; cv=none; b=ULQ6nLC1RSlFNU17G+Os6cggLbhesWx+rfcu2RbiGHq3pcv++HftY7tJO7TgMP3SXdRo9wHbGpFpU2Dej7NHKxB/VBTD0cS1zW7fVt0tBFK4sTatmI4tgG9tZn2EBowPAdYAsFw9oOtYWvLHG/iJYNIoUfiHFp5pkVazw+sdDfg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713459134; c=relaxed/simple; bh=P1jKaaFIVDCOd1shZPQNQUq8dSyyRB+AouxP+iSFsSY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=p7xM8B9oGQKgzkXU14dApZ11byQwhm0875uvbeaUvL3Yvfw/TrgBnYkYVGKenA/pZOTJh8q8nyhrO1RJ2BeypW36x/0WDFwf8Q5UY1lC71+I4uI2+onE80mvjiwadrIp0p+HL6qgOFinWjNGr23i5bl7poa6Kk8PWAmyfzVZ3x0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com; spf=pass smtp.mailfrom=linux.microsoft.com; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b=aQuP8NeG; arc=none smtp.client-ip=13.77.154.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.microsoft.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.b="aQuP8NeG" Received: from linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net (linux.microsoft.com [13.77.154.182]) by linux.microsoft.com (Postfix) with ESMTPSA id A3EAB20FD8F6; Thu, 18 Apr 2024 09:52:11 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com A3EAB20FD8F6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1713459131; bh=LYgSVLk66YgQdAnxAyejIaaET5e5BXdpX71D97ms0eo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aQuP8NeGhL4bt890gwh6NwiSRFptH/Qr8r5eIRLYUX8T6fPhwjiEV2fB9btUWDDwa Md0JoDc8qSvsjGgZVYXz49HW2uKUu0PWtYhsAkiHgK9TJFNwOthO9rRoMjcQ3aaHEv BRlbZpSA6BkagarwLmOE/bpFeBeFxvz39UQgL2OU= From: Konstantin Taranov To: kotaranov@microsoft.com, sharmaajay@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 6/6] RDMA/mana_ib: implement uapi for creation of rnic cq Date: Thu, 18 Apr 2024 09:52:05 -0700 Message-Id: <1713459125-14914-7-git-send-email-kotaranov@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1713459125-14914-1-git-send-email-kotaranov@linux.microsoft.com> References: <1713459125-14914-1-git-send-email-kotaranov@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: From: Konstantin Taranov Enable users to create RNIC CQs. With the previous request size, an ethernet CQ is created. Use the cq_buf_size from the user to create an RNIC CQ and return its ID. Signed-off-by: Konstantin Taranov --- drivers/infiniband/hw/mana/cq.c | 56 ++++++++++++++++++++++++++++++--- include/uapi/rdma/mana-abi.h | 7 +++++ 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/hw/mana/cq.c b/drivers/infiniband/hw/mana/cq.c index 8323085..a62bda7 100644 --- a/drivers/infiniband/hw/mana/cq.c +++ b/drivers/infiniband/hw/mana/cq.c @@ -9,17 +9,25 @@ 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 = true; + u32 doorbell; int err; mdev = container_of(ibdev, struct mana_ib_dev, ib_dev); - if (udata->inlen < sizeof(ucmd)) + 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, cq_buf_size)) return -EINVAL; - cq->comp_vector = attr->comp_vector % ibdev->num_comp_vectors; + if (udata->inlen == offsetof(struct mana_ib_create_cq, cq_buf_size)) + is_rnic_cq = false; err = ib_copy_from_udata(&ucmd, udata, min(sizeof(ucmd), udata->inlen)); if (err) { @@ -28,19 +36,53 @@ 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) { + if (!is_rnic_cq && attr->cqe > mdev->adapter_caps.max_qp_wr) { ibdev_dbg(ibdev, "CQE %d exceeding limit\n", attr->cqe); return -EINVAL; } - cq->buf_size = attr->cqe * COMP_ENTRY_SIZE; + cq->buf_size = is_rnic_cq ? ucmd.cq_buf_size : attr->cqe * COMP_ENTRY_SIZE; err = mana_ib_create_queue(mdev, ucmd.buf_addr, cq->buf_size, &cq->queue); if (err) { ibdev_dbg(ibdev, "Failed to create queue for create cq, %d\n", err); 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 +94,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..8fc9d32 100644 --- a/include/uapi/rdma/mana-abi.h +++ b/include/uapi/rdma/mana-abi.h @@ -18,6 +18,13 @@ struct mana_ib_create_cq { __aligned_u64 buf_addr; + __u32 cq_buf_size; + __u32 reserved; +}; + +struct mana_ib_create_cq_resp { + __u32 cqid; + __u32 reserved; }; struct mana_ib_create_qp {