Skip to content

Commit a8ffcc7

Browse files
Rabie LoulouSaeed Mahameed
authored andcommitted
net/mlx5: Increase the maximum flow counters supported
Read new NIC capability field which represnts 16 MSBs of the max flow counters number supported (max_flow_counter_31_16). Backward compatibility with older firmware is preserved, the modified driver reads max_flow_counter_31_16 as 0 from the older firmware and uses up to 64K counters. Changed flow counter id from 16 bits to 32 bits. Backward compatibility with older firmware is preserved as we kept the 16 LSBs of the counter id in place and added 16 MSBs from reserved field. Changed the background bulk reading of flow counters to work in chunks of at most 32K counters, to make sure we don't attempt to allocate very large buffers. Signed-off-by: Rabie Loulou <rabiel@mellanox.com> Reviewed-by: Or Gerlitz <ogerlitz@mellanox.com> Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
1 parent 61690e0 commit a8ffcc7

File tree

6 files changed

+32
-27
lines changed

6 files changed

+32
-27
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ static int esw_create_offloads_fast_fdb_table(struct mlx5_eswitch *esw)
433433
struct mlx5_flow_table *fdb = NULL;
434434
int esw_size, err = 0;
435435
u32 flags = 0;
436+
u32 max_flow_counter = (MLX5_CAP_GEN(dev, max_flow_counter_31_16) << 16) |
437+
MLX5_CAP_GEN(dev, max_flow_counter_15_0);
436438

437439
root_ns = mlx5_get_flow_namespace(dev, MLX5_FLOW_NAMESPACE_FDB);
438440
if (!root_ns) {
@@ -443,9 +445,9 @@ static int esw_create_offloads_fast_fdb_table(struct mlx5_eswitch *esw)
443445

444446
esw_debug(dev, "Create offloads FDB table, min (max esw size(2^%d), max counters(%d)*groups(%d))\n",
445447
MLX5_CAP_ESW_FLOWTABLE_FDB(dev, log_max_ft_size),
446-
MLX5_CAP_GEN(dev, max_flow_counter), ESW_OFFLOADS_NUM_GROUPS);
448+
max_flow_counter, ESW_OFFLOADS_NUM_GROUPS);
447449

