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
);
190 struct softnic_table_action_profile
*
191 softnic_table_action_profile_find(struct pmd_internals
*p
,
194 struct softnic_table_action_profile
*profile
;
199 TAILQ_FOREACH(profile
, &p
->table_action_profile_list
, node
)
200 if (strcmp(profile
->name
, name
) == 0)
206 struct softnic_table_action_profile
*
207 softnic_table_action_profile_create(struct pmd_internals
*p
,
209 struct softnic_table_action_profile_params
*params
)
211 struct softnic_table_action_profile
*profile
;
212 struct rte_table_action_profile
*ap
;
215 /* Check input params */
217 softnic_table_action_profile_find(p
, name
) ||
219 ((params
->action_mask
& (1LLU << RTE_TABLE_ACTION_FWD
)) == 0))
222 if ((params
->action_mask
& (1LLU << RTE_TABLE_ACTION_LB
)) &&
223 params
->lb
.f_hash
== NULL
) {
224 switch (params
->lb
.key_size
) {
226 params
->lb
.f_hash
= rte_table_hash_crc_key8
;
230 params
->lb
.f_hash
= rte_table_hash_crc_key16
;
234 params
->lb
.f_hash
= rte_table_hash_crc_key24
;
238 params
->lb
.f_hash
= rte_table_hash_crc_key32
;
242 params
->lb
.f_hash
= rte_table_hash_crc_key40
;
246 params
->lb
.f_hash
= rte_table_hash_crc_key48
;
250 params
->lb
.f_hash
= rte_table_hash_crc_key56
;
254 params
->lb
.f_hash
= rte_table_hash_crc_key64
;
265 ap
= rte_table_action_profile_create(¶ms
->common
);
269 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_FWD
)) {
270 status
= rte_table_action_profile_action_register(ap
,
271 RTE_TABLE_ACTION_FWD
,
275 rte_table_action_profile_free(ap
);
280 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_LB
)) {
281 status
= rte_table_action_profile_action_register(ap
,
286 rte_table_action_profile_free(ap
);
291 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_MTR
)) {
292 status
= rte_table_action_profile_action_register(ap
,
293 RTE_TABLE_ACTION_MTR
,
297 rte_table_action_profile_free(ap
);
302 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_TM
)) {
303 status
= rte_table_action_profile_action_register(ap
,
308 rte_table_action_profile_free(ap
);
313 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_ENCAP
)) {
314 status
= rte_table_action_profile_action_register(ap
,
315 RTE_TABLE_ACTION_ENCAP
,
319 rte_table_action_profile_free(ap
);
324 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_NAT
)) {
325 status
= rte_table_action_profile_action_register(ap
,
326 RTE_TABLE_ACTION_NAT
,
330 rte_table_action_profile_free(ap
);
335 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_TTL
)) {
336 status
= rte_table_action_profile_action_register(ap
,
337 RTE_TABLE_ACTION_TTL
,
341 rte_table_action_profile_free(ap
);
346 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_STATS
)) {
347 status
= rte_table_action_profile_action_register(ap
,
348 RTE_TABLE_ACTION_STATS
,
352 rte_table_action_profile_free(ap
);
356 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_TIME
)) {
357 status
= rte_table_action_profile_action_register(ap
,
358 RTE_TABLE_ACTION_TIME
,
362 rte_table_action_profile_free(ap
);
367 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_TAG
)) {
368 status
= rte_table_action_profile_action_register(ap
,
369 RTE_TABLE_ACTION_TAG
,
373 rte_table_action_profile_free(ap
);
378 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_DECAP
)) {
379 status
= rte_table_action_profile_action_register(ap
,
380 RTE_TABLE_ACTION_DECAP
,
384 rte_table_action_profile_free(ap
);
389 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_SYM_CRYPTO
)) {
390 status
= rte_table_action_profile_action_register(ap
,
391 RTE_TABLE_ACTION_SYM_CRYPTO
,
392 ¶ms
->sym_crypto
);
395 rte_table_action_profile_free(ap
);
400 status
= rte_table_action_profile_freeze(ap
);
402 rte_table_action_profile_free(ap
);
406 /* Node allocation */
407 profile
= calloc(1, sizeof(struct softnic_table_action_profile
));
408 if (profile
== NULL
) {
409 rte_table_action_profile_free(ap
);
414 strlcpy(profile
->name
, name
, sizeof(profile
->name
));
415 memcpy(&profile
->params
, params
, sizeof(*params
));
418 /* Node add to list */
419 TAILQ_INSERT_TAIL(&p
->table_action_profile_list
, profile
, node
);