| 499 | } |
| 500 | |
| 501 | void * |
| 502 | dir24_8_create(const char *name, int socket_id, struct rte_fib_conf *fib_conf) |
| 503 | { |
| 504 | char mem_name[DIR24_8_NAMESIZE]; |
| 505 | struct dir24_8_tbl *dp; |
| 506 | uint64_t def_nh; |
| 507 | uint32_t num_tbl8; |
| 508 | enum rte_fib_dir24_8_nh_sz nh_sz; |
| 509 | |
| 510 | if ((name == NULL) || (fib_conf == NULL) || |
| 511 | (fib_conf->dir24_8.nh_sz < RTE_FIB_DIR24_8_1B) || |
| 512 | (fib_conf->dir24_8.nh_sz > RTE_FIB_DIR24_8_8B) || |
| 513 | (fib_conf->dir24_8.num_tbl8 > |
| 514 | get_max_nh(fib_conf->dir24_8.nh_sz)) || |
| 515 | (fib_conf->dir24_8.num_tbl8 == 0) || |
| 516 | (fib_conf->default_nh > |
| 517 | get_max_nh(fib_conf->dir24_8.nh_sz))) { |
| 518 | rte_errno = EINVAL; |
| 519 | return NULL; |
| 520 | } |
| 521 | |
| 522 | def_nh = fib_conf->default_nh; |
| 523 | nh_sz = fib_conf->dir24_8.nh_sz; |
| 524 | num_tbl8 = RTE_ALIGN_CEIL(fib_conf->dir24_8.num_tbl8, |
| 525 | BITMAP_SLAB_BIT_SIZE); |
| 526 | |
| 527 | snprintf(mem_name, sizeof(mem_name), "DP_%s", name); |
| 528 | dp = rte_zmalloc_socket(name, sizeof(struct dir24_8_tbl) + |
| 529 | DIR24_8_TBL24_NUM_ENT * (1 << nh_sz) + sizeof(uint32_t), |
| 530 | RTE_CACHE_LINE_SIZE, socket_id); |
| 531 | if (dp == NULL) { |
| 532 | rte_errno = ENOMEM; |
| 533 | return NULL; |
| 534 | } |
| 535 | |
| 536 | /* Init table with default value */ |
| 537 | write_to_fib(dp->tbl24, (def_nh << 1), nh_sz, 1 << 24); |
| 538 | |
| 539 | snprintf(mem_name, sizeof(mem_name), "TBL8_%p", dp); |
| 540 | uint64_t tbl8_sz = DIR24_8_TBL8_GRP_NUM_ENT * (1ULL << nh_sz) * |
| 541 | (num_tbl8 + 1); |
| 542 | dp->tbl8 = rte_zmalloc_socket(mem_name, tbl8_sz, |
| 543 | RTE_CACHE_LINE_SIZE, socket_id); |
| 544 | if (dp->tbl8 == NULL) { |
| 545 | rte_errno = ENOMEM; |
| 546 | rte_free(dp); |
| 547 | return NULL; |
| 548 | } |
| 549 | dp->def_nh = def_nh; |
| 550 | dp->nh_sz = nh_sz; |
| 551 | dp->number_tbl8s = num_tbl8; |
| 552 | |
| 553 | snprintf(mem_name, sizeof(mem_name), "TBL8_idxes_%p", dp); |
| 554 | dp->tbl8_idxes = rte_zmalloc_socket(mem_name, |
| 555 | RTE_ALIGN_CEIL(dp->number_tbl8s, 64) >> 3, |
| 556 | RTE_CACHE_LINE_SIZE, socket_id); |
| 557 | if (dp->tbl8_idxes == NULL) { |
| 558 | rte_errno = ENOMEM; |
no test coverage detected