1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2019-2020 Xilinx, Inc.
4 * Copyright(c) 2019 Solarflare Communications Inc.
6 * This software was jointly developed between OKTET Labs (under contract
7 * for Solarflare) and Solarflare Communications, Inc.
12 #include <rte_common.h>
18 #include "sfc_switch.h"
21 sfc_mae_assign_entity_mport(struct sfc_adapter *sa,
22 efx_mport_sel_t *mportp)
24 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
26 return efx_mae_mport_by_pcie_function(encp->enc_pf, encp->enc_vf,
31 sfc_mae_attach(struct sfc_adapter *sa)
33 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
34 struct sfc_mae_switch_port_request switch_port_request = {0};
35 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
36 efx_mport_sel_t entity_mport;
37 struct sfc_mae *mae = &sa->mae;
38 efx_mae_limits_t limits;
41 sfc_log_init(sa, "entry");
43 if (!encp->enc_mae_supported) {
44 mae->status = SFC_MAE_STATUS_UNSUPPORTED;
48 sfc_log_init(sa, "init MAE");
49 rc = efx_mae_init(sa->nic);
53 sfc_log_init(sa, "get MAE limits");
54 rc = efx_mae_get_limits(sa->nic, &limits);
56 goto fail_mae_get_limits;
58 sfc_log_init(sa, "assign entity MPORT");
59 rc = sfc_mae_assign_entity_mport(sa, &entity_mport);
61 goto fail_mae_assign_entity_mport;
63 sfc_log_init(sa, "assign RTE switch domain");
64 rc = sfc_mae_assign_switch_domain(sa, &mae->switch_domain_id);
66 goto fail_mae_assign_switch_domain;
68 sfc_log_init(sa, "assign RTE switch port");
69 switch_port_request.type = SFC_MAE_SWITCH_PORT_INDEPENDENT;
70 switch_port_request.entity_mportp = &entity_mport;
72 * As of now, the driver does not support representors, so
73 * RTE ethdev MPORT simply matches that of the entity.
75 switch_port_request.ethdev_mportp = &entity_mport;
76 switch_port_request.ethdev_port_id = sas->port_id;
77 rc = sfc_mae_assign_switch_port(mae->switch_domain_id,
79 &mae->switch_port_id);
81 goto fail_mae_assign_switch_port;
83 mae->status = SFC_MAE_STATUS_SUPPORTED;
84 mae->nb_outer_rule_prios_max = limits.eml_max_n_outer_prios;
85 mae->nb_action_rule_prios_max = limits.eml_max_n_action_prios;
86 mae->encap_types_supported = limits.eml_encap_types_supported;
87 TAILQ_INIT(&mae->outer_rules);
88 TAILQ_INIT(&mae->action_sets);
90 sfc_log_init(sa, "done");
94 fail_mae_assign_switch_port:
95 fail_mae_assign_switch_domain:
96 fail_mae_assign_entity_mport:
98 efx_mae_fini(sa->nic);
101 sfc_log_init(sa, "failed %d", rc);
107 sfc_mae_detach(struct sfc_adapter *sa)
109 struct sfc_mae *mae = &sa->mae;
110 enum sfc_mae_status status_prev = mae->status;
112 sfc_log_init(sa, "entry");
114 mae->nb_action_rule_prios_max = 0;
115 mae->status = SFC_MAE_STATUS_UNKNOWN;
117 if (status_prev != SFC_MAE_STATUS_SUPPORTED)
120 efx_mae_fini(sa->nic);
122 sfc_log_init(sa, "done");
125 static struct sfc_mae_outer_rule *
126 sfc_mae_outer_rule_attach(struct sfc_adapter *sa,
127 const efx_mae_match_spec_t *match_spec,
128 efx_tunnel_protocol_t encap_type)
130 struct sfc_mae_outer_rule *rule;
131 struct sfc_mae *mae = &sa->mae;
133 SFC_ASSERT(sfc_adapter_is_locked(sa));
135 TAILQ_FOREACH(rule, &mae->outer_rules, entries) {
136 if (efx_mae_match_specs_equal(rule->match_spec, match_spec) &&
137 rule->encap_type == encap_type) {
147 sfc_mae_outer_rule_add(struct sfc_adapter *sa,
148 efx_mae_match_spec_t *match_spec,
149 efx_tunnel_protocol_t encap_type,
150 struct sfc_mae_outer_rule **rulep)
152 struct sfc_mae_outer_rule *rule;
153 struct sfc_mae *mae = &sa->mae;
155 SFC_ASSERT(sfc_adapter_is_locked(sa));
157 rule = rte_zmalloc("sfc_mae_outer_rule", sizeof(*rule), 0);
162 rule->match_spec = match_spec;
163 rule->encap_type = encap_type;
165 rule->fw_rsrc.rule_id.id = EFX_MAE_RSRC_ID_INVALID;
167 TAILQ_INSERT_TAIL(&mae->outer_rules, rule, entries);
175 sfc_mae_outer_rule_del(struct sfc_adapter *sa,
176 struct sfc_mae_outer_rule *rule)
178 struct sfc_mae *mae = &sa->mae;
180 SFC_ASSERT(sfc_adapter_is_locked(sa));
181 SFC_ASSERT(rule->refcnt != 0);
185 if (rule->refcnt != 0)
188 SFC_ASSERT(rule->fw_rsrc.rule_id.id == EFX_MAE_RSRC_ID_INVALID);
189 SFC_ASSERT(rule->fw_rsrc.refcnt == 0);
191 efx_mae_match_spec_fini(sa->nic, rule->match_spec);
193 TAILQ_REMOVE(&mae->outer_rules, rule, entries);
198 sfc_mae_outer_rule_enable(struct sfc_adapter *sa,
199 struct sfc_mae_outer_rule *rule,
200 efx_mae_match_spec_t *match_spec_action)
202 struct sfc_mae_fw_rsrc *fw_rsrc = &rule->fw_rsrc;
205 SFC_ASSERT(sfc_adapter_is_locked(sa));
207 if (fw_rsrc->refcnt == 0) {
208 SFC_ASSERT(fw_rsrc->rule_id.id == EFX_MAE_RSRC_ID_INVALID);
209 SFC_ASSERT(rule->match_spec != NULL);
211 rc = efx_mae_outer_rule_insert(sa->nic, rule->match_spec,
218 rc = efx_mae_match_spec_outer_rule_id_set(match_spec_action,
221 if (fw_rsrc->refcnt == 0) {
222 (void)efx_mae_outer_rule_remove(sa->nic,
234 sfc_mae_outer_rule_disable(struct sfc_adapter *sa,
235 struct sfc_mae_outer_rule *rule)
237 struct sfc_mae_fw_rsrc *fw_rsrc = &rule->fw_rsrc;
240 SFC_ASSERT(sfc_adapter_is_locked(sa));
241 SFC_ASSERT(fw_rsrc->rule_id.id != EFX_MAE_RSRC_ID_INVALID);
242 SFC_ASSERT(fw_rsrc->refcnt != 0);
244 if (fw_rsrc->refcnt == 1) {
245 rc = efx_mae_outer_rule_remove(sa->nic, &fw_rsrc->rule_id);
249 fw_rsrc->rule_id.id = EFX_MAE_RSRC_ID_INVALID;
257 static struct sfc_mae_action_set *
258 sfc_mae_action_set_attach(struct sfc_adapter *sa,
259 const efx_mae_actions_t *spec)
261 struct sfc_mae_action_set *action_set;
262 struct sfc_mae *mae = &sa->mae;
264 SFC_ASSERT(sfc_adapter_is_locked(sa));
266 TAILQ_FOREACH(action_set, &mae->action_sets, entries) {
267 if (efx_mae_action_set_specs_equal(action_set->spec, spec)) {
268 ++(action_set->refcnt);
277 sfc_mae_action_set_add(struct sfc_adapter *sa,
278 efx_mae_actions_t *spec,
279 struct sfc_mae_action_set **action_setp)
281 struct sfc_mae_action_set *action_set;
282 struct sfc_mae *mae = &sa->mae;
284 SFC_ASSERT(sfc_adapter_is_locked(sa));
286 action_set = rte_zmalloc("sfc_mae_action_set", sizeof(*action_set), 0);
287 if (action_set == NULL)
290 action_set->refcnt = 1;
291 action_set->spec = spec;
293 action_set->fw_rsrc.aset_id.id = EFX_MAE_RSRC_ID_INVALID;
295 TAILQ_INSERT_TAIL(&mae->action_sets, action_set, entries);
297 *action_setp = action_set;
303 sfc_mae_action_set_del(struct sfc_adapter *sa,
304 struct sfc_mae_action_set *action_set)
306 struct sfc_mae *mae = &sa->mae;
308 SFC_ASSERT(sfc_adapter_is_locked(sa));
309 SFC_ASSERT(action_set->refcnt != 0);
311 --(action_set->refcnt);
313 if (action_set->refcnt != 0)
316 SFC_ASSERT(action_set->fw_rsrc.aset_id.id == EFX_MAE_RSRC_ID_INVALID);
317 SFC_ASSERT(action_set->fw_rsrc.refcnt == 0);
319 efx_mae_action_set_spec_fini(sa->nic, action_set->spec);
320 TAILQ_REMOVE(&mae->action_sets, action_set, entries);
321 rte_free(action_set);
325 sfc_mae_action_set_enable(struct sfc_adapter *sa,
326 struct sfc_mae_action_set *action_set)
328 struct sfc_mae_fw_rsrc *fw_rsrc = &action_set->fw_rsrc;
331 SFC_ASSERT(sfc_adapter_is_locked(sa));
333 if (fw_rsrc->refcnt == 0) {
334 SFC_ASSERT(fw_rsrc->aset_id.id == EFX_MAE_RSRC_ID_INVALID);
335 SFC_ASSERT(action_set->spec != NULL);
337 rc = efx_mae_action_set_alloc(sa->nic, action_set->spec,
349 sfc_mae_action_set_disable(struct sfc_adapter *sa,
350 struct sfc_mae_action_set *action_set)
352 struct sfc_mae_fw_rsrc *fw_rsrc = &action_set->fw_rsrc;
355 SFC_ASSERT(sfc_adapter_is_locked(sa));
356 SFC_ASSERT(fw_rsrc->aset_id.id != EFX_MAE_RSRC_ID_INVALID);
357 SFC_ASSERT(fw_rsrc->refcnt != 0);
359 if (fw_rsrc->refcnt == 1) {
360 rc = efx_mae_action_set_free(sa->nic, &fw_rsrc->aset_id);
364 fw_rsrc->aset_id.id = EFX_MAE_RSRC_ID_INVALID;
373 sfc_mae_flow_cleanup(struct sfc_adapter *sa,
374 struct rte_flow *flow)
376 struct sfc_flow_spec *spec;
377 struct sfc_flow_spec_mae *spec_mae;
387 spec_mae = &spec->mae;
389 SFC_ASSERT(spec_mae->rule_id.id == EFX_MAE_RSRC_ID_INVALID);
391 if (spec_mae->outer_rule != NULL)
392 sfc_mae_outer_rule_del(sa, spec_mae->outer_rule);
394 if (spec_mae->action_set != NULL)
395 sfc_mae_action_set_del(sa, spec_mae->action_set);
397 if (spec_mae->match_spec != NULL)
398 efx_mae_match_spec_fini(sa->nic, spec_mae->match_spec);
402 sfc_mae_set_ethertypes(struct sfc_mae_parse_ctx *ctx)
404 struct sfc_mae_pattern_data *pdata = &ctx->pattern_data;
405 const efx_mae_field_id_t *fremap = ctx->field_ids_remap;
406 const efx_mae_field_id_t field_ids[] = {
407 EFX_MAE_FIELD_VLAN0_PROTO_BE,
408 EFX_MAE_FIELD_VLAN1_PROTO_BE,
410 const struct sfc_mae_ethertype *et;
415 * In accordance with RTE flow API convention, the innermost L2
416 * item's "type" ("inner_type") is a L3 EtherType. If there is
417 * no L3 item, it's 0x0000/0x0000.
419 et = &pdata->ethertypes[pdata->nb_vlan_tags];
420 rc = efx_mae_match_spec_field_set(ctx->match_spec,
421 fremap[EFX_MAE_FIELD_ETHER_TYPE_BE],
423 (const uint8_t *)&et->value,
425 (const uint8_t *)&et->mask);
430 * sfc_mae_rule_parse_item_vlan() has already made sure
431 * that pdata->nb_vlan_tags does not exceed this figure.
433 RTE_BUILD_BUG_ON(SFC_MAE_MATCH_VLAN_MAX_NTAGS != 2);
435 for (i = 0; i < pdata->nb_vlan_tags; ++i) {
436 et = &pdata->ethertypes[i];
438 rc = efx_mae_match_spec_field_set(ctx->match_spec,
439 fremap[field_ids[i]],
441 (const uint8_t *)&et->value,
443 (const uint8_t *)&et->mask);
452 sfc_mae_rule_process_pattern_data(struct sfc_mae_parse_ctx *ctx,
453 struct rte_flow_error *error)
455 const efx_mae_field_id_t *fremap = ctx->field_ids_remap;
456 struct sfc_mae_pattern_data *pdata = &ctx->pattern_data;
457 struct sfc_mae_ethertype *ethertypes = pdata->ethertypes;
458 const rte_be16_t supported_tpids[] = {
459 /* VLAN standard TPID (always the first element) */
460 RTE_BE16(RTE_ETHER_TYPE_VLAN),
462 /* Double-tagging TPIDs */
463 RTE_BE16(RTE_ETHER_TYPE_QINQ),
464 RTE_BE16(RTE_ETHER_TYPE_QINQ1),
465 RTE_BE16(RTE_ETHER_TYPE_QINQ2),
466 RTE_BE16(RTE_ETHER_TYPE_QINQ3),
468 unsigned int nb_supported_tpids = RTE_DIM(supported_tpids);
469 unsigned int ethertype_idx;
470 const uint8_t *valuep;
471 const uint8_t *maskp;
474 if (pdata->innermost_ethertype_restriction.mask != 0 &&
475 pdata->nb_vlan_tags < SFC_MAE_MATCH_VLAN_MAX_NTAGS) {
477 * If a single item VLAN is followed by a L3 item, value
478 * of "type" in item ETH can't be a double-tagging TPID.
480 nb_supported_tpids = 1;
484 * sfc_mae_rule_parse_item_vlan() has already made sure
485 * that pdata->nb_vlan_tags does not exceed this figure.
487 RTE_BUILD_BUG_ON(SFC_MAE_MATCH_VLAN_MAX_NTAGS != 2);
489 for (ethertype_idx = 0;
490 ethertype_idx < pdata->nb_vlan_tags; ++ethertype_idx) {
491 unsigned int tpid_idx;
493 /* Exact match is supported only. */
494 if (ethertypes[ethertype_idx].mask != RTE_BE16(0xffff)) {
499 for (tpid_idx = pdata->nb_vlan_tags - ethertype_idx - 1;
500 tpid_idx < nb_supported_tpids; ++tpid_idx) {
501 if (ethertypes[ethertype_idx].value ==
502 supported_tpids[tpid_idx])
506 if (tpid_idx == nb_supported_tpids) {
511 nb_supported_tpids = 1;
514 if (pdata->innermost_ethertype_restriction.mask == RTE_BE16(0xffff)) {
515 struct sfc_mae_ethertype *et = ðertypes[ethertype_idx];
518 et->mask = RTE_BE16(0xffff);
520 pdata->innermost_ethertype_restriction.value;
521 } else if (et->mask != RTE_BE16(0xffff) ||
523 pdata->innermost_ethertype_restriction.value) {
530 * Now, when the number of VLAN tags is known, set fields
531 * ETHER_TYPE, VLAN0_PROTO and VLAN1_PROTO so that the first
532 * one is either a valid L3 EtherType (or 0x0000/0x0000),
533 * and the last two are valid TPIDs (or 0x0000/0x0000).
535 rc = sfc_mae_set_ethertypes(ctx);
539 if (pdata->l3_next_proto_restriction_mask == 0xff) {
540 if (pdata->l3_next_proto_mask == 0) {
541 pdata->l3_next_proto_mask = 0xff;
542 pdata->l3_next_proto_value =
543 pdata->l3_next_proto_restriction_value;
544 } else if (pdata->l3_next_proto_mask != 0xff ||
545 pdata->l3_next_proto_value !=
546 pdata->l3_next_proto_restriction_value) {
552 valuep = (const uint8_t *)&pdata->l3_next_proto_value;
553 maskp = (const uint8_t *)&pdata->l3_next_proto_mask;
554 rc = efx_mae_match_spec_field_set(ctx->match_spec,
555 fremap[EFX_MAE_FIELD_IP_PROTO],
556 sizeof(pdata->l3_next_proto_value),
558 sizeof(pdata->l3_next_proto_mask),
566 return rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM, NULL,
567 "Failed to process pattern data");
571 sfc_mae_rule_parse_item_port_id(const struct rte_flow_item *item,
572 struct sfc_flow_parse_ctx *ctx,
573 struct rte_flow_error *error)
575 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
576 const struct rte_flow_item_port_id supp_mask = {
579 const void *def_mask = &rte_flow_item_port_id_mask;
580 const struct rte_flow_item_port_id *spec = NULL;
581 const struct rte_flow_item_port_id *mask = NULL;
582 efx_mport_sel_t mport_sel;
585 if (ctx_mae->match_mport_set) {
586 return rte_flow_error_set(error, ENOTSUP,
587 RTE_FLOW_ERROR_TYPE_ITEM, item,
588 "Can't handle multiple traffic source items");
591 rc = sfc_flow_parse_init(item,
592 (const void **)&spec, (const void **)&mask,
593 (const void *)&supp_mask, def_mask,
594 sizeof(struct rte_flow_item_port_id), error);
598 if (mask->id != supp_mask.id) {
599 return rte_flow_error_set(error, EINVAL,
600 RTE_FLOW_ERROR_TYPE_ITEM, item,
601 "Bad mask in the PORT_ID pattern item");
604 /* If "spec" is not set, could be any port ID */
608 if (spec->id > UINT16_MAX) {
609 return rte_flow_error_set(error, EOVERFLOW,
610 RTE_FLOW_ERROR_TYPE_ITEM, item,
611 "The port ID is too large");
614 rc = sfc_mae_switch_port_by_ethdev(ctx_mae->sa->mae.switch_domain_id,
615 spec->id, &mport_sel);
617 return rte_flow_error_set(error, rc,
618 RTE_FLOW_ERROR_TYPE_ITEM, item,
619 "Can't find RTE ethdev by the port ID");
622 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec,
625 return rte_flow_error_set(error, rc,
626 RTE_FLOW_ERROR_TYPE_ITEM, item,
627 "Failed to set MPORT for the port ID");
630 ctx_mae->match_mport_set = B_TRUE;
636 sfc_mae_rule_parse_item_phy_port(const struct rte_flow_item *item,
637 struct sfc_flow_parse_ctx *ctx,
638 struct rte_flow_error *error)
640 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
641 const struct rte_flow_item_phy_port supp_mask = {
644 const void *def_mask = &rte_flow_item_phy_port_mask;
645 const struct rte_flow_item_phy_port *spec = NULL;
646 const struct rte_flow_item_phy_port *mask = NULL;
647 efx_mport_sel_t mport_v;
650 if (ctx_mae->match_mport_set) {
651 return rte_flow_error_set(error, ENOTSUP,
652 RTE_FLOW_ERROR_TYPE_ITEM, item,
653 "Can't handle multiple traffic source items");
656 rc = sfc_flow_parse_init(item,
657 (const void **)&spec, (const void **)&mask,
658 (const void *)&supp_mask, def_mask,
659 sizeof(struct rte_flow_item_phy_port), error);
663 if (mask->index != supp_mask.index) {
664 return rte_flow_error_set(error, EINVAL,
665 RTE_FLOW_ERROR_TYPE_ITEM, item,
666 "Bad mask in the PHY_PORT pattern item");
669 /* If "spec" is not set, could be any physical port */
673 rc = efx_mae_mport_by_phy_port(spec->index, &mport_v);
675 return rte_flow_error_set(error, rc,
676 RTE_FLOW_ERROR_TYPE_ITEM, item,
677 "Failed to convert the PHY_PORT index");
680 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec, &mport_v, NULL);
682 return rte_flow_error_set(error, rc,
683 RTE_FLOW_ERROR_TYPE_ITEM, item,
684 "Failed to set MPORT for the PHY_PORT");
687 ctx_mae->match_mport_set = B_TRUE;
693 sfc_mae_rule_parse_item_pf(const struct rte_flow_item *item,
694 struct sfc_flow_parse_ctx *ctx,
695 struct rte_flow_error *error)
697 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
698 const efx_nic_cfg_t *encp = efx_nic_cfg_get(ctx_mae->sa->nic);
699 efx_mport_sel_t mport_v;
702 if (ctx_mae->match_mport_set) {
703 return rte_flow_error_set(error, ENOTSUP,
704 RTE_FLOW_ERROR_TYPE_ITEM, item,
705 "Can't handle multiple traffic source items");
708 rc = efx_mae_mport_by_pcie_function(encp->enc_pf, EFX_PCI_VF_INVALID,
711 return rte_flow_error_set(error, rc,
712 RTE_FLOW_ERROR_TYPE_ITEM, item,
713 "Failed to convert the PF ID");
716 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec, &mport_v, NULL);
718 return rte_flow_error_set(error, rc,
719 RTE_FLOW_ERROR_TYPE_ITEM, item,
720 "Failed to set MPORT for the PF");
723 ctx_mae->match_mport_set = B_TRUE;
729 sfc_mae_rule_parse_item_vf(const struct rte_flow_item *item,
730 struct sfc_flow_parse_ctx *ctx,
731 struct rte_flow_error *error)
733 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
734 const efx_nic_cfg_t *encp = efx_nic_cfg_get(ctx_mae->sa->nic);
735 const struct rte_flow_item_vf supp_mask = {
738 const void *def_mask = &rte_flow_item_vf_mask;
739 const struct rte_flow_item_vf *spec = NULL;
740 const struct rte_flow_item_vf *mask = NULL;
741 efx_mport_sel_t mport_v;
744 if (ctx_mae->match_mport_set) {
745 return rte_flow_error_set(error, ENOTSUP,
746 RTE_FLOW_ERROR_TYPE_ITEM, item,
747 "Can't handle multiple traffic source items");
750 rc = sfc_flow_parse_init(item,
751 (const void **)&spec, (const void **)&mask,
752 (const void *)&supp_mask, def_mask,
753 sizeof(struct rte_flow_item_vf), error);
757 if (mask->id != supp_mask.id) {
758 return rte_flow_error_set(error, EINVAL,
759 RTE_FLOW_ERROR_TYPE_ITEM, item,
760 "Bad mask in the VF pattern item");
764 * If "spec" is not set, the item requests any VF related to the
765 * PF of the current DPDK port (but not the PF itself).
766 * Reject this match criterion as unsupported.
769 return rte_flow_error_set(error, EINVAL,
770 RTE_FLOW_ERROR_TYPE_ITEM, item,
771 "Bad spec in the VF pattern item");
774 rc = efx_mae_mport_by_pcie_function(encp->enc_pf, spec->id, &mport_v);
776 return rte_flow_error_set(error, rc,
777 RTE_FLOW_ERROR_TYPE_ITEM, item,
778 "Failed to convert the PF + VF IDs");
781 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec, &mport_v, NULL);
783 return rte_flow_error_set(error, rc,
784 RTE_FLOW_ERROR_TYPE_ITEM, item,
785 "Failed to set MPORT for the PF + VF");
788 ctx_mae->match_mport_set = B_TRUE;
794 * Having this field ID in a field locator means that this
795 * locator cannot be used to actually set the field at the
796 * time when the corresponding item gets encountered. Such
797 * fields get stashed in the parsing context instead. This
798 * is required to resolve dependencies between the stashed
799 * fields. See sfc_mae_rule_process_pattern_data().
801 #define SFC_MAE_FIELD_HANDLING_DEFERRED EFX_MAE_FIELD_NIDS
803 struct sfc_mae_field_locator {
804 efx_mae_field_id_t field_id;
806 /* Field offset in the corresponding rte_flow_item_ struct */
811 sfc_mae_item_build_supp_mask(const struct sfc_mae_field_locator *field_locators,
812 unsigned int nb_field_locators, void *mask_ptr,
817 memset(mask_ptr, 0, mask_size);
819 for (i = 0; i < nb_field_locators; ++i) {
820 const struct sfc_mae_field_locator *fl = &field_locators[i];
822 SFC_ASSERT(fl->ofst + fl->size <= mask_size);
823 memset(RTE_PTR_ADD(mask_ptr, fl->ofst), 0xff, fl->size);
828 sfc_mae_parse_item(const struct sfc_mae_field_locator *field_locators,
829 unsigned int nb_field_locators, const uint8_t *spec,
830 const uint8_t *mask, struct sfc_mae_parse_ctx *ctx,
831 struct rte_flow_error *error)
833 const efx_mae_field_id_t *fremap = ctx->field_ids_remap;
837 for (i = 0; i < nb_field_locators; ++i) {
838 const struct sfc_mae_field_locator *fl = &field_locators[i];
840 if (fl->field_id == SFC_MAE_FIELD_HANDLING_DEFERRED)
843 rc = efx_mae_match_spec_field_set(ctx->match_spec,
844 fremap[fl->field_id],
845 fl->size, spec + fl->ofst,
846 fl->size, mask + fl->ofst);
852 rc = rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM,
853 NULL, "Failed to process item fields");
859 static const struct sfc_mae_field_locator flocs_eth[] = {
862 * This locator is used only for building supported fields mask.
863 * The field is handled by sfc_mae_rule_process_pattern_data().
865 SFC_MAE_FIELD_HANDLING_DEFERRED,
866 RTE_SIZEOF_FIELD(struct rte_flow_item_eth, type),
867 offsetof(struct rte_flow_item_eth, type),
870 EFX_MAE_FIELD_ETH_DADDR_BE,
871 RTE_SIZEOF_FIELD(struct rte_flow_item_eth, dst),
872 offsetof(struct rte_flow_item_eth, dst),
875 EFX_MAE_FIELD_ETH_SADDR_BE,
876 RTE_SIZEOF_FIELD(struct rte_flow_item_eth, src),
877 offsetof(struct rte_flow_item_eth, src),
882 sfc_mae_rule_parse_item_eth(const struct rte_flow_item *item,
883 struct sfc_flow_parse_ctx *ctx,
884 struct rte_flow_error *error)
886 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
887 struct rte_flow_item_eth supp_mask;
888 const uint8_t *spec = NULL;
889 const uint8_t *mask = NULL;
892 sfc_mae_item_build_supp_mask(flocs_eth, RTE_DIM(flocs_eth),
893 &supp_mask, sizeof(supp_mask));
895 rc = sfc_flow_parse_init(item,
896 (const void **)&spec, (const void **)&mask,
897 (const void *)&supp_mask,
898 &rte_flow_item_eth_mask,
899 sizeof(struct rte_flow_item_eth), error);
904 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
905 struct sfc_mae_ethertype *ethertypes = pdata->ethertypes;
906 const struct rte_flow_item_eth *item_spec;
907 const struct rte_flow_item_eth *item_mask;
909 item_spec = (const struct rte_flow_item_eth *)spec;
910 item_mask = (const struct rte_flow_item_eth *)mask;
912 ethertypes[0].value = item_spec->type;
913 ethertypes[0].mask = item_mask->type;
916 * The specification is empty. This is wrong in the case
917 * when there are more network patterns in line. Other
918 * than that, any Ethernet can match. All of that is
919 * checked at the end of parsing.
924 return sfc_mae_parse_item(flocs_eth, RTE_DIM(flocs_eth), spec, mask,
928 static const struct sfc_mae_field_locator flocs_vlan[] = {
931 EFX_MAE_FIELD_VLAN0_TCI_BE,
932 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, tci),
933 offsetof(struct rte_flow_item_vlan, tci),
937 * This locator is used only for building supported fields mask.
938 * The field is handled by sfc_mae_rule_process_pattern_data().
940 SFC_MAE_FIELD_HANDLING_DEFERRED,
941 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, inner_type),
942 offsetof(struct rte_flow_item_vlan, inner_type),
947 EFX_MAE_FIELD_VLAN1_TCI_BE,
948 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, tci),
949 offsetof(struct rte_flow_item_vlan, tci),
953 * This locator is used only for building supported fields mask.
954 * The field is handled by sfc_mae_rule_process_pattern_data().
956 SFC_MAE_FIELD_HANDLING_DEFERRED,
957 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, inner_type),
958 offsetof(struct rte_flow_item_vlan, inner_type),
963 sfc_mae_rule_parse_item_vlan(const struct rte_flow_item *item,
964 struct sfc_flow_parse_ctx *ctx,
965 struct rte_flow_error *error)
967 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
968 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
969 const struct sfc_mae_field_locator *flocs;
970 struct rte_flow_item_vlan supp_mask;
971 const uint8_t *spec = NULL;
972 const uint8_t *mask = NULL;
973 unsigned int nb_flocs;
976 RTE_BUILD_BUG_ON(SFC_MAE_MATCH_VLAN_MAX_NTAGS != 2);
978 if (pdata->nb_vlan_tags == SFC_MAE_MATCH_VLAN_MAX_NTAGS) {
979 return rte_flow_error_set(error, ENOTSUP,
980 RTE_FLOW_ERROR_TYPE_ITEM, item,
981 "Can't match that many VLAN tags");
984 nb_flocs = RTE_DIM(flocs_vlan) / SFC_MAE_MATCH_VLAN_MAX_NTAGS;
985 flocs = flocs_vlan + pdata->nb_vlan_tags * nb_flocs;
987 /* If parsing fails, this can remain incremented. */
988 ++pdata->nb_vlan_tags;
990 sfc_mae_item_build_supp_mask(flocs, nb_flocs,
991 &supp_mask, sizeof(supp_mask));
993 rc = sfc_flow_parse_init(item,
994 (const void **)&spec, (const void **)&mask,
995 (const void *)&supp_mask,
996 &rte_flow_item_vlan_mask,
997 sizeof(struct rte_flow_item_vlan), error);
1002 struct sfc_mae_ethertype *ethertypes = pdata->ethertypes;
1003 const struct rte_flow_item_vlan *item_spec;
1004 const struct rte_flow_item_vlan *item_mask;
1006 item_spec = (const struct rte_flow_item_vlan *)spec;
1007 item_mask = (const struct rte_flow_item_vlan *)mask;
1009 ethertypes[pdata->nb_vlan_tags].value = item_spec->inner_type;
1010 ethertypes[pdata->nb_vlan_tags].mask = item_mask->inner_type;
1013 * The specification is empty. This is wrong in the case
1014 * when there are more network patterns in line. Other
1015 * than that, any Ethernet can match. All of that is
1016 * checked at the end of parsing.
1021 return sfc_mae_parse_item(flocs, nb_flocs, spec, mask, ctx_mae, error);
1024 static const struct sfc_mae_field_locator flocs_ipv4[] = {
1026 EFX_MAE_FIELD_SRC_IP4_BE,
1027 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.src_addr),
1028 offsetof(struct rte_flow_item_ipv4, hdr.src_addr),
1031 EFX_MAE_FIELD_DST_IP4_BE,
1032 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.dst_addr),
1033 offsetof(struct rte_flow_item_ipv4, hdr.dst_addr),
1037 * This locator is used only for building supported fields mask.
1038 * The field is handled by sfc_mae_rule_process_pattern_data().
1040 SFC_MAE_FIELD_HANDLING_DEFERRED,
1041 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.next_proto_id),
1042 offsetof(struct rte_flow_item_ipv4, hdr.next_proto_id),
1045 EFX_MAE_FIELD_IP_TOS,
1046 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4,
1047 hdr.type_of_service),
1048 offsetof(struct rte_flow_item_ipv4, hdr.type_of_service),
1051 EFX_MAE_FIELD_IP_TTL,
1052 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.time_to_live),
1053 offsetof(struct rte_flow_item_ipv4, hdr.time_to_live),
1058 sfc_mae_rule_parse_item_ipv4(const struct rte_flow_item *item,
1059 struct sfc_flow_parse_ctx *ctx,
1060 struct rte_flow_error *error)
1062 rte_be16_t ethertype_ipv4_be = RTE_BE16(RTE_ETHER_TYPE_IPV4);
1063 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1064 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
1065 struct rte_flow_item_ipv4 supp_mask;
1066 const uint8_t *spec = NULL;
1067 const uint8_t *mask = NULL;
1070 sfc_mae_item_build_supp_mask(flocs_ipv4, RTE_DIM(flocs_ipv4),
1071 &supp_mask, sizeof(supp_mask));
1073 rc = sfc_flow_parse_init(item,
1074 (const void **)&spec, (const void **)&mask,
1075 (const void *)&supp_mask,
1076 &rte_flow_item_ipv4_mask,
1077 sizeof(struct rte_flow_item_ipv4), error);
1081 pdata->innermost_ethertype_restriction.value = ethertype_ipv4_be;
1082 pdata->innermost_ethertype_restriction.mask = RTE_BE16(0xffff);
1085 const struct rte_flow_item_ipv4 *item_spec;
1086 const struct rte_flow_item_ipv4 *item_mask;
1088 item_spec = (const struct rte_flow_item_ipv4 *)spec;
1089 item_mask = (const struct rte_flow_item_ipv4 *)mask;
1091 pdata->l3_next_proto_value = item_spec->hdr.next_proto_id;
1092 pdata->l3_next_proto_mask = item_mask->hdr.next_proto_id;
1097 return sfc_mae_parse_item(flocs_ipv4, RTE_DIM(flocs_ipv4), spec, mask,
1101 static const struct sfc_mae_field_locator flocs_ipv6[] = {
1103 EFX_MAE_FIELD_SRC_IP6_BE,
1104 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.src_addr),
1105 offsetof(struct rte_flow_item_ipv6, hdr.src_addr),
1108 EFX_MAE_FIELD_DST_IP6_BE,
1109 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.dst_addr),
1110 offsetof(struct rte_flow_item_ipv6, hdr.dst_addr),
1114 * This locator is used only for building supported fields mask.
1115 * The field is handled by sfc_mae_rule_process_pattern_data().
1117 SFC_MAE_FIELD_HANDLING_DEFERRED,
1118 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.proto),
1119 offsetof(struct rte_flow_item_ipv6, hdr.proto),
1122 EFX_MAE_FIELD_IP_TTL,
1123 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.hop_limits),
1124 offsetof(struct rte_flow_item_ipv6, hdr.hop_limits),
1129 sfc_mae_rule_parse_item_ipv6(const struct rte_flow_item *item,
1130 struct sfc_flow_parse_ctx *ctx,
1131 struct rte_flow_error *error)
1133 rte_be16_t ethertype_ipv6_be = RTE_BE16(RTE_ETHER_TYPE_IPV6);
1134 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1135 const efx_mae_field_id_t *fremap = ctx_mae->field_ids_remap;
1136 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
1137 struct rte_flow_item_ipv6 supp_mask;
1138 const uint8_t *spec = NULL;
1139 const uint8_t *mask = NULL;
1140 rte_be32_t vtc_flow_be;
1146 sfc_mae_item_build_supp_mask(flocs_ipv6, RTE_DIM(flocs_ipv6),
1147 &supp_mask, sizeof(supp_mask));
1149 vtc_flow_be = RTE_BE32(RTE_IPV6_HDR_TC_MASK);
1150 memcpy(&supp_mask, &vtc_flow_be, sizeof(vtc_flow_be));
1152 rc = sfc_flow_parse_init(item,
1153 (const void **)&spec, (const void **)&mask,
1154 (const void *)&supp_mask,
1155 &rte_flow_item_ipv6_mask,
1156 sizeof(struct rte_flow_item_ipv6), error);
1160 pdata->innermost_ethertype_restriction.value = ethertype_ipv6_be;
1161 pdata->innermost_ethertype_restriction.mask = RTE_BE16(0xffff);
1164 const struct rte_flow_item_ipv6 *item_spec;
1165 const struct rte_flow_item_ipv6 *item_mask;
1167 item_spec = (const struct rte_flow_item_ipv6 *)spec;
1168 item_mask = (const struct rte_flow_item_ipv6 *)mask;
1170 pdata->l3_next_proto_value = item_spec->hdr.proto;
1171 pdata->l3_next_proto_mask = item_mask->hdr.proto;
1176 rc = sfc_mae_parse_item(flocs_ipv6, RTE_DIM(flocs_ipv6), spec, mask,
1181 memcpy(&vtc_flow_be, spec, sizeof(vtc_flow_be));
1182 vtc_flow = rte_be_to_cpu_32(vtc_flow_be);
1183 tc_value = (vtc_flow & RTE_IPV6_HDR_TC_MASK) >> RTE_IPV6_HDR_TC_SHIFT;
1185 memcpy(&vtc_flow_be, mask, sizeof(vtc_flow_be));
1186 vtc_flow = rte_be_to_cpu_32(vtc_flow_be);
1187 tc_mask = (vtc_flow & RTE_IPV6_HDR_TC_MASK) >> RTE_IPV6_HDR_TC_SHIFT;
1189 rc = efx_mae_match_spec_field_set(ctx_mae->match_spec,
1190 fremap[EFX_MAE_FIELD_IP_TOS],
1191 sizeof(tc_value), &tc_value,
1192 sizeof(tc_mask), &tc_mask);
1194 return rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM,
1195 NULL, "Failed to process item fields");
1201 static const struct sfc_mae_field_locator flocs_tcp[] = {
1203 EFX_MAE_FIELD_L4_SPORT_BE,
1204 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.src_port),
1205 offsetof(struct rte_flow_item_tcp, hdr.src_port),
1208 EFX_MAE_FIELD_L4_DPORT_BE,
1209 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.dst_port),
1210 offsetof(struct rte_flow_item_tcp, hdr.dst_port),
1213 EFX_MAE_FIELD_TCP_FLAGS_BE,
1215 * The values have been picked intentionally since the
1216 * target MAE field is oversize (16 bit). This mapping
1217 * relies on the fact that the MAE field is big-endian.
1219 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.data_off) +
1220 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.tcp_flags),
1221 offsetof(struct rte_flow_item_tcp, hdr.data_off),
1226 sfc_mae_rule_parse_item_tcp(const struct rte_flow_item *item,
1227 struct sfc_flow_parse_ctx *ctx,
1228 struct rte_flow_error *error)
1230 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1231 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
1232 struct rte_flow_item_tcp supp_mask;
1233 const uint8_t *spec = NULL;
1234 const uint8_t *mask = NULL;
1238 * When encountered among outermost items, item TCP is invalid.
1239 * Check which match specification is being constructed now.
1241 if (ctx_mae->match_spec != ctx_mae->match_spec_action) {
1242 return rte_flow_error_set(error, EINVAL,
1243 RTE_FLOW_ERROR_TYPE_ITEM, item,
1244 "TCP in outer frame is invalid");
1247 sfc_mae_item_build_supp_mask(flocs_tcp, RTE_DIM(flocs_tcp),
1248 &supp_mask, sizeof(supp_mask));
1250 rc = sfc_flow_parse_init(item,
1251 (const void **)&spec, (const void **)&mask,
1252 (const void *)&supp_mask,
1253 &rte_flow_item_tcp_mask,
1254 sizeof(struct rte_flow_item_tcp), error);
1258 pdata->l3_next_proto_restriction_value = IPPROTO_TCP;
1259 pdata->l3_next_proto_restriction_mask = 0xff;
1264 return sfc_mae_parse_item(flocs_tcp, RTE_DIM(flocs_tcp), spec, mask,
1268 static const struct sfc_mae_field_locator flocs_udp[] = {
1270 EFX_MAE_FIELD_L4_SPORT_BE,
1271 RTE_SIZEOF_FIELD(struct rte_flow_item_udp, hdr.src_port),
1272 offsetof(struct rte_flow_item_udp, hdr.src_port),
1275 EFX_MAE_FIELD_L4_DPORT_BE,
1276 RTE_SIZEOF_FIELD(struct rte_flow_item_udp, hdr.dst_port),
1277 offsetof(struct rte_flow_item_udp, hdr.dst_port),
1282 sfc_mae_rule_parse_item_udp(const struct rte_flow_item *item,
1283 struct sfc_flow_parse_ctx *ctx,
1284 struct rte_flow_error *error)
1286 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1287 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
1288 struct rte_flow_item_udp supp_mask;
1289 const uint8_t *spec = NULL;
1290 const uint8_t *mask = NULL;
1293 sfc_mae_item_build_supp_mask(flocs_udp, RTE_DIM(flocs_udp),
1294 &supp_mask, sizeof(supp_mask));
1296 rc = sfc_flow_parse_init(item,
1297 (const void **)&spec, (const void **)&mask,
1298 (const void *)&supp_mask,
1299 &rte_flow_item_udp_mask,
1300 sizeof(struct rte_flow_item_udp), error);
1304 pdata->l3_next_proto_restriction_value = IPPROTO_UDP;
1305 pdata->l3_next_proto_restriction_mask = 0xff;
1310 return sfc_mae_parse_item(flocs_udp, RTE_DIM(flocs_udp), spec, mask,
1314 static const struct sfc_mae_field_locator flocs_tunnel[] = {
1317 * The size and offset values are relevant
1318 * for Geneve and NVGRE, too.
1320 .size = RTE_SIZEOF_FIELD(struct rte_flow_item_vxlan, vni),
1321 .ofst = offsetof(struct rte_flow_item_vxlan, vni),
1326 * An auxiliary registry which allows using non-encap. field IDs
1327 * directly when building a match specification of type ACTION.
1329 * See sfc_mae_rule_parse_pattern() and sfc_mae_rule_parse_item_tunnel().
1331 static const efx_mae_field_id_t field_ids_no_remap[] = {
1332 #define FIELD_ID_NO_REMAP(_field) \
1333 [EFX_MAE_FIELD_##_field] = EFX_MAE_FIELD_##_field
1335 FIELD_ID_NO_REMAP(ETHER_TYPE_BE),
1336 FIELD_ID_NO_REMAP(ETH_SADDR_BE),
1337 FIELD_ID_NO_REMAP(ETH_DADDR_BE),
1338 FIELD_ID_NO_REMAP(VLAN0_TCI_BE),
1339 FIELD_ID_NO_REMAP(VLAN0_PROTO_BE),
1340 FIELD_ID_NO_REMAP(VLAN1_TCI_BE),
1341 FIELD_ID_NO_REMAP(VLAN1_PROTO_BE),
1342 FIELD_ID_NO_REMAP(SRC_IP4_BE),
1343 FIELD_ID_NO_REMAP(DST_IP4_BE),
1344 FIELD_ID_NO_REMAP(IP_PROTO),
1345 FIELD_ID_NO_REMAP(IP_TOS),
1346 FIELD_ID_NO_REMAP(IP_TTL),
1347 FIELD_ID_NO_REMAP(SRC_IP6_BE),
1348 FIELD_ID_NO_REMAP(DST_IP6_BE),
1349 FIELD_ID_NO_REMAP(L4_SPORT_BE),
1350 FIELD_ID_NO_REMAP(L4_DPORT_BE),
1351 FIELD_ID_NO_REMAP(TCP_FLAGS_BE),
1353 #undef FIELD_ID_NO_REMAP
1357 * An auxiliary registry which allows using "ENC" field IDs
1358 * when building a match specification of type OUTER.
1360 * See sfc_mae_rule_encap_parse_init().
1362 static const efx_mae_field_id_t field_ids_remap_to_encap[] = {
1363 #define FIELD_ID_REMAP_TO_ENCAP(_field) \
1364 [EFX_MAE_FIELD_##_field] = EFX_MAE_FIELD_ENC_##_field
1366 FIELD_ID_REMAP_TO_ENCAP(ETHER_TYPE_BE),
1367 FIELD_ID_REMAP_TO_ENCAP(ETH_SADDR_BE),
1368 FIELD_ID_REMAP_TO_ENCAP(ETH_DADDR_BE),
1369 FIELD_ID_REMAP_TO_ENCAP(VLAN0_TCI_BE),
1370 FIELD_ID_REMAP_TO_ENCAP(VLAN0_PROTO_BE),
1371 FIELD_ID_REMAP_TO_ENCAP(VLAN1_TCI_BE),
1372 FIELD_ID_REMAP_TO_ENCAP(VLAN1_PROTO_BE),
1373 FIELD_ID_REMAP_TO_ENCAP(SRC_IP4_BE),
1374 FIELD_ID_REMAP_TO_ENCAP(DST_IP4_BE),
1375 FIELD_ID_REMAP_TO_ENCAP(IP_PROTO),
1376 FIELD_ID_REMAP_TO_ENCAP(IP_TOS),
1377 FIELD_ID_REMAP_TO_ENCAP(IP_TTL),
1378 FIELD_ID_REMAP_TO_ENCAP(SRC_IP6_BE),
1379 FIELD_ID_REMAP_TO_ENCAP(DST_IP6_BE),
1380 FIELD_ID_REMAP_TO_ENCAP(L4_SPORT_BE),
1381 FIELD_ID_REMAP_TO_ENCAP(L4_DPORT_BE),
1383 #undef FIELD_ID_REMAP_TO_ENCAP
1387 sfc_mae_rule_parse_item_tunnel(const struct rte_flow_item *item,
1388 struct sfc_flow_parse_ctx *ctx,
1389 struct rte_flow_error *error)
1391 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1392 uint8_t vnet_id_v[sizeof(uint32_t)] = {0};
1393 uint8_t vnet_id_m[sizeof(uint32_t)] = {0};
1394 const struct rte_flow_item_vxlan *vxp;
1395 uint8_t supp_mask[sizeof(uint64_t)];
1396 const uint8_t *spec = NULL;
1397 const uint8_t *mask = NULL;
1398 const void *def_mask;
1402 * We're about to start processing inner frame items.
1403 * Process pattern data that has been deferred so far
1404 * and reset pattern data storage.
1406 rc = sfc_mae_rule_process_pattern_data(ctx_mae, error);
1410 memset(&ctx_mae->pattern_data, 0, sizeof(ctx_mae->pattern_data));
1412 sfc_mae_item_build_supp_mask(flocs_tunnel, RTE_DIM(flocs_tunnel),
1413 &supp_mask, sizeof(supp_mask));
1416 * This tunnel item was preliminarily detected by
1417 * sfc_mae_rule_encap_parse_init(). Default mask
1418 * was also picked by that helper. Use it here.
1420 def_mask = ctx_mae->tunnel_def_mask;
1422 rc = sfc_flow_parse_init(item,
1423 (const void **)&spec, (const void **)&mask,
1424 (const void *)&supp_mask, def_mask,
1425 sizeof(def_mask), error);
1430 * This item and later ones comprise a
1431 * match specification of type ACTION.
1433 ctx_mae->match_spec = ctx_mae->match_spec_action;
1435 /* This item and later ones use non-encap. EFX MAE field IDs. */
1436 ctx_mae->field_ids_remap = field_ids_no_remap;
1442 * Field EFX_MAE_FIELD_ENC_VNET_ID_BE is a 32-bit one.
1443 * Copy 24-bit VNI, which is BE, at offset 1 in it.
1444 * The extra byte is 0 both in the mask and in the value.
1446 vxp = (const struct rte_flow_item_vxlan *)spec;
1447 memcpy(vnet_id_v + 1, &vxp->vni, sizeof(vxp->vni));
1449 vxp = (const struct rte_flow_item_vxlan *)mask;
1450 memcpy(vnet_id_m + 1, &vxp->vni, sizeof(vxp->vni));
1452 rc = efx_mae_match_spec_field_set(ctx_mae->match_spec,
1453 EFX_MAE_FIELD_ENC_VNET_ID_BE,
1454 sizeof(vnet_id_v), vnet_id_v,
1455 sizeof(vnet_id_m), vnet_id_m);
1457 rc = rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM,
1458 item, "Failed to set VXLAN VNI");
1464 static const struct sfc_flow_item sfc_flow_items[] = {
1466 .type = RTE_FLOW_ITEM_TYPE_PORT_ID,
1468 * In terms of RTE flow, this item is a META one,
1469 * and its position in the pattern is don't care.
1471 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
1472 .layer = SFC_FLOW_ITEM_ANY_LAYER,
1473 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
1474 .parse = sfc_mae_rule_parse_item_port_id,
1477 .type = RTE_FLOW_ITEM_TYPE_PHY_PORT,
1479 * In terms of RTE flow, this item is a META one,
1480 * and its position in the pattern is don't care.
1482 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
1483 .layer = SFC_FLOW_ITEM_ANY_LAYER,
1484 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
1485 .parse = sfc_mae_rule_parse_item_phy_port,
1488 .type = RTE_FLOW_ITEM_TYPE_PF,
1490 * In terms of RTE flow, this item is a META one,
1491 * and its position in the pattern is don't care.
1493 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
1494 .layer = SFC_FLOW_ITEM_ANY_LAYER,
1495 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
1496 .parse = sfc_mae_rule_parse_item_pf,
1499 .type = RTE_FLOW_ITEM_TYPE_VF,
1501 * In terms of RTE flow, this item is a META one,
1502 * and its position in the pattern is don't care.
1504 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
1505 .layer = SFC_FLOW_ITEM_ANY_LAYER,
1506 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
1507 .parse = sfc_mae_rule_parse_item_vf,
1510 .type = RTE_FLOW_ITEM_TYPE_ETH,
1511 .prev_layer = SFC_FLOW_ITEM_START_LAYER,
1512 .layer = SFC_FLOW_ITEM_L2,
1513 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
1514 .parse = sfc_mae_rule_parse_item_eth,
1517 .type = RTE_FLOW_ITEM_TYPE_VLAN,
1518 .prev_layer = SFC_FLOW_ITEM_L2,
1519 .layer = SFC_FLOW_ITEM_L2,
1520 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
1521 .parse = sfc_mae_rule_parse_item_vlan,
1524 .type = RTE_FLOW_ITEM_TYPE_IPV4,
1525 .prev_layer = SFC_FLOW_ITEM_L2,
1526 .layer = SFC_FLOW_ITEM_L3,
1527 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
1528 .parse = sfc_mae_rule_parse_item_ipv4,
1531 .type = RTE_FLOW_ITEM_TYPE_IPV6,
1532 .prev_layer = SFC_FLOW_ITEM_L2,
1533 .layer = SFC_FLOW_ITEM_L3,
1534 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
1535 .parse = sfc_mae_rule_parse_item_ipv6,
1538 .type = RTE_FLOW_ITEM_TYPE_TCP,
1539 .prev_layer = SFC_FLOW_ITEM_L3,
1540 .layer = SFC_FLOW_ITEM_L4,
1541 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
1542 .parse = sfc_mae_rule_parse_item_tcp,
1545 .type = RTE_FLOW_ITEM_TYPE_UDP,
1546 .prev_layer = SFC_FLOW_ITEM_L3,
1547 .layer = SFC_FLOW_ITEM_L4,
1548 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
1549 .parse = sfc_mae_rule_parse_item_udp,
1552 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
1553 .prev_layer = SFC_FLOW_ITEM_L4,
1554 .layer = SFC_FLOW_ITEM_START_LAYER,
1555 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
1556 .parse = sfc_mae_rule_parse_item_tunnel,
1559 .type = RTE_FLOW_ITEM_TYPE_GENEVE,
1560 .prev_layer = SFC_FLOW_ITEM_L4,
1561 .layer = SFC_FLOW_ITEM_START_LAYER,
1562 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
1563 .parse = sfc_mae_rule_parse_item_tunnel,
1566 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
1567 .prev_layer = SFC_FLOW_ITEM_L3,
1568 .layer = SFC_FLOW_ITEM_START_LAYER,
1569 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
1570 .parse = sfc_mae_rule_parse_item_tunnel,
1575 sfc_mae_rule_process_outer(struct sfc_adapter *sa,
1576 struct sfc_mae_parse_ctx *ctx,
1577 struct sfc_mae_outer_rule **rulep,
1578 struct rte_flow_error *error)
1580 struct sfc_mae_outer_rule *rule;
1583 if (ctx->encap_type == EFX_TUNNEL_PROTOCOL_NONE) {
1588 SFC_ASSERT(ctx->match_spec_outer != NULL);
1590 if (!efx_mae_match_spec_is_valid(sa->nic, ctx->match_spec_outer)) {
1591 return rte_flow_error_set(error, ENOTSUP,
1592 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1593 "Inconsistent pattern (outer)");
1596 *rulep = sfc_mae_outer_rule_attach(sa, ctx->match_spec_outer,
1598 if (*rulep != NULL) {
1599 efx_mae_match_spec_fini(sa->nic, ctx->match_spec_outer);
1601 rc = sfc_mae_outer_rule_add(sa, ctx->match_spec_outer,
1602 ctx->encap_type, rulep);
1604 return rte_flow_error_set(error, rc,
1605 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1606 "Failed to process the pattern");
1610 /* The spec has now been tracked by the outer rule entry. */
1611 ctx->match_spec_outer = NULL;
1614 * Depending on whether we reuse an existing outer rule or create a
1615 * new one (see above), outer rule ID is either a valid value or
1616 * EFX_MAE_RSRC_ID_INVALID. Set it in the action rule match
1617 * specification (and the full mask, too) in order to have correct
1618 * class comparisons of the new rule with existing ones.
1619 * Also, action rule match specification will be validated shortly,
1620 * and having the full mask set for outer rule ID indicates that we
1621 * will use this field, and support for this field has to be checked.
1624 rc = efx_mae_match_spec_outer_rule_id_set(ctx->match_spec_action,
1625 &rule->fw_rsrc.rule_id);
1627 sfc_mae_outer_rule_del(sa, *rulep);
1630 return rte_flow_error_set(error, rc,
1631 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1632 "Failed to process the pattern");
1639 sfc_mae_rule_encap_parse_init(struct sfc_adapter *sa,
1640 const struct rte_flow_item pattern[],
1641 struct sfc_mae_parse_ctx *ctx,
1642 struct rte_flow_error *error)
1644 struct sfc_mae *mae = &sa->mae;
1647 if (pattern == NULL) {
1648 rte_flow_error_set(error, EINVAL,
1649 RTE_FLOW_ERROR_TYPE_ITEM_NUM, NULL,
1655 switch (pattern->type) {
1656 case RTE_FLOW_ITEM_TYPE_VXLAN:
1657 ctx->encap_type = EFX_TUNNEL_PROTOCOL_VXLAN;
1658 ctx->tunnel_def_mask = &rte_flow_item_vxlan_mask;
1659 RTE_BUILD_BUG_ON(sizeof(ctx->tunnel_def_mask) !=
1660 sizeof(rte_flow_item_vxlan_mask));
1662 case RTE_FLOW_ITEM_TYPE_GENEVE:
1663 ctx->encap_type = EFX_TUNNEL_PROTOCOL_GENEVE;
1664 ctx->tunnel_def_mask = &rte_flow_item_geneve_mask;
1665 RTE_BUILD_BUG_ON(sizeof(ctx->tunnel_def_mask) !=
1666 sizeof(rte_flow_item_geneve_mask));
1668 case RTE_FLOW_ITEM_TYPE_NVGRE:
1669 ctx->encap_type = EFX_TUNNEL_PROTOCOL_NVGRE;
1670 ctx->tunnel_def_mask = &rte_flow_item_nvgre_mask;
1671 RTE_BUILD_BUG_ON(sizeof(ctx->tunnel_def_mask) !=
1672 sizeof(rte_flow_item_nvgre_mask));
1674 case RTE_FLOW_ITEM_TYPE_END:
1684 if (pattern->type == RTE_FLOW_ITEM_TYPE_END)
1687 if ((mae->encap_types_supported & (1U << ctx->encap_type)) == 0) {
1688 return rte_flow_error_set(error, ENOTSUP,
1689 RTE_FLOW_ERROR_TYPE_ITEM,
1690 pattern, "Unsupported tunnel item");
1693 if (ctx->priority >= mae->nb_outer_rule_prios_max) {
1694 return rte_flow_error_set(error, ENOTSUP,
1695 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
1696 NULL, "Unsupported priority level");
1699 rc = efx_mae_match_spec_init(sa->nic, EFX_MAE_RULE_OUTER, ctx->priority,
1700 &ctx->match_spec_outer);
1702 return rte_flow_error_set(error, rc,
1703 RTE_FLOW_ERROR_TYPE_ITEM, pattern,
1704 "Failed to initialise outer rule match specification");
1707 /* Outermost items comprise a match specification of type OUTER. */
1708 ctx->match_spec = ctx->match_spec_outer;
1710 /* Outermost items use "ENC" EFX MAE field IDs. */
1711 ctx->field_ids_remap = field_ids_remap_to_encap;
1717 sfc_mae_rule_encap_parse_fini(struct sfc_adapter *sa,
1718 struct sfc_mae_parse_ctx *ctx)
1720 if (ctx->encap_type == EFX_TUNNEL_PROTOCOL_NONE)
1723 if (ctx->match_spec_outer != NULL)
1724 efx_mae_match_spec_fini(sa->nic, ctx->match_spec_outer);
1728 sfc_mae_rule_parse_pattern(struct sfc_adapter *sa,
1729 const struct rte_flow_item pattern[],
1730 struct sfc_flow_spec_mae *spec,
1731 struct rte_flow_error *error)
1733 struct sfc_mae_parse_ctx ctx_mae;
1734 struct sfc_flow_parse_ctx ctx;
1737 memset(&ctx_mae, 0, sizeof(ctx_mae));
1738 ctx_mae.priority = spec->priority;
1741 rc = efx_mae_match_spec_init(sa->nic, EFX_MAE_RULE_ACTION,
1743 &ctx_mae.match_spec_action);
1745 rc = rte_flow_error_set(error, rc,
1746 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1747 "Failed to initialise action rule match specification");
1748 goto fail_init_match_spec_action;
1752 * As a preliminary setting, assume that there is no encapsulation
1753 * in the pattern. That is, pattern items are about to comprise a
1754 * match specification of type ACTION and use non-encap. field IDs.
1756 * sfc_mae_rule_encap_parse_init() below may override this.
1758 ctx_mae.encap_type = EFX_TUNNEL_PROTOCOL_NONE;
1759 ctx_mae.match_spec = ctx_mae.match_spec_action;
1760 ctx_mae.field_ids_remap = field_ids_no_remap;
1762 ctx.type = SFC_FLOW_PARSE_CTX_MAE;
1765 rc = sfc_mae_rule_encap_parse_init(sa, pattern, &ctx_mae, error);
1767 goto fail_encap_parse_init;
1769 rc = sfc_flow_parse_pattern(sfc_flow_items, RTE_DIM(sfc_flow_items),
1770 pattern, &ctx, error);
1772 goto fail_parse_pattern;
1774 rc = sfc_mae_rule_process_pattern_data(&ctx_mae, error);
1776 goto fail_process_pattern_data;
1778 rc = sfc_mae_rule_process_outer(sa, &ctx_mae, &spec->outer_rule, error);
1780 goto fail_process_outer;
1782 if (!efx_mae_match_spec_is_valid(sa->nic, ctx_mae.match_spec_action)) {
1783 rc = rte_flow_error_set(error, ENOTSUP,
1784 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1785 "Inconsistent pattern");
1786 goto fail_validate_match_spec_action;
1789 spec->match_spec = ctx_mae.match_spec_action;
1793 fail_validate_match_spec_action:
1795 fail_process_pattern_data:
1797 sfc_mae_rule_encap_parse_fini(sa, &ctx_mae);
1799 fail_encap_parse_init:
1800 efx_mae_match_spec_fini(sa->nic, ctx_mae.match_spec_action);
1802 fail_init_match_spec_action:
1807 * An action supported by MAE may correspond to a bundle of RTE flow actions,
1808 * in example, VLAN_PUSH = OF_PUSH_VLAN + OF_VLAN_SET_VID + OF_VLAN_SET_PCP.
1809 * That is, related RTE flow actions need to be tracked as parts of a whole
1810 * so that they can be combined into a single action and submitted to MAE
1811 * representation of a given rule's action set.
1813 * Each RTE flow action provided by an application gets classified as
1814 * one belonging to some bundle type. If an action is not supposed to
1815 * belong to any bundle, or if this action is END, it is described as
1816 * one belonging to a dummy bundle of type EMPTY.
1818 * A currently tracked bundle will be submitted if a repeating
1819 * action or an action of different bundle type follows.
1822 enum sfc_mae_actions_bundle_type {
1823 SFC_MAE_ACTIONS_BUNDLE_EMPTY = 0,
1824 SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH,
1827 struct sfc_mae_actions_bundle {
1828 enum sfc_mae_actions_bundle_type type;
1830 /* Indicates actions already tracked by the current bundle */
1831 uint64_t actions_mask;
1833 /* Parameters used by SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH */
1834 rte_be16_t vlan_push_tpid;
1835 rte_be16_t vlan_push_tci;
1839 * Combine configuration of RTE flow actions tracked by the bundle into a
1840 * single action and submit the result to MAE action set specification.
1841 * Do nothing in the case of dummy action bundle.
1844 sfc_mae_actions_bundle_submit(const struct sfc_mae_actions_bundle *bundle,
1845 efx_mae_actions_t *spec)
1849 switch (bundle->type) {
1850 case SFC_MAE_ACTIONS_BUNDLE_EMPTY:
1852 case SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH:
1853 rc = efx_mae_action_set_populate_vlan_push(
1854 spec, bundle->vlan_push_tpid, bundle->vlan_push_tci);
1857 SFC_ASSERT(B_FALSE);
1865 * Given the type of the next RTE flow action in the line, decide
1866 * whether a new bundle is about to start, and, if this is the case,
1867 * submit and reset the current bundle.
1870 sfc_mae_actions_bundle_sync(const struct rte_flow_action *action,
1871 struct sfc_mae_actions_bundle *bundle,
1872 efx_mae_actions_t *spec,
1873 struct rte_flow_error *error)
1875 enum sfc_mae_actions_bundle_type bundle_type_new;
1878 switch (action->type) {
1879 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
1880 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
1881 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
1882 bundle_type_new = SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH;
1886 * Self-sufficient actions, including END, are handled in this
1887 * case. No checks for unsupported actions are needed here
1888 * because parsing doesn't occur at this point.
1890 bundle_type_new = SFC_MAE_ACTIONS_BUNDLE_EMPTY;
1894 if (bundle_type_new != bundle->type ||
1895 (bundle->actions_mask & (1ULL << action->type)) != 0) {
1896 rc = sfc_mae_actions_bundle_submit(bundle, spec);
1900 memset(bundle, 0, sizeof(*bundle));
1903 bundle->type = bundle_type_new;
1908 return rte_flow_error_set(error, rc,
1909 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1910 "Failed to request the (group of) action(s)");
1914 sfc_mae_rule_parse_action_of_push_vlan(
1915 const struct rte_flow_action_of_push_vlan *conf,
1916 struct sfc_mae_actions_bundle *bundle)
1918 bundle->vlan_push_tpid = conf->ethertype;
1922 sfc_mae_rule_parse_action_of_set_vlan_vid(
1923 const struct rte_flow_action_of_set_vlan_vid *conf,
1924 struct sfc_mae_actions_bundle *bundle)
1926 bundle->vlan_push_tci |= (conf->vlan_vid &
1927 rte_cpu_to_be_16(RTE_LEN2MASK(12, uint16_t)));
1931 sfc_mae_rule_parse_action_of_set_vlan_pcp(
1932 const struct rte_flow_action_of_set_vlan_pcp *conf,
1933 struct sfc_mae_actions_bundle *bundle)
1935 uint16_t vlan_tci_pcp = (uint16_t)(conf->vlan_pcp &
1936 RTE_LEN2MASK(3, uint8_t)) << 13;
1938 bundle->vlan_push_tci |= rte_cpu_to_be_16(vlan_tci_pcp);
1942 sfc_mae_rule_parse_action_mark(const struct rte_flow_action_mark *conf,
1943 efx_mae_actions_t *spec)
1945 return efx_mae_action_set_populate_mark(spec, conf->id);
1949 sfc_mae_rule_parse_action_phy_port(struct sfc_adapter *sa,
1950 const struct rte_flow_action_phy_port *conf,
1951 efx_mae_actions_t *spec)
1953 efx_mport_sel_t mport;
1957 if (conf->original != 0)
1958 phy_port = efx_nic_cfg_get(sa->nic)->enc_assigned_port;
1960 phy_port = conf->index;
1962 rc = efx_mae_mport_by_phy_port(phy_port, &mport);
1966 return efx_mae_action_set_populate_deliver(spec, &mport);
1970 sfc_mae_rule_parse_action_pf_vf(struct sfc_adapter *sa,
1971 const struct rte_flow_action_vf *vf_conf,
1972 efx_mae_actions_t *spec)
1974 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
1975 efx_mport_sel_t mport;
1979 if (vf_conf == NULL)
1980 vf = EFX_PCI_VF_INVALID;
1981 else if (vf_conf->original != 0)
1986 rc = efx_mae_mport_by_pcie_function(encp->enc_pf, vf, &mport);
1990 return efx_mae_action_set_populate_deliver(spec, &mport);
1994 sfc_mae_rule_parse_action_port_id(struct sfc_adapter *sa,
1995 const struct rte_flow_action_port_id *conf,
1996 efx_mae_actions_t *spec)
1998 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
1999 struct sfc_mae *mae = &sa->mae;
2000 efx_mport_sel_t mport;
2004 port_id = (conf->original != 0) ? sas->port_id : conf->id;
2006 rc = sfc_mae_switch_port_by_ethdev(mae->switch_domain_id,
2011 return efx_mae_action_set_populate_deliver(spec, &mport);
2015 sfc_mae_rule_parse_action(struct sfc_adapter *sa,
2016 const struct rte_flow_action *action,
2017 struct sfc_mae_actions_bundle *bundle,
2018 efx_mae_actions_t *spec,
2019 struct rte_flow_error *error)
2023 switch (action->type) {
2024 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
2025 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_POP_VLAN,
2026 bundle->actions_mask);
2027 rc = efx_mae_action_set_populate_vlan_pop(spec);
2029 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
2030 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN,
2031 bundle->actions_mask);
2032 sfc_mae_rule_parse_action_of_push_vlan(action->conf, bundle);
2034 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
2035 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID,
2036 bundle->actions_mask);
2037 sfc_mae_rule_parse_action_of_set_vlan_vid(action->conf, bundle);
2039 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
2040 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP,
2041 bundle->actions_mask);
2042 sfc_mae_rule_parse_action_of_set_vlan_pcp(action->conf, bundle);
2044 case RTE_FLOW_ACTION_TYPE_FLAG:
2045 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_FLAG,
2046 bundle->actions_mask);
2047 rc = efx_mae_action_set_populate_flag(spec);
2049 case RTE_FLOW_ACTION_TYPE_MARK:
2050 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_MARK,
2051 bundle->actions_mask);
2052 rc = sfc_mae_rule_parse_action_mark(action->conf, spec);
2054 case RTE_FLOW_ACTION_TYPE_PHY_PORT:
2055 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_PHY_PORT,
2056 bundle->actions_mask);
2057 rc = sfc_mae_rule_parse_action_phy_port(sa, action->conf, spec);
2059 case RTE_FLOW_ACTION_TYPE_PF:
2060 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_PF,
2061 bundle->actions_mask);
2062 rc = sfc_mae_rule_parse_action_pf_vf(sa, NULL, spec);
2064 case RTE_FLOW_ACTION_TYPE_VF:
2065 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VF,
2066 bundle->actions_mask);
2067 rc = sfc_mae_rule_parse_action_pf_vf(sa, action->conf, spec);
2069 case RTE_FLOW_ACTION_TYPE_PORT_ID:
2070 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_PORT_ID,
2071 bundle->actions_mask);
2072 rc = sfc_mae_rule_parse_action_port_id(sa, action->conf, spec);
2074 case RTE_FLOW_ACTION_TYPE_DROP:
2075 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_DROP,
2076 bundle->actions_mask);
2077 rc = efx_mae_action_set_populate_drop(spec);
2080 return rte_flow_error_set(error, ENOTSUP,
2081 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2082 "Unsupported action");
2086 rc = rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ACTION,
2087 NULL, "Failed to request the action");
2089 bundle->actions_mask |= (1ULL << action->type);
2096 sfc_mae_rule_parse_actions(struct sfc_adapter *sa,
2097 const struct rte_flow_action actions[],
2098 struct sfc_mae_action_set **action_setp,
2099 struct rte_flow_error *error)
2101 struct sfc_mae_actions_bundle bundle = {0};
2102 const struct rte_flow_action *action;
2103 efx_mae_actions_t *spec;
2106 if (actions == NULL) {
2107 return rte_flow_error_set(error, EINVAL,
2108 RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
2112 rc = efx_mae_action_set_spec_init(sa->nic, &spec);
2114 goto fail_action_set_spec_init;
2116 for (action = actions;
2117 action->type != RTE_FLOW_ACTION_TYPE_END; ++action) {
2118 rc = sfc_mae_actions_bundle_sync(action, &bundle, spec, error);
2120 goto fail_rule_parse_action;
2122 rc = sfc_mae_rule_parse_action(sa, action, &bundle, spec,
2125 goto fail_rule_parse_action;
2128 rc = sfc_mae_actions_bundle_sync(action, &bundle, spec, error);
2130 goto fail_rule_parse_action;
2132 *action_setp = sfc_mae_action_set_attach(sa, spec);
2133 if (*action_setp != NULL) {
2134 efx_mae_action_set_spec_fini(sa->nic, spec);
2138 rc = sfc_mae_action_set_add(sa, spec, action_setp);
2140 goto fail_action_set_add;
2144 fail_action_set_add:
2145 fail_rule_parse_action:
2146 efx_mae_action_set_spec_fini(sa->nic, spec);
2148 fail_action_set_spec_init:
2150 rc = rte_flow_error_set(error, rc,
2151 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2152 NULL, "Failed to process the action");
2158 sfc_mae_rules_class_cmp(struct sfc_adapter *sa,
2159 const efx_mae_match_spec_t *left,
2160 const efx_mae_match_spec_t *right)
2162 bool have_same_class;
2165 rc = efx_mae_match_specs_class_cmp(sa->nic, left, right,
2168 return (rc == 0) ? have_same_class : false;
2172 sfc_mae_outer_rule_class_verify(struct sfc_adapter *sa,
2173 struct sfc_mae_outer_rule *rule)
2175 struct sfc_mae_fw_rsrc *fw_rsrc = &rule->fw_rsrc;
2176 struct sfc_mae_outer_rule *entry;
2177 struct sfc_mae *mae = &sa->mae;
2179 if (fw_rsrc->rule_id.id != EFX_MAE_RSRC_ID_INVALID) {
2180 /* An active rule is reused. It's class is wittingly valid. */
2184 TAILQ_FOREACH_REVERSE(entry, &mae->outer_rules,
2185 sfc_mae_outer_rules, entries) {
2186 const efx_mae_match_spec_t *left = entry->match_spec;
2187 const efx_mae_match_spec_t *right = rule->match_spec;
2192 if (sfc_mae_rules_class_cmp(sa, left, right))
2196 sfc_info(sa, "for now, the HW doesn't support rule validation, and HW "
2197 "support for outer frame pattern items is not guaranteed; "
2198 "other than that, the items are valid from SW standpoint");
2203 sfc_mae_action_rule_class_verify(struct sfc_adapter *sa,
2204 struct sfc_flow_spec_mae *spec)
2206 const struct rte_flow *entry;
2208 TAILQ_FOREACH_REVERSE(entry, &sa->flow_list, sfc_flow_list, entries) {
2209 const struct sfc_flow_spec *entry_spec = &entry->spec;
2210 const struct sfc_flow_spec_mae *es_mae = &entry_spec->mae;
2211 const efx_mae_match_spec_t *left = es_mae->match_spec;
2212 const efx_mae_match_spec_t *right = spec->match_spec;
2214 switch (entry_spec->type) {
2215 case SFC_FLOW_SPEC_FILTER:
2216 /* Ignore VNIC-level flows */
2218 case SFC_FLOW_SPEC_MAE:
2219 if (sfc_mae_rules_class_cmp(sa, left, right))
2227 sfc_info(sa, "for now, the HW doesn't support rule validation, and HW "
2228 "support for inner frame pattern items is not guaranteed; "
2229 "other than that, the items are valid from SW standpoint");
2234 * Confirm that a given flow can be accepted by the FW.
2237 * Software adapter context
2239 * Flow to be verified
2241 * Zero on success and non-zero in the case of error.
2242 * A special value of EAGAIN indicates that the adapter is
2243 * not in started state. This state is compulsory because
2244 * it only makes sense to compare the rule class of the flow
2245 * being validated with classes of the active rules.
2246 * Such classes are wittingly supported by the FW.
2249 sfc_mae_flow_verify(struct sfc_adapter *sa,
2250 struct rte_flow *flow)
2252 struct sfc_flow_spec *spec = &flow->spec;
2253 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
2254 struct sfc_mae_outer_rule *outer_rule = spec_mae->outer_rule;
2257 SFC_ASSERT(sfc_adapter_is_locked(sa));
2259 if (sa->state != SFC_ADAPTER_STARTED)
2262 if (outer_rule != NULL) {
2263 rc = sfc_mae_outer_rule_class_verify(sa, outer_rule);
2268 return sfc_mae_action_rule_class_verify(sa, spec_mae);
2272 sfc_mae_flow_insert(struct sfc_adapter *sa,
2273 struct rte_flow *flow)
2275 struct sfc_flow_spec *spec = &flow->spec;
2276 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
2277 struct sfc_mae_outer_rule *outer_rule = spec_mae->outer_rule;
2278 struct sfc_mae_action_set *action_set = spec_mae->action_set;
2279 struct sfc_mae_fw_rsrc *fw_rsrc = &action_set->fw_rsrc;
2282 SFC_ASSERT(spec_mae->rule_id.id == EFX_MAE_RSRC_ID_INVALID);
2283 SFC_ASSERT(action_set != NULL);
2285 if (outer_rule != NULL) {
2286 rc = sfc_mae_outer_rule_enable(sa, outer_rule,
2287 spec_mae->match_spec);
2289 goto fail_outer_rule_enable;
2292 rc = sfc_mae_action_set_enable(sa, action_set);
2294 goto fail_action_set_enable;
2296 rc = efx_mae_action_rule_insert(sa->nic, spec_mae->match_spec,
2297 NULL, &fw_rsrc->aset_id,
2298 &spec_mae->rule_id);
2300 goto fail_action_rule_insert;
2304 fail_action_rule_insert:
2305 (void)sfc_mae_action_set_disable(sa, action_set);
2307 fail_action_set_enable:
2308 if (outer_rule != NULL)
2309 (void)sfc_mae_outer_rule_disable(sa, outer_rule);
2311 fail_outer_rule_enable:
2316 sfc_mae_flow_remove(struct sfc_adapter *sa,
2317 struct rte_flow *flow)
2319 struct sfc_flow_spec *spec = &flow->spec;
2320 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
2321 struct sfc_mae_action_set *action_set = spec_mae->action_set;
2322 struct sfc_mae_outer_rule *outer_rule = spec_mae->outer_rule;
2325 SFC_ASSERT(spec_mae->rule_id.id != EFX_MAE_RSRC_ID_INVALID);
2326 SFC_ASSERT(action_set != NULL);
2328 rc = efx_mae_action_rule_remove(sa->nic, &spec_mae->rule_id);
2332 spec_mae->rule_id.id = EFX_MAE_RSRC_ID_INVALID;
2334 rc = sfc_mae_action_set_disable(sa, action_set);
2336 sfc_err(sa, "failed to disable the action set (rc = %d)", rc);
2337 /* Despite the error, proceed with outer rule removal. */
2340 if (outer_rule != NULL)
2341 return sfc_mae_outer_rule_disable(sa, outer_rule);