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_0 = {
80 ICE_FLOW_SEG_HDR_NONE, 0};
81 struct rss_type_match_hdr hint_1 = {
82 ICE_FLOW_SEG_HDR_IPV4, ETH_RSS_IPV4};
83 struct rss_type_match_hdr hint_2 = {
84 ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_UDP, ETH_RSS_NONFRAG_IPV4_UDP};
85 struct rss_type_match_hdr hint_3 = {
86 ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_TCP, ETH_RSS_NONFRAG_IPV4_TCP};
87 struct rss_type_match_hdr hint_4 = {
88 ICE_FLOW_SEG_HDR_IPV4 | ICE_FLOW_SEG_HDR_SCTP, ETH_RSS_NONFRAG_IPV4_SCTP};
89 struct rss_type_match_hdr hint_5 = {
90 ICE_FLOW_SEG_HDR_IPV6, ETH_RSS_IPV6};
91 struct rss_type_match_hdr hint_6 = {
92 ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_UDP, ETH_RSS_NONFRAG_IPV6_UDP};
93 struct rss_type_match_hdr hint_7 = {
94 ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_TCP, ETH_RSS_NONFRAG_IPV6_TCP};
95 struct rss_type_match_hdr hint_8 = {
96 ICE_FLOW_SEG_HDR_IPV6 | ICE_FLOW_SEG_HDR_SCTP, ETH_RSS_NONFRAG_IPV6_SCTP};
97 struct rss_type_match_hdr hint_9 = {
98 ICE_FLOW_SEG_HDR_GTPU_IP, ETH_RSS_IPV4};
99 struct rss_type_match_hdr hint_10 = {
100 ICE_FLOW_SEG_HDR_PPPOE, ETH_RSS_IPV4};
101 struct rss_type_match_hdr hint_11 = {
102 ICE_FLOW_SEG_HDR_PPPOE, ETH_RSS_NONFRAG_IPV4_UDP};
103 struct rss_type_match_hdr hint_12 = {
104 ICE_FLOW_SEG_HDR_PPPOE, ETH_RSS_NONFRAG_IPV4_TCP};
105 struct rss_type_match_hdr hint_13 = {
106 ICE_FLOW_SEG_HDR_PPPOE, ETH_RSS_NONFRAG_IPV4_SCTP};
108 /* Supported pattern for os default package. */
109 static struct ice_pattern_match_item ice_hash_pattern_list_os[] = {
110 {pattern_eth_ipv4, ICE_INSET_NONE, &hint_1},
111 {pattern_eth_ipv4_udp, ICE_INSET_NONE, &hint_2},
112 {pattern_eth_ipv4_tcp, ICE_INSET_NONE, &hint_3},
113 {pattern_eth_ipv4_sctp, ICE_INSET_NONE, &hint_4},
114 {pattern_eth_ipv6, ICE_INSET_NONE, &hint_5},
115 {pattern_eth_ipv6_udp, ICE_INSET_NONE, &hint_6},
116 {pattern_eth_ipv6_tcp, ICE_INSET_NONE, &hint_7},
117 {pattern_eth_ipv6_sctp, ICE_INSET_NONE, &hint_8},
118 {pattern_empty, ICE_INSET_NONE, &hint_0},
121 /* Supported pattern for comms package. */
122 static struct ice_pattern_match_item ice_hash_pattern_list_comms[] = {
123 {pattern_eth_ipv4, ICE_INSET_NONE, &hint_1},
124 {pattern_eth_ipv4_udp, ICE_INSET_NONE, &hint_2},
125 {pattern_eth_ipv4_tcp, ICE_INSET_NONE, &hint_3},
126 {pattern_eth_ipv4_sctp, ICE_INSET_NONE, &hint_4},
127 {pattern_eth_ipv6, ICE_INSET_NONE, &hint_5},
128 {pattern_eth_ipv6_udp, ICE_INSET_NONE, &hint_6},
129 {pattern_eth_ipv6_tcp, ICE_INSET_NONE, &hint_7},
130 {pattern_eth_ipv6_sctp, ICE_INSET_NONE, &hint_8},
131 {pattern_empty, ICE_INSET_NONE, &hint_0},
132 {pattern_eth_ipv4_gtpu_eh_ipv4, ICE_INSET_NONE, &hint_9},
133 {pattern_eth_ipv4_gtpu_eh_ipv4_udp, ICE_INSET_NONE, &hint_9},
134 {pattern_eth_ipv4_gtpu_eh_ipv4_tcp, ICE_INSET_NONE, &hint_9},
135 {pattern_eth_pppoes_ipv4, ICE_INSET_NONE, &hint_10},
136 {pattern_eth_pppoes_ipv4_udp, ICE_INSET_NONE, &hint_11},
137 {pattern_eth_pppoes_ipv4_tcp, ICE_INSET_NONE, &hint_12},
138 {pattern_eth_pppoes_ipv4_sctp, ICE_INSET_NONE, &hint_13},
142 * The first member is input set combination,
143 * the second member is hash fields.
145 struct ice_hash_match_type ice_hash_type_list[] = {
146 {ETH_RSS_IPV4 | ETH_RSS_L3_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA)},
147 {ETH_RSS_IPV4 | ETH_RSS_L3_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA)},
148 {ETH_RSS_IPV4, ICE_FLOW_HASH_IPV4},
149 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA) | BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT)},
150 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA) | BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT)},
151 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L3_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA)},
152 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA) | BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT)},
153 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA) | BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT)},
154 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L3_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA)},
155 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L4_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT)},
156 {ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_L4_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT)},
157 {ETH_RSS_NONFRAG_IPV4_UDP, ICE_HASH_UDP_IPV4},
158 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA) | BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT)},
159 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA) | BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT)},
160 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L3_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA)},
161 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA) | BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT)},
162 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA) | BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT)},
163 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L3_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA)},
164 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L4_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT)},
165 {ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_L4_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT)},
166 {ETH_RSS_NONFRAG_IPV4_TCP, ICE_HASH_TCP_IPV4},
167 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA) | BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT)},
168 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA) | BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)},
169 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L3_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_SA)},
170 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA) | BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT)},
171 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA) | BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)},
172 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L3_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV4_DA)},
173 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L4_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT)},
174 {ETH_RSS_NONFRAG_IPV4_SCTP | ETH_RSS_L4_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)},
175 {ETH_RSS_NONFRAG_IPV4_SCTP, ICE_HASH_SCTP_IPV4},
176 {ETH_RSS_IPV6 | ETH_RSS_L3_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA)},
177 {ETH_RSS_IPV6 | ETH_RSS_L3_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA)},
178 {ETH_RSS_IPV6, ICE_FLOW_HASH_IPV6},
179 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA) | BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT)},
180 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA) | BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT)},
181 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L3_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA)},
182 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA) | BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT)},
183 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA) | BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT)},
184 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L3_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA)},
185 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L4_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_SRC_PORT)},
186 {ETH_RSS_NONFRAG_IPV6_UDP | ETH_RSS_L4_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_UDP_DST_PORT)},
187 {ETH_RSS_NONFRAG_IPV6_UDP, ICE_HASH_UDP_IPV6},
188 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA) | BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT)},
189 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA) | BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT)},
190 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L3_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA)},
191 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA) | BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT)},
192 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA) | BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT)},
193 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L3_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA)},
194 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L4_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_SRC_PORT)},
195 {ETH_RSS_NONFRAG_IPV6_TCP | ETH_RSS_L4_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_TCP_DST_PORT)},
196 {ETH_RSS_NONFRAG_IPV6_TCP, ICE_HASH_TCP_IPV6},
197 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA) | BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT)},
198 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L3_SRC_ONLY | ETH_RSS_L4_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA) | BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)},
199 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L3_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_SA)},
200 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA) | BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT)},
201 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L3_DST_ONLY | ETH_RSS_L4_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA) | BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)},
202 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L3_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_IPV6_DA)},
203 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L4_SRC_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_SRC_PORT)},
204 {ETH_RSS_NONFRAG_IPV6_SCTP | ETH_RSS_L4_DST_ONLY, BIT_ULL(ICE_FLOW_FIELD_IDX_SCTP_DST_PORT)},
205 {ETH_RSS_NONFRAG_IPV6_SCTP, ICE_HASH_SCTP_IPV6},
208 static struct ice_flow_engine ice_hash_engine = {
209 .init = ice_hash_init,
210 .create = ice_hash_create,
211 .destroy = ice_hash_destroy,
212 .uninit = ice_hash_uninit,
213 .free = ice_hash_free,
214 .type = ICE_FLOW_ENGINE_HASH,
217 /* Register parser for os package. */
218 static struct ice_flow_parser ice_hash_parser_os = {
219 .engine = &ice_hash_engine,
220 .array = ice_hash_pattern_list_os,
221 .array_len = RTE_DIM(ice_hash_pattern_list_os),
222 .parse_pattern_action = ice_hash_parse_pattern_action,
223 .stage = ICE_FLOW_STAGE_RSS,
226 /* Register parser for comms package. */
227 static struct ice_flow_parser ice_hash_parser_comms = {
228 .engine = &ice_hash_engine,
229 .array = ice_hash_pattern_list_comms,
230 .array_len = RTE_DIM(ice_hash_pattern_list_comms),
231 .parse_pattern_action = ice_hash_parse_pattern_action,
232 .stage = ICE_FLOW_STAGE_RSS,
235 RTE_INIT(ice_hash_engine_init)
237 struct ice_flow_engine *engine = &ice_hash_engine;
238 ice_register_flow_engine(engine);
242 ice_hash_init(struct ice_adapter *ad)
244 struct ice_flow_parser *parser = NULL;
246 if (ad->hw.dcf_enabled)
249 if (ad->active_pkg_type == ICE_PKG_TYPE_OS_DEFAULT)
250 parser = &ice_hash_parser_os;
251 else if (ad->active_pkg_type == ICE_PKG_TYPE_COMMS)
252 parser = &ice_hash_parser_comms;
256 return ice_register_parser(parser, ad);
260 ice_hash_check_inset(const struct rte_flow_item pattern[],
261 struct rte_flow_error *error)
263 const struct rte_flow_item *item = pattern;
265 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
267 rte_flow_error_set(error, EINVAL,
268 RTE_FLOW_ERROR_TYPE_ITEM, item,
269 "Not support range");
273 /* Ignore spec and mask. */
274 if (item->spec || item->mask) {
275 rte_flow_error_set(error, EINVAL,
276 RTE_FLOW_ERROR_TYPE_ITEM, item,
277 "Invalid spec/mask.");
286 ice_hash_parse_action(struct ice_pattern_match_item *pattern_match_item,
287 const struct rte_flow_action actions[],
289 struct rte_flow_error *error)
291 const struct rte_flow_action *action;
292 enum rte_flow_action_type action_type;
293 const struct rte_flow_action_rss *rss;
294 struct rss_type_match_hdr *m = (struct rss_type_match_hdr *)
295 (pattern_match_item->meta);
296 uint32_t type_list_len = RTE_DIM(ice_hash_type_list);
297 struct ice_hash_match_type *type_match_item;
301 /* Supported action is RSS. */
302 for (action = actions; action->type !=
303 RTE_FLOW_ACTION_TYPE_END; action++) {
304 action_type = action->type;
305 switch (action_type) {
306 case RTE_FLOW_ACTION_TYPE_RSS:
311 * Check simultaneous use of SRC_ONLY and DST_ONLY
314 rss_hf = rte_eth_rss_hf_refine(rss_hf);
316 /* Check if pattern is empty. */
317 if (pattern_match_item->pattern_list !=
318 pattern_empty && rss->func ==
319 RTE_ETH_HASH_FUNCTION_SIMPLE_XOR)
320 return rte_flow_error_set(error, ENOTSUP,
321 RTE_FLOW_ERROR_TYPE_ACTION, action,
322 "Not supported flow");
324 /* Check if rss types match pattern. */
325 if (rss->func != RTE_ETH_HASH_FUNCTION_SIMPLE_XOR) {
326 if (((rss_hf & ETH_RSS_IPV4) != m->eth_rss_hint) &&
327 ((rss_hf & ETH_RSS_NONFRAG_IPV4_UDP) != m->eth_rss_hint) &&
328 ((rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) != m->eth_rss_hint) &&
329 ((rss_hf & ETH_RSS_NONFRAG_IPV4_SCTP) != m->eth_rss_hint) &&
330 ((rss_hf & ETH_RSS_IPV6) != m->eth_rss_hint) &&
331 ((rss_hf & ETH_RSS_NONFRAG_IPV6_UDP) != m->eth_rss_hint) &&
332 ((rss_hf & ETH_RSS_NONFRAG_IPV6_TCP) != m->eth_rss_hint) &&
333 ((rss_hf & ETH_RSS_NONFRAG_IPV6_SCTP) != m->eth_rss_hint))
334 return rte_flow_error_set(error,
335 ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
336 action, "Not supported RSS types");
340 return rte_flow_error_set(error, ENOTSUP,
341 RTE_FLOW_ERROR_TYPE_ACTION, action,
342 "a nonzero RSS encapsulation level is not supported");
345 return rte_flow_error_set(error, ENOTSUP,
346 RTE_FLOW_ERROR_TYPE_ACTION, action,
347 "a nonzero RSS key_len is not supported");
350 return rte_flow_error_set(error, ENOTSUP,
351 RTE_FLOW_ERROR_TYPE_ACTION, action,
352 "a non-NULL RSS queue is not supported");
354 /* Check hash function and save it to rss_meta. */
356 RTE_ETH_HASH_FUNCTION_SIMPLE_XOR)
357 ((struct rss_meta *)*meta)->hash_function =
358 RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
361 RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ)
362 ((struct rss_meta *)*meta)->hash_function =
363 RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ;
365 type_match_item = rte_zmalloc("ice_type_match_item",
366 sizeof(struct ice_hash_match_type), 0);
367 if (!type_match_item) {
368 rte_flow_error_set(error, EINVAL,
369 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
370 "No memory for type_match_item");
374 /* Find matched hash fields according to hash type. */
375 for (i = 0; i < type_list_len; i++) {
377 ice_hash_type_list[i].hash_type) {
378 type_match_item->hash_type =
379 ice_hash_type_list[i].hash_type;
380 type_match_item->hash_flds =
381 ice_hash_type_list[i].hash_flds;
385 /* Save hash fileds to rss_meta. */
386 ((struct rss_meta *)*meta)->hash_flds =
387 type_match_item->hash_flds;
389 rte_free(type_match_item);
392 case RTE_FLOW_ACTION_TYPE_END:
396 rte_flow_error_set(error, EINVAL,
397 RTE_FLOW_ERROR_TYPE_ACTION, action,
407 ice_hash_parse_pattern_action(__rte_unused struct ice_adapter *ad,
408 struct ice_pattern_match_item *array,
410 const struct rte_flow_item pattern[],
411 const struct rte_flow_action actions[],
413 struct rte_flow_error *error)
416 struct ice_pattern_match_item *pattern_match_item;
417 struct rss_meta *rss_meta_ptr;
419 rss_meta_ptr = rte_zmalloc(NULL, sizeof(*rss_meta_ptr), 0);
421 rte_flow_error_set(error, EINVAL,
422 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
423 "No memory for rss_meta_ptr");
427 /* Check rss supported pattern and find matched pattern. */
428 pattern_match_item = ice_search_pattern_match_item(pattern,
429 array, array_len, error);
430 if (!pattern_match_item) {
435 ret = ice_hash_check_inset(pattern, error);
439 /* Save protocol header to rss_meta. */
440 rss_meta_ptr->pkt_hdr = ((struct rss_type_match_hdr *)
441 (pattern_match_item->meta))->hdr_mask;
443 /* Check rss action. */
444 ret = ice_hash_parse_action(pattern_match_item, actions,
445 (void **)&rss_meta_ptr, error);
449 *meta = rss_meta_ptr;
451 rte_free(rss_meta_ptr);
452 rte_free(pattern_match_item);
458 ice_hash_create(struct ice_adapter *ad,
459 struct rte_flow *flow,
461 struct rte_flow_error *error)
463 struct ice_pf *pf = &ad->pf;
464 struct ice_hw *hw = ICE_PF_TO_HW(pf);
465 struct ice_vsi *vsi = pf->main_vsi;
468 struct ice_hash_flow_cfg *filter_ptr;
470 uint32_t headermask = ((struct rss_meta *)meta)->pkt_hdr;
471 uint64_t hash_field = ((struct rss_meta *)meta)->hash_flds;
472 uint8_t hash_function = ((struct rss_meta *)meta)->hash_function;
474 filter_ptr = rte_zmalloc("ice_rss_filter",
475 sizeof(struct ice_hash_flow_cfg), 0);
477 rte_flow_error_set(error, EINVAL,
478 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
479 "No memory for filter_ptr");
483 if (hash_function == RTE_ETH_HASH_FUNCTION_SIMPLE_XOR) {
484 /* Enable registers for simple_xor hash function. */
485 reg = ICE_READ_REG(hw, VSIQF_HASH_CTL(vsi->vsi_id));
486 reg = (reg & (~VSIQF_HASH_CTL_HASH_SCHEME_M)) |
487 (2 << VSIQF_HASH_CTL_HASH_SCHEME_S);
488 ICE_WRITE_REG(hw, VSIQF_HASH_CTL(vsi->vsi_id), reg);
490 filter_ptr->simple_xor = 1;
494 filter_ptr->rss_cfg.packet_hdr = headermask;
495 filter_ptr->rss_cfg.hashed_flds = hash_field;
496 filter_ptr->rss_cfg.symm =
498 RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ);
500 ret = ice_add_rss_cfg(hw, vsi->idx,
501 filter_ptr->rss_cfg.hashed_flds,
502 filter_ptr->rss_cfg.packet_hdr,
503 filter_ptr->rss_cfg.symm);
505 rte_flow_error_set(error, EINVAL,
506 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
507 "rss flow create fail");
513 flow->rule = filter_ptr;
518 rte_free(filter_ptr);
524 ice_hash_destroy(struct ice_adapter *ad,
525 struct rte_flow *flow,
526 struct rte_flow_error *error)
528 struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(ad);
529 struct ice_hw *hw = ICE_PF_TO_HW(pf);
530 struct ice_vsi *vsi = pf->main_vsi;
533 struct ice_hash_flow_cfg *filter_ptr;
535 filter_ptr = (struct ice_hash_flow_cfg *)flow->rule;
537 if (filter_ptr->simple_xor == 1) {
538 /* Return to symmetric_toeplitz state. */
539 reg = ICE_READ_REG(hw, VSIQF_HASH_CTL(vsi->vsi_id));
540 reg = (reg & (~VSIQF_HASH_CTL_HASH_SCHEME_M)) |
541 (1 << VSIQF_HASH_CTL_HASH_SCHEME_S);
542 ICE_WRITE_REG(hw, VSIQF_HASH_CTL(vsi->vsi_id), reg);
544 ret = ice_rem_rss_cfg(hw, vsi->idx,
545 filter_ptr->rss_cfg.hashed_flds,
546 filter_ptr->rss_cfg.packet_hdr);
547 /* Fixme: Ignore the error if a rule does not exist.
548 * Currently a rule for inputset change or symm turn on/off
549 * will overwrite an exist rule, while application still
550 * have 2 rte_flow handles.
552 if (ret && ret != ICE_ERR_DOES_NOT_EXIST) {
553 rte_flow_error_set(error, EINVAL,
554 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
555 "rss flow destroy fail");
560 rte_free(filter_ptr);
564 rte_free(filter_ptr);
569 ice_hash_uninit(struct ice_adapter *ad)
571 if (ad->hw.dcf_enabled)
574 if (ad->active_pkg_type == ICE_PKG_TYPE_OS_DEFAULT)
575 ice_unregister_parser(&ice_hash_parser_os, ad);
576 else if (ad->active_pkg_type == ICE_PKG_TYPE_COMMS)
577 ice_unregister_parser(&ice_hash_parser_comms, ad);
581 ice_hash_free(struct rte_flow *flow)
583 rte_free(flow->rule);