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_common_devx.h>
19 #include <mlx5_malloc.h>
22 #include "mlx5_common_os.h"
23 #include "mlx5_rxtx.h"
24 #include "mlx5_utils.h"
25 #include "mlx5_devx.h"
26 #include "mlx5_flow.h"
27 #include "mlx5_flow_os.h"
30 * Modify RQ vlan stripping offload
36 * 0 on success, non-0 otherwise
39 mlx5_rxq_obj_modify_rq_vlan_strip(struct mlx5_rxq_obj *rxq_obj, int on)
41 struct mlx5_devx_modify_rq_attr rq_attr;
43 memset(&rq_attr, 0, sizeof(rq_attr));
44 rq_attr.rq_state = MLX5_RQC_STATE_RDY;
45 rq_attr.state = MLX5_RQC_STATE_RDY;
46 rq_attr.vsd = (on ? 0 : 1);
47 rq_attr.modify_bitmask = MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_VSD;
48 return mlx5_devx_cmd_modify_rq(rxq_obj->rq_obj.rq, &rq_attr);
52 * Modify RQ using DevX API.
55 * DevX Rx queue object.
57 * Type of change queue state.
60 * 0 on success, a negative errno value otherwise and rte_errno is set.
63 mlx5_devx_modify_rq(struct mlx5_rxq_obj *rxq_obj, uint8_t type)
65 struct mlx5_devx_modify_rq_attr rq_attr;
67 memset(&rq_attr, 0, sizeof(rq_attr));
69 case MLX5_RXQ_MOD_ERR2RST:
70 rq_attr.rq_state = MLX5_RQC_STATE_ERR;
71 rq_attr.state = MLX5_RQC_STATE_RST;
73 case MLX5_RXQ_MOD_RST2RDY:
74 rq_attr.rq_state = MLX5_RQC_STATE_RST;
75 rq_attr.state = MLX5_RQC_STATE_RDY;
77 case MLX5_RXQ_MOD_RDY2ERR:
78 rq_attr.rq_state = MLX5_RQC_STATE_RDY;
79 rq_attr.state = MLX5_RQC_STATE_ERR;
81 case MLX5_RXQ_MOD_RDY2RST:
82 rq_attr.rq_state = MLX5_RQC_STATE_RDY;
83 rq_attr.state = MLX5_RQC_STATE_RST;
88 return mlx5_devx_cmd_modify_rq(rxq_obj->rq_obj.rq, &rq_attr);
92 * Modify SQ using DevX API.
95 * DevX Tx queue object.
97 * Type of change queue state.
102 * 0 on success, a negative errno value otherwise and rte_errno is set.
105 mlx5_devx_modify_sq(struct mlx5_txq_obj *obj, enum mlx5_txq_modify_type type,
108 struct mlx5_devx_modify_sq_attr msq_attr = { 0 };
111 if (type != MLX5_TXQ_MOD_RST2RDY) {
112 /* Change queue state to reset. */
113 if (type == MLX5_TXQ_MOD_ERR2RDY)
114 msq_attr.sq_state = MLX5_SQC_STATE_ERR;
116 msq_attr.sq_state = MLX5_SQC_STATE_RDY;
117 msq_attr.state = MLX5_SQC_STATE_RST;
118 ret = mlx5_devx_cmd_modify_sq(obj->sq_obj.sq, &msq_attr);
120 DRV_LOG(ERR, "Cannot change the Tx SQ state to RESET"
121 " %s", strerror(errno));
126 if (type != MLX5_TXQ_MOD_RDY2RST) {
127 /* Change queue state to ready. */
128 msq_attr.sq_state = MLX5_SQC_STATE_RST;
129 msq_attr.state = MLX5_SQC_STATE_RDY;
130 ret = mlx5_devx_cmd_modify_sq(obj->sq_obj.sq, &msq_attr);
132 DRV_LOG(ERR, "Cannot change the Tx SQ state to READY"
133 " %s", strerror(errno));
139 * The dev_port variable is relevant only in Verbs API, and there is a
140 * pointer that points to this function and a parallel function in verbs
141 * intermittently, so they should have the same parameters.
148 * Destroy the Rx queue DevX object.
151 * Rxq object to destroy.
154 mlx5_rxq_release_devx_resources(struct mlx5_rxq_obj *rxq_obj)
156 mlx5_devx_rq_destroy(&rxq_obj->rq_obj);
157 memset(&rxq_obj->rq_obj, 0, sizeof(rxq_obj->rq_obj));
158 mlx5_devx_cq_destroy(&rxq_obj->cq_obj);
159 memset(&rxq_obj->cq_obj, 0, sizeof(rxq_obj->cq_obj));
163 * Release an Rx DevX queue object.
166 * DevX Rx queue object.
169 mlx5_rxq_devx_obj_release(struct mlx5_rxq_obj *rxq_obj)
171 MLX5_ASSERT(rxq_obj);
172 if (rxq_obj->rxq_ctrl->type == MLX5_RXQ_TYPE_HAIRPIN) {
173 MLX5_ASSERT(rxq_obj->rq);
174 mlx5_devx_modify_rq(rxq_obj, MLX5_RXQ_MOD_RDY2RST);
175 claim_zero(mlx5_devx_cmd_destroy(rxq_obj->rq));
177 MLX5_ASSERT(rxq_obj->cq_obj.cq);
178 MLX5_ASSERT(rxq_obj->rq_obj.rq);
179 mlx5_rxq_release_devx_resources(rxq_obj);
180 if (rxq_obj->devx_channel)
181 mlx5_os_devx_destroy_event_channel
182 (rxq_obj->devx_channel);
187 * Get event for an Rx DevX queue object.
190 * DevX Rx queue object.
193 * 0 on success, a negative errno value otherwise and rte_errno is set.
196 mlx5_rx_devx_get_event(struct mlx5_rxq_obj *rxq_obj)
198 #ifdef HAVE_IBV_DEVX_EVENT
200 struct mlx5dv_devx_async_event_hdr event_resp;
201 uint8_t buf[sizeof(struct mlx5dv_devx_async_event_hdr) + 128];
203 int ret = mlx5_glue->devx_get_event(rxq_obj->devx_channel,
211 if (out.event_resp.cookie != (uint64_t)(uintptr_t)rxq_obj->cq_obj.cq) {
220 #endif /* HAVE_IBV_DEVX_EVENT */
224 * Create a RQ object using DevX.
227 * Pointer to Ethernet device.
229 * Queue index in DPDK Rx queue array.
232 * 0 on success, a negative errno value otherwise and rte_errno is set.
235 mlx5_rxq_create_devx_rq_resources(struct rte_eth_dev *dev, uint16_t idx)
237 struct mlx5_priv *priv = dev->data->dev_private;
238 struct mlx5_rxq_data *rxq_data = (*priv->rxqs)[idx];
239 struct mlx5_rxq_ctrl *rxq_ctrl =
240 container_of(rxq_data, struct mlx5_rxq_ctrl, rxq);
241 struct mlx5_devx_create_rq_attr rq_attr = { 0 };
242 uint16_t log_desc_n = rxq_data->elts_n - rxq_data->sges_n;
243 uint32_t wqe_size, log_wqe_size;
245 /* Fill RQ attributes. */
246 rq_attr.mem_rq_type = MLX5_RQC_MEM_RQ_TYPE_MEMORY_RQ_INLINE;
247 rq_attr.flush_in_error_en = 1;
248 rq_attr.vsd = (rxq_data->vlan_strip) ? 0 : 1;
249 rq_attr.cqn = rxq_ctrl->obj->cq_obj.cq->id;
250 rq_attr.scatter_fcs = (rxq_data->crc_present) ? 1 : 0;
251 /* Fill WQ attributes for this RQ. */
252 if (mlx5_rxq_mprq_enabled(rxq_data)) {
253 rq_attr.wq_attr.wq_type = MLX5_WQ_TYPE_CYCLIC_STRIDING_RQ;
255 * Number of strides in each WQE:
256 * 512*2^single_wqe_log_num_of_strides.
258 rq_attr.wq_attr.single_wqe_log_num_of_strides =
259 rxq_data->strd_num_n -
260 MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES;
261 /* Stride size = (2^single_stride_log_num_of_bytes)*64B. */
262 rq_attr.wq_attr.single_stride_log_num_of_bytes =
263 rxq_data->strd_sz_n -
264 MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES;
265 wqe_size = sizeof(struct mlx5_wqe_mprq);
267 rq_attr.wq_attr.wq_type = MLX5_WQ_TYPE_CYCLIC;
268 wqe_size = sizeof(struct mlx5_wqe_data_seg);
270 log_wqe_size = log2above(wqe_size) + rxq_data->sges_n;
271 wqe_size = 1 << log_wqe_size; /* round up power of two.*/
272 rq_attr.wq_attr.log_wq_stride = log_wqe_size;
273 rq_attr.wq_attr.log_wq_sz = log_desc_n;
274 rq_attr.wq_attr.end_padding_mode = priv->config.hw_padding ?
275 MLX5_WQ_END_PAD_MODE_ALIGN :
276 MLX5_WQ_END_PAD_MODE_NONE;
277 rq_attr.wq_attr.pd = priv->sh->pdn;
278 /* Create RQ using DevX API. */
279 return mlx5_devx_rq_create(priv->sh->ctx, &rxq_ctrl->obj->rq_obj,
280 wqe_size, log_desc_n, &rq_attr,
285 * Create a DevX CQ object for an Rx queue.
288 * Pointer to Ethernet device.
290 * Queue index in DPDK Rx queue array.
293 * 0 on success, a negative errno value otherwise and rte_errno is set.
296 mlx5_rxq_create_devx_cq_resources(struct rte_eth_dev *dev, uint16_t idx)
298 struct mlx5_devx_cq *cq_obj = 0;
299 struct mlx5_devx_cq_attr cq_attr = { 0 };
300 struct mlx5_priv *priv = dev->data->dev_private;
301 struct mlx5_dev_ctx_shared *sh = priv->sh;
302 struct mlx5_rxq_data *rxq_data = (*priv->rxqs)[idx];
303 struct mlx5_rxq_ctrl *rxq_ctrl =
304 container_of(rxq_data, struct mlx5_rxq_ctrl, rxq);
305 unsigned int cqe_n = mlx5_rxq_cqe_num(rxq_data);
307 uint16_t event_nums[1] = { 0 };
310 if (priv->config.cqe_comp && !rxq_data->hw_timestamp &&
312 cq_attr.cqe_comp_en = 1u;
313 rxq_data->mcqe_format = priv->config.cqe_comp_fmt;
314 rxq_data->byte_mask = UINT32_MAX;
315 switch (priv->config.cqe_comp_fmt) {
316 case MLX5_CQE_RESP_FORMAT_HASH:
318 case MLX5_CQE_RESP_FORMAT_CSUM:
320 * Select CSUM miniCQE format only for non-vectorized
321 * MPRQ Rx burst, use HASH miniCQE format for others.
323 if (mlx5_rxq_check_vec_support(rxq_data) < 0 &&
324 mlx5_rxq_mprq_enabled(rxq_data))
325 cq_attr.mini_cqe_res_format =
326 MLX5_CQE_RESP_FORMAT_CSUM_STRIDX;
328 cq_attr.mini_cqe_res_format =
329 MLX5_CQE_RESP_FORMAT_HASH;
330 rxq_data->mcqe_format = cq_attr.mini_cqe_res_format;
332 case MLX5_CQE_RESP_FORMAT_FTAG_STRIDX:
333 rxq_data->byte_mask = MLX5_LEN_WITH_MARK_MASK;
335 case MLX5_CQE_RESP_FORMAT_CSUM_STRIDX:
336 cq_attr.mini_cqe_res_format = priv->config.cqe_comp_fmt;
338 case MLX5_CQE_RESP_FORMAT_L34H_STRIDX:
339 cq_attr.mini_cqe_res_format = 0;
340 cq_attr.mini_cqe_res_format_ext = 1;
344 "Port %u Rx CQE compression is enabled, format %d.",
345 dev->data->port_id, priv->config.cqe_comp_fmt);
347 * For vectorized Rx, it must not be doubled in order to
348 * make cq_ci and rq_ci aligned.
350 if (mlx5_rxq_check_vec_support(rxq_data) < 0)
352 } else if (priv->config.cqe_comp && rxq_data->hw_timestamp) {
354 "Port %u Rx CQE compression is disabled for HW"
357 } else if (priv->config.cqe_comp && rxq_data->lro) {
359 "Port %u Rx CQE compression is disabled for LRO.",
362 cq_attr.uar_page_id = mlx5_os_get_devx_uar_page_id(sh->devx_rx_uar);
363 log_cqe_n = log2above(cqe_n);
364 /* Create CQ using DevX API. */
365 ret = mlx5_devx_cq_create(sh->ctx, &rxq_ctrl->obj->cq_obj, log_cqe_n,
366 &cq_attr, sh->numa_node);
369 cq_obj = &rxq_ctrl->obj->cq_obj;
370 rxq_data->cqes = (volatile struct mlx5_cqe (*)[])
371 (uintptr_t)cq_obj->cqes;
372 rxq_data->cq_db = cq_obj->db_rec;
373 rxq_data->cq_uar = mlx5_os_get_devx_uar_base_addr(sh->devx_rx_uar);
374 rxq_data->cqe_n = log_cqe_n;
375 rxq_data->cqn = cq_obj->cq->id;
376 if (rxq_ctrl->obj->devx_channel) {
377 ret = mlx5_os_devx_subscribe_devx_event
378 (rxq_ctrl->obj->devx_channel,
382 (uint64_t)(uintptr_t)cq_obj->cq);
384 DRV_LOG(ERR, "Fail to subscribe CQ to event channel.");
386 mlx5_devx_cq_destroy(cq_obj);
387 memset(cq_obj, 0, sizeof(*cq_obj));
396 * Create the Rx hairpin queue object.
399 * Pointer to Ethernet device.
401 * Queue index in DPDK Rx queue array.
404 * 0 on success, a negative errno value otherwise and rte_errno is set.
407 mlx5_rxq_obj_hairpin_new(struct rte_eth_dev *dev, uint16_t idx)
409 struct mlx5_priv *priv = dev->data->dev_private;
410 struct mlx5_rxq_data *rxq_data = (*priv->rxqs)[idx];
411 struct mlx5_rxq_ctrl *rxq_ctrl =
412 container_of(rxq_data, struct mlx5_rxq_ctrl, rxq);
413 struct mlx5_devx_create_rq_attr attr = { 0 };
414 struct mlx5_rxq_obj *tmpl = rxq_ctrl->obj;
415 uint32_t max_wq_data;
417 MLX5_ASSERT(rxq_data);
419 tmpl->rxq_ctrl = rxq_ctrl;
421 max_wq_data = priv->config.hca_attr.log_max_hairpin_wq_data_sz;
422 /* Jumbo frames > 9KB should be supported, and more packets. */
423 if (priv->config.log_hp_size != (uint32_t)MLX5_ARG_UNSET) {
424 if (priv->config.log_hp_size > max_wq_data) {
425 DRV_LOG(ERR, "Total data size %u power of 2 is "
426 "too large for hairpin.",
427 priv->config.log_hp_size);
431 attr.wq_attr.log_hairpin_data_sz = priv->config.log_hp_size;
433 attr.wq_attr.log_hairpin_data_sz =
434 (max_wq_data < MLX5_HAIRPIN_JUMBO_LOG_SIZE) ?
435 max_wq_data : MLX5_HAIRPIN_JUMBO_LOG_SIZE;
437 /* Set the packets number to the maximum value for performance. */
438 attr.wq_attr.log_hairpin_num_packets =
439 attr.wq_attr.log_hairpin_data_sz -
440 MLX5_HAIRPIN_QUEUE_STRIDE;
441 tmpl->rq = mlx5_devx_cmd_create_rq(priv->sh->ctx, &attr,
445 "Port %u Rx hairpin queue %u can't create rq object.",
446 dev->data->port_id, idx);
450 dev->data->rx_queue_state[idx] = RTE_ETH_QUEUE_STATE_HAIRPIN;
455 * Create the Rx queue DevX object.
458 * Pointer to Ethernet device.
460 * Queue index in DPDK Rx queue array.
463 * 0 on success, a negative errno value otherwise and rte_errno is set.
466 mlx5_rxq_devx_obj_new(struct rte_eth_dev *dev, uint16_t idx)
468 struct mlx5_priv *priv = dev->data->dev_private;
469 struct mlx5_rxq_data *rxq_data = (*priv->rxqs)[idx];
470 struct mlx5_rxq_ctrl *rxq_ctrl =
471 container_of(rxq_data, struct mlx5_rxq_ctrl, rxq);
472 struct mlx5_rxq_obj *tmpl = rxq_ctrl->obj;
475 MLX5_ASSERT(rxq_data);
477 if (rxq_ctrl->type == MLX5_RXQ_TYPE_HAIRPIN)
478 return mlx5_rxq_obj_hairpin_new(dev, idx);
479 tmpl->rxq_ctrl = rxq_ctrl;
482 MLX5DV_DEVX_CREATE_EVENT_CHANNEL_FLAGS_OMIT_EV_DATA;
484 tmpl->devx_channel = mlx5_os_devx_create_event_channel
487 if (!tmpl->devx_channel) {
489 DRV_LOG(ERR, "Failed to create event channel %d.",
493 tmpl->fd = mlx5_os_get_devx_channel_fd(tmpl->devx_channel);
495 /* Create CQ using DevX API. */
496 ret = mlx5_rxq_create_devx_cq_resources(dev, idx);
498 DRV_LOG(ERR, "Failed to create CQ.");
501 /* Create RQ using DevX API. */
502 ret = mlx5_rxq_create_devx_rq_resources(dev, idx);
504 DRV_LOG(ERR, "Port %u Rx queue %u RQ creation failure.",
505 dev->data->port_id, idx);
509 /* Change queue state to ready. */
510 ret = mlx5_devx_modify_rq(tmpl, MLX5_RXQ_MOD_RST2RDY);
513 rxq_data->wqes = (void *)(uintptr_t)tmpl->rq_obj.umem_buf;
514 rxq_data->rq_db = (uint32_t *)(uintptr_t)tmpl->rq_obj.db_rec;
515 rxq_data->cq_arm_sn = 0;
517 mlx5_rxq_initialize(rxq_data);
518 dev->data->rx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STARTED;
519 rxq_ctrl->wqn = tmpl->rq_obj.rq->id;
522 ret = rte_errno; /* Save rte_errno before cleanup. */
523 mlx5_rxq_devx_obj_release(tmpl);
524 rte_errno = ret; /* Restore rte_errno. */
529 * Prepare RQT attribute structure for DevX RQT API.
532 * Pointer to Ethernet device.
534 * Log of number of queues in the array.
536 * DevX indirection table object.
539 * The RQT attr object initialized, NULL otherwise and rte_errno is set.
541 static struct mlx5_devx_rqt_attr *
542 mlx5_devx_ind_table_create_rqt_attr(struct rte_eth_dev *dev,
543 const unsigned int log_n,
544 const uint16_t *queues,
545 const uint32_t queues_n)
547 struct mlx5_priv *priv = dev->data->dev_private;
548 struct mlx5_devx_rqt_attr *rqt_attr = NULL;
549 const unsigned int rqt_n = 1 << log_n;
552 rqt_attr = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*rqt_attr) +
553 rqt_n * sizeof(uint32_t), 0, SOCKET_ID_ANY);
555 DRV_LOG(ERR, "Port %u cannot allocate RQT resources.",
560 rqt_attr->rqt_max_size = priv->config.ind_table_max_size;
561 rqt_attr->rqt_actual_size = rqt_n;
562 for (i = 0; i != queues_n; ++i) {
563 struct mlx5_rxq_data *rxq = (*priv->rxqs)[queues[i]];
564 struct mlx5_rxq_ctrl *rxq_ctrl =
565 container_of(rxq, struct mlx5_rxq_ctrl, rxq);
567 rqt_attr->rq_list[i] = rxq_ctrl->obj->rq_obj.rq->id;
570 for (j = 0; i != rqt_n; ++j, ++i)
571 rqt_attr->rq_list[i] = rqt_attr->rq_list[j];
576 * Create RQT using DevX API as a filed of indirection table.
579 * Pointer to Ethernet device.
581 * Log of number of queues in the array.
583 * DevX indirection table object.
586 * 0 on success, a negative errno value otherwise and rte_errno is set.
589 mlx5_devx_ind_table_new(struct rte_eth_dev *dev, const unsigned int log_n,
590 struct mlx5_ind_table_obj *ind_tbl)
592 struct mlx5_priv *priv = dev->data->dev_private;
593 struct mlx5_devx_rqt_attr *rqt_attr = NULL;
595 MLX5_ASSERT(ind_tbl);
596 rqt_attr = mlx5_devx_ind_table_create_rqt_attr(dev, log_n,
601 ind_tbl->rqt = mlx5_devx_cmd_create_rqt(priv->sh->ctx, rqt_attr);
604 DRV_LOG(ERR, "Port %u cannot create DevX RQT.",
613 * Modify RQT using DevX API as a filed of indirection table.
616 * Pointer to Ethernet device.
618 * Log of number of queues in the array.
620 * DevX indirection table object.
623 * 0 on success, a negative errno value otherwise and rte_errno is set.
626 mlx5_devx_ind_table_modify(struct rte_eth_dev *dev, const unsigned int log_n,
627 const uint16_t *queues, const uint32_t queues_n,
628 struct mlx5_ind_table_obj *ind_tbl)
631 struct mlx5_devx_rqt_attr *rqt_attr = NULL;
633 MLX5_ASSERT(ind_tbl);
634 rqt_attr = mlx5_devx_ind_table_create_rqt_attr(dev, log_n,
639 ret = mlx5_devx_cmd_modify_rqt(ind_tbl->rqt, rqt_attr);
642 DRV_LOG(ERR, "Port %u cannot modify DevX RQT.",
648 * Destroy the DevX RQT object.
651 * Indirection table to release.
654 mlx5_devx_ind_table_destroy(struct mlx5_ind_table_obj *ind_tbl)
656 claim_zero(mlx5_devx_cmd_destroy(ind_tbl->rqt));
660 * Set TIR attribute struct with relevant input values.
663 * Pointer to Ethernet device.
665 * RSS key for the Rx hash queue.
666 * @param[in] hash_fields
667 * Verbs protocol hash field to make the RSS on.
669 * Indirection table for TIR.
672 * @param[out] tir_attr
673 * Parameters structure for TIR creation/modification.
676 * The Verbs/DevX object initialised index, 0 otherwise and rte_errno is set.
679 mlx5_devx_tir_attr_set(struct rte_eth_dev *dev, const uint8_t *rss_key,
680 uint64_t hash_fields,
681 const struct mlx5_ind_table_obj *ind_tbl,
682 int tunnel, struct mlx5_devx_tir_attr *tir_attr)
684 struct mlx5_priv *priv = dev->data->dev_private;
685 struct mlx5_rxq_data *rxq_data = (*priv->rxqs)[ind_tbl->queues[0]];
686 struct mlx5_rxq_ctrl *rxq_ctrl =
687 container_of(rxq_data, struct mlx5_rxq_ctrl, rxq);
688 enum mlx5_rxq_type rxq_obj_type = rxq_ctrl->type;
692 /* Enable TIR LRO only if all the queues were configured for. */
693 for (i = 0; i < ind_tbl->queues_n; ++i) {
694 if (!(*priv->rxqs)[ind_tbl->queues[i]]->lro) {
699 memset(tir_attr, 0, sizeof(*tir_attr));
700 tir_attr->disp_type = MLX5_TIRC_DISP_TYPE_INDIRECT;
701 tir_attr->rx_hash_fn = MLX5_RX_HASH_FN_TOEPLITZ;
702 tir_attr->tunneled_offload_en = !!tunnel;
703 /* If needed, translate hash_fields bitmap to PRM format. */
705 struct mlx5_rx_hash_field_select *rx_hash_field_select =
706 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
707 hash_fields & IBV_RX_HASH_INNER ?
708 &tir_attr->rx_hash_field_selector_inner :
710 &tir_attr->rx_hash_field_selector_outer;
711 /* 1 bit: 0: IPv4, 1: IPv6. */
712 rx_hash_field_select->l3_prot_type =
713 !!(hash_fields & MLX5_IPV6_IBV_RX_HASH);
714 /* 1 bit: 0: TCP, 1: UDP. */
715 rx_hash_field_select->l4_prot_type =
716 !!(hash_fields & MLX5_UDP_IBV_RX_HASH);
717 /* Bitmask which sets which fields to use in RX Hash. */
718 rx_hash_field_select->selected_fields =
719 ((!!(hash_fields & MLX5_L3_SRC_IBV_RX_HASH)) <<
720 MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_SRC_IP) |
721 (!!(hash_fields & MLX5_L3_DST_IBV_RX_HASH)) <<
722 MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_DST_IP |
723 (!!(hash_fields & MLX5_L4_SRC_IBV_RX_HASH)) <<
724 MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_L4_SPORT |
725 (!!(hash_fields & MLX5_L4_DST_IBV_RX_HASH)) <<
726 MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_L4_DPORT;
728 if (rxq_obj_type == MLX5_RXQ_TYPE_HAIRPIN)
729 tir_attr->transport_domain = priv->sh->td->id;
731 tir_attr->transport_domain = priv->sh->tdn;
732 memcpy(tir_attr->rx_hash_toeplitz_key, rss_key, MLX5_RSS_HASH_KEY_LEN);
733 tir_attr->indirect_table = ind_tbl->rqt->id;
734 if (dev->data->dev_conf.lpbk_mode)
735 tir_attr->self_lb_block =
736 MLX5_TIRC_SELF_LB_BLOCK_BLOCK_UNICAST;
738 tir_attr->lro_timeout_period_usecs = priv->config.lro.timeout;
739 tir_attr->lro_max_msg_sz = priv->max_lro_msg_size;
740 tir_attr->lro_enable_mask =
741 MLX5_TIRC_LRO_ENABLE_MASK_IPV4_LRO |
742 MLX5_TIRC_LRO_ENABLE_MASK_IPV6_LRO;
747 * Create an Rx Hash queue.
750 * Pointer to Ethernet device.
752 * Pointer to Rx Hash queue.
757 * 0 on success, a negative errno value otherwise and rte_errno is set.
760 mlx5_devx_hrxq_new(struct rte_eth_dev *dev, struct mlx5_hrxq *hrxq,
761 int tunnel __rte_unused)
763 struct mlx5_priv *priv = dev->data->dev_private;
764 struct mlx5_devx_tir_attr tir_attr = {0};
767 mlx5_devx_tir_attr_set(dev, hrxq->rss_key, hrxq->hash_fields,
768 hrxq->ind_table, tunnel, &tir_attr);
769 hrxq->tir = mlx5_devx_cmd_create_tir(priv->sh->ctx, &tir_attr);
771 DRV_LOG(ERR, "Port %u cannot create DevX TIR.",
776 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H)
777 if (mlx5_flow_os_create_flow_action_dest_devx_tir(hrxq->tir,
785 err = rte_errno; /* Save rte_errno before cleanup. */
787 claim_zero(mlx5_devx_cmd_destroy(hrxq->tir));
788 rte_errno = err; /* Restore rte_errno. */
793 * Destroy a DevX TIR object.
796 * Hash Rx queue to release its tir.
799 mlx5_devx_tir_destroy(struct mlx5_hrxq *hrxq)
801 claim_zero(mlx5_devx_cmd_destroy(hrxq->tir));
805 * Modify an Rx Hash queue configuration.
808 * Pointer to Ethernet device.
810 * Hash Rx queue to modify.
812 * RSS key for the Rx hash queue.
814 * Verbs protocol hash field to make the RSS on.
816 * Indirection table for TIR.
819 * 0 on success, a negative errno value otherwise and rte_errno is set.
822 mlx5_devx_hrxq_modify(struct rte_eth_dev *dev, struct mlx5_hrxq *hrxq,
823 const uint8_t *rss_key,
824 uint64_t hash_fields,
825 const struct mlx5_ind_table_obj *ind_tbl)
827 struct mlx5_devx_modify_tir_attr modify_tir = {0};
830 * untested for modification fields:
831 * - rx_hash_symmetric not set in hrxq_new(),
832 * - rx_hash_fn set hard-coded in hrxq_new(),
833 * - lro_xxx not set after rxq setup
835 if (ind_tbl != hrxq->ind_table)
836 modify_tir.modify_bitmask |=
837 MLX5_MODIFY_TIR_IN_MODIFY_BITMASK_INDIRECT_TABLE;
838 if (hash_fields != hrxq->hash_fields ||
839 memcmp(hrxq->rss_key, rss_key, MLX5_RSS_HASH_KEY_LEN))
840 modify_tir.modify_bitmask |=
841 MLX5_MODIFY_TIR_IN_MODIFY_BITMASK_HASH;
842 mlx5_devx_tir_attr_set(dev, rss_key, hash_fields, ind_tbl,
843 0, /* N/A - tunnel modification unsupported */
845 modify_tir.tirn = hrxq->tir->id;
846 if (mlx5_devx_cmd_modify_tir(hrxq->tir, &modify_tir)) {
847 DRV_LOG(ERR, "port %u cannot modify DevX TIR",
856 * Create a DevX drop action for Rx Hash queue.
859 * Pointer to Ethernet device.
862 * 0 on success, a negative errno value otherwise and rte_errno is set.
865 mlx5_devx_drop_action_create(struct rte_eth_dev *dev)
868 DRV_LOG(ERR, "DevX drop action is not supported yet.");
874 * Release a drop hash Rx queue.
877 * Pointer to Ethernet device.
880 mlx5_devx_drop_action_destroy(struct rte_eth_dev *dev)
883 DRV_LOG(ERR, "DevX drop action is not supported yet.");
888 * Create the Tx hairpin queue object.
891 * Pointer to Ethernet device.
893 * Queue index in DPDK Tx queue array.
896 * 0 on success, a negative errno value otherwise and rte_errno is set.
899 mlx5_txq_obj_hairpin_new(struct rte_eth_dev *dev, uint16_t idx)
901 struct mlx5_priv *priv = dev->data->dev_private;
902 struct mlx5_txq_data *txq_data = (*priv->txqs)[idx];
903 struct mlx5_txq_ctrl *txq_ctrl =
904 container_of(txq_data, struct mlx5_txq_ctrl, txq);
905 struct mlx5_devx_create_sq_attr attr = { 0 };
906 struct mlx5_txq_obj *tmpl = txq_ctrl->obj;
907 uint32_t max_wq_data;
909 MLX5_ASSERT(txq_data);
911 tmpl->txq_ctrl = txq_ctrl;
914 max_wq_data = priv->config.hca_attr.log_max_hairpin_wq_data_sz;
915 /* Jumbo frames > 9KB should be supported, and more packets. */
916 if (priv->config.log_hp_size != (uint32_t)MLX5_ARG_UNSET) {
917 if (priv->config.log_hp_size > max_wq_data) {
918 DRV_LOG(ERR, "Total data size %u power of 2 is "
919 "too large for hairpin.",
920 priv->config.log_hp_size);
924 attr.wq_attr.log_hairpin_data_sz = priv->config.log_hp_size;
926 attr.wq_attr.log_hairpin_data_sz =
927 (max_wq_data < MLX5_HAIRPIN_JUMBO_LOG_SIZE) ?
928 max_wq_data : MLX5_HAIRPIN_JUMBO_LOG_SIZE;
930 /* Set the packets number to the maximum value for performance. */
931 attr.wq_attr.log_hairpin_num_packets =
932 attr.wq_attr.log_hairpin_data_sz -
933 MLX5_HAIRPIN_QUEUE_STRIDE;
934 attr.tis_num = priv->sh->tis->id;
935 tmpl->sq = mlx5_devx_cmd_create_sq(priv->sh->ctx, &attr);
938 "Port %u tx hairpin queue %u can't create SQ object.",
939 dev->data->port_id, idx);
946 #if defined(HAVE_MLX5DV_DEVX_UAR_OFFSET) || !defined(HAVE_INFINIBAND_VERBS_H)
948 * Destroy the Tx queue DevX object.
951 * Txq object to destroy.
954 mlx5_txq_release_devx_resources(struct mlx5_txq_obj *txq_obj)
956 mlx5_devx_sq_destroy(&txq_obj->sq_obj);
957 memset(&txq_obj->sq_obj, 0, sizeof(txq_obj->sq_obj));
958 mlx5_devx_cq_destroy(&txq_obj->cq_obj);
959 memset(&txq_obj->cq_obj, 0, sizeof(txq_obj->cq_obj));
963 * Create a SQ object and its resources using DevX.
966 * Pointer to Ethernet device.
968 * Queue index in DPDK Tx queue array.
969 * @param[in] log_desc_n
970 * Log of number of descriptors in queue.
973 * 0 on success, a negative errno value otherwise and rte_errno is set.
976 mlx5_txq_create_devx_sq_resources(struct rte_eth_dev *dev, uint16_t idx,
979 struct mlx5_priv *priv = dev->data->dev_private;
980 struct mlx5_txq_data *txq_data = (*priv->txqs)[idx];
981 struct mlx5_txq_ctrl *txq_ctrl =
982 container_of(txq_data, struct mlx5_txq_ctrl, txq);
983 struct mlx5_txq_obj *txq_obj = txq_ctrl->obj;
984 struct mlx5_devx_create_sq_attr sq_attr = {
985 .flush_in_error_en = 1,
986 .allow_multi_pkt_send_wqe = !!priv->config.mps,
987 .min_wqe_inline_mode = priv->config.hca_attr.vport_inline_mode,
988 .allow_swp = !!priv->config.swp,
989 .cqn = txq_obj->cq_obj.cq->id,
991 .tis_num = priv->sh->tis->id,
992 .wq_attr = (struct mlx5_devx_wq_attr){
995 mlx5_os_get_devx_uar_page_id(priv->sh->tx_uar),
999 /* Create Send Queue object with DevX. */
1000 return mlx5_devx_sq_create(priv->sh->ctx, &txq_obj->sq_obj, log_desc_n,
1001 &sq_attr, priv->sh->numa_node);
1006 * Create the Tx queue DevX object.
1009 * Pointer to Ethernet device.
1011 * Queue index in DPDK Tx queue array.
1014 * 0 on success, a negative errno value otherwise and rte_errno is set.
1017 mlx5_txq_devx_obj_new(struct rte_eth_dev *dev, uint16_t idx)
1019 struct mlx5_priv *priv = dev->data->dev_private;
1020 struct mlx5_txq_data *txq_data = (*priv->txqs)[idx];
1021 struct mlx5_txq_ctrl *txq_ctrl =
1022 container_of(txq_data, struct mlx5_txq_ctrl, txq);
1024 if (txq_ctrl->type == MLX5_TXQ_TYPE_HAIRPIN)
1025 return mlx5_txq_obj_hairpin_new(dev, idx);
1026 #if !defined(HAVE_MLX5DV_DEVX_UAR_OFFSET) && defined(HAVE_INFINIBAND_VERBS_H)
1027 DRV_LOG(ERR, "Port %u Tx queue %u cannot create with DevX, no UAR.",
1028 dev->data->port_id, idx);
1032 struct mlx5_dev_ctx_shared *sh = priv->sh;
1033 struct mlx5_txq_obj *txq_obj = txq_ctrl->obj;
1034 struct mlx5_devx_cq_attr cq_attr = {
1035 .uar_page_id = mlx5_os_get_devx_uar_page_id(sh->tx_uar),
1038 uint32_t cqe_n, log_desc_n;
1039 uint32_t wqe_n, wqe_size;
1042 MLX5_ASSERT(txq_data);
1043 MLX5_ASSERT(txq_obj);
1044 txq_obj->txq_ctrl = txq_ctrl;
1046 cqe_n = (1UL << txq_data->elts_n) / MLX5_TX_COMP_THRESH +
1047 1 + MLX5_TX_COMP_THRESH_INLINE_DIV;
1048 log_desc_n = log2above(cqe_n);
1049 cqe_n = 1UL << log_desc_n;
1050 if (cqe_n > UINT16_MAX) {
1051 DRV_LOG(ERR, "Port %u Tx queue %u requests to many CQEs %u.",
1052 dev->data->port_id, txq_data->idx, cqe_n);
1056 /* Create completion queue object with DevX. */
1057 ret = mlx5_devx_cq_create(sh->ctx, &txq_obj->cq_obj, log_desc_n,
1058 &cq_attr, priv->sh->numa_node);
1060 DRV_LOG(ERR, "Port %u Tx queue %u CQ creation failure.",
1061 dev->data->port_id, idx);
1064 txq_data->cqe_n = log_desc_n;
1065 txq_data->cqe_s = cqe_n;
1066 txq_data->cqe_m = txq_data->cqe_s - 1;
1067 txq_data->cqes = txq_obj->cq_obj.cqes;
1068 txq_data->cq_ci = 0;
1069 txq_data->cq_pi = 0;
1070 txq_data->cq_db = txq_obj->cq_obj.db_rec;
1071 *txq_data->cq_db = 0;
1073 * Adjust the amount of WQEs depending on inline settings.
1074 * The number of descriptors should be enough to handle
1075 * the specified number of packets. If queue is being created
1076 * with Verbs the rdma-core does queue size adjustment
1077 * internally in the mlx5_calc_sq_size(), we do the same
1078 * for the queue being created with DevX at this point.
1080 wqe_size = txq_data->tso_en ?
1081 RTE_ALIGN(txq_ctrl->max_tso_header, MLX5_WSEG_SIZE) : 0;
1082 wqe_size += sizeof(struct mlx5_wqe_cseg) +
1083 sizeof(struct mlx5_wqe_eseg) +
1084 sizeof(struct mlx5_wqe_dseg);
1085 if (txq_data->inlen_send)
1086 wqe_size = RTE_MAX(wqe_size, sizeof(struct mlx5_wqe_cseg) +
1087 sizeof(struct mlx5_wqe_eseg) +
1088 RTE_ALIGN(txq_data->inlen_send +
1091 wqe_size = RTE_ALIGN(wqe_size, MLX5_WQE_SIZE) / MLX5_WQE_SIZE;
1092 /* Create Send Queue object with DevX. */
1093 wqe_n = RTE_MIN((1UL << txq_data->elts_n) * wqe_size,
1094 (uint32_t)priv->sh->device_attr.max_qp_wr);
1095 log_desc_n = log2above(wqe_n);
1096 ret = mlx5_txq_create_devx_sq_resources(dev, idx, log_desc_n);
1098 DRV_LOG(ERR, "Port %u Tx queue %u SQ creation failure.",
1099 dev->data->port_id, idx);
1103 /* Create the Work Queue. */
1104 txq_data->wqe_n = log_desc_n;
1105 txq_data->wqe_s = 1 << txq_data->wqe_n;
1106 txq_data->wqe_m = txq_data->wqe_s - 1;
1107 txq_data->wqes = (struct mlx5_wqe *)(uintptr_t)txq_obj->sq_obj.wqes;
1108 txq_data->wqes_end = txq_data->wqes + txq_data->wqe_s;
1109 txq_data->wqe_ci = 0;
1110 txq_data->wqe_pi = 0;
1111 txq_data->wqe_comp = 0;
1112 txq_data->wqe_thres = txq_data->wqe_s / MLX5_TX_COMP_THRESH_INLINE_DIV;
1113 txq_data->qp_db = txq_obj->sq_obj.db_rec;
1114 *txq_data->qp_db = 0;
1115 txq_data->qp_num_8s = txq_obj->sq_obj.sq->id << 8;
1116 /* Change Send Queue state to Ready-to-Send. */
1117 ret = mlx5_devx_modify_sq(txq_obj, MLX5_TXQ_MOD_RST2RDY, 0);
1121 "Port %u Tx queue %u SQ state to SQC_STATE_RDY failed.",
1122 dev->data->port_id, idx);
1125 #ifdef HAVE_IBV_FLOW_DV_SUPPORT
1127 * If using DevX need to query and store TIS transport domain value.
1128 * This is done once per port.
1129 * Will use this value on Rx, when creating matching TIR.
1132 priv->sh->tdn = priv->sh->td->id;
1134 MLX5_ASSERT(sh->tx_uar);
1135 reg_addr = mlx5_os_get_devx_uar_reg_addr(sh->tx_uar);
1136 MLX5_ASSERT(reg_addr);
1137 txq_ctrl->bf_reg = reg_addr;
1138 txq_ctrl->uar_mmap_offset =
1139 mlx5_os_get_devx_uar_mmap_offset(sh->tx_uar);
1140 txq_uar_init(txq_ctrl);
1141 dev->data->tx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STARTED;
1144 ret = rte_errno; /* Save rte_errno before cleanup. */
1145 mlx5_txq_release_devx_resources(txq_obj);
1146 rte_errno = ret; /* Restore rte_errno. */
1152 * Release an Tx DevX queue object.
1155 * DevX Tx queue object.
1158 mlx5_txq_devx_obj_release(struct mlx5_txq_obj *txq_obj)
1160 MLX5_ASSERT(txq_obj);
1161 if (txq_obj->txq_ctrl->type == MLX5_TXQ_TYPE_HAIRPIN) {
1163 claim_zero(mlx5_devx_cmd_destroy(txq_obj->tis));
1164 #if defined(HAVE_MLX5DV_DEVX_UAR_OFFSET) || !defined(HAVE_INFINIBAND_VERBS_H)
1166 mlx5_txq_release_devx_resources(txq_obj);
1171 struct mlx5_obj_ops devx_obj_ops = {
1172 .rxq_obj_modify_vlan_strip = mlx5_rxq_obj_modify_rq_vlan_strip,
1173 .rxq_obj_new = mlx5_rxq_devx_obj_new,
1174 .rxq_event_get = mlx5_rx_devx_get_event,
1175 .rxq_obj_modify = mlx5_devx_modify_rq,
1176 .rxq_obj_release = mlx5_rxq_devx_obj_release,
1177 .ind_table_new = mlx5_devx_ind_table_new,
1178 .ind_table_modify = mlx5_devx_ind_table_modify,
1179 .ind_table_destroy = mlx5_devx_ind_table_destroy,
1180 .hrxq_new = mlx5_devx_hrxq_new,
1181 .hrxq_destroy = mlx5_devx_tir_destroy,
1182 .hrxq_modify = mlx5_devx_hrxq_modify,
1183 .drop_action_create = mlx5_devx_drop_action_create,
1184 .drop_action_destroy = mlx5_devx_drop_action_destroy,
1185 .txq_obj_new = mlx5_txq_devx_obj_new,
1186 .txq_obj_modify = mlx5_devx_modify_sq,
1187 .txq_obj_release = mlx5_txq_devx_obj_release,