[SRU][J:linux-azure][PATCH 1/1] net: mana: Add handler for sriov configure

John Cabaj john.cabaj at canonical.com
Thu Aug 6 03:49:17 UTC 2026


From: Haiyang Zhang <haiyangz at microsoft.com>

BugLink: https://bugs.launchpad.net/bugs/2162934

Add callback function for the pci_driver / sriov_configure.

It asks the NIC to provide certain number of VFs, or disable
VFs if the request is zero.

Signed-off-by: Haiyang Zhang <haiyangz at microsoft.com>
Link: https://patch.msgid.link/20260710192735.2921300-1-haiyangz@linux.microsoft.com
Signed-off-by: Paolo Abeni <pabeni at redhat.com>
(backported from commit ce6b4d3216b63f902bb8e9695ee6c10c83415f65 linux-next)
[john-cabaj: context changes]
Signed-off-by: John Cabaj <john.cabaj at canonical.com>
---
 .../net/ethernet/microsoft/mana/gdma_main.c   | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/net/ethernet/microsoft/mana/gdma_main.c b/drivers/net/ethernet/microsoft/mana/gdma_main.c
index 1082b4e012d31..e9d34cf6c8fc0 100644
--- a/drivers/net/ethernet/microsoft/mana/gdma_main.c
+++ b/drivers/net/ethernet/microsoft/mana/gdma_main.c
@@ -1619,6 +1619,8 @@ static void mana_gd_remove(struct pci_dev *pdev)
 {
 	struct gdma_context *gc = pci_get_drvdata(pdev);
 
+	pci_disable_sriov(pdev);
+
 	mana_remove(&gc->mana, false);
 
 	mana_gd_cleanup(pdev);
@@ -1688,6 +1690,27 @@ static void mana_gd_shutdown(struct pci_dev *pdev)
 	pci_disable_device(pdev);
 }
 
+static int mana_sriov_configure(struct pci_dev *pdev, int numvfs)
+{
+	int err = 0;
+
+	dev_info(&pdev->dev, "Requested num VFs: %d\n", numvfs);
+
+	if (numvfs > 0) {
+		err = pci_enable_sriov(pdev, numvfs);
+	} else {
+		if (pci_vfs_assigned(pdev)) {
+			dev_warn(&pdev->dev,
+				 "Cannot disable SR-IOV while VFs are assigned\n");
+			return -EPERM;
+		}
+
+		pci_disable_sriov(pdev);
+	}
+
+	return err ? err : numvfs;
+}
+
 static const struct pci_device_id mana_id_table[] = {
 	{ PCI_DEVICE(PCI_VENDOR_ID_MICROSOFT, MANA_PF_DEVICE_ID) },
 	{ PCI_DEVICE(PCI_VENDOR_ID_MICROSOFT, MANA_VF_DEVICE_ID) },
@@ -1702,6 +1725,7 @@ static struct pci_driver mana_driver = {
 	.suspend	= mana_gd_suspend,
 	.resume		= mana_gd_resume,
 	.shutdown	= mana_gd_shutdown,
+	.sriov_configure = mana_sriov_configure,
 };
 
 static int __init mana_driver_init(void)
-- 
2.43.0




More information about the kernel-team mailing list