net/sfc: support flow item UDP in transfer rules
[dpdk.git] / drivers / net / sfc / sfc_mae.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2019-2020 Xilinx, Inc.
4  * Copyright(c) 2019 Solarflare Communications Inc.
5  *
6  * This software was jointly developed between OKTET Labs (under contract
7  * for Solarflare) and Solarflare Communications, Inc.
8  */
9
10 #include <stdbool.h>
11
12 #include <rte_common.h>
13
14 #include "efx.h"
15
16 #include "sfc.h"
17 #include "sfc_log.h"
18 #include "sfc_switch.h"
19
20 static int
21 sfc_mae_assign_entity_mport(struct sfc_adapter *sa,
22                             efx_mport_sel_t *mportp)
23 {
24         const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
25
26         return efx_mae_mport_by_pcie_function(encp->enc_pf, encp->enc_vf,
27                                               mportp);
28 }
29
30 int
31 sfc_mae_attach(struct sfc_adapter *sa)
32 {
33         struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
34         struct sfc_mae_switch_port_request switch_port_request = {0};
35         const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
36         efx_mport_sel_t entity_mport;
37         struct sfc_mae *mae = &sa->mae;
38         efx_mae_limits_t limits;
39         int rc;
40
41         sfc_log_init(sa, "entry");
42
43         if (!encp->enc_mae_supported) {
44                 mae->status = SFC_MAE_STATUS_UNSUPPORTED;
45                 return 0;
46         }
47
48         sfc_log_init(sa, "init MAE");
49         rc = efx_mae_init(sa->nic);
50         if (rc != 0)
51                 goto fail_mae_init;
52
53         sfc_log_init(sa, "get MAE limits");
54         rc = efx_mae_get_limits(sa->nic, &limits);
55         if (rc != 0)
56                 goto fail_mae_get_limits;
57
58         sfc_log_init(sa, "assign entity MPORT");
59         rc = sfc_mae_assign_entity_mport(sa, &entity_mport);
60         if (rc != 0)
61                 goto fail_mae_assign_entity_mport;
62
63         sfc_log_init(sa, "assign RTE switch domain");
64         rc = sfc_mae_assign_switch_domain(sa, &mae->switch_domain_id);
65         if (rc != 0)
66                 goto fail_mae_assign_switch_domain;
67
68         sfc_log_init(sa, "assign RTE switch port");
69         switch_port_request.type = SFC_MAE_SWITCH_PORT_INDEPENDENT;
70         switch_port_request.entity_mportp = &entity_mport;
71         /*
72          * As of now, the driver does not support representors, so
73          * RTE ethdev MPORT simply matches that of the entity.
74          */
75         switch_port_request.ethdev_mportp = &entity_mport;
76         switch_port_request.ethdev_port_id = sas->port_id;
77         rc = sfc_mae_assign_switch_port(mae->switch_domain_id,
78                                         &switch_port_request,
79                                         &mae->switch_port_id);
80         if (rc != 0)
81                 goto fail_mae_assign_switch_port;
82
83         mae->status = SFC_MAE_STATUS_SUPPORTED;
84         mae->nb_action_rule_prios_max = limits.eml_max_n_action_prios;
85         TAILQ_INIT(&mae->action_sets);
86
87         sfc_log_init(sa, "done");
88
89         return 0;
90
91 fail_mae_assign_switch_port:
92 fail_mae_assign_switch_domain:
93 fail_mae_assign_entity_mport:
94 fail_mae_get_limits:
95         efx_mae_fini(sa->nic);
96
97 fail_mae_init:
98         sfc_log_init(sa, "failed %d", rc);
99
100         return rc;
101 }
102
103 void
104 sfc_mae_detach(struct sfc_adapter *sa)
105 {
106         struct sfc_mae *mae = &sa->mae;
107         enum sfc_mae_status status_prev = mae->status;
108
109         sfc_log_init(sa, "entry");
110
111         mae->nb_action_rule_prios_max = 0;
112         mae->status = SFC_MAE_STATUS_UNKNOWN;
113
114         if (status_prev != SFC_MAE_STATUS_SUPPORTED)
115                 return;
116
117         efx_mae_fini(sa->nic);
118
119         sfc_log_init(sa, "done");
120 }
121
122 static struct sfc_mae_action_set *
123 sfc_mae_action_set_attach(struct sfc_adapter *sa,
124                           const efx_mae_actions_t *spec)
125 {
126         struct sfc_mae_action_set *action_set;
127         struct sfc_mae *mae = &sa->mae;
128
129         SFC_ASSERT(sfc_adapter_is_locked(sa));
130
131         TAILQ_FOREACH(action_set, &mae->action_sets, entries) {
132                 if (efx_mae_action_set_specs_equal(action_set->spec, spec)) {
133                         ++(action_set->refcnt);
134                         return action_set;
135                 }
136         }
137
138         return NULL;
139 }
140
141 static int
142 sfc_mae_action_set_add(struct sfc_adapter *sa,
143                        efx_mae_actions_t *spec,
144                        struct sfc_mae_action_set **action_setp)
145 {
146         struct sfc_mae_action_set *action_set;
147         struct sfc_mae *mae = &sa->mae;
148
149         SFC_ASSERT(sfc_adapter_is_locked(sa));
150
151         action_set = rte_zmalloc("sfc_mae_action_set", sizeof(*action_set), 0);
152         if (action_set == NULL)
153                 return ENOMEM;
154
155         action_set->refcnt = 1;
156         action_set->spec = spec;
157
158         action_set->fw_rsrc.aset_id.id = EFX_MAE_RSRC_ID_INVALID;
159
160         TAILQ_INSERT_TAIL(&mae->action_sets, action_set, entries);
161
162         *action_setp = action_set;
163
164         return 0;
165 }
166
167 static void
168 sfc_mae_action_set_del(struct sfc_adapter *sa,
169                        struct sfc_mae_action_set *action_set)
170 {
171         struct sfc_mae *mae = &sa->mae;
172
173         SFC_ASSERT(sfc_adapter_is_locked(sa));
174         SFC_ASSERT(action_set->refcnt != 0);
175
176         --(action_set->refcnt);
177
178         if (action_set->refcnt != 0)
179                 return;
180
181         SFC_ASSERT(action_set->fw_rsrc.aset_id.id == EFX_MAE_RSRC_ID_INVALID);
182         SFC_ASSERT(action_set->fw_rsrc.refcnt == 0);
183
184         efx_mae_action_set_spec_fini(sa->nic, action_set->spec);
185         TAILQ_REMOVE(&mae->action_sets, action_set, entries);
186         rte_free(action_set);
187 }
188
189 static int
190 sfc_mae_action_set_enable(struct sfc_adapter *sa,
191                           struct sfc_mae_action_set *action_set)
192 {
193         struct sfc_mae_fw_rsrc *fw_rsrc = &action_set->fw_rsrc;
194         int rc;
195
196         SFC_ASSERT(sfc_adapter_is_locked(sa));
197
198         if (fw_rsrc->refcnt == 0) {
199                 SFC_ASSERT(fw_rsrc->aset_id.id == EFX_MAE_RSRC_ID_INVALID);
200                 SFC_ASSERT(action_set->spec != NULL);
201
202                 rc = efx_mae_action_set_alloc(sa->nic, action_set->spec,
203                                               &fw_rsrc->aset_id);
204                 if (rc != 0)
205                         return rc;
206         }
207
208         ++(fw_rsrc->refcnt);
209
210         return 0;
211 }
212
213 static int
214 sfc_mae_action_set_disable(struct sfc_adapter *sa,
215                            struct sfc_mae_action_set *action_set)
216 {
217         struct sfc_mae_fw_rsrc *fw_rsrc = &action_set->fw_rsrc;
218         int rc;
219
220         SFC_ASSERT(sfc_adapter_is_locked(sa));
221         SFC_ASSERT(fw_rsrc->aset_id.id != EFX_MAE_RSRC_ID_INVALID);
222         SFC_ASSERT(fw_rsrc->refcnt != 0);
223
224         if (fw_rsrc->refcnt == 1) {
225                 rc = efx_mae_action_set_free(sa->nic, &fw_rsrc->aset_id);
226                 if (rc != 0)
227                         return rc;
228
229                 fw_rsrc->aset_id.id = EFX_MAE_RSRC_ID_INVALID;
230         }
231
232         --(fw_rsrc->refcnt);
233
234         return 0;
235 }
236
237 void
238 sfc_mae_flow_cleanup(struct sfc_adapter *sa,
239                      struct rte_flow *flow)
240 {
241         struct sfc_flow_spec *spec;
242         struct sfc_flow_spec_mae *spec_mae;
243
244         if (flow == NULL)
245                 return;
246
247         spec = &flow->spec;
248
249         if (spec == NULL)
250                 return;
251
252         spec_mae = &spec->mae;
253
254         SFC_ASSERT(spec_mae->rule_id.id == EFX_MAE_RSRC_ID_INVALID);
255
256         if (spec_mae->action_set != NULL)
257                 sfc_mae_action_set_del(sa, spec_mae->action_set);
258
259         if (spec_mae->match_spec != NULL)
260                 efx_mae_match_spec_fini(sa->nic, spec_mae->match_spec);
261 }
262
263 static int
264 sfc_mae_set_ethertypes(struct sfc_mae_parse_ctx *ctx)
265 {
266         efx_mae_match_spec_t *efx_spec = ctx->match_spec_action;
267         struct sfc_mae_pattern_data *pdata = &ctx->pattern_data;
268         const efx_mae_field_id_t field_ids[] = {
269                 EFX_MAE_FIELD_VLAN0_PROTO_BE,
270                 EFX_MAE_FIELD_VLAN1_PROTO_BE,
271         };
272         const struct sfc_mae_ethertype *et;
273         unsigned int i;
274         int rc;
275
276         /*
277          * In accordance with RTE flow API convention, the innermost L2
278          * item's "type" ("inner_type") is a L3 EtherType. If there is
279          * no L3 item, it's 0x0000/0x0000.
280          */
281         et = &pdata->ethertypes[pdata->nb_vlan_tags];
282         rc = efx_mae_match_spec_field_set(efx_spec, EFX_MAE_FIELD_ETHER_TYPE_BE,
283                                           sizeof(et->value),
284                                           (const uint8_t *)&et->value,
285                                           sizeof(et->mask),
286                                           (const uint8_t *)&et->mask);
287         if (rc != 0)
288                 return rc;
289
290         /*
291          * sfc_mae_rule_parse_item_vlan() has already made sure
292          * that pdata->nb_vlan_tags does not exceed this figure.
293          */
294         RTE_BUILD_BUG_ON(SFC_MAE_MATCH_VLAN_MAX_NTAGS != 2);
295
296         for (i = 0; i < pdata->nb_vlan_tags; ++i) {
297                 et = &pdata->ethertypes[i];
298
299                 rc = efx_mae_match_spec_field_set(efx_spec, field_ids[i],
300                                                   sizeof(et->value),
301                                                   (const uint8_t *)&et->value,
302                                                   sizeof(et->mask),
303                                                   (const uint8_t *)&et->mask);
304                 if (rc != 0)
305                         return rc;
306         }
307
308         return 0;
309 }
310
311 static int
312 sfc_mae_rule_process_pattern_data(struct sfc_mae_parse_ctx *ctx,
313                                   struct rte_flow_error *error)
314 {
315         efx_mae_match_spec_t *efx_spec = ctx->match_spec_action;
316         struct sfc_mae_pattern_data *pdata = &ctx->pattern_data;
317         struct sfc_mae_ethertype *ethertypes = pdata->ethertypes;
318         const rte_be16_t supported_tpids[] = {
319                 /* VLAN standard TPID (always the first element) */
320                 RTE_BE16(RTE_ETHER_TYPE_VLAN),
321
322                 /* Double-tagging TPIDs */
323                 RTE_BE16(RTE_ETHER_TYPE_QINQ),
324                 RTE_BE16(RTE_ETHER_TYPE_QINQ1),
325                 RTE_BE16(RTE_ETHER_TYPE_QINQ2),
326                 RTE_BE16(RTE_ETHER_TYPE_QINQ3),
327         };
328         unsigned int nb_supported_tpids = RTE_DIM(supported_tpids);
329         unsigned int ethertype_idx;
330         const uint8_t *valuep;
331         const uint8_t *maskp;
332         int rc;
333
334         if (pdata->innermost_ethertype_restriction.mask != 0 &&
335             pdata->nb_vlan_tags < SFC_MAE_MATCH_VLAN_MAX_NTAGS) {
336                 /*
337                  * If a single item VLAN is followed by a L3 item, value
338                  * of "type" in item ETH can't be a double-tagging TPID.
339                  */
340                 nb_supported_tpids = 1;
341         }
342
343         /*
344          * sfc_mae_rule_parse_item_vlan() has already made sure
345          * that pdata->nb_vlan_tags does not exceed this figure.
346          */
347         RTE_BUILD_BUG_ON(SFC_MAE_MATCH_VLAN_MAX_NTAGS != 2);
348
349         for (ethertype_idx = 0;
350              ethertype_idx < pdata->nb_vlan_tags; ++ethertype_idx) {
351                 unsigned int tpid_idx;
352
353                 /* Exact match is supported only. */
354                 if (ethertypes[ethertype_idx].mask != RTE_BE16(0xffff)) {
355                         rc = EINVAL;
356                         goto fail;
357                 }
358
359                 for (tpid_idx = pdata->nb_vlan_tags - ethertype_idx - 1;
360                      tpid_idx < nb_supported_tpids; ++tpid_idx) {
361                         if (ethertypes[ethertype_idx].value ==
362                             supported_tpids[tpid_idx])
363                                 break;
364                 }
365
366                 if (tpid_idx == nb_supported_tpids) {
367                         rc = EINVAL;
368                         goto fail;
369                 }
370
371                 nb_supported_tpids = 1;
372         }
373
374         if (pdata->innermost_ethertype_restriction.mask == RTE_BE16(0xffff)) {
375                 struct sfc_mae_ethertype *et = &ethertypes[ethertype_idx];
376
377                 if (et->mask == 0) {
378                         et->mask = RTE_BE16(0xffff);
379                         et->value =
380                             pdata->innermost_ethertype_restriction.value;
381                 } else if (et->mask != RTE_BE16(0xffff) ||
382                            et->value !=
383                            pdata->innermost_ethertype_restriction.value) {
384                         rc = EINVAL;
385                         goto fail;
386                 }
387         }
388
389         /*
390          * Now, when the number of VLAN tags is known, set fields
391          * ETHER_TYPE, VLAN0_PROTO and VLAN1_PROTO so that the first
392          * one is either a valid L3 EtherType (or 0x0000/0x0000),
393          * and the last two are valid TPIDs (or 0x0000/0x0000).
394          */
395         rc = sfc_mae_set_ethertypes(ctx);
396         if (rc != 0)
397                 goto fail;
398
399         if (pdata->l3_next_proto_restriction_mask == 0xff) {
400                 if (pdata->l3_next_proto_mask == 0) {
401                         pdata->l3_next_proto_mask = 0xff;
402                         pdata->l3_next_proto_value =
403                             pdata->l3_next_proto_restriction_value;
404                 } else if (pdata->l3_next_proto_mask != 0xff ||
405                            pdata->l3_next_proto_value !=
406                            pdata->l3_next_proto_restriction_value) {
407                         rc = EINVAL;
408                         goto fail;
409                 }
410         }
411
412         valuep = (const uint8_t *)&pdata->l3_next_proto_value;
413         maskp = (const uint8_t *)&pdata->l3_next_proto_mask;
414         rc = efx_mae_match_spec_field_set(efx_spec, EFX_MAE_FIELD_IP_PROTO,
415                                           sizeof(pdata->l3_next_proto_value),
416                                           valuep,
417                                           sizeof(pdata->l3_next_proto_mask),
418                                           maskp);
419         if (rc != 0)
420                 goto fail;
421
422         return 0;
423
424 fail:
425         return rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM, NULL,
426                                   "Failed to process pattern data");
427 }
428
429 static int
430 sfc_mae_rule_parse_item_port_id(const struct rte_flow_item *item,
431                                 struct sfc_flow_parse_ctx *ctx,
432                                 struct rte_flow_error *error)
433 {
434         struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
435         const struct rte_flow_item_port_id supp_mask = {
436                 .id = 0xffffffff,
437         };
438         const void *def_mask = &rte_flow_item_port_id_mask;
439         const struct rte_flow_item_port_id *spec = NULL;
440         const struct rte_flow_item_port_id *mask = NULL;
441         efx_mport_sel_t mport_sel;
442         int rc;
443
444         if (ctx_mae->match_mport_set) {
445                 return rte_flow_error_set(error, ENOTSUP,
446                                 RTE_FLOW_ERROR_TYPE_ITEM, item,
447                                 "Can't handle multiple traffic source items");
448         }
449
450         rc = sfc_flow_parse_init(item,
451                                  (const void **)&spec, (const void **)&mask,
452                                  (const void *)&supp_mask, def_mask,
453                                  sizeof(struct rte_flow_item_port_id), error);
454         if (rc != 0)
455                 return rc;
456
457         if (mask->id != supp_mask.id) {
458                 return rte_flow_error_set(error, EINVAL,
459                                 RTE_FLOW_ERROR_TYPE_ITEM, item,
460                                 "Bad mask in the PORT_ID pattern item");
461         }
462
463         /* If "spec" is not set, could be any port ID */
464         if (spec == NULL)
465                 return 0;
466
467         if (spec->id > UINT16_MAX) {
468                 return rte_flow_error_set(error, EOVERFLOW,
469                                           RTE_FLOW_ERROR_TYPE_ITEM, item,
470                                           "The port ID is too large");
471         }
472
473         rc = sfc_mae_switch_port_by_ethdev(ctx_mae->sa->mae.switch_domain_id,
474                                            spec->id, &mport_sel);
475         if (rc != 0) {
476                 return rte_flow_error_set(error, rc,
477                                 RTE_FLOW_ERROR_TYPE_ITEM, item,
478                                 "Can't find RTE ethdev by the port ID");
479         }
480
481         rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec_action,
482                                           &mport_sel, NULL);
483         if (rc != 0) {
484                 return rte_flow_error_set(error, rc,
485                                 RTE_FLOW_ERROR_TYPE_ITEM, item,
486                                 "Failed to set MPORT for the port ID");
487         }
488
489         ctx_mae->match_mport_set = B_TRUE;
490
491         return 0;
492 }
493
494 static int
495 sfc_mae_rule_parse_item_phy_port(const struct rte_flow_item *item,
496                                  struct sfc_flow_parse_ctx *ctx,
497                                  struct rte_flow_error *error)
498 {
499         struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
500         const struct rte_flow_item_phy_port supp_mask = {
501                 .index = 0xffffffff,
502         };
503         const void *def_mask = &rte_flow_item_phy_port_mask;
504         const struct rte_flow_item_phy_port *spec = NULL;
505         const struct rte_flow_item_phy_port *mask = NULL;
506         efx_mport_sel_t mport_v;
507         int rc;
508
509         if (ctx_mae->match_mport_set) {
510                 return rte_flow_error_set(error, ENOTSUP,
511                                 RTE_FLOW_ERROR_TYPE_ITEM, item,
512                                 "Can't handle multiple traffic source items");
513         }
514
515         rc = sfc_flow_parse_init(item,
516                                  (const void **)&spec, (const void **)&mask,
517                                  (const void *)&supp_mask, def_mask,
518                                  sizeof(struct rte_flow_item_phy_port), error);
519         if (rc != 0)
520                 return rc;
521
522         if (mask->index != supp_mask.index) {
523                 return rte_flow_error_set(error, EINVAL,
524                                 RTE_FLOW_ERROR_TYPE_ITEM, item,
525                                 "Bad mask in the PHY_PORT pattern item");
526         }
527
528         /* If "spec" is not set, could be any physical port */
529         if (spec == NULL)
530                 return 0;
531
532         rc = efx_mae_mport_by_phy_port(spec->index, &mport_v);
533         if (rc != 0) {
534                 return rte_flow_error_set(error, rc,
535                                 RTE_FLOW_ERROR_TYPE_ITEM, item,
536                                 "Failed to convert the PHY_PORT index");
537         }
538
539         rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec_action,
540                                           &mport_v, NULL);
541         if (rc != 0) {
542                 return rte_flow_error_set(error, rc,
543                                 RTE_FLOW_ERROR_TYPE_ITEM, item,
544                                 "Failed to set MPORT for the PHY_PORT");
545         }
546
547         ctx_mae->match_mport_set = B_TRUE;
548
549         return 0;
550 }
551
552 static int
553 sfc_mae_rule_parse_item_pf(const struct rte_flow_item *item,
554                            struct sfc_flow_parse_ctx *ctx,
555                            struct rte_flow_error *error)
556 {
557         struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
558         const efx_nic_cfg_t *encp = efx_nic_cfg_get(ctx_mae->sa->nic);
559         efx_mport_sel_t mport_v;
560         int rc;
561
562         if (ctx_mae->match_mport_set) {
563                 return rte_flow_error_set(error, ENOTSUP,
564                                 RTE_FLOW_ERROR_TYPE_ITEM, item,
565                                 "Can't handle multiple traffic source items");
566         }
567
568         rc = efx_mae_mport_by_pcie_function(encp->enc_pf, EFX_PCI_VF_INVALID,
569                                             &mport_v);
570         if (rc != 0) {
571                 return rte_flow_error_set(error, rc,
572                                 RTE_FLOW_ERROR_TYPE_ITEM, item,
573                                 "Failed to convert the PF ID");
574         }
575
576         rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec_action,
577                                           &mport_v, NULL);
578         if (rc != 0) {
579                 return rte_flow_error_set(error, rc,
580                                 RTE_FLOW_ERROR_TYPE_ITEM, item,
581                                 "Failed to set MPORT for the PF");
582         }
583
584         ctx_mae->match_mport_set = B_TRUE;
585
586         return 0;
587 }
588
589 static int
590 sfc_mae_rule_parse_item_vf(const struct rte_flow_item *item,
591                            struct sfc_flow_parse_ctx *ctx,
592                            struct rte_flow_error *error)
593 {
594         struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
595         const efx_nic_cfg_t *encp = efx_nic_cfg_get(ctx_mae->sa->nic);
596         const struct rte_flow_item_vf supp_mask = {
597                 .id = 0xffffffff,
598         };
599         const void *def_mask = &rte_flow_item_vf_mask;
600         const struct rte_flow_item_vf *spec = NULL;
601         const struct rte_flow_item_vf *mask = NULL;
602         efx_mport_sel_t mport_v;
603         int rc;
604
605         if (ctx_mae->match_mport_set) {
606                 return rte_flow_error_set(error, ENOTSUP,
607                                 RTE_FLOW_ERROR_TYPE_ITEM, item,
608                                 "Can't handle multiple traffic source items");
609         }
610
611         rc = sfc_flow_parse_init(item,
612                                  (const void **)&spec, (const void **)&mask,
613                                  (const void *)&supp_mask, def_mask,
614                                  sizeof(struct rte_flow_item_vf), error);
615         if (rc != 0)
616                 return rc;
617
618         if (mask->id != supp_mask.id) {
619                 return rte_flow_error_set(error, EINVAL,
620                                 RTE_FLOW_ERROR_TYPE_ITEM, item,
621                                 "Bad mask in the VF pattern item");
622         }
623
624         /*
625          * If "spec" is not set, the item requests any VF related to the
626          * PF of the current DPDK port (but not the PF itself).
627          * Reject this match criterion as unsupported.
628          */
629         if (spec == NULL) {
630                 return rte_flow_error_set(error, EINVAL,
631                                 RTE_FLOW_ERROR_TYPE_ITEM, item,
632                                 "Bad spec in the VF pattern item");
633         }
634
635         rc = efx_mae_mport_by_pcie_function(encp->enc_pf, spec->id, &mport_v);
636         if (rc != 0) {
637                 return rte_flow_error_set(error, rc,
638                                 RTE_FLOW_ERROR_TYPE_ITEM, item,
639                                 "Failed to convert the PF + VF IDs");
640         }
641
642         rc = efx_mae_match_spec_mport_set(ctx_mae->match_spec_action,
643                                           &mport_v, NULL);
644         if (rc != 0) {
645                 return rte_flow_error_set(error, rc,
646                                 RTE_FLOW_ERROR_TYPE_ITEM, item,
647                                 "Failed to set MPORT for the PF + VF");
648         }
649
650         ctx_mae->match_mport_set = B_TRUE;
651
652         return 0;
653 }
654
655 /*
656  * Having this field ID in a field locator means that this
657  * locator cannot be used to actually set the field at the
658  * time when the corresponding item gets encountered. Such
659  * fields get stashed in the parsing context instead. This
660  * is required to resolve dependencies between the stashed
661  * fields. See sfc_mae_rule_process_pattern_data().
662  */
663 #define SFC_MAE_FIELD_HANDLING_DEFERRED EFX_MAE_FIELD_NIDS
664
665 struct sfc_mae_field_locator {
666         efx_mae_field_id_t              field_id;
667         size_t                          size;
668         /* Field offset in the corresponding rte_flow_item_ struct */
669         size_t                          ofst;
670 };
671
672 static void
673 sfc_mae_item_build_supp_mask(const struct sfc_mae_field_locator *field_locators,
674                              unsigned int nb_field_locators, void *mask_ptr,
675                              size_t mask_size)
676 {
677         unsigned int i;
678
679         memset(mask_ptr, 0, mask_size);
680
681         for (i = 0; i < nb_field_locators; ++i) {
682                 const struct sfc_mae_field_locator *fl = &field_locators[i];
683
684                 SFC_ASSERT(fl->ofst + fl->size <= mask_size);
685                 memset(RTE_PTR_ADD(mask_ptr, fl->ofst), 0xff, fl->size);
686         }
687 }
688
689 static int
690 sfc_mae_parse_item(const struct sfc_mae_field_locator *field_locators,
691                    unsigned int nb_field_locators, const uint8_t *spec,
692                    const uint8_t *mask, efx_mae_match_spec_t *efx_spec,
693                    struct rte_flow_error *error)
694 {
695         unsigned int i;
696         int rc = 0;
697
698         for (i = 0; i < nb_field_locators; ++i) {
699                 const struct sfc_mae_field_locator *fl = &field_locators[i];
700
701                 if (fl->field_id == SFC_MAE_FIELD_HANDLING_DEFERRED)
702                         continue;
703
704                 rc = efx_mae_match_spec_field_set(efx_spec, fl->field_id,
705                                                   fl->size, spec + fl->ofst,
706                                                   fl->size, mask + fl->ofst);
707                 if (rc != 0)
708                         break;
709         }
710
711         if (rc != 0) {
712                 rc = rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM,
713                                 NULL, "Failed to process item fields");
714         }
715
716         return rc;
717 }
718
719 static const struct sfc_mae_field_locator flocs_eth[] = {
720         {
721                 /*
722                  * This locator is used only for building supported fields mask.
723                  * The field is handled by sfc_mae_rule_process_pattern_data().
724                  */
725                 SFC_MAE_FIELD_HANDLING_DEFERRED,
726                 RTE_SIZEOF_FIELD(struct rte_flow_item_eth, type),
727                 offsetof(struct rte_flow_item_eth, type),
728         },
729         {
730                 EFX_MAE_FIELD_ETH_DADDR_BE,
731                 RTE_SIZEOF_FIELD(struct rte_flow_item_eth, dst),
732                 offsetof(struct rte_flow_item_eth, dst),
733         },
734         {
735                 EFX_MAE_FIELD_ETH_SADDR_BE,
736                 RTE_SIZEOF_FIELD(struct rte_flow_item_eth, src),
737                 offsetof(struct rte_flow_item_eth, src),
738         },
739 };
740
741 static int
742 sfc_mae_rule_parse_item_eth(const struct rte_flow_item *item,
743                             struct sfc_flow_parse_ctx *ctx,
744                             struct rte_flow_error *error)
745 {
746         struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
747         struct rte_flow_item_eth supp_mask;
748         const uint8_t *spec = NULL;
749         const uint8_t *mask = NULL;
750         int rc;
751
752         sfc_mae_item_build_supp_mask(flocs_eth, RTE_DIM(flocs_eth),
753                                      &supp_mask, sizeof(supp_mask));
754
755         rc = sfc_flow_parse_init(item,
756                                  (const void **)&spec, (const void **)&mask,
757                                  (const void *)&supp_mask,
758                                  &rte_flow_item_eth_mask,
759                                  sizeof(struct rte_flow_item_eth), error);
760         if (rc != 0)
761                 return rc;
762
763         if (spec != NULL) {
764                 struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
765                 struct sfc_mae_ethertype *ethertypes = pdata->ethertypes;
766                 const struct rte_flow_item_eth *item_spec;
767                 const struct rte_flow_item_eth *item_mask;
768
769                 item_spec = (const struct rte_flow_item_eth *)spec;
770                 item_mask = (const struct rte_flow_item_eth *)mask;
771
772                 ethertypes[0].value = item_spec->type;
773                 ethertypes[0].mask = item_mask->type;
774         } else {
775                 /*
776                  * The specification is empty. This is wrong in the case
777                  * when there are more network patterns in line. Other
778                  * than that, any Ethernet can match. All of that is
779                  * checked at the end of parsing.
780                  */
781                 return 0;
782         }
783
784         return sfc_mae_parse_item(flocs_eth, RTE_DIM(flocs_eth), spec, mask,
785                                   ctx_mae->match_spec_action, error);
786 }
787
788 static const struct sfc_mae_field_locator flocs_vlan[] = {
789         /* Outermost tag */
790         {
791                 EFX_MAE_FIELD_VLAN0_TCI_BE,
792                 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, tci),
793                 offsetof(struct rte_flow_item_vlan, tci),
794         },
795         {
796                 /*
797                  * This locator is used only for building supported fields mask.
798                  * The field is handled by sfc_mae_rule_process_pattern_data().
799                  */
800                 SFC_MAE_FIELD_HANDLING_DEFERRED,
801                 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, inner_type),
802                 offsetof(struct rte_flow_item_vlan, inner_type),
803         },
804
805         /* Innermost tag */
806         {
807                 EFX_MAE_FIELD_VLAN1_TCI_BE,
808                 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, tci),
809                 offsetof(struct rte_flow_item_vlan, tci),
810         },
811         {
812                 /*
813                  * This locator is used only for building supported fields mask.
814                  * The field is handled by sfc_mae_rule_process_pattern_data().
815                  */
816                 SFC_MAE_FIELD_HANDLING_DEFERRED,
817                 RTE_SIZEOF_FIELD(struct rte_flow_item_vlan, inner_type),
818                 offsetof(struct rte_flow_item_vlan, inner_type),
819         },
820 };
821
822 static int
823 sfc_mae_rule_parse_item_vlan(const struct rte_flow_item *item,
824                              struct sfc_flow_parse_ctx *ctx,
825                              struct rte_flow_error *error)
826 {
827         struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
828         struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
829         const struct sfc_mae_field_locator *flocs;
830         struct rte_flow_item_vlan supp_mask;
831         const uint8_t *spec = NULL;
832         const uint8_t *mask = NULL;
833         unsigned int nb_flocs;
834         int rc;
835
836         RTE_BUILD_BUG_ON(SFC_MAE_MATCH_VLAN_MAX_NTAGS != 2);
837
838         if (pdata->nb_vlan_tags == SFC_MAE_MATCH_VLAN_MAX_NTAGS) {
839                 return rte_flow_error_set(error, ENOTSUP,
840                                 RTE_FLOW_ERROR_TYPE_ITEM, item,
841                                 "Can't match that many VLAN tags");
842         }
843
844         nb_flocs = RTE_DIM(flocs_vlan) / SFC_MAE_MATCH_VLAN_MAX_NTAGS;
845         flocs = flocs_vlan + pdata->nb_vlan_tags * nb_flocs;
846
847         /* If parsing fails, this can remain incremented. */
848         ++pdata->nb_vlan_tags;
849
850         sfc_mae_item_build_supp_mask(flocs, nb_flocs,
851                                      &supp_mask, sizeof(supp_mask));
852
853         rc = sfc_flow_parse_init(item,
854                                  (const void **)&spec, (const void **)&mask,
855                                  (const void *)&supp_mask,
856                                  &rte_flow_item_vlan_mask,
857                                  sizeof(struct rte_flow_item_vlan), error);
858         if (rc != 0)
859                 return rc;
860
861         if (spec != NULL) {
862                 struct sfc_mae_ethertype *ethertypes = pdata->ethertypes;
863                 const struct rte_flow_item_vlan *item_spec;
864                 const struct rte_flow_item_vlan *item_mask;
865
866                 item_spec = (const struct rte_flow_item_vlan *)spec;
867                 item_mask = (const struct rte_flow_item_vlan *)mask;
868
869                 ethertypes[pdata->nb_vlan_tags].value = item_spec->inner_type;
870                 ethertypes[pdata->nb_vlan_tags].mask = item_mask->inner_type;
871         } else {
872                 /*
873                  * The specification is empty. This is wrong in the case
874                  * when there are more network patterns in line. Other
875                  * than that, any Ethernet can match. All of that is
876                  * checked at the end of parsing.
877                  */
878                 return 0;
879         }
880
881         return sfc_mae_parse_item(flocs, nb_flocs, spec, mask,
882                                   ctx_mae->match_spec_action, error);
883 }
884
885 static const struct sfc_mae_field_locator flocs_ipv4[] = {
886         {
887                 EFX_MAE_FIELD_SRC_IP4_BE,
888                 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.src_addr),
889                 offsetof(struct rte_flow_item_ipv4, hdr.src_addr),
890         },
891         {
892                 EFX_MAE_FIELD_DST_IP4_BE,
893                 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.dst_addr),
894                 offsetof(struct rte_flow_item_ipv4, hdr.dst_addr),
895         },
896         {
897                 /*
898                  * This locator is used only for building supported fields mask.
899                  * The field is handled by sfc_mae_rule_process_pattern_data().
900                  */
901                 SFC_MAE_FIELD_HANDLING_DEFERRED,
902                 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.next_proto_id),
903                 offsetof(struct rte_flow_item_ipv4, hdr.next_proto_id),
904         },
905         {
906                 EFX_MAE_FIELD_IP_TOS,
907                 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4,
908                                  hdr.type_of_service),
909                 offsetof(struct rte_flow_item_ipv4, hdr.type_of_service),
910         },
911         {
912                 EFX_MAE_FIELD_IP_TTL,
913                 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv4, hdr.time_to_live),
914                 offsetof(struct rte_flow_item_ipv4, hdr.time_to_live),
915         },
916 };
917
918 static int
919 sfc_mae_rule_parse_item_ipv4(const struct rte_flow_item *item,
920                              struct sfc_flow_parse_ctx *ctx,
921                              struct rte_flow_error *error)
922 {
923         rte_be16_t ethertype_ipv4_be = RTE_BE16(RTE_ETHER_TYPE_IPV4);
924         struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
925         struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
926         struct rte_flow_item_ipv4 supp_mask;
927         const uint8_t *spec = NULL;
928         const uint8_t *mask = NULL;
929         int rc;
930
931         sfc_mae_item_build_supp_mask(flocs_ipv4, RTE_DIM(flocs_ipv4),
932                                      &supp_mask, sizeof(supp_mask));
933
934         rc = sfc_flow_parse_init(item,
935                                  (const void **)&spec, (const void **)&mask,
936                                  (const void *)&supp_mask,
937                                  &rte_flow_item_ipv4_mask,
938                                  sizeof(struct rte_flow_item_ipv4), error);
939         if (rc != 0)
940                 return rc;
941
942         pdata->innermost_ethertype_restriction.value = ethertype_ipv4_be;
943         pdata->innermost_ethertype_restriction.mask = RTE_BE16(0xffff);
944
945         if (spec != NULL) {
946                 const struct rte_flow_item_ipv4 *item_spec;
947                 const struct rte_flow_item_ipv4 *item_mask;
948
949                 item_spec = (const struct rte_flow_item_ipv4 *)spec;
950                 item_mask = (const struct rte_flow_item_ipv4 *)mask;
951
952                 pdata->l3_next_proto_value = item_spec->hdr.next_proto_id;
953                 pdata->l3_next_proto_mask = item_mask->hdr.next_proto_id;
954         } else {
955                 return 0;
956         }
957
958         return sfc_mae_parse_item(flocs_ipv4, RTE_DIM(flocs_ipv4), spec, mask,
959                                   ctx_mae->match_spec_action, error);
960 }
961
962 static const struct sfc_mae_field_locator flocs_ipv6[] = {
963         {
964                 EFX_MAE_FIELD_SRC_IP6_BE,
965                 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.src_addr),
966                 offsetof(struct rte_flow_item_ipv6, hdr.src_addr),
967         },
968         {
969                 EFX_MAE_FIELD_DST_IP6_BE,
970                 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.dst_addr),
971                 offsetof(struct rte_flow_item_ipv6, hdr.dst_addr),
972         },
973         {
974                 /*
975                  * This locator is used only for building supported fields mask.
976                  * The field is handled by sfc_mae_rule_process_pattern_data().
977                  */
978                 SFC_MAE_FIELD_HANDLING_DEFERRED,
979                 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.proto),
980                 offsetof(struct rte_flow_item_ipv6, hdr.proto),
981         },
982         {
983                 EFX_MAE_FIELD_IP_TTL,
984                 RTE_SIZEOF_FIELD(struct rte_flow_item_ipv6, hdr.hop_limits),
985                 offsetof(struct rte_flow_item_ipv6, hdr.hop_limits),
986         },
987 };
988
989 static int
990 sfc_mae_rule_parse_item_ipv6(const struct rte_flow_item *item,
991                              struct sfc_flow_parse_ctx *ctx,
992                              struct rte_flow_error *error)
993 {
994         rte_be16_t ethertype_ipv6_be = RTE_BE16(RTE_ETHER_TYPE_IPV6);
995         struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
996         struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
997         struct rte_flow_item_ipv6 supp_mask;
998         const uint8_t *spec = NULL;
999         const uint8_t *mask = NULL;
1000         rte_be32_t vtc_flow_be;
1001         uint32_t vtc_flow;
1002         uint8_t tc_value;
1003         uint8_t tc_mask;
1004         int rc;
1005
1006         sfc_mae_item_build_supp_mask(flocs_ipv6, RTE_DIM(flocs_ipv6),
1007                                      &supp_mask, sizeof(supp_mask));
1008
1009         vtc_flow_be = RTE_BE32(RTE_IPV6_HDR_TC_MASK);
1010         memcpy(&supp_mask, &vtc_flow_be, sizeof(vtc_flow_be));
1011
1012         rc = sfc_flow_parse_init(item,
1013                                  (const void **)&spec, (const void **)&mask,
1014                                  (const void *)&supp_mask,
1015                                  &rte_flow_item_ipv6_mask,
1016                                  sizeof(struct rte_flow_item_ipv6), error);
1017         if (rc != 0)
1018                 return rc;
1019
1020         pdata->innermost_ethertype_restriction.value = ethertype_ipv6_be;
1021         pdata->innermost_ethertype_restriction.mask = RTE_BE16(0xffff);
1022
1023         if (spec != NULL) {
1024                 const struct rte_flow_item_ipv6 *item_spec;
1025                 const struct rte_flow_item_ipv6 *item_mask;
1026
1027                 item_spec = (const struct rte_flow_item_ipv6 *)spec;
1028                 item_mask = (const struct rte_flow_item_ipv6 *)mask;
1029
1030                 pdata->l3_next_proto_value = item_spec->hdr.proto;
1031                 pdata->l3_next_proto_mask = item_mask->hdr.proto;
1032         } else {
1033                 return 0;
1034         }
1035
1036         rc = sfc_mae_parse_item(flocs_ipv6, RTE_DIM(flocs_ipv6), spec, mask,
1037                                 ctx_mae->match_spec_action, error);
1038         if (rc != 0)
1039                 return rc;
1040
1041         memcpy(&vtc_flow_be, spec, sizeof(vtc_flow_be));
1042         vtc_flow = rte_be_to_cpu_32(vtc_flow_be);
1043         tc_value = (vtc_flow & RTE_IPV6_HDR_TC_MASK) >> RTE_IPV6_HDR_TC_SHIFT;
1044
1045         memcpy(&vtc_flow_be, mask, sizeof(vtc_flow_be));
1046         vtc_flow = rte_be_to_cpu_32(vtc_flow_be);
1047         tc_mask = (vtc_flow & RTE_IPV6_HDR_TC_MASK) >> RTE_IPV6_HDR_TC_SHIFT;
1048
1049         rc = efx_mae_match_spec_field_set(ctx_mae->match_spec_action,
1050                                           EFX_MAE_FIELD_IP_TOS,
1051                                           sizeof(tc_value), &tc_value,
1052                                           sizeof(tc_mask), &tc_mask);
1053         if (rc != 0) {
1054                 return rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ITEM,
1055                                 NULL, "Failed to process item fields");
1056         }
1057
1058         return 0;
1059 }
1060
1061 static const struct sfc_mae_field_locator flocs_tcp[] = {
1062         {
1063                 EFX_MAE_FIELD_L4_SPORT_BE,
1064                 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.src_port),
1065                 offsetof(struct rte_flow_item_tcp, hdr.src_port),
1066         },
1067         {
1068                 EFX_MAE_FIELD_L4_DPORT_BE,
1069                 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.dst_port),
1070                 offsetof(struct rte_flow_item_tcp, hdr.dst_port),
1071         },
1072         {
1073                 EFX_MAE_FIELD_TCP_FLAGS_BE,
1074                 /*
1075                  * The values have been picked intentionally since the
1076                  * target MAE field is oversize (16 bit). This mapping
1077                  * relies on the fact that the MAE field is big-endian.
1078                  */
1079                 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.data_off) +
1080                 RTE_SIZEOF_FIELD(struct rte_flow_item_tcp, hdr.tcp_flags),
1081                 offsetof(struct rte_flow_item_tcp, hdr.data_off),
1082         },
1083 };
1084
1085 static int
1086 sfc_mae_rule_parse_item_tcp(const struct rte_flow_item *item,
1087                             struct sfc_flow_parse_ctx *ctx,
1088                             struct rte_flow_error *error)
1089 {
1090         struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1091         struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
1092         struct rte_flow_item_tcp supp_mask;
1093         const uint8_t *spec = NULL;
1094         const uint8_t *mask = NULL;
1095         int rc;
1096
1097         sfc_mae_item_build_supp_mask(flocs_tcp, RTE_DIM(flocs_tcp),
1098                                      &supp_mask, sizeof(supp_mask));
1099
1100         rc = sfc_flow_parse_init(item,
1101                                  (const void **)&spec, (const void **)&mask,
1102                                  (const void *)&supp_mask,
1103                                  &rte_flow_item_tcp_mask,
1104                                  sizeof(struct rte_flow_item_tcp), error);
1105         if (rc != 0)
1106                 return rc;
1107
1108         pdata->l3_next_proto_restriction_value = IPPROTO_TCP;
1109         pdata->l3_next_proto_restriction_mask = 0xff;
1110
1111         if (spec == NULL)
1112                 return 0;
1113
1114         return sfc_mae_parse_item(flocs_tcp, RTE_DIM(flocs_tcp), spec, mask,
1115                                   ctx_mae->match_spec_action, error);
1116 }
1117
1118 static const struct sfc_mae_field_locator flocs_udp[] = {
1119         {
1120                 EFX_MAE_FIELD_L4_SPORT_BE,
1121                 RTE_SIZEOF_FIELD(struct rte_flow_item_udp, hdr.src_port),
1122                 offsetof(struct rte_flow_item_udp, hdr.src_port),
1123         },
1124         {
1125                 EFX_MAE_FIELD_L4_DPORT_BE,
1126                 RTE_SIZEOF_FIELD(struct rte_flow_item_udp, hdr.dst_port),
1127                 offsetof(struct rte_flow_item_udp, hdr.dst_port),
1128         },
1129 };
1130
1131 static int
1132 sfc_mae_rule_parse_item_udp(const struct rte_flow_item *item,
1133                             struct sfc_flow_parse_ctx *ctx,
1134                             struct rte_flow_error *error)
1135 {
1136         struct sfc_mae_parse_ctx *ctx_mae = ctx->mae;
1137         struct sfc_mae_pattern_data *pdata = &ctx_mae->pattern_data;
1138         struct rte_flow_item_udp supp_mask;
1139         const uint8_t *spec = NULL;
1140         const uint8_t *mask = NULL;
1141         int rc;
1142
1143         sfc_mae_item_build_supp_mask(flocs_udp, RTE_DIM(flocs_udp),
1144                                      &supp_mask, sizeof(supp_mask));
1145
1146         rc = sfc_flow_parse_init(item,
1147                                  (const void **)&spec, (const void **)&mask,
1148                                  (const void *)&supp_mask,
1149                                  &rte_flow_item_udp_mask,
1150                                  sizeof(struct rte_flow_item_udp), error);
1151         if (rc != 0)
1152                 return rc;
1153
1154         pdata->l3_next_proto_restriction_value = IPPROTO_UDP;
1155         pdata->l3_next_proto_restriction_mask = 0xff;
1156
1157         if (spec == NULL)
1158                 return 0;
1159
1160         return sfc_mae_parse_item(flocs_udp, RTE_DIM(flocs_udp), spec, mask,
1161                                   ctx_mae->match_spec_action, error);
1162 }
1163
1164 static const struct sfc_flow_item sfc_flow_items[] = {
1165         {
1166                 .type = RTE_FLOW_ITEM_TYPE_PORT_ID,
1167                 /*
1168                  * In terms of RTE flow, this item is a META one,
1169                  * and its position in the pattern is don't care.
1170                  */
1171                 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
1172                 .layer = SFC_FLOW_ITEM_ANY_LAYER,
1173                 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
1174                 .parse = sfc_mae_rule_parse_item_port_id,
1175         },
1176         {
1177                 .type = RTE_FLOW_ITEM_TYPE_PHY_PORT,
1178                 /*
1179                  * In terms of RTE flow, this item is a META one,
1180                  * and its position in the pattern is don't care.
1181                  */
1182                 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
1183                 .layer = SFC_FLOW_ITEM_ANY_LAYER,
1184                 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
1185                 .parse = sfc_mae_rule_parse_item_phy_port,
1186         },
1187         {
1188                 .type = RTE_FLOW_ITEM_TYPE_PF,
1189                 /*
1190                  * In terms of RTE flow, this item is a META one,
1191                  * and its position in the pattern is don't care.
1192                  */
1193                 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
1194                 .layer = SFC_FLOW_ITEM_ANY_LAYER,
1195                 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
1196                 .parse = sfc_mae_rule_parse_item_pf,
1197         },
1198         {
1199                 .type = RTE_FLOW_ITEM_TYPE_VF,
1200                 /*
1201                  * In terms of RTE flow, this item is a META one,
1202                  * and its position in the pattern is don't care.
1203                  */
1204                 .prev_layer = SFC_FLOW_ITEM_ANY_LAYER,
1205                 .layer = SFC_FLOW_ITEM_ANY_LAYER,
1206                 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
1207                 .parse = sfc_mae_rule_parse_item_vf,
1208         },
1209         {
1210                 .type = RTE_FLOW_ITEM_TYPE_ETH,
1211                 .prev_layer = SFC_FLOW_ITEM_START_LAYER,
1212                 .layer = SFC_FLOW_ITEM_L2,
1213                 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
1214                 .parse = sfc_mae_rule_parse_item_eth,
1215         },
1216         {
1217                 .type = RTE_FLOW_ITEM_TYPE_VLAN,
1218                 .prev_layer = SFC_FLOW_ITEM_L2,
1219                 .layer = SFC_FLOW_ITEM_L2,
1220                 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
1221                 .parse = sfc_mae_rule_parse_item_vlan,
1222         },
1223         {
1224                 .type = RTE_FLOW_ITEM_TYPE_IPV4,
1225                 .prev_layer = SFC_FLOW_ITEM_L2,
1226                 .layer = SFC_FLOW_ITEM_L3,
1227                 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
1228                 .parse = sfc_mae_rule_parse_item_ipv4,
1229         },
1230         {
1231                 .type = RTE_FLOW_ITEM_TYPE_IPV6,
1232                 .prev_layer = SFC_FLOW_ITEM_L2,
1233                 .layer = SFC_FLOW_ITEM_L3,
1234                 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
1235                 .parse = sfc_mae_rule_parse_item_ipv6,
1236         },
1237         {
1238                 .type = RTE_FLOW_ITEM_TYPE_TCP,
1239                 .prev_layer = SFC_FLOW_ITEM_L3,
1240                 .layer = SFC_FLOW_ITEM_L4,
1241                 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
1242                 .parse = sfc_mae_rule_parse_item_tcp,
1243         },
1244         {
1245                 .type = RTE_FLOW_ITEM_TYPE_UDP,
1246                 .prev_layer = SFC_FLOW_ITEM_L3,
1247                 .layer = SFC_FLOW_ITEM_L4,
1248                 .ctx_type = SFC_FLOW_PARSE_CTX_MAE,
1249                 .parse = sfc_mae_rule_parse_item_udp,
1250         },
1251 };
1252
1253 int
1254 sfc_mae_rule_parse_pattern(struct sfc_adapter *sa,
1255                            const struct rte_flow_item pattern[],
1256                            struct sfc_flow_spec_mae *spec,
1257                            struct rte_flow_error *error)
1258 {
1259         struct sfc_mae_parse_ctx ctx_mae;
1260         struct sfc_flow_parse_ctx ctx;
1261         int rc;
1262
1263         memset(&ctx_mae, 0, sizeof(ctx_mae));
1264         ctx_mae.sa = sa;
1265
1266         rc = efx_mae_match_spec_init(sa->nic, EFX_MAE_RULE_ACTION,
1267                                      spec->priority,
1268                                      &ctx_mae.match_spec_action);
1269         if (rc != 0) {
1270                 rc = rte_flow_error_set(error, rc,
1271                         RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1272                         "Failed to initialise action rule match specification");
1273                 goto fail_init_match_spec_action;
1274         }
1275
1276         ctx.type = SFC_FLOW_PARSE_CTX_MAE;
1277         ctx.mae = &ctx_mae;
1278
1279         rc = sfc_flow_parse_pattern(sfc_flow_items, RTE_DIM(sfc_flow_items),
1280                                     pattern, &ctx, error);
1281         if (rc != 0)
1282                 goto fail_parse_pattern;
1283
1284         rc = sfc_mae_rule_process_pattern_data(&ctx_mae, error);
1285         if (rc != 0)
1286                 goto fail_process_pattern_data;
1287
1288         if (!efx_mae_match_spec_is_valid(sa->nic, ctx_mae.match_spec_action)) {
1289                 rc = rte_flow_error_set(error, ENOTSUP,
1290                                         RTE_FLOW_ERROR_TYPE_ITEM, NULL,
1291                                         "Inconsistent pattern");
1292                 goto fail_validate_match_spec_action;
1293         }
1294
1295         spec->match_spec = ctx_mae.match_spec_action;
1296
1297         return 0;
1298
1299 fail_validate_match_spec_action:
1300 fail_process_pattern_data:
1301 fail_parse_pattern:
1302         efx_mae_match_spec_fini(sa->nic, ctx_mae.match_spec_action);
1303
1304 fail_init_match_spec_action:
1305         return rc;
1306 }
1307
1308 /*
1309  * An action supported by MAE may correspond to a bundle of RTE flow actions,
1310  * in example, VLAN_PUSH = OF_PUSH_VLAN + OF_VLAN_SET_VID + OF_VLAN_SET_PCP.
1311  * That is, related RTE flow actions need to be tracked as parts of a whole
1312  * so that they can be combined into a single action and submitted to MAE
1313  * representation of a given rule's action set.
1314  *
1315  * Each RTE flow action provided by an application gets classified as
1316  * one belonging to some bundle type. If an action is not supposed to
1317  * belong to any bundle, or if this action is END, it is described as
1318  * one belonging to a dummy bundle of type EMPTY.
1319  *
1320  * A currently tracked bundle will be submitted if a repeating
1321  * action or an action of different bundle type follows.
1322  */
1323
1324 enum sfc_mae_actions_bundle_type {
1325         SFC_MAE_ACTIONS_BUNDLE_EMPTY = 0,
1326         SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH,
1327 };
1328
1329 struct sfc_mae_actions_bundle {
1330         enum sfc_mae_actions_bundle_type        type;
1331
1332         /* Indicates actions already tracked by the current bundle */
1333         uint64_t                                actions_mask;
1334
1335         /* Parameters used by SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH */
1336         rte_be16_t                              vlan_push_tpid;
1337         rte_be16_t                              vlan_push_tci;
1338 };
1339
1340 /*
1341  * Combine configuration of RTE flow actions tracked by the bundle into a
1342  * single action and submit the result to MAE action set specification.
1343  * Do nothing in the case of dummy action bundle.
1344  */
1345 static int
1346 sfc_mae_actions_bundle_submit(const struct sfc_mae_actions_bundle *bundle,
1347                               efx_mae_actions_t *spec)
1348 {
1349         int rc = 0;
1350
1351         switch (bundle->type) {
1352         case SFC_MAE_ACTIONS_BUNDLE_EMPTY:
1353                 break;
1354         case SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH:
1355                 rc = efx_mae_action_set_populate_vlan_push(
1356                         spec, bundle->vlan_push_tpid, bundle->vlan_push_tci);
1357                 break;
1358         default:
1359                 SFC_ASSERT(B_FALSE);
1360                 break;
1361         }
1362
1363         return rc;
1364 }
1365
1366 /*
1367  * Given the type of the next RTE flow action in the line, decide
1368  * whether a new bundle is about to start, and, if this is the case,
1369  * submit and reset the current bundle.
1370  */
1371 static int
1372 sfc_mae_actions_bundle_sync(const struct rte_flow_action *action,
1373                             struct sfc_mae_actions_bundle *bundle,
1374                             efx_mae_actions_t *spec,
1375                             struct rte_flow_error *error)
1376 {
1377         enum sfc_mae_actions_bundle_type bundle_type_new;
1378         int rc;
1379
1380         switch (action->type) {
1381         case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
1382         case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
1383         case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
1384                 bundle_type_new = SFC_MAE_ACTIONS_BUNDLE_VLAN_PUSH;
1385                 break;
1386         default:
1387                 /*
1388                  * Self-sufficient actions, including END, are handled in this
1389                  * case. No checks for unsupported actions are needed here
1390                  * because parsing doesn't occur at this point.
1391                  */
1392                 bundle_type_new = SFC_MAE_ACTIONS_BUNDLE_EMPTY;
1393                 break;
1394         }
1395
1396         if (bundle_type_new != bundle->type ||
1397             (bundle->actions_mask & (1ULL << action->type)) != 0) {
1398                 rc = sfc_mae_actions_bundle_submit(bundle, spec);
1399                 if (rc != 0)
1400                         goto fail_submit;
1401
1402                 memset(bundle, 0, sizeof(*bundle));
1403         }
1404
1405         bundle->type = bundle_type_new;
1406
1407         return 0;
1408
1409 fail_submit:
1410         return rte_flow_error_set(error, rc,
1411                         RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1412                         "Failed to request the (group of) action(s)");
1413 }
1414
1415 static void
1416 sfc_mae_rule_parse_action_of_push_vlan(
1417                             const struct rte_flow_action_of_push_vlan *conf,
1418                             struct sfc_mae_actions_bundle *bundle)
1419 {
1420         bundle->vlan_push_tpid = conf->ethertype;
1421 }
1422
1423 static void
1424 sfc_mae_rule_parse_action_of_set_vlan_vid(
1425                             const struct rte_flow_action_of_set_vlan_vid *conf,
1426                             struct sfc_mae_actions_bundle *bundle)
1427 {
1428         bundle->vlan_push_tci |= (conf->vlan_vid &
1429                                   rte_cpu_to_be_16(RTE_LEN2MASK(12, uint16_t)));
1430 }
1431
1432 static void
1433 sfc_mae_rule_parse_action_of_set_vlan_pcp(
1434                             const struct rte_flow_action_of_set_vlan_pcp *conf,
1435                             struct sfc_mae_actions_bundle *bundle)
1436 {
1437         uint16_t vlan_tci_pcp = (uint16_t)(conf->vlan_pcp &
1438                                            RTE_LEN2MASK(3, uint8_t)) << 13;
1439
1440         bundle->vlan_push_tci |= rte_cpu_to_be_16(vlan_tci_pcp);
1441 }
1442
1443 static int
1444 sfc_mae_rule_parse_action_mark(const struct rte_flow_action_mark *conf,
1445                                efx_mae_actions_t *spec)
1446 {
1447         return efx_mae_action_set_populate_mark(spec, conf->id);
1448 }
1449
1450 static int
1451 sfc_mae_rule_parse_action_phy_port(struct sfc_adapter *sa,
1452                                    const struct rte_flow_action_phy_port *conf,
1453                                    efx_mae_actions_t *spec)
1454 {
1455         efx_mport_sel_t mport;
1456         uint32_t phy_port;
1457         int rc;
1458
1459         if (conf->original != 0)
1460                 phy_port = efx_nic_cfg_get(sa->nic)->enc_assigned_port;
1461         else
1462                 phy_port = conf->index;
1463
1464         rc = efx_mae_mport_by_phy_port(phy_port, &mport);
1465         if (rc != 0)
1466                 return rc;
1467
1468         return efx_mae_action_set_populate_deliver(spec, &mport);
1469 }
1470
1471 static int
1472 sfc_mae_rule_parse_action_pf_vf(struct sfc_adapter *sa,
1473                                 const struct rte_flow_action_vf *vf_conf,
1474                                 efx_mae_actions_t *spec)
1475 {
1476         const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
1477         efx_mport_sel_t mport;
1478         uint32_t vf;
1479         int rc;
1480
1481         if (vf_conf == NULL)
1482                 vf = EFX_PCI_VF_INVALID;
1483         else if (vf_conf->original != 0)
1484                 vf = encp->enc_vf;
1485         else
1486                 vf = vf_conf->id;
1487
1488         rc = efx_mae_mport_by_pcie_function(encp->enc_pf, vf, &mport);
1489         if (rc != 0)
1490                 return rc;
1491
1492         return efx_mae_action_set_populate_deliver(spec, &mport);
1493 }
1494
1495 static int
1496 sfc_mae_rule_parse_action_port_id(struct sfc_adapter *sa,
1497                                   const struct rte_flow_action_port_id *conf,
1498                                   efx_mae_actions_t *spec)
1499 {
1500         struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
1501         struct sfc_mae *mae = &sa->mae;
1502         efx_mport_sel_t mport;
1503         uint16_t port_id;
1504         int rc;
1505
1506         port_id = (conf->original != 0) ? sas->port_id : conf->id;
1507
1508         rc = sfc_mae_switch_port_by_ethdev(mae->switch_domain_id,
1509                                            port_id, &mport);
1510         if (rc != 0)
1511                 return rc;
1512
1513         return efx_mae_action_set_populate_deliver(spec, &mport);
1514 }
1515
1516 static int
1517 sfc_mae_rule_parse_action(struct sfc_adapter *sa,
1518                           const struct rte_flow_action *action,
1519                           struct sfc_mae_actions_bundle *bundle,
1520                           efx_mae_actions_t *spec,
1521                           struct rte_flow_error *error)
1522 {
1523         int rc = 0;
1524
1525         switch (action->type) {
1526         case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
1527                 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_POP_VLAN,
1528                                        bundle->actions_mask);
1529                 rc = efx_mae_action_set_populate_vlan_pop(spec);
1530                 break;
1531         case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
1532                 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN,
1533                                        bundle->actions_mask);
1534                 sfc_mae_rule_parse_action_of_push_vlan(action->conf, bundle);
1535                 break;
1536         case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
1537                 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID,
1538                                        bundle->actions_mask);
1539                 sfc_mae_rule_parse_action_of_set_vlan_vid(action->conf, bundle);
1540                 break;
1541         case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
1542                 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP,
1543                                        bundle->actions_mask);
1544                 sfc_mae_rule_parse_action_of_set_vlan_pcp(action->conf, bundle);
1545                 break;
1546         case RTE_FLOW_ACTION_TYPE_FLAG:
1547                 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_FLAG,
1548                                        bundle->actions_mask);
1549                 rc = efx_mae_action_set_populate_flag(spec);
1550                 break;
1551         case RTE_FLOW_ACTION_TYPE_MARK:
1552                 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_MARK,
1553                                        bundle->actions_mask);
1554                 rc = sfc_mae_rule_parse_action_mark(action->conf, spec);
1555                 break;
1556         case RTE_FLOW_ACTION_TYPE_PHY_PORT:
1557                 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_PHY_PORT,
1558                                        bundle->actions_mask);
1559                 rc = sfc_mae_rule_parse_action_phy_port(sa, action->conf, spec);
1560                 break;
1561         case RTE_FLOW_ACTION_TYPE_PF:
1562                 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_PF,
1563                                        bundle->actions_mask);
1564                 rc = sfc_mae_rule_parse_action_pf_vf(sa, NULL, spec);
1565                 break;
1566         case RTE_FLOW_ACTION_TYPE_VF:
1567                 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_VF,
1568                                        bundle->actions_mask);
1569                 rc = sfc_mae_rule_parse_action_pf_vf(sa, action->conf, spec);
1570                 break;
1571         case RTE_FLOW_ACTION_TYPE_PORT_ID:
1572                 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_PORT_ID,
1573                                        bundle->actions_mask);
1574                 rc = sfc_mae_rule_parse_action_port_id(sa, action->conf, spec);
1575                 break;
1576         case RTE_FLOW_ACTION_TYPE_DROP:
1577                 SFC_BUILD_SET_OVERFLOW(RTE_FLOW_ACTION_TYPE_DROP,
1578                                        bundle->actions_mask);
1579                 rc = efx_mae_action_set_populate_drop(spec);
1580                 break;
1581         default:
1582                 return rte_flow_error_set(error, ENOTSUP,
1583                                 RTE_FLOW_ERROR_TYPE_ACTION, NULL,
1584                                 "Unsupported action");
1585         }
1586
1587         if (rc != 0) {
1588                 rc = rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ACTION,
1589                                 NULL, "Failed to request the action");
1590         } else {
1591                 bundle->actions_mask |= (1ULL << action->type);
1592         }
1593
1594         return rc;
1595 }
1596
1597 int
1598 sfc_mae_rule_parse_actions(struct sfc_adapter *sa,
1599                            const struct rte_flow_action actions[],
1600                            struct sfc_mae_action_set **action_setp,
1601                            struct rte_flow_error *error)
1602 {
1603         struct sfc_mae_actions_bundle bundle = {0};
1604         const struct rte_flow_action *action;
1605         efx_mae_actions_t *spec;
1606         int rc;
1607
1608         if (actions == NULL) {
1609                 return rte_flow_error_set(error, EINVAL,
1610                                 RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
1611                                 "NULL actions");
1612         }
1613
1614         rc = efx_mae_action_set_spec_init(sa->nic, &spec);
1615         if (rc != 0)
1616                 goto fail_action_set_spec_init;
1617
1618         for (action = actions;
1619              action->type != RTE_FLOW_ACTION_TYPE_END; ++action) {
1620                 rc = sfc_mae_actions_bundle_sync(action, &bundle, spec, error);
1621                 if (rc != 0)
1622                         goto fail_rule_parse_action;
1623
1624                 rc = sfc_mae_rule_parse_action(sa, action, &bundle, spec,
1625                                                error);
1626                 if (rc != 0)
1627                         goto fail_rule_parse_action;
1628         }
1629
1630         rc = sfc_mae_actions_bundle_sync(action, &bundle, spec, error);
1631         if (rc != 0)
1632                 goto fail_rule_parse_action;
1633
1634         *action_setp = sfc_mae_action_set_attach(sa, spec);
1635         if (*action_setp != NULL) {
1636                 efx_mae_action_set_spec_fini(sa->nic, spec);
1637                 return 0;
1638         }
1639
1640         rc = sfc_mae_action_set_add(sa, spec, action_setp);
1641         if (rc != 0)
1642                 goto fail_action_set_add;
1643
1644         return 0;
1645
1646 fail_action_set_add:
1647 fail_rule_parse_action:
1648         efx_mae_action_set_spec_fini(sa->nic, spec);
1649
1650 fail_action_set_spec_init:
1651         if (rc > 0) {
1652                 rc = rte_flow_error_set(error, rc,
1653                         RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1654                         NULL, "Failed to process the action");
1655         }
1656         return rc;
1657 }
1658
1659 static bool
1660 sfc_mae_rules_class_cmp(struct sfc_adapter *sa,
1661                         const efx_mae_match_spec_t *left,
1662                         const efx_mae_match_spec_t *right)
1663 {
1664         bool have_same_class;
1665         int rc;
1666
1667         rc = efx_mae_match_specs_class_cmp(sa->nic, left, right,
1668                                            &have_same_class);
1669
1670         return (rc == 0) ? have_same_class : false;
1671 }
1672
1673 static int
1674 sfc_mae_action_rule_class_verify(struct sfc_adapter *sa,
1675                                  struct sfc_flow_spec_mae *spec)
1676 {
1677         const struct rte_flow *entry;
1678
1679         TAILQ_FOREACH_REVERSE(entry, &sa->flow_list, sfc_flow_list, entries) {
1680                 const struct sfc_flow_spec *entry_spec = &entry->spec;
1681                 const struct sfc_flow_spec_mae *es_mae = &entry_spec->mae;
1682                 const efx_mae_match_spec_t *left = es_mae->match_spec;
1683                 const efx_mae_match_spec_t *right = spec->match_spec;
1684
1685                 switch (entry_spec->type) {
1686                 case SFC_FLOW_SPEC_FILTER:
1687                         /* Ignore VNIC-level flows */
1688                         break;
1689                 case SFC_FLOW_SPEC_MAE:
1690                         if (sfc_mae_rules_class_cmp(sa, left, right))
1691                                 return 0;
1692                         break;
1693                 default:
1694                         SFC_ASSERT(false);
1695                 }
1696         }
1697
1698         sfc_info(sa, "for now, the HW doesn't support rule validation, and HW "
1699                  "support for inner frame pattern items is not guaranteed; "
1700                  "other than that, the items are valid from SW standpoint");
1701         return 0;
1702 }
1703
1704 /**
1705  * Confirm that a given flow can be accepted by the FW.
1706  *
1707  * @param sa
1708  *   Software adapter context
1709  * @param flow
1710  *   Flow to be verified
1711  * @return
1712  *   Zero on success and non-zero in the case of error.
1713  *   A special value of EAGAIN indicates that the adapter is
1714  *   not in started state. This state is compulsory because
1715  *   it only makes sense to compare the rule class of the flow
1716  *   being validated with classes of the active rules.
1717  *   Such classes are wittingly supported by the FW.
1718  */
1719 int
1720 sfc_mae_flow_verify(struct sfc_adapter *sa,
1721                     struct rte_flow *flow)
1722 {
1723         struct sfc_flow_spec *spec = &flow->spec;
1724         struct sfc_flow_spec_mae *spec_mae = &spec->mae;
1725
1726         SFC_ASSERT(sfc_adapter_is_locked(sa));
1727
1728         if (sa->state != SFC_ADAPTER_STARTED)
1729                 return EAGAIN;
1730
1731         return sfc_mae_action_rule_class_verify(sa, spec_mae);
1732 }
1733
1734 int
1735 sfc_mae_flow_insert(struct sfc_adapter *sa,
1736                     struct rte_flow *flow)
1737 {
1738         struct sfc_flow_spec *spec = &flow->spec;
1739         struct sfc_flow_spec_mae *spec_mae = &spec->mae;
1740         struct sfc_mae_action_set *action_set = spec_mae->action_set;
1741         struct sfc_mae_fw_rsrc *fw_rsrc = &action_set->fw_rsrc;
1742         int rc;
1743
1744         SFC_ASSERT(spec_mae->rule_id.id == EFX_MAE_RSRC_ID_INVALID);
1745         SFC_ASSERT(action_set != NULL);
1746
1747         rc = sfc_mae_action_set_enable(sa, action_set);
1748         if (rc != 0)
1749                 goto fail_action_set_enable;
1750
1751         rc = efx_mae_action_rule_insert(sa->nic, spec_mae->match_spec,
1752                                         NULL, &fw_rsrc->aset_id,
1753                                         &spec_mae->rule_id);
1754         if (rc != 0)
1755                 goto fail_action_rule_insert;
1756
1757         return 0;
1758
1759 fail_action_rule_insert:
1760         (void)sfc_mae_action_set_disable(sa, action_set);
1761
1762 fail_action_set_enable:
1763         return rc;
1764 }
1765
1766 int
1767 sfc_mae_flow_remove(struct sfc_adapter *sa,
1768                     struct rte_flow *flow)
1769 {
1770         struct sfc_flow_spec *spec = &flow->spec;
1771         struct sfc_flow_spec_mae *spec_mae = &spec->mae;
1772         struct sfc_mae_action_set *action_set = spec_mae->action_set;
1773         int rc;
1774
1775         SFC_ASSERT(spec_mae->rule_id.id != EFX_MAE_RSRC_ID_INVALID);
1776         SFC_ASSERT(action_set != NULL);
1777
1778         rc = efx_mae_action_rule_remove(sa->nic, &spec_mae->rule_id);
1779         if (rc != 0)
1780                 return rc;
1781
1782         spec_mae->rule_id.id = EFX_MAE_RSRC_ID_INVALID;
1783
1784         return sfc_mae_action_set_disable(sa, action_set);
1785 }