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_tx.h" 24 #include "mlx5_rx.h" 25 #include "mlx5_utils.h" 26 #include "mlx5_devx.h" 27 #include "mlx5_flow.h" 28 #include "mlx5_flow_os.h" 29 30 /** 31 * Modify RQ vlan stripping offload 32 * 33 * @param rxq 34 * Rx queue. 35 * @param on 36 * Enable/disable VLAN stripping. 37 * 38 * @return 39 * 0 on success, non-0 otherwise 40 */ 41 static int 42 mlx5_rxq_obj_modify_rq_vlan_strip(struct mlx5_rxq_priv *rxq, int on) 43 { 44 struct mlx5_devx_modify_rq_attr rq_attr; 45 46 memset(&rq_attr, 0, sizeof(rq_attr)); 47 rq_attr.rq_state = MLX5_RQC_STATE_RDY; 48 rq_attr.state = MLX5_RQC_STATE_RDY; 49 rq_attr.vsd = (on ? 0 : 1); 50 rq_attr.modify_bitmask = MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_VSD; 51 return mlx5_devx_cmd_modify_rq(rxq->devx_rq.rq, &rq_attr); 52 } 53 54 /** 55 * Modify RQ using DevX API. 56 * 57 * @param rxq 58 * DevX rx queue. 59 * @param type 60 * Type of change queue state. 61 * 62 * @return 63 * 0 on success, a negative errno value otherwise and rte_errno is set. 64 */ 65 int 66 mlx5_devx_modify_rq(struct mlx5_rxq_priv *rxq, uint8_t type) 67 { 68 struct mlx5_devx_modify_rq_attr rq_attr; 69 70 memset(&rq_attr, 0, sizeof(rq_attr)); 71 switch (type) { 72 case MLX5_RXQ_MOD_ERR2RST: 73 rq_attr.rq_state = MLX5_RQC_STATE_ERR; 74 rq_attr.state = MLX5_RQC_STATE_RST; 75 break; 76 case MLX5_RXQ_MOD_RST2RDY: 77 rq_attr.rq_state = MLX5_RQC_STATE_RST; 78 rq_attr.state = MLX5_RQC_STATE_RDY; 79 if (rxq->lwm) { 80 rq_attr.modify_bitmask |= 81 MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_WQ_LWM; 82 rq_attr.lwm = rxq->lwm; 83 } 84 break; 85 case MLX5_RXQ_MOD_RDY2ERR: 86 rq_attr.rq_state = MLX5_RQC_STATE_RDY; 87 rq_attr.state = MLX5_RQC_STATE_ERR; 88 break; 89 case MLX5_RXQ_MOD_RDY2RST: 90 rq_attr.rq_state = MLX5_RQC_STATE_RDY; 91 rq_attr.state = MLX5_RQC_STATE_RST; 92 break; 93 case MLX5_RXQ_MOD_RDY2RDY: 94 rq_attr.rq_state = MLX5_RQC_STATE_RDY; 95 rq_attr.state = MLX5_RQC_STATE_RDY; 96 rq_attr.modify_bitmask |= MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_WQ_LWM; 97 rq_attr.lwm = rxq->lwm; 98 break; 99 default: 100 break; 101 } 102 if (rxq->ctrl->is_hairpin) 103 return mlx5_devx_cmd_modify_rq(rxq->ctrl->obj->rq, &rq_attr); 104 return mlx5_devx_cmd_modify_rq(rxq->devx_rq.rq, &rq_attr); 105 } 106 107 /** 108 * Modify SQ using DevX API. 109 * 110 * @param txq_obj 111 * DevX Tx queue object. 112 * @param type 113 * Type of change queue state. 114 * @param dev_port 115 * Unnecessary. 116 * 117 * @return 118 * 0 on success, a negative errno value otherwise and rte_errno is set. 119 */ 120 int 121 mlx5_txq_devx_modify(struct mlx5_txq_obj *obj, enum mlx5_txq_modify_type type, 122 uint8_t dev_port) 123 { 124 struct mlx5_devx_modify_sq_attr msq_attr = { 0 }; 125 int ret; 126 127 if (type != MLX5_TXQ_MOD_RST2RDY) { 128 /* Change queue state to reset. */ 129 if (type == MLX5_TXQ_MOD_ERR2RDY) 130 msq_attr.sq_state = MLX5_SQC_STATE_ERR; 131 else 132 msq_attr.sq_state = MLX5_SQC_STATE_RDY; 133 msq_attr.state = MLX5_SQC_STATE_RST; 134 ret = mlx5_devx_cmd_modify_sq(obj->sq_obj.sq, &msq_attr); 135 if (ret) { 136 DRV_LOG(ERR, "Cannot change the Tx SQ state to RESET" 137 " %s", strerror(errno)); 138 rte_errno = errno; 139 return ret; 140 } 141 } 142 if (type != MLX5_TXQ_MOD_RDY2RST) { 143 /* Change queue state to ready. */ 144 msq_attr.sq_state = MLX5_SQC_STATE_RST; 145 msq_attr.state = MLX5_SQC_STATE_RDY; 146 ret = mlx5_devx_cmd_modify_sq(obj->sq_obj.sq, &msq_attr); 147 if (ret) { 148 DRV_LOG(ERR, "Cannot change the Tx SQ state to READY" 149 " %s", strerror(errno)); 150 rte_errno = errno; 151 return ret; 152 } 153 } 154 /* 155 * The dev_port variable is relevant only in Verbs API, and there is a 156 * pointer that points to this function and a parallel function in verbs 157 * intermittently, so they should have the same parameters. 158 */ 159 (void)dev_port; 160 return 0; 161 } 162 163 /** 164 * Release an Rx DevX queue object. 165 * 166 * @param rxq 167 * DevX Rx queue. 168 */ 169 static void 170 mlx5_rxq_devx_obj_release(struct mlx5_rxq_priv *rxq) 171 { 172 struct mlx5_rxq_obj *rxq_obj = rxq->ctrl->obj; 173 174 if (rxq_obj == NULL) 175 return; 176 if (rxq_obj->rxq_ctrl->is_hairpin) { 177 if (rxq_obj->rq == NULL) 178 return; 179 mlx5_devx_modify_rq(rxq, MLX5_RXQ_MOD_RDY2RST); 180 claim_zero(mlx5_devx_cmd_destroy(rxq_obj->rq)); 181 } else { 182 if (rxq->devx_rq.rq == NULL) 183 return; 184 mlx5_devx_rq_destroy(&rxq->devx_rq); 185 if (rxq->devx_rq.rmp != NULL && rxq->devx_rq.rmp->ref_cnt > 0) 186 return; 187 mlx5_devx_cq_destroy(&rxq_obj->cq_obj); 188 memset(&rxq_obj->cq_obj, 0, sizeof(rxq_obj->cq_obj)); 189 if (rxq_obj->devx_channel) { 190 mlx5_os_devx_destroy_event_channel 191 (rxq_obj->devx_channel); 192 rxq_obj->devx_channel = NULL; 193 } 194 } 195 rxq->ctrl->started = false; 196 } 197 198 /** 199 * Get event for an Rx DevX queue object. 200 * 201 * @param rxq_obj 202 * DevX Rx queue object. 203 * 204 * @return 205 * 0 on success, a negative errno value otherwise and rte_errno is set. 206 */ 207 static int 208 mlx5_rx_devx_get_event(struct mlx5_rxq_obj *rxq_obj) 209 { 210 #ifdef HAVE_IBV_DEVX_EVENT 211 union { 212 struct mlx5dv_devx_async_event_hdr event_resp; 213 uint8_t buf[sizeof(struct mlx5dv_devx_async_event_hdr) + 128]; 214 } out; 215 int ret = mlx5_glue->devx_get_event(rxq_obj->devx_channel, 216 &out.event_resp, 217 sizeof(out.buf)); 218 219 if (ret < 0) { 220 rte_errno = errno; 221 return -rte_errno; 222 } 223 if (out.event_resp.cookie != (uint64_t)(uintptr_t)rxq_obj->cq_obj.cq) { 224 rte_errno = EINVAL; 225 return -rte_errno; 226 } 227 return 0; 228 #else 229 (void)rxq_obj; 230 rte_errno = ENOTSUP; 231 return -rte_errno; 232 #endif /* HAVE_IBV_DEVX_EVENT */ 233 } 234 235 /** 236 * Get LWM event for shared context, return the correct port/rxq for this event. 237 * 238 * @param priv 239 * Mlx5_priv object. 240 * @param rxq_idx [out] 241 * Which rxq gets this event. 242 * @param port_id [out] 243 * Which port gets this event. 244 * 245 * @return 246 * 0 on success, a negative errno value otherwise and rte_errno is set. 247 */ 248 static int 249 mlx5_rx_devx_get_event_lwm(struct mlx5_priv *priv, int *rxq_idx, int *port_id) 250 { 251 #ifdef HAVE_IBV_DEVX_EVENT 252 union { 253 struct mlx5dv_devx_async_event_hdr event_resp; 254 uint8_t buf[sizeof(struct mlx5dv_devx_async_event_hdr) + 128]; 255 } out; 256 int ret; 257 258 memset(&out, 0, sizeof(out)); 259 ret = mlx5_glue->devx_get_event(priv->sh->devx_channel_lwm, 260 &out.event_resp, 261 sizeof(out.buf)); 262 if (ret < 0) { 263 rte_errno = errno; 264 DRV_LOG(WARNING, "%s err\n", __func__); 265 return -rte_errno; 266 } 267 *port_id = (((uint32_t)out.event_resp.cookie) >> 268 LWM_COOKIE_PORTID_OFFSET) & LWM_COOKIE_PORTID_MASK; 269 *rxq_idx = (((uint32_t)out.event_resp.cookie) >> 270 LWM_COOKIE_RXQID_OFFSET) & LWM_COOKIE_RXQID_MASK; 271 return 0; 272 #else 273 (void)priv; 274 (void)rxq_idx; 275 (void)port_id; 276 rte_errno = ENOTSUP; 277 return -rte_errno; 278 #endif /* HAVE_IBV_DEVX_EVENT */ 279 } 280 281 /** 282 * Create a RQ object using DevX. 283 * 284 * @param rxq 285 * Pointer to Rx queue. 286 * 287 * @return 288 * 0 on success, a negative errno value otherwise and rte_errno is set. 289 */ 290 static int 291 mlx5_rxq_create_devx_rq_resources(struct mlx5_rxq_priv *rxq) 292 { 293 struct mlx5_priv *priv = rxq->priv; 294 struct mlx5_common_device *cdev = priv->sh->cdev; 295 struct mlx5_rxq_ctrl *rxq_ctrl = rxq->ctrl; 296 struct mlx5_rxq_data *rxq_data = &rxq->ctrl->rxq; 297 struct mlx5_devx_create_rq_attr rq_attr = { 0 }; 298 uint16_t log_desc_n = rxq_data->elts_n - rxq_data->sges_n; 299 uint32_t wqe_size, log_wqe_size; 300 301 /* Fill RQ attributes. */ 302 rq_attr.mem_rq_type = MLX5_RQC_MEM_RQ_TYPE_MEMORY_RQ_INLINE; 303 rq_attr.flush_in_error_en = 1; 304 rq_attr.vsd = (rxq_data->vlan_strip) ? 0 : 1; 305 rq_attr.cqn = rxq_ctrl->obj->cq_obj.cq->id; 306 rq_attr.scatter_fcs = (rxq_data->crc_present) ? 1 : 0; 307 rq_attr.ts_format = 308 mlx5_ts_format_conv(cdev->config.hca_attr.rq_ts_format); 309 /* Fill WQ attributes for this RQ. */ 310 if (mlx5_rxq_mprq_enabled(rxq_data)) { 311 rq_attr.wq_attr.wq_type = MLX5_WQ_TYPE_CYCLIC_STRIDING_RQ; 312 /* 313 * Number of strides in each WQE: 314 * 512*2^single_wqe_log_num_of_strides. 315 */ 316 rq_attr.wq_attr.single_wqe_log_num_of_strides = 317 rxq_data->log_strd_num - 318 MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES; 319 /* Stride size = (2^single_stride_log_num_of_bytes)*64B. */ 320 rq_attr.wq_attr.single_stride_log_num_of_bytes = 321 rxq_data->log_strd_sz - 322 MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES; 323 wqe_size = sizeof(struct mlx5_wqe_mprq); 324 } else { 325 rq_attr.wq_attr.wq_type = MLX5_WQ_TYPE_CYCLIC; 326 wqe_size = sizeof(struct mlx5_wqe_data_seg); 327 } 328 log_wqe_size = log2above(wqe_size) + rxq_data->sges_n; 329 wqe_size = 1 << log_wqe_size; /* round up power of two.*/ 330 rq_attr.wq_attr.log_wq_stride = log_wqe_size; 331 rq_attr.wq_attr.log_wq_sz = log_desc_n; 332 rq_attr.wq_attr.end_padding_mode = priv->config.hw_padding ? 333 MLX5_WQ_END_PAD_MODE_ALIGN : 334 MLX5_WQ_END_PAD_MODE_NONE; 335 rq_attr.wq_attr.pd = cdev->pdn; 336 rq_attr.counter_set_id = priv->counter_set_id; 337 rq_attr.delay_drop_en = rxq_data->delay_drop; 338 rq_attr.user_index = rte_cpu_to_be_16(priv->dev_data->port_id); 339 if (rxq_data->shared) /* Create RMP based RQ. */ 340 rxq->devx_rq.rmp = &rxq_ctrl->obj->devx_rmp; 341 /* Create RQ using DevX API. */ 342 return mlx5_devx_rq_create(cdev->ctx, &rxq->devx_rq, wqe_size, 343 log_desc_n, &rq_attr, rxq_ctrl->socket); 344 } 345 346 /** 347 * Create a DevX CQ object for an Rx queue. 348 * 349 * @param rxq 350 * Pointer to Rx queue. 351 * 352 * @return 353 * 0 on success, a negative errno value otherwise and rte_errno is set. 354 */ 355 static int 356 mlx5_rxq_create_devx_cq_resources(struct mlx5_rxq_priv *rxq) 357 { 358 struct mlx5_devx_cq *cq_obj = 0; 359 struct mlx5_devx_cq_attr cq_attr = { 0 }; 360 struct mlx5_priv *priv = rxq->priv; 361 struct mlx5_dev_ctx_shared *sh = priv->sh; 362 uint16_t port_id = priv->dev_data->port_id; 363 struct mlx5_rxq_ctrl *rxq_ctrl = rxq->ctrl; 364 struct mlx5_rxq_data *rxq_data = &rxq_ctrl->rxq; 365 unsigned int cqe_n = mlx5_rxq_cqe_num(rxq_data); 366 uint32_t log_cqe_n; 367 uint16_t event_nums[1] = { 0 }; 368 int ret = 0; 369 370 if (rxq_ctrl->started) 371 return 0; 372 if (priv->config.cqe_comp && !rxq_data->hw_timestamp && 373 !rxq_data->lro) { 374 cq_attr.cqe_comp_en = 1u; 375 cq_attr.cqe_comp_layout = priv->config.enh_cqe_comp; 376 rxq_data->cqe_comp_layout = cq_attr.cqe_comp_layout; 377 rxq_data->mcqe_format = priv->config.cqe_comp_fmt; 378 rxq_data->byte_mask = UINT32_MAX; 379 switch (priv->config.cqe_comp_fmt) { 380 case MLX5_CQE_RESP_FORMAT_HASH: 381 /* fallthrough */ 382 case MLX5_CQE_RESP_FORMAT_CSUM: 383 /* 384 * Select CSUM miniCQE format only for non-vectorized 385 * MPRQ Rx burst, use HASH miniCQE format for others. 386 */ 387 if (mlx5_rxq_check_vec_support(rxq_data) < 0 && 388 mlx5_rxq_mprq_enabled(rxq_data)) 389 cq_attr.mini_cqe_res_format = 390 MLX5_CQE_RESP_FORMAT_CSUM_STRIDX; 391 else 392 cq_attr.mini_cqe_res_format = 393 MLX5_CQE_RESP_FORMAT_HASH; 394 rxq_data->mcqe_format = cq_attr.mini_cqe_res_format; 395 break; 396 case MLX5_CQE_RESP_FORMAT_FTAG_STRIDX: 397 rxq_data->byte_mask = MLX5_LEN_WITH_MARK_MASK; 398 /* fallthrough */ 399 case MLX5_CQE_RESP_FORMAT_CSUM_STRIDX: 400 cq_attr.mini_cqe_res_format = priv->config.cqe_comp_fmt; 401 break; 402 case MLX5_CQE_RESP_FORMAT_L34H_STRIDX: 403 cq_attr.mini_cqe_res_format = 0; 404 cq_attr.mini_cqe_res_format_ext = 1; 405 break; 406 } 407 DRV_LOG(DEBUG, 408 "Port %u Rx CQE compression is enabled, format %d.", 409 port_id, priv->config.cqe_comp_fmt); 410 /* 411 * For vectorized Rx, it must not be doubled in order to 412 * make cq_ci and rq_ci aligned. 413 */ 414 if (mlx5_rxq_check_vec_support(rxq_data) < 0) 415 cqe_n *= 2; 416 } else if (priv->config.cqe_comp && rxq_data->hw_timestamp) { 417 DRV_LOG(DEBUG, 418 "Port %u Rx CQE compression is disabled for HW timestamp.", 419 port_id); 420 } else if (priv->config.cqe_comp && rxq_data->lro) { 421 DRV_LOG(DEBUG, 422 "Port %u Rx CQE compression is disabled for LRO.", 423 port_id); 424 } 425 cq_attr.uar_page_id = mlx5_os_get_devx_uar_page_id(sh->rx_uar.obj); 426 log_cqe_n = log2above(cqe_n); 427 /* Create CQ using DevX API. */ 428 ret = mlx5_devx_cq_create(sh->cdev->ctx, &rxq_ctrl->obj->cq_obj, 429 log_cqe_n, &cq_attr, sh->numa_node); 430 if (ret) 431 return ret; 432 cq_obj = &rxq_ctrl->obj->cq_obj; 433 rxq_data->cqes = (volatile struct mlx5_cqe (*)[]) 434 (uintptr_t)cq_obj->cqes; 435 rxq_data->cq_db = cq_obj->db_rec; 436 rxq_data->uar_data = sh->rx_uar.cq_db; 437 rxq_data->cqe_n = log_cqe_n; 438 rxq_data->cqn = cq_obj->cq->id; 439 rxq_data->cq_ci = 0; 440 if (rxq_ctrl->obj->devx_channel) { 441 ret = mlx5_os_devx_subscribe_devx_event 442 (rxq_ctrl->obj->devx_channel, 443 cq_obj->cq->obj, 444 sizeof(event_nums), 445 event_nums, 446 (uint64_t)(uintptr_t)cq_obj->cq); 447 if (ret) { 448 DRV_LOG(ERR, "Fail to subscribe CQ to event channel."); 449 ret = errno; 450 mlx5_devx_cq_destroy(cq_obj); 451 memset(cq_obj, 0, sizeof(*cq_obj)); 452 rte_errno = ret; 453 return -ret; 454 } 455 } 456 return 0; 457 } 458 459 /** 460 * Create the Rx hairpin queue object. 461 * 462 * @param rxq 463 * Pointer to Rx queue. 464 * 465 * @return 466 * 0 on success, a negative errno value otherwise and rte_errno is set. 467 */ 468 static int 469 mlx5_rxq_obj_hairpin_new(struct mlx5_rxq_priv *rxq) 470 { 471 uint16_t idx = rxq->idx; 472 struct mlx5_priv *priv = rxq->priv; 473 struct mlx5_hca_attr *hca_attr __rte_unused = &priv->sh->cdev->config.hca_attr; 474 struct mlx5_rxq_ctrl *rxq_ctrl = rxq->ctrl; 475 struct mlx5_devx_create_rq_attr unlocked_attr = { 0 }; 476 struct mlx5_devx_create_rq_attr locked_attr = { 0 }; 477 struct mlx5_rxq_obj *tmpl = rxq_ctrl->obj; 478 uint32_t max_wq_data; 479 480 MLX5_ASSERT(rxq != NULL && rxq->ctrl != NULL && tmpl != NULL); 481 tmpl->rxq_ctrl = rxq_ctrl; 482 unlocked_attr.hairpin = 1; 483 max_wq_data = 484 priv->sh->cdev->config.hca_attr.log_max_hairpin_wq_data_sz; 485 /* Jumbo frames > 9KB should be supported, and more packets. */ 486 if (priv->config.log_hp_size != (uint32_t)MLX5_ARG_UNSET) { 487 if (priv->config.log_hp_size > max_wq_data) { 488 DRV_LOG(ERR, "Total data size %u power of 2 is " 489 "too large for hairpin.", 490 priv->config.log_hp_size); 491 rte_errno = ERANGE; 492 return -rte_errno; 493 } 494 unlocked_attr.wq_attr.log_hairpin_data_sz = priv->config.log_hp_size; 495 } else { 496 unlocked_attr.wq_attr.log_hairpin_data_sz = 497 (max_wq_data < MLX5_HAIRPIN_JUMBO_LOG_SIZE) ? 498 max_wq_data : MLX5_HAIRPIN_JUMBO_LOG_SIZE; 499 } 500 /* Set the packets number to the maximum value for performance. */ 501 unlocked_attr.wq_attr.log_hairpin_num_packets = 502 unlocked_attr.wq_attr.log_hairpin_data_sz - 503 MLX5_HAIRPIN_QUEUE_STRIDE; 504 unlocked_attr.counter_set_id = priv->counter_set_id; 505 rxq_ctrl->rxq.delay_drop = priv->config.hp_delay_drop; 506 unlocked_attr.delay_drop_en = priv->config.hp_delay_drop; 507 unlocked_attr.hairpin_data_buffer_type = 508 MLX5_RQC_HAIRPIN_DATA_BUFFER_TYPE_UNLOCKED_INTERNAL_BUFFER; 509 if (rxq->hairpin_conf.use_locked_device_memory) { 510 /* 511 * It is assumed that configuration is verified against capabilities 512 * during queue setup. 513 */ 514 MLX5_ASSERT(hca_attr->hairpin_data_buffer_locked); 515 rte_memcpy(&locked_attr, &unlocked_attr, sizeof(locked_attr)); 516 locked_attr.hairpin_data_buffer_type = 517 MLX5_RQC_HAIRPIN_DATA_BUFFER_TYPE_LOCKED_INTERNAL_BUFFER; 518 tmpl->rq = mlx5_devx_cmd_create_rq(priv->sh->cdev->ctx, &locked_attr, 519 rxq_ctrl->socket); 520 if (!tmpl->rq && rxq->hairpin_conf.force_memory) { 521 DRV_LOG(ERR, "Port %u Rx hairpin queue %u can't create RQ object" 522 " with locked memory buffer", 523 priv->dev_data->port_id, idx); 524 return -rte_errno; 525 } else if (!tmpl->rq && !rxq->hairpin_conf.force_memory) { 526 DRV_LOG(WARNING, "Port %u Rx hairpin queue %u can't create RQ object" 527 " with locked memory buffer. Falling back to unlocked" 528 " device memory.", 529 priv->dev_data->port_id, idx); 530 rte_errno = 0; 531 goto create_rq_unlocked; 532 } 533 goto create_rq_set_state; 534 } 535 536 create_rq_unlocked: 537 tmpl->rq = mlx5_devx_cmd_create_rq(priv->sh->cdev->ctx, &unlocked_attr, 538 rxq_ctrl->socket); 539 if (!tmpl->rq) { 540 DRV_LOG(ERR, 541 "Port %u Rx hairpin queue %u can't create rq object.", 542 priv->dev_data->port_id, idx); 543 rte_errno = errno; 544 return -rte_errno; 545 } 546 create_rq_set_state: 547 priv->dev_data->rx_queue_state[idx] = RTE_ETH_QUEUE_STATE_HAIRPIN; 548 return 0; 549 } 550 551 /** 552 * Create the Rx queue DevX object. 553 * 554 * @param rxq 555 * Pointer to Rx queue. 556 * 557 * @return 558 * 0 on success, a negative errno value otherwise and rte_errno is set. 559 */ 560 static int 561 mlx5_rxq_devx_obj_new(struct mlx5_rxq_priv *rxq) 562 { 563 struct mlx5_priv *priv = rxq->priv; 564 struct mlx5_rxq_ctrl *rxq_ctrl = rxq->ctrl; 565 struct mlx5_rxq_data *rxq_data = &rxq_ctrl->rxq; 566 struct mlx5_rxq_obj *tmpl = rxq_ctrl->obj; 567 int ret = 0; 568 569 MLX5_ASSERT(rxq_data); 570 MLX5_ASSERT(tmpl); 571 if (rxq_ctrl->is_hairpin) 572 return mlx5_rxq_obj_hairpin_new(rxq); 573 tmpl->rxq_ctrl = rxq_ctrl; 574 if (rxq_ctrl->irq && !rxq_ctrl->started) { 575 int devx_ev_flag = 576 MLX5DV_DEVX_CREATE_EVENT_CHANNEL_FLAGS_OMIT_EV_DATA; 577 578 tmpl->devx_channel = mlx5_os_devx_create_event_channel 579 (priv->sh->cdev->ctx, 580 devx_ev_flag); 581 if (!tmpl->devx_channel) { 582 rte_errno = errno; 583 DRV_LOG(ERR, "Failed to create event channel %d.", 584 rte_errno); 585 goto error; 586 } 587 tmpl->fd = mlx5_os_get_devx_channel_fd(tmpl->devx_channel); 588 } 589 /* Create CQ using DevX API. */ 590 ret = mlx5_rxq_create_devx_cq_resources(rxq); 591 if (ret) { 592 DRV_LOG(ERR, "Failed to create CQ."); 593 goto error; 594 } 595 rxq_data->delay_drop = priv->config.std_delay_drop; 596 /* Create RQ using DevX API. */ 597 ret = mlx5_rxq_create_devx_rq_resources(rxq); 598 if (ret) { 599 DRV_LOG(ERR, "Port %u Rx queue %u RQ creation failure.", 600 priv->dev_data->port_id, rxq->idx); 601 rte_errno = ENOMEM; 602 goto error; 603 } 604 /* Change queue state to ready. */ 605 ret = mlx5_devx_modify_rq(rxq, MLX5_RXQ_MOD_RST2RDY); 606 if (ret) 607 goto error; 608 if (!rxq_data->shared) { 609 rxq_data->wqes = (void *)(uintptr_t)rxq->devx_rq.wq.umem_buf; 610 rxq_data->rq_db = (uint32_t *)(uintptr_t)rxq->devx_rq.wq.db_rec; 611 } else if (!rxq_ctrl->started) { 612 rxq_data->wqes = (void *)(uintptr_t)tmpl->devx_rmp.wq.umem_buf; 613 rxq_data->rq_db = 614 (uint32_t *)(uintptr_t)tmpl->devx_rmp.wq.db_rec; 615 } 616 if (!rxq_ctrl->started) { 617 mlx5_rxq_initialize(rxq_data); 618 rxq_ctrl->wqn = rxq->devx_rq.rq->id; 619 } 620 priv->dev_data->rx_queue_state[rxq->idx] = RTE_ETH_QUEUE_STATE_STARTED; 621 return 0; 622 error: 623 ret = rte_errno; /* Save rte_errno before cleanup. */ 624 mlx5_rxq_devx_obj_release(rxq); 625 rte_errno = ret; /* Restore rte_errno. */ 626 return -rte_errno; 627 } 628 629 /** 630 * Prepare RQT attribute structure for DevX RQT API. 631 * 632 * @param dev 633 * Pointer to Ethernet device. 634 * @param log_n 635 * Log of number of queues in the array. 636 * @param queues 637 * List of RX queue indices or NULL, in which case 638 * the attribute will be filled by drop queue ID. 639 * @param queues_n 640 * Size of @p queues array or 0 if it is NULL. 641 * @param ind_tbl 642 * DevX indirection table object. 643 * 644 * @return 645 * The RQT attr object initialized, NULL otherwise and rte_errno is set. 646 */ 647 static struct mlx5_devx_rqt_attr * 648 mlx5_devx_ind_table_create_rqt_attr(struct rte_eth_dev *dev, 649 const unsigned int log_n, 650 const uint16_t *queues, 651 const uint32_t queues_n) 652 { 653 struct mlx5_priv *priv = dev->data->dev_private; 654 struct mlx5_devx_rqt_attr *rqt_attr = NULL; 655 const unsigned int rqt_n = 1 << log_n; 656 unsigned int i, j; 657 658 rqt_attr = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*rqt_attr) + 659 rqt_n * sizeof(uint32_t), 0, SOCKET_ID_ANY); 660 if (!rqt_attr) { 661 DRV_LOG(ERR, "Port %u cannot allocate RQT resources.", 662 dev->data->port_id); 663 rte_errno = ENOMEM; 664 return NULL; 665 } 666 rqt_attr->rqt_max_size = priv->sh->dev_cap.ind_table_max_size; 667 rqt_attr->rqt_actual_size = rqt_n; 668 if (queues == NULL) { 669 for (i = 0; i < rqt_n; i++) 670 rqt_attr->rq_list[i] = 671 priv->drop_queue.rxq->devx_rq.rq->id; 672 return rqt_attr; 673 } 674 for (i = 0; i != queues_n; ++i) { 675 if (mlx5_is_external_rxq(dev, queues[i])) { 676 struct mlx5_external_rxq *ext_rxq = 677 mlx5_ext_rxq_get(dev, queues[i]); 678 679 rqt_attr->rq_list[i] = ext_rxq->hw_id; 680 } else { 681 struct mlx5_rxq_priv *rxq = 682 mlx5_rxq_get(dev, queues[i]); 683 684 MLX5_ASSERT(rxq != NULL); 685 if (rxq->ctrl->is_hairpin) 686 rqt_attr->rq_list[i] = rxq->ctrl->obj->rq->id; 687 else 688 rqt_attr->rq_list[i] = rxq->devx_rq.rq->id; 689 } 690 } 691 MLX5_ASSERT(i > 0); 692 for (j = 0; i != rqt_n; ++j, ++i) 693 rqt_attr->rq_list[i] = rqt_attr->rq_list[j]; 694 return rqt_attr; 695 } 696 697 /** 698 * Create RQT using DevX API as a filed of indirection table. 699 * 700 * @param dev 701 * Pointer to Ethernet device. 702 * @param log_n 703 * Log of number of queues in the array. 704 * @param ind_tbl 705 * DevX indirection table object. 706 * 707 * @return 708 * 0 on success, a negative errno value otherwise and rte_errno is set. 709 */ 710 static int 711 mlx5_devx_ind_table_new(struct rte_eth_dev *dev, const unsigned int log_n, 712 struct mlx5_ind_table_obj *ind_tbl) 713 { 714 struct mlx5_priv *priv = dev->data->dev_private; 715 struct mlx5_devx_rqt_attr *rqt_attr = NULL; 716 const uint16_t *queues = dev->data->dev_started ? ind_tbl->queues : 717 NULL; 718 719 MLX5_ASSERT(ind_tbl); 720 rqt_attr = mlx5_devx_ind_table_create_rqt_attr(dev, log_n, queues, 721 ind_tbl->queues_n); 722 if (!rqt_attr) 723 return -rte_errno; 724 ind_tbl->rqt = mlx5_devx_cmd_create_rqt(priv->sh->cdev->ctx, rqt_attr); 725 mlx5_free(rqt_attr); 726 if (!ind_tbl->rqt) { 727 DRV_LOG(ERR, "Port %u cannot create DevX RQT.", 728 dev->data->port_id); 729 rte_errno = errno; 730 return -rte_errno; 731 } 732 return 0; 733 } 734 735 /** 736 * Modify RQT using DevX API as a filed of indirection table. 737 * 738 * @param dev 739 * Pointer to Ethernet device. 740 * @param log_n 741 * Log of number of queues in the array. 742 * @param ind_tbl 743 * DevX indirection table object. 744 * 745 * @return 746 * 0 on success, a negative errno value otherwise and rte_errno is set. 747 */ 748 static int 749 mlx5_devx_ind_table_modify(struct rte_eth_dev *dev, const unsigned int log_n, 750 const uint16_t *queues, const uint32_t queues_n, 751 struct mlx5_ind_table_obj *ind_tbl) 752 { 753 int ret = 0; 754 struct mlx5_devx_rqt_attr *rqt_attr = NULL; 755 756 MLX5_ASSERT(ind_tbl); 757 rqt_attr = mlx5_devx_ind_table_create_rqt_attr(dev, log_n, 758 queues, 759 queues_n); 760 if (!rqt_attr) 761 return -rte_errno; 762 ret = mlx5_devx_cmd_modify_rqt(ind_tbl->rqt, rqt_attr); 763 mlx5_free(rqt_attr); 764 if (ret) 765 DRV_LOG(ERR, "Port %u cannot modify DevX RQT.", 766 dev->data->port_id); 767 return ret; 768 } 769 770 /** 771 * Destroy the DevX RQT object. 772 * 773 * @param ind_table 774 * Indirection table to release. 775 */ 776 static void 777 mlx5_devx_ind_table_destroy(struct mlx5_ind_table_obj *ind_tbl) 778 { 779 claim_zero(mlx5_devx_cmd_destroy(ind_tbl->rqt)); 780 } 781 782 /** 783 * Set TIR attribute struct with relevant input values. 784 * 785 * @param[in] dev 786 * Pointer to Ethernet device. 787 * @param[in] rss_key 788 * RSS key for the Rx hash queue. 789 * @param[in] hash_fields 790 * Verbs protocol hash field to make the RSS on. 791 * @param[in] ind_tbl 792 * Indirection table for TIR. If table queues array is NULL, 793 * a TIR for drop queue is assumed. 794 * @param[in] tunnel 795 * Tunnel type. 796 * @param[out] tir_attr 797 * Parameters structure for TIR creation/modification. 798 * 799 * @return 800 * The Verbs/DevX object initialised index, 0 otherwise and rte_errno is set. 801 */ 802 static void 803 mlx5_devx_tir_attr_set(struct rte_eth_dev *dev, const uint8_t *rss_key, 804 uint64_t hash_fields, 805 const struct mlx5_ind_table_obj *ind_tbl, 806 int tunnel, bool symmetric_hash_function, 807 struct mlx5_devx_tir_attr *tir_attr) 808 { 809 struct mlx5_priv *priv = dev->data->dev_private; 810 bool is_hairpin; 811 bool lro = false; 812 uint32_t i; 813 814 /* NULL queues designate drop queue. */ 815 if (ind_tbl->queues == NULL) { 816 is_hairpin = priv->drop_queue.rxq->ctrl->is_hairpin; 817 } else if (mlx5_is_external_rxq(dev, ind_tbl->queues[0])) { 818 /* External RxQ supports neither Hairpin nor LRO. */ 819 is_hairpin = false; 820 } else { 821 is_hairpin = mlx5_rxq_is_hairpin(dev, ind_tbl->queues[0]); 822 lro = true; 823 /* Enable TIR LRO only if all the queues were configured for. */ 824 for (i = 0; i < ind_tbl->queues_n; ++i) { 825 struct mlx5_rxq_data *rxq_i = 826 mlx5_rxq_data_get(dev, ind_tbl->queues[i]); 827 828 if (rxq_i != NULL && !rxq_i->lro) { 829 lro = false; 830 break; 831 } 832 } 833 } 834 memset(tir_attr, 0, sizeof(*tir_attr)); 835 tir_attr->disp_type = MLX5_TIRC_DISP_TYPE_INDIRECT; 836 tir_attr->rx_hash_fn = MLX5_RX_HASH_FN_TOEPLITZ; 837 tir_attr->tunneled_offload_en = !!tunnel; 838 tir_attr->rx_hash_symmetric = symmetric_hash_function; 839 /* If needed, translate hash_fields bitmap to PRM format. */ 840 if (hash_fields) { 841 struct mlx5_rx_hash_field_select *rx_hash_field_select = 842 #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT 843 hash_fields & IBV_RX_HASH_INNER ? 844 &tir_attr->rx_hash_field_selector_inner : 845 #endif 846 &tir_attr->rx_hash_field_selector_outer; 847 /* 1 bit: 0: IPv4, 1: IPv6. */ 848 rx_hash_field_select->l3_prot_type = 849 !!(hash_fields & MLX5_IPV6_IBV_RX_HASH); 850 /* 1 bit: 0: TCP, 1: UDP. */ 851 rx_hash_field_select->l4_prot_type = 852 !!(hash_fields & MLX5_UDP_IBV_RX_HASH); 853 /* Bitmask which sets which fields to use in RX Hash. */ 854 rx_hash_field_select->selected_fields = 855 ((!!(hash_fields & MLX5_L3_SRC_IBV_RX_HASH)) << 856 MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_SRC_IP) | 857 (!!(hash_fields & MLX5_L3_DST_IBV_RX_HASH)) << 858 MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_DST_IP | 859 (!!(hash_fields & MLX5_L4_SRC_IBV_RX_HASH)) << 860 MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_L4_SPORT | 861 (!!(hash_fields & MLX5_L4_DST_IBV_RX_HASH)) << 862 MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_L4_DPORT | 863 (!!(hash_fields & IBV_RX_HASH_IPSEC_SPI)) << 864 MLX5_RX_HASH_FIELD_SELECT_SELECTED_FIELDS_IPSEC_SPI; 865 } 866 if (is_hairpin) 867 tir_attr->transport_domain = priv->sh->td->id; 868 else 869 tir_attr->transport_domain = priv->sh->tdn; 870 memcpy(tir_attr->rx_hash_toeplitz_key, rss_key, MLX5_RSS_HASH_KEY_LEN); 871 tir_attr->indirect_table = ind_tbl->rqt->id; 872 if (dev->data->dev_conf.lpbk_mode) 873 tir_attr->self_lb_block = MLX5_TIRC_SELF_LB_BLOCK_BLOCK_UNICAST; 874 if (lro) { 875 MLX5_ASSERT(priv->sh->config.lro_allowed); 876 tir_attr->lro_timeout_period_usecs = priv->config.lro_timeout; 877 tir_attr->lro_max_msg_sz = 878 priv->max_lro_msg_size / MLX5_LRO_SEG_CHUNK_SIZE; 879 tir_attr->lro_enable_mask = 880 MLX5_TIRC_LRO_ENABLE_MASK_IPV4_LRO | 881 MLX5_TIRC_LRO_ENABLE_MASK_IPV6_LRO; 882 } 883 } 884 885 /** 886 * Create an Rx Hash queue. 887 * 888 * @param dev 889 * Pointer to Ethernet device. 890 * @param hrxq 891 * Pointer to Rx Hash queue. 892 * @param tunnel 893 * Tunnel type. 894 * 895 * @return 896 * 0 on success, a negative errno value otherwise and rte_errno is set. 897 */ 898 static int 899 mlx5_devx_hrxq_new(struct rte_eth_dev *dev, struct mlx5_hrxq *hrxq, 900 int tunnel __rte_unused) 901 { 902 struct mlx5_priv *priv = dev->data->dev_private; 903 struct mlx5_devx_tir_attr tir_attr = {0}; 904 int err; 905 906 mlx5_devx_tir_attr_set(dev, hrxq->rss_key, hrxq->hash_fields, 907 hrxq->ind_table, tunnel, hrxq->symmetric_hash_function, 908 &tir_attr); 909 hrxq->tir = mlx5_devx_cmd_create_tir(priv->sh->cdev->ctx, &tir_attr); 910 if (!hrxq->tir) { 911 DRV_LOG(ERR, "Port %u cannot create DevX TIR.", 912 dev->data->port_id); 913 rte_errno = errno; 914 goto error; 915 } 916 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H) 917 #ifdef HAVE_MLX5_HWS_SUPPORT 918 if (hrxq->hws_flags) { 919 hrxq->action = mlx5dr_action_create_dest_tir 920 (priv->dr_ctx, 921 (struct mlx5dr_devx_obj *)hrxq->tir, hrxq->hws_flags, true); 922 if (!hrxq->action) 923 goto error; 924 return 0; 925 } 926 #endif 927 if (mlx5_flow_os_create_flow_action_dest_devx_tir(hrxq->tir, 928 &hrxq->action)) { 929 rte_errno = errno; 930 goto error; 931 } 932 #endif 933 return 0; 934 error: 935 err = rte_errno; /* Save rte_errno before cleanup. */ 936 if (hrxq->tir) 937 claim_zero(mlx5_devx_cmd_destroy(hrxq->tir)); 938 rte_errno = err; /* Restore rte_errno. */ 939 return -rte_errno; 940 } 941 942 /** 943 * Destroy a DevX TIR object. 944 * 945 * @param hrxq 946 * Hash Rx queue to release its tir. 947 */ 948 static void 949 mlx5_devx_tir_destroy(struct mlx5_hrxq *hrxq) 950 { 951 claim_zero(mlx5_devx_cmd_destroy(hrxq->tir)); 952 } 953 954 /** 955 * Modify an Rx Hash queue configuration. 956 * 957 * @param dev 958 * Pointer to Ethernet device. 959 * @param hrxq 960 * Hash Rx queue to modify. 961 * @param rss_key 962 * RSS key for the Rx hash queue. 963 * @param hash_fields 964 * Verbs protocol hash field to make the RSS on. 965 * @param[in] ind_tbl 966 * Indirection table for TIR. 967 * 968 * @return 969 * 0 on success, a negative errno value otherwise and rte_errno is set. 970 */ 971 static int 972 mlx5_devx_hrxq_modify(struct rte_eth_dev *dev, struct mlx5_hrxq *hrxq, 973 const uint8_t *rss_key, 974 uint64_t hash_fields, 975 bool symmetric_hash_function, 976 const struct mlx5_ind_table_obj *ind_tbl) 977 { 978 struct mlx5_devx_modify_tir_attr modify_tir = {0}; 979 980 /* 981 * untested for modification fields: 982 * - rx_hash_fn set hard-coded in hrxq_new(), 983 * - lro_xxx not set after rxq setup 984 */ 985 if (ind_tbl != hrxq->ind_table) 986 modify_tir.modify_bitmask |= 987 MLX5_MODIFY_TIR_IN_MODIFY_BITMASK_INDIRECT_TABLE; 988 if (hash_fields != hrxq->hash_fields || 989 symmetric_hash_function != hrxq->symmetric_hash_function || 990 memcmp(hrxq->rss_key, rss_key, MLX5_RSS_HASH_KEY_LEN)) 991 modify_tir.modify_bitmask |= 992 MLX5_MODIFY_TIR_IN_MODIFY_BITMASK_HASH; 993 mlx5_devx_tir_attr_set(dev, rss_key, hash_fields, ind_tbl, 994 0, /* N/A - tunnel modification unsupported */ 995 symmetric_hash_function, 996 &modify_tir.tir); 997 modify_tir.tirn = hrxq->tir->id; 998 if (mlx5_devx_cmd_modify_tir(hrxq->tir, &modify_tir)) { 999 DRV_LOG(ERR, "port %u cannot modify DevX TIR", 1000 dev->data->port_id); 1001 rte_errno = errno; 1002 return -rte_errno; 1003 } 1004 return 0; 1005 } 1006 1007 /** 1008 * Create a DevX drop Rx queue. 1009 * 1010 * @param dev 1011 * Pointer to Ethernet device. 1012 * 1013 * @return 1014 * 0 on success, a negative errno value otherwise and rte_errno is set. 1015 */ 1016 static int 1017 mlx5_rxq_devx_obj_drop_create(struct rte_eth_dev *dev) 1018 { 1019 struct mlx5_priv *priv = dev->data->dev_private; 1020 int socket_id = dev->device->numa_node; 1021 struct mlx5_rxq_priv *rxq; 1022 struct mlx5_rxq_ctrl *rxq_ctrl = NULL; 1023 struct mlx5_rxq_obj *rxq_obj = NULL; 1024 int ret; 1025 1026 /* 1027 * Initialize dummy control structures. 1028 * They are required to hold pointers for cleanup 1029 * and are only accessible via drop queue DevX objects. 1030 */ 1031 rxq = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*rxq), 0, socket_id); 1032 if (rxq == NULL) { 1033 DRV_LOG(ERR, "Port %u could not allocate drop queue private", 1034 dev->data->port_id); 1035 rte_errno = ENOMEM; 1036 goto error; 1037 } 1038 rxq_ctrl = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*rxq_ctrl), 1039 0, socket_id); 1040 if (rxq_ctrl == NULL) { 1041 DRV_LOG(ERR, "Port %u could not allocate drop queue control", 1042 dev->data->port_id); 1043 rte_errno = ENOMEM; 1044 goto error; 1045 } 1046 rxq_obj = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*rxq_obj), 0, socket_id); 1047 if (rxq_obj == NULL) { 1048 DRV_LOG(ERR, "Port %u could not allocate drop queue object", 1049 dev->data->port_id); 1050 rte_errno = ENOMEM; 1051 goto error; 1052 } 1053 /* set the CPU socket ID where the rxq_ctrl was allocated */ 1054 rxq_ctrl->socket = socket_id; 1055 rxq_obj->rxq_ctrl = rxq_ctrl; 1056 rxq_ctrl->is_hairpin = false; 1057 rxq_ctrl->sh = priv->sh; 1058 rxq_ctrl->obj = rxq_obj; 1059 rxq->ctrl = rxq_ctrl; 1060 rxq->priv = priv; 1061 LIST_INSERT_HEAD(&rxq_ctrl->owners, rxq, owner_entry); 1062 /* Create CQ using DevX API. */ 1063 ret = mlx5_rxq_create_devx_cq_resources(rxq); 1064 if (ret != 0) { 1065 DRV_LOG(ERR, "Port %u drop queue CQ creation failed.", 1066 dev->data->port_id); 1067 goto error; 1068 } 1069 rxq_ctrl->rxq.delay_drop = 0; 1070 /* Create RQ using DevX API. */ 1071 ret = mlx5_rxq_create_devx_rq_resources(rxq); 1072 if (ret != 0) { 1073 DRV_LOG(ERR, "Port %u drop queue RQ creation failed.", 1074 dev->data->port_id); 1075 rte_errno = ENOMEM; 1076 goto error; 1077 } 1078 /* Change queue state to ready. */ 1079 ret = mlx5_devx_modify_rq(rxq, MLX5_RXQ_MOD_RST2RDY); 1080 if (ret != 0) 1081 goto error; 1082 /* Initialize drop queue. */ 1083 priv->drop_queue.rxq = rxq; 1084 return 0; 1085 error: 1086 ret = rte_errno; /* Save rte_errno before cleanup. */ 1087 if (rxq != NULL && rxq->devx_rq.rq != NULL) 1088 mlx5_devx_rq_destroy(&rxq->devx_rq); 1089 if (rxq_obj != NULL) { 1090 if (rxq_obj->cq_obj.cq != NULL) 1091 mlx5_devx_cq_destroy(&rxq_obj->cq_obj); 1092 if (rxq_obj->devx_channel) 1093 mlx5_os_devx_destroy_event_channel 1094 (rxq_obj->devx_channel); 1095 mlx5_free(rxq_obj); 1096 } 1097 if (rxq_ctrl != NULL) 1098 mlx5_free(rxq_ctrl); 1099 if (rxq != NULL) 1100 mlx5_free(rxq); 1101 rte_errno = ret; /* Restore rte_errno. */ 1102 return -rte_errno; 1103 } 1104 1105 /** 1106 * Release drop Rx queue resources. 1107 * 1108 * @param dev 1109 * Pointer to Ethernet device. 1110 */ 1111 static void 1112 mlx5_rxq_devx_obj_drop_release(struct rte_eth_dev *dev) 1113 { 1114 struct mlx5_priv *priv = dev->data->dev_private; 1115 struct mlx5_rxq_priv *rxq = priv->drop_queue.rxq; 1116 struct mlx5_rxq_ctrl *rxq_ctrl = rxq->ctrl; 1117 1118 mlx5_rxq_devx_obj_release(rxq); 1119 mlx5_free(rxq_ctrl->obj); 1120 mlx5_free(rxq_ctrl); 1121 mlx5_free(rxq); 1122 priv->drop_queue.rxq = NULL; 1123 } 1124 1125 /** 1126 * Release a drop hash Rx queue. 1127 * 1128 * @param dev 1129 * Pointer to Ethernet device. 1130 */ 1131 static void 1132 mlx5_devx_drop_action_destroy(struct rte_eth_dev *dev) 1133 { 1134 struct mlx5_priv *priv = dev->data->dev_private; 1135 struct mlx5_hrxq *hrxq = priv->drop_queue.hrxq; 1136 1137 #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H) 1138 if (hrxq->action != NULL) 1139 mlx5_flow_os_destroy_flow_action(hrxq->action); 1140 #endif 1141 if (hrxq->tir != NULL) 1142 mlx5_devx_tir_destroy(hrxq); 1143 if (hrxq->ind_table->ind_table != NULL) 1144 mlx5_devx_ind_table_destroy(hrxq->ind_table); 1145 if (priv->drop_queue.rxq->devx_rq.rq != NULL) 1146 mlx5_rxq_devx_obj_drop_release(dev); 1147 } 1148 1149 /** 1150 * Create a DevX drop action for Rx Hash queue. 1151 * 1152 * @param dev 1153 * Pointer to Ethernet device. 1154 * 1155 * @return 1156 * 0 on success, a negative errno value otherwise and rte_errno is set. 1157 */ 1158 static int 1159 mlx5_devx_drop_action_create(struct rte_eth_dev *dev) 1160 { 1161 struct mlx5_priv *priv = dev->data->dev_private; 1162 struct mlx5_hrxq *hrxq = priv->drop_queue.hrxq; 1163 int ret; 1164 1165 ret = mlx5_rxq_devx_obj_drop_create(dev); 1166 if (ret != 0) { 1167 DRV_LOG(ERR, "Cannot create drop RX queue"); 1168 return ret; 1169 } 1170 if (priv->sh->config.dv_flow_en == 2) 1171 return 0; 1172 /* hrxq->ind_table queues are NULL, drop RX queue ID will be used */ 1173 ret = mlx5_devx_ind_table_new(dev, 0, hrxq->ind_table); 1174 if (ret != 0) { 1175 DRV_LOG(ERR, "Cannot create drop hash RX queue indirection table"); 1176 goto error; 1177 } 1178 ret = mlx5_devx_hrxq_new(dev, hrxq, /* tunnel */ false); 1179 if (ret != 0) { 1180 DRV_LOG(ERR, "Cannot create drop hash RX queue"); 1181 goto error; 1182 } 1183 return 0; 1184 error: 1185 mlx5_devx_drop_action_destroy(dev); 1186 return ret; 1187 } 1188 1189 /** 1190 * Select TXQ TIS number. 1191 * 1192 * @param dev 1193 * Pointer to Ethernet device. 1194 * @param queue_idx 1195 * Queue index in DPDK Tx queue array. 1196 * 1197 * @return 1198 * > 0 on success, a negative errno value otherwise. 1199 */ 1200 static uint32_t 1201 mlx5_get_txq_tis_num(struct rte_eth_dev *dev, uint16_t queue_idx) 1202 { 1203 struct mlx5_priv *priv = dev->data->dev_private; 1204 struct mlx5_txq_data *txq_data = (*priv->txqs)[queue_idx]; 1205 int tis_idx = 0; 1206 1207 if (priv->sh->bond.n_port) { 1208 if (txq_data->tx_aggr_affinity) { 1209 tis_idx = txq_data->tx_aggr_affinity; 1210 } else if (priv->sh->lag.affinity_mode == MLX5_LAG_MODE_TIS) { 1211 tis_idx = (priv->lag_affinity_idx + queue_idx) % 1212 priv->sh->bond.n_port + 1; 1213 DRV_LOG(INFO, "port %d txq %d gets affinity %d and maps to PF %d.", 1214 dev->data->port_id, queue_idx, tis_idx, 1215 priv->sh->lag.tx_remap_affinity[tis_idx - 1]); 1216 } 1217 } 1218 MLX5_ASSERT(priv->sh->tis[tis_idx]); 1219 return priv->sh->tis[tis_idx]->id; 1220 } 1221 1222 /** 1223 * Create the Tx hairpin queue object. 1224 * 1225 * @param dev 1226 * Pointer to Ethernet device. 1227 * @param idx 1228 * Queue index in DPDK Tx queue array. 1229 * 1230 * @return 1231 * 0 on success, a negative errno value otherwise and rte_errno is set. 1232 */ 1233 static int 1234 mlx5_txq_obj_hairpin_new(struct rte_eth_dev *dev, uint16_t idx) 1235 { 1236 struct mlx5_priv *priv = dev->data->dev_private; 1237 struct mlx5_hca_attr *hca_attr = &priv->sh->cdev->config.hca_attr; 1238 struct mlx5_txq_data *txq_data = (*priv->txqs)[idx]; 1239 struct mlx5_txq_ctrl *txq_ctrl = 1240 container_of(txq_data, struct mlx5_txq_ctrl, txq); 1241 struct mlx5_devx_create_sq_attr dev_mem_attr = { 0 }; 1242 struct mlx5_devx_create_sq_attr host_mem_attr = { 0 }; 1243 struct mlx5_txq_obj *tmpl = txq_ctrl->obj; 1244 void *umem_buf = NULL; 1245 void *umem_obj = NULL; 1246 uint32_t max_wq_data; 1247 1248 MLX5_ASSERT(txq_data); 1249 MLX5_ASSERT(tmpl); 1250 tmpl->txq_ctrl = txq_ctrl; 1251 dev_mem_attr.hairpin = 1; 1252 dev_mem_attr.tis_lst_sz = 1; 1253 dev_mem_attr.tis_num = mlx5_get_txq_tis_num(dev, idx); 1254 max_wq_data = 1255 priv->sh->cdev->config.hca_attr.log_max_hairpin_wq_data_sz; 1256 /* Jumbo frames > 9KB should be supported, and more packets. */ 1257 if (priv->config.log_hp_size != (uint32_t)MLX5_ARG_UNSET) { 1258 if (priv->config.log_hp_size > max_wq_data) { 1259 DRV_LOG(ERR, "Total data size %u power of 2 is " 1260 "too large for hairpin.", 1261 priv->config.log_hp_size); 1262 rte_errno = ERANGE; 1263 return -rte_errno; 1264 } 1265 dev_mem_attr.wq_attr.log_hairpin_data_sz = priv->config.log_hp_size; 1266 } else { 1267 dev_mem_attr.wq_attr.log_hairpin_data_sz = 1268 (max_wq_data < MLX5_HAIRPIN_JUMBO_LOG_SIZE) ? 1269 max_wq_data : MLX5_HAIRPIN_JUMBO_LOG_SIZE; 1270 } 1271 /* Set the packets number to the maximum value for performance. */ 1272 dev_mem_attr.wq_attr.log_hairpin_num_packets = 1273 dev_mem_attr.wq_attr.log_hairpin_data_sz - 1274 MLX5_HAIRPIN_QUEUE_STRIDE; 1275 dev_mem_attr.hairpin_wq_buffer_type = MLX5_SQC_HAIRPIN_WQ_BUFFER_TYPE_INTERNAL_BUFFER; 1276 if (txq_ctrl->hairpin_conf.use_rte_memory) { 1277 uint32_t umem_size; 1278 uint32_t umem_dbrec; 1279 size_t alignment = MLX5_WQE_BUF_ALIGNMENT; 1280 1281 if (alignment == (size_t)-1) { 1282 DRV_LOG(ERR, "Failed to get WQE buf alignment."); 1283 rte_errno = ENOMEM; 1284 return -rte_errno; 1285 } 1286 /* 1287 * It is assumed that configuration is verified against capabilities 1288 * during queue setup. 1289 */ 1290 MLX5_ASSERT(hca_attr->hairpin_sq_wq_in_host_mem); 1291 MLX5_ASSERT(hca_attr->hairpin_sq_wqe_bb_size > 0); 1292 rte_memcpy(&host_mem_attr, &dev_mem_attr, sizeof(host_mem_attr)); 1293 umem_size = MLX5_WQE_SIZE * 1294 RTE_BIT32(host_mem_attr.wq_attr.log_hairpin_num_packets); 1295 umem_dbrec = RTE_ALIGN(umem_size, MLX5_DBR_SIZE); 1296 umem_size += MLX5_DBR_SIZE; 1297 umem_buf = mlx5_malloc(MLX5_MEM_RTE | MLX5_MEM_ZERO, umem_size, 1298 alignment, priv->sh->numa_node); 1299 if (umem_buf == NULL && txq_ctrl->hairpin_conf.force_memory) { 1300 DRV_LOG(ERR, "Failed to allocate memory for hairpin TX queue"); 1301 rte_errno = ENOMEM; 1302 return -rte_errno; 1303 } else if (umem_buf == NULL && !txq_ctrl->hairpin_conf.force_memory) { 1304 DRV_LOG(WARNING, "Failed to allocate memory for hairpin TX queue." 1305 " Falling back to TX queue located on the device."); 1306 goto create_sq_on_device; 1307 } 1308 umem_obj = mlx5_os_umem_reg(priv->sh->cdev->ctx, 1309 (void *)(uintptr_t)umem_buf, 1310 umem_size, 1311 IBV_ACCESS_LOCAL_WRITE); 1312 if (umem_obj == NULL && txq_ctrl->hairpin_conf.force_memory) { 1313 DRV_LOG(ERR, "Failed to register UMEM for hairpin TX queue"); 1314 mlx5_free(umem_buf); 1315 return -rte_errno; 1316 } else if (umem_obj == NULL && !txq_ctrl->hairpin_conf.force_memory) { 1317 DRV_LOG(WARNING, "Failed to register UMEM for hairpin TX queue." 1318 " Falling back to TX queue located on the device."); 1319 rte_errno = 0; 1320 mlx5_free(umem_buf); 1321 goto create_sq_on_device; 1322 } 1323 host_mem_attr.wq_attr.wq_type = MLX5_WQ_TYPE_CYCLIC; 1324 host_mem_attr.wq_attr.wq_umem_valid = 1; 1325 host_mem_attr.wq_attr.wq_umem_id = mlx5_os_get_umem_id(umem_obj); 1326 host_mem_attr.wq_attr.wq_umem_offset = 0; 1327 host_mem_attr.wq_attr.dbr_umem_valid = 1; 1328 host_mem_attr.wq_attr.dbr_umem_id = host_mem_attr.wq_attr.wq_umem_id; 1329 host_mem_attr.wq_attr.dbr_addr = umem_dbrec; 1330 host_mem_attr.wq_attr.log_wq_stride = rte_log2_u32(MLX5_WQE_SIZE); 1331 host_mem_attr.wq_attr.log_wq_sz = 1332 host_mem_attr.wq_attr.log_hairpin_num_packets * 1333 hca_attr->hairpin_sq_wqe_bb_size; 1334 host_mem_attr.wq_attr.log_wq_pg_sz = MLX5_LOG_PAGE_SIZE; 1335 host_mem_attr.hairpin_wq_buffer_type = MLX5_SQC_HAIRPIN_WQ_BUFFER_TYPE_HOST_MEMORY; 1336 tmpl->sq = mlx5_devx_cmd_create_sq(priv->sh->cdev->ctx, &host_mem_attr); 1337 if (!tmpl->sq && txq_ctrl->hairpin_conf.force_memory) { 1338 DRV_LOG(ERR, 1339 "Port %u tx hairpin queue %u can't create SQ object.", 1340 dev->data->port_id, idx); 1341 claim_zero(mlx5_os_umem_dereg(umem_obj)); 1342 mlx5_free(umem_buf); 1343 return -rte_errno; 1344 } else if (!tmpl->sq && !txq_ctrl->hairpin_conf.force_memory) { 1345 DRV_LOG(WARNING, 1346 "Port %u tx hairpin queue %u failed to allocate SQ object" 1347 " using host memory. Falling back to TX queue located" 1348 " on the device", 1349 dev->data->port_id, idx); 1350 rte_errno = 0; 1351 claim_zero(mlx5_os_umem_dereg(umem_obj)); 1352 mlx5_free(umem_buf); 1353 goto create_sq_on_device; 1354 } 1355 tmpl->umem_buf_wq_buffer = umem_buf; 1356 tmpl->umem_obj_wq_buffer = umem_obj; 1357 return 0; 1358 } 1359 1360 create_sq_on_device: 1361 tmpl->sq = mlx5_devx_cmd_create_sq(priv->sh->cdev->ctx, &dev_mem_attr); 1362 if (!tmpl->sq) { 1363 DRV_LOG(ERR, 1364 "Port %u tx hairpin queue %u can't create SQ object.", 1365 dev->data->port_id, idx); 1366 rte_errno = errno; 1367 return -rte_errno; 1368 } 1369 return 0; 1370 } 1371 1372 #if defined(HAVE_MLX5DV_DEVX_UAR_OFFSET) || !defined(HAVE_INFINIBAND_VERBS_H) 1373 /** 1374 * Destroy the Tx queue DevX object. 1375 * 1376 * @param txq_obj 1377 * Txq object to destroy. 1378 */ 1379 static void 1380 mlx5_txq_release_devx_resources(struct mlx5_txq_obj *txq_obj) 1381 { 1382 mlx5_devx_sq_destroy(&txq_obj->sq_obj); 1383 memset(&txq_obj->sq_obj, 0, sizeof(txq_obj->sq_obj)); 1384 mlx5_devx_cq_destroy(&txq_obj->cq_obj); 1385 memset(&txq_obj->cq_obj, 0, sizeof(txq_obj->cq_obj)); 1386 } 1387 1388 /** 1389 * Create a SQ object and its resources using DevX. 1390 * 1391 * @param dev 1392 * Pointer to Ethernet device. 1393 * @param idx 1394 * Queue index in DPDK Tx queue array. 1395 * @param[in] log_desc_n 1396 * Log of number of descriptors in queue. 1397 * 1398 * @return 1399 * 0 on success, a negative errno value otherwise and rte_errno is set. 1400 */ 1401 static int 1402 mlx5_txq_create_devx_sq_resources(struct rte_eth_dev *dev, uint16_t idx, 1403 uint16_t log_desc_n) 1404 { 1405 struct mlx5_priv *priv = dev->data->dev_private; 1406 struct mlx5_common_device *cdev = priv->sh->cdev; 1407 struct mlx5_uar *uar = &priv->sh->tx_uar; 1408 struct mlx5_txq_data *txq_data = (*priv->txqs)[idx]; 1409 struct mlx5_txq_ctrl *txq_ctrl = 1410 container_of(txq_data, struct mlx5_txq_ctrl, txq); 1411 struct mlx5_txq_obj *txq_obj = txq_ctrl->obj; 1412 struct mlx5_devx_create_sq_attr sq_attr = { 1413 .flush_in_error_en = 1, 1414 .allow_multi_pkt_send_wqe = !!priv->config.mps, 1415 .min_wqe_inline_mode = cdev->config.hca_attr.vport_inline_mode, 1416 .allow_swp = !!priv->sh->dev_cap.swp, 1417 .cqn = txq_obj->cq_obj.cq->id, 1418 .tis_lst_sz = 1, 1419 .wq_attr = (struct mlx5_devx_wq_attr){ 1420 .pd = cdev->pdn, 1421 .uar_page = mlx5_os_get_devx_uar_page_id(uar->obj), 1422 }, 1423 .ts_format = 1424 mlx5_ts_format_conv(cdev->config.hca_attr.sq_ts_format), 1425 .tis_num = mlx5_get_txq_tis_num(dev, idx), 1426 }; 1427 1428 /* Create Send Queue object with DevX. */ 1429 return mlx5_devx_sq_create(cdev->ctx, &txq_obj->sq_obj, 1430 log_desc_n, &sq_attr, priv->sh->numa_node); 1431 } 1432 #endif 1433 1434 /** 1435 * Create the Tx queue DevX object. 1436 * 1437 * @param dev 1438 * Pointer to Ethernet device. 1439 * @param idx 1440 * Queue index in DPDK Tx queue array. 1441 * 1442 * @return 1443 * 0 on success, a negative errno value otherwise and rte_errno is set. 1444 */ 1445 int 1446 mlx5_txq_devx_obj_new(struct rte_eth_dev *dev, uint16_t idx) 1447 { 1448 struct mlx5_priv *priv = dev->data->dev_private; 1449 struct mlx5_txq_data *txq_data = (*priv->txqs)[idx]; 1450 struct mlx5_txq_ctrl *txq_ctrl = 1451 container_of(txq_data, struct mlx5_txq_ctrl, txq); 1452 1453 if (txq_ctrl->is_hairpin) 1454 return mlx5_txq_obj_hairpin_new(dev, idx); 1455 #if !defined(HAVE_MLX5DV_DEVX_UAR_OFFSET) && defined(HAVE_INFINIBAND_VERBS_H) 1456 DRV_LOG(ERR, "Port %u Tx queue %u cannot create with DevX, no UAR.", 1457 dev->data->port_id, idx); 1458 rte_errno = ENOMEM; 1459 return -rte_errno; 1460 #else 1461 struct mlx5_proc_priv *ppriv = MLX5_PROC_PRIV(PORT_ID(priv)); 1462 struct mlx5_dev_ctx_shared *sh = priv->sh; 1463 struct mlx5_txq_obj *txq_obj = txq_ctrl->obj; 1464 struct mlx5_devx_cq_attr cq_attr = { 1465 .uar_page_id = mlx5_os_get_devx_uar_page_id(sh->tx_uar.obj), 1466 }; 1467 uint32_t cqe_n, log_desc_n; 1468 uint32_t wqe_n, wqe_size; 1469 int ret = 0; 1470 1471 MLX5_ASSERT(txq_data); 1472 MLX5_ASSERT(txq_obj); 1473 MLX5_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY); 1474 MLX5_ASSERT(ppriv); 1475 txq_obj->txq_ctrl = txq_ctrl; 1476 txq_obj->dev = dev; 1477 if (__rte_trace_point_fp_is_enabled() && 1478 txq_data->offloads & RTE_ETH_TX_OFFLOAD_SEND_ON_TIMESTAMP) 1479 cqe_n = UINT16_MAX / 2 - 1; 1480 else 1481 cqe_n = (1UL << txq_data->elts_n) / MLX5_TX_COMP_THRESH + 1482 1 + MLX5_TX_COMP_THRESH_INLINE_DIV; 1483 log_desc_n = log2above(cqe_n); 1484 cqe_n = 1UL << log_desc_n; 1485 if (cqe_n > UINT16_MAX) { 1486 DRV_LOG(ERR, "Port %u Tx queue %u requests to many CQEs %u.", 1487 dev->data->port_id, txq_data->idx, cqe_n); 1488 rte_errno = EINVAL; 1489 return 0; 1490 } 1491 /* Create completion queue object with DevX. */ 1492 ret = mlx5_devx_cq_create(sh->cdev->ctx, &txq_obj->cq_obj, log_desc_n, 1493 &cq_attr, priv->sh->numa_node); 1494 if (ret) { 1495 DRV_LOG(ERR, "Port %u Tx queue %u CQ creation failure.", 1496 dev->data->port_id, idx); 1497 goto error; 1498 } 1499 txq_data->cqe_n = log_desc_n; 1500 txq_data->cqe_s = cqe_n; 1501 txq_data->cqe_m = txq_data->cqe_s - 1; 1502 txq_data->cqes = txq_obj->cq_obj.cqes; 1503 txq_data->cq_ci = 0; 1504 txq_data->cq_pi = 0; 1505 txq_data->cq_db = txq_obj->cq_obj.db_rec; 1506 *txq_data->cq_db = 0; 1507 /* 1508 * Adjust the amount of WQEs depending on inline settings. 1509 * The number of descriptors should be enough to handle 1510 * the specified number of packets. If queue is being created 1511 * with Verbs the rdma-core does queue size adjustment 1512 * internally in the mlx5_calc_sq_size(), we do the same 1513 * for the queue being created with DevX at this point. 1514 */ 1515 wqe_size = txq_data->tso_en ? 1516 RTE_ALIGN(txq_ctrl->max_tso_header, MLX5_WSEG_SIZE) : 0; 1517 wqe_size += sizeof(struct mlx5_wqe_cseg) + 1518 sizeof(struct mlx5_wqe_eseg) + 1519 sizeof(struct mlx5_wqe_dseg); 1520 if (txq_data->inlen_send) 1521 wqe_size = RTE_MAX(wqe_size, sizeof(struct mlx5_wqe_cseg) + 1522 sizeof(struct mlx5_wqe_eseg) + 1523 RTE_ALIGN(txq_data->inlen_send + 1524 sizeof(uint32_t), 1525 MLX5_WSEG_SIZE)); 1526 wqe_size = RTE_ALIGN(wqe_size, MLX5_WQE_SIZE) / MLX5_WQE_SIZE; 1527 /* Create Send Queue object with DevX. */ 1528 wqe_n = RTE_MIN((1UL << txq_data->elts_n) * wqe_size, 1529 (uint32_t)priv->sh->dev_cap.max_qp_wr); 1530 log_desc_n = log2above(wqe_n); 1531 ret = mlx5_txq_create_devx_sq_resources(dev, idx, log_desc_n); 1532 if (ret) { 1533 DRV_LOG(ERR, "Port %u Tx queue %u SQ creation failure.", 1534 dev->data->port_id, idx); 1535 rte_errno = errno; 1536 goto error; 1537 } 1538 /* Create the Work Queue. */ 1539 txq_data->wqe_n = log_desc_n; 1540 txq_data->wqe_s = 1 << txq_data->wqe_n; 1541 txq_data->wqe_m = txq_data->wqe_s - 1; 1542 txq_data->wqes = (struct mlx5_wqe *)(uintptr_t)txq_obj->sq_obj.wqes; 1543 txq_data->wqes_end = txq_data->wqes + txq_data->wqe_s; 1544 txq_data->wqe_ci = 0; 1545 txq_data->wqe_pi = 0; 1546 txq_data->wqe_comp = 0; 1547 txq_data->wqe_thres = txq_data->wqe_s / MLX5_TX_COMP_THRESH_INLINE_DIV; 1548 txq_data->qp_db = &txq_obj->sq_obj.db_rec[MLX5_SND_DBR]; 1549 *txq_data->qp_db = 0; 1550 txq_data->qp_num_8s = txq_obj->sq_obj.sq->id << 8; 1551 txq_data->db_heu = sh->cdev->config.dbnc == MLX5_SQ_DB_HEURISTIC; 1552 txq_data->db_nc = sh->tx_uar.dbnc; 1553 txq_data->wait_on_time = !!(!sh->config.tx_pp && 1554 sh->cdev->config.hca_attr.wait_on_time); 1555 /* Change Send Queue state to Ready-to-Send. */ 1556 ret = mlx5_txq_devx_modify(txq_obj, MLX5_TXQ_MOD_RST2RDY, 0); 1557 if (ret) { 1558 rte_errno = errno; 1559 DRV_LOG(ERR, 1560 "Port %u Tx queue %u SQ state to SQC_STATE_RDY failed.", 1561 dev->data->port_id, idx); 1562 goto error; 1563 } 1564 #ifdef HAVE_IBV_FLOW_DV_SUPPORT 1565 /* 1566 * If using DevX need to query and store TIS transport domain value. 1567 * This is done once per port. 1568 * Will use this value on Rx, when creating matching TIR. 1569 */ 1570 if (!priv->sh->tdn) 1571 priv->sh->tdn = priv->sh->td->id; 1572 #endif 1573 txq_ctrl->uar_mmap_offset = 1574 mlx5_os_get_devx_uar_mmap_offset(sh->tx_uar.obj); 1575 ppriv->uar_table[txq_data->idx] = sh->tx_uar.bf_db; 1576 dev->data->tx_queue_state[idx] = RTE_ETH_QUEUE_STATE_STARTED; 1577 return 0; 1578 error: 1579 ret = rte_errno; /* Save rte_errno before cleanup. */ 1580 mlx5_txq_release_devx_resources(txq_obj); 1581 rte_errno = ret; /* Restore rte_errno. */ 1582 return -rte_errno; 1583 #endif 1584 } 1585 1586 /** 1587 * Release an Tx DevX queue object. 1588 * 1589 * @param txq_obj 1590 * DevX Tx queue object. 1591 */ 1592 void 1593 mlx5_txq_devx_obj_release(struct mlx5_txq_obj *txq_obj) 1594 { 1595 MLX5_ASSERT(txq_obj); 1596 if (txq_obj->txq_ctrl->is_hairpin) { 1597 if (txq_obj->sq) { 1598 claim_zero(mlx5_devx_cmd_destroy(txq_obj->sq)); 1599 txq_obj->sq = NULL; 1600 } 1601 if (txq_obj->tis) 1602 claim_zero(mlx5_devx_cmd_destroy(txq_obj->tis)); 1603 if (txq_obj->umem_obj_wq_buffer) { 1604 claim_zero(mlx5_os_umem_dereg(txq_obj->umem_obj_wq_buffer)); 1605 txq_obj->umem_obj_wq_buffer = NULL; 1606 } 1607 if (txq_obj->umem_buf_wq_buffer) { 1608 mlx5_free(txq_obj->umem_buf_wq_buffer); 1609 txq_obj->umem_buf_wq_buffer = NULL; 1610 } 1611 #if defined(HAVE_MLX5DV_DEVX_UAR_OFFSET) || !defined(HAVE_INFINIBAND_VERBS_H) 1612 } else { 1613 mlx5_txq_release_devx_resources(txq_obj); 1614 #endif 1615 } 1616 } 1617 1618 struct mlx5_obj_ops devx_obj_ops = { 1619 .rxq_obj_modify_vlan_strip = mlx5_rxq_obj_modify_rq_vlan_strip, 1620 .rxq_obj_new = mlx5_rxq_devx_obj_new, 1621 .rxq_event_get = mlx5_rx_devx_get_event, 1622 .rxq_obj_modify = mlx5_devx_modify_rq, 1623 .rxq_obj_release = mlx5_rxq_devx_obj_release, 1624 .rxq_event_get_lwm = mlx5_rx_devx_get_event_lwm, 1625 .ind_table_new = mlx5_devx_ind_table_new, 1626 .ind_table_modify = mlx5_devx_ind_table_modify, 1627 .ind_table_destroy = mlx5_devx_ind_table_destroy, 1628 .hrxq_new = mlx5_devx_hrxq_new, 1629 .hrxq_destroy = mlx5_devx_tir_destroy, 1630 .hrxq_modify = mlx5_devx_hrxq_modify, 1631 .drop_action_create = mlx5_devx_drop_action_create, 1632 .drop_action_destroy = mlx5_devx_drop_action_destroy, 1633 .txq_obj_new = mlx5_txq_devx_obj_new, 1634 .txq_obj_modify = mlx5_txq_devx_modify, 1635 .txq_obj_release = mlx5_txq_devx_obj_release, 1636 .lb_dummy_queue_create = NULL, 1637 .lb_dummy_queue_release = NULL, 1638 }; 1639