net/mlx5: Read num_vfs before disabling SR-IOV
authorParav Pandit <parav@mellanox.com>
Mon, 28 Oct 2019 18:29:17 +0000 (13:29 -0500)
committerSaeed Mahameed <saeedm@mellanox.com>
Wed, 13 Nov 2019 22:25:03 +0000 (14:25 -0800)
mlx5_device_disable_sriov() currently reads num_vfs from the PCI core.
However when mlx5_device_disable_sriov() is executed, SR-IOV is
already disabled at the PCI level.
Due to this disable_hca() cleanup is not done during SR-IOV disable
flow.

mlx5_sriov_disable()
  pci_enable_sriov()
  mlx5_device_disable_sriov() <- num_vfs is zero here.

When SR-IOV enablement fails during mlx5_sriov_enable(), HCA's are left
in enabled stage because mlx5_device_disable_sriov() relies on num_vfs
from PCI core.

mlx5_sriov_enable()
  mlx5_device_enable_sriov()
  pci_enable_sriov() <- Fails

Hence, to overcome above issues,
(a) Read num_vfs before disabling SR-IOV and use it.
(b) Use num_vfs given when enabling sriov in error unwinding path.

Fixes: d886aba677a0 ("net/mlx5: Reduce dependency on enabled_vfs counter and num_vfs")
Signed-off-by: Parav Pandit <parav@mellanox.com>
Reviewed-by: Daniel Jurgens <danielj@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/net/ethernet/mellanox/mlx5/core/sriov.c

index f641f13364020a15475c79d3fa5e231613d9bc11..03f037811f1d9219b652baf8421e1767d9f22e49 100644 (file)
@@ -108,10 +108,10 @@ enable_vfs_hca:
        return 0;
 }
 
-static void mlx5_device_disable_sriov(struct mlx5_core_dev *dev, bool clear_vf)
+static void
+mlx5_device_disable_sriov(struct mlx5_core_dev *dev, int num_vfs, bool clear_vf)
 {
        struct mlx5_core_sriov *sriov = &dev->priv.sriov;
-       int num_vfs = pci_num_vf(dev->pdev);
        int err;
        int vf;
 
@@ -147,7 +147,7 @@ static int mlx5_sriov_enable(struct pci_dev *pdev, int num_vfs)
        err = pci_enable_sriov(pdev, num_vfs);
        if (err) {
                mlx5_core_warn(dev, "pci_enable_sriov failed : %d\n", err);
-               mlx5_device_disable_sriov(dev, true);
+               mlx5_device_disable_sriov(dev, num_vfs, true);
        }
        return err;
 }
@@ -155,9 +155,10 @@ static int mlx5_sriov_enable(struct pci_dev *pdev, int num_vfs)
 static void mlx5_sriov_disable(struct pci_dev *pdev)
 {
        struct mlx5_core_dev *dev  = pci_get_drvdata(pdev);
+       int num_vfs = pci_num_vf(dev->pdev);
 
        pci_disable_sriov(pdev);
-       mlx5_device_disable_sriov(dev, true);
+       mlx5_device_disable_sriov(dev, num_vfs, true);
 }
 
 int mlx5_core_sriov_configure(struct pci_dev *pdev, int num_vfs)
@@ -192,7 +193,7 @@ void mlx5_sriov_detach(struct mlx5_core_dev *dev)
        if (!mlx5_core_is_pf(dev))
                return;
 
-       mlx5_device_disable_sriov(dev, false);
+       mlx5_device_disable_sriov(dev, pci_num_vf(dev->pdev), false);
 }
 
 static u16 mlx5_get_max_vfs(struct mlx5_core_dev *dev)