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;
1297 if (queue->index >= sfc_sa2shared(sa)->rxq_count)
1300 rxq = &sa->rxq_ctrl[queue->index];
1301 spec_filter->template.efs_dmaq_id = (uint16_t)rxq->hw_index;
1307 sfc_flow_parse_rss(struct sfc_adapter *sa,
1308 const struct rte_flow_action_rss *action_rss,
1309 struct rte_flow *flow)
1311 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
1312 struct sfc_rss *rss = &sas->rss;
1313 unsigned int rxq_sw_index;
1314 struct sfc_rxq *rxq;
1315 unsigned int rxq_hw_index_min;
1316 unsigned int rxq_hw_index_max;
1317 efx_rx_hash_type_t efx_hash_types;
1318 const uint8_t *rss_key;
1319 struct sfc_flow_spec *spec = &flow->spec;
1320 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1321 struct sfc_flow_rss *sfc_rss_conf = &spec_filter->rss_conf;
1324 if (action_rss->queue_num == 0)
1327 rxq_sw_index = sfc_sa2shared(sa)->rxq_count - 1;
1328 rxq = &sa->rxq_ctrl[rxq_sw_index];
1329 rxq_hw_index_min = rxq->hw_index;
1330 rxq_hw_index_max = 0;
1332 for (i = 0; i < action_rss->queue_num; ++i) {
1333 rxq_sw_index = action_rss->queue[i];
1335 if (rxq_sw_index >= sfc_sa2shared(sa)->rxq_count)
1338 rxq = &sa->rxq_ctrl[rxq_sw_index];
1340 if (rxq->hw_index < rxq_hw_index_min)
1341 rxq_hw_index_min = rxq->hw_index;
1343 if (rxq->hw_index > rxq_hw_index_max)
1344 rxq_hw_index_max = rxq->hw_index;
1347 switch (action_rss->func) {
1348 case RTE_ETH_HASH_FUNCTION_DEFAULT:
1349 case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
1355 if (action_rss->level)
1359 * Dummy RSS action with only one queue and no specific settings
1360 * for hash types and key does not require dedicated RSS context
1361 * and may be simplified to single queue action.
1363 if (action_rss->queue_num == 1 && action_rss->types == 0 &&
1364 action_rss->key_len == 0) {
1365 spec_filter->template.efs_dmaq_id = rxq_hw_index_min;
1369 if (action_rss->types) {
1372 rc = sfc_rx_hf_rte_to_efx(sa, action_rss->types,
1380 for (i = 0; i < rss->hf_map_nb_entries; ++i)
1381 efx_hash_types |= rss->hf_map[i].efx;
1384 if (action_rss->key_len) {
1385 if (action_rss->key_len != sizeof(rss->key))
1388 rss_key = action_rss->key;
1393 spec_filter->rss = B_TRUE;
1395 sfc_rss_conf->rxq_hw_index_min = rxq_hw_index_min;
1396 sfc_rss_conf->rxq_hw_index_max = rxq_hw_index_max;
1397 sfc_rss_conf->rss_hash_types = efx_hash_types;
1398 rte_memcpy(sfc_rss_conf->rss_key, rss_key, sizeof(rss->key));
1400 for (i = 0; i < RTE_DIM(sfc_rss_conf->rss_tbl); ++i) {
1401 unsigned int nb_queues = action_rss->queue_num;
1402 unsigned int rxq_sw_index = action_rss->queue[i % nb_queues];
1403 struct sfc_rxq *rxq = &sa->rxq_ctrl[rxq_sw_index];
1405 sfc_rss_conf->rss_tbl[i] = rxq->hw_index - rxq_hw_index_min;
1412 sfc_flow_spec_flush(struct sfc_adapter *sa, struct sfc_flow_spec *spec,
1413 unsigned int filters_count)
1415 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1419 for (i = 0; i < filters_count; i++) {
1422 rc = efx_filter_remove(sa->nic, &spec_filter->filters[i]);
1423 if (ret == 0 && rc != 0) {
1424 sfc_err(sa, "failed to remove filter specification "
1434 sfc_flow_spec_insert(struct sfc_adapter *sa, struct sfc_flow_spec *spec)
1436 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1440 for (i = 0; i < spec_filter->count; i++) {
1441 rc = efx_filter_insert(sa->nic, &spec_filter->filters[i]);
1443 sfc_flow_spec_flush(sa, spec, i);
1452 sfc_flow_spec_remove(struct sfc_adapter *sa, struct sfc_flow_spec *spec)
1454 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1456 return sfc_flow_spec_flush(sa, spec, spec_filter->count);
1460 sfc_flow_filter_insert(struct sfc_adapter *sa,
1461 struct rte_flow *flow)
1463 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
1464 struct sfc_rss *rss = &sas->rss;
1465 struct sfc_flow_spec_filter *spec_filter = &flow->spec.filter;
1466 struct sfc_flow_rss *flow_rss = &spec_filter->rss_conf;
1467 uint32_t efs_rss_context = EFX_RSS_CONTEXT_DEFAULT;
1471 if (spec_filter->rss) {
1472 unsigned int rss_spread = MIN(flow_rss->rxq_hw_index_max -
1473 flow_rss->rxq_hw_index_min + 1,
1476 rc = efx_rx_scale_context_alloc(sa->nic,
1477 EFX_RX_SCALE_EXCLUSIVE,
1481 goto fail_scale_context_alloc;
1483 rc = efx_rx_scale_mode_set(sa->nic, efs_rss_context,
1485 flow_rss->rss_hash_types, B_TRUE);
1487 goto fail_scale_mode_set;
1489 rc = efx_rx_scale_key_set(sa->nic, efs_rss_context,
1493 goto fail_scale_key_set;
1496 * At this point, fully elaborated filter specifications
1497 * have been produced from the template. To make sure that
1498 * RSS behaviour is consistent between them, set the same
1499 * RSS context value everywhere.
1501 for (i = 0; i < spec_filter->count; i++) {
1502 efx_filter_spec_t *spec = &spec_filter->filters[i];
1504 spec->efs_rss_context = efs_rss_context;
1505 spec->efs_dmaq_id = flow_rss->rxq_hw_index_min;
1506 spec->efs_flags |= EFX_FILTER_FLAG_RX_RSS;
1510 rc = sfc_flow_spec_insert(sa, &flow->spec);
1512 goto fail_filter_insert;
1514 if (spec_filter->rss) {
1516 * Scale table is set after filter insertion because
1517 * the table entries are relative to the base RxQ ID
1518 * and the latter is submitted to the HW by means of
1519 * inserting a filter, so by the time of the request
1520 * the HW knows all the information needed to verify
1521 * the table entries, and the operation will succeed
1523 rc = efx_rx_scale_tbl_set(sa->nic, efs_rss_context,
1525 RTE_DIM(flow_rss->rss_tbl));
1527 goto fail_scale_tbl_set;
1533 sfc_flow_spec_remove(sa, &flow->spec);
1537 fail_scale_mode_set:
1538 if (efs_rss_context != EFX_RSS_CONTEXT_DEFAULT)
1539 efx_rx_scale_context_free(sa->nic, efs_rss_context);
1541 fail_scale_context_alloc:
1546 sfc_flow_filter_remove(struct sfc_adapter *sa,
1547 struct rte_flow *flow)
1549 struct sfc_flow_spec_filter *spec_filter = &flow->spec.filter;
1552 rc = sfc_flow_spec_remove(sa, &flow->spec);
1556 if (spec_filter->rss) {
1558 * All specifications for a given flow rule have the same RSS
1559 * context, so that RSS context value is taken from the first
1560 * filter specification
1562 efx_filter_spec_t *spec = &spec_filter->filters[0];
1564 rc = efx_rx_scale_context_free(sa->nic, spec->efs_rss_context);
1571 sfc_flow_parse_mark(struct sfc_adapter *sa,
1572 const struct rte_flow_action_mark *mark,
1573 struct rte_flow *flow)
1575 struct sfc_flow_spec *spec = &flow->spec;
1576 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1577 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
1579 if (mark == NULL || mark->id > encp->enc_filter_action_mark_max)
1582 spec_filter->template.efs_flags |= EFX_FILTER_FLAG_ACTION_MARK;
1583 spec_filter->template.efs_mark = mark->id;
1589 sfc_flow_parse_actions(struct sfc_adapter *sa,
1590 const struct rte_flow_action actions[],
1591 struct rte_flow *flow,
1592 struct rte_flow_error *error)
1595 struct sfc_flow_spec *spec = &flow->spec;
1596 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1597 const unsigned int dp_rx_features = sa->priv.dp_rx->features;
1598 uint32_t actions_set = 0;
1599 const uint32_t fate_actions_mask = (1UL << RTE_FLOW_ACTION_TYPE_QUEUE) |
1600 (1UL << RTE_FLOW_ACTION_TYPE_RSS) |
1601 (1UL << RTE_FLOW_ACTION_TYPE_DROP);
1602 const uint32_t mark_actions_mask = (1UL << RTE_FLOW_ACTION_TYPE_MARK) |
1603 (1UL << RTE_FLOW_ACTION_TYPE_FLAG);
1605 if (actions == NULL) {
1606 rte_flow_error_set(error, EINVAL,
1607 RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
1612 #define SFC_BUILD_SET_OVERFLOW(_action, _set) \
1613 RTE_BUILD_BUG_ON(_action >= sizeof(_set) * CHAR_BIT)
1615 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1616 switch (actions->type) {
1617 case RTE_FLOW_ACTION_TYPE_VOID:
1618 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VOID,
1622 case RTE_FLOW_ACTION_TYPE_QUEUE:
1623 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_QUEUE,
1625 if ((actions_set & fate_actions_mask) != 0)
1626 goto fail_fate_actions;
1628 rc = sfc_flow_parse_queue(sa, actions->conf, flow);
1630 rte_flow_error_set(error, EINVAL,
1631 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1632 "Bad QUEUE action");
1637 case RTE_FLOW_ACTION_TYPE_RSS:
1638 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_RSS,
1640 if ((actions_set & fate_actions_mask) != 0)
1641 goto fail_fate_actions;
1643 rc = sfc_flow_parse_rss(sa, actions->conf, flow);
1645 rte_flow_error_set(error, -rc,
1646 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1652 case RTE_FLOW_ACTION_TYPE_DROP:
1653 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_DROP,
1655 if ((actions_set & fate_actions_mask) != 0)
1656 goto fail_fate_actions;
1658 spec_filter->template.efs_dmaq_id =
1659 EFX_FILTER_SPEC_RX_DMAQ_ID_DROP;
1662 case RTE_FLOW_ACTION_TYPE_FLAG:
1663 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_FLAG,
1665 if ((actions_set & mark_actions_mask) != 0)
1666 goto fail_actions_overlap;
1668 if ((dp_rx_features & SFC_DP_RX_FEAT_FLOW_FLAG) == 0) {
1669 rte_flow_error_set(error, ENOTSUP,
1670 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1671 "FLAG action is not supported on the current Rx datapath");
1675 spec_filter->template.efs_flags |=
1676 EFX_FILTER_FLAG_ACTION_FLAG;
1679 case RTE_FLOW_ACTION_TYPE_MARK:
1680 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_MARK,
1682 if ((actions_set & mark_actions_mask) != 0)
1683 goto fail_actions_overlap;
1685 if ((dp_rx_features & SFC_DP_RX_FEAT_FLOW_MARK) == 0) {
1686 rte_flow_error_set(error, ENOTSUP,
1687 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1688 "MARK action is not supported on the current Rx datapath");
1692 rc = sfc_flow_parse_mark(sa, actions->conf, flow);
1694 rte_flow_error_set(error, rc,
1695 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1702 rte_flow_error_set(error, ENOTSUP,
1703 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1704 "Action is not supported");
1708 actions_set |= (1UL << actions->type);
1710 #undef SFC_BUILD_SET_OVERFLOW
1712 /* When fate is unknown, drop traffic. */
1713 if ((actions_set & fate_actions_mask) == 0) {
1714 spec_filter->template.efs_dmaq_id =
1715 EFX_FILTER_SPEC_RX_DMAQ_ID_DROP;
1721 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, actions,
1722 "Cannot combine several fate-deciding actions, "
1723 "choose between QUEUE, RSS or DROP");
1726 fail_actions_overlap:
1727 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, actions,
1728 "Overlapping actions are not supported");
1733 * Set the EFX_FILTER_MATCH_UNKNOWN_UCAST_DST
1734 * and EFX_FILTER_MATCH_UNKNOWN_MCAST_DST match flags in the same
1735 * specifications after copying.
1737 * @param spec[in, out]
1738 * SFC flow specification to update.
1739 * @param filters_count_for_one_val[in]
1740 * How many specifications should have the same match flag, what is the
1741 * number of specifications before copying.
1743 * Perform verbose error reporting if not NULL.
1746 sfc_flow_set_unknown_dst_flags(struct sfc_flow_spec *spec,
1747 unsigned int filters_count_for_one_val,
1748 struct rte_flow_error *error)
1751 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1752 static const efx_filter_match_flags_t vals[] = {
1753 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST,
1754 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST
1757 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
1758 rte_flow_error_set(error, EINVAL,
1759 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1760 "Number of specifications is incorrect while copying "
1761 "by unknown destination flags");
1765 for (i = 0; i < spec_filter->count; i++) {
1766 /* The check above ensures that divisor can't be zero here */
1767 spec_filter->filters[i].efs_match_flags |=
1768 vals[i / filters_count_for_one_val];
1775 * Check that the following conditions are met:
1776 * - the list of supported filters has a filter
1777 * with EFX_FILTER_MATCH_UNKNOWN_MCAST_DST flag instead of
1778 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST, since this filter will also
1782 * The match flags of filter.
1784 * Specification to be supplemented.
1786 * SFC filter with list of supported filters.
1789 sfc_flow_check_unknown_dst_flags(efx_filter_match_flags_t match,
1790 __rte_unused efx_filter_spec_t *spec,
1791 struct sfc_filter *filter)
1794 efx_filter_match_flags_t match_mcast_dst;
1797 (match & ~EFX_FILTER_MATCH_UNKNOWN_UCAST_DST) |
1798 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST;
1799 for (i = 0; i < filter->supported_match_num; i++) {
1800 if (match_mcast_dst == filter->supported_match[i])
1808 * Set the EFX_FILTER_MATCH_ETHER_TYPE match flag and EFX_ETHER_TYPE_IPV4 and
1809 * EFX_ETHER_TYPE_IPV6 values of the corresponding field in the same
1810 * specifications after copying.
1812 * @param spec[in, out]
1813 * SFC flow specification to update.
1814 * @param filters_count_for_one_val[in]
1815 * How many specifications should have the same EtherType value, what is the
1816 * number of specifications before copying.
1818 * Perform verbose error reporting if not NULL.
1821 sfc_flow_set_ethertypes(struct sfc_flow_spec *spec,
1822 unsigned int filters_count_for_one_val,
1823 struct rte_flow_error *error)
1826 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1827 static const uint16_t vals[] = {
1828 EFX_ETHER_TYPE_IPV4, EFX_ETHER_TYPE_IPV6
1831 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
1832 rte_flow_error_set(error, EINVAL,
1833 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1834 "Number of specifications is incorrect "
1835 "while copying by Ethertype");
1839 for (i = 0; i < spec_filter->count; i++) {
1840 spec_filter->filters[i].efs_match_flags |=
1841 EFX_FILTER_MATCH_ETHER_TYPE;
1844 * The check above ensures that
1845 * filters_count_for_one_val is not 0
1847 spec_filter->filters[i].efs_ether_type =
1848 vals[i / filters_count_for_one_val];
1855 * Set the EFX_FILTER_MATCH_OUTER_VID match flag with value 0
1856 * in the same specifications after copying.
1858 * @param spec[in, out]
1859 * SFC flow specification to update.
1860 * @param filters_count_for_one_val[in]
1861 * How many specifications should have the same match flag, what is the
1862 * number of specifications before copying.
1864 * Perform verbose error reporting if not NULL.
1867 sfc_flow_set_outer_vid_flag(struct sfc_flow_spec *spec,
1868 unsigned int filters_count_for_one_val,
1869 struct rte_flow_error *error)
1871 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1874 if (filters_count_for_one_val != spec_filter->count) {
1875 rte_flow_error_set(error, EINVAL,
1876 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1877 "Number of specifications is incorrect "
1878 "while copying by outer VLAN ID");
1882 for (i = 0; i < spec_filter->count; i++) {
1883 spec_filter->filters[i].efs_match_flags |=
1884 EFX_FILTER_MATCH_OUTER_VID;
1886 spec_filter->filters[i].efs_outer_vid = 0;
1893 * Set the EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST and
1894 * EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST match flags in the same
1895 * specifications after copying.
1897 * @param spec[in, out]
1898 * SFC flow specification to update.
1899 * @param filters_count_for_one_val[in]
1900 * How many specifications should have the same match flag, what is the
1901 * number of specifications before copying.
1903 * Perform verbose error reporting if not NULL.
1906 sfc_flow_set_ifrm_unknown_dst_flags(struct sfc_flow_spec *spec,
1907 unsigned int filters_count_for_one_val,
1908 struct rte_flow_error *error)
1911 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1912 static const efx_filter_match_flags_t vals[] = {
1913 EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST,
1914 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST
1917 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
1918 rte_flow_error_set(error, EINVAL,
1919 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1920 "Number of specifications is incorrect while copying "
1921 "by inner frame unknown destination flags");
1925 for (i = 0; i < spec_filter->count; i++) {
1926 /* The check above ensures that divisor can't be zero here */
1927 spec_filter->filters[i].efs_match_flags |=
1928 vals[i / filters_count_for_one_val];
1935 * Check that the following conditions are met:
1936 * - the specification corresponds to a filter for encapsulated traffic
1937 * - the list of supported filters has a filter
1938 * with EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST flag instead of
1939 * EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST, since this filter will also
1943 * The match flags of filter.
1945 * Specification to be supplemented.
1947 * SFC filter with list of supported filters.
1950 sfc_flow_check_ifrm_unknown_dst_flags(efx_filter_match_flags_t match,
1951 efx_filter_spec_t *spec,
1952 struct sfc_filter *filter)
1955 efx_tunnel_protocol_t encap_type = spec->efs_encap_type;
1956 efx_filter_match_flags_t match_mcast_dst;
1958 if (encap_type == EFX_TUNNEL_PROTOCOL_NONE)
1962 (match & ~EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST) |
1963 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST;
1964 for (i = 0; i < filter->supported_match_num; i++) {
1965 if (match_mcast_dst == filter->supported_match[i])
1973 * Check that the list of supported filters has a filter that differs
1974 * from @p match in that it has no flag EFX_FILTER_MATCH_OUTER_VID
1975 * in this case that filter will be used and the flag
1976 * EFX_FILTER_MATCH_OUTER_VID is not needed.
1979 * The match flags of filter.
1981 * Specification to be supplemented.
1983 * SFC filter with list of supported filters.
1986 sfc_flow_check_outer_vid_flag(efx_filter_match_flags_t match,
1987 __rte_unused efx_filter_spec_t *spec,
1988 struct sfc_filter *filter)
1991 efx_filter_match_flags_t match_without_vid =
1992 match & ~EFX_FILTER_MATCH_OUTER_VID;
1994 for (i = 0; i < filter->supported_match_num; i++) {
1995 if (match_without_vid == filter->supported_match[i])
2003 * Match flags that can be automatically added to filters.
2004 * Selecting the last minimum when searching for the copy flag ensures that the
2005 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST flag has a higher priority than
2006 * EFX_FILTER_MATCH_ETHER_TYPE. This is because the filter
2007 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST is at the end of the list of supported
2010 static const struct sfc_flow_copy_flag sfc_flow_copy_flags[] = {
2012 .flag = EFX_FILTER_MATCH_UNKNOWN_UCAST_DST,
2014 .set_vals = sfc_flow_set_unknown_dst_flags,
2015 .spec_check = sfc_flow_check_unknown_dst_flags,
2018 .flag = EFX_FILTER_MATCH_ETHER_TYPE,
2020 .set_vals = sfc_flow_set_ethertypes,
2024 .flag = EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST,
2026 .set_vals = sfc_flow_set_ifrm_unknown_dst_flags,
2027 .spec_check = sfc_flow_check_ifrm_unknown_dst_flags,
2030 .flag = EFX_FILTER_MATCH_OUTER_VID,
2032 .set_vals = sfc_flow_set_outer_vid_flag,
2033 .spec_check = sfc_flow_check_outer_vid_flag,
2037 /* Get item from array sfc_flow_copy_flags */
2038 static const struct sfc_flow_copy_flag *
2039 sfc_flow_get_copy_flag(efx_filter_match_flags_t flag)
2043 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
2044 if (sfc_flow_copy_flags[i].flag == flag)
2045 return &sfc_flow_copy_flags[i];
2052 * Make copies of the specifications, set match flag and values
2053 * of the field that corresponds to it.
2055 * @param spec[in, out]
2056 * SFC flow specification to update.
2058 * The match flag to add.
2060 * Perform verbose error reporting if not NULL.
2063 sfc_flow_spec_add_match_flag(struct sfc_flow_spec *spec,
2064 efx_filter_match_flags_t flag,
2065 struct rte_flow_error *error)
2068 unsigned int new_filters_count;
2069 unsigned int filters_count_for_one_val;
2070 const struct sfc_flow_copy_flag *copy_flag;
2071 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2074 copy_flag = sfc_flow_get_copy_flag(flag);
2075 if (copy_flag == NULL) {
2076 rte_flow_error_set(error, ENOTSUP,
2077 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2078 "Unsupported spec field for copying");
2082 new_filters_count = spec_filter->count * copy_flag->vals_count;
2083 if (new_filters_count > SF_FLOW_SPEC_NB_FILTERS_MAX) {
2084 rte_flow_error_set(error, EINVAL,
2085 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2086 "Too much EFX specifications in the flow rule");
2090 /* Copy filters specifications */
2091 for (i = spec_filter->count; i < new_filters_count; i++) {
2092 spec_filter->filters[i] =
2093 spec_filter->filters[i - spec_filter->count];
2096 filters_count_for_one_val = spec_filter->count;
2097 spec_filter->count = new_filters_count;
2099 rc = copy_flag->set_vals(spec, filters_count_for_one_val, error);
2107 * Check that the given set of match flags missing in the original filter spec
2108 * could be covered by adding spec copies which specify the corresponding
2109 * flags and packet field values to match.
2111 * @param miss_flags[in]
2112 * Flags that are missing until the supported filter.
2114 * Specification to be supplemented.
2119 * Number of specifications after copy or 0, if the flags can not be added.
2122 sfc_flow_check_missing_flags(efx_filter_match_flags_t miss_flags,
2123 efx_filter_spec_t *spec,
2124 struct sfc_filter *filter)
2127 efx_filter_match_flags_t copy_flags = 0;
2128 efx_filter_match_flags_t flag;
2129 efx_filter_match_flags_t match = spec->efs_match_flags | miss_flags;
2130 sfc_flow_spec_check *check;
2131 unsigned int multiplier = 1;
2133 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
2134 flag = sfc_flow_copy_flags[i].flag;
2135 check = sfc_flow_copy_flags[i].spec_check;
2136 if ((flag & miss_flags) == flag) {
2137 if (check != NULL && (!check(match, spec, filter)))
2141 multiplier *= sfc_flow_copy_flags[i].vals_count;
2145 if (copy_flags == miss_flags)
2152 * Attempt to supplement the specification template to the minimally
2153 * supported set of match flags. To do this, it is necessary to copy
2154 * the specifications, filling them with the values of fields that
2155 * correspond to the missing flags.
2156 * The necessary and sufficient filter is built from the fewest number
2157 * of copies which could be made to cover the minimally required set
2162 * @param spec[in, out]
2163 * SFC flow specification to update.
2165 * Perform verbose error reporting if not NULL.
2168 sfc_flow_spec_filters_complete(struct sfc_adapter *sa,
2169 struct sfc_flow_spec *spec,
2170 struct rte_flow_error *error)
2172 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2173 struct sfc_filter *filter = &sa->filter;
2174 efx_filter_match_flags_t miss_flags;
2175 efx_filter_match_flags_t min_miss_flags = 0;
2176 efx_filter_match_flags_t match;
2177 unsigned int min_multiplier = UINT_MAX;
2178 unsigned int multiplier;
2182 match = spec_filter->template.efs_match_flags;
2183 for (i = 0; i < filter->supported_match_num; i++) {
2184 if ((match & filter->supported_match[i]) == match) {
2185 miss_flags = filter->supported_match[i] & (~match);
2186 multiplier = sfc_flow_check_missing_flags(miss_flags,
2187 &spec_filter->template, filter);
2188 if (multiplier > 0) {
2189 if (multiplier <= min_multiplier) {
2190 min_multiplier = multiplier;
2191 min_miss_flags = miss_flags;
2197 if (min_multiplier == UINT_MAX) {
2198 rte_flow_error_set(error, ENOTSUP,
2199 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2200 "The flow rule pattern is unsupported");
2204 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
2205 efx_filter_match_flags_t flag = sfc_flow_copy_flags[i].flag;
2207 if ((flag & min_miss_flags) == flag) {
2208 rc = sfc_flow_spec_add_match_flag(spec, flag, error);
2218 * Check that set of match flags is referred to by a filter. Filter is
2219 * described by match flags with the ability to add OUTER_VID and INNER_VID
2222 * @param match_flags[in]
2223 * Set of match flags.
2224 * @param flags_pattern[in]
2225 * Pattern of filter match flags.
2228 sfc_flow_is_match_with_vids(efx_filter_match_flags_t match_flags,
2229 efx_filter_match_flags_t flags_pattern)
2231 if ((match_flags & flags_pattern) != flags_pattern)
2234 switch (match_flags & ~flags_pattern) {
2236 case EFX_FILTER_MATCH_OUTER_VID:
2237 case EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_INNER_VID:
2245 * Check whether the spec maps to a hardware filter which is known to be
2246 * ineffective despite being valid.
2249 * SFC filter with list of supported filters.
2251 * SFC flow specification.
2254 sfc_flow_is_match_flags_exception(struct sfc_filter *filter,
2255 struct sfc_flow_spec *spec)
2258 uint16_t ether_type;
2260 efx_filter_match_flags_t match_flags;
2261 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2263 for (i = 0; i < spec_filter->count; i++) {
2264 match_flags = spec_filter->filters[i].efs_match_flags;
2266 if (sfc_flow_is_match_with_vids(match_flags,
2267 EFX_FILTER_MATCH_ETHER_TYPE) ||
2268 sfc_flow_is_match_with_vids(match_flags,
2269 EFX_FILTER_MATCH_ETHER_TYPE |
2270 EFX_FILTER_MATCH_LOC_MAC)) {
2271 ether_type = spec_filter->filters[i].efs_ether_type;
2272 if (filter->supports_ip_proto_or_addr_filter &&
2273 (ether_type == EFX_ETHER_TYPE_IPV4 ||
2274 ether_type == EFX_ETHER_TYPE_IPV6))
2276 } else if (sfc_flow_is_match_with_vids(match_flags,
2277 EFX_FILTER_MATCH_ETHER_TYPE |
2278 EFX_FILTER_MATCH_IP_PROTO) ||
2279 sfc_flow_is_match_with_vids(match_flags,
2280 EFX_FILTER_MATCH_ETHER_TYPE |
2281 EFX_FILTER_MATCH_IP_PROTO |
2282 EFX_FILTER_MATCH_LOC_MAC)) {
2283 ip_proto = spec_filter->filters[i].efs_ip_proto;
2284 if (filter->supports_rem_or_local_port_filter &&
2285 (ip_proto == EFX_IPPROTO_TCP ||
2286 ip_proto == EFX_IPPROTO_UDP))
2295 sfc_flow_validate_match_flags(struct sfc_adapter *sa,
2296 struct rte_flow *flow,
2297 struct rte_flow_error *error)
2299 struct sfc_flow_spec *spec = &flow->spec;
2300 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2301 efx_filter_spec_t *spec_tmpl = &spec_filter->template;
2302 efx_filter_match_flags_t match_flags = spec_tmpl->efs_match_flags;
2305 /* Initialize the first filter spec with template */
2306 spec_filter->filters[0] = *spec_tmpl;
2307 spec_filter->count = 1;
2309 if (!sfc_filter_is_match_supported(sa, match_flags)) {
2310 rc = sfc_flow_spec_filters_complete(sa, &flow->spec, error);
2315 if (sfc_flow_is_match_flags_exception(&sa->filter, &flow->spec)) {
2316 rte_flow_error_set(error, ENOTSUP,
2317 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2318 "The flow rule pattern is unsupported");
2326 sfc_flow_parse_rte_to_filter(struct rte_eth_dev *dev,
2327 const struct rte_flow_item pattern[],
2328 const struct rte_flow_action actions[],
2329 struct rte_flow *flow,
2330 struct rte_flow_error *error)
2332 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2333 struct sfc_flow_spec *spec = &flow->spec;
2334 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2335 struct sfc_flow_parse_ctx ctx;
2338 ctx.type = SFC_FLOW_PARSE_CTX_FILTER;
2339 ctx.filter = &spec_filter->template;
2341 rc = sfc_flow_parse_pattern(sfc_flow_items, RTE_DIM(sfc_flow_items),
2342 pattern, &ctx, error);
2344 goto fail_bad_value;
2346 rc = sfc_flow_parse_actions(sa, actions, flow, error);
2348 goto fail_bad_value;
2350 rc = sfc_flow_validate_match_flags(sa, flow, error);
2352 goto fail_bad_value;
2361 sfc_flow_parse(struct rte_eth_dev *dev,
2362 const struct rte_flow_attr *attr,
2363 const struct rte_flow_item pattern[],
2364 const struct rte_flow_action actions[],
2365 struct rte_flow *flow,
2366 struct rte_flow_error *error)
2368 const struct sfc_flow_ops_by_spec *ops;
2371 rc = sfc_flow_parse_attr(attr, flow, error);
2375 ops = sfc_flow_get_ops_by_spec(flow);
2376 if (ops == NULL || ops->parse == NULL) {
2377 rte_flow_error_set(error, ENOTSUP,
2378 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2379 "No backend to handle this flow");
2383 return ops->parse(dev, pattern, actions, flow, error);
2386 static struct rte_flow *
2387 sfc_flow_zmalloc(struct rte_flow_error *error)
2389 struct rte_flow *flow;
2391 flow = rte_zmalloc("sfc_rte_flow", sizeof(*flow), 0);
2393 rte_flow_error_set(error, ENOMEM,
2394 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2395 "Failed to allocate memory");
2402 sfc_flow_free(__rte_unused struct sfc_adapter *sa, struct rte_flow *flow)
2408 sfc_flow_insert(struct sfc_adapter *sa, struct rte_flow *flow,
2409 struct rte_flow_error *error)
2411 const struct sfc_flow_ops_by_spec *ops;
2414 ops = sfc_flow_get_ops_by_spec(flow);
2415 if (ops == NULL || ops->insert == NULL) {
2416 rte_flow_error_set(error, ENOTSUP,
2417 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2418 "No backend to handle this flow");
2422 rc = ops->insert(sa, flow);
2424 rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2425 NULL, "Failed to insert the flow rule");
2432 sfc_flow_remove(struct sfc_adapter *sa, struct rte_flow *flow,
2433 struct rte_flow_error *error)
2435 const struct sfc_flow_ops_by_spec *ops;
2438 ops = sfc_flow_get_ops_by_spec(flow);
2439 if (ops == NULL || ops->remove == NULL) {
2440 rte_flow_error_set(error, ENOTSUP,
2441 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2442 "No backend to handle this flow");
2446 rc = ops->remove(sa, flow);
2448 rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2449 NULL, "Failed to remove the flow rule");
2456 sfc_flow_validate(struct rte_eth_dev *dev,
2457 const struct rte_flow_attr *attr,
2458 const struct rte_flow_item pattern[],
2459 const struct rte_flow_action actions[],
2460 struct rte_flow_error *error)
2462 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2463 struct rte_flow *flow;
2466 flow = sfc_flow_zmalloc(error);
2470 rc = sfc_flow_parse(dev, attr, pattern, actions, flow, error);
2472 sfc_flow_free(sa, flow);
2477 static struct rte_flow *
2478 sfc_flow_create(struct rte_eth_dev *dev,
2479 const struct rte_flow_attr *attr,
2480 const struct rte_flow_item pattern[],
2481 const struct rte_flow_action actions[],
2482 struct rte_flow_error *error)
2484 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2485 struct rte_flow *flow = NULL;
2488 flow = sfc_flow_zmalloc(error);
2492 rc = sfc_flow_parse(dev, attr, pattern, actions, flow, error);
2494 goto fail_bad_value;
2496 sfc_adapter_lock(sa);
2498 TAILQ_INSERT_TAIL(&sa->flow_list, flow, entries);
2500 if (sa->state == SFC_ADAPTER_STARTED) {
2501 rc = sfc_flow_insert(sa, flow, error);
2503 goto fail_flow_insert;
2506 sfc_adapter_unlock(sa);
2511 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2514 sfc_flow_free(sa, flow);
2515 sfc_adapter_unlock(sa);
2522 sfc_flow_destroy(struct rte_eth_dev *dev,
2523 struct rte_flow *flow,
2524 struct rte_flow_error *error)
2526 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2527 struct rte_flow *flow_ptr;
2530 sfc_adapter_lock(sa);
2532 TAILQ_FOREACH(flow_ptr, &sa->flow_list, entries) {
2533 if (flow_ptr == flow)
2537 rte_flow_error_set(error, rc,
2538 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
2539 "Failed to find flow rule to destroy");
2540 goto fail_bad_value;
2543 if (sa->state == SFC_ADAPTER_STARTED)
2544 rc = sfc_flow_remove(sa, flow, error);
2546 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2547 sfc_flow_free(sa, flow);
2550 sfc_adapter_unlock(sa);
2556 sfc_flow_flush(struct rte_eth_dev *dev,
2557 struct rte_flow_error *error)
2559 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2560 struct rte_flow *flow;
2563 sfc_adapter_lock(sa);
2565 while ((flow = TAILQ_FIRST(&sa->flow_list)) != NULL) {
2566 if (sa->state == SFC_ADAPTER_STARTED) {
2569 rc = sfc_flow_remove(sa, flow, error);
2574 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2575 sfc_flow_free(sa, flow);
2578 sfc_adapter_unlock(sa);
2584 sfc_flow_isolate(struct rte_eth_dev *dev, int enable,
2585 struct rte_flow_error *error)
2587 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2590 sfc_adapter_lock(sa);
2591 if (sa->state != SFC_ADAPTER_INITIALIZED) {
2592 rte_flow_error_set(error, EBUSY,
2593 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2594 NULL, "please close the port first");
2597 sfc_sa2shared(sa)->isolated = (enable) ? B_TRUE : B_FALSE;
2599 sfc_adapter_unlock(sa);
2604 const struct rte_flow_ops sfc_flow_ops = {
2605 .validate = sfc_flow_validate,
2606 .create = sfc_flow_create,
2607 .destroy = sfc_flow_destroy,
2608 .flush = sfc_flow_flush,
2610 .isolate = sfc_flow_isolate,
2614 sfc_flow_init(struct sfc_adapter *sa)
2616 SFC_ASSERT(sfc_adapter_is_locked(sa));
2618 TAILQ_INIT(&sa->flow_list);
2622 sfc_flow_fini(struct sfc_adapter *sa)
2624 struct rte_flow *flow;
2626 SFC_ASSERT(sfc_adapter_is_locked(sa));
2628 while ((flow = TAILQ_FIRST(&sa->flow_list)) != NULL) {
2629 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2630 sfc_flow_free(sa, flow);
2635 sfc_flow_stop(struct sfc_adapter *sa)
2637 struct rte_flow *flow;
2639 SFC_ASSERT(sfc_adapter_is_locked(sa));
2641 TAILQ_FOREACH(flow, &sa->flow_list, entries)
2642 sfc_flow_remove(sa, flow, NULL);
2646 sfc_flow_start(struct sfc_adapter *sa)
2648 struct rte_flow *flow;
2651 sfc_log_init(sa, "entry");
2653 SFC_ASSERT(sfc_adapter_is_locked(sa));
2655 TAILQ_FOREACH(flow, &sa->flow_list, entries) {
2656 rc = sfc_flow_insert(sa, flow, NULL);
2661 sfc_log_init(sa, "done");