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

Change-Id: I5ffb1e21843dfe1fef6ca86900a1e3d38a7fe0e5
---
 .../ethernet/mellanox/mlx5/core/sf/hw_table.c | 20 +++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

--- a/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
@@ -246,7 +246,13 @@ static void mlx5_sf_hw_table_hwc_cleanup
 
 static void mlx5_sf_hw_table_res_unregister(struct mlx5_core_dev *dev)
 {
+#ifdef HAVE_DEVL_RESOURCES_UNREGISTER
 	devl_resources_unregister(priv_to_devlink(dev));
+#elif defined(HAVE_DEVLINK_RESOURCES_UNREGISTER_1_PARAMS)
+	devlink_resources_unregister(priv_to_devlink(dev));
+#elif defined(HAVE_DEVLINK_RESOURCES_UNREGISTER_2_PARAMS)
+	devlink_resources_unregister(priv_to_devlink(dev), NULL);
+#endif
 }
 
 static int mlx5_sf_hw_table_res_register(struct mlx5_core_dev *dev, u16 max_fn,
@@ -258,16 +264,27 @@ static int mlx5_sf_hw_table_res_register
 
 	devlink_resource_size_params_init(&size_params, max_fn, max_fn, 1,
 					  DEVLINK_RESOURCE_UNIT_ENTRY);
+#ifdef HAVE_DEVL_RESOURCE_REGISTER
 	err = devl_resource_register(devlink, "max_local_SFs", max_fn, MLX5_DL_RES_MAX_LOCAL_SFS,
 				     DEVLINK_RESOURCE_ID_PARENT_TOP, &size_params);
+#else
+	err = devlink_resource_register(devlink, "max_local_SFs", max_fn, MLX5_DL_RES_MAX_LOCAL_SFS,
+				     DEVLINK_RESOURCE_ID_PARENT_TOP, &size_params);
+#endif
 	if (err)
 		return err;
 
 	devlink_resource_size_params_init(&size_params, max_ext_fn, max_ext_fn, 1,
 					  DEVLINK_RESOURCE_UNIT_ENTRY);
+#ifdef HAVE_DEVL_RESOURCE_REGISTER
 	return devl_resource_register(devlink, "max_external_SFs", max_ext_fn,
 				      MLX5_DL_RES_MAX_EXTERNAL_SFS, DEVLINK_RESOURCE_ID_PARENT_TOP,
 				      &size_params);
+#else
+	return devlink_resource_register(devlink, "max_external_SFs", max_ext_fn,
+				      MLX5_DL_RES_MAX_EXTERNAL_SFS, DEVLINK_RESOURCE_ID_PARENT_TOP,
+				      &size_params);
+#endif /* HAVE_DEVL_RESOURCE_REGISTER */
 }
 
 int mlx5_sf_hw_table_init(struct mlx5_core_dev *dev)
@@ -287,10 +304,8 @@ int mlx5_sf_hw_table_init(struct mlx5_co
 	err = mlx5_esw_sf_max_hpf_functions(dev, &max_ext_fn, &ext_base_id);
 	if (err)
 		return err;
-
 	if (mlx5_sf_hw_table_res_register(dev, max_fn, max_ext_fn))
 		mlx5_core_dbg(dev, "failed to register max SFs resources");
-
 	if (!max_fn && !max_ext_fn)
 		return 0;
 
@@ -340,6 +355,7 @@ void mlx5_sf_hw_table_cleanup(struct mlx
 	kfree(table);
 res_unregister:
 	mlx5_sf_hw_table_res_unregister(dev);
+	return;
 }
 
 static int mlx5_sf_hw_vhca_event(struct notifier_block *nb, unsigned long opcode, void *data)
