net/sfc: support flow item UDP in transfer rules
[dpdk.git] / drivers / net / sfc / sfc_mae.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2019-2020 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 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 /** FW-allocatable resource context */
24 struct sfc_mae_fw_rsrc {
25         unsigned int                    refcnt;
26         RTE_STD_C11
27         union {
28                 efx_mae_aset_id_t       aset_id;
29         };
30 };
31
32 /** Action set registry entry */
33 struct sfc_mae_action_set {
34         TAILQ_ENTRY(sfc_mae_action_set) entries;
35         unsigned int                    refcnt;
36         efx_mae_actions_t               *spec;
37         struct sfc_mae_fw_rsrc          fw_rsrc;
38 };
39
40 TAILQ_HEAD(sfc_mae_action_sets, sfc_mae_action_set);
41
42 /** Options for MAE support status */
43 enum sfc_mae_status {
44         SFC_MAE_STATUS_UNKNOWN = 0,
45         SFC_MAE_STATUS_UNSUPPORTED,
46         SFC_MAE_STATUS_SUPPORTED
47 };
48
49 struct sfc_mae {
50         /** Assigned switch domain identifier */
51         uint16_t                        switch_domain_id;
52         /** Assigned switch port identifier */
53         uint16_t                        switch_port_id;
54         /** NIC support for MAE status */
55         enum sfc_mae_status             status;
56         /** Priority level limit for MAE action rules */
57         unsigned int                    nb_action_rule_prios_max;
58         /** Action set registry */
59         struct sfc_mae_action_sets      action_sets;
60 };
61
62 struct sfc_adapter;
63 struct sfc_flow_spec;
64
65 /** This implementation supports double-tagging */
66 #define SFC_MAE_MATCH_VLAN_MAX_NTAGS    (2)
67
68 /** It is possible to keep track of one item ETH and two items VLAN */
69 #define SFC_MAE_L2_MAX_NITEMS           (SFC_MAE_MATCH_VLAN_MAX_NTAGS + 1)
70
71 /** Auxiliary entry format to keep track of L2 "type" ("inner_type") */
72 struct sfc_mae_ethertype {
73         rte_be16_t      value;
74         rte_be16_t      mask;
75 };
76
77 struct sfc_mae_pattern_data {
78         /**
79          * Keeps track of "type" ("inner_type") mask and value for each
80          * parsed L2 item in a pattern. These values/masks get filled
81          * in MAE match specification at the end of parsing. Also, this
82          * information is used to conduct consistency checks:
83          *
84          * - If an item ETH is followed by a single item VLAN,
85          *   the former must have "type" set to one of supported
86          *   TPID values (0x8100, 0x88a8, 0x9100, 0x9200, 0x9300).
87          *
88          * - If an item ETH is followed by two items VLAN, the
89          *   item ETH must have "type" set to one of supported TPID
90          *   values (0x88a8, 0x9100, 0x9200, 0x9300), and the outermost
91          *   VLAN item must have "inner_type" set to TPID value 0x8100.
92          *
93          * - If a L2 item is followed by a L3 one, the former must
94          *   indicate "type" ("inner_type") which corresponds to
95          *   the protocol used in the L3 item, or 0x0000/0x0000.
96          *
97          * In turn, mapping between RTE convention (above requirements) and
98          * MAE fields is non-trivial. The following scheme indicates
99          * which item EtherTypes go to which MAE fields in the case
100          * of single tag:
101          *
102          * ETH  (0x8100)        --> VLAN0_PROTO_BE
103          * VLAN (L3 EtherType)  --> ETHER_TYPE_BE
104          *
105          * Similarly, in the case of double tagging:
106          *
107          * ETH  (0x88a8)        --> VLAN0_PROTO_BE
108          * VLAN (0x8100)        --> VLAN1_PROTO_BE
109          * VLAN (L3 EtherType)  --> ETHER_TYPE_BE
110          */
111         struct sfc_mae_ethertype        ethertypes[SFC_MAE_L2_MAX_NITEMS];
112         unsigned int                    nb_vlan_tags;
113
114         /**
115          * L3 requirement for the innermost L2 item's "type" ("inner_type").
116          * This contains one of:
117          * - 0x0800/0xffff: IPV4
118          * - 0x86dd/0xffff: IPV6
119          * - 0x0000/0x0000: no L3 item
120          */
121         struct sfc_mae_ethertype        innermost_ethertype_restriction;
122
123         /**
124          * The following two fields keep track of L3 "proto" mask and value.
125          * The corresponding fields get filled in MAE match specification
126          * at the end of parsing. Also, the information is used by a
127          * post-check to enforce consistency requirements:
128          *
129          * - If a L3 item is followed by an item TCP, the former has
130          *   its "proto" set to either 0x06/0xff or 0x00/0x00.
131          *
132          * - If a L3 item is followed by an item UDP, the former has
133          *   its "proto" set to either 0x11/0xff or 0x00/0x00.
134          */
135         uint8_t                         l3_next_proto_value;
136         uint8_t                         l3_next_proto_mask;
137
138         /*
139          * L4 requirement for L3 item's "proto".
140          * This contains one of:
141          * - 0x06/0xff: TCP
142          * - 0x11/0xff: UDP
143          * - 0x00/0x00: no L4 item
144          */
145         uint8_t                         l3_next_proto_restriction_value;
146         uint8_t                         l3_next_proto_restriction_mask;
147 };
148
149 struct sfc_mae_parse_ctx {
150         struct sfc_adapter              *sa;
151         efx_mae_match_spec_t            *match_spec_action;
152         bool                            match_mport_set;
153         struct sfc_mae_pattern_data     pattern_data;
154 };
155
156 int sfc_mae_attach(struct sfc_adapter *sa);
157 void sfc_mae_detach(struct sfc_adapter *sa);
158 sfc_flow_cleanup_cb_t sfc_mae_flow_cleanup;
159 int sfc_mae_rule_parse_pattern(struct sfc_adapter *sa,
160                                const struct rte_flow_item pattern[],
161                                struct sfc_flow_spec_mae *spec,
162                                struct rte_flow_error *error);
163 int sfc_mae_rule_parse_actions(struct sfc_adapter *sa,
164                                const struct rte_flow_action actions[],
165                                struct sfc_mae_action_set **action_setp,
166                                struct rte_flow_error *error);
167 sfc_flow_verify_cb_t sfc_mae_flow_verify;
168 sfc_flow_insert_cb_t sfc_mae_flow_insert;
169 sfc_flow_remove_cb_t sfc_mae_flow_remove;
170
171 #ifdef __cplusplus
172 }
173 #endif
174 #endif /* _SFC_MAE_H */