net/mlx5: Simplify sriov enable/disable flow
authorParav Pandit <parav@mellanox.com>
Thu, 21 Mar 2019 22:51:28 +0000 (15:51 -0700)
committerSaeed Mahameed <saeedm@mellanox.com>
Fri, 22 Mar 2019 19:09:29 +0000 (12:09 -0700)
Simplify sriov enable/disable flow for below two checks.

1. PCI core driver allows sriov configuration only on a PF.
This is done in drivers/pci/pci-sysfs.c sriov_attrs_are_visible().

2. PCI core driver allow sriov enablement if the sriov is currently
disabled for for a PF. This is done in drivers/pci/pci-sysfs.c
sriov_numvfs_store().

Hence there is no need for mlx5 driver to duplicate such checks.

Signed-off-by: Parav Pandit <parav@mellanox.com>
Reviewed-by: Bodong Wang <bodong@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/net/ethernet/mellanox/mlx5/core/sriov.c

index 7b23fa8..105e652 100644 (file)
@@ -151,33 +151,10 @@ out:
                mlx5_core_warn(dev, "timeout reclaiming VFs pages\n");
 }
 
-static int mlx5_pci_enable_sriov(struct pci_dev *pdev, int num_vfs)
-{
-       struct mlx5_core_dev *dev  = pci_get_drvdata(pdev);
-       int err = 0;
-
-       if (pci_num_vf(pdev)) {
-               mlx5_core_warn(dev, "Unable to enable pci sriov, already enabled\n");
-               return -EBUSY;
-       }
-
-       err = pci_enable_sriov(pdev, num_vfs);
-       if (err)
-               mlx5_core_warn(dev, "pci_enable_sriov failed : %d\n", err);
-
-       return err;
-}
-
-static void mlx5_pci_disable_sriov(struct pci_dev *pdev)
-{
-       pci_disable_sriov(pdev);
-}
-
 static int mlx5_sriov_enable(struct pci_dev *pdev, int num_vfs)
 {
        struct mlx5_core_dev *dev  = pci_get_drvdata(pdev);
-       struct mlx5_core_sriov *sriov = &dev->priv.sriov;
-       int err = 0;
+       int err;
 
        err = mlx5_device_enable_sriov(dev, num_vfs);
        if (err) {
@@ -185,42 +162,37 @@ static int mlx5_sriov_enable(struct pci_dev *pdev, int num_vfs)
                return err;
        }
 
-       err = mlx5_pci_enable_sriov(pdev, num_vfs);
+       err = pci_enable_sriov(pdev, num_vfs);
        if (err) {
-               mlx5_core_warn(dev, "mlx5_pci_enable_sriov failed : %d\n", err);
+               mlx5_core_warn(dev, "pci_enable_sriov failed : %d\n", err);
                mlx5_device_disable_sriov(dev);
-               return err;
        }
-
-       sriov->num_vfs = num_vfs;
-
-       return 0;
+       return err;
 }
 
 static void mlx5_sriov_disable(struct pci_dev *pdev)
 {
        struct mlx5_core_dev *dev  = pci_get_drvdata(pdev);
-       struct mlx5_core_sriov *sriov = &dev->priv.sriov;
 
-       mlx5_pci_disable_sriov(pdev);
+       pci_disable_sriov(pdev);
        mlx5_device_disable_sriov(dev);
-       sriov->num_vfs = 0;
 }
 
 int mlx5_core_sriov_configure(struct pci_dev *pdev, int num_vfs)
 {
        struct mlx5_core_dev *dev  = pci_get_drvdata(pdev);
+       struct mlx5_core_sriov *sriov = &dev->priv.sriov;
        int err = 0;
 
        mlx5_core_dbg(dev, "requested num_vfs %d\n", num_vfs);
-       if (!mlx5_core_is_pf(dev))
-               return -EPERM;
 
        if (num_vfs)
                err = mlx5_sriov_enable(pdev, num_vfs);
        else
                mlx5_sriov_disable(pdev);
 
+       if (!err)
+               sriov->num_vfs = num_vfs;
        return err ? err : num_vfs;
 }