Commit d886aba6 authored by Parav Pandit's avatar Parav Pandit Committed by Saeed Mahameed

net/mlx5: Reduce dependency on enabled_vfs counter and num_vfs

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: default avatarParav Pandit <parav@mellanox.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@mellanox.com>
parent 5ccf2770
...@@ -74,13 +74,6 @@ static int mlx5_device_enable_sriov(struct mlx5_core_dev *dev, int num_vfs) ...@@ -74,13 +74,6 @@ static int mlx5_device_enable_sriov(struct mlx5_core_dev *dev, int num_vfs)
int err; int err;
int vf; 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)) if (!MLX5_ESWITCH_MANAGER(dev))
goto enable_vfs_hca; goto enable_vfs_hca;
...@@ -99,7 +92,6 @@ static int mlx5_device_enable_sriov(struct mlx5_core_dev *dev, int num_vfs) ...@@ -99,7 +92,6 @@ static int mlx5_device_enable_sriov(struct mlx5_core_dev *dev, int num_vfs)
continue; continue;
} }
sriov->vfs_ctx[vf].enabled = 1; sriov->vfs_ctx[vf].enabled = 1;
sriov->enabled_vfs++;
if (MLX5_CAP_GEN(dev, port_type) == MLX5_CAP_PORT_TYPE_IB) { if (MLX5_CAP_GEN(dev, port_type) == MLX5_CAP_PORT_TYPE_IB) {
err = sriov_restore_guids(dev, vf); err = sriov_restore_guids(dev, vf);
if (err) { if (err) {
...@@ -118,13 +110,11 @@ static int mlx5_device_enable_sriov(struct mlx5_core_dev *dev, int num_vfs) ...@@ -118,13 +110,11 @@ static int mlx5_device_enable_sriov(struct mlx5_core_dev *dev, int num_vfs)
static void mlx5_device_disable_sriov(struct mlx5_core_dev *dev) static void mlx5_device_disable_sriov(struct mlx5_core_dev *dev)
{ {
struct mlx5_core_sriov *sriov = &dev->priv.sriov; struct mlx5_core_sriov *sriov = &dev->priv.sriov;
int num_vfs = pci_num_vf(dev->pdev);
int err; int err;
int vf; int vf;
if (!sriov->enabled_vfs) for (vf = num_vfs - 1; vf >= 0; vf--) {
goto out;
for (vf = 0; vf < sriov->num_vfs; vf++) {
if (!sriov->vfs_ctx[vf].enabled) if (!sriov->vfs_ctx[vf].enabled)
continue; continue;
err = mlx5_core_disable_hca(dev, vf + 1); err = mlx5_core_disable_hca(dev, vf + 1);
...@@ -133,10 +123,8 @@ static void mlx5_device_disable_sriov(struct mlx5_core_dev *dev) ...@@ -133,10 +123,8 @@ static void mlx5_device_disable_sriov(struct mlx5_core_dev *dev)
continue; continue;
} }
sriov->vfs_ctx[vf].enabled = 0; sriov->vfs_ctx[vf].enabled = 0;
sriov->enabled_vfs--;
} }
out:
if (MLX5_ESWITCH_MANAGER(dev)) if (MLX5_ESWITCH_MANAGER(dev))
mlx5_eswitch_disable_sriov(dev->priv.eswitch); mlx5_eswitch_disable_sriov(dev->priv.eswitch);
...@@ -191,13 +179,11 @@ int mlx5_core_sriov_configure(struct pci_dev *pdev, int num_vfs) ...@@ -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) int mlx5_sriov_attach(struct mlx5_core_dev *dev)
{ {
struct mlx5_core_sriov *sriov = &dev->priv.sriov; if (!mlx5_core_is_pf(dev) || !pci_num_vf(dev->pdev))
if (!mlx5_core_is_pf(dev) || !sriov->num_vfs)
return 0; return 0;
/* If sriov VFs exist in PCI level, enable them in device level */ /* 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) void mlx5_sriov_detach(struct mlx5_core_dev *dev)
......
...@@ -468,7 +468,6 @@ struct mlx5_vf_context { ...@@ -468,7 +468,6 @@ struct mlx5_vf_context {
struct mlx5_core_sriov { struct mlx5_core_sriov {
struct mlx5_vf_context *vfs_ctx; struct mlx5_vf_context *vfs_ctx;
int num_vfs; int num_vfs;
int enabled_vfs;
u16 max_vfs; u16 max_vfs;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment