Skip to content

Commit

Permalink
mlxsw: spectrum: Fix handling of resource_size_param
Browse files Browse the repository at this point in the history
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: ef3116e ("mlxsw: spectrum: Register KVD resources with devlink")
Signed-off-by: Jiri Pirko <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
jpirko authored and davem330 committed Feb 28, 2018
1 parent 2ddc94c commit 77d2709
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 43 deletions.
75 changes: 38 additions & 37 deletions drivers/net/ethernet/mellanox/mlxsw/spectrum.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
18 changes: 15 additions & 3 deletions include/net/devlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions net/core/devlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 77d2709

Please sign in to comment.