Commit 77d27096 authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

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: ef3116e5 ("mlxsw: spectrum: Register KVD resources with devlink")
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 2ddc94c7
...@@ -4207,13 +4207,12 @@ static struct devlink_resource_ops mlxsw_sp_resource_kvd_hash_double_ops = { ...@@ -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, .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 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, u32 single_size_min = MLXSW_CORE_RES_GET(mlxsw_core,
KVD_SINGLE_MIN_SIZE); KVD_SINGLE_MIN_SIZE);
...@@ -4222,37 +4221,35 @@ mlxsw_sp_resource_size_params_prepare(struct mlxsw_core *mlxsw_core) ...@@ -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 kvd_size = MLXSW_CORE_RES_GET(mlxsw_core, KVD_SIZE);
u32 linear_size_min = 0; u32 linear_size_min = 0;
/* KVD top resource */ devlink_resource_size_params_init(kvd_size_params, kvd_size, kvd_size,
mlxsw_sp_kvd_size_params.size_min = kvd_size; MLXSW_SP_KVD_GRANULARITY,
mlxsw_sp_kvd_size_params.size_max = kvd_size; DEVLINK_RESOURCE_UNIT_ENTRY);
mlxsw_sp_kvd_size_params.size_granularity = MLXSW_SP_KVD_GRANULARITY; devlink_resource_size_params_init(linear_size_params, linear_size_min,
mlxsw_sp_kvd_size_params.unit = DEVLINK_RESOURCE_UNIT_ENTRY; kvd_size - single_size_min -
double_size_min,
/* Linear part init */ MLXSW_SP_KVD_GRANULARITY,
mlxsw_sp_linear_size_params.size_min = linear_size_min; DEVLINK_RESOURCE_UNIT_ENTRY);
mlxsw_sp_linear_size_params.size_max = kvd_size - single_size_min - devlink_resource_size_params_init(hash_double_size_params,
double_size_min; double_size_min,
mlxsw_sp_linear_size_params.size_granularity = MLXSW_SP_KVD_GRANULARITY; kvd_size - single_size_min -
mlxsw_sp_linear_size_params.unit = DEVLINK_RESOURCE_UNIT_ENTRY; linear_size_min,
MLXSW_SP_KVD_GRANULARITY,
/* Hash double part init */ DEVLINK_RESOURCE_UNIT_ENTRY);
mlxsw_sp_hash_double_size_params.size_min = double_size_min; devlink_resource_size_params_init(hash_single_size_params,
mlxsw_sp_hash_double_size_params.size_max = kvd_size - single_size_min - single_size_min,
linear_size_min; kvd_size - double_size_min -
mlxsw_sp_hash_double_size_params.size_granularity = MLXSW_SP_KVD_GRANULARITY; linear_size_min,
mlxsw_sp_hash_double_size_params.unit = DEVLINK_RESOURCE_UNIT_ENTRY; MLXSW_SP_KVD_GRANULARITY,
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;
} }
static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core) static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core)
{ {
struct devlink *devlink = priv_to_devlink(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; u32 kvd_size, single_size, double_size, linear_size;
const struct mlxsw_config_profile *profile; const struct mlxsw_config_profile *profile;
int err; int err;
...@@ -4261,13 +4258,17 @@ static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core) ...@@ -4261,13 +4258,17 @@ static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core)
if (!MLXSW_CORE_RES_VALID(mlxsw_core, KVD_SIZE)) if (!MLXSW_CORE_RES_VALID(mlxsw_core, KVD_SIZE))
return -EIO; 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); kvd_size = MLXSW_CORE_RES_GET(mlxsw_core, KVD_SIZE);
err = devlink_resource_register(devlink, MLXSW_SP_RESOURCE_NAME_KVD, err = devlink_resource_register(devlink, MLXSW_SP_RESOURCE_NAME_KVD,
true, kvd_size, true, kvd_size,
MLXSW_SP_RESOURCE_KVD, MLXSW_SP_RESOURCE_KVD,
DEVLINK_RESOURCE_ID_PARENT_TOP, DEVLINK_RESOURCE_ID_PARENT_TOP,
&mlxsw_sp_kvd_size_params, &kvd_size_params,
&mlxsw_sp_resource_kvd_ops); &mlxsw_sp_resource_kvd_ops);
if (err) if (err)
return err; return err;
...@@ -4277,7 +4278,7 @@ static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core) ...@@ -4277,7 +4278,7 @@ static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core)
false, linear_size, false, linear_size,
MLXSW_SP_RESOURCE_KVD_LINEAR, MLXSW_SP_RESOURCE_KVD_LINEAR,
MLXSW_SP_RESOURCE_KVD, MLXSW_SP_RESOURCE_KVD,
&mlxsw_sp_linear_size_params, &linear_size_params,
&mlxsw_sp_resource_kvd_linear_ops); &mlxsw_sp_resource_kvd_linear_ops);
if (err) if (err)
return err; return err;
...@@ -4291,7 +4292,7 @@ static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core) ...@@ -4291,7 +4292,7 @@ static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core)
false, double_size, false, double_size,
MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE, MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE,
MLXSW_SP_RESOURCE_KVD, MLXSW_SP_RESOURCE_KVD,
&mlxsw_sp_hash_double_size_params, &hash_double_size_params,
&mlxsw_sp_resource_kvd_hash_double_ops); &mlxsw_sp_resource_kvd_hash_double_ops);
if (err) if (err)
return err; return err;
...@@ -4301,7 +4302,7 @@ static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core) ...@@ -4301,7 +4302,7 @@ static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core)
false, single_size, false, single_size,
MLXSW_SP_RESOURCE_KVD_HASH_SINGLE, MLXSW_SP_RESOURCE_KVD_HASH_SINGLE,
MLXSW_SP_RESOURCE_KVD, MLXSW_SP_RESOURCE_KVD,
&mlxsw_sp_hash_single_size_params, &hash_single_size_params,
&mlxsw_sp_resource_kvd_hash_single_ops); &mlxsw_sp_resource_kvd_hash_single_ops);
if (err) if (err)
return err; return err;
......
...@@ -257,6 +257,18 @@ struct devlink_resource_size_params { ...@@ -257,6 +257,18 @@ struct devlink_resource_size_params {
enum devlink_resource_unit unit; 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 * struct devlink_resource - devlink resource
* @name: name of the resource * @name: name of the resource
...@@ -278,7 +290,7 @@ struct devlink_resource { ...@@ -278,7 +290,7 @@ struct devlink_resource {
u64 size_new; u64 size_new;
bool size_valid; bool size_valid;
struct devlink_resource *parent; 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 list;
struct list_head resource_list; struct list_head resource_list;
const struct devlink_resource_ops *resource_ops; const struct devlink_resource_ops *resource_ops;
...@@ -402,7 +414,7 @@ int devlink_resource_register(struct devlink *devlink, ...@@ -402,7 +414,7 @@ int devlink_resource_register(struct devlink *devlink,
u64 resource_size, u64 resource_size,
u64 resource_id, u64 resource_id,
u64 parent_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); const struct devlink_resource_ops *resource_ops);
void devlink_resources_unregister(struct devlink *devlink, void devlink_resources_unregister(struct devlink *devlink,
struct devlink_resource *resource); struct devlink_resource *resource);
...@@ -556,7 +568,7 @@ devlink_resource_register(struct devlink *devlink, ...@@ -556,7 +568,7 @@ devlink_resource_register(struct devlink *devlink,
u64 resource_size, u64 resource_size,
u64 resource_id, u64 resource_id,
u64 parent_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) const struct devlink_resource_ops *resource_ops)
{ {
return 0; return 0;
......
...@@ -2379,7 +2379,7 @@ devlink_resource_size_params_put(struct devlink_resource *resource, ...@@ -2379,7 +2379,7 @@ devlink_resource_size_params_put(struct devlink_resource *resource,
{ {
struct devlink_resource_size_params *size_params; 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, if (nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_SIZE_GRAN,
size_params->size_granularity, DEVLINK_ATTR_PAD) || size_params->size_granularity, DEVLINK_ATTR_PAD) ||
nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_SIZE_MAX, nla_put_u64_64bit(skb, DEVLINK_ATTR_RESOURCE_SIZE_MAX,
...@@ -3156,7 +3156,7 @@ int devlink_resource_register(struct devlink *devlink, ...@@ -3156,7 +3156,7 @@ int devlink_resource_register(struct devlink *devlink,
u64 resource_size, u64 resource_size,
u64 resource_id, u64 resource_id,
u64 parent_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) const struct devlink_resource_ops *resource_ops)
{ {
struct devlink_resource *resource; struct devlink_resource *resource;
...@@ -3199,7 +3199,8 @@ int devlink_resource_register(struct devlink *devlink, ...@@ -3199,7 +3199,8 @@ int devlink_resource_register(struct devlink *devlink,
resource->id = resource_id; resource->id = resource_id;
resource->resource_ops = resource_ops; resource->resource_ops = resource_ops;
resource->size_valid = true; 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); INIT_LIST_HEAD(&resource->resource_list);
list_add_tail(&resource->list, resource_list); list_add_tail(&resource->list, resource_list);
out: out:
......
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