Skip to content

Commit ef3116e

Browse files
Arkadi Sharshevskydavem330
authored andcommitted
mlxsw: spectrum: Register KVD resources with devlink
Register the KVD resources with devlink. The KVD is a memory resource which is subdivided into three partitions which are the linear, hash single and hash double. Signed-off-by: Arkadi Sharshevsky <[email protected]> Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 54a2e8d commit ef3116e

File tree

4 files changed

+205
-0
lines changed

4 files changed

+205
-0
lines changed

drivers/net/ethernet/mellanox/mlxsw/core.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,12 @@ int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
10121012
if (err)
10131013
goto err_bus_init;
10141014

1015+
if (mlxsw_driver->resources_register) {
1016+
err = mlxsw_driver->resources_register(mlxsw_core);
1017+
if (err)
1018+
goto err_register_resources;
1019+
}
1020+
10151021
err = mlxsw_ports_init(mlxsw_core);
10161022
if (err)
10171023
goto err_ports_init;
@@ -1067,6 +1073,8 @@ int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
10671073
err_ports_init:
10681074
mlxsw_bus->fini(bus_priv);
10691075
err_bus_init:
1076+
devlink_resources_unregister(devlink, NULL);
1077+
err_register_resources:
10701078
devlink_free(devlink);
10711079
err_devlink_alloc:
10721080
mlxsw_core_driver_put(device_kind);
@@ -1086,6 +1094,7 @@ void mlxsw_core_bus_device_unregister(struct mlxsw_core *mlxsw_core)
10861094
mlxsw_emad_fini(mlxsw_core);
10871095
kfree(mlxsw_core->lag.mapping);
10881096
mlxsw_ports_fini(mlxsw_core);
1097+
devlink_resources_unregister(devlink, NULL);
10891098
mlxsw_core->bus->fini(mlxsw_core->bus_priv);
10901099
devlink_free(devlink);
10911100
mlxsw_core_driver_put(device_kind);

drivers/net/ethernet/mellanox/mlxsw/core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ struct mlxsw_driver {
308308
u32 *p_cur, u32 *p_max);
309309
void (*txhdr_construct)(struct sk_buff *skb,
310310
const struct mlxsw_tx_info *tx_info);
311+
int (*resources_register)(struct mlxsw_core *mlxsw_core);
311312
u8 txhdr_len;
312313
const struct mlxsw_config_profile *profile;
313314
};

drivers/net/ethernet/mellanox/mlxsw/spectrum.c

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3991,6 +3991,188 @@ static const struct mlxsw_config_profile mlxsw_sp_config_profile = {
39913991
.resource_query_enable = 1,
39923992
};
39933993

