From nobody Sun Jun 14 07:35:30 2026 Received: from SN4PR2101CU001.outbound.protection.outlook.com (mail-southcentralusazon11012018.outbound.protection.outlook.com [40.93.195.18]) (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 389052E7F39; Fri, 1 May 2026 04:42:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.195.18 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777610554; cv=fail; b=DTrTqujCj+UlWEASBFYHGDmn41IAje044sNnwVXlkK+zJFrzrRNL00pJ1tzksmXDJwm1UehUayIawgrBJBblp6/+tN1b/n+4AY1neUfNI94iCmAqBsrCOYCUzYx4mXoBFkiX17v9nJQyP2YPaiJcgJj9a5I7qE+pD4fXWQ2N93E= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777610554; c=relaxed/simple; bh=qRPLqSmTdL7RgFrpA39YtEfL8GmJqojniB9toq76cd4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dyh42qXwAfcYFSywiAsa4FPL64tU0jZfNyCFfrYG3WU/pub4m0vIpvCS/n01tok2CJ0Yywh7W4HMwu9i/D6fXiV/c5sbrDLPtkjjGQ+Wj7c5rYQfdmwjEeYTefqvoTy68l3sFhW4i6p4KRAsvxbh13qHGT8eKovaPyhRfeZLzzc= 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=Yw72i8m2; arc=fail smtp.client-ip=40.93.195.18 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="Yw72i8m2" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RsEAWnH7aSeRKwz0SJj5uzWYrWlRL/jcNemX9CxaHKaRVi6zD1ppaUmqE+NI8wVBGS9ABHzrs4fxuzodefkIYFk0e9QAuEtQNGMug4dLPaRdo4h+uY/ArpxjBdFpOiW+9HTBg8vdgml33+9PDVsagCEY9hb6IC18sPxIs76dF1d7jtqWb6pOQlftjtP+QFrMophcSn88Or0jSiUG9CJ+o3lppuFkE7w5z1wW1tlwTPogbO5bv51pysKSV+4D4bYk58rGuvheWa/OyLRtm1rzxLtYcmXFVZo8LG7v8vi7BwBdx91MywnZFn81Zy3KvLyhEzlv5ntOW/yOO/LlwbOt0Q== 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=hKAm1Kw0m1lZImrfB9XzU16kod3fBCXGquKUYeNU6xA=; b=QXetdFe3mDPy634RRFdqJncM4JlJmaLVLQjDjU8iEJK0i0bYEvx5M4Gv7HyHm6JxYdV5ycWmMvHwfwru7ZkOpGCME+OCtzf7Wm2nmMvhXJ8+8rLIxpcVWFfqmGsQ0hxGUIo3DDzpP4LiVLTKBsaX3cQ6LAtPH36w7kl+HgauuErFOkUDzcTTkLMGtP/EZQoQcz2iIA4j/JDnldSAaRbLnZ965tm5/L7sknuDBp1bm/UrxJdAeyKJn7VmSoFNOFYFNYIwUSWDqSQ4LKEAa1Qa0HCM3XRwOO8+gwSGoyiuQiHCEfauRgXbjXcEGPiUFC4aVK0PJmtLK4jI1tdG0VeesQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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=hKAm1Kw0m1lZImrfB9XzU16kod3fBCXGquKUYeNU6xA=; b=Yw72i8m2zHURNn1lJLNmP2BcpjK68z41QQ75Zgx6WDf+X3gYwqoS/uykcHGd4T6HqC1f0Dmxi7vpfbNNU8j6fCa4MOq+z2vInnwT+tkAzqQaelJgSMbk9O1YN589Tq6Ad2vtAdK5s3O5QsquFJfY0EvsJxfpcMHb7FjrMrDVDKlyPDz7vQ0YUJaqGE1jIpCgvI228CMxuzuAZ/38sPjnaXuzm6B/hID+Eciy1CCHrmOX0b7dHk3J9ko3RLaKhVmg9Fa3AhNSpL6DzNY75i7EZN5lRHY/50IVDWeyX/qKGV1D2pnZ1mJhZPy9kdKSkyKUvp4TS266b608G3a0aAregw== Received: from BN9PR03CA0240.namprd03.prod.outlook.com (2603:10b6:408:f8::35) by CH0PR12MB8580.namprd12.prod.outlook.com (2603:10b6:610:192::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.22; Fri, 1 May 2026 04:42:25 +0000 Received: from BN3PEPF0000B074.namprd04.prod.outlook.com (2603:10b6:408:f8:cafe::d4) by BN9PR03CA0240.outlook.office365.com (2603:10b6:408:f8::35) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9870.21 via Frontend Transport; Fri, 1 May 2026 04:42:24 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BN3PEPF0000B074.mail.protection.outlook.com (10.167.243.119) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9891.9 via Frontend Transport; Fri, 1 May 2026 04:42:24 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Thu, 30 Apr 2026 21:42:12 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Thu, 30 Apr 2026 21:42:12 -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; Thu, 30 Apr 2026 21:42:08 -0700 From: Tariq Toukan To: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , "David S. Miller" CC: Saeed Mahameed , Leon Romanovsky , Tariq Toukan , Mark Bloch , "Moshe Shemesh" , Akiva Goldberger , , , , Gal Pressman , Dragos Tatulea Subject: [PATCH net-next 1/3] net/mlx5: Relax capability check for eswitch query paths Date: Fri, 1 May 2026 07:41:54 +0300 Message-ID: <20260501044156.260875-2-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20260501044156.260875-1-tariqt@nvidia.com> References: <20260501044156.260875-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: BN3PEPF0000B074:EE_|CH0PR12MB8580:EE_ X-MS-Office365-Filtering-Correlation-Id: 9067e584-0504-427a-11e4-08dea73c0a82 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|82310400026|36860700016|22082099003|18002099003|56012099003; X-Microsoft-Antispam-Message-Info: Rr71VDLh1e8hfKm803XMiiDw6FKfd6vOUJu7WWx4t9k3wYoLVddkWJovGAtgyu82e25FO9I7fL9KqUVesi2ewpiZE6O8GF5Nwv8SFvK/CZDrcD/lREQPyidAi8NzSxYaf4XQMTgDHLaj8Fayk7DQbdNh3tJ6/7+lrW/ZWOz2DtZd4FKHy2ASI+B6SBN4IiYsNmMBybBx7niwjMphpmiKHJZFgXAwOlu7Q8jm98w9Ez7+ohxN2l10MFAKlFdOIt+M+URJwL18C7AYRDS+pwmRI2zSwtYbg4RB13AQ2KpXUsrn6Tt/Uw9wnPsMw1DRI+4LwYfBW3e9BTY+kBfwztubf118AEufBVBxo8OcNva41lxowV9P9UOQrZegP+0AtlVgBRvbtNPXkzei5rWbFRICl50thGZKxBTuO35l4pq723nQook277mPFB0404Vs6JyVyAXrLbWjSngMcQbYWrmA0F3Bdd3ZXMdZ9Y1zL+wCTUnJss9wLIWhv52I/N8W7OEheFq7L0V08GVcLxO1cY3EJxSNlsKuHISHYRX+ASFeSW1glsuBpDmu1c6m7s9fXNd1HUB7ecl5U7V8VWq9iwabHnyUcgWQaSIrL5nWSUm8obgv0XM+375hrUAkJhDT/uuNpndaGDWgAHSnIfMDHRwA98T72wGNmutRXa6vg8r2Cds3SoBBy3bvuFeB4xhnWHSxQfUaBROyoRAGR6fycZ5q6d4JIskQP6E0c9sIAs8PnP0= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(376014)(1800799024)(82310400026)(36860700016)(22082099003)(18002099003)(56012099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Uo6c/t4noq5ijHq++eCFiOz+fbmVvrp7GseW0VwgFbJlOVw9IXeCZmPL0Gh+rB6r+Qz7+w4Wl7qvd2ph/NTLq3UE9FMtgz7rTFK/VkSb51VSnnk9sCOSuX1BW45eIzPi0qK8GrIuMq18YmadUIT+KQtkppLXZxaPNC0WnQ1TJHxEyw2uR7o4cYz9DpxnimMQIzmwi0oAMAdyVcsajvUvufn05stiSdtyAZN7pU9dsGVc5WI5XFECl9nFPnXMBPtSaMpFoItsRNQlziMgJq66ysx3+eevbT5PG+C4r48DJKlyXaCNT1YKtHqzchv02aqymYhrSs9gQoD0iyuceo1ziKCmVkKXUEeLkCIBlf9eeWo0zB1d7m7MLqeiRvrc2mVtLStZ3EHHd9YlTPDn9CA8yyXF+W/AibD+bQtUtleH/Ojhi0GHDbz4pzR9KeKuwQLi X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 May 2026 04:42:24.7565 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9067e584-0504-427a-11e4-08dea73c0a82 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.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B074.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB8580 Content-Type: text/plain; charset="utf-8" From: Moshe Shemesh Several eswitch functions that only query other functions' HCA capabilities or read cached vport state are guarded by the vhca_resource_manager capability. This capability is required for set_hca_cap operations but query_hca_cap of other functions only requires the vport_group_manager capability. Relax the capability check from vhca_resource_manager to vport_group_manager in the following query-only paths: - mlx5_esw_vport_caps_get() - queries other function general caps - esw_ipsec_vf_query_generic() - queries other function ipsec cap - mlx5_devlink_port_fn_migratable_get() - reads cached vport state - mlx5_devlink_port_fn_roce_get() - reads cached vport state - mlx5_devlink_port_fn_max_io_eqs_get() - queries other function caps - mlx5_esw_vport_enable/disable() - vhca_id map/unmap Functions that perform also set_hca_cap (migratable_set, roce_set, max_io_eqs_set, esw_ipsec_vf_set_generic, esw_ipsec_vf_set_bytype) retain the vhca_resource_manager requirement. Signed-off-by: Moshe Shemesh Reviewed-by: Akiva Goldberger Reviewed-by: Mark Bloch Signed-off-by: Tariq Toukan --- .../net/ethernet/mellanox/mlx5/core/esw/ipsec.c | 2 +- drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 6 +++--- .../ethernet/mellanox/mlx5/core/eswitch_offloads.c | 14 ++++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/ipsec.c b/drivers/= net/ethernet/mellanox/mlx5/core/esw/ipsec.c index 8b12c3ae0cf7..4811b60ea430 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/esw/ipsec.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/ipsec.c @@ -12,7 +12,7 @@ static int esw_ipsec_vf_query_generic(struct mlx5_core_de= v *dev, u16 vport_num, void *hca_cap, *query_cap; int err; =20 - if (!MLX5_CAP_GEN(dev, vhca_resource_manager)) + if (!MLX5_CAP_GEN(dev, vport_group_manager)) return -EOPNOTSUPP; =20 if (!mlx5_esw_ipsec_vf_offload_supported(dev)) { diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/ne= t/ethernet/mellanox/mlx5/core/eswitch.c index 66a773a99876..e0eafcf0c52a 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c @@ -806,7 +806,7 @@ static int mlx5_esw_vport_caps_get(struct mlx5_eswitch = *esw, struct mlx5_vport * void *hca_caps; int err; =20 - if (!MLX5_CAP_GEN(esw->dev, vhca_resource_manager)) + if (!MLX5_CAP_GEN(esw->dev, vport_group_manager)) return 0; =20 query_ctx =3D kzalloc(query_out_sz, GFP_KERNEL); @@ -938,7 +938,7 @@ int mlx5_esw_vport_enable(struct mlx5_eswitch *esw, str= uct mlx5_vport *vport, vport->info.trusted =3D true; =20 if (!mlx5_esw_is_manager_vport(esw, vport_num) && - MLX5_CAP_GEN(esw->dev, vhca_resource_manager)) { + MLX5_CAP_GEN(esw->dev, vport_group_manager)) { ret =3D mlx5_esw_vport_vhca_id_map(esw, vport); if (ret) goto err_vhca_mapping; @@ -976,7 +976,7 @@ void mlx5_esw_vport_disable(struct mlx5_eswitch *esw, s= truct mlx5_vport *vport) arm_vport_context_events_cmd(esw->dev, vport_num, 0); =20 if (!mlx5_esw_is_manager_vport(esw, vport_num) && - MLX5_CAP_GEN(esw->dev, vhca_resource_manager)) + MLX5_CAP_GEN(esw->dev, vport_group_manager)) mlx5_esw_vport_vhca_id_unmap(esw, vport); =20 if (vport->vport !=3D MLX5_VPORT_HOST_PF && diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/d= rivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c index 69ddf56e2fc9..392d8f364db6 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c @@ -4677,8 +4677,9 @@ int mlx5_devlink_port_fn_migratable_get(struct devlin= k_port *port, bool *is_enab return -EOPNOTSUPP; } =20 - if (!MLX5_CAP_GEN(esw->dev, vhca_resource_manager)) { - NL_SET_ERR_MSG_MOD(extack, "Device doesn't support VHCA management"); + if (!MLX5_CAP_GEN(esw->dev, vport_group_manager)) { + NL_SET_ERR_MSG_MOD(extack, + "Device doesn't support vport group management"); return -EOPNOTSUPP; } =20 @@ -4753,8 +4754,9 @@ int mlx5_devlink_port_fn_roce_get(struct devlink_port= *port, bool *is_enabled, struct mlx5_eswitch *esw =3D mlx5_devlink_eswitch_nocheck_get(port->devli= nk); struct mlx5_vport *vport =3D mlx5_devlink_port_vport_get(port); =20 - if (!MLX5_CAP_GEN(esw->dev, vhca_resource_manager)) { - NL_SET_ERR_MSG_MOD(extack, "Device doesn't support VHCA management"); + if (!MLX5_CAP_GEN(esw->dev, vport_group_manager)) { + NL_SET_ERR_MSG_MOD(extack, + "Device doesn't support vport group management"); return -EOPNOTSUPP; } =20 @@ -5076,9 +5078,9 @@ mlx5_devlink_port_fn_max_io_eqs_get(struct devlink_po= rt *port, u32 *max_io_eqs, int err; =20 esw =3D mlx5_devlink_eswitch_nocheck_get(port->devlink); - if (!MLX5_CAP_GEN(esw->dev, vhca_resource_manager)) { + if (!MLX5_CAP_GEN(esw->dev, vport_group_manager)) { NL_SET_ERR_MSG_MOD(extack, - "Device doesn't support VHCA management"); + "Device doesn't support vport group management"); return -EOPNOTSUPP; } =20 --=20 2.44.0 From nobody Sun Jun 14 07:35:30 2026 Received: from SN4PR2101CU001.outbound.protection.outlook.com (mail-southcentralusazon11012024.outbound.protection.outlook.com [40.93.195.24]) (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 105662F6591; Fri, 1 May 2026 04:42:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.93.195.24 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777610560; cv=fail; b=ldiKDcToNVVP2EwpRCXQcPQyK5MmtSvaErbK9XDiYs6WMm0mGbjljy8YssTbFBEKVKlrrzC/87THMW0zSgMdQeADOCgP1+tgLx3d1sPeKyaMJcUAV9lOFJa6s/odpvqSpEh83T4Sfj++yu06bYcoxexUklbWbcD5cnHPlhfJWnA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777610560; c=relaxed/simple; bh=K2/MIV7+tJh+CZBnb8pYkHHcDDIbavN7ZupkRXfFxYM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LGnccYiLmweBvBhlG/1A6cB1XCQC5gfAAiL6wuxd1CB0AAcUaiAjKy4duqU8iiZwDkvu5IFwMgJP/wa3uDQGCSbekb+TEDMWmTUMX471WWRomKB3ZTo3xcXnLQHgT7TytlSwbLF+yG9FJ7bzp+DgFy0YR6HgdlQTTfmzNk27x9Y= 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=k473HF2N; arc=fail smtp.client-ip=40.93.195.24 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="k473HF2N" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NGDehPNvs8GGlKMLMLeQFu98jcJeAs3dW6OmLEMICCRPy4Z7iZGqN1wlHkGimgBvM5zVymk6VAFXiu6oCbmE3/lYf9IQt0VbZ+f3A0uyM6UH7cxSt+usdf+8xKZhquAL63zU5jTbdQF7yjFrYwyOirU/dUcsLiAB174RjWf7pYB0ad9wwTlNL0LkVie2mgasAp8RJSl9EpR2D6kRbGMcZEKgGo7qAPDMojRqahqyYO4bW8pbLy1zs1lIiIDICDXcb95dARjZ+6OEsFMYPA45WQvAvZlOGMXG+kiYF/k+UqXsqHrXs5ctB2/tBCSxmhdCGa3kz9Bjct9LaFa/cAV4hA== 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=W2EZ5NYUoKQT3I16W3+5ooLJ8PUS/E3jaZnYCanYk2c=; b=dyCx3J4lwZX5AAI43NMhi4sFvGfT279U8KqDCqo4xo8iT3wp4EKJCwiZ78n4pb9HIaK3o86WjQoqvqoE81U0bREZ2dw5qZJeKCR9RXGzfLVISzc9ivr5Z2kyzV2i0/6b0CP2sdl0kWujQSjIEm815j7mfImVNpoCYF3tXHq5sV/aX0jFHwr8mS49fpQH1TqVNniArsPIa/8jMZA6IS765ANG3ms4iyAMswMbbB/Msva0MTxYDtdd4KXTtJtObfJSxy7DMJJS1BwN+2Ks1cgt4orUS4lqiwoIht1LQFKSaS21BAUcCCSzbRIJt1FJNgfJrzEE12JXZLLxbC8ncPCYBQ== 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=W2EZ5NYUoKQT3I16W3+5ooLJ8PUS/E3jaZnYCanYk2c=; b=k473HF2NJDXJu3/g2sBLg0oy0jrd5/KqApEs0pqe4nrFs+PJdxzqzdGle2Vd+4klYODwpfH8emU13mgWabsaagwOaiyEM88+Pz8zMxK6Uec8W/qXOKLRKFuaYWqg5aP6BQIKitAb6EPgjM3nc41mqogCRXTvd4iKiv4Q0HnQr584disbHNBwyhZENMFbef/OX5CZsQDwzkswuNuK4jISBieSWxxf9s0mq8QwDfyhELrHevrFurf3X1BTF2LeiAM9rz8SIxRbsZeic6tRKJydyZHtBryvVBGGSbtS7D4Y2W5Ih3VIcrFeuMy7R4jlNi5cBbWu3YQcS03klK+f37rfIQ== Received: from PH1PEPF000132E6.NAMP220.PROD.OUTLOOK.COM (2603:10b6:518:1::26) by CY1PR12MB9676.namprd12.prod.outlook.com (2603:10b6:930:104::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.12; Fri, 1 May 2026 04:42:32 +0000 Received: from CY4PEPF0000FCBF.namprd03.prod.outlook.com (2a01:111:f403:f910::) by PH1PEPF000132E6.outlook.office365.com (2603:1036:903:47::3) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9870.21 via Frontend Transport; Fri, 1 May 2026 04:42:32 +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 CY4PEPF0000FCBF.mail.protection.outlook.com (10.167.242.101) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9891.9 via Frontend Transport; Fri, 1 May 2026 04:42:32 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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; Thu, 30 Apr 2026 21:42:17 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Thu, 30 Apr 2026 21:42:17 -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; Thu, 30 Apr 2026 21:42:13 -0700 From: Tariq Toukan To: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , "David S. Miller" CC: Saeed Mahameed , Leon Romanovsky , Tariq Toukan , Mark Bloch , "Moshe Shemesh" , Akiva Goldberger , , , , Gal Pressman , Dragos Tatulea Subject: [PATCH net-next 2/3] net/mlx5: Make debugfs page counters by function type dynamic Date: Fri, 1 May 2026 07:41:55 +0300 Message-ID: <20260501044156.260875-3-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20260501044156.260875-1-tariqt@nvidia.com> References: <20260501044156.260875-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: CY4PEPF0000FCBF:EE_|CY1PR12MB9676:EE_ X-MS-Office365-Filtering-Correlation-Id: e1c30a58-f046-47c4-f80a-08dea73c0ed9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|36860700016|376014|56012099003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: RiBx9tagm+iJjy3OK11sZgaYJZDKbO0jVJxmcQAsnP4BVG/kisLqmmYiJwpMp7AmVPYf62DaN78F4XuHx67odIrDgcvC3cKD6SAIR/mWX5r2GOYc6qxMGbpiM6iE2Dni9H7R+22XUc4+IFFggksRrAkZHQ3EnDxwf4a1Qni3UGrtMe67vyOgUfjEo2JIPYynSj5Afw6b9fPlsJhlnvNX+8njjLofjajBOZC1sozXGzAq3LAXZ152N8Vvwx3GyzoVW5yT1Zx9ln81lnOdbZkkBWfSY2YFiIB+uKPhhjXHDqCqVODM3xPt05f77h06Nxjh3MYNQMSS8/bnovS8yRlbOSTWyiiHFHWPmPEXR/SIqMtLbR+7EQSTWZwuG8+K9HcEY8zaBmZu54fX78R68+BMFZcF4mGWUV2HGk9YYp7HIkcFDwl9hvy7Teh44ivYUeeckhsX+Med215F8NHNN65SwHBEeSthSDwC5Y46ygMgyQkbtJPkIRbSsTwPMNpgJeQm0Bca07BZaW1a+BUz/RKt6A/TPqZAGwUcuTwTErGQjF0Z/xC96tlbyQMm2m8wliS3rRGTuMo5wLf4VSR0I6EkAU27GQHErFJTIxu7o0sYVvzZVDfnZVNGtGCnrXAHfGlNap/GC8qpJkKVFwoJXm2qh/qleDYT6zmBD70h2GDH7wr5ahsmcfXiAz/7KxfPWuRTWQlxC6/9irRT+2GJMBcFql+jMm+4RylxhDWN4cB6izQ= 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)(82310400026)(1800799024)(36860700016)(376014)(56012099003)(22082099003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: SbhHGXla3SEGOgNR4FQ6xh/sDEXPpM9HGCtIWaA0ay1tS2hnIQcDEeMUPi+z0VOIvSOQ1Ycsl2ceyY8AvybN2DShZdMmRTS8NUxA/Xe3SyOJQrjAgD6uzfhAEiVFSxILS/opAPGzKWB/bghjmpqx8wZEqH5bAjlnsYPEp8UY6O0D7vU7bfESUWToU5xsThLxqYTp01ByRRhOEj4RWIiZHuosI+S0YkVLN8b4x8Xdkbp0wEjqOXQbzphpIlqvHWkCMMd0/tTI4AuyHLstG0iF4r2zOXboBWhcE4/SGxFqmKvLzFpzqjihvsQhaDfy4ZWogcZ+RgqaeIe1b/Umqev2AOxzhhonaFCulIXhVVck30wwClDJst+HArs26CqjICJhDO+mCtvW4uEsuBNSJuN7ZZuJE6wo3di+aCvaP11dMYy5ptqFrYaUzASB8O2I0rj9 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 May 2026 04:42:32.1076 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e1c30a58-f046-47c4-f80a-08dea73c0ed9 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: CY4PEPF0000FCBF.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR12MB9676 Content-Type: text/plain; charset="utf-8" From: Moshe Shemesh Make the per function type debugfs page counters dynamically added after mlx5_eswitch_init(). When page management operates in vhca_id mode, only the function acting as either eSwitch or vport manager can initialize the eSwitch structure and translate the vhca_id to function type for the functions to which it supplies pages. The next patch will add support for page management in vhca_id mode. Signed-off-by: Moshe Shemesh Reviewed-by: Akiva Goldberger Reviewed-by: Mark Bloch Signed-off-by: Tariq Toukan --- .../net/ethernet/mellanox/mlx5/core/debugfs.c | 39 +++++++++++++++++-- .../net/ethernet/mellanox/mlx5/core/main.c | 7 +++- include/linux/mlx5/driver.h | 2 + 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c b/drivers/ne= t/ethernet/mellanox/mlx5/core/debugfs.c index 8fe263190d38..6347957fefcb 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/debugfs.c @@ -285,10 +285,6 @@ void mlx5_pages_debugfs_init(struct mlx5_core_dev *dev) pages =3D dev->priv.dbg.pages_debugfs; =20 debugfs_create_u32("fw_pages_total", 0400, pages, &dev->priv.fw_pages); - debugfs_create_u32("fw_pages_vfs", 0400, pages, &dev->priv.page_counters[= MLX5_VF]); - debugfs_create_u32("fw_pages_ec_vfs", 0400, pages, &dev->priv.page_counte= rs[MLX5_EC_VF]); - debugfs_create_u32("fw_pages_sfs", 0400, pages, &dev->priv.page_counters[= MLX5_SF]); - debugfs_create_u32("fw_pages_host_pf", 0400, pages, &dev->priv.page_count= ers[MLX5_HOST_PF]); debugfs_create_u32("fw_pages_alloc_failed", 0400, pages, &dev->priv.fw_pa= ges_alloc_failed); debugfs_create_u32("fw_pages_give_dropped", 0400, pages, &dev->priv.give_= pages_dropped); debugfs_create_u32("fw_pages_reclaim_discard", 0400, pages, @@ -300,6 +296,41 @@ void mlx5_pages_debugfs_cleanup(struct mlx5_core_dev *= dev) debugfs_remove_recursive(dev->priv.dbg.pages_debugfs); } =20 +void mlx5_pages_by_func_type_debugfs_init(struct mlx5_core_dev *dev) +{ + struct dentry *pages =3D dev->priv.dbg.pages_debugfs; + + if (!pages) + return; + + if (!dev->priv.eswitch && + MLX5_CAP_GEN(dev, icm_mng_function_id_mode) =3D=3D + MLX5_ID_MODE_FUNCTION_VHCA_ID) + return; + + debugfs_create_u32("fw_pages_vfs", 0400, pages, + &dev->priv.page_counters[MLX5_VF]); + debugfs_create_u32("fw_pages_ec_vfs", 0400, pages, + &dev->priv.page_counters[MLX5_EC_VF]); + debugfs_create_u32("fw_pages_sfs", 0400, pages, + &dev->priv.page_counters[MLX5_SF]); + debugfs_create_u32("fw_pages_host_pf", 0400, pages, + &dev->priv.page_counters[MLX5_HOST_PF]); +} + +void mlx5_pages_by_func_type_debugfs_cleanup(struct mlx5_core_dev *dev) +{ + struct dentry *pages =3D dev->priv.dbg.pages_debugfs; + + if (!pages) + return; + + debugfs_lookup_and_remove("fw_pages_vfs", pages); + debugfs_lookup_and_remove("fw_pages_ec_vfs", pages); + debugfs_lookup_and_remove("fw_pages_sfs", pages); + debugfs_lookup_and_remove("fw_pages_host_pf", pages); +} + static u64 qp_read_field(struct mlx5_core_dev *dev, struct mlx5_core_qp *q= p, int index, int *is_str) { diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/e= thernet/mellanox/mlx5/core/main.c index 74827e8ca125..a242053f3a58 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c @@ -987,11 +987,12 @@ static int mlx5_init_once(struct mlx5_core_dev *dev) mlx5_core_err(dev, "Failed to init eswitch %d\n", err); goto err_sriov_cleanup; } + mlx5_pages_by_func_type_debugfs_init(dev); =20 err =3D mlx5_fpga_init(dev); if (err) { mlx5_core_err(dev, "Failed to init fpga device %d\n", err); - goto err_eswitch_cleanup; + goto err_page_debugfs_cleanup; } =20 err =3D mlx5_vhca_event_init(dev); @@ -1034,7 +1035,8 @@ static int mlx5_init_once(struct mlx5_core_dev *dev) mlx5_vhca_event_cleanup(dev); err_fpga_cleanup: mlx5_fpga_cleanup(dev); -err_eswitch_cleanup: +err_page_debugfs_cleanup: + mlx5_pages_by_func_type_debugfs_cleanup(dev); mlx5_eswitch_cleanup(dev->priv.eswitch); err_sriov_cleanup: mlx5_sriov_cleanup(dev); @@ -1072,6 +1074,7 @@ static void mlx5_cleanup_once(struct mlx5_core_dev *d= ev) mlx5_sf_hw_table_cleanup(dev); mlx5_vhca_event_cleanup(dev); mlx5_fpga_cleanup(dev); + mlx5_pages_by_func_type_debugfs_cleanup(dev); mlx5_eswitch_cleanup(dev->priv.eswitch); mlx5_sriov_cleanup(dev); mlx5_mpfs_cleanup(dev); diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h index 04b96c5abb57..b460b3bae195 100644 --- a/include/linux/mlx5/driver.h +++ b/include/linux/mlx5/driver.h @@ -1034,6 +1034,8 @@ void mlx5_pagealloc_start(struct mlx5_core_dev *dev); void mlx5_pagealloc_stop(struct mlx5_core_dev *dev); void mlx5_pages_debugfs_init(struct mlx5_core_dev *dev); void mlx5_pages_debugfs_cleanup(struct mlx5_core_dev *dev); +void mlx5_pages_by_func_type_debugfs_init(struct mlx5_core_dev *dev); +void mlx5_pages_by_func_type_debugfs_cleanup(struct mlx5_core_dev *dev); int mlx5_satisfy_startup_pages(struct mlx5_core_dev *dev, int boot); int mlx5_reclaim_startup_pages(struct mlx5_core_dev *dev); void mlx5_register_debugfs(void); --=20 2.44.0 From nobody Sun Jun 14 07:35:30 2026 Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011066.outbound.protection.outlook.com [52.101.52.66]) (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 36A51218EB1; Fri, 1 May 2026 04:42:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.52.66 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777610566; cv=fail; b=hTJzztMvx3r+ziTMdhJGvG0qVKOkVGpqWKOZqbAAJTM6R5iLjsAa+JqeNRsiehF5w3KtkVS86Qu7YgBGMoxlN5ZjNXBPqmTmhhYDxR6QR8VcrNX2ZNPzxj7f1oOn8Z4/2cLSlOswaoL0rZvJzznaT08FpxkXTm98PmXAHZr+8J8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777610566; c=relaxed/simple; bh=Om35aU01Q3mpzqMnST7rprSIW33NoFxDLnG0fCcXlUo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ROXdNvC1c1Wea8m4Lvp7xbTE+s4HjKtqamu9SxSjGotTz2vBkrfMrqW9mnrI5RLa0kbRs6PK90aMJp/BNn827nuhbIV0512n0KDsZjsPlyiQUQl7cLy0Q+Lxk1Qcn91+FAy/8i/0gUOO7oRIfZO5sThzgLi6B8eV1mRUr4GM6/Y= 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=QhOK9IoG; arc=fail smtp.client-ip=52.101.52.66 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="QhOK9IoG" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pmrzNMu6CznwUnGYe6mzi2fbLXuh6buoxgKr/DPe7grxEERqoGVSTXRlgFF6XjjZDLw9p5kbq9fDM/DgYhhV4tzLm34VAbYWY2Iu/hLyQxrGU6hQf5f/6keIDYOoGTHEWsyl8McRXpk88mLEVsqT3ZXTX6ZXyjDgpReS2kfMAA8xsT3mkoa1f0BQvVgb0u5wjeNNayRSM3WTL0KVE64bDNnDC8KFtda5o6vJGAjhMv9yA8H5A+MfHwfhgTxPEv+J669v5/P8+5/r5YwOcsW/qA0kHw/HKVK9PV0c/CNMpBTnx/l1C7PrsB73HI4u48ftkBDPvikJs/4pNRlnL3deZg== 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=w9GR7Tu7iF8rZ9R39TNUJ2FCY2aN6JcmSCKN7wmo+gA=; b=LfNmD6wNYVU0cbJfrKCFnfM7b/F8StDWDwy+oKEH3PBxypX8xq7dV0WSuH38bdgZ2WLNtGzLqLmE7+auD4f96mGzGVQv+2NESU8Rjg9EkjA+QXDdtC4Kc8+Qc6sYtg0YT+JVa2Kesrh/oGjuvwtOnH5Dl7oUAe46ZSeCcPOqj2OwVBDhfkNzKduQUfTc9x5Zyi2uBQV/qJFsPEbanhHvf3Q++yvopxz0j3DoBlYcbGk+3QHNncJwKxd3JXpvv43OqcNL05QP0QdvzIlVG5hsS1jL64UrWrYXy3hCXJQks48XwIyX1nDgcK+zJEF3T0sso0ao/IDqcBdVU799u1IAlA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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=w9GR7Tu7iF8rZ9R39TNUJ2FCY2aN6JcmSCKN7wmo+gA=; b=QhOK9IoGjZBG/1rnbX2aeUHK7PDjLupHTeEfvqwnlgrwqNa/54tlvU9cQJ5zBfTAYXjC6Z8dFXkF2Xd1civLZH6hwSPi68azpxYNUGK2/0SQMv1bZOMaotDPnbVkhwd4GtcQJ4AQsPKvCqwjueX4cwYN/q04Z7JfFtmCgySIcS9eXXNujymsgkaRuTYOZCZX2RkcGBtkk2OKh4aptK2CURW90YFDVf+FXdJdibo7HEv7PXEso/WTLKLATrdjMY9aLM6uyBKpHLBdAOtZxN2n9JhczY1UMyDHEDoqHVH3T1LGKSqR4c0XEU9QR7/z44cvrj502ndTOUpXGXRxUC0xxQ== Received: from BN9PR03CA0792.namprd03.prod.outlook.com (2603:10b6:408:13f::17) by PH8PR12MB8432.namprd12.prod.outlook.com (2603:10b6:510:25b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9870.22; Fri, 1 May 2026 04:42:34 +0000 Received: from BN3PEPF0000B076.namprd04.prod.outlook.com (2603:10b6:408:13f:cafe::9c) by BN9PR03CA0792.outlook.office365.com (2603:10b6:408:13f::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9870.22 via Frontend Transport; Fri, 1 May 2026 04:42:34 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BN3PEPF0000B076.mail.protection.outlook.com (10.167.243.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9891.9 via Frontend Transport; Fri, 1 May 2026 04:42:34 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Thu, 30 Apr 2026 21:42:22 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Thu, 30 Apr 2026 21:42:21 -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; Thu, 30 Apr 2026 21:42:17 -0700 From: Tariq Toukan To: Eric Dumazet , Jakub Kicinski , Paolo Abeni , Andrew Lunn , "David S. Miller" CC: Saeed Mahameed , Leon Romanovsky , Tariq Toukan , Mark Bloch , "Moshe Shemesh" , Akiva Goldberger , , , , Gal Pressman , Dragos Tatulea Subject: [PATCH net-next 3/3] net/mlx5: Add VHCA_ID page management mode support Date: Fri, 1 May 2026 07:41:56 +0300 Message-ID: <20260501044156.260875-4-tariqt@nvidia.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20260501044156.260875-1-tariqt@nvidia.com> References: <20260501044156.260875-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: BN3PEPF0000B076:EE_|PH8PR12MB8432:EE_ X-MS-Office365-Filtering-Correlation-Id: 4220014e-6b69-4fc1-54d8-08dea73c1037 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|376014|36860700016|1800799024|18092099006|18002099003|56012099003|22082099003; X-Microsoft-Antispam-Message-Info: 8xGasQUoQAfYBYXcIkStn+CdJdZQbV63ITeAi/SsXy7WWJkfBhLtQjdqQ89hUVzjBF3220SzmWYORnwdBsTzxNiBzLnz3ikVPL+Om1AgMZONwonONj6rqwRfiT4CvoAGojO6x+NZYEo+xpjgF95e5OfKdGZ18dfEK6kTfOmZp/yCv564cvZ67VOvsvd7QygCFBEkr91Yo9TAXmpGvO4PjT5bE1LJFD02b+Rkz4GZLrp0gTYoBPltnQLfbr65bmwzBY6AmYYydDndJA0wQURMrIbzLZwc93+75Wgusjd5tQDXpkAHTsSATM3vwdIvqzhKJn0JuybG6hhLb62tmkQ+tbDbtLKvV7HB8fj370YNclousV0NY2fKmMPnU6baeemDoHyt653qPb2Kicz2wbH8zVvMo4QBxlan0sKn7oPZvGK3ORFw8rvtlOHdPetxeIxhoYvYzxYJCaUE0sq78fEsewa2zyhyoPdg0IrW/ArQIZjaVL4FX7NnFQhHdouVtCbyyDCaFkT+kRncgJ1LzYWW0YD9OZG2hQ7YuRW9Krh4kG+aj8T2YVmboPvlIvF+yNR+g0s0IZk4DI+mxkALIC/lZdye9Sx0RQQG0gsDyHwNUn3ul7gBVR0Lzulfp98JXhVSVfYS9PBzbn76vFR7eSN6NLLScHGiGCjsuv54bU1LHBtFlv0EUBqR1IDwY3BrVvEi9NCEcQGhG0tB6os7aVrjDDLQL256Oj0lBaNVSxTVaRY= X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(376014)(36860700016)(1800799024)(18092099006)(18002099003)(56012099003)(22082099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Vpb8FK7Am5MgE3RzHzSjYe8gcffouTNVEhdlE6eNuxkBhRjzSbIP+MvAOpAAU2Ft3NrAiinD071ihZz1f47PXFt5GHQbOEz/SQBWVMvj11P22Ouz+F8cyPNrsetQtyoQPTEqxGLB2MCOvJjO7oxsFE+lUZyo66WZHeDJ2laDrnHnpFysQaz2fkwF1g864SfwNmeLQVBqrhK5UwYT2pGUU2wc5sDoTIskYyx/SlmlfLwgX6FFP/kERFl28aJsqqnYG77CCM81McShnPH8vmFqgT58xWwp792JwvV0gQAx92B/HMl9/VWVyCFA7gfsvGf+pDxMI8yRcaNqLjzHX3stj7qVN1p+tyAFP/X61I/KH7UB5VD0FPdW4IE8NLskK/v9R2wHLwiKtjPTXSb5uiVFSmnSjnADss/etk3A3rxKc2221typF8cSe93NiCuyCGFW X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 May 2026 04:42:34.3332 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4220014e-6b69-4fc1-54d8-08dea73c1037 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.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN3PEPF0000B076.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB8432 Content-Type: text/plain; charset="utf-8" From: Moshe Shemesh Add support for VHCA_ID-based page management mode. When the device firmware advertises the icm_mng_function_id_mode capability with MLX5_ID_MODE_FUNCTION_VHCA_ID, page management operations between the driver and firmware may use vhca_id instead of function_id as the effective function identifier, and the ec_function field is ignored. Update page management commands to conditionally set ec_function field only in FUNC_ID mode. Boot page allocation always uses FUNC_ID mode semantics for backward compatibility, as the capability bit is only available after set_hca_cap(). If after set_hca_cap() VHCA_ID mode was set, modify the tracking of the boot pages in page_root_xa to use vhca_id too. Add mlx5_esw_vhca_id_to_func_type() to resolve the function type via vport lookup in VHCA_ID mode, enabling per-type debugfs counters. Signed-off-by: Moshe Shemesh Reviewed-by: Akiva Goldberger Reviewed-by: Mark Bloch Signed-off-by: Tariq Toukan --- .../net/ethernet/mellanox/mlx5/core/eswitch.c | 42 ++++ .../net/ethernet/mellanox/mlx5/core/eswitch.h | 7 + .../net/ethernet/mellanox/mlx5/core/main.c | 3 + .../ethernet/mellanox/mlx5/core/pagealloc.c | 226 ++++++++++++++---- include/linux/mlx5/driver.h | 7 + 5 files changed, 235 insertions(+), 50 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c b/drivers/ne= t/ethernet/mellanox/mlx5/core/eswitch.c index e0eafcf0c52a..d3eaefc5c0e0 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.c @@ -852,6 +852,48 @@ bool mlx5_esw_vport_vhca_id(struct mlx5_eswitch *esw, = u16 vportn, u16 *vhca_id) return true; } =20 +u16 mlx5_esw_vhca_id_to_func_type(struct mlx5_core_dev *dev, u16 vhca_id) +{ + struct mlx5_eswitch *esw =3D dev->priv.eswitch; + struct mlx5_vport *vport; + unsigned long i; + u16 type; + + if (vhca_id =3D=3D MLX5_CAP_GEN(dev, vhca_id)) + return MLX5_SELF; + + if (!esw) + return MLX5_FUNC_TYPE_NONE; + + mutex_lock(&esw->state_lock); + mlx5_esw_for_each_vport(esw, i, vport) { + if (vport->vhca_id !=3D vhca_id) + continue; + + if (vport->vport =3D=3D MLX5_VPORT_HOST_PF) { + type =3D MLX5_HOST_PF; + goto unlock; + } + + if (xa_get_mark(&esw->vports, i, MLX5_ESW_VPT_SF)) { + type =3D MLX5_SF; + goto unlock; + } + + if (xa_get_mark(&esw->vports, i, MLX5_ESW_VPT_VF)) { + type =3D MLX5_VF; + goto unlock; + } + + type =3D MLX5_EC_VF; + goto unlock; + } + type =3D MLX5_FUNC_TYPE_NONE; +unlock: + mutex_unlock(&esw->state_lock); + return type; +} + static int esw_vport_setup(struct mlx5_eswitch *esw, struct mlx5_vport *vp= ort) { bool vst_mode_steering =3D esw_vst_mode_is_steering(esw); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h b/drivers/ne= t/ethernet/mellanox/mlx5/core/eswitch.h index 2fd601bd102f..5940b4cbfd77 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch.h @@ -863,6 +863,7 @@ void mlx5_esw_vport_vhca_id_unmap(struct mlx5_eswitch *= esw, struct mlx5_vport *vport); int mlx5_eswitch_vhca_id_to_vport(struct mlx5_eswitch *esw, u16 vhca_id, u= 16 *vport_num); bool mlx5_esw_vport_vhca_id(struct mlx5_eswitch *esw, u16 vportn, u16 *vhc= a_id); +u16 mlx5_esw_vhca_id_to_func_type(struct mlx5_core_dev *dev, u16 vhca_id); =20 void mlx5_esw_offloads_rep_remove(struct mlx5_eswitch *esw, const struct mlx5_vport *vport); @@ -1034,6 +1035,12 @@ mlx5_esw_vport_vhca_id(struct mlx5_eswitch *esw, u16= vportn, u16 *vhca_id) return false; } =20 +static inline u16 +mlx5_esw_vhca_id_to_func_type(struct mlx5_core_dev *dev, u16 vhca_id) +{ + return MLX5_FUNC_TYPE_NONE; +} + static inline void mlx5_eswitch_safe_aux_devs_remove(struct mlx5_core_dev *dev) {} static inline struct mlx5_flow_handle * diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/e= thernet/mellanox/mlx5/core/main.c index a242053f3a58..52cf341ad6b3 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c @@ -597,6 +597,9 @@ static int handle_hca_cap(struct mlx5_core_dev *dev, vo= id *set_ctx) if (MLX5_CAP_GEN_MAX(dev, release_all_pages)) MLX5_SET(cmd_hca_cap, set_hca_cap, release_all_pages, 1); =20 + if (MLX5_CAP_GEN_MAX(dev, icm_mng_function_id_mode)) + MLX5_SET(cmd_hca_cap, set_hca_cap, icm_mng_function_id_mode, 1); + if (MLX5_CAP_GEN_MAX(dev, mkey_by_name)) MLX5_SET(cmd_hca_cap, set_hca_cap, mkey_by_name, 1); =20 diff --git a/drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c b/drivers/= net/ethernet/mellanox/mlx5/core/pagealloc.c index 77ffa31cc505..7ebe88aa3b3e 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/pagealloc.c @@ -38,6 +38,7 @@ #include "mlx5_core.h" #include "lib/eq.h" #include "lib/tout.h" +#include "eswitch.h" =20 enum { MLX5_PAGES_CANT_GIVE =3D 0, @@ -69,9 +70,24 @@ enum { MLX5_NUM_4K_IN_PAGE =3D PAGE_SIZE / MLX5_ADAPTER_PAGE_SIZE, }; =20 -static u32 get_function(u16 func_id, bool ec_function) +static bool mlx5_page_mgt_mode_is_vhca_id(const struct mlx5_core_dev *dev) { - return (u32)func_id | (ec_function << 16); + return dev->priv.page_mgt_mode =3D=3D MLX5_PAGE_MGT_MODE_VHCA_ID; +} + +static void mlx5_page_mgt_mode_set(struct mlx5_core_dev *dev, + enum mlx5_page_mgt_mode mode) +{ + dev->priv.page_mgt_mode =3D mode; +} + +static u32 get_function_key(struct mlx5_core_dev *dev, u16 func_vhca_id, + bool ec_function) +{ + if (mlx5_page_mgt_mode_is_vhca_id(dev)) + return (u32)func_vhca_id; + + return (u32)func_vhca_id | (ec_function << 16); } =20 static u16 func_id_to_type(struct mlx5_core_dev *dev, u16 func_id, bool ec= _function) @@ -89,12 +105,21 @@ static u16 func_id_to_type(struct mlx5_core_dev *dev, = u16 func_id, bool ec_funct return MLX5_SF; } =20 +static u16 func_vhca_id_to_type(struct mlx5_core_dev *dev, u16 func_vhca_i= d, + bool ec_function) +{ + if (mlx5_page_mgt_mode_is_vhca_id(dev)) + return mlx5_esw_vhca_id_to_func_type(dev, func_vhca_id); + + return func_id_to_type(dev, func_vhca_id, ec_function); +} + static u32 mlx5_get_ec_function(u32 function) { return function >> 16; } =20 -static u32 mlx5_get_func_id(u32 function) +static u32 mlx5_get_func_vhca_id(u32 function) { return function & 0xffff; } @@ -196,7 +221,7 @@ static struct fw_page *find_fw_page(struct mlx5_core_de= v *dev, u64 addr, return result; } =20 -static int mlx5_cmd_query_pages(struct mlx5_core_dev *dev, u16 *func_id, +static int mlx5_cmd_query_pages(struct mlx5_core_dev *dev, u16 *func_vhca_= id, s32 *npages, int boot) { u32 out[MLX5_ST_SZ_DW(query_pages_out)] =3D {}; @@ -207,14 +232,20 @@ static int mlx5_cmd_query_pages(struct mlx5_core_dev = *dev, u16 *func_id, MLX5_SET(query_pages_in, in, op_mod, boot ? MLX5_QUERY_PAGES_IN_OP_MOD_BOOT_PAGES : MLX5_QUERY_PAGES_IN_OP_MOD_INIT_PAGES); - MLX5_SET(query_pages_in, in, embedded_cpu_function, mlx5_core_is_ecpf(dev= )); + + if (mlx5_page_mgt_mode_is_vhca_id(dev)) + MLX5_SET(query_pages_in, in, function_id, + MLX5_CAP_GEN(dev, vhca_id)); + else + MLX5_SET(query_pages_in, in, embedded_cpu_function, + mlx5_core_is_ecpf(dev)); =20 err =3D mlx5_cmd_exec_inout(dev, query_pages, in, out); if (err) return err; =20 *npages =3D MLX5_GET(query_pages_out, out, num_pages); - *func_id =3D MLX5_GET(query_pages_out, out, function_id); + *func_vhca_id =3D MLX5_GET(query_pages_out, out, function_id); =20 return err; } @@ -334,7 +365,7 @@ static int alloc_system_page(struct mlx5_core_dev *dev,= u32 function) return err; } =20 -static void page_notify_fail(struct mlx5_core_dev *dev, u16 func_id, +static void page_notify_fail(struct mlx5_core_dev *dev, u16 func_vhca_id, bool ec_function) { u32 in[MLX5_ST_SZ_DW(manage_pages_in)] =3D {}; @@ -342,19 +373,23 @@ static void page_notify_fail(struct mlx5_core_dev *de= v, u16 func_id, =20 MLX5_SET(manage_pages_in, in, opcode, MLX5_CMD_OP_MANAGE_PAGES); MLX5_SET(manage_pages_in, in, op_mod, MLX5_PAGES_CANT_GIVE); - MLX5_SET(manage_pages_in, in, function_id, func_id); - MLX5_SET(manage_pages_in, in, embedded_cpu_function, ec_function); + MLX5_SET(manage_pages_in, in, function_id, func_vhca_id); + + if (!mlx5_page_mgt_mode_is_vhca_id(dev)) + MLX5_SET(manage_pages_in, in, embedded_cpu_function, + ec_function); =20 err =3D mlx5_cmd_exec_in(dev, manage_pages, in); if (err) - mlx5_core_warn(dev, "page notify failed func_id(%d) err(%d)\n", - func_id, err); + mlx5_core_warn(dev, + "page notify failed func_vhca_id(%d) err(%d)\n", + func_vhca_id, err); } =20 -static int give_pages(struct mlx5_core_dev *dev, u16 func_id, int npages, +static int give_pages(struct mlx5_core_dev *dev, u16 func_vhca_id, int npa= ges, int event, bool ec_function) { - u32 function =3D get_function(func_id, ec_function); + u32 function =3D get_function_key(dev, func_vhca_id, ec_function); u32 out[MLX5_ST_SZ_DW(manage_pages_out)] =3D {0}; int inlen =3D MLX5_ST_SZ_BYTES(manage_pages_in); int notify_fail =3D event; @@ -390,9 +425,12 @@ static int give_pages(struct mlx5_core_dev *dev, u16 f= unc_id, int npages, =20 MLX5_SET(manage_pages_in, in, opcode, MLX5_CMD_OP_MANAGE_PAGES); MLX5_SET(manage_pages_in, in, op_mod, MLX5_PAGES_GIVE); - MLX5_SET(manage_pages_in, in, function_id, func_id); + MLX5_SET(manage_pages_in, in, function_id, func_vhca_id); MLX5_SET(manage_pages_in, in, input_num_entries, npages); - MLX5_SET(manage_pages_in, in, embedded_cpu_function, ec_function); + + if (!mlx5_page_mgt_mode_is_vhca_id(dev)) + MLX5_SET(manage_pages_in, in, embedded_cpu_function, + ec_function); =20 err =3D mlx5_cmd_do(dev, in, inlen, out, sizeof(out)); if (err =3D=3D -EREMOTEIO) { @@ -405,17 +443,20 @@ static int give_pages(struct mlx5_core_dev *dev, u16 = func_id, int npages, } err =3D mlx5_cmd_check(dev, err, in, out); if (err) { - mlx5_core_warn(dev, "func_id 0x%x, npages %d, err %d\n", - func_id, npages, err); + mlx5_core_warn(dev, "func_vhca_id 0x%x, npages %d, err %d\n", + func_vhca_id, npages, err); goto out_dropped; } =20 - func_type =3D func_id_to_type(dev, func_id, ec_function); - dev->priv.page_counters[func_type] +=3D npages; + func_type =3D func_vhca_id_to_type(dev, func_vhca_id, ec_function); + if (func_type !=3D MLX5_FUNC_TYPE_NONE) + dev->priv.page_counters[func_type] +=3D npages; dev->priv.fw_pages +=3D npages; =20 - mlx5_core_dbg(dev, "npages %d, ec_function %d, func_id 0x%x, err %d\n", - npages, ec_function, func_id, err); + mlx5_core_dbg(dev, + "npages %d, ec_function %d, func 0x%x, mode %d, err %d\n", + npages, ec_function, func_vhca_id, + mlx5_page_mgt_mode_is_vhca_id(dev), err); =20 kvfree(in); return 0; @@ -428,14 +469,14 @@ static int give_pages(struct mlx5_core_dev *dev, u16 = func_id, int npages, out_free: kvfree(in); if (notify_fail) - page_notify_fail(dev, func_id, ec_function); + page_notify_fail(dev, func_vhca_id, ec_function); return err; } =20 -static void release_all_pages(struct mlx5_core_dev *dev, u16 func_id, +static void release_all_pages(struct mlx5_core_dev *dev, u16 func_vhca_id, bool ec_function) { - u32 function =3D get_function(func_id, ec_function); + u32 function =3D get_function_key(dev, func_vhca_id, ec_function); struct rb_root *root; struct rb_node *p; int npages =3D 0; @@ -454,12 +495,14 @@ static void release_all_pages(struct mlx5_core_dev *d= ev, u16 func_id, free_fwp(dev, fwp, fwp->free_count); } =20 - func_type =3D func_id_to_type(dev, func_id, ec_function); - dev->priv.page_counters[func_type] -=3D npages; + func_type =3D func_vhca_id_to_type(dev, func_vhca_id, ec_function); + if (func_type !=3D MLX5_FUNC_TYPE_NONE) + dev->priv.page_counters[func_type] -=3D npages; dev->priv.fw_pages -=3D npages; =20 - mlx5_core_dbg(dev, "npages %d, ec_function %d, func_id 0x%x\n", - npages, ec_function, func_id); + mlx5_core_dbg(dev, "npages %d, ec_function %d, func 0x%x, mode %d\n", + npages, ec_function, func_vhca_id, + mlx5_page_mgt_mode_is_vhca_id(dev)); } =20 static u32 fwp_fill_manage_pages_out(struct fw_page *fwp, u32 *out, u32 in= dex, @@ -487,7 +530,7 @@ static int reclaim_pages_cmd(struct mlx5_core_dev *dev, struct fw_page *fwp; struct rb_node *p; bool ec_function; - u32 func_id; + u32 func_vhca_id; u32 npages; u32 i =3D 0; int err; @@ -499,10 +542,11 @@ static int reclaim_pages_cmd(struct mlx5_core_dev *de= v, =20 /* No hard feelings, we want our pages back! */ npages =3D MLX5_GET(manage_pages_in, in, input_num_entries); - func_id =3D MLX5_GET(manage_pages_in, in, function_id); + func_vhca_id =3D MLX5_GET(manage_pages_in, in, function_id); ec_function =3D MLX5_GET(manage_pages_in, in, embedded_cpu_function); =20 - root =3D xa_load(&dev->priv.page_root_xa, get_function(func_id, ec_functi= on)); + root =3D xa_load(&dev->priv.page_root_xa, + get_function_key(dev, func_vhca_id, ec_function)); if (WARN_ON_ONCE(!root)) return -EEXIST; =20 @@ -518,10 +562,11 @@ static int reclaim_pages_cmd(struct mlx5_core_dev *de= v, return 0; } =20 -static int reclaim_pages(struct mlx5_core_dev *dev, u16 func_id, int npage= s, - int *nclaimed, bool event, bool ec_function) +static int reclaim_pages(struct mlx5_core_dev *dev, u16 func_vhca_id, + int npages, int *nclaimed, bool event, + bool ec_function) { - u32 function =3D get_function(func_id, ec_function); + u32 function =3D get_function_key(dev, func_vhca_id, ec_function); int outlen =3D MLX5_ST_SZ_BYTES(manage_pages_out); u32 in[MLX5_ST_SZ_DW(manage_pages_in)] =3D {}; int num_claimed; @@ -540,12 +585,16 @@ static int reclaim_pages(struct mlx5_core_dev *dev, u= 16 func_id, int npages, =20 MLX5_SET(manage_pages_in, in, opcode, MLX5_CMD_OP_MANAGE_PAGES); MLX5_SET(manage_pages_in, in, op_mod, MLX5_PAGES_TAKE); - MLX5_SET(manage_pages_in, in, function_id, func_id); + MLX5_SET(manage_pages_in, in, function_id, func_vhca_id); MLX5_SET(manage_pages_in, in, input_num_entries, npages); - MLX5_SET(manage_pages_in, in, embedded_cpu_function, ec_function); =20 - mlx5_core_dbg(dev, "func 0x%x, npages %d, outlen %d\n", - func_id, npages, outlen); + if (!mlx5_page_mgt_mode_is_vhca_id(dev)) + MLX5_SET(manage_pages_in, in, embedded_cpu_function, + ec_function); + + mlx5_core_dbg(dev, "func 0x%x, npages %d, outlen %d mode %d\n", + func_vhca_id, npages, outlen, + mlx5_page_mgt_mode_is_vhca_id(dev)); err =3D reclaim_pages_cmd(dev, in, sizeof(in), out, outlen); if (err) { npages =3D MLX5_GET(manage_pages_in, in, input_num_entries); @@ -577,8 +626,9 @@ static int reclaim_pages(struct mlx5_core_dev *dev, u16= func_id, int npages, if (nclaimed) *nclaimed =3D num_claimed; =20 - func_type =3D func_id_to_type(dev, func_id, ec_function); - dev->priv.page_counters[func_type] -=3D num_claimed; + func_type =3D func_vhca_id_to_type(dev, func_vhca_id, ec_function); + if (func_type !=3D MLX5_FUNC_TYPE_NONE) + dev->priv.page_counters[func_type] -=3D num_claimed; dev->priv.fw_pages -=3D num_claimed; =20 out_free: @@ -658,30 +708,101 @@ static int req_pages_handler(struct notifier_block *= nb, * req->npages (and not min ()). */ req->npages =3D max_t(s32, npages, MAX_RECLAIM_NPAGES); - req->ec_function =3D ec_function; + if (!mlx5_page_mgt_mode_is_vhca_id(dev)) + req->ec_function =3D ec_function; req->release_all =3D release_all; INIT_WORK(&req->work, pages_work_handler); queue_work(dev->priv.pg_wq, &req->work); return NOTIFY_OK; } =20 +/* + * After set_hca_cap(), the second satisfy_startup_pages(dev, 0) may see + * VHCA_ID mode. If page_root_xa already has the PF entry from the first + * (boot) call under FUNC_ID keys 0 or (ec_function << 16), migrate that + * entry to the device vhca_id key so lookups use VHCA_ID semantics. + */ +static int mlx5_pagealloc_migrate_pf_to_vhca_id(struct mlx5_core_dev *dev) +{ + u32 vhca_id_key, old_key; + struct rb_root *root; + struct fw_page *fwp; + struct rb_node *p; + bool ec_function; + int err; + + if (xa_empty(&dev->priv.page_root_xa)) + return 0; + + vhca_id_key =3D MLX5_CAP_GEN(dev, vhca_id); + ec_function =3D mlx5_core_is_ecpf(dev); + + old_key =3D ec_function ? (1U << 16) : 0; + root =3D xa_load(&dev->priv.page_root_xa, old_key); + if (!root) + return 0; + + if (old_key =3D=3D vhca_id_key) + return 0; + + err =3D xa_insert(&dev->priv.page_root_xa, vhca_id_key, root, GFP_KERNEL); + if (err) { + mlx5_core_warn(dev, + "failed to migrate page root key 0x%x to vhca_id 0x%x\n", + old_key, vhca_id_key); + return err; + } + + xa_erase(&dev->priv.page_root_xa, old_key); + + for (p =3D rb_first(root); p; p =3D rb_next(p)) { + fwp =3D rb_entry(p, struct fw_page, rb_node); + fwp->function =3D vhca_id_key; + } + + return 0; +} + int mlx5_satisfy_startup_pages(struct mlx5_core_dev *dev, int boot) { - u16 func_id; + bool ec_function =3D false; + u16 func_vhca_id; s32 npages; int err; =20 - err =3D mlx5_cmd_query_pages(dev, &func_id, &npages, boot); + /* When boot flag is set, the icm_mng_function_id_mode capability is + * not yet set (only set after set_hca_cap()), so use FUNC_ID mode + * for backward compatibility. When boot is false, set mode from + * cap (set_hca_cap has run successfully). + */ + if (boot) { + mlx5_page_mgt_mode_set(dev, MLX5_PAGE_MGT_MODE_FUNC_ID); + } else { + if (MLX5_CAP_GEN_MAX(dev, icm_mng_function_id_mode) =3D=3D + MLX5_ID_MODE_FUNCTION_VHCA_ID) { + err =3D mlx5_pagealloc_migrate_pf_to_vhca_id(dev); + if (err) + return err; + mlx5_page_mgt_mode_set(dev, MLX5_PAGE_MGT_MODE_VHCA_ID); + } + } + + err =3D mlx5_cmd_query_pages(dev, &func_vhca_id, &npages, boot); if (err) return err; =20 - mlx5_core_dbg(dev, "requested %d %s pages for func_id 0x%x\n", - npages, boot ? "boot" : "init", func_id); + mlx5_core_dbg(dev, + "requested %d %s pages for func_vhca_id 0x%x\n", + npages, boot ? "boot" : "init", func_vhca_id); =20 if (!npages) return 0; =20 - return give_pages(dev, func_id, npages, 0, mlx5_core_is_ecpf(dev)); + /* In VHCA_ID mode, ec_function remains false (not used). */ + if (!mlx5_page_mgt_mode_is_vhca_id(dev)) + ec_function =3D mlx5_core_is_ecpf(dev); + + return give_pages(dev, func_vhca_id, npages, 0, ec_function); } =20 enum { @@ -709,15 +830,17 @@ static int mlx5_reclaim_root_pages(struct mlx5_core_d= ev *dev, =20 while (!RB_EMPTY_ROOT(root)) { u32 ec_function =3D mlx5_get_ec_function(function); - u32 function_id =3D mlx5_get_func_id(function); + u32 func_vhca_id =3D mlx5_get_func_vhca_id(function); int nclaimed; int err; =20 - err =3D reclaim_pages(dev, function_id, optimal_reclaimed_pages(), + err =3D reclaim_pages(dev, func_vhca_id, + optimal_reclaimed_pages(), &nclaimed, false, ec_function); if (err) { - mlx5_core_warn(dev, "reclaim_pages err (%d) func_id=3D0x%x ec_func=3D0x= %x\n", - err, function_id, ec_function); + mlx5_core_warn(dev, + "reclaim_pages err (%d) func_vhca_id=3D0x%x ec_func=3D0x%x\n", + err, func_vhca_id, ec_function); return err; } =20 @@ -751,6 +874,9 @@ int mlx5_reclaim_startup_pages(struct mlx5_core_dev *de= v) WARN(dev->priv.fw_pages, "FW pages counter is %d after reclaiming all pages\n", dev->priv.fw_pages); + if (mlx5_page_mgt_mode_is_vhca_id(dev) && !dev->priv.eswitch) + return 0; + WARN(dev->priv.page_counters[MLX5_VF], "VFs FW pages counter is %d after reclaiming all pages\n", dev->priv.page_counters[MLX5_VF]); diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h index b460b3bae195..8e22ea662644 100644 --- a/include/linux/mlx5/driver.h +++ b/include/linux/mlx5/driver.h @@ -556,6 +556,12 @@ enum mlx5_func_type { MLX5_HOST_PF, MLX5_EC_VF, MLX5_FUNC_TYPE_NUM, + MLX5_FUNC_TYPE_NONE =3D MLX5_FUNC_TYPE_NUM, +}; + +enum mlx5_page_mgt_mode { + MLX5_PAGE_MGT_MODE_FUNC_ID, + MLX5_PAGE_MGT_MODE_VHCA_ID, }; =20 struct mlx5_ft_pool; @@ -575,6 +581,7 @@ struct mlx5_priv { u32 fw_pages_alloc_failed; u32 give_pages_dropped; u32 reclaim_pages_discard; + enum mlx5_page_mgt_mode page_mgt_mode; =20 struct mlx5_core_health health; struct list_head traps; --=20 2.44.0