1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2019-2021 Xilinx, Inc.
4 * Copyright(c) 2019 Solarflare Communications Inc.
6 * This software was jointly developed between OKTET Labs (under contract
7 * for Solarflare) and Solarflare Communications, Inc.
12 #include <rte_bitops.h>
13 #include <rte_common.h>
14 #include <rte_vxlan.h>
19 #include "sfc_flow_tunnel.h"
20 #include "sfc_mae_counter.h"
22 #include "sfc_switch.h"
23 #include "sfc_service.h"
26 sfc_mae_assign_ethdev_mport(struct sfc_adapter *sa,
27 efx_mport_sel_t *mportp)
29 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
31 return efx_mae_mport_by_pcie_function(encp->enc_pf, encp->enc_vf,
36 sfc_mae_assign_entity_mport(struct sfc_adapter *sa,
37 efx_mport_sel_t *mportp)
39 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
42 if (encp->enc_mae_admin) {
44 * This ethdev sits on MAE admin PF. The represented
45 * entity is the network port assigned to that PF.
47 rc = efx_mae_mport_by_phy_port(encp->enc_assigned_port, mportp);
50 * This ethdev sits on unprivileged PF / VF. The entity
51 * represented by the ethdev can change dynamically
52 * as MAE admin changes default traffic rules.
54 * For the sake of simplicity, do not fill in the m-port
55 * and assume that flow rules should not be allowed to
56 * reference the entity represented by this ethdev.
58 efx_mae_mport_invalid(mportp);
65 sfc_mae_counter_registry_init(struct sfc_mae_counter_registry *registry,
66 uint32_t nb_counters_max)
68 return sfc_mae_counters_init(®istry->counters, nb_counters_max);
72 sfc_mae_counter_registry_fini(struct sfc_mae_counter_registry *registry)
74 sfc_mae_counters_fini(®istry->counters);
78 sfc_mae_internal_rule_find_empty_slot(struct sfc_adapter *sa,
79 struct sfc_mae_rule **rule)
81 struct sfc_mae *mae = &sa->mae;
82 struct sfc_mae_internal_rules *internal_rules = &mae->internal_rules;
86 for (entry = 0; entry < SFC_MAE_NB_RULES_MAX; entry++) {
87 if (internal_rules->rules[entry].spec == NULL)
91 if (entry == SFC_MAE_NB_RULES_MAX) {
93 sfc_err(sa, "failed too many rules (%u rules used)", entry);
94 goto fail_too_many_rules;
97 *rule = &internal_rules->rules[entry];
106 sfc_mae_rule_add_mport_match_deliver(struct sfc_adapter *sa,
107 const efx_mport_sel_t *mport_match,
108 const efx_mport_sel_t *mport_deliver,
109 int prio, struct sfc_mae_rule **rulep)
111 struct sfc_mae *mae = &sa->mae;
112 struct sfc_mae_rule *rule;
115 sfc_log_init(sa, "entry");
117 if (prio > 0 && (unsigned int)prio >= mae->nb_action_rule_prios_max) {
119 sfc_err(sa, "failed: invalid priority %d (max %u)", prio,
120 mae->nb_action_rule_prios_max);
121 goto fail_invalid_prio;
124 prio = mae->nb_action_rule_prios_max - 1;
126 rc = sfc_mae_internal_rule_find_empty_slot(sa, &rule);
128 goto fail_find_empty_slot;
130 sfc_log_init(sa, "init MAE match spec");
131 rc = efx_mae_match_spec_init(sa->nic, EFX_MAE_RULE_ACTION,
132 (uint32_t)prio, &rule->spec);
134 sfc_err(sa, "failed to init MAE match spec");
135 goto fail_match_init;
138 rc = efx_mae_match_spec_mport_set(rule->spec, mport_match, NULL);
140 sfc_err(sa, "failed to get MAE match mport selector");
144 rc = efx_mae_action_set_spec_init(sa->nic, &rule->actions);
146 sfc_err(sa, "failed to init MAE action set");
147 goto fail_action_init;
150 rc = efx_mae_action_set_populate_deliver(rule->actions,
153 sfc_err(sa, "failed to populate deliver action");
154 goto fail_populate_deliver;
157 rc = efx_mae_action_set_alloc(sa->nic, rule->actions,
160 sfc_err(sa, "failed to allocate action set");
161 goto fail_action_set_alloc;
164 rc = efx_mae_action_rule_insert(sa->nic, rule->spec, NULL,
168 sfc_err(sa, "failed to insert action rule");
169 goto fail_rule_insert;
174 sfc_log_init(sa, "done");
179 efx_mae_action_set_free(sa->nic, &rule->action_set);
181 fail_action_set_alloc:
182 fail_populate_deliver:
183 efx_mae_action_set_spec_fini(sa->nic, rule->actions);
187 efx_mae_match_spec_fini(sa->nic, rule->spec);
190 fail_find_empty_slot:
192 sfc_log_init(sa, "failed: %s", rte_strerror(rc));
197 sfc_mae_rule_del(struct sfc_adapter *sa, struct sfc_mae_rule *rule)
199 if (rule == NULL || rule->spec == NULL)
202 efx_mae_action_rule_remove(sa->nic, &rule->rule_id);
203 efx_mae_action_set_free(sa->nic, &rule->action_set);
204 efx_mae_action_set_spec_fini(sa->nic, rule->actions);
205 efx_mae_match_spec_fini(sa->nic, rule->spec);
211 sfc_mae_attach(struct sfc_adapter *sa)
213 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
214 struct sfc_mae_switch_port_request switch_port_request = {0};
215 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
216 efx_mport_sel_t ethdev_mport;
217 efx_mport_sel_t entity_mport;
218 struct sfc_mae *mae = &sa->mae;
219 struct sfc_mae_bounce_eh *bounce_eh = &mae->bounce_eh;
220 efx_mae_limits_t limits;
223 sfc_log_init(sa, "entry");
225 if (!encp->enc_mae_supported) {
226 mae->status = SFC_MAE_STATUS_UNSUPPORTED;
230 if (encp->enc_mae_admin) {
231 sfc_log_init(sa, "init MAE");
232 rc = efx_mae_init(sa->nic);
236 sfc_log_init(sa, "get MAE limits");
237 rc = efx_mae_get_limits(sa->nic, &limits);
239 goto fail_mae_get_limits;
241 sfc_log_init(sa, "init MAE counter registry");
242 rc = sfc_mae_counter_registry_init(&mae->counter_registry,
243 limits.eml_max_n_counters);
245 sfc_err(sa, "failed to init MAE counters registry for %u entries: %s",
246 limits.eml_max_n_counters, rte_strerror(rc));
247 goto fail_counter_registry_init;
251 sfc_log_init(sa, "assign ethdev MPORT");
252 rc = sfc_mae_assign_ethdev_mport(sa, ðdev_mport);
254 goto fail_mae_assign_ethdev_mport;
256 sfc_log_init(sa, "assign entity MPORT");
257 rc = sfc_mae_assign_entity_mport(sa, &entity_mport);
259 goto fail_mae_assign_entity_mport;
261 sfc_log_init(sa, "assign RTE switch domain");
262 rc = sfc_mae_assign_switch_domain(sa, &mae->switch_domain_id);
264 goto fail_mae_assign_switch_domain;
266 sfc_log_init(sa, "assign RTE switch port");
267 switch_port_request.type = SFC_MAE_SWITCH_PORT_INDEPENDENT;
268 switch_port_request.ethdev_mportp = ðdev_mport;
269 switch_port_request.entity_mportp = &entity_mport;
270 switch_port_request.ethdev_port_id = sas->port_id;
271 switch_port_request.port_data.indep.mae_admin =
272 encp->enc_mae_admin == B_TRUE;
273 rc = sfc_mae_assign_switch_port(mae->switch_domain_id,
274 &switch_port_request,
275 &mae->switch_port_id);
277 goto fail_mae_assign_switch_port;
279 if (encp->enc_mae_admin) {
280 sfc_log_init(sa, "allocate encap. header bounce buffer");
281 bounce_eh->buf_size = limits.eml_encap_header_size_limit;
282 bounce_eh->buf = rte_malloc("sfc_mae_bounce_eh",
283 bounce_eh->buf_size, 0);
284 if (bounce_eh->buf == NULL)
285 goto fail_mae_alloc_bounce_eh;
287 mae->nb_outer_rule_prios_max = limits.eml_max_n_outer_prios;
288 mae->nb_action_rule_prios_max = limits.eml_max_n_action_prios;
289 mae->encap_types_supported = limits.eml_encap_types_supported;
292 TAILQ_INIT(&mae->outer_rules);
293 TAILQ_INIT(&mae->encap_headers);
294 TAILQ_INIT(&mae->action_sets);
296 if (encp->enc_mae_admin)
297 mae->status = SFC_MAE_STATUS_ADMIN;
299 mae->status = SFC_MAE_STATUS_SUPPORTED;
301 sfc_log_init(sa, "done");
305 fail_mae_alloc_bounce_eh:
306 fail_mae_assign_switch_port:
307 fail_mae_assign_switch_domain:
308 fail_mae_assign_entity_mport:
309 fail_mae_assign_ethdev_mport:
310 if (encp->enc_mae_admin)
311 sfc_mae_counter_registry_fini(&mae->counter_registry);
313 fail_counter_registry_init:
315 if (encp->enc_mae_admin)
316 efx_mae_fini(sa->nic);
319 sfc_log_init(sa, "failed %d", rc);
325 sfc_mae_detach(struct sfc_adapter *sa)
327 struct sfc_mae *mae = &sa->mae;
328 enum sfc_mae_status status_prev = mae->status;
330 sfc_log_init(sa, "entry");
332 mae->nb_action_rule_prios_max = 0;
333 mae->status = SFC_MAE_STATUS_UNKNOWN;
335 if (status_prev != SFC_MAE_STATUS_ADMIN)
338 rte_free(mae->bounce_eh.buf);
339 sfc_mae_counter_registry_fini(&mae->counter_registry);
341 efx_mae_fini(sa->nic);
343 sfc_log_init(sa, "done");
346 static struct sfc_mae_outer_rule *
347 sfc_mae_outer_rule_attach(struct sfc_adapter *sa,
348 const efx_mae_match_spec_t *match_spec,
349 efx_tunnel_protocol_t encap_type)
351 struct sfc_mae_outer_rule *rule;
352 struct sfc_mae *mae = &sa->mae;
354 SFC_ASSERT(sfc_adapter_is_locked(sa));
356 TAILQ_FOREACH(rule, &mae->outer_rules, entries) {
357 if (efx_mae_match_specs_equal(rule->match_spec, match_spec) &&
358 rule->encap_type == encap_type) {
359 sfc_dbg(sa, "attaching to outer_rule=%p", rule);
369 sfc_mae_outer_rule_add(struct sfc_adapter *sa,
370 efx_mae_match_spec_t *match_spec,
371 efx_tunnel_protocol_t encap_type,
372 struct sfc_mae_outer_rule **rulep)
374 struct sfc_mae_outer_rule *rule;
375 struct sfc_mae *mae = &sa->mae;
377 SFC_ASSERT(sfc_adapter_is_locked(sa));
379 rule = rte_zmalloc("sfc_mae_outer_rule", sizeof(*rule), 0);
384 rule->match_spec = match_spec;
385 rule->encap_type = encap_type;
387 rule->fw_rsrc.rule_id.id = EFX_MAE_RSRC_ID_INVALID;
389 TAILQ_INSERT_TAIL(&mae->outer_rules, rule, entries);
393 sfc_dbg(sa, "added outer_rule=%p", rule);
399 sfc_mae_outer_rule_del(struct sfc_adapter *sa,
400 struct sfc_mae_outer_rule *rule)
402 struct sfc_mae *mae = &sa->mae;
404 SFC_ASSERT(sfc_adapter_is_locked(sa));
405 SFC_ASSERT(rule->refcnt != 0);
409 if (rule->refcnt != 0)
412 if (rule->fw_rsrc.rule_id.id != EFX_MAE_RSRC_ID_INVALID ||
413 rule->fw_rsrc.refcnt != 0) {
414 sfc_err(sa, "deleting outer_rule=%p abandons its FW resource: OR_ID=0x%08x, refcnt=%u",
415 rule, rule->fw_rsrc.rule_id.id, rule->fw_rsrc.refcnt);
418 efx_mae_match_spec_fini(sa->nic, rule->match_spec);
420 TAILQ_REMOVE(&mae->outer_rules, rule, entries);
423 sfc_dbg(sa, "deleted outer_rule=%p", rule);
427 sfc_mae_outer_rule_enable(struct sfc_adapter *sa,
428 struct sfc_mae_outer_rule *rule,
429 efx_mae_match_spec_t *match_spec_action)
431 struct sfc_mae_fw_rsrc *fw_rsrc = &rule->fw_rsrc;
434 SFC_ASSERT(sfc_adapter_is_locked(sa));
436 if (fw_rsrc->refcnt == 0) {
437 SFC_ASSERT(fw_rsrc->rule_id.id == EFX_MAE_RSRC_ID_INVALID);
438 SFC_ASSERT(rule->match_spec != NULL);
440 rc = efx_mae_outer_rule_insert(sa->nic, rule->match_spec,
444 sfc_err(sa, "failed to enable outer_rule=%p: %s",
450 if (match_spec_action == NULL)
451 goto skip_action_rule;
453 rc = efx_mae_match_spec_outer_rule_id_set(match_spec_action,
456 if (fw_rsrc->refcnt == 0) {
457 (void)efx_mae_outer_rule_remove(sa->nic,
459 fw_rsrc->rule_id.id = EFX_MAE_RSRC_ID_INVALID;
462 sfc_err(sa, "can't match on outer rule ID: %s", strerror(rc));
468 if (fw_rsrc->refcnt == 0) {
469 sfc_dbg(sa, "enabled outer_rule=%p: OR_ID=0x%08x",
470 rule, fw_rsrc->rule_id.id);
479 sfc_mae_outer_rule_disable(struct sfc_adapter *sa,
480 struct sfc_mae_outer_rule *rule)
482 struct sfc_mae_fw_rsrc *fw_rsrc = &rule->fw_rsrc;
485 SFC_ASSERT(sfc_adapter_is_locked(sa));
487 if (fw_rsrc->rule_id.id == EFX_MAE_RSRC_ID_INVALID ||
488 fw_rsrc->refcnt == 0) {
489 sfc_err(sa, "failed to disable outer_rule=%p: already disabled; OR_ID=0x%08x, refcnt=%u",
490 rule, fw_rsrc->rule_id.id, fw_rsrc->refcnt);
494 if (fw_rsrc->refcnt == 1) {
495 rc = efx_mae_outer_rule_remove(sa->nic, &fw_rsrc->rule_id);
497 sfc_dbg(sa, "disabled outer_rule=%p with OR_ID=0x%08x",
498 rule, fw_rsrc->rule_id.id);
500 sfc_err(sa, "failed to disable outer_rule=%p with OR_ID=0x%08x: %s",
501 rule, fw_rsrc->rule_id.id, strerror(rc));
503 fw_rsrc->rule_id.id = EFX_MAE_RSRC_ID_INVALID;
509 static struct sfc_mae_encap_header *
510 sfc_mae_encap_header_attach(struct sfc_adapter *sa,
511 const struct sfc_mae_bounce_eh *bounce_eh)
513 struct sfc_mae_encap_header *encap_header;
514 struct sfc_mae *mae = &sa->mae;
516 SFC_ASSERT(sfc_adapter_is_locked(sa));
518 TAILQ_FOREACH(encap_header, &mae->encap_headers, entries) {
519 if (encap_header->size == bounce_eh->size &&
520 memcmp(encap_header->buf, bounce_eh->buf,
521 bounce_eh->size) == 0) {
522 sfc_dbg(sa, "attaching to encap_header=%p",
524 ++(encap_header->refcnt);
533 sfc_mae_encap_header_add(struct sfc_adapter *sa,
534 const struct sfc_mae_bounce_eh *bounce_eh,
535 struct sfc_mae_encap_header **encap_headerp)
537 struct sfc_mae_encap_header *encap_header;
538 struct sfc_mae *mae = &sa->mae;
540 SFC_ASSERT(sfc_adapter_is_locked(sa));
542 encap_header = rte_zmalloc("sfc_mae_encap_header",
543 sizeof(*encap_header), 0);
544 if (encap_header == NULL)
547 encap_header->size = bounce_eh->size;
549 encap_header->buf = rte_malloc("sfc_mae_encap_header_buf",
550 encap_header->size, 0);
551 if (encap_header->buf == NULL) {
552 rte_free(encap_header);
556 rte_memcpy(encap_header->buf, bounce_eh->buf, bounce_eh->size);
558 encap_header->refcnt = 1;
559 encap_header->type = bounce_eh->type;
560 encap_header->fw_rsrc.eh_id.id = EFX_MAE_RSRC_ID_INVALID;
562 TAILQ_INSERT_TAIL(&mae->encap_headers, encap_header, entries);
564 *encap_headerp = encap_header;
566 sfc_dbg(sa, "added encap_header=%p", encap_header);
572 sfc_mae_encap_header_del(struct sfc_adapter *sa,
573 struct sfc_mae_encap_header *encap_header)
575 struct sfc_mae *mae = &sa->mae;
577 if (encap_header == NULL)
580 SFC_ASSERT(sfc_adapter_is_locked(sa));
581 SFC_ASSERT(encap_header->refcnt != 0);
583 --(encap_header->refcnt);
585 if (encap_header->refcnt != 0)
588 if (encap_header->fw_rsrc.eh_id.id != EFX_MAE_RSRC_ID_INVALID ||
589 encap_header->fw_rsrc.refcnt != 0) {
590 sfc_err(sa, "deleting encap_header=%p abandons its FW resource: EH_ID=0x%08x, refcnt=%u",
591 encap_header, encap_header->fw_rsrc.eh_id.id,
592 encap_header->fw_rsrc.refcnt);
595 TAILQ_REMOVE(&mae->encap_headers, encap_header, entries);
596 rte_free(encap_header->buf);
597 rte_free(encap_header);
599 sfc_dbg(sa, "deleted encap_header=%p", encap_header);
603 sfc_mae_encap_header_enable(struct sfc_adapter *sa,
604 struct sfc_mae_encap_header *encap_header,
605 efx_mae_actions_t *action_set_spec)
607 struct sfc_mae_fw_rsrc *fw_rsrc;
610 if (encap_header == NULL)
613 SFC_ASSERT(sfc_adapter_is_locked(sa));
615 fw_rsrc = &encap_header->fw_rsrc;
617 if (fw_rsrc->refcnt == 0) {
618 SFC_ASSERT(fw_rsrc->eh_id.id == EFX_MAE_RSRC_ID_INVALID);
619 SFC_ASSERT(encap_header->buf != NULL);
620 SFC_ASSERT(encap_header->size != 0);
622 rc = efx_mae_encap_header_alloc(sa->nic, encap_header->type,
627 sfc_err(sa, "failed to enable encap_header=%p: %s",
628 encap_header, strerror(rc));
633 rc = efx_mae_action_set_fill_in_eh_id(action_set_spec,
636 if (fw_rsrc->refcnt == 0) {
637 (void)efx_mae_encap_header_free(sa->nic,
639 fw_rsrc->eh_id.id = EFX_MAE_RSRC_ID_INVALID;
642 sfc_err(sa, "can't fill in encap. header ID: %s", strerror(rc));
647 if (fw_rsrc->refcnt == 0) {
648 sfc_dbg(sa, "enabled encap_header=%p: EH_ID=0x%08x",
649 encap_header, fw_rsrc->eh_id.id);
658 sfc_mae_encap_header_disable(struct sfc_adapter *sa,
659 struct sfc_mae_encap_header *encap_header)
661 struct sfc_mae_fw_rsrc *fw_rsrc;
664 if (encap_header == NULL)
667 SFC_ASSERT(sfc_adapter_is_locked(sa));
669 fw_rsrc = &encap_header->fw_rsrc;
671 if (fw_rsrc->eh_id.id == EFX_MAE_RSRC_ID_INVALID ||
672 fw_rsrc->refcnt == 0) {
673 sfc_err(sa, "failed to disable encap_header=%p: already disabled; EH_ID=0x%08x, refcnt=%u",
674 encap_header, fw_rsrc->eh_id.id, fw_rsrc->refcnt);
678 if (fw_rsrc->refcnt == 1) {
679 rc = efx_mae_encap_header_free(sa->nic, &fw_rsrc->eh_id);
681 sfc_dbg(sa, "disabled encap_header=%p with EH_ID=0x%08x",
682 encap_header, fw_rsrc->eh_id.id);
684 sfc_err(sa, "failed to disable encap_header=%p with EH_ID=0x%08x: %s",
685 encap_header, fw_rsrc->eh_id.id, strerror(rc));
687 fw_rsrc->eh_id.id = EFX_MAE_RSRC_ID_INVALID;
694 sfc_mae_counters_enable(struct sfc_adapter *sa,
695 struct sfc_mae_counter_id *counters,
696 unsigned int n_counters,
697 efx_mae_actions_t *action_set_spec)
701 sfc_log_init(sa, "entry");
703 if (n_counters == 0) {
704 sfc_log_init(sa, "no counters - skip");
708 SFC_ASSERT(sfc_adapter_is_locked(sa));
709 SFC_ASSERT(n_counters == 1);
711 rc = sfc_mae_counter_enable(sa, &counters[0]);
713 sfc_err(sa, "failed to enable MAE counter %u: %s",
714 counters[0].mae_id.id, rte_strerror(rc));
715 goto fail_counter_add;
718 rc = efx_mae_action_set_fill_in_counter_id(action_set_spec,
719 &counters[0].mae_id);
721 sfc_err(sa, "failed to fill in MAE counter %u in action set: %s",
722 counters[0].mae_id.id, rte_strerror(rc));
723 goto fail_fill_in_id;
729 (void)sfc_mae_counter_disable(sa, &counters[0]);
732 sfc_log_init(sa, "failed: %s", rte_strerror(rc));
737 sfc_mae_counters_disable(struct sfc_adapter *sa,
738 struct sfc_mae_counter_id *counters,
739 unsigned int n_counters)
744 SFC_ASSERT(sfc_adapter_is_locked(sa));
745 SFC_ASSERT(n_counters == 1);
747 if (counters[0].mae_id.id == EFX_MAE_RSRC_ID_INVALID) {
748 sfc_err(sa, "failed to disable: already disabled");
752 return sfc_mae_counter_disable(sa, &counters[0]);
755 static struct sfc_mae_action_set *
756 sfc_mae_action_set_attach(struct sfc_adapter *sa,
757 const struct sfc_mae_encap_header *encap_header,
758 unsigned int n_count,
759 const efx_mae_actions_t *spec)
761 struct sfc_mae_action_set *action_set;
762 struct sfc_mae *mae = &sa->mae;
764 SFC_ASSERT(sfc_adapter_is_locked(sa));
767 * Shared counters are not supported, hence, action
768 * sets with counters are not attachable.
773 TAILQ_FOREACH(action_set, &mae->action_sets, entries) {
774 if (action_set->encap_header == encap_header &&
775 efx_mae_action_set_specs_equal(action_set->spec, spec)) {
776 sfc_dbg(sa, "attaching to action_set=%p", action_set);
777 ++(action_set->refcnt);
786 sfc_mae_action_set_add(struct sfc_adapter *sa,
787 const struct rte_flow_action actions[],
788 efx_mae_actions_t *spec,
789 struct sfc_mae_encap_header *encap_header,
790 uint64_t *ft_group_hit_counter,
791 struct sfc_flow_tunnel *ft,
792 unsigned int n_counters,
793 struct sfc_mae_action_set **action_setp)
795 struct sfc_mae_action_set *action_set;
796 struct sfc_mae *mae = &sa->mae;
799 SFC_ASSERT(sfc_adapter_is_locked(sa));
801 action_set = rte_zmalloc("sfc_mae_action_set", sizeof(*action_set), 0);
802 if (action_set == NULL) {
803 sfc_err(sa, "failed to alloc action set");
807 if (n_counters > 0) {
808 const struct rte_flow_action *action;
810 action_set->counters = rte_malloc("sfc_mae_counter_ids",
811 sizeof(action_set->counters[0]) * n_counters, 0);
812 if (action_set->counters == NULL) {
813 rte_free(action_set);
814 sfc_err(sa, "failed to alloc counters");
818 for (i = 0; i < n_counters; ++i) {
819 action_set->counters[i].rte_id_valid = B_FALSE;
820 action_set->counters[i].mae_id.id =
821 EFX_MAE_RSRC_ID_INVALID;
823 action_set->counters[i].ft_group_hit_counter =
824 ft_group_hit_counter;
825 action_set->counters[i].ft = ft;
828 for (action = actions, i = 0;
829 action->type != RTE_FLOW_ACTION_TYPE_END && i < n_counters;
831 const struct rte_flow_action_count *conf;
833 if (action->type != RTE_FLOW_ACTION_TYPE_COUNT)
838 action_set->counters[i].rte_id_valid = B_TRUE;
839 action_set->counters[i].rte_id = conf->id;
842 action_set->n_counters = n_counters;
845 action_set->refcnt = 1;
846 action_set->spec = spec;
847 action_set->encap_header = encap_header;
849 action_set->fw_rsrc.aset_id.id = EFX_MAE_RSRC_ID_INVALID;
851 TAILQ_INSERT_TAIL(&mae->action_sets, action_set, entries);
853 *action_setp = action_set;
855 sfc_dbg(sa, "added action_set=%p", action_set);
861 sfc_mae_action_set_del(struct sfc_adapter *sa,
862 struct sfc_mae_action_set *action_set)
864 struct sfc_mae *mae = &sa->mae;
866 SFC_ASSERT(sfc_adapter_is_locked(sa));
867 SFC_ASSERT(action_set->refcnt != 0);
869 --(action_set->refcnt);
871 if (action_set->refcnt != 0)
874 if (action_set->fw_rsrc.aset_id.id != EFX_MAE_RSRC_ID_INVALID ||
875 action_set->fw_rsrc.refcnt != 0) {
876 sfc_err(sa, "deleting action_set=%p abandons its FW resource: AS_ID=0x%08x, refcnt=%u",
877 action_set, action_set->fw_rsrc.aset_id.id,
878 action_set->fw_rsrc.refcnt);
881 efx_mae_action_set_spec_fini(sa->nic, action_set->spec);
882 sfc_mae_encap_header_del(sa, action_set->encap_header);
883 if (action_set->n_counters > 0) {
884 SFC_ASSERT(action_set->n_counters == 1);
885 SFC_ASSERT(action_set->counters[0].mae_id.id ==
886 EFX_MAE_RSRC_ID_INVALID);
887 rte_free(action_set->counters);
889 TAILQ_REMOVE(&mae->action_sets, action_set, entries);
890 rte_free(action_set);
892 sfc_dbg(sa, "deleted action_set=%p", action_set);
896 sfc_mae_action_set_enable(struct sfc_adapter *sa,
897 struct sfc_mae_action_set *action_set)
899 struct sfc_mae_encap_header *encap_header = action_set->encap_header;
900 struct sfc_mae_counter_id *counters = action_set->counters;
901 struct sfc_mae_fw_rsrc *fw_rsrc = &action_set->fw_rsrc;
904 SFC_ASSERT(sfc_adapter_is_locked(sa));
906 if (fw_rsrc->refcnt == 0) {
907 SFC_ASSERT(fw_rsrc->aset_id.id == EFX_MAE_RSRC_ID_INVALID);
908 SFC_ASSERT(action_set->spec != NULL);
910 rc = sfc_mae_encap_header_enable(sa, encap_header,
915 rc = sfc_mae_counters_enable(sa, counters,
916 action_set->n_counters,
919 sfc_err(sa, "failed to enable %u MAE counters: %s",
920 action_set->n_counters, rte_strerror(rc));
922 sfc_mae_encap_header_disable(sa, encap_header);
926 rc = efx_mae_action_set_alloc(sa->nic, action_set->spec,
929 sfc_err(sa, "failed to enable action_set=%p: %s",
930 action_set, strerror(rc));
932 (void)sfc_mae_counters_disable(sa, counters,
933 action_set->n_counters);
934 sfc_mae_encap_header_disable(sa, encap_header);
938 sfc_dbg(sa, "enabled action_set=%p: AS_ID=0x%08x",
939 action_set, fw_rsrc->aset_id.id);
948 sfc_mae_action_set_disable(struct sfc_adapter *sa,
949 struct sfc_mae_action_set *action_set)
951 struct sfc_mae_fw_rsrc *fw_rsrc = &action_set->fw_rsrc;
954 SFC_ASSERT(sfc_adapter_is_locked(sa));
956 if (fw_rsrc->aset_id.id == EFX_MAE_RSRC_ID_INVALID ||
957 fw_rsrc->refcnt == 0) {
958 sfc_err(sa, "failed to disable action_set=%p: already disabled; AS_ID=0x%08x, refcnt=%u",
959 action_set, fw_rsrc->aset_id.id, fw_rsrc->refcnt);
963 if (fw_rsrc->refcnt == 1) {
964 rc = efx_mae_action_set_free(sa->nic, &fw_rsrc->aset_id);
966 sfc_dbg(sa, "disabled action_set=%p with AS_ID=0x%08x",
967 action_set, fw_rsrc->aset_id.id);
969 sfc_err(sa, "failed to disable action_set=%p with AS_ID=0x%08x: %s",
970 action_set, fw_rsrc->aset_id.id, strerror(rc));
972 fw_rsrc->aset_id.id = EFX_MAE_RSRC_ID_INVALID;
974 rc = sfc_mae_counters_disable(sa, action_set->counters,
975 action_set->n_counters);
977 sfc_err(sa, "failed to disable %u MAE counters: %s",
978 action_set->n_counters, rte_strerror(rc));
981 sfc_mae_encap_header_disable(sa, action_set->encap_header);
988 sfc_mae_flow_cleanup(struct sfc_adapter *sa,
989 struct rte_flow *flow)
991 struct sfc_flow_spec *spec;
992 struct sfc_flow_spec_mae *spec_mae;
1002 spec_mae = &spec->mae;
1004 if (spec_mae->ft != NULL) {
1005 if (spec_mae->ft_rule_type == SFC_FT_RULE_JUMP)
1006 spec_mae->ft->jump_rule_is_set = B_FALSE;
1008 SFC_ASSERT(spec_mae->ft->refcnt != 0);
1009 --(spec_mae->ft->refcnt);
1012 SFC_ASSERT(spec_mae->rule_id.id == EFX_MAE_RSRC_ID_INVALID);
1014 if (spec_mae->outer_rule != NULL)
1015 sfc_mae_outer_rule_del(sa, spec_mae->outer_rule);
1017 if (spec_mae->action_set != NULL)
1018 sfc_mae_action_set_del(sa, spec_mae->action_set);
1020 if (spec_mae->match_spec != NULL)
1021 efx_mae_match_spec_fini(sa->nic, spec_mae->match_spec);
1025 sfc_mae_set_ethertypes(struct sfc_mae_parse_ctx *ctx)
1027 struct sfc_mae_pattern_data *pdata = &ctx->pattern_data;
1028 const efx_mae_field_id_t *fremap = ctx->field_ids_remap;
1029 const efx_mae_field_id_t field_ids[] = {
1030 EFX_MAE_FIELD_VLAN0_PROTO_BE,
1031 EFX_MAE_FIELD_VLAN1_PROTO_BE,
1033 const struct sfc_mae_ethertype *et;
1038 * In accordance with RTE flow API convention, the innermost L2
1039 * item's "type" ("inner_type") is a L3 EtherType. If there is
1040 * no L3 item, it's 0x0000/0x0000.
1042 et = &pdata->ethertypes[pdata->nb_vlan_tags];
1043 rc = efx_mae_match_spec_field_set(ctx->match_spec,
1044 fremap[EFX_MAE_FIELD_ETHER_TYPE_BE],
1046 (const uint8_t *)&et->value,
1048 (const uint8_t *)&et->mask);
1053 * sfc_mae_rule_parse_item_vlan() has already made sure
1054 * that pdata->nb_vlan_tags does not exceed this figure.
1056 RTE_BUILD_BUG_ON(SFC_MAE_MATCH_VLAN_MAX_NTAGS != 2);
1058 for (i = 0; i < pdata->nb_vlan_tags; ++i) {
1059 et = &pdata->ethertypes[i];
1061 rc = efx_mae_match_spec_field_set(ctx->match_spec,
1062 fremap[field_ids[i]],
1064 (const uint8_t *)&et->value,
1066 (const uint8_t *)&et->mask);
1075 sfc_mae_rule_process_pattern_data(struct sfc_mae_parse_ctx *ctx,
1076 struct rte_flow_error *error)
1078 const efx_mae_field_id_t *fremap = ctx->field_ids_remap;
1079 struct sfc_mae_pattern_data *pdata = &ctx->pattern_data;
1080 struct sfc_mae_ethertype *ethertypes = pdata->ethertypes;
1081 const rte_be16_t supported_tpids[] = {
1082 /* VLAN standard TPID (always the first element) */
1083 RTE_BE16(RTE_ETHER_TYPE_VLAN),
1085 /* Double-tagging TPIDs */
1086 RTE_BE16(RTE_ETHER_TYPE_QINQ),
1087 RTE_BE16(RTE_ETHER_TYPE_QINQ1),
1088 RTE_BE16(RTE_ETHER_TYPE_QINQ2),
1089 RTE_BE16(RTE_ETHER_TYPE_QINQ3),
1091 bool enforce_tag_presence[SFC_MAE_MATCH_VLAN_MAX_NTAGS] = {0};
1092 unsigned int nb_supported_tpids = RTE_DIM(supported_tpids);
1093 unsigned int ethertype_idx;
1094 const uint8_t *valuep;
1095 const uint8_t *maskp;
1098 if (pdata->innermost_ethertype_restriction.mask != 0 &&
1099 pdata->nb_vlan_tags < SFC_MAE_MATCH_VLAN_MAX_NTAGS) {
1101 * If a single item VLAN is followed by a L3 item, value
1102 * of "type" in item ETH can't be a double-tagging TPID.
1104 nb_supported_tpids = 1;
1108 * sfc_mae_rule_parse_item_vlan() has already made sure
1109 * that pdata->nb_vlan_tags does not exceed this figure.
1111 RTE_BUILD_BUG_ON(SFC_MAE_MATCH_VLAN_MAX_NTAGS != 2);
1113 for (ethertype_idx = 0;
1114 ethertype_idx < pdata->nb_vlan_tags; ++ethertype_idx) {
1115 rte_be16_t tpid_v = ethertypes[ethertype_idx].value;
1116 rte_be16_t tpid_m = ethertypes[ethertype_idx].mask;
1117 unsigned int tpid_idx;
1120 * This loop can have only two iterations. On the second one,
1121 * drop outer tag presence enforcement bit because the inner
1122 * tag presence automatically assumes that for the outer tag.
1124 enforce_tag_presence[0] = B_FALSE;
1126 if (tpid_m == RTE_BE16(0)) {
1127 if (pdata->tci_masks[ethertype_idx] == RTE_BE16(0))
1128 enforce_tag_presence[ethertype_idx] = B_TRUE;
1130 /* No match on this field, and no value check. */
1131 nb_supported_tpids = 1;
1135 /* Exact match is supported only. */
1136 if (tpid_m != RTE_BE16(0xffff)) {
1137 sfc_err(ctx->sa, "TPID mask must be 0x0 or 0xffff; got 0x%04x",
1138 rte_be_to_cpu_16(tpid_m));
1143 for (tpid_idx = pdata->nb_vlan_tags - ethertype_idx - 1;
1144 tpid_idx < nb_supported_tpids; ++tpid_idx) {
1145 if (tpid_v == supported_tpids[tpid_idx])
1149 if (tpid_idx == nb_supported_tpids) {
1150 sfc_err(ctx->sa, "TPID 0x%04x is unsupported",
1151 rte_be_to_cpu_16(tpid_v));
1156 nb_supported_tpids = 1;
1159 if (pdata->innermost_ethertype_restriction.mask == RTE_BE16(0xffff)) {
1160 struct sfc_mae_ethertype *et = ðertypes[ethertype_idx];
1161 rte_be16_t enforced_et;
1163 enforced_et = pdata->innermost_ethertype_restriction.value;
1165 if (et->mask == 0) {
1166 et->mask = RTE_BE16(0xffff);
1167 et->value = enforced_et;
1168 } else if (et->mask != RTE_BE16(0xffff) ||
1169 et->value != enforced_et) {
1170 sfc_err(ctx->sa, "L3 EtherType must be 0x0/0x0 or 0x%04x/0xffff; got 0x%04x/0x%04x",
1171 rte_be_to_cpu_16(enforced_et),
1172 rte_be_to_cpu_16(et->value),
1173 rte_be_to_cpu_16(et->mask));
1180 * Now, when the number of VLAN tags is known, set fields
1181 * ETHER_TYPE, VLAN0_PROTO and VLAN1_PROTO so that the first
1182 * one is either a valid L3 EtherType (or 0x0000/0x0000),
1183 * and the last two are valid TPIDs (or 0x0000/0x0000).
1185 rc = sfc_mae_set_ethertypes(ctx);
1189 if (pdata->l3_next_proto_restriction_mask == 0xff) {
1190 if (pdata->l3_next_proto_mask == 0) {
1191 pdata->l3_next_proto_mask = 0xff;
1192 pdata->l3_next_proto_value =
1193 pdata->l3_next_proto_restriction_value;
1194 } else if (pdata->l3_next_proto_mask != 0xff ||
1195 pdata->l3_next_proto_value !=
1196 pdata->l3_next_proto_restriction_value) {
1197 sfc_err(ctx->sa, "L3 next protocol must be 0x0/0x0 or 0x%02x/0xff; got 0x%02x/0x%02x",
1198 pdata->l3_next_proto_restriction_value,
1199 pdata->l3_next_proto_value,
1200 pdata->l3_next_proto_mask);
1206 if (enforce_tag_presence[0] || pdata->has_ovlan_mask) {
1207 rc = efx_mae_match_spec_bit_set(ctx->match_spec,
1208 fremap[EFX_MAE_FIELD_HAS_OVLAN],
1209 enforce_tag_presence[0] ||
1210 pdata->has_ovlan_value);
1215 if (enforce_tag_presence[1] || pdata->has_ivlan_mask) {
1216 rc = efx_mae_match_spec_bit_set(ctx->match_spec,
1217 fremap[EFX_MAE_FIELD_HAS_IVLAN],
1218 enforce_tag_presence[1] ||
1219 pdata->has_ivlan_value);
1224 valuep = (const uint8_t *)&pdata->l3_next_proto_value;
1225 maskp = (const uint8_t *)&pdata->l3_next_proto_mask;
1226 rc = efx_mae_match_spec_field_set(ctx->match_spec,
1227 fremap[EFX_MAE_FIELD_IP_PROTO],
1228 sizeof(pdata->l3_next_proto_value),
1230 sizeof(pdata->l3_next_proto_mask),
1238 return rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1239 "Failed to process pattern data");
1243 sfc_mae_rule_parse_item_mark(const struct rte_flow_item *item,
1244 struct sfc_flow_parse_ctx *ctx,
1245 struct rte_flow_error *error)
1247 const struct rte_flow_item_mark *spec = item->spec;
1248 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1251 return rte_flow_error_set(error, EINVAL,
1252 RTE_FLOW_ERROR_TYPE_ITEM, item,
1253 "NULL spec in item MARK");
1257 * This item is used in tunnel offload support only.
1258 * It must go before any network header items. This
1259 * way, sfc_mae_rule_preparse_item_mark() must have
1260 * already parsed it. Only one item MARK is allowed.
1262 if (ctx_mae->ft_rule_type != SFC_FT_RULE_GROUP ||
1263 spec->id != (uint32_t)SFC_FT_ID_TO_MARK(ctx_mae->ft->id)) {
1264 return rte_flow_error_set(error, EINVAL,
1265 RTE_FLOW_ERROR_TYPE_ITEM,
1266 item, "invalid item MARK");
1273 sfc_mae_rule_parse_item_port_id(const struct rte_flow_item *item,
1274 struct sfc_flow_parse_ctx *ctx,
1275 struct rte_flow_error *error)
1277 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1278 const struct rte_flow_item_port_id supp_mask = {
1281 const void *def_mask = &rte_flow_item_port_id_mask;
1282 const struct rte_flow_item_port_id *spec = NULL;
1283 const struct rte_flow_item_port_id *mask = NULL;
1284 efx_mport_sel_t mport_sel;
1287 if (ctx_mae->match_mport_set) {
1288 return rte_flow_error_set(error, ENOTSUP,
1289 RTE_FLOW_ERROR_TYPE_ITEM, item,
1290 "Can't handle multiple traffic source items");
1293 rc = sfc_flow_parse_init(item,
1294 (const void **)&spec, (const void **)&mask,
1295 (const void *)&supp_mask, def_mask,
1296 sizeof(struct rte_flow_item_port_id), error);
1300 if (mask->id != supp_mask.id) {
1301 return rte_flow_error_set(error, EINVAL,
1302 RTE_FLOW_ERROR_TYPE_ITEM, item,
1303 "Bad mask in the PORT_ID pattern item");
1306 /* If "spec" is not set, could be any port ID */
1310 if (spec->id > UINT16_MAX) {
1311 return rte_flow_error_set(error, EOVERFLOW,
1312 RTE_FLOW_ERROR_TYPE_ITEM, item,
1313 "The port ID is too large");
1316 rc = sfc_mae_switch_get_ethdev_mport(ctx_mae->sa->mae.switch_domain_id,
1317 spec->id, &mport_sel);
1319 return rte_flow_error_set(error, rc,
1320 RTE_FLOW_ERROR_TYPE_ITEM, item,
1321 "Can't get m-port for the given ethdev");
1324 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec,
1327 return rte_flow_error_set(error, rc,
1328 RTE_FLOW_ERROR_TYPE_ITEM, item,
1329 "Failed to set MPORT for the port ID");
1332 ctx_mae->match_mport_set = B_TRUE;
1338 sfc_mae_rule_parse_item_ethdev_based(const struct rte_flow_item *item,
1339 struct sfc_flow_parse_ctx *ctx,
1340 struct rte_flow_error *error)
1342 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1343 const struct rte_flow_item_ethdev supp_mask = {
1346 const void *def_mask = &rte_flow_item_ethdev_mask;
1347 const struct rte_flow_item_ethdev *spec = NULL;
1348 const struct rte_flow_item_ethdev *mask = NULL;
1349 efx_mport_sel_t mport_sel;
1352 if (ctx_mae->match_mport_set) {
1353 return rte_flow_error_set(error, ENOTSUP,
1354 RTE_FLOW_ERROR_TYPE_ITEM, item,
1355 "Can't handle multiple traffic source items");
1358 rc = sfc_flow_parse_init(item,
1359 (const void **)&spec, (const void **)&mask,
1360 (const void *)&supp_mask, def_mask,
1361 sizeof(struct rte_flow_item_ethdev), error);
1365 if (mask->port_id != supp_mask.port_id) {
1366 return rte_flow_error_set(error, EINVAL,
1367 RTE_FLOW_ERROR_TYPE_ITEM, item,
1368 "Bad mask in the ethdev-based pattern item");
1371 /* If "spec" is not set, could be any port ID */
1375 switch (item->type) {
1376 case RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR:
1377 rc = sfc_mae_switch_get_ethdev_mport(
1378 ctx_mae->sa->mae.switch_domain_id,
1379 spec->port_id, &mport_sel);
1381 return rte_flow_error_set(error, rc,
1382 RTE_FLOW_ERROR_TYPE_ITEM, item,
1383 "Can't get m-port for the given ethdev");
1386 case RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT:
1387 rc = sfc_mae_switch_get_entity_mport(
1388 ctx_mae->sa->mae.switch_domain_id,
1389 spec->port_id, &mport_sel);
1391 return rte_flow_error_set(error, rc,
1392 RTE_FLOW_ERROR_TYPE_ITEM, item,
1393 "Can't get m-port for the given ethdev");
1397 return rte_flow_error_set(error, EINVAL,
1398 RTE_FLOW_ERROR_TYPE_ITEM, item,
1399 "Unsupported ethdev-based flow item");
1402 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec,
1405 return rte_flow_error_set(error, rc,
1406 RTE_FLOW_ERROR_TYPE_ITEM, item,
1407 "Failed to set MPORT for the port ID");
1410 ctx_mae->match_mport_set = B_TRUE;
1416 sfc_mae_rule_parse_item_phy_port(const struct rte_flow_item *item,
1417 struct sfc_flow_parse_ctx *ctx,
1418 struct rte_flow_error *error)
1420 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1421 const struct rte_flow_item_phy_port supp_mask = {
1422 .index = 0xffffffff,
1424 const void *def_mask = &rte_flow_item_phy_port_mask;
1425 const struct rte_flow_item_phy_port *spec = NULL;
1426 const struct rte_flow_item_phy_port *mask = NULL;
1427 efx_mport_sel_t mport_v;
1430 if (ctx_mae->match_mport_set) {
1431 return rte_flow_error_set(error, ENOTSUP,
1432 RTE_FLOW_ERROR_TYPE_ITEM, item,
1433 "Can't handle multiple traffic source items");
1436 rc = sfc_flow_parse_init(item,
1437 (const void **)&spec, (const void **)&mask,
1438 (const void *)&supp_mask, def_mask,
1439 sizeof(struct rte_flow_item_phy_port), error);
1443 if (mask->index != supp_mask.index) {
1444 return rte_flow_error_set(error, EINVAL,
1445 RTE_FLOW_ERROR_TYPE_ITEM, item,
1446 "Bad mask in the PHY_PORT pattern item");
1449 /* If "spec" is not set, could be any physical port */
1453 rc = efx_mae_mport_by_phy_port(spec->index, &mport_v);
1455 return rte_flow_error_set(error, rc,
1456 RTE_FLOW_ERROR_TYPE_ITEM, item,
1457 "Failed to convert the PHY_PORT index");
1460 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec, &mport_v, NULL);
1462 return rte_flow_error_set(error, rc,
1463 RTE_FLOW_ERROR_TYPE_ITEM, item,
1464 "Failed to set MPORT for the PHY_PORT");
1467 ctx_mae->match_mport_set = B_TRUE;
1473 sfc_mae_rule_parse_item_pf(const struct rte_flow_item *item,
1474 struct sfc_flow_parse_ctx *ctx,
1475 struct rte_flow_error *error)
1477 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1478 const efx_nic_cfg_t *encp = efx_nic_cfg_get(ctx_mae->sa->nic);
1479 efx_mport_sel_t mport_v;
1482 if (ctx_mae->match_mport_set) {
1483 return rte_flow_error_set(error, ENOTSUP,
1484 RTE_FLOW_ERROR_TYPE_ITEM, item,
1485 "Can't handle multiple traffic source items");
1488 rc = efx_mae_mport_by_pcie_function(encp->enc_pf, EFX_PCI_VF_INVALID,
1491 return rte_flow_error_set(error, rc,
1492 RTE_FLOW_ERROR_TYPE_ITEM, item,
1493 "Failed to convert the PF ID");
1496 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec, &mport_v, NULL);
1498 return rte_flow_error_set(error, rc,
1499 RTE_FLOW_ERROR_TYPE_ITEM, item,
1500 "Failed to set MPORT for the PF");
1503 ctx_mae->match_mport_set = B_TRUE;
1509 sfc_mae_rule_parse_item_vf(const struct rte_flow_item *item,
1510 struct sfc_flow_parse_ctx *ctx,
1511 struct rte_flow_error *error)
1513 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1514 const efx_nic_cfg_t *encp = efx_nic_cfg_get(ctx_mae->sa->nic);
1515 const struct rte_flow_item_vf supp_mask = {
1518 const void *def_mask = &rte_flow_item_vf_mask;
1519 const struct rte_flow_item_vf *spec = NULL;
1520 const struct rte_flow_item_vf *mask = NULL;
1521 efx_mport_sel_t mport_v;
1524 if (ctx_mae->match_mport_set) {
1525 return rte_flow_error_set(error, ENOTSUP,
1526 RTE_FLOW_ERROR_TYPE_ITEM, item,
1527 "Can't handle multiple traffic source items");
1530 rc = sfc_flow_parse_init(item,
1531 (const void **)&spec, (const void **)&mask,
1532 (const void *)&supp_mask, def_mask,
1533 sizeof(struct rte_flow_item_vf), error);
1537 if (mask->id != supp_mask.id) {
1538 return rte_flow_error_set(error, EINVAL,
1539 RTE_FLOW_ERROR_TYPE_ITEM, item,
1540 "Bad mask in the VF pattern item");
1544 * If "spec" is not set, the item requests any VF related to the
1545 * PF of the current DPDK port (but not the PF itself).
1546 * Reject this match criterion as unsupported.
1549 return rte_flow_error_set(error, EINVAL,
1550 RTE_FLOW_ERROR_TYPE_ITEM, item,
1551 "Bad spec in the VF pattern item");
1554 rc = efx_mae_mport_by_pcie_function(encp->enc_pf, spec->id, &mport_v);
1556 return rte_flow_error_set(error, rc,
1557 RTE_FLOW_ERROR_TYPE_ITEM, item,
1558 "Failed to convert the PF + VF IDs");
1561 rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec, &mport_v, NULL);
1563 return rte_flow_error_set(error, rc,
1564 RTE_FLOW_ERROR_TYPE_ITEM, item,
1565 "Failed to set MPORT for the PF + VF");
1568 ctx_mae->match_mport_set = B_TRUE;
1574 * Having this field ID in a field locator means that this
1575 * locator cannot be used to actually set the field at the
1576 * time when the corresponding item gets encountered. Such
1577 * fields get stashed in the parsing context instead. This
1578 * is required to resolve dependencies between the stashed
1579 * fields. See sfc_mae_rule_process_pattern_data().
1581 #define SFC_MAE_FIELD_HANDLING_DEFERRED EFX_MAE_FIELD_NIDS
1583 struct sfc_mae_field_locator {
1584 efx_mae_field_id_t field_id;
1586 /* Field offset in the corresponding rte_flow_item_ struct */
1591 sfc_mae_item_build_supp_mask(const struct sfc_mae_field_locator *field_locators,
1592 unsigned int nb_field_locators, void *mask_ptr,
1597 memset(mask_ptr, 0, mask_size);
1599 for (i = 0; i < nb_field_locators; ++i) {
1600 const struct sfc_mae_field_locator *fl = &field_locators[i];
1602 SFC_ASSERT(fl->ofst + fl->size <= mask_size);
1603 memset(RTE_PTR_ADD(mask_ptr, fl->ofst), 0xff, fl->size);
1608 sfc_mae_parse_item(const struct sfc_mae_field_locator *field_locators,
1609 unsigned int nb_field_locators, const uint8_t *spec,
1610 const uint8_t *mask, struct sfc_mae_parse_ctx *ctx,
1611 struct rte_flow_error *error)
1613 const efx_mae_field_id_t *fremap = ctx->field_ids_remap;
1617 for (i = 0; i < nb_field_locators; ++i) {
1618 const struct sfc_mae_field_locator *fl = &field_locators[i];
1620 if (fl->field_id == SFC_MAE_FIELD_HANDLING_DEFERRED)
1623 rc = efx_mae_match_spec_field_set(ctx->match_spec,
1624 fremap[fl->field_id],
1625 fl->size, spec + fl->ofst,
1626 fl->size, mask + fl->ofst);
1632 rc = rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM,
1633 NULL, "Failed to process item fields");
1639 static const struct sfc_mae_field_locator flocs_eth[] = {
1642 * This locator is used only for building supported fields mask.
1643 * The field is handled by sfc_mae_rule_process_pattern_data().
1645 SFC_MAE_FIELD_HANDLING_DEFERRED,
1646 RTE_SIZEOF_FIELD(struct rte_flow_item_eth, type),
1647 offsetof(struct rte_flow_item_eth, type),
1650 EFX_MAE_FIELD_ETH_DADDR_BE,
1651 RTE_SIZEOF_FIELD(struct rte_flow_item_eth, dst),
1652 offsetof(struct rte_flow_item_eth, dst),
1655 EFX_MAE_FIELD_ETH_SADDR_BE,
1656 RTE_SIZEOF_FIELD(struct rte_flow_item_eth, src),
1657 offsetof(struct rte_flow_item_eth, src),
1662 sfc_mae_rule_parse_item_eth(const struct rte_flow_item *item,
1663 struct sfc_flow_parse_ctx *ctx,
1664 struct rte_flow_error *error)
1666 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1667 struct rte_flow_item_eth override_mask;
1668 struct rte_flow_item_eth supp_mask;
1669 const uint8_t *spec = NULL;
1670 const uint8_t *mask = NULL;
1673 sfc_mae_item_build_supp_mask(flocs_eth, RTE_DIM(flocs_eth),
1674 &supp_mask, sizeof(supp_mask));
1675 supp_mask.has_vlan = 1;
1677 rc = sfc_flow_parse_init(item,
1678 (const void **)&spec, (const void **)&mask,
1679 (const void *)&supp_mask,
1680 &rte_flow_item_eth_mask,
1681 sizeof(struct rte_flow_item_eth), error);
1685 if (ctx_mae->ft_rule_type == SFC_FT_RULE_JUMP && mask != NULL) {
1687 * The HW/FW hasn't got support for match on MAC addresses in
1688 * outer rules yet (this will change). Match on VLAN presence
1689 * isn't supported either. Ignore these match criteria.
1691 memcpy(&override_mask, mask, sizeof(override_mask));
1692 memset(&override_mask.hdr.dst_addr, 0,
1693 sizeof(override_mask.hdr.dst_addr));
1694 memset(&override_mask.hdr.src_addr, 0,
1695 sizeof(override_mask.hdr.src_addr));
1696 override_mask.has_vlan = 0;
1698 mask = (const uint8_t *)&override_mask;
1702 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
1703 struct sfc_mae_ethertype *ethertypes = pdata->ethertypes;
1704 const struct rte_flow_item_eth *item_spec;
1705 const struct rte_flow_item_eth *item_mask;
1707 item_spec = (const struct rte_flow_item_eth *)spec;
1708 item_mask = (const struct rte_flow_item_eth *)mask;
1711 * Remember various match criteria in the parsing context.
1712 * sfc_mae_rule_process_pattern_data() will consider them
1713 * altogether when the rest of the items have been parsed.
1715 ethertypes[0].value = item_spec->type;
1716 ethertypes[0].mask = item_mask->type;
1717 if (item_mask->has_vlan) {
1718 pdata->has_ovlan_mask = B_TRUE;
1719 if (item_spec->has_vlan)
1720 pdata->has_ovlan_value = B_TRUE;
1724 * The specification is empty. The overall pattern
1725 * validity will be enforced at the end of parsing.
1726 * See sfc_mae_rule_process_pattern_data().
1731 return sfc_mae_parse_item(flocs_eth, RTE_DIM(flocs_eth), spec, mask,
1735 static const struct sfc_mae_field_locator flocs_vlan[] = {
1738 EFX_MAE_FIELD_VLAN0_TCI_BE,
1739 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, tci),
1740 offsetof(struct rte_flow_item_vlan, tci),
1744 * This locator is used only for building supported fields mask.
1745 * The field is handled by sfc_mae_rule_process_pattern_data().
1747 SFC_MAE_FIELD_HANDLING_DEFERRED,
1748 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, inner_type),
1749 offsetof(struct rte_flow_item_vlan, inner_type),
1754 EFX_MAE_FIELD_VLAN1_TCI_BE,
1755 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, tci),
1756 offsetof(struct rte_flow_item_vlan, tci),
1760 * This locator is used only for building supported fields mask.
1761 * The field is handled by sfc_mae_rule_process_pattern_data().
1763 SFC_MAE_FIELD_HANDLING_DEFERRED,
1764 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, inner_type),
1765 offsetof(struct rte_flow_item_vlan, inner_type),
1770 sfc_mae_rule_parse_item_vlan(const struct rte_flow_item *item,
1771 struct sfc_flow_parse_ctx *ctx,
1772 struct rte_flow_error *error)
1774 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1775 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
1776 boolean_t *has_vlan_mp_by_nb_tags[SFC_MAE_MATCH_VLAN_MAX_NTAGS] = {
1777 &pdata->has_ovlan_mask,
1778 &pdata->has_ivlan_mask,
1780 boolean_t *has_vlan_vp_by_nb_tags[SFC_MAE_MATCH_VLAN_MAX_NTAGS] = {
1781 &pdata->has_ovlan_value,
1782 &pdata->has_ivlan_value,
1784 boolean_t *cur_tag_presence_bit_mp;
1785 boolean_t *cur_tag_presence_bit_vp;
1786 const struct sfc_mae_field_locator *flocs;
1787 struct rte_flow_item_vlan supp_mask;
1788 const uint8_t *spec = NULL;
1789 const uint8_t *mask = NULL;
1790 unsigned int nb_flocs;
1793 RTE_BUILD_BUG_ON(SFC_MAE_MATCH_VLAN_MAX_NTAGS != 2);
1795 if (pdata->nb_vlan_tags == SFC_MAE_MATCH_VLAN_MAX_NTAGS) {
1796 return rte_flow_error_set(error, ENOTSUP,
1797 RTE_FLOW_ERROR_TYPE_ITEM, item,
1798 "Can't match that many VLAN tags");
1801 cur_tag_presence_bit_mp = has_vlan_mp_by_nb_tags[pdata->nb_vlan_tags];
1802 cur_tag_presence_bit_vp = has_vlan_vp_by_nb_tags[pdata->nb_vlan_tags];
1804 if (*cur_tag_presence_bit_mp == B_TRUE &&
1805 *cur_tag_presence_bit_vp == B_FALSE) {
1806 return rte_flow_error_set(error, EINVAL,
1807 RTE_FLOW_ERROR_TYPE_ITEM, item,
1808 "The previous item enforces no (more) VLAN, "
1809 "so the current item (VLAN) must not exist");
1812 nb_flocs = RTE_DIM(flocs_vlan) / SFC_MAE_MATCH_VLAN_MAX_NTAGS;
1813 flocs = flocs_vlan + pdata->nb_vlan_tags * nb_flocs;
1815 sfc_mae_item_build_supp_mask(flocs, nb_flocs,
1816 &supp_mask, sizeof(supp_mask));
1818 * This only means that the field is supported by the driver and libefx.
1819 * Support on NIC level will be checked when all items have been parsed.
1821 supp_mask.has_more_vlan = 1;
1823 rc = sfc_flow_parse_init(item,
1824 (const void **)&spec, (const void **)&mask,
1825 (const void *)&supp_mask,
1826 &rte_flow_item_vlan_mask,
1827 sizeof(struct rte_flow_item_vlan), error);
1832 struct sfc_mae_ethertype *et = pdata->ethertypes;
1833 const struct rte_flow_item_vlan *item_spec;
1834 const struct rte_flow_item_vlan *item_mask;
1836 item_spec = (const struct rte_flow_item_vlan *)spec;
1837 item_mask = (const struct rte_flow_item_vlan *)mask;
1840 * Remember various match criteria in the parsing context.
1841 * sfc_mae_rule_process_pattern_data() will consider them
1842 * altogether when the rest of the items have been parsed.
1844 et[pdata->nb_vlan_tags + 1].value = item_spec->inner_type;
1845 et[pdata->nb_vlan_tags + 1].mask = item_mask->inner_type;
1846 pdata->tci_masks[pdata->nb_vlan_tags] = item_mask->tci;
1847 if (item_mask->has_more_vlan) {
1848 if (pdata->nb_vlan_tags ==
1849 SFC_MAE_MATCH_VLAN_MAX_NTAGS) {
1850 return rte_flow_error_set(error, ENOTSUP,
1851 RTE_FLOW_ERROR_TYPE_ITEM, item,
1852 "Can't use 'has_more_vlan' in "
1853 "the second item VLAN");
1855 pdata->has_ivlan_mask = B_TRUE;
1856 if (item_spec->has_more_vlan)
1857 pdata->has_ivlan_value = B_TRUE;
1860 /* Convert TCI to MAE representation right now. */
1861 rc = sfc_mae_parse_item(flocs, nb_flocs, spec, mask,
1867 ++(pdata->nb_vlan_tags);
1872 static const struct sfc_mae_field_locator flocs_ipv4[] = {
1874 EFX_MAE_FIELD_SRC_IP4_BE,
1875 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.src_addr),
1876 offsetof(struct rte_flow_item_ipv4, hdr.src_addr),
1879 EFX_MAE_FIELD_DST_IP4_BE,
1880 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.dst_addr),
1881 offsetof(struct rte_flow_item_ipv4, hdr.dst_addr),
1885 * This locator is used only for building supported fields mask.
1886 * The field is handled by sfc_mae_rule_process_pattern_data().
1888 SFC_MAE_FIELD_HANDLING_DEFERRED,
1889 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.next_proto_id),
1890 offsetof(struct rte_flow_item_ipv4, hdr.next_proto_id),
1893 EFX_MAE_FIELD_IP_TOS,
1894 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4,
1895 hdr.type_of_service),
1896 offsetof(struct rte_flow_item_ipv4, hdr.type_of_service),
1899 EFX_MAE_FIELD_IP_TTL,
1900 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.time_to_live),
1901 offsetof(struct rte_flow_item_ipv4, hdr.time_to_live),
1906 sfc_mae_rule_parse_item_ipv4(const struct rte_flow_item *item,
1907 struct sfc_flow_parse_ctx *ctx,
1908 struct rte_flow_error *error)
1910 rte_be16_t ethertype_ipv4_be = RTE_BE16(RTE_ETHER_TYPE_IPV4);
1911 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1912 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
1913 struct rte_flow_item_ipv4 supp_mask;
1914 const uint8_t *spec = NULL;
1915 const uint8_t *mask = NULL;
1918 sfc_mae_item_build_supp_mask(flocs_ipv4, RTE_DIM(flocs_ipv4),
1919 &supp_mask, sizeof(supp_mask));
1921 rc = sfc_flow_parse_init(item,
1922 (const void **)&spec, (const void **)&mask,
1923 (const void *)&supp_mask,
1924 &rte_flow_item_ipv4_mask,
1925 sizeof(struct rte_flow_item_ipv4), error);
1929 pdata->innermost_ethertype_restriction.value = ethertype_ipv4_be;
1930 pdata->innermost_ethertype_restriction.mask = RTE_BE16(0xffff);
1933 const struct rte_flow_item_ipv4 *item_spec;
1934 const struct rte_flow_item_ipv4 *item_mask;
1936 item_spec = (const struct rte_flow_item_ipv4 *)spec;
1937 item_mask = (const struct rte_flow_item_ipv4 *)mask;
1939 pdata->l3_next_proto_value = item_spec->hdr.next_proto_id;
1940 pdata->l3_next_proto_mask = item_mask->hdr.next_proto_id;
1945 return sfc_mae_parse_item(flocs_ipv4, RTE_DIM(flocs_ipv4), spec, mask,
1949 static const struct sfc_mae_field_locator flocs_ipv6[] = {
1951 EFX_MAE_FIELD_SRC_IP6_BE,
1952 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.src_addr),
1953 offsetof(struct rte_flow_item_ipv6, hdr.src_addr),
1956 EFX_MAE_FIELD_DST_IP6_BE,
1957 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.dst_addr),
1958 offsetof(struct rte_flow_item_ipv6, hdr.dst_addr),
1962 * This locator is used only for building supported fields mask.
1963 * The field is handled by sfc_mae_rule_process_pattern_data().
1965 SFC_MAE_FIELD_HANDLING_DEFERRED,
1966 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.proto),
1967 offsetof(struct rte_flow_item_ipv6, hdr.proto),
1970 EFX_MAE_FIELD_IP_TTL,
1971 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.hop_limits),
1972 offsetof(struct rte_flow_item_ipv6, hdr.hop_limits),
1977 sfc_mae_rule_parse_item_ipv6(const struct rte_flow_item *item,
1978 struct sfc_flow_parse_ctx *ctx,
1979 struct rte_flow_error *error)
1981 rte_be16_t ethertype_ipv6_be = RTE_BE16(RTE_ETHER_TYPE_IPV6);
1982 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1983 const efx_mae_field_id_t *fremap = ctx_mae->field_ids_remap;
1984 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
1985 struct rte_flow_item_ipv6 supp_mask;
1986 const uint8_t *spec = NULL;
1987 const uint8_t *mask = NULL;
1988 rte_be32_t vtc_flow_be;
1994 sfc_mae_item_build_supp_mask(flocs_ipv6, RTE_DIM(flocs_ipv6),
1995 &supp_mask, sizeof(supp_mask));
1997 vtc_flow_be = RTE_BE32(RTE_IPV6_HDR_TC_MASK);
1998 memcpy(&supp_mask, &vtc_flow_be, sizeof(vtc_flow_be));
2000 rc = sfc_flow_parse_init(item,
2001 (const void **)&spec, (const void **)&mask,
2002 (const void *)&supp_mask,
2003 &rte_flow_item_ipv6_mask,
2004 sizeof(struct rte_flow_item_ipv6), error);
2008 pdata->innermost_ethertype_restriction.value = ethertype_ipv6_be;
2009 pdata->innermost_ethertype_restriction.mask = RTE_BE16(0xffff);
2012 const struct rte_flow_item_ipv6 *item_spec;
2013 const struct rte_flow_item_ipv6 *item_mask;
2015 item_spec = (const struct rte_flow_item_ipv6 *)spec;
2016 item_mask = (const struct rte_flow_item_ipv6 *)mask;
2018 pdata->l3_next_proto_value = item_spec->hdr.proto;
2019 pdata->l3_next_proto_mask = item_mask->hdr.proto;
2024 rc = sfc_mae_parse_item(flocs_ipv6, RTE_DIM(flocs_ipv6), spec, mask,
2029 memcpy(&vtc_flow_be, spec, sizeof(vtc_flow_be));
2030 vtc_flow = rte_be_to_cpu_32(vtc_flow_be);
2031 tc_value = (vtc_flow & RTE_IPV6_HDR_TC_MASK) >> RTE_IPV6_HDR_TC_SHIFT;
2033 memcpy(&vtc_flow_be, mask, sizeof(vtc_flow_be));
2034 vtc_flow = rte_be_to_cpu_32(vtc_flow_be);
2035 tc_mask = (vtc_flow & RTE_IPV6_HDR_TC_MASK) >> RTE_IPV6_HDR_TC_SHIFT;
2037 rc = efx_mae_match_spec_field_set(ctx_mae->match_spec,
2038 fremap[EFX_MAE_FIELD_IP_TOS],
2039 sizeof(tc_value), &tc_value,
2040 sizeof(tc_mask), &tc_mask);
2042 return rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM,
2043 NULL, "Failed to process item fields");
2049 static const struct sfc_mae_field_locator flocs_tcp[] = {
2051 EFX_MAE_FIELD_L4_SPORT_BE,
2052 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.src_port),
2053 offsetof(struct rte_flow_item_tcp, hdr.src_port),
2056 EFX_MAE_FIELD_L4_DPORT_BE,
2057 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.dst_port),
2058 offsetof(struct rte_flow_item_tcp, hdr.dst_port),
2061 EFX_MAE_FIELD_TCP_FLAGS_BE,
2063 * The values have been picked intentionally since the
2064 * target MAE field is oversize (16 bit). This mapping
2065 * relies on the fact that the MAE field is big-endian.
2067 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.data_off) +
2068 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.tcp_flags),
2069 offsetof(struct rte_flow_item_tcp, hdr.data_off),
2074 sfc_mae_rule_parse_item_tcp(const struct rte_flow_item *item,
2075 struct sfc_flow_parse_ctx *ctx,
2076 struct rte_flow_error *error)
2078 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
2079 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
2080 struct rte_flow_item_tcp supp_mask;
2081 const uint8_t *spec = NULL;
2082 const uint8_t *mask = NULL;
2086 * When encountered among outermost items, item TCP is invalid.
2087 * Check which match specification is being constructed now.
2089 if (ctx_mae->match_spec != ctx_mae->match_spec_action) {
2090 return rte_flow_error_set(error, EINVAL,
2091 RTE_FLOW_ERROR_TYPE_ITEM, item,
2092 "TCP in outer frame is invalid");
2095 sfc_mae_item_build_supp_mask(flocs_tcp, RTE_DIM(flocs_tcp),
2096 &supp_mask, sizeof(supp_mask));
2098 rc = sfc_flow_parse_init(item,
2099 (const void **)&spec, (const void **)&mask,
2100 (const void *)&supp_mask,
2101 &rte_flow_item_tcp_mask,
2102 sizeof(struct rte_flow_item_tcp), error);
2106 pdata->l3_next_proto_restriction_value = IPPROTO_TCP;
2107 pdata->l3_next_proto_restriction_mask = 0xff;
2112 return sfc_mae_parse_item(flocs_tcp, RTE_DIM(flocs_tcp), spec, mask,
2116 static const struct sfc_mae_field_locator flocs_udp[] = {
2118 EFX_MAE_FIELD_L4_SPORT_BE,
2119 RTE_SIZEOF_FIELD(struct rte_flow_item_udp, hdr.src_port),
2120 offsetof(struct rte_flow_item_udp, hdr.src_port),
2123 EFX_MAE_FIELD_L4_DPORT_BE,
2124 RTE_SIZEOF_FIELD(struct rte_flow_item_udp, hdr.dst_port),
2125 offsetof(struct rte_flow_item_udp, hdr.dst_port),
2130 sfc_mae_rule_parse_item_udp(const struct rte_flow_item *item,
2131 struct sfc_flow_parse_ctx *ctx,
2132 struct rte_flow_error *error)
2134 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
2135 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
2136 struct rte_flow_item_udp supp_mask;
2137 const uint8_t *spec = NULL;
2138 const uint8_t *mask = NULL;
2141 sfc_mae_item_build_supp_mask(flocs_udp, RTE_DIM(flocs_udp),
2142 &supp_mask, sizeof(supp_mask));
2144 rc = sfc_flow_parse_init(item,
2145 (const void **)&spec, (const void **)&mask,
2146 (const void *)&supp_mask,
2147 &rte_flow_item_udp_mask,
2148 sizeof(struct rte_flow_item_udp), error);
2152 pdata->l3_next_proto_restriction_value = IPPROTO_UDP;
2153 pdata->l3_next_proto_restriction_mask = 0xff;
2158 return sfc_mae_parse_item(flocs_udp, RTE_DIM(flocs_udp), spec, mask,
2162 static const struct sfc_mae_field_locator flocs_tunnel[] = {
2165 * The size and offset values are relevant
2166 * for Geneve and NVGRE, too.
2168 .size = RTE_SIZEOF_FIELD(struct rte_flow_item_vxlan, vni),
2169 .ofst = offsetof(struct rte_flow_item_vxlan, vni),
2174 * An auxiliary registry which allows using non-encap. field IDs
2175 * directly when building a match specification of type ACTION.
2177 * See sfc_mae_rule_parse_pattern() and sfc_mae_rule_parse_item_tunnel().
2179 static const efx_mae_field_id_t field_ids_no_remap[] = {
2180 #define FIELD_ID_NO_REMAP(_field) \
2181 [EFX_MAE_FIELD_##_field] = EFX_MAE_FIELD_##_field
2183 FIELD_ID_NO_REMAP(ETHER_TYPE_BE),
2184 FIELD_ID_NO_REMAP(ETH_SADDR_BE),
2185 FIELD_ID_NO_REMAP(ETH_DADDR_BE),
2186 FIELD_ID_NO_REMAP(VLAN0_TCI_BE),
2187 FIELD_ID_NO_REMAP(VLAN0_PROTO_BE),
2188 FIELD_ID_NO_REMAP(VLAN1_TCI_BE),
2189 FIELD_ID_NO_REMAP(VLAN1_PROTO_BE),
2190 FIELD_ID_NO_REMAP(SRC_IP4_BE),
2191 FIELD_ID_NO_REMAP(DST_IP4_BE),
2192 FIELD_ID_NO_REMAP(IP_PROTO),
2193 FIELD_ID_NO_REMAP(IP_TOS),
2194 FIELD_ID_NO_REMAP(IP_TTL),
2195 FIELD_ID_NO_REMAP(SRC_IP6_BE),
2196 FIELD_ID_NO_REMAP(DST_IP6_BE),
2197 FIELD_ID_NO_REMAP(L4_SPORT_BE),
2198 FIELD_ID_NO_REMAP(L4_DPORT_BE),
2199 FIELD_ID_NO_REMAP(TCP_FLAGS_BE),
2200 FIELD_ID_NO_REMAP(HAS_OVLAN),
2201 FIELD_ID_NO_REMAP(HAS_IVLAN),
2203 #undef FIELD_ID_NO_REMAP
2207 * An auxiliary registry which allows using "ENC" field IDs
2208 * when building a match specification of type OUTER.
2210 * See sfc_mae_rule_encap_parse_init().
2212 static const efx_mae_field_id_t field_ids_remap_to_encap[] = {
2213 #define FIELD_ID_REMAP_TO_ENCAP(_field) \
2214 [EFX_MAE_FIELD_##_field] = EFX_MAE_FIELD_ENC_##_field
2216 FIELD_ID_REMAP_TO_ENCAP(ETHER_TYPE_BE),
2217 FIELD_ID_REMAP_TO_ENCAP(ETH_SADDR_BE),
2218 FIELD_ID_REMAP_TO_ENCAP(ETH_DADDR_BE),
2219 FIELD_ID_REMAP_TO_ENCAP(VLAN0_TCI_BE),
2220 FIELD_ID_REMAP_TO_ENCAP(VLAN0_PROTO_BE),
2221 FIELD_ID_REMAP_TO_ENCAP(VLAN1_TCI_BE),
2222 FIELD_ID_REMAP_TO_ENCAP(VLAN1_PROTO_BE),
2223 FIELD_ID_REMAP_TO_ENCAP(SRC_IP4_BE),
2224 FIELD_ID_REMAP_TO_ENCAP(DST_IP4_BE),
2225 FIELD_ID_REMAP_TO_ENCAP(IP_PROTO),
2226 FIELD_ID_REMAP_TO_ENCAP(IP_TOS),
2227 FIELD_ID_REMAP_TO_ENCAP(IP_TTL),
2228 FIELD_ID_REMAP_TO_ENCAP(SRC_IP6_BE),
2229 FIELD_ID_REMAP_TO_ENCAP(DST_IP6_BE),
2230 FIELD_ID_REMAP_TO_ENCAP(L4_SPORT_BE),
2231 FIELD_ID_REMAP_TO_ENCAP(L4_DPORT_BE),
2232 FIELD_ID_REMAP_TO_ENCAP(HAS_OVLAN),
2233 FIELD_ID_REMAP_TO_ENCAP(HAS_IVLAN),
2235 #undef FIELD_ID_REMAP_TO_ENCAP
2239 sfc_mae_rule_parse_item_tunnel(const struct rte_flow_item *item,
2240 struct sfc_flow_parse_ctx *ctx,
2241 struct rte_flow_error *error)
2243 struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
2244 uint8_t vnet_id_v[sizeof(uint32_t)] = {0};
2245 uint8_t vnet_id_m[sizeof(uint32_t)] = {0};
2246 const struct rte_flow_item_vxlan *vxp;
2247 uint8_t supp_mask[sizeof(uint64_t)];
2248 const uint8_t *spec = NULL;
2249 const uint8_t *mask = NULL;
2252 if (ctx_mae->ft_rule_type == SFC_FT_RULE_GROUP) {
2254 * As a workaround, pattern processing has started from
2255 * this (tunnel) item. No pattern data to process yet.
2259 * We're about to start processing inner frame items.
2260 * Process pattern data that has been deferred so far
2261 * and reset pattern data storage.
2263 rc = sfc_mae_rule_process_pattern_data(ctx_mae, error);
2268 memset(&ctx_mae->pattern_data, 0, sizeof(ctx_mae->pattern_data));
2270 sfc_mae_item_build_supp_mask(flocs_tunnel, RTE_DIM(flocs_tunnel),
2271 &supp_mask, sizeof(supp_mask));
2274 * This tunnel item was preliminarily detected by
2275 * sfc_mae_rule_encap_parse_init(). Default mask
2276 * was also picked by that helper. Use it here.
2278 rc = sfc_flow_parse_init(item,
2279 (const void **)&spec, (const void **)&mask,
2280 (const void *)&supp_mask,
2281 ctx_mae->tunnel_def_mask,
2282 ctx_mae->tunnel_def_mask_size, error);
2287 * This item and later ones comprise a
2288 * match specification of type ACTION.
2290 ctx_mae->match_spec = ctx_mae->match_spec_action;
2292 /* This item and later ones use non-encap. EFX MAE field IDs. */
2293 ctx_mae->field_ids_remap = field_ids_no_remap;
2299 * Field EFX_MAE_FIELD_ENC_VNET_ID_BE is a 32-bit one.
2300 * Copy 24-bit VNI, which is BE, at offset 1 in it.
2301 * The extra byte is 0 both in the mask and in the value.
2303 vxp = (const struct rte_flow_item_vxlan *)spec;
2304 memcpy(vnet_id_v + 1, &vxp->vni, sizeof(vxp->vni));
2306 vxp = (const struct rte_flow_item_vxlan *)mask;
2307 memcpy(vnet_id_m + 1, &vxp->vni, sizeof(vxp->vni));
2309 rc = efx_mae_match_spec_field_set(ctx_mae->match_spec,
2310 EFX_MAE_FIELD_ENC_VNET_ID_BE,
2311 sizeof(vnet_id_v), vnet_id_v,
2312 sizeof(vnet_id_m), vnet_id_m);
2314 rc = rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM,
2315 item, "Failed to set VXLAN VNI");
2321 static const struct sfc_flow_item sfc_flow_items[] = {
2323 .type = RTE_FLOW_ITEM_TYPE_MARK,
2325 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2326 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2327 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2328 .parse = sfc_mae_rule_parse_item_mark,
2331 .type = RTE_FLOW_ITEM_TYPE_PORT_ID,
2334 * In terms of RTE flow, this item is a META one,
2335 * and its position in the pattern is don't care.
2337 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2338 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2339 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2340 .parse = sfc_mae_rule_parse_item_port_id,
2343 .type = RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR,
2344 .name = "PORT_REPRESENTOR",
2346 * In terms of RTE flow, this item is a META one,
2347 * and its position in the pattern is don't care.
2349 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2350 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2351 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2352 .parse = sfc_mae_rule_parse_item_ethdev_based,
2355 .type = RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT,
2356 .name = "REPRESENTED_PORT",
2358 * In terms of RTE flow, this item is a META one,
2359 * and its position in the pattern is don't care.
2361 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2362 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2363 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2364 .parse = sfc_mae_rule_parse_item_ethdev_based,
2367 .type = RTE_FLOW_ITEM_TYPE_PHY_PORT,
2370 * In terms of RTE flow, this item is a META one,
2371 * and its position in the pattern is don't care.
2373 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2374 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2375 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2376 .parse = sfc_mae_rule_parse_item_phy_port,
2379 .type = RTE_FLOW_ITEM_TYPE_PF,
2382 * In terms of RTE flow, this item is a META one,
2383 * and its position in the pattern is don't care.
2385 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2386 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2387 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2388 .parse = sfc_mae_rule_parse_item_pf,
2391 .type = RTE_FLOW_ITEM_TYPE_VF,
2394 * In terms of RTE flow, this item is a META one,
2395 * and its position in the pattern is don't care.
2397 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
2398 .layer = SFC_FLOW_ITEM_ANY_LAYER,
2399 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2400 .parse = sfc_mae_rule_parse_item_vf,
2403 .type = RTE_FLOW_ITEM_TYPE_ETH,
2405 .prev_layer = SFC_FLOW_ITEM_START_LAYER,
2406 .layer = SFC_FLOW_ITEM_L2,
2407 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2408 .parse = sfc_mae_rule_parse_item_eth,
2411 .type = RTE_FLOW_ITEM_TYPE_VLAN,
2413 .prev_layer = SFC_FLOW_ITEM_L2,
2414 .layer = SFC_FLOW_ITEM_L2,
2415 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2416 .parse = sfc_mae_rule_parse_item_vlan,
2419 .type = RTE_FLOW_ITEM_TYPE_IPV4,
2421 .prev_layer = SFC_FLOW_ITEM_L2,
2422 .layer = SFC_FLOW_ITEM_L3,
2423 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2424 .parse = sfc_mae_rule_parse_item_ipv4,
2427 .type = RTE_FLOW_ITEM_TYPE_IPV6,
2429 .prev_layer = SFC_FLOW_ITEM_L2,
2430 .layer = SFC_FLOW_ITEM_L3,
2431 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2432 .parse = sfc_mae_rule_parse_item_ipv6,
2435 .type = RTE_FLOW_ITEM_TYPE_TCP,
2437 .prev_layer = SFC_FLOW_ITEM_L3,
2438 .layer = SFC_FLOW_ITEM_L4,
2439 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2440 .parse = sfc_mae_rule_parse_item_tcp,
2443 .type = RTE_FLOW_ITEM_TYPE_UDP,
2445 .prev_layer = SFC_FLOW_ITEM_L3,
2446 .layer = SFC_FLOW_ITEM_L4,
2447 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2448 .parse = sfc_mae_rule_parse_item_udp,
2451 .type = RTE_FLOW_ITEM_TYPE_VXLAN,
2453 .prev_layer = SFC_FLOW_ITEM_L4,
2454 .layer = SFC_FLOW_ITEM_START_LAYER,
2455 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2456 .parse = sfc_mae_rule_parse_item_tunnel,
2459 .type = RTE_FLOW_ITEM_TYPE_GENEVE,
2461 .prev_layer = SFC_FLOW_ITEM_L4,
2462 .layer = SFC_FLOW_ITEM_START_LAYER,
2463 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2464 .parse = sfc_mae_rule_parse_item_tunnel,
2467 .type = RTE_FLOW_ITEM_TYPE_NVGRE,
2469 .prev_layer = SFC_FLOW_ITEM_L3,
2470 .layer = SFC_FLOW_ITEM_START_LAYER,
2471 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
2472 .parse = sfc_mae_rule_parse_item_tunnel,
2477 sfc_mae_rule_process_outer(struct sfc_adapter *sa,
2478 struct sfc_mae_parse_ctx *ctx,
2479 struct sfc_mae_outer_rule **rulep,
2480 struct rte_flow_error *error)
2482 efx_mae_rule_id_t invalid_rule_id = { .id = EFX_MAE_RSRC_ID_INVALID };
2485 if (ctx->encap_type == EFX_TUNNEL_PROTOCOL_NONE) {
2490 SFC_ASSERT(ctx->match_spec_outer != NULL);
2492 if (!efx_mae_match_spec_is_valid(sa->nic, ctx->match_spec_outer)) {
2493 return rte_flow_error_set(error, ENOTSUP,
2494 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2495 "Inconsistent pattern (outer)");
2498 *rulep = sfc_mae_outer_rule_attach(sa, ctx->match_spec_outer,
2500 if (*rulep != NULL) {
2501 efx_mae_match_spec_fini(sa->nic, ctx->match_spec_outer);
2503 rc = sfc_mae_outer_rule_add(sa, ctx->match_spec_outer,
2504 ctx->encap_type, rulep);
2506 return rte_flow_error_set(error, rc,
2507 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2508 "Failed to process the pattern");
2512 /* The spec has now been tracked by the outer rule entry. */
2513 ctx->match_spec_outer = NULL;
2516 switch (ctx->ft_rule_type) {
2517 case SFC_FT_RULE_NONE:
2519 case SFC_FT_RULE_JUMP:
2520 /* No action rule */
2522 case SFC_FT_RULE_GROUP:
2524 * Match on recirculation ID rather than
2525 * on the outer rule allocation handle.
2527 rc = efx_mae_match_spec_recirc_id_set(ctx->match_spec_action,
2528 SFC_FT_ID_TO_TUNNEL_MARK(ctx->ft->id));
2530 return rte_flow_error_set(error, rc,
2531 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2532 "tunnel offload: GROUP: AR: failed to request match on RECIRC_ID");
2536 SFC_ASSERT(B_FALSE);
2540 * In MAE, lookup sequence comprises outer parse, outer rule lookup,
2541 * inner parse (when some outer rule is hit) and action rule lookup.
2542 * If the currently processed flow does not come with an outer rule,
2543 * its action rule must be available only for packets which miss in
2544 * outer rule table. Set OR_ID match field to 0xffffffff/0xffffffff
2545 * in the action rule specification; this ensures correct behaviour.
2547 * If, on the other hand, this flow does have an outer rule, its ID
2548 * may be unknown at the moment (not yet allocated), but OR_ID mask
2549 * has to be set to 0xffffffff anyway for correct class comparisons.
2550 * When the outer rule has been allocated, this match field will be
2551 * overridden by sfc_mae_outer_rule_enable() to use the right value.
2553 rc = efx_mae_match_spec_outer_rule_id_set(ctx->match_spec_action,
2557 sfc_mae_outer_rule_del(sa, *rulep);
2561 return rte_flow_error_set(error, rc,
2562 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2563 "Failed to process the pattern");
2570 sfc_mae_rule_preparse_item_mark(const struct rte_flow_item_mark *spec,
2571 struct sfc_mae_parse_ctx *ctx)
2573 struct sfc_flow_tunnel *ft;
2577 sfc_err(ctx->sa, "tunnel offload: GROUP: NULL spec in item MARK");
2581 ft = sfc_flow_tunnel_pick(ctx->sa, spec->id);
2583 sfc_err(ctx->sa, "tunnel offload: GROUP: invalid tunnel");
2587 if (ft->refcnt == 0) {
2588 sfc_err(ctx->sa, "tunnel offload: GROUP: tunnel=%u does not exist",
2593 user_mark = SFC_FT_GET_USER_MARK(spec->id);
2594 if (user_mark != 0) {
2595 sfc_err(ctx->sa, "tunnel offload: GROUP: invalid item MARK");
2599 sfc_dbg(ctx->sa, "tunnel offload: GROUP: detected");
2601 ctx->ft_rule_type = SFC_FT_RULE_GROUP;
2608 sfc_mae_rule_encap_parse_init(struct sfc_adapter *sa,
2609 struct sfc_mae_parse_ctx *ctx,
2610 struct rte_flow_error *error)
2612 const struct rte_flow_item *pattern = ctx->pattern;
2613 struct sfc_mae *mae = &sa->mae;
2614 uint8_t recirc_id = 0;
2617 if (pattern == NULL) {
2618 rte_flow_error_set(error, EINVAL,
2619 RTE_FLOW_ERROR_TYPE_ITEM_NUM, NULL,
2625 switch (pattern->type) {
2626 case RTE_FLOW_ITEM_TYPE_MARK:
2627 rc = sfc_mae_rule_preparse_item_mark(pattern->spec,
2630 return rte_flow_error_set(error, rc,
2631 RTE_FLOW_ERROR_TYPE_ITEM,
2632 pattern, "tunnel offload: GROUP: invalid item MARK");
2636 case RTE_FLOW_ITEM_TYPE_VXLAN:
2637 ctx->encap_type = EFX_TUNNEL_PROTOCOL_VXLAN;
2638 ctx->tunnel_def_mask = &rte_flow_item_vxlan_mask;
2639 ctx->tunnel_def_mask_size =
2640 sizeof(rte_flow_item_vxlan_mask);
2642 case RTE_FLOW_ITEM_TYPE_GENEVE:
2643 ctx->encap_type = EFX_TUNNEL_PROTOCOL_GENEVE;
2644 ctx->tunnel_def_mask = &rte_flow_item_geneve_mask;
2645 ctx->tunnel_def_mask_size =
2646 sizeof(rte_flow_item_geneve_mask);
2648 case RTE_FLOW_ITEM_TYPE_NVGRE:
2649 ctx->encap_type = EFX_TUNNEL_PROTOCOL_NVGRE;
2650 ctx->tunnel_def_mask = &rte_flow_item_nvgre_mask;
2651 ctx->tunnel_def_mask_size =
2652 sizeof(rte_flow_item_nvgre_mask);
2654 case RTE_FLOW_ITEM_TYPE_END:
2664 switch (ctx->ft_rule_type) {
2665 case SFC_FT_RULE_NONE:
2666 if (pattern->type == RTE_FLOW_ITEM_TYPE_END)
2669 case SFC_FT_RULE_JUMP:
2670 if (pattern->type != RTE_FLOW_ITEM_TYPE_END) {
2671 return rte_flow_error_set(error, ENOTSUP,
2672 RTE_FLOW_ERROR_TYPE_ITEM,
2673 pattern, "tunnel offload: JUMP: invalid item");
2675 ctx->encap_type = ctx->ft->encap_type;
2677 case SFC_FT_RULE_GROUP:
2678 if (pattern->type == RTE_FLOW_ITEM_TYPE_END) {
2679 return rte_flow_error_set(error, EINVAL,
2680 RTE_FLOW_ERROR_TYPE_ITEM,
2681 NULL, "tunnel offload: GROUP: missing tunnel item");
2682 } else if (ctx->encap_type != ctx->ft->encap_type) {
2683 return rte_flow_error_set(error, EINVAL,
2684 RTE_FLOW_ERROR_TYPE_ITEM,
2685 pattern, "tunnel offload: GROUP: tunnel type mismatch");
2689 * The HW/FW hasn't got support for the use of "ENC" fields in
2690 * action rules (except the VNET_ID one) yet. As a workaround,
2691 * start parsing the pattern from the tunnel item.
2693 ctx->pattern = pattern;
2696 SFC_ASSERT(B_FALSE);
2700 if ((mae->encap_types_supported & (1U << ctx->encap_type)) == 0) {
2701 return rte_flow_error_set(error, ENOTSUP,
2702 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2703 "OR: unsupported tunnel type");
2706 switch (ctx->ft_rule_type) {
2707 case SFC_FT_RULE_JUMP:
2708 recirc_id = SFC_FT_ID_TO_TUNNEL_MARK(ctx->ft->id);
2710 case SFC_FT_RULE_NONE:
2711 if (ctx->priority >= mae->nb_outer_rule_prios_max) {
2712 return rte_flow_error_set(error, ENOTSUP,
2713 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
2714 NULL, "OR: unsupported priority level");
2717 rc = efx_mae_match_spec_init(sa->nic,
2718 EFX_MAE_RULE_OUTER, ctx->priority,
2719 &ctx->match_spec_outer);
2721 return rte_flow_error_set(error, rc,
2722 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2723 "OR: failed to initialise the match specification");
2727 * Outermost items comprise a match
2728 * specification of type OUTER.
2730 ctx->match_spec = ctx->match_spec_outer;
2732 /* Outermost items use "ENC" EFX MAE field IDs. */
2733 ctx->field_ids_remap = field_ids_remap_to_encap;
2735 rc = efx_mae_outer_rule_recirc_id_set(ctx->match_spec,
2738 return rte_flow_error_set(error, rc,
2739 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2740 "OR: failed to initialise RECIRC_ID");
2743 case SFC_FT_RULE_GROUP:
2744 /* Outermost items -> "ENC" match fields in the action rule. */
2745 ctx->field_ids_remap = field_ids_remap_to_encap;
2746 ctx->match_spec = ctx->match_spec_action;
2748 /* No own outer rule; match on JUMP OR's RECIRC_ID is used. */
2749 ctx->encap_type = EFX_TUNNEL_PROTOCOL_NONE;
2752 SFC_ASSERT(B_FALSE);
2760 sfc_mae_rule_encap_parse_fini(struct sfc_adapter *sa,
2761 struct sfc_mae_parse_ctx *ctx)
2763 if (ctx->encap_type == EFX_TUNNEL_PROTOCOL_NONE)
2766 if (ctx->match_spec_outer != NULL)
2767 efx_mae_match_spec_fini(sa->nic, ctx->match_spec_outer);
2771 sfc_mae_rule_parse_pattern(struct sfc_adapter *sa,
2772 const struct rte_flow_item pattern[],
2773 struct sfc_flow_spec_mae *spec,
2774 struct rte_flow_error *error)
2776 struct sfc_mae_parse_ctx ctx_mae;
2777 unsigned int priority_shift = 0;
2778 struct sfc_flow_parse_ctx ctx;
2781 memset(&ctx_mae, 0, sizeof(ctx_mae));
2782 ctx_mae.ft_rule_type = spec->ft_rule_type;
2783 ctx_mae.priority = spec->priority;
2784 ctx_mae.ft = spec->ft;
2787 switch (ctx_mae.ft_rule_type) {
2788 case SFC_FT_RULE_JUMP:
2790 * By design, this flow should be represented solely by the
2791 * outer rule. But the HW/FW hasn't got support for setting
2792 * Rx mark from RECIRC_ID on outer rule lookup yet. Neither
2793 * does it support outer rule counters. As a workaround, an
2794 * action rule of lower priority is used to do the job.
2799 case SFC_FT_RULE_GROUP:
2800 if (ctx_mae.priority != 0) {
2802 * Because of the above workaround, deny the
2803 * use of priorities to JUMP and GROUP rules.
2805 rc = rte_flow_error_set(error, ENOTSUP,
2806 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY, NULL,
2807 "tunnel offload: priorities are not supported");
2808 goto fail_priority_check;
2812 case SFC_FT_RULE_NONE:
2813 rc = efx_mae_match_spec_init(sa->nic, EFX_MAE_RULE_ACTION,
2814 spec->priority + priority_shift,
2815 &ctx_mae.match_spec_action);
2817 rc = rte_flow_error_set(error, rc,
2818 RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2819 "AR: failed to initialise the match specification");
2820 goto fail_init_match_spec_action;
2824 SFC_ASSERT(B_FALSE);
2829 * As a preliminary setting, assume that there is no encapsulation
2830 * in the pattern. That is, pattern items are about to comprise a
2831 * match specification of type ACTION and use non-encap. field IDs.
2833 * sfc_mae_rule_encap_parse_init() below may override this.
2835 ctx_mae.encap_type = EFX_TUNNEL_PROTOCOL_NONE;
2836 ctx_mae.match_spec = ctx_mae.match_spec_action;
2837 ctx_mae.field_ids_remap = field_ids_no_remap;
2838 ctx_mae.pattern = pattern;
2840 ctx.type = SFC_FLOW_PARSE_CTX_MAE;
2843 rc = sfc_mae_rule_encap_parse_init(sa, &ctx_mae, error);
2845 goto fail_encap_parse_init;
2848 * sfc_mae_rule_encap_parse_init() may have detected tunnel offload
2849 * GROUP rule. Remember its properties for later use.
2851 spec->ft_rule_type = ctx_mae.ft_rule_type;
2852 spec->ft = ctx_mae.ft;
2854 rc = sfc_flow_parse_pattern(sa, sfc_flow_items, RTE_DIM(sfc_flow_items),
2855 ctx_mae.pattern, &ctx, error);
2857 goto fail_parse_pattern;
2859 rc = sfc_mae_rule_process_pattern_data(&ctx_mae, error);
2861 goto fail_process_pattern_data;
2863 rc = sfc_mae_rule_process_outer(sa, &ctx_mae, &spec->outer_rule, error);
2865 goto fail_process_outer;
2867 if (ctx_mae.match_spec_action != NULL &&
2868 !efx_mae_match_spec_is_valid(sa->nic, ctx_mae.match_spec_action)) {
2869 rc = rte_flow_error_set(error, ENOTSUP,
2870 RTE_FLOW_ERROR_TYPE_ITEM, NULL,
2871 "Inconsistent pattern");
2872 goto fail_validate_match_spec_action;
2875 spec->match_spec = ctx_mae.match_spec_action;
2879 fail_validate_match_spec_action:
2881 fail_process_pattern_data:
2883 sfc_mae_rule_encap_parse_fini(sa, &ctx_mae);
2885 fail_encap_parse_init:
2886 if (ctx_mae.match_spec_action != NULL)
2887 efx_mae_match_spec_fini(sa->nic, ctx_mae.match_spec_action);
2889 fail_init_match_spec_action:
2890 fail_priority_check:
2895 * An action supported by MAE may correspond to a bundle of RTE flow actions,
2896 * in example, VLAN_PUSH = OF_PUSH_VLAN + OF_VLAN_SET_VID + OF_VLAN_SET_PCP.
2897 * That is, related RTE flow actions need to be tracked as parts of a whole
2898 * so that they can be combined into a single action and submitted to MAE
2899 * representation of a given rule's action set.
2901 * Each RTE flow action provided by an application gets classified as
2902 * one belonging to some bundle type. If an action is not supposed to
2903 * belong to any bundle, or if this action is END, it is described as
2904 * one belonging to a dummy bundle of type EMPTY.
2906 * A currently tracked bundle will be submitted if a repeating
2907 * action or an action of different bundle type follows.
2910 enum sfc_mae_actions_bundle_type {
2911 SFC_MAE_ACTIONS_BUNDLE_EMPTY = 0,
2912 SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH,
2915 struct sfc_mae_actions_bundle {
2916 enum sfc_mae_actions_bundle_type type;
2918 /* Indicates actions already tracked by the current bundle */
2919 uint64_t actions_mask;
2921 /* Parameters used by SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH */
2922 rte_be16_t vlan_push_tpid;
2923 rte_be16_t vlan_push_tci;
2927 * Combine configuration of RTE flow actions tracked by the bundle into a
2928 * single action and submit the result to MAE action set specification.
2929 * Do nothing in the case of dummy action bundle.
2932 sfc_mae_actions_bundle_submit(const struct sfc_mae_actions_bundle *bundle,
2933 efx_mae_actions_t *spec)
2937 switch (bundle->type) {
2938 case SFC_MAE_ACTIONS_BUNDLE_EMPTY:
2940 case SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH:
2941 rc = efx_mae_action_set_populate_vlan_push(
2942 spec, bundle->vlan_push_tpid, bundle->vlan_push_tci);
2945 SFC_ASSERT(B_FALSE);
2953 * Given the type of the next RTE flow action in the line, decide
2954 * whether a new bundle is about to start, and, if this is the case,
2955 * submit and reset the current bundle.
2958 sfc_mae_actions_bundle_sync(const struct rte_flow_action *action,
2959 struct sfc_mae_actions_bundle *bundle,
2960 efx_mae_actions_t *spec,
2961 struct rte_flow_error *error)
2963 enum sfc_mae_actions_bundle_type bundle_type_new;
2966 switch (action->type) {
2967 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
2968 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
2969 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
2970 bundle_type_new = SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH;
2974 * Self-sufficient actions, including END, are handled in this
2975 * case. No checks for unsupported actions are needed here
2976 * because parsing doesn't occur at this point.
2978 bundle_type_new = SFC_MAE_ACTIONS_BUNDLE_EMPTY;
2982 if (bundle_type_new != bundle->type ||
2983 (bundle->actions_mask & (1ULL << action->type)) != 0) {
2984 rc = sfc_mae_actions_bundle_submit(bundle, spec);
2988 memset(bundle, 0, sizeof(*bundle));
2991 bundle->type = bundle_type_new;
2996 return rte_flow_error_set(error, rc,
2997 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2998 "Failed to request the (group of) action(s)");
3002 sfc_mae_rule_parse_action_of_push_vlan(
3003 const struct rte_flow_action_of_push_vlan *conf,
3004 struct sfc_mae_actions_bundle *bundle)
3006 bundle->vlan_push_tpid = conf->ethertype;
3010 sfc_mae_rule_parse_action_of_set_vlan_vid(
3011 const struct rte_flow_action_of_set_vlan_vid *conf,
3012 struct sfc_mae_actions_bundle *bundle)
3014 bundle->vlan_push_tci |= (conf->vlan_vid &
3015 rte_cpu_to_be_16(RTE_LEN2MASK(12, uint16_t)));
3019 sfc_mae_rule_parse_action_of_set_vlan_pcp(
3020 const struct rte_flow_action_of_set_vlan_pcp *conf,
3021 struct sfc_mae_actions_bundle *bundle)
3023 uint16_t vlan_tci_pcp = (uint16_t)(conf->vlan_pcp &
3024 RTE_LEN2MASK(3, uint8_t)) << 13;
3026 bundle->vlan_push_tci |= rte_cpu_to_be_16(vlan_tci_pcp);
3029 struct sfc_mae_parsed_item {
3030 const struct rte_flow_item *item;
3031 size_t proto_header_ofst;
3032 size_t proto_header_size;
3036 * For each 16-bit word of the given header, override
3037 * bits enforced by the corresponding 16-bit mask.
3040 sfc_mae_header_force_item_masks(uint8_t *header_buf,
3041 const struct sfc_mae_parsed_item *parsed_items,
3042 unsigned int nb_parsed_items)
3044 unsigned int item_idx;
3046 for (item_idx = 0; item_idx < nb_parsed_items; ++item_idx) {
3047 const struct sfc_mae_parsed_item *parsed_item;
3048 const struct rte_flow_item *item;
3049 size_t proto_header_size;
3052 parsed_item = &parsed_items[item_idx];
3053 proto_header_size = parsed_item->proto_header_size;
3054 item = parsed_item->item;
3056 for (ofst = 0; ofst < proto_header_size;
3057 ofst += sizeof(rte_be16_t)) {
3058 rte_be16_t *wp = RTE_PTR_ADD(header_buf, ofst);
3059 const rte_be16_t *w_maskp;
3060 const rte_be16_t *w_specp;
3062 w_maskp = RTE_PTR_ADD(item->mask, ofst);
3063 w_specp = RTE_PTR_ADD(item->spec, ofst);
3066 *wp |= (*w_specp & *w_maskp);
3069 header_buf += proto_header_size;
3073 #define SFC_IPV4_TTL_DEF 0x40
3074 #define SFC_IPV6_VTC_FLOW_DEF 0x60000000
3075 #define SFC_IPV6_HOP_LIMITS_DEF 0xff
3076 #define SFC_VXLAN_FLAGS_DEF 0x08000000
3079 sfc_mae_rule_parse_action_vxlan_encap(
3080 struct sfc_mae *mae,
3081 const struct rte_flow_action_vxlan_encap *conf,
3082 efx_mae_actions_t *spec,
3083 struct rte_flow_error *error)
3085 struct sfc_mae_bounce_eh *bounce_eh = &mae->bounce_eh;
3086 struct rte_flow_item *pattern = conf->definition;
3087 uint8_t *buf = bounce_eh->buf;
3089 /* This array will keep track of non-VOID pattern items. */
3090 struct sfc_mae_parsed_item parsed_items[1 /* Ethernet */ +
3092 1 /* IPv4 or IPv6 */ +
3095 unsigned int nb_parsed_items = 0;
3097 size_t eth_ethertype_ofst = offsetof(struct rte_ether_hdr, ether_type);
3098 uint8_t dummy_buf[RTE_MAX(sizeof(struct rte_ipv4_hdr),
3099 sizeof(struct rte_ipv6_hdr))];
3100 struct rte_ipv4_hdr *ipv4 = (void *)dummy_buf;
3101 struct rte_ipv6_hdr *ipv6 = (void *)dummy_buf;
3102 struct rte_vxlan_hdr *vxlan = NULL;
3103 struct rte_udp_hdr *udp = NULL;
3104 unsigned int nb_vlan_tags = 0;
3105 size_t next_proto_ofst = 0;
3106 size_t ethertype_ofst = 0;
3110 if (pattern == NULL) {
3111 return rte_flow_error_set(error, EINVAL,
3112 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3113 "The encap. header definition is NULL");
3116 bounce_eh->type = EFX_TUNNEL_PROTOCOL_VXLAN;
3117 bounce_eh->size = 0;
3120 * Process pattern items and remember non-VOID ones.
3121 * Defer applying masks until after the complete header
3122 * has been built from the pattern items.
3124 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_ETH);
3126 for (; pattern->type != RTE_FLOW_ITEM_TYPE_END; ++pattern) {
3127 struct sfc_mae_parsed_item *parsed_item;
3128 const uint64_t exp_items_extra_vlan[] = {
3129 RTE_BIT64(RTE_FLOW_ITEM_TYPE_VLAN), 0
3131 size_t proto_header_size;
3132 rte_be16_t *ethertypep;
3133 uint8_t *next_protop;
3136 if (pattern->spec == NULL) {
3137 return rte_flow_error_set(error, EINVAL,
3138 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3139 "NULL item spec in the encap. header");
3142 if (pattern->mask == NULL) {
3143 return rte_flow_error_set(error, EINVAL,
3144 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3145 "NULL item mask in the encap. header");
3148 if (pattern->last != NULL) {
3149 /* This is not a match pattern, so disallow range. */
3150 return rte_flow_error_set(error, EINVAL,
3151 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3152 "Range item in the encap. header");
3155 if (pattern->type == RTE_FLOW_ITEM_TYPE_VOID) {
3156 /* Handle VOID separately, for clarity. */
3160 if ((exp_items & RTE_BIT64(pattern->type)) == 0) {
3161 return rte_flow_error_set(error, ENOTSUP,
3162 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3163 "Unexpected item in the encap. header");
3166 parsed_item = &parsed_items[nb_parsed_items];
3167 buf_cur = buf + bounce_eh->size;
3169 switch (pattern->type) {
3170 case RTE_FLOW_ITEM_TYPE_ETH:
3171 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_ETH,
3173 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_eth,
3176 proto_header_size = sizeof(struct rte_ether_hdr);
3178 ethertype_ofst = eth_ethertype_ofst;
3180 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_VLAN) |
3181 RTE_BIT64(RTE_FLOW_ITEM_TYPE_IPV4) |
3182 RTE_BIT64(RTE_FLOW_ITEM_TYPE_IPV6);
3184 case RTE_FLOW_ITEM_TYPE_VLAN:
3185 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_VLAN,
3187 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_vlan,
3190 proto_header_size = sizeof(struct rte_vlan_hdr);
3192 ethertypep = RTE_PTR_ADD(buf, eth_ethertype_ofst);
3193 *ethertypep = RTE_BE16(RTE_ETHER_TYPE_QINQ);
3195 ethertypep = RTE_PTR_ADD(buf, ethertype_ofst);
3196 *ethertypep = RTE_BE16(RTE_ETHER_TYPE_VLAN);
3200 offsetof(struct rte_vlan_hdr, eth_proto);
3202 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_IPV4) |
3203 RTE_BIT64(RTE_FLOW_ITEM_TYPE_IPV6);
3204 exp_items |= exp_items_extra_vlan[nb_vlan_tags];
3208 case RTE_FLOW_ITEM_TYPE_IPV4:
3209 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_IPV4,
3211 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_ipv4,
3214 proto_header_size = sizeof(struct rte_ipv4_hdr);
3216 ethertypep = RTE_PTR_ADD(buf, ethertype_ofst);
3217 *ethertypep = RTE_BE16(RTE_ETHER_TYPE_IPV4);
3221 offsetof(struct rte_ipv4_hdr, next_proto_id);
3223 ipv4 = (struct rte_ipv4_hdr *)buf_cur;
3225 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_UDP);
3227 case RTE_FLOW_ITEM_TYPE_IPV6:
3228 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_IPV6,
3230 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_ipv6,
3233 proto_header_size = sizeof(struct rte_ipv6_hdr);
3235 ethertypep = RTE_PTR_ADD(buf, ethertype_ofst);
3236 *ethertypep = RTE_BE16(RTE_ETHER_TYPE_IPV6);
3238 next_proto_ofst = bounce_eh->size +
3239 offsetof(struct rte_ipv6_hdr, proto);
3241 ipv6 = (struct rte_ipv6_hdr *)buf_cur;
3243 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_UDP);
3245 case RTE_FLOW_ITEM_TYPE_UDP:
3246 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_UDP,
3248 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_udp,
3251 proto_header_size = sizeof(struct rte_udp_hdr);
3253 next_protop = RTE_PTR_ADD(buf, next_proto_ofst);
3254 *next_protop = IPPROTO_UDP;
3256 udp = (struct rte_udp_hdr *)buf_cur;
3258 exp_items = RTE_BIT64(RTE_FLOW_ITEM_TYPE_VXLAN);
3260 case RTE_FLOW_ITEM_TYPE_VXLAN:
3261 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ITEM_TYPE_VXLAN,
3263 RTE_BUILD_BUG_ON(offsetof(struct rte_flow_item_vxlan,
3266 proto_header_size = sizeof(struct rte_vxlan_hdr);
3268 vxlan = (struct rte_vxlan_hdr *)buf_cur;
3270 udp->dst_port = RTE_BE16(RTE_VXLAN_DEFAULT_PORT);
3271 udp->dgram_len = RTE_BE16(sizeof(*udp) +
3273 udp->dgram_cksum = 0;
3278 return rte_flow_error_set(error, ENOTSUP,
3279 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3280 "Unknown item in the encap. header");
3283 if (bounce_eh->size + proto_header_size > bounce_eh->buf_size) {
3284 return rte_flow_error_set(error, E2BIG,
3285 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3286 "The encap. header is too big");
3289 if ((proto_header_size & 1) != 0) {
3290 return rte_flow_error_set(error, EINVAL,
3291 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3292 "Odd layer size in the encap. header");
3295 rte_memcpy(buf_cur, pattern->spec, proto_header_size);
3296 bounce_eh->size += proto_header_size;
3298 parsed_item->item = pattern;
3299 parsed_item->proto_header_size = proto_header_size;
3303 if (exp_items != 0) {
3304 /* Parsing item VXLAN would have reset exp_items to 0. */
3305 return rte_flow_error_set(error, ENOTSUP,
3306 RTE_FLOW_ERROR_TYPE_ACTION_CONF, NULL,
3307 "No item VXLAN in the encap. header");
3310 /* One of the pointers (ipv4, ipv6) refers to a dummy area. */
3311 ipv4->version_ihl = RTE_IPV4_VHL_DEF;
3312 ipv4->time_to_live = SFC_IPV4_TTL_DEF;
3313 ipv4->total_length = RTE_BE16(sizeof(*ipv4) + sizeof(*udp) +
3315 /* The HW cannot compute this checksum. */
3316 ipv4->hdr_checksum = 0;
3317 ipv4->hdr_checksum = rte_ipv4_cksum(ipv4);
3319 ipv6->vtc_flow = RTE_BE32(SFC_IPV6_VTC_FLOW_DEF);
3320 ipv6->hop_limits = SFC_IPV6_HOP_LIMITS_DEF;
3321 ipv6->payload_len = udp->dgram_len;
3323 vxlan->vx_flags = RTE_BE32(SFC_VXLAN_FLAGS_DEF);
3325 /* Take care of the masks. */
3326 sfc_mae_header_force_item_masks(buf, parsed_items, nb_parsed_items);
3328 rc = efx_mae_action_set_populate_encap(spec);
3330 rc = rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ACTION,
3331 NULL, "failed to request action ENCAP");
3338 sfc_mae_rule_parse_action_mark(struct sfc_adapter *sa,
3339 const struct rte_flow_action_mark *conf,
3340 const struct sfc_flow_spec_mae *spec_mae,
3341 efx_mae_actions_t *spec)
3345 if (spec_mae->ft_rule_type == SFC_FT_RULE_JUMP) {
3346 /* Workaround. See sfc_flow_parse_rte_to_mae() */
3347 } else if (conf->id > SFC_FT_USER_MARK_MASK) {
3348 sfc_err(sa, "the mark value is too large");
3352 rc = efx_mae_action_set_populate_mark(spec, conf->id);
3354 sfc_err(sa, "failed to request action MARK: %s", strerror(rc));
3360 sfc_mae_rule_parse_action_count(struct sfc_adapter *sa,
3361 const struct rte_flow_action_count *conf
3363 efx_mae_actions_t *spec)
3367 if ((sa->counter_rxq.state & SFC_COUNTER_RXQ_INITIALIZED) == 0) {
3369 "counter queue is not configured for COUNT action");
3371 goto fail_counter_queue_uninit;
3374 if (sfc_get_service_lcore(SOCKET_ID_ANY) == RTE_MAX_LCORE) {
3376 goto fail_no_service_core;
3379 rc = efx_mae_action_set_populate_count(spec);
3382 "failed to populate counters in MAE action set: %s",
3384 goto fail_populate_count;
3389 fail_populate_count:
3390 fail_no_service_core:
3391 fail_counter_queue_uninit:
3397 sfc_mae_rule_parse_action_phy_port(struct sfc_adapter *sa,
3398 const struct rte_flow_action_phy_port *conf,
3399 efx_mae_actions_t *spec)
3401 efx_mport_sel_t mport;
3405 if (conf->original != 0)
3406 phy_port = efx_nic_cfg_get(sa->nic)->enc_assigned_port;
3408 phy_port = conf->index;
3410 rc = efx_mae_mport_by_phy_port(phy_port, &mport);
3412 sfc_err(sa, "failed to convert phys. port ID %u to m-port selector: %s",
3413 phy_port, strerror(rc));
3417 rc = efx_mae_action_set_populate_deliver(spec, &mport);
3419 sfc_err(sa, "failed to request action DELIVER with m-port selector 0x%08x: %s",
3420 mport.sel, strerror(rc));
3427 sfc_mae_rule_parse_action_pf_vf(struct sfc_adapter *sa,
3428 const struct rte_flow_action_vf *vf_conf,
3429 efx_mae_actions_t *spec)
3431 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
3432 efx_mport_sel_t mport;
3436 if (vf_conf == NULL)
3437 vf = EFX_PCI_VF_INVALID;
3438 else if (vf_conf->original != 0)
3443 rc = efx_mae_mport_by_pcie_function(encp->enc_pf, vf, &mport);
3445 sfc_err(sa, "failed to convert PF %u VF %d to m-port: %s",
3446 encp->enc_pf, (vf != EFX_PCI_VF_INVALID) ? (int)vf : -1,
3451 rc = efx_mae_action_set_populate_deliver(spec, &mport);
3453 sfc_err(sa, "failed to request action DELIVER with m-port selector 0x%08x: %s",
3454 mport.sel, strerror(rc));
3461 sfc_mae_rule_parse_action_port_id(struct sfc_adapter *sa,
3462 const struct rte_flow_action_port_id *conf,
3463 efx_mae_actions_t *spec)
3465 struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
3466 struct sfc_mae *mae = &sa->mae;
3467 efx_mport_sel_t mport;
3471 if (conf->id > UINT16_MAX)
3474 port_id = (conf->original != 0) ? sas->port_id : conf->id;
3476 rc = sfc_mae_switch_get_ethdev_mport(mae->switch_domain_id,
3479 sfc_err(sa, "failed to get m-port for the given ethdev (port_id=%u): %s",
3480 port_id, strerror(rc));
3484 rc = efx_mae_action_set_populate_deliver(spec, &mport);
3486 sfc_err(sa, "failed to request action DELIVER with m-port selector 0x%08x: %s",
3487 mport.sel, strerror(rc));
3494 sfc_mae_rule_parse_action_port_representor(struct sfc_adapter *sa,
3495 const struct rte_flow_action_ethdev *conf,
3496 efx_mae_actions_t *spec)
3498 struct sfc_mae *mae = &sa->mae;
3499 efx_mport_sel_t mport;
3502 rc = sfc_mae_switch_get_ethdev_mport(mae->switch_domain_id,
3503 conf->port_id, &mport);
3505 sfc_err(sa, "failed to get m-port for the given ethdev (port_id=%u): %s",
3506 conf->port_id, strerror(rc));
3510 rc = efx_mae_action_set_populate_deliver(spec, &mport);
3512 sfc_err(sa, "failed to request action DELIVER with m-port selector 0x%08x: %s",
3513 mport.sel, strerror(rc));
3520 sfc_mae_rule_parse_action_represented_port(struct sfc_adapter *sa,
3521 const struct rte_flow_action_ethdev *conf,
3522 efx_mae_actions_t *spec)
3524 struct sfc_mae *mae = &sa->mae;
3525 efx_mport_sel_t mport;
3528 rc = sfc_mae_switch_get_entity_mport(mae->switch_domain_id,
3529 conf->port_id, &mport);
3531 sfc_err(sa, "failed to get m-port for the given ethdev (port_id=%u): %s",
3532 conf->port_id, strerror(rc));
3536 rc = efx_mae_action_set_populate_deliver(spec, &mport);
3538 sfc_err(sa, "failed to request action DELIVER with m-port selector 0x%08x: %s",
3539 mport.sel, strerror(rc));
3545 static const char * const action_names[] = {
3546 [RTE_FLOW_ACTION_TYPE_VXLAN_DECAP] = "VXLAN_DECAP",
3547 [RTE_FLOW_ACTION_TYPE_OF_POP_VLAN] = "OF_POP_VLAN",
3548 [RTE_FLOW_ACTION_TYPE_OF_DEC_NW_TTL] = "OF_DEC_NW_TTL",
3549 [RTE_FLOW_ACTION_TYPE_DEC_TTL] = "DEC_TTL",
3550 [RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN] = "OF_PUSH_VLAN",
3551 [RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID] = "OF_SET_VLAN_VID",
3552 [RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP] = "OF_SET_VLAN_PCP",
3553 [RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP] = "VXLAN_ENCAP",
3554 [RTE_FLOW_ACTION_TYPE_COUNT] = "COUNT",
3555 [RTE_FLOW_ACTION_TYPE_FLAG] = "FLAG",
3556 [RTE_FLOW_ACTION_TYPE_MARK] = "MARK",
3557 [RTE_FLOW_ACTION_TYPE_PHY_PORT] = "PHY_PORT",
3558 [RTE_FLOW_ACTION_TYPE_PF] = "PF",
3559 [RTE_FLOW_ACTION_TYPE_VF] = "VF",
3560 [RTE_FLOW_ACTION_TYPE_PORT_ID] = "PORT_ID",
3561 [RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR] = "PORT_REPRESENTOR",
3562 [RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT] = "REPRESENTED_PORT",
3563 [RTE_FLOW_ACTION_TYPE_DROP] = "DROP",
3564 [RTE_FLOW_ACTION_TYPE_JUMP] = "JUMP",
3568 sfc_mae_rule_parse_action(struct sfc_adapter *sa,
3569 const struct rte_flow_action *action,
3570 const struct sfc_flow_spec_mae *spec_mae,
3571 struct sfc_mae_actions_bundle *bundle,
3572 efx_mae_actions_t *spec,
3573 struct rte_flow_error *error)
3575 const struct sfc_mae_outer_rule *outer_rule = spec_mae->outer_rule;
3576 const uint64_t rx_metadata = sa->negotiated_rx_metadata;
3577 bool custom_error = B_FALSE;
3580 switch (action->type) {
3581 case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
3582 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VXLAN_DECAP,
3583 bundle->actions_mask);
3584 if (outer_rule == NULL ||
3585 outer_rule->encap_type != EFX_TUNNEL_PROTOCOL_VXLAN)
3588 rc = efx_mae_action_set_populate_decap(spec);
3590 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
3591 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_POP_VLAN,
3592 bundle->actions_mask);
3593 rc = efx_mae_action_set_populate_vlan_pop(spec);
3595 case RTE_FLOW_ACTION_TYPE_OF_DEC_NW_TTL:
3596 case RTE_FLOW_ACTION_TYPE_DEC_TTL:
3597 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_DEC_NW_TTL,
3598 bundle->actions_mask);
3599 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_DEC_TTL,
3600 bundle->actions_mask);
3601 rc = efx_mae_action_set_populate_decr_ip_ttl(spec);
3603 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
3604 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN,
3605 bundle->actions_mask);
3606 sfc_mae_rule_parse_action_of_push_vlan(action->conf, bundle);
3608 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
3609 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID,
3610 bundle->actions_mask);
3611 sfc_mae_rule_parse_action_of_set_vlan_vid(action->conf, bundle);
3613 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
3614 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP,
3615 bundle->actions_mask);
3616 sfc_mae_rule_parse_action_of_set_vlan_pcp(action->conf, bundle);
3618 case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
3619 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP,
3620 bundle->actions_mask);
3621 rc = sfc_mae_rule_parse_action_vxlan_encap(&sa->mae,
3624 custom_error = B_TRUE;
3626 case RTE_FLOW_ACTION_TYPE_COUNT:
3627 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_COUNT,
3628 bundle->actions_mask);
3629 rc = sfc_mae_rule_parse_action_count(sa, action->conf, spec);
3631 case RTE_FLOW_ACTION_TYPE_FLAG:
3632 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_FLAG,
3633 bundle->actions_mask);
3634 if ((rx_metadata & RTE_ETH_RX_METADATA_USER_FLAG) != 0) {
3635 rc = efx_mae_action_set_populate_flag(spec);
3637 rc = rte_flow_error_set(error, ENOTSUP,
3638 RTE_FLOW_ERROR_TYPE_ACTION,
3640 "flag delivery has not been negotiated");
3641 custom_error = B_TRUE;
3644 case RTE_FLOW_ACTION_TYPE_MARK:
3645 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_MARK,
3646 bundle->actions_mask);
3647 if ((rx_metadata & RTE_ETH_RX_METADATA_USER_MARK) != 0 ||
3648 spec_mae->ft_rule_type == SFC_FT_RULE_JUMP) {
3649 rc = sfc_mae_rule_parse_action_mark(sa, action->conf,
3652 rc = rte_flow_error_set(error, ENOTSUP,
3653 RTE_FLOW_ERROR_TYPE_ACTION,
3655 "mark delivery has not been negotiated");
3656 custom_error = B_TRUE;
3659 case RTE_FLOW_ACTION_TYPE_PHY_PORT:
3660 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_PHY_PORT,
3661 bundle->actions_mask);
3662 rc = sfc_mae_rule_parse_action_phy_port(sa, action->conf, spec);
3664 case RTE_FLOW_ACTION_TYPE_PF:
3665 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_PF,
3666 bundle->actions_mask);
3667 rc = sfc_mae_rule_parse_action_pf_vf(sa, NULL, spec);
3669 case RTE_FLOW_ACTION_TYPE_VF:
3670 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VF,
3671 bundle->actions_mask);
3672 rc = sfc_mae_rule_parse_action_pf_vf(sa, action->conf, spec);
3674 case RTE_FLOW_ACTION_TYPE_PORT_ID:
3675 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_PORT_ID,
3676 bundle->actions_mask);
3677 rc = sfc_mae_rule_parse_action_port_id(sa, action->conf, spec);
3679 case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
3680 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR,
3681 bundle->actions_mask);
3682 rc = sfc_mae_rule_parse_action_port_representor(sa,
3683 action->conf, spec);
3685 case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
3686 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT,
3687 bundle->actions_mask);
3688 rc = sfc_mae_rule_parse_action_represented_port(sa,
3689 action->conf, spec);
3691 case RTE_FLOW_ACTION_TYPE_DROP:
3692 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_DROP,
3693 bundle->actions_mask);
3694 rc = efx_mae_action_set_populate_drop(spec);
3696 case RTE_FLOW_ACTION_TYPE_JUMP:
3697 if (spec_mae->ft_rule_type == SFC_FT_RULE_JUMP) {
3698 /* Workaround. See sfc_flow_parse_rte_to_mae() */
3703 return rte_flow_error_set(error, ENOTSUP,
3704 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
3705 "Unsupported action");
3709 bundle->actions_mask |= (1ULL << action->type);
3710 } else if (!custom_error) {
3711 if (action->type < RTE_DIM(action_names)) {
3712 const char *action_name = action_names[action->type];
3714 if (action_name != NULL) {
3715 sfc_err(sa, "action %s was rejected: %s",
3716 action_name, strerror(rc));
3719 rc = rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ACTION,
3720 NULL, "Failed to request the action");
3727 sfc_mae_bounce_eh_invalidate(struct sfc_mae_bounce_eh *bounce_eh)
3729 bounce_eh->type = EFX_TUNNEL_PROTOCOL_NONE;
3733 sfc_mae_process_encap_header(struct sfc_adapter *sa,
3734 const struct sfc_mae_bounce_eh *bounce_eh,
3735 struct sfc_mae_encap_header **encap_headerp)
3737 if (bounce_eh->type == EFX_TUNNEL_PROTOCOL_NONE) {
3738 encap_headerp = NULL;
3742 *encap_headerp = sfc_mae_encap_header_attach(sa, bounce_eh);
3743 if (*encap_headerp != NULL)
3746 return sfc_mae_encap_header_add(sa, bounce_eh, encap_headerp);
3750 sfc_mae_rule_parse_actions(struct sfc_adapter *sa,
3751 const struct rte_flow_action actions[],
3752 struct sfc_flow_spec_mae *spec_mae,
3753 struct rte_flow_error *error)
3755 struct sfc_mae_encap_header *encap_header = NULL;
3756 struct sfc_mae_actions_bundle bundle = {0};
3757 struct sfc_flow_tunnel *counter_ft = NULL;
3758 uint64_t *ft_group_hit_counter = NULL;
3759 const struct rte_flow_action *action;
3760 struct sfc_mae *mae = &sa->mae;
3761 unsigned int n_count = 0;
3762 efx_mae_actions_t *spec;
3767 if (actions == NULL) {
3768 return rte_flow_error_set(error, EINVAL,
3769 RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
3773 rc = efx_mae_action_set_spec_init(sa->nic, &spec);
3775 goto fail_action_set_spec_init;
3777 for (action = actions;
3778 action->type != RTE_FLOW_ACTION_TYPE_END; ++action) {
3779 if (action->type == RTE_FLOW_ACTION_TYPE_COUNT)
3783 if (spec_mae->ft_rule_type == SFC_FT_RULE_GROUP) {
3784 /* JUMP rules don't decapsulate packets. GROUP rules do. */
3785 rc = efx_mae_action_set_populate_decap(spec);
3787 goto fail_enforce_ft_decap;
3789 if (n_count == 0 && sfc_mae_counter_stream_enabled(sa)) {
3791 * The user opted not to use action COUNT in this rule,
3792 * but the counter should be enabled implicitly because
3793 * packets hitting this rule contribute to the tunnel's
3794 * total number of hits. See sfc_mae_counter_get().
3796 rc = efx_mae_action_set_populate_count(spec);
3798 goto fail_enforce_ft_count;
3804 /* Cleanup after previous encap. header bounce buffer usage. */
3805 sfc_mae_bounce_eh_invalidate(&mae->bounce_eh);
3807 for (action = actions;
3808 action->type != RTE_FLOW_ACTION_TYPE_END; ++action) {
3809 rc = sfc_mae_actions_bundle_sync(action, &bundle, spec, error);
3811 goto fail_rule_parse_action;
3813 rc = sfc_mae_rule_parse_action(sa, action, spec_mae,
3814 &bundle, spec, error);
3816 goto fail_rule_parse_action;
3819 rc = sfc_mae_actions_bundle_sync(action, &bundle, spec, error);
3821 goto fail_rule_parse_action;
3823 rc = sfc_mae_process_encap_header(sa, &mae->bounce_eh, &encap_header);
3825 goto fail_process_encap_header;
3829 sfc_err(sa, "too many count actions requested: %u", n_count);
3833 switch (spec_mae->ft_rule_type) {
3834 case SFC_FT_RULE_NONE:
3836 case SFC_FT_RULE_JUMP:
3837 /* Workaround. See sfc_flow_parse_rte_to_mae() */
3838 rc = sfc_mae_rule_parse_action_pf_vf(sa, NULL, spec);
3840 goto fail_workaround_jump_delivery;
3842 counter_ft = spec_mae->ft;
3844 case SFC_FT_RULE_GROUP:
3846 * Packets that go to the rule's AR have FT mark set (from the
3847 * JUMP rule OR's RECIRC_ID). Remove this mark in matching
3848 * packets. The user may have provided their own action
3849 * MARK above, so don't check the return value here.
3851 (void)efx_mae_action_set_populate_mark(spec, 0);
3853 ft_group_hit_counter = &spec_mae->ft->group_hit_counter;
3856 SFC_ASSERT(B_FALSE);
3859 spec_mae->action_set = sfc_mae_action_set_attach(sa, encap_header,
3861 if (spec_mae->action_set != NULL) {
3862 sfc_mae_encap_header_del(sa, encap_header);
3863 efx_mae_action_set_spec_fini(sa->nic, spec);
3867 rc = sfc_mae_action_set_add(sa, actions, spec, encap_header,
3868 ft_group_hit_counter, counter_ft, n_count,
3869 &spec_mae->action_set);
3871 goto fail_action_set_add;
3875 fail_action_set_add:
3876 fail_workaround_jump_delivery:
3878 sfc_mae_encap_header_del(sa, encap_header);
3880 fail_process_encap_header:
3881 fail_rule_parse_action:
3882 efx_mae_action_set_spec_fini(sa->nic, spec);
3884 fail_enforce_ft_count:
3885 fail_enforce_ft_decap:
3886 fail_action_set_spec_init:
3887 if (rc > 0 && rte_errno == 0) {
3888 rc = rte_flow_error_set(error, rc,
3889 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
3890 NULL, "Failed to process the action");
3896 sfc_mae_rules_class_cmp(struct sfc_adapter *sa,
3897 const efx_mae_match_spec_t *left,
3898 const efx_mae_match_spec_t *right)
3900 bool have_same_class;
3903 rc = efx_mae_match_specs_class_cmp(sa->nic, left, right,
3906 return (rc == 0) ? have_same_class : false;
3910 sfc_mae_outer_rule_class_verify(struct sfc_adapter *sa,
3911 struct sfc_mae_outer_rule *rule)
3913 struct sfc_mae_fw_rsrc *fw_rsrc = &rule->fw_rsrc;
3914 struct sfc_mae_outer_rule *entry;
3915 struct sfc_mae *mae = &sa->mae;
3917 if (fw_rsrc->rule_id.id != EFX_MAE_RSRC_ID_INVALID) {
3918 /* An active rule is reused. It's class is wittingly valid. */
3922 TAILQ_FOREACH_REVERSE(entry, &mae->outer_rules,
3923 sfc_mae_outer_rules, entries) {
3924 const efx_mae_match_spec_t *left = entry->match_spec;
3925 const efx_mae_match_spec_t *right = rule->match_spec;
3930 if (sfc_mae_rules_class_cmp(sa, left, right))
3934 sfc_info(sa, "for now, the HW doesn't support rule validation, and HW "
3935 "support for outer frame pattern items is not guaranteed; "
3936 "other than that, the items are valid from SW standpoint");
3941 sfc_mae_action_rule_class_verify(struct sfc_adapter *sa,
3942 struct sfc_flow_spec_mae *spec)
3944 const struct rte_flow *entry;
3946 if (spec->match_spec == NULL)
3949 TAILQ_FOREACH_REVERSE(entry, &sa->flow_list, sfc_flow_list, entries) {
3950 const struct sfc_flow_spec *entry_spec = &entry->spec;
3951 const struct sfc_flow_spec_mae *es_mae = &entry_spec->mae;
3952 const efx_mae_match_spec_t *left = es_mae->match_spec;
3953 const efx_mae_match_spec_t *right = spec->match_spec;
3955 switch (entry_spec->type) {
3956 case SFC_FLOW_SPEC_FILTER:
3957 /* Ignore VNIC-level flows */
3959 case SFC_FLOW_SPEC_MAE:
3960 if (sfc_mae_rules_class_cmp(sa, left, right))
3968 sfc_info(sa, "for now, the HW doesn't support rule validation, and HW "
3969 "support for inner frame pattern items is not guaranteed; "
3970 "other than that, the items are valid from SW standpoint");
3975 * Confirm that a given flow can be accepted by the FW.
3978 * Software adapter context
3980 * Flow to be verified
3982 * Zero on success and non-zero in the case of error.
3983 * A special value of EAGAIN indicates that the adapter is
3984 * not in started state. This state is compulsory because
3985 * it only makes sense to compare the rule class of the flow
3986 * being validated with classes of the active rules.
3987 * Such classes are wittingly supported by the FW.
3990 sfc_mae_flow_verify(struct sfc_adapter *sa,
3991 struct rte_flow *flow)
3993 struct sfc_flow_spec *spec = &flow->spec;
3994 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
3995 struct sfc_mae_outer_rule *outer_rule = spec_mae->outer_rule;
3998 SFC_ASSERT(sfc_adapter_is_locked(sa));
4000 if (sa->state != SFC_ETHDEV_STARTED)
4003 if (outer_rule != NULL) {
4004 rc = sfc_mae_outer_rule_class_verify(sa, outer_rule);
4009 return sfc_mae_action_rule_class_verify(sa, spec_mae);
4013 sfc_mae_flow_insert(struct sfc_adapter *sa,
4014 struct rte_flow *flow)
4016 struct sfc_flow_spec *spec = &flow->spec;
4017 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
4018 struct sfc_mae_outer_rule *outer_rule = spec_mae->outer_rule;
4019 struct sfc_mae_action_set *action_set = spec_mae->action_set;
4020 struct sfc_mae_fw_rsrc *fw_rsrc;
4023 SFC_ASSERT(spec_mae->rule_id.id == EFX_MAE_RSRC_ID_INVALID);
4025 if (outer_rule != NULL) {
4026 rc = sfc_mae_outer_rule_enable(sa, outer_rule,
4027 spec_mae->match_spec);
4029 goto fail_outer_rule_enable;
4032 if (spec_mae->ft_rule_type == SFC_FT_RULE_JUMP) {
4033 spec_mae->ft->reset_jump_hit_counter =
4034 spec_mae->ft->group_hit_counter;
4037 if (action_set == NULL) {
4038 sfc_dbg(sa, "enabled flow=%p (no AR)", flow);
4042 rc = sfc_mae_action_set_enable(sa, action_set);
4044 goto fail_action_set_enable;
4046 if (action_set->n_counters > 0) {
4047 rc = sfc_mae_counter_start(sa);
4049 sfc_err(sa, "failed to start MAE counters support: %s",
4051 goto fail_mae_counter_start;
4055 fw_rsrc = &action_set->fw_rsrc;
4057 rc = efx_mae_action_rule_insert(sa->nic, spec_mae->match_spec,
4058 NULL, &fw_rsrc->aset_id,
4059 &spec_mae->rule_id);
4061 goto fail_action_rule_insert;
4063 sfc_dbg(sa, "enabled flow=%p: AR_ID=0x%08x",
4064 flow, spec_mae->rule_id.id);
4068 fail_action_rule_insert:
4069 fail_mae_counter_start:
4070 sfc_mae_action_set_disable(sa, action_set);
4072 fail_action_set_enable:
4073 if (outer_rule != NULL)
4074 sfc_mae_outer_rule_disable(sa, outer_rule);
4076 fail_outer_rule_enable:
4081 sfc_mae_flow_remove(struct sfc_adapter *sa,
4082 struct rte_flow *flow)
4084 struct sfc_flow_spec *spec = &flow->spec;
4085 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
4086 struct sfc_mae_action_set *action_set = spec_mae->action_set;
4087 struct sfc_mae_outer_rule *outer_rule = spec_mae->outer_rule;
4090 if (action_set == NULL) {
4091 sfc_dbg(sa, "disabled flow=%p (no AR)", flow);
4092 goto skip_action_rule;
4095 SFC_ASSERT(spec_mae->rule_id.id != EFX_MAE_RSRC_ID_INVALID);
4097 rc = efx_mae_action_rule_remove(sa->nic, &spec_mae->rule_id);
4099 sfc_err(sa, "failed to disable flow=%p with AR_ID=0x%08x: %s",
4100 flow, spec_mae->rule_id.id, strerror(rc));
4102 sfc_dbg(sa, "disabled flow=%p with AR_ID=0x%08x",
4103 flow, spec_mae->rule_id.id);
4104 spec_mae->rule_id.id = EFX_MAE_RSRC_ID_INVALID;
4106 sfc_mae_action_set_disable(sa, action_set);
4109 if (outer_rule != NULL)
4110 sfc_mae_outer_rule_disable(sa, outer_rule);
4116 sfc_mae_query_counter(struct sfc_adapter *sa,
4117 struct sfc_flow_spec_mae *spec,
4118 const struct rte_flow_action *action,
4119 struct rte_flow_query_count *data,
4120 struct rte_flow_error *error)
4122 struct sfc_mae_action_set *action_set = spec->action_set;
4123 const struct rte_flow_action_count *conf = action->conf;
4127 if (action_set == NULL || action_set->n_counters == 0) {
4128 return rte_flow_error_set(error, EINVAL,
4129 RTE_FLOW_ERROR_TYPE_ACTION, action,
4130 "Queried flow rule does not have count actions");
4133 for (i = 0; i < action_set->n_counters; i++) {
4135 * Get the first available counter of the flow rule if
4136 * counter ID is not specified, provided that this
4137 * counter is not an automatic (implicit) one.
4139 if (conf != NULL && action_set->counters[i].rte_id != conf->id)
4142 rc = sfc_mae_counter_get(&sa->mae.counter_registry.counters,
4143 &action_set->counters[i], data);
4145 return rte_flow_error_set(error, EINVAL,
4146 RTE_FLOW_ERROR_TYPE_ACTION, action,
4147 "Queried flow rule counter action is invalid");
4153 return rte_flow_error_set(error, ENOENT,
4154 RTE_FLOW_ERROR_TYPE_ACTION, action,
4155 "no such flow rule action or such count ID");
4159 sfc_mae_flow_query(struct rte_eth_dev *dev,
4160 struct rte_flow *flow,
4161 const struct rte_flow_action *action,
4163 struct rte_flow_error *error)
4165 struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
4166 struct sfc_flow_spec *spec = &flow->spec;
4167 struct sfc_flow_spec_mae *spec_mae = &spec->mae;
4169 switch (action->type) {
4170 case RTE_FLOW_ACTION_TYPE_COUNT:
4171 return sfc_mae_query_counter(sa, spec_mae, action,
4174 return rte_flow_error_set(error, ENOTSUP,
4175 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
4176 "Query for action of this type is not supported");
4181 sfc_mae_switchdev_init(struct sfc_adapter *sa)
4183 const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
4184 struct sfc_mae *mae = &sa->mae;
4186 efx_mport_sel_t phy;
4189 sfc_log_init(sa, "entry");
4191 if (!sa->switchdev) {
4192 sfc_log_init(sa, "switchdev is not enabled - skip");
4196 if (mae->status != SFC_MAE_STATUS_ADMIN) {
4198 sfc_err(sa, "failed to init switchdev - no admin MAE privilege");
4202 rc = efx_mae_mport_by_pcie_function(encp->enc_pf, EFX_PCI_VF_INVALID,
4205 sfc_err(sa, "failed get PF mport");
4209 rc = efx_mae_mport_by_phy_port(encp->enc_assigned_port, &phy);
4211 sfc_err(sa, "failed get PHY mport");
4215 rc = sfc_mae_rule_add_mport_match_deliver(sa, &pf, &phy,
4216 SFC_MAE_RULE_PRIO_LOWEST,
4217 &mae->switchdev_rule_pf_to_ext);
4219 sfc_err(sa, "failed add MAE rule to forward from PF to PHY");
4223 rc = sfc_mae_rule_add_mport_match_deliver(sa, &phy, &pf,
4224 SFC_MAE_RULE_PRIO_LOWEST,
4225 &mae->switchdev_rule_ext_to_pf);
4227 sfc_err(sa, "failed add MAE rule to forward from PHY to PF");
4231 sfc_log_init(sa, "done");
4236 sfc_mae_rule_del(sa, mae->switchdev_rule_pf_to_ext);
4242 sfc_log_init(sa, "failed: %s", rte_strerror(rc));
4247 sfc_mae_switchdev_fini(struct sfc_adapter *sa)
4249 struct sfc_mae *mae = &sa->mae;
4254 sfc_mae_rule_del(sa, mae->switchdev_rule_pf_to_ext);
4255 sfc_mae_rule_del(sa, mae->switchdev_rule_ext_to_pf);