Skip to content

Commit

Permalink
Merge branch 'net-Expose-KVD-linear-parts-as-resources'
Browse files Browse the repository at this point in the history
Jiri Pirko says:

====================
net: Expose KVD linear parts as resources

Arkadi says:

Expose the KVD linear partitions via the devlink resource interface. This
will give the user the ability to control the linear memory division.

---
v1->v2:
- patch1:
 - fixed u64 division error reported by kbuildbot
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Feb 20, 2018
2 parents b99fe0e + 7f47b19 commit a38bbe7
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 97 deletions.
87 changes: 7 additions & 80 deletions drivers/net/ethernet/mellanox/mlxsw/spectrum.c
Original file line number Diff line number Diff line change
Expand Up @@ -3798,70 +3798,6 @@ static const struct mlxsw_config_profile mlxsw_sp_config_profile = {
.resource_query_enable = 1,
};

static bool
mlxsw_sp_resource_kvd_granularity_validate(struct netlink_ext_ack *extack,
u64 size)
{
const struct mlxsw_config_profile *profile;

profile = &mlxsw_sp_config_profile;
if (size % profile->kvd_hash_granularity) {
NL_SET_ERR_MSG_MOD(extack, "resource set with wrong granularity");
return false;
}
return true;
}

static int
mlxsw_sp_resource_kvd_size_validate(struct devlink *devlink, u64 size,
struct netlink_ext_ack *extack)
{
NL_SET_ERR_MSG_MOD(extack, "kvd size cannot be changed");
return -EINVAL;
}

static int
mlxsw_sp_resource_kvd_linear_size_validate(struct devlink *devlink, u64 size,
struct netlink_ext_ack *extack)
{
if (!mlxsw_sp_resource_kvd_granularity_validate(extack, size))
return -EINVAL;

return 0;
}

static int
mlxsw_sp_resource_kvd_hash_single_size_validate(struct devlink *devlink, u64 size,
struct netlink_ext_ack *extack)
{
struct mlxsw_core *mlxsw_core = devlink_priv(devlink);

if (!mlxsw_sp_resource_kvd_granularity_validate(extack, size))
return -EINVAL;

if (size < MLXSW_CORE_RES_GET(mlxsw_core, KVD_SINGLE_MIN_SIZE)) {
NL_SET_ERR_MSG_MOD(extack, "hash single size is smaller than minimum");
return -EINVAL;
}
return 0;
}

static int
mlxsw_sp_resource_kvd_hash_double_size_validate(struct devlink *devlink, u64 size,
struct netlink_ext_ack *extack)
{
struct mlxsw_core *mlxsw_core = devlink_priv(devlink);

if (!mlxsw_sp_resource_kvd_granularity_validate(extack, size))
return -EINVAL;

if (size < MLXSW_CORE_RES_GET(mlxsw_core, KVD_DOUBLE_MIN_SIZE)) {
NL_SET_ERR_MSG_MOD(extack, "hash double size is smaller than minimum");
return -EINVAL;
}
return 0;
}

static u64 mlxsw_sp_resource_kvd_linear_occ_get(struct devlink *devlink)
{
struct mlxsw_core *mlxsw_core = devlink_priv(devlink);
Expand All @@ -3870,23 +3806,10 @@ static u64 mlxsw_sp_resource_kvd_linear_occ_get(struct devlink *devlink)
return mlxsw_sp_kvdl_occ_get(mlxsw_sp);
}

static struct devlink_resource_ops mlxsw_sp_resource_kvd_ops = {
.size_validate = mlxsw_sp_resource_kvd_size_validate,
};

static struct devlink_resource_ops mlxsw_sp_resource_kvd_linear_ops = {
.size_validate = mlxsw_sp_resource_kvd_linear_size_validate,
.occ_get = mlxsw_sp_resource_kvd_linear_occ_get,
};

static struct devlink_resource_ops mlxsw_sp_resource_kvd_hash_single_ops = {
.size_validate = mlxsw_sp_resource_kvd_hash_single_size_validate,
};

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;
Expand Down Expand Up @@ -3948,7 +3871,7 @@ static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core)
MLXSW_SP_RESOURCE_KVD,
DEVLINK_RESOURCE_ID_PARENT_TOP,
&mlxsw_sp_kvd_size_params,
&mlxsw_sp_resource_kvd_ops);
NULL);
if (err)
return err;

Expand All @@ -3962,6 +3885,10 @@ static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core)
if (err)
return err;

err = mlxsw_sp_kvdl_resources_register(devlink);
if (err)
return err;

double_size = kvd_size - linear_size;
double_size *= profile->kvd_hash_double_parts;
double_size /= profile->kvd_hash_double_parts +
Expand All @@ -3972,7 +3899,7 @@ static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core)
MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE,
MLXSW_SP_RESOURCE_KVD,
&mlxsw_sp_hash_double_size_params,
&mlxsw_sp_resource_kvd_hash_double_ops);
NULL);
if (err)
return err;

Expand All @@ -3982,7 +3909,7 @@ static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core)
MLXSW_SP_RESOURCE_KVD_HASH_SINGLE,
MLXSW_SP_RESOURCE_KVD,
&mlxsw_sp_hash_single_size_params,
&mlxsw_sp_resource_kvd_hash_single_ops);
NULL);
if (err)
return err;

Expand Down
7 changes: 7 additions & 0 deletions drivers/net/ethernet/mellanox/mlxsw/spectrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,18 @@
#define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR "linear"
#define MLXSW_SP_RESOURCE_NAME_KVD_HASH_SINGLE "hash_single"
#define MLXSW_SP_RESOURCE_NAME_KVD_HASH_DOUBLE "hash_double"
#define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_SINGLES "singles"
#define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_CHUNKS "chunks"
#define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR_LARGE_CHUNKS "large_chunks"

enum mlxsw_sp_resource_id {
MLXSW_SP_RESOURCE_KVD,
MLXSW_SP_RESOURCE_KVD_LINEAR,
MLXSW_SP_RESOURCE_KVD_HASH_SINGLE,
MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE,
MLXSW_SP_RESOURCE_KVD_LINEAR_SINGLE,
MLXSW_SP_RESOURCE_KVD_LINEAR_CHUNKS,
MLXSW_SP_RESOURCE_KVD_LINEAR_LARGE_CHUNKS,
};

struct mlxsw_sp_port;
Expand Down Expand Up @@ -433,6 +439,7 @@ int mlxsw_sp_kvdl_alloc_size_query(struct mlxsw_sp *mlxsw_sp,
unsigned int entry_count,
unsigned int *p_alloc_size);
u64 mlxsw_sp_kvdl_occ_get(const struct mlxsw_sp *mlxsw_sp);
int mlxsw_sp_kvdl_resources_register(struct devlink *devlink);

struct mlxsw_sp_acl_rule_info {
unsigned int priority;
Expand Down
Loading

0 comments on commit a38bbe7

Please sign in to comment.