| 581 | } |
| 582 | |
| 583 | void |
| 584 | mlx5_ipool_free(struct mlx5_indexed_pool *pool, uint32_t idx) |
| 585 | { |
| 586 | struct mlx5_indexed_trunk *trunk; |
| 587 | uint32_t trunk_idx; |
| 588 | uint32_t entry_idx; |
| 589 | |
| 590 | if (!idx) |
| 591 | return; |
| 592 | if (pool->cfg.per_core_cache) { |
| 593 | mlx5_ipool_free_cache(pool, idx); |
| 594 | return; |
| 595 | } |
| 596 | idx -= 1; |
| 597 | mlx5_ipool_lock(pool); |
| 598 | trunk_idx = mlx5_trunk_idx_get(pool, idx); |
| 599 | if ((!pool->cfg.release_mem_en && trunk_idx >= pool->n_trunk_valid) || |
| 600 | (pool->cfg.release_mem_en && trunk_idx >= pool->n_trunk)) |
| 601 | goto out; |
| 602 | trunk = pool->trunks[trunk_idx]; |
| 603 | if (!trunk) |
| 604 | goto out; |
| 605 | entry_idx = idx - mlx5_trunk_idx_offset_get(pool, trunk->idx); |
| 606 | if (trunk_idx != trunk->idx || |
| 607 | rte_bitmap_get(trunk->bmp, entry_idx)) |
| 608 | goto out; |
| 609 | rte_bitmap_set(trunk->bmp, entry_idx); |
| 610 | trunk->free++; |
| 611 | if (pool->cfg.release_mem_en && trunk->free == mlx5_trunk_size_get |
| 612 | (pool, trunk->idx)) { |
| 613 | if (pool->free_list == trunk->idx) |
| 614 | pool->free_list = trunk->next; |
| 615 | if (trunk->next != TRUNK_INVALID) |
| 616 | pool->trunks[trunk->next]->prev = trunk->prev; |
| 617 | if (trunk->prev != TRUNK_INVALID) |
| 618 | pool->trunks[trunk->prev]->next = trunk->next; |
| 619 | pool->cfg.free(trunk); |
| 620 | pool->trunks[trunk_idx] = NULL; |
| 621 | pool->n_trunk_valid--; |
| 622 | #ifdef POOL_DEBUG |
| 623 | pool->trunk_avail--; |
| 624 | pool->trunk_free++; |
| 625 | #endif |
| 626 | if (pool->n_trunk_valid == 0) { |
| 627 | pool->cfg.free(pool->trunks); |
| 628 | pool->trunks = NULL; |
| 629 | pool->n_trunk = 0; |
| 630 | } |
| 631 | } else if (trunk->free == 1) { |
| 632 | /* Put into free trunk list head. */ |
| 633 | MLX5_ASSERT(pool->free_list != trunk->idx); |
| 634 | trunk->next = pool->free_list; |
| 635 | trunk->prev = TRUNK_INVALID; |
| 636 | if (pool->free_list != TRUNK_INVALID) |
| 637 | pool->trunks[pool->free_list]->prev = trunk->idx; |
| 638 | pool->free_list = trunk->idx; |
| 639 | #ifdef POOL_DEBUG |
| 640 | pool->trunk_empty--; |
no test coverage detected