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_gtpu[];
187 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_eh[];
190 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu[];
191 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_eh[];
194 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_ipv4[];
195 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_ipv4_udp[];
196 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_ipv4_tcp[];
197 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_ipv4_icmp[];
200 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_ipv6[];
201 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_ipv6_udp[];
202 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_ipv6_tcp[];
203 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_ipv6_icmp[];
206 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_ipv4[];
207 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_ipv4_udp[];
208 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_ipv4_tcp[];
209 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_ipv4_icmp[];
212 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_ipv6[];
213 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_ipv6_udp[];
214 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_ipv6_tcp[];
215 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_ipv6_icmp[];
217 /* IPv4 GTPU EH IPv4 */
218 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_eh_ipv4[];
219 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_eh_ipv4_udp[];
220 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_eh_ipv4_tcp[];
221 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_eh_ipv4_icmp[];
223 /* IPv4 GTPU EH IPv6 */
224 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_eh_ipv6[];
225 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_eh_ipv6_udp[];
226 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_eh_ipv6_tcp[];
227 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_eh_ipv6_icmp[];
229 /* IPv6 GTPU EH IPv4 */
230 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_eh_ipv4[];
231 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_eh_ipv4_udp[];
232 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_eh_ipv4_tcp[];
233 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_eh_ipv4_icmp[];
235 /* IPv6 GTPU EH IPv6 */
236 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_eh_ipv6[];
237 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_eh_ipv6_udp[];
238 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_eh_ipv6_tcp[];
239 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_gtpu_eh_ipv6_icmp[];
242 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_esp[];
243 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_udp_esp[];
244 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_esp[];
245 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_udp_esp[];
248 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_ah[];
249 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_ah[];
252 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_l2tpv3[];
253 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_l2tpv3[];
256 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_pfcp[];
257 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_pfcp[];
260 extern const struct rte_flow_ops iavf_flow_ops;
262 /* pattern structure */
263 struct iavf_pattern_match_item {
264 enum rte_flow_item_type *pattern_list;
265 /* pattern_list must end with RTE_FLOW_ITEM_TYPE_END */
266 uint64_t input_set_mask;
270 typedef int (*engine_init_t)(struct iavf_adapter *ad);
271 typedef void (*engine_uninit_t)(struct iavf_adapter *ad);
272 typedef int (*engine_validation_t)(struct iavf_adapter *ad,
273 struct rte_flow *flow,
275 struct rte_flow_error *error);
276 typedef int (*engine_create_t)(struct iavf_adapter *ad,
277 struct rte_flow *flow,
279 struct rte_flow_error *error);
280 typedef int (*engine_destroy_t)(struct iavf_adapter *ad,
281 struct rte_flow *flow,
282 struct rte_flow_error *error);
283 typedef int (*engine_query_t)(struct iavf_adapter *ad,
284 struct rte_flow *flow,
285 struct rte_flow_query_count *count,
286 struct rte_flow_error *error);
287 typedef void (*engine_free_t) (struct rte_flow *flow);
288 typedef int (*parse_pattern_action_t)(struct iavf_adapter *ad,
289 struct iavf_pattern_match_item *array,
291 const struct rte_flow_item pattern[],
292 const struct rte_flow_action actions[],
294 struct rte_flow_error *error);
297 enum iavf_flow_engine_type {
298 IAVF_FLOW_ENGINE_NONE = 0,
299 IAVF_FLOW_ENGINE_FDIR,
300 IAVF_FLOW_ENGINE_HASH,
301 IAVF_FLOW_ENGINE_MAX,
305 * classification stages.
306 * for non-pipeline mode, we have two classification stages: Distributor/RSS
307 * for pipeline-mode we have three classification stages:
308 * Permission/Distributor/RSS
310 enum iavf_flow_classification_stage {
311 IAVF_FLOW_STAGE_NONE = 0,
313 IAVF_FLOW_STAGE_DISTRIBUTOR,
317 /* Struct to store engine created. */
318 struct iavf_flow_engine {
319 TAILQ_ENTRY(iavf_flow_engine) node;
321 engine_uninit_t uninit;
322 engine_validation_t validation;
323 engine_create_t create;
324 engine_destroy_t destroy;
325 engine_query_t query_count;
327 enum iavf_flow_engine_type type;
330 TAILQ_HEAD(iavf_engine_list, iavf_flow_engine);
332 /* Struct to store flow created. */
334 TAILQ_ENTRY(rte_flow) node;
335 struct iavf_flow_engine *engine;
339 struct iavf_flow_parser {
340 struct iavf_flow_engine *engine;
341 struct iavf_pattern_match_item *array;
343 parse_pattern_action_t parse_pattern_action;
344 enum iavf_flow_classification_stage stage;
347 /* Struct to store parser created. */
348 struct iavf_flow_parser_node {
349 TAILQ_ENTRY(iavf_flow_parser_node) node;
350 struct iavf_flow_parser *parser;
353 void iavf_register_flow_engine(struct iavf_flow_engine *engine);
354 int iavf_flow_init(struct iavf_adapter *ad);
355 void iavf_flow_uninit(struct iavf_adapter *ad);
356 int iavf_flow_flush(struct rte_eth_dev *dev,
357 struct rte_flow_error *error);
358 int iavf_register_parser(struct iavf_flow_parser *parser,
359 struct iavf_adapter *ad);
360 void iavf_unregister_parser(struct iavf_flow_parser *parser,
361 struct iavf_adapter *ad);
362 struct iavf_pattern_match_item *
363 iavf_search_pattern_match_item(const struct rte_flow_item pattern[],
364 struct iavf_pattern_match_item *array,
366 struct rte_flow_error *error);