Commit 74d6786c authored by Ido Schimmel's avatar Ido Schimmel Committed by Jakub Kicinski

mlxsw: spectrum_port_range: Add devlink resource support

Expose via devlink-resource the maximum number of port range registers
and their current occupancy. Besides the observability benefits, this
resource will be used by subsequent patches for scale and occupancy
tests.
Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
Reviewed-by: default avatarPetr Machata <petrm@nvidia.com>
Signed-off-by: default avatarPetr Machata <petrm@nvidia.com>
Link: https://lore.kernel.org/r/7945e0c715dc5efb1617f45f7560c1f1bd0bcf8a.1689092769.git.petrm@nvidia.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent b3eb04be
......@@ -3739,6 +3739,26 @@ static int mlxsw_sp_resources_rifs_register(struct mlxsw_core *mlxsw_core)
&size_params);
}
static int
mlxsw_sp_resources_port_range_register(struct mlxsw_core *mlxsw_core)
{
struct devlink *devlink = priv_to_devlink(mlxsw_core);
struct devlink_resource_size_params size_params;
u64 max;
if (!MLXSW_CORE_RES_VALID(mlxsw_core, ACL_MAX_L4_PORT_RANGE))
return -EIO;
max = MLXSW_CORE_RES_GET(mlxsw_core, ACL_MAX_L4_PORT_RANGE);
devlink_resource_size_params_init(&size_params, max, max, 1,
DEVLINK_RESOURCE_UNIT_ENTRY);
return devl_resource_register(devlink, "port_range_registers", max,
MLXSW_SP_RESOURCE_PORT_RANGE_REGISTERS,
DEVLINK_RESOURCE_ID_PARENT_TOP,
&size_params);
}
static int mlxsw_sp1_resources_register(struct mlxsw_core *mlxsw_core)
{
int err;
......@@ -3767,8 +3787,13 @@ static int mlxsw_sp1_resources_register(struct mlxsw_core *mlxsw_core)
if (err)
goto err_resources_rifs_register;
err = mlxsw_sp_resources_port_range_register(mlxsw_core);
if (err)
goto err_resources_port_range_register;
return 0;
err_resources_port_range_register:
err_resources_rifs_register:
err_resources_rif_mac_profile_register:
err_policer_resources_register:
......@@ -3806,8 +3831,13 @@ static int mlxsw_sp2_resources_register(struct mlxsw_core *mlxsw_core)
if (err)
goto err_resources_rifs_register;
err = mlxsw_sp_resources_port_range_register(mlxsw_core);
if (err)
goto err_resources_port_range_register;
return 0;
err_resources_port_range_register:
err_resources_rifs_register:
err_resources_rif_mac_profile_register:
err_policer_resources_register:
......
......@@ -69,6 +69,7 @@ enum mlxsw_sp_resource_id {
MLXSW_SP_RESOURCE_SINGLE_RATE_POLICERS,
MLXSW_SP_RESOURCE_RIF_MAC_PROFILES,
MLXSW_SP_RESOURCE_RIFS,
MLXSW_SP_RESOURCE_PORT_RANGE_REGISTERS,
};
struct mlxsw_sp_port;
......
......@@ -5,6 +5,7 @@
#include <linux/netlink.h>
#include <linux/refcount.h>
#include <linux/xarray.h>
#include <net/devlink.h>
#include "spectrum.h"
......@@ -17,6 +18,7 @@ struct mlxsw_sp_port_range_reg {
struct mlxsw_sp_port_range_core {
struct xarray prr_xa;
struct xa_limit prr_ids;
atomic_t prr_count;
};
static int
......@@ -71,6 +73,8 @@ mlxsw_sp_port_range_reg_create(struct mlxsw_sp *mlxsw_sp,
goto err_reg_configure;
}
atomic_inc(&pr_core->prr_count);
return prr;
err_reg_configure:
......@@ -85,6 +89,7 @@ static void mlxsw_sp_port_range_reg_destroy(struct mlxsw_sp *mlxsw_sp,
{
struct mlxsw_sp_port_range_core *pr_core = mlxsw_sp->pr_core;
atomic_dec(&pr_core->prr_count);
xa_erase(&pr_core->prr_xa, prr->index);
kfree(prr);
}
......@@ -145,6 +150,13 @@ void mlxsw_sp_port_range_reg_put(struct mlxsw_sp *mlxsw_sp, u8 prr_index)
mlxsw_sp_port_range_reg_destroy(mlxsw_sp, prr);
}
static u64 mlxsw_sp_port_range_reg_occ_get(void *priv)
{
struct mlxsw_sp_port_range_core *pr_core = priv;
return atomic_read(&pr_core->prr_count);
}
int mlxsw_sp_port_range_init(struct mlxsw_sp *mlxsw_sp)
{
struct mlxsw_sp_port_range_core *pr_core;
......@@ -168,6 +180,11 @@ int mlxsw_sp_port_range_init(struct mlxsw_sp *mlxsw_sp)
pr_core->prr_ids.max = max - 1;
xa_init_flags(&pr_core->prr_xa, XA_FLAGS_ALLOC);
devl_resource_occ_get_register(priv_to_devlink(core),
MLXSW_SP_RESOURCE_PORT_RANGE_REGISTERS,
mlxsw_sp_port_range_reg_occ_get,
pr_core);
return 0;
}
......@@ -175,6 +192,8 @@ void mlxsw_sp_port_range_fini(struct mlxsw_sp *mlxsw_sp)
{
struct mlxsw_sp_port_range_core *pr_core = mlxsw_sp->pr_core;
devl_resource_occ_get_unregister(priv_to_devlink(mlxsw_sp->core),
MLXSW_SP_RESOURCE_PORT_RANGE_REGISTERS);
WARN_ON(!xa_empty(&pr_core->prr_xa));
xa_destroy(&pr_core->prr_xa);
kfree(pr_core);
......
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