1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2020 Mellanox Technologies, Ltd
10 #include <sys/queue.h>
12 #include <rte_malloc.h>
13 #include <rte_common.h>
14 #include <rte_eal_paging.h>
16 #include <mlx5_glue.h>
17 #include <mlx5_devx_cmds.h>
18 #include <mlx5_malloc.h>
21 #include "mlx5_common_os.h"
22 #include "mlx5_rxtx.h"
23 #include "mlx5_utils.h"
24 #include "mlx5_devx.h"
25 #include "mlx5_flow.h"
29 * Modify RQ vlan stripping offload
35 * 0 on success, non-0 otherwise
38 mlx5_rxq_obj_modify_rq_vlan_strip(struct mlx5_rxq_obj *rxq_obj, int on)
40 struct mlx5_devx_modify_rq_attr rq_attr;
42 memset(&rq_attr, 0, sizeof(rq_attr));
43 rq_attr.rq_state = MLX5_RQC_STATE_RDY;
44 rq_attr.state = MLX5_RQC_STATE_RDY;
45 rq_attr.vsd = (on ? 0 : 1);
46 rq_attr.modify_bitmask = MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_VSD;
47 return mlx5_devx_cmd_modify_rq(rxq_obj->rq, &rq_attr);
51 * Modify RQ using DevX API.
54 * DevX Rx queue object.
56 * Type of change queue state.
59 * 0 on success, a negative errno value otherwise and rte_errno is set.
62 mlx5_devx_modify_rq(struct mlx5_rxq_obj *rxq_obj, uint8_t type)
64 struct mlx5_devx_modify_rq_attr rq_attr;
66 memset(&rq_attr, 0, sizeof(rq_attr));
68 case MLX5_RXQ_MOD_ERR2RST:
69 rq_attr.rq_state = MLX5_RQC_STATE_ERR;
70 rq_attr.state = MLX5_RQC_STATE_RST;
72 case MLX5_RXQ_MOD_RST2RDY:
73 rq_attr.rq_state = MLX5_RQC_STATE_RST;
74 rq_attr.state = MLX5_RQC_STATE_RDY;
76 case MLX5_RXQ_MOD_RDY2ERR:
77 rq_attr.rq_state = MLX5_RQC_STATE_RDY;
78 rq_attr.state = MLX5_RQC_STATE_ERR;
80 case MLX5_RXQ_MOD_RDY2RST:
81 rq_attr.rq_state = MLX5_RQC_STATE_RDY;
82 rq_attr.state = MLX5_RQC_STATE_RST;
87 return mlx5_devx_cmd_modify_rq(rxq_obj->rq, &rq_attr);
91 * Modify SQ using DevX API.
94 * DevX Tx queue object.
96 * Type of change queue state.
101 * 0 on success, a negative errno value otherwise and rte_errno is set.
104 mlx5_devx_modify_sq(struct mlx5_txq_obj *obj, enum mlx5_txq_modify_type type,
107 struct mlx5_devx_modify_sq_attr msq_attr = { 0 };
110 if (type != MLX5_TXQ_MOD_RST2RDY) {
111 /* Change queue state to reset. */
112 if (type == MLX5_TXQ_MOD_ERR2RDY)
113 msq_attr.sq_state = MLX5_SQC_STATE_ERR;
115 msq_attr.sq_state = MLX5_SQC_STATE_RDY;
116 msq_attr.state = MLX5_SQC_STATE_RST;
117 ret = mlx5_devx_cmd_modify_sq(obj->sq_devx, &msq_attr);
119 DRV_LOG(ERR, "Cannot change the Tx SQ state to RESET"
120 " %s", strerror(errno));
125 if (type != MLX5_TXQ_MOD_RDY2RST) {
126 /* Change queue state to ready. */
127 msq_attr.sq_state = MLX5_SQC_STATE_RST;
128 msq_attr.state = MLX5_SQC_STATE_RDY;
129 ret = mlx5_devx_cmd_modify_sq(obj->sq_devx, &msq_attr);
131 DRV_LOG(ERR, "Cannot change the Tx SQ state to READY"
132 " %s", strerror(errno));
138 * The dev_port variable is relevant only in Verbs API, and there is a
139 * pointer that points to this function and a parallel function in verbs
140 * intermittently, so they should have the same parameters.
147 * Release the resources allocated for an RQ DevX object.
150 * DevX Rx queue object.
153 mlx5_rxq_release_devx_rq_resources(struct mlx5_rxq_ctrl *rxq_ctrl)
155 struct mlx5_devx_dbr_page *dbr_page = rxq_ctrl->rq_dbrec_page;
157 if (rxq_ctrl->wq_umem) {
158 mlx5_os_umem_dereg(rxq_ctrl->wq_umem);
159 rxq_ctrl->wq_umem = NULL;
161 if (rxq_ctrl->rxq.wqes) {
162 mlx5_free((void *)(uintptr_t)rxq_ctrl->rxq.wqes);
163 rxq_ctrl->rxq.wqes = NULL;
166 claim_zero(mlx5_release_dbr(&rxq_ctrl->priv->dbrpgs,
167 mlx5_os_get_umem_id(dbr_page->umem),
168 rxq_ctrl->rq_dbr_offset));
169 rxq_ctrl->rq_dbrec_page = NULL;
174 * Release the resources allocated for the Rx CQ DevX object.
177 * DevX Rx queue object.
180 mlx5_rxq_release_devx_cq_resources(struct mlx5_rxq_ctrl *rxq_ctrl)
182 struct mlx5_devx_dbr_page *dbr_page = rxq_ctrl->cq_dbrec_page;
184 if (rxq_ctrl->cq_umem) {
185 mlx5_os_umem_dereg(rxq_ctrl->cq_umem);
186 rxq_ctrl->cq_umem = NULL;
188 if (rxq_ctrl->rxq.cqes) {
189 rte_free((void *)(uintptr_t)rxq_ctrl->rxq.cqes);
190 rxq_ctrl->rxq.cqes = NULL;
193 claim_zero(mlx5_release_dbr(&rxq_ctrl->priv->dbrpgs,
194 mlx5_os_get_umem_id(dbr_page->umem),
195 rxq_ctrl->cq_dbr_offset));
196 rxq_ctrl->cq_dbrec_page = NULL;
201 * Release an Rx DevX queue object.
204 * DevX Rx queue object.
207 mlx5_rxq_devx_obj_release(struct mlx5_rxq_obj *rxq_obj)
209 MLX5_ASSERT(rxq_obj);
210 MLX5_ASSERT(rxq_obj->rq);
211 if (rxq_obj->rxq_ctrl->type == MLX5_RXQ_TYPE_HAIRPIN) {
212 mlx5_devx_modify_rq(rxq_obj, MLX5_RXQ_MOD_RDY2RST);
213 claim_zero(mlx5_devx_cmd_destroy(rxq_obj->rq));
215 MLX5_ASSERT(rxq_obj->devx_cq);
216 claim_zero(mlx5_devx_cmd_destroy(rxq_obj->rq));
217 claim_zero(mlx5_devx_cmd_destroy(rxq_obj->devx_cq));
218 if (rxq_obj->devx_channel)
219 mlx5_os_devx_destroy_event_channel
220 (rxq_obj->devx_channel);
221 mlx5_rxq_release_devx_rq_resources(rxq_obj->rxq_ctrl);
222 mlx5_rxq_release_devx_cq_resources(rxq_obj->rxq_ctrl);
227 * Get event for an Rx DevX queue object.
230 * DevX Rx queue object.
233 * 0 on success, a negative errno value otherwise and rte_errno is set.
236 mlx5_rx_devx_get_event(struct mlx5_rxq_obj *rxq_obj)
238 #ifdef HAVE_IBV_DEVX_EVENT
240 struct mlx5dv_devx_async_event_hdr event_resp;
241 uint8_t buf[sizeof(struct mlx5dv_devx_async_event_hdr) + 128];
243 int ret = mlx5_glue->devx_get_event(rxq_obj->devx_channel,
251 if (out.event_resp.cookie != (uint64_t)(uintptr_t)rxq_obj->devx_cq) {
260 #endif /* HAVE_IBV_DEVX_EVENT */
264 * Fill common fields of create RQ attributes structure.
267 * Pointer to Rx queue data.
269 * CQ number to use with this RQ.
271 * RQ attributes structure to fill..
274 mlx5_devx_create_rq_attr_fill(struct mlx5_rxq_data *rxq_data, uint32_t cqn,
275 struct mlx5_devx_create_rq_attr *rq_attr)
277 rq_attr->state = MLX5_RQC_STATE_RST;
278 rq_attr->vsd = (rxq_data->vlan_strip) ? 0 : 1;
280 rq_attr->scatter_fcs = (rxq_data->crc_present) ? 1 : 0;
284 * Fill common fields of DevX WQ attributes structure.
287 * Pointer to device private data.
289 * Pointer to Rx queue control structure.
291 * WQ attributes structure to fill..
294 mlx5_devx_wq_attr_fill(struct mlx5_priv *priv, struct mlx5_rxq_ctrl *rxq_ctrl,
295 struct mlx5_devx_wq_attr *wq_attr)
297 wq_attr->end_padding_mode = priv->config.hw_padding ?
298 MLX5_WQ_END_PAD_MODE_ALIGN :
299 MLX5_WQ_END_PAD_MODE_NONE;
300 wq_attr->pd = priv->sh->pdn;
301 wq_attr->dbr_addr = rxq_ctrl->rq_dbr_offset;
302 wq_attr->dbr_umem_id =
303 mlx5_os_get_umem_id(rxq_ctrl->rq_dbrec_page->umem);
304 wq_attr->dbr_umem_valid = 1;
305 wq_attr->wq_umem_id = mlx5_os_get_umem_id(rxq_ctrl->wq_umem);
306 wq_attr->wq_umem_valid = 1;
310 * Create a RQ object using DevX.
313 * Pointer to Ethernet device.
315 * Queue index in DPDK Rx queue array.
318 * The DevX RQ object initialized, NULL otherwise and rte_errno is set.
320 static struct mlx5_devx_obj *
321 mlx5_rxq_create_devx_rq_resources(struct rte_eth_dev *dev, uint16_t idx)
323 struct mlx5_priv *priv = dev->data->dev_private;
324 struct mlx5_rxq_data *rxq_data = (*priv->rxqs)[idx];
325 struct mlx5_rxq_ctrl *rxq_ctrl =
326 container_of(rxq_data, struct mlx5_rxq_ctrl, rxq);
327 struct mlx5_devx_create_rq_attr rq_attr = { 0 };
328 uint32_t wqe_n = 1 << (rxq_data->elts_n - rxq_data->sges_n);
329 uint32_t cqn = rxq_ctrl->obj->devx_cq->id;
330 struct mlx5_devx_dbr_page *dbr_page;
332 uint32_t wq_size = 0;
333 uint32_t wqe_size = 0;
334 uint32_t log_wqe_size = 0;
336 struct mlx5_devx_obj *rq;
338 /* Fill RQ attributes. */
339 rq_attr.mem_rq_type = MLX5_RQC_MEM_RQ_TYPE_MEMORY_RQ_INLINE;
340 rq_attr.flush_in_error_en = 1;
341 mlx5_devx_create_rq_attr_fill(rxq_data, cqn, &rq_attr);
342 /* Fill WQ attributes for this RQ. */
343 if (mlx5_rxq_mprq_enabled(rxq_data)) {
344 rq_attr.wq_attr.wq_type = MLX5_WQ_TYPE_CYCLIC_STRIDING_RQ;
346 * Number of strides in each WQE:
347 * 512*2^single_wqe_log_num_of_strides.
349 rq_attr.wq_attr.single_wqe_log_num_of_strides =
350 rxq_data->strd_num_n -
351 MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES;
352 /* Stride size = (2^single_stride_log_num_of_bytes)*64B. */
353 rq_attr.wq_attr.single_stride_log_num_of_bytes =
354 rxq_data->strd_sz_n -
355 MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES;
356 wqe_size = sizeof(struct mlx5_wqe_mprq);
358 rq_attr.wq_attr.wq_type = MLX5_WQ_TYPE_CYCLIC;
359 wqe_size = sizeof(struct mlx5_wqe_data_seg);
361 log_wqe_size = log2above(wqe_size) + rxq_data->sges_n;
362 rq_attr.wq_attr.log_wq_stride = log_wqe_size;
363 rq_attr.wq_attr.log_wq_sz = rxq_data->elts_n - rxq_data->sges_n;
364 /* Calculate and allocate WQ memory space. */
365 wqe_size = 1 << log_wqe_size; /* round up power of two.*/
366 wq_size = wqe_n * wqe_size;
367 size_t alignment = MLX5_WQE_BUF_ALIGNMENT;
368 if (alignment == (size_t)-1) {
369 DRV_LOG(ERR, "Failed to get mem page size");
373 buf = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, wq_size,
374 alignment, rxq_ctrl->socket);
377 rxq_data->wqes = buf;
378 rxq_ctrl->wq_umem = mlx5_os_umem_reg(priv->sh->ctx,
380 if (!rxq_ctrl->wq_umem)
382 /* Allocate RQ door-bell. */
383 dbr_offset = mlx5_get_dbr(priv->sh->ctx, &priv->dbrpgs, &dbr_page);
384 if (dbr_offset < 0) {
385 DRV_LOG(ERR, "Failed to allocate RQ door-bell.");
388 rxq_ctrl->rq_dbr_offset = dbr_offset;
389 rxq_ctrl->rq_dbrec_page = dbr_page;
390 rxq_data->rq_db = (uint32_t *)((uintptr_t)dbr_page->dbrs +
391 (uintptr_t)rxq_ctrl->rq_dbr_offset);
392 /* Create RQ using DevX API. */
393 mlx5_devx_wq_attr_fill(priv, rxq_ctrl, &rq_attr.wq_attr);
394 rq = mlx5_devx_cmd_create_rq(priv->sh->ctx, &rq_attr, rxq_ctrl->socket);
399 mlx5_rxq_release_devx_rq_resources(rxq_ctrl);
404 * Create a DevX CQ object for an Rx queue.
407 * Pointer to Ethernet device.
409 * Queue index in DPDK Rx queue array.
412 * The DevX CQ object initialized, NULL otherwise and rte_errno is set.
414 static struct mlx5_devx_obj *
415 mlx5_rxq_create_devx_cq_resources(struct rte_eth_dev *dev, uint16_t idx)
417 struct mlx5_devx_obj *cq_obj = 0;
418 struct mlx5_devx_cq_attr cq_attr = { 0 };
419 struct mlx5_priv *priv = dev->data->dev_private;
420 struct mlx5_rxq_data *rxq_data = (*priv->rxqs)[idx];
421 struct mlx5_rxq_ctrl *rxq_ctrl =
422 container_of(rxq_data, struct mlx5_rxq_ctrl, rxq);
423 size_t page_size = rte_mem_page_size();
424 unsigned int cqe_n = mlx5_rxq_cqe_num(rxq_data);
425 struct mlx5_devx_dbr_page *dbr_page;
428 uint16_t event_nums[1] = {0};
433 if (page_size == (size_t)-1) {
434 DRV_LOG(ERR, "Failed to get page_size.");
437 if (priv->config.cqe_comp && !rxq_data->hw_timestamp &&
439 cq_attr.cqe_comp_en = 1u;
440 rxq_data->mcqe_format = priv->config.cqe_comp_fmt;
441 rxq_data->byte_mask = UINT32_MAX;
442 switch (priv->config.cqe_comp_fmt) {
443 case MLX5_CQE_RESP_FORMAT_HASH:
445 case MLX5_CQE_RESP_FORMAT_CSUM:
447 * Select CSUM miniCQE format only for non-vectorized
448 * MPRQ Rx burst, use HASH miniCQE format for others.
450 if (mlx5_rxq_check_vec_support(rxq_data) < 0 &&
451 mlx5_rxq_mprq_enabled(rxq_data))
452 cq_attr.mini_cqe_res_format =
453 MLX5_CQE_RESP_FORMAT_CSUM_STRIDX;
455 cq_attr.mini_cqe_res_format =
456 MLX5_CQE_RESP_FORMAT_HASH;
457 rxq_data->mcqe_format = cq_attr.mini_cqe_res_format;
459 case MLX5_CQE_RESP_FORMAT_FTAG_STRIDX:
460 rxq_data->byte_mask = MLX5_LEN_WITH_MARK_MASK;
462 case MLX5_CQE_RESP_FORMAT_CSUM_STRIDX:
463 cq_attr.mini_cqe_res_format = priv->config.cqe_comp_fmt;
465 case MLX5_CQE_RESP_FORMAT_L34H_STRIDX:
466 cq_attr.mini_cqe_res_format = 0;
467 cq_attr.mini_cqe_res_format_ext = 1;
471 "Port %u Rx CQE compression is enabled, format %d.",
472 dev->data->port_id, priv->config.cqe_comp_fmt);
474 * For vectorized Rx, it must not be doubled in order to
475 * make cq_ci and rq_ci aligned.
477 if (mlx5_rxq_check_vec_support(rxq_data) < 0)
479 } else if (priv->config.cqe_comp && rxq_data->hw_timestamp) {
481 "Port %u Rx CQE compression is disabled for HW"
484 } else if (priv->config.cqe_comp && rxq_data->lro) {
486 "Port %u Rx CQE compression is disabled for LRO.",
489 if (priv->config.cqe_pad)
490 cq_attr.cqe_size = MLX5_CQE_SIZE_128B;
491 log_cqe_n = log2above(cqe_n);
492 cq_size = sizeof(struct mlx5_cqe) * (1 << log_cqe_n);
493 buf = rte_calloc_socket(__func__, 1, cq_size, page_size,
496 DRV_LOG(ERR, "Failed to allocate memory for CQ.");
499 rxq_data->cqes = (volatile struct mlx5_cqe (*)[])(uintptr_t)buf;
500 rxq_ctrl->cq_umem = mlx5_os_umem_reg(priv->sh->ctx, buf,
502 IBV_ACCESS_LOCAL_WRITE);
503 if (!rxq_ctrl->cq_umem) {
504 DRV_LOG(ERR, "Failed to register umem for CQ.");
507 /* Allocate CQ door-bell. */
508 dbr_offset = mlx5_get_dbr(priv->sh->ctx, &priv->dbrpgs, &dbr_page);
509 if (dbr_offset < 0) {
510 DRV_LOG(ERR, "Failed to allocate CQ door-bell.");
513 rxq_ctrl->cq_dbr_offset = dbr_offset;
514 rxq_ctrl->cq_dbrec_page = dbr_page;
515 rxq_data->cq_db = (uint32_t *)((uintptr_t)dbr_page->dbrs +
516 (uintptr_t)rxq_ctrl->cq_dbr_offset);
518 mlx5_os_get_devx_uar_base_addr(priv->sh->devx_rx_uar);
519 /* Create CQ using DevX API. */
520 cq_attr.eqn = priv->sh->eqn;
521 cq_attr.uar_page_id =
522 mlx5_os_get_devx_uar_page_id(priv->sh->devx_rx_uar);
523 cq_attr.q_umem_id = mlx5_os_get_umem_id(rxq_ctrl->cq_umem);
524 cq_attr.q_umem_valid = 1;
525 cq_attr.log_cq_size = log_cqe_n;
526 cq_attr.log_page_size = rte_log2_u32(page_size);
527 cq_attr.db_umem_offset = rxq_ctrl->cq_dbr_offset;
528 cq_attr.db_umem_id = mlx5_os_get_umem_id(dbr_page->umem);
529 cq_attr.db_umem_valid = 1;
530 cq_obj = mlx5_devx_cmd_create_cq(priv->sh->ctx, &cq_attr);
533 rxq_data->cqe_n = log_cqe_n;
534 rxq_data->cqn = cq_obj->id;
535 if (rxq_ctrl->obj->devx_channel) {
536 ret = mlx5_os_devx_subscribe_devx_event
537 (rxq_ctrl->obj->devx_channel,
541 (uint64_t)(uintptr_t)cq_obj);
543 DRV_LOG(ERR, "Fail to subscribe CQ to event channel.");
548 /* Initialise CQ to 1's to mark HW ownership for all CQEs. */
549 memset((void *)(uintptr_t)rxq_data->cqes, 0xFF, cq_size);
553 mlx5_devx_cmd_destroy(cq_obj);
554 mlx5_rxq_release_devx_cq_resources(rxq_ctrl);
559 * Create the Rx hairpin queue object.
562 * Pointer to Ethernet device.
564 * Queue index in DPDK Rx queue array.
567 * 0 on success, a negative errno value otherwise and rte_errno is set.
570 mlx5_rxq_obj_hairpin_new(struct rte_eth_dev *dev, uint16_t idx)
572 struct mlx5_priv *priv = dev->data->dev_private;
573 struct mlx5_rxq_data *rxq_data = (*priv->rxqs)[idx];
574 struct mlx5_rxq_ctrl *rxq_ctrl =
575 container_of(rxq_data, struct mlx5_rxq_ctrl, rxq);
576 struct mlx5_devx_create_rq_attr attr = { 0 };
577 struct mlx5_rxq_obj *tmpl = rxq_ctrl->obj;
578 uint32_t max_wq_data;
580 MLX5_ASSERT(rxq_data);
582 tmpl->rxq_ctrl = rxq_ctrl;
584 max_wq_data = priv->config.hca_attr.log_max_hairpin_wq_data_sz;
585 /* Jumbo frames > 9KB should be supported, and more packets. */
586 if (priv->config.log_hp_size != (uint32_t)MLX5_ARG_UNSET) {
587 if (priv->config.log_hp_size > max_wq_data) {
588 DRV_LOG(ERR, "Total data size %u power of 2 is "
589 "too large for hairpin.",
590 priv->config.log_hp_size);
594 attr.wq_attr.log_hairpin_data_sz = priv->config.log_hp_size;
596 attr.wq_attr.log_hairpin_data_sz =
597 (max_wq_data < MLX5_HAIRPIN_JUMBO_LOG_SIZE) ?
598 max_wq_data : MLX5_HAIRPIN_JUMBO_LOG_SIZE;
600 /* Set the packets number to the maximum value for performance. */
601 attr.wq_attr.log_hairpin_num_packets =
602 attr.wq_attr.log_hairpin_data_sz -
603 MLX5_HAIRPIN_QUEUE_STRIDE;
604 tmpl->rq = mlx5_devx_cmd_create_rq(priv->sh->ctx, &attr,
608 "Port %u Rx hairpin queue %u can't create rq object.",
609 dev->data->port_id, idx);
613 dev->data->rx_queue_state[idx] = RTE_ETH_QUEUE_STATE_HAIRPIN;
618 * Create the Rx queue DevX object.
621 * Pointer to Ethernet device.
623 * Queue index in DPDK Rx queue array.
626 * 0 on success, a negative errno value otherwise and rte_errno is set.
629 mlx5_rxq_devx_obj_new(struct rte_eth_dev *dev, uint16_t idx)
631 struct mlx5_priv *priv = dev->data->dev_private;
632 struct mlx5_rxq_data *rxq_data = (*priv->rxqs)[idx];
633 struct mlx5_rxq_ctrl *rxq_ctrl =
634 container_of(rxq_data, struct mlx5_rxq_ctrl, rxq);
635 struct mlx5_rxq_obj *tmpl = rxq_ctrl->obj;
638 MLX5_ASSERT(rxq_data);
640 if (rxq_ctrl->type == MLX5_RXQ_TYPE_HAIRPIN)
641 return mlx5_rxq_obj_hairpin_new(dev, idx);
642 tmpl->rxq_ctrl = rxq_ctrl;
645 MLX5DV_DEVX_CREATE_EVENT_CHANNEL_FLAGS_OMIT_EV_DATA;
647 tmpl->devx_channel = mlx5_os_devx_create_event_channel
650 if (!tmpl->devx_channel) {
652 DRV_LOG(ERR, "Failed to create event channel %d.",
656 tmpl->fd = mlx5_os_get_devx_channel_fd(tmpl->devx_channel);
658 /* Create CQ using DevX API. */
659 tmpl->devx_cq = mlx5_rxq_create_devx_cq_resources(dev, idx);
660 if (!tmpl->devx_cq) {
661 DRV_LOG(ERR, "Failed to create CQ.");
664 /* Create RQ using DevX API. */
665 tmpl->rq = mlx5_rxq_create_devx_rq_resources(dev, idx);
667 DRV_LOG(ERR, "Port %u Rx queue %u RQ creation failure.",
668 dev->data->port_id, idx);
672 /* Change queue state to ready. */
673 ret = mlx5_devx_modify_rq(tmpl, MLX5_RXQ_MOD_RST2RDY);
676 rxq_data->cq_arm_sn = 0;
677 mlx5_rxq_initialize(rxq_data);
679 dev->data->rx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STARTED;
680 rxq_ctrl->wqn = tmpl->rq->id;
683 ret = rte_errno; /* Save rte_errno before cleanup. */
685 claim_zero(mlx5_devx_cmd_destroy(tmpl->rq));
687 claim_zero(mlx5_devx_cmd_destroy(tmpl->devx_cq));
688 if (tmpl->devx_channel)
689 mlx5_os_devx_destroy_event_channel(tmpl->devx_channel);
690 mlx5_rxq_release_devx_rq_resources(rxq_ctrl);
691 mlx5_rxq_release_devx_cq_resources(rxq_ctrl);
692 rte_errno = ret; /* Restore rte_errno. */
697 * Prepare RQT attribute structure for DevX RQT API.
700 * Pointer to Ethernet device.
702 * Log of number of queues in the array.
704 * DevX indirection table object.
707 * The RQT attr object initialized, NULL otherwise and rte_errno is set.
709 static struct mlx5_devx_rqt_attr *
710 mlx5_devx_ind_table_create_rqt_attr(struct rte_eth_dev *dev,
711 const unsigned int log_n,
712 const uint16_t *queues,
713 const uint32_t queues_n)
715 struct mlx5_priv *priv = dev->data->dev_private;
716 struct mlx5_devx_rqt_attr *rqt_attr = NULL;
717 const unsigned int rqt_n = 1 << log_n;
720 rqt_attr = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*rqt_attr) +
721 rqt_n * sizeof(uint32_t), 0, SOCKET_ID_ANY);
723 DRV_LOG(ERR, "Port %u cannot allocate RQT resources.",
728 rqt_attr->rqt_max_size = priv->config.ind_table_max_size;
729 rqt_attr->rqt_actual_size = rqt_n;
730 for (i = 0; i != queues_n; ++i) {
731 struct mlx5_rxq_data *rxq = (*priv->rxqs)[queues[i]];
732 struct mlx5_rxq_ctrl *rxq_ctrl =
733 container_of(rxq, struct mlx5_rxq_ctrl, rxq);
735 rqt_attr->rq_list[i] = rxq_ctrl->obj->rq->id;
738 for (j = 0; i != rqt_n; ++j, ++i)
739 rqt_attr->rq_list[i] = rqt_attr->rq_list[j];
744 * Create RQT using DevX API as a filed of indirection table.
747 * Pointer to Ethernet device.
749 * Log of number of queues in the array.
751 * DevX indirection table object.
754 * 0 on success, a negative errno value otherwise and rte_errno is set.
757 mlx5_devx_ind_table_new(struct rte_eth_dev *dev, const unsigned int log_n,
758 struct mlx5_ind_table_obj *ind_tbl)
760 struct mlx5_priv *priv = dev->data->dev_private;
761 struct mlx5_devx_rqt_attr *rqt_attr = NULL;
763 MLX5_ASSERT(ind_tbl);
764 rqt_attr = mlx5_devx_ind_table_create_rqt_attr(dev, log_n,
769 ind_tbl->rqt = mlx5_devx_cmd_create_rqt(priv->sh->ctx, rqt_attr);
772 DRV_LOG(ERR, "Port %u cannot create DevX RQT.",
781 * Modify RQT using DevX API as a filed of indirection table.
784 * Pointer to Ethernet device.
786 * Log of number of queues in the array.
788 * DevX indirection table object.
791 * 0 on success, a negative errno value otherwise and rte_errno is set.
794 mlx5_devx_ind_table_modify(struct rte_eth_dev *dev, const unsigned int log_n,
795 const uint16_t *queues, const uint32_t queues_n,
796 struct mlx5_ind_table_obj *ind_tbl)
799 struct mlx5_devx_rqt_attr *rqt_attr = NULL;
801 MLX5_ASSERT(ind_tbl);
802 rqt_attr = mlx5_devx_ind_table_create_rqt_attr(dev, log_n,
807 ret = mlx5_devx_cmd_modify_rqt(ind_tbl->rqt, rqt_attr);
810 DRV_LOG(ERR, "Port %u cannot modify DevX RQT.",
816 * Destroy the DevX RQT object.
819 * Indirection table to release.
822 mlx5_devx_ind_table_destroy(struct mlx5_ind_table_obj *ind_tbl)
824 claim_zero(mlx5_devx_cmd_destroy(ind_tbl->rqt));
828 * Set TIR attribute struct with relevant input values.
831 * Pointer to Ethernet device.
833 * RSS key for the Rx hash queue.
834 * @param[in] hash_fields
835 * Verbs protocol hash field to make the RSS on.
837 * Indirection table for TIR.
840 * @param[out] tir_attr
841 * Parameters structure for TIR creation/modification.
844 * The Verbs/DevX object initialised index, 0 otherwise and rte_errno is set.
847 mlx5_devx_tir_attr_set(struct rte_eth_dev *dev, const uint8_t *rss_key,
848 uint64_t hash_fields,
849 const struct mlx5_ind_table_obj *ind_tbl,
850 int tunnel, struct mlx5_devx_tir_attr *tir_attr)
852 struct mlx5_priv *priv = dev->data->dev_private;
853 struct mlx5_rxq_data *rxq_data = (*priv->rxqs)[ind_tbl->queues[0]];
854 struct mlx5_rxq_ctrl *rxq_ctrl =
855 container_of(rxq_data, struct mlx5_rxq_ctrl, rxq);
856 enum mlx5_rxq_type rxq_obj_type = rxq_ctrl->type;
860 /* Enable TIR LRO only if all the queues were configured for. */
861 for (i = 0; i < ind_tbl->queues_n; ++i) {
862 if (!(*priv->rxqs)[ind_tbl->queues[i]]->lro) {
867 memset(tir_attr, 0, sizeof(*tir_attr));
868 tir_attr->disp_type = MLX5_TIRC_DISP_TYPE_INDIRECT;
869 tir_attr->rx_hash_fn = MLX5_RX_HASH_FN_TOEPLITZ;
870 tir_attr->tunneled_offload_en = !!tunnel;
871 /* If needed, translate hash_fields bitmap to PRM format. */
873 struct mlx5_rx_hash_field_select *rx_hash_field_select =
874 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
875 hash_fields & IBV_RX_HASH_INNER ?
876 &tir_attr->rx_hash_field_selector_inner :
878 &tir_attr->rx_hash_field_selector_outer;
879 /* 1 bit: 0: IPv4, 1: IPv6. */
880 rx_hash_field_select->l3_prot_type =
881 !!(hash_fields & MLX5_IPV6_IBV_RX_HASH);
882 /* 1 bit: 0: TCP, 1: UDP. */
883 rx_hash_field_select->l4_prot_type =
884 !!(hash_fields & MLX5_UDP_IBV_RX_HASH);
885 /* Bitmask which sets which fields to use in RX Hash. */
886 rx_hash_field_select->selected_fields =
887 ((!!(hash_fields & MLX5_L3_SRC_IBV_RX_HASH)) <<
888 MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_SRC_IP) |
889 (!!(hash_fields & MLX5_L3_DST_IBV_RX_HASH)) <<
890 MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_DST_IP |
891 (!!(hash_fields & MLX5_L4_SRC_IBV_RX_HASH)) <<
892 MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_L4_SPORT |
893 (!!(hash_fields & MLX5_L4_DST_IBV_RX_HASH)) <<
894 MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_L4_DPORT;
896 if (rxq_obj_type == MLX5_RXQ_TYPE_HAIRPIN)
897 tir_attr->transport_domain = priv->sh->td->id;
899 tir_attr->transport_domain = priv->sh->tdn;
900 memcpy(tir_attr->rx_hash_toeplitz_key, rss_key, MLX5_RSS_HASH_KEY_LEN);
901 tir_attr->indirect_table = ind_tbl->rqt->id;
902 if (dev->data->dev_conf.lpbk_mode)
903 tir_attr->self_lb_block =
904 MLX5_TIRC_SELF_LB_BLOCK_BLOCK_UNICAST;
906 tir_attr->lro_timeout_period_usecs = priv->config.lro.timeout;
907 tir_attr->lro_max_msg_sz = priv->max_lro_msg_size;
908 tir_attr->lro_enable_mask =
909 MLX5_TIRC_LRO_ENABLE_MASK_IPV4_LRO |
910 MLX5_TIRC_LRO_ENABLE_MASK_IPV6_LRO;
915 * Create an Rx Hash queue.
918 * Pointer to Ethernet device.
920 * Pointer to Rx Hash queue.
925 * 0 on success, a negative errno value otherwise and rte_errno is set.
928 mlx5_devx_hrxq_new(struct rte_eth_dev *dev, struct mlx5_hrxq *hrxq,
929 int tunnel __rte_unused)
931 struct mlx5_priv *priv = dev->data->dev_private;
932 struct mlx5_devx_tir_attr tir_attr = {0};
935 mlx5_devx_tir_attr_set(dev, hrxq->rss_key, hrxq->hash_fields,
936 hrxq->ind_table, tunnel, &tir_attr);
937 hrxq->tir = mlx5_devx_cmd_create_tir(priv->sh->ctx, &tir_attr);
939 DRV_LOG(ERR, "Port %u cannot create DevX TIR.",
944 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
945 hrxq->action = mlx5_glue->dv_create_flow_action_dest_devx_tir
954 err = rte_errno; /* Save rte_errno before cleanup. */
956 claim_zero(mlx5_devx_cmd_destroy(hrxq->tir));
957 rte_errno = err; /* Restore rte_errno. */
962 * Destroy a DevX TIR object.
965 * Hash Rx queue to release its tir.
968 mlx5_devx_tir_destroy(struct mlx5_hrxq *hrxq)
970 claim_zero(mlx5_devx_cmd_destroy(hrxq->tir));
974 * Modify an Rx Hash queue configuration.
977 * Pointer to Ethernet device.
979 * Hash Rx queue to modify.
981 * RSS key for the Rx hash queue.
983 * Verbs protocol hash field to make the RSS on.
985 * Indirection table for TIR.
988 * 0 on success, a negative errno value otherwise and rte_errno is set.
991 mlx5_devx_hrxq_modify(struct rte_eth_dev *dev, struct mlx5_hrxq *hrxq,
992 const uint8_t *rss_key,
993 uint64_t hash_fields,
994 const struct mlx5_ind_table_obj *ind_tbl)
996 struct mlx5_devx_modify_tir_attr modify_tir = {0};
999 * untested for modification fields:
1000 * - rx_hash_symmetric not set in hrxq_new(),
1001 * - rx_hash_fn set hard-coded in hrxq_new(),
1002 * - lro_xxx not set after rxq setup
1004 if (ind_tbl != hrxq->ind_table)
1005 modify_tir.modify_bitmask |=
1006 MLX5_MODIFY_TIR_IN_MODIFY_BITMASK_INDIRECT_TABLE;
1007 if (hash_fields != hrxq->hash_fields ||
1008 memcmp(hrxq->rss_key, rss_key, MLX5_RSS_HASH_KEY_LEN))
1009 modify_tir.modify_bitmask |=
1010 MLX5_MODIFY_TIR_IN_MODIFY_BITMASK_HASH;
1011 mlx5_devx_tir_attr_set(dev, rss_key, hash_fields, ind_tbl,
1012 0, /* N/A - tunnel modification unsupported */
1014 modify_tir.tirn = hrxq->tir->id;
1015 if (mlx5_devx_cmd_modify_tir(hrxq->tir, &modify_tir)) {
1016 DRV_LOG(ERR, "port %u cannot modify DevX TIR",
1017 dev->data->port_id);
1025 * Create a DevX drop action for Rx Hash queue.
1028 * Pointer to Ethernet device.
1031 * 0 on success, a negative errno value otherwise and rte_errno is set.
1034 mlx5_devx_drop_action_create(struct rte_eth_dev *dev)
1037 DRV_LOG(ERR, "DevX drop action is not supported yet.");
1038 rte_errno = ENOTSUP;
1043 * Release a drop hash Rx queue.
1046 * Pointer to Ethernet device.
1049 mlx5_devx_drop_action_destroy(struct rte_eth_dev *dev)
1052 DRV_LOG(ERR, "DevX drop action is not supported yet.");
1053 rte_errno = ENOTSUP;
1057 * Create the Tx hairpin queue object.
1060 * Pointer to Ethernet device.
1062 * Queue index in DPDK Tx queue array.
1065 * 0 on success, a negative errno value otherwise and rte_errno is set.
1068 mlx5_txq_obj_hairpin_new(struct rte_eth_dev *dev, uint16_t idx)
1070 struct mlx5_priv *priv = dev->data->dev_private;
1071 struct mlx5_txq_data *txq_data = (*priv->txqs)[idx];
1072 struct mlx5_txq_ctrl *txq_ctrl =
1073 container_of(txq_data, struct mlx5_txq_ctrl, txq);
1074 struct mlx5_devx_create_sq_attr attr = { 0 };
1075 struct mlx5_txq_obj *tmpl = txq_ctrl->obj;
1076 uint32_t max_wq_data;
1078 MLX5_ASSERT(txq_data);
1080 tmpl->txq_ctrl = txq_ctrl;
1082 attr.tis_lst_sz = 1;
1083 max_wq_data = priv->config.hca_attr.log_max_hairpin_wq_data_sz;
1084 /* Jumbo frames > 9KB should be supported, and more packets. */
1085 if (priv->config.log_hp_size != (uint32_t)MLX5_ARG_UNSET) {
1086 if (priv->config.log_hp_size > max_wq_data) {
1087 DRV_LOG(ERR, "Total data size %u power of 2 is "
1088 "too large for hairpin.",
1089 priv->config.log_hp_size);
1093 attr.wq_attr.log_hairpin_data_sz = priv->config.log_hp_size;
1095 attr.wq_attr.log_hairpin_data_sz =
1096 (max_wq_data < MLX5_HAIRPIN_JUMBO_LOG_SIZE) ?
1097 max_wq_data : MLX5_HAIRPIN_JUMBO_LOG_SIZE;
1099 /* Set the packets number to the maximum value for performance. */
1100 attr.wq_attr.log_hairpin_num_packets =
1101 attr.wq_attr.log_hairpin_data_sz -
1102 MLX5_HAIRPIN_QUEUE_STRIDE;
1103 attr.tis_num = priv->sh->tis->id;
1104 tmpl->sq = mlx5_devx_cmd_create_sq(priv->sh->ctx, &attr);
1107 "Port %u tx hairpin queue %u can't create SQ object.",
1108 dev->data->port_id, idx);
1115 #ifdef HAVE_MLX5DV_DEVX_UAR_OFFSET
1117 * Release DevX SQ resources.
1120 * DevX Tx queue object.
1123 mlx5_txq_release_devx_sq_resources(struct mlx5_txq_obj *txq_obj)
1125 if (txq_obj->sq_devx) {
1126 claim_zero(mlx5_devx_cmd_destroy(txq_obj->sq_devx));
1127 txq_obj->sq_devx = NULL;
1129 if (txq_obj->sq_umem) {
1130 claim_zero(mlx5_os_umem_dereg(txq_obj->sq_umem));
1131 txq_obj->sq_umem = NULL;
1133 if (txq_obj->sq_buf) {
1134 mlx5_free(txq_obj->sq_buf);
1135 txq_obj->sq_buf = NULL;
1137 if (txq_obj->sq_dbrec_page) {
1138 claim_zero(mlx5_release_dbr(&txq_obj->txq_ctrl->priv->dbrpgs,
1140 (txq_obj->sq_dbrec_page->umem),
1141 txq_obj->sq_dbrec_offset));
1142 txq_obj->sq_dbrec_page = NULL;
1147 * Release DevX Tx CQ resources.
1150 * DevX Tx queue object.
1153 mlx5_txq_release_devx_cq_resources(struct mlx5_txq_obj *txq_obj)
1155 if (txq_obj->cq_devx)
1156 claim_zero(mlx5_devx_cmd_destroy(txq_obj->cq_devx));
1157 if (txq_obj->cq_umem)
1158 claim_zero(mlx5_os_umem_dereg(txq_obj->cq_umem));
1159 if (txq_obj->cq_buf)
1160 mlx5_free(txq_obj->cq_buf);
1161 if (txq_obj->cq_dbrec_page)
1162 claim_zero(mlx5_release_dbr(&txq_obj->txq_ctrl->priv->dbrpgs,
1164 (txq_obj->cq_dbrec_page->umem),
1165 txq_obj->cq_dbrec_offset));
1169 * Destroy the Tx queue DevX object.
1172 * Txq object to destroy.
1175 mlx5_txq_release_devx_resources(struct mlx5_txq_obj *txq_obj)
1177 mlx5_txq_release_devx_sq_resources(txq_obj);
1178 mlx5_txq_release_devx_cq_resources(txq_obj);
1182 * Create a DevX CQ object and its resources for an Tx queue.
1185 * Pointer to Ethernet device.
1187 * Queue index in DPDK Tx queue array.
1190 * Number of CQEs in CQ, 0 otherwise and rte_errno is set.
1193 mlx5_txq_create_devx_cq_resources(struct rte_eth_dev *dev, uint16_t idx)
1195 struct mlx5_priv *priv = dev->data->dev_private;
1196 struct mlx5_txq_data *txq_data = (*priv->txqs)[idx];
1197 struct mlx5_txq_ctrl *txq_ctrl =
1198 container_of(txq_data, struct mlx5_txq_ctrl, txq);
1199 struct mlx5_txq_obj *txq_obj = txq_ctrl->obj;
1200 struct mlx5_devx_cq_attr cq_attr = { 0 };
1201 struct mlx5_cqe *cqe;
1208 MLX5_ASSERT(txq_data);
1209 MLX5_ASSERT(txq_obj);
1210 page_size = rte_mem_page_size();
1211 if (page_size == (size_t)-1) {
1212 DRV_LOG(ERR, "Failed to get mem page size.");
1216 /* Allocate memory buffer for CQEs. */
1217 alignment = MLX5_CQE_BUF_ALIGNMENT;
1218 if (alignment == (size_t)-1) {
1219 DRV_LOG(ERR, "Failed to get CQE buf alignment.");
1223 /* Create the Completion Queue. */
1224 cqe_n = (1UL << txq_data->elts_n) / MLX5_TX_COMP_THRESH +
1225 1 + MLX5_TX_COMP_THRESH_INLINE_DIV;
1226 cqe_n = 1UL << log2above(cqe_n);
1227 if (cqe_n > UINT16_MAX) {
1229 "Port %u Tx queue %u requests to many CQEs %u.",
1230 dev->data->port_id, txq_data->idx, cqe_n);
1234 txq_obj->cq_buf = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO,
1235 cqe_n * sizeof(struct mlx5_cqe),
1237 priv->sh->numa_node);
1238 if (!txq_obj->cq_buf) {
1240 "Port %u Tx queue %u cannot allocate memory (CQ).",
1241 dev->data->port_id, txq_data->idx);
1245 /* Register allocated buffer in user space with DevX. */
1246 txq_obj->cq_umem = mlx5_os_umem_reg(priv->sh->ctx,
1247 (void *)txq_obj->cq_buf,
1248 cqe_n * sizeof(struct mlx5_cqe),
1249 IBV_ACCESS_LOCAL_WRITE);
1250 if (!txq_obj->cq_umem) {
1253 "Port %u Tx queue %u cannot register memory (CQ).",
1254 dev->data->port_id, txq_data->idx);
1257 /* Allocate doorbell record for completion queue. */
1258 txq_obj->cq_dbrec_offset = mlx5_get_dbr(priv->sh->ctx,
1260 &txq_obj->cq_dbrec_page);
1261 if (txq_obj->cq_dbrec_offset < 0) {
1263 DRV_LOG(ERR, "Failed to allocate CQ door-bell.");
1266 cq_attr.cqe_size = (sizeof(struct mlx5_cqe) == 128) ?
1267 MLX5_CQE_SIZE_128B : MLX5_CQE_SIZE_64B;
1268 cq_attr.uar_page_id = mlx5_os_get_devx_uar_page_id(priv->sh->tx_uar);
1269 cq_attr.eqn = priv->sh->eqn;
1270 cq_attr.q_umem_valid = 1;
1271 cq_attr.q_umem_offset = (uintptr_t)txq_obj->cq_buf % page_size;
1272 cq_attr.q_umem_id = mlx5_os_get_umem_id(txq_obj->cq_umem);
1273 cq_attr.db_umem_valid = 1;
1274 cq_attr.db_umem_offset = txq_obj->cq_dbrec_offset;
1275 cq_attr.db_umem_id = mlx5_os_get_umem_id(txq_obj->cq_dbrec_page->umem);
1276 cq_attr.log_cq_size = rte_log2_u32(cqe_n);
1277 cq_attr.log_page_size = rte_log2_u32(page_size);
1278 /* Create completion queue object with DevX. */
1279 txq_obj->cq_devx = mlx5_devx_cmd_create_cq(priv->sh->ctx, &cq_attr);
1280 if (!txq_obj->cq_devx) {
1282 DRV_LOG(ERR, "Port %u Tx queue %u CQ creation failure.",
1283 dev->data->port_id, idx);
1286 /* Initial fill CQ buffer with invalid CQE opcode. */
1287 cqe = (struct mlx5_cqe *)txq_obj->cq_buf;
1288 for (i = 0; i < cqe_n; i++) {
1289 cqe->op_own = (MLX5_CQE_INVALID << 4) | MLX5_CQE_OWNER_MASK;
1295 mlx5_txq_release_devx_cq_resources(txq_obj);
1301 * Create a SQ object and its resources using DevX.
1304 * Pointer to Ethernet device.
1306 * Queue index in DPDK Tx queue array.
1309 * Number of WQEs in SQ, 0 otherwise and rte_errno is set.
1312 mlx5_txq_create_devx_sq_resources(struct rte_eth_dev *dev, uint16_t idx)
1314 struct mlx5_priv *priv = dev->data->dev_private;
1315 struct mlx5_txq_data *txq_data = (*priv->txqs)[idx];
1316 struct mlx5_txq_ctrl *txq_ctrl =
1317 container_of(txq_data, struct mlx5_txq_ctrl, txq);
1318 struct mlx5_txq_obj *txq_obj = txq_ctrl->obj;
1319 struct mlx5_devx_create_sq_attr sq_attr = { 0 };
1324 MLX5_ASSERT(txq_data);
1325 MLX5_ASSERT(txq_obj);
1326 page_size = rte_mem_page_size();
1327 if (page_size == (size_t)-1) {
1328 DRV_LOG(ERR, "Failed to get mem page size.");
1332 wqe_n = RTE_MIN(1UL << txq_data->elts_n,
1333 (uint32_t)priv->sh->device_attr.max_qp_wr);
1334 txq_obj->sq_buf = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO,
1335 wqe_n * sizeof(struct mlx5_wqe),
1336 page_size, priv->sh->numa_node);
1337 if (!txq_obj->sq_buf) {
1339 "Port %u Tx queue %u cannot allocate memory (SQ).",
1340 dev->data->port_id, txq_data->idx);
1344 /* Register allocated buffer in user space with DevX. */
1345 txq_obj->sq_umem = mlx5_os_umem_reg
1347 (void *)txq_obj->sq_buf,
1348 wqe_n * sizeof(struct mlx5_wqe),
1349 IBV_ACCESS_LOCAL_WRITE);
1350 if (!txq_obj->sq_umem) {
1353 "Port %u Tx queue %u cannot register memory (SQ).",
1354 dev->data->port_id, txq_data->idx);
1357 /* Allocate doorbell record for send queue. */
1358 txq_obj->sq_dbrec_offset = mlx5_get_dbr(priv->sh->ctx,
1360 &txq_obj->sq_dbrec_page);
1361 if (txq_obj->sq_dbrec_offset < 0) {
1363 DRV_LOG(ERR, "Failed to allocate SQ door-bell.");
1366 sq_attr.tis_lst_sz = 1;
1367 sq_attr.tis_num = priv->sh->tis->id;
1368 sq_attr.state = MLX5_SQC_STATE_RST;
1369 sq_attr.cqn = txq_obj->cq_devx->id;
1370 sq_attr.flush_in_error_en = 1;
1371 sq_attr.allow_multi_pkt_send_wqe = !!priv->config.mps;
1372 sq_attr.allow_swp = !!priv->config.swp;
1373 sq_attr.min_wqe_inline_mode = priv->config.hca_attr.vport_inline_mode;
1374 sq_attr.wq_attr.uar_page =
1375 mlx5_os_get_devx_uar_page_id(priv->sh->tx_uar);
1376 sq_attr.wq_attr.wq_type = MLX5_WQ_TYPE_CYCLIC;
1377 sq_attr.wq_attr.pd = priv->sh->pdn;
1378 sq_attr.wq_attr.log_wq_stride = rte_log2_u32(MLX5_WQE_SIZE);
1379 sq_attr.wq_attr.log_wq_sz = log2above(wqe_n);
1380 sq_attr.wq_attr.dbr_umem_valid = 1;
1381 sq_attr.wq_attr.dbr_addr = txq_obj->sq_dbrec_offset;
1382 sq_attr.wq_attr.dbr_umem_id =
1383 mlx5_os_get_umem_id(txq_obj->sq_dbrec_page->umem);
1384 sq_attr.wq_attr.wq_umem_valid = 1;
1385 sq_attr.wq_attr.wq_umem_id = mlx5_os_get_umem_id(txq_obj->sq_umem);
1386 sq_attr.wq_attr.wq_umem_offset = (uintptr_t)txq_obj->sq_buf % page_size;
1387 /* Create Send Queue object with DevX. */
1388 txq_obj->sq_devx = mlx5_devx_cmd_create_sq(priv->sh->ctx, &sq_attr);
1389 if (!txq_obj->sq_devx) {
1391 DRV_LOG(ERR, "Port %u Tx queue %u SQ creation failure.",
1392 dev->data->port_id, idx);
1398 mlx5_txq_release_devx_sq_resources(txq_obj);
1405 * Create the Tx queue DevX object.
1408 * Pointer to Ethernet device.
1410 * Queue index in DPDK Tx queue array.
1413 * 0 on success, a negative errno value otherwise and rte_errno is set.
1416 mlx5_txq_devx_obj_new(struct rte_eth_dev *dev, uint16_t idx)
1418 struct mlx5_priv *priv = dev->data->dev_private;
1419 struct mlx5_txq_data *txq_data = (*priv->txqs)[idx];
1420 struct mlx5_txq_ctrl *txq_ctrl =
1421 container_of(txq_data, struct mlx5_txq_ctrl, txq);
1423 if (txq_ctrl->type == MLX5_TXQ_TYPE_HAIRPIN)
1424 return mlx5_txq_obj_hairpin_new(dev, idx);
1425 #ifndef HAVE_MLX5DV_DEVX_UAR_OFFSET
1426 DRV_LOG(ERR, "Port %u Tx queue %u cannot create with DevX, no UAR.",
1427 dev->data->port_id, idx);
1431 struct mlx5_dev_ctx_shared *sh = priv->sh;
1432 struct mlx5_txq_obj *txq_obj = txq_ctrl->obj;
1438 MLX5_ASSERT(txq_data);
1439 MLX5_ASSERT(txq_obj);
1440 txq_obj->txq_ctrl = txq_ctrl;
1442 cqe_n = mlx5_txq_create_devx_cq_resources(dev, idx);
1447 txq_data->cqe_n = log2above(cqe_n);
1448 txq_data->cqe_s = 1 << txq_data->cqe_n;
1449 txq_data->cqe_m = txq_data->cqe_s - 1;
1450 txq_data->cqes = (volatile struct mlx5_cqe *)txq_obj->cq_buf;
1451 txq_data->cq_ci = 0;
1452 txq_data->cq_pi = 0;
1453 txq_data->cq_db = (volatile uint32_t *)(txq_obj->cq_dbrec_page->dbrs +
1454 txq_obj->cq_dbrec_offset);
1455 *txq_data->cq_db = 0;
1456 /* Create Send Queue object with DevX. */
1457 wqe_n = mlx5_txq_create_devx_sq_resources(dev, idx);
1462 /* Create the Work Queue. */
1463 txq_data->wqe_n = log2above(wqe_n);
1464 txq_data->wqe_s = 1 << txq_data->wqe_n;
1465 txq_data->wqe_m = txq_data->wqe_s - 1;
1466 txq_data->wqes = (struct mlx5_wqe *)txq_obj->sq_buf;
1467 txq_data->wqes_end = txq_data->wqes + txq_data->wqe_s;
1468 txq_data->wqe_ci = 0;
1469 txq_data->wqe_pi = 0;
1470 txq_data->wqe_comp = 0;
1471 txq_data->wqe_thres = txq_data->wqe_s / MLX5_TX_COMP_THRESH_INLINE_DIV;
1472 txq_data->qp_db = (volatile uint32_t *)
1473 (txq_obj->sq_dbrec_page->dbrs +
1474 txq_obj->sq_dbrec_offset +
1475 MLX5_SND_DBR * sizeof(uint32_t));
1476 *txq_data->qp_db = 0;
1477 txq_data->qp_num_8s = txq_obj->sq_devx->id << 8;
1478 /* Change Send Queue state to Ready-to-Send. */
1479 ret = mlx5_devx_modify_sq(txq_obj, MLX5_TXQ_MOD_RST2RDY, 0);
1483 "Port %u Tx queue %u SQ state to SQC_STATE_RDY failed.",
1484 dev->data->port_id, idx);
1487 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
1489 * If using DevX need to query and store TIS transport domain value.
1490 * This is done once per port.
1491 * Will use this value on Rx, when creating matching TIR.
1494 priv->sh->tdn = priv->sh->td->id;
1496 MLX5_ASSERT(sh->tx_uar);
1497 reg_addr = mlx5_os_get_devx_uar_reg_addr(sh->tx_uar);
1498 MLX5_ASSERT(reg_addr);
1499 txq_ctrl->bf_reg = reg_addr;
1500 txq_ctrl->uar_mmap_offset =
1501 mlx5_os_get_devx_uar_mmap_offset(sh->tx_uar);
1502 txq_uar_init(txq_ctrl);
1503 dev->data->tx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STARTED;
1506 ret = rte_errno; /* Save rte_errno before cleanup. */
1507 mlx5_txq_release_devx_resources(txq_obj);
1508 rte_errno = ret; /* Restore rte_errno. */
1514 * Release an Tx DevX queue object.
1517 * DevX Tx queue object.
1520 mlx5_txq_devx_obj_release(struct mlx5_txq_obj *txq_obj)
1522 MLX5_ASSERT(txq_obj);
1523 if (txq_obj->txq_ctrl->type == MLX5_TXQ_TYPE_HAIRPIN) {
1525 claim_zero(mlx5_devx_cmd_destroy(txq_obj->tis));
1526 #ifdef HAVE_MLX5DV_DEVX_UAR_OFFSET
1528 mlx5_txq_release_devx_resources(txq_obj);
1533 struct mlx5_obj_ops devx_obj_ops = {
1534 .rxq_obj_modify_vlan_strip = mlx5_rxq_obj_modify_rq_vlan_strip,
1535 .rxq_obj_new = mlx5_rxq_devx_obj_new,
1536 .rxq_event_get = mlx5_rx_devx_get_event,
1537 .rxq_obj_modify = mlx5_devx_modify_rq,
1538 .rxq_obj_release = mlx5_rxq_devx_obj_release,
1539 .ind_table_new = mlx5_devx_ind_table_new,
1540 .ind_table_modify = mlx5_devx_ind_table_modify,
1541 .ind_table_destroy = mlx5_devx_ind_table_destroy,
1542 .hrxq_new = mlx5_devx_hrxq_new,
1543 .hrxq_destroy = mlx5_devx_tir_destroy,
1544 .hrxq_modify = mlx5_devx_hrxq_modify,
1545 .drop_action_create = mlx5_devx_drop_action_create,
1546 .drop_action_destroy = mlx5_devx_drop_action_destroy,
1547 .txq_obj_new = mlx5_txq_devx_obj_new,
1548 .txq_obj_modify = mlx5_devx_modify_sq,
1549 .txq_obj_release = mlx5_txq_devx_obj_release,