1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2017-2018 Solarflare Communications Inc.
6 * This software was jointly developed between OKTET Labs (under contract
7 * for Solarflare) and Solarflare Communications, Inc.
10 #include <rte_byteorder.h>
11 #include <rte_tailq.h>
12 #include <rte_common.h>
13 #include <rte_ethdev_driver.h>
14 #include <rte_ether.h>
16 #include <rte_flow_driver.h>
22 #include "sfc_filter.h"
25 #include "sfc_dp_rx.h"
28 * Currently, filter-based (VNIC) flow API is implemented in such a manner
29 * that each flow rule is converted to one or more hardware filters.
30 * All elements of flow rule (attributes, pattern items, actions)
31 * correspond to one or more fields in the efx_filter_spec_s structure
32 * that is responsible for the hardware filter.
33 * If some required field is unset in the flow rule, then a handful
34 * of filter copies will be created to cover all possible values
38 enum sfc_flow_item_layers {
39 SFC_FLOW_ITEM_ANY_LAYER,
40 SFC_FLOW_ITEM_START_LAYER,
46 typedef int (sfc_flow_item_parse)(const struct rte_flow_item *item,
47 efx_filter_spec_t *spec,
48 struct rte_flow_error *error);
50 struct sfc_flow_item {
51 enum rte_flow_item_type type; /* Type of item */
52 enum sfc_flow_item_layers layer; /* Layer of item */
53 enum sfc_flow_item_layers prev_layer; /* Previous layer of item */
54 sfc_flow_item_parse *parse; /* Parsing function */
57 static sfc_flow_item_parse sfc_flow_parse_void;
58 static sfc_flow_item_parse sfc_flow_parse_eth;
59 static sfc_flow_item_parse sfc_flow_parse_vlan;
60 static sfc_flow_item_parse sfc_flow_parse_ipv4;
61 static sfc_flow_item_parse sfc_flow_parse_ipv6;
62 static sfc_flow_item_parse sfc_flow_parse_tcp;
63 static sfc_flow_item_parse sfc_flow_parse_udp;
64 static sfc_flow_item_parse sfc_flow_parse_vxlan;
65 static sfc_flow_item_parse sfc_flow_parse_geneve;
66 static sfc_flow_item_parse sfc_flow_parse_nvgre;
68 typedef int (sfc_flow_spec_set_vals)(struct sfc_flow_spec *spec,
69 unsigned int filters_count_for_one_val,
70 struct rte_flow_error *error);
72 typedef boolean_t (sfc_flow_spec_check)(efx_filter_match_flags_t match,
73 efx_filter_spec_t *spec,
74 struct sfc_filter *filter);
76 struct sfc_flow_copy_flag {
77 /* EFX filter specification match flag */
78 efx_filter_match_flags_t flag;
79 /* Number of values of corresponding field */
80 unsigned int vals_count;
81 /* Function to set values in specifications */
82 sfc_flow_spec_set_vals *set_vals;
84 * Function to check that the specification is suitable
85 * for adding this match flag
87 sfc_flow_spec_check *spec_check;
90 static sfc_flow_spec_set_vals sfc_flow_set_unknown_dst_flags;
91 static sfc_flow_spec_check sfc_flow_check_unknown_dst_flags;
92 static sfc_flow_spec_set_vals sfc_flow_set_ethertypes;
93 static sfc_flow_spec_set_vals sfc_flow_set_ifrm_unknown_dst_flags;
94 static sfc_flow_spec_check sfc_flow_check_ifrm_unknown_dst_flags;
95 static sfc_flow_spec_set_vals sfc_flow_set_outer_vid_flag;
96 static sfc_flow_spec_check sfc_flow_check_outer_vid_flag;
99 sfc_flow_is_zero(const uint8_t *buf, unsigned int size)
104 for (i = 0; i < size; i++)
107 return (sum == 0) ? B_TRUE : B_FALSE;
111 * Validate item and prepare structures spec and mask for parsing
114 sfc_flow_parse_init(const struct rte_flow_item *item,
115 const void **spec_ptr,
116 const void **mask_ptr,
117 const void *supp_mask,
118 const void *def_mask,
120 struct rte_flow_error *error)
129 rte_flow_error_set(error, EINVAL,
130 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
135 if ((item->last != NULL || item->mask != NULL) && item->spec == NULL) {
136 rte_flow_error_set(error, EINVAL,
137 RTE_FLOW_ERROR_TYPE_ITEM, item,
138 "Mask or last is set without spec");
143 * If "mask" is not set, default mask is used,
144 * but if default mask is NULL, "mask" should be set
146 if (item->mask == NULL) {
147 if (def_mask == NULL) {
148 rte_flow_error_set(error, EINVAL,
149 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
150 "Mask should be specified");
166 * If field values in "last" are either 0 or equal to the corresponding
167 * values in "spec" then they are ignored
170 !sfc_flow_is_zero(last, size) &&
171 memcmp(last, spec, size) != 0) {
172 rte_flow_error_set(error, ENOTSUP,
173 RTE_FLOW_ERROR_TYPE_ITEM, item,
174 "Ranging is not supported");
178 if (supp_mask == NULL) {
179 rte_flow_error_set(error, EINVAL,
180 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
181 "Supported mask for item should be specified");
185 /* Check that mask does not ask for more match than supp_mask */
186 for (i = 0; i < size; i++) {
187 supp = ((const uint8_t *)supp_mask)[i];
189 if (~supp & mask[i]) {
190 rte_flow_error_set(error, ENOTSUP,
191 RTE_FLOW_ERROR_TYPE_ITEM, item,
192 "Item's field is not supported");
205 * Masking is not supported, so masks in items should be either
206 * full or empty (zeroed) and set only for supported fields which
207 * are specified in the supp_mask.
211 sfc_flow_parse_void(__rte_unused const struct rte_flow_item *item,
212 __rte_unused efx_filter_spec_t *efx_spec,
213 __rte_unused struct rte_flow_error *error)
219 * Convert Ethernet item to EFX filter specification.
222 * Item specification. Outer frame specification may only comprise
223 * source/destination addresses and Ethertype field.
224 * Inner frame specification may contain destination address only.
225 * There is support for individual/group mask as well as for empty and full.
226 * If the mask is NULL, default mask will be used. Ranging is not supported.
227 * @param efx_spec[in, out]
228 * EFX filter specification to update.
230 * Perform verbose error reporting if not NULL.
233 sfc_flow_parse_eth(const struct rte_flow_item *item,
234 efx_filter_spec_t *efx_spec,
235 struct rte_flow_error *error)
238 const struct rte_flow_item_eth *spec = NULL;
239 const struct rte_flow_item_eth *mask = NULL;
240 const struct rte_flow_item_eth supp_mask = {
241 .dst.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
242 .src.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
245 const struct rte_flow_item_eth ifrm_supp_mask = {
246 .dst.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
248 const uint8_t ig_mask[EFX_MAC_ADDR_LEN] = {
249 0x01, 0x00, 0x00, 0x00, 0x00, 0x00
251 const struct rte_flow_item_eth *supp_mask_p;
252 const struct rte_flow_item_eth *def_mask_p;
253 uint8_t *loc_mac = NULL;
254 boolean_t is_ifrm = (efx_spec->efs_encap_type !=
255 EFX_TUNNEL_PROTOCOL_NONE);
258 supp_mask_p = &ifrm_supp_mask;
259 def_mask_p = &ifrm_supp_mask;
260 loc_mac = efx_spec->efs_ifrm_loc_mac;
262 supp_mask_p = &supp_mask;
263 def_mask_p = &rte_flow_item_eth_mask;
264 loc_mac = efx_spec->efs_loc_mac;
267 rc = sfc_flow_parse_init(item,
268 (const void **)&spec,
269 (const void **)&mask,
270 supp_mask_p, def_mask_p,
271 sizeof(struct rte_flow_item_eth),
276 /* If "spec" is not set, could be any Ethernet */
280 if (rte_is_same_ether_addr(&mask->dst, &supp_mask.dst)) {
281 efx_spec->efs_match_flags |= is_ifrm ?
282 EFX_FILTER_MATCH_IFRM_LOC_MAC :
283 EFX_FILTER_MATCH_LOC_MAC;
284 rte_memcpy(loc_mac, spec->dst.addr_bytes,
286 } else if (memcmp(mask->dst.addr_bytes, ig_mask,
287 EFX_MAC_ADDR_LEN) == 0) {
288 if (rte_is_unicast_ether_addr(&spec->dst))
289 efx_spec->efs_match_flags |= is_ifrm ?
290 EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST :
291 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST;
293 efx_spec->efs_match_flags |= is_ifrm ?
294 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST :
295 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST;
296 } else if (!rte_is_zero_ether_addr(&mask->dst)) {
301 * ifrm_supp_mask ensures that the source address and
302 * ethertype masks are equal to zero in inner frame,
303 * so these fields are filled in only for the outer frame
305 if (rte_is_same_ether_addr(&mask->src, &supp_mask.src)) {
306 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_MAC;
307 rte_memcpy(efx_spec->efs_rem_mac, spec->src.addr_bytes,
309 } else if (!rte_is_zero_ether_addr(&mask->src)) {
314 * Ether type is in big-endian byte order in item and
315 * in little-endian in efx_spec, so byte swap is used
317 if (mask->type == supp_mask.type) {
318 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
319 efx_spec->efs_ether_type = rte_bswap16(spec->type);
320 } else if (mask->type != 0) {
327 rte_flow_error_set(error, EINVAL,
328 RTE_FLOW_ERROR_TYPE_ITEM, item,
329 "Bad mask in the ETH pattern item");
334 * Convert VLAN item to EFX filter specification.
337 * Item specification. Only VID field is supported.
338 * The mask can not be NULL. Ranging is not supported.
339 * @param efx_spec[in, out]
340 * EFX filter specification to update.
342 * Perform verbose error reporting if not NULL.
345 sfc_flow_parse_vlan(const struct rte_flow_item *item,
346 efx_filter_spec_t *efx_spec,
347 struct rte_flow_error *error)
351 const struct rte_flow_item_vlan *spec = NULL;
352 const struct rte_flow_item_vlan *mask = NULL;
353 const struct rte_flow_item_vlan supp_mask = {
354 .tci = rte_cpu_to_be_16(ETH_VLAN_ID_MAX),
355 .inner_type = RTE_BE16(0xffff),
358 rc = sfc_flow_parse_init(item,
359 (const void **)&spec,
360 (const void **)&mask,
363 sizeof(struct rte_flow_item_vlan),
369 * VID is in big-endian byte order in item and
370 * in little-endian in efx_spec, so byte swap is used.
371 * If two VLAN items are included, the first matches
372 * the outer tag and the next matches the inner tag.
374 if (mask->tci == supp_mask.tci) {
375 /* Apply mask to keep VID only */
376 vid = rte_bswap16(spec->tci & mask->tci);
378 if (!(efx_spec->efs_match_flags &
379 EFX_FILTER_MATCH_OUTER_VID)) {
380 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_OUTER_VID;
381 efx_spec->efs_outer_vid = vid;
382 } else if (!(efx_spec->efs_match_flags &
383 EFX_FILTER_MATCH_INNER_VID)) {
384 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_INNER_VID;
385 efx_spec->efs_inner_vid = vid;
387 rte_flow_error_set(error, EINVAL,
388 RTE_FLOW_ERROR_TYPE_ITEM, item,
389 "More than two VLAN items");
393 rte_flow_error_set(error, EINVAL,
394 RTE_FLOW_ERROR_TYPE_ITEM, item,
395 "VLAN ID in TCI match is required");
399 if (efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE) {
400 rte_flow_error_set(error, EINVAL,
401 RTE_FLOW_ERROR_TYPE_ITEM, item,
402 "VLAN TPID matching is not supported");
405 if (mask->inner_type == supp_mask.inner_type) {
406 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
407 efx_spec->efs_ether_type = rte_bswap16(spec->inner_type);
408 } else if (mask->inner_type) {
409 rte_flow_error_set(error, EINVAL,
410 RTE_FLOW_ERROR_TYPE_ITEM, item,
411 "Bad mask for VLAN inner_type");
419 * Convert IPv4 item to EFX filter specification.
422 * Item specification. Only source and destination addresses and
423 * protocol fields are supported. If the mask is NULL, default
424 * mask will be used. Ranging is not supported.
425 * @param efx_spec[in, out]
426 * EFX filter specification to update.
428 * Perform verbose error reporting if not NULL.
431 sfc_flow_parse_ipv4(const struct rte_flow_item *item,
432 efx_filter_spec_t *efx_spec,
433 struct rte_flow_error *error)
436 const struct rte_flow_item_ipv4 *spec = NULL;
437 const struct rte_flow_item_ipv4 *mask = NULL;
438 const uint16_t ether_type_ipv4 = rte_cpu_to_le_16(EFX_ETHER_TYPE_IPV4);
439 const struct rte_flow_item_ipv4 supp_mask = {
441 .src_addr = 0xffffffff,
442 .dst_addr = 0xffffffff,
443 .next_proto_id = 0xff,
447 rc = sfc_flow_parse_init(item,
448 (const void **)&spec,
449 (const void **)&mask,
451 &rte_flow_item_ipv4_mask,
452 sizeof(struct rte_flow_item_ipv4),
458 * Filtering by IPv4 source and destination addresses requires
459 * the appropriate ETHER_TYPE in hardware filters
461 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE)) {
462 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
463 efx_spec->efs_ether_type = ether_type_ipv4;
464 } else if (efx_spec->efs_ether_type != ether_type_ipv4) {
465 rte_flow_error_set(error, EINVAL,
466 RTE_FLOW_ERROR_TYPE_ITEM, item,
467 "Ethertype in pattern with IPV4 item should be appropriate");
475 * IPv4 addresses are in big-endian byte order in item and in
478 if (mask->hdr.src_addr == supp_mask.hdr.src_addr) {
479 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_HOST;
480 efx_spec->efs_rem_host.eo_u32[0] = spec->hdr.src_addr;
481 } else if (mask->hdr.src_addr != 0) {
485 if (mask->hdr.dst_addr == supp_mask.hdr.dst_addr) {
486 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_HOST;
487 efx_spec->efs_loc_host.eo_u32[0] = spec->hdr.dst_addr;
488 } else if (mask->hdr.dst_addr != 0) {
492 if (mask->hdr.next_proto_id == supp_mask.hdr.next_proto_id) {
493 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
494 efx_spec->efs_ip_proto = spec->hdr.next_proto_id;
495 } else if (mask->hdr.next_proto_id != 0) {
502 rte_flow_error_set(error, EINVAL,
503 RTE_FLOW_ERROR_TYPE_ITEM, item,
504 "Bad mask in the IPV4 pattern item");
509 * Convert IPv6 item to EFX filter specification.
512 * Item specification. Only source and destination addresses and
513 * next header fields are supported. If the mask is NULL, default
514 * mask will be used. Ranging is not supported.
515 * @param efx_spec[in, out]
516 * EFX filter specification to update.
518 * Perform verbose error reporting if not NULL.
521 sfc_flow_parse_ipv6(const struct rte_flow_item *item,
522 efx_filter_spec_t *efx_spec,
523 struct rte_flow_error *error)
526 const struct rte_flow_item_ipv6 *spec = NULL;
527 const struct rte_flow_item_ipv6 *mask = NULL;
528 const uint16_t ether_type_ipv6 = rte_cpu_to_le_16(EFX_ETHER_TYPE_IPV6);
529 const struct rte_flow_item_ipv6 supp_mask = {
531 .src_addr = { 0xff, 0xff, 0xff, 0xff,
532 0xff, 0xff, 0xff, 0xff,
533 0xff, 0xff, 0xff, 0xff,
534 0xff, 0xff, 0xff, 0xff },
535 .dst_addr = { 0xff, 0xff, 0xff, 0xff,
536 0xff, 0xff, 0xff, 0xff,
537 0xff, 0xff, 0xff, 0xff,
538 0xff, 0xff, 0xff, 0xff },
543 rc = sfc_flow_parse_init(item,
544 (const void **)&spec,
545 (const void **)&mask,
547 &rte_flow_item_ipv6_mask,
548 sizeof(struct rte_flow_item_ipv6),
554 * Filtering by IPv6 source and destination addresses requires
555 * the appropriate ETHER_TYPE in hardware filters
557 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE)) {
558 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
559 efx_spec->efs_ether_type = ether_type_ipv6;
560 } else if (efx_spec->efs_ether_type != ether_type_ipv6) {
561 rte_flow_error_set(error, EINVAL,
562 RTE_FLOW_ERROR_TYPE_ITEM, item,
563 "Ethertype in pattern with IPV6 item should be appropriate");
571 * IPv6 addresses are in big-endian byte order in item and in
574 if (memcmp(mask->hdr.src_addr, supp_mask.hdr.src_addr,
575 sizeof(mask->hdr.src_addr)) == 0) {
576 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_HOST;
578 RTE_BUILD_BUG_ON(sizeof(efx_spec->efs_rem_host) !=
579 sizeof(spec->hdr.src_addr));
580 rte_memcpy(&efx_spec->efs_rem_host, spec->hdr.src_addr,
581 sizeof(efx_spec->efs_rem_host));
582 } else if (!sfc_flow_is_zero(mask->hdr.src_addr,
583 sizeof(mask->hdr.src_addr))) {
587 if (memcmp(mask->hdr.dst_addr, supp_mask.hdr.dst_addr,
588 sizeof(mask->hdr.dst_addr)) == 0) {
589 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_HOST;
591 RTE_BUILD_BUG_ON(sizeof(efx_spec->efs_loc_host) !=
592 sizeof(spec->hdr.dst_addr));
593 rte_memcpy(&efx_spec->efs_loc_host, spec->hdr.dst_addr,
594 sizeof(efx_spec->efs_loc_host));
595 } else if (!sfc_flow_is_zero(mask->hdr.dst_addr,
596 sizeof(mask->hdr.dst_addr))) {
600 if (mask->hdr.proto == supp_mask.hdr.proto) {
601 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
602 efx_spec->efs_ip_proto = spec->hdr.proto;
603 } else if (mask->hdr.proto != 0) {
610 rte_flow_error_set(error, EINVAL,
611 RTE_FLOW_ERROR_TYPE_ITEM, item,
612 "Bad mask in the IPV6 pattern item");
617 * Convert TCP item to EFX filter specification.
620 * Item specification. Only source and destination ports fields
621 * are supported. If the mask is NULL, default mask will be used.
622 * Ranging is not supported.
623 * @param efx_spec[in, out]
624 * EFX filter specification to update.
626 * Perform verbose error reporting if not NULL.
629 sfc_flow_parse_tcp(const struct rte_flow_item *item,
630 efx_filter_spec_t *efx_spec,
631 struct rte_flow_error *error)
634 const struct rte_flow_item_tcp *spec = NULL;
635 const struct rte_flow_item_tcp *mask = NULL;
636 const struct rte_flow_item_tcp supp_mask = {
643 rc = sfc_flow_parse_init(item,
644 (const void **)&spec,
645 (const void **)&mask,
647 &rte_flow_item_tcp_mask,
648 sizeof(struct rte_flow_item_tcp),
654 * Filtering by TCP source and destination ports requires
655 * the appropriate IP_PROTO in hardware filters
657 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_IP_PROTO)) {
658 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
659 efx_spec->efs_ip_proto = EFX_IPPROTO_TCP;
660 } else if (efx_spec->efs_ip_proto != EFX_IPPROTO_TCP) {
661 rte_flow_error_set(error, EINVAL,
662 RTE_FLOW_ERROR_TYPE_ITEM, item,
663 "IP proto in pattern with TCP item should be appropriate");
671 * Source and destination ports are in big-endian byte order in item and
672 * in little-endian in efx_spec, so byte swap is used
674 if (mask->hdr.src_port == supp_mask.hdr.src_port) {
675 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_PORT;
676 efx_spec->efs_rem_port = rte_bswap16(spec->hdr.src_port);
677 } else if (mask->hdr.src_port != 0) {
681 if (mask->hdr.dst_port == supp_mask.hdr.dst_port) {
682 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_PORT;
683 efx_spec->efs_loc_port = rte_bswap16(spec->hdr.dst_port);
684 } else if (mask->hdr.dst_port != 0) {
691 rte_flow_error_set(error, EINVAL,
692 RTE_FLOW_ERROR_TYPE_ITEM, item,
693 "Bad mask in the TCP pattern item");
698 * Convert UDP item to EFX filter specification.
701 * Item specification. Only source and destination ports fields
702 * are supported. If the mask is NULL, default mask will be used.
703 * Ranging is not supported.
704 * @param efx_spec[in, out]
705 * EFX filter specification to update.
707 * Perform verbose error reporting if not NULL.
710 sfc_flow_parse_udp(const struct rte_flow_item *item,
711 efx_filter_spec_t *efx_spec,
712 struct rte_flow_error *error)
715 const struct rte_flow_item_udp *spec = NULL;
716 const struct rte_flow_item_udp *mask = NULL;
717 const struct rte_flow_item_udp supp_mask = {
724 rc = sfc_flow_parse_init(item,
725 (const void **)&spec,
726 (const void **)&mask,
728 &rte_flow_item_udp_mask,
729 sizeof(struct rte_flow_item_udp),
735 * Filtering by UDP source and destination ports requires
736 * the appropriate IP_PROTO in hardware filters
738 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_IP_PROTO)) {
739 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
740 efx_spec->efs_ip_proto = EFX_IPPROTO_UDP;
741 } else if (efx_spec->efs_ip_proto != EFX_IPPROTO_UDP) {
742 rte_flow_error_set(error, EINVAL,
743 RTE_FLOW_ERROR_TYPE_ITEM, item,
744 "IP proto in pattern with UDP item should be appropriate");
752 * Source and destination ports are in big-endian byte order in item and
753 * in little-endian in efx_spec, so byte swap is used
755 if (mask->hdr.src_port == supp_mask.hdr.src_port) {
756 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_PORT;
757 efx_spec->efs_rem_port = rte_bswap16(spec->hdr.src_port);
758 } else if (mask->hdr.src_port != 0) {
762 if (mask->hdr.dst_port == supp_mask.hdr.dst_port) {
763 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_PORT;
764 efx_spec->efs_loc_port = rte_bswap16(spec->hdr.dst_port);
765 } else if (mask->hdr.dst_port != 0) {
772 rte_flow_error_set(error, EINVAL,
773 RTE_FLOW_ERROR_TYPE_ITEM, item,
774 "Bad mask in the UDP pattern item");
779 * Filters for encapsulated packets match based on the EtherType and IP
780 * protocol in the outer frame.
783 sfc_flow_set_match_flags_for_encap_pkts(const struct rte_flow_item *item,
784 efx_filter_spec_t *efx_spec,
786 struct rte_flow_error *error)
788 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_IP_PROTO)) {
789 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
790 efx_spec->efs_ip_proto = ip_proto;
791 } else if (efx_spec->efs_ip_proto != ip_proto) {
793 case EFX_IPPROTO_UDP:
794 rte_flow_error_set(error, EINVAL,
795 RTE_FLOW_ERROR_TYPE_ITEM, item,
796 "Outer IP header protocol must be UDP "
797 "in VxLAN/GENEVE pattern");
800 case EFX_IPPROTO_GRE:
801 rte_flow_error_set(error, EINVAL,
802 RTE_FLOW_ERROR_TYPE_ITEM, item,
803 "Outer IP header protocol must be GRE "
808 rte_flow_error_set(error, EINVAL,
809 RTE_FLOW_ERROR_TYPE_ITEM, item,
810 "Only VxLAN/GENEVE/NVGRE tunneling patterns "
816 if (efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
817 efx_spec->efs_ether_type != EFX_ETHER_TYPE_IPV4 &&
818 efx_spec->efs_ether_type != EFX_ETHER_TYPE_IPV6) {
819 rte_flow_error_set(error, EINVAL,
820 RTE_FLOW_ERROR_TYPE_ITEM, item,
821 "Outer frame EtherType in pattern with tunneling "
822 "must be IPv4 or IPv6");
830 sfc_flow_set_efx_spec_vni_or_vsid(efx_filter_spec_t *efx_spec,
831 const uint8_t *vni_or_vsid_val,
832 const uint8_t *vni_or_vsid_mask,
833 const struct rte_flow_item *item,
834 struct rte_flow_error *error)
836 const uint8_t vni_or_vsid_full_mask[EFX_VNI_OR_VSID_LEN] = {
840 if (memcmp(vni_or_vsid_mask, vni_or_vsid_full_mask,
841 EFX_VNI_OR_VSID_LEN) == 0) {
842 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_VNI_OR_VSID;
843 rte_memcpy(efx_spec->efs_vni_or_vsid, vni_or_vsid_val,
844 EFX_VNI_OR_VSID_LEN);
845 } else if (!sfc_flow_is_zero(vni_or_vsid_mask, EFX_VNI_OR_VSID_LEN)) {
846 rte_flow_error_set(error, EINVAL,
847 RTE_FLOW_ERROR_TYPE_ITEM, item,
848 "Unsupported VNI/VSID mask");
856 * Convert VXLAN item to EFX filter specification.
859 * Item specification. Only VXLAN network identifier field is supported.
860 * If the mask is NULL, default mask will be used.
861 * Ranging is not supported.
862 * @param efx_spec[in, out]
863 * EFX filter specification to update.
865 * Perform verbose error reporting if not NULL.
868 sfc_flow_parse_vxlan(const struct rte_flow_item *item,
869 efx_filter_spec_t *efx_spec,
870 struct rte_flow_error *error)
873 const struct rte_flow_item_vxlan *spec = NULL;
874 const struct rte_flow_item_vxlan *mask = NULL;
875 const struct rte_flow_item_vxlan supp_mask = {
876 .vni = { 0xff, 0xff, 0xff }
879 rc = sfc_flow_parse_init(item,
880 (const void **)&spec,
881 (const void **)&mask,
883 &rte_flow_item_vxlan_mask,
884 sizeof(struct rte_flow_item_vxlan),
889 rc = sfc_flow_set_match_flags_for_encap_pkts(item, efx_spec,
890 EFX_IPPROTO_UDP, error);
894 efx_spec->efs_encap_type = EFX_TUNNEL_PROTOCOL_VXLAN;
895 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
900 rc = sfc_flow_set_efx_spec_vni_or_vsid(efx_spec, spec->vni,
901 mask->vni, item, error);
907 * Convert GENEVE item to EFX filter specification.
910 * Item specification. Only Virtual Network Identifier and protocol type
911 * fields are supported. But protocol type can be only Ethernet (0x6558).
912 * If the mask is NULL, default mask will be used.
913 * Ranging is not supported.
914 * @param efx_spec[in, out]
915 * EFX filter specification to update.
917 * Perform verbose error reporting if not NULL.
920 sfc_flow_parse_geneve(const struct rte_flow_item *item,
921 efx_filter_spec_t *efx_spec,
922 struct rte_flow_error *error)
925 const struct rte_flow_item_geneve *spec = NULL;
926 const struct rte_flow_item_geneve *mask = NULL;
927 const struct rte_flow_item_geneve supp_mask = {
928 .protocol = RTE_BE16(0xffff),
929 .vni = { 0xff, 0xff, 0xff }
932 rc = sfc_flow_parse_init(item,
933 (const void **)&spec,
934 (const void **)&mask,
936 &rte_flow_item_geneve_mask,
937 sizeof(struct rte_flow_item_geneve),
942 rc = sfc_flow_set_match_flags_for_encap_pkts(item, efx_spec,
943 EFX_IPPROTO_UDP, error);
947 efx_spec->efs_encap_type = EFX_TUNNEL_PROTOCOL_GENEVE;
948 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
953 if (mask->protocol == supp_mask.protocol) {
954 if (spec->protocol != rte_cpu_to_be_16(RTE_ETHER_TYPE_TEB)) {
955 rte_flow_error_set(error, EINVAL,
956 RTE_FLOW_ERROR_TYPE_ITEM, item,
957 "GENEVE encap. protocol must be Ethernet "
958 "(0x6558) in the GENEVE pattern item");
961 } else if (mask->protocol != 0) {
962 rte_flow_error_set(error, EINVAL,
963 RTE_FLOW_ERROR_TYPE_ITEM, item,
964 "Unsupported mask for GENEVE encap. protocol");
968 rc = sfc_flow_set_efx_spec_vni_or_vsid(efx_spec, spec->vni,
969 mask->vni, item, error);
975 * Convert NVGRE item to EFX filter specification.
978 * Item specification. Only virtual subnet ID field is supported.
979 * If the mask is NULL, default mask will be used.
980 * Ranging is not supported.
981 * @param efx_spec[in, out]
982 * EFX filter specification to update.
984 * Perform verbose error reporting if not NULL.
987 sfc_flow_parse_nvgre(const struct rte_flow_item *item,
988 efx_filter_spec_t *efx_spec,
989 struct rte_flow_error *error)
992 const struct rte_flow_item_nvgre *spec = NULL;
993 const struct rte_flow_item_nvgre *mask = NULL;
994 const struct rte_flow_item_nvgre supp_mask = {
995 .tni = { 0xff, 0xff, 0xff }
998 rc = sfc_flow_parse_init(item,
999 (const void **)&spec,
1000 (const void **)&mask,
1002 &rte_flow_item_nvgre_mask,
1003 sizeof(struct rte_flow_item_nvgre),
1008 rc = sfc_flow_set_match_flags_for_encap_pkts(item, efx_spec,
1009 EFX_IPPROTO_GRE, error);
1013 efx_spec->efs_encap_type = EFX_TUNNEL_PROTOCOL_NVGRE;
1014 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
1019 rc = sfc_flow_set_efx_spec_vni_or_vsid(efx_spec, spec->tni,
1020 mask->tni, item, error);
1025 static const struct sfc_flow_item sfc_flow_items[] = {
1027 .type = RTE_FLOW_ITEM_TYPE_VOID,
1028 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
1029 .layer = SFC_FLOW_ITEM_ANY_LAYER,
1030 .parse = sfc_flow_parse_void,
1033 .type = RTE_FLOW_ITEM_TYPE_ETH,
1034 .prev_layer = SFC_FLOW_ITEM_START_LAYER,
1035 .layer = SFC_FLOW_ITEM_L2,
1036 .parse = sfc_flow_parse_eth,
1039 .type = RTE_FLOW_ITEM_TYPE_VLAN,
1040 .prev_layer = SFC_FLOW_ITEM_L2,
1041 .layer = SFC_FLOW_ITEM_L2,
1042 .parse = sfc_flow_parse_vlan,
1045 .type = RTE_FLOW_ITEM_TYPE_IPV4,
1046 .prev_layer = SFC_FLOW_ITEM_L2,
1047 .layer = SFC_FLOW_ITEM_L3,
1048 .parse = sfc_flow_parse_ipv4,
1051 .type = RTE_FLOW_ITEM_TYPE_IPV6,
1052 .prev_layer = SFC_FLOW_ITEM_L2,
1053 .layer = SFC_FLOW_ITEM_L3,
1054 .parse = sfc_flow_parse_ipv6,
1057 .type = RTE_FLOW_ITEM_TYPE_TCP,
1058 .prev_layer = SFC_FLOW_ITEM_L3,
1059 .layer = SFC_FLOW_ITEM_L4,
1060 .parse = sfc_flow_parse_tcp,
1063 .type = RTE_FLOW_ITEM_TYPE_UDP,
1064 .prev_layer = SFC_FLOW_ITEM_L3,
1065 .layer = SFC_FLOW_ITEM_L4,
1066 .parse = sfc_flow_parse_udp,
1069 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
1070 .prev_layer = SFC_FLOW_ITEM_L4,
1071 .layer = SFC_FLOW_ITEM_START_LAYER,
1072 .parse = sfc_flow_parse_vxlan,
1075 .type = RTE_FLOW_ITEM_TYPE_GENEVE,
1076 .prev_layer = SFC_FLOW_ITEM_L4,
1077 .layer = SFC_FLOW_ITEM_START_LAYER,
1078 .parse = sfc_flow_parse_geneve,
1081 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
1082 .prev_layer = SFC_FLOW_ITEM_L3,
1083 .layer = SFC_FLOW_ITEM_START_LAYER,
1084 .parse = sfc_flow_parse_nvgre,
1089 * Protocol-independent flow API support
1092 sfc_flow_parse_attr(const struct rte_flow_attr *attr,
1093 struct rte_flow *flow,
1094 struct rte_flow_error *error)
1096 struct sfc_flow_spec *spec = &flow->spec;
1097 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1100 rte_flow_error_set(error, EINVAL,
1101 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
1105 if (attr->group != 0) {
1106 rte_flow_error_set(error, ENOTSUP,
1107 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, attr,
1108 "Groups are not supported");
1111 if (attr->priority != 0) {
1112 rte_flow_error_set(error, ENOTSUP,
1113 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, attr,
1114 "Priorities are not supported");
1117 if (attr->egress != 0) {
1118 rte_flow_error_set(error, ENOTSUP,
1119 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attr,
1120 "Egress is not supported");
1123 if (attr->transfer != 0) {
1124 rte_flow_error_set(error, ENOTSUP,
1125 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER, attr,
1126 "Transfer is not supported");
1129 if (attr->ingress == 0) {
1130 rte_flow_error_set(error, ENOTSUP,
1131 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, attr,
1132 "Only ingress is supported");
1136 spec->type = SFC_FLOW_SPEC_FILTER;
1137 spec_filter->template.efs_flags |= EFX_FILTER_FLAG_RX;
1138 spec_filter->template.efs_rss_context = EFX_RSS_CONTEXT_DEFAULT;
1143 /* Get item from array sfc_flow_items */
1144 static const struct sfc_flow_item *
1145 sfc_flow_get_item(enum rte_flow_item_type type)
1149 for (i = 0; i < RTE_DIM(sfc_flow_items); i++)
1150 if (sfc_flow_items[i].type == type)
1151 return &sfc_flow_items[i];
1157 sfc_flow_parse_pattern(const struct rte_flow_item pattern[],
1158 struct rte_flow *flow,
1159 struct rte_flow_error *error)
1162 unsigned int prev_layer = SFC_FLOW_ITEM_ANY_LAYER;
1163 boolean_t is_ifrm = B_FALSE;
1164 const struct sfc_flow_item *item;
1165 struct sfc_flow_spec *spec = &flow->spec;
1166 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1168 if (pattern == NULL) {
1169 rte_flow_error_set(error, EINVAL,
1170 RTE_FLOW_ERROR_TYPE_ITEM_NUM, NULL,
1175 for (; pattern->type != RTE_FLOW_ITEM_TYPE_END; pattern++) {
1176 item = sfc_flow_get_item(pattern->type);
1178 rte_flow_error_set(error, ENOTSUP,
1179 RTE_FLOW_ERROR_TYPE_ITEM, pattern,
1180 "Unsupported pattern item");
1185 * Omitting one or several protocol layers at the beginning
1186 * of pattern is supported
1188 if (item->prev_layer != SFC_FLOW_ITEM_ANY_LAYER &&
1189 prev_layer != SFC_FLOW_ITEM_ANY_LAYER &&
1190 item->prev_layer != prev_layer) {
1191 rte_flow_error_set(error, ENOTSUP,
1192 RTE_FLOW_ERROR_TYPE_ITEM, pattern,
1193 "Unexpected sequence of pattern items");
1198 * Allow only VOID and ETH pattern items in the inner frame.
1199 * Also check that there is only one tunneling protocol.
1201 switch (item->type) {
1202 case RTE_FLOW_ITEM_TYPE_VOID:
1203 case RTE_FLOW_ITEM_TYPE_ETH:
1206 case RTE_FLOW_ITEM_TYPE_VXLAN:
1207 case RTE_FLOW_ITEM_TYPE_GENEVE:
1208 case RTE_FLOW_ITEM_TYPE_NVGRE:
1210 rte_flow_error_set(error, EINVAL,
1211 RTE_FLOW_ERROR_TYPE_ITEM,
1213 "More than one tunneling protocol");
1221 rte_flow_error_set(error, EINVAL,
1222 RTE_FLOW_ERROR_TYPE_ITEM,
1224 "There is an unsupported pattern item "
1225 "in the inner frame");
1231 rc = item->parse(pattern, &spec_filter->template, error);
1235 if (item->layer != SFC_FLOW_ITEM_ANY_LAYER)
1236 prev_layer = item->layer;
1243 sfc_flow_parse_queue(struct sfc_adapter *sa,
1244 const struct rte_flow_action_queue *queue,
1245 struct rte_flow *flow)
1247 struct sfc_flow_spec *spec = &flow->spec;
1248 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1249 struct sfc_rxq *rxq;
1251 if (queue->index >= sfc_sa2shared(sa)->rxq_count)
1254 rxq = &sa->rxq_ctrl[queue->index];
1255 spec_filter->template.efs_dmaq_id = (uint16_t)rxq->hw_index;
1261 sfc_flow_parse_rss(struct sfc_adapter *sa,
1262 const struct rte_flow_action_rss *action_rss,
1263 struct rte_flow *flow)
1265 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
1266 struct sfc_rss *rss = &sas->rss;
1267 unsigned int rxq_sw_index;
1268 struct sfc_rxq *rxq;
1269 unsigned int rxq_hw_index_min;
1270 unsigned int rxq_hw_index_max;
1271 efx_rx_hash_type_t efx_hash_types;
1272 const uint8_t *rss_key;
1273 struct sfc_flow_spec *spec = &flow->spec;
1274 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1275 struct sfc_flow_rss *sfc_rss_conf = &spec_filter->rss_conf;
1278 if (action_rss->queue_num == 0)
1281 rxq_sw_index = sfc_sa2shared(sa)->rxq_count - 1;
1282 rxq = &sa->rxq_ctrl[rxq_sw_index];
1283 rxq_hw_index_min = rxq->hw_index;
1284 rxq_hw_index_max = 0;
1286 for (i = 0; i < action_rss->queue_num; ++i) {
1287 rxq_sw_index = action_rss->queue[i];
1289 if (rxq_sw_index >= sfc_sa2shared(sa)->rxq_count)
1292 rxq = &sa->rxq_ctrl[rxq_sw_index];
1294 if (rxq->hw_index < rxq_hw_index_min)
1295 rxq_hw_index_min = rxq->hw_index;
1297 if (rxq->hw_index > rxq_hw_index_max)
1298 rxq_hw_index_max = rxq->hw_index;
1301 switch (action_rss->func) {
1302 case RTE_ETH_HASH_FUNCTION_DEFAULT:
1303 case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
1309 if (action_rss->level)
1313 * Dummy RSS action with only one queue and no specific settings
1314 * for hash types and key does not require dedicated RSS context
1315 * and may be simplified to single queue action.
1317 if (action_rss->queue_num == 1 && action_rss->types == 0 &&
1318 action_rss->key_len == 0) {
1319 spec_filter->template.efs_dmaq_id = rxq_hw_index_min;
1323 if (action_rss->types) {
1326 rc = sfc_rx_hf_rte_to_efx(sa, action_rss->types,
1334 for (i = 0; i < rss->hf_map_nb_entries; ++i)
1335 efx_hash_types |= rss->hf_map[i].efx;
1338 if (action_rss->key_len) {
1339 if (action_rss->key_len != sizeof(rss->key))
1342 rss_key = action_rss->key;
1347 spec_filter->rss = B_TRUE;
1349 sfc_rss_conf->rxq_hw_index_min = rxq_hw_index_min;
1350 sfc_rss_conf->rxq_hw_index_max = rxq_hw_index_max;
1351 sfc_rss_conf->rss_hash_types = efx_hash_types;
1352 rte_memcpy(sfc_rss_conf->rss_key, rss_key, sizeof(rss->key));
1354 for (i = 0; i < RTE_DIM(sfc_rss_conf->rss_tbl); ++i) {
1355 unsigned int nb_queues = action_rss->queue_num;
1356 unsigned int rxq_sw_index = action_rss->queue[i % nb_queues];
1357 struct sfc_rxq *rxq = &sa->rxq_ctrl[rxq_sw_index];
1359 sfc_rss_conf->rss_tbl[i] = rxq->hw_index - rxq_hw_index_min;
1366 sfc_flow_spec_flush(struct sfc_adapter *sa, struct sfc_flow_spec *spec,
1367 unsigned int filters_count)
1369 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1373 for (i = 0; i < filters_count; i++) {
1376 rc = efx_filter_remove(sa->nic, &spec_filter->filters[i]);
1377 if (ret == 0 && rc != 0) {
1378 sfc_err(sa, "failed to remove filter specification "
1388 sfc_flow_spec_insert(struct sfc_adapter *sa, struct sfc_flow_spec *spec)
1390 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1394 for (i = 0; i < spec_filter->count; i++) {
1395 rc = efx_filter_insert(sa->nic, &spec_filter->filters[i]);
1397 sfc_flow_spec_flush(sa, spec, i);
1406 sfc_flow_spec_remove(struct sfc_adapter *sa, struct sfc_flow_spec *spec)
1408 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1410 return sfc_flow_spec_flush(sa, spec, spec_filter->count);
1414 sfc_flow_filter_insert(struct sfc_adapter *sa,
1415 struct rte_flow *flow)
1417 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
1418 struct sfc_rss *rss = &sas->rss;
1419 struct sfc_flow_spec_filter *spec_filter = &flow->spec.filter;
1420 struct sfc_flow_rss *flow_rss = &spec_filter->rss_conf;
1421 uint32_t efs_rss_context = EFX_RSS_CONTEXT_DEFAULT;
1425 if (spec_filter->rss) {
1426 unsigned int rss_spread = MIN(flow_rss->rxq_hw_index_max -
1427 flow_rss->rxq_hw_index_min + 1,
1430 rc = efx_rx_scale_context_alloc(sa->nic,
1431 EFX_RX_SCALE_EXCLUSIVE,
1435 goto fail_scale_context_alloc;
1437 rc = efx_rx_scale_mode_set(sa->nic, efs_rss_context,
1439 flow_rss->rss_hash_types, B_TRUE);
1441 goto fail_scale_mode_set;
1443 rc = efx_rx_scale_key_set(sa->nic, efs_rss_context,
1447 goto fail_scale_key_set;
1450 * At this point, fully elaborated filter specifications
1451 * have been produced from the template. To make sure that
1452 * RSS behaviour is consistent between them, set the same
1453 * RSS context value everywhere.
1455 for (i = 0; i < spec_filter->count; i++) {
1456 efx_filter_spec_t *spec = &spec_filter->filters[i];
1458 spec->efs_rss_context = efs_rss_context;
1459 spec->efs_dmaq_id = flow_rss->rxq_hw_index_min;
1460 spec->efs_flags |= EFX_FILTER_FLAG_RX_RSS;
1464 rc = sfc_flow_spec_insert(sa, &flow->spec);
1466 goto fail_filter_insert;
1468 if (spec_filter->rss) {
1470 * Scale table is set after filter insertion because
1471 * the table entries are relative to the base RxQ ID
1472 * and the latter is submitted to the HW by means of
1473 * inserting a filter, so by the time of the request
1474 * the HW knows all the information needed to verify
1475 * the table entries, and the operation will succeed
1477 rc = efx_rx_scale_tbl_set(sa->nic, efs_rss_context,
1479 RTE_DIM(flow_rss->rss_tbl));
1481 goto fail_scale_tbl_set;
1487 sfc_flow_spec_remove(sa, &flow->spec);
1491 fail_scale_mode_set:
1492 if (efs_rss_context != EFX_RSS_CONTEXT_DEFAULT)
1493 efx_rx_scale_context_free(sa->nic, efs_rss_context);
1495 fail_scale_context_alloc:
1500 sfc_flow_filter_remove(struct sfc_adapter *sa,
1501 struct rte_flow *flow)
1503 struct sfc_flow_spec_filter *spec_filter = &flow->spec.filter;
1506 rc = sfc_flow_spec_remove(sa, &flow->spec);
1510 if (spec_filter->rss) {
1512 * All specifications for a given flow rule have the same RSS
1513 * context, so that RSS context value is taken from the first
1514 * filter specification
1516 efx_filter_spec_t *spec = &spec_filter->filters[0];
1518 rc = efx_rx_scale_context_free(sa->nic, spec->efs_rss_context);
1525 sfc_flow_parse_mark(struct sfc_adapter *sa,
1526 const struct rte_flow_action_mark *mark,
1527 struct rte_flow *flow)
1529 struct sfc_flow_spec *spec = &flow->spec;
1530 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1531 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
1533 if (mark == NULL || mark->id > encp->enc_filter_action_mark_max)
1536 spec_filter->template.efs_flags |= EFX_FILTER_FLAG_ACTION_MARK;
1537 spec_filter->template.efs_mark = mark->id;
1543 sfc_flow_parse_actions(struct sfc_adapter *sa,
1544 const struct rte_flow_action actions[],
1545 struct rte_flow *flow,
1546 struct rte_flow_error *error)
1549 struct sfc_flow_spec *spec = &flow->spec;
1550 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1551 const unsigned int dp_rx_features = sa->priv.dp_rx->features;
1552 uint32_t actions_set = 0;
1553 const uint32_t fate_actions_mask = (1UL << RTE_FLOW_ACTION_TYPE_QUEUE) |
1554 (1UL << RTE_FLOW_ACTION_TYPE_RSS) |
1555 (1UL << RTE_FLOW_ACTION_TYPE_DROP);
1556 const uint32_t mark_actions_mask = (1UL << RTE_FLOW_ACTION_TYPE_MARK) |
1557 (1UL << RTE_FLOW_ACTION_TYPE_FLAG);
1559 if (actions == NULL) {
1560 rte_flow_error_set(error, EINVAL,
1561 RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
1566 #define SFC_BUILD_SET_OVERFLOW(_action, _set) \
1567 RTE_BUILD_BUG_ON(_action >= sizeof(_set) * CHAR_BIT)
1569 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1570 switch (actions->type) {
1571 case RTE_FLOW_ACTION_TYPE_VOID:
1572 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VOID,
1576 case RTE_FLOW_ACTION_TYPE_QUEUE:
1577 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_QUEUE,
1579 if ((actions_set & fate_actions_mask) != 0)
1580 goto fail_fate_actions;
1582 rc = sfc_flow_parse_queue(sa, actions->conf, flow);
1584 rte_flow_error_set(error, EINVAL,
1585 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1586 "Bad QUEUE action");
1591 case RTE_FLOW_ACTION_TYPE_RSS:
1592 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_RSS,
1594 if ((actions_set & fate_actions_mask) != 0)
1595 goto fail_fate_actions;
1597 rc = sfc_flow_parse_rss(sa, actions->conf, flow);
1599 rte_flow_error_set(error, -rc,
1600 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1606 case RTE_FLOW_ACTION_TYPE_DROP:
1607 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_DROP,
1609 if ((actions_set & fate_actions_mask) != 0)
1610 goto fail_fate_actions;
1612 spec_filter->template.efs_dmaq_id =
1613 EFX_FILTER_SPEC_RX_DMAQ_ID_DROP;
1616 case RTE_FLOW_ACTION_TYPE_FLAG:
1617 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_FLAG,
1619 if ((actions_set & mark_actions_mask) != 0)
1620 goto fail_actions_overlap;
1622 if ((dp_rx_features & SFC_DP_RX_FEAT_FLOW_FLAG) == 0) {
1623 rte_flow_error_set(error, ENOTSUP,
1624 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1625 "FLAG action is not supported on the current Rx datapath");
1629 spec_filter->template.efs_flags |=
1630 EFX_FILTER_FLAG_ACTION_FLAG;
1633 case RTE_FLOW_ACTION_TYPE_MARK:
1634 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_MARK,
1636 if ((actions_set & mark_actions_mask) != 0)
1637 goto fail_actions_overlap;
1639 if ((dp_rx_features & SFC_DP_RX_FEAT_FLOW_MARK) == 0) {
1640 rte_flow_error_set(error, ENOTSUP,
1641 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1642 "MARK action is not supported on the current Rx datapath");
1646 rc = sfc_flow_parse_mark(sa, actions->conf, flow);
1648 rte_flow_error_set(error, rc,
1649 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1656 rte_flow_error_set(error, ENOTSUP,
1657 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1658 "Action is not supported");
1662 actions_set |= (1UL << actions->type);
1664 #undef SFC_BUILD_SET_OVERFLOW
1666 /* When fate is unknown, drop traffic. */
1667 if ((actions_set & fate_actions_mask) == 0) {
1668 spec_filter->template.efs_dmaq_id =
1669 EFX_FILTER_SPEC_RX_DMAQ_ID_DROP;
1675 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, actions,
1676 "Cannot combine several fate-deciding actions, "
1677 "choose between QUEUE, RSS or DROP");
1680 fail_actions_overlap:
1681 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, actions,
1682 "Overlapping actions are not supported");
1687 * Set the EFX_FILTER_MATCH_UNKNOWN_UCAST_DST
1688 * and EFX_FILTER_MATCH_UNKNOWN_MCAST_DST match flags in the same
1689 * specifications after copying.
1691 * @param spec[in, out]
1692 * SFC flow specification to update.
1693 * @param filters_count_for_one_val[in]
1694 * How many specifications should have the same match flag, what is the
1695 * number of specifications before copying.
1697 * Perform verbose error reporting if not NULL.
1700 sfc_flow_set_unknown_dst_flags(struct sfc_flow_spec *spec,
1701 unsigned int filters_count_for_one_val,
1702 struct rte_flow_error *error)
1705 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1706 static const efx_filter_match_flags_t vals[] = {
1707 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST,
1708 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST
1711 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
1712 rte_flow_error_set(error, EINVAL,
1713 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1714 "Number of specifications is incorrect while copying "
1715 "by unknown destination flags");
1719 for (i = 0; i < spec_filter->count; i++) {
1720 /* The check above ensures that divisor can't be zero here */
1721 spec_filter->filters[i].efs_match_flags |=
1722 vals[i / filters_count_for_one_val];
1729 * Check that the following conditions are met:
1730 * - the list of supported filters has a filter
1731 * with EFX_FILTER_MATCH_UNKNOWN_MCAST_DST flag instead of
1732 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST, since this filter will also
1736 * The match flags of filter.
1738 * Specification to be supplemented.
1740 * SFC filter with list of supported filters.
1743 sfc_flow_check_unknown_dst_flags(efx_filter_match_flags_t match,
1744 __rte_unused efx_filter_spec_t *spec,
1745 struct sfc_filter *filter)
1748 efx_filter_match_flags_t match_mcast_dst;
1751 (match & ~EFX_FILTER_MATCH_UNKNOWN_UCAST_DST) |
1752 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST;
1753 for (i = 0; i < filter->supported_match_num; i++) {
1754 if (match_mcast_dst == filter->supported_match[i])
1762 * Set the EFX_FILTER_MATCH_ETHER_TYPE match flag and EFX_ETHER_TYPE_IPV4 and
1763 * EFX_ETHER_TYPE_IPV6 values of the corresponding field in the same
1764 * specifications after copying.
1766 * @param spec[in, out]
1767 * SFC flow specification to update.
1768 * @param filters_count_for_one_val[in]
1769 * How many specifications should have the same EtherType value, what is the
1770 * number of specifications before copying.
1772 * Perform verbose error reporting if not NULL.
1775 sfc_flow_set_ethertypes(struct sfc_flow_spec *spec,
1776 unsigned int filters_count_for_one_val,
1777 struct rte_flow_error *error)
1780 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1781 static const uint16_t vals[] = {
1782 EFX_ETHER_TYPE_IPV4, EFX_ETHER_TYPE_IPV6
1785 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
1786 rte_flow_error_set(error, EINVAL,
1787 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1788 "Number of specifications is incorrect "
1789 "while copying by Ethertype");
1793 for (i = 0; i < spec_filter->count; i++) {
1794 spec_filter->filters[i].efs_match_flags |=
1795 EFX_FILTER_MATCH_ETHER_TYPE;
1798 * The check above ensures that
1799 * filters_count_for_one_val is not 0
1801 spec_filter->filters[i].efs_ether_type =
1802 vals[i / filters_count_for_one_val];
1809 * Set the EFX_FILTER_MATCH_OUTER_VID match flag with value 0
1810 * in the same specifications after copying.
1812 * @param spec[in, out]
1813 * SFC flow specification to update.
1814 * @param filters_count_for_one_val[in]
1815 * How many specifications should have the same match flag, what is the
1816 * number of specifications before copying.
1818 * Perform verbose error reporting if not NULL.
1821 sfc_flow_set_outer_vid_flag(struct sfc_flow_spec *spec,
1822 unsigned int filters_count_for_one_val,
1823 struct rte_flow_error *error)
1825 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1828 if (filters_count_for_one_val != spec_filter->count) {
1829 rte_flow_error_set(error, EINVAL,
1830 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1831 "Number of specifications is incorrect "
1832 "while copying by outer VLAN ID");
1836 for (i = 0; i < spec_filter->count; i++) {
1837 spec_filter->filters[i].efs_match_flags |=
1838 EFX_FILTER_MATCH_OUTER_VID;
1840 spec_filter->filters[i].efs_outer_vid = 0;
1847 * Set the EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST and
1848 * EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST match flags in the same
1849 * specifications after copying.
1851 * @param spec[in, out]
1852 * SFC flow specification to update.
1853 * @param filters_count_for_one_val[in]
1854 * How many specifications should have the same match flag, what is the
1855 * number of specifications before copying.
1857 * Perform verbose error reporting if not NULL.
1860 sfc_flow_set_ifrm_unknown_dst_flags(struct sfc_flow_spec *spec,
1861 unsigned int filters_count_for_one_val,
1862 struct rte_flow_error *error)
1865 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1866 static const efx_filter_match_flags_t vals[] = {
1867 EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST,
1868 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST
1871 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
1872 rte_flow_error_set(error, EINVAL,
1873 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1874 "Number of specifications is incorrect while copying "
1875 "by inner frame unknown destination flags");
1879 for (i = 0; i < spec_filter->count; i++) {
1880 /* The check above ensures that divisor can't be zero here */
1881 spec_filter->filters[i].efs_match_flags |=
1882 vals[i / filters_count_for_one_val];
1889 * Check that the following conditions are met:
1890 * - the specification corresponds to a filter for encapsulated traffic
1891 * - the list of supported filters has a filter
1892 * with EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST flag instead of
1893 * EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST, since this filter will also
1897 * The match flags of filter.
1899 * Specification to be supplemented.
1901 * SFC filter with list of supported filters.
1904 sfc_flow_check_ifrm_unknown_dst_flags(efx_filter_match_flags_t match,
1905 efx_filter_spec_t *spec,
1906 struct sfc_filter *filter)
1909 efx_tunnel_protocol_t encap_type = spec->efs_encap_type;
1910 efx_filter_match_flags_t match_mcast_dst;
1912 if (encap_type == EFX_TUNNEL_PROTOCOL_NONE)
1916 (match & ~EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST) |
1917 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST;
1918 for (i = 0; i < filter->supported_match_num; i++) {
1919 if (match_mcast_dst == filter->supported_match[i])
1927 * Check that the list of supported filters has a filter that differs
1928 * from @p match in that it has no flag EFX_FILTER_MATCH_OUTER_VID
1929 * in this case that filter will be used and the flag
1930 * EFX_FILTER_MATCH_OUTER_VID is not needed.
1933 * The match flags of filter.
1935 * Specification to be supplemented.
1937 * SFC filter with list of supported filters.
1940 sfc_flow_check_outer_vid_flag(efx_filter_match_flags_t match,
1941 __rte_unused efx_filter_spec_t *spec,
1942 struct sfc_filter *filter)
1945 efx_filter_match_flags_t match_without_vid =
1946 match & ~EFX_FILTER_MATCH_OUTER_VID;
1948 for (i = 0; i < filter->supported_match_num; i++) {
1949 if (match_without_vid == filter->supported_match[i])
1957 * Match flags that can be automatically added to filters.
1958 * Selecting the last minimum when searching for the copy flag ensures that the
1959 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST flag has a higher priority than
1960 * EFX_FILTER_MATCH_ETHER_TYPE. This is because the filter
1961 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST is at the end of the list of supported
1964 static const struct sfc_flow_copy_flag sfc_flow_copy_flags[] = {
1966 .flag = EFX_FILTER_MATCH_UNKNOWN_UCAST_DST,
1968 .set_vals = sfc_flow_set_unknown_dst_flags,
1969 .spec_check = sfc_flow_check_unknown_dst_flags,
1972 .flag = EFX_FILTER_MATCH_ETHER_TYPE,
1974 .set_vals = sfc_flow_set_ethertypes,
1978 .flag = EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST,
1980 .set_vals = sfc_flow_set_ifrm_unknown_dst_flags,
1981 .spec_check = sfc_flow_check_ifrm_unknown_dst_flags,
1984 .flag = EFX_FILTER_MATCH_OUTER_VID,
1986 .set_vals = sfc_flow_set_outer_vid_flag,
1987 .spec_check = sfc_flow_check_outer_vid_flag,
1991 /* Get item from array sfc_flow_copy_flags */
1992 static const struct sfc_flow_copy_flag *
1993 sfc_flow_get_copy_flag(efx_filter_match_flags_t flag)
1997 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
1998 if (sfc_flow_copy_flags[i].flag == flag)
1999 return &sfc_flow_copy_flags[i];
2006 * Make copies of the specifications, set match flag and values
2007 * of the field that corresponds to it.
2009 * @param spec[in, out]
2010 * SFC flow specification to update.
2012 * The match flag to add.
2014 * Perform verbose error reporting if not NULL.
2017 sfc_flow_spec_add_match_flag(struct sfc_flow_spec *spec,
2018 efx_filter_match_flags_t flag,
2019 struct rte_flow_error *error)
2022 unsigned int new_filters_count;
2023 unsigned int filters_count_for_one_val;
2024 const struct sfc_flow_copy_flag *copy_flag;
2025 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2028 copy_flag = sfc_flow_get_copy_flag(flag);
2029 if (copy_flag == NULL) {
2030 rte_flow_error_set(error, ENOTSUP,
2031 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2032 "Unsupported spec field for copying");
2036 new_filters_count = spec_filter->count * copy_flag->vals_count;
2037 if (new_filters_count > SF_FLOW_SPEC_NB_FILTERS_MAX) {
2038 rte_flow_error_set(error, EINVAL,
2039 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2040 "Too much EFX specifications in the flow rule");
2044 /* Copy filters specifications */
2045 for (i = spec_filter->count; i < new_filters_count; i++) {
2046 spec_filter->filters[i] =
2047 spec_filter->filters[i - spec_filter->count];
2050 filters_count_for_one_val = spec_filter->count;
2051 spec_filter->count = new_filters_count;
2053 rc = copy_flag->set_vals(spec, filters_count_for_one_val, error);
2061 * Check that the given set of match flags missing in the original filter spec
2062 * could be covered by adding spec copies which specify the corresponding
2063 * flags and packet field values to match.
2065 * @param miss_flags[in]
2066 * Flags that are missing until the supported filter.
2068 * Specification to be supplemented.
2073 * Number of specifications after copy or 0, if the flags can not be added.
2076 sfc_flow_check_missing_flags(efx_filter_match_flags_t miss_flags,
2077 efx_filter_spec_t *spec,
2078 struct sfc_filter *filter)
2081 efx_filter_match_flags_t copy_flags = 0;
2082 efx_filter_match_flags_t flag;
2083 efx_filter_match_flags_t match = spec->efs_match_flags | miss_flags;
2084 sfc_flow_spec_check *check;
2085 unsigned int multiplier = 1;
2087 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
2088 flag = sfc_flow_copy_flags[i].flag;
2089 check = sfc_flow_copy_flags[i].spec_check;
2090 if ((flag & miss_flags) == flag) {
2091 if (check != NULL && (!check(match, spec, filter)))
2095 multiplier *= sfc_flow_copy_flags[i].vals_count;
2099 if (copy_flags == miss_flags)
2106 * Attempt to supplement the specification template to the minimally
2107 * supported set of match flags. To do this, it is necessary to copy
2108 * the specifications, filling them with the values of fields that
2109 * correspond to the missing flags.
2110 * The necessary and sufficient filter is built from the fewest number
2111 * of copies which could be made to cover the minimally required set
2116 * @param spec[in, out]
2117 * SFC flow specification to update.
2119 * Perform verbose error reporting if not NULL.
2122 sfc_flow_spec_filters_complete(struct sfc_adapter *sa,
2123 struct sfc_flow_spec *spec,
2124 struct rte_flow_error *error)
2126 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2127 struct sfc_filter *filter = &sa->filter;
2128 efx_filter_match_flags_t miss_flags;
2129 efx_filter_match_flags_t min_miss_flags = 0;
2130 efx_filter_match_flags_t match;
2131 unsigned int min_multiplier = UINT_MAX;
2132 unsigned int multiplier;
2136 match = spec_filter->template.efs_match_flags;
2137 for (i = 0; i < filter->supported_match_num; i++) {
2138 if ((match & filter->supported_match[i]) == match) {
2139 miss_flags = filter->supported_match[i] & (~match);
2140 multiplier = sfc_flow_check_missing_flags(miss_flags,
2141 &spec_filter->template, filter);
2142 if (multiplier > 0) {
2143 if (multiplier <= min_multiplier) {
2144 min_multiplier = multiplier;
2145 min_miss_flags = miss_flags;
2151 if (min_multiplier == UINT_MAX) {
2152 rte_flow_error_set(error, ENOTSUP,
2153 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2154 "The flow rule pattern is unsupported");
2158 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
2159 efx_filter_match_flags_t flag = sfc_flow_copy_flags[i].flag;
2161 if ((flag & min_miss_flags) == flag) {
2162 rc = sfc_flow_spec_add_match_flag(spec, flag, error);
2172 * Check that set of match flags is referred to by a filter. Filter is
2173 * described by match flags with the ability to add OUTER_VID and INNER_VID
2176 * @param match_flags[in]
2177 * Set of match flags.
2178 * @param flags_pattern[in]
2179 * Pattern of filter match flags.
2182 sfc_flow_is_match_with_vids(efx_filter_match_flags_t match_flags,
2183 efx_filter_match_flags_t flags_pattern)
2185 if ((match_flags & flags_pattern) != flags_pattern)
2188 switch (match_flags & ~flags_pattern) {
2190 case EFX_FILTER_MATCH_OUTER_VID:
2191 case EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_INNER_VID:
2199 * Check whether the spec maps to a hardware filter which is known to be
2200 * ineffective despite being valid.
2203 * SFC filter with list of supported filters.
2205 * SFC flow specification.
2208 sfc_flow_is_match_flags_exception(struct sfc_filter *filter,
2209 struct sfc_flow_spec *spec)
2212 uint16_t ether_type;
2214 efx_filter_match_flags_t match_flags;
2215 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2217 for (i = 0; i < spec_filter->count; i++) {
2218 match_flags = spec_filter->filters[i].efs_match_flags;
2220 if (sfc_flow_is_match_with_vids(match_flags,
2221 EFX_FILTER_MATCH_ETHER_TYPE) ||
2222 sfc_flow_is_match_with_vids(match_flags,
2223 EFX_FILTER_MATCH_ETHER_TYPE |
2224 EFX_FILTER_MATCH_LOC_MAC)) {
2225 ether_type = spec_filter->filters[i].efs_ether_type;
2226 if (filter->supports_ip_proto_or_addr_filter &&
2227 (ether_type == EFX_ETHER_TYPE_IPV4 ||
2228 ether_type == EFX_ETHER_TYPE_IPV6))
2230 } else if (sfc_flow_is_match_with_vids(match_flags,
2231 EFX_FILTER_MATCH_ETHER_TYPE |
2232 EFX_FILTER_MATCH_IP_PROTO) ||
2233 sfc_flow_is_match_with_vids(match_flags,
2234 EFX_FILTER_MATCH_ETHER_TYPE |
2235 EFX_FILTER_MATCH_IP_PROTO |
2236 EFX_FILTER_MATCH_LOC_MAC)) {
2237 ip_proto = spec_filter->filters[i].efs_ip_proto;
2238 if (filter->supports_rem_or_local_port_filter &&
2239 (ip_proto == EFX_IPPROTO_TCP ||
2240 ip_proto == EFX_IPPROTO_UDP))
2249 sfc_flow_validate_match_flags(struct sfc_adapter *sa,
2250 struct rte_flow *flow,
2251 struct rte_flow_error *error)
2253 struct sfc_flow_spec *spec = &flow->spec;
2254 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2255 efx_filter_spec_t *spec_tmpl = &spec_filter->template;
2256 efx_filter_match_flags_t match_flags = spec_tmpl->efs_match_flags;
2259 /* Initialize the first filter spec with template */
2260 spec_filter->filters[0] = *spec_tmpl;
2261 spec_filter->count = 1;
2263 if (!sfc_filter_is_match_supported(sa, match_flags)) {
2264 rc = sfc_flow_spec_filters_complete(sa, &flow->spec, error);
2269 if (sfc_flow_is_match_flags_exception(&sa->filter, &flow->spec)) {
2270 rte_flow_error_set(error, ENOTSUP,
2271 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2272 "The flow rule pattern is unsupported");
2280 sfc_flow_parse(struct rte_eth_dev *dev,
2281 const struct rte_flow_attr *attr,
2282 const struct rte_flow_item pattern[],
2283 const struct rte_flow_action actions[],
2284 struct rte_flow *flow,
2285 struct rte_flow_error *error)
2287 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2290 rc = sfc_flow_parse_attr(attr, flow, error);
2292 goto fail_bad_value;
2294 rc = sfc_flow_parse_pattern(pattern, flow, error);
2296 goto fail_bad_value;
2298 rc = sfc_flow_parse_actions(sa, actions, flow, error);
2300 goto fail_bad_value;
2302 rc = sfc_flow_validate_match_flags(sa, flow, error);
2304 goto fail_bad_value;
2312 static struct rte_flow *
2313 sfc_flow_zmalloc(struct rte_flow_error *error)
2315 struct rte_flow *flow;
2317 flow = rte_zmalloc("sfc_rte_flow", sizeof(*flow), 0);
2319 rte_flow_error_set(error, ENOMEM,
2320 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2321 "Failed to allocate memory");
2328 sfc_flow_free(__rte_unused struct sfc_adapter *sa, struct rte_flow *flow)
2334 sfc_flow_validate(struct rte_eth_dev *dev,
2335 const struct rte_flow_attr *attr,
2336 const struct rte_flow_item pattern[],
2337 const struct rte_flow_action actions[],
2338 struct rte_flow_error *error)
2340 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2341 struct rte_flow *flow;
2344 flow = sfc_flow_zmalloc(error);
2348 rc = sfc_flow_parse(dev, attr, pattern, actions, flow, error);
2350 sfc_flow_free(sa, flow);
2355 static struct rte_flow *
2356 sfc_flow_create(struct rte_eth_dev *dev,
2357 const struct rte_flow_attr *attr,
2358 const struct rte_flow_item pattern[],
2359 const struct rte_flow_action actions[],
2360 struct rte_flow_error *error)
2362 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2363 struct rte_flow *flow = NULL;
2366 flow = sfc_flow_zmalloc(error);
2370 rc = sfc_flow_parse(dev, attr, pattern, actions, flow, error);
2372 goto fail_bad_value;
2374 sfc_adapter_lock(sa);
2376 TAILQ_INSERT_TAIL(&sa->flow_list, flow, entries);
2378 if (sa->state == SFC_ADAPTER_STARTED) {
2379 rc = sfc_flow_filter_insert(sa, flow);
2381 rte_flow_error_set(error, rc,
2382 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2383 "Failed to insert filter");
2384 goto fail_filter_insert;
2388 sfc_adapter_unlock(sa);
2393 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2396 sfc_flow_free(sa, flow);
2397 sfc_adapter_unlock(sa);
2404 sfc_flow_remove(struct sfc_adapter *sa,
2405 struct rte_flow *flow,
2406 struct rte_flow_error *error)
2410 SFC_ASSERT(sfc_adapter_is_locked(sa));
2412 if (sa->state == SFC_ADAPTER_STARTED) {
2413 rc = sfc_flow_filter_remove(sa, flow);
2415 rte_flow_error_set(error, rc,
2416 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2417 "Failed to destroy flow rule");
2420 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2421 sfc_flow_free(sa, flow);
2427 sfc_flow_destroy(struct rte_eth_dev *dev,
2428 struct rte_flow *flow,
2429 struct rte_flow_error *error)
2431 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2432 struct rte_flow *flow_ptr;
2435 sfc_adapter_lock(sa);
2437 TAILQ_FOREACH(flow_ptr, &sa->flow_list, entries) {
2438 if (flow_ptr == flow)
2442 rte_flow_error_set(error, rc,
2443 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
2444 "Failed to find flow rule to destroy");
2445 goto fail_bad_value;
2448 rc = sfc_flow_remove(sa, flow, error);
2451 sfc_adapter_unlock(sa);
2457 sfc_flow_flush(struct rte_eth_dev *dev,
2458 struct rte_flow_error *error)
2460 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2461 struct rte_flow *flow;
2465 sfc_adapter_lock(sa);
2467 while ((flow = TAILQ_FIRST(&sa->flow_list)) != NULL) {
2468 rc = sfc_flow_remove(sa, flow, error);
2473 sfc_adapter_unlock(sa);
2479 sfc_flow_isolate(struct rte_eth_dev *dev, int enable,
2480 struct rte_flow_error *error)
2482 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2485 sfc_adapter_lock(sa);
2486 if (sa->state != SFC_ADAPTER_INITIALIZED) {
2487 rte_flow_error_set(error, EBUSY,
2488 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2489 NULL, "please close the port first");
2492 sfc_sa2shared(sa)->isolated = (enable) ? B_TRUE : B_FALSE;
2494 sfc_adapter_unlock(sa);
2499 const struct rte_flow_ops sfc_flow_ops = {
2500 .validate = sfc_flow_validate,
2501 .create = sfc_flow_create,
2502 .destroy = sfc_flow_destroy,
2503 .flush = sfc_flow_flush,
2505 .isolate = sfc_flow_isolate,
2509 sfc_flow_init(struct sfc_adapter *sa)
2511 SFC_ASSERT(sfc_adapter_is_locked(sa));
2513 TAILQ_INIT(&sa->flow_list);
2517 sfc_flow_fini(struct sfc_adapter *sa)
2519 struct rte_flow *flow;
2521 SFC_ASSERT(sfc_adapter_is_locked(sa));
2523 while ((flow = TAILQ_FIRST(&sa->flow_list)) != NULL) {
2524 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2525 sfc_flow_free(sa, flow);
2530 sfc_flow_stop(struct sfc_adapter *sa)
2532 struct rte_flow *flow;
2534 SFC_ASSERT(sfc_adapter_is_locked(sa));
2536 TAILQ_FOREACH(flow, &sa->flow_list, entries)
2537 sfc_flow_filter_remove(sa, flow);
2541 sfc_flow_start(struct sfc_adapter *sa)
2543 struct rte_flow *flow;
2546 sfc_log_init(sa, "entry");
2548 SFC_ASSERT(sfc_adapter_is_locked(sa));
2550 TAILQ_FOREACH(flow, &sa->flow_list, entries) {
2551 rc = sfc_flow_filter_insert(sa, flow);
2556 sfc_log_init(sa, "done");