From patchwork Wed Feb 19 16:32:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Przemek Kitszel X-Patchwork-Id: 13982591 X-Patchwork-Delegate: kuba@kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4181A2147F3; Wed, 19 Feb 2025 17:46:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739987182; cv=none; b=IS+YyTZGHmkcLLXnx34FU/k0ooSBNE7MOKBL1URoqsWIrhpHuB+QqMcdEGvsqHuFDKo/s+D/1fvVkZAyrBLLQGTiE0flScy/r8HK4XfKDap+vYR8ePuRe1fFJ3CEbHHDsQN/kg/jW3XeRhgJA81t8vcvqFeyTUFH2BvqiXeVAZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739987182; c=relaxed/simple; bh=v0mV9d9F4bC7WQnGYcrOFt0VFmgb9KQ5yKqZlvACNA8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cpC7n/eBqtet9rn8Aiqsi8wTTG6TYKdgfYHT7YrXlusrU0CRVpTaFoV+UXF+eazy8Q5W58MZw7ke3SXNRz1h2OSziaey4Qc0QLJDvGFXPWFOgaWZ6X4UbkDqY57fPS7xWh7j4ZeHyBSTUM5ZNKQsG835Km4cBGzyil0oTAkW09U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=NaM3GKas; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="NaM3GKas" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739987180; x=1771523180; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=v0mV9d9F4bC7WQnGYcrOFt0VFmgb9KQ5yKqZlvACNA8=; b=NaM3GKasLxExeBqTyLYX113znVvUFWm/OGrHxdCkytn6ffHn3kqG8vjq bRDI1nE6XOsoGuGafTpOx9Juj3l2SI0mDhSsFOqn2tVvpWBq0J2nAhBnH MDCu8CvIoGQEttu2UhY8wmAAJwOoAQ88H0fZbY3ueT6IIGS3XBYspaO4t 4qmlOnvHmYtrDdk5Cu8Q6VpCYliR2triLpmWgLPOERh548neJPEWxDQOL emeVNLbksKbpRMpe9Dr0o46mn0vDjbiFQilJxlU/Agk7PMvliCPFBaG2t xk7Blt19P+iCAHBksBouMFseo1qLIZ8A3c9XLRATtdm7vi0eEh+3Z9+RH Q==; X-CSE-ConnectionGUID: RMpb0ihTTE2+NVygFa8K8g== X-CSE-MsgGUID: W2F+T7wATfmkYf5/lVmmNA== X-IronPort-AV: E=McAfee;i="6700,10204,11350"; a="50953029" X-IronPort-AV: E=Sophos;i="6.13,299,1732608000"; d="scan'208";a="50953029" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Feb 2025 09:46:18 -0800 X-CSE-ConnectionGUID: bQm2QqyNSUiunKFvJuH9ZQ== X-CSE-MsgGUID: VIGPr0GVSWuUJ9IY1w87TA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="119427316" Received: from irvmail002.ir.intel.com ([10.43.11.120]) by fmviesa005.fm.intel.com with ESMTP; 19 Feb 2025 08:44:32 -0800 Received: from pkitszel-desk.intel.com (unknown [10.245.246.109]) by irvmail002.ir.intel.com (Postfix) with ESMTP id 4F7EC34301; Wed, 19 Feb 2025 16:44:19 +0000 (GMT) From: Przemek Kitszel To: intel-wired-lan@lists.osuosl.org, Tony Nguyen , Jiri Pirko , Jakub Kicinski , Cosmin Ratiu , Tariq Toukan Cc: netdev@vger.kernel.org, Konrad Knitter , Jacob Keller , davem@davemloft.net, Eric Dumazet , Paolo Abeni , Andrew Lunn , linux-kernel@vger.kernel.org, ITP Upstream , Carolina Jubran , Przemek Kitszel Subject: [RFC net-next v2 1/2] devlink: add whole device devlink instance Date: Wed, 19 Feb 2025 17:32:54 +0100 Message-ID: <20250219164410.35665-2-przemyslaw.kitszel@intel.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250219164410.35665-1-przemyslaw.kitszel@intel.com> References: <20250219164410.35665-1-przemyslaw.kitszel@intel.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Add a support for whole device devlink instance. Intented as a entity over all PF devices on given physical device. In case of ice driver we have multiple PF devices (with their devlink dev representation), that have separate drivers loaded. However those still do share lots of resources due to being the on same HW. Examples include PTP clock and RSS LUT. Historically such stuff was assigned to PF0, but that was both not clear and not working well. Now such stuff is moved to be covered into struct ice_adapter, there is just one instance of such per HW. This patch adds a devlink instance that corresponds to that ice_adapter, to allow arbitrage over resources (as RSS LUT) via it (further in the series (RFC NOTE: stripped out so far)). Thanks to Wojciech Drewek for very nice naming of the devlink instance: PF0: pci/0000:00:18.0 whole-dev: pci/0000:00:18 But I made this a param for now (driver is free to pass just "whole-dev"). $ devlink dev # (Interesting part of output only) pci/0000:af:00: nested_devlink: pci/0000:af:00.0 pci/0000:af:00.1 pci/0000:af:00.2 pci/0000:af:00.3 pci/0000:af:00.4 pci/0000:af:00.5 pci/0000:af:00.6 pci/0000:af:00.7 Signed-off-by: Przemek Kitszel --- net/devlink/devl_internal.h | 14 +++++---- net/devlink/core.c | 58 +++++++++++++++++++++++++++++-------- net/devlink/netlink.c | 4 +-- net/devlink/port.c | 4 +-- 4 files changed, 58 insertions(+), 22 deletions(-) diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index 14eaad9cfe35..073afe02ce2f 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -49,6 +49,8 @@ struct devlink { struct xarray snapshot_ids; struct devlink_dev_stats stats; struct device *dev; + const char *dev_name; + const char *bus_name; possible_net_t _net; /* Serializes access to devlink instance specific objects such as * port, sb, dpipe, resource, params, region, traps and more. @@ -104,15 +106,15 @@ static inline bool devl_is_registered(struct devlink *devlink) static inline void devl_dev_lock(struct devlink *devlink, bool dev_lock) { - if (dev_lock) + if (dev_lock && devlink->dev) device_lock(devlink->dev); devl_lock(devlink); } static inline void devl_dev_unlock(struct devlink *devlink, bool dev_lock) { devl_unlock(devlink); - if (dev_lock) + if (dev_lock && devlink->dev) device_unlock(devlink->dev); } @@ -174,9 +176,9 @@ devlink_dump_state(struct netlink_callback *cb) static inline int devlink_nl_put_handle(struct sk_buff *msg, struct devlink *devlink) { - if (nla_put_string(msg, DEVLINK_ATTR_BUS_NAME, devlink->dev->bus->name)) + if (nla_put_string(msg, DEVLINK_ATTR_BUS_NAME, devlink->bus_name)) return -EMSGSIZE; - if (nla_put_string(msg, DEVLINK_ATTR_DEV_NAME, dev_name(devlink->dev))) + if (nla_put_string(msg, DEVLINK_ATTR_DEV_NAME, devlink->dev_name)) return -EMSGSIZE; return 0; } @@ -209,8 +211,8 @@ static inline void devlink_nl_obj_desc_init(struct devlink_obj_desc *desc, struct devlink *devlink) { memset(desc, 0, sizeof(*desc)); - desc->bus_name = devlink->dev->bus->name; - desc->dev_name = dev_name(devlink->dev); + desc->bus_name = devlink->bus_name; + desc->dev_name = devlink->dev_name; } static inline void devlink_nl_obj_desc_port_set(struct devlink_obj_desc *desc, diff --git a/net/devlink/core.c b/net/devlink/core.c index f49cd83f1955..f4960074b845 100644 --- a/net/devlink/core.c +++ b/net/devlink/core.c @@ -397,26 +397,25 @@ void devlink_unregister(struct devlink *devlink) EXPORT_SYMBOL_GPL(devlink_unregister); /** - * devlink_alloc_ns - Allocate new devlink instance resources - * in specific namespace + * devlink_alloc_wrapper - Allocate a new devlink instance resources + * for a SW wrapper over multiple HW devlink instances * * @ops: ops * @priv_size: size of user private data - * @net: net namespace - * @dev: parent device + * @bus_name: user visible bus name + * @dev_name: user visible device name * - * Allocate new devlink instance resources, including devlink index - * and name. + * Allocate new devlink instance resources, including devlink index. */ -struct devlink *devlink_alloc_ns(const struct devlink_ops *ops, - size_t priv_size, struct net *net, - struct device *dev) +struct devlink *devlink_alloc_wrapper(const struct devlink_ops *ops, + size_t priv_size, const char *bus_name, + const char *dev_name) { struct devlink *devlink; static u32 last_id; int ret; - WARN_ON(!ops || !dev); + WARN_ON(!ops); if (!devlink_reload_actions_valid(ops)) return NULL; @@ -429,13 +428,14 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops, if (ret < 0) goto err_xa_alloc; - devlink->dev = get_device(dev); devlink->ops = ops; + devlink->bus_name = bus_name; + devlink->dev_name = dev_name; xa_init_flags(&devlink->ports, XA_FLAGS_ALLOC); xa_init_flags(&devlink->params, XA_FLAGS_ALLOC); xa_init_flags(&devlink->snapshot_ids, XA_FLAGS_ALLOC); xa_init_flags(&devlink->nested_rels, XA_FLAGS_ALLOC); - write_pnet(&devlink->_net, net); + write_pnet(&devlink->_net, &init_net); INIT_LIST_HEAD(&devlink->rate_list); INIT_LIST_HEAD(&devlink->linecard_list); INIT_LIST_HEAD(&devlink->sb_list); @@ -458,6 +458,40 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops, kvfree(devlink); return NULL; } +EXPORT_SYMBOL_GPL(devlink_alloc_wrapper); + +/** + * devlink_alloc_ns - Allocate new devlink instance resources + * in specific namespace + * + * @ops: ops + * @priv_size: size of user private data + * @net: net namespace + * @dev: parent device + * + * Allocate new devlink instance resources, including devlink index + * and name. + */ +struct devlink *devlink_alloc_ns(const struct devlink_ops *ops, + size_t priv_size, struct net *net, + struct device *dev) +{ + struct devlink *devlink; + + if (WARN_ON(!dev)) + return NULL; + + dev = get_device(dev); + devlink = devlink_alloc_wrapper(ops, priv_size, dev->bus->name, + dev_name(dev)); + if (!devlink) { + put_device(dev); + return NULL; + } + devlink->dev = dev; + write_pnet(&devlink->_net, net); + return devlink; +} EXPORT_SYMBOL_GPL(devlink_alloc_ns); /** diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index 593605c1b1ef..3f73ced2d879 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -193,8 +193,8 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs, devname = nla_data(attrs[DEVLINK_ATTR_DEV_NAME]); devlinks_xa_for_each_registered_get(net, index, devlink) { - if (strcmp(devlink->dev->bus->name, busname) == 0 && - strcmp(dev_name(devlink->dev), devname) == 0) { + if (strcmp(devlink->bus_name, busname) == 0 && + strcmp(devlink->dev_name, devname) == 0) { devl_dev_lock(devlink, dev_lock); if (devl_is_registered(devlink)) return devlink; diff --git a/net/devlink/port.c b/net/devlink/port.c index 939081a0e615..508ecf34d41a 100644 --- a/net/devlink/port.c +++ b/net/devlink/port.c @@ -220,8 +220,8 @@ size_t devlink_nl_port_handle_size(struct devlink_port *devlink_port) { struct devlink *devlink = devlink_port->devlink; - return nla_total_size(strlen(devlink->dev->bus->name) + 1) /* DEVLINK_ATTR_BUS_NAME */ - + nla_total_size(strlen(dev_name(devlink->dev)) + 1) /* DEVLINK_ATTR_DEV_NAME */ + return nla_total_size(strlen(devlink->bus_name) + 1) /* DEVLINK_ATTR_BUS_NAME */ + + nla_total_size(strlen(devlink->dev_name) + 1) /* DEVLINK_ATTR_DEV_NAME */ + nla_total_size(4); /* DEVLINK_ATTR_PORT_INDEX */ } From patchwork Wed Feb 19 16:32:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Przemek Kitszel X-Patchwork-Id: 13982590 X-Patchwork-Delegate: kuba@kernel.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2544619CC33; Wed, 19 Feb 2025 17:46:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739987179; cv=none; b=Ctr1+/floHoydFFmxBiYDumTOoRQEgJdZvJasu2OpmKIBbEu3bf6XmsKsy7tsIKzlig5o5yIjh+FUYcIMkty+JdubvHXOhfVVCekRfxgrW19x1cPd9OyGzqL4M7cH4+wg0aYHBO3gMUCnWWCT9G6HfMBCucs8r0oKJy0PeFUyoA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739987179; c=relaxed/simple; bh=MwD19ihbKaz4IBkMTRxc/PBUn4IuzdESisvBCresR44=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sQ21Mclpk/ioxzYngMmIBHM9vQXSXF7RqrzxkdiEThjA+Hv7rubndpUKiXq+UJvP0GoaOVf3PhzaONpHkwsgod4IyVckZxfWfGdC+4QAEIdxeK3lmjKFn+KUqivPQSESojcvnlzQJtpMsuBX0pNnyyz9Ehoo5hqPaCxiqAsVJmw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=CLvlm4nO; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="CLvlm4nO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739987178; x=1771523178; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MwD19ihbKaz4IBkMTRxc/PBUn4IuzdESisvBCresR44=; b=CLvlm4nO5TEwjKrt4mBiV4y+7S+atYFqK0RjjU35ugunmNglyXEams0m wI9b3G5IdfOyvXm0/XTJXMtwQAN6NZ+p7l6dn79LPTi5AUTW1HgMqW+8B sWQKxPA/Ldwh/8d0DIUrERKuOhmFlT3H+bTpn4EyGwSKbKhfEqRz584om Iwdq50/EqVUoRsmwMGLdocaThKG3XZ2MkZ+ZCJ++OfmKRV8dmRuZyc75o A4XAbRLlHa2kSrzsS6X1Vu6vE37PtcqTdWprpRaNNynFOv9pX4E1JT0+Y NMg0KfSRsRs6lxiG5Zzu1uidEXAS5aU3l1nnsbV5TDICN+82VJR35XlwN Q==; X-CSE-ConnectionGUID: IwAdkIkEQlW6TRwLCFCYvA== X-CSE-MsgGUID: 5E+qTyDkRBOctPBl1ZCa5Q== X-IronPort-AV: E=McAfee;i="6700,10204,11350"; a="50953011" X-IronPort-AV: E=Sophos;i="6.13,299,1732608000"; d="scan'208";a="50953011" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Feb 2025 09:46:14 -0800 X-CSE-ConnectionGUID: YOtOd1d7QwCLO2vwn6JMHg== X-CSE-MsgGUID: uUBZIoz/QmWhN/9y7wplPA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="119427317" Received: from irvmail002.ir.intel.com ([10.43.11.120]) by fmviesa005.fm.intel.com with ESMTP; 19 Feb 2025 08:44:32 -0800 Received: from pkitszel-desk.intel.com (unknown [10.245.246.109]) by irvmail002.ir.intel.com (Postfix) with ESMTP id A28D134302; Wed, 19 Feb 2025 16:44:21 +0000 (GMT) From: Przemek Kitszel To: intel-wired-lan@lists.osuosl.org, Tony Nguyen , Jiri Pirko , Jakub Kicinski , Cosmin Ratiu , Tariq Toukan Cc: netdev@vger.kernel.org, Konrad Knitter , Jacob Keller , davem@davemloft.net, Eric Dumazet , Paolo Abeni , Andrew Lunn , linux-kernel@vger.kernel.org, ITP Upstream , Carolina Jubran , Przemek Kitszel Subject: [RFC net-next v2 2/2] devlink: give user option to allocate resources Date: Wed, 19 Feb 2025 17:32:55 +0100 Message-ID: <20250219164410.35665-3-przemyslaw.kitszel@intel.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250219164410.35665-1-przemyslaw.kitszel@intel.com> References: <20250219164410.35665-1-przemyslaw.kitszel@intel.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Current devlink resources are designed as a thing that user could limit, but there is not much otherwise that could be done with them. Perhaps that's the reason there is no much adoption despite API being there for multiple years. Add new mode of operation, where user could allocate/assign resources (from a common pool) to specific devices. That requires "occ set" support, triggered by user. To support that mode, "occ get" is (only then) turned into a simple "get/show" operation, as opposed to "ask driver about current occupation" in the "legacy" mode. Naming advice welcomed, for now the modes are reffered as: legacy/static-occ/mlx vs new/ice/dynamic-occ Perhaps "user-settable" for the new mode and "driver-only" for the legacy? Does not matter much, as this will be only embedded in the net/devlink/resource.c file as names/comments for clarity. Signed-off-by: Przemek Kitszel --- net/devlink/resource.c | 94 +++++++++++++++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 20 deletions(-) diff --git a/net/devlink/resource.c b/net/devlink/resource.c index 2d6324f3d91f..c81d05427e12 100644 --- a/net/devlink/resource.c +++ b/net/devlink/resource.c @@ -14,25 +14,30 @@ * @size_new: updated size of the resource, reload is needed * @size_valid: valid in case the total size of the resource is valid * including its children + * @occ_mode: false for static occ mode == legacy mlx like + * true for dynamic occ mode == new one for intel * @parent: parent resource * @size_params: size parameters * @list: parent list * @resource_list: list of child resources * @occ_get: occupancy getter callback - * @occ_get_priv: occupancy getter callback priv + * @occ_set: occupancy setter callback + * @occ_priv: occupancy callbacks priv */ struct devlink_resource { const char *name; u64 id; u64 size; u64 size_new; bool size_valid; + bool occ_mode; struct devlink_resource *parent; struct devlink_resource_size_params size_params; struct list_head list; struct list_head resource_list; devlink_resource_occ_get_t *occ_get; - void *occ_get_priv; + devlink_resource_occ_set_t *occ_set; + void *occ_priv; }; static struct devlink_resource * @@ -127,6 +132,9 @@ int devlink_nl_resource_set_doit(struct sk_buff *skb, struct genl_info *info) if (err) return err; + if (resource->occ_set) + return resource->occ_set(size, info->extack, resource->occ_priv); + resource->size_new = size; devlink_resource_validate_children(resource); if (resource->parent) @@ -152,13 +160,46 @@ devlink_resource_size_params_put(struct devlink_resource *resource, return 0; } -static int devlink_resource_occ_put(struct devlink_resource *resource, - struct sk_buff *skb) +static +int devlink_resource_occ_size_put_legacy(struct devlink_resource *resource, + struct sk_buff *skb) +{ + int err; + + if (resource->occ_get) { + err = devlink_nl_put_u64(skb, DEVLINK_ATTR_RESOURCE_OCC, + resource->occ_get(resource->occ_priv)); + if (err) + return err; + } + + if (resource->size != resource->size_new) { + err = devlink_nl_put_u64(skb, DEVLINK_ATTR_RESOURCE_SIZE_NEW, + resource->size_new); + if (err) + return err; + } + + err = nla_put_u8(skb, DEVLINK_ATTR_RESOURCE_SIZE_VALID, + resource->size_valid); + if (err) + return err; + + + return devlink_nl_put_u64(skb, DEVLINK_ATTR_RESOURCE_SIZE, + resource->size); +} + +static int devlink_resource_occ_size_put(struct devlink_resource *resource, + struct sk_buff *skb) { - if (!resource->occ_get) - return 0; - return devlink_nl_put_u64(skb, DEVLINK_ATTR_RESOURCE_OCC, - resource->occ_get(resource->occ_get_priv)); + if (!resource->occ_get || !resource->occ_set) + return devlink_resource_occ_size_put_legacy(resource, skb); + + nla_put_u8(skb, DEVLINK_ATTR_RESOURCE_SIZE_VALID, true); + + return devlink_nl_put_u64(skb, DEVLINK_ATTR_RESOURCE_SIZE, + resource->occ_get(resource->occ_priv)); } static int devlink_resource_put(struct devlink *devlink, struct sk_buff *skb, @@ -173,23 +214,16 @@ static int devlink_resource_put(struct devlink *devlink, struct sk_buff *skb, return -EMSGSIZE; if (nla_put_string(skb, DEVLINK_ATTR_RESOURCE_NAME, resource->name) || - devlink_nl_put_u64(skb, DEVLINK_ATTR_RESOURCE_SIZE, resource->size) || devlink_nl_put_u64(skb, DEVLINK_ATTR_RESOURCE_ID, resource->id)) goto nla_put_failure; - if (resource->size != resource->size_new && - devlink_nl_put_u64(skb, DEVLINK_ATTR_RESOURCE_SIZE_NEW, - resource->size_new)) - goto nla_put_failure; - if (devlink_resource_occ_put(resource, skb)) - goto nla_put_failure; if (devlink_resource_size_params_put(resource, skb)) goto nla_put_failure; + if (devlink_resource_occ_size_put(resource, skb)) + goto nla_put_failure; + if (list_empty(&resource->resource_list)) goto out; - if (nla_put_u8(skb, DEVLINK_ATTR_RESOURCE_SIZE_VALID, - resource->size_valid)) - goto nla_put_failure; child_resource_attr = nla_nest_start_noflag(skb, DEVLINK_ATTR_RESOURCE_LIST); @@ -476,7 +510,7 @@ void devl_resource_occ_get_register(struct devlink *devlink, WARN_ON(resource->occ_get); resource->occ_get = occ_get; - resource->occ_get_priv = occ_get_priv; + resource->occ_priv = occ_get_priv; } EXPORT_SYMBOL_GPL(devl_resource_occ_get_register); @@ -499,6 +533,26 @@ void devl_resource_occ_get_unregister(struct devlink *devlink, WARN_ON(!resource->occ_get); resource->occ_get = NULL; - resource->occ_get_priv = NULL; } EXPORT_SYMBOL_GPL(devl_resource_occ_get_unregister); + +void devl_resource_occ_set_get_register(struct devlink *devlink, + u64 resource_id, + devlink_resource_occ_set_t *occ_set, + devlink_resource_occ_get_t *occ_get, + void *occ_priv) +{ + struct devlink_resource *resource; + + lockdep_assert_held(&devlink->lock); + + resource = devlink_resource_find(devlink, NULL, resource_id); + if (WARN_ON(!resource)) + return; + WARN_ON(resource->occ_get || resource->occ_set); + + resource->occ_set = occ_set; + resource->occ_get = occ_get; + resource->occ_priv = occ_priv; +} +EXPORT_SYMBOL_GPL(devl_resource_occ_set_get_register);