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>
17 static struct port_in_action_profile_list port_in_action_profile_list
;
20 port_in_action_profile_init(void)
22 TAILQ_INIT(&port_in_action_profile_list
);
27 struct port_in_action_profile
*
28 port_in_action_profile_find(const char *name
)
30 struct port_in_action_profile
*profile
;
35 TAILQ_FOREACH(profile
, &port_in_action_profile_list
, node
)
36 if (strcmp(profile
->name
, name
) == 0)
42 struct port_in_action_profile
*
43 port_in_action_profile_create(const char *name
,
44 struct port_in_action_profile_params
*params
)
46 struct port_in_action_profile
*profile
;
47 struct rte_port_in_action_profile
*ap
;
50 /* Check input params */
52 port_in_action_profile_find(name
) ||
56 if ((params
->action_mask
& (1LLU << RTE_PORT_IN_ACTION_LB
)) &&
57 (params
->lb
.f_hash
== NULL
)) {
58 switch (params
->lb
.key_size
) {
60 params
->lb
.f_hash
= rte_table_hash_crc_key8
;
64 params
->lb
.f_hash
= rte_table_hash_crc_key16
;
68 params
->lb
.f_hash
= rte_table_hash_crc_key24
;
72 params
->lb
.f_hash
= rte_table_hash_crc_key32
;
76 params
->lb
.f_hash
= rte_table_hash_crc_key40
;
80 params
->lb
.f_hash
= rte_table_hash_crc_key48
;
84 params
->lb
.f_hash
= rte_table_hash_crc_key56
;
88 params
->lb
.f_hash
= rte_table_hash_crc_key64
;
98 ap
= rte_port_in_action_profile_create(0);
102 if (params
->action_mask
& (1LLU << RTE_PORT_IN_ACTION_FLTR
)) {
103 status
= rte_port_in_action_profile_action_register(ap
,
104 RTE_PORT_IN_ACTION_FLTR
,
108 rte_port_in_action_profile_free(ap
);
113 if (params
->action_mask
& (1LLU << RTE_PORT_IN_ACTION_LB
)) {
114 status
= rte_port_in_action_profile_action_register(ap
,
115 RTE_PORT_IN_ACTION_LB
,
119 rte_port_in_action_profile_free(ap
);
124 status
= rte_port_in_action_profile_freeze(ap
);
126 rte_port_in_action_profile_free(ap
);
130 /* Node allocation */
131 profile
= calloc(1, sizeof(struct port_in_action_profile
));
132 if (profile
== NULL
) {
133 rte_port_in_action_profile_free(ap
);
138 strlcpy(profile
->name
, name
, sizeof(profile
->name
));
139 memcpy(&profile
->params
, params
, sizeof(*params
));
142 /* Node add to list */
143 TAILQ_INSERT_TAIL(&port_in_action_profile_list
, profile
, node
);
151 static struct table_action_profile_list table_action_profile_list
;
154 table_action_profile_init(void)
156 TAILQ_INIT(&table_action_profile_list
);
161 struct table_action_profile
*
162 table_action_profile_find(const char *name
)
164 struct table_action_profile
*profile
;
169 TAILQ_FOREACH(profile
, &table_action_profile_list
, node
)
170 if (strcmp(profile
->name
, name
) == 0)
176 struct table_action_profile
*
177 table_action_profile_create(const char *name
,
178 struct table_action_profile_params
*params
)
180 struct table_action_profile
*profile
;
181 struct rte_table_action_profile
*ap
;
184 /* Check input params */
185 if ((name
== NULL
) ||
186 table_action_profile_find(name
) ||
188 ((params
->action_mask
& (1LLU << RTE_TABLE_ACTION_FWD
)) == 0))
191 if ((params
->action_mask
& (1LLU << RTE_TABLE_ACTION_LB
)) &&
192 (params
->lb
.f_hash
== NULL
)) {
193 switch (params
->lb
.key_size
) {
195 params
->lb
.f_hash
= rte_table_hash_crc_key8
;
199 params
->lb
.f_hash
= rte_table_hash_crc_key16
;
203 params
->lb
.f_hash
= rte_table_hash_crc_key24
;
207 params
->lb
.f_hash
= rte_table_hash_crc_key32
;
211 params
->lb
.f_hash
= rte_table_hash_crc_key40
;
215 params
->lb
.f_hash
= rte_table_hash_crc_key48
;
219 params
->lb
.f_hash
= rte_table_hash_crc_key56
;
223 params
->lb
.f_hash
= rte_table_hash_crc_key64
;
234 ap
= rte_table_action_profile_create(¶ms
->common
);
238 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_FWD
)) {
239 status
= rte_table_action_profile_action_register(ap
,
240 RTE_TABLE_ACTION_FWD
,
244 rte_table_action_profile_free(ap
);
249 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_LB
)) {
250 status
= rte_table_action_profile_action_register(ap
,
255 rte_table_action_profile_free(ap
);
260 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_MTR
)) {
261 status
= rte_table_action_profile_action_register(ap
,
262 RTE_TABLE_ACTION_MTR
,
266 rte_table_action_profile_free(ap
);
271 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_TM
)) {
272 status
= rte_table_action_profile_action_register(ap
,
277 rte_table_action_profile_free(ap
);
282 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_ENCAP
)) {
283 status
= rte_table_action_profile_action_register(ap
,
284 RTE_TABLE_ACTION_ENCAP
,
288 rte_table_action_profile_free(ap
);
293 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_NAT
)) {
294 status
= rte_table_action_profile_action_register(ap
,
295 RTE_TABLE_ACTION_NAT
,
299 rte_table_action_profile_free(ap
);
304 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_TTL
)) {
305 status
= rte_table_action_profile_action_register(ap
,
306 RTE_TABLE_ACTION_TTL
,
310 rte_table_action_profile_free(ap
);
315 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_STATS
)) {
316 status
= rte_table_action_profile_action_register(ap
,
317 RTE_TABLE_ACTION_STATS
,
321 rte_table_action_profile_free(ap
);
325 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_TIME
)) {
326 status
= rte_table_action_profile_action_register(ap
,
327 RTE_TABLE_ACTION_TIME
,
331 rte_table_action_profile_free(ap
);
336 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_SYM_CRYPTO
)) {
337 status
= rte_table_action_profile_action_register(ap
,
338 RTE_TABLE_ACTION_SYM_CRYPTO
,
339 ¶ms
->sym_crypto
);
342 rte_table_action_profile_free(ap
);
347 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_TAG
)) {
348 status
= rte_table_action_profile_action_register(ap
,
349 RTE_TABLE_ACTION_TAG
,
353 rte_table_action_profile_free(ap
);
358 if (params
->action_mask
& (1LLU << RTE_TABLE_ACTION_DECAP
)) {
359 status
= rte_table_action_profile_action_register(ap
,
360 RTE_TABLE_ACTION_DECAP
,
364 rte_table_action_profile_free(ap
);
369 status
= rte_table_action_profile_freeze(ap
);
371 rte_table_action_profile_free(ap
);
375 /* Node allocation */
376 profile
= calloc(1, sizeof(struct table_action_profile
));
377 if (profile
== NULL
) {
378 rte_table_action_profile_free(ap
);
383 strlcpy(profile
->name
, name
, sizeof(profile
->name
));
384 memcpy(&profile
->params
, params
, sizeof(*params
));
387 /* Node add to list */
388 TAILQ_INSERT_TAIL(&table_action_profile_list
, profile
, node
);