3994+
static bool
3995+
mlxsw_sp_resource_kvd_granularity_validate(struct netlink_ext_ack *extack,
3996+
u64 size)
3997+
{
3998+
const struct mlxsw_config_profile *profile;
3999+
4000+
profile = &mlxsw_sp_config_profile;
4001+
if (size % profile->kvd_hash_granularity) {
4002+
NL_SET_ERR_MSG_MOD(extack, "resource set with wrong granularity");
4003+
return false;
4004+
}
4005+
return true;
4006+
}
4007+
4008+
static int
4009+
mlxsw_sp_resource_kvd_size_validate(struct devlink *devlink, u64 size,
4010+
struct netlink_ext_ack *extack)
4011+
{
4012+
NL_SET_ERR_MSG_MOD(extack, "kvd size cannot be changed");
4013+
return -EINVAL;
4014+
}
4015+
4016+
static int
4017+
mlxsw_sp_resource_kvd_linear_size_validate(struct devlink *devlink, u64 size,
4018+
struct netlink_ext_ack *extack)
4019+
{
4020+
if (!mlxsw_sp_resource_kvd_granularity_validate(extack, size))
4021+
return -EINVAL;
4022+
4023+
return 0;
4024+
}
4025+
4026+
static int
4027+
mlxsw_sp_resource_kvd_hash_single_size_validate(struct devlink *devlink, u64 size,
4028+
struct netlink_ext_ack *extack)
4029+
{
4030+
struct mlxsw_core *mlxsw_core = devlink_priv(devlink);
4031+
4032+
if (!mlxsw_sp_resource_kvd_granularity_validate(extack, size))
4033+
return -EINVAL;
4034+
4035+
if (size < MLXSW_CORE_RES_GET(mlxsw_core, KVD_SINGLE_MIN_SIZE)) {
4036+
NL_SET_ERR_MSG_MOD(extack, "hash single size is smaller than minimum");
4037+
return -EINVAL;
4038+
}
4039+
return 0;
4040+
}
4041+
4042+
static int
4043+
mlxsw_sp_resource_kvd_hash_double_size_validate(struct devlink *devlink, u64 size,
4044+
struct netlink_ext_ack *extack)
4045+
{
4046+
struct mlxsw_core *mlxsw_core = devlink_priv(devlink);
4047+
4048+
if (!mlxsw_sp_resource_kvd_granularity_validate(extack, size))
4049+
return -EINVAL;
4050+
4051+
if (size < MLXSW_CORE_RES_GET(mlxsw_core, KVD_DOUBLE_MIN_SIZE)) {
4052+
NL_SET_ERR_MSG_MOD(extack, "hash double size is smaller than minimum");
4053+
return -EINVAL;
4054+
}
4055+
return 0;
4056+
}
4057+
4058+
static struct devlink_resource_ops mlxsw_sp_resource_kvd_ops = {
4059+
.size_validate = mlxsw_sp_resource_kvd_size_validate,
4060+
};
4061+
4062+
static struct devlink_resource_ops mlxsw_sp_resource_kvd_linear_ops = {
4063+
.size_validate = mlxsw_sp_resource_kvd_linear_size_validate,
4064+
};
4065+
4066+
static struct devlink_resource_ops mlxsw_sp_resource_kvd_hash_single_ops = {
4067+
.size_validate = mlxsw_sp_resource_kvd_hash_single_size_validate,
4068+
};
4069+
4070+
static struct devlink_resource_ops mlxsw_sp_resource_kvd_hash_double_ops = {
4071+
.size_validate = mlxsw_sp_resource_kvd_hash_double_size_validate,
4072+
};
4073+
4074+
static struct devlink_resource_size_params mlxsw_sp_kvd_size_params;
4075+
static struct devlink_resource_size_params mlxsw_sp_linear_size_params;
4076+
static struct devlink_resource_size_params mlxsw_sp_hash_single_size_params;
4077+
static struct devlink_resource_size_params mlxsw_sp_hash_double_size_params;
4078+
4079+
static void
4080+
mlxsw_sp_resource_size_params_prepare(struct mlxsw_core *mlxsw_core)
4081+
{
4082+
u32 single_size_min = MLXSW_CORE_RES_GET(mlxsw_core,
4083+
KVD_SINGLE_MIN_SIZE);
4084+
u32 double_size_min = MLXSW_CORE_RES_GET(mlxsw_core,
4085+
KVD_DOUBLE_MIN_SIZE);
4086+
u32 kvd_size = MLXSW_CORE_RES_GET(mlxsw_core, KVD_SIZE);
4087+
u32 linear_size_min = 0;
4088+
4089+
/* KVD top resource */
4090+
mlxsw_sp_kvd_size_params.size_min = kvd_size;
4091+
mlxsw_sp_kvd_size_params.size_max = kvd_size;
4092+
mlxsw_sp_kvd_size_params.size_granularity = MLXSW_SP_KVD_GRANULARITY;
4093+
mlxsw_sp_kvd_size_params.unit = DEVLINK_RESOURCE_UNIT_ENTRY;
4094+
4095+
/* Linear part init */
4096+
mlxsw_sp_linear_size_params.size_min = linear_size_min;
4097+
mlxsw_sp_linear_size_params.size_max = kvd_size - single_size_min -
4098+
double_size_min;
4099+
mlxsw_sp_linear_size_params.size_granularity = MLXSW_SP_KVD_GRANULARITY;
4100+
mlxsw_sp_linear_size_params.unit = DEVLINK_RESOURCE_UNIT_ENTRY;
4101+
4102+
/* Hash double part init */
4103+
mlxsw_sp_hash_double_size_params.size_min = double_size_min;
4104+
mlxsw_sp_hash_double_size_params.size_max = kvd_size - single_size_min -
4105+
linear_size_min;
4106+
mlxsw_sp_hash_double_size_params.size_granularity = MLXSW_SP_KVD_GRANULARITY;
4107+
mlxsw_sp_hash_double_size_params.unit = DEVLINK_RESOURCE_UNIT_ENTRY;
4108+
4109+
/* Hash single part init */
4110+
mlxsw_sp_hash_single_size_params.size_min = single_size_min;
4111+
mlxsw_sp_hash_single_size_params.size_max = kvd_size - double_size_min -
4112+
linear_size_min;
4113+
mlxsw_sp_hash_single_size_params.size_granularity = MLXSW_SP_KVD_GRANULARITY;
4114+
mlxsw_sp_hash_single_size_params.unit = DEVLINK_RESOURCE_UNIT_ENTRY;
4115+
}
4116+
4117+
static int mlxsw_sp_resources_register(struct mlxsw_core *mlxsw_core)
4118+
{
4119+
struct devlink *devlink = priv_to_devlink(mlxsw_core);
4120+
u32 kvd_size, single_size, double_size, linear_size;
4121+
const struct mlxsw_config_profile *profile;
4122+
int err;
4123+
4124+
profile = &mlxsw_sp_config_profile;
4125+
if (!MLXSW_CORE_RES_VALID(mlxsw_core, KVD_SIZE))
4126+
return -EIO;
4127+
4128+
mlxsw_sp_resource_size_params_prepare(mlxsw_core);
4129+
kvd_size = MLXSW_CORE_RES_GET(mlxsw_core, KVD_SIZE);
4130+
err = devlink_resource_register(devlink, MLXSW_SP_RESOURCE_NAME_KVD,
4131+
true, kvd_size,
4132+
MLXSW_SP_RESOURCE_KVD,
4133+
DEVLINK_RESOURCE_ID_PARENT_TOP,
4134+
&mlxsw_sp_kvd_size_params,
4135+
&mlxsw_sp_resource_kvd_ops);
4136+
if (err)
4137+
return err;
4138+
4139+
linear_size = profile->kvd_linear_size;
4140+
err = devlink_resource_register(devlink, MLXSW_SP_RESOURCE_NAME_KVD_LINEAR,
4141+
false, linear_size,
4142+
MLXSW_SP_RESOURCE_KVD_LINEAR,
4143+
MLXSW_SP_RESOURCE_KVD,
4144+
&mlxsw_sp_linear_size_params,
4145+
&mlxsw_sp_resource_kvd_linear_ops);
4146+
if (err)
4147+
return err;
4148+
4149+
double_size = kvd_size - linear_size;
4150+
double_size *= profile->kvd_hash_double_parts;
4151+
double_size /= profile->kvd_hash_double_parts +
4152+
profile->kvd_hash_single_parts;
4153+
double_size = rounddown(double_size, profile->kvd_hash_granularity);
4154+
err = devlink_resource_register(devlink, MLXSW_SP_RESOURCE_NAME_KVD_HASH_DOUBLE,
4155+
false, double_size,
4156+
MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE,
4157+
MLXSW_SP_RESOURCE_KVD,
4158+
&mlxsw_sp_hash_double_size_params,
4159+
&mlxsw_sp_resource_kvd_hash_double_ops);
4160+
if (err)
4161+
return err;
4162+
4163+
single_size = kvd_size - double_size - linear_size;
4164+
err = devlink_resource_register(devlink, MLXSW_SP_RESOURCE_NAME_KVD_HASH_SINGLE,
4165+
false, single_size,
4166+
MLXSW_SP_RESOURCE_KVD_HASH_SINGLE,
4167+
MLXSW_SP_RESOURCE_KVD,
4168+
&mlxsw_sp_hash_single_size_params,
4169+
&mlxsw_sp_resource_kvd_hash_single_ops);
4170+
if (err)
4171+
return err;
4172+
4173+
return 0;
4174+
}
4175+
39944176
static struct mlxsw_driver mlxsw_sp_driver = {
39954177
.kind = mlxsw_sp_driver_name,
39964178
.priv_size = sizeof(struct mlxsw_sp),
@@ -4010,6 +4192,7 @@ static struct mlxsw_driver mlxsw_sp_driver = {
40104192
.sb_occ_port_pool_get = mlxsw_sp_sb_occ_port_pool_get,
40114193
.sb_occ_tc_port_bind_get = mlxsw_sp_sb_occ_tc_port_bind_get,
40124194
.txhdr_construct = mlxsw_sp_txhdr_construct,
4195+
.resources_register = mlxsw_sp_resources_register,
40134196
.txhdr_len = MLXSW_TXHDR_LEN,
40144197
.profile = &mlxsw_sp_config_profile,
40154198
};

drivers/net/ethernet/mellanox/mlxsw/spectrum.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@
6666
#define MLXSW_SP_KVD_LINEAR_SIZE 98304 /* entries */
6767
#define MLXSW_SP_KVD_GRANULARITY 128
6868

69+
#define MLXSW_SP_RESOURCE_NAME_KVD "kvd"
70+
#define MLXSW_SP_RESOURCE_NAME_KVD_LINEAR "linear"
71+
#define MLXSW_SP_RESOURCE_NAME_KVD_HASH_SINGLE "hash_single"
72+
#define MLXSW_SP_RESOURCE_NAME_KVD_HASH_DOUBLE "hash_double"
73+
74+
enum mlxsw_sp_resource_id {
75+
MLXSW_SP_RESOURCE_KVD,
76+
MLXSW_SP_RESOURCE_KVD_LINEAR,
77+
MLXSW_SP_RESOURCE_KVD_HASH_SINGLE,
78+
MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE,
79+
};
80+
6981
struct mlxsw_sp_port;
7082
struct mlxsw_sp_rif;
7183

0 commit comments

Comments
 (0)