1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (C) 2019 Marvell International Ltd.
4 #include <rte_cryptodev.h>
6 #include "otx2_cryptodev.h"
7 #include "otx2_cryptodev_mbox.h"
11 #include "cpt_pmd_logs.h"
14 otx2_cpt_available_queues_get(const struct rte_cryptodev *dev,
17 struct otx2_cpt_vf *vf = dev->data->dev_private;
18 struct otx2_dev *otx2_dev = &vf->otx2_dev;
19 struct free_rsrcs_rsp *rsp;
22 otx2_mbox_alloc_msg_free_rsrc_cnt(otx2_dev->mbox);
24 ret = otx2_mbox_process_msg(otx2_dev->mbox, (void *)&rsp);
28 *nb_queues = rsp->cpt;
33 otx2_cpt_queues_attach(const struct rte_cryptodev *dev, uint8_t nb_queues)
35 struct otx2_cpt_vf *vf = dev->data->dev_private;
36 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
37 struct rsrc_attach_req *req;
39 /* Ask AF to attach required LFs */
41 req = otx2_mbox_alloc_msg_attach_resources(mbox);
44 req->cptlfs = nb_queues;
46 if (otx2_mbox_process(mbox) < 0)
49 /* Update number of attached queues */
50 vf->nb_queues = nb_queues;
56 otx2_cpt_queues_detach(const struct rte_cryptodev *dev)
58 struct otx2_cpt_vf *vf = dev->data->dev_private;
59 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
60 struct rsrc_detach_req *req;
62 req = otx2_mbox_alloc_msg_detach_resources(mbox);
65 if (otx2_mbox_process(mbox) < 0)
68 /* Queues have been detached */
75 otx2_cpt_msix_offsets_get(const struct rte_cryptodev *dev)
77 struct otx2_cpt_vf *vf = dev->data->dev_private;
78 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
79 struct msix_offset_rsp *rsp;
82 /* Get CPT MSI-X vector offsets */
84 otx2_mbox_alloc_msg_msix_offset(mbox);
86 ret = otx2_mbox_process_msg(mbox, (void *)&rsp);
90 for (i = 0; i < vf->nb_queues; i++)
91 vf->lf_msixoff[i] = rsp->cptlf_msixoff[i];
97 otx2_cpt_send_mbox_msg(struct otx2_cpt_vf *vf)
99 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
102 otx2_mbox_msg_send(mbox, 0);
104 ret = otx2_mbox_wait_for_rsp(mbox, 0);
106 CPT_LOG_ERR("Could not get mailbox response");
114 otx2_cpt_af_reg_read(const struct rte_cryptodev *dev, uint64_t reg,
117 struct otx2_cpt_vf *vf = dev->data->dev_private;
118 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
119 struct otx2_mbox_dev *mdev = &mbox->dev[0];
120 struct cpt_rd_wr_reg_msg *msg;
123 msg = (struct cpt_rd_wr_reg_msg *)
124 otx2_mbox_alloc_msg_rsp(mbox, 0, sizeof(*msg),
127 CPT_LOG_ERR("Could not allocate mailbox message");
131 msg->hdr.id = MBOX_MSG_CPT_RD_WR_REGISTER;
132 msg->hdr.sig = OTX2_MBOX_REQ_SIG;
133 msg->hdr.pcifunc = vf->otx2_dev.pf_func;
135 msg->reg_offset = reg;
138 ret = otx2_cpt_send_mbox_msg(vf);
142 off = mbox->rx_start +
143 RTE_ALIGN(sizeof(struct mbox_hdr), MBOX_MSG_ALIGN);
144 msg = (struct cpt_rd_wr_reg_msg *) ((uintptr_t)mdev->mbase + off);
152 otx2_cpt_af_reg_write(const struct rte_cryptodev *dev, uint64_t reg,
155 struct otx2_cpt_vf *vf = dev->data->dev_private;
156 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
157 struct cpt_rd_wr_reg_msg *msg;
159 msg = (struct cpt_rd_wr_reg_msg *)
160 otx2_mbox_alloc_msg_rsp(mbox, 0, sizeof(*msg),
163 CPT_LOG_ERR("Could not allocate mailbox message");
167 msg->hdr.id = MBOX_MSG_CPT_RD_WR_REGISTER;
168 msg->hdr.sig = OTX2_MBOX_REQ_SIG;
169 msg->hdr.pcifunc = vf->otx2_dev.pf_func;
171 msg->reg_offset = reg;
174 return otx2_cpt_send_mbox_msg(vf);