Skip to content

Commit 8acb480

Browse files
pmachatakuba-moo
authored andcommitted
mlxsw: spectrum_router: Have mlxsw_sp_nexthop_counter_enable() return int
In order to be able to diagnose failures in counter allocation, have the function mlxsw_sp_nexthop_counter_enable() return an error code. Signed-off-by: Petr Machata <petrm@nvidia.com> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Link: https://lore.kernel.org/r/e0bb5c0cc6234ade2ade1e92abac991359c3f446.1709901020.git.petrm@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 64f962c commit 8acb480

3 files changed

Lines changed: 36 additions & 12 deletions

File tree

drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,9 +1181,11 @@ static int mlxsw_sp_dpipe_table_adj_counters_update(void *priv, bool enable)
11811181
char ratr_pl[MLXSW_REG_RATR_LEN];
11821182
struct mlxsw_sp *mlxsw_sp = priv;
11831183
struct mlxsw_sp_nexthop *nh;
1184+
unsigned int n_done = 0;
11841185
u32 adj_hash_index = 0;
11851186
u32 adj_index = 0;
11861187
u32 adj_size = 0;
1188+
int err;
11871189

11881190
mlxsw_sp_nexthop_for_each(nh, mlxsw_sp->router) {
11891191
if (!mlxsw_sp_nexthop_is_forward(nh) ||
@@ -1192,15 +1194,27 @@ static int mlxsw_sp_dpipe_table_adj_counters_update(void *priv, bool enable)
11921194

11931195
mlxsw_sp_nexthop_indexes(nh, &adj_index, &adj_size,
11941196
&adj_hash_index);
1195-
if (enable)
1196-
mlxsw_sp_nexthop_counter_enable(mlxsw_sp, nh);
1197-
else
1197+
if (enable) {
1198+
err = mlxsw_sp_nexthop_counter_enable(mlxsw_sp, nh);
1199+
if (err)
1200+
goto err_counter_enable;
1201+
} else {
11981202
mlxsw_sp_nexthop_counter_disable(mlxsw_sp, nh);
1203+
}
11991204
mlxsw_sp_nexthop_eth_update(mlxsw_sp,
12001205
adj_index + adj_hash_index, nh,
12011206
true, ratr_pl);
1207+
n_done++;
12021208
}
12031209
return 0;
1210+
1211+
err_counter_enable:
1212+
mlxsw_sp_nexthop_for_each(nh, mlxsw_sp->router) {
1213+
if (!n_done--)
1214+
break;
1215+
mlxsw_sp_nexthop_counter_disable(mlxsw_sp, nh);
1216+
}
1217+
return err;
12041218
}
12051219

12061220
static u64

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3151,20 +3151,23 @@ struct mlxsw_sp_nexthop_group {
31513151
bool can_destroy;
31523152
};
31533153

3154-
void mlxsw_sp_nexthop_counter_enable(struct mlxsw_sp *mlxsw_sp,
3155-
struct mlxsw_sp_nexthop *nh)
3154+
int mlxsw_sp_nexthop_counter_enable(struct mlxsw_sp *mlxsw_sp,
3155+
struct mlxsw_sp_nexthop *nh)
31563156
{
31573157
struct devlink *devlink;
3158+
int err;
31583159

31593160
devlink = priv_to_devlink(mlxsw_sp->core);
31603161
if (!devlink_dpipe_table_counter_enabled(devlink,
31613162
MLXSW_SP_DPIPE_TABLE_NAME_ADJ))
3162-
return;
3163+
return 0;
31633164

3164-
if (mlxsw_sp_flow_counter_alloc(mlxsw_sp, &nh->counter_index))
3165-
return;
3165+
err = mlxsw_sp_flow_counter_alloc(mlxsw_sp, &nh->counter_index);
3166+
if (err)
3167+
return err;
31663168

31673169
nh->counter_valid = true;
3170+
return 0;
31683171
}
31693172

31703173
void mlxsw_sp_nexthop_counter_disable(struct mlxsw_sp *mlxsw_sp,
@@ -4507,7 +4510,10 @@ static int mlxsw_sp_nexthop4_init(struct mlxsw_sp *mlxsw_sp,
45074510
if (err)
45084511
return err;
45094512

4510-
mlxsw_sp_nexthop_counter_enable(mlxsw_sp, nh);
4513+
err = mlxsw_sp_nexthop_counter_enable(mlxsw_sp, nh);
4514+
if (err)
4515+
goto err_counter_enable;
4516+
45114517
list_add_tail(&nh->router_list_node, &mlxsw_sp->router->nexthop_list);
45124518

45134519
if (!dev)
@@ -4532,6 +4538,7 @@ static int mlxsw_sp_nexthop4_init(struct mlxsw_sp *mlxsw_sp,
45324538
err_nexthop_neigh_init:
45334539
list_del(&nh->router_list_node);
45344540
mlxsw_sp_nexthop_counter_disable(mlxsw_sp, nh);
4541+
err_counter_enable:
45354542
mlxsw_sp_nexthop_remove(mlxsw_sp, nh);
45364543
return err;
45374544
}
@@ -6734,7 +6741,10 @@ static int mlxsw_sp_nexthop6_init(struct mlxsw_sp *mlxsw_sp,
67346741
#if IS_ENABLED(CONFIG_IPV6)
67356742
nh->neigh_tbl = &nd_tbl;
67366743
#endif
6737-
mlxsw_sp_nexthop_counter_enable(mlxsw_sp, nh);
6744+
6745+
err = mlxsw_sp_nexthop_counter_enable(mlxsw_sp, nh);
6746+
if (err)
6747+
return err;
67386748

67396749
list_add_tail(&nh->router_list_node, &mlxsw_sp->router->nexthop_list);
67406750

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ int mlxsw_sp_nexthop_counter_get(struct mlxsw_sp *mlxsw_sp,
156156
int mlxsw_sp_nexthop_eth_update(struct mlxsw_sp *mlxsw_sp, u32 adj_index,
157157
struct mlxsw_sp_nexthop *nh, bool force,
158158
char *ratr_pl);
159-
void mlxsw_sp_nexthop_counter_enable(struct mlxsw_sp *mlxsw_sp,
160-
struct mlxsw_sp_nexthop *nh);
159+
int mlxsw_sp_nexthop_counter_enable(struct mlxsw_sp *mlxsw_sp,
160+
struct mlxsw_sp_nexthop *nh);
161161
void mlxsw_sp_nexthop_counter_disable(struct mlxsw_sp *mlxsw_sp,
162162
struct mlxsw_sp_nexthop *nh);
163163

0 commit comments

Comments
 (0)