@@ -3991,6 +3991,188 @@ static const struct mlxsw_config_profile mlxsw_sp_config_profile = {
3991
3991
.resource_query_enable = 1 ,
3992
3992
};
3993
3993
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
+
3994
4176
static struct mlxsw_driver mlxsw_sp_driver = {
3995
4177
.kind = mlxsw_sp_driver_name ,
3996
4178
.priv_size = sizeof (struct mlxsw_sp ),
@@ -4010,6 +4192,7 @@ static struct mlxsw_driver mlxsw_sp_driver = {
4010
4192
.sb_occ_port_pool_get = mlxsw_sp_sb_occ_port_pool_get ,
4011
4193
.sb_occ_tc_port_bind_get = mlxsw_sp_sb_occ_tc_port_bind_get ,
4012
4194
.txhdr_construct = mlxsw_sp_txhdr_construct ,
4195
+ .resources_register = mlxsw_sp_resources_register ,
4013
4196
.txhdr_len = MLXSW_TXHDR_LEN ,
4014
4197
.profile = & mlxsw_sp_config_profile ,
4015
4198
};
0 commit comments