Skip to content

Commit

Permalink
net/mlx5: Expose max possible SFs via devlink resource
Browse files Browse the repository at this point in the history
Introduce devlink resource for exposing max possible SFs on mlx5
devices.

For example:
$ devlink resource show pci/0000:00:0b.0
pci/0000:00:0b.0:
  name max_local_SFs size 5 unit entry dpipe_tables none
  name max_external_SFs size 0 unit entry dpipe_tables none

Signed-off-by: Shay Drory <shayd@nvidia.com>
Reviewed-by: Moshe Shemesh <moshe@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
  • Loading branch information
Shay Drory authored and Saeed Mahameed committed Aug 14, 2023
1 parent 53b836a commit 6486c0f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
8 changes: 8 additions & 0 deletions drivers/net/ethernet/mellanox/mlx5/core/devlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@

#include <net/devlink.h>

enum mlx5_devlink_resource_id {
MLX5_DL_RES_MAX_LOCAL_SFS = 1,
MLX5_DL_RES_MAX_EXTERNAL_SFS,

__MLX5_ID_RES_MAX,
MLX5_ID_RES_MAX = __MLX5_ID_RES_MAX - 1,
};

enum mlx5_devlink_param_id {
MLX5_DEVLINK_PARAM_ID_BASE = DEVLINK_PARAM_GENERIC_ID_MAX,
MLX5_DEVLINK_PARAM_ID_FLOW_STEERING_MODE,
Expand Down
44 changes: 40 additions & 4 deletions drivers/net/ethernet/mellanox/mlx5/core/sf/hw_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "mlx5_core.h"
#include "eswitch.h"
#include "diag/sf_tracepoint.h"
#include "devlink.h"

struct mlx5_sf_hw {
u32 usr_sfnum;
Expand Down Expand Up @@ -243,6 +244,32 @@ static void mlx5_sf_hw_table_hwc_cleanup(struct mlx5_sf_hwc_table *hwc)
kfree(hwc->sfs);
}

static void mlx5_sf_hw_table_res_unregister(struct mlx5_core_dev *dev)
{
devl_resources_unregister(priv_to_devlink(dev));
}

static int mlx5_sf_hw_table_res_register(struct mlx5_core_dev *dev, u16 max_fn,
u16 max_ext_fn)
{
struct devlink_resource_size_params size_params;
struct devlink *devlink = priv_to_devlink(dev);
int err;

devlink_resource_size_params_init(&size_params, max_fn, max_fn, 1,
DEVLINK_RESOURCE_UNIT_ENTRY);
err = devl_resource_register(devlink, "max_local_SFs", max_fn, MLX5_DL_RES_MAX_LOCAL_SFS,
DEVLINK_RESOURCE_ID_PARENT_TOP, &size_params);
if (err)
return err;

devlink_resource_size_params_init(&size_params, max_ext_fn, max_ext_fn, 1,
DEVLINK_RESOURCE_UNIT_ENTRY);
return devl_resource_register(devlink, "max_external_SFs", max_ext_fn,
MLX5_DL_RES_MAX_EXTERNAL_SFS, DEVLINK_RESOURCE_ID_PARENT_TOP,
&size_params);
}

int mlx5_sf_hw_table_init(struct mlx5_core_dev *dev)
{
struct mlx5_sf_hw_table *table;
Expand All @@ -262,12 +289,17 @@ int mlx5_sf_hw_table_init(struct mlx5_core_dev *dev)
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;

table = kzalloc(sizeof(*table), GFP_KERNEL);
if (!table)
return -ENOMEM;
if (!table) {
err = -ENOMEM;
goto alloc_err;
}

mutex_init(&table->table_lock);
table->dev = dev;
Expand All @@ -291,6 +323,8 @@ int mlx5_sf_hw_table_init(struct mlx5_core_dev *dev)
table_err:
mutex_destroy(&table->table_lock);
kfree(table);
alloc_err:
mlx5_sf_hw_table_res_unregister(dev);
return err;
}

Expand All @@ -299,12 +333,14 @@ void mlx5_sf_hw_table_cleanup(struct mlx5_core_dev *dev)
struct mlx5_sf_hw_table *table = dev->priv.sf_hw_table;

if (!table)
return;
goto res_unregister;

mutex_destroy(&table->table_lock);
mlx5_sf_hw_table_hwc_cleanup(&table->hwc[MLX5_SF_HWC_EXTERNAL]);
mlx5_sf_hw_table_hwc_cleanup(&table->hwc[MLX5_SF_HWC_LOCAL]);
mutex_destroy(&table->table_lock);
kfree(table);
res_unregister:
mlx5_sf_hw_table_res_unregister(dev);
}

static int mlx5_sf_hw_vhca_event(struct notifier_block *nb, unsigned long opcode, void *data)
Expand Down

0 comments on commit 6486c0f

Please sign in to comment.