From: Valentine Fatiev <valentinef@nvidia.com>
Subject: [PATCH] BACKPORT: drivers/net/ethernet/mellanox/mlx5/core/sriov.c

Change-Id: I9cb7f2773cb0d44ab041fe1661c05d7e72a6bd85
---
 .../net/ethernet/mellanox/mlx5/core/sriov.c   | 32 +++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

--- a/drivers/net/ethernet/mellanox/mlx5/core/sriov.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/sriov.c
@@ -72,7 +72,10 @@ static int sriov_restore_guids(struct ml
 static int mlx5_device_enable_sriov(struct mlx5_core_dev *dev, int num_vfs)
 {
 	struct mlx5_core_sriov *sriov = &dev->priv.sriov;
-	int err, vf, num_msix_count;
+#ifdef HAVE_SRIOV_GET_SET_MSIX_VEC_COUNT
+	int num_msix_count;
+#endif
+	int err, vf;
 
 	if (!MLX5_ESWITCH_MANAGER(dev))
 		goto enable_vfs_hca;
@@ -94,8 +97,9 @@ enable_vfs_hca:
 #endif
 		return err;
 	}
-
+#ifdef HAVE_SRIOV_GET_SET_MSIX_VEC_COUNT
 	num_msix_count = mlx5_get_default_msix_vec_count(dev, num_vfs);
+#endif
 	for (vf = 0; vf < num_vfs; vf++) {
 		err = mlx5_core_enable_hca(dev, vf + 1);
 		if (err) {
@@ -103,6 +107,7 @@ enable_vfs_hca:
 			continue;
 		}
 
+#ifdef HAVE_SRIOV_GET_SET_MSIX_VEC_COUNT
 		err = mlx5_set_msix_vec_count(dev, vf + 1, num_msix_count);
 		if (err) {
 			mlx5_core_warn(dev,
@@ -110,6 +115,7 @@ enable_vfs_hca:
 				       vf, err);
 			continue;
 		}
+#endif
 
 		sriov->vfs_ctx[vf].enabled = 1;
 		if (MLX5_CAP_GEN(dev, port_type) == MLX5_CAP_PORT_TYPE_IB) {
@@ -156,6 +162,9 @@ mlx5_device_disable_sriov(struct mlx5_co
 static int mlx5_sriov_enable(struct pci_dev *pdev, int num_vfs)
 {
 	struct mlx5_core_dev *dev  = pci_get_drvdata(pdev);
+#ifdef HAVE_DEVL_TRAP_GROUPS_REGISTER //forward port
+	struct devlink *devlink = priv_to_devlink(dev);
+#endif
 	int err;
 
 	if (num_vfs && pci_num_vf(dev->pdev)) {
@@ -168,7 +177,13 @@ static int mlx5_sriov_enable(struct pci_
 		return -EBUSY;
 	}
 
+#ifdef HAVE_DEVL_TRAP_GROUPS_REGISTER //forward port
+	devl_lock(devlink);
+#endif
 	err = mlx5_device_enable_sriov(dev, num_vfs);
+#ifdef HAVE_DEVL_TRAP_GROUPS_REGISTER //forward port
+	devl_unlock(devlink);
+#endif
 	if (err) {
 		mlx5_core_warn(dev, "mlx5_device_enable_sriov failed : %d\n", err);
 		return err;
@@ -185,10 +200,19 @@ static int mlx5_sriov_enable(struct pci_
 static void mlx5_sriov_disable(struct pci_dev *pdev)
 {
 	struct mlx5_core_dev *dev  = pci_get_drvdata(pdev);
+#ifdef HAVE_DEVL_TRAP_GROUPS_REGISTER //forward port
+	struct devlink *devlink = priv_to_devlink(dev);
+#endif
 	int num_vfs = pci_num_vf(dev->pdev);
 
 	pci_disable_sriov(pdev);
+#ifdef HAVE_DEVL_TRAP_GROUPS_REGISTER //forward port
+	devl_lock(devlink);
+#endif
 	mlx5_device_disable_sriov(dev, num_vfs, true);
+#ifdef HAVE_DEVL_TRAP_GROUPS_REGISTER //forward port
+	devl_unlock(devlink);
+#endif
 }
 
 int mlx5_core_sriov_configure(struct pci_dev *pdev, int num_vfs)
@@ -209,6 +233,7 @@ int mlx5_core_sriov_configure(struct pci
 	return err ? err : num_vfs;
 }
 
+#ifdef HAVE_SRIOV_GET_SET_MSIX_VEC_COUNT
 int mlx5_core_sriov_set_msix_vec_count(struct pci_dev *vf, int msix_vec_count)
 {
 	struct pci_dev *pf = pci_physfn(vf);
@@ -236,6 +261,7 @@ int mlx5_core_sriov_set_msix_vec_count(s
 
 		if (vf->devfn == pci_iov_virtfn_devfn(pf, id))
 			break;
+
 	}
 
 	if (id == pci_num_vf(pf) || !sriov->vfs_ctx[id].enabled)
@@ -243,6 +269,7 @@ int mlx5_core_sriov_set_msix_vec_count(s
 
 	return mlx5_set_msix_vec_count(dev, id + 1, msix_vec_count);
 }
+#endif
 
 int mlx5_sriov_attach(struct mlx5_core_dev *dev)
 {
@@ -296,6 +323,7 @@ int mlx5_sriov_init(struct mlx5_core_dev
 		return 0;
 
 	total_vfs = pci_sriov_get_totalvfs(pdev);
+
 	sriov->max_vfs = mlx5_get_max_vfs(dev);
 	sriov->num_vfs = pci_num_vf(pdev);
 	sriov->vfs_ctx = kcalloc(total_vfs, sizeof(*sriov->vfs_ctx), GFP_KERNEL);
