Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2018 Mellanox Technologies, Ltd
3 : : */
4 : :
5 : : #include <unistd.h>
6 : :
7 : : #include <eal_export.h>
8 : : #include <rte_errno.h>
9 : : #include <rte_malloc.h>
10 : : #include <rte_eal_paging.h>
11 : :
12 : : #include "mlx5_prm.h"
13 : : #include "mlx5_devx_cmds.h"
14 : : #include "mlx5_common_log.h"
15 : : #include "mlx5_malloc.h"
16 : :
17 : : /* FW writes status value to the OUT buffer at offset 00H */
18 : : #define MLX5_FW_STATUS(o) MLX5_GET(general_obj_out_cmd_hdr, (o), status)
19 : : /* FW writes syndrome value to the OUT buffer at offset 04H */
20 : : #define MLX5_FW_SYNDROME(o) MLX5_GET(general_obj_out_cmd_hdr, (o), syndrome)
21 : :
22 : : #define MLX5_DEVX_ERR_RC(x) ((x) > 0 ? -(x) : ((x) < 0 ? (x) : -1))
23 : :
24 : : #define DEVX_DRV_LOG(level, out, reason, param, value) \
25 : : do { \
26 : : /* \
27 : : * Some (old) GCC compilers like 7.5.0 and aarch64 GCC 7.1-2017.08 \
28 : : * do not expand correctly when the macro invoked when the `param` \
29 : : * is `NULL`. \
30 : : * Use `local_param` to avoid direct `NULL` expansion. \
31 : : */ \
32 : : const char *local_param = (const char *)param; \
33 : : \
34 : : rte_errno = errno; \
35 : : if (!local_param) { \
36 : : DRV_LOG(level, \
37 : : "DevX %s failed errno=%d status=%#x syndrome=%#x", \
38 : : (reason), errno, MLX5_FW_STATUS((out)), \
39 : : MLX5_FW_SYNDROME((out))); \
40 : : } else { \
41 : : DRV_LOG(level, \
42 : : "DevX %s %s=%#X failed errno=%d status=%#x syndrome=%#x",\
43 : : (reason), local_param, (value), errno, \
44 : : MLX5_FW_STATUS((out)), MLX5_FW_SYNDROME((out))); \
45 : : } \
46 : : } while (0)
47 : :
48 : : static void *
49 [ # # ]: 0 : mlx5_devx_get_hca_cap(void *ctx, uint32_t *in, uint32_t *out,
50 : : int *err, uint32_t flags)
51 : : {
52 : : const size_t size_in = MLX5_ST_SZ_DW(query_hca_cap_in) * sizeof(int);
53 : : const size_t size_out = MLX5_ST_SZ_DW(query_hca_cap_out) * sizeof(int);
54 : : int rc;
55 : :
56 : : memset(in, 0, size_in);
57 : : memset(out, 0, size_out);
58 [ # # ]: 0 : MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP);
59 [ # # ]: 0 : MLX5_SET(query_hca_cap_in, in, op_mod, flags);
60 : 0 : rc = mlx5_glue->devx_general_cmd(ctx, in, size_in, out, size_out);
61 [ # # # # : 0 : if (rc || MLX5_FW_STATUS(out)) {
# # # # ]
62 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "HCA capabilities", "func", flags >> 1);
63 [ # # ]: 0 : if (err)
64 [ # # ]: 0 : *err = MLX5_DEVX_ERR_RC(rc);
65 : 0 : return NULL;
66 : : }
67 [ # # ]: 0 : if (err)
68 : 0 : *err = 0;
69 : 0 : return MLX5_ADDR_OF(query_hca_cap_out, out, capability);
70 : : }
71 : :
72 : : /**
73 : : * Perform read access to the registers. Reads data from register
74 : : * and writes ones to the specified buffer.
75 : : *
76 : : * @param[in] ctx
77 : : * Context returned from mlx5 open_device() glue function.
78 : : * @param[in] reg_id
79 : : * Register identifier according to the PRM.
80 : : * @param[in] arg
81 : : * Register access auxiliary parameter according to the PRM.
82 : : * @param[out] data
83 : : * Pointer to the buffer to store read data.
84 : : * @param[in] dw_cnt
85 : : * Buffer size in double words.
86 : : *
87 : : * @return
88 : : * 0 on success, a negative value otherwise.
89 : : */
90 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_register_read)
91 : : int
92 : 0 : mlx5_devx_cmd_register_read(void *ctx, uint16_t reg_id, uint32_t arg,
93 : : uint32_t *data, uint32_t dw_cnt)
94 : : {
95 : 0 : uint32_t in[MLX5_ST_SZ_DW(access_register_in)] = {0};
96 : 0 : uint32_t out[MLX5_ST_SZ_DW(access_register_out) +
97 : : MLX5_ACCESS_REGISTER_DATA_DWORD_MAX] = {0};
98 : : int rc;
99 : :
100 : : MLX5_ASSERT(data && dw_cnt);
101 : : MLX5_ASSERT(dw_cnt <= MLX5_ACCESS_REGISTER_DATA_DWORD_MAX);
102 [ # # ]: 0 : if (dw_cnt > MLX5_ACCESS_REGISTER_DATA_DWORD_MAX) {
103 : 0 : DRV_LOG(ERR, "Not enough buffer for register read data");
104 : 0 : return -1;
105 : : }
106 : 0 : MLX5_SET(access_register_in, in, opcode,
107 : : MLX5_CMD_OP_ACCESS_REGISTER_USER);
108 : 0 : MLX5_SET(access_register_in, in, op_mod,
109 : : MLX5_ACCESS_REGISTER_IN_OP_MOD_READ);
110 : 0 : MLX5_SET(access_register_in, in, register_id, reg_id);
111 : 0 : MLX5_SET(access_register_in, in, argument, arg);
112 : 0 : rc = mlx5_glue->devx_general_cmd(ctx, in, sizeof(in), out,
113 : 0 : MLX5_ST_SZ_BYTES(access_register_out) +
114 : : sizeof(uint32_t) * dw_cnt);
115 [ # # # # : 0 : if (rc || MLX5_FW_STATUS(out)) {
# # # # ]
116 [ # # # # ]: 0 : DEVX_DRV_LOG(DEBUG, out, "read access", "NIC register", reg_id);
117 [ # # ]: 0 : return MLX5_DEVX_ERR_RC(rc);
118 : : }
119 : 0 : memcpy(data, &out[MLX5_ST_SZ_DW(access_register_out)],
120 : : dw_cnt * sizeof(uint32_t));
121 : 0 : return 0;
122 : : }
123 : :
124 : : /**
125 : : * Perform write access to the registers.
126 : : *
127 : : * @param[in] ctx
128 : : * Context returned from mlx5 open_device() glue function.
129 : : * @param[in] reg_id
130 : : * Register identifier according to the PRM.
131 : : * @param[in] arg
132 : : * Register access auxiliary parameter according to the PRM.
133 : : * @param[out] data
134 : : * Pointer to the buffer containing data to write.
135 : : * @param[in] dw_cnt
136 : : * Buffer size in double words (32bit units).
137 : : *
138 : : * @return
139 : : * 0 on success, a negative value otherwise.
140 : : */
141 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_register_write)
142 : : int
143 : 0 : mlx5_devx_cmd_register_write(void *ctx, uint16_t reg_id, uint32_t arg,
144 : : uint32_t *data, uint32_t dw_cnt)
145 : : {
146 : 0 : uint32_t in[MLX5_ST_SZ_DW(access_register_in) +
147 : : MLX5_ACCESS_REGISTER_DATA_DWORD_MAX] = {0};
148 : 0 : uint32_t out[MLX5_ST_SZ_DW(access_register_out)] = {0};
149 : : int rc;
150 : : void *ptr;
151 : :
152 : : MLX5_ASSERT(data && dw_cnt);
153 : : MLX5_ASSERT(dw_cnt <= MLX5_ACCESS_REGISTER_DATA_DWORD_MAX);
154 [ # # ]: 0 : if (dw_cnt > MLX5_ACCESS_REGISTER_DATA_DWORD_MAX) {
155 : 0 : DRV_LOG(ERR, "Data to write exceeds max size");
156 : 0 : return -1;
157 : : }
158 : 0 : MLX5_SET(access_register_in, in, opcode,
159 : : MLX5_CMD_OP_ACCESS_REGISTER_USER);
160 : 0 : MLX5_SET(access_register_in, in, op_mod,
161 : : MLX5_ACCESS_REGISTER_IN_OP_MOD_WRITE);
162 : 0 : MLX5_SET(access_register_in, in, register_id, reg_id);
163 : 0 : MLX5_SET(access_register_in, in, argument, arg);
164 : : ptr = MLX5_ADDR_OF(access_register_in, in, register_data);
165 : 0 : memcpy(ptr, data, dw_cnt * sizeof(uint32_t));
166 : 0 : rc = mlx5_glue->devx_general_cmd(ctx, in, sizeof(in), out, sizeof(out));
167 [ # # # # : 0 : if (rc || MLX5_FW_STATUS(out)) {
# # # # ]
168 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "write access", "NIC register", reg_id);
169 [ # # ]: 0 : return MLX5_DEVX_ERR_RC(rc);
170 : : }
171 : 0 : rc = mlx5_glue->devx_general_cmd(ctx, in,
172 : 0 : MLX5_ST_SZ_BYTES(access_register_in) +
173 : : dw_cnt * sizeof(uint32_t),
174 : : out, sizeof(out));
175 [ # # # # : 0 : if (rc || MLX5_FW_STATUS(out)) {
# # # # ]
176 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "write access", "NIC register", reg_id);
177 [ # # ]: 0 : return MLX5_DEVX_ERR_RC(rc);
178 : : }
179 : : return 0;
180 : : }
181 : :
182 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_flow_counter_alloc_general)
183 : : struct mlx5_devx_obj *
184 : 0 : mlx5_devx_cmd_flow_counter_alloc_general(void *ctx,
185 : : struct mlx5_devx_counter_attr *attr)
186 : : {
187 : 0 : struct mlx5_devx_obj *dcs = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*dcs),
188 : : 0, SOCKET_ID_ANY);
189 : 0 : uint32_t in[MLX5_ST_SZ_DW(alloc_flow_counter_in)] = {0};
190 : 0 : uint32_t out[MLX5_ST_SZ_DW(alloc_flow_counter_out)] = {0};
191 : :
192 [ # # ]: 0 : if (!dcs) {
193 : 0 : rte_errno = ENOMEM;
194 : 0 : return NULL;
195 : : }
196 : 0 : MLX5_SET(alloc_flow_counter_in, in, opcode,
197 : : MLX5_CMD_OP_ALLOC_FLOW_COUNTER);
198 [ # # ]: 0 : if (attr->bulk_log_max_alloc)
199 : 0 : MLX5_SET(alloc_flow_counter_in, in, flow_counter_bulk_log_size,
200 : : attr->flow_counter_bulk_log_size);
201 : : else
202 : 0 : MLX5_SET(alloc_flow_counter_in, in, flow_counter_bulk,
203 : : attr->bulk_n_128);
204 [ # # ]: 0 : if (attr->pd_valid)
205 : 0 : MLX5_SET(alloc_flow_counter_in, in, pd, attr->pd);
206 : 0 : dcs->obj = mlx5_glue->devx_obj_create(ctx, in,
207 : : sizeof(in), out, sizeof(out));
208 [ # # ]: 0 : if (!dcs->obj) {
209 : 0 : DRV_LOG(ERR, "Can't allocate counters - error %d", errno);
210 : 0 : rte_errno = errno;
211 : 0 : mlx5_free(dcs);
212 : 0 : return NULL;
213 : : }
214 [ # # ]: 0 : dcs->id = MLX5_GET(alloc_flow_counter_out, out, flow_counter_id);
215 : 0 : return dcs;
216 : : }
217 : :
218 : : /**
219 : : * Allocate flow counters via devx interface.
220 : : *
221 : : * @param[in] ctx
222 : : * Context returned from mlx5 open_device() glue function.
223 : : * @param dcs
224 : : * Pointer to counters properties structure to be filled by the routine.
225 : : * @param bulk_n_128
226 : : * Bulk counter numbers in 128 counters units.
227 : : *
228 : : * @return
229 : : * Pointer to counter object on success, a negative value otherwise and
230 : : * rte_errno is set.
231 : : */
232 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_flow_counter_alloc)
233 : : struct mlx5_devx_obj *
234 : 0 : mlx5_devx_cmd_flow_counter_alloc(void *ctx, uint32_t bulk_n_128)
235 : : {
236 : 0 : struct mlx5_devx_obj *dcs = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*dcs),
237 : : 0, SOCKET_ID_ANY);
238 : 0 : uint32_t in[MLX5_ST_SZ_DW(alloc_flow_counter_in)] = {0};
239 : 0 : uint32_t out[MLX5_ST_SZ_DW(alloc_flow_counter_out)] = {0};
240 : :
241 [ # # ]: 0 : if (!dcs) {
242 : 0 : rte_errno = ENOMEM;
243 : 0 : return NULL;
244 : : }
245 : 0 : MLX5_SET(alloc_flow_counter_in, in, opcode,
246 : : MLX5_CMD_OP_ALLOC_FLOW_COUNTER);
247 : 0 : MLX5_SET(alloc_flow_counter_in, in, flow_counter_bulk, bulk_n_128);
248 : 0 : dcs->obj = mlx5_glue->devx_obj_create(ctx, in,
249 : : sizeof(in), out, sizeof(out));
250 [ # # ]: 0 : if (!dcs->obj) {
251 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "allocate counters", NULL, 0);
252 : 0 : mlx5_free(dcs);
253 : 0 : return NULL;
254 : : }
255 [ # # ]: 0 : dcs->id = MLX5_GET(alloc_flow_counter_out, out, flow_counter_id);
256 : 0 : return dcs;
257 : : }
258 : :
259 : : /**
260 : : * Query flow counters values.
261 : : *
262 : : * @param[in] dcs
263 : : * devx object that was obtained from mlx5_devx_cmd_fc_alloc.
264 : : * @param[in] clear
265 : : * Whether hardware should clear the counters after the query or not.
266 : : * @param[in] n_counters
267 : : * 0 in case of 1 counter to read, otherwise the counter number to read.
268 : : * @param pkts
269 : : * The number of packets that matched the flow.
270 : : * @param bytes
271 : : * The number of bytes that matched the flow.
272 : : * @param mkey
273 : : * The mkey key for batch query.
274 : : * @param addr
275 : : * The address in the mkey range for batch query.
276 : : * @param cmd_comp
277 : : * The completion object for asynchronous batch query.
278 : : * @param async_id
279 : : * The ID to be returned in the asynchronous batch query response.
280 : : *
281 : : * @return
282 : : * 0 on success, a negative value otherwise.
283 : : */
284 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_flow_counter_query)
285 : : int
286 : 0 : mlx5_devx_cmd_flow_counter_query(struct mlx5_devx_obj *dcs,
287 : : int clear, uint32_t n_counters,
288 : : uint64_t *pkts, uint64_t *bytes,
289 : : uint32_t mkey, void *addr,
290 : : void *cmd_comp,
291 : : uint64_t async_id)
292 : : {
293 : : uint32_t out[MLX5_ST_SZ_BYTES(query_flow_counter_out) + MLX5_ST_SZ_BYTES(traffic_counter)];
294 : 0 : uint32_t in[MLX5_ST_SZ_DW(query_flow_counter_in)] = {0};
295 : : const int out_len = RTE_DIM(out);
296 : : void *stats;
297 : : int rc;
298 : :
299 : 0 : MLX5_SET(query_flow_counter_in, in, opcode,
300 : : MLX5_CMD_OP_QUERY_FLOW_COUNTER);
301 : 0 : MLX5_SET(query_flow_counter_in, in, op_mod, 0);
302 : 0 : MLX5_SET(query_flow_counter_in, in, flow_counter_id, dcs->id);
303 : 0 : MLX5_SET(query_flow_counter_in, in, clear, !!clear);
304 : :
305 [ # # ]: 0 : if (n_counters) {
306 [ # # ]: 0 : MLX5_SET(query_flow_counter_in, in, num_of_counters,
307 : : n_counters);
308 [ # # ]: 0 : MLX5_SET(query_flow_counter_in, in, dump_to_memory, 1);
309 : 0 : MLX5_SET(query_flow_counter_in, in, mkey, mkey);
310 : 0 : MLX5_SET64(query_flow_counter_in, in, address,
311 : : (uint64_t)(uintptr_t)addr);
312 : : }
313 [ # # ]: 0 : if (!cmd_comp)
314 : 0 : rc = mlx5_glue->devx_obj_query(dcs->obj, in, sizeof(in), out,
315 : : out_len);
316 : : else
317 : 0 : rc = mlx5_glue->devx_obj_query_async(dcs->obj, in, sizeof(in),
318 : : out_len, async_id,
319 : : cmd_comp);
320 [ # # ]: 0 : if (rc) {
321 : 0 : DRV_LOG(ERR, "Failed to query devx counters with rc %d", rc);
322 : 0 : rte_errno = rc;
323 : 0 : return -rc;
324 : : }
325 [ # # ]: 0 : if (!n_counters) {
326 : : stats = MLX5_ADDR_OF(query_flow_counter_out,
327 : : out, flow_statistics);
328 [ # # ]: 0 : *pkts = MLX5_GET64(traffic_counter, stats, packets);
329 [ # # ]: 0 : *bytes = MLX5_GET64(traffic_counter, stats, octets);
330 : : }
331 : : return 0;
332 : : }
333 : :
334 : : /**
335 : : * Create a new mkey.
336 : : *
337 : : * @param[in] ctx
338 : : * Context returned from mlx5 open_device() glue function.
339 : : * @param[in] attr
340 : : * Attributes of the requested mkey.
341 : : *
342 : : * @return
343 : : * Pointer to Devx mkey on success, a negative value otherwise and rte_errno
344 : : * is set.
345 : : */
346 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_mkey_create)
347 : : struct mlx5_devx_obj *
348 : 0 : mlx5_devx_cmd_mkey_create(void *ctx,
349 : : struct mlx5_devx_mkey_attr *attr)
350 : : {
351 : 0 : struct mlx5_klm *klm_array = attr->klm_array;
352 : 0 : int klm_num = attr->klm_num;
353 [ # # ]: 0 : int in_size_dw = MLX5_ST_SZ_DW(create_mkey_in) +
354 : 0 : (klm_num ? RTE_ALIGN(klm_num, 4) : 0) * MLX5_ST_SZ_DW(klm);
355 : 0 : uint32_t *in = alloca(sizeof(uint32_t) * in_size_dw);
356 : 0 : uint32_t out[MLX5_ST_SZ_DW(create_mkey_out)] = {0};
357 : : void *mkc;
358 : 0 : struct mlx5_devx_obj *mkey = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*mkey),
359 : : 0, SOCKET_ID_ANY);
360 : : size_t pgsize;
361 : : uint32_t translation_size;
362 : :
363 [ # # ]: 0 : if (!mkey) {
364 : 0 : rte_errno = ENOMEM;
365 : 0 : return NULL;
366 : : }
367 : : memset(in, 0, in_size_dw * 4);
368 : 0 : pgsize = rte_mem_page_size();
369 [ # # ]: 0 : if (pgsize == (size_t)-1) {
370 : 0 : mlx5_free(mkey);
371 : 0 : DRV_LOG(ERR, "Failed to get page size");
372 : 0 : rte_errno = ENOMEM;
373 : 0 : return NULL;
374 : : }
375 [ # # ]: 0 : MLX5_SET(create_mkey_in, in, opcode, MLX5_CMD_OP_CREATE_MKEY);
376 : : mkc = MLX5_ADDR_OF(create_mkey_in, in, memory_key_mkey_entry);
377 [ # # ]: 0 : if (klm_num > 0) {
378 : : int i;
379 : 0 : uint8_t *klm = (uint8_t *)MLX5_ADDR_OF(create_mkey_in, in,
380 : : klm_pas_mtt);
381 : 0 : translation_size = RTE_ALIGN(klm_num, 4);
382 [ # # ]: 0 : for (i = 0; i < klm_num; i++) {
383 [ # # ]: 0 : MLX5_SET(klm, klm, byte_count, klm_array[i].byte_count);
384 [ # # ]: 0 : MLX5_SET(klm, klm, mkey, klm_array[i].mkey);
385 [ # # ]: 0 : MLX5_SET64(klm, klm, address, klm_array[i].address);
386 : 0 : klm += MLX5_ST_SZ_BYTES(klm);
387 : : }
388 [ # # ]: 0 : for (; i < (int)translation_size; i++) {
389 [ # # ]: 0 : MLX5_SET(klm, klm, mkey, 0x0);
390 : 0 : MLX5_SET64(klm, klm, address, 0x0);
391 : 0 : klm += MLX5_ST_SZ_BYTES(klm);
392 : : }
393 [ # # # # ]: 0 : MLX5_SET(mkc, mkc, access_mode_1_0, attr->log_entity_size ?
394 : : MLX5_MKC_ACCESS_MODE_KLM_FBS :
395 : : MLX5_MKC_ACCESS_MODE_KLM);
396 [ # # ]: 0 : MLX5_SET(mkc, mkc, log_page_size, attr->log_entity_size);
397 : : } else {
398 : 0 : translation_size = (RTE_ALIGN(attr->size, pgsize) * 8) / 16;
399 [ # # ]: 0 : MLX5_SET(mkc, mkc, access_mode_1_0, MLX5_MKC_ACCESS_MODE_MTT);
400 [ # # # # ]: 0 : MLX5_SET(mkc, mkc, log_page_size, rte_log2_u32(pgsize));
401 : : }
402 [ # # ]: 0 : MLX5_SET(create_mkey_in, in, translations_octword_actual_size,
403 : : translation_size);
404 [ # # ]: 0 : MLX5_SET(create_mkey_in, in, mkey_umem_id, attr->umem_id);
405 [ # # ]: 0 : MLX5_SET(create_mkey_in, in, pg_access, attr->pg_access);
406 [ # # ]: 0 : MLX5_SET(mkc, mkc, lw, 0x1);
407 [ # # ]: 0 : MLX5_SET(mkc, mkc, lr, 0x1);
408 [ # # ]: 0 : if (attr->set_remote_rw) {
409 [ # # ]: 0 : MLX5_SET(mkc, mkc, rw, 0x1);
410 [ # # ]: 0 : MLX5_SET(mkc, mkc, rr, 0x1);
411 : : }
412 [ # # ]: 0 : MLX5_SET(mkc, mkc, qpn, 0xffffff);
413 [ # # ]: 0 : MLX5_SET(mkc, mkc, pd, attr->pd);
414 [ # # ]: 0 : MLX5_SET(mkc, mkc, mkey_7_0, attr->umem_id & 0xFF);
415 [ # # ]: 0 : MLX5_SET(mkc, mkc, umr_en, attr->umr_en);
416 [ # # ]: 0 : MLX5_SET(mkc, mkc, translations_octword_size, translation_size);
417 [ # # ]: 0 : MLX5_SET(mkc, mkc, relaxed_ordering_write,
418 : : attr->relaxed_ordering_write);
419 [ # # ]: 0 : MLX5_SET(mkc, mkc, relaxed_ordering_read, attr->relaxed_ordering_read);
420 [ # # ]: 0 : MLX5_SET64(mkc, mkc, start_addr, attr->addr);
421 [ # # ]: 0 : MLX5_SET64(mkc, mkc, len, attr->size);
422 [ # # ]: 0 : MLX5_SET(mkc, mkc, crypto_en, attr->crypto_en);
423 [ # # ]: 0 : if (attr->crypto_en) {
424 [ # # ]: 0 : MLX5_SET(mkc, mkc, bsf_en, attr->crypto_en);
425 [ # # ]: 0 : MLX5_SET(mkc, mkc, bsf_octword_size, 4);
426 : : }
427 : 0 : mkey->obj = mlx5_glue->devx_obj_create(ctx, in, in_size_dw * 4, out,
428 : : sizeof(out));
429 [ # # ]: 0 : if (!mkey->obj) {
430 [ # # # # : 0 : DEVX_DRV_LOG(ERR, out, klm_num ? "create indirect mkey"
# # ]
431 : : : "create direct key", NULL, 0);
432 : 0 : mlx5_free(mkey);
433 : 0 : return NULL;
434 : : }
435 [ # # ]: 0 : mkey->id = MLX5_GET(create_mkey_out, out, mkey_index);
436 : 0 : mkey->id = (mkey->id << 8) | (attr->umem_id & 0xFF);
437 : 0 : return mkey;
438 : : }
439 : :
440 : : /**
441 : : * Get status of devx command response.
442 : : * Mainly used for asynchronous commands.
443 : : *
444 : : * @param[in] out
445 : : * The out response buffer.
446 : : *
447 : : * @return
448 : : * 0 on success, non-zero value otherwise.
449 : : */
450 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_get_out_command_status)
451 : : int
452 : 0 : mlx5_devx_get_out_command_status(void *out)
453 : : {
454 : : int status;
455 : :
456 [ # # ]: 0 : if (!out)
457 : : return -EINVAL;
458 [ # # ]: 0 : status = MLX5_GET(query_flow_counter_out, out, status);
459 [ # # ]: 0 : if (status) {
460 [ # # ]: 0 : int syndrome = MLX5_GET(query_flow_counter_out, out, syndrome);
461 : :
462 : 0 : DRV_LOG(ERR, "Bad DevX status %x, syndrome = %x", status,
463 : : syndrome);
464 : : }
465 : : return status;
466 : : }
467 : :
468 : : /**
469 : : * Destroy any object allocated by a Devx API.
470 : : *
471 : : * @param[in] obj
472 : : * Pointer to a general object.
473 : : *
474 : : * @return
475 : : * 0 on success, a negative value otherwise.
476 : : */
477 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_destroy)
478 : : int
479 : 0 : mlx5_devx_cmd_destroy(struct mlx5_devx_obj *obj)
480 : : {
481 : : int ret;
482 : :
483 [ # # ]: 0 : if (!obj)
484 : : return 0;
485 : 0 : ret = mlx5_glue->devx_obj_destroy(obj->obj);
486 : 0 : mlx5_free(obj);
487 : 0 : return ret;
488 : : }
489 : :
490 : : /**
491 : : * Query NIC vport context.
492 : : * Fills minimal inline attribute.
493 : : *
494 : : * @param[in] ctx
495 : : * ibv contexts returned from mlx5dv_open_device.
496 : : * @param[in] vport
497 : : * vport index
498 : : * @param[out] attr
499 : : * Attributes device values.
500 : : *
501 : : * @return
502 : : * 0 on success, a negative value otherwise.
503 : : */
504 : : static int
505 : 0 : mlx5_devx_cmd_query_nic_vport_context(void *ctx,
506 : : unsigned int vport,
507 : : struct mlx5_hca_attr *attr)
508 : : {
509 : 0 : uint32_t in[MLX5_ST_SZ_DW(query_nic_vport_context_in)] = {0};
510 : 0 : uint32_t out[MLX5_ST_SZ_DW(query_nic_vport_context_out)] = {0};
511 : : void *vctx;
512 : : int rc;
513 : :
514 : : /* Query NIC vport context to determine inline mode. */
515 : 0 : MLX5_SET(query_nic_vport_context_in, in, opcode,
516 : : MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT);
517 : 0 : MLX5_SET(query_nic_vport_context_in, in, vport_number, vport);
518 [ # # ]: 0 : if (vport)
519 [ # # ]: 0 : MLX5_SET(query_nic_vport_context_in, in, other_vport, 1);
520 : 0 : rc = mlx5_glue->devx_general_cmd(ctx,
521 : : in, sizeof(in),
522 : : out, sizeof(out));
523 [ # # # # : 0 : if (rc || MLX5_FW_STATUS(out)) {
# # # # ]
524 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "query NIC vport context", NULL, 0);
525 [ # # ]: 0 : return MLX5_DEVX_ERR_RC(rc);
526 : : }
527 : : vctx = MLX5_ADDR_OF(query_nic_vport_context_out, out,
528 : : nic_vport_context);
529 [ # # ]: 0 : if (attr->wqe_inline_mode == MLX5_CAP_INLINE_MODE_VPORT_CONTEXT)
530 [ # # ]: 0 : attr->vport_inline_mode = MLX5_GET(nic_vport_context, vctx,
531 : : min_wqe_inline_mode);
532 [ # # ]: 0 : attr->system_image_guid = MLX5_GET64(nic_vport_context, vctx,
533 : : system_image_guid);
534 : 0 : return 0;
535 : : }
536 : :
537 : : /**
538 : : * Query NIC vDPA attributes.
539 : : *
540 : : * @param[in] ctx
541 : : * Context returned from mlx5 open_device() glue function.
542 : : * @param[out] vdpa_attr
543 : : * vDPA Attributes structure to fill.
544 : : */
545 : : static void
546 : 0 : mlx5_devx_cmd_query_hca_vdpa_attr(void *ctx,
547 : : struct mlx5_hca_vdpa_attr *vdpa_attr)
548 : : {
549 : : uint32_t in[MLX5_ST_SZ_DW(query_hca_cap_in)];
550 : : uint32_t out[MLX5_ST_SZ_DW(query_hca_cap_out)];
551 : : void *hcattr;
552 : :
553 : 0 : hcattr = mlx5_devx_get_hca_cap(ctx, in, out, NULL,
554 : : MLX5_GET_HCA_CAP_OP_MOD_VDPA_EMULATION |
555 : : (uint32_t)MLX5_HCA_CAP_OPMOD_GET_CUR);
556 [ # # ]: 0 : if (!hcattr) {
557 : 0 : DRV_LOG(DEBUG, "Failed to query devx VDPA capabilities");
558 : 0 : vdpa_attr->valid = 0;
559 : : } else {
560 : 0 : vdpa_attr->valid = 1;
561 : 0 : vdpa_attr->desc_tunnel_offload_type =
562 [ # # ]: 0 : MLX5_GET(virtio_emulation_cap, hcattr,
563 : : desc_tunnel_offload_type);
564 : 0 : vdpa_attr->eth_frame_offload_type =
565 [ # # ]: 0 : MLX5_GET(virtio_emulation_cap, hcattr,
566 : : eth_frame_offload_type);
567 : 0 : vdpa_attr->virtio_version_1_0 =
568 [ # # ]: 0 : MLX5_GET(virtio_emulation_cap, hcattr,
569 : : virtio_version_1_0);
570 [ # # ]: 0 : vdpa_attr->tso_ipv4 = MLX5_GET(virtio_emulation_cap, hcattr,
571 : : tso_ipv4);
572 [ # # ]: 0 : vdpa_attr->tso_ipv6 = MLX5_GET(virtio_emulation_cap, hcattr,
573 : : tso_ipv6);
574 [ # # ]: 0 : vdpa_attr->tx_csum = MLX5_GET(virtio_emulation_cap, hcattr,
575 : : tx_csum);
576 [ # # ]: 0 : vdpa_attr->rx_csum = MLX5_GET(virtio_emulation_cap, hcattr,
577 : : rx_csum);
578 [ # # ]: 0 : vdpa_attr->event_mode = MLX5_GET(virtio_emulation_cap, hcattr,
579 : : event_mode);
580 : 0 : vdpa_attr->virtio_queue_type =
581 [ # # ]: 0 : MLX5_GET(virtio_emulation_cap, hcattr,
582 : : virtio_queue_type);
583 : 0 : vdpa_attr->log_doorbell_stride =
584 [ # # ]: 0 : MLX5_GET(virtio_emulation_cap, hcattr,
585 : : log_doorbell_stride);
586 : 0 : vdpa_attr->vnet_modify_ext =
587 [ # # ]: 0 : MLX5_GET(virtio_emulation_cap, hcattr,
588 : : vnet_modify_ext);
589 : 0 : vdpa_attr->virtio_net_q_addr_modify =
590 [ # # ]: 0 : MLX5_GET(virtio_emulation_cap, hcattr,
591 : : virtio_net_q_addr_modify);
592 : 0 : vdpa_attr->virtio_q_index_modify =
593 [ # # ]: 0 : MLX5_GET(virtio_emulation_cap, hcattr,
594 : : virtio_q_index_modify);
595 : 0 : vdpa_attr->log_doorbell_bar_size =
596 [ # # ]: 0 : MLX5_GET(virtio_emulation_cap, hcattr,
597 : : log_doorbell_bar_size);
598 : 0 : vdpa_attr->doorbell_bar_offset =
599 [ # # ]: 0 : MLX5_GET64(virtio_emulation_cap, hcattr,
600 : : doorbell_bar_offset);
601 : 0 : vdpa_attr->max_num_virtio_queues =
602 [ # # ]: 0 : MLX5_GET(virtio_emulation_cap, hcattr,
603 : : max_num_virtio_queues);
604 [ # # ]: 0 : vdpa_attr->umems[0].a = MLX5_GET(virtio_emulation_cap, hcattr,
605 : : umem_1_buffer_param_a);
606 [ # # ]: 0 : vdpa_attr->umems[0].b = MLX5_GET(virtio_emulation_cap, hcattr,
607 : : umem_1_buffer_param_b);
608 [ # # ]: 0 : vdpa_attr->umems[1].a = MLX5_GET(virtio_emulation_cap, hcattr,
609 : : umem_2_buffer_param_a);
610 [ # # ]: 0 : vdpa_attr->umems[1].b = MLX5_GET(virtio_emulation_cap, hcattr,
611 : : umem_2_buffer_param_b);
612 [ # # ]: 0 : vdpa_attr->umems[2].a = MLX5_GET(virtio_emulation_cap, hcattr,
613 : : umem_3_buffer_param_a);
614 [ # # ]: 0 : vdpa_attr->umems[2].b = MLX5_GET(virtio_emulation_cap, hcattr,
615 : : umem_3_buffer_param_b);
616 : : }
617 : 0 : }
618 : :
619 : : /**
620 : : * Query match sample handle parameters.
621 : : *
622 : : * This command allows translating a field sample handle returned by either
623 : : * PARSE_GRAPH_FLOW_MATCH_SAMPLE or by GENEVE TLV OPTION object into values
624 : : * used for header modification or header matching/hashing.
625 : : *
626 : : * @param[in] ctx
627 : : * Context used to create either GENEVE TLV option or FLEX PARSE GRAPH object.
628 : : * @param[in] sample_field_id
629 : : * Field sample handle returned by either PARSE_GRAPH_FLOW_MATCH_SAMPLE
630 : : * or by GENEVE TLV OPTION object.
631 : : * @param[out] attr
632 : : * Pointer to match sample info attributes structure.
633 : : *
634 : : * @return
635 : : * 0 on success, a negative errno otherwise and rte_errno is set.
636 : : */
637 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_match_sample_info_query)
638 : : int
639 : 0 : mlx5_devx_cmd_match_sample_info_query(void *ctx, uint32_t sample_field_id,
640 : : struct mlx5_devx_match_sample_info_query_attr *attr)
641 : : {
642 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
643 : 0 : uint32_t out[MLX5_ST_SZ_DW(query_match_sample_info_out)] = {0};
644 : 0 : uint32_t in[MLX5_ST_SZ_DW(query_match_sample_info_in)] = {0};
645 : : int rc;
646 : :
647 : 0 : MLX5_SET(query_match_sample_info_in, in, opcode,
648 : : MLX5_CMD_OP_QUERY_MATCH_SAMPLE_INFO);
649 : 0 : MLX5_SET(query_match_sample_info_in, in, op_mod, 0);
650 : 0 : MLX5_SET(query_match_sample_info_in, in, sample_field_id,
651 : : sample_field_id);
652 : 0 : rc = mlx5_glue->devx_general_cmd(ctx, in, sizeof(in), out, sizeof(out));
653 [ # # # # : 0 : if (rc || MLX5_FW_STATUS(out)) {
# # # # ]
654 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "query match sample info",
655 : : "sample_field_id", sample_field_id);
656 [ # # ]: 0 : return MLX5_DEVX_ERR_RC(rc);
657 : : }
658 [ # # ]: 0 : attr->modify_field_id = MLX5_GET(query_match_sample_info_out, out,
659 : : modify_field_id);
660 [ # # ]: 0 : attr->sample_dw_data = MLX5_GET(query_match_sample_info_out, out,
661 : : field_format_select_dw);
662 [ # # ]: 0 : attr->sample_dw_ok_bit = MLX5_GET(query_match_sample_info_out, out,
663 : : ok_bit_format_select_dw);
664 [ # # ]: 0 : attr->sample_dw_ok_bit_offset = MLX5_GET(query_match_sample_info_out,
665 : : out, ok_bit_offset);
666 : 0 : return 0;
667 : : #else
668 : : (void)ctx;
669 : : (void)sample_field_id;
670 : : (void)attr;
671 : : return -ENOTSUP;
672 : : #endif
673 : : }
674 : :
675 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_query_parse_samples)
676 : : int
677 : 0 : mlx5_devx_cmd_query_parse_samples(struct mlx5_devx_obj *flex_obj,
678 : : uint32_t *ids,
679 : : uint32_t num, uint8_t *anchor)
680 : : {
681 : 0 : uint32_t in[MLX5_ST_SZ_DW(general_obj_in_cmd_hdr)] = {0};
682 : 0 : uint32_t out[MLX5_ST_SZ_DW(create_flex_parser_out)] = {0};
683 : : void *hdr = MLX5_ADDR_OF(create_flex_parser_out, in, hdr);
684 : : void *flex = MLX5_ADDR_OF(create_flex_parser_out, out, flex);
685 : : void *sample = MLX5_ADDR_OF(parse_graph_flex, flex, sample_table);
686 : : int ret;
687 : : uint32_t idx = 0;
688 : : uint32_t i;
689 : :
690 [ # # ]: 0 : if (num > MLX5_GRAPH_NODE_SAMPLE_NUM) {
691 : 0 : rte_errno = EINVAL;
692 : 0 : DRV_LOG(ERR, "Too many sample IDs to be fetched.");
693 : 0 : return -rte_errno;
694 : : }
695 : 0 : MLX5_SET(general_obj_in_cmd_hdr, hdr, opcode,
696 : : MLX5_CMD_OP_QUERY_GENERAL_OBJECT);
697 : 0 : MLX5_SET(general_obj_in_cmd_hdr, hdr, obj_type,
698 : : MLX5_GENERAL_OBJ_TYPE_FLEX_PARSE_GRAPH);
699 : 0 : MLX5_SET(general_obj_in_cmd_hdr, hdr, obj_id, flex_obj->id);
700 : 0 : ret = mlx5_glue->devx_obj_query(flex_obj->obj, in, sizeof(in),
701 : : out, sizeof(out));
702 [ # # ]: 0 : if (ret) {
703 : 0 : rte_errno = ret;
704 : 0 : DRV_LOG(ERR, "Failed to query sample IDs with object %p.",
705 : : (void *)flex_obj);
706 : 0 : return -rte_errno;
707 : : }
708 [ # # ]: 0 : if (anchor)
709 [ # # ]: 0 : *anchor = MLX5_GET(parse_graph_flex, flex, head_anchor_id);
710 [ # # ]: 0 : for (i = 0; i < MLX5_GRAPH_NODE_SAMPLE_NUM && idx < num; i++) {
711 : 0 : void *s_off = (void *)((char *)sample + i *
712 : : MLX5_ST_SZ_BYTES(parse_graph_flow_match_sample));
713 : : uint32_t en;
714 : :
715 [ # # ]: 0 : en = MLX5_GET(parse_graph_flow_match_sample, s_off,
716 : : flow_match_sample_en);
717 [ # # ]: 0 : if (!en)
718 : 0 : continue;
719 [ # # ]: 0 : ids[idx++] = MLX5_GET(parse_graph_flow_match_sample, s_off,
720 : : flow_match_sample_field_id);
721 : : }
722 [ # # ]: 0 : if (num != idx) {
723 : 0 : rte_errno = EINVAL;
724 : 0 : DRV_LOG(ERR, "Number of sample IDs are not as expected.");
725 : 0 : return -rte_errno;
726 : : }
727 : : return ret;
728 : : }
729 : :
730 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_create_flex_parser)
731 : : struct mlx5_devx_obj *
732 : 0 : mlx5_devx_cmd_create_flex_parser(void *ctx,
733 : : struct mlx5_devx_graph_node_attr *data)
734 : : {
735 : 0 : uint32_t in[MLX5_ST_SZ_DW(create_flex_parser_in)] = {0};
736 : 0 : uint32_t out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)] = {0};
737 : : void *hdr = MLX5_ADDR_OF(create_flex_parser_in, in, hdr);
738 : : void *flex = MLX5_ADDR_OF(create_flex_parser_in, in, flex);
739 : : void *sample = MLX5_ADDR_OF(parse_graph_flex, flex, sample_table);
740 : : void *in_arc = MLX5_ADDR_OF(parse_graph_flex, flex, input_arc);
741 : : void *out_arc = MLX5_ADDR_OF(parse_graph_flex, flex, output_arc);
742 : 0 : struct mlx5_devx_obj *parse_flex_obj = mlx5_malloc
743 : : (MLX5_MEM_ZERO, sizeof(*parse_flex_obj), 0, SOCKET_ID_ANY);
744 : : uint32_t i;
745 : :
746 [ # # ]: 0 : if (!parse_flex_obj) {
747 : 0 : DRV_LOG(ERR, "Failed to allocate flex parser data.");
748 : 0 : rte_errno = ENOMEM;
749 : 0 : return NULL;
750 : : }
751 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, hdr, opcode,
752 : : MLX5_CMD_OP_CREATE_GENERAL_OBJECT);
753 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, hdr, obj_type,
754 : : MLX5_GENERAL_OBJ_TYPE_FLEX_PARSE_GRAPH);
755 [ # # ]: 0 : MLX5_SET(parse_graph_flex, flex, header_length_mode,
756 : : data->header_length_mode);
757 [ # # ]: 0 : MLX5_SET64(parse_graph_flex, flex, modify_field_select,
758 : : data->modify_field_select);
759 [ # # ]: 0 : MLX5_SET(parse_graph_flex, flex, header_length_base_value,
760 : : data->header_length_base_value);
761 [ # # ]: 0 : MLX5_SET(parse_graph_flex, flex, header_length_field_offset,
762 : : data->header_length_field_offset);
763 [ # # ]: 0 : MLX5_SET(parse_graph_flex, flex, header_length_field_shift,
764 : : data->header_length_field_shift);
765 [ # # ]: 0 : MLX5_SET(parse_graph_flex, flex, next_header_field_offset,
766 : : data->next_header_field_offset);
767 [ # # ]: 0 : MLX5_SET(parse_graph_flex, flex, next_header_field_size,
768 : : data->next_header_field_size);
769 [ # # ]: 0 : MLX5_SET(parse_graph_flex, flex, header_length_field_mask,
770 : : data->header_length_field_mask);
771 [ # # ]: 0 : for (i = 0; i < MLX5_GRAPH_NODE_SAMPLE_NUM; i++) {
772 : : struct mlx5_devx_match_sample_attr *s = &data->sample[i];
773 : 0 : void *s_off = (void *)((char *)sample + i *
774 : : MLX5_ST_SZ_BYTES(parse_graph_flow_match_sample));
775 : :
776 [ # # ]: 0 : if (!s->flow_match_sample_en)
777 : 0 : continue;
778 [ # # ]: 0 : MLX5_SET(parse_graph_flow_match_sample, s_off,
779 : : flow_match_sample_en, !!s->flow_match_sample_en);
780 [ # # ]: 0 : MLX5_SET(parse_graph_flow_match_sample, s_off,
781 : : flow_match_sample_field_offset,
782 : : s->flow_match_sample_field_offset);
783 [ # # ]: 0 : MLX5_SET(parse_graph_flow_match_sample, s_off,
784 : : flow_match_sample_offset_mode,
785 : : s->flow_match_sample_offset_mode);
786 [ # # ]: 0 : MLX5_SET(parse_graph_flow_match_sample, s_off,
787 : : flow_match_sample_field_offset_mask,
788 : : s->flow_match_sample_field_offset_mask);
789 [ # # ]: 0 : MLX5_SET(parse_graph_flow_match_sample, s_off,
790 : : flow_match_sample_field_offset_shift,
791 : : s->flow_match_sample_field_offset_shift);
792 [ # # ]: 0 : MLX5_SET(parse_graph_flow_match_sample, s_off,
793 : : flow_match_sample_field_base_offset,
794 : : s->flow_match_sample_field_base_offset);
795 [ # # ]: 0 : MLX5_SET(parse_graph_flow_match_sample, s_off,
796 : : flow_match_sample_tunnel_mode,
797 : : s->flow_match_sample_tunnel_mode);
798 : : }
799 [ # # ]: 0 : for (i = 0; i < MLX5_GRAPH_NODE_ARC_NUM; i++) {
800 : : struct mlx5_devx_graph_arc_attr *ia = &data->in[i];
801 : : struct mlx5_devx_graph_arc_attr *oa = &data->out[i];
802 : 0 : void *in_off = (void *)((char *)in_arc + i *
803 : : MLX5_ST_SZ_BYTES(parse_graph_arc));
804 : 0 : void *out_off = (void *)((char *)out_arc + i *
805 : : MLX5_ST_SZ_BYTES(parse_graph_arc));
806 : :
807 [ # # ]: 0 : if (ia->arc_parse_graph_node != 0) {
808 [ # # ]: 0 : MLX5_SET(parse_graph_arc, in_off,
809 : : compare_condition_value,
810 : : ia->compare_condition_value);
811 [ # # ]: 0 : MLX5_SET(parse_graph_arc, in_off, start_inner_tunnel,
812 : : ia->start_inner_tunnel);
813 [ # # ]: 0 : MLX5_SET(parse_graph_arc, in_off, arc_parse_graph_node,
814 : : ia->arc_parse_graph_node);
815 [ # # ]: 0 : MLX5_SET(parse_graph_arc, in_off,
816 : : parse_graph_node_handle,
817 : : ia->parse_graph_node_handle);
818 : : }
819 [ # # ]: 0 : if (oa->arc_parse_graph_node != 0) {
820 [ # # ]: 0 : MLX5_SET(parse_graph_arc, out_off,
821 : : compare_condition_value,
822 : : oa->compare_condition_value);
823 [ # # ]: 0 : MLX5_SET(parse_graph_arc, out_off, start_inner_tunnel,
824 : : oa->start_inner_tunnel);
825 [ # # ]: 0 : MLX5_SET(parse_graph_arc, out_off, arc_parse_graph_node,
826 : : oa->arc_parse_graph_node);
827 [ # # ]: 0 : MLX5_SET(parse_graph_arc, out_off,
828 : : parse_graph_node_handle,
829 : : oa->parse_graph_node_handle);
830 : : }
831 : : }
832 : 0 : parse_flex_obj->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in),
833 : : out, sizeof(out));
834 [ # # ]: 0 : if (!parse_flex_obj->obj) {
835 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "create FLEX PARSE GRAPH", NULL, 0);
836 : 0 : mlx5_free(parse_flex_obj);
837 : 0 : return NULL;
838 : : }
839 [ # # ]: 0 : parse_flex_obj->id = MLX5_GET(general_obj_out_cmd_hdr, out, obj_id);
840 : 0 : return parse_flex_obj;
841 : : }
842 : :
843 : : static int
844 : 0 : mlx5_devx_cmd_query_hca_parse_graph_node_cap
845 : : (void *ctx, struct mlx5_hca_flex_attr *attr)
846 : : {
847 : : uint32_t in[MLX5_ST_SZ_DW(query_hca_cap_in)];
848 : : uint32_t out[MLX5_ST_SZ_DW(query_hca_cap_out)];
849 : : void *hcattr;
850 : : int rc;
851 : :
852 : 0 : hcattr = mlx5_devx_get_hca_cap(ctx, in, out, &rc,
853 : : MLX5_GET_HCA_CAP_OP_MOD_PARSE_GRAPH_NODE_CAP |
854 : : (uint32_t)MLX5_HCA_CAP_OPMOD_GET_CUR);
855 [ # # ]: 0 : if (!hcattr)
856 : 0 : return rc;
857 [ # # ]: 0 : attr->node_in = MLX5_GET(parse_graph_node_cap, hcattr, node_in);
858 [ # # ]: 0 : attr->node_out = MLX5_GET(parse_graph_node_cap, hcattr, node_out);
859 [ # # ]: 0 : attr->header_length_mode = MLX5_GET(parse_graph_node_cap, hcattr,
860 : : header_length_mode);
861 [ # # ]: 0 : attr->sample_offset_mode = MLX5_GET(parse_graph_node_cap, hcattr,
862 : : sample_offset_mode);
863 [ # # ]: 0 : attr->max_num_arc_in = MLX5_GET(parse_graph_node_cap, hcattr,
864 : : max_num_arc_in);
865 [ # # ]: 0 : attr->max_num_arc_out = MLX5_GET(parse_graph_node_cap, hcattr,
866 : : max_num_arc_out);
867 [ # # ]: 0 : attr->max_num_sample = MLX5_GET(parse_graph_node_cap, hcattr,
868 : : max_num_sample);
869 [ # # ]: 0 : attr->parse_graph_anchor = MLX5_GET(parse_graph_node_cap, hcattr, parse_graph_anchor);
870 [ # # ]: 0 : attr->sample_tunnel_inner2 = MLX5_GET(parse_graph_node_cap, hcattr,
871 : : sample_tunnel_inner2);
872 [ # # ]: 0 : attr->zero_size_supported = MLX5_GET(parse_graph_node_cap, hcattr,
873 : : zero_size_supported);
874 [ # # ]: 0 : attr->sample_id_in_out = MLX5_GET(parse_graph_node_cap, hcattr,
875 : : sample_id_in_out);
876 [ # # ]: 0 : attr->max_base_header_length = MLX5_GET(parse_graph_node_cap, hcattr,
877 : : max_base_header_length);
878 [ # # ]: 0 : attr->max_sample_base_offset = MLX5_GET(parse_graph_node_cap, hcattr,
879 : : max_sample_base_offset);
880 [ # # ]: 0 : attr->max_next_header_offset = MLX5_GET(parse_graph_node_cap, hcattr,
881 : : max_next_header_offset);
882 [ # # ]: 0 : attr->header_length_mask_width = MLX5_GET(parse_graph_node_cap, hcattr,
883 : : header_length_mask_width);
884 : : /* Get the max supported samples from HCA CAP 2 */
885 : 0 : hcattr = mlx5_devx_get_hca_cap(ctx, in, out, &rc,
886 : : MLX5_GET_HCA_CAP_OP_MOD_GENERAL_DEVICE_2 |
887 : : (uint32_t)MLX5_HCA_CAP_OPMOD_GET_CUR);
888 [ # # ]: 0 : if (!hcattr)
889 : 0 : return rc;
890 : 0 : attr->max_num_prog_sample =
891 [ # # ]: 0 : MLX5_GET(cmd_hca_cap_2, hcattr, max_num_prog_sample_field);
892 : 0 : return 0;
893 : : }
894 : :
895 : : static int
896 : 0 : mlx5_devx_query_pkt_integrity_match(void *hcattr)
897 : : {
898 [ # # ]: 0 : return MLX5_GET(flow_table_nic_cap, hcattr,
899 [ # # # # ]: 0 : ft_field_support_2_nic_receive.inner_l3_ok) &&
900 : : MLX5_GET(flow_table_nic_cap, hcattr,
901 [ # # # # ]: 0 : ft_field_support_2_nic_receive.inner_l4_ok) &&
902 : : MLX5_GET(flow_table_nic_cap, hcattr,
903 [ # # # # ]: 0 : ft_field_support_2_nic_receive.outer_l3_ok) &&
904 : : MLX5_GET(flow_table_nic_cap, hcattr,
905 [ # # # # ]: 0 : ft_field_support_2_nic_receive.outer_l4_ok) &&
906 : : MLX5_GET(flow_table_nic_cap, hcattr,
907 : : ft_field_support_2_nic_receive
908 [ # # # # ]: 0 : .inner_ipv4_checksum_ok) &&
909 : : MLX5_GET(flow_table_nic_cap, hcattr,
910 [ # # # # ]: 0 : ft_field_support_2_nic_receive.inner_l4_checksum_ok) &&
911 : : MLX5_GET(flow_table_nic_cap, hcattr,
912 : : ft_field_support_2_nic_receive
913 [ # # # # : 0 : .outer_ipv4_checksum_ok) &&
# # # # #
# # # # #
# # # # ]
914 [ # # # # ]: 0 : MLX5_GET(flow_table_nic_cap, hcattr,
915 : : ft_field_support_2_nic_receive.outer_l4_checksum_ok);
916 : : }
917 : :
918 : : /**
919 : : * Query HCA attributes.
920 : : * Using those attributes we can check on run time if the device
921 : : * is having the required capabilities.
922 : : *
923 : : * @param[in] ctx
924 : : * Context returned from mlx5 open_device() glue function.
925 : : * @param[out] attr
926 : : * Attributes device values.
927 : : *
928 : : * @return
929 : : * 0 on success, a negative value otherwise.
930 : : */
931 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_query_hca_attr)
932 : : int
933 : 0 : mlx5_devx_cmd_query_hca_attr(void *ctx,
934 : : struct mlx5_hca_attr *attr)
935 : : {
936 : 0 : uint32_t in[MLX5_ST_SZ_DW(query_hca_cap_in)] = {0};
937 : 0 : uint32_t out[MLX5_ST_SZ_DW(query_hca_cap_out)] = {0};
938 : : bool hca_cap_2_sup;
939 : : uint64_t general_obj_types_supported = 0;
940 : : uint64_t stc_action_type_127_64;
941 : : void *hcattr;
942 : : int rc, i;
943 : :
944 : 0 : hcattr = mlx5_devx_get_hca_cap(ctx, in, out, &rc,
945 : : MLX5_GET_HCA_CAP_OP_MOD_GENERAL_DEVICE |
946 : : (uint32_t)MLX5_HCA_CAP_OPMOD_GET_CUR);
947 [ # # ]: 0 : if (!hcattr)
948 : 0 : return rc;
949 [ # # ]: 0 : hca_cap_2_sup = MLX5_GET(cmd_hca_cap, hcattr, hca_cap_2);
950 [ # # ]: 0 : attr->max_wqe_sz_sq = MLX5_GET(cmd_hca_cap, hcattr, max_wqe_sz_sq);
951 : 0 : attr->flow_counter_bulk_alloc_bitmap =
952 [ # # ]: 0 : MLX5_GET(cmd_hca_cap, hcattr, flow_counter_bulk_alloc);
953 [ # # ]: 0 : attr->flow_counters_dump = MLX5_GET(cmd_hca_cap, hcattr,
954 : : flow_counters_dump);
955 [ # # ]: 0 : attr->log_max_rmp = MLX5_GET(cmd_hca_cap, hcattr, log_max_rmp);
956 [ # # ]: 0 : attr->mem_rq_rmp = MLX5_GET(cmd_hca_cap, hcattr, mem_rq_rmp);
957 [ # # ]: 0 : attr->log_max_rqt_size = MLX5_GET(cmd_hca_cap, hcattr,
958 : : log_max_rqt_size);
959 [ # # ]: 0 : attr->eswitch_manager = MLX5_GET(cmd_hca_cap, hcattr, eswitch_manager);
960 [ # # ]: 0 : attr->hairpin = MLX5_GET(cmd_hca_cap, hcattr, hairpin);
961 [ # # ]: 0 : attr->log_max_hairpin_queues = MLX5_GET(cmd_hca_cap, hcattr,
962 : : log_max_hairpin_queues);
963 [ # # ]: 0 : attr->log_max_hairpin_wq_data_sz = MLX5_GET(cmd_hca_cap, hcattr,
964 : : log_max_hairpin_wq_data_sz);
965 [ # # ]: 0 : attr->log_max_hairpin_num_packets = MLX5_GET
966 : : (cmd_hca_cap, hcattr, log_min_hairpin_wq_data_sz);
967 [ # # ]: 0 : attr->vhca_id = MLX5_GET(cmd_hca_cap, hcattr, vhca_id);
968 [ # # ]: 0 : attr->relaxed_ordering_write = MLX5_GET(cmd_hca_cap, hcattr,
969 : : relaxed_ordering_write);
970 [ # # ]: 0 : attr->relaxed_ordering_read = MLX5_GET(cmd_hca_cap, hcattr,
971 : : relaxed_ordering_read);
972 [ # # ]: 0 : attr->access_register_user = MLX5_GET(cmd_hca_cap, hcattr,
973 : : access_register_user);
974 [ # # ]: 0 : attr->eth_net_offloads = MLX5_GET(cmd_hca_cap, hcattr,
975 : : eth_net_offloads);
976 [ # # ]: 0 : attr->eth_virt = MLX5_GET(cmd_hca_cap, hcattr, eth_virt);
977 [ # # ]: 0 : attr->flex_parser_protocols = MLX5_GET(cmd_hca_cap, hcattr,
978 : : flex_parser_protocols);
979 [ # # ]: 0 : attr->max_geneve_tlv_options = MLX5_GET(cmd_hca_cap, hcattr,
980 : : max_geneve_tlv_options);
981 [ # # ]: 0 : attr->max_geneve_tlv_option_data_len = MLX5_GET(cmd_hca_cap, hcattr,
982 : : max_geneve_tlv_option_data_len);
983 [ # # ]: 0 : attr->geneve_tlv_option_offset = MLX5_GET(cmd_hca_cap, hcattr,
984 : : geneve_tlv_option_offset);
985 [ # # ]: 0 : attr->geneve_tlv_sample = MLX5_GET(cmd_hca_cap, hcattr,
986 : : geneve_tlv_sample);
987 [ # # ]: 0 : attr->query_match_sample_info = MLX5_GET(cmd_hca_cap, hcattr,
988 : : query_match_sample_info);
989 [ # # ]: 0 : attr->geneve_tlv_option_sample_id = MLX5_GET(cmd_hca_cap, hcattr,
990 : : flex_parser_id_geneve_opt_0);
991 [ # # ]: 0 : attr->qos.sup = MLX5_GET(cmd_hca_cap, hcattr, qos);
992 [ # # ]: 0 : attr->wqe_index_ignore = MLX5_GET(cmd_hca_cap, hcattr,
993 : : wqe_index_ignore_cap);
994 [ # # ]: 0 : attr->cross_channel = MLX5_GET(cmd_hca_cap, hcattr, cd);
995 [ # # ]: 0 : attr->non_wire_sq = MLX5_GET(cmd_hca_cap, hcattr, non_wire_sq);
996 [ # # ]: 0 : attr->log_max_static_sq_wq = MLX5_GET(cmd_hca_cap, hcattr,
997 : : log_max_static_sq_wq);
998 [ # # ]: 0 : attr->num_lag_ports = MLX5_GET(cmd_hca_cap, hcattr, num_lag_ports);
999 [ # # ]: 0 : attr->dev_freq_khz = MLX5_GET(cmd_hca_cap, hcattr,
1000 : : device_frequency_khz);
1001 : 0 : attr->scatter_fcs_w_decap_disable =
1002 [ # # ]: 0 : MLX5_GET(cmd_hca_cap, hcattr, scatter_fcs_w_decap_disable);
1003 [ # # ]: 0 : attr->roce = MLX5_GET(cmd_hca_cap, hcattr, roce);
1004 [ # # ]: 0 : attr->rq_ts_format = MLX5_GET(cmd_hca_cap, hcattr, rq_ts_format);
1005 [ # # ]: 0 : attr->sq_ts_format = MLX5_GET(cmd_hca_cap, hcattr, sq_ts_format);
1006 : 0 : attr->steering_format_version =
1007 [ # # ]: 0 : MLX5_GET(cmd_hca_cap, hcattr, steering_format_version);
1008 [ # # ]: 0 : attr->regexp_params = MLX5_GET(cmd_hca_cap, hcattr, regexp_params);
1009 [ # # ]: 0 : attr->regexp_version = MLX5_GET(cmd_hca_cap, hcattr, regexp_version);
1010 [ # # ]: 0 : attr->regexp_num_of_engines = MLX5_GET(cmd_hca_cap, hcattr,
1011 : : regexp_num_of_engines);
1012 : : /* Read the general_obj_types bitmap and extract the relevant bits. */
1013 [ # # ]: 0 : general_obj_types_supported = MLX5_GET64(cmd_hca_cap, hcattr,
1014 : : general_obj_types);
1015 : 0 : attr->qos.flow_meter_aso_sup =
1016 : 0 : !!(general_obj_types_supported &
1017 : : MLX5_GENERAL_OBJ_TYPES_CAP_FLOW_METER_ASO);
1018 : 0 : attr->vdpa.valid = !!(general_obj_types_supported &
1019 : : MLX5_GENERAL_OBJ_TYPES_CAP_VIRTQ_NET_Q);
1020 : 0 : attr->vdpa.queue_counters_valid =
1021 : 0 : !!(general_obj_types_supported &
1022 : : MLX5_GENERAL_OBJ_TYPES_CAP_VIRTIO_Q_COUNTERS);
1023 : 0 : attr->parse_graph_flex_node =
1024 : 0 : !!(general_obj_types_supported &
1025 : : MLX5_GENERAL_OBJ_TYPES_CAP_PARSE_GRAPH_FLEX_NODE);
1026 : 0 : attr->flow_hit_aso = !!(general_obj_types_supported &
1027 : : MLX5_GENERAL_OBJ_TYPES_CAP_FLOW_HIT_ASO);
1028 : 0 : attr->geneve_tlv_opt = !!(general_obj_types_supported &
1029 : : MLX5_GENERAL_OBJ_TYPES_CAP_GENEVE_TLV_OPT);
1030 : 0 : attr->dek = !!(general_obj_types_supported &
1031 : : MLX5_GENERAL_OBJ_TYPES_CAP_DEK);
1032 : 0 : attr->import_kek = !!(general_obj_types_supported &
1033 : : MLX5_GENERAL_OBJ_TYPES_CAP_IMPORT_KEK);
1034 : 0 : attr->credential = !!(general_obj_types_supported &
1035 : : MLX5_GENERAL_OBJ_TYPES_CAP_CREDENTIAL);
1036 : 0 : attr->crypto_login = !!(general_obj_types_supported &
1037 : : MLX5_GENERAL_OBJ_TYPES_CAP_CRYPTO_LOGIN);
1038 : : /* Add reading of other GENERAL_OBJ_TYPES_CAP bits above this line. */
1039 [ # # ]: 0 : attr->log_max_cq = MLX5_GET(cmd_hca_cap, hcattr, log_max_cq);
1040 [ # # ]: 0 : attr->log_max_qp = MLX5_GET(cmd_hca_cap, hcattr, log_max_qp);
1041 [ # # ]: 0 : attr->log_max_cq_sz = MLX5_GET(cmd_hca_cap, hcattr, log_max_cq_sz);
1042 [ # # ]: 0 : attr->log_max_qp_sz = MLX5_GET(cmd_hca_cap, hcattr, log_max_qp_sz);
1043 [ # # ]: 0 : attr->log_max_wq_sz = MLX5_GET(cmd_hca_cap, hcattr, log_max_wq_sz);
1044 [ # # ]: 0 : attr->log_max_mrw_sz = MLX5_GET(cmd_hca_cap, hcattr, log_max_mrw_sz);
1045 [ # # ]: 0 : attr->log_max_pd = MLX5_GET(cmd_hca_cap, hcattr, log_max_pd);
1046 [ # # ]: 0 : attr->log_max_srq = MLX5_GET(cmd_hca_cap, hcattr, log_max_srq);
1047 [ # # ]: 0 : attr->log_max_srq_sz = MLX5_GET(cmd_hca_cap, hcattr, log_max_srq_sz);
1048 : 0 : attr->reg_c_preserve =
1049 [ # # ]: 0 : MLX5_GET(cmd_hca_cap, hcattr, reg_c_preserve);
1050 [ # # ]: 0 : attr->mmo_regex_qp_en = MLX5_GET(cmd_hca_cap, hcattr, regexp_mmo_qp);
1051 [ # # ]: 0 : attr->mmo_regex_sq_en = MLX5_GET(cmd_hca_cap, hcattr, regexp_mmo_sq);
1052 [ # # ]: 0 : attr->mmo_dma_sq_en = MLX5_GET(cmd_hca_cap, hcattr, dma_mmo_sq);
1053 [ # # ]: 0 : attr->mmo_compress_sq_en = MLX5_GET(cmd_hca_cap, hcattr,
1054 : : compress_mmo_sq);
1055 [ # # ]: 0 : attr->mmo_decompress_sq_en = MLX5_GET(cmd_hca_cap, hcattr,
1056 : : decompress_mmo_sq);
1057 [ # # ]: 0 : attr->mmo_dma_qp_en = MLX5_GET(cmd_hca_cap, hcattr, dma_mmo_qp);
1058 [ # # ]: 0 : attr->mmo_compress_qp_en = MLX5_GET(cmd_hca_cap, hcattr,
1059 : : compress_mmo_qp);
1060 [ # # ]: 0 : attr->decomp_deflate_v1_en = MLX5_GET(cmd_hca_cap, hcattr,
1061 : : decompress_deflate_v1);
1062 [ # # ]: 0 : attr->decomp_deflate_v2_en = MLX5_GET(cmd_hca_cap, hcattr,
1063 : : decompress_deflate_v2);
1064 [ # # ]: 0 : attr->compress_min_block_size = MLX5_GET(cmd_hca_cap, hcattr,
1065 : : compress_min_block_size);
1066 [ # # ]: 0 : attr->log_max_mmo_dma = MLX5_GET(cmd_hca_cap, hcattr, log_dma_mmo_size);
1067 [ # # ]: 0 : attr->log_max_mmo_compress = MLX5_GET(cmd_hca_cap, hcattr,
1068 : : log_compress_mmo_size);
1069 [ # # ]: 0 : attr->log_max_mmo_decompress = MLX5_GET(cmd_hca_cap, hcattr,
1070 : : log_decompress_mmo_size);
1071 [ # # ]: 0 : attr->decomp_lz4_data_only_en = MLX5_GET(cmd_hca_cap, hcattr,
1072 : : decompress_lz4_data_only_v2);
1073 [ # # ]: 0 : attr->decomp_lz4_no_checksum_en = MLX5_GET(cmd_hca_cap, hcattr,
1074 : : decompress_lz4_no_checksum_v2);
1075 [ # # ]: 0 : attr->decomp_lz4_checksum_en = MLX5_GET(cmd_hca_cap, hcattr,
1076 : : decompress_lz4_checksum_v2);
1077 [ # # ]: 0 : attr->cqe_compression = MLX5_GET(cmd_hca_cap, hcattr, cqe_compression);
1078 [ # # ]: 0 : attr->mini_cqe_resp_flow_tag = MLX5_GET(cmd_hca_cap, hcattr,
1079 : : mini_cqe_resp_flow_tag);
1080 [ # # ]: 0 : attr->cqe_compression_128 = MLX5_GET(cmd_hca_cap, hcattr,
1081 : : cqe_compression_128);
1082 [ # # ]: 0 : attr->mini_cqe_resp_l3_l4_tag = MLX5_GET(cmd_hca_cap, hcattr,
1083 : : mini_cqe_resp_l3_l4_tag);
1084 [ # # ]: 0 : attr->enhanced_cqe_compression = MLX5_GET(cmd_hca_cap, hcattr,
1085 : : enhanced_cqe_compression);
1086 : 0 : attr->umr_indirect_mkey_disabled =
1087 [ # # ]: 0 : MLX5_GET(cmd_hca_cap, hcattr, umr_indirect_mkey_disabled);
1088 : 0 : attr->umr_modify_entity_size_disabled =
1089 [ # # ]: 0 : MLX5_GET(cmd_hca_cap, hcattr, umr_modify_entity_size_disabled);
1090 [ # # ]: 0 : attr->wait_on_time = MLX5_GET(cmd_hca_cap, hcattr, wait_on_time);
1091 [ # # ]: 0 : attr->crypto = MLX5_GET(cmd_hca_cap, hcattr, crypto);
1092 : 0 : attr->ct_offload = !!(general_obj_types_supported &
1093 : : MLX5_GENERAL_OBJ_TYPES_CAP_CONN_TRACK_OFFLOAD);
1094 [ # # ]: 0 : attr->rq_delay_drop = MLX5_GET(cmd_hca_cap, hcattr, rq_delay_drop);
1095 [ # # ]: 0 : attr->nic_flow_table = MLX5_GET(cmd_hca_cap, hcattr, nic_flow_table);
1096 [ # # ]: 0 : attr->striding_rq = MLX5_GET(cmd_hca_cap, hcattr, striding_rq);
1097 : 0 : attr->ext_stride_num_range =
1098 [ # # ]: 0 : MLX5_GET(cmd_hca_cap, hcattr, ext_stride_num_range);
1099 [ # # ]: 0 : attr->nic_flow_table = MLX5_GET(cmd_hca_cap, hcattr, nic_flow_table);
1100 [ # # ]: 0 : attr->max_flow_counter_15_0 = MLX5_GET(cmd_hca_cap, hcattr,
1101 : : max_flow_counter_15_0);
1102 [ # # ]: 0 : attr->max_flow_counter_31_16 = MLX5_GET(cmd_hca_cap, hcattr,
1103 : : max_flow_counter_31_16);
1104 [ # # ]: 0 : attr->alloc_flow_counter_pd = MLX5_GET(cmd_hca_cap, hcattr,
1105 : : alloc_flow_counter_pd);
1106 [ # # ]: 0 : attr->flow_counter_access_aso = MLX5_GET(cmd_hca_cap, hcattr,
1107 : : flow_counter_access_aso);
1108 [ # # ]: 0 : attr->flow_access_aso_opc_mod = MLX5_GET(cmd_hca_cap, hcattr,
1109 : : flow_access_aso_opc_mod);
1110 [ # # ]: 0 : attr->wqe_based_flow_table_sup = MLX5_GET(cmd_hca_cap, hcattr,
1111 : : wqe_based_flow_table_update_cap);
1112 : : /*
1113 : : * Flex item support needs max_num_prog_sample_field
1114 : : * from the Capabilities 2 table for PARSE_GRAPH_NODE
1115 : : */
1116 [ # # ]: 0 : if (attr->parse_graph_flex_node) {
1117 : 0 : rc = mlx5_devx_cmd_query_hca_parse_graph_node_cap
1118 : : (ctx, &attr->flex);
1119 [ # # ]: 0 : if (rc)
1120 : : return -1;
1121 : 0 : attr->flex.query_match_sample_info =
1122 : 0 : attr->query_match_sample_info;
1123 : : }
1124 [ # # ]: 0 : if (attr->crypto) {
1125 [ # # # # : 0 : attr->aes_xts = MLX5_GET(cmd_hca_cap, hcattr, aes_xts) ||
# # ]
1126 [ # # # # : 0 : MLX5_GET(cmd_hca_cap, hcattr, aes_xts_multi_block_be_tweak) ||
# # # # #
# # # ]
1127 : : MLX5_GET(cmd_hca_cap, hcattr, aes_xts_single_block_le_tweak);
1128 : 0 : hcattr = mlx5_devx_get_hca_cap(ctx, in, out, &rc,
1129 : : MLX5_GET_HCA_CAP_OP_MOD_CRYPTO |
1130 : : (uint32_t)MLX5_HCA_CAP_OPMOD_GET_CUR);
1131 [ # # ]: 0 : if (!hcattr)
1132 : : return -1;
1133 [ # # ]: 0 : attr->crypto_wrapped_import_method = !!(MLX5_GET(crypto_caps,
1134 : : hcattr, wrapped_import_method)
1135 : 0 : & 1 << 2);
1136 [ # # ]: 0 : attr->crypto_mmo.crypto_mmo_qp = MLX5_GET(crypto_caps, hcattr, crypto_mmo_qp);
1137 : 0 : attr->crypto_mmo.gcm_256_encrypt =
1138 [ # # ]: 0 : MLX5_GET(crypto_caps, hcattr, crypto_aes_gcm_256_encrypt);
1139 : 0 : attr->crypto_mmo.gcm_128_encrypt =
1140 [ # # ]: 0 : MLX5_GET(crypto_caps, hcattr, crypto_aes_gcm_128_encrypt);
1141 : 0 : attr->crypto_mmo.gcm_256_decrypt =
1142 [ # # ]: 0 : MLX5_GET(crypto_caps, hcattr, crypto_aes_gcm_256_decrypt);
1143 : 0 : attr->crypto_mmo.gcm_128_decrypt =
1144 [ # # ]: 0 : MLX5_GET(crypto_caps, hcattr, crypto_aes_gcm_128_decrypt);
1145 : 0 : attr->crypto_mmo.gcm_auth_tag_128 =
1146 [ # # ]: 0 : MLX5_GET(crypto_caps, hcattr, gcm_auth_tag_128);
1147 : 0 : attr->crypto_mmo.gcm_auth_tag_96 =
1148 [ # # ]: 0 : MLX5_GET(crypto_caps, hcattr, gcm_auth_tag_96);
1149 : 0 : attr->crypto_mmo.log_crypto_mmo_max_size =
1150 [ # # ]: 0 : MLX5_GET(crypto_caps, hcattr, log_crypto_mmo_max_size);
1151 : : }
1152 [ # # ]: 0 : if (hca_cap_2_sup) {
1153 : 0 : hcattr = mlx5_devx_get_hca_cap(ctx, in, out, &rc,
1154 : : MLX5_GET_HCA_CAP_OP_MOD_GENERAL_DEVICE_2 |
1155 : : (uint32_t)MLX5_HCA_CAP_OPMOD_GET_CUR);
1156 [ # # ]: 0 : if (!hcattr) {
1157 : 0 : DRV_LOG(DEBUG,
1158 : : "Failed to query DevX HCA capabilities 2.");
1159 : 0 : return rc;
1160 : : }
1161 [ # # ]: 0 : attr->log_min_stride_wqe_sz = MLX5_GET(cmd_hca_cap_2, hcattr,
1162 : : log_min_stride_wqe_sz);
1163 [ # # ]: 0 : attr->hairpin_sq_wqe_bb_size = MLX5_GET(cmd_hca_cap_2, hcattr,
1164 : : hairpin_sq_wqe_bb_size);
1165 [ # # ]: 0 : attr->hairpin_sq_wq_in_host_mem = MLX5_GET(cmd_hca_cap_2, hcattr,
1166 : : hairpin_sq_wq_in_host_mem);
1167 [ # # ]: 0 : attr->hairpin_data_buffer_locked = MLX5_GET(cmd_hca_cap_2, hcattr,
1168 : : hairpin_data_buffer_locked);
1169 [ # # ]: 0 : attr->flow_counter_bulk_log_max_alloc = MLX5_GET(cmd_hca_cap_2,
1170 : : hcattr, flow_counter_bulk_log_max_alloc);
1171 : 0 : attr->flow_counter_bulk_log_granularity =
1172 [ # # ]: 0 : MLX5_GET(cmd_hca_cap_2, hcattr,
1173 : : flow_counter_bulk_log_granularity);
1174 [ # # ]: 0 : rc = MLX5_GET(cmd_hca_cap_2, hcattr,
1175 : : cross_vhca_object_to_object_supported);
1176 : 0 : attr->cross_vhca =
1177 : : (rc & MLX5_CROSS_VHCA_OBJ_TO_OBJ_TYPE_STC_TO_TIR) &&
1178 : : (rc & MLX5_CROSS_VHCA_OBJ_TO_OBJ_TYPE_STC_TO_FT) &&
1179 : 0 : (rc & MLX5_CROSS_VHCA_OBJ_TO_OBJ_TYPE_FT_TO_FT) &&
1180 : : (rc & MLX5_CROSS_VHCA_OBJ_TO_OBJ_TYPE_FT_TO_RTC);
1181 [ # # ]: 0 : rc = MLX5_GET(cmd_hca_cap_2, hcattr,
1182 : : allowed_object_for_other_vhca_access);
1183 : 0 : attr->cross_vhca = attr->cross_vhca &&
1184 : : (rc & MLX5_CROSS_VHCA_ALLOWED_OBJS_TIR) &&
1185 [ # # # # ]: 0 : (rc & MLX5_CROSS_VHCA_ALLOWED_OBJS_FT) &&
1186 : : (rc & MLX5_CROSS_VHCA_ALLOWED_OBJS_RTC);
1187 [ # # ]: 0 : if (attr->ct_offload)
1188 [ # # ]: 0 : attr->log_max_conn_track_offload = MLX5_GET(cmd_hca_cap_2, hcattr,
1189 : : log_max_conn_track_offload);
1190 : : }
1191 [ # # ]: 0 : if (attr->log_min_stride_wqe_sz == 0)
1192 : 0 : attr->log_min_stride_wqe_sz = MLX5_MPRQ_LOG_MIN_STRIDE_WQE_SIZE;
1193 [ # # ]: 0 : if (attr->qos.sup) {
1194 : 0 : hcattr = mlx5_devx_get_hca_cap(ctx, in, out, &rc,
1195 : : MLX5_GET_HCA_CAP_OP_MOD_QOS_CAP |
1196 : : (uint32_t)MLX5_HCA_CAP_OPMOD_GET_CUR);
1197 [ # # ]: 0 : if (!hcattr) {
1198 : 0 : DRV_LOG(DEBUG, "Failed to query devx QOS capabilities");
1199 : 0 : return rc;
1200 : : }
1201 : 0 : attr->qos.flow_meter_old =
1202 [ # # ]: 0 : MLX5_GET(qos_cap, hcattr, flow_meter_old);
1203 [ # # ]: 0 : attr->qos.log_max_flow_meter =
1204 : 0 : MLX5_GET(qos_cap, hcattr, log_max_flow_meter);
1205 [ # # ]: 0 : attr->qos.flow_meter_reg_c_ids =
1206 : : MLX5_GET(qos_cap, hcattr, flow_meter_reg_id);
1207 : 0 : attr->qos.flow_meter =
1208 [ # # ]: 0 : MLX5_GET(qos_cap, hcattr, flow_meter);
1209 : 0 : attr->qos.packet_pacing =
1210 [ # # ]: 0 : MLX5_GET(qos_cap, hcattr, packet_pacing);
1211 : 0 : attr->qos.wqe_rate_pp =
1212 [ # # ]: 0 : MLX5_GET(qos_cap, hcattr, wqe_rate_pp);
1213 [ # # ]: 0 : if (attr->qos.flow_meter_aso_sup) {
1214 : 0 : attr->qos.log_meter_aso_granularity =
1215 [ # # ]: 0 : MLX5_GET(qos_cap, hcattr,
1216 : : log_meter_aso_granularity);
1217 : 0 : attr->qos.log_meter_aso_max_alloc =
1218 [ # # ]: 0 : MLX5_GET(qos_cap, hcattr,
1219 : : log_meter_aso_max_alloc);
1220 : 0 : attr->qos.log_max_num_meter_aso =
1221 [ # # ]: 0 : MLX5_GET(qos_cap, hcattr,
1222 : : log_max_num_meter_aso);
1223 : : }
1224 : : }
1225 [ # # ]: 0 : if (attr->vdpa.valid)
1226 : 0 : mlx5_devx_cmd_query_hca_vdpa_attr(ctx, &attr->vdpa);
1227 [ # # ]: 0 : if (!attr->eth_net_offloads)
1228 : : return 0;
1229 : : /* Query Flow Sampler Capability From FLow Table Properties Layout. */
1230 : 0 : hcattr = mlx5_devx_get_hca_cap(ctx, in, out, &rc,
1231 : : MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE |
1232 : : (uint32_t)MLX5_HCA_CAP_OPMOD_GET_CUR);
1233 [ # # ]: 0 : if (!hcattr) {
1234 : 0 : attr->log_max_ft_sampler_num = 0;
1235 : 0 : return rc;
1236 : : }
1237 [ # # ]: 0 : attr->log_max_ft_sampler_num = MLX5_GET
1238 : : (flow_table_nic_cap, hcattr,
1239 : : flow_table_properties_nic_receive.log_max_ft_sampler_num);
1240 [ # # ]: 0 : attr->flow.tunnel_header_0_1 = MLX5_GET
1241 : : (flow_table_nic_cap, hcattr,
1242 : : ft_field_support_2_nic_receive.tunnel_header_0_1);
1243 [ # # ]: 0 : attr->flow.tunnel_header_2_3 = MLX5_GET
1244 : : (flow_table_nic_cap, hcattr,
1245 : : ft_field_support_2_nic_receive.tunnel_header_2_3);
1246 [ # # ]: 0 : attr->modify_outer_ip_ecn = MLX5_GET
1247 : : (flow_table_nic_cap, hcattr,
1248 : : ft_header_modify_nic_receive.outer_ip_ecn);
1249 [ # # ]: 0 : attr->modify_outer_ipv6_traffic_class = MLX5_GET
1250 : : (flow_table_nic_cap, hcattr,
1251 : : ft_header_modify_nic_receive.outer_ipv6_traffic_class);
1252 : 0 : attr->set_reg_c = 0xffff;
1253 [ # # ]: 0 : if (attr->nic_flow_table) {
1254 : : #define GET_RX_REG_X_BITS \
1255 : : MLX5_GET(flow_table_nic_cap, hcattr, \
1256 : : ft_header_modify_nic_receive.metadata_reg_c_x)
1257 : : #define GET_TX_REG_X_BITS \
1258 : : MLX5_GET(flow_table_nic_cap, hcattr, \
1259 : : ft_header_modify_nic_transmit.metadata_reg_c_x)
1260 : :
1261 : : uint32_t tx_reg, rx_reg, reg_c_8_15;
1262 : :
1263 [ # # ]: 0 : tx_reg = GET_TX_REG_X_BITS;
1264 [ # # ]: 0 : reg_c_8_15 = MLX5_GET(flow_table_nic_cap, hcattr,
1265 : : ft_field_support_2_nic_transmit.metadata_reg_c_8_15);
1266 : 0 : tx_reg |= ((0xff & reg_c_8_15) << 8);
1267 [ # # ]: 0 : rx_reg = GET_RX_REG_X_BITS;
1268 [ # # ]: 0 : reg_c_8_15 = MLX5_GET(flow_table_nic_cap, hcattr,
1269 : : ft_field_support_2_nic_receive.metadata_reg_c_8_15);
1270 : 0 : rx_reg |= ((0xff & reg_c_8_15) << 8);
1271 : 0 : attr->set_reg_c &= (rx_reg & tx_reg);
1272 : :
1273 : : #undef GET_RX_REG_X_BITS
1274 : : #undef GET_TX_REG_X_BITS
1275 : : }
1276 : 0 : attr->pkt_integrity_match = mlx5_devx_query_pkt_integrity_match(hcattr);
1277 [ # # ]: 0 : attr->inner_ipv4_ihl = MLX5_GET
1278 : : (flow_table_nic_cap, hcattr,
1279 : : ft_field_support_2_nic_receive.inner_ipv4_ihl);
1280 [ # # ]: 0 : attr->outer_ipv4_ihl = MLX5_GET
1281 : : (flow_table_nic_cap, hcattr,
1282 : : ft_field_support_2_nic_receive.outer_ipv4_ihl);
1283 [ # # ]: 0 : attr->lag_rx_port_affinity = MLX5_GET
1284 : : (flow_table_nic_cap, hcattr,
1285 : : ft_field_support_2_nic_receive.lag_rx_port_affinity);
1286 : : /* Query HCA offloads for Ethernet protocol. */
1287 : 0 : hcattr = mlx5_devx_get_hca_cap(ctx, in, out, &rc,
1288 : : MLX5_GET_HCA_CAP_OP_MOD_ETHERNET_OFFLOAD_CAPS |
1289 : : (uint32_t)MLX5_HCA_CAP_OPMOD_GET_CUR);
1290 [ # # ]: 0 : if (!hcattr) {
1291 : 0 : attr->eth_net_offloads = 0;
1292 : 0 : return rc;
1293 : : }
1294 [ # # ]: 0 : attr->wqe_vlan_insert = MLX5_GET(per_protocol_networking_offload_caps,
1295 : : hcattr, wqe_vlan_insert);
1296 [ # # ]: 0 : attr->csum_cap = MLX5_GET(per_protocol_networking_offload_caps,
1297 : : hcattr, csum_cap);
1298 [ # # ]: 0 : attr->vlan_cap = MLX5_GET(per_protocol_networking_offload_caps,
1299 : : hcattr, vlan_cap);
1300 [ # # ]: 0 : attr->lro_cap = MLX5_GET(per_protocol_networking_offload_caps, hcattr,
1301 : : lro_cap);
1302 [ # # ]: 0 : attr->max_lso_cap = MLX5_GET(per_protocol_networking_offload_caps,
1303 : : hcattr, max_lso_cap);
1304 [ # # ]: 0 : attr->scatter_fcs = MLX5_GET(per_protocol_networking_offload_caps,
1305 : : hcattr, scatter_fcs);
1306 [ # # ]: 0 : attr->tunnel_lro_gre = MLX5_GET(per_protocol_networking_offload_caps,
1307 : : hcattr, tunnel_lro_gre);
1308 [ # # ]: 0 : attr->tunnel_lro_vxlan = MLX5_GET(per_protocol_networking_offload_caps,
1309 : : hcattr, tunnel_lro_vxlan);
1310 [ # # ]: 0 : attr->swp = MLX5_GET(per_protocol_networking_offload_caps,
1311 : : hcattr, swp);
1312 : 0 : attr->tunnel_stateless_gre =
1313 [ # # ]: 0 : MLX5_GET(per_protocol_networking_offload_caps,
1314 : : hcattr, tunnel_stateless_gre);
1315 : 0 : attr->tunnel_stateless_vxlan =
1316 [ # # ]: 0 : MLX5_GET(per_protocol_networking_offload_caps,
1317 : : hcattr, tunnel_stateless_vxlan);
1318 [ # # ]: 0 : attr->swp_csum = MLX5_GET(per_protocol_networking_offload_caps,
1319 : : hcattr, swp_csum);
1320 [ # # ]: 0 : attr->swp_lso = MLX5_GET(per_protocol_networking_offload_caps,
1321 : : hcattr, swp_lso);
1322 [ # # ]: 0 : attr->lro_max_msg_sz_mode = MLX5_GET
1323 : : (per_protocol_networking_offload_caps,
1324 : : hcattr, lro_max_msg_sz_mode);
1325 [ # # ]: 0 : for (i = 0 ; i < MLX5_LRO_NUM_SUPP_PERIODS ; i++) {
1326 : 0 : attr->lro_timer_supported_periods[i] =
1327 [ # # ]: 0 : MLX5_GET(per_protocol_networking_offload_caps, hcattr,
1328 : : lro_timer_supported_periods[i]);
1329 : : }
1330 [ # # ]: 0 : attr->lro_min_mss_size = MLX5_GET(per_protocol_networking_offload_caps,
1331 : : hcattr, lro_min_mss_size);
1332 : 0 : attr->tunnel_stateless_geneve_rx =
1333 [ # # ]: 0 : MLX5_GET(per_protocol_networking_offload_caps,
1334 : : hcattr, tunnel_stateless_geneve_rx);
1335 : 0 : attr->geneve_max_opt_len =
1336 [ # # ]: 0 : MLX5_GET(per_protocol_networking_offload_caps,
1337 : : hcattr, max_geneve_opt_len);
1338 [ # # ]: 0 : attr->wqe_inline_mode = MLX5_GET(per_protocol_networking_offload_caps,
1339 : : hcattr, wqe_inline_mode);
1340 [ # # ]: 0 : attr->tunnel_stateless_gtp = MLX5_GET
1341 : : (per_protocol_networking_offload_caps,
1342 : : hcattr, tunnel_stateless_gtp);
1343 [ # # ]: 0 : attr->tunnel_stateless_vxlan_gpe_nsh = MLX5_GET
1344 : : (per_protocol_networking_offload_caps,
1345 : : hcattr, tunnel_stateless_vxlan_gpe_nsh);
1346 [ # # ]: 0 : attr->rss_ind_tbl_cap = MLX5_GET
1347 : : (per_protocol_networking_offload_caps,
1348 : : hcattr, rss_ind_tbl_cap);
1349 [ # # ]: 0 : attr->multi_pkt_send_wqe = MLX5_GET
1350 : : (per_protocol_networking_offload_caps,
1351 : : hcattr, multi_pkt_send_wqe);
1352 [ # # ]: 0 : attr->enhanced_multi_pkt_send_wqe = MLX5_GET
1353 : : (per_protocol_networking_offload_caps,
1354 : : hcattr, enhanced_multi_pkt_send_wqe);
1355 [ # # ]: 0 : if (attr->wqe_based_flow_table_sup) {
1356 : 0 : hcattr = mlx5_devx_get_hca_cap(ctx, in, out, &rc,
1357 : : MLX5_GET_HCA_CAP_OP_MOD_WQE_BASED_FLOW_TABLE |
1358 : : (uint32_t)MLX5_HCA_CAP_OPMOD_GET_CUR);
1359 [ # # ]: 0 : if (!hcattr) {
1360 : 0 : DRV_LOG(DEBUG, "Failed to query WQE Based Flow table capabilities");
1361 : 0 : return rc;
1362 : : }
1363 [ # # ]: 0 : attr->max_header_modify_pattern_length = MLX5_GET(wqe_based_flow_table_cap,
1364 : : hcattr,
1365 : : max_header_modify_pattern_length);
1366 [ # # ]: 0 : attr->fdb_unified_en = MLX5_GET(wqe_based_flow_table_cap,
1367 : : hcattr,
1368 : : fdb_unified_en);
1369 [ # # ]: 0 : attr->fdb_rx_set_flow_tag_stc = MLX5_GET(wqe_based_flow_table_cap,
1370 : : hcattr,
1371 : : fdb_rx_set_flow_tag_stc);
1372 [ # # ]: 0 : stc_action_type_127_64 = MLX5_GET64(wqe_based_flow_table_cap,
1373 : : hcattr,
1374 : : stc_action_type_127_64);
1375 [ # # ]: 0 : if (stc_action_type_127_64 &
1376 : : (1 << (MLX5_IFC_STC_ACTION_TYPE_JUMP_FLOW_TABLE_FDB_RX_BIT_INDEX -
1377 : : MLX5_IFC_STC_ACTION_TYPE_BIT_64_INDEX)))
1378 : 0 : attr->jump_fdb_rx_en = 1;
1379 : : }
1380 : : /* Query HCA attribute for ROCE. */
1381 [ # # ]: 0 : if (attr->roce) {
1382 : 0 : hcattr = mlx5_devx_get_hca_cap(ctx, in, out, &rc,
1383 : : MLX5_GET_HCA_CAP_OP_MOD_ROCE |
1384 : : (uint32_t)MLX5_HCA_CAP_OPMOD_GET_CUR);
1385 [ # # ]: 0 : if (!hcattr) {
1386 : 0 : DRV_LOG(DEBUG,
1387 : : "Failed to query devx HCA ROCE capabilities");
1388 : 0 : return rc;
1389 : : }
1390 [ # # ]: 0 : attr->qp_ts_format = MLX5_GET(roce_caps, hcattr, qp_ts_format);
1391 : : }
1392 [ # # ]: 0 : if (attr->eth_virt) {
1393 : 0 : rc = mlx5_devx_cmd_query_nic_vport_context(ctx, 0, attr);
1394 [ # # ]: 0 : if (rc) {
1395 : 0 : attr->eth_virt = 0;
1396 : 0 : goto error;
1397 : : }
1398 : : }
1399 [ # # ]: 0 : if (attr->eswitch_manager) {
1400 : 0 : hcattr = mlx5_devx_get_hca_cap(ctx, in, out, &rc,
1401 : : MLX5_SET_HCA_CAP_OP_MOD_ESW |
1402 : : (uint32_t)MLX5_HCA_CAP_OPMOD_GET_CUR);
1403 [ # # ]: 0 : if (!hcattr)
1404 : 0 : return rc;
1405 : 0 : attr->esw_mgr_vport_id_valid =
1406 [ # # ]: 0 : MLX5_GET(esw_cap, hcattr,
1407 : : esw_manager_vport_number_valid);
1408 : 0 : attr->esw_mgr_vport_id =
1409 [ # # ]: 0 : MLX5_GET(esw_cap, hcattr, esw_manager_vport_number);
1410 : : }
1411 [ # # ]: 0 : if (attr->eswitch_manager) {
1412 : : uint32_t esw_reg, reg_c_8_15;
1413 : :
1414 : 0 : hcattr = mlx5_devx_get_hca_cap(ctx, in, out, &rc,
1415 : : MLX5_GET_HCA_CAP_OP_MOD_ESW_FLOW_TABLE |
1416 : : (uint32_t)MLX5_HCA_CAP_OPMOD_GET_CUR);
1417 [ # # ]: 0 : if (!hcattr)
1418 : 0 : return rc;
1419 [ # # ]: 0 : esw_reg = MLX5_GET(flow_table_esw_cap, hcattr,
1420 : : ft_header_modify_esw_fdb.metadata_reg_c_x);
1421 [ # # ]: 0 : reg_c_8_15 = MLX5_GET(flow_table_esw_cap, hcattr,
1422 : : ft_field_support_2_esw_fdb.metadata_reg_c_8_15);
1423 : 0 : attr->set_reg_c &= ((0xff & reg_c_8_15) << 8) | esw_reg;
1424 : : }
1425 : : return 0;
1426 : : error:
1427 : 0 : rc = (rc > 0) ? -rc : rc;
1428 : 0 : return rc;
1429 : : }
1430 : :
1431 : : /**
1432 : : * Query TIS transport domain from QP verbs object using DevX API.
1433 : : *
1434 : : * @param[in] qp
1435 : : * Pointer to verbs QP returned by ibv_create_qp .
1436 : : * @param[in] tis_num
1437 : : * TIS number of TIS to query.
1438 : : * @param[out] tis_td
1439 : : * Pointer to TIS transport domain variable, to be set by the routine.
1440 : : *
1441 : : * @return
1442 : : * 0 on success, a negative value otherwise.
1443 : : */
1444 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_qp_query_tis_td)
1445 : : int
1446 : 0 : mlx5_devx_cmd_qp_query_tis_td(void *qp, uint32_t tis_num,
1447 : : uint32_t *tis_td)
1448 : : {
1449 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
1450 : 0 : uint32_t in[MLX5_ST_SZ_DW(query_tis_in)] = {0};
1451 : 0 : uint32_t out[MLX5_ST_SZ_DW(query_tis_out)] = {0};
1452 : : int rc;
1453 : : void *tis_ctx;
1454 : :
1455 : 0 : MLX5_SET(query_tis_in, in, opcode, MLX5_CMD_OP_QUERY_TIS);
1456 : 0 : MLX5_SET(query_tis_in, in, tisn, tis_num);
1457 : 0 : rc = mlx5_glue->devx_qp_query(qp, in, sizeof(in), out, sizeof(out));
1458 [ # # ]: 0 : if (rc) {
1459 : 0 : DRV_LOG(ERR, "Failed to query QP using DevX");
1460 : 0 : return -rc;
1461 : : };
1462 : : tis_ctx = MLX5_ADDR_OF(query_tis_out, out, tis_context);
1463 [ # # ]: 0 : *tis_td = MLX5_GET(tisc, tis_ctx, transport_domain);
1464 : 0 : return 0;
1465 : : #else
1466 : : (void)qp;
1467 : : (void)tis_num;
1468 : : (void)tis_td;
1469 : : return -ENOTSUP;
1470 : : #endif
1471 : : }
1472 : :
1473 : : /**
1474 : : * Fill WQ data for DevX API command.
1475 : : * Utility function for use when creating DevX objects containing a WQ.
1476 : : *
1477 : : * @param[in] wq_ctx
1478 : : * Pointer to WQ context to fill with data.
1479 : : * @param [in] wq_attr
1480 : : * Pointer to WQ attributes structure to fill in WQ context.
1481 : : */
1482 : : static void
1483 : 0 : devx_cmd_fill_wq_data(void *wq_ctx, struct mlx5_devx_wq_attr *wq_attr)
1484 : : {
1485 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, wq_type, wq_attr->wq_type);
1486 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, wq_signature, wq_attr->wq_signature);
1487 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, end_padding_mode, wq_attr->end_padding_mode);
1488 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, cd_slave, wq_attr->cd_slave);
1489 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, hds_skip_first_sge, wq_attr->hds_skip_first_sge);
1490 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, log2_hds_buf_size, wq_attr->log2_hds_buf_size);
1491 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, page_offset, wq_attr->page_offset);
1492 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, lwm, wq_attr->lwm);
1493 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, pd, wq_attr->pd);
1494 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, uar_page, wq_attr->uar_page);
1495 [ # # ]: 0 : MLX5_SET64(wq, wq_ctx, dbr_addr, wq_attr->dbr_addr);
1496 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, hw_counter, wq_attr->hw_counter);
1497 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, sw_counter, wq_attr->sw_counter);
1498 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, log_wq_stride, wq_attr->log_wq_stride);
1499 [ # # ]: 0 : if (wq_attr->log_wq_pg_sz > MLX5_ADAPTER_PAGE_SHIFT)
1500 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, log_wq_pg_sz,
1501 : : wq_attr->log_wq_pg_sz - MLX5_ADAPTER_PAGE_SHIFT);
1502 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, log_wq_sz, wq_attr->log_wq_sz);
1503 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, dbr_umem_valid, wq_attr->dbr_umem_valid);
1504 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, wq_umem_valid, wq_attr->wq_umem_valid);
1505 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, log_hairpin_num_packets,
1506 : : wq_attr->log_hairpin_num_packets);
1507 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, log_hairpin_data_sz, wq_attr->log_hairpin_data_sz);
1508 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, single_wqe_log_num_of_strides,
1509 : : wq_attr->single_wqe_log_num_of_strides);
1510 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, two_byte_shift_en, wq_attr->two_byte_shift_en);
1511 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, single_stride_log_num_of_bytes,
1512 : : wq_attr->single_stride_log_num_of_bytes);
1513 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, dbr_umem_id, wq_attr->dbr_umem_id);
1514 [ # # ]: 0 : MLX5_SET(wq, wq_ctx, wq_umem_id, wq_attr->wq_umem_id);
1515 [ # # ]: 0 : MLX5_SET64(wq, wq_ctx, wq_umem_offset, wq_attr->wq_umem_offset);
1516 : 0 : }
1517 : :
1518 : : /**
1519 : : * Create RQ using DevX API.
1520 : : *
1521 : : * @param[in] ctx
1522 : : * Context returned from mlx5 open_device() glue function.
1523 : : * @param [in] rq_attr
1524 : : * Pointer to create RQ attributes structure.
1525 : : * @param [in] socket
1526 : : * CPU socket ID for allocations.
1527 : : *
1528 : : * @return
1529 : : * The DevX object created, NULL otherwise and rte_errno is set.
1530 : : */
1531 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_create_rq)
1532 : : struct mlx5_devx_obj *
1533 : 0 : mlx5_devx_cmd_create_rq(void *ctx,
1534 : : struct mlx5_devx_create_rq_attr *rq_attr,
1535 : : int socket)
1536 : : {
1537 : 0 : uint32_t in[MLX5_ST_SZ_DW(create_rq_in)] = {0};
1538 : 0 : uint32_t out[MLX5_ST_SZ_DW(create_rq_out)] = {0};
1539 : : void *rq_ctx, *wq_ctx;
1540 : : struct mlx5_devx_wq_attr *wq_attr;
1541 : : struct mlx5_devx_obj *rq = NULL;
1542 : :
1543 [ # # # # ]: 0 : rq = mlx5_malloc_numa_tolerant(MLX5_MEM_ZERO, sizeof(*rq), 0, socket);
1544 [ # # ]: 0 : if (!rq) {
1545 : 0 : DRV_LOG(ERR, "Failed to allocate RQ data");
1546 : 0 : rte_errno = ENOMEM;
1547 : 0 : return NULL;
1548 : : }
1549 [ # # ]: 0 : MLX5_SET(create_rq_in, in, opcode, MLX5_CMD_OP_CREATE_RQ);
1550 : : rq_ctx = MLX5_ADDR_OF(create_rq_in, in, ctx);
1551 [ # # ]: 0 : MLX5_SET(rqc, rq_ctx, rlky, rq_attr->rlky);
1552 [ # # ]: 0 : MLX5_SET(rqc, rq_ctx, delay_drop_en, rq_attr->delay_drop_en);
1553 [ # # ]: 0 : MLX5_SET(rqc, rq_ctx, scatter_fcs, rq_attr->scatter_fcs);
1554 [ # # ]: 0 : MLX5_SET(rqc, rq_ctx, vsd, rq_attr->vsd);
1555 [ # # ]: 0 : MLX5_SET(rqc, rq_ctx, mem_rq_type, rq_attr->mem_rq_type);
1556 [ # # ]: 0 : MLX5_SET(rqc, rq_ctx, state, rq_attr->state);
1557 [ # # ]: 0 : MLX5_SET(rqc, rq_ctx, flush_in_error_en, rq_attr->flush_in_error_en);
1558 [ # # ]: 0 : MLX5_SET(rqc, rq_ctx, hairpin, rq_attr->hairpin);
1559 [ # # ]: 0 : MLX5_SET(rqc, rq_ctx, hairpin_data_buffer_type, rq_attr->hairpin_data_buffer_type);
1560 [ # # ]: 0 : MLX5_SET(rqc, rq_ctx, user_index, rq_attr->user_index);
1561 [ # # ]: 0 : MLX5_SET(rqc, rq_ctx, cqn, rq_attr->cqn);
1562 [ # # ]: 0 : MLX5_SET(rqc, rq_ctx, counter_set_id, rq_attr->counter_set_id);
1563 [ # # ]: 0 : MLX5_SET(rqc, rq_ctx, rmpn, rq_attr->rmpn);
1564 [ # # ]: 0 : MLX5_SET(sqc, rq_ctx, ts_format, rq_attr->ts_format);
1565 : : wq_ctx = MLX5_ADDR_OF(rqc, rq_ctx, wq);
1566 : 0 : wq_attr = &rq_attr->wq_attr;
1567 : 0 : devx_cmd_fill_wq_data(wq_ctx, wq_attr);
1568 : 0 : rq->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in),
1569 : : out, sizeof(out));
1570 [ # # ]: 0 : if (!rq->obj) {
1571 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "create RQ", NULL, 0);
1572 : 0 : mlx5_free(rq);
1573 : 0 : return NULL;
1574 : : }
1575 [ # # ]: 0 : rq->id = MLX5_GET(create_rq_out, out, rqn);
1576 : 0 : return rq;
1577 : : }
1578 : :
1579 : : /**
1580 : : * Modify RQ using DevX API.
1581 : : *
1582 : : * @param[in] rq
1583 : : * Pointer to RQ object structure.
1584 : : * @param [in] rq_attr
1585 : : * Pointer to modify RQ attributes structure.
1586 : : *
1587 : : * @return
1588 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1589 : : */
1590 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_modify_rq)
1591 : : int
1592 : 0 : mlx5_devx_cmd_modify_rq(struct mlx5_devx_obj *rq,
1593 : : struct mlx5_devx_modify_rq_attr *rq_attr)
1594 : : {
1595 : 0 : uint32_t in[MLX5_ST_SZ_DW(modify_rq_in)] = {0};
1596 : 0 : uint32_t out[MLX5_ST_SZ_DW(modify_rq_out)] = {0};
1597 : : void *rq_ctx, *wq_ctx;
1598 : : int ret;
1599 : :
1600 : 0 : MLX5_SET(modify_rq_in, in, opcode, MLX5_CMD_OP_MODIFY_RQ);
1601 : 0 : MLX5_SET(modify_rq_in, in, rq_state, rq_attr->rq_state);
1602 [ # # ]: 0 : MLX5_SET(modify_rq_in, in, rqn, rq->id);
1603 [ # # ]: 0 : MLX5_SET64(modify_rq_in, in, modify_bitmask, rq_attr->modify_bitmask);
1604 : : rq_ctx = MLX5_ADDR_OF(modify_rq_in, in, ctx);
1605 : 0 : MLX5_SET(rqc, rq_ctx, state, rq_attr->state);
1606 [ # # ]: 0 : if (rq_attr->modify_bitmask &
1607 : : MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_SCATTER_FCS)
1608 [ # # ]: 0 : MLX5_SET(rqc, rq_ctx, scatter_fcs, rq_attr->scatter_fcs);
1609 [ # # ]: 0 : if (rq_attr->modify_bitmask & MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_VSD)
1610 [ # # ]: 0 : MLX5_SET(rqc, rq_ctx, vsd, rq_attr->vsd);
1611 [ # # ]: 0 : if (rq_attr->modify_bitmask &
1612 : : MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_RQ_COUNTER_SET_ID)
1613 : 0 : MLX5_SET(rqc, rq_ctx, counter_set_id, rq_attr->counter_set_id);
1614 : 0 : MLX5_SET(rqc, rq_ctx, hairpin_peer_sq, rq_attr->hairpin_peer_sq);
1615 : 0 : MLX5_SET(rqc, rq_ctx, hairpin_peer_vhca, rq_attr->hairpin_peer_vhca);
1616 [ # # ]: 0 : if (rq_attr->modify_bitmask & MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_WQ_LWM) {
1617 : : wq_ctx = MLX5_ADDR_OF(rqc, rq_ctx, wq);
1618 : 0 : MLX5_SET(wq, wq_ctx, lwm, rq_attr->lwm);
1619 : : }
1620 : 0 : ret = mlx5_glue->devx_obj_modify(rq->obj, in, sizeof(in),
1621 : : out, sizeof(out));
1622 : :
1623 [ # # ]: 0 : if (ret) {
1624 : 0 : DRV_LOG(ERR, "Failed to modify RQ using DevX");
1625 : 0 : rte_errno = errno;
1626 : 0 : return -errno;
1627 : : }
1628 : : return ret;
1629 : : }
1630 : :
1631 : : /*
1632 : : * Query RQ using DevX API.
1633 : : *
1634 : : * @param[in] rq_obj
1635 : : * RQ Devx Object
1636 : : * @param[out] out
1637 : : * RQ Query Output
1638 : : * @param[in] outlen
1639 : : * RQ Query Output Length
1640 : : *
1641 : : * @return
1642 : : * 0 if Query successful, else non-zero return value from devx_obj_query API
1643 : : */
1644 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_query_rq)
1645 : : int
1646 : 0 : mlx5_devx_cmd_query_rq(struct mlx5_devx_obj *rq_obj, void *out, size_t outlen)
1647 : : {
1648 : 0 : uint32_t in[MLX5_ST_SZ_DW(query_rq_in)] = {0};
1649 : : int rc;
1650 : :
1651 : 0 : MLX5_SET(query_rq_in, in, opcode, MLX5_CMD_OP_QUERY_RQ);
1652 : 0 : MLX5_SET(query_rq_in, in, rqn, rq_obj->id);
1653 : 0 : rc = mlx5_glue->devx_obj_query(rq_obj->obj, in, sizeof(in), out, outlen);
1654 [ # # # # : 0 : if (rc || MLX5_FW_STATUS(out)) {
# # # # ]
1655 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "RQ query", "rq_id", rq_obj->id);
1656 [ # # ]: 0 : return MLX5_DEVX_ERR_RC(rc);
1657 : : }
1658 : : return 0;
1659 : : }
1660 : :
1661 : : /**
1662 : : * Create RMP using DevX API.
1663 : : *
1664 : : * @param[in] ctx
1665 : : * Context returned from mlx5 open_device() glue function.
1666 : : * @param [in] rmp_attr
1667 : : * Pointer to create RMP attributes structure.
1668 : : * @param [in] socket
1669 : : * CPU socket ID for allocations.
1670 : : *
1671 : : * @return
1672 : : * The DevX object created, NULL otherwise and rte_errno is set.
1673 : : */
1674 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_create_rmp)
1675 : : struct mlx5_devx_obj *
1676 : 0 : mlx5_devx_cmd_create_rmp(void *ctx,
1677 : : struct mlx5_devx_create_rmp_attr *rmp_attr,
1678 : : int socket)
1679 : : {
1680 : 0 : uint32_t in[MLX5_ST_SZ_DW(create_rmp_in)] = {0};
1681 : 0 : uint32_t out[MLX5_ST_SZ_DW(create_rmp_out)] = {0};
1682 : : void *rmp_ctx, *wq_ctx;
1683 : : struct mlx5_devx_wq_attr *wq_attr;
1684 : : struct mlx5_devx_obj *rmp = NULL;
1685 : :
1686 [ # # # # ]: 0 : rmp = mlx5_malloc_numa_tolerant(MLX5_MEM_ZERO, sizeof(*rmp), 0, socket);
1687 [ # # ]: 0 : if (!rmp) {
1688 : 0 : DRV_LOG(ERR, "Failed to allocate RMP data");
1689 : 0 : rte_errno = ENOMEM;
1690 : 0 : return NULL;
1691 : : }
1692 [ # # ]: 0 : MLX5_SET(create_rmp_in, in, opcode, MLX5_CMD_OP_CREATE_RMP);
1693 : : rmp_ctx = MLX5_ADDR_OF(create_rmp_in, in, ctx);
1694 [ # # ]: 0 : MLX5_SET(rmpc, rmp_ctx, state, rmp_attr->state);
1695 [ # # ]: 0 : MLX5_SET(rmpc, rmp_ctx, basic_cyclic_rcv_wqe,
1696 : : rmp_attr->basic_cyclic_rcv_wqe);
1697 : : wq_ctx = MLX5_ADDR_OF(rmpc, rmp_ctx, wq);
1698 : 0 : wq_attr = &rmp_attr->wq_attr;
1699 : 0 : devx_cmd_fill_wq_data(wq_ctx, wq_attr);
1700 : 0 : rmp->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in), out,
1701 : : sizeof(out));
1702 [ # # ]: 0 : if (!rmp->obj) {
1703 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "create RMP", NULL, 0);
1704 : 0 : mlx5_free(rmp);
1705 : 0 : return NULL;
1706 : : }
1707 [ # # ]: 0 : rmp->id = MLX5_GET(create_rmp_out, out, rmpn);
1708 : 0 : return rmp;
1709 : : }
1710 : :
1711 : : /*
1712 : : * Create TIR using DevX API.
1713 : : *
1714 : : * @param[in] ctx
1715 : : * Context returned from mlx5 open_device() glue function.
1716 : : * @param [in] tir_attr
1717 : : * Pointer to TIR attributes structure.
1718 : : *
1719 : : * @return
1720 : : * The DevX object created, NULL otherwise and rte_errno is set.
1721 : : */
1722 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_create_tir)
1723 : : struct mlx5_devx_obj *
1724 : 0 : mlx5_devx_cmd_create_tir(void *ctx,
1725 : : struct mlx5_devx_tir_attr *tir_attr)
1726 : : {
1727 : 0 : uint32_t in[MLX5_ST_SZ_DW(create_tir_in)] = {0};
1728 : 0 : uint32_t out[MLX5_ST_SZ_DW(create_tir_out)] = {0};
1729 : : void *tir_ctx, *outer, *inner, *rss_key;
1730 : : struct mlx5_devx_obj *tir = NULL;
1731 : :
1732 : 0 : tir = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*tir), 0, SOCKET_ID_ANY);
1733 [ # # ]: 0 : if (!tir) {
1734 : 0 : DRV_LOG(ERR, "Failed to allocate TIR data");
1735 : 0 : rte_errno = ENOMEM;
1736 : 0 : return NULL;
1737 : : }
1738 [ # # ]: 0 : MLX5_SET(create_tir_in, in, opcode, MLX5_CMD_OP_CREATE_TIR);
1739 : : tir_ctx = MLX5_ADDR_OF(create_tir_in, in, ctx);
1740 [ # # ]: 0 : MLX5_SET(tirc, tir_ctx, disp_type, tir_attr->disp_type);
1741 [ # # ]: 0 : MLX5_SET(tirc, tir_ctx, lro_timeout_period_usecs,
1742 : : tir_attr->lro_timeout_period_usecs);
1743 [ # # ]: 0 : MLX5_SET(tirc, tir_ctx, lro_enable_mask, tir_attr->lro_enable_mask);
1744 [ # # ]: 0 : MLX5_SET(tirc, tir_ctx, lro_max_msg_sz, tir_attr->lro_max_msg_sz);
1745 [ # # ]: 0 : MLX5_SET(tirc, tir_ctx, inline_rqn, tir_attr->inline_rqn);
1746 [ # # ]: 0 : MLX5_SET(tirc, tir_ctx, rx_hash_symmetric, tir_attr->rx_hash_symmetric);
1747 [ # # ]: 0 : MLX5_SET(tirc, tir_ctx, tunneled_offload_en,
1748 : : tir_attr->tunneled_offload_en);
1749 [ # # ]: 0 : MLX5_SET(tirc, tir_ctx, indirect_table, tir_attr->indirect_table);
1750 [ # # ]: 0 : MLX5_SET(tirc, tir_ctx, rx_hash_fn, tir_attr->rx_hash_fn);
1751 [ # # ]: 0 : MLX5_SET(tirc, tir_ctx, self_lb_block, tir_attr->self_lb_block);
1752 [ # # ]: 0 : MLX5_SET(tirc, tir_ctx, transport_domain, tir_attr->transport_domain);
1753 : : rss_key = MLX5_ADDR_OF(tirc, tir_ctx, rx_hash_toeplitz_key);
1754 [ # # ]: 0 : memcpy(rss_key, tir_attr->rx_hash_toeplitz_key, MLX5_RSS_HASH_KEY_LEN);
1755 : : outer = MLX5_ADDR_OF(tirc, tir_ctx, rx_hash_field_selector_outer);
1756 [ # # ]: 0 : MLX5_SET(rx_hash_field_select, outer, l3_prot_type,
1757 : : tir_attr->rx_hash_field_selector_outer.l3_prot_type);
1758 [ # # ]: 0 : MLX5_SET(rx_hash_field_select, outer, l4_prot_type,
1759 : : tir_attr->rx_hash_field_selector_outer.l4_prot_type);
1760 [ # # ]: 0 : MLX5_SET(rx_hash_field_select, outer, selected_fields,
1761 : : tir_attr->rx_hash_field_selector_outer.selected_fields);
1762 : : inner = MLX5_ADDR_OF(tirc, tir_ctx, rx_hash_field_selector_inner);
1763 [ # # ]: 0 : MLX5_SET(rx_hash_field_select, inner, l3_prot_type,
1764 : : tir_attr->rx_hash_field_selector_inner.l3_prot_type);
1765 [ # # ]: 0 : MLX5_SET(rx_hash_field_select, inner, l4_prot_type,
1766 : : tir_attr->rx_hash_field_selector_inner.l4_prot_type);
1767 [ # # ]: 0 : MLX5_SET(rx_hash_field_select, inner, selected_fields,
1768 : : tir_attr->rx_hash_field_selector_inner.selected_fields);
1769 : 0 : tir->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in),
1770 : : out, sizeof(out));
1771 [ # # ]: 0 : if (!tir->obj) {
1772 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "create TIR", NULL, 0);
1773 : 0 : mlx5_free(tir);
1774 : 0 : return NULL;
1775 : : }
1776 [ # # ]: 0 : tir->id = MLX5_GET(create_tir_out, out, tirn);
1777 : 0 : return tir;
1778 : : }
1779 : :
1780 : : /**
1781 : : * Modify TIR using DevX API.
1782 : : *
1783 : : * @param[in] tir
1784 : : * Pointer to TIR DevX object structure.
1785 : : * @param [in] modify_tir_attr
1786 : : * Pointer to TIR modification attributes structure.
1787 : : *
1788 : : * @return
1789 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1790 : : */
1791 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_modify_tir)
1792 : : int
1793 : 0 : mlx5_devx_cmd_modify_tir(struct mlx5_devx_obj *tir,
1794 : : struct mlx5_devx_modify_tir_attr *modify_tir_attr)
1795 : : {
1796 : : struct mlx5_devx_tir_attr *tir_attr = &modify_tir_attr->tir;
1797 : 0 : uint32_t in[MLX5_ST_SZ_DW(modify_tir_in)] = {0};
1798 : 0 : uint32_t out[MLX5_ST_SZ_DW(modify_tir_out)] = {0};
1799 : : void *tir_ctx;
1800 : : int ret;
1801 : :
1802 : 0 : MLX5_SET(modify_tir_in, in, opcode, MLX5_CMD_OP_MODIFY_TIR);
1803 : 0 : MLX5_SET(modify_tir_in, in, tirn, modify_tir_attr->tirn);
1804 [ # # ]: 0 : MLX5_SET64(modify_tir_in, in, modify_bitmask,
1805 : : modify_tir_attr->modify_bitmask);
1806 : : tir_ctx = MLX5_ADDR_OF(modify_rq_in, in, ctx);
1807 [ # # ]: 0 : if (modify_tir_attr->modify_bitmask &
1808 : : MLX5_MODIFY_TIR_IN_MODIFY_BITMASK_LRO) {
1809 : 0 : MLX5_SET(tirc, tir_ctx, lro_timeout_period_usecs,
1810 : : tir_attr->lro_timeout_period_usecs);
1811 [ # # ]: 0 : MLX5_SET(tirc, tir_ctx, lro_enable_mask,
1812 : : tir_attr->lro_enable_mask);
1813 [ # # ]: 0 : MLX5_SET(tirc, tir_ctx, lro_max_msg_sz,
1814 : : tir_attr->lro_max_msg_sz);
1815 : : }
1816 [ # # ]: 0 : if (modify_tir_attr->modify_bitmask &
1817 : : MLX5_MODIFY_TIR_IN_MODIFY_BITMASK_INDIRECT_TABLE)
1818 : 0 : MLX5_SET(tirc, tir_ctx, indirect_table,
1819 : : tir_attr->indirect_table);
1820 [ # # ]: 0 : if (modify_tir_attr->modify_bitmask &
1821 : : MLX5_MODIFY_TIR_IN_MODIFY_BITMASK_HASH) {
1822 : : int i;
1823 : : void *outer, *inner;
1824 : :
1825 [ # # ]: 0 : MLX5_SET(tirc, tir_ctx, rx_hash_symmetric,
1826 : : tir_attr->rx_hash_symmetric);
1827 : 0 : MLX5_SET(tirc, tir_ctx, rx_hash_fn, tir_attr->rx_hash_fn);
1828 [ # # ]: 0 : for (i = 0; i < 10; i++) {
1829 [ # # ]: 0 : MLX5_SET(tirc, tir_ctx, rx_hash_toeplitz_key[i],
1830 : : tir_attr->rx_hash_toeplitz_key[i]);
1831 : : }
1832 : : outer = MLX5_ADDR_OF(tirc, tir_ctx,
1833 : : rx_hash_field_selector_outer);
1834 [ # # ]: 0 : MLX5_SET(rx_hash_field_select, outer, l3_prot_type,
1835 : : tir_attr->rx_hash_field_selector_outer.l3_prot_type);
1836 [ # # ]: 0 : MLX5_SET(rx_hash_field_select, outer, l4_prot_type,
1837 : : tir_attr->rx_hash_field_selector_outer.l4_prot_type);
1838 [ # # ]: 0 : MLX5_SET
1839 : : (rx_hash_field_select, outer, selected_fields,
1840 : : tir_attr->rx_hash_field_selector_outer.selected_fields);
1841 : : inner = MLX5_ADDR_OF(tirc, tir_ctx,
1842 : : rx_hash_field_selector_inner);
1843 [ # # ]: 0 : MLX5_SET(rx_hash_field_select, inner, l3_prot_type,
1844 : : tir_attr->rx_hash_field_selector_inner.l3_prot_type);
1845 [ # # ]: 0 : MLX5_SET(rx_hash_field_select, inner, l4_prot_type,
1846 : : tir_attr->rx_hash_field_selector_inner.l4_prot_type);
1847 [ # # ]: 0 : MLX5_SET
1848 : : (rx_hash_field_select, inner, selected_fields,
1849 : : tir_attr->rx_hash_field_selector_inner.selected_fields);
1850 : : }
1851 [ # # ]: 0 : if (modify_tir_attr->modify_bitmask &
1852 : : MLX5_MODIFY_TIR_IN_MODIFY_BITMASK_SELF_LB_EN) {
1853 [ # # ]: 0 : MLX5_SET(tirc, tir_ctx, self_lb_block, tir_attr->self_lb_block);
1854 : : }
1855 : 0 : ret = mlx5_glue->devx_obj_modify(tir->obj, in, sizeof(in),
1856 : : out, sizeof(out));
1857 [ # # ]: 0 : if (ret) {
1858 : 0 : DRV_LOG(ERR, "Failed to modify TIR using DevX");
1859 : 0 : rte_errno = errno;
1860 : 0 : return -errno;
1861 : : }
1862 : : return ret;
1863 : : }
1864 : :
1865 : : /**
1866 : : * Create RQT using DevX API.
1867 : : *
1868 : : * @param[in] ctx
1869 : : * Context returned from mlx5 open_device() glue function.
1870 : : * @param [in] rqt_attr
1871 : : * Pointer to RQT attributes structure.
1872 : : *
1873 : : * @return
1874 : : * The DevX object created, NULL otherwise and rte_errno is set.
1875 : : */
1876 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_create_rqt)
1877 : : struct mlx5_devx_obj *
1878 : 0 : mlx5_devx_cmd_create_rqt(void *ctx,
1879 : : struct mlx5_devx_rqt_attr *rqt_attr)
1880 : : {
1881 : : uint32_t *in = NULL;
1882 : 0 : uint32_t inlen = MLX5_ST_SZ_BYTES(create_rqt_in) +
1883 : 0 : rqt_attr->rqt_actual_size * sizeof(uint32_t);
1884 : 0 : uint32_t out[MLX5_ST_SZ_DW(create_rqt_out)] = {0};
1885 : : void *rqt_ctx;
1886 : : struct mlx5_devx_obj *rqt = NULL;
1887 : : unsigned int i;
1888 : :
1889 : 0 : in = mlx5_malloc(MLX5_MEM_ZERO, inlen, 0, SOCKET_ID_ANY);
1890 [ # # ]: 0 : if (!in) {
1891 : 0 : DRV_LOG(ERR, "Failed to allocate RQT IN data");
1892 : 0 : rte_errno = ENOMEM;
1893 : 0 : return NULL;
1894 : : }
1895 : 0 : rqt = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*rqt), 0, SOCKET_ID_ANY);
1896 [ # # ]: 0 : if (!rqt) {
1897 : 0 : DRV_LOG(ERR, "Failed to allocate RQT data");
1898 : 0 : rte_errno = ENOMEM;
1899 : 0 : mlx5_free(in);
1900 : 0 : return NULL;
1901 : : }
1902 [ # # ]: 0 : MLX5_SET(create_rqt_in, in, opcode, MLX5_CMD_OP_CREATE_RQT);
1903 : 0 : rqt_ctx = MLX5_ADDR_OF(create_rqt_in, in, rqt_context);
1904 [ # # ]: 0 : MLX5_SET(rqtc, rqt_ctx, list_q_type, rqt_attr->rq_type);
1905 [ # # ]: 0 : MLX5_SET(rqtc, rqt_ctx, rqt_max_size, rqt_attr->rqt_max_size);
1906 [ # # ]: 0 : MLX5_SET(rqtc, rqt_ctx, rqt_actual_size, rqt_attr->rqt_actual_size);
1907 [ # # ]: 0 : for (i = 0; i < rqt_attr->rqt_actual_size; i++)
1908 [ # # ]: 0 : MLX5_SET(rqtc, rqt_ctx, rq_num[i], rqt_attr->rq_list[i]);
1909 : 0 : rqt->obj = mlx5_glue->devx_obj_create(ctx, in, inlen, out, sizeof(out));
1910 : 0 : mlx5_free(in);
1911 [ # # ]: 0 : if (!rqt->obj) {
1912 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "create RQT", NULL, 0);
1913 : 0 : mlx5_free(rqt);
1914 : 0 : return NULL;
1915 : : }
1916 [ # # ]: 0 : rqt->id = MLX5_GET(create_rqt_out, out, rqtn);
1917 : 0 : return rqt;
1918 : : }
1919 : :
1920 : : /**
1921 : : * Modify RQT using DevX API.
1922 : : *
1923 : : * @param[in] rqt
1924 : : * Pointer to RQT DevX object structure.
1925 : : * @param [in] rqt_attr
1926 : : * Pointer to RQT attributes structure.
1927 : : *
1928 : : * @return
1929 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
1930 : : */
1931 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_modify_rqt)
1932 : : int
1933 : 0 : mlx5_devx_cmd_modify_rqt(struct mlx5_devx_obj *rqt,
1934 : : struct mlx5_devx_rqt_attr *rqt_attr)
1935 : : {
1936 : 0 : uint32_t inlen = MLX5_ST_SZ_BYTES(modify_rqt_in) +
1937 : 0 : rqt_attr->rqt_actual_size * sizeof(uint32_t);
1938 : 0 : uint32_t out[MLX5_ST_SZ_DW(modify_rqt_out)] = {0};
1939 : 0 : uint32_t *in = mlx5_malloc(MLX5_MEM_ZERO, inlen, 0, SOCKET_ID_ANY);
1940 : : void *rqt_ctx;
1941 : : unsigned int i;
1942 : : int ret;
1943 : :
1944 [ # # ]: 0 : if (!in) {
1945 : 0 : DRV_LOG(ERR, "Failed to allocate RQT modify IN data.");
1946 : 0 : rte_errno = ENOMEM;
1947 : 0 : return -ENOMEM;
1948 : : }
1949 [ # # ]: 0 : MLX5_SET(modify_rqt_in, in, opcode, MLX5_CMD_OP_MODIFY_RQT);
1950 [ # # ]: 0 : MLX5_SET(modify_rqt_in, in, rqtn, rqt->id);
1951 : 0 : MLX5_SET64(modify_rqt_in, in, modify_bitmask, 0x1);
1952 : 0 : rqt_ctx = MLX5_ADDR_OF(modify_rqt_in, in, rqt_context);
1953 [ # # ]: 0 : MLX5_SET(rqtc, rqt_ctx, list_q_type, rqt_attr->rq_type);
1954 [ # # ]: 0 : MLX5_SET(rqtc, rqt_ctx, rqt_actual_size, rqt_attr->rqt_actual_size);
1955 [ # # ]: 0 : for (i = 0; i < rqt_attr->rqt_actual_size; i++)
1956 [ # # ]: 0 : MLX5_SET(rqtc, rqt_ctx, rq_num[i], rqt_attr->rq_list[i]);
1957 : 0 : ret = mlx5_glue->devx_obj_modify(rqt->obj, in, inlen, out, sizeof(out));
1958 : 0 : mlx5_free(in);
1959 [ # # ]: 0 : if (ret) {
1960 : 0 : DRV_LOG(ERR, "Failed to modify RQT using DevX.");
1961 : 0 : rte_errno = errno;
1962 : 0 : return -rte_errno;
1963 : : }
1964 : : return ret;
1965 : : }
1966 : :
1967 : : /**
1968 : : * Create SQ using DevX API.
1969 : : *
1970 : : * @param[in] ctx
1971 : : * Context returned from mlx5 open_device() glue function.
1972 : : * @param [in] sq_attr
1973 : : * Pointer to SQ attributes structure.
1974 : : * @param [in] socket
1975 : : * CPU socket ID for allocations.
1976 : : *
1977 : : * @return
1978 : : * The DevX object created, NULL otherwise and rte_errno is set.
1979 : : **/
1980 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_create_sq)
1981 : : struct mlx5_devx_obj *
1982 : 0 : mlx5_devx_cmd_create_sq(void *ctx,
1983 : : struct mlx5_devx_create_sq_attr *sq_attr)
1984 : : {
1985 : 0 : uint32_t in[MLX5_ST_SZ_DW(create_sq_in)] = {0};
1986 : 0 : uint32_t out[MLX5_ST_SZ_DW(create_sq_out)] = {0};
1987 : : void *sq_ctx;
1988 : : void *wq_ctx;
1989 : : struct mlx5_devx_wq_attr *wq_attr;
1990 : : struct mlx5_devx_obj *sq = NULL;
1991 : :
1992 : 0 : sq = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*sq), 0, SOCKET_ID_ANY);
1993 [ # # ]: 0 : if (!sq) {
1994 : 0 : DRV_LOG(ERR, "Failed to allocate SQ data");
1995 : 0 : rte_errno = ENOMEM;
1996 : 0 : return NULL;
1997 : : }
1998 [ # # ]: 0 : MLX5_SET(create_sq_in, in, opcode, MLX5_CMD_OP_CREATE_SQ);
1999 : : sq_ctx = MLX5_ADDR_OF(create_sq_in, in, ctx);
2000 [ # # ]: 0 : MLX5_SET(sqc, sq_ctx, rlky, sq_attr->rlky);
2001 [ # # ]: 0 : MLX5_SET(sqc, sq_ctx, cd_master, sq_attr->cd_master);
2002 [ # # ]: 0 : MLX5_SET(sqc, sq_ctx, fre, sq_attr->fre);
2003 [ # # ]: 0 : MLX5_SET(sqc, sq_ctx, flush_in_error_en, sq_attr->flush_in_error_en);
2004 [ # # ]: 0 : MLX5_SET(sqc, sq_ctx, allow_multi_pkt_send_wqe,
2005 : : sq_attr->allow_multi_pkt_send_wqe);
2006 [ # # ]: 0 : MLX5_SET(sqc, sq_ctx, min_wqe_inline_mode,
2007 : : sq_attr->min_wqe_inline_mode);
2008 [ # # ]: 0 : MLX5_SET(sqc, sq_ctx, state, sq_attr->state);
2009 [ # # ]: 0 : MLX5_SET(sqc, sq_ctx, reg_umr, sq_attr->reg_umr);
2010 [ # # ]: 0 : MLX5_SET(sqc, sq_ctx, allow_swp, sq_attr->allow_swp);
2011 [ # # ]: 0 : MLX5_SET(sqc, sq_ctx, hairpin, sq_attr->hairpin);
2012 [ # # ]: 0 : MLX5_SET(sqc, sq_ctx, non_wire, sq_attr->non_wire);
2013 [ # # ]: 0 : MLX5_SET(sqc, sq_ctx, static_sq_wq, sq_attr->static_sq_wq);
2014 [ # # ]: 0 : MLX5_SET(sqc, sq_ctx, hairpin_wq_buffer_type, sq_attr->hairpin_wq_buffer_type);
2015 [ # # ]: 0 : MLX5_SET(sqc, sq_ctx, user_index, sq_attr->user_index);
2016 [ # # ]: 0 : MLX5_SET(sqc, sq_ctx, cqn, sq_attr->cqn);
2017 [ # # ]: 0 : MLX5_SET(sqc, sq_ctx, packet_pacing_rate_limit_index,
2018 : : sq_attr->packet_pacing_rate_limit_index);
2019 [ # # ]: 0 : MLX5_SET(sqc, sq_ctx, tis_lst_sz, sq_attr->tis_lst_sz);
2020 [ # # ]: 0 : MLX5_SET(sqc, sq_ctx, tis_num_0, sq_attr->tis_num);
2021 [ # # ]: 0 : MLX5_SET(sqc, sq_ctx, ts_format, sq_attr->ts_format);
2022 : : wq_ctx = MLX5_ADDR_OF(sqc, sq_ctx, wq);
2023 : 0 : wq_attr = &sq_attr->wq_attr;
2024 : 0 : devx_cmd_fill_wq_data(wq_ctx, wq_attr);
2025 : 0 : sq->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in),
2026 : : out, sizeof(out));
2027 [ # # ]: 0 : if (!sq->obj) {
2028 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "create SQ", NULL, 0);
2029 : 0 : mlx5_free(sq);
2030 : 0 : return NULL;
2031 : : }
2032 [ # # ]: 0 : sq->id = MLX5_GET(create_sq_out, out, sqn);
2033 : 0 : return sq;
2034 : : }
2035 : :
2036 : : /**
2037 : : * Modify SQ using DevX API.
2038 : : *
2039 : : * @param[in] sq
2040 : : * Pointer to SQ object structure.
2041 : : * @param [in] sq_attr
2042 : : * Pointer to SQ attributes structure.
2043 : : *
2044 : : * @return
2045 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2046 : : */
2047 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_modify_sq)
2048 : : int
2049 : 0 : mlx5_devx_cmd_modify_sq(struct mlx5_devx_obj *sq,
2050 : : struct mlx5_devx_modify_sq_attr *sq_attr)
2051 : : {
2052 : 0 : uint32_t in[MLX5_ST_SZ_DW(modify_sq_in)] = {0};
2053 : 0 : uint32_t out[MLX5_ST_SZ_DW(modify_sq_out)] = {0};
2054 : : void *sq_ctx;
2055 : : int ret;
2056 : :
2057 : 0 : MLX5_SET(modify_sq_in, in, opcode, MLX5_CMD_OP_MODIFY_SQ);
2058 : 0 : MLX5_SET(modify_sq_in, in, sq_state, sq_attr->sq_state);
2059 [ # # ]: 0 : MLX5_SET(modify_sq_in, in, sqn, sq->id);
2060 : : sq_ctx = MLX5_ADDR_OF(modify_sq_in, in, ctx);
2061 : 0 : MLX5_SET(sqc, sq_ctx, state, sq_attr->state);
2062 : 0 : MLX5_SET(sqc, sq_ctx, hairpin_peer_rq, sq_attr->hairpin_peer_rq);
2063 : 0 : MLX5_SET(sqc, sq_ctx, hairpin_peer_vhca, sq_attr->hairpin_peer_vhca);
2064 : 0 : ret = mlx5_glue->devx_obj_modify(sq->obj, in, sizeof(in),
2065 : : out, sizeof(out));
2066 [ # # ]: 0 : if (ret) {
2067 : 0 : DRV_LOG(ERR, "Failed to modify SQ using DevX");
2068 : 0 : rte_errno = errno;
2069 : 0 : return -rte_errno;
2070 : : }
2071 : : return ret;
2072 : : }
2073 : :
2074 : : /*
2075 : : * Query SQ using DevX API.
2076 : : *
2077 : : * @param[in] sq_obj
2078 : : * SQ Devx Object
2079 : : * @param[out] out
2080 : : * SQ Query Output
2081 : : * @param[in] outlen
2082 : : * SQ Query Output Length
2083 : : *
2084 : : * @return
2085 : : * 0 if Query successful, else non-zero return value from devx_obj_query API
2086 : : */
2087 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_query_sq)
2088 : : int
2089 : 0 : mlx5_devx_cmd_query_sq(struct mlx5_devx_obj *sq_obj, void *out, size_t outlen)
2090 : : {
2091 : 0 : uint32_t in[MLX5_ST_SZ_DW(query_sq_in)] = {0};
2092 : : int rc;
2093 : :
2094 : 0 : MLX5_SET(query_sq_in, in, opcode, MLX5_CMD_OP_QUERY_SQ);
2095 : 0 : MLX5_SET(query_sq_in, in, sqn, sq_obj->id);
2096 : 0 : rc = mlx5_glue->devx_obj_query(sq_obj->obj, in, sizeof(in), out, outlen);
2097 [ # # # # : 0 : if (rc || MLX5_FW_STATUS(out)) {
# # # # ]
2098 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "SQ query", "sq_id", sq_obj->id);
2099 [ # # ]: 0 : return MLX5_DEVX_ERR_RC(rc);
2100 : : }
2101 : : return 0;
2102 : : }
2103 : :
2104 : : /**
2105 : : * Create TIS using DevX API.
2106 : : *
2107 : : * @param[in] ctx
2108 : : * Context returned from mlx5 open_device() glue function.
2109 : : * @param [in] tis_attr
2110 : : * Pointer to TIS attributes structure.
2111 : : *
2112 : : * @return
2113 : : * The DevX object created, NULL otherwise and rte_errno is set.
2114 : : */
2115 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_create_tis)
2116 : : struct mlx5_devx_obj *
2117 : 0 : mlx5_devx_cmd_create_tis(void *ctx,
2118 : : struct mlx5_devx_tis_attr *tis_attr)
2119 : : {
2120 : 0 : uint32_t in[MLX5_ST_SZ_DW(create_tis_in)] = {0};
2121 : 0 : uint32_t out[MLX5_ST_SZ_DW(create_tis_out)] = {0};
2122 : : struct mlx5_devx_obj *tis = NULL;
2123 : : void *tis_ctx;
2124 : :
2125 : 0 : tis = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*tis), 0, SOCKET_ID_ANY);
2126 [ # # ]: 0 : if (!tis) {
2127 : 0 : DRV_LOG(ERR, "Failed to allocate TIS object");
2128 : 0 : rte_errno = ENOMEM;
2129 : 0 : return NULL;
2130 : : }
2131 [ # # ]: 0 : MLX5_SET(create_tis_in, in, opcode, MLX5_CMD_OP_CREATE_TIS);
2132 : : tis_ctx = MLX5_ADDR_OF(create_tis_in, in, ctx);
2133 [ # # ]: 0 : MLX5_SET(tisc, tis_ctx, strict_lag_tx_port_affinity,
2134 : : tis_attr->strict_lag_tx_port_affinity);
2135 [ # # ]: 0 : MLX5_SET(tisc, tis_ctx, lag_tx_port_affinity,
2136 : : tis_attr->lag_tx_port_affinity);
2137 [ # # ]: 0 : MLX5_SET(tisc, tis_ctx, prio, tis_attr->prio);
2138 [ # # ]: 0 : MLX5_SET(tisc, tis_ctx, transport_domain,
2139 : : tis_attr->transport_domain);
2140 : 0 : tis->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in),
2141 : : out, sizeof(out));
2142 [ # # ]: 0 : if (!tis->obj) {
2143 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "create TIS", NULL, 0);
2144 : 0 : mlx5_free(tis);
2145 : 0 : return NULL;
2146 : : }
2147 [ # # ]: 0 : tis->id = MLX5_GET(create_tis_out, out, tisn);
2148 : 0 : return tis;
2149 : : }
2150 : :
2151 : : /**
2152 : : * Create transport domain using DevX API.
2153 : : *
2154 : : * @param[in] ctx
2155 : : * Context returned from mlx5 open_device() glue function.
2156 : : * @return
2157 : : * The DevX object created, NULL otherwise and rte_errno is set.
2158 : : */
2159 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_create_td)
2160 : : struct mlx5_devx_obj *
2161 : 0 : mlx5_devx_cmd_create_td(void *ctx)
2162 : : {
2163 : 0 : uint32_t in[MLX5_ST_SZ_DW(alloc_transport_domain_in)] = {0};
2164 : 0 : uint32_t out[MLX5_ST_SZ_DW(alloc_transport_domain_out)] = {0};
2165 : : struct mlx5_devx_obj *td = NULL;
2166 : :
2167 : 0 : td = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*td), 0, SOCKET_ID_ANY);
2168 [ # # ]: 0 : if (!td) {
2169 : 0 : DRV_LOG(ERR, "Failed to allocate TD object");
2170 : 0 : rte_errno = ENOMEM;
2171 : 0 : return NULL;
2172 : : }
2173 [ # # ]: 0 : MLX5_SET(alloc_transport_domain_in, in, opcode,
2174 : : MLX5_CMD_OP_ALLOC_TRANSPORT_DOMAIN);
2175 : 0 : td->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in),
2176 : : out, sizeof(out));
2177 [ # # ]: 0 : if (!td->obj) {
2178 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "create TIS", NULL, 0);
2179 : 0 : mlx5_free(td);
2180 : 0 : return NULL;
2181 : : }
2182 [ # # ]: 0 : td->id = MLX5_GET(alloc_transport_domain_out, out,
2183 : : transport_domain);
2184 : 0 : return td;
2185 : : }
2186 : :
2187 : : /**
2188 : : * Dump all flows to file.
2189 : : *
2190 : : * @param[in] fdb_domain
2191 : : * FDB domain.
2192 : : * @param[in] rx_domain
2193 : : * RX domain.
2194 : : * @param[in] tx_domain
2195 : : * TX domain.
2196 : : * @param[out] file
2197 : : * Pointer to file stream.
2198 : : *
2199 : : * @return
2200 : : * 0 on success, a negative value otherwise.
2201 : : */
2202 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_flow_dump)
2203 : : int
2204 : 0 : mlx5_devx_cmd_flow_dump(void *fdb_domain __rte_unused,
2205 : : void *rx_domain __rte_unused,
2206 : : void *tx_domain __rte_unused, FILE *file __rte_unused)
2207 : : {
2208 : : int ret = 0;
2209 : :
2210 : : #ifdef HAVE_MLX5_DR_FLOW_DUMP
2211 [ # # ]: 0 : if (fdb_domain) {
2212 : 0 : ret = mlx5_glue->dr_dump_domain(file, fdb_domain);
2213 [ # # ]: 0 : if (ret)
2214 : : return ret;
2215 : : }
2216 : : MLX5_ASSERT(rx_domain);
2217 : 0 : ret = mlx5_glue->dr_dump_domain(file, rx_domain);
2218 [ # # ]: 0 : if (ret)
2219 : : return ret;
2220 : : MLX5_ASSERT(tx_domain);
2221 : 0 : ret = mlx5_glue->dr_dump_domain(file, tx_domain);
2222 : : #else
2223 : : ret = ENOTSUP;
2224 : : #endif
2225 : 0 : return -ret;
2226 : : }
2227 : :
2228 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_flow_single_dump)
2229 : : int
2230 : 0 : mlx5_devx_cmd_flow_single_dump(void *rule_info __rte_unused,
2231 : : FILE *file __rte_unused)
2232 : : {
2233 : : int ret = 0;
2234 : : #ifdef HAVE_MLX5_DR_FLOW_DUMP_RULE
2235 [ # # ]: 0 : if (rule_info)
2236 : 0 : ret = mlx5_glue->dr_dump_rule(file, rule_info);
2237 : : #else
2238 : : ret = ENOTSUP;
2239 : : #endif
2240 : 0 : return -ret;
2241 : : }
2242 : :
2243 : : /*
2244 : : * Create CQ using DevX API.
2245 : : *
2246 : : * @param[in] ctx
2247 : : * Context returned from mlx5 open_device() glue function.
2248 : : * @param [in] attr
2249 : : * Pointer to CQ attributes structure.
2250 : : *
2251 : : * @return
2252 : : * The DevX object created, NULL otherwise and rte_errno is set.
2253 : : */
2254 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_create_cq)
2255 : : struct mlx5_devx_obj *
2256 : 0 : mlx5_devx_cmd_create_cq(void *ctx, struct mlx5_devx_cq_attr *attr)
2257 : : {
2258 : 0 : uint32_t in[MLX5_ST_SZ_DW(create_cq_in)] = {0};
2259 : 0 : uint32_t out[MLX5_ST_SZ_DW(create_cq_out)] = {0};
2260 : 0 : struct mlx5_devx_obj *cq_obj = mlx5_malloc(MLX5_MEM_ZERO,
2261 : : sizeof(*cq_obj),
2262 : : 0, SOCKET_ID_ANY);
2263 : : void *cqctx = MLX5_ADDR_OF(create_cq_in, in, cq_context);
2264 : :
2265 [ # # ]: 0 : if (!cq_obj) {
2266 : 0 : DRV_LOG(ERR, "Failed to allocate CQ object memory.");
2267 : 0 : rte_errno = ENOMEM;
2268 : 0 : return NULL;
2269 : : }
2270 [ # # ]: 0 : MLX5_SET(create_cq_in, in, opcode, MLX5_CMD_OP_CREATE_CQ);
2271 [ # # ]: 0 : if (attr->db_umem_valid) {
2272 [ # # ]: 0 : MLX5_SET(cqc, cqctx, dbr_umem_valid, attr->db_umem_valid);
2273 [ # # ]: 0 : MLX5_SET(cqc, cqctx, dbr_umem_id, attr->db_umem_id);
2274 [ # # ]: 0 : MLX5_SET64(cqc, cqctx, dbr_addr, attr->db_umem_offset);
2275 : : } else {
2276 [ # # ]: 0 : MLX5_SET64(cqc, cqctx, dbr_addr, attr->db_addr);
2277 : : }
2278 [ # # ]: 0 : MLX5_SET(cqc, cqctx, cqe_sz, (RTE_CACHE_LINE_SIZE == 128) ?
2279 : : MLX5_CQE_SIZE_128B : MLX5_CQE_SIZE_64B);
2280 [ # # ]: 0 : MLX5_SET(cqc, cqctx, cc, attr->use_first_only);
2281 [ # # ]: 0 : MLX5_SET(cqc, cqctx, oi, attr->overrun_ignore);
2282 [ # # ]: 0 : MLX5_SET(cqc, cqctx, log_cq_size, attr->log_cq_size);
2283 [ # # ]: 0 : if (attr->log_page_size > MLX5_ADAPTER_PAGE_SHIFT)
2284 [ # # ]: 0 : MLX5_SET(cqc, cqctx, log_page_size,
2285 : : attr->log_page_size - MLX5_ADAPTER_PAGE_SHIFT);
2286 [ # # ]: 0 : MLX5_SET(cqc, cqctx, c_eqn, attr->eqn);
2287 [ # # ]: 0 : MLX5_SET(cqc, cqctx, uar_page, attr->uar_page_id);
2288 [ # # ]: 0 : MLX5_SET(cqc, cqctx, cqe_comp_en, !!attr->cqe_comp_en);
2289 [ # # ]: 0 : MLX5_SET(cqc, cqctx, cqe_comp_layout, !!attr->cqe_comp_layout);
2290 [ # # ]: 0 : MLX5_SET(cqc, cqctx, mini_cqe_res_format, attr->mini_cqe_res_format);
2291 [ # # ]: 0 : MLX5_SET(cqc, cqctx, mini_cqe_res_format_ext,
2292 : : attr->mini_cqe_res_format_ext);
2293 [ # # ]: 0 : if (attr->q_umem_valid) {
2294 [ # # ]: 0 : MLX5_SET(create_cq_in, in, cq_umem_valid, attr->q_umem_valid);
2295 [ # # ]: 0 : MLX5_SET(create_cq_in, in, cq_umem_id, attr->q_umem_id);
2296 [ # # ]: 0 : MLX5_SET64(create_cq_in, in, cq_umem_offset,
2297 : : attr->q_umem_offset);
2298 : : }
2299 : 0 : cq_obj->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in), out,
2300 : : sizeof(out));
2301 [ # # ]: 0 : if (!cq_obj->obj) {
2302 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "create CQ", NULL, 0);
2303 : 0 : mlx5_free(cq_obj);
2304 : 0 : return NULL;
2305 : : }
2306 [ # # ]: 0 : cq_obj->id = MLX5_GET(create_cq_out, out, cqn);
2307 : 0 : return cq_obj;
2308 : : }
2309 : :
2310 : : /*
2311 : : * Query CQ using DevX API.
2312 : : *
2313 : : * @param[in] cq_obj
2314 : : * CQ Devx Object
2315 : : * @param[out] out
2316 : : * CQ Query Output
2317 : : * @param[in] outlen
2318 : : * CQ Query Output Length
2319 : : *
2320 : : * @return
2321 : : * 0 if Query successful, else non-zero return value from devx_obj_query API
2322 : : */
2323 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_query_cq)
2324 : : int
2325 : 0 : mlx5_devx_cmd_query_cq(struct mlx5_devx_obj *cq_obj, void *out, size_t outlen)
2326 : : {
2327 : 0 : uint32_t in[MLX5_ST_SZ_DW(query_cq_in)] = {0};
2328 : : int rc;
2329 : :
2330 : 0 : MLX5_SET(query_cq_in, in, opcode, MLX5_CMD_OP_QUERY_CQ);
2331 : 0 : MLX5_SET(query_cq_in, in, cqn, cq_obj->id);
2332 : 0 : rc = mlx5_glue->devx_obj_query(cq_obj->obj, in, sizeof(in), out, outlen);
2333 [ # # # # : 0 : if (rc || MLX5_FW_STATUS(out)) {
# # # # ]
2334 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "CQ query", "cq_id", cq_obj->id);
2335 [ # # ]: 0 : return MLX5_DEVX_ERR_RC(rc);
2336 : : }
2337 : : return 0;
2338 : : }
2339 : :
2340 : : /**
2341 : : * Create VIRTQ using DevX API.
2342 : : *
2343 : : * @param[in] ctx
2344 : : * Context returned from mlx5 open_device() glue function.
2345 : : * @param [in] attr
2346 : : * Pointer to VIRTQ attributes structure.
2347 : : *
2348 : : * @return
2349 : : * The DevX object created, NULL otherwise and rte_errno is set.
2350 : : */
2351 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_create_virtq)
2352 : : struct mlx5_devx_obj *
2353 : 0 : mlx5_devx_cmd_create_virtq(void *ctx,
2354 : : struct mlx5_devx_virtq_attr *attr)
2355 : : {
2356 : 0 : uint32_t in[MLX5_ST_SZ_DW(create_virtq_in)] = {0};
2357 : 0 : uint32_t out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)] = {0};
2358 : 0 : struct mlx5_devx_obj *virtq_obj = mlx5_malloc(MLX5_MEM_ZERO,
2359 : : sizeof(*virtq_obj),
2360 : : 0, SOCKET_ID_ANY);
2361 : : void *virtq = MLX5_ADDR_OF(create_virtq_in, in, virtq);
2362 : : void *hdr = MLX5_ADDR_OF(create_virtq_in, in, hdr);
2363 : : void *virtctx = MLX5_ADDR_OF(virtio_net_q, virtq, virtio_q_context);
2364 : :
2365 [ # # ]: 0 : if (!virtq_obj) {
2366 : 0 : DRV_LOG(ERR, "Failed to allocate virtq data.");
2367 : 0 : rte_errno = ENOMEM;
2368 : 0 : return NULL;
2369 : : }
2370 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, hdr, opcode,
2371 : : MLX5_CMD_OP_CREATE_GENERAL_OBJECT);
2372 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, hdr, obj_type,
2373 : : MLX5_GENERAL_OBJ_TYPE_VIRTQ);
2374 [ # # ]: 0 : MLX5_SET16(virtio_net_q, virtq, hw_available_index,
2375 : : attr->hw_available_index);
2376 [ # # ]: 0 : MLX5_SET16(virtio_net_q, virtq, hw_used_index, attr->hw_used_index);
2377 [ # # ]: 0 : MLX5_SET16(virtio_net_q, virtq, tso_ipv4, attr->tso_ipv4);
2378 [ # # ]: 0 : MLX5_SET16(virtio_net_q, virtq, tso_ipv6, attr->tso_ipv6);
2379 [ # # ]: 0 : MLX5_SET16(virtio_net_q, virtq, tx_csum, attr->tx_csum);
2380 [ # # ]: 0 : MLX5_SET16(virtio_net_q, virtq, rx_csum, attr->rx_csum);
2381 [ # # ]: 0 : MLX5_SET16(virtio_q, virtctx, virtio_version_1_0,
2382 : : attr->virtio_version_1_0);
2383 [ # # ]: 0 : MLX5_SET16(virtio_q, virtctx, event_mode, attr->event_mode);
2384 [ # # ]: 0 : MLX5_SET(virtio_q, virtctx, event_qpn_or_msix, attr->qp_id);
2385 [ # # ]: 0 : MLX5_SET64(virtio_q, virtctx, desc_addr, attr->desc_addr);
2386 [ # # ]: 0 : MLX5_SET64(virtio_q, virtctx, used_addr, attr->used_addr);
2387 [ # # ]: 0 : MLX5_SET64(virtio_q, virtctx, available_addr, attr->available_addr);
2388 [ # # ]: 0 : MLX5_SET16(virtio_q, virtctx, queue_index, attr->queue_index);
2389 [ # # ]: 0 : MLX5_SET16(virtio_q, virtctx, queue_size, attr->q_size);
2390 [ # # ]: 0 : MLX5_SET(virtio_q, virtctx, virtio_q_mkey, attr->mkey);
2391 [ # # ]: 0 : MLX5_SET(virtio_q, virtctx, umem_1_id, attr->umems[0].id);
2392 [ # # ]: 0 : MLX5_SET(virtio_q, virtctx, umem_1_size, attr->umems[0].size);
2393 [ # # ]: 0 : MLX5_SET64(virtio_q, virtctx, umem_1_offset, attr->umems[0].offset);
2394 [ # # ]: 0 : MLX5_SET(virtio_q, virtctx, umem_2_id, attr->umems[1].id);
2395 [ # # ]: 0 : MLX5_SET(virtio_q, virtctx, umem_2_size, attr->umems[1].size);
2396 [ # # ]: 0 : MLX5_SET64(virtio_q, virtctx, umem_2_offset, attr->umems[1].offset);
2397 [ # # ]: 0 : MLX5_SET(virtio_q, virtctx, umem_3_id, attr->umems[2].id);
2398 [ # # ]: 0 : MLX5_SET(virtio_q, virtctx, umem_3_size, attr->umems[2].size);
2399 [ # # ]: 0 : MLX5_SET64(virtio_q, virtctx, umem_3_offset, attr->umems[2].offset);
2400 [ # # ]: 0 : MLX5_SET(virtio_q, virtctx, counter_set_id, attr->counters_obj_id);
2401 [ # # ]: 0 : MLX5_SET(virtio_q, virtctx, pd, attr->pd);
2402 [ # # ]: 0 : MLX5_SET(virtio_q, virtctx, queue_period_mode, attr->hw_latency_mode);
2403 [ # # ]: 0 : MLX5_SET(virtio_q, virtctx, queue_period_us, attr->hw_max_latency_us);
2404 [ # # ]: 0 : MLX5_SET(virtio_q, virtctx, queue_max_count, attr->hw_max_pending_comp);
2405 [ # # ]: 0 : MLX5_SET(virtio_net_q, virtq, tisn_or_qpn, attr->tis_id);
2406 : 0 : virtq_obj->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in), out,
2407 : : sizeof(out));
2408 [ # # ]: 0 : if (!virtq_obj->obj) {
2409 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "create VIRTQ", NULL, 0);
2410 : 0 : mlx5_free(virtq_obj);
2411 : 0 : return NULL;
2412 : : }
2413 [ # # ]: 0 : virtq_obj->id = MLX5_GET(general_obj_out_cmd_hdr, out, obj_id);
2414 : 0 : return virtq_obj;
2415 : : }
2416 : :
2417 : : /**
2418 : : * Modify VIRTQ using DevX API.
2419 : : *
2420 : : * @param[in] virtq_obj
2421 : : * Pointer to virtq object structure.
2422 : : * @param [in] attr
2423 : : * Pointer to modify virtq attributes structure.
2424 : : *
2425 : : * @return
2426 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2427 : : */
2428 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_modify_virtq)
2429 : : int
2430 : 0 : mlx5_devx_cmd_modify_virtq(struct mlx5_devx_obj *virtq_obj,
2431 : : struct mlx5_devx_virtq_attr *attr)
2432 : : {
2433 : 0 : uint32_t in[MLX5_ST_SZ_DW(create_virtq_in)] = {0};
2434 : 0 : uint32_t out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)] = {0};
2435 : : void *virtq = MLX5_ADDR_OF(create_virtq_in, in, virtq);
2436 : : void *hdr = MLX5_ADDR_OF(create_virtq_in, in, hdr);
2437 : : void *virtctx = MLX5_ADDR_OF(virtio_net_q, virtq, virtio_q_context);
2438 : : int ret;
2439 : :
2440 : 0 : MLX5_SET(general_obj_in_cmd_hdr, hdr, opcode,
2441 : : MLX5_CMD_OP_MODIFY_GENERAL_OBJECT);
2442 : 0 : MLX5_SET(general_obj_in_cmd_hdr, hdr, obj_type,
2443 : : MLX5_GENERAL_OBJ_TYPE_VIRTQ);
2444 : 0 : MLX5_SET(general_obj_in_cmd_hdr, hdr, obj_id, virtq_obj->id);
2445 [ # # ]: 0 : MLX5_SET64(virtio_net_q, virtq, modify_field_select,
2446 : : attr->mod_fields_bitmap);
2447 : 0 : MLX5_SET16(virtio_q, virtctx, queue_index, attr->queue_index);
2448 [ # # ]: 0 : if (!attr->mod_fields_bitmap) {
2449 : 0 : DRV_LOG(ERR, "Failed to modify VIRTQ for no type set.");
2450 : 0 : rte_errno = EINVAL;
2451 : 0 : return -rte_errno;
2452 : : }
2453 [ # # ]: 0 : if (attr->mod_fields_bitmap & MLX5_VIRTQ_MODIFY_TYPE_STATE)
2454 : 0 : MLX5_SET16(virtio_net_q, virtq, state, attr->state);
2455 [ # # ]: 0 : if (attr->mod_fields_bitmap &
2456 : : MLX5_VIRTQ_MODIFY_TYPE_DIRTY_BITMAP_PARAMS) {
2457 : 0 : MLX5_SET(virtio_net_q, virtq, dirty_bitmap_mkey,
2458 : : attr->dirty_bitmap_mkey);
2459 [ # # ]: 0 : MLX5_SET64(virtio_net_q, virtq, dirty_bitmap_addr,
2460 : : attr->dirty_bitmap_addr);
2461 : 0 : MLX5_SET(virtio_net_q, virtq, dirty_bitmap_size,
2462 : : attr->dirty_bitmap_size);
2463 : : }
2464 [ # # ]: 0 : if (attr->mod_fields_bitmap &
2465 : : MLX5_VIRTQ_MODIFY_TYPE_DIRTY_BITMAP_DUMP_ENABLE)
2466 [ # # ]: 0 : MLX5_SET(virtio_net_q, virtq, dirty_bitmap_dump_enable,
2467 : : attr->dirty_bitmap_dump_enable);
2468 [ # # ]: 0 : if (attr->mod_fields_bitmap & MLX5_VIRTQ_MODIFY_TYPE_QUEUE_PERIOD) {
2469 : 0 : MLX5_SET(virtio_q, virtctx, queue_period_mode,
2470 : : attr->hw_latency_mode);
2471 [ # # ]: 0 : MLX5_SET(virtio_q, virtctx, queue_period_us,
2472 : : attr->hw_max_latency_us);
2473 [ # # ]: 0 : MLX5_SET(virtio_q, virtctx, queue_max_count,
2474 : : attr->hw_max_pending_comp);
2475 : : }
2476 [ # # ]: 0 : if (attr->mod_fields_bitmap & MLX5_VIRTQ_MODIFY_TYPE_ADDR) {
2477 [ # # ]: 0 : MLX5_SET64(virtio_q, virtctx, desc_addr, attr->desc_addr);
2478 [ # # ]: 0 : MLX5_SET64(virtio_q, virtctx, used_addr, attr->used_addr);
2479 [ # # ]: 0 : MLX5_SET64(virtio_q, virtctx, available_addr,
2480 : : attr->available_addr);
2481 : : }
2482 [ # # ]: 0 : if (attr->mod_fields_bitmap & MLX5_VIRTQ_MODIFY_TYPE_HW_AVAILABLE_INDEX)
2483 : 0 : MLX5_SET16(virtio_net_q, virtq, hw_available_index,
2484 : : attr->hw_available_index);
2485 [ # # ]: 0 : if (attr->mod_fields_bitmap & MLX5_VIRTQ_MODIFY_TYPE_HW_USED_INDEX)
2486 : 0 : MLX5_SET16(virtio_net_q, virtq, hw_used_index,
2487 : : attr->hw_used_index);
2488 [ # # ]: 0 : if (attr->mod_fields_bitmap & MLX5_VIRTQ_MODIFY_TYPE_Q_TYPE)
2489 : 0 : MLX5_SET16(virtio_q, virtctx, virtio_q_type, attr->q_type);
2490 [ # # ]: 0 : if (attr->mod_fields_bitmap & MLX5_VIRTQ_MODIFY_TYPE_VERSION_1_0)
2491 : 0 : MLX5_SET16(virtio_q, virtctx, virtio_version_1_0,
2492 : : attr->virtio_version_1_0);
2493 [ # # ]: 0 : if (attr->mod_fields_bitmap & MLX5_VIRTQ_MODIFY_TYPE_Q_MKEY)
2494 : 0 : MLX5_SET(virtio_q, virtctx, virtio_q_mkey, attr->mkey);
2495 [ # # ]: 0 : if (attr->mod_fields_bitmap &
2496 : : MLX5_VIRTQ_MODIFY_TYPE_QUEUE_FEATURE_BIT_MASK) {
2497 [ # # ]: 0 : MLX5_SET16(virtio_net_q, virtq, tso_ipv4, attr->tso_ipv4);
2498 [ # # ]: 0 : MLX5_SET16(virtio_net_q, virtq, tso_ipv6, attr->tso_ipv6);
2499 [ # # ]: 0 : MLX5_SET16(virtio_net_q, virtq, tx_csum, attr->tx_csum);
2500 [ # # ]: 0 : MLX5_SET16(virtio_net_q, virtq, rx_csum, attr->rx_csum);
2501 : : }
2502 [ # # ]: 0 : if (attr->mod_fields_bitmap & MLX5_VIRTQ_MODIFY_TYPE_EVENT_MODE) {
2503 [ # # ]: 0 : MLX5_SET16(virtio_q, virtctx, event_mode, attr->event_mode);
2504 [ # # ]: 0 : MLX5_SET(virtio_q, virtctx, event_qpn_or_msix, attr->qp_id);
2505 : : }
2506 : 0 : ret = mlx5_glue->devx_obj_modify(virtq_obj->obj, in, sizeof(in),
2507 : : out, sizeof(out));
2508 [ # # ]: 0 : if (ret) {
2509 : 0 : DRV_LOG(ERR, "Failed to modify VIRTQ using DevX.");
2510 : 0 : rte_errno = errno;
2511 : 0 : return -rte_errno;
2512 : : }
2513 : : return ret;
2514 : : }
2515 : :
2516 : : /**
2517 : : * Query VIRTQ using DevX API.
2518 : : *
2519 : : * @param[in] virtq_obj
2520 : : * Pointer to virtq object structure.
2521 : : * @param [in/out] attr
2522 : : * Pointer to virtq attributes structure.
2523 : : *
2524 : : * @return
2525 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2526 : : */
2527 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_query_virtq)
2528 : : int
2529 : 0 : mlx5_devx_cmd_query_virtq(struct mlx5_devx_obj *virtq_obj,
2530 : : struct mlx5_devx_virtq_attr *attr)
2531 : : {
2532 : 0 : uint32_t in[MLX5_ST_SZ_DW(general_obj_in_cmd_hdr)] = {0};
2533 : 0 : uint32_t out[MLX5_ST_SZ_DW(query_virtq_out)] = {0};
2534 : : void *hdr = MLX5_ADDR_OF(query_virtq_out, in, hdr);
2535 : : void *virtq = MLX5_ADDR_OF(query_virtq_out, out, virtq);
2536 : : int ret;
2537 : :
2538 : 0 : MLX5_SET(general_obj_in_cmd_hdr, hdr, opcode,
2539 : : MLX5_CMD_OP_QUERY_GENERAL_OBJECT);
2540 : 0 : MLX5_SET(general_obj_in_cmd_hdr, hdr, obj_type,
2541 : : MLX5_GENERAL_OBJ_TYPE_VIRTQ);
2542 : 0 : MLX5_SET(general_obj_in_cmd_hdr, hdr, obj_id, virtq_obj->id);
2543 : 0 : ret = mlx5_glue->devx_obj_query(virtq_obj->obj, in, sizeof(in),
2544 : : out, sizeof(out));
2545 [ # # ]: 0 : if (ret) {
2546 : 0 : DRV_LOG(ERR, "Failed to modify VIRTQ using DevX.");
2547 : 0 : rte_errno = errno;
2548 : 0 : return -errno;
2549 : : }
2550 [ # # ]: 0 : attr->hw_available_index = MLX5_GET16(virtio_net_q, virtq,
2551 : : hw_available_index);
2552 [ # # ]: 0 : attr->hw_used_index = MLX5_GET16(virtio_net_q, virtq, hw_used_index);
2553 [ # # ]: 0 : attr->state = MLX5_GET16(virtio_net_q, virtq, state);
2554 [ # # ]: 0 : attr->error_type = MLX5_GET16(virtio_net_q, virtq,
2555 : : virtio_q_context.error_type);
2556 : 0 : return ret;
2557 : : }
2558 : :
2559 : : /**
2560 : : * Create QP using DevX API.
2561 : : *
2562 : : * @param[in] ctx
2563 : : * Context returned from mlx5 open_device() glue function.
2564 : : * @param [in] attr
2565 : : * Pointer to QP attributes structure.
2566 : : *
2567 : : * @return
2568 : : * The DevX object created, NULL otherwise and rte_errno is set.
2569 : : */
2570 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_create_qp)
2571 : : struct mlx5_devx_obj *
2572 : 0 : mlx5_devx_cmd_create_qp(void *ctx,
2573 : : struct mlx5_devx_qp_attr *attr)
2574 : : {
2575 : 0 : uint32_t in[MLX5_ST_SZ_DW(create_qp_in)] = {0};
2576 : 0 : uint32_t out[MLX5_ST_SZ_DW(create_qp_out)] = {0};
2577 : 0 : struct mlx5_devx_obj *qp_obj = mlx5_malloc(MLX5_MEM_ZERO,
2578 : : sizeof(*qp_obj),
2579 : : 0, SOCKET_ID_ANY);
2580 : : void *qpc = MLX5_ADDR_OF(create_qp_in, in, qpc);
2581 : :
2582 [ # # ]: 0 : if (!qp_obj) {
2583 : 0 : DRV_LOG(ERR, "Failed to allocate QP data.");
2584 : 0 : rte_errno = ENOMEM;
2585 : 0 : return NULL;
2586 : : }
2587 [ # # ]: 0 : MLX5_SET(create_qp_in, in, opcode, MLX5_CMD_OP_CREATE_QP);
2588 [ # # ]: 0 : MLX5_SET(qpc, qpc, st, MLX5_QP_ST_RC);
2589 [ # # ]: 0 : MLX5_SET(qpc, qpc, pd, attr->pd);
2590 [ # # ]: 0 : MLX5_SET(qpc, qpc, ts_format, attr->ts_format);
2591 [ # # ]: 0 : MLX5_SET(qpc, qpc, user_index, attr->user_index);
2592 [ # # ]: 0 : if (attr->uar_index) {
2593 [ # # ]: 0 : if (attr->mmo) {
2594 : : void *qpc_ext_and_pas_list = MLX5_ADDR_OF(create_qp_in,
2595 : : in, qpc_extension_and_pas_list);
2596 : : void *qpc_ext = MLX5_ADDR_OF(qpc_extension_and_pas_list,
2597 : : qpc_ext_and_pas_list, qpc_data_extension);
2598 : :
2599 [ # # ]: 0 : MLX5_SET(create_qp_in, in, qpc_ext, 1);
2600 [ # # ]: 0 : MLX5_SET(qpc_extension, qpc_ext, mmo, 1);
2601 : : }
2602 [ # # ]: 0 : MLX5_SET(qpc, qpc, pm_state, MLX5_QP_PM_MIGRATED);
2603 [ # # ]: 0 : MLX5_SET(qpc, qpc, uar_page, attr->uar_index);
2604 [ # # ]: 0 : if (attr->log_page_size > MLX5_ADAPTER_PAGE_SHIFT)
2605 [ # # ]: 0 : MLX5_SET(qpc, qpc, log_page_size,
2606 : : attr->log_page_size - MLX5_ADAPTER_PAGE_SHIFT);
2607 [ # # ]: 0 : if (attr->num_of_send_wqbbs) {
2608 : : MLX5_ASSERT(RTE_IS_POWER_OF_2(attr->num_of_send_wqbbs));
2609 [ # # ]: 0 : MLX5_SET(qpc, qpc, cqn_snd, attr->cqn);
2610 [ # # ]: 0 : MLX5_SET(qpc, qpc, log_sq_size,
2611 : : rte_log2_u32(attr->num_of_send_wqbbs));
2612 : : } else {
2613 [ # # ]: 0 : MLX5_SET(qpc, qpc, no_sq, 1);
2614 : : }
2615 [ # # ]: 0 : if (attr->num_of_receive_wqes) {
2616 : : MLX5_ASSERT(RTE_IS_POWER_OF_2(
2617 : : attr->num_of_receive_wqes));
2618 [ # # ]: 0 : MLX5_SET(qpc, qpc, cqn_rcv, attr->cqn);
2619 [ # # ]: 0 : MLX5_SET(qpc, qpc, log_rq_stride, attr->log_rq_stride -
2620 : : MLX5_LOG_RQ_STRIDE_SHIFT);
2621 [ # # # # ]: 0 : MLX5_SET(qpc, qpc, log_rq_size,
2622 : : rte_log2_u32(attr->num_of_receive_wqes));
2623 [ # # ]: 0 : MLX5_SET(qpc, qpc, rq_type, MLX5_NON_ZERO_RQ);
2624 : : } else {
2625 [ # # ]: 0 : MLX5_SET(qpc, qpc, rq_type, MLX5_ZERO_LEN_RQ);
2626 : : }
2627 [ # # ]: 0 : if (attr->dbr_umem_valid) {
2628 [ # # ]: 0 : MLX5_SET(qpc, qpc, dbr_umem_valid,
2629 : : attr->dbr_umem_valid);
2630 [ # # ]: 0 : MLX5_SET(qpc, qpc, dbr_umem_id, attr->dbr_umem_id);
2631 : : }
2632 [ # # ]: 0 : if (attr->cd_master)
2633 [ # # ]: 0 : MLX5_SET(qpc, qpc, cd_master, attr->cd_master);
2634 [ # # ]: 0 : if (attr->cd_slave_send)
2635 [ # # ]: 0 : MLX5_SET(qpc, qpc, cd_slave_send, attr->cd_slave_send);
2636 [ # # ]: 0 : if (attr->cd_slave_recv)
2637 [ # # ]: 0 : MLX5_SET(qpc, qpc, cd_slave_receive, attr->cd_slave_recv);
2638 [ # # ]: 0 : MLX5_SET64(qpc, qpc, dbr_addr, attr->dbr_address);
2639 [ # # ]: 0 : MLX5_SET64(create_qp_in, in, wq_umem_offset,
2640 : : attr->wq_umem_offset);
2641 [ # # ]: 0 : MLX5_SET(create_qp_in, in, wq_umem_id, attr->wq_umem_id);
2642 [ # # ]: 0 : MLX5_SET(create_qp_in, in, wq_umem_valid, 1);
2643 : : } else {
2644 : : /* Special QP to be managed by FW - no SQ\RQ\CQ\UAR\DB rec. */
2645 [ # # ]: 0 : MLX5_SET(qpc, qpc, rq_type, MLX5_ZERO_LEN_RQ);
2646 [ # # ]: 0 : MLX5_SET(qpc, qpc, no_sq, 1);
2647 : : }
2648 : 0 : qp_obj->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in), out,
2649 : : sizeof(out));
2650 [ # # ]: 0 : if (!qp_obj->obj) {
2651 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "create QP", NULL, 0);
2652 : 0 : mlx5_free(qp_obj);
2653 : 0 : return NULL;
2654 : : }
2655 [ # # ]: 0 : qp_obj->id = MLX5_GET(create_qp_out, out, qpn);
2656 : 0 : return qp_obj;
2657 : : }
2658 : :
2659 : : /**
2660 : : * Modify QP using DevX API.
2661 : : * Currently supports only force loop-back QP.
2662 : : *
2663 : : * @param[in] qp
2664 : : * Pointer to QP object structure.
2665 : : * @param [in] qp_st_mod_op
2666 : : * The QP state modification operation.
2667 : : * @param [in] remote_qp_id
2668 : : * The remote QP ID for MLX5_CMD_OP_INIT2RTR_QP operation.
2669 : : *
2670 : : * @return
2671 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2672 : : */
2673 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_modify_qp_state)
2674 : : int
2675 : 0 : mlx5_devx_cmd_modify_qp_state(struct mlx5_devx_obj *qp, uint32_t qp_st_mod_op,
2676 : : uint32_t remote_qp_id)
2677 : : {
2678 : : union {
2679 : : uint32_t rst2init[MLX5_ST_SZ_DW(rst2init_qp_in)];
2680 : : uint32_t init2rtr[MLX5_ST_SZ_DW(init2rtr_qp_in)];
2681 : : uint32_t rtr2rts[MLX5_ST_SZ_DW(rtr2rts_qp_in)];
2682 : : uint32_t qp2rst[MLX5_ST_SZ_DW(2rst_qp_in)];
2683 : : } in;
2684 : : union {
2685 : : uint32_t rst2init[MLX5_ST_SZ_DW(rst2init_qp_out)];
2686 : : uint32_t init2rtr[MLX5_ST_SZ_DW(init2rtr_qp_out)];
2687 : : uint32_t rtr2rts[MLX5_ST_SZ_DW(rtr2rts_qp_out)];
2688 : : uint32_t qp2rst[MLX5_ST_SZ_DW(2rst_qp_out)];
2689 : : } out;
2690 : : void *qpc;
2691 : : int ret;
2692 : : unsigned int inlen;
2693 : : unsigned int outlen;
2694 : :
2695 : : memset(&in, 0, sizeof(in));
2696 : : memset(&out, 0, sizeof(out));
2697 : 0 : MLX5_SET(rst2init_qp_in, &in, opcode, qp_st_mod_op);
2698 [ # # # # : 0 : switch (qp_st_mod_op) {
# ]
2699 : 0 : case MLX5_CMD_OP_RST2INIT_QP:
2700 : 0 : MLX5_SET(rst2init_qp_in, &in, qpn, qp->id);
2701 : : qpc = MLX5_ADDR_OF(rst2init_qp_in, &in, qpc);
2702 : 0 : MLX5_SET(qpc, qpc, primary_address_path.vhca_port_num, 1);
2703 : : MLX5_SET(qpc, qpc, rre, 1);
2704 [ # # ]: 0 : MLX5_SET(qpc, qpc, rwe, 1);
2705 : 0 : MLX5_SET(qpc, qpc, pm_state, MLX5_QP_PM_MIGRATED);
2706 : : inlen = sizeof(in.rst2init);
2707 : : outlen = sizeof(out.rst2init);
2708 : 0 : break;
2709 : 0 : case MLX5_CMD_OP_INIT2RTR_QP:
2710 : 0 : MLX5_SET(init2rtr_qp_in, &in, qpn, qp->id);
2711 : : qpc = MLX5_ADDR_OF(init2rtr_qp_in, &in, qpc);
2712 : 0 : MLX5_SET(qpc, qpc, primary_address_path.fl, 1);
2713 : 0 : MLX5_SET(qpc, qpc, primary_address_path.vhca_port_num, 1);
2714 : : MLX5_SET(qpc, qpc, mtu, 1);
2715 [ # # ]: 0 : MLX5_SET(qpc, qpc, log_msg_max, 30);
2716 : 0 : MLX5_SET(qpc, qpc, remote_qpn, remote_qp_id);
2717 : 0 : MLX5_SET(qpc, qpc, min_rnr_nak, 0);
2718 : : inlen = sizeof(in.init2rtr);
2719 : : outlen = sizeof(out.init2rtr);
2720 : 0 : break;
2721 : 0 : case MLX5_CMD_OP_RTR2RTS_QP:
2722 : : qpc = MLX5_ADDR_OF(rtr2rts_qp_in, &in, qpc);
2723 : 0 : MLX5_SET(rtr2rts_qp_in, &in, qpn, qp->id);
2724 : 0 : MLX5_SET(qpc, qpc, primary_address_path.ack_timeout, 16);
2725 : : MLX5_SET(qpc, qpc, log_ack_req_freq, 0);
2726 [ # # ]: 0 : MLX5_SET(qpc, qpc, retry_count, 7);
2727 [ # # ]: 0 : MLX5_SET(qpc, qpc, rnr_retry, 7);
2728 : : inlen = sizeof(in.rtr2rts);
2729 : : outlen = sizeof(out.rtr2rts);
2730 : 0 : break;
2731 : 0 : case MLX5_CMD_OP_QP_2RST:
2732 : 0 : MLX5_SET(2rst_qp_in, &in, qpn, qp->id);
2733 : : inlen = sizeof(in.qp2rst);
2734 : : outlen = sizeof(out.qp2rst);
2735 : 0 : break;
2736 : 0 : default:
2737 : 0 : DRV_LOG(ERR, "Invalid or unsupported QP modify op %u.",
2738 : : qp_st_mod_op);
2739 : 0 : rte_errno = EINVAL;
2740 : 0 : return -rte_errno;
2741 : : }
2742 : 0 : ret = mlx5_glue->devx_obj_modify(qp->obj, &in, inlen, &out, outlen);
2743 [ # # ]: 0 : if (ret) {
2744 : 0 : DRV_LOG(ERR, "Failed to modify QP using DevX.");
2745 : 0 : rte_errno = errno;
2746 : 0 : return -rte_errno;
2747 : : }
2748 : : return ret;
2749 : : }
2750 : :
2751 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_create_virtio_q_counters)
2752 : : struct mlx5_devx_obj *
2753 : 0 : mlx5_devx_cmd_create_virtio_q_counters(void *ctx)
2754 : : {
2755 : 0 : uint32_t in[MLX5_ST_SZ_DW(create_virtio_q_counters_in)] = {0};
2756 : 0 : uint32_t out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)] = {0};
2757 : 0 : struct mlx5_devx_obj *couners_obj = mlx5_malloc(MLX5_MEM_ZERO,
2758 : : sizeof(*couners_obj), 0,
2759 : : SOCKET_ID_ANY);
2760 : : void *hdr = MLX5_ADDR_OF(create_virtio_q_counters_in, in, hdr);
2761 : :
2762 [ # # ]: 0 : if (!couners_obj) {
2763 : 0 : DRV_LOG(ERR, "Failed to allocate virtio queue counters data.");
2764 : 0 : rte_errno = ENOMEM;
2765 : 0 : return NULL;
2766 : : }
2767 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, hdr, opcode,
2768 : : MLX5_CMD_OP_CREATE_GENERAL_OBJECT);
2769 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, hdr, obj_type,
2770 : : MLX5_GENERAL_OBJ_TYPE_VIRTIO_Q_COUNTERS);
2771 : 0 : couners_obj->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in), out,
2772 : : sizeof(out));
2773 [ # # ]: 0 : if (!couners_obj->obj) {
2774 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "create virtio queue counters Obj", NULL,
2775 : : 0);
2776 : 0 : mlx5_free(couners_obj);
2777 : 0 : return NULL;
2778 : : }
2779 [ # # ]: 0 : couners_obj->id = MLX5_GET(general_obj_out_cmd_hdr, out, obj_id);
2780 : 0 : return couners_obj;
2781 : : }
2782 : :
2783 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_query_virtio_q_counters)
2784 : : int
2785 : 0 : mlx5_devx_cmd_query_virtio_q_counters(struct mlx5_devx_obj *couners_obj,
2786 : : struct mlx5_devx_virtio_q_couners_attr *attr)
2787 : : {
2788 : 0 : uint32_t in[MLX5_ST_SZ_DW(general_obj_in_cmd_hdr)] = {0};
2789 : 0 : uint32_t out[MLX5_ST_SZ_DW(query_virtio_q_counters_out)] = {0};
2790 : : void *hdr = MLX5_ADDR_OF(query_virtio_q_counters_out, in, hdr);
2791 : : void *virtio_q_counters = MLX5_ADDR_OF(query_virtio_q_counters_out, out,
2792 : : virtio_q_counters);
2793 : : int ret;
2794 : :
2795 : 0 : MLX5_SET(general_obj_in_cmd_hdr, hdr, opcode,
2796 : : MLX5_CMD_OP_QUERY_GENERAL_OBJECT);
2797 : 0 : MLX5_SET(general_obj_in_cmd_hdr, hdr, obj_type,
2798 : : MLX5_GENERAL_OBJ_TYPE_VIRTIO_Q_COUNTERS);
2799 : 0 : MLX5_SET(general_obj_in_cmd_hdr, hdr, obj_id, couners_obj->id);
2800 : 0 : ret = mlx5_glue->devx_obj_query(couners_obj->obj, in, sizeof(in), out,
2801 : : sizeof(out));
2802 [ # # ]: 0 : if (ret) {
2803 : 0 : DRV_LOG(ERR, "Failed to query virtio q counters using DevX.");
2804 : 0 : rte_errno = errno;
2805 : 0 : return -errno;
2806 : : }
2807 [ # # ]: 0 : attr->received_desc = MLX5_GET64(virtio_q_counters, virtio_q_counters,
2808 : : received_desc);
2809 [ # # ]: 0 : attr->completed_desc = MLX5_GET64(virtio_q_counters, virtio_q_counters,
2810 : : completed_desc);
2811 [ # # ]: 0 : attr->error_cqes = MLX5_GET(virtio_q_counters, virtio_q_counters,
2812 : : error_cqes);
2813 [ # # ]: 0 : attr->bad_desc_errors = MLX5_GET(virtio_q_counters, virtio_q_counters,
2814 : : bad_desc_errors);
2815 [ # # ]: 0 : attr->exceed_max_chain = MLX5_GET(virtio_q_counters, virtio_q_counters,
2816 : : exceed_max_chain);
2817 [ # # ]: 0 : attr->invalid_buffer = MLX5_GET(virtio_q_counters, virtio_q_counters,
2818 : : invalid_buffer);
2819 : 0 : return ret;
2820 : : }
2821 : :
2822 : : /**
2823 : : * Create general object of type FLOW_HIT_ASO using DevX API.
2824 : : *
2825 : : * @param[in] ctx
2826 : : * Context returned from mlx5 open_device() glue function.
2827 : : * @param [in] pd
2828 : : * PD value to associate the FLOW_HIT_ASO object with.
2829 : : *
2830 : : * @return
2831 : : * The DevX object created, NULL otherwise and rte_errno is set.
2832 : : */
2833 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_create_flow_hit_aso_obj)
2834 : : struct mlx5_devx_obj *
2835 : 0 : mlx5_devx_cmd_create_flow_hit_aso_obj(void *ctx, uint32_t pd)
2836 : : {
2837 : 0 : uint32_t in[MLX5_ST_SZ_DW(create_flow_hit_aso_in)] = {0};
2838 : 0 : uint32_t out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)] = {0};
2839 : : struct mlx5_devx_obj *flow_hit_aso_obj = NULL;
2840 : : void *ptr = NULL;
2841 : :
2842 : 0 : flow_hit_aso_obj = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*flow_hit_aso_obj),
2843 : : 0, SOCKET_ID_ANY);
2844 [ # # ]: 0 : if (!flow_hit_aso_obj) {
2845 : 0 : DRV_LOG(ERR, "Failed to allocate FLOW_HIT_ASO object data");
2846 : 0 : rte_errno = ENOMEM;
2847 : 0 : return NULL;
2848 : : }
2849 : : ptr = MLX5_ADDR_OF(create_flow_hit_aso_in, in, hdr);
2850 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, ptr, opcode,
2851 : : MLX5_CMD_OP_CREATE_GENERAL_OBJECT);
2852 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, ptr, obj_type,
2853 : : MLX5_GENERAL_OBJ_TYPE_FLOW_HIT_ASO);
2854 : : ptr = MLX5_ADDR_OF(create_flow_hit_aso_in, in, flow_hit_aso);
2855 [ # # ]: 0 : MLX5_SET(flow_hit_aso, ptr, access_pd, pd);
2856 : 0 : flow_hit_aso_obj->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in),
2857 : : out, sizeof(out));
2858 [ # # ]: 0 : if (!flow_hit_aso_obj->obj) {
2859 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "create FLOW_HIT_ASO", NULL, 0);
2860 : 0 : mlx5_free(flow_hit_aso_obj);
2861 : 0 : return NULL;
2862 : : }
2863 [ # # ]: 0 : flow_hit_aso_obj->id = MLX5_GET(general_obj_out_cmd_hdr, out, obj_id);
2864 : 0 : return flow_hit_aso_obj;
2865 : : }
2866 : :
2867 : : /*
2868 : : * Create PD using DevX API.
2869 : : *
2870 : : * @param[in] ctx
2871 : : * Context returned from mlx5 open_device() glue function.
2872 : : *
2873 : : * @return
2874 : : * The DevX object created, NULL otherwise and rte_errno is set.
2875 : : */
2876 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_alloc_pd)
2877 : : struct mlx5_devx_obj *
2878 : 0 : mlx5_devx_cmd_alloc_pd(void *ctx)
2879 : : {
2880 : : struct mlx5_devx_obj *ppd =
2881 : 0 : mlx5_malloc(MLX5_MEM_ZERO, sizeof(*ppd), 0, SOCKET_ID_ANY);
2882 : 0 : u32 in[MLX5_ST_SZ_DW(alloc_pd_in)] = {0};
2883 : 0 : u32 out[MLX5_ST_SZ_DW(alloc_pd_out)] = {0};
2884 : :
2885 [ # # ]: 0 : if (!ppd) {
2886 : 0 : DRV_LOG(ERR, "Failed to allocate PD data.");
2887 : 0 : rte_errno = ENOMEM;
2888 : 0 : return NULL;
2889 : : }
2890 : 0 : MLX5_SET(alloc_pd_in, in, opcode, MLX5_CMD_OP_ALLOC_PD);
2891 : 0 : ppd->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in),
2892 : : out, sizeof(out));
2893 [ # # ]: 0 : if (!ppd->obj) {
2894 : 0 : mlx5_free(ppd);
2895 : 0 : DRV_LOG(ERR, "Failed to allocate PD Obj using DevX.");
2896 : 0 : rte_errno = errno;
2897 : 0 : return NULL;
2898 : : }
2899 [ # # ]: 0 : ppd->id = MLX5_GET(alloc_pd_out, out, pd);
2900 : 0 : return ppd;
2901 : : }
2902 : :
2903 : : /**
2904 : : * Create general object of type FLOW_METER_ASO using DevX API.
2905 : : *
2906 : : * @param[in] ctx
2907 : : * Context returned from mlx5 open_device() glue function.
2908 : : * @param [in] pd
2909 : : * PD value to associate the FLOW_METER_ASO object with.
2910 : : * @param [in] log_obj_size
2911 : : * log_obj_size define to allocate number of 2 * meters
2912 : : * in one FLOW_METER_ASO object.
2913 : : *
2914 : : * @return
2915 : : * The DevX object created, NULL otherwise and rte_errno is set.
2916 : : */
2917 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_create_flow_meter_aso_obj)
2918 : : struct mlx5_devx_obj *
2919 : 0 : mlx5_devx_cmd_create_flow_meter_aso_obj(void *ctx, uint32_t pd,
2920 : : uint32_t log_obj_size)
2921 : : {
2922 : 0 : uint32_t in[MLX5_ST_SZ_DW(create_flow_meter_aso_in)] = {0};
2923 : : uint32_t out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)];
2924 : : struct mlx5_devx_obj *flow_meter_aso_obj;
2925 : : void *ptr;
2926 : :
2927 : 0 : flow_meter_aso_obj = mlx5_malloc(MLX5_MEM_ZERO,
2928 : : sizeof(*flow_meter_aso_obj),
2929 : : 0, SOCKET_ID_ANY);
2930 [ # # ]: 0 : if (!flow_meter_aso_obj) {
2931 : 0 : DRV_LOG(ERR, "Failed to allocate FLOW_METER_ASO object data");
2932 : 0 : rte_errno = ENOMEM;
2933 : 0 : return NULL;
2934 : : }
2935 : : ptr = MLX5_ADDR_OF(create_flow_meter_aso_in, in, hdr);
2936 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, ptr, opcode,
2937 : : MLX5_CMD_OP_CREATE_GENERAL_OBJECT);
2938 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, ptr, obj_type,
2939 : : MLX5_GENERAL_OBJ_TYPE_FLOW_METER_ASO);
2940 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, ptr, log_obj_range,
2941 : : log_obj_size);
2942 : : ptr = MLX5_ADDR_OF(create_flow_meter_aso_in, in, flow_meter_aso);
2943 [ # # ]: 0 : MLX5_SET(flow_meter_aso, ptr, access_pd, pd);
2944 : 0 : flow_meter_aso_obj->obj = mlx5_glue->devx_obj_create(
2945 : : ctx, in, sizeof(in),
2946 : : out, sizeof(out));
2947 [ # # ]: 0 : if (!flow_meter_aso_obj->obj) {
2948 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "create FLOW_METTER_ASO", NULL, 0);
2949 : 0 : mlx5_free(flow_meter_aso_obj);
2950 : 0 : return NULL;
2951 : : }
2952 [ # # ]: 0 : flow_meter_aso_obj->id = MLX5_GET(general_obj_out_cmd_hdr,
2953 : : out, obj_id);
2954 : 0 : return flow_meter_aso_obj;
2955 : : }
2956 : :
2957 : : /*
2958 : : * Create general object of type CONN_TRACK_OFFLOAD using DevX API.
2959 : : *
2960 : : * @param[in] ctx
2961 : : * Context returned from mlx5 open_device() glue function.
2962 : : * @param [in] pd
2963 : : * PD value to associate the CONN_TRACK_OFFLOAD ASO object with.
2964 : : * @param [in] log_obj_size
2965 : : * log_obj_size to allocate its power of 2 * objects
2966 : : * in one CONN_TRACK_OFFLOAD bulk allocation.
2967 : : *
2968 : : * @return
2969 : : * The DevX object created, NULL otherwise and rte_errno is set.
2970 : : */
2971 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_create_conn_track_offload_obj)
2972 : : struct mlx5_devx_obj *
2973 : 0 : mlx5_devx_cmd_create_conn_track_offload_obj(void *ctx, uint32_t pd,
2974 : : uint32_t log_obj_size)
2975 : : {
2976 : 0 : uint32_t in[MLX5_ST_SZ_DW(create_conn_track_aso_in)] = {0};
2977 : : uint32_t out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)];
2978 : : struct mlx5_devx_obj *ct_aso_obj;
2979 : : void *ptr;
2980 : :
2981 : 0 : ct_aso_obj = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*ct_aso_obj),
2982 : : 0, SOCKET_ID_ANY);
2983 [ # # ]: 0 : if (!ct_aso_obj) {
2984 : 0 : DRV_LOG(ERR, "Failed to allocate CONN_TRACK_OFFLOAD object.");
2985 : 0 : rte_errno = ENOMEM;
2986 : 0 : return NULL;
2987 : : }
2988 : : ptr = MLX5_ADDR_OF(create_conn_track_aso_in, in, hdr);
2989 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, ptr, opcode,
2990 : : MLX5_CMD_OP_CREATE_GENERAL_OBJECT);
2991 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, ptr, obj_type,
2992 : : MLX5_GENERAL_OBJ_TYPE_CONN_TRACK_OFFLOAD);
2993 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, ptr, log_obj_range, log_obj_size);
2994 : : ptr = MLX5_ADDR_OF(create_conn_track_aso_in, in, conn_track_offload);
2995 [ # # ]: 0 : MLX5_SET(conn_track_offload, ptr, conn_track_aso_access_pd, pd);
2996 : 0 : ct_aso_obj->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in),
2997 : : out, sizeof(out));
2998 [ # # ]: 0 : if (!ct_aso_obj->obj) {
2999 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "create CONN_TRACK_OFFLOAD", NULL, 0);
3000 : 0 : mlx5_free(ct_aso_obj);
3001 : 0 : return NULL;
3002 : : }
3003 [ # # ]: 0 : ct_aso_obj->id = MLX5_GET(general_obj_out_cmd_hdr, out, obj_id);
3004 : 0 : return ct_aso_obj;
3005 : : }
3006 : :
3007 : : /**
3008 : : * Create general object of type GENEVE TLV option using DevX API.
3009 : : *
3010 : : * @param[in] ctx
3011 : : * Context returned from mlx5 open_device() glue function.
3012 : : * @param[in] attr
3013 : : * Pointer to GENEVE TLV option attributes structure.
3014 : : *
3015 : : * @return
3016 : : * The DevX object created, NULL otherwise and rte_errno is set.
3017 : : */
3018 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_create_geneve_tlv_option)
3019 : : struct mlx5_devx_obj *
3020 : 0 : mlx5_devx_cmd_create_geneve_tlv_option(void *ctx,
3021 : : struct mlx5_devx_geneve_tlv_option_attr *attr)
3022 : : {
3023 : 0 : uint32_t in[MLX5_ST_SZ_DW(create_geneve_tlv_option_in)] = {0};
3024 : 0 : uint32_t out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)] = {0};
3025 : 0 : struct mlx5_devx_obj *geneve_tlv_opt_obj = mlx5_malloc(MLX5_MEM_ZERO,
3026 : : sizeof(*geneve_tlv_opt_obj),
3027 : : 0, SOCKET_ID_ANY);
3028 : :
3029 [ # # ]: 0 : if (!geneve_tlv_opt_obj) {
3030 : 0 : DRV_LOG(ERR, "Failed to allocate GENEVE TLV option object.");
3031 : 0 : rte_errno = ENOMEM;
3032 : 0 : return NULL;
3033 : : }
3034 : : void *hdr = MLX5_ADDR_OF(create_geneve_tlv_option_in, in, hdr);
3035 : : void *opt = MLX5_ADDR_OF(create_geneve_tlv_option_in, in,
3036 : : geneve_tlv_opt);
3037 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, hdr, opcode,
3038 : : MLX5_CMD_OP_CREATE_GENERAL_OBJECT);
3039 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, hdr, obj_type,
3040 : : MLX5_GENERAL_OBJ_TYPE_GENEVE_TLV_OPT);
3041 [ # # ]: 0 : MLX5_SET(geneve_tlv_option, opt, option_type, attr->option_type);
3042 [ # # ]: 0 : MLX5_SET(geneve_tlv_option, opt, option_data_length,
3043 : : attr->option_data_len);
3044 [ # # ]: 0 : if (attr->option_class_ignore)
3045 [ # # ]: 0 : MLX5_SET(geneve_tlv_option, opt, option_class_ignore,
3046 : : attr->option_class_ignore);
3047 : : else
3048 [ # # # # ]: 0 : MLX5_SET(geneve_tlv_option, opt, option_class,
3049 : : rte_be_to_cpu_16(attr->option_class));
3050 [ # # ]: 0 : if (attr->offset_valid) {
3051 [ # # ]: 0 : MLX5_SET(geneve_tlv_option, opt, sample_offset_valid,
3052 : : attr->offset_valid);
3053 [ # # ]: 0 : MLX5_SET(geneve_tlv_option, opt, sample_offset,
3054 : : attr->sample_offset);
3055 : : }
3056 : 0 : geneve_tlv_opt_obj->obj = mlx5_glue->devx_obj_create(ctx, in,
3057 : : sizeof(in), out,
3058 : : sizeof(out));
3059 [ # # ]: 0 : if (!geneve_tlv_opt_obj->obj) {
3060 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "create GENEVE TLV option", NULL, 0);
3061 : 0 : mlx5_free(geneve_tlv_opt_obj);
3062 : 0 : return NULL;
3063 : : }
3064 [ # # ]: 0 : geneve_tlv_opt_obj->id = MLX5_GET(general_obj_out_cmd_hdr, out, obj_id);
3065 : 0 : return geneve_tlv_opt_obj;
3066 : : }
3067 : :
3068 : : /**
3069 : : * Query GENEVE TLV option using DevX API.
3070 : : *
3071 : : * @param[in] ctx
3072 : : * Context used to create GENEVE TLV option object.
3073 : : * @param[in] geneve_tlv_opt_obj
3074 : : * DevX object of the GENEVE TLV option.
3075 : : * @param[out] attr
3076 : : * Pointer to match sample info attributes structure.
3077 : : *
3078 : : * @return
3079 : : * 0 on success, a negative errno otherwise and rte_errno is set.
3080 : : */
3081 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_query_geneve_tlv_option)
3082 : : int
3083 : 0 : mlx5_devx_cmd_query_geneve_tlv_option(void *ctx,
3084 : : struct mlx5_devx_obj *geneve_tlv_opt_obj,
3085 : : struct mlx5_devx_match_sample_info_query_attr *attr)
3086 : : {
3087 : 0 : uint32_t in[MLX5_ST_SZ_DW(general_obj_in_cmd_hdr)] = {0};
3088 : 0 : uint32_t out[MLX5_ST_SZ_DW(query_geneve_tlv_option_out)] = {0};
3089 : : void *hdr = MLX5_ADDR_OF(query_geneve_tlv_option_out, in, hdr);
3090 : : void *opt = MLX5_ADDR_OF(query_geneve_tlv_option_out, out,
3091 : : geneve_tlv_opt);
3092 : : int ret;
3093 : :
3094 : 0 : MLX5_SET(general_obj_in_cmd_hdr, hdr, opcode,
3095 : : MLX5_CMD_OP_QUERY_GENERAL_OBJECT);
3096 : 0 : MLX5_SET(general_obj_in_cmd_hdr, hdr, obj_type,
3097 : : MLX5_GENERAL_OBJ_TYPE_GENEVE_TLV_OPT);
3098 : 0 : MLX5_SET(general_obj_in_cmd_hdr, hdr, obj_id, geneve_tlv_opt_obj->id);
3099 : : /* Call first query to get sample handle. */
3100 : 0 : ret = mlx5_glue->devx_obj_query(geneve_tlv_opt_obj->obj, in, sizeof(in),
3101 : : out, sizeof(out));
3102 [ # # ]: 0 : if (ret) {
3103 : 0 : DRV_LOG(ERR, "Failed to query GENEVE TLV option using DevX.");
3104 : 0 : rte_errno = errno;
3105 : 0 : return -errno;
3106 : : }
3107 : : /* Call second query to get sample information. */
3108 [ # # # # ]: 0 : if (MLX5_GET(geneve_tlv_option, opt, sample_id_valid)) {
3109 [ # # ]: 0 : uint32_t sample_id = MLX5_GET(geneve_tlv_option, opt,
3110 : : geneve_sample_field_id);
3111 : :
3112 : 0 : return mlx5_devx_cmd_match_sample_info_query(ctx, sample_id,
3113 : : attr);
3114 : : }
3115 : 0 : DRV_LOG(DEBUG, "GENEVE TLV option sample isn't valid.");
3116 : 0 : return 0;
3117 : : }
3118 : :
3119 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_wq_query)
3120 : : int
3121 : 0 : mlx5_devx_cmd_wq_query(void *wq, uint32_t *counter_set_id)
3122 : : {
3123 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
3124 : 0 : uint32_t in[MLX5_ST_SZ_DW(query_rq_in)] = {0};
3125 : 0 : uint32_t out[MLX5_ST_SZ_DW(query_rq_out)] = {0};
3126 : : int rc;
3127 : : void *rq_ctx;
3128 : :
3129 : 0 : MLX5_SET(query_rq_in, in, opcode, MLX5_CMD_OP_QUERY_RQ);
3130 : 0 : MLX5_SET(query_rq_in, in, rqn, ((struct ibv_wq *)wq)->wq_num);
3131 : 0 : rc = mlx5_glue->devx_wq_query(wq, in, sizeof(in), out, sizeof(out));
3132 [ # # ]: 0 : if (rc) {
3133 : 0 : rte_errno = errno;
3134 : 0 : DRV_LOG(ERR, "Failed to query WQ counter set ID using DevX - "
3135 : : "rc = %d, errno = %d.", rc, errno);
3136 : 0 : return -rc;
3137 : : };
3138 : : rq_ctx = MLX5_ADDR_OF(query_rq_out, out, rq_context);
3139 [ # # ]: 0 : *counter_set_id = MLX5_GET(rqc, rq_ctx, counter_set_id);
3140 : 0 : return 0;
3141 : : #else
3142 : : (void)wq;
3143 : : (void)counter_set_id;
3144 : : return -ENOTSUP;
3145 : : #endif
3146 : : }
3147 : :
3148 : : /*
3149 : : * Allocate queue counters via devx interface.
3150 : : *
3151 : : * @param[in] ctx
3152 : : * Context returned from mlx5 open_device() glue function.
3153 : : * @param[out] syndrome
3154 : : * Get syndrome of devx command response.
3155 : : *
3156 : : * @return
3157 : : * Pointer to counter object on success, a NULL value otherwise and
3158 : : * rte_errno is set.
3159 : : */
3160 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_queue_counter_alloc)
3161 : : struct mlx5_devx_obj *
3162 : 0 : mlx5_devx_cmd_queue_counter_alloc(void *ctx, int *syndrome)
3163 : : {
3164 : : int status;
3165 : 0 : struct mlx5_devx_obj *dcs = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*dcs), 0,
3166 : : SOCKET_ID_ANY);
3167 : 0 : uint32_t in[MLX5_ST_SZ_DW(alloc_q_counter_in)] = {0};
3168 : 0 : uint32_t out[MLX5_ST_SZ_DW(alloc_q_counter_out)] = {0};
3169 : :
3170 [ # # ]: 0 : if (!dcs) {
3171 : 0 : rte_errno = ENOMEM;
3172 : 0 : return NULL;
3173 : : }
3174 : 0 : MLX5_SET(alloc_q_counter_in, in, opcode, MLX5_CMD_OP_ALLOC_Q_COUNTER);
3175 : 0 : dcs->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in), out,
3176 : : sizeof(out));
3177 [ # # ]: 0 : if (!dcs->obj) {
3178 [ # # # # ]: 0 : DEVX_DRV_LOG(DEBUG, out, "create q counter set", NULL, 0);
3179 [ # # ]: 0 : status = MLX5_GET(alloc_q_counter_out, out, status);
3180 [ # # ]: 0 : if (status && syndrome)
3181 [ # # ]: 0 : *syndrome = MLX5_GET(alloc_q_counter_out, out, syndrome);
3182 : 0 : mlx5_free(dcs);
3183 : 0 : return NULL;
3184 : : }
3185 [ # # ]: 0 : dcs->id = MLX5_GET(alloc_q_counter_out, out, counter_set_id);
3186 : 0 : return dcs;
3187 : : }
3188 : :
3189 : : /**
3190 : : * Query queue counters values.
3191 : : *
3192 : : * @param[in] dcs
3193 : : * devx object of the queue counter set.
3194 : : * @param[in] clear
3195 : : * Whether hardware should clear the counters after the query or not.
3196 : : * @param[out] out_of_buffers
3197 : : * Number of dropped occurred due to lack of WQE for the associated QPs/RQs.
3198 : : *
3199 : : * @return
3200 : : * 0 on success, a negative value otherwise.
3201 : : */
3202 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_queue_counter_query)
3203 : : int
3204 : 0 : mlx5_devx_cmd_queue_counter_query(struct mlx5_devx_obj *dcs, int clear,
3205 : : uint32_t *out_of_buffers)
3206 : : {
3207 : 0 : uint32_t out[MLX5_ST_SZ_BYTES(query_q_counter_out)] = {0};
3208 : 0 : uint32_t in[MLX5_ST_SZ_DW(query_q_counter_in)] = {0};
3209 : : int rc;
3210 : :
3211 : 0 : MLX5_SET(query_q_counter_in, in, opcode,
3212 : : MLX5_CMD_OP_QUERY_Q_COUNTER);
3213 : 0 : MLX5_SET(query_q_counter_in, in, op_mod, 0);
3214 : 0 : MLX5_SET(query_q_counter_in, in, counter_set_id, dcs->id);
3215 : 0 : MLX5_SET(query_q_counter_in, in, clear, !!clear);
3216 : 0 : rc = mlx5_glue->devx_obj_query(dcs->obj, in, sizeof(in), out,
3217 : : sizeof(out));
3218 [ # # ]: 0 : if (rc) {
3219 : 0 : DRV_LOG(ERR, "Failed to query devx q counter set - rc %d", rc);
3220 : 0 : rte_errno = rc;
3221 : 0 : return -rc;
3222 : : }
3223 [ # # ]: 0 : *out_of_buffers = MLX5_GET(query_q_counter_out, out, out_of_buffer);
3224 : 0 : return 0;
3225 : : }
3226 : :
3227 : : /**
3228 : : * Create general object of type DEK using DevX API.
3229 : : *
3230 : : * @param[in] ctx
3231 : : * Context returned from mlx5 open_device() glue function.
3232 : : * @param [in] attr
3233 : : * Pointer to DEK attributes structure.
3234 : : *
3235 : : * @return
3236 : : * The DevX object created, NULL otherwise and rte_errno is set.
3237 : : */
3238 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_create_dek_obj)
3239 : : struct mlx5_devx_obj *
3240 : 0 : mlx5_devx_cmd_create_dek_obj(void *ctx, struct mlx5_devx_dek_attr *attr)
3241 : : {
3242 : 0 : uint32_t in[MLX5_ST_SZ_DW(create_dek_in)] = {0};
3243 : 0 : uint32_t out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)] = {0};
3244 : : struct mlx5_devx_obj *dek_obj = NULL;
3245 : : void *ptr = NULL, *key_addr = NULL;
3246 : :
3247 : 0 : dek_obj = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*dek_obj),
3248 : : 0, SOCKET_ID_ANY);
3249 [ # # ]: 0 : if (dek_obj == NULL) {
3250 : 0 : DRV_LOG(ERR, "Failed to allocate DEK object data");
3251 : 0 : rte_errno = ENOMEM;
3252 : 0 : return NULL;
3253 : : }
3254 : : ptr = MLX5_ADDR_OF(create_dek_in, in, hdr);
3255 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, ptr, opcode,
3256 : : MLX5_CMD_OP_CREATE_GENERAL_OBJECT);
3257 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, ptr, obj_type,
3258 : : MLX5_GENERAL_OBJ_TYPE_DEK);
3259 : : ptr = MLX5_ADDR_OF(create_dek_in, in, dek);
3260 [ # # ]: 0 : MLX5_SET(dek, ptr, key_size, attr->key_size);
3261 [ # # ]: 0 : MLX5_SET(dek, ptr, has_keytag, attr->has_keytag);
3262 [ # # ]: 0 : MLX5_SET(dek, ptr, key_purpose, attr->key_purpose);
3263 [ # # ]: 0 : MLX5_SET(dek, ptr, pd, attr->pd);
3264 [ # # ]: 0 : MLX5_SET64(dek, ptr, opaque, attr->opaque);
3265 : : key_addr = MLX5_ADDR_OF(dek, ptr, key);
3266 : 0 : memcpy(key_addr, (void *)(attr->key), MLX5_CRYPTO_KEY_MAX_SIZE);
3267 : 0 : dek_obj->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in),
3268 : : out, sizeof(out));
3269 [ # # ]: 0 : if (dek_obj->obj == NULL) {
3270 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "create DEK", NULL, 0);
3271 : 0 : mlx5_free(dek_obj);
3272 : 0 : return NULL;
3273 : : }
3274 [ # # ]: 0 : dek_obj->id = MLX5_GET(general_obj_out_cmd_hdr, out, obj_id);
3275 : 0 : return dek_obj;
3276 : : }
3277 : :
3278 : : /**
3279 : : * Create general object of type IMPORT_KEK using DevX API.
3280 : : *
3281 : : * @param[in] ctx
3282 : : * Context returned from mlx5 open_device() glue function.
3283 : : * @param [in] attr
3284 : : * Pointer to IMPORT_KEK attributes structure.
3285 : : *
3286 : : * @return
3287 : : * The DevX object created, NULL otherwise and rte_errno is set.
3288 : : */
3289 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_create_import_kek_obj)
3290 : : struct mlx5_devx_obj *
3291 : 0 : mlx5_devx_cmd_create_import_kek_obj(void *ctx,
3292 : : struct mlx5_devx_import_kek_attr *attr)
3293 : : {
3294 : 0 : uint32_t in[MLX5_ST_SZ_DW(create_import_kek_in)] = {0};
3295 : 0 : uint32_t out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)] = {0};
3296 : : struct mlx5_devx_obj *import_kek_obj = NULL;
3297 : : void *ptr = NULL, *key_addr = NULL;
3298 : :
3299 : 0 : import_kek_obj = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*import_kek_obj),
3300 : : 0, SOCKET_ID_ANY);
3301 [ # # ]: 0 : if (import_kek_obj == NULL) {
3302 : 0 : DRV_LOG(ERR, "Failed to allocate IMPORT_KEK object data");
3303 : 0 : rte_errno = ENOMEM;
3304 : 0 : return NULL;
3305 : : }
3306 : : ptr = MLX5_ADDR_OF(create_import_kek_in, in, hdr);
3307 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, ptr, opcode,
3308 : : MLX5_CMD_OP_CREATE_GENERAL_OBJECT);
3309 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, ptr, obj_type,
3310 : : MLX5_GENERAL_OBJ_TYPE_IMPORT_KEK);
3311 : : ptr = MLX5_ADDR_OF(create_import_kek_in, in, import_kek);
3312 [ # # ]: 0 : MLX5_SET(import_kek, ptr, key_size, attr->key_size);
3313 : : key_addr = MLX5_ADDR_OF(import_kek, ptr, key);
3314 : 0 : memcpy(key_addr, (void *)(attr->key), MLX5_CRYPTO_KEY_MAX_SIZE);
3315 : 0 : import_kek_obj->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in),
3316 : : out, sizeof(out));
3317 [ # # ]: 0 : if (import_kek_obj->obj == NULL) {
3318 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "create IMPORT_KEK", NULL, 0);
3319 : 0 : mlx5_free(import_kek_obj);
3320 : 0 : return NULL;
3321 : : }
3322 [ # # ]: 0 : import_kek_obj->id = MLX5_GET(general_obj_out_cmd_hdr, out, obj_id);
3323 : 0 : return import_kek_obj;
3324 : : }
3325 : :
3326 : : /**
3327 : : * Create general object of type CREDENTIAL using DevX API.
3328 : : *
3329 : : * @param[in] ctx
3330 : : * Context returned from mlx5 open_device() glue function.
3331 : : * @param [in] attr
3332 : : * Pointer to CREDENTIAL attributes structure.
3333 : : *
3334 : : * @return
3335 : : * The DevX object created, NULL otherwise and rte_errno is set.
3336 : : */
3337 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_create_credential_obj)
3338 : : struct mlx5_devx_obj *
3339 : 0 : mlx5_devx_cmd_create_credential_obj(void *ctx,
3340 : : struct mlx5_devx_credential_attr *attr)
3341 : : {
3342 : 0 : uint32_t in[MLX5_ST_SZ_DW(create_credential_in)] = {0};
3343 : 0 : uint32_t out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)] = {0};
3344 : : struct mlx5_devx_obj *credential_obj = NULL;
3345 : : void *ptr = NULL, *credential_addr = NULL;
3346 : :
3347 : 0 : credential_obj = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*credential_obj),
3348 : : 0, SOCKET_ID_ANY);
3349 [ # # ]: 0 : if (credential_obj == NULL) {
3350 : 0 : DRV_LOG(ERR, "Failed to allocate CREDENTIAL object data");
3351 : 0 : rte_errno = ENOMEM;
3352 : 0 : return NULL;
3353 : : }
3354 : : ptr = MLX5_ADDR_OF(create_credential_in, in, hdr);
3355 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, ptr, opcode,
3356 : : MLX5_CMD_OP_CREATE_GENERAL_OBJECT);
3357 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, ptr, obj_type,
3358 : : MLX5_GENERAL_OBJ_TYPE_CREDENTIAL);
3359 : : ptr = MLX5_ADDR_OF(create_credential_in, in, credential);
3360 [ # # ]: 0 : MLX5_SET(credential, ptr, credential_role, attr->credential_role);
3361 : : credential_addr = MLX5_ADDR_OF(credential, ptr, credential);
3362 : 0 : memcpy(credential_addr, (void *)(attr->credential),
3363 : : MLX5_CRYPTO_CREDENTIAL_SIZE);
3364 : 0 : credential_obj->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in),
3365 : : out, sizeof(out));
3366 [ # # ]: 0 : if (credential_obj->obj == NULL) {
3367 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "create CREDENTIAL", NULL, 0);
3368 : 0 : mlx5_free(credential_obj);
3369 : 0 : return NULL;
3370 : : }
3371 [ # # ]: 0 : credential_obj->id = MLX5_GET(general_obj_out_cmd_hdr, out, obj_id);
3372 : 0 : return credential_obj;
3373 : : }
3374 : :
3375 : : /**
3376 : : * Create general object of type CRYPTO_LOGIN using DevX API.
3377 : : *
3378 : : * @param[in] ctx
3379 : : * Context returned from mlx5 open_device() glue function.
3380 : : * @param [in] attr
3381 : : * Pointer to CRYPTO_LOGIN attributes structure.
3382 : : *
3383 : : * @return
3384 : : * The DevX object created, NULL otherwise and rte_errno is set.
3385 : : */
3386 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_create_crypto_login_obj)
3387 : : struct mlx5_devx_obj *
3388 : 0 : mlx5_devx_cmd_create_crypto_login_obj(void *ctx,
3389 : : struct mlx5_devx_crypto_login_attr *attr)
3390 : : {
3391 : 0 : uint32_t in[MLX5_ST_SZ_DW(create_crypto_login_in)] = {0};
3392 : 0 : uint32_t out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)] = {0};
3393 : : struct mlx5_devx_obj *crypto_login_obj = NULL;
3394 : : void *ptr = NULL, *credential_addr = NULL;
3395 : :
3396 : 0 : crypto_login_obj = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*crypto_login_obj),
3397 : : 0, SOCKET_ID_ANY);
3398 [ # # ]: 0 : if (crypto_login_obj == NULL) {
3399 : 0 : DRV_LOG(ERR, "Failed to allocate CRYPTO_LOGIN object data");
3400 : 0 : rte_errno = ENOMEM;
3401 : 0 : return NULL;
3402 : : }
3403 : : ptr = MLX5_ADDR_OF(create_crypto_login_in, in, hdr);
3404 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, ptr, opcode,
3405 : : MLX5_CMD_OP_CREATE_GENERAL_OBJECT);
3406 [ # # ]: 0 : MLX5_SET(general_obj_in_cmd_hdr, ptr, obj_type,
3407 : : MLX5_GENERAL_OBJ_TYPE_CRYPTO_LOGIN);
3408 : : ptr = MLX5_ADDR_OF(create_crypto_login_in, in, crypto_login);
3409 [ # # ]: 0 : MLX5_SET(crypto_login, ptr, credential_pointer,
3410 : : attr->credential_pointer);
3411 [ # # ]: 0 : MLX5_SET(crypto_login, ptr, session_import_kek_ptr,
3412 : : attr->session_import_kek_ptr);
3413 : : credential_addr = MLX5_ADDR_OF(crypto_login, ptr, credential);
3414 : 0 : memcpy(credential_addr, (void *)(attr->credential),
3415 : : MLX5_CRYPTO_CREDENTIAL_SIZE);
3416 : 0 : crypto_login_obj->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in),
3417 : : out, sizeof(out));
3418 [ # # ]: 0 : if (crypto_login_obj->obj == NULL) {
3419 [ # # # # ]: 0 : DEVX_DRV_LOG(ERR, out, "create CRYPTO_LOGIN", NULL, 0);
3420 : 0 : mlx5_free(crypto_login_obj);
3421 : 0 : return NULL;
3422 : : }
3423 [ # # ]: 0 : crypto_login_obj->id = MLX5_GET(general_obj_out_cmd_hdr, out, obj_id);
3424 : 0 : return crypto_login_obj;
3425 : : }
3426 : :
3427 : : /**
3428 : : * Query LAG context.
3429 : : *
3430 : : * @param[in] ctx
3431 : : * Pointer to ibv_context, returned from mlx5dv_open_device.
3432 : : * @param[out] lag_ctx
3433 : : * Pointer to struct mlx5_devx_lag_context, to be set by the routine.
3434 : : *
3435 : : * @return
3436 : : * 0 on success, a negative value otherwise.
3437 : : */
3438 : : RTE_EXPORT_INTERNAL_SYMBOL(mlx5_devx_cmd_query_lag)
3439 : : int
3440 : 0 : mlx5_devx_cmd_query_lag(void *ctx,
3441 : : struct mlx5_devx_lag_context *lag_ctx)
3442 : : {
3443 : 0 : uint32_t in[MLX5_ST_SZ_DW(query_lag_in)] = {0};
3444 : 0 : uint32_t out[MLX5_ST_SZ_DW(query_lag_out)] = {0};
3445 : : void *lctx;
3446 : : int rc;
3447 : :
3448 : 0 : MLX5_SET(query_lag_in, in, opcode, MLX5_CMD_OP_QUERY_LAG);
3449 : 0 : rc = mlx5_glue->devx_general_cmd(ctx, in, sizeof(in), out, sizeof(out));
3450 [ # # ]: 0 : if (rc)
3451 : 0 : goto error;
3452 : : lctx = MLX5_ADDR_OF(query_lag_out, out, context);
3453 [ # # ]: 0 : lag_ctx->fdb_selection_mode = MLX5_GET(lag_context, lctx,
3454 : : fdb_selection_mode);
3455 [ # # ]: 0 : lag_ctx->port_select_mode = MLX5_GET(lag_context, lctx,
3456 : : port_select_mode);
3457 [ # # ]: 0 : lag_ctx->lag_state = MLX5_GET(lag_context, lctx, lag_state);
3458 [ # # ]: 0 : lag_ctx->tx_remap_affinity_2 = MLX5_GET(lag_context, lctx,
3459 : : tx_remap_affinity_2);
3460 [ # # ]: 0 : lag_ctx->tx_remap_affinity_1 = MLX5_GET(lag_context, lctx,
3461 : : tx_remap_affinity_1);
3462 : 0 : return 0;
3463 : : error:
3464 : 0 : rc = (rc > 0) ? -rc : rc;
3465 : 0 : return rc;
3466 : : }
|