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"
27 struct sfc_flow_ops_by_spec {
28 sfc_flow_parse_cb_t *parse;
29 sfc_flow_insert_cb_t *insert;
30 sfc_flow_remove_cb_t *remove;
33 static sfc_flow_parse_cb_t sfc_flow_parse_rte_to_filter;
34 static sfc_flow_insert_cb_t sfc_flow_filter_insert;
35 static sfc_flow_remove_cb_t sfc_flow_filter_remove;
37 static const struct sfc_flow_ops_by_spec sfc_flow_ops_filter = {
38 .parse = sfc_flow_parse_rte_to_filter,
39 .insert = sfc_flow_filter_insert,
40 .remove = sfc_flow_filter_remove,
43 static const struct sfc_flow_ops_by_spec *
44 sfc_flow_get_ops_by_spec(struct rte_flow *flow)
46 struct sfc_flow_spec *spec = &flow->spec;
47 const struct sfc_flow_ops_by_spec *ops = NULL;
50 case SFC_FLOW_SPEC_FILTER:
51 ops = &sfc_flow_ops_filter;
62 * Currently, filter-based (VNIC) flow API is implemented in such a manner
63 * that each flow rule is converted to one or more hardware filters.
64 * All elements of flow rule (attributes, pattern items, actions)
65 * correspond to one or more fields in the efx_filter_spec_s structure
66 * that is responsible for the hardware filter.
67 * If some required field is unset in the flow rule, then a handful
68 * of filter copies will be created to cover all possible values
72 static sfc_flow_item_parse sfc_flow_parse_void;
73 static sfc_flow_item_parse sfc_flow_parse_eth;
74 static sfc_flow_item_parse sfc_flow_parse_vlan;
75 static sfc_flow_item_parse sfc_flow_parse_ipv4;
76 static sfc_flow_item_parse sfc_flow_parse_ipv6;
77 static sfc_flow_item_parse sfc_flow_parse_tcp;
78 static sfc_flow_item_parse sfc_flow_parse_udp;
79 static sfc_flow_item_parse sfc_flow_parse_vxlan;
80 static sfc_flow_item_parse sfc_flow_parse_geneve;
81 static sfc_flow_item_parse sfc_flow_parse_nvgre;
83 typedef int (sfc_flow_spec_set_vals)(struct sfc_flow_spec *spec,
84 unsigned int filters_count_for_one_val,
85 struct rte_flow_error *error);
87 typedef boolean_t (sfc_flow_spec_check)(efx_filter_match_flags_t match,
88 efx_filter_spec_t *spec,
89 struct sfc_filter *filter);
91 struct sfc_flow_copy_flag {
92 /* EFX filter specification match flag */
93 efx_filter_match_flags_t flag;
94 /* Number of values of corresponding field */
95 unsigned int vals_count;
96 /* Function to set values in specifications */
97 sfc_flow_spec_set_vals *set_vals;
99 * Function to check that the specification is suitable
100 * for adding this match flag
102 sfc_flow_spec_check *spec_check;
105 static sfc_flow_spec_set_vals sfc_flow_set_unknown_dst_flags;
106 static sfc_flow_spec_check sfc_flow_check_unknown_dst_flags;
107 static sfc_flow_spec_set_vals sfc_flow_set_ethertypes;
108 static sfc_flow_spec_set_vals sfc_flow_set_ifrm_unknown_dst_flags;
109 static sfc_flow_spec_check sfc_flow_check_ifrm_unknown_dst_flags;
110 static sfc_flow_spec_set_vals sfc_flow_set_outer_vid_flag;
111 static sfc_flow_spec_check sfc_flow_check_outer_vid_flag;
114 sfc_flow_is_zero(const uint8_t *buf, unsigned int size)
119 for (i = 0; i < size; i++)
122 return (sum == 0) ? B_TRUE : B_FALSE;
126 * Validate item and prepare structures spec and mask for parsing
129 sfc_flow_parse_init(const struct rte_flow_item *item,
130 const void **spec_ptr,
131 const void **mask_ptr,
132 const void *supp_mask,
133 const void *def_mask,
135 struct rte_flow_error *error)
144 rte_flow_error_set(error, EINVAL,
145 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
150 if ((item->last != NULL || item->mask != NULL) && item->spec == NULL) {
151 rte_flow_error_set(error, EINVAL,
152 RTE_FLOW_ERROR_TYPE_ITEM, item,
153 "Mask or last is set without spec");
158 * If "mask" is not set, default mask is used,
159 * but if default mask is NULL, "mask" should be set
161 if (item->mask == NULL) {
162 if (def_mask == NULL) {
163 rte_flow_error_set(error, EINVAL,
164 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
165 "Mask should be specified");
181 * If field values in "last" are either 0 or equal to the corresponding
182 * values in "spec" then they are ignored
185 !sfc_flow_is_zero(last, size) &&
186 memcmp(last, spec, size) != 0) {
187 rte_flow_error_set(error, ENOTSUP,
188 RTE_FLOW_ERROR_TYPE_ITEM, item,
189 "Ranging is not supported");
193 if (supp_mask == NULL) {
194 rte_flow_error_set(error, EINVAL,
195 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
196 "Supported mask for item should be specified");
200 /* Check that mask does not ask for more match than supp_mask */
201 for (i = 0; i < size; i++) {
202 supp = ((const uint8_t *)supp_mask)[i];
204 if (~supp & mask[i]) {
205 rte_flow_error_set(error, ENOTSUP,
206 RTE_FLOW_ERROR_TYPE_ITEM, item,
207 "Item's field is not supported");
220 * Masking is not supported, so masks in items should be either
221 * full or empty (zeroed) and set only for supported fields which
222 * are specified in the supp_mask.
226 sfc_flow_parse_void(__rte_unused const struct rte_flow_item *item,
227 __rte_unused struct sfc_flow_parse_ctx *parse_ctx,
228 __rte_unused struct rte_flow_error *error)
234 * Convert Ethernet item to EFX filter specification.
237 * Item specification. Outer frame specification may only comprise
238 * source/destination addresses and Ethertype field.
239 * Inner frame specification may contain destination address only.
240 * There is support for individual/group mask as well as for empty and full.
241 * If the mask is NULL, default mask will be used. Ranging is not supported.
242 * @param efx_spec[in, out]
243 * EFX filter specification to update.
245 * Perform verbose error reporting if not NULL.
248 sfc_flow_parse_eth(const struct rte_flow_item *item,
249 struct sfc_flow_parse_ctx *parse_ctx,
250 struct rte_flow_error *error)
253 efx_filter_spec_t *efx_spec = parse_ctx->filter;
254 const struct rte_flow_item_eth *spec = NULL;
255 const struct rte_flow_item_eth *mask = NULL;
256 const struct rte_flow_item_eth supp_mask = {
257 .dst.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
258 .src.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
261 const struct rte_flow_item_eth ifrm_supp_mask = {
262 .dst.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
264 const uint8_t ig_mask[EFX_MAC_ADDR_LEN] = {
265 0x01, 0x00, 0x00, 0x00, 0x00, 0x00
267 const struct rte_flow_item_eth *supp_mask_p;
268 const struct rte_flow_item_eth *def_mask_p;
269 uint8_t *loc_mac = NULL;
270 boolean_t is_ifrm = (efx_spec->efs_encap_type !=
271 EFX_TUNNEL_PROTOCOL_NONE);
274 supp_mask_p = &ifrm_supp_mask;
275 def_mask_p = &ifrm_supp_mask;
276 loc_mac = efx_spec->efs_ifrm_loc_mac;
278 supp_mask_p = &supp_mask;
279 def_mask_p = &rte_flow_item_eth_mask;
280 loc_mac = efx_spec->efs_loc_mac;
283 rc = sfc_flow_parse_init(item,
284 (const void **)&spec,
285 (const void **)&mask,
286 supp_mask_p, def_mask_p,
287 sizeof(struct rte_flow_item_eth),
292 /* If "spec" is not set, could be any Ethernet */
296 if (rte_is_same_ether_addr(&mask->dst, &supp_mask.dst)) {
297 efx_spec->efs_match_flags |= is_ifrm ?
298 EFX_FILTER_MATCH_IFRM_LOC_MAC :
299 EFX_FILTER_MATCH_LOC_MAC;
300 rte_memcpy(loc_mac, spec->dst.addr_bytes,
302 } else if (memcmp(mask->dst.addr_bytes, ig_mask,
303 EFX_MAC_ADDR_LEN) == 0) {
304 if (rte_is_unicast_ether_addr(&spec->dst))
305 efx_spec->efs_match_flags |= is_ifrm ?
306 EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST :
307 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST;
309 efx_spec->efs_match_flags |= is_ifrm ?
310 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST :
311 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST;
312 } else if (!rte_is_zero_ether_addr(&mask->dst)) {
317 * ifrm_supp_mask ensures that the source address and
318 * ethertype masks are equal to zero in inner frame,
319 * so these fields are filled in only for the outer frame
321 if (rte_is_same_ether_addr(&mask->src, &supp_mask.src)) {
322 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_MAC;
323 rte_memcpy(efx_spec->efs_rem_mac, spec->src.addr_bytes,
325 } else if (!rte_is_zero_ether_addr(&mask->src)) {
330 * Ether type is in big-endian byte order in item and
331 * in little-endian in efx_spec, so byte swap is used
333 if (mask->type == supp_mask.type) {
334 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
335 efx_spec->efs_ether_type = rte_bswap16(spec->type);
336 } else if (mask->type != 0) {
343 rte_flow_error_set(error, EINVAL,
344 RTE_FLOW_ERROR_TYPE_ITEM, item,
345 "Bad mask in the ETH pattern item");
350 * Convert VLAN item to EFX filter specification.
353 * Item specification. Only VID field is supported.
354 * The mask can not be NULL. Ranging is not supported.
355 * @param efx_spec[in, out]
356 * EFX filter specification to update.
358 * Perform verbose error reporting if not NULL.
361 sfc_flow_parse_vlan(const struct rte_flow_item *item,
362 struct sfc_flow_parse_ctx *parse_ctx,
363 struct rte_flow_error *error)
367 efx_filter_spec_t *efx_spec = parse_ctx->filter;
368 const struct rte_flow_item_vlan *spec = NULL;
369 const struct rte_flow_item_vlan *mask = NULL;
370 const struct rte_flow_item_vlan supp_mask = {
371 .tci = rte_cpu_to_be_16(ETH_VLAN_ID_MAX),
372 .inner_type = RTE_BE16(0xffff),
375 rc = sfc_flow_parse_init(item,
376 (const void **)&spec,
377 (const void **)&mask,
380 sizeof(struct rte_flow_item_vlan),
386 * VID is in big-endian byte order in item and
387 * in little-endian in efx_spec, so byte swap is used.
388 * If two VLAN items are included, the first matches
389 * the outer tag and the next matches the inner tag.
391 if (mask->tci == supp_mask.tci) {
392 /* Apply mask to keep VID only */
393 vid = rte_bswap16(spec->tci & mask->tci);
395 if (!(efx_spec->efs_match_flags &
396 EFX_FILTER_MATCH_OUTER_VID)) {
397 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_OUTER_VID;
398 efx_spec->efs_outer_vid = vid;
399 } else if (!(efx_spec->efs_match_flags &
400 EFX_FILTER_MATCH_INNER_VID)) {
401 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_INNER_VID;
402 efx_spec->efs_inner_vid = vid;
404 rte_flow_error_set(error, EINVAL,
405 RTE_FLOW_ERROR_TYPE_ITEM, item,
406 "More than two VLAN items");
410 rte_flow_error_set(error, EINVAL,
411 RTE_FLOW_ERROR_TYPE_ITEM, item,
412 "VLAN ID in TCI match is required");
416 if (efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE) {
417 rte_flow_error_set(error, EINVAL,
418 RTE_FLOW_ERROR_TYPE_ITEM, item,
419 "VLAN TPID matching is not supported");
422 if (mask->inner_type == supp_mask.inner_type) {
423 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
424 efx_spec->efs_ether_type = rte_bswap16(spec->inner_type);
425 } else if (mask->inner_type) {
426 rte_flow_error_set(error, EINVAL,
427 RTE_FLOW_ERROR_TYPE_ITEM, item,
428 "Bad mask for VLAN inner_type");
436 * Convert IPv4 item to EFX filter specification.
439 * Item specification. Only source and destination addresses and
440 * protocol fields are supported. If the mask is NULL, default
441 * mask will be used. Ranging is not supported.
442 * @param efx_spec[in, out]
443 * EFX filter specification to update.
445 * Perform verbose error reporting if not NULL.
448 sfc_flow_parse_ipv4(const struct rte_flow_item *item,
449 struct sfc_flow_parse_ctx *parse_ctx,
450 struct rte_flow_error *error)
453 efx_filter_spec_t *efx_spec = parse_ctx->filter;
454 const struct rte_flow_item_ipv4 *spec = NULL;
455 const struct rte_flow_item_ipv4 *mask = NULL;
456 const uint16_t ether_type_ipv4 = rte_cpu_to_le_16(EFX_ETHER_TYPE_IPV4);
457 const struct rte_flow_item_ipv4 supp_mask = {
459 .src_addr = 0xffffffff,
460 .dst_addr = 0xffffffff,
461 .next_proto_id = 0xff,
465 rc = sfc_flow_parse_init(item,
466 (const void **)&spec,
467 (const void **)&mask,
469 &rte_flow_item_ipv4_mask,
470 sizeof(struct rte_flow_item_ipv4),
476 * Filtering by IPv4 source and destination addresses requires
477 * the appropriate ETHER_TYPE in hardware filters
479 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE)) {
480 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
481 efx_spec->efs_ether_type = ether_type_ipv4;
482 } else if (efx_spec->efs_ether_type != ether_type_ipv4) {
483 rte_flow_error_set(error, EINVAL,
484 RTE_FLOW_ERROR_TYPE_ITEM, item,
485 "Ethertype in pattern with IPV4 item should be appropriate");
493 * IPv4 addresses are in big-endian byte order in item and in
496 if (mask->hdr.src_addr == supp_mask.hdr.src_addr) {
497 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_HOST;
498 efx_spec->efs_rem_host.eo_u32[0] = spec->hdr.src_addr;
499 } else if (mask->hdr.src_addr != 0) {
503 if (mask->hdr.dst_addr == supp_mask.hdr.dst_addr) {
504 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_HOST;
505 efx_spec->efs_loc_host.eo_u32[0] = spec->hdr.dst_addr;
506 } else if (mask->hdr.dst_addr != 0) {
510 if (mask->hdr.next_proto_id == supp_mask.hdr.next_proto_id) {
511 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
512 efx_spec->efs_ip_proto = spec->hdr.next_proto_id;
513 } else if (mask->hdr.next_proto_id != 0) {
520 rte_flow_error_set(error, EINVAL,
521 RTE_FLOW_ERROR_TYPE_ITEM, item,
522 "Bad mask in the IPV4 pattern item");
527 * Convert IPv6 item to EFX filter specification.
530 * Item specification. Only source and destination addresses and
531 * next header fields are supported. If the mask is NULL, default
532 * mask will be used. Ranging is not supported.
533 * @param efx_spec[in, out]
534 * EFX filter specification to update.
536 * Perform verbose error reporting if not NULL.
539 sfc_flow_parse_ipv6(const struct rte_flow_item *item,
540 struct sfc_flow_parse_ctx *parse_ctx,
541 struct rte_flow_error *error)
544 efx_filter_spec_t *efx_spec = parse_ctx->filter;
545 const struct rte_flow_item_ipv6 *spec = NULL;
546 const struct rte_flow_item_ipv6 *mask = NULL;
547 const uint16_t ether_type_ipv6 = rte_cpu_to_le_16(EFX_ETHER_TYPE_IPV6);
548 const struct rte_flow_item_ipv6 supp_mask = {
550 .src_addr = { 0xff, 0xff, 0xff, 0xff,
551 0xff, 0xff, 0xff, 0xff,
552 0xff, 0xff, 0xff, 0xff,
553 0xff, 0xff, 0xff, 0xff },
554 .dst_addr = { 0xff, 0xff, 0xff, 0xff,
555 0xff, 0xff, 0xff, 0xff,
556 0xff, 0xff, 0xff, 0xff,
557 0xff, 0xff, 0xff, 0xff },
562 rc = sfc_flow_parse_init(item,
563 (const void **)&spec,
564 (const void **)&mask,
566 &rte_flow_item_ipv6_mask,
567 sizeof(struct rte_flow_item_ipv6),
573 * Filtering by IPv6 source and destination addresses requires
574 * the appropriate ETHER_TYPE in hardware filters
576 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE)) {
577 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
578 efx_spec->efs_ether_type = ether_type_ipv6;
579 } else if (efx_spec->efs_ether_type != ether_type_ipv6) {
580 rte_flow_error_set(error, EINVAL,
581 RTE_FLOW_ERROR_TYPE_ITEM, item,
582 "Ethertype in pattern with IPV6 item should be appropriate");
590 * IPv6 addresses are in big-endian byte order in item and in
593 if (memcmp(mask->hdr.src_addr, supp_mask.hdr.src_addr,
594 sizeof(mask->hdr.src_addr)) == 0) {
595 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_HOST;
597 RTE_BUILD_BUG_ON(sizeof(efx_spec->efs_rem_host) !=
598 sizeof(spec->hdr.src_addr));
599 rte_memcpy(&efx_spec->efs_rem_host, spec->hdr.src_addr,
600 sizeof(efx_spec->efs_rem_host));
601 } else if (!sfc_flow_is_zero(mask->hdr.src_addr,
602 sizeof(mask->hdr.src_addr))) {
606 if (memcmp(mask->hdr.dst_addr, supp_mask.hdr.dst_addr,
607 sizeof(mask->hdr.dst_addr)) == 0) {
608 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_HOST;
610 RTE_BUILD_BUG_ON(sizeof(efx_spec->efs_loc_host) !=
611 sizeof(spec->hdr.dst_addr));
612 rte_memcpy(&efx_spec->efs_loc_host, spec->hdr.dst_addr,
613 sizeof(efx_spec->efs_loc_host));
614 } else if (!sfc_flow_is_zero(mask->hdr.dst_addr,
615 sizeof(mask->hdr.dst_addr))) {
619 if (mask->hdr.proto == supp_mask.hdr.proto) {
620 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
621 efx_spec->efs_ip_proto = spec->hdr.proto;
622 } else if (mask->hdr.proto != 0) {
629 rte_flow_error_set(error, EINVAL,
630 RTE_FLOW_ERROR_TYPE_ITEM, item,
631 "Bad mask in the IPV6 pattern item");
636 * Convert TCP item to EFX filter specification.
639 * Item specification. Only source and destination ports fields
640 * are supported. If the mask is NULL, default mask will be used.
641 * Ranging is not supported.
642 * @param efx_spec[in, out]
643 * EFX filter specification to update.
645 * Perform verbose error reporting if not NULL.
648 sfc_flow_parse_tcp(const struct rte_flow_item *item,
649 struct sfc_flow_parse_ctx *parse_ctx,
650 struct rte_flow_error *error)
653 efx_filter_spec_t *efx_spec = parse_ctx->filter;
654 const struct rte_flow_item_tcp *spec = NULL;
655 const struct rte_flow_item_tcp *mask = NULL;
656 const struct rte_flow_item_tcp supp_mask = {
663 rc = sfc_flow_parse_init(item,
664 (const void **)&spec,
665 (const void **)&mask,
667 &rte_flow_item_tcp_mask,
668 sizeof(struct rte_flow_item_tcp),
674 * Filtering by TCP source and destination ports requires
675 * the appropriate IP_PROTO in hardware filters
677 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_IP_PROTO)) {
678 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
679 efx_spec->efs_ip_proto = EFX_IPPROTO_TCP;
680 } else if (efx_spec->efs_ip_proto != EFX_IPPROTO_TCP) {
681 rte_flow_error_set(error, EINVAL,
682 RTE_FLOW_ERROR_TYPE_ITEM, item,
683 "IP proto in pattern with TCP item should be appropriate");
691 * Source and destination ports are in big-endian byte order in item and
692 * in little-endian in efx_spec, so byte swap is used
694 if (mask->hdr.src_port == supp_mask.hdr.src_port) {
695 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_PORT;
696 efx_spec->efs_rem_port = rte_bswap16(spec->hdr.src_port);
697 } else if (mask->hdr.src_port != 0) {
701 if (mask->hdr.dst_port == supp_mask.hdr.dst_port) {
702 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_PORT;
703 efx_spec->efs_loc_port = rte_bswap16(spec->hdr.dst_port);
704 } else if (mask->hdr.dst_port != 0) {
711 rte_flow_error_set(error, EINVAL,
712 RTE_FLOW_ERROR_TYPE_ITEM, item,
713 "Bad mask in the TCP pattern item");
718 * Convert UDP item to EFX filter specification.
721 * Item specification. Only source and destination ports fields
722 * are supported. If the mask is NULL, default mask will be used.
723 * Ranging is not supported.
724 * @param efx_spec[in, out]
725 * EFX filter specification to update.
727 * Perform verbose error reporting if not NULL.
730 sfc_flow_parse_udp(const struct rte_flow_item *item,
731 struct sfc_flow_parse_ctx *parse_ctx,
732 struct rte_flow_error *error)
735 efx_filter_spec_t *efx_spec = parse_ctx->filter;
736 const struct rte_flow_item_udp *spec = NULL;
737 const struct rte_flow_item_udp *mask = NULL;
738 const struct rte_flow_item_udp supp_mask = {
745 rc = sfc_flow_parse_init(item,
746 (const void **)&spec,
747 (const void **)&mask,
749 &rte_flow_item_udp_mask,
750 sizeof(struct rte_flow_item_udp),
756 * Filtering by UDP source and destination ports requires
757 * the appropriate IP_PROTO in hardware filters
759 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_IP_PROTO)) {
760 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
761 efx_spec->efs_ip_proto = EFX_IPPROTO_UDP;
762 } else if (efx_spec->efs_ip_proto != EFX_IPPROTO_UDP) {
763 rte_flow_error_set(error, EINVAL,
764 RTE_FLOW_ERROR_TYPE_ITEM, item,
765 "IP proto in pattern with UDP item should be appropriate");
773 * Source and destination ports are in big-endian byte order in item and
774 * in little-endian in efx_spec, so byte swap is used
776 if (mask->hdr.src_port == supp_mask.hdr.src_port) {
777 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_PORT;
778 efx_spec->efs_rem_port = rte_bswap16(spec->hdr.src_port);
779 } else if (mask->hdr.src_port != 0) {
783 if (mask->hdr.dst_port == supp_mask.hdr.dst_port) {
784 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_PORT;
785 efx_spec->efs_loc_port = rte_bswap16(spec->hdr.dst_port);
786 } else if (mask->hdr.dst_port != 0) {
793 rte_flow_error_set(error, EINVAL,
794 RTE_FLOW_ERROR_TYPE_ITEM, item,
795 "Bad mask in the UDP pattern item");
800 * Filters for encapsulated packets match based on the EtherType and IP
801 * protocol in the outer frame.
804 sfc_flow_set_match_flags_for_encap_pkts(const struct rte_flow_item *item,
805 efx_filter_spec_t *efx_spec,
807 struct rte_flow_error *error)
809 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_IP_PROTO)) {
810 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
811 efx_spec->efs_ip_proto = ip_proto;
812 } else if (efx_spec->efs_ip_proto != ip_proto) {
814 case EFX_IPPROTO_UDP:
815 rte_flow_error_set(error, EINVAL,
816 RTE_FLOW_ERROR_TYPE_ITEM, item,
817 "Outer IP header protocol must be UDP "
818 "in VxLAN/GENEVE pattern");
821 case EFX_IPPROTO_GRE:
822 rte_flow_error_set(error, EINVAL,
823 RTE_FLOW_ERROR_TYPE_ITEM, item,
824 "Outer IP header protocol must be GRE "
829 rte_flow_error_set(error, EINVAL,
830 RTE_FLOW_ERROR_TYPE_ITEM, item,
831 "Only VxLAN/GENEVE/NVGRE tunneling patterns "
837 if (efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
838 efx_spec->efs_ether_type != EFX_ETHER_TYPE_IPV4 &&
839 efx_spec->efs_ether_type != EFX_ETHER_TYPE_IPV6) {
840 rte_flow_error_set(error, EINVAL,
841 RTE_FLOW_ERROR_TYPE_ITEM, item,
842 "Outer frame EtherType in pattern with tunneling "
843 "must be IPv4 or IPv6");
851 sfc_flow_set_efx_spec_vni_or_vsid(efx_filter_spec_t *efx_spec,
852 const uint8_t *vni_or_vsid_val,
853 const uint8_t *vni_or_vsid_mask,
854 const struct rte_flow_item *item,
855 struct rte_flow_error *error)
857 const uint8_t vni_or_vsid_full_mask[EFX_VNI_OR_VSID_LEN] = {
861 if (memcmp(vni_or_vsid_mask, vni_or_vsid_full_mask,
862 EFX_VNI_OR_VSID_LEN) == 0) {
863 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_VNI_OR_VSID;
864 rte_memcpy(efx_spec->efs_vni_or_vsid, vni_or_vsid_val,
865 EFX_VNI_OR_VSID_LEN);
866 } else if (!sfc_flow_is_zero(vni_or_vsid_mask, EFX_VNI_OR_VSID_LEN)) {
867 rte_flow_error_set(error, EINVAL,
868 RTE_FLOW_ERROR_TYPE_ITEM, item,
869 "Unsupported VNI/VSID mask");
877 * Convert VXLAN item to EFX filter specification.
880 * Item specification. Only VXLAN network identifier field is supported.
881 * If the mask is NULL, default mask will be used.
882 * Ranging is not supported.
883 * @param efx_spec[in, out]
884 * EFX filter specification to update.
886 * Perform verbose error reporting if not NULL.
889 sfc_flow_parse_vxlan(const struct rte_flow_item *item,
890 struct sfc_flow_parse_ctx *parse_ctx,
891 struct rte_flow_error *error)
894 efx_filter_spec_t *efx_spec = parse_ctx->filter;
895 const struct rte_flow_item_vxlan *spec = NULL;
896 const struct rte_flow_item_vxlan *mask = NULL;
897 const struct rte_flow_item_vxlan supp_mask = {
898 .vni = { 0xff, 0xff, 0xff }
901 rc = sfc_flow_parse_init(item,
902 (const void **)&spec,
903 (const void **)&mask,
905 &rte_flow_item_vxlan_mask,
906 sizeof(struct rte_flow_item_vxlan),
911 rc = sfc_flow_set_match_flags_for_encap_pkts(item, efx_spec,
912 EFX_IPPROTO_UDP, error);
916 efx_spec->efs_encap_type = EFX_TUNNEL_PROTOCOL_VXLAN;
917 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
922 rc = sfc_flow_set_efx_spec_vni_or_vsid(efx_spec, spec->vni,
923 mask->vni, item, error);
929 * Convert GENEVE item to EFX filter specification.
932 * Item specification. Only Virtual Network Identifier and protocol type
933 * fields are supported. But protocol type can be only Ethernet (0x6558).
934 * If the mask is NULL, default mask will be used.
935 * Ranging is not supported.
936 * @param efx_spec[in, out]
937 * EFX filter specification to update.
939 * Perform verbose error reporting if not NULL.
942 sfc_flow_parse_geneve(const struct rte_flow_item *item,
943 struct sfc_flow_parse_ctx *parse_ctx,
944 struct rte_flow_error *error)
947 efx_filter_spec_t *efx_spec = parse_ctx->filter;
948 const struct rte_flow_item_geneve *spec = NULL;
949 const struct rte_flow_item_geneve *mask = NULL;
950 const struct rte_flow_item_geneve supp_mask = {
951 .protocol = RTE_BE16(0xffff),
952 .vni = { 0xff, 0xff, 0xff }
955 rc = sfc_flow_parse_init(item,
956 (const void **)&spec,
957 (const void **)&mask,
959 &rte_flow_item_geneve_mask,
960 sizeof(struct rte_flow_item_geneve),
965 rc = sfc_flow_set_match_flags_for_encap_pkts(item, efx_spec,
966 EFX_IPPROTO_UDP, error);
970 efx_spec->efs_encap_type = EFX_TUNNEL_PROTOCOL_GENEVE;
971 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
976 if (mask->protocol == supp_mask.protocol) {
977 if (spec->protocol != rte_cpu_to_be_16(RTE_ETHER_TYPE_TEB)) {
978 rte_flow_error_set(error, EINVAL,
979 RTE_FLOW_ERROR_TYPE_ITEM, item,
980 "GENEVE encap. protocol must be Ethernet "
981 "(0x6558) in the GENEVE pattern item");
984 } else if (mask->protocol != 0) {
985 rte_flow_error_set(error, EINVAL,
986 RTE_FLOW_ERROR_TYPE_ITEM, item,
987 "Unsupported mask for GENEVE encap. protocol");
991 rc = sfc_flow_set_efx_spec_vni_or_vsid(efx_spec, spec->vni,
992 mask->vni, item, error);
998 * Convert NVGRE item to EFX filter specification.
1001 * Item specification. Only virtual subnet ID field is supported.
1002 * If the mask is NULL, default mask will be used.
1003 * Ranging is not supported.
1004 * @param efx_spec[in, out]
1005 * EFX filter specification to update.
1007 * Perform verbose error reporting if not NULL.
1010 sfc_flow_parse_nvgre(const struct rte_flow_item *item,
1011 struct sfc_flow_parse_ctx *parse_ctx,
1012 struct rte_flow_error *error)
1015 efx_filter_spec_t *efx_spec = parse_ctx->filter;
1016 const struct rte_flow_item_nvgre *spec = NULL;
1017 const struct rte_flow_item_nvgre *mask = NULL;
1018 const struct rte_flow_item_nvgre supp_mask = {
1019 .tni = { 0xff, 0xff, 0xff }
1022 rc = sfc_flow_parse_init(item,
1023 (const void **)&spec,
1024 (const void **)&mask,
1026 &rte_flow_item_nvgre_mask,
1027 sizeof(struct rte_flow_item_nvgre),
1032 rc = sfc_flow_set_match_flags_for_encap_pkts(item, efx_spec,
1033 EFX_IPPROTO_GRE, error);
1037 efx_spec->efs_encap_type = EFX_TUNNEL_PROTOCOL_NVGRE;
1038 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
1043 rc = sfc_flow_set_efx_spec_vni_or_vsid(efx_spec, spec->tni,
1044 mask->tni, item, error);
1049 static const struct sfc_flow_item sfc_flow_items[] = {
1051 .type = RTE_FLOW_ITEM_TYPE_VOID,
1052 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
1053 .layer = SFC_FLOW_ITEM_ANY_LAYER,
1054 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1055 .parse = sfc_flow_parse_void,
1058 .type = RTE_FLOW_ITEM_TYPE_ETH,
1059 .prev_layer = SFC_FLOW_ITEM_START_LAYER,
1060 .layer = SFC_FLOW_ITEM_L2,
1061 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1062 .parse = sfc_flow_parse_eth,
1065 .type = RTE_FLOW_ITEM_TYPE_VLAN,
1066 .prev_layer = SFC_FLOW_ITEM_L2,
1067 .layer = SFC_FLOW_ITEM_L2,
1068 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1069 .parse = sfc_flow_parse_vlan,
1072 .type = RTE_FLOW_ITEM_TYPE_IPV4,
1073 .prev_layer = SFC_FLOW_ITEM_L2,
1074 .layer = SFC_FLOW_ITEM_L3,
1075 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1076 .parse = sfc_flow_parse_ipv4,
1079 .type = RTE_FLOW_ITEM_TYPE_IPV6,
1080 .prev_layer = SFC_FLOW_ITEM_L2,
1081 .layer = SFC_FLOW_ITEM_L3,
1082 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1083 .parse = sfc_flow_parse_ipv6,
1086 .type = RTE_FLOW_ITEM_TYPE_TCP,
1087 .prev_layer = SFC_FLOW_ITEM_L3,
1088 .layer = SFC_FLOW_ITEM_L4,
1089 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1090 .parse = sfc_flow_parse_tcp,
1093 .type = RTE_FLOW_ITEM_TYPE_UDP,
1094 .prev_layer = SFC_FLOW_ITEM_L3,
1095 .layer = SFC_FLOW_ITEM_L4,
1096 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1097 .parse = sfc_flow_parse_udp,
1100 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
1101 .prev_layer = SFC_FLOW_ITEM_L4,
1102 .layer = SFC_FLOW_ITEM_START_LAYER,
1103 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1104 .parse = sfc_flow_parse_vxlan,
1107 .type = RTE_FLOW_ITEM_TYPE_GENEVE,
1108 .prev_layer = SFC_FLOW_ITEM_L4,
1109 .layer = SFC_FLOW_ITEM_START_LAYER,
1110 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1111 .parse = sfc_flow_parse_geneve,
1114 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
1115 .prev_layer = SFC_FLOW_ITEM_L3,
1116 .layer = SFC_FLOW_ITEM_START_LAYER,
1117 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1118 .parse = sfc_flow_parse_nvgre,
1123 * Protocol-independent flow API support
1126 sfc_flow_parse_attr(const struct rte_flow_attr *attr,
1127 struct rte_flow *flow,
1128 struct rte_flow_error *error)
1130 struct sfc_flow_spec *spec = &flow->spec;
1131 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1134 rte_flow_error_set(error, EINVAL,
1135 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
1139 if (attr->group != 0) {
1140 rte_flow_error_set(error, ENOTSUP,
1141 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, attr,
1142 "Groups are not supported");
1145 if (attr->egress != 0) {
1146 rte_flow_error_set(error, ENOTSUP,
1147 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attr,
1148 "Egress is not supported");
1151 if (attr->ingress == 0) {
1152 rte_flow_error_set(error, ENOTSUP,
1153 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, attr,
1154 "Ingress is compulsory");
1157 if (attr->transfer == 0) {
1158 if (attr->priority != 0) {
1159 rte_flow_error_set(error, ENOTSUP,
1160 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1161 attr, "Priorities are unsupported");
1164 spec->type = SFC_FLOW_SPEC_FILTER;
1165 spec_filter->template.efs_flags |= EFX_FILTER_FLAG_RX;
1166 spec_filter->template.efs_rss_context = EFX_RSS_CONTEXT_DEFAULT;
1168 rte_flow_error_set(error, ENOTSUP,
1169 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER, attr,
1170 "Transfer is not supported");
1177 /* Get item from array sfc_flow_items */
1178 static const struct sfc_flow_item *
1179 sfc_flow_get_item(const struct sfc_flow_item *items,
1180 unsigned int nb_items,
1181 enum rte_flow_item_type type)
1185 for (i = 0; i < nb_items; i++)
1186 if (items[i].type == type)
1193 sfc_flow_parse_pattern(const struct sfc_flow_item *flow_items,
1194 unsigned int nb_flow_items,
1195 const struct rte_flow_item pattern[],
1196 struct sfc_flow_parse_ctx *parse_ctx,
1197 struct rte_flow_error *error)
1200 unsigned int prev_layer = SFC_FLOW_ITEM_ANY_LAYER;
1201 boolean_t is_ifrm = B_FALSE;
1202 const struct sfc_flow_item *item;
1204 if (pattern == NULL) {
1205 rte_flow_error_set(error, EINVAL,
1206 RTE_FLOW_ERROR_TYPE_ITEM_NUM, NULL,
1211 for (; pattern->type != RTE_FLOW_ITEM_TYPE_END; pattern++) {
1212 item = sfc_flow_get_item(flow_items, nb_flow_items,
1215 rte_flow_error_set(error, ENOTSUP,
1216 RTE_FLOW_ERROR_TYPE_ITEM, pattern,
1217 "Unsupported pattern item");
1222 * Omitting one or several protocol layers at the beginning
1223 * of pattern is supported
1225 if (item->prev_layer != SFC_FLOW_ITEM_ANY_LAYER &&
1226 prev_layer != SFC_FLOW_ITEM_ANY_LAYER &&
1227 item->prev_layer != prev_layer) {
1228 rte_flow_error_set(error, ENOTSUP,
1229 RTE_FLOW_ERROR_TYPE_ITEM, pattern,
1230 "Unexpected sequence of pattern items");
1235 * Allow only VOID and ETH pattern items in the inner frame.
1236 * Also check that there is only one tunneling protocol.
1238 switch (item->type) {
1239 case RTE_FLOW_ITEM_TYPE_VOID:
1240 case RTE_FLOW_ITEM_TYPE_ETH:
1243 case RTE_FLOW_ITEM_TYPE_VXLAN:
1244 case RTE_FLOW_ITEM_TYPE_GENEVE:
1245 case RTE_FLOW_ITEM_TYPE_NVGRE:
1247 rte_flow_error_set(error, EINVAL,
1248 RTE_FLOW_ERROR_TYPE_ITEM,
1250 "More than one tunneling protocol");
1258 rte_flow_error_set(error, EINVAL,
1259 RTE_FLOW_ERROR_TYPE_ITEM,
1261 "There is an unsupported pattern item "
1262 "in the inner frame");
1268 if (parse_ctx->type != item->ctx_type) {
1269 rte_flow_error_set(error, EINVAL,
1270 RTE_FLOW_ERROR_TYPE_ITEM, pattern,
1271 "Parse context type mismatch");
1275 rc = item->parse(pattern, parse_ctx, error);
1279 if (item->layer != SFC_FLOW_ITEM_ANY_LAYER)
1280 prev_layer = item->layer;
1287 sfc_flow_parse_queue(struct sfc_adapter *sa,
1288 const struct rte_flow_action_queue *queue,
1289 struct rte_flow *flow)
1291 struct sfc_flow_spec *spec = &flow->spec;
1292 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1293 struct sfc_rxq *rxq;
1295 if (queue->index >= sfc_sa2shared(sa)->rxq_count)
1298 rxq = &sa->rxq_ctrl[queue->index];
1299 spec_filter->template.efs_dmaq_id = (uint16_t)rxq->hw_index;
1305 sfc_flow_parse_rss(struct sfc_adapter *sa,
1306 const struct rte_flow_action_rss *action_rss,
1307 struct rte_flow *flow)
1309 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
1310 struct sfc_rss *rss = &sas->rss;
1311 unsigned int rxq_sw_index;
1312 struct sfc_rxq *rxq;
1313 unsigned int rxq_hw_index_min;
1314 unsigned int rxq_hw_index_max;
1315 efx_rx_hash_type_t efx_hash_types;
1316 const uint8_t *rss_key;
1317 struct sfc_flow_spec *spec = &flow->spec;
1318 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1319 struct sfc_flow_rss *sfc_rss_conf = &spec_filter->rss_conf;
1322 if (action_rss->queue_num == 0)
1325 rxq_sw_index = sfc_sa2shared(sa)->rxq_count - 1;
1326 rxq = &sa->rxq_ctrl[rxq_sw_index];
1327 rxq_hw_index_min = rxq->hw_index;
1328 rxq_hw_index_max = 0;
1330 for (i = 0; i < action_rss->queue_num; ++i) {
1331 rxq_sw_index = action_rss->queue[i];
1333 if (rxq_sw_index >= sfc_sa2shared(sa)->rxq_count)
1336 rxq = &sa->rxq_ctrl[rxq_sw_index];
1338 if (rxq->hw_index < rxq_hw_index_min)
1339 rxq_hw_index_min = rxq->hw_index;
1341 if (rxq->hw_index > rxq_hw_index_max)
1342 rxq_hw_index_max = rxq->hw_index;
1345 switch (action_rss->func) {
1346 case RTE_ETH_HASH_FUNCTION_DEFAULT:
1347 case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
1353 if (action_rss->level)
1357 * Dummy RSS action with only one queue and no specific settings
1358 * for hash types and key does not require dedicated RSS context
1359 * and may be simplified to single queue action.
1361 if (action_rss->queue_num == 1 && action_rss->types == 0 &&
1362 action_rss->key_len == 0) {
1363 spec_filter->template.efs_dmaq_id = rxq_hw_index_min;
1367 if (action_rss->types) {
1370 rc = sfc_rx_hf_rte_to_efx(sa, action_rss->types,
1378 for (i = 0; i < rss->hf_map_nb_entries; ++i)
1379 efx_hash_types |= rss->hf_map[i].efx;
1382 if (action_rss->key_len) {
1383 if (action_rss->key_len != sizeof(rss->key))
1386 rss_key = action_rss->key;
1391 spec_filter->rss = B_TRUE;
1393 sfc_rss_conf->rxq_hw_index_min = rxq_hw_index_min;
1394 sfc_rss_conf->rxq_hw_index_max = rxq_hw_index_max;
1395 sfc_rss_conf->rss_hash_types = efx_hash_types;
1396 rte_memcpy(sfc_rss_conf->rss_key, rss_key, sizeof(rss->key));
1398 for (i = 0; i < RTE_DIM(sfc_rss_conf->rss_tbl); ++i) {
1399 unsigned int nb_queues = action_rss->queue_num;
1400 unsigned int rxq_sw_index = action_rss->queue[i % nb_queues];
1401 struct sfc_rxq *rxq = &sa->rxq_ctrl[rxq_sw_index];
1403 sfc_rss_conf->rss_tbl[i] = rxq->hw_index - rxq_hw_index_min;
1410 sfc_flow_spec_flush(struct sfc_adapter *sa, struct sfc_flow_spec *spec,
1411 unsigned int filters_count)
1413 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1417 for (i = 0; i < filters_count; i++) {
1420 rc = efx_filter_remove(sa->nic, &spec_filter->filters[i]);
1421 if (ret == 0 && rc != 0) {
1422 sfc_err(sa, "failed to remove filter specification "
1432 sfc_flow_spec_insert(struct sfc_adapter *sa, struct sfc_flow_spec *spec)
1434 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1438 for (i = 0; i < spec_filter->count; i++) {
1439 rc = efx_filter_insert(sa->nic, &spec_filter->filters[i]);
1441 sfc_flow_spec_flush(sa, spec, i);
1450 sfc_flow_spec_remove(struct sfc_adapter *sa, struct sfc_flow_spec *spec)
1452 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1454 return sfc_flow_spec_flush(sa, spec, spec_filter->count);
1458 sfc_flow_filter_insert(struct sfc_adapter *sa,
1459 struct rte_flow *flow)
1461 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
1462 struct sfc_rss *rss = &sas->rss;
1463 struct sfc_flow_spec_filter *spec_filter = &flow->spec.filter;
1464 struct sfc_flow_rss *flow_rss = &spec_filter->rss_conf;
1465 uint32_t efs_rss_context = EFX_RSS_CONTEXT_DEFAULT;
1469 if (spec_filter->rss) {
1470 unsigned int rss_spread = MIN(flow_rss->rxq_hw_index_max -
1471 flow_rss->rxq_hw_index_min + 1,
1474 rc = efx_rx_scale_context_alloc(sa->nic,
1475 EFX_RX_SCALE_EXCLUSIVE,
1479 goto fail_scale_context_alloc;
1481 rc = efx_rx_scale_mode_set(sa->nic, efs_rss_context,
1483 flow_rss->rss_hash_types, B_TRUE);
1485 goto fail_scale_mode_set;
1487 rc = efx_rx_scale_key_set(sa->nic, efs_rss_context,
1491 goto fail_scale_key_set;
1494 * At this point, fully elaborated filter specifications
1495 * have been produced from the template. To make sure that
1496 * RSS behaviour is consistent between them, set the same
1497 * RSS context value everywhere.
1499 for (i = 0; i < spec_filter->count; i++) {
1500 efx_filter_spec_t *spec = &spec_filter->filters[i];
1502 spec->efs_rss_context = efs_rss_context;
1503 spec->efs_dmaq_id = flow_rss->rxq_hw_index_min;
1504 spec->efs_flags |= EFX_FILTER_FLAG_RX_RSS;
1508 rc = sfc_flow_spec_insert(sa, &flow->spec);
1510 goto fail_filter_insert;
1512 if (spec_filter->rss) {
1514 * Scale table is set after filter insertion because
1515 * the table entries are relative to the base RxQ ID
1516 * and the latter is submitted to the HW by means of
1517 * inserting a filter, so by the time of the request
1518 * the HW knows all the information needed to verify
1519 * the table entries, and the operation will succeed
1521 rc = efx_rx_scale_tbl_set(sa->nic, efs_rss_context,
1523 RTE_DIM(flow_rss->rss_tbl));
1525 goto fail_scale_tbl_set;
1531 sfc_flow_spec_remove(sa, &flow->spec);
1535 fail_scale_mode_set:
1536 if (efs_rss_context != EFX_RSS_CONTEXT_DEFAULT)
1537 efx_rx_scale_context_free(sa->nic, efs_rss_context);
1539 fail_scale_context_alloc:
1544 sfc_flow_filter_remove(struct sfc_adapter *sa,
1545 struct rte_flow *flow)
1547 struct sfc_flow_spec_filter *spec_filter = &flow->spec.filter;
1550 rc = sfc_flow_spec_remove(sa, &flow->spec);
1554 if (spec_filter->rss) {
1556 * All specifications for a given flow rule have the same RSS
1557 * context, so that RSS context value is taken from the first
1558 * filter specification
1560 efx_filter_spec_t *spec = &spec_filter->filters[0];
1562 rc = efx_rx_scale_context_free(sa->nic, spec->efs_rss_context);
1569 sfc_flow_parse_mark(struct sfc_adapter *sa,
1570 const struct rte_flow_action_mark *mark,
1571 struct rte_flow *flow)
1573 struct sfc_flow_spec *spec = &flow->spec;
1574 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1575 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
1577 if (mark == NULL || mark->id > encp->enc_filter_action_mark_max)
1580 spec_filter->template.efs_flags |= EFX_FILTER_FLAG_ACTION_MARK;
1581 spec_filter->template.efs_mark = mark->id;
1587 sfc_flow_parse_actions(struct sfc_adapter *sa,
1588 const struct rte_flow_action actions[],
1589 struct rte_flow *flow,
1590 struct rte_flow_error *error)
1593 struct sfc_flow_spec *spec = &flow->spec;
1594 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1595 const unsigned int dp_rx_features = sa->priv.dp_rx->features;
1596 uint32_t actions_set = 0;
1597 const uint32_t fate_actions_mask = (1UL << RTE_FLOW_ACTION_TYPE_QUEUE) |
1598 (1UL << RTE_FLOW_ACTION_TYPE_RSS) |
1599 (1UL << RTE_FLOW_ACTION_TYPE_DROP);
1600 const uint32_t mark_actions_mask = (1UL << RTE_FLOW_ACTION_TYPE_MARK) |
1601 (1UL << RTE_FLOW_ACTION_TYPE_FLAG);
1603 if (actions == NULL) {
1604 rte_flow_error_set(error, EINVAL,
1605 RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
1610 #define SFC_BUILD_SET_OVERFLOW(_action, _set) \
1611 RTE_BUILD_BUG_ON(_action >= sizeof(_set) * CHAR_BIT)
1613 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1614 switch (actions->type) {
1615 case RTE_FLOW_ACTION_TYPE_VOID:
1616 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VOID,
1620 case RTE_FLOW_ACTION_TYPE_QUEUE:
1621 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_QUEUE,
1623 if ((actions_set & fate_actions_mask) != 0)
1624 goto fail_fate_actions;
1626 rc = sfc_flow_parse_queue(sa, actions->conf, flow);
1628 rte_flow_error_set(error, EINVAL,
1629 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1630 "Bad QUEUE action");
1635 case RTE_FLOW_ACTION_TYPE_RSS:
1636 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_RSS,
1638 if ((actions_set & fate_actions_mask) != 0)
1639 goto fail_fate_actions;
1641 rc = sfc_flow_parse_rss(sa, actions->conf, flow);
1643 rte_flow_error_set(error, -rc,
1644 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1650 case RTE_FLOW_ACTION_TYPE_DROP:
1651 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_DROP,
1653 if ((actions_set & fate_actions_mask) != 0)
1654 goto fail_fate_actions;
1656 spec_filter->template.efs_dmaq_id =
1657 EFX_FILTER_SPEC_RX_DMAQ_ID_DROP;
1660 case RTE_FLOW_ACTION_TYPE_FLAG:
1661 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_FLAG,
1663 if ((actions_set & mark_actions_mask) != 0)
1664 goto fail_actions_overlap;
1666 if ((dp_rx_features & SFC_DP_RX_FEAT_FLOW_FLAG) == 0) {
1667 rte_flow_error_set(error, ENOTSUP,
1668 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1669 "FLAG action is not supported on the current Rx datapath");
1673 spec_filter->template.efs_flags |=
1674 EFX_FILTER_FLAG_ACTION_FLAG;
1677 case RTE_FLOW_ACTION_TYPE_MARK:
1678 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_MARK,
1680 if ((actions_set & mark_actions_mask) != 0)
1681 goto fail_actions_overlap;
1683 if ((dp_rx_features & SFC_DP_RX_FEAT_FLOW_MARK) == 0) {
1684 rte_flow_error_set(error, ENOTSUP,
1685 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1686 "MARK action is not supported on the current Rx datapath");
1690 rc = sfc_flow_parse_mark(sa, actions->conf, flow);
1692 rte_flow_error_set(error, rc,
1693 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1700 rte_flow_error_set(error, ENOTSUP,
1701 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1702 "Action is not supported");
1706 actions_set |= (1UL << actions->type);
1708 #undef SFC_BUILD_SET_OVERFLOW
1710 /* When fate is unknown, drop traffic. */
1711 if ((actions_set & fate_actions_mask) == 0) {
1712 spec_filter->template.efs_dmaq_id =
1713 EFX_FILTER_SPEC_RX_DMAQ_ID_DROP;
1719 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, actions,
1720 "Cannot combine several fate-deciding actions, "
1721 "choose between QUEUE, RSS or DROP");
1724 fail_actions_overlap:
1725 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, actions,
1726 "Overlapping actions are not supported");
1731 * Set the EFX_FILTER_MATCH_UNKNOWN_UCAST_DST
1732 * and EFX_FILTER_MATCH_UNKNOWN_MCAST_DST match flags in the same
1733 * specifications after copying.
1735 * @param spec[in, out]
1736 * SFC flow specification to update.
1737 * @param filters_count_for_one_val[in]
1738 * How many specifications should have the same match flag, what is the
1739 * number of specifications before copying.
1741 * Perform verbose error reporting if not NULL.
1744 sfc_flow_set_unknown_dst_flags(struct sfc_flow_spec *spec,
1745 unsigned int filters_count_for_one_val,
1746 struct rte_flow_error *error)
1749 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1750 static const efx_filter_match_flags_t vals[] = {
1751 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST,
1752 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST
1755 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
1756 rte_flow_error_set(error, EINVAL,
1757 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1758 "Number of specifications is incorrect while copying "
1759 "by unknown destination flags");
1763 for (i = 0; i < spec_filter->count; i++) {
1764 /* The check above ensures that divisor can't be zero here */
1765 spec_filter->filters[i].efs_match_flags |=
1766 vals[i / filters_count_for_one_val];
1773 * Check that the following conditions are met:
1774 * - the list of supported filters has a filter
1775 * with EFX_FILTER_MATCH_UNKNOWN_MCAST_DST flag instead of
1776 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST, since this filter will also
1780 * The match flags of filter.
1782 * Specification to be supplemented.
1784 * SFC filter with list of supported filters.
1787 sfc_flow_check_unknown_dst_flags(efx_filter_match_flags_t match,
1788 __rte_unused efx_filter_spec_t *spec,
1789 struct sfc_filter *filter)
1792 efx_filter_match_flags_t match_mcast_dst;
1795 (match & ~EFX_FILTER_MATCH_UNKNOWN_UCAST_DST) |
1796 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST;
1797 for (i = 0; i < filter->supported_match_num; i++) {
1798 if (match_mcast_dst == filter->supported_match[i])
1806 * Set the EFX_FILTER_MATCH_ETHER_TYPE match flag and EFX_ETHER_TYPE_IPV4 and
1807 * EFX_ETHER_TYPE_IPV6 values of the corresponding field in the same
1808 * specifications after copying.
1810 * @param spec[in, out]
1811 * SFC flow specification to update.
1812 * @param filters_count_for_one_val[in]
1813 * How many specifications should have the same EtherType value, what is the
1814 * number of specifications before copying.
1816 * Perform verbose error reporting if not NULL.
1819 sfc_flow_set_ethertypes(struct sfc_flow_spec *spec,
1820 unsigned int filters_count_for_one_val,
1821 struct rte_flow_error *error)
1824 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1825 static const uint16_t vals[] = {
1826 EFX_ETHER_TYPE_IPV4, EFX_ETHER_TYPE_IPV6
1829 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
1830 rte_flow_error_set(error, EINVAL,
1831 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1832 "Number of specifications is incorrect "
1833 "while copying by Ethertype");
1837 for (i = 0; i < spec_filter->count; i++) {
1838 spec_filter->filters[i].efs_match_flags |=
1839 EFX_FILTER_MATCH_ETHER_TYPE;
1842 * The check above ensures that
1843 * filters_count_for_one_val is not 0
1845 spec_filter->filters[i].efs_ether_type =
1846 vals[i / filters_count_for_one_val];
1853 * Set the EFX_FILTER_MATCH_OUTER_VID match flag with value 0
1854 * in the same specifications after copying.
1856 * @param spec[in, out]
1857 * SFC flow specification to update.
1858 * @param filters_count_for_one_val[in]
1859 * How many specifications should have the same match flag, what is the
1860 * number of specifications before copying.
1862 * Perform verbose error reporting if not NULL.
1865 sfc_flow_set_outer_vid_flag(struct sfc_flow_spec *spec,
1866 unsigned int filters_count_for_one_val,
1867 struct rte_flow_error *error)
1869 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1872 if (filters_count_for_one_val != spec_filter->count) {
1873 rte_flow_error_set(error, EINVAL,
1874 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1875 "Number of specifications is incorrect "
1876 "while copying by outer VLAN ID");
1880 for (i = 0; i < spec_filter->count; i++) {
1881 spec_filter->filters[i].efs_match_flags |=
1882 EFX_FILTER_MATCH_OUTER_VID;
1884 spec_filter->filters[i].efs_outer_vid = 0;
1891 * Set the EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST and
1892 * EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST match flags in the same
1893 * specifications after copying.
1895 * @param spec[in, out]
1896 * SFC flow specification to update.
1897 * @param filters_count_for_one_val[in]
1898 * How many specifications should have the same match flag, what is the
1899 * number of specifications before copying.
1901 * Perform verbose error reporting if not NULL.
1904 sfc_flow_set_ifrm_unknown_dst_flags(struct sfc_flow_spec *spec,
1905 unsigned int filters_count_for_one_val,
1906 struct rte_flow_error *error)
1909 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1910 static const efx_filter_match_flags_t vals[] = {
1911 EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST,
1912 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST
1915 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
1916 rte_flow_error_set(error, EINVAL,
1917 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1918 "Number of specifications is incorrect while copying "
1919 "by inner frame unknown destination flags");
1923 for (i = 0; i < spec_filter->count; i++) {
1924 /* The check above ensures that divisor can't be zero here */
1925 spec_filter->filters[i].efs_match_flags |=
1926 vals[i / filters_count_for_one_val];
1933 * Check that the following conditions are met:
1934 * - the specification corresponds to a filter for encapsulated traffic
1935 * - the list of supported filters has a filter
1936 * with EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST flag instead of
1937 * EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST, since this filter will also
1941 * The match flags of filter.
1943 * Specification to be supplemented.
1945 * SFC filter with list of supported filters.
1948 sfc_flow_check_ifrm_unknown_dst_flags(efx_filter_match_flags_t match,
1949 efx_filter_spec_t *spec,
1950 struct sfc_filter *filter)
1953 efx_tunnel_protocol_t encap_type = spec->efs_encap_type;
1954 efx_filter_match_flags_t match_mcast_dst;
1956 if (encap_type == EFX_TUNNEL_PROTOCOL_NONE)
1960 (match & ~EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST) |
1961 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST;
1962 for (i = 0; i < filter->supported_match_num; i++) {
1963 if (match_mcast_dst == filter->supported_match[i])
1971 * Check that the list of supported filters has a filter that differs
1972 * from @p match in that it has no flag EFX_FILTER_MATCH_OUTER_VID
1973 * in this case that filter will be used and the flag
1974 * EFX_FILTER_MATCH_OUTER_VID is not needed.
1977 * The match flags of filter.
1979 * Specification to be supplemented.
1981 * SFC filter with list of supported filters.
1984 sfc_flow_check_outer_vid_flag(efx_filter_match_flags_t match,
1985 __rte_unused efx_filter_spec_t *spec,
1986 struct sfc_filter *filter)
1989 efx_filter_match_flags_t match_without_vid =
1990 match & ~EFX_FILTER_MATCH_OUTER_VID;
1992 for (i = 0; i < filter->supported_match_num; i++) {
1993 if (match_without_vid == filter->supported_match[i])
2001 * Match flags that can be automatically added to filters.
2002 * Selecting the last minimum when searching for the copy flag ensures that the
2003 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST flag has a higher priority than
2004 * EFX_FILTER_MATCH_ETHER_TYPE. This is because the filter
2005 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST is at the end of the list of supported
2008 static const struct sfc_flow_copy_flag sfc_flow_copy_flags[] = {
2010 .flag = EFX_FILTER_MATCH_UNKNOWN_UCAST_DST,
2012 .set_vals = sfc_flow_set_unknown_dst_flags,
2013 .spec_check = sfc_flow_check_unknown_dst_flags,
2016 .flag = EFX_FILTER_MATCH_ETHER_TYPE,
2018 .set_vals = sfc_flow_set_ethertypes,
2022 .flag = EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST,
2024 .set_vals = sfc_flow_set_ifrm_unknown_dst_flags,
2025 .spec_check = sfc_flow_check_ifrm_unknown_dst_flags,
2028 .flag = EFX_FILTER_MATCH_OUTER_VID,
2030 .set_vals = sfc_flow_set_outer_vid_flag,
2031 .spec_check = sfc_flow_check_outer_vid_flag,
2035 /* Get item from array sfc_flow_copy_flags */
2036 static const struct sfc_flow_copy_flag *
2037 sfc_flow_get_copy_flag(efx_filter_match_flags_t flag)
2041 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
2042 if (sfc_flow_copy_flags[i].flag == flag)
2043 return &sfc_flow_copy_flags[i];
2050 * Make copies of the specifications, set match flag and values
2051 * of the field that corresponds to it.
2053 * @param spec[in, out]
2054 * SFC flow specification to update.
2056 * The match flag to add.
2058 * Perform verbose error reporting if not NULL.
2061 sfc_flow_spec_add_match_flag(struct sfc_flow_spec *spec,
2062 efx_filter_match_flags_t flag,
2063 struct rte_flow_error *error)
2066 unsigned int new_filters_count;
2067 unsigned int filters_count_for_one_val;
2068 const struct sfc_flow_copy_flag *copy_flag;
2069 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2072 copy_flag = sfc_flow_get_copy_flag(flag);
2073 if (copy_flag == NULL) {
2074 rte_flow_error_set(error, ENOTSUP,
2075 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2076 "Unsupported spec field for copying");
2080 new_filters_count = spec_filter->count * copy_flag->vals_count;
2081 if (new_filters_count > SF_FLOW_SPEC_NB_FILTERS_MAX) {
2082 rte_flow_error_set(error, EINVAL,
2083 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2084 "Too much EFX specifications in the flow rule");
2088 /* Copy filters specifications */
2089 for (i = spec_filter->count; i < new_filters_count; i++) {
2090 spec_filter->filters[i] =
2091 spec_filter->filters[i - spec_filter->count];
2094 filters_count_for_one_val = spec_filter->count;
2095 spec_filter->count = new_filters_count;
2097 rc = copy_flag->set_vals(spec, filters_count_for_one_val, error);
2105 * Check that the given set of match flags missing in the original filter spec
2106 * could be covered by adding spec copies which specify the corresponding
2107 * flags and packet field values to match.
2109 * @param miss_flags[in]
2110 * Flags that are missing until the supported filter.
2112 * Specification to be supplemented.
2117 * Number of specifications after copy or 0, if the flags can not be added.
2120 sfc_flow_check_missing_flags(efx_filter_match_flags_t miss_flags,
2121 efx_filter_spec_t *spec,
2122 struct sfc_filter *filter)
2125 efx_filter_match_flags_t copy_flags = 0;
2126 efx_filter_match_flags_t flag;
2127 efx_filter_match_flags_t match = spec->efs_match_flags | miss_flags;
2128 sfc_flow_spec_check *check;
2129 unsigned int multiplier = 1;
2131 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
2132 flag = sfc_flow_copy_flags[i].flag;
2133 check = sfc_flow_copy_flags[i].spec_check;
2134 if ((flag & miss_flags) == flag) {
2135 if (check != NULL && (!check(match, spec, filter)))
2139 multiplier *= sfc_flow_copy_flags[i].vals_count;
2143 if (copy_flags == miss_flags)
2150 * Attempt to supplement the specification template to the minimally
2151 * supported set of match flags. To do this, it is necessary to copy
2152 * the specifications, filling them with the values of fields that
2153 * correspond to the missing flags.
2154 * The necessary and sufficient filter is built from the fewest number
2155 * of copies which could be made to cover the minimally required set
2160 * @param spec[in, out]
2161 * SFC flow specification to update.
2163 * Perform verbose error reporting if not NULL.
2166 sfc_flow_spec_filters_complete(struct sfc_adapter *sa,
2167 struct sfc_flow_spec *spec,
2168 struct rte_flow_error *error)
2170 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2171 struct sfc_filter *filter = &sa->filter;
2172 efx_filter_match_flags_t miss_flags;
2173 efx_filter_match_flags_t min_miss_flags = 0;
2174 efx_filter_match_flags_t match;
2175 unsigned int min_multiplier = UINT_MAX;
2176 unsigned int multiplier;
2180 match = spec_filter->template.efs_match_flags;
2181 for (i = 0; i < filter->supported_match_num; i++) {
2182 if ((match & filter->supported_match[i]) == match) {
2183 miss_flags = filter->supported_match[i] & (~match);
2184 multiplier = sfc_flow_check_missing_flags(miss_flags,
2185 &spec_filter->template, filter);
2186 if (multiplier > 0) {
2187 if (multiplier <= min_multiplier) {
2188 min_multiplier = multiplier;
2189 min_miss_flags = miss_flags;
2195 if (min_multiplier == UINT_MAX) {
2196 rte_flow_error_set(error, ENOTSUP,
2197 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2198 "The flow rule pattern is unsupported");
2202 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
2203 efx_filter_match_flags_t flag = sfc_flow_copy_flags[i].flag;
2205 if ((flag & min_miss_flags) == flag) {
2206 rc = sfc_flow_spec_add_match_flag(spec, flag, error);
2216 * Check that set of match flags is referred to by a filter. Filter is
2217 * described by match flags with the ability to add OUTER_VID and INNER_VID
2220 * @param match_flags[in]
2221 * Set of match flags.
2222 * @param flags_pattern[in]
2223 * Pattern of filter match flags.
2226 sfc_flow_is_match_with_vids(efx_filter_match_flags_t match_flags,
2227 efx_filter_match_flags_t flags_pattern)
2229 if ((match_flags & flags_pattern) != flags_pattern)
2232 switch (match_flags & ~flags_pattern) {
2234 case EFX_FILTER_MATCH_OUTER_VID:
2235 case EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_INNER_VID:
2243 * Check whether the spec maps to a hardware filter which is known to be
2244 * ineffective despite being valid.
2247 * SFC filter with list of supported filters.
2249 * SFC flow specification.
2252 sfc_flow_is_match_flags_exception(struct sfc_filter *filter,
2253 struct sfc_flow_spec *spec)
2256 uint16_t ether_type;
2258 efx_filter_match_flags_t match_flags;
2259 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2261 for (i = 0; i < spec_filter->count; i++) {
2262 match_flags = spec_filter->filters[i].efs_match_flags;
2264 if (sfc_flow_is_match_with_vids(match_flags,
2265 EFX_FILTER_MATCH_ETHER_TYPE) ||
2266 sfc_flow_is_match_with_vids(match_flags,
2267 EFX_FILTER_MATCH_ETHER_TYPE |
2268 EFX_FILTER_MATCH_LOC_MAC)) {
2269 ether_type = spec_filter->filters[i].efs_ether_type;
2270 if (filter->supports_ip_proto_or_addr_filter &&
2271 (ether_type == EFX_ETHER_TYPE_IPV4 ||
2272 ether_type == EFX_ETHER_TYPE_IPV6))
2274 } else if (sfc_flow_is_match_with_vids(match_flags,
2275 EFX_FILTER_MATCH_ETHER_TYPE |
2276 EFX_FILTER_MATCH_IP_PROTO) ||
2277 sfc_flow_is_match_with_vids(match_flags,
2278 EFX_FILTER_MATCH_ETHER_TYPE |
2279 EFX_FILTER_MATCH_IP_PROTO |
2280 EFX_FILTER_MATCH_LOC_MAC)) {
2281 ip_proto = spec_filter->filters[i].efs_ip_proto;
2282 if (filter->supports_rem_or_local_port_filter &&
2283 (ip_proto == EFX_IPPROTO_TCP ||
2284 ip_proto == EFX_IPPROTO_UDP))
2293 sfc_flow_validate_match_flags(struct sfc_adapter *sa,
2294 struct rte_flow *flow,
2295 struct rte_flow_error *error)
2297 struct sfc_flow_spec *spec = &flow->spec;
2298 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2299 efx_filter_spec_t *spec_tmpl = &spec_filter->template;
2300 efx_filter_match_flags_t match_flags = spec_tmpl->efs_match_flags;
2303 /* Initialize the first filter spec with template */
2304 spec_filter->filters[0] = *spec_tmpl;
2305 spec_filter->count = 1;
2307 if (!sfc_filter_is_match_supported(sa, match_flags)) {
2308 rc = sfc_flow_spec_filters_complete(sa, &flow->spec, error);
2313 if (sfc_flow_is_match_flags_exception(&sa->filter, &flow->spec)) {
2314 rte_flow_error_set(error, ENOTSUP,
2315 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2316 "The flow rule pattern is unsupported");
2324 sfc_flow_parse_rte_to_filter(struct rte_eth_dev *dev,
2325 const struct rte_flow_item pattern[],
2326 const struct rte_flow_action actions[],
2327 struct rte_flow *flow,
2328 struct rte_flow_error *error)
2330 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2331 struct sfc_flow_spec *spec = &flow->spec;
2332 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2333 struct sfc_flow_parse_ctx ctx;
2336 ctx.type = SFC_FLOW_PARSE_CTX_FILTER;
2337 ctx.filter = &spec_filter->template;
2339 rc = sfc_flow_parse_pattern(sfc_flow_items, RTE_DIM(sfc_flow_items),
2340 pattern, &ctx, error);
2342 goto fail_bad_value;
2344 rc = sfc_flow_parse_actions(sa, actions, flow, error);
2346 goto fail_bad_value;
2348 rc = sfc_flow_validate_match_flags(sa, flow, error);
2350 goto fail_bad_value;
2359 sfc_flow_parse(struct rte_eth_dev *dev,
2360 const struct rte_flow_attr *attr,
2361 const struct rte_flow_item pattern[],
2362 const struct rte_flow_action actions[],
2363 struct rte_flow *flow,
2364 struct rte_flow_error *error)
2366 const struct sfc_flow_ops_by_spec *ops;
2369 rc = sfc_flow_parse_attr(attr, flow, error);
2373 ops = sfc_flow_get_ops_by_spec(flow);
2374 if (ops == NULL || ops->parse == NULL) {
2375 rte_flow_error_set(error, ENOTSUP,
2376 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2377 "No backend to handle this flow");
2381 return ops->parse(dev, pattern, actions, flow, error);
2384 static struct rte_flow *
2385 sfc_flow_zmalloc(struct rte_flow_error *error)
2387 struct rte_flow *flow;
2389 flow = rte_zmalloc("sfc_rte_flow", sizeof(*flow), 0);
2391 rte_flow_error_set(error, ENOMEM,
2392 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2393 "Failed to allocate memory");
2400 sfc_flow_free(__rte_unused struct sfc_adapter *sa, struct rte_flow *flow)
2406 sfc_flow_insert(struct sfc_adapter *sa, struct rte_flow *flow,
2407 struct rte_flow_error *error)
2409 const struct sfc_flow_ops_by_spec *ops;
2412 ops = sfc_flow_get_ops_by_spec(flow);
2413 if (ops == NULL || ops->insert == NULL) {
2414 rte_flow_error_set(error, ENOTSUP,
2415 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2416 "No backend to handle this flow");
2420 rc = ops->insert(sa, flow);
2422 rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2423 NULL, "Failed to insert the flow rule");
2430 sfc_flow_remove(struct sfc_adapter *sa, struct rte_flow *flow,
2431 struct rte_flow_error *error)
2433 const struct sfc_flow_ops_by_spec *ops;
2436 ops = sfc_flow_get_ops_by_spec(flow);
2437 if (ops == NULL || ops->remove == NULL) {
2438 rte_flow_error_set(error, ENOTSUP,
2439 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2440 "No backend to handle this flow");
2444 rc = ops->remove(sa, flow);
2446 rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2447 NULL, "Failed to remove the flow rule");
2454 sfc_flow_validate(struct rte_eth_dev *dev,
2455 const struct rte_flow_attr *attr,
2456 const struct rte_flow_item pattern[],
2457 const struct rte_flow_action actions[],
2458 struct rte_flow_error *error)
2460 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2461 struct rte_flow *flow;
2464 flow = sfc_flow_zmalloc(error);
2468 rc = sfc_flow_parse(dev, attr, pattern, actions, flow, error);
2470 sfc_flow_free(sa, flow);
2475 static struct rte_flow *
2476 sfc_flow_create(struct rte_eth_dev *dev,
2477 const struct rte_flow_attr *attr,
2478 const struct rte_flow_item pattern[],
2479 const struct rte_flow_action actions[],
2480 struct rte_flow_error *error)
2482 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2483 struct rte_flow *flow = NULL;
2486 flow = sfc_flow_zmalloc(error);
2490 rc = sfc_flow_parse(dev, attr, pattern, actions, flow, error);
2492 goto fail_bad_value;
2494 sfc_adapter_lock(sa);
2496 TAILQ_INSERT_TAIL(&sa->flow_list, flow, entries);
2498 if (sa->state == SFC_ADAPTER_STARTED) {
2499 rc = sfc_flow_insert(sa, flow, error);
2501 goto fail_flow_insert;
2504 sfc_adapter_unlock(sa);
2509 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2512 sfc_flow_free(sa, flow);
2513 sfc_adapter_unlock(sa);
2520 sfc_flow_destroy(struct rte_eth_dev *dev,
2521 struct rte_flow *flow,
2522 struct rte_flow_error *error)
2524 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2525 struct rte_flow *flow_ptr;
2528 sfc_adapter_lock(sa);
2530 TAILQ_FOREACH(flow_ptr, &sa->flow_list, entries) {
2531 if (flow_ptr == flow)
2535 rte_flow_error_set(error, rc,
2536 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
2537 "Failed to find flow rule to destroy");
2538 goto fail_bad_value;
2541 if (sa->state == SFC_ADAPTER_STARTED)
2542 rc = sfc_flow_remove(sa, flow, error);
2544 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2545 sfc_flow_free(sa, flow);
2548 sfc_adapter_unlock(sa);
2554 sfc_flow_flush(struct rte_eth_dev *dev,
2555 struct rte_flow_error *error)
2557 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2558 struct rte_flow *flow;
2561 sfc_adapter_lock(sa);
2563 while ((flow = TAILQ_FIRST(&sa->flow_list)) != NULL) {
2564 if (sa->state == SFC_ADAPTER_STARTED) {
2567 rc = sfc_flow_remove(sa, flow, error);
2572 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2573 sfc_flow_free(sa, flow);
2576 sfc_adapter_unlock(sa);
2582 sfc_flow_isolate(struct rte_eth_dev *dev, int enable,
2583 struct rte_flow_error *error)
2585 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2588 sfc_adapter_lock(sa);
2589 if (sa->state != SFC_ADAPTER_INITIALIZED) {
2590 rte_flow_error_set(error, EBUSY,
2591 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2592 NULL, "please close the port first");
2595 sfc_sa2shared(sa)->isolated = (enable) ? B_TRUE : B_FALSE;
2597 sfc_adapter_unlock(sa);
2602 const struct rte_flow_ops sfc_flow_ops = {
2603 .validate = sfc_flow_validate,
2604 .create = sfc_flow_create,
2605 .destroy = sfc_flow_destroy,
2606 .flush = sfc_flow_flush,
2608 .isolate = sfc_flow_isolate,
2612 sfc_flow_init(struct sfc_adapter *sa)
2614 SFC_ASSERT(sfc_adapter_is_locked(sa));
2616 TAILQ_INIT(&sa->flow_list);
2620 sfc_flow_fini(struct sfc_adapter *sa)
2622 struct rte_flow *flow;
2624 SFC_ASSERT(sfc_adapter_is_locked(sa));
2626 while ((flow = TAILQ_FIRST(&sa->flow_list)) != NULL) {
2627 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2628 sfc_flow_free(sa, flow);
2633 sfc_flow_stop(struct sfc_adapter *sa)
2635 struct rte_flow *flow;
2637 SFC_ASSERT(sfc_adapter_is_locked(sa));
2639 TAILQ_FOREACH(flow, &sa->flow_list, entries)
2640 sfc_flow_remove(sa, flow, NULL);
2644 sfc_flow_start(struct sfc_adapter *sa)
2646 struct rte_flow *flow;
2649 sfc_log_init(sa, "entry");
2651 SFC_ASSERT(sfc_adapter_is_locked(sa));
2653 TAILQ_FOREACH(flow, &sa->flow_list, entries) {
2654 rc = sfc_flow_insert(sa, flow, NULL);
2659 sfc_log_init(sa, "done");