1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Intel Corporation
13 #include <rte_debug.h>
14 #include <rte_ether.h>
15 #include <rte_ethdev_driver.h>
17 #include <rte_malloc.h>
18 #include <rte_eth_ctrl.h>
19 #include <rte_tailq.h>
20 #include <rte_flow_driver.h>
23 #include "base/ice_type.h"
24 #include "base/ice_flow.h"
25 #include "ice_ethdev.h"
26 #include "ice_generic_flow.h"
28 struct rss_type_match_hdr {
30 uint64_t eth_rss_hint;
33 struct ice_hash_match_type {
41 uint8_t hash_function;
44 struct ice_hash_flow_cfg {
46 struct ice_rss_cfg rss_cfg;
50 ice_hash_init(struct ice_adapter *ad);
53 ice_hash_create(struct ice_adapter *ad,
54 struct rte_flow *flow,
56 struct rte_flow_error *error);
59 ice_hash_destroy(struct ice_adapter *ad,
60 struct rte_flow *flow,
61 struct rte_flow_error *error);
64 ice_hash_uninit(struct ice_adapter *ad);
67 ice_hash_free(struct rte_flow *flow);
70 ice_hash_parse_pattern_action(struct ice_adapter *ad,
71 struct ice_pattern_match_item *array,
73 const struct rte_flow_item pattern[],
74 const struct rte_flow_action actions[],
76 struct rte_flow_error *error);
78 /* The first member is protocol header, the second member is ETH_RSS_*. */
79 struct rss_type_match_hdr hint_empty = {
80 ICE_FLOW_SEG_HDR_NONE, 0};
81 struct rss_type_match_hdr hint_eth_ipv4 = {
82 ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV_OTHER,
83 ETH_RSS_ETH | ETH_RSS_IPV4};
84 struct rss_type_match_hdr hint_eth_ipv4_udp = {
85 ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV_OTHER |
87 ETH_RSS_ETH | ETH_RSS_NONFRAG_IPV4_UDP};
88 struct rss_type_match_hdr hint_eth_ipv4_tcp = {
89 ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV_OTHER |
91 ETH_RSS_ETH | ETH_RSS_NONFRAG_IPV4_TCP};
92 struct rss_type_match_hdr hint_eth_ipv4_sctp = {
93 ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_IPV_OTHER |
94 ICE_FLOW_SEG_HDR_SCTP,
95 ETH_RSS_ETH | ETH_RSS_NONFRAG_IPV4_SCTP};
96 struct rss_type_match_hdr hint_eth_ipv4_gtpu_eh_ipv4 = {
97 ICE_FLOW_SEG_HDR_GTPU_EH | ICE_FLOW_SEG_HDR_IPV4 |
98 ICE_FLOW_SEG_HDR_IPV_OTHER,
99 ETH_RSS_GTPU | ETH_RSS_IPV4};
100 struct rss_type_match_hdr hint_eth_ipv4_gtpu_eh_ipv4_udp = {
101 ICE_FLOW_SEG_HDR_GTPU_EH | ICE_FLOW_SEG_HDR_IPV4 |
102 ICE_FLOW_SEG_HDR_IPV_OTHER | ICE_FLOW_SEG_HDR_UDP,
103 ETH_RSS_GTPU | ETH_RSS_NONFRAG_IPV4_UDP};
104 struct rss_type_match_hdr hint_eth_ipv4_gtpu_eh_ipv4_tcp = {
105 ICE_FLOW_SEG_HDR_GTPU_EH | ICE_FLOW_SEG_HDR_IPV4 |
106 ICE_FLOW_SEG_HDR_IPV_OTHER | ICE_FLOW_SEG_HDR_TCP,
107 ETH_RSS_GTPU | ETH_RSS_NONFRAG_IPV4_TCP};
108 struct rss_type_match_hdr hint_eth_pppoes_ipv4 = {
109 ICE_FLOW_SEG_HDR_PPPOE,
110 ETH_RSS_ETH | ETH_RSS_PPPOE | ETH_RSS_IPV4};
111 struct rss_type_match_hdr hint_eth_pppoes_ipv4_udp = {
112 ICE_FLOW_SEG_HDR_PPPOE,
113 ETH_RSS_ETH | ETH_RSS_PPPOE | ETH_RSS_NONFRAG_IPV4_UDP};
114 struct rss_type_match_hdr hint_eth_pppoes_ipv4_tcp = {
115 ICE_FLOW_SEG_HDR_PPPOE,
116 ETH_RSS_ETH | ETH_RSS_PPPOE | ETH_RSS_NONFRAG_IPV4_TCP};
117 struct rss_type_match_hdr hint_eth_pppoes_ipv4_sctp = {
118 ICE_FLOW_SEG_HDR_PPPOE,
119 ETH_RSS_ETH | ETH_RSS_PPPOE | ETH_RSS_NONFRAG_IPV4_SCTP};
120 struct rss_type_match_hdr hint_eth_ipv6 = {
121 ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_IPV_OTHER,
122 ETH_RSS_ETH | ETH_RSS_IPV6};
123 struct rss_type_match_hdr hint_eth_ipv6_udp = {
124 ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_IPV_OTHER |
125 ICE_FLOW_SEG_HDR_UDP,
126 ETH_RSS_ETH | ETH_RSS_NONFRAG_IPV6_UDP};
127 struct rss_type_match_hdr hint_eth_ipv6_tcp = {
128 ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_IPV_OTHER |
129 ICE_FLOW_SEG_HDR_TCP,
130 ETH_RSS_ETH | ETH_RSS_NONFRAG_IPV6_TCP};
131 struct rss_type_match_hdr hint_eth_ipv6_sctp = {
132 ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_IPV_OTHER |
133 ICE_FLOW_SEG_HDR_SCTP,
134 ETH_RSS_ETH | ETH_RSS_NONFRAG_IPV6_SCTP};
135 struct rss_type_match_hdr hint_eth_pppoes_ipv6 = {
136 ICE_FLOW_SEG_HDR_PPPOE,
137 ETH_RSS_ETH | ETH_RSS_PPPOE | ETH_RSS_IPV6};
138 struct rss_type_match_hdr hint_eth_pppoes_ipv6_udp = {
139 ICE_FLOW_SEG_HDR_PPPOE,
140 ETH_RSS_ETH | ETH_RSS_PPPOE | ETH_RSS_NONFRAG_IPV6_UDP};
141 struct rss_type_match_hdr hint_eth_pppoes_ipv6_tcp = {
142 ICE_FLOW_SEG_HDR_PPPOE,
143 ETH_RSS_ETH | ETH_RSS_PPPOE | ETH_RSS_NONFRAG_IPV6_TCP};
144 struct rss_type_match_hdr hint_eth_pppoes_ipv6_sctp = {
145 ICE_FLOW_SEG_HDR_PPPOE,
146 ETH_RSS_ETH | ETH_RSS_PPPOE | ETH_RSS_NONFRAG_IPV6_SCTP};
147 struct rss_type_match_hdr hint_eth_pppoes = {
148 ICE_FLOW_SEG_HDR_PPPOE,
149 ETH_RSS_ETH | ETH_RSS_PPPOE};
151 /* Supported pattern for os default package. */
152 static struct ice_pattern_match_item ice_hash_pattern_list_os[] = {
153 {pattern_eth_ipv4, ICE_INSET_NONE, &hint_eth_ipv4},
154 {pattern_eth_ipv4_udp, ICE_INSET_NONE, &hint_eth_ipv4_udp},
155 {pattern_eth_ipv4_tcp, ICE_INSET_NONE, &hint_eth_ipv4_tcp},
156 {pattern_eth_ipv4_sctp, ICE_INSET_NONE, &hint_eth_ipv4_sctp},
157 {pattern_eth_ipv6, ICE_INSET_NONE, &hint_eth_ipv6},
158 {pattern_eth_ipv6_udp, ICE_INSET_NONE, &hint_eth_ipv6_udp},
159 {pattern_eth_ipv6_tcp, ICE_INSET_NONE, &hint_eth_ipv6_tcp},
160 {pattern_eth_ipv6_sctp, ICE_INSET_NONE, &hint_eth_ipv6_sctp},
161 {pattern_empty, ICE_INSET_NONE, &hint_empty},
164 /* Supported pattern for comms package. */
165 static struct ice_pattern_match_item ice_hash_pattern_list_comms[] = {
166 {pattern_empty, ICE_INSET_NONE,
168 {pattern_eth_ipv4, ICE_INSET_NONE,
170 {pattern_eth_ipv4_udp, ICE_INSET_NONE,
172 {pattern_eth_ipv4_tcp, ICE_INSET_NONE,
174 {pattern_eth_ipv4_sctp, ICE_INSET_NONE,
175 &hint_eth_ipv4_sctp},
176 {pattern_eth_ipv4_gtpu_eh_ipv4, ICE_INSET_NONE,
177 &hint_eth_ipv4_gtpu_eh_ipv4},
178 {pattern_eth_ipv4_gtpu_eh_ipv4_udp, ICE_INSET_NONE,
179 &hint_eth_ipv4_gtpu_eh_ipv4_udp},
180 {pattern_eth_ipv4_gtpu_eh_ipv4_tcp, ICE_INSET_NONE,
181 &hint_eth_ipv4_gtpu_eh_ipv4_tcp},
182 {pattern_eth_pppoes_ipv4, ICE_INSET_NONE,
183 &hint_eth_pppoes_ipv4},
184 {pattern_eth_pppoes_ipv4_udp, ICE_INSET_NONE,
185 &hint_eth_pppoes_ipv4_udp},
186 {pattern_eth_pppoes_ipv4_tcp, ICE_INSET_NONE,
187 &hint_eth_pppoes_ipv4_tcp},
188 {pattern_eth_pppoes_ipv4_sctp, ICE_INSET_NONE,
189 &hint_eth_pppoes_ipv4_sctp},
190 {pattern_eth_ipv6, ICE_INSET_NONE,
192 {pattern_eth_ipv6_udp, ICE_INSET_NONE,
194 {pattern_eth_ipv6_tcp, ICE_INSET_NONE,
196 {pattern_eth_ipv6_sctp, ICE_INSET_NONE,
197 &hint_eth_ipv6_sctp},
198 {pattern_eth_pppoes_ipv6, ICE_INSET_NONE,
199 &hint_eth_pppoes_ipv6},
200 {pattern_eth_pppoes_ipv6_udp, ICE_INSET_NONE,
201 &hint_eth_pppoes_ipv6_udp},
202 {pattern_eth_pppoes_ipv6_tcp, ICE_INSET_NONE,
203 &hint_eth_pppoes_ipv6_tcp},
204 {pattern_eth_pppoes_ipv6_sctp, ICE_INSET_NONE,
205 &hint_eth_pppoes_ipv6_sctp},
206 {pattern_eth_pppoes, ICE_INSET_NONE,
211 * The first member is input set combination,
212 * the second member is hash fields.
214 struct ice_hash_match_type ice_hash_type_list[] = {
216 ICE_FLOW_HASH_PPPOE_SESS_ID},
217 {ETH_RSS_ETH | ETH_RSS_PPPOE | ETH_RSS_L2_SRC_ONLY,
218 ICE_FLOW_HASH_PPPOE_SESS_ID |
219 BIT_ULL(ICE_FLOW_FIELD_IDX_ETH_SA)},
221 {ETH_RSS_IPV4 | ETH_RSS_L3_SRC_ONLY,
222 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA)},
223 {ETH_RSS_IPV4 | ETH_RSS_L3_DST_ONLY,
224 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA)},
225 {ETH_RSS_IPV4, ICE_FLOW_HASH_IPV4},
226 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_SRC_ONLY,
227 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA) |
228 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT) |
229 BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT)},
230 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_DST_ONLY,
231 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA) |
232 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT) |
233 BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT)},
234 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L3_SRC_ONLY,
235 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA)},
236 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_SRC_ONLY,
237 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA) |
238 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT) |
239 BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT)},
240 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_DST_ONLY,
241 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA) |
242 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT) |
243 BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT)},
244 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L3_DST_ONLY,
245 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA)},
246 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L4_SRC_ONLY,
247 BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT) |
248 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
249 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L4_DST_ONLY,
250 BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT) |
251 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
252 {ETH_RSS_NONFRAG_IPV4_UDP,
254 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
255 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_SRC_ONLY,
256 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA) |
257 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT) |
258 BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT)},
259 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_DST_ONLY,
260 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA) |
261 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT) |
262 BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT)},
263 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L3_SRC_ONLY,
264 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA)},
265 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_SRC_ONLY,
266 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA) |
267 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT) |
268 BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT)},
269 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_DST_ONLY,
270 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA) |
271 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT) |
272 BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT)},
273 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L3_DST_ONLY,
274 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA)},
275 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L4_SRC_ONLY,
276 BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT) |
277 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
278 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L4_DST_ONLY,
279 BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT) |
280 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
281 {ETH_RSS_NONFRAG_IPV4_TCP,
283 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
284 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_SRC_ONLY,
285 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA) |
286 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT) |
287 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT)},
288 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_DST_ONLY,
289 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA) |
290 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT) |
291 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)},
292 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L3_SRC_ONLY,
293 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA)},
294 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_SRC_ONLY,
295 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA) |
296 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT) |
297 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT)},
298 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_DST_ONLY,
299 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA) |
300 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT) |
301 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)},
302 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L3_DST_ONLY,
303 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA)},
304 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L4_SRC_ONLY,
305 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT) |
306 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
307 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L4_DST_ONLY,
308 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT) |
309 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
310 {ETH_RSS_NONFRAG_IPV4_SCTP,
312 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_PROT)},
314 {ETH_RSS_IPV6 | ETH_RSS_L3_SRC_ONLY,
315 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA)},
316 {ETH_RSS_IPV6 | ETH_RSS_L3_DST_ONLY,
317 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA)},
318 {ETH_RSS_IPV6, ICE_FLOW_HASH_IPV6},
319 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_SRC_ONLY,
320 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA) |
321 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT) |
322 BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT)},
323 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_DST_ONLY,
324 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA) |
325 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT) |
326 BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT)},
327 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L3_SRC_ONLY,
328 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA)},
329 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_SRC_ONLY,
330 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA) |
331 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT) |
332 BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT)},
333 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_DST_ONLY,
334 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA) |
335 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT) |
336 BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT)},
337 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L3_DST_ONLY,
338 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA)},
339 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L4_SRC_ONLY,
340 BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT) |
341 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
342 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L4_DST_ONLY,
343 BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT) |
344 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
345 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_PFCP,
346 BIT_ULL(ICE_FLOW_FIELD_IDX_PFCP_SEID)},
347 {ETH_RSS_NONFRAG_IPV6_UDP,
349 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
350 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_SRC_ONLY,
351 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA) |
352 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT) |
353 BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT)},
354 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_DST_ONLY,
355 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA) |
356 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT) |
357 BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT)},
358 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L3_SRC_ONLY,
359 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA)},
360 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_SRC_ONLY,
361 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA) |
362 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT) |
363 BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT)},
364 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_DST_ONLY,
365 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA) |
366 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT) |
367 BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT)},
368 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L3_DST_ONLY,
369 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA)},
370 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L4_SRC_ONLY,
371 BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT) |
372 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
373 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L4_DST_ONLY,
374 BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT) |
375 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
376 {ETH_RSS_NONFRAG_IPV6_TCP,
378 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
379 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_SRC_ONLY,
380 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA) |
381 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT) |
382 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT)},
383 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_DST_ONLY,
384 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA) |
385 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT) |
386 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)},
387 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L3_SRC_ONLY,
388 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA)},
389 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_SRC_ONLY,
390 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA) |
391 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT) |
392 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT)},
393 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_DST_ONLY,
394 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA) |
395 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT) |
396 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)},
397 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L3_DST_ONLY,
398 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA)},
399 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L4_SRC_ONLY,
400 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT) |
401 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
402 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L4_DST_ONLY,
403 BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT) |
404 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
405 {ETH_RSS_NONFRAG_IPV6_SCTP,
407 BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_PROT)},
410 static struct ice_flow_engine ice_hash_engine = {
411 .init = ice_hash_init,
412 .create = ice_hash_create,
413 .destroy = ice_hash_destroy,
414 .uninit = ice_hash_uninit,
415 .free = ice_hash_free,
416 .type = ICE_FLOW_ENGINE_HASH,
419 /* Register parser for os package. */
420 static struct ice_flow_parser ice_hash_parser_os = {
421 .engine = &ice_hash_engine,
422 .array = ice_hash_pattern_list_os,
423 .array_len = RTE_DIM(ice_hash_pattern_list_os),
424 .parse_pattern_action = ice_hash_parse_pattern_action,
425 .stage = ICE_FLOW_STAGE_RSS,
428 /* Register parser for comms package. */
429 static struct ice_flow_parser ice_hash_parser_comms = {
430 .engine = &ice_hash_engine,
431 .array = ice_hash_pattern_list_comms,
432 .array_len = RTE_DIM(ice_hash_pattern_list_comms),
433 .parse_pattern_action = ice_hash_parse_pattern_action,
434 .stage = ICE_FLOW_STAGE_RSS,
437 RTE_INIT(ice_hash_engine_init)
439 struct ice_flow_engine *engine = &ice_hash_engine;
440 ice_register_flow_engine(engine);
444 ice_hash_init(struct ice_adapter *ad)
446 struct ice_flow_parser *parser = NULL;
448 if (ad->hw.dcf_enabled)
451 if (ad->active_pkg_type == ICE_PKG_TYPE_OS_DEFAULT)
452 parser = &ice_hash_parser_os;
453 else if (ad->active_pkg_type == ICE_PKG_TYPE_COMMS)
454 parser = &ice_hash_parser_comms;
458 return ice_register_parser(parser, ad);
462 ice_hash_check_inset(const struct rte_flow_item pattern[],
463 struct rte_flow_error *error)
465 const struct rte_flow_item *item = pattern;
467 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
469 rte_flow_error_set(error, EINVAL,
470 RTE_FLOW_ERROR_TYPE_ITEM, item,
471 "Not support range");
475 /* Ignore spec and mask. */
476 if (item->spec || item->mask) {
477 rte_flow_error_set(error, EINVAL,
478 RTE_FLOW_ERROR_TYPE_ITEM, item,
479 "Invalid spec/mask.");
488 ice_hash_parse_action(struct ice_pattern_match_item *pattern_match_item,
489 const struct rte_flow_action actions[],
491 struct rte_flow_error *error)
493 struct rss_type_match_hdr *m = (struct rss_type_match_hdr *)
494 (pattern_match_item->meta);
495 struct rss_meta *hash_meta = (struct rss_meta *)*meta;
496 uint32_t type_list_len = RTE_DIM(ice_hash_type_list);
497 enum rte_flow_action_type action_type;
498 const struct rte_flow_action_rss *rss;
499 const struct rte_flow_action *action;
500 uint64_t combine_type;
504 /* Supported action is RSS. */
505 for (action = actions; action->type !=
506 RTE_FLOW_ACTION_TYPE_END; action++) {
507 action_type = action->type;
508 switch (action_type) {
509 case RTE_FLOW_ACTION_TYPE_RSS:
511 rss_type = rss->types;
513 /* Check hash function and save it to rss_meta. */
514 if (pattern_match_item->pattern_list !=
515 pattern_empty && rss->func ==
516 RTE_ETH_HASH_FUNCTION_SIMPLE_XOR) {
517 return rte_flow_error_set(error, ENOTSUP,
518 RTE_FLOW_ERROR_TYPE_ACTION, action,
519 "Not supported flow");
520 } else if (rss->func ==
521 RTE_ETH_HASH_FUNCTION_SIMPLE_XOR){
522 ((struct rss_meta *)*meta)->hash_function =
523 RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
525 } else if (rss->func ==
526 RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ) {
527 ((struct rss_meta *)*meta)->hash_function =
528 RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
532 return rte_flow_error_set(error, ENOTSUP,
533 RTE_FLOW_ERROR_TYPE_ACTION, action,
534 "a nonzero RSS encapsulation level is not supported");
537 return rte_flow_error_set(error, ENOTSUP,
538 RTE_FLOW_ERROR_TYPE_ACTION, action,
539 "a nonzero RSS key_len is not supported");
542 return rte_flow_error_set(error, ENOTSUP,
543 RTE_FLOW_ERROR_TYPE_ACTION, action,
544 "a non-NULL RSS queue is not supported");
547 * Check simultaneous use of SRC_ONLY and DST_ONLY
550 rss_type = rte_eth_rss_hf_refine(rss_type);
552 combine_type = ETH_RSS_L2_SRC_ONLY |
553 ETH_RSS_L2_DST_ONLY |
554 ETH_RSS_L3_SRC_ONLY |
555 ETH_RSS_L3_DST_ONLY |
556 ETH_RSS_L4_SRC_ONLY |
559 /* Check if rss types match pattern. */
560 if (rss_type & ~combine_type & ~m->eth_rss_hint) {
561 return rte_flow_error_set(error,
562 ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
563 action, "Not supported RSS types");
566 /* Find matched hash fields according to hash type. */
567 for (i = 0; i < type_list_len; i++) {
568 struct ice_hash_match_type *ht_map =
569 &ice_hash_type_list[i];
571 if (rss_type == ht_map->hash_type) {
572 hash_meta->hash_flds =
580 case RTE_FLOW_ACTION_TYPE_END:
584 rte_flow_error_set(error, EINVAL,
585 RTE_FLOW_ERROR_TYPE_ACTION, action,
595 ice_hash_parse_pattern_action(__rte_unused struct ice_adapter *ad,
596 struct ice_pattern_match_item *array,
598 const struct rte_flow_item pattern[],
599 const struct rte_flow_action actions[],
601 struct rte_flow_error *error)
604 struct ice_pattern_match_item *pattern_match_item;
605 struct rss_meta *rss_meta_ptr;
607 rss_meta_ptr = rte_zmalloc(NULL, sizeof(*rss_meta_ptr), 0);
609 rte_flow_error_set(error, EINVAL,
610 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
611 "No memory for rss_meta_ptr");
615 /* Check rss supported pattern and find matched pattern. */
616 pattern_match_item = ice_search_pattern_match_item(pattern,
617 array, array_len, error);
618 if (!pattern_match_item) {
623 ret = ice_hash_check_inset(pattern, error);
627 /* Save protocol header to rss_meta. */
628 rss_meta_ptr->pkt_hdr = ((struct rss_type_match_hdr *)
629 (pattern_match_item->meta))->hdr_mask;
631 /* Check rss action. */
632 ret = ice_hash_parse_action(pattern_match_item, actions,
633 (void **)&rss_meta_ptr, error);
637 *meta = rss_meta_ptr;
639 rte_free(rss_meta_ptr);
640 rte_free(pattern_match_item);
646 ice_hash_create(struct ice_adapter *ad,
647 struct rte_flow *flow,
649 struct rte_flow_error *error)
651 struct ice_pf *pf = &ad->pf;
652 struct ice_hw *hw = ICE_PF_TO_HW(pf);
653 struct ice_vsi *vsi = pf->main_vsi;
656 struct ice_hash_flow_cfg *filter_ptr;
658 uint32_t headermask = ((struct rss_meta *)meta)->pkt_hdr;
659 uint64_t hash_field = ((struct rss_meta *)meta)->hash_flds;
660 uint8_t hash_function = ((struct rss_meta *)meta)->hash_function;
662 filter_ptr = rte_zmalloc("ice_rss_filter",
663 sizeof(struct ice_hash_flow_cfg), 0);
665 rte_flow_error_set(error, EINVAL,
666 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
667 "No memory for filter_ptr");
671 if (hash_function == RTE_ETH_HASH_FUNCTION_SIMPLE_XOR) {
672 /* Enable registers for simple_xor hash function. */
673 reg = ICE_READ_REG(hw, VSIQF_HASH_CTL(vsi->vsi_id));
674 reg = (reg & (~VSIQF_HASH_CTL_HASH_SCHEME_M)) |
675 (2 << VSIQF_HASH_CTL_HASH_SCHEME_S);
676 ICE_WRITE_REG(hw, VSIQF_HASH_CTL(vsi->vsi_id), reg);
678 filter_ptr->simple_xor = 1;
682 filter_ptr->rss_cfg.packet_hdr = headermask;
683 filter_ptr->rss_cfg.hashed_flds = hash_field;
684 filter_ptr->rss_cfg.symm =
686 RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ);
688 ret = ice_add_rss_cfg(hw, vsi->idx,
689 filter_ptr->rss_cfg.hashed_flds,
690 filter_ptr->rss_cfg.packet_hdr,
691 filter_ptr->rss_cfg.symm);
693 rte_flow_error_set(error, EINVAL,
694 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
695 "rss flow create fail");
701 flow->rule = filter_ptr;
706 rte_free(filter_ptr);
712 ice_hash_destroy(struct ice_adapter *ad,
713 struct rte_flow *flow,
714 struct rte_flow_error *error)
716 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(ad);
717 struct ice_hw *hw = ICE_PF_TO_HW(pf);
718 struct ice_vsi *vsi = pf->main_vsi;
721 struct ice_hash_flow_cfg *filter_ptr;
723 filter_ptr = (struct ice_hash_flow_cfg *)flow->rule;
725 if (filter_ptr->simple_xor == 1) {
726 /* Return to symmetric_toeplitz state. */
727 reg = ICE_READ_REG(hw, VSIQF_HASH_CTL(vsi->vsi_id));
728 reg = (reg & (~VSIQF_HASH_CTL_HASH_SCHEME_M)) |
729 (1 << VSIQF_HASH_CTL_HASH_SCHEME_S);
730 ICE_WRITE_REG(hw, VSIQF_HASH_CTL(vsi->vsi_id), reg);
732 ret = ice_rem_rss_cfg(hw, vsi->idx,
733 filter_ptr->rss_cfg.hashed_flds,
734 filter_ptr->rss_cfg.packet_hdr);
735 /* Fixme: Ignore the error if a rule does not exist.
736 * Currently a rule for inputset change or symm turn on/off
737 * will overwrite an exist rule, while application still
738 * have 2 rte_flow handles.
740 if (ret && ret != ICE_ERR_DOES_NOT_EXIST) {
741 rte_flow_error_set(error, EINVAL,
742 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
743 "rss flow destroy fail");
748 rte_free(filter_ptr);
752 rte_free(filter_ptr);
757 ice_hash_uninit(struct ice_adapter *ad)
759 if (ad->hw.dcf_enabled)
762 if (ad->active_pkg_type == ICE_PKG_TYPE_OS_DEFAULT)
763 ice_unregister_parser(&ice_hash_parser_os, ad);
764 else if (ad->active_pkg_type == ICE_PKG_TYPE_COMMS)
765 ice_unregister_parser(&ice_hash_parser_comms, ad);
769 ice_hash_free(struct rte_flow *flow)
771 rte_free(flow->rule);