448-
esw_size = min_t(int, MLX5_CAP_GEN(dev, max_flow_counter) * ESW_OFFLOADS_NUM_GROUPS,
450+
esw_size = min_t(int, max_flow_counter * ESW_OFFLOADS_NUM_GROUPS,
449451
1 << MLX5_CAP_ESW_FLOWTABLE_FDB(dev, log_max_ft_size));
450452

451453
if (esw->offloads.encap != DEVLINK_ESWITCH_ENCAP_MODE_NONE)

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ int mlx5_cmd_delete_fte(struct mlx5_core_dev *dev,
359359
return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
360360
}
361361

362-
int mlx5_cmd_fc_alloc(struct mlx5_core_dev *dev, u16 *id)
362+
int mlx5_cmd_fc_alloc(struct mlx5_core_dev *dev, u32 *id)
363363
{
364364
u32 in[MLX5_ST_SZ_DW(alloc_flow_counter_in)] = {0};
365365
u32 out[MLX5_ST_SZ_DW(alloc_flow_counter_out)] = {0};
@@ -374,7 +374,7 @@ int mlx5_cmd_fc_alloc(struct mlx5_core_dev *dev, u16 *id)
374374
return err;
375375
}
376376

377-
int mlx5_cmd_fc_free(struct mlx5_core_dev *dev, u16 id)
377+
int mlx5_cmd_fc_free(struct mlx5_core_dev *dev, u32 id)
378378
{
379379
u32 in[MLX5_ST_SZ_DW(dealloc_flow_counter_in)] = {0};
380380
u32 out[MLX5_ST_SZ_DW(dealloc_flow_counter_out)] = {0};
@@ -385,7 +385,7 @@ int mlx5_cmd_fc_free(struct mlx5_core_dev *dev, u16 id)
385385
return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
386386
}
387387

388-
int mlx5_cmd_fc_query(struct mlx5_core_dev *dev, u16 id,
388+
int mlx5_cmd_fc_query(struct mlx5_core_dev *dev, u32 id,
389389
u64 *packets, u64 *bytes)
390390
{
391391
u32 out[MLX5_ST_SZ_BYTES(query_flow_counter_out) +
@@ -409,14 +409,14 @@ int mlx5_cmd_fc_query(struct mlx5_core_dev *dev, u16 id,
409409
}
410410

411411
struct mlx5_cmd_fc_bulk {
412-
u16 id;
412+
u32 id;
413413
int num;
414414
int outlen;
415415
u32 out[0];
416416
};
417417

418418
struct mlx5_cmd_fc_bulk *
419-
mlx5_cmd_fc_bulk_alloc(struct mlx5_core_dev *dev, u16 id, int num)
419+
mlx5_cmd_fc_bulk_alloc(struct mlx5_core_dev *dev, u32 id, int num)
420420
{
421421
struct mlx5_cmd_fc_bulk *b;
422422
int outlen =
@@ -453,7 +453,7 @@ mlx5_cmd_fc_bulk_query(struct mlx5_core_dev *dev, struct mlx5_cmd_fc_bulk *b)
453453
}
454454

455455
void mlx5_cmd_fc_bulk_get(struct mlx5_core_dev *dev,
456-
struct mlx5_cmd_fc_bulk *b, u16 id,
456+
struct mlx5_cmd_fc_bulk *b, u32 id,
457457
u64 *packets, u64 *bytes)
458458
{
459459
int index = id - b->id;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,20 @@ int mlx5_cmd_update_root_ft(struct mlx5_core_dev *dev,
7474
struct mlx5_flow_table *ft,
7575
u32 underlay_qpn);
7676

77-
int mlx5_cmd_fc_alloc(struct mlx5_core_dev *dev, u16 *id);
78-
int mlx5_cmd_fc_free(struct mlx5_core_dev *dev, u16 id);
79-
int mlx5_cmd_fc_query(struct mlx5_core_dev *dev, u16 id,
77+
int mlx5_cmd_fc_alloc(struct mlx5_core_dev *dev, u32 *id);
78+
int mlx5_cmd_fc_free(struct mlx5_core_dev *dev, u32 id);
79+
int mlx5_cmd_fc_query(struct mlx5_core_dev *dev, u32 id,
8080
u64 *packets, u64 *bytes);
8181

8282
struct mlx5_cmd_fc_bulk;
8383

8484
struct mlx5_cmd_fc_bulk *
85-
mlx5_cmd_fc_bulk_alloc(struct mlx5_core_dev *dev, u16 id, int num);
85+
mlx5_cmd_fc_bulk_alloc(struct mlx5_core_dev *dev, u32 id, int num);
8686
void mlx5_cmd_fc_bulk_free(struct mlx5_cmd_fc_bulk *b);
8787
int
8888
mlx5_cmd_fc_bulk_query(struct mlx5_core_dev *dev, struct mlx5_cmd_fc_bulk *b);
8989
void mlx5_cmd_fc_bulk_get(struct mlx5_core_dev *dev,
90-
struct mlx5_cmd_fc_bulk *b, u16 id,
90+
struct mlx5_cmd_fc_bulk *b, u32 id,
9191
u64 *packets, u64 *bytes);
9292

9393
#endif

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ struct mlx5_fc {
136136
u64 lastpackets;
137137
u64 lastbytes;
138138

139-
u16 id;
139+
u32 id;
140140
bool deleted;
141141
bool aging;
142142

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#include "fs_cmd.h"
3939

4040
#define MLX5_FC_STATS_PERIOD msecs_to_jiffies(1000)
41+
/* Max number of counters to query in bulk read is 32K */
42+
#define MLX5_SW_MAX_COUNTERS_BULK BIT(15)
4143

4244
/* locking scheme:
4345
*
@@ -90,16 +92,21 @@ static void mlx5_fc_stats_insert(struct rb_root *root, struct mlx5_fc *counter)
9092
rb_insert_color(&counter->node, root);
9193
}
9294

95+
/* The function returns the last node that was queried so the caller
96+
* function can continue calling it till all counters are queried.
97+
*/
9398
static struct rb_node *mlx5_fc_stats_query(struct mlx5_core_dev *dev,
9499
struct mlx5_fc *first,
95-
u16 last_id)
100+
u32 last_id)
96101
{
97102
struct mlx5_cmd_fc_bulk *b;
98103
struct rb_node *node = NULL;
99-
u16 afirst_id;
104+
u32 afirst_id;
100105
int num;
101106
int err;
102-
int max_bulk = 1 << MLX5_CAP_GEN(dev, log_max_flow_counter_bulk);
107+
108+
int max_bulk = min_t(int, MLX5_SW_MAX_COUNTERS_BULK,
109+
(1 << MLX5_CAP_GEN(dev, log_max_flow_counter_bulk)));
103110

104111
/* first id must be aligned to 4 when using bulk query */
105112
afirst_id = first->id & ~0x3;

include/linux/mlx5/mlx5_ifc.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ struct mlx5_ifc_cmd_hca_cap_bits {
963963
u8 reserved_at_2a0[0x10];
964964
u8 max_wqe_sz_rq[0x10];
965965

966-
u8 reserved_at_2c0[0x10];
966+
u8 max_flow_counter_31_16[0x10];
967967
u8 max_wqe_sz_sq_dc[0x10];
968968

969969
u8 reserved_at_2e0[0x7];
@@ -981,7 +981,7 @@ struct mlx5_ifc_cmd_hca_cap_bits {
981981

982982
u8 reserved_at_340[0x8];
983983
u8 log_max_flow_counter_bulk[0x8];
984-
u8 max_flow_counter[0x10];
984+
u8 max_flow_counter_15_0[0x10];
985985

986986

987987
u8 reserved_at_360[0x3];
@@ -1071,8 +1071,7 @@ struct mlx5_ifc_dest_format_struct_bits {
10711071
};
10721072

10731073
struct mlx5_ifc_flow_counter_list_bits {
1074-
u8 reserved_at_0[0x10];
1075-
u8 flow_counter_id[0x10];
1074+
u8 flow_counter_id[0x20];
10761075

10771076
u8 reserved_at_20[0x20];
10781077
};
@@ -4402,8 +4401,7 @@ struct mlx5_ifc_query_flow_counter_in_bits {
44024401
u8 reserved_at_c1[0xf];
44034402
u8 num_of_counters[0x10];
44044403

4405-
u8 reserved_at_e0[0x10];
4406-
u8 flow_counter_id[0x10];
4404+
u8 flow_counter_id[0x20];
44074405
};
44084406

44094407
struct mlx5_ifc_query_esw_vport_context_out_bits {
@@ -6271,8 +6269,7 @@ struct mlx5_ifc_dealloc_flow_counter_in_bits {
62716269
u8 reserved_at_20[0x10];
62726270
u8 op_mod[0x10];
62736271

6274-
u8 reserved_at_40[0x10];
6275-
u8 flow_counter_id[0x10];
6272+
u8 flow_counter_id[0x20];
62766273

62776274
u8 reserved_at_60[0x20];
62786275
};
@@ -7097,8 +7094,7 @@ struct mlx5_ifc_alloc_flow_counter_out_bits {
70977094

70987095
u8 syndrome[0x20];
70997096

7100-
u8 reserved_at_40[0x10];
7101-
u8 flow_counter_id[0x10];
7097+
u8 flow_counter_id[0x20];
71027098

71037099
u8 reserved_at_60[0x20];
71047100
};

0 commit comments

Comments
 (0)