Skip to content

Commit 171c762

Browse files
mark-blochSaeed Mahameed
authored andcommitted
net/mlx5: Use flow counter IDs and not the wrapping cache object
Currently, when a flow rule is created using the FS core layer, the caller has to pass the entire flow counter object and not just the counter HW handle (ID). This requires both the FS core and the caller to have knowledge about the inner implementation of the FS layer flow counters cache and limits the possible users. Move to use the counter ID across the place when dealing with flows. Doing this decoupling, now can we privatize the inner implementation of the flow counters. Signed-off-by: Mark Bloch <[email protected]> Reviewed-by: Or Gerlitz <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent b8aee82 commit 171c762

File tree

9 files changed

+23
-19
lines changed

9 files changed

+23
-19
lines changed

drivers/infiniband/hw/mlx5/main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3320,15 +3320,18 @@ static struct mlx5_ib_flow_handler *_create_flow_rule(struct mlx5_ib_dev *dev,
33203320
}
33213321

33223322
if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_COUNT) {
3323+
struct mlx5_ib_mcounters *mcounters;
3324+
33233325
err = flow_counters_set_data(flow_act.counters, ucmd);
33243326
if (err)
33253327
goto free;
33263328

3329+
mcounters = to_mcounters(flow_act.counters);
33273330
handler->ibcounters = flow_act.counters;
33283331
dest_arr[dest_num].type =
33293332
MLX5_FLOW_DESTINATION_TYPE_COUNTER;
3330-
dest_arr[dest_num].counter =
3331-
to_mcounters(flow_act.counters)->hw_cntrs_hndl;
3333+
dest_arr[dest_num].counter_id =
3334+
mlx5_fc_id(mcounters->hw_cntrs_hndl);
33323335
dest_num++;
33333336
}
33343337

drivers/net/ethernet/mellanox/mlx5/core/diag/fs_tracepoint.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,10 @@ TRACE_EVENT(mlx5_fs_add_rule,
252252
memcpy(__entry->destination,
253253
&rule->dest_attr,
254254
sizeof(__entry->destination));
255-
if (rule->dest_attr.type & MLX5_FLOW_DESTINATION_TYPE_COUNTER &&
256-
rule->dest_attr.counter)
255+
if (rule->dest_attr.type &
256+
MLX5_FLOW_DESTINATION_TYPE_COUNTER)
257257
__entry->counter_id =
258-
rule->dest_attr.counter->id;
258+
rule->dest_attr.counter_id;
259259
),
260260
TP_printk("rule=%p fte=%p index=%u sw_action=<%s> [dst] %s\n",
261261
__entry->rule, __entry->fte, __entry->index,

drivers/net/ethernet/mellanox/mlx5/core/en_tc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ mlx5e_tc_add_nic_flow(struct mlx5e_priv *priv,
720720
goto err_fc_create;
721721
}
722722
dest[dest_ix].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
723-
dest[dest_ix].counter = counter;
723+
dest[dest_ix].counter_id = mlx5_fc_id(counter);
724724
dest_ix++;
725725
attr->counter = counter;
726726
}

drivers/net/ethernet/mellanox/mlx5/core/eswitch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ static int esw_vport_ingress_config(struct mlx5_eswitch *esw,
11981198
if (counter) {
11991199
flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_COUNT;
12001200
drop_ctr_dst.type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
1201-
drop_ctr_dst.counter = counter;
1201+
drop_ctr_dst.counter_id = mlx5_fc_id(counter);
12021202
dst = &drop_ctr_dst;
12031203
dest_num++;
12041204
}
@@ -1285,7 +1285,7 @@ static int esw_vport_egress_config(struct mlx5_eswitch *esw,
12851285
if (counter) {
12861286
flow_act.action |= MLX5_FLOW_CONTEXT_ACTION_COUNT;
12871287
drop_ctr_dst.type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
1288-
drop_ctr_dst.counter = counter;
1288+
drop_ctr_dst.counter_id = mlx5_fc_id(counter);
12891289
dst = &drop_ctr_dst;
12901290
dest_num++;
12911291
}

drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch *esw,
9191
}
9292
if (flow_act.action & MLX5_FLOW_CONTEXT_ACTION_COUNT) {
9393
dest[i].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER;
94-
dest[i].counter = attr->counter;
94+
dest[i].counter_id = mlx5_fc_id(attr->counter);
9595
i++;
9696
}
9797

drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev,
419419
continue;
420420

421421
MLX5_SET(flow_counter_list, in_dests, flow_counter_id,
422-
dst->dest_attr.counter->id);
422+
dst->dest_attr.counter_id);
423423
in_dests += MLX5_ST_SZ_BYTES(dest_format_struct);
424424
list_size++;
425425
}

drivers/net/ethernet/mellanox/mlx5/core/fs_core.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,14 +1474,8 @@ static struct mlx5_flow_handle *add_rule_fg(struct mlx5_flow_group *fg,
14741474
return handle;
14751475
}
14761476

1477-
static bool counter_is_valid(struct mlx5_fc *counter, u32 action)
1477+
static bool counter_is_valid(u32 action)
14781478
{
1479-
if (!(action & MLX5_FLOW_CONTEXT_ACTION_COUNT))
1480-
return !counter;
1481-
1482-
if (!counter)
1483-
return false;
1484-
14851479
return (action & (MLX5_FLOW_CONTEXT_ACTION_DROP |
14861480
MLX5_FLOW_CONTEXT_ACTION_FWD_DEST));
14871481
}
@@ -1491,7 +1485,7 @@ static bool dest_is_valid(struct mlx5_flow_destination *dest,
14911485
struct mlx5_flow_table *ft)
14921486
{
14931487
if (dest && (dest->type == MLX5_FLOW_DESTINATION_TYPE_COUNTER))
1494-
return counter_is_valid(dest->counter, action);
1488+
return counter_is_valid(action);
14951489

14961490
if (!(action & MLX5_FLOW_CONTEXT_ACTION_FWD_DEST))
14971491
return true;

drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ struct mlx5_fc *mlx5_fc_create(struct mlx5_core_dev *dev, bool aging)
258258
}
259259
EXPORT_SYMBOL(mlx5_fc_create);
260260

261+
u32 mlx5_fc_id(struct mlx5_fc *counter)
262+
{
263+
return counter->id;
264+
}
265+
EXPORT_SYMBOL(mlx5_fc_id);
266+
261267
void mlx5_fc_destroy(struct mlx5_core_dev *dev, struct mlx5_fc *counter)
262268
{
263269
struct mlx5_fc_stats *fc_stats = &dev->priv.fc_stats;

include/linux/mlx5/fs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ struct mlx5_flow_destination {
9292
u32 tir_num;
9393
u32 ft_num;
9494
struct mlx5_flow_table *ft;
95-
struct mlx5_fc *counter;
95+
u32 counter_id;
9696
struct {
9797
u16 num;
9898
u16 vhca_id;
@@ -192,6 +192,7 @@ void mlx5_fc_query_cached(struct mlx5_fc *counter,
192192
u64 *bytes, u64 *packets, u64 *lastuse);
193193
int mlx5_fc_query(struct mlx5_core_dev *dev, struct mlx5_fc *counter,
194194
u64 *packets, u64 *bytes);
195+
u32 mlx5_fc_id(struct mlx5_fc *counter);
195196

196197
int mlx5_fs_add_rx_underlay_qpn(struct mlx5_core_dev *dev, u32 underlay_qpn);
197198
int mlx5_fs_remove_rx_underlay_qpn(struct mlx5_core_dev *dev, u32 underlay_qpn);

0 commit comments

Comments
 (0)