e8953bbc3738625a225c9148cd2cf27921ce2139
[dpdk.git] / drivers / net / mlx5 / mlx5_devx_cmds.c
1 // SPDX-License-Identifier: BSD-3-Clause
2 /* Copyright 2018 Mellanox Technologies, Ltd */
3
4 #include <rte_flow_driver.h>
5 #include <rte_malloc.h>
6 #include <unistd.h>
7
8 #include "mlx5.h"
9 #include "mlx5_glue.h"
10 #include "mlx5_prm.h"
11
12 /**
13  * Allocate flow counters via devx interface.
14  *
15  * @param[in] ctx
16  *   ibv contexts returned from mlx5dv_open_device.
17  * @param dcs
18  *   Pointer to counters properties structure to be filled by the routine.
19  * @param bulk_n_128
20  *   Bulk counter numbers in 128 counters units.
21  *
22  * @return
23  *   Pointer to counter object on success, a negative value otherwise and
24  *   rte_errno is set.
25  */
26 struct mlx5_devx_obj *
27 mlx5_devx_cmd_flow_counter_alloc(struct ibv_context *ctx, uint32_t bulk_n_128)
28 {
29         struct mlx5_devx_obj *dcs = rte_zmalloc("dcs", sizeof(*dcs), 0);
30         uint32_t in[MLX5_ST_SZ_DW(alloc_flow_counter_in)]   = {0};
31         uint32_t out[MLX5_ST_SZ_DW(alloc_flow_counter_out)] = {0};
32
33         if (!dcs) {
34                 rte_errno = ENOMEM;
35                 return NULL;
36         }
37         MLX5_SET(alloc_flow_counter_in, in, opcode,
38                  MLX5_CMD_OP_ALLOC_FLOW_COUNTER);
39         MLX5_SET(alloc_flow_counter_in, in, flow_counter_bulk, bulk_n_128);
40         dcs->obj = mlx5_glue->devx_obj_create(ctx, in,
41                                               sizeof(in), out, sizeof(out));
42         if (!dcs->obj) {
43                 DRV_LOG(ERR, "Can't allocate counters - error %d\n", errno);
44                 rte_errno = errno;
45                 rte_free(dcs);
46                 return NULL;
47         }
48         dcs->id = MLX5_GET(alloc_flow_counter_out, out, flow_counter_id);
49         return dcs;
50 }
51
52 /**
53  * Query flow counters values.
54  *
55  * @param[in] dcs
56  *   devx object that was obtained from mlx5_devx_cmd_fc_alloc.
57  * @param[in] clear
58  *   Whether hardware should clear the counters after the query or not.
59  * @param[in] n_counters
60  *   0 in case of 1 counter to read, otherwise the counter number to read.
61  *  @param pkts
62  *   The number of packets that matched the flow.
63  *  @param bytes
64  *    The number of bytes that matched the flow.
65  *  @param mkey
66  *   The mkey key for batch query.
67  *  @param addr
68  *    The address in the mkey range for batch query.
69  *  @param cmd_comp
70  *   The completion object for asynchronous batch query.
71  *  @param async_id
72  *    The ID to be returned in the asynchronous batch query response.
73  *
74  * @return
75  *   0 on success, a negative value otherwise.
76  */
77 int
78 mlx5_devx_cmd_flow_counter_query(struct mlx5_devx_obj *dcs,
79                                  int clear, uint32_t n_counters,
80                                  uint64_t *pkts, uint64_t *bytes,
81                                  uint32_t mkey, void *addr,
82                                  struct mlx5dv_devx_cmd_comp *cmd_comp,
83                                  uint64_t async_id)
84 {
85         int out_len = MLX5_ST_SZ_BYTES(query_flow_counter_out) +
86                         MLX5_ST_SZ_BYTES(traffic_counter);
87         uint32_t out[out_len];
88         uint32_t in[MLX5_ST_SZ_DW(query_flow_counter_in)] = {0};
89         void *stats;
90         int rc;
91
92         MLX5_SET(query_flow_counter_in, in, opcode,
93                  MLX5_CMD_OP_QUERY_FLOW_COUNTER);
94         MLX5_SET(query_flow_counter_in, in, op_mod, 0);
95         MLX5_SET(query_flow_counter_in, in, flow_counter_id, dcs->id);
96         MLX5_SET(query_flow_counter_in, in, clear, !!clear);
97
98         if (n_counters) {
99                 MLX5_SET(query_flow_counter_in, in, num_of_counters,
100                          n_counters);
101                 MLX5_SET(query_flow_counter_in, in, dump_to_memory, 1);
102                 MLX5_SET(query_flow_counter_in, in, mkey, mkey);
103                 MLX5_SET64(query_flow_counter_in, in, address,
104                            (uint64_t)(uintptr_t)addr);
105         }
106         if (!cmd_comp)
107                 rc = mlx5_glue->devx_obj_query(dcs->obj, in, sizeof(in), out,
108                                                out_len);
109         else
110                 rc = mlx5_glue->devx_obj_query_async(dcs->obj, in, sizeof(in),
111                                                      out_len, async_id,
112                                                      cmd_comp);
113         if (rc) {
114                 DRV_LOG(ERR, "Failed to query devx counters with rc %d\n ", rc);
115                 rte_errno = rc;
116                 return -rc;
117         }
118         if (!n_counters) {
119                 stats = MLX5_ADDR_OF(query_flow_counter_out,
120                                      out, flow_statistics);
121                 *pkts = MLX5_GET64(traffic_counter, stats, packets);
122                 *bytes = MLX5_GET64(traffic_counter, stats, octets);
123         }
124         return 0;
125 }
126
127 /**
128  * Create a new mkey.
129  *
130  * @param[in] ctx
131  *   ibv contexts returned from mlx5dv_open_device.
132  * @param[in] attr
133  *   Attributes of the requested mkey.
134  *
135  * @return
136  *   Pointer to Devx mkey on success, a negative value otherwise and rte_errno
137  *   is set.
138  */
139 struct mlx5_devx_obj *
140 mlx5_devx_cmd_mkey_create(struct ibv_context *ctx,
141                           struct mlx5_devx_mkey_attr *attr)
142 {
143         uint32_t in[MLX5_ST_SZ_DW(create_mkey_in)] = {0};
144         uint32_t out[MLX5_ST_SZ_DW(create_mkey_out)] = {0};
145         void *mkc;
146         struct mlx5_devx_obj *mkey = rte_zmalloc("mkey", sizeof(*mkey), 0);
147         size_t pgsize;
148         uint32_t translation_size;
149
150         if (!mkey) {
151                 rte_errno = ENOMEM;
152                 return NULL;
153         }
154         pgsize = sysconf(_SC_PAGESIZE);
155         translation_size = (RTE_ALIGN(attr->size, pgsize) * 8) / 16;
156         MLX5_SET(create_mkey_in, in, opcode, MLX5_CMD_OP_CREATE_MKEY);
157         MLX5_SET(create_mkey_in, in, translations_octword_actual_size,
158                  translation_size);
159         MLX5_SET(create_mkey_in, in, mkey_umem_id, attr->umem_id);
160         mkc = MLX5_ADDR_OF(create_mkey_in, in, memory_key_mkey_entry);
161         MLX5_SET(mkc, mkc, lw, 0x1);
162         MLX5_SET(mkc, mkc, lr, 0x1);
163         MLX5_SET(mkc, mkc, access_mode_1_0, MLX5_MKC_ACCESS_MODE_MTT);
164         MLX5_SET(mkc, mkc, qpn, 0xffffff);
165         MLX5_SET(mkc, mkc, pd, attr->pd);
166         MLX5_SET(mkc, mkc, mkey_7_0, attr->umem_id & 0xFF);
167         MLX5_SET(mkc, mkc, translations_octword_size, translation_size);
168         MLX5_SET64(mkc, mkc, start_addr, attr->addr);
169         MLX5_SET64(mkc, mkc, len, attr->size);
170         MLX5_SET(mkc, mkc, log_page_size, rte_log2_u32(pgsize));
171         mkey->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in), out,
172                                                sizeof(out));
173         if (!mkey->obj) {
174                 DRV_LOG(ERR, "Can't create mkey - error %d\n", errno);
175                 rte_errno = errno;
176                 rte_free(mkey);
177                 return NULL;
178         }
179         mkey->id = MLX5_GET(create_mkey_out, out, mkey_index);
180         mkey->id = (mkey->id << 8) | (attr->umem_id & 0xFF);
181         return mkey;
182 }
183
184 /**
185  * Get status of devx command response.
186  * Mainly used for asynchronous commands.
187  *
188  * @param[in] out
189  *   The out response buffer.
190  *
191  * @return
192  *   0 on success, non-zero value otherwise.
193  */
194 int
195 mlx5_devx_get_out_command_status(void *out)
196 {
197         int status;
198
199         if (!out)
200                 return -EINVAL;
201         status = MLX5_GET(query_flow_counter_out, out, status);
202         if (status) {
203                 int syndrome = MLX5_GET(query_flow_counter_out, out, syndrome);
204
205                 DRV_LOG(ERR, "Bad devX status %x, syndrome = %x\n", status,
206                         syndrome);
207         }
208         return status;
209 }
210
211 /**
212  * Destroy any object allocated by a Devx API.
213  *
214  * @param[in] obj
215  *   Pointer to a general object.
216  *
217  * @return
218  *   0 on success, a negative value otherwise.
219  */
220 int
221 mlx5_devx_cmd_destroy(struct mlx5_devx_obj *obj)
222 {
223         int ret;
224
225         if (!obj)
226                 return 0;
227         ret =  mlx5_glue->devx_obj_destroy(obj->obj);
228         rte_free(obj);
229         return ret;
230 }
231
232 /**
233  * Query NIC vport context.
234  * Fills minimal inline attribute.
235  *
236  * @param[in] ctx
237  *   ibv contexts returned from mlx5dv_open_device.
238  * @param[in] vport
239  *   vport index
240  * @param[out] attr
241  *   Attributes device values.
242  *
243  * @return
244  *   0 on success, a negative value otherwise.
245  */
246 static int
247 mlx5_devx_cmd_query_nic_vport_context(struct ibv_context *ctx,
248                                       unsigned int vport,
249                                       struct mlx5_hca_attr *attr)
250 {
251         uint32_t in[MLX5_ST_SZ_DW(query_nic_vport_context_in)] = {0};
252         uint32_t out[MLX5_ST_SZ_DW(query_nic_vport_context_out)] = {0};
253         void *vctx;
254         int status, syndrome, rc;
255
256         /* Query NIC vport context to determine inline mode. */
257         MLX5_SET(query_nic_vport_context_in, in, opcode,
258                  MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT);
259         MLX5_SET(query_nic_vport_context_in, in, vport_number, vport);
260         if (vport)
261                 MLX5_SET(query_nic_vport_context_in, in, other_vport, 1);
262         rc = mlx5_glue->devx_general_cmd(ctx,
263                                          in, sizeof(in),
264                                          out, sizeof(out));
265         if (rc)
266                 goto error;
267         status = MLX5_GET(query_nic_vport_context_out, out, status);
268         syndrome = MLX5_GET(query_nic_vport_context_out, out, syndrome);
269         if (status) {
270                 DRV_LOG(DEBUG, "Failed to query NIC vport context, "
271                         "status %x, syndrome = %x",
272                         status, syndrome);
273                 return -1;
274         }
275         vctx = MLX5_ADDR_OF(query_nic_vport_context_out, out,
276                             nic_vport_context);
277         attr->vport_inline_mode = MLX5_GET(nic_vport_context, vctx,
278                                            min_wqe_inline_mode);
279         return 0;
280 error:
281         rc = (rc > 0) ? -rc : rc;
282         return rc;
283 }
284
285 /**
286  * Query HCA attributes.
287  * Using those attributes we can check on run time if the device
288  * is having the required capabilities.
289  *
290  * @param[in] ctx
291  *   ibv contexts returned from mlx5dv_open_device.
292  * @param[out] attr
293  *   Attributes device values.
294  *
295  * @return
296  *   0 on success, a negative value otherwise.
297  */
298 int
299 mlx5_devx_cmd_query_hca_attr(struct ibv_context *ctx,
300                              struct mlx5_hca_attr *attr)
301 {
302         uint32_t in[MLX5_ST_SZ_DW(query_hca_cap_in)] = {0};
303         uint32_t out[MLX5_ST_SZ_DW(query_hca_cap_out)] = {0};
304         void *hcattr;
305         int status, syndrome, rc;
306
307         MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP);
308         MLX5_SET(query_hca_cap_in, in, op_mod,
309                  MLX5_GET_HCA_CAP_OP_MOD_GENERAL_DEVICE |
310                  MLX5_HCA_CAP_OPMOD_GET_CUR);
311
312         rc = mlx5_glue->devx_general_cmd(ctx,
313                                          in, sizeof(in), out, sizeof(out));
314         if (rc)
315                 goto error;
316         status = MLX5_GET(query_hca_cap_out, out, status);
317         syndrome = MLX5_GET(query_hca_cap_out, out, syndrome);
318         if (status) {
319                 DRV_LOG(DEBUG, "Failed to query devx HCA capabilities, "
320                         "status %x, syndrome = %x",
321                         status, syndrome);
322                 return -1;
323         }
324         hcattr = MLX5_ADDR_OF(query_hca_cap_out, out, capability);
325         attr->flow_counter_bulk_alloc_bitmap =
326                         MLX5_GET(cmd_hca_cap, hcattr, flow_counter_bulk_alloc);
327         attr->flow_counters_dump = MLX5_GET(cmd_hca_cap, hcattr,
328                                             flow_counters_dump);
329         attr->eswitch_manager = MLX5_GET(cmd_hca_cap, hcattr, eswitch_manager);
330         attr->eth_net_offloads = MLX5_GET(cmd_hca_cap, hcattr,
331                                           eth_net_offloads);
332         attr->eth_virt = MLX5_GET(cmd_hca_cap, hcattr, eth_virt);
333         if (!attr->eth_net_offloads)
334                 return 0;
335
336         /* Query HCA offloads for Ethernet protocol. */
337         memset(in, 0, sizeof(in));
338         memset(out, 0, sizeof(out));
339         MLX5_SET(query_hca_cap_in, in, opcode, MLX5_CMD_OP_QUERY_HCA_CAP);
340         MLX5_SET(query_hca_cap_in, in, op_mod,
341                  MLX5_GET_HCA_CAP_OP_MOD_ETHERNET_OFFLOAD_CAPS |
342                  MLX5_HCA_CAP_OPMOD_GET_CUR);
343
344         rc = mlx5_glue->devx_general_cmd(ctx,
345                                          in, sizeof(in),
346                                          out, sizeof(out));
347         if (rc) {
348                 attr->eth_net_offloads = 0;
349                 goto error;
350         }
351         status = MLX5_GET(query_hca_cap_out, out, status);
352         syndrome = MLX5_GET(query_hca_cap_out, out, syndrome);
353         if (status) {
354                 DRV_LOG(DEBUG, "Failed to query devx HCA capabilities, "
355                         "status %x, syndrome = %x",
356                         status, syndrome);
357                 attr->eth_net_offloads = 0;
358                 return -1;
359         }
360         hcattr = MLX5_ADDR_OF(query_hca_cap_out, out, capability);
361         attr->wqe_vlan_insert = MLX5_GET(per_protocol_networking_offload_caps,
362                                          hcattr, wqe_vlan_insert);
363         attr->lro_cap = MLX5_GET(per_protocol_networking_offload_caps, hcattr,
364                                  lro_cap);
365         attr->tunnel_lro_gre = MLX5_GET(per_protocol_networking_offload_caps,
366                                         hcattr, tunnel_lro_gre);
367         attr->tunnel_lro_vxlan = MLX5_GET(per_protocol_networking_offload_caps,
368                                           hcattr, tunnel_lro_vxlan);
369         attr->lro_max_msg_sz_mode = MLX5_GET
370                                         (per_protocol_networking_offload_caps,
371                                          hcattr, lro_max_msg_sz_mode);
372         for (int i = 0 ; i < MLX5_LRO_NUM_SUPP_PERIODS ; i++) {
373                 attr->lro_timer_supported_periods[i] =
374                         MLX5_GET(per_protocol_networking_offload_caps, hcattr,
375                                  lro_timer_supported_periods[i]);
376         }
377         attr->wqe_inline_mode = MLX5_GET(per_protocol_networking_offload_caps,
378                                          hcattr, wqe_inline_mode);
379         if (attr->wqe_inline_mode != MLX5_CAP_INLINE_MODE_VPORT_CONTEXT)
380                 return 0;
381         if (attr->eth_virt) {
382                 rc = mlx5_devx_cmd_query_nic_vport_context(ctx, 0, attr);
383                 if (rc) {
384                         attr->eth_virt = 0;
385                         goto error;
386                 }
387         }
388         return 0;
389 error:
390         rc = (rc > 0) ? -rc : rc;
391         return rc;
392 }
393
394 /**
395  * Query TIS transport domain from QP verbs object using DevX API.
396  *
397  * @param[in] qp
398  *   Pointer to verbs QP returned by ibv_create_qp .
399  * @param[in] tis_num
400  *   TIS number of TIS to query.
401  * @param[out] tis_td
402  *   Pointer to TIS transport domain variable, to be set by the routine.
403  *
404  * @return
405  *   0 on success, a negative value otherwise.
406  */
407 int
408 mlx5_devx_cmd_qp_query_tis_td(struct ibv_qp *qp, uint32_t tis_num,
409                               uint32_t *tis_td)
410 {
411         uint32_t in[MLX5_ST_SZ_DW(query_tis_in)] = {0};
412         uint32_t out[MLX5_ST_SZ_DW(query_tis_out)] = {0};
413         int rc;
414         void *tis_ctx;
415
416         MLX5_SET(query_tis_in, in, opcode, MLX5_CMD_OP_QUERY_TIS);
417         MLX5_SET(query_tis_in, in, tisn, tis_num);
418         rc = mlx5_glue->devx_qp_query(qp, in, sizeof(in), out, sizeof(out));
419         if (rc) {
420                 DRV_LOG(ERR, "Failed to query QP using DevX");
421                 return -rc;
422         };
423         tis_ctx = MLX5_ADDR_OF(query_tis_out, out, tis_context);
424         *tis_td = MLX5_GET(tisc, tis_ctx, transport_domain);
425         return 0;
426 }
427
428 /**
429  * Fill WQ data for DevX API command.
430  * Utility function for use when creating DevX objects containing a WQ.
431  *
432  * @param[in] wq_ctx
433  *   Pointer to WQ context to fill with data.
434  * @param [in] wq_attr
435  *   Pointer to WQ attributes structure to fill in WQ context.
436  */
437 static void
438 devx_cmd_fill_wq_data(void *wq_ctx, struct mlx5_devx_wq_attr *wq_attr)
439 {
440         MLX5_SET(wq, wq_ctx, wq_type, wq_attr->wq_type);
441         MLX5_SET(wq, wq_ctx, wq_signature, wq_attr->wq_signature);
442         MLX5_SET(wq, wq_ctx, end_padding_mode, wq_attr->end_padding_mode);
443         MLX5_SET(wq, wq_ctx, cd_slave, wq_attr->cd_slave);
444         MLX5_SET(wq, wq_ctx, hds_skip_first_sge, wq_attr->hds_skip_first_sge);
445         MLX5_SET(wq, wq_ctx, log2_hds_buf_size, wq_attr->log2_hds_buf_size);
446         MLX5_SET(wq, wq_ctx, page_offset, wq_attr->page_offset);
447         MLX5_SET(wq, wq_ctx, lwm, wq_attr->lwm);
448         MLX5_SET(wq, wq_ctx, pd, wq_attr->pd);
449         MLX5_SET(wq, wq_ctx, uar_page, wq_attr->uar_page);
450         MLX5_SET64(wq, wq_ctx, dbr_addr, wq_attr->dbr_addr);
451         MLX5_SET(wq, wq_ctx, hw_counter, wq_attr->hw_counter);
452         MLX5_SET(wq, wq_ctx, sw_counter, wq_attr->sw_counter);
453         MLX5_SET(wq, wq_ctx, log_wq_stride, wq_attr->log_wq_stride);
454         MLX5_SET(wq, wq_ctx, log_wq_pg_sz, wq_attr->log_wq_pg_sz);
455         MLX5_SET(wq, wq_ctx, log_wq_sz, wq_attr->log_wq_sz);
456         MLX5_SET(wq, wq_ctx, dbr_umem_valid, wq_attr->dbr_umem_valid);
457         MLX5_SET(wq, wq_ctx, wq_umem_valid, wq_attr->wq_umem_valid);
458         MLX5_SET(wq, wq_ctx, log_hairpin_num_packets,
459                  wq_attr->log_hairpin_num_packets);
460         MLX5_SET(wq, wq_ctx, log_hairpin_data_sz, wq_attr->log_hairpin_data_sz);
461         MLX5_SET(wq, wq_ctx, single_wqe_log_num_of_strides,
462                  wq_attr->single_wqe_log_num_of_strides);
463         MLX5_SET(wq, wq_ctx, two_byte_shift_en, wq_attr->two_byte_shift_en);
464         MLX5_SET(wq, wq_ctx, single_stride_log_num_of_bytes,
465                  wq_attr->single_stride_log_num_of_bytes);
466         MLX5_SET(wq, wq_ctx, dbr_umem_id, wq_attr->dbr_umem_id);
467         MLX5_SET(wq, wq_ctx, wq_umem_id, wq_attr->wq_umem_id);
468         MLX5_SET64(wq, wq_ctx, wq_umem_offset, wq_attr->wq_umem_offset);
469 }
470
471 /**
472  * Create RQ using DevX API.
473  *
474  * @param[in] ctx
475  *   ibv_context returned from mlx5dv_open_device.
476  * @param [in] rq_attr
477  *   Pointer to create RQ attributes structure.
478  * @param [in] socket
479  *   CPU socket ID for allocations.
480  *
481  * @return
482  *   The DevX object created, NULL otherwise and rte_errno is set.
483  */
484 struct mlx5_devx_obj *
485 mlx5_devx_cmd_create_rq(struct ibv_context *ctx,
486                         struct mlx5_devx_create_rq_attr *rq_attr,
487                         int socket)
488 {
489         uint32_t in[MLX5_ST_SZ_DW(create_rq_in)] = {0};
490         uint32_t out[MLX5_ST_SZ_DW(create_rq_out)] = {0};
491         void *rq_ctx, *wq_ctx;
492         struct mlx5_devx_wq_attr *wq_attr;
493         struct mlx5_devx_obj *rq = NULL;
494
495         rq = rte_calloc_socket(__func__, 1, sizeof(*rq), 0, socket);
496         if (!rq) {
497                 DRV_LOG(ERR, "Failed to allocate RQ data");
498                 rte_errno = ENOMEM;
499                 return NULL;
500         }
501         MLX5_SET(create_rq_in, in, opcode, MLX5_CMD_OP_CREATE_RQ);
502         rq_ctx = MLX5_ADDR_OF(create_rq_in, in, ctx);
503         MLX5_SET(rqc, rq_ctx, rlky, rq_attr->rlky);
504         MLX5_SET(rqc, rq_ctx, delay_drop_en, rq_attr->delay_drop_en);
505         MLX5_SET(rqc, rq_ctx, scatter_fcs, rq_attr->scatter_fcs);
506         MLX5_SET(rqc, rq_ctx, vsd, rq_attr->vsd);
507         MLX5_SET(rqc, rq_ctx, mem_rq_type, rq_attr->mem_rq_type);
508         MLX5_SET(rqc, rq_ctx, state, rq_attr->state);
509         MLX5_SET(rqc, rq_ctx, flush_in_error_en, rq_attr->flush_in_error_en);
510         MLX5_SET(rqc, rq_ctx, hairpin, rq_attr->hairpin);
511         MLX5_SET(rqc, rq_ctx, user_index, rq_attr->user_index);
512         MLX5_SET(rqc, rq_ctx, cqn, rq_attr->cqn);
513         MLX5_SET(rqc, rq_ctx, counter_set_id, rq_attr->counter_set_id);
514         MLX5_SET(rqc, rq_ctx, rmpn, rq_attr->rmpn);
515         wq_ctx = MLX5_ADDR_OF(rqc, rq_ctx, wq);
516         wq_attr = &rq_attr->wq_attr;
517         devx_cmd_fill_wq_data(wq_ctx, wq_attr);
518         rq->obj = mlx5_glue->devx_obj_create(ctx, in, sizeof(in),
519                                                   out, sizeof(out));
520         if (!rq->obj) {
521                 DRV_LOG(ERR, "Failed to create RQ using DevX");
522                 rte_errno = errno;
523                 rte_free(rq);
524                 return NULL;
525         }
526         rq->id = MLX5_GET(create_rq_out, out, rqn);
527         return rq;
528 }
529
530 /**
531  * Modify RQ using DevX API.
532  *
533  * @param[in] rq
534  *   Pointer to RQ object structure.
535  * @param [in] rq_attr
536  *   Pointer to modify RQ attributes structure.
537  *
538  * @return
539  *   0 on success, a negative errno value otherwise and rte_errno is set.
540  */
541 int
542 mlx5_devx_cmd_modify_rq(struct mlx5_devx_obj *rq,
543                         struct mlx5_devx_modify_rq_attr *rq_attr)
544 {
545         uint32_t in[MLX5_ST_SZ_DW(modify_rq_in)] = {0};
546         uint32_t out[MLX5_ST_SZ_DW(modify_rq_out)] = {0};
547         void *rq_ctx, *wq_ctx;
548         int ret;
549
550         MLX5_SET(modify_rq_in, in, opcode, MLX5_CMD_OP_MODIFY_RQ);
551         MLX5_SET(modify_rq_in, in, rq_state, rq_attr->rq_state);
552         MLX5_SET(modify_rq_in, in, rqn, rq->id);
553         MLX5_SET64(modify_rq_in, in, modify_bitmask, rq_attr->modify_bitmask);
554         rq_ctx = MLX5_ADDR_OF(modify_rq_in, in, ctx);
555         MLX5_SET(rqc, rq_ctx, state, rq_attr->state);
556         if (rq_attr->modify_bitmask &
557                         MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_SCATTER_FCS)
558                 MLX5_SET(rqc, rq_ctx, scatter_fcs, rq_attr->scatter_fcs);
559         if (rq_attr->modify_bitmask & MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_VSD)
560                 MLX5_SET(rqc, rq_ctx, vsd, rq_attr->vsd);
561         if (rq_attr->modify_bitmask &
562                         MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_RQ_COUNTER_SET_ID)
563                 MLX5_SET(rqc, rq_ctx, counter_set_id, rq_attr->counter_set_id);
564         MLX5_SET(rqc, rq_ctx, hairpin_peer_sq, rq_attr->hairpin_peer_sq);
565         MLX5_SET(rqc, rq_ctx, hairpin_peer_vhca, rq_attr->hairpin_peer_vhca);
566         if (rq_attr->modify_bitmask & MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_WQ_LWM) {
567                 wq_ctx = MLX5_ADDR_OF(rqc, rq_ctx, wq);
568                 MLX5_SET(wq, wq_ctx, lwm, rq_attr->lwm);
569         }
570         ret = mlx5_glue->devx_obj_modify(rq->obj, in, sizeof(in),
571                                          out, sizeof(out));
572         if (ret) {
573                 DRV_LOG(ERR, "Failed to modify RQ using DevX");
574                 rte_errno = errno;
575                 return -errno;
576         }
577         return ret;
578 }