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))
190 ap = rte_table_action_profile_create(¶ms->common);
194 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) {
195 status = rte_table_action_profile_action_register(ap,
196 RTE_TABLE_ACTION_FWD,
200 rte_table_action_profile_free(ap);
205 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
206 status = rte_table_action_profile_action_register(ap,
207 RTE_TABLE_ACTION_MTR,
211 rte_table_action_profile_free(ap);
216 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_TM)) {
217 status = rte_table_action_profile_action_register(ap,
222 rte_table_action_profile_free(ap);
227 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
228 status = rte_table_action_profile_action_register(ap,
229 RTE_TABLE_ACTION_ENCAP,
233 rte_table_action_profile_free(ap);
238 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
239 status = rte_table_action_profile_action_register(ap,
240 RTE_TABLE_ACTION_NAT,
244 rte_table_action_profile_free(ap);
249 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_TTL)) {
250 status = rte_table_action_profile_action_register(ap,
251 RTE_TABLE_ACTION_TTL,
255 rte_table_action_profile_free(ap);
260 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_STATS)) {
261 status = rte_table_action_profile_action_register(ap,
262 RTE_TABLE_ACTION_STATS,
266 rte_table_action_profile_free(ap);
270 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_TIME)) {
271 status = rte_table_action_profile_action_register(ap,
272 RTE_TABLE_ACTION_TIME,
276 rte_table_action_profile_free(ap);
281 status = rte_table_action_profile_freeze(ap);
283 rte_table_action_profile_free(ap);
287 /* Node allocation */
288 profile = calloc(1, sizeof(struct table_action_profile));
289 if (profile == NULL) {
290 rte_table_action_profile_free(ap);
295 strncpy(profile->name, name, sizeof(profile->name));
296 memcpy(&profile->params, params, sizeof(*params));
299 /* Node add to list */
300 TAILQ_INSERT_TAIL(&table_action_profile_list, profile, node);