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