* Generate the runtime structure using build structure */
| 445 | * Generate the runtime structure using build structure |
| 446 | */ |
| 447 | int |
| 448 | rte_acl_gen(struct rte_acl_ctx *ctx, struct rte_acl_trie *trie, |
| 449 | struct rte_acl_bld_trie *node_bld_trie, uint32_t num_tries, |
| 450 | uint32_t num_categories, uint32_t data_index_sz, size_t max_size) |
| 451 | { |
| 452 | void *mem; |
| 453 | size_t total_size; |
| 454 | uint64_t *node_array, no_match; |
| 455 | uint32_t n, match_index; |
| 456 | struct rte_acl_match_results *match; |
| 457 | struct acl_node_counters counts; |
| 458 | struct rte_acl_indices indices; |
| 459 | |
| 460 | no_match = RTE_ACL_NODE_MATCH; |
| 461 | |
| 462 | /* Fill counts and indices arrays from the nodes. */ |
| 463 | acl_calc_counts_indices(&counts, &indices, |
| 464 | node_bld_trie, num_tries, no_match); |
| 465 | |
| 466 | /* Allocate runtime memory (align to cache boundary) */ |
| 467 | total_size = RTE_ALIGN(data_index_sz, RTE_CACHE_LINE_SIZE) + |
| 468 | indices.match_start * sizeof(uint64_t) + |
| 469 | (counts.match + 1) * sizeof(struct rte_acl_match_results) + |
| 470 | XMM_SIZE; |
| 471 | |
| 472 | if (total_size > max_size) { |
| 473 | RTE_LOG(DEBUG, ACL, |
| 474 | "Gen phase for ACL ctx \"%s\" exceeds max_size limit, " |
| 475 | "bytes required: %zu, allowed: %zu\n", |
| 476 | ctx->name, total_size, max_size); |
| 477 | return -ERANGE; |
| 478 | } |
| 479 | |
| 480 | mem = rte_zmalloc_socket(ctx->name, total_size, RTE_CACHE_LINE_SIZE, |
| 481 | ctx->socket_id); |
| 482 | if (mem == NULL) { |
| 483 | RTE_LOG(ERR, ACL, |
| 484 | "allocation of %zu bytes on socket %d for %s failed\n", |
| 485 | total_size, ctx->socket_id, ctx->name); |
| 486 | return -ENOMEM; |
| 487 | } |
| 488 | |
| 489 | /* Fill the runtime structure */ |
| 490 | match_index = indices.match_start; |
| 491 | node_array = (uint64_t *)((uintptr_t)mem + |
| 492 | RTE_ALIGN(data_index_sz, RTE_CACHE_LINE_SIZE)); |
| 493 | |
| 494 | /* |
| 495 | * Setup the NOMATCH node (a SINGLE at the |
| 496 | * highest index, that points to itself) |
| 497 | */ |
| 498 | |
| 499 | node_array[RTE_ACL_DFA_SIZE] = RTE_ACL_IDLE_NODE; |
| 500 | |
| 501 | for (n = 0; n < RTE_ACL_DFA_SIZE; n++) |
| 502 | node_array[n] = no_match; |
| 503 | |
| 504 | /* NOMATCH result at index 0 */ |
no test coverage detected