| 1619 | } |
| 1620 | |
| 1621 | int |
| 1622 | rte_acl_build(struct rte_acl_ctx *ctx, const struct rte_acl_config *cfg) |
| 1623 | { |
| 1624 | int32_t rc; |
| 1625 | uint32_t n; |
| 1626 | size_t max_size; |
| 1627 | struct acl_build_context bcx; |
| 1628 | |
| 1629 | rc = acl_check_bld_param(ctx, cfg); |
| 1630 | if (rc != 0) |
| 1631 | return rc; |
| 1632 | |
| 1633 | acl_build_reset(ctx); |
| 1634 | |
| 1635 | if (cfg->max_size == 0) { |
| 1636 | n = NODE_MIN; |
| 1637 | max_size = SIZE_MAX; |
| 1638 | } else { |
| 1639 | n = NODE_MAX; |
| 1640 | max_size = cfg->max_size; |
| 1641 | } |
| 1642 | |
| 1643 | for (rc = -ERANGE; n >= NODE_MIN && rc == -ERANGE; n /= 2) { |
| 1644 | |
| 1645 | /* perform build phase. */ |
| 1646 | rc = acl_bld(&bcx, ctx, cfg, n); |
| 1647 | |
| 1648 | if (rc == 0) { |
| 1649 | /* allocate and fill run-time structures. */ |
| 1650 | rc = rte_acl_gen(ctx, bcx.tries, bcx.bld_tries, |
| 1651 | bcx.num_tries, bcx.cfg.num_categories, |
| 1652 | ACL_MAX_INDEXES * RTE_DIM(bcx.tries) * |
| 1653 | sizeof(ctx->data_indexes[0]), max_size); |
| 1654 | if (rc == 0) { |
| 1655 | /* set data indexes. */ |
| 1656 | acl_set_data_indexes(ctx); |
| 1657 | |
| 1658 | /* determine can we always do 4B load */ |
| 1659 | ctx->first_load_sz = get_first_load_size(cfg); |
| 1660 | |
| 1661 | /* copy in build config. */ |
| 1662 | ctx->config = *cfg; |
| 1663 | } |
| 1664 | } |
| 1665 | |
| 1666 | acl_build_log(&bcx); |
| 1667 | |
| 1668 | /* cleanup after build. */ |
| 1669 | tb_free_pool(&bcx.pool); |
| 1670 | } |
| 1671 | |
| 1672 | return rc; |
| 1673 | } |