199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 299a2dd95SBruce Richardson * Copyright(c) 2018 Intel Corporation 399a2dd95SBruce Richardson */ 499a2dd95SBruce Richardson 599a2dd95SBruce Richardson #ifndef __INCLUDE_RTE_PORT_IN_ACTION_H__ 699a2dd95SBruce Richardson #define __INCLUDE_RTE_PORT_IN_ACTION_H__ 799a2dd95SBruce Richardson 899a2dd95SBruce Richardson /** 999a2dd95SBruce Richardson * @file 1099a2dd95SBruce Richardson * RTE Pipeline Input Port Actions 1199a2dd95SBruce Richardson * 1299a2dd95SBruce Richardson * This API provides a common set of actions for pipeline input ports to speed 1399a2dd95SBruce Richardson * up application development. 1499a2dd95SBruce Richardson * 1599a2dd95SBruce Richardson * Each pipeline input port can be assigned an action handler to be executed 1699a2dd95SBruce Richardson * on every input packet during the pipeline execution. The pipeline library 1799a2dd95SBruce Richardson * allows the user to define his own input port actions by providing customized 1899a2dd95SBruce Richardson * input port action handler. While the user can still follow this process, this 1999a2dd95SBruce Richardson * API is intended to provide a quicker development alternative for a set of 2099a2dd95SBruce Richardson * predefined actions. 2199a2dd95SBruce Richardson * 2299a2dd95SBruce Richardson * The typical steps to use this API are: 2399a2dd95SBruce Richardson * - Define an input port action profile. This is a configuration template that 2499a2dd95SBruce Richardson * can potentially be shared by multiple input ports from the same or 2599a2dd95SBruce Richardson * different pipelines, with different input ports from the same pipeline 2699a2dd95SBruce Richardson * able to use different action profiles. For every input port using a given 2799a2dd95SBruce Richardson * action profile, the profile defines the set of actions and the action 2899a2dd95SBruce Richardson * configuration to be executed by the input port. API functions: 2999a2dd95SBruce Richardson * rte_port_in_action_profile_create(), 3099a2dd95SBruce Richardson * rte_port_in_action_profile_action_register(), 3199a2dd95SBruce Richardson * rte_port_in_action_profile_freeze(). 3299a2dd95SBruce Richardson * 3399a2dd95SBruce Richardson * - Instantiate the input port action profile to create input port action 3499a2dd95SBruce Richardson * objects. Each pipeline input port has its own action object. 3599a2dd95SBruce Richardson * API functions: rte_port_in_action_create(). 3699a2dd95SBruce Richardson * 3799a2dd95SBruce Richardson * - Use the input port action object to generate the input port action handler 3899a2dd95SBruce Richardson * invoked by the pipeline. API functions: 3999a2dd95SBruce Richardson * rte_port_in_action_params_get(). 4099a2dd95SBruce Richardson * 4199a2dd95SBruce Richardson * - Use the input port action object to generate the internal data structures 4299a2dd95SBruce Richardson * used by the input port action handler based on given action parameters. 4399a2dd95SBruce Richardson * API functions: rte_port_in_action_apply(). 4499a2dd95SBruce Richardson * 4599a2dd95SBruce Richardson * @warning 4699a2dd95SBruce Richardson * @b EXPERIMENTAL: this API may change without prior notice 4799a2dd95SBruce Richardson */ 4899a2dd95SBruce Richardson 4999a2dd95SBruce Richardson #include <stdint.h> 5099a2dd95SBruce Richardson 5199a2dd95SBruce Richardson #include <rte_compat.h> 5299a2dd95SBruce Richardson #include <rte_table_hash.h> 5399a2dd95SBruce Richardson 5499a2dd95SBruce Richardson #include "rte_pipeline.h" 5599a2dd95SBruce Richardson 56*719834a6SMattias Rönnblom #ifdef __cplusplus 57*719834a6SMattias Rönnblom extern "C" { 58*719834a6SMattias Rönnblom #endif 59*719834a6SMattias Rönnblom 6099a2dd95SBruce Richardson /** Input port actions. */ 6199a2dd95SBruce Richardson enum rte_port_in_action_type { 6299a2dd95SBruce Richardson /** Filter selected input packets. */ 6399a2dd95SBruce Richardson RTE_PORT_IN_ACTION_FLTR = 0, 6499a2dd95SBruce Richardson 6599a2dd95SBruce Richardson /** Load balance. */ 6699a2dd95SBruce Richardson RTE_PORT_IN_ACTION_LB, 6799a2dd95SBruce Richardson }; 6899a2dd95SBruce Richardson 6999a2dd95SBruce Richardson /** 7099a2dd95SBruce Richardson * RTE_PORT_IN_ACTION_FLTR 7199a2dd95SBruce Richardson */ 7299a2dd95SBruce Richardson /** Filter key size (number of bytes) */ 7399a2dd95SBruce Richardson #define RTE_PORT_IN_ACTION_FLTR_KEY_SIZE 16 7499a2dd95SBruce Richardson 7599a2dd95SBruce Richardson /** Filter action configuration (per action profile). */ 7699a2dd95SBruce Richardson struct rte_port_in_action_fltr_config { 7799a2dd95SBruce Richardson /** Key offset within the input packet buffer. Offset 0 points to the 7899a2dd95SBruce Richardson * first byte of the MBUF structure. 7999a2dd95SBruce Richardson */ 8099a2dd95SBruce Richardson uint32_t key_offset; 8199a2dd95SBruce Richardson 8299a2dd95SBruce Richardson /** Key mask. */ 8399a2dd95SBruce Richardson uint8_t key_mask[RTE_PORT_IN_ACTION_FLTR_KEY_SIZE]; 8499a2dd95SBruce Richardson 8599a2dd95SBruce Richardson /** Key value. */ 8699a2dd95SBruce Richardson uint8_t key[RTE_PORT_IN_ACTION_FLTR_KEY_SIZE]; 8799a2dd95SBruce Richardson 8899a2dd95SBruce Richardson /** When non-zero, all the input packets that match the *key* (with the 8999a2dd95SBruce Richardson * *key_mask* applied) are sent to the pipeline output port *port_id*. 9099a2dd95SBruce Richardson * When zero, all the input packets that do NOT match the *key* (with 9199a2dd95SBruce Richardson * *key_mask* applied) are sent to the pipeline output port *port_id*. 9299a2dd95SBruce Richardson */ 9399a2dd95SBruce Richardson int filter_on_match; 9499a2dd95SBruce Richardson 9599a2dd95SBruce Richardson /** Pipeline output port ID to send the filtered input packets to. 9699a2dd95SBruce Richardson * Can be updated later. 9799a2dd95SBruce Richardson * 9899a2dd95SBruce Richardson * @see struct rte_port_in_action_fltr_params 9999a2dd95SBruce Richardson */ 10099a2dd95SBruce Richardson uint32_t port_id; 10199a2dd95SBruce Richardson }; 10299a2dd95SBruce Richardson 10399a2dd95SBruce Richardson /** Filter action parameters (per action). */ 10499a2dd95SBruce Richardson struct rte_port_in_action_fltr_params { 10599a2dd95SBruce Richardson /** Pipeline output port ID to send the filtered input packets to. */ 10699a2dd95SBruce Richardson uint32_t port_id; 10799a2dd95SBruce Richardson }; 10899a2dd95SBruce Richardson 10999a2dd95SBruce Richardson /** 11099a2dd95SBruce Richardson * RTE_PORT_IN_ACTION_LB 11199a2dd95SBruce Richardson */ 11299a2dd95SBruce Richardson /** Load balance key size min (number of bytes). */ 11399a2dd95SBruce Richardson #define RTE_PORT_IN_ACTION_LB_KEY_SIZE_MIN 8 11499a2dd95SBruce Richardson 11599a2dd95SBruce Richardson /** Load balance key size max (number of bytes). */ 11699a2dd95SBruce Richardson #define RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX 64 11799a2dd95SBruce Richardson 11899a2dd95SBruce Richardson /** Load balance table size. */ 11999a2dd95SBruce Richardson #define RTE_PORT_IN_ACTION_LB_TABLE_SIZE 16 12099a2dd95SBruce Richardson 12199a2dd95SBruce Richardson /** Load balance action configuration (per action profile). */ 12299a2dd95SBruce Richardson struct rte_port_in_action_lb_config { 12399a2dd95SBruce Richardson /** Key size (number of bytes). */ 12499a2dd95SBruce Richardson uint32_t key_size; 12599a2dd95SBruce Richardson 12699a2dd95SBruce Richardson /** Key offset within the input packet buffer. Offset 0 points to the 12799a2dd95SBruce Richardson * first byte of the MBUF structure. 12899a2dd95SBruce Richardson */ 12999a2dd95SBruce Richardson uint32_t key_offset; 13099a2dd95SBruce Richardson 13199a2dd95SBruce Richardson /** Key mask(*key_size* bytes are valid). */ 13299a2dd95SBruce Richardson uint8_t key_mask[RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX]; 13399a2dd95SBruce Richardson 13499a2dd95SBruce Richardson /** Hash function. */ 13599a2dd95SBruce Richardson rte_table_hash_op_hash f_hash; 13699a2dd95SBruce Richardson 13799a2dd95SBruce Richardson /** Seed value for *f_hash*. */ 13899a2dd95SBruce Richardson uint64_t seed; 13999a2dd95SBruce Richardson 14099a2dd95SBruce Richardson /** Table defining the weight of each pipeline output port. The weights 14199a2dd95SBruce Richardson * are set in 1/RTE_PORT_IN_ACTION_LB_TABLE_SIZE increments. To assign a 14299a2dd95SBruce Richardson * weight of N/RTE_PORT_IN_ACTION_LB_TABLE_SIZE to a given output port 14399a2dd95SBruce Richardson * (0 <= N <= RTE_PORT_IN_ACTION_LB_TABLE_SIZE), the output port needs 14499a2dd95SBruce Richardson * to show up exactly N times in this table. Can be updated later. 14599a2dd95SBruce Richardson * 14699a2dd95SBruce Richardson * @see struct rte_port_in_action_lb_params 14799a2dd95SBruce Richardson */ 14899a2dd95SBruce Richardson uint32_t port_id[RTE_PORT_IN_ACTION_LB_TABLE_SIZE]; 14999a2dd95SBruce Richardson }; 15099a2dd95SBruce Richardson 15199a2dd95SBruce Richardson /** Load balance action parameters (per action). */ 15299a2dd95SBruce Richardson struct rte_port_in_action_lb_params { 15399a2dd95SBruce Richardson /** Table defining the weight of each pipeline output port. The weights 15499a2dd95SBruce Richardson * are set in 1/RTE_PORT_IN_ACTION_LB_TABLE_SIZE increments. To assign a 15599a2dd95SBruce Richardson * weight of N/RTE_PORT_IN_ACTION_LB_TABLE_SIZE to a given output port 15699a2dd95SBruce Richardson * (0 <= N <= RTE_PORT_IN_ACTION_LB_TABLE_SIZE), the output port needs 15799a2dd95SBruce Richardson * to show up exactly N times in this table. 15899a2dd95SBruce Richardson */ 15999a2dd95SBruce Richardson uint32_t port_id[RTE_PORT_IN_ACTION_LB_TABLE_SIZE]; 16099a2dd95SBruce Richardson }; 16199a2dd95SBruce Richardson 16299a2dd95SBruce Richardson /** 16399a2dd95SBruce Richardson * Input port action profile. 16499a2dd95SBruce Richardson */ 16599a2dd95SBruce Richardson struct rte_port_in_action_profile; 16699a2dd95SBruce Richardson 16799a2dd95SBruce Richardson /** 16899a2dd95SBruce Richardson * Input port action profile create. 16999a2dd95SBruce Richardson * 17099a2dd95SBruce Richardson * @param[in] socket_id 17199a2dd95SBruce Richardson * CPU socket ID for the internal data structures memory allocation. 17299a2dd95SBruce Richardson * @return 17399a2dd95SBruce Richardson * Input port action profile handle on success, NULL otherwise. 17499a2dd95SBruce Richardson */ 17599a2dd95SBruce Richardson __rte_experimental 17699a2dd95SBruce Richardson struct rte_port_in_action_profile * 17799a2dd95SBruce Richardson rte_port_in_action_profile_create(uint32_t socket_id); 17899a2dd95SBruce Richardson 17999a2dd95SBruce Richardson /** 18099a2dd95SBruce Richardson * Input port action profile free. 18199a2dd95SBruce Richardson * 18299a2dd95SBruce Richardson * @param[in] profile 18399a2dd95SBruce Richardson * Input port action profile handle (needs to be valid). 184448e01f1SStephen Hemminger * If profile is NULL, no operation is performed. 18599a2dd95SBruce Richardson * @return 186448e01f1SStephen Hemminger * Always zero. 18799a2dd95SBruce Richardson */ 18899a2dd95SBruce Richardson __rte_experimental 18999a2dd95SBruce Richardson int 19099a2dd95SBruce Richardson rte_port_in_action_profile_free(struct rte_port_in_action_profile *profile); 19199a2dd95SBruce Richardson 19299a2dd95SBruce Richardson /** 19399a2dd95SBruce Richardson * Input port action profile action register. 19499a2dd95SBruce Richardson * 19599a2dd95SBruce Richardson * @param[in] profile 19699a2dd95SBruce Richardson * Input port action profile handle (needs to be valid and not in frozen 19799a2dd95SBruce Richardson * state). 19899a2dd95SBruce Richardson * @param[in] type 19999a2dd95SBruce Richardson * Specific input port action to be registered for *profile*. 20099a2dd95SBruce Richardson * @param[in] action_config 20199a2dd95SBruce Richardson * Configuration for the *type* action. 20299a2dd95SBruce Richardson * If struct rte_port_in_action_*type*_config is defined, it needs to point to 20399a2dd95SBruce Richardson * a valid instance of this structure, otherwise it needs to be set to NULL. 20499a2dd95SBruce Richardson * @return 20599a2dd95SBruce Richardson * Zero on success, non-zero error code otherwise. 20699a2dd95SBruce Richardson */ 20799a2dd95SBruce Richardson __rte_experimental 20899a2dd95SBruce Richardson int 20999a2dd95SBruce Richardson rte_port_in_action_profile_action_register( 21099a2dd95SBruce Richardson struct rte_port_in_action_profile *profile, 21199a2dd95SBruce Richardson enum rte_port_in_action_type type, 21299a2dd95SBruce Richardson void *action_config); 21399a2dd95SBruce Richardson 21499a2dd95SBruce Richardson /** 21599a2dd95SBruce Richardson * Input port action profile freeze. 21699a2dd95SBruce Richardson * 21799a2dd95SBruce Richardson * Once this function is called successfully, the given profile enters the 21899a2dd95SBruce Richardson * frozen state with the following immediate effects: no more actions can be 21999a2dd95SBruce Richardson * registered for this profile, so the profile can be instantiated to create 22099a2dd95SBruce Richardson * input port action objects. 22199a2dd95SBruce Richardson * 22299a2dd95SBruce Richardson * @param[in] profile 22399a2dd95SBruce Richardson * Input port profile action handle (needs to be valid and not in frozen 22499a2dd95SBruce Richardson * state). 22599a2dd95SBruce Richardson * @return 22699a2dd95SBruce Richardson * Zero on success, non-zero error code otherwise. 22799a2dd95SBruce Richardson * 22899a2dd95SBruce Richardson * @see rte_port_in_action_create() 22999a2dd95SBruce Richardson */ 23099a2dd95SBruce Richardson __rte_experimental 23199a2dd95SBruce Richardson int 23299a2dd95SBruce Richardson rte_port_in_action_profile_freeze(struct rte_port_in_action_profile *profile); 23399a2dd95SBruce Richardson 23499a2dd95SBruce Richardson /** 23599a2dd95SBruce Richardson * Input port action. 23699a2dd95SBruce Richardson */ 23799a2dd95SBruce Richardson struct rte_port_in_action; 23899a2dd95SBruce Richardson 23999a2dd95SBruce Richardson /** 24099a2dd95SBruce Richardson * Input port action create. 24199a2dd95SBruce Richardson * 24299a2dd95SBruce Richardson * Instantiates the given input port action profile to create an input port 24399a2dd95SBruce Richardson * action object. 24499a2dd95SBruce Richardson * 24599a2dd95SBruce Richardson * @param[in] profile 24699a2dd95SBruce Richardson * Input port profile action handle (needs to be valid and in frozen state). 24799a2dd95SBruce Richardson * @param[in] socket_id 24899a2dd95SBruce Richardson * CPU socket ID where the internal data structures required by the new input 24999a2dd95SBruce Richardson * port action object should be allocated. 25099a2dd95SBruce Richardson * @return 25199a2dd95SBruce Richardson * Handle to input port action object on success, NULL on error. 25299a2dd95SBruce Richardson */ 25399a2dd95SBruce Richardson __rte_experimental 25499a2dd95SBruce Richardson struct rte_port_in_action * 25599a2dd95SBruce Richardson rte_port_in_action_create(struct rte_port_in_action_profile *profile, 25699a2dd95SBruce Richardson uint32_t socket_id); 25799a2dd95SBruce Richardson 25899a2dd95SBruce Richardson /** 25999a2dd95SBruce Richardson * Input port action free. 26099a2dd95SBruce Richardson * 26199a2dd95SBruce Richardson * @param[in] action 26299a2dd95SBruce Richardson * Handle to input port action object (needs to be valid). 263448e01f1SStephen Hemminger * If action is NULL, no operation is performed. 26499a2dd95SBruce Richardson * @return 265448e01f1SStephen Hemminger * Always zero. 26699a2dd95SBruce Richardson */ 26799a2dd95SBruce Richardson __rte_experimental 26899a2dd95SBruce Richardson int 26999a2dd95SBruce Richardson rte_port_in_action_free(struct rte_port_in_action *action); 27099a2dd95SBruce Richardson 27199a2dd95SBruce Richardson /** 27299a2dd95SBruce Richardson * Input port params get. 27399a2dd95SBruce Richardson * 27499a2dd95SBruce Richardson * @param[in] action 27599a2dd95SBruce Richardson * Handle to input port action object (needs to be valid). 27699a2dd95SBruce Richardson * @param[inout] params 27799a2dd95SBruce Richardson * Pipeline input port parameters (needs to be pre-allocated). 27899a2dd95SBruce Richardson * @return 27999a2dd95SBruce Richardson * Zero on success, non-zero error code otherwise. 28099a2dd95SBruce Richardson */ 28199a2dd95SBruce Richardson __rte_experimental 28299a2dd95SBruce Richardson int 28399a2dd95SBruce Richardson rte_port_in_action_params_get(struct rte_port_in_action *action, 28499a2dd95SBruce Richardson struct rte_pipeline_port_in_params *params); 28599a2dd95SBruce Richardson 28699a2dd95SBruce Richardson /** 28799a2dd95SBruce Richardson * Input port action apply. 28899a2dd95SBruce Richardson * 28999a2dd95SBruce Richardson * @param[in] action 29099a2dd95SBruce Richardson * Handle to input port action object (needs to be valid). 29199a2dd95SBruce Richardson * @param[in] type 29299a2dd95SBruce Richardson * Specific input port action previously registered for the input port action 29399a2dd95SBruce Richardson * profile of the *action* object. 29499a2dd95SBruce Richardson * @param[in] action_params 29599a2dd95SBruce Richardson * Parameters for the *type* action. 29699a2dd95SBruce Richardson * If struct rte_port_in_action_*type*_params is defined, it needs to point to 29799a2dd95SBruce Richardson * a valid instance of this structure, otherwise it needs to be set to NULL. 29899a2dd95SBruce Richardson * @return 29999a2dd95SBruce Richardson * Zero on success, non-zero error code otherwise. 30099a2dd95SBruce Richardson */ 30199a2dd95SBruce Richardson __rte_experimental 30299a2dd95SBruce Richardson int 30399a2dd95SBruce Richardson rte_port_in_action_apply(struct rte_port_in_action *action, 30499a2dd95SBruce Richardson enum rte_port_in_action_type type, 30599a2dd95SBruce Richardson void *action_params); 30699a2dd95SBruce Richardson 30799a2dd95SBruce Richardson #ifdef __cplusplus 30899a2dd95SBruce Richardson } 30999a2dd95SBruce Richardson #endif 31099a2dd95SBruce Richardson 31199a2dd95SBruce Richardson #endif /* __INCLUDE_RTE_PORT_IN_ACTION_H__ */ 312