1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2019-2021 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 <ethdev_driver.h>
14 #include <rte_ether.h>
16 #include <rte_flow_driver.h>
21 #include "sfc_debug.h"
23 #include "sfc_filter.h"
25 #include "sfc_flow_tunnel.h"
27 #include "sfc_dp_rx.h"
28 #include "sfc_mae_counter.h"
30 struct sfc_flow_ops_by_spec {
31 sfc_flow_parse_cb_t *parse;
32 sfc_flow_verify_cb_t *verify;
33 sfc_flow_cleanup_cb_t *cleanup;
34 sfc_flow_insert_cb_t *insert;
35 sfc_flow_remove_cb_t *remove;
36 sfc_flow_query_cb_t *query;
39 static sfc_flow_parse_cb_t sfc_flow_parse_rte_to_filter;
40 static sfc_flow_parse_cb_t sfc_flow_parse_rte_to_mae;
41 static sfc_flow_insert_cb_t sfc_flow_filter_insert;
42 static sfc_flow_remove_cb_t sfc_flow_filter_remove;
44 static const struct sfc_flow_ops_by_spec sfc_flow_ops_filter = {
45 .parse = sfc_flow_parse_rte_to_filter,
48 .insert = sfc_flow_filter_insert,
49 .remove = sfc_flow_filter_remove,
53 static const struct sfc_flow_ops_by_spec sfc_flow_ops_mae = {
54 .parse = sfc_flow_parse_rte_to_mae,
55 .verify = sfc_mae_flow_verify,
56 .cleanup = sfc_mae_flow_cleanup,
57 .insert = sfc_mae_flow_insert,
58 .remove = sfc_mae_flow_remove,
59 .query = sfc_mae_flow_query,
62 static const struct sfc_flow_ops_by_spec *
63 sfc_flow_get_ops_by_spec(struct rte_flow *flow)
65 struct sfc_flow_spec *spec = &flow->spec;
66 const struct sfc_flow_ops_by_spec *ops = NULL;
69 case SFC_FLOW_SPEC_FILTER:
70 ops = &sfc_flow_ops_filter;
72 case SFC_FLOW_SPEC_MAE:
73 ops = &sfc_flow_ops_mae;
84 * Currently, filter-based (VNIC) flow API is implemented in such a manner
85 * that each flow rule is converted to one or more hardware filters.
86 * All elements of flow rule (attributes, pattern items, actions)
87 * correspond to one or more fields in the efx_filter_spec_s structure
88 * that is responsible for the hardware filter.
89 * If some required field is unset in the flow rule, then a handful
90 * of filter copies will be created to cover all possible values
94 static sfc_flow_item_parse sfc_flow_parse_void;
95 static sfc_flow_item_parse sfc_flow_parse_eth;
96 static sfc_flow_item_parse sfc_flow_parse_vlan;
97 static sfc_flow_item_parse sfc_flow_parse_ipv4;
98 static sfc_flow_item_parse sfc_flow_parse_ipv6;
99 static sfc_flow_item_parse sfc_flow_parse_tcp;
100 static sfc_flow_item_parse sfc_flow_parse_udp;
101 static sfc_flow_item_parse sfc_flow_parse_vxlan;
102 static sfc_flow_item_parse sfc_flow_parse_geneve;
103 static sfc_flow_item_parse sfc_flow_parse_nvgre;
104 static sfc_flow_item_parse sfc_flow_parse_pppoex;
106 typedef int (sfc_flow_spec_set_vals)(struct sfc_flow_spec *spec,
107 unsigned int filters_count_for_one_val,
108 struct rte_flow_error *error);
110 typedef boolean_t (sfc_flow_spec_check)(efx_filter_match_flags_t match,
111 efx_filter_spec_t *spec,
112 struct sfc_filter *filter);
114 struct sfc_flow_copy_flag {
115 /* EFX filter specification match flag */
116 efx_filter_match_flags_t flag;
117 /* Number of values of corresponding field */
118 unsigned int vals_count;
119 /* Function to set values in specifications */
120 sfc_flow_spec_set_vals *set_vals;
122 * Function to check that the specification is suitable
123 * for adding this match flag
125 sfc_flow_spec_check *spec_check;
128 static sfc_flow_spec_set_vals sfc_flow_set_unknown_dst_flags;
129 static sfc_flow_spec_check sfc_flow_check_unknown_dst_flags;
130 static sfc_flow_spec_set_vals sfc_flow_set_ethertypes;
131 static sfc_flow_spec_set_vals sfc_flow_set_ifrm_unknown_dst_flags;
132 static sfc_flow_spec_check sfc_flow_check_ifrm_unknown_dst_flags;
133 static sfc_flow_spec_set_vals sfc_flow_set_outer_vid_flag;
134 static sfc_flow_spec_check sfc_flow_check_outer_vid_flag;
137 sfc_flow_is_zero(const uint8_t *buf, unsigned int size)
142 for (i = 0; i < size; i++)
145 return (sum == 0) ? B_TRUE : B_FALSE;
149 * Validate item and prepare structures spec and mask for parsing
152 sfc_flow_parse_init(const struct rte_flow_item *item,
153 const void **spec_ptr,
154 const void **mask_ptr,
155 const void *supp_mask,
156 const void *def_mask,
158 struct rte_flow_error *error)
167 rte_flow_error_set(error, EINVAL,
168 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
173 if ((item->last != NULL || item->mask != NULL) && item->spec == NULL) {
174 rte_flow_error_set(error, EINVAL,
175 RTE_FLOW_ERROR_TYPE_ITEM, item,
176 "Mask or last is set without spec");
181 * If "mask" is not set, default mask is used,
182 * but if default mask is NULL, "mask" should be set
184 if (item->mask == NULL) {
185 if (def_mask == NULL) {
186 rte_flow_error_set(error, EINVAL,
187 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
188 "Mask should be specified");
204 * If field values in "last" are either 0 or equal to the corresponding
205 * values in "spec" then they are ignored
208 !sfc_flow_is_zero(last, size) &&
209 memcmp(last, spec, size) != 0) {
210 rte_flow_error_set(error, ENOTSUP,
211 RTE_FLOW_ERROR_TYPE_ITEM, item,
212 "Ranging is not supported");
216 if (supp_mask == NULL) {
217 rte_flow_error_set(error, EINVAL,
218 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
219 "Supported mask for item should be specified");
223 /* Check that mask does not ask for more match than supp_mask */
224 for (i = 0; i < size; i++) {
225 supp = ((const uint8_t *)supp_mask)[i];
227 if (~supp & mask[i]) {
228 rte_flow_error_set(error, ENOTSUP,
229 RTE_FLOW_ERROR_TYPE_ITEM, item,
230 "Item's field is not supported");
243 * Masking is not supported, so masks in items should be either
244 * full or empty (zeroed) and set only for supported fields which
245 * are specified in the supp_mask.
249 sfc_flow_parse_void(__rte_unused const struct rte_flow_item *item,
250 __rte_unused struct sfc_flow_parse_ctx *parse_ctx,
251 __rte_unused struct rte_flow_error *error)
257 * Convert Ethernet item to EFX filter specification.
260 * Item specification. Outer frame specification may only comprise
261 * source/destination addresses and Ethertype field.
262 * Inner frame specification may contain destination address only.
263 * There is support for individual/group mask as well as for empty and full.
264 * If the mask is NULL, default mask will be used. Ranging is not supported.
265 * @param efx_spec[in, out]
266 * EFX filter specification to update.
268 * Perform verbose error reporting if not NULL.
271 sfc_flow_parse_eth(const struct rte_flow_item *item,
272 struct sfc_flow_parse_ctx *parse_ctx,
273 struct rte_flow_error *error)
276 efx_filter_spec_t *efx_spec = parse_ctx->filter;
277 const struct rte_flow_item_eth *spec = NULL;
278 const struct rte_flow_item_eth *mask = NULL;
279 const struct rte_flow_item_eth supp_mask = {
280 .dst.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
281 .src.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
284 const struct rte_flow_item_eth ifrm_supp_mask = {
285 .dst.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
287 const uint8_t ig_mask[EFX_MAC_ADDR_LEN] = {
288 0x01, 0x00, 0x00, 0x00, 0x00, 0x00
290 const struct rte_flow_item_eth *supp_mask_p;
291 const struct rte_flow_item_eth *def_mask_p;
292 uint8_t *loc_mac = NULL;
293 boolean_t is_ifrm = (efx_spec->efs_encap_type !=
294 EFX_TUNNEL_PROTOCOL_NONE);
297 supp_mask_p = &ifrm_supp_mask;
298 def_mask_p = &ifrm_supp_mask;
299 loc_mac = efx_spec->efs_ifrm_loc_mac;
301 supp_mask_p = &supp_mask;
302 def_mask_p = &rte_flow_item_eth_mask;
303 loc_mac = efx_spec->efs_loc_mac;
306 rc = sfc_flow_parse_init(item,
307 (const void **)&spec,
308 (const void **)&mask,
309 supp_mask_p, def_mask_p,
310 sizeof(struct rte_flow_item_eth),
315 /* If "spec" is not set, could be any Ethernet */
319 if (rte_is_same_ether_addr(&mask->dst, &supp_mask.dst)) {
320 efx_spec->efs_match_flags |= is_ifrm ?
321 EFX_FILTER_MATCH_IFRM_LOC_MAC :
322 EFX_FILTER_MATCH_LOC_MAC;
323 rte_memcpy(loc_mac, spec->dst.addr_bytes,
325 } else if (memcmp(mask->dst.addr_bytes, ig_mask,
326 EFX_MAC_ADDR_LEN) == 0) {
327 if (rte_is_unicast_ether_addr(&spec->dst))
328 efx_spec->efs_match_flags |= is_ifrm ?
329 EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST :
330 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST;
332 efx_spec->efs_match_flags |= is_ifrm ?
333 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST :
334 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST;
335 } else if (!rte_is_zero_ether_addr(&mask->dst)) {
340 * ifrm_supp_mask ensures that the source address and
341 * ethertype masks are equal to zero in inner frame,
342 * so these fields are filled in only for the outer frame
344 if (rte_is_same_ether_addr(&mask->src, &supp_mask.src)) {
345 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_MAC;
346 rte_memcpy(efx_spec->efs_rem_mac, spec->src.addr_bytes,
348 } else if (!rte_is_zero_ether_addr(&mask->src)) {
353 * Ether type is in big-endian byte order in item and
354 * in little-endian in efx_spec, so byte swap is used
356 if (mask->type == supp_mask.type) {
357 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
358 efx_spec->efs_ether_type = rte_bswap16(spec->type);
359 } else if (mask->type != 0) {
366 rte_flow_error_set(error, EINVAL,
367 RTE_FLOW_ERROR_TYPE_ITEM, item,
368 "Bad mask in the ETH pattern item");
373 * Convert VLAN item to EFX filter specification.
376 * Item specification. Only VID field is supported.
377 * The mask can not be NULL. Ranging is not supported.
378 * @param efx_spec[in, out]
379 * EFX filter specification to update.
381 * Perform verbose error reporting if not NULL.
384 sfc_flow_parse_vlan(const struct rte_flow_item *item,
385 struct sfc_flow_parse_ctx *parse_ctx,
386 struct rte_flow_error *error)
390 efx_filter_spec_t *efx_spec = parse_ctx->filter;
391 const struct rte_flow_item_vlan *spec = NULL;
392 const struct rte_flow_item_vlan *mask = NULL;
393 const struct rte_flow_item_vlan supp_mask = {
394 .tci = rte_cpu_to_be_16(ETH_VLAN_ID_MAX),
395 .inner_type = RTE_BE16(0xffff),
398 rc = sfc_flow_parse_init(item,
399 (const void **)&spec,
400 (const void **)&mask,
403 sizeof(struct rte_flow_item_vlan),
409 * VID is in big-endian byte order in item and
410 * in little-endian in efx_spec, so byte swap is used.
411 * If two VLAN items are included, the first matches
412 * the outer tag and the next matches the inner tag.
414 if (mask->tci == supp_mask.tci) {
415 /* Apply mask to keep VID only */
416 vid = rte_bswap16(spec->tci & mask->tci);
418 if (!(efx_spec->efs_match_flags &
419 EFX_FILTER_MATCH_OUTER_VID)) {
420 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_OUTER_VID;
421 efx_spec->efs_outer_vid = vid;
422 } else if (!(efx_spec->efs_match_flags &
423 EFX_FILTER_MATCH_INNER_VID)) {
424 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_INNER_VID;
425 efx_spec->efs_inner_vid = vid;
427 rte_flow_error_set(error, EINVAL,
428 RTE_FLOW_ERROR_TYPE_ITEM, item,
429 "More than two VLAN items");
433 rte_flow_error_set(error, EINVAL,
434 RTE_FLOW_ERROR_TYPE_ITEM, item,
435 "VLAN ID in TCI match is required");
439 if (efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE) {
440 rte_flow_error_set(error, EINVAL,
441 RTE_FLOW_ERROR_TYPE_ITEM, item,
442 "VLAN TPID matching is not supported");
445 if (mask->inner_type == supp_mask.inner_type) {
446 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
447 efx_spec->efs_ether_type = rte_bswap16(spec->inner_type);
448 } else if (mask->inner_type) {
449 rte_flow_error_set(error, EINVAL,
450 RTE_FLOW_ERROR_TYPE_ITEM, item,
451 "Bad mask for VLAN inner_type");
459 * Convert IPv4 item to EFX filter specification.
462 * Item specification. Only source and destination addresses and
463 * protocol fields are supported. If the mask is NULL, default
464 * mask will be used. Ranging is not supported.
465 * @param efx_spec[in, out]
466 * EFX filter specification to update.
468 * Perform verbose error reporting if not NULL.
471 sfc_flow_parse_ipv4(const struct rte_flow_item *item,
472 struct sfc_flow_parse_ctx *parse_ctx,
473 struct rte_flow_error *error)
476 efx_filter_spec_t *efx_spec = parse_ctx->filter;
477 const struct rte_flow_item_ipv4 *spec = NULL;
478 const struct rte_flow_item_ipv4 *mask = NULL;
479 const uint16_t ether_type_ipv4 = rte_cpu_to_le_16(EFX_ETHER_TYPE_IPV4);
480 const struct rte_flow_item_ipv4 supp_mask = {
482 .src_addr = 0xffffffff,
483 .dst_addr = 0xffffffff,
484 .next_proto_id = 0xff,
488 rc = sfc_flow_parse_init(item,
489 (const void **)&spec,
490 (const void **)&mask,
492 &rte_flow_item_ipv4_mask,
493 sizeof(struct rte_flow_item_ipv4),
499 * Filtering by IPv4 source and destination addresses requires
500 * the appropriate ETHER_TYPE in hardware filters
502 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE)) {
503 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
504 efx_spec->efs_ether_type = ether_type_ipv4;
505 } else if (efx_spec->efs_ether_type != ether_type_ipv4) {
506 rte_flow_error_set(error, EINVAL,
507 RTE_FLOW_ERROR_TYPE_ITEM, item,
508 "Ethertype in pattern with IPV4 item should be appropriate");
516 * IPv4 addresses are in big-endian byte order in item and in
519 if (mask->hdr.src_addr == supp_mask.hdr.src_addr) {
520 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_HOST;
521 efx_spec->efs_rem_host.eo_u32[0] = spec->hdr.src_addr;
522 } else if (mask->hdr.src_addr != 0) {
526 if (mask->hdr.dst_addr == supp_mask.hdr.dst_addr) {
527 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_HOST;
528 efx_spec->efs_loc_host.eo_u32[0] = spec->hdr.dst_addr;
529 } else if (mask->hdr.dst_addr != 0) {
533 if (mask->hdr.next_proto_id == supp_mask.hdr.next_proto_id) {
534 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
535 efx_spec->efs_ip_proto = spec->hdr.next_proto_id;
536 } else if (mask->hdr.next_proto_id != 0) {
543 rte_flow_error_set(error, EINVAL,
544 RTE_FLOW_ERROR_TYPE_ITEM, item,
545 "Bad mask in the IPV4 pattern item");
550 * Convert IPv6 item to EFX filter specification.
553 * Item specification. Only source and destination addresses and
554 * next header fields are supported. If the mask is NULL, default
555 * mask will be used. Ranging is not supported.
556 * @param efx_spec[in, out]
557 * EFX filter specification to update.
559 * Perform verbose error reporting if not NULL.
562 sfc_flow_parse_ipv6(const struct rte_flow_item *item,
563 struct sfc_flow_parse_ctx *parse_ctx,
564 struct rte_flow_error *error)
567 efx_filter_spec_t *efx_spec = parse_ctx->filter;
568 const struct rte_flow_item_ipv6 *spec = NULL;
569 const struct rte_flow_item_ipv6 *mask = NULL;
570 const uint16_t ether_type_ipv6 = rte_cpu_to_le_16(EFX_ETHER_TYPE_IPV6);
571 const struct rte_flow_item_ipv6 supp_mask = {
573 .src_addr = { 0xff, 0xff, 0xff, 0xff,
574 0xff, 0xff, 0xff, 0xff,
575 0xff, 0xff, 0xff, 0xff,
576 0xff, 0xff, 0xff, 0xff },
577 .dst_addr = { 0xff, 0xff, 0xff, 0xff,
578 0xff, 0xff, 0xff, 0xff,
579 0xff, 0xff, 0xff, 0xff,
580 0xff, 0xff, 0xff, 0xff },
585 rc = sfc_flow_parse_init(item,
586 (const void **)&spec,
587 (const void **)&mask,
589 &rte_flow_item_ipv6_mask,
590 sizeof(struct rte_flow_item_ipv6),
596 * Filtering by IPv6 source and destination addresses requires
597 * the appropriate ETHER_TYPE in hardware filters
599 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE)) {
600 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
601 efx_spec->efs_ether_type = ether_type_ipv6;
602 } else if (efx_spec->efs_ether_type != ether_type_ipv6) {
603 rte_flow_error_set(error, EINVAL,
604 RTE_FLOW_ERROR_TYPE_ITEM, item,
605 "Ethertype in pattern with IPV6 item should be appropriate");
613 * IPv6 addresses are in big-endian byte order in item and in
616 if (memcmp(mask->hdr.src_addr, supp_mask.hdr.src_addr,
617 sizeof(mask->hdr.src_addr)) == 0) {
618 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_HOST;
620 RTE_BUILD_BUG_ON(sizeof(efx_spec->efs_rem_host) !=
621 sizeof(spec->hdr.src_addr));
622 rte_memcpy(&efx_spec->efs_rem_host, spec->hdr.src_addr,
623 sizeof(efx_spec->efs_rem_host));
624 } else if (!sfc_flow_is_zero(mask->hdr.src_addr,
625 sizeof(mask->hdr.src_addr))) {
629 if (memcmp(mask->hdr.dst_addr, supp_mask.hdr.dst_addr,
630 sizeof(mask->hdr.dst_addr)) == 0) {
631 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_HOST;
633 RTE_BUILD_BUG_ON(sizeof(efx_spec->efs_loc_host) !=
634 sizeof(spec->hdr.dst_addr));
635 rte_memcpy(&efx_spec->efs_loc_host, spec->hdr.dst_addr,
636 sizeof(efx_spec->efs_loc_host));
637 } else if (!sfc_flow_is_zero(mask->hdr.dst_addr,
638 sizeof(mask->hdr.dst_addr))) {
642 if (mask->hdr.proto == supp_mask.hdr.proto) {
643 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
644 efx_spec->efs_ip_proto = spec->hdr.proto;
645 } else if (mask->hdr.proto != 0) {
652 rte_flow_error_set(error, EINVAL,
653 RTE_FLOW_ERROR_TYPE_ITEM, item,
654 "Bad mask in the IPV6 pattern item");
659 * Convert TCP item to EFX filter specification.
662 * Item specification. Only source and destination ports fields
663 * are supported. If the mask is NULL, default mask will be used.
664 * Ranging is not supported.
665 * @param efx_spec[in, out]
666 * EFX filter specification to update.
668 * Perform verbose error reporting if not NULL.
671 sfc_flow_parse_tcp(const struct rte_flow_item *item,
672 struct sfc_flow_parse_ctx *parse_ctx,
673 struct rte_flow_error *error)
676 efx_filter_spec_t *efx_spec = parse_ctx->filter;
677 const struct rte_flow_item_tcp *spec = NULL;
678 const struct rte_flow_item_tcp *mask = NULL;
679 const struct rte_flow_item_tcp supp_mask = {
686 rc = sfc_flow_parse_init(item,
687 (const void **)&spec,
688 (const void **)&mask,
690 &rte_flow_item_tcp_mask,
691 sizeof(struct rte_flow_item_tcp),
697 * Filtering by TCP source and destination ports requires
698 * the appropriate IP_PROTO in hardware filters
700 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_IP_PROTO)) {
701 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
702 efx_spec->efs_ip_proto = EFX_IPPROTO_TCP;
703 } else if (efx_spec->efs_ip_proto != EFX_IPPROTO_TCP) {
704 rte_flow_error_set(error, EINVAL,
705 RTE_FLOW_ERROR_TYPE_ITEM, item,
706 "IP proto in pattern with TCP item should be appropriate");
714 * Source and destination ports are in big-endian byte order in item and
715 * in little-endian in efx_spec, so byte swap is used
717 if (mask->hdr.src_port == supp_mask.hdr.src_port) {
718 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_PORT;
719 efx_spec->efs_rem_port = rte_bswap16(spec->hdr.src_port);
720 } else if (mask->hdr.src_port != 0) {
724 if (mask->hdr.dst_port == supp_mask.hdr.dst_port) {
725 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_PORT;
726 efx_spec->efs_loc_port = rte_bswap16(spec->hdr.dst_port);
727 } else if (mask->hdr.dst_port != 0) {
734 rte_flow_error_set(error, EINVAL,
735 RTE_FLOW_ERROR_TYPE_ITEM, item,
736 "Bad mask in the TCP pattern item");
741 * Convert UDP item to EFX filter specification.
744 * Item specification. Only source and destination ports fields
745 * are supported. If the mask is NULL, default mask will be used.
746 * Ranging is not supported.
747 * @param efx_spec[in, out]
748 * EFX filter specification to update.
750 * Perform verbose error reporting if not NULL.
753 sfc_flow_parse_udp(const struct rte_flow_item *item,
754 struct sfc_flow_parse_ctx *parse_ctx,
755 struct rte_flow_error *error)
758 efx_filter_spec_t *efx_spec = parse_ctx->filter;
759 const struct rte_flow_item_udp *spec = NULL;
760 const struct rte_flow_item_udp *mask = NULL;
761 const struct rte_flow_item_udp supp_mask = {
768 rc = sfc_flow_parse_init(item,
769 (const void **)&spec,
770 (const void **)&mask,
772 &rte_flow_item_udp_mask,
773 sizeof(struct rte_flow_item_udp),
779 * Filtering by UDP source and destination ports requires
780 * the appropriate IP_PROTO in hardware filters
782 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_IP_PROTO)) {
783 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
784 efx_spec->efs_ip_proto = EFX_IPPROTO_UDP;
785 } else if (efx_spec->efs_ip_proto != EFX_IPPROTO_UDP) {
786 rte_flow_error_set(error, EINVAL,
787 RTE_FLOW_ERROR_TYPE_ITEM, item,
788 "IP proto in pattern with UDP item should be appropriate");
796 * Source and destination ports are in big-endian byte order in item and
797 * in little-endian in efx_spec, so byte swap is used
799 if (mask->hdr.src_port == supp_mask.hdr.src_port) {
800 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_PORT;
801 efx_spec->efs_rem_port = rte_bswap16(spec->hdr.src_port);
802 } else if (mask->hdr.src_port != 0) {
806 if (mask->hdr.dst_port == supp_mask.hdr.dst_port) {
807 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_PORT;
808 efx_spec->efs_loc_port = rte_bswap16(spec->hdr.dst_port);
809 } else if (mask->hdr.dst_port != 0) {
816 rte_flow_error_set(error, EINVAL,
817 RTE_FLOW_ERROR_TYPE_ITEM, item,
818 "Bad mask in the UDP pattern item");
823 * Filters for encapsulated packets match based on the EtherType and IP
824 * protocol in the outer frame.
827 sfc_flow_set_match_flags_for_encap_pkts(const struct rte_flow_item *item,
828 efx_filter_spec_t *efx_spec,
830 struct rte_flow_error *error)
832 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_IP_PROTO)) {
833 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
834 efx_spec->efs_ip_proto = ip_proto;
835 } else if (efx_spec->efs_ip_proto != ip_proto) {
837 case EFX_IPPROTO_UDP:
838 rte_flow_error_set(error, EINVAL,
839 RTE_FLOW_ERROR_TYPE_ITEM, item,
840 "Outer IP header protocol must be UDP "
841 "in VxLAN/GENEVE pattern");
844 case EFX_IPPROTO_GRE:
845 rte_flow_error_set(error, EINVAL,
846 RTE_FLOW_ERROR_TYPE_ITEM, item,
847 "Outer IP header protocol must be GRE "
852 rte_flow_error_set(error, EINVAL,
853 RTE_FLOW_ERROR_TYPE_ITEM, item,
854 "Only VxLAN/GENEVE/NVGRE tunneling patterns "
860 if (efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
861 efx_spec->efs_ether_type != EFX_ETHER_TYPE_IPV4 &&
862 efx_spec->efs_ether_type != EFX_ETHER_TYPE_IPV6) {
863 rte_flow_error_set(error, EINVAL,
864 RTE_FLOW_ERROR_TYPE_ITEM, item,
865 "Outer frame EtherType in pattern with tunneling "
866 "must be IPv4 or IPv6");
874 sfc_flow_set_efx_spec_vni_or_vsid(efx_filter_spec_t *efx_spec,
875 const uint8_t *vni_or_vsid_val,
876 const uint8_t *vni_or_vsid_mask,
877 const struct rte_flow_item *item,
878 struct rte_flow_error *error)
880 const uint8_t vni_or_vsid_full_mask[EFX_VNI_OR_VSID_LEN] = {
884 if (memcmp(vni_or_vsid_mask, vni_or_vsid_full_mask,
885 EFX_VNI_OR_VSID_LEN) == 0) {
886 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_VNI_OR_VSID;
887 rte_memcpy(efx_spec->efs_vni_or_vsid, vni_or_vsid_val,
888 EFX_VNI_OR_VSID_LEN);
889 } else if (!sfc_flow_is_zero(vni_or_vsid_mask, EFX_VNI_OR_VSID_LEN)) {
890 rte_flow_error_set(error, EINVAL,
891 RTE_FLOW_ERROR_TYPE_ITEM, item,
892 "Unsupported VNI/VSID mask");
900 * Convert VXLAN item to EFX filter specification.
903 * Item specification. Only VXLAN network identifier field is supported.
904 * If the mask is NULL, default mask will be used.
905 * Ranging is not supported.
906 * @param efx_spec[in, out]
907 * EFX filter specification to update.
909 * Perform verbose error reporting if not NULL.
912 sfc_flow_parse_vxlan(const struct rte_flow_item *item,
913 struct sfc_flow_parse_ctx *parse_ctx,
914 struct rte_flow_error *error)
917 efx_filter_spec_t *efx_spec = parse_ctx->filter;
918 const struct rte_flow_item_vxlan *spec = NULL;
919 const struct rte_flow_item_vxlan *mask = NULL;
920 const struct rte_flow_item_vxlan supp_mask = {
921 .vni = { 0xff, 0xff, 0xff }
924 rc = sfc_flow_parse_init(item,
925 (const void **)&spec,
926 (const void **)&mask,
928 &rte_flow_item_vxlan_mask,
929 sizeof(struct rte_flow_item_vxlan),
934 rc = sfc_flow_set_match_flags_for_encap_pkts(item, efx_spec,
935 EFX_IPPROTO_UDP, error);
939 efx_spec->efs_encap_type = EFX_TUNNEL_PROTOCOL_VXLAN;
940 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
945 rc = sfc_flow_set_efx_spec_vni_or_vsid(efx_spec, spec->vni,
946 mask->vni, item, error);
952 * Convert GENEVE item to EFX filter specification.
955 * Item specification. Only Virtual Network Identifier and protocol type
956 * fields are supported. But protocol type can be only Ethernet (0x6558).
957 * If the mask is NULL, default mask will be used.
958 * Ranging is not supported.
959 * @param efx_spec[in, out]
960 * EFX filter specification to update.
962 * Perform verbose error reporting if not NULL.
965 sfc_flow_parse_geneve(const struct rte_flow_item *item,
966 struct sfc_flow_parse_ctx *parse_ctx,
967 struct rte_flow_error *error)
970 efx_filter_spec_t *efx_spec = parse_ctx->filter;
971 const struct rte_flow_item_geneve *spec = NULL;
972 const struct rte_flow_item_geneve *mask = NULL;
973 const struct rte_flow_item_geneve supp_mask = {
974 .protocol = RTE_BE16(0xffff),
975 .vni = { 0xff, 0xff, 0xff }
978 rc = sfc_flow_parse_init(item,
979 (const void **)&spec,
980 (const void **)&mask,
982 &rte_flow_item_geneve_mask,
983 sizeof(struct rte_flow_item_geneve),
988 rc = sfc_flow_set_match_flags_for_encap_pkts(item, efx_spec,
989 EFX_IPPROTO_UDP, error);
993 efx_spec->efs_encap_type = EFX_TUNNEL_PROTOCOL_GENEVE;
994 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
999 if (mask->protocol == supp_mask.protocol) {
1000 if (spec->protocol != rte_cpu_to_be_16(RTE_ETHER_TYPE_TEB)) {
1001 rte_flow_error_set(error, EINVAL,
1002 RTE_FLOW_ERROR_TYPE_ITEM, item,
1003 "GENEVE encap. protocol must be Ethernet "
1004 "(0x6558) in the GENEVE pattern item");
1007 } else if (mask->protocol != 0) {
1008 rte_flow_error_set(error, EINVAL,
1009 RTE_FLOW_ERROR_TYPE_ITEM, item,
1010 "Unsupported mask for GENEVE encap. protocol");
1014 rc = sfc_flow_set_efx_spec_vni_or_vsid(efx_spec, spec->vni,
1015 mask->vni, item, error);
1021 * Convert NVGRE item to EFX filter specification.
1024 * Item specification. Only virtual subnet ID field is supported.
1025 * If the mask is NULL, default mask will be used.
1026 * Ranging is not supported.
1027 * @param efx_spec[in, out]
1028 * EFX filter specification to update.
1030 * Perform verbose error reporting if not NULL.
1033 sfc_flow_parse_nvgre(const struct rte_flow_item *item,
1034 struct sfc_flow_parse_ctx *parse_ctx,
1035 struct rte_flow_error *error)
1038 efx_filter_spec_t *efx_spec = parse_ctx->filter;
1039 const struct rte_flow_item_nvgre *spec = NULL;
1040 const struct rte_flow_item_nvgre *mask = NULL;
1041 const struct rte_flow_item_nvgre supp_mask = {
1042 .tni = { 0xff, 0xff, 0xff }
1045 rc = sfc_flow_parse_init(item,
1046 (const void **)&spec,
1047 (const void **)&mask,
1049 &rte_flow_item_nvgre_mask,
1050 sizeof(struct rte_flow_item_nvgre),
1055 rc = sfc_flow_set_match_flags_for_encap_pkts(item, efx_spec,
1056 EFX_IPPROTO_GRE, error);
1060 efx_spec->efs_encap_type = EFX_TUNNEL_PROTOCOL_NVGRE;
1061 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
1066 rc = sfc_flow_set_efx_spec_vni_or_vsid(efx_spec, spec->tni,
1067 mask->tni, item, error);
1073 * Convert PPPoEx item to EFX filter specification.
1076 * Item specification.
1077 * Matching on PPPoEx fields is not supported.
1078 * This item can only be used to set or validate the EtherType filter.
1079 * Only zero masks are allowed.
1080 * Ranging is not supported.
1081 * @param efx_spec[in, out]
1082 * EFX filter specification to update.
1084 * Perform verbose error reporting if not NULL.
1087 sfc_flow_parse_pppoex(const struct rte_flow_item *item,
1088 struct sfc_flow_parse_ctx *parse_ctx,
1089 struct rte_flow_error *error)
1091 efx_filter_spec_t *efx_spec = parse_ctx->filter;
1092 const struct rte_flow_item_pppoe *spec = NULL;
1093 const struct rte_flow_item_pppoe *mask = NULL;
1094 const struct rte_flow_item_pppoe supp_mask = {};
1095 const struct rte_flow_item_pppoe def_mask = {};
1096 uint16_t ether_type;
1099 rc = sfc_flow_parse_init(item,
1100 (const void **)&spec,
1101 (const void **)&mask,
1104 sizeof(struct rte_flow_item_pppoe),
1109 if (item->type == RTE_FLOW_ITEM_TYPE_PPPOED)
1110 ether_type = RTE_ETHER_TYPE_PPPOE_DISCOVERY;
1112 ether_type = RTE_ETHER_TYPE_PPPOE_SESSION;
1114 if ((efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE) != 0) {
1115 if (efx_spec->efs_ether_type != ether_type) {
1116 rte_flow_error_set(error, EINVAL,
1117 RTE_FLOW_ERROR_TYPE_ITEM, item,
1118 "Invalid EtherType for a PPPoE flow item");
1122 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
1123 efx_spec->efs_ether_type = ether_type;
1129 static const struct sfc_flow_item sfc_flow_items[] = {
1131 .type = RTE_FLOW_ITEM_TYPE_VOID,
1133 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
1134 .layer = SFC_FLOW_ITEM_ANY_LAYER,
1135 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1136 .parse = sfc_flow_parse_void,
1139 .type = RTE_FLOW_ITEM_TYPE_ETH,
1141 .prev_layer = SFC_FLOW_ITEM_START_LAYER,
1142 .layer = SFC_FLOW_ITEM_L2,
1143 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1144 .parse = sfc_flow_parse_eth,
1147 .type = RTE_FLOW_ITEM_TYPE_VLAN,
1149 .prev_layer = SFC_FLOW_ITEM_L2,
1150 .layer = SFC_FLOW_ITEM_L2,
1151 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1152 .parse = sfc_flow_parse_vlan,
1155 .type = RTE_FLOW_ITEM_TYPE_PPPOED,
1157 .prev_layer = SFC_FLOW_ITEM_L2,
1158 .layer = SFC_FLOW_ITEM_L2,
1159 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1160 .parse = sfc_flow_parse_pppoex,
1163 .type = RTE_FLOW_ITEM_TYPE_PPPOES,
1165 .prev_layer = SFC_FLOW_ITEM_L2,
1166 .layer = SFC_FLOW_ITEM_L2,
1167 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1168 .parse = sfc_flow_parse_pppoex,
1171 .type = RTE_FLOW_ITEM_TYPE_IPV4,
1173 .prev_layer = SFC_FLOW_ITEM_L2,
1174 .layer = SFC_FLOW_ITEM_L3,
1175 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1176 .parse = sfc_flow_parse_ipv4,
1179 .type = RTE_FLOW_ITEM_TYPE_IPV6,
1181 .prev_layer = SFC_FLOW_ITEM_L2,
1182 .layer = SFC_FLOW_ITEM_L3,
1183 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1184 .parse = sfc_flow_parse_ipv6,
1187 .type = RTE_FLOW_ITEM_TYPE_TCP,
1189 .prev_layer = SFC_FLOW_ITEM_L3,
1190 .layer = SFC_FLOW_ITEM_L4,
1191 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1192 .parse = sfc_flow_parse_tcp,
1195 .type = RTE_FLOW_ITEM_TYPE_UDP,
1197 .prev_layer = SFC_FLOW_ITEM_L3,
1198 .layer = SFC_FLOW_ITEM_L4,
1199 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1200 .parse = sfc_flow_parse_udp,
1203 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
1205 .prev_layer = SFC_FLOW_ITEM_L4,
1206 .layer = SFC_FLOW_ITEM_START_LAYER,
1207 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1208 .parse = sfc_flow_parse_vxlan,
1211 .type = RTE_FLOW_ITEM_TYPE_GENEVE,
1213 .prev_layer = SFC_FLOW_ITEM_L4,
1214 .layer = SFC_FLOW_ITEM_START_LAYER,
1215 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1216 .parse = sfc_flow_parse_geneve,
1219 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
1221 .prev_layer = SFC_FLOW_ITEM_L3,
1222 .layer = SFC_FLOW_ITEM_START_LAYER,
1223 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1224 .parse = sfc_flow_parse_nvgre,
1229 * Protocol-independent flow API support
1232 sfc_flow_parse_attr(struct sfc_adapter *sa,
1233 const struct rte_flow_attr *attr,
1234 struct rte_flow *flow,
1235 struct rte_flow_error *error)
1237 struct sfc_flow_spec *spec = &flow->spec;
1238 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1239 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
1240 struct sfc_mae *mae = &sa->mae;
1243 rte_flow_error_set(error, EINVAL,
1244 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
1248 if (attr->group != 0) {
1249 rte_flow_error_set(error, ENOTSUP,
1250 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, attr,
1251 "Groups are not supported");
1254 if (attr->egress != 0) {
1255 rte_flow_error_set(error, ENOTSUP,
1256 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attr,
1257 "Egress is not supported");
1260 if (attr->ingress == 0) {
1261 rte_flow_error_set(error, ENOTSUP,
1262 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, attr,
1263 "Ingress is compulsory");
1266 if (attr->transfer == 0) {
1267 if (attr->priority != 0) {
1268 rte_flow_error_set(error, ENOTSUP,
1269 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1270 attr, "Priorities are unsupported");
1273 spec->type = SFC_FLOW_SPEC_FILTER;
1274 spec_filter->template.efs_flags |= EFX_FILTER_FLAG_RX;
1275 spec_filter->template.efs_rss_context = EFX_RSS_CONTEXT_DEFAULT;
1276 spec_filter->template.efs_priority = EFX_FILTER_PRI_MANUAL;
1278 if (mae->status != SFC_MAE_STATUS_ADMIN) {
1279 rte_flow_error_set(error, ENOTSUP,
1280 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1281 attr, "Transfer is not supported");
1284 if (attr->priority > mae->nb_action_rule_prios_max) {
1285 rte_flow_error_set(error, ENOTSUP,
1286 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1287 attr, "Unsupported priority level");
1290 spec->type = SFC_FLOW_SPEC_MAE;
1291 spec_mae->priority = attr->priority;
1292 spec_mae->match_spec = NULL;
1293 spec_mae->action_set = NULL;
1294 spec_mae->rule_id.id = EFX_MAE_RSRC_ID_INVALID;
1300 /* Get item from array sfc_flow_items */
1301 static const struct sfc_flow_item *
1302 sfc_flow_get_item(const struct sfc_flow_item *items,
1303 unsigned int nb_items,
1304 enum rte_flow_item_type type)
1308 for (i = 0; i < nb_items; i++)
1309 if (items[i].type == type)
1316 sfc_flow_parse_pattern(struct sfc_adapter *sa,
1317 const struct sfc_flow_item *flow_items,
1318 unsigned int nb_flow_items,
1319 const struct rte_flow_item pattern[],
1320 struct sfc_flow_parse_ctx *parse_ctx,
1321 struct rte_flow_error *error)
1324 unsigned int prev_layer = SFC_FLOW_ITEM_ANY_LAYER;
1325 boolean_t is_ifrm = B_FALSE;
1326 const struct sfc_flow_item *item;
1328 if (pattern == NULL) {
1329 rte_flow_error_set(error, EINVAL,
1330 RTE_FLOW_ERROR_TYPE_ITEM_NUM, NULL,
1335 for (; pattern->type != RTE_FLOW_ITEM_TYPE_END; pattern++) {
1336 item = sfc_flow_get_item(flow_items, nb_flow_items,
1339 rte_flow_error_set(error, ENOTSUP,
1340 RTE_FLOW_ERROR_TYPE_ITEM, pattern,
1341 "Unsupported pattern item");
1346 * Omitting one or several protocol layers at the beginning
1347 * of pattern is supported
1349 if (item->prev_layer != SFC_FLOW_ITEM_ANY_LAYER &&
1350 prev_layer != SFC_FLOW_ITEM_ANY_LAYER &&
1351 item->prev_layer != prev_layer) {
1352 rte_flow_error_set(error, ENOTSUP,
1353 RTE_FLOW_ERROR_TYPE_ITEM, pattern,
1354 "Unexpected sequence of pattern items");
1359 * Allow only VOID and ETH pattern items in the inner frame.
1360 * Also check that there is only one tunneling protocol.
1362 switch (item->type) {
1363 case RTE_FLOW_ITEM_TYPE_VOID:
1364 case RTE_FLOW_ITEM_TYPE_ETH:
1367 case RTE_FLOW_ITEM_TYPE_VXLAN:
1368 case RTE_FLOW_ITEM_TYPE_GENEVE:
1369 case RTE_FLOW_ITEM_TYPE_NVGRE:
1371 rte_flow_error_set(error, EINVAL,
1372 RTE_FLOW_ERROR_TYPE_ITEM,
1374 "More than one tunneling protocol");
1381 if (parse_ctx->type == SFC_FLOW_PARSE_CTX_FILTER &&
1383 rte_flow_error_set(error, EINVAL,
1384 RTE_FLOW_ERROR_TYPE_ITEM,
1386 "There is an unsupported pattern item "
1387 "in the inner frame");
1393 if (parse_ctx->type != item->ctx_type) {
1394 rte_flow_error_set(error, EINVAL,
1395 RTE_FLOW_ERROR_TYPE_ITEM, pattern,
1396 "Parse context type mismatch");
1400 rc = item->parse(pattern, parse_ctx, error);
1402 sfc_err(sa, "failed to parse item %s: %s",
1403 item->name, strerror(-rc));
1407 if (item->layer != SFC_FLOW_ITEM_ANY_LAYER)
1408 prev_layer = item->layer;
1415 sfc_flow_parse_queue(struct sfc_adapter *sa,
1416 const struct rte_flow_action_queue *queue,
1417 struct rte_flow *flow)
1419 struct sfc_flow_spec *spec = &flow->spec;
1420 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1421 struct sfc_rxq *rxq;
1422 struct sfc_rxq_info *rxq_info;
1424 if (queue->index >= sfc_sa2shared(sa)->ethdev_rxq_count)
1427 rxq = sfc_rxq_ctrl_by_ethdev_qid(sa, queue->index);
1428 spec_filter->template.efs_dmaq_id = (uint16_t)rxq->hw_index;
1430 rxq_info = &sfc_sa2shared(sa)->rxq_info[queue->index];
1431 spec_filter->rss_hash_required = !!(rxq_info->rxq_flags &
1432 SFC_RXQ_FLAG_RSS_HASH);
1438 sfc_flow_parse_rss(struct sfc_adapter *sa,
1439 const struct rte_flow_action_rss *action_rss,
1440 struct rte_flow *flow)
1442 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
1443 struct sfc_rss *rss = &sas->rss;
1444 sfc_ethdev_qid_t ethdev_qid;
1445 struct sfc_rxq *rxq;
1446 unsigned int rxq_hw_index_min;
1447 unsigned int rxq_hw_index_max;
1448 efx_rx_hash_type_t efx_hash_types;
1449 const uint8_t *rss_key;
1450 struct sfc_flow_spec *spec = &flow->spec;
1451 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1452 struct sfc_flow_rss *sfc_rss_conf = &spec_filter->rss_conf;
1455 if (action_rss->queue_num == 0)
1458 ethdev_qid = sfc_sa2shared(sa)->ethdev_rxq_count - 1;
1459 rxq = sfc_rxq_ctrl_by_ethdev_qid(sa, ethdev_qid);
1460 rxq_hw_index_min = rxq->hw_index;
1461 rxq_hw_index_max = 0;
1463 for (i = 0; i < action_rss->queue_num; ++i) {
1464 ethdev_qid = action_rss->queue[i];
1466 if ((unsigned int)ethdev_qid >=
1467 sfc_sa2shared(sa)->ethdev_rxq_count)
1470 rxq = sfc_rxq_ctrl_by_ethdev_qid(sa, ethdev_qid);
1472 if (rxq->hw_index < rxq_hw_index_min)
1473 rxq_hw_index_min = rxq->hw_index;
1475 if (rxq->hw_index > rxq_hw_index_max)
1476 rxq_hw_index_max = rxq->hw_index;
1479 switch (action_rss->func) {
1480 case RTE_ETH_HASH_FUNCTION_DEFAULT:
1481 case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
1487 if (action_rss->level)
1491 * Dummy RSS action with only one queue and no specific settings
1492 * for hash types and key does not require dedicated RSS context
1493 * and may be simplified to single queue action.
1495 if (action_rss->queue_num == 1 && action_rss->types == 0 &&
1496 action_rss->key_len == 0) {
1497 spec_filter->template.efs_dmaq_id = rxq_hw_index_min;
1501 if (action_rss->types) {
1504 rc = sfc_rx_hf_rte_to_efx(sa, action_rss->types,
1512 for (i = 0; i < rss->hf_map_nb_entries; ++i)
1513 efx_hash_types |= rss->hf_map[i].efx;
1516 if (action_rss->key_len) {
1517 if (action_rss->key_len != sizeof(rss->key))
1520 rss_key = action_rss->key;
1525 spec_filter->rss = B_TRUE;
1527 sfc_rss_conf->rxq_hw_index_min = rxq_hw_index_min;
1528 sfc_rss_conf->rxq_hw_index_max = rxq_hw_index_max;
1529 sfc_rss_conf->rss_hash_types = efx_hash_types;
1530 rte_memcpy(sfc_rss_conf->rss_key, rss_key, sizeof(rss->key));
1532 for (i = 0; i < RTE_DIM(sfc_rss_conf->rss_tbl); ++i) {
1533 unsigned int nb_queues = action_rss->queue_num;
1534 struct sfc_rxq *rxq;
1536 ethdev_qid = action_rss->queue[i % nb_queues];
1537 rxq = sfc_rxq_ctrl_by_ethdev_qid(sa, ethdev_qid);
1538 sfc_rss_conf->rss_tbl[i] = rxq->hw_index - rxq_hw_index_min;
1545 sfc_flow_spec_flush(struct sfc_adapter *sa, struct sfc_flow_spec *spec,
1546 unsigned int filters_count)
1548 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1552 for (i = 0; i < filters_count; i++) {
1555 rc = efx_filter_remove(sa->nic, &spec_filter->filters[i]);
1556 if (ret == 0 && rc != 0) {
1557 sfc_err(sa, "failed to remove filter specification "
1567 sfc_flow_spec_insert(struct sfc_adapter *sa, struct sfc_flow_spec *spec)
1569 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1573 for (i = 0; i < spec_filter->count; i++) {
1574 rc = efx_filter_insert(sa->nic, &spec_filter->filters[i]);
1576 sfc_flow_spec_flush(sa, spec, i);
1585 sfc_flow_spec_remove(struct sfc_adapter *sa, struct sfc_flow_spec *spec)
1587 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1589 return sfc_flow_spec_flush(sa, spec, spec_filter->count);
1593 sfc_flow_filter_insert(struct sfc_adapter *sa,
1594 struct rte_flow *flow)
1596 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
1597 struct sfc_rss *rss = &sas->rss;
1598 struct sfc_flow_spec_filter *spec_filter = &flow->spec.filter;
1599 struct sfc_flow_rss *flow_rss = &spec_filter->rss_conf;
1600 uint32_t efs_rss_context = EFX_RSS_CONTEXT_DEFAULT;
1601 boolean_t create_context;
1605 create_context = spec_filter->rss || (spec_filter->rss_hash_required &&
1606 rss->dummy_rss_context == EFX_RSS_CONTEXT_DEFAULT);
1608 if (create_context) {
1609 unsigned int rss_spread;
1610 unsigned int rss_hash_types;
1613 if (spec_filter->rss) {
1614 rss_spread = MIN(flow_rss->rxq_hw_index_max -
1615 flow_rss->rxq_hw_index_min + 1,
1617 rss_hash_types = flow_rss->rss_hash_types;
1618 rss_key = flow_rss->rss_key;
1621 * Initialize dummy RSS context parameters to have
1622 * valid RSS hash. Use default RSS hash function and
1626 rss_hash_types = rss->hash_types;
1630 rc = efx_rx_scale_context_alloc(sa->nic,
1631 EFX_RX_SCALE_EXCLUSIVE,
1635 goto fail_scale_context_alloc;
1637 rc = efx_rx_scale_mode_set(sa->nic, efs_rss_context,
1639 rss_hash_types, B_TRUE);
1641 goto fail_scale_mode_set;
1643 rc = efx_rx_scale_key_set(sa->nic, efs_rss_context,
1644 rss_key, sizeof(rss->key));
1646 goto fail_scale_key_set;
1648 efs_rss_context = rss->dummy_rss_context;
1651 if (spec_filter->rss || spec_filter->rss_hash_required) {
1653 * At this point, fully elaborated filter specifications
1654 * have been produced from the template. To make sure that
1655 * RSS behaviour is consistent between them, set the same
1656 * RSS context value everywhere.
1658 for (i = 0; i < spec_filter->count; i++) {
1659 efx_filter_spec_t *spec = &spec_filter->filters[i];
1661 spec->efs_rss_context = efs_rss_context;
1662 spec->efs_flags |= EFX_FILTER_FLAG_RX_RSS;
1663 if (spec_filter->rss)
1664 spec->efs_dmaq_id = flow_rss->rxq_hw_index_min;
1668 rc = sfc_flow_spec_insert(sa, &flow->spec);
1670 goto fail_filter_insert;
1672 if (create_context) {
1673 unsigned int dummy_tbl[RTE_DIM(flow_rss->rss_tbl)] = {0};
1676 tbl = spec_filter->rss ? flow_rss->rss_tbl : dummy_tbl;
1679 * Scale table is set after filter insertion because
1680 * the table entries are relative to the base RxQ ID
1681 * and the latter is submitted to the HW by means of
1682 * inserting a filter, so by the time of the request
1683 * the HW knows all the information needed to verify
1684 * the table entries, and the operation will succeed
1686 rc = efx_rx_scale_tbl_set(sa->nic, efs_rss_context,
1687 tbl, RTE_DIM(flow_rss->rss_tbl));
1689 goto fail_scale_tbl_set;
1691 /* Remember created dummy RSS context */
1692 if (!spec_filter->rss)
1693 rss->dummy_rss_context = efs_rss_context;
1699 sfc_flow_spec_remove(sa, &flow->spec);
1703 fail_scale_mode_set:
1705 efx_rx_scale_context_free(sa->nic, efs_rss_context);
1707 fail_scale_context_alloc:
1712 sfc_flow_filter_remove(struct sfc_adapter *sa,
1713 struct rte_flow *flow)
1715 struct sfc_flow_spec_filter *spec_filter = &flow->spec.filter;
1718 rc = sfc_flow_spec_remove(sa, &flow->spec);
1722 if (spec_filter->rss) {
1724 * All specifications for a given flow rule have the same RSS
1725 * context, so that RSS context value is taken from the first
1726 * filter specification
1728 efx_filter_spec_t *spec = &spec_filter->filters[0];
1730 rc = efx_rx_scale_context_free(sa->nic, spec->efs_rss_context);
1737 sfc_flow_parse_mark(struct sfc_adapter *sa,
1738 const struct rte_flow_action_mark *mark,
1739 struct rte_flow *flow)
1741 struct sfc_flow_spec *spec = &flow->spec;
1742 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1743 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
1746 mark_max = encp->enc_filter_action_mark_max;
1747 if (sfc_flow_tunnel_is_active(sa))
1748 mark_max = RTE_MIN(mark_max, SFC_FT_USER_MARK_MASK);
1750 if (mark == NULL || mark->id > mark_max)
1753 spec_filter->template.efs_flags |= EFX_FILTER_FLAG_ACTION_MARK;
1754 spec_filter->template.efs_mark = mark->id;
1760 sfc_flow_parse_actions(struct sfc_adapter *sa,
1761 const struct rte_flow_action actions[],
1762 struct rte_flow *flow,
1763 struct rte_flow_error *error)
1766 struct sfc_flow_spec *spec = &flow->spec;
1767 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1768 const unsigned int dp_rx_features = sa->priv.dp_rx->features;
1769 const uint64_t rx_metadata = sa->negotiated_rx_metadata;
1770 uint32_t actions_set = 0;
1771 const uint32_t fate_actions_mask = (1UL << RTE_FLOW_ACTION_TYPE_QUEUE) |
1772 (1UL << RTE_FLOW_ACTION_TYPE_RSS) |
1773 (1UL << RTE_FLOW_ACTION_TYPE_DROP);
1774 const uint32_t mark_actions_mask = (1UL << RTE_FLOW_ACTION_TYPE_MARK) |
1775 (1UL << RTE_FLOW_ACTION_TYPE_FLAG);
1777 if (actions == NULL) {
1778 rte_flow_error_set(error, EINVAL,
1779 RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
1784 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1785 switch (actions->type) {
1786 case RTE_FLOW_ACTION_TYPE_VOID:
1787 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VOID,
1791 case RTE_FLOW_ACTION_TYPE_QUEUE:
1792 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_QUEUE,
1794 if ((actions_set & fate_actions_mask) != 0)
1795 goto fail_fate_actions;
1797 rc = sfc_flow_parse_queue(sa, actions->conf, flow);
1799 rte_flow_error_set(error, EINVAL,
1800 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1801 "Bad QUEUE action");
1806 case RTE_FLOW_ACTION_TYPE_RSS:
1807 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_RSS,
1809 if ((actions_set & fate_actions_mask) != 0)
1810 goto fail_fate_actions;
1812 rc = sfc_flow_parse_rss(sa, actions->conf, flow);
1814 rte_flow_error_set(error, -rc,
1815 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1821 case RTE_FLOW_ACTION_TYPE_DROP:
1822 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_DROP,
1824 if ((actions_set & fate_actions_mask) != 0)
1825 goto fail_fate_actions;
1827 spec_filter->template.efs_dmaq_id =
1828 EFX_FILTER_SPEC_RX_DMAQ_ID_DROP;
1831 case RTE_FLOW_ACTION_TYPE_FLAG:
1832 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_FLAG,
1834 if ((actions_set & mark_actions_mask) != 0)
1835 goto fail_actions_overlap;
1837 if ((dp_rx_features & SFC_DP_RX_FEAT_FLOW_FLAG) == 0) {
1838 rte_flow_error_set(error, ENOTSUP,
1839 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1840 "FLAG action is not supported on the current Rx datapath");
1842 } else if ((rx_metadata &
1843 RTE_ETH_RX_METADATA_USER_FLAG) == 0) {
1844 rte_flow_error_set(error, ENOTSUP,
1845 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1846 "flag delivery has not been negotiated");
1850 spec_filter->template.efs_flags |=
1851 EFX_FILTER_FLAG_ACTION_FLAG;
1854 case RTE_FLOW_ACTION_TYPE_MARK:
1855 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_MARK,
1857 if ((actions_set & mark_actions_mask) != 0)
1858 goto fail_actions_overlap;
1860 if ((dp_rx_features & SFC_DP_RX_FEAT_FLOW_MARK) == 0) {
1861 rte_flow_error_set(error, ENOTSUP,
1862 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1863 "MARK action is not supported on the current Rx datapath");
1865 } else if ((rx_metadata &
1866 RTE_ETH_RX_METADATA_USER_MARK) == 0) {
1867 rte_flow_error_set(error, ENOTSUP,
1868 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1869 "mark delivery has not been negotiated");
1873 rc = sfc_flow_parse_mark(sa, actions->conf, flow);
1875 rte_flow_error_set(error, rc,
1876 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1883 rte_flow_error_set(error, ENOTSUP,
1884 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1885 "Action is not supported");
1889 actions_set |= (1UL << actions->type);
1892 /* When fate is unknown, drop traffic. */
1893 if ((actions_set & fate_actions_mask) == 0) {
1894 spec_filter->template.efs_dmaq_id =
1895 EFX_FILTER_SPEC_RX_DMAQ_ID_DROP;
1901 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, actions,
1902 "Cannot combine several fate-deciding actions, "
1903 "choose between QUEUE, RSS or DROP");
1906 fail_actions_overlap:
1907 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, actions,
1908 "Overlapping actions are not supported");
1913 * Set the EFX_FILTER_MATCH_UNKNOWN_UCAST_DST
1914 * and EFX_FILTER_MATCH_UNKNOWN_MCAST_DST match flags in the same
1915 * specifications after copying.
1917 * @param spec[in, out]
1918 * SFC flow specification to update.
1919 * @param filters_count_for_one_val[in]
1920 * How many specifications should have the same match flag, what is the
1921 * number of specifications before copying.
1923 * Perform verbose error reporting if not NULL.
1926 sfc_flow_set_unknown_dst_flags(struct sfc_flow_spec *spec,
1927 unsigned int filters_count_for_one_val,
1928 struct rte_flow_error *error)
1931 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1932 static const efx_filter_match_flags_t vals[] = {
1933 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST,
1934 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST
1937 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
1938 rte_flow_error_set(error, EINVAL,
1939 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1940 "Number of specifications is incorrect while copying "
1941 "by unknown destination flags");
1945 for (i = 0; i < spec_filter->count; i++) {
1946 /* The check above ensures that divisor can't be zero here */
1947 spec_filter->filters[i].efs_match_flags |=
1948 vals[i / filters_count_for_one_val];
1955 * Check that the following conditions are met:
1956 * - the list of supported filters has a filter
1957 * with EFX_FILTER_MATCH_UNKNOWN_MCAST_DST flag instead of
1958 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST, since this filter will also
1962 * The match flags of filter.
1964 * Specification to be supplemented.
1966 * SFC filter with list of supported filters.
1969 sfc_flow_check_unknown_dst_flags(efx_filter_match_flags_t match,
1970 __rte_unused efx_filter_spec_t *spec,
1971 struct sfc_filter *filter)
1974 efx_filter_match_flags_t match_mcast_dst;
1977 (match & ~EFX_FILTER_MATCH_UNKNOWN_UCAST_DST) |
1978 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST;
1979 for (i = 0; i < filter->supported_match_num; i++) {
1980 if (match_mcast_dst == filter->supported_match[i])
1988 * Set the EFX_FILTER_MATCH_ETHER_TYPE match flag and EFX_ETHER_TYPE_IPV4 and
1989 * EFX_ETHER_TYPE_IPV6 values of the corresponding field in the same
1990 * specifications after copying.
1992 * @param spec[in, out]
1993 * SFC flow specification to update.
1994 * @param filters_count_for_one_val[in]
1995 * How many specifications should have the same EtherType value, what is the
1996 * number of specifications before copying.
1998 * Perform verbose error reporting if not NULL.
2001 sfc_flow_set_ethertypes(struct sfc_flow_spec *spec,
2002 unsigned int filters_count_for_one_val,
2003 struct rte_flow_error *error)
2006 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2007 static const uint16_t vals[] = {
2008 EFX_ETHER_TYPE_IPV4, EFX_ETHER_TYPE_IPV6
2011 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
2012 rte_flow_error_set(error, EINVAL,
2013 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2014 "Number of specifications is incorrect "
2015 "while copying by Ethertype");
2019 for (i = 0; i < spec_filter->count; i++) {
2020 spec_filter->filters[i].efs_match_flags |=
2021 EFX_FILTER_MATCH_ETHER_TYPE;
2024 * The check above ensures that
2025 * filters_count_for_one_val is not 0
2027 spec_filter->filters[i].efs_ether_type =
2028 vals[i / filters_count_for_one_val];
2035 * Set the EFX_FILTER_MATCH_OUTER_VID match flag with value 0
2036 * in the same specifications after copying.
2038 * @param spec[in, out]
2039 * SFC flow specification to update.
2040 * @param filters_count_for_one_val[in]
2041 * How many specifications should have the same match flag, what is the
2042 * number of specifications before copying.
2044 * Perform verbose error reporting if not NULL.
2047 sfc_flow_set_outer_vid_flag(struct sfc_flow_spec *spec,
2048 unsigned int filters_count_for_one_val,
2049 struct rte_flow_error *error)
2051 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2054 if (filters_count_for_one_val != spec_filter->count) {
2055 rte_flow_error_set(error, EINVAL,
2056 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2057 "Number of specifications is incorrect "
2058 "while copying by outer VLAN ID");
2062 for (i = 0; i < spec_filter->count; i++) {
2063 spec_filter->filters[i].efs_match_flags |=
2064 EFX_FILTER_MATCH_OUTER_VID;
2066 spec_filter->filters[i].efs_outer_vid = 0;
2073 * Set the EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST and
2074 * EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST match flags in the same
2075 * specifications after copying.
2077 * @param spec[in, out]
2078 * SFC flow specification to update.
2079 * @param filters_count_for_one_val[in]
2080 * How many specifications should have the same match flag, what is the
2081 * number of specifications before copying.
2083 * Perform verbose error reporting if not NULL.
2086 sfc_flow_set_ifrm_unknown_dst_flags(struct sfc_flow_spec *spec,
2087 unsigned int filters_count_for_one_val,
2088 struct rte_flow_error *error)
2091 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2092 static const efx_filter_match_flags_t vals[] = {
2093 EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST,
2094 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST
2097 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
2098 rte_flow_error_set(error, EINVAL,
2099 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2100 "Number of specifications is incorrect while copying "
2101 "by inner frame unknown destination flags");
2105 for (i = 0; i < spec_filter->count; i++) {
2106 /* The check above ensures that divisor can't be zero here */
2107 spec_filter->filters[i].efs_match_flags |=
2108 vals[i / filters_count_for_one_val];
2115 * Check that the following conditions are met:
2116 * - the specification corresponds to a filter for encapsulated traffic
2117 * - the list of supported filters has a filter
2118 * with EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST flag instead of
2119 * EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST, since this filter will also
2123 * The match flags of filter.
2125 * Specification to be supplemented.
2127 * SFC filter with list of supported filters.
2130 sfc_flow_check_ifrm_unknown_dst_flags(efx_filter_match_flags_t match,
2131 efx_filter_spec_t *spec,
2132 struct sfc_filter *filter)
2135 efx_tunnel_protocol_t encap_type = spec->efs_encap_type;
2136 efx_filter_match_flags_t match_mcast_dst;
2138 if (encap_type == EFX_TUNNEL_PROTOCOL_NONE)
2142 (match & ~EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST) |
2143 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST;
2144 for (i = 0; i < filter->supported_match_num; i++) {
2145 if (match_mcast_dst == filter->supported_match[i])
2153 * Check that the list of supported filters has a filter that differs
2154 * from @p match in that it has no flag EFX_FILTER_MATCH_OUTER_VID
2155 * in this case that filter will be used and the flag
2156 * EFX_FILTER_MATCH_OUTER_VID is not needed.
2159 * The match flags of filter.
2161 * Specification to be supplemented.
2163 * SFC filter with list of supported filters.
2166 sfc_flow_check_outer_vid_flag(efx_filter_match_flags_t match,
2167 __rte_unused efx_filter_spec_t *spec,
2168 struct sfc_filter *filter)
2171 efx_filter_match_flags_t match_without_vid =
2172 match & ~EFX_FILTER_MATCH_OUTER_VID;
2174 for (i = 0; i < filter->supported_match_num; i++) {
2175 if (match_without_vid == filter->supported_match[i])
2183 * Match flags that can be automatically added to filters.
2184 * Selecting the last minimum when searching for the copy flag ensures that the
2185 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST flag has a higher priority than
2186 * EFX_FILTER_MATCH_ETHER_TYPE. This is because the filter
2187 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST is at the end of the list of supported
2190 static const struct sfc_flow_copy_flag sfc_flow_copy_flags[] = {
2192 .flag = EFX_FILTER_MATCH_UNKNOWN_UCAST_DST,
2194 .set_vals = sfc_flow_set_unknown_dst_flags,
2195 .spec_check = sfc_flow_check_unknown_dst_flags,
2198 .flag = EFX_FILTER_MATCH_ETHER_TYPE,
2200 .set_vals = sfc_flow_set_ethertypes,
2204 .flag = EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST,
2206 .set_vals = sfc_flow_set_ifrm_unknown_dst_flags,
2207 .spec_check = sfc_flow_check_ifrm_unknown_dst_flags,
2210 .flag = EFX_FILTER_MATCH_OUTER_VID,
2212 .set_vals = sfc_flow_set_outer_vid_flag,
2213 .spec_check = sfc_flow_check_outer_vid_flag,
2217 /* Get item from array sfc_flow_copy_flags */
2218 static const struct sfc_flow_copy_flag *
2219 sfc_flow_get_copy_flag(efx_filter_match_flags_t flag)
2223 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
2224 if (sfc_flow_copy_flags[i].flag == flag)
2225 return &sfc_flow_copy_flags[i];
2232 * Make copies of the specifications, set match flag and values
2233 * of the field that corresponds to it.
2235 * @param spec[in, out]
2236 * SFC flow specification to update.
2238 * The match flag to add.
2240 * Perform verbose error reporting if not NULL.
2243 sfc_flow_spec_add_match_flag(struct sfc_flow_spec *spec,
2244 efx_filter_match_flags_t flag,
2245 struct rte_flow_error *error)
2248 unsigned int new_filters_count;
2249 unsigned int filters_count_for_one_val;
2250 const struct sfc_flow_copy_flag *copy_flag;
2251 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2254 copy_flag = sfc_flow_get_copy_flag(flag);
2255 if (copy_flag == NULL) {
2256 rte_flow_error_set(error, ENOTSUP,
2257 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2258 "Unsupported spec field for copying");
2262 new_filters_count = spec_filter->count * copy_flag->vals_count;
2263 if (new_filters_count > SF_FLOW_SPEC_NB_FILTERS_MAX) {
2264 rte_flow_error_set(error, EINVAL,
2265 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2266 "Too much EFX specifications in the flow rule");
2270 /* Copy filters specifications */
2271 for (i = spec_filter->count; i < new_filters_count; i++) {
2272 spec_filter->filters[i] =
2273 spec_filter->filters[i - spec_filter->count];
2276 filters_count_for_one_val = spec_filter->count;
2277 spec_filter->count = new_filters_count;
2279 rc = copy_flag->set_vals(spec, filters_count_for_one_val, error);
2287 * Check that the given set of match flags missing in the original filter spec
2288 * could be covered by adding spec copies which specify the corresponding
2289 * flags and packet field values to match.
2291 * @param miss_flags[in]
2292 * Flags that are missing until the supported filter.
2294 * Specification to be supplemented.
2299 * Number of specifications after copy or 0, if the flags can not be added.
2302 sfc_flow_check_missing_flags(efx_filter_match_flags_t miss_flags,
2303 efx_filter_spec_t *spec,
2304 struct sfc_filter *filter)
2307 efx_filter_match_flags_t copy_flags = 0;
2308 efx_filter_match_flags_t flag;
2309 efx_filter_match_flags_t match = spec->efs_match_flags | miss_flags;
2310 sfc_flow_spec_check *check;
2311 unsigned int multiplier = 1;
2313 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
2314 flag = sfc_flow_copy_flags[i].flag;
2315 check = sfc_flow_copy_flags[i].spec_check;
2316 if ((flag & miss_flags) == flag) {
2317 if (check != NULL && (!check(match, spec, filter)))
2321 multiplier *= sfc_flow_copy_flags[i].vals_count;
2325 if (copy_flags == miss_flags)
2332 * Attempt to supplement the specification template to the minimally
2333 * supported set of match flags. To do this, it is necessary to copy
2334 * the specifications, filling them with the values of fields that
2335 * correspond to the missing flags.
2336 * The necessary and sufficient filter is built from the fewest number
2337 * of copies which could be made to cover the minimally required set
2342 * @param spec[in, out]
2343 * SFC flow specification to update.
2345 * Perform verbose error reporting if not NULL.
2348 sfc_flow_spec_filters_complete(struct sfc_adapter *sa,
2349 struct sfc_flow_spec *spec,
2350 struct rte_flow_error *error)
2352 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2353 struct sfc_filter *filter = &sa->filter;
2354 efx_filter_match_flags_t miss_flags;
2355 efx_filter_match_flags_t min_miss_flags = 0;
2356 efx_filter_match_flags_t match;
2357 unsigned int min_multiplier = UINT_MAX;
2358 unsigned int multiplier;
2362 match = spec_filter->template.efs_match_flags;
2363 for (i = 0; i < filter->supported_match_num; i++) {
2364 if ((match & filter->supported_match[i]) == match) {
2365 miss_flags = filter->supported_match[i] & (~match);
2366 multiplier = sfc_flow_check_missing_flags(miss_flags,
2367 &spec_filter->template, filter);
2368 if (multiplier > 0) {
2369 if (multiplier <= min_multiplier) {
2370 min_multiplier = multiplier;
2371 min_miss_flags = miss_flags;
2377 if (min_multiplier == UINT_MAX) {
2378 rte_flow_error_set(error, ENOTSUP,
2379 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2380 "The flow rule pattern is unsupported");
2384 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
2385 efx_filter_match_flags_t flag = sfc_flow_copy_flags[i].flag;
2387 if ((flag & min_miss_flags) == flag) {
2388 rc = sfc_flow_spec_add_match_flag(spec, flag, error);
2398 * Check that set of match flags is referred to by a filter. Filter is
2399 * described by match flags with the ability to add OUTER_VID and INNER_VID
2402 * @param match_flags[in]
2403 * Set of match flags.
2404 * @param flags_pattern[in]
2405 * Pattern of filter match flags.
2408 sfc_flow_is_match_with_vids(efx_filter_match_flags_t match_flags,
2409 efx_filter_match_flags_t flags_pattern)
2411 if ((match_flags & flags_pattern) != flags_pattern)
2414 switch (match_flags & ~flags_pattern) {
2416 case EFX_FILTER_MATCH_OUTER_VID:
2417 case EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_INNER_VID:
2425 * Check whether the spec maps to a hardware filter which is known to be
2426 * ineffective despite being valid.
2429 * SFC filter with list of supported filters.
2431 * SFC flow specification.
2434 sfc_flow_is_match_flags_exception(struct sfc_filter *filter,
2435 struct sfc_flow_spec *spec)
2438 uint16_t ether_type;
2440 efx_filter_match_flags_t match_flags;
2441 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2443 for (i = 0; i < spec_filter->count; i++) {
2444 match_flags = spec_filter->filters[i].efs_match_flags;
2446 if (sfc_flow_is_match_with_vids(match_flags,
2447 EFX_FILTER_MATCH_ETHER_TYPE) ||
2448 sfc_flow_is_match_with_vids(match_flags,
2449 EFX_FILTER_MATCH_ETHER_TYPE |
2450 EFX_FILTER_MATCH_LOC_MAC)) {
2451 ether_type = spec_filter->filters[i].efs_ether_type;
2452 if (filter->supports_ip_proto_or_addr_filter &&
2453 (ether_type == EFX_ETHER_TYPE_IPV4 ||
2454 ether_type == EFX_ETHER_TYPE_IPV6))
2456 } else if (sfc_flow_is_match_with_vids(match_flags,
2457 EFX_FILTER_MATCH_ETHER_TYPE |
2458 EFX_FILTER_MATCH_IP_PROTO) ||
2459 sfc_flow_is_match_with_vids(match_flags,
2460 EFX_FILTER_MATCH_ETHER_TYPE |
2461 EFX_FILTER_MATCH_IP_PROTO |
2462 EFX_FILTER_MATCH_LOC_MAC)) {
2463 ip_proto = spec_filter->filters[i].efs_ip_proto;
2464 if (filter->supports_rem_or_local_port_filter &&
2465 (ip_proto == EFX_IPPROTO_TCP ||
2466 ip_proto == EFX_IPPROTO_UDP))
2475 sfc_flow_validate_match_flags(struct sfc_adapter *sa,
2476 struct rte_flow *flow,
2477 struct rte_flow_error *error)
2479 struct sfc_flow_spec *spec = &flow->spec;
2480 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2481 efx_filter_spec_t *spec_tmpl = &spec_filter->template;
2482 efx_filter_match_flags_t match_flags = spec_tmpl->efs_match_flags;
2485 /* Initialize the first filter spec with template */
2486 spec_filter->filters[0] = *spec_tmpl;
2487 spec_filter->count = 1;
2489 if (!sfc_filter_is_match_supported(sa, match_flags)) {
2490 rc = sfc_flow_spec_filters_complete(sa, &flow->spec, error);
2495 if (sfc_flow_is_match_flags_exception(&sa->filter, &flow->spec)) {
2496 rte_flow_error_set(error, ENOTSUP,
2497 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2498 "The flow rule pattern is unsupported");
2506 sfc_flow_parse_rte_to_filter(struct rte_eth_dev *dev,
2507 const struct rte_flow_item pattern[],
2508 const struct rte_flow_action actions[],
2509 struct rte_flow *flow,
2510 struct rte_flow_error *error)
2512 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2513 struct sfc_flow_spec *spec = &flow->spec;
2514 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2515 struct sfc_flow_parse_ctx ctx;
2518 ctx.type = SFC_FLOW_PARSE_CTX_FILTER;
2519 ctx.filter = &spec_filter->template;
2521 rc = sfc_flow_parse_pattern(sa, sfc_flow_items, RTE_DIM(sfc_flow_items),
2522 pattern, &ctx, error);
2524 goto fail_bad_value;
2526 rc = sfc_flow_parse_actions(sa, actions, flow, error);
2528 goto fail_bad_value;
2530 rc = sfc_flow_validate_match_flags(sa, flow, error);
2532 goto fail_bad_value;
2541 sfc_flow_parse_rte_to_mae(struct rte_eth_dev *dev,
2542 const struct rte_flow_item pattern[],
2543 const struct rte_flow_action actions[],
2544 struct rte_flow *flow,
2545 struct rte_flow_error *error)
2547 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2548 struct sfc_flow_spec *spec = &flow->spec;
2549 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
2553 * If the flow is meant to be a JUMP rule in tunnel offload,
2554 * preparse its actions and save its properties in spec_mae.
2556 rc = sfc_flow_tunnel_detect_jump_rule(sa, actions, spec_mae, error);
2560 rc = sfc_mae_rule_parse_pattern(sa, pattern, spec_mae, error);
2564 if (spec_mae->ft_rule_type == SFC_FT_RULE_JUMP) {
2566 * By design, this flow should be represented solely by the
2567 * outer rule. But the HW/FW hasn't got support for setting
2568 * Rx mark from RECIRC_ID on outer rule lookup yet. Neither
2569 * does it support outer rule counters. As a workaround, an
2570 * action rule of lower priority is used to do the job.
2572 * So don't skip sfc_mae_rule_parse_actions() below.
2576 rc = sfc_mae_rule_parse_actions(sa, actions, spec_mae, error);
2580 if (spec_mae->ft != NULL) {
2581 if (spec_mae->ft_rule_type == SFC_FT_RULE_JUMP)
2582 spec_mae->ft->jump_rule_is_set = B_TRUE;
2584 ++(spec_mae->ft->refcnt);
2590 /* Reset these values to avoid confusing sfc_mae_flow_cleanup(). */
2591 spec_mae->ft_rule_type = SFC_FT_RULE_NONE;
2592 spec_mae->ft = NULL;
2598 sfc_flow_parse(struct rte_eth_dev *dev,
2599 const struct rte_flow_attr *attr,
2600 const struct rte_flow_item pattern[],
2601 const struct rte_flow_action actions[],
2602 struct rte_flow *flow,
2603 struct rte_flow_error *error)
2605 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2606 const struct sfc_flow_ops_by_spec *ops;
2609 rc = sfc_flow_parse_attr(sa, attr, flow, error);
2613 ops = sfc_flow_get_ops_by_spec(flow);
2614 if (ops == NULL || ops->parse == NULL) {
2615 rte_flow_error_set(error, ENOTSUP,
2616 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2617 "No backend to handle this flow");
2621 return ops->parse(dev, pattern, actions, flow, error);
2624 static struct rte_flow *
2625 sfc_flow_zmalloc(struct rte_flow_error *error)
2627 struct rte_flow *flow;
2629 flow = rte_zmalloc("sfc_rte_flow", sizeof(*flow), 0);
2631 rte_flow_error_set(error, ENOMEM,
2632 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2633 "Failed to allocate memory");
2640 sfc_flow_free(struct sfc_adapter *sa, struct rte_flow *flow)
2642 const struct sfc_flow_ops_by_spec *ops;
2644 ops = sfc_flow_get_ops_by_spec(flow);
2645 if (ops != NULL && ops->cleanup != NULL)
2646 ops->cleanup(sa, flow);
2652 sfc_flow_insert(struct sfc_adapter *sa, struct rte_flow *flow,
2653 struct rte_flow_error *error)
2655 const struct sfc_flow_ops_by_spec *ops;
2658 ops = sfc_flow_get_ops_by_spec(flow);
2659 if (ops == NULL || ops->insert == NULL) {
2660 rte_flow_error_set(error, ENOTSUP,
2661 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2662 "No backend to handle this flow");
2666 rc = ops->insert(sa, flow);
2668 rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2669 NULL, "Failed to insert the flow rule");
2676 sfc_flow_remove(struct sfc_adapter *sa, struct rte_flow *flow,
2677 struct rte_flow_error *error)
2679 const struct sfc_flow_ops_by_spec *ops;
2682 ops = sfc_flow_get_ops_by_spec(flow);
2683 if (ops == NULL || ops->remove == NULL) {
2684 rte_flow_error_set(error, ENOTSUP,
2685 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2686 "No backend to handle this flow");
2690 rc = ops->remove(sa, flow);
2692 rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2693 NULL, "Failed to remove the flow rule");
2700 sfc_flow_verify(struct sfc_adapter *sa, struct rte_flow *flow,
2701 struct rte_flow_error *error)
2703 const struct sfc_flow_ops_by_spec *ops;
2706 ops = sfc_flow_get_ops_by_spec(flow);
2708 rte_flow_error_set(error, ENOTSUP,
2709 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2710 "No backend to handle this flow");
2714 if (ops->verify != NULL) {
2715 SFC_ASSERT(sfc_adapter_is_locked(sa));
2716 rc = ops->verify(sa, flow);
2720 rte_flow_error_set(error, rc,
2721 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2722 "Failed to verify flow validity with FW");
2730 sfc_flow_validate(struct rte_eth_dev *dev,
2731 const struct rte_flow_attr *attr,
2732 const struct rte_flow_item pattern[],
2733 const struct rte_flow_action actions[],
2734 struct rte_flow_error *error)
2736 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2737 struct rte_flow *flow;
2740 flow = sfc_flow_zmalloc(error);
2744 sfc_adapter_lock(sa);
2746 rc = sfc_flow_parse(dev, attr, pattern, actions, flow, error);
2748 rc = sfc_flow_verify(sa, flow, error);
2750 sfc_flow_free(sa, flow);
2752 sfc_adapter_unlock(sa);
2757 static struct rte_flow *
2758 sfc_flow_create(struct rte_eth_dev *dev,
2759 const struct rte_flow_attr *attr,
2760 const struct rte_flow_item pattern[],
2761 const struct rte_flow_action actions[],
2762 struct rte_flow_error *error)
2764 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2765 struct rte_flow *flow = NULL;
2768 flow = sfc_flow_zmalloc(error);
2772 sfc_adapter_lock(sa);
2774 rc = sfc_flow_parse(dev, attr, pattern, actions, flow, error);
2776 goto fail_bad_value;
2778 TAILQ_INSERT_TAIL(&sa->flow_list, flow, entries);
2780 if (sa->state == SFC_ETHDEV_STARTED) {
2781 rc = sfc_flow_insert(sa, flow, error);
2783 goto fail_flow_insert;
2786 sfc_adapter_unlock(sa);
2791 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2794 sfc_flow_free(sa, flow);
2795 sfc_adapter_unlock(sa);
2802 sfc_flow_destroy(struct rte_eth_dev *dev,
2803 struct rte_flow *flow,
2804 struct rte_flow_error *error)
2806 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2807 struct rte_flow *flow_ptr;
2810 sfc_adapter_lock(sa);
2812 TAILQ_FOREACH(flow_ptr, &sa->flow_list, entries) {
2813 if (flow_ptr == flow)
2817 rte_flow_error_set(error, rc,
2818 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
2819 "Failed to find flow rule to destroy");
2820 goto fail_bad_value;
2823 if (sa->state == SFC_ETHDEV_STARTED)
2824 rc = sfc_flow_remove(sa, flow, error);
2826 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2827 sfc_flow_free(sa, flow);
2830 sfc_adapter_unlock(sa);
2836 sfc_flow_flush(struct rte_eth_dev *dev,
2837 struct rte_flow_error *error)
2839 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2840 struct rte_flow *flow;
2843 sfc_adapter_lock(sa);
2845 while ((flow = TAILQ_FIRST(&sa->flow_list)) != NULL) {
2846 if (sa->state == SFC_ETHDEV_STARTED) {
2849 rc = sfc_flow_remove(sa, flow, error);
2854 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2855 sfc_flow_free(sa, flow);
2858 sfc_adapter_unlock(sa);
2864 sfc_flow_query(struct rte_eth_dev *dev,
2865 struct rte_flow *flow,
2866 const struct rte_flow_action *action,
2868 struct rte_flow_error *error)
2870 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2871 const struct sfc_flow_ops_by_spec *ops;
2874 sfc_adapter_lock(sa);
2876 ops = sfc_flow_get_ops_by_spec(flow);
2877 if (ops == NULL || ops->query == NULL) {
2878 ret = rte_flow_error_set(error, ENOTSUP,
2879 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2880 "No backend to handle this flow");
2881 goto fail_no_backend;
2884 if (sa->state != SFC_ETHDEV_STARTED) {
2885 ret = rte_flow_error_set(error, EINVAL,
2886 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2887 "Can't query the flow: the adapter is not started");
2888 goto fail_not_started;
2891 ret = ops->query(dev, flow, action, data, error);
2895 sfc_adapter_unlock(sa);
2902 sfc_adapter_unlock(sa);
2907 sfc_flow_isolate(struct rte_eth_dev *dev, int enable,
2908 struct rte_flow_error *error)
2910 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2913 sfc_adapter_lock(sa);
2914 if (sa->state != SFC_ETHDEV_INITIALIZED) {
2915 rte_flow_error_set(error, EBUSY,
2916 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2917 NULL, "please close the port first");
2920 sfc_sa2shared(sa)->isolated = (enable) ? B_TRUE : B_FALSE;
2922 sfc_adapter_unlock(sa);
2927 const struct rte_flow_ops sfc_flow_ops = {
2928 .validate = sfc_flow_validate,
2929 .create = sfc_flow_create,
2930 .destroy = sfc_flow_destroy,
2931 .flush = sfc_flow_flush,
2932 .query = sfc_flow_query,
2933 .isolate = sfc_flow_isolate,
2934 .tunnel_decap_set = sfc_flow_tunnel_decap_set,
2935 .tunnel_match = sfc_flow_tunnel_match,
2936 .tunnel_action_decap_release = sfc_flow_tunnel_action_decap_release,
2937 .tunnel_item_release = sfc_flow_tunnel_item_release,
2938 .get_restore_info = sfc_flow_tunnel_get_restore_info,
2942 sfc_flow_init(struct sfc_adapter *sa)
2944 SFC_ASSERT(sfc_adapter_is_locked(sa));
2946 TAILQ_INIT(&sa->flow_list);
2950 sfc_flow_fini(struct sfc_adapter *sa)
2952 struct rte_flow *flow;
2954 SFC_ASSERT(sfc_adapter_is_locked(sa));
2956 while ((flow = TAILQ_FIRST(&sa->flow_list)) != NULL) {
2957 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2958 sfc_flow_free(sa, flow);
2963 sfc_flow_stop(struct sfc_adapter *sa)
2965 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
2966 struct sfc_rss *rss = &sas->rss;
2967 struct rte_flow *flow;
2969 SFC_ASSERT(sfc_adapter_is_locked(sa));
2971 TAILQ_FOREACH(flow, &sa->flow_list, entries)
2972 sfc_flow_remove(sa, flow, NULL);
2974 if (rss->dummy_rss_context != EFX_RSS_CONTEXT_DEFAULT) {
2975 efx_rx_scale_context_free(sa->nic, rss->dummy_rss_context);
2976 rss->dummy_rss_context = EFX_RSS_CONTEXT_DEFAULT;
2980 * MAE counter service is not stopped on flow rule remove to avoid
2981 * extra work. Make sure that it is stopped here.
2983 sfc_mae_counter_stop(sa);
2987 sfc_flow_start(struct sfc_adapter *sa)
2989 struct rte_flow *flow;
2992 sfc_log_init(sa, "entry");
2994 SFC_ASSERT(sfc_adapter_is_locked(sa));
2996 sfc_flow_tunnel_reset_hit_counters(sa);
2998 TAILQ_FOREACH(flow, &sa->flow_list, entries) {
2999 rc = sfc_flow_insert(sa, flow, NULL);
3004 sfc_log_init(sa, "done");