Skip to content

Commit 16f1c5b

Browse files
Raed SalemSaeed Mahameed
authored andcommitted
net/mlx5: Check device capability for maximum flow counters
Added check for the maximal number of flow counters attached to rule (FTE). Fixes: bd5251d ('net/mlx5_core: Introduce flow steering destination of type counter') Signed-off-by: Raed Salem <[email protected]> Reviewed-by: Maor Gottlieb <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 99d3cd2 commit 16f1c5b

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,9 @@ static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev,
293293
}
294294

295295
if (fte->action & MLX5_FLOW_CONTEXT_ACTION_COUNT) {
296+
int max_list_size = BIT(MLX5_CAP_FLOWTABLE_TYPE(dev,
297+
log_max_flow_counter,
298+
ft->type));
296299
int list_size = 0;
297300

298301
list_for_each_entry(dst, &fte->node.children, node.list) {
@@ -305,12 +308,17 @@ static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev,
305308
in_dests += MLX5_ST_SZ_BYTES(dest_format_struct);
306309
list_size++;
307310
}
311+
if (list_size > max_list_size) {
312+
err = -EINVAL;
313+
goto err_out;
314+
}
308315

309316
MLX5_SET(flow_context, in_flow_context, flow_counter_list_size,
310317
list_size);
311318
}
312319

313320
err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
321+
err_out:
314322
kvfree(in);
315323
return err;
316324
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ enum fs_flow_table_type {
5252
FS_FT_FDB = 0X4,
5353
FS_FT_SNIFFER_RX = 0X5,
5454
FS_FT_SNIFFER_TX = 0X6,
55+
FS_FT_MAX_TYPE = FS_FT_SNIFFER_TX,
5556
};
5657

5758
enum fs_flow_table_op_mod {
@@ -260,4 +261,14 @@ void mlx5_cleanup_fs(struct mlx5_core_dev *dev);
260261
#define fs_for_each_dst(pos, fte) \
261262
fs_list_for_each_entry(pos, &(fte)->node.children)
262263

264+
#define MLX5_CAP_FLOWTABLE_TYPE(mdev, cap, type) ( \
265+
(type == FS_FT_NIC_RX) ? MLX5_CAP_FLOWTABLE_NIC_RX(mdev, cap) : \
266+
(type == FS_FT_ESW_EGRESS_ACL) ? MLX5_CAP_ESW_EGRESS_ACL(mdev, cap) : \
267+
(type == FS_FT_ESW_INGRESS_ACL) ? MLX5_CAP_ESW_INGRESS_ACL(mdev, cap) : \
268+
(type == FS_FT_FDB) ? MLX5_CAP_ESW_FLOWTABLE_FDB(mdev, cap) : \
269+
(type == FS_FT_SNIFFER_RX) ? MLX5_CAP_FLOWTABLE_SNIFFER_RX(mdev, cap) : \
270+
(type == FS_FT_SNIFFER_TX) ? MLX5_CAP_FLOWTABLE_SNIFFER_TX(mdev, cap) : \
271+
(BUILD_BUG_ON_ZERO(FS_FT_SNIFFER_TX != FS_FT_MAX_TYPE))\
272+
)
273+
263274
#endif

include/linux/mlx5/mlx5_ifc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,8 @@ struct mlx5_ifc_flow_table_prop_layout_bits {
327327
u8 reserved_at_80[0x18];
328328
u8 log_max_destination[0x8];
329329

330-
u8 reserved_at_a0[0x18];
330+
u8 log_max_flow_counter[0x8];
331+
u8 reserved_at_a8[0x10];
331332
u8 log_max_flow[0x8];
332333

333334
u8 reserved_at_c0[0x40];

0 commit comments

Comments
 (0)