@@ -3049,6 +3049,8 @@ struct mlxsw_sp_nexthop_key {
3049
3049
struct fib_nh * fib_nh ;
3050
3050
};
3051
3051
3052
+ struct mlxsw_sp_nexthop_counter ;
3053
+
3052
3054
struct mlxsw_sp_nexthop {
3053
3055
struct list_head neigh_list_node ; /* member of neigh entry list */
3054
3056
struct list_head crif_list_node ;
@@ -3080,8 +3082,7 @@ struct mlxsw_sp_nexthop {
3080
3082
struct mlxsw_sp_neigh_entry * neigh_entry ;
3081
3083
struct mlxsw_sp_ipip_entry * ipip_entry ;
3082
3084
};
3083
- unsigned int counter_index ;
3084
- bool counter_valid ;
3085
+ struct mlxsw_sp_nexthop_counter * counter ;
3085
3086
};
3086
3087
3087
3088
static struct net_device *
@@ -3151,44 +3152,77 @@ struct mlxsw_sp_nexthop_group {
3151
3152
bool can_destroy ;
3152
3153
};
3153
3154
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
+
3154
3188
int mlxsw_sp_nexthop_counter_enable (struct mlxsw_sp * mlxsw_sp ,
3155
3189
struct mlxsw_sp_nexthop * nh )
3156
3190
{
3191
+ struct mlxsw_sp_nexthop_counter * nhct ;
3157
3192
struct devlink * devlink ;
3158
- int err ;
3159
3193
3160
- if (nh -> counter_valid )
3194
+ if (nh -> counter )
3161
3195
return 0 ;
3162
3196
3163
3197
devlink = priv_to_devlink (mlxsw_sp -> core );
3164
3198
if (!devlink_dpipe_table_counter_enabled (devlink ,
3165
3199
MLXSW_SP_DPIPE_TABLE_NAME_ADJ ))
3166
3200
return 0 ;
3167
3201
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 ) ;
3171
3205
3172
- nh -> counter_valid = true ;
3206
+ nh -> counter = nhct ;
3173
3207
return 0 ;
3174
3208
}
3175
3209
3176
3210
void mlxsw_sp_nexthop_counter_disable (struct mlxsw_sp * mlxsw_sp ,
3177
3211
struct mlxsw_sp_nexthop * nh )
3178
3212
{
3179
- if (!nh -> counter_valid )
3213
+ if (!nh -> counter )
3180
3214
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 ;
3183
3217
}
3184
3218
3185
3219
int mlxsw_sp_nexthop_counter_get (struct mlxsw_sp * mlxsw_sp ,
3186
3220
struct mlxsw_sp_nexthop * nh , u64 * p_counter )
3187
3221
{
3188
- if (!nh -> counter_valid )
3222
+ if (!nh -> counter )
3189
3223
return - EINVAL ;
3190
3224
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 ,
3192
3226
false, p_counter , NULL );
3193
3227
}
3194
3228
@@ -3662,8 +3696,9 @@ static int __mlxsw_sp_nexthop_eth_update(struct mlxsw_sp *mlxsw_sp,
3662
3696
WARN_ON_ONCE (1 );
3663
3697
return - EINVAL ;
3664
3698
}
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);
3667
3702
else
3668
3703
mlxsw_reg_ratr_counter_pack (ratr_pl , 0 , false);
3669
3704
0 commit comments