ada3d563ad9078b88966291d2424505df4017156
[dpdk.git] / drivers / net / sfc / sfc_flow.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2019-2021 Xilinx, Inc.
4  * Copyright(c) 2017-2019 Solarflare Communications Inc.
5  *
6  * This software was jointly developed between OKTET Labs (under contract
7  * for Solarflare) and Solarflare Communications, Inc.
8  */
9
10 #ifndef _SFC_FLOW_H
11 #define _SFC_FLOW_H
12
13 #include <rte_tailq.h>
14 #include <rte_flow_driver.h>
15
16 #include "efx.h"
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 /*
23  * The maximum number of fully elaborated hardware filter specifications
24  * which can be produced from a template by means of multiplication, if
25  * missing match flags are needed to be taken into account
26  */
27 #define SF_FLOW_SPEC_NB_FILTERS_MAX 8
28
29 /* Used to guard action masks */
30 #define SFC_BUILD_SET_OVERFLOW(_action, _set) \
31         RTE_BUILD_BUG_ON((_action) >= sizeof(_set) * CHAR_BIT)
32
33 /* RSS configuration storage */
34 struct sfc_flow_rss {
35         unsigned int    rxq_hw_index_min;
36         unsigned int    rxq_hw_index_max;
37         unsigned int    rss_hash_types;
38         uint8_t         rss_key[EFX_RSS_KEY_SIZE];
39         unsigned int    rss_tbl[EFX_RSS_TBL_SIZE];
40 };
41
42 /* Flow engines supported by the implementation */
43 enum sfc_flow_spec_type {
44         SFC_FLOW_SPEC_FILTER = 0,
45         SFC_FLOW_SPEC_MAE,
46
47         SFC_FLOW_SPEC_NTYPES
48 };
49
50 /* VNIC-specific flow specification */
51 struct sfc_flow_spec_filter {
52         /* partial specification from flow rule */
53         efx_filter_spec_t template;
54         /* fully elaborated hardware filters specifications */
55         efx_filter_spec_t filters[SF_FLOW_SPEC_NB_FILTERS_MAX];
56         /* number of complete specifications */
57         unsigned int count;
58         /* RSS toggle */
59         boolean_t rss;
60         /* RSS hash toggle */
61         boolean_t rss_hash_required;
62         /* RSS configuration */
63         struct sfc_flow_rss rss_conf;
64 };
65
66 /* Indicates the role of a given flow in tunnel offload */
67 enum sfc_flow_tunnel_rule_type {
68         /* The flow has nothing to do with tunnel offload */
69         SFC_FT_RULE_NONE = 0,
70         /* The flow represents a JUMP rule */
71         SFC_FT_RULE_JUMP,
72 };
73
74 /* MAE-specific flow specification */
75 struct sfc_flow_spec_mae {
76         /* FLow Tunnel (FT) rule type (or NONE) */
77         enum sfc_flow_tunnel_rule_type  ft_rule_type;
78         /* Flow Tunnel (FT) context (or NULL) */
79         struct sfc_flow_tunnel          *ft;
80         /* Desired priority level */
81         unsigned int                    priority;
82         /* Outer rule registry entry */
83         struct sfc_mae_outer_rule       *outer_rule;
84         /* EFX match specification */
85         efx_mae_match_spec_t            *match_spec;
86         /* Action set registry entry */
87         struct sfc_mae_action_set       *action_set;
88         /* Firmware-allocated rule ID */
89         efx_mae_rule_id_t               rule_id;
90 };
91
92 /* Flow specification */
93 struct sfc_flow_spec {
94         /* Flow specification type (engine-based) */
95         enum sfc_flow_spec_type type;
96
97         RTE_STD_C11
98         union {
99                 /* Filter-based (VNIC level flows) specification */
100                 struct sfc_flow_spec_filter filter;
101                 /* MAE-based (lower-level HW switch flows) specification */
102                 struct sfc_flow_spec_mae mae;
103         };
104 };
105
106 /* PMD-specific definition of the opaque type from rte_flow.h */
107 struct rte_flow {
108         struct sfc_flow_spec spec;      /* flow specification */
109         TAILQ_ENTRY(rte_flow) entries;  /* flow list entries */
110 };
111
112 TAILQ_HEAD(sfc_flow_list, rte_flow);
113
114 extern const struct rte_flow_ops sfc_flow_ops;
115
116 enum sfc_flow_item_layers {
117         SFC_FLOW_ITEM_ANY_LAYER,
118         SFC_FLOW_ITEM_START_LAYER,
119         SFC_FLOW_ITEM_L2,
120         SFC_FLOW_ITEM_L3,
121         SFC_FLOW_ITEM_L4,
122 };
123
124 /* Flow parse context types */
125 enum sfc_flow_parse_ctx_type {
126         SFC_FLOW_PARSE_CTX_FILTER = 0,
127         SFC_FLOW_PARSE_CTX_MAE,
128
129         SFC_FLOW_PARSE_CTX_NTYPES
130 };
131
132 /* Flow parse context */
133 struct sfc_flow_parse_ctx {
134         enum sfc_flow_parse_ctx_type type;
135
136         RTE_STD_C11
137         union {
138                 /* Context pointer valid for filter-based (VNIC) flows */
139                 efx_filter_spec_t *filter;
140                 /* Context pointer valid for MAE-based flows */
141                 struct sfc_mae_parse_ctx *mae;
142         };
143 };
144
145 typedef int (sfc_flow_item_parse)(const struct rte_flow_item *item,
146                                   struct sfc_flow_parse_ctx *parse_ctx,
147                                   struct rte_flow_error *error);
148
149 struct sfc_flow_item {
150         enum rte_flow_item_type type;           /* Type of item */
151         const char *name;                       /* Item name */
152         enum sfc_flow_item_layers layer;        /* Layer of item */
153         enum sfc_flow_item_layers prev_layer;   /* Previous layer of item */
154         enum sfc_flow_parse_ctx_type ctx_type;  /* Parse context type */
155         sfc_flow_item_parse *parse;             /* Parsing function */
156 };
157
158 struct sfc_adapter;
159
160 int sfc_flow_parse_pattern(struct sfc_adapter *sa,
161                            const struct sfc_flow_item *flow_items,
162                            unsigned int nb_flow_items,
163                            const struct rte_flow_item pattern[],
164                            struct sfc_flow_parse_ctx *parse_ctx,
165                            struct rte_flow_error *error);
166
167 int sfc_flow_parse_init(const struct rte_flow_item *item,
168                         const void **spec_ptr,
169                         const void **mask_ptr,
170                         const void *supp_mask,
171                         const void *def_mask,
172                         unsigned int size,
173                         struct rte_flow_error *error);
174
175 void sfc_flow_init(struct sfc_adapter *sa);
176 void sfc_flow_fini(struct sfc_adapter *sa);
177 int sfc_flow_start(struct sfc_adapter *sa);
178 void sfc_flow_stop(struct sfc_adapter *sa);
179
180 typedef int (sfc_flow_parse_cb_t)(struct rte_eth_dev *dev,
181                                   const struct rte_flow_item items[],
182                                   const struct rte_flow_action actions[],
183                                   struct rte_flow *flow,
184                                   struct rte_flow_error *error);
185
186 typedef int (sfc_flow_verify_cb_t)(struct sfc_adapter *sa,
187                                    struct rte_flow *flow);
188
189 typedef void (sfc_flow_cleanup_cb_t)(struct sfc_adapter *sa,
190                                      struct rte_flow *flow);
191
192 typedef int (sfc_flow_insert_cb_t)(struct sfc_adapter *sa,
193                                    struct rte_flow *flow);
194
195 typedef int (sfc_flow_remove_cb_t)(struct sfc_adapter *sa,
196                                    struct rte_flow *flow);
197
198 typedef int (sfc_flow_query_cb_t)(struct rte_eth_dev *dev,
199                                   struct rte_flow *flow,
200                                   const struct rte_flow_action *action,
201                                   void *data,
202                                   struct rte_flow_error *error);
203
204 #ifdef __cplusplus
205 }
206 #endif
207 #endif /* _SFC_FLOW_H */