net/sfc: add concept of MAE (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
19 int
20 sfc_mae_attach(struct sfc_adapter *sa)
21 {
22         const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
23         struct sfc_mae *mae = &sa->mae;
24         efx_mae_limits_t limits;
25         int rc;
26
27         sfc_log_init(sa, "entry");
28
29         if (!encp->enc_mae_supported) {
30                 mae->status = SFC_MAE_STATUS_UNSUPPORTED;
31                 return 0;
32         }
33
34         sfc_log_init(sa, "init MAE");
35         rc = efx_mae_init(sa->nic);
36         if (rc != 0)
37                 goto fail_mae_init;
38
39         sfc_log_init(sa, "get MAE limits");
40         rc = efx_mae_get_limits(sa->nic, &limits);
41         if (rc != 0)
42                 goto fail_mae_get_limits;
43
44         mae->status = SFC_MAE_STATUS_SUPPORTED;
45         mae->nb_action_rule_prios_max = limits.eml_max_n_action_prios;
46
47         sfc_log_init(sa, "done");
48
49         return 0;
50
51 fail_mae_get_limits:
52         efx_mae_fini(sa->nic);
53
54 fail_mae_init:
55         sfc_log_init(sa, "failed %d", rc);
56
57         return rc;
58 }
59
60 void
61 sfc_mae_detach(struct sfc_adapter *sa)
62 {
63         struct sfc_mae *mae = &sa->mae;
64         enum sfc_mae_status status_prev = mae->status;
65
66         sfc_log_init(sa, "entry");
67
68         mae->nb_action_rule_prios_max = 0;
69         mae->status = SFC_MAE_STATUS_UNKNOWN;
70
71         if (status_prev != SFC_MAE_STATUS_SUPPORTED)
72                 return;
73
74         efx_mae_fini(sa->nic);
75
76         sfc_log_init(sa, "done");
77 }