1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
9 #include <rte_string_fns.h>
10 #include <rte_table_hash_func.h>
12 #include "rte_eth_softnic_internals.h"
18 softnic_port_in_action_profile_init(struct pmd_internals *p)
20 TAILQ_INIT(&p->port_in_action_profile_list);
26 softnic_port_in_action_profile_free(struct pmd_internals *p)
29 struct softnic_port_in_action_profile *profile;
31 profile = TAILQ_FIRST(&p->port_in_action_profile_list);
35 TAILQ_REMOVE(&p->port_in_action_profile_list, profile, node);
40 struct softnic_port_in_action_profile *
41 softnic_port_in_action_profile_find(struct pmd_internals *p,
44 struct softnic_port_in_action_profile *profile;
49 TAILQ_FOREACH(profile, &p->port_in_action_profile_list, node)
50 if (strcmp(profile->name, name) == 0)
56 struct softnic_port_in_action_profile *
57 softnic_port_in_action_profile_create(struct pmd_internals *p,
59 struct softnic_port_in_action_profile_params *params)
61 struct softnic_port_in_action_profile *profile;
62 struct rte_port_in_action_profile *ap;
65 /* Check input params */
67 softnic_port_in_action_profile_find(p, name) ||
71 if ((params->action_mask & (1LLU << RTE_PORT_IN_ACTION_LB)) &&
72 params->lb.f_hash == NULL) {
73 switch (params->lb.key_size) {
75 params->lb.f_hash = rte_table_hash_crc_key8;
79 params->lb.f_hash = rte_table_hash_crc_key16;
83 params->lb.f_hash = rte_table_hash_crc_key24;
87 params->lb.f_hash = rte_table_hash_crc_key32;
91 params->lb.f_hash = rte_table_hash_crc_key40;
95 params->lb.f_hash = rte_table_hash_crc_key48;
99 params->lb.f_hash = rte_table_hash_crc_key56;
103 params->lb.f_hash = rte_table_hash_crc_key64;
114 ap = rte_port_in_action_profile_create(0);
118 if (params->action_mask & (1LLU << RTE_PORT_IN_ACTION_FLTR)) {
119 status = rte_port_in_action_profile_action_register(ap,
120 RTE_PORT_IN_ACTION_FLTR,
124 rte_port_in_action_profile_free(ap);
129 if (params->action_mask & (1LLU << RTE_PORT_IN_ACTION_LB)) {
130 status = rte_port_in_action_profile_action_register(ap,
131 RTE_PORT_IN_ACTION_LB,
135 rte_port_in_action_profile_free(ap);
140 status = rte_port_in_action_profile_freeze(ap);
142 rte_port_in_action_profile_free(ap);
146 /* Node allocation */
147 profile = calloc(1, sizeof(struct softnic_port_in_action_profile));
148 if (profile == NULL) {
149 rte_port_in_action_profile_free(ap);
154 strlcpy(profile->name, name, sizeof(profile->name));
155 memcpy(&profile->params, params, sizeof(*params));
158 /* Node add to list */
159 TAILQ_INSERT_TAIL(&p->port_in_action_profile_list, profile, node);
168 softnic_table_action_profile_init(struct pmd_internals *p)
170 TAILQ_INIT(&p->table_action_profile_list);
176 softnic_table_action_profile_free(struct pmd_internals *p)
179 struct softnic_table_action_profile *profile;
181 profile = TAILQ_FIRST(&p->table_action_profile_list);
185 TAILQ_REMOVE(&p->table_action_profile_list, profile, node);
186 rte_table_action_profile_free(profile->ap);
191 struct softnic_table_action_profile *
192 softnic_table_action_profile_find(struct pmd_internals *p,
195 struct softnic_table_action_profile *profile;
200 TAILQ_FOREACH(profile, &p->table_action_profile_list, node)
201 if (strcmp(profile->name, name) == 0)
207 struct softnic_table_action_profile *
208 softnic_table_action_profile_create(struct pmd_internals *p,
210 struct softnic_table_action_profile_params *params)
212 struct softnic_table_action_profile *profile;
213 struct rte_table_action_profile *ap;
216 /* Check input params */
218 softnic_table_action_profile_find(p, name) ||
220 ((params->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) == 0))
223 if ((params->action_mask & (1LLU << RTE_TABLE_ACTION_LB)) &&
224 params->lb.f_hash == NULL) {
225 switch (params->lb.key_size) {
227 params->lb.f_hash = rte_table_hash_crc_key8;
231 params->lb.f_hash = rte_table_hash_crc_key16;
235 params->lb.f_hash = rte_table_hash_crc_key24;
239 params->lb.f_hash = rte_table_hash_crc_key32;
243 params->lb.f_hash = rte_table_hash_crc_key40;
247 params->lb.f_hash = rte_table_hash_crc_key48;
251 params->lb.f_hash = rte_table_hash_crc_key56;
255 params->lb.f_hash = rte_table_hash_crc_key64;
266 ap = rte_table_action_profile_create(¶ms->common);
270 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) {
271 status = rte_table_action_profile_action_register(ap,
272 RTE_TABLE_ACTION_FWD,
276 rte_table_action_profile_free(ap);
281 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_LB)) {
282 status = rte_table_action_profile_action_register(ap,
287 rte_table_action_profile_free(ap);
292 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
293 status = rte_table_action_profile_action_register(ap,
294 RTE_TABLE_ACTION_MTR,
298 rte_table_action_profile_free(ap);
303 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_TM)) {
304 status = rte_table_action_profile_action_register(ap,
309 rte_table_action_profile_free(ap);
314 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
315 status = rte_table_action_profile_action_register(ap,
316 RTE_TABLE_ACTION_ENCAP,
320 rte_table_action_profile_free(ap);
325 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
326 status = rte_table_action_profile_action_register(ap,
327 RTE_TABLE_ACTION_NAT,
331 rte_table_action_profile_free(ap);
336 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_TTL)) {
337 status = rte_table_action_profile_action_register(ap,
338 RTE_TABLE_ACTION_TTL,
342 rte_table_action_profile_free(ap);
347 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_STATS)) {
348 status = rte_table_action_profile_action_register(ap,
349 RTE_TABLE_ACTION_STATS,
353 rte_table_action_profile_free(ap);
357 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_TIME)) {
358 status = rte_table_action_profile_action_register(ap,
359 RTE_TABLE_ACTION_TIME,
363 rte_table_action_profile_free(ap);
368 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_TAG)) {
369 status = rte_table_action_profile_action_register(ap,
370 RTE_TABLE_ACTION_TAG,
374 rte_table_action_profile_free(ap);
379 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_DECAP)) {
380 status = rte_table_action_profile_action_register(ap,
381 RTE_TABLE_ACTION_DECAP,
385 rte_table_action_profile_free(ap);
390 if (params->action_mask & (1LLU << RTE_TABLE_ACTION_SYM_CRYPTO)) {
391 status = rte_table_action_profile_action_register(ap,
392 RTE_TABLE_ACTION_SYM_CRYPTO,
393 ¶ms->sym_crypto);
396 rte_table_action_profile_free(ap);
401 status = rte_table_action_profile_freeze(ap);
403 rte_table_action_profile_free(ap);
407 /* Node allocation */
408 profile = calloc(1, sizeof(struct softnic_table_action_profile));
409 if (profile == NULL) {
410 rte_table_action_profile_free(ap);
415 strlcpy(profile->name, name, sizeof(profile->name));
416 memcpy(&profile->params, params, sizeof(*params));
419 /* Node add to list */
420 TAILQ_INSERT_TAIL(&p->table_action_profile_list, profile, node);