1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Intel Corporation
5 #ifndef _IAVF_GENERIC_FLOW_H_
6 #define _IAVF_GENERIC_FLOW_H_
8 #include <rte_flow_driver.h>
12 #define IAVF_PROT_MAC_INNER (1ULL << 1)
13 #define IAVF_PROT_MAC_OUTER (1ULL << 2)
14 #define IAVF_PROT_VLAN_INNER (1ULL << 3)
15 #define IAVF_PROT_VLAN_OUTER (1ULL << 4)
16 #define IAVF_PROT_IPV4_INNER (1ULL << 5)
17 #define IAVF_PROT_IPV4_OUTER (1ULL << 6)
18 #define IAVF_PROT_IPV6_INNER (1ULL << 7)
19 #define IAVF_PROT_IPV6_OUTER (1ULL << 8)
20 #define IAVF_PROT_TCP_INNER (1ULL << 9)
21 #define IAVF_PROT_TCP_OUTER (1ULL << 10)
22 #define IAVF_PROT_UDP_INNER (1ULL << 11)
23 #define IAVF_PROT_UDP_OUTER (1ULL << 12)
24 #define IAVF_PROT_SCTP_INNER (1ULL << 13)
25 #define IAVF_PROT_SCTP_OUTER (1ULL << 14)
26 #define IAVF_PROT_ICMP4_INNER (1ULL << 15)
27 #define IAVF_PROT_ICMP4_OUTER (1ULL << 16)
28 #define IAVF_PROT_ICMP6_INNER (1ULL << 17)
29 #define IAVF_PROT_ICMP6_OUTER (1ULL << 18)
30 #define IAVF_PROT_VXLAN (1ULL << 19)
31 #define IAVF_PROT_NVGRE (1ULL << 20)
32 #define IAVF_PROT_GTPU (1ULL << 21)
33 #define IAVF_PROT_ESP (1ULL << 22)
34 #define IAVF_PROT_AH (1ULL << 23)
35 #define IAVF_PROT_L2TPV3OIP (1ULL << 24)
36 #define IAVF_PROT_PFCP (1ULL << 25)
41 #define IAVF_SMAC (1ULL << 63)
42 #define IAVF_DMAC (1ULL << 62)
43 #define IAVF_ETHERTYPE (1ULL << 61)
44 #define IAVF_IP_SRC (1ULL << 60)
45 #define IAVF_IP_DST (1ULL << 59)
46 #define IAVF_IP_PROTO (1ULL << 58)
47 #define IAVF_IP_TTL (1ULL << 57)
48 #define IAVF_IP_TOS (1ULL << 56)
49 #define IAVF_SPORT (1ULL << 55)
50 #define IAVF_DPORT (1ULL << 54)
51 #define IAVF_ICMP_TYPE (1ULL << 53)
52 #define IAVF_ICMP_CODE (1ULL << 52)
53 #define IAVF_VXLAN_VNI (1ULL << 51)
54 #define IAVF_NVGRE_TNI (1ULL << 50)
55 #define IAVF_GTPU_TEID (1ULL << 49)
56 #define IAVF_GTPU_QFI (1ULL << 48)
57 #define IAVF_ESP_SPI (1ULL << 47)
58 #define IAVF_AH_SPI (1ULL << 46)
59 #define IAVF_L2TPV3OIP_SESSION_ID (1ULL << 45)
60 #define IAVF_PFCP_S_FIELD (1ULL << 44)
61 #define IAVF_PFCP_SEID (1ULL << 43)
65 #define IAVF_INSET_NONE 0ULL
69 #define IAVF_INSET_SMAC (IAVF_PROT_MAC_OUTER | IAVF_SMAC)
70 #define IAVF_INSET_DMAC (IAVF_PROT_MAC_OUTER | IAVF_DMAC)
71 #define IAVF_INSET_VLAN_INNER (IAVF_PROT_VLAN_INNER)
72 #define IAVF_INSET_VLAN_OUTER (IAVF_PROT_VLAN_OUTER)
73 #define IAVF_INSET_ETHERTYPE (IAVF_ETHERTYPE)
75 #define IAVF_INSET_IPV4_SRC \
76 (IAVF_PROT_IPV4_OUTER | IAVF_IP_SRC)
77 #define IAVF_INSET_IPV4_DST \
78 (IAVF_PROT_IPV4_OUTER | IAVF_IP_DST)
79 #define IAVF_INSET_IPV4_TOS \
80 (IAVF_PROT_IPV4_OUTER | IAVF_IP_TOS)
81 #define IAVF_INSET_IPV4_PROTO \
82 (IAVF_PROT_IPV4_OUTER | IAVF_IP_PROTO)
83 #define IAVF_INSET_IPV4_TTL \
84 (IAVF_PROT_IPV4_OUTER | IAVF_IP_TTL)
85 #define IAVF_INSET_IPV6_SRC \
86 (IAVF_PROT_IPV6_OUTER | IAVF_IP_SRC)
87 #define IAVF_INSET_IPV6_DST \
88 (IAVF_PROT_IPV6_OUTER | IAVF_IP_DST)
89 #define IAVF_INSET_IPV6_NEXT_HDR \
90 (IAVF_PROT_IPV6_OUTER | IAVF_IP_PROTO)
91 #define IAVF_INSET_IPV6_HOP_LIMIT \
92 (IAVF_PROT_IPV6_OUTER | IAVF_IP_TTL)
93 #define IAVF_INSET_IPV6_TC \
94 (IAVF_PROT_IPV6_OUTER | IAVF_IP_TOS)
96 #define IAVF_INSET_TCP_SRC_PORT \
97 (IAVF_PROT_TCP_OUTER | IAVF_SPORT)
98 #define IAVF_INSET_TCP_DST_PORT \
99 (IAVF_PROT_TCP_OUTER | IAVF_DPORT)
100 #define IAVF_INSET_UDP_SRC_PORT \
101 (IAVF_PROT_UDP_OUTER | IAVF_SPORT)
102 #define IAVF_INSET_UDP_DST_PORT \
103 (IAVF_PROT_UDP_OUTER | IAVF_DPORT)
104 #define IAVF_INSET_SCTP_SRC_PORT \
105 (IAVF_PROT_SCTP_OUTER | IAVF_SPORT)
106 #define IAVF_INSET_SCTP_DST_PORT \
107 (IAVF_PROT_SCTP_OUTER | IAVF_DPORT)
108 #define IAVF_INSET_ICMP4_SRC_PORT \
109 (IAVF_PROT_ICMP4_OUTER | IAVF_SPORT)
110 #define IAVF_INSET_ICMP4_DST_PORT \
111 (IAVF_PROT_ICMP4_OUTER | IAVF_DPORT)
112 #define IAVF_INSET_ICMP6_SRC_PORT \
113 (IAVF_PROT_ICMP6_OUTER | IAVF_SPORT)
114 #define IAVF_INSET_ICMP6_DST_PORT \
115 (IAVF_PROT_ICMP6_OUTER | IAVF_DPORT)
116 #define IAVF_INSET_ICMP4_TYPE \
117 (IAVF_PROT_ICMP4_OUTER | IAVF_ICMP_TYPE)
118 #define IAVF_INSET_ICMP4_CODE \
119 (IAVF_PROT_ICMP4_OUTER | IAVF_ICMP_CODE)
120 #define IAVF_INSET_ICMP6_TYPE \
121 (IAVF_PROT_ICMP6_OUTER | IAVF_ICMP_TYPE)
122 #define IAVF_INSET_ICMP6_CODE \
123 (IAVF_PROT_ICMP6_OUTER | IAVF_ICMP_CODE)
124 #define IAVF_INSET_GTPU_TEID \
125 (IAVF_PROT_GTPU | IAVF_GTPU_TEID)
126 #define IAVF_INSET_GTPU_QFI \
127 (IAVF_PROT_GTPU | IAVF_GTPU_QFI)
128 #define IAVF_INSET_ESP_SPI \
129 (IAVF_PROT_ESP | IAVF_ESP_SPI)
130 #define IAVF_INSET_AH_SPI \
131 (IAVF_PROT_AH | IAVF_AH_SPI)
132 #define IAVF_INSET_L2TPV3OIP_SESSION_ID \
133 (IAVF_PROT_L2TPV3OIP | IAVF_L2TPV3OIP_SESSION_ID)
134 #define IAVF_INSET_PFCP_S_FIELD \
135 (IAVF_PROT_PFCP | IAVF_PFCP_S_FIELD)
136 #define IAVF_INSET_PFCP_SEID \
137 (IAVF_PROT_PFCP | IAVF_PFCP_S_FIELD | IAVF_PFCP_SEID)
141 extern enum rte_flow_item_type iavf_pattern_empty[];
144 extern enum rte_flow_item_type iavf_pattern_ethertype[];
145 extern enum rte_flow_item_type iavf_pattern_ethertype_vlan[];
146 extern enum rte_flow_item_type iavf_pattern_ethertype_qinq[];
149 extern enum rte_flow_item_type iavf_pattern_eth_arp[];
151 /* non-tunnel IPv4 */
152 extern enum rte_flow_item_type iavf_pattern_eth_ipv4[];
153 extern enum rte_flow_item_type iavf_pattern_eth_vlan_ipv4[];
154 extern enum rte_flow_item_type iavf_pattern_eth_qinq_ipv4[];
155 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_udp[];
156 extern enum rte_flow_item_type iavf_pattern_eth_vlan_ipv4_udp[];
157 extern enum rte_flow_item_type iavf_pattern_eth_qinq_ipv4_udp[];
158 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_tcp[];
159 extern enum rte_flow_item_type iavf_pattern_eth_vlan_ipv4_tcp[];
160 extern enum rte_flow_item_type iavf_pattern_eth_qinq_ipv4_tcp[];
161 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_sctp[];
162 extern enum rte_flow_item_type iavf_pattern_eth_vlan_ipv4_sctp[];
163 extern enum rte_flow_item_type iavf_pattern_eth_qinq_ipv4_sctp[];
164 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_icmp[];
165 extern enum rte_flow_item_type iavf_pattern_eth_vlan_ipv4_icmp[];
166 extern enum rte_flow_item_type iavf_pattern_eth_qinq_ipv4_icmp[];
168 /* non-tunnel IPv6 */
169 extern enum rte_flow_item_type iavf_pattern_eth_ipv6[];
170 extern enum rte_flow_item_type iavf_pattern_eth_vlan_ipv6[];
171 extern enum rte_flow_item_type iavf_pattern_eth_qinq_ipv6[];
172 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_udp[];
173 extern enum rte_flow_item_type iavf_pattern_eth_vlan_ipv6_udp[];
174 extern enum rte_flow_item_type iavf_pattern_eth_qinq_ipv6_udp[];
175 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_tcp[];
176 extern enum rte_flow_item_type iavf_pattern_eth_vlan_ipv6_tcp[];
177 extern enum rte_flow_item_type iavf_pattern_eth_qinq_ipv6_tcp[];
178 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_sctp[];
179 extern enum rte_flow_item_type iavf_pattern_eth_vlan_ipv6_sctp[];
180 extern enum rte_flow_item_type iavf_pattern_eth_qinq_ipv6_sctp[];
181 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_icmp6[];
182 extern enum rte_flow_item_type iavf_pattern_eth_vlan_ipv6_icmp6[];
183 extern enum rte_flow_item_type iavf_pattern_eth_qinq_ipv6_icmp6[];
186 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpc[];
189 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu[];
190 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_eh[];
193 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpc[];
196 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu[];
197 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_eh[];
200 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_ipv4[];
201 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_ipv4_udp[];
202 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_ipv4_tcp[];
203 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_ipv4_icmp[];
206 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_ipv6[];
207 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_ipv6_udp[];
208 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_ipv6_tcp[];
209 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_ipv6_icmp[];
212 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_ipv4[];
213 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_ipv4_udp[];
214 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_ipv4_tcp[];
215 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_ipv4_icmp[];
218 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_ipv6[];
219 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_ipv6_udp[];
220 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_ipv6_tcp[];
221 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_ipv6_icmp[];
223 /* IPv4 GTPU EH IPv4 */
224 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_eh_ipv4[];
225 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_eh_ipv4_udp[];
226 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_eh_ipv4_tcp[];
227 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_eh_ipv4_icmp[];
229 /* IPv4 GTPU EH IPv6 */
230 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_eh_ipv6[];
231 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_eh_ipv6_udp[];
232 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_eh_ipv6_tcp[];
233 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_eh_ipv6_icmp[];
235 /* IPv6 GTPU EH IPv4 */
236 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_eh_ipv4[];
237 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_eh_ipv4_udp[];
238 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_eh_ipv4_tcp[];
239 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_eh_ipv4_icmp[];
241 /* IPv6 GTPU EH IPv6 */
242 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_eh_ipv6[];
243 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_eh_ipv6_udp[];
244 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_eh_ipv6_tcp[];
245 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_eh_ipv6_icmp[];
248 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_esp[];
249 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_udp_esp[];
250 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_esp[];
251 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_udp_esp[];
254 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_ah[];
255 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_ah[];
258 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_l2tpv3[];
259 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_l2tpv3[];
262 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_pfcp[];
263 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_pfcp[];
266 extern const struct rte_flow_ops iavf_flow_ops;
268 /* pattern structure */
269 struct iavf_pattern_match_item {
270 enum rte_flow_item_type *pattern_list;
271 /* pattern_list must end with RTE_FLOW_ITEM_TYPE_END */
272 uint64_t input_set_mask;
276 typedef int (*engine_init_t)(struct iavf_adapter *ad);
277 typedef void (*engine_uninit_t)(struct iavf_adapter *ad);
278 typedef int (*engine_validation_t)(struct iavf_adapter *ad,
279 struct rte_flow *flow,
281 struct rte_flow_error *error);
282 typedef int (*engine_create_t)(struct iavf_adapter *ad,
283 struct rte_flow *flow,
285 struct rte_flow_error *error);
286 typedef int (*engine_destroy_t)(struct iavf_adapter *ad,
287 struct rte_flow *flow,
288 struct rte_flow_error *error);
289 typedef int (*engine_query_t)(struct iavf_adapter *ad,
290 struct rte_flow *flow,
291 struct rte_flow_query_count *count,
292 struct rte_flow_error *error);
293 typedef void (*engine_free_t) (struct rte_flow *flow);
294 typedef int (*parse_pattern_action_t)(struct iavf_adapter *ad,
295 struct iavf_pattern_match_item *array,
297 const struct rte_flow_item pattern[],
298 const struct rte_flow_action actions[],
300 struct rte_flow_error *error);
303 enum iavf_flow_engine_type {
304 IAVF_FLOW_ENGINE_NONE = 0,
305 IAVF_FLOW_ENGINE_FDIR,
306 IAVF_FLOW_ENGINE_HASH,
307 IAVF_FLOW_ENGINE_MAX,
311 * classification stages.
312 * for non-pipeline mode, we have two classification stages: Distributor/RSS
313 * for pipeline-mode we have three classification stages:
314 * Permission/Distributor/RSS
316 enum iavf_flow_classification_stage {
317 IAVF_FLOW_STAGE_NONE = 0,
319 IAVF_FLOW_STAGE_DISTRIBUTOR,
323 /* Struct to store engine created. */
324 struct iavf_flow_engine {
325 TAILQ_ENTRY(iavf_flow_engine) node;
327 engine_uninit_t uninit;
328 engine_validation_t validation;
329 engine_create_t create;
330 engine_destroy_t destroy;
331 engine_query_t query_count;
333 enum iavf_flow_engine_type type;
336 TAILQ_HEAD(iavf_engine_list, iavf_flow_engine);
338 /* Struct to store flow created. */
340 TAILQ_ENTRY(rte_flow) node;
341 struct iavf_flow_engine *engine;
345 struct iavf_flow_parser {
346 struct iavf_flow_engine *engine;
347 struct iavf_pattern_match_item *array;
349 parse_pattern_action_t parse_pattern_action;
350 enum iavf_flow_classification_stage stage;
353 /* Struct to store parser created. */
354 struct iavf_flow_parser_node {
355 TAILQ_ENTRY(iavf_flow_parser_node) node;
356 struct iavf_flow_parser *parser;
359 void iavf_register_flow_engine(struct iavf_flow_engine *engine);
360 int iavf_flow_init(struct iavf_adapter *ad);
361 void iavf_flow_uninit(struct iavf_adapter *ad);
362 int iavf_flow_flush(struct rte_eth_dev *dev,
363 struct rte_flow_error *error);
364 int iavf_register_parser(struct iavf_flow_parser *parser,
365 struct iavf_adapter *ad);
366 void iavf_unregister_parser(struct iavf_flow_parser *parser,
367 struct iavf_adapter *ad);
368 struct iavf_pattern_match_item *
369 iavf_search_pattern_match_item(const struct rte_flow_item pattern[],
370 struct iavf_pattern_match_item *array,
372 struct rte_flow_error *error);