diff mbox series

[v1,3/4] RDMA/mana_ib: create RDMA adapter handle

Message ID 1700709010-22042-4-git-send-email-longli@linuxonhyperv.com (mailing list archive)
State Not Applicable
Headers show
Series [v1,1/4] RDMA/mana_ib: register RDMA device with GDMA | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Long Li Nov. 23, 2023, 3:10 a.m. UTC
From: Long Li <longli@microsoft.com>

Create the RDMA device handle with the SoC using the management EQ created
earlier.

Signed-off-by: Long Li <longli@microsoft.com>
---
 drivers/infiniband/hw/mana/device.c  | 10 ++++--
 drivers/infiniband/hw/mana/main.c    | 51 ++++++++++++++++++++++++++++
 drivers/infiniband/hw/mana/mana_ib.h | 30 ++++++++++++++++
 3 files changed, 88 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/infiniband/hw/mana/device.c b/drivers/infiniband/hw/mana/device.c
index 3da4763e1a0c..5e5aa75230c2 100644
--- a/drivers/infiniband/hw/mana/device.c
+++ b/drivers/infiniband/hw/mana/device.c
@@ -93,9 +93,10 @@  static int mana_ib_probe(struct auxiliary_device *adev,
 		goto deregister_device;
 	}
 
+	ret = mana_ib_create_adapter(dev);
 	if (ret) {
-		ib_dealloc_device(&dev->ib_dev);
-		return ret;
+		ibdev_err(&dev->ib_dev, "Failed to create adapter");
+		goto free_error_eq;
 	}
 
 	ret = ib_register_device(&dev->ib_dev, "mana_%d",
@@ -108,8 +109,10 @@  static int mana_ib_probe(struct auxiliary_device *adev,
 	return 0;
 
 destroy_adapter:
-	mana_gd_destroy_queue(dev->gdma_dev->gdma_context, dev->fatal_err_eq);
+	mana_ib_destroy_adapter(dev);
+free_error_eq:
 	xa_destroy(&dev->rq_to_qp_lookup_table);
+	mana_gd_destroy_queue(dev->gdma_dev->gdma_context, dev->fatal_err_eq);
 deregister_device:
 	mana_gd_deregister_device(dev->gdma_dev);
 free_ib_device:
@@ -123,6 +126,7 @@  static void mana_ib_remove(struct auxiliary_device *adev)
 
 	ib_unregister_device(&dev->ib_dev);
 
+	mana_ib_destroy_adapter(dev);
 	mana_gd_destroy_queue(dev->gdma_dev->gdma_context, dev->fatal_err_eq);
 	xa_destroy(&dev->rq_to_qp_lookup_table);
 	mana_gd_deregister_device(dev->gdma_dev);
diff --git a/drivers/infiniband/hw/mana/main.c b/drivers/infiniband/hw/mana/main.c
index 032f926bf1ab..4f4343d14041 100644
--- a/drivers/infiniband/hw/mana/main.c
+++ b/drivers/infiniband/hw/mana/main.c
@@ -522,6 +522,57 @@  void mana_ib_disassociate_ucontext(struct ib_ucontext *ibcontext)
 {
 }
 
+int mana_ib_destroy_adapter(struct mana_ib_dev *dev)
+{
+	struct mana_ib_destroy_adapter_resp resp = {};
+	struct mana_ib_destroy_adapter_req req = {};
+	struct gdma_context *gc;
+	int err;
+
+	gc = dev->gdma_dev->gdma_context;
+
+	mana_gd_init_req_hdr(&req.hdr, MANA_IB_DESTROY_ADAPTER, sizeof(req),
+			     sizeof(resp));
+	req.adapter = dev->adapter_handle;
+	req.hdr.dev_id = gc->mana_ib.dev_id;
+
+	err = mana_gd_send_request(gc, sizeof(req), &req, sizeof(resp), &resp);
+
+	if (err) {
+		ibdev_err(&dev->ib_dev, "Failed to destroy adapter err %d", err);
+		return err;
+	}
+
+	return 0;
+}
+
+int mana_ib_create_adapter(struct mana_ib_dev *dev)
+{
+	struct mana_ib_create_adapter_resp resp = {};
+	struct mana_ib_create_adapter_req req = {};
+	struct gdma_context *gc;
+	int err;
+
+	gc = dev->gdma_dev->gdma_context;
+
+	mana_gd_init_req_hdr(&req.hdr, MANA_IB_CREATE_ADAPTER, sizeof(req),
+			     sizeof(resp));
+	req.notify_eq_id = dev->fatal_err_eq->id;
+	req.hdr.dev_id = gc->mana_ib.dev_id;
+
+	err = mana_gd_send_request(gc, sizeof(req), &req, sizeof(resp), &resp);
+
+	if (err) {
+		ibdev_err(&dev->ib_dev, "Failed to create adapter err %d",
+			  err);
+		return err;
+	}
+
+	dev->adapter_handle = resp.adapter;
+
+	return 0;
+}
+
 static void mana_ib_critical_event_handler(void *ctx, struct gdma_queue *queue,
 				      struct gdma_event *event)
 {
diff --git a/drivers/infiniband/hw/mana/mana_ib.h b/drivers/infiniband/hw/mana/mana_ib.h
index a5577c119def..4286caf0d67c 100644
--- a/drivers/infiniband/hw/mana/mana_ib.h
+++ b/drivers/infiniband/hw/mana/mana_ib.h
@@ -31,6 +31,7 @@  struct mana_ib_dev {
 	struct ib_device ib_dev;
 	struct gdma_dev *gdma_dev;
 	struct gdma_queue *fatal_err_eq;
+	mana_handle_t adapter_handle;
 	struct xarray rq_to_qp_lookup_table;
 };
 
@@ -94,6 +95,31 @@  struct mana_ib_rwq_ind_table {
 	struct ib_rwq_ind_table ib_ind_table;
 };
 
+enum mana_ib_command_code {
+	MANA_IB_CREATE_ADAPTER  = 0x30002,
+	MANA_IB_DESTROY_ADAPTER = 0x30003,
+};
+
+struct mana_ib_create_adapter_req {
+	struct gdma_req_hdr hdr;
+	u32 notify_eq_id;
+	u32 reserved;
+}; /*HW Data */
+
+struct mana_ib_create_adapter_resp {
+	struct gdma_resp_hdr hdr;
+	mana_handle_t adapter;
+}; /* HW Data */
+
+struct mana_ib_destroy_adapter_req {
+	struct gdma_req_hdr hdr;
+	mana_handle_t adapter;
+}; /*HW Data */
+
+struct mana_ib_destroy_adapter_resp {
+	struct gdma_resp_hdr hdr;
+}; /* HW Data */
+
 int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem,
 				 mana_handle_t *gdma_region);
 
@@ -163,4 +189,8 @@  void mana_ib_disassociate_ucontext(struct ib_ucontext *ibcontext);
 
 int mana_ib_create_error_eq(struct mana_ib_dev *mdev);
 
+int mana_ib_create_adapter(struct mana_ib_dev *mdev);
+
+int mana_ib_destroy_adapter(struct mana_ib_dev *mdev);
+
 #endif