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
);
110 * Query HCA attributes.
111 * Using those attributes we can check on run time if the device
112 * is having the required capabilities.
115 * ibv contexts returned from mlx5dv_open_device.
117 * Attributes device values.
120 * 0 on success, a negative value otherwise.
123 mlx5_devx_cmd_query_hca_attr(struct ibv_context
*ctx
,
124 struct mlx5_hca_attr
*attr
)
126 uint32_t in
[MLX5_ST_SZ_DW(query_hca_cap_in
)] = {0};
127 uint32_t out
[MLX5_ST_SZ_DW(query_hca_cap_out
)] = {0};
129 int status
, syndrome
, rc
;
131 MLX5_SET(query_hca_cap_in
, in
, opcode
, MLX5_CMD_OP_QUERY_HCA_CAP
);
132 MLX5_SET(query_hca_cap_in
, in
, op_mod
,
133 MLX5_GET_HCA_CAP_OP_MOD_GENERAL_DEVICE
|
134 MLX5_HCA_CAP_OPMOD_GET_CUR
);
136 rc
= mlx5_glue
->devx_general_cmd(ctx
,
137 in
, sizeof(in
), out
, sizeof(out
));
140 status
= MLX5_GET(query_hca_cap_out
, out
, status
);
141 syndrome
= MLX5_GET(query_hca_cap_out
, out
, syndrome
);
143 DRV_LOG(DEBUG
, "Failed to query devx HCA capabilities, "
144 "status %x, syndrome = %x",
148 hcattr
= MLX5_ADDR_OF(query_hca_cap_out
, out
, capability
);
149 attr
->eswitch_manager
= MLX5_GET(cmd_hca_cap
, hcattr
, eswitch_manager
);