Skip to content

Commit 10bf92f

Browse files
pmachatakuba-moo
authored andcommitted
mlxsw: spectrum_router: Add helpers for nexthop counters
The next patch will add the ability to share nexthop counters among mlxsw nexthops backed by the same core nexthop. To have a place to store reference count, the counter should be kept in a dedicated structure. In this patch, introduce the structure together with the related helpers, sans the refcount, which comes in the next patch. Signed-off-by: Petr Machata <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Link: https://lore.kernel.org/r/61f23fa4f8c5d7879f68dacd793d8ab7425f33c0.1709901020.git.petrm@nvidia.com Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 79fa521 commit 10bf92f

File tree

1 file changed

+50
-15
lines changed

1 file changed

+50
-15
lines changed

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

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3049,6 +3049,8 @@ struct mlxsw_sp_nexthop_key {
30493049
struct fib_nh *fib_nh;
30503050
};
30513051

3052+
struct mlxsw_sp_nexthop_counter;
3053+
30523054
struct mlxsw_sp_nexthop {
30533055
struct list_head neigh_list_node; /* member of neigh entry list */
30543056
struct list_head crif_list_node;
@@ -3080,8 +3082,7 @@ struct mlxsw_sp_nexthop {
30803082
struct mlxsw_sp_neigh_entry *neigh_entry;
30813083
struct mlxsw_sp_ipip_entry *ipip_entry;
30823084
};
3083-
unsigned int counter_index;
3084-
bool counter_valid;
3085+
struct mlxsw_sp_nexthop_counter *counter;
30853086
};
30863087

30873088
static struct net_device *
@@ -3151,44 +3152,77 @@ struct mlxsw_sp_nexthop_group {
31513152
bool can_destroy;
31523153
};
31533154

3155+
struct mlxsw_sp_nexthop_counter {
3156+
unsigned int counter_index;
3157+
};
3158+
3159+
static struct mlxsw_sp_nexthop_counter *
3160+
mlxsw_sp_nexthop_counter_alloc(struct mlxsw_sp *mlxsw_sp)
3161+
{
3162+
struct mlxsw_sp_nexthop_counter *nhct;
3163+
int err;
3164+
3165+
nhct = kzalloc(sizeof(*nhct), GFP_KERNEL);
3166+
if (!nhct)
3167+
return ERR_PTR(-ENOMEM);
3168+
3169+
err = mlxsw_sp_flow_counter_alloc(mlxsw_sp, &nhct->counter_index);
3170+
if (err)
3171+
goto err_counter_alloc;
3172+
3173+
return nhct;
3174+
3175+
err_counter_alloc:
3176+
kfree(nhct);
3177+
return ERR_PTR(err);
3178+
}
3179+
3180+
static void
3181+
mlxsw_sp_nexthop_counter_free(struct mlxsw_sp *mlxsw_sp,
3182+
struct mlxsw_sp_nexthop_counter *nhct)
3183+
{
3184+
mlxsw_sp_flow_counter_free(mlxsw_sp, nhct->counter_index);
3185+
kfree(nhct);
3186+
}
3187+
31543188
int mlxsw_sp_nexthop_counter_enable(struct mlxsw_sp *mlxsw_sp,
31553189
struct mlxsw_sp_nexthop *nh)
31563190
{
3191+
struct mlxsw_sp_nexthop_counter *nhct;
31573192
struct devlink *devlink;
3158-
int err;
31593193

3160-
if (nh->counter_valid)
3194+
if (nh->counter)
31613195
return 0;
31623196

31633197
devlink = priv_to_devlink(mlxsw_sp->core);
31643198
if (!devlink_dpipe_table_counter_enabled(devlink,
31653199
MLXSW_SP_DPIPE_TABLE_NAME_ADJ))
31663200
return 0;
31673201

3168-
err = mlxsw_sp_flow_counter_alloc(mlxsw_sp, &nh->counter_index);
3169-
if (err)
3170-
return err;
3202+
nhct = mlxsw_sp_nexthop_counter_alloc(mlxsw_sp);
3203+
if (IS_ERR(nhct))
3204+
return PTR_ERR(nhct);
31713205

3172-
nh->counter_valid = true;
3206+
nh->counter = nhct;
31733207
return 0;
31743208
}
31753209

31763210
void mlxsw_sp_nexthop_counter_disable(struct mlxsw_sp *mlxsw_sp,
31773211
struct mlxsw_sp_nexthop *nh)
31783212
{
3179-
if (!nh->counter_valid)
3213+
if (!nh->counter)
31803214
return;
3181-
mlxsw_sp_flow_counter_free(mlxsw_sp, nh->counter_index);
3182-
nh->counter_valid = false;
3215+
mlxsw_sp_nexthop_counter_free(mlxsw_sp, nh->counter);
3216+
nh->counter = NULL;
31833217
}
31843218

31853219
int mlxsw_sp_nexthop_counter_get(struct mlxsw_sp *mlxsw_sp,
31863220
struct mlxsw_sp_nexthop *nh, u64 *p_counter)
31873221
{
3188-
if (!nh->counter_valid)
3222+
if (!nh->counter)
31893223
return -EINVAL;
31903224

3191-
return mlxsw_sp_flow_counter_get(mlxsw_sp, nh->counter_index,
3225+
return mlxsw_sp_flow_counter_get(mlxsw_sp, nh->counter->counter_index,
31923226
false, p_counter, NULL);
31933227
}
31943228

@@ -3662,8 +3696,9 @@ static int __mlxsw_sp_nexthop_eth_update(struct mlxsw_sp *mlxsw_sp,
36623696
WARN_ON_ONCE(1);
36633697
return -EINVAL;
36643698
}
3665-
if (nh->counter_valid)
3666-
mlxsw_reg_ratr_counter_pack(ratr_pl, nh->counter_index, true);
3699+
if (nh->counter)
3700+
mlxsw_reg_ratr_counter_pack(ratr_pl, nh->counter->counter_index,
3701+
true);
36673702
else
36683703
mlxsw_reg_ratr_counter_pack(ratr_pl, 0, false);
36693704

0 commit comments

Comments
 (0)