diff mbox series

[net-next,4/6] mlxsw: spectrum: Search for free LAD ID once

Message ID 903f25dbfc84fe1f384d92ea7f8902a2051bb7bc.1706293430.git.petrm@nvidia.com (mailing list archive)
State Accepted
Commit 8d8d33d4e38b5c60cdb3dcd6f190fcf91e306dd0
Delegated to: Netdev Maintainers
Headers show
Series mlxsw: Refactor reference counting code | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1064 this patch: 1064
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 0 of 0 maintainers
netdev/build_clang success Errors and warnings before: 1081 this patch: 1081
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1081 this patch: 1081
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 40 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-01-29--21-00 (tests: 623)

Commit Message

Petr Machata Jan. 26, 2024, 6:58 p.m. UTC
From: Amit Cohen <amcohen@nvidia.com>

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 <amcohen@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Petr Machata <petrm@nvidia.com>
---
 drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

Comments

Simon Horman Jan. 29, 2024, 7:53 p.m. UTC | #1
On Fri, Jan 26, 2024 at 07:58:29PM +0100, Petr Machata wrote:
> From: Amit Cohen <amcohen@nvidia.com>
> 
> 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 <amcohen@nvidia.com>
> Reviewed-by: Ido Schimmel <idosch@nvidia.com>
> Signed-off-by: Ido Schimmel <idosch@nvidia.com>
> Signed-off-by: Petr Machata <petrm@nvidia.com>

Reviewed-by: Simon Horman <horms@kernel.org>
diff mbox series

Patch

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];