1 // SPDX-License-Identifier: BSD-3-Clause
2 /* Copyright 2018 Mellanox Technologies, Ltd */
4 #include <rte_flow_driver.h>
11 * Allocate flow counters via devx interface.
14 * ibv contexts returned from mlx5dv_open_device.
16 * Pointer to counters properties structure to be filled by the routine.
19 * 0 on success, a negative value otherwise.
21 int mlx5_devx_cmd_flow_counter_alloc(struct ibv_context *ctx,
22 struct mlx5_devx_counter_set *dcs)
24 uint32_t in[MLX5_ST_SZ_DW(alloc_flow_counter_in)] = {0};
25 uint32_t out[MLX5_ST_SZ_DW(alloc_flow_counter_out)] = {0};
28 MLX5_SET(alloc_flow_counter_in, in, opcode,
29 MLX5_CMD_OP_ALLOC_FLOW_COUNTER);
30 dcs->obj = mlx5_glue->devx_obj_create(ctx, in,
31 sizeof(in), out, sizeof(out));
34 status = MLX5_GET(query_flow_counter_out, out, status);
35 syndrome = MLX5_GET(query_flow_counter_out, out, syndrome);
37 DRV_LOG(DEBUG, "Failed to create devx counters, "
38 "status %x, syndrome %x", status, syndrome);
41 dcs->id = MLX5_GET(alloc_flow_counter_out,
42 out, flow_counter_id);
47 * Free flow counters obtained via devx interface.
50 * devx object that was obtained from mlx5_devx_cmd_fc_alloc.
53 * 0 on success, a negative value otherwise.
55 int mlx5_devx_cmd_flow_counter_free(struct mlx5dv_devx_obj *obj)
57 return mlx5_glue->devx_obj_destroy(obj);
61 * Query flow counters values.
64 * devx object that was obtained from mlx5_devx_cmd_fc_alloc.
66 * Whether hardware should clear the counters after the query or not.
68 * The number of packets that matched the flow.
70 * The number of bytes that matched the flow.
73 * 0 on success, a negative value otherwise.
76 mlx5_devx_cmd_flow_counter_query(struct mlx5_devx_counter_set *dcs,
77 int clear __rte_unused,
78 uint64_t *pkts, uint64_t *bytes)
80 uint32_t out[MLX5_ST_SZ_BYTES(query_flow_counter_out) +
81 MLX5_ST_SZ_BYTES(traffic_counter)] = {0};
82 uint32_t in[MLX5_ST_SZ_DW(query_flow_counter_in)] = {0};
84 int status, syndrome, rc;
86 MLX5_SET(query_flow_counter_in, in, opcode,
87 MLX5_CMD_OP_QUERY_FLOW_COUNTER);
88 MLX5_SET(query_flow_counter_in, in, op_mod, 0);
89 MLX5_SET(query_flow_counter_in, in, flow_counter_id, dcs->id);
90 rc = mlx5_glue->devx_obj_query(dcs->obj,
91 in, sizeof(in), out, sizeof(out));
94 status = MLX5_GET(query_flow_counter_out, out, status);
95 syndrome = MLX5_GET(query_flow_counter_out, out, syndrome);
97 DRV_LOG(DEBUG, "Failed to query devx counters, "
98 "id %d, status %x, syndrome = %x",
99 status, syndrome, dcs->id);
102 stats = MLX5_ADDR_OF(query_flow_counter_out,
103 out, flow_statistics);
104 *pkts = MLX5_GET64(traffic_counter, stats, packets);
105 *bytes = MLX5_GET64(traffic_counter, stats, octets);