1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
5 #ifndef __INCLUDE_RTE_PORT_IN_ACTION_H__
6 #define __INCLUDE_RTE_PORT_IN_ACTION_H__
10 * RTE Pipeline Input Port Actions
12 * This API provides a common set of actions for pipeline input ports to speed
13 * up application development.
15 * Each pipeline input port can be assigned an action handler to be executed
16 * on every input packet during the pipeline execution. The pipeline library
17 * allows the user to define his own input port actions by providing customized
18 * input port action handler. While the user can still follow this process, this
19 * API is intended to provide a quicker development alternative for a set of
22 * The typical steps to use this API are:
23 * - Define an input port action profile. This is a configuration template that
24 * can potentially be shared by multiple input ports from the same or
25 * different pipelines, with different input ports from the same pipeline
26 * able to use different action profiles. For every input port using a given
27 * action profile, the profile defines the set of actions and the action
28 * configuration to be executed by the input port. API functions:
29 * rte_port_in_action_profile_create(),
30 * rte_port_in_action_profile_action_register(),
31 * rte_port_in_action_profile_freeze().
33 * - Instantiate the input port action profile to create input port action
34 * objects. Each pipeline input port has its own action object.
35 * API functions: rte_port_in_action_create().
37 * - Use the input port action object to generate the input port action handler
38 * invoked by the pipeline. API functions:
39 * rte_port_in_action_params_get().
41 * - Use the input port action object to generate the internal data structures
42 * used by the input port action handler based on given action parameters.
43 * API functions: rte_port_in_action_apply().
46 * @b EXPERIMENTAL: this API may change without prior notice
55 #include <rte_compat.h>
56 #include <rte_table_hash.h>
58 #include "rte_pipeline.h"
60 /** Input port actions. */
61 enum rte_port_in_action_type {
62 /** Filter selected input packets. */
63 RTE_PORT_IN_ACTION_FLTR = 0,
66 RTE_PORT_IN_ACTION_LB,
70 * RTE_PORT_IN_ACTION_FLTR
72 /** Filter key size (number of bytes) */
73 #define RTE_PORT_IN_ACTION_FLTR_KEY_SIZE 16
75 /** Filter action configuration (per action profile). */
76 struct rte_port_in_action_fltr_config {
77 /** Key offset within the input packet buffer. Offset 0 points to the
78 * first byte of the MBUF structure.
83 uint8_t key_mask[RTE_PORT_IN_ACTION_FLTR_KEY_SIZE];
86 uint8_t key[RTE_PORT_IN_ACTION_FLTR_KEY_SIZE];
88 /** When non-zero, all the input packets that match the *key* (with the
89 * *key_mask* applied) are sent to the pipeline output port *port_id*.
90 * When zero, all the input packets that do NOT match the *key* (with
91 * *key_mask* applied) are sent to the pipeline output port *port_id*.
95 /** Pipeline output port ID to send the filtered input packets to.
96 * Can be updated later.
98 * @see struct rte_port_in_action_fltr_params
103 /** Filter action parameters (per action). */
104 struct rte_port_in_action_fltr_params {
105 /** Pipeline output port ID to send the filtered input packets to. */
110 * RTE_PORT_IN_ACTION_LB
112 /** Load balance key size min (number of bytes). */
113 #define RTE_PORT_IN_ACTION_LB_KEY_SIZE_MIN 8
115 /** Load balance key size max (number of bytes). */
116 #define RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX 64
118 /** Load balance table size. */
119 #define RTE_PORT_IN_ACTION_LB_TABLE_SIZE 16
121 /** Load balance action configuration (per action profile). */
122 struct rte_port_in_action_lb_config {
123 /** Key size (number of bytes). */
126 /** Key offset within the input packet buffer. Offset 0 points to the
127 * first byte of the MBUF structure.
131 /** Key mask(*key_size* bytes are valid). */
132 uint8_t key_mask[RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX];
134 /** Hash function. */
135 rte_table_hash_op_hash f_hash;
137 /** Seed value for *f_hash*. */
140 /** Table defining the weight of each pipeline output port. The weights
141 * are set in 1/RTE_PORT_IN_ACTION_LB_TABLE_SIZE increments. To assign a
142 * weight of N/RTE_PORT_IN_ACTION_LB_TABLE_SIZE to a given output port
143 * (0 <= N <= RTE_PORT_IN_ACTION_LB_TABLE_SIZE), the output port needs
144 * to show up exactly N times in this table. Can be updated later.
146 * @see struct rte_port_in_action_lb_params
148 uint32_t port_id[RTE_PORT_IN_ACTION_LB_TABLE_SIZE];
151 /** Load balance action parameters (per action). */
152 struct rte_port_in_action_lb_params {
153 /** Table defining the weight of each pipeline output port. The weights
154 * are set in 1/RTE_PORT_IN_ACTION_LB_TABLE_SIZE increments. To assign a
155 * weight of N/RTE_PORT_IN_ACTION_LB_TABLE_SIZE to a given output port
156 * (0 <= N <= RTE_PORT_IN_ACTION_LB_TABLE_SIZE), the output port needs
157 * to show up exactly N times in this table.
159 uint32_t port_id[RTE_PORT_IN_ACTION_LB_TABLE_SIZE];
163 * Input port action profile.
165 struct rte_port_in_action_profile;
168 * Input port action profile create.
170 * @param[in] socket_id
171 * CPU socket ID for the internal data structures memory allocation.
173 * Input port action profile handle on success, NULL otherwise.
176 struct rte_port_in_action_profile *
177 rte_port_in_action_profile_create(uint32_t socket_id);
180 * Input port action profile free.
183 * Input port action profile handle (needs to be valid).
185 * Zero on success, non-zero error code otherwise.
189 rte_port_in_action_profile_free(struct rte_port_in_action_profile *profile);
192 * Input port action profile action register.
195 * Input port action profile handle (needs to be valid and not in frozen
198 * Specific input port action to be registered for *profile*.
199 * @param[in] action_config
200 * Configuration for the *type* action.
201 * If struct rte_port_in_action_*type*_config is defined, it needs to point to
202 * a valid instance of this structure, otherwise it needs to be set to NULL.
204 * Zero on success, non-zero error code otherwise.
208 rte_port_in_action_profile_action_register(
209 struct rte_port_in_action_profile *profile,
210 enum rte_port_in_action_type type,
211 void *action_config);
214 * Input port action profile freeze.
216 * Once this function is called successfully, the given profile enters the
217 * frozen state with the following immediate effects: no more actions can be
218 * registered for this profile, so the profile can be instantiated to create
219 * input port action objects.
222 * Input port profile action handle (needs to be valid and not in frozen
225 * Zero on success, non-zero error code otherwise.
227 * @see rte_port_in_action_create()
231 rte_port_in_action_profile_freeze(struct rte_port_in_action_profile *profile);
236 struct rte_port_in_action;
239 * Input port action create.
241 * Instantiates the given input port action profile to create an input port
245 * Input port profile action handle (needs to be valid and in frozen state).
246 * @param[in] socket_id
247 * CPU socket ID where the internal data structures required by the new input
248 * port action object should be allocated.
250 * Handle to input port action object on success, NULL on error.
253 struct rte_port_in_action *
254 rte_port_in_action_create(struct rte_port_in_action_profile *profile,
258 * Input port action free.
261 * Handle to input port action object (needs to be valid).
263 * Zero on success, non-zero error code otherwise.
267 rte_port_in_action_free(struct rte_port_in_action *action);
270 * Input port params get.
273 * Handle to input port action object (needs to be valid).
274 * @param[inout] params
275 * Pipeline input port parameters (needs to be pre-allocated).
277 * Zero on success, non-zero error code otherwise.
281 rte_port_in_action_params_get(struct rte_port_in_action *action,
282 struct rte_pipeline_port_in_params *params);
285 * Input port action apply.
288 * Handle to input port action object (needs to be valid).
290 * Specific input port action previously registered for the input port action
291 * profile of the *action* object.
292 * @param[in] action_params
293 * Parameters for the *type* action.
294 * If struct rte_port_in_action_*type*_params is defined, it needs to point to
295 * a valid instance of this structure, otherwise it needs to be set to NULL.
297 * Zero on success, non-zero error code otherwise.
301 rte_port_in_action_apply(struct rte_port_in_action *action,
302 enum rte_port_in_action_type type,
303 void *action_params);
309 #endif /* __INCLUDE_RTE_PORT_IN_ACTION_H__ */