1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2019-2021 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_bitops.h>
13 #include <rte_common.h>
14 #include <rte_vxlan.h>
19 #include "sfc_flow_tunnel.h"
20 #include "sfc_mae_counter.h"
22 #include "sfc_switch.h"
23 #include "sfc_service.h"
26 sfc_mae_assign_ethdev_mport(struct sfc_adapter *sa,
27 efx_mport_sel_t *mportp)
29 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
31 return efx_mae_mport_by_pcie_function(encp->enc_pf, encp->enc_vf,
36 sfc_mae_assign_entity_mport(struct sfc_adapter *sa,
37 efx_mport_sel_t *mportp)
39 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
42 if (encp->enc_mae_admin) {
44 * This ethdev sits on MAE admin PF. The represented
45 * entity is the network port assigned to that PF.
47 rc = efx_mae_mport_by_phy_port(encp->enc_assigned_port, mportp);
50 * This ethdev sits on unprivileged PF / VF. The entity
51 * represented by the ethdev can change dynamically
52 * as MAE admin changes default traffic rules.
54 * For the sake of simplicity, do not fill in the m-port
55 * and assume that flow rules should not be allowed to
56 * reference the entity represented by this ethdev.
58 efx_mae_mport_invalid(mportp);
65 sfc_mae_counter_registry_init(struct sfc_mae_counter_registry *registry,
66 uint32_t nb_counters_max)
68 return sfc_mae_counters_init(®istry->counters, nb_counters_max);
72 sfc_mae_counter_registry_fini(struct sfc_mae_counter_registry *registry)
74 sfc_mae_counters_fini(®istry->counters);
78 sfc_mae_internal_rule_find_empty_slot(struct sfc_adapter *sa,
79 struct sfc_mae_rule **rule)
81 struct sfc_mae *mae = &sa->mae;
82 struct sfc_mae_internal_rules *internal_rules = &mae->internal_rules;
86 for (entry = 0; entry < SFC_MAE_NB_RULES_MAX; entry++) {
87 if (internal_rules->rules[entry].spec == NULL)
91 if (entry == SFC_MAE_NB_RULES_MAX) {
93 sfc_err(sa, "failed too many rules (%u rules used)", entry);
94 goto fail_too_many_rules;
97 *rule = &internal_rules->rules[entry];
106 sfc_mae_rule_add_mport_match_deliver(struct sfc_adapter *sa,
107 const efx_mport_sel_t *mport_match,
108 const efx_mport_sel_t *mport_deliver,
109 int prio, struct sfc_mae_rule **rulep)
111 struct sfc_mae *mae = &sa->mae;
112 struct sfc_mae_rule *rule;
115 sfc_log_init(sa, "entry");
117 if (prio > 0 && (unsigned int)prio >= mae->nb_action_rule_prios_max) {
119 sfc_err(sa, "failed: invalid priority %d (max %u)", prio,
120 mae->nb_action_rule_prios_max);
121 goto fail_invalid_prio;
124 prio = mae->nb_action_rule_prios_max - 1;
126 rc = sfc_mae_internal_rule_find_empty_slot(sa, &rule);
128 goto fail_find_empty_slot;
130 sfc_log_init(sa, "init MAE match spec");
131 rc = efx_mae_match_spec_init(sa->nic, EFX_MAE_RULE_ACTION,
132 (uint32_t)prio, &rule->spec);
134 sfc_err(sa, "failed to init MAE match spec");
135 goto fail_match_init;
138 rc = efx_mae_match_spec_mport_set(rule->spec, mport_match, NULL);
140 sfc_err(sa, "failed to get MAE match mport selector");
144 rc = efx_mae_action_set_spec_init(sa->nic, &rule->actions);
146 sfc_err(sa, "failed to init MAE action set");
147 goto fail_action_init;
150 rc = efx_mae_action_set_populate_deliver(rule->actions,
153 sfc_err(sa, "failed to populate deliver action");
154 goto fail_populate_deliver;
157 rc = efx_mae_action_set_alloc(sa->nic, rule->actions,
160 sfc_err(sa, "failed to allocate action set");
161 goto fail_action_set_alloc;
164 rc = efx_mae_action_rule_insert(sa->nic, rule->spec, NULL,
168 sfc_err(sa, "failed to insert action rule");
169 goto fail_rule_insert;
174 sfc_log_init(sa, "done");
179 efx_mae_action_set_free(sa->nic, &rule->action_set);
181 fail_action_set_alloc:
182 fail_populate_deliver:
183 efx_mae_action_set_spec_fini(sa->nic, rule->actions);
187 efx_mae_match_spec_fini(sa->nic, rule->spec);
190 fail_find_empty_slot:
192 sfc_log_init(sa, "failed: %s", rte_strerror(rc));
197 sfc_mae_rule_del(struct sfc_adapter *sa, struct sfc_mae_rule *rule)
199 if (rule == NULL || rule->spec == NULL)
202 efx_mae_action_rule_remove(sa->nic, &rule->rule_id);
203 efx_mae_action_set_free(sa->nic, &rule->action_set);
204 efx_mae_action_set_spec_fini(sa->nic, rule->actions);
205 efx_mae_match_spec_fini(sa->nic, rule->spec);
211 sfc_mae_attach(struct sfc_adapter *sa)
213 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
214 struct sfc_mae_switch_port_request switch_port_request = {0};
215 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
216 efx_mport_sel_t ethdev_mport;
217 efx_mport_sel_t entity_mport;
218 struct sfc_mae *mae = &sa->mae;
219 struct sfc_mae_bounce_eh *bounce_eh = &mae->bounce_eh;
220 efx_mae_limits_t limits;
223 sfc_log_init(sa, "entry");
225 if (!encp->enc_mae_supported) {
226 mae->status = SFC_MAE_STATUS_UNSUPPORTED;
230 if (encp->enc_mae_admin) {
231 sfc_log_init(sa, "init MAE");
232 rc = efx_mae_init(sa->nic);
236 sfc_log_init(sa, "get MAE limits");
237 rc = efx_mae_get_limits(sa->nic, &limits);
239 goto fail_mae_get_limits;
241 sfc_log_init(sa, "init MAE counter registry");
242 rc = sfc_mae_counter_registry_init(&mae->counter_registry,
243 limits.eml_max_n_counters);
245 sfc_err(sa, "failed to init MAE counters registry for %u entries: %s",
246 limits.eml_max_n_counters, rte_strerror(rc));
247 goto fail_counter_registry_init;
251 sfc_log_init(sa, "assign ethdev MPORT");
252 rc = sfc_mae_assign_ethdev_mport(sa, ðdev_mport);
254 goto fail_mae_assign_ethdev_mport;
256 sfc_log_init(sa, "assign entity MPORT");
257 rc = sfc_mae_assign_entity_mport(sa, &entity_mport);
259 goto fail_mae_assign_entity_mport;
261 sfc_log_init(sa, "assign RTE switch domain");
262 rc = sfc_mae_assign_switch_domain(sa, &mae->switch_domain_id);
264 goto fail_mae_assign_switch_domain;
266 sfc_log_init(sa, "assign RTE switch port");
267 switch_port_request.type = SFC_MAE_SWITCH_PORT_INDEPENDENT;
268 switch_port_request.ethdev_mportp = ðdev_mport;
269 switch_port_request.entity_mportp = &entity_mport;
270 switch_port_request.ethdev_port_id = sas->port_id;
271 switch_port_request.port_data.indep.mae_admin =
272 encp->enc_mae_admin == B_TRUE;
273 rc = sfc_mae_assign_switch_port(mae->switch_domain_id,
274 &switch_port_request,
275 &mae->switch_port_id);
277 goto fail_mae_assign_switch_port;
279 if (encp->enc_mae_admin) {
280 sfc_log_init(sa, "allocate encap. header bounce buffer");
281 bounce_eh->buf_size = limits.eml_encap_header_size_limit;
282 bounce_eh->buf = rte_malloc("sfc_mae_bounce_eh",
283 bounce_eh->buf_size, 0);
284 if (bounce_eh->buf == NULL)
285 goto fail_mae_alloc_bounce_eh;
287 mae->nb_outer_rule_prios_max = limits.eml_max_n_outer_prios;
288 mae->nb_action_rule_prios_max = limits.eml_max_n_action_prios;
289 mae->encap_types_supported = limits.eml_encap_types_supported;
292 TAILQ_INIT(&mae->outer_rules);
293 TAILQ_INIT(&mae->encap_headers);
294 TAILQ_INIT(&mae->action_sets);
296 if (encp->enc_mae_admin)
297 mae->status = SFC_MAE_STATUS_ADMIN;
299 mae->status = SFC_MAE_STATUS_SUPPORTED;
301 sfc_log_init(sa, "done");
305 fail_mae_alloc_bounce_eh:
306 fail_mae_assign_switch_port:
307 fail_mae_assign_switch_domain:
308 fail_mae_assign_entity_mport:
309 fail_mae_assign_ethdev_mport:
310 if (encp->enc_mae_admin)
311 sfc_mae_counter_registry_fini(&mae->counter_registry);
313 fail_counter_registry_init:
315 if (encp->enc_mae_admin)
316 efx_mae_fini(sa->nic);
319 sfc_log_init(sa, "failed %d", rc);
325 sfc_mae_detach(struct sfc_adapter *sa)
327 struct sfc_mae *mae = &sa->mae;
328 enum sfc_mae_status status_prev = mae->status;
330 sfc_log_init(sa, "entry");
332 mae->nb_action_rule_prios_max = 0;
333 mae->status = SFC_MAE_STATUS_UNKNOWN;
335 if (status_prev != SFC_MAE_STATUS_ADMIN)
338 rte_free(mae->bounce_eh.buf);
339 sfc_mae_counter_registry_fini(&mae->counter_registry);
341 efx_mae_fini(sa->nic);
343 sfc_log_init(sa, "done");
346 static struct sfc_mae_outer_rule *
347 sfc_mae_outer_rule_attach(struct sfc_adapter *sa,
348 const efx_mae_match_spec_t *match_spec,
349 efx_tunnel_protocol_t encap_type)
351 struct sfc_mae_outer_rule *rule;
352 struct sfc_mae *mae = &sa->mae;
354 SFC_ASSERT(sfc_adapter_is_locked(sa));
356 TAILQ_FOREACH(rule, &mae->outer_rules, entries) {
357 if (efx_mae_match_specs_equal(rule->match_spec, match_spec) &&
358 rule->encap_type == encap_type) {
359 sfc_dbg(sa, "attaching to outer_rule=%p", rule);
369 sfc_mae_outer_rule_add(struct sfc_adapter *sa,
370 efx_mae_match_spec_t *match_spec,
371 efx_tunnel_protocol_t encap_type,
372 struct sfc_mae_outer_rule **rulep)
374 struct sfc_mae_outer_rule *rule;
375 struct sfc_mae *mae = &sa->mae;
377 SFC_ASSERT(sfc_adapter_is_locked(sa));
379 rule = rte_zmalloc("sfc_mae_outer_rule", sizeof(*rule), 0);
384 rule->match_spec = match_spec;
385 rule->encap_type = encap_type;
387 rule->fw_rsrc.rule_id.id = EFX_MAE_RSRC_ID_INVALID;
389 TAILQ_INSERT_TAIL(&mae->outer_rules, rule, entries);
393 sfc_dbg(sa, "added outer_rule=%p", rule);
399 sfc_mae_outer_rule_del(struct sfc_adapter *sa,
400 struct sfc_mae_outer_rule *rule)
402 struct sfc_mae *mae = &sa->mae;
404 SFC_ASSERT(sfc_adapter_is_locked(sa));
405 SFC_ASSERT(rule->refcnt != 0);
409 if (rule->refcnt != 0)
412 if (rule->fw_rsrc.rule_id.id != EFX_MAE_RSRC_ID_INVALID ||
413 rule->fw_rsrc.refcnt != 0) {
414 sfc_err(sa, "deleting outer_rule=%p abandons its FW resource: OR_ID=0x%08x, refcnt=%u",
415 rule, rule->fw_rsrc.rule_id.id, rule->fw_rsrc.refcnt);
418 efx_mae_match_spec_fini(sa->nic, rule->match_spec);
420 TAILQ_REMOVE(&mae->outer_rules, rule, entries);
423 sfc_dbg(sa, "deleted outer_rule=%p", rule);
427 sfc_mae_outer_rule_enable(struct sfc_adapter *sa,
428 struct sfc_mae_outer_rule *rule,
429 efx_mae_match_spec_t *match_spec_action)
431 struct sfc_mae_fw_rsrc *fw_rsrc = &rule->fw_rsrc;
434 SFC_ASSERT(sfc_adapter_is_locked(sa));
436 if (fw_rsrc->refcnt == 0) {
437 SFC_ASSERT(fw_rsrc->rule_id.id == EFX_MAE_RSRC_ID_INVALID);
438 SFC_ASSERT(rule->match_spec != NULL);
440 rc = efx_mae_outer_rule_insert(sa->nic, rule->match_spec,
444 sfc_err(sa, "failed to enable outer_rule=%p: %s",
450 if (match_spec_action == NULL)
451 goto skip_action_rule;
453 rc = efx_mae_match_spec_outer_rule_id_set(match_spec_action,
456 if (fw_rsrc->refcnt == 0) {
457 (void)efx_mae_outer_rule_remove(sa->nic,
459 fw_rsrc->rule_id.id = EFX_MAE_RSRC_ID_INVALID;
462 sfc_err(sa, "can't match on outer rule ID: %s", strerror(rc));
468 if (fw_rsrc->refcnt == 0) {
469 sfc_dbg(sa, "enabled outer_rule=%p: OR_ID=0x%08x",
470 rule, fw_rsrc->rule_id.id);
479 sfc_mae_outer_rule_disable(struct sfc_adapter *sa,
480 struct sfc_mae_outer_rule *rule)
482 struct sfc_mae_fw_rsrc *fw_rsrc = &rule->fw_rsrc;
485 SFC_ASSERT(sfc_adapter_is_locked(sa));
487 if (fw_rsrc->rule_id.id == EFX_MAE_RSRC_ID_INVALID ||
488 fw_rsrc->refcnt == 0) {
489 sfc_err(sa, "failed to disable outer_rule=%p: already disabled; OR_ID=0x%08x, refcnt=%u",
490 rule, fw_rsrc->rule_id.id, fw_rsrc->refcnt);
494 if (fw_rsrc->refcnt == 1) {
495 rc = efx_mae_outer_rule_remove(sa->nic, &fw_rsrc->rule_id);
497 sfc_dbg(sa, "disabled outer_rule=%p with OR_ID=0x%08x",
498 rule, fw_rsrc->rule_id.id);
500 sfc_err(sa, "failed to disable outer_rule=%p with OR_ID=0x%08x: %s",
501 rule, fw_rsrc->rule_id.id, strerror(rc));
503 fw_rsrc->rule_id.id = EFX_MAE_RSRC_ID_INVALID;
509 static struct sfc_mae_encap_header *
510 sfc_mae_encap_header_attach(struct sfc_adapter *sa,
511 const struct sfc_mae_bounce_eh *bounce_eh)
513 struct sfc_mae_encap_header *encap_header;
514 struct sfc_mae *mae = &sa->mae;
516 SFC_ASSERT(sfc_adapter_is_locked(sa));
518 TAILQ_FOREACH(encap_header, &mae->encap_headers, entries) {
519 if (encap_header->size == bounce_eh->size &&
520 memcmp(encap_header->buf, bounce_eh->buf,
521 bounce_eh->size) == 0) {
522 sfc_dbg(sa, "attaching to encap_header=%p",
524 ++(encap_header->refcnt);
533 sfc_mae_encap_header_add(struct sfc_adapter *sa,
534 const struct sfc_mae_bounce_eh *bounce_eh,
535 struct sfc_mae_encap_header **encap_headerp)
537 struct sfc_mae_encap_header *encap_header;
538 struct sfc_mae *mae = &sa->mae;
540 SFC_ASSERT(sfc_adapter_is_locked(sa));
542 encap_header = rte_zmalloc("sfc_mae_encap_header",
543 sizeof(*encap_header), 0);
544 if (encap_header == NULL)
547 encap_header->size = bounce_eh->size;
549 encap_header->buf = rte_malloc("sfc_mae_encap_header_buf",
550 encap_header->size, 0);
551 if (encap_header->buf == NULL) {
552 rte_free(encap_header);
556 rte_memcpy(encap_header->buf, bounce_eh->buf, bounce_eh->size);
558 encap_header->refcnt = 1;
559 encap_header->type = bounce_eh->type;
560 encap_header->fw_rsrc.eh_id.id = EFX_MAE_RSRC_ID_INVALID;
562 TAILQ_INSERT_TAIL(&mae->encap_headers, encap_header, entries);
564 *encap_headerp = encap_header;
566 sfc_dbg(sa, "added encap_header=%p", encap_header);
572 sfc_mae_encap_header_del(struct sfc_adapter *sa,
573 struct sfc_mae_encap_header *encap_header)
575 struct sfc_mae *mae = &sa->mae;
577 if (encap_header == NULL)
580 SFC_ASSERT(sfc_adapter_is_locked(sa));
581 SFC_ASSERT(encap_header->refcnt != 0);
583 --(encap_header->refcnt);
585 if (encap_header->refcnt != 0)
588 if (encap_header->fw_rsrc.eh_id.id != EFX_MAE_RSRC_ID_INVALID ||
589 encap_header->fw_rsrc.refcnt != 0) {
590 sfc_err(sa, "deleting encap_header=%p abandons its FW resource: EH_ID=0x%08x, refcnt=%u",
591 encap_header, encap_header->fw_rsrc.eh_id.id,
592 encap_header->fw_rsrc.refcnt);
595 TAILQ_REMOVE(&mae->encap_headers, encap_header, entries);
596 rte_free(encap_header->buf);
597 rte_free(encap_header);
599 sfc_dbg(sa, "deleted encap_header=%p", encap_header);
603 sfc_mae_encap_header_enable(struct sfc_adapter *sa,
604 struct sfc_mae_encap_header *encap_header,
605 efx_mae_actions_t *action_set_spec)
607 struct sfc_mae_fw_rsrc *fw_rsrc;
610 if (encap_header == NULL)
613 SFC_ASSERT(sfc_adapter_is_locked(sa));
615 fw_rsrc = &encap_header->fw_rsrc;
617 if (fw_rsrc->refcnt == 0) {
618 SFC_ASSERT(fw_rsrc->eh_id.id == EFX_MAE_RSRC_ID_INVALID);
619 SFC_ASSERT(encap_header->buf != NULL);
620 SFC_ASSERT(encap_header->size != 0);
622 rc = efx_mae_encap_header_alloc(sa->nic, encap_header->type,
627 sfc_err(sa, "failed to enable encap_header=%p: %s",
628 encap_header, strerror(rc));
633 rc = efx_mae_action_set_fill_in_eh_id(action_set_spec,
636 if (fw_rsrc->refcnt == 0) {
637 (void)efx_mae_encap_header_free(sa->nic,
639 fw_rsrc->eh_id.id = EFX_MAE_RSRC_ID_INVALID;
642 sfc_err(sa, "can't fill in encap. header ID: %s", strerror(rc));
647 if (fw_rsrc->refcnt == 0) {
648 sfc_dbg(sa, "enabled encap_header=%p: EH_ID=0x%08x",
649 encap_header, fw_rsrc->eh_id.id);
658 sfc_mae_encap_header_disable(struct sfc_adapter *sa,
659 struct sfc_mae_encap_header *encap_header)
661 struct sfc_mae_fw_rsrc *fw_rsrc;
664 if (encap_header == NULL)
667 SFC_ASSERT(sfc_adapter_is_locked(sa));
669 fw_rsrc = &encap_header->fw_rsrc;
671 if (fw_rsrc->eh_id.id == EFX_MAE_RSRC_ID_INVALID ||
672 fw_rsrc->refcnt == 0) {
673 sfc_err(sa, "failed to disable encap_header=%p: already disabled; EH_ID=0x%08x, refcnt=%u",
674 encap_header, fw_rsrc->eh_id.id, fw_rsrc->refcnt);
678 if (fw_rsrc->refcnt == 1) {
679 rc = efx_mae_encap_header_free(sa->nic, &fw_rsrc->eh_id);
681 sfc_dbg(sa, "disabled encap_header=%p with EH_ID=0x%08x",
682 encap_header, fw_rsrc->eh_id.id);
684 sfc_err(sa, "failed to disable encap_header=%p with EH_ID=0x%08x: %s",
685 encap_header, fw_rsrc->eh_id.id, strerror(rc));
687 fw_rsrc->eh_id.id = EFX_MAE_RSRC_ID_INVALID;
694 sfc_mae_counters_enable(struct sfc_adapter *sa,
695 struct sfc_mae_counter_id *counters,
696 unsigned int n_counters,
697 efx_mae_actions_t *action_set_spec)
701 sfc_log_init(sa, "entry");
703 if (n_counters == 0) {
704 sfc_log_init(sa, "no counters - skip");
708 SFC_ASSERT(sfc_adapter_is_locked(sa));
709 SFC_ASSERT(n_counters == 1);
711 rc = sfc_mae_counter_enable(sa, &counters[0]);
713 sfc_err(sa, "failed to enable MAE counter %u: %s",
714 counters[0].mae_id.id, rte_strerror(rc));
715 goto fail_counter_add;
718 rc = efx_mae_action_set_fill_in_counter_id(action_set_spec,
719 &counters[0].mae_id);
721 sfc_err(sa, "failed to fill in MAE counter %u in action set: %s",
722 counters[0].mae_id.id, rte_strerror(rc));
723 goto fail_fill_in_id;
729 (void)sfc_mae_counter_disable(sa, &counters[0]);
732 sfc_log_init(sa, "failed: %s", rte_strerror(rc));
737 sfc_mae_counters_disable(struct sfc_adapter *sa,
738 struct sfc_mae_counter_id *counters,
739 unsigned int n_counters)
744 SFC_ASSERT(sfc_adapter_is_locked(sa));
745 SFC_ASSERT(n_counters == 1);
747 if (counters[0].mae_id.id == EFX_MAE_RSRC_ID_INVALID) {
748 sfc_err(sa, "failed to disable: already disabled");
752 return sfc_mae_counter_disable(sa, &counters[0]);
755 struct sfc_mae_aset_ctx {
756 uint64_t *ft_group_hit_counter;
757 struct sfc_mae_encap_header *encap_header;
758 struct sfc_flow_tunnel *counter_ft;
759 unsigned int n_counters;
761 efx_mae_actions_t *spec;
764 static struct sfc_mae_action_set *
765 sfc_mae_action_set_attach(struct sfc_adapter *sa,
766 const struct sfc_mae_aset_ctx *ctx)
768 struct sfc_mae_action_set *action_set;
769 struct sfc_mae *mae = &sa->mae;
771 SFC_ASSERT(sfc_adapter_is_locked(sa));
774 * Shared counters are not supported, hence, action
775 * sets with counters are not attachable.
777 if (ctx->n_counters != 0)
780 TAILQ_FOREACH(action_set, &mae->action_sets, entries) {
781 if (action_set->encap_header == ctx->encap_header &&
782 efx_mae_action_set_specs_equal(action_set->spec,
784 sfc_dbg(sa, "attaching to action_set=%p", action_set);
785 ++(action_set->refcnt);
794 sfc_mae_action_set_add(struct sfc_adapter *sa,
795 const struct rte_flow_action actions[],
796 const struct sfc_mae_aset_ctx *ctx,
797 struct sfc_mae_action_set **action_setp)
799 struct sfc_mae_action_set *action_set;
800 struct sfc_mae *mae = &sa->mae;
803 SFC_ASSERT(sfc_adapter_is_locked(sa));
805 action_set = rte_zmalloc("sfc_mae_action_set", sizeof(*action_set), 0);
806 if (action_set == NULL) {
807 sfc_err(sa, "failed to alloc action set");
811 if (ctx->n_counters > 0) {
812 const struct rte_flow_action *action;
814 action_set->counters = rte_malloc("sfc_mae_counter_ids",
815 sizeof(action_set->counters[0]) * ctx->n_counters, 0);
816 if (action_set->counters == NULL) {
817 rte_free(action_set);
818 sfc_err(sa, "failed to alloc counters");
822 for (i = 0; i < ctx->n_counters; ++i) {
823 action_set->counters[i].rte_id_valid = B_FALSE;
824 action_set->counters[i].mae_id.id =
825 EFX_MAE_RSRC_ID_INVALID;
827 action_set->counters[i].ft_group_hit_counter =
828 ctx->ft_group_hit_counter;
829 action_set->counters[i].ft = ctx->counter_ft;
832 for (action = actions, i = 0;
833 action->type != RTE_FLOW_ACTION_TYPE_END &&
834 i < ctx->n_counters; ++action) {
835 const struct rte_flow_action_count *conf;
837 if (action->type != RTE_FLOW_ACTION_TYPE_COUNT)
842 action_set->counters[i].rte_id_valid = B_TRUE;
843 action_set->counters[i].rte_id = conf->id;
846 action_set->n_counters = ctx->n_counters;
849 action_set->refcnt = 1;
850 action_set->spec = ctx->spec;
851 action_set->encap_header = ctx->encap_header;
853 action_set->fw_rsrc.aset_id.id = EFX_MAE_RSRC_ID_INVALID;
855 TAILQ_INSERT_TAIL(&mae->action_sets, action_set, entries);
857 *action_setp = action_set;
859 sfc_dbg(sa, "added action_set=%p", action_set);
865 sfc_mae_action_set_del(struct sfc_adapter *sa,
866 struct sfc_mae_action_set *action_set)
868 struct sfc_mae *mae = &sa->mae;
870 SFC_ASSERT(sfc_adapter_is_locked(sa));
871 SFC_ASSERT(action_set->refcnt != 0);
873 --(action_set->refcnt);
875 if (action_set->refcnt != 0)
878 if (action_set->fw_rsrc.aset_id.id != EFX_MAE_RSRC_ID_INVALID ||
879 action_set->fw_rsrc.refcnt != 0) {
880 sfc_err(sa, "deleting action_set=%p abandons its FW resource: AS_ID=0x%08x, refcnt=%u",
881 action_set, action_set->fw_rsrc.aset_id.id,
882 action_set->fw_rsrc.refcnt);
885 efx_mae_action_set_spec_fini(sa->nic, action_set->spec);
886 sfc_mae_encap_header_del(sa, action_set->encap_header);
887 if (action_set->n_counters > 0) {
888 SFC_ASSERT(action_set->n_counters == 1);
889 SFC_ASSERT(action_set->counters[0].mae_id.id ==
890 EFX_MAE_RSRC_ID_INVALID);
891 rte_free(action_set->counters);
893 TAILQ_REMOVE(&mae->action_sets, action_set, entries);
894 rte_free(action_set);
896 sfc_dbg(sa, "deleted action_set=%p", action_set);
900 sfc_mae_action_set_enable(struct sfc_adapter *sa,
901 struct sfc_mae_action_set *action_set)
903 struct sfc_mae_encap_header *encap_header = action_set->encap_header;
904 struct sfc_mae_counter_id *counters = action_set->counters;
905 struct sfc_mae_fw_rsrc *fw_rsrc = &action_set->fw_rsrc;
908 SFC_ASSERT(sfc_adapter_is_locked(sa));
910 if (fw_rsrc->refcnt == 0) {
911 SFC_ASSERT(fw_rsrc->aset_id.id == EFX_MAE_RSRC_ID_INVALID);
912 SFC_ASSERT(action_set->spec != NULL);
914 rc = sfc_mae_encap_header_enable(sa, encap_header,
919 rc = sfc_mae_counters_enable(sa, counters,
920 action_set->n_counters,
923 sfc_err(sa, "failed to enable %u MAE counters: %s",
924 action_set->n_counters, rte_strerror(rc));
926 sfc_mae_encap_header_disable(sa, encap_header);
930 rc = efx_mae_action_set_alloc(sa->nic, action_set->spec,
933 sfc_err(sa, "failed to enable action_set=%p: %s",
934 action_set, strerror(rc));
936 (void)sfc_mae_counters_disable(sa, counters,
937 action_set->n_counters);
938 sfc_mae_encap_header_disable(sa, encap_header);
942 sfc_dbg(sa, "enabled action_set=%p: AS_ID=0x%08x",
943 action_set, fw_rsrc->aset_id.id);
952 sfc_mae_action_set_disable(struct sfc_adapter *sa,
953 struct sfc_mae_action_set *action_set)
955 struct sfc_mae_fw_rsrc *fw_rsrc = &action_set->fw_rsrc;
958 SFC_ASSERT(sfc_adapter_is_locked(sa));
960 if (fw_rsrc->aset_id.id == EFX_MAE_RSRC_ID_INVALID ||
961 fw_rsrc->refcnt == 0) {
962 sfc_err(sa, "failed to disable action_set=%p: already disabled; AS_ID=0x%08x, refcnt=%u",
963 action_set, fw_rsrc->aset_id.id, fw_rsrc->refcnt);
967 if (fw_rsrc->refcnt == 1) {
968 rc = efx_mae_action_set_free(sa->nic, &fw_rsrc->aset_id);
970 sfc_dbg(sa, "disabled action_set=%p with AS_ID=0x%08x",
971 action_set, fw_rsrc->aset_id.id);
973 sfc_err(sa, "failed to disable action_set=%p with AS_ID=0x%08x: %s",
974 action_set, fw_rsrc->aset_id.id, strerror(rc));
976 fw_rsrc->aset_id.id = EFX_MAE_RSRC_ID_INVALID;
978 rc = sfc_mae_counters_disable(sa, action_set->counters,
979 action_set->n_counters);
981 sfc_err(sa, "failed to disable %u MAE counters: %s",
982 action_set->n_counters, rte_strerror(rc));
985 sfc_mae_encap_header_disable(sa, action_set->encap_header);
992 sfc_mae_flow_cleanup(struct sfc_adapter *sa,
993 struct rte_flow *flow)
995 struct sfc_flow_spec *spec;
996 struct sfc_flow_spec_mae *spec_mae;
1006 spec_mae = &spec->mae;
1008 if (spec_mae->ft != NULL) {
1009 if (spec_mae->ft_rule_type == SFC_FT_RULE_JUMP)
1010 spec_mae->ft->jump_rule_is_set = B_FALSE;
1012 SFC_ASSERT(spec_mae->ft->refcnt != 0);
1013 --(spec_mae->ft->refcnt);
1016 SFC_ASSERT(spec_mae->rule_id.id == EFX_MAE_RSRC_ID_INVALID);
1018 if (spec_mae->outer_rule != NULL)
1019 sfc_mae_outer_rule_del(sa, spec_mae->outer_rule);
1021 if (spec_mae->action_set != NULL)
1022 sfc_mae_action_set_del(sa, spec_mae->action_set);
1024 if (spec_mae->match_spec != NULL)
1025 efx_mae_match_spec_fini(sa->nic, spec_mae->match_spec);
1029 sfc_mae_set_ethertypes(struct sfc_mae_parse_ctx *ctx)
1031 struct sfc_mae_pattern_data *pdata = &ctx->pattern_data;
1032 const efx_mae_field_id_t *fremap = ctx->field_ids_remap;
1033 const efx_mae_field_id_t field_ids[] = {
1034 EFX_MAE_FIELD_VLAN0_PROTO_BE,
1035 EFX_MAE_FIELD_VLAN1_PROTO_BE,
1037 const struct sfc_mae_ethertype *et;
1042 * In accordance with RTE flow API convention, the innermost L2
1043 * item's "type" ("inner_type") is a L3 EtherType. If there is
1044 * no L3 item, it's 0x0000/0x0000.
1046 et = &pdata->ethertypes[pdata->nb_vlan_tags];
1047 rc = efx_mae_match_spec_field_set(ctx->match_spec,
1048 fremap[EFX_MAE_FIELD_ETHER_TYPE_BE],
1050 (const uint8_t *)&et->value,
1052 (const uint8_t *)&et->mask);
1057 * sfc_mae_rule_parse_item_vlan() has already made sure
1058 * that pdata->nb_vlan_tags does not exceed this figure.
1060 RTE_BUILD_BUG_ON(SFC_MAE_MATCH_VLAN_MAX_NTAGS != 2);
1062 for (i = 0; i < pdata->nb_vlan_tags; ++i) {
1063 et = &pdata->ethertypes[i];
1065 rc = efx_mae_match_spec_field_set(ctx->match_spec,
1066 fremap[field_ids[i]],
1068 (const uint8_t *)&et->value,
1070 (const uint8_t *)&et->mask);
1079 sfc_mae_rule_process_pattern_data(struct sfc_mae_parse_ctx *ctx,
1080 struct rte_flow_error *error)
1082 const efx_mae_field_id_t *fremap = ctx->field_ids_remap;
1083 struct sfc_mae_pattern_data *pdata = &ctx->pattern_data;
1084 struct sfc_mae_ethertype *ethertypes = pdata->ethertypes;
1085 const rte_be16_t supported_tpids[] = {
1086 /* VLAN standard TPID (always the first element) */
1087 RTE_BE16(RTE_ETHER_TYPE_VLAN),
1089 /* Double-tagging TPIDs */
1090 RTE_BE16(RTE_ETHER_TYPE_QINQ),
1091 RTE_BE16(RTE_ETHER_TYPE_QINQ1),
1092 RTE_BE16(RTE_ETHER_TYPE_QINQ2),
1093 RTE_BE16(RTE_ETHER_TYPE_QINQ3),
1095 bool enforce_tag_presence[SFC_MAE_MATCH_VLAN_MAX_NTAGS] = {0};
1096 unsigned int nb_supported_tpids = RTE_DIM(supported_tpids);
1097 unsigned int ethertype_idx;
1098 const uint8_t *valuep;
1099 const uint8_t *maskp;
1102 if (pdata->innermost_ethertype_restriction.mask != 0 &&
1103 pdata->nb_vlan_tags < SFC_MAE_MATCH_VLAN_MAX_NTAGS) {
1105 * If a single item VLAN is followed by a L3 item, value
1106 * of "type" in item ETH can't be a double-tagging TPID.
1108 nb_supported_tpids = 1;
1112 * sfc_mae_rule_parse_item_vlan() has already made sure
1113 * that pdata->nb_vlan_tags does not exceed this figure.
1115 RTE_BUILD_BUG_ON(SFC_MAE_MATCH_VLAN_MAX_NTAGS != 2);
1117 for (ethertype_idx = 0;
1118 ethertype_idx < pdata->nb_vlan_tags; ++ethertype_idx) {
1119 rte_be16_t tpid_v = ethertypes[ethertype_idx].value;
1120 rte_be16_t tpid_m = ethertypes[ethertype_idx].mask;
1121 unsigned int tpid_idx;
1124 * This loop can have only two iterations. On the second one,
1125 * drop outer tag presence enforcement bit because the inner
1126 * tag presence automatically assumes that for the outer tag.
1128 enforce_tag_presence[0] = B_FALSE;
1130 if (tpid_m == RTE_BE16(0)) {
1131 if (pdata->tci_masks[ethertype_idx] == RTE_BE16(0))
1132 enforce_tag_presence[ethertype_idx] = B_TRUE;
1134 /* No match on this field, and no value check. */
1135 nb_supported_tpids = 1;
1139 /* Exact match is supported only. */
1140 if (tpid_m != RTE_BE16(0xffff)) {
1141 sfc_err(ctx->sa, "TPID mask must be 0x0 or 0xffff; got 0x%04x",
1142 rte_be_to_cpu_16(tpid_m));
1147 for (tpid_idx = pdata->nb_vlan_tags - ethertype_idx - 1;
1148 tpid_idx < nb_supported_tpids; ++tpid_idx) {
1149 if (tpid_v == supported_tpids[tpid_idx])
1153 if (tpid_idx == nb_supported_tpids) {
1154 sfc_err(ctx->sa, "TPID 0x%04x is unsupported",
1155 rte_be_to_cpu_16(tpid_v));
1160 nb_supported_tpids = 1;
1163 if (pdata->innermost_ethertype_restriction.mask == RTE_BE16(0xffff)) {
1164 struct sfc_mae_ethertype *et = ðertypes[ethertype_idx];
1165 rte_be16_t enforced_et;
1167 enforced_et = pdata->innermost_ethertype_restriction.value;
1169 if (et->mask == 0) {
1170 et->mask = RTE_BE16(0xffff);
1171 et->value = enforced_et;
1172 } else if (et->mask != RTE_BE16(0xffff) ||
1173 et->value != enforced_et) {
1174 sfc_err(ctx->sa, "L3 EtherType must be 0x0/0x0 or 0x%04x/0xffff; got 0x%04x/0x%04x",
1175 rte_be_to_cpu_16(enforced_et),
1176 rte_be_to_cpu_16(et->value),
1177 rte_be_to_cpu_16(et->mask));
1184 * Now, when the number of VLAN tags is known, set fields
1185 * ETHER_TYPE, VLAN0_PROTO and VLAN1_PROTO so that the first
1186 * one is either a valid L3 EtherType (or 0x0000/0x0000),
1187 * and the last two are valid TPIDs (or 0x0000/0x0000).
1189 rc = sfc_mae_set_ethertypes(ctx);
1193 if (pdata->l3_next_proto_restriction_mask == 0xff) {
1194 if (pdata->l3_next_proto_mask == 0) {
1195 pdata->l3_next_proto_mask = 0xff;
1196 pdata->l3_next_proto_value =
1197 pdata->l3_next_proto_restriction_value;
1198 } else if (pdata->l3_next_proto_mask != 0xff ||
1199 pdata->l3_next_proto_value !=
1200 pdata->l3_next_proto_restriction_value) {
1201 sfc_err(ctx->sa, "L3 next protocol must be 0x0/0x0 or 0x%02x/0xff; got 0x%02x/0x%02x",
1202 pdata->l3_next_proto_restriction_value,
1203 pdata->l3_next_proto_value,
1204 pdata->l3_next_proto_mask);
1210 if (enforce_tag_presence[0] || pdata->has_ovlan_mask) {
1211 rc = efx_mae_match_spec_bit_set(ctx->match_spec,
1212 fremap[EFX_MAE_FIELD_HAS_OVLAN],
1213 enforce_tag_presence[0] ||
1214 pdata->has_ovlan_value);
1219 if (enforce_tag_presence[1] || pdata->has_ivlan_mask) {
1220 rc = efx_mae_match_spec_bit_set(ctx->match_spec,
1221 fremap[EFX_MAE_FIELD_HAS_IVLAN],
1222 enforce_tag_presence[1] ||
1223 pdata->has_ivlan_value);
1228 valuep = (const uint8_t *)&pdata->l3_next_proto_value;
1229 maskp = (const uint8_t *)&pdata->l3_next_proto_mask;
1230 rc = efx_mae_match_spec_field_set(ctx->match_spec,
1231 fremap[EFX_MAE_FIELD_IP_PROTO],
1232 sizeof(pdata->l3_next_proto_value),
1234 sizeof(pdata->l3_next_proto_mask),
1242 return rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1243 "Failed to process pattern data");
1247 sfc_mae_rule_parse_item_mark(const struct rte_flow_item *item,
1248 struct sfc_flow_parse_ctx *ctx,
1249 struct rte_flow_error *error)
1251 const struct rte_flow_item_mark *spec = item->spec;
1252 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1255 return rte_flow_error_set(error, EINVAL,
1256 RTE_FLOW_ERROR_TYPE_ITEM, item,
1257 "NULL spec in item MARK");
1261 * This item is used in tunnel offload support only.
1262 * It must go before any network header items. This
1263 * way, sfc_mae_rule_preparse_item_mark() must have
1264 * already parsed it. Only one item MARK is allowed.
1266 if (ctx_mae->ft_rule_type != SFC_FT_RULE_GROUP ||
1267 spec->id != (uint32_t)SFC_FT_ID_TO_MARK(ctx_mae->ft->id)) {
1268 return rte_flow_error_set(error, EINVAL,
1269 RTE_FLOW_ERROR_TYPE_ITEM,
1270 item, "invalid item MARK");
1277 sfc_mae_rule_parse_item_port_id(const struct rte_flow_item *item,
1278 struct sfc_flow_parse_ctx *ctx,
1279 struct rte_flow_error *error)
1281 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1282 const struct rte_flow_item_port_id supp_mask = {
1285 const void *def_mask = &rte_flow_item_port_id_mask;
1286 const struct rte_flow_item_port_id *spec = NULL;
1287 const struct rte_flow_item_port_id *mask = NULL;
1288 efx_mport_sel_t mport_sel;
1291 if (ctx_mae->match_mport_set) {
1292 return rte_flow_error_set(error, ENOTSUP,
1293 RTE_FLOW_ERROR_TYPE_ITEM, item,
1294 "Can't handle multiple traffic source items");
1297 rc = sfc_flow_parse_init(item,
1298 (const void **)&spec, (const void **)&mask,
1299 (const void *)&supp_mask, def_mask,
1300 sizeof(struct rte_flow_item_port_id), error);
1304 if (mask->id != supp_mask.id) {
1305 return rte_flow_error_set(error, EINVAL,
1306 RTE_FLOW_ERROR_TYPE_ITEM, item,
1307 "Bad mask in the PORT_ID pattern item");
1310 /* If "spec" is not set, could be any port ID */
1314 if (spec->id > UINT16_MAX) {
1315 return rte_flow_error_set(error, EOVERFLOW,
1316 RTE_FLOW_ERROR_TYPE_ITEM, item,
1317 "The port ID is too large");
1320 rc = sfc_mae_switch_get_ethdev_mport(ctx_mae->sa->mae.switch_domain_id,
1321 spec->id, &mport_sel);
1323 return rte_flow_error_set(error, rc,
1324 RTE_FLOW_ERROR_TYPE_ITEM, item,
1325 "Can't get m-port for the given ethdev");
1328 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec,
1331 return rte_flow_error_set(error, rc,
1332 RTE_FLOW_ERROR_TYPE_ITEM, item,
1333 "Failed to set MPORT for the port ID");
1336 ctx_mae->match_mport_set = B_TRUE;
1342 sfc_mae_rule_parse_item_ethdev_based(const struct rte_flow_item *item,
1343 struct sfc_flow_parse_ctx *ctx,
1344 struct rte_flow_error *error)
1346 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1347 const struct rte_flow_item_ethdev supp_mask = {
1350 const void *def_mask = &rte_flow_item_ethdev_mask;
1351 const struct rte_flow_item_ethdev *spec = NULL;
1352 const struct rte_flow_item_ethdev *mask = NULL;
1353 efx_mport_sel_t mport_sel;
1356 if (ctx_mae->match_mport_set) {
1357 return rte_flow_error_set(error, ENOTSUP,
1358 RTE_FLOW_ERROR_TYPE_ITEM, item,
1359 "Can't handle multiple traffic source items");
1362 rc = sfc_flow_parse_init(item,
1363 (const void **)&spec, (const void **)&mask,
1364 (const void *)&supp_mask, def_mask,
1365 sizeof(struct rte_flow_item_ethdev), error);
1369 if (mask->port_id != supp_mask.port_id) {
1370 return rte_flow_error_set(error, EINVAL,
1371 RTE_FLOW_ERROR_TYPE_ITEM, item,
1372 "Bad mask in the ethdev-based pattern item");
1375 /* If "spec" is not set, could be any port ID */
1379 switch (item->type) {
1380 case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
1381 rc = sfc_mae_switch_get_ethdev_mport(
1382 ctx_mae->sa->mae.switch_domain_id,
1383 spec->port_id, &mport_sel);
1385 return rte_flow_error_set(error, rc,
1386 RTE_FLOW_ERROR_TYPE_ITEM, item,
1387 "Can't get m-port for the given ethdev");
1390 case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
1391 rc = sfc_mae_switch_get_entity_mport(
1392 ctx_mae->sa->mae.switch_domain_id,
1393 spec->port_id, &mport_sel);
1395 return rte_flow_error_set(error, rc,
1396 RTE_FLOW_ERROR_TYPE_ITEM, item,
1397 "Can't get m-port for the given ethdev");
1401 return rte_flow_error_set(error, EINVAL,
1402 RTE_FLOW_ERROR_TYPE_ITEM, item,
1403 "Unsupported ethdev-based flow item");
1406 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec,
1409 return rte_flow_error_set(error, rc,
1410 RTE_FLOW_ERROR_TYPE_ITEM, item,
1411 "Failed to set MPORT for the port ID");
1414 ctx_mae->match_mport_set = B_TRUE;
1420 sfc_mae_rule_parse_item_phy_port(const struct rte_flow_item *item,
1421 struct sfc_flow_parse_ctx *ctx,
1422 struct rte_flow_error *error)
1424 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1425 const struct rte_flow_item_phy_port supp_mask = {
1426 .index = 0xffffffff,
1428 const void *def_mask = &rte_flow_item_phy_port_mask;
1429 const struct rte_flow_item_phy_port *spec = NULL;
1430 const struct rte_flow_item_phy_port *mask = NULL;
1431 efx_mport_sel_t mport_v;
1434 if (ctx_mae->match_mport_set) {
1435 return rte_flow_error_set(error, ENOTSUP,
1436 RTE_FLOW_ERROR_TYPE_ITEM, item,
1437 "Can't handle multiple traffic source items");
1440 rc = sfc_flow_parse_init(item,
1441 (const void **)&spec, (const void **)&mask,
1442 (const void *)&supp_mask, def_mask,
1443 sizeof(struct rte_flow_item_phy_port), error);
1447 if (mask->index != supp_mask.index) {
1448 return rte_flow_error_set(error, EINVAL,
1449 RTE_FLOW_ERROR_TYPE_ITEM, item,
1450 "Bad mask in the PHY_PORT pattern item");
1453 /* If "spec" is not set, could be any physical port */
1457 rc = efx_mae_mport_by_phy_port(spec->index, &mport_v);
1459 return rte_flow_error_set(error, rc,
1460 RTE_FLOW_ERROR_TYPE_ITEM, item,
1461 "Failed to convert the PHY_PORT index");
1464 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec, &mport_v, NULL);
1466 return rte_flow_error_set(error, rc,
1467 RTE_FLOW_ERROR_TYPE_ITEM, item,
1468 "Failed to set MPORT for the PHY_PORT");
1471 ctx_mae->match_mport_set = B_TRUE;
1477 sfc_mae_rule_parse_item_pf(const struct rte_flow_item *item,
1478 struct sfc_flow_parse_ctx *ctx,
1479 struct rte_flow_error *error)
1481 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1482 const efx_nic_cfg_t *encp = efx_nic_cfg_get(ctx_mae->sa->nic);
1483 efx_mport_sel_t mport_v;
1486 if (ctx_mae->match_mport_set) {
1487 return rte_flow_error_set(error, ENOTSUP,
1488 RTE_FLOW_ERROR_TYPE_ITEM, item,
1489 "Can't handle multiple traffic source items");
1492 rc = efx_mae_mport_by_pcie_function(encp->enc_pf, EFX_PCI_VF_INVALID,
1495 return rte_flow_error_set(error, rc,
1496 RTE_FLOW_ERROR_TYPE_ITEM, item,
1497 "Failed to convert the PF ID");
1500 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec, &mport_v, NULL);
1502 return rte_flow_error_set(error, rc,
1503 RTE_FLOW_ERROR_TYPE_ITEM, item,
1504 "Failed to set MPORT for the PF");
1507 ctx_mae->match_mport_set = B_TRUE;
1513 sfc_mae_rule_parse_item_vf(const struct rte_flow_item *item,
1514 struct sfc_flow_parse_ctx *ctx,
1515 struct rte_flow_error *error)
1517 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1518 const efx_nic_cfg_t *encp = efx_nic_cfg_get(ctx_mae->sa->nic);
1519 const struct rte_flow_item_vf supp_mask = {
1522 const void *def_mask = &rte_flow_item_vf_mask;
1523 const struct rte_flow_item_vf *spec = NULL;
1524 const struct rte_flow_item_vf *mask = NULL;
1525 efx_mport_sel_t mport_v;
1528 if (ctx_mae->match_mport_set) {
1529 return rte_flow_error_set(error, ENOTSUP,
1530 RTE_FLOW_ERROR_TYPE_ITEM, item,
1531 "Can't handle multiple traffic source items");
1534 rc = sfc_flow_parse_init(item,
1535 (const void **)&spec, (const void **)&mask,
1536 (const void *)&supp_mask, def_mask,
1537 sizeof(struct rte_flow_item_vf), error);
1541 if (mask->id != supp_mask.id) {
1542 return rte_flow_error_set(error, EINVAL,
1543 RTE_FLOW_ERROR_TYPE_ITEM, item,
1544 "Bad mask in the VF pattern item");
1548 * If "spec" is not set, the item requests any VF related to the
1549 * PF of the current DPDK port (but not the PF itself).
1550 * Reject this match criterion as unsupported.
1553 return rte_flow_error_set(error, EINVAL,
1554 RTE_FLOW_ERROR_TYPE_ITEM, item,
1555 "Bad spec in the VF pattern item");
1558 rc = efx_mae_mport_by_pcie_function(encp->enc_pf, spec->id, &mport_v);
1560 return rte_flow_error_set(error, rc,
1561 RTE_FLOW_ERROR_TYPE_ITEM, item,
1562 "Failed to convert the PF + VF IDs");
1565 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec, &mport_v, NULL);
1567 return rte_flow_error_set(error, rc,
1568 RTE_FLOW_ERROR_TYPE_ITEM, item,
1569 "Failed to set MPORT for the PF + VF");
1572 ctx_mae->match_mport_set = B_TRUE;
1578 * Having this field ID in a field locator means that this
1579 * locator cannot be used to actually set the field at the
1580 * time when the corresponding item gets encountered. Such
1581 * fields get stashed in the parsing context instead. This
1582 * is required to resolve dependencies between the stashed
1583 * fields. See sfc_mae_rule_process_pattern_data().
1585 #define SFC_MAE_FIELD_HANDLING_DEFERRED EFX_MAE_FIELD_NIDS
1587 struct sfc_mae_field_locator {
1588 efx_mae_field_id_t field_id;
1590 /* Field offset in the corresponding rte_flow_item_ struct */
1595 sfc_mae_item_build_supp_mask(const struct sfc_mae_field_locator *field_locators,
1596 unsigned int nb_field_locators, void *mask_ptr,
1601 memset(mask_ptr, 0, mask_size);
1603 for (i = 0; i < nb_field_locators; ++i) {
1604 const struct sfc_mae_field_locator *fl = &field_locators[i];
1606 SFC_ASSERT(fl->ofst + fl->size <= mask_size);
1607 memset(RTE_PTR_ADD(mask_ptr, fl->ofst), 0xff, fl->size);
1612 sfc_mae_parse_item(const struct sfc_mae_field_locator *field_locators,
1613 unsigned int nb_field_locators, const uint8_t *spec,
1614 const uint8_t *mask, struct sfc_mae_parse_ctx *ctx,
1615 struct rte_flow_error *error)
1617 const efx_mae_field_id_t *fremap = ctx->field_ids_remap;
1621 for (i = 0; i < nb_field_locators; ++i) {
1622 const struct sfc_mae_field_locator *fl = &field_locators[i];
1624 if (fl->field_id == SFC_MAE_FIELD_HANDLING_DEFERRED)
1627 rc = efx_mae_match_spec_field_set(ctx->match_spec,
1628 fremap[fl->field_id],
1629 fl->size, spec + fl->ofst,
1630 fl->size, mask + fl->ofst);
1636 rc = rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM,
1637 NULL, "Failed to process item fields");
1643 static const struct sfc_mae_field_locator flocs_eth[] = {
1646 * This locator is used only for building supported fields mask.
1647 * The field is handled by sfc_mae_rule_process_pattern_data().
1649 SFC_MAE_FIELD_HANDLING_DEFERRED,
1650 RTE_SIZEOF_FIELD(struct rte_flow_item_eth, type),
1651 offsetof(struct rte_flow_item_eth, type),
1654 EFX_MAE_FIELD_ETH_DADDR_BE,
1655 RTE_SIZEOF_FIELD(struct rte_flow_item_eth, dst),
1656 offsetof(struct rte_flow_item_eth, dst),
1659 EFX_MAE_FIELD_ETH_SADDR_BE,
1660 RTE_SIZEOF_FIELD(struct rte_flow_item_eth, src),
1661 offsetof(struct rte_flow_item_eth, src),
1666 sfc_mae_rule_parse_item_eth(const struct rte_flow_item *item,
1667 struct sfc_flow_parse_ctx *ctx,
1668 struct rte_flow_error *error)
1670 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1671 struct rte_flow_item_eth override_mask;
1672 struct rte_flow_item_eth supp_mask;
1673 const uint8_t *spec = NULL;
1674 const uint8_t *mask = NULL;
1677 sfc_mae_item_build_supp_mask(flocs_eth, RTE_DIM(flocs_eth),
1678 &supp_mask, sizeof(supp_mask));
1679 supp_mask.has_vlan = 1;
1681 rc = sfc_flow_parse_init(item,
1682 (const void **)&spec, (const void **)&mask,
1683 (const void *)&supp_mask,
1684 &rte_flow_item_eth_mask,
1685 sizeof(struct rte_flow_item_eth), error);
1689 if (ctx_mae->ft_rule_type == SFC_FT_RULE_JUMP && mask != NULL) {
1691 * The HW/FW hasn't got support for match on MAC addresses in
1692 * outer rules yet (this will change). Match on VLAN presence
1693 * isn't supported either. Ignore these match criteria.
1695 memcpy(&override_mask, mask, sizeof(override_mask));
1696 memset(&override_mask.hdr.dst_addr, 0,
1697 sizeof(override_mask.hdr.dst_addr));
1698 memset(&override_mask.hdr.src_addr, 0,
1699 sizeof(override_mask.hdr.src_addr));
1700 override_mask.has_vlan = 0;
1702 mask = (const uint8_t *)&override_mask;
1706 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
1707 struct sfc_mae_ethertype *ethertypes = pdata->ethertypes;
1708 const struct rte_flow_item_eth *item_spec;
1709 const struct rte_flow_item_eth *item_mask;
1711 item_spec = (const struct rte_flow_item_eth *)spec;
1712 item_mask = (const struct rte_flow_item_eth *)mask;
1715 * Remember various match criteria in the parsing context.
1716 * sfc_mae_rule_process_pattern_data() will consider them
1717 * altogether when the rest of the items have been parsed.
1719 ethertypes[0].value = item_spec->type;
1720 ethertypes[0].mask = item_mask->type;
1721 if (item_mask->has_vlan) {
1722 pdata->has_ovlan_mask = B_TRUE;
1723 if (item_spec->has_vlan)
1724 pdata->has_ovlan_value = B_TRUE;
1728 * The specification is empty. The overall pattern
1729 * validity will be enforced at the end of parsing.
1730 * See sfc_mae_rule_process_pattern_data().
1735 return sfc_mae_parse_item(flocs_eth, RTE_DIM(flocs_eth), spec, mask,
1739 static const struct sfc_mae_field_locator flocs_vlan[] = {
1742 EFX_MAE_FIELD_VLAN0_TCI_BE,
1743 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, tci),
1744 offsetof(struct rte_flow_item_vlan, tci),
1748 * This locator is used only for building supported fields mask.
1749 * The field is handled by sfc_mae_rule_process_pattern_data().
1751 SFC_MAE_FIELD_HANDLING_DEFERRED,
1752 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, inner_type),
1753 offsetof(struct rte_flow_item_vlan, inner_type),
1758 EFX_MAE_FIELD_VLAN1_TCI_BE,
1759 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, tci),
1760 offsetof(struct rte_flow_item_vlan, tci),
1764 * This locator is used only for building supported fields mask.
1765 * The field is handled by sfc_mae_rule_process_pattern_data().
1767 SFC_MAE_FIELD_HANDLING_DEFERRED,
1768 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, inner_type),
1769 offsetof(struct rte_flow_item_vlan, inner_type),
1774 sfc_mae_rule_parse_item_vlan(const struct rte_flow_item *item,
1775 struct sfc_flow_parse_ctx *ctx,
1776 struct rte_flow_error *error)
1778 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1779 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
1780 boolean_t *has_vlan_mp_by_nb_tags[SFC_MAE_MATCH_VLAN_MAX_NTAGS] = {
1781 &pdata->has_ovlan_mask,
1782 &pdata->has_ivlan_mask,
1784 boolean_t *has_vlan_vp_by_nb_tags[SFC_MAE_MATCH_VLAN_MAX_NTAGS] = {
1785 &pdata->has_ovlan_value,
1786 &pdata->has_ivlan_value,
1788 boolean_t *cur_tag_presence_bit_mp;
1789 boolean_t *cur_tag_presence_bit_vp;
1790 const struct sfc_mae_field_locator *flocs;
1791 struct rte_flow_item_vlan supp_mask;
1792 const uint8_t *spec = NULL;
1793 const uint8_t *mask = NULL;
1794 unsigned int nb_flocs;
1797 RTE_BUILD_BUG_ON(SFC_MAE_MATCH_VLAN_MAX_NTAGS != 2);
1799 if (pdata->nb_vlan_tags == SFC_MAE_MATCH_VLAN_MAX_NTAGS) {
1800 return rte_flow_error_set(error, ENOTSUP,
1801 RTE_FLOW_ERROR_TYPE_ITEM, item,
1802 "Can't match that many VLAN tags");
1805 cur_tag_presence_bit_mp = has_vlan_mp_by_nb_tags[pdata->nb_vlan_tags];
1806 cur_tag_presence_bit_vp = has_vlan_vp_by_nb_tags[pdata->nb_vlan_tags];
1808 if (*cur_tag_presence_bit_mp == B_TRUE &&
1809 *cur_tag_presence_bit_vp == B_FALSE) {
1810 return rte_flow_error_set(error, EINVAL,
1811 RTE_FLOW_ERROR_TYPE_ITEM, item,
1812 "The previous item enforces no (more) VLAN, "
1813 "so the current item (VLAN) must not exist");
1816 nb_flocs = RTE_DIM(flocs_vlan) / SFC_MAE_MATCH_VLAN_MAX_NTAGS;
1817 flocs = flocs_vlan + pdata->nb_vlan_tags * nb_flocs;
1819 sfc_mae_item_build_supp_mask(flocs, nb_flocs,
1820 &supp_mask, sizeof(supp_mask));
1822 * This only means that the field is supported by the driver and libefx.
1823 * Support on NIC level will be checked when all items have been parsed.
1825 supp_mask.has_more_vlan = 1;
1827 rc = sfc_flow_parse_init(item,
1828 (const void **)&spec, (const void **)&mask,
1829 (const void *)&supp_mask,
1830 &rte_flow_item_vlan_mask,
1831 sizeof(struct rte_flow_item_vlan), error);
1836 struct sfc_mae_ethertype *et = pdata->ethertypes;
1837 const struct rte_flow_item_vlan *item_spec;
1838 const struct rte_flow_item_vlan *item_mask;
1840 item_spec = (const struct rte_flow_item_vlan *)spec;
1841 item_mask = (const struct rte_flow_item_vlan *)mask;
1844 * Remember various match criteria in the parsing context.
1845 * sfc_mae_rule_process_pattern_data() will consider them
1846 * altogether when the rest of the items have been parsed.
1848 et[pdata->nb_vlan_tags + 1].value = item_spec->inner_type;
1849 et[pdata->nb_vlan_tags + 1].mask = item_mask->inner_type;
1850 pdata->tci_masks[pdata->nb_vlan_tags] = item_mask->tci;
1851 if (item_mask->has_more_vlan) {
1852 if (pdata->nb_vlan_tags ==
1853 SFC_MAE_MATCH_VLAN_MAX_NTAGS) {
1854 return rte_flow_error_set(error, ENOTSUP,
1855 RTE_FLOW_ERROR_TYPE_ITEM, item,
1856 "Can't use 'has_more_vlan' in "
1857 "the second item VLAN");
1859 pdata->has_ivlan_mask = B_TRUE;
1860 if (item_spec->has_more_vlan)
1861 pdata->has_ivlan_value = B_TRUE;
1864 /* Convert TCI to MAE representation right now. */
1865 rc = sfc_mae_parse_item(flocs, nb_flocs, spec, mask,
1871 ++(pdata->nb_vlan_tags);
1876 static const struct sfc_mae_field_locator flocs_ipv4[] = {
1878 EFX_MAE_FIELD_SRC_IP4_BE,
1879 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.src_addr),
1880 offsetof(struct rte_flow_item_ipv4, hdr.src_addr),
1883 EFX_MAE_FIELD_DST_IP4_BE,
1884 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.dst_addr),
1885 offsetof(struct rte_flow_item_ipv4, hdr.dst_addr),
1889 * This locator is used only for building supported fields mask.
1890 * The field is handled by sfc_mae_rule_process_pattern_data().
1892 SFC_MAE_FIELD_HANDLING_DEFERRED,
1893 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.next_proto_id),
1894 offsetof(struct rte_flow_item_ipv4, hdr.next_proto_id),
1897 EFX_MAE_FIELD_IP_TOS,
1898 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4,
1899 hdr.type_of_service),
1900 offsetof(struct rte_flow_item_ipv4, hdr.type_of_service),
1903 EFX_MAE_FIELD_IP_TTL,
1904 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.time_to_live),
1905 offsetof(struct rte_flow_item_ipv4, hdr.time_to_live),
1910 sfc_mae_rule_parse_item_ipv4(const struct rte_flow_item *item,
1911 struct sfc_flow_parse_ctx *ctx,
1912 struct rte_flow_error *error)
1914 rte_be16_t ethertype_ipv4_be = RTE_BE16(RTE_ETHER_TYPE_IPV4);
1915 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1916 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
1917 struct rte_flow_item_ipv4 supp_mask;
1918 const uint8_t *spec = NULL;
1919 const uint8_t *mask = NULL;
1922 sfc_mae_item_build_supp_mask(flocs_ipv4, RTE_DIM(flocs_ipv4),
1923 &supp_mask, sizeof(supp_mask));
1925 rc = sfc_flow_parse_init(item,
1926 (const void **)&spec, (const void **)&mask,
1927 (const void *)&supp_mask,
1928 &rte_flow_item_ipv4_mask,
1929 sizeof(struct rte_flow_item_ipv4), error);
1933 pdata->innermost_ethertype_restriction.value = ethertype_ipv4_be;
1934 pdata->innermost_ethertype_restriction.mask = RTE_BE16(0xffff);
1937 const struct rte_flow_item_ipv4 *item_spec;
1938 const struct rte_flow_item_ipv4 *item_mask;
1940 item_spec = (const struct rte_flow_item_ipv4 *)spec;
1941 item_mask = (const struct rte_flow_item_ipv4 *)mask;
1943 pdata->l3_next_proto_value = item_spec->hdr.next_proto_id;
1944 pdata->l3_next_proto_mask = item_mask->hdr.next_proto_id;
1949 return sfc_mae_parse_item(flocs_ipv4, RTE_DIM(flocs_ipv4), spec, mask,
1953 static const struct sfc_mae_field_locator flocs_ipv6[] = {
1955 EFX_MAE_FIELD_SRC_IP6_BE,
1956 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.src_addr),
1957 offsetof(struct rte_flow_item_ipv6, hdr.src_addr),
1960 EFX_MAE_FIELD_DST_IP6_BE,
1961 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.dst_addr),
1962 offsetof(struct rte_flow_item_ipv6, hdr.dst_addr),
1966 * This locator is used only for building supported fields mask.
1967 * The field is handled by sfc_mae_rule_process_pattern_data().
1969 SFC_MAE_FIELD_HANDLING_DEFERRED,
1970 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.proto),
1971 offsetof(struct rte_flow_item_ipv6, hdr.proto),
1974 EFX_MAE_FIELD_IP_TTL,
1975 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.hop_limits),
1976 offsetof(struct rte_flow_item_ipv6, hdr.hop_limits),
1981 sfc_mae_rule_parse_item_ipv6(const struct rte_flow_item *item,
1982 struct sfc_flow_parse_ctx *ctx,
1983 struct rte_flow_error *error)
1985 rte_be16_t ethertype_ipv6_be = RTE_BE16(RTE_ETHER_TYPE_IPV6);
1986 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1987 const efx_mae_field_id_t *fremap = ctx_mae->field_ids_remap;
1988 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
1989 struct rte_flow_item_ipv6 supp_mask;
1990 const uint8_t *spec = NULL;
1991 const uint8_t *mask = NULL;
1992 rte_be32_t vtc_flow_be;
1998 sfc_mae_item_build_supp_mask(flocs_ipv6, RTE_DIM(flocs_ipv6),
1999 &supp_mask, sizeof(supp_mask));
2001 vtc_flow_be = RTE_BE32(RTE_IPV6_HDR_TC_MASK);
2002 memcpy(&supp_mask, &vtc_flow_be, sizeof(vtc_flow_be));
2004 rc = sfc_flow_parse_init(item,
2005 (const void **)&spec, (const void **)&mask,
2006 (const void *)&supp_mask,
2007 &rte_flow_item_ipv6_mask,
2008 sizeof(struct rte_flow_item_ipv6), error);
2012 pdata->innermost_ethertype_restriction.value = ethertype_ipv6_be;
2013 pdata->innermost_ethertype_restriction.mask = RTE_BE16(0xffff);
2016 const struct rte_flow_item_ipv6 *item_spec;
2017 const struct rte_flow_item_ipv6 *item_mask;
2019 item_spec = (const struct rte_flow_item_ipv6 *)spec;
2020 item_mask = (const struct rte_flow_item_ipv6 *)mask;
2022 pdata->l3_next_proto_value = item_spec->hdr.proto;
2023 pdata->l3_next_proto_mask = item_mask->hdr.proto;
2028 rc = sfc_mae_parse_item(flocs_ipv6, RTE_DIM(flocs_ipv6), spec, mask,
2033 memcpy(&vtc_flow_be, spec, sizeof(vtc_flow_be));
2034 vtc_flow = rte_be_to_cpu_32(vtc_flow_be);
2035 tc_value = (vtc_flow & RTE_IPV6_HDR_TC_MASK) >> RTE_IPV6_HDR_TC_SHIFT;
2037 memcpy(&vtc_flow_be, mask, sizeof(vtc_flow_be));
2038 vtc_flow = rte_be_to_cpu_32(vtc_flow_be);
2039 tc_mask = (vtc_flow & RTE_IPV6_HDR_TC_MASK) >> RTE_IPV6_HDR_TC_SHIFT;
2041 rc = efx_mae_match_spec_field_set(ctx_mae->match_spec,
2042 fremap[EFX_MAE_FIELD_IP_TOS],
2043 sizeof(tc_value), &tc_value,
2044 sizeof(tc_mask), &tc_mask);
2046 return rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM,
2047 NULL, "Failed to process item fields");
2053 static const struct sfc_mae_field_locator flocs_tcp[] = {
2055 EFX_MAE_FIELD_L4_SPORT_BE,
2056 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.src_port),
2057 offsetof(struct rte_flow_item_tcp, hdr.src_port),
2060 EFX_MAE_FIELD_L4_DPORT_BE,
2061 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.dst_port),
2062 offsetof(struct rte_flow_item_tcp, hdr.dst_port),
2065 EFX_MAE_FIELD_TCP_FLAGS_BE,
2067 * The values have been picked intentionally since the
2068 * target MAE field is oversize (16 bit). This mapping
2069 * relies on the fact that the MAE field is big-endian.
2071 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.data_off) +
2072 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.tcp_flags),
2073 offsetof(struct rte_flow_item_tcp, hdr.data_off),
2078 sfc_mae_rule_parse_item_tcp(const struct rte_flow_item *item,
2079 struct sfc_flow_parse_ctx *ctx,
2080 struct rte_flow_error *error)
2082 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
2083 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
2084 struct rte_flow_item_tcp supp_mask;
2085 const uint8_t *spec = NULL;
2086 const uint8_t *mask = NULL;
2090 * When encountered among outermost items, item TCP is invalid.
2091 * Check which match specification is being constructed now.
2093 if (ctx_mae->match_spec != ctx_mae->match_spec_action) {
2094 return rte_flow_error_set(error, EINVAL,
2095 RTE_FLOW_ERROR_TYPE_ITEM, item,
2096 "TCP in outer frame is invalid");
2099 sfc_mae_item_build_supp_mask(flocs_tcp, RTE_DIM(flocs_tcp),
2100 &supp_mask, sizeof(supp_mask));
2102 rc = sfc_flow_parse_init(item,
2103 (const void **)&spec, (const void **)&mask,
2104 (const void *)&supp_mask,
2105 &rte_flow_item_tcp_mask,
2106 sizeof(struct rte_flow_item_tcp), error);
2110 pdata->l3_next_proto_restriction_value = IPPROTO_TCP;
2111 pdata->l3_next_proto_restriction_mask = 0xff;
2116 return sfc_mae_parse_item(flocs_tcp, RTE_DIM(flocs_tcp), spec, mask,
2120 static const struct sfc_mae_field_locator flocs_udp[] = {
2122 EFX_MAE_FIELD_L4_SPORT_BE,
2123 RTE_SIZEOF_FIELD(struct rte_flow_item_udp, hdr.src_port),
2124 offsetof(struct rte_flow_item_udp, hdr.src_port),
2127 EFX_MAE_FIELD_L4_DPORT_BE,
2128 RTE_SIZEOF_FIELD(struct rte_flow_item_udp, hdr.dst_port),
2129 offsetof(struct rte_flow_item_udp, hdr.dst_port),
2134 sfc_mae_rule_parse_item_udp(const struct rte_flow_item *item,
2135 struct sfc_flow_parse_ctx *ctx,
2136 struct rte_flow_error *error)
2138 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
2139 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
2140 struct rte_flow_item_udp supp_mask;
2141 const uint8_t *spec = NULL;
2142 const uint8_t *mask = NULL;
2145 sfc_mae_item_build_supp_mask(flocs_udp, RTE_DIM(flocs_udp),
2146 &supp_mask, sizeof(supp_mask));
2148 rc = sfc_flow_parse_init(item,
2149 (const void **)&spec, (const void **)&mask,
2150 (const void *)&supp_mask,
2151 &rte_flow_item_udp_mask,
2152 sizeof(struct rte_flow_item_udp), error);
2156 pdata->l3_next_proto_restriction_value = IPPROTO_UDP;
2157 pdata->l3_next_proto_restriction_mask = 0xff;
2162 return sfc_mae_parse_item(flocs_udp, RTE_DIM(flocs_udp), spec, mask,
2166 static const struct sfc_mae_field_locator flocs_tunnel[] = {
2169 * The size and offset values are relevant
2170 * for Geneve and NVGRE, too.
2172 .size = RTE_SIZEOF_FIELD(struct rte_flow_item_vxlan, vni),
2173 .ofst = offsetof(struct rte_flow_item_vxlan, vni),
2178 * An auxiliary registry which allows using non-encap. field IDs
2179 * directly when building a match specification of type ACTION.
2181 * See sfc_mae_rule_parse_pattern() and sfc_mae_rule_parse_item_tunnel().
2183 static const efx_mae_field_id_t field_ids_no_remap[] = {
2184 #define FIELD_ID_NO_REMAP(_field) \
2185 [EFX_MAE_FIELD_##_field] = EFX_MAE_FIELD_##_field
2187 FIELD_ID_NO_REMAP(ETHER_TYPE_BE),
2188 FIELD_ID_NO_REMAP(ETH_SADDR_BE),
2189 FIELD_ID_NO_REMAP(ETH_DADDR_BE),
2190 FIELD_ID_NO_REMAP(VLAN0_TCI_BE),
2191 FIELD_ID_NO_REMAP(VLAN0_PROTO_BE),
2192 FIELD_ID_NO_REMAP(VLAN1_TCI_BE),
2193 FIELD_ID_NO_REMAP(VLAN1_PROTO_BE),
2194 FIELD_ID_NO_REMAP(SRC_IP4_BE),
2195 FIELD_ID_NO_REMAP(DST_IP4_BE),
2196 FIELD_ID_NO_REMAP(IP_PROTO),
2197 FIELD_ID_NO_REMAP(IP_TOS),
2198 FIELD_ID_NO_REMAP(IP_TTL),
2199 FIELD_ID_NO_REMAP(SRC_IP6_BE),
2200 FIELD_ID_NO_REMAP(DST_IP6_BE),
2201 FIELD_ID_NO_REMAP(L4_SPORT_BE),
2202 FIELD_ID_NO_REMAP(L4_DPORT_BE),
2203 FIELD_ID_NO_REMAP(TCP_FLAGS_BE),
2204 FIELD_ID_NO_REMAP(HAS_OVLAN),
2205 FIELD_ID_NO_REMAP(HAS_IVLAN),
2207 #undef FIELD_ID_NO_REMAP
2211 * An auxiliary registry which allows using "ENC" field IDs
2212 * when building a match specification of type OUTER.
2214 * See sfc_mae_rule_encap_parse_init().
2216 static const efx_mae_field_id_t field_ids_remap_to_encap[] = {
2217 #define FIELD_ID_REMAP_TO_ENCAP(_field) \
2218 [EFX_MAE_FIELD_##_field] = EFX_MAE_FIELD_ENC_##_field
2220 FIELD_ID_REMAP_TO_ENCAP(ETHER_TYPE_BE),
2221 FIELD_ID_REMAP_TO_ENCAP(ETH_SADDR_BE),
2222 FIELD_ID_REMAP_TO_ENCAP(ETH_DADDR_BE),
2223 FIELD_ID_REMAP_TO_ENCAP(VLAN0_TCI_BE),
2224 FIELD_ID_REMAP_TO_ENCAP(VLAN0_PROTO_BE),
2225 FIELD_ID_REMAP_TO_ENCAP(VLAN1_TCI_BE),
2226 FIELD_ID_REMAP_TO_ENCAP(VLAN1_PROTO_BE),
2227 FIELD_ID_REMAP_TO_ENCAP(SRC_IP4_BE),
2228 FIELD_ID_REMAP_TO_ENCAP(DST_IP4_BE),
2229 FIELD_ID_REMAP_TO_ENCAP(IP_PROTO),
2230 FIELD_ID_REMAP_TO_ENCAP(IP_TOS),
2231 FIELD_ID_REMAP_TO_ENCAP(IP_TTL),
2232 FIELD_ID_REMAP_TO_ENCAP(SRC_IP6_BE),
2233 FIELD_ID_REMAP_TO_ENCAP(DST_IP6_BE),
2234 FIELD_ID_REMAP_TO_ENCAP(L4_SPORT_BE),
2235 FIELD_ID_REMAP_TO_ENCAP(L4_DPORT_BE),
2236 FIELD_ID_REMAP_TO_ENCAP(HAS_OVLAN),
2237 FIELD_ID_REMAP_TO_ENCAP(HAS_IVLAN),
2239 #undef FIELD_ID_REMAP_TO_ENCAP
2243 sfc_mae_rule_parse_item_tunnel(const struct rte_flow_item *item,
2244 struct sfc_flow_parse_ctx *ctx,
2245 struct rte_flow_error *error)
2247 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
2248 uint8_t vnet_id_v[sizeof(uint32_t)] = {0};
2249 uint8_t vnet_id_m[sizeof(uint32_t)] = {0};
2250 const struct rte_flow_item_vxlan *vxp;
2251 uint8_t supp_mask[sizeof(uint64_t)];
2252 const uint8_t *spec = NULL;
2253 const uint8_t *mask = NULL;
2256 if (ctx_mae->ft_rule_type == SFC_FT_RULE_GROUP) {
2258 * As a workaround, pattern processing has started from
2259 * this (tunnel) item. No pattern data to process yet.
2263 * We're about to start processing inner frame items.
2264 * Process pattern data that has been deferred so far
2265 * and reset pattern data storage.
2267 rc = sfc_mae_rule_process_pattern_data(ctx_mae, error);
2272 memset(&ctx_mae->pattern_data, 0, sizeof(ctx_mae->pattern_data));
2274 sfc_mae_item_build_supp_mask(flocs_tunnel, RTE_DIM(flocs_tunnel),
2275 &supp_mask, sizeof(supp_mask));
2278 * This tunnel item was preliminarily detected by
2279 * sfc_mae_rule_encap_parse_init(). Default mask
2280 * was also picked by that helper. Use it here.
2282 rc = sfc_flow_parse_init(item,
2283 (const void **)&spec, (const void **)&mask,
2284 (const void *)&supp_mask,
2285 ctx_mae->tunnel_def_mask,
2286 ctx_mae->tunnel_def_mask_size, error);
2291 * This item and later ones comprise a
2292 * match specification of type ACTION.
2294 ctx_mae->match_spec = ctx_mae->match_spec_action;
2296 /* This item and later ones use non-encap. EFX MAE field IDs. */
2297 ctx_mae->field_ids_remap = field_ids_no_remap;
2303 * Field EFX_MAE_FIELD_ENC_VNET_ID_BE is a 32-bit one.
2304 * Copy 24-bit VNI, which is BE, at offset 1 in it.
2305 * The extra byte is 0 both in the mask and in the value.
2307 vxp = (const struct rte_flow_item_vxlan *)spec;
2308 memcpy(vnet_id_v + 1, &vxp->vni, sizeof(vxp->vni));
2310 vxp = (const struct rte_flow_item_vxlan *)mask;
2311 memcpy(vnet_id_m + 1, &vxp->vni, sizeof(vxp->vni));
2313 rc = efx_mae_match_spec_field_set(ctx_mae->match_spec,
2314 EFX_MAE_FIELD_ENC_VNET_ID_BE,
2315 sizeof(vnet_id_v), vnet_id_v,
2316 sizeof(vnet_id_m), vnet_id_m);
2318 rc = rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM,
2319 item, "Failed to set VXLAN VNI");
2325 static const struct sfc_flow_item sfc_flow_items[] = {
2327 .type = RTE_FLOW_ITEM_TYPE_MARK,
2329 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2330 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2331 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2332 .parse = sfc_mae_rule_parse_item_mark,
2335 .type = RTE_FLOW_ITEM_TYPE_PORT_ID,
2338 * In terms of RTE flow, this item is a META one,
2339 * and its position in the pattern is don't care.
2341 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2342 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2343 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2344 .parse = sfc_mae_rule_parse_item_port_id,
2347 .type = RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR,
2348 .name = "PORT_REPRESENTOR",
2350 * In terms of RTE flow, this item is a META one,
2351 * and its position in the pattern is don't care.
2353 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2354 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2355 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2356 .parse = sfc_mae_rule_parse_item_ethdev_based,
2359 .type = RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT,
2360 .name = "REPRESENTED_PORT",
2362 * In terms of RTE flow, this item is a META one,
2363 * and its position in the pattern is don't care.
2365 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2366 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2367 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2368 .parse = sfc_mae_rule_parse_item_ethdev_based,
2371 .type = RTE_FLOW_ITEM_TYPE_PHY_PORT,
2374 * In terms of RTE flow, this item is a META one,
2375 * and its position in the pattern is don't care.
2377 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2378 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2379 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2380 .parse = sfc_mae_rule_parse_item_phy_port,
2383 .type = RTE_FLOW_ITEM_TYPE_PF,
2386 * In terms of RTE flow, this item is a META one,
2387 * and its position in the pattern is don't care.
2389 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2390 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2391 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2392 .parse = sfc_mae_rule_parse_item_pf,
2395 .type = RTE_FLOW_ITEM_TYPE_VF,
2398 * In terms of RTE flow, this item is a META one,
2399 * and its position in the pattern is don't care.
2401 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2402 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2403 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2404 .parse = sfc_mae_rule_parse_item_vf,
2407 .type = RTE_FLOW_ITEM_TYPE_ETH,
2409 .prev_layer = SFC_FLOW_ITEM_START_LAYER,
2410 .layer = SFC_FLOW_ITEM_L2,
2411 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2412 .parse = sfc_mae_rule_parse_item_eth,
2415 .type = RTE_FLOW_ITEM_TYPE_VLAN,
2417 .prev_layer = SFC_FLOW_ITEM_L2,
2418 .layer = SFC_FLOW_ITEM_L2,
2419 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2420 .parse = sfc_mae_rule_parse_item_vlan,
2423 .type = RTE_FLOW_ITEM_TYPE_IPV4,
2425 .prev_layer = SFC_FLOW_ITEM_L2,
2426 .layer = SFC_FLOW_ITEM_L3,
2427 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2428 .parse = sfc_mae_rule_parse_item_ipv4,
2431 .type = RTE_FLOW_ITEM_TYPE_IPV6,
2433 .prev_layer = SFC_FLOW_ITEM_L2,
2434 .layer = SFC_FLOW_ITEM_L3,
2435 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2436 .parse = sfc_mae_rule_parse_item_ipv6,
2439 .type = RTE_FLOW_ITEM_TYPE_TCP,
2441 .prev_layer = SFC_FLOW_ITEM_L3,
2442 .layer = SFC_FLOW_ITEM_L4,
2443 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2444 .parse = sfc_mae_rule_parse_item_tcp,
2447 .type = RTE_FLOW_ITEM_TYPE_UDP,
2449 .prev_layer = SFC_FLOW_ITEM_L3,
2450 .layer = SFC_FLOW_ITEM_L4,
2451 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2452 .parse = sfc_mae_rule_parse_item_udp,
2455 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
2457 .prev_layer = SFC_FLOW_ITEM_L4,
2458 .layer = SFC_FLOW_ITEM_START_LAYER,
2459 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2460 .parse = sfc_mae_rule_parse_item_tunnel,
2463 .type = RTE_FLOW_ITEM_TYPE_GENEVE,
2465 .prev_layer = SFC_FLOW_ITEM_L4,
2466 .layer = SFC_FLOW_ITEM_START_LAYER,
2467 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2468 .parse = sfc_mae_rule_parse_item_tunnel,
2471 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
2473 .prev_layer = SFC_FLOW_ITEM_L3,
2474 .layer = SFC_FLOW_ITEM_START_LAYER,
2475 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2476 .parse = sfc_mae_rule_parse_item_tunnel,
2481 sfc_mae_rule_process_outer(struct sfc_adapter *sa,
2482 struct sfc_mae_parse_ctx *ctx,
2483 struct sfc_mae_outer_rule **rulep,
2484 struct rte_flow_error *error)
2486 efx_mae_rule_id_t invalid_rule_id = { .id = EFX_MAE_RSRC_ID_INVALID };
2489 if (ctx->encap_type == EFX_TUNNEL_PROTOCOL_NONE) {
2494 SFC_ASSERT(ctx->match_spec_outer != NULL);
2496 if (!efx_mae_match_spec_is_valid(sa->nic, ctx->match_spec_outer)) {
2497 return rte_flow_error_set(error, ENOTSUP,
2498 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2499 "Inconsistent pattern (outer)");
2502 *rulep = sfc_mae_outer_rule_attach(sa, ctx->match_spec_outer,
2504 if (*rulep != NULL) {
2505 efx_mae_match_spec_fini(sa->nic, ctx->match_spec_outer);
2507 rc = sfc_mae_outer_rule_add(sa, ctx->match_spec_outer,
2508 ctx->encap_type, rulep);
2510 return rte_flow_error_set(error, rc,
2511 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2512 "Failed to process the pattern");
2516 /* The spec has now been tracked by the outer rule entry. */
2517 ctx->match_spec_outer = NULL;
2520 switch (ctx->ft_rule_type) {
2521 case SFC_FT_RULE_NONE:
2523 case SFC_FT_RULE_JUMP:
2524 /* No action rule */
2526 case SFC_FT_RULE_GROUP:
2528 * Match on recirculation ID rather than
2529 * on the outer rule allocation handle.
2531 rc = efx_mae_match_spec_recirc_id_set(ctx->match_spec_action,
2532 SFC_FT_ID_TO_TUNNEL_MARK(ctx->ft->id));
2534 return rte_flow_error_set(error, rc,
2535 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2536 "tunnel offload: GROUP: AR: failed to request match on RECIRC_ID");
2540 SFC_ASSERT(B_FALSE);
2544 * In MAE, lookup sequence comprises outer parse, outer rule lookup,
2545 * inner parse (when some outer rule is hit) and action rule lookup.
2546 * If the currently processed flow does not come with an outer rule,
2547 * its action rule must be available only for packets which miss in
2548 * outer rule table. Set OR_ID match field to 0xffffffff/0xffffffff
2549 * in the action rule specification; this ensures correct behaviour.
2551 * If, on the other hand, this flow does have an outer rule, its ID
2552 * may be unknown at the moment (not yet allocated), but OR_ID mask
2553 * has to be set to 0xffffffff anyway for correct class comparisons.
2554 * When the outer rule has been allocated, this match field will be
2555 * overridden by sfc_mae_outer_rule_enable() to use the right value.
2557 rc = efx_mae_match_spec_outer_rule_id_set(ctx->match_spec_action,
2561 sfc_mae_outer_rule_del(sa, *rulep);
2565 return rte_flow_error_set(error, rc,
2566 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2567 "Failed to process the pattern");
2574 sfc_mae_rule_preparse_item_mark(const struct rte_flow_item_mark *spec,
2575 struct sfc_mae_parse_ctx *ctx)
2577 struct sfc_flow_tunnel *ft;
2581 sfc_err(ctx->sa, "tunnel offload: GROUP: NULL spec in item MARK");
2585 ft = sfc_flow_tunnel_pick(ctx->sa, spec->id);
2587 sfc_err(ctx->sa, "tunnel offload: GROUP: invalid tunnel");
2591 if (ft->refcnt == 0) {
2592 sfc_err(ctx->sa, "tunnel offload: GROUP: tunnel=%u does not exist",
2597 user_mark = SFC_FT_GET_USER_MARK(spec->id);
2598 if (user_mark != 0) {
2599 sfc_err(ctx->sa, "tunnel offload: GROUP: invalid item MARK");
2603 sfc_dbg(ctx->sa, "tunnel offload: GROUP: detected");
2605 ctx->ft_rule_type = SFC_FT_RULE_GROUP;
2612 sfc_mae_rule_encap_parse_init(struct sfc_adapter *sa,
2613 struct sfc_mae_parse_ctx *ctx,
2614 struct rte_flow_error *error)
2616 const struct rte_flow_item *pattern = ctx->pattern;
2617 struct sfc_mae *mae = &sa->mae;
2618 uint8_t recirc_id = 0;
2621 if (pattern == NULL) {
2622 rte_flow_error_set(error, EINVAL,
2623 RTE_FLOW_ERROR_TYPE_ITEM_NUM, NULL,
2629 switch (pattern->type) {
2630 case RTE_FLOW_ITEM_TYPE_MARK:
2631 rc = sfc_mae_rule_preparse_item_mark(pattern->spec,
2634 return rte_flow_error_set(error, rc,
2635 RTE_FLOW_ERROR_TYPE_ITEM,
2636 pattern, "tunnel offload: GROUP: invalid item MARK");
2640 case RTE_FLOW_ITEM_TYPE_VXLAN:
2641 ctx->encap_type = EFX_TUNNEL_PROTOCOL_VXLAN;
2642 ctx->tunnel_def_mask = &rte_flow_item_vxlan_mask;
2643 ctx->tunnel_def_mask_size =
2644 sizeof(rte_flow_item_vxlan_mask);
2646 case RTE_FLOW_ITEM_TYPE_GENEVE:
2647 ctx->encap_type = EFX_TUNNEL_PROTOCOL_GENEVE;
2648 ctx->tunnel_def_mask = &rte_flow_item_geneve_mask;
2649 ctx->tunnel_def_mask_size =
2650 sizeof(rte_flow_item_geneve_mask);
2652 case RTE_FLOW_ITEM_TYPE_NVGRE:
2653 ctx->encap_type = EFX_TUNNEL_PROTOCOL_NVGRE;
2654 ctx->tunnel_def_mask = &rte_flow_item_nvgre_mask;
2655 ctx->tunnel_def_mask_size =
2656 sizeof(rte_flow_item_nvgre_mask);
2658 case RTE_FLOW_ITEM_TYPE_END:
2668 switch (ctx->ft_rule_type) {
2669 case SFC_FT_RULE_NONE:
2670 if (pattern->type == RTE_FLOW_ITEM_TYPE_END)
2673 case SFC_FT_RULE_JUMP:
2674 if (pattern->type != RTE_FLOW_ITEM_TYPE_END) {
2675 return rte_flow_error_set(error, ENOTSUP,
2676 RTE_FLOW_ERROR_TYPE_ITEM,
2677 pattern, "tunnel offload: JUMP: invalid item");
2679 ctx->encap_type = ctx->ft->encap_type;
2681 case SFC_FT_RULE_GROUP:
2682 if (pattern->type == RTE_FLOW_ITEM_TYPE_END) {
2683 return rte_flow_error_set(error, EINVAL,
2684 RTE_FLOW_ERROR_TYPE_ITEM,
2685 NULL, "tunnel offload: GROUP: missing tunnel item");
2686 } else if (ctx->encap_type != ctx->ft->encap_type) {
2687 return rte_flow_error_set(error, EINVAL,
2688 RTE_FLOW_ERROR_TYPE_ITEM,
2689 pattern, "tunnel offload: GROUP: tunnel type mismatch");
2693 * The HW/FW hasn't got support for the use of "ENC" fields in
2694 * action rules (except the VNET_ID one) yet. As a workaround,
2695 * start parsing the pattern from the tunnel item.
2697 ctx->pattern = pattern;
2700 SFC_ASSERT(B_FALSE);
2704 if ((mae->encap_types_supported & (1U << ctx->encap_type)) == 0) {
2705 return rte_flow_error_set(error, ENOTSUP,
2706 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2707 "OR: unsupported tunnel type");
2710 switch (ctx->ft_rule_type) {
2711 case SFC_FT_RULE_JUMP:
2712 recirc_id = SFC_FT_ID_TO_TUNNEL_MARK(ctx->ft->id);
2714 case SFC_FT_RULE_NONE:
2715 if (ctx->priority >= mae->nb_outer_rule_prios_max) {
2716 return rte_flow_error_set(error, ENOTSUP,
2717 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
2718 NULL, "OR: unsupported priority level");
2721 rc = efx_mae_match_spec_init(sa->nic,
2722 EFX_MAE_RULE_OUTER, ctx->priority,
2723 &ctx->match_spec_outer);
2725 return rte_flow_error_set(error, rc,
2726 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2727 "OR: failed to initialise the match specification");
2731 * Outermost items comprise a match
2732 * specification of type OUTER.
2734 ctx->match_spec = ctx->match_spec_outer;
2736 /* Outermost items use "ENC" EFX MAE field IDs. */
2737 ctx->field_ids_remap = field_ids_remap_to_encap;
2739 rc = efx_mae_outer_rule_recirc_id_set(ctx->match_spec,
2742 return rte_flow_error_set(error, rc,
2743 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2744 "OR: failed to initialise RECIRC_ID");
2747 case SFC_FT_RULE_GROUP:
2748 /* Outermost items -> "ENC" match fields in the action rule. */
2749 ctx->field_ids_remap = field_ids_remap_to_encap;
2750 ctx->match_spec = ctx->match_spec_action;
2752 /* No own outer rule; match on JUMP OR's RECIRC_ID is used. */
2753 ctx->encap_type = EFX_TUNNEL_PROTOCOL_NONE;
2756 SFC_ASSERT(B_FALSE);
2764 sfc_mae_rule_encap_parse_fini(struct sfc_adapter *sa,
2765 struct sfc_mae_parse_ctx *ctx)
2767 if (ctx->encap_type == EFX_TUNNEL_PROTOCOL_NONE)
2770 if (ctx->match_spec_outer != NULL)
2771 efx_mae_match_spec_fini(sa->nic, ctx->match_spec_outer);
2775 sfc_mae_rule_parse_pattern(struct sfc_adapter *sa,
2776 const struct rte_flow_item pattern[],
2777 struct sfc_flow_spec_mae *spec,
2778 struct rte_flow_error *error)
2780 struct sfc_mae_parse_ctx ctx_mae;
2781 unsigned int priority_shift = 0;
2782 struct sfc_flow_parse_ctx ctx;
2785 memset(&ctx_mae, 0, sizeof(ctx_mae));
2786 ctx_mae.ft_rule_type = spec->ft_rule_type;
2787 ctx_mae.priority = spec->priority;
2788 ctx_mae.ft = spec->ft;
2791 switch (ctx_mae.ft_rule_type) {
2792 case SFC_FT_RULE_JUMP:
2794 * By design, this flow should be represented solely by the
2795 * outer rule. But the HW/FW hasn't got support for setting
2796 * Rx mark from RECIRC_ID on outer rule lookup yet. Neither
2797 * does it support outer rule counters. As a workaround, an
2798 * action rule of lower priority is used to do the job.
2803 case SFC_FT_RULE_GROUP:
2804 if (ctx_mae.priority != 0) {
2806 * Because of the above workaround, deny the
2807 * use of priorities to JUMP and GROUP rules.
2809 rc = rte_flow_error_set(error, ENOTSUP,
2810 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, NULL,
2811 "tunnel offload: priorities are not supported");
2812 goto fail_priority_check;
2816 case SFC_FT_RULE_NONE:
2817 rc = efx_mae_match_spec_init(sa->nic, EFX_MAE_RULE_ACTION,
2818 spec->priority + priority_shift,
2819 &ctx_mae.match_spec_action);
2821 rc = rte_flow_error_set(error, rc,
2822 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2823 "AR: failed to initialise the match specification");
2824 goto fail_init_match_spec_action;
2828 SFC_ASSERT(B_FALSE);
2833 * As a preliminary setting, assume that there is no encapsulation
2834 * in the pattern. That is, pattern items are about to comprise a
2835 * match specification of type ACTION and use non-encap. field IDs.
2837 * sfc_mae_rule_encap_parse_init() below may override this.
2839 ctx_mae.encap_type = EFX_TUNNEL_PROTOCOL_NONE;
2840 ctx_mae.match_spec = ctx_mae.match_spec_action;
2841 ctx_mae.field_ids_remap = field_ids_no_remap;
2842 ctx_mae.pattern = pattern;
2844 ctx.type = SFC_FLOW_PARSE_CTX_MAE;
2847 rc = sfc_mae_rule_encap_parse_init(sa, &ctx_mae, error);
2849 goto fail_encap_parse_init;
2852 * sfc_mae_rule_encap_parse_init() may have detected tunnel offload
2853 * GROUP rule. Remember its properties for later use.
2855 spec->ft_rule_type = ctx_mae.ft_rule_type;
2856 spec->ft = ctx_mae.ft;
2858 rc = sfc_flow_parse_pattern(sa, sfc_flow_items, RTE_DIM(sfc_flow_items),
2859 ctx_mae.pattern, &ctx, error);
2861 goto fail_parse_pattern;
2863 rc = sfc_mae_rule_process_pattern_data(&ctx_mae, error);
2865 goto fail_process_pattern_data;
2867 rc = sfc_mae_rule_process_outer(sa, &ctx_mae, &spec->outer_rule, error);
2869 goto fail_process_outer;
2871 if (ctx_mae.match_spec_action != NULL &&
2872 !efx_mae_match_spec_is_valid(sa->nic, ctx_mae.match_spec_action)) {
2873 rc = rte_flow_error_set(error, ENOTSUP,
2874 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2875 "Inconsistent pattern");
2876 goto fail_validate_match_spec_action;
2879 spec->match_spec = ctx_mae.match_spec_action;
2883 fail_validate_match_spec_action:
2885 fail_process_pattern_data:
2887 sfc_mae_rule_encap_parse_fini(sa, &ctx_mae);
2889 fail_encap_parse_init:
2890 if (ctx_mae.match_spec_action != NULL)
2891 efx_mae_match_spec_fini(sa->nic, ctx_mae.match_spec_action);
2893 fail_init_match_spec_action:
2894 fail_priority_check:
2899 * An action supported by MAE may correspond to a bundle of RTE flow actions,
2900 * in example, VLAN_PUSH = OF_PUSH_VLAN + OF_VLAN_SET_VID + OF_VLAN_SET_PCP.
2901 * That is, related RTE flow actions need to be tracked as parts of a whole
2902 * so that they can be combined into a single action and submitted to MAE
2903 * representation of a given rule's action set.
2905 * Each RTE flow action provided by an application gets classified as
2906 * one belonging to some bundle type. If an action is not supposed to
2907 * belong to any bundle, or if this action is END, it is described as
2908 * one belonging to a dummy bundle of type EMPTY.
2910 * A currently tracked bundle will be submitted if a repeating
2911 * action or an action of different bundle type follows.
2914 enum sfc_mae_actions_bundle_type {
2915 SFC_MAE_ACTIONS_BUNDLE_EMPTY = 0,
2916 SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH,
2919 struct sfc_mae_actions_bundle {
2920 enum sfc_mae_actions_bundle_type type;
2922 /* Indicates actions already tracked by the current bundle */
2923 uint64_t actions_mask;
2925 /* Parameters used by SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH */
2926 rte_be16_t vlan_push_tpid;
2927 rte_be16_t vlan_push_tci;
2931 * Combine configuration of RTE flow actions tracked by the bundle into a
2932 * single action and submit the result to MAE action set specification.
2933 * Do nothing in the case of dummy action bundle.
2936 sfc_mae_actions_bundle_submit(const struct sfc_mae_actions_bundle *bundle,
2937 efx_mae_actions_t *spec)
2941 switch (bundle->type) {
2942 case SFC_MAE_ACTIONS_BUNDLE_EMPTY:
2944 case SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH:
2945 rc = efx_mae_action_set_populate_vlan_push(
2946 spec, bundle->vlan_push_tpid, bundle->vlan_push_tci);
2949 SFC_ASSERT(B_FALSE);
2957 * Given the type of the next RTE flow action in the line, decide
2958 * whether a new bundle is about to start, and, if this is the case,
2959 * submit and reset the current bundle.
2962 sfc_mae_actions_bundle_sync(const struct rte_flow_action *action,
2963 struct sfc_mae_actions_bundle *bundle,
2964 efx_mae_actions_t *spec,
2965 struct rte_flow_error *error)
2967 enum sfc_mae_actions_bundle_type bundle_type_new;
2970 switch (action->type) {
2971 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
2972 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
2973 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
2974 bundle_type_new = SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH;
2978 * Self-sufficient actions, including END, are handled in this
2979 * case. No checks for unsupported actions are needed here
2980 * because parsing doesn't occur at this point.
2982 bundle_type_new = SFC_MAE_ACTIONS_BUNDLE_EMPTY;
2986 if (bundle_type_new != bundle->type ||
2987 (bundle->actions_mask & (1ULL << action->type)) != 0) {
2988 rc = sfc_mae_actions_bundle_submit(bundle, spec);
2992 memset(bundle, 0, sizeof(*bundle));
2995 bundle->type = bundle_type_new;
3000 return rte_flow_error_set(error, rc,
3001 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3002 "Failed to request the (group of) action(s)");
3006 sfc_mae_rule_parse_action_of_push_vlan(
3007 const struct rte_flow_action_of_push_vlan *conf,
3008 struct sfc_mae_actions_bundle *bundle)
3010 bundle->vlan_push_tpid = conf->ethertype;
3014 sfc_mae_rule_parse_action_of_set_vlan_vid(
3015 const struct rte_flow_action_of_set_vlan_vid *conf,
3016 struct sfc_mae_actions_bundle *bundle)
3018 bundle->vlan_push_tci |= (conf->vlan_vid &
3019 rte_cpu_to_be_16(RTE_LEN2MASK(12, uint16_t)));
3023 sfc_mae_rule_parse_action_of_set_vlan_pcp(
3024 const struct rte_flow_action_of_set_vlan_pcp *conf,
3025 struct sfc_mae_actions_bundle *bundle)
3027 uint16_t vlan_tci_pcp = (uint16_t)(conf->vlan_pcp &
3028 RTE_LEN2MASK(3, uint8_t)) << 13;
3030 bundle->vlan_push_tci |= rte_cpu_to_be_16(vlan_tci_pcp);
3033 struct sfc_mae_parsed_item {
3034 const struct rte_flow_item *item;
3035 size_t proto_header_ofst;
3036 size_t proto_header_size;
3040 * For each 16-bit word of the given header, override
3041 * bits enforced by the corresponding 16-bit mask.
3044 sfc_mae_header_force_item_masks(uint8_t *header_buf,
3045 const struct sfc_mae_parsed_item *parsed_items,
3046 unsigned int nb_parsed_items)
3048 unsigned int item_idx;
3050 for (item_idx = 0; item_idx < nb_parsed_items; ++item_idx) {
3051 const struct sfc_mae_parsed_item *parsed_item;
3052 const struct rte_flow_item *item;
3053 size_t proto_header_size;
3056 parsed_item = &parsed_items[item_idx];
3057 proto_header_size = parsed_item->proto_header_size;
3058 item = parsed_item->item;
3060 for (ofst = 0; ofst < proto_header_size;
3061 ofst += sizeof(rte_be16_t)) {
3062 rte_be16_t *wp = RTE_PTR_ADD(header_buf, ofst);
3063 const rte_be16_t *w_maskp;
3064 const rte_be16_t *w_specp;
3066 w_maskp = RTE_PTR_ADD(item->mask, ofst);
3067 w_specp = RTE_PTR_ADD(item->spec, ofst);
3070 *wp |= (*w_specp & *w_maskp);
3073 header_buf += proto_header_size;
3077 #define SFC_IPV4_TTL_DEF 0x40
3078 #define SFC_IPV6_VTC_FLOW_DEF 0x60000000
3079 #define SFC_IPV6_HOP_LIMITS_DEF 0xff
3080 #define SFC_VXLAN_FLAGS_DEF 0x08000000
3083 sfc_mae_rule_parse_action_vxlan_encap(
3084 struct sfc_mae *mae,
3085 const struct rte_flow_action_vxlan_encap *conf,
3086 efx_mae_actions_t *spec,
3087 struct rte_flow_error *error)
3089 struct sfc_mae_bounce_eh *bounce_eh = &mae->bounce_eh;
3090 struct rte_flow_item *pattern = conf->definition;
3091 uint8_t *buf = bounce_eh->buf;
3093 /* This array will keep track of non-VOID pattern items. */
3094 struct sfc_mae_parsed_item parsed_items[1 /* Ethernet */ +
3096 1 /* IPv4 or IPv6 */ +
3099 unsigned int nb_parsed_items = 0;
3101 size_t eth_ethertype_ofst = offsetof(struct rte_ether_hdr, ether_type);
3102 uint8_t dummy_buf[RTE_MAX(sizeof(struct rte_ipv4_hdr),
3103 sizeof(struct rte_ipv6_hdr))];
3104 struct rte_ipv4_hdr *ipv4 = (void *)dummy_buf;
3105 struct rte_ipv6_hdr *ipv6 = (void *)dummy_buf;
3106 struct rte_vxlan_hdr *vxlan = NULL;
3107 struct rte_udp_hdr *udp = NULL;
3108 unsigned int nb_vlan_tags = 0;
3109 size_t next_proto_ofst = 0;
3110 size_t ethertype_ofst = 0;
3114 if (pattern == NULL) {
3115 return rte_flow_error_set(error, EINVAL,
3116 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3117 "The encap. header definition is NULL");
3120 bounce_eh->type = EFX_TUNNEL_PROTOCOL_VXLAN;
3121 bounce_eh->size = 0;
3124 * Process pattern items and remember non-VOID ones.
3125 * Defer applying masks until after the complete header
3126 * has been built from the pattern items.
3128 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_ETH);
3130 for (; pattern->type != RTE_FLOW_ITEM_TYPE_END; ++pattern) {
3131 struct sfc_mae_parsed_item *parsed_item;
3132 const uint64_t exp_items_extra_vlan[] = {
3133 RTE_BIT64(RTE_FLOW_ITEM_TYPE_VLAN), 0
3135 size_t proto_header_size;
3136 rte_be16_t *ethertypep;
3137 uint8_t *next_protop;
3140 if (pattern->spec == NULL) {
3141 return rte_flow_error_set(error, EINVAL,
3142 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3143 "NULL item spec in the encap. header");
3146 if (pattern->mask == NULL) {
3147 return rte_flow_error_set(error, EINVAL,
3148 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3149 "NULL item mask in the encap. header");
3152 if (pattern->last != NULL) {
3153 /* This is not a match pattern, so disallow range. */
3154 return rte_flow_error_set(error, EINVAL,
3155 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3156 "Range item in the encap. header");
3159 if (pattern->type == RTE_FLOW_ITEM_TYPE_VOID) {
3160 /* Handle VOID separately, for clarity. */
3164 if ((exp_items & RTE_BIT64(pattern->type)) == 0) {
3165 return rte_flow_error_set(error, ENOTSUP,
3166 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3167 "Unexpected item in the encap. header");
3170 parsed_item = &parsed_items[nb_parsed_items];
3171 buf_cur = buf + bounce_eh->size;
3173 switch (pattern->type) {
3174 case RTE_FLOW_ITEM_TYPE_ETH:
3175 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_ETH,
3177 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_eth,
3180 proto_header_size = sizeof(struct rte_ether_hdr);
3182 ethertype_ofst = eth_ethertype_ofst;
3184 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_VLAN) |
3185 RTE_BIT64(RTE_FLOW_ITEM_TYPE_IPV4) |
3186 RTE_BIT64(RTE_FLOW_ITEM_TYPE_IPV6);
3188 case RTE_FLOW_ITEM_TYPE_VLAN:
3189 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_VLAN,
3191 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_vlan,
3194 proto_header_size = sizeof(struct rte_vlan_hdr);
3196 ethertypep = RTE_PTR_ADD(buf, eth_ethertype_ofst);
3197 *ethertypep = RTE_BE16(RTE_ETHER_TYPE_QINQ);
3199 ethertypep = RTE_PTR_ADD(buf, ethertype_ofst);
3200 *ethertypep = RTE_BE16(RTE_ETHER_TYPE_VLAN);
3204 offsetof(struct rte_vlan_hdr, eth_proto);
3206 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_IPV4) |
3207 RTE_BIT64(RTE_FLOW_ITEM_TYPE_IPV6);
3208 exp_items |= exp_items_extra_vlan[nb_vlan_tags];
3212 case RTE_FLOW_ITEM_TYPE_IPV4:
3213 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_IPV4,
3215 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_ipv4,
3218 proto_header_size = sizeof(struct rte_ipv4_hdr);
3220 ethertypep = RTE_PTR_ADD(buf, ethertype_ofst);
3221 *ethertypep = RTE_BE16(RTE_ETHER_TYPE_IPV4);
3225 offsetof(struct rte_ipv4_hdr, next_proto_id);
3227 ipv4 = (struct rte_ipv4_hdr *)buf_cur;
3229 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_UDP);
3231 case RTE_FLOW_ITEM_TYPE_IPV6:
3232 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_IPV6,
3234 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_ipv6,
3237 proto_header_size = sizeof(struct rte_ipv6_hdr);
3239 ethertypep = RTE_PTR_ADD(buf, ethertype_ofst);
3240 *ethertypep = RTE_BE16(RTE_ETHER_TYPE_IPV6);
3242 next_proto_ofst = bounce_eh->size +
3243 offsetof(struct rte_ipv6_hdr, proto);
3245 ipv6 = (struct rte_ipv6_hdr *)buf_cur;
3247 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_UDP);
3249 case RTE_FLOW_ITEM_TYPE_UDP:
3250 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_UDP,
3252 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_udp,
3255 proto_header_size = sizeof(struct rte_udp_hdr);
3257 next_protop = RTE_PTR_ADD(buf, next_proto_ofst);
3258 *next_protop = IPPROTO_UDP;
3260 udp = (struct rte_udp_hdr *)buf_cur;
3262 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_VXLAN);
3264 case RTE_FLOW_ITEM_TYPE_VXLAN:
3265 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_VXLAN,
3267 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_vxlan,
3270 proto_header_size = sizeof(struct rte_vxlan_hdr);
3272 vxlan = (struct rte_vxlan_hdr *)buf_cur;
3274 udp->dst_port = RTE_BE16(RTE_VXLAN_DEFAULT_PORT);
3275 udp->dgram_len = RTE_BE16(sizeof(*udp) +
3277 udp->dgram_cksum = 0;
3282 return rte_flow_error_set(error, ENOTSUP,
3283 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3284 "Unknown item in the encap. header");
3287 if (bounce_eh->size + proto_header_size > bounce_eh->buf_size) {
3288 return rte_flow_error_set(error, E2BIG,
3289 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3290 "The encap. header is too big");
3293 if ((proto_header_size & 1) != 0) {
3294 return rte_flow_error_set(error, EINVAL,
3295 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3296 "Odd layer size in the encap. header");
3299 rte_memcpy(buf_cur, pattern->spec, proto_header_size);
3300 bounce_eh->size += proto_header_size;
3302 parsed_item->item = pattern;
3303 parsed_item->proto_header_size = proto_header_size;
3307 if (exp_items != 0) {
3308 /* Parsing item VXLAN would have reset exp_items to 0. */
3309 return rte_flow_error_set(error, ENOTSUP,
3310 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3311 "No item VXLAN in the encap. header");
3314 /* One of the pointers (ipv4, ipv6) refers to a dummy area. */
3315 ipv4->version_ihl = RTE_IPV4_VHL_DEF;
3316 ipv4->time_to_live = SFC_IPV4_TTL_DEF;
3317 ipv4->total_length = RTE_BE16(sizeof(*ipv4) + sizeof(*udp) +
3319 /* The HW cannot compute this checksum. */
3320 ipv4->hdr_checksum = 0;
3321 ipv4->hdr_checksum = rte_ipv4_cksum(ipv4);
3323 ipv6->vtc_flow = RTE_BE32(SFC_IPV6_VTC_FLOW_DEF);
3324 ipv6->hop_limits = SFC_IPV6_HOP_LIMITS_DEF;
3325 ipv6->payload_len = udp->dgram_len;
3327 vxlan->vx_flags = RTE_BE32(SFC_VXLAN_FLAGS_DEF);
3329 /* Take care of the masks. */
3330 sfc_mae_header_force_item_masks(buf, parsed_items, nb_parsed_items);
3332 rc = efx_mae_action_set_populate_encap(spec);
3334 rc = rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ACTION,
3335 NULL, "failed to request action ENCAP");
3342 sfc_mae_rule_parse_action_mark(struct sfc_adapter *sa,
3343 const struct rte_flow_action_mark *conf,
3344 const struct sfc_flow_spec_mae *spec_mae,
3345 efx_mae_actions_t *spec)
3349 if (spec_mae->ft_rule_type == SFC_FT_RULE_JUMP) {
3350 /* Workaround. See sfc_flow_parse_rte_to_mae() */
3351 } else if (conf->id > SFC_FT_USER_MARK_MASK) {
3352 sfc_err(sa, "the mark value is too large");
3356 rc = efx_mae_action_set_populate_mark(spec, conf->id);
3358 sfc_err(sa, "failed to request action MARK: %s", strerror(rc));
3364 sfc_mae_rule_parse_action_count(struct sfc_adapter *sa,
3365 const struct rte_flow_action_count *conf
3367 efx_mae_actions_t *spec)
3371 if ((sa->counter_rxq.state & SFC_COUNTER_RXQ_INITIALIZED) == 0) {
3373 "counter queue is not configured for COUNT action");
3375 goto fail_counter_queue_uninit;
3378 if (sfc_get_service_lcore(SOCKET_ID_ANY) == RTE_MAX_LCORE) {
3380 goto fail_no_service_core;
3383 rc = efx_mae_action_set_populate_count(spec);
3386 "failed to populate counters in MAE action set: %s",
3388 goto fail_populate_count;
3393 fail_populate_count:
3394 fail_no_service_core:
3395 fail_counter_queue_uninit:
3401 sfc_mae_rule_parse_action_phy_port(struct sfc_adapter *sa,
3402 const struct rte_flow_action_phy_port *conf,
3403 efx_mae_actions_t *spec)
3405 efx_mport_sel_t mport;
3409 if (conf->original != 0)
3410 phy_port = efx_nic_cfg_get(sa->nic)->enc_assigned_port;
3412 phy_port = conf->index;
3414 rc = efx_mae_mport_by_phy_port(phy_port, &mport);
3416 sfc_err(sa, "failed to convert phys. port ID %u to m-port selector: %s",
3417 phy_port, strerror(rc));
3421 rc = efx_mae_action_set_populate_deliver(spec, &mport);
3423 sfc_err(sa, "failed to request action DELIVER with m-port selector 0x%08x: %s",
3424 mport.sel, strerror(rc));
3431 sfc_mae_rule_parse_action_pf_vf(struct sfc_adapter *sa,
3432 const struct rte_flow_action_vf *vf_conf,
3433 efx_mae_actions_t *spec)
3435 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
3436 efx_mport_sel_t mport;
3440 if (vf_conf == NULL)
3441 vf = EFX_PCI_VF_INVALID;
3442 else if (vf_conf->original != 0)
3447 rc = efx_mae_mport_by_pcie_function(encp->enc_pf, vf, &mport);
3449 sfc_err(sa, "failed to convert PF %u VF %d to m-port: %s",
3450 encp->enc_pf, (vf != EFX_PCI_VF_INVALID) ? (int)vf : -1,
3455 rc = efx_mae_action_set_populate_deliver(spec, &mport);
3457 sfc_err(sa, "failed to request action DELIVER with m-port selector 0x%08x: %s",
3458 mport.sel, strerror(rc));
3465 sfc_mae_rule_parse_action_port_id(struct sfc_adapter *sa,
3466 const struct rte_flow_action_port_id *conf,
3467 efx_mae_actions_t *spec)
3469 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
3470 struct sfc_mae *mae = &sa->mae;
3471 efx_mport_sel_t mport;
3475 if (conf->id > UINT16_MAX)
3478 port_id = (conf->original != 0) ? sas->port_id : conf->id;
3480 rc = sfc_mae_switch_get_ethdev_mport(mae->switch_domain_id,
3483 sfc_err(sa, "failed to get m-port for the given ethdev (port_id=%u): %s",
3484 port_id, strerror(rc));
3488 rc = efx_mae_action_set_populate_deliver(spec, &mport);
3490 sfc_err(sa, "failed to request action DELIVER with m-port selector 0x%08x: %s",
3491 mport.sel, strerror(rc));
3498 sfc_mae_rule_parse_action_port_representor(struct sfc_adapter *sa,
3499 const struct rte_flow_action_ethdev *conf,
3500 efx_mae_actions_t *spec)
3502 struct sfc_mae *mae = &sa->mae;
3503 efx_mport_sel_t mport;
3506 rc = sfc_mae_switch_get_ethdev_mport(mae->switch_domain_id,
3507 conf->port_id, &mport);
3509 sfc_err(sa, "failed to get m-port for the given ethdev (port_id=%u): %s",
3510 conf->port_id, strerror(rc));
3514 rc = efx_mae_action_set_populate_deliver(spec, &mport);
3516 sfc_err(sa, "failed to request action DELIVER with m-port selector 0x%08x: %s",
3517 mport.sel, strerror(rc));
3524 sfc_mae_rule_parse_action_represented_port(struct sfc_adapter *sa,
3525 const struct rte_flow_action_ethdev *conf,
3526 efx_mae_actions_t *spec)
3528 struct sfc_mae *mae = &sa->mae;
3529 efx_mport_sel_t mport;
3532 rc = sfc_mae_switch_get_entity_mport(mae->switch_domain_id,
3533 conf->port_id, &mport);
3535 sfc_err(sa, "failed to get m-port for the given ethdev (port_id=%u): %s",
3536 conf->port_id, strerror(rc));
3540 rc = efx_mae_action_set_populate_deliver(spec, &mport);
3542 sfc_err(sa, "failed to request action DELIVER with m-port selector 0x%08x: %s",
3543 mport.sel, strerror(rc));
3549 static const char * const action_names[] = {
3550 [RTE_FLOW_ACTION_TYPE_VXLAN_DECAP] = "VXLAN_DECAP",
3551 [RTE_FLOW_ACTION_TYPE_OF_POP_VLAN] = "OF_POP_VLAN",
3552 [RTE_FLOW_ACTION_TYPE_OF_DEC_NW_TTL] = "OF_DEC_NW_TTL",
3553 [RTE_FLOW_ACTION_TYPE_DEC_TTL] = "DEC_TTL",
3554 [RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN] = "OF_PUSH_VLAN",
3555 [RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID] = "OF_SET_VLAN_VID",
3556 [RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP] = "OF_SET_VLAN_PCP",
3557 [RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP] = "VXLAN_ENCAP",
3558 [RTE_FLOW_ACTION_TYPE_COUNT] = "COUNT",
3559 [RTE_FLOW_ACTION_TYPE_FLAG] = "FLAG",
3560 [RTE_FLOW_ACTION_TYPE_MARK] = "MARK",
3561 [RTE_FLOW_ACTION_TYPE_PHY_PORT] = "PHY_PORT",
3562 [RTE_FLOW_ACTION_TYPE_PF] = "PF",
3563 [RTE_FLOW_ACTION_TYPE_VF] = "VF",
3564 [RTE_FLOW_ACTION_TYPE_PORT_ID] = "PORT_ID",
3565 [RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR] = "PORT_REPRESENTOR",
3566 [RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT] = "REPRESENTED_PORT",
3567 [RTE_FLOW_ACTION_TYPE_DROP] = "DROP",
3568 [RTE_FLOW_ACTION_TYPE_JUMP] = "JUMP",
3572 sfc_mae_rule_parse_action(struct sfc_adapter *sa,
3573 const struct rte_flow_action *action,
3574 const struct sfc_flow_spec_mae *spec_mae,
3575 struct sfc_mae_actions_bundle *bundle,
3576 efx_mae_actions_t *spec,
3577 struct rte_flow_error *error)
3579 const struct sfc_mae_outer_rule *outer_rule = spec_mae->outer_rule;
3580 const uint64_t rx_metadata = sa->negotiated_rx_metadata;
3581 bool custom_error = B_FALSE;
3584 switch (action->type) {
3585 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
3586 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VXLAN_DECAP,
3587 bundle->actions_mask);
3588 if (outer_rule == NULL ||
3589 outer_rule->encap_type != EFX_TUNNEL_PROTOCOL_VXLAN)
3592 rc = efx_mae_action_set_populate_decap(spec);
3594 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
3595 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_POP_VLAN,
3596 bundle->actions_mask);
3597 rc = efx_mae_action_set_populate_vlan_pop(spec);
3599 case RTE_FLOW_ACTION_TYPE_OF_DEC_NW_TTL:
3600 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
3601 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_DEC_NW_TTL,
3602 bundle->actions_mask);
3603 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_DEC_TTL,
3604 bundle->actions_mask);
3605 rc = efx_mae_action_set_populate_decr_ip_ttl(spec);
3607 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3608 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN,
3609 bundle->actions_mask);
3610 sfc_mae_rule_parse_action_of_push_vlan(action->conf, bundle);
3612 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3613 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID,
3614 bundle->actions_mask);
3615 sfc_mae_rule_parse_action_of_set_vlan_vid(action->conf, bundle);
3617 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3618 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP,
3619 bundle->actions_mask);
3620 sfc_mae_rule_parse_action_of_set_vlan_pcp(action->conf, bundle);
3622 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3623 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP,
3624 bundle->actions_mask);
3625 rc = sfc_mae_rule_parse_action_vxlan_encap(&sa->mae,
3628 custom_error = B_TRUE;
3630 case RTE_FLOW_ACTION_TYPE_COUNT:
3631 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_COUNT,
3632 bundle->actions_mask);
3633 rc = sfc_mae_rule_parse_action_count(sa, action->conf, spec);
3635 case RTE_FLOW_ACTION_TYPE_FLAG:
3636 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_FLAG,
3637 bundle->actions_mask);
3638 if ((rx_metadata & RTE_ETH_RX_METADATA_USER_FLAG) != 0) {
3639 rc = efx_mae_action_set_populate_flag(spec);
3641 rc = rte_flow_error_set(error, ENOTSUP,
3642 RTE_FLOW_ERROR_TYPE_ACTION,
3644 "flag delivery has not been negotiated");
3645 custom_error = B_TRUE;
3648 case RTE_FLOW_ACTION_TYPE_MARK:
3649 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_MARK,
3650 bundle->actions_mask);
3651 if ((rx_metadata & RTE_ETH_RX_METADATA_USER_MARK) != 0 ||
3652 spec_mae->ft_rule_type == SFC_FT_RULE_JUMP) {
3653 rc = sfc_mae_rule_parse_action_mark(sa, action->conf,
3656 rc = rte_flow_error_set(error, ENOTSUP,
3657 RTE_FLOW_ERROR_TYPE_ACTION,
3659 "mark delivery has not been negotiated");
3660 custom_error = B_TRUE;
3663 case RTE_FLOW_ACTION_TYPE_PHY_PORT:
3664 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_PHY_PORT,
3665 bundle->actions_mask);
3666 rc = sfc_mae_rule_parse_action_phy_port(sa, action->conf, spec);
3668 case RTE_FLOW_ACTION_TYPE_PF:
3669 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_PF,
3670 bundle->actions_mask);
3671 rc = sfc_mae_rule_parse_action_pf_vf(sa, NULL, spec);
3673 case RTE_FLOW_ACTION_TYPE_VF:
3674 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VF,
3675 bundle->actions_mask);
3676 rc = sfc_mae_rule_parse_action_pf_vf(sa, action->conf, spec);
3678 case RTE_FLOW_ACTION_TYPE_PORT_ID:
3679 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_PORT_ID,
3680 bundle->actions_mask);
3681 rc = sfc_mae_rule_parse_action_port_id(sa, action->conf, spec);
3683 case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
3684 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR,
3685 bundle->actions_mask);
3686 rc = sfc_mae_rule_parse_action_port_representor(sa,
3687 action->conf, spec);
3689 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
3690 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT,
3691 bundle->actions_mask);
3692 rc = sfc_mae_rule_parse_action_represented_port(sa,
3693 action->conf, spec);
3695 case RTE_FLOW_ACTION_TYPE_DROP:
3696 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_DROP,
3697 bundle->actions_mask);
3698 rc = efx_mae_action_set_populate_drop(spec);
3700 case RTE_FLOW_ACTION_TYPE_JUMP:
3701 if (spec_mae->ft_rule_type == SFC_FT_RULE_JUMP) {
3702 /* Workaround. See sfc_flow_parse_rte_to_mae() */
3707 return rte_flow_error_set(error, ENOTSUP,
3708 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3709 "Unsupported action");
3713 bundle->actions_mask |= (1ULL << action->type);
3714 } else if (!custom_error) {
3715 if (action->type < RTE_DIM(action_names)) {
3716 const char *action_name = action_names[action->type];
3718 if (action_name != NULL) {
3719 sfc_err(sa, "action %s was rejected: %s",
3720 action_name, strerror(rc));
3723 rc = rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ACTION,
3724 NULL, "Failed to request the action");
3731 sfc_mae_bounce_eh_invalidate(struct sfc_mae_bounce_eh *bounce_eh)
3733 bounce_eh->type = EFX_TUNNEL_PROTOCOL_NONE;
3737 sfc_mae_process_encap_header(struct sfc_adapter *sa,
3738 const struct sfc_mae_bounce_eh *bounce_eh,
3739 struct sfc_mae_encap_header **encap_headerp)
3741 if (bounce_eh->type == EFX_TUNNEL_PROTOCOL_NONE) {
3742 encap_headerp = NULL;
3746 *encap_headerp = sfc_mae_encap_header_attach(sa, bounce_eh);
3747 if (*encap_headerp != NULL)
3750 return sfc_mae_encap_header_add(sa, bounce_eh, encap_headerp);
3754 sfc_mae_rule_parse_actions(struct sfc_adapter *sa,
3755 const struct rte_flow_action actions[],
3756 struct sfc_flow_spec_mae *spec_mae,
3757 struct rte_flow_error *error)
3759 struct sfc_mae_actions_bundle bundle = {0};
3760 const struct rte_flow_action *action;
3761 struct sfc_mae_aset_ctx ctx = {0};
3762 struct sfc_mae *mae = &sa->mae;
3767 if (actions == NULL) {
3768 return rte_flow_error_set(error, EINVAL,
3769 RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
3773 rc = efx_mae_action_set_spec_init(sa->nic, &ctx.spec);
3775 goto fail_action_set_spec_init;
3777 for (action = actions;
3778 action->type != RTE_FLOW_ACTION_TYPE_END; ++action) {
3779 if (action->type == RTE_FLOW_ACTION_TYPE_COUNT)
3783 if (spec_mae->ft_rule_type == SFC_FT_RULE_GROUP) {
3784 /* JUMP rules don't decapsulate packets. GROUP rules do. */
3785 rc = efx_mae_action_set_populate_decap(ctx.spec);
3787 goto fail_enforce_ft_decap;
3789 if (ctx.n_counters == 0 &&
3790 sfc_mae_counter_stream_enabled(sa)) {
3792 * The user opted not to use action COUNT in this rule,
3793 * but the counter should be enabled implicitly because
3794 * packets hitting this rule contribute to the tunnel's
3795 * total number of hits. See sfc_mae_counter_get().
3797 rc = efx_mae_action_set_populate_count(ctx.spec);
3799 goto fail_enforce_ft_count;
3805 /* Cleanup after previous encap. header bounce buffer usage. */
3806 sfc_mae_bounce_eh_invalidate(&mae->bounce_eh);
3808 for (action = actions;
3809 action->type != RTE_FLOW_ACTION_TYPE_END; ++action) {
3810 rc = sfc_mae_actions_bundle_sync(action, &bundle,
3813 goto fail_rule_parse_action;
3815 rc = sfc_mae_rule_parse_action(sa, action, spec_mae,
3816 &bundle, ctx.spec, error);
3818 goto fail_rule_parse_action;
3821 rc = sfc_mae_actions_bundle_sync(action, &bundle, ctx.spec, error);
3823 goto fail_rule_parse_action;
3825 rc = sfc_mae_process_encap_header(sa, &mae->bounce_eh,
3828 goto fail_process_encap_header;
3830 if (ctx.n_counters > 1) {
3832 sfc_err(sa, "too many count actions requested: %u",
3837 switch (spec_mae->ft_rule_type) {
3838 case SFC_FT_RULE_NONE:
3840 case SFC_FT_RULE_JUMP:
3841 /* Workaround. See sfc_flow_parse_rte_to_mae() */
3842 rc = sfc_mae_rule_parse_action_pf_vf(sa, NULL, ctx.spec);
3844 goto fail_workaround_jump_delivery;
3846 ctx.counter_ft = spec_mae->ft;
3848 case SFC_FT_RULE_GROUP:
3850 * Packets that go to the rule's AR have FT mark set (from the
3851 * JUMP rule OR's RECIRC_ID). Remove this mark in matching
3852 * packets. The user may have provided their own action
3853 * MARK above, so don't check the return value here.
3855 (void)efx_mae_action_set_populate_mark(ctx.spec, 0);
3857 ctx.ft_group_hit_counter = &spec_mae->ft->group_hit_counter;
3860 SFC_ASSERT(B_FALSE);
3863 spec_mae->action_set = sfc_mae_action_set_attach(sa, &ctx);
3864 if (spec_mae->action_set != NULL) {
3865 sfc_mae_encap_header_del(sa, ctx.encap_header);
3866 efx_mae_action_set_spec_fini(sa->nic, ctx.spec);
3870 rc = sfc_mae_action_set_add(sa, actions, &ctx, &spec_mae->action_set);
3872 goto fail_action_set_add;
3876 fail_action_set_add:
3877 fail_workaround_jump_delivery:
3879 sfc_mae_encap_header_del(sa, ctx.encap_header);
3881 fail_process_encap_header:
3882 fail_rule_parse_action:
3883 efx_mae_action_set_spec_fini(sa->nic, ctx.spec);
3885 fail_enforce_ft_count:
3886 fail_enforce_ft_decap:
3887 fail_action_set_spec_init:
3888 if (rc > 0 && rte_errno == 0) {
3889 rc = rte_flow_error_set(error, rc,
3890 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3891 NULL, "Failed to process the action");
3897 sfc_mae_rules_class_cmp(struct sfc_adapter *sa,
3898 const efx_mae_match_spec_t *left,
3899 const efx_mae_match_spec_t *right)
3901 bool have_same_class;
3904 rc = efx_mae_match_specs_class_cmp(sa->nic, left, right,
3907 return (rc == 0) ? have_same_class : false;
3911 sfc_mae_outer_rule_class_verify(struct sfc_adapter *sa,
3912 struct sfc_mae_outer_rule *rule)
3914 struct sfc_mae_fw_rsrc *fw_rsrc = &rule->fw_rsrc;
3915 struct sfc_mae_outer_rule *entry;
3916 struct sfc_mae *mae = &sa->mae;
3918 if (fw_rsrc->rule_id.id != EFX_MAE_RSRC_ID_INVALID) {
3919 /* An active rule is reused. It's class is wittingly valid. */
3923 TAILQ_FOREACH_REVERSE(entry, &mae->outer_rules,
3924 sfc_mae_outer_rules, entries) {
3925 const efx_mae_match_spec_t *left = entry->match_spec;
3926 const efx_mae_match_spec_t *right = rule->match_spec;
3931 if (sfc_mae_rules_class_cmp(sa, left, right))
3935 sfc_info(sa, "for now, the HW doesn't support rule validation, and HW "
3936 "support for outer frame pattern items is not guaranteed; "
3937 "other than that, the items are valid from SW standpoint");
3942 sfc_mae_action_rule_class_verify(struct sfc_adapter *sa,
3943 struct sfc_flow_spec_mae *spec)
3945 const struct rte_flow *entry;
3947 if (spec->match_spec == NULL)
3950 TAILQ_FOREACH_REVERSE(entry, &sa->flow_list, sfc_flow_list, entries) {
3951 const struct sfc_flow_spec *entry_spec = &entry->spec;
3952 const struct sfc_flow_spec_mae *es_mae = &entry_spec->mae;
3953 const efx_mae_match_spec_t *left = es_mae->match_spec;
3954 const efx_mae_match_spec_t *right = spec->match_spec;
3956 switch (entry_spec->type) {
3957 case SFC_FLOW_SPEC_FILTER:
3958 /* Ignore VNIC-level flows */
3960 case SFC_FLOW_SPEC_MAE:
3961 if (sfc_mae_rules_class_cmp(sa, left, right))
3969 sfc_info(sa, "for now, the HW doesn't support rule validation, and HW "
3970 "support for inner frame pattern items is not guaranteed; "
3971 "other than that, the items are valid from SW standpoint");
3976 * Confirm that a given flow can be accepted by the FW.
3979 * Software adapter context
3981 * Flow to be verified
3983 * Zero on success and non-zero in the case of error.
3984 * A special value of EAGAIN indicates that the adapter is
3985 * not in started state. This state is compulsory because
3986 * it only makes sense to compare the rule class of the flow
3987 * being validated with classes of the active rules.
3988 * Such classes are wittingly supported by the FW.
3991 sfc_mae_flow_verify(struct sfc_adapter *sa,
3992 struct rte_flow *flow)
3994 struct sfc_flow_spec *spec = &flow->spec;
3995 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
3996 struct sfc_mae_outer_rule *outer_rule = spec_mae->outer_rule;
3999 SFC_ASSERT(sfc_adapter_is_locked(sa));
4001 if (sa->state != SFC_ETHDEV_STARTED)
4004 if (outer_rule != NULL) {
4005 rc = sfc_mae_outer_rule_class_verify(sa, outer_rule);
4010 return sfc_mae_action_rule_class_verify(sa, spec_mae);
4014 sfc_mae_flow_insert(struct sfc_adapter *sa,
4015 struct rte_flow *flow)
4017 struct sfc_flow_spec *spec = &flow->spec;
4018 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
4019 struct sfc_mae_outer_rule *outer_rule = spec_mae->outer_rule;
4020 struct sfc_mae_action_set *action_set = spec_mae->action_set;
4021 struct sfc_mae_fw_rsrc *fw_rsrc;
4024 SFC_ASSERT(spec_mae->rule_id.id == EFX_MAE_RSRC_ID_INVALID);
4026 if (outer_rule != NULL) {
4027 rc = sfc_mae_outer_rule_enable(sa, outer_rule,
4028 spec_mae->match_spec);
4030 goto fail_outer_rule_enable;
4033 if (spec_mae->ft_rule_type == SFC_FT_RULE_JUMP) {
4034 spec_mae->ft->reset_jump_hit_counter =
4035 spec_mae->ft->group_hit_counter;
4038 if (action_set == NULL) {
4039 sfc_dbg(sa, "enabled flow=%p (no AR)", flow);
4043 rc = sfc_mae_action_set_enable(sa, action_set);
4045 goto fail_action_set_enable;
4047 if (action_set->n_counters > 0) {
4048 rc = sfc_mae_counter_start(sa);
4050 sfc_err(sa, "failed to start MAE counters support: %s",
4052 goto fail_mae_counter_start;
4056 fw_rsrc = &action_set->fw_rsrc;
4058 rc = efx_mae_action_rule_insert(sa->nic, spec_mae->match_spec,
4059 NULL, &fw_rsrc->aset_id,
4060 &spec_mae->rule_id);
4062 goto fail_action_rule_insert;
4064 sfc_dbg(sa, "enabled flow=%p: AR_ID=0x%08x",
4065 flow, spec_mae->rule_id.id);
4069 fail_action_rule_insert:
4070 fail_mae_counter_start:
4071 sfc_mae_action_set_disable(sa, action_set);
4073 fail_action_set_enable:
4074 if (outer_rule != NULL)
4075 sfc_mae_outer_rule_disable(sa, outer_rule);
4077 fail_outer_rule_enable:
4082 sfc_mae_flow_remove(struct sfc_adapter *sa,
4083 struct rte_flow *flow)
4085 struct sfc_flow_spec *spec = &flow->spec;
4086 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
4087 struct sfc_mae_action_set *action_set = spec_mae->action_set;
4088 struct sfc_mae_outer_rule *outer_rule = spec_mae->outer_rule;
4091 if (action_set == NULL) {
4092 sfc_dbg(sa, "disabled flow=%p (no AR)", flow);
4093 goto skip_action_rule;
4096 SFC_ASSERT(spec_mae->rule_id.id != EFX_MAE_RSRC_ID_INVALID);
4098 rc = efx_mae_action_rule_remove(sa->nic, &spec_mae->rule_id);
4100 sfc_err(sa, "failed to disable flow=%p with AR_ID=0x%08x: %s",
4101 flow, spec_mae->rule_id.id, strerror(rc));
4103 sfc_dbg(sa, "disabled flow=%p with AR_ID=0x%08x",
4104 flow, spec_mae->rule_id.id);
4105 spec_mae->rule_id.id = EFX_MAE_RSRC_ID_INVALID;
4107 sfc_mae_action_set_disable(sa, action_set);
4110 if (outer_rule != NULL)
4111 sfc_mae_outer_rule_disable(sa, outer_rule);
4117 sfc_mae_query_counter(struct sfc_adapter *sa,
4118 struct sfc_flow_spec_mae *spec,
4119 const struct rte_flow_action *action,
4120 struct rte_flow_query_count *data,
4121 struct rte_flow_error *error)
4123 struct sfc_mae_action_set *action_set = spec->action_set;
4124 const struct rte_flow_action_count *conf = action->conf;
4128 if (action_set == NULL || action_set->n_counters == 0) {
4129 return rte_flow_error_set(error, EINVAL,
4130 RTE_FLOW_ERROR_TYPE_ACTION, action,
4131 "Queried flow rule does not have count actions");
4134 for (i = 0; i < action_set->n_counters; i++) {
4136 * Get the first available counter of the flow rule if
4137 * counter ID is not specified, provided that this
4138 * counter is not an automatic (implicit) one.
4140 if (conf != NULL && action_set->counters[i].rte_id != conf->id)
4143 rc = sfc_mae_counter_get(&sa->mae.counter_registry.counters,
4144 &action_set->counters[i], data);
4146 return rte_flow_error_set(error, EINVAL,
4147 RTE_FLOW_ERROR_TYPE_ACTION, action,
4148 "Queried flow rule counter action is invalid");
4154 return rte_flow_error_set(error, ENOENT,
4155 RTE_FLOW_ERROR_TYPE_ACTION, action,
4156 "no such flow rule action or such count ID");
4160 sfc_mae_flow_query(struct rte_eth_dev *dev,
4161 struct rte_flow *flow,
4162 const struct rte_flow_action *action,
4164 struct rte_flow_error *error)
4166 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
4167 struct sfc_flow_spec *spec = &flow->spec;
4168 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
4170 switch (action->type) {
4171 case RTE_FLOW_ACTION_TYPE_COUNT:
4172 return sfc_mae_query_counter(sa, spec_mae, action,
4175 return rte_flow_error_set(error, ENOTSUP,
4176 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4177 "Query for action of this type is not supported");
4182 sfc_mae_switchdev_init(struct sfc_adapter *sa)
4184 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
4185 struct sfc_mae *mae = &sa->mae;
4187 efx_mport_sel_t phy;
4190 sfc_log_init(sa, "entry");
4192 if (!sa->switchdev) {
4193 sfc_log_init(sa, "switchdev is not enabled - skip");
4197 if (mae->status != SFC_MAE_STATUS_ADMIN) {
4199 sfc_err(sa, "failed to init switchdev - no admin MAE privilege");
4203 rc = efx_mae_mport_by_pcie_function(encp->enc_pf, EFX_PCI_VF_INVALID,
4206 sfc_err(sa, "failed get PF mport");
4210 rc = efx_mae_mport_by_phy_port(encp->enc_assigned_port, &phy);
4212 sfc_err(sa, "failed get PHY mport");
4216 rc = sfc_mae_rule_add_mport_match_deliver(sa, &pf, &phy,
4217 SFC_MAE_RULE_PRIO_LOWEST,
4218 &mae->switchdev_rule_pf_to_ext);
4220 sfc_err(sa, "failed add MAE rule to forward from PF to PHY");
4224 rc = sfc_mae_rule_add_mport_match_deliver(sa, &phy, &pf,
4225 SFC_MAE_RULE_PRIO_LOWEST,
4226 &mae->switchdev_rule_ext_to_pf);
4228 sfc_err(sa, "failed add MAE rule to forward from PHY to PF");
4232 sfc_log_init(sa, "done");
4237 sfc_mae_rule_del(sa, mae->switchdev_rule_pf_to_ext);
4243 sfc_log_init(sa, "failed: %s", rte_strerror(rc));
4248 sfc_mae_switchdev_fini(struct sfc_adapter *sa)
4250 struct sfc_mae *mae = &sa->mae;
4255 sfc_mae_rule_del(sa, mae->switchdev_rule_pf_to_ext);
4256 sfc_mae_rule_del(sa, mae->switchdev_rule_ext_to_pf);