LCOV - code coverage report
Current view: top level - drivers/net/cpfl - cpfl_flow_parser.h (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 2 0.0 %
Date: 2025-01-02 22:41:34 Functions: 0 0 -
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2023 Intel Corporation
       3                 :            :  */
       4                 :            : #include <jansson.h>
       5                 :            : #include <rte_flow.h>
       6                 :            : 
       7                 :            : #include "cpfl_ethdev.h"
       8                 :            : 
       9                 :            : #ifndef _CPFL_FLOW_PARSER_H_
      10                 :            : #define _CPFL_FLOW_PARSER_H_
      11                 :            : 
      12                 :            : #define CPFL_JS_STR_SIZE 100
      13                 :            : #define CPFL_JS_SEM_FV_KEY_NUM_MAX 64
      14                 :            : #define CPFL_JS_PROTO_NUM_MAX 16
      15                 :            : #define CPFL_JS_MOD_KEY_NUM_MAX 8
      16                 :            : #define CPFL_JS_PROG_CONTENT_FIELD_NUM_MAX 64
      17                 :            : #define CPFL_JS_PROG_CONSTANT_VALUE_NUM_MAX 8
      18                 :            : #define CPFL_JS_PROG_PARAM_NUM_MAX 10
      19                 :            : 
      20                 :            : /* Pattern Rules Storage */
      21                 :            : enum cpfl_flow_pr_action_type {
      22                 :            :         CPFL_JS_PR_ACTION_TYPE_SEM,
      23                 :            :         CPFL_JS_PR_ACTION_TYPE_UNKNOWN = -1,
      24                 :            : };
      25                 :            : 
      26                 :            : /* This structure matches a sequence of fields in struct rte_flow_attr */
      27                 :            : struct cpfl_flow_js_pr_key_attr {
      28                 :            :         uint16_t ingress;
      29                 :            :         uint16_t egress;
      30                 :            : };
      31                 :            : 
      32                 :            : struct cpfl_flow_js_pr_key_proto_field {
      33                 :            :         char name[CPFL_JS_STR_SIZE];
      34                 :            :         union {
      35                 :            :                 char mask[CPFL_JS_STR_SIZE];
      36                 :            :                 uint32_t mask_32b;
      37                 :            :         };
      38                 :            : };
      39                 :            : 
      40                 :            : /* This structure matches a sequence of "struct rte_flow_item" */
      41                 :            : struct cpfl_flow_js_pr_key_proto {
      42                 :            :         enum rte_flow_item_type type;
      43                 :            :         struct cpfl_flow_js_pr_key_proto_field *fields;
      44                 :            :         int fields_size;
      45                 :            : };
      46                 :            : 
      47                 :            : enum cpfl_flow_js_fv_type {
      48                 :            :         CPFL_FV_TYPE_PROTOCOL,
      49                 :            :         CPFL_FV_TYPE_IMMEDIATE,
      50                 :            :         CPFL_FV_TYPE_METADATA,
      51                 :            :         CPFL_FV_TYPE_UNKNOWN = -1,
      52                 :            : };
      53                 :            : 
      54                 :            : struct cpfl_flow_js_fv {
      55                 :            :         uint16_t offset;
      56                 :            :         enum cpfl_flow_js_fv_type type;
      57                 :            :         union {
      58                 :            :                 /*  a 16 bits value */
      59                 :            :                 uint16_t immediate;
      60                 :            :                 /* a reference to a protocol header with a <header, layer, offset, mask> tuple */
      61                 :            :                 struct {
      62                 :            :                         enum rte_flow_item_type header;
      63                 :            :                         uint16_t layer;
      64                 :            :                         uint16_t offset;
      65                 :            :                         uint16_t mask;
      66                 :            :                 } proto;
      67                 :            :                 /* a reference to a metadata */
      68                 :            :                 struct {
      69                 :            :                         uint16_t type;
      70                 :            :                         uint16_t offset;
      71                 :            :                         uint16_t mask;
      72                 :            :                 } meta;
      73                 :            :         };
      74                 :            : };
      75                 :            : 
      76                 :            : /**
      77                 :            :  * This structure defines the message be used to composite the
      78                 :            :  * profile / key of a SEM control packet
      79                 :            :  */
      80                 :            : struct cpfl_flow_js_pr_action_sem {
      81                 :            :         uint16_t prof;              /* SEM profile ID */
      82                 :            :         uint16_t subprof;           /* SEM subprofile ID */
      83                 :            :         uint16_t keysize;           /* extract key size in bytes */
      84                 :            :         struct cpfl_flow_js_fv *fv; /* A SEM field vector array */
      85                 :            :         int fv_size;
      86                 :            : };
      87                 :            : 
      88                 :            : /* define how to map current key to low level pipeline configuration */
      89                 :            : struct cpfl_flow_js_pr_action {
      90                 :            :         enum cpfl_flow_pr_action_type type;
      91                 :            :         union {
      92                 :            :                 struct cpfl_flow_js_pr_action_sem sem;
      93                 :            :         };
      94                 :            : };
      95                 :            : 
      96                 :            : /**
      97                 :            :  * This structure defines a set of rules that direct PMD how to parse rte_flow
      98                 :            :  * protocol headers. Each rule be described by a key object and a action array.
      99                 :            :  */
     100                 :            : struct cpfl_flow_js_pr {
     101                 :            :         struct {
     102                 :            :                 struct cpfl_flow_js_pr_key_proto *protocols;
     103                 :            :                 uint16_t proto_size;
     104                 :            :                 struct cpfl_flow_js_pr_key_attr *attributes;
     105                 :            :                 uint16_t attr_size;
     106                 :            :         } key;
     107                 :            :         /* An array to define how to map current key to low level pipeline configuration. */
     108                 :            :         struct cpfl_flow_js_pr_action *actions;
     109                 :            :         uint16_t actions_size;
     110                 :            : };
     111                 :            : 
     112                 :            : /* Modification Rules Storage */
     113                 :            : /**
     114                 :            :  * The vxlan_encap action matches RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP
     115                 :            :  * and include a sequence of protocol headers defined in field protocols
     116                 :            :  * of data.
     117                 :            :  */
     118                 :            : struct cpfl_flow_js_mr_key_action_vxlan_encap {
     119                 :            :         enum rte_flow_item_type protocols[CPFL_JS_PROTO_NUM_MAX];
     120                 :            :         int proto_size;
     121                 :            : };
     122                 :            : 
     123                 :            : struct cpfl_flow_js_prog_parameter {
     124                 :            :         bool has_name;
     125                 :            :         uint16_t index;
     126                 :            :         char name[CPFL_JS_STR_SIZE];
     127                 :            :         uint16_t size;
     128                 :            : };
     129                 :            : 
     130                 :            : struct cpfl_flow_js_mr_key_action_prog {
     131                 :            :         bool has_name;
     132                 :            :         uint32_t id;
     133                 :            :         char name[CPFL_JS_STR_SIZE];
     134                 :            :         uint32_t param_size;
     135                 :            :         struct cpfl_flow_js_prog_parameter params[CPFL_JS_PROG_PARAM_NUM_MAX];
     136                 :            : };
     137                 :            : 
     138                 :            : /* A set of modification rte_flow_action_xxx objects can be defined as a type / data pair. */
     139                 :            : struct cpfl_flow_js_mr_key_action {
     140                 :            :         enum rte_flow_action_type type;
     141                 :            :         union {
     142                 :            :                 struct cpfl_flow_js_mr_key_action_vxlan_encap encap;
     143                 :            :                 struct cpfl_flow_js_mr_key_action_prog prog;
     144                 :            :         };
     145                 :            : };
     146                 :            : 
     147                 :            : struct cpfl_flow_js_mr_key {
     148                 :            :         struct cpfl_flow_js_mr_key_action *actions;
     149                 :            :         int actions_size;
     150                 :            : };
     151                 :            : 
     152                 :            : struct cpfl_flow_js_mr_layout {
     153                 :            :         int index;                              /* links to the element of the actions array */
     154                 :            :         char hint[CPFL_JS_STR_SIZE]; /* where the data to copy from */
     155                 :            :         uint16_t offset;                        /* the start byte of the data to copy from */
     156                 :            :         uint16_t size; /*  bytes of the data to be copied to the memory region */
     157                 :            : };
     158                 :            : 
     159                 :            : struct cpfl_flow_js_mr_field {
     160                 :            :         char type[CPFL_JS_STR_SIZE];
     161                 :            :         uint16_t start;
     162                 :            :         uint16_t width;
     163                 :            :         union {
     164                 :            :                 uint16_t index;
     165                 :            :                 uint8_t value[CPFL_JS_PROG_CONSTANT_VALUE_NUM_MAX];
     166                 :            :         };
     167                 :            : };
     168                 :            : 
     169                 :            : struct cpfl_flow_js_mr_content {
     170                 :            :         uint16_t size;
     171                 :            :         struct cpfl_flow_js_mr_field fields[CPFL_JS_PROG_CONTENT_FIELD_NUM_MAX];
     172                 :            :         int field_size;
     173                 :            : };
     174                 :            : 
     175                 :            : /** For mod data, besides the profile ID, a layout array defines a set of hints that helps
     176                 :            :  * driver composing the MOD memory region when the action need to insert/update some packet
     177                 :            :  * data from user input.
     178                 :            :  */
     179                 :            : struct cpfl_flow_js_mr_action_mod {
     180                 :            :         uint16_t prof;
     181                 :            :         uint16_t byte_len;
     182                 :            :         bool is_content;
     183                 :            :         union {
     184                 :            :                 struct {
     185                 :            :                         struct cpfl_flow_js_mr_layout layout[CPFL_JS_PROTO_NUM_MAX];
     186                 :            :                         int layout_size;
     187                 :            :                 };
     188                 :            :                 struct cpfl_flow_js_mr_content content;
     189                 :            :         };
     190                 :            : };
     191                 :            : 
     192                 :            : enum cpfl_flow_mr_action_type {
     193                 :            :         CPFL_JS_MR_ACTION_TYPE_MOD,
     194                 :            : };
     195                 :            : 
     196                 :            : /** Currently, the type can only be mod.
     197                 :            :  *
     198                 :            :  * For mod data, besides the profile ID, a layout array defines a set
     199                 :            :  * of hints that helps driver composing the MOD memory region when the
     200                 :            :  * action need to insert/update some packet data from user input.
     201                 :            :  */
     202                 :            : struct cpfl_flow_js_mr_action {
     203                 :            :         enum cpfl_flow_mr_action_type type;
     204                 :            :         union {
     205                 :            :                 struct cpfl_flow_js_mr_action_mod mod;
     206                 :            :         };
     207                 :            : };
     208                 :            : 
     209                 :            : /**
     210                 :            :  * This structure defines a set of rules that direct PMD to parse rte_flow modification
     211                 :            :  * actions. Each rule be described by a pair of key and action
     212                 :            :  */
     213                 :            : struct cpfl_flow_js_mr {
     214                 :            :         struct cpfl_flow_js_mr_key key;
     215                 :            :         struct cpfl_flow_js_mr_action action;
     216                 :            : };
     217                 :            : 
     218                 :            : struct cpfl_flow_js_parser {
     219                 :            :         struct cpfl_flow_js_pr *patterns;
     220                 :            :         int pr_size;
     221                 :            :         struct cpfl_flow_js_mr *modifications;
     222                 :            :         int mr_size;
     223                 :            : };
     224                 :            : 
     225                 :            : /* Pattern Rules */
     226                 :            : struct cpfl_flow_pr_action_sem {
     227                 :            :         uint16_t prof;
     228                 :            :         uint16_t subprof;
     229                 :            :         uint16_t keysize;
     230                 :            :         uint8_t cpfl_flow_pr_fv[CPFL_JS_SEM_FV_KEY_NUM_MAX];
     231                 :            : };
     232                 :            : 
     233                 :            : struct cpfl_flow_pr_action {
     234                 :            :         enum cpfl_flow_pr_action_type type;
     235                 :            :         union {
     236                 :            :                 struct cpfl_flow_pr_action_sem sem;
     237                 :            :         };
     238                 :            : };
     239                 :            : 
     240                 :            : /* Modification Rules */
     241                 :            : struct cpfl_flow_mr_key_action_vxlan_encap {
     242                 :            :         enum rte_flow_item_type protocols[CPFL_JS_PROTO_NUM_MAX];
     243                 :            :         uint16_t proto_size;
     244                 :            :         const struct rte_flow_action *action;
     245                 :            : };
     246                 :            : 
     247                 :            : struct cpfl_flow_mr_key_action_prog {
     248                 :            :         const struct rte_flow_action_prog *prog;
     249                 :            :         bool has_name;
     250                 :            :         char name[CPFL_JS_PROG_PARAM_NUM_MAX][CPFL_JS_STR_SIZE];
     251                 :            : };
     252                 :            : 
     253                 :            : struct cpfl_flow_mr_key_mod {
     254                 :            :         enum rte_flow_action_type type;
     255                 :            :         struct cpfl_flow_mr_key_action_vxlan_encap encap;
     256                 :            : };
     257                 :            : 
     258                 :            : struct cpfl_flow_mr_key_action {
     259                 :            :         struct cpfl_flow_mr_key_mod mods[CPFL_JS_MOD_KEY_NUM_MAX];
     260                 :            :         struct cpfl_flow_mr_key_action_prog prog;
     261                 :            : };
     262                 :            : 
     263                 :            : struct cpfl_flow_mr_action_mod {
     264                 :            :         uint16_t prof;
     265                 :            :         uint16_t byte_len;
     266                 :            :         uint8_t data[256];
     267                 :            : };
     268                 :            : 
     269                 :            : struct cpfl_flow_mr_action {
     270                 :            :         enum cpfl_flow_mr_action_type type;
     271                 :            :         union {
     272                 :            :                 struct cpfl_flow_mr_action_mod mod;
     273                 :            :         };
     274                 :            : };
     275                 :            : 
     276                 :            : int cpfl_parser_create(struct cpfl_flow_js_parser **parser, const char *filename);
     277                 :            : int cpfl_parser_destroy(struct cpfl_flow_js_parser *parser);
     278                 :            : int cpfl_flow_parse_items(struct cpfl_itf *itf,
     279                 :            :                           struct cpfl_flow_js_parser *parser,
     280                 :            :                           const struct rte_flow_item *items,
     281                 :            :                           const struct rte_flow_attr *attr,
     282                 :            :                           struct cpfl_flow_pr_action *pr_action);
     283                 :            : int cpfl_flow_parse_actions(struct cpfl_flow_js_parser *parser,
     284                 :            :                             const struct rte_flow_action *actions,
     285                 :            :                             struct cpfl_flow_mr_action *mr_action);
     286                 :            : bool cpfl_metadata_write_port_id(struct cpfl_itf *itf);
     287                 :            : bool cpfl_metadata_write_vsi(struct cpfl_itf *itf);
     288                 :            : bool cpfl_metadata_write_targetvsi(struct cpfl_itf *itf);
     289                 :            : bool cpfl_metadata_write_sourcevsi(struct cpfl_itf *itf);
     290                 :            : 
     291                 :            : static inline void
     292                 :            : cpfl_metadata_init(struct cpfl_metadata *meta)
     293                 :            : {
     294                 :            :         int i;
     295                 :            : 
     296                 :            :         for (i = 0; i < CPFL_META_LENGTH; i++)
     297                 :            :                 meta->chunks[i].type = i;
     298                 :            : }
     299                 :            : 
     300                 :            : static inline void
     301                 :            : cpfl_metadata_write16(struct cpfl_metadata *meta, int type, int offset, uint16_t data)
     302                 :            : {
     303                 :          0 :         memcpy(&meta->chunks[type].data[offset], &data, sizeof(uint16_t));
     304                 :            : }
     305                 :            : 
     306                 :            : static inline void
     307                 :            : cpfl_metadata_write32(struct cpfl_metadata *meta, int type, int offset, uint32_t data)
     308                 :            : {
     309                 :            :         memcpy(&meta->chunks[type].data[offset], &data, sizeof(uint32_t));
     310                 :            : }
     311                 :            : 
     312                 :            : static inline uint16_t
     313                 :            : cpfl_metadata_read16(struct cpfl_metadata *meta, int type, int offset)
     314                 :            : {
     315                 :          0 :         return *((uint16_t *)(&meta->chunks[type].data[offset]));
     316                 :            : }
     317                 :            : 
     318                 :            : #endif

Generated by: LCOV version 1.14