Skip to content

Commit 9dc0b28

Browse files
amirvdavem330
authored andcommitted
net/mlx5_core: Firmware commands to support flow counters
Getting packet/byte statistics on flows is done through flow counters. Implement the firmware commands to alloc, free and query flow counters. Signed-off-by: Amir Vadai <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 42ca502 commit 9dc0b28

File tree

4 files changed

+173
-3
lines changed

4 files changed

+173
-3
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ static int mlx5_internal_err_ret_value(struct mlx5_core_dev *dev, u16 op,
294294
case MLX5_CMD_OP_DESTROY_FLOW_TABLE:
295295
case MLX5_CMD_OP_DESTROY_FLOW_GROUP:
296296
case MLX5_CMD_OP_DELETE_FLOW_TABLE_ENTRY:
297+
case MLX5_CMD_OP_DEALLOC_FLOW_COUNTER:
297298
return MLX5_CMD_STAT_OK;
298299

299300
case MLX5_CMD_OP_QUERY_HCA_CAP:
@@ -395,6 +396,8 @@ static int mlx5_internal_err_ret_value(struct mlx5_core_dev *dev, u16 op,
395396
case MLX5_CMD_OP_QUERY_FLOW_GROUP:
396397
case MLX5_CMD_OP_SET_FLOW_TABLE_ENTRY:
397398
case MLX5_CMD_OP_QUERY_FLOW_TABLE_ENTRY:
399+
case MLX5_CMD_OP_ALLOC_FLOW_COUNTER:
400+
case MLX5_CMD_OP_QUERY_FLOW_COUNTER:
398401
*status = MLX5_DRIVER_STATUS_ABORTED;
399402
*synd = MLX5_DRIVER_SYND;
400403
return -EIO;
@@ -539,6 +542,9 @@ const char *mlx5_command_str(int command)
539542
MLX5_COMMAND_STR_CASE(SET_FLOW_TABLE_ENTRY);
540543
MLX5_COMMAND_STR_CASE(QUERY_FLOW_TABLE_ENTRY);
541544
MLX5_COMMAND_STR_CASE(DELETE_FLOW_TABLE_ENTRY);
545+
MLX5_COMMAND_STR_CASE(ALLOC_FLOW_COUNTER);
546+
MLX5_COMMAND_STR_CASE(DEALLOC_FLOW_COUNTER);
547+
MLX5_COMMAND_STR_CASE(QUERY_FLOW_COUNTER);
542548
default: return "unknown command opcode";
543549
}
544550
}

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,69 @@ int mlx5_cmd_delete_fte(struct mlx5_core_dev *dev,
323323

324324
return err;
325325
}
326+
327+
int mlx5_cmd_fc_alloc(struct mlx5_core_dev *dev, u16 *id)
328+
{
329+
u32 in[MLX5_ST_SZ_DW(alloc_flow_counter_in)];
330+
u32 out[MLX5_ST_SZ_DW(alloc_flow_counter_out)];
331+
int err;
332+
333+
memset(in, 0, sizeof(in));
334+
memset(out, 0, sizeof(out));
335+
336+
MLX5_SET(alloc_flow_counter_in, in, opcode,
337+
MLX5_CMD_OP_ALLOC_FLOW_COUNTER);
338+
339+
err = mlx5_cmd_exec_check_status(dev, in, sizeof(in), out,
340+
sizeof(out));
341+
if (err)
342+
return err;
343+
344+
*id = MLX5_GET(alloc_flow_counter_out, out, flow_counter_id);
345+
346+
return 0;
347+
}
348+
349+
int mlx5_cmd_fc_free(struct mlx5_core_dev *dev, u16 id)
350+
{
351+
u32 in[MLX5_ST_SZ_DW(dealloc_flow_counter_in)];
352+
u32 out[MLX5_ST_SZ_DW(dealloc_flow_counter_out)];
353+
354+
memset(in, 0, sizeof(in));
355+
memset(out, 0, sizeof(out));
356+
357+
MLX5_SET(dealloc_flow_counter_in, in, opcode,
358+
MLX5_CMD_OP_DEALLOC_FLOW_COUNTER);
359+
MLX5_SET(dealloc_flow_counter_in, in, flow_counter_id, id);
360+
361+
return mlx5_cmd_exec_check_status(dev, in, sizeof(in), out,
362+
sizeof(out));
363+
}
364+
365+
int mlx5_cmd_fc_query(struct mlx5_core_dev *dev, u16 id,
366+
u64 *packets, u64 *bytes)
367+
{
368+
u32 out[MLX5_ST_SZ_BYTES(query_flow_counter_out) +
369+
MLX5_ST_SZ_BYTES(traffic_counter)];
370+
u32 in[MLX5_ST_SZ_DW(query_flow_counter_in)];
371+
void *stats;
372+
int err = 0;
373+
374+
memset(in, 0, sizeof(in));
375+
memset(out, 0, sizeof(out));
376+
377+
MLX5_SET(query_flow_counter_in, in, opcode,
378+
MLX5_CMD_OP_QUERY_FLOW_COUNTER);
379+
MLX5_SET(query_flow_counter_in, in, op_mod, 0);
380+
MLX5_SET(query_flow_counter_in, in, flow_counter_id, id);
381+
382+
err = mlx5_cmd_exec_check_status(dev, in, sizeof(in), out, sizeof(out));
383+
if (err)
384+
return err;
385+
386+
stats = MLX5_ADDR_OF(query_flow_counter_out, out, flow_statistics);
387+
*packets = MLX5_GET64(traffic_counter, stats, packets);
388+
*bytes = MLX5_GET64(traffic_counter, stats, octets);
389+
390+
return 0;
391+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,9 @@ int mlx5_cmd_delete_fte(struct mlx5_core_dev *dev,
7070

7171
int mlx5_cmd_update_root_ft(struct mlx5_core_dev *dev,
7272
struct mlx5_flow_table *ft);
73+
74+
int mlx5_cmd_fc_alloc(struct mlx5_core_dev *dev, u16 *id);
75+
int mlx5_cmd_fc_free(struct mlx5_core_dev *dev, u16 id);
76+
int mlx5_cmd_fc_query(struct mlx5_core_dev *dev, u16 id,
77+
u64 *packets, u64 *bytes);
7378
#endif

include/linux/mlx5/mlx5_ifc.h

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ enum {
202202
MLX5_CMD_OP_SET_FLOW_TABLE_ENTRY = 0x936,
203203
MLX5_CMD_OP_QUERY_FLOW_TABLE_ENTRY = 0x937,
204204
MLX5_CMD_OP_DELETE_FLOW_TABLE_ENTRY = 0x938,
205+
MLX5_CMD_OP_ALLOC_FLOW_COUNTER = 0x939,
206+
MLX5_CMD_OP_DEALLOC_FLOW_COUNTER = 0x93a,
207+
MLX5_CMD_OP_QUERY_FLOW_COUNTER = 0x93b,
205208
MLX5_CMD_OP_MODIFY_FLOW_TABLE = 0x93c
206209
};
207210

@@ -265,7 +268,8 @@ struct mlx5_ifc_flow_table_fields_supported_bits {
265268

266269
struct mlx5_ifc_flow_table_prop_layout_bits {
267270
u8 ft_support[0x1];
268-
u8 reserved_at_1[0x2];
271+
u8 reserved_at_1[0x1];
272+
u8 flow_counter[0x1];
269273
u8 flow_modify_en[0x1];
270274
u8 modify_root[0x1];
271275
u8 identified_miss_table_mode[0x1];
@@ -941,6 +945,19 @@ struct mlx5_ifc_dest_format_struct_bits {
941945
u8 reserved_at_20[0x20];
942946
};
943947

948+
struct mlx5_ifc_flow_counter_list_bits {
949+
u8 reserved_at_0[0x10];
950+
u8 flow_counter_id[0x10];
951+
952+
u8 reserved_at_20[0x20];
953+
};
954+
955+
union mlx5_ifc_dest_format_struct_flow_counter_list_auto_bits {
956+
struct mlx5_ifc_dest_format_struct_bits dest_format_struct;
957+
struct mlx5_ifc_flow_counter_list_bits flow_counter_list;
958+
u8 reserved_at_0[0x40];
959+
};
960+
944961
struct mlx5_ifc_fte_match_param_bits {
945962
struct mlx5_ifc_fte_match_set_lyr_2_4_bits outer_headers;
946963

@@ -2006,6 +2023,7 @@ enum {
20062023
MLX5_FLOW_CONTEXT_ACTION_ALLOW = 0x1,
20072024
MLX5_FLOW_CONTEXT_ACTION_DROP = 0x2,
20082025
MLX5_FLOW_CONTEXT_ACTION_FWD_DEST = 0x4,
2026+
MLX5_FLOW_CONTEXT_ACTION_COUNT = 0x8,
20092027
};
20102028

20112029
struct mlx5_ifc_flow_context_bits {
@@ -2022,13 +2040,16 @@ struct mlx5_ifc_flow_context_bits {
20222040
u8 reserved_at_80[0x8];
20232041
u8 destination_list_size[0x18];
20242042

2025-
u8 reserved_at_a0[0x160];
2043+
u8 reserved_at_a0[0x8];
2044+
u8 flow_counter_list_size[0x18];
2045+
2046+
u8 reserved_at_c0[0x140];
20262047

20272048
struct mlx5_ifc_fte_match_param_bits match_value;
20282049

20292050
u8 reserved_at_1200[0x600];
20302051

2031-
struct mlx5_ifc_dest_format_struct_bits destination[0];
2052+
union mlx5_ifc_dest_format_struct_flow_counter_list_auto_bits destination[0];
20322053
};
20332054

20342055
enum {
@@ -3937,6 +3958,34 @@ struct mlx5_ifc_query_flow_group_in_bits {
39373958
u8 reserved_at_e0[0x120];
39383959
};
39393960

3961+
struct mlx5_ifc_query_flow_counter_out_bits {
3962+
u8 status[0x8];
3963+
u8 reserved_at_8[0x18];
3964+
3965+
u8 syndrome[0x20];
3966+
3967+
u8 reserved_at_40[0x40];
3968+
3969+
struct mlx5_ifc_traffic_counter_bits flow_statistics[0];
3970+
};
3971+
3972+
struct mlx5_ifc_query_flow_counter_in_bits {
3973+
u8 opcode[0x10];
3974+
u8 reserved_at_10[0x10];
3975+
3976+
u8 reserved_at_20[0x10];
3977+
u8 op_mod[0x10];
3978+
3979+
u8 reserved_at_40[0x80];
3980+
3981+
u8 clear[0x1];
3982+
u8 reserved_at_c1[0xf];
3983+
u8 num_of_counters[0x10];
3984+
3985+
u8 reserved_at_e0[0x10];
3986+
u8 flow_counter_id[0x10];
3987+
};
3988+
39403989
struct mlx5_ifc_query_esw_vport_context_out_bits {
39413990
u8 status[0x8];
39423991
u8 reserved_at_8[0x18];
@@ -5510,6 +5559,28 @@ struct mlx5_ifc_dealloc_pd_in_bits {
55105559
u8 reserved_at_60[0x20];
55115560
};
55125561

5562+
struct mlx5_ifc_dealloc_flow_counter_out_bits {
5563+
u8 status[0x8];
5564+
u8 reserved_at_8[0x18];
5565+
5566+
u8 syndrome[0x20];
5567+
5568+
u8 reserved_at_40[0x40];
5569+
};
5570+
5571+
struct mlx5_ifc_dealloc_flow_counter_in_bits {
5572+
u8 opcode[0x10];
5573+
u8 reserved_at_10[0x10];
5574+
5575+
u8 reserved_at_20[0x10];
5576+
u8 op_mod[0x10];
5577+
5578+
u8 reserved_at_40[0x10];
5579+
u8 flow_counter_id[0x10];
5580+
5581+
u8 reserved_at_60[0x20];
5582+
};
5583+
55135584
struct mlx5_ifc_create_xrc_srq_out_bits {
55145585
u8 status[0x8];
55155586
u8 reserved_at_8[0x18];
@@ -6237,6 +6308,28 @@ struct mlx5_ifc_alloc_pd_in_bits {
62376308
u8 reserved_at_40[0x40];
62386309
};
62396310

6311+
struct mlx5_ifc_alloc_flow_counter_out_bits {
6312+
u8 status[0x8];
6313+
u8 reserved_at_8[0x18];
6314+
6315+
u8 syndrome[0x20];
6316+
6317+
u8 reserved_at_40[0x10];
6318+
u8 flow_counter_id[0x10];
6319+
6320+
u8 reserved_at_60[0x20];
6321+
};
6322+
6323+
struct mlx5_ifc_alloc_flow_counter_in_bits {
6324+
u8 opcode[0x10];
6325+
u8 reserved_at_10[0x10];
6326+
6327+
u8 reserved_at_20[0x10];
6328+
u8 op_mod[0x10];
6329+
6330+
u8 reserved_at_40[0x40];
6331+
};
6332+
62406333
struct mlx5_ifc_add_vxlan_udp_dport_out_bits {
62416334
u8 status[0x8];
62426335
u8 reserved_at_8[0x18];

0 commit comments

Comments
 (0)