Commit c6ca2884 authored by Amit Cohen's avatar Amit Cohen Committed by Paolo Abeni

mlxsw: spectrum: Query max_lag once

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: default avatarAmit Cohen <amcohen@nvidia.com>
Reviewed-by: default avatarIdo Schimmel <idosch@nvidia.com>
Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
Signed-off-by: default avatarPetr Machata <petrm@nvidia.com>
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent 5a448905
...@@ -2695,23 +2695,18 @@ static void mlxsw_sp_traps_fini(struct mlxsw_sp *mlxsw_sp) ...@@ -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) static int mlxsw_sp_lag_pgt_init(struct mlxsw_sp *mlxsw_sp)
{ {
char sgcr_pl[MLXSW_REG_SGCR_LEN]; char sgcr_pl[MLXSW_REG_SGCR_LEN];
u16 max_lag;
int err; int err;
if (mlxsw_core_lag_mode(mlxsw_sp->core) != if (mlxsw_core_lag_mode(mlxsw_sp->core) !=
MLXSW_CMD_MBOX_CONFIG_PROFILE_LAG_MODE_SW) MLXSW_CMD_MBOX_CONFIG_PROFILE_LAG_MODE_SW)
return 0; 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 /* 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 * entries. The LAG table address needs to be 8-aligned, but that ought
* to be the case, since the LAG table is allocated first. * 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, err = mlxsw_sp_pgt_mid_alloc_range(mlxsw_sp, &mlxsw_sp->lag_pgt_base,
max_lag * 8); mlxsw_sp->max_lag * 8);
if (err) if (err)
return err; return err;
if (WARN_ON_ONCE(mlxsw_sp->lag_pgt_base % 8)) { 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) ...@@ -2728,25 +2723,18 @@ static int mlxsw_sp_lag_pgt_init(struct mlxsw_sp *mlxsw_sp)
err_mid_alloc_range: err_mid_alloc_range:
mlxsw_sp_pgt_mid_free_range(mlxsw_sp, mlxsw_sp->lag_pgt_base, mlxsw_sp_pgt_mid_free_range(mlxsw_sp, mlxsw_sp->lag_pgt_base,
max_lag * 8); mlxsw_sp->max_lag * 8);
return err; return err;
} }
static void mlxsw_sp_lag_pgt_fini(struct mlxsw_sp *mlxsw_sp) 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) != if (mlxsw_core_lag_mode(mlxsw_sp->core) !=
MLXSW_CMD_MBOX_CONFIG_PROFILE_LAG_MODE_SW) MLXSW_CMD_MBOX_CONFIG_PROFILE_LAG_MODE_SW)
return; 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, 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 #define MLXSW_SP_LAG_SEED_INIT 0xcafecafe
...@@ -2759,7 +2747,6 @@ struct mlxsw_sp_lag { ...@@ -2759,7 +2747,6 @@ struct mlxsw_sp_lag {
static int mlxsw_sp_lag_init(struct mlxsw_sp *mlxsw_sp) static int mlxsw_sp_lag_init(struct mlxsw_sp *mlxsw_sp)
{ {
char slcr_pl[MLXSW_REG_SLCR_LEN]; char slcr_pl[MLXSW_REG_SLCR_LEN];
u16 max_lag;
u32 seed; u32 seed;
int err; int err;
...@@ -2778,7 +2765,7 @@ static int mlxsw_sp_lag_init(struct mlxsw_sp *mlxsw_sp) ...@@ -2778,7 +2765,7 @@ static int mlxsw_sp_lag_init(struct mlxsw_sp *mlxsw_sp)
if (err) if (err)
return 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) if (err)
return err; return err;
...@@ -2789,7 +2776,7 @@ static int mlxsw_sp_lag_init(struct mlxsw_sp *mlxsw_sp) ...@@ -2789,7 +2776,7 @@ static int mlxsw_sp_lag_init(struct mlxsw_sp *mlxsw_sp)
if (err) if (err)
return 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); GFP_KERNEL);
if (!mlxsw_sp->lags) { if (!mlxsw_sp->lags) {
err = -ENOMEM; err = -ENOMEM;
...@@ -4340,14 +4327,9 @@ static int mlxsw_sp_lag_index_get(struct mlxsw_sp *mlxsw_sp, ...@@ -4340,14 +4327,9 @@ static int mlxsw_sp_lag_index_get(struct mlxsw_sp *mlxsw_sp,
{ {
struct mlxsw_sp_lag *lag; struct mlxsw_sp_lag *lag;
int free_lag_id = -1; int free_lag_id = -1;
u16 max_lag; int i;
int err, 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]; lag = &mlxsw_sp->lags[i];
if (lag->ref_count) { if (lag->ref_count) {
if (lag->dev == lag_dev) { if (lag->dev == lag_dev) {
......
...@@ -161,6 +161,7 @@ struct mlxsw_sp { ...@@ -161,6 +161,7 @@ struct mlxsw_sp {
unsigned char base_mac[ETH_ALEN]; unsigned char base_mac[ETH_ALEN];
const unsigned char *mac_mask; const unsigned char *mac_mask;
struct mlxsw_sp_lag *lags; struct mlxsw_sp_lag *lags;
u16 max_lag;
struct mlxsw_sp_port_mapping *port_mapping; struct mlxsw_sp_port_mapping *port_mapping;
struct mlxsw_sp_port_mapping_events port_mapping_events; struct mlxsw_sp_port_mapping_events port_mapping_events;
struct rhashtable sample_trigger_ht; struct rhashtable sample_trigger_ht;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment