mlxsw: spectrum: Refactor LAG create and destroy code
authorAmit Cohen <amcohen@nvidia.com>
Fri, 26 Jan 2024 18:58:30 +0000 (19:58 +0100)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 30 Jan 2024 14:47:36 +0000 (15:47 +0100)
commitbe2f16a994f09b7f95db57f106520dd5e2585050
tree741b40c1c728bd9f2c53090d4607c3efb733adf9
parent8d8d33d4e38b5c60cdb3dcd6f190fcf91e306dd0
mlxsw: spectrum: Refactor LAG create and destroy code

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 <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>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/mellanox/mlxsw/spectrum.c