1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
10 #include "hash_func.h"
15 static struct port_in_action_profile_list port_in_action_profile_list;
18 port_in_action_profile_init(void)
20 TAILQ_INIT(&port_in_action_profile_list);
25 struct port_in_action_profile *
26 port_in_action_profile_find(const char *name)
28 struct port_in_action_profile *profile;
33 TAILQ_FOREACH(profile, &port_in_action_profile_list, node)
34 if (strcmp(profile->name, name) == 0)
40 struct port_in_action_profile *
41 port_in_action_profile_create(const char *name,
42 struct port_in_action_profile_params *params)
44 struct port_in_action_profile *profile;
45 struct rte_port_in_action_profile *ap;
48 /* Check input params */
50 port_in_action_profile_find(name) ||
54 if ((params->action_mask & (1LLU << RTE_PORT_IN_ACTION_LB)) &&
55 (params->lb.f_hash == NULL)) {
56 switch (params->lb.key_size) {
58 params->lb.f_hash = hash_default_key8;
62 params->lb.f_hash = hash_default_key16;
66 params->lb.f_hash = hash_default_key24;
70 params->lb.f_hash = hash_default_key32;
74 params->lb.f_hash = hash_default_key40;
78 params->lb.f_hash = hash_default_key48;
82 params->lb.f_hash = hash_default_key56;
86 params->lb.f_hash = hash_default_key64;
96 ap = rte_port_in_action_profile_create(0);
100 if (params->action_mask & (1LLU << RTE_PORT_IN_ACTION_FLTR)) {
101 status = rte_port_in_action_profile_action_register(ap,
102 RTE_PORT_IN_ACTION_FLTR,
106 rte_port_in_action_profile_free(ap);
111 if (params->action_mask & (1LLU << RTE_PORT_IN_ACTION_LB)) {
112 status = rte_port_in_action_profile_action_register(ap,
113 RTE_PORT_IN_ACTION_LB,
117 rte_port_in_action_profile_free(ap);
122 status = rte_port_in_action_profile_freeze(ap);
124 rte_port_in_action_profile_free(ap);
128 /* Node allocation */
129 profile = calloc(1, sizeof(struct port_in_action_profile));
130 if (profile == NULL) {
131 rte_port_in_action_profile_free(ap);
136 strncpy(profile->name, name, sizeof(profile->name));
137 memcpy(&profile->params, params, sizeof(*params));
140 /* Node add to list */
141 TAILQ_INSERT_TAIL(&port_in_action_profile_list, profile, node);
149 static struct table_action_profile_list table_action_profile_list;
152 table_action_profile_init(void)
154 TAILQ_INIT(&table_action_profile_list);
159 struct table_action_profile *
160 table_action_profile_find(const char *name)
162 struct table_action_profile *profile;
167 TAILQ_FOREACH(profile, &table_action_profile_list, node)
168 if (strcmp(profile->name, name) == 0)
174 struct table_action_profile *
175 table_action_profile_create(const char *name,
176 struct table_action_profile_params *params)
178 struct table_action_profile *profile;
179 struct rte_table_action_profile *ap;
182 /* Check input params */
183 if ((name == NULL) ||
184 table_action_profile_find(name) ||
186 ((params->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) == 0))
189 if ((params->action_mask & (1LLU << RTE_TABLE_ACTION_LB)) &&
190 (params->lb.f_hash == NULL)) {
191 switch (params->lb.key_size) {
193 params->lb.f_hash = hash_default_key8;
197 params->lb.f_hash = hash_default_key16;
201 params->lb.f_hash = hash_default_key24;
205 params->lb.f_hash = hash_default_key32;
209 params->lb.f_hash = hash_default_key40;
213 params->lb.f_hash = hash_default_key48;
217 params->lb.f_hash = hash_default_key56;
221 params->lb.f_hash = hash_default_key64;
232 ap = rte_table_action_profile_create(¶ms->common);
236 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) {
237 status = rte_table_action_profile_action_register(ap,
238 RTE_TABLE_ACTION_FWD,
242 rte_table_action_profile_free(ap);
247 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_LB)) {
248 status = rte_table_action_profile_action_register(ap,
253 rte_table_action_profile_free(ap);
258 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
259 status = rte_table_action_profile_action_register(ap,
260 RTE_TABLE_ACTION_MTR,
264 rte_table_action_profile_free(ap);
269 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_TM)) {
270 status = rte_table_action_profile_action_register(ap,
275 rte_table_action_profile_free(ap);
280 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
281 status = rte_table_action_profile_action_register(ap,
282 RTE_TABLE_ACTION_ENCAP,
286 rte_table_action_profile_free(ap);
291 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
292 status = rte_table_action_profile_action_register(ap,
293 RTE_TABLE_ACTION_NAT,
297 rte_table_action_profile_free(ap);
302 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_TTL)) {
303 status = rte_table_action_profile_action_register(ap,
304 RTE_TABLE_ACTION_TTL,
308 rte_table_action_profile_free(ap);
313 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_STATS)) {
314 status = rte_table_action_profile_action_register(ap,
315 RTE_TABLE_ACTION_STATS,
319 rte_table_action_profile_free(ap);
323 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_TIME)) {
324 status = rte_table_action_profile_action_register(ap,
325 RTE_TABLE_ACTION_TIME,
329 rte_table_action_profile_free(ap);
334 status = rte_table_action_profile_freeze(ap);
336 rte_table_action_profile_free(ap);
340 /* Node allocation */
341 profile = calloc(1, sizeof(struct table_action_profile));
342 if (profile == NULL) {
343 rte_table_action_profile_free(ap);
348 strncpy(profile->name, name, sizeof(profile->name));
349 memcpy(&profile->params, params, sizeof(*params));
352 /* Node add to list */
353 TAILQ_INSERT_TAIL(&table_action_profile_list, profile, node);