net/sfc: support flow action count in transfer rules
[dpdk.git] / drivers / net / sfc / sfc_mae.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2019-2021 Xilinx, Inc.
4  * Copyright(c) 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_MAE_H
11 #define _SFC_MAE_H
12
13 #include <stdbool.h>
14
15 #include <rte_spinlock.h>
16
17 #include "efx.h"
18
19 #include "sfc_stats.h"
20
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24
25 /** FW-allocatable resource context */
26 struct sfc_mae_fw_rsrc {
27         unsigned int                    refcnt;
28         RTE_STD_C11
29         union {
30                 efx_mae_aset_id_t       aset_id;
31                 efx_mae_rule_id_t       rule_id;
32                 efx_mae_eh_id_t         eh_id;
33         };
34 };
35
36 /** Outer rule registry entry */
37 struct sfc_mae_outer_rule {
38         TAILQ_ENTRY(sfc_mae_outer_rule) entries;
39         unsigned int                    refcnt;
40         efx_mae_match_spec_t            *match_spec;
41         efx_tunnel_protocol_t           encap_type;
42         struct sfc_mae_fw_rsrc          fw_rsrc;
43 };
44
45 TAILQ_HEAD(sfc_mae_outer_rules, sfc_mae_outer_rule);
46
47 /** Encap. header registry entry */
48 struct sfc_mae_encap_header {
49         TAILQ_ENTRY(sfc_mae_encap_header)       entries;
50         unsigned int                            refcnt;
51         uint8_t                                 *buf;
52         size_t                                  size;
53         efx_tunnel_protocol_t                   type;
54         struct sfc_mae_fw_rsrc                  fw_rsrc;
55 };
56
57 TAILQ_HEAD(sfc_mae_encap_headers, sfc_mae_encap_header);
58
59 /* Counter ID */
60 struct sfc_mae_counter_id {
61         /* ID of a counter in MAE */
62         efx_counter_t                   mae_id;
63         /* ID of a counter in RTE */
64         uint32_t                        rte_id;
65 };
66
67 /** Action set registry entry */
68 struct sfc_mae_action_set {
69         TAILQ_ENTRY(sfc_mae_action_set) entries;
70         unsigned int                    refcnt;
71         struct sfc_mae_counter_id       *counters;
72         uint32_t                        n_counters;
73         efx_mae_actions_t               *spec;
74         struct sfc_mae_encap_header     *encap_header;
75         struct sfc_mae_fw_rsrc          fw_rsrc;
76 };
77
78 TAILQ_HEAD(sfc_mae_action_sets, sfc_mae_action_set);
79
80 /** Options for MAE support status */
81 enum sfc_mae_status {
82         SFC_MAE_STATUS_UNKNOWN = 0,
83         SFC_MAE_STATUS_UNSUPPORTED,
84         SFC_MAE_STATUS_SUPPORTED
85 };
86
87 /*
88  * Encap. header bounce buffer. It is used to store header data
89  * when parsing the header definition in the action VXLAN_ENCAP.
90  */
91 struct sfc_mae_bounce_eh {
92         uint8_t                         *buf;
93         size_t                          buf_size;
94         size_t                          size;
95         efx_tunnel_protocol_t           type;
96 };
97
98 /** Counter collection entry */
99 struct sfc_mae_counter {
100         bool                            inuse;
101         uint32_t                        generation_count;
102         union sfc_pkts_bytes            value;
103         union sfc_pkts_bytes            reset;
104 };
105
106 struct sfc_mae_counters_xstats {
107         uint64_t                        not_inuse_update;
108         uint64_t                        realloc_update;
109 };
110
111 struct sfc_mae_counters {
112         /** An array of all MAE counters */
113         struct sfc_mae_counter          *mae_counters;
114         /** Extra statistics for counters */
115         struct sfc_mae_counters_xstats  xstats;
116         /** Count of all MAE counters */
117         unsigned int                    n_mae_counters;
118 };
119
120 struct sfc_mae_counter_registry {
121         /* Common counter information */
122         /** Counters collection */
123         struct sfc_mae_counters         counters;
124
125         /* Information used by counter update service */
126         /** Callback to get packets from RxQ */
127         eth_rx_burst_t                  rx_pkt_burst;
128         /** Data for the callback to get packets */
129         struct sfc_dp_rxq               *rx_dp;
130         /** Number of buffers pushed to the RxQ */
131         unsigned int                    pushed_n_buffers;
132         /** Are credits used by counter stream */
133         bool                            use_credits;
134
135         /* Information used by configuration routines */
136         /** Counter service core ID */
137         uint32_t                        service_core_id;
138         /** Counter service ID */
139         uint32_t                        service_id;
140 };
141
142 struct sfc_mae {
143         /** Assigned switch domain identifier */
144         uint16_t                        switch_domain_id;
145         /** Assigned switch port identifier */
146         uint16_t                        switch_port_id;
147         /** NIC support for MAE status */
148         enum sfc_mae_status             status;
149         /** Priority level limit for MAE outer rules */
150         unsigned int                    nb_outer_rule_prios_max;
151         /** Priority level limit for MAE action rules */
152         unsigned int                    nb_action_rule_prios_max;
153         /** Encapsulation support status */
154         uint32_t                        encap_types_supported;
155         /** Outer rule registry */
156         struct sfc_mae_outer_rules      outer_rules;
157         /** Encap. header registry */
158         struct sfc_mae_encap_headers    encap_headers;
159         /** Action set registry */
160         struct sfc_mae_action_sets      action_sets;
161         /** Encap. header bounce buffer */
162         struct sfc_mae_bounce_eh        bounce_eh;
163         /** Flag indicating whether counter-only RxQ is running */
164         bool                            counter_rxq_running;
165         /** Counter registry */
166         struct sfc_mae_counter_registry counter_registry;
167 };
168
169 struct sfc_adapter;
170 struct sfc_flow_spec;
171
172 /** This implementation supports double-tagging */
173 #define SFC_MAE_MATCH_VLAN_MAX_NTAGS    (2)
174
175 /** It is possible to keep track of one item ETH and two items VLAN */
176 #define SFC_MAE_L2_MAX_NITEMS           (SFC_MAE_MATCH_VLAN_MAX_NTAGS + 1)
177
178 /** Auxiliary entry format to keep track of L2 "type" ("inner_type") */
179 struct sfc_mae_ethertype {
180         rte_be16_t      value;
181         rte_be16_t      mask;
182 };
183
184 struct sfc_mae_pattern_data {
185         /**
186          * Keeps track of "type" ("inner_type") mask and value for each
187          * parsed L2 item in a pattern. These values/masks get filled
188          * in MAE match specification at the end of parsing. Also, this
189          * information is used to conduct consistency checks:
190          *
191          * - If an item ETH is followed by a single item VLAN,
192          *   the former must have "type" set to one of supported
193          *   TPID values (0x8100, 0x88a8, 0x9100, 0x9200, 0x9300),
194          *   or 0x0000/0x0000.
195          *
196          * - If an item ETH is followed by two items VLAN, the
197          *   item ETH must have "type" set to one of supported TPID
198          *   values (0x88a8, 0x9100, 0x9200, 0x9300), or 0x0000/0x0000,
199          *   and the outermost VLAN item must have "inner_type" set
200          *   to TPID value 0x8100, or 0x0000/0x0000
201          *
202          * - If a L2 item is followed by a L3 one, the former must
203          *   indicate "type" ("inner_type") which corresponds to
204          *   the protocol used in the L3 item, or 0x0000/0x0000.
205          *
206          * In turn, mapping between RTE convention (above requirements) and
207          * MAE fields is non-trivial. The following scheme indicates
208          * which item EtherTypes go to which MAE fields in the case
209          * of single tag:
210          *
211          * ETH  (0x8100)        --> VLAN0_PROTO_BE
212          * VLAN (L3 EtherType)  --> ETHER_TYPE_BE
213          *
214          * Similarly, in the case of double tagging:
215          *
216          * ETH  (0x88a8)        --> VLAN0_PROTO_BE
217          * VLAN (0x8100)        --> VLAN1_PROTO_BE
218          * VLAN (L3 EtherType)  --> ETHER_TYPE_BE
219          */
220         struct sfc_mae_ethertype        ethertypes[SFC_MAE_L2_MAX_NITEMS];
221
222         rte_be16_t                      tci_masks[SFC_MAE_MATCH_VLAN_MAX_NTAGS];
223
224         unsigned int                    nb_vlan_tags;
225
226         /**
227          * L3 requirement for the innermost L2 item's "type" ("inner_type").
228          * This contains one of:
229          * - 0x0800/0xffff: IPV4
230          * - 0x86dd/0xffff: IPV6
231          * - 0x0000/0x0000: no L3 item
232          */
233         struct sfc_mae_ethertype        innermost_ethertype_restriction;
234
235         /**
236          * The following two fields keep track of L3 "proto" mask and value.
237          * The corresponding fields get filled in MAE match specification
238          * at the end of parsing. Also, the information is used by a
239          * post-check to enforce consistency requirements:
240          *
241          * - If a L3 item is followed by an item TCP, the former has
242          *   its "proto" set to either 0x06/0xff or 0x00/0x00.
243          *
244          * - If a L3 item is followed by an item UDP, the former has
245          *   its "proto" set to either 0x11/0xff or 0x00/0x00.
246          */
247         uint8_t                         l3_next_proto_value;
248         uint8_t                         l3_next_proto_mask;
249
250         /*
251          * L4 requirement for L3 item's "proto".
252          * This contains one of:
253          * - 0x06/0xff: TCP
254          * - 0x11/0xff: UDP
255          * - 0x00/0x00: no L4 item
256          */
257         uint8_t                         l3_next_proto_restriction_value;
258         uint8_t                         l3_next_proto_restriction_mask;
259
260         /* Projected state of EFX_MAE_FIELD_HAS_OVLAN match bit */
261         bool                            has_ovlan_value;
262         bool                            has_ovlan_mask;
263
264         /* Projected state of EFX_MAE_FIELD_HAS_IVLAN match bit */
265         bool                            has_ivlan_value;
266         bool                            has_ivlan_mask;
267 };
268
269 struct sfc_mae_parse_ctx {
270         struct sfc_adapter              *sa;
271         efx_mae_match_spec_t            *match_spec_action;
272         efx_mae_match_spec_t            *match_spec_outer;
273         /*
274          * This points to either of the above two specifications depending
275          * on which part of the pattern is being parsed (outer / inner).
276          */
277         efx_mae_match_spec_t            *match_spec;
278         /*
279          * This points to either "field_ids_remap_to_encap"
280          * or "field_ids_no_remap" (see sfc_mae.c) depending on
281          * which part of the pattern is being parsed.
282          */
283         const efx_mae_field_id_t        *field_ids_remap;
284         /* These two fields correspond to the tunnel-specific default mask. */
285         size_t                          tunnel_def_mask_size;
286         const void                      *tunnel_def_mask;
287         bool                            match_mport_set;
288         struct sfc_mae_pattern_data     pattern_data;
289         efx_tunnel_protocol_t           encap_type;
290         unsigned int                    priority;
291 };
292
293 int sfc_mae_attach(struct sfc_adapter *sa);
294 void sfc_mae_detach(struct sfc_adapter *sa);
295 sfc_flow_cleanup_cb_t sfc_mae_flow_cleanup;
296 int sfc_mae_rule_parse_pattern(struct sfc_adapter *sa,
297                                const struct rte_flow_item pattern[],
298                                struct sfc_flow_spec_mae *spec,
299                                struct rte_flow_error *error);
300 int sfc_mae_rule_parse_actions(struct sfc_adapter *sa,
301                                const struct rte_flow_action actions[],
302                                struct sfc_flow_spec_mae *spec_mae,
303                                struct rte_flow_error *error);
304 sfc_flow_verify_cb_t sfc_mae_flow_verify;
305 sfc_flow_insert_cb_t sfc_mae_flow_insert;
306 sfc_flow_remove_cb_t sfc_mae_flow_remove;
307
308 #ifdef __cplusplus
309 }
310 #endif
311 #endif /* _SFC_MAE_H */