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"
29 #include "sfc_switch.h"
31 struct sfc_flow_ops_by_spec {
32 sfc_flow_parse_cb_t *parse;
33 sfc_flow_verify_cb_t *verify;
34 sfc_flow_cleanup_cb_t *cleanup;
35 sfc_flow_insert_cb_t *insert;
36 sfc_flow_remove_cb_t *remove;
37 sfc_flow_query_cb_t *query;
40 static sfc_flow_parse_cb_t sfc_flow_parse_rte_to_filter;
41 static sfc_flow_parse_cb_t sfc_flow_parse_rte_to_mae;
42 static sfc_flow_insert_cb_t sfc_flow_filter_insert;
43 static sfc_flow_remove_cb_t sfc_flow_filter_remove;
45 static const struct sfc_flow_ops_by_spec sfc_flow_ops_filter = {
46 .parse = sfc_flow_parse_rte_to_filter,
49 .insert = sfc_flow_filter_insert,
50 .remove = sfc_flow_filter_remove,
54 static const struct sfc_flow_ops_by_spec sfc_flow_ops_mae = {
55 .parse = sfc_flow_parse_rte_to_mae,
56 .verify = sfc_mae_flow_verify,
57 .cleanup = sfc_mae_flow_cleanup,
58 .insert = sfc_mae_flow_insert,
59 .remove = sfc_mae_flow_remove,
60 .query = sfc_mae_flow_query,
63 static const struct sfc_flow_ops_by_spec *
64 sfc_flow_get_ops_by_spec(struct rte_flow *flow)
66 struct sfc_flow_spec *spec = &flow->spec;
67 const struct sfc_flow_ops_by_spec *ops = NULL;
70 case SFC_FLOW_SPEC_FILTER:
71 ops = &sfc_flow_ops_filter;
73 case SFC_FLOW_SPEC_MAE:
74 ops = &sfc_flow_ops_mae;
85 * Currently, filter-based (VNIC) flow API is implemented in such a manner
86 * that each flow rule is converted to one or more hardware filters.
87 * All elements of flow rule (attributes, pattern items, actions)
88 * correspond to one or more fields in the efx_filter_spec_s structure
89 * that is responsible for the hardware filter.
90 * If some required field is unset in the flow rule, then a handful
91 * of filter copies will be created to cover all possible values
95 static sfc_flow_item_parse sfc_flow_parse_void;
96 static sfc_flow_item_parse sfc_flow_parse_eth;
97 static sfc_flow_item_parse sfc_flow_parse_vlan;
98 static sfc_flow_item_parse sfc_flow_parse_ipv4;
99 static sfc_flow_item_parse sfc_flow_parse_ipv6;
100 static sfc_flow_item_parse sfc_flow_parse_tcp;
101 static sfc_flow_item_parse sfc_flow_parse_udp;
102 static sfc_flow_item_parse sfc_flow_parse_vxlan;
103 static sfc_flow_item_parse sfc_flow_parse_geneve;
104 static sfc_flow_item_parse sfc_flow_parse_nvgre;
105 static sfc_flow_item_parse sfc_flow_parse_pppoex;
107 typedef int (sfc_flow_spec_set_vals)(struct sfc_flow_spec *spec,
108 unsigned int filters_count_for_one_val,
109 struct rte_flow_error *error);
111 typedef boolean_t (sfc_flow_spec_check)(efx_filter_match_flags_t match,
112 efx_filter_spec_t *spec,
113 struct sfc_filter *filter);
115 struct sfc_flow_copy_flag {
116 /* EFX filter specification match flag */
117 efx_filter_match_flags_t flag;
118 /* Number of values of corresponding field */
119 unsigned int vals_count;
120 /* Function to set values in specifications */
121 sfc_flow_spec_set_vals *set_vals;
123 * Function to check that the specification is suitable
124 * for adding this match flag
126 sfc_flow_spec_check *spec_check;
129 static sfc_flow_spec_set_vals sfc_flow_set_unknown_dst_flags;
130 static sfc_flow_spec_check sfc_flow_check_unknown_dst_flags;
131 static sfc_flow_spec_set_vals sfc_flow_set_ethertypes;
132 static sfc_flow_spec_set_vals sfc_flow_set_ifrm_unknown_dst_flags;
133 static sfc_flow_spec_check sfc_flow_check_ifrm_unknown_dst_flags;
134 static sfc_flow_spec_set_vals sfc_flow_set_outer_vid_flag;
135 static sfc_flow_spec_check sfc_flow_check_outer_vid_flag;
138 sfc_flow_is_zero(const uint8_t *buf, unsigned int size)
143 for (i = 0; i < size; i++)
146 return (sum == 0) ? B_TRUE : B_FALSE;
150 * Validate item and prepare structures spec and mask for parsing
153 sfc_flow_parse_init(const struct rte_flow_item *item,
154 const void **spec_ptr,
155 const void **mask_ptr,
156 const void *supp_mask,
157 const void *def_mask,
159 struct rte_flow_error *error)
168 rte_flow_error_set(error, EINVAL,
169 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
174 if ((item->last != NULL || item->mask != NULL) && item->spec == NULL) {
175 rte_flow_error_set(error, EINVAL,
176 RTE_FLOW_ERROR_TYPE_ITEM, item,
177 "Mask or last is set without spec");
182 * If "mask" is not set, default mask is used,
183 * but if default mask is NULL, "mask" should be set
185 if (item->mask == NULL) {
186 if (def_mask == NULL) {
187 rte_flow_error_set(error, EINVAL,
188 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
189 "Mask should be specified");
205 * If field values in "last" are either 0 or equal to the corresponding
206 * values in "spec" then they are ignored
209 !sfc_flow_is_zero(last, size) &&
210 memcmp(last, spec, size) != 0) {
211 rte_flow_error_set(error, ENOTSUP,
212 RTE_FLOW_ERROR_TYPE_ITEM, item,
213 "Ranging is not supported");
217 if (supp_mask == NULL) {
218 rte_flow_error_set(error, EINVAL,
219 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
220 "Supported mask for item should be specified");
224 /* Check that mask does not ask for more match than supp_mask */
225 for (i = 0; i < size; i++) {
226 supp = ((const uint8_t *)supp_mask)[i];
228 if (~supp & mask[i]) {
229 rte_flow_error_set(error, ENOTSUP,
230 RTE_FLOW_ERROR_TYPE_ITEM, item,
231 "Item's field is not supported");
244 * Masking is not supported, so masks in items should be either
245 * full or empty (zeroed) and set only for supported fields which
246 * are specified in the supp_mask.
250 sfc_flow_parse_void(__rte_unused const struct rte_flow_item *item,
251 __rte_unused struct sfc_flow_parse_ctx *parse_ctx,
252 __rte_unused struct rte_flow_error *error)
258 * Convert Ethernet item to EFX filter specification.
261 * Item specification. Outer frame specification may only comprise
262 * source/destination addresses and Ethertype field.
263 * Inner frame specification may contain destination address only.
264 * There is support for individual/group mask as well as for empty and full.
265 * If the mask is NULL, default mask will be used. Ranging is not supported.
266 * @param efx_spec[in, out]
267 * EFX filter specification to update.
269 * Perform verbose error reporting if not NULL.
272 sfc_flow_parse_eth(const struct rte_flow_item *item,
273 struct sfc_flow_parse_ctx *parse_ctx,
274 struct rte_flow_error *error)
277 efx_filter_spec_t *efx_spec = parse_ctx->filter;
278 const struct rte_flow_item_eth *spec = NULL;
279 const struct rte_flow_item_eth *mask = NULL;
280 const struct rte_flow_item_eth supp_mask = {
281 .dst.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
282 .src.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
285 const struct rte_flow_item_eth ifrm_supp_mask = {
286 .dst.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
288 const uint8_t ig_mask[EFX_MAC_ADDR_LEN] = {
289 0x01, 0x00, 0x00, 0x00, 0x00, 0x00
291 const struct rte_flow_item_eth *supp_mask_p;
292 const struct rte_flow_item_eth *def_mask_p;
293 uint8_t *loc_mac = NULL;
294 boolean_t is_ifrm = (efx_spec->efs_encap_type !=
295 EFX_TUNNEL_PROTOCOL_NONE);
298 supp_mask_p = &ifrm_supp_mask;
299 def_mask_p = &ifrm_supp_mask;
300 loc_mac = efx_spec->efs_ifrm_loc_mac;
302 supp_mask_p = &supp_mask;
303 def_mask_p = &rte_flow_item_eth_mask;
304 loc_mac = efx_spec->efs_loc_mac;
307 rc = sfc_flow_parse_init(item,
308 (const void **)&spec,
309 (const void **)&mask,
310 supp_mask_p, def_mask_p,
311 sizeof(struct rte_flow_item_eth),
316 /* If "spec" is not set, could be any Ethernet */
320 if (rte_is_same_ether_addr(&mask->dst, &supp_mask.dst)) {
321 efx_spec->efs_match_flags |= is_ifrm ?
322 EFX_FILTER_MATCH_IFRM_LOC_MAC :
323 EFX_FILTER_MATCH_LOC_MAC;
324 rte_memcpy(loc_mac, spec->dst.addr_bytes,
326 } else if (memcmp(mask->dst.addr_bytes, ig_mask,
327 EFX_MAC_ADDR_LEN) == 0) {
328 if (rte_is_unicast_ether_addr(&spec->dst))
329 efx_spec->efs_match_flags |= is_ifrm ?
330 EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST :
331 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST;
333 efx_spec->efs_match_flags |= is_ifrm ?
334 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST :
335 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST;
336 } else if (!rte_is_zero_ether_addr(&mask->dst)) {
341 * ifrm_supp_mask ensures that the source address and
342 * ethertype masks are equal to zero in inner frame,
343 * so these fields are filled in only for the outer frame
345 if (rte_is_same_ether_addr(&mask->src, &supp_mask.src)) {
346 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_MAC;
347 rte_memcpy(efx_spec->efs_rem_mac, spec->src.addr_bytes,
349 } else if (!rte_is_zero_ether_addr(&mask->src)) {
354 * Ether type is in big-endian byte order in item and
355 * in little-endian in efx_spec, so byte swap is used
357 if (mask->type == supp_mask.type) {
358 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
359 efx_spec->efs_ether_type = rte_bswap16(spec->type);
360 } else if (mask->type != 0) {
367 rte_flow_error_set(error, EINVAL,
368 RTE_FLOW_ERROR_TYPE_ITEM, item,
369 "Bad mask in the ETH pattern item");
374 * Convert VLAN item to EFX filter specification.
377 * Item specification. Only VID field is supported.
378 * The mask can not be NULL. Ranging is not supported.
379 * @param efx_spec[in, out]
380 * EFX filter specification to update.
382 * Perform verbose error reporting if not NULL.
385 sfc_flow_parse_vlan(const struct rte_flow_item *item,
386 struct sfc_flow_parse_ctx *parse_ctx,
387 struct rte_flow_error *error)
391 efx_filter_spec_t *efx_spec = parse_ctx->filter;
392 const struct rte_flow_item_vlan *spec = NULL;
393 const struct rte_flow_item_vlan *mask = NULL;
394 const struct rte_flow_item_vlan supp_mask = {
395 .tci = rte_cpu_to_be_16(ETH_VLAN_ID_MAX),
396 .inner_type = RTE_BE16(0xffff),
399 rc = sfc_flow_parse_init(item,
400 (const void **)&spec,
401 (const void **)&mask,
404 sizeof(struct rte_flow_item_vlan),
410 * VID is in big-endian byte order in item and
411 * in little-endian in efx_spec, so byte swap is used.
412 * If two VLAN items are included, the first matches
413 * the outer tag and the next matches the inner tag.
415 if (mask->tci == supp_mask.tci) {
416 /* Apply mask to keep VID only */
417 vid = rte_bswap16(spec->tci & mask->tci);
419 if (!(efx_spec->efs_match_flags &
420 EFX_FILTER_MATCH_OUTER_VID)) {
421 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_OUTER_VID;
422 efx_spec->efs_outer_vid = vid;
423 } else if (!(efx_spec->efs_match_flags &
424 EFX_FILTER_MATCH_INNER_VID)) {
425 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_INNER_VID;
426 efx_spec->efs_inner_vid = vid;
428 rte_flow_error_set(error, EINVAL,
429 RTE_FLOW_ERROR_TYPE_ITEM, item,
430 "More than two VLAN items");
434 rte_flow_error_set(error, EINVAL,
435 RTE_FLOW_ERROR_TYPE_ITEM, item,
436 "VLAN ID in TCI match is required");
440 if (efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE) {
441 rte_flow_error_set(error, EINVAL,
442 RTE_FLOW_ERROR_TYPE_ITEM, item,
443 "VLAN TPID matching is not supported");
446 if (mask->inner_type == supp_mask.inner_type) {
447 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
448 efx_spec->efs_ether_type = rte_bswap16(spec->inner_type);
449 } else if (mask->inner_type) {
450 rte_flow_error_set(error, EINVAL,
451 RTE_FLOW_ERROR_TYPE_ITEM, item,
452 "Bad mask for VLAN inner_type");
460 * Convert IPv4 item to EFX filter specification.
463 * Item specification. Only source and destination addresses and
464 * protocol fields are supported. If the mask is NULL, default
465 * mask will be used. Ranging is not supported.
466 * @param efx_spec[in, out]
467 * EFX filter specification to update.
469 * Perform verbose error reporting if not NULL.
472 sfc_flow_parse_ipv4(const struct rte_flow_item *item,
473 struct sfc_flow_parse_ctx *parse_ctx,
474 struct rte_flow_error *error)
477 efx_filter_spec_t *efx_spec = parse_ctx->filter;
478 const struct rte_flow_item_ipv4 *spec = NULL;
479 const struct rte_flow_item_ipv4 *mask = NULL;
480 const uint16_t ether_type_ipv4 = rte_cpu_to_le_16(EFX_ETHER_TYPE_IPV4);
481 const struct rte_flow_item_ipv4 supp_mask = {
483 .src_addr = 0xffffffff,
484 .dst_addr = 0xffffffff,
485 .next_proto_id = 0xff,
489 rc = sfc_flow_parse_init(item,
490 (const void **)&spec,
491 (const void **)&mask,
493 &rte_flow_item_ipv4_mask,
494 sizeof(struct rte_flow_item_ipv4),
500 * Filtering by IPv4 source and destination addresses requires
501 * the appropriate ETHER_TYPE in hardware filters
503 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE)) {
504 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
505 efx_spec->efs_ether_type = ether_type_ipv4;
506 } else if (efx_spec->efs_ether_type != ether_type_ipv4) {
507 rte_flow_error_set(error, EINVAL,
508 RTE_FLOW_ERROR_TYPE_ITEM, item,
509 "Ethertype in pattern with IPV4 item should be appropriate");
517 * IPv4 addresses are in big-endian byte order in item and in
520 if (mask->hdr.src_addr == supp_mask.hdr.src_addr) {
521 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_HOST;
522 efx_spec->efs_rem_host.eo_u32[0] = spec->hdr.src_addr;
523 } else if (mask->hdr.src_addr != 0) {
527 if (mask->hdr.dst_addr == supp_mask.hdr.dst_addr) {
528 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_HOST;
529 efx_spec->efs_loc_host.eo_u32[0] = spec->hdr.dst_addr;
530 } else if (mask->hdr.dst_addr != 0) {
534 if (mask->hdr.next_proto_id == supp_mask.hdr.next_proto_id) {
535 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
536 efx_spec->efs_ip_proto = spec->hdr.next_proto_id;
537 } else if (mask->hdr.next_proto_id != 0) {
544 rte_flow_error_set(error, EINVAL,
545 RTE_FLOW_ERROR_TYPE_ITEM, item,
546 "Bad mask in the IPV4 pattern item");
551 * Convert IPv6 item to EFX filter specification.
554 * Item specification. Only source and destination addresses and
555 * next header fields are supported. If the mask is NULL, default
556 * mask will be used. Ranging is not supported.
557 * @param efx_spec[in, out]
558 * EFX filter specification to update.
560 * Perform verbose error reporting if not NULL.
563 sfc_flow_parse_ipv6(const struct rte_flow_item *item,
564 struct sfc_flow_parse_ctx *parse_ctx,
565 struct rte_flow_error *error)
568 efx_filter_spec_t *efx_spec = parse_ctx->filter;
569 const struct rte_flow_item_ipv6 *spec = NULL;
570 const struct rte_flow_item_ipv6 *mask = NULL;
571 const uint16_t ether_type_ipv6 = rte_cpu_to_le_16(EFX_ETHER_TYPE_IPV6);
572 const struct rte_flow_item_ipv6 supp_mask = {
574 .src_addr = { 0xff, 0xff, 0xff, 0xff,
575 0xff, 0xff, 0xff, 0xff,
576 0xff, 0xff, 0xff, 0xff,
577 0xff, 0xff, 0xff, 0xff },
578 .dst_addr = { 0xff, 0xff, 0xff, 0xff,
579 0xff, 0xff, 0xff, 0xff,
580 0xff, 0xff, 0xff, 0xff,
581 0xff, 0xff, 0xff, 0xff },
586 rc = sfc_flow_parse_init(item,
587 (const void **)&spec,
588 (const void **)&mask,
590 &rte_flow_item_ipv6_mask,
591 sizeof(struct rte_flow_item_ipv6),
597 * Filtering by IPv6 source and destination addresses requires
598 * the appropriate ETHER_TYPE in hardware filters
600 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE)) {
601 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
602 efx_spec->efs_ether_type = ether_type_ipv6;
603 } else if (efx_spec->efs_ether_type != ether_type_ipv6) {
604 rte_flow_error_set(error, EINVAL,
605 RTE_FLOW_ERROR_TYPE_ITEM, item,
606 "Ethertype in pattern with IPV6 item should be appropriate");
614 * IPv6 addresses are in big-endian byte order in item and in
617 if (memcmp(mask->hdr.src_addr, supp_mask.hdr.src_addr,
618 sizeof(mask->hdr.src_addr)) == 0) {
619 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_HOST;
621 RTE_BUILD_BUG_ON(sizeof(efx_spec->efs_rem_host) !=
622 sizeof(spec->hdr.src_addr));
623 rte_memcpy(&efx_spec->efs_rem_host, spec->hdr.src_addr,
624 sizeof(efx_spec->efs_rem_host));
625 } else if (!sfc_flow_is_zero(mask->hdr.src_addr,
626 sizeof(mask->hdr.src_addr))) {
630 if (memcmp(mask->hdr.dst_addr, supp_mask.hdr.dst_addr,
631 sizeof(mask->hdr.dst_addr)) == 0) {
632 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_HOST;
634 RTE_BUILD_BUG_ON(sizeof(efx_spec->efs_loc_host) !=
635 sizeof(spec->hdr.dst_addr));
636 rte_memcpy(&efx_spec->efs_loc_host, spec->hdr.dst_addr,
637 sizeof(efx_spec->efs_loc_host));
638 } else if (!sfc_flow_is_zero(mask->hdr.dst_addr,
639 sizeof(mask->hdr.dst_addr))) {
643 if (mask->hdr.proto == supp_mask.hdr.proto) {
644 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
645 efx_spec->efs_ip_proto = spec->hdr.proto;
646 } else if (mask->hdr.proto != 0) {
653 rte_flow_error_set(error, EINVAL,
654 RTE_FLOW_ERROR_TYPE_ITEM, item,
655 "Bad mask in the IPV6 pattern item");
660 * Convert TCP item to EFX filter specification.
663 * Item specification. Only source and destination ports fields
664 * are supported. If the mask is NULL, default mask will be used.
665 * Ranging is not supported.
666 * @param efx_spec[in, out]
667 * EFX filter specification to update.
669 * Perform verbose error reporting if not NULL.
672 sfc_flow_parse_tcp(const struct rte_flow_item *item,
673 struct sfc_flow_parse_ctx *parse_ctx,
674 struct rte_flow_error *error)
677 efx_filter_spec_t *efx_spec = parse_ctx->filter;
678 const struct rte_flow_item_tcp *spec = NULL;
679 const struct rte_flow_item_tcp *mask = NULL;
680 const struct rte_flow_item_tcp supp_mask = {
687 rc = sfc_flow_parse_init(item,
688 (const void **)&spec,
689 (const void **)&mask,
691 &rte_flow_item_tcp_mask,
692 sizeof(struct rte_flow_item_tcp),
698 * Filtering by TCP source and destination ports requires
699 * the appropriate IP_PROTO in hardware filters
701 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_IP_PROTO)) {
702 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
703 efx_spec->efs_ip_proto = EFX_IPPROTO_TCP;
704 } else if (efx_spec->efs_ip_proto != EFX_IPPROTO_TCP) {
705 rte_flow_error_set(error, EINVAL,
706 RTE_FLOW_ERROR_TYPE_ITEM, item,
707 "IP proto in pattern with TCP item should be appropriate");
715 * Source and destination ports are in big-endian byte order in item and
716 * in little-endian in efx_spec, so byte swap is used
718 if (mask->hdr.src_port == supp_mask.hdr.src_port) {
719 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_PORT;
720 efx_spec->efs_rem_port = rte_bswap16(spec->hdr.src_port);
721 } else if (mask->hdr.src_port != 0) {
725 if (mask->hdr.dst_port == supp_mask.hdr.dst_port) {
726 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_PORT;
727 efx_spec->efs_loc_port = rte_bswap16(spec->hdr.dst_port);
728 } else if (mask->hdr.dst_port != 0) {
735 rte_flow_error_set(error, EINVAL,
736 RTE_FLOW_ERROR_TYPE_ITEM, item,
737 "Bad mask in the TCP pattern item");
742 * Convert UDP item to EFX filter specification.
745 * Item specification. Only source and destination ports fields
746 * are supported. If the mask is NULL, default mask will be used.
747 * Ranging is not supported.
748 * @param efx_spec[in, out]
749 * EFX filter specification to update.
751 * Perform verbose error reporting if not NULL.
754 sfc_flow_parse_udp(const struct rte_flow_item *item,
755 struct sfc_flow_parse_ctx *parse_ctx,
756 struct rte_flow_error *error)
759 efx_filter_spec_t *efx_spec = parse_ctx->filter;
760 const struct rte_flow_item_udp *spec = NULL;
761 const struct rte_flow_item_udp *mask = NULL;
762 const struct rte_flow_item_udp supp_mask = {
769 rc = sfc_flow_parse_init(item,
770 (const void **)&spec,
771 (const void **)&mask,
773 &rte_flow_item_udp_mask,
774 sizeof(struct rte_flow_item_udp),
780 * Filtering by UDP source and destination ports requires
781 * the appropriate IP_PROTO in hardware filters
783 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_IP_PROTO)) {
784 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
785 efx_spec->efs_ip_proto = EFX_IPPROTO_UDP;
786 } else if (efx_spec->efs_ip_proto != EFX_IPPROTO_UDP) {
787 rte_flow_error_set(error, EINVAL,
788 RTE_FLOW_ERROR_TYPE_ITEM, item,
789 "IP proto in pattern with UDP item should be appropriate");
797 * Source and destination ports are in big-endian byte order in item and
798 * in little-endian in efx_spec, so byte swap is used
800 if (mask->hdr.src_port == supp_mask.hdr.src_port) {
801 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_PORT;
802 efx_spec->efs_rem_port = rte_bswap16(spec->hdr.src_port);
803 } else if (mask->hdr.src_port != 0) {
807 if (mask->hdr.dst_port == supp_mask.hdr.dst_port) {
808 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_PORT;
809 efx_spec->efs_loc_port = rte_bswap16(spec->hdr.dst_port);
810 } else if (mask->hdr.dst_port != 0) {
817 rte_flow_error_set(error, EINVAL,
818 RTE_FLOW_ERROR_TYPE_ITEM, item,
819 "Bad mask in the UDP pattern item");
824 * Filters for encapsulated packets match based on the EtherType and IP
825 * protocol in the outer frame.
828 sfc_flow_set_match_flags_for_encap_pkts(const struct rte_flow_item *item,
829 efx_filter_spec_t *efx_spec,
831 struct rte_flow_error *error)
833 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_IP_PROTO)) {
834 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
835 efx_spec->efs_ip_proto = ip_proto;
836 } else if (efx_spec->efs_ip_proto != ip_proto) {
838 case EFX_IPPROTO_UDP:
839 rte_flow_error_set(error, EINVAL,
840 RTE_FLOW_ERROR_TYPE_ITEM, item,
841 "Outer IP header protocol must be UDP "
842 "in VxLAN/GENEVE pattern");
845 case EFX_IPPROTO_GRE:
846 rte_flow_error_set(error, EINVAL,
847 RTE_FLOW_ERROR_TYPE_ITEM, item,
848 "Outer IP header protocol must be GRE "
853 rte_flow_error_set(error, EINVAL,
854 RTE_FLOW_ERROR_TYPE_ITEM, item,
855 "Only VxLAN/GENEVE/NVGRE tunneling patterns "
861 if (efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
862 efx_spec->efs_ether_type != EFX_ETHER_TYPE_IPV4 &&
863 efx_spec->efs_ether_type != EFX_ETHER_TYPE_IPV6) {
864 rte_flow_error_set(error, EINVAL,
865 RTE_FLOW_ERROR_TYPE_ITEM, item,
866 "Outer frame EtherType in pattern with tunneling "
867 "must be IPv4 or IPv6");
875 sfc_flow_set_efx_spec_vni_or_vsid(efx_filter_spec_t *efx_spec,
876 const uint8_t *vni_or_vsid_val,
877 const uint8_t *vni_or_vsid_mask,
878 const struct rte_flow_item *item,
879 struct rte_flow_error *error)
881 const uint8_t vni_or_vsid_full_mask[EFX_VNI_OR_VSID_LEN] = {
885 if (memcmp(vni_or_vsid_mask, vni_or_vsid_full_mask,
886 EFX_VNI_OR_VSID_LEN) == 0) {
887 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_VNI_OR_VSID;
888 rte_memcpy(efx_spec->efs_vni_or_vsid, vni_or_vsid_val,
889 EFX_VNI_OR_VSID_LEN);
890 } else if (!sfc_flow_is_zero(vni_or_vsid_mask, EFX_VNI_OR_VSID_LEN)) {
891 rte_flow_error_set(error, EINVAL,
892 RTE_FLOW_ERROR_TYPE_ITEM, item,
893 "Unsupported VNI/VSID mask");
901 * Convert VXLAN item to EFX filter specification.
904 * Item specification. Only VXLAN network identifier field is supported.
905 * If the mask is NULL, default mask will be used.
906 * Ranging is not supported.
907 * @param efx_spec[in, out]
908 * EFX filter specification to update.
910 * Perform verbose error reporting if not NULL.
913 sfc_flow_parse_vxlan(const struct rte_flow_item *item,
914 struct sfc_flow_parse_ctx *parse_ctx,
915 struct rte_flow_error *error)
918 efx_filter_spec_t *efx_spec = parse_ctx->filter;
919 const struct rte_flow_item_vxlan *spec = NULL;
920 const struct rte_flow_item_vxlan *mask = NULL;
921 const struct rte_flow_item_vxlan supp_mask = {
922 .vni = { 0xff, 0xff, 0xff }
925 rc = sfc_flow_parse_init(item,
926 (const void **)&spec,
927 (const void **)&mask,
929 &rte_flow_item_vxlan_mask,
930 sizeof(struct rte_flow_item_vxlan),
935 rc = sfc_flow_set_match_flags_for_encap_pkts(item, efx_spec,
936 EFX_IPPROTO_UDP, error);
940 efx_spec->efs_encap_type = EFX_TUNNEL_PROTOCOL_VXLAN;
941 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
946 rc = sfc_flow_set_efx_spec_vni_or_vsid(efx_spec, spec->vni,
947 mask->vni, item, error);
953 * Convert GENEVE item to EFX filter specification.
956 * Item specification. Only Virtual Network Identifier and protocol type
957 * fields are supported. But protocol type can be only Ethernet (0x6558).
958 * If the mask is NULL, default mask will be used.
959 * Ranging is not supported.
960 * @param efx_spec[in, out]
961 * EFX filter specification to update.
963 * Perform verbose error reporting if not NULL.
966 sfc_flow_parse_geneve(const struct rte_flow_item *item,
967 struct sfc_flow_parse_ctx *parse_ctx,
968 struct rte_flow_error *error)
971 efx_filter_spec_t *efx_spec = parse_ctx->filter;
972 const struct rte_flow_item_geneve *spec = NULL;
973 const struct rte_flow_item_geneve *mask = NULL;
974 const struct rte_flow_item_geneve supp_mask = {
975 .protocol = RTE_BE16(0xffff),
976 .vni = { 0xff, 0xff, 0xff }
979 rc = sfc_flow_parse_init(item,
980 (const void **)&spec,
981 (const void **)&mask,
983 &rte_flow_item_geneve_mask,
984 sizeof(struct rte_flow_item_geneve),
989 rc = sfc_flow_set_match_flags_for_encap_pkts(item, efx_spec,
990 EFX_IPPROTO_UDP, error);
994 efx_spec->efs_encap_type = EFX_TUNNEL_PROTOCOL_GENEVE;
995 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
1000 if (mask->protocol == supp_mask.protocol) {
1001 if (spec->protocol != rte_cpu_to_be_16(RTE_ETHER_TYPE_TEB)) {
1002 rte_flow_error_set(error, EINVAL,
1003 RTE_FLOW_ERROR_TYPE_ITEM, item,
1004 "GENEVE encap. protocol must be Ethernet "
1005 "(0x6558) in the GENEVE pattern item");
1008 } else if (mask->protocol != 0) {
1009 rte_flow_error_set(error, EINVAL,
1010 RTE_FLOW_ERROR_TYPE_ITEM, item,
1011 "Unsupported mask for GENEVE encap. protocol");
1015 rc = sfc_flow_set_efx_spec_vni_or_vsid(efx_spec, spec->vni,
1016 mask->vni, item, error);
1022 * Convert NVGRE item to EFX filter specification.
1025 * Item specification. Only virtual subnet ID field is supported.
1026 * If the mask is NULL, default mask will be used.
1027 * Ranging is not supported.
1028 * @param efx_spec[in, out]
1029 * EFX filter specification to update.
1031 * Perform verbose error reporting if not NULL.
1034 sfc_flow_parse_nvgre(const struct rte_flow_item *item,
1035 struct sfc_flow_parse_ctx *parse_ctx,
1036 struct rte_flow_error *error)
1039 efx_filter_spec_t *efx_spec = parse_ctx->filter;
1040 const struct rte_flow_item_nvgre *spec = NULL;
1041 const struct rte_flow_item_nvgre *mask = NULL;
1042 const struct rte_flow_item_nvgre supp_mask = {
1043 .tni = { 0xff, 0xff, 0xff }
1046 rc = sfc_flow_parse_init(item,
1047 (const void **)&spec,
1048 (const void **)&mask,
1050 &rte_flow_item_nvgre_mask,
1051 sizeof(struct rte_flow_item_nvgre),
1056 rc = sfc_flow_set_match_flags_for_encap_pkts(item, efx_spec,
1057 EFX_IPPROTO_GRE, error);
1061 efx_spec->efs_encap_type = EFX_TUNNEL_PROTOCOL_NVGRE;
1062 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
1067 rc = sfc_flow_set_efx_spec_vni_or_vsid(efx_spec, spec->tni,
1068 mask->tni, item, error);
1074 * Convert PPPoEx item to EFX filter specification.
1077 * Item specification.
1078 * Matching on PPPoEx fields is not supported.
1079 * This item can only be used to set or validate the EtherType filter.
1080 * Only zero masks are allowed.
1081 * Ranging is not supported.
1082 * @param efx_spec[in, out]
1083 * EFX filter specification to update.
1085 * Perform verbose error reporting if not NULL.
1088 sfc_flow_parse_pppoex(const struct rte_flow_item *item,
1089 struct sfc_flow_parse_ctx *parse_ctx,
1090 struct rte_flow_error *error)
1092 efx_filter_spec_t *efx_spec = parse_ctx->filter;
1093 const struct rte_flow_item_pppoe *spec = NULL;
1094 const struct rte_flow_item_pppoe *mask = NULL;
1095 const struct rte_flow_item_pppoe supp_mask = {};
1096 const struct rte_flow_item_pppoe def_mask = {};
1097 uint16_t ether_type;
1100 rc = sfc_flow_parse_init(item,
1101 (const void **)&spec,
1102 (const void **)&mask,
1105 sizeof(struct rte_flow_item_pppoe),
1110 if (item->type == RTE_FLOW_ITEM_TYPE_PPPOED)
1111 ether_type = RTE_ETHER_TYPE_PPPOE_DISCOVERY;
1113 ether_type = RTE_ETHER_TYPE_PPPOE_SESSION;
1115 if ((efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE) != 0) {
1116 if (efx_spec->efs_ether_type != ether_type) {
1117 rte_flow_error_set(error, EINVAL,
1118 RTE_FLOW_ERROR_TYPE_ITEM, item,
1119 "Invalid EtherType for a PPPoE flow item");
1123 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
1124 efx_spec->efs_ether_type = ether_type;
1130 static const struct sfc_flow_item sfc_flow_items[] = {
1132 .type = RTE_FLOW_ITEM_TYPE_VOID,
1134 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
1135 .layer = SFC_FLOW_ITEM_ANY_LAYER,
1136 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1137 .parse = sfc_flow_parse_void,
1140 .type = RTE_FLOW_ITEM_TYPE_ETH,
1142 .prev_layer = SFC_FLOW_ITEM_START_LAYER,
1143 .layer = SFC_FLOW_ITEM_L2,
1144 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1145 .parse = sfc_flow_parse_eth,
1148 .type = RTE_FLOW_ITEM_TYPE_VLAN,
1150 .prev_layer = SFC_FLOW_ITEM_L2,
1151 .layer = SFC_FLOW_ITEM_L2,
1152 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1153 .parse = sfc_flow_parse_vlan,
1156 .type = RTE_FLOW_ITEM_TYPE_PPPOED,
1158 .prev_layer = SFC_FLOW_ITEM_L2,
1159 .layer = SFC_FLOW_ITEM_L2,
1160 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1161 .parse = sfc_flow_parse_pppoex,
1164 .type = RTE_FLOW_ITEM_TYPE_PPPOES,
1166 .prev_layer = SFC_FLOW_ITEM_L2,
1167 .layer = SFC_FLOW_ITEM_L2,
1168 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1169 .parse = sfc_flow_parse_pppoex,
1172 .type = RTE_FLOW_ITEM_TYPE_IPV4,
1174 .prev_layer = SFC_FLOW_ITEM_L2,
1175 .layer = SFC_FLOW_ITEM_L3,
1176 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1177 .parse = sfc_flow_parse_ipv4,
1180 .type = RTE_FLOW_ITEM_TYPE_IPV6,
1182 .prev_layer = SFC_FLOW_ITEM_L2,
1183 .layer = SFC_FLOW_ITEM_L3,
1184 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1185 .parse = sfc_flow_parse_ipv6,
1188 .type = RTE_FLOW_ITEM_TYPE_TCP,
1190 .prev_layer = SFC_FLOW_ITEM_L3,
1191 .layer = SFC_FLOW_ITEM_L4,
1192 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1193 .parse = sfc_flow_parse_tcp,
1196 .type = RTE_FLOW_ITEM_TYPE_UDP,
1198 .prev_layer = SFC_FLOW_ITEM_L3,
1199 .layer = SFC_FLOW_ITEM_L4,
1200 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1201 .parse = sfc_flow_parse_udp,
1204 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
1206 .prev_layer = SFC_FLOW_ITEM_L4,
1207 .layer = SFC_FLOW_ITEM_START_LAYER,
1208 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1209 .parse = sfc_flow_parse_vxlan,
1212 .type = RTE_FLOW_ITEM_TYPE_GENEVE,
1214 .prev_layer = SFC_FLOW_ITEM_L4,
1215 .layer = SFC_FLOW_ITEM_START_LAYER,
1216 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1217 .parse = sfc_flow_parse_geneve,
1220 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
1222 .prev_layer = SFC_FLOW_ITEM_L3,
1223 .layer = SFC_FLOW_ITEM_START_LAYER,
1224 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1225 .parse = sfc_flow_parse_nvgre,
1230 * Protocol-independent flow API support
1233 sfc_flow_parse_attr(struct sfc_adapter *sa,
1234 const struct rte_flow_attr *attr,
1235 struct rte_flow *flow,
1236 struct rte_flow_error *error)
1238 struct sfc_flow_spec *spec = &flow->spec;
1239 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1240 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
1241 struct sfc_mae *mae = &sa->mae;
1244 rte_flow_error_set(error, EINVAL,
1245 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
1249 if (attr->group != 0) {
1250 rte_flow_error_set(error, ENOTSUP,
1251 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, attr,
1252 "Groups are not supported");
1255 if (attr->egress != 0) {
1256 rte_flow_error_set(error, ENOTSUP,
1257 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attr,
1258 "Egress is not supported");
1261 if (attr->ingress == 0) {
1262 rte_flow_error_set(error, ENOTSUP,
1263 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, attr,
1264 "Ingress is compulsory");
1267 if (attr->transfer == 0) {
1268 if (attr->priority != 0) {
1269 rte_flow_error_set(error, ENOTSUP,
1270 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1271 attr, "Priorities are unsupported");
1274 spec->type = SFC_FLOW_SPEC_FILTER;
1275 spec_filter->template.efs_flags |= EFX_FILTER_FLAG_RX;
1276 spec_filter->template.efs_rss_context = EFX_RSS_CONTEXT_DEFAULT;
1277 spec_filter->template.efs_priority = EFX_FILTER_PRI_MANUAL;
1279 if (mae->status != SFC_MAE_STATUS_ADMIN) {
1280 rte_flow_error_set(error, ENOTSUP,
1281 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1282 attr, "Transfer is not supported");
1285 if (attr->priority > mae->nb_action_rule_prios_max) {
1286 rte_flow_error_set(error, ENOTSUP,
1287 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1288 attr, "Unsupported priority level");
1291 spec->type = SFC_FLOW_SPEC_MAE;
1292 spec_mae->priority = attr->priority;
1293 spec_mae->match_spec = NULL;
1294 spec_mae->action_set = NULL;
1295 spec_mae->rule_id.id = EFX_MAE_RSRC_ID_INVALID;
1301 /* Get item from array sfc_flow_items */
1302 static const struct sfc_flow_item *
1303 sfc_flow_get_item(const struct sfc_flow_item *items,
1304 unsigned int nb_items,
1305 enum rte_flow_item_type type)
1309 for (i = 0; i < nb_items; i++)
1310 if (items[i].type == type)
1317 sfc_flow_parse_pattern(struct sfc_adapter *sa,
1318 const struct sfc_flow_item *flow_items,
1319 unsigned int nb_flow_items,
1320 const struct rte_flow_item pattern[],
1321 struct sfc_flow_parse_ctx *parse_ctx,
1322 struct rte_flow_error *error)
1325 unsigned int prev_layer = SFC_FLOW_ITEM_ANY_LAYER;
1326 boolean_t is_ifrm = B_FALSE;
1327 const struct sfc_flow_item *item;
1329 if (pattern == NULL) {
1330 rte_flow_error_set(error, EINVAL,
1331 RTE_FLOW_ERROR_TYPE_ITEM_NUM, NULL,
1336 for (; pattern->type != RTE_FLOW_ITEM_TYPE_END; pattern++) {
1337 item = sfc_flow_get_item(flow_items, nb_flow_items,
1340 rte_flow_error_set(error, ENOTSUP,
1341 RTE_FLOW_ERROR_TYPE_ITEM, pattern,
1342 "Unsupported pattern item");
1347 * Omitting one or several protocol layers at the beginning
1348 * of pattern is supported
1350 if (item->prev_layer != SFC_FLOW_ITEM_ANY_LAYER &&
1351 prev_layer != SFC_FLOW_ITEM_ANY_LAYER &&
1352 item->prev_layer != prev_layer) {
1353 rte_flow_error_set(error, ENOTSUP,
1354 RTE_FLOW_ERROR_TYPE_ITEM, pattern,
1355 "Unexpected sequence of pattern items");
1360 * Allow only VOID and ETH pattern items in the inner frame.
1361 * Also check that there is only one tunneling protocol.
1363 switch (item->type) {
1364 case RTE_FLOW_ITEM_TYPE_VOID:
1365 case RTE_FLOW_ITEM_TYPE_ETH:
1368 case RTE_FLOW_ITEM_TYPE_VXLAN:
1369 case RTE_FLOW_ITEM_TYPE_GENEVE:
1370 case RTE_FLOW_ITEM_TYPE_NVGRE:
1372 rte_flow_error_set(error, EINVAL,
1373 RTE_FLOW_ERROR_TYPE_ITEM,
1375 "More than one tunneling protocol");
1382 if (parse_ctx->type == SFC_FLOW_PARSE_CTX_FILTER &&
1384 rte_flow_error_set(error, EINVAL,
1385 RTE_FLOW_ERROR_TYPE_ITEM,
1387 "There is an unsupported pattern item "
1388 "in the inner frame");
1394 if (parse_ctx->type != item->ctx_type) {
1395 rte_flow_error_set(error, EINVAL,
1396 RTE_FLOW_ERROR_TYPE_ITEM, pattern,
1397 "Parse context type mismatch");
1401 rc = item->parse(pattern, parse_ctx, error);
1403 sfc_err(sa, "failed to parse item %s: %s",
1404 item->name, strerror(-rc));
1408 if (item->layer != SFC_FLOW_ITEM_ANY_LAYER)
1409 prev_layer = item->layer;
1416 sfc_flow_parse_queue(struct sfc_adapter *sa,
1417 const struct rte_flow_action_queue *queue,
1418 struct rte_flow *flow)
1420 struct sfc_flow_spec *spec = &flow->spec;
1421 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1422 struct sfc_rxq *rxq;
1423 struct sfc_rxq_info *rxq_info;
1425 if (queue->index >= sfc_sa2shared(sa)->ethdev_rxq_count)
1428 rxq = sfc_rxq_ctrl_by_ethdev_qid(sa, queue->index);
1429 spec_filter->template.efs_dmaq_id = (uint16_t)rxq->hw_index;
1431 rxq_info = &sfc_sa2shared(sa)->rxq_info[queue->index];
1432 spec_filter->rss_hash_required = !!(rxq_info->rxq_flags &
1433 SFC_RXQ_FLAG_RSS_HASH);
1439 sfc_flow_parse_rss(struct sfc_adapter *sa,
1440 const struct rte_flow_action_rss *action_rss,
1441 struct rte_flow *flow)
1443 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
1444 struct sfc_rss *rss = &sas->rss;
1445 sfc_ethdev_qid_t ethdev_qid;
1446 struct sfc_rxq *rxq;
1447 unsigned int rxq_hw_index_min;
1448 unsigned int rxq_hw_index_max;
1449 efx_rx_hash_type_t efx_hash_types;
1450 const uint8_t *rss_key;
1451 struct sfc_flow_spec *spec = &flow->spec;
1452 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1453 struct sfc_flow_rss *sfc_rss_conf = &spec_filter->rss_conf;
1456 if (action_rss->queue_num == 0)
1459 ethdev_qid = sfc_sa2shared(sa)->ethdev_rxq_count - 1;
1460 rxq = sfc_rxq_ctrl_by_ethdev_qid(sa, ethdev_qid);
1461 rxq_hw_index_min = rxq->hw_index;
1462 rxq_hw_index_max = 0;
1464 for (i = 0; i < action_rss->queue_num; ++i) {
1465 ethdev_qid = action_rss->queue[i];
1467 if ((unsigned int)ethdev_qid >=
1468 sfc_sa2shared(sa)->ethdev_rxq_count)
1471 rxq = sfc_rxq_ctrl_by_ethdev_qid(sa, ethdev_qid);
1473 if (rxq->hw_index < rxq_hw_index_min)
1474 rxq_hw_index_min = rxq->hw_index;
1476 if (rxq->hw_index > rxq_hw_index_max)
1477 rxq_hw_index_max = rxq->hw_index;
1480 switch (action_rss->func) {
1481 case RTE_ETH_HASH_FUNCTION_DEFAULT:
1482 case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
1488 if (action_rss->level)
1492 * Dummy RSS action with only one queue and no specific settings
1493 * for hash types and key does not require dedicated RSS context
1494 * and may be simplified to single queue action.
1496 if (action_rss->queue_num == 1 && action_rss->types == 0 &&
1497 action_rss->key_len == 0) {
1498 spec_filter->template.efs_dmaq_id = rxq_hw_index_min;
1502 if (action_rss->types) {
1505 rc = sfc_rx_hf_rte_to_efx(sa, action_rss->types,
1513 for (i = 0; i < rss->hf_map_nb_entries; ++i)
1514 efx_hash_types |= rss->hf_map[i].efx;
1517 if (action_rss->key_len) {
1518 if (action_rss->key_len != sizeof(rss->key))
1521 rss_key = action_rss->key;
1526 spec_filter->rss = B_TRUE;
1528 sfc_rss_conf->rxq_hw_index_min = rxq_hw_index_min;
1529 sfc_rss_conf->rxq_hw_index_max = rxq_hw_index_max;
1530 sfc_rss_conf->rss_hash_types = efx_hash_types;
1531 rte_memcpy(sfc_rss_conf->rss_key, rss_key, sizeof(rss->key));
1533 for (i = 0; i < RTE_DIM(sfc_rss_conf->rss_tbl); ++i) {
1534 unsigned int nb_queues = action_rss->queue_num;
1535 struct sfc_rxq *rxq;
1537 ethdev_qid = action_rss->queue[i % nb_queues];
1538 rxq = sfc_rxq_ctrl_by_ethdev_qid(sa, ethdev_qid);
1539 sfc_rss_conf->rss_tbl[i] = rxq->hw_index - rxq_hw_index_min;
1546 sfc_flow_spec_flush(struct sfc_adapter *sa, struct sfc_flow_spec *spec,
1547 unsigned int filters_count)
1549 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1553 for (i = 0; i < filters_count; i++) {
1556 rc = efx_filter_remove(sa->nic, &spec_filter->filters[i]);
1557 if (ret == 0 && rc != 0) {
1558 sfc_err(sa, "failed to remove filter specification "
1568 sfc_flow_spec_insert(struct sfc_adapter *sa, struct sfc_flow_spec *spec)
1570 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1574 for (i = 0; i < spec_filter->count; i++) {
1575 rc = efx_filter_insert(sa->nic, &spec_filter->filters[i]);
1577 sfc_flow_spec_flush(sa, spec, i);
1586 sfc_flow_spec_remove(struct sfc_adapter *sa, struct sfc_flow_spec *spec)
1588 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1590 return sfc_flow_spec_flush(sa, spec, spec_filter->count);
1594 sfc_flow_filter_insert(struct sfc_adapter *sa,
1595 struct rte_flow *flow)
1597 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
1598 struct sfc_rss *rss = &sas->rss;
1599 struct sfc_flow_spec_filter *spec_filter = &flow->spec.filter;
1600 struct sfc_flow_rss *flow_rss = &spec_filter->rss_conf;
1601 uint32_t efs_rss_context = EFX_RSS_CONTEXT_DEFAULT;
1602 boolean_t create_context;
1606 create_context = spec_filter->rss || (spec_filter->rss_hash_required &&
1607 rss->dummy_rss_context == EFX_RSS_CONTEXT_DEFAULT);
1609 if (create_context) {
1610 unsigned int rss_spread;
1611 unsigned int rss_hash_types;
1614 if (spec_filter->rss) {
1615 rss_spread = MIN(flow_rss->rxq_hw_index_max -
1616 flow_rss->rxq_hw_index_min + 1,
1618 rss_hash_types = flow_rss->rss_hash_types;
1619 rss_key = flow_rss->rss_key;
1622 * Initialize dummy RSS context parameters to have
1623 * valid RSS hash. Use default RSS hash function and
1627 rss_hash_types = rss->hash_types;
1631 rc = efx_rx_scale_context_alloc(sa->nic,
1632 EFX_RX_SCALE_EXCLUSIVE,
1636 goto fail_scale_context_alloc;
1638 rc = efx_rx_scale_mode_set(sa->nic, efs_rss_context,
1640 rss_hash_types, B_TRUE);
1642 goto fail_scale_mode_set;
1644 rc = efx_rx_scale_key_set(sa->nic, efs_rss_context,
1645 rss_key, sizeof(rss->key));
1647 goto fail_scale_key_set;
1649 efs_rss_context = rss->dummy_rss_context;
1652 if (spec_filter->rss || spec_filter->rss_hash_required) {
1654 * At this point, fully elaborated filter specifications
1655 * have been produced from the template. To make sure that
1656 * RSS behaviour is consistent between them, set the same
1657 * RSS context value everywhere.
1659 for (i = 0; i < spec_filter->count; i++) {
1660 efx_filter_spec_t *spec = &spec_filter->filters[i];
1662 spec->efs_rss_context = efs_rss_context;
1663 spec->efs_flags |= EFX_FILTER_FLAG_RX_RSS;
1664 if (spec_filter->rss)
1665 spec->efs_dmaq_id = flow_rss->rxq_hw_index_min;
1669 rc = sfc_flow_spec_insert(sa, &flow->spec);
1671 goto fail_filter_insert;
1673 if (create_context) {
1674 unsigned int dummy_tbl[RTE_DIM(flow_rss->rss_tbl)] = {0};
1677 tbl = spec_filter->rss ? flow_rss->rss_tbl : dummy_tbl;
1680 * Scale table is set after filter insertion because
1681 * the table entries are relative to the base RxQ ID
1682 * and the latter is submitted to the HW by means of
1683 * inserting a filter, so by the time of the request
1684 * the HW knows all the information needed to verify
1685 * the table entries, and the operation will succeed
1687 rc = efx_rx_scale_tbl_set(sa->nic, efs_rss_context,
1688 tbl, RTE_DIM(flow_rss->rss_tbl));
1690 goto fail_scale_tbl_set;
1692 /* Remember created dummy RSS context */
1693 if (!spec_filter->rss)
1694 rss->dummy_rss_context = efs_rss_context;
1700 sfc_flow_spec_remove(sa, &flow->spec);
1704 fail_scale_mode_set:
1706 efx_rx_scale_context_free(sa->nic, efs_rss_context);
1708 fail_scale_context_alloc:
1713 sfc_flow_filter_remove(struct sfc_adapter *sa,
1714 struct rte_flow *flow)
1716 struct sfc_flow_spec_filter *spec_filter = &flow->spec.filter;
1719 rc = sfc_flow_spec_remove(sa, &flow->spec);
1723 if (spec_filter->rss) {
1725 * All specifications for a given flow rule have the same RSS
1726 * context, so that RSS context value is taken from the first
1727 * filter specification
1729 efx_filter_spec_t *spec = &spec_filter->filters[0];
1731 rc = efx_rx_scale_context_free(sa->nic, spec->efs_rss_context);
1738 sfc_flow_parse_mark(struct sfc_adapter *sa,
1739 const struct rte_flow_action_mark *mark,
1740 struct rte_flow *flow)
1742 struct sfc_flow_spec *spec = &flow->spec;
1743 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1744 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
1747 mark_max = encp->enc_filter_action_mark_max;
1748 if (sfc_flow_tunnel_is_active(sa))
1749 mark_max = RTE_MIN(mark_max, SFC_FT_USER_MARK_MASK);
1751 if (mark == NULL || mark->id > mark_max)
1754 spec_filter->template.efs_flags |= EFX_FILTER_FLAG_ACTION_MARK;
1755 spec_filter->template.efs_mark = mark->id;
1761 sfc_flow_parse_actions(struct sfc_adapter *sa,
1762 const struct rte_flow_action actions[],
1763 struct rte_flow *flow,
1764 struct rte_flow_error *error)
1767 struct sfc_flow_spec *spec = &flow->spec;
1768 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1769 const unsigned int dp_rx_features = sa->priv.dp_rx->features;
1770 const uint64_t rx_metadata = sa->negotiated_rx_metadata;
1771 uint32_t actions_set = 0;
1772 const uint32_t fate_actions_mask = (1UL << RTE_FLOW_ACTION_TYPE_QUEUE) |
1773 (1UL << RTE_FLOW_ACTION_TYPE_RSS) |
1774 (1UL << RTE_FLOW_ACTION_TYPE_DROP);
1775 const uint32_t mark_actions_mask = (1UL << RTE_FLOW_ACTION_TYPE_MARK) |
1776 (1UL << RTE_FLOW_ACTION_TYPE_FLAG);
1778 if (actions == NULL) {
1779 rte_flow_error_set(error, EINVAL,
1780 RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
1785 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1786 switch (actions->type) {
1787 case RTE_FLOW_ACTION_TYPE_VOID:
1788 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VOID,
1792 case RTE_FLOW_ACTION_TYPE_QUEUE:
1793 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_QUEUE,
1795 if ((actions_set & fate_actions_mask) != 0)
1796 goto fail_fate_actions;
1798 rc = sfc_flow_parse_queue(sa, actions->conf, flow);
1800 rte_flow_error_set(error, EINVAL,
1801 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1802 "Bad QUEUE action");
1807 case RTE_FLOW_ACTION_TYPE_RSS:
1808 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_RSS,
1810 if ((actions_set & fate_actions_mask) != 0)
1811 goto fail_fate_actions;
1813 rc = sfc_flow_parse_rss(sa, actions->conf, flow);
1815 rte_flow_error_set(error, -rc,
1816 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1822 case RTE_FLOW_ACTION_TYPE_DROP:
1823 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_DROP,
1825 if ((actions_set & fate_actions_mask) != 0)
1826 goto fail_fate_actions;
1828 spec_filter->template.efs_dmaq_id =
1829 EFX_FILTER_SPEC_RX_DMAQ_ID_DROP;
1832 case RTE_FLOW_ACTION_TYPE_FLAG:
1833 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_FLAG,
1835 if ((actions_set & mark_actions_mask) != 0)
1836 goto fail_actions_overlap;
1838 if ((dp_rx_features & SFC_DP_RX_FEAT_FLOW_FLAG) == 0) {
1839 rte_flow_error_set(error, ENOTSUP,
1840 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1841 "FLAG action is not supported on the current Rx datapath");
1843 } else if ((rx_metadata &
1844 RTE_ETH_RX_METADATA_USER_FLAG) == 0) {
1845 rte_flow_error_set(error, ENOTSUP,
1846 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1847 "flag delivery has not been negotiated");
1851 spec_filter->template.efs_flags |=
1852 EFX_FILTER_FLAG_ACTION_FLAG;
1855 case RTE_FLOW_ACTION_TYPE_MARK:
1856 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_MARK,
1858 if ((actions_set & mark_actions_mask) != 0)
1859 goto fail_actions_overlap;
1861 if ((dp_rx_features & SFC_DP_RX_FEAT_FLOW_MARK) == 0) {
1862 rte_flow_error_set(error, ENOTSUP,
1863 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1864 "MARK action is not supported on the current Rx datapath");
1866 } else if ((rx_metadata &
1867 RTE_ETH_RX_METADATA_USER_MARK) == 0) {
1868 rte_flow_error_set(error, ENOTSUP,
1869 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1870 "mark delivery has not been negotiated");
1874 rc = sfc_flow_parse_mark(sa, actions->conf, flow);
1876 rte_flow_error_set(error, rc,
1877 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1884 rte_flow_error_set(error, ENOTSUP,
1885 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1886 "Action is not supported");
1890 actions_set |= (1UL << actions->type);
1893 /* When fate is unknown, drop traffic. */
1894 if ((actions_set & fate_actions_mask) == 0) {
1895 spec_filter->template.efs_dmaq_id =
1896 EFX_FILTER_SPEC_RX_DMAQ_ID_DROP;
1902 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, actions,
1903 "Cannot combine several fate-deciding actions, "
1904 "choose between QUEUE, RSS or DROP");
1907 fail_actions_overlap:
1908 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, actions,
1909 "Overlapping actions are not supported");
1914 * Set the EFX_FILTER_MATCH_UNKNOWN_UCAST_DST
1915 * and EFX_FILTER_MATCH_UNKNOWN_MCAST_DST match flags in the same
1916 * specifications after copying.
1918 * @param spec[in, out]
1919 * SFC flow specification to update.
1920 * @param filters_count_for_one_val[in]
1921 * How many specifications should have the same match flag, what is the
1922 * number of specifications before copying.
1924 * Perform verbose error reporting if not NULL.
1927 sfc_flow_set_unknown_dst_flags(struct sfc_flow_spec *spec,
1928 unsigned int filters_count_for_one_val,
1929 struct rte_flow_error *error)
1932 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1933 static const efx_filter_match_flags_t vals[] = {
1934 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST,
1935 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST
1938 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
1939 rte_flow_error_set(error, EINVAL,
1940 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1941 "Number of specifications is incorrect while copying "
1942 "by unknown destination flags");
1946 for (i = 0; i < spec_filter->count; i++) {
1947 /* The check above ensures that divisor can't be zero here */
1948 spec_filter->filters[i].efs_match_flags |=
1949 vals[i / filters_count_for_one_val];
1956 * Check that the following conditions are met:
1957 * - the list of supported filters has a filter
1958 * with EFX_FILTER_MATCH_UNKNOWN_MCAST_DST flag instead of
1959 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST, since this filter will also
1963 * The match flags of filter.
1965 * Specification to be supplemented.
1967 * SFC filter with list of supported filters.
1970 sfc_flow_check_unknown_dst_flags(efx_filter_match_flags_t match,
1971 __rte_unused efx_filter_spec_t *spec,
1972 struct sfc_filter *filter)
1975 efx_filter_match_flags_t match_mcast_dst;
1978 (match & ~EFX_FILTER_MATCH_UNKNOWN_UCAST_DST) |
1979 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST;
1980 for (i = 0; i < filter->supported_match_num; i++) {
1981 if (match_mcast_dst == filter->supported_match[i])
1989 * Set the EFX_FILTER_MATCH_ETHER_TYPE match flag and EFX_ETHER_TYPE_IPV4 and
1990 * EFX_ETHER_TYPE_IPV6 values of the corresponding field in the same
1991 * specifications after copying.
1993 * @param spec[in, out]
1994 * SFC flow specification to update.
1995 * @param filters_count_for_one_val[in]
1996 * How many specifications should have the same EtherType value, what is the
1997 * number of specifications before copying.
1999 * Perform verbose error reporting if not NULL.
2002 sfc_flow_set_ethertypes(struct sfc_flow_spec *spec,
2003 unsigned int filters_count_for_one_val,
2004 struct rte_flow_error *error)
2007 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2008 static const uint16_t vals[] = {
2009 EFX_ETHER_TYPE_IPV4, EFX_ETHER_TYPE_IPV6
2012 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
2013 rte_flow_error_set(error, EINVAL,
2014 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2015 "Number of specifications is incorrect "
2016 "while copying by Ethertype");
2020 for (i = 0; i < spec_filter->count; i++) {
2021 spec_filter->filters[i].efs_match_flags |=
2022 EFX_FILTER_MATCH_ETHER_TYPE;
2025 * The check above ensures that
2026 * filters_count_for_one_val is not 0
2028 spec_filter->filters[i].efs_ether_type =
2029 vals[i / filters_count_for_one_val];
2036 * Set the EFX_FILTER_MATCH_OUTER_VID match flag with value 0
2037 * in the same specifications after copying.
2039 * @param spec[in, out]
2040 * SFC flow specification to update.
2041 * @param filters_count_for_one_val[in]
2042 * How many specifications should have the same match flag, what is the
2043 * number of specifications before copying.
2045 * Perform verbose error reporting if not NULL.
2048 sfc_flow_set_outer_vid_flag(struct sfc_flow_spec *spec,
2049 unsigned int filters_count_for_one_val,
2050 struct rte_flow_error *error)
2052 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2055 if (filters_count_for_one_val != spec_filter->count) {
2056 rte_flow_error_set(error, EINVAL,
2057 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2058 "Number of specifications is incorrect "
2059 "while copying by outer VLAN ID");
2063 for (i = 0; i < spec_filter->count; i++) {
2064 spec_filter->filters[i].efs_match_flags |=
2065 EFX_FILTER_MATCH_OUTER_VID;
2067 spec_filter->filters[i].efs_outer_vid = 0;
2074 * Set the EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST and
2075 * EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST match flags in the same
2076 * specifications after copying.
2078 * @param spec[in, out]
2079 * SFC flow specification to update.
2080 * @param filters_count_for_one_val[in]
2081 * How many specifications should have the same match flag, what is the
2082 * number of specifications before copying.
2084 * Perform verbose error reporting if not NULL.
2087 sfc_flow_set_ifrm_unknown_dst_flags(struct sfc_flow_spec *spec,
2088 unsigned int filters_count_for_one_val,
2089 struct rte_flow_error *error)
2092 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2093 static const efx_filter_match_flags_t vals[] = {
2094 EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST,
2095 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST
2098 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
2099 rte_flow_error_set(error, EINVAL,
2100 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2101 "Number of specifications is incorrect while copying "
2102 "by inner frame unknown destination flags");
2106 for (i = 0; i < spec_filter->count; i++) {
2107 /* The check above ensures that divisor can't be zero here */
2108 spec_filter->filters[i].efs_match_flags |=
2109 vals[i / filters_count_for_one_val];
2116 * Check that the following conditions are met:
2117 * - the specification corresponds to a filter for encapsulated traffic
2118 * - the list of supported filters has a filter
2119 * with EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST flag instead of
2120 * EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST, since this filter will also
2124 * The match flags of filter.
2126 * Specification to be supplemented.
2128 * SFC filter with list of supported filters.
2131 sfc_flow_check_ifrm_unknown_dst_flags(efx_filter_match_flags_t match,
2132 efx_filter_spec_t *spec,
2133 struct sfc_filter *filter)
2136 efx_tunnel_protocol_t encap_type = spec->efs_encap_type;
2137 efx_filter_match_flags_t match_mcast_dst;
2139 if (encap_type == EFX_TUNNEL_PROTOCOL_NONE)
2143 (match & ~EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST) |
2144 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST;
2145 for (i = 0; i < filter->supported_match_num; i++) {
2146 if (match_mcast_dst == filter->supported_match[i])
2154 * Check that the list of supported filters has a filter that differs
2155 * from @p match in that it has no flag EFX_FILTER_MATCH_OUTER_VID
2156 * in this case that filter will be used and the flag
2157 * EFX_FILTER_MATCH_OUTER_VID is not needed.
2160 * The match flags of filter.
2162 * Specification to be supplemented.
2164 * SFC filter with list of supported filters.
2167 sfc_flow_check_outer_vid_flag(efx_filter_match_flags_t match,
2168 __rte_unused efx_filter_spec_t *spec,
2169 struct sfc_filter *filter)
2172 efx_filter_match_flags_t match_without_vid =
2173 match & ~EFX_FILTER_MATCH_OUTER_VID;
2175 for (i = 0; i < filter->supported_match_num; i++) {
2176 if (match_without_vid == filter->supported_match[i])
2184 * Match flags that can be automatically added to filters.
2185 * Selecting the last minimum when searching for the copy flag ensures that the
2186 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST flag has a higher priority than
2187 * EFX_FILTER_MATCH_ETHER_TYPE. This is because the filter
2188 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST is at the end of the list of supported
2191 static const struct sfc_flow_copy_flag sfc_flow_copy_flags[] = {
2193 .flag = EFX_FILTER_MATCH_UNKNOWN_UCAST_DST,
2195 .set_vals = sfc_flow_set_unknown_dst_flags,
2196 .spec_check = sfc_flow_check_unknown_dst_flags,
2199 .flag = EFX_FILTER_MATCH_ETHER_TYPE,
2201 .set_vals = sfc_flow_set_ethertypes,
2205 .flag = EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST,
2207 .set_vals = sfc_flow_set_ifrm_unknown_dst_flags,
2208 .spec_check = sfc_flow_check_ifrm_unknown_dst_flags,
2211 .flag = EFX_FILTER_MATCH_OUTER_VID,
2213 .set_vals = sfc_flow_set_outer_vid_flag,
2214 .spec_check = sfc_flow_check_outer_vid_flag,
2218 /* Get item from array sfc_flow_copy_flags */
2219 static const struct sfc_flow_copy_flag *
2220 sfc_flow_get_copy_flag(efx_filter_match_flags_t flag)
2224 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
2225 if (sfc_flow_copy_flags[i].flag == flag)
2226 return &sfc_flow_copy_flags[i];
2233 * Make copies of the specifications, set match flag and values
2234 * of the field that corresponds to it.
2236 * @param spec[in, out]
2237 * SFC flow specification to update.
2239 * The match flag to add.
2241 * Perform verbose error reporting if not NULL.
2244 sfc_flow_spec_add_match_flag(struct sfc_flow_spec *spec,
2245 efx_filter_match_flags_t flag,
2246 struct rte_flow_error *error)
2249 unsigned int new_filters_count;
2250 unsigned int filters_count_for_one_val;
2251 const struct sfc_flow_copy_flag *copy_flag;
2252 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2255 copy_flag = sfc_flow_get_copy_flag(flag);
2256 if (copy_flag == NULL) {
2257 rte_flow_error_set(error, ENOTSUP,
2258 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2259 "Unsupported spec field for copying");
2263 new_filters_count = spec_filter->count * copy_flag->vals_count;
2264 if (new_filters_count > SF_FLOW_SPEC_NB_FILTERS_MAX) {
2265 rte_flow_error_set(error, EINVAL,
2266 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2267 "Too much EFX specifications in the flow rule");
2271 /* Copy filters specifications */
2272 for (i = spec_filter->count; i < new_filters_count; i++) {
2273 spec_filter->filters[i] =
2274 spec_filter->filters[i - spec_filter->count];
2277 filters_count_for_one_val = spec_filter->count;
2278 spec_filter->count = new_filters_count;
2280 rc = copy_flag->set_vals(spec, filters_count_for_one_val, error);
2288 * Check that the given set of match flags missing in the original filter spec
2289 * could be covered by adding spec copies which specify the corresponding
2290 * flags and packet field values to match.
2292 * @param miss_flags[in]
2293 * Flags that are missing until the supported filter.
2295 * Specification to be supplemented.
2300 * Number of specifications after copy or 0, if the flags can not be added.
2303 sfc_flow_check_missing_flags(efx_filter_match_flags_t miss_flags,
2304 efx_filter_spec_t *spec,
2305 struct sfc_filter *filter)
2308 efx_filter_match_flags_t copy_flags = 0;
2309 efx_filter_match_flags_t flag;
2310 efx_filter_match_flags_t match = spec->efs_match_flags | miss_flags;
2311 sfc_flow_spec_check *check;
2312 unsigned int multiplier = 1;
2314 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
2315 flag = sfc_flow_copy_flags[i].flag;
2316 check = sfc_flow_copy_flags[i].spec_check;
2317 if ((flag & miss_flags) == flag) {
2318 if (check != NULL && (!check(match, spec, filter)))
2322 multiplier *= sfc_flow_copy_flags[i].vals_count;
2326 if (copy_flags == miss_flags)
2333 * Attempt to supplement the specification template to the minimally
2334 * supported set of match flags. To do this, it is necessary to copy
2335 * the specifications, filling them with the values of fields that
2336 * correspond to the missing flags.
2337 * The necessary and sufficient filter is built from the fewest number
2338 * of copies which could be made to cover the minimally required set
2343 * @param spec[in, out]
2344 * SFC flow specification to update.
2346 * Perform verbose error reporting if not NULL.
2349 sfc_flow_spec_filters_complete(struct sfc_adapter *sa,
2350 struct sfc_flow_spec *spec,
2351 struct rte_flow_error *error)
2353 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2354 struct sfc_filter *filter = &sa->filter;
2355 efx_filter_match_flags_t miss_flags;
2356 efx_filter_match_flags_t min_miss_flags = 0;
2357 efx_filter_match_flags_t match;
2358 unsigned int min_multiplier = UINT_MAX;
2359 unsigned int multiplier;
2363 match = spec_filter->template.efs_match_flags;
2364 for (i = 0; i < filter->supported_match_num; i++) {
2365 if ((match & filter->supported_match[i]) == match) {
2366 miss_flags = filter->supported_match[i] & (~match);
2367 multiplier = sfc_flow_check_missing_flags(miss_flags,
2368 &spec_filter->template, filter);
2369 if (multiplier > 0) {
2370 if (multiplier <= min_multiplier) {
2371 min_multiplier = multiplier;
2372 min_miss_flags = miss_flags;
2378 if (min_multiplier == UINT_MAX) {
2379 rte_flow_error_set(error, ENOTSUP,
2380 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2381 "The flow rule pattern is unsupported");
2385 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
2386 efx_filter_match_flags_t flag = sfc_flow_copy_flags[i].flag;
2388 if ((flag & min_miss_flags) == flag) {
2389 rc = sfc_flow_spec_add_match_flag(spec, flag, error);
2399 * Check that set of match flags is referred to by a filter. Filter is
2400 * described by match flags with the ability to add OUTER_VID and INNER_VID
2403 * @param match_flags[in]
2404 * Set of match flags.
2405 * @param flags_pattern[in]
2406 * Pattern of filter match flags.
2409 sfc_flow_is_match_with_vids(efx_filter_match_flags_t match_flags,
2410 efx_filter_match_flags_t flags_pattern)
2412 if ((match_flags & flags_pattern) != flags_pattern)
2415 switch (match_flags & ~flags_pattern) {
2417 case EFX_FILTER_MATCH_OUTER_VID:
2418 case EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_INNER_VID:
2426 * Check whether the spec maps to a hardware filter which is known to be
2427 * ineffective despite being valid.
2430 * SFC filter with list of supported filters.
2432 * SFC flow specification.
2435 sfc_flow_is_match_flags_exception(struct sfc_filter *filter,
2436 struct sfc_flow_spec *spec)
2439 uint16_t ether_type;
2441 efx_filter_match_flags_t match_flags;
2442 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2444 for (i = 0; i < spec_filter->count; i++) {
2445 match_flags = spec_filter->filters[i].efs_match_flags;
2447 if (sfc_flow_is_match_with_vids(match_flags,
2448 EFX_FILTER_MATCH_ETHER_TYPE) ||
2449 sfc_flow_is_match_with_vids(match_flags,
2450 EFX_FILTER_MATCH_ETHER_TYPE |
2451 EFX_FILTER_MATCH_LOC_MAC)) {
2452 ether_type = spec_filter->filters[i].efs_ether_type;
2453 if (filter->supports_ip_proto_or_addr_filter &&
2454 (ether_type == EFX_ETHER_TYPE_IPV4 ||
2455 ether_type == EFX_ETHER_TYPE_IPV6))
2457 } else if (sfc_flow_is_match_with_vids(match_flags,
2458 EFX_FILTER_MATCH_ETHER_TYPE |
2459 EFX_FILTER_MATCH_IP_PROTO) ||
2460 sfc_flow_is_match_with_vids(match_flags,
2461 EFX_FILTER_MATCH_ETHER_TYPE |
2462 EFX_FILTER_MATCH_IP_PROTO |
2463 EFX_FILTER_MATCH_LOC_MAC)) {
2464 ip_proto = spec_filter->filters[i].efs_ip_proto;
2465 if (filter->supports_rem_or_local_port_filter &&
2466 (ip_proto == EFX_IPPROTO_TCP ||
2467 ip_proto == EFX_IPPROTO_UDP))
2476 sfc_flow_validate_match_flags(struct sfc_adapter *sa,
2477 struct rte_flow *flow,
2478 struct rte_flow_error *error)
2480 struct sfc_flow_spec *spec = &flow->spec;
2481 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2482 efx_filter_spec_t *spec_tmpl = &spec_filter->template;
2483 efx_filter_match_flags_t match_flags = spec_tmpl->efs_match_flags;
2486 /* Initialize the first filter spec with template */
2487 spec_filter->filters[0] = *spec_tmpl;
2488 spec_filter->count = 1;
2490 if (!sfc_filter_is_match_supported(sa, match_flags)) {
2491 rc = sfc_flow_spec_filters_complete(sa, &flow->spec, error);
2496 if (sfc_flow_is_match_flags_exception(&sa->filter, &flow->spec)) {
2497 rte_flow_error_set(error, ENOTSUP,
2498 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2499 "The flow rule pattern is unsupported");
2507 sfc_flow_parse_rte_to_filter(struct rte_eth_dev *dev,
2508 const struct rte_flow_item pattern[],
2509 const struct rte_flow_action actions[],
2510 struct rte_flow *flow,
2511 struct rte_flow_error *error)
2513 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2514 struct sfc_flow_spec *spec = &flow->spec;
2515 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2516 struct sfc_flow_parse_ctx ctx;
2519 ctx.type = SFC_FLOW_PARSE_CTX_FILTER;
2520 ctx.filter = &spec_filter->template;
2522 rc = sfc_flow_parse_pattern(sa, sfc_flow_items, RTE_DIM(sfc_flow_items),
2523 pattern, &ctx, error);
2525 goto fail_bad_value;
2527 rc = sfc_flow_parse_actions(sa, actions, flow, error);
2529 goto fail_bad_value;
2531 rc = sfc_flow_validate_match_flags(sa, flow, error);
2533 goto fail_bad_value;
2542 sfc_flow_parse_rte_to_mae(struct rte_eth_dev *dev,
2543 const struct rte_flow_item pattern[],
2544 const struct rte_flow_action actions[],
2545 struct rte_flow *flow,
2546 struct rte_flow_error *error)
2548 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2549 struct sfc_flow_spec *spec = &flow->spec;
2550 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
2554 * If the flow is meant to be a JUMP rule in tunnel offload,
2555 * preparse its actions and save its properties in spec_mae.
2557 rc = sfc_flow_tunnel_detect_jump_rule(sa, actions, spec_mae, error);
2561 rc = sfc_mae_rule_parse_pattern(sa, pattern, spec_mae, error);
2565 if (spec_mae->ft_rule_type == SFC_FT_RULE_JUMP) {
2567 * By design, this flow should be represented solely by the
2568 * outer rule. But the HW/FW hasn't got support for setting
2569 * Rx mark from RECIRC_ID on outer rule lookup yet. Neither
2570 * does it support outer rule counters. As a workaround, an
2571 * action rule of lower priority is used to do the job.
2573 * So don't skip sfc_mae_rule_parse_actions() below.
2577 rc = sfc_mae_rule_parse_actions(sa, actions, spec_mae, error);
2581 if (spec_mae->ft != NULL) {
2582 if (spec_mae->ft_rule_type == SFC_FT_RULE_JUMP)
2583 spec_mae->ft->jump_rule_is_set = B_TRUE;
2585 ++(spec_mae->ft->refcnt);
2591 /* Reset these values to avoid confusing sfc_mae_flow_cleanup(). */
2592 spec_mae->ft_rule_type = SFC_FT_RULE_NONE;
2593 spec_mae->ft = NULL;
2599 sfc_flow_parse(struct rte_eth_dev *dev,
2600 const struct rte_flow_attr *attr,
2601 const struct rte_flow_item pattern[],
2602 const struct rte_flow_action actions[],
2603 struct rte_flow *flow,
2604 struct rte_flow_error *error)
2606 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2607 const struct sfc_flow_ops_by_spec *ops;
2610 rc = sfc_flow_parse_attr(sa, attr, flow, error);
2614 ops = sfc_flow_get_ops_by_spec(flow);
2615 if (ops == NULL || ops->parse == NULL) {
2616 rte_flow_error_set(error, ENOTSUP,
2617 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2618 "No backend to handle this flow");
2622 return ops->parse(dev, pattern, actions, flow, error);
2625 static struct rte_flow *
2626 sfc_flow_zmalloc(struct rte_flow_error *error)
2628 struct rte_flow *flow;
2630 flow = rte_zmalloc("sfc_rte_flow", sizeof(*flow), 0);
2632 rte_flow_error_set(error, ENOMEM,
2633 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2634 "Failed to allocate memory");
2641 sfc_flow_free(struct sfc_adapter *sa, struct rte_flow *flow)
2643 const struct sfc_flow_ops_by_spec *ops;
2645 ops = sfc_flow_get_ops_by_spec(flow);
2646 if (ops != NULL && ops->cleanup != NULL)
2647 ops->cleanup(sa, flow);
2653 sfc_flow_insert(struct sfc_adapter *sa, struct rte_flow *flow,
2654 struct rte_flow_error *error)
2656 const struct sfc_flow_ops_by_spec *ops;
2659 ops = sfc_flow_get_ops_by_spec(flow);
2660 if (ops == NULL || ops->insert == NULL) {
2661 rte_flow_error_set(error, ENOTSUP,
2662 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2663 "No backend to handle this flow");
2667 rc = ops->insert(sa, flow);
2669 rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2670 NULL, "Failed to insert the flow rule");
2677 sfc_flow_remove(struct sfc_adapter *sa, struct rte_flow *flow,
2678 struct rte_flow_error *error)
2680 const struct sfc_flow_ops_by_spec *ops;
2683 ops = sfc_flow_get_ops_by_spec(flow);
2684 if (ops == NULL || ops->remove == NULL) {
2685 rte_flow_error_set(error, ENOTSUP,
2686 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2687 "No backend to handle this flow");
2691 rc = ops->remove(sa, flow);
2693 rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2694 NULL, "Failed to remove the flow rule");
2701 sfc_flow_verify(struct sfc_adapter *sa, struct rte_flow *flow,
2702 struct rte_flow_error *error)
2704 const struct sfc_flow_ops_by_spec *ops;
2707 ops = sfc_flow_get_ops_by_spec(flow);
2709 rte_flow_error_set(error, ENOTSUP,
2710 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2711 "No backend to handle this flow");
2715 if (ops->verify != NULL) {
2716 SFC_ASSERT(sfc_adapter_is_locked(sa));
2717 rc = ops->verify(sa, flow);
2721 rte_flow_error_set(error, rc,
2722 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2723 "Failed to verify flow validity with FW");
2731 sfc_flow_validate(struct rte_eth_dev *dev,
2732 const struct rte_flow_attr *attr,
2733 const struct rte_flow_item pattern[],
2734 const struct rte_flow_action actions[],
2735 struct rte_flow_error *error)
2737 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2738 struct rte_flow *flow;
2741 flow = sfc_flow_zmalloc(error);
2745 sfc_adapter_lock(sa);
2747 rc = sfc_flow_parse(dev, attr, pattern, actions, flow, error);
2749 rc = sfc_flow_verify(sa, flow, error);
2751 sfc_flow_free(sa, flow);
2753 sfc_adapter_unlock(sa);
2758 static struct rte_flow *
2759 sfc_flow_create(struct rte_eth_dev *dev,
2760 const struct rte_flow_attr *attr,
2761 const struct rte_flow_item pattern[],
2762 const struct rte_flow_action actions[],
2763 struct rte_flow_error *error)
2765 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2766 struct rte_flow *flow = NULL;
2769 flow = sfc_flow_zmalloc(error);
2773 sfc_adapter_lock(sa);
2775 rc = sfc_flow_parse(dev, attr, pattern, actions, flow, error);
2777 goto fail_bad_value;
2779 TAILQ_INSERT_TAIL(&sa->flow_list, flow, entries);
2781 if (sa->state == SFC_ETHDEV_STARTED) {
2782 rc = sfc_flow_insert(sa, flow, error);
2784 goto fail_flow_insert;
2787 sfc_adapter_unlock(sa);
2792 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2795 sfc_flow_free(sa, flow);
2796 sfc_adapter_unlock(sa);
2803 sfc_flow_destroy(struct rte_eth_dev *dev,
2804 struct rte_flow *flow,
2805 struct rte_flow_error *error)
2807 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2808 struct rte_flow *flow_ptr;
2811 sfc_adapter_lock(sa);
2813 TAILQ_FOREACH(flow_ptr, &sa->flow_list, entries) {
2814 if (flow_ptr == flow)
2818 rte_flow_error_set(error, rc,
2819 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
2820 "Failed to find flow rule to destroy");
2821 goto fail_bad_value;
2824 if (sa->state == SFC_ETHDEV_STARTED)
2825 rc = sfc_flow_remove(sa, flow, error);
2827 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2828 sfc_flow_free(sa, flow);
2831 sfc_adapter_unlock(sa);
2837 sfc_flow_flush(struct rte_eth_dev *dev,
2838 struct rte_flow_error *error)
2840 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2841 struct rte_flow *flow;
2844 sfc_adapter_lock(sa);
2846 while ((flow = TAILQ_FIRST(&sa->flow_list)) != NULL) {
2847 if (sa->state == SFC_ETHDEV_STARTED) {
2850 rc = sfc_flow_remove(sa, flow, error);
2855 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2856 sfc_flow_free(sa, flow);
2859 sfc_adapter_unlock(sa);
2865 sfc_flow_query(struct rte_eth_dev *dev,
2866 struct rte_flow *flow,
2867 const struct rte_flow_action *action,
2869 struct rte_flow_error *error)
2871 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2872 const struct sfc_flow_ops_by_spec *ops;
2875 sfc_adapter_lock(sa);
2877 ops = sfc_flow_get_ops_by_spec(flow);
2878 if (ops == NULL || ops->query == NULL) {
2879 ret = rte_flow_error_set(error, ENOTSUP,
2880 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2881 "No backend to handle this flow");
2882 goto fail_no_backend;
2885 if (sa->state != SFC_ETHDEV_STARTED) {
2886 ret = rte_flow_error_set(error, EINVAL,
2887 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2888 "Can't query the flow: the adapter is not started");
2889 goto fail_not_started;
2892 ret = ops->query(dev, flow, action, data, error);
2896 sfc_adapter_unlock(sa);
2903 sfc_adapter_unlock(sa);
2908 sfc_flow_isolate(struct rte_eth_dev *dev, int enable,
2909 struct rte_flow_error *error)
2911 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2914 sfc_adapter_lock(sa);
2915 if (sa->state != SFC_ETHDEV_INITIALIZED) {
2916 rte_flow_error_set(error, EBUSY,
2917 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2918 NULL, "please close the port first");
2921 sfc_sa2shared(sa)->isolated = (enable) ? B_TRUE : B_FALSE;
2923 sfc_adapter_unlock(sa);
2929 sfc_flow_pick_transfer_proxy(struct rte_eth_dev *dev,
2930 uint16_t *transfer_proxy_port,
2931 struct rte_flow_error *error)
2933 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2936 ret = sfc_mae_get_switch_domain_admin(sa->mae.switch_domain_id,
2937 transfer_proxy_port);
2939 return rte_flow_error_set(error, ret,
2940 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2947 const struct rte_flow_ops sfc_flow_ops = {
2948 .validate = sfc_flow_validate,
2949 .create = sfc_flow_create,
2950 .destroy = sfc_flow_destroy,
2951 .flush = sfc_flow_flush,
2952 .query = sfc_flow_query,
2953 .isolate = sfc_flow_isolate,
2954 .tunnel_decap_set = sfc_flow_tunnel_decap_set,
2955 .tunnel_match = sfc_flow_tunnel_match,
2956 .tunnel_action_decap_release = sfc_flow_tunnel_action_decap_release,
2957 .tunnel_item_release = sfc_flow_tunnel_item_release,
2958 .get_restore_info = sfc_flow_tunnel_get_restore_info,
2959 .pick_transfer_proxy = sfc_flow_pick_transfer_proxy,
2963 sfc_flow_init(struct sfc_adapter *sa)
2965 SFC_ASSERT(sfc_adapter_is_locked(sa));
2967 TAILQ_INIT(&sa->flow_list);
2971 sfc_flow_fini(struct sfc_adapter *sa)
2973 struct rte_flow *flow;
2975 SFC_ASSERT(sfc_adapter_is_locked(sa));
2977 while ((flow = TAILQ_FIRST(&sa->flow_list)) != NULL) {
2978 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2979 sfc_flow_free(sa, flow);
2984 sfc_flow_stop(struct sfc_adapter *sa)
2986 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
2987 struct sfc_rss *rss = &sas->rss;
2988 struct rte_flow *flow;
2990 SFC_ASSERT(sfc_adapter_is_locked(sa));
2992 TAILQ_FOREACH(flow, &sa->flow_list, entries)
2993 sfc_flow_remove(sa, flow, NULL);
2995 if (rss->dummy_rss_context != EFX_RSS_CONTEXT_DEFAULT) {
2996 efx_rx_scale_context_free(sa->nic, rss->dummy_rss_context);
2997 rss->dummy_rss_context = EFX_RSS_CONTEXT_DEFAULT;
3001 * MAE counter service is not stopped on flow rule remove to avoid
3002 * extra work. Make sure that it is stopped here.
3004 sfc_mae_counter_stop(sa);
3008 sfc_flow_start(struct sfc_adapter *sa)
3010 struct rte_flow *flow;
3013 sfc_log_init(sa, "entry");
3015 SFC_ASSERT(sfc_adapter_is_locked(sa));
3017 sfc_flow_tunnel_reset_hit_counters(sa);
3019 TAILQ_FOREACH(flow, &sa->flow_list, entries) {
3020 rc = sfc_flow_insert(sa, flow, NULL);
3025 sfc_log_init(sa, "done");