Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2015-2020 Beijing WangXun Technology Co., Ltd.
3 : : * Copyright(c) 2010-2017 Intel Corporation
4 : : */
5 : :
6 : : #include <sys/queue.h>
7 : : #include <bus_pci_driver.h>
8 : : #include <rte_malloc.h>
9 : : #include <rte_flow.h>
10 : : #include <rte_flow_driver.h>
11 : :
12 : : #include "txgbe_ethdev.h"
13 : :
14 : : #define TXGBE_MIN_N_TUPLE_PRIO 1
15 : : #define TXGBE_MAX_N_TUPLE_PRIO 7
16 : : #define TXGBE_MAX_FLX_SOURCE_OFF 62
17 : :
18 : : /* ntuple filter list structure */
19 : : struct txgbe_ntuple_filter_ele {
20 : : TAILQ_ENTRY(txgbe_ntuple_filter_ele) entries;
21 : : struct rte_eth_ntuple_filter filter_info;
22 : : };
23 : : /* ethertype filter list structure */
24 : : struct txgbe_ethertype_filter_ele {
25 : : TAILQ_ENTRY(txgbe_ethertype_filter_ele) entries;
26 : : struct rte_eth_ethertype_filter filter_info;
27 : : };
28 : : /* syn filter list structure */
29 : : struct txgbe_eth_syn_filter_ele {
30 : : TAILQ_ENTRY(txgbe_eth_syn_filter_ele) entries;
31 : : struct rte_eth_syn_filter filter_info;
32 : : };
33 : : /* fdir filter list structure */
34 : : struct txgbe_fdir_rule_ele {
35 : : TAILQ_ENTRY(txgbe_fdir_rule_ele) entries;
36 : : struct txgbe_fdir_rule filter_info;
37 : : };
38 : : /* l2_tunnel filter list structure */
39 : : struct txgbe_eth_l2_tunnel_conf_ele {
40 : : TAILQ_ENTRY(txgbe_eth_l2_tunnel_conf_ele) entries;
41 : : struct txgbe_l2_tunnel_conf filter_info;
42 : : };
43 : : /* rss filter list structure */
44 : : struct txgbe_rss_conf_ele {
45 : : TAILQ_ENTRY(txgbe_rss_conf_ele) entries;
46 : : struct txgbe_rte_flow_rss_conf filter_info;
47 : : };
48 : : /* txgbe_flow memory list structure */
49 : : struct txgbe_flow_mem {
50 : : TAILQ_ENTRY(txgbe_flow_mem) entries;
51 : : struct rte_flow *flow;
52 : : };
53 : :
54 : : TAILQ_HEAD(txgbe_ntuple_filter_list, txgbe_ntuple_filter_ele);
55 : : TAILQ_HEAD(txgbe_ethertype_filter_list, txgbe_ethertype_filter_ele);
56 : : TAILQ_HEAD(txgbe_syn_filter_list, txgbe_eth_syn_filter_ele);
57 : : TAILQ_HEAD(txgbe_fdir_rule_filter_list, txgbe_fdir_rule_ele);
58 : : TAILQ_HEAD(txgbe_l2_tunnel_filter_list, txgbe_eth_l2_tunnel_conf_ele);
59 : : TAILQ_HEAD(txgbe_rss_filter_list, txgbe_rss_conf_ele);
60 : : TAILQ_HEAD(txgbe_flow_mem_list, txgbe_flow_mem);
61 : :
62 : : static struct txgbe_ntuple_filter_list filter_ntuple_list;
63 : : static struct txgbe_ethertype_filter_list filter_ethertype_list;
64 : : static struct txgbe_syn_filter_list filter_syn_list;
65 : : static struct txgbe_fdir_rule_filter_list filter_fdir_list;
66 : : static struct txgbe_l2_tunnel_filter_list filter_l2_tunnel_list;
67 : : static struct txgbe_rss_filter_list filter_rss_list;
68 : : static struct txgbe_flow_mem_list txgbe_flow_list;
69 : :
70 : : /**
71 : : * Endless loop will never happen with below assumption
72 : : * 1. there is at least one no-void item(END)
73 : : * 2. cur is before END.
74 : : */
75 : : static inline
76 : : const struct rte_flow_item *next_no_void_pattern(
77 : : const struct rte_flow_item pattern[],
78 : : const struct rte_flow_item *cur)
79 : : {
80 : : const struct rte_flow_item *next =
81 : 0 : cur ? cur + 1 : &pattern[0];
82 : : while (1) {
83 [ # # # # : 0 : if (next->type != RTE_FLOW_ITEM_TYPE_VOID)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
84 : : return next;
85 : 0 : next++;
86 : : }
87 : : }
88 : :
89 : : static inline
90 : : const struct rte_flow_action *next_no_void_action(
91 : : const struct rte_flow_action actions[],
92 : : const struct rte_flow_action *cur)
93 : : {
94 : : const struct rte_flow_action *next =
95 : 0 : cur ? cur + 1 : &actions[0];
96 : : while (1) {
97 [ # # # # : 0 : if (next->type != RTE_FLOW_ACTION_TYPE_VOID)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
98 : : return next;
99 : 0 : next++;
100 : : }
101 : : }
102 : :
103 : : /**
104 : : * Please aware there's an assumption for all the parsers.
105 : : * rte_flow_item is using big endian, rte_flow_attr and
106 : : * rte_flow_action are using CPU order.
107 : : * Because the pattern is used to describe the packets,
108 : : * normally the packets should use network order.
109 : : */
110 : :
111 : : /**
112 : : * Parse the rule to see if it is a n-tuple rule.
113 : : * And get the n-tuple filter info BTW.
114 : : * pattern:
115 : : * The first not void item can be ETH or IPV4.
116 : : * The second not void item must be IPV4 if the first one is ETH.
117 : : * The third not void item must be UDP or TCP.
118 : : * The next not void item must be END.
119 : : * action:
120 : : * The first not void action should be QUEUE.
121 : : * The next not void action should be END.
122 : : * pattern example:
123 : : * ITEM Spec Mask
124 : : * ETH NULL NULL
125 : : * IPV4 src_addr 192.168.1.20 0xFFFFFFFF
126 : : * dst_addr 192.167.3.50 0xFFFFFFFF
127 : : * next_proto_id 17 0xFF
128 : : * UDP/TCP/ src_port 80 0xFFFF
129 : : * SCTP dst_port 80 0xFFFF
130 : : * END
131 : : * other members in mask and spec should set to 0x00.
132 : : * item->last should be NULL.
133 : : *
134 : : * Special case for flow action type RTE_FLOW_ACTION_TYPE_SECURITY.
135 : : *
136 : : */
137 : : static int
138 : 0 : cons_parse_ntuple_filter(const struct rte_flow_attr *attr,
139 : : const struct rte_flow_item pattern[],
140 : : const struct rte_flow_action actions[],
141 : : struct rte_eth_ntuple_filter *filter,
142 : : struct rte_flow_error *error)
143 : : {
144 : : const struct rte_flow_item *item;
145 : : const struct rte_flow_action *act;
146 : : const struct rte_flow_item_ipv4 *ipv4_spec;
147 : : const struct rte_flow_item_ipv4 *ipv4_mask;
148 : : const struct rte_flow_item_tcp *tcp_spec;
149 : : const struct rte_flow_item_tcp *tcp_mask;
150 : : const struct rte_flow_item_udp *udp_spec;
151 : : const struct rte_flow_item_udp *udp_mask;
152 : : const struct rte_flow_item_sctp *sctp_spec;
153 : : const struct rte_flow_item_sctp *sctp_mask;
154 : : const struct rte_flow_item_eth *eth_spec;
155 : : const struct rte_flow_item_eth *eth_mask;
156 : : const struct rte_flow_item_vlan *vlan_spec;
157 : : const struct rte_flow_item_vlan *vlan_mask;
158 : : struct rte_flow_item_eth eth_null;
159 : : struct rte_flow_item_vlan vlan_null;
160 : :
161 [ # # ]: 0 : if (!pattern) {
162 : 0 : rte_flow_error_set(error,
163 : : EINVAL, RTE_FLOW_ERROR_TYPE_ITEM_NUM,
164 : : NULL, "NULL pattern.");
165 : 0 : return -rte_errno;
166 : : }
167 : :
168 [ # # ]: 0 : if (!actions) {
169 : 0 : rte_flow_error_set(error, EINVAL,
170 : : RTE_FLOW_ERROR_TYPE_ACTION_NUM,
171 : : NULL, "NULL action.");
172 : 0 : return -rte_errno;
173 : : }
174 [ # # ]: 0 : if (!attr) {
175 : 0 : rte_flow_error_set(error, EINVAL,
176 : : RTE_FLOW_ERROR_TYPE_ATTR,
177 : : NULL, "NULL attribute.");
178 : 0 : return -rte_errno;
179 : : }
180 : :
181 : : memset(ð_null, 0, sizeof(struct rte_flow_item_eth));
182 : : memset(&vlan_null, 0, sizeof(struct rte_flow_item_vlan));
183 : :
184 : : #ifdef RTE_LIB_SECURITY
185 : : /**
186 : : * Special case for flow action type RTE_FLOW_ACTION_TYPE_SECURITY
187 : : */
188 : : act = next_no_void_action(actions, NULL);
189 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_SECURITY) {
190 : 0 : const void *conf = act->conf;
191 : : /* check if the next not void item is END */
192 : : act = next_no_void_action(actions, act);
193 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_END) {
194 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
195 : 0 : rte_flow_error_set(error, EINVAL,
196 : : RTE_FLOW_ERROR_TYPE_ACTION,
197 : : act, "Not supported action.");
198 : 0 : return -rte_errno;
199 : : }
200 : :
201 : : /* get the IP pattern*/
202 : : item = next_no_void_pattern(pattern, NULL);
203 [ # # ]: 0 : while (item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
204 : : item->type != RTE_FLOW_ITEM_TYPE_IPV6) {
205 [ # # # # ]: 0 : if (item->last ||
206 : : item->type == RTE_FLOW_ITEM_TYPE_END) {
207 : 0 : rte_flow_error_set(error, EINVAL,
208 : : RTE_FLOW_ERROR_TYPE_ITEM,
209 : : item, "IP pattern missing.");
210 : 0 : return -rte_errno;
211 : : }
212 : : item = next_no_void_pattern(pattern, item);
213 : : }
214 : :
215 : 0 : filter->proto = IPPROTO_ESP;
216 : 0 : return txgbe_crypto_add_ingress_sa_from_flow(conf, item->spec,
217 : : item->type == RTE_FLOW_ITEM_TYPE_IPV6);
218 : : }
219 : : #endif
220 : :
221 : : /* the first not void item can be MAC or IPv4 */
222 : : item = next_no_void_pattern(pattern, NULL);
223 : :
224 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_ETH &&
225 : : item->type != RTE_FLOW_ITEM_TYPE_IPV4) {
226 : 0 : rte_flow_error_set(error, EINVAL,
227 : : RTE_FLOW_ERROR_TYPE_ITEM,
228 : : item, "Not supported by ntuple filter");
229 : 0 : return -rte_errno;
230 : : }
231 : : /* Skip Ethernet */
232 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_ETH) {
233 : 0 : eth_spec = item->spec;
234 : 0 : eth_mask = item->mask;
235 : : /*Not supported last point for range*/
236 [ # # ]: 0 : if (item->last) {
237 : 0 : rte_flow_error_set(error,
238 : : EINVAL,
239 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
240 : : item, "Not supported last point for range");
241 : 0 : return -rte_errno;
242 : : }
243 : : /* if the first item is MAC, the content should be NULL */
244 [ # # # # ]: 0 : if ((item->spec && memcmp(eth_spec, ð_null,
245 [ # # ]: 0 : sizeof(struct rte_flow_item_eth))) ||
246 [ # # ]: 0 : (item->mask && memcmp(eth_mask, ð_null,
247 : : sizeof(struct rte_flow_item_eth)))) {
248 : 0 : rte_flow_error_set(error, EINVAL,
249 : : RTE_FLOW_ERROR_TYPE_ITEM,
250 : : item, "Not supported by ntuple filter");
251 : 0 : return -rte_errno;
252 : : }
253 : : /* check if the next not void item is IPv4 or Vlan */
254 : : item = next_no_void_pattern(pattern, item);
255 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
256 : : item->type != RTE_FLOW_ITEM_TYPE_VLAN) {
257 : 0 : rte_flow_error_set(error,
258 : : EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
259 : : item, "Not supported by ntuple filter");
260 : 0 : return -rte_errno;
261 : : }
262 : : }
263 : :
264 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
265 : 0 : vlan_spec = item->spec;
266 : 0 : vlan_mask = item->mask;
267 : : /*Not supported last point for range*/
268 [ # # ]: 0 : if (item->last) {
269 : 0 : rte_flow_error_set(error,
270 : : EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
271 : : item, "Not supported last point for range");
272 : 0 : return -rte_errno;
273 : : }
274 : : /* the content should be NULL */
275 [ # # # # ]: 0 : if ((item->spec && memcmp(vlan_spec, &vlan_null,
276 [ # # ]: 0 : sizeof(struct rte_flow_item_vlan))) ||
277 [ # # ]: 0 : (item->mask && memcmp(vlan_mask, &vlan_null,
278 : : sizeof(struct rte_flow_item_vlan)))) {
279 : 0 : rte_flow_error_set(error, EINVAL,
280 : : RTE_FLOW_ERROR_TYPE_ITEM,
281 : : item, "Not supported by ntuple filter");
282 : 0 : return -rte_errno;
283 : : }
284 : : /* check if the next not void item is IPv4 */
285 : : item = next_no_void_pattern(pattern, item);
286 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_IPV4) {
287 : 0 : rte_flow_error_set(error,
288 : : EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
289 : : item, "Not supported by ntuple filter");
290 : 0 : return -rte_errno;
291 : : }
292 : : }
293 : :
294 [ # # ]: 0 : if (item->mask) {
295 : : /* get the IPv4 info */
296 [ # # ]: 0 : if (!item->spec || !item->mask) {
297 : 0 : rte_flow_error_set(error, EINVAL,
298 : : RTE_FLOW_ERROR_TYPE_ITEM,
299 : : item, "Invalid ntuple mask");
300 : 0 : return -rte_errno;
301 : : }
302 : : /*Not supported last point for range*/
303 [ # # ]: 0 : if (item->last) {
304 : 0 : rte_flow_error_set(error, EINVAL,
305 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
306 : : item, "Not supported last point for range");
307 : 0 : return -rte_errno;
308 : : }
309 : :
310 : : ipv4_mask = item->mask;
311 : : /**
312 : : * Only support src & dst addresses, protocol,
313 : : * others should be masked.
314 : : */
315 [ # # ]: 0 : if (ipv4_mask->hdr.version_ihl ||
316 : 0 : ipv4_mask->hdr.type_of_service ||
317 [ # # ]: 0 : ipv4_mask->hdr.total_length ||
318 [ # # ]: 0 : ipv4_mask->hdr.packet_id ||
319 [ # # ]: 0 : ipv4_mask->hdr.fragment_offset ||
320 [ # # ]: 0 : ipv4_mask->hdr.time_to_live ||
321 [ # # ]: 0 : ipv4_mask->hdr.hdr_checksum) {
322 : 0 : rte_flow_error_set(error,
323 : : EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
324 : : item, "Not supported by ntuple filter");
325 : 0 : return -rte_errno;
326 : : }
327 [ # # ]: 0 : if ((ipv4_mask->hdr.src_addr != 0 &&
328 : 0 : ipv4_mask->hdr.src_addr != UINT32_MAX) ||
329 [ # # ]: 0 : (ipv4_mask->hdr.dst_addr != 0 &&
330 : 0 : ipv4_mask->hdr.dst_addr != UINT32_MAX) ||
331 [ # # ]: 0 : (ipv4_mask->hdr.next_proto_id != UINT8_MAX &&
332 : : ipv4_mask->hdr.next_proto_id != 0)) {
333 : 0 : rte_flow_error_set(error,
334 : : EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
335 : : item, "Not supported by ntuple filter");
336 : 0 : return -rte_errno;
337 : : }
338 : :
339 : 0 : filter->dst_ip_mask = ipv4_mask->hdr.dst_addr;
340 : 0 : filter->src_ip_mask = ipv4_mask->hdr.src_addr;
341 : 0 : filter->proto_mask = ipv4_mask->hdr.next_proto_id;
342 : :
343 : : ipv4_spec = item->spec;
344 : 0 : filter->dst_ip = ipv4_spec->hdr.dst_addr;
345 : 0 : filter->src_ip = ipv4_spec->hdr.src_addr;
346 : 0 : filter->proto = ipv4_spec->hdr.next_proto_id;
347 : : }
348 : :
349 : : /* check if the next not void item is TCP or UDP */
350 : : item = next_no_void_pattern(pattern, item);
351 : 0 : if (item->type != RTE_FLOW_ITEM_TYPE_TCP &&
352 : : item->type != RTE_FLOW_ITEM_TYPE_UDP &&
353 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_SCTP &&
354 : : item->type != RTE_FLOW_ITEM_TYPE_END) {
355 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
356 : 0 : rte_flow_error_set(error, EINVAL,
357 : : RTE_FLOW_ERROR_TYPE_ITEM,
358 : : item, "Not supported by ntuple filter");
359 : 0 : return -rte_errno;
360 : : }
361 : :
362 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END &&
363 [ # # # # ]: 0 : (!item->spec && !item->mask)) {
364 : 0 : goto item_end;
365 : : }
366 : :
367 : : /* get the TCP/UDP/SCTP info */
368 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END &&
369 [ # # # # ]: 0 : (!item->spec || !item->mask)) {
370 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
371 : 0 : rte_flow_error_set(error, EINVAL,
372 : : RTE_FLOW_ERROR_TYPE_ITEM,
373 : : item, "Invalid ntuple mask");
374 : 0 : return -rte_errno;
375 : : }
376 : :
377 : : /*Not supported last point for range*/
378 [ # # ]: 0 : if (item->last) {
379 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
380 : 0 : rte_flow_error_set(error, EINVAL,
381 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
382 : : item, "Not supported last point for range");
383 : 0 : return -rte_errno;
384 : : }
385 : :
386 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_TCP) {
387 : 0 : tcp_mask = item->mask;
388 : :
389 : : /**
390 : : * Only support src & dst ports, tcp flags,
391 : : * others should be masked.
392 : : */
393 [ # # ]: 0 : if (tcp_mask->hdr.sent_seq ||
394 [ # # ]: 0 : tcp_mask->hdr.recv_ack ||
395 [ # # ]: 0 : tcp_mask->hdr.data_off ||
396 [ # # ]: 0 : tcp_mask->hdr.rx_win ||
397 [ # # ]: 0 : tcp_mask->hdr.cksum ||
398 [ # # ]: 0 : tcp_mask->hdr.tcp_urp) {
399 : : memset(filter, 0,
400 : : sizeof(struct rte_eth_ntuple_filter));
401 : 0 : rte_flow_error_set(error, EINVAL,
402 : : RTE_FLOW_ERROR_TYPE_ITEM,
403 : : item, "Not supported by ntuple filter");
404 : 0 : return -rte_errno;
405 : : }
406 [ # # ]: 0 : if ((tcp_mask->hdr.src_port != 0 &&
407 : 0 : tcp_mask->hdr.src_port != UINT16_MAX) ||
408 [ # # ]: 0 : (tcp_mask->hdr.dst_port != 0 &&
409 : : tcp_mask->hdr.dst_port != UINT16_MAX)) {
410 : 0 : rte_flow_error_set(error,
411 : : EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
412 : : item, "Not supported by ntuple filter");
413 : 0 : return -rte_errno;
414 : : }
415 : :
416 : 0 : filter->dst_port_mask = tcp_mask->hdr.dst_port;
417 : 0 : filter->src_port_mask = tcp_mask->hdr.src_port;
418 [ # # ]: 0 : if (tcp_mask->hdr.tcp_flags == 0xFF) {
419 : 0 : filter->flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
420 [ # # ]: 0 : } else if (!tcp_mask->hdr.tcp_flags) {
421 : 0 : filter->flags &= ~RTE_NTUPLE_FLAGS_TCP_FLAG;
422 : : } else {
423 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
424 : 0 : rte_flow_error_set(error, EINVAL,
425 : : RTE_FLOW_ERROR_TYPE_ITEM,
426 : : item, "Not supported by ntuple filter");
427 : 0 : return -rte_errno;
428 : : }
429 : :
430 : 0 : tcp_spec = item->spec;
431 : 0 : filter->dst_port = tcp_spec->hdr.dst_port;
432 : 0 : filter->src_port = tcp_spec->hdr.src_port;
433 : 0 : filter->tcp_flags = tcp_spec->hdr.tcp_flags;
434 [ # # ]: 0 : } else if (item->type == RTE_FLOW_ITEM_TYPE_UDP) {
435 : 0 : udp_mask = item->mask;
436 : :
437 : : /**
438 : : * Only support src & dst ports,
439 : : * others should be masked.
440 : : */
441 [ # # ]: 0 : if (udp_mask->hdr.dgram_len ||
442 [ # # ]: 0 : udp_mask->hdr.dgram_cksum) {
443 : : memset(filter, 0,
444 : : sizeof(struct rte_eth_ntuple_filter));
445 : 0 : rte_flow_error_set(error, EINVAL,
446 : : RTE_FLOW_ERROR_TYPE_ITEM,
447 : : item, "Not supported by ntuple filter");
448 : 0 : return -rte_errno;
449 : : }
450 [ # # ]: 0 : if ((udp_mask->hdr.src_port != 0 &&
451 : 0 : udp_mask->hdr.src_port != UINT16_MAX) ||
452 [ # # ]: 0 : (udp_mask->hdr.dst_port != 0 &&
453 : : udp_mask->hdr.dst_port != UINT16_MAX)) {
454 : 0 : rte_flow_error_set(error,
455 : : EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
456 : : item, "Not supported by ntuple filter");
457 : 0 : return -rte_errno;
458 : : }
459 : :
460 : 0 : filter->dst_port_mask = udp_mask->hdr.dst_port;
461 : 0 : filter->src_port_mask = udp_mask->hdr.src_port;
462 : :
463 : 0 : udp_spec = item->spec;
464 : 0 : filter->dst_port = udp_spec->hdr.dst_port;
465 : 0 : filter->src_port = udp_spec->hdr.src_port;
466 [ # # ]: 0 : } else if (item->type == RTE_FLOW_ITEM_TYPE_SCTP) {
467 : 0 : sctp_mask = item->mask;
468 : :
469 : : /**
470 : : * Only support src & dst ports,
471 : : * others should be masked.
472 : : */
473 [ # # ]: 0 : if (sctp_mask->hdr.tag ||
474 [ # # ]: 0 : sctp_mask->hdr.cksum) {
475 : : memset(filter, 0,
476 : : sizeof(struct rte_eth_ntuple_filter));
477 : 0 : rte_flow_error_set(error, EINVAL,
478 : : RTE_FLOW_ERROR_TYPE_ITEM,
479 : : item, "Not supported by ntuple filter");
480 : 0 : return -rte_errno;
481 : : }
482 : :
483 : 0 : filter->dst_port_mask = sctp_mask->hdr.dst_port;
484 : 0 : filter->src_port_mask = sctp_mask->hdr.src_port;
485 : :
486 : 0 : sctp_spec = item->spec;
487 : 0 : filter->dst_port = sctp_spec->hdr.dst_port;
488 : 0 : filter->src_port = sctp_spec->hdr.src_port;
489 : : } else {
490 : 0 : goto action;
491 : : }
492 : :
493 : 0 : item_end:
494 : : /* check if the next not void item is END */
495 : : item = next_no_void_pattern(pattern, item);
496 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END) {
497 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
498 : 0 : rte_flow_error_set(error, EINVAL,
499 : : RTE_FLOW_ERROR_TYPE_ITEM,
500 : : item, "Not supported by ntuple filter");
501 : 0 : return -rte_errno;
502 : : }
503 : :
504 : 0 : action:
505 : :
506 : : /**
507 : : * n-tuple only supports forwarding,
508 : : * check if the first not void action is QUEUE.
509 : : */
510 : : act = next_no_void_action(actions, NULL);
511 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_QUEUE) {
512 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
513 : 0 : rte_flow_error_set(error, EINVAL,
514 : : RTE_FLOW_ERROR_TYPE_ACTION,
515 : : act, "Not supported action.");
516 : 0 : return -rte_errno;
517 : : }
518 : 0 : filter->queue =
519 : 0 : ((const struct rte_flow_action_queue *)act->conf)->index;
520 : :
521 : : /* check if the next not void item is END */
522 : : act = next_no_void_action(actions, act);
523 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_END) {
524 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
525 : 0 : rte_flow_error_set(error, EINVAL,
526 : : RTE_FLOW_ERROR_TYPE_ACTION,
527 : : act, "Not supported action.");
528 : 0 : return -rte_errno;
529 : : }
530 : :
531 : : /* parse attr */
532 : : /* must be input direction */
533 [ # # ]: 0 : if (!attr->ingress) {
534 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
535 : 0 : rte_flow_error_set(error, EINVAL,
536 : : RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
537 : : attr, "Only support ingress.");
538 : 0 : return -rte_errno;
539 : : }
540 : :
541 : : /* not supported */
542 [ # # ]: 0 : if (attr->egress) {
543 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
544 : 0 : rte_flow_error_set(error, EINVAL,
545 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
546 : : attr, "Not support egress.");
547 : 0 : return -rte_errno;
548 : : }
549 : :
550 : : /* not supported */
551 [ # # ]: 0 : if (attr->transfer) {
552 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
553 : 0 : rte_flow_error_set(error, EINVAL,
554 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
555 : : attr, "No support for transfer.");
556 : 0 : return -rte_errno;
557 : : }
558 : :
559 [ # # ]: 0 : if (attr->priority > 0xFFFF) {
560 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
561 : 0 : rte_flow_error_set(error, EINVAL,
562 : : RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
563 : : attr, "Error priority.");
564 : 0 : return -rte_errno;
565 : : }
566 : 0 : filter->priority = (uint16_t)attr->priority;
567 [ # # ]: 0 : if (attr->priority < TXGBE_MIN_N_TUPLE_PRIO ||
568 : : attr->priority > TXGBE_MAX_N_TUPLE_PRIO)
569 : 0 : filter->priority = 1;
570 : :
571 : : return 0;
572 : : }
573 : :
574 : : /* a specific function for txgbe because the flags is specific */
575 : : static int
576 : 0 : txgbe_parse_ntuple_filter(struct rte_eth_dev *dev,
577 : : const struct rte_flow_attr *attr,
578 : : const struct rte_flow_item pattern[],
579 : : const struct rte_flow_action actions[],
580 : : struct rte_eth_ntuple_filter *filter,
581 : : struct rte_flow_error *error)
582 : : {
583 : : int ret;
584 : :
585 : 0 : ret = cons_parse_ntuple_filter(attr, pattern, actions, filter, error);
586 : :
587 [ # # ]: 0 : if (ret)
588 : : return ret;
589 : :
590 : : #ifdef RTE_LIB_SECURITY
591 : : /* ESP flow not really a flow */
592 [ # # ]: 0 : if (filter->proto == IPPROTO_ESP)
593 : : return 0;
594 : : #endif
595 : :
596 : : /* txgbe doesn't support tcp flags */
597 [ # # ]: 0 : if (filter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG) {
598 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
599 : 0 : rte_flow_error_set(error, EINVAL,
600 : : RTE_FLOW_ERROR_TYPE_ITEM,
601 : : NULL, "Not supported by ntuple filter");
602 : 0 : return -rte_errno;
603 : : }
604 : :
605 : : /* txgbe doesn't support many priorities */
606 [ # # ]: 0 : if (filter->priority < TXGBE_MIN_N_TUPLE_PRIO ||
607 : : filter->priority > TXGBE_MAX_N_TUPLE_PRIO) {
608 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
609 : 0 : rte_flow_error_set(error, EINVAL,
610 : : RTE_FLOW_ERROR_TYPE_ITEM,
611 : : NULL, "Priority not supported by ntuple filter");
612 : 0 : return -rte_errno;
613 : : }
614 : :
615 [ # # ]: 0 : if (filter->queue >= dev->data->nb_rx_queues) {
616 : : memset(filter, 0, sizeof(struct rte_eth_ntuple_filter));
617 : 0 : rte_flow_error_set(error, EINVAL,
618 : : RTE_FLOW_ERROR_TYPE_ITEM,
619 : : NULL, "Not supported by ntuple filter");
620 : 0 : return -rte_errno;
621 : : }
622 : :
623 : : /* fixed value for txgbe */
624 : 0 : filter->flags = RTE_5TUPLE_FLAGS;
625 : 0 : return 0;
626 : : }
627 : :
628 : : /**
629 : : * Parse the rule to see if it is a ethertype rule.
630 : : * And get the ethertype filter info BTW.
631 : : * pattern:
632 : : * The first not void item can be ETH.
633 : : * The next not void item must be END.
634 : : * action:
635 : : * The first not void action should be QUEUE.
636 : : * The next not void action should be END.
637 : : * pattern example:
638 : : * ITEM Spec Mask
639 : : * ETH type 0x0807 0xFFFF
640 : : * END
641 : : * other members in mask and spec should set to 0x00.
642 : : * item->last should be NULL.
643 : : */
644 : : static int
645 : 0 : cons_parse_ethertype_filter(const struct rte_flow_attr *attr,
646 : : const struct rte_flow_item *pattern,
647 : : const struct rte_flow_action *actions,
648 : : struct rte_eth_ethertype_filter *filter,
649 : : struct rte_flow_error *error)
650 : : {
651 : : const struct rte_flow_item *item;
652 : : const struct rte_flow_action *act;
653 : : const struct rte_flow_item_eth *eth_spec;
654 : : const struct rte_flow_item_eth *eth_mask;
655 : : const struct rte_flow_action_queue *act_q;
656 : :
657 [ # # ]: 0 : if (!pattern) {
658 : 0 : rte_flow_error_set(error, EINVAL,
659 : : RTE_FLOW_ERROR_TYPE_ITEM_NUM,
660 : : NULL, "NULL pattern.");
661 : 0 : return -rte_errno;
662 : : }
663 : :
664 [ # # ]: 0 : if (!actions) {
665 : 0 : rte_flow_error_set(error, EINVAL,
666 : : RTE_FLOW_ERROR_TYPE_ACTION_NUM,
667 : : NULL, "NULL action.");
668 : 0 : return -rte_errno;
669 : : }
670 : :
671 [ # # ]: 0 : if (!attr) {
672 : 0 : rte_flow_error_set(error, EINVAL,
673 : : RTE_FLOW_ERROR_TYPE_ATTR,
674 : : NULL, "NULL attribute.");
675 : 0 : return -rte_errno;
676 : : }
677 : :
678 : : item = next_no_void_pattern(pattern, NULL);
679 : : /* The first non-void item should be MAC. */
680 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_ETH) {
681 : 0 : rte_flow_error_set(error, EINVAL,
682 : : RTE_FLOW_ERROR_TYPE_ITEM,
683 : : item, "Not supported by ethertype filter");
684 : 0 : return -rte_errno;
685 : : }
686 : :
687 : : /*Not supported last point for range*/
688 [ # # ]: 0 : if (item->last) {
689 : 0 : rte_flow_error_set(error, EINVAL,
690 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
691 : : item, "Not supported last point for range");
692 : 0 : return -rte_errno;
693 : : }
694 : :
695 : : /* Get the MAC info. */
696 [ # # # # ]: 0 : if (!item->spec || !item->mask) {
697 : 0 : rte_flow_error_set(error, EINVAL,
698 : : RTE_FLOW_ERROR_TYPE_ITEM,
699 : : item, "Not supported by ethertype filter");
700 : 0 : return -rte_errno;
701 : : }
702 : :
703 : : eth_spec = item->spec;
704 : : eth_mask = item->mask;
705 : :
706 : : /* Mask bits of source MAC address must be full of 0.
707 : : * Mask bits of destination MAC address must be full
708 : : * of 1 or full of 0.
709 : : */
710 [ # # # # ]: 0 : if (!rte_is_zero_ether_addr(ð_mask->hdr.src_addr) ||
711 [ # # ]: 0 : (!rte_is_zero_ether_addr(ð_mask->hdr.dst_addr) &&
712 : : !rte_is_broadcast_ether_addr(ð_mask->hdr.dst_addr))) {
713 : 0 : rte_flow_error_set(error, EINVAL,
714 : : RTE_FLOW_ERROR_TYPE_ITEM,
715 : : item, "Invalid ether address mask");
716 : 0 : return -rte_errno;
717 : : }
718 : :
719 [ # # ]: 0 : if ((eth_mask->hdr.ether_type & UINT16_MAX) != UINT16_MAX) {
720 : 0 : rte_flow_error_set(error, EINVAL,
721 : : RTE_FLOW_ERROR_TYPE_ITEM,
722 : : item, "Invalid ethertype mask");
723 : 0 : return -rte_errno;
724 : : }
725 : :
726 : : /* If mask bits of destination MAC address
727 : : * are full of 1, set RTE_ETHTYPE_FLAGS_MAC.
728 : : */
729 [ # # ]: 0 : if (rte_is_broadcast_ether_addr(ð_mask->hdr.dst_addr)) {
730 : 0 : filter->mac_addr = eth_spec->hdr.dst_addr;
731 : 0 : filter->flags |= RTE_ETHTYPE_FLAGS_MAC;
732 : : } else {
733 : 0 : filter->flags &= ~RTE_ETHTYPE_FLAGS_MAC;
734 : : }
735 [ # # ]: 0 : filter->ether_type = rte_be_to_cpu_16(eth_spec->hdr.ether_type);
736 : :
737 : : /* Check if the next non-void item is END. */
738 : : item = next_no_void_pattern(pattern, item);
739 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END) {
740 : 0 : rte_flow_error_set(error, EINVAL,
741 : : RTE_FLOW_ERROR_TYPE_ITEM,
742 : : item, "Not supported by ethertype filter.");
743 : 0 : return -rte_errno;
744 : : }
745 : :
746 : : /* Parse action */
747 : :
748 : : act = next_no_void_action(actions, NULL);
749 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_QUEUE &&
750 : : act->type != RTE_FLOW_ACTION_TYPE_DROP) {
751 : 0 : rte_flow_error_set(error, EINVAL,
752 : : RTE_FLOW_ERROR_TYPE_ACTION,
753 : : act, "Not supported action.");
754 : 0 : return -rte_errno;
755 : : }
756 : :
757 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
758 : 0 : act_q = (const struct rte_flow_action_queue *)act->conf;
759 : 0 : filter->queue = act_q->index;
760 : : } else {
761 : 0 : filter->flags |= RTE_ETHTYPE_FLAGS_DROP;
762 : : }
763 : :
764 : : /* Check if the next non-void item is END */
765 : : act = next_no_void_action(actions, act);
766 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_END) {
767 : 0 : rte_flow_error_set(error, EINVAL,
768 : : RTE_FLOW_ERROR_TYPE_ACTION,
769 : : act, "Not supported action.");
770 : 0 : return -rte_errno;
771 : : }
772 : :
773 : : /* Parse attr */
774 : : /* Must be input direction */
775 [ # # ]: 0 : if (!attr->ingress) {
776 : 0 : rte_flow_error_set(error, EINVAL,
777 : : RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
778 : : attr, "Only support ingress.");
779 : 0 : return -rte_errno;
780 : : }
781 : :
782 : : /* Not supported */
783 [ # # ]: 0 : if (attr->egress) {
784 : 0 : rte_flow_error_set(error, EINVAL,
785 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
786 : : attr, "Not support egress.");
787 : 0 : return -rte_errno;
788 : : }
789 : :
790 : : /* Not supported */
791 [ # # ]: 0 : if (attr->transfer) {
792 : 0 : rte_flow_error_set(error, EINVAL,
793 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
794 : : attr, "No support for transfer.");
795 : 0 : return -rte_errno;
796 : : }
797 : :
798 : : /* Not supported */
799 [ # # ]: 0 : if (attr->priority) {
800 : 0 : rte_flow_error_set(error, EINVAL,
801 : : RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
802 : : attr, "Not support priority.");
803 : 0 : return -rte_errno;
804 : : }
805 : :
806 : : /* Not supported */
807 [ # # ]: 0 : if (attr->group) {
808 : 0 : rte_flow_error_set(error, EINVAL,
809 : : RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
810 : : attr, "Not support group.");
811 : 0 : return -rte_errno;
812 : : }
813 : :
814 : : return 0;
815 : : }
816 : :
817 : : static int
818 : 0 : txgbe_parse_ethertype_filter(struct rte_eth_dev *dev,
819 : : const struct rte_flow_attr *attr,
820 : : const struct rte_flow_item pattern[],
821 : : const struct rte_flow_action actions[],
822 : : struct rte_eth_ethertype_filter *filter,
823 : : struct rte_flow_error *error)
824 : : {
825 : : int ret;
826 : :
827 : 0 : ret = cons_parse_ethertype_filter(attr, pattern,
828 : : actions, filter, error);
829 : :
830 [ # # ]: 0 : if (ret)
831 : : return ret;
832 : :
833 [ # # ]: 0 : if (filter->queue >= dev->data->nb_rx_queues) {
834 : : memset(filter, 0, sizeof(struct rte_eth_ethertype_filter));
835 : 0 : rte_flow_error_set(error, EINVAL,
836 : : RTE_FLOW_ERROR_TYPE_ITEM,
837 : : NULL, "queue index much too big");
838 : 0 : return -rte_errno;
839 : : }
840 : :
841 [ # # ]: 0 : if (filter->ether_type == RTE_ETHER_TYPE_IPV4 ||
842 : : filter->ether_type == RTE_ETHER_TYPE_IPV6) {
843 : : memset(filter, 0, sizeof(struct rte_eth_ethertype_filter));
844 : 0 : rte_flow_error_set(error, EINVAL,
845 : : RTE_FLOW_ERROR_TYPE_ITEM,
846 : : NULL, "IPv4/IPv6 not supported by ethertype filter");
847 : 0 : return -rte_errno;
848 : : }
849 : :
850 [ # # ]: 0 : if (filter->flags & RTE_ETHTYPE_FLAGS_MAC) {
851 : : memset(filter, 0, sizeof(struct rte_eth_ethertype_filter));
852 : 0 : rte_flow_error_set(error, EINVAL,
853 : : RTE_FLOW_ERROR_TYPE_ITEM,
854 : : NULL, "mac compare is unsupported");
855 : 0 : return -rte_errno;
856 : : }
857 : :
858 [ # # ]: 0 : if (filter->flags & RTE_ETHTYPE_FLAGS_DROP) {
859 : : memset(filter, 0, sizeof(struct rte_eth_ethertype_filter));
860 : 0 : rte_flow_error_set(error, EINVAL,
861 : : RTE_FLOW_ERROR_TYPE_ITEM,
862 : : NULL, "drop option is unsupported");
863 : 0 : return -rte_errno;
864 : : }
865 : :
866 : : return 0;
867 : : }
868 : :
869 : : /**
870 : : * Parse the rule to see if it is a TCP SYN rule.
871 : : * And get the TCP SYN filter info BTW.
872 : : * pattern:
873 : : * The first not void item must be ETH.
874 : : * The second not void item must be IPV4 or IPV6.
875 : : * The third not void item must be TCP.
876 : : * The next not void item must be END.
877 : : * action:
878 : : * The first not void action should be QUEUE.
879 : : * The next not void action should be END.
880 : : * pattern example:
881 : : * ITEM Spec Mask
882 : : * ETH NULL NULL
883 : : * IPV4/IPV6 NULL NULL
884 : : * TCP tcp_flags 0x02 0xFF
885 : : * END
886 : : * other members in mask and spec should set to 0x00.
887 : : * item->last should be NULL.
888 : : */
889 : : static int
890 : 0 : cons_parse_syn_filter(const struct rte_flow_attr *attr,
891 : : const struct rte_flow_item pattern[],
892 : : const struct rte_flow_action actions[],
893 : : struct rte_eth_syn_filter *filter,
894 : : struct rte_flow_error *error)
895 : : {
896 : : const struct rte_flow_item *item;
897 : : const struct rte_flow_action *act;
898 : : const struct rte_flow_item_tcp *tcp_spec;
899 : : const struct rte_flow_item_tcp *tcp_mask;
900 : : const struct rte_flow_action_queue *act_q;
901 : :
902 [ # # ]: 0 : if (!pattern) {
903 : 0 : rte_flow_error_set(error, EINVAL,
904 : : RTE_FLOW_ERROR_TYPE_ITEM_NUM,
905 : : NULL, "NULL pattern.");
906 : 0 : return -rte_errno;
907 : : }
908 : :
909 [ # # ]: 0 : if (!actions) {
910 : 0 : rte_flow_error_set(error, EINVAL,
911 : : RTE_FLOW_ERROR_TYPE_ACTION_NUM,
912 : : NULL, "NULL action.");
913 : 0 : return -rte_errno;
914 : : }
915 : :
916 [ # # ]: 0 : if (!attr) {
917 : 0 : rte_flow_error_set(error, EINVAL,
918 : : RTE_FLOW_ERROR_TYPE_ATTR,
919 : : NULL, "NULL attribute.");
920 : 0 : return -rte_errno;
921 : : }
922 : :
923 : :
924 : : /* the first not void item should be MAC or IPv4 or IPv6 or TCP */
925 : : item = next_no_void_pattern(pattern, NULL);
926 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_ETH &&
927 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
928 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_IPV6 &&
929 : : item->type != RTE_FLOW_ITEM_TYPE_TCP) {
930 : 0 : rte_flow_error_set(error, EINVAL,
931 : : RTE_FLOW_ERROR_TYPE_ITEM,
932 : : item, "Not supported by syn filter");
933 : 0 : return -rte_errno;
934 : : }
935 : : /*Not supported last point for range*/
936 [ # # ]: 0 : if (item->last) {
937 : 0 : rte_flow_error_set(error, EINVAL,
938 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
939 : : item, "Not supported last point for range");
940 : 0 : return -rte_errno;
941 : : }
942 : :
943 : : /* Skip Ethernet */
944 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_ETH) {
945 : : /* if the item is MAC, the content should be NULL */
946 [ # # # # ]: 0 : if (item->spec || item->mask) {
947 : 0 : rte_flow_error_set(error, EINVAL,
948 : : RTE_FLOW_ERROR_TYPE_ITEM,
949 : : item, "Invalid SYN address mask");
950 : 0 : return -rte_errno;
951 : : }
952 : :
953 : : /* check if the next not void item is IPv4 or IPv6 */
954 : : item = next_no_void_pattern(pattern, item);
955 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
956 : : item->type != RTE_FLOW_ITEM_TYPE_IPV6) {
957 : 0 : rte_flow_error_set(error, EINVAL,
958 : : RTE_FLOW_ERROR_TYPE_ITEM,
959 : : item, "Not supported by syn filter");
960 : 0 : return -rte_errno;
961 : : }
962 : : }
963 : :
964 : : /* Skip IP */
965 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
966 : : item->type == RTE_FLOW_ITEM_TYPE_IPV6) {
967 : : /* if the item is IP, the content should be NULL */
968 [ # # # # ]: 0 : if (item->spec || item->mask) {
969 : 0 : rte_flow_error_set(error, EINVAL,
970 : : RTE_FLOW_ERROR_TYPE_ITEM,
971 : : item, "Invalid SYN mask");
972 : 0 : return -rte_errno;
973 : : }
974 : :
975 : : /* check if the next not void item is TCP */
976 : : item = next_no_void_pattern(pattern, item);
977 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_TCP) {
978 : 0 : rte_flow_error_set(error, EINVAL,
979 : : RTE_FLOW_ERROR_TYPE_ITEM,
980 : : item, "Not supported by syn filter");
981 : 0 : return -rte_errno;
982 : : }
983 : : }
984 : :
985 : : /* Get the TCP info. Only support SYN. */
986 [ # # # # ]: 0 : if (!item->spec || !item->mask) {
987 : 0 : rte_flow_error_set(error, EINVAL,
988 : : RTE_FLOW_ERROR_TYPE_ITEM,
989 : : item, "Invalid SYN mask");
990 : 0 : return -rte_errno;
991 : : }
992 : : /*Not supported last point for range*/
993 [ # # ]: 0 : if (item->last) {
994 : 0 : rte_flow_error_set(error, EINVAL,
995 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
996 : : item, "Not supported last point for range");
997 : 0 : return -rte_errno;
998 : : }
999 : :
1000 : : tcp_spec = item->spec;
1001 : : tcp_mask = item->mask;
1002 [ # # ]: 0 : if (!(tcp_spec->hdr.tcp_flags & RTE_TCP_SYN_FLAG) ||
1003 [ # # ]: 0 : tcp_mask->hdr.src_port ||
1004 [ # # ]: 0 : tcp_mask->hdr.dst_port ||
1005 [ # # ]: 0 : tcp_mask->hdr.sent_seq ||
1006 [ # # ]: 0 : tcp_mask->hdr.recv_ack ||
1007 [ # # ]: 0 : tcp_mask->hdr.data_off ||
1008 [ # # ]: 0 : tcp_mask->hdr.tcp_flags != RTE_TCP_SYN_FLAG ||
1009 [ # # ]: 0 : tcp_mask->hdr.rx_win ||
1010 [ # # ]: 0 : tcp_mask->hdr.cksum ||
1011 [ # # ]: 0 : tcp_mask->hdr.tcp_urp) {
1012 : : memset(filter, 0, sizeof(struct rte_eth_syn_filter));
1013 : 0 : rte_flow_error_set(error, EINVAL,
1014 : : RTE_FLOW_ERROR_TYPE_ITEM,
1015 : : item, "Not supported by syn filter");
1016 : 0 : return -rte_errno;
1017 : : }
1018 : :
1019 : : /* check if the next not void item is END */
1020 : : item = next_no_void_pattern(pattern, item);
1021 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END) {
1022 : : memset(filter, 0, sizeof(struct rte_eth_syn_filter));
1023 : 0 : rte_flow_error_set(error, EINVAL,
1024 : : RTE_FLOW_ERROR_TYPE_ITEM,
1025 : : item, "Not supported by syn filter");
1026 : 0 : return -rte_errno;
1027 : : }
1028 : :
1029 : : /* check if the first not void action is QUEUE. */
1030 : : act = next_no_void_action(actions, NULL);
1031 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_QUEUE) {
1032 : : memset(filter, 0, sizeof(struct rte_eth_syn_filter));
1033 : 0 : rte_flow_error_set(error, EINVAL,
1034 : : RTE_FLOW_ERROR_TYPE_ACTION,
1035 : : act, "Not supported action.");
1036 : 0 : return -rte_errno;
1037 : : }
1038 : :
1039 : 0 : act_q = (const struct rte_flow_action_queue *)act->conf;
1040 : 0 : filter->queue = act_q->index;
1041 [ # # ]: 0 : if (filter->queue >= TXGBE_MAX_RX_QUEUE_NUM) {
1042 : : memset(filter, 0, sizeof(struct rte_eth_syn_filter));
1043 : 0 : rte_flow_error_set(error, EINVAL,
1044 : : RTE_FLOW_ERROR_TYPE_ACTION,
1045 : : act, "Not supported action.");
1046 : 0 : return -rte_errno;
1047 : : }
1048 : :
1049 : : /* check if the next not void item is END */
1050 : : act = next_no_void_action(actions, act);
1051 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_END) {
1052 : : memset(filter, 0, sizeof(struct rte_eth_syn_filter));
1053 : 0 : rte_flow_error_set(error, EINVAL,
1054 : : RTE_FLOW_ERROR_TYPE_ACTION,
1055 : : act, "Not supported action.");
1056 : 0 : return -rte_errno;
1057 : : }
1058 : :
1059 : : /* parse attr */
1060 : : /* must be input direction */
1061 [ # # ]: 0 : if (!attr->ingress) {
1062 : : memset(filter, 0, sizeof(struct rte_eth_syn_filter));
1063 : 0 : rte_flow_error_set(error, EINVAL,
1064 : : RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1065 : : attr, "Only support ingress.");
1066 : 0 : return -rte_errno;
1067 : : }
1068 : :
1069 : : /* not supported */
1070 [ # # ]: 0 : if (attr->egress) {
1071 : : memset(filter, 0, sizeof(struct rte_eth_syn_filter));
1072 : 0 : rte_flow_error_set(error, EINVAL,
1073 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
1074 : : attr, "Not support egress.");
1075 : 0 : return -rte_errno;
1076 : : }
1077 : :
1078 : : /* not supported */
1079 [ # # ]: 0 : if (attr->transfer) {
1080 : : memset(filter, 0, sizeof(struct rte_eth_syn_filter));
1081 : 0 : rte_flow_error_set(error, EINVAL,
1082 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1083 : : attr, "No support for transfer.");
1084 : 0 : return -rte_errno;
1085 : : }
1086 : :
1087 : : /* Support 2 priorities, the lowest or highest. */
1088 [ # # ]: 0 : if (!attr->priority) {
1089 : 0 : filter->hig_pri = 0;
1090 [ # # ]: 0 : } else if (attr->priority == (uint32_t)~0U) {
1091 : 0 : filter->hig_pri = 1;
1092 : : } else {
1093 : : memset(filter, 0, sizeof(struct rte_eth_syn_filter));
1094 : 0 : rte_flow_error_set(error, EINVAL,
1095 : : RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1096 : : attr, "Not support priority.");
1097 : 0 : return -rte_errno;
1098 : : }
1099 : :
1100 : : return 0;
1101 : : }
1102 : :
1103 : : static int
1104 : : txgbe_parse_syn_filter(struct rte_eth_dev *dev,
1105 : : const struct rte_flow_attr *attr,
1106 : : const struct rte_flow_item pattern[],
1107 : : const struct rte_flow_action actions[],
1108 : : struct rte_eth_syn_filter *filter,
1109 : : struct rte_flow_error *error)
1110 : : {
1111 : : int ret;
1112 : :
1113 : 0 : ret = cons_parse_syn_filter(attr, pattern,
1114 : : actions, filter, error);
1115 : :
1116 [ # # # # ]: 0 : if (filter->queue >= dev->data->nb_rx_queues)
1117 : 0 : return -rte_errno;
1118 : :
1119 [ # # # # ]: 0 : if (ret)
1120 : : return ret;
1121 : :
1122 : : return 0;
1123 : : }
1124 : :
1125 : : /**
1126 : : * Parse the rule to see if it is a L2 tunnel rule.
1127 : : * And get the L2 tunnel filter info BTW.
1128 : : * Only support E-tag now.
1129 : : * pattern:
1130 : : * The first not void item can be E_TAG.
1131 : : * The next not void item must be END.
1132 : : * action:
1133 : : * The first not void action should be VF or PF.
1134 : : * The next not void action should be END.
1135 : : * pattern example:
1136 : : * ITEM Spec Mask
1137 : : * E_TAG grp 0x1 0x3
1138 : : e_cid_base 0x309 0xFFF
1139 : : * END
1140 : : * other members in mask and spec should set to 0x00.
1141 : : * item->last should be NULL.
1142 : : */
1143 : : static int
1144 : 0 : cons_parse_l2_tn_filter(struct rte_eth_dev *dev,
1145 : : const struct rte_flow_attr *attr,
1146 : : const struct rte_flow_item pattern[],
1147 : : const struct rte_flow_action actions[],
1148 : : struct txgbe_l2_tunnel_conf *filter,
1149 : : struct rte_flow_error *error)
1150 : : {
1151 : : const struct rte_flow_item *item;
1152 : : const struct rte_flow_item_e_tag *e_tag_spec;
1153 : : const struct rte_flow_item_e_tag *e_tag_mask;
1154 : : const struct rte_flow_action *act;
1155 : : const struct rte_flow_action_vf *act_vf;
1156 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1157 : :
1158 [ # # ]: 0 : if (!pattern) {
1159 : 0 : rte_flow_error_set(error, EINVAL,
1160 : : RTE_FLOW_ERROR_TYPE_ITEM_NUM,
1161 : : NULL, "NULL pattern.");
1162 : 0 : return -rte_errno;
1163 : : }
1164 : :
1165 [ # # ]: 0 : if (!actions) {
1166 : 0 : rte_flow_error_set(error, EINVAL,
1167 : : RTE_FLOW_ERROR_TYPE_ACTION_NUM,
1168 : : NULL, "NULL action.");
1169 : 0 : return -rte_errno;
1170 : : }
1171 : :
1172 [ # # ]: 0 : if (!attr) {
1173 : 0 : rte_flow_error_set(error, EINVAL,
1174 : : RTE_FLOW_ERROR_TYPE_ATTR,
1175 : : NULL, "NULL attribute.");
1176 : 0 : return -rte_errno;
1177 : : }
1178 : :
1179 : : /* The first not void item should be e-tag. */
1180 : : item = next_no_void_pattern(pattern, NULL);
1181 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_E_TAG) {
1182 : : memset(filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
1183 : 0 : rte_flow_error_set(error, EINVAL,
1184 : : RTE_FLOW_ERROR_TYPE_ITEM,
1185 : : item, "Not supported by L2 tunnel filter");
1186 : 0 : return -rte_errno;
1187 : : }
1188 : :
1189 [ # # # # ]: 0 : if (!item->spec || !item->mask) {
1190 : : memset(filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
1191 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ITEM,
1192 : : item, "Not supported by L2 tunnel filter");
1193 : 0 : return -rte_errno;
1194 : : }
1195 : :
1196 : : /*Not supported last point for range*/
1197 [ # # ]: 0 : if (item->last) {
1198 : 0 : rte_flow_error_set(error, EINVAL,
1199 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1200 : : item, "Not supported last point for range");
1201 : 0 : return -rte_errno;
1202 : : }
1203 : :
1204 : : e_tag_spec = item->spec;
1205 : : e_tag_mask = item->mask;
1206 : :
1207 : : /* Only care about GRP and E cid base. */
1208 [ # # ]: 0 : if (e_tag_mask->epcp_edei_in_ecid_b ||
1209 [ # # ]: 0 : e_tag_mask->in_ecid_e ||
1210 : 0 : e_tag_mask->ecid_e ||
1211 [ # # ]: 0 : e_tag_mask->rsvd_grp_ecid_b != rte_cpu_to_be_16(0x3FFF)) {
1212 : : memset(filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
1213 : 0 : rte_flow_error_set(error, EINVAL,
1214 : : RTE_FLOW_ERROR_TYPE_ITEM,
1215 : : item, "Not supported by L2 tunnel filter");
1216 : 0 : return -rte_errno;
1217 : : }
1218 : :
1219 : 0 : filter->l2_tunnel_type = RTE_ETH_L2_TUNNEL_TYPE_E_TAG;
1220 : : /**
1221 : : * grp and e_cid_base are bit fields and only use 14 bits.
1222 : : * e-tag id is taken as little endian by HW.
1223 : : */
1224 [ # # ]: 0 : filter->tunnel_id = rte_be_to_cpu_16(e_tag_spec->rsvd_grp_ecid_b);
1225 : :
1226 : : /* check if the next not void item is END */
1227 : : item = next_no_void_pattern(pattern, item);
1228 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END) {
1229 : : memset(filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
1230 : 0 : rte_flow_error_set(error, EINVAL,
1231 : : RTE_FLOW_ERROR_TYPE_ITEM,
1232 : : item, "Not supported by L2 tunnel filter");
1233 : 0 : return -rte_errno;
1234 : : }
1235 : :
1236 : : /* parse attr */
1237 : : /* must be input direction */
1238 [ # # ]: 0 : if (!attr->ingress) {
1239 : : memset(filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
1240 : 0 : rte_flow_error_set(error, EINVAL,
1241 : : RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1242 : : attr, "Only support ingress.");
1243 : 0 : return -rte_errno;
1244 : : }
1245 : :
1246 : : /* not supported */
1247 [ # # ]: 0 : if (attr->egress) {
1248 : : memset(filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
1249 : 0 : rte_flow_error_set(error, EINVAL,
1250 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
1251 : : attr, "Not support egress.");
1252 : 0 : return -rte_errno;
1253 : : }
1254 : :
1255 : : /* not supported */
1256 [ # # ]: 0 : if (attr->transfer) {
1257 : : memset(filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
1258 : 0 : rte_flow_error_set(error, EINVAL,
1259 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1260 : : attr, "No support for transfer.");
1261 : 0 : return -rte_errno;
1262 : : }
1263 : :
1264 : : /* not supported */
1265 [ # # ]: 0 : if (attr->priority) {
1266 : : memset(filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
1267 : 0 : rte_flow_error_set(error, EINVAL,
1268 : : RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1269 : : attr, "Not support priority.");
1270 : 0 : return -rte_errno;
1271 : : }
1272 : :
1273 : : /* check if the first not void action is VF or PF. */
1274 : : act = next_no_void_action(actions, NULL);
1275 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_VF &&
1276 : : act->type != RTE_FLOW_ACTION_TYPE_PF) {
1277 : : memset(filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
1278 : 0 : rte_flow_error_set(error, EINVAL,
1279 : : RTE_FLOW_ERROR_TYPE_ACTION,
1280 : : act, "Not supported action.");
1281 : 0 : return -rte_errno;
1282 : : }
1283 : :
1284 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_VF) {
1285 : 0 : act_vf = (const struct rte_flow_action_vf *)act->conf;
1286 : 0 : filter->pool = act_vf->id;
1287 : : } else {
1288 : 0 : filter->pool = pci_dev->max_vfs;
1289 : : }
1290 : :
1291 : : /* check if the next not void item is END */
1292 : : act = next_no_void_action(actions, act);
1293 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_END) {
1294 : : memset(filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
1295 : 0 : rte_flow_error_set(error, EINVAL,
1296 : : RTE_FLOW_ERROR_TYPE_ACTION,
1297 : : act, "Not supported action.");
1298 : 0 : return -rte_errno;
1299 : : }
1300 : :
1301 : : return 0;
1302 : : }
1303 : :
1304 : : static int
1305 : : txgbe_parse_l2_tn_filter(struct rte_eth_dev *dev,
1306 : : const struct rte_flow_attr *attr,
1307 : : const struct rte_flow_item pattern[],
1308 : : const struct rte_flow_action actions[],
1309 : : struct txgbe_l2_tunnel_conf *l2_tn_filter,
1310 : : struct rte_flow_error *error)
1311 : : {
1312 : : int ret = 0;
1313 : 0 : struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1314 : : uint16_t vf_num;
1315 : :
1316 : 0 : ret = cons_parse_l2_tn_filter(dev, attr, pattern,
1317 : : actions, l2_tn_filter, error);
1318 : :
1319 : 0 : vf_num = pci_dev->max_vfs;
1320 : :
1321 [ # # # # ]: 0 : if (l2_tn_filter->pool > vf_num)
1322 : 0 : return -rte_errno;
1323 : :
1324 : : return ret;
1325 : : }
1326 : :
1327 : : /* Parse to get the attr and action info of flow director rule. */
1328 : : static int
1329 : 0 : txgbe_parse_fdir_act_attr(const struct rte_flow_attr *attr,
1330 : : const struct rte_flow_action actions[],
1331 : : struct txgbe_fdir_rule *rule,
1332 : : struct rte_flow_error *error)
1333 : : {
1334 : : const struct rte_flow_action *act;
1335 : : const struct rte_flow_action_queue *act_q;
1336 : : const struct rte_flow_action_mark *mark;
1337 : :
1338 : : /* parse attr */
1339 : : /* must be input direction */
1340 [ # # ]: 0 : if (!attr->ingress) {
1341 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1342 : 0 : rte_flow_error_set(error, EINVAL,
1343 : : RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
1344 : : attr, "Only support ingress.");
1345 : 0 : return -rte_errno;
1346 : : }
1347 : :
1348 : : /* not supported */
1349 [ # # ]: 0 : if (attr->egress) {
1350 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1351 : 0 : rte_flow_error_set(error, EINVAL,
1352 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
1353 : : attr, "Not support egress.");
1354 : 0 : return -rte_errno;
1355 : : }
1356 : :
1357 : : /* not supported */
1358 [ # # ]: 0 : if (attr->transfer) {
1359 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1360 : 0 : rte_flow_error_set(error, EINVAL,
1361 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1362 : : attr, "No support for transfer.");
1363 : 0 : return -rte_errno;
1364 : : }
1365 : :
1366 : : /* not supported */
1367 [ # # ]: 0 : if (attr->priority) {
1368 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1369 : 0 : rte_flow_error_set(error, EINVAL,
1370 : : RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1371 : : attr, "Not support priority.");
1372 : 0 : return -rte_errno;
1373 : : }
1374 : :
1375 : : /* check if the first not void action is QUEUE or DROP. */
1376 : : act = next_no_void_action(actions, NULL);
1377 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_QUEUE &&
1378 : : act->type != RTE_FLOW_ACTION_TYPE_DROP) {
1379 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1380 : 0 : rte_flow_error_set(error, EINVAL,
1381 : : RTE_FLOW_ERROR_TYPE_ACTION,
1382 : : act, "Not supported action.");
1383 : 0 : return -rte_errno;
1384 : : }
1385 : :
1386 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_QUEUE) {
1387 : 0 : act_q = (const struct rte_flow_action_queue *)act->conf;
1388 : 0 : rule->queue = act_q->index;
1389 : : } else { /* drop */
1390 : : /* signature mode does not support drop action. */
1391 [ # # ]: 0 : if (rule->mode == RTE_FDIR_MODE_SIGNATURE) {
1392 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1393 : 0 : rte_flow_error_set(error, EINVAL,
1394 : : RTE_FLOW_ERROR_TYPE_ACTION,
1395 : : act, "Not supported action.");
1396 : 0 : return -rte_errno;
1397 : : }
1398 : 0 : rule->fdirflags = TXGBE_FDIRPICMD_DROP;
1399 : : }
1400 : :
1401 : : /* check if the next not void item is MARK */
1402 : : act = next_no_void_action(actions, act);
1403 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_MARK &&
1404 : : act->type != RTE_FLOW_ACTION_TYPE_END) {
1405 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1406 : 0 : rte_flow_error_set(error, EINVAL,
1407 : : RTE_FLOW_ERROR_TYPE_ACTION,
1408 : : act, "Not supported action.");
1409 : 0 : return -rte_errno;
1410 : : }
1411 : :
1412 : 0 : rule->soft_id = 0;
1413 : :
1414 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_MARK) {
1415 : 0 : mark = (const struct rte_flow_action_mark *)act->conf;
1416 : 0 : rule->soft_id = mark->id;
1417 : : act = next_no_void_action(actions, act);
1418 : : }
1419 : :
1420 : : /* check if the next not void item is END */
1421 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_END) {
1422 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1423 : 0 : rte_flow_error_set(error, EINVAL,
1424 : : RTE_FLOW_ERROR_TYPE_ACTION,
1425 : : act, "Not supported action.");
1426 : 0 : return -rte_errno;
1427 : : }
1428 : :
1429 : : return 0;
1430 : : }
1431 : :
1432 : : /* search next no void pattern and skip fuzzy */
1433 : : static inline
1434 : : const struct rte_flow_item *next_no_fuzzy_pattern(
1435 : : const struct rte_flow_item pattern[],
1436 : : const struct rte_flow_item *cur)
1437 : : {
1438 : : const struct rte_flow_item *next =
1439 : : next_no_void_pattern(pattern, cur);
1440 : : while (1) {
1441 [ # # # # : 0 : if (next->type != RTE_FLOW_ITEM_TYPE_FUZZY)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
1442 : : return next;
1443 : : next = next_no_void_pattern(pattern, next);
1444 : : }
1445 : : }
1446 : :
1447 : 0 : static inline uint8_t signature_match(const struct rte_flow_item pattern[])
1448 : : {
1449 : : const struct rte_flow_item_fuzzy *spec, *last, *mask;
1450 : : const struct rte_flow_item *item;
1451 : : uint32_t sh, lh, mh;
1452 : : int i = 0;
1453 : :
1454 : : while (1) {
1455 : 0 : item = pattern + i;
1456 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_END)
1457 : : break;
1458 : :
1459 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_FUZZY) {
1460 : 0 : spec = item->spec;
1461 : 0 : last = item->last;
1462 : 0 : mask = item->mask;
1463 : :
1464 [ # # ]: 0 : if (!spec || !mask)
1465 : : return 0;
1466 : :
1467 : 0 : sh = spec->thresh;
1468 : :
1469 [ # # ]: 0 : if (!last)
1470 : : lh = sh;
1471 : : else
1472 : 0 : lh = last->thresh;
1473 : :
1474 : 0 : mh = mask->thresh;
1475 : 0 : sh = sh & mh;
1476 : 0 : lh = lh & mh;
1477 : :
1478 [ # # ]: 0 : if (!sh || sh > lh)
1479 : : return 0;
1480 : :
1481 : 0 : return 1;
1482 : : }
1483 : :
1484 : 0 : i++;
1485 : : }
1486 : :
1487 : : return 0;
1488 : : }
1489 : :
1490 : : static void
1491 : 0 : txgbe_fdir_parse_flow_type(struct txgbe_atr_input *input, u8 ptid, bool tun)
1492 : : {
1493 [ # # ]: 0 : if (!tun)
1494 : : ptid = TXGBE_PTID_PKT_IP;
1495 : :
1496 [ # # # # ]: 0 : switch (input->flow_type & TXGBE_ATR_L4TYPE_MASK) {
1497 : 0 : case TXGBE_ATR_L4TYPE_UDP:
1498 : 0 : ptid |= TXGBE_PTID_TYP_UDP;
1499 : 0 : break;
1500 : 0 : case TXGBE_ATR_L4TYPE_TCP:
1501 : 0 : ptid |= TXGBE_PTID_TYP_TCP;
1502 : 0 : break;
1503 : 0 : case TXGBE_ATR_L4TYPE_SCTP:
1504 : 0 : ptid |= TXGBE_PTID_TYP_SCTP;
1505 : 0 : break;
1506 : : default:
1507 : : break;
1508 : : }
1509 : :
1510 [ # # ]: 0 : switch (input->flow_type & TXGBE_ATR_L3TYPE_MASK) {
1511 : : case TXGBE_ATR_L3TYPE_IPV4:
1512 : : break;
1513 : 0 : case TXGBE_ATR_L3TYPE_IPV6:
1514 : 0 : ptid |= TXGBE_PTID_PKT_IPV6;
1515 : 0 : break;
1516 : : default:
1517 : : break;
1518 : : }
1519 : :
1520 [ # # ]: 0 : input->pkt_type = cpu_to_be16(ptid);
1521 : 0 : }
1522 : :
1523 : : /**
1524 : : * Parse the rule to see if it is a IP flow director rule.
1525 : : * And get the flow director filter info BTW.
1526 : : * UDP/TCP/SCTP PATTERN:
1527 : : * The first not void item can be ETH or IPV4 or IPV6
1528 : : * The second not void item must be IPV4 or IPV6 if the first one is ETH.
1529 : : * The next not void item could be UDP or TCP or SCTP (optional)
1530 : : * The next not void item could be RAW (for flexbyte, optional)
1531 : : * The next not void item must be END.
1532 : : * A Fuzzy Match pattern can appear at any place before END.
1533 : : * Fuzzy Match is optional for IPV4 but is required for IPV6
1534 : : * MAC VLAN PATTERN:
1535 : : * The first not void item must be ETH.
1536 : : * The second not void item must be MAC VLAN.
1537 : : * The next not void item must be END.
1538 : : * ACTION:
1539 : : * The first not void action should be QUEUE or DROP.
1540 : : * The second not void optional action should be MARK,
1541 : : * mark_id is a uint32_t number.
1542 : : * The next not void action should be END.
1543 : : * UDP/TCP/SCTP pattern example:
1544 : : * ITEM Spec Mask
1545 : : * ETH NULL NULL
1546 : : * IPV4 src_addr 192.168.1.20 0xFFFFFFFF
1547 : : * dst_addr 192.167.3.50 0xFFFFFFFF
1548 : : * UDP/TCP/SCTP src_port 80 0xFFFF
1549 : : * dst_port 80 0xFFFF
1550 : : * FLEX relative 0 0x1
1551 : : * search 0 0x1
1552 : : * reserved 0 0
1553 : : * offset 12 0xFFFFFFFF
1554 : : * limit 0 0xFFFF
1555 : : * length 2 0xFFFF
1556 : : * pattern[0] 0x86 0xFF
1557 : : * pattern[1] 0xDD 0xFF
1558 : : * END
1559 : : * MAC VLAN pattern example:
1560 : : * ITEM Spec Mask
1561 : : * ETH dst_addr
1562 : : {0xAC, 0x7B, 0xA1, {0xFF, 0xFF, 0xFF,
1563 : : 0x2C, 0x6D, 0x36} 0xFF, 0xFF, 0xFF}
1564 : : * MAC VLAN tci 0x2016 0xEFFF
1565 : : * END
1566 : : * Other members in mask and spec should set to 0x00.
1567 : : * Item->last should be NULL.
1568 : : */
1569 : : static int
1570 : 0 : txgbe_parse_fdir_filter_normal(struct rte_eth_dev *dev __rte_unused,
1571 : : const struct rte_flow_attr *attr,
1572 : : const struct rte_flow_item pattern[],
1573 : : const struct rte_flow_action actions[],
1574 : : struct txgbe_fdir_rule *rule,
1575 : : struct rte_flow_error *error)
1576 : : {
1577 : : const struct rte_flow_item *item;
1578 : : const struct rte_flow_item_eth *eth_mask;
1579 : : const struct rte_flow_item_ipv4 *ipv4_spec;
1580 : : const struct rte_flow_item_ipv4 *ipv4_mask;
1581 : : const struct rte_flow_item_ipv6 *ipv6_spec;
1582 : : const struct rte_flow_item_ipv6 *ipv6_mask;
1583 : : const struct rte_flow_item_tcp *tcp_spec;
1584 : : const struct rte_flow_item_tcp *tcp_mask;
1585 : : const struct rte_flow_item_udp *udp_spec;
1586 : : const struct rte_flow_item_udp *udp_mask;
1587 : : const struct rte_flow_item_sctp *sctp_spec;
1588 : : const struct rte_flow_item_sctp *sctp_mask;
1589 : : const struct rte_flow_item_raw *raw_mask;
1590 : : const struct rte_flow_item_raw *raw_spec;
1591 : : uint8_t j;
1592 : :
1593 [ # # ]: 0 : if (!pattern) {
1594 : 0 : rte_flow_error_set(error, EINVAL,
1595 : : RTE_FLOW_ERROR_TYPE_ITEM_NUM,
1596 : : NULL, "NULL pattern.");
1597 : 0 : return -rte_errno;
1598 : : }
1599 : :
1600 [ # # ]: 0 : if (!actions) {
1601 : 0 : rte_flow_error_set(error, EINVAL,
1602 : : RTE_FLOW_ERROR_TYPE_ACTION_NUM,
1603 : : NULL, "NULL action.");
1604 : 0 : return -rte_errno;
1605 : : }
1606 : :
1607 [ # # ]: 0 : if (!attr) {
1608 : 0 : rte_flow_error_set(error, EINVAL,
1609 : : RTE_FLOW_ERROR_TYPE_ATTR,
1610 : : NULL, "NULL attribute.");
1611 : 0 : return -rte_errno;
1612 : : }
1613 : :
1614 : : /**
1615 : : * Some fields may not be provided. Set spec to 0 and mask to default
1616 : : * value. So, we need not do anything for the not provided fields later.
1617 : : */
1618 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1619 : : memset(&rule->mask, 0, sizeof(struct txgbe_hw_fdir_mask));
1620 : 0 : rule->mask.pkt_type_mask = TXGBE_ATR_TYPE_MASK_L3P |
1621 : : TXGBE_ATR_TYPE_MASK_L4P;
1622 : 0 : memset(&rule->input, 0, sizeof(struct txgbe_atr_input));
1623 : :
1624 : : /**
1625 : : * The first not void item should be
1626 : : * MAC or IPv4 or TCP or UDP or SCTP.
1627 : : */
1628 : : item = next_no_fuzzy_pattern(pattern, NULL);
1629 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_ETH &&
1630 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
1631 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_IPV6 &&
1632 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_TCP &&
1633 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_UDP &&
1634 : : item->type != RTE_FLOW_ITEM_TYPE_SCTP) {
1635 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1636 : 0 : rte_flow_error_set(error, EINVAL,
1637 : : RTE_FLOW_ERROR_TYPE_ITEM,
1638 : : item, "Not supported by fdir filter");
1639 : 0 : return -rte_errno;
1640 : : }
1641 : :
1642 [ # # ]: 0 : if (signature_match(pattern))
1643 : 0 : rule->mode = RTE_FDIR_MODE_SIGNATURE;
1644 : : else
1645 : 0 : rule->mode = RTE_FDIR_MODE_PERFECT;
1646 : :
1647 : : /*Not supported last point for range*/
1648 [ # # ]: 0 : if (item->last) {
1649 : 0 : rte_flow_error_set(error, EINVAL,
1650 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1651 : : item, "Not supported last point for range");
1652 : 0 : return -rte_errno;
1653 : : }
1654 : :
1655 : : /* Get the MAC info. */
1656 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_ETH) {
1657 : : /**
1658 : : * Only support vlan and dst MAC address,
1659 : : * others should be masked.
1660 : : */
1661 [ # # # # ]: 0 : if (item->spec && !item->mask) {
1662 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1663 : 0 : rte_flow_error_set(error, EINVAL,
1664 : : RTE_FLOW_ERROR_TYPE_ITEM,
1665 : : item, "Not supported by fdir filter");
1666 : 0 : return -rte_errno;
1667 : : }
1668 : :
1669 [ # # ]: 0 : if (item->mask) {
1670 : 0 : rule->b_mask = TRUE;
1671 : : eth_mask = item->mask;
1672 : :
1673 : : /* Ether type should be masked. */
1674 [ # # ]: 0 : if (eth_mask->hdr.ether_type ||
1675 [ # # ]: 0 : rule->mode == RTE_FDIR_MODE_SIGNATURE) {
1676 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1677 : 0 : rte_flow_error_set(error, EINVAL,
1678 : : RTE_FLOW_ERROR_TYPE_ITEM,
1679 : : item, "Not supported by fdir filter");
1680 : 0 : return -rte_errno;
1681 : : }
1682 : :
1683 : : /* If ethernet has meaning, it means MAC VLAN mode. */
1684 : 0 : rule->mode = RTE_FDIR_MODE_PERFECT_MAC_VLAN;
1685 : :
1686 : : /**
1687 : : * src MAC address must be masked,
1688 : : * and don't support dst MAC address mask.
1689 : : */
1690 [ # # ]: 0 : for (j = 0; j < RTE_ETHER_ADDR_LEN; j++) {
1691 [ # # ]: 0 : if (eth_mask->hdr.src_addr.addr_bytes[j] ||
1692 [ # # ]: 0 : eth_mask->hdr.dst_addr.addr_bytes[j] != 0xFF) {
1693 : : memset(rule, 0,
1694 : : sizeof(struct txgbe_fdir_rule));
1695 : 0 : rte_flow_error_set(error, EINVAL,
1696 : : RTE_FLOW_ERROR_TYPE_ITEM,
1697 : : item, "Not supported by fdir filter");
1698 : 0 : return -rte_errno;
1699 : : }
1700 : : }
1701 : :
1702 : : /* When no VLAN, considered as full mask. */
1703 : 0 : rule->mask.vlan_tci_mask = rte_cpu_to_be_16(0xEFFF);
1704 : : }
1705 : : /*** If both spec and mask are item,
1706 : : * it means don't care about ETH.
1707 : : * Do nothing.
1708 : : */
1709 : :
1710 : : /**
1711 : : * Check if the next not void item is vlan or ipv4.
1712 : : * IPv6 is not supported.
1713 : : */
1714 : : item = next_no_fuzzy_pattern(pattern, item);
1715 [ # # ]: 0 : if (rule->mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
1716 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_VLAN) {
1717 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1718 : 0 : rte_flow_error_set(error, EINVAL,
1719 : : RTE_FLOW_ERROR_TYPE_ITEM,
1720 : : item, "Not supported by fdir filter");
1721 : 0 : return -rte_errno;
1722 : : }
1723 : : } else {
1724 : 0 : if (item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
1725 : : item->type != RTE_FLOW_ITEM_TYPE_VLAN &&
1726 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_IPV6 &&
1727 : : item->type != RTE_FLOW_ITEM_TYPE_RAW) {
1728 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1729 : 0 : rte_flow_error_set(error, EINVAL,
1730 : : RTE_FLOW_ERROR_TYPE_ITEM,
1731 : : item, "Not supported by fdir filter");
1732 : 0 : return -rte_errno;
1733 : : }
1734 : : }
1735 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_VLAN)
1736 : : item = next_no_fuzzy_pattern(pattern, item);
1737 : : }
1738 : :
1739 : : /* Get the IPV4 info. */
1740 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_IPV4) {
1741 : : /**
1742 : : * Set the flow type even if there's no content
1743 : : * as we must have a flow type.
1744 : : */
1745 : : rule->input.flow_type = TXGBE_ATR_FLOW_TYPE_IPV4;
1746 : 0 : rule->mask.pkt_type_mask &= ~TXGBE_ATR_TYPE_MASK_L3P;
1747 : : /*Not supported last point for range*/
1748 [ # # ]: 0 : if (item->last) {
1749 : 0 : rte_flow_error_set(error, EINVAL,
1750 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1751 : : item, "Not supported last point for range");
1752 : 0 : return -rte_errno;
1753 : : }
1754 : : /**
1755 : : * Only care about src & dst addresses,
1756 : : * others should be masked.
1757 : : */
1758 [ # # ]: 0 : if (item->mask) {
1759 : 0 : rule->b_mask = TRUE;
1760 : : ipv4_mask = item->mask;
1761 [ # # ]: 0 : if (ipv4_mask->hdr.version_ihl ||
1762 : 0 : ipv4_mask->hdr.type_of_service ||
1763 [ # # ]: 0 : ipv4_mask->hdr.total_length ||
1764 [ # # ]: 0 : ipv4_mask->hdr.packet_id ||
1765 [ # # ]: 0 : ipv4_mask->hdr.fragment_offset ||
1766 [ # # ]: 0 : ipv4_mask->hdr.time_to_live ||
1767 : 0 : ipv4_mask->hdr.next_proto_id ||
1768 [ # # ]: 0 : ipv4_mask->hdr.hdr_checksum) {
1769 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1770 : 0 : rte_flow_error_set(error, EINVAL,
1771 : : RTE_FLOW_ERROR_TYPE_ITEM,
1772 : : item, "Not supported by fdir filter");
1773 : 0 : return -rte_errno;
1774 : : }
1775 : 0 : rule->mask.dst_ipv4_mask = ipv4_mask->hdr.dst_addr;
1776 : 0 : rule->mask.src_ipv4_mask = ipv4_mask->hdr.src_addr;
1777 : : }
1778 : :
1779 [ # # ]: 0 : if (item->spec) {
1780 : 0 : rule->b_spec = TRUE;
1781 : : ipv4_spec = item->spec;
1782 : 0 : rule->input.dst_ip[0] =
1783 : 0 : ipv4_spec->hdr.dst_addr;
1784 : 0 : rule->input.src_ip[0] =
1785 : 0 : ipv4_spec->hdr.src_addr;
1786 : : }
1787 : :
1788 : : /**
1789 : : * Check if the next not void item is
1790 : : * TCP or UDP or SCTP or END.
1791 : : */
1792 : : item = next_no_fuzzy_pattern(pattern, item);
1793 : 0 : if (item->type != RTE_FLOW_ITEM_TYPE_TCP &&
1794 : : item->type != RTE_FLOW_ITEM_TYPE_UDP &&
1795 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_SCTP &&
1796 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_END &&
1797 : : item->type != RTE_FLOW_ITEM_TYPE_RAW) {
1798 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1799 : 0 : rte_flow_error_set(error, EINVAL,
1800 : : RTE_FLOW_ERROR_TYPE_ITEM,
1801 : : item, "Not supported by fdir filter");
1802 : 0 : return -rte_errno;
1803 : : }
1804 : : }
1805 : :
1806 : : /* Get the IPV6 info. */
1807 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_IPV6) {
1808 : : /**
1809 : : * Set the flow type even if there's no content
1810 : : * as we must have a flow type.
1811 : : */
1812 : 0 : rule->input.flow_type = TXGBE_ATR_FLOW_TYPE_IPV6;
1813 : 0 : rule->mask.pkt_type_mask &= ~TXGBE_ATR_TYPE_MASK_L3P;
1814 : :
1815 [ # # ]: 0 : if (item->last) {
1816 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1817 : 0 : rte_flow_error_set(error, EINVAL,
1818 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1819 : : item, "Not supported last point for range");
1820 : 0 : return -rte_errno;
1821 : : }
1822 : :
1823 [ # # ]: 0 : if (item->mask) {
1824 : 0 : rule->b_mask = TRUE;
1825 : : ipv6_mask = item->mask;
1826 [ # # ]: 0 : if (ipv6_mask->hdr.vtc_flow ||
1827 : : ipv6_mask->hdr.payload_len ||
1828 [ # # ]: 0 : ipv6_mask->hdr.proto ||
1829 : : ipv6_mask->hdr.hop_limits) {
1830 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1831 : 0 : rte_flow_error_set(error, EINVAL,
1832 : : RTE_FLOW_ERROR_TYPE_ITEM,
1833 : : item, "Not supported by fdir filter");
1834 : 0 : return -rte_errno;
1835 : : }
1836 : :
1837 : : /* check src addr mask */
1838 [ # # ]: 0 : for (j = 0; j < 16; j++) {
1839 [ # # ]: 0 : if (ipv6_mask->hdr.src_addr.a[j] == UINT8_MAX) {
1840 : 0 : rule->mask.src_ipv6_mask |= 1 << j;
1841 [ # # ]: 0 : } else if (ipv6_mask->hdr.src_addr.a[j] != 0) {
1842 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1843 : 0 : rte_flow_error_set(error, EINVAL,
1844 : : RTE_FLOW_ERROR_TYPE_ITEM,
1845 : : item, "Not supported by fdir filter");
1846 : 0 : return -rte_errno;
1847 : : }
1848 : : }
1849 : :
1850 : : /* check dst addr mask */
1851 [ # # ]: 0 : for (j = 0; j < 16; j++) {
1852 [ # # ]: 0 : if (ipv6_mask->hdr.dst_addr.a[j] == UINT8_MAX) {
1853 : 0 : rule->mask.dst_ipv6_mask |= 1 << j;
1854 [ # # ]: 0 : } else if (ipv6_mask->hdr.dst_addr.a[j] != 0) {
1855 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1856 : 0 : rte_flow_error_set(error, EINVAL,
1857 : : RTE_FLOW_ERROR_TYPE_ITEM,
1858 : : item, "Not supported by fdir filter");
1859 : 0 : return -rte_errno;
1860 : : }
1861 : : }
1862 : : }
1863 : :
1864 [ # # ]: 0 : if (item->spec) {
1865 : 0 : rule->b_spec = TRUE;
1866 : : ipv6_spec = item->spec;
1867 : 0 : rte_memcpy(rule->input.src_ip,
1868 [ # # ]: 0 : &ipv6_spec->hdr.src_addr, 16);
1869 : 0 : rte_memcpy(rule->input.dst_ip,
1870 [ # # ]: 0 : &ipv6_spec->hdr.dst_addr, 16);
1871 : : }
1872 : :
1873 : : /**
1874 : : * Check if the next not void item is
1875 : : * TCP or UDP or SCTP or END.
1876 : : */
1877 : : item = next_no_fuzzy_pattern(pattern, item);
1878 : 0 : if (item->type != RTE_FLOW_ITEM_TYPE_TCP &&
1879 : : item->type != RTE_FLOW_ITEM_TYPE_UDP &&
1880 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_SCTP &&
1881 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_END &&
1882 : : item->type != RTE_FLOW_ITEM_TYPE_RAW) {
1883 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1884 : 0 : rte_flow_error_set(error, EINVAL,
1885 : : RTE_FLOW_ERROR_TYPE_ITEM,
1886 : : item, "Not supported by fdir filter");
1887 : 0 : return -rte_errno;
1888 : : }
1889 : : }
1890 : :
1891 : : /* Get the TCP info. */
1892 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_TCP) {
1893 : : /**
1894 : : * Set the flow type even if there's no content
1895 : : * as we must have a flow type.
1896 : : */
1897 : 0 : rule->input.flow_type |= TXGBE_ATR_L4TYPE_TCP;
1898 : 0 : rule->mask.pkt_type_mask &= ~TXGBE_ATR_TYPE_MASK_L4P;
1899 : :
1900 : : /*Not supported last point for range*/
1901 [ # # ]: 0 : if (item->last) {
1902 : 0 : rte_flow_error_set(error, EINVAL,
1903 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1904 : : item, "Not supported last point for range");
1905 : 0 : return -rte_errno;
1906 : : }
1907 : : /**
1908 : : * Only care about src & dst ports,
1909 : : * others should be masked.
1910 : : */
1911 [ # # ]: 0 : if (!item->mask) {
1912 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1913 : 0 : rte_flow_error_set(error, EINVAL,
1914 : : RTE_FLOW_ERROR_TYPE_ITEM,
1915 : : item, "Not supported by fdir filter");
1916 : 0 : return -rte_errno;
1917 : : }
1918 : 0 : rule->b_mask = TRUE;
1919 : : tcp_mask = item->mask;
1920 [ # # ]: 0 : if (tcp_mask->hdr.sent_seq ||
1921 [ # # ]: 0 : tcp_mask->hdr.recv_ack ||
1922 [ # # ]: 0 : tcp_mask->hdr.data_off ||
1923 [ # # ]: 0 : tcp_mask->hdr.tcp_flags ||
1924 [ # # ]: 0 : tcp_mask->hdr.rx_win ||
1925 [ # # ]: 0 : tcp_mask->hdr.cksum ||
1926 [ # # ]: 0 : tcp_mask->hdr.tcp_urp) {
1927 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1928 : 0 : rte_flow_error_set(error, EINVAL,
1929 : : RTE_FLOW_ERROR_TYPE_ITEM,
1930 : : item, "Not supported by fdir filter");
1931 : 0 : return -rte_errno;
1932 : : }
1933 : 0 : rule->mask.src_port_mask = tcp_mask->hdr.src_port;
1934 : 0 : rule->mask.dst_port_mask = tcp_mask->hdr.dst_port;
1935 : :
1936 [ # # ]: 0 : if (item->spec) {
1937 : 0 : rule->b_spec = TRUE;
1938 : : tcp_spec = item->spec;
1939 : 0 : rule->input.src_port =
1940 : 0 : tcp_spec->hdr.src_port;
1941 : 0 : rule->input.dst_port =
1942 : 0 : tcp_spec->hdr.dst_port;
1943 : : }
1944 : :
1945 : : item = next_no_fuzzy_pattern(pattern, item);
1946 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_RAW &&
1947 : : item->type != RTE_FLOW_ITEM_TYPE_END) {
1948 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1949 : 0 : rte_flow_error_set(error, EINVAL,
1950 : : RTE_FLOW_ERROR_TYPE_ITEM,
1951 : : item, "Not supported by fdir filter");
1952 : 0 : return -rte_errno;
1953 : : }
1954 : : }
1955 : :
1956 : : /* Get the UDP info */
1957 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_UDP) {
1958 : : /**
1959 : : * Set the flow type even if there's no content
1960 : : * as we must have a flow type.
1961 : : */
1962 : 0 : rule->input.flow_type |= TXGBE_ATR_L4TYPE_UDP;
1963 : 0 : rule->mask.pkt_type_mask &= ~TXGBE_ATR_TYPE_MASK_L4P;
1964 : :
1965 : : /*Not supported last point for range*/
1966 [ # # ]: 0 : if (item->last) {
1967 : 0 : rte_flow_error_set(error, EINVAL,
1968 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1969 : : item, "Not supported last point for range");
1970 : 0 : return -rte_errno;
1971 : : }
1972 : : /**
1973 : : * Only care about src & dst ports,
1974 : : * others should be masked.
1975 : : */
1976 [ # # ]: 0 : if (!item->mask) {
1977 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1978 : 0 : rte_flow_error_set(error, EINVAL,
1979 : : RTE_FLOW_ERROR_TYPE_ITEM,
1980 : : item, "Not supported by fdir filter");
1981 : 0 : return -rte_errno;
1982 : : }
1983 : 0 : rule->b_mask = TRUE;
1984 : : udp_mask = item->mask;
1985 [ # # ]: 0 : if (udp_mask->hdr.dgram_len ||
1986 [ # # ]: 0 : udp_mask->hdr.dgram_cksum) {
1987 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
1988 : 0 : rte_flow_error_set(error, EINVAL,
1989 : : RTE_FLOW_ERROR_TYPE_ITEM,
1990 : : item, "Not supported by fdir filter");
1991 : 0 : return -rte_errno;
1992 : : }
1993 : 0 : rule->mask.src_port_mask = udp_mask->hdr.src_port;
1994 : 0 : rule->mask.dst_port_mask = udp_mask->hdr.dst_port;
1995 : :
1996 [ # # ]: 0 : if (item->spec) {
1997 : 0 : rule->b_spec = TRUE;
1998 : : udp_spec = item->spec;
1999 : 0 : rule->input.src_port =
2000 : 0 : udp_spec->hdr.src_port;
2001 : 0 : rule->input.dst_port =
2002 : 0 : udp_spec->hdr.dst_port;
2003 : : }
2004 : :
2005 : : item = next_no_fuzzy_pattern(pattern, item);
2006 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_RAW &&
2007 : : item->type != RTE_FLOW_ITEM_TYPE_END) {
2008 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2009 : 0 : rte_flow_error_set(error, EINVAL,
2010 : : RTE_FLOW_ERROR_TYPE_ITEM,
2011 : : item, "Not supported by fdir filter");
2012 : 0 : return -rte_errno;
2013 : : }
2014 : : }
2015 : :
2016 : : /* Get the SCTP info */
2017 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_SCTP) {
2018 : : /**
2019 : : * Set the flow type even if there's no content
2020 : : * as we must have a flow type.
2021 : : */
2022 : 0 : rule->input.flow_type |= TXGBE_ATR_L4TYPE_SCTP;
2023 : 0 : rule->mask.pkt_type_mask &= ~TXGBE_ATR_TYPE_MASK_L4P;
2024 : :
2025 : : /*Not supported last point for range*/
2026 [ # # ]: 0 : if (item->last) {
2027 : 0 : rte_flow_error_set(error, EINVAL,
2028 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2029 : : item, "Not supported last point for range");
2030 : 0 : return -rte_errno;
2031 : : }
2032 : :
2033 : : /**
2034 : : * Only care about src & dst ports,
2035 : : * others should be masked.
2036 : : */
2037 [ # # ]: 0 : if (!item->mask) {
2038 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2039 : 0 : rte_flow_error_set(error, EINVAL,
2040 : : RTE_FLOW_ERROR_TYPE_ITEM,
2041 : : item, "Not supported by fdir filter");
2042 : 0 : return -rte_errno;
2043 : : }
2044 : 0 : rule->b_mask = TRUE;
2045 : : sctp_mask = item->mask;
2046 [ # # ]: 0 : if (sctp_mask->hdr.tag ||
2047 [ # # ]: 0 : sctp_mask->hdr.cksum) {
2048 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2049 : 0 : rte_flow_error_set(error, EINVAL,
2050 : : RTE_FLOW_ERROR_TYPE_ITEM,
2051 : : item, "Not supported by fdir filter");
2052 : 0 : return -rte_errno;
2053 : : }
2054 : 0 : rule->mask.src_port_mask = sctp_mask->hdr.src_port;
2055 : 0 : rule->mask.dst_port_mask = sctp_mask->hdr.dst_port;
2056 : :
2057 [ # # ]: 0 : if (item->spec) {
2058 : 0 : rule->b_spec = TRUE;
2059 : : sctp_spec = item->spec;
2060 : 0 : rule->input.src_port =
2061 : 0 : sctp_spec->hdr.src_port;
2062 : 0 : rule->input.dst_port =
2063 : 0 : sctp_spec->hdr.dst_port;
2064 : : }
2065 : :
2066 : : item = next_no_fuzzy_pattern(pattern, item);
2067 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_RAW &&
2068 : : item->type != RTE_FLOW_ITEM_TYPE_END) {
2069 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2070 : 0 : rte_flow_error_set(error, EINVAL,
2071 : : RTE_FLOW_ERROR_TYPE_ITEM,
2072 : : item, "Not supported by fdir filter");
2073 : 0 : return -rte_errno;
2074 : : }
2075 : : }
2076 : :
2077 : : /* Get the flex byte info */
2078 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_RAW) {
2079 : 0 : uint16_t pattern = 0;
2080 : :
2081 : : /* Not supported last point for range*/
2082 [ # # ]: 0 : if (item->last) {
2083 : 0 : rte_flow_error_set(error, EINVAL,
2084 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2085 : : item, "Not supported last point for range");
2086 : 0 : return -rte_errno;
2087 : : }
2088 : : /* mask should not be null */
2089 [ # # # # ]: 0 : if (!item->mask || !item->spec) {
2090 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2091 : 0 : rte_flow_error_set(error, EINVAL,
2092 : : RTE_FLOW_ERROR_TYPE_ITEM,
2093 : : item, "Not supported by fdir filter");
2094 : 0 : return -rte_errno;
2095 : : }
2096 : :
2097 : 0 : rule->b_mask = TRUE;
2098 : : raw_mask = item->mask;
2099 : :
2100 : : /* check mask */
2101 : 0 : if (raw_mask->relative != 0x1 ||
2102 : : raw_mask->search != 0x1 ||
2103 [ # # ]: 0 : raw_mask->reserved != 0x0 ||
2104 : : (uint32_t)raw_mask->offset != 0xffffffff ||
2105 [ # # ]: 0 : raw_mask->limit != 0xffff ||
2106 : : raw_mask->length != 0xffff) {
2107 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2108 : 0 : rte_flow_error_set(error, EINVAL,
2109 : : RTE_FLOW_ERROR_TYPE_ITEM,
2110 : : item, "Not supported by fdir filter");
2111 : 0 : return -rte_errno;
2112 : : }
2113 : :
2114 : 0 : rule->b_spec = TRUE;
2115 : : raw_spec = item->spec;
2116 : :
2117 : : /* check spec */
2118 [ # # ]: 0 : if (raw_spec->search != 0 ||
2119 : 0 : raw_spec->reserved != 0 ||
2120 [ # # # # ]: 0 : raw_spec->offset > TXGBE_MAX_FLX_SOURCE_OFF ||
2121 : : raw_spec->offset % 2 ||
2122 [ # # ]: 0 : raw_spec->limit != 0 ||
2123 : 0 : raw_spec->length != 4 ||
2124 : : /* pattern can't be 0xffff */
2125 [ # # ]: 0 : (raw_spec->pattern[0] == 0xff &&
2126 [ # # ]: 0 : raw_spec->pattern[1] == 0xff &&
2127 [ # # ]: 0 : raw_spec->pattern[2] == 0xff &&
2128 [ # # ]: 0 : raw_spec->pattern[3] == 0xff)) {
2129 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2130 : 0 : rte_flow_error_set(error, EINVAL,
2131 : : RTE_FLOW_ERROR_TYPE_ITEM,
2132 : : item, "Not supported by fdir filter");
2133 : 0 : return -rte_errno;
2134 : : }
2135 : :
2136 : : /* check pattern mask */
2137 [ # # ]: 0 : if (raw_mask->pattern[0] != 0xff ||
2138 [ # # ]: 0 : raw_mask->pattern[1] != 0xff ||
2139 [ # # ]: 0 : raw_mask->pattern[2] != 0xff ||
2140 [ # # ]: 0 : raw_mask->pattern[3] != 0xff) {
2141 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2142 : 0 : rte_flow_error_set(error, EINVAL,
2143 : : RTE_FLOW_ERROR_TYPE_ITEM,
2144 : : item, "Not supported by fdir filter");
2145 : 0 : return -rte_errno;
2146 : : }
2147 : :
2148 : 0 : rule->mask.flex_bytes_mask = 0xffff;
2149 : : /* Convert pattern string to hex bytes */
2150 [ # # ]: 0 : if (sscanf((const char *)raw_spec->pattern, "%hx", &pattern) != 1) {
2151 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2152 : 0 : rte_flow_error_set(error, EINVAL,
2153 : : RTE_FLOW_ERROR_TYPE_ITEM,
2154 : : item, "Failed to parse raw pattern");
2155 : 0 : return -rte_errno;
2156 : : }
2157 : 0 : rule->input.flex_bytes = (pattern & 0x00FF) << 8;
2158 : 0 : rule->input.flex_bytes |= (pattern & 0xFF00) >> 8;
2159 : :
2160 : 0 : rule->flex_bytes_offset = raw_spec->offset;
2161 : 0 : rule->flex_relative = raw_spec->relative;
2162 : : }
2163 : :
2164 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END) {
2165 : : /* check if the next not void item is END */
2166 : : item = next_no_fuzzy_pattern(pattern, item);
2167 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END) {
2168 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2169 : 0 : rte_flow_error_set(error, EINVAL,
2170 : : RTE_FLOW_ERROR_TYPE_ITEM,
2171 : : item, "Not supported by fdir filter");
2172 : 0 : return -rte_errno;
2173 : : }
2174 : : }
2175 : :
2176 : 0 : txgbe_fdir_parse_flow_type(&rule->input, 0, false);
2177 : :
2178 : 0 : return txgbe_parse_fdir_act_attr(attr, actions, rule, error);
2179 : : }
2180 : :
2181 : : /**
2182 : : * Parse the rule to see if it is a IP tunnel flow director rule.
2183 : : * And get the flow director filter info BTW.
2184 : : * PATTERN:
2185 : : * The first not void item can be ETH or IPV4 or IPV6 or UDP or tunnel type.
2186 : : * The second not void item must be IPV4 or IPV6 if the first one is ETH.
2187 : : * The next not void item could be UDP or tunnel type.
2188 : : * The next not void item could be a certain inner layer.
2189 : : * The next not void item must be END.
2190 : : * ACTION:
2191 : : * The first not void action should be QUEUE.
2192 : : * The next not void action should be END.
2193 : : * pattern example:
2194 : : * ITEM Spec Mask
2195 : : * ETH NULL NULL
2196 : : * IPV4 NULL NULL
2197 : : * UDP NULL NULL
2198 : : * VXLAN NULL NULL
2199 : : * ETH NULL NULL
2200 : : * IPV4 src_addr 192.168.1.20 0xFFFFFFFF
2201 : : * dst_addr 192.167.3.50 0xFFFFFFFF
2202 : : * UDP/TCP/SCTP src_port 80 0xFFFF
2203 : : * dst_port 80 0xFFFF
2204 : : * END
2205 : : */
2206 : : static int
2207 : 0 : txgbe_parse_fdir_filter_tunnel(const struct rte_flow_attr *attr,
2208 : : const struct rte_flow_item pattern[],
2209 : : const struct rte_flow_action actions[],
2210 : : struct txgbe_fdir_rule *rule,
2211 : : struct rte_flow_error *error)
2212 : : {
2213 : : const struct rte_flow_item *item;
2214 : : const struct rte_flow_item_eth *eth_mask;
2215 : : const struct rte_flow_item_ipv4 *ipv4_spec;
2216 : : const struct rte_flow_item_ipv4 *ipv4_mask;
2217 : : const struct rte_flow_item_ipv6 *ipv6_spec;
2218 : : const struct rte_flow_item_ipv6 *ipv6_mask;
2219 : : const struct rte_flow_item_tcp *tcp_spec;
2220 : : const struct rte_flow_item_tcp *tcp_mask;
2221 : : const struct rte_flow_item_udp *udp_spec;
2222 : : const struct rte_flow_item_udp *udp_mask;
2223 : : const struct rte_flow_item_sctp *sctp_spec;
2224 : : const struct rte_flow_item_sctp *sctp_mask;
2225 : : u8 ptid = 0;
2226 : : uint32_t j;
2227 : :
2228 [ # # ]: 0 : if (!pattern) {
2229 : 0 : rte_flow_error_set(error, EINVAL,
2230 : : RTE_FLOW_ERROR_TYPE_ITEM_NUM,
2231 : : NULL, "NULL pattern.");
2232 : 0 : return -rte_errno;
2233 : : }
2234 : :
2235 [ # # ]: 0 : if (!actions) {
2236 : 0 : rte_flow_error_set(error, EINVAL,
2237 : : RTE_FLOW_ERROR_TYPE_ACTION_NUM,
2238 : : NULL, "NULL action.");
2239 : 0 : return -rte_errno;
2240 : : }
2241 : :
2242 [ # # ]: 0 : if (!attr) {
2243 : 0 : rte_flow_error_set(error, EINVAL,
2244 : : RTE_FLOW_ERROR_TYPE_ATTR,
2245 : : NULL, "NULL attribute.");
2246 : 0 : return -rte_errno;
2247 : : }
2248 : :
2249 : : /**
2250 : : * Some fields may not be provided. Set spec to 0 and mask to default
2251 : : * value. So, we need not do anything for the not provided fields later.
2252 : : */
2253 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2254 : : memset(&rule->mask, 0, sizeof(struct txgbe_hw_fdir_mask));
2255 : 0 : rule->mask.pkt_type_mask = TXGBE_ATR_TYPE_MASK_TUN_OUTIP |
2256 : : TXGBE_ATR_TYPE_MASK_L3P |
2257 : : TXGBE_ATR_TYPE_MASK_L4P;
2258 : :
2259 : : /**
2260 : : * The first not void item should be
2261 : : * MAC or IPv4 or IPv6 or UDP or tunnel.
2262 : : */
2263 : : item = next_no_void_pattern(pattern, NULL);
2264 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_ETH &&
2265 : : item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
2266 : : item->type != RTE_FLOW_ITEM_TYPE_IPV6 &&
2267 : : item->type != RTE_FLOW_ITEM_TYPE_UDP &&
2268 : : item->type != RTE_FLOW_ITEM_TYPE_VXLAN &&
2269 : : item->type != RTE_FLOW_ITEM_TYPE_NVGRE &&
2270 : : item->type != RTE_FLOW_ITEM_TYPE_GRE &&
2271 : : item->type != RTE_FLOW_ITEM_TYPE_GENEVE) {
2272 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2273 : 0 : rte_flow_error_set(error, EINVAL,
2274 : : RTE_FLOW_ERROR_TYPE_ITEM,
2275 : : item, "Not supported by fdir filter");
2276 : 0 : return -rte_errno;
2277 : : }
2278 : :
2279 : 0 : rule->mode = RTE_FDIR_MODE_PERFECT;
2280 : : ptid = TXGBE_PTID_PKT_TUN;
2281 : :
2282 : : /* Skip MAC. */
2283 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_ETH) {
2284 : : /* Only used to describe the protocol stack. */
2285 [ # # # # ]: 0 : if (item->spec || item->mask) {
2286 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2287 : 0 : rte_flow_error_set(error, EINVAL,
2288 : : RTE_FLOW_ERROR_TYPE_ITEM,
2289 : : item, "Not supported by fdir filter");
2290 : 0 : return -rte_errno;
2291 : : }
2292 : : /* Not supported last point for range*/
2293 [ # # ]: 0 : if (item->last) {
2294 : 0 : rte_flow_error_set(error, EINVAL,
2295 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2296 : : item, "Not supported last point for range");
2297 : 0 : return -rte_errno;
2298 : : }
2299 : :
2300 : : /* Check if the next not void item is IPv4 or IPv6. */
2301 : : item = next_no_void_pattern(pattern, item);
2302 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_VLAN)
2303 : : item = next_no_fuzzy_pattern(pattern, item);
2304 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
2305 : : item->type != RTE_FLOW_ITEM_TYPE_IPV6) {
2306 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2307 : 0 : rte_flow_error_set(error, EINVAL,
2308 : : RTE_FLOW_ERROR_TYPE_ITEM,
2309 : : item, "Not supported by fdir filter");
2310 : 0 : return -rte_errno;
2311 : : }
2312 : : }
2313 : :
2314 : : /* Skip IP. */
2315 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
2316 : : item->type == RTE_FLOW_ITEM_TYPE_IPV6) {
2317 : 0 : rule->mask.pkt_type_mask &= ~TXGBE_ATR_TYPE_MASK_TUN_OUTIP;
2318 : :
2319 : : /* Only used to describe the protocol stack. */
2320 [ # # # # ]: 0 : if (item->spec || item->mask) {
2321 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2322 : 0 : rte_flow_error_set(error, EINVAL,
2323 : : RTE_FLOW_ERROR_TYPE_ITEM,
2324 : : item, "Not supported by fdir filter");
2325 : 0 : return -rte_errno;
2326 : : }
2327 : : /*Not supported last point for range*/
2328 [ # # ]: 0 : if (item->last) {
2329 : 0 : rte_flow_error_set(error, EINVAL,
2330 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2331 : : item, "Not supported last point for range");
2332 : 0 : return -rte_errno;
2333 : : }
2334 : :
2335 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_IPV6)
2336 : : ptid |= TXGBE_PTID_TUN_IPV6;
2337 : :
2338 : : item = next_no_void_pattern(pattern, item);
2339 : 0 : if (item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
2340 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_IPV6 &&
2341 : : item->type != RTE_FLOW_ITEM_TYPE_UDP &&
2342 : : item->type != RTE_FLOW_ITEM_TYPE_VXLAN &&
2343 : : item->type != RTE_FLOW_ITEM_TYPE_GRE &&
2344 : : item->type != RTE_FLOW_ITEM_TYPE_NVGRE &&
2345 : : item->type != RTE_FLOW_ITEM_TYPE_GENEVE) {
2346 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2347 : 0 : rte_flow_error_set(error, EINVAL,
2348 : : RTE_FLOW_ERROR_TYPE_ITEM,
2349 : : item, "Not supported by fdir filter");
2350 : 0 : return -rte_errno;
2351 : : }
2352 : : }
2353 : :
2354 : : /* Skip UDP. */
2355 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_UDP) {
2356 : : /*Not supported last point for range*/
2357 [ # # ]: 0 : if (item->last) {
2358 : 0 : rte_flow_error_set(error, EINVAL,
2359 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2360 : : item, "Not supported last point for range");
2361 : 0 : return -rte_errno;
2362 : : }
2363 : :
2364 : : /* Check if the next not void item is VxLAN or GENEVE. */
2365 : : item = next_no_void_pattern(pattern, item);
2366 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_VXLAN &&
2367 : : item->type != RTE_FLOW_ITEM_TYPE_GENEVE) {
2368 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2369 : 0 : rte_flow_error_set(error, EINVAL,
2370 : : RTE_FLOW_ERROR_TYPE_ITEM,
2371 : : item, "Not supported by fdir filter");
2372 : 0 : return -rte_errno;
2373 : : }
2374 : : }
2375 : :
2376 : : /* Skip tunnel. */
2377 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_VXLAN ||
2378 [ # # ]: 0 : item->type == RTE_FLOW_ITEM_TYPE_GRE ||
2379 [ # # ]: 0 : item->type == RTE_FLOW_ITEM_TYPE_NVGRE ||
2380 : : item->type == RTE_FLOW_ITEM_TYPE_GENEVE) {
2381 : : /* Only used to describe the protocol stack. */
2382 [ # # # # ]: 0 : if (item->spec || item->mask) {
2383 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2384 : 0 : rte_flow_error_set(error, EINVAL,
2385 : : RTE_FLOW_ERROR_TYPE_ITEM,
2386 : : item, "Not supported by fdir filter");
2387 : 0 : return -rte_errno;
2388 : : }
2389 : : /*Not supported last point for range*/
2390 [ # # ]: 0 : if (item->last) {
2391 : 0 : rte_flow_error_set(error, EINVAL,
2392 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2393 : : item, "Not supported last point for range");
2394 : 0 : return -rte_errno;
2395 : : }
2396 : :
2397 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_GRE)
2398 : 0 : ptid |= TXGBE_PTID_TUN_EIG;
2399 : : else
2400 : 0 : ptid |= TXGBE_PTID_TUN_EIGM;
2401 : :
2402 : : item = next_no_void_pattern(pattern, item);
2403 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_ETH &&
2404 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
2405 : : item->type != RTE_FLOW_ITEM_TYPE_IPV6) {
2406 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2407 : 0 : rte_flow_error_set(error, EINVAL,
2408 : : RTE_FLOW_ERROR_TYPE_ITEM,
2409 : : item, "Not supported by fdir filter");
2410 : 0 : return -rte_errno;
2411 : : }
2412 : : }
2413 : :
2414 : : /* Get the MAC info. */
2415 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_ETH) {
2416 : : /**
2417 : : * Only support vlan and dst MAC address,
2418 : : * others should be masked.
2419 : : */
2420 [ # # # # ]: 0 : if (item->spec && !item->mask) {
2421 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2422 : 0 : rte_flow_error_set(error, EINVAL,
2423 : : RTE_FLOW_ERROR_TYPE_ITEM,
2424 : : item, "Not supported by fdir filter");
2425 : 0 : return -rte_errno;
2426 : : }
2427 : :
2428 [ # # ]: 0 : if (item->mask) {
2429 : 0 : rule->b_mask = TRUE;
2430 : : eth_mask = item->mask;
2431 : :
2432 : : /* Ether type should be masked. */
2433 [ # # ]: 0 : if (eth_mask->hdr.ether_type) {
2434 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2435 : 0 : rte_flow_error_set(error, EINVAL,
2436 : : RTE_FLOW_ERROR_TYPE_ITEM,
2437 : : item, "Not supported by fdir filter");
2438 : 0 : return -rte_errno;
2439 : : }
2440 : :
2441 : : /**
2442 : : * src MAC address must be masked,
2443 : : * and don't support dst MAC address mask.
2444 : : */
2445 [ # # ]: 0 : for (j = 0; j < RTE_ETHER_ADDR_LEN; j++) {
2446 [ # # ]: 0 : if (eth_mask->hdr.src_addr.addr_bytes[j] ||
2447 [ # # ]: 0 : eth_mask->hdr.dst_addr.addr_bytes[j] != 0xFF) {
2448 : : memset(rule, 0,
2449 : : sizeof(struct txgbe_fdir_rule));
2450 : 0 : rte_flow_error_set(error, EINVAL,
2451 : : RTE_FLOW_ERROR_TYPE_ITEM,
2452 : : item, "Not supported by fdir filter");
2453 : 0 : return -rte_errno;
2454 : : }
2455 : : }
2456 : :
2457 : : /* When no VLAN, considered as full mask. */
2458 : 0 : rule->mask.vlan_tci_mask = rte_cpu_to_be_16(0xEFFF);
2459 : : }
2460 : :
2461 : : item = next_no_fuzzy_pattern(pattern, item);
2462 [ # # ]: 0 : if (rule->mask.vlan_tci_mask) {
2463 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_VLAN) {
2464 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2465 : 0 : rte_flow_error_set(error, EINVAL,
2466 : : RTE_FLOW_ERROR_TYPE_ITEM,
2467 : : item, "Not supported by fdir filter");
2468 : 0 : return -rte_errno;
2469 : : }
2470 : : } else {
2471 : 0 : if (item->type != RTE_FLOW_ITEM_TYPE_IPV4 &&
2472 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_IPV6 &&
2473 : : item->type != RTE_FLOW_ITEM_TYPE_VLAN) {
2474 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2475 : 0 : rte_flow_error_set(error, EINVAL,
2476 : : RTE_FLOW_ERROR_TYPE_ITEM,
2477 : : item, "Not supported by fdir filter");
2478 : 0 : return -rte_errno;
2479 : : }
2480 : : }
2481 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_VLAN) {
2482 : 0 : ptid |= TXGBE_PTID_TUN_EIGMV;
2483 : : item = next_no_fuzzy_pattern(pattern, item);
2484 : : }
2485 : : }
2486 : :
2487 : : /* Get the IPV4 info. */
2488 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_IPV4) {
2489 : : /**
2490 : : * Set the flow type even if there's no content
2491 : : * as we must have a flow type.
2492 : : */
2493 : : rule->input.flow_type = TXGBE_ATR_FLOW_TYPE_IPV4;
2494 : 0 : rule->mask.pkt_type_mask &= ~TXGBE_ATR_TYPE_MASK_L3P;
2495 : :
2496 : : /*Not supported last point for range*/
2497 [ # # ]: 0 : if (item->last) {
2498 : 0 : rte_flow_error_set(error, EINVAL,
2499 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2500 : : item, "Not supported last point for range");
2501 : 0 : return -rte_errno;
2502 : : }
2503 : : /**
2504 : : * Only care about src & dst addresses,
2505 : : * others should be masked.
2506 : : */
2507 [ # # # # ]: 0 : if (item->spec && !item->mask) {
2508 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2509 : 0 : rte_flow_error_set(error, EINVAL,
2510 : : RTE_FLOW_ERROR_TYPE_ITEM,
2511 : : item, "Not supported by fdir filter");
2512 : 0 : return -rte_errno;
2513 : : }
2514 [ # # ]: 0 : if (item->mask) {
2515 : 0 : rule->b_mask = TRUE;
2516 : : ipv4_mask = item->mask;
2517 [ # # ]: 0 : if (ipv4_mask->hdr.version_ihl ||
2518 : 0 : ipv4_mask->hdr.type_of_service ||
2519 [ # # ]: 0 : ipv4_mask->hdr.total_length ||
2520 [ # # ]: 0 : ipv4_mask->hdr.packet_id ||
2521 [ # # ]: 0 : ipv4_mask->hdr.fragment_offset ||
2522 [ # # ]: 0 : ipv4_mask->hdr.time_to_live ||
2523 : 0 : ipv4_mask->hdr.next_proto_id ||
2524 [ # # ]: 0 : ipv4_mask->hdr.hdr_checksum) {
2525 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2526 : 0 : rte_flow_error_set(error, EINVAL,
2527 : : RTE_FLOW_ERROR_TYPE_ITEM,
2528 : : item, "Not supported by fdir filter");
2529 : 0 : return -rte_errno;
2530 : : }
2531 : 0 : rule->mask.dst_ipv4_mask = ipv4_mask->hdr.dst_addr;
2532 : 0 : rule->mask.src_ipv4_mask = ipv4_mask->hdr.src_addr;
2533 : : }
2534 [ # # ]: 0 : if (item->spec) {
2535 : 0 : rule->b_spec = TRUE;
2536 : : ipv4_spec = item->spec;
2537 : 0 : rule->input.dst_ip[0] =
2538 : 0 : ipv4_spec->hdr.dst_addr;
2539 : 0 : rule->input.src_ip[0] =
2540 : 0 : ipv4_spec->hdr.src_addr;
2541 : : }
2542 : :
2543 : : /**
2544 : : * Check if the next not void item is
2545 : : * TCP or UDP or SCTP or END.
2546 : : */
2547 : : item = next_no_fuzzy_pattern(pattern, item);
2548 : 0 : if (item->type != RTE_FLOW_ITEM_TYPE_TCP &&
2549 : : item->type != RTE_FLOW_ITEM_TYPE_UDP &&
2550 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_SCTP &&
2551 : : item->type != RTE_FLOW_ITEM_TYPE_END) {
2552 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2553 : 0 : rte_flow_error_set(error, EINVAL,
2554 : : RTE_FLOW_ERROR_TYPE_ITEM,
2555 : : item, "Not supported by fdir filter");
2556 : 0 : return -rte_errno;
2557 : : }
2558 : : }
2559 : :
2560 : : /* Get the IPV6 info. */
2561 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_IPV6) {
2562 : : /**
2563 : : * Set the flow type even if there's no content
2564 : : * as we must have a flow type.
2565 : : */
2566 : 0 : rule->input.flow_type = TXGBE_ATR_FLOW_TYPE_IPV6;
2567 : 0 : rule->mask.pkt_type_mask &= ~TXGBE_ATR_TYPE_MASK_L3P;
2568 : :
2569 [ # # ]: 0 : if (item->last) {
2570 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2571 : 0 : rte_flow_error_set(error, EINVAL,
2572 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2573 : : item, "Not supported last point for range");
2574 : 0 : return -rte_errno;
2575 : : }
2576 [ # # # # ]: 0 : if (item->spec && !item->mask) {
2577 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2578 : 0 : rte_flow_error_set(error, EINVAL,
2579 : : RTE_FLOW_ERROR_TYPE_ITEM,
2580 : : item, "Not supported by fdir filter");
2581 : 0 : return -rte_errno;
2582 : : }
2583 [ # # ]: 0 : if (item->mask) {
2584 : 0 : rule->b_mask = TRUE;
2585 : : ipv6_mask = item->mask;
2586 [ # # ]: 0 : if (ipv6_mask->hdr.vtc_flow ||
2587 : : ipv6_mask->hdr.payload_len ||
2588 [ # # ]: 0 : ipv6_mask->hdr.proto ||
2589 : : ipv6_mask->hdr.hop_limits) {
2590 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2591 : 0 : rte_flow_error_set(error, EINVAL,
2592 : : RTE_FLOW_ERROR_TYPE_ITEM,
2593 : : item, "Not supported by fdir filter");
2594 : 0 : return -rte_errno;
2595 : : }
2596 : :
2597 : : /* check src addr mask */
2598 [ # # ]: 0 : for (j = 0; j < 16; j++) {
2599 [ # # ]: 0 : if (ipv6_mask->hdr.src_addr.a[j] == UINT8_MAX) {
2600 : 0 : rule->mask.src_ipv6_mask |= 1 << j;
2601 [ # # ]: 0 : } else if (ipv6_mask->hdr.src_addr.a[j] != 0) {
2602 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2603 : 0 : rte_flow_error_set(error, EINVAL,
2604 : : RTE_FLOW_ERROR_TYPE_ITEM,
2605 : : item, "Not supported by fdir filter");
2606 : 0 : return -rte_errno;
2607 : : }
2608 : : }
2609 : :
2610 : : /* check dst addr mask */
2611 [ # # ]: 0 : for (j = 0; j < 16; j++) {
2612 [ # # ]: 0 : if (ipv6_mask->hdr.dst_addr.a[j] == UINT8_MAX) {
2613 : 0 : rule->mask.dst_ipv6_mask |= 1 << j;
2614 [ # # ]: 0 : } else if (ipv6_mask->hdr.dst_addr.a[j] != 0) {
2615 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2616 : 0 : rte_flow_error_set(error, EINVAL,
2617 : : RTE_FLOW_ERROR_TYPE_ITEM,
2618 : : item, "Not supported by fdir filter");
2619 : 0 : return -rte_errno;
2620 : : }
2621 : : }
2622 : : }
2623 [ # # ]: 0 : if (item->spec) {
2624 : 0 : rule->b_spec = TRUE;
2625 : : ipv6_spec = item->spec;
2626 : 0 : rte_memcpy(rule->input.src_ip,
2627 [ # # ]: 0 : &ipv6_spec->hdr.src_addr, 16);
2628 : 0 : rte_memcpy(rule->input.dst_ip,
2629 [ # # ]: 0 : &ipv6_spec->hdr.dst_addr, 16);
2630 : : }
2631 : :
2632 : : /**
2633 : : * Check if the next not void item is
2634 : : * TCP or UDP or SCTP or END.
2635 : : */
2636 : : item = next_no_fuzzy_pattern(pattern, item);
2637 : 0 : if (item->type != RTE_FLOW_ITEM_TYPE_TCP &&
2638 : : item->type != RTE_FLOW_ITEM_TYPE_UDP &&
2639 [ # # ]: 0 : item->type != RTE_FLOW_ITEM_TYPE_SCTP &&
2640 : : item->type != RTE_FLOW_ITEM_TYPE_END) {
2641 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2642 : 0 : rte_flow_error_set(error, EINVAL,
2643 : : RTE_FLOW_ERROR_TYPE_ITEM,
2644 : : item, "Not supported by fdir filter");
2645 : 0 : return -rte_errno;
2646 : : }
2647 : : }
2648 : :
2649 : : /* Get the TCP info. */
2650 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_TCP) {
2651 : : /**
2652 : : * Set the flow type even if there's no content
2653 : : * as we must have a flow type.
2654 : : */
2655 : 0 : rule->input.flow_type |= TXGBE_ATR_L4TYPE_TCP;
2656 : 0 : rule->mask.pkt_type_mask &= ~TXGBE_ATR_TYPE_MASK_L4P;
2657 : :
2658 : : /*Not supported last point for range*/
2659 [ # # ]: 0 : if (item->last) {
2660 : 0 : rte_flow_error_set(error, EINVAL,
2661 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2662 : : item, "Not supported last point for range");
2663 : 0 : return -rte_errno;
2664 : : }
2665 : : /**
2666 : : * Only care about src & dst ports,
2667 : : * others should be masked.
2668 : : */
2669 [ # # ]: 0 : if (!item->mask) {
2670 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2671 : 0 : rte_flow_error_set(error, EINVAL,
2672 : : RTE_FLOW_ERROR_TYPE_ITEM,
2673 : : item, "Not supported by fdir filter");
2674 : 0 : return -rte_errno;
2675 : : }
2676 : 0 : rule->b_mask = TRUE;
2677 : : tcp_mask = item->mask;
2678 [ # # ]: 0 : if (tcp_mask->hdr.sent_seq ||
2679 [ # # ]: 0 : tcp_mask->hdr.recv_ack ||
2680 [ # # ]: 0 : tcp_mask->hdr.data_off ||
2681 [ # # ]: 0 : tcp_mask->hdr.tcp_flags ||
2682 [ # # ]: 0 : tcp_mask->hdr.rx_win ||
2683 [ # # ]: 0 : tcp_mask->hdr.cksum ||
2684 [ # # ]: 0 : tcp_mask->hdr.tcp_urp) {
2685 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2686 : 0 : rte_flow_error_set(error, EINVAL,
2687 : : RTE_FLOW_ERROR_TYPE_ITEM,
2688 : : item, "Not supported by fdir filter");
2689 : 0 : return -rte_errno;
2690 : : }
2691 : 0 : rule->mask.src_port_mask = tcp_mask->hdr.src_port;
2692 : 0 : rule->mask.dst_port_mask = tcp_mask->hdr.dst_port;
2693 : :
2694 [ # # ]: 0 : if (item->spec) {
2695 : 0 : rule->b_spec = TRUE;
2696 : : tcp_spec = item->spec;
2697 : 0 : rule->input.src_port =
2698 : 0 : tcp_spec->hdr.src_port;
2699 : 0 : rule->input.dst_port =
2700 : 0 : tcp_spec->hdr.dst_port;
2701 : : }
2702 : : }
2703 : :
2704 : : /* Get the UDP info */
2705 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_UDP) {
2706 : : /**
2707 : : * Set the flow type even if there's no content
2708 : : * as we must have a flow type.
2709 : : */
2710 : 0 : rule->input.flow_type |= TXGBE_ATR_L4TYPE_UDP;
2711 : 0 : rule->mask.pkt_type_mask &= ~TXGBE_ATR_TYPE_MASK_L4P;
2712 : : /*Not supported last point for range*/
2713 [ # # ]: 0 : if (item->last) {
2714 : 0 : rte_flow_error_set(error, EINVAL,
2715 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2716 : : item, "Not supported last point for range");
2717 : 0 : return -rte_errno;
2718 : : }
2719 : : /**
2720 : : * Only care about src & dst ports,
2721 : : * others should be masked.
2722 : : */
2723 [ # # ]: 0 : if (!item->mask) {
2724 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2725 : 0 : rte_flow_error_set(error, EINVAL,
2726 : : RTE_FLOW_ERROR_TYPE_ITEM,
2727 : : item, "Not supported by fdir filter");
2728 : 0 : return -rte_errno;
2729 : : }
2730 : 0 : rule->b_mask = TRUE;
2731 : : udp_mask = item->mask;
2732 [ # # ]: 0 : if (udp_mask->hdr.dgram_len ||
2733 [ # # ]: 0 : udp_mask->hdr.dgram_cksum) {
2734 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2735 : 0 : rte_flow_error_set(error, EINVAL,
2736 : : RTE_FLOW_ERROR_TYPE_ITEM,
2737 : : item, "Not supported by fdir filter");
2738 : 0 : return -rte_errno;
2739 : : }
2740 : 0 : rule->mask.src_port_mask = udp_mask->hdr.src_port;
2741 : 0 : rule->mask.dst_port_mask = udp_mask->hdr.dst_port;
2742 : :
2743 [ # # ]: 0 : if (item->spec) {
2744 : 0 : rule->b_spec = TRUE;
2745 : : udp_spec = item->spec;
2746 : 0 : rule->input.src_port =
2747 : 0 : udp_spec->hdr.src_port;
2748 : 0 : rule->input.dst_port =
2749 : 0 : udp_spec->hdr.dst_port;
2750 : : }
2751 : : }
2752 : :
2753 : : /* Get the SCTP info */
2754 [ # # ]: 0 : if (item->type == RTE_FLOW_ITEM_TYPE_SCTP) {
2755 : : /**
2756 : : * Set the flow type even if there's no content
2757 : : * as we must have a flow type.
2758 : : */
2759 : 0 : rule->input.flow_type |= TXGBE_ATR_L4TYPE_SCTP;
2760 : 0 : rule->mask.pkt_type_mask &= ~TXGBE_ATR_TYPE_MASK_L4P;
2761 : :
2762 : : /*Not supported last point for range*/
2763 [ # # ]: 0 : if (item->last) {
2764 : 0 : rte_flow_error_set(error, EINVAL,
2765 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2766 : : item, "Not supported last point for range");
2767 : 0 : return -rte_errno;
2768 : : }
2769 : :
2770 : : /**
2771 : : * Only care about src & dst ports,
2772 : : * others should be masked.
2773 : : */
2774 [ # # ]: 0 : if (!item->mask) {
2775 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2776 : 0 : rte_flow_error_set(error, EINVAL,
2777 : : RTE_FLOW_ERROR_TYPE_ITEM,
2778 : : item, "Not supported by fdir filter");
2779 : 0 : return -rte_errno;
2780 : : }
2781 : 0 : rule->b_mask = TRUE;
2782 : : sctp_mask = item->mask;
2783 [ # # # # ]: 0 : if (sctp_mask->hdr.tag || sctp_mask->hdr.cksum) {
2784 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2785 : 0 : rte_flow_error_set(error, EINVAL,
2786 : : RTE_FLOW_ERROR_TYPE_ITEM,
2787 : : item, "Not supported by fdir filter");
2788 : 0 : return -rte_errno;
2789 : : }
2790 : 0 : rule->mask.src_port_mask = sctp_mask->hdr.src_port;
2791 : 0 : rule->mask.dst_port_mask = sctp_mask->hdr.dst_port;
2792 : :
2793 [ # # ]: 0 : if (item->spec) {
2794 : 0 : rule->b_spec = TRUE;
2795 : : sctp_spec = item->spec;
2796 : 0 : rule->input.src_port =
2797 : 0 : sctp_spec->hdr.src_port;
2798 : 0 : rule->input.dst_port =
2799 : 0 : sctp_spec->hdr.dst_port;
2800 : : }
2801 : : /* others even sctp port is not supported */
2802 : : sctp_mask = item->mask;
2803 [ # # ]: 0 : if (sctp_mask &&
2804 [ # # ]: 0 : (sctp_mask->hdr.src_port ||
2805 : : sctp_mask->hdr.dst_port ||
2806 : : sctp_mask->hdr.tag ||
2807 : : sctp_mask->hdr.cksum)) {
2808 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2809 : 0 : rte_flow_error_set(error, EINVAL,
2810 : : RTE_FLOW_ERROR_TYPE_ITEM,
2811 : : item, "Not supported by fdir filter");
2812 : 0 : return -rte_errno;
2813 : : }
2814 : : }
2815 : :
2816 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END) {
2817 : : /* check if the next not void item is END */
2818 : : item = next_no_fuzzy_pattern(pattern, item);
2819 [ # # ]: 0 : if (item->type != RTE_FLOW_ITEM_TYPE_END) {
2820 : : memset(rule, 0, sizeof(struct txgbe_fdir_rule));
2821 : 0 : rte_flow_error_set(error, EINVAL,
2822 : : RTE_FLOW_ERROR_TYPE_ITEM,
2823 : : item, "Not supported by fdir filter");
2824 : 0 : return -rte_errno;
2825 : : }
2826 : : }
2827 : :
2828 : 0 : txgbe_fdir_parse_flow_type(&rule->input, ptid, true);
2829 : :
2830 : 0 : return txgbe_parse_fdir_act_attr(attr, actions, rule, error);
2831 : : }
2832 : :
2833 : : static int
2834 : 0 : txgbe_parse_fdir_filter(struct rte_eth_dev *dev,
2835 : : const struct rte_flow_attr *attr,
2836 : : const struct rte_flow_item pattern[],
2837 : : const struct rte_flow_action actions[],
2838 : : struct txgbe_fdir_rule *rule,
2839 : : struct rte_flow_error *error)
2840 : : {
2841 : : int ret;
2842 : 0 : struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
2843 : : struct rte_eth_fdir_conf *fdir_conf = TXGBE_DEV_FDIR_CONF(dev);
2844 : :
2845 : 0 : ret = txgbe_parse_fdir_filter_normal(dev, attr, pattern,
2846 : : actions, rule, error);
2847 [ # # ]: 0 : if (!ret)
2848 : 0 : goto step_next;
2849 : :
2850 : 0 : ret = txgbe_parse_fdir_filter_tunnel(attr, pattern,
2851 : : actions, rule, error);
2852 [ # # ]: 0 : if (ret)
2853 : : return ret;
2854 : :
2855 : 0 : step_next:
2856 : :
2857 [ # # ]: 0 : if (hw->mac.type == txgbe_mac_raptor &&
2858 [ # # ]: 0 : rule->fdirflags == TXGBE_FDIRPICMD_DROP &&
2859 [ # # ]: 0 : (rule->input.src_port != 0 || rule->input.dst_port != 0))
2860 : : return -ENOTSUP;
2861 : :
2862 [ # # ]: 0 : if (fdir_conf->mode == RTE_FDIR_MODE_NONE) {
2863 : 0 : fdir_conf->mode = rule->mode;
2864 : 0 : ret = txgbe_fdir_configure(dev);
2865 [ # # ]: 0 : if (ret) {
2866 : 0 : fdir_conf->mode = RTE_FDIR_MODE_NONE;
2867 : 0 : return ret;
2868 : : }
2869 [ # # ]: 0 : } else if (fdir_conf->mode != rule->mode) {
2870 : : return -ENOTSUP;
2871 : : }
2872 : :
2873 [ # # ]: 0 : if (rule->queue >= dev->data->nb_rx_queues)
2874 : 0 : return -ENOTSUP;
2875 : :
2876 : : return ret;
2877 : : }
2878 : :
2879 : : static int
2880 : 0 : txgbe_parse_rss_filter(struct rte_eth_dev *dev,
2881 : : const struct rte_flow_attr *attr,
2882 : : const struct rte_flow_action actions[],
2883 : : struct txgbe_rte_flow_rss_conf *rss_conf,
2884 : : struct rte_flow_error *error)
2885 : : {
2886 : : const struct rte_flow_action *act;
2887 : : const struct rte_flow_action_rss *rss;
2888 : : uint16_t n;
2889 : :
2890 : : /**
2891 : : * rss only supports forwarding,
2892 : : * check if the first not void action is RSS.
2893 : : */
2894 : : act = next_no_void_action(actions, NULL);
2895 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_RSS) {
2896 : : memset(rss_conf, 0, sizeof(struct txgbe_rte_flow_rss_conf));
2897 : 0 : rte_flow_error_set(error, EINVAL,
2898 : : RTE_FLOW_ERROR_TYPE_ACTION,
2899 : : act, "Not supported action.");
2900 : 0 : return -rte_errno;
2901 : : }
2902 : :
2903 : 0 : rss = (const struct rte_flow_action_rss *)act->conf;
2904 : :
2905 [ # # # # ]: 0 : if (!rss || !rss->queue_num) {
2906 : 0 : rte_flow_error_set(error, EINVAL,
2907 : : RTE_FLOW_ERROR_TYPE_ACTION,
2908 : : act,
2909 : : "no valid queues");
2910 : 0 : return -rte_errno;
2911 : : }
2912 : :
2913 [ # # ]: 0 : for (n = 0; n < rss->queue_num; n++) {
2914 [ # # ]: 0 : if (rss->queue[n] >= dev->data->nb_rx_queues) {
2915 : 0 : rte_flow_error_set(error, EINVAL,
2916 : : RTE_FLOW_ERROR_TYPE_ACTION,
2917 : : act,
2918 : : "queue id > max number of queues");
2919 : 0 : return -rte_errno;
2920 : : }
2921 : : }
2922 : :
2923 [ # # ]: 0 : if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT)
2924 : 0 : return rte_flow_error_set
2925 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, act,
2926 : : "non-default RSS hash functions are not supported");
2927 [ # # ]: 0 : if (rss->level)
2928 : 0 : return rte_flow_error_set
2929 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, act,
2930 : : "a nonzero RSS encapsulation level is not supported");
2931 [ # # ]: 0 : if (rss->key_len && rss->key_len != RTE_DIM(rss_conf->key))
2932 : 0 : return rte_flow_error_set
2933 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, act,
2934 : : "RSS hash key must be exactly 40 bytes");
2935 [ # # ]: 0 : if (rss->queue_num > RTE_DIM(rss_conf->queue))
2936 : 0 : return rte_flow_error_set
2937 : : (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, act,
2938 : : "too many queues for RSS context");
2939 [ # # ]: 0 : if (txgbe_rss_conf_init(rss_conf, rss))
2940 : 0 : return rte_flow_error_set
2941 : : (error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, act,
2942 : : "RSS context initialization failure");
2943 : :
2944 : : /* check if the next not void item is END */
2945 : : act = next_no_void_action(actions, act);
2946 [ # # ]: 0 : if (act->type != RTE_FLOW_ACTION_TYPE_END) {
2947 : : memset(rss_conf, 0, sizeof(struct txgbe_rte_flow_rss_conf));
2948 : 0 : rte_flow_error_set(error, EINVAL,
2949 : : RTE_FLOW_ERROR_TYPE_ACTION,
2950 : : act, "Not supported action.");
2951 : 0 : return -rte_errno;
2952 : : }
2953 : :
2954 : : /* parse attr */
2955 : : /* must be input direction */
2956 [ # # ]: 0 : if (!attr->ingress) {
2957 : : memset(rss_conf, 0, sizeof(struct txgbe_rte_flow_rss_conf));
2958 : 0 : rte_flow_error_set(error, EINVAL,
2959 : : RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
2960 : : attr, "Only support ingress.");
2961 : 0 : return -rte_errno;
2962 : : }
2963 : :
2964 : : /* not supported */
2965 [ # # ]: 0 : if (attr->egress) {
2966 : : memset(rss_conf, 0, sizeof(struct txgbe_rte_flow_rss_conf));
2967 : 0 : rte_flow_error_set(error, EINVAL,
2968 : : RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
2969 : : attr, "Not support egress.");
2970 : 0 : return -rte_errno;
2971 : : }
2972 : :
2973 : : /* not supported */
2974 [ # # ]: 0 : if (attr->transfer) {
2975 : : memset(rss_conf, 0, sizeof(struct txgbe_rte_flow_rss_conf));
2976 : 0 : rte_flow_error_set(error, EINVAL,
2977 : : RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
2978 : : attr, "No support for transfer.");
2979 : 0 : return -rte_errno;
2980 : : }
2981 : :
2982 [ # # ]: 0 : if (attr->priority > 0xFFFF) {
2983 : : memset(rss_conf, 0, sizeof(struct txgbe_rte_flow_rss_conf));
2984 : 0 : rte_flow_error_set(error, EINVAL,
2985 : : RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
2986 : : attr, "Error priority.");
2987 : 0 : return -rte_errno;
2988 : : }
2989 : :
2990 : : return 0;
2991 : : }
2992 : :
2993 : : /* remove the rss filter */
2994 : : static void
2995 : : txgbe_clear_rss_filter(struct rte_eth_dev *dev)
2996 : : {
2997 : 0 : struct txgbe_filter_info *filter_info = TXGBE_DEV_FILTER(dev);
2998 : :
2999 [ # # ]: 0 : if (filter_info->rss_info.conf.queue_num)
3000 : 0 : txgbe_config_rss_filter(dev, &filter_info->rss_info, FALSE);
3001 : : }
3002 : :
3003 : : void
3004 : 0 : txgbe_filterlist_init(void)
3005 : : {
3006 : 0 : TAILQ_INIT(&filter_ntuple_list);
3007 : 0 : TAILQ_INIT(&filter_ethertype_list);
3008 : 0 : TAILQ_INIT(&filter_syn_list);
3009 : 0 : TAILQ_INIT(&filter_fdir_list);
3010 : 0 : TAILQ_INIT(&filter_l2_tunnel_list);
3011 : 0 : TAILQ_INIT(&filter_rss_list);
3012 : 0 : TAILQ_INIT(&txgbe_flow_list);
3013 : 0 : }
3014 : :
3015 : : void
3016 : 0 : txgbe_filterlist_flush(void)
3017 : : {
3018 : : struct txgbe_ntuple_filter_ele *ntuple_filter_ptr;
3019 : : struct txgbe_ethertype_filter_ele *ethertype_filter_ptr;
3020 : : struct txgbe_eth_syn_filter_ele *syn_filter_ptr;
3021 : : struct txgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
3022 : : struct txgbe_fdir_rule_ele *fdir_rule_ptr;
3023 : : struct txgbe_flow_mem *txgbe_flow_mem_ptr;
3024 : : struct txgbe_rss_conf_ele *rss_filter_ptr;
3025 : :
3026 [ # # ]: 0 : while ((ntuple_filter_ptr = TAILQ_FIRST(&filter_ntuple_list))) {
3027 [ # # ]: 0 : TAILQ_REMOVE(&filter_ntuple_list,
3028 : : ntuple_filter_ptr,
3029 : : entries);
3030 : 0 : rte_free(ntuple_filter_ptr);
3031 : : }
3032 : :
3033 [ # # ]: 0 : while ((ethertype_filter_ptr = TAILQ_FIRST(&filter_ethertype_list))) {
3034 [ # # ]: 0 : TAILQ_REMOVE(&filter_ethertype_list,
3035 : : ethertype_filter_ptr,
3036 : : entries);
3037 : 0 : rte_free(ethertype_filter_ptr);
3038 : : }
3039 : :
3040 [ # # ]: 0 : while ((syn_filter_ptr = TAILQ_FIRST(&filter_syn_list))) {
3041 [ # # ]: 0 : TAILQ_REMOVE(&filter_syn_list,
3042 : : syn_filter_ptr,
3043 : : entries);
3044 : 0 : rte_free(syn_filter_ptr);
3045 : : }
3046 : :
3047 [ # # ]: 0 : while ((l2_tn_filter_ptr = TAILQ_FIRST(&filter_l2_tunnel_list))) {
3048 [ # # ]: 0 : TAILQ_REMOVE(&filter_l2_tunnel_list,
3049 : : l2_tn_filter_ptr,
3050 : : entries);
3051 : 0 : rte_free(l2_tn_filter_ptr);
3052 : : }
3053 : :
3054 [ # # ]: 0 : while ((fdir_rule_ptr = TAILQ_FIRST(&filter_fdir_list))) {
3055 [ # # ]: 0 : TAILQ_REMOVE(&filter_fdir_list,
3056 : : fdir_rule_ptr,
3057 : : entries);
3058 : 0 : rte_free(fdir_rule_ptr);
3059 : : }
3060 : :
3061 [ # # ]: 0 : while ((rss_filter_ptr = TAILQ_FIRST(&filter_rss_list))) {
3062 [ # # ]: 0 : TAILQ_REMOVE(&filter_rss_list,
3063 : : rss_filter_ptr,
3064 : : entries);
3065 : 0 : rte_free(rss_filter_ptr);
3066 : : }
3067 : :
3068 [ # # ]: 0 : while ((txgbe_flow_mem_ptr = TAILQ_FIRST(&txgbe_flow_list))) {
3069 [ # # ]: 0 : TAILQ_REMOVE(&txgbe_flow_list,
3070 : : txgbe_flow_mem_ptr,
3071 : : entries);
3072 : 0 : rte_free(txgbe_flow_mem_ptr->flow);
3073 : 0 : rte_free(txgbe_flow_mem_ptr);
3074 : : }
3075 : 0 : }
3076 : :
3077 : : /**
3078 : : * Create or destroy a flow rule.
3079 : : * Theorically one rule can match more than one filters.
3080 : : * We will let it use the filter which it hit first.
3081 : : * So, the sequence matters.
3082 : : */
3083 : : static struct rte_flow *
3084 : 0 : txgbe_flow_create(struct rte_eth_dev *dev,
3085 : : const struct rte_flow_attr *attr,
3086 : : const struct rte_flow_item pattern[],
3087 : : const struct rte_flow_action actions[],
3088 : : struct rte_flow_error *error)
3089 : : {
3090 : : int ret;
3091 : : struct rte_eth_ntuple_filter ntuple_filter;
3092 : : struct rte_eth_ethertype_filter ethertype_filter;
3093 : : struct rte_eth_syn_filter syn_filter;
3094 : : struct txgbe_fdir_rule fdir_rule;
3095 : : struct txgbe_l2_tunnel_conf l2_tn_filter;
3096 : 0 : struct txgbe_hw_fdir_info *fdir_info = TXGBE_DEV_FDIR(dev);
3097 : : struct txgbe_rte_flow_rss_conf rss_conf;
3098 : : struct rte_flow *flow = NULL;
3099 : : struct txgbe_ntuple_filter_ele *ntuple_filter_ptr;
3100 : : struct txgbe_ethertype_filter_ele *ethertype_filter_ptr;
3101 : : struct txgbe_eth_syn_filter_ele *syn_filter_ptr;
3102 : : struct txgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
3103 : : struct txgbe_fdir_rule_ele *fdir_rule_ptr;
3104 : : struct txgbe_rss_conf_ele *rss_filter_ptr;
3105 : : struct txgbe_flow_mem *txgbe_flow_mem_ptr;
3106 : : uint8_t first_mask = FALSE;
3107 : :
3108 : 0 : flow = rte_zmalloc("txgbe_rte_flow", sizeof(struct rte_flow), 0);
3109 [ # # ]: 0 : if (!flow) {
3110 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3111 : 0 : return (struct rte_flow *)flow;
3112 : : }
3113 : 0 : txgbe_flow_mem_ptr = rte_zmalloc("txgbe_flow_mem",
3114 : : sizeof(struct txgbe_flow_mem), 0);
3115 [ # # ]: 0 : if (!txgbe_flow_mem_ptr) {
3116 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3117 : 0 : rte_free(flow);
3118 : 0 : return NULL;
3119 : : }
3120 : 0 : txgbe_flow_mem_ptr->flow = flow;
3121 : 0 : TAILQ_INSERT_TAIL(&txgbe_flow_list,
3122 : : txgbe_flow_mem_ptr, entries);
3123 : :
3124 : : memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter));
3125 : 0 : ret = txgbe_parse_ntuple_filter(dev, attr, pattern,
3126 : : actions, &ntuple_filter, error);
3127 : :
3128 : : #ifdef RTE_LIB_SECURITY
3129 : : /* ESP flow not really a flow*/
3130 [ # # ]: 0 : if (ntuple_filter.proto == IPPROTO_ESP)
3131 : : return flow;
3132 : : #endif
3133 : :
3134 [ # # ]: 0 : if (!ret) {
3135 : 0 : ret = txgbe_add_del_ntuple_filter(dev, &ntuple_filter, TRUE);
3136 [ # # ]: 0 : if (!ret) {
3137 : 0 : ntuple_filter_ptr = rte_zmalloc("txgbe_ntuple_filter",
3138 : : sizeof(struct txgbe_ntuple_filter_ele), 0);
3139 [ # # ]: 0 : if (!ntuple_filter_ptr) {
3140 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3141 : 0 : goto out;
3142 : : }
3143 [ # # ]: 0 : rte_memcpy(&ntuple_filter_ptr->filter_info,
3144 : : &ntuple_filter,
3145 : : sizeof(struct rte_eth_ntuple_filter));
3146 : 0 : TAILQ_INSERT_TAIL(&filter_ntuple_list,
3147 : : ntuple_filter_ptr, entries);
3148 : 0 : flow->rule = ntuple_filter_ptr;
3149 : 0 : flow->filter_type = RTE_ETH_FILTER_NTUPLE;
3150 : 0 : return flow;
3151 : : }
3152 : 0 : goto out;
3153 : : }
3154 : :
3155 [ # # ]: 0 : if (!txgbe_is_pf(TXGBE_DEV_HW(dev))) {
3156 : 0 : PMD_DRV_LOG(ERR, "Flow type not suppotted yet on VF.");
3157 : 0 : goto out;
3158 : : }
3159 : :
3160 : : memset(ðertype_filter, 0, sizeof(struct rte_eth_ethertype_filter));
3161 : 0 : ret = txgbe_parse_ethertype_filter(dev, attr, pattern,
3162 : : actions, ðertype_filter, error);
3163 [ # # ]: 0 : if (!ret) {
3164 : 0 : ret = txgbe_add_del_ethertype_filter(dev,
3165 : : ðertype_filter, TRUE);
3166 [ # # ]: 0 : if (!ret) {
3167 : : ethertype_filter_ptr =
3168 : 0 : rte_zmalloc("txgbe_ethertype_filter",
3169 : : sizeof(struct txgbe_ethertype_filter_ele), 0);
3170 [ # # ]: 0 : if (!ethertype_filter_ptr) {
3171 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3172 : 0 : goto out;
3173 : : }
3174 [ # # ]: 0 : rte_memcpy(ðertype_filter_ptr->filter_info,
3175 : : ðertype_filter,
3176 : : sizeof(struct rte_eth_ethertype_filter));
3177 : 0 : TAILQ_INSERT_TAIL(&filter_ethertype_list,
3178 : : ethertype_filter_ptr, entries);
3179 : 0 : flow->rule = ethertype_filter_ptr;
3180 : 0 : flow->filter_type = RTE_ETH_FILTER_ETHERTYPE;
3181 : 0 : return flow;
3182 : : }
3183 : 0 : goto out;
3184 : : }
3185 : :
3186 : : memset(&syn_filter, 0, sizeof(struct rte_eth_syn_filter));
3187 : : ret = txgbe_parse_syn_filter(dev, attr, pattern,
3188 : : actions, &syn_filter, error);
3189 [ # # ]: 0 : if (!ret) {
3190 : 0 : ret = txgbe_syn_filter_set(dev, &syn_filter, TRUE);
3191 [ # # ]: 0 : if (!ret) {
3192 : 0 : syn_filter_ptr = rte_zmalloc("txgbe_syn_filter",
3193 : : sizeof(struct txgbe_eth_syn_filter_ele), 0);
3194 [ # # ]: 0 : if (!syn_filter_ptr) {
3195 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3196 : 0 : goto out;
3197 : : }
3198 [ # # ]: 0 : rte_memcpy(&syn_filter_ptr->filter_info,
3199 : : &syn_filter,
3200 : : sizeof(struct rte_eth_syn_filter));
3201 : 0 : TAILQ_INSERT_TAIL(&filter_syn_list,
3202 : : syn_filter_ptr,
3203 : : entries);
3204 : 0 : flow->rule = syn_filter_ptr;
3205 : 0 : flow->filter_type = RTE_ETH_FILTER_SYN;
3206 : 0 : return flow;
3207 : : }
3208 : 0 : goto out;
3209 : : }
3210 : :
3211 : : memset(&fdir_rule, 0, sizeof(struct txgbe_fdir_rule));
3212 : 0 : ret = txgbe_parse_fdir_filter(dev, attr, pattern,
3213 : : actions, &fdir_rule, error);
3214 [ # # ]: 0 : if (!ret) {
3215 : : /* A mask cannot be deleted. */
3216 [ # # ]: 0 : if (fdir_rule.b_mask) {
3217 [ # # ]: 0 : if (!fdir_info->mask_added) {
3218 : : /* It's the first time the mask is set. */
3219 : 0 : fdir_info->mask = fdir_rule.mask;
3220 : 0 : fdir_info->flex_bytes_offset =
3221 : 0 : fdir_rule.flex_bytes_offset;
3222 : 0 : fdir_info->flex_relative = fdir_rule.flex_relative;
3223 : :
3224 [ # # ]: 0 : if (fdir_rule.mask.flex_bytes_mask) {
3225 : : uint16_t flex_base;
3226 : :
3227 : 0 : flex_base = txgbe_fdir_get_flex_base(&fdir_rule);
3228 : 0 : txgbe_fdir_set_flexbytes_offset(dev,
3229 : 0 : fdir_rule.flex_bytes_offset,
3230 : : flex_base);
3231 : : }
3232 : :
3233 : 0 : fdir_info->mask.pkt_type_mask =
3234 : 0 : fdir_rule.mask.pkt_type_mask;
3235 : 0 : ret = txgbe_fdir_set_input_mask(dev);
3236 [ # # ]: 0 : if (ret)
3237 : 0 : goto out;
3238 : :
3239 : 0 : fdir_info->mask_added = TRUE;
3240 : : first_mask = TRUE;
3241 : : } else {
3242 : : /**
3243 : : * Only support one global mask,
3244 : : * all the masks should be the same.
3245 : : */
3246 : 0 : ret = memcmp(&fdir_info->mask,
3247 : : &fdir_rule.mask,
3248 : : sizeof(struct txgbe_hw_fdir_mask));
3249 [ # # ]: 0 : if (ret) {
3250 : 0 : PMD_DRV_LOG(ERR, "only support one global mask");
3251 : 0 : goto out;
3252 : : }
3253 : :
3254 : 0 : if (fdir_info->flex_bytes_offset !=
3255 [ # # ]: 0 : fdir_rule.flex_bytes_offset ||
3256 : : fdir_info->flex_relative !=
3257 : : fdir_rule.flex_relative)
3258 : 0 : goto out;
3259 : : }
3260 : : }
3261 : :
3262 [ # # ]: 0 : if (fdir_rule.b_spec) {
3263 : 0 : ret = txgbe_fdir_filter_program(dev, &fdir_rule,
3264 : : FALSE, FALSE);
3265 [ # # ]: 0 : if (!ret) {
3266 : 0 : fdir_rule_ptr = rte_zmalloc("txgbe_fdir_filter",
3267 : : sizeof(struct txgbe_fdir_rule_ele), 0);
3268 [ # # ]: 0 : if (!fdir_rule_ptr) {
3269 : 0 : PMD_DRV_LOG(ERR,
3270 : : "failed to allocate memory");
3271 : 0 : goto out;
3272 : : }
3273 [ # # ]: 0 : rte_memcpy(&fdir_rule_ptr->filter_info,
3274 : : &fdir_rule,
3275 : : sizeof(struct txgbe_fdir_rule));
3276 : 0 : TAILQ_INSERT_TAIL(&filter_fdir_list,
3277 : : fdir_rule_ptr, entries);
3278 : 0 : flow->rule = fdir_rule_ptr;
3279 : 0 : flow->filter_type = RTE_ETH_FILTER_FDIR;
3280 : :
3281 : 0 : return flow;
3282 : : }
3283 : :
3284 : : if (ret) {
3285 : : /**
3286 : : * clean the mask_added flag if fail to
3287 : : * program
3288 : : **/
3289 [ # # ]: 0 : if (first_mask)
3290 : 0 : fdir_info->mask_added = FALSE;
3291 : 0 : goto out;
3292 : : }
3293 : : }
3294 : :
3295 : 0 : goto out;
3296 : : }
3297 : :
3298 : : memset(&l2_tn_filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
3299 : : ret = txgbe_parse_l2_tn_filter(dev, attr, pattern,
3300 : : actions, &l2_tn_filter, error);
3301 [ # # ]: 0 : if (!ret) {
3302 : 0 : ret = txgbe_dev_l2_tunnel_filter_add(dev, &l2_tn_filter, FALSE);
3303 [ # # ]: 0 : if (!ret) {
3304 : 0 : l2_tn_filter_ptr = rte_zmalloc("txgbe_l2_tn_filter",
3305 : : sizeof(struct txgbe_eth_l2_tunnel_conf_ele), 0);
3306 [ # # ]: 0 : if (!l2_tn_filter_ptr) {
3307 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3308 : 0 : goto out;
3309 : : }
3310 [ # # ]: 0 : rte_memcpy(&l2_tn_filter_ptr->filter_info,
3311 : : &l2_tn_filter,
3312 : : sizeof(struct txgbe_l2_tunnel_conf));
3313 : 0 : TAILQ_INSERT_TAIL(&filter_l2_tunnel_list,
3314 : : l2_tn_filter_ptr, entries);
3315 : 0 : flow->rule = l2_tn_filter_ptr;
3316 : 0 : flow->filter_type = RTE_ETH_FILTER_L2_TUNNEL;
3317 : 0 : return flow;
3318 : : }
3319 : : }
3320 : :
3321 : : memset(&rss_conf, 0, sizeof(struct txgbe_rte_flow_rss_conf));
3322 : 0 : ret = txgbe_parse_rss_filter(dev, attr,
3323 : : actions, &rss_conf, error);
3324 [ # # ]: 0 : if (!ret) {
3325 : 0 : ret = txgbe_config_rss_filter(dev, &rss_conf, TRUE);
3326 [ # # ]: 0 : if (!ret) {
3327 : 0 : rss_filter_ptr = rte_zmalloc("txgbe_rss_filter",
3328 : : sizeof(struct txgbe_rss_conf_ele), 0);
3329 [ # # ]: 0 : if (!rss_filter_ptr) {
3330 : 0 : PMD_DRV_LOG(ERR, "failed to allocate memory");
3331 : 0 : goto out;
3332 : : }
3333 : 0 : txgbe_rss_conf_init(&rss_filter_ptr->filter_info,
3334 : : &rss_conf.conf);
3335 : 0 : TAILQ_INSERT_TAIL(&filter_rss_list,
3336 : : rss_filter_ptr, entries);
3337 : 0 : flow->rule = rss_filter_ptr;
3338 : 0 : flow->filter_type = RTE_ETH_FILTER_HASH;
3339 : 0 : return flow;
3340 : : }
3341 : : }
3342 : :
3343 : 0 : out:
3344 [ # # ]: 0 : TAILQ_REMOVE(&txgbe_flow_list,
3345 : : txgbe_flow_mem_ptr, entries);
3346 : 0 : rte_flow_error_set(error, -ret,
3347 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
3348 : : "Failed to create flow.");
3349 : 0 : rte_free(txgbe_flow_mem_ptr);
3350 : 0 : rte_free(flow);
3351 : 0 : return NULL;
3352 : : }
3353 : :
3354 : : /**
3355 : : * Check if the flow rule is supported by txgbe.
3356 : : * It only checks the format. Don't guarantee the rule can be programmed into
3357 : : * the HW. Because there can be no enough room for the rule.
3358 : : */
3359 : : static int
3360 : 0 : txgbe_flow_validate(struct rte_eth_dev *dev,
3361 : : const struct rte_flow_attr *attr,
3362 : : const struct rte_flow_item pattern[],
3363 : : const struct rte_flow_action actions[],
3364 : : struct rte_flow_error *error)
3365 : : {
3366 : : struct rte_eth_ntuple_filter ntuple_filter;
3367 : : struct rte_eth_ethertype_filter ethertype_filter;
3368 : : struct rte_eth_syn_filter syn_filter;
3369 : : struct txgbe_l2_tunnel_conf l2_tn_filter;
3370 : : struct txgbe_fdir_rule fdir_rule;
3371 : : struct txgbe_rte_flow_rss_conf rss_conf;
3372 : : int ret = 0;
3373 : :
3374 : : memset(&ntuple_filter, 0, sizeof(struct rte_eth_ntuple_filter));
3375 : 0 : ret = txgbe_parse_ntuple_filter(dev, attr, pattern,
3376 : : actions, &ntuple_filter, error);
3377 [ # # ]: 0 : if (!ret)
3378 : : return 0;
3379 : :
3380 : : memset(ðertype_filter, 0, sizeof(struct rte_eth_ethertype_filter));
3381 : 0 : ret = txgbe_parse_ethertype_filter(dev, attr, pattern,
3382 : : actions, ðertype_filter, error);
3383 [ # # ]: 0 : if (!ret)
3384 : : return 0;
3385 : :
3386 : : memset(&syn_filter, 0, sizeof(struct rte_eth_syn_filter));
3387 : : ret = txgbe_parse_syn_filter(dev, attr, pattern,
3388 : : actions, &syn_filter, error);
3389 [ # # ]: 0 : if (!ret)
3390 : : return 0;
3391 : :
3392 : : memset(&fdir_rule, 0, sizeof(struct txgbe_fdir_rule));
3393 : 0 : ret = txgbe_parse_fdir_filter(dev, attr, pattern,
3394 : : actions, &fdir_rule, error);
3395 [ # # ]: 0 : if (!ret)
3396 : : return 0;
3397 : :
3398 : : memset(&l2_tn_filter, 0, sizeof(struct txgbe_l2_tunnel_conf));
3399 : : ret = txgbe_parse_l2_tn_filter(dev, attr, pattern,
3400 : : actions, &l2_tn_filter, error);
3401 [ # # ]: 0 : if (!ret)
3402 : : return 0;
3403 : :
3404 : : memset(&rss_conf, 0, sizeof(struct txgbe_rte_flow_rss_conf));
3405 : 0 : ret = txgbe_parse_rss_filter(dev, attr,
3406 : : actions, &rss_conf, error);
3407 : :
3408 : 0 : return ret;
3409 : : }
3410 : :
3411 : : /* Destroy a flow rule on txgbe. */
3412 : : static int
3413 : 0 : txgbe_flow_destroy(struct rte_eth_dev *dev,
3414 : : struct rte_flow *flow,
3415 : : struct rte_flow_error *error)
3416 : : {
3417 : : int ret = 0;
3418 : : struct rte_flow *pmd_flow = flow;
3419 : 0 : enum rte_filter_type filter_type = pmd_flow->filter_type;
3420 : : struct rte_eth_ntuple_filter ntuple_filter;
3421 : : struct rte_eth_ethertype_filter ethertype_filter;
3422 : : struct rte_eth_syn_filter syn_filter;
3423 : : struct txgbe_fdir_rule fdir_rule;
3424 : : struct txgbe_l2_tunnel_conf l2_tn_filter;
3425 : : struct txgbe_ntuple_filter_ele *ntuple_filter_ptr;
3426 : : struct txgbe_ethertype_filter_ele *ethertype_filter_ptr;
3427 : : struct txgbe_eth_syn_filter_ele *syn_filter_ptr;
3428 : : struct txgbe_eth_l2_tunnel_conf_ele *l2_tn_filter_ptr;
3429 : : struct txgbe_fdir_rule_ele *fdir_rule_ptr;
3430 : : struct txgbe_flow_mem *txgbe_flow_mem_ptr;
3431 : 0 : struct txgbe_hw_fdir_info *fdir_info = TXGBE_DEV_FDIR(dev);
3432 : : struct txgbe_rss_conf_ele *rss_filter_ptr;
3433 : :
3434 [ # # # # : 0 : switch (filter_type) {
# # # ]
3435 : 0 : case RTE_ETH_FILTER_NTUPLE:
3436 : 0 : ntuple_filter_ptr = (struct txgbe_ntuple_filter_ele *)
3437 : : pmd_flow->rule;
3438 : : rte_memcpy(&ntuple_filter,
3439 [ # # ]: 0 : &ntuple_filter_ptr->filter_info,
3440 : : sizeof(struct rte_eth_ntuple_filter));
3441 : 0 : ret = txgbe_add_del_ntuple_filter(dev, &ntuple_filter, FALSE);
3442 [ # # ]: 0 : if (!ret) {
3443 [ # # ]: 0 : TAILQ_REMOVE(&filter_ntuple_list,
3444 : : ntuple_filter_ptr, entries);
3445 : 0 : rte_free(ntuple_filter_ptr);
3446 : : }
3447 : : break;
3448 : 0 : case RTE_ETH_FILTER_ETHERTYPE:
3449 : 0 : ethertype_filter_ptr = (struct txgbe_ethertype_filter_ele *)
3450 : : pmd_flow->rule;
3451 : : rte_memcpy(ðertype_filter,
3452 [ # # ]: 0 : ðertype_filter_ptr->filter_info,
3453 : : sizeof(struct rte_eth_ethertype_filter));
3454 : 0 : ret = txgbe_add_del_ethertype_filter(dev,
3455 : : ðertype_filter, FALSE);
3456 [ # # ]: 0 : if (!ret) {
3457 [ # # ]: 0 : TAILQ_REMOVE(&filter_ethertype_list,
3458 : : ethertype_filter_ptr, entries);
3459 : 0 : rte_free(ethertype_filter_ptr);
3460 : : }
3461 : : break;
3462 : 0 : case RTE_ETH_FILTER_SYN:
3463 : 0 : syn_filter_ptr = (struct txgbe_eth_syn_filter_ele *)
3464 : : pmd_flow->rule;
3465 : : rte_memcpy(&syn_filter,
3466 [ # # ]: 0 : &syn_filter_ptr->filter_info,
3467 : : sizeof(struct rte_eth_syn_filter));
3468 : 0 : ret = txgbe_syn_filter_set(dev, &syn_filter, FALSE);
3469 [ # # ]: 0 : if (!ret) {
3470 [ # # ]: 0 : TAILQ_REMOVE(&filter_syn_list,
3471 : : syn_filter_ptr, entries);
3472 : 0 : rte_free(syn_filter_ptr);
3473 : : }
3474 : : break;
3475 : 0 : case RTE_ETH_FILTER_FDIR:
3476 : 0 : fdir_rule_ptr = (struct txgbe_fdir_rule_ele *)pmd_flow->rule;
3477 : : rte_memcpy(&fdir_rule,
3478 [ # # ]: 0 : &fdir_rule_ptr->filter_info,
3479 : : sizeof(struct txgbe_fdir_rule));
3480 : 0 : ret = txgbe_fdir_filter_program(dev, &fdir_rule, TRUE, FALSE);
3481 [ # # ]: 0 : if (!ret) {
3482 [ # # ]: 0 : TAILQ_REMOVE(&filter_fdir_list,
3483 : : fdir_rule_ptr, entries);
3484 : 0 : rte_free(fdir_rule_ptr);
3485 [ # # ]: 0 : if (TAILQ_EMPTY(&filter_fdir_list)) {
3486 : 0 : memset(&fdir_info->mask, 0,
3487 : : sizeof(struct txgbe_hw_fdir_mask));
3488 : 0 : fdir_info->mask_added = false;
3489 : 0 : fdir_info->flex_relative = false;
3490 : 0 : fdir_info->flex_bytes_offset = 0;
3491 : : }
3492 : : }
3493 : : break;
3494 : 0 : case RTE_ETH_FILTER_L2_TUNNEL:
3495 : 0 : l2_tn_filter_ptr = (struct txgbe_eth_l2_tunnel_conf_ele *)
3496 : : pmd_flow->rule;
3497 [ # # ]: 0 : rte_memcpy(&l2_tn_filter, &l2_tn_filter_ptr->filter_info,
3498 : : sizeof(struct txgbe_l2_tunnel_conf));
3499 : 0 : ret = txgbe_dev_l2_tunnel_filter_del(dev, &l2_tn_filter);
3500 [ # # ]: 0 : if (!ret) {
3501 [ # # ]: 0 : TAILQ_REMOVE(&filter_l2_tunnel_list,
3502 : : l2_tn_filter_ptr, entries);
3503 : 0 : rte_free(l2_tn_filter_ptr);
3504 : : }
3505 : : break;
3506 : 0 : case RTE_ETH_FILTER_HASH:
3507 : 0 : rss_filter_ptr = (struct txgbe_rss_conf_ele *)
3508 : : pmd_flow->rule;
3509 : 0 : ret = txgbe_config_rss_filter(dev,
3510 : : &rss_filter_ptr->filter_info, FALSE);
3511 [ # # ]: 0 : if (!ret) {
3512 [ # # ]: 0 : TAILQ_REMOVE(&filter_rss_list,
3513 : : rss_filter_ptr, entries);
3514 : 0 : rte_free(rss_filter_ptr);
3515 : : }
3516 : : break;
3517 : 0 : default:
3518 : 0 : PMD_DRV_LOG(WARNING, "Filter type (%d) not supported",
3519 : : filter_type);
3520 : : ret = -EINVAL;
3521 : : break;
3522 : : }
3523 : :
3524 [ # # ]: 0 : if (ret) {
3525 : 0 : rte_flow_error_set(error, EINVAL,
3526 : : RTE_FLOW_ERROR_TYPE_HANDLE,
3527 : : NULL, "Failed to destroy flow");
3528 : 0 : return ret;
3529 : : }
3530 : :
3531 [ # # ]: 0 : TAILQ_FOREACH(txgbe_flow_mem_ptr, &txgbe_flow_list, entries) {
3532 [ # # ]: 0 : if (txgbe_flow_mem_ptr->flow == pmd_flow) {
3533 [ # # ]: 0 : TAILQ_REMOVE(&txgbe_flow_list,
3534 : : txgbe_flow_mem_ptr, entries);
3535 : 0 : rte_free(txgbe_flow_mem_ptr);
3536 : : }
3537 : : }
3538 : 0 : rte_free(flow);
3539 : :
3540 : 0 : return ret;
3541 : : }
3542 : :
3543 : : /* Destroy all flow rules associated with a port on txgbe. */
3544 : : static int
3545 : 0 : txgbe_flow_flush(struct rte_eth_dev *dev,
3546 : : struct rte_flow_error *error)
3547 : : {
3548 : : int ret = 0;
3549 : :
3550 : 0 : txgbe_clear_all_ntuple_filter(dev);
3551 : :
3552 [ # # ]: 0 : if (!txgbe_is_pf(TXGBE_DEV_HW(dev)))
3553 : 0 : goto out;
3554 : :
3555 : 0 : txgbe_clear_all_ethertype_filter(dev);
3556 : 0 : txgbe_clear_syn_filter(dev);
3557 : :
3558 : 0 : ret = txgbe_clear_all_fdir_filter(dev);
3559 [ # # ]: 0 : if (ret < 0) {
3560 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_HANDLE,
3561 : : NULL, "Failed to flush rule");
3562 : 0 : return ret;
3563 : : }
3564 : :
3565 : 0 : ret = txgbe_clear_all_l2_tn_filter(dev);
3566 [ # # ]: 0 : if (ret < 0) {
3567 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_HANDLE,
3568 : : NULL, "Failed to flush rule");
3569 : 0 : return ret;
3570 : : }
3571 : :
3572 : : txgbe_clear_rss_filter(dev);
3573 : :
3574 : 0 : out:
3575 : 0 : txgbe_filterlist_flush();
3576 : :
3577 : 0 : return 0;
3578 : : }
3579 : :
3580 : : const struct rte_flow_ops txgbe_flow_ops = {
3581 : : .validate = txgbe_flow_validate,
3582 : : .create = txgbe_flow_create,
3583 : : .destroy = txgbe_flow_destroy,
3584 : : .flush = txgbe_flow_flush,
3585 : : };
|