1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2019-2021 Xilinx, Inc.
4 * Copyright(c) 2019 Solarflare Communications Inc.
6 * This software was jointly developed between OKTET Labs (under contract
7 * for Solarflare) and Solarflare Communications, Inc.
12 #include <rte_bitops.h>
13 #include <rte_common.h>
14 #include <rte_vxlan.h>
19 #include "sfc_flow_tunnel.h"
20 #include "sfc_mae_counter.h"
22 #include "sfc_switch.h"
23 #include "sfc_service.h"
26 sfc_mae_assign_ethdev_mport(struct sfc_adapter *sa,
27 efx_mport_sel_t *mportp)
29 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
31 return efx_mae_mport_by_pcie_function(encp->enc_pf, encp->enc_vf,
36 sfc_mae_assign_entity_mport(struct sfc_adapter *sa,
37 efx_mport_sel_t *mportp)
39 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
42 if (encp->enc_mae_admin) {
44 * This ethdev sits on MAE admin PF. The represented
45 * entity is the network port assigned to that PF.
47 rc = efx_mae_mport_by_phy_port(encp->enc_assigned_port, mportp);
50 * This ethdev sits on unprivileged PF / VF. The entity
51 * represented by the ethdev can change dynamically
52 * as MAE admin changes default traffic rules.
54 * For the sake of simplicity, do not fill in the m-port
55 * and assume that flow rules should not be allowed to
56 * reference the entity represented by this ethdev.
58 efx_mae_mport_invalid(mportp);
65 sfc_mae_counter_registry_init(struct sfc_mae_counter_registry *registry,
66 uint32_t nb_counters_max)
68 return sfc_mae_counters_init(®istry->counters, nb_counters_max);
72 sfc_mae_counter_registry_fini(struct sfc_mae_counter_registry *registry)
74 sfc_mae_counters_fini(®istry->counters);
78 sfc_mae_internal_rule_find_empty_slot(struct sfc_adapter *sa,
79 struct sfc_mae_rule **rule)
81 struct sfc_mae *mae = &sa->mae;
82 struct sfc_mae_internal_rules *internal_rules = &mae->internal_rules;
86 for (entry = 0; entry < SFC_MAE_NB_RULES_MAX; entry++) {
87 if (internal_rules->rules[entry].spec == NULL)
91 if (entry == SFC_MAE_NB_RULES_MAX) {
93 sfc_err(sa, "failed too many rules (%u rules used)", entry);
94 goto fail_too_many_rules;
97 *rule = &internal_rules->rules[entry];
106 sfc_mae_rule_add_mport_match_deliver(struct sfc_adapter *sa,
107 const efx_mport_sel_t *mport_match,
108 const efx_mport_sel_t *mport_deliver,
109 int prio, struct sfc_mae_rule **rulep)
111 struct sfc_mae *mae = &sa->mae;
112 struct sfc_mae_rule *rule;
115 sfc_log_init(sa, "entry");
117 if (prio > 0 && (unsigned int)prio >= mae->nb_action_rule_prios_max) {
119 sfc_err(sa, "failed: invalid priority %d (max %u)", prio,
120 mae->nb_action_rule_prios_max);
121 goto fail_invalid_prio;
124 prio = mae->nb_action_rule_prios_max - 1;
126 rc = sfc_mae_internal_rule_find_empty_slot(sa, &rule);
128 goto fail_find_empty_slot;
130 sfc_log_init(sa, "init MAE match spec");
131 rc = efx_mae_match_spec_init(sa->nic, EFX_MAE_RULE_ACTION,
132 (uint32_t)prio, &rule->spec);
134 sfc_err(sa, "failed to init MAE match spec");
135 goto fail_match_init;
138 rc = efx_mae_match_spec_mport_set(rule->spec, mport_match, NULL);
140 sfc_err(sa, "failed to get MAE match mport selector");
144 rc = efx_mae_action_set_spec_init(sa->nic, &rule->actions);
146 sfc_err(sa, "failed to init MAE action set");
147 goto fail_action_init;
150 rc = efx_mae_action_set_populate_deliver(rule->actions,
153 sfc_err(sa, "failed to populate deliver action");
154 goto fail_populate_deliver;
157 rc = efx_mae_action_set_alloc(sa->nic, rule->actions,
160 sfc_err(sa, "failed to allocate action set");
161 goto fail_action_set_alloc;
164 rc = efx_mae_action_rule_insert(sa->nic, rule->spec, NULL,
168 sfc_err(sa, "failed to insert action rule");
169 goto fail_rule_insert;
174 sfc_log_init(sa, "done");
179 efx_mae_action_set_free(sa->nic, &rule->action_set);
181 fail_action_set_alloc:
182 fail_populate_deliver:
183 efx_mae_action_set_spec_fini(sa->nic, rule->actions);
187 efx_mae_match_spec_fini(sa->nic, rule->spec);
190 fail_find_empty_slot:
192 sfc_log_init(sa, "failed: %s", rte_strerror(rc));
197 sfc_mae_rule_del(struct sfc_adapter *sa, struct sfc_mae_rule *rule)
199 if (rule == NULL || rule->spec == NULL)
202 efx_mae_action_rule_remove(sa->nic, &rule->rule_id);
203 efx_mae_action_set_free(sa->nic, &rule->action_set);
204 efx_mae_action_set_spec_fini(sa->nic, rule->actions);
205 efx_mae_match_spec_fini(sa->nic, rule->spec);
211 sfc_mae_attach(struct sfc_adapter *sa)
213 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
214 struct sfc_mae_switch_port_request switch_port_request = {0};
215 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
216 efx_mport_sel_t ethdev_mport;
217 efx_mport_sel_t entity_mport;
218 struct sfc_mae *mae = &sa->mae;
219 struct sfc_mae_bounce_eh *bounce_eh = &mae->bounce_eh;
220 efx_mae_limits_t limits;
223 sfc_log_init(sa, "entry");
225 if (!encp->enc_mae_supported) {
226 mae->status = SFC_MAE_STATUS_UNSUPPORTED;
230 if (encp->enc_mae_admin) {
231 sfc_log_init(sa, "init MAE");
232 rc = efx_mae_init(sa->nic);
236 sfc_log_init(sa, "get MAE limits");
237 rc = efx_mae_get_limits(sa->nic, &limits);
239 goto fail_mae_get_limits;
241 sfc_log_init(sa, "init MAE counter registry");
242 rc = sfc_mae_counter_registry_init(&mae->counter_registry,
243 limits.eml_max_n_counters);
245 sfc_err(sa, "failed to init MAE counters registry for %u entries: %s",
246 limits.eml_max_n_counters, rte_strerror(rc));
247 goto fail_counter_registry_init;
251 sfc_log_init(sa, "assign ethdev MPORT");
252 rc = sfc_mae_assign_ethdev_mport(sa, ðdev_mport);
254 goto fail_mae_assign_ethdev_mport;
256 sfc_log_init(sa, "assign entity MPORT");
257 rc = sfc_mae_assign_entity_mport(sa, &entity_mport);
259 goto fail_mae_assign_entity_mport;
261 sfc_log_init(sa, "assign RTE switch domain");
262 rc = sfc_mae_assign_switch_domain(sa, &mae->switch_domain_id);
264 goto fail_mae_assign_switch_domain;
266 sfc_log_init(sa, "assign RTE switch port");
267 switch_port_request.type = SFC_MAE_SWITCH_PORT_INDEPENDENT;
268 switch_port_request.ethdev_mportp = ðdev_mport;
269 switch_port_request.entity_mportp = &entity_mport;
270 switch_port_request.ethdev_port_id = sas->port_id;
271 switch_port_request.port_data.indep.mae_admin =
272 encp->enc_mae_admin == B_TRUE;
273 rc = sfc_mae_assign_switch_port(mae->switch_domain_id,
274 &switch_port_request,
275 &mae->switch_port_id);
277 goto fail_mae_assign_switch_port;
279 if (encp->enc_mae_admin) {
280 sfc_log_init(sa, "allocate encap. header bounce buffer");
281 bounce_eh->buf_size = limits.eml_encap_header_size_limit;
282 bounce_eh->buf = rte_malloc("sfc_mae_bounce_eh",
283 bounce_eh->buf_size, 0);
284 if (bounce_eh->buf == NULL)
285 goto fail_mae_alloc_bounce_eh;
287 mae->nb_outer_rule_prios_max = limits.eml_max_n_outer_prios;
288 mae->nb_action_rule_prios_max = limits.eml_max_n_action_prios;
289 mae->encap_types_supported = limits.eml_encap_types_supported;
292 TAILQ_INIT(&mae->outer_rules);
293 TAILQ_INIT(&mae->mac_addrs);
294 TAILQ_INIT(&mae->encap_headers);
295 TAILQ_INIT(&mae->action_sets);
297 if (encp->enc_mae_admin)
298 mae->status = SFC_MAE_STATUS_ADMIN;
300 mae->status = SFC_MAE_STATUS_SUPPORTED;
302 sfc_log_init(sa, "done");
306 fail_mae_alloc_bounce_eh:
307 fail_mae_assign_switch_port:
308 fail_mae_assign_switch_domain:
309 fail_mae_assign_entity_mport:
310 fail_mae_assign_ethdev_mport:
311 if (encp->enc_mae_admin)
312 sfc_mae_counter_registry_fini(&mae->counter_registry);
314 fail_counter_registry_init:
316 if (encp->enc_mae_admin)
317 efx_mae_fini(sa->nic);
320 sfc_log_init(sa, "failed %d", rc);
326 sfc_mae_detach(struct sfc_adapter *sa)
328 struct sfc_mae *mae = &sa->mae;
329 enum sfc_mae_status status_prev = mae->status;
331 sfc_log_init(sa, "entry");
333 mae->nb_action_rule_prios_max = 0;
334 mae->status = SFC_MAE_STATUS_UNKNOWN;
336 if (status_prev != SFC_MAE_STATUS_ADMIN)
339 rte_free(mae->bounce_eh.buf);
340 sfc_mae_counter_registry_fini(&mae->counter_registry);
342 efx_mae_fini(sa->nic);
344 sfc_log_init(sa, "done");
347 static struct sfc_mae_outer_rule *
348 sfc_mae_outer_rule_attach(struct sfc_adapter *sa,
349 const efx_mae_match_spec_t *match_spec,
350 efx_tunnel_protocol_t encap_type)
352 struct sfc_mae_outer_rule *rule;
353 struct sfc_mae *mae = &sa->mae;
355 SFC_ASSERT(sfc_adapter_is_locked(sa));
357 TAILQ_FOREACH(rule, &mae->outer_rules, entries) {
358 if (efx_mae_match_specs_equal(rule->match_spec, match_spec) &&
359 rule->encap_type == encap_type) {
360 sfc_dbg(sa, "attaching to outer_rule=%p", rule);
370 sfc_mae_outer_rule_add(struct sfc_adapter *sa,
371 efx_mae_match_spec_t *match_spec,
372 efx_tunnel_protocol_t encap_type,
373 struct sfc_mae_outer_rule **rulep)
375 struct sfc_mae_outer_rule *rule;
376 struct sfc_mae *mae = &sa->mae;
378 SFC_ASSERT(sfc_adapter_is_locked(sa));
380 rule = rte_zmalloc("sfc_mae_outer_rule", sizeof(*rule), 0);
385 rule->match_spec = match_spec;
386 rule->encap_type = encap_type;
388 rule->fw_rsrc.rule_id.id = EFX_MAE_RSRC_ID_INVALID;
390 TAILQ_INSERT_TAIL(&mae->outer_rules, rule, entries);
394 sfc_dbg(sa, "added outer_rule=%p", rule);
400 sfc_mae_outer_rule_del(struct sfc_adapter *sa,
401 struct sfc_mae_outer_rule *rule)
403 struct sfc_mae *mae = &sa->mae;
405 SFC_ASSERT(sfc_adapter_is_locked(sa));
406 SFC_ASSERT(rule->refcnt != 0);
410 if (rule->refcnt != 0)
413 if (rule->fw_rsrc.rule_id.id != EFX_MAE_RSRC_ID_INVALID ||
414 rule->fw_rsrc.refcnt != 0) {
415 sfc_err(sa, "deleting outer_rule=%p abandons its FW resource: OR_ID=0x%08x, refcnt=%u",
416 rule, rule->fw_rsrc.rule_id.id, rule->fw_rsrc.refcnt);
419 efx_mae_match_spec_fini(sa->nic, rule->match_spec);
421 TAILQ_REMOVE(&mae->outer_rules, rule, entries);
424 sfc_dbg(sa, "deleted outer_rule=%p", rule);
428 sfc_mae_outer_rule_enable(struct sfc_adapter *sa,
429 struct sfc_mae_outer_rule *rule,
430 efx_mae_match_spec_t *match_spec_action)
432 struct sfc_mae_fw_rsrc *fw_rsrc = &rule->fw_rsrc;
435 SFC_ASSERT(sfc_adapter_is_locked(sa));
437 if (fw_rsrc->refcnt == 0) {
438 SFC_ASSERT(fw_rsrc->rule_id.id == EFX_MAE_RSRC_ID_INVALID);
439 SFC_ASSERT(rule->match_spec != NULL);
441 rc = efx_mae_outer_rule_insert(sa->nic, rule->match_spec,
445 sfc_err(sa, "failed to enable outer_rule=%p: %s",
451 if (match_spec_action == NULL)
452 goto skip_action_rule;
454 rc = efx_mae_match_spec_outer_rule_id_set(match_spec_action,
457 if (fw_rsrc->refcnt == 0) {
458 (void)efx_mae_outer_rule_remove(sa->nic,
460 fw_rsrc->rule_id.id = EFX_MAE_RSRC_ID_INVALID;
463 sfc_err(sa, "can't match on outer rule ID: %s", strerror(rc));
469 if (fw_rsrc->refcnt == 0) {
470 sfc_dbg(sa, "enabled outer_rule=%p: OR_ID=0x%08x",
471 rule, fw_rsrc->rule_id.id);
480 sfc_mae_outer_rule_disable(struct sfc_adapter *sa,
481 struct sfc_mae_outer_rule *rule)
483 struct sfc_mae_fw_rsrc *fw_rsrc = &rule->fw_rsrc;
486 SFC_ASSERT(sfc_adapter_is_locked(sa));
488 if (fw_rsrc->rule_id.id == EFX_MAE_RSRC_ID_INVALID ||
489 fw_rsrc->refcnt == 0) {
490 sfc_err(sa, "failed to disable outer_rule=%p: already disabled; OR_ID=0x%08x, refcnt=%u",
491 rule, fw_rsrc->rule_id.id, fw_rsrc->refcnt);
495 if (fw_rsrc->refcnt == 1) {
496 rc = efx_mae_outer_rule_remove(sa->nic, &fw_rsrc->rule_id);
498 sfc_dbg(sa, "disabled outer_rule=%p with OR_ID=0x%08x",
499 rule, fw_rsrc->rule_id.id);
501 sfc_err(sa, "failed to disable outer_rule=%p with OR_ID=0x%08x: %s",
502 rule, fw_rsrc->rule_id.id, strerror(rc));
504 fw_rsrc->rule_id.id = EFX_MAE_RSRC_ID_INVALID;
510 static struct sfc_mae_mac_addr *
511 sfc_mae_mac_addr_attach(struct sfc_adapter *sa,
512 const uint8_t addr_bytes[EFX_MAC_ADDR_LEN])
514 struct sfc_mae_mac_addr *mac_addr;
515 struct sfc_mae *mae = &sa->mae;
517 SFC_ASSERT(sfc_adapter_is_locked(sa));
519 TAILQ_FOREACH(mac_addr, &mae->mac_addrs, entries) {
520 if (memcmp(mac_addr->addr_bytes, addr_bytes,
521 EFX_MAC_ADDR_LEN) == 0) {
522 sfc_dbg(sa, "attaching to mac_addr=%p", mac_addr);
523 ++(mac_addr->refcnt);
532 sfc_mae_mac_addr_add(struct sfc_adapter *sa,
533 const uint8_t addr_bytes[EFX_MAC_ADDR_LEN],
534 struct sfc_mae_mac_addr **mac_addrp)
536 struct sfc_mae_mac_addr *mac_addr;
537 struct sfc_mae *mae = &sa->mae;
539 SFC_ASSERT(sfc_adapter_is_locked(sa));
541 mac_addr = rte_zmalloc("sfc_mae_mac_addr", sizeof(*mac_addr), 0);
542 if (mac_addr == NULL)
545 rte_memcpy(mac_addr->addr_bytes, addr_bytes, EFX_MAC_ADDR_LEN);
547 mac_addr->refcnt = 1;
548 mac_addr->fw_rsrc.mac_id.id = EFX_MAE_RSRC_ID_INVALID;
550 TAILQ_INSERT_TAIL(&mae->mac_addrs, mac_addr, entries);
552 *mac_addrp = mac_addr;
554 sfc_dbg(sa, "added mac_addr=%p", mac_addr);
560 sfc_mae_mac_addr_del(struct sfc_adapter *sa, struct sfc_mae_mac_addr *mac_addr)
562 struct sfc_mae *mae = &sa->mae;
564 if (mac_addr == NULL)
567 SFC_ASSERT(sfc_adapter_is_locked(sa));
568 SFC_ASSERT(mac_addr->refcnt != 0);
570 --(mac_addr->refcnt);
572 if (mac_addr->refcnt != 0)
575 if (mac_addr->fw_rsrc.mac_id.id != EFX_MAE_RSRC_ID_INVALID ||
576 mac_addr->fw_rsrc.refcnt != 0) {
577 sfc_err(sa, "deleting mac_addr=%p abandons its FW resource: MAC_ID=0x%08x, refcnt=%u",
578 mac_addr, mac_addr->fw_rsrc.mac_id.id,
579 mac_addr->fw_rsrc.refcnt);
582 TAILQ_REMOVE(&mae->mac_addrs, mac_addr, entries);
585 sfc_dbg(sa, "deleted mac_addr=%p", mac_addr);
588 enum sfc_mae_mac_addr_type {
589 SFC_MAE_MAC_ADDR_DST,
594 sfc_mae_mac_addr_enable(struct sfc_adapter *sa,
595 struct sfc_mae_mac_addr *mac_addr,
596 enum sfc_mae_mac_addr_type type,
597 efx_mae_actions_t *aset_spec)
599 struct sfc_mae_fw_rsrc *fw_rsrc;
602 if (mac_addr == NULL)
605 SFC_ASSERT(sfc_adapter_is_locked(sa));
607 fw_rsrc = &mac_addr->fw_rsrc;
609 if (fw_rsrc->refcnt == 0) {
610 SFC_ASSERT(fw_rsrc->mac_id.id == EFX_MAE_RSRC_ID_INVALID);
612 rc = efx_mae_mac_addr_alloc(sa->nic, mac_addr->addr_bytes,
615 sfc_err(sa, "failed to enable mac_addr=%p: %s",
616 mac_addr, strerror(rc));
622 case SFC_MAE_MAC_ADDR_DST:
623 rc = efx_mae_action_set_fill_in_dst_mac_id(aset_spec,
626 case SFC_MAE_MAC_ADDR_SRC:
627 rc = efx_mae_action_set_fill_in_src_mac_id(aset_spec,
636 if (fw_rsrc->refcnt == 0) {
637 (void)efx_mae_mac_addr_free(sa->nic, &fw_rsrc->mac_id);
638 fw_rsrc->mac_id.id = EFX_MAE_RSRC_ID_INVALID;
641 sfc_err(sa, "cannot fill in MAC address entry ID: %s",
647 if (fw_rsrc->refcnt == 0) {
648 sfc_dbg(sa, "enabled mac_addr=%p: MAC_ID=0x%08x",
649 mac_addr, fw_rsrc->mac_id.id);
658 sfc_mae_mac_addr_disable(struct sfc_adapter *sa,
659 struct sfc_mae_mac_addr *mac_addr)
661 struct sfc_mae_fw_rsrc *fw_rsrc;
664 if (mac_addr == NULL)
667 SFC_ASSERT(sfc_adapter_is_locked(sa));
669 fw_rsrc = &mac_addr->fw_rsrc;
671 if (fw_rsrc->mac_id.id == EFX_MAE_RSRC_ID_INVALID ||
672 fw_rsrc->refcnt == 0) {
673 sfc_err(sa, "failed to disable mac_addr=%p: already disabled; MAC_ID=0x%08x, refcnt=%u",
674 mac_addr, fw_rsrc->mac_id.id, fw_rsrc->refcnt);
678 if (fw_rsrc->refcnt == 1) {
679 rc = efx_mae_mac_addr_free(sa->nic, &fw_rsrc->mac_id);
681 sfc_dbg(sa, "disabled mac_addr=%p with MAC_ID=0x%08x",
682 mac_addr, fw_rsrc->mac_id.id);
684 sfc_err(sa, "failed to disable mac_addr=%p with MAC_ID=0x%08x: %s",
685 mac_addr, fw_rsrc->mac_id.id, strerror(rc));
687 fw_rsrc->mac_id.id = EFX_MAE_RSRC_ID_INVALID;
693 static struct sfc_mae_encap_header *
694 sfc_mae_encap_header_attach(struct sfc_adapter *sa,
695 const struct sfc_mae_bounce_eh *bounce_eh)
697 struct sfc_mae_encap_header *encap_header;
698 struct sfc_mae *mae = &sa->mae;
700 SFC_ASSERT(sfc_adapter_is_locked(sa));
702 TAILQ_FOREACH(encap_header, &mae->encap_headers, entries) {
703 if (encap_header->size == bounce_eh->size &&
704 memcmp(encap_header->buf, bounce_eh->buf,
705 bounce_eh->size) == 0) {
706 sfc_dbg(sa, "attaching to encap_header=%p",
708 ++(encap_header->refcnt);
717 sfc_mae_encap_header_add(struct sfc_adapter *sa,
718 const struct sfc_mae_bounce_eh *bounce_eh,
719 struct sfc_mae_encap_header **encap_headerp)
721 struct sfc_mae_encap_header *encap_header;
722 struct sfc_mae *mae = &sa->mae;
724 SFC_ASSERT(sfc_adapter_is_locked(sa));
726 encap_header = rte_zmalloc("sfc_mae_encap_header",
727 sizeof(*encap_header), 0);
728 if (encap_header == NULL)
731 encap_header->size = bounce_eh->size;
733 encap_header->buf = rte_malloc("sfc_mae_encap_header_buf",
734 encap_header->size, 0);
735 if (encap_header->buf == NULL) {
736 rte_free(encap_header);
740 rte_memcpy(encap_header->buf, bounce_eh->buf, bounce_eh->size);
742 encap_header->refcnt = 1;
743 encap_header->type = bounce_eh->type;
744 encap_header->fw_rsrc.eh_id.id = EFX_MAE_RSRC_ID_INVALID;
746 TAILQ_INSERT_TAIL(&mae->encap_headers, encap_header, entries);
748 *encap_headerp = encap_header;
750 sfc_dbg(sa, "added encap_header=%p", encap_header);
756 sfc_mae_encap_header_del(struct sfc_adapter *sa,
757 struct sfc_mae_encap_header *encap_header)
759 struct sfc_mae *mae = &sa->mae;
761 if (encap_header == NULL)
764 SFC_ASSERT(sfc_adapter_is_locked(sa));
765 SFC_ASSERT(encap_header->refcnt != 0);
767 --(encap_header->refcnt);
769 if (encap_header->refcnt != 0)
772 if (encap_header->fw_rsrc.eh_id.id != EFX_MAE_RSRC_ID_INVALID ||
773 encap_header->fw_rsrc.refcnt != 0) {
774 sfc_err(sa, "deleting encap_header=%p abandons its FW resource: EH_ID=0x%08x, refcnt=%u",
775 encap_header, encap_header->fw_rsrc.eh_id.id,
776 encap_header->fw_rsrc.refcnt);
779 TAILQ_REMOVE(&mae->encap_headers, encap_header, entries);
780 rte_free(encap_header->buf);
781 rte_free(encap_header);
783 sfc_dbg(sa, "deleted encap_header=%p", encap_header);
787 sfc_mae_encap_header_enable(struct sfc_adapter *sa,
788 struct sfc_mae_encap_header *encap_header,
789 efx_mae_actions_t *action_set_spec)
791 struct sfc_mae_fw_rsrc *fw_rsrc;
794 if (encap_header == NULL)
797 SFC_ASSERT(sfc_adapter_is_locked(sa));
799 fw_rsrc = &encap_header->fw_rsrc;
801 if (fw_rsrc->refcnt == 0) {
802 SFC_ASSERT(fw_rsrc->eh_id.id == EFX_MAE_RSRC_ID_INVALID);
803 SFC_ASSERT(encap_header->buf != NULL);
804 SFC_ASSERT(encap_header->size != 0);
806 rc = efx_mae_encap_header_alloc(sa->nic, encap_header->type,
811 sfc_err(sa, "failed to enable encap_header=%p: %s",
812 encap_header, strerror(rc));
817 rc = efx_mae_action_set_fill_in_eh_id(action_set_spec,
820 if (fw_rsrc->refcnt == 0) {
821 (void)efx_mae_encap_header_free(sa->nic,
823 fw_rsrc->eh_id.id = EFX_MAE_RSRC_ID_INVALID;
826 sfc_err(sa, "can't fill in encap. header ID: %s", strerror(rc));
831 if (fw_rsrc->refcnt == 0) {
832 sfc_dbg(sa, "enabled encap_header=%p: EH_ID=0x%08x",
833 encap_header, fw_rsrc->eh_id.id);
842 sfc_mae_encap_header_disable(struct sfc_adapter *sa,
843 struct sfc_mae_encap_header *encap_header)
845 struct sfc_mae_fw_rsrc *fw_rsrc;
848 if (encap_header == NULL)
851 SFC_ASSERT(sfc_adapter_is_locked(sa));
853 fw_rsrc = &encap_header->fw_rsrc;
855 if (fw_rsrc->eh_id.id == EFX_MAE_RSRC_ID_INVALID ||
856 fw_rsrc->refcnt == 0) {
857 sfc_err(sa, "failed to disable encap_header=%p: already disabled; EH_ID=0x%08x, refcnt=%u",
858 encap_header, fw_rsrc->eh_id.id, fw_rsrc->refcnt);
862 if (fw_rsrc->refcnt == 1) {
863 rc = efx_mae_encap_header_free(sa->nic, &fw_rsrc->eh_id);
865 sfc_dbg(sa, "disabled encap_header=%p with EH_ID=0x%08x",
866 encap_header, fw_rsrc->eh_id.id);
868 sfc_err(sa, "failed to disable encap_header=%p with EH_ID=0x%08x: %s",
869 encap_header, fw_rsrc->eh_id.id, strerror(rc));
871 fw_rsrc->eh_id.id = EFX_MAE_RSRC_ID_INVALID;
878 sfc_mae_counters_enable(struct sfc_adapter *sa,
879 struct sfc_mae_counter_id *counters,
880 unsigned int n_counters,
881 efx_mae_actions_t *action_set_spec)
885 sfc_log_init(sa, "entry");
887 if (n_counters == 0) {
888 sfc_log_init(sa, "no counters - skip");
892 SFC_ASSERT(sfc_adapter_is_locked(sa));
893 SFC_ASSERT(n_counters == 1);
895 rc = sfc_mae_counter_enable(sa, &counters[0]);
897 sfc_err(sa, "failed to enable MAE counter %u: %s",
898 counters[0].mae_id.id, rte_strerror(rc));
899 goto fail_counter_add;
902 rc = efx_mae_action_set_fill_in_counter_id(action_set_spec,
903 &counters[0].mae_id);
905 sfc_err(sa, "failed to fill in MAE counter %u in action set: %s",
906 counters[0].mae_id.id, rte_strerror(rc));
907 goto fail_fill_in_id;
913 (void)sfc_mae_counter_disable(sa, &counters[0]);
916 sfc_log_init(sa, "failed: %s", rte_strerror(rc));
921 sfc_mae_counters_disable(struct sfc_adapter *sa,
922 struct sfc_mae_counter_id *counters,
923 unsigned int n_counters)
928 SFC_ASSERT(sfc_adapter_is_locked(sa));
929 SFC_ASSERT(n_counters == 1);
931 if (counters[0].mae_id.id == EFX_MAE_RSRC_ID_INVALID) {
932 sfc_err(sa, "failed to disable: already disabled");
936 return sfc_mae_counter_disable(sa, &counters[0]);
939 struct sfc_mae_aset_ctx {
940 uint64_t *ft_switch_hit_counter;
941 struct sfc_ft_ctx *counter_ft_ctx;
942 struct sfc_mae_encap_header *encap_header;
943 unsigned int n_counters;
944 struct sfc_mae_mac_addr *dst_mac;
945 struct sfc_mae_mac_addr *src_mac;
947 efx_mae_actions_t *spec;
950 static struct sfc_mae_action_set *
951 sfc_mae_action_set_attach(struct sfc_adapter *sa,
952 const struct sfc_mae_aset_ctx *ctx)
954 struct sfc_mae_action_set *action_set;
955 struct sfc_mae *mae = &sa->mae;
957 SFC_ASSERT(sfc_adapter_is_locked(sa));
960 * Shared counters are not supported, hence, action
961 * sets with counters are not attachable.
963 if (ctx->n_counters != 0)
966 TAILQ_FOREACH(action_set, &mae->action_sets, entries) {
967 if (action_set->encap_header == ctx->encap_header &&
968 action_set->dst_mac_addr == ctx->dst_mac &&
969 action_set->src_mac_addr == ctx->src_mac &&
970 efx_mae_action_set_specs_equal(action_set->spec,
972 sfc_dbg(sa, "attaching to action_set=%p", action_set);
973 ++(action_set->refcnt);
982 sfc_mae_action_set_add(struct sfc_adapter *sa,
983 const struct rte_flow_action actions[],
984 const struct sfc_mae_aset_ctx *ctx,
985 struct sfc_mae_action_set **action_setp)
987 struct sfc_mae_action_set *action_set;
988 struct sfc_mae *mae = &sa->mae;
991 SFC_ASSERT(sfc_adapter_is_locked(sa));
993 action_set = rte_zmalloc("sfc_mae_action_set", sizeof(*action_set), 0);
994 if (action_set == NULL) {
995 sfc_err(sa, "failed to alloc action set");
999 if (ctx->n_counters > 0) {
1000 const struct rte_flow_action *action;
1002 action_set->counters = rte_malloc("sfc_mae_counter_ids",
1003 sizeof(action_set->counters[0]) * ctx->n_counters, 0);
1004 if (action_set->counters == NULL) {
1005 rte_free(action_set);
1006 sfc_err(sa, "failed to alloc counters");
1010 for (i = 0; i < ctx->n_counters; ++i) {
1011 action_set->counters[i].rte_id_valid = B_FALSE;
1012 action_set->counters[i].mae_id.id =
1013 EFX_MAE_RSRC_ID_INVALID;
1015 action_set->counters[i].ft_ctx = ctx->counter_ft_ctx;
1016 action_set->counters[i].ft_switch_hit_counter =
1017 ctx->ft_switch_hit_counter;
1020 for (action = actions, i = 0;
1021 action->type != RTE_FLOW_ACTION_TYPE_END &&
1022 i < ctx->n_counters; ++action) {
1023 const struct rte_flow_action_count *conf;
1025 if (action->type != RTE_FLOW_ACTION_TYPE_COUNT)
1028 conf = action->conf;
1030 action_set->counters[i].rte_id_valid = B_TRUE;
1031 action_set->counters[i].rte_id = conf->id;
1034 action_set->n_counters = ctx->n_counters;
1037 action_set->refcnt = 1;
1038 action_set->spec = ctx->spec;
1039 action_set->encap_header = ctx->encap_header;
1040 action_set->dst_mac_addr = ctx->dst_mac;
1041 action_set->src_mac_addr = ctx->src_mac;
1043 action_set->fw_rsrc.aset_id.id = EFX_MAE_RSRC_ID_INVALID;
1045 TAILQ_INSERT_TAIL(&mae->action_sets, action_set, entries);
1047 *action_setp = action_set;
1049 sfc_dbg(sa, "added action_set=%p", action_set);
1055 sfc_mae_action_set_del(struct sfc_adapter *sa,
1056 struct sfc_mae_action_set *action_set)
1058 struct sfc_mae *mae = &sa->mae;
1060 SFC_ASSERT(sfc_adapter_is_locked(sa));
1061 SFC_ASSERT(action_set->refcnt != 0);
1063 --(action_set->refcnt);
1065 if (action_set->refcnt != 0)
1068 if (action_set->fw_rsrc.aset_id.id != EFX_MAE_RSRC_ID_INVALID ||
1069 action_set->fw_rsrc.refcnt != 0) {
1070 sfc_err(sa, "deleting action_set=%p abandons its FW resource: AS_ID=0x%08x, refcnt=%u",
1071 action_set, action_set->fw_rsrc.aset_id.id,
1072 action_set->fw_rsrc.refcnt);
1075 efx_mae_action_set_spec_fini(sa->nic, action_set->spec);
1076 sfc_mae_encap_header_del(sa, action_set->encap_header);
1077 sfc_mae_mac_addr_del(sa, action_set->dst_mac_addr);
1078 sfc_mae_mac_addr_del(sa, action_set->src_mac_addr);
1079 if (action_set->n_counters > 0) {
1080 SFC_ASSERT(action_set->n_counters == 1);
1081 SFC_ASSERT(action_set->counters[0].mae_id.id ==
1082 EFX_MAE_RSRC_ID_INVALID);
1083 rte_free(action_set->counters);
1085 TAILQ_REMOVE(&mae->action_sets, action_set, entries);
1086 rte_free(action_set);
1088 sfc_dbg(sa, "deleted action_set=%p", action_set);
1092 sfc_mae_action_set_enable(struct sfc_adapter *sa,
1093 struct sfc_mae_action_set *action_set)
1095 struct sfc_mae_encap_header *encap_header = action_set->encap_header;
1096 struct sfc_mae_mac_addr *dst_mac_addr = action_set->dst_mac_addr;
1097 struct sfc_mae_mac_addr *src_mac_addr = action_set->src_mac_addr;
1098 struct sfc_mae_counter_id *counters = action_set->counters;
1099 struct sfc_mae_fw_rsrc *fw_rsrc = &action_set->fw_rsrc;
1102 SFC_ASSERT(sfc_adapter_is_locked(sa));
1104 if (fw_rsrc->refcnt == 0) {
1105 SFC_ASSERT(fw_rsrc->aset_id.id == EFX_MAE_RSRC_ID_INVALID);
1106 SFC_ASSERT(action_set->spec != NULL);
1108 rc = sfc_mae_mac_addr_enable(sa, dst_mac_addr,
1109 SFC_MAE_MAC_ADDR_DST,
1114 rc = sfc_mae_mac_addr_enable(sa, src_mac_addr,
1115 SFC_MAE_MAC_ADDR_SRC,
1118 sfc_mae_mac_addr_disable(sa, dst_mac_addr);
1122 rc = sfc_mae_encap_header_enable(sa, encap_header,
1125 sfc_mae_mac_addr_disable(sa, src_mac_addr);
1126 sfc_mae_mac_addr_disable(sa, dst_mac_addr);
1130 rc = sfc_mae_counters_enable(sa, counters,
1131 action_set->n_counters,
1134 sfc_err(sa, "failed to enable %u MAE counters: %s",
1135 action_set->n_counters, rte_strerror(rc));
1137 sfc_mae_encap_header_disable(sa, encap_header);
1138 sfc_mae_mac_addr_disable(sa, src_mac_addr);
1139 sfc_mae_mac_addr_disable(sa, dst_mac_addr);
1143 rc = efx_mae_action_set_alloc(sa->nic, action_set->spec,
1146 sfc_err(sa, "failed to enable action_set=%p: %s",
1147 action_set, strerror(rc));
1149 (void)sfc_mae_counters_disable(sa, counters,
1150 action_set->n_counters);
1151 sfc_mae_encap_header_disable(sa, encap_header);
1152 sfc_mae_mac_addr_disable(sa, src_mac_addr);
1153 sfc_mae_mac_addr_disable(sa, dst_mac_addr);
1157 sfc_dbg(sa, "enabled action_set=%p: AS_ID=0x%08x",
1158 action_set, fw_rsrc->aset_id.id);
1161 ++(fw_rsrc->refcnt);
1167 sfc_mae_action_set_disable(struct sfc_adapter *sa,
1168 struct sfc_mae_action_set *action_set)
1170 struct sfc_mae_fw_rsrc *fw_rsrc = &action_set->fw_rsrc;
1173 SFC_ASSERT(sfc_adapter_is_locked(sa));
1175 if (fw_rsrc->aset_id.id == EFX_MAE_RSRC_ID_INVALID ||
1176 fw_rsrc->refcnt == 0) {
1177 sfc_err(sa, "failed to disable action_set=%p: already disabled; AS_ID=0x%08x, refcnt=%u",
1178 action_set, fw_rsrc->aset_id.id, fw_rsrc->refcnt);
1182 if (fw_rsrc->refcnt == 1) {
1183 rc = efx_mae_action_set_free(sa->nic, &fw_rsrc->aset_id);
1185 sfc_dbg(sa, "disabled action_set=%p with AS_ID=0x%08x",
1186 action_set, fw_rsrc->aset_id.id);
1188 sfc_err(sa, "failed to disable action_set=%p with AS_ID=0x%08x: %s",
1189 action_set, fw_rsrc->aset_id.id, strerror(rc));
1191 fw_rsrc->aset_id.id = EFX_MAE_RSRC_ID_INVALID;
1193 rc = sfc_mae_counters_disable(sa, action_set->counters,
1194 action_set->n_counters);
1196 sfc_err(sa, "failed to disable %u MAE counters: %s",
1197 action_set->n_counters, rte_strerror(rc));
1200 sfc_mae_encap_header_disable(sa, action_set->encap_header);
1201 sfc_mae_mac_addr_disable(sa, action_set->src_mac_addr);
1202 sfc_mae_mac_addr_disable(sa, action_set->dst_mac_addr);
1205 --(fw_rsrc->refcnt);
1209 sfc_mae_flow_cleanup(struct sfc_adapter *sa,
1210 struct rte_flow *flow)
1212 struct sfc_flow_spec_mae *spec_mae;
1217 spec_mae = &flow->spec.mae;
1219 if (spec_mae->ft_ctx != NULL) {
1220 if (spec_mae->ft_rule_type == SFC_FT_RULE_TUNNEL)
1221 spec_mae->ft_ctx->tunnel_rule_is_set = B_FALSE;
1223 SFC_ASSERT(spec_mae->ft_ctx->refcnt != 0);
1224 --(spec_mae->ft_ctx->refcnt);
1227 SFC_ASSERT(spec_mae->rule_id.id == EFX_MAE_RSRC_ID_INVALID);
1229 if (spec_mae->outer_rule != NULL)
1230 sfc_mae_outer_rule_del(sa, spec_mae->outer_rule);
1232 if (spec_mae->action_set != NULL)
1233 sfc_mae_action_set_del(sa, spec_mae->action_set);
1235 if (spec_mae->match_spec != NULL)
1236 efx_mae_match_spec_fini(sa->nic, spec_mae->match_spec);
1240 sfc_mae_set_ethertypes(struct sfc_mae_parse_ctx *ctx)
1242 struct sfc_mae_pattern_data *pdata = &ctx->pattern_data;
1243 const efx_mae_field_id_t *fremap = ctx->field_ids_remap;
1244 const efx_mae_field_id_t field_ids[] = {
1245 EFX_MAE_FIELD_VLAN0_PROTO_BE,
1246 EFX_MAE_FIELD_VLAN1_PROTO_BE,
1248 const struct sfc_mae_ethertype *et;
1253 * In accordance with RTE flow API convention, the innermost L2
1254 * item's "type" ("inner_type") is a L3 EtherType. If there is
1255 * no L3 item, it's 0x0000/0x0000.
1257 et = &pdata->ethertypes[pdata->nb_vlan_tags];
1258 rc = efx_mae_match_spec_field_set(ctx->match_spec,
1259 fremap[EFX_MAE_FIELD_ETHER_TYPE_BE],
1261 (const uint8_t *)&et->value,
1263 (const uint8_t *)&et->mask);
1268 * sfc_mae_rule_parse_item_vlan() has already made sure
1269 * that pdata->nb_vlan_tags does not exceed this figure.
1271 RTE_BUILD_BUG_ON(SFC_MAE_MATCH_VLAN_MAX_NTAGS != 2);
1273 for (i = 0; i < pdata->nb_vlan_tags; ++i) {
1274 et = &pdata->ethertypes[i];
1276 rc = efx_mae_match_spec_field_set(ctx->match_spec,
1277 fremap[field_ids[i]],
1279 (const uint8_t *)&et->value,
1281 (const uint8_t *)&et->mask);
1290 sfc_mae_rule_process_pattern_data(struct sfc_mae_parse_ctx *ctx,
1291 struct rte_flow_error *error)
1293 const efx_mae_field_id_t *fremap = ctx->field_ids_remap;
1294 struct sfc_mae_pattern_data *pdata = &ctx->pattern_data;
1295 struct sfc_mae_ethertype *ethertypes = pdata->ethertypes;
1296 const rte_be16_t supported_tpids[] = {
1297 /* VLAN standard TPID (always the first element) */
1298 RTE_BE16(RTE_ETHER_TYPE_VLAN),
1300 /* Double-tagging TPIDs */
1301 RTE_BE16(RTE_ETHER_TYPE_QINQ),
1302 RTE_BE16(RTE_ETHER_TYPE_QINQ1),
1303 RTE_BE16(RTE_ETHER_TYPE_QINQ2),
1304 RTE_BE16(RTE_ETHER_TYPE_QINQ3),
1306 bool enforce_tag_presence[SFC_MAE_MATCH_VLAN_MAX_NTAGS] = {0};
1307 unsigned int nb_supported_tpids = RTE_DIM(supported_tpids);
1308 unsigned int ethertype_idx;
1309 const uint8_t *valuep;
1310 const uint8_t *maskp;
1313 if (pdata->innermost_ethertype_restriction.mask != 0 &&
1314 pdata->nb_vlan_tags < SFC_MAE_MATCH_VLAN_MAX_NTAGS) {
1316 * If a single item VLAN is followed by a L3 item, value
1317 * of "type" in item ETH can't be a double-tagging TPID.
1319 nb_supported_tpids = 1;
1323 * sfc_mae_rule_parse_item_vlan() has already made sure
1324 * that pdata->nb_vlan_tags does not exceed this figure.
1326 RTE_BUILD_BUG_ON(SFC_MAE_MATCH_VLAN_MAX_NTAGS != 2);
1328 for (ethertype_idx = 0;
1329 ethertype_idx < pdata->nb_vlan_tags; ++ethertype_idx) {
1330 rte_be16_t tpid_v = ethertypes[ethertype_idx].value;
1331 rte_be16_t tpid_m = ethertypes[ethertype_idx].mask;
1332 unsigned int tpid_idx;
1335 * This loop can have only two iterations. On the second one,
1336 * drop outer tag presence enforcement bit because the inner
1337 * tag presence automatically assumes that for the outer tag.
1339 enforce_tag_presence[0] = B_FALSE;
1341 if (tpid_m == RTE_BE16(0)) {
1342 if (pdata->tci_masks[ethertype_idx] == RTE_BE16(0))
1343 enforce_tag_presence[ethertype_idx] = B_TRUE;
1345 /* No match on this field, and no value check. */
1346 nb_supported_tpids = 1;
1350 /* Exact match is supported only. */
1351 if (tpid_m != RTE_BE16(0xffff)) {
1352 sfc_err(ctx->sa, "TPID mask must be 0x0 or 0xffff; got 0x%04x",
1353 rte_be_to_cpu_16(tpid_m));
1358 for (tpid_idx = pdata->nb_vlan_tags - ethertype_idx - 1;
1359 tpid_idx < nb_supported_tpids; ++tpid_idx) {
1360 if (tpid_v == supported_tpids[tpid_idx])
1364 if (tpid_idx == nb_supported_tpids) {
1365 sfc_err(ctx->sa, "TPID 0x%04x is unsupported",
1366 rte_be_to_cpu_16(tpid_v));
1371 nb_supported_tpids = 1;
1374 if (pdata->innermost_ethertype_restriction.mask == RTE_BE16(0xffff)) {
1375 struct sfc_mae_ethertype *et = ðertypes[ethertype_idx];
1376 rte_be16_t enforced_et;
1378 enforced_et = pdata->innermost_ethertype_restriction.value;
1380 if (et->mask == 0) {
1381 et->mask = RTE_BE16(0xffff);
1382 et->value = enforced_et;
1383 } else if (et->mask != RTE_BE16(0xffff) ||
1384 et->value != enforced_et) {
1385 sfc_err(ctx->sa, "L3 EtherType must be 0x0/0x0 or 0x%04x/0xffff; got 0x%04x/0x%04x",
1386 rte_be_to_cpu_16(enforced_et),
1387 rte_be_to_cpu_16(et->value),
1388 rte_be_to_cpu_16(et->mask));
1395 * Now, when the number of VLAN tags is known, set fields
1396 * ETHER_TYPE, VLAN0_PROTO and VLAN1_PROTO so that the first
1397 * one is either a valid L3 EtherType (or 0x0000/0x0000),
1398 * and the last two are valid TPIDs (or 0x0000/0x0000).
1400 rc = sfc_mae_set_ethertypes(ctx);
1404 if (pdata->l3_next_proto_restriction_mask == 0xff) {
1405 if (pdata->l3_next_proto_mask == 0) {
1406 pdata->l3_next_proto_mask = 0xff;
1407 pdata->l3_next_proto_value =
1408 pdata->l3_next_proto_restriction_value;
1409 } else if (pdata->l3_next_proto_mask != 0xff ||
1410 pdata->l3_next_proto_value !=
1411 pdata->l3_next_proto_restriction_value) {
1412 sfc_err(ctx->sa, "L3 next protocol must be 0x0/0x0 or 0x%02x/0xff; got 0x%02x/0x%02x",
1413 pdata->l3_next_proto_restriction_value,
1414 pdata->l3_next_proto_value,
1415 pdata->l3_next_proto_mask);
1421 if (enforce_tag_presence[0] || pdata->has_ovlan_mask) {
1422 rc = efx_mae_match_spec_bit_set(ctx->match_spec,
1423 fremap[EFX_MAE_FIELD_HAS_OVLAN],
1424 enforce_tag_presence[0] ||
1425 pdata->has_ovlan_value);
1430 if (enforce_tag_presence[1] || pdata->has_ivlan_mask) {
1431 rc = efx_mae_match_spec_bit_set(ctx->match_spec,
1432 fremap[EFX_MAE_FIELD_HAS_IVLAN],
1433 enforce_tag_presence[1] ||
1434 pdata->has_ivlan_value);
1439 valuep = (const uint8_t *)&pdata->l3_next_proto_value;
1440 maskp = (const uint8_t *)&pdata->l3_next_proto_mask;
1441 rc = efx_mae_match_spec_field_set(ctx->match_spec,
1442 fremap[EFX_MAE_FIELD_IP_PROTO],
1443 sizeof(pdata->l3_next_proto_value),
1445 sizeof(pdata->l3_next_proto_mask),
1453 return rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1454 "Failed to process pattern data");
1458 sfc_mae_rule_parse_item_mark(const struct rte_flow_item *item,
1459 struct sfc_flow_parse_ctx *ctx,
1460 struct rte_flow_error *error)
1462 const struct rte_flow_item_mark *spec = item->spec;
1463 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1464 struct sfc_ft_ctx *ft_ctx = ctx_mae->ft_ctx;
1467 return rte_flow_error_set(error, EINVAL,
1468 RTE_FLOW_ERROR_TYPE_ITEM, item,
1469 "NULL spec in item MARK");
1473 * This item is used in tunnel offload support only.
1474 * It must go before any network header items. This
1475 * way, sfc_mae_rule_preparse_item_mark() must have
1476 * already parsed it. Only one item MARK is allowed.
1478 if (ctx_mae->ft_rule_type != SFC_FT_RULE_SWITCH ||
1479 spec->id != (uint32_t)SFC_FT_CTX_ID_TO_FLOW_MARK(ft_ctx->id)) {
1480 return rte_flow_error_set(error, EINVAL,
1481 RTE_FLOW_ERROR_TYPE_ITEM,
1482 item, "invalid item MARK");
1489 sfc_mae_rule_parse_item_port_id(const struct rte_flow_item *item,
1490 struct sfc_flow_parse_ctx *ctx,
1491 struct rte_flow_error *error)
1493 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1494 const struct rte_flow_item_port_id supp_mask = {
1497 const void *def_mask = &rte_flow_item_port_id_mask;
1498 const struct rte_flow_item_port_id *spec = NULL;
1499 const struct rte_flow_item_port_id *mask = NULL;
1500 efx_mport_sel_t mport_sel;
1503 if (ctx_mae->match_mport_set) {
1504 return rte_flow_error_set(error, ENOTSUP,
1505 RTE_FLOW_ERROR_TYPE_ITEM, item,
1506 "Can't handle multiple traffic source items");
1509 rc = sfc_flow_parse_init(item,
1510 (const void **)&spec, (const void **)&mask,
1511 (const void *)&supp_mask, def_mask,
1512 sizeof(struct rte_flow_item_port_id), error);
1516 if (mask->id != supp_mask.id) {
1517 return rte_flow_error_set(error, EINVAL,
1518 RTE_FLOW_ERROR_TYPE_ITEM, item,
1519 "Bad mask in the PORT_ID pattern item");
1522 /* If "spec" is not set, could be any port ID */
1526 if (spec->id > UINT16_MAX) {
1527 return rte_flow_error_set(error, EOVERFLOW,
1528 RTE_FLOW_ERROR_TYPE_ITEM, item,
1529 "The port ID is too large");
1532 rc = sfc_mae_switch_get_ethdev_mport(ctx_mae->sa->mae.switch_domain_id,
1533 spec->id, &mport_sel);
1535 return rte_flow_error_set(error, rc,
1536 RTE_FLOW_ERROR_TYPE_ITEM, item,
1537 "Can't get m-port for the given ethdev");
1540 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec,
1543 return rte_flow_error_set(error, rc,
1544 RTE_FLOW_ERROR_TYPE_ITEM, item,
1545 "Failed to set MPORT for the port ID");
1548 ctx_mae->match_mport_set = B_TRUE;
1554 sfc_mae_rule_parse_item_ethdev_based(const struct rte_flow_item *item,
1555 struct sfc_flow_parse_ctx *ctx,
1556 struct rte_flow_error *error)
1558 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1559 const struct rte_flow_item_ethdev supp_mask = {
1562 const void *def_mask = &rte_flow_item_ethdev_mask;
1563 const struct rte_flow_item_ethdev *spec = NULL;
1564 const struct rte_flow_item_ethdev *mask = NULL;
1565 efx_mport_sel_t mport_sel;
1568 if (ctx_mae->match_mport_set) {
1569 return rte_flow_error_set(error, ENOTSUP,
1570 RTE_FLOW_ERROR_TYPE_ITEM, item,
1571 "Can't handle multiple traffic source items");
1574 rc = sfc_flow_parse_init(item,
1575 (const void **)&spec, (const void **)&mask,
1576 (const void *)&supp_mask, def_mask,
1577 sizeof(struct rte_flow_item_ethdev), error);
1581 if (mask->port_id != supp_mask.port_id) {
1582 return rte_flow_error_set(error, EINVAL,
1583 RTE_FLOW_ERROR_TYPE_ITEM, item,
1584 "Bad mask in the ethdev-based pattern item");
1587 /* If "spec" is not set, could be any port ID */
1591 switch (item->type) {
1592 case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
1593 rc = sfc_mae_switch_get_ethdev_mport(
1594 ctx_mae->sa->mae.switch_domain_id,
1595 spec->port_id, &mport_sel);
1597 return rte_flow_error_set(error, rc,
1598 RTE_FLOW_ERROR_TYPE_ITEM, item,
1599 "Can't get m-port for the given ethdev");
1602 case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
1603 rc = sfc_mae_switch_get_entity_mport(
1604 ctx_mae->sa->mae.switch_domain_id,
1605 spec->port_id, &mport_sel);
1607 return rte_flow_error_set(error, rc,
1608 RTE_FLOW_ERROR_TYPE_ITEM, item,
1609 "Can't get m-port for the given ethdev");
1613 return rte_flow_error_set(error, EINVAL,
1614 RTE_FLOW_ERROR_TYPE_ITEM, item,
1615 "Unsupported ethdev-based flow item");
1618 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec,
1621 return rte_flow_error_set(error, rc,
1622 RTE_FLOW_ERROR_TYPE_ITEM, item,
1623 "Failed to set MPORT for the port ID");
1626 ctx_mae->match_mport_set = B_TRUE;
1632 sfc_mae_rule_parse_item_phy_port(const struct rte_flow_item *item,
1633 struct sfc_flow_parse_ctx *ctx,
1634 struct rte_flow_error *error)
1636 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1637 const struct rte_flow_item_phy_port supp_mask = {
1638 .index = 0xffffffff,
1640 const void *def_mask = &rte_flow_item_phy_port_mask;
1641 const struct rte_flow_item_phy_port *spec = NULL;
1642 const struct rte_flow_item_phy_port *mask = NULL;
1643 efx_mport_sel_t mport_v;
1646 if (ctx_mae->match_mport_set) {
1647 return rte_flow_error_set(error, ENOTSUP,
1648 RTE_FLOW_ERROR_TYPE_ITEM, item,
1649 "Can't handle multiple traffic source items");
1652 rc = sfc_flow_parse_init(item,
1653 (const void **)&spec, (const void **)&mask,
1654 (const void *)&supp_mask, def_mask,
1655 sizeof(struct rte_flow_item_phy_port), error);
1659 if (mask->index != supp_mask.index) {
1660 return rte_flow_error_set(error, EINVAL,
1661 RTE_FLOW_ERROR_TYPE_ITEM, item,
1662 "Bad mask in the PHY_PORT pattern item");
1665 /* If "spec" is not set, could be any physical port */
1669 rc = efx_mae_mport_by_phy_port(spec->index, &mport_v);
1671 return rte_flow_error_set(error, rc,
1672 RTE_FLOW_ERROR_TYPE_ITEM, item,
1673 "Failed to convert the PHY_PORT index");
1676 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec, &mport_v, NULL);
1678 return rte_flow_error_set(error, rc,
1679 RTE_FLOW_ERROR_TYPE_ITEM, item,
1680 "Failed to set MPORT for the PHY_PORT");
1683 ctx_mae->match_mport_set = B_TRUE;
1689 sfc_mae_rule_parse_item_pf(const struct rte_flow_item *item,
1690 struct sfc_flow_parse_ctx *ctx,
1691 struct rte_flow_error *error)
1693 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1694 const efx_nic_cfg_t *encp = efx_nic_cfg_get(ctx_mae->sa->nic);
1695 efx_mport_sel_t mport_v;
1698 if (ctx_mae->match_mport_set) {
1699 return rte_flow_error_set(error, ENOTSUP,
1700 RTE_FLOW_ERROR_TYPE_ITEM, item,
1701 "Can't handle multiple traffic source items");
1704 rc = efx_mae_mport_by_pcie_function(encp->enc_pf, EFX_PCI_VF_INVALID,
1707 return rte_flow_error_set(error, rc,
1708 RTE_FLOW_ERROR_TYPE_ITEM, item,
1709 "Failed to convert the PF ID");
1712 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec, &mport_v, NULL);
1714 return rte_flow_error_set(error, rc,
1715 RTE_FLOW_ERROR_TYPE_ITEM, item,
1716 "Failed to set MPORT for the PF");
1719 ctx_mae->match_mport_set = B_TRUE;
1725 sfc_mae_rule_parse_item_vf(const struct rte_flow_item *item,
1726 struct sfc_flow_parse_ctx *ctx,
1727 struct rte_flow_error *error)
1729 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1730 const efx_nic_cfg_t *encp = efx_nic_cfg_get(ctx_mae->sa->nic);
1731 const struct rte_flow_item_vf supp_mask = {
1734 const void *def_mask = &rte_flow_item_vf_mask;
1735 const struct rte_flow_item_vf *spec = NULL;
1736 const struct rte_flow_item_vf *mask = NULL;
1737 efx_mport_sel_t mport_v;
1740 if (ctx_mae->match_mport_set) {
1741 return rte_flow_error_set(error, ENOTSUP,
1742 RTE_FLOW_ERROR_TYPE_ITEM, item,
1743 "Can't handle multiple traffic source items");
1746 rc = sfc_flow_parse_init(item,
1747 (const void **)&spec, (const void **)&mask,
1748 (const void *)&supp_mask, def_mask,
1749 sizeof(struct rte_flow_item_vf), error);
1753 if (mask->id != supp_mask.id) {
1754 return rte_flow_error_set(error, EINVAL,
1755 RTE_FLOW_ERROR_TYPE_ITEM, item,
1756 "Bad mask in the VF pattern item");
1760 * If "spec" is not set, the item requests any VF related to the
1761 * PF of the current DPDK port (but not the PF itself).
1762 * Reject this match criterion as unsupported.
1765 return rte_flow_error_set(error, EINVAL,
1766 RTE_FLOW_ERROR_TYPE_ITEM, item,
1767 "Bad spec in the VF pattern item");
1770 rc = efx_mae_mport_by_pcie_function(encp->enc_pf, spec->id, &mport_v);
1772 return rte_flow_error_set(error, rc,
1773 RTE_FLOW_ERROR_TYPE_ITEM, item,
1774 "Failed to convert the PF + VF IDs");
1777 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec, &mport_v, NULL);
1779 return rte_flow_error_set(error, rc,
1780 RTE_FLOW_ERROR_TYPE_ITEM, item,
1781 "Failed to set MPORT for the PF + VF");
1784 ctx_mae->match_mport_set = B_TRUE;
1790 * Having this field ID in a field locator means that this
1791 * locator cannot be used to actually set the field at the
1792 * time when the corresponding item gets encountered. Such
1793 * fields get stashed in the parsing context instead. This
1794 * is required to resolve dependencies between the stashed
1795 * fields. See sfc_mae_rule_process_pattern_data().
1797 #define SFC_MAE_FIELD_HANDLING_DEFERRED EFX_MAE_FIELD_NIDS
1799 struct sfc_mae_field_locator {
1800 efx_mae_field_id_t field_id;
1802 /* Field offset in the corresponding rte_flow_item_ struct */
1807 sfc_mae_item_build_supp_mask(const struct sfc_mae_field_locator *field_locators,
1808 unsigned int nb_field_locators, void *mask_ptr,
1813 memset(mask_ptr, 0, mask_size);
1815 for (i = 0; i < nb_field_locators; ++i) {
1816 const struct sfc_mae_field_locator *fl = &field_locators[i];
1818 SFC_ASSERT(fl->ofst + fl->size <= mask_size);
1819 memset(RTE_PTR_ADD(mask_ptr, fl->ofst), 0xff, fl->size);
1824 sfc_mae_parse_item(const struct sfc_mae_field_locator *field_locators,
1825 unsigned int nb_field_locators, const uint8_t *spec,
1826 const uint8_t *mask, struct sfc_mae_parse_ctx *ctx,
1827 struct rte_flow_error *error)
1829 const efx_mae_field_id_t *fremap = ctx->field_ids_remap;
1833 for (i = 0; i < nb_field_locators; ++i) {
1834 const struct sfc_mae_field_locator *fl = &field_locators[i];
1836 if (fl->field_id == SFC_MAE_FIELD_HANDLING_DEFERRED)
1839 rc = efx_mae_match_spec_field_set(ctx->match_spec,
1840 fremap[fl->field_id],
1841 fl->size, spec + fl->ofst,
1842 fl->size, mask + fl->ofst);
1848 rc = rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM,
1849 NULL, "Failed to process item fields");
1855 static const struct sfc_mae_field_locator flocs_eth[] = {
1858 * This locator is used only for building supported fields mask.
1859 * The field is handled by sfc_mae_rule_process_pattern_data().
1861 SFC_MAE_FIELD_HANDLING_DEFERRED,
1862 RTE_SIZEOF_FIELD(struct rte_flow_item_eth, type),
1863 offsetof(struct rte_flow_item_eth, type),
1866 EFX_MAE_FIELD_ETH_DADDR_BE,
1867 RTE_SIZEOF_FIELD(struct rte_flow_item_eth, dst),
1868 offsetof(struct rte_flow_item_eth, dst),
1871 EFX_MAE_FIELD_ETH_SADDR_BE,
1872 RTE_SIZEOF_FIELD(struct rte_flow_item_eth, src),
1873 offsetof(struct rte_flow_item_eth, src),
1878 sfc_mae_rule_parse_item_eth(const struct rte_flow_item *item,
1879 struct sfc_flow_parse_ctx *ctx,
1880 struct rte_flow_error *error)
1882 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1883 struct rte_flow_item_eth override_mask;
1884 struct rte_flow_item_eth supp_mask;
1885 const uint8_t *spec = NULL;
1886 const uint8_t *mask = NULL;
1889 sfc_mae_item_build_supp_mask(flocs_eth, RTE_DIM(flocs_eth),
1890 &supp_mask, sizeof(supp_mask));
1891 supp_mask.has_vlan = 1;
1893 rc = sfc_flow_parse_init(item,
1894 (const void **)&spec, (const void **)&mask,
1895 (const void *)&supp_mask,
1896 &rte_flow_item_eth_mask,
1897 sizeof(struct rte_flow_item_eth), error);
1901 if (ctx_mae->ft_rule_type == SFC_FT_RULE_TUNNEL && mask != NULL) {
1903 * The HW/FW hasn't got support for match on MAC addresses in
1904 * outer rules yet (this will change). Match on VLAN presence
1905 * isn't supported either. Ignore these match criteria.
1907 memcpy(&override_mask, mask, sizeof(override_mask));
1908 memset(&override_mask.hdr.dst_addr, 0,
1909 sizeof(override_mask.hdr.dst_addr));
1910 memset(&override_mask.hdr.src_addr, 0,
1911 sizeof(override_mask.hdr.src_addr));
1912 override_mask.has_vlan = 0;
1914 mask = (const uint8_t *)&override_mask;
1918 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
1919 struct sfc_mae_ethertype *ethertypes = pdata->ethertypes;
1920 const struct rte_flow_item_eth *item_spec;
1921 const struct rte_flow_item_eth *item_mask;
1923 item_spec = (const struct rte_flow_item_eth *)spec;
1924 item_mask = (const struct rte_flow_item_eth *)mask;
1927 * Remember various match criteria in the parsing context.
1928 * sfc_mae_rule_process_pattern_data() will consider them
1929 * altogether when the rest of the items have been parsed.
1931 ethertypes[0].value = item_spec->type;
1932 ethertypes[0].mask = item_mask->type;
1933 if (item_mask->has_vlan) {
1934 pdata->has_ovlan_mask = B_TRUE;
1935 if (item_spec->has_vlan)
1936 pdata->has_ovlan_value = B_TRUE;
1940 * The specification is empty. The overall pattern
1941 * validity will be enforced at the end of parsing.
1942 * See sfc_mae_rule_process_pattern_data().
1947 return sfc_mae_parse_item(flocs_eth, RTE_DIM(flocs_eth), spec, mask,
1951 static const struct sfc_mae_field_locator flocs_vlan[] = {
1954 EFX_MAE_FIELD_VLAN0_TCI_BE,
1955 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, tci),
1956 offsetof(struct rte_flow_item_vlan, tci),
1960 * This locator is used only for building supported fields mask.
1961 * The field is handled by sfc_mae_rule_process_pattern_data().
1963 SFC_MAE_FIELD_HANDLING_DEFERRED,
1964 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, inner_type),
1965 offsetof(struct rte_flow_item_vlan, inner_type),
1970 EFX_MAE_FIELD_VLAN1_TCI_BE,
1971 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, tci),
1972 offsetof(struct rte_flow_item_vlan, tci),
1976 * This locator is used only for building supported fields mask.
1977 * The field is handled by sfc_mae_rule_process_pattern_data().
1979 SFC_MAE_FIELD_HANDLING_DEFERRED,
1980 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, inner_type),
1981 offsetof(struct rte_flow_item_vlan, inner_type),
1986 sfc_mae_rule_parse_item_vlan(const struct rte_flow_item *item,
1987 struct sfc_flow_parse_ctx *ctx,
1988 struct rte_flow_error *error)
1990 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1991 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
1992 boolean_t *has_vlan_mp_by_nb_tags[SFC_MAE_MATCH_VLAN_MAX_NTAGS] = {
1993 &pdata->has_ovlan_mask,
1994 &pdata->has_ivlan_mask,
1996 boolean_t *has_vlan_vp_by_nb_tags[SFC_MAE_MATCH_VLAN_MAX_NTAGS] = {
1997 &pdata->has_ovlan_value,
1998 &pdata->has_ivlan_value,
2000 boolean_t *cur_tag_presence_bit_mp;
2001 boolean_t *cur_tag_presence_bit_vp;
2002 const struct sfc_mae_field_locator *flocs;
2003 struct rte_flow_item_vlan supp_mask;
2004 const uint8_t *spec = NULL;
2005 const uint8_t *mask = NULL;
2006 unsigned int nb_flocs;
2009 RTE_BUILD_BUG_ON(SFC_MAE_MATCH_VLAN_MAX_NTAGS != 2);
2011 if (pdata->nb_vlan_tags == SFC_MAE_MATCH_VLAN_MAX_NTAGS) {
2012 return rte_flow_error_set(error, ENOTSUP,
2013 RTE_FLOW_ERROR_TYPE_ITEM, item,
2014 "Can't match that many VLAN tags");
2017 cur_tag_presence_bit_mp = has_vlan_mp_by_nb_tags[pdata->nb_vlan_tags];
2018 cur_tag_presence_bit_vp = has_vlan_vp_by_nb_tags[pdata->nb_vlan_tags];
2020 if (*cur_tag_presence_bit_mp == B_TRUE &&
2021 *cur_tag_presence_bit_vp == B_FALSE) {
2022 return rte_flow_error_set(error, EINVAL,
2023 RTE_FLOW_ERROR_TYPE_ITEM, item,
2024 "The previous item enforces no (more) VLAN, "
2025 "so the current item (VLAN) must not exist");
2028 nb_flocs = RTE_DIM(flocs_vlan) / SFC_MAE_MATCH_VLAN_MAX_NTAGS;
2029 flocs = flocs_vlan + pdata->nb_vlan_tags * nb_flocs;
2031 sfc_mae_item_build_supp_mask(flocs, nb_flocs,
2032 &supp_mask, sizeof(supp_mask));
2034 * This only means that the field is supported by the driver and libefx.
2035 * Support on NIC level will be checked when all items have been parsed.
2037 supp_mask.has_more_vlan = 1;
2039 rc = sfc_flow_parse_init(item,
2040 (const void **)&spec, (const void **)&mask,
2041 (const void *)&supp_mask,
2042 &rte_flow_item_vlan_mask,
2043 sizeof(struct rte_flow_item_vlan), error);
2048 struct sfc_mae_ethertype *et = pdata->ethertypes;
2049 const struct rte_flow_item_vlan *item_spec;
2050 const struct rte_flow_item_vlan *item_mask;
2052 item_spec = (const struct rte_flow_item_vlan *)spec;
2053 item_mask = (const struct rte_flow_item_vlan *)mask;
2056 * Remember various match criteria in the parsing context.
2057 * sfc_mae_rule_process_pattern_data() will consider them
2058 * altogether when the rest of the items have been parsed.
2060 et[pdata->nb_vlan_tags + 1].value = item_spec->inner_type;
2061 et[pdata->nb_vlan_tags + 1].mask = item_mask->inner_type;
2062 pdata->tci_masks[pdata->nb_vlan_tags] = item_mask->tci;
2063 if (item_mask->has_more_vlan) {
2064 if (pdata->nb_vlan_tags ==
2065 SFC_MAE_MATCH_VLAN_MAX_NTAGS) {
2066 return rte_flow_error_set(error, ENOTSUP,
2067 RTE_FLOW_ERROR_TYPE_ITEM, item,
2068 "Can't use 'has_more_vlan' in "
2069 "the second item VLAN");
2071 pdata->has_ivlan_mask = B_TRUE;
2072 if (item_spec->has_more_vlan)
2073 pdata->has_ivlan_value = B_TRUE;
2076 /* Convert TCI to MAE representation right now. */
2077 rc = sfc_mae_parse_item(flocs, nb_flocs, spec, mask,
2083 ++(pdata->nb_vlan_tags);
2088 static const struct sfc_mae_field_locator flocs_ipv4[] = {
2090 EFX_MAE_FIELD_SRC_IP4_BE,
2091 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.src_addr),
2092 offsetof(struct rte_flow_item_ipv4, hdr.src_addr),
2095 EFX_MAE_FIELD_DST_IP4_BE,
2096 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.dst_addr),
2097 offsetof(struct rte_flow_item_ipv4, hdr.dst_addr),
2101 * This locator is used only for building supported fields mask.
2102 * The field is handled by sfc_mae_rule_process_pattern_data().
2104 SFC_MAE_FIELD_HANDLING_DEFERRED,
2105 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.next_proto_id),
2106 offsetof(struct rte_flow_item_ipv4, hdr.next_proto_id),
2109 EFX_MAE_FIELD_IP_TOS,
2110 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4,
2111 hdr.type_of_service),
2112 offsetof(struct rte_flow_item_ipv4, hdr.type_of_service),
2115 EFX_MAE_FIELD_IP_TTL,
2116 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.time_to_live),
2117 offsetof(struct rte_flow_item_ipv4, hdr.time_to_live),
2122 sfc_mae_rule_parse_item_ipv4(const struct rte_flow_item *item,
2123 struct sfc_flow_parse_ctx *ctx,
2124 struct rte_flow_error *error)
2126 rte_be16_t ethertype_ipv4_be = RTE_BE16(RTE_ETHER_TYPE_IPV4);
2127 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
2128 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
2129 struct rte_flow_item_ipv4 supp_mask;
2130 const uint8_t *spec = NULL;
2131 const uint8_t *mask = NULL;
2134 sfc_mae_item_build_supp_mask(flocs_ipv4, RTE_DIM(flocs_ipv4),
2135 &supp_mask, sizeof(supp_mask));
2137 rc = sfc_flow_parse_init(item,
2138 (const void **)&spec, (const void **)&mask,
2139 (const void *)&supp_mask,
2140 &rte_flow_item_ipv4_mask,
2141 sizeof(struct rte_flow_item_ipv4), error);
2145 pdata->innermost_ethertype_restriction.value = ethertype_ipv4_be;
2146 pdata->innermost_ethertype_restriction.mask = RTE_BE16(0xffff);
2149 const struct rte_flow_item_ipv4 *item_spec;
2150 const struct rte_flow_item_ipv4 *item_mask;
2152 item_spec = (const struct rte_flow_item_ipv4 *)spec;
2153 item_mask = (const struct rte_flow_item_ipv4 *)mask;
2155 pdata->l3_next_proto_value = item_spec->hdr.next_proto_id;
2156 pdata->l3_next_proto_mask = item_mask->hdr.next_proto_id;
2161 return sfc_mae_parse_item(flocs_ipv4, RTE_DIM(flocs_ipv4), spec, mask,
2165 static const struct sfc_mae_field_locator flocs_ipv6[] = {
2167 EFX_MAE_FIELD_SRC_IP6_BE,
2168 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.src_addr),
2169 offsetof(struct rte_flow_item_ipv6, hdr.src_addr),
2172 EFX_MAE_FIELD_DST_IP6_BE,
2173 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.dst_addr),
2174 offsetof(struct rte_flow_item_ipv6, hdr.dst_addr),
2178 * This locator is used only for building supported fields mask.
2179 * The field is handled by sfc_mae_rule_process_pattern_data().
2181 SFC_MAE_FIELD_HANDLING_DEFERRED,
2182 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.proto),
2183 offsetof(struct rte_flow_item_ipv6, hdr.proto),
2186 EFX_MAE_FIELD_IP_TTL,
2187 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.hop_limits),
2188 offsetof(struct rte_flow_item_ipv6, hdr.hop_limits),
2193 sfc_mae_rule_parse_item_ipv6(const struct rte_flow_item *item,
2194 struct sfc_flow_parse_ctx *ctx,
2195 struct rte_flow_error *error)
2197 rte_be16_t ethertype_ipv6_be = RTE_BE16(RTE_ETHER_TYPE_IPV6);
2198 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
2199 const efx_mae_field_id_t *fremap = ctx_mae->field_ids_remap;
2200 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
2201 struct rte_flow_item_ipv6 supp_mask;
2202 const uint8_t *spec = NULL;
2203 const uint8_t *mask = NULL;
2204 rte_be32_t vtc_flow_be;
2210 sfc_mae_item_build_supp_mask(flocs_ipv6, RTE_DIM(flocs_ipv6),
2211 &supp_mask, sizeof(supp_mask));
2213 vtc_flow_be = RTE_BE32(RTE_IPV6_HDR_TC_MASK);
2214 memcpy(&supp_mask, &vtc_flow_be, sizeof(vtc_flow_be));
2216 rc = sfc_flow_parse_init(item,
2217 (const void **)&spec, (const void **)&mask,
2218 (const void *)&supp_mask,
2219 &rte_flow_item_ipv6_mask,
2220 sizeof(struct rte_flow_item_ipv6), error);
2224 pdata->innermost_ethertype_restriction.value = ethertype_ipv6_be;
2225 pdata->innermost_ethertype_restriction.mask = RTE_BE16(0xffff);
2228 const struct rte_flow_item_ipv6 *item_spec;
2229 const struct rte_flow_item_ipv6 *item_mask;
2231 item_spec = (const struct rte_flow_item_ipv6 *)spec;
2232 item_mask = (const struct rte_flow_item_ipv6 *)mask;
2234 pdata->l3_next_proto_value = item_spec->hdr.proto;
2235 pdata->l3_next_proto_mask = item_mask->hdr.proto;
2240 rc = sfc_mae_parse_item(flocs_ipv6, RTE_DIM(flocs_ipv6), spec, mask,
2245 memcpy(&vtc_flow_be, spec, sizeof(vtc_flow_be));
2246 vtc_flow = rte_be_to_cpu_32(vtc_flow_be);
2247 tc_value = (vtc_flow & RTE_IPV6_HDR_TC_MASK) >> RTE_IPV6_HDR_TC_SHIFT;
2249 memcpy(&vtc_flow_be, mask, sizeof(vtc_flow_be));
2250 vtc_flow = rte_be_to_cpu_32(vtc_flow_be);
2251 tc_mask = (vtc_flow & RTE_IPV6_HDR_TC_MASK) >> RTE_IPV6_HDR_TC_SHIFT;
2253 rc = efx_mae_match_spec_field_set(ctx_mae->match_spec,
2254 fremap[EFX_MAE_FIELD_IP_TOS],
2255 sizeof(tc_value), &tc_value,
2256 sizeof(tc_mask), &tc_mask);
2258 return rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM,
2259 NULL, "Failed to process item fields");
2265 static const struct sfc_mae_field_locator flocs_tcp[] = {
2267 EFX_MAE_FIELD_L4_SPORT_BE,
2268 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.src_port),
2269 offsetof(struct rte_flow_item_tcp, hdr.src_port),
2272 EFX_MAE_FIELD_L4_DPORT_BE,
2273 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.dst_port),
2274 offsetof(struct rte_flow_item_tcp, hdr.dst_port),
2277 EFX_MAE_FIELD_TCP_FLAGS_BE,
2279 * The values have been picked intentionally since the
2280 * target MAE field is oversize (16 bit). This mapping
2281 * relies on the fact that the MAE field is big-endian.
2283 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.data_off) +
2284 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.tcp_flags),
2285 offsetof(struct rte_flow_item_tcp, hdr.data_off),
2290 sfc_mae_rule_parse_item_tcp(const struct rte_flow_item *item,
2291 struct sfc_flow_parse_ctx *ctx,
2292 struct rte_flow_error *error)
2294 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
2295 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
2296 struct rte_flow_item_tcp supp_mask;
2297 const uint8_t *spec = NULL;
2298 const uint8_t *mask = NULL;
2302 * When encountered among outermost items, item TCP is invalid.
2303 * Check which match specification is being constructed now.
2305 if (ctx_mae->match_spec != ctx_mae->match_spec_action) {
2306 return rte_flow_error_set(error, EINVAL,
2307 RTE_FLOW_ERROR_TYPE_ITEM, item,
2308 "TCP in outer frame is invalid");
2311 sfc_mae_item_build_supp_mask(flocs_tcp, RTE_DIM(flocs_tcp),
2312 &supp_mask, sizeof(supp_mask));
2314 rc = sfc_flow_parse_init(item,
2315 (const void **)&spec, (const void **)&mask,
2316 (const void *)&supp_mask,
2317 &rte_flow_item_tcp_mask,
2318 sizeof(struct rte_flow_item_tcp), error);
2322 pdata->l3_next_proto_restriction_value = IPPROTO_TCP;
2323 pdata->l3_next_proto_restriction_mask = 0xff;
2328 return sfc_mae_parse_item(flocs_tcp, RTE_DIM(flocs_tcp), spec, mask,
2332 static const struct sfc_mae_field_locator flocs_udp[] = {
2334 EFX_MAE_FIELD_L4_SPORT_BE,
2335 RTE_SIZEOF_FIELD(struct rte_flow_item_udp, hdr.src_port),
2336 offsetof(struct rte_flow_item_udp, hdr.src_port),
2339 EFX_MAE_FIELD_L4_DPORT_BE,
2340 RTE_SIZEOF_FIELD(struct rte_flow_item_udp, hdr.dst_port),
2341 offsetof(struct rte_flow_item_udp, hdr.dst_port),
2346 sfc_mae_rule_parse_item_udp(const struct rte_flow_item *item,
2347 struct sfc_flow_parse_ctx *ctx,
2348 struct rte_flow_error *error)
2350 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
2351 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
2352 struct rte_flow_item_udp supp_mask;
2353 const uint8_t *spec = NULL;
2354 const uint8_t *mask = NULL;
2357 sfc_mae_item_build_supp_mask(flocs_udp, RTE_DIM(flocs_udp),
2358 &supp_mask, sizeof(supp_mask));
2360 rc = sfc_flow_parse_init(item,
2361 (const void **)&spec, (const void **)&mask,
2362 (const void *)&supp_mask,
2363 &rte_flow_item_udp_mask,
2364 sizeof(struct rte_flow_item_udp), error);
2368 pdata->l3_next_proto_restriction_value = IPPROTO_UDP;
2369 pdata->l3_next_proto_restriction_mask = 0xff;
2374 return sfc_mae_parse_item(flocs_udp, RTE_DIM(flocs_udp), spec, mask,
2378 static const struct sfc_mae_field_locator flocs_tunnel[] = {
2381 * The size and offset values are relevant
2382 * for Geneve and NVGRE, too.
2384 .size = RTE_SIZEOF_FIELD(struct rte_flow_item_vxlan, vni),
2385 .ofst = offsetof(struct rte_flow_item_vxlan, vni),
2390 * An auxiliary registry which allows using non-encap. field IDs
2391 * directly when building a match specification of type ACTION.
2393 * See sfc_mae_rule_parse_pattern() and sfc_mae_rule_parse_item_tunnel().
2395 static const efx_mae_field_id_t field_ids_no_remap[] = {
2396 #define FIELD_ID_NO_REMAP(_field) \
2397 [EFX_MAE_FIELD_##_field] = EFX_MAE_FIELD_##_field
2399 FIELD_ID_NO_REMAP(ETHER_TYPE_BE),
2400 FIELD_ID_NO_REMAP(ETH_SADDR_BE),
2401 FIELD_ID_NO_REMAP(ETH_DADDR_BE),
2402 FIELD_ID_NO_REMAP(VLAN0_TCI_BE),
2403 FIELD_ID_NO_REMAP(VLAN0_PROTO_BE),
2404 FIELD_ID_NO_REMAP(VLAN1_TCI_BE),
2405 FIELD_ID_NO_REMAP(VLAN1_PROTO_BE),
2406 FIELD_ID_NO_REMAP(SRC_IP4_BE),
2407 FIELD_ID_NO_REMAP(DST_IP4_BE),
2408 FIELD_ID_NO_REMAP(IP_PROTO),
2409 FIELD_ID_NO_REMAP(IP_TOS),
2410 FIELD_ID_NO_REMAP(IP_TTL),
2411 FIELD_ID_NO_REMAP(SRC_IP6_BE),
2412 FIELD_ID_NO_REMAP(DST_IP6_BE),
2413 FIELD_ID_NO_REMAP(L4_SPORT_BE),
2414 FIELD_ID_NO_REMAP(L4_DPORT_BE),
2415 FIELD_ID_NO_REMAP(TCP_FLAGS_BE),
2416 FIELD_ID_NO_REMAP(HAS_OVLAN),
2417 FIELD_ID_NO_REMAP(HAS_IVLAN),
2419 #undef FIELD_ID_NO_REMAP
2423 * An auxiliary registry which allows using "ENC" field IDs
2424 * when building a match specification of type OUTER.
2426 * See sfc_mae_rule_encap_parse_init().
2428 static const efx_mae_field_id_t field_ids_remap_to_encap[] = {
2429 #define FIELD_ID_REMAP_TO_ENCAP(_field) \
2430 [EFX_MAE_FIELD_##_field] = EFX_MAE_FIELD_ENC_##_field
2432 FIELD_ID_REMAP_TO_ENCAP(ETHER_TYPE_BE),
2433 FIELD_ID_REMAP_TO_ENCAP(ETH_SADDR_BE),
2434 FIELD_ID_REMAP_TO_ENCAP(ETH_DADDR_BE),
2435 FIELD_ID_REMAP_TO_ENCAP(VLAN0_TCI_BE),
2436 FIELD_ID_REMAP_TO_ENCAP(VLAN0_PROTO_BE),
2437 FIELD_ID_REMAP_TO_ENCAP(VLAN1_TCI_BE),
2438 FIELD_ID_REMAP_TO_ENCAP(VLAN1_PROTO_BE),
2439 FIELD_ID_REMAP_TO_ENCAP(SRC_IP4_BE),
2440 FIELD_ID_REMAP_TO_ENCAP(DST_IP4_BE),
2441 FIELD_ID_REMAP_TO_ENCAP(IP_PROTO),
2442 FIELD_ID_REMAP_TO_ENCAP(IP_TOS),
2443 FIELD_ID_REMAP_TO_ENCAP(IP_TTL),
2444 FIELD_ID_REMAP_TO_ENCAP(SRC_IP6_BE),
2445 FIELD_ID_REMAP_TO_ENCAP(DST_IP6_BE),
2446 FIELD_ID_REMAP_TO_ENCAP(L4_SPORT_BE),
2447 FIELD_ID_REMAP_TO_ENCAP(L4_DPORT_BE),
2448 FIELD_ID_REMAP_TO_ENCAP(HAS_OVLAN),
2449 FIELD_ID_REMAP_TO_ENCAP(HAS_IVLAN),
2451 #undef FIELD_ID_REMAP_TO_ENCAP
2455 sfc_mae_rule_parse_item_tunnel(const struct rte_flow_item *item,
2456 struct sfc_flow_parse_ctx *ctx,
2457 struct rte_flow_error *error)
2459 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
2460 uint8_t vnet_id_v[sizeof(uint32_t)] = {0};
2461 uint8_t vnet_id_m[sizeof(uint32_t)] = {0};
2462 const struct rte_flow_item_vxlan *vxp;
2463 uint8_t supp_mask[sizeof(uint64_t)];
2464 const uint8_t *spec = NULL;
2465 const uint8_t *mask = NULL;
2468 if (ctx_mae->ft_rule_type == SFC_FT_RULE_SWITCH) {
2470 * As a workaround, pattern processing has started from
2471 * this (tunnel) item. No pattern data to process yet.
2475 * We're about to start processing inner frame items.
2476 * Process pattern data that has been deferred so far
2477 * and reset pattern data storage.
2479 rc = sfc_mae_rule_process_pattern_data(ctx_mae, error);
2484 memset(&ctx_mae->pattern_data, 0, sizeof(ctx_mae->pattern_data));
2486 sfc_mae_item_build_supp_mask(flocs_tunnel, RTE_DIM(flocs_tunnel),
2487 &supp_mask, sizeof(supp_mask));
2490 * This tunnel item was preliminarily detected by
2491 * sfc_mae_rule_encap_parse_init(). Default mask
2492 * was also picked by that helper. Use it here.
2494 rc = sfc_flow_parse_init(item,
2495 (const void **)&spec, (const void **)&mask,
2496 (const void *)&supp_mask,
2497 ctx_mae->tunnel_def_mask,
2498 ctx_mae->tunnel_def_mask_size, error);
2503 * This item and later ones comprise a
2504 * match specification of type ACTION.
2506 ctx_mae->match_spec = ctx_mae->match_spec_action;
2508 /* This item and later ones use non-encap. EFX MAE field IDs. */
2509 ctx_mae->field_ids_remap = field_ids_no_remap;
2515 * Field EFX_MAE_FIELD_ENC_VNET_ID_BE is a 32-bit one.
2516 * Copy 24-bit VNI, which is BE, at offset 1 in it.
2517 * The extra byte is 0 both in the mask and in the value.
2519 vxp = (const struct rte_flow_item_vxlan *)spec;
2520 memcpy(vnet_id_v + 1, &vxp->vni, sizeof(vxp->vni));
2522 vxp = (const struct rte_flow_item_vxlan *)mask;
2523 memcpy(vnet_id_m + 1, &vxp->vni, sizeof(vxp->vni));
2525 rc = efx_mae_match_spec_field_set(ctx_mae->match_spec,
2526 EFX_MAE_FIELD_ENC_VNET_ID_BE,
2527 sizeof(vnet_id_v), vnet_id_v,
2528 sizeof(vnet_id_m), vnet_id_m);
2530 rc = rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM,
2531 item, "Failed to set VXLAN VNI");
2537 static const struct sfc_flow_item sfc_flow_items[] = {
2539 .type = RTE_FLOW_ITEM_TYPE_MARK,
2541 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2542 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2543 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2544 .parse = sfc_mae_rule_parse_item_mark,
2547 .type = RTE_FLOW_ITEM_TYPE_PORT_ID,
2550 * In terms of RTE flow, this item is a META one,
2551 * and its position in the pattern is don't care.
2553 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2554 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2555 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2556 .parse = sfc_mae_rule_parse_item_port_id,
2559 .type = RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR,
2560 .name = "PORT_REPRESENTOR",
2562 * In terms of RTE flow, this item is a META one,
2563 * and its position in the pattern is don't care.
2565 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2566 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2567 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2568 .parse = sfc_mae_rule_parse_item_ethdev_based,
2571 .type = RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT,
2572 .name = "REPRESENTED_PORT",
2574 * In terms of RTE flow, this item is a META one,
2575 * and its position in the pattern is don't care.
2577 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2578 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2579 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2580 .parse = sfc_mae_rule_parse_item_ethdev_based,
2583 .type = RTE_FLOW_ITEM_TYPE_PHY_PORT,
2586 * In terms of RTE flow, this item is a META one,
2587 * and its position in the pattern is don't care.
2589 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2590 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2591 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2592 .parse = sfc_mae_rule_parse_item_phy_port,
2595 .type = RTE_FLOW_ITEM_TYPE_PF,
2598 * In terms of RTE flow, this item is a META one,
2599 * and its position in the pattern is don't care.
2601 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2602 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2603 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2604 .parse = sfc_mae_rule_parse_item_pf,
2607 .type = RTE_FLOW_ITEM_TYPE_VF,
2610 * In terms of RTE flow, this item is a META one,
2611 * and its position in the pattern is don't care.
2613 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2614 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2615 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2616 .parse = sfc_mae_rule_parse_item_vf,
2619 .type = RTE_FLOW_ITEM_TYPE_ETH,
2621 .prev_layer = SFC_FLOW_ITEM_START_LAYER,
2622 .layer = SFC_FLOW_ITEM_L2,
2623 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2624 .parse = sfc_mae_rule_parse_item_eth,
2627 .type = RTE_FLOW_ITEM_TYPE_VLAN,
2629 .prev_layer = SFC_FLOW_ITEM_L2,
2630 .layer = SFC_FLOW_ITEM_L2,
2631 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2632 .parse = sfc_mae_rule_parse_item_vlan,
2635 .type = RTE_FLOW_ITEM_TYPE_IPV4,
2637 .prev_layer = SFC_FLOW_ITEM_L2,
2638 .layer = SFC_FLOW_ITEM_L3,
2639 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2640 .parse = sfc_mae_rule_parse_item_ipv4,
2643 .type = RTE_FLOW_ITEM_TYPE_IPV6,
2645 .prev_layer = SFC_FLOW_ITEM_L2,
2646 .layer = SFC_FLOW_ITEM_L3,
2647 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2648 .parse = sfc_mae_rule_parse_item_ipv6,
2651 .type = RTE_FLOW_ITEM_TYPE_TCP,
2653 .prev_layer = SFC_FLOW_ITEM_L3,
2654 .layer = SFC_FLOW_ITEM_L4,
2655 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2656 .parse = sfc_mae_rule_parse_item_tcp,
2659 .type = RTE_FLOW_ITEM_TYPE_UDP,
2661 .prev_layer = SFC_FLOW_ITEM_L3,
2662 .layer = SFC_FLOW_ITEM_L4,
2663 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2664 .parse = sfc_mae_rule_parse_item_udp,
2667 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
2669 .prev_layer = SFC_FLOW_ITEM_L4,
2670 .layer = SFC_FLOW_ITEM_START_LAYER,
2671 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2672 .parse = sfc_mae_rule_parse_item_tunnel,
2675 .type = RTE_FLOW_ITEM_TYPE_GENEVE,
2677 .prev_layer = SFC_FLOW_ITEM_L4,
2678 .layer = SFC_FLOW_ITEM_START_LAYER,
2679 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2680 .parse = sfc_mae_rule_parse_item_tunnel,
2683 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
2685 .prev_layer = SFC_FLOW_ITEM_L3,
2686 .layer = SFC_FLOW_ITEM_START_LAYER,
2687 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2688 .parse = sfc_mae_rule_parse_item_tunnel,
2693 sfc_mae_rule_process_outer(struct sfc_adapter *sa,
2694 struct sfc_mae_parse_ctx *ctx,
2695 struct sfc_mae_outer_rule **rulep,
2696 struct rte_flow_error *error)
2698 efx_mae_rule_id_t invalid_rule_id = { .id = EFX_MAE_RSRC_ID_INVALID };
2701 if (ctx->encap_type == EFX_TUNNEL_PROTOCOL_NONE) {
2706 SFC_ASSERT(ctx->match_spec_outer != NULL);
2708 if (!efx_mae_match_spec_is_valid(sa->nic, ctx->match_spec_outer)) {
2709 return rte_flow_error_set(error, ENOTSUP,
2710 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2711 "Inconsistent pattern (outer)");
2714 *rulep = sfc_mae_outer_rule_attach(sa, ctx->match_spec_outer,
2716 if (*rulep != NULL) {
2717 efx_mae_match_spec_fini(sa->nic, ctx->match_spec_outer);
2719 rc = sfc_mae_outer_rule_add(sa, ctx->match_spec_outer,
2720 ctx->encap_type, rulep);
2722 return rte_flow_error_set(error, rc,
2723 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2724 "Failed to process the pattern");
2728 /* The spec has now been tracked by the outer rule entry. */
2729 ctx->match_spec_outer = NULL;
2732 switch (ctx->ft_rule_type) {
2733 case SFC_FT_RULE_NONE:
2735 case SFC_FT_RULE_TUNNEL:
2736 /* No action rule */
2738 case SFC_FT_RULE_SWITCH:
2740 * Match on recirculation ID rather than
2741 * on the outer rule allocation handle.
2743 rc = efx_mae_match_spec_recirc_id_set(ctx->match_spec_action,
2744 SFC_FT_CTX_ID_TO_CTX_MARK(ctx->ft_ctx->id));
2746 return rte_flow_error_set(error, rc,
2747 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2748 "FT: SWITCH: AR: failed to request match on RECIRC_ID");
2752 SFC_ASSERT(B_FALSE);
2756 * In MAE, lookup sequence comprises outer parse, outer rule lookup,
2757 * inner parse (when some outer rule is hit) and action rule lookup.
2758 * If the currently processed flow does not come with an outer rule,
2759 * its action rule must be available only for packets which miss in
2760 * outer rule table. Set OR_ID match field to 0xffffffff/0xffffffff
2761 * in the action rule specification; this ensures correct behaviour.
2763 * If, on the other hand, this flow does have an outer rule, its ID
2764 * may be unknown at the moment (not yet allocated), but OR_ID mask
2765 * has to be set to 0xffffffff anyway for correct class comparisons.
2766 * When the outer rule has been allocated, this match field will be
2767 * overridden by sfc_mae_outer_rule_enable() to use the right value.
2769 rc = efx_mae_match_spec_outer_rule_id_set(ctx->match_spec_action,
2773 sfc_mae_outer_rule_del(sa, *rulep);
2777 return rte_flow_error_set(error, rc,
2778 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2779 "Failed to process the pattern");
2786 sfc_mae_rule_preparse_item_mark(const struct rte_flow_item_mark *spec,
2787 struct sfc_mae_parse_ctx *ctx)
2789 struct sfc_ft_ctx *ft_ctx;
2793 sfc_err(ctx->sa, "FT: SWITCH: NULL spec in item MARK");
2797 ft_ctx = sfc_ft_ctx_pick(ctx->sa, spec->id);
2798 if (ft_ctx == NULL) {
2799 sfc_err(ctx->sa, "FT: SWITCH: invalid context");
2803 if (ft_ctx->refcnt == 0) {
2804 sfc_err(ctx->sa, "FT: SWITCH: inactive context (ID=%u)",
2809 user_mark = SFC_FT_FLOW_MARK_TO_USER_MARK(spec->id);
2810 if (user_mark != 0) {
2811 sfc_err(ctx->sa, "FT: SWITCH: invalid item MARK");
2815 sfc_dbg(ctx->sa, "FT: SWITCH: detected");
2817 ctx->ft_rule_type = SFC_FT_RULE_SWITCH;
2818 ctx->ft_ctx = ft_ctx;
2824 sfc_mae_rule_encap_parse_init(struct sfc_adapter *sa,
2825 struct sfc_mae_parse_ctx *ctx,
2826 struct rte_flow_error *error)
2828 const struct rte_flow_item *pattern = ctx->pattern;
2829 struct sfc_mae *mae = &sa->mae;
2830 uint8_t recirc_id = 0;
2833 if (pattern == NULL) {
2834 rte_flow_error_set(error, EINVAL,
2835 RTE_FLOW_ERROR_TYPE_ITEM_NUM, NULL,
2841 switch (pattern->type) {
2842 case RTE_FLOW_ITEM_TYPE_MARK:
2843 rc = sfc_mae_rule_preparse_item_mark(pattern->spec,
2846 return rte_flow_error_set(error, rc,
2847 RTE_FLOW_ERROR_TYPE_ITEM,
2848 pattern, "FT: SWITCH: invalid item MARK");
2852 case RTE_FLOW_ITEM_TYPE_VXLAN:
2853 ctx->encap_type = EFX_TUNNEL_PROTOCOL_VXLAN;
2854 ctx->tunnel_def_mask = &rte_flow_item_vxlan_mask;
2855 ctx->tunnel_def_mask_size =
2856 sizeof(rte_flow_item_vxlan_mask);
2858 case RTE_FLOW_ITEM_TYPE_GENEVE:
2859 ctx->encap_type = EFX_TUNNEL_PROTOCOL_GENEVE;
2860 ctx->tunnel_def_mask = &rte_flow_item_geneve_mask;
2861 ctx->tunnel_def_mask_size =
2862 sizeof(rte_flow_item_geneve_mask);
2864 case RTE_FLOW_ITEM_TYPE_NVGRE:
2865 ctx->encap_type = EFX_TUNNEL_PROTOCOL_NVGRE;
2866 ctx->tunnel_def_mask = &rte_flow_item_nvgre_mask;
2867 ctx->tunnel_def_mask_size =
2868 sizeof(rte_flow_item_nvgre_mask);
2870 case RTE_FLOW_ITEM_TYPE_END:
2880 switch (ctx->ft_rule_type) {
2881 case SFC_FT_RULE_NONE:
2882 if (pattern->type == RTE_FLOW_ITEM_TYPE_END)
2885 case SFC_FT_RULE_TUNNEL:
2886 if (pattern->type != RTE_FLOW_ITEM_TYPE_END) {
2887 return rte_flow_error_set(error, ENOTSUP,
2888 RTE_FLOW_ERROR_TYPE_ITEM,
2889 pattern, "FT: TUNNEL: invalid item");
2891 ctx->encap_type = ctx->ft_ctx->encap_type;
2893 case SFC_FT_RULE_SWITCH:
2894 if (pattern->type == RTE_FLOW_ITEM_TYPE_END) {
2895 return rte_flow_error_set(error, EINVAL,
2896 RTE_FLOW_ERROR_TYPE_ITEM,
2897 NULL, "FT: SWITCH: missing tunnel item");
2898 } else if (ctx->encap_type != ctx->ft_ctx->encap_type) {
2899 return rte_flow_error_set(error, EINVAL,
2900 RTE_FLOW_ERROR_TYPE_ITEM,
2901 pattern, "FT: SWITCH: tunnel type mismatch");
2905 * The HW/FW hasn't got support for the use of "ENC" fields in
2906 * action rules (except the VNET_ID one) yet. As a workaround,
2907 * start parsing the pattern from the tunnel item.
2909 ctx->pattern = pattern;
2912 SFC_ASSERT(B_FALSE);
2916 if ((mae->encap_types_supported & (1U << ctx->encap_type)) == 0) {
2917 return rte_flow_error_set(error, ENOTSUP,
2918 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2919 "OR: unsupported tunnel type");
2922 switch (ctx->ft_rule_type) {
2923 case SFC_FT_RULE_TUNNEL:
2924 recirc_id = SFC_FT_CTX_ID_TO_CTX_MARK(ctx->ft_ctx->id);
2926 case SFC_FT_RULE_NONE:
2927 if (ctx->priority >= mae->nb_outer_rule_prios_max) {
2928 return rte_flow_error_set(error, ENOTSUP,
2929 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
2930 NULL, "OR: unsupported priority level");
2933 rc = efx_mae_match_spec_init(sa->nic,
2934 EFX_MAE_RULE_OUTER, ctx->priority,
2935 &ctx->match_spec_outer);
2937 return rte_flow_error_set(error, rc,
2938 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2939 "OR: failed to initialise the match specification");
2943 * Outermost items comprise a match
2944 * specification of type OUTER.
2946 ctx->match_spec = ctx->match_spec_outer;
2948 /* Outermost items use "ENC" EFX MAE field IDs. */
2949 ctx->field_ids_remap = field_ids_remap_to_encap;
2951 rc = efx_mae_outer_rule_recirc_id_set(ctx->match_spec,
2954 return rte_flow_error_set(error, rc,
2955 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2956 "OR: failed to initialise RECIRC_ID");
2959 case SFC_FT_RULE_SWITCH:
2960 /* Outermost items -> "ENC" match fields in the action rule. */
2961 ctx->field_ids_remap = field_ids_remap_to_encap;
2962 ctx->match_spec = ctx->match_spec_action;
2964 /* No own outer rule; match on TUNNEL OR's RECIRC_ID is used. */
2965 ctx->encap_type = EFX_TUNNEL_PROTOCOL_NONE;
2968 SFC_ASSERT(B_FALSE);
2976 sfc_mae_rule_encap_parse_fini(struct sfc_adapter *sa,
2977 struct sfc_mae_parse_ctx *ctx)
2979 if (ctx->encap_type == EFX_TUNNEL_PROTOCOL_NONE)
2982 if (ctx->match_spec_outer != NULL)
2983 efx_mae_match_spec_fini(sa->nic, ctx->match_spec_outer);
2987 sfc_mae_rule_parse_pattern(struct sfc_adapter *sa,
2988 const struct rte_flow_item pattern[],
2989 struct sfc_flow_spec_mae *spec,
2990 struct rte_flow_error *error)
2992 struct sfc_mae_parse_ctx ctx_mae;
2993 unsigned int priority_shift = 0;
2994 struct sfc_flow_parse_ctx ctx;
2997 memset(&ctx_mae, 0, sizeof(ctx_mae));
2998 ctx_mae.ft_rule_type = spec->ft_rule_type;
2999 ctx_mae.priority = spec->priority;
3000 ctx_mae.ft_ctx = spec->ft_ctx;
3003 switch (ctx_mae.ft_rule_type) {
3004 case SFC_FT_RULE_TUNNEL:
3006 * By design, this flow should be represented solely by the
3007 * outer rule. But the HW/FW hasn't got support for setting
3008 * Rx mark from RECIRC_ID on outer rule lookup yet. Neither
3009 * does it support outer rule counters. As a workaround, an
3010 * action rule of lower priority is used to do the job.
3015 case SFC_FT_RULE_SWITCH:
3016 if (ctx_mae.priority != 0) {
3018 * Because of the above workaround, deny the use
3019 * of priorities to TUNNEL and SWITCH rules.
3021 rc = rte_flow_error_set(error, ENOTSUP,
3022 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, NULL,
3023 "FT: priorities are not supported");
3024 goto fail_priority_check;
3028 case SFC_FT_RULE_NONE:
3029 rc = efx_mae_match_spec_init(sa->nic, EFX_MAE_RULE_ACTION,
3030 spec->priority + priority_shift,
3031 &ctx_mae.match_spec_action);
3033 rc = rte_flow_error_set(error, rc,
3034 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
3035 "AR: failed to initialise the match specification");
3036 goto fail_init_match_spec_action;
3040 SFC_ASSERT(B_FALSE);
3045 * As a preliminary setting, assume that there is no encapsulation
3046 * in the pattern. That is, pattern items are about to comprise a
3047 * match specification of type ACTION and use non-encap. field IDs.
3049 * sfc_mae_rule_encap_parse_init() below may override this.
3051 ctx_mae.encap_type = EFX_TUNNEL_PROTOCOL_NONE;
3052 ctx_mae.match_spec = ctx_mae.match_spec_action;
3053 ctx_mae.field_ids_remap = field_ids_no_remap;
3054 ctx_mae.pattern = pattern;
3056 ctx.type = SFC_FLOW_PARSE_CTX_MAE;
3059 rc = sfc_mae_rule_encap_parse_init(sa, &ctx_mae, error);
3061 goto fail_encap_parse_init;
3064 * sfc_mae_rule_encap_parse_init() may have detected tunnel offload
3065 * SWITCH rule. Remember its properties for later use.
3067 spec->ft_rule_type = ctx_mae.ft_rule_type;
3068 spec->ft_ctx = ctx_mae.ft_ctx;
3070 rc = sfc_flow_parse_pattern(sa, sfc_flow_items, RTE_DIM(sfc_flow_items),
3071 ctx_mae.pattern, &ctx, error);
3073 goto fail_parse_pattern;
3075 rc = sfc_mae_rule_process_pattern_data(&ctx_mae, error);
3077 goto fail_process_pattern_data;
3079 rc = sfc_mae_rule_process_outer(sa, &ctx_mae, &spec->outer_rule, error);
3081 goto fail_process_outer;
3083 if (ctx_mae.match_spec_action != NULL &&
3084 !efx_mae_match_spec_is_valid(sa->nic, ctx_mae.match_spec_action)) {
3085 rc = rte_flow_error_set(error, ENOTSUP,
3086 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
3087 "Inconsistent pattern");
3088 goto fail_validate_match_spec_action;
3091 spec->match_spec = ctx_mae.match_spec_action;
3095 fail_validate_match_spec_action:
3097 fail_process_pattern_data:
3099 sfc_mae_rule_encap_parse_fini(sa, &ctx_mae);
3101 fail_encap_parse_init:
3102 if (ctx_mae.match_spec_action != NULL)
3103 efx_mae_match_spec_fini(sa->nic, ctx_mae.match_spec_action);
3105 fail_init_match_spec_action:
3106 fail_priority_check:
3111 sfc_mae_rule_parse_action_set_mac(struct sfc_adapter *sa,
3112 enum sfc_mae_mac_addr_type type,
3113 const struct rte_flow_action_set_mac *conf,
3114 struct sfc_mae_aset_ctx *ctx,
3115 struct rte_flow_error *error)
3117 struct sfc_mae_mac_addr **mac_addrp;
3121 return rte_flow_error_set(error, EINVAL,
3122 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3123 "the MAC address entry definition is NULL");
3127 case SFC_MAE_MAC_ADDR_DST:
3128 rc = efx_mae_action_set_populate_set_dst_mac(ctx->spec);
3129 mac_addrp = &ctx->dst_mac;
3131 case SFC_MAE_MAC_ADDR_SRC:
3132 rc = efx_mae_action_set_populate_set_src_mac(ctx->spec);
3133 mac_addrp = &ctx->src_mac;
3143 *mac_addrp = sfc_mae_mac_addr_attach(sa, conf->mac_addr);
3144 if (*mac_addrp != NULL)
3147 rc = sfc_mae_mac_addr_add(sa, conf->mac_addr, mac_addrp);
3154 return rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ACTION,
3155 NULL, "failed to request set MAC action");
3159 * An action supported by MAE may correspond to a bundle of RTE flow actions,
3160 * in example, VLAN_PUSH = OF_PUSH_VLAN + OF_VLAN_SET_VID + OF_VLAN_SET_PCP.
3161 * That is, related RTE flow actions need to be tracked as parts of a whole
3162 * so that they can be combined into a single action and submitted to MAE
3163 * representation of a given rule's action set.
3165 * Each RTE flow action provided by an application gets classified as
3166 * one belonging to some bundle type. If an action is not supposed to
3167 * belong to any bundle, or if this action is END, it is described as
3168 * one belonging to a dummy bundle of type EMPTY.
3170 * A currently tracked bundle will be submitted if a repeating
3171 * action or an action of different bundle type follows.
3174 enum sfc_mae_actions_bundle_type {
3175 SFC_MAE_ACTIONS_BUNDLE_EMPTY = 0,
3176 SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH,
3179 struct sfc_mae_actions_bundle {
3180 enum sfc_mae_actions_bundle_type type;
3182 /* Indicates actions already tracked by the current bundle */
3183 uint64_t actions_mask;
3185 /* Parameters used by SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH */
3186 rte_be16_t vlan_push_tpid;
3187 rte_be16_t vlan_push_tci;
3191 * Combine configuration of RTE flow actions tracked by the bundle into a
3192 * single action and submit the result to MAE action set specification.
3193 * Do nothing in the case of dummy action bundle.
3196 sfc_mae_actions_bundle_submit(const struct sfc_mae_actions_bundle *bundle,
3197 efx_mae_actions_t *spec)
3201 switch (bundle->type) {
3202 case SFC_MAE_ACTIONS_BUNDLE_EMPTY:
3204 case SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH:
3205 rc = efx_mae_action_set_populate_vlan_push(
3206 spec, bundle->vlan_push_tpid, bundle->vlan_push_tci);
3209 SFC_ASSERT(B_FALSE);
3217 * Given the type of the next RTE flow action in the line, decide
3218 * whether a new bundle is about to start, and, if this is the case,
3219 * submit and reset the current bundle.
3222 sfc_mae_actions_bundle_sync(const struct rte_flow_action *action,
3223 struct sfc_mae_actions_bundle *bundle,
3224 efx_mae_actions_t *spec,
3225 struct rte_flow_error *error)
3227 enum sfc_mae_actions_bundle_type bundle_type_new;
3230 switch (action->type) {
3231 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3232 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3233 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3234 bundle_type_new = SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH;
3238 * Self-sufficient actions, including END, are handled in this
3239 * case. No checks for unsupported actions are needed here
3240 * because parsing doesn't occur at this point.
3242 bundle_type_new = SFC_MAE_ACTIONS_BUNDLE_EMPTY;
3246 if (bundle_type_new != bundle->type ||
3247 (bundle->actions_mask & (1ULL << action->type)) != 0) {
3248 rc = sfc_mae_actions_bundle_submit(bundle, spec);
3252 memset(bundle, 0, sizeof(*bundle));
3255 bundle->type = bundle_type_new;
3260 return rte_flow_error_set(error, rc,
3261 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3262 "Failed to request the (group of) action(s)");
3266 sfc_mae_rule_parse_action_of_push_vlan(
3267 const struct rte_flow_action_of_push_vlan *conf,
3268 struct sfc_mae_actions_bundle *bundle)
3270 bundle->vlan_push_tpid = conf->ethertype;
3274 sfc_mae_rule_parse_action_of_set_vlan_vid(
3275 const struct rte_flow_action_of_set_vlan_vid *conf,
3276 struct sfc_mae_actions_bundle *bundle)
3278 bundle->vlan_push_tci |= (conf->vlan_vid &
3279 rte_cpu_to_be_16(RTE_LEN2MASK(12, uint16_t)));
3283 sfc_mae_rule_parse_action_of_set_vlan_pcp(
3284 const struct rte_flow_action_of_set_vlan_pcp *conf,
3285 struct sfc_mae_actions_bundle *bundle)
3287 uint16_t vlan_tci_pcp = (uint16_t)(conf->vlan_pcp &
3288 RTE_LEN2MASK(3, uint8_t)) << 13;
3290 bundle->vlan_push_tci |= rte_cpu_to_be_16(vlan_tci_pcp);
3293 struct sfc_mae_parsed_item {
3294 const struct rte_flow_item *item;
3295 size_t proto_header_ofst;
3296 size_t proto_header_size;
3300 * For each 16-bit word of the given header, override
3301 * bits enforced by the corresponding 16-bit mask.
3304 sfc_mae_header_force_item_masks(uint8_t *header_buf,
3305 const struct sfc_mae_parsed_item *parsed_items,
3306 unsigned int nb_parsed_items)
3308 unsigned int item_idx;
3310 for (item_idx = 0; item_idx < nb_parsed_items; ++item_idx) {
3311 const struct sfc_mae_parsed_item *parsed_item;
3312 const struct rte_flow_item *item;
3313 size_t proto_header_size;
3316 parsed_item = &parsed_items[item_idx];
3317 proto_header_size = parsed_item->proto_header_size;
3318 item = parsed_item->item;
3320 for (ofst = 0; ofst < proto_header_size;
3321 ofst += sizeof(rte_be16_t)) {
3322 rte_be16_t *wp = RTE_PTR_ADD(header_buf, ofst);
3323 const rte_be16_t *w_maskp;
3324 const rte_be16_t *w_specp;
3326 w_maskp = RTE_PTR_ADD(item->mask, ofst);
3327 w_specp = RTE_PTR_ADD(item->spec, ofst);
3330 *wp |= (*w_specp & *w_maskp);
3333 header_buf += proto_header_size;
3337 #define SFC_IPV4_TTL_DEF 0x40
3338 #define SFC_IPV6_VTC_FLOW_DEF 0x60000000
3339 #define SFC_IPV6_HOP_LIMITS_DEF 0xff
3340 #define SFC_VXLAN_FLAGS_DEF 0x08000000
3343 sfc_mae_rule_parse_action_vxlan_encap(
3344 struct sfc_mae *mae,
3345 const struct rte_flow_action_vxlan_encap *conf,
3346 efx_mae_actions_t *spec,
3347 struct rte_flow_error *error)
3349 struct sfc_mae_bounce_eh *bounce_eh = &mae->bounce_eh;
3350 struct rte_flow_item *pattern = conf->definition;
3351 uint8_t *buf = bounce_eh->buf;
3353 /* This array will keep track of non-VOID pattern items. */
3354 struct sfc_mae_parsed_item parsed_items[1 /* Ethernet */ +
3356 1 /* IPv4 or IPv6 */ +
3359 unsigned int nb_parsed_items = 0;
3361 size_t eth_ethertype_ofst = offsetof(struct rte_ether_hdr, ether_type);
3362 uint8_t dummy_buf[RTE_MAX(sizeof(struct rte_ipv4_hdr),
3363 sizeof(struct rte_ipv6_hdr))];
3364 struct rte_ipv4_hdr *ipv4 = (void *)dummy_buf;
3365 struct rte_ipv6_hdr *ipv6 = (void *)dummy_buf;
3366 struct rte_vxlan_hdr *vxlan = NULL;
3367 struct rte_udp_hdr *udp = NULL;
3368 unsigned int nb_vlan_tags = 0;
3369 size_t next_proto_ofst = 0;
3370 size_t ethertype_ofst = 0;
3374 if (pattern == NULL) {
3375 return rte_flow_error_set(error, EINVAL,
3376 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3377 "The encap. header definition is NULL");
3380 bounce_eh->type = EFX_TUNNEL_PROTOCOL_VXLAN;
3381 bounce_eh->size = 0;
3384 * Process pattern items and remember non-VOID ones.
3385 * Defer applying masks until after the complete header
3386 * has been built from the pattern items.
3388 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_ETH);
3390 for (; pattern->type != RTE_FLOW_ITEM_TYPE_END; ++pattern) {
3391 struct sfc_mae_parsed_item *parsed_item;
3392 const uint64_t exp_items_extra_vlan[] = {
3393 RTE_BIT64(RTE_FLOW_ITEM_TYPE_VLAN), 0
3395 size_t proto_header_size;
3396 rte_be16_t *ethertypep;
3397 uint8_t *next_protop;
3400 if (pattern->spec == NULL) {
3401 return rte_flow_error_set(error, EINVAL,
3402 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3403 "NULL item spec in the encap. header");
3406 if (pattern->mask == NULL) {
3407 return rte_flow_error_set(error, EINVAL,
3408 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3409 "NULL item mask in the encap. header");
3412 if (pattern->last != NULL) {
3413 /* This is not a match pattern, so disallow range. */
3414 return rte_flow_error_set(error, EINVAL,
3415 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3416 "Range item in the encap. header");
3419 if (pattern->type == RTE_FLOW_ITEM_TYPE_VOID) {
3420 /* Handle VOID separately, for clarity. */
3424 if ((exp_items & RTE_BIT64(pattern->type)) == 0) {
3425 return rte_flow_error_set(error, ENOTSUP,
3426 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3427 "Unexpected item in the encap. header");
3430 parsed_item = &parsed_items[nb_parsed_items];
3431 buf_cur = buf + bounce_eh->size;
3433 switch (pattern->type) {
3434 case RTE_FLOW_ITEM_TYPE_ETH:
3435 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_ETH,
3437 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_eth,
3440 proto_header_size = sizeof(struct rte_ether_hdr);
3442 ethertype_ofst = eth_ethertype_ofst;
3444 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_VLAN) |
3445 RTE_BIT64(RTE_FLOW_ITEM_TYPE_IPV4) |
3446 RTE_BIT64(RTE_FLOW_ITEM_TYPE_IPV6);
3448 case RTE_FLOW_ITEM_TYPE_VLAN:
3449 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_VLAN,
3451 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_vlan,
3454 proto_header_size = sizeof(struct rte_vlan_hdr);
3456 ethertypep = RTE_PTR_ADD(buf, eth_ethertype_ofst);
3457 *ethertypep = RTE_BE16(RTE_ETHER_TYPE_QINQ);
3459 ethertypep = RTE_PTR_ADD(buf, ethertype_ofst);
3460 *ethertypep = RTE_BE16(RTE_ETHER_TYPE_VLAN);
3464 offsetof(struct rte_vlan_hdr, eth_proto);
3466 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_IPV4) |
3467 RTE_BIT64(RTE_FLOW_ITEM_TYPE_IPV6);
3468 exp_items |= exp_items_extra_vlan[nb_vlan_tags];
3472 case RTE_FLOW_ITEM_TYPE_IPV4:
3473 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_IPV4,
3475 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_ipv4,
3478 proto_header_size = sizeof(struct rte_ipv4_hdr);
3480 ethertypep = RTE_PTR_ADD(buf, ethertype_ofst);
3481 *ethertypep = RTE_BE16(RTE_ETHER_TYPE_IPV4);
3485 offsetof(struct rte_ipv4_hdr, next_proto_id);
3487 ipv4 = (struct rte_ipv4_hdr *)buf_cur;
3489 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_UDP);
3491 case RTE_FLOW_ITEM_TYPE_IPV6:
3492 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_IPV6,
3494 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_ipv6,
3497 proto_header_size = sizeof(struct rte_ipv6_hdr);
3499 ethertypep = RTE_PTR_ADD(buf, ethertype_ofst);
3500 *ethertypep = RTE_BE16(RTE_ETHER_TYPE_IPV6);
3502 next_proto_ofst = bounce_eh->size +
3503 offsetof(struct rte_ipv6_hdr, proto);
3505 ipv6 = (struct rte_ipv6_hdr *)buf_cur;
3507 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_UDP);
3509 case RTE_FLOW_ITEM_TYPE_UDP:
3510 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_UDP,
3512 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_udp,
3515 proto_header_size = sizeof(struct rte_udp_hdr);
3517 next_protop = RTE_PTR_ADD(buf, next_proto_ofst);
3518 *next_protop = IPPROTO_UDP;
3520 udp = (struct rte_udp_hdr *)buf_cur;
3522 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_VXLAN);
3524 case RTE_FLOW_ITEM_TYPE_VXLAN:
3525 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_VXLAN,
3527 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_vxlan,
3530 proto_header_size = sizeof(struct rte_vxlan_hdr);
3532 vxlan = (struct rte_vxlan_hdr *)buf_cur;
3534 udp->dst_port = RTE_BE16(RTE_VXLAN_DEFAULT_PORT);
3535 udp->dgram_len = RTE_BE16(sizeof(*udp) +
3537 udp->dgram_cksum = 0;
3542 return rte_flow_error_set(error, ENOTSUP,
3543 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3544 "Unknown item in the encap. header");
3547 if (bounce_eh->size + proto_header_size > bounce_eh->buf_size) {
3548 return rte_flow_error_set(error, E2BIG,
3549 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3550 "The encap. header is too big");
3553 if ((proto_header_size & 1) != 0) {
3554 return rte_flow_error_set(error, EINVAL,
3555 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3556 "Odd layer size in the encap. header");
3559 rte_memcpy(buf_cur, pattern->spec, proto_header_size);
3560 bounce_eh->size += proto_header_size;
3562 parsed_item->item = pattern;
3563 parsed_item->proto_header_size = proto_header_size;
3567 if (exp_items != 0) {
3568 /* Parsing item VXLAN would have reset exp_items to 0. */
3569 return rte_flow_error_set(error, ENOTSUP,
3570 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3571 "No item VXLAN in the encap. header");
3574 /* One of the pointers (ipv4, ipv6) refers to a dummy area. */
3575 ipv4->version_ihl = RTE_IPV4_VHL_DEF;
3576 ipv4->time_to_live = SFC_IPV4_TTL_DEF;
3577 ipv4->total_length = RTE_BE16(sizeof(*ipv4) + sizeof(*udp) +
3579 /* The HW cannot compute this checksum. */
3580 ipv4->hdr_checksum = 0;
3581 ipv4->hdr_checksum = rte_ipv4_cksum(ipv4);
3583 ipv6->vtc_flow = RTE_BE32(SFC_IPV6_VTC_FLOW_DEF);
3584 ipv6->hop_limits = SFC_IPV6_HOP_LIMITS_DEF;
3585 ipv6->payload_len = udp->dgram_len;
3587 vxlan->vx_flags = RTE_BE32(SFC_VXLAN_FLAGS_DEF);
3589 /* Take care of the masks. */
3590 sfc_mae_header_force_item_masks(buf, parsed_items, nb_parsed_items);
3592 rc = efx_mae_action_set_populate_encap(spec);
3594 rc = rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ACTION,
3595 NULL, "failed to request action ENCAP");
3602 sfc_mae_rule_parse_action_mark(struct sfc_adapter *sa,
3603 const struct rte_flow_action_mark *conf,
3604 const struct sfc_flow_spec_mae *spec_mae,
3605 efx_mae_actions_t *spec)
3609 if (spec_mae->ft_rule_type == SFC_FT_RULE_TUNNEL) {
3610 /* Workaround. See sfc_flow_parse_rte_to_mae() */
3611 } else if (conf->id > SFC_FT_USER_MARK_MASK) {
3612 sfc_err(sa, "the mark value is too large");
3616 rc = efx_mae_action_set_populate_mark(spec, conf->id);
3618 sfc_err(sa, "failed to request action MARK: %s", strerror(rc));
3624 sfc_mae_rule_parse_action_count(struct sfc_adapter *sa,
3625 const struct rte_flow_action_count *conf
3627 efx_mae_actions_t *spec)
3631 if ((sa->counter_rxq.state & SFC_COUNTER_RXQ_INITIALIZED) == 0) {
3633 "counter queue is not configured for COUNT action");
3635 goto fail_counter_queue_uninit;
3638 if (sfc_get_service_lcore(SOCKET_ID_ANY) == RTE_MAX_LCORE) {
3640 goto fail_no_service_core;
3643 rc = efx_mae_action_set_populate_count(spec);
3646 "failed to populate counters in MAE action set: %s",
3648 goto fail_populate_count;
3653 fail_populate_count:
3654 fail_no_service_core:
3655 fail_counter_queue_uninit:
3661 sfc_mae_rule_parse_action_phy_port(struct sfc_adapter *sa,
3662 const struct rte_flow_action_phy_port *conf,
3663 efx_mae_actions_t *spec)
3665 efx_mport_sel_t mport;
3669 if (conf->original != 0)
3670 phy_port = efx_nic_cfg_get(sa->nic)->enc_assigned_port;
3672 phy_port = conf->index;
3674 rc = efx_mae_mport_by_phy_port(phy_port, &mport);
3676 sfc_err(sa, "failed to convert phys. port ID %u to m-port selector: %s",
3677 phy_port, strerror(rc));
3681 rc = efx_mae_action_set_populate_deliver(spec, &mport);
3683 sfc_err(sa, "failed to request action DELIVER with m-port selector 0x%08x: %s",
3684 mport.sel, strerror(rc));
3691 sfc_mae_rule_parse_action_pf_vf(struct sfc_adapter *sa,
3692 const struct rte_flow_action_vf *vf_conf,
3693 efx_mae_actions_t *spec)
3695 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
3696 efx_mport_sel_t mport;
3700 if (vf_conf == NULL)
3701 vf = EFX_PCI_VF_INVALID;
3702 else if (vf_conf->original != 0)
3707 rc = efx_mae_mport_by_pcie_function(encp->enc_pf, vf, &mport);
3709 sfc_err(sa, "failed to convert PF %u VF %d to m-port: %s",
3710 encp->enc_pf, (vf != EFX_PCI_VF_INVALID) ? (int)vf : -1,
3715 rc = efx_mae_action_set_populate_deliver(spec, &mport);
3717 sfc_err(sa, "failed to request action DELIVER with m-port selector 0x%08x: %s",
3718 mport.sel, strerror(rc));
3725 sfc_mae_rule_parse_action_port_id(struct sfc_adapter *sa,
3726 const struct rte_flow_action_port_id *conf,
3727 efx_mae_actions_t *spec)
3729 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
3730 struct sfc_mae *mae = &sa->mae;
3731 efx_mport_sel_t mport;
3735 if (conf->id > UINT16_MAX)
3738 port_id = (conf->original != 0) ? sas->port_id : conf->id;
3740 rc = sfc_mae_switch_get_ethdev_mport(mae->switch_domain_id,
3743 sfc_err(sa, "failed to get m-port for the given ethdev (port_id=%u): %s",
3744 port_id, strerror(rc));
3748 rc = efx_mae_action_set_populate_deliver(spec, &mport);
3750 sfc_err(sa, "failed to request action DELIVER with m-port selector 0x%08x: %s",
3751 mport.sel, strerror(rc));
3758 sfc_mae_rule_parse_action_port_representor(struct sfc_adapter *sa,
3759 const struct rte_flow_action_ethdev *conf,
3760 efx_mae_actions_t *spec)
3762 struct sfc_mae *mae = &sa->mae;
3763 efx_mport_sel_t mport;
3766 rc = sfc_mae_switch_get_ethdev_mport(mae->switch_domain_id,
3767 conf->port_id, &mport);
3769 sfc_err(sa, "failed to get m-port for the given ethdev (port_id=%u): %s",
3770 conf->port_id, strerror(rc));
3774 rc = efx_mae_action_set_populate_deliver(spec, &mport);
3776 sfc_err(sa, "failed to request action DELIVER with m-port selector 0x%08x: %s",
3777 mport.sel, strerror(rc));
3784 sfc_mae_rule_parse_action_represented_port(struct sfc_adapter *sa,
3785 const struct rte_flow_action_ethdev *conf,
3786 efx_mae_actions_t *spec)
3788 struct sfc_mae *mae = &sa->mae;
3789 efx_mport_sel_t mport;
3792 rc = sfc_mae_switch_get_entity_mport(mae->switch_domain_id,
3793 conf->port_id, &mport);
3795 sfc_err(sa, "failed to get m-port for the given ethdev (port_id=%u): %s",
3796 conf->port_id, strerror(rc));
3800 rc = efx_mae_action_set_populate_deliver(spec, &mport);
3802 sfc_err(sa, "failed to request action DELIVER with m-port selector 0x%08x: %s",
3803 mport.sel, strerror(rc));
3809 static const char * const action_names[] = {
3810 [RTE_FLOW_ACTION_TYPE_VXLAN_DECAP] = "VXLAN_DECAP",
3811 [RTE_FLOW_ACTION_TYPE_OF_POP_VLAN] = "OF_POP_VLAN",
3812 [RTE_FLOW_ACTION_TYPE_SET_MAC_DST] = "SET_MAC_DST",
3813 [RTE_FLOW_ACTION_TYPE_SET_MAC_SRC] = "SET_MAC_SRC",
3814 [RTE_FLOW_ACTION_TYPE_OF_DEC_NW_TTL] = "OF_DEC_NW_TTL",
3815 [RTE_FLOW_ACTION_TYPE_DEC_TTL] = "DEC_TTL",
3816 [RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN] = "OF_PUSH_VLAN",
3817 [RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID] = "OF_SET_VLAN_VID",
3818 [RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP] = "OF_SET_VLAN_PCP",
3819 [RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP] = "VXLAN_ENCAP",
3820 [RTE_FLOW_ACTION_TYPE_COUNT] = "COUNT",
3821 [RTE_FLOW_ACTION_TYPE_FLAG] = "FLAG",
3822 [RTE_FLOW_ACTION_TYPE_MARK] = "MARK",
3823 [RTE_FLOW_ACTION_TYPE_PHY_PORT] = "PHY_PORT",
3824 [RTE_FLOW_ACTION_TYPE_PF] = "PF",
3825 [RTE_FLOW_ACTION_TYPE_VF] = "VF",
3826 [RTE_FLOW_ACTION_TYPE_PORT_ID] = "PORT_ID",
3827 [RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR] = "PORT_REPRESENTOR",
3828 [RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT] = "REPRESENTED_PORT",
3829 [RTE_FLOW_ACTION_TYPE_DROP] = "DROP",
3830 [RTE_FLOW_ACTION_TYPE_JUMP] = "JUMP",
3834 sfc_mae_rule_parse_action(struct sfc_adapter *sa,
3835 const struct rte_flow_action *action,
3836 const struct sfc_flow_spec_mae *spec_mae,
3837 struct sfc_mae_actions_bundle *bundle,
3838 struct sfc_mae_aset_ctx *ctx,
3839 struct rte_flow_error *error)
3841 const struct sfc_mae_outer_rule *outer_rule = spec_mae->outer_rule;
3842 const uint64_t rx_metadata = sa->negotiated_rx_metadata;
3843 efx_mae_actions_t *spec = ctx->spec;
3844 bool custom_error = B_FALSE;
3847 switch (action->type) {
3848 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
3849 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VXLAN_DECAP,
3850 bundle->actions_mask);
3851 if (outer_rule == NULL ||
3852 outer_rule->encap_type != EFX_TUNNEL_PROTOCOL_VXLAN)
3855 rc = efx_mae_action_set_populate_decap(spec);
3857 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
3858 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_POP_VLAN,
3859 bundle->actions_mask);
3860 rc = efx_mae_action_set_populate_vlan_pop(spec);
3862 case RTE_FLOW_ACTION_TYPE_SET_MAC_DST:
3863 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_SET_MAC_DST,
3864 bundle->actions_mask);
3865 rc = sfc_mae_rule_parse_action_set_mac(sa, SFC_MAE_MAC_ADDR_DST,
3868 custom_error = B_TRUE;
3870 case RTE_FLOW_ACTION_TYPE_SET_MAC_SRC:
3871 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_SET_MAC_SRC,
3872 bundle->actions_mask);
3873 rc = sfc_mae_rule_parse_action_set_mac(sa, SFC_MAE_MAC_ADDR_SRC,
3876 custom_error = B_TRUE;
3878 case RTE_FLOW_ACTION_TYPE_OF_DEC_NW_TTL:
3879 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
3880 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_DEC_NW_TTL,
3881 bundle->actions_mask);
3882 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_DEC_TTL,
3883 bundle->actions_mask);
3884 rc = efx_mae_action_set_populate_decr_ip_ttl(spec);
3886 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3887 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN,
3888 bundle->actions_mask);
3889 sfc_mae_rule_parse_action_of_push_vlan(action->conf, bundle);
3891 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3892 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID,
3893 bundle->actions_mask);
3894 sfc_mae_rule_parse_action_of_set_vlan_vid(action->conf, bundle);
3896 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3897 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP,
3898 bundle->actions_mask);
3899 sfc_mae_rule_parse_action_of_set_vlan_pcp(action->conf, bundle);
3901 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3902 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP,
3903 bundle->actions_mask);
3904 rc = sfc_mae_rule_parse_action_vxlan_encap(&sa->mae,
3907 custom_error = B_TRUE;
3909 case RTE_FLOW_ACTION_TYPE_COUNT:
3910 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_COUNT,
3911 bundle->actions_mask);
3912 rc = sfc_mae_rule_parse_action_count(sa, action->conf, spec);
3914 case RTE_FLOW_ACTION_TYPE_FLAG:
3915 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_FLAG,
3916 bundle->actions_mask);
3917 if ((rx_metadata & RTE_ETH_RX_METADATA_USER_FLAG) != 0) {
3918 rc = efx_mae_action_set_populate_flag(spec);
3920 rc = rte_flow_error_set(error, ENOTSUP,
3921 RTE_FLOW_ERROR_TYPE_ACTION,
3923 "flag delivery has not been negotiated");
3924 custom_error = B_TRUE;
3927 case RTE_FLOW_ACTION_TYPE_MARK:
3928 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_MARK,
3929 bundle->actions_mask);
3930 if ((rx_metadata & RTE_ETH_RX_METADATA_USER_MARK) != 0 ||
3931 spec_mae->ft_rule_type == SFC_FT_RULE_TUNNEL) {
3932 rc = sfc_mae_rule_parse_action_mark(sa, action->conf,
3935 rc = rte_flow_error_set(error, ENOTSUP,
3936 RTE_FLOW_ERROR_TYPE_ACTION,
3938 "mark delivery has not been negotiated");
3939 custom_error = B_TRUE;
3942 case RTE_FLOW_ACTION_TYPE_PHY_PORT:
3943 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_PHY_PORT,
3944 bundle->actions_mask);
3945 rc = sfc_mae_rule_parse_action_phy_port(sa, action->conf, spec);
3947 case RTE_FLOW_ACTION_TYPE_PF:
3948 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_PF,
3949 bundle->actions_mask);
3950 rc = sfc_mae_rule_parse_action_pf_vf(sa, NULL, spec);
3952 case RTE_FLOW_ACTION_TYPE_VF:
3953 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VF,
3954 bundle->actions_mask);
3955 rc = sfc_mae_rule_parse_action_pf_vf(sa, action->conf, spec);
3957 case RTE_FLOW_ACTION_TYPE_PORT_ID:
3958 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_PORT_ID,
3959 bundle->actions_mask);
3960 rc = sfc_mae_rule_parse_action_port_id(sa, action->conf, spec);
3962 case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
3963 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR,
3964 bundle->actions_mask);
3965 rc = sfc_mae_rule_parse_action_port_representor(sa,
3966 action->conf, spec);
3968 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
3969 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT,
3970 bundle->actions_mask);
3971 rc = sfc_mae_rule_parse_action_represented_port(sa,
3972 action->conf, spec);
3974 case RTE_FLOW_ACTION_TYPE_DROP:
3975 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_DROP,
3976 bundle->actions_mask);
3977 rc = efx_mae_action_set_populate_drop(spec);
3979 case RTE_FLOW_ACTION_TYPE_JUMP:
3980 if (spec_mae->ft_rule_type == SFC_FT_RULE_TUNNEL) {
3981 /* Workaround. See sfc_flow_parse_rte_to_mae() */
3986 return rte_flow_error_set(error, ENOTSUP,
3987 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3988 "Unsupported action");
3992 bundle->actions_mask |= (1ULL << action->type);
3993 } else if (!custom_error) {
3994 if (action->type < RTE_DIM(action_names)) {
3995 const char *action_name = action_names[action->type];
3997 if (action_name != NULL) {
3998 sfc_err(sa, "action %s was rejected: %s",
3999 action_name, strerror(rc));
4002 rc = rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ACTION,
4003 NULL, "Failed to request the action");
4010 sfc_mae_bounce_eh_invalidate(struct sfc_mae_bounce_eh *bounce_eh)
4012 bounce_eh->type = EFX_TUNNEL_PROTOCOL_NONE;
4016 sfc_mae_process_encap_header(struct sfc_adapter *sa,
4017 const struct sfc_mae_bounce_eh *bounce_eh,
4018 struct sfc_mae_encap_header **encap_headerp)
4020 if (bounce_eh->type == EFX_TUNNEL_PROTOCOL_NONE) {
4021 encap_headerp = NULL;
4025 *encap_headerp = sfc_mae_encap_header_attach(sa, bounce_eh);
4026 if (*encap_headerp != NULL)
4029 return sfc_mae_encap_header_add(sa, bounce_eh, encap_headerp);
4033 sfc_mae_rule_parse_actions(struct sfc_adapter *sa,
4034 const struct rte_flow_action actions[],
4035 struct sfc_flow_spec_mae *spec_mae,
4036 struct rte_flow_error *error)
4038 struct sfc_mae_actions_bundle bundle = {0};
4039 const struct rte_flow_action *action;
4040 struct sfc_mae_aset_ctx ctx = {0};
4041 struct sfc_mae *mae = &sa->mae;
4046 if (actions == NULL) {
4047 return rte_flow_error_set(error, EINVAL,
4048 RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
4052 rc = efx_mae_action_set_spec_init(sa->nic, &ctx.spec);
4054 goto fail_action_set_spec_init;
4056 for (action = actions;
4057 action->type != RTE_FLOW_ACTION_TYPE_END; ++action) {
4058 if (action->type == RTE_FLOW_ACTION_TYPE_COUNT)
4062 if (spec_mae->ft_rule_type == SFC_FT_RULE_SWITCH) {
4063 /* TUNNEL rules don't decapsulate packets. SWITCH rules do. */
4064 rc = efx_mae_action_set_populate_decap(ctx.spec);
4066 goto fail_enforce_ft_decap;
4068 if (ctx.n_counters == 0 &&
4069 sfc_mae_counter_stream_enabled(sa)) {
4071 * The user opted not to use action COUNT in this rule,
4072 * but the counter should be enabled implicitly because
4073 * packets hitting this rule contribute to the tunnel's
4074 * total number of hits. See sfc_mae_counter_get().
4076 rc = efx_mae_action_set_populate_count(ctx.spec);
4078 goto fail_enforce_ft_count;
4084 /* Cleanup after previous encap. header bounce buffer usage. */
4085 sfc_mae_bounce_eh_invalidate(&mae->bounce_eh);
4087 for (action = actions;
4088 action->type != RTE_FLOW_ACTION_TYPE_END; ++action) {
4089 rc = sfc_mae_actions_bundle_sync(action, &bundle,
4092 goto fail_rule_parse_action;
4094 rc = sfc_mae_rule_parse_action(sa, action, spec_mae,
4095 &bundle, &ctx, error);
4097 goto fail_rule_parse_action;
4100 rc = sfc_mae_actions_bundle_sync(action, &bundle, ctx.spec, error);
4102 goto fail_rule_parse_action;
4104 rc = sfc_mae_process_encap_header(sa, &mae->bounce_eh,
4107 goto fail_process_encap_header;
4109 if (ctx.n_counters > 1) {
4111 sfc_err(sa, "too many count actions requested: %u",
4116 switch (spec_mae->ft_rule_type) {
4117 case SFC_FT_RULE_NONE:
4119 case SFC_FT_RULE_TUNNEL:
4120 /* Workaround. See sfc_flow_parse_rte_to_mae() */
4121 rc = sfc_mae_rule_parse_action_pf_vf(sa, NULL, ctx.spec);
4123 goto fail_workaround_tunnel_delivery;
4125 ctx.counter_ft_ctx = spec_mae->ft_ctx;
4127 case SFC_FT_RULE_SWITCH:
4129 * Packets that go to the rule's AR have FT mark set (from the
4130 * TUNNEL rule OR's RECIRC_ID). Remove this mark in matching
4131 * packets. The user may have provided their own action
4132 * MARK above, so don't check the return value here.
4134 (void)efx_mae_action_set_populate_mark(ctx.spec, 0);
4136 ctx.ft_switch_hit_counter =
4137 &spec_mae->ft_ctx->switch_hit_counter;
4140 SFC_ASSERT(B_FALSE);
4143 spec_mae->action_set = sfc_mae_action_set_attach(sa, &ctx);
4144 if (spec_mae->action_set != NULL) {
4145 sfc_mae_encap_header_del(sa, ctx.encap_header);
4146 efx_mae_action_set_spec_fini(sa->nic, ctx.spec);
4150 rc = sfc_mae_action_set_add(sa, actions, &ctx, &spec_mae->action_set);
4152 goto fail_action_set_add;
4156 fail_action_set_add:
4157 fail_workaround_tunnel_delivery:
4159 sfc_mae_encap_header_del(sa, ctx.encap_header);
4161 fail_process_encap_header:
4162 fail_rule_parse_action:
4163 sfc_mae_mac_addr_del(sa, ctx.src_mac);
4164 sfc_mae_mac_addr_del(sa, ctx.dst_mac);
4165 efx_mae_action_set_spec_fini(sa->nic, ctx.spec);
4167 fail_enforce_ft_count:
4168 fail_enforce_ft_decap:
4169 fail_action_set_spec_init:
4170 if (rc > 0 && rte_errno == 0) {
4171 rc = rte_flow_error_set(error, rc,
4172 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
4173 NULL, "Failed to process the action");
4179 sfc_mae_rules_class_cmp(struct sfc_adapter *sa,
4180 const efx_mae_match_spec_t *left,
4181 const efx_mae_match_spec_t *right)
4183 bool have_same_class;
4186 rc = efx_mae_match_specs_class_cmp(sa->nic, left, right,
4189 return (rc == 0) ? have_same_class : false;
4193 sfc_mae_outer_rule_class_verify(struct sfc_adapter *sa,
4194 struct sfc_mae_outer_rule *rule)
4196 struct sfc_mae_fw_rsrc *fw_rsrc = &rule->fw_rsrc;
4197 struct sfc_mae_outer_rule *entry;
4198 struct sfc_mae *mae = &sa->mae;
4200 if (fw_rsrc->rule_id.id != EFX_MAE_RSRC_ID_INVALID) {
4201 /* An active rule is reused. It's class is wittingly valid. */
4205 TAILQ_FOREACH_REVERSE(entry, &mae->outer_rules,
4206 sfc_mae_outer_rules, entries) {
4207 const efx_mae_match_spec_t *left = entry->match_spec;
4208 const efx_mae_match_spec_t *right = rule->match_spec;
4213 if (sfc_mae_rules_class_cmp(sa, left, right))
4217 sfc_info(sa, "for now, the HW doesn't support rule validation, and HW "
4218 "support for outer frame pattern items is not guaranteed; "
4219 "other than that, the items are valid from SW standpoint");
4224 sfc_mae_action_rule_class_verify(struct sfc_adapter *sa,
4225 struct sfc_flow_spec_mae *spec)
4227 const struct rte_flow *entry;
4229 if (spec->match_spec == NULL)
4232 TAILQ_FOREACH_REVERSE(entry, &sa->flow_list, sfc_flow_list, entries) {
4233 const struct sfc_flow_spec *entry_spec = &entry->spec;
4234 const struct sfc_flow_spec_mae *es_mae = &entry_spec->mae;
4235 const efx_mae_match_spec_t *left = es_mae->match_spec;
4236 const efx_mae_match_spec_t *right = spec->match_spec;
4238 switch (entry_spec->type) {
4239 case SFC_FLOW_SPEC_FILTER:
4240 /* Ignore VNIC-level flows */
4242 case SFC_FLOW_SPEC_MAE:
4243 if (sfc_mae_rules_class_cmp(sa, left, right))
4251 sfc_info(sa, "for now, the HW doesn't support rule validation, and HW "
4252 "support for inner frame pattern items is not guaranteed; "
4253 "other than that, the items are valid from SW standpoint");
4258 * Confirm that a given flow can be accepted by the FW.
4261 * Software adapter context
4263 * Flow to be verified
4265 * Zero on success and non-zero in the case of error.
4266 * A special value of EAGAIN indicates that the adapter is
4267 * not in started state. This state is compulsory because
4268 * it only makes sense to compare the rule class of the flow
4269 * being validated with classes of the active rules.
4270 * Such classes are wittingly supported by the FW.
4273 sfc_mae_flow_verify(struct sfc_adapter *sa,
4274 struct rte_flow *flow)
4276 struct sfc_flow_spec *spec = &flow->spec;
4277 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
4278 struct sfc_mae_outer_rule *outer_rule = spec_mae->outer_rule;
4281 SFC_ASSERT(sfc_adapter_is_locked(sa));
4283 if (sa->state != SFC_ETHDEV_STARTED)
4286 if (outer_rule != NULL) {
4287 rc = sfc_mae_outer_rule_class_verify(sa, outer_rule);
4292 return sfc_mae_action_rule_class_verify(sa, spec_mae);
4296 sfc_mae_flow_insert(struct sfc_adapter *sa,
4297 struct rte_flow *flow)
4299 struct sfc_flow_spec *spec = &flow->spec;
4300 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
4301 struct sfc_mae_outer_rule *outer_rule = spec_mae->outer_rule;
4302 struct sfc_mae_action_set *action_set = spec_mae->action_set;
4303 struct sfc_mae_fw_rsrc *fw_rsrc;
4306 SFC_ASSERT(spec_mae->rule_id.id == EFX_MAE_RSRC_ID_INVALID);
4308 if (outer_rule != NULL) {
4309 rc = sfc_mae_outer_rule_enable(sa, outer_rule,
4310 spec_mae->match_spec);
4312 goto fail_outer_rule_enable;
4315 if (spec_mae->ft_rule_type == SFC_FT_RULE_TUNNEL) {
4316 spec_mae->ft_ctx->reset_tunnel_hit_counter =
4317 spec_mae->ft_ctx->switch_hit_counter;
4320 if (action_set == NULL) {
4321 sfc_dbg(sa, "enabled flow=%p (no AR)", flow);
4325 rc = sfc_mae_action_set_enable(sa, action_set);
4327 goto fail_action_set_enable;
4329 if (action_set->n_counters > 0) {
4330 rc = sfc_mae_counter_start(sa);
4332 sfc_err(sa, "failed to start MAE counters support: %s",
4334 goto fail_mae_counter_start;
4338 fw_rsrc = &action_set->fw_rsrc;
4340 rc = efx_mae_action_rule_insert(sa->nic, spec_mae->match_spec,
4341 NULL, &fw_rsrc->aset_id,
4342 &spec_mae->rule_id);
4344 goto fail_action_rule_insert;
4346 sfc_dbg(sa, "enabled flow=%p: AR_ID=0x%08x",
4347 flow, spec_mae->rule_id.id);
4351 fail_action_rule_insert:
4352 fail_mae_counter_start:
4353 sfc_mae_action_set_disable(sa, action_set);
4355 fail_action_set_enable:
4356 if (outer_rule != NULL)
4357 sfc_mae_outer_rule_disable(sa, outer_rule);
4359 fail_outer_rule_enable:
4364 sfc_mae_flow_remove(struct sfc_adapter *sa,
4365 struct rte_flow *flow)
4367 struct sfc_flow_spec *spec = &flow->spec;
4368 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
4369 struct sfc_mae_action_set *action_set = spec_mae->action_set;
4370 struct sfc_mae_outer_rule *outer_rule = spec_mae->outer_rule;
4373 if (action_set == NULL) {
4374 sfc_dbg(sa, "disabled flow=%p (no AR)", flow);
4375 goto skip_action_rule;
4378 SFC_ASSERT(spec_mae->rule_id.id != EFX_MAE_RSRC_ID_INVALID);
4380 rc = efx_mae_action_rule_remove(sa->nic, &spec_mae->rule_id);
4382 sfc_err(sa, "failed to disable flow=%p with AR_ID=0x%08x: %s",
4383 flow, spec_mae->rule_id.id, strerror(rc));
4385 sfc_dbg(sa, "disabled flow=%p with AR_ID=0x%08x",
4386 flow, spec_mae->rule_id.id);
4387 spec_mae->rule_id.id = EFX_MAE_RSRC_ID_INVALID;
4389 sfc_mae_action_set_disable(sa, action_set);
4392 if (outer_rule != NULL)
4393 sfc_mae_outer_rule_disable(sa, outer_rule);
4399 sfc_mae_query_counter(struct sfc_adapter *sa,
4400 struct sfc_flow_spec_mae *spec,
4401 const struct rte_flow_action *action,
4402 struct rte_flow_query_count *data,
4403 struct rte_flow_error *error)
4405 struct sfc_mae_action_set *action_set = spec->action_set;
4406 const struct rte_flow_action_count *conf = action->conf;
4410 if (action_set == NULL || action_set->n_counters == 0) {
4411 return rte_flow_error_set(error, EINVAL,
4412 RTE_FLOW_ERROR_TYPE_ACTION, action,
4413 "Queried flow rule does not have count actions");
4416 for (i = 0; i < action_set->n_counters; i++) {
4418 * Get the first available counter of the flow rule if
4419 * counter ID is not specified, provided that this
4420 * counter is not an automatic (implicit) one.
4422 if (conf != NULL && action_set->counters[i].rte_id != conf->id)
4425 rc = sfc_mae_counter_get(&sa->mae.counter_registry.counters,
4426 &action_set->counters[i], data);
4428 return rte_flow_error_set(error, EINVAL,
4429 RTE_FLOW_ERROR_TYPE_ACTION, action,
4430 "Queried flow rule counter action is invalid");
4436 return rte_flow_error_set(error, ENOENT,
4437 RTE_FLOW_ERROR_TYPE_ACTION, action,
4438 "no such flow rule action or such count ID");
4442 sfc_mae_flow_query(struct rte_eth_dev *dev,
4443 struct rte_flow *flow,
4444 const struct rte_flow_action *action,
4446 struct rte_flow_error *error)
4448 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
4449 struct sfc_flow_spec *spec = &flow->spec;
4450 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
4452 switch (action->type) {
4453 case RTE_FLOW_ACTION_TYPE_COUNT:
4454 return sfc_mae_query_counter(sa, spec_mae, action,
4457 return rte_flow_error_set(error, ENOTSUP,
4458 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4459 "Query for action of this type is not supported");
4464 sfc_mae_switchdev_init(struct sfc_adapter *sa)
4466 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
4467 struct sfc_mae *mae = &sa->mae;
4469 efx_mport_sel_t phy;
4472 sfc_log_init(sa, "entry");
4474 if (!sa->switchdev) {
4475 sfc_log_init(sa, "switchdev is not enabled - skip");
4479 if (mae->status != SFC_MAE_STATUS_ADMIN) {
4481 sfc_err(sa, "failed to init switchdev - no admin MAE privilege");
4485 rc = efx_mae_mport_by_pcie_function(encp->enc_pf, EFX_PCI_VF_INVALID,
4488 sfc_err(sa, "failed get PF mport");
4492 rc = efx_mae_mport_by_phy_port(encp->enc_assigned_port, &phy);
4494 sfc_err(sa, "failed get PHY mport");
4498 rc = sfc_mae_rule_add_mport_match_deliver(sa, &pf, &phy,
4499 SFC_MAE_RULE_PRIO_LOWEST,
4500 &mae->switchdev_rule_pf_to_ext);
4502 sfc_err(sa, "failed add MAE rule to forward from PF to PHY");
4506 rc = sfc_mae_rule_add_mport_match_deliver(sa, &phy, &pf,
4507 SFC_MAE_RULE_PRIO_LOWEST,
4508 &mae->switchdev_rule_ext_to_pf);
4510 sfc_err(sa, "failed add MAE rule to forward from PHY to PF");
4514 sfc_log_init(sa, "done");
4519 sfc_mae_rule_del(sa, mae->switchdev_rule_pf_to_ext);
4525 sfc_log_init(sa, "failed: %s", rte_strerror(rc));
4530 sfc_mae_switchdev_fini(struct sfc_adapter *sa)
4532 struct sfc_mae *mae = &sa->mae;
4537 sfc_mae_rule_del(sa, mae->switchdev_rule_pf_to_ext);
4538 sfc_mae_rule_del(sa, mae->switchdev_rule_ext_to_pf);