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"
26 #include "sfc_dp_rx.h"
28 struct sfc_flow_ops_by_spec {
29 sfc_flow_parse_cb_t *parse;
30 sfc_flow_verify_cb_t *verify;
31 sfc_flow_cleanup_cb_t *cleanup;
32 sfc_flow_insert_cb_t *insert;
33 sfc_flow_remove_cb_t *remove;
36 static sfc_flow_parse_cb_t sfc_flow_parse_rte_to_filter;
37 static sfc_flow_parse_cb_t sfc_flow_parse_rte_to_mae;
38 static sfc_flow_insert_cb_t sfc_flow_filter_insert;
39 static sfc_flow_remove_cb_t sfc_flow_filter_remove;
41 static const struct sfc_flow_ops_by_spec sfc_flow_ops_filter = {
42 .parse = sfc_flow_parse_rte_to_filter,
45 .insert = sfc_flow_filter_insert,
46 .remove = sfc_flow_filter_remove,
49 static const struct sfc_flow_ops_by_spec sfc_flow_ops_mae = {
50 .parse = sfc_flow_parse_rte_to_mae,
51 .verify = sfc_mae_flow_verify,
52 .cleanup = sfc_mae_flow_cleanup,
53 .insert = sfc_mae_flow_insert,
54 .remove = sfc_mae_flow_remove,
57 static const struct sfc_flow_ops_by_spec *
58 sfc_flow_get_ops_by_spec(struct rte_flow *flow)
60 struct sfc_flow_spec *spec = &flow->spec;
61 const struct sfc_flow_ops_by_spec *ops = NULL;
64 case SFC_FLOW_SPEC_FILTER:
65 ops = &sfc_flow_ops_filter;
67 case SFC_FLOW_SPEC_MAE:
68 ops = &sfc_flow_ops_mae;
79 * Currently, filter-based (VNIC) flow API is implemented in such a manner
80 * that each flow rule is converted to one or more hardware filters.
81 * All elements of flow rule (attributes, pattern items, actions)
82 * correspond to one or more fields in the efx_filter_spec_s structure
83 * that is responsible for the hardware filter.
84 * If some required field is unset in the flow rule, then a handful
85 * of filter copies will be created to cover all possible values
89 static sfc_flow_item_parse sfc_flow_parse_void;
90 static sfc_flow_item_parse sfc_flow_parse_eth;
91 static sfc_flow_item_parse sfc_flow_parse_vlan;
92 static sfc_flow_item_parse sfc_flow_parse_ipv4;
93 static sfc_flow_item_parse sfc_flow_parse_ipv6;
94 static sfc_flow_item_parse sfc_flow_parse_tcp;
95 static sfc_flow_item_parse sfc_flow_parse_udp;
96 static sfc_flow_item_parse sfc_flow_parse_vxlan;
97 static sfc_flow_item_parse sfc_flow_parse_geneve;
98 static sfc_flow_item_parse sfc_flow_parse_nvgre;
99 static sfc_flow_item_parse sfc_flow_parse_pppoex;
101 typedef int (sfc_flow_spec_set_vals)(struct sfc_flow_spec *spec,
102 unsigned int filters_count_for_one_val,
103 struct rte_flow_error *error);
105 typedef boolean_t (sfc_flow_spec_check)(efx_filter_match_flags_t match,
106 efx_filter_spec_t *spec,
107 struct sfc_filter *filter);
109 struct sfc_flow_copy_flag {
110 /* EFX filter specification match flag */
111 efx_filter_match_flags_t flag;
112 /* Number of values of corresponding field */
113 unsigned int vals_count;
114 /* Function to set values in specifications */
115 sfc_flow_spec_set_vals *set_vals;
117 * Function to check that the specification is suitable
118 * for adding this match flag
120 sfc_flow_spec_check *spec_check;
123 static sfc_flow_spec_set_vals sfc_flow_set_unknown_dst_flags;
124 static sfc_flow_spec_check sfc_flow_check_unknown_dst_flags;
125 static sfc_flow_spec_set_vals sfc_flow_set_ethertypes;
126 static sfc_flow_spec_set_vals sfc_flow_set_ifrm_unknown_dst_flags;
127 static sfc_flow_spec_check sfc_flow_check_ifrm_unknown_dst_flags;
128 static sfc_flow_spec_set_vals sfc_flow_set_outer_vid_flag;
129 static sfc_flow_spec_check sfc_flow_check_outer_vid_flag;
132 sfc_flow_is_zero(const uint8_t *buf, unsigned int size)
137 for (i = 0; i < size; i++)
140 return (sum == 0) ? B_TRUE : B_FALSE;
144 * Validate item and prepare structures spec and mask for parsing
147 sfc_flow_parse_init(const struct rte_flow_item *item,
148 const void **spec_ptr,
149 const void **mask_ptr,
150 const void *supp_mask,
151 const void *def_mask,
153 struct rte_flow_error *error)
162 rte_flow_error_set(error, EINVAL,
163 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
168 if ((item->last != NULL || item->mask != NULL) && item->spec == NULL) {
169 rte_flow_error_set(error, EINVAL,
170 RTE_FLOW_ERROR_TYPE_ITEM, item,
171 "Mask or last is set without spec");
176 * If "mask" is not set, default mask is used,
177 * but if default mask is NULL, "mask" should be set
179 if (item->mask == NULL) {
180 if (def_mask == NULL) {
181 rte_flow_error_set(error, EINVAL,
182 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
183 "Mask should be specified");
199 * If field values in "last" are either 0 or equal to the corresponding
200 * values in "spec" then they are ignored
203 !sfc_flow_is_zero(last, size) &&
204 memcmp(last, spec, size) != 0) {
205 rte_flow_error_set(error, ENOTSUP,
206 RTE_FLOW_ERROR_TYPE_ITEM, item,
207 "Ranging is not supported");
211 if (supp_mask == NULL) {
212 rte_flow_error_set(error, EINVAL,
213 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
214 "Supported mask for item should be specified");
218 /* Check that mask does not ask for more match than supp_mask */
219 for (i = 0; i < size; i++) {
220 supp = ((const uint8_t *)supp_mask)[i];
222 if (~supp & mask[i]) {
223 rte_flow_error_set(error, ENOTSUP,
224 RTE_FLOW_ERROR_TYPE_ITEM, item,
225 "Item's field is not supported");
238 * Masking is not supported, so masks in items should be either
239 * full or empty (zeroed) and set only for supported fields which
240 * are specified in the supp_mask.
244 sfc_flow_parse_void(__rte_unused const struct rte_flow_item *item,
245 __rte_unused struct sfc_flow_parse_ctx *parse_ctx,
246 __rte_unused struct rte_flow_error *error)
252 * Convert Ethernet item to EFX filter specification.
255 * Item specification. Outer frame specification may only comprise
256 * source/destination addresses and Ethertype field.
257 * Inner frame specification may contain destination address only.
258 * There is support for individual/group mask as well as for empty and full.
259 * If the mask is NULL, default mask will be used. Ranging is not supported.
260 * @param efx_spec[in, out]
261 * EFX filter specification to update.
263 * Perform verbose error reporting if not NULL.
266 sfc_flow_parse_eth(const struct rte_flow_item *item,
267 struct sfc_flow_parse_ctx *parse_ctx,
268 struct rte_flow_error *error)
271 efx_filter_spec_t *efx_spec = parse_ctx->filter;
272 const struct rte_flow_item_eth *spec = NULL;
273 const struct rte_flow_item_eth *mask = NULL;
274 const struct rte_flow_item_eth supp_mask = {
275 .dst.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
276 .src.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
279 const struct rte_flow_item_eth ifrm_supp_mask = {
280 .dst.addr_bytes = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
282 const uint8_t ig_mask[EFX_MAC_ADDR_LEN] = {
283 0x01, 0x00, 0x00, 0x00, 0x00, 0x00
285 const struct rte_flow_item_eth *supp_mask_p;
286 const struct rte_flow_item_eth *def_mask_p;
287 uint8_t *loc_mac = NULL;
288 boolean_t is_ifrm = (efx_spec->efs_encap_type !=
289 EFX_TUNNEL_PROTOCOL_NONE);
292 supp_mask_p = &ifrm_supp_mask;
293 def_mask_p = &ifrm_supp_mask;
294 loc_mac = efx_spec->efs_ifrm_loc_mac;
296 supp_mask_p = &supp_mask;
297 def_mask_p = &rte_flow_item_eth_mask;
298 loc_mac = efx_spec->efs_loc_mac;
301 rc = sfc_flow_parse_init(item,
302 (const void **)&spec,
303 (const void **)&mask,
304 supp_mask_p, def_mask_p,
305 sizeof(struct rte_flow_item_eth),
310 /* If "spec" is not set, could be any Ethernet */
314 if (rte_is_same_ether_addr(&mask->dst, &supp_mask.dst)) {
315 efx_spec->efs_match_flags |= is_ifrm ?
316 EFX_FILTER_MATCH_IFRM_LOC_MAC :
317 EFX_FILTER_MATCH_LOC_MAC;
318 rte_memcpy(loc_mac, spec->dst.addr_bytes,
320 } else if (memcmp(mask->dst.addr_bytes, ig_mask,
321 EFX_MAC_ADDR_LEN) == 0) {
322 if (rte_is_unicast_ether_addr(&spec->dst))
323 efx_spec->efs_match_flags |= is_ifrm ?
324 EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST :
325 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST;
327 efx_spec->efs_match_flags |= is_ifrm ?
328 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST :
329 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST;
330 } else if (!rte_is_zero_ether_addr(&mask->dst)) {
335 * ifrm_supp_mask ensures that the source address and
336 * ethertype masks are equal to zero in inner frame,
337 * so these fields are filled in only for the outer frame
339 if (rte_is_same_ether_addr(&mask->src, &supp_mask.src)) {
340 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_MAC;
341 rte_memcpy(efx_spec->efs_rem_mac, spec->src.addr_bytes,
343 } else if (!rte_is_zero_ether_addr(&mask->src)) {
348 * Ether type is in big-endian byte order in item and
349 * in little-endian in efx_spec, so byte swap is used
351 if (mask->type == supp_mask.type) {
352 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
353 efx_spec->efs_ether_type = rte_bswap16(spec->type);
354 } else if (mask->type != 0) {
361 rte_flow_error_set(error, EINVAL,
362 RTE_FLOW_ERROR_TYPE_ITEM, item,
363 "Bad mask in the ETH pattern item");
368 * Convert VLAN item to EFX filter specification.
371 * Item specification. Only VID field is supported.
372 * The mask can not be NULL. Ranging is not supported.
373 * @param efx_spec[in, out]
374 * EFX filter specification to update.
376 * Perform verbose error reporting if not NULL.
379 sfc_flow_parse_vlan(const struct rte_flow_item *item,
380 struct sfc_flow_parse_ctx *parse_ctx,
381 struct rte_flow_error *error)
385 efx_filter_spec_t *efx_spec = parse_ctx->filter;
386 const struct rte_flow_item_vlan *spec = NULL;
387 const struct rte_flow_item_vlan *mask = NULL;
388 const struct rte_flow_item_vlan supp_mask = {
389 .tci = rte_cpu_to_be_16(ETH_VLAN_ID_MAX),
390 .inner_type = RTE_BE16(0xffff),
393 rc = sfc_flow_parse_init(item,
394 (const void **)&spec,
395 (const void **)&mask,
398 sizeof(struct rte_flow_item_vlan),
404 * VID is in big-endian byte order in item and
405 * in little-endian in efx_spec, so byte swap is used.
406 * If two VLAN items are included, the first matches
407 * the outer tag and the next matches the inner tag.
409 if (mask->tci == supp_mask.tci) {
410 /* Apply mask to keep VID only */
411 vid = rte_bswap16(spec->tci & mask->tci);
413 if (!(efx_spec->efs_match_flags &
414 EFX_FILTER_MATCH_OUTER_VID)) {
415 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_OUTER_VID;
416 efx_spec->efs_outer_vid = vid;
417 } else if (!(efx_spec->efs_match_flags &
418 EFX_FILTER_MATCH_INNER_VID)) {
419 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_INNER_VID;
420 efx_spec->efs_inner_vid = vid;
422 rte_flow_error_set(error, EINVAL,
423 RTE_FLOW_ERROR_TYPE_ITEM, item,
424 "More than two VLAN items");
428 rte_flow_error_set(error, EINVAL,
429 RTE_FLOW_ERROR_TYPE_ITEM, item,
430 "VLAN ID in TCI match is required");
434 if (efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE) {
435 rte_flow_error_set(error, EINVAL,
436 RTE_FLOW_ERROR_TYPE_ITEM, item,
437 "VLAN TPID matching is not supported");
440 if (mask->inner_type == supp_mask.inner_type) {
441 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
442 efx_spec->efs_ether_type = rte_bswap16(spec->inner_type);
443 } else if (mask->inner_type) {
444 rte_flow_error_set(error, EINVAL,
445 RTE_FLOW_ERROR_TYPE_ITEM, item,
446 "Bad mask for VLAN inner_type");
454 * Convert IPv4 item to EFX filter specification.
457 * Item specification. Only source and destination addresses and
458 * protocol fields are supported. If the mask is NULL, default
459 * mask will be used. Ranging is not supported.
460 * @param efx_spec[in, out]
461 * EFX filter specification to update.
463 * Perform verbose error reporting if not NULL.
466 sfc_flow_parse_ipv4(const struct rte_flow_item *item,
467 struct sfc_flow_parse_ctx *parse_ctx,
468 struct rte_flow_error *error)
471 efx_filter_spec_t *efx_spec = parse_ctx->filter;
472 const struct rte_flow_item_ipv4 *spec = NULL;
473 const struct rte_flow_item_ipv4 *mask = NULL;
474 const uint16_t ether_type_ipv4 = rte_cpu_to_le_16(EFX_ETHER_TYPE_IPV4);
475 const struct rte_flow_item_ipv4 supp_mask = {
477 .src_addr = 0xffffffff,
478 .dst_addr = 0xffffffff,
479 .next_proto_id = 0xff,
483 rc = sfc_flow_parse_init(item,
484 (const void **)&spec,
485 (const void **)&mask,
487 &rte_flow_item_ipv4_mask,
488 sizeof(struct rte_flow_item_ipv4),
494 * Filtering by IPv4 source and destination addresses requires
495 * the appropriate ETHER_TYPE in hardware filters
497 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE)) {
498 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
499 efx_spec->efs_ether_type = ether_type_ipv4;
500 } else if (efx_spec->efs_ether_type != ether_type_ipv4) {
501 rte_flow_error_set(error, EINVAL,
502 RTE_FLOW_ERROR_TYPE_ITEM, item,
503 "Ethertype in pattern with IPV4 item should be appropriate");
511 * IPv4 addresses are in big-endian byte order in item and in
514 if (mask->hdr.src_addr == supp_mask.hdr.src_addr) {
515 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_HOST;
516 efx_spec->efs_rem_host.eo_u32[0] = spec->hdr.src_addr;
517 } else if (mask->hdr.src_addr != 0) {
521 if (mask->hdr.dst_addr == supp_mask.hdr.dst_addr) {
522 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_HOST;
523 efx_spec->efs_loc_host.eo_u32[0] = spec->hdr.dst_addr;
524 } else if (mask->hdr.dst_addr != 0) {
528 if (mask->hdr.next_proto_id == supp_mask.hdr.next_proto_id) {
529 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
530 efx_spec->efs_ip_proto = spec->hdr.next_proto_id;
531 } else if (mask->hdr.next_proto_id != 0) {
538 rte_flow_error_set(error, EINVAL,
539 RTE_FLOW_ERROR_TYPE_ITEM, item,
540 "Bad mask in the IPV4 pattern item");
545 * Convert IPv6 item to EFX filter specification.
548 * Item specification. Only source and destination addresses and
549 * next header fields are supported. If the mask is NULL, default
550 * mask will be used. Ranging is not supported.
551 * @param efx_spec[in, out]
552 * EFX filter specification to update.
554 * Perform verbose error reporting if not NULL.
557 sfc_flow_parse_ipv6(const struct rte_flow_item *item,
558 struct sfc_flow_parse_ctx *parse_ctx,
559 struct rte_flow_error *error)
562 efx_filter_spec_t *efx_spec = parse_ctx->filter;
563 const struct rte_flow_item_ipv6 *spec = NULL;
564 const struct rte_flow_item_ipv6 *mask = NULL;
565 const uint16_t ether_type_ipv6 = rte_cpu_to_le_16(EFX_ETHER_TYPE_IPV6);
566 const struct rte_flow_item_ipv6 supp_mask = {
568 .src_addr = { 0xff, 0xff, 0xff, 0xff,
569 0xff, 0xff, 0xff, 0xff,
570 0xff, 0xff, 0xff, 0xff,
571 0xff, 0xff, 0xff, 0xff },
572 .dst_addr = { 0xff, 0xff, 0xff, 0xff,
573 0xff, 0xff, 0xff, 0xff,
574 0xff, 0xff, 0xff, 0xff,
575 0xff, 0xff, 0xff, 0xff },
580 rc = sfc_flow_parse_init(item,
581 (const void **)&spec,
582 (const void **)&mask,
584 &rte_flow_item_ipv6_mask,
585 sizeof(struct rte_flow_item_ipv6),
591 * Filtering by IPv6 source and destination addresses requires
592 * the appropriate ETHER_TYPE in hardware filters
594 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE)) {
595 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
596 efx_spec->efs_ether_type = ether_type_ipv6;
597 } else if (efx_spec->efs_ether_type != ether_type_ipv6) {
598 rte_flow_error_set(error, EINVAL,
599 RTE_FLOW_ERROR_TYPE_ITEM, item,
600 "Ethertype in pattern with IPV6 item should be appropriate");
608 * IPv6 addresses are in big-endian byte order in item and in
611 if (memcmp(mask->hdr.src_addr, supp_mask.hdr.src_addr,
612 sizeof(mask->hdr.src_addr)) == 0) {
613 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_HOST;
615 RTE_BUILD_BUG_ON(sizeof(efx_spec->efs_rem_host) !=
616 sizeof(spec->hdr.src_addr));
617 rte_memcpy(&efx_spec->efs_rem_host, spec->hdr.src_addr,
618 sizeof(efx_spec->efs_rem_host));
619 } else if (!sfc_flow_is_zero(mask->hdr.src_addr,
620 sizeof(mask->hdr.src_addr))) {
624 if (memcmp(mask->hdr.dst_addr, supp_mask.hdr.dst_addr,
625 sizeof(mask->hdr.dst_addr)) == 0) {
626 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_HOST;
628 RTE_BUILD_BUG_ON(sizeof(efx_spec->efs_loc_host) !=
629 sizeof(spec->hdr.dst_addr));
630 rte_memcpy(&efx_spec->efs_loc_host, spec->hdr.dst_addr,
631 sizeof(efx_spec->efs_loc_host));
632 } else if (!sfc_flow_is_zero(mask->hdr.dst_addr,
633 sizeof(mask->hdr.dst_addr))) {
637 if (mask->hdr.proto == supp_mask.hdr.proto) {
638 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
639 efx_spec->efs_ip_proto = spec->hdr.proto;
640 } else if (mask->hdr.proto != 0) {
647 rte_flow_error_set(error, EINVAL,
648 RTE_FLOW_ERROR_TYPE_ITEM, item,
649 "Bad mask in the IPV6 pattern item");
654 * Convert TCP item to EFX filter specification.
657 * Item specification. Only source and destination ports fields
658 * are supported. If the mask is NULL, default mask will be used.
659 * Ranging is not supported.
660 * @param efx_spec[in, out]
661 * EFX filter specification to update.
663 * Perform verbose error reporting if not NULL.
666 sfc_flow_parse_tcp(const struct rte_flow_item *item,
667 struct sfc_flow_parse_ctx *parse_ctx,
668 struct rte_flow_error *error)
671 efx_filter_spec_t *efx_spec = parse_ctx->filter;
672 const struct rte_flow_item_tcp *spec = NULL;
673 const struct rte_flow_item_tcp *mask = NULL;
674 const struct rte_flow_item_tcp supp_mask = {
681 rc = sfc_flow_parse_init(item,
682 (const void **)&spec,
683 (const void **)&mask,
685 &rte_flow_item_tcp_mask,
686 sizeof(struct rte_flow_item_tcp),
692 * Filtering by TCP source and destination ports requires
693 * the appropriate IP_PROTO in hardware filters
695 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_IP_PROTO)) {
696 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
697 efx_spec->efs_ip_proto = EFX_IPPROTO_TCP;
698 } else if (efx_spec->efs_ip_proto != EFX_IPPROTO_TCP) {
699 rte_flow_error_set(error, EINVAL,
700 RTE_FLOW_ERROR_TYPE_ITEM, item,
701 "IP proto in pattern with TCP item should be appropriate");
709 * Source and destination ports are in big-endian byte order in item and
710 * in little-endian in efx_spec, so byte swap is used
712 if (mask->hdr.src_port == supp_mask.hdr.src_port) {
713 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_PORT;
714 efx_spec->efs_rem_port = rte_bswap16(spec->hdr.src_port);
715 } else if (mask->hdr.src_port != 0) {
719 if (mask->hdr.dst_port == supp_mask.hdr.dst_port) {
720 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_PORT;
721 efx_spec->efs_loc_port = rte_bswap16(spec->hdr.dst_port);
722 } else if (mask->hdr.dst_port != 0) {
729 rte_flow_error_set(error, EINVAL,
730 RTE_FLOW_ERROR_TYPE_ITEM, item,
731 "Bad mask in the TCP pattern item");
736 * Convert UDP item to EFX filter specification.
739 * Item specification. Only source and destination ports fields
740 * are supported. If the mask is NULL, default mask will be used.
741 * Ranging is not supported.
742 * @param efx_spec[in, out]
743 * EFX filter specification to update.
745 * Perform verbose error reporting if not NULL.
748 sfc_flow_parse_udp(const struct rte_flow_item *item,
749 struct sfc_flow_parse_ctx *parse_ctx,
750 struct rte_flow_error *error)
753 efx_filter_spec_t *efx_spec = parse_ctx->filter;
754 const struct rte_flow_item_udp *spec = NULL;
755 const struct rte_flow_item_udp *mask = NULL;
756 const struct rte_flow_item_udp supp_mask = {
763 rc = sfc_flow_parse_init(item,
764 (const void **)&spec,
765 (const void **)&mask,
767 &rte_flow_item_udp_mask,
768 sizeof(struct rte_flow_item_udp),
774 * Filtering by UDP source and destination ports requires
775 * the appropriate IP_PROTO in hardware filters
777 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_IP_PROTO)) {
778 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
779 efx_spec->efs_ip_proto = EFX_IPPROTO_UDP;
780 } else if (efx_spec->efs_ip_proto != EFX_IPPROTO_UDP) {
781 rte_flow_error_set(error, EINVAL,
782 RTE_FLOW_ERROR_TYPE_ITEM, item,
783 "IP proto in pattern with UDP item should be appropriate");
791 * Source and destination ports are in big-endian byte order in item and
792 * in little-endian in efx_spec, so byte swap is used
794 if (mask->hdr.src_port == supp_mask.hdr.src_port) {
795 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_REM_PORT;
796 efx_spec->efs_rem_port = rte_bswap16(spec->hdr.src_port);
797 } else if (mask->hdr.src_port != 0) {
801 if (mask->hdr.dst_port == supp_mask.hdr.dst_port) {
802 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_LOC_PORT;
803 efx_spec->efs_loc_port = rte_bswap16(spec->hdr.dst_port);
804 } else if (mask->hdr.dst_port != 0) {
811 rte_flow_error_set(error, EINVAL,
812 RTE_FLOW_ERROR_TYPE_ITEM, item,
813 "Bad mask in the UDP pattern item");
818 * Filters for encapsulated packets match based on the EtherType and IP
819 * protocol in the outer frame.
822 sfc_flow_set_match_flags_for_encap_pkts(const struct rte_flow_item *item,
823 efx_filter_spec_t *efx_spec,
825 struct rte_flow_error *error)
827 if (!(efx_spec->efs_match_flags & EFX_FILTER_MATCH_IP_PROTO)) {
828 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_IP_PROTO;
829 efx_spec->efs_ip_proto = ip_proto;
830 } else if (efx_spec->efs_ip_proto != ip_proto) {
832 case EFX_IPPROTO_UDP:
833 rte_flow_error_set(error, EINVAL,
834 RTE_FLOW_ERROR_TYPE_ITEM, item,
835 "Outer IP header protocol must be UDP "
836 "in VxLAN/GENEVE pattern");
839 case EFX_IPPROTO_GRE:
840 rte_flow_error_set(error, EINVAL,
841 RTE_FLOW_ERROR_TYPE_ITEM, item,
842 "Outer IP header protocol must be GRE "
847 rte_flow_error_set(error, EINVAL,
848 RTE_FLOW_ERROR_TYPE_ITEM, item,
849 "Only VxLAN/GENEVE/NVGRE tunneling patterns "
855 if (efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE &&
856 efx_spec->efs_ether_type != EFX_ETHER_TYPE_IPV4 &&
857 efx_spec->efs_ether_type != EFX_ETHER_TYPE_IPV6) {
858 rte_flow_error_set(error, EINVAL,
859 RTE_FLOW_ERROR_TYPE_ITEM, item,
860 "Outer frame EtherType in pattern with tunneling "
861 "must be IPv4 or IPv6");
869 sfc_flow_set_efx_spec_vni_or_vsid(efx_filter_spec_t *efx_spec,
870 const uint8_t *vni_or_vsid_val,
871 const uint8_t *vni_or_vsid_mask,
872 const struct rte_flow_item *item,
873 struct rte_flow_error *error)
875 const uint8_t vni_or_vsid_full_mask[EFX_VNI_OR_VSID_LEN] = {
879 if (memcmp(vni_or_vsid_mask, vni_or_vsid_full_mask,
880 EFX_VNI_OR_VSID_LEN) == 0) {
881 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_VNI_OR_VSID;
882 rte_memcpy(efx_spec->efs_vni_or_vsid, vni_or_vsid_val,
883 EFX_VNI_OR_VSID_LEN);
884 } else if (!sfc_flow_is_zero(vni_or_vsid_mask, EFX_VNI_OR_VSID_LEN)) {
885 rte_flow_error_set(error, EINVAL,
886 RTE_FLOW_ERROR_TYPE_ITEM, item,
887 "Unsupported VNI/VSID mask");
895 * Convert VXLAN item to EFX filter specification.
898 * Item specification. Only VXLAN network identifier field is supported.
899 * If the mask is NULL, default mask will be used.
900 * Ranging is not supported.
901 * @param efx_spec[in, out]
902 * EFX filter specification to update.
904 * Perform verbose error reporting if not NULL.
907 sfc_flow_parse_vxlan(const struct rte_flow_item *item,
908 struct sfc_flow_parse_ctx *parse_ctx,
909 struct rte_flow_error *error)
912 efx_filter_spec_t *efx_spec = parse_ctx->filter;
913 const struct rte_flow_item_vxlan *spec = NULL;
914 const struct rte_flow_item_vxlan *mask = NULL;
915 const struct rte_flow_item_vxlan supp_mask = {
916 .vni = { 0xff, 0xff, 0xff }
919 rc = sfc_flow_parse_init(item,
920 (const void **)&spec,
921 (const void **)&mask,
923 &rte_flow_item_vxlan_mask,
924 sizeof(struct rte_flow_item_vxlan),
929 rc = sfc_flow_set_match_flags_for_encap_pkts(item, efx_spec,
930 EFX_IPPROTO_UDP, error);
934 efx_spec->efs_encap_type = EFX_TUNNEL_PROTOCOL_VXLAN;
935 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
940 rc = sfc_flow_set_efx_spec_vni_or_vsid(efx_spec, spec->vni,
941 mask->vni, item, error);
947 * Convert GENEVE item to EFX filter specification.
950 * Item specification. Only Virtual Network Identifier and protocol type
951 * fields are supported. But protocol type can be only Ethernet (0x6558).
952 * If the mask is NULL, default mask will be used.
953 * Ranging is not supported.
954 * @param efx_spec[in, out]
955 * EFX filter specification to update.
957 * Perform verbose error reporting if not NULL.
960 sfc_flow_parse_geneve(const struct rte_flow_item *item,
961 struct sfc_flow_parse_ctx *parse_ctx,
962 struct rte_flow_error *error)
965 efx_filter_spec_t *efx_spec = parse_ctx->filter;
966 const struct rte_flow_item_geneve *spec = NULL;
967 const struct rte_flow_item_geneve *mask = NULL;
968 const struct rte_flow_item_geneve supp_mask = {
969 .protocol = RTE_BE16(0xffff),
970 .vni = { 0xff, 0xff, 0xff }
973 rc = sfc_flow_parse_init(item,
974 (const void **)&spec,
975 (const void **)&mask,
977 &rte_flow_item_geneve_mask,
978 sizeof(struct rte_flow_item_geneve),
983 rc = sfc_flow_set_match_flags_for_encap_pkts(item, efx_spec,
984 EFX_IPPROTO_UDP, error);
988 efx_spec->efs_encap_type = EFX_TUNNEL_PROTOCOL_GENEVE;
989 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
994 if (mask->protocol == supp_mask.protocol) {
995 if (spec->protocol != rte_cpu_to_be_16(RTE_ETHER_TYPE_TEB)) {
996 rte_flow_error_set(error, EINVAL,
997 RTE_FLOW_ERROR_TYPE_ITEM, item,
998 "GENEVE encap. protocol must be Ethernet "
999 "(0x6558) in the GENEVE pattern item");
1002 } else if (mask->protocol != 0) {
1003 rte_flow_error_set(error, EINVAL,
1004 RTE_FLOW_ERROR_TYPE_ITEM, item,
1005 "Unsupported mask for GENEVE encap. protocol");
1009 rc = sfc_flow_set_efx_spec_vni_or_vsid(efx_spec, spec->vni,
1010 mask->vni, item, error);
1016 * Convert NVGRE item to EFX filter specification.
1019 * Item specification. Only virtual subnet ID field is supported.
1020 * If the mask is NULL, default mask will be used.
1021 * Ranging is not supported.
1022 * @param efx_spec[in, out]
1023 * EFX filter specification to update.
1025 * Perform verbose error reporting if not NULL.
1028 sfc_flow_parse_nvgre(const struct rte_flow_item *item,
1029 struct sfc_flow_parse_ctx *parse_ctx,
1030 struct rte_flow_error *error)
1033 efx_filter_spec_t *efx_spec = parse_ctx->filter;
1034 const struct rte_flow_item_nvgre *spec = NULL;
1035 const struct rte_flow_item_nvgre *mask = NULL;
1036 const struct rte_flow_item_nvgre supp_mask = {
1037 .tni = { 0xff, 0xff, 0xff }
1040 rc = sfc_flow_parse_init(item,
1041 (const void **)&spec,
1042 (const void **)&mask,
1044 &rte_flow_item_nvgre_mask,
1045 sizeof(struct rte_flow_item_nvgre),
1050 rc = sfc_flow_set_match_flags_for_encap_pkts(item, efx_spec,
1051 EFX_IPPROTO_GRE, error);
1055 efx_spec->efs_encap_type = EFX_TUNNEL_PROTOCOL_NVGRE;
1056 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ENCAP_TYPE;
1061 rc = sfc_flow_set_efx_spec_vni_or_vsid(efx_spec, spec->tni,
1062 mask->tni, item, error);
1068 * Convert PPPoEx item to EFX filter specification.
1071 * Item specification.
1072 * Matching on PPPoEx fields is not supported.
1073 * This item can only be used to set or validate the EtherType filter.
1074 * Only zero masks are allowed.
1075 * Ranging is not supported.
1076 * @param efx_spec[in, out]
1077 * EFX filter specification to update.
1079 * Perform verbose error reporting if not NULL.
1082 sfc_flow_parse_pppoex(const struct rte_flow_item *item,
1083 struct sfc_flow_parse_ctx *parse_ctx,
1084 struct rte_flow_error *error)
1086 efx_filter_spec_t *efx_spec = parse_ctx->filter;
1087 const struct rte_flow_item_pppoe *spec = NULL;
1088 const struct rte_flow_item_pppoe *mask = NULL;
1089 const struct rte_flow_item_pppoe supp_mask = {};
1090 const struct rte_flow_item_pppoe def_mask = {};
1091 uint16_t ether_type;
1094 rc = sfc_flow_parse_init(item,
1095 (const void **)&spec,
1096 (const void **)&mask,
1099 sizeof(struct rte_flow_item_pppoe),
1104 if (item->type == RTE_FLOW_ITEM_TYPE_PPPOED)
1105 ether_type = RTE_ETHER_TYPE_PPPOE_DISCOVERY;
1107 ether_type = RTE_ETHER_TYPE_PPPOE_SESSION;
1109 if ((efx_spec->efs_match_flags & EFX_FILTER_MATCH_ETHER_TYPE) != 0) {
1110 if (efx_spec->efs_ether_type != ether_type) {
1111 rte_flow_error_set(error, EINVAL,
1112 RTE_FLOW_ERROR_TYPE_ITEM, item,
1113 "Invalid EtherType for a PPPoE flow item");
1117 efx_spec->efs_match_flags |= EFX_FILTER_MATCH_ETHER_TYPE;
1118 efx_spec->efs_ether_type = ether_type;
1124 static const struct sfc_flow_item sfc_flow_items[] = {
1126 .type = RTE_FLOW_ITEM_TYPE_VOID,
1127 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
1128 .layer = SFC_FLOW_ITEM_ANY_LAYER,
1129 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1130 .parse = sfc_flow_parse_void,
1133 .type = RTE_FLOW_ITEM_TYPE_ETH,
1134 .prev_layer = SFC_FLOW_ITEM_START_LAYER,
1135 .layer = SFC_FLOW_ITEM_L2,
1136 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1137 .parse = sfc_flow_parse_eth,
1140 .type = RTE_FLOW_ITEM_TYPE_VLAN,
1141 .prev_layer = SFC_FLOW_ITEM_L2,
1142 .layer = SFC_FLOW_ITEM_L2,
1143 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1144 .parse = sfc_flow_parse_vlan,
1147 .type = RTE_FLOW_ITEM_TYPE_PPPOED,
1148 .prev_layer = SFC_FLOW_ITEM_L2,
1149 .layer = SFC_FLOW_ITEM_L2,
1150 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1151 .parse = sfc_flow_parse_pppoex,
1154 .type = RTE_FLOW_ITEM_TYPE_PPPOES,
1155 .prev_layer = SFC_FLOW_ITEM_L2,
1156 .layer = SFC_FLOW_ITEM_L2,
1157 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1158 .parse = sfc_flow_parse_pppoex,
1161 .type = RTE_FLOW_ITEM_TYPE_IPV4,
1162 .prev_layer = SFC_FLOW_ITEM_L2,
1163 .layer = SFC_FLOW_ITEM_L3,
1164 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1165 .parse = sfc_flow_parse_ipv4,
1168 .type = RTE_FLOW_ITEM_TYPE_IPV6,
1169 .prev_layer = SFC_FLOW_ITEM_L2,
1170 .layer = SFC_FLOW_ITEM_L3,
1171 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1172 .parse = sfc_flow_parse_ipv6,
1175 .type = RTE_FLOW_ITEM_TYPE_TCP,
1176 .prev_layer = SFC_FLOW_ITEM_L3,
1177 .layer = SFC_FLOW_ITEM_L4,
1178 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1179 .parse = sfc_flow_parse_tcp,
1182 .type = RTE_FLOW_ITEM_TYPE_UDP,
1183 .prev_layer = SFC_FLOW_ITEM_L3,
1184 .layer = SFC_FLOW_ITEM_L4,
1185 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1186 .parse = sfc_flow_parse_udp,
1189 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
1190 .prev_layer = SFC_FLOW_ITEM_L4,
1191 .layer = SFC_FLOW_ITEM_START_LAYER,
1192 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1193 .parse = sfc_flow_parse_vxlan,
1196 .type = RTE_FLOW_ITEM_TYPE_GENEVE,
1197 .prev_layer = SFC_FLOW_ITEM_L4,
1198 .layer = SFC_FLOW_ITEM_START_LAYER,
1199 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1200 .parse = sfc_flow_parse_geneve,
1203 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
1204 .prev_layer = SFC_FLOW_ITEM_L3,
1205 .layer = SFC_FLOW_ITEM_START_LAYER,
1206 .ctx_type = SFC_FLOW_PARSE_CTX_FILTER,
1207 .parse = sfc_flow_parse_nvgre,
1212 * Protocol-independent flow API support
1215 sfc_flow_parse_attr(struct sfc_adapter *sa,
1216 const struct rte_flow_attr *attr,
1217 struct rte_flow *flow,
1218 struct rte_flow_error *error)
1220 struct sfc_flow_spec *spec = &flow->spec;
1221 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1222 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
1223 struct sfc_mae *mae = &sa->mae;
1226 rte_flow_error_set(error, EINVAL,
1227 RTE_FLOW_ERROR_TYPE_ATTR, NULL,
1231 if (attr->group != 0) {
1232 rte_flow_error_set(error, ENOTSUP,
1233 RTE_FLOW_ERROR_TYPE_ATTR_GROUP, attr,
1234 "Groups are not supported");
1237 if (attr->egress != 0) {
1238 rte_flow_error_set(error, ENOTSUP,
1239 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS, attr,
1240 "Egress is not supported");
1243 if (attr->ingress == 0) {
1244 rte_flow_error_set(error, ENOTSUP,
1245 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS, attr,
1246 "Ingress is compulsory");
1249 if (attr->transfer == 0) {
1250 if (attr->priority != 0) {
1251 rte_flow_error_set(error, ENOTSUP,
1252 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1253 attr, "Priorities are unsupported");
1256 spec->type = SFC_FLOW_SPEC_FILTER;
1257 spec_filter->template.efs_flags |= EFX_FILTER_FLAG_RX;
1258 spec_filter->template.efs_rss_context = EFX_RSS_CONTEXT_DEFAULT;
1259 spec_filter->template.efs_priority = EFX_FILTER_PRI_MANUAL;
1261 if (mae->status != SFC_MAE_STATUS_SUPPORTED) {
1262 rte_flow_error_set(error, ENOTSUP,
1263 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
1264 attr, "Transfer is not supported");
1267 if (attr->priority > mae->nb_action_rule_prios_max) {
1268 rte_flow_error_set(error, ENOTSUP,
1269 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1270 attr, "Unsupported priority level");
1273 spec->type = SFC_FLOW_SPEC_MAE;
1274 spec_mae->priority = attr->priority;
1275 spec_mae->match_spec = NULL;
1276 spec_mae->action_set = NULL;
1277 spec_mae->rule_id.id = EFX_MAE_RSRC_ID_INVALID;
1283 /* Get item from array sfc_flow_items */
1284 static const struct sfc_flow_item *
1285 sfc_flow_get_item(const struct sfc_flow_item *items,
1286 unsigned int nb_items,
1287 enum rte_flow_item_type type)
1291 for (i = 0; i < nb_items; i++)
1292 if (items[i].type == type)
1299 sfc_flow_parse_pattern(const struct sfc_flow_item *flow_items,
1300 unsigned int nb_flow_items,
1301 const struct rte_flow_item pattern[],
1302 struct sfc_flow_parse_ctx *parse_ctx,
1303 struct rte_flow_error *error)
1306 unsigned int prev_layer = SFC_FLOW_ITEM_ANY_LAYER;
1307 boolean_t is_ifrm = B_FALSE;
1308 const struct sfc_flow_item *item;
1310 if (pattern == NULL) {
1311 rte_flow_error_set(error, EINVAL,
1312 RTE_FLOW_ERROR_TYPE_ITEM_NUM, NULL,
1317 for (; pattern->type != RTE_FLOW_ITEM_TYPE_END; pattern++) {
1318 item = sfc_flow_get_item(flow_items, nb_flow_items,
1321 rte_flow_error_set(error, ENOTSUP,
1322 RTE_FLOW_ERROR_TYPE_ITEM, pattern,
1323 "Unsupported pattern item");
1328 * Omitting one or several protocol layers at the beginning
1329 * of pattern is supported
1331 if (item->prev_layer != SFC_FLOW_ITEM_ANY_LAYER &&
1332 prev_layer != SFC_FLOW_ITEM_ANY_LAYER &&
1333 item->prev_layer != prev_layer) {
1334 rte_flow_error_set(error, ENOTSUP,
1335 RTE_FLOW_ERROR_TYPE_ITEM, pattern,
1336 "Unexpected sequence of pattern items");
1341 * Allow only VOID and ETH pattern items in the inner frame.
1342 * Also check that there is only one tunneling protocol.
1344 switch (item->type) {
1345 case RTE_FLOW_ITEM_TYPE_VOID:
1346 case RTE_FLOW_ITEM_TYPE_ETH:
1349 case RTE_FLOW_ITEM_TYPE_VXLAN:
1350 case RTE_FLOW_ITEM_TYPE_GENEVE:
1351 case RTE_FLOW_ITEM_TYPE_NVGRE:
1353 rte_flow_error_set(error, EINVAL,
1354 RTE_FLOW_ERROR_TYPE_ITEM,
1356 "More than one tunneling protocol");
1363 if (parse_ctx->type == SFC_FLOW_PARSE_CTX_FILTER &&
1365 rte_flow_error_set(error, EINVAL,
1366 RTE_FLOW_ERROR_TYPE_ITEM,
1368 "There is an unsupported pattern item "
1369 "in the inner frame");
1375 if (parse_ctx->type != item->ctx_type) {
1376 rte_flow_error_set(error, EINVAL,
1377 RTE_FLOW_ERROR_TYPE_ITEM, pattern,
1378 "Parse context type mismatch");
1382 rc = item->parse(pattern, parse_ctx, error);
1386 if (item->layer != SFC_FLOW_ITEM_ANY_LAYER)
1387 prev_layer = item->layer;
1394 sfc_flow_parse_queue(struct sfc_adapter *sa,
1395 const struct rte_flow_action_queue *queue,
1396 struct rte_flow *flow)
1398 struct sfc_flow_spec *spec = &flow->spec;
1399 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1400 struct sfc_rxq *rxq;
1401 struct sfc_rxq_info *rxq_info;
1403 if (queue->index >= sfc_sa2shared(sa)->ethdev_rxq_count)
1406 rxq = sfc_rxq_ctrl_by_ethdev_qid(sa, queue->index);
1407 spec_filter->template.efs_dmaq_id = (uint16_t)rxq->hw_index;
1409 rxq_info = &sfc_sa2shared(sa)->rxq_info[queue->index];
1410 spec_filter->rss_hash_required = !!(rxq_info->rxq_flags &
1411 SFC_RXQ_FLAG_RSS_HASH);
1417 sfc_flow_parse_rss(struct sfc_adapter *sa,
1418 const struct rte_flow_action_rss *action_rss,
1419 struct rte_flow *flow)
1421 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
1422 struct sfc_rss *rss = &sas->rss;
1423 sfc_ethdev_qid_t ethdev_qid;
1424 struct sfc_rxq *rxq;
1425 unsigned int rxq_hw_index_min;
1426 unsigned int rxq_hw_index_max;
1427 efx_rx_hash_type_t efx_hash_types;
1428 const uint8_t *rss_key;
1429 struct sfc_flow_spec *spec = &flow->spec;
1430 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1431 struct sfc_flow_rss *sfc_rss_conf = &spec_filter->rss_conf;
1434 if (action_rss->queue_num == 0)
1437 ethdev_qid = sfc_sa2shared(sa)->ethdev_rxq_count - 1;
1438 rxq = sfc_rxq_ctrl_by_ethdev_qid(sa, ethdev_qid);
1439 rxq_hw_index_min = rxq->hw_index;
1440 rxq_hw_index_max = 0;
1442 for (i = 0; i < action_rss->queue_num; ++i) {
1443 ethdev_qid = action_rss->queue[i];
1445 if ((unsigned int)ethdev_qid >=
1446 sfc_sa2shared(sa)->ethdev_rxq_count)
1449 rxq = sfc_rxq_ctrl_by_ethdev_qid(sa, ethdev_qid);
1451 if (rxq->hw_index < rxq_hw_index_min)
1452 rxq_hw_index_min = rxq->hw_index;
1454 if (rxq->hw_index > rxq_hw_index_max)
1455 rxq_hw_index_max = rxq->hw_index;
1458 switch (action_rss->func) {
1459 case RTE_ETH_HASH_FUNCTION_DEFAULT:
1460 case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
1466 if (action_rss->level)
1470 * Dummy RSS action with only one queue and no specific settings
1471 * for hash types and key does not require dedicated RSS context
1472 * and may be simplified to single queue action.
1474 if (action_rss->queue_num == 1 && action_rss->types == 0 &&
1475 action_rss->key_len == 0) {
1476 spec_filter->template.efs_dmaq_id = rxq_hw_index_min;
1480 if (action_rss->types) {
1483 rc = sfc_rx_hf_rte_to_efx(sa, action_rss->types,
1491 for (i = 0; i < rss->hf_map_nb_entries; ++i)
1492 efx_hash_types |= rss->hf_map[i].efx;
1495 if (action_rss->key_len) {
1496 if (action_rss->key_len != sizeof(rss->key))
1499 rss_key = action_rss->key;
1504 spec_filter->rss = B_TRUE;
1506 sfc_rss_conf->rxq_hw_index_min = rxq_hw_index_min;
1507 sfc_rss_conf->rxq_hw_index_max = rxq_hw_index_max;
1508 sfc_rss_conf->rss_hash_types = efx_hash_types;
1509 rte_memcpy(sfc_rss_conf->rss_key, rss_key, sizeof(rss->key));
1511 for (i = 0; i < RTE_DIM(sfc_rss_conf->rss_tbl); ++i) {
1512 unsigned int nb_queues = action_rss->queue_num;
1513 struct sfc_rxq *rxq;
1515 ethdev_qid = action_rss->queue[i % nb_queues];
1516 rxq = sfc_rxq_ctrl_by_ethdev_qid(sa, ethdev_qid);
1517 sfc_rss_conf->rss_tbl[i] = rxq->hw_index - rxq_hw_index_min;
1524 sfc_flow_spec_flush(struct sfc_adapter *sa, struct sfc_flow_spec *spec,
1525 unsigned int filters_count)
1527 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1531 for (i = 0; i < filters_count; i++) {
1534 rc = efx_filter_remove(sa->nic, &spec_filter->filters[i]);
1535 if (ret == 0 && rc != 0) {
1536 sfc_err(sa, "failed to remove filter specification "
1546 sfc_flow_spec_insert(struct sfc_adapter *sa, struct sfc_flow_spec *spec)
1548 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1552 for (i = 0; i < spec_filter->count; i++) {
1553 rc = efx_filter_insert(sa->nic, &spec_filter->filters[i]);
1555 sfc_flow_spec_flush(sa, spec, i);
1564 sfc_flow_spec_remove(struct sfc_adapter *sa, struct sfc_flow_spec *spec)
1566 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1568 return sfc_flow_spec_flush(sa, spec, spec_filter->count);
1572 sfc_flow_filter_insert(struct sfc_adapter *sa,
1573 struct rte_flow *flow)
1575 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
1576 struct sfc_rss *rss = &sas->rss;
1577 struct sfc_flow_spec_filter *spec_filter = &flow->spec.filter;
1578 struct sfc_flow_rss *flow_rss = &spec_filter->rss_conf;
1579 uint32_t efs_rss_context = EFX_RSS_CONTEXT_DEFAULT;
1580 boolean_t create_context;
1584 create_context = spec_filter->rss || (spec_filter->rss_hash_required &&
1585 rss->dummy_rss_context == EFX_RSS_CONTEXT_DEFAULT);
1587 if (create_context) {
1588 unsigned int rss_spread;
1589 unsigned int rss_hash_types;
1592 if (spec_filter->rss) {
1593 rss_spread = MIN(flow_rss->rxq_hw_index_max -
1594 flow_rss->rxq_hw_index_min + 1,
1596 rss_hash_types = flow_rss->rss_hash_types;
1597 rss_key = flow_rss->rss_key;
1600 * Initialize dummy RSS context parameters to have
1601 * valid RSS hash. Use default RSS hash function and
1605 rss_hash_types = rss->hash_types;
1609 rc = efx_rx_scale_context_alloc(sa->nic,
1610 EFX_RX_SCALE_EXCLUSIVE,
1614 goto fail_scale_context_alloc;
1616 rc = efx_rx_scale_mode_set(sa->nic, efs_rss_context,
1618 rss_hash_types, B_TRUE);
1620 goto fail_scale_mode_set;
1622 rc = efx_rx_scale_key_set(sa->nic, efs_rss_context,
1623 rss_key, sizeof(rss->key));
1625 goto fail_scale_key_set;
1627 efs_rss_context = rss->dummy_rss_context;
1630 if (spec_filter->rss || spec_filter->rss_hash_required) {
1632 * At this point, fully elaborated filter specifications
1633 * have been produced from the template. To make sure that
1634 * RSS behaviour is consistent between them, set the same
1635 * RSS context value everywhere.
1637 for (i = 0; i < spec_filter->count; i++) {
1638 efx_filter_spec_t *spec = &spec_filter->filters[i];
1640 spec->efs_rss_context = efs_rss_context;
1641 spec->efs_flags |= EFX_FILTER_FLAG_RX_RSS;
1642 if (spec_filter->rss)
1643 spec->efs_dmaq_id = flow_rss->rxq_hw_index_min;
1647 rc = sfc_flow_spec_insert(sa, &flow->spec);
1649 goto fail_filter_insert;
1651 if (create_context) {
1652 unsigned int dummy_tbl[RTE_DIM(flow_rss->rss_tbl)] = {0};
1655 tbl = spec_filter->rss ? flow_rss->rss_tbl : dummy_tbl;
1658 * Scale table is set after filter insertion because
1659 * the table entries are relative to the base RxQ ID
1660 * and the latter is submitted to the HW by means of
1661 * inserting a filter, so by the time of the request
1662 * the HW knows all the information needed to verify
1663 * the table entries, and the operation will succeed
1665 rc = efx_rx_scale_tbl_set(sa->nic, efs_rss_context,
1666 tbl, RTE_DIM(flow_rss->rss_tbl));
1668 goto fail_scale_tbl_set;
1670 /* Remember created dummy RSS context */
1671 if (!spec_filter->rss)
1672 rss->dummy_rss_context = efs_rss_context;
1678 sfc_flow_spec_remove(sa, &flow->spec);
1682 fail_scale_mode_set:
1684 efx_rx_scale_context_free(sa->nic, efs_rss_context);
1686 fail_scale_context_alloc:
1691 sfc_flow_filter_remove(struct sfc_adapter *sa,
1692 struct rte_flow *flow)
1694 struct sfc_flow_spec_filter *spec_filter = &flow->spec.filter;
1697 rc = sfc_flow_spec_remove(sa, &flow->spec);
1701 if (spec_filter->rss) {
1703 * All specifications for a given flow rule have the same RSS
1704 * context, so that RSS context value is taken from the first
1705 * filter specification
1707 efx_filter_spec_t *spec = &spec_filter->filters[0];
1709 rc = efx_rx_scale_context_free(sa->nic, spec->efs_rss_context);
1716 sfc_flow_parse_mark(struct sfc_adapter *sa,
1717 const struct rte_flow_action_mark *mark,
1718 struct rte_flow *flow)
1720 struct sfc_flow_spec *spec = &flow->spec;
1721 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1722 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
1724 if (mark == NULL || mark->id > encp->enc_filter_action_mark_max)
1727 spec_filter->template.efs_flags |= EFX_FILTER_FLAG_ACTION_MARK;
1728 spec_filter->template.efs_mark = mark->id;
1734 sfc_flow_parse_actions(struct sfc_adapter *sa,
1735 const struct rte_flow_action actions[],
1736 struct rte_flow *flow,
1737 struct rte_flow_error *error)
1740 struct sfc_flow_spec *spec = &flow->spec;
1741 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1742 const unsigned int dp_rx_features = sa->priv.dp_rx->features;
1743 uint32_t actions_set = 0;
1744 const uint32_t fate_actions_mask = (1UL << RTE_FLOW_ACTION_TYPE_QUEUE) |
1745 (1UL << RTE_FLOW_ACTION_TYPE_RSS) |
1746 (1UL << RTE_FLOW_ACTION_TYPE_DROP);
1747 const uint32_t mark_actions_mask = (1UL << RTE_FLOW_ACTION_TYPE_MARK) |
1748 (1UL << RTE_FLOW_ACTION_TYPE_FLAG);
1750 if (actions == NULL) {
1751 rte_flow_error_set(error, EINVAL,
1752 RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
1757 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1758 switch (actions->type) {
1759 case RTE_FLOW_ACTION_TYPE_VOID:
1760 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VOID,
1764 case RTE_FLOW_ACTION_TYPE_QUEUE:
1765 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_QUEUE,
1767 if ((actions_set & fate_actions_mask) != 0)
1768 goto fail_fate_actions;
1770 rc = sfc_flow_parse_queue(sa, actions->conf, flow);
1772 rte_flow_error_set(error, EINVAL,
1773 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1774 "Bad QUEUE action");
1779 case RTE_FLOW_ACTION_TYPE_RSS:
1780 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_RSS,
1782 if ((actions_set & fate_actions_mask) != 0)
1783 goto fail_fate_actions;
1785 rc = sfc_flow_parse_rss(sa, actions->conf, flow);
1787 rte_flow_error_set(error, -rc,
1788 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1794 case RTE_FLOW_ACTION_TYPE_DROP:
1795 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_DROP,
1797 if ((actions_set & fate_actions_mask) != 0)
1798 goto fail_fate_actions;
1800 spec_filter->template.efs_dmaq_id =
1801 EFX_FILTER_SPEC_RX_DMAQ_ID_DROP;
1804 case RTE_FLOW_ACTION_TYPE_FLAG:
1805 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_FLAG,
1807 if ((actions_set & mark_actions_mask) != 0)
1808 goto fail_actions_overlap;
1810 if ((dp_rx_features & SFC_DP_RX_FEAT_FLOW_FLAG) == 0) {
1811 rte_flow_error_set(error, ENOTSUP,
1812 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1813 "FLAG action is not supported on the current Rx datapath");
1817 spec_filter->template.efs_flags |=
1818 EFX_FILTER_FLAG_ACTION_FLAG;
1821 case RTE_FLOW_ACTION_TYPE_MARK:
1822 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_MARK,
1824 if ((actions_set & mark_actions_mask) != 0)
1825 goto fail_actions_overlap;
1827 if ((dp_rx_features & SFC_DP_RX_FEAT_FLOW_MARK) == 0) {
1828 rte_flow_error_set(error, ENOTSUP,
1829 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1830 "MARK action is not supported on the current Rx datapath");
1834 rc = sfc_flow_parse_mark(sa, actions->conf, flow);
1836 rte_flow_error_set(error, rc,
1837 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1844 rte_flow_error_set(error, ENOTSUP,
1845 RTE_FLOW_ERROR_TYPE_ACTION, actions,
1846 "Action is not supported");
1850 actions_set |= (1UL << actions->type);
1853 /* When fate is unknown, drop traffic. */
1854 if ((actions_set & fate_actions_mask) == 0) {
1855 spec_filter->template.efs_dmaq_id =
1856 EFX_FILTER_SPEC_RX_DMAQ_ID_DROP;
1862 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, actions,
1863 "Cannot combine several fate-deciding actions, "
1864 "choose between QUEUE, RSS or DROP");
1867 fail_actions_overlap:
1868 rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, actions,
1869 "Overlapping actions are not supported");
1874 * Set the EFX_FILTER_MATCH_UNKNOWN_UCAST_DST
1875 * and EFX_FILTER_MATCH_UNKNOWN_MCAST_DST match flags in the same
1876 * specifications after copying.
1878 * @param spec[in, out]
1879 * SFC flow specification to update.
1880 * @param filters_count_for_one_val[in]
1881 * How many specifications should have the same match flag, what is the
1882 * number of specifications before copying.
1884 * Perform verbose error reporting if not NULL.
1887 sfc_flow_set_unknown_dst_flags(struct sfc_flow_spec *spec,
1888 unsigned int filters_count_for_one_val,
1889 struct rte_flow_error *error)
1892 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1893 static const efx_filter_match_flags_t vals[] = {
1894 EFX_FILTER_MATCH_UNKNOWN_UCAST_DST,
1895 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST
1898 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
1899 rte_flow_error_set(error, EINVAL,
1900 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1901 "Number of specifications is incorrect while copying "
1902 "by unknown destination flags");
1906 for (i = 0; i < spec_filter->count; i++) {
1907 /* The check above ensures that divisor can't be zero here */
1908 spec_filter->filters[i].efs_match_flags |=
1909 vals[i / filters_count_for_one_val];
1916 * Check that the following conditions are met:
1917 * - the list of supported filters has a filter
1918 * with EFX_FILTER_MATCH_UNKNOWN_MCAST_DST flag instead of
1919 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST, since this filter will also
1923 * The match flags of filter.
1925 * Specification to be supplemented.
1927 * SFC filter with list of supported filters.
1930 sfc_flow_check_unknown_dst_flags(efx_filter_match_flags_t match,
1931 __rte_unused efx_filter_spec_t *spec,
1932 struct sfc_filter *filter)
1935 efx_filter_match_flags_t match_mcast_dst;
1938 (match & ~EFX_FILTER_MATCH_UNKNOWN_UCAST_DST) |
1939 EFX_FILTER_MATCH_UNKNOWN_MCAST_DST;
1940 for (i = 0; i < filter->supported_match_num; i++) {
1941 if (match_mcast_dst == filter->supported_match[i])
1949 * Set the EFX_FILTER_MATCH_ETHER_TYPE match flag and EFX_ETHER_TYPE_IPV4 and
1950 * EFX_ETHER_TYPE_IPV6 values of the corresponding field in the same
1951 * specifications after copying.
1953 * @param spec[in, out]
1954 * SFC flow specification to update.
1955 * @param filters_count_for_one_val[in]
1956 * How many specifications should have the same EtherType value, what is the
1957 * number of specifications before copying.
1959 * Perform verbose error reporting if not NULL.
1962 sfc_flow_set_ethertypes(struct sfc_flow_spec *spec,
1963 unsigned int filters_count_for_one_val,
1964 struct rte_flow_error *error)
1967 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
1968 static const uint16_t vals[] = {
1969 EFX_ETHER_TYPE_IPV4, EFX_ETHER_TYPE_IPV6
1972 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
1973 rte_flow_error_set(error, EINVAL,
1974 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1975 "Number of specifications is incorrect "
1976 "while copying by Ethertype");
1980 for (i = 0; i < spec_filter->count; i++) {
1981 spec_filter->filters[i].efs_match_flags |=
1982 EFX_FILTER_MATCH_ETHER_TYPE;
1985 * The check above ensures that
1986 * filters_count_for_one_val is not 0
1988 spec_filter->filters[i].efs_ether_type =
1989 vals[i / filters_count_for_one_val];
1996 * Set the EFX_FILTER_MATCH_OUTER_VID match flag with value 0
1997 * in the same specifications after copying.
1999 * @param spec[in, out]
2000 * SFC flow specification to update.
2001 * @param filters_count_for_one_val[in]
2002 * How many specifications should have the same match flag, what is the
2003 * number of specifications before copying.
2005 * Perform verbose error reporting if not NULL.
2008 sfc_flow_set_outer_vid_flag(struct sfc_flow_spec *spec,
2009 unsigned int filters_count_for_one_val,
2010 struct rte_flow_error *error)
2012 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2015 if (filters_count_for_one_val != spec_filter->count) {
2016 rte_flow_error_set(error, EINVAL,
2017 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2018 "Number of specifications is incorrect "
2019 "while copying by outer VLAN ID");
2023 for (i = 0; i < spec_filter->count; i++) {
2024 spec_filter->filters[i].efs_match_flags |=
2025 EFX_FILTER_MATCH_OUTER_VID;
2027 spec_filter->filters[i].efs_outer_vid = 0;
2034 * Set the EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST and
2035 * EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST match flags in the same
2036 * 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_ifrm_unknown_dst_flags(struct sfc_flow_spec *spec,
2048 unsigned int filters_count_for_one_val,
2049 struct rte_flow_error *error)
2052 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2053 static const efx_filter_match_flags_t vals[] = {
2054 EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST,
2055 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST
2058 if (filters_count_for_one_val * RTE_DIM(vals) != spec_filter->count) {
2059 rte_flow_error_set(error, EINVAL,
2060 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2061 "Number of specifications is incorrect while copying "
2062 "by inner frame unknown destination flags");
2066 for (i = 0; i < spec_filter->count; i++) {
2067 /* The check above ensures that divisor can't be zero here */
2068 spec_filter->filters[i].efs_match_flags |=
2069 vals[i / filters_count_for_one_val];
2076 * Check that the following conditions are met:
2077 * - the specification corresponds to a filter for encapsulated traffic
2078 * - the list of supported filters has a filter
2079 * with EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST flag instead of
2080 * EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST, since this filter will also
2084 * The match flags of filter.
2086 * Specification to be supplemented.
2088 * SFC filter with list of supported filters.
2091 sfc_flow_check_ifrm_unknown_dst_flags(efx_filter_match_flags_t match,
2092 efx_filter_spec_t *spec,
2093 struct sfc_filter *filter)
2096 efx_tunnel_protocol_t encap_type = spec->efs_encap_type;
2097 efx_filter_match_flags_t match_mcast_dst;
2099 if (encap_type == EFX_TUNNEL_PROTOCOL_NONE)
2103 (match & ~EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST) |
2104 EFX_FILTER_MATCH_IFRM_UNKNOWN_MCAST_DST;
2105 for (i = 0; i < filter->supported_match_num; i++) {
2106 if (match_mcast_dst == filter->supported_match[i])
2114 * Check that the list of supported filters has a filter that differs
2115 * from @p match in that it has no flag EFX_FILTER_MATCH_OUTER_VID
2116 * in this case that filter will be used and the flag
2117 * EFX_FILTER_MATCH_OUTER_VID is not needed.
2120 * The match flags of filter.
2122 * Specification to be supplemented.
2124 * SFC filter with list of supported filters.
2127 sfc_flow_check_outer_vid_flag(efx_filter_match_flags_t match,
2128 __rte_unused efx_filter_spec_t *spec,
2129 struct sfc_filter *filter)
2132 efx_filter_match_flags_t match_without_vid =
2133 match & ~EFX_FILTER_MATCH_OUTER_VID;
2135 for (i = 0; i < filter->supported_match_num; i++) {
2136 if (match_without_vid == filter->supported_match[i])
2144 * Match flags that can be automatically added to filters.
2145 * Selecting the last minimum when searching for the copy flag ensures that the
2146 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST flag has a higher priority than
2147 * EFX_FILTER_MATCH_ETHER_TYPE. This is because the filter
2148 * EFX_FILTER_MATCH_UNKNOWN_UCAST_DST is at the end of the list of supported
2151 static const struct sfc_flow_copy_flag sfc_flow_copy_flags[] = {
2153 .flag = EFX_FILTER_MATCH_UNKNOWN_UCAST_DST,
2155 .set_vals = sfc_flow_set_unknown_dst_flags,
2156 .spec_check = sfc_flow_check_unknown_dst_flags,
2159 .flag = EFX_FILTER_MATCH_ETHER_TYPE,
2161 .set_vals = sfc_flow_set_ethertypes,
2165 .flag = EFX_FILTER_MATCH_IFRM_UNKNOWN_UCAST_DST,
2167 .set_vals = sfc_flow_set_ifrm_unknown_dst_flags,
2168 .spec_check = sfc_flow_check_ifrm_unknown_dst_flags,
2171 .flag = EFX_FILTER_MATCH_OUTER_VID,
2173 .set_vals = sfc_flow_set_outer_vid_flag,
2174 .spec_check = sfc_flow_check_outer_vid_flag,
2178 /* Get item from array sfc_flow_copy_flags */
2179 static const struct sfc_flow_copy_flag *
2180 sfc_flow_get_copy_flag(efx_filter_match_flags_t flag)
2184 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
2185 if (sfc_flow_copy_flags[i].flag == flag)
2186 return &sfc_flow_copy_flags[i];
2193 * Make copies of the specifications, set match flag and values
2194 * of the field that corresponds to it.
2196 * @param spec[in, out]
2197 * SFC flow specification to update.
2199 * The match flag to add.
2201 * Perform verbose error reporting if not NULL.
2204 sfc_flow_spec_add_match_flag(struct sfc_flow_spec *spec,
2205 efx_filter_match_flags_t flag,
2206 struct rte_flow_error *error)
2209 unsigned int new_filters_count;
2210 unsigned int filters_count_for_one_val;
2211 const struct sfc_flow_copy_flag *copy_flag;
2212 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2215 copy_flag = sfc_flow_get_copy_flag(flag);
2216 if (copy_flag == NULL) {
2217 rte_flow_error_set(error, ENOTSUP,
2218 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2219 "Unsupported spec field for copying");
2223 new_filters_count = spec_filter->count * copy_flag->vals_count;
2224 if (new_filters_count > SF_FLOW_SPEC_NB_FILTERS_MAX) {
2225 rte_flow_error_set(error, EINVAL,
2226 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2227 "Too much EFX specifications in the flow rule");
2231 /* Copy filters specifications */
2232 for (i = spec_filter->count; i < new_filters_count; i++) {
2233 spec_filter->filters[i] =
2234 spec_filter->filters[i - spec_filter->count];
2237 filters_count_for_one_val = spec_filter->count;
2238 spec_filter->count = new_filters_count;
2240 rc = copy_flag->set_vals(spec, filters_count_for_one_val, error);
2248 * Check that the given set of match flags missing in the original filter spec
2249 * could be covered by adding spec copies which specify the corresponding
2250 * flags and packet field values to match.
2252 * @param miss_flags[in]
2253 * Flags that are missing until the supported filter.
2255 * Specification to be supplemented.
2260 * Number of specifications after copy or 0, if the flags can not be added.
2263 sfc_flow_check_missing_flags(efx_filter_match_flags_t miss_flags,
2264 efx_filter_spec_t *spec,
2265 struct sfc_filter *filter)
2268 efx_filter_match_flags_t copy_flags = 0;
2269 efx_filter_match_flags_t flag;
2270 efx_filter_match_flags_t match = spec->efs_match_flags | miss_flags;
2271 sfc_flow_spec_check *check;
2272 unsigned int multiplier = 1;
2274 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
2275 flag = sfc_flow_copy_flags[i].flag;
2276 check = sfc_flow_copy_flags[i].spec_check;
2277 if ((flag & miss_flags) == flag) {
2278 if (check != NULL && (!check(match, spec, filter)))
2282 multiplier *= sfc_flow_copy_flags[i].vals_count;
2286 if (copy_flags == miss_flags)
2293 * Attempt to supplement the specification template to the minimally
2294 * supported set of match flags. To do this, it is necessary to copy
2295 * the specifications, filling them with the values of fields that
2296 * correspond to the missing flags.
2297 * The necessary and sufficient filter is built from the fewest number
2298 * of copies which could be made to cover the minimally required set
2303 * @param spec[in, out]
2304 * SFC flow specification to update.
2306 * Perform verbose error reporting if not NULL.
2309 sfc_flow_spec_filters_complete(struct sfc_adapter *sa,
2310 struct sfc_flow_spec *spec,
2311 struct rte_flow_error *error)
2313 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2314 struct sfc_filter *filter = &sa->filter;
2315 efx_filter_match_flags_t miss_flags;
2316 efx_filter_match_flags_t min_miss_flags = 0;
2317 efx_filter_match_flags_t match;
2318 unsigned int min_multiplier = UINT_MAX;
2319 unsigned int multiplier;
2323 match = spec_filter->template.efs_match_flags;
2324 for (i = 0; i < filter->supported_match_num; i++) {
2325 if ((match & filter->supported_match[i]) == match) {
2326 miss_flags = filter->supported_match[i] & (~match);
2327 multiplier = sfc_flow_check_missing_flags(miss_flags,
2328 &spec_filter->template, filter);
2329 if (multiplier > 0) {
2330 if (multiplier <= min_multiplier) {
2331 min_multiplier = multiplier;
2332 min_miss_flags = miss_flags;
2338 if (min_multiplier == UINT_MAX) {
2339 rte_flow_error_set(error, ENOTSUP,
2340 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2341 "The flow rule pattern is unsupported");
2345 for (i = 0; i < RTE_DIM(sfc_flow_copy_flags); i++) {
2346 efx_filter_match_flags_t flag = sfc_flow_copy_flags[i].flag;
2348 if ((flag & min_miss_flags) == flag) {
2349 rc = sfc_flow_spec_add_match_flag(spec, flag, error);
2359 * Check that set of match flags is referred to by a filter. Filter is
2360 * described by match flags with the ability to add OUTER_VID and INNER_VID
2363 * @param match_flags[in]
2364 * Set of match flags.
2365 * @param flags_pattern[in]
2366 * Pattern of filter match flags.
2369 sfc_flow_is_match_with_vids(efx_filter_match_flags_t match_flags,
2370 efx_filter_match_flags_t flags_pattern)
2372 if ((match_flags & flags_pattern) != flags_pattern)
2375 switch (match_flags & ~flags_pattern) {
2377 case EFX_FILTER_MATCH_OUTER_VID:
2378 case EFX_FILTER_MATCH_OUTER_VID | EFX_FILTER_MATCH_INNER_VID:
2386 * Check whether the spec maps to a hardware filter which is known to be
2387 * ineffective despite being valid.
2390 * SFC filter with list of supported filters.
2392 * SFC flow specification.
2395 sfc_flow_is_match_flags_exception(struct sfc_filter *filter,
2396 struct sfc_flow_spec *spec)
2399 uint16_t ether_type;
2401 efx_filter_match_flags_t match_flags;
2402 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2404 for (i = 0; i < spec_filter->count; i++) {
2405 match_flags = spec_filter->filters[i].efs_match_flags;
2407 if (sfc_flow_is_match_with_vids(match_flags,
2408 EFX_FILTER_MATCH_ETHER_TYPE) ||
2409 sfc_flow_is_match_with_vids(match_flags,
2410 EFX_FILTER_MATCH_ETHER_TYPE |
2411 EFX_FILTER_MATCH_LOC_MAC)) {
2412 ether_type = spec_filter->filters[i].efs_ether_type;
2413 if (filter->supports_ip_proto_or_addr_filter &&
2414 (ether_type == EFX_ETHER_TYPE_IPV4 ||
2415 ether_type == EFX_ETHER_TYPE_IPV6))
2417 } else if (sfc_flow_is_match_with_vids(match_flags,
2418 EFX_FILTER_MATCH_ETHER_TYPE |
2419 EFX_FILTER_MATCH_IP_PROTO) ||
2420 sfc_flow_is_match_with_vids(match_flags,
2421 EFX_FILTER_MATCH_ETHER_TYPE |
2422 EFX_FILTER_MATCH_IP_PROTO |
2423 EFX_FILTER_MATCH_LOC_MAC)) {
2424 ip_proto = spec_filter->filters[i].efs_ip_proto;
2425 if (filter->supports_rem_or_local_port_filter &&
2426 (ip_proto == EFX_IPPROTO_TCP ||
2427 ip_proto == EFX_IPPROTO_UDP))
2436 sfc_flow_validate_match_flags(struct sfc_adapter *sa,
2437 struct rte_flow *flow,
2438 struct rte_flow_error *error)
2440 struct sfc_flow_spec *spec = &flow->spec;
2441 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2442 efx_filter_spec_t *spec_tmpl = &spec_filter->template;
2443 efx_filter_match_flags_t match_flags = spec_tmpl->efs_match_flags;
2446 /* Initialize the first filter spec with template */
2447 spec_filter->filters[0] = *spec_tmpl;
2448 spec_filter->count = 1;
2450 if (!sfc_filter_is_match_supported(sa, match_flags)) {
2451 rc = sfc_flow_spec_filters_complete(sa, &flow->spec, error);
2456 if (sfc_flow_is_match_flags_exception(&sa->filter, &flow->spec)) {
2457 rte_flow_error_set(error, ENOTSUP,
2458 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2459 "The flow rule pattern is unsupported");
2467 sfc_flow_parse_rte_to_filter(struct rte_eth_dev *dev,
2468 const struct rte_flow_item pattern[],
2469 const struct rte_flow_action actions[],
2470 struct rte_flow *flow,
2471 struct rte_flow_error *error)
2473 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2474 struct sfc_flow_spec *spec = &flow->spec;
2475 struct sfc_flow_spec_filter *spec_filter = &spec->filter;
2476 struct sfc_flow_parse_ctx ctx;
2479 ctx.type = SFC_FLOW_PARSE_CTX_FILTER;
2480 ctx.filter = &spec_filter->template;
2482 rc = sfc_flow_parse_pattern(sfc_flow_items, RTE_DIM(sfc_flow_items),
2483 pattern, &ctx, error);
2485 goto fail_bad_value;
2487 rc = sfc_flow_parse_actions(sa, actions, flow, error);
2489 goto fail_bad_value;
2491 rc = sfc_flow_validate_match_flags(sa, flow, error);
2493 goto fail_bad_value;
2502 sfc_flow_parse_rte_to_mae(struct rte_eth_dev *dev,
2503 const struct rte_flow_item pattern[],
2504 const struct rte_flow_action actions[],
2505 struct rte_flow *flow,
2506 struct rte_flow_error *error)
2508 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2509 struct sfc_flow_spec *spec = &flow->spec;
2510 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
2513 rc = sfc_mae_rule_parse_pattern(sa, pattern, spec_mae, error);
2517 rc = sfc_mae_rule_parse_actions(sa, actions, spec_mae, error);
2525 sfc_flow_parse(struct rte_eth_dev *dev,
2526 const struct rte_flow_attr *attr,
2527 const struct rte_flow_item pattern[],
2528 const struct rte_flow_action actions[],
2529 struct rte_flow *flow,
2530 struct rte_flow_error *error)
2532 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2533 const struct sfc_flow_ops_by_spec *ops;
2536 rc = sfc_flow_parse_attr(sa, attr, flow, error);
2540 ops = sfc_flow_get_ops_by_spec(flow);
2541 if (ops == NULL || ops->parse == NULL) {
2542 rte_flow_error_set(error, ENOTSUP,
2543 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2544 "No backend to handle this flow");
2548 return ops->parse(dev, pattern, actions, flow, error);
2551 static struct rte_flow *
2552 sfc_flow_zmalloc(struct rte_flow_error *error)
2554 struct rte_flow *flow;
2556 flow = rte_zmalloc("sfc_rte_flow", sizeof(*flow), 0);
2558 rte_flow_error_set(error, ENOMEM,
2559 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2560 "Failed to allocate memory");
2567 sfc_flow_free(struct sfc_adapter *sa, struct rte_flow *flow)
2569 const struct sfc_flow_ops_by_spec *ops;
2571 ops = sfc_flow_get_ops_by_spec(flow);
2572 if (ops != NULL && ops->cleanup != NULL)
2573 ops->cleanup(sa, flow);
2579 sfc_flow_insert(struct sfc_adapter *sa, struct rte_flow *flow,
2580 struct rte_flow_error *error)
2582 const struct sfc_flow_ops_by_spec *ops;
2585 ops = sfc_flow_get_ops_by_spec(flow);
2586 if (ops == NULL || ops->insert == NULL) {
2587 rte_flow_error_set(error, ENOTSUP,
2588 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2589 "No backend to handle this flow");
2593 rc = ops->insert(sa, flow);
2595 rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2596 NULL, "Failed to insert the flow rule");
2603 sfc_flow_remove(struct sfc_adapter *sa, struct rte_flow *flow,
2604 struct rte_flow_error *error)
2606 const struct sfc_flow_ops_by_spec *ops;
2609 ops = sfc_flow_get_ops_by_spec(flow);
2610 if (ops == NULL || ops->remove == NULL) {
2611 rte_flow_error_set(error, ENOTSUP,
2612 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2613 "No backend to handle this flow");
2617 rc = ops->remove(sa, flow);
2619 rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2620 NULL, "Failed to remove the flow rule");
2627 sfc_flow_verify(struct sfc_adapter *sa, struct rte_flow *flow,
2628 struct rte_flow_error *error)
2630 const struct sfc_flow_ops_by_spec *ops;
2633 ops = sfc_flow_get_ops_by_spec(flow);
2635 rte_flow_error_set(error, ENOTSUP,
2636 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2637 "No backend to handle this flow");
2641 if (ops->verify != NULL) {
2642 SFC_ASSERT(sfc_adapter_is_locked(sa));
2643 rc = ops->verify(sa, flow);
2647 rte_flow_error_set(error, rc,
2648 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2649 "Failed to verify flow validity with FW");
2657 sfc_flow_validate(struct rte_eth_dev *dev,
2658 const struct rte_flow_attr *attr,
2659 const struct rte_flow_item pattern[],
2660 const struct rte_flow_action actions[],
2661 struct rte_flow_error *error)
2663 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2664 struct rte_flow *flow;
2667 flow = sfc_flow_zmalloc(error);
2671 sfc_adapter_lock(sa);
2673 rc = sfc_flow_parse(dev, attr, pattern, actions, flow, error);
2675 rc = sfc_flow_verify(sa, flow, error);
2677 sfc_flow_free(sa, flow);
2679 sfc_adapter_unlock(sa);
2684 static struct rte_flow *
2685 sfc_flow_create(struct rte_eth_dev *dev,
2686 const struct rte_flow_attr *attr,
2687 const struct rte_flow_item pattern[],
2688 const struct rte_flow_action actions[],
2689 struct rte_flow_error *error)
2691 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2692 struct rte_flow *flow = NULL;
2695 flow = sfc_flow_zmalloc(error);
2699 sfc_adapter_lock(sa);
2701 rc = sfc_flow_parse(dev, attr, pattern, actions, flow, error);
2703 goto fail_bad_value;
2705 TAILQ_INSERT_TAIL(&sa->flow_list, flow, entries);
2707 if (sa->state == SFC_ADAPTER_STARTED) {
2708 rc = sfc_flow_insert(sa, flow, error);
2710 goto fail_flow_insert;
2713 sfc_adapter_unlock(sa);
2718 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2721 sfc_flow_free(sa, flow);
2722 sfc_adapter_unlock(sa);
2729 sfc_flow_destroy(struct rte_eth_dev *dev,
2730 struct rte_flow *flow,
2731 struct rte_flow_error *error)
2733 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2734 struct rte_flow *flow_ptr;
2737 sfc_adapter_lock(sa);
2739 TAILQ_FOREACH(flow_ptr, &sa->flow_list, entries) {
2740 if (flow_ptr == flow)
2744 rte_flow_error_set(error, rc,
2745 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
2746 "Failed to find flow rule to destroy");
2747 goto fail_bad_value;
2750 if (sa->state == SFC_ADAPTER_STARTED)
2751 rc = sfc_flow_remove(sa, flow, error);
2753 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2754 sfc_flow_free(sa, flow);
2757 sfc_adapter_unlock(sa);
2763 sfc_flow_flush(struct rte_eth_dev *dev,
2764 struct rte_flow_error *error)
2766 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2767 struct rte_flow *flow;
2770 sfc_adapter_lock(sa);
2772 while ((flow = TAILQ_FIRST(&sa->flow_list)) != NULL) {
2773 if (sa->state == SFC_ADAPTER_STARTED) {
2776 rc = sfc_flow_remove(sa, flow, error);
2781 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2782 sfc_flow_free(sa, flow);
2785 sfc_adapter_unlock(sa);
2791 sfc_flow_isolate(struct rte_eth_dev *dev, int enable,
2792 struct rte_flow_error *error)
2794 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2797 sfc_adapter_lock(sa);
2798 if (sa->state != SFC_ADAPTER_INITIALIZED) {
2799 rte_flow_error_set(error, EBUSY,
2800 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2801 NULL, "please close the port first");
2804 sfc_sa2shared(sa)->isolated = (enable) ? B_TRUE : B_FALSE;
2806 sfc_adapter_unlock(sa);
2811 const struct rte_flow_ops sfc_flow_ops = {
2812 .validate = sfc_flow_validate,
2813 .create = sfc_flow_create,
2814 .destroy = sfc_flow_destroy,
2815 .flush = sfc_flow_flush,
2817 .isolate = sfc_flow_isolate,
2821 sfc_flow_init(struct sfc_adapter *sa)
2823 SFC_ASSERT(sfc_adapter_is_locked(sa));
2825 TAILQ_INIT(&sa->flow_list);
2829 sfc_flow_fini(struct sfc_adapter *sa)
2831 struct rte_flow *flow;
2833 SFC_ASSERT(sfc_adapter_is_locked(sa));
2835 while ((flow = TAILQ_FIRST(&sa->flow_list)) != NULL) {
2836 TAILQ_REMOVE(&sa->flow_list, flow, entries);
2837 sfc_flow_free(sa, flow);
2842 sfc_flow_stop(struct sfc_adapter *sa)
2844 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
2845 struct sfc_rss *rss = &sas->rss;
2846 struct rte_flow *flow;
2848 SFC_ASSERT(sfc_adapter_is_locked(sa));
2850 TAILQ_FOREACH(flow, &sa->flow_list, entries)
2851 sfc_flow_remove(sa, flow, NULL);
2853 if (rss->dummy_rss_context != EFX_RSS_CONTEXT_DEFAULT) {
2854 efx_rx_scale_context_free(sa->nic, rss->dummy_rss_context);
2855 rss->dummy_rss_context = EFX_RSS_CONTEXT_DEFAULT;
2860 sfc_flow_start(struct sfc_adapter *sa)
2862 struct rte_flow *flow;
2865 sfc_log_init(sa, "entry");
2867 SFC_ASSERT(sfc_adapter_is_locked(sa));
2869 TAILQ_FOREACH(flow, &sa->flow_list, entries) {
2870 rc = sfc_flow_insert(sa, flow, NULL);
2875 sfc_log_init(sa, "done");