* Initialize the counters management structure. * * @param[in] sh * Pointer to mlx5_dev_ctx_shared object to free * * @return * 0 on success, otherwise negative errno value and rte_errno is set. */
| 573 | * 0 on success, otherwise negative errno value and rte_errno is set. |
| 574 | */ |
| 575 | static int |
| 576 | mlx5_flow_counters_mng_init(struct mlx5_dev_ctx_shared *sh) |
| 577 | { |
| 578 | int i, j; |
| 579 | |
| 580 | if (sh->config.dv_flow_en < 2) { |
| 581 | void *pools; |
| 582 | |
| 583 | pools = mlx5_malloc(MLX5_MEM_ZERO, |
| 584 | sizeof(struct mlx5_flow_counter_pool *) * |
| 585 | MLX5_COUNTER_POOLS_MAX_NUM, |
| 586 | 0, SOCKET_ID_ANY); |
| 587 | if (!pools) { |
| 588 | DRV_LOG(ERR, |
| 589 | "Counter management allocation was failed."); |
| 590 | rte_errno = ENOMEM; |
| 591 | return -rte_errno; |
| 592 | } |
| 593 | memset(&sh->sws_cmng, 0, sizeof(sh->sws_cmng)); |
| 594 | TAILQ_INIT(&sh->sws_cmng.flow_counters); |
| 595 | sh->sws_cmng.min_id = MLX5_CNT_BATCH_OFFSET; |
| 596 | sh->sws_cmng.max_id = -1; |
| 597 | sh->sws_cmng.last_pool_idx = POOL_IDX_INVALID; |
| 598 | sh->sws_cmng.pools = pools; |
| 599 | rte_spinlock_init(&sh->sws_cmng.pool_update_sl); |
| 600 | for (i = 0; i < MLX5_COUNTER_TYPE_MAX; i++) { |
| 601 | TAILQ_INIT(&sh->sws_cmng.counters[i]); |
| 602 | rte_spinlock_init(&sh->sws_cmng.csl[i]); |
| 603 | } |
| 604 | } else { |
| 605 | struct mlx5_hca_attr *attr = &sh->cdev->config.hca_attr; |
| 606 | uint32_t fw_max_nb_cnts = attr->max_flow_counter; |
| 607 | uint8_t log_dcs = log2above(fw_max_nb_cnts) - 1; |
| 608 | uint32_t max_nb_cnts = 0; |
| 609 | |
| 610 | for (i = 0, j = 0; j < MLX5_HWS_CNT_DCS_NUM; ++i) { |
| 611 | int log_dcs_i = log_dcs - i; |
| 612 | |
| 613 | if (log_dcs_i < 0) |
| 614 | break; |
| 615 | if ((max_nb_cnts | RTE_BIT32(log_dcs_i)) > |
| 616 | fw_max_nb_cnts) |
| 617 | continue; |
| 618 | max_nb_cnts |= RTE_BIT32(log_dcs_i); |
| 619 | j++; |
| 620 | } |
| 621 | sh->hws_max_log_bulk_sz = log_dcs; |
| 622 | sh->hws_max_nb_counters = max_nb_cnts; |
| 623 | } |
| 624 | return 0; |
| 625 | } |
| 626 | |
| 627 | /** |
| 628 | * Destroy all the resources allocated for a counter memory management. |
no test coverage detected