1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
8 #include <rte_malloc.h>
10 #include <rte_common.h>
11 #include <rte_malloc.h>
13 #include "rte_table_action.h"
16 * RTE_TABLE_ACTION_FWD
18 #define fwd_data rte_pipeline_table_entry
21 fwd_apply(struct fwd_data *data,
22 struct rte_table_action_fwd_params *p)
24 data->action = p->action;
26 if (p->action == RTE_PIPELINE_ACTION_PORT)
27 data->port_id = p->id;
29 if (p->action == RTE_PIPELINE_ACTION_TABLE)
30 data->table_id = p->id;
39 action_valid(enum rte_table_action_type action)
42 case RTE_TABLE_ACTION_FWD:
50 #define RTE_TABLE_ACTION_MAX 64
54 struct rte_table_action_common_config common;
58 action_cfg_size(enum rte_table_action_type action)
67 action_cfg_get(struct ap_config *ap_config __rte_unused,
68 enum rte_table_action_type type)
77 action_cfg_set(struct ap_config *ap_config,
78 enum rte_table_action_type type,
81 void *dst = action_cfg_get(ap_config, type);
84 memcpy(dst, action_cfg, action_cfg_size(type));
86 ap_config->action_mask |= 1LLU << type;
90 size_t offset[RTE_TABLE_ACTION_MAX];
95 action_data_size(enum rte_table_action_type action,
96 struct ap_config *ap_config __rte_unused)
99 case RTE_TABLE_ACTION_FWD:
100 return sizeof(struct fwd_data);
109 action_data_offset_set(struct ap_data *ap_data,
110 struct ap_config *ap_config)
112 uint64_t action_mask = ap_config->action_mask;
116 memset(ap_data->offset, 0, sizeof(ap_data->offset));
119 for (action = 0; action < RTE_TABLE_ACTION_MAX; action++)
120 if (action_mask & (1LLU << action)) {
121 ap_data->offset[action] = offset;
122 offset += action_data_size((enum rte_table_action_type)action,
126 ap_data->total_size = offset;
129 struct rte_table_action_profile {
130 struct ap_config cfg;
135 struct rte_table_action_profile *
136 rte_table_action_profile_create(struct rte_table_action_common_config *common)
138 struct rte_table_action_profile *ap;
140 /* Check input arguments */
144 /* Memory allocation */
145 ap = calloc(1, sizeof(struct rte_table_action_profile));
150 memcpy(&ap->cfg.common, common, sizeof(*common));
157 rte_table_action_profile_action_register(struct rte_table_action_profile *profile,
158 enum rte_table_action_type type,
161 /* Check input arguments */
162 if ((profile == NULL) ||
164 (action_valid(type) == 0) ||
165 (profile->cfg.action_mask & (1LLU << type)) ||
166 ((action_cfg_size(type) == 0) && action_config) ||
167 (action_cfg_size(type) && (action_config == NULL)))
171 action_cfg_set(&profile->cfg, type, action_config);
177 rte_table_action_profile_freeze(struct rte_table_action_profile *profile)
182 profile->cfg.action_mask |= 1LLU << RTE_TABLE_ACTION_FWD;
183 action_data_offset_set(&profile->data, &profile->cfg);
190 rte_table_action_profile_free(struct rte_table_action_profile *profile)
199 struct rte_table_action {
200 struct ap_config cfg;
204 struct rte_table_action *
205 rte_table_action_create(struct rte_table_action_profile *profile,
208 struct rte_table_action *action;
210 /* Check input arguments */
211 if ((profile == NULL) ||
212 (profile->frozen == 0))
215 /* Memory allocation */
216 action = rte_zmalloc_socket(NULL,
217 sizeof(struct rte_table_action),
224 memcpy(&action->cfg, &profile->cfg, sizeof(profile->cfg));
225 memcpy(&action->data, &profile->data, sizeof(profile->data));
230 static __rte_always_inline void *
231 action_data_get(void *data,
232 struct rte_table_action *action,
233 enum rte_table_action_type type)
235 size_t offset = action->data.offset[type];
236 uint8_t *data_bytes = data;
238 return &data_bytes[offset];
242 rte_table_action_apply(struct rte_table_action *action,
244 enum rte_table_action_type type,
249 /* Check input arguments */
250 if ((action == NULL) ||
252 (action_valid(type) == 0) ||
253 ((action->cfg.action_mask & (1LLU << type)) == 0) ||
254 (action_params == NULL))
258 action_data = action_data_get(data, action, type);
261 case RTE_TABLE_ACTION_FWD:
262 return fwd_apply(action_data,
271 rte_table_action_free(struct rte_table_action *action)