On 11/18/2017 09:18 PM, David Ahern wrote:
> On 11/14/17 9:18 AM, Jiri Pirko wrote:
>> diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c 
>> b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
>> index d02c130..f0cbd67 100644
>> --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
>> +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
>> @@ -3927,6 +3927,173 @@ 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(extack, MLXSW_SP_PREFIX "resource set with wrong 
>> granularity");
>> +            return false;
>> +    }
>> +    return true;
>> +}
>> +
>> +static int
>> +mlxsw_sp_resource_kvd_size_validate(struct devlink *devlink, u64 size,
>> +                                struct list_head *resource_list,
>> +                                struct netlink_ext_ack *extack)
>> +{
>> +    struct mlxsw_core *mlxsw_core = devlink_priv(devlink);
>> +    u32 kvd_size, single_size, double_size, linear_size;
>> +    struct devlink_resource *resource;
>> +
>> +    kvd_size = MLXSW_CORE_RES_GET(mlxsw_core, KVD_SIZE);
>> +    if (kvd_size != size) {
>> +            NL_SET_ERR_MSG(extack, MLXSW_SP_PREFIX "kvd size cannot be 
>> chagned");
> 
> s/chagned/changed/
> 
>> +            return -EINVAL;
>> +    }
>> +
>> +    list_for_each_entry(resource, resource_list, list) {
>> +            switch (resource->id) {
>> +            case MLXSW_SP_RESOURCE_KVD_LINEAR:
>> +                    linear_size = resource->size_new;
>> +                    break;
>> +            case MLXSW_SP_RESOURCE_KVD_HASH_SINGLE:
>> +                    single_size = resource->size_new;
>> +                    break;
>> +            case MLXSW_SP_RESOURCE_KVD_HASH_DOUBLE:
>> +                    double_size = resource->size_new;
>> +                    break;
>> +            }
>> +    }
>> +
>> +    /* Overlap is not supported */
>> +    if (linear_size + single_size + double_size > kvd_size) {
>> +            NL_SET_ERR_MSG(extack, MLXSW_SP_PREFIX "Overlap is not 
>> supported");
> 
> Overlap? Isn't that sum of the partitions are greater than total size?
> 

In case sum of the partitions is greater than the kvd tot size, the
hash single/double will be set in an overlapping state, which we do
not support currently.

> 
>> +            return -EINVAL;
>> +    }
>> +
>> +    return 0;
>> +}
>> +
>> +static int
>> +mlxsw_sp_resource_kvd_linear_size_validate(struct devlink *devlink, u64 
>> size,
>> +                                       struct list_head *resource_list,
>> +                                       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 list_head *resource_list,
>> +                                            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(extack, MLXSW_SP_PREFIX "hash single size is 
>> smaller then min");
> 
> s/then min/than minimium/
> 
>> +            return -EINVAL;
>> +    }
>> +    return 0;
>> +}
>> +
>> +static int
>> +mlxsw_sp_resource_kvd_hash_double_size_validate(struct devlink *devlink, 
>> u64 size,
>> +                                            struct list_head *resource_list,
>> +                                            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(extack, MLXSW_SP_PREFIX "hash double size is 
>> smaller then min");
> 
> s/then min/than minimium/
> 
> How does the user learn the minimum size and the granularity for the KVD
> resources? Seems like those could be read-only attributes in the
> resource dump to make it easier for the user.
> 

This seems to me as too case specific and I didn't want to add
UAPI attributes for this stuff..

The resource shouldn't be define as only memory based hardware blocks.
I actually plane expose the rifs as resource as well.

I think that if the user try to configure and receives an such error
it is very clear what is the problem.


> 
> 

Reply via email to