common/sfc_efx/base: add MAE limit query API
[dpdk.git] / drivers / common / sfc_efx / base / efx_mae.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2019 Xilinx, Inc. All rights reserved.
4  * All rights reserved.
5  */
6
7 #include "efx.h"
8 #include "efx_impl.h"
9
10
11 #if EFSYS_OPT_MAE
12
13 static  __checkReturn                   efx_rc_t
14 efx_mae_get_capabilities(
15         __in                            efx_nic_t *enp)
16 {
17         efx_mcdi_req_t req;
18         EFX_MCDI_DECLARE_BUF(payload,
19             MC_CMD_MAE_GET_CAPS_IN_LEN,
20             MC_CMD_MAE_GET_CAPS_OUT_LEN);
21         struct efx_mae_s *maep = enp->en_maep;
22         efx_rc_t rc;
23
24         req.emr_cmd = MC_CMD_MAE_GET_CAPS;
25         req.emr_in_buf = payload;
26         req.emr_in_length = MC_CMD_MAE_GET_CAPS_IN_LEN;
27         req.emr_out_buf = payload;
28         req.emr_out_length = MC_CMD_MAE_GET_CAPS_OUT_LEN;
29
30         efx_mcdi_execute(enp, &req);
31
32         if (req.emr_rc != 0) {
33                 rc = req.emr_rc;
34                 goto fail1;
35         }
36
37         if (req.emr_out_length_used < MC_CMD_MAE_GET_CAPS_OUT_LEN) {
38                 rc = EMSGSIZE;
39                 goto fail2;
40         }
41
42         maep->em_max_n_action_prios =
43             MCDI_OUT_DWORD(req, MAE_GET_CAPS_OUT_ACTION_PRIOS);
44
45         return (0);
46
47 fail2:
48         EFSYS_PROBE(fail2);
49 fail1:
50         EFSYS_PROBE1(fail1, efx_rc_t, rc);
51         return (rc);
52 }
53
54         __checkReturn                   efx_rc_t
55 efx_mae_init(
56         __in                            efx_nic_t *enp)
57 {
58         const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
59         efx_mae_t *maep;
60         efx_rc_t rc;
61
62         if (encp->enc_mae_supported == B_FALSE) {
63                 rc = ENOTSUP;
64                 goto fail1;
65         }
66
67         EFSYS_KMEM_ALLOC(enp->en_esip, sizeof (*maep), maep);
68         if (maep == NULL) {
69                 rc = ENOMEM;
70                 goto fail2;
71         }
72
73         enp->en_maep = maep;
74
75         rc = efx_mae_get_capabilities(enp);
76         if (rc != 0)
77                 goto fail3;
78
79         return (0);
80
81 fail3:
82         EFSYS_PROBE(fail3);
83         EFSYS_KMEM_FREE(enp->en_esip, sizeof (struct efx_mae_s), enp->en_maep);
84         enp->en_maep = NULL;
85 fail2:
86         EFSYS_PROBE(fail2);
87 fail1:
88         EFSYS_PROBE1(fail1, efx_rc_t, rc);
89         return (rc);
90 }
91
92                                         void
93 efx_mae_fini(
94         __in                            efx_nic_t *enp)
95 {
96         const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
97         efx_mae_t *maep = enp->en_maep;
98
99         if (encp->enc_mae_supported == B_FALSE)
100                 return;
101
102         EFSYS_KMEM_FREE(enp->en_esip, sizeof (*maep), maep);
103         enp->en_maep = NULL;
104 }
105
106         __checkReturn                   efx_rc_t
107 efx_mae_get_limits(
108         __in                            efx_nic_t *enp,
109         __out                           efx_mae_limits_t *emlp)
110 {
111         const efx_nic_cfg_t *encp = efx_nic_cfg_get(enp);
112         struct efx_mae_s *maep = enp->en_maep;
113         efx_rc_t rc;
114
115         if (encp->enc_mae_supported == B_FALSE) {
116                 rc = ENOTSUP;
117                 goto fail1;
118         }
119
120         emlp->eml_max_n_action_prios = maep->em_max_n_action_prios;
121
122         return (0);
123
124 fail1:
125         EFSYS_PROBE1(fail1, efx_rc_t, rc);
126         return (rc);
127 }
128
129 #endif /* EFSYS_OPT_MAE */