net/mlx5: Reduce dependency on enabled_vfs counter and num_vfs
authorParav Pandit <parav@mellanox.com>
Fri, 28 Jun 2019 22:36:06 +0000 (22:36 +0000)
committerSaeed Mahameed <saeedm@mellanox.com>
Mon, 1 Jul 2019 23:40:30 +0000 (16:40 -0700)
While enabling SR-IOV, PCI core already checks that if SR-IOV is already
enabled, it returns failure error code.
Hence, remove such duplicate check from mlx5_core driver.

While at it, make mlx5_device_disable_sriov() to perform cleanup of VFs in
reverse order of mlx5_device_enable_sriov().

Signed-off-by: Parav Pandit <parav@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/net/ethernet/mellanox/mlx5/core/sriov.c
include/linux/mlx5/driver.h

index 2eecb831c4997adbebe5e8c091e0cba278d5ebab..9d9ff4511306344b35c83789d9dd2a471fb6e88e 100644 (file)
@@ -74,13 +74,6 @@ static int mlx5_device_enable_sriov(struct mlx5_core_dev *dev, int num_vfs)
        int err;
        int vf;
 
-       if (sriov->enabled_vfs) {
-               mlx5_core_warn(dev,
-                              "failed to enable SRIOV on device, already enabled with %d vfs\n",
-                              sriov->enabled_vfs);
-               return -EBUSY;
-       }
-
        if (!MLX5_ESWITCH_MANAGER(dev))
                goto enable_vfs_hca;
 
@@ -99,7 +92,6 @@ enable_vfs_hca:
                        continue;
                }
                sriov->vfs_ctx[vf].enabled = 1;
-               sriov->enabled_vfs++;
                if (MLX5_CAP_GEN(dev, port_type) == MLX5_CAP_PORT_TYPE_IB) {
                        err = sriov_restore_guids(dev, vf);
                        if (err) {
@@ -118,13 +110,11 @@ enable_vfs_hca:
 static void mlx5_device_disable_sriov(struct mlx5_core_dev *dev)
 {
        struct mlx5_core_sriov *sriov = &dev->priv.sriov;
+       int num_vfs = pci_num_vf(dev->pdev);
        int err;
        int vf;
 
-       if (!sriov->enabled_vfs)
-               goto out;
-
-       for (vf = 0; vf < sriov->num_vfs; vf++) {
+       for (vf = num_vfs - 1; vf >= 0; vf--) {
                if (!sriov->vfs_ctx[vf].enabled)
                        continue;
                err = mlx5_core_disable_hca(dev, vf + 1);
@@ -133,10 +123,8 @@ static void mlx5_device_disable_sriov(struct mlx5_core_dev *dev)
                        continue;
                }
                sriov->vfs_ctx[vf].enabled = 0;
-               sriov->enabled_vfs--;
        }
 
-out:
        if (MLX5_ESWITCH_MANAGER(dev))
                mlx5_eswitch_disable_sriov(dev->priv.eswitch);
 
@@ -191,13 +179,11 @@ int mlx5_core_sriov_configure(struct pci_dev *pdev, int num_vfs)
 
 int mlx5_sriov_attach(struct mlx5_core_dev *dev)
 {
-       struct mlx5_core_sriov *sriov = &dev->priv.sriov;
-
-       if (!mlx5_core_is_pf(dev) || !sriov->num_vfs)
+       if (!mlx5_core_is_pf(dev) || !pci_num_vf(dev->pdev))
                return 0;
 
        /* If sriov VFs exist in PCI level, enable them in device level */
-       return mlx5_device_enable_sriov(dev, sriov->num_vfs);
+       return mlx5_device_enable_sriov(dev, pci_num_vf(dev->pdev));
 }
 
 void mlx5_sriov_detach(struct mlx5_core_dev *dev)
index 155b8cbe1cc9fe603858fce32144d8f37af892ab..7658a490843123a769330712518c7012078316a4 100644 (file)
@@ -468,7 +468,6 @@ struct mlx5_vf_context {
 struct mlx5_core_sriov {
        struct mlx5_vf_context  *vfs_ctx;
        int                     num_vfs;
-       int                     enabled_vfs;
        u16                     max_vfs;
 };