1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
7 #include <rte_string_fns.h>
9 #include <rte_eal_memconfig.h>
10 #include <rte_memory.h>
11 #include <rte_malloc.h>
12 #include <rte_errno.h>
13 #include <rte_tailq.h>
15 #include "rte_member.h"
16 #include "rte_member_ht.h"
17 #include "rte_member_vbf.h"
19 TAILQ_HEAD(rte_member_list, rte_tailq_entry);
20 static struct rte_tailq_elem rte_member_tailq = {
23 EAL_REGISTER_TAILQ(rte_member_tailq)
25 struct rte_member_setsum *
26 rte_member_find_existing(const char *name)
28 struct rte_member_setsum *setsum = NULL;
29 struct rte_tailq_entry *te;
30 struct rte_member_list *member_list;
32 member_list = RTE_TAILQ_CAST(rte_member_tailq.head, rte_member_list);
34 rte_mcfg_tailq_read_lock();
35 TAILQ_FOREACH(te, member_list, next) {
36 setsum = (struct rte_member_setsum *) te->data;
37 if (strncmp(name, setsum->name, RTE_MEMBER_NAMESIZE) == 0)
40 rte_mcfg_tailq_read_unlock();
50 rte_member_free(struct rte_member_setsum *setsum)
52 struct rte_member_list *member_list;
53 struct rte_tailq_entry *te;
57 member_list = RTE_TAILQ_CAST(rte_member_tailq.head, rte_member_list);
58 rte_mcfg_tailq_write_lock();
59 TAILQ_FOREACH(te, member_list, next) {
60 if (te->data == (void *)setsum)
64 rte_mcfg_tailq_write_unlock();
67 TAILQ_REMOVE(member_list, te, next);
68 rte_mcfg_tailq_write_unlock();
70 switch (setsum->type) {
71 case RTE_MEMBER_TYPE_HT:
72 rte_member_free_ht(setsum);
74 case RTE_MEMBER_TYPE_VBF:
75 rte_member_free_vbf(setsum);
84 struct rte_member_setsum *
85 rte_member_create(const struct rte_member_parameters *params)
87 struct rte_tailq_entry *te;
88 struct rte_member_list *member_list;
89 struct rte_member_setsum *setsum;
97 if (params->key_len == 0 ||
98 params->prim_hash_seed == params->sec_hash_seed) {
100 RTE_MEMBER_LOG(ERR, "Create setsummary with "
101 "invalid parameters\n");
105 member_list = RTE_TAILQ_CAST(rte_member_tailq.head, rte_member_list);
107 rte_mcfg_tailq_write_lock();
109 TAILQ_FOREACH(te, member_list, next) {
111 if (strncmp(params->name, setsum->name,
112 RTE_MEMBER_NAMESIZE) == 0)
119 goto error_unlock_exit;
121 te = rte_zmalloc("MEMBER_TAILQ_ENTRY", sizeof(*te), 0);
123 RTE_MEMBER_LOG(ERR, "tailq entry allocation failed\n");
124 goto error_unlock_exit;
127 /* Create a new setsum structure */
128 setsum = rte_zmalloc_socket(params->name,
129 sizeof(struct rte_member_setsum), RTE_CACHE_LINE_SIZE,
131 if (setsum == NULL) {
132 RTE_MEMBER_LOG(ERR, "Create setsummary failed\n");
133 goto error_unlock_exit;
135 strlcpy(setsum->name, params->name, sizeof(setsum->name));
136 setsum->type = params->type;
137 setsum->socket_id = params->socket_id;
138 setsum->key_len = params->key_len;
139 setsum->num_set = params->num_set;
140 setsum->prim_hash_seed = params->prim_hash_seed;
141 setsum->sec_hash_seed = params->sec_hash_seed;
143 switch (setsum->type) {
144 case RTE_MEMBER_TYPE_HT:
145 ret = rte_member_create_ht(setsum, params);
147 case RTE_MEMBER_TYPE_VBF:
148 ret = rte_member_create_vbf(setsum, params);
151 goto error_unlock_exit;
154 goto error_unlock_exit;
156 RTE_MEMBER_LOG(DEBUG, "Creating a setsummary table with "
157 "mode %u\n", setsum->type);
159 te->data = (void *)setsum;
160 TAILQ_INSERT_TAIL(member_list, te, next);
161 rte_mcfg_tailq_write_unlock();
167 rte_mcfg_tailq_write_unlock();
172 rte_member_add(const struct rte_member_setsum *setsum, const void *key,
175 if (setsum == NULL || key == NULL)
178 switch (setsum->type) {
179 case RTE_MEMBER_TYPE_HT:
180 return rte_member_add_ht(setsum, key, set_id);
181 case RTE_MEMBER_TYPE_VBF:
182 return rte_member_add_vbf(setsum, key, set_id);
189 rte_member_lookup(const struct rte_member_setsum *setsum, const void *key,
190 member_set_t *set_id)
192 if (setsum == NULL || key == NULL || set_id == NULL)
195 switch (setsum->type) {
196 case RTE_MEMBER_TYPE_HT:
197 return rte_member_lookup_ht(setsum, key, set_id);
198 case RTE_MEMBER_TYPE_VBF:
199 return rte_member_lookup_vbf(setsum, key, set_id);
206 rte_member_lookup_bulk(const struct rte_member_setsum *setsum,
207 const void **keys, uint32_t num_keys,
208 member_set_t *set_ids)
210 if (setsum == NULL || keys == NULL || set_ids == NULL)
213 switch (setsum->type) {
214 case RTE_MEMBER_TYPE_HT:
215 return rte_member_lookup_bulk_ht(setsum, keys, num_keys,
217 case RTE_MEMBER_TYPE_VBF:
218 return rte_member_lookup_bulk_vbf(setsum, keys, num_keys,
226 rte_member_lookup_multi(const struct rte_member_setsum *setsum, const void *key,
227 uint32_t match_per_key, member_set_t *set_id)
229 if (setsum == NULL || key == NULL || set_id == NULL)
232 switch (setsum->type) {
233 case RTE_MEMBER_TYPE_HT:
234 return rte_member_lookup_multi_ht(setsum, key, match_per_key,
236 case RTE_MEMBER_TYPE_VBF:
237 return rte_member_lookup_multi_vbf(setsum, key, match_per_key,
245 rte_member_lookup_multi_bulk(const struct rte_member_setsum *setsum,
246 const void **keys, uint32_t num_keys,
247 uint32_t max_match_per_key, uint32_t *match_count,
248 member_set_t *set_ids)
250 if (setsum == NULL || keys == NULL || set_ids == NULL ||
254 switch (setsum->type) {
255 case RTE_MEMBER_TYPE_HT:
256 return rte_member_lookup_multi_bulk_ht(setsum, keys, num_keys,
257 max_match_per_key, match_count, set_ids);
258 case RTE_MEMBER_TYPE_VBF:
259 return rte_member_lookup_multi_bulk_vbf(setsum, keys, num_keys,
260 max_match_per_key, match_count, set_ids);
267 rte_member_delete(const struct rte_member_setsum *setsum, const void *key,
270 if (setsum == NULL || key == NULL)
273 switch (setsum->type) {
274 case RTE_MEMBER_TYPE_HT:
275 return rte_member_delete_ht(setsum, key, set_id);
276 /* current vBF implementation does not support delete function */
277 case RTE_MEMBER_TYPE_VBF:
284 rte_member_reset(const struct rte_member_setsum *setsum)
288 switch (setsum->type) {
289 case RTE_MEMBER_TYPE_HT:
290 rte_member_reset_ht(setsum);
292 case RTE_MEMBER_TYPE_VBF:
293 rte_member_reset_vbf(setsum);
300 RTE_LOG_REGISTER(librte_member_logtype, lib.member, DEBUG);