sfc: add EF100 VF support via a write to sriov_numvfs
authorPieter Jansen van Vuuren <pieter.jansen-van-vuuren@amd.com>
Thu, 28 Apr 2022 11:39:33 +0000 (12:39 +0100)
committerJakub Kicinski <kuba@kernel.org>
Sat, 30 Apr 2022 01:43:01 +0000 (18:43 -0700)
This patch extends the EF100 PF driver by adding .sriov_configure()
which would allow users to enable and disable virtual functions
using the sriov sysfs.

Signed-off-by: Pieter Jansen van Vuuren <pieter.jansen-van-vuuren@amd.com>
Signed-off-by: Edward Cree <ecree.xilinx@gmail.com>
Link: https://lore.kernel.org/r/75e74d9e-14ce-0524-9668-5ab735a7cf62@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/sfc/Makefile
drivers/net/ethernet/sfc/ef100.c
drivers/net/ethernet/sfc/ef100_nic.c
drivers/net/ethernet/sfc/ef100_sriov.c [new file with mode: 0644]
drivers/net/ethernet/sfc/ef100_sriov.h [new file with mode: 0644]

index 8bd01c429f9137366c39fc2d0c2c5f5faa048708..5ba98769b52bb2f6257d8a1dc38022e770e917df 100644 (file)
@@ -8,7 +8,7 @@ sfc-y                   += efx.o efx_common.o efx_channels.o nic.o \
                           ef100.o ef100_nic.o ef100_netdev.o \
                           ef100_ethtool.o ef100_rx.o ef100_tx.o
 sfc-$(CONFIG_SFC_MTD)  += mtd.o
-sfc-$(CONFIG_SFC_SRIOV)        += sriov.o siena_sriov.o ef10_sriov.o
+sfc-$(CONFIG_SFC_SRIOV)        += sriov.o siena_sriov.o ef10_sriov.o ef100_sriov.o
 
 obj-$(CONFIG_SFC)      += sfc.o
 
index ffdb36715a49689edbe1212298cee4c6e4ee17cb..173f0ecebc70fe0a59d0c0252f3b8c9dbb4a2f7a 100644 (file)
@@ -2,7 +2,7 @@
 /****************************************************************************
  * Driver for Solarflare network controllers and boards
  * Copyright 2005-2018 Solarflare Communications Inc.
- * Copyright 2019-2020 Xilinx Inc.
+ * Copyright 2019-2022 Xilinx Inc.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 as published
@@ -17,6 +17,7 @@
 #include "io.h"
 #include "ef100_nic.h"
 #include "ef100_netdev.h"
+#include "ef100_sriov.h"
 #include "ef100_regs.h"
 #include "ef100.h"
 
@@ -436,6 +437,10 @@ static void ef100_pci_remove(struct pci_dev *pci_dev)
         * blocks, so we have to do it before PCI removal.
         */
        unregister_netdevice_notifier(&efx->netdev_notifier);
+#if defined(CONFIG_SFC_SRIOV)
+       if (!efx->type->is_vf)
+               efx_ef100_pci_sriov_disable(efx);
+#endif
        ef100_remove(efx);
        efx_fini_io(efx);
        netif_dbg(efx, drv, efx->net_dev, "shutdown successful\n");
@@ -524,6 +529,23 @@ fail:
        return rc;
 }
 
