net/sfc: implement flow insert/remove in MAE backend
[dpdk.git] / drivers / net / sfc / sfc_flow.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2019-2020 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 /* RSS configuration storage */
30 struct sfc_flow_rss {
31         unsigned int    rxq_hw_index_min;
32         unsigned int    rxq_hw_index_max;
33         unsigned int    rss_hash_types;
34         uint8_t         rss_key[EFX_RSS_KEY_SIZE];
35         unsigned int    rss_tbl[EFX_RSS_TBL_SIZE];
36 };
37
38 /* Flow engines supported by the implementation */
39 enum sfc_flow_spec_type {
40         SFC_FLOW_SPEC_FILTER = 0,
41         SFC_FLOW_SPEC_MAE,
42
43         SFC_FLOW_SPEC_NTYPES
44 };
45
46 /* VNIC-specific flow specification */
47 struct sfc_flow_spec_filter {
48         /* partial specification from flow rule */
49         efx_filter_spec_t template;
50         /* fully elaborated hardware filters specifications */
51         efx_filter_spec_t filters[SF_FLOW_SPEC_NB_FILTERS_MAX];
52         /* number of complete specifications */
53         unsigned int count;
54         /* RSS toggle */
55         boolean_t rss;
56         /* RSS hash toggle */
57         boolean_t rss_hash_required;
58         /* RSS configuration */
59         struct sfc_flow_rss rss_conf;
60 };
61
62 /* MAE-specific flow specification */
63 struct sfc_flow_spec_mae {
64         /* Desired priority level */
65         unsigned int                    priority;
66         /* EFX match specification */
67         efx_mae_match_spec_t            *match_spec;
68         /* Action set registry entry */
69         struct sfc_mae_action_set       *action_set;
70         /* Firmware-allocated rule ID */
71         efx_mae_rule_id_t               rule_id;
72 };
73
74 /* Flow specification */
75 struct sfc_flow_spec {
76         /* Flow specification type (engine-based) */
77         enum sfc_flow_spec_type type;
78
79         RTE_STD_C11
80         union {
81                 /* Filter-based (VNIC level flows) specification */
82                 struct sfc_flow_spec_filter filter;
83                 /* MAE-based (lower-level HW switch flows) specification */
84                 struct sfc_flow_spec_mae mae;
85         };
86 };
87
88 /* PMD-specific definition of the opaque type from rte_flow.h */
89 struct rte_flow {
90         struct sfc_flow_spec spec;      /* flow specification */
91         TAILQ_ENTRY(rte_flow) entries;  /* flow list entries */
92 };
93
94 TAILQ_HEAD(sfc_flow_list, rte_flow);
95
96 extern const struct rte_flow_ops sfc_flow_ops;
97
98 enum sfc_flow_item_layers {
99         SFC_FLOW_ITEM_ANY_LAYER,
100         SFC_FLOW_ITEM_START_LAYER,
101         SFC_FLOW_ITEM_L2,
102         SFC_FLOW_ITEM_L3,
103         SFC_FLOW_ITEM_L4,
104 };
105
106 /* Flow parse context types */
107 enum sfc_flow_parse_ctx_type {
108         SFC_FLOW_PARSE_CTX_FILTER = 0,
109         SFC_FLOW_PARSE_CTX_MAE,
110
111         SFC_FLOW_PARSE_CTX_NTYPES
112 };
113
114 /* Flow parse context */
115 struct sfc_flow_parse_ctx {
116         enum sfc_flow_parse_ctx_type type;
117
118         RTE_STD_C11
119         union {
120                 /* Context pointer valid for filter-based (VNIC) flows */
121                 efx_filter_spec_t *filter;
122                 /* Context pointer valid for MAE-based flows */
123                 struct sfc_mae_parse_ctx *mae;
124         };
125 };
126
127 typedef int (sfc_flow_item_parse)(const struct rte_flow_item *item,
128                                   struct sfc_flow_parse_ctx *parse_ctx,
129                                   struct rte_flow_error *error);
130
131 struct sfc_flow_item {
132         enum rte_flow_item_type type;           /* Type of item */
133         enum sfc_flow_item_layers layer;        /* Layer of item */
134         enum sfc_flow_item_layers prev_layer;   /* Previous layer of item */
135         enum sfc_flow_parse_ctx_type ctx_type;  /* Parse context type */
136         sfc_flow_item_parse *parse;             /* Parsing function */
137 };
138
139 int sfc_flow_parse_pattern(const struct sfc_flow_item *flow_items,
140                            unsigned int nb_flow_items,
141                            const struct rte_flow_item pattern[],
142                            struct sfc_flow_parse_ctx *parse_ctx,
143                            struct rte_flow_error *error);
144
145 int sfc_flow_parse_init(const struct rte_flow_item *item,
146                         const void **spec_ptr,
147                         const void **mask_ptr,
148                         const void *supp_mask,
149                         const void *def_mask,
150                         unsigned int size,
151                         struct rte_flow_error *error);
152
153 struct sfc_adapter;
154
155 void sfc_flow_init(struct sfc_adapter *sa);
156 void sfc_flow_fini(struct sfc_adapter *sa);
157 int sfc_flow_start(struct sfc_adapter *sa);
158 void sfc_flow_stop(struct sfc_adapter *sa);
159
160 typedef int (sfc_flow_parse_cb_t)(struct rte_eth_dev *dev,
161                                   const struct rte_flow_item items[],
162                                   const struct rte_flow_action actions[],
163                                   struct rte_flow *flow,
164                                   struct rte_flow_error *error);
165
166 typedef int (sfc_flow_verify_cb_t)(struct sfc_adapter *sa,
167                                    struct rte_flow *flow);
168
169 typedef void (sfc_flow_cleanup_cb_t)(struct sfc_adapter *sa,
170                                      struct rte_flow *flow);
171
172 typedef int (sfc_flow_insert_cb_t)(struct sfc_adapter *sa,
173                                    struct rte_flow *flow);
174
175 typedef int (sfc_flow_remove_cb_t)(struct sfc_adapter *sa,
176                                    struct rte_flow *flow);
177
178 #ifdef __cplusplus
179 }
180 #endif
181 #endif /* _SFC_FLOW_H */