From patchwork Fri Jan 26 18:58:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13533224 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2053.outbound.protection.outlook.com [40.107.101.53]) (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 0DD8021A19 for ; Fri, 26 Jan 2024 18:59:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.53 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706295550; cv=fail; b=LAbPkL4ZiCKoiA+V95Ih2n5DgOn56dK8PGq3+CZCJM7H0CPrZlfPJ94Vwa6VYwo2nrCiHTYKmxgfVhJeJDZiyr4M5CITY6UglU9M6GUNpwPkE7URTYVyUlTqzcJjVc4o9Tkds/fb2QvOCLXyfKkYsp/KXkEg+SYFN6Ho6QXGmaw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706295550; c=relaxed/simple; bh=XbIVoY/rHpOJG/Lw0J8ZvoaB+vieBV25Ax//Xg4n6TY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZJQ5Q9PQ3otDmKY01TjGMjN/0ePs3T01CHd7/hL//03n3qWYfT1Nr7PQ06h3aN76VS58r9XbYhZ16hScOdw6p9aLfQaYI3YQOJ1IS3LsM1+ZLVjUERMpHOYYh/urjxoUMm6lbkO8BM6cPH5F/fc3OGGB8ZWw2zRDEFbIAFyfkAU= 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=cmfqLOyM; arc=fail smtp.client-ip=40.107.101.53 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="cmfqLOyM" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gHLg6yq5duq8lvtoVzu1b83Zh0gZ8tBg+G9cZ0kqb0q/Z6y+Le0ICC2Rt127COjqYC9btlCrybR843kOziV7BSRzaCLmi4NPgYTgGom06fTB8v8du2gswptzeztTKss0Y3PriHOlEhcRRM4My7igIJ3IVmiaQ1sUOfeeqlXUYOnYMHtY8TMPFrAuEGkmUAKGTMw2ow9zBYe6weI8An3WtvUq271yIkRSGmNTc/FgwLKNCaqVgATiO/oT2G4V3yzaB1V316WfQMaZnOy3to9S1/JwMSSwjLMH1o48OTdGHch9ztfe9q/AVTvYkkpjH4KHSdGv26sft9zEs01XZrHjuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=ZK6NDZa4+J1B5WnOvd1PlMyGouAzdBsw/IQCPQ8DvQ0=; b=l0/1555x4p2KTgxkLViH2CiQPgyjt5J+qrUpRp2aErSDyOZ8MBdOXukUu2bJavC77f8ZStL+Q4tt1pXvioqZjbA8e67et5AuxxMPh/oo2n6aj9uIbbC7i5+BQiNA0QiWYOXBAAz9pFE5l/DL7/G2UAIycLbnZlWsJsqs8BX11TPeczTdZyO011dXeb7vEyIb5OdYfVywv/SqypnNF/CPq6JP0pm8/zqCDbfSnmGtn4flK88ZZJ8Qg9X49chlr0rX0w4YNwnroy34uoUw44wUz6uf+sRZOujE+NcDYn/eB2INohPTd+pGGT/cJLViujW4T5cxHzEoSkKXo1ySHM12Nw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=davemloft.net 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=ZK6NDZa4+J1B5WnOvd1PlMyGouAzdBsw/IQCPQ8DvQ0=; b=cmfqLOyMxkLZxsu1U/Q3c4I/+2QW6ZNe6XEm15+Dqo5Nb3ptxvPIULUr0mZHMgsw58c6JgH8vSzzPlnkxy9Z1Cslxp4AkqeEROYYoWP5EeHZIMuPDySDtYjsbSRRXaewMLgB4xyppMBklLYCDekySqxWd5dcOYNffn26SCqz5UiH8TwnnfeQ6chtoATTYdviryedvkq297ubA+A0digxiGoh3rbtwWku+px+8nUejtvrjSa+2MDX3D9YI90EP5ICsOn39sEyEMz9wVWQEH8vmm+wPSlZ+L5FHZmcbBFC8XmQb+TNac7a+GlHeQxxvfsb2wt/bBm/dK9TRRSEenSAvQ== Received: from BL0PR02CA0042.namprd02.prod.outlook.com (2603:10b6:207:3d::19) by PH0PR12MB7077.namprd12.prod.outlook.com (2603:10b6:510:21d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.27; Fri, 26 Jan 2024 18:59:06 +0000 Received: from MN1PEPF0000ECD5.namprd02.prod.outlook.com (2603:10b6:207:3d:cafe::3e) by BL0PR02CA0042.outlook.office365.com (2603:10b6:207:3d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.22 via Frontend Transport; Fri, 26 Jan 2024 18:59:06 +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 MN1PEPF0000ECD5.mail.protection.outlook.com (10.167.242.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.16 via Frontend Transport; Fri, 26 Jan 2024 18:59:05 +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.986.41; Fri, 26 Jan 2024 10:58:50 -0800 Received: from localhost.localdomain (10.126.230.35) 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.986.41; Fri, 26 Jan 2024 10:58:47 -0800 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "Amit Cohen" , Subject: [PATCH net-next 1/6] mlxsw: spectrum: Change mlxsw_sp_upper to LAG structure Date: Fri, 26 Jan 2024 19:58:26 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000ECD5:EE_|PH0PR12MB7077:EE_ X-MS-Office365-Filtering-Correlation-Id: 5fa3ca7a-af0b-47aa-3663-08dc1ea0de8a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qcp6RfMLzZdzM5npoE+XD/Nkg6MLT7WNh8hdP9Qtzl/rO0mAx5So7wQfTCU2PXptYOXYWTpsAIRlfwIk/Q1g2h/M2BtjRhzsje1MLstK2HaB5gdkJif6pAz2Ye1/3zuGrSVBiZT+q027Oq8Nrc9h87/Xj85w4QKzgX3aVHTU2yzJ/H6zA1ELP2wExO/wTOHSdURPHsPOV28OGnoDXF0aHh2/A4vV7/034N7h+9KJeFR+LrtqFY6yJYKc4MG8smEX9r82RcMTqnhuvcXF6MjyWBJretf5nyUlOnkFCslnwRdXry34iJ4WVYSp0fh6LWrckjhfGVxMJKfPA9SBwdeuUK8jxCE+sjZqdPghthFEIPBEPooN+Cxzh4VmKuzmG3ivWI+5kTuqaMNIgmp8GdQSF5kcJ/cXW+sRFIIC39PNer5CAXx82gEWut2rAzbyCm8wVrs+x6+3Tu6qZ0rsQHKyeQ6mCx7Nb7Ylxuiu6TJwukcev9TH6nQE7769D3rt9jht8O8SkhkQmblnsj3CO2/91bWmJT7AJWAAF6yaKUR9xY3dLokbHUCza9ZoLCrGHlh13aS/RCVyeuGw5tZ3eoblczD8yPok4fW5SNVGESp5iwmpV9zWaNlJCmzhR2N7tc2jUDW4juaMbl9F45BjQYaDOjJ61KIBKJZ0AsVwSrkrLupws3kM7b0iFVfXQr9l2D0M0KW/RsBkvLprV65CwzCmfjRB53u+3OwzCKFXelkPol7es/KrX4xXTTFMwlPFObDp 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:(13230031)(4636009)(39860400002)(136003)(376002)(396003)(346002)(230922051799003)(64100799003)(82310400011)(1800799012)(186009)(451199024)(40470700004)(46966006)(36840700001)(82740400003)(7636003)(36860700001)(5660300002)(2906002)(36756003)(41300700001)(356005)(26005)(16526019)(86362001)(426003)(478600001)(107886003)(2616005)(6666004)(336012)(83380400001)(8936002)(4326008)(8676002)(47076005)(54906003)(70206006)(70586007)(110136005)(316002)(40460700003)(40480700001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 18:59:05.4937 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5fa3ca7a-af0b-47aa-3663-08dc1ea0de8a 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: MN1PEPF0000ECD5.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7077 X-Patchwork-Delegate: kuba@kernel.org From: Amit Cohen The structure mlxsw_sp_upper is used only as LAG. Rename it to mlxsw_sp_lag and move it to spectrum.c file, as it is used only there. Move the function mlxsw_sp_lag_get() with the structure. Signed-off-by: Amit Cohen Reviewed-by: Ido Schimmel Signed-off-by: Ido Schimmel Signed-off-by: Petr Machata Reviewed-by: Simon Horman --- .../net/ethernet/mellanox/mlxsw/spectrum.c | 19 +++++++++++++++---- .../net/ethernet/mellanox/mlxsw/spectrum.h | 14 ++------------ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c index 5d3413636a62..38428d2ef0e2 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c @@ -2751,6 +2751,11 @@ static void mlxsw_sp_lag_pgt_fini(struct mlxsw_sp *mlxsw_sp) #define MLXSW_SP_LAG_SEED_INIT 0xcafecafe +struct mlxsw_sp_lag { + struct net_device *dev; + unsigned int ref_count; +}; + static int mlxsw_sp_lag_init(struct mlxsw_sp *mlxsw_sp) { char slcr_pl[MLXSW_REG_SLCR_LEN]; @@ -2784,7 +2789,7 @@ static int mlxsw_sp_lag_init(struct mlxsw_sp *mlxsw_sp) if (err) return err; - mlxsw_sp->lags = kcalloc(max_lag, sizeof(struct mlxsw_sp_upper), + mlxsw_sp->lags = kcalloc(max_lag, sizeof(struct mlxsw_sp_lag), GFP_KERNEL); if (!mlxsw_sp->lags) { err = -ENOMEM; @@ -4329,11 +4334,17 @@ static int mlxsw_sp_lag_col_port_disable(struct mlxsw_sp_port *mlxsw_sp_port, return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(slcor), slcor_pl); } +static struct mlxsw_sp_lag * +mlxsw_sp_lag_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id) +{ + return &mlxsw_sp->lags[lag_id]; +} + static int mlxsw_sp_lag_index_get(struct mlxsw_sp *mlxsw_sp, struct net_device *lag_dev, u16 *p_lag_id) { - struct mlxsw_sp_upper *lag; + struct mlxsw_sp_lag *lag; int free_lag_id = -1; u16 max_lag; int err, i; @@ -4482,7 +4493,7 @@ static int mlxsw_sp_port_lag_join(struct mlxsw_sp_port *mlxsw_sp_port, struct netlink_ext_ack *extack) { struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; - struct mlxsw_sp_upper *lag; + struct mlxsw_sp_lag *lag; u16 lag_id; u8 port_index; int err; @@ -4560,7 +4571,7 @@ static void mlxsw_sp_port_lag_leave(struct mlxsw_sp_port *mlxsw_sp_port, { struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; u16 lag_id = mlxsw_sp_port->lag_id; - struct mlxsw_sp_upper *lag; + struct mlxsw_sp_lag *lag; if (!mlxsw_sp_port->lagged) return; diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h index a0c9775fa955..dd2f05a6d909 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h @@ -78,11 +78,6 @@ struct mlxsw_sp_span_entry; enum mlxsw_sp_l3proto; union mlxsw_sp_l3addr; -struct mlxsw_sp_upper { - struct net_device *dev; - unsigned int ref_count; -}; - enum mlxsw_sp_rif_type { MLXSW_SP_RIF_TYPE_SUBPORT, MLXSW_SP_RIF_TYPE_VLAN, @@ -136,6 +131,7 @@ struct mlxsw_sp_span_ops; struct mlxsw_sp_qdisc_state; struct mlxsw_sp_mall_entry; struct mlxsw_sp_pgt; +struct mlxsw_sp_lag; struct mlxsw_sp_port_mapping { u8 module; @@ -164,7 +160,7 @@ struct mlxsw_sp { const struct mlxsw_bus_info *bus_info; unsigned char base_mac[ETH_ALEN]; const unsigned char *mac_mask; - struct mlxsw_sp_upper *lags; + struct mlxsw_sp_lag *lags; struct mlxsw_sp_port_mapping *port_mapping; struct mlxsw_sp_port_mapping_events port_mapping_events; struct rhashtable sample_trigger_ht; @@ -257,12 +253,6 @@ struct mlxsw_sp_fid_core_ops { void (*fini)(struct mlxsw_sp *mlxsw_sp); }; -static inline struct mlxsw_sp_upper * -mlxsw_sp_lag_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id) -{ - return &mlxsw_sp->lags[lag_id]; -} - struct mlxsw_sp_port_pcpu_stats { u64 rx_packets; u64 rx_bytes; From patchwork Fri Jan 26 18:58:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13533223 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2043.outbound.protection.outlook.com [40.107.101.43]) (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 2D8B3224C6 for ; Fri, 26 Jan 2024 18:59:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.101.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706295549; cv=fail; b=AsVeL1opROMlbcqIrXqX/UseMKPWWWVQJnJw+QRqnZfyHN+MUjbIn8a8OaA00G6T0/Oxx6LMbKzIaZ4HIGWnZQ9le9JG0I7tjR6t2d6g7mDJcrduchSQ49WCHQRaiORLrzLKWibWStyC1M2Qg0+9bqK4c2I0pm3uKeOgmhwt3+g= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706295549; c=relaxed/simple; bh=hzjE49PiSIKmI2V2sLIaQP1j1IMPW5HD8WGm3pFpQTw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Y+9fB1cA5ujb8rzHwpeYvU06N4V2Rdy1o0mW83IpnU650PDuJ4M2gqFS8oOKwXYeOmChtSbhPrjkuRyQPp4KlJIGPjUKjhxdVLg2vbUc4tADtpNQPz7xpSoJJewv3OdWjvObkjNJdV+rkkoUUCdPOOqbZWxSmvzsrLulZNOTdQw= 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=gv3V37Wb; arc=fail smtp.client-ip=40.107.101.43 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="gv3V37Wb" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G5V6Cz5yWhyMDC76ZDDk/Kuorw3nTWf9dcUiEZhPxm6uH7Yi0WoV3qAmWZWca8hxUV2a6uzjuVQPOkpzOjRFCMOOZTyemyFNUGG5HWO0cBL1eJmyKemlV/+dItBln+8yMN1JT2bkQHMziprqgisfJJ3crsaX7Jr0e9QCfc91tm0pFp4Hyzz1ViDpGwPeM3sg5iGeGlJbJTxWDv8sgo4N3CcmdphwIH85iJLEcU94evl2zym0yE4ZXhsaiG7LwLAextReAGyXce7bUeULVnIA+ZGj0bvQJaj8k+RjCDK4J7s4S1xrIOVecLawm/2jGqOHtgnDWbkK407/IJLY9/WtpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=z7YVh+uJpSwJxKGH4tM2vc7DTX+Tl8CyzgivVYBOgaY=; b=C5TmDIGuxX8pElaoxIPhyTh4Qt+sRiy1hhafy/MrGFuIZ+9rZZGB24uTTRjOCLoiob9ZKZ11LT3/rr9dfcPX2Gj/RJVlBQUzZbFlJ+5CPnBkf08SDQi2++NBC3WKTV5lkha3VkMEyVhEbWw6EwHyCidyspq23G0gzlmG9a3QWRMxjV7Hs9efWMa4WhmrghWucwBqRm+PWw3aGpYNyh40MWRfMG1yFD4zlJsuSmGzWVAHPjNGU/IZ071lZtzsHMwsSBwwEklVXYrJkuEp1i7YC7G1TsnywHJ60b4Ki80mXYSqlQW5N9XJifEt1devub4xwY3ud9XmMWitHRqdT0Xjbw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=davemloft.net 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=z7YVh+uJpSwJxKGH4tM2vc7DTX+Tl8CyzgivVYBOgaY=; b=gv3V37WbsIOJK1I78EO8JC1JURSSI1riSSzlL8JyrzZOEraFskXzNghPE068Bf2n/SNFG35kUbZ5bGNrHdJUdCJUOz2PbxCCLt7aNYSlM+R1ovEtswHZ2droUDm0URXLh3Vih/M4sBKIz1bvfm347j3IeAqtVk2bp+LcReYg0oLzylGvYnTa8MfugT5UDt3bbkHEZPX2N8VlMpxwq5U/XHLSALc6gkj0cJIGPt9tLAxHmGnLPlGk/V8GVFQcB+yQ9lcpidV2P2O04z60tdSa29klRZdlpDDDZbbIqh9jLSz69S146XnZS8Y+rApSjjPf2RC2wPCoemKcQrSCBfWP7Q== Received: from DS7PR03CA0330.namprd03.prod.outlook.com (2603:10b6:8:2b::22) by LV8PR12MB9153.namprd12.prod.outlook.com (2603:10b6:408:185::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.23; Fri, 26 Jan 2024 18:59:02 +0000 Received: from DS1PEPF00017091.namprd03.prod.outlook.com (2603:10b6:8:2b:cafe::55) by DS7PR03CA0330.outlook.office365.com (2603:10b6:8:2b::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.27 via Frontend Transport; Fri, 26 Jan 2024 18:59:02 +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 DS1PEPF00017091.mail.protection.outlook.com (10.167.17.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.16 via Frontend Transport; Fri, 26 Jan 2024 18:59:01 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) 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.986.41; Fri, 26 Jan 2024 10:58:52 -0800 Received: from localhost.localdomain (10.126.230.35) 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.986.41; Fri, 26 Jan 2024 10:58:50 -0800 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "Amit Cohen" , Subject: [PATCH net-next 2/6] mlxsw: spectrum: Remove mlxsw_sp_lag_get() Date: Fri, 26 Jan 2024 19:58:27 +0100 Message-ID: <60abbc61e47cce691121e761340d6cc5d7f06f4e.1706293430.git.petrm@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017091:EE_|LV8PR12MB9153:EE_ X-MS-Office365-Filtering-Correlation-Id: 08c4a64b-8e1e-4171-e6f6-08dc1ea0dc56 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: z9qdIFt1heF9B8GTccSJE1BZrH4khA6NLUM5ARq9aK4i2gWVpRWowzLTWWpLPxl/p8aTJshCICSYexu/CtmDiObxszsxcCNNCDkxE18H0dZLRV19VaBt6T4IZz4dAZskn8RdMfMACFxvN0GTsza53uS1tK5BdW8s6gC3qvYLBbZF3bPlP545Ej6jJMD1pKHGiQBFmir//IE5o5tXV55FFnhSziuil4xBaoocvyd2nO2rfP2zBZr4t06dfqf8kUM+WHBrc8CSHEW7OPVhq5y31BvaCJgTib70z1yqsqkcMJ745VdO301E6biKt67dVeCTSMdzZHGFIidjhtruI1J7nJk7MLNWIi9oCGhXJrYxMuOMWcTY6clPw9liqMPRVJuV9ZF1AR0KqRDqgxnkQdo7gnbgfTVfCAg2IkckXZO+6AUW2HTe4c5JAlpCDgxSq8BSNsDkQT/CEgRyHmHOw4mRKXkwRhgKXqJMkbfI8r4S3VD7ZexNQMXhki1jFQK7Ym2JMmGzCFWhmNevxrrx5+KehpEbUOD9dZGFUGFYy5gLtZPB6VuLb9J6MZLjSe866MMryz/66G/xhHqT2g3Oxaapkou/1u6ug6Bx21fupe14XMtZYwXgc/WPM+Nt8/pElLXVdtW/suZpc0oQCds+ZQZUTtSDhu7fPiNbf17nfFKrY5KGJjTbrZIRqePBtBjui1fHztO58BZBskcGV+CjVXyN9zAfeD0HBoIomRQywNWR9WZiG/HQgQzt4vjZm+fHhgCh 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:(13230031)(4636009)(39860400002)(376002)(346002)(136003)(396003)(230922051799003)(186009)(1800799012)(451199024)(64100799003)(82310400011)(40470700004)(36840700001)(46966006)(110136005)(8936002)(316002)(26005)(36860700001)(2906002)(2616005)(82740400003)(336012)(478600001)(16526019)(70206006)(41300700001)(6666004)(4326008)(70586007)(54906003)(47076005)(107886003)(5660300002)(426003)(356005)(7636003)(36756003)(86362001)(8676002)(83380400001)(40480700001)(40460700003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 18:59:01.8488 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 08c4a64b-8e1e-4171-e6f6-08dc1ea0dc56 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: DS1PEPF00017091.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9153 X-Patchwork-Delegate: kuba@kernel.org From: Amit Cohen A next patch will add mlxsw_sp_lag_{get,put}() functions to handle LAG reference counting and create/destroy it only for first user/last user. Remove mlxsw_sp_lag_get() function and access LAG array directly. Signed-off-by: Amit Cohen Reviewed-by: Ido Schimmel Signed-off-by: Ido Schimmel Signed-off-by: Petr Machata Reviewed-by: Simon Horman --- drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c index 38428d2ef0e2..ff52028a957b 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c @@ -4334,12 +4334,6 @@ static int mlxsw_sp_lag_col_port_disable(struct mlxsw_sp_port *mlxsw_sp_port, return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(slcor), slcor_pl); } -static struct mlxsw_sp_lag * -mlxsw_sp_lag_get(struct mlxsw_sp *mlxsw_sp, u16 lag_id) -{ - return &mlxsw_sp->lags[lag_id]; -} - static int mlxsw_sp_lag_index_get(struct mlxsw_sp *mlxsw_sp, struct net_device *lag_dev, u16 *p_lag_id) @@ -4354,7 +4348,7 @@ static int mlxsw_sp_lag_index_get(struct mlxsw_sp *mlxsw_sp, return err; for (i = 0; i < max_lag; i++) { - lag = mlxsw_sp_lag_get(mlxsw_sp, i); + lag = &mlxsw_sp->lags[i]; if (lag->ref_count) { if (lag->dev == lag_dev) { *p_lag_id = i; @@ -4501,7 +4495,7 @@ static int mlxsw_sp_port_lag_join(struct mlxsw_sp_port *mlxsw_sp_port, err = mlxsw_sp_lag_index_get(mlxsw_sp, lag_dev, &lag_id); if (err) return err; - lag = mlxsw_sp_lag_get(mlxsw_sp, lag_id); + lag = &mlxsw_sp->lags[lag_id]; if (!lag->ref_count) { err = mlxsw_sp_lag_create(mlxsw_sp, lag_id); if (err) @@ -4575,7 +4569,7 @@ static void mlxsw_sp_port_lag_leave(struct mlxsw_sp_port *mlxsw_sp_port, if (!mlxsw_sp_port->lagged) return; - lag = mlxsw_sp_lag_get(mlxsw_sp, lag_id); + lag = &mlxsw_sp->lags[lag_id]; WARN_ON(lag->ref_count == 0); mlxsw_sp_lag_col_port_remove(mlxsw_sp_port, lag_id); From patchwork Fri Jan 26 18:58:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13533227 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2068.outbound.protection.outlook.com [40.107.223.68]) (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 C76B120DD3 for ; Fri, 26 Jan 2024 18:59:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.68 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706295560; cv=fail; b=CEP6GzBkZqd9s3N4klP7MdhAXMPBhpoKShF6PC0rhC3uz1pw5CymFV4ydoExBUe35VB+AYIT1sWzxZHr4Ke29WwoTrn9To9lcOzZRKv2khnKYLUx43spSZt+kSBtmSNDo+nOGYw3Ll5CUoW4A3MQ6tfICzWKWFaUs7yH/wDZAFo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706295560; c=relaxed/simple; bh=YfDHAyiwybt+FZlKZhXLYYRSm2P97yeazTkzqVXZxJg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iEp/c0EvvS1dVGBgxqZbmxqdg1b0upbhaUZVEzXUvjxM1fNoB3P00oQ9CyhrIejpLq2A63rYELMsse88bQ3rKYoqvHcGmXxGpErD/1IbUw+1TiRwGlACMTBKZygzT6CoYWH0VCvAMsU6rU3y/+oIGNMZmm/i6sV4TktjHd8ELyU= 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=HRenGbTE; arc=fail smtp.client-ip=40.107.223.68 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="HRenGbTE" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V+6i1AUV5X5/GIGT6XOsmN6i2YQ+dZs43dgn9dI1MgqURdJa2KEEBsRjNEkwbqmwEs7oUxMI+QUJds89/vBXeZJ5rhN/B6TdLjfRr9crNDtQPoJr99Cn1pV+rS+SJyljMY4aYV7hz7NN6PwqGmk9xdnW5ZslY1/WmXfkioRzNVZgmBo3aJuzOtiyg9oNhF3IoM2SNOyqKSX5E+7p+EdCqR7Q7v0dfOOi0AMrGsQzD9HDGSdGnV3Y5VUuAPe3w5zDgWKo/FN3MfvNZKaW4FX3ZGF9jjwVdBoU401h27pXSN76D6m6ThE19dc0ndFs/d7dDUYDaE7xC9Ujgvyzcp6rLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=2l50NdTWHMNZ9CUOS2Il/v5WpiCDu/3EdVSgy/7wPB0=; b=dIpRCgQVOjWvIZ3YNCyk4zSupOEqhySv8jV8vggdD6SdCYnoiH8qXueLyvYuPwofKnJsqJYefBgIYwYv6jTrije6EpxdVhXvf6netPZDIhLzUiEzIV0hEgzzKwny6UA+M4ePV0yrY6fh5xMDqxVmcnNCNUuzm20YlKxKGTPtGdteN/60BXOW7wYmHb4Jj407PNk2TcWgkyqNb0wbyCDWBR0WjBh/cPwmWndB7zAy71pua1iqXfAMEw9nncx15VPAnV7/qoKq9kmjIXPBc8fnkG0/xUQ7q6LQvNjnnHY9QD35QP0vFMGGSfx4Z9g6oj0IcEqd0iXey4OEzLrRfXqt8g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=davemloft.net 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=2l50NdTWHMNZ9CUOS2Il/v5WpiCDu/3EdVSgy/7wPB0=; b=HRenGbTEXMz7USGFfqaOoIPv3OaqIot+ZneNCXZIrrIbBCsBRi7bHkhOcnkKYsRphI4UUwQePgaxHhs8z7p4XG9lea5doXh+5mrCWGNNFy252wZ2pnV0KiuBZgbYFHic3zfcrpsoRbi3RvJ4bG4au2VxA1uVSdMcCEYW+BpTaDsJdBg0MvuQtKrxM/m6rvHhON3oodkBqndqrvNyBnKfo+gTJGy3VN8ZA4BDjWitZBTM7fqVx+1EsyDJusH2I/Z0LUXq6T5U546aMIeGnLIf2F7Z04lySEdcCipclcQWkERCSx9uAt3ZZBi+N2Qq6Zve6v+fDMdDf152NK1/SLxVZg== Received: from BL0PR02CA0066.namprd02.prod.outlook.com (2603:10b6:207:3d::43) by PH7PR12MB6936.namprd12.prod.outlook.com (2603:10b6:510:1ba::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.27; Fri, 26 Jan 2024 18:59:13 +0000 Received: from MN1PEPF0000ECD5.namprd02.prod.outlook.com (2603:10b6:207:3d:cafe::ab) by BL0PR02CA0066.outlook.office365.com (2603:10b6:207:3d::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.26 via Frontend Transport; Fri, 26 Jan 2024 18:59:13 +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 MN1PEPF0000ECD5.mail.protection.outlook.com (10.167.242.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.16 via Frontend Transport; Fri, 26 Jan 2024 18:59:12 +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.986.41; Fri, 26 Jan 2024 10:58:54 -0800 Received: from localhost.localdomain (10.126.230.35) 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.986.41; Fri, 26 Jan 2024 10:58:52 -0800 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "Amit Cohen" , Subject: [PATCH net-next 3/6] mlxsw: spectrum: Query max_lag once Date: Fri, 26 Jan 2024 19:58:28 +0100 Message-ID: <5bfdfa5f8df8ef0211649f08d508b631d104d214.1706293430.git.petrm@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000ECD5:EE_|PH7PR12MB6936:EE_ X-MS-Office365-Filtering-Correlation-Id: 46d3fdfb-2e2c-4e80-a302-08dc1ea0e2e3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tGNEI/qzlAky5znagRjEQOXsjvetUGhcNHT3bZs6ZqOTm0eGOORPXzRBSV4Yz1mndCx9iTI/0pkNKOE3+3aqvtN2WLN8drPBjaZiKXcBk//JijRF4zQGcjgbDP7+fvDx8QuK7+4i00rvShSmYVeWK+g1g/aA2jvDjhQWmb3wOTHU+xtKK6gDb6G8mgTCsMl1cfM6DYhssKqf0uHmqEM2CAdQSOthBZz/C+Am+P6FDduoNGbX2BNS0ditN8BD1WyeggsgzqKdqvwXV4i6868S/5fzS+KxvFjjLoPu3l4105FYGbN97+bxj9oXO+TzTik88A+mdv99H/HLLIDleYhePwuEkBUlrLIre527HEMH7cKmRUJy5E39o40WPO/wmxYwpwp0aIPIgRKYNI3+rnE5fc3SAgba8yUxy4kPlJtDz6meX6f0k54lGC6KRcKStRRmh7BvC1RkjI+ly1X4y6dNrh0fE+PqDwLDrdRfCM1GKTAYVY9cC5jsNp/+b1x/trPC7LpynWEc9HCSMh1/3hEu/rp1YZNNRR+JtA0ix/aH7ossv53ESVRygQHrP220CcVIWh5JlRaujefyBczW82XmUIVW960dDjRaL8gkuIH34enN5IyvvVcik5lktchGfW1EL8QQfydB2/c3ojyzFNfdC5q0SoJKcmBkU61CLMi+CTjG3OKg4SDq0MM1awifpjOK5vc/RU9dWkK8NMG1LaqHiOTNBWzLzgdqBFGfQWz6RH3Liuoe01Xzf65WF7xakZyf 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:(13230031)(4636009)(39860400002)(346002)(136003)(376002)(396003)(230922051799003)(451199024)(64100799003)(82310400011)(186009)(1800799012)(46966006)(36840700001)(40470700004)(5660300002)(6666004)(2906002)(478600001)(4326008)(8676002)(8936002)(316002)(86362001)(70206006)(54906003)(70586007)(110136005)(356005)(336012)(426003)(40460700003)(40480700001)(26005)(16526019)(107886003)(47076005)(83380400001)(36860700001)(7636003)(36756003)(2616005)(41300700001)(82740400003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 18:59:12.7906 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 46d3fdfb-2e2c-4e80-a302-08dc1ea0e2e3 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: MN1PEPF0000ECD5.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6936 X-Patchwork-Delegate: kuba@kernel.org From: Amit Cohen The maximum number of LAGs is queried from core several times. It is used to allocate LAG array, and then to iterate over it. In addition, it is used for PGT initialization. To simplify the code, instead of querying it several times, store the value as part of 'mlxsw_sp' and use it. Signed-off-by: Amit Cohen Reviewed-by: Ido Schimmel Signed-off-by: Ido Schimmel Signed-off-by: Petr Machata Reviewed-by: Simon Horman --- .../net/ethernet/mellanox/mlxsw/spectrum.c | 32 ++++--------------- .../net/ethernet/mellanox/mlxsw/spectrum.h | 1 + 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c index ff52028a957b..75fea062a984 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c @@ -2695,23 +2695,18 @@ static void mlxsw_sp_traps_fini(struct mlxsw_sp *mlxsw_sp) static int mlxsw_sp_lag_pgt_init(struct mlxsw_sp *mlxsw_sp) { char sgcr_pl[MLXSW_REG_SGCR_LEN]; - u16 max_lag; int err; if (mlxsw_core_lag_mode(mlxsw_sp->core) != MLXSW_CMD_MBOX_CONFIG_PROFILE_LAG_MODE_SW) return 0; - err = mlxsw_core_max_lag(mlxsw_sp->core, &max_lag); - if (err) - return err; - /* In DDD mode, which we by default use, each LAG entry is 8 PGT * entries. The LAG table address needs to be 8-aligned, but that ought * to be the case, since the LAG table is allocated first. */ err = mlxsw_sp_pgt_mid_alloc_range(mlxsw_sp, &mlxsw_sp->lag_pgt_base, - max_lag * 8); + mlxsw_sp->max_lag * 8); if (err) return err; if (WARN_ON_ONCE(mlxsw_sp->lag_pgt_base % 8)) { @@ -2728,25 +2723,18 @@ static int mlxsw_sp_lag_pgt_init(struct mlxsw_sp *mlxsw_sp) err_mid_alloc_range: mlxsw_sp_pgt_mid_free_range(mlxsw_sp, mlxsw_sp->lag_pgt_base, - max_lag * 8); + mlxsw_sp->max_lag * 8); return err; } static void mlxsw_sp_lag_pgt_fini(struct mlxsw_sp *mlxsw_sp) { - u16 max_lag; - int err; - if (mlxsw_core_lag_mode(mlxsw_sp->core) != MLXSW_CMD_MBOX_CONFIG_PROFILE_LAG_MODE_SW) return; - err = mlxsw_core_max_lag(mlxsw_sp->core, &max_lag); - if (err) - return; - mlxsw_sp_pgt_mid_free_range(mlxsw_sp, mlxsw_sp->lag_pgt_base, - max_lag * 8); + mlxsw_sp->max_lag * 8); } #define MLXSW_SP_LAG_SEED_INIT 0xcafecafe @@ -2759,7 +2747,6 @@ struct mlxsw_sp_lag { static int mlxsw_sp_lag_init(struct mlxsw_sp *mlxsw_sp) { char slcr_pl[MLXSW_REG_SLCR_LEN]; - u16 max_lag; u32 seed; int err; @@ -2778,7 +2765,7 @@ static int mlxsw_sp_lag_init(struct mlxsw_sp *mlxsw_sp) if (err) return err; - err = mlxsw_core_max_lag(mlxsw_sp->core, &max_lag); + err = mlxsw_core_max_lag(mlxsw_sp->core, &mlxsw_sp->max_lag); if (err) return err; @@ -2789,7 +2776,7 @@ static int mlxsw_sp_lag_init(struct mlxsw_sp *mlxsw_sp) if (err) return err; - mlxsw_sp->lags = kcalloc(max_lag, sizeof(struct mlxsw_sp_lag), + mlxsw_sp->lags = kcalloc(mlxsw_sp->max_lag, sizeof(struct mlxsw_sp_lag), GFP_KERNEL); if (!mlxsw_sp->lags) { err = -ENOMEM; @@ -4340,14 +4327,9 @@ static int mlxsw_sp_lag_index_get(struct mlxsw_sp *mlxsw_sp, { struct mlxsw_sp_lag *lag; int free_lag_id = -1; - u16 max_lag; - int err, i; + int i; - err = mlxsw_core_max_lag(mlxsw_sp->core, &max_lag); - if (err) - return err; - - for (i = 0; i < max_lag; i++) { + for (i = 0; i < mlxsw_sp->max_lag; i++) { lag = &mlxsw_sp->lags[i]; if (lag->ref_count) { if (lag->dev == lag_dev) { diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h index dd2f05a6d909..898d24232935 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h @@ -161,6 +161,7 @@ struct mlxsw_sp { unsigned char base_mac[ETH_ALEN]; const unsigned char *mac_mask; struct mlxsw_sp_lag *lags; + u16 max_lag; struct mlxsw_sp_port_mapping *port_mapping; struct mlxsw_sp_port_mapping_events port_mapping_events; struct rhashtable sample_trigger_ht; From patchwork Fri Jan 26 18:58:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13533226 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2079.outbound.protection.outlook.com [40.107.94.79]) (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 A54E6224DB for ; Fri, 26 Jan 2024 18:59:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.94.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706295558; cv=fail; b=EajQKabYQ3HQwB1NJyD5jUN68RiEjlaTkCGrHGFrsUqTW9k0GbkeZevOT00399w4Jjyh/bUv/MJl+ARb/yNnO4Du3dKe66Dq0DdfsYjvMfZ9t1tnq9yJhjK1vCtOH5MeEL7jeFD7vi7uzpw599rL6j5H//wPGsqgBiGFzWHwf/M= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706295558; c=relaxed/simple; bh=8ePw04mKAp6x+WPnjt9fIgtvVh76IQKcph4eW2jACM4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RLfEmbsntvn/5Ago+MWvRPEYLTuWO6ylblXZVn736a/irgX1ITS7Fst25Sw2UvzOA6EErhkhaHoSFYPfmSmvMFM5Yish3GSfzCS5CDMiDBwUuuV+1HfOZaQaBSXqZeXIlK2yFQ/OGaJK9Y/98FfCpgpTqinJdXqZRWDHbTafJpI= 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=kT4nhKPx; arc=fail smtp.client-ip=40.107.94.79 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="kT4nhKPx" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HHBlv2Oor5NozULk+J6g74LXZ8TAhGve8BNuO2pXcpkChGdfozdK062kBGjAADYdNidnDvmnYWPuNxTVWznDY3HvG0rh59jS/8AJ8lHZ2zTEJ0Jd9dghtlv/R+AtgQn9UELx2GIneFszAfufxx1vPutzTMnj7My6MbCj04XuFdHo6sDalK0pJo09oZto+OW+SGUqkm/KGa3tKk0twGsXridMONJBiN/rbLsvdBE1wRCmRDfX6/B6sKkzfekorsGYA7LGCwjR3xr3ZtOfO+627JrXJHbP4hkXxB6TKIVOo40vJF7B755GtLUBBfshanA5IUDYUN8bEssIB8MD3zS6Tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=07sUYA0+Bnjxlpg4L/nrtkoFiqnL2PRuw7mMv+RyY5w=; b=n48POJ67AFnyzM88t7Ac51NhO8Fi2sU/pgPITrMPJ6MJDWWE58c+lCf5vyNIU8DsY3vvHXIGv51LHVTdNUGkVZsa4RRBoHm/agbaEvIcHkG44jSXJ7NAe3p50aMU1lkmVi8eT+kJCjUkRWTVkds75bN72DWKHE/Sl5vty3265RDOuZz8Rmt/8VXTjUcm4CcgbrhqtafCqECN39NhJSS7vRTZP1/p6yQRfIi8jEy57nnWL3IW+5arVv75bG5fSIO3mzlTntDYTfZxYODdNjcMgY7rmCHA1t36Y3b835IFz/0lCjtihmJ5Cv5CfbTYdb1dAWTPnRPfra1kfj0VGxJ/dw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=davemloft.net 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=07sUYA0+Bnjxlpg4L/nrtkoFiqnL2PRuw7mMv+RyY5w=; b=kT4nhKPxhUsEg9RmC+a5alzxpNal670ZGxNU5XPR6dvvJvF0HvbcwQWBcDdaJ64pldcPb4tVgsXg50Z/lsTySaa1iZ6YHQB9AoShDpj/yGes6ZA7ORrLH53IyzBS6cxKPvFA09OvO6CN5+t0JxvTC5NEvZ9amcw40TVsneiqD+4Ox4qqqXHCtOAhaqdVQqOOvI8a8WnJ5/fn1FBn3bTclpv8rRlITGKrfPjrLANTngF3rB/73PPhrYJAj7PO9g8ggmQIk8mwxAYZbzNpTaTs4W/XNDhuV4XcT+os+f0r+Hy4ixRy0davJQrFOVgANYGIUgyDoWBnzmjouKcjnxa4Kg== Received: from BL1PR13CA0419.namprd13.prod.outlook.com (2603:10b6:208:2c2::34) by SN7PR12MB7835.namprd12.prod.outlook.com (2603:10b6:806:328::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.26; Fri, 26 Jan 2024 18:59:14 +0000 Received: from MN1PEPF0000ECD4.namprd02.prod.outlook.com (2603:10b6:208:2c2:cafe::fd) by BL1PR13CA0419.outlook.office365.com (2603:10b6:208:2c2::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.21 via Frontend Transport; Fri, 26 Jan 2024 18:59:14 +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 MN1PEPF0000ECD4.mail.protection.outlook.com (10.167.242.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.16 via Frontend Transport; Fri, 26 Jan 2024 18:59:14 +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.986.41; Fri, 26 Jan 2024 10:58:57 -0800 Received: from localhost.localdomain (10.126.230.35) 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.986.41; Fri, 26 Jan 2024 10:58:54 -0800 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "Amit Cohen" , Subject: [PATCH net-next 4/6] mlxsw: spectrum: Search for free LAD ID once Date: Fri, 26 Jan 2024 19:58:29 +0100 Message-ID: <903f25dbfc84fe1f384d92ea7f8902a2051bb7bc.1706293430.git.petrm@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000ECD4:EE_|SN7PR12MB7835:EE_ X-MS-Office365-Filtering-Correlation-Id: 6831d3c9-7c9c-48ab-1687-08dc1ea0e3c4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kUzRHYExMYbcv04VT81uwtFj33SEs4zN3TxTXw785l5qWrO4GhQN8t5JyZkRmhZkIl9O9GB5GHcXUyFytbaAdx2KM8B2uQqnbKT9+0J71pnIQkE0dHzlK5kQ4brawkq8ED+6CAhaWdiNZI4ZWIzOJxwHRGWkDqny0+OAHra5tPxgUmB+rXfRLuoskN87bOGu1evRtGyb8pA1iwDGRGwYjnS65s7WTN//zgThM+qbCkkEw/w4tiUhXxjRjJGHUUmg61vj/DtgSQXLeG7oJ6JspoDsUgYS9o66VBX/Z3vnHpFahaZvKjW/2GSvORSU40ZDGJhCFb2vLeW6ynP3mNZcvyllDGUaLuSDx62j4C4rfsR0KNXHSTzr+0Vk4ILkugJFgULdBv1gVHAdIDVTmlnPDWAd/gLTKrFu7j6Crcj5tIfqn7Y3pmg96rFA6A6XWzyFA8TxTEqVoFVEH0kdHIOPj5vi822ZgxIIsBM1s+xIIlX/LWNsaZd6MnZuj9K7uWwA0Jv1qHgAxMMaSYPnzSNtUhLLlC+NWqXfbqLxhNH3Wf39dI1LqCwfeUuWI3pR3MZJq3+QTP7EZW+GH3jHoVOt39wfZddoaC4d7xdvOQJx9lwCoaoGwUrrXvDXLRDuVn6VVL+3NYpeGF0ERvcX0AQpu3bb/HHT05FbGsjC9RcMIwVBR9Mo4BuCez1LeoH4LMVBvO00OAU0rPKbUMIwf/a4ubY9m3EefYPUyu637Jwr2D3S7A8WvPw3teEnQXd0XWBZ 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:(13230031)(4636009)(346002)(39860400002)(376002)(136003)(396003)(230922051799003)(186009)(451199024)(64100799003)(82310400011)(1800799012)(46966006)(40470700004)(36840700001)(7636003)(36860700001)(336012)(16526019)(426003)(47076005)(41300700001)(83380400001)(26005)(8936002)(4326008)(8676002)(54906003)(86362001)(70206006)(478600001)(110136005)(70586007)(36756003)(5660300002)(107886003)(316002)(2616005)(2906002)(6666004)(356005)(82740400003)(40460700003)(40480700001)(4533004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 18:59:14.2616 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6831d3c9-7c9c-48ab-1687-08dc1ea0e3c4 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: MN1PEPF0000ECD4.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7835 X-Patchwork-Delegate: kuba@kernel.org From: Amit Cohen Currently, the function mlxsw_sp_lag_index_get() is called twice - first as part of NETDEV_PRECHANGEUPPER event and later as part of NETDEV_CHANGEUPPER. This function will be changed in the next patch. To simplify the code, call it only once as part of NETDEV_CHANGEUPPER event and set an error message using 'extack' in case of failure. Signed-off-by: Amit Cohen Reviewed-by: Ido Schimmel Signed-off-by: Ido Schimmel Signed-off-by: Petr Machata Reviewed-by: Simon Horman --- drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c index 75fea062a984..556dfddff005 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c @@ -4323,7 +4323,7 @@ static int mlxsw_sp_lag_col_port_disable(struct mlxsw_sp_port *mlxsw_sp_port, static int mlxsw_sp_lag_index_get(struct mlxsw_sp *mlxsw_sp, struct net_device *lag_dev, - u16 *p_lag_id) + u16 *p_lag_id, struct netlink_ext_ack *extack) { struct mlxsw_sp_lag *lag; int free_lag_id = -1; @@ -4340,8 +4340,11 @@ static int mlxsw_sp_lag_index_get(struct mlxsw_sp *mlxsw_sp, free_lag_id = i; } } - if (free_lag_id < 0) + if (free_lag_id < 0) { + NL_SET_ERR_MSG_MOD(extack, + "Exceeded number of supported LAG devices"); return -EBUSY; + } *p_lag_id = free_lag_id; return 0; } @@ -4352,12 +4355,6 @@ mlxsw_sp_master_lag_check(struct mlxsw_sp *mlxsw_sp, struct netdev_lag_upper_info *lag_upper_info, struct netlink_ext_ack *extack) { - u16 lag_id; - - if (mlxsw_sp_lag_index_get(mlxsw_sp, lag_dev, &lag_id) != 0) { - NL_SET_ERR_MSG_MOD(extack, "Exceeded number of supported LAG devices"); - return false; - } if (lag_upper_info->tx_type != NETDEV_LAG_TX_TYPE_HASH) { NL_SET_ERR_MSG_MOD(extack, "LAG device using unsupported Tx type"); return false; @@ -4474,7 +4471,7 @@ static int mlxsw_sp_port_lag_join(struct mlxsw_sp_port *mlxsw_sp_port, u8 port_index; int err; - err = mlxsw_sp_lag_index_get(mlxsw_sp, lag_dev, &lag_id); + err = mlxsw_sp_lag_index_get(mlxsw_sp, lag_dev, &lag_id, extack); if (err) return err; lag = &mlxsw_sp->lags[lag_id]; From patchwork Fri Jan 26 18:58:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13533225 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2066.outbound.protection.outlook.com [40.107.244.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 349F621A19 for ; Fri, 26 Jan 2024 18:59:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.66 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706295555; cv=fail; b=dqGU2OfPEhsVcuOfGZgUe9COwmz4B4a3dDR/hTOqx27J31e92VNNseEqZ86qLoUpPaInvoAGn4A0Mx2kb6/n9vyxL+lPl5K7TX9XdPCef3xkqfQ5DNo6dN+LbXArd45glyxR8hpHOmzO/R5+RpzqcExkvA+5xLYHXne8nGUqsdY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706295555; c=relaxed/simple; bh=yYj81KJfFxv44QXziC0KNu1ZPI/x8sYwZIrO47m7Qfo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mBUpt7Wplwdw/C+uPZWhpgFASQT86gwpD6cBeKltgQaVH3EZcSxwem787g90487xBVrlWTmCM/TSPbd4F7JaeLonz1RdCfGZPx+lt7Q/PMzzim2m+EXwx+8RChJQbxzgcutEuRVlqvXMV6VuMzfQNlMs5SIzqPM9g3DPQDksBBg= 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=sgbcd1aJ; arc=fail smtp.client-ip=40.107.244.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="sgbcd1aJ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GnZI5Sv8UR7KA2FUUoZ/jjdJ+SJi9G4tao+I6Fm0KaMUU+I6b8tN91FZr6ijZUkVF4TemBJMWshLjvFF39xyUG6RQx2uXAP9uRlvd04WMU9F/i2b7w3ghWjBupBGlHFqGInTvMKph0eNlY3k6+0lLb8xYyYd+Cg8uPHzFUwo2DR0HvUlB4gvPR2cGF9/PQWmOn55c3cDuJqkddU9nghvERtHXzKpKmwMHPzK27fWZ6yLud9iMHqORjOnRKqHr56/37lxxeBNVAVjJ9w8zl8WlwpB+yZXuDk/DH6MCa2EHrM7lRqFbRmzRiHjBNTrxxH6pLT+TYWAqvaKzNkH7hzahA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=fZjDNkcE0U5z7LP4YVoaYEIn6ym6nkpKzfpMYYzMNiE=; b=b9VVpyXVh7dp66TRnJK06O7Xg5tPBYPCe1us3gjhiojT9pnV6ta1CRdR/QFnfqXBDZIZEH7Pg9fc5BS4uU8osvsNPJ+CjjBYtlr5CdDYho5LFMVA8f6vHkSWeOSgYgz4Fj1jg6bdZ/xO1MD1Us6EMZ7iGNRso/e7OvaRBvb0p4AJHGi3GxFkjBo4YEnj0oYARuCQsg85X8crDl9gx8B3a7n32zPcbXEuu9LwSPfp6h/0QNkGegVUGny4b+z5NZhrVhJb7PaQlpHjxpXhhvI/c0xbALkJFaxlW2EeQOi1e8j+R/rfsXiyb9KYf5SXRD6KoHhtR7QXlxw1QhLJk2y5iA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=davemloft.net 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=fZjDNkcE0U5z7LP4YVoaYEIn6ym6nkpKzfpMYYzMNiE=; b=sgbcd1aJPO/mgqZeHURJSkwe88joWwY/i4kL9rGzqI9oAZ66bIQU55E+v7tzOklGcFv808YnvOW5u8lK647mTW60gmy4PJfHgajplabAHU5Cj2jIaUndm2O2lHm36IE6UsGU6brYBdz6AbwynICltY1/YYxd+GgsHaS+FCzV8f/3YeWqI38aETN7PRdCS3xFh2v9JkiadBj+yNckYImb0Yw8pDL8wo/OJ9GJNlyeh9Z4h6+dUozPp/UAAgh2Dqh44xe+J0cuHHNMdt/C27jYPA0KMCDws6RBaSWOClS08rvU1B63s2f3k90cfxC4WrdUKv/mivid9yHJGinNPcBZfg== Received: from DS7PR05CA0107.namprd05.prod.outlook.com (2603:10b6:8:56::25) by DS7PR12MB6215.namprd12.prod.outlook.com (2603:10b6:8:95::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.37; Fri, 26 Jan 2024 18:59:11 +0000 Received: from DS1PEPF00017094.namprd03.prod.outlook.com (2603:10b6:8:56:cafe::b6) by DS7PR05CA0107.outlook.office365.com (2603:10b6:8:56::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.15 via Frontend Transport; Fri, 26 Jan 2024 18:59:11 +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 DS1PEPF00017094.mail.protection.outlook.com (10.167.17.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.16 via Frontend Transport; Fri, 26 Jan 2024 18:59:10 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) 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.986.41; Fri, 26 Jan 2024 10:58:59 -0800 Received: from localhost.localdomain (10.126.230.35) 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.986.41; Fri, 26 Jan 2024 10:58:57 -0800 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "Amit Cohen" , Subject: [PATCH net-next 5/6] mlxsw: spectrum: Refactor LAG create and destroy code Date: Fri, 26 Jan 2024 19:58:30 +0100 Message-ID: <30eb498438bf114bfcd8c02bc6117007aa0e9600.1706293430.git.petrm@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017094:EE_|DS7PR12MB6215:EE_ X-MS-Office365-Filtering-Correlation-Id: 48f7b821-e107-47bc-84b7-08dc1ea0e1ae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AfXlGRnyLdavWExULOFekEmNgrSpMeWnd9va6Q6kLQGkKxPeh5DzHJZA06PnpTgl98XCtGO1D7U4vcfgfDVwZ213MclEhmGJVrIYGiJQlo7OIyctZhFEe09PtXiBHpkytlwbdzif7zHTj57Pp6fB53deOIgYaaCU7ylLFkoZkHTdV2V2kaIqbg+3AgletvkxmqN5//F1L+U4mCbhgNG7IHHLfnfuB148fFoe8Q72cKe1mmNk0Rj3YWDqsTIWTEk2PtAJxHgl6Jbnx1MYDeeEjIJlTVmf2QmQ79RQJ1COq6lnhSdZtB6d8DIaxAaQYES43VUlQshfO35i+ldhq3f5AGA+N9CbqN+15r1Qae1U3KeG+oVPHDjiVclsptDVoMczCmxIJ+Ob+N/PHVqyvbsz7kHeh31Z/7fDPJk+9ua7wmKDsCDiIngUZb40dZK8WoVdPlJnmWTwtIgl+IYs6UWlUAsHW0l0BRKdPwDM4KJbdox5bjd7KXc73GxI5MiMKlCyGtGKdU63K5YRusEdpBwaZamjnAZtRKDppw3JuMuc3+rPz55XSeiynDHTAizdPFII1NUWblhfXY098VRcel4cVRprZWDNE5mVZCYdTR1FBXBGbokC9Cy4izngO0ttaHNp32Hp/Lysd4a2NLKrNz6H6T5tMKYqNFw7ntYu1fPVPL63flpY1Aa3mbxIggZlZ1OtBUKKYN6UEhQ/olP0hTVHyoiFWsJ2eK3udVxioVKIZJWDkgCqd/Zac7ggOU0PzQwZ 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:(13230031)(4636009)(376002)(136003)(346002)(39860400002)(396003)(230922051799003)(1800799012)(186009)(451199024)(64100799003)(82310400011)(46966006)(40470700004)(36840700001)(5660300002)(6666004)(478600001)(4326008)(316002)(54906003)(86362001)(8936002)(8676002)(70586007)(70206006)(110136005)(36860700001)(356005)(82740400003)(41300700001)(47076005)(7636003)(36756003)(426003)(2616005)(66574015)(336012)(26005)(40480700001)(2906002)(40460700003)(107886003)(16526019)(83380400001);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 18:59:10.8116 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 48f7b821-e107-47bc-84b7-08dc1ea0e1ae 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: DS1PEPF00017094.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6215 X-Patchwork-Delegate: kuba@kernel.org From: Amit Cohen mlxsw_sp stores an array of LAGs. When a port joins a LAG, in case that this LAG is already in use, we only have to increase the reference counter. Otherwise, we have to search for an unused LAG ID and configure it in hardware. When a port leaves a LAG, we have to destroy it only for the last user. This code can be simplified, for such requirements we usually add get() and put() functions which create and destroy the object. Add mlxsw_sp_lag_{get,put}() and use them. These functions take care of the reference counter and hardware configuration if needed. Change the reference counter to refcount_t type which catches overflow and underflow issues. Signed-off-by: Amit Cohen Reviewed-by: Ido Schimmel Signed-off-by: Ido Schimmel Signed-off-by: Petr Machata Reviewed-by: Simon Horman --- .../net/ethernet/mellanox/mlxsw/spectrum.c | 116 +++++++++++------- 1 file changed, 73 insertions(+), 43 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c index 556dfddff005..ecde2086c703 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c @@ -2741,7 +2741,8 @@ static void mlxsw_sp_lag_pgt_fini(struct mlxsw_sp *mlxsw_sp) struct mlxsw_sp_lag { struct net_device *dev; - unsigned int ref_count; + refcount_t ref_count; + u16 lag_id; }; static int mlxsw_sp_lag_init(struct mlxsw_sp *mlxsw_sp) @@ -4261,19 +4262,48 @@ mlxsw_sp_port_lag_uppers_cleanup(struct mlxsw_sp_port *mlxsw_sp_port, } } -static int mlxsw_sp_lag_create(struct mlxsw_sp *mlxsw_sp, u16 lag_id) +static struct mlxsw_sp_lag * +mlxsw_sp_lag_create(struct mlxsw_sp *mlxsw_sp, struct net_device *lag_dev, + struct netlink_ext_ack *extack) { char sldr_pl[MLXSW_REG_SLDR_LEN]; + struct mlxsw_sp_lag *lag; + u16 lag_id; + int i, err; + for (i = 0; i < mlxsw_sp->max_lag; i++) { + if (!mlxsw_sp->lags[i].dev) + break; + } + + if (i == mlxsw_sp->max_lag) { + NL_SET_ERR_MSG_MOD(extack, + "Exceeded number of supported LAG devices"); + return ERR_PTR(-EBUSY); + } + + lag_id = i; mlxsw_reg_sldr_lag_create_pack(sldr_pl, lag_id); - return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sldr), sldr_pl); + err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sldr), sldr_pl); + if (err) + return ERR_PTR(err); + + lag = &mlxsw_sp->lags[lag_id]; + lag->lag_id = lag_id; + lag->dev = lag_dev; + refcount_set(&lag->ref_count, 1); + + return lag; } -static int mlxsw_sp_lag_destroy(struct mlxsw_sp *mlxsw_sp, u16 lag_id) +static int +mlxsw_sp_lag_destroy(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_lag *lag) { char sldr_pl[MLXSW_REG_SLDR_LEN]; - mlxsw_reg_sldr_lag_destroy_pack(sldr_pl, lag_id); + lag->dev = NULL; + + mlxsw_reg_sldr_lag_destroy_pack(sldr_pl, lag->lag_id); return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sldr), sldr_pl); } @@ -4321,32 +4351,44 @@ static int mlxsw_sp_lag_col_port_disable(struct mlxsw_sp_port *mlxsw_sp_port, return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(slcor), slcor_pl); } -static int mlxsw_sp_lag_index_get(struct mlxsw_sp *mlxsw_sp, - struct net_device *lag_dev, - u16 *p_lag_id, struct netlink_ext_ack *extack) +static struct mlxsw_sp_lag * +mlxsw_sp_lag_find(struct mlxsw_sp *mlxsw_sp, struct net_device *lag_dev) { - struct mlxsw_sp_lag *lag; - int free_lag_id = -1; int i; for (i = 0; i < mlxsw_sp->max_lag; i++) { - lag = &mlxsw_sp->lags[i]; - if (lag->ref_count) { - if (lag->dev == lag_dev) { - *p_lag_id = i; - return 0; - } - } else if (free_lag_id < 0) { - free_lag_id = i; - } + if (!mlxsw_sp->lags[i].dev) + continue; + + if (mlxsw_sp->lags[i].dev == lag_dev) + return &mlxsw_sp->lags[i]; } - if (free_lag_id < 0) { - NL_SET_ERR_MSG_MOD(extack, - "Exceeded number of supported LAG devices"); - return -EBUSY; + + return NULL; +} + +static struct mlxsw_sp_lag * +mlxsw_sp_lag_get(struct mlxsw_sp *mlxsw_sp, struct net_device *lag_dev, + struct netlink_ext_ack *extack) +{ + struct mlxsw_sp_lag *lag; + + lag = mlxsw_sp_lag_find(mlxsw_sp, lag_dev); + if (lag) { + refcount_inc(&lag->ref_count); + return lag; } - *p_lag_id = free_lag_id; - return 0; + + return mlxsw_sp_lag_create(mlxsw_sp, lag_dev, extack); +} + +static void +mlxsw_sp_lag_put(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_lag *lag) +{ + if (!refcount_dec_and_test(&lag->ref_count)) + return; + + mlxsw_sp_lag_destroy(mlxsw_sp, lag); } static bool @@ -4471,17 +4513,11 @@ static int mlxsw_sp_port_lag_join(struct mlxsw_sp_port *mlxsw_sp_port, u8 port_index; int err; - err = mlxsw_sp_lag_index_get(mlxsw_sp, lag_dev, &lag_id, extack); - if (err) - return err; - lag = &mlxsw_sp->lags[lag_id]; - if (!lag->ref_count) { - err = mlxsw_sp_lag_create(mlxsw_sp, lag_id); - if (err) - return err; - lag->dev = lag_dev; - } + lag = mlxsw_sp_lag_get(mlxsw_sp, lag_dev, extack); + if (IS_ERR(lag)) + return PTR_ERR(lag); + lag_id = lag->lag_id; err = mlxsw_sp_port_lag_index_get(mlxsw_sp, lag_id, &port_index); if (err) return err; @@ -4499,7 +4535,6 @@ static int mlxsw_sp_port_lag_join(struct mlxsw_sp_port *mlxsw_sp_port, mlxsw_sp_port->local_port); mlxsw_sp_port->lag_id = lag_id; mlxsw_sp_port->lagged = 1; - lag->ref_count++; err = mlxsw_sp_fid_port_join_lag(mlxsw_sp_port); if (err) @@ -4526,7 +4561,6 @@ static int mlxsw_sp_port_lag_join(struct mlxsw_sp_port *mlxsw_sp_port, err_router_join: mlxsw_sp_fid_port_leave_lag(mlxsw_sp_port); err_fid_port_join_lag: - lag->ref_count--; mlxsw_sp_port->lagged = 0; mlxsw_core_lag_mapping_clear(mlxsw_sp->core, lag_id, mlxsw_sp_port->local_port); @@ -4534,8 +4568,7 @@ static int mlxsw_sp_port_lag_join(struct mlxsw_sp_port *mlxsw_sp_port, err_col_port_add: mlxsw_sp_lag_uppers_bridge_leave(mlxsw_sp_port, lag_dev); err_lag_uppers_bridge_join: - if (!lag->ref_count) - mlxsw_sp_lag_destroy(mlxsw_sp, lag_id); + mlxsw_sp_lag_put(mlxsw_sp, lag); return err; } @@ -4549,7 +4582,6 @@ static void mlxsw_sp_port_lag_leave(struct mlxsw_sp_port *mlxsw_sp_port, if (!mlxsw_sp_port->lagged) return; lag = &mlxsw_sp->lags[lag_id]; - WARN_ON(lag->ref_count == 0); mlxsw_sp_lag_col_port_remove(mlxsw_sp_port, lag_id); @@ -4563,13 +4595,11 @@ static void mlxsw_sp_port_lag_leave(struct mlxsw_sp_port *mlxsw_sp_port, mlxsw_sp_fid_port_leave_lag(mlxsw_sp_port); - if (lag->ref_count == 1) - mlxsw_sp_lag_destroy(mlxsw_sp, lag_id); + mlxsw_sp_lag_put(mlxsw_sp, lag); mlxsw_core_lag_mapping_clear(mlxsw_sp->core, lag_id, mlxsw_sp_port->local_port); mlxsw_sp_port->lagged = 0; - lag->ref_count--; /* Make sure untagged frames are allowed to ingress */ mlxsw_sp_port_pvid_set(mlxsw_sp_port, MLXSW_SP_DEFAULT_VID, From patchwork Fri Jan 26 18:58:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Machata X-Patchwork-Id: 13533228 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2043.outbound.protection.outlook.com [40.107.100.43]) (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 2F868210ED for ; Fri, 26 Jan 2024 18:59:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706295566; cv=fail; b=qSR9V6vcP2+8fYLR+DtzP0UUNYrywUPglCPXjXeeZasolF5N0Buo/9QLA3xOR8rR4jrqzn50ntYGgh3TP88nzKlAkZ3CBx6RIkFbf/uZHDT1wxBiZH+8KUhM9bvaw/X/6hiMhjXA24DU6geq7b0x9Y0MxSIMxOJDQgKWWBiJ5+k= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706295566; c=relaxed/simple; bh=FERHuUg7a05rGcjtKusL/7DEMA9LkpsltrrbrjW1bAE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jIZfj46UMUe+q33UydEmexsc2I+kGhbw41esvamktQ6vvPQyDHE7o1kXVJkLLbZxGE9C4ZoOxucwNjjUQ7bj9uxrmmp83TNYBjwKg3z6kRnWszEPe6Ulzldl1kJEAgMHbiDzJmeMkxHsz7xrnhCjzcNCr/4iYVM0WzlXWOjmeWw= 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=AkdI/9Xn; arc=fail smtp.client-ip=40.107.100.43 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="AkdI/9Xn" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VljqBYpLN/CnP+HAC1nM2lk39AgjyyBPEHq6ZhZzJkwC0GcmHGmOaj2o4zbgNGLrAfItH5f4N3/qt62Rec9Q3/aahV6qTf0APHfXrxhJGovUJl6qvWK2eKWLHqdOyxFK/WbKNUaszLpsXi95laAnqwYpGt70lqwz7iU7d+tafGUQgIDqtj59D/orIAMPeI6+p0Ukl02JifAeOTkf2m5qr0ByZShFtqe/M4RsviNDTBuCpk/m1STDNp7P4P27YNvWyxKRB+dao65ehF1vxH3ZuEh+90jPnZRVMlhXOZ43gYX9ON6LOU4SsOuxu53S36EcgaEND0ktqGesOvXgdpYYJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=4xj5Q7kuL829aQHX8uO0t5JH4W2yn9zi8WgzD4h8uGw=; b=Mh3WB2Zywu8n6qSFC4uxzWjNqJwBG7eZBS1/YFd9VO/I2pkuIrb3w6KzHanemQ28XihQCQX7mLSmvnnhRIlPMs+0QAzn08d40O36ZAzqQnXU5qXjWbYQpKeg5ySvMpmM4M65n7Fqnp4NUgtt5DXP33Rc+jbAcH5V8nt2kWK3g0eIKY4pQht/MOen9iam3DYKNp91B2gh82eyosdmHfn0GA3UsromnGOXg45GbZ3c9drziHKjy4RgF2dM/cnM93Cj/4TVmh/LdXwfNtyo7CfwOvJ6Gy9pAiSF7Bc8Ldd3ieE0/9c3w2PQSDtAIviHEy3avpz2SpAq+nXeS2pBMIbUgQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=davemloft.net 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=4xj5Q7kuL829aQHX8uO0t5JH4W2yn9zi8WgzD4h8uGw=; b=AkdI/9Xn7hdSR/tSNRm4dkRiZYJQfNkdyA4PDgO1Ag7jFnBgLQW+dVLRqtPDQpFFL4G0QTc76/Be49Oh9yH9V6v1y8G0d8Qv5iE0h1t1hiCT0AgOirVveTV/gB2xw0wngcvQSd97o58MbyZD2FqjhLYSPbqBc2xp4XWE6bsurpNOr6GIoBTjtrmypOAabw6EVsoQdfbrnf6VtZUrHipeQv6Bgt9nG1504MDTuP36XBCEmTRIYfvtMG+LDfJ0QxtPFDwq4U0f6/7iXsb9yXbDqvHPq0rlyNNisNWTj4XXufPC9nsz3/O56ifkA2bLhlncb40CmeTGbivSgdns+RRK8Q== Received: from DS7PR06CA0037.namprd06.prod.outlook.com (2603:10b6:8:54::12) by DS7PR12MB8202.namprd12.prod.outlook.com (2603:10b6:8:e1::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7202.37; Fri, 26 Jan 2024 18:59:14 +0000 Received: from DS1PEPF00017090.namprd03.prod.outlook.com (2603:10b6:8:54:cafe::e0) by DS7PR06CA0037.outlook.office365.com (2603:10b6:8:54::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.27 via Frontend Transport; Fri, 26 Jan 2024 18:59:14 +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 DS1PEPF00017090.mail.protection.outlook.com (10.167.17.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.16 via Frontend Transport; Fri, 26 Jan 2024 18:59:13 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) 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.986.41; Fri, 26 Jan 2024 10:59:02 -0800 Received: from localhost.localdomain (10.126.230.35) 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.986.41; Fri, 26 Jan 2024 10:58:59 -0800 From: Petr Machata To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , CC: Ido Schimmel , Petr Machata , "Amit Cohen" , Subject: [PATCH net-next 6/6] mlxsw: Use refcount_t for reference counting Date: Fri, 26 Jan 2024 19:58:31 +0100 Message-ID: <4ffc173920a7b0780dee4f5af91e0d44d0b898f3.1706293430.git.petrm@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017090:EE_|DS7PR12MB8202:EE_ X-MS-Office365-Filtering-Correlation-Id: 246d0298-139d-4357-f4fb-08dc1ea0e385 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ln7tlKngaH9HDzluGRXq14fchTeyLMer1Vt6m0PcOaYrKDHn71AlUApqiSQIMt2wr84icO2aDliaOW4REEsvkQhIHB50R6z2R7etSN4XY6Xqd0NMP7f7A2meS0RhpYqp7jKfZWBc+aPv6aLx28N1faMWtsl/+44/Q1ADCS8DdRQjzLsk4Fc/mTzt064yWDBsceVpyEeDXVNlW7T9HwvfY7bjg93NnrMElDwljC7nuIvhQMLRg8Bb5mhXLpGMPOUvfr4lNJ2o1xq0q0Kb0bp/QdUyRqRe5OePjSuWM0yX6ylPO3yp21CGJokvWgBxYNnFyykuGpbglqS2c1mhjcPYJvzTS3SzGnLW2dx6q/ONZHZaIHaN3lsVF2+SY4HuJjoTceDOqRKx6yC3lhiQAIIiXMH6kqec4YWfqkD6g9U2+tzsB5gLbwkYMvUpvFhQDMLVdiMsQOlNVYZptdwN7C0CPINEOe1oPmZT2O2zQShSXruK25Iee5DCZQfFHoCVIr4F17YqtPI9vxn9K3G2qXBzlPnThpo9DC/nwhT2yIcvtU5ZhbQBcrbz9h4wMDlUPylbD8Qho9bRx6Bgc8nO9PhhayWT87pl94Yi1RA8XzFiKel+U8OO1kvXkLSYp95EJ5nULEE9QhulU6Z1i4fMQQe46fkWHs6rcPJ86gO/C6nHqs4BACOH+kyX02avzFfrZx9m0OtJDlNoRonyLf1R2yuP8ilN0EJG6Uupl4Qs5C7EUbQPQr+IpR+h7xdKB+bhaB4j 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:(13230031)(4636009)(346002)(376002)(136003)(39860400002)(396003)(230922051799003)(451199024)(64100799003)(186009)(82310400011)(1800799012)(36840700001)(46966006)(40470700004)(2906002)(30864003)(5660300002)(41300700001)(426003)(16526019)(66574015)(82740400003)(478600001)(36860700001)(40460700003)(26005)(6666004)(47076005)(83380400001)(86362001)(107886003)(4326008)(2616005)(356005)(40480700001)(110136005)(7636003)(8936002)(54906003)(316002)(336012)(70206006)(8676002)(70586007)(36756003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 18:59:13.9012 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 246d0298-139d-4357-f4fb-08dc1ea0e385 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: DS1PEPF00017090.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8202 X-Patchwork-Delegate: kuba@kernel.org From: Amit Cohen mlxsw driver uses 'unsigned int' for reference counters in several structures. Instead, use refcount_t type which allows us to catch overflow and underflow issues. Change the type of the counters and use the appropriate API. Signed-off-by: Amit Cohen Reviewed-by: Ido Schimmel Signed-off-by: Ido Schimmel Signed-off-by: Petr Machata Reviewed-by: Simon Horman --- .../mellanox/mlxsw/core_acl_flex_actions.c | 16 ++++++++-------- .../mellanox/mlxsw/core_acl_flex_keys.c | 9 +++++---- .../net/ethernet/mellanox/mlxsw/spectrum_acl.c | 11 ++++++----- .../ethernet/mellanox/mlxsw/spectrum_acl_tcam.c | 17 +++++++++-------- .../ethernet/mellanox/mlxsw/spectrum_router.c | 15 ++++++++------- .../mellanox/mlxsw/spectrum_switchdev.c | 8 ++++---- 6 files changed, 40 insertions(+), 36 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c index faa63ea9b83e..1915fa41c622 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_actions.c @@ -95,7 +95,7 @@ struct mlxsw_afa_set { */ has_trap:1, has_police:1; - unsigned int ref_count; + refcount_t ref_count; struct mlxsw_afa_set *next; /* Pointer to the next set. */ struct mlxsw_afa_set *prev; /* Pointer to the previous set, * note that set may have multiple @@ -120,7 +120,7 @@ struct mlxsw_afa_fwd_entry { struct rhash_head ht_node; struct mlxsw_afa_fwd_entry_ht_key ht_key; u32 kvdl_index; - unsigned int ref_count; + refcount_t ref_count; }; static const struct rhashtable_params mlxsw_afa_fwd_entry_ht_params = { @@ -282,7 +282,7 @@ static struct mlxsw_afa_set *mlxsw_afa_set_create(bool is_first) /* Need to initialize the set to pass by default */ mlxsw_afa_set_goto_set(set, MLXSW_AFA_SET_GOTO_BINDING_CMD_TERM, 0); set->ht_key.is_first = is_first; - set->ref_count = 1; + refcount_set(&set->ref_count, 1); return set; } @@ -330,7 +330,7 @@ static void mlxsw_afa_set_unshare(struct mlxsw_afa *mlxsw_afa, static void mlxsw_afa_set_put(struct mlxsw_afa *mlxsw_afa, struct mlxsw_afa_set *set) { - if (--set->ref_count) + if (!refcount_dec_and_test(&set->ref_count)) return; if (set->shared) mlxsw_afa_set_unshare(mlxsw_afa, set); @@ -350,7 +350,7 @@ static struct mlxsw_afa_set *mlxsw_afa_set_get(struct mlxsw_afa *mlxsw_afa, set = rhashtable_lookup_fast(&mlxsw_afa->set_ht, &orig_set->ht_key, mlxsw_afa_set_ht_params); if (set) { - set->ref_count++; + refcount_inc(&set->ref_count); mlxsw_afa_set_put(mlxsw_afa, orig_set); } else { set = orig_set; @@ -564,7 +564,7 @@ mlxsw_afa_fwd_entry_create(struct mlxsw_afa *mlxsw_afa, u16 local_port) if (!fwd_entry) return ERR_PTR(-ENOMEM); fwd_entry->ht_key.local_port = local_port; - fwd_entry->ref_count = 1; + refcount_set(&fwd_entry->ref_count, 1); err = rhashtable_insert_fast(&mlxsw_afa->fwd_entry_ht, &fwd_entry->ht_node, @@ -607,7 +607,7 @@ mlxsw_afa_fwd_entry_get(struct mlxsw_afa *mlxsw_afa, u16 local_port) fwd_entry = rhashtable_lookup_fast(&mlxsw_afa->fwd_entry_ht, &ht_key, mlxsw_afa_fwd_entry_ht_params); if (fwd_entry) { - fwd_entry->ref_count++; + refcount_inc(&fwd_entry->ref_count); return fwd_entry; } return mlxsw_afa_fwd_entry_create(mlxsw_afa, local_port); @@ -616,7 +616,7 @@ mlxsw_afa_fwd_entry_get(struct mlxsw_afa *mlxsw_afa, u16 local_port) static void mlxsw_afa_fwd_entry_put(struct mlxsw_afa *mlxsw_afa, struct mlxsw_afa_fwd_entry *fwd_entry) { - if (--fwd_entry->ref_count) + if (!refcount_dec_and_test(&fwd_entry->ref_count)) return; mlxsw_afa_fwd_entry_destroy(mlxsw_afa, fwd_entry); } diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.c b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.c index 0d5e6f9b466e..947500f8ed71 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "item.h" #include "core_acl_flex_keys.h" @@ -107,7 +108,7 @@ EXPORT_SYMBOL(mlxsw_afk_destroy); struct mlxsw_afk_key_info { struct list_head list; - unsigned int ref_count; + refcount_t ref_count; unsigned int blocks_count; int element_to_block[MLXSW_AFK_ELEMENT_MAX]; /* index is element, value * is index inside "blocks" @@ -334,7 +335,7 @@ mlxsw_afk_key_info_create(struct mlxsw_afk *mlxsw_afk, if (err) goto err_picker; list_add(&key_info->list, &mlxsw_afk->key_info_list); - key_info->ref_count = 1; + refcount_set(&key_info->ref_count, 1); return key_info; err_picker: @@ -356,7 +357,7 @@ mlxsw_afk_key_info_get(struct mlxsw_afk *mlxsw_afk, key_info = mlxsw_afk_key_info_find(mlxsw_afk, elusage); if (key_info) { - key_info->ref_count++; + refcount_inc(&key_info->ref_count); return key_info; } return mlxsw_afk_key_info_create(mlxsw_afk, elusage); @@ -365,7 +366,7 @@ EXPORT_SYMBOL(mlxsw_afk_key_info_get); void mlxsw_afk_key_info_put(struct mlxsw_afk_key_info *key_info) { - if (--key_info->ref_count) + if (!refcount_dec_and_test(&key_info->ref_count)) return; mlxsw_afk_key_info_destroy(key_info); } diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c index 7c59c8a13584..b01b000bc71c 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -55,7 +56,7 @@ struct mlxsw_sp_acl_ruleset { struct rhash_head ht_node; /* Member of acl HT */ struct mlxsw_sp_acl_ruleset_ht_key ht_key; struct rhashtable rule_ht; - unsigned int ref_count; + refcount_t ref_count; unsigned int min_prio; unsigned int max_prio; unsigned long priv[]; @@ -99,7 +100,7 @@ static bool mlxsw_sp_acl_ruleset_is_singular(const struct mlxsw_sp_acl_ruleset *ruleset) { /* We hold a reference on ruleset ourselves */ - return ruleset->ref_count == 2; + return refcount_read(&ruleset->ref_count) == 2; } int mlxsw_sp_acl_ruleset_bind(struct mlxsw_sp *mlxsw_sp, @@ -176,7 +177,7 @@ mlxsw_sp_acl_ruleset_create(struct mlxsw_sp *mlxsw_sp, ruleset = kzalloc(alloc_size, GFP_KERNEL); if (!ruleset) return ERR_PTR(-ENOMEM); - ruleset->ref_count = 1; + refcount_set(&ruleset->ref_count, 1); ruleset->ht_key.block = block; ruleset->ht_key.chain_index = chain_index; ruleset->ht_key.ops = ops; @@ -222,13 +223,13 @@ static void mlxsw_sp_acl_ruleset_destroy(struct mlxsw_sp *mlxsw_sp, static void mlxsw_sp_acl_ruleset_ref_inc(struct mlxsw_sp_acl_ruleset *ruleset) { - ruleset->ref_count++; + refcount_inc(&ruleset->ref_count); } static void mlxsw_sp_acl_ruleset_ref_dec(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_ruleset *ruleset) { - if (--ruleset->ref_count) + if (!refcount_dec_and_test(&ruleset->ref_count)) return; mlxsw_sp_acl_ruleset_destroy(mlxsw_sp, ruleset); } diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c index 50ea1eff02b2..f20052776b3f 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -155,7 +156,7 @@ struct mlxsw_sp_acl_tcam_vregion { struct mlxsw_sp_acl_tcam_rehash_ctx ctx; } rehash; struct mlxsw_sp *mlxsw_sp; - unsigned int ref_count; + refcount_t ref_count; }; struct mlxsw_sp_acl_tcam_vchunk; @@ -176,7 +177,7 @@ struct mlxsw_sp_acl_tcam_vchunk { unsigned int priority; /* Priority within the vregion and group */ struct mlxsw_sp_acl_tcam_vgroup *vgroup; struct mlxsw_sp_acl_tcam_vregion *vregion; - unsigned int ref_count; + refcount_t ref_count; }; struct mlxsw_sp_acl_tcam_entry { @@ -769,7 +770,7 @@ mlxsw_sp_acl_tcam_vregion_create(struct mlxsw_sp *mlxsw_sp, vregion->tcam = tcam; vregion->mlxsw_sp = mlxsw_sp; vregion->vgroup = vgroup; - vregion->ref_count = 1; + refcount_set(&vregion->ref_count, 1); vregion->key_info = mlxsw_afk_key_info_get(afk, elusage); if (IS_ERR(vregion->key_info)) { @@ -856,7 +857,7 @@ mlxsw_sp_acl_tcam_vregion_get(struct mlxsw_sp *mlxsw_sp, */ return ERR_PTR(-EOPNOTSUPP); } - vregion->ref_count++; + refcount_inc(&vregion->ref_count); return vregion; } @@ -871,7 +872,7 @@ static void mlxsw_sp_acl_tcam_vregion_put(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_tcam_vregion *vregion) { - if (--vregion->ref_count) + if (!refcount_dec_and_test(&vregion->ref_count)) return; mlxsw_sp_acl_tcam_vregion_destroy(mlxsw_sp, vregion); } @@ -924,7 +925,7 @@ mlxsw_sp_acl_tcam_vchunk_create(struct mlxsw_sp *mlxsw_sp, INIT_LIST_HEAD(&vchunk->ventry_list); vchunk->priority = priority; vchunk->vgroup = vgroup; - vchunk->ref_count = 1; + refcount_set(&vchunk->ref_count, 1); vregion = mlxsw_sp_acl_tcam_vregion_get(mlxsw_sp, vgroup, priority, elusage); @@ -1008,7 +1009,7 @@ mlxsw_sp_acl_tcam_vchunk_get(struct mlxsw_sp *mlxsw_sp, if (WARN_ON(!mlxsw_afk_key_info_subset(vchunk->vregion->key_info, elusage))) return ERR_PTR(-EINVAL); - vchunk->ref_count++; + refcount_inc(&vchunk->ref_count); return vchunk; } return mlxsw_sp_acl_tcam_vchunk_create(mlxsw_sp, vgroup, @@ -1019,7 +1020,7 @@ static void mlxsw_sp_acl_tcam_vchunk_put(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_tcam_vchunk *vchunk) { - if (--vchunk->ref_count) + if (!refcount_dec_and_test(&vchunk->ref_count)) return; mlxsw_sp_acl_tcam_vchunk_destroy(mlxsw_sp, vchunk); } diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c index 7164f9e6370f..87617df694ab 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c @@ -501,7 +501,7 @@ struct mlxsw_sp_rt6 { struct mlxsw_sp_lpm_tree { u8 id; /* tree ID */ - unsigned int ref_count; + refcount_t ref_count; enum mlxsw_sp_l3proto proto; unsigned long prefix_ref_count[MLXSW_SP_PREFIX_COUNT]; struct mlxsw_sp_prefix_usage prefix_usage; @@ -578,7 +578,7 @@ mlxsw_sp_lpm_tree_find_unused(struct mlxsw_sp *mlxsw_sp) for (i = 0; i < mlxsw_sp->router->lpm.tree_count; i++) { lpm_tree = &mlxsw_sp->router->lpm.trees[i]; - if (lpm_tree->ref_count == 0) + if (refcount_read(&lpm_tree->ref_count) == 0) return lpm_tree; } return NULL; @@ -654,7 +654,7 @@ mlxsw_sp_lpm_tree_create(struct mlxsw_sp *mlxsw_sp, sizeof(lpm_tree->prefix_usage)); memset(&lpm_tree->prefix_ref_count, 0, sizeof(lpm_tree->prefix_ref_count)); - lpm_tree->ref_count = 1; + refcount_set(&lpm_tree->ref_count, 1); return lpm_tree; err_left_struct_set: @@ -678,7 +678,7 @@ mlxsw_sp_lpm_tree_get(struct mlxsw_sp *mlxsw_sp, for (i = 0; i < mlxsw_sp->router->lpm.tree_count; i++) { lpm_tree = &mlxsw_sp->router->lpm.trees[i]; - if (lpm_tree->ref_count != 0 && + if (refcount_read(&lpm_tree->ref_count) && lpm_tree->proto == proto && mlxsw_sp_prefix_usage_eq(&lpm_tree->prefix_usage, prefix_usage)) { @@ -691,14 +691,15 @@ mlxsw_sp_lpm_tree_get(struct mlxsw_sp *mlxsw_sp, static void mlxsw_sp_lpm_tree_hold(struct mlxsw_sp_lpm_tree *lpm_tree) { - lpm_tree->ref_count++; + refcount_inc(&lpm_tree->ref_count); } static void mlxsw_sp_lpm_tree_put(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_lpm_tree *lpm_tree) { - if (--lpm_tree->ref_count == 0) - mlxsw_sp_lpm_tree_destroy(mlxsw_sp, lpm_tree); + if (!refcount_dec_and_test(&lpm_tree->ref_count)) + return; + mlxsw_sp_lpm_tree_destroy(mlxsw_sp, lpm_tree); } #define MLXSW_SP_LPM_TREE_MIN 1 /* tree 0 is reserved */ diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c index 6c749c148148..6397ff0dc951 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c @@ -61,7 +61,7 @@ struct mlxsw_sp_bridge_port { struct mlxsw_sp_bridge_device *bridge_device; struct list_head list; struct list_head vlans_list; - unsigned int ref_count; + refcount_t ref_count; u8 stp_state; unsigned long flags; bool mrouter; @@ -495,7 +495,7 @@ mlxsw_sp_bridge_port_create(struct mlxsw_sp_bridge_device *bridge_device, BR_MCAST_FLOOD; INIT_LIST_HEAD(&bridge_port->vlans_list); list_add(&bridge_port->list, &bridge_device->ports_list); - bridge_port->ref_count = 1; + refcount_set(&bridge_port->ref_count, 1); err = switchdev_bridge_port_offload(brport_dev, mlxsw_sp_port->dev, NULL, NULL, NULL, false, extack); @@ -531,7 +531,7 @@ mlxsw_sp_bridge_port_get(struct mlxsw_sp_bridge *bridge, bridge_port = mlxsw_sp_bridge_port_find(bridge, brport_dev); if (bridge_port) { - bridge_port->ref_count++; + refcount_inc(&bridge_port->ref_count); return bridge_port; } @@ -558,7 +558,7 @@ static void mlxsw_sp_bridge_port_put(struct mlxsw_sp_bridge *bridge, { struct mlxsw_sp_bridge_device *bridge_device; - if (--bridge_port->ref_count != 0) + if (!refcount_dec_and_test(&bridge_port->ref_count)) return; bridge_device = bridge_port->bridge_device; mlxsw_sp_bridge_port_destroy(bridge_port);