1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (C) 2019 Marvell International Ltd.
4 #include <rte_cryptodev.h>
5 #include <rte_ethdev.h>
7 #include "otx2_cryptodev.h"
8 #include "otx2_cryptodev_hw_access.h"
9 #include "otx2_cryptodev_mbox.h"
11 #include "otx2_ethdev.h"
12 #include "otx2_sec_idev.h"
13 #include "otx2_mbox.h"
15 #include "cpt_pmd_logs.h"
18 otx2_cpt_available_queues_get(const struct rte_cryptodev *dev,
21 struct otx2_cpt_vf *vf = dev->data->dev_private;
22 struct otx2_dev *otx2_dev = &vf->otx2_dev;
23 struct free_rsrcs_rsp *rsp;
26 otx2_mbox_alloc_msg_free_rsrc_cnt(otx2_dev->mbox);
28 ret = otx2_mbox_process_msg(otx2_dev->mbox, (void *)&rsp);
32 *nb_queues = rsp->cpt;
37 otx2_cpt_queues_attach(const struct rte_cryptodev *dev, uint8_t nb_queues)
39 struct otx2_cpt_vf *vf = dev->data->dev_private;
40 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
41 struct rsrc_attach_req *req;
43 /* Ask AF to attach required LFs */
45 req = otx2_mbox_alloc_msg_attach_resources(mbox);
48 req->cptlfs = nb_queues;
50 if (otx2_mbox_process(mbox) < 0)
53 /* Update number of attached queues */
54 vf->nb_queues = nb_queues;
60 otx2_cpt_queues_detach(const struct rte_cryptodev *dev)
62 struct otx2_cpt_vf *vf = dev->data->dev_private;
63 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
64 struct rsrc_detach_req *req;
66 req = otx2_mbox_alloc_msg_detach_resources(mbox);
69 if (otx2_mbox_process(mbox) < 0)
72 /* Queues have been detached */
79 otx2_cpt_msix_offsets_get(const struct rte_cryptodev *dev)
81 struct otx2_cpt_vf *vf = dev->data->dev_private;
82 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
83 struct msix_offset_rsp *rsp;
86 /* Get CPT MSI-X vector offsets */
88 otx2_mbox_alloc_msg_msix_offset(mbox);
90 ret = otx2_mbox_process_msg(mbox, (void *)&rsp);
94 for (i = 0; i < vf->nb_queues; i++)
95 vf->lf_msixoff[i] = rsp->cptlf_msixoff[i];
101 otx2_cpt_send_mbox_msg(struct otx2_cpt_vf *vf)
103 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
106 otx2_mbox_msg_send(mbox, 0);
108 ret = otx2_mbox_wait_for_rsp(mbox, 0);
110 CPT_LOG_ERR("Could not get mailbox response");
118 otx2_cpt_af_reg_read(const struct rte_cryptodev *dev, uint64_t reg,
121 struct otx2_cpt_vf *vf = dev->data->dev_private;
122 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
123 struct otx2_mbox_dev *mdev = &mbox->dev[0];
124 struct cpt_rd_wr_reg_msg *msg;
127 msg = (struct cpt_rd_wr_reg_msg *)
128 otx2_mbox_alloc_msg_rsp(mbox, 0, sizeof(*msg),
131 CPT_LOG_ERR("Could not allocate mailbox message");
135 msg->hdr.id = MBOX_MSG_CPT_RD_WR_REGISTER;
136 msg->hdr.sig = OTX2_MBOX_REQ_SIG;
137 msg->hdr.pcifunc = vf->otx2_dev.pf_func;
139 msg->reg_offset = reg;
142 ret = otx2_cpt_send_mbox_msg(vf);
146 off = mbox->rx_start +
147 RTE_ALIGN(sizeof(struct mbox_hdr), MBOX_MSG_ALIGN);
148 msg = (struct cpt_rd_wr_reg_msg *) ((uintptr_t)mdev->mbase + off);
156 otx2_cpt_af_reg_write(const struct rte_cryptodev *dev, uint64_t reg,
159 struct otx2_cpt_vf *vf = dev->data->dev_private;
160 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
161 struct cpt_rd_wr_reg_msg *msg;
163 msg = (struct cpt_rd_wr_reg_msg *)
164 otx2_mbox_alloc_msg_rsp(mbox, 0, sizeof(*msg),
167 CPT_LOG_ERR("Could not allocate mailbox message");
171 msg->hdr.id = MBOX_MSG_CPT_RD_WR_REGISTER;
172 msg->hdr.sig = OTX2_MBOX_REQ_SIG;
173 msg->hdr.pcifunc = vf->otx2_dev.pf_func;
175 msg->reg_offset = reg;
178 return otx2_cpt_send_mbox_msg(vf);
182 otx2_cpt_inline_init(const struct rte_cryptodev *dev)
184 struct otx2_cpt_vf *vf = dev->data->dev_private;
185 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
186 struct cpt_rx_inline_lf_cfg_msg *msg;
189 msg = otx2_mbox_alloc_msg_cpt_rx_inline_lf_cfg(mbox);
190 msg->sso_pf_func = otx2_sso_pf_func_get();
192 otx2_mbox_msg_send(mbox, 0);
193 ret = otx2_mbox_process(mbox);
201 otx2_cpt_qp_ethdev_bind(const struct rte_cryptodev *dev, struct otx2_cpt_qp *qp,
204 struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
205 struct otx2_cpt_vf *vf = dev->data->dev_private;
206 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
207 struct cpt_inline_ipsec_cfg_msg *msg;
208 struct otx2_eth_dev *otx2_eth_dev;
211 if (!otx2_eth_dev_is_sec_capable(&rte_eth_devices[port_id]))
214 otx2_eth_dev = otx2_eth_pmd_priv(eth_dev);
216 msg = otx2_mbox_alloc_msg_cpt_inline_ipsec_cfg(mbox);
217 msg->dir = CPT_INLINE_OUTBOUND;
221 msg->nix_pf_func = otx2_eth_dev->pf_func;
223 otx2_mbox_msg_send(mbox, 0);
224 ret = otx2_mbox_process(mbox);