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_entity_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_counter_registry_init(struct sfc_mae_counter_registry *registry,
37 uint32_t nb_counters_max)
39 return sfc_mae_counters_init(®istry->counters, nb_counters_max);
43 sfc_mae_counter_registry_fini(struct sfc_mae_counter_registry *registry)
45 sfc_mae_counters_fini(®istry->counters);
49 sfc_mae_internal_rule_find_empty_slot(struct sfc_adapter *sa,
50 struct sfc_mae_rule **rule)
52 struct sfc_mae *mae = &sa->mae;
53 struct sfc_mae_internal_rules *internal_rules = &mae->internal_rules;
57 for (entry = 0; entry < SFC_MAE_NB_RULES_MAX; entry++) {
58 if (internal_rules->rules[entry].spec == NULL)
62 if (entry == SFC_MAE_NB_RULES_MAX) {
64 sfc_err(sa, "failed too many rules (%u rules used)", entry);
65 goto fail_too_many_rules;
68 *rule = &internal_rules->rules[entry];
77 sfc_mae_rule_add_mport_match_deliver(struct sfc_adapter *sa,
78 const efx_mport_sel_t *mport_match,
79 const efx_mport_sel_t *mport_deliver,
80 int prio, struct sfc_mae_rule **rulep)
82 struct sfc_mae *mae = &sa->mae;
83 struct sfc_mae_rule *rule;
86 sfc_log_init(sa, "entry");
88 if (prio > 0 && (unsigned int)prio >= mae->nb_action_rule_prios_max) {
90 sfc_err(sa, "failed: invalid priority %d (max %u)", prio,
91 mae->nb_action_rule_prios_max);
92 goto fail_invalid_prio;
95 prio = mae->nb_action_rule_prios_max - 1;
97 rc = sfc_mae_internal_rule_find_empty_slot(sa, &rule);
99 goto fail_find_empty_slot;
101 sfc_log_init(sa, "init MAE match spec");
102 rc = efx_mae_match_spec_init(sa->nic, EFX_MAE_RULE_ACTION,
103 (uint32_t)prio, &rule->spec);
105 sfc_err(sa, "failed to init MAE match spec");
106 goto fail_match_init;
109 rc = efx_mae_match_spec_mport_set(rule->spec, mport_match, NULL);
111 sfc_err(sa, "failed to get MAE match mport selector");
115 rc = efx_mae_action_set_spec_init(sa->nic, &rule->actions);
117 sfc_err(sa, "failed to init MAE action set");
118 goto fail_action_init;
121 rc = efx_mae_action_set_populate_deliver(rule->actions,
124 sfc_err(sa, "failed to populate deliver action");
125 goto fail_populate_deliver;
128 rc = efx_mae_action_set_alloc(sa->nic, rule->actions,
131 sfc_err(sa, "failed to allocate action set");
132 goto fail_action_set_alloc;
135 rc = efx_mae_action_rule_insert(sa->nic, rule->spec, NULL,
139 sfc_err(sa, "failed to insert action rule");
140 goto fail_rule_insert;
145 sfc_log_init(sa, "done");
150 efx_mae_action_set_free(sa->nic, &rule->action_set);
152 fail_action_set_alloc:
153 fail_populate_deliver:
154 efx_mae_action_set_spec_fini(sa->nic, rule->actions);
158 efx_mae_match_spec_fini(sa->nic, rule->spec);
161 fail_find_empty_slot:
163 sfc_log_init(sa, "failed: %s", rte_strerror(rc));
168 sfc_mae_rule_del(struct sfc_adapter *sa, struct sfc_mae_rule *rule)
170 if (rule == NULL || rule->spec == NULL)
173 efx_mae_action_rule_remove(sa->nic, &rule->rule_id);
174 efx_mae_action_set_free(sa->nic, &rule->action_set);
175 efx_mae_action_set_spec_fini(sa->nic, rule->actions);
176 efx_mae_match_spec_fini(sa->nic, rule->spec);
182 sfc_mae_attach(struct sfc_adapter *sa)
184 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
185 struct sfc_mae_switch_port_request switch_port_request = {0};
186 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
187 efx_mport_sel_t entity_mport;
188 struct sfc_mae *mae = &sa->mae;
189 struct sfc_mae_bounce_eh *bounce_eh = &mae->bounce_eh;
190 efx_mae_limits_t limits;
193 sfc_log_init(sa, "entry");
195 if (!encp->enc_mae_supported) {
196 mae->status = SFC_MAE_STATUS_UNSUPPORTED;
200 if (encp->enc_mae_admin) {
201 sfc_log_init(sa, "init MAE");
202 rc = efx_mae_init(sa->nic);
206 sfc_log_init(sa, "get MAE limits");
207 rc = efx_mae_get_limits(sa->nic, &limits);
209 goto fail_mae_get_limits;
211 sfc_log_init(sa, "init MAE counter registry");
212 rc = sfc_mae_counter_registry_init(&mae->counter_registry,
213 limits.eml_max_n_counters);
215 sfc_err(sa, "failed to init MAE counters registry for %u entries: %s",
216 limits.eml_max_n_counters, rte_strerror(rc));
217 goto fail_counter_registry_init;
221 sfc_log_init(sa, "assign entity MPORT");
222 rc = sfc_mae_assign_entity_mport(sa, &entity_mport);
224 goto fail_mae_assign_entity_mport;
226 sfc_log_init(sa, "assign RTE switch domain");
227 rc = sfc_mae_assign_switch_domain(sa, &mae->switch_domain_id);
229 goto fail_mae_assign_switch_domain;
231 sfc_log_init(sa, "assign RTE switch port");
232 switch_port_request.type = SFC_MAE_SWITCH_PORT_INDEPENDENT;
233 switch_port_request.entity_mportp = &entity_mport;
234 /* RTE ethdev MPORT matches that of the entity for independent ports. */
235 switch_port_request.ethdev_mportp = &entity_mport;
236 switch_port_request.ethdev_port_id = sas->port_id;
237 rc = sfc_mae_assign_switch_port(mae->switch_domain_id,
238 &switch_port_request,
239 &mae->switch_port_id);
241 goto fail_mae_assign_switch_port;
243 if (encp->enc_mae_admin) {
244 sfc_log_init(sa, "allocate encap. header bounce buffer");
245 bounce_eh->buf_size = limits.eml_encap_header_size_limit;
246 bounce_eh->buf = rte_malloc("sfc_mae_bounce_eh",
247 bounce_eh->buf_size, 0);
248 if (bounce_eh->buf == NULL)
249 goto fail_mae_alloc_bounce_eh;
251 mae->nb_outer_rule_prios_max = limits.eml_max_n_outer_prios;
252 mae->nb_action_rule_prios_max = limits.eml_max_n_action_prios;
253 mae->encap_types_supported = limits.eml_encap_types_supported;
256 TAILQ_INIT(&mae->outer_rules);
257 TAILQ_INIT(&mae->encap_headers);
258 TAILQ_INIT(&mae->action_sets);
260 if (encp->enc_mae_admin)
261 mae->status = SFC_MAE_STATUS_ADMIN;
263 mae->status = SFC_MAE_STATUS_SUPPORTED;
265 sfc_log_init(sa, "done");
269 fail_mae_alloc_bounce_eh:
270 fail_mae_assign_switch_port:
271 fail_mae_assign_switch_domain:
272 fail_mae_assign_entity_mport:
273 if (encp->enc_mae_admin)
274 sfc_mae_counter_registry_fini(&mae->counter_registry);
276 fail_counter_registry_init:
278 if (encp->enc_mae_admin)
279 efx_mae_fini(sa->nic);
282 sfc_log_init(sa, "failed %d", rc);
288 sfc_mae_detach(struct sfc_adapter *sa)
290 struct sfc_mae *mae = &sa->mae;
291 enum sfc_mae_status status_prev = mae->status;
293 sfc_log_init(sa, "entry");
295 mae->nb_action_rule_prios_max = 0;
296 mae->status = SFC_MAE_STATUS_UNKNOWN;
298 if (status_prev != SFC_MAE_STATUS_ADMIN)
301 rte_free(mae->bounce_eh.buf);
302 sfc_mae_counter_registry_fini(&mae->counter_registry);
304 efx_mae_fini(sa->nic);
306 sfc_log_init(sa, "done");
309 static struct sfc_mae_outer_rule *
310 sfc_mae_outer_rule_attach(struct sfc_adapter *sa,
311 const efx_mae_match_spec_t *match_spec,
312 efx_tunnel_protocol_t encap_type)
314 struct sfc_mae_outer_rule *rule;
315 struct sfc_mae *mae = &sa->mae;
317 SFC_ASSERT(sfc_adapter_is_locked(sa));
319 TAILQ_FOREACH(rule, &mae->outer_rules, entries) {
320 if (efx_mae_match_specs_equal(rule->match_spec, match_spec) &&
321 rule->encap_type == encap_type) {
322 sfc_dbg(sa, "attaching to outer_rule=%p", rule);
332 sfc_mae_outer_rule_add(struct sfc_adapter *sa,
333 efx_mae_match_spec_t *match_spec,
334 efx_tunnel_protocol_t encap_type,
335 struct sfc_mae_outer_rule **rulep)
337 struct sfc_mae_outer_rule *rule;
338 struct sfc_mae *mae = &sa->mae;
340 SFC_ASSERT(sfc_adapter_is_locked(sa));
342 rule = rte_zmalloc("sfc_mae_outer_rule", sizeof(*rule), 0);
347 rule->match_spec = match_spec;
348 rule->encap_type = encap_type;
350 rule->fw_rsrc.rule_id.id = EFX_MAE_RSRC_ID_INVALID;
352 TAILQ_INSERT_TAIL(&mae->outer_rules, rule, entries);
356 sfc_dbg(sa, "added outer_rule=%p", rule);
362 sfc_mae_outer_rule_del(struct sfc_adapter *sa,
363 struct sfc_mae_outer_rule *rule)
365 struct sfc_mae *mae = &sa->mae;
367 SFC_ASSERT(sfc_adapter_is_locked(sa));
368 SFC_ASSERT(rule->refcnt != 0);
372 if (rule->refcnt != 0)
375 if (rule->fw_rsrc.rule_id.id != EFX_MAE_RSRC_ID_INVALID ||
376 rule->fw_rsrc.refcnt != 0) {
377 sfc_err(sa, "deleting outer_rule=%p abandons its FW resource: OR_ID=0x%08x, refcnt=%u",
378 rule, rule->fw_rsrc.rule_id.id, rule->fw_rsrc.refcnt);
381 efx_mae_match_spec_fini(sa->nic, rule->match_spec);
383 TAILQ_REMOVE(&mae->outer_rules, rule, entries);
386 sfc_dbg(sa, "deleted outer_rule=%p", rule);
390 sfc_mae_outer_rule_enable(struct sfc_adapter *sa,
391 struct sfc_mae_outer_rule *rule,
392 efx_mae_match_spec_t *match_spec_action)
394 struct sfc_mae_fw_rsrc *fw_rsrc = &rule->fw_rsrc;
397 SFC_ASSERT(sfc_adapter_is_locked(sa));
399 if (fw_rsrc->refcnt == 0) {
400 SFC_ASSERT(fw_rsrc->rule_id.id == EFX_MAE_RSRC_ID_INVALID);
401 SFC_ASSERT(rule->match_spec != NULL);
403 rc = efx_mae_outer_rule_insert(sa->nic, rule->match_spec,
407 sfc_err(sa, "failed to enable outer_rule=%p: %s",
413 if (match_spec_action == NULL)
414 goto skip_action_rule;
416 rc = efx_mae_match_spec_outer_rule_id_set(match_spec_action,
419 if (fw_rsrc->refcnt == 0) {
420 (void)efx_mae_outer_rule_remove(sa->nic,
422 fw_rsrc->rule_id.id = EFX_MAE_RSRC_ID_INVALID;
425 sfc_err(sa, "can't match on outer rule ID: %s", strerror(rc));
431 if (fw_rsrc->refcnt == 0) {
432 sfc_dbg(sa, "enabled outer_rule=%p: OR_ID=0x%08x",
433 rule, fw_rsrc->rule_id.id);
442 sfc_mae_outer_rule_disable(struct sfc_adapter *sa,
443 struct sfc_mae_outer_rule *rule)
445 struct sfc_mae_fw_rsrc *fw_rsrc = &rule->fw_rsrc;
448 SFC_ASSERT(sfc_adapter_is_locked(sa));
450 if (fw_rsrc->rule_id.id == EFX_MAE_RSRC_ID_INVALID ||
451 fw_rsrc->refcnt == 0) {
452 sfc_err(sa, "failed to disable outer_rule=%p: already disabled; OR_ID=0x%08x, refcnt=%u",
453 rule, fw_rsrc->rule_id.id, fw_rsrc->refcnt);
457 if (fw_rsrc->refcnt == 1) {
458 rc = efx_mae_outer_rule_remove(sa->nic, &fw_rsrc->rule_id);
460 sfc_dbg(sa, "disabled outer_rule=%p with OR_ID=0x%08x",
461 rule, fw_rsrc->rule_id.id);
463 sfc_err(sa, "failed to disable outer_rule=%p with OR_ID=0x%08x: %s",
464 rule, fw_rsrc->rule_id.id, strerror(rc));
466 fw_rsrc->rule_id.id = EFX_MAE_RSRC_ID_INVALID;
472 static struct sfc_mae_encap_header *
473 sfc_mae_encap_header_attach(struct sfc_adapter *sa,
474 const struct sfc_mae_bounce_eh *bounce_eh)
476 struct sfc_mae_encap_header *encap_header;
477 struct sfc_mae *mae = &sa->mae;
479 SFC_ASSERT(sfc_adapter_is_locked(sa));
481 TAILQ_FOREACH(encap_header, &mae->encap_headers, entries) {
482 if (encap_header->size == bounce_eh->size &&
483 memcmp(encap_header->buf, bounce_eh->buf,
484 bounce_eh->size) == 0) {
485 sfc_dbg(sa, "attaching to encap_header=%p",
487 ++(encap_header->refcnt);
496 sfc_mae_encap_header_add(struct sfc_adapter *sa,
497 const struct sfc_mae_bounce_eh *bounce_eh,
498 struct sfc_mae_encap_header **encap_headerp)
500 struct sfc_mae_encap_header *encap_header;
501 struct sfc_mae *mae = &sa->mae;
503 SFC_ASSERT(sfc_adapter_is_locked(sa));
505 encap_header = rte_zmalloc("sfc_mae_encap_header",
506 sizeof(*encap_header), 0);
507 if (encap_header == NULL)
510 encap_header->size = bounce_eh->size;
512 encap_header->buf = rte_malloc("sfc_mae_encap_header_buf",
513 encap_header->size, 0);
514 if (encap_header->buf == NULL) {
515 rte_free(encap_header);
519 rte_memcpy(encap_header->buf, bounce_eh->buf, bounce_eh->size);
521 encap_header->refcnt = 1;
522 encap_header->type = bounce_eh->type;
523 encap_header->fw_rsrc.eh_id.id = EFX_MAE_RSRC_ID_INVALID;
525 TAILQ_INSERT_TAIL(&mae->encap_headers, encap_header, entries);
527 *encap_headerp = encap_header;
529 sfc_dbg(sa, "added encap_header=%p", encap_header);
535 sfc_mae_encap_header_del(struct sfc_adapter *sa,
536 struct sfc_mae_encap_header *encap_header)
538 struct sfc_mae *mae = &sa->mae;
540 if (encap_header == NULL)
543 SFC_ASSERT(sfc_adapter_is_locked(sa));
544 SFC_ASSERT(encap_header->refcnt != 0);
546 --(encap_header->refcnt);
548 if (encap_header->refcnt != 0)
551 if (encap_header->fw_rsrc.eh_id.id != EFX_MAE_RSRC_ID_INVALID ||
552 encap_header->fw_rsrc.refcnt != 0) {
553 sfc_err(sa, "deleting encap_header=%p abandons its FW resource: EH_ID=0x%08x, refcnt=%u",
554 encap_header, encap_header->fw_rsrc.eh_id.id,
555 encap_header->fw_rsrc.refcnt);
558 TAILQ_REMOVE(&mae->encap_headers, encap_header, entries);
559 rte_free(encap_header->buf);
560 rte_free(encap_header);
562 sfc_dbg(sa, "deleted encap_header=%p", encap_header);
566 sfc_mae_encap_header_enable(struct sfc_adapter *sa,
567 struct sfc_mae_encap_header *encap_header,
568 efx_mae_actions_t *action_set_spec)
570 struct sfc_mae_fw_rsrc *fw_rsrc;
573 if (encap_header == NULL)
576 SFC_ASSERT(sfc_adapter_is_locked(sa));
578 fw_rsrc = &encap_header->fw_rsrc;
580 if (fw_rsrc->refcnt == 0) {
581 SFC_ASSERT(fw_rsrc->eh_id.id == EFX_MAE_RSRC_ID_INVALID);
582 SFC_ASSERT(encap_header->buf != NULL);
583 SFC_ASSERT(encap_header->size != 0);
585 rc = efx_mae_encap_header_alloc(sa->nic, encap_header->type,
590 sfc_err(sa, "failed to enable encap_header=%p: %s",
591 encap_header, strerror(rc));
596 rc = efx_mae_action_set_fill_in_eh_id(action_set_spec,
599 if (fw_rsrc->refcnt == 0) {
600 (void)efx_mae_encap_header_free(sa->nic,
602 fw_rsrc->eh_id.id = EFX_MAE_RSRC_ID_INVALID;
605 sfc_err(sa, "can't fill in encap. header ID: %s", strerror(rc));
610 if (fw_rsrc->refcnt == 0) {
611 sfc_dbg(sa, "enabled encap_header=%p: EH_ID=0x%08x",
612 encap_header, fw_rsrc->eh_id.id);
621 sfc_mae_encap_header_disable(struct sfc_adapter *sa,
622 struct sfc_mae_encap_header *encap_header)
624 struct sfc_mae_fw_rsrc *fw_rsrc;
627 if (encap_header == NULL)
630 SFC_ASSERT(sfc_adapter_is_locked(sa));
632 fw_rsrc = &encap_header->fw_rsrc;
634 if (fw_rsrc->eh_id.id == EFX_MAE_RSRC_ID_INVALID ||
635 fw_rsrc->refcnt == 0) {
636 sfc_err(sa, "failed to disable encap_header=%p: already disabled; EH_ID=0x%08x, refcnt=%u",
637 encap_header, fw_rsrc->eh_id.id, fw_rsrc->refcnt);
641 if (fw_rsrc->refcnt == 1) {
642 rc = efx_mae_encap_header_free(sa->nic, &fw_rsrc->eh_id);
644 sfc_dbg(sa, "disabled encap_header=%p with EH_ID=0x%08x",
645 encap_header, fw_rsrc->eh_id.id);
647 sfc_err(sa, "failed to disable encap_header=%p with EH_ID=0x%08x: %s",
648 encap_header, fw_rsrc->eh_id.id, strerror(rc));
650 fw_rsrc->eh_id.id = EFX_MAE_RSRC_ID_INVALID;
657 sfc_mae_counters_enable(struct sfc_adapter *sa,
658 struct sfc_mae_counter_id *counters,
659 unsigned int n_counters,
660 efx_mae_actions_t *action_set_spec)
664 sfc_log_init(sa, "entry");
666 if (n_counters == 0) {
667 sfc_log_init(sa, "no counters - skip");
671 SFC_ASSERT(sfc_adapter_is_locked(sa));
672 SFC_ASSERT(n_counters == 1);
674 rc = sfc_mae_counter_enable(sa, &counters[0]);
676 sfc_err(sa, "failed to enable MAE counter %u: %s",
677 counters[0].mae_id.id, rte_strerror(rc));
678 goto fail_counter_add;
681 rc = efx_mae_action_set_fill_in_counter_id(action_set_spec,
682 &counters[0].mae_id);
684 sfc_err(sa, "failed to fill in MAE counter %u in action set: %s",
685 counters[0].mae_id.id, rte_strerror(rc));
686 goto fail_fill_in_id;
692 (void)sfc_mae_counter_disable(sa, &counters[0]);
695 sfc_log_init(sa, "failed: %s", rte_strerror(rc));
700 sfc_mae_counters_disable(struct sfc_adapter *sa,
701 struct sfc_mae_counter_id *counters,
702 unsigned int n_counters)
707 SFC_ASSERT(sfc_adapter_is_locked(sa));
708 SFC_ASSERT(n_counters == 1);
710 if (counters[0].mae_id.id == EFX_MAE_RSRC_ID_INVALID) {
711 sfc_err(sa, "failed to disable: already disabled");
715 return sfc_mae_counter_disable(sa, &counters[0]);
718 static struct sfc_mae_action_set *
719 sfc_mae_action_set_attach(struct sfc_adapter *sa,
720 const struct sfc_mae_encap_header *encap_header,
721 unsigned int n_count,
722 const efx_mae_actions_t *spec)
724 struct sfc_mae_action_set *action_set;
725 struct sfc_mae *mae = &sa->mae;
727 SFC_ASSERT(sfc_adapter_is_locked(sa));
729 TAILQ_FOREACH(action_set, &mae->action_sets, entries) {
731 * Shared counters are not supported, hence action sets with
732 * COUNT are not attachable.
734 if (action_set->encap_header == encap_header &&
736 efx_mae_action_set_specs_equal(action_set->spec, spec)) {
737 sfc_dbg(sa, "attaching to action_set=%p", action_set);
738 ++(action_set->refcnt);
747 sfc_mae_action_set_add(struct sfc_adapter *sa,
748 const struct rte_flow_action actions[],
749 efx_mae_actions_t *spec,
750 struct sfc_mae_encap_header *encap_header,
751 uint64_t *ft_group_hit_counter,
752 struct sfc_flow_tunnel *ft,
753 unsigned int n_counters,
754 struct sfc_mae_action_set **action_setp)
756 struct sfc_mae_action_set *action_set;
757 struct sfc_mae *mae = &sa->mae;
760 SFC_ASSERT(sfc_adapter_is_locked(sa));
762 action_set = rte_zmalloc("sfc_mae_action_set", sizeof(*action_set), 0);
763 if (action_set == NULL) {
764 sfc_err(sa, "failed to alloc action set");
768 if (n_counters > 0) {
769 const struct rte_flow_action *action;
771 action_set->counters = rte_malloc("sfc_mae_counter_ids",
772 sizeof(action_set->counters[0]) * n_counters, 0);
773 if (action_set->counters == NULL) {
774 rte_free(action_set);
775 sfc_err(sa, "failed to alloc counters");
779 for (i = 0; i < n_counters; ++i) {
780 action_set->counters[i].rte_id_valid = B_FALSE;
781 action_set->counters[i].mae_id.id =
782 EFX_MAE_RSRC_ID_INVALID;
784 action_set->counters[i].ft_group_hit_counter =
785 ft_group_hit_counter;
786 action_set->counters[i].ft = ft;
789 for (action = actions, i = 0;
790 action->type != RTE_FLOW_ACTION_TYPE_END && i < n_counters;
792 const struct rte_flow_action_count *conf;
794 if (action->type != RTE_FLOW_ACTION_TYPE_COUNT)
799 action_set->counters[i].rte_id_valid = B_TRUE;
800 action_set->counters[i].rte_id = conf->id;
803 action_set->n_counters = n_counters;
806 action_set->refcnt = 1;
807 action_set->spec = spec;
808 action_set->encap_header = encap_header;
810 action_set->fw_rsrc.aset_id.id = EFX_MAE_RSRC_ID_INVALID;
812 TAILQ_INSERT_TAIL(&mae->action_sets, action_set, entries);
814 *action_setp = action_set;
816 sfc_dbg(sa, "added action_set=%p", action_set);
822 sfc_mae_action_set_del(struct sfc_adapter *sa,
823 struct sfc_mae_action_set *action_set)
825 struct sfc_mae *mae = &sa->mae;
827 SFC_ASSERT(sfc_adapter_is_locked(sa));
828 SFC_ASSERT(action_set->refcnt != 0);
830 --(action_set->refcnt);
832 if (action_set->refcnt != 0)
835 if (action_set->fw_rsrc.aset_id.id != EFX_MAE_RSRC_ID_INVALID ||
836 action_set->fw_rsrc.refcnt != 0) {
837 sfc_err(sa, "deleting action_set=%p abandons its FW resource: AS_ID=0x%08x, refcnt=%u",
838 action_set, action_set->fw_rsrc.aset_id.id,
839 action_set->fw_rsrc.refcnt);
842 efx_mae_action_set_spec_fini(sa->nic, action_set->spec);
843 sfc_mae_encap_header_del(sa, action_set->encap_header);
844 if (action_set->n_counters > 0) {
845 SFC_ASSERT(action_set->n_counters == 1);
846 SFC_ASSERT(action_set->counters[0].mae_id.id ==
847 EFX_MAE_RSRC_ID_INVALID);
848 rte_free(action_set->counters);
850 TAILQ_REMOVE(&mae->action_sets, action_set, entries);
851 rte_free(action_set);
853 sfc_dbg(sa, "deleted action_set=%p", action_set);
857 sfc_mae_action_set_enable(struct sfc_adapter *sa,
858 struct sfc_mae_action_set *action_set)
860 struct sfc_mae_encap_header *encap_header = action_set->encap_header;
861 struct sfc_mae_counter_id *counters = action_set->counters;
862 struct sfc_mae_fw_rsrc *fw_rsrc = &action_set->fw_rsrc;
865 SFC_ASSERT(sfc_adapter_is_locked(sa));
867 if (fw_rsrc->refcnt == 0) {
868 SFC_ASSERT(fw_rsrc->aset_id.id == EFX_MAE_RSRC_ID_INVALID);
869 SFC_ASSERT(action_set->spec != NULL);
871 rc = sfc_mae_encap_header_enable(sa, encap_header,
876 rc = sfc_mae_counters_enable(sa, counters,
877 action_set->n_counters,
880 sfc_err(sa, "failed to enable %u MAE counters: %s",
881 action_set->n_counters, rte_strerror(rc));
883 sfc_mae_encap_header_disable(sa, encap_header);
887 rc = efx_mae_action_set_alloc(sa->nic, action_set->spec,
890 sfc_err(sa, "failed to enable action_set=%p: %s",
891 action_set, strerror(rc));
893 (void)sfc_mae_counters_disable(sa, counters,
894 action_set->n_counters);
895 sfc_mae_encap_header_disable(sa, encap_header);
899 sfc_dbg(sa, "enabled action_set=%p: AS_ID=0x%08x",
900 action_set, fw_rsrc->aset_id.id);
909 sfc_mae_action_set_disable(struct sfc_adapter *sa,
910 struct sfc_mae_action_set *action_set)
912 struct sfc_mae_fw_rsrc *fw_rsrc = &action_set->fw_rsrc;
915 SFC_ASSERT(sfc_adapter_is_locked(sa));
917 if (fw_rsrc->aset_id.id == EFX_MAE_RSRC_ID_INVALID ||
918 fw_rsrc->refcnt == 0) {
919 sfc_err(sa, "failed to disable action_set=%p: already disabled; AS_ID=0x%08x, refcnt=%u",
920 action_set, fw_rsrc->aset_id.id, fw_rsrc->refcnt);
924 if (fw_rsrc->refcnt == 1) {
925 rc = efx_mae_action_set_free(sa->nic, &fw_rsrc->aset_id);
927 sfc_dbg(sa, "disabled action_set=%p with AS_ID=0x%08x",
928 action_set, fw_rsrc->aset_id.id);
930 sfc_err(sa, "failed to disable action_set=%p with AS_ID=0x%08x: %s",
931 action_set, fw_rsrc->aset_id.id, strerror(rc));
933 fw_rsrc->aset_id.id = EFX_MAE_RSRC_ID_INVALID;
935 rc = sfc_mae_counters_disable(sa, action_set->counters,
936 action_set->n_counters);
938 sfc_err(sa, "failed to disable %u MAE counters: %s",
939 action_set->n_counters, rte_strerror(rc));
942 sfc_mae_encap_header_disable(sa, action_set->encap_header);
949 sfc_mae_flow_cleanup(struct sfc_adapter *sa,
950 struct rte_flow *flow)
952 struct sfc_flow_spec *spec;
953 struct sfc_flow_spec_mae *spec_mae;
963 spec_mae = &spec->mae;
965 if (spec_mae->ft != NULL) {
966 if (spec_mae->ft_rule_type == SFC_FT_RULE_JUMP)
967 spec_mae->ft->jump_rule_is_set = B_FALSE;
969 SFC_ASSERT(spec_mae->ft->refcnt != 0);
970 --(spec_mae->ft->refcnt);
973 SFC_ASSERT(spec_mae->rule_id.id == EFX_MAE_RSRC_ID_INVALID);
975 if (spec_mae->outer_rule != NULL)
976 sfc_mae_outer_rule_del(sa, spec_mae->outer_rule);
978 if (spec_mae->action_set != NULL)
979 sfc_mae_action_set_del(sa, spec_mae->action_set);
981 if (spec_mae->match_spec != NULL)
982 efx_mae_match_spec_fini(sa->nic, spec_mae->match_spec);
986 sfc_mae_set_ethertypes(struct sfc_mae_parse_ctx *ctx)
988 struct sfc_mae_pattern_data *pdata = &ctx->pattern_data;
989 const efx_mae_field_id_t *fremap = ctx->field_ids_remap;
990 const efx_mae_field_id_t field_ids[] = {
991 EFX_MAE_FIELD_VLAN0_PROTO_BE,
992 EFX_MAE_FIELD_VLAN1_PROTO_BE,
994 const struct sfc_mae_ethertype *et;
999 * In accordance with RTE flow API convention, the innermost L2
1000 * item's "type" ("inner_type") is a L3 EtherType. If there is
1001 * no L3 item, it's 0x0000/0x0000.
1003 et = &pdata->ethertypes[pdata->nb_vlan_tags];
1004 rc = efx_mae_match_spec_field_set(ctx->match_spec,
1005 fremap[EFX_MAE_FIELD_ETHER_TYPE_BE],
1007 (const uint8_t *)&et->value,
1009 (const uint8_t *)&et->mask);
1014 * sfc_mae_rule_parse_item_vlan() has already made sure
1015 * that pdata->nb_vlan_tags does not exceed this figure.
1017 RTE_BUILD_BUG_ON(SFC_MAE_MATCH_VLAN_MAX_NTAGS != 2);
1019 for (i = 0; i < pdata->nb_vlan_tags; ++i) {
1020 et = &pdata->ethertypes[i];
1022 rc = efx_mae_match_spec_field_set(ctx->match_spec,
1023 fremap[field_ids[i]],
1025 (const uint8_t *)&et->value,
1027 (const uint8_t *)&et->mask);
1036 sfc_mae_rule_process_pattern_data(struct sfc_mae_parse_ctx *ctx,
1037 struct rte_flow_error *error)
1039 const efx_mae_field_id_t *fremap = ctx->field_ids_remap;
1040 struct sfc_mae_pattern_data *pdata = &ctx->pattern_data;
1041 struct sfc_mae_ethertype *ethertypes = pdata->ethertypes;
1042 const rte_be16_t supported_tpids[] = {
1043 /* VLAN standard TPID (always the first element) */
1044 RTE_BE16(RTE_ETHER_TYPE_VLAN),
1046 /* Double-tagging TPIDs */
1047 RTE_BE16(RTE_ETHER_TYPE_QINQ),
1048 RTE_BE16(RTE_ETHER_TYPE_QINQ1),
1049 RTE_BE16(RTE_ETHER_TYPE_QINQ2),
1050 RTE_BE16(RTE_ETHER_TYPE_QINQ3),
1052 bool enforce_tag_presence[SFC_MAE_MATCH_VLAN_MAX_NTAGS] = {0};
1053 unsigned int nb_supported_tpids = RTE_DIM(supported_tpids);
1054 unsigned int ethertype_idx;
1055 const uint8_t *valuep;
1056 const uint8_t *maskp;
1059 if (pdata->innermost_ethertype_restriction.mask != 0 &&
1060 pdata->nb_vlan_tags < SFC_MAE_MATCH_VLAN_MAX_NTAGS) {
1062 * If a single item VLAN is followed by a L3 item, value
1063 * of "type" in item ETH can't be a double-tagging TPID.
1065 nb_supported_tpids = 1;
1069 * sfc_mae_rule_parse_item_vlan() has already made sure
1070 * that pdata->nb_vlan_tags does not exceed this figure.
1072 RTE_BUILD_BUG_ON(SFC_MAE_MATCH_VLAN_MAX_NTAGS != 2);
1074 for (ethertype_idx = 0;
1075 ethertype_idx < pdata->nb_vlan_tags; ++ethertype_idx) {
1076 rte_be16_t tpid_v = ethertypes[ethertype_idx].value;
1077 rte_be16_t tpid_m = ethertypes[ethertype_idx].mask;
1078 unsigned int tpid_idx;
1081 * This loop can have only two iterations. On the second one,
1082 * drop outer tag presence enforcement bit because the inner
1083 * tag presence automatically assumes that for the outer tag.
1085 enforce_tag_presence[0] = B_FALSE;
1087 if (tpid_m == RTE_BE16(0)) {
1088 if (pdata->tci_masks[ethertype_idx] == RTE_BE16(0))
1089 enforce_tag_presence[ethertype_idx] = B_TRUE;
1091 /* No match on this field, and no value check. */
1092 nb_supported_tpids = 1;
1096 /* Exact match is supported only. */
1097 if (tpid_m != RTE_BE16(0xffff)) {
1098 sfc_err(ctx->sa, "TPID mask must be 0x0 or 0xffff; got 0x%04x",
1099 rte_be_to_cpu_16(tpid_m));
1104 for (tpid_idx = pdata->nb_vlan_tags - ethertype_idx - 1;
1105 tpid_idx < nb_supported_tpids; ++tpid_idx) {
1106 if (tpid_v == supported_tpids[tpid_idx])
1110 if (tpid_idx == nb_supported_tpids) {
1111 sfc_err(ctx->sa, "TPID 0x%04x is unsupported",
1112 rte_be_to_cpu_16(tpid_v));
1117 nb_supported_tpids = 1;
1120 if (pdata->innermost_ethertype_restriction.mask == RTE_BE16(0xffff)) {
1121 struct sfc_mae_ethertype *et = ðertypes[ethertype_idx];
1122 rte_be16_t enforced_et;
1124 enforced_et = pdata->innermost_ethertype_restriction.value;
1126 if (et->mask == 0) {
1127 et->mask = RTE_BE16(0xffff);
1128 et->value = enforced_et;
1129 } else if (et->mask != RTE_BE16(0xffff) ||
1130 et->value != enforced_et) {
1131 sfc_err(ctx->sa, "L3 EtherType must be 0x0/0x0 or 0x%04x/0xffff; got 0x%04x/0x%04x",
1132 rte_be_to_cpu_16(enforced_et),
1133 rte_be_to_cpu_16(et->value),
1134 rte_be_to_cpu_16(et->mask));
1141 * Now, when the number of VLAN tags is known, set fields
1142 * ETHER_TYPE, VLAN0_PROTO and VLAN1_PROTO so that the first
1143 * one is either a valid L3 EtherType (or 0x0000/0x0000),
1144 * and the last two are valid TPIDs (or 0x0000/0x0000).
1146 rc = sfc_mae_set_ethertypes(ctx);
1150 if (pdata->l3_next_proto_restriction_mask == 0xff) {
1151 if (pdata->l3_next_proto_mask == 0) {
1152 pdata->l3_next_proto_mask = 0xff;
1153 pdata->l3_next_proto_value =
1154 pdata->l3_next_proto_restriction_value;
1155 } else if (pdata->l3_next_proto_mask != 0xff ||
1156 pdata->l3_next_proto_value !=
1157 pdata->l3_next_proto_restriction_value) {
1158 sfc_err(ctx->sa, "L3 next protocol must be 0x0/0x0 or 0x%02x/0xff; got 0x%02x/0x%02x",
1159 pdata->l3_next_proto_restriction_value,
1160 pdata->l3_next_proto_value,
1161 pdata->l3_next_proto_mask);
1167 if (enforce_tag_presence[0] || pdata->has_ovlan_mask) {
1168 rc = efx_mae_match_spec_bit_set(ctx->match_spec,
1169 fremap[EFX_MAE_FIELD_HAS_OVLAN],
1170 enforce_tag_presence[0] ||
1171 pdata->has_ovlan_value);
1176 if (enforce_tag_presence[1] || pdata->has_ivlan_mask) {
1177 rc = efx_mae_match_spec_bit_set(ctx->match_spec,
1178 fremap[EFX_MAE_FIELD_HAS_IVLAN],
1179 enforce_tag_presence[1] ||
1180 pdata->has_ivlan_value);
1185 valuep = (const uint8_t *)&pdata->l3_next_proto_value;
1186 maskp = (const uint8_t *)&pdata->l3_next_proto_mask;
1187 rc = efx_mae_match_spec_field_set(ctx->match_spec,
1188 fremap[EFX_MAE_FIELD_IP_PROTO],
1189 sizeof(pdata->l3_next_proto_value),
1191 sizeof(pdata->l3_next_proto_mask),
1199 return rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1200 "Failed to process pattern data");
1204 sfc_mae_rule_parse_item_mark(const struct rte_flow_item *item,
1205 struct sfc_flow_parse_ctx *ctx,
1206 struct rte_flow_error *error)
1208 const struct rte_flow_item_mark *spec = item->spec;
1209 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1212 return rte_flow_error_set(error, EINVAL,
1213 RTE_FLOW_ERROR_TYPE_ITEM, item,
1214 "NULL spec in item MARK");
1218 * This item is used in tunnel offload support only.
1219 * It must go before any network header items. This
1220 * way, sfc_mae_rule_preparse_item_mark() must have
1221 * already parsed it. Only one item MARK is allowed.
1223 if (ctx_mae->ft_rule_type != SFC_FT_RULE_GROUP ||
1224 spec->id != (uint32_t)SFC_FT_ID_TO_MARK(ctx_mae->ft->id)) {
1225 return rte_flow_error_set(error, EINVAL,
1226 RTE_FLOW_ERROR_TYPE_ITEM,
1227 item, "invalid item MARK");
1234 sfc_mae_rule_parse_item_port_id(const struct rte_flow_item *item,
1235 struct sfc_flow_parse_ctx *ctx,
1236 struct rte_flow_error *error)
1238 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1239 const struct rte_flow_item_port_id supp_mask = {
1242 const void *def_mask = &rte_flow_item_port_id_mask;
1243 const struct rte_flow_item_port_id *spec = NULL;
1244 const struct rte_flow_item_port_id *mask = NULL;
1245 efx_mport_sel_t mport_sel;
1248 if (ctx_mae->match_mport_set) {
1249 return rte_flow_error_set(error, ENOTSUP,
1250 RTE_FLOW_ERROR_TYPE_ITEM, item,
1251 "Can't handle multiple traffic source items");
1254 rc = sfc_flow_parse_init(item,
1255 (const void **)&spec, (const void **)&mask,
1256 (const void *)&supp_mask, def_mask,
1257 sizeof(struct rte_flow_item_port_id), error);
1261 if (mask->id != supp_mask.id) {
1262 return rte_flow_error_set(error, EINVAL,
1263 RTE_FLOW_ERROR_TYPE_ITEM, item,
1264 "Bad mask in the PORT_ID pattern item");
1267 /* If "spec" is not set, could be any port ID */
1271 if (spec->id > UINT16_MAX) {
1272 return rte_flow_error_set(error, EOVERFLOW,
1273 RTE_FLOW_ERROR_TYPE_ITEM, item,
1274 "The port ID is too large");
1277 rc = sfc_mae_switch_port_by_ethdev(ctx_mae->sa->mae.switch_domain_id,
1278 spec->id, &mport_sel);
1280 return rte_flow_error_set(error, rc,
1281 RTE_FLOW_ERROR_TYPE_ITEM, item,
1282 "Can't find RTE ethdev by the port ID");
1285 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec,
1288 return rte_flow_error_set(error, rc,
1289 RTE_FLOW_ERROR_TYPE_ITEM, item,
1290 "Failed to set MPORT for the port ID");
1293 ctx_mae->match_mport_set = B_TRUE;
1299 sfc_mae_rule_parse_item_port_representor(const struct rte_flow_item *item,
1300 struct sfc_flow_parse_ctx *ctx,
1301 struct rte_flow_error *error)
1303 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1304 const struct rte_flow_item_ethdev supp_mask = {
1307 const void *def_mask = &rte_flow_item_ethdev_mask;
1308 const struct rte_flow_item_ethdev *spec = NULL;
1309 const struct rte_flow_item_ethdev *mask = NULL;
1310 efx_mport_sel_t mport_sel;
1313 if (ctx_mae->match_mport_set) {
1314 return rte_flow_error_set(error, ENOTSUP,
1315 RTE_FLOW_ERROR_TYPE_ITEM, item,
1316 "Can't handle multiple traffic source items");
1319 rc = sfc_flow_parse_init(item,
1320 (const void **)&spec, (const void **)&mask,
1321 (const void *)&supp_mask, def_mask,
1322 sizeof(struct rte_flow_item_ethdev), error);
1326 if (mask->port_id != supp_mask.port_id) {
1327 return rte_flow_error_set(error, EINVAL,
1328 RTE_FLOW_ERROR_TYPE_ITEM, item,
1329 "Bad mask in the PORT_REPRESENTOR pattern item");
1332 /* If "spec" is not set, could be any port ID */
1336 rc = sfc_mae_switch_port_by_ethdev(
1337 ctx_mae->sa->mae.switch_domain_id,
1338 spec->port_id, &mport_sel);
1340 return rte_flow_error_set(error, rc,
1341 RTE_FLOW_ERROR_TYPE_ITEM, item,
1342 "Can't find RTE ethdev by the port ID");
1345 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec,
1348 return rte_flow_error_set(error, rc,
1349 RTE_FLOW_ERROR_TYPE_ITEM, item,
1350 "Failed to set MPORT for the port ID");
1353 ctx_mae->match_mport_set = B_TRUE;
1359 sfc_mae_rule_parse_item_phy_port(const struct rte_flow_item *item,
1360 struct sfc_flow_parse_ctx *ctx,
1361 struct rte_flow_error *error)
1363 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1364 const struct rte_flow_item_phy_port supp_mask = {
1365 .index = 0xffffffff,
1367 const void *def_mask = &rte_flow_item_phy_port_mask;
1368 const struct rte_flow_item_phy_port *spec = NULL;
1369 const struct rte_flow_item_phy_port *mask = NULL;
1370 efx_mport_sel_t mport_v;
1373 if (ctx_mae->match_mport_set) {
1374 return rte_flow_error_set(error, ENOTSUP,
1375 RTE_FLOW_ERROR_TYPE_ITEM, item,
1376 "Can't handle multiple traffic source items");
1379 rc = sfc_flow_parse_init(item,
1380 (const void **)&spec, (const void **)&mask,
1381 (const void *)&supp_mask, def_mask,
1382 sizeof(struct rte_flow_item_phy_port), error);
1386 if (mask->index != supp_mask.index) {
1387 return rte_flow_error_set(error, EINVAL,
1388 RTE_FLOW_ERROR_TYPE_ITEM, item,
1389 "Bad mask in the PHY_PORT pattern item");
1392 /* If "spec" is not set, could be any physical port */
1396 rc = efx_mae_mport_by_phy_port(spec->index, &mport_v);
1398 return rte_flow_error_set(error, rc,
1399 RTE_FLOW_ERROR_TYPE_ITEM, item,
1400 "Failed to convert the PHY_PORT index");
1403 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec, &mport_v, NULL);
1405 return rte_flow_error_set(error, rc,
1406 RTE_FLOW_ERROR_TYPE_ITEM, item,
1407 "Failed to set MPORT for the PHY_PORT");
1410 ctx_mae->match_mport_set = B_TRUE;
1416 sfc_mae_rule_parse_item_pf(const struct rte_flow_item *item,
1417 struct sfc_flow_parse_ctx *ctx,
1418 struct rte_flow_error *error)
1420 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1421 const efx_nic_cfg_t *encp = efx_nic_cfg_get(ctx_mae->sa->nic);
1422 efx_mport_sel_t mport_v;
1425 if (ctx_mae->match_mport_set) {
1426 return rte_flow_error_set(error, ENOTSUP,
1427 RTE_FLOW_ERROR_TYPE_ITEM, item,
1428 "Can't handle multiple traffic source items");
1431 rc = efx_mae_mport_by_pcie_function(encp->enc_pf, EFX_PCI_VF_INVALID,
1434 return rte_flow_error_set(error, rc,
1435 RTE_FLOW_ERROR_TYPE_ITEM, item,
1436 "Failed to convert the PF ID");
1439 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec, &mport_v, NULL);
1441 return rte_flow_error_set(error, rc,
1442 RTE_FLOW_ERROR_TYPE_ITEM, item,
1443 "Failed to set MPORT for the PF");
1446 ctx_mae->match_mport_set = B_TRUE;
1452 sfc_mae_rule_parse_item_vf(const struct rte_flow_item *item,
1453 struct sfc_flow_parse_ctx *ctx,
1454 struct rte_flow_error *error)
1456 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1457 const efx_nic_cfg_t *encp = efx_nic_cfg_get(ctx_mae->sa->nic);
1458 const struct rte_flow_item_vf supp_mask = {
1461 const void *def_mask = &rte_flow_item_vf_mask;
1462 const struct rte_flow_item_vf *spec = NULL;
1463 const struct rte_flow_item_vf *mask = NULL;
1464 efx_mport_sel_t mport_v;
1467 if (ctx_mae->match_mport_set) {
1468 return rte_flow_error_set(error, ENOTSUP,
1469 RTE_FLOW_ERROR_TYPE_ITEM, item,
1470 "Can't handle multiple traffic source items");
1473 rc = sfc_flow_parse_init(item,
1474 (const void **)&spec, (const void **)&mask,
1475 (const void *)&supp_mask, def_mask,
1476 sizeof(struct rte_flow_item_vf), error);
1480 if (mask->id != supp_mask.id) {
1481 return rte_flow_error_set(error, EINVAL,
1482 RTE_FLOW_ERROR_TYPE_ITEM, item,
1483 "Bad mask in the VF pattern item");
1487 * If "spec" is not set, the item requests any VF related to the
1488 * PF of the current DPDK port (but not the PF itself).
1489 * Reject this match criterion as unsupported.
1492 return rte_flow_error_set(error, EINVAL,
1493 RTE_FLOW_ERROR_TYPE_ITEM, item,
1494 "Bad spec in the VF pattern item");
1497 rc = efx_mae_mport_by_pcie_function(encp->enc_pf, spec->id, &mport_v);
1499 return rte_flow_error_set(error, rc,
1500 RTE_FLOW_ERROR_TYPE_ITEM, item,
1501 "Failed to convert the PF + VF IDs");
1504 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec, &mport_v, NULL);
1506 return rte_flow_error_set(error, rc,
1507 RTE_FLOW_ERROR_TYPE_ITEM, item,
1508 "Failed to set MPORT for the PF + VF");
1511 ctx_mae->match_mport_set = B_TRUE;
1517 * Having this field ID in a field locator means that this
1518 * locator cannot be used to actually set the field at the
1519 * time when the corresponding item gets encountered. Such
1520 * fields get stashed in the parsing context instead. This
1521 * is required to resolve dependencies between the stashed
1522 * fields. See sfc_mae_rule_process_pattern_data().
1524 #define SFC_MAE_FIELD_HANDLING_DEFERRED EFX_MAE_FIELD_NIDS
1526 struct sfc_mae_field_locator {
1527 efx_mae_field_id_t field_id;
1529 /* Field offset in the corresponding rte_flow_item_ struct */
1534 sfc_mae_item_build_supp_mask(const struct sfc_mae_field_locator *field_locators,
1535 unsigned int nb_field_locators, void *mask_ptr,
1540 memset(mask_ptr, 0, mask_size);
1542 for (i = 0; i < nb_field_locators; ++i) {
1543 const struct sfc_mae_field_locator *fl = &field_locators[i];
1545 SFC_ASSERT(fl->ofst + fl->size <= mask_size);
1546 memset(RTE_PTR_ADD(mask_ptr, fl->ofst), 0xff, fl->size);
1551 sfc_mae_parse_item(const struct sfc_mae_field_locator *field_locators,
1552 unsigned int nb_field_locators, const uint8_t *spec,
1553 const uint8_t *mask, struct sfc_mae_parse_ctx *ctx,
1554 struct rte_flow_error *error)
1556 const efx_mae_field_id_t *fremap = ctx->field_ids_remap;
1560 for (i = 0; i < nb_field_locators; ++i) {
1561 const struct sfc_mae_field_locator *fl = &field_locators[i];
1563 if (fl->field_id == SFC_MAE_FIELD_HANDLING_DEFERRED)
1566 rc = efx_mae_match_spec_field_set(ctx->match_spec,
1567 fremap[fl->field_id],
1568 fl->size, spec + fl->ofst,
1569 fl->size, mask + fl->ofst);
1575 rc = rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM,
1576 NULL, "Failed to process item fields");
1582 static const struct sfc_mae_field_locator flocs_eth[] = {
1585 * This locator is used only for building supported fields mask.
1586 * The field is handled by sfc_mae_rule_process_pattern_data().
1588 SFC_MAE_FIELD_HANDLING_DEFERRED,
1589 RTE_SIZEOF_FIELD(struct rte_flow_item_eth, type),
1590 offsetof(struct rte_flow_item_eth, type),
1593 EFX_MAE_FIELD_ETH_DADDR_BE,
1594 RTE_SIZEOF_FIELD(struct rte_flow_item_eth, dst),
1595 offsetof(struct rte_flow_item_eth, dst),
1598 EFX_MAE_FIELD_ETH_SADDR_BE,
1599 RTE_SIZEOF_FIELD(struct rte_flow_item_eth, src),
1600 offsetof(struct rte_flow_item_eth, src),
1605 sfc_mae_rule_parse_item_eth(const struct rte_flow_item *item,
1606 struct sfc_flow_parse_ctx *ctx,
1607 struct rte_flow_error *error)
1609 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1610 struct rte_flow_item_eth override_mask;
1611 struct rte_flow_item_eth supp_mask;
1612 const uint8_t *spec = NULL;
1613 const uint8_t *mask = NULL;
1616 sfc_mae_item_build_supp_mask(flocs_eth, RTE_DIM(flocs_eth),
1617 &supp_mask, sizeof(supp_mask));
1618 supp_mask.has_vlan = 1;
1620 rc = sfc_flow_parse_init(item,
1621 (const void **)&spec, (const void **)&mask,
1622 (const void *)&supp_mask,
1623 &rte_flow_item_eth_mask,
1624 sizeof(struct rte_flow_item_eth), error);
1628 if (ctx_mae->ft_rule_type == SFC_FT_RULE_JUMP && mask != NULL) {
1630 * The HW/FW hasn't got support for match on MAC addresses in
1631 * outer rules yet (this will change). Match on VLAN presence
1632 * isn't supported either. Ignore these match criteria.
1634 memcpy(&override_mask, mask, sizeof(override_mask));
1635 memset(&override_mask.hdr.dst_addr, 0,
1636 sizeof(override_mask.hdr.dst_addr));
1637 memset(&override_mask.hdr.src_addr, 0,
1638 sizeof(override_mask.hdr.src_addr));
1639 override_mask.has_vlan = 0;
1641 mask = (const uint8_t *)&override_mask;
1645 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
1646 struct sfc_mae_ethertype *ethertypes = pdata->ethertypes;
1647 const struct rte_flow_item_eth *item_spec;
1648 const struct rte_flow_item_eth *item_mask;
1650 item_spec = (const struct rte_flow_item_eth *)spec;
1651 item_mask = (const struct rte_flow_item_eth *)mask;
1654 * Remember various match criteria in the parsing context.
1655 * sfc_mae_rule_process_pattern_data() will consider them
1656 * altogether when the rest of the items have been parsed.
1658 ethertypes[0].value = item_spec->type;
1659 ethertypes[0].mask = item_mask->type;
1660 if (item_mask->has_vlan) {
1661 pdata->has_ovlan_mask = B_TRUE;
1662 if (item_spec->has_vlan)
1663 pdata->has_ovlan_value = B_TRUE;
1667 * The specification is empty. The overall pattern
1668 * validity will be enforced at the end of parsing.
1669 * See sfc_mae_rule_process_pattern_data().
1674 return sfc_mae_parse_item(flocs_eth, RTE_DIM(flocs_eth), spec, mask,
1678 static const struct sfc_mae_field_locator flocs_vlan[] = {
1681 EFX_MAE_FIELD_VLAN0_TCI_BE,
1682 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, tci),
1683 offsetof(struct rte_flow_item_vlan, tci),
1687 * This locator is used only for building supported fields mask.
1688 * The field is handled by sfc_mae_rule_process_pattern_data().
1690 SFC_MAE_FIELD_HANDLING_DEFERRED,
1691 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, inner_type),
1692 offsetof(struct rte_flow_item_vlan, inner_type),
1697 EFX_MAE_FIELD_VLAN1_TCI_BE,
1698 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, tci),
1699 offsetof(struct rte_flow_item_vlan, tci),
1703 * This locator is used only for building supported fields mask.
1704 * The field is handled by sfc_mae_rule_process_pattern_data().
1706 SFC_MAE_FIELD_HANDLING_DEFERRED,
1707 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, inner_type),
1708 offsetof(struct rte_flow_item_vlan, inner_type),
1713 sfc_mae_rule_parse_item_vlan(const struct rte_flow_item *item,
1714 struct sfc_flow_parse_ctx *ctx,
1715 struct rte_flow_error *error)
1717 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1718 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
1719 boolean_t *has_vlan_mp_by_nb_tags[SFC_MAE_MATCH_VLAN_MAX_NTAGS] = {
1720 &pdata->has_ovlan_mask,
1721 &pdata->has_ivlan_mask,
1723 boolean_t *has_vlan_vp_by_nb_tags[SFC_MAE_MATCH_VLAN_MAX_NTAGS] = {
1724 &pdata->has_ovlan_value,
1725 &pdata->has_ivlan_value,
1727 boolean_t *cur_tag_presence_bit_mp;
1728 boolean_t *cur_tag_presence_bit_vp;
1729 const struct sfc_mae_field_locator *flocs;
1730 struct rte_flow_item_vlan supp_mask;
1731 const uint8_t *spec = NULL;
1732 const uint8_t *mask = NULL;
1733 unsigned int nb_flocs;
1736 RTE_BUILD_BUG_ON(SFC_MAE_MATCH_VLAN_MAX_NTAGS != 2);
1738 if (pdata->nb_vlan_tags == SFC_MAE_MATCH_VLAN_MAX_NTAGS) {
1739 return rte_flow_error_set(error, ENOTSUP,
1740 RTE_FLOW_ERROR_TYPE_ITEM, item,
1741 "Can't match that many VLAN tags");
1744 cur_tag_presence_bit_mp = has_vlan_mp_by_nb_tags[pdata->nb_vlan_tags];
1745 cur_tag_presence_bit_vp = has_vlan_vp_by_nb_tags[pdata->nb_vlan_tags];
1747 if (*cur_tag_presence_bit_mp == B_TRUE &&
1748 *cur_tag_presence_bit_vp == B_FALSE) {
1749 return rte_flow_error_set(error, EINVAL,
1750 RTE_FLOW_ERROR_TYPE_ITEM, item,
1751 "The previous item enforces no (more) VLAN, "
1752 "so the current item (VLAN) must not exist");
1755 nb_flocs = RTE_DIM(flocs_vlan) / SFC_MAE_MATCH_VLAN_MAX_NTAGS;
1756 flocs = flocs_vlan + pdata->nb_vlan_tags * nb_flocs;
1758 sfc_mae_item_build_supp_mask(flocs, nb_flocs,
1759 &supp_mask, sizeof(supp_mask));
1761 * This only means that the field is supported by the driver and libefx.
1762 * Support on NIC level will be checked when all items have been parsed.
1764 supp_mask.has_more_vlan = 1;
1766 rc = sfc_flow_parse_init(item,
1767 (const void **)&spec, (const void **)&mask,
1768 (const void *)&supp_mask,
1769 &rte_flow_item_vlan_mask,
1770 sizeof(struct rte_flow_item_vlan), error);
1775 struct sfc_mae_ethertype *et = pdata->ethertypes;
1776 const struct rte_flow_item_vlan *item_spec;
1777 const struct rte_flow_item_vlan *item_mask;
1779 item_spec = (const struct rte_flow_item_vlan *)spec;
1780 item_mask = (const struct rte_flow_item_vlan *)mask;
1783 * Remember various match criteria in the parsing context.
1784 * sfc_mae_rule_process_pattern_data() will consider them
1785 * altogether when the rest of the items have been parsed.
1787 et[pdata->nb_vlan_tags + 1].value = item_spec->inner_type;
1788 et[pdata->nb_vlan_tags + 1].mask = item_mask->inner_type;
1789 pdata->tci_masks[pdata->nb_vlan_tags] = item_mask->tci;
1790 if (item_mask->has_more_vlan) {
1791 if (pdata->nb_vlan_tags ==
1792 SFC_MAE_MATCH_VLAN_MAX_NTAGS) {
1793 return rte_flow_error_set(error, ENOTSUP,
1794 RTE_FLOW_ERROR_TYPE_ITEM, item,
1795 "Can't use 'has_more_vlan' in "
1796 "the second item VLAN");
1798 pdata->has_ivlan_mask = B_TRUE;
1799 if (item_spec->has_more_vlan)
1800 pdata->has_ivlan_value = B_TRUE;
1803 /* Convert TCI to MAE representation right now. */
1804 rc = sfc_mae_parse_item(flocs, nb_flocs, spec, mask,
1810 ++(pdata->nb_vlan_tags);
1815 static const struct sfc_mae_field_locator flocs_ipv4[] = {
1817 EFX_MAE_FIELD_SRC_IP4_BE,
1818 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.src_addr),
1819 offsetof(struct rte_flow_item_ipv4, hdr.src_addr),
1822 EFX_MAE_FIELD_DST_IP4_BE,
1823 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.dst_addr),
1824 offsetof(struct rte_flow_item_ipv4, hdr.dst_addr),
1828 * This locator is used only for building supported fields mask.
1829 * The field is handled by sfc_mae_rule_process_pattern_data().
1831 SFC_MAE_FIELD_HANDLING_DEFERRED,
1832 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.next_proto_id),
1833 offsetof(struct rte_flow_item_ipv4, hdr.next_proto_id),
1836 EFX_MAE_FIELD_IP_TOS,
1837 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4,
1838 hdr.type_of_service),
1839 offsetof(struct rte_flow_item_ipv4, hdr.type_of_service),
1842 EFX_MAE_FIELD_IP_TTL,
1843 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.time_to_live),
1844 offsetof(struct rte_flow_item_ipv4, hdr.time_to_live),
1849 sfc_mae_rule_parse_item_ipv4(const struct rte_flow_item *item,
1850 struct sfc_flow_parse_ctx *ctx,
1851 struct rte_flow_error *error)
1853 rte_be16_t ethertype_ipv4_be = RTE_BE16(RTE_ETHER_TYPE_IPV4);
1854 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1855 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
1856 struct rte_flow_item_ipv4 supp_mask;
1857 const uint8_t *spec = NULL;
1858 const uint8_t *mask = NULL;
1861 sfc_mae_item_build_supp_mask(flocs_ipv4, RTE_DIM(flocs_ipv4),
1862 &supp_mask, sizeof(supp_mask));
1864 rc = sfc_flow_parse_init(item,
1865 (const void **)&spec, (const void **)&mask,
1866 (const void *)&supp_mask,
1867 &rte_flow_item_ipv4_mask,
1868 sizeof(struct rte_flow_item_ipv4), error);
1872 pdata->innermost_ethertype_restriction.value = ethertype_ipv4_be;
1873 pdata->innermost_ethertype_restriction.mask = RTE_BE16(0xffff);
1876 const struct rte_flow_item_ipv4 *item_spec;
1877 const struct rte_flow_item_ipv4 *item_mask;
1879 item_spec = (const struct rte_flow_item_ipv4 *)spec;
1880 item_mask = (const struct rte_flow_item_ipv4 *)mask;
1882 pdata->l3_next_proto_value = item_spec->hdr.next_proto_id;
1883 pdata->l3_next_proto_mask = item_mask->hdr.next_proto_id;
1888 return sfc_mae_parse_item(flocs_ipv4, RTE_DIM(flocs_ipv4), spec, mask,
1892 static const struct sfc_mae_field_locator flocs_ipv6[] = {
1894 EFX_MAE_FIELD_SRC_IP6_BE,
1895 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.src_addr),
1896 offsetof(struct rte_flow_item_ipv6, hdr.src_addr),
1899 EFX_MAE_FIELD_DST_IP6_BE,
1900 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.dst_addr),
1901 offsetof(struct rte_flow_item_ipv6, hdr.dst_addr),
1905 * This locator is used only for building supported fields mask.
1906 * The field is handled by sfc_mae_rule_process_pattern_data().
1908 SFC_MAE_FIELD_HANDLING_DEFERRED,
1909 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.proto),
1910 offsetof(struct rte_flow_item_ipv6, hdr.proto),
1913 EFX_MAE_FIELD_IP_TTL,
1914 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.hop_limits),
1915 offsetof(struct rte_flow_item_ipv6, hdr.hop_limits),
1920 sfc_mae_rule_parse_item_ipv6(const struct rte_flow_item *item,
1921 struct sfc_flow_parse_ctx *ctx,
1922 struct rte_flow_error *error)
1924 rte_be16_t ethertype_ipv6_be = RTE_BE16(RTE_ETHER_TYPE_IPV6);
1925 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1926 const efx_mae_field_id_t *fremap = ctx_mae->field_ids_remap;
1927 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
1928 struct rte_flow_item_ipv6 supp_mask;
1929 const uint8_t *spec = NULL;
1930 const uint8_t *mask = NULL;
1931 rte_be32_t vtc_flow_be;
1937 sfc_mae_item_build_supp_mask(flocs_ipv6, RTE_DIM(flocs_ipv6),
1938 &supp_mask, sizeof(supp_mask));
1940 vtc_flow_be = RTE_BE32(RTE_IPV6_HDR_TC_MASK);
1941 memcpy(&supp_mask, &vtc_flow_be, sizeof(vtc_flow_be));
1943 rc = sfc_flow_parse_init(item,
1944 (const void **)&spec, (const void **)&mask,
1945 (const void *)&supp_mask,
1946 &rte_flow_item_ipv6_mask,
1947 sizeof(struct rte_flow_item_ipv6), error);
1951 pdata->innermost_ethertype_restriction.value = ethertype_ipv6_be;
1952 pdata->innermost_ethertype_restriction.mask = RTE_BE16(0xffff);
1955 const struct rte_flow_item_ipv6 *item_spec;
1956 const struct rte_flow_item_ipv6 *item_mask;
1958 item_spec = (const struct rte_flow_item_ipv6 *)spec;
1959 item_mask = (const struct rte_flow_item_ipv6 *)mask;
1961 pdata->l3_next_proto_value = item_spec->hdr.proto;
1962 pdata->l3_next_proto_mask = item_mask->hdr.proto;
1967 rc = sfc_mae_parse_item(flocs_ipv6, RTE_DIM(flocs_ipv6), spec, mask,
1972 memcpy(&vtc_flow_be, spec, sizeof(vtc_flow_be));
1973 vtc_flow = rte_be_to_cpu_32(vtc_flow_be);
1974 tc_value = (vtc_flow & RTE_IPV6_HDR_TC_MASK) >> RTE_IPV6_HDR_TC_SHIFT;
1976 memcpy(&vtc_flow_be, mask, sizeof(vtc_flow_be));
1977 vtc_flow = rte_be_to_cpu_32(vtc_flow_be);
1978 tc_mask = (vtc_flow & RTE_IPV6_HDR_TC_MASK) >> RTE_IPV6_HDR_TC_SHIFT;
1980 rc = efx_mae_match_spec_field_set(ctx_mae->match_spec,
1981 fremap[EFX_MAE_FIELD_IP_TOS],
1982 sizeof(tc_value), &tc_value,
1983 sizeof(tc_mask), &tc_mask);
1985 return rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM,
1986 NULL, "Failed to process item fields");
1992 static const struct sfc_mae_field_locator flocs_tcp[] = {
1994 EFX_MAE_FIELD_L4_SPORT_BE,
1995 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.src_port),
1996 offsetof(struct rte_flow_item_tcp, hdr.src_port),
1999 EFX_MAE_FIELD_L4_DPORT_BE,
2000 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.dst_port),
2001 offsetof(struct rte_flow_item_tcp, hdr.dst_port),
2004 EFX_MAE_FIELD_TCP_FLAGS_BE,
2006 * The values have been picked intentionally since the
2007 * target MAE field is oversize (16 bit). This mapping
2008 * relies on the fact that the MAE field is big-endian.
2010 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.data_off) +
2011 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.tcp_flags),
2012 offsetof(struct rte_flow_item_tcp, hdr.data_off),
2017 sfc_mae_rule_parse_item_tcp(const struct rte_flow_item *item,
2018 struct sfc_flow_parse_ctx *ctx,
2019 struct rte_flow_error *error)
2021 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
2022 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
2023 struct rte_flow_item_tcp supp_mask;
2024 const uint8_t *spec = NULL;
2025 const uint8_t *mask = NULL;
2029 * When encountered among outermost items, item TCP is invalid.
2030 * Check which match specification is being constructed now.
2032 if (ctx_mae->match_spec != ctx_mae->match_spec_action) {
2033 return rte_flow_error_set(error, EINVAL,
2034 RTE_FLOW_ERROR_TYPE_ITEM, item,
2035 "TCP in outer frame is invalid");
2038 sfc_mae_item_build_supp_mask(flocs_tcp, RTE_DIM(flocs_tcp),
2039 &supp_mask, sizeof(supp_mask));
2041 rc = sfc_flow_parse_init(item,
2042 (const void **)&spec, (const void **)&mask,
2043 (const void *)&supp_mask,
2044 &rte_flow_item_tcp_mask,
2045 sizeof(struct rte_flow_item_tcp), error);
2049 pdata->l3_next_proto_restriction_value = IPPROTO_TCP;
2050 pdata->l3_next_proto_restriction_mask = 0xff;
2055 return sfc_mae_parse_item(flocs_tcp, RTE_DIM(flocs_tcp), spec, mask,
2059 static const struct sfc_mae_field_locator flocs_udp[] = {
2061 EFX_MAE_FIELD_L4_SPORT_BE,
2062 RTE_SIZEOF_FIELD(struct rte_flow_item_udp, hdr.src_port),
2063 offsetof(struct rte_flow_item_udp, hdr.src_port),
2066 EFX_MAE_FIELD_L4_DPORT_BE,
2067 RTE_SIZEOF_FIELD(struct rte_flow_item_udp, hdr.dst_port),
2068 offsetof(struct rte_flow_item_udp, hdr.dst_port),
2073 sfc_mae_rule_parse_item_udp(const struct rte_flow_item *item,
2074 struct sfc_flow_parse_ctx *ctx,
2075 struct rte_flow_error *error)
2077 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
2078 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
2079 struct rte_flow_item_udp supp_mask;
2080 const uint8_t *spec = NULL;
2081 const uint8_t *mask = NULL;
2084 sfc_mae_item_build_supp_mask(flocs_udp, RTE_DIM(flocs_udp),
2085 &supp_mask, sizeof(supp_mask));
2087 rc = sfc_flow_parse_init(item,
2088 (const void **)&spec, (const void **)&mask,
2089 (const void *)&supp_mask,
2090 &rte_flow_item_udp_mask,
2091 sizeof(struct rte_flow_item_udp), error);
2095 pdata->l3_next_proto_restriction_value = IPPROTO_UDP;
2096 pdata->l3_next_proto_restriction_mask = 0xff;
2101 return sfc_mae_parse_item(flocs_udp, RTE_DIM(flocs_udp), spec, mask,
2105 static const struct sfc_mae_field_locator flocs_tunnel[] = {
2108 * The size and offset values are relevant
2109 * for Geneve and NVGRE, too.
2111 .size = RTE_SIZEOF_FIELD(struct rte_flow_item_vxlan, vni),
2112 .ofst = offsetof(struct rte_flow_item_vxlan, vni),
2117 * An auxiliary registry which allows using non-encap. field IDs
2118 * directly when building a match specification of type ACTION.
2120 * See sfc_mae_rule_parse_pattern() and sfc_mae_rule_parse_item_tunnel().
2122 static const efx_mae_field_id_t field_ids_no_remap[] = {
2123 #define FIELD_ID_NO_REMAP(_field) \
2124 [EFX_MAE_FIELD_##_field] = EFX_MAE_FIELD_##_field
2126 FIELD_ID_NO_REMAP(ETHER_TYPE_BE),
2127 FIELD_ID_NO_REMAP(ETH_SADDR_BE),
2128 FIELD_ID_NO_REMAP(ETH_DADDR_BE),
2129 FIELD_ID_NO_REMAP(VLAN0_TCI_BE),
2130 FIELD_ID_NO_REMAP(VLAN0_PROTO_BE),
2131 FIELD_ID_NO_REMAP(VLAN1_TCI_BE),
2132 FIELD_ID_NO_REMAP(VLAN1_PROTO_BE),
2133 FIELD_ID_NO_REMAP(SRC_IP4_BE),
2134 FIELD_ID_NO_REMAP(DST_IP4_BE),
2135 FIELD_ID_NO_REMAP(IP_PROTO),
2136 FIELD_ID_NO_REMAP(IP_TOS),
2137 FIELD_ID_NO_REMAP(IP_TTL),
2138 FIELD_ID_NO_REMAP(SRC_IP6_BE),
2139 FIELD_ID_NO_REMAP(DST_IP6_BE),
2140 FIELD_ID_NO_REMAP(L4_SPORT_BE),
2141 FIELD_ID_NO_REMAP(L4_DPORT_BE),
2142 FIELD_ID_NO_REMAP(TCP_FLAGS_BE),
2143 FIELD_ID_NO_REMAP(HAS_OVLAN),
2144 FIELD_ID_NO_REMAP(HAS_IVLAN),
2146 #undef FIELD_ID_NO_REMAP
2150 * An auxiliary registry which allows using "ENC" field IDs
2151 * when building a match specification of type OUTER.
2153 * See sfc_mae_rule_encap_parse_init().
2155 static const efx_mae_field_id_t field_ids_remap_to_encap[] = {
2156 #define FIELD_ID_REMAP_TO_ENCAP(_field) \
2157 [EFX_MAE_FIELD_##_field] = EFX_MAE_FIELD_ENC_##_field
2159 FIELD_ID_REMAP_TO_ENCAP(ETHER_TYPE_BE),
2160 FIELD_ID_REMAP_TO_ENCAP(ETH_SADDR_BE),
2161 FIELD_ID_REMAP_TO_ENCAP(ETH_DADDR_BE),
2162 FIELD_ID_REMAP_TO_ENCAP(VLAN0_TCI_BE),
2163 FIELD_ID_REMAP_TO_ENCAP(VLAN0_PROTO_BE),
2164 FIELD_ID_REMAP_TO_ENCAP(VLAN1_TCI_BE),
2165 FIELD_ID_REMAP_TO_ENCAP(VLAN1_PROTO_BE),
2166 FIELD_ID_REMAP_TO_ENCAP(SRC_IP4_BE),
2167 FIELD_ID_REMAP_TO_ENCAP(DST_IP4_BE),
2168 FIELD_ID_REMAP_TO_ENCAP(IP_PROTO),
2169 FIELD_ID_REMAP_TO_ENCAP(IP_TOS),
2170 FIELD_ID_REMAP_TO_ENCAP(IP_TTL),
2171 FIELD_ID_REMAP_TO_ENCAP(SRC_IP6_BE),
2172 FIELD_ID_REMAP_TO_ENCAP(DST_IP6_BE),
2173 FIELD_ID_REMAP_TO_ENCAP(L4_SPORT_BE),
2174 FIELD_ID_REMAP_TO_ENCAP(L4_DPORT_BE),
2175 FIELD_ID_REMAP_TO_ENCAP(HAS_OVLAN),
2176 FIELD_ID_REMAP_TO_ENCAP(HAS_IVLAN),
2178 #undef FIELD_ID_REMAP_TO_ENCAP
2182 sfc_mae_rule_parse_item_tunnel(const struct rte_flow_item *item,
2183 struct sfc_flow_parse_ctx *ctx,
2184 struct rte_flow_error *error)
2186 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
2187 uint8_t vnet_id_v[sizeof(uint32_t)] = {0};
2188 uint8_t vnet_id_m[sizeof(uint32_t)] = {0};
2189 const struct rte_flow_item_vxlan *vxp;
2190 uint8_t supp_mask[sizeof(uint64_t)];
2191 const uint8_t *spec = NULL;
2192 const uint8_t *mask = NULL;
2195 if (ctx_mae->ft_rule_type == SFC_FT_RULE_GROUP) {
2197 * As a workaround, pattern processing has started from
2198 * this (tunnel) item. No pattern data to process yet.
2202 * We're about to start processing inner frame items.
2203 * Process pattern data that has been deferred so far
2204 * and reset pattern data storage.
2206 rc = sfc_mae_rule_process_pattern_data(ctx_mae, error);
2211 memset(&ctx_mae->pattern_data, 0, sizeof(ctx_mae->pattern_data));
2213 sfc_mae_item_build_supp_mask(flocs_tunnel, RTE_DIM(flocs_tunnel),
2214 &supp_mask, sizeof(supp_mask));
2217 * This tunnel item was preliminarily detected by
2218 * sfc_mae_rule_encap_parse_init(). Default mask
2219 * was also picked by that helper. Use it here.
2221 rc = sfc_flow_parse_init(item,
2222 (const void **)&spec, (const void **)&mask,
2223 (const void *)&supp_mask,
2224 ctx_mae->tunnel_def_mask,
2225 ctx_mae->tunnel_def_mask_size, error);
2230 * This item and later ones comprise a
2231 * match specification of type ACTION.
2233 ctx_mae->match_spec = ctx_mae->match_spec_action;
2235 /* This item and later ones use non-encap. EFX MAE field IDs. */
2236 ctx_mae->field_ids_remap = field_ids_no_remap;
2242 * Field EFX_MAE_FIELD_ENC_VNET_ID_BE is a 32-bit one.
2243 * Copy 24-bit VNI, which is BE, at offset 1 in it.
2244 * The extra byte is 0 both in the mask and in the value.
2246 vxp = (const struct rte_flow_item_vxlan *)spec;
2247 memcpy(vnet_id_v + 1, &vxp->vni, sizeof(vxp->vni));
2249 vxp = (const struct rte_flow_item_vxlan *)mask;
2250 memcpy(vnet_id_m + 1, &vxp->vni, sizeof(vxp->vni));
2252 rc = efx_mae_match_spec_field_set(ctx_mae->match_spec,
2253 EFX_MAE_FIELD_ENC_VNET_ID_BE,
2254 sizeof(vnet_id_v), vnet_id_v,
2255 sizeof(vnet_id_m), vnet_id_m);
2257 rc = rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM,
2258 item, "Failed to set VXLAN VNI");
2264 static const struct sfc_flow_item sfc_flow_items[] = {
2266 .type = RTE_FLOW_ITEM_TYPE_MARK,
2268 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2269 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2270 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2271 .parse = sfc_mae_rule_parse_item_mark,
2274 .type = RTE_FLOW_ITEM_TYPE_PORT_ID,
2277 * In terms of RTE flow, this item is a META one,
2278 * and its position in the pattern is don't care.
2280 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2281 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2282 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2283 .parse = sfc_mae_rule_parse_item_port_id,
2286 .type = RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR,
2287 .name = "PORT_REPRESENTOR",
2289 * In terms of RTE flow, this item is a META one,
2290 * and its position in the pattern is don't care.
2292 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2293 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2294 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2295 .parse = sfc_mae_rule_parse_item_port_representor,
2298 .type = RTE_FLOW_ITEM_TYPE_PHY_PORT,
2301 * In terms of RTE flow, this item is a META one,
2302 * and its position in the pattern is don't care.
2304 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2305 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2306 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2307 .parse = sfc_mae_rule_parse_item_phy_port,
2310 .type = RTE_FLOW_ITEM_TYPE_PF,
2313 * In terms of RTE flow, this item is a META one,
2314 * and its position in the pattern is don't care.
2316 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2317 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2318 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2319 .parse = sfc_mae_rule_parse_item_pf,
2322 .type = RTE_FLOW_ITEM_TYPE_VF,
2325 * In terms of RTE flow, this item is a META one,
2326 * and its position in the pattern is don't care.
2328 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2329 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2330 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2331 .parse = sfc_mae_rule_parse_item_vf,
2334 .type = RTE_FLOW_ITEM_TYPE_ETH,
2336 .prev_layer = SFC_FLOW_ITEM_START_LAYER,
2337 .layer = SFC_FLOW_ITEM_L2,
2338 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2339 .parse = sfc_mae_rule_parse_item_eth,
2342 .type = RTE_FLOW_ITEM_TYPE_VLAN,
2344 .prev_layer = SFC_FLOW_ITEM_L2,
2345 .layer = SFC_FLOW_ITEM_L2,
2346 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2347 .parse = sfc_mae_rule_parse_item_vlan,
2350 .type = RTE_FLOW_ITEM_TYPE_IPV4,
2352 .prev_layer = SFC_FLOW_ITEM_L2,
2353 .layer = SFC_FLOW_ITEM_L3,
2354 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2355 .parse = sfc_mae_rule_parse_item_ipv4,
2358 .type = RTE_FLOW_ITEM_TYPE_IPV6,
2360 .prev_layer = SFC_FLOW_ITEM_L2,
2361 .layer = SFC_FLOW_ITEM_L3,
2362 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2363 .parse = sfc_mae_rule_parse_item_ipv6,
2366 .type = RTE_FLOW_ITEM_TYPE_TCP,
2368 .prev_layer = SFC_FLOW_ITEM_L3,
2369 .layer = SFC_FLOW_ITEM_L4,
2370 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2371 .parse = sfc_mae_rule_parse_item_tcp,
2374 .type = RTE_FLOW_ITEM_TYPE_UDP,
2376 .prev_layer = SFC_FLOW_ITEM_L3,
2377 .layer = SFC_FLOW_ITEM_L4,
2378 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2379 .parse = sfc_mae_rule_parse_item_udp,
2382 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
2384 .prev_layer = SFC_FLOW_ITEM_L4,
2385 .layer = SFC_FLOW_ITEM_START_LAYER,
2386 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2387 .parse = sfc_mae_rule_parse_item_tunnel,
2390 .type = RTE_FLOW_ITEM_TYPE_GENEVE,
2392 .prev_layer = SFC_FLOW_ITEM_L4,
2393 .layer = SFC_FLOW_ITEM_START_LAYER,
2394 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2395 .parse = sfc_mae_rule_parse_item_tunnel,
2398 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
2400 .prev_layer = SFC_FLOW_ITEM_L3,
2401 .layer = SFC_FLOW_ITEM_START_LAYER,
2402 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2403 .parse = sfc_mae_rule_parse_item_tunnel,
2408 sfc_mae_rule_process_outer(struct sfc_adapter *sa,
2409 struct sfc_mae_parse_ctx *ctx,
2410 struct sfc_mae_outer_rule **rulep,
2411 struct rte_flow_error *error)
2413 efx_mae_rule_id_t invalid_rule_id = { .id = EFX_MAE_RSRC_ID_INVALID };
2416 if (ctx->encap_type == EFX_TUNNEL_PROTOCOL_NONE) {
2421 SFC_ASSERT(ctx->match_spec_outer != NULL);
2423 if (!efx_mae_match_spec_is_valid(sa->nic, ctx->match_spec_outer)) {
2424 return rte_flow_error_set(error, ENOTSUP,
2425 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2426 "Inconsistent pattern (outer)");
2429 *rulep = sfc_mae_outer_rule_attach(sa, ctx->match_spec_outer,
2431 if (*rulep != NULL) {
2432 efx_mae_match_spec_fini(sa->nic, ctx->match_spec_outer);
2434 rc = sfc_mae_outer_rule_add(sa, ctx->match_spec_outer,
2435 ctx->encap_type, rulep);
2437 return rte_flow_error_set(error, rc,
2438 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2439 "Failed to process the pattern");
2443 /* The spec has now been tracked by the outer rule entry. */
2444 ctx->match_spec_outer = NULL;
2447 switch (ctx->ft_rule_type) {
2448 case SFC_FT_RULE_NONE:
2450 case SFC_FT_RULE_JUMP:
2451 /* No action rule */
2453 case SFC_FT_RULE_GROUP:
2455 * Match on recirculation ID rather than
2456 * on the outer rule allocation handle.
2458 rc = efx_mae_match_spec_recirc_id_set(ctx->match_spec_action,
2459 SFC_FT_ID_TO_TUNNEL_MARK(ctx->ft->id));
2461 return rte_flow_error_set(error, rc,
2462 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2463 "tunnel offload: GROUP: AR: failed to request match on RECIRC_ID");
2467 SFC_ASSERT(B_FALSE);
2471 * In MAE, lookup sequence comprises outer parse, outer rule lookup,
2472 * inner parse (when some outer rule is hit) and action rule lookup.
2473 * If the currently processed flow does not come with an outer rule,
2474 * its action rule must be available only for packets which miss in
2475 * outer rule table. Set OR_ID match field to 0xffffffff/0xffffffff
2476 * in the action rule specification; this ensures correct behaviour.
2478 * If, on the other hand, this flow does have an outer rule, its ID
2479 * may be unknown at the moment (not yet allocated), but OR_ID mask
2480 * has to be set to 0xffffffff anyway for correct class comparisons.
2481 * When the outer rule has been allocated, this match field will be
2482 * overridden by sfc_mae_outer_rule_enable() to use the right value.
2484 rc = efx_mae_match_spec_outer_rule_id_set(ctx->match_spec_action,
2488 sfc_mae_outer_rule_del(sa, *rulep);
2492 return rte_flow_error_set(error, rc,
2493 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2494 "Failed to process the pattern");
2501 sfc_mae_rule_preparse_item_mark(const struct rte_flow_item_mark *spec,
2502 struct sfc_mae_parse_ctx *ctx)
2504 struct sfc_flow_tunnel *ft;
2508 sfc_err(ctx->sa, "tunnel offload: GROUP: NULL spec in item MARK");
2512 ft = sfc_flow_tunnel_pick(ctx->sa, spec->id);
2514 sfc_err(ctx->sa, "tunnel offload: GROUP: invalid tunnel");
2518 if (ft->refcnt == 0) {
2519 sfc_err(ctx->sa, "tunnel offload: GROUP: tunnel=%u does not exist",
2524 user_mark = SFC_FT_GET_USER_MARK(spec->id);
2525 if (user_mark != 0) {
2526 sfc_err(ctx->sa, "tunnel offload: GROUP: invalid item MARK");
2530 sfc_dbg(ctx->sa, "tunnel offload: GROUP: detected");
2532 ctx->ft_rule_type = SFC_FT_RULE_GROUP;
2539 sfc_mae_rule_encap_parse_init(struct sfc_adapter *sa,
2540 struct sfc_mae_parse_ctx *ctx,
2541 struct rte_flow_error *error)
2543 const struct rte_flow_item *pattern = ctx->pattern;
2544 struct sfc_mae *mae = &sa->mae;
2545 uint8_t recirc_id = 0;
2548 if (pattern == NULL) {
2549 rte_flow_error_set(error, EINVAL,
2550 RTE_FLOW_ERROR_TYPE_ITEM_NUM, NULL,
2556 switch (pattern->type) {
2557 case RTE_FLOW_ITEM_TYPE_MARK:
2558 rc = sfc_mae_rule_preparse_item_mark(pattern->spec,
2561 return rte_flow_error_set(error, rc,
2562 RTE_FLOW_ERROR_TYPE_ITEM,
2563 pattern, "tunnel offload: GROUP: invalid item MARK");
2567 case RTE_FLOW_ITEM_TYPE_VXLAN:
2568 ctx->encap_type = EFX_TUNNEL_PROTOCOL_VXLAN;
2569 ctx->tunnel_def_mask = &rte_flow_item_vxlan_mask;
2570 ctx->tunnel_def_mask_size =
2571 sizeof(rte_flow_item_vxlan_mask);
2573 case RTE_FLOW_ITEM_TYPE_GENEVE:
2574 ctx->encap_type = EFX_TUNNEL_PROTOCOL_GENEVE;
2575 ctx->tunnel_def_mask = &rte_flow_item_geneve_mask;
2576 ctx->tunnel_def_mask_size =
2577 sizeof(rte_flow_item_geneve_mask);
2579 case RTE_FLOW_ITEM_TYPE_NVGRE:
2580 ctx->encap_type = EFX_TUNNEL_PROTOCOL_NVGRE;
2581 ctx->tunnel_def_mask = &rte_flow_item_nvgre_mask;
2582 ctx->tunnel_def_mask_size =
2583 sizeof(rte_flow_item_nvgre_mask);
2585 case RTE_FLOW_ITEM_TYPE_END:
2595 switch (ctx->ft_rule_type) {
2596 case SFC_FT_RULE_NONE:
2597 if (pattern->type == RTE_FLOW_ITEM_TYPE_END)
2600 case SFC_FT_RULE_JUMP:
2601 if (pattern->type != RTE_FLOW_ITEM_TYPE_END) {
2602 return rte_flow_error_set(error, ENOTSUP,
2603 RTE_FLOW_ERROR_TYPE_ITEM,
2604 pattern, "tunnel offload: JUMP: invalid item");
2606 ctx->encap_type = ctx->ft->encap_type;
2608 case SFC_FT_RULE_GROUP:
2609 if (pattern->type == RTE_FLOW_ITEM_TYPE_END) {
2610 return rte_flow_error_set(error, EINVAL,
2611 RTE_FLOW_ERROR_TYPE_ITEM,
2612 NULL, "tunnel offload: GROUP: missing tunnel item");
2613 } else if (ctx->encap_type != ctx->ft->encap_type) {
2614 return rte_flow_error_set(error, EINVAL,
2615 RTE_FLOW_ERROR_TYPE_ITEM,
2616 pattern, "tunnel offload: GROUP: tunnel type mismatch");
2620 * The HW/FW hasn't got support for the use of "ENC" fields in
2621 * action rules (except the VNET_ID one) yet. As a workaround,
2622 * start parsing the pattern from the tunnel item.
2624 ctx->pattern = pattern;
2627 SFC_ASSERT(B_FALSE);
2631 if ((mae->encap_types_supported & (1U << ctx->encap_type)) == 0) {
2632 return rte_flow_error_set(error, ENOTSUP,
2633 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2634 "OR: unsupported tunnel type");
2637 switch (ctx->ft_rule_type) {
2638 case SFC_FT_RULE_JUMP:
2639 recirc_id = SFC_FT_ID_TO_TUNNEL_MARK(ctx->ft->id);
2641 case SFC_FT_RULE_NONE:
2642 if (ctx->priority >= mae->nb_outer_rule_prios_max) {
2643 return rte_flow_error_set(error, ENOTSUP,
2644 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
2645 NULL, "OR: unsupported priority level");
2648 rc = efx_mae_match_spec_init(sa->nic,
2649 EFX_MAE_RULE_OUTER, ctx->priority,
2650 &ctx->match_spec_outer);
2652 return rte_flow_error_set(error, rc,
2653 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2654 "OR: failed to initialise the match specification");
2658 * Outermost items comprise a match
2659 * specification of type OUTER.
2661 ctx->match_spec = ctx->match_spec_outer;
2663 /* Outermost items use "ENC" EFX MAE field IDs. */
2664 ctx->field_ids_remap = field_ids_remap_to_encap;
2666 rc = efx_mae_outer_rule_recirc_id_set(ctx->match_spec,
2669 return rte_flow_error_set(error, rc,
2670 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2671 "OR: failed to initialise RECIRC_ID");
2674 case SFC_FT_RULE_GROUP:
2675 /* Outermost items -> "ENC" match fields in the action rule. */
2676 ctx->field_ids_remap = field_ids_remap_to_encap;
2677 ctx->match_spec = ctx->match_spec_action;
2679 /* No own outer rule; match on JUMP OR's RECIRC_ID is used. */
2680 ctx->encap_type = EFX_TUNNEL_PROTOCOL_NONE;
2683 SFC_ASSERT(B_FALSE);
2691 sfc_mae_rule_encap_parse_fini(struct sfc_adapter *sa,
2692 struct sfc_mae_parse_ctx *ctx)
2694 if (ctx->encap_type == EFX_TUNNEL_PROTOCOL_NONE)
2697 if (ctx->match_spec_outer != NULL)
2698 efx_mae_match_spec_fini(sa->nic, ctx->match_spec_outer);
2702 sfc_mae_rule_parse_pattern(struct sfc_adapter *sa,
2703 const struct rte_flow_item pattern[],
2704 struct sfc_flow_spec_mae *spec,
2705 struct rte_flow_error *error)
2707 struct sfc_mae_parse_ctx ctx_mae;
2708 unsigned int priority_shift = 0;
2709 struct sfc_flow_parse_ctx ctx;
2712 memset(&ctx_mae, 0, sizeof(ctx_mae));
2713 ctx_mae.ft_rule_type = spec->ft_rule_type;
2714 ctx_mae.priority = spec->priority;
2715 ctx_mae.ft = spec->ft;
2718 switch (ctx_mae.ft_rule_type) {
2719 case SFC_FT_RULE_JUMP:
2721 * By design, this flow should be represented solely by the
2722 * outer rule. But the HW/FW hasn't got support for setting
2723 * Rx mark from RECIRC_ID on outer rule lookup yet. Neither
2724 * does it support outer rule counters. As a workaround, an
2725 * action rule of lower priority is used to do the job.
2730 case SFC_FT_RULE_GROUP:
2731 if (ctx_mae.priority != 0) {
2733 * Because of the above workaround, deny the
2734 * use of priorities to JUMP and GROUP rules.
2736 rc = rte_flow_error_set(error, ENOTSUP,
2737 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, NULL,
2738 "tunnel offload: priorities are not supported");
2739 goto fail_priority_check;
2743 case SFC_FT_RULE_NONE:
2744 rc = efx_mae_match_spec_init(sa->nic, EFX_MAE_RULE_ACTION,
2745 spec->priority + priority_shift,
2746 &ctx_mae.match_spec_action);
2748 rc = rte_flow_error_set(error, rc,
2749 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2750 "AR: failed to initialise the match specification");
2751 goto fail_init_match_spec_action;
2755 SFC_ASSERT(B_FALSE);
2760 * As a preliminary setting, assume that there is no encapsulation
2761 * in the pattern. That is, pattern items are about to comprise a
2762 * match specification of type ACTION and use non-encap. field IDs.
2764 * sfc_mae_rule_encap_parse_init() below may override this.
2766 ctx_mae.encap_type = EFX_TUNNEL_PROTOCOL_NONE;
2767 ctx_mae.match_spec = ctx_mae.match_spec_action;
2768 ctx_mae.field_ids_remap = field_ids_no_remap;
2769 ctx_mae.pattern = pattern;
2771 ctx.type = SFC_FLOW_PARSE_CTX_MAE;
2774 rc = sfc_mae_rule_encap_parse_init(sa, &ctx_mae, error);
2776 goto fail_encap_parse_init;
2779 * sfc_mae_rule_encap_parse_init() may have detected tunnel offload
2780 * GROUP rule. Remember its properties for later use.
2782 spec->ft_rule_type = ctx_mae.ft_rule_type;
2783 spec->ft = ctx_mae.ft;
2785 rc = sfc_flow_parse_pattern(sa, sfc_flow_items, RTE_DIM(sfc_flow_items),
2786 ctx_mae.pattern, &ctx, error);
2788 goto fail_parse_pattern;
2790 rc = sfc_mae_rule_process_pattern_data(&ctx_mae, error);
2792 goto fail_process_pattern_data;
2794 rc = sfc_mae_rule_process_outer(sa, &ctx_mae, &spec->outer_rule, error);
2796 goto fail_process_outer;
2798 if (ctx_mae.match_spec_action != NULL &&
2799 !efx_mae_match_spec_is_valid(sa->nic, ctx_mae.match_spec_action)) {
2800 rc = rte_flow_error_set(error, ENOTSUP,
2801 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2802 "Inconsistent pattern");
2803 goto fail_validate_match_spec_action;
2806 spec->match_spec = ctx_mae.match_spec_action;
2810 fail_validate_match_spec_action:
2812 fail_process_pattern_data:
2814 sfc_mae_rule_encap_parse_fini(sa, &ctx_mae);
2816 fail_encap_parse_init:
2817 if (ctx_mae.match_spec_action != NULL)
2818 efx_mae_match_spec_fini(sa->nic, ctx_mae.match_spec_action);
2820 fail_init_match_spec_action:
2821 fail_priority_check:
2826 * An action supported by MAE may correspond to a bundle of RTE flow actions,
2827 * in example, VLAN_PUSH = OF_PUSH_VLAN + OF_VLAN_SET_VID + OF_VLAN_SET_PCP.
2828 * That is, related RTE flow actions need to be tracked as parts of a whole
2829 * so that they can be combined into a single action and submitted to MAE
2830 * representation of a given rule's action set.
2832 * Each RTE flow action provided by an application gets classified as
2833 * one belonging to some bundle type. If an action is not supposed to
2834 * belong to any bundle, or if this action is END, it is described as
2835 * one belonging to a dummy bundle of type EMPTY.
2837 * A currently tracked bundle will be submitted if a repeating
2838 * action or an action of different bundle type follows.
2841 enum sfc_mae_actions_bundle_type {
2842 SFC_MAE_ACTIONS_BUNDLE_EMPTY = 0,
2843 SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH,
2846 struct sfc_mae_actions_bundle {
2847 enum sfc_mae_actions_bundle_type type;
2849 /* Indicates actions already tracked by the current bundle */
2850 uint64_t actions_mask;
2852 /* Parameters used by SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH */
2853 rte_be16_t vlan_push_tpid;
2854 rte_be16_t vlan_push_tci;
2858 * Combine configuration of RTE flow actions tracked by the bundle into a
2859 * single action and submit the result to MAE action set specification.
2860 * Do nothing in the case of dummy action bundle.
2863 sfc_mae_actions_bundle_submit(const struct sfc_mae_actions_bundle *bundle,
2864 efx_mae_actions_t *spec)
2868 switch (bundle->type) {
2869 case SFC_MAE_ACTIONS_BUNDLE_EMPTY:
2871 case SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH:
2872 rc = efx_mae_action_set_populate_vlan_push(
2873 spec, bundle->vlan_push_tpid, bundle->vlan_push_tci);
2876 SFC_ASSERT(B_FALSE);
2884 * Given the type of the next RTE flow action in the line, decide
2885 * whether a new bundle is about to start, and, if this is the case,
2886 * submit and reset the current bundle.
2889 sfc_mae_actions_bundle_sync(const struct rte_flow_action *action,
2890 struct sfc_mae_actions_bundle *bundle,
2891 efx_mae_actions_t *spec,
2892 struct rte_flow_error *error)
2894 enum sfc_mae_actions_bundle_type bundle_type_new;
2897 switch (action->type) {
2898 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
2899 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
2900 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
2901 bundle_type_new = SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH;
2905 * Self-sufficient actions, including END, are handled in this
2906 * case. No checks for unsupported actions are needed here
2907 * because parsing doesn't occur at this point.
2909 bundle_type_new = SFC_MAE_ACTIONS_BUNDLE_EMPTY;
2913 if (bundle_type_new != bundle->type ||
2914 (bundle->actions_mask & (1ULL << action->type)) != 0) {
2915 rc = sfc_mae_actions_bundle_submit(bundle, spec);
2919 memset(bundle, 0, sizeof(*bundle));
2922 bundle->type = bundle_type_new;
2927 return rte_flow_error_set(error, rc,
2928 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2929 "Failed to request the (group of) action(s)");
2933 sfc_mae_rule_parse_action_of_push_vlan(
2934 const struct rte_flow_action_of_push_vlan *conf,
2935 struct sfc_mae_actions_bundle *bundle)
2937 bundle->vlan_push_tpid = conf->ethertype;
2941 sfc_mae_rule_parse_action_of_set_vlan_vid(
2942 const struct rte_flow_action_of_set_vlan_vid *conf,
2943 struct sfc_mae_actions_bundle *bundle)
2945 bundle->vlan_push_tci |= (conf->vlan_vid &
2946 rte_cpu_to_be_16(RTE_LEN2MASK(12, uint16_t)));
2950 sfc_mae_rule_parse_action_of_set_vlan_pcp(
2951 const struct rte_flow_action_of_set_vlan_pcp *conf,
2952 struct sfc_mae_actions_bundle *bundle)
2954 uint16_t vlan_tci_pcp = (uint16_t)(conf->vlan_pcp &
2955 RTE_LEN2MASK(3, uint8_t)) << 13;
2957 bundle->vlan_push_tci |= rte_cpu_to_be_16(vlan_tci_pcp);
2960 struct sfc_mae_parsed_item {
2961 const struct rte_flow_item *item;
2962 size_t proto_header_ofst;
2963 size_t proto_header_size;
2967 * For each 16-bit word of the given header, override
2968 * bits enforced by the corresponding 16-bit mask.
2971 sfc_mae_header_force_item_masks(uint8_t *header_buf,
2972 const struct sfc_mae_parsed_item *parsed_items,
2973 unsigned int nb_parsed_items)
2975 unsigned int item_idx;
2977 for (item_idx = 0; item_idx < nb_parsed_items; ++item_idx) {
2978 const struct sfc_mae_parsed_item *parsed_item;
2979 const struct rte_flow_item *item;
2980 size_t proto_header_size;
2983 parsed_item = &parsed_items[item_idx];
2984 proto_header_size = parsed_item->proto_header_size;
2985 item = parsed_item->item;
2987 for (ofst = 0; ofst < proto_header_size;
2988 ofst += sizeof(rte_be16_t)) {
2989 rte_be16_t *wp = RTE_PTR_ADD(header_buf, ofst);
2990 const rte_be16_t *w_maskp;
2991 const rte_be16_t *w_specp;
2993 w_maskp = RTE_PTR_ADD(item->mask, ofst);
2994 w_specp = RTE_PTR_ADD(item->spec, ofst);
2997 *wp |= (*w_specp & *w_maskp);
3000 header_buf += proto_header_size;
3004 #define SFC_IPV4_TTL_DEF 0x40
3005 #define SFC_IPV6_VTC_FLOW_DEF 0x60000000
3006 #define SFC_IPV6_HOP_LIMITS_DEF 0xff
3007 #define SFC_VXLAN_FLAGS_DEF 0x08000000
3010 sfc_mae_rule_parse_action_vxlan_encap(
3011 struct sfc_mae *mae,
3012 const struct rte_flow_action_vxlan_encap *conf,
3013 efx_mae_actions_t *spec,
3014 struct rte_flow_error *error)
3016 struct sfc_mae_bounce_eh *bounce_eh = &mae->bounce_eh;
3017 struct rte_flow_item *pattern = conf->definition;
3018 uint8_t *buf = bounce_eh->buf;
3020 /* This array will keep track of non-VOID pattern items. */
3021 struct sfc_mae_parsed_item parsed_items[1 /* Ethernet */ +
3023 1 /* IPv4 or IPv6 */ +
3026 unsigned int nb_parsed_items = 0;
3028 size_t eth_ethertype_ofst = offsetof(struct rte_ether_hdr, ether_type);
3029 uint8_t dummy_buf[RTE_MAX(sizeof(struct rte_ipv4_hdr),
3030 sizeof(struct rte_ipv6_hdr))];
3031 struct rte_ipv4_hdr *ipv4 = (void *)dummy_buf;
3032 struct rte_ipv6_hdr *ipv6 = (void *)dummy_buf;
3033 struct rte_vxlan_hdr *vxlan = NULL;
3034 struct rte_udp_hdr *udp = NULL;
3035 unsigned int nb_vlan_tags = 0;
3036 size_t next_proto_ofst = 0;
3037 size_t ethertype_ofst = 0;
3041 if (pattern == NULL) {
3042 return rte_flow_error_set(error, EINVAL,
3043 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3044 "The encap. header definition is NULL");
3047 bounce_eh->type = EFX_TUNNEL_PROTOCOL_VXLAN;
3048 bounce_eh->size = 0;
3051 * Process pattern items and remember non-VOID ones.
3052 * Defer applying masks until after the complete header
3053 * has been built from the pattern items.
3055 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_ETH);
3057 for (; pattern->type != RTE_FLOW_ITEM_TYPE_END; ++pattern) {
3058 struct sfc_mae_parsed_item *parsed_item;
3059 const uint64_t exp_items_extra_vlan[] = {
3060 RTE_BIT64(RTE_FLOW_ITEM_TYPE_VLAN), 0
3062 size_t proto_header_size;
3063 rte_be16_t *ethertypep;
3064 uint8_t *next_protop;
3067 if (pattern->spec == NULL) {
3068 return rte_flow_error_set(error, EINVAL,
3069 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3070 "NULL item spec in the encap. header");
3073 if (pattern->mask == NULL) {
3074 return rte_flow_error_set(error, EINVAL,
3075 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3076 "NULL item mask in the encap. header");
3079 if (pattern->last != NULL) {
3080 /* This is not a match pattern, so disallow range. */
3081 return rte_flow_error_set(error, EINVAL,
3082 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3083 "Range item in the encap. header");
3086 if (pattern->type == RTE_FLOW_ITEM_TYPE_VOID) {
3087 /* Handle VOID separately, for clarity. */
3091 if ((exp_items & RTE_BIT64(pattern->type)) == 0) {
3092 return rte_flow_error_set(error, ENOTSUP,
3093 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3094 "Unexpected item in the encap. header");
3097 parsed_item = &parsed_items[nb_parsed_items];
3098 buf_cur = buf + bounce_eh->size;
3100 switch (pattern->type) {
3101 case RTE_FLOW_ITEM_TYPE_ETH:
3102 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_ETH,
3104 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_eth,
3107 proto_header_size = sizeof(struct rte_ether_hdr);
3109 ethertype_ofst = eth_ethertype_ofst;
3111 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_VLAN) |
3112 RTE_BIT64(RTE_FLOW_ITEM_TYPE_IPV4) |
3113 RTE_BIT64(RTE_FLOW_ITEM_TYPE_IPV6);
3115 case RTE_FLOW_ITEM_TYPE_VLAN:
3116 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_VLAN,
3118 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_vlan,
3121 proto_header_size = sizeof(struct rte_vlan_hdr);
3123 ethertypep = RTE_PTR_ADD(buf, eth_ethertype_ofst);
3124 *ethertypep = RTE_BE16(RTE_ETHER_TYPE_QINQ);
3126 ethertypep = RTE_PTR_ADD(buf, ethertype_ofst);
3127 *ethertypep = RTE_BE16(RTE_ETHER_TYPE_VLAN);
3131 offsetof(struct rte_vlan_hdr, eth_proto);
3133 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_IPV4) |
3134 RTE_BIT64(RTE_FLOW_ITEM_TYPE_IPV6);
3135 exp_items |= exp_items_extra_vlan[nb_vlan_tags];
3139 case RTE_FLOW_ITEM_TYPE_IPV4:
3140 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_IPV4,
3142 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_ipv4,
3145 proto_header_size = sizeof(struct rte_ipv4_hdr);
3147 ethertypep = RTE_PTR_ADD(buf, ethertype_ofst);
3148 *ethertypep = RTE_BE16(RTE_ETHER_TYPE_IPV4);
3152 offsetof(struct rte_ipv4_hdr, next_proto_id);
3154 ipv4 = (struct rte_ipv4_hdr *)buf_cur;
3156 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_UDP);
3158 case RTE_FLOW_ITEM_TYPE_IPV6:
3159 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_IPV6,
3161 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_ipv6,
3164 proto_header_size = sizeof(struct rte_ipv6_hdr);
3166 ethertypep = RTE_PTR_ADD(buf, ethertype_ofst);
3167 *ethertypep = RTE_BE16(RTE_ETHER_TYPE_IPV6);
3169 next_proto_ofst = bounce_eh->size +
3170 offsetof(struct rte_ipv6_hdr, proto);
3172 ipv6 = (struct rte_ipv6_hdr *)buf_cur;
3174 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_UDP);
3176 case RTE_FLOW_ITEM_TYPE_UDP:
3177 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_UDP,
3179 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_udp,
3182 proto_header_size = sizeof(struct rte_udp_hdr);
3184 next_protop = RTE_PTR_ADD(buf, next_proto_ofst);
3185 *next_protop = IPPROTO_UDP;
3187 udp = (struct rte_udp_hdr *)buf_cur;
3189 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_VXLAN);
3191 case RTE_FLOW_ITEM_TYPE_VXLAN:
3192 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_VXLAN,
3194 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_vxlan,
3197 proto_header_size = sizeof(struct rte_vxlan_hdr);
3199 vxlan = (struct rte_vxlan_hdr *)buf_cur;
3201 udp->dst_port = RTE_BE16(RTE_VXLAN_DEFAULT_PORT);
3202 udp->dgram_len = RTE_BE16(sizeof(*udp) +
3204 udp->dgram_cksum = 0;
3209 return rte_flow_error_set(error, ENOTSUP,
3210 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3211 "Unknown item in the encap. header");
3214 if (bounce_eh->size + proto_header_size > bounce_eh->buf_size) {
3215 return rte_flow_error_set(error, E2BIG,
3216 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3217 "The encap. header is too big");
3220 if ((proto_header_size & 1) != 0) {
3221 return rte_flow_error_set(error, EINVAL,
3222 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3223 "Odd layer size in the encap. header");
3226 rte_memcpy(buf_cur, pattern->spec, proto_header_size);
3227 bounce_eh->size += proto_header_size;
3229 parsed_item->item = pattern;
3230 parsed_item->proto_header_size = proto_header_size;
3234 if (exp_items != 0) {
3235 /* Parsing item VXLAN would have reset exp_items to 0. */
3236 return rte_flow_error_set(error, ENOTSUP,
3237 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3238 "No item VXLAN in the encap. header");
3241 /* One of the pointers (ipv4, ipv6) refers to a dummy area. */
3242 ipv4->version_ihl = RTE_IPV4_VHL_DEF;
3243 ipv4->time_to_live = SFC_IPV4_TTL_DEF;
3244 ipv4->total_length = RTE_BE16(sizeof(*ipv4) + sizeof(*udp) +
3246 /* The HW cannot compute this checksum. */
3247 ipv4->hdr_checksum = 0;
3248 ipv4->hdr_checksum = rte_ipv4_cksum(ipv4);
3250 ipv6->vtc_flow = RTE_BE32(SFC_IPV6_VTC_FLOW_DEF);
3251 ipv6->hop_limits = SFC_IPV6_HOP_LIMITS_DEF;
3252 ipv6->payload_len = udp->dgram_len;
3254 vxlan->vx_flags = RTE_BE32(SFC_VXLAN_FLAGS_DEF);
3256 /* Take care of the masks. */
3257 sfc_mae_header_force_item_masks(buf, parsed_items, nb_parsed_items);
3259 rc = efx_mae_action_set_populate_encap(spec);
3261 rc = rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ACTION,
3262 NULL, "failed to request action ENCAP");
3269 sfc_mae_rule_parse_action_mark(struct sfc_adapter *sa,
3270 const struct rte_flow_action_mark *conf,
3271 const struct sfc_flow_spec_mae *spec_mae,
3272 efx_mae_actions_t *spec)
3276 if (spec_mae->ft_rule_type == SFC_FT_RULE_JUMP) {
3277 /* Workaround. See sfc_flow_parse_rte_to_mae() */
3278 } else if (conf->id > SFC_FT_USER_MARK_MASK) {
3279 sfc_err(sa, "the mark value is too large");
3283 rc = efx_mae_action_set_populate_mark(spec, conf->id);
3285 sfc_err(sa, "failed to request action MARK: %s", strerror(rc));
3291 sfc_mae_rule_parse_action_count(struct sfc_adapter *sa,
3292 const struct rte_flow_action_count *conf
3294 efx_mae_actions_t *spec)
3298 if ((sa->counter_rxq.state & SFC_COUNTER_RXQ_INITIALIZED) == 0) {
3300 "counter queue is not configured for COUNT action");
3302 goto fail_counter_queue_uninit;
3305 if (sfc_get_service_lcore(SOCKET_ID_ANY) == RTE_MAX_LCORE) {
3307 goto fail_no_service_core;
3310 rc = efx_mae_action_set_populate_count(spec);
3313 "failed to populate counters in MAE action set: %s",
3315 goto fail_populate_count;
3320 fail_populate_count:
3321 fail_no_service_core:
3322 fail_counter_queue_uninit:
3328 sfc_mae_rule_parse_action_phy_port(struct sfc_adapter *sa,
3329 const struct rte_flow_action_phy_port *conf,
3330 efx_mae_actions_t *spec)
3332 efx_mport_sel_t mport;
3336 if (conf->original != 0)
3337 phy_port = efx_nic_cfg_get(sa->nic)->enc_assigned_port;
3339 phy_port = conf->index;
3341 rc = efx_mae_mport_by_phy_port(phy_port, &mport);
3343 sfc_err(sa, "failed to convert phys. port ID %u to m-port selector: %s",
3344 phy_port, strerror(rc));
3348 rc = efx_mae_action_set_populate_deliver(spec, &mport);
3350 sfc_err(sa, "failed to request action DELIVER with m-port selector 0x%08x: %s",
3351 mport.sel, strerror(rc));
3358 sfc_mae_rule_parse_action_pf_vf(struct sfc_adapter *sa,
3359 const struct rte_flow_action_vf *vf_conf,
3360 efx_mae_actions_t *spec)
3362 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
3363 efx_mport_sel_t mport;
3367 if (vf_conf == NULL)
3368 vf = EFX_PCI_VF_INVALID;
3369 else if (vf_conf->original != 0)
3374 rc = efx_mae_mport_by_pcie_function(encp->enc_pf, vf, &mport);
3376 sfc_err(sa, "failed to convert PF %u VF %d to m-port: %s",
3377 encp->enc_pf, (vf != EFX_PCI_VF_INVALID) ? (int)vf : -1,
3382 rc = efx_mae_action_set_populate_deliver(spec, &mport);
3384 sfc_err(sa, "failed to request action DELIVER with m-port selector 0x%08x: %s",
3385 mport.sel, strerror(rc));
3392 sfc_mae_rule_parse_action_port_id(struct sfc_adapter *sa,
3393 const struct rte_flow_action_port_id *conf,
3394 efx_mae_actions_t *spec)
3396 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
3397 struct sfc_mae *mae = &sa->mae;
3398 efx_mport_sel_t mport;
3402 if (conf->id > UINT16_MAX)
3405 port_id = (conf->original != 0) ? sas->port_id : conf->id;
3407 rc = sfc_mae_switch_port_by_ethdev(mae->switch_domain_id,
3410 sfc_err(sa, "failed to find MAE switch port SW entry for RTE ethdev port %u: %s",
3411 port_id, strerror(rc));
3415 rc = efx_mae_action_set_populate_deliver(spec, &mport);
3417 sfc_err(sa, "failed to request action DELIVER with m-port selector 0x%08x: %s",
3418 mport.sel, strerror(rc));
3424 static const char * const action_names[] = {
3425 [RTE_FLOW_ACTION_TYPE_VXLAN_DECAP] = "VXLAN_DECAP",
3426 [RTE_FLOW_ACTION_TYPE_OF_POP_VLAN] = "OF_POP_VLAN",
3427 [RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN] = "OF_PUSH_VLAN",
3428 [RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID] = "OF_SET_VLAN_VID",
3429 [RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP] = "OF_SET_VLAN_PCP",
3430 [RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP] = "VXLAN_ENCAP",
3431 [RTE_FLOW_ACTION_TYPE_FLAG] = "FLAG",
3432 [RTE_FLOW_ACTION_TYPE_MARK] = "MARK",
3433 [RTE_FLOW_ACTION_TYPE_PHY_PORT] = "PHY_PORT",
3434 [RTE_FLOW_ACTION_TYPE_PF] = "PF",
3435 [RTE_FLOW_ACTION_TYPE_VF] = "VF",
3436 [RTE_FLOW_ACTION_TYPE_PORT_ID] = "PORT_ID",
3437 [RTE_FLOW_ACTION_TYPE_DROP] = "DROP",
3438 [RTE_FLOW_ACTION_TYPE_JUMP] = "JUMP",
3442 sfc_mae_rule_parse_action(struct sfc_adapter *sa,
3443 const struct rte_flow_action *action,
3444 const struct sfc_flow_spec_mae *spec_mae,
3445 struct sfc_mae_actions_bundle *bundle,
3446 efx_mae_actions_t *spec,
3447 struct rte_flow_error *error)
3449 const struct sfc_mae_outer_rule *outer_rule = spec_mae->outer_rule;
3450 const uint64_t rx_metadata = sa->negotiated_rx_metadata;
3451 bool custom_error = B_FALSE;
3454 switch (action->type) {
3455 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
3456 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VXLAN_DECAP,
3457 bundle->actions_mask);
3458 if (outer_rule == NULL ||
3459 outer_rule->encap_type != EFX_TUNNEL_PROTOCOL_VXLAN)
3462 rc = efx_mae_action_set_populate_decap(spec);
3464 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
3465 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_POP_VLAN,
3466 bundle->actions_mask);
3467 rc = efx_mae_action_set_populate_vlan_pop(spec);
3469 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3470 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN,
3471 bundle->actions_mask);
3472 sfc_mae_rule_parse_action_of_push_vlan(action->conf, bundle);
3474 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3475 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID,
3476 bundle->actions_mask);
3477 sfc_mae_rule_parse_action_of_set_vlan_vid(action->conf, bundle);
3479 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3480 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP,
3481 bundle->actions_mask);
3482 sfc_mae_rule_parse_action_of_set_vlan_pcp(action->conf, bundle);
3484 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3485 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP,
3486 bundle->actions_mask);
3487 rc = sfc_mae_rule_parse_action_vxlan_encap(&sa->mae,
3490 custom_error = B_TRUE;
3492 case RTE_FLOW_ACTION_TYPE_COUNT:
3493 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_COUNT,
3494 bundle->actions_mask);
3495 rc = sfc_mae_rule_parse_action_count(sa, action->conf, spec);
3497 case RTE_FLOW_ACTION_TYPE_FLAG:
3498 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_FLAG,
3499 bundle->actions_mask);
3500 if ((rx_metadata & RTE_ETH_RX_METADATA_USER_FLAG) != 0) {
3501 rc = efx_mae_action_set_populate_flag(spec);
3503 rc = rte_flow_error_set(error, ENOTSUP,
3504 RTE_FLOW_ERROR_TYPE_ACTION,
3506 "flag delivery has not been negotiated");
3507 custom_error = B_TRUE;
3510 case RTE_FLOW_ACTION_TYPE_MARK:
3511 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_MARK,
3512 bundle->actions_mask);
3513 if ((rx_metadata & RTE_ETH_RX_METADATA_USER_MARK) != 0 ||
3514 spec_mae->ft_rule_type == SFC_FT_RULE_JUMP) {
3515 rc = sfc_mae_rule_parse_action_mark(sa, action->conf,
3518 rc = rte_flow_error_set(error, ENOTSUP,
3519 RTE_FLOW_ERROR_TYPE_ACTION,
3521 "mark delivery has not been negotiated");
3522 custom_error = B_TRUE;
3525 case RTE_FLOW_ACTION_TYPE_PHY_PORT:
3526 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_PHY_PORT,
3527 bundle->actions_mask);
3528 rc = sfc_mae_rule_parse_action_phy_port(sa, action->conf, spec);
3530 case RTE_FLOW_ACTION_TYPE_PF:
3531 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_PF,
3532 bundle->actions_mask);
3533 rc = sfc_mae_rule_parse_action_pf_vf(sa, NULL, spec);
3535 case RTE_FLOW_ACTION_TYPE_VF:
3536 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VF,
3537 bundle->actions_mask);
3538 rc = sfc_mae_rule_parse_action_pf_vf(sa, action->conf, spec);
3540 case RTE_FLOW_ACTION_TYPE_PORT_ID:
3541 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_PORT_ID,
3542 bundle->actions_mask);
3543 rc = sfc_mae_rule_parse_action_port_id(sa, action->conf, spec);
3545 case RTE_FLOW_ACTION_TYPE_DROP:
3546 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_DROP,
3547 bundle->actions_mask);
3548 rc = efx_mae_action_set_populate_drop(spec);
3550 case RTE_FLOW_ACTION_TYPE_JUMP:
3551 if (spec_mae->ft_rule_type == SFC_FT_RULE_JUMP) {
3552 /* Workaround. See sfc_flow_parse_rte_to_mae() */
3557 return rte_flow_error_set(error, ENOTSUP,
3558 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3559 "Unsupported action");
3563 bundle->actions_mask |= (1ULL << action->type);
3564 } else if (!custom_error) {
3565 if (action->type < RTE_DIM(action_names)) {
3566 const char *action_name = action_names[action->type];
3568 if (action_name != NULL) {
3569 sfc_err(sa, "action %s was rejected: %s",
3570 action_name, strerror(rc));
3573 rc = rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ACTION,
3574 NULL, "Failed to request the action");
3581 sfc_mae_bounce_eh_invalidate(struct sfc_mae_bounce_eh *bounce_eh)
3583 bounce_eh->type = EFX_TUNNEL_PROTOCOL_NONE;
3587 sfc_mae_process_encap_header(struct sfc_adapter *sa,
3588 const struct sfc_mae_bounce_eh *bounce_eh,
3589 struct sfc_mae_encap_header **encap_headerp)
3591 if (bounce_eh->type == EFX_TUNNEL_PROTOCOL_NONE) {
3592 encap_headerp = NULL;
3596 *encap_headerp = sfc_mae_encap_header_attach(sa, bounce_eh);
3597 if (*encap_headerp != NULL)
3600 return sfc_mae_encap_header_add(sa, bounce_eh, encap_headerp);
3604 sfc_mae_rule_parse_actions(struct sfc_adapter *sa,
3605 const struct rte_flow_action actions[],
3606 struct sfc_flow_spec_mae *spec_mae,
3607 struct rte_flow_error *error)
3609 struct sfc_mae_encap_header *encap_header = NULL;
3610 struct sfc_mae_actions_bundle bundle = {0};
3611 struct sfc_flow_tunnel *counter_ft = NULL;
3612 uint64_t *ft_group_hit_counter = NULL;
3613 const struct rte_flow_action *action;
3614 struct sfc_mae *mae = &sa->mae;
3615 unsigned int n_count = 0;
3616 efx_mae_actions_t *spec;
3621 if (actions == NULL) {
3622 return rte_flow_error_set(error, EINVAL,
3623 RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
3627 rc = efx_mae_action_set_spec_init(sa->nic, &spec);
3629 goto fail_action_set_spec_init;
3631 for (action = actions;
3632 action->type != RTE_FLOW_ACTION_TYPE_END; ++action) {
3633 if (action->type == RTE_FLOW_ACTION_TYPE_COUNT)
3637 if (spec_mae->ft_rule_type == SFC_FT_RULE_GROUP) {
3638 /* JUMP rules don't decapsulate packets. GROUP rules do. */
3639 rc = efx_mae_action_set_populate_decap(spec);
3641 goto fail_enforce_ft_decap;
3643 if (n_count == 0 && sfc_mae_counter_stream_enabled(sa)) {
3645 * The user opted not to use action COUNT in this rule,
3646 * but the counter should be enabled implicitly because
3647 * packets hitting this rule contribute to the tunnel's
3648 * total number of hits. See sfc_mae_counter_get().
3650 rc = efx_mae_action_set_populate_count(spec);
3652 goto fail_enforce_ft_count;
3658 /* Cleanup after previous encap. header bounce buffer usage. */
3659 sfc_mae_bounce_eh_invalidate(&mae->bounce_eh);
3661 for (action = actions;
3662 action->type != RTE_FLOW_ACTION_TYPE_END; ++action) {
3663 rc = sfc_mae_actions_bundle_sync(action, &bundle, spec, error);
3665 goto fail_rule_parse_action;
3667 rc = sfc_mae_rule_parse_action(sa, action, spec_mae,
3668 &bundle, spec, error);
3670 goto fail_rule_parse_action;
3673 rc = sfc_mae_actions_bundle_sync(action, &bundle, spec, error);
3675 goto fail_rule_parse_action;
3677 rc = sfc_mae_process_encap_header(sa, &mae->bounce_eh, &encap_header);
3679 goto fail_process_encap_header;
3683 sfc_err(sa, "too many count actions requested: %u", n_count);
3687 switch (spec_mae->ft_rule_type) {
3688 case SFC_FT_RULE_NONE:
3690 case SFC_FT_RULE_JUMP:
3691 /* Workaround. See sfc_flow_parse_rte_to_mae() */
3692 rc = sfc_mae_rule_parse_action_pf_vf(sa, NULL, spec);
3694 goto fail_workaround_jump_delivery;
3696 counter_ft = spec_mae->ft;
3698 case SFC_FT_RULE_GROUP:
3700 * Packets that go to the rule's AR have FT mark set (from the
3701 * JUMP rule OR's RECIRC_ID). Remove this mark in matching
3702 * packets. The user may have provided their own action
3703 * MARK above, so don't check the return value here.
3705 (void)efx_mae_action_set_populate_mark(spec, 0);
3707 ft_group_hit_counter = &spec_mae->ft->group_hit_counter;
3710 SFC_ASSERT(B_FALSE);
3713 spec_mae->action_set = sfc_mae_action_set_attach(sa, encap_header,
3715 if (spec_mae->action_set != NULL) {
3716 sfc_mae_encap_header_del(sa, encap_header);
3717 efx_mae_action_set_spec_fini(sa->nic, spec);
3721 rc = sfc_mae_action_set_add(sa, actions, spec, encap_header,
3722 ft_group_hit_counter, counter_ft, n_count,
3723 &spec_mae->action_set);
3725 goto fail_action_set_add;
3729 fail_action_set_add:
3730 fail_workaround_jump_delivery:
3732 sfc_mae_encap_header_del(sa, encap_header);
3734 fail_process_encap_header:
3735 fail_rule_parse_action:
3736 efx_mae_action_set_spec_fini(sa->nic, spec);
3738 fail_enforce_ft_count:
3739 fail_enforce_ft_decap:
3740 fail_action_set_spec_init:
3741 if (rc > 0 && rte_errno == 0) {
3742 rc = rte_flow_error_set(error, rc,
3743 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3744 NULL, "Failed to process the action");
3750 sfc_mae_rules_class_cmp(struct sfc_adapter *sa,
3751 const efx_mae_match_spec_t *left,
3752 const efx_mae_match_spec_t *right)
3754 bool have_same_class;
3757 rc = efx_mae_match_specs_class_cmp(sa->nic, left, right,
3760 return (rc == 0) ? have_same_class : false;
3764 sfc_mae_outer_rule_class_verify(struct sfc_adapter *sa,
3765 struct sfc_mae_outer_rule *rule)
3767 struct sfc_mae_fw_rsrc *fw_rsrc = &rule->fw_rsrc;
3768 struct sfc_mae_outer_rule *entry;
3769 struct sfc_mae *mae = &sa->mae;
3771 if (fw_rsrc->rule_id.id != EFX_MAE_RSRC_ID_INVALID) {
3772 /* An active rule is reused. It's class is wittingly valid. */
3776 TAILQ_FOREACH_REVERSE(entry, &mae->outer_rules,
3777 sfc_mae_outer_rules, entries) {
3778 const efx_mae_match_spec_t *left = entry->match_spec;
3779 const efx_mae_match_spec_t *right = rule->match_spec;
3784 if (sfc_mae_rules_class_cmp(sa, left, right))
3788 sfc_info(sa, "for now, the HW doesn't support rule validation, and HW "
3789 "support for outer frame pattern items is not guaranteed; "
3790 "other than that, the items are valid from SW standpoint");
3795 sfc_mae_action_rule_class_verify(struct sfc_adapter *sa,
3796 struct sfc_flow_spec_mae *spec)
3798 const struct rte_flow *entry;
3800 if (spec->match_spec == NULL)
3803 TAILQ_FOREACH_REVERSE(entry, &sa->flow_list, sfc_flow_list, entries) {
3804 const struct sfc_flow_spec *entry_spec = &entry->spec;
3805 const struct sfc_flow_spec_mae *es_mae = &entry_spec->mae;
3806 const efx_mae_match_spec_t *left = es_mae->match_spec;
3807 const efx_mae_match_spec_t *right = spec->match_spec;
3809 switch (entry_spec->type) {
3810 case SFC_FLOW_SPEC_FILTER:
3811 /* Ignore VNIC-level flows */
3813 case SFC_FLOW_SPEC_MAE:
3814 if (sfc_mae_rules_class_cmp(sa, left, right))
3822 sfc_info(sa, "for now, the HW doesn't support rule validation, and HW "
3823 "support for inner frame pattern items is not guaranteed; "
3824 "other than that, the items are valid from SW standpoint");
3829 * Confirm that a given flow can be accepted by the FW.
3832 * Software adapter context
3834 * Flow to be verified
3836 * Zero on success and non-zero in the case of error.
3837 * A special value of EAGAIN indicates that the adapter is
3838 * not in started state. This state is compulsory because
3839 * it only makes sense to compare the rule class of the flow
3840 * being validated with classes of the active rules.
3841 * Such classes are wittingly supported by the FW.
3844 sfc_mae_flow_verify(struct sfc_adapter *sa,
3845 struct rte_flow *flow)
3847 struct sfc_flow_spec *spec = &flow->spec;
3848 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
3849 struct sfc_mae_outer_rule *outer_rule = spec_mae->outer_rule;
3852 SFC_ASSERT(sfc_adapter_is_locked(sa));
3854 if (sa->state != SFC_ETHDEV_STARTED)
3857 if (outer_rule != NULL) {
3858 rc = sfc_mae_outer_rule_class_verify(sa, outer_rule);
3863 return sfc_mae_action_rule_class_verify(sa, spec_mae);
3867 sfc_mae_flow_insert(struct sfc_adapter *sa,
3868 struct rte_flow *flow)
3870 struct sfc_flow_spec *spec = &flow->spec;
3871 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
3872 struct sfc_mae_outer_rule *outer_rule = spec_mae->outer_rule;
3873 struct sfc_mae_action_set *action_set = spec_mae->action_set;
3874 struct sfc_mae_fw_rsrc *fw_rsrc;
3877 SFC_ASSERT(spec_mae->rule_id.id == EFX_MAE_RSRC_ID_INVALID);
3879 if (outer_rule != NULL) {
3880 rc = sfc_mae_outer_rule_enable(sa, outer_rule,
3881 spec_mae->match_spec);
3883 goto fail_outer_rule_enable;
3886 if (spec_mae->ft_rule_type == SFC_FT_RULE_JUMP) {
3887 spec_mae->ft->reset_jump_hit_counter =
3888 spec_mae->ft->group_hit_counter;
3891 if (action_set == NULL) {
3892 sfc_dbg(sa, "enabled flow=%p (no AR)", flow);
3896 rc = sfc_mae_action_set_enable(sa, action_set);
3898 goto fail_action_set_enable;
3900 if (action_set->n_counters > 0) {
3901 rc = sfc_mae_counter_start(sa);
3903 sfc_err(sa, "failed to start MAE counters support: %s",
3905 goto fail_mae_counter_start;
3909 fw_rsrc = &action_set->fw_rsrc;
3911 rc = efx_mae_action_rule_insert(sa->nic, spec_mae->match_spec,
3912 NULL, &fw_rsrc->aset_id,
3913 &spec_mae->rule_id);
3915 goto fail_action_rule_insert;
3917 sfc_dbg(sa, "enabled flow=%p: AR_ID=0x%08x",
3918 flow, spec_mae->rule_id.id);
3922 fail_action_rule_insert:
3923 fail_mae_counter_start:
3924 sfc_mae_action_set_disable(sa, action_set);
3926 fail_action_set_enable:
3927 if (outer_rule != NULL)
3928 sfc_mae_outer_rule_disable(sa, outer_rule);
3930 fail_outer_rule_enable:
3935 sfc_mae_flow_remove(struct sfc_adapter *sa,
3936 struct rte_flow *flow)
3938 struct sfc_flow_spec *spec = &flow->spec;
3939 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
3940 struct sfc_mae_action_set *action_set = spec_mae->action_set;
3941 struct sfc_mae_outer_rule *outer_rule = spec_mae->outer_rule;
3944 if (action_set == NULL) {
3945 sfc_dbg(sa, "disabled flow=%p (no AR)", flow);
3946 goto skip_action_rule;
3949 SFC_ASSERT(spec_mae->rule_id.id != EFX_MAE_RSRC_ID_INVALID);
3951 rc = efx_mae_action_rule_remove(sa->nic, &spec_mae->rule_id);
3953 sfc_err(sa, "failed to disable flow=%p with AR_ID=0x%08x: %s",
3954 flow, spec_mae->rule_id.id, strerror(rc));
3956 sfc_dbg(sa, "disabled flow=%p with AR_ID=0x%08x",
3957 flow, spec_mae->rule_id.id);
3958 spec_mae->rule_id.id = EFX_MAE_RSRC_ID_INVALID;
3960 sfc_mae_action_set_disable(sa, action_set);
3963 if (outer_rule != NULL)
3964 sfc_mae_outer_rule_disable(sa, outer_rule);
3970 sfc_mae_query_counter(struct sfc_adapter *sa,
3971 struct sfc_flow_spec_mae *spec,
3972 const struct rte_flow_action *action,
3973 struct rte_flow_query_count *data,
3974 struct rte_flow_error *error)
3976 struct sfc_mae_action_set *action_set = spec->action_set;
3977 const struct rte_flow_action_count *conf = action->conf;
3981 if (action_set == NULL || action_set->n_counters == 0) {
3982 return rte_flow_error_set(error, EINVAL,
3983 RTE_FLOW_ERROR_TYPE_ACTION, action,
3984 "Queried flow rule does not have count actions");
3987 for (i = 0; i < action_set->n_counters; i++) {
3989 * Get the first available counter of the flow rule if
3990 * counter ID is not specified, provided that this
3991 * counter is not an automatic (implicit) one.
3993 if (conf != NULL && action_set->counters[i].rte_id != conf->id)
3996 rc = sfc_mae_counter_get(&sa->mae.counter_registry.counters,
3997 &action_set->counters[i], data);
3999 return rte_flow_error_set(error, EINVAL,
4000 RTE_FLOW_ERROR_TYPE_ACTION, action,
4001 "Queried flow rule counter action is invalid");
4007 return rte_flow_error_set(error, ENOENT,
4008 RTE_FLOW_ERROR_TYPE_ACTION, action,
4009 "no such flow rule action or such count ID");
4013 sfc_mae_flow_query(struct rte_eth_dev *dev,
4014 struct rte_flow *flow,
4015 const struct rte_flow_action *action,
4017 struct rte_flow_error *error)
4019 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
4020 struct sfc_flow_spec *spec = &flow->spec;
4021 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
4023 switch (action->type) {
4024 case RTE_FLOW_ACTION_TYPE_COUNT:
4025 return sfc_mae_query_counter(sa, spec_mae, action,
4028 return rte_flow_error_set(error, ENOTSUP,
4029 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4030 "Query for action of this type is not supported");
4035 sfc_mae_switchdev_init(struct sfc_adapter *sa)
4037 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
4038 struct sfc_mae *mae = &sa->mae;
4040 efx_mport_sel_t phy;
4043 sfc_log_init(sa, "entry");
4045 if (!sa->switchdev) {
4046 sfc_log_init(sa, "switchdev is not enabled - skip");
4050 if (mae->status != SFC_MAE_STATUS_ADMIN) {
4052 sfc_err(sa, "failed to init switchdev - no admin MAE privilege");
4056 rc = efx_mae_mport_by_pcie_function(encp->enc_pf, EFX_PCI_VF_INVALID,
4059 sfc_err(sa, "failed get PF mport");
4063 rc = efx_mae_mport_by_phy_port(encp->enc_assigned_port, &phy);
4065 sfc_err(sa, "failed get PHY mport");
4069 rc = sfc_mae_rule_add_mport_match_deliver(sa, &pf, &phy,
4070 SFC_MAE_RULE_PRIO_LOWEST,
4071 &mae->switchdev_rule_pf_to_ext);
4073 sfc_err(sa, "failed add MAE rule to forward from PF to PHY");
4077 rc = sfc_mae_rule_add_mport_match_deliver(sa, &phy, &pf,
4078 SFC_MAE_RULE_PRIO_LOWEST,
4079 &mae->switchdev_rule_ext_to_pf);
4081 sfc_err(sa, "failed add MAE rule to forward from PHY to PF");
4085 sfc_log_init(sa, "done");
4090 sfc_mae_rule_del(sa, mae->switchdev_rule_pf_to_ext);
4096 sfc_log_init(sa, "failed: %s", rte_strerror(rc));
4101 sfc_mae_switchdev_fini(struct sfc_adapter *sa)
4103 struct sfc_mae *mae = &sa->mae;
4108 sfc_mae_rule_del(sa, mae->switchdev_rule_pf_to_ext);
4109 sfc_mae_rule_del(sa, mae->switchdev_rule_ext_to_pf);