summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorMohamad Haj Yahia <mohamad@mellanox.com>2016-09-09 17:35:21 +0300
committerDavid S. Miller <davem@davemloft.net>2016-09-11 07:21:49 +0300
commitacab721b5d8d9431cc80acc827973eeeda4dec24 (patch)
tree1434b33b18b88759f14b6aabd44a3df88d7249ac /drivers
parent59211bd3b6329c3e5f4a90ac3d7f87ffa7867073 (diff)
downloadlinux-acab721b5d8d9431cc80acc827973eeeda4dec24.tar.xz
net/mlx5: Implement SRIOV attach/detach flows
Needed for lightweight and modular internal/pci error handling. Implement sriov attach function which enables pre-saved number of vfs on the device side. Implement sriov detach function which disable the current vfs on the device side. Init/cleanup function only handles sriov software context allocation and destruction. Signed-off-by: Mohamad Haj Yahia <mohamad@mellanox.com> Signed-off-by: Saeed Mahameed <saeedm@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h2
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/sriov.c29
2 files changed, 23 insertions, 8 deletions
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h b/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h
index 7dd14cf73181..04b719a53313 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h
@@ -91,6 +91,8 @@ void mlx5_enter_error_state(struct mlx5_core_dev *dev);
void mlx5_disable_device(struct mlx5_core_dev *dev);
int mlx5_sriov_init(struct mlx5_core_dev *dev);
void mlx5_sriov_cleanup(struct mlx5_core_dev *dev);
+int mlx5_sriov_attach(struct mlx5_core_dev *dev);
+void mlx5_sriov_detach(struct mlx5_core_dev *dev);
int mlx5_core_sriov_configure(struct pci_dev *dev, int num_vfs);
bool mlx5_sriov_is_enabled(struct mlx5_core_dev *dev);
int mlx5_core_enable_hca(struct mlx5_core_dev *dev, u16 func_id);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sriov.c b/drivers/net/ethernet/mellanox/mlx5/core/sriov.c
index 72a8215a2d02..f4f02b64f552 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/sriov.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/sriov.c
@@ -188,6 +188,25 @@ int mlx5_core_sriov_configure(struct pci_dev *pdev, int num_vfs)
return err ? err : 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)
+ return 0;
+
+ /* If sriov VFs exist in PCI level, enable them in device level */
+ return mlx5_device_enable_sriov(dev, sriov->num_vfs);
+}
+
+void mlx5_sriov_detach(struct mlx5_core_dev *dev)
+{
+ if (!mlx5_core_is_pf(dev))
+ return;
+
+ mlx5_device_disable_sriov(dev);
+}
+
int mlx5_sriov_init(struct mlx5_core_dev *dev)
{
struct mlx5_core_sriov *sriov = &dev->priv.sriov;
@@ -203,12 +222,7 @@ int mlx5_sriov_init(struct mlx5_core_dev *dev)
if (!sriov->vfs_ctx)
return -ENOMEM;
- /* If sriov VFs exist in PCI level, enable them in device level */
- if (!sriov->num_vfs)
- return 0;
-
- mlx5_device_enable_sriov(dev, sriov->num_vfs);
- return 0;
+ return mlx5_sriov_attach(dev);
}
void mlx5_sriov_cleanup(struct mlx5_core_dev *dev)
@@ -217,7 +231,6 @@ void mlx5_sriov_cleanup(struct mlx5_core_dev *dev)
if (!mlx5_core_is_pf(dev))
return;
-
- mlx5_device_disable_sriov(dev);
+ mlx5_sriov_detach(dev);
kfree(sriov->vfs_ctx);
}