[Patch v2 4/5] RDMA/mana_ib : Create Adapter - each vf bound to adapter object

sharmaajay
2023-07-26T03:57:29Z

Create adapte object to have nice container
for VF resources.

Signed-off-by: Ajay Sharma <sharmaajay@microsoft.com>
---
drivers/infiniband/hw/mana/device.c | 11 +++++-
drivers/infiniband/hw/mana/main.c | 50 ++++++++++++++++++++++++++++
drivers/infiniband/hw/mana/mana_ib.h | 30 +++++++++++++++++
3 files changed, 90 insertions(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/mana/device.c b/drivers/infiniband/hw/mana/device.c
index 3ab4e69705df..4077e440657a 100644
--- a/drivers/infiniband/hw/mana/device.c
+++ b/drivers/infiniband/hw/mana/device.c
@@ -91,15 +91,23 @@ static int mana_ib_probe(struct auxiliary_device *adev,
goto deregister_device;
}

+ ret = mana_ib_create_adapter(mib_dev);
+ if (ret) {
+ ibdev_err(&mib_dev->ib_dev, "Failed to create adapter");
+ goto free_error_eq;
+ }
+
ret = ib_register_device(&mib_dev->ib_dev, "mana_%d",
mdev->gdma_context->dev);
if (ret)
- goto free_error_eq;
+ goto destroy_adapter;

dev_set_drvdata(&adev->dev, mib_dev);

return 0;

+destroy_adapter:
+ mana_ib_destroy_adapter(mib_dev);
free_error_eq:
mana_gd_destroy_queue(mib_dev->gc, mib_dev->fatal_err_eq);
deregister_device:
@@ -114,6 +122,7 @@ static void mana_ib_remove(struct auxiliary_device *adev)
struct mana_ib_dev *mib_dev = dev_get_drvdata(&adev->dev);

mana_gd_destroy_queue(mib_dev->gc, mib_dev->fatal_err_eq);
+ mana_ib_destroy_adapter(mib_dev);
mana_gd_deregister_device(&mib_dev->gc->mana_ib);
ib_unregister_device(&mib_dev->ib_dev);
ib_dealloc_device(&mib_dev->ib_dev);
diff --git a/drivers/infiniband/hw/mana/main.c b/drivers/infiniband/hw/mana/main.c
index 2ea24ba3065f..aab1cc096824 100644
--- a/drivers/infiniband/hw/mana/main.c
+++ b/drivers/infiniband/hw/mana/main.c
@@ -505,6 +505,56 @@ void mana_ib_disassociate_ucontext(struct ib_ucontext *ibcontext)
{
}

+int mana_ib_destroy_adapter(struct mana_ib_dev *mib_dev)
+{
+ struct mana_ib_destroy_adapter_resp resp = {};
+ struct mana_ib_destroy_adapter_req req = {};
+ struct gdma_context *gc;
+ int err;
+
+ gc = mib_dev->gc;
+
+ mana_gd_init_req_hdr(&req.hdr, MANA_IB_DESTROY_ADAPTER, sizeof(req),
+ sizeof(resp));
+ req.adapter = mib_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(&mib_dev->ib_dev, "Failed to destroy adapter err %d", err);
+ return err;
+ }
+
+ return 0;
+}
+
+int mana_ib_create_adapter(struct mana_ib_dev *mib_dev)
+{
+ struct mana_ib_create_adapter_resp resp = {};
+ struct mana_ib_create_adapter_req req = {};
+ struct gdma_context *gc;
+ int err;
+
+ gc = mib_dev->gc;
+
+ mana_gd_init_req_hdr(&req.hdr, MANA_IB_CREATE_ADAPTER, sizeof(req),
+ sizeof(resp));
+ req.notify_eq_id = mib_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(&mib_dev->ib_dev, "Failed to create adapter err %d", err);
+ return err;
+ }
+
+ mib_dev->adapter_handle = resp.adapter;
+
+ return 0;
+}
+
void mana_ib_soc_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 4383777354d3..8a652bccd978 100644
--- a/drivers/infiniband/hw/mana/mana_ib.h
+++ b/drivers/infiniband/hw/mana/mana_ib.h
@@ -32,6 +32,7 @@ struct mana_ib_dev {
struct gdma_dev *gdma_dev;
struct gdma_context *gc;
struct gdma_queue *fatal_err_eq;
+ mana_handle_t adapter_handle;
};

struct mana_ib_wq {
@@ -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 *mib_dev,
struct ib_umem *umem,
mana_handle_t *gdma_region);
@@ -164,4 +190,8 @@ void mana_ib_disassociate_ucontext(struct ib_ucontext *ibcontext);

int mana_ib_create_error_eq(struct mana_ib_dev *mib_dev);

+int mana_ib_create_adapter(struct mana_ib_dev *mib_dev);
+
+int mana_ib_destroy_adapter(struct mana_ib_dev *mib_dev);
+
#endif
--
2.25.1