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_mae_switch_port_request switch_port_request = {0};
34 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
35 efx_mport_sel_t entity_mport;
36 struct sfc_mae *mae = &sa->mae;
37 efx_mae_limits_t limits;
40 sfc_log_init(sa, "entry");
42 if (!encp->enc_mae_supported) {
43 mae->status = SFC_MAE_STATUS_UNSUPPORTED;
47 sfc_log_init(sa, "init MAE");
48 rc = efx_mae_init(sa->nic);
52 sfc_log_init(sa, "get MAE limits");
53 rc = efx_mae_get_limits(sa->nic, &limits);
55 goto fail_mae_get_limits;
57 sfc_log_init(sa, "assign entity MPORT");
58 rc = sfc_mae_assign_entity_mport(sa, &entity_mport);
60 goto fail_mae_assign_entity_mport;
62 sfc_log_init(sa, "assign RTE switch domain");
63 rc = sfc_mae_assign_switch_domain(sa, &mae->switch_domain_id);
65 goto fail_mae_assign_switch_domain;
67 sfc_log_init(sa, "assign RTE switch port");
68 switch_port_request.type = SFC_MAE_SWITCH_PORT_INDEPENDENT;
69 switch_port_request.entity_mportp = &entity_mport;
70 rc = sfc_mae_assign_switch_port(mae->switch_domain_id,
72 &mae->switch_port_id);
74 goto fail_mae_assign_switch_port;
76 mae->status = SFC_MAE_STATUS_SUPPORTED;
77 mae->nb_action_rule_prios_max = limits.eml_max_n_action_prios;
78 TAILQ_INIT(&mae->action_sets);
80 sfc_log_init(sa, "done");
84 fail_mae_assign_switch_port:
85 fail_mae_assign_switch_domain:
86 fail_mae_assign_entity_mport:
88 efx_mae_fini(sa->nic);
91 sfc_log_init(sa, "failed %d", rc);
97 sfc_mae_detach(struct sfc_adapter *sa)
99 struct sfc_mae *mae = &sa->mae;
100 enum sfc_mae_status status_prev = mae->status;
102 sfc_log_init(sa, "entry");
104 mae->nb_action_rule_prios_max = 0;
105 mae->status = SFC_MAE_STATUS_UNKNOWN;
107 if (status_prev != SFC_MAE_STATUS_SUPPORTED)
110 efx_mae_fini(sa->nic);
112 sfc_log_init(sa, "done");
115 static struct sfc_mae_action_set *
116 sfc_mae_action_set_attach(struct sfc_adapter *sa,
117 const efx_mae_actions_t *spec)
119 struct sfc_mae_action_set *action_set;
120 struct sfc_mae *mae = &sa->mae;
122 SFC_ASSERT(sfc_adapter_is_locked(sa));
124 TAILQ_FOREACH(action_set, &mae->action_sets, entries) {
125 if (efx_mae_action_set_specs_equal(action_set->spec, spec)) {
126 ++(action_set->refcnt);
135 sfc_mae_action_set_add(struct sfc_adapter *sa,
136 efx_mae_actions_t *spec,
137 struct sfc_mae_action_set **action_setp)
139 struct sfc_mae_action_set *action_set;
140 struct sfc_mae *mae = &sa->mae;
142 SFC_ASSERT(sfc_adapter_is_locked(sa));
144 action_set = rte_zmalloc("sfc_mae_action_set", sizeof(*action_set), 0);
145 if (action_set == NULL)
148 action_set->refcnt = 1;
149 action_set->spec = spec;
151 action_set->fw_rsrc.aset_id.id = EFX_MAE_RSRC_ID_INVALID;
153 TAILQ_INSERT_TAIL(&mae->action_sets, action_set, entries);
155 *action_setp = action_set;
161 sfc_mae_action_set_del(struct sfc_adapter *sa,
162 struct sfc_mae_action_set *action_set)
164 struct sfc_mae *mae = &sa->mae;
166 SFC_ASSERT(sfc_adapter_is_locked(sa));
167 SFC_ASSERT(action_set->refcnt != 0);
169 --(action_set->refcnt);
171 if (action_set->refcnt != 0)
174 SFC_ASSERT(action_set->fw_rsrc.aset_id.id == EFX_MAE_RSRC_ID_INVALID);
175 SFC_ASSERT(action_set->fw_rsrc.refcnt == 0);
177 efx_mae_action_set_spec_fini(sa->nic, action_set->spec);
178 TAILQ_REMOVE(&mae->action_sets, action_set, entries);
179 rte_free(action_set);
183 sfc_mae_action_set_enable(struct sfc_adapter *sa,
184 struct sfc_mae_action_set *action_set)
186 struct sfc_mae_fw_rsrc *fw_rsrc = &action_set->fw_rsrc;
189 SFC_ASSERT(sfc_adapter_is_locked(sa));
191 if (fw_rsrc->refcnt == 0) {
192 SFC_ASSERT(fw_rsrc->aset_id.id == EFX_MAE_RSRC_ID_INVALID);
193 SFC_ASSERT(action_set->spec != NULL);
195 rc = efx_mae_action_set_alloc(sa->nic, action_set->spec,
207 sfc_mae_action_set_disable(struct sfc_adapter *sa,
208 struct sfc_mae_action_set *action_set)
210 struct sfc_mae_fw_rsrc *fw_rsrc = &action_set->fw_rsrc;
213 SFC_ASSERT(sfc_adapter_is_locked(sa));
214 SFC_ASSERT(fw_rsrc->aset_id.id != EFX_MAE_RSRC_ID_INVALID);
215 SFC_ASSERT(fw_rsrc->refcnt != 0);
217 if (fw_rsrc->refcnt == 1) {
218 rc = efx_mae_action_set_free(sa->nic, &fw_rsrc->aset_id);
222 fw_rsrc->aset_id.id = EFX_MAE_RSRC_ID_INVALID;
231 sfc_mae_flow_cleanup(struct sfc_adapter *sa,
232 struct rte_flow *flow)
234 struct sfc_flow_spec *spec;
235 struct sfc_flow_spec_mae *spec_mae;
245 spec_mae = &spec->mae;
247 SFC_ASSERT(spec_mae->rule_id.id == EFX_MAE_RSRC_ID_INVALID);
249 if (spec_mae->action_set != NULL)
250 sfc_mae_action_set_del(sa, spec_mae->action_set);
252 if (spec_mae->match_spec != NULL)
253 efx_mae_match_spec_fini(sa->nic, spec_mae->match_spec);
257 sfc_mae_rule_parse_item_phy_port(const struct rte_flow_item *item,
258 struct sfc_flow_parse_ctx *ctx,
259 struct rte_flow_error *error)
261 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
262 const struct rte_flow_item_phy_port supp_mask = {
265 const void *def_mask = &rte_flow_item_phy_port_mask;
266 const struct rte_flow_item_phy_port *spec = NULL;
267 const struct rte_flow_item_phy_port *mask = NULL;
268 efx_mport_sel_t mport_v;
271 if (ctx_mae->match_mport_set) {
272 return rte_flow_error_set(error, ENOTSUP,
273 RTE_FLOW_ERROR_TYPE_ITEM, item,
274 "Can't handle multiple traffic source items");
277 rc = sfc_flow_parse_init(item,
278 (const void **)&spec, (const void **)&mask,
279 (const void *)&supp_mask, def_mask,
280 sizeof(struct rte_flow_item_phy_port), error);
284 if (mask->index != supp_mask.index) {
285 return rte_flow_error_set(error, EINVAL,
286 RTE_FLOW_ERROR_TYPE_ITEM, item,
287 "Bad mask in the PHY_PORT pattern item");
290 /* If "spec" is not set, could be any physical port */
294 rc = efx_mae_mport_by_phy_port(spec->index, &mport_v);
296 return rte_flow_error_set(error, rc,
297 RTE_FLOW_ERROR_TYPE_ITEM, item,
298 "Failed to convert the PHY_PORT index");
301 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec_action,
304 return rte_flow_error_set(error, rc,
305 RTE_FLOW_ERROR_TYPE_ITEM, item,
306 "Failed to set MPORT for the PHY_PORT");
309 ctx_mae->match_mport_set = B_TRUE;
315 sfc_mae_rule_parse_item_pf(const struct rte_flow_item *item,
316 struct sfc_flow_parse_ctx *ctx,
317 struct rte_flow_error *error)
319 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
320 const efx_nic_cfg_t *encp = efx_nic_cfg_get(ctx_mae->sa->nic);
321 efx_mport_sel_t mport_v;
324 if (ctx_mae->match_mport_set) {
325 return rte_flow_error_set(error, ENOTSUP,
326 RTE_FLOW_ERROR_TYPE_ITEM, item,
327 "Can't handle multiple traffic source items");
330 rc = efx_mae_mport_by_pcie_function(encp->enc_pf, EFX_PCI_VF_INVALID,
333 return rte_flow_error_set(error, rc,
334 RTE_FLOW_ERROR_TYPE_ITEM, item,
335 "Failed to convert the PF ID");
338 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec_action,
341 return rte_flow_error_set(error, rc,
342 RTE_FLOW_ERROR_TYPE_ITEM, item,
343 "Failed to set MPORT for the PF");
346 ctx_mae->match_mport_set = B_TRUE;
352 sfc_mae_rule_parse_item_vf(const struct rte_flow_item *item,
353 struct sfc_flow_parse_ctx *ctx,
354 struct rte_flow_error *error)
356 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
357 const efx_nic_cfg_t *encp = efx_nic_cfg_get(ctx_mae->sa->nic);
358 const struct rte_flow_item_vf supp_mask = {
361 const void *def_mask = &rte_flow_item_vf_mask;
362 const struct rte_flow_item_vf *spec = NULL;
363 const struct rte_flow_item_vf *mask = NULL;
364 efx_mport_sel_t mport_v;
367 if (ctx_mae->match_mport_set) {
368 return rte_flow_error_set(error, ENOTSUP,
369 RTE_FLOW_ERROR_TYPE_ITEM, item,
370 "Can't handle multiple traffic source items");
373 rc = sfc_flow_parse_init(item,
374 (const void **)&spec, (const void **)&mask,
375 (const void *)&supp_mask, def_mask,
376 sizeof(struct rte_flow_item_vf), error);
380 if (mask->id != supp_mask.id) {
381 return rte_flow_error_set(error, EINVAL,
382 RTE_FLOW_ERROR_TYPE_ITEM, item,
383 "Bad mask in the VF pattern item");
387 * If "spec" is not set, the item requests any VF related to the
388 * PF of the current DPDK port (but not the PF itself).
389 * Reject this match criterion as unsupported.
392 return rte_flow_error_set(error, EINVAL,
393 RTE_FLOW_ERROR_TYPE_ITEM, item,
394 "Bad spec in the VF pattern item");
397 rc = efx_mae_mport_by_pcie_function(encp->enc_pf, spec->id, &mport_v);
399 return rte_flow_error_set(error, rc,
400 RTE_FLOW_ERROR_TYPE_ITEM, item,
401 "Failed to convert the PF + VF IDs");
404 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec_action,
407 return rte_flow_error_set(error, rc,
408 RTE_FLOW_ERROR_TYPE_ITEM, item,
409 "Failed to set MPORT for the PF + VF");
412 ctx_mae->match_mport_set = B_TRUE;
417 struct sfc_mae_field_locator {
418 efx_mae_field_id_t field_id;
420 /* Field offset in the corresponding rte_flow_item_ struct */
425 sfc_mae_item_build_supp_mask(const struct sfc_mae_field_locator *field_locators,
426 unsigned int nb_field_locators, void *mask_ptr,
431 memset(mask_ptr, 0, mask_size);
433 for (i = 0; i < nb_field_locators; ++i) {
434 const struct sfc_mae_field_locator *fl = &field_locators[i];
436 SFC_ASSERT(fl->ofst + fl->size <= mask_size);
437 memset(RTE_PTR_ADD(mask_ptr, fl->ofst), 0xff, fl->size);
442 sfc_mae_parse_item(const struct sfc_mae_field_locator *field_locators,
443 unsigned int nb_field_locators, const uint8_t *spec,
444 const uint8_t *mask, efx_mae_match_spec_t *efx_spec,
445 struct rte_flow_error *error)
450 for (i = 0; i < nb_field_locators; ++i) {
451 const struct sfc_mae_field_locator *fl = &field_locators[i];
453 rc = efx_mae_match_spec_field_set(efx_spec, fl->field_id,
454 fl->size, spec + fl->ofst,
455 fl->size, mask + fl->ofst);
461 rc = rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM,
462 NULL, "Failed to process item fields");
468 static const struct sfc_mae_field_locator flocs_eth[] = {
470 EFX_MAE_FIELD_ETHER_TYPE_BE,
471 RTE_SIZEOF_FIELD(struct rte_flow_item_eth, type),
472 offsetof(struct rte_flow_item_eth, type),
475 EFX_MAE_FIELD_ETH_DADDR_BE,
476 RTE_SIZEOF_FIELD(struct rte_flow_item_eth, dst),
477 offsetof(struct rte_flow_item_eth, dst),
480 EFX_MAE_FIELD_ETH_SADDR_BE,
481 RTE_SIZEOF_FIELD(struct rte_flow_item_eth, src),
482 offsetof(struct rte_flow_item_eth, src),
487 sfc_mae_rule_parse_item_eth(const struct rte_flow_item *item,
488 struct sfc_flow_parse_ctx *ctx,
489 struct rte_flow_error *error)
491 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
492 struct rte_flow_item_eth supp_mask;
493 const uint8_t *spec = NULL;
494 const uint8_t *mask = NULL;
497 sfc_mae_item_build_supp_mask(flocs_eth, RTE_DIM(flocs_eth),
498 &supp_mask, sizeof(supp_mask));
500 rc = sfc_flow_parse_init(item,
501 (const void **)&spec, (const void **)&mask,
502 (const void *)&supp_mask,
503 &rte_flow_item_eth_mask,
504 sizeof(struct rte_flow_item_eth), error);
508 /* If "spec" is not set, could be any Ethernet */
512 return sfc_mae_parse_item(flocs_eth, RTE_DIM(flocs_eth), spec, mask,
513 ctx_mae->match_spec_action, error);
516 static const struct sfc_flow_item sfc_flow_items[] = {
518 .type = RTE_FLOW_ITEM_TYPE_PHY_PORT,
520 * In terms of RTE flow, this item is a META one,
521 * and its position in the pattern is don't care.
523 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
524 .layer = SFC_FLOW_ITEM_ANY_LAYER,
525 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
526 .parse = sfc_mae_rule_parse_item_phy_port,
529 .type = RTE_FLOW_ITEM_TYPE_PF,
531 * In terms of RTE flow, this item is a META one,
532 * and its position in the pattern is don't care.
534 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
535 .layer = SFC_FLOW_ITEM_ANY_LAYER,
536 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
537 .parse = sfc_mae_rule_parse_item_pf,
540 .type = RTE_FLOW_ITEM_TYPE_VF,
542 * In terms of RTE flow, this item is a META one,
543 * and its position in the pattern is don't care.
545 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
546 .layer = SFC_FLOW_ITEM_ANY_LAYER,
547 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
548 .parse = sfc_mae_rule_parse_item_vf,
551 .type = RTE_FLOW_ITEM_TYPE_ETH,
552 .prev_layer = SFC_FLOW_ITEM_START_LAYER,
553 .layer = SFC_FLOW_ITEM_L2,
554 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
555 .parse = sfc_mae_rule_parse_item_eth,
560 sfc_mae_rule_parse_pattern(struct sfc_adapter *sa,
561 const struct rte_flow_item pattern[],
562 struct sfc_flow_spec_mae *spec,
563 struct rte_flow_error *error)
565 struct sfc_mae_parse_ctx ctx_mae;
566 struct sfc_flow_parse_ctx ctx;
569 memset(&ctx_mae, 0, sizeof(ctx_mae));
572 rc = efx_mae_match_spec_init(sa->nic, EFX_MAE_RULE_ACTION,
574 &ctx_mae.match_spec_action);
576 rc = rte_flow_error_set(error, rc,
577 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
578 "Failed to initialise action rule match specification");
579 goto fail_init_match_spec_action;
582 ctx.type = SFC_FLOW_PARSE_CTX_MAE;
585 rc = sfc_flow_parse_pattern(sfc_flow_items, RTE_DIM(sfc_flow_items),
586 pattern, &ctx, error);
588 goto fail_parse_pattern;
590 if (!efx_mae_match_spec_is_valid(sa->nic, ctx_mae.match_spec_action)) {
591 rc = rte_flow_error_set(error, ENOTSUP,
592 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
593 "Inconsistent pattern");
594 goto fail_validate_match_spec_action;
597 spec->match_spec = ctx_mae.match_spec_action;
601 fail_validate_match_spec_action:
603 efx_mae_match_spec_fini(sa->nic, ctx_mae.match_spec_action);
605 fail_init_match_spec_action:
610 * An action supported by MAE may correspond to a bundle of RTE flow actions,
611 * in example, VLAN_PUSH = OF_PUSH_VLAN + OF_VLAN_SET_VID + OF_VLAN_SET_PCP.
612 * That is, related RTE flow actions need to be tracked as parts of a whole
613 * so that they can be combined into a single action and submitted to MAE
614 * representation of a given rule's action set.
616 * Each RTE flow action provided by an application gets classified as
617 * one belonging to some bundle type. If an action is not supposed to
618 * belong to any bundle, or if this action is END, it is described as
619 * one belonging to a dummy bundle of type EMPTY.
621 * A currently tracked bundle will be submitted if a repeating
622 * action or an action of different bundle type follows.
625 enum sfc_mae_actions_bundle_type {
626 SFC_MAE_ACTIONS_BUNDLE_EMPTY = 0,
627 SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH,
630 struct sfc_mae_actions_bundle {
631 enum sfc_mae_actions_bundle_type type;
633 /* Indicates actions already tracked by the current bundle */
634 uint64_t actions_mask;
636 /* Parameters used by SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH */
637 rte_be16_t vlan_push_tpid;
638 rte_be16_t vlan_push_tci;
642 * Combine configuration of RTE flow actions tracked by the bundle into a
643 * single action and submit the result to MAE action set specification.
644 * Do nothing in the case of dummy action bundle.
647 sfc_mae_actions_bundle_submit(const struct sfc_mae_actions_bundle *bundle,
648 efx_mae_actions_t *spec)
652 switch (bundle->type) {
653 case SFC_MAE_ACTIONS_BUNDLE_EMPTY:
655 case SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH:
656 rc = efx_mae_action_set_populate_vlan_push(
657 spec, bundle->vlan_push_tpid, bundle->vlan_push_tci);
668 * Given the type of the next RTE flow action in the line, decide
669 * whether a new bundle is about to start, and, if this is the case,
670 * submit and reset the current bundle.
673 sfc_mae_actions_bundle_sync(const struct rte_flow_action *action,
674 struct sfc_mae_actions_bundle *bundle,
675 efx_mae_actions_t *spec,
676 struct rte_flow_error *error)
678 enum sfc_mae_actions_bundle_type bundle_type_new;
681 switch (action->type) {
682 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
683 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
684 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
685 bundle_type_new = SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH;
689 * Self-sufficient actions, including END, are handled in this
690 * case. No checks for unsupported actions are needed here
691 * because parsing doesn't occur at this point.
693 bundle_type_new = SFC_MAE_ACTIONS_BUNDLE_EMPTY;
697 if (bundle_type_new != bundle->type ||
698 (bundle->actions_mask & (1ULL << action->type)) != 0) {
699 rc = sfc_mae_actions_bundle_submit(bundle, spec);
703 memset(bundle, 0, sizeof(*bundle));
706 bundle->type = bundle_type_new;
711 return rte_flow_error_set(error, rc,
712 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
713 "Failed to request the (group of) action(s)");
717 sfc_mae_rule_parse_action_of_push_vlan(
718 const struct rte_flow_action_of_push_vlan *conf,
719 struct sfc_mae_actions_bundle *bundle)
721 bundle->vlan_push_tpid = conf->ethertype;
725 sfc_mae_rule_parse_action_of_set_vlan_vid(
726 const struct rte_flow_action_of_set_vlan_vid *conf,
727 struct sfc_mae_actions_bundle *bundle)
729 bundle->vlan_push_tci |= (conf->vlan_vid &
730 rte_cpu_to_be_16(RTE_LEN2MASK(12, uint16_t)));
734 sfc_mae_rule_parse_action_of_set_vlan_pcp(
735 const struct rte_flow_action_of_set_vlan_pcp *conf,
736 struct sfc_mae_actions_bundle *bundle)
738 uint16_t vlan_tci_pcp = (uint16_t)(conf->vlan_pcp &
739 RTE_LEN2MASK(3, uint8_t)) << 13;
741 bundle->vlan_push_tci |= rte_cpu_to_be_16(vlan_tci_pcp);
745 sfc_mae_rule_parse_action_mark(const struct rte_flow_action_mark *conf,
746 efx_mae_actions_t *spec)
748 return efx_mae_action_set_populate_mark(spec, conf->id);
752 sfc_mae_rule_parse_action_phy_port(struct sfc_adapter *sa,
753 const struct rte_flow_action_phy_port *conf,
754 efx_mae_actions_t *spec)
756 efx_mport_sel_t mport;
760 if (conf->original != 0)
761 phy_port = efx_nic_cfg_get(sa->nic)->enc_assigned_port;
763 phy_port = conf->index;
765 rc = efx_mae_mport_by_phy_port(phy_port, &mport);
769 return efx_mae_action_set_populate_deliver(spec, &mport);
773 sfc_mae_rule_parse_action_pf_vf(struct sfc_adapter *sa,
774 const struct rte_flow_action_vf *vf_conf,
775 efx_mae_actions_t *spec)
777 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
778 efx_mport_sel_t mport;
783 vf = EFX_PCI_VF_INVALID;
784 else if (vf_conf->original != 0)
789 rc = efx_mae_mport_by_pcie_function(encp->enc_pf, vf, &mport);
793 return efx_mae_action_set_populate_deliver(spec, &mport);
797 sfc_mae_rule_parse_action(struct sfc_adapter *sa,
798 const struct rte_flow_action *action,
799 struct sfc_mae_actions_bundle *bundle,
800 efx_mae_actions_t *spec,
801 struct rte_flow_error *error)
805 switch (action->type) {
806 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
807 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_POP_VLAN,
808 bundle->actions_mask);
809 rc = efx_mae_action_set_populate_vlan_pop(spec);
811 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
812 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN,
813 bundle->actions_mask);
814 sfc_mae_rule_parse_action_of_push_vlan(action->conf, bundle);
816 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
817 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID,
818 bundle->actions_mask);
819 sfc_mae_rule_parse_action_of_set_vlan_vid(action->conf, bundle);
821 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
822 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP,
823 bundle->actions_mask);
824 sfc_mae_rule_parse_action_of_set_vlan_pcp(action->conf, bundle);
826 case RTE_FLOW_ACTION_TYPE_FLAG:
827 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_FLAG,
828 bundle->actions_mask);
829 rc = efx_mae_action_set_populate_flag(spec);
831 case RTE_FLOW_ACTION_TYPE_MARK:
832 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_MARK,
833 bundle->actions_mask);
834 rc = sfc_mae_rule_parse_action_mark(action->conf, spec);
836 case RTE_FLOW_ACTION_TYPE_PHY_PORT:
837 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_PHY_PORT,
838 bundle->actions_mask);
839 rc = sfc_mae_rule_parse_action_phy_port(sa, action->conf, spec);
841 case RTE_FLOW_ACTION_TYPE_PF:
842 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_PF,
843 bundle->actions_mask);
844 rc = sfc_mae_rule_parse_action_pf_vf(sa, NULL, spec);
846 case RTE_FLOW_ACTION_TYPE_VF:
847 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VF,
848 bundle->actions_mask);
849 rc = sfc_mae_rule_parse_action_pf_vf(sa, action->conf, spec);
851 case RTE_FLOW_ACTION_TYPE_DROP:
852 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_DROP,
853 bundle->actions_mask);
854 rc = efx_mae_action_set_populate_drop(spec);
857 return rte_flow_error_set(error, ENOTSUP,
858 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
859 "Unsupported action");
863 rc = rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ACTION,
864 NULL, "Failed to request the action");
866 bundle->actions_mask |= (1ULL << action->type);
873 sfc_mae_rule_parse_actions(struct sfc_adapter *sa,
874 const struct rte_flow_action actions[],
875 struct sfc_mae_action_set **action_setp,
876 struct rte_flow_error *error)
878 struct sfc_mae_actions_bundle bundle = {0};
879 const struct rte_flow_action *action;
880 efx_mae_actions_t *spec;
883 if (actions == NULL) {
884 return rte_flow_error_set(error, EINVAL,
885 RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
889 rc = efx_mae_action_set_spec_init(sa->nic, &spec);
891 goto fail_action_set_spec_init;
893 for (action = actions;
894 action->type != RTE_FLOW_ACTION_TYPE_END; ++action) {
895 rc = sfc_mae_actions_bundle_sync(action, &bundle, spec, error);
897 goto fail_rule_parse_action;
899 rc = sfc_mae_rule_parse_action(sa, action, &bundle, spec,
902 goto fail_rule_parse_action;
905 rc = sfc_mae_actions_bundle_sync(action, &bundle, spec, error);
907 goto fail_rule_parse_action;
909 *action_setp = sfc_mae_action_set_attach(sa, spec);
910 if (*action_setp != NULL) {
911 efx_mae_action_set_spec_fini(sa->nic, spec);
915 rc = sfc_mae_action_set_add(sa, spec, action_setp);
917 goto fail_action_set_add;
922 fail_rule_parse_action:
923 efx_mae_action_set_spec_fini(sa->nic, spec);
925 fail_action_set_spec_init:
927 rc = rte_flow_error_set(error, rc,
928 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
929 NULL, "Failed to process the action");
935 sfc_mae_rules_class_cmp(struct sfc_adapter *sa,
936 const efx_mae_match_spec_t *left,
937 const efx_mae_match_spec_t *right)
939 bool have_same_class;
942 rc = efx_mae_match_specs_class_cmp(sa->nic, left, right,
945 return (rc == 0) ? have_same_class : false;
949 sfc_mae_action_rule_class_verify(struct sfc_adapter *sa,
950 struct sfc_flow_spec_mae *spec)
952 const struct rte_flow *entry;
954 TAILQ_FOREACH_REVERSE(entry, &sa->flow_list, sfc_flow_list, entries) {
955 const struct sfc_flow_spec *entry_spec = &entry->spec;
956 const struct sfc_flow_spec_mae *es_mae = &entry_spec->mae;
957 const efx_mae_match_spec_t *left = es_mae->match_spec;
958 const efx_mae_match_spec_t *right = spec->match_spec;
960 switch (entry_spec->type) {
961 case SFC_FLOW_SPEC_FILTER:
962 /* Ignore VNIC-level flows */
964 case SFC_FLOW_SPEC_MAE:
965 if (sfc_mae_rules_class_cmp(sa, left, right))
973 sfc_info(sa, "for now, the HW doesn't support rule validation, and HW "
974 "support for inner frame pattern items is not guaranteed; "
975 "other than that, the items are valid from SW standpoint");
980 * Confirm that a given flow can be accepted by the FW.
983 * Software adapter context
985 * Flow to be verified
987 * Zero on success and non-zero in the case of error.
988 * A special value of EAGAIN indicates that the adapter is
989 * not in started state. This state is compulsory because
990 * it only makes sense to compare the rule class of the flow
991 * being validated with classes of the active rules.
992 * Such classes are wittingly supported by the FW.
995 sfc_mae_flow_verify(struct sfc_adapter *sa,
996 struct rte_flow *flow)
998 struct sfc_flow_spec *spec = &flow->spec;
999 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
1001 SFC_ASSERT(sfc_adapter_is_locked(sa));
1003 if (sa->state != SFC_ADAPTER_STARTED)
1006 return sfc_mae_action_rule_class_verify(sa, spec_mae);
1010 sfc_mae_flow_insert(struct sfc_adapter *sa,
1011 struct rte_flow *flow)
1013 struct sfc_flow_spec *spec = &flow->spec;
1014 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
1015 struct sfc_mae_action_set *action_set = spec_mae->action_set;
1016 struct sfc_mae_fw_rsrc *fw_rsrc = &action_set->fw_rsrc;
1019 SFC_ASSERT(spec_mae->rule_id.id == EFX_MAE_RSRC_ID_INVALID);
1020 SFC_ASSERT(action_set != NULL);
1022 rc = sfc_mae_action_set_enable(sa, action_set);
1024 goto fail_action_set_enable;
1026 rc = efx_mae_action_rule_insert(sa->nic, spec_mae->match_spec,
1027 NULL, &fw_rsrc->aset_id,
1028 &spec_mae->rule_id);
1030 goto fail_action_rule_insert;
1034 fail_action_rule_insert:
1035 (void)sfc_mae_action_set_disable(sa, action_set);
1037 fail_action_set_enable:
1042 sfc_mae_flow_remove(struct sfc_adapter *sa,
1043 struct rte_flow *flow)
1045 struct sfc_flow_spec *spec = &flow->spec;
1046 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
1047 struct sfc_mae_action_set *action_set = spec_mae->action_set;
1050 SFC_ASSERT(spec_mae->rule_id.id != EFX_MAE_RSRC_ID_INVALID);
1051 SFC_ASSERT(action_set != NULL);
1053 rc = efx_mae_action_rule_remove(sa->nic, &spec_mae->rule_id);
1057 spec_mae->rule_id.id = EFX_MAE_RSRC_ID_INVALID;
1059 return sfc_mae_action_set_disable(sa, action_set);