[PATCH rdma-next 1/4] net: mana: Probe rdma device in mana driver

Konstantin Taranov
2025-04-14T18:28:50Z

Initialize gdma device for rdma inside mana module.
For each gdma device, initialize an auxiliary ib device.

Signed-off-by: Konstantin Taranov <kotaranov@microsoft.com>
---
.../net/ethernet/microsoft/mana/gdma_main.c | 16 +++++++-
drivers/net/ethernet/microsoft/mana/mana_en.c | 39 +++++++++++++++++--
include/net/mana/mana.h | 3 ++
3 files changed, 53 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c b/drivers/net/ethernet/microsoft/mana/gdma_main.c
index b5156d4..1caf73c 100644
--- a/drivers/net/ethernet/microsoft/mana/gdma_main.c
+++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c
@@ -978,7 +978,6 @@ int mana_gd_register_device(struct gdma_dev *gd)

return 0;
}
-EXPORT_SYMBOL_NS(mana_gd_register_device, "NET_MANA");

int mana_gd_deregister_device(struct gdma_dev *gd)
{
@@ -1009,7 +1008,6 @@ int mana_gd_deregister_device(struct gdma_dev *gd)

return err;
}
-EXPORT_SYMBOL_NS(mana_gd_deregister_device, "NET_MANA");

u32 mana_gd_wq_avail_space(struct gdma_queue *wq)
{
@@ -1541,8 +1539,15 @@ static int mana_gd_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
if (err)
goto cleanup_gd;

+
+ err = mana_rdma_probe(&gc->mana_ib);
+ if (err)
+ goto cleanup_mana;
+
return 0;

+cleanup_mana:
+ mana_remove(&gc->mana, false);
cleanup_gd:
mana_gd_cleanup(pdev);
unmap_bar:
@@ -1569,6 +1574,7 @@ static void mana_gd_remove(struct pci_dev *pdev)
{
struct gdma_context *gc = pci_get_drvdata(pdev);

+ mana_rdma_remove(&gc->mana_ib);
mana_remove(&gc->mana, false);

mana_gd_cleanup(pdev);
@@ -1588,6 +1594,7 @@ static int mana_gd_suspend(struct pci_dev *pdev, pm_message_t state)
{
struct gdma_context *gc = pci_get_drvdata(pdev);

+ mana_rdma_remove(&gc->mana_ib);
mana_remove(&gc->mana, true);

mana_gd_cleanup(pdev);
@@ -1612,6 +1619,10 @@ static int mana_gd_resume(struct pci_dev *pdev)
if (err)
return err;

+ err = mana_rdma_probe(&gc->mana_ib);
+ if (err)
+ return err;
+
return 0;
}

@@ -1622,6 +1633,7 @@ static void mana_gd_shutdown(struct pci_dev *pdev)

dev_info(&pdev->dev, "Shutdown was called\n");

+ mana_rdma_remove(&gc->mana_ib);
mana_remove(&gc->mana, true);

mana_gd_cleanup(pdev);
diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c
index 4e870b1..70c4955 100644
--- a/drivers/net/ethernet/microsoft/mana/mana_en.c
+++ b/drivers/net/ethernet/microsoft/mana/mana_en.c
@@ -2936,7 +2936,7 @@ static void remove_adev(struct gdma_dev *gd)
gd->adev = NULL;
}

-static int add_adev(struct gdma_dev *gd)
+static int add_adev(struct gdma_dev *gd, const char *name)
{
struct auxiliary_device *adev;
struct mana_adev *madev;
@@ -2952,7 +2952,7 @@ static int add_adev(struct gdma_dev *gd)
goto idx_fail;
adev->id = ret;

- adev->name = "rdma";
+ adev->name = name;
adev->dev.parent = gd->gdma_context->dev;
adev->dev.release = adev_release;
madev->mdev = gd;
@@ -3064,7 +3064,7 @@ int mana_probe(struct gdma_dev *gd, bool resuming)
}
}

- err = add_adev(gd);
+ err = add_adev(gd, "dpdk");
out:
if (err)
mana_remove(gd, false);
@@ -3131,6 +3131,39 @@ out:
kfree(ac);
}

+int mana_rdma_probe(struct gdma_dev *gd)
+{
+ int err = 0;
+
+ if (gd->dev_id.type != GDMA_DEVICE_MANA_IB) {
+ /* RDMA device is not detected on pci */
+ return err;
+ }
+
+ err = mana_gd_register_device(gd);
+ if (err)
+ return err;
+
+ err = add_adev(gd, "rdma");
+ if (err)
+ mana_gd_deregister_device(gd);
+
+ return err;
+}
+
+void mana_rdma_remove(struct gdma_dev *gd)
+{
+ if (gd->dev_id.type != GDMA_DEVICE_MANA_IB) {
+ /* RDMA device is not detected on pci */
+ return;
+ }
+
+ if (gd->adev)
+ remove_adev(gd);
+
+ mana_gd_deregister_device(gd);
+}
+
struct net_device *mana_get_primary_netdev(struct mana_context *ac,
u32 port_index,
netdevice_tracker *tracker)
diff --git a/include/net/mana/mana.h b/include/net/mana/mana.h
index 0f78065..5857efc 100644
--- a/include/net/mana/mana.h
+++ b/include/net/mana/mana.h
@@ -488,6 +488,9 @@ int mana_detach(struct net_device *ndev, bool from_close);
int mana_probe(struct gdma_dev *gd, bool resuming);
void mana_remove(struct gdma_dev *gd, bool suspending);

+int mana_rdma_probe(struct gdma_dev *gd);
+void mana_rdma_remove(struct gdma_dev *gd);
+
void mana_xdp_tx(struct sk_buff *skb, struct net_device *ndev);
int mana_xdp_xmit(struct net_device *ndev, int n, struct xdp_frame **frames,
u32 flags);
--
2.43.0