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_verify_cb_t *verify;
31 sfc_flow_cleanup_cb_t *cleanup;
32 sfc_flow_insert_cb_t *insert;
33 sfc_flow_remove_cb_t *remove;
36 static sfc_flow_parse_cb_t sfc_flow_parse_rte_to_filter;
37 static sfc_flow_parse_cb_t sfc_flow_parse_rte_to_mae;
38 static sfc_flow_insert_cb_t sfc_flow_filter_insert;
39 static sfc_flow_remove_cb_t sfc_flow_filter_remove;
41 static const struct sfc_flow_ops_by_spec sfc_flow_ops_filter = {
42 .parse = sfc_flow_parse_rte_to_filter,
45 .insert = sfc_flow_filter_insert,
46 .remove = sfc_flow_filter_remove,
49 static const struct sfc_flow_ops_by_spec sfc_flow_ops_mae = {
50 .parse = sfc_flow_parse_rte_to_mae,
51 .verify = sfc_mae_flow_verify,
52 .cleanup = sfc_mae_flow_cleanup,
53 .insert = sfc_mae_flow_insert,
54 .remove = sfc_mae_flow_remove,
57 static const struct sfc_flow_ops_by_spec *
58 sfc_flow_get_ops_by_spec(struct rte_flow *flow)
60 struct sfc_flow_spec *spec = &flow->spec;
61 const struct sfc_flow_ops_by_spec *ops = NULL;
64 case SFC_FLOW_SPEC_FILTER:
65 ops = &sfc_flow_ops_filter;
67 case SFC_FLOW_SPEC_MAE:
68 ops = &sfc_flow_ops_mae;
79 * Currently, filter-based (VNIC) flow API is implemented in such a manner
80 * that each flow rule is converted to one or more hardware filters.
81 * All elements of flow rule (attributes, pattern items, actions)
82 * correspond to one or more fields in the efx_filter_spec_s structure
83 * that is responsible for the hardware filter.
84 * If some required field is unset in the flow rule, then a handful
85 * of filter copies will be created to cover all possible values
89 static sfc_flow_item_parse sfc_flow_parse_void;
90 static sfc_flow_item_parse sfc_flow_parse_eth;
91 static sfc_flow_item_parse sfc_flow_parse_vlan;
92 static sfc_flow_item_parse sfc_flow_parse_ipv4;
93 static sfc_flow_item_parse sfc_flow_parse_ipv6;
94 static sfc_flow_item_parse sfc_flow_parse_tcp;
95 static sfc_flow_item_parse sfc_flow_parse_udp;
96 static sfc_flow_item_parse sfc_flow_parse_vxlan;
97 static sfc_flow_item_parse sfc_flow_parse_geneve;
98 static sfc_flow_item_parse sfc_flow_parse_nvgre;
100 typedef int (sfc_flow_spec_set_vals)(struct sfc_flow_spec *spec,
101 unsigned int filters_count_for_one_val,
102 struct rte_flow_error *error);
104 typedef boolean_t (sfc_flow_spec_check)(efx_filter_match_flags_t match,
105 efx_filter_spec_t *spec,
106 struct sfc_filter *filter);
108 struct sfc_flow_copy_flag {
109 /* EFX filter specification match flag */
110 efx_filter_match_flags_t flag;
111 /* Number of values of corresponding field */
112 unsigned int vals_count;
113 /* Function to set values in specifications */
114 sfc_flow_spec_set_vals *set_vals;
116 * Function to check that the specification is suitable
117 * for adding this match flag
119 sfc_flow_spec_check *spec_check;
122 static sfc_flow_spec_set_vals sfc_flow_set_unknown_dst_flags;
123 static sfc_flow_spec_check sfc_flow_check_unknown_dst_flags;
124 static sfc_flow_spec_set_vals sfc_flow_set_ethertypes;
125 static sfc_flow_spec_set_vals sfc_flow_set_ifrm_unknown_dst_flags;
126 static sfc_flow_spec_check sfc_flow_check_ifrm_unknown_dst_flags;
127 static sfc_flow_spec_set_vals sfc_flow_set_outer_vid_flag;
128 static sfc_flow_spec_check sfc_flow_check_outer_vid_flag;
131 sfc_flow_is_zero(const uint8_t *buf, unsigned int size)
136 for (i = 0; i < size; i++)
139 return (sum == 0) ? B_TRUE : B_FALSE;
143 * Validate item and prepare structures spec and mask for parsing
146 sfc_flow_parse_init(const struct rte_flow_item *item,
147 const void **spec_ptr,
148 const void **mask_ptr,
149 const void *supp_mask,
150 const void *def_mask,
152 struct rte_flow_error *error)
161 rte_flow_error_set(error, EINVAL,
162 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
167 if ((item->last != NULL || item->mask != NULL) && item->spec == NULL) {
168 rte_flow_error_set(error, EINVAL,
169 RTE_FLOW_ERROR_TYPE_ITEM, item,
170 "Mask or last is set without spec");
175 * If "mask" is not set, default mask is used,
176 * but if default mask is NULL, "mask" should be set
178 if (item->mask == NULL) {
179 if (def_mask == NULL) {
180 rte_flow_error_set(error, EINVAL,
181 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
182 "Mask should be specified");
198 * If field values in "last" are either 0 or equal to the corresponding
199 * values in "spec" then they are ignored
202 !sfc_flow_is_zero(last, size) &&
203 memcmp(last, spec, size) != 0) {
204 rte_flow_error_set(error, ENOTSUP,
205 RTE_FLOW_ERROR_TYPE_ITEM, item,
206 "Ranging is not supported");
210 if (supp_mask == NULL) {
211 rte_flow_error_set(error, EINVAL,
212 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
213 "Supported mask for item should be specified");
217 /* Check that mask does not ask for more match than supp_mask */
218 for (i = 0; i < size; i++) {
219 supp = ((const uint8_t *)supp_mask)[i];
221 if (~supp & mask[i]) {
222 rte_flow_error_set(error, ENOTSUP,
223 RTE_FLOW_ERROR_TYPE_ITEM, item,
224 "Item's field is not supported");
237 * Masking is not supported, so masks in items should be either
238 * full or empty (zeroed) and set only for supported fields which
239 * are specified in the supp_mask.
243 sfc_flow_parse_void(__rte_unused const struct rte_flow_item *item,
244 __rte_unused struct sfc_flow_parse_ctx *parse_ctx,
245 __rte_unused struct rte_flow_error *error)
251 * Convert Ethernet item to EFX filter specification.
254 * Item specification. Outer frame specification may only comprise
255 * source/destination addresses and Ethertype field.
256 * Inner frame specification may contain destination address only.
257 * There is support for individual/group mask as well as for empty and full.
258 * If the mask is NULL, default mask will be used. Ranging is not supported.
259 * @param efx_spec[in, out]
260 * EFX filter specification to update.
262 * Perform verbose error reporting if not NULL.
265 sfc_flow_parse_eth(const struct rte_flow_item *item,
266 struct sfc_flow_parse_ctx *parse_ctx,
267 struct rte_flow_error *error)
270 efx_filter_spec_t *efx_spec = parse_ctx->filter;
271 const struct rte_flow_item_eth *spec = NULL;
272 const struct rte_flow_item_eth *mask = NULL;
273 const struct rte_flow_item_eth supp_mask = {
274 .dst.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
275 .src.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
278 const struct rte_flow_item_eth ifrm_supp_mask = {
279 .dst.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
281 const uint8_t ig_mask[EFX_MAC_ADDR_LEN] = {
282 0x01, 0x00, 0x00, 0x00, 0x00, 0x00
284 const struct rte_flow_item_eth *supp_mask_p;
285 const struct rte_flow_item_eth *def_mask_p;
286 uint8_t *loc_mac = NULL;
287 boolean_t is_ifrm = (efx_spec->efs_encap_type !=
288 EFX_TUNNEL_PROTOCOL_NONE);
291 supp_mask_p = &ifrm_supp_mask;
292 def_mask_p = &ifrm_supp_mask;
293 loc_mac = efx_spec->efs_ifrm_loc_mac;
295 supp_mask_p = &supp_mask;
296 def_mask_p = &rte_flow_item_eth_mask;
297 loc_mac = efx_spec->efs_loc_mac;
300 rc = sfc_flow_parse_init(item,
301 (const void **)&spec,
302 (const void **)&mask,
303 supp_mask_p, def_mask_p,
304 sizeof(struct rte_flow_item_eth),
309 /* If "spec" is not set, could be any Ethernet */
313 if (rte_is_same_ether_addr(&mask->dst, &supp_mask.dst)) {
314 efx_spec->efs_match_flags |= is_ifrm ?
315 EFX_FILTER_MATCH_IFRM_LOC_MAC :
316 EFX_FILTER_MATCH_LOC_MAC;
317 rte_memcpy(loc_mac, spec->dst.addr_bytes,
319 } else if (memcmp(mask->dst.addr_bytes, ig_mask,
320 EFX_MAC_ADDR_LEN) == 0) {
321 if (rte_is_unicast_ether_addr(&spec->dst))
322 efx_spec->efs_match_flags |= is_ifrm ?
323 EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST :
324 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST;
326 efx_spec->efs_match_flags |= is_ifrm ?
327 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST :
328 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST;
329 } else if (!rte_is_zero_ether_addr(&mask->dst)) {
334 * ifrm_supp_mask ensures that the source address and
335 * ethertype masks are equal to zero in inner frame,
336 * so these fields are filled in only for the outer frame
338 if (rte_is_same_ether_addr(&mask->src, &supp_mask.src)) {
339 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_MAC;
340 rte_memcpy(efx_spec->efs_rem_mac, spec->src.addr_bytes,
342 } else if (!rte_is_zero_ether_addr(&mask->src)) {
347 * Ether type is in big-endian byte order in item and
348 * in little-endian in efx_spec, so byte swap is used
350 if (mask->type == supp_mask.type) {
351 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
352 efx_spec->efs_ether_type = rte_bswap16(spec->type);
353 } else if (mask->type != 0) {
360 rte_flow_error_set(error, EINVAL,
361 RTE_FLOW_ERROR_TYPE_ITEM, item,
362 "Bad mask in the ETH pattern item");
367 * Convert VLAN item to EFX filter specification.
370 * Item specification. Only VID field is supported.
371 * The mask can not be NULL. Ranging is not supported.
372 * @param efx_spec[in, out]
373 * EFX filter specification to update.
375 * Perform verbose error reporting if not NULL.
378 sfc_flow_parse_vlan(const struct rte_flow_item *item,
379 struct sfc_flow_parse_ctx *parse_ctx,
380 struct rte_flow_error *error)
384 efx_filter_spec_t *efx_spec = parse_ctx->filter;
385 const struct rte_flow_item_vlan *spec = NULL;
386 const struct rte_flow_item_vlan *mask = NULL;
387 const struct rte_flow_item_vlan supp_mask = {
388 .tci = rte_cpu_to_be_16(ETH_VLAN_ID_MAX),
389 .inner_type = RTE_BE16(0xffff),
392 rc = sfc_flow_parse_init(item,
393 (const void **)&spec,
394 (const void **)&mask,
397 sizeof(struct rte_flow_item_vlan),
403 * VID is in big-endian byte order in item and
404 * in little-endian in efx_spec, so byte swap is used.
405 * If two VLAN items are included, the first matches
406 * the outer tag and the next matches the inner tag.
408 if (mask->tci == supp_mask.tci) {
409 /* Apply mask to keep VID only */
410 vid = rte_bswap16(spec->tci & mask->tci);
412 if (!(efx_spec->efs_match_flags &
413 EFX_FILTER_MATCH_OUTER_VID)) {
414 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_OUTER_VID;
415 efx_spec->efs_outer_vid = vid;
416 } else if (!(efx_spec->efs_match_flags &
417 EFX_FILTER_MATCH_INNER_VID)) {
418 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_INNER_VID;
419 efx_spec->efs_inner_vid = vid;
421 rte_flow_error_set(error, EINVAL,
422 RTE_FLOW_ERROR_TYPE_ITEM, item,
423 "More than two VLAN items");
427 rte_flow_error_set(error, EINVAL,
428 RTE_FLOW_ERROR_TYPE_ITEM, item,
429 "VLAN ID in TCI match is required");
433 if (efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE) {
434 rte_flow_error_set(error, EINVAL,
435 RTE_FLOW_ERROR_TYPE_ITEM, item,
436 "VLAN TPID matching is not supported");
439 if (mask->inner_type == supp_mask.inner_type) {
440 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
441 efx_spec->efs_ether_type = rte_bswap16(spec->inner_type);
442 } else if (mask->inner_type) {
443 rte_flow_error_set(error, EINVAL,
444 RTE_FLOW_ERROR_TYPE_ITEM, item,
445 "Bad mask for VLAN inner_type");
453 * Convert IPv4 item to EFX filter specification.
456 * Item specification. Only source and destination addresses and
457 * protocol fields are supported. If the mask is NULL, default
458 * mask will be used. Ranging is not supported.
459 * @param efx_spec[in, out]
460 * EFX filter specification to update.
462 * Perform verbose error reporting if not NULL.
465 sfc_flow_parse_ipv4(const struct rte_flow_item *item,
466 struct sfc_flow_parse_ctx *parse_ctx,
467 struct rte_flow_error *error)
470 efx_filter_spec_t *efx_spec = parse_ctx->filter;
471 const struct rte_flow_item_ipv4 *spec = NULL;
472 const struct rte_flow_item_ipv4 *mask = NULL;
473 const uint16_t ether_type_ipv4 = rte_cpu_to_le_16(EFX_ETHER_TYPE_IPV4);
474 const struct rte_flow_item_ipv4 supp_mask = {
476 .src_addr = 0xffffffff,
477 .dst_addr = 0xffffffff,
478 .next_proto_id = 0xff,
482 rc = sfc_flow_parse_init(item,
483 (const void **)&spec,
484 (const void **)&mask,
486 &rte_flow_item_ipv4_mask,
487 sizeof(struct rte_flow_item_ipv4),
493 * Filtering by IPv4 source and destination addresses requires
494 * the appropriate ETHER_TYPE in hardware filters
496 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE)) {
497 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
498 efx_spec->efs_ether_type = ether_type_ipv4;
499 } else if (efx_spec->efs_ether_type != ether_type_ipv4) {
500 rte_flow_error_set(error, EINVAL,
501 RTE_FLOW_ERROR_TYPE_ITEM, item,
502 "Ethertype in pattern with IPV4 item should be appropriate");
510 * IPv4 addresses are in big-endian byte order in item and in
513 if (mask->hdr.src_addr == supp_mask.hdr.src_addr) {
514 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_HOST;
515 efx_spec->efs_rem_host.eo_u32[0] = spec->hdr.src_addr;
516 } else if (mask->hdr.src_addr != 0) {
520 if (mask->hdr.dst_addr == supp_mask.hdr.dst_addr) {
521 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_HOST;
522 efx_spec->efs_loc_host.eo_u32[0] = spec->hdr.dst_addr;
523 } else if (mask->hdr.dst_addr != 0) {
527 if (mask->hdr.next_proto_id == supp_mask.hdr.next_proto_id) {
528 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
529 efx_spec->efs_ip_proto = spec->hdr.next_proto_id;
530 } else if (mask->hdr.next_proto_id != 0) {
537 rte_flow_error_set(error, EINVAL,
538 RTE_FLOW_ERROR_TYPE_ITEM, item,
539 "Bad mask in the IPV4 pattern item");
544 * Convert IPv6 item to EFX filter specification.
547 * Item specification. Only source and destination addresses and
548 * next header fields are supported. If the mask is NULL, default
549 * mask will be used. Ranging is not supported.
550 * @param efx_spec[in, out]
551 * EFX filter specification to update.
553 * Perform verbose error reporting if not NULL.
556 sfc_flow_parse_ipv6(const struct rte_flow_item *item,
557 struct sfc_flow_parse_ctx *parse_ctx,
558 struct rte_flow_error *error)
561 efx_filter_spec_t *efx_spec = parse_ctx->filter;
562 const struct rte_flow_item_ipv6 *spec = NULL;
563 const struct rte_flow_item_ipv6 *mask = NULL;
564 const uint16_t ether_type_ipv6 = rte_cpu_to_le_16(EFX_ETHER_TYPE_IPV6);
565 const struct rte_flow_item_ipv6 supp_mask = {
567 .src_addr = { 0xff, 0xff, 0xff, 0xff,
568 0xff, 0xff, 0xff, 0xff,
569 0xff, 0xff, 0xff, 0xff,
570 0xff, 0xff, 0xff, 0xff },
571 .dst_addr = { 0xff, 0xff, 0xff, 0xff,
572 0xff, 0xff, 0xff, 0xff,
573 0xff, 0xff, 0xff, 0xff,
574 0xff, 0xff, 0xff, 0xff },
579 rc = sfc_flow_parse_init(item,
580 (const void **)&spec,
581 (const void **)&mask,
583 &rte_flow_item_ipv6_mask,
584 sizeof(struct rte_flow_item_ipv6),
590 * Filtering by IPv6 source and destination addresses requires
591 * the appropriate ETHER_TYPE in hardware filters
593 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE)) {
594 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
595 efx_spec->efs_ether_type = ether_type_ipv6;
596 } else if (efx_spec->efs_ether_type != ether_type_ipv6) {
597 rte_flow_error_set(error, EINVAL,
598 RTE_FLOW_ERROR_TYPE_ITEM, item,
599 "Ethertype in pattern with IPV6 item should be appropriate");
607 * IPv6 addresses are in big-endian byte order in item and in
610 if (memcmp(mask->hdr.src_addr, supp_mask.hdr.src_addr,
611 sizeof(mask->hdr.src_addr)) == 0) {
612 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_HOST;
614 RTE_BUILD_BUG_ON(sizeof(efx_spec->efs_rem_host) !=
615 sizeof(spec->hdr.src_addr));
616 rte_memcpy(&efx_spec->efs_rem_host, spec->hdr.src_addr,
617 sizeof(efx_spec->efs_rem_host));
618 } else if (!sfc_flow_is_zero(mask->hdr.src_addr,
619 sizeof(mask->hdr.src_addr))) {
623 if (memcmp(mask->hdr.dst_addr, supp_mask.hdr.dst_addr,
624 sizeof(mask->hdr.dst_addr)) == 0) {
625 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_HOST;
627 RTE_BUILD_BUG_ON(sizeof(efx_spec->efs_loc_host) !=
628 sizeof(spec->hdr.dst_addr));
629 rte_memcpy(&efx_spec->efs_loc_host, spec->hdr.dst_addr,
630 sizeof(efx_spec->efs_loc_host));
631 } else if (!sfc_flow_is_zero(mask->hdr.dst_addr,
632 sizeof(mask->hdr.dst_addr))) {
636 if (mask->hdr.proto == supp_mask.hdr.proto) {
637 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
638 efx_spec->efs_ip_proto = spec->hdr.proto;
639 } else if (mask->hdr.proto != 0) {
646 rte_flow_error_set(error, EINVAL,
647 RTE_FLOW_ERROR_TYPE_ITEM, item,
648 "Bad mask in the IPV6 pattern item");
653 * Convert TCP item to EFX filter specification.
656 * Item specification. Only source and destination ports fields
657 * are supported. If the mask is NULL, default mask will be used.
658 * Ranging is not supported.
659 * @param efx_spec[in, out]
660 * EFX filter specification to update.
662 * Perform verbose error reporting if not NULL.
665 sfc_flow_parse_tcp(const struct rte_flow_item *item,
666 struct sfc_flow_parse_ctx *parse_ctx,
667 struct rte_flow_error *error)
670 efx_filter_spec_t *efx_spec = parse_ctx->filter;
671 const struct rte_flow_item_tcp *spec = NULL;
672 const struct rte_flow_item_tcp *mask = NULL;
673 const struct rte_flow_item_tcp supp_mask = {
680 rc = sfc_flow_parse_init(item,
681 (const void **)&spec,
682 (const void **)&mask,
684 &rte_flow_item_tcp_mask,
685 sizeof(struct rte_flow_item_tcp),
691 * Filtering by TCP source and destination ports requires
692 * the appropriate IP_PROTO in hardware filters
694 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_IP_PROTO)) {
695 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
696 efx_spec->efs_ip_proto = EFX_IPPROTO_TCP;
697 } else if (efx_spec->efs_ip_proto != EFX_IPPROTO_TCP) {
698 rte_flow_error_set(error, EINVAL,
699 RTE_FLOW_ERROR_TYPE_ITEM, item,
700 "IP proto in pattern with TCP item should be appropriate");
708 * Source and destination ports are in big-endian byte order in item and
709 * in little-endian in efx_spec, so byte swap is used
711 if (mask->hdr.src_port == supp_mask.hdr.src_port) {
712 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_PORT;
713 efx_spec->efs_rem_port = rte_bswap16(spec->hdr.src_port);
714 } else if (mask->hdr.src_port != 0) {
718 if (mask->hdr.dst_port == supp_mask.hdr.dst_port) {
719 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_PORT;
720 efx_spec->efs_loc_port = rte_bswap16(spec->hdr.dst_port);
721 } else if (mask->hdr.dst_port != 0) {
728 rte_flow_error_set(error, EINVAL,
729 RTE_FLOW_ERROR_TYPE_ITEM, item,
730 "Bad mask in the TCP pattern item");
735 * Convert UDP item to EFX filter specification.
738 * Item specification. Only source and destination ports fields
739 * are supported. If the mask is NULL, default mask will be used.
740 * Ranging is not supported.
741 * @param efx_spec[in, out]
742 * EFX filter specification to update.
744 * Perform verbose error reporting if not NULL.
747 sfc_flow_parse_udp(const struct rte_flow_item *item,
748 struct sfc_flow_parse_ctx *parse_ctx,
749 struct rte_flow_error *error)
752 efx_filter_spec_t *efx_spec = parse_ctx->filter;
753 const struct rte_flow_item_udp *spec = NULL;
754 const struct rte_flow_item_udp *mask = NULL;
755 const struct rte_flow_item_udp supp_mask = {
762 rc = sfc_flow_parse_init(item,
763 (const void **)&spec,
764 (const void **)&mask,
766 &rte_flow_item_udp_mask,
767 sizeof(struct rte_flow_item_udp),
773 * Filtering by UDP source and destination ports requires
774 * the appropriate IP_PROTO in hardware filters
776 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_IP_PROTO)) {
777 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
778 efx_spec->efs_ip_proto = EFX_IPPROTO_UDP;
779 } else if (efx_spec->efs_ip_proto != EFX_IPPROTO_UDP) {
780 rte_flow_error_set(error, EINVAL,
781 RTE_FLOW_ERROR_TYPE_ITEM, item,
782 "IP proto in pattern with UDP item should be appropriate");
790 * Source and destination ports are in big-endian byte order in item and
791 * in little-endian in efx_spec, so byte swap is used
793 if (mask->hdr.src_port == supp_mask.hdr.src_port) {
794 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_PORT;
795 efx_spec->efs_rem_port = rte_bswap16(spec->hdr.src_port);
796 } else if (mask->hdr.src_port != 0) {
800 if (mask->hdr.dst_port == supp_mask.hdr.dst_port) {
801 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_PORT;
802 efx_spec->efs_loc_port = rte_bswap16(spec->hdr.dst_port);
803 } else if (mask->hdr.dst_port != 0) {
810 rte_flow_error_set(error, EINVAL,
811 RTE_FLOW_ERROR_TYPE_ITEM, item,
812 "Bad mask in the UDP pattern item");
817 * Filters for encapsulated packets match based on the EtherType and IP
818 * protocol in the outer frame.
821 sfc_flow_set_match_flags_for_encap_pkts(const struct rte_flow_item *item,
822 efx_filter_spec_t *efx_spec,
824 struct rte_flow_error *error)
826 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_IP_PROTO)) {
827 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
828 efx_spec->efs_ip_proto = ip_proto;
829 } else if (efx_spec->efs_ip_proto != ip_proto) {
831 case EFX_IPPROTO_UDP:
832 rte_flow_error_set(error, EINVAL,
833 RTE_FLOW_ERROR_TYPE_ITEM, item,
834 "Outer IP header protocol must be UDP "
835 "in VxLAN/GENEVE pattern");
838 case EFX_IPPROTO_GRE:
839 rte_flow_error_set(error, EINVAL,
840 RTE_FLOW_ERROR_TYPE_ITEM, item,
841 "Outer IP header protocol must be GRE "
846 rte_flow_error_set(error, EINVAL,
847 RTE_FLOW_ERROR_TYPE_ITEM, item,
848 "Only VxLAN/GENEVE/NVGRE tunneling patterns "
854 if (efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
855 efx_spec->efs_ether_type != EFX_ETHER_TYPE_IPV4 &&
856 efx_spec->efs_ether_type != EFX_ETHER_TYPE_IPV6) {
857 rte_flow_error_set(error, EINVAL,
858 RTE_FLOW_ERROR_TYPE_ITEM, item,
859 "Outer frame EtherType in pattern with tunneling "
860 "must be IPv4 or IPv6");
868 sfc_flow_set_efx_spec_vni_or_vsid(efx_filter_spec_t *efx_spec,
869 const uint8_t *vni_or_vsid_val,
870 const uint8_t *vni_or_vsid_mask,
871 const struct rte_flow_item *item,
872 struct rte_flow_error *error)
874 const uint8_t vni_or_vsid_full_mask[EFX_VNI_OR_VSID_LEN] = {
878 if (memcmp(vni_or_vsid_mask, vni_or_vsid_full_mask,
879 EFX_VNI_OR_VSID_LEN) == 0) {
880 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_VNI_OR_VSID;
881 rte_memcpy(efx_spec->efs_vni_or_vsid, vni_or_vsid_val,
882 EFX_VNI_OR_VSID_LEN);
883 } else if (!sfc_flow_is_zero(vni_or_vsid_mask, EFX_VNI_OR_VSID_LEN)) {
884 rte_flow_error_set(error, EINVAL,
885 RTE_FLOW_ERROR_TYPE_ITEM, item,
886 "Unsupported VNI/VSID mask");
894 * Convert VXLAN item to EFX filter specification.
897 * Item specification. Only VXLAN network identifier field is supported.
898 * If the mask is NULL, default mask will be used.
899 * Ranging is not supported.
900 * @param efx_spec[in, out]
901 * EFX filter specification to update.
903 * Perform verbose error reporting if not NULL.
906 sfc_flow_parse_vxlan(const struct rte_flow_item *item,
907 struct sfc_flow_parse_ctx *parse_ctx,
908 struct rte_flow_error *error)
911 efx_filter_spec_t *efx_spec = parse_ctx->filter;
912 const struct rte_flow_item_vxlan *spec = NULL;
913 const struct rte_flow_item_vxlan *mask = NULL;
914 const struct rte_flow_item_vxlan supp_mask = {
915 .vni = { 0xff, 0xff, 0xff }
918 rc = sfc_flow_parse_init(item,
919 (const void **)&spec,
920 (const void **)&mask,
922 &rte_flow_item_vxlan_mask,
923 sizeof(struct rte_flow_item_vxlan),
928 rc = sfc_flow_set_match_flags_for_encap_pkts(item, efx_spec,
929 EFX_IPPROTO_UDP, error);
933 efx_spec->efs_encap_type = EFX_TUNNEL_PROTOCOL_VXLAN;
934 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
939 rc = sfc_flow_set_efx_spec_vni_or_vsid(efx_spec, spec->vni,
940 mask->vni, item, error);
946 * Convert GENEVE item to EFX filter specification.
949 * Item specification. Only Virtual Network Identifier and protocol type
950 * fields are supported. But protocol type can be only Ethernet (0x6558).
951 * If the mask is NULL, default mask will be used.
952 * Ranging is not supported.
953 * @param efx_spec[in, out]
954 * EFX filter specification to update.
956 * Perform verbose error reporting if not NULL.
959 sfc_flow_parse_geneve(const struct rte_flow_item *item,
960 struct sfc_flow_parse_ctx *parse_ctx,
961 struct rte_flow_error *error)
964 efx_filter_spec_t *efx_spec = parse_ctx->filter;
965 const struct rte_flow_item_geneve *spec = NULL;
966 const struct rte_flow_item_geneve *mask = NULL;
967 const struct rte_flow_item_geneve supp_mask = {
968 .protocol = RTE_BE16(0xffff),
969 .vni = { 0xff, 0xff, 0xff }
972 rc = sfc_flow_parse_init(item,
973 (const void **)&spec,
974 (const void **)&mask,
976 &rte_flow_item_geneve_mask,
977 sizeof(struct rte_flow_item_geneve),
982 rc = sfc_flow_set_match_flags_for_encap_pkts(item, efx_spec,
983 EFX_IPPROTO_UDP, error);
987 efx_spec->efs_encap_type = EFX_TUNNEL_PROTOCOL_GENEVE;
988 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
993 if (mask->protocol == supp_mask.protocol) {
994 if (spec->protocol != rte_cpu_to_be_16(RTE_ETHER_TYPE_TEB)) {
995 rte_flow_error_set(error, EINVAL,
996 RTE_FLOW_ERROR_TYPE_ITEM, item,
997 "GENEVE encap. protocol must be Ethernet "
998 "(0x6558) in the GENEVE pattern item");
1001 } else if (mask->protocol != 0) {
1002 rte_flow_error_set(error, EINVAL,
1003 RTE_FLOW_ERROR_TYPE_ITEM, item,
1004 "Unsupported mask for GENEVE encap. protocol");
1008 rc = sfc_flow_set_efx_spec_vni_or_vsid(efx_spec, spec->vni,
1009 mask->vni, item, error);
1015 * Convert NVGRE item to EFX filter specification.
1018 * Item specification. Only virtual subnet ID field is supported.
1019 * If the mask is NULL, default mask will be used.
1020 * Ranging is not supported.
1021 * @param efx_spec[in, out]
1022 * EFX filter specification to update.
1024 * Perform verbose error reporting if not NULL.
1027 sfc_flow_parse_nvgre(const struct rte_flow_item *item,
1028 struct sfc_flow_parse_ctx *parse_ctx,
1029 struct rte_flow_error *error)
1032 efx_filter_spec_t *efx_spec = parse_ctx->filter;
1033 const struct rte_flow_item_nvgre *spec = NULL;
1034 const struct rte_flow_item_nvgre *mask = NULL;
1035 const struct rte_flow_item_nvgre supp_mask = {
1036 .tni = { 0xff, 0xff, 0xff }
1039 rc = sfc_flow_parse_init(item,
1040 (const void **)&spec,
1041 (const void **)&mask,
1043 &rte_flow_item_nvgre_mask,
1044 sizeof(struct rte_flow_item_nvgre),
1049 rc = sfc_flow_set_match_flags_for_encap_pkts(item, efx_spec,
1050 EFX_IPPROTO_GRE, error);
1054 efx_spec->efs_encap_type = EFX_TUNNEL_PROTOCOL_NVGRE;
1055 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
1060 rc = sfc_flow_set_efx_spec_vni_or_vsid(efx_spec, spec->tni,
1061 mask->tni, item, error);
1066 static const struct sfc_flow_item sfc_flow_items[] = {
1068 .type = RTE_FLOW_ITEM_TYPE_VOID,
1069 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
1070 .layer = SFC_FLOW_ITEM_ANY_LAYER,
1071 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1072 .parse = sfc_flow_parse_void,
1075 .type = RTE_FLOW_ITEM_TYPE_ETH,
1076 .prev_layer = SFC_FLOW_ITEM_START_LAYER,
1077 .layer = SFC_FLOW_ITEM_L2,
1078 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1079 .parse = sfc_flow_parse_eth,
1082 .type = RTE_FLOW_ITEM_TYPE_VLAN,
1083 .prev_layer = SFC_FLOW_ITEM_L2,
1084 .layer = SFC_FLOW_ITEM_L2,
1085 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1086 .parse = sfc_flow_parse_vlan,
1089 .type = RTE_FLOW_ITEM_TYPE_IPV4,
1090 .prev_layer = SFC_FLOW_ITEM_L2,
1091 .layer = SFC_FLOW_ITEM_L3,
1092 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1093 .parse = sfc_flow_parse_ipv4,
1096 .type = RTE_FLOW_ITEM_TYPE_IPV6,
1097 .prev_layer = SFC_FLOW_ITEM_L2,
1098 .layer = SFC_FLOW_ITEM_L3,
1099 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1100 .parse = sfc_flow_parse_ipv6,
1103 .type = RTE_FLOW_ITEM_TYPE_TCP,
1104 .prev_layer = SFC_FLOW_ITEM_L3,
1105 .layer = SFC_FLOW_ITEM_L4,
1106 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1107 .parse = sfc_flow_parse_tcp,
1110 .type = RTE_FLOW_ITEM_TYPE_UDP,
1111 .prev_layer = SFC_FLOW_ITEM_L3,
1112 .layer = SFC_FLOW_ITEM_L4,
1113 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1114 .parse = sfc_flow_parse_udp,
1117 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
1118 .prev_layer = SFC_FLOW_ITEM_L4,
1119 .layer = SFC_FLOW_ITEM_START_LAYER,
1120 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1121 .parse = sfc_flow_parse_vxlan,
1124 .type = RTE_FLOW_ITEM_TYPE_GENEVE,
1125 .prev_layer = SFC_FLOW_ITEM_L4,
1126 .layer = SFC_FLOW_ITEM_START_LAYER,
1127 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1128 .parse = sfc_flow_parse_geneve,
1131 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
1132 .prev_layer = SFC_FLOW_ITEM_L3,
1133 .layer = SFC_FLOW_ITEM_START_LAYER,
1134 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1135 .parse = sfc_flow_parse_nvgre,
1140 * Protocol-independent flow API support
1143 sfc_flow_parse_attr(struct sfc_adapter *sa,
1144 const struct rte_flow_attr *attr,
1145 struct rte_flow *flow,
1146 struct rte_flow_error *error)
1148 struct sfc_flow_spec *spec = &flow->spec;
1149 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1150 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
1151 struct sfc_mae *mae = &sa->mae;
1154 rte_flow_error_set(error, EINVAL,
1155 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
1159 if (attr->group != 0) {
1160 rte_flow_error_set(error, ENOTSUP,
1161 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, attr,
1162 "Groups are not supported");
1165 if (attr->egress != 0) {
1166 rte_flow_error_set(error, ENOTSUP,
1167 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attr,
1168 "Egress is not supported");
1171 if (attr->ingress == 0) {
1172 rte_flow_error_set(error, ENOTSUP,
1173 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, attr,
1174 "Ingress is compulsory");
1177 if (attr->transfer == 0) {
1178 if (attr->priority != 0) {
1179 rte_flow_error_set(error, ENOTSUP,
1180 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1181 attr, "Priorities are unsupported");
1184 spec->type = SFC_FLOW_SPEC_FILTER;
1185 spec_filter->template.efs_flags |= EFX_FILTER_FLAG_RX;
1186 spec_filter->template.efs_rss_context = EFX_RSS_CONTEXT_DEFAULT;
1187 spec_filter->template.efs_priority = EFX_FILTER_PRI_MANUAL;
1189 if (mae->status != SFC_MAE_STATUS_SUPPORTED) {
1190 rte_flow_error_set(error, ENOTSUP,
1191 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1192 attr, "Transfer is not supported");
1195 if (attr->priority > mae->nb_action_rule_prios_max) {
1196 rte_flow_error_set(error, ENOTSUP,
1197 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1198 attr, "Unsupported priority level");
1201 spec->type = SFC_FLOW_SPEC_MAE;
1202 spec_mae->priority = attr->priority;
1203 spec_mae->match_spec = NULL;
1204 spec_mae->action_set = NULL;
1205 spec_mae->rule_id.id = EFX_MAE_RSRC_ID_INVALID;
1211 /* Get item from array sfc_flow_items */
1212 static const struct sfc_flow_item *
1213 sfc_flow_get_item(const struct sfc_flow_item *items,
1214 unsigned int nb_items,
1215 enum rte_flow_item_type type)
1219 for (i = 0; i < nb_items; i++)
1220 if (items[i].type == type)
1227 sfc_flow_parse_pattern(const struct sfc_flow_item *flow_items,
1228 unsigned int nb_flow_items,
1229 const struct rte_flow_item pattern[],
1230 struct sfc_flow_parse_ctx *parse_ctx,
1231 struct rte_flow_error *error)
1234 unsigned int prev_layer = SFC_FLOW_ITEM_ANY_LAYER;
1235 boolean_t is_ifrm = B_FALSE;
1236 const struct sfc_flow_item *item;
1238 if (pattern == NULL) {
1239 rte_flow_error_set(error, EINVAL,
1240 RTE_FLOW_ERROR_TYPE_ITEM_NUM, NULL,
1245 for (; pattern->type != RTE_FLOW_ITEM_TYPE_END; pattern++) {
1246 item = sfc_flow_get_item(flow_items, nb_flow_items,
1249 rte_flow_error_set(error, ENOTSUP,
1250 RTE_FLOW_ERROR_TYPE_ITEM, pattern,
1251 "Unsupported pattern item");
1256 * Omitting one or several protocol layers at the beginning
1257 * of pattern is supported
1259 if (item->prev_layer != SFC_FLOW_ITEM_ANY_LAYER &&
1260 prev_layer != SFC_FLOW_ITEM_ANY_LAYER &&
1261 item->prev_layer != prev_layer) {
1262 rte_flow_error_set(error, ENOTSUP,
1263 RTE_FLOW_ERROR_TYPE_ITEM, pattern,
1264 "Unexpected sequence of pattern items");
1269 * Allow only VOID and ETH pattern items in the inner frame.
1270 * Also check that there is only one tunneling protocol.
1272 switch (item->type) {
1273 case RTE_FLOW_ITEM_TYPE_VOID:
1274 case RTE_FLOW_ITEM_TYPE_ETH:
1277 case RTE_FLOW_ITEM_TYPE_VXLAN:
1278 case RTE_FLOW_ITEM_TYPE_GENEVE:
1279 case RTE_FLOW_ITEM_TYPE_NVGRE:
1281 rte_flow_error_set(error, EINVAL,
1282 RTE_FLOW_ERROR_TYPE_ITEM,
1284 "More than one tunneling protocol");
1292 rte_flow_error_set(error, EINVAL,
1293 RTE_FLOW_ERROR_TYPE_ITEM,
1295 "There is an unsupported pattern item "
1296 "in the inner frame");
1302 if (parse_ctx->type != item->ctx_type) {
1303 rte_flow_error_set(error, EINVAL,
1304 RTE_FLOW_ERROR_TYPE_ITEM, pattern,
1305 "Parse context type mismatch");
1309 rc = item->parse(pattern, parse_ctx, error);
1313 if (item->layer != SFC_FLOW_ITEM_ANY_LAYER)
1314 prev_layer = item->layer;
1321 sfc_flow_parse_queue(struct sfc_adapter *sa,
1322 const struct rte_flow_action_queue *queue,
1323 struct rte_flow *flow)
1325 struct sfc_flow_spec *spec = &flow->spec;
1326 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1327 struct sfc_rxq *rxq;
1328 struct sfc_rxq_info *rxq_info;
1330 if (queue->index >= sfc_sa2shared(sa)->rxq_count)
1333 rxq = &sa->rxq_ctrl[queue->index];
1334 spec_filter->template.efs_dmaq_id = (uint16_t)rxq->hw_index;
1336 rxq_info = &sfc_sa2shared(sa)->rxq_info[queue->index];
1337 spec_filter->rss_hash_required = !!(rxq_info->rxq_flags &
1338 SFC_RXQ_FLAG_RSS_HASH);
1344 sfc_flow_parse_rss(struct sfc_adapter *sa,
1345 const struct rte_flow_action_rss *action_rss,
1346 struct rte_flow *flow)
1348 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
1349 struct sfc_rss *rss = &sas->rss;
1350 unsigned int rxq_sw_index;
1351 struct sfc_rxq *rxq;
1352 unsigned int rxq_hw_index_min;
1353 unsigned int rxq_hw_index_max;
1354 efx_rx_hash_type_t efx_hash_types;
1355 const uint8_t *rss_key;
1356 struct sfc_flow_spec *spec = &flow->spec;
1357 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1358 struct sfc_flow_rss *sfc_rss_conf = &spec_filter->rss_conf;
1361 if (action_rss->queue_num == 0)
1364 rxq_sw_index = sfc_sa2shared(sa)->rxq_count - 1;
1365 rxq = &sa->rxq_ctrl[rxq_sw_index];
1366 rxq_hw_index_min = rxq->hw_index;
1367 rxq_hw_index_max = 0;
1369 for (i = 0; i < action_rss->queue_num; ++i) {
1370 rxq_sw_index = action_rss->queue[i];
1372 if (rxq_sw_index >= sfc_sa2shared(sa)->rxq_count)
1375 rxq = &sa->rxq_ctrl[rxq_sw_index];
1377 if (rxq->hw_index < rxq_hw_index_min)
1378 rxq_hw_index_min = rxq->hw_index;
1380 if (rxq->hw_index > rxq_hw_index_max)
1381 rxq_hw_index_max = rxq->hw_index;
1384 switch (action_rss->func) {
1385 case RTE_ETH_HASH_FUNCTION_DEFAULT:
1386 case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
1392 if (action_rss->level)
1396 * Dummy RSS action with only one queue and no specific settings
1397 * for hash types and key does not require dedicated RSS context
1398 * and may be simplified to single queue action.
1400 if (action_rss->queue_num == 1 && action_rss->types == 0 &&
1401 action_rss->key_len == 0) {
1402 spec_filter->template.efs_dmaq_id = rxq_hw_index_min;
1406 if (action_rss->types) {
1409 rc = sfc_rx_hf_rte_to_efx(sa, action_rss->types,
1417 for (i = 0; i < rss->hf_map_nb_entries; ++i)
1418 efx_hash_types |= rss->hf_map[i].efx;
1421 if (action_rss->key_len) {
1422 if (action_rss->key_len != sizeof(rss->key))
1425 rss_key = action_rss->key;
1430 spec_filter->rss = B_TRUE;
1432 sfc_rss_conf->rxq_hw_index_min = rxq_hw_index_min;
1433 sfc_rss_conf->rxq_hw_index_max = rxq_hw_index_max;
1434 sfc_rss_conf->rss_hash_types = efx_hash_types;
1435 rte_memcpy(sfc_rss_conf->rss_key, rss_key, sizeof(rss->key));
1437 for (i = 0; i < RTE_DIM(sfc_rss_conf->rss_tbl); ++i) {
1438 unsigned int nb_queues = action_rss->queue_num;
1439 unsigned int rxq_sw_index = action_rss->queue[i % nb_queues];
1440 struct sfc_rxq *rxq = &sa->rxq_ctrl[rxq_sw_index];
1442 sfc_rss_conf->rss_tbl[i] = rxq->hw_index - rxq_hw_index_min;
1449 sfc_flow_spec_flush(struct sfc_adapter *sa, struct sfc_flow_spec *spec,
1450 unsigned int filters_count)
1452 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1456 for (i = 0; i < filters_count; i++) {
1459 rc = efx_filter_remove(sa->nic, &spec_filter->filters[i]);
1460 if (ret == 0 && rc != 0) {
1461 sfc_err(sa, "failed to remove filter specification "
1471 sfc_flow_spec_insert(struct sfc_adapter *sa, struct sfc_flow_spec *spec)
1473 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1477 for (i = 0; i < spec_filter->count; i++) {
1478 rc = efx_filter_insert(sa->nic, &spec_filter->filters[i]);
1480 sfc_flow_spec_flush(sa, spec, i);
1489 sfc_flow_spec_remove(struct sfc_adapter *sa, struct sfc_flow_spec *spec)
1491 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1493 return sfc_flow_spec_flush(sa, spec, spec_filter->count);
1497 sfc_flow_filter_insert(struct sfc_adapter *sa,
1498 struct rte_flow *flow)
1500 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
1501 struct sfc_rss *rss = &sas->rss;
1502 struct sfc_flow_spec_filter *spec_filter = &flow->spec.filter;
1503 struct sfc_flow_rss *flow_rss = &spec_filter->rss_conf;
1504 uint32_t efs_rss_context = EFX_RSS_CONTEXT_DEFAULT;
1505 boolean_t create_context;
1509 create_context = spec_filter->rss || (spec_filter->rss_hash_required &&
1510 rss->dummy_rss_context == EFX_RSS_CONTEXT_DEFAULT);
1512 if (create_context) {
1513 unsigned int rss_spread;
1514 unsigned int rss_hash_types;
1517 if (spec_filter->rss) {
1518 rss_spread = MIN(flow_rss->rxq_hw_index_max -
1519 flow_rss->rxq_hw_index_min + 1,
1521 rss_hash_types = flow_rss->rss_hash_types;
1522 rss_key = flow_rss->rss_key;
1525 * Initialize dummy RSS context parameters to have
1526 * valid RSS hash. Use default RSS hash function and
1530 rss_hash_types = rss->hash_types;
1534 rc = efx_rx_scale_context_alloc(sa->nic,
1535 EFX_RX_SCALE_EXCLUSIVE,
1539 goto fail_scale_context_alloc;
1541 rc = efx_rx_scale_mode_set(sa->nic, efs_rss_context,
1543 rss_hash_types, B_TRUE);
1545 goto fail_scale_mode_set;
1547 rc = efx_rx_scale_key_set(sa->nic, efs_rss_context,
1548 rss_key, sizeof(rss->key));
1550 goto fail_scale_key_set;
1552 efs_rss_context = rss->dummy_rss_context;
1555 if (spec_filter->rss || spec_filter->rss_hash_required) {
1557 * At this point, fully elaborated filter specifications
1558 * have been produced from the template. To make sure that
1559 * RSS behaviour is consistent between them, set the same
1560 * RSS context value everywhere.
1562 for (i = 0; i < spec_filter->count; i++) {
1563 efx_filter_spec_t *spec = &spec_filter->filters[i];
1565 spec->efs_rss_context = efs_rss_context;
1566 spec->efs_flags |= EFX_FILTER_FLAG_RX_RSS;
1567 if (spec_filter->rss)
1568 spec->efs_dmaq_id = flow_rss->rxq_hw_index_min;
1572 rc = sfc_flow_spec_insert(sa, &flow->spec);
1574 goto fail_filter_insert;
1576 if (create_context) {
1577 unsigned int dummy_tbl[RTE_DIM(flow_rss->rss_tbl)] = {0};
1580 tbl = spec_filter->rss ? flow_rss->rss_tbl : dummy_tbl;
1583 * Scale table is set after filter insertion because
1584 * the table entries are relative to the base RxQ ID
1585 * and the latter is submitted to the HW by means of
1586 * inserting a filter, so by the time of the request
1587 * the HW knows all the information needed to verify
1588 * the table entries, and the operation will succeed
1590 rc = efx_rx_scale_tbl_set(sa->nic, efs_rss_context,
1591 tbl, RTE_DIM(flow_rss->rss_tbl));
1593 goto fail_scale_tbl_set;
1595 /* Remember created dummy RSS context */
1596 if (!spec_filter->rss)
1597 rss->dummy_rss_context = efs_rss_context;
1603 sfc_flow_spec_remove(sa, &flow->spec);
1607 fail_scale_mode_set:
1609 efx_rx_scale_context_free(sa->nic, efs_rss_context);
1611 fail_scale_context_alloc:
1616 sfc_flow_filter_remove(struct sfc_adapter *sa,
1617 struct rte_flow *flow)
1619 struct sfc_flow_spec_filter *spec_filter = &flow->spec.filter;
1622 rc = sfc_flow_spec_remove(sa, &flow->spec);
1626 if (spec_filter->rss) {
1628 * All specifications for a given flow rule have the same RSS
1629 * context, so that RSS context value is taken from the first
1630 * filter specification
1632 efx_filter_spec_t *spec = &spec_filter->filters[0];
1634 rc = efx_rx_scale_context_free(sa->nic, spec->efs_rss_context);
1641 sfc_flow_parse_mark(struct sfc_adapter *sa,
1642 const struct rte_flow_action_mark *mark,
1643 struct rte_flow *flow)
1645 struct sfc_flow_spec *spec = &flow->spec;
1646 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1647 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
1649 if (mark == NULL || mark->id > encp->enc_filter_action_mark_max)
1652 spec_filter->template.efs_flags |= EFX_FILTER_FLAG_ACTION_MARK;
1653 spec_filter->template.efs_mark = mark->id;
1659 sfc_flow_parse_actions(struct sfc_adapter *sa,
1660 const struct rte_flow_action actions[],
1661 struct rte_flow *flow,
1662 struct rte_flow_error *error)
1665 struct sfc_flow_spec *spec = &flow->spec;
1666 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1667 const unsigned int dp_rx_features = sa->priv.dp_rx->features;
1668 uint32_t actions_set = 0;
1669 const uint32_t fate_actions_mask = (1UL << RTE_FLOW_ACTION_TYPE_QUEUE) |
1670 (1UL << RTE_FLOW_ACTION_TYPE_RSS) |
1671 (1UL << RTE_FLOW_ACTION_TYPE_DROP);
1672 const uint32_t mark_actions_mask = (1UL << RTE_FLOW_ACTION_TYPE_MARK) |
1673 (1UL << RTE_FLOW_ACTION_TYPE_FLAG);
1675 if (actions == NULL) {
1676 rte_flow_error_set(error, EINVAL,
1677 RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
1682 #define SFC_BUILD_SET_OVERFLOW(_action, _set) \
1683 RTE_BUILD_BUG_ON(_action >= sizeof(_set) * CHAR_BIT)
1685 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1686 switch (actions->type) {
1687 case RTE_FLOW_ACTION_TYPE_VOID:
1688 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VOID,
1692 case RTE_FLOW_ACTION_TYPE_QUEUE:
1693 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_QUEUE,
1695 if ((actions_set & fate_actions_mask) != 0)
1696 goto fail_fate_actions;
1698 rc = sfc_flow_parse_queue(sa, actions->conf, flow);
1700 rte_flow_error_set(error, EINVAL,
1701 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1702 "Bad QUEUE action");
1707 case RTE_FLOW_ACTION_TYPE_RSS:
1708 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_RSS,
1710 if ((actions_set & fate_actions_mask) != 0)
1711 goto fail_fate_actions;
1713 rc = sfc_flow_parse_rss(sa, actions->conf, flow);
1715 rte_flow_error_set(error, -rc,
1716 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1722 case RTE_FLOW_ACTION_TYPE_DROP:
1723 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_DROP,
1725 if ((actions_set & fate_actions_mask) != 0)
1726 goto fail_fate_actions;
1728 spec_filter->template.efs_dmaq_id =
1729 EFX_FILTER_SPEC_RX_DMAQ_ID_DROP;
1732 case RTE_FLOW_ACTION_TYPE_FLAG:
1733 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_FLAG,
1735 if ((actions_set & mark_actions_mask) != 0)
1736 goto fail_actions_overlap;
1738 if ((dp_rx_features & SFC_DP_RX_FEAT_FLOW_FLAG) == 0) {
1739 rte_flow_error_set(error, ENOTSUP,
1740 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1741 "FLAG action is not supported on the current Rx datapath");
1745 spec_filter->template.efs_flags |=
1746 EFX_FILTER_FLAG_ACTION_FLAG;
1749 case RTE_FLOW_ACTION_TYPE_MARK:
1750 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_MARK,
1752 if ((actions_set & mark_actions_mask) != 0)
1753 goto fail_actions_overlap;
1755 if ((dp_rx_features & SFC_DP_RX_FEAT_FLOW_MARK) == 0) {
1756 rte_flow_error_set(error, ENOTSUP,
1757 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1758 "MARK action is not supported on the current Rx datapath");
1762 rc = sfc_flow_parse_mark(sa, actions->conf, flow);
1764 rte_flow_error_set(error, rc,
1765 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1772 rte_flow_error_set(error, ENOTSUP,
1773 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1774 "Action is not supported");
1778 actions_set |= (1UL << actions->type);
1780 #undef SFC_BUILD_SET_OVERFLOW
1782 /* When fate is unknown, drop traffic. */
1783 if ((actions_set & fate_actions_mask) == 0) {
1784 spec_filter->template.efs_dmaq_id =
1785 EFX_FILTER_SPEC_RX_DMAQ_ID_DROP;
1791 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, actions,
1792 "Cannot combine several fate-deciding actions, "
1793 "choose between QUEUE, RSS or DROP");
1796 fail_actions_overlap:
1797 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, actions,
1798 "Overlapping actions are not supported");
1803 * Set the EFX_FILTER_MATCH_UNKNOWN_UCAST_DST
1804 * and EFX_FILTER_MATCH_UNKNOWN_MCAST_DST match flags in the same
1805 * specifications after copying.
1807 * @param spec[in, out]
1808 * SFC flow specification to update.
1809 * @param filters_count_for_one_val[in]
1810 * How many specifications should have the same match flag, what is the
1811 * number of specifications before copying.
1813 * Perform verbose error reporting if not NULL.
1816 sfc_flow_set_unknown_dst_flags(struct sfc_flow_spec *spec,
1817 unsigned int filters_count_for_one_val,
1818 struct rte_flow_error *error)
1821 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1822 static const efx_filter_match_flags_t vals[] = {
1823 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST,
1824 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST
1827 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
1828 rte_flow_error_set(error, EINVAL,
1829 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1830 "Number of specifications is incorrect while copying "
1831 "by unknown destination flags");
1835 for (i = 0; i < spec_filter->count; i++) {
1836 /* The check above ensures that divisor can't be zero here */
1837 spec_filter->filters[i].efs_match_flags |=
1838 vals[i / filters_count_for_one_val];
1845 * Check that the following conditions are met:
1846 * - the list of supported filters has a filter
1847 * with EFX_FILTER_MATCH_UNKNOWN_MCAST_DST flag instead of
1848 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST, since this filter will also
1852 * The match flags of filter.
1854 * Specification to be supplemented.
1856 * SFC filter with list of supported filters.
1859 sfc_flow_check_unknown_dst_flags(efx_filter_match_flags_t match,
1860 __rte_unused efx_filter_spec_t *spec,
1861 struct sfc_filter *filter)
1864 efx_filter_match_flags_t match_mcast_dst;
1867 (match & ~EFX_FILTER_MATCH_UNKNOWN_UCAST_DST) |
1868 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST;
1869 for (i = 0; i < filter->supported_match_num; i++) {
1870 if (match_mcast_dst == filter->supported_match[i])
1878 * Set the EFX_FILTER_MATCH_ETHER_TYPE match flag and EFX_ETHER_TYPE_IPV4 and
1879 * EFX_ETHER_TYPE_IPV6 values of the corresponding field in the same
1880 * specifications after copying.
1882 * @param spec[in, out]
1883 * SFC flow specification to update.
1884 * @param filters_count_for_one_val[in]
1885 * How many specifications should have the same EtherType value, what is the
1886 * number of specifications before copying.
1888 * Perform verbose error reporting if not NULL.
1891 sfc_flow_set_ethertypes(struct sfc_flow_spec *spec,
1892 unsigned int filters_count_for_one_val,
1893 struct rte_flow_error *error)
1896 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1897 static const uint16_t vals[] = {
1898 EFX_ETHER_TYPE_IPV4, EFX_ETHER_TYPE_IPV6
1901 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
1902 rte_flow_error_set(error, EINVAL,
1903 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1904 "Number of specifications is incorrect "
1905 "while copying by Ethertype");
1909 for (i = 0; i < spec_filter->count; i++) {
1910 spec_filter->filters[i].efs_match_flags |=
1911 EFX_FILTER_MATCH_ETHER_TYPE;
1914 * The check above ensures that
1915 * filters_count_for_one_val is not 0
1917 spec_filter->filters[i].efs_ether_type =
1918 vals[i / filters_count_for_one_val];
1925 * Set the EFX_FILTER_MATCH_OUTER_VID match flag with value 0
1926 * in the same specifications after copying.
1928 * @param spec[in, out]
1929 * SFC flow specification to update.
1930 * @param filters_count_for_one_val[in]
1931 * How many specifications should have the same match flag, what is the
1932 * number of specifications before copying.
1934 * Perform verbose error reporting if not NULL.
1937 sfc_flow_set_outer_vid_flag(struct sfc_flow_spec *spec,
1938 unsigned int filters_count_for_one_val,
1939 struct rte_flow_error *error)
1941 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1944 if (filters_count_for_one_val != spec_filter->count) {
1945 rte_flow_error_set(error, EINVAL,
1946 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1947 "Number of specifications is incorrect "
1948 "while copying by outer VLAN ID");
1952 for (i = 0; i < spec_filter->count; i++) {
1953 spec_filter->filters[i].efs_match_flags |=
1954 EFX_FILTER_MATCH_OUTER_VID;
1956 spec_filter->filters[i].efs_outer_vid = 0;
1963 * Set the EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST and
1964 * EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST match flags in the same
1965 * specifications after copying.
1967 * @param spec[in, out]
1968 * SFC flow specification to update.
1969 * @param filters_count_for_one_val[in]
1970 * How many specifications should have the same match flag, what is the
1971 * number of specifications before copying.
1973 * Perform verbose error reporting if not NULL.
1976 sfc_flow_set_ifrm_unknown_dst_flags(struct sfc_flow_spec *spec,
1977 unsigned int filters_count_for_one_val,
1978 struct rte_flow_error *error)
1981 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1982 static const efx_filter_match_flags_t vals[] = {
1983 EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST,
1984 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST
1987 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
1988 rte_flow_error_set(error, EINVAL,
1989 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1990 "Number of specifications is incorrect while copying "
1991 "by inner frame unknown destination flags");
1995 for (i = 0; i < spec_filter->count; i++) {
1996 /* The check above ensures that divisor can't be zero here */
1997 spec_filter->filters[i].efs_match_flags |=
1998 vals[i / filters_count_for_one_val];
2005 * Check that the following conditions are met:
2006 * - the specification corresponds to a filter for encapsulated traffic
2007 * - the list of supported filters has a filter
2008 * with EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST flag instead of
2009 * EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST, since this filter will also
2013 * The match flags of filter.
2015 * Specification to be supplemented.
2017 * SFC filter with list of supported filters.
2020 sfc_flow_check_ifrm_unknown_dst_flags(efx_filter_match_flags_t match,
2021 efx_filter_spec_t *spec,
2022 struct sfc_filter *filter)
2025 efx_tunnel_protocol_t encap_type = spec->efs_encap_type;
2026 efx_filter_match_flags_t match_mcast_dst;
2028 if (encap_type == EFX_TUNNEL_PROTOCOL_NONE)
2032 (match & ~EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST) |
2033 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST;
2034 for (i = 0; i < filter->supported_match_num; i++) {
2035 if (match_mcast_dst == filter->supported_match[i])
2043 * Check that the list of supported filters has a filter that differs
2044 * from @p match in that it has no flag EFX_FILTER_MATCH_OUTER_VID
2045 * in this case that filter will be used and the flag
2046 * EFX_FILTER_MATCH_OUTER_VID is not needed.
2049 * The match flags of filter.
2051 * Specification to be supplemented.
2053 * SFC filter with list of supported filters.
2056 sfc_flow_check_outer_vid_flag(efx_filter_match_flags_t match,
2057 __rte_unused efx_filter_spec_t *spec,
2058 struct sfc_filter *filter)
2061 efx_filter_match_flags_t match_without_vid =
2062 match & ~EFX_FILTER_MATCH_OUTER_VID;
2064 for (i = 0; i < filter->supported_match_num; i++) {
2065 if (match_without_vid == filter->supported_match[i])
2073 * Match flags that can be automatically added to filters.
2074 * Selecting the last minimum when searching for the copy flag ensures that the
2075 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST flag has a higher priority than
2076 * EFX_FILTER_MATCH_ETHER_TYPE. This is because the filter
2077 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST is at the end of the list of supported
2080 static const struct sfc_flow_copy_flag sfc_flow_copy_flags[] = {
2082 .flag = EFX_FILTER_MATCH_UNKNOWN_UCAST_DST,
2084 .set_vals = sfc_flow_set_unknown_dst_flags,
2085 .spec_check = sfc_flow_check_unknown_dst_flags,
2088 .flag = EFX_FILTER_MATCH_ETHER_TYPE,
2090 .set_vals = sfc_flow_set_ethertypes,
2094 .flag = EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST,
2096 .set_vals = sfc_flow_set_ifrm_unknown_dst_flags,
2097 .spec_check = sfc_flow_check_ifrm_unknown_dst_flags,
2100 .flag = EFX_FILTER_MATCH_OUTER_VID,
2102 .set_vals = sfc_flow_set_outer_vid_flag,
2103 .spec_check = sfc_flow_check_outer_vid_flag,
2107 /* Get item from array sfc_flow_copy_flags */
2108 static const struct sfc_flow_copy_flag *
2109 sfc_flow_get_copy_flag(efx_filter_match_flags_t flag)
2113 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
2114 if (sfc_flow_copy_flags[i].flag == flag)
2115 return &sfc_flow_copy_flags[i];
2122 * Make copies of the specifications, set match flag and values
2123 * of the field that corresponds to it.
2125 * @param spec[in, out]
2126 * SFC flow specification to update.
2128 * The match flag to add.
2130 * Perform verbose error reporting if not NULL.
2133 sfc_flow_spec_add_match_flag(struct sfc_flow_spec *spec,
2134 efx_filter_match_flags_t flag,
2135 struct rte_flow_error *error)
2138 unsigned int new_filters_count;
2139 unsigned int filters_count_for_one_val;
2140 const struct sfc_flow_copy_flag *copy_flag;
2141 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2144 copy_flag = sfc_flow_get_copy_flag(flag);
2145 if (copy_flag == NULL) {
2146 rte_flow_error_set(error, ENOTSUP,
2147 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2148 "Unsupported spec field for copying");
2152 new_filters_count = spec_filter->count * copy_flag->vals_count;
2153 if (new_filters_count > SF_FLOW_SPEC_NB_FILTERS_MAX) {
2154 rte_flow_error_set(error, EINVAL,
2155 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2156 "Too much EFX specifications in the flow rule");
2160 /* Copy filters specifications */
2161 for (i = spec_filter->count; i < new_filters_count; i++) {
2162 spec_filter->filters[i] =
2163 spec_filter->filters[i - spec_filter->count];
2166 filters_count_for_one_val = spec_filter->count;
2167 spec_filter->count = new_filters_count;
2169 rc = copy_flag->set_vals(spec, filters_count_for_one_val, error);
2177 * Check that the given set of match flags missing in the original filter spec
2178 * could be covered by adding spec copies which specify the corresponding
2179 * flags and packet field values to match.
2181 * @param miss_flags[in]
2182 * Flags that are missing until the supported filter.
2184 * Specification to be supplemented.
2189 * Number of specifications after copy or 0, if the flags can not be added.
2192 sfc_flow_check_missing_flags(efx_filter_match_flags_t miss_flags,
2193 efx_filter_spec_t *spec,
2194 struct sfc_filter *filter)
2197 efx_filter_match_flags_t copy_flags = 0;
2198 efx_filter_match_flags_t flag;
2199 efx_filter_match_flags_t match = spec->efs_match_flags | miss_flags;
2200 sfc_flow_spec_check *check;
2201 unsigned int multiplier = 1;
2203 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
2204 flag = sfc_flow_copy_flags[i].flag;
2205 check = sfc_flow_copy_flags[i].spec_check;
2206 if ((flag & miss_flags) == flag) {
2207 if (check != NULL && (!check(match, spec, filter)))
2211 multiplier *= sfc_flow_copy_flags[i].vals_count;
2215 if (copy_flags == miss_flags)
2222 * Attempt to supplement the specification template to the minimally
2223 * supported set of match flags. To do this, it is necessary to copy
2224 * the specifications, filling them with the values of fields that
2225 * correspond to the missing flags.
2226 * The necessary and sufficient filter is built from the fewest number
2227 * of copies which could be made to cover the minimally required set
2232 * @param spec[in, out]
2233 * SFC flow specification to update.
2235 * Perform verbose error reporting if not NULL.
2238 sfc_flow_spec_filters_complete(struct sfc_adapter *sa,
2239 struct sfc_flow_spec *spec,
2240 struct rte_flow_error *error)
2242 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2243 struct sfc_filter *filter = &sa->filter;
2244 efx_filter_match_flags_t miss_flags;
2245 efx_filter_match_flags_t min_miss_flags = 0;
2246 efx_filter_match_flags_t match;
2247 unsigned int min_multiplier = UINT_MAX;
2248 unsigned int multiplier;
2252 match = spec_filter->template.efs_match_flags;
2253 for (i = 0; i < filter->supported_match_num; i++) {
2254 if ((match & filter->supported_match[i]) == match) {
2255 miss_flags = filter->supported_match[i] & (~match);
2256 multiplier = sfc_flow_check_missing_flags(miss_flags,
2257 &spec_filter->template, filter);
2258 if (multiplier > 0) {
2259 if (multiplier <= min_multiplier) {
2260 min_multiplier = multiplier;
2261 min_miss_flags = miss_flags;
2267 if (min_multiplier == UINT_MAX) {
2268 rte_flow_error_set(error, ENOTSUP,
2269 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2270 "The flow rule pattern is unsupported");
2274 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
2275 efx_filter_match_flags_t flag = sfc_flow_copy_flags[i].flag;
2277 if ((flag & min_miss_flags) == flag) {
2278 rc = sfc_flow_spec_add_match_flag(spec, flag, error);
2288 * Check that set of match flags is referred to by a filter. Filter is
2289 * described by match flags with the ability to add OUTER_VID and INNER_VID
2292 * @param match_flags[in]
2293 * Set of match flags.
2294 * @param flags_pattern[in]
2295 * Pattern of filter match flags.
2298 sfc_flow_is_match_with_vids(efx_filter_match_flags_t match_flags,
2299 efx_filter_match_flags_t flags_pattern)
2301 if ((match_flags & flags_pattern) != flags_pattern)
2304 switch (match_flags & ~flags_pattern) {
2306 case EFX_FILTER_MATCH_OUTER_VID:
2307 case EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_INNER_VID:
2315 * Check whether the spec maps to a hardware filter which is known to be
2316 * ineffective despite being valid.
2319 * SFC filter with list of supported filters.
2321 * SFC flow specification.
2324 sfc_flow_is_match_flags_exception(struct sfc_filter *filter,
2325 struct sfc_flow_spec *spec)
2328 uint16_t ether_type;
2330 efx_filter_match_flags_t match_flags;
2331 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2333 for (i = 0; i < spec_filter->count; i++) {
2334 match_flags = spec_filter->filters[i].efs_match_flags;
2336 if (sfc_flow_is_match_with_vids(match_flags,
2337 EFX_FILTER_MATCH_ETHER_TYPE) ||
2338 sfc_flow_is_match_with_vids(match_flags,
2339 EFX_FILTER_MATCH_ETHER_TYPE |
2340 EFX_FILTER_MATCH_LOC_MAC)) {
2341 ether_type = spec_filter->filters[i].efs_ether_type;
2342 if (filter->supports_ip_proto_or_addr_filter &&
2343 (ether_type == EFX_ETHER_TYPE_IPV4 ||
2344 ether_type == EFX_ETHER_TYPE_IPV6))
2346 } else if (sfc_flow_is_match_with_vids(match_flags,
2347 EFX_FILTER_MATCH_ETHER_TYPE |
2348 EFX_FILTER_MATCH_IP_PROTO) ||
2349 sfc_flow_is_match_with_vids(match_flags,
2350 EFX_FILTER_MATCH_ETHER_TYPE |
2351 EFX_FILTER_MATCH_IP_PROTO |
2352 EFX_FILTER_MATCH_LOC_MAC)) {
2353 ip_proto = spec_filter->filters[i].efs_ip_proto;
2354 if (filter->supports_rem_or_local_port_filter &&
2355 (ip_proto == EFX_IPPROTO_TCP ||
2356 ip_proto == EFX_IPPROTO_UDP))
2365 sfc_flow_validate_match_flags(struct sfc_adapter *sa,
2366 struct rte_flow *flow,
2367 struct rte_flow_error *error)
2369 struct sfc_flow_spec *spec = &flow->spec;
2370 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2371 efx_filter_spec_t *spec_tmpl = &spec_filter->template;
2372 efx_filter_match_flags_t match_flags = spec_tmpl->efs_match_flags;
2375 /* Initialize the first filter spec with template */
2376 spec_filter->filters[0] = *spec_tmpl;
2377 spec_filter->count = 1;
2379 if (!sfc_filter_is_match_supported(sa, match_flags)) {
2380 rc = sfc_flow_spec_filters_complete(sa, &flow->spec, error);
2385 if (sfc_flow_is_match_flags_exception(&sa->filter, &flow->spec)) {
2386 rte_flow_error_set(error, ENOTSUP,
2387 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2388 "The flow rule pattern is unsupported");
2396 sfc_flow_parse_rte_to_filter(struct rte_eth_dev *dev,
2397 const struct rte_flow_item pattern[],
2398 const struct rte_flow_action actions[],
2399 struct rte_flow *flow,
2400 struct rte_flow_error *error)
2402 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2403 struct sfc_flow_spec *spec = &flow->spec;
2404 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2405 struct sfc_flow_parse_ctx ctx;
2408 ctx.type = SFC_FLOW_PARSE_CTX_FILTER;
2409 ctx.filter = &spec_filter->template;
2411 rc = sfc_flow_parse_pattern(sfc_flow_items, RTE_DIM(sfc_flow_items),
2412 pattern, &ctx, error);
2414 goto fail_bad_value;
2416 rc = sfc_flow_parse_actions(sa, actions, flow, error);
2418 goto fail_bad_value;
2420 rc = sfc_flow_validate_match_flags(sa, flow, error);
2422 goto fail_bad_value;
2431 sfc_flow_parse_rte_to_mae(struct rte_eth_dev *dev,
2432 const struct rte_flow_item pattern[],
2433 const struct rte_flow_action actions[],
2434 struct rte_flow *flow,
2435 struct rte_flow_error *error)
2437 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2438 struct sfc_flow_spec *spec = &flow->spec;
2439 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
2442 rc = sfc_mae_rule_parse_pattern(sa, pattern, spec_mae, error);
2446 rc = sfc_mae_rule_parse_actions(sa, actions, &spec_mae->action_set,
2455 sfc_flow_parse(struct rte_eth_dev *dev,
2456 const struct rte_flow_attr *attr,
2457 const struct rte_flow_item pattern[],
2458 const struct rte_flow_action actions[],
2459 struct rte_flow *flow,
2460 struct rte_flow_error *error)
2462 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2463 const struct sfc_flow_ops_by_spec *ops;
2466 rc = sfc_flow_parse_attr(sa, attr, flow, error);
2470 ops = sfc_flow_get_ops_by_spec(flow);
2471 if (ops == NULL || ops->parse == NULL) {
2472 rte_flow_error_set(error, ENOTSUP,
2473 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2474 "No backend to handle this flow");
2478 return ops->parse(dev, pattern, actions, flow, error);
2481 static struct rte_flow *
2482 sfc_flow_zmalloc(struct rte_flow_error *error)
2484 struct rte_flow *flow;
2486 flow = rte_zmalloc("sfc_rte_flow", sizeof(*flow), 0);
2488 rte_flow_error_set(error, ENOMEM,
2489 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2490 "Failed to allocate memory");
2497 sfc_flow_free(struct sfc_adapter *sa, struct rte_flow *flow)
2499 const struct sfc_flow_ops_by_spec *ops;
2501 ops = sfc_flow_get_ops_by_spec(flow);
2502 if (ops != NULL && ops->cleanup != NULL)
2503 ops->cleanup(sa, flow);
2509 sfc_flow_insert(struct sfc_adapter *sa, struct rte_flow *flow,
2510 struct rte_flow_error *error)
2512 const struct sfc_flow_ops_by_spec *ops;
2515 ops = sfc_flow_get_ops_by_spec(flow);
2516 if (ops == NULL || ops->insert == NULL) {
2517 rte_flow_error_set(error, ENOTSUP,
2518 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2519 "No backend to handle this flow");
2523 rc = ops->insert(sa, flow);
2525 rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2526 NULL, "Failed to insert the flow rule");
2533 sfc_flow_remove(struct sfc_adapter *sa, struct rte_flow *flow,
2534 struct rte_flow_error *error)
2536 const struct sfc_flow_ops_by_spec *ops;
2539 ops = sfc_flow_get_ops_by_spec(flow);
2540 if (ops == NULL || ops->remove == NULL) {
2541 rte_flow_error_set(error, ENOTSUP,
2542 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2543 "No backend to handle this flow");
2547 rc = ops->remove(sa, flow);
2549 rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2550 NULL, "Failed to remove the flow rule");
2557 sfc_flow_verify(struct sfc_adapter *sa, struct rte_flow *flow,
2558 struct rte_flow_error *error)
2560 const struct sfc_flow_ops_by_spec *ops;
2563 ops = sfc_flow_get_ops_by_spec(flow);
2565 rte_flow_error_set(error, ENOTSUP,
2566 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2567 "No backend to handle this flow");
2571 if (ops->verify != NULL) {
2573 * Use locking since verify method may need to
2574 * access the list of already created rules.
2576 sfc_adapter_lock(sa);
2577 rc = ops->verify(sa, flow);
2578 sfc_adapter_unlock(sa);
2582 rte_flow_error_set(error, rc,
2583 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2584 "Failed to verify flow validity with FW");
2592 sfc_flow_validate(struct rte_eth_dev *dev,
2593 const struct rte_flow_attr *attr,
2594 const struct rte_flow_item pattern[],
2595 const struct rte_flow_action actions[],
2596 struct rte_flow_error *error)
2598 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2599 struct rte_flow *flow;
2602 flow = sfc_flow_zmalloc(error);
2606 rc = sfc_flow_parse(dev, attr, pattern, actions, flow, error);
2608 rc = sfc_flow_verify(sa, flow, error);
2610 sfc_flow_free(sa, flow);
2615 static struct rte_flow *
2616 sfc_flow_create(struct rte_eth_dev *dev,
2617 const struct rte_flow_attr *attr,
2618 const struct rte_flow_item pattern[],
2619 const struct rte_flow_action actions[],
2620 struct rte_flow_error *error)
2622 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2623 struct rte_flow *flow = NULL;
2626 flow = sfc_flow_zmalloc(error);
2630 rc = sfc_flow_parse(dev, attr, pattern, actions, flow, error);
2632 goto fail_bad_value;
2634 sfc_adapter_lock(sa);
2636 TAILQ_INSERT_TAIL(&sa->flow_list, flow, entries);
2638 if (sa->state == SFC_ADAPTER_STARTED) {
2639 rc = sfc_flow_insert(sa, flow, error);
2641 goto fail_flow_insert;
2644 sfc_adapter_unlock(sa);
2649 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2652 sfc_flow_free(sa, flow);
2653 sfc_adapter_unlock(sa);
2660 sfc_flow_destroy(struct rte_eth_dev *dev,
2661 struct rte_flow *flow,
2662 struct rte_flow_error *error)
2664 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2665 struct rte_flow *flow_ptr;
2668 sfc_adapter_lock(sa);
2670 TAILQ_FOREACH(flow_ptr, &sa->flow_list, entries) {
2671 if (flow_ptr == flow)
2675 rte_flow_error_set(error, rc,
2676 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
2677 "Failed to find flow rule to destroy");
2678 goto fail_bad_value;
2681 if (sa->state == SFC_ADAPTER_STARTED)
2682 rc = sfc_flow_remove(sa, flow, error);
2684 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2685 sfc_flow_free(sa, flow);
2688 sfc_adapter_unlock(sa);
2694 sfc_flow_flush(struct rte_eth_dev *dev,
2695 struct rte_flow_error *error)
2697 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2698 struct rte_flow *flow;
2701 sfc_adapter_lock(sa);
2703 while ((flow = TAILQ_FIRST(&sa->flow_list)) != NULL) {
2704 if (sa->state == SFC_ADAPTER_STARTED) {
2707 rc = sfc_flow_remove(sa, flow, error);
2712 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2713 sfc_flow_free(sa, flow);
2716 sfc_adapter_unlock(sa);
2722 sfc_flow_isolate(struct rte_eth_dev *dev, int enable,
2723 struct rte_flow_error *error)
2725 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2728 sfc_adapter_lock(sa);
2729 if (sa->state != SFC_ADAPTER_INITIALIZED) {
2730 rte_flow_error_set(error, EBUSY,
2731 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2732 NULL, "please close the port first");
2735 sfc_sa2shared(sa)->isolated = (enable) ? B_TRUE : B_FALSE;
2737 sfc_adapter_unlock(sa);
2742 const struct rte_flow_ops sfc_flow_ops = {
2743 .validate = sfc_flow_validate,
2744 .create = sfc_flow_create,
2745 .destroy = sfc_flow_destroy,
2746 .flush = sfc_flow_flush,
2748 .isolate = sfc_flow_isolate,
2752 sfc_flow_init(struct sfc_adapter *sa)
2754 SFC_ASSERT(sfc_adapter_is_locked(sa));
2756 TAILQ_INIT(&sa->flow_list);
2760 sfc_flow_fini(struct sfc_adapter *sa)
2762 struct rte_flow *flow;
2764 SFC_ASSERT(sfc_adapter_is_locked(sa));
2766 while ((flow = TAILQ_FIRST(&sa->flow_list)) != NULL) {
2767 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2768 sfc_flow_free(sa, flow);
2773 sfc_flow_stop(struct sfc_adapter *sa)
2775 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
2776 struct sfc_rss *rss = &sas->rss;
2777 struct rte_flow *flow;
2779 SFC_ASSERT(sfc_adapter_is_locked(sa));
2781 TAILQ_FOREACH(flow, &sa->flow_list, entries)
2782 sfc_flow_remove(sa, flow, NULL);
2784 if (rss->dummy_rss_context != EFX_RSS_CONTEXT_DEFAULT) {
2785 efx_rx_scale_context_free(sa->nic, rss->dummy_rss_context);
2786 rss->dummy_rss_context = EFX_RSS_CONTEXT_DEFAULT;
2791 sfc_flow_start(struct sfc_adapter *sa)
2793 struct rte_flow *flow;
2796 sfc_log_init(sa, "entry");
2798 SFC_ASSERT(sfc_adapter_is_locked(sa));
2800 TAILQ_FOREACH(flow, &sa->flow_list, entries) {
2801 rc = sfc_flow_insert(sa, flow, NULL);
2806 sfc_log_init(sa, "done");