1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright 2020 Mellanox Technologies, Ltd 3 */ 4 5 #include <stddef.h> 6 #include <errno.h> 7 #include <stdbool.h> 8 #include <string.h> 9 #include <stdint.h> 10 #include <sys/queue.h> 11 12 #include <rte_malloc.h> 13 #include <rte_common.h> 14 #include <rte_eal_paging.h> 15 16 #include <mlx5_glue.h> 17 #include <mlx5_devx_cmds.h> 18 #include <mlx5_common_devx.h> 19 #include <mlx5_malloc.h> 20 21 #include "mlx5.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" 28 29 /** 30 * Modify RQ vlan stripping offload 31 * 32 * @param rxq_obj 33 * Rx queue object. 34 * 35 * @return 36 * 0 on success, non-0 otherwise 37 */ 38 static int 39 mlx5_rxq_obj_modify_rq_vlan_strip(struct mlx5_rxq_obj *rxq_obj, int on) 40 { 41 struct mlx5_devx_modify_rq_attr rq_attr; 42 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); 49 } 50 51 /** 52 * Modify RQ using DevX API. 53 * 54 * @param rxq_obj 55 * DevX Rx queue object. 56 * @param type 57 * Type of change queue state. 58 * 59 * @return 60 * 0 on success, a negative errno value otherwise and rte_errno is set. 61 */ 62 static int 63 mlx5_devx_modify_rq(struct mlx5_rxq_obj *rxq_obj, uint8_t type) 64 { 65 struct mlx5_devx_modify_rq_attr rq_attr; 66 67 memset(&rq_attr, 0, sizeof(rq_attr)); 68 switch (type) { 69 case MLX5_RXQ_MOD_ERR2RST: 70 rq_attr.rq_state = MLX5_RQC_STATE_ERR; 71 rq_attr.state = MLX5_RQC_STATE_RST; 72 break; 73 case MLX5_RXQ_MOD_RST2RDY: 74 rq_attr.rq_state = MLX5_RQC_STATE_RST; 75 rq_attr.state = MLX5_RQC_STATE_RDY; 76 break; 77 case MLX5_RXQ_MOD_RDY2ERR: 78 rq_attr.rq_state = MLX5_RQC_STATE_RDY; 79 rq_attr.state = MLX5_RQC_STATE_ERR; 80 break; 81 case MLX5_RXQ_MOD_RDY2RST: 82 rq_attr.rq_state = MLX5_RQC_STATE_RDY; 83 rq_attr.state = MLX5_RQC_STATE_RST; 84 break; 85 default: 86 break; 87 } 88 return mlx5_devx_cmd_modify_rq(rxq_obj->rq_obj.rq, &rq_attr); 89 } 90 91 /** 92 * Modify SQ using DevX API. 93 * 94 * @param txq_obj 95 * DevX Tx queue object. 96 * @param type 97 * Type of change queue state. 98 * @param dev_port 99 * Unnecessary. 100 * 101 * @return 102 * 0 on success, a negative errno value otherwise and rte_errno is set. 103 */ 104 static int 105 mlx5_devx_modify_sq(struct mlx5_txq_obj *obj, enum mlx5_txq_modify_type type, 106 uint8_t dev_port) 107 { 108 struct mlx5_devx_modify_sq_attr msq_attr = { 0 }; 109 int ret; 110 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; 115 else 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); 119 if (ret) { 120 DRV_LOG(ERR, "Cannot change the Tx SQ state to RESET" 121 " %s", strerror(errno)); 122 rte_errno = errno; 123 return ret; 124 } 125 } 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); 131 if (ret) { 132 DRV_LOG(ERR, "Cannot change the Tx SQ state to READY" 133 " %s", strerror(errno)); 134 rte_errno = errno; 135 return ret; 136 } 137 } 138 /* 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. 142 */ 143 (void)dev_port; 144 return 0; 145 } 146 147 /** 148 * Destroy the Rx queue DevX object. 149 * 150 * @param rxq_obj 151 * Rxq object to destroy. 152 */ 153 static void 154 mlx5_rxq_release_devx_resources(struct mlx5_rxq_obj *rxq_obj) 155 { 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)); 160 } 161 162 /** 163 * Release an Rx DevX queue object. 164 * 165 * @param rxq_obj 166 * DevX Rx queue object. 167 */ 168 static void 169 mlx5_rxq_devx_obj_release(struct mlx5_rxq_obj *rxq_obj) 170 { 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)); 176 } else { 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); 183 } 184 } 185 186 /** 187 * Get event for an Rx DevX queue object. 188 * 189 * @param rxq_obj 190 * DevX Rx queue object. 191 * 192 * @return 193 * 0 on success, a negative errno value otherwise and rte_errno is set. 194 */ 195 static int 196 mlx5_rx_devx_get_event(struct mlx5_rxq_obj *rxq_obj) 197 { 198 #ifdef HAVE_IBV_DEVX_EVENT 199 union { 200 struct mlx5dv_devx_async_event_hdr event_resp; 201 uint8_t buf[sizeof(struct mlx5dv_devx_async_event_hdr) + 128]; 202 } out; 203 int ret = mlx5_glue->devx_get_event(rxq_obj->devx_channel, 204 &out.event_resp, 205 sizeof(out.buf)); 206 207 if (ret < 0) { 208 rte_errno = errno; 209 return -rte_errno; 210 } 211 if (out.event_resp.cookie != (uint64_t)(uintptr_t)rxq_obj->cq_obj.cq) { 212 rte_errno = EINVAL; 213 return -rte_errno; 214 } 215 return 0; 216 #else 217 (void)rxq_obj; 218 rte_errno = ENOTSUP; 219 return -rte_errno; 220 #endif /* HAVE_IBV_DEVX_EVENT */ 221 } 222 223 /** 224 * Create a RQ object using DevX. 225 * 226 * @param dev 227 * Pointer to Ethernet device. 228 * @param idx 229 * Queue index in DPDK Rx queue array. 230 * 231 * @return 232 * 0 on success, a negative errno value otherwise and rte_errno is set. 233 */ 234 static int 235 mlx5_rxq_create_devx_rq_resources(struct rte_eth_dev *dev, uint16_t idx) 236 { 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; 244 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; 254 /* 255 * Number of strides in each WQE: 256 * 512*2^single_wqe_log_num_of_strides. 257 */ 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); 266 } else { 267 rq_attr.wq_attr.wq_type = MLX5_WQ_TYPE_CYCLIC; 268 wqe_size = sizeof(struct mlx5_wqe_data_seg); 269 } 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, 281 rxq_ctrl->socket); 282 } 283 284 /** 285 * Create a DevX CQ object for an Rx queue. 286 * 287 * @param dev 288 * Pointer to Ethernet device. 289 * @param idx 290 * Queue index in DPDK Rx queue array. 291 * 292 * @return 293 * 0 on success, a negative errno value otherwise and rte_errno is set. 294 */ 295 static int 296 mlx5_rxq_create_devx_cq_resources(struct rte_eth_dev *dev, uint16_t idx) 297 { 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); 306 uint32_t log_cqe_n; 307 uint16_t event_nums[1] = { 0 }; 308 int ret = 0; 309 310 if (priv->config.cqe_comp && !rxq_data->hw_timestamp && 311 !rxq_data->lro) { 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: 317 /* fallthrough */ 318 case MLX5_CQE_RESP_FORMAT_CSUM: 319 /* 320 * Select CSUM miniCQE format only for non-vectorized 321 * MPRQ Rx burst, use HASH miniCQE format for others. 322 */ 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; 327 else 328 cq_attr.mini_cqe_res_format = 329 MLX5_CQE_RESP_FORMAT_HASH; 330 rxq_data->mcqe_format = cq_attr.mini_cqe_res_format; 331 break; 332 case MLX5_CQE_RESP_FORMAT_FTAG_STRIDX: 333 rxq_data->byte_mask = MLX5_LEN_WITH_MARK_MASK; 334 /* fallthrough */ 335 case MLX5_CQE_RESP_FORMAT_CSUM_STRIDX: 336 cq_attr.mini_cqe_res_format = priv->config.cqe_comp_fmt; 337 break; 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; 341 break; 342 } 343 DRV_LOG(DEBUG, 344 "Port %u Rx CQE compression is enabled, format %d.", 345 dev->data->port_id, priv->config.cqe_comp_fmt); 346 /* 347 * For vectorized Rx, it must not be doubled in order to 348 * make cq_ci and rq_ci aligned. 349 */ 350 if (mlx5_rxq_check_vec_support(rxq_data) < 0) 351 cqe_n *= 2; 352 } else if (priv->config.cqe_comp && rxq_data->hw_timestamp) { 353 DRV_LOG(DEBUG, 354 "Port %u Rx CQE compression is disabled for HW" 355 " timestamp.", 356 dev->data->port_id); 357 } else if (priv->config.cqe_comp && rxq_data->lro) { 358 DRV_LOG(DEBUG, 359 "Port %u Rx CQE compression is disabled for LRO.", 360 dev->data->port_id); 361 } 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); 367 if (ret) 368 return ret; 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, 379 cq_obj->cq->obj, 380 sizeof(event_nums), 381 event_nums, 382 (uint64_t)(uintptr_t)cq_obj->cq); 383 if (ret) { 384 DRV_LOG(ERR, "Fail to subscribe CQ to event channel."); 385 ret = errno; 386 mlx5_devx_cq_destroy(cq_obj); 387 memset(cq_obj, 0, sizeof(*cq_obj)); 388 rte_errno = ret; 389 return -ret; 390 } 391 } 392 return 0; 393 } 394 395 /** 396 * Create the Rx hairpin queue object. 397 * 398 * @param dev 399 * Pointer to Ethernet device. 400 * @param idx 401 * Queue index in DPDK Rx queue array. 402 * 403 * @return 404 * 0 on success, a negative errno value otherwise and rte_errno is set. 405 */ 406 static int 407 mlx5_rxq_obj_hairpin_new(struct rte_eth_dev *dev, uint16_t idx) 408 { 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; 416 417 MLX5_ASSERT(rxq_data); 418 MLX5_ASSERT(tmpl); 419 tmpl->rxq_ctrl = rxq_ctrl; 420 attr.hairpin = 1; 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); 428 rte_errno = ERANGE; 429 return -rte_errno; 430 } 431 attr.wq_attr.log_hairpin_data_sz = priv->config.log_hp_size; 432 } else { 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; 436 } 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, 442 rxq_ctrl->socket); 443 if (!tmpl->rq) { 444 DRV_LOG(ERR, 445 "Port %u Rx hairpin queue %u can't create rq object.", 446 dev->data->port_id, idx); 447 rte_errno = errno; 448 return -rte_errno; 449 } 450 dev->data->rx_queue_state[idx] = RTE_ETH_QUEUE_STATE_HAIRPIN; 451 return 0; 452 } 453 454 /** 455 * Create the Rx queue DevX object. 456 * 457 * @param dev 458 * Pointer to Ethernet device. 459 * @param idx 460 * Queue index in DPDK Rx queue array. 461 * 462 * @return 463 * 0 on success, a negative errno value otherwise and rte_errno is set. 464 */ 465 static int 466 mlx5_rxq_devx_obj_new(struct rte_eth_dev *dev, uint16_t idx) 467 { 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; 473 int ret = 0; 474 475 MLX5_ASSERT(rxq_data); 476 MLX5_ASSERT(tmpl); 477 if (rxq_ctrl->type == MLX5_RXQ_TYPE_HAIRPIN) 478 return mlx5_rxq_obj_hairpin_new(dev, idx); 479 tmpl->rxq_ctrl = rxq_ctrl; 480 if (rxq_ctrl->irq) { 481 int devx_ev_flag = 482 MLX5DV_DEVX_CREATE_EVENT_CHANNEL_FLAGS_OMIT_EV_DATA; 483 484 tmpl->devx_channel = mlx5_os_devx_create_event_channel 485 (priv->sh->ctx, 486 devx_ev_flag); 487 if (!tmpl->devx_channel) { 488 rte_errno = errno; 489 DRV_LOG(ERR, "Failed to create event channel %d.", 490 rte_errno); 491 goto error; 492 } 493 tmpl->fd = mlx5_os_get_devx_channel_fd(tmpl->devx_channel); 494 } 495 /* Create CQ using DevX API. */ 496 ret = mlx5_rxq_create_devx_cq_resources(dev, idx); 497 if (ret) { 498 DRV_LOG(ERR, "Failed to create CQ."); 499 goto error; 500 } 501 /* Create RQ using DevX API. */ 502 ret = mlx5_rxq_create_devx_rq_resources(dev, idx); 503 if (ret) { 504 DRV_LOG(ERR, "Port %u Rx queue %u RQ creation failure.", 505 dev->data->port_id, idx); 506 rte_errno = ENOMEM; 507 goto error; 508 } 509 /* Change queue state to ready. */ 510 ret = mlx5_devx_modify_rq(tmpl, MLX5_RXQ_MOD_RST2RDY); 511 if (ret) 512 goto error; 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; 516 rxq_data->cq_ci = 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; 520 return 0; 521 error: 522 ret = rte_errno; /* Save rte_errno before cleanup. */ 523 mlx5_rxq_devx_obj_release(tmpl); 524 rte_errno = ret; /* Restore rte_errno. */ 525 return -rte_errno; 526 } 527 528 /** 529 * Prepare RQT attribute structure for DevX RQT API. 530 * 531 * @param dev 532 * Pointer to Ethernet device. 533 * @param log_n 534 * Log of number of queues in the array. 535 * @param ind_tbl 536 * DevX indirection table object. 537 * 538 * @return 539 * The RQT attr object initialized, NULL otherwise and rte_errno is set. 540 */ 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) 546 { 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; 550 unsigned int i, j; 551 552 rqt_attr = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*rqt_attr) + 553 rqt_n * sizeof(uint32_t), 0, SOCKET_ID_ANY); 554 if (!rqt_attr) { 555 DRV_LOG(ERR, "Port %u cannot allocate RQT resources.", 556 dev->data->port_id); 557 rte_errno = ENOMEM; 558 return NULL; 559 } 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); 566 567 rqt_attr->rq_list[i] = rxq_ctrl->obj->rq_obj.rq->id; 568 } 569 MLX5_ASSERT(i > 0); 570 for (j = 0; i != rqt_n; ++j, ++i) 571 rqt_attr->rq_list[i] = rqt_attr->rq_list[j]; 572 return rqt_attr; 573 } 574 575 /** 576 * Create RQT using DevX API as a filed of indirection table. 577 * 578 * @param dev 579 * Pointer to Ethernet device. 580 * @param log_n 581 * Log of number of queues in the array. 582 * @param ind_tbl 583 * DevX indirection table object. 584 * 585 * @return 586 * 0 on success, a negative errno value otherwise and rte_errno is set. 587 */ 588 static int 589 mlx5_devx_ind_table_new(struct rte_eth_dev *dev, const unsigned int log_n, 590 struct mlx5_ind_table_obj *ind_tbl) 591 { 592 struct mlx5_priv *priv = dev->data->dev_private; 593 struct mlx5_devx_rqt_attr *rqt_attr = NULL; 594 595 MLX5_ASSERT(ind_tbl); 596 rqt_attr = mlx5_devx_ind_table_create_rqt_attr(dev, log_n, 597 ind_tbl->queues, 598 ind_tbl->queues_n); 599 if (!rqt_attr) 600 return -rte_errno; 601 ind_tbl->rqt = mlx5_devx_cmd_create_rqt(priv->sh->ctx, rqt_attr); 602 mlx5_free(rqt_attr); 603 if (!ind_tbl->rqt) { 604 DRV_LOG(ERR, "Port %u cannot create DevX RQT.", 605 dev->data->port_id); 606 rte_errno = errno; 607 return -rte_errno; 608 } 609 return 0; 610 } 611 612 /** 613 * Modify RQT using DevX API as a filed of indirection table. 614 * 615 * @param dev 616 * Pointer to Ethernet device. 617 * @param log_n 618 * Log of number of queues in the array. 619 * @param ind_tbl 620 * DevX indirection table object. 621 * 622 * @return 623 * 0 on success, a negative errno value otherwise and rte_errno is set. 624 */ 625 static int 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) 629 { 630 int ret = 0; 631 struct mlx5_devx_rqt_attr *rqt_attr = NULL; 632 633 MLX5_ASSERT(ind_tbl); 634 rqt_attr = mlx5_devx_ind_table_create_rqt_attr(dev, log_n, 635 queues, 636 queues_n); 637 if (!rqt_attr) 638 return -rte_errno; 639 ret = mlx5_devx_cmd_modify_rqt(ind_tbl->rqt, rqt_attr); 640 mlx5_free(rqt_attr); 641 if (ret) 642 DRV_LOG(ERR, "Port %u cannot modify DevX RQT.", 643 dev->data->port_id); 644 return ret; 645 } 646 647 /** 648 * Destroy the DevX RQT object. 649 * 650 * @param ind_table 651 * Indirection table to release. 652 */ 653 static void 654 mlx5_devx_ind_table_destroy(struct mlx5_ind_table_obj *ind_tbl) 655 { 656 claim_zero(mlx5_devx_cmd_destroy(ind_tbl->rqt)); 657 } 658 659 /** 660 * Set TIR attribute struct with relevant input values. 661 * 662 * @param[in] dev 663 * Pointer to Ethernet device. 664 * @param[in] rss_key 665 * RSS key for the Rx hash queue. 666 * @param[in] hash_fields 667 * Verbs protocol hash field to make the RSS on. 668 * @param[in] ind_tbl 669 * Indirection table for TIR. 670 * @param[in] tunnel 671 * Tunnel type. 672 * @param[out] tir_attr 673 * Parameters structure for TIR creation/modification. 674 * 675 * @return 676 * The Verbs/DevX object initialised index, 0 otherwise and rte_errno is set. 677 */ 678 static void 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) 683 { 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; 689 bool lro = true; 690 uint32_t i; 691 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) { 695 lro = false; 696 break; 697 } 698 } 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. */ 704 if (hash_fields) { 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 : 709 #endif 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; 727 } 728 if (rxq_obj_type == MLX5_RXQ_TYPE_HAIRPIN) 729 tir_attr->transport_domain = priv->sh->td->id; 730 else 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; 737 if (lro) { 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; 743 } 744 } 745 746 /** 747 * Create an Rx Hash queue. 748 * 749 * @param dev 750 * Pointer to Ethernet device. 751 * @param hrxq 752 * Pointer to Rx Hash queue. 753 * @param tunnel 754 * Tunnel type. 755 * 756 * @return 757 * 0 on success, a negative errno value otherwise and rte_errno is set. 758 */ 759 static int 760 mlx5_devx_hrxq_new(struct rte_eth_dev *dev, struct mlx5_hrxq *hrxq, 761 int tunnel __rte_unused) 762 { 763 struct mlx5_priv *priv = dev->data->dev_private; 764 struct mlx5_devx_tir_attr tir_attr = {0}; 765 int err; 766 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); 770 if (!hrxq->tir) { 771 DRV_LOG(ERR, "Port %u cannot create DevX TIR.", 772 dev->data->port_id); 773 rte_errno = errno; 774 goto error; 775 } 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, 778 &hrxq->action)) { 779 rte_errno = errno; 780 goto error; 781 } 782 #endif 783 return 0; 784 error: 785 err = rte_errno; /* Save rte_errno before cleanup. */ 786 if (hrxq->tir) 787 claim_zero(mlx5_devx_cmd_destroy(hrxq->tir)); 788 rte_errno = err; /* Restore rte_errno. */ 789 return -rte_errno; 790 } 791 792 /** 793 * Destroy a DevX TIR object. 794 * 795 * @param hrxq 796 * Hash Rx queue to release its tir. 797 */ 798 static void 799 mlx5_devx_tir_destroy(struct mlx5_hrxq *hrxq) 800 { 801 claim_zero(mlx5_devx_cmd_destroy(hrxq->tir)); 802 } 803 804 /** 805 * Modify an Rx Hash queue configuration. 806 * 807 * @param dev 808 * Pointer to Ethernet device. 809 * @param hrxq 810 * Hash Rx queue to modify. 811 * @param rss_key 812 * RSS key for the Rx hash queue. 813 * @param hash_fields 814 * Verbs protocol hash field to make the RSS on. 815 * @param[in] ind_tbl 816 * Indirection table for TIR. 817 * 818 * @return 819 * 0 on success, a negative errno value otherwise and rte_errno is set. 820 */ 821 static int 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) 826 { 827 struct mlx5_devx_modify_tir_attr modify_tir = {0}; 828 829 /* 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 834 */ 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 */ 844 &modify_tir.tir); 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", 848 dev->data->port_id); 849 rte_errno = errno; 850 return -rte_errno; 851 } 852 return 0; 853 } 854 855 /** 856 * Create a DevX drop action for Rx Hash queue. 857 * 858 * @param dev 859 * Pointer to Ethernet device. 860 * 861 * @return 862 * 0 on success, a negative errno value otherwise and rte_errno is set. 863 */ 864 static int 865 mlx5_devx_drop_action_create(struct rte_eth_dev *dev) 866 { 867 (void)dev; 868 DRV_LOG(ERR, "DevX drop action is not supported yet."); 869 rte_errno = ENOTSUP; 870 return -rte_errno; 871 } 872 873 /** 874 * Release a drop hash Rx queue. 875 * 876 * @param dev 877 * Pointer to Ethernet device. 878 */ 879 static void 880 mlx5_devx_drop_action_destroy(struct rte_eth_dev *dev) 881 { 882 (void)dev; 883 DRV_LOG(ERR, "DevX drop action is not supported yet."); 884 rte_errno = ENOTSUP; 885 } 886 887 /** 888 * Create the Tx hairpin queue object. 889 * 890 * @param dev 891 * Pointer to Ethernet device. 892 * @param idx 893 * Queue index in DPDK Tx queue array. 894 * 895 * @return 896 * 0 on success, a negative errno value otherwise and rte_errno is set. 897 */ 898 static int 899 mlx5_txq_obj_hairpin_new(struct rte_eth_dev *dev, uint16_t idx) 900 { 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; 908 909 MLX5_ASSERT(txq_data); 910 MLX5_ASSERT(tmpl); 911 tmpl->txq_ctrl = txq_ctrl; 912 attr.hairpin = 1; 913 attr.tis_lst_sz = 1; 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); 921 rte_errno = ERANGE; 922 return -rte_errno; 923 } 924 attr.wq_attr.log_hairpin_data_sz = priv->config.log_hp_size; 925 } else { 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; 929 } 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); 936 if (!tmpl->sq) { 937 DRV_LOG(ERR, 938 "Port %u tx hairpin queue %u can't create SQ object.", 939 dev->data->port_id, idx); 940 rte_errno = errno; 941 return -rte_errno; 942 } 943 return 0; 944 } 945 946 #if defined(HAVE_MLX5DV_DEVX_UAR_OFFSET) || !defined(HAVE_INFINIBAND_VERBS_H) 947 /** 948 * Destroy the Tx queue DevX object. 949 * 950 * @param txq_obj 951 * Txq object to destroy. 952 */ 953 static void 954 mlx5_txq_release_devx_resources(struct mlx5_txq_obj *txq_obj) 955 { 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)); 960 } 961 962 /** 963 * Create a SQ object and its resources using DevX. 964 * 965 * @param dev 966 * Pointer to Ethernet device. 967 * @param idx 968 * Queue index in DPDK Tx queue array. 969 * @param[in] log_desc_n 970 * Log of number of descriptors in queue. 971 * 972 * @return 973 * 0 on success, a negative errno value otherwise and rte_errno is set. 974 */ 975 static int 976 mlx5_txq_create_devx_sq_resources(struct rte_eth_dev *dev, uint16_t idx, 977 uint16_t log_desc_n) 978 { 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, 990 .tis_lst_sz = 1, 991 .tis_num = priv->sh->tis->id, 992 .wq_attr = (struct mlx5_devx_wq_attr){ 993 .pd = priv->sh->pdn, 994 .uar_page = 995 mlx5_os_get_devx_uar_page_id(priv->sh->tx_uar), 996 }, 997 }; 998 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); 1002 } 1003 #endif 1004 1005 /** 1006 * Create the Tx queue DevX object. 1007 * 1008 * @param dev 1009 * Pointer to Ethernet device. 1010 * @param idx 1011 * Queue index in DPDK Tx queue array. 1012 * 1013 * @return 1014 * 0 on success, a negative errno value otherwise and rte_errno is set. 1015 */ 1016 int 1017 mlx5_txq_devx_obj_new(struct rte_eth_dev *dev, uint16_t idx) 1018 { 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); 1023 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); 1029 rte_errno = ENOMEM; 1030 return -rte_errno; 1031 #else 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), 1036 }; 1037 void *reg_addr; 1038 uint32_t cqe_n, log_desc_n; 1039 uint32_t wqe_n; 1040 int ret = 0; 1041 1042 MLX5_ASSERT(txq_data); 1043 MLX5_ASSERT(txq_obj); 1044 txq_obj->txq_ctrl = txq_ctrl; 1045 txq_obj->dev = dev; 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); 1053 rte_errno = EINVAL; 1054 return 0; 1055 } 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); 1059 if (ret) { 1060 DRV_LOG(ERR, "Port %u Tx queue %u CQ creation failure.", 1061 dev->data->port_id, idx); 1062 goto error; 1063 } 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; 1072 /* Create Send Queue object with DevX. */ 1073 wqe_n = RTE_MIN(1UL << txq_data->elts_n, 1074 (uint32_t)priv->sh->device_attr.max_qp_wr); 1075 log_desc_n = log2above(wqe_n); 1076 ret = mlx5_txq_create_devx_sq_resources(dev, idx, log_desc_n); 1077 if (ret) { 1078 DRV_LOG(ERR, "Port %u Tx queue %u SQ creation failure.", 1079 dev->data->port_id, idx); 1080 rte_errno = errno; 1081 goto error; 1082 } 1083 /* Create the Work Queue. */ 1084 txq_data->wqe_n = log_desc_n; 1085 txq_data->wqe_s = 1 << txq_data->wqe_n; 1086 txq_data->wqe_m = txq_data->wqe_s - 1; 1087 txq_data->wqes = (struct mlx5_wqe *)(uintptr_t)txq_obj->sq_obj.wqes; 1088 txq_data->wqes_end = txq_data->wqes + txq_data->wqe_s; 1089 txq_data->wqe_ci = 0; 1090 txq_data->wqe_pi = 0; 1091 txq_data->wqe_comp = 0; 1092 txq_data->wqe_thres = txq_data->wqe_s / MLX5_TX_COMP_THRESH_INLINE_DIV; 1093 txq_data->qp_db = txq_obj->sq_obj.db_rec; 1094 *txq_data->qp_db = 0; 1095 txq_data->qp_num_8s = txq_obj->sq_obj.sq->id << 8; 1096 /* Change Send Queue state to Ready-to-Send. */ 1097 ret = mlx5_devx_modify_sq(txq_obj, MLX5_TXQ_MOD_RST2RDY, 0); 1098 if (ret) { 1099 rte_errno = errno; 1100 DRV_LOG(ERR, 1101 "Port %u Tx queue %u SQ state to SQC_STATE_RDY failed.", 1102 dev->data->port_id, idx); 1103 goto error; 1104 } 1105 #ifdef HAVE_IBV_FLOW_DV_SUPPORT 1106 /* 1107 * If using DevX need to query and store TIS transport domain value. 1108 * This is done once per port. 1109 * Will use this value on Rx, when creating matching TIR. 1110 */ 1111 if (!priv->sh->tdn) 1112 priv->sh->tdn = priv->sh->td->id; 1113 #endif 1114 MLX5_ASSERT(sh->tx_uar); 1115 reg_addr = mlx5_os_get_devx_uar_reg_addr(sh->tx_uar); 1116 MLX5_ASSERT(reg_addr); 1117 txq_ctrl->bf_reg = reg_addr; 1118 txq_ctrl->uar_mmap_offset = 1119 mlx5_os_get_devx_uar_mmap_offset(sh->tx_uar); 1120 txq_uar_init(txq_ctrl); 1121 dev->data->tx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STARTED; 1122 return 0; 1123 error: 1124 ret = rte_errno; /* Save rte_errno before cleanup. */ 1125 mlx5_txq_release_devx_resources(txq_obj); 1126 rte_errno = ret; /* Restore rte_errno. */ 1127 return -rte_errno; 1128 #endif 1129 } 1130 1131 /** 1132 * Release an Tx DevX queue object. 1133 * 1134 * @param txq_obj 1135 * DevX Tx queue object. 1136 */ 1137 void 1138 mlx5_txq_devx_obj_release(struct mlx5_txq_obj *txq_obj) 1139 { 1140 MLX5_ASSERT(txq_obj); 1141 if (txq_obj->txq_ctrl->type == MLX5_TXQ_TYPE_HAIRPIN) { 1142 if (txq_obj->tis) 1143 claim_zero(mlx5_devx_cmd_destroy(txq_obj->tis)); 1144 #if defined(HAVE_MLX5DV_DEVX_UAR_OFFSET) || !defined(HAVE_INFINIBAND_VERBS_H) 1145 } else { 1146 mlx5_txq_release_devx_resources(txq_obj); 1147 #endif 1148 } 1149 } 1150 1151 struct mlx5_obj_ops devx_obj_ops = { 1152 .rxq_obj_modify_vlan_strip = mlx5_rxq_obj_modify_rq_vlan_strip, 1153 .rxq_obj_new = mlx5_rxq_devx_obj_new, 1154 .rxq_event_get = mlx5_rx_devx_get_event, 1155 .rxq_obj_modify = mlx5_devx_modify_rq, 1156 .rxq_obj_release = mlx5_rxq_devx_obj_release, 1157 .ind_table_new = mlx5_devx_ind_table_new, 1158 .ind_table_modify = mlx5_devx_ind_table_modify, 1159 .ind_table_destroy = mlx5_devx_ind_table_destroy, 1160 .hrxq_new = mlx5_devx_hrxq_new, 1161 .hrxq_destroy = mlx5_devx_tir_destroy, 1162 .hrxq_modify = mlx5_devx_hrxq_modify, 1163 .drop_action_create = mlx5_devx_drop_action_create, 1164 .drop_action_destroy = mlx5_devx_drop_action_destroy, 1165 .txq_obj_new = mlx5_txq_devx_obj_new, 1166 .txq_obj_modify = mlx5_devx_modify_sq, 1167 .txq_obj_release = mlx5_txq_devx_obj_release, 1168 }; 1169