From nobody Thu Apr 2 01:54:02 2026 Received: from BN1PR04CU002.outbound.protection.outlook.com (mail-eastus2azon11010004.outbound.protection.outlook.com [52.101.56.4]) (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 4274A331A43; Wed, 1 Apr 2026 18:50:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.56.4 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775069458; cv=fail; b=CDc/rQSlg7Z/jNZ0EmU6UbwJ9V2BA44gmixAlLGH+IEBu6Anedh6y2t5rReUUaXF/iLOAKzqGO4PtjnfrJmwA1p7CZEL58PmK/NebAXsaxiyNJpsYbtCyokmwJrTyer/xHQoFkwzmj0cNXFE7rFme5hTDrKlPc/UxDOTLSUktw0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775069458; c=relaxed/simple; bh=5JAmz16WJ+MWQG0y8uNwgIKv3u9h9778y7vday56gRc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OaS+gaCvtVl2x+aFwt6s9IUVnCinMT8iPLIGuyXz4KYIJQUCoRVhNkpzRLaMSO+Uc1Md5P6xOAAujJ7RZdGisK6+tqhSeg/6ltiHqzqYNqEhQNPi1czzPhWNnD1OQc/DKwWVHR/+CDfNXPKSjkABtJOBnJx4TVJx4DEsRL9TUPA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=rC+c4EdB; arc=fail smtp.client-ip=52.101.56.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="rC+c4EdB" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=l5ZmE1Cv49Fk//c2FT1zEjfxbSl8+ok8KnZ6MYcFeOVAassGiHaySioTuWVBCwyAks3kL376n/iik0KtNArTwsNUL2GU3Ib3/rZsRdOk8aIC88YfI89T3pAlmweWRz3m9Qn79+ipv222zzuPSCPr3bTkJIXQyKgr3O3jkmjMMRT8t3GjVXyVek/YVogQJY/zoVZalsngoIxgfWTJM0l6a/7FBga30DIo4vk1HTdFacDrpkcyRU6JIP6Prnib1v+lIEbwLLcBoyHqDFBlsJXqxnTypFgdJZBNBR4hwLu/FLtkRIS2zmGxpB3lo7kDJc7xKVSgctZ6oj8IHXIANBBpog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Sc0HMEbZ3vW90tigxNiYCOF4QxSriaibXJ+1aFADTI8=; b=PuX3DqyzGw/bnXqnzq0M/rq8vND9ylp9UM8bLnW4wBNn6+ywjdkFpbZ5g0mVuoKJpGWY4HdLcdLG2d5XggHQk+/WLh1GLbK7oC+GIPphy8LovPWJ1pZ8mB0hFdT2eAX4KR2B2OsyQt79n/pqdG4UjvbrHkDwnPRBSxhIDRQ89d14hL19NhEQywxnuM6zf9GxW3veX0x6Bv3GjGgvVhDB6QWKrrOUTWaRrUWA1l1fkdjmGgy5sEBP2Jf5MnhRtJ6Eo1b7Y4DzpQbFVBqjCmTGwA19vKNe/SmuNT52AXcapeXw/VY1Brz5DnA173oOrpG3kIXVcoli/ElNmeiKMJ1+DA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=google.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Sc0HMEbZ3vW90tigxNiYCOF4QxSriaibXJ+1aFADTI8=; b=rC+c4EdBg3eZBbU6zNIi+cBMsXRwhE3NQGbGvuxOzmRDuhsC/ZEZFkV6LNEBocfdhfOLnPpVc59SJfh45XbB7cUhhWdymfFl2zppQgkZCi1hpx5K2CZ3Hkf1lvKulCEQVhfkk70HwdATkTbcmDqZX2N4F2/9GW4Y4JQAyLBUexY1jSaBKf8ZguZJYrHl7yPWgB/88C0Y67HWxbKtYU3GeLB1nQCyAyrS0vS0mLTiFLjplwTkAfYMwcIvaU5Le9hkZV1vLmnHeq7tSgB/9HEj9ANjXXBg1pNj6ti7sy+wUpqmFXTofKRCgu7urCpafs6NA3YBypP1TdU0+X7zPSvCcQ== Received: from BN9PR03CA0070.namprd03.prod.outlook.com (2603:10b6:408:fc::15) by LV8PR12MB9715.namprd12.prod.outlook.com (2603:10b6:408:2a0::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9769.17; Wed, 1 Apr 2026 18:50:51 +0000 Received: from BN2PEPF0000449D.namprd02.prod.outlook.com (2603:10b6:408:fc:cafe::2f) by BN9PR03CA0070.outlook.office365.com (2603:10b6:408:fc::15) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9745.30 via Frontend Transport; Wed, 1 Apr 2026 18:50:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by BN2PEPF0000449D.mail.protection.outlook.com (10.167.243.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9769.17 via Frontend Transport; Wed, 1 Apr 2026 18:50:51 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 1 Apr 2026 11:50:30 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Wed, 1 Apr 2026 11:50:29 -0700 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Wed, 1 Apr 2026 11:50:21 -0700 From: Tariq Toukan To: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , "David S. Miller" CC: Simon Horman , Donald Hunter , Jiri Pirko , Jonathan Corbet , Shuah Khan , Saeed Mahameed , "Leon Romanovsky" , Tariq Toukan , Mark Bloch , Shuah Khan , Chuck Lever , "Matthieu Baerts (NGI0)" , Carolina Jubran , Or Har-Toov , Moshe Shemesh , Dragos Tatulea , Shahar Shitrit , Daniel Zahka , Jacob Keller , Cosmin Ratiu , Parav Pandit , Shay Drori , "Adithya Jayachandran" , Kees Cook , "Daniel Jurgens" , , , , , , Gal Pressman , Jiri Pirko Subject: [PATCH net-next V4 01/12] devlink: Refactor resource functions to be generic Date: Wed, 1 Apr 2026 21:49:36 +0300 Message-ID: <20260401184947.135205-2-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20260401184947.135205-1-tariqt@nvidia.com> References: <20260401184947.135205-1-tariqt@nvidia.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF0000449D:EE_|LV8PR12MB9715:EE_ X-MS-Office365-Filtering-Correlation-Id: 4f8b7bbb-8602-47ef-7f41-08de901f98ad X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700016|376014|1800799024|7416014|82310400026|56012099003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: aUEiN+/CRTognrZQ070RIOxZGVEgfRd+LBsK0UN+We2ZqbAmoOhCaiXrHT6S72qU2Y7vVJLGXXb8ykauY4mcXGHxtWfdLceR4tdnWftcPqKFYi13OvI8L1qmWNO5xxtcoYtcULzJJIue9D4ZJeHQwpqjswnTatyUnoeDIMmi5DOwUbjMRkwAbyXtMTJx57MclZ5KdGyLMqkWyva0bSyBKj8T5oEdPLvnb5Zm4B9Ts/NRgg/mda2e+8qkbgasz10tcM2VP+9NU2HJVnSJ2Bsg8TTEW3XUnzMTt/ZQH7RxYOJM9+SEIsnU7txjhcZTX3ObcRAVA7FOR6rwQSAR6ApilnhRkhM09IL+4ciCgU5tTOqgEy1rFIWf+dwpNmVHUIoeqmC3dEmViWZu/XcXOiqiqQ+wYs2RYN3hyJUUs6piZEGfUFPqK/Oj0nOzhbma+KxiNxhlHyzgq4bKpd7yIWU2iMJ7zPsj2M+4jfA64UTL6bEX9/94hKzrEknK58SBIxBjaVugnFjw63OIYWGqHWhHOWW2ZhDqdJSXk0Z+ga1Ml17TCPM4jujrBT324lZBAx3vSINTtTtVNPzVmaZ3PsiYIjsendTNlUmF1o0ThhLGVw4UG0hqPMWoWyfUsavbgAeBNynOuiSl7NCGMUts7PAx8rq7ObNAF/LH/UVsXCowdTG9oawHK57ILUrVCm1hNVs8jSp1WNiB7gRb4IZMVM2xtJRRMUDP8MthywZ8RCaJCMQ8y79QbDG3Ex/58mN8Q/eFfE95KQ4TXpLHOxE4ZVYhMQ== X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(36860700016)(376014)(1800799024)(7416014)(82310400026)(56012099003)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: upU7cvWFp9huyq/iAwKBHv6Gnh5T2//H5xNJJNz8XPRL72bScgssFqn+7BtxmoLYzLalqWkIhcxDch8cFsj1Ykf5SqozmLTGMBuVKaF0N68Bq1RtbGWFqH0FOt0MQBwz+i2cHTdKdXG+Tv+ercgkufB8LFRdZoWuvE21e5L9ae68cbLx10rPl2eXjfeaezzCTgATzVjQVFNDhjZE9Ql9sesPnJAL+qzu0MAyJ3SQhQau6cwtf1BCPcgK+ZEHQTsaQX3/R0hHZa/qn5usHGDLnNJGvUPdFvfeyMU9ta0YHoOPZVZgFff9EVlCSIpn9DTPOfEkY2ugCAH5XoPK8s+Hbg9PF5O0bRQqff1T/QAVJ9Nsq9O+fHoF7xyhuOT7MhNunwX6TeghrQiF1Q7U4pujEmfhsKoHfEE4LF1z2h9aV3C24iKWMBdyY9o9FM4GbT3c X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Apr 2026 18:50:51.1239 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4f8b7bbb-8602-47ef-7f41-08de901f98ad X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN2PEPF0000449D.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9715 Content-Type: text/plain; charset="utf-8" From: Or Har-Toov Currently the resource functions take devlink pointer as parameter and take the resource list from there. Allow resource functions to work with other resource lists that will be added in next patches and not only with the devlink's resource list. Signed-off-by: Or Har-Toov Reviewed-by: Shay Drori Reviewed-by: Moshe Shemesh Reviewed-by: Jiri Pirko Signed-off-by: Tariq Toukan --- include/net/devlink.h | 2 +- net/devlink/resource.c | 114 ++++++++++++++++++++++++++--------------- 2 files changed, 73 insertions(+), 43 deletions(-) diff --git a/include/net/devlink.h b/include/net/devlink.h index 3038af6ec017..f5439d050eb0 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -1885,7 +1885,7 @@ int devl_resource_register(struct devlink *devlink, u64 resource_size, u64 resource_id, u64 parent_resource_id, - const struct devlink_resource_size_params *size_params); + const struct devlink_resource_size_params *params); void devl_resources_unregister(struct devlink *devlink); void devlink_resources_unregister(struct devlink *devlink); int devl_resource_size_get(struct devlink *devlink, diff --git a/net/devlink/resource.c b/net/devlink/resource.c index 351835a710b1..ee169a467d48 100644 --- a/net/devlink/resource.c +++ b/net/devlink/resource.c @@ -36,15 +36,16 @@ struct devlink_resource { }; =20 static struct devlink_resource * -devlink_resource_find(struct devlink *devlink, - struct devlink_resource *resource, u64 resource_id) +__devlink_resource_find(struct list_head *resource_list_head, + struct devlink_resource *resource, + u64 resource_id) { struct list_head *resource_list; =20 if (resource) resource_list =3D &resource->resource_list; else - resource_list =3D &devlink->resource_list; + resource_list =3D resource_list_head; =20 list_for_each_entry(resource, resource_list, list) { struct devlink_resource *child_resource; @@ -52,14 +53,23 @@ devlink_resource_find(struct devlink *devlink, if (resource->id =3D=3D resource_id) return resource; =20 - child_resource =3D devlink_resource_find(devlink, resource, - resource_id); + child_resource =3D __devlink_resource_find(resource_list_head, + resource, + resource_id); if (child_resource) return child_resource; } return NULL; } =20 +static struct devlink_resource * +devlink_resource_find(struct devlink *devlink, + struct devlink_resource *resource, u64 resource_id) +{ + return __devlink_resource_find(&devlink->resource_list, + resource, resource_id); +} + static void devlink_resource_validate_children(struct devlink_resource *resource) { @@ -314,26 +324,12 @@ int devlink_resources_validate(struct devlink *devlin= k, return err; } =20 -/** - * devl_resource_register - devlink resource register - * - * @devlink: devlink - * @resource_name: resource's name - * @resource_size: resource's size - * @resource_id: resource's id - * @parent_resource_id: resource's parent id - * @size_params: size parameters - * - * Generic resources should reuse the same names across drivers. - * Please see the generic resources list at: - * Documentation/networking/devlink/devlink-resource.rst - */ -int devl_resource_register(struct devlink *devlink, - const char *resource_name, - u64 resource_size, - u64 resource_id, - u64 parent_resource_id, - const struct devlink_resource_size_params *size_params) +static int +__devl_resource_register(struct devlink *devlink, + struct list_head *resource_list_head, + const char *resource_name, u64 resource_size, + u64 resource_id, u64 parent_resource_id, + const struct devlink_resource_size_params *params) { struct devlink_resource *resource; struct list_head *resource_list; @@ -343,7 +339,8 @@ int devl_resource_register(struct devlink *devlink, =20 top_hierarchy =3D parent_resource_id =3D=3D DEVLINK_RESOURCE_ID_PARENT_TO= P; =20 - resource =3D devlink_resource_find(devlink, NULL, resource_id); + resource =3D __devlink_resource_find(resource_list_head, NULL, + resource_id); if (resource) return -EEXIST; =20 @@ -352,12 +349,13 @@ int devl_resource_register(struct devlink *devlink, return -ENOMEM; =20 if (top_hierarchy) { - resource_list =3D &devlink->resource_list; + resource_list =3D resource_list_head; } else { struct devlink_resource *parent_resource; =20 - parent_resource =3D devlink_resource_find(devlink, NULL, - parent_resource_id); + parent_resource =3D __devlink_resource_find(resource_list_head, + NULL, + parent_resource_id); if (parent_resource) { resource_list =3D &parent_resource->resource_list; resource->parent =3D parent_resource; @@ -372,46 +370,78 @@ int devl_resource_register(struct devlink *devlink, resource->size_new =3D resource_size; resource->id =3D resource_id; resource->size_valid =3D true; - memcpy(&resource->size_params, size_params, - sizeof(resource->size_params)); + memcpy(&resource->size_params, params, sizeof(resource->size_params)); INIT_LIST_HEAD(&resource->resource_list); list_add_tail(&resource->list, resource_list); =20 return 0; } + +/** + * devl_resource_register - devlink resource register + * + * @devlink: devlink + * @resource_name: resource's name + * @resource_size: resource's size + * @resource_id: resource's id + * @parent_resource_id: resource's parent id + * @params: size parameters + * + * Generic resources should reuse the same names across drivers. + * Please see the generic resources list at: + * Documentation/networking/devlink/devlink-resource.rst + * + * Return: 0 on success, negative error code otherwise. + */ +int devl_resource_register(struct devlink *devlink, const char *resource_n= ame, + u64 resource_size, u64 resource_id, + u64 parent_resource_id, + const struct devlink_resource_size_params *params) +{ + return __devl_resource_register(devlink, &devlink->resource_list, + resource_name, resource_size, + resource_id, parent_resource_id, + params); +} EXPORT_SYMBOL_GPL(devl_resource_register); =20 -static void devlink_resource_unregister(struct devlink *devlink, - struct devlink_resource *resource) +static void devlink_resource_unregister(struct devlink_resource *resource) { struct devlink_resource *tmp, *child_resource; =20 list_for_each_entry_safe(child_resource, tmp, &resource->resource_list, list) { - devlink_resource_unregister(devlink, child_resource); + devlink_resource_unregister(child_resource); list_del(&child_resource->list); kfree(child_resource); } } =20 -/** - * devl_resources_unregister - free all resources - * - * @devlink: devlink - */ -void devl_resources_unregister(struct devlink *devlink) +static void +__devl_resources_unregister(struct devlink *devlink, + struct list_head *resource_list_head) { struct devlink_resource *tmp, *child_resource; =20 lockdep_assert_held(&devlink->lock); =20 - list_for_each_entry_safe(child_resource, tmp, &devlink->resource_list, + list_for_each_entry_safe(child_resource, tmp, resource_list_head, list) { - devlink_resource_unregister(devlink, child_resource); + devlink_resource_unregister(child_resource); list_del(&child_resource->list); kfree(child_resource); } } + +/** + * devl_resources_unregister - free all resources + * + * @devlink: devlink + */ +void devl_resources_unregister(struct devlink *devlink) +{ + __devl_resources_unregister(devlink, &devlink->resource_list); +} EXPORT_SYMBOL_GPL(devl_resources_unregister); =20 /** --=20 2.44.0