+#ifdef CONFIG_SFC_SRIOV
+static int ef100_pci_sriov_configure(struct pci_dev *dev, int num_vfs)
+{
+       struct efx_nic *efx = pci_get_drvdata(dev);
+       int rc;
+
+       if (efx->type->sriov_configure) {
+               rc = efx->type->sriov_configure(efx, num_vfs);
+               if (rc)
+                       return rc;
+               else
+                       return num_vfs;
+       }
+       return -ENOENT;
+}
+#endif
+
 /* PCI device ID table */
 static const struct pci_device_id ef100_pci_table[] = {
        {PCI_DEVICE(PCI_VENDOR_ID_XILINX, 0x0100),  /* Riverhead PF */
@@ -538,6 +560,9 @@ struct pci_driver ef100_pci_driver = {
        .id_table       = ef100_pci_table,
        .probe          = ef100_pci_probe,
        .remove         = ef100_pci_remove,
+#ifdef CONFIG_SFC_SRIOV
+       .sriov_configure = ef100_pci_sriov_configure,
+#endif
        .err_handler    = &efx_err_handlers,
 };
 
index a07cbf45a3266649dce019ef64788d363c367176..b04911bc8c5719e14c326e9ff5e3ad687f7354b3 100644 (file)
@@ -2,7 +2,7 @@
 /****************************************************************************
  * Driver for Solarflare network controllers and boards
  * Copyright 2018 Solarflare Communications Inc.
- * Copyright 2019-2020 Xilinx Inc.
+ * Copyright 2019-2022 Xilinx Inc.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 as published
@@ -22,6 +22,7 @@
 #include "mcdi_filters.h"
 #include "ef100_rx.h"
 #include "ef100_tx.h"
+#include "ef100_sriov.h"
 #include "ef100_netdev.h"
 #include "rx_common.h"
 
@@ -787,6 +788,9 @@ const struct efx_nic_type ef100_pf_nic_type = {
        .update_stats = ef100_update_stats,
        .pull_stats = efx_mcdi_mac_pull_stats,
        .stop_stats = efx_mcdi_mac_stop_stats,
+#ifdef CONFIG_SFC_SRIOV
+       .sriov_configure = efx_ef100_sriov_configure,
+#endif
 
        /* Per-type bar/size configuration not used on ef100. Location of
         * registers is defined by extended capabilities.
diff --git a/drivers/net/ethernet/sfc/ef100_sriov.c b/drivers/net/ethernet/sfc/ef100_sriov.c
new file mode 100644 (file)
index 0000000..6645781
--- /dev/null
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/****************************************************************************
+ * Driver for Solarflare network controllers and boards
+ * Copyright 2019 Solarflare Communications Inc.
+ * Copyright 2020-2022 Xilinx Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation, incorporated herein by reference.
+ */
+
+#include "ef100_sriov.h"
+#include "ef100_nic.h"
+
+static int efx_ef100_pci_sriov_enable(struct efx_nic *efx, int num_vfs)
+{
+       struct pci_dev *dev = efx->pci_dev;
+       int rc;
+
+       efx->vf_count = num_vfs;
+       rc = pci_enable_sriov(dev, num_vfs);
+       if (rc)
+               goto fail;
+
+       return 0;
+
+fail:
+       netif_err(efx, probe, efx->net_dev, "Failed to enable SRIOV VFs\n");
+       efx->vf_count = 0;
+       return rc;
+}
+
+int efx_ef100_pci_sriov_disable(struct efx_nic *efx)
+{
+       struct pci_dev *dev = efx->pci_dev;
+       unsigned int vfs_assigned;
+
+       vfs_assigned = pci_vfs_assigned(dev);
+       if (vfs_assigned) {
+               netif_info(efx, drv, efx->net_dev, "VFs are assigned to guests; "
+                          "please detach them before disabling SR-IOV\n");
+               return -EBUSY;
+       }
+
+       pci_disable_sriov(dev);
+
+       return 0;
+}
+
+int efx_ef100_sriov_configure(struct efx_nic *efx, int num_vfs)
+{
+       if (num_vfs == 0)
+               return efx_ef100_pci_sriov_disable(efx);
+       else
+               return efx_ef100_pci_sriov_enable(efx, num_vfs);
+}
diff --git a/drivers/net/ethernet/sfc/ef100_sriov.h b/drivers/net/ethernet/sfc/ef100_sriov.h
new file mode 100644 (file)
index 0000000..c48fccd
--- /dev/null
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/****************************************************************************
+ * Driver for Solarflare network controllers and boards
+ * Copyright 2019 Solarflare Communications Inc.
+ * Copyright 2020-2022 Xilinx Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation, incorporated herein by reference.
+ */
+#include "net_driver.h"
+
+int efx_ef100_sriov_configure(struct efx_nic *efx, int num_vfs);
+int efx_ef100_pci_sriov_disable(struct efx_nic *efx);