mirror of
https://github.com/torvalds/linux.git
synced 2024-11-10 22:21:40 +00:00
mlxsw: spectrum: Fix handling of resource_size_param
Current code uses global variables, adjusts them and passes pointer down
to devlink. With every other mlxsw_core instance, the previously passed
pointer values are rewritten. Fix this by de-globalize the variables and
also memcpy size_params during devlink resource registration.
Also, introduce a convenient size_param_init helper.
Fixes: ef3116e540
("mlxsw: spectrum: Register KVD resources with devlink")
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
2ddc94c76c
commit
77d270967c
@ -4207,13 +4207,12 @@ static struct devlink_resource_ops mlxsw_sp_resource_kvd_hash_double_ops = {
|
||||
.size_validate = mlxsw_sp_resource_kvd_hash_double_size_validate,
|
||||
};
|
||||
|
||||
static struct devlink_resource_size_params mlxsw_sp_kvd_size_params;
|
||||
static struct devlink_resource_size_params mlxsw_sp_linear_size_params;
|
||||
static struct devlink_resource_size_params mlxsw_sp_hash_single_size_params;
|
||||
static struct devlink_resource_size_params mlxsw_sp_hash_double_size_params;
|
||||
|
||||
static void
|
||||
mlxsw_sp_resource_size_params_prepare(struct mlxsw_core *mlxsw_core)
|
||||
mlxsw_sp_resource_size_params_prepare(struct mlxsw_core *mlxsw_core,
|
||||
struct devlink_resource_size_params *kvd_size_params,
|
||||
struct devlink_resource_size_params *linear_size_params,
|
||||
struct devlink_resource_size_params *hash_double_size_params,
|
||||
struct devlink_resource_size_params *hash_single_size_params)
|
||||
{
|
||||
u32 single_size_min = MLXSW_CORE_RES_GET(mlxsw_core,
|
||||
KVD_SINGLE_MIN_SIZE);
|
||||
@ -4222,37 +4221,35 @@ mlxsw_sp_resource_size_params_prepare(struct mlxsw_core *mlxsw_core)
|
||||
u32 kvd_size = MLXSW_CORE_RES_GET(mlxsw_core, KVD_SIZE);
|
||||
u32 linear_size_min = 0;
|
||||
|
||||
/* KVD top resource */
|
||||
mlxsw_sp_kvd_size_params.size_min = kvd_size;
|
||||
mlxsw_sp_kvd_size_params.size_max = kvd_size;
|
||||
mlxsw_sp_kvd_size_params.size_granularity = MLXSW_SP_KVD_GRANULARITY;
|
||||
mlxsw_sp_kvd_size_params.unit = DEVLINK_RESOURCE_UNIT_ENTRY;
|
||||
|
||||
/* Linear part init */
|
||||
mlxsw_sp_linear_size_params.size_min = linear_size_min;
|
||||
mlxsw_sp_linear_size_params.size_max = kvd_size - single_size_min -
|
||||
double_size_min;
|
||||
mlxsw_sp_linear_size_params.size_granularity = MLXSW_SP_KVD_GRANULARITY;
|
||||
mlxsw_sp_linear_size_params.unit = DEVLINK_RESOURCE_UNIT_ENTRY;
|
||||
|
||||
/* Hash double part init */
|
||||
mlxsw_sp_hash_double_size_params.size_min = double_size_min;
|
||||
mlxsw_sp_hash_double_size_params.size_max = kvd_size - single_size_min -
|
||||
linear_size_min;
|
||||
mlxsw_sp_hash_double_size_params.size_granularity = MLXSW_SP_KVD_GRANULARITY;
|
||||
mlxsw_sp_hash_double_size_params.unit = DEVLINK_RESOURCE_UNIT_ENTRY;
|
||||
|
||||
/* Hash single part init */
|
||||
mlxsw_sp_hash_single_size_params.size_min = single_size_min;
|
||||
mlxsw_sp_hash_single_size_params.size_max = kvd_size - double_size_min -
|
||||
linear_size_min;
|
||||
mlxsw_sp_hash_single_size_params.size_granularity = MLXSW_SP_KVD_GRANULARITY;
|
||||
mlxsw_sp_hash_single_size_params.unit = DEVLINK_RESOURCE_UNIT_ENTRY;
|
||||
devlink_resource_size_params_init(kvd_size_params, kvd_size, kvd_size,
|
||||
MLXSW_SP_KVD_GRANULARITY,
|
||||
DEVLINK_RESOURCE_UNIT_ENTRY);
|
||||
devlink_resource_size_params_init(linear_size_params, linear_size_min,
|
||||
kvd_size - single_size_min -
|
||||
double_size_min,
|
||||
MLXSW_SP_KVD_GRANULARITY,
|
||||
DEVLINK_RESOURCE_UNIT_ENTRY);
|
||||
devlink_resource_size_params_init(hash_double_size_params,
|
||||
double_size_min,
|
||||
kvd_size - single_size_min -
|
||||
linear_size_min,
|
||||
MLXSW_SP_KVD_GRANULARITY,
|
||||
DEVLINK_RESOURCE_UNIT_ENTRY);
|
||||
devlink_resource_size_params_init(hash_single_size_params,
|
||||
single_size_min,
|
||||
kvd_size - double_size_min -
|
||||
linear_size_min,
|
||||
MLXSW_SP_KVD_GRANULARITY,
|
||||
DEVLINK_RESOURCE_UNIT_ENTRY);
|
||||
}
|
||||
|
||||
static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core)
|
||||
{
|
||||
struct devlink *devlink = priv_to_devlink(mlxsw_core);
|
||||
struct devlink_resource_size_params hash_single_size_params;
|
||||
struct devlink_resource_size_params hash_double_size_params;
|
||||
struct devlink_resource_size_params linear_size_params;
|
||||
struct devlink_resource_size_params kvd_size_params;
|
||||
u32 kvd_size, single_size, double_size, linear_size;
|
||||
const struct mlxsw_config_profile *profile;
|
||||
int err;
|
||||
@ -4261,13 +4258,17 @@ static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core)
|
||||
if (!MLXSW_CORE_RES_VALID(mlxsw_core, KVD_SIZE))
|
||||
return -EIO;
|
||||
|
||||
mlxsw_sp_resource_size_params_prepare(mlxsw_core);
|
||||
mlxsw_sp_resource_size_params_prepare(mlxsw_core, &kvd_size_params,
|
||||
&linear_size_params,
|
||||
&hash_double_size_params,
|
||||
&hash_single_size_params);
|
||||
|
||||
kvd_size = MLXSW_CORE_RES_GET(mlxsw_core, KVD_SIZE);
|
||||
err = devlink_resource_register(devlink, MLXSW_SP_RESOURCE_NAME_KVD,
|
||||
true, kvd_size,
|
||||
MLXSW_SP_RESOURCE_KVD,
|
||||
DEVLINK_RESOURCE_ID_PARENT_TOP,
|
||||
&mlxsw_sp_kvd_size_params,
|
||||
&kvd_size_params,
|
||||
&mlxsw_sp_resource_kvd_ops);
|
||||
if (err)
|
||||
return err;
|
||||
@ -4277,7 +4278,7 @@ static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core)
|
||||
false, linear_size,
|
||||
MLXSW_SP_RESOURCE_KVD_LINEAR,
|
||||
MLXSW_SP_RESOURCE_KVD,
|
||||
&mlxsw_sp_linear_size_params,
|
||||
&linear_size_params,
|
||||
&mlxsw_sp_resource_kvd_linear_ops);
|
||||
if (err)
|
||||
return err;
|
||||
@ -4291,7 +4292,7 @@ static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core)
|
||||
false, double_size,
|
||||
MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE,
|
||||
MLXSW_SP_RESOURCE_KVD,
|
||||
&mlxsw_sp_hash_double_size_params,
|
||||
&hash_double_size_params,
|
||||
&mlxsw_sp_resource_kvd_hash_double_ops);
|
||||
if (err)
|
||||
return err;
|
||||
@ -4301,7 +4302,7 @@ static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core)
|
||||
false, single_size,
|
||||
MLXSW_SP_RESOURCE_KVD_HASH_SINGLE,
|
||||
MLXSW_SP_RESOURCE_KVD,
|
||||
&mlxsw_sp_hash_single_size_params,
|
||||
&hash_single_size_params,
|
||||
&mlxsw_sp_resource_kvd_hash_single_ops);
|
||||
if (err)
|
||||
return err;
|
||||
|
@ -257,6 +257,18 @@ struct devlink_resource_size_params {
|
||||
enum devlink_resource_unit unit;
|
||||
};
|
||||
|
||||
static inline void
|
||||
devlink_resource_size_params_init(struct devlink_resource_size_params *size_params,
|
||||
u64 size_min, u64 size_max,
|
||||
u64 size_granularity,
|
||||
enum devlink_resource_unit unit)
|
||||
{
|
||||
size_params->size_min = size_min;
|
||||
size_params->size_max = size_max;
|
||||
size_params->size_granularity = size_granularity;
|
||||
size_params->unit = unit;
|
||||
}
|
||||
|
||||
/**
|
||||
* struct devlink_resource - devlink resource
|
||||
* @name: name of the resource
|
||||
@ -278,7 +290,7 @@ struct devlink_resource {
|
||||
u64 size_new;
|
||||
bool size_valid;
|
||||
struct devlink_resource *parent;
|
||||
struct devlink_resource_size_params *size_params;
|
||||
struct devlink_resource_size_params size_params;
|
||||
struct list_head list;
|
||||
struct list_head resource_list;
|
||||
const struct devlink_resource_ops *resource_ops;
|
||||
@ -402,7 +414,7 @@ int devlink_resource_register(struct devlink *devlink,
|
||||
u64 resource_size,
|
||||
u64 resource_id,
|
||||
u64 parent_resource_id,
|
||||
struct devlink_resource_size_params *size_params,
|
||||
const struct devlink_resource_size_params *size_params,
|
||||
const struct devlink_resource_ops *resource_ops);
|
||||
void devlink_resources_unregister(struct devlink *devlink,
|
||||
struct devlink_resource *resource);
|
||||
@ -556,7 +568,7 @@ devlink_resource_register(struct devlink *devlink,
|
||||
u64 resource_size,
|
||||
u64 resource_id,
|
||||
u64 parent_resource_id,
|
||||
struct devlink_resource_size_params *size_params,
|
||||
const struct devlink_resource_size_params *size_params,
|
||||
const struct devlink_resource_ops *resource_ops)
|
||||
{
|
||||
return 0;
|
||||
|
@ -2379,7 +2379,7 @@ devlink_resource_size_params_put(struct devlink_resource *resource,
|
||||
{
|
||||
struct devlink_resource_size_params *size_params;
|
||||
|
||||
size_params = resource->size_params;
|
||||
size_params = &resource->size_params;
|
||||
if (nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_SIZE_GRAN,
|
||||
size_params->size_granularity, DEVLINK_ATTR_PAD) ||
|
||||
nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_SIZE_MAX,
|
||||
@ -3156,7 +3156,7 @@ int devlink_resource_register(struct devlink *devlink,
|
||||
u64 resource_size,
|
||||
u64 resource_id,
|
||||
u64 parent_resource_id,
|
||||
struct devlink_resource_size_params *size_params,
|
||||
const struct devlink_resource_size_params *size_params,
|
||||
const struct devlink_resource_ops *resource_ops)
|
||||
{
|
||||
struct devlink_resource *resource;
|
||||
@ -3199,7 +3199,8 @@ int devlink_resource_register(struct devlink *devlink,
|
||||
resource->id = resource_id;
|
||||
resource->resource_ops = resource_ops;
|
||||
resource->size_valid = true;
|
||||
resource->size_params = size_params;
|
||||
memcpy(&resource->size_params, size_params,
|
||||
sizeof(resource->size_params));
|
||||
INIT_LIST_HEAD(&resource->resource_list);
|
||||
list_add_tail(&resource->list, resource_list);
|
||||
out:
|
||||
|
Loading…
Reference in New Issue
Block a user