e991ae132c7bc4625ba443dd1cc528af9dfa3990
[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 /* 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 /* MAE-specific flow specification */
67 struct sfc_flow_spec_mae {
68         /* Desired priority level */
69         unsigned int                    priority;
70         /* EFX match specification */
71         efx_mae_match_spec_t            *match_spec;
72         /* Action set registry entry */
73         struct sfc_mae_action_set       *action_set;
74         /* Firmware-allocated rule ID */
75         efx_mae_rule_id_t               rule_id;
76 };
77
78 /* Flow specification */
79 struct sfc_flow_spec {
80         /* Flow specification type (engine-based) */
81         enum sfc_flow_spec_type type;
82
83         RTE_STD_C11
84         union {
85                 /* Filter-based (VNIC level flows) specification */
86                 struct sfc_flow_spec_filter filter;
87                 /* MAE-based (lower-level HW switch flows) specification */
88                 struct sfc_flow_spec_mae mae;
89         };
90 };
91
92 /* PMD-specific definition of the opaque type from rte_flow.h */
93 struct rte_flow {
94         struct sfc_flow_spec spec;      /* flow specification */
95         TAILQ_ENTRY(rte_flow) entries;  /* flow list entries */
96 };
97
98 TAILQ_HEAD(sfc_flow_list, rte_flow);
99
100 extern const struct rte_flow_ops sfc_flow_ops;
101
102 enum sfc_flow_item_layers {
103         SFC_FLOW_ITEM_ANY_LAYER,
104         SFC_FLOW_ITEM_START_LAYER,
105         SFC_FLOW_ITEM_L2,
106         SFC_FLOW_ITEM_L3,
107         SFC_FLOW_ITEM_L4,
108 };
109
110 /* Flow parse context types */
111 enum sfc_flow_parse_ctx_type {
112         SFC_FLOW_PARSE_CTX_FILTER = 0,
113         SFC_FLOW_PARSE_CTX_MAE,
114
115         SFC_FLOW_PARSE_CTX_NTYPES
116 };
117
118 /* Flow parse context */
119 struct sfc_flow_parse_ctx {
120         enum sfc_flow_parse_ctx_type type;
121
122         RTE_STD_C11
123         union {
124                 /* Context pointer valid for filter-based (VNIC) flows */
125                 efx_filter_spec_t *filter;
126                 /* Context pointer valid for MAE-based flows */
127                 struct sfc_mae_parse_ctx *mae;
128         };
129 };
130
131 typedef int (sfc_flow_item_parse)(const struct rte_flow_item *item,
132                                   struct sfc_flow_parse_ctx *parse_ctx,
133                                   struct rte_flow_error *error);
134
135 struct sfc_flow_item {
136         enum rte_flow_item_type type;           /* Type of item */
137         enum sfc_flow_item_layers layer;        /* Layer of item */
138         enum sfc_flow_item_layers prev_layer;   /* Previous layer of item */
139         enum sfc_flow_parse_ctx_type ctx_type;  /* Parse context type */
140         sfc_flow_item_parse *parse;             /* Parsing function */
141 };
142
143 int sfc_flow_parse_pattern(const struct sfc_flow_item *flow_items,
144                            unsigned int nb_flow_items,
145                            const struct rte_flow_item pattern[],
146                            struct sfc_flow_parse_ctx *parse_ctx,
147                            struct rte_flow_error *error);
148
149 int sfc_flow_parse_init(const struct rte_flow_item *item,
150                         const void **spec_ptr,
151                         const void **mask_ptr,
152                         const void *supp_mask,
153                         const void *def_mask,
154                         unsigned int size,
155                         struct rte_flow_error *error);
156
157 struct sfc_adapter;
158
159 void sfc_flow_init(struct sfc_adapter *sa);
160 void sfc_flow_fini(struct sfc_adapter *sa);
161 int sfc_flow_start(struct sfc_adapter *sa);
162 void sfc_flow_stop(struct sfc_adapter *sa);
163
164 typedef int (sfc_flow_parse_cb_t)(struct rte_eth_dev *dev,
165                                   const struct rte_flow_item items[],
166                                   const struct rte_flow_action actions[],
167                                   struct rte_flow *flow,
168                                   struct rte_flow_error *error);
169
170 typedef int (sfc_flow_verify_cb_t)(struct sfc_adapter *sa,
171                                    struct rte_flow *flow);
172
173 typedef void (sfc_flow_cleanup_cb_t)(struct sfc_adapter *sa,
174                                      struct rte_flow *flow);
175
176 typedef int (sfc_flow_insert_cb_t)(struct sfc_adapter *sa,
177                                    struct rte_flow *flow);
178
179 typedef int (sfc_flow_remove_cb_t)(struct sfc_adapter *sa,
180                                    struct rte_flow *flow);
181
182 #ifdef __cplusplus
183 }
184 #endif
185 #endif /* _SFC_FLOW_H */