2 * Copyright (c) 2016 Intel Corporation.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #include <rte_malloc.h>
17 #include <rte_errno.h>
19 #include "stream_table.h"
22 stbl_fini(struct stbl *st)
26 for (i = 0; i != RTE_DIM(st->ht); i++) {
27 rte_hash_free(st->ht[i].t);
28 rte_free(st->ht[i].ent);
31 memset(st, 0, sizeof(*st));
35 stbl_init(struct stbl *st, uint32_t num, int32_t socket)
39 struct rte_hash_parameters hprm;
40 char buf[RTE_HASH_NAMESIZE];
42 num = RTE_MAX(5 * num / 4, 0x10U);
44 memset(&hprm, 0, sizeof(hprm));
47 hprm.socket_id = socket;
51 snprintf(buf, sizeof(buf), "stbl4@%p", st);
52 hprm.key_len = sizeof(struct stbl4_key);
53 st->ht[TLE_V4].t = rte_hash_create(&hprm);
54 if (st->ht[TLE_V4].t == NULL)
55 rc = (rte_errno != 0) ? -rte_errno : -ENOMEM;
58 snprintf(buf, sizeof(buf), "stbl6@%p", st);
59 hprm.key_len = sizeof(struct stbl6_key);
60 st->ht[TLE_V6].t = rte_hash_create(&hprm);
61 if (st->ht[TLE_V6].t == NULL)
62 rc = (rte_errno != 0) ? -rte_errno : -ENOMEM;
65 for (i = 0; i != RTE_DIM(st->ht) && rc == 0; i++) {
67 sz = sizeof(*st->ht[i].ent) * num;
68 st->ht[i].ent = rte_zmalloc_socket(NULL, sz,
69 RTE_CACHE_LINE_SIZE, socket);
70 if (st->ht[i].ent == NULL)
73 st->ht[i].nb_ent = num;