From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Ahern Subject: Re: [patch net-next RFC v2 07/11] mlxsw: spectrum: Register KVD resources with devlink Date: Sat, 18 Nov 2017 12:18:28 -0700 Message-ID: <8882720f-9eae-514d-e32a-234be8d8568a@cumulusnetworks.com> References: <20171114161852.6633-1-jiri@resnulli.us> <20171114161852.6633-8-jiri@resnulli.us> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: davem@davemloft.net, mlxsw@mellanox.com, andrew@lunn.ch, vivien.didelot@savoirfairelinux.com, f.fainelli@gmail.com, michael.chan@broadcom.com, ganeshgr@chelsio.com, saeedm@mellanox.com, matanb@mellanox.com, leonro@mellanox.com, idosch@mellanox.com, jakub.kicinski@netronome.com, ast@kernel.org, daniel@iogearbox.net, simon.horman@netronome.com, pieter.jansenvanvuuren@netronome.com, john.hurley@netronome.com, alexander.h.duyck@intel.com, linville@tuxdriver.com, gospo@broadcom.com, steven.lin1@broadcom.com, yuvalm@mellanox.com, ogerlitz@mellanox.com, roopa@cumulusnetworks.com To: Jiri Pirko , netdev@vger.kernel.org Return-path: Received: from mail-pg0-f65.google.com ([74.125.83.65]:46124 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1162160AbdKRTSc (ORCPT ); Sat, 18 Nov 2017 14:18:32 -0500 Received: by mail-pg0-f65.google.com with SMTP id z184so4327234pgd.13 for ; Sat, 18 Nov 2017 11:18:32 -0800 (PST) In-Reply-To: <20171114161852.6633-8-jiri@resnulli.us> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: 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? > + 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.