1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2019-2020 Xilinx, Inc.
4 * Copyright(c) 2017-2019 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>
21 #include "sfc_debug.h"
23 #include "sfc_filter.h"
26 #include "sfc_dp_rx.h"
28 struct sfc_flow_ops_by_spec {
29 sfc_flow_parse_cb_t *parse;
30 sfc_flow_insert_cb_t *insert;
31 sfc_flow_remove_cb_t *remove;
34 static sfc_flow_parse_cb_t sfc_flow_parse_rte_to_filter;
35 static sfc_flow_insert_cb_t sfc_flow_filter_insert;
36 static sfc_flow_remove_cb_t sfc_flow_filter_remove;
38 static const struct sfc_flow_ops_by_spec sfc_flow_ops_filter = {
39 .parse = sfc_flow_parse_rte_to_filter,
40 .insert = sfc_flow_filter_insert,
41 .remove = sfc_flow_filter_remove,
44 static const struct sfc_flow_ops_by_spec *
45 sfc_flow_get_ops_by_spec(struct rte_flow *flow)
47 struct sfc_flow_spec *spec = &flow->spec;
48 const struct sfc_flow_ops_by_spec *ops = NULL;
51 case SFC_FLOW_SPEC_FILTER:
52 ops = &sfc_flow_ops_filter;
63 * Currently, filter-based (VNIC) flow API is implemented in such a manner
64 * that each flow rule is converted to one or more hardware filters.
65 * All elements of flow rule (attributes, pattern items, actions)
66 * correspond to one or more fields in the efx_filter_spec_s structure
67 * that is responsible for the hardware filter.
68 * If some required field is unset in the flow rule, then a handful
69 * of filter copies will be created to cover all possible values
73 static sfc_flow_item_parse sfc_flow_parse_void;
74 static sfc_flow_item_parse sfc_flow_parse_eth;
75 static sfc_flow_item_parse sfc_flow_parse_vlan;
76 static sfc_flow_item_parse sfc_flow_parse_ipv4;
77 static sfc_flow_item_parse sfc_flow_parse_ipv6;
78 static sfc_flow_item_parse sfc_flow_parse_tcp;
79 static sfc_flow_item_parse sfc_flow_parse_udp;
80 static sfc_flow_item_parse sfc_flow_parse_vxlan;
81 static sfc_flow_item_parse sfc_flow_parse_geneve;
82 static sfc_flow_item_parse sfc_flow_parse_nvgre;
84 typedef int (sfc_flow_spec_set_vals)(struct sfc_flow_spec *spec,
85 unsigned int filters_count_for_one_val,
86 struct rte_flow_error *error);
88 typedef boolean_t (sfc_flow_spec_check)(efx_filter_match_flags_t match,
89 efx_filter_spec_t *spec,
90 struct sfc_filter *filter);
92 struct sfc_flow_copy_flag {
93 /* EFX filter specification match flag */
94 efx_filter_match_flags_t flag;
95 /* Number of values of corresponding field */
96 unsigned int vals_count;
97 /* Function to set values in specifications */
98 sfc_flow_spec_set_vals *set_vals;
100 * Function to check that the specification is suitable
101 * for adding this match flag
103 sfc_flow_spec_check *spec_check;
106 static sfc_flow_spec_set_vals sfc_flow_set_unknown_dst_flags;
107 static sfc_flow_spec_check sfc_flow_check_unknown_dst_flags;
108 static sfc_flow_spec_set_vals sfc_flow_set_ethertypes;
109 static sfc_flow_spec_set_vals sfc_flow_set_ifrm_unknown_dst_flags;
110 static sfc_flow_spec_check sfc_flow_check_ifrm_unknown_dst_flags;
111 static sfc_flow_spec_set_vals sfc_flow_set_outer_vid_flag;
112 static sfc_flow_spec_check sfc_flow_check_outer_vid_flag;
115 sfc_flow_is_zero(const uint8_t *buf, unsigned int size)
120 for (i = 0; i < size; i++)
123 return (sum == 0) ? B_TRUE : B_FALSE;
127 * Validate item and prepare structures spec and mask for parsing
130 sfc_flow_parse_init(const struct rte_flow_item *item,
131 const void **spec_ptr,
132 const void **mask_ptr,
133 const void *supp_mask,
134 const void *def_mask,
136 struct rte_flow_error *error)
145 rte_flow_error_set(error, EINVAL,
146 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
151 if ((item->last != NULL || item->mask != NULL) && item->spec == NULL) {
152 rte_flow_error_set(error, EINVAL,
153 RTE_FLOW_ERROR_TYPE_ITEM, item,
154 "Mask or last is set without spec");
159 * If "mask" is not set, default mask is used,
160 * but if default mask is NULL, "mask" should be set
162 if (item->mask == NULL) {
163 if (def_mask == NULL) {
164 rte_flow_error_set(error, EINVAL,
165 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
166 "Mask should be specified");
182 * If field values in "last" are either 0 or equal to the corresponding
183 * values in "spec" then they are ignored
186 !sfc_flow_is_zero(last, size) &&
187 memcmp(last, spec, size) != 0) {
188 rte_flow_error_set(error, ENOTSUP,
189 RTE_FLOW_ERROR_TYPE_ITEM, item,
190 "Ranging is not supported");
194 if (supp_mask == NULL) {
195 rte_flow_error_set(error, EINVAL,
196 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
197 "Supported mask for item should be specified");
201 /* Check that mask does not ask for more match than supp_mask */
202 for (i = 0; i < size; i++) {
203 supp = ((const uint8_t *)supp_mask)[i];
205 if (~supp & mask[i]) {
206 rte_flow_error_set(error, ENOTSUP,
207 RTE_FLOW_ERROR_TYPE_ITEM, item,
208 "Item's field is not supported");
221 * Masking is not supported, so masks in items should be either
222 * full or empty (zeroed) and set only for supported fields which
223 * are specified in the supp_mask.
227 sfc_flow_parse_void(__rte_unused const struct rte_flow_item *item,
228 __rte_unused struct sfc_flow_parse_ctx *parse_ctx,
229 __rte_unused struct rte_flow_error *error)
235 * Convert Ethernet item to EFX filter specification.
238 * Item specification. Outer frame specification may only comprise
239 * source/destination addresses and Ethertype field.
240 * Inner frame specification may contain destination address only.
241 * There is support for individual/group mask as well as for empty and full.
242 * If the mask is NULL, default mask will be used. Ranging is not supported.
243 * @param efx_spec[in, out]
244 * EFX filter specification to update.
246 * Perform verbose error reporting if not NULL.
249 sfc_flow_parse_eth(const struct rte_flow_item *item,
250 struct sfc_flow_parse_ctx *parse_ctx,
251 struct rte_flow_error *error)
254 efx_filter_spec_t *efx_spec = parse_ctx->filter;
255 const struct rte_flow_item_eth *spec = NULL;
256 const struct rte_flow_item_eth *mask = NULL;
257 const struct rte_flow_item_eth supp_mask = {
258 .dst.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
259 .src.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
262 const struct rte_flow_item_eth ifrm_supp_mask = {
263 .dst.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
265 const uint8_t ig_mask[EFX_MAC_ADDR_LEN] = {
266 0x01, 0x00, 0x00, 0x00, 0x00, 0x00
268 const struct rte_flow_item_eth *supp_mask_p;
269 const struct rte_flow_item_eth *def_mask_p;
270 uint8_t *loc_mac = NULL;
271 boolean_t is_ifrm = (efx_spec->efs_encap_type !=
272 EFX_TUNNEL_PROTOCOL_NONE);
275 supp_mask_p = &ifrm_supp_mask;
276 def_mask_p = &ifrm_supp_mask;
277 loc_mac = efx_spec->efs_ifrm_loc_mac;
279 supp_mask_p = &supp_mask;
280 def_mask_p = &rte_flow_item_eth_mask;
281 loc_mac = efx_spec->efs_loc_mac;
284 rc = sfc_flow_parse_init(item,
285 (const void **)&spec,
286 (const void **)&mask,
287 supp_mask_p, def_mask_p,
288 sizeof(struct rte_flow_item_eth),
293 /* If "spec" is not set, could be any Ethernet */
297 if (rte_is_same_ether_addr(&mask->dst, &supp_mask.dst)) {
298 efx_spec->efs_match_flags |= is_ifrm ?
299 EFX_FILTER_MATCH_IFRM_LOC_MAC :
300 EFX_FILTER_MATCH_LOC_MAC;
301 rte_memcpy(loc_mac, spec->dst.addr_bytes,
303 } else if (memcmp(mask->dst.addr_bytes, ig_mask,
304 EFX_MAC_ADDR_LEN) == 0) {
305 if (rte_is_unicast_ether_addr(&spec->dst))
306 efx_spec->efs_match_flags |= is_ifrm ?
307 EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST :
308 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST;
310 efx_spec->efs_match_flags |= is_ifrm ?
311 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST :
312 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST;
313 } else if (!rte_is_zero_ether_addr(&mask->dst)) {
318 * ifrm_supp_mask ensures that the source address and
319 * ethertype masks are equal to zero in inner frame,
320 * so these fields are filled in only for the outer frame
322 if (rte_is_same_ether_addr(&mask->src, &supp_mask.src)) {
323 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_MAC;
324 rte_memcpy(efx_spec->efs_rem_mac, spec->src.addr_bytes,
326 } else if (!rte_is_zero_ether_addr(&mask->src)) {
331 * Ether type is in big-endian byte order in item and
332 * in little-endian in efx_spec, so byte swap is used
334 if (mask->type == supp_mask.type) {
335 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
336 efx_spec->efs_ether_type = rte_bswap16(spec->type);
337 } else if (mask->type != 0) {
344 rte_flow_error_set(error, EINVAL,
345 RTE_FLOW_ERROR_TYPE_ITEM, item,
346 "Bad mask in the ETH pattern item");
351 * Convert VLAN item to EFX filter specification.
354 * Item specification. Only VID field is supported.
355 * The mask can not be NULL. Ranging is not supported.
356 * @param efx_spec[in, out]
357 * EFX filter specification to update.
359 * Perform verbose error reporting if not NULL.
362 sfc_flow_parse_vlan(const struct rte_flow_item *item,
363 struct sfc_flow_parse_ctx *parse_ctx,
364 struct rte_flow_error *error)
368 efx_filter_spec_t *efx_spec = parse_ctx->filter;
369 const struct rte_flow_item_vlan *spec = NULL;
370 const struct rte_flow_item_vlan *mask = NULL;
371 const struct rte_flow_item_vlan supp_mask = {
372 .tci = rte_cpu_to_be_16(ETH_VLAN_ID_MAX),
373 .inner_type = RTE_BE16(0xffff),
376 rc = sfc_flow_parse_init(item,
377 (const void **)&spec,
378 (const void **)&mask,
381 sizeof(struct rte_flow_item_vlan),
387 * VID is in big-endian byte order in item and
388 * in little-endian in efx_spec, so byte swap is used.
389 * If two VLAN items are included, the first matches
390 * the outer tag and the next matches the inner tag.
392 if (mask->tci == supp_mask.tci) {
393 /* Apply mask to keep VID only */
394 vid = rte_bswap16(spec->tci & mask->tci);
396 if (!(efx_spec->efs_match_flags &
397 EFX_FILTER_MATCH_OUTER_VID)) {
398 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_OUTER_VID;
399 efx_spec->efs_outer_vid = vid;
400 } else if (!(efx_spec->efs_match_flags &
401 EFX_FILTER_MATCH_INNER_VID)) {
402 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_INNER_VID;
403 efx_spec->efs_inner_vid = vid;
405 rte_flow_error_set(error, EINVAL,
406 RTE_FLOW_ERROR_TYPE_ITEM, item,
407 "More than two VLAN items");
411 rte_flow_error_set(error, EINVAL,
412 RTE_FLOW_ERROR_TYPE_ITEM, item,
413 "VLAN ID in TCI match is required");
417 if (efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE) {
418 rte_flow_error_set(error, EINVAL,
419 RTE_FLOW_ERROR_TYPE_ITEM, item,
420 "VLAN TPID matching is not supported");
423 if (mask->inner_type == supp_mask.inner_type) {
424 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
425 efx_spec->efs_ether_type = rte_bswap16(spec->inner_type);
426 } else if (mask->inner_type) {
427 rte_flow_error_set(error, EINVAL,
428 RTE_FLOW_ERROR_TYPE_ITEM, item,
429 "Bad mask for VLAN inner_type");
437 * Convert IPv4 item to EFX filter specification.
440 * Item specification. Only source and destination addresses and
441 * protocol fields are supported. If the mask is NULL, default
442 * mask will be used. Ranging is not supported.
443 * @param efx_spec[in, out]
444 * EFX filter specification to update.
446 * Perform verbose error reporting if not NULL.
449 sfc_flow_parse_ipv4(const struct rte_flow_item *item,
450 struct sfc_flow_parse_ctx *parse_ctx,
451 struct rte_flow_error *error)
454 efx_filter_spec_t *efx_spec = parse_ctx->filter;
455 const struct rte_flow_item_ipv4 *spec = NULL;
456 const struct rte_flow_item_ipv4 *mask = NULL;
457 const uint16_t ether_type_ipv4 = rte_cpu_to_le_16(EFX_ETHER_TYPE_IPV4);
458 const struct rte_flow_item_ipv4 supp_mask = {
460 .src_addr = 0xffffffff,
461 .dst_addr = 0xffffffff,
462 .next_proto_id = 0xff,
466 rc = sfc_flow_parse_init(item,
467 (const void **)&spec,
468 (const void **)&mask,
470 &rte_flow_item_ipv4_mask,
471 sizeof(struct rte_flow_item_ipv4),
477 * Filtering by IPv4 source and destination addresses requires
478 * the appropriate ETHER_TYPE in hardware filters
480 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE)) {
481 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
482 efx_spec->efs_ether_type = ether_type_ipv4;
483 } else if (efx_spec->efs_ether_type != ether_type_ipv4) {
484 rte_flow_error_set(error, EINVAL,
485 RTE_FLOW_ERROR_TYPE_ITEM, item,
486 "Ethertype in pattern with IPV4 item should be appropriate");
494 * IPv4 addresses are in big-endian byte order in item and in
497 if (mask->hdr.src_addr == supp_mask.hdr.src_addr) {
498 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_HOST;
499 efx_spec->efs_rem_host.eo_u32[0] = spec->hdr.src_addr;
500 } else if (mask->hdr.src_addr != 0) {
504 if (mask->hdr.dst_addr == supp_mask.hdr.dst_addr) {
505 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_HOST;
506 efx_spec->efs_loc_host.eo_u32[0] = spec->hdr.dst_addr;
507 } else if (mask->hdr.dst_addr != 0) {
511 if (mask->hdr.next_proto_id == supp_mask.hdr.next_proto_id) {
512 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
513 efx_spec->efs_ip_proto = spec->hdr.next_proto_id;
514 } else if (mask->hdr.next_proto_id != 0) {
521 rte_flow_error_set(error, EINVAL,
522 RTE_FLOW_ERROR_TYPE_ITEM, item,
523 "Bad mask in the IPV4 pattern item");
528 * Convert IPv6 item to EFX filter specification.
531 * Item specification. Only source and destination addresses and
532 * next header fields are supported. If the mask is NULL, default
533 * mask will be used. Ranging is not supported.
534 * @param efx_spec[in, out]
535 * EFX filter specification to update.
537 * Perform verbose error reporting if not NULL.
540 sfc_flow_parse_ipv6(const struct rte_flow_item *item,
541 struct sfc_flow_parse_ctx *parse_ctx,
542 struct rte_flow_error *error)
545 efx_filter_spec_t *efx_spec = parse_ctx->filter;
546 const struct rte_flow_item_ipv6 *spec = NULL;
547 const struct rte_flow_item_ipv6 *mask = NULL;
548 const uint16_t ether_type_ipv6 = rte_cpu_to_le_16(EFX_ETHER_TYPE_IPV6);
549 const struct rte_flow_item_ipv6 supp_mask = {
551 .src_addr = { 0xff, 0xff, 0xff, 0xff,
552 0xff, 0xff, 0xff, 0xff,
553 0xff, 0xff, 0xff, 0xff,
554 0xff, 0xff, 0xff, 0xff },
555 .dst_addr = { 0xff, 0xff, 0xff, 0xff,
556 0xff, 0xff, 0xff, 0xff,
557 0xff, 0xff, 0xff, 0xff,
558 0xff, 0xff, 0xff, 0xff },
563 rc = sfc_flow_parse_init(item,
564 (const void **)&spec,
565 (const void **)&mask,
567 &rte_flow_item_ipv6_mask,
568 sizeof(struct rte_flow_item_ipv6),
574 * Filtering by IPv6 source and destination addresses requires
575 * the appropriate ETHER_TYPE in hardware filters
577 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE)) {
578 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
579 efx_spec->efs_ether_type = ether_type_ipv6;
580 } else if (efx_spec->efs_ether_type != ether_type_ipv6) {
581 rte_flow_error_set(error, EINVAL,
582 RTE_FLOW_ERROR_TYPE_ITEM, item,
583 "Ethertype in pattern with IPV6 item should be appropriate");
591 * IPv6 addresses are in big-endian byte order in item and in
594 if (memcmp(mask->hdr.src_addr, supp_mask.hdr.src_addr,
595 sizeof(mask->hdr.src_addr)) == 0) {
596 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_HOST;
598 RTE_BUILD_BUG_ON(sizeof(efx_spec->efs_rem_host) !=
599 sizeof(spec->hdr.src_addr));
600 rte_memcpy(&efx_spec->efs_rem_host, spec->hdr.src_addr,
601 sizeof(efx_spec->efs_rem_host));
602 } else if (!sfc_flow_is_zero(mask->hdr.src_addr,
603 sizeof(mask->hdr.src_addr))) {
607 if (memcmp(mask->hdr.dst_addr, supp_mask.hdr.dst_addr,
608 sizeof(mask->hdr.dst_addr)) == 0) {
609 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_HOST;
611 RTE_BUILD_BUG_ON(sizeof(efx_spec->efs_loc_host) !=
612 sizeof(spec->hdr.dst_addr));
613 rte_memcpy(&efx_spec->efs_loc_host, spec->hdr.dst_addr,
614 sizeof(efx_spec->efs_loc_host));
615 } else if (!sfc_flow_is_zero(mask->hdr.dst_addr,
616 sizeof(mask->hdr.dst_addr))) {
620 if (mask->hdr.proto == supp_mask.hdr.proto) {
621 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
622 efx_spec->efs_ip_proto = spec->hdr.proto;
623 } else if (mask->hdr.proto != 0) {
630 rte_flow_error_set(error, EINVAL,
631 RTE_FLOW_ERROR_TYPE_ITEM, item,
632 "Bad mask in the IPV6 pattern item");
637 * Convert TCP item to EFX filter specification.
640 * Item specification. Only source and destination ports fields
641 * are supported. If the mask is NULL, default mask will be used.
642 * Ranging is not supported.
643 * @param efx_spec[in, out]
644 * EFX filter specification to update.
646 * Perform verbose error reporting if not NULL.
649 sfc_flow_parse_tcp(const struct rte_flow_item *item,
650 struct sfc_flow_parse_ctx *parse_ctx,
651 struct rte_flow_error *error)
654 efx_filter_spec_t *efx_spec = parse_ctx->filter;
655 const struct rte_flow_item_tcp *spec = NULL;
656 const struct rte_flow_item_tcp *mask = NULL;
657 const struct rte_flow_item_tcp supp_mask = {
664 rc = sfc_flow_parse_init(item,
665 (const void **)&spec,
666 (const void **)&mask,
668 &rte_flow_item_tcp_mask,
669 sizeof(struct rte_flow_item_tcp),
675 * Filtering by TCP source and destination ports requires
676 * the appropriate IP_PROTO in hardware filters
678 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_IP_PROTO)) {
679 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
680 efx_spec->efs_ip_proto = EFX_IPPROTO_TCP;
681 } else if (efx_spec->efs_ip_proto != EFX_IPPROTO_TCP) {
682 rte_flow_error_set(error, EINVAL,
683 RTE_FLOW_ERROR_TYPE_ITEM, item,
684 "IP proto in pattern with TCP item should be appropriate");
692 * Source and destination ports are in big-endian byte order in item and
693 * in little-endian in efx_spec, so byte swap is used
695 if (mask->hdr.src_port == supp_mask.hdr.src_port) {
696 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_PORT;
697 efx_spec->efs_rem_port = rte_bswap16(spec->hdr.src_port);
698 } else if (mask->hdr.src_port != 0) {
702 if (mask->hdr.dst_port == supp_mask.hdr.dst_port) {
703 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_PORT;
704 efx_spec->efs_loc_port = rte_bswap16(spec->hdr.dst_port);
705 } else if (mask->hdr.dst_port != 0) {
712 rte_flow_error_set(error, EINVAL,
713 RTE_FLOW_ERROR_TYPE_ITEM, item,
714 "Bad mask in the TCP pattern item");
719 * Convert UDP item to EFX filter specification.
722 * Item specification. Only source and destination ports fields
723 * are supported. If the mask is NULL, default mask will be used.
724 * Ranging is not supported.
725 * @param efx_spec[in, out]
726 * EFX filter specification to update.
728 * Perform verbose error reporting if not NULL.
731 sfc_flow_parse_udp(const struct rte_flow_item *item,
732 struct sfc_flow_parse_ctx *parse_ctx,
733 struct rte_flow_error *error)
736 efx_filter_spec_t *efx_spec = parse_ctx->filter;
737 const struct rte_flow_item_udp *spec = NULL;
738 const struct rte_flow_item_udp *mask = NULL;
739 const struct rte_flow_item_udp supp_mask = {
746 rc = sfc_flow_parse_init(item,
747 (const void **)&spec,
748 (const void **)&mask,
750 &rte_flow_item_udp_mask,
751 sizeof(struct rte_flow_item_udp),
757 * Filtering by UDP source and destination ports requires
758 * the appropriate IP_PROTO in hardware filters
760 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_IP_PROTO)) {
761 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
762 efx_spec->efs_ip_proto = EFX_IPPROTO_UDP;
763 } else if (efx_spec->efs_ip_proto != EFX_IPPROTO_UDP) {
764 rte_flow_error_set(error, EINVAL,
765 RTE_FLOW_ERROR_TYPE_ITEM, item,
766 "IP proto in pattern with UDP item should be appropriate");
774 * Source and destination ports are in big-endian byte order in item and
775 * in little-endian in efx_spec, so byte swap is used
777 if (mask->hdr.src_port == supp_mask.hdr.src_port) {
778 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_PORT;
779 efx_spec->efs_rem_port = rte_bswap16(spec->hdr.src_port);
780 } else if (mask->hdr.src_port != 0) {
784 if (mask->hdr.dst_port == supp_mask.hdr.dst_port) {
785 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_PORT;
786 efx_spec->efs_loc_port = rte_bswap16(spec->hdr.dst_port);
787 } else if (mask->hdr.dst_port != 0) {
794 rte_flow_error_set(error, EINVAL,
795 RTE_FLOW_ERROR_TYPE_ITEM, item,
796 "Bad mask in the UDP pattern item");
801 * Filters for encapsulated packets match based on the EtherType and IP
802 * protocol in the outer frame.
805 sfc_flow_set_match_flags_for_encap_pkts(const struct rte_flow_item *item,
806 efx_filter_spec_t *efx_spec,
808 struct rte_flow_error *error)
810 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_IP_PROTO)) {
811 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
812 efx_spec->efs_ip_proto = ip_proto;
813 } else if (efx_spec->efs_ip_proto != ip_proto) {
815 case EFX_IPPROTO_UDP:
816 rte_flow_error_set(error, EINVAL,
817 RTE_FLOW_ERROR_TYPE_ITEM, item,
818 "Outer IP header protocol must be UDP "
819 "in VxLAN/GENEVE pattern");
822 case EFX_IPPROTO_GRE:
823 rte_flow_error_set(error, EINVAL,
824 RTE_FLOW_ERROR_TYPE_ITEM, item,
825 "Outer IP header protocol must be GRE "
830 rte_flow_error_set(error, EINVAL,
831 RTE_FLOW_ERROR_TYPE_ITEM, item,
832 "Only VxLAN/GENEVE/NVGRE tunneling patterns "
838 if (efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
839 efx_spec->efs_ether_type != EFX_ETHER_TYPE_IPV4 &&
840 efx_spec->efs_ether_type != EFX_ETHER_TYPE_IPV6) {
841 rte_flow_error_set(error, EINVAL,
842 RTE_FLOW_ERROR_TYPE_ITEM, item,
843 "Outer frame EtherType in pattern with tunneling "
844 "must be IPv4 or IPv6");
852 sfc_flow_set_efx_spec_vni_or_vsid(efx_filter_spec_t *efx_spec,
853 const uint8_t *vni_or_vsid_val,
854 const uint8_t *vni_or_vsid_mask,
855 const struct rte_flow_item *item,
856 struct rte_flow_error *error)
858 const uint8_t vni_or_vsid_full_mask[EFX_VNI_OR_VSID_LEN] = {
862 if (memcmp(vni_or_vsid_mask, vni_or_vsid_full_mask,
863 EFX_VNI_OR_VSID_LEN) == 0) {
864 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_VNI_OR_VSID;
865 rte_memcpy(efx_spec->efs_vni_or_vsid, vni_or_vsid_val,
866 EFX_VNI_OR_VSID_LEN);
867 } else if (!sfc_flow_is_zero(vni_or_vsid_mask, EFX_VNI_OR_VSID_LEN)) {
868 rte_flow_error_set(error, EINVAL,
869 RTE_FLOW_ERROR_TYPE_ITEM, item,
870 "Unsupported VNI/VSID mask");
878 * Convert VXLAN item to EFX filter specification.
881 * Item specification. Only VXLAN network identifier field is supported.
882 * If the mask is NULL, default mask will be used.
883 * Ranging is not supported.
884 * @param efx_spec[in, out]
885 * EFX filter specification to update.
887 * Perform verbose error reporting if not NULL.
890 sfc_flow_parse_vxlan(const struct rte_flow_item *item,
891 struct sfc_flow_parse_ctx *parse_ctx,
892 struct rte_flow_error *error)
895 efx_filter_spec_t *efx_spec = parse_ctx->filter;
896 const struct rte_flow_item_vxlan *spec = NULL;
897 const struct rte_flow_item_vxlan *mask = NULL;
898 const struct rte_flow_item_vxlan supp_mask = {
899 .vni = { 0xff, 0xff, 0xff }
902 rc = sfc_flow_parse_init(item,
903 (const void **)&spec,
904 (const void **)&mask,
906 &rte_flow_item_vxlan_mask,
907 sizeof(struct rte_flow_item_vxlan),
912 rc = sfc_flow_set_match_flags_for_encap_pkts(item, efx_spec,
913 EFX_IPPROTO_UDP, error);
917 efx_spec->efs_encap_type = EFX_TUNNEL_PROTOCOL_VXLAN;
918 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
923 rc = sfc_flow_set_efx_spec_vni_or_vsid(efx_spec, spec->vni,
924 mask->vni, item, error);
930 * Convert GENEVE item to EFX filter specification.
933 * Item specification. Only Virtual Network Identifier and protocol type
934 * fields are supported. But protocol type can be only Ethernet (0x6558).
935 * If the mask is NULL, default mask will be used.
936 * Ranging is not supported.
937 * @param efx_spec[in, out]
938 * EFX filter specification to update.
940 * Perform verbose error reporting if not NULL.
943 sfc_flow_parse_geneve(const struct rte_flow_item *item,
944 struct sfc_flow_parse_ctx *parse_ctx,
945 struct rte_flow_error *error)
948 efx_filter_spec_t *efx_spec = parse_ctx->filter;
949 const struct rte_flow_item_geneve *spec = NULL;
950 const struct rte_flow_item_geneve *mask = NULL;
951 const struct rte_flow_item_geneve supp_mask = {
952 .protocol = RTE_BE16(0xffff),
953 .vni = { 0xff, 0xff, 0xff }
956 rc = sfc_flow_parse_init(item,
957 (const void **)&spec,
958 (const void **)&mask,
960 &rte_flow_item_geneve_mask,
961 sizeof(struct rte_flow_item_geneve),
966 rc = sfc_flow_set_match_flags_for_encap_pkts(item, efx_spec,
967 EFX_IPPROTO_UDP, error);
971 efx_spec->efs_encap_type = EFX_TUNNEL_PROTOCOL_GENEVE;
972 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
977 if (mask->protocol == supp_mask.protocol) {
978 if (spec->protocol != rte_cpu_to_be_16(RTE_ETHER_TYPE_TEB)) {
979 rte_flow_error_set(error, EINVAL,
980 RTE_FLOW_ERROR_TYPE_ITEM, item,
981 "GENEVE encap. protocol must be Ethernet "
982 "(0x6558) in the GENEVE pattern item");
985 } else if (mask->protocol != 0) {
986 rte_flow_error_set(error, EINVAL,
987 RTE_FLOW_ERROR_TYPE_ITEM, item,
988 "Unsupported mask for GENEVE encap. protocol");
992 rc = sfc_flow_set_efx_spec_vni_or_vsid(efx_spec, spec->vni,
993 mask->vni, item, error);
999 * Convert NVGRE item to EFX filter specification.
1002 * Item specification. Only virtual subnet ID field is supported.
1003 * If the mask is NULL, default mask will be used.
1004 * Ranging is not supported.
1005 * @param efx_spec[in, out]
1006 * EFX filter specification to update.
1008 * Perform verbose error reporting if not NULL.
1011 sfc_flow_parse_nvgre(const struct rte_flow_item *item,
1012 struct sfc_flow_parse_ctx *parse_ctx,
1013 struct rte_flow_error *error)
1016 efx_filter_spec_t *efx_spec = parse_ctx->filter;
1017 const struct rte_flow_item_nvgre *spec = NULL;
1018 const struct rte_flow_item_nvgre *mask = NULL;
1019 const struct rte_flow_item_nvgre supp_mask = {
1020 .tni = { 0xff, 0xff, 0xff }
1023 rc = sfc_flow_parse_init(item,
1024 (const void **)&spec,
1025 (const void **)&mask,
1027 &rte_flow_item_nvgre_mask,
1028 sizeof(struct rte_flow_item_nvgre),
1033 rc = sfc_flow_set_match_flags_for_encap_pkts(item, efx_spec,
1034 EFX_IPPROTO_GRE, error);
1038 efx_spec->efs_encap_type = EFX_TUNNEL_PROTOCOL_NVGRE;
1039 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
1044 rc = sfc_flow_set_efx_spec_vni_or_vsid(efx_spec, spec->tni,
1045 mask->tni, item, error);
1050 static const struct sfc_flow_item sfc_flow_items[] = {
1052 .type = RTE_FLOW_ITEM_TYPE_VOID,
1053 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
1054 .layer = SFC_FLOW_ITEM_ANY_LAYER,
1055 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1056 .parse = sfc_flow_parse_void,
1059 .type = RTE_FLOW_ITEM_TYPE_ETH,
1060 .prev_layer = SFC_FLOW_ITEM_START_LAYER,
1061 .layer = SFC_FLOW_ITEM_L2,
1062 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1063 .parse = sfc_flow_parse_eth,
1066 .type = RTE_FLOW_ITEM_TYPE_VLAN,
1067 .prev_layer = SFC_FLOW_ITEM_L2,
1068 .layer = SFC_FLOW_ITEM_L2,
1069 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1070 .parse = sfc_flow_parse_vlan,
1073 .type = RTE_FLOW_ITEM_TYPE_IPV4,
1074 .prev_layer = SFC_FLOW_ITEM_L2,
1075 .layer = SFC_FLOW_ITEM_L3,
1076 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1077 .parse = sfc_flow_parse_ipv4,
1080 .type = RTE_FLOW_ITEM_TYPE_IPV6,
1081 .prev_layer = SFC_FLOW_ITEM_L2,
1082 .layer = SFC_FLOW_ITEM_L3,
1083 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1084 .parse = sfc_flow_parse_ipv6,
1087 .type = RTE_FLOW_ITEM_TYPE_TCP,
1088 .prev_layer = SFC_FLOW_ITEM_L3,
1089 .layer = SFC_FLOW_ITEM_L4,
1090 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1091 .parse = sfc_flow_parse_tcp,
1094 .type = RTE_FLOW_ITEM_TYPE_UDP,
1095 .prev_layer = SFC_FLOW_ITEM_L3,
1096 .layer = SFC_FLOW_ITEM_L4,
1097 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1098 .parse = sfc_flow_parse_udp,
1101 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
1102 .prev_layer = SFC_FLOW_ITEM_L4,
1103 .layer = SFC_FLOW_ITEM_START_LAYER,
1104 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1105 .parse = sfc_flow_parse_vxlan,
1108 .type = RTE_FLOW_ITEM_TYPE_GENEVE,
1109 .prev_layer = SFC_FLOW_ITEM_L4,
1110 .layer = SFC_FLOW_ITEM_START_LAYER,
1111 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1112 .parse = sfc_flow_parse_geneve,
1115 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
1116 .prev_layer = SFC_FLOW_ITEM_L3,
1117 .layer = SFC_FLOW_ITEM_START_LAYER,
1118 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1119 .parse = sfc_flow_parse_nvgre,
1124 * Protocol-independent flow API support
1127 sfc_flow_parse_attr(const struct rte_flow_attr *attr,
1128 struct rte_flow *flow,
1129 struct rte_flow_error *error)
1131 struct sfc_flow_spec *spec = &flow->spec;
1132 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1135 rte_flow_error_set(error, EINVAL,
1136 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
1140 if (attr->group != 0) {
1141 rte_flow_error_set(error, ENOTSUP,
1142 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, attr,
1143 "Groups are not supported");
1146 if (attr->egress != 0) {
1147 rte_flow_error_set(error, ENOTSUP,
1148 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attr,
1149 "Egress is not supported");
1152 if (attr->ingress == 0) {
1153 rte_flow_error_set(error, ENOTSUP,
1154 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, attr,
1155 "Ingress is compulsory");
1158 if (attr->transfer == 0) {
1159 if (attr->priority != 0) {
1160 rte_flow_error_set(error, ENOTSUP,
1161 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1162 attr, "Priorities are unsupported");
1165 spec->type = SFC_FLOW_SPEC_FILTER;
1166 spec_filter->template.efs_flags |= EFX_FILTER_FLAG_RX;
1167 spec_filter->template.efs_rss_context = EFX_RSS_CONTEXT_DEFAULT;
1168 spec_filter->template.efs_priority = EFX_FILTER_PRI_MANUAL;
1170 rte_flow_error_set(error, ENOTSUP,
1171 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER, attr,
1172 "Transfer is not supported");
1179 /* Get item from array sfc_flow_items */
1180 static const struct sfc_flow_item *
1181 sfc_flow_get_item(const struct sfc_flow_item *items,
1182 unsigned int nb_items,
1183 enum rte_flow_item_type type)
1187 for (i = 0; i < nb_items; i++)
1188 if (items[i].type == type)
1195 sfc_flow_parse_pattern(const struct sfc_flow_item *flow_items,
1196 unsigned int nb_flow_items,
1197 const struct rte_flow_item pattern[],
1198 struct sfc_flow_parse_ctx *parse_ctx,
1199 struct rte_flow_error *error)
1202 unsigned int prev_layer = SFC_FLOW_ITEM_ANY_LAYER;
1203 boolean_t is_ifrm = B_FALSE;
1204 const struct sfc_flow_item *item;
1206 if (pattern == NULL) {
1207 rte_flow_error_set(error, EINVAL,
1208 RTE_FLOW_ERROR_TYPE_ITEM_NUM, NULL,
1213 for (; pattern->type != RTE_FLOW_ITEM_TYPE_END; pattern++) {
1214 item = sfc_flow_get_item(flow_items, nb_flow_items,
1217 rte_flow_error_set(error, ENOTSUP,
1218 RTE_FLOW_ERROR_TYPE_ITEM, pattern,
1219 "Unsupported pattern item");
1224 * Omitting one or several protocol layers at the beginning
1225 * of pattern is supported
1227 if (item->prev_layer != SFC_FLOW_ITEM_ANY_LAYER &&
1228 prev_layer != SFC_FLOW_ITEM_ANY_LAYER &&
1229 item->prev_layer != prev_layer) {
1230 rte_flow_error_set(error, ENOTSUP,
1231 RTE_FLOW_ERROR_TYPE_ITEM, pattern,
1232 "Unexpected sequence of pattern items");
1237 * Allow only VOID and ETH pattern items in the inner frame.
1238 * Also check that there is only one tunneling protocol.
1240 switch (item->type) {
1241 case RTE_FLOW_ITEM_TYPE_VOID:
1242 case RTE_FLOW_ITEM_TYPE_ETH:
1245 case RTE_FLOW_ITEM_TYPE_VXLAN:
1246 case RTE_FLOW_ITEM_TYPE_GENEVE:
1247 case RTE_FLOW_ITEM_TYPE_NVGRE:
1249 rte_flow_error_set(error, EINVAL,
1250 RTE_FLOW_ERROR_TYPE_ITEM,
1252 "More than one tunneling protocol");
1260 rte_flow_error_set(error, EINVAL,
1261 RTE_FLOW_ERROR_TYPE_ITEM,
1263 "There is an unsupported pattern item "
1264 "in the inner frame");
1270 if (parse_ctx->type != item->ctx_type) {
1271 rte_flow_error_set(error, EINVAL,
1272 RTE_FLOW_ERROR_TYPE_ITEM, pattern,
1273 "Parse context type mismatch");
1277 rc = item->parse(pattern, parse_ctx, error);
1281 if (item->layer != SFC_FLOW_ITEM_ANY_LAYER)
1282 prev_layer = item->layer;
1289 sfc_flow_parse_queue(struct sfc_adapter *sa,
1290 const struct rte_flow_action_queue *queue,
1291 struct rte_flow *flow)
1293 struct sfc_flow_spec *spec = &flow->spec;
1294 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1295 struct sfc_rxq *rxq;
1296 struct sfc_rxq_info *rxq_info;
1298 if (queue->index >= sfc_sa2shared(sa)->rxq_count)
1301 rxq = &sa->rxq_ctrl[queue->index];
1302 spec_filter->template.efs_dmaq_id = (uint16_t)rxq->hw_index;
1304 rxq_info = &sfc_sa2shared(sa)->rxq_info[queue->index];
1305 spec_filter->rss_hash_required = !!(rxq_info->rxq_flags &
1306 SFC_RXQ_FLAG_RSS_HASH);
1312 sfc_flow_parse_rss(struct sfc_adapter *sa,
1313 const struct rte_flow_action_rss *action_rss,
1314 struct rte_flow *flow)
1316 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
1317 struct sfc_rss *rss = &sas->rss;
1318 unsigned int rxq_sw_index;
1319 struct sfc_rxq *rxq;
1320 unsigned int rxq_hw_index_min;
1321 unsigned int rxq_hw_index_max;
1322 efx_rx_hash_type_t efx_hash_types;
1323 const uint8_t *rss_key;
1324 struct sfc_flow_spec *spec = &flow->spec;
1325 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1326 struct sfc_flow_rss *sfc_rss_conf = &spec_filter->rss_conf;
1329 if (action_rss->queue_num == 0)
1332 rxq_sw_index = sfc_sa2shared(sa)->rxq_count - 1;
1333 rxq = &sa->rxq_ctrl[rxq_sw_index];
1334 rxq_hw_index_min = rxq->hw_index;
1335 rxq_hw_index_max = 0;
1337 for (i = 0; i < action_rss->queue_num; ++i) {
1338 rxq_sw_index = action_rss->queue[i];
1340 if (rxq_sw_index >= sfc_sa2shared(sa)->rxq_count)
1343 rxq = &sa->rxq_ctrl[rxq_sw_index];
1345 if (rxq->hw_index < rxq_hw_index_min)
1346 rxq_hw_index_min = rxq->hw_index;
1348 if (rxq->hw_index > rxq_hw_index_max)
1349 rxq_hw_index_max = rxq->hw_index;
1352 switch (action_rss->func) {
1353 case RTE_ETH_HASH_FUNCTION_DEFAULT:
1354 case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
1360 if (action_rss->level)
1364 * Dummy RSS action with only one queue and no specific settings
1365 * for hash types and key does not require dedicated RSS context
1366 * and may be simplified to single queue action.
1368 if (action_rss->queue_num == 1 && action_rss->types == 0 &&
1369 action_rss->key_len == 0) {
1370 spec_filter->template.efs_dmaq_id = rxq_hw_index_min;
1374 if (action_rss->types) {
1377 rc = sfc_rx_hf_rte_to_efx(sa, action_rss->types,
1385 for (i = 0; i < rss->hf_map_nb_entries; ++i)
1386 efx_hash_types |= rss->hf_map[i].efx;
1389 if (action_rss->key_len) {
1390 if (action_rss->key_len != sizeof(rss->key))
1393 rss_key = action_rss->key;
1398 spec_filter->rss = B_TRUE;
1400 sfc_rss_conf->rxq_hw_index_min = rxq_hw_index_min;
1401 sfc_rss_conf->rxq_hw_index_max = rxq_hw_index_max;
1402 sfc_rss_conf->rss_hash_types = efx_hash_types;
1403 rte_memcpy(sfc_rss_conf->rss_key, rss_key, sizeof(rss->key));
1405 for (i = 0; i < RTE_DIM(sfc_rss_conf->rss_tbl); ++i) {
1406 unsigned int nb_queues = action_rss->queue_num;
1407 unsigned int rxq_sw_index = action_rss->queue[i % nb_queues];
1408 struct sfc_rxq *rxq = &sa->rxq_ctrl[rxq_sw_index];
1410 sfc_rss_conf->rss_tbl[i] = rxq->hw_index - rxq_hw_index_min;
1417 sfc_flow_spec_flush(struct sfc_adapter *sa, struct sfc_flow_spec *spec,
1418 unsigned int filters_count)
1420 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1424 for (i = 0; i < filters_count; i++) {
1427 rc = efx_filter_remove(sa->nic, &spec_filter->filters[i]);
1428 if (ret == 0 && rc != 0) {
1429 sfc_err(sa, "failed to remove filter specification "
1439 sfc_flow_spec_insert(struct sfc_adapter *sa, struct sfc_flow_spec *spec)
1441 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1445 for (i = 0; i < spec_filter->count; i++) {
1446 rc = efx_filter_insert(sa->nic, &spec_filter->filters[i]);
1448 sfc_flow_spec_flush(sa, spec, i);
1457 sfc_flow_spec_remove(struct sfc_adapter *sa, struct sfc_flow_spec *spec)
1459 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1461 return sfc_flow_spec_flush(sa, spec, spec_filter->count);
1465 sfc_flow_filter_insert(struct sfc_adapter *sa,
1466 struct rte_flow *flow)
1468 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
1469 struct sfc_rss *rss = &sas->rss;
1470 struct sfc_flow_spec_filter *spec_filter = &flow->spec.filter;
1471 struct sfc_flow_rss *flow_rss = &spec_filter->rss_conf;
1472 uint32_t efs_rss_context = EFX_RSS_CONTEXT_DEFAULT;
1473 boolean_t create_context;
1477 create_context = spec_filter->rss || (spec_filter->rss_hash_required &&
1478 rss->dummy_rss_context == EFX_RSS_CONTEXT_DEFAULT);
1480 if (create_context) {
1481 unsigned int rss_spread;
1482 unsigned int rss_hash_types;
1485 if (spec_filter->rss) {
1486 rss_spread = MIN(flow_rss->rxq_hw_index_max -
1487 flow_rss->rxq_hw_index_min + 1,
1489 rss_hash_types = flow_rss->rss_hash_types;
1490 rss_key = flow_rss->rss_key;
1493 * Initialize dummy RSS context parameters to have
1494 * valid RSS hash. Use default RSS hash function and
1498 rss_hash_types = rss->hash_types;
1502 rc = efx_rx_scale_context_alloc(sa->nic,
1503 EFX_RX_SCALE_EXCLUSIVE,
1507 goto fail_scale_context_alloc;
1509 rc = efx_rx_scale_mode_set(sa->nic, efs_rss_context,
1511 rss_hash_types, B_TRUE);
1513 goto fail_scale_mode_set;
1515 rc = efx_rx_scale_key_set(sa->nic, efs_rss_context,
1516 rss_key, sizeof(rss->key));
1518 goto fail_scale_key_set;
1520 efs_rss_context = rss->dummy_rss_context;
1523 if (spec_filter->rss || spec_filter->rss_hash_required) {
1525 * At this point, fully elaborated filter specifications
1526 * have been produced from the template. To make sure that
1527 * RSS behaviour is consistent between them, set the same
1528 * RSS context value everywhere.
1530 for (i = 0; i < spec_filter->count; i++) {
1531 efx_filter_spec_t *spec = &spec_filter->filters[i];
1533 spec->efs_rss_context = efs_rss_context;
1534 spec->efs_flags |= EFX_FILTER_FLAG_RX_RSS;
1535 if (spec_filter->rss)
1536 spec->efs_dmaq_id = flow_rss->rxq_hw_index_min;
1540 rc = sfc_flow_spec_insert(sa, &flow->spec);
1542 goto fail_filter_insert;
1544 if (create_context) {
1545 unsigned int dummy_tbl[RTE_DIM(flow_rss->rss_tbl)] = {0};
1548 tbl = spec_filter->rss ? flow_rss->rss_tbl : dummy_tbl;
1551 * Scale table is set after filter insertion because
1552 * the table entries are relative to the base RxQ ID
1553 * and the latter is submitted to the HW by means of
1554 * inserting a filter, so by the time of the request
1555 * the HW knows all the information needed to verify
1556 * the table entries, and the operation will succeed
1558 rc = efx_rx_scale_tbl_set(sa->nic, efs_rss_context,
1559 tbl, RTE_DIM(flow_rss->rss_tbl));
1561 goto fail_scale_tbl_set;
1563 /* Remember created dummy RSS context */
1564 if (!spec_filter->rss)
1565 rss->dummy_rss_context = efs_rss_context;
1571 sfc_flow_spec_remove(sa, &flow->spec);
1575 fail_scale_mode_set:
1577 efx_rx_scale_context_free(sa->nic, efs_rss_context);
1579 fail_scale_context_alloc:
1584 sfc_flow_filter_remove(struct sfc_adapter *sa,
1585 struct rte_flow *flow)
1587 struct sfc_flow_spec_filter *spec_filter = &flow->spec.filter;
1590 rc = sfc_flow_spec_remove(sa, &flow->spec);
1594 if (spec_filter->rss) {
1596 * All specifications for a given flow rule have the same RSS
1597 * context, so that RSS context value is taken from the first
1598 * filter specification
1600 efx_filter_spec_t *spec = &spec_filter->filters[0];
1602 rc = efx_rx_scale_context_free(sa->nic, spec->efs_rss_context);
1609 sfc_flow_parse_mark(struct sfc_adapter *sa,
1610 const struct rte_flow_action_mark *mark,
1611 struct rte_flow *flow)
1613 struct sfc_flow_spec *spec = &flow->spec;
1614 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1615 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
1617 if (mark == NULL || mark->id > encp->enc_filter_action_mark_max)
1620 spec_filter->template.efs_flags |= EFX_FILTER_FLAG_ACTION_MARK;
1621 spec_filter->template.efs_mark = mark->id;
1627 sfc_flow_parse_actions(struct sfc_adapter *sa,
1628 const struct rte_flow_action actions[],
1629 struct rte_flow *flow,
1630 struct rte_flow_error *error)
1633 struct sfc_flow_spec *spec = &flow->spec;
1634 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1635 const unsigned int dp_rx_features = sa->priv.dp_rx->features;
1636 uint32_t actions_set = 0;
1637 const uint32_t fate_actions_mask = (1UL << RTE_FLOW_ACTION_TYPE_QUEUE) |
1638 (1UL << RTE_FLOW_ACTION_TYPE_RSS) |
1639 (1UL << RTE_FLOW_ACTION_TYPE_DROP);
1640 const uint32_t mark_actions_mask = (1UL << RTE_FLOW_ACTION_TYPE_MARK) |
1641 (1UL << RTE_FLOW_ACTION_TYPE_FLAG);
1643 if (actions == NULL) {
1644 rte_flow_error_set(error, EINVAL,
1645 RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
1650 #define SFC_BUILD_SET_OVERFLOW(_action, _set) \
1651 RTE_BUILD_BUG_ON(_action >= sizeof(_set) * CHAR_BIT)
1653 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1654 switch (actions->type) {
1655 case RTE_FLOW_ACTION_TYPE_VOID:
1656 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VOID,
1660 case RTE_FLOW_ACTION_TYPE_QUEUE:
1661 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_QUEUE,
1663 if ((actions_set & fate_actions_mask) != 0)
1664 goto fail_fate_actions;
1666 rc = sfc_flow_parse_queue(sa, actions->conf, flow);
1668 rte_flow_error_set(error, EINVAL,
1669 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1670 "Bad QUEUE action");
1675 case RTE_FLOW_ACTION_TYPE_RSS:
1676 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_RSS,
1678 if ((actions_set & fate_actions_mask) != 0)
1679 goto fail_fate_actions;
1681 rc = sfc_flow_parse_rss(sa, actions->conf, flow);
1683 rte_flow_error_set(error, -rc,
1684 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1690 case RTE_FLOW_ACTION_TYPE_DROP:
1691 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_DROP,
1693 if ((actions_set & fate_actions_mask) != 0)
1694 goto fail_fate_actions;
1696 spec_filter->template.efs_dmaq_id =
1697 EFX_FILTER_SPEC_RX_DMAQ_ID_DROP;
1700 case RTE_FLOW_ACTION_TYPE_FLAG:
1701 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_FLAG,
1703 if ((actions_set & mark_actions_mask) != 0)
1704 goto fail_actions_overlap;
1706 if ((dp_rx_features & SFC_DP_RX_FEAT_FLOW_FLAG) == 0) {
1707 rte_flow_error_set(error, ENOTSUP,
1708 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1709 "FLAG action is not supported on the current Rx datapath");
1713 spec_filter->template.efs_flags |=
1714 EFX_FILTER_FLAG_ACTION_FLAG;
1717 case RTE_FLOW_ACTION_TYPE_MARK:
1718 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_MARK,
1720 if ((actions_set & mark_actions_mask) != 0)
1721 goto fail_actions_overlap;
1723 if ((dp_rx_features & SFC_DP_RX_FEAT_FLOW_MARK) == 0) {
1724 rte_flow_error_set(error, ENOTSUP,
1725 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1726 "MARK action is not supported on the current Rx datapath");
1730 rc = sfc_flow_parse_mark(sa, actions->conf, flow);
1732 rte_flow_error_set(error, rc,
1733 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1740 rte_flow_error_set(error, ENOTSUP,
1741 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1742 "Action is not supported");
1746 actions_set |= (1UL << actions->type);
1748 #undef SFC_BUILD_SET_OVERFLOW
1750 /* When fate is unknown, drop traffic. */
1751 if ((actions_set & fate_actions_mask) == 0) {
1752 spec_filter->template.efs_dmaq_id =
1753 EFX_FILTER_SPEC_RX_DMAQ_ID_DROP;
1759 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, actions,
1760 "Cannot combine several fate-deciding actions, "
1761 "choose between QUEUE, RSS or DROP");
1764 fail_actions_overlap:
1765 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, actions,
1766 "Overlapping actions are not supported");
1771 * Set the EFX_FILTER_MATCH_UNKNOWN_UCAST_DST
1772 * and EFX_FILTER_MATCH_UNKNOWN_MCAST_DST match flags in the same
1773 * specifications after copying.
1775 * @param spec[in, out]
1776 * SFC flow specification to update.
1777 * @param filters_count_for_one_val[in]
1778 * How many specifications should have the same match flag, what is the
1779 * number of specifications before copying.
1781 * Perform verbose error reporting if not NULL.
1784 sfc_flow_set_unknown_dst_flags(struct sfc_flow_spec *spec,
1785 unsigned int filters_count_for_one_val,
1786 struct rte_flow_error *error)
1789 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1790 static const efx_filter_match_flags_t vals[] = {
1791 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST,
1792 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST
1795 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
1796 rte_flow_error_set(error, EINVAL,
1797 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1798 "Number of specifications is incorrect while copying "
1799 "by unknown destination flags");
1803 for (i = 0; i < spec_filter->count; i++) {
1804 /* The check above ensures that divisor can't be zero here */
1805 spec_filter->filters[i].efs_match_flags |=
1806 vals[i / filters_count_for_one_val];
1813 * Check that the following conditions are met:
1814 * - the list of supported filters has a filter
1815 * with EFX_FILTER_MATCH_UNKNOWN_MCAST_DST flag instead of
1816 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST, since this filter will also
1820 * The match flags of filter.
1822 * Specification to be supplemented.
1824 * SFC filter with list of supported filters.
1827 sfc_flow_check_unknown_dst_flags(efx_filter_match_flags_t match,
1828 __rte_unused efx_filter_spec_t *spec,
1829 struct sfc_filter *filter)
1832 efx_filter_match_flags_t match_mcast_dst;
1835 (match & ~EFX_FILTER_MATCH_UNKNOWN_UCAST_DST) |
1836 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST;
1837 for (i = 0; i < filter->supported_match_num; i++) {
1838 if (match_mcast_dst == filter->supported_match[i])
1846 * Set the EFX_FILTER_MATCH_ETHER_TYPE match flag and EFX_ETHER_TYPE_IPV4 and
1847 * EFX_ETHER_TYPE_IPV6 values of the corresponding field in the same
1848 * specifications after copying.
1850 * @param spec[in, out]
1851 * SFC flow specification to update.
1852 * @param filters_count_for_one_val[in]
1853 * How many specifications should have the same EtherType value, what is the
1854 * number of specifications before copying.
1856 * Perform verbose error reporting if not NULL.
1859 sfc_flow_set_ethertypes(struct sfc_flow_spec *spec,
1860 unsigned int filters_count_for_one_val,
1861 struct rte_flow_error *error)
1864 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1865 static const uint16_t vals[] = {
1866 EFX_ETHER_TYPE_IPV4, EFX_ETHER_TYPE_IPV6
1869 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
1870 rte_flow_error_set(error, EINVAL,
1871 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1872 "Number of specifications is incorrect "
1873 "while copying by Ethertype");
1877 for (i = 0; i < spec_filter->count; i++) {
1878 spec_filter->filters[i].efs_match_flags |=
1879 EFX_FILTER_MATCH_ETHER_TYPE;
1882 * The check above ensures that
1883 * filters_count_for_one_val is not 0
1885 spec_filter->filters[i].efs_ether_type =
1886 vals[i / filters_count_for_one_val];
1893 * Set the EFX_FILTER_MATCH_OUTER_VID match flag with value 0
1894 * in the same specifications after copying.
1896 * @param spec[in, out]
1897 * SFC flow specification to update.
1898 * @param filters_count_for_one_val[in]
1899 * How many specifications should have the same match flag, what is the
1900 * number of specifications before copying.
1902 * Perform verbose error reporting if not NULL.
1905 sfc_flow_set_outer_vid_flag(struct sfc_flow_spec *spec,
1906 unsigned int filters_count_for_one_val,
1907 struct rte_flow_error *error)
1909 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1912 if (filters_count_for_one_val != spec_filter->count) {
1913 rte_flow_error_set(error, EINVAL,
1914 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1915 "Number of specifications is incorrect "
1916 "while copying by outer VLAN ID");
1920 for (i = 0; i < spec_filter->count; i++) {
1921 spec_filter->filters[i].efs_match_flags |=
1922 EFX_FILTER_MATCH_OUTER_VID;
1924 spec_filter->filters[i].efs_outer_vid = 0;
1931 * Set the EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST and
1932 * EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST match flags in the same
1933 * specifications after copying.
1935 * @param spec[in, out]
1936 * SFC flow specification to update.
1937 * @param filters_count_for_one_val[in]
1938 * How many specifications should have the same match flag, what is the
1939 * number of specifications before copying.
1941 * Perform verbose error reporting if not NULL.
1944 sfc_flow_set_ifrm_unknown_dst_flags(struct sfc_flow_spec *spec,
1945 unsigned int filters_count_for_one_val,
1946 struct rte_flow_error *error)
1949 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1950 static const efx_filter_match_flags_t vals[] = {
1951 EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST,
1952 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST
1955 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
1956 rte_flow_error_set(error, EINVAL,
1957 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1958 "Number of specifications is incorrect while copying "
1959 "by inner frame unknown destination flags");
1963 for (i = 0; i < spec_filter->count; i++) {
1964 /* The check above ensures that divisor can't be zero here */
1965 spec_filter->filters[i].efs_match_flags |=
1966 vals[i / filters_count_for_one_val];
1973 * Check that the following conditions are met:
1974 * - the specification corresponds to a filter for encapsulated traffic
1975 * - the list of supported filters has a filter
1976 * with EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST flag instead of
1977 * EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST, since this filter will also
1981 * The match flags of filter.
1983 * Specification to be supplemented.
1985 * SFC filter with list of supported filters.
1988 sfc_flow_check_ifrm_unknown_dst_flags(efx_filter_match_flags_t match,
1989 efx_filter_spec_t *spec,
1990 struct sfc_filter *filter)
1993 efx_tunnel_protocol_t encap_type = spec->efs_encap_type;
1994 efx_filter_match_flags_t match_mcast_dst;
1996 if (encap_type == EFX_TUNNEL_PROTOCOL_NONE)
2000 (match & ~EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST) |
2001 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST;
2002 for (i = 0; i < filter->supported_match_num; i++) {
2003 if (match_mcast_dst == filter->supported_match[i])
2011 * Check that the list of supported filters has a filter that differs
2012 * from @p match in that it has no flag EFX_FILTER_MATCH_OUTER_VID
2013 * in this case that filter will be used and the flag
2014 * EFX_FILTER_MATCH_OUTER_VID is not needed.
2017 * The match flags of filter.
2019 * Specification to be supplemented.
2021 * SFC filter with list of supported filters.
2024 sfc_flow_check_outer_vid_flag(efx_filter_match_flags_t match,
2025 __rte_unused efx_filter_spec_t *spec,
2026 struct sfc_filter *filter)
2029 efx_filter_match_flags_t match_without_vid =
2030 match & ~EFX_FILTER_MATCH_OUTER_VID;
2032 for (i = 0; i < filter->supported_match_num; i++) {
2033 if (match_without_vid == filter->supported_match[i])
2041 * Match flags that can be automatically added to filters.
2042 * Selecting the last minimum when searching for the copy flag ensures that the
2043 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST flag has a higher priority than
2044 * EFX_FILTER_MATCH_ETHER_TYPE. This is because the filter
2045 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST is at the end of the list of supported
2048 static const struct sfc_flow_copy_flag sfc_flow_copy_flags[] = {
2050 .flag = EFX_FILTER_MATCH_UNKNOWN_UCAST_DST,
2052 .set_vals = sfc_flow_set_unknown_dst_flags,
2053 .spec_check = sfc_flow_check_unknown_dst_flags,
2056 .flag = EFX_FILTER_MATCH_ETHER_TYPE,
2058 .set_vals = sfc_flow_set_ethertypes,
2062 .flag = EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST,
2064 .set_vals = sfc_flow_set_ifrm_unknown_dst_flags,
2065 .spec_check = sfc_flow_check_ifrm_unknown_dst_flags,
2068 .flag = EFX_FILTER_MATCH_OUTER_VID,
2070 .set_vals = sfc_flow_set_outer_vid_flag,
2071 .spec_check = sfc_flow_check_outer_vid_flag,
2075 /* Get item from array sfc_flow_copy_flags */
2076 static const struct sfc_flow_copy_flag *
2077 sfc_flow_get_copy_flag(efx_filter_match_flags_t flag)
2081 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
2082 if (sfc_flow_copy_flags[i].flag == flag)
2083 return &sfc_flow_copy_flags[i];
2090 * Make copies of the specifications, set match flag and values
2091 * of the field that corresponds to it.
2093 * @param spec[in, out]
2094 * SFC flow specification to update.
2096 * The match flag to add.
2098 * Perform verbose error reporting if not NULL.
2101 sfc_flow_spec_add_match_flag(struct sfc_flow_spec *spec,
2102 efx_filter_match_flags_t flag,
2103 struct rte_flow_error *error)
2106 unsigned int new_filters_count;
2107 unsigned int filters_count_for_one_val;
2108 const struct sfc_flow_copy_flag *copy_flag;
2109 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2112 copy_flag = sfc_flow_get_copy_flag(flag);
2113 if (copy_flag == NULL) {
2114 rte_flow_error_set(error, ENOTSUP,
2115 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2116 "Unsupported spec field for copying");
2120 new_filters_count = spec_filter->count * copy_flag->vals_count;
2121 if (new_filters_count > SF_FLOW_SPEC_NB_FILTERS_MAX) {
2122 rte_flow_error_set(error, EINVAL,
2123 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2124 "Too much EFX specifications in the flow rule");
2128 /* Copy filters specifications */
2129 for (i = spec_filter->count; i < new_filters_count; i++) {
2130 spec_filter->filters[i] =
2131 spec_filter->filters[i - spec_filter->count];
2134 filters_count_for_one_val = spec_filter->count;
2135 spec_filter->count = new_filters_count;
2137 rc = copy_flag->set_vals(spec, filters_count_for_one_val, error);
2145 * Check that the given set of match flags missing in the original filter spec
2146 * could be covered by adding spec copies which specify the corresponding
2147 * flags and packet field values to match.
2149 * @param miss_flags[in]
2150 * Flags that are missing until the supported filter.
2152 * Specification to be supplemented.
2157 * Number of specifications after copy or 0, if the flags can not be added.
2160 sfc_flow_check_missing_flags(efx_filter_match_flags_t miss_flags,
2161 efx_filter_spec_t *spec,
2162 struct sfc_filter *filter)
2165 efx_filter_match_flags_t copy_flags = 0;
2166 efx_filter_match_flags_t flag;
2167 efx_filter_match_flags_t match = spec->efs_match_flags | miss_flags;
2168 sfc_flow_spec_check *check;
2169 unsigned int multiplier = 1;
2171 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
2172 flag = sfc_flow_copy_flags[i].flag;
2173 check = sfc_flow_copy_flags[i].spec_check;
2174 if ((flag & miss_flags) == flag) {
2175 if (check != NULL && (!check(match, spec, filter)))
2179 multiplier *= sfc_flow_copy_flags[i].vals_count;
2183 if (copy_flags == miss_flags)
2190 * Attempt to supplement the specification template to the minimally
2191 * supported set of match flags. To do this, it is necessary to copy
2192 * the specifications, filling them with the values of fields that
2193 * correspond to the missing flags.
2194 * The necessary and sufficient filter is built from the fewest number
2195 * of copies which could be made to cover the minimally required set
2200 * @param spec[in, out]
2201 * SFC flow specification to update.
2203 * Perform verbose error reporting if not NULL.
2206 sfc_flow_spec_filters_complete(struct sfc_adapter *sa,
2207 struct sfc_flow_spec *spec,
2208 struct rte_flow_error *error)
2210 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2211 struct sfc_filter *filter = &sa->filter;
2212 efx_filter_match_flags_t miss_flags;
2213 efx_filter_match_flags_t min_miss_flags = 0;
2214 efx_filter_match_flags_t match;
2215 unsigned int min_multiplier = UINT_MAX;
2216 unsigned int multiplier;
2220 match = spec_filter->template.efs_match_flags;
2221 for (i = 0; i < filter->supported_match_num; i++) {
2222 if ((match & filter->supported_match[i]) == match) {
2223 miss_flags = filter->supported_match[i] & (~match);
2224 multiplier = sfc_flow_check_missing_flags(miss_flags,
2225 &spec_filter->template, filter);
2226 if (multiplier > 0) {
2227 if (multiplier <= min_multiplier) {
2228 min_multiplier = multiplier;
2229 min_miss_flags = miss_flags;
2235 if (min_multiplier == UINT_MAX) {
2236 rte_flow_error_set(error, ENOTSUP,
2237 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2238 "The flow rule pattern is unsupported");
2242 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
2243 efx_filter_match_flags_t flag = sfc_flow_copy_flags[i].flag;
2245 if ((flag & min_miss_flags) == flag) {
2246 rc = sfc_flow_spec_add_match_flag(spec, flag, error);
2256 * Check that set of match flags is referred to by a filter. Filter is
2257 * described by match flags with the ability to add OUTER_VID and INNER_VID
2260 * @param match_flags[in]
2261 * Set of match flags.
2262 * @param flags_pattern[in]
2263 * Pattern of filter match flags.
2266 sfc_flow_is_match_with_vids(efx_filter_match_flags_t match_flags,
2267 efx_filter_match_flags_t flags_pattern)
2269 if ((match_flags & flags_pattern) != flags_pattern)
2272 switch (match_flags & ~flags_pattern) {
2274 case EFX_FILTER_MATCH_OUTER_VID:
2275 case EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_INNER_VID:
2283 * Check whether the spec maps to a hardware filter which is known to be
2284 * ineffective despite being valid.
2287 * SFC filter with list of supported filters.
2289 * SFC flow specification.
2292 sfc_flow_is_match_flags_exception(struct sfc_filter *filter,
2293 struct sfc_flow_spec *spec)
2296 uint16_t ether_type;
2298 efx_filter_match_flags_t match_flags;
2299 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2301 for (i = 0; i < spec_filter->count; i++) {
2302 match_flags = spec_filter->filters[i].efs_match_flags;
2304 if (sfc_flow_is_match_with_vids(match_flags,
2305 EFX_FILTER_MATCH_ETHER_TYPE) ||
2306 sfc_flow_is_match_with_vids(match_flags,
2307 EFX_FILTER_MATCH_ETHER_TYPE |
2308 EFX_FILTER_MATCH_LOC_MAC)) {
2309 ether_type = spec_filter->filters[i].efs_ether_type;
2310 if (filter->supports_ip_proto_or_addr_filter &&
2311 (ether_type == EFX_ETHER_TYPE_IPV4 ||
2312 ether_type == EFX_ETHER_TYPE_IPV6))
2314 } else if (sfc_flow_is_match_with_vids(match_flags,
2315 EFX_FILTER_MATCH_ETHER_TYPE |
2316 EFX_FILTER_MATCH_IP_PROTO) ||
2317 sfc_flow_is_match_with_vids(match_flags,
2318 EFX_FILTER_MATCH_ETHER_TYPE |
2319 EFX_FILTER_MATCH_IP_PROTO |
2320 EFX_FILTER_MATCH_LOC_MAC)) {
2321 ip_proto = spec_filter->filters[i].efs_ip_proto;
2322 if (filter->supports_rem_or_local_port_filter &&
2323 (ip_proto == EFX_IPPROTO_TCP ||
2324 ip_proto == EFX_IPPROTO_UDP))
2333 sfc_flow_validate_match_flags(struct sfc_adapter *sa,
2334 struct rte_flow *flow,
2335 struct rte_flow_error *error)
2337 struct sfc_flow_spec *spec = &flow->spec;
2338 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2339 efx_filter_spec_t *spec_tmpl = &spec_filter->template;
2340 efx_filter_match_flags_t match_flags = spec_tmpl->efs_match_flags;
2343 /* Initialize the first filter spec with template */
2344 spec_filter->filters[0] = *spec_tmpl;
2345 spec_filter->count = 1;
2347 if (!sfc_filter_is_match_supported(sa, match_flags)) {
2348 rc = sfc_flow_spec_filters_complete(sa, &flow->spec, error);
2353 if (sfc_flow_is_match_flags_exception(&sa->filter, &flow->spec)) {
2354 rte_flow_error_set(error, ENOTSUP,
2355 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2356 "The flow rule pattern is unsupported");
2364 sfc_flow_parse_rte_to_filter(struct rte_eth_dev *dev,
2365 const struct rte_flow_item pattern[],
2366 const struct rte_flow_action actions[],
2367 struct rte_flow *flow,
2368 struct rte_flow_error *error)
2370 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2371 struct sfc_flow_spec *spec = &flow->spec;
2372 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2373 struct sfc_flow_parse_ctx ctx;
2376 ctx.type = SFC_FLOW_PARSE_CTX_FILTER;
2377 ctx.filter = &spec_filter->template;
2379 rc = sfc_flow_parse_pattern(sfc_flow_items, RTE_DIM(sfc_flow_items),
2380 pattern, &ctx, error);
2382 goto fail_bad_value;
2384 rc = sfc_flow_parse_actions(sa, actions, flow, error);
2386 goto fail_bad_value;
2388 rc = sfc_flow_validate_match_flags(sa, flow, error);
2390 goto fail_bad_value;
2399 sfc_flow_parse(struct rte_eth_dev *dev,
2400 const struct rte_flow_attr *attr,
2401 const struct rte_flow_item pattern[],
2402 const struct rte_flow_action actions[],
2403 struct rte_flow *flow,
2404 struct rte_flow_error *error)
2406 const struct sfc_flow_ops_by_spec *ops;
2409 rc = sfc_flow_parse_attr(attr, flow, error);
2413 ops = sfc_flow_get_ops_by_spec(flow);
2414 if (ops == NULL || ops->parse == NULL) {
2415 rte_flow_error_set(error, ENOTSUP,
2416 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2417 "No backend to handle this flow");
2421 return ops->parse(dev, pattern, actions, flow, error);
2424 static struct rte_flow *
2425 sfc_flow_zmalloc(struct rte_flow_error *error)
2427 struct rte_flow *flow;
2429 flow = rte_zmalloc("sfc_rte_flow", sizeof(*flow), 0);
2431 rte_flow_error_set(error, ENOMEM,
2432 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2433 "Failed to allocate memory");
2440 sfc_flow_free(__rte_unused struct sfc_adapter *sa, struct rte_flow *flow)
2446 sfc_flow_insert(struct sfc_adapter *sa, struct rte_flow *flow,
2447 struct rte_flow_error *error)
2449 const struct sfc_flow_ops_by_spec *ops;
2452 ops = sfc_flow_get_ops_by_spec(flow);
2453 if (ops == NULL || ops->insert == NULL) {
2454 rte_flow_error_set(error, ENOTSUP,
2455 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2456 "No backend to handle this flow");
2460 rc = ops->insert(sa, flow);
2462 rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2463 NULL, "Failed to insert the flow rule");
2470 sfc_flow_remove(struct sfc_adapter *sa, struct rte_flow *flow,
2471 struct rte_flow_error *error)
2473 const struct sfc_flow_ops_by_spec *ops;
2476 ops = sfc_flow_get_ops_by_spec(flow);
2477 if (ops == NULL || ops->remove == NULL) {
2478 rte_flow_error_set(error, ENOTSUP,
2479 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2480 "No backend to handle this flow");
2484 rc = ops->remove(sa, flow);
2486 rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2487 NULL, "Failed to remove the flow rule");
2494 sfc_flow_validate(struct rte_eth_dev *dev,
2495 const struct rte_flow_attr *attr,
2496 const struct rte_flow_item pattern[],
2497 const struct rte_flow_action actions[],
2498 struct rte_flow_error *error)
2500 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2501 struct rte_flow *flow;
2504 flow = sfc_flow_zmalloc(error);
2508 rc = sfc_flow_parse(dev, attr, pattern, actions, flow, error);
2510 sfc_flow_free(sa, flow);
2515 static struct rte_flow *
2516 sfc_flow_create(struct rte_eth_dev *dev,
2517 const struct rte_flow_attr *attr,
2518 const struct rte_flow_item pattern[],
2519 const struct rte_flow_action actions[],
2520 struct rte_flow_error *error)
2522 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2523 struct rte_flow *flow = NULL;
2526 flow = sfc_flow_zmalloc(error);
2530 rc = sfc_flow_parse(dev, attr, pattern, actions, flow, error);
2532 goto fail_bad_value;
2534 sfc_adapter_lock(sa);
2536 TAILQ_INSERT_TAIL(&sa->flow_list, flow, entries);
2538 if (sa->state == SFC_ADAPTER_STARTED) {
2539 rc = sfc_flow_insert(sa, flow, error);
2541 goto fail_flow_insert;
2544 sfc_adapter_unlock(sa);
2549 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2552 sfc_flow_free(sa, flow);
2553 sfc_adapter_unlock(sa);
2560 sfc_flow_destroy(struct rte_eth_dev *dev,
2561 struct rte_flow *flow,
2562 struct rte_flow_error *error)
2564 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2565 struct rte_flow *flow_ptr;
2568 sfc_adapter_lock(sa);
2570 TAILQ_FOREACH(flow_ptr, &sa->flow_list, entries) {
2571 if (flow_ptr == flow)
2575 rte_flow_error_set(error, rc,
2576 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
2577 "Failed to find flow rule to destroy");
2578 goto fail_bad_value;
2581 if (sa->state == SFC_ADAPTER_STARTED)
2582 rc = sfc_flow_remove(sa, flow, error);
2584 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2585 sfc_flow_free(sa, flow);
2588 sfc_adapter_unlock(sa);
2594 sfc_flow_flush(struct rte_eth_dev *dev,
2595 struct rte_flow_error *error)
2597 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2598 struct rte_flow *flow;
2601 sfc_adapter_lock(sa);
2603 while ((flow = TAILQ_FIRST(&sa->flow_list)) != NULL) {
2604 if (sa->state == SFC_ADAPTER_STARTED) {
2607 rc = sfc_flow_remove(sa, flow, error);
2612 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2613 sfc_flow_free(sa, flow);
2616 sfc_adapter_unlock(sa);
2622 sfc_flow_isolate(struct rte_eth_dev *dev, int enable,
2623 struct rte_flow_error *error)
2625 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2628 sfc_adapter_lock(sa);
2629 if (sa->state != SFC_ADAPTER_INITIALIZED) {
2630 rte_flow_error_set(error, EBUSY,
2631 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2632 NULL, "please close the port first");
2635 sfc_sa2shared(sa)->isolated = (enable) ? B_TRUE : B_FALSE;
2637 sfc_adapter_unlock(sa);
2642 const struct rte_flow_ops sfc_flow_ops = {
2643 .validate = sfc_flow_validate,
2644 .create = sfc_flow_create,
2645 .destroy = sfc_flow_destroy,
2646 .flush = sfc_flow_flush,
2648 .isolate = sfc_flow_isolate,
2652 sfc_flow_init(struct sfc_adapter *sa)
2654 SFC_ASSERT(sfc_adapter_is_locked(sa));
2656 TAILQ_INIT(&sa->flow_list);
2660 sfc_flow_fini(struct sfc_adapter *sa)
2662 struct rte_flow *flow;
2664 SFC_ASSERT(sfc_adapter_is_locked(sa));
2666 while ((flow = TAILQ_FIRST(&sa->flow_list)) != NULL) {
2667 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2668 sfc_flow_free(sa, flow);
2673 sfc_flow_stop(struct sfc_adapter *sa)
2675 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
2676 struct sfc_rss *rss = &sas->rss;
2677 struct rte_flow *flow;
2679 SFC_ASSERT(sfc_adapter_is_locked(sa));
2681 TAILQ_FOREACH(flow, &sa->flow_list, entries)
2682 sfc_flow_remove(sa, flow, NULL);
2684 if (rss->dummy_rss_context != EFX_RSS_CONTEXT_DEFAULT) {
2685 efx_rx_scale_context_free(sa->nic, rss->dummy_rss_context);
2686 rss->dummy_rss_context = EFX_RSS_CONTEXT_DEFAULT;
2691 sfc_flow_start(struct sfc_adapter *sa)
2693 struct rte_flow *flow;
2696 sfc_log_init(sa, "entry");
2698 SFC_ASSERT(sfc_adapter_is_locked(sa));
2700 TAILQ_FOREACH(flow, &sa->flow_list, entries) {
2701 rc = sfc_flow_insert(sa, flow, NULL);
2706 sfc_log_init(sa, "done");