crypto/octeontx2: support control ops
[dpdk.git] / drivers / crypto / octeontx2 / otx2_cryptodev_mbox.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (C) 2019 Marvell International Ltd.
3  */
4 #include <rte_cryptodev.h>
5
6 #include "otx2_cryptodev.h"
7 #include "otx2_cryptodev_mbox.h"
8 #include "otx2_dev.h"
9 #include "otx2_mbox.h"
10
11 int
12 otx2_cpt_available_queues_get(const struct rte_cryptodev *dev,
13                               uint16_t *nb_queues)
14 {
15         struct otx2_cpt_vf *vf = dev->data->dev_private;
16         struct otx2_dev *otx2_dev = &vf->otx2_dev;
17         struct free_rsrcs_rsp *rsp;
18         int ret;
19
20         otx2_mbox_alloc_msg_free_rsrc_cnt(otx2_dev->mbox);
21
22         ret = otx2_mbox_process_msg(otx2_dev->mbox, (void *)&rsp);
23         if (ret)
24                 return -EIO;
25
26         *nb_queues = rsp->cpt;
27         return 0;
28 }
29
30 int
31 otx2_cpt_queues_attach(const struct rte_cryptodev *dev, uint8_t nb_queues)
32 {
33         struct otx2_cpt_vf *vf = dev->data->dev_private;
34         struct otx2_mbox *mbox = vf->otx2_dev.mbox;
35         struct rsrc_attach_req *req;
36
37         /* Ask AF to attach required LFs */
38
39         req = otx2_mbox_alloc_msg_attach_resources(mbox);
40
41         /* 1 LF = 1 queue */
42         req->cptlfs = nb_queues;
43
44         if (otx2_mbox_process(mbox) < 0)
45                 return -EIO;
46
47         /* Update number of attached queues */
48         vf->nb_queues = nb_queues;
49
50         return 0;
51 }
52
53 int
54 otx2_cpt_queues_detach(const struct rte_cryptodev *dev)
55 {
56         struct otx2_cpt_vf *vf = dev->data->dev_private;
57         struct otx2_mbox *mbox = vf->otx2_dev.mbox;
58         struct rsrc_detach_req *req;
59
60         req = otx2_mbox_alloc_msg_detach_resources(mbox);
61         req->cptlfs = true;
62         req->partial = true;
63         if (otx2_mbox_process(mbox) < 0)
64                 return -EIO;
65
66         /* Queues have been detached */
67         vf->nb_queues = 0;
68
69         return 0;
70 }
71
72 int
73 otx2_cpt_msix_offsets_get(const struct rte_cryptodev *dev)
74 {
75         struct otx2_cpt_vf *vf = dev->data->dev_private;
76         struct otx2_mbox *mbox = vf->otx2_dev.mbox;
77         struct msix_offset_rsp *rsp;
78         uint32_t i, ret;
79
80         /* Get CPT MSI-X vector offsets */
81
82         otx2_mbox_alloc_msg_msix_offset(mbox);
83
84         ret = otx2_mbox_process_msg(mbox, (void *)&rsp);
85         if (ret)
86                 return ret;
87
88         for (i = 0; i < vf->nb_queues; i++)
89                 vf->lf_msixoff[i] = rsp->cptlf_msixoff[i];
90
91         return 0;
92 }