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_ipv4[];
188 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_eh[];
189 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_eh_ipv4[];
190 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_eh_ipv4_udp[];
191 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_eh_ipv4_tcp[];
192 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_gtpu_eh_ipv4_icmp[];
195 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_esp[];
196 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_udp_esp[];
197 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_esp[];
198 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_udp_esp[];
201 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_ah[];
202 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_ah[];
205 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_l2tpv3[];
206 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_l2tpv3[];
209 extern enum rte_flow_item_type iavf_pattern_eth_ipv4_pfcp[];
210 extern enum rte_flow_item_type iavf_pattern_eth_ipv6_pfcp[];
213 extern const struct rte_flow_ops iavf_flow_ops;
215 /* pattern structure */
216 struct iavf_pattern_match_item {
217 enum rte_flow_item_type *pattern_list;
218 /* pattern_list must end with RTE_FLOW_ITEM_TYPE_END */
219 uint64_t input_set_mask;
223 typedef int (*engine_init_t)(struct iavf_adapter *ad);
224 typedef void (*engine_uninit_t)(struct iavf_adapter *ad);
225 typedef int (*engine_validation_t)(struct iavf_adapter *ad,
226 struct rte_flow *flow,
228 struct rte_flow_error *error);
229 typedef int (*engine_create_t)(struct iavf_adapter *ad,
230 struct rte_flow *flow,
232 struct rte_flow_error *error);
233 typedef int (*engine_destroy_t)(struct iavf_adapter *ad,
234 struct rte_flow *flow,
235 struct rte_flow_error *error);
236 typedef int (*engine_query_t)(struct iavf_adapter *ad,
237 struct rte_flow *flow,
238 struct rte_flow_query_count *count,
239 struct rte_flow_error *error);
240 typedef void (*engine_free_t) (struct rte_flow *flow);
241 typedef int (*parse_pattern_action_t)(struct iavf_adapter *ad,
242 struct iavf_pattern_match_item *array,
244 const struct rte_flow_item pattern[],
245 const struct rte_flow_action actions[],
247 struct rte_flow_error *error);
250 enum iavf_flow_engine_type {
251 IAVF_FLOW_ENGINE_NONE = 0,
252 IAVF_FLOW_ENGINE_FDIR,
253 IAVF_FLOW_ENGINE_HASH,
254 IAVF_FLOW_ENGINE_MAX,
258 * classification stages.
259 * for non-pipeline mode, we have two classification stages: Distributor/RSS
260 * for pipeline-mode we have three classification stages:
261 * Permission/Distributor/RSS
263 enum iavf_flow_classification_stage {
264 IAVF_FLOW_STAGE_NONE = 0,
266 IAVF_FLOW_STAGE_DISTRIBUTOR,
270 /* Struct to store engine created. */
271 struct iavf_flow_engine {
272 TAILQ_ENTRY(iavf_flow_engine) node;
274 engine_uninit_t uninit;
275 engine_validation_t validation;
276 engine_create_t create;
277 engine_destroy_t destroy;
278 engine_query_t query_count;
280 enum iavf_flow_engine_type type;
283 TAILQ_HEAD(iavf_engine_list, iavf_flow_engine);
285 /* Struct to store flow created. */
287 TAILQ_ENTRY(rte_flow) node;
288 struct iavf_flow_engine *engine;
292 struct iavf_flow_parser {
293 struct iavf_flow_engine *engine;
294 struct iavf_pattern_match_item *array;
296 parse_pattern_action_t parse_pattern_action;
297 enum iavf_flow_classification_stage stage;
300 /* Struct to store parser created. */
301 struct iavf_flow_parser_node {
302 TAILQ_ENTRY(iavf_flow_parser_node) node;
303 struct iavf_flow_parser *parser;
306 void iavf_register_flow_engine(struct iavf_flow_engine *engine);
307 int iavf_flow_init(struct iavf_adapter *ad);
308 void iavf_flow_uninit(struct iavf_adapter *ad);
309 int iavf_flow_flush(struct rte_eth_dev *dev,
310 struct rte_flow_error *error);
311 int iavf_register_parser(struct iavf_flow_parser *parser,
312 struct iavf_adapter *ad);
313 void iavf_unregister_parser(struct iavf_flow_parser *parser,
314 struct iavf_adapter *ad);
315 struct iavf_pattern_match_item *
316 iavf_search_pattern_match_item(const struct rte_flow_item pattern[],
317 struct iavf_pattern_match_item *array,
319 struct rte_flow_error *error);