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_hardware_caps_get(const struct rte_cryptodev *dev,
19 union cpt_eng_caps *hw_caps)
21 struct otx2_cpt_vf *vf = dev->data->dev_private;
22 struct otx2_dev *otx2_dev = &vf->otx2_dev;
23 struct cpt_caps_rsp_msg *rsp;
26 otx2_mbox_alloc_msg_cpt_caps_get(otx2_dev->mbox);
28 ret = otx2_mbox_process_msg(otx2_dev->mbox, (void *)&rsp);
32 if (rsp->cpt_pf_drv_version != OTX2_CPT_PMD_VERSION) {
33 otx2_err("Incompatible CPT PMD version"
34 "(Kernel: 0x%04x DPDK: 0x%04x)",
35 rsp->cpt_pf_drv_version, OTX2_CPT_PMD_VERSION);
39 memcpy(hw_caps, rsp->eng_caps,
40 sizeof(union cpt_eng_caps) * CPT_MAX_ENG_TYPES);
46 otx2_cpt_available_queues_get(const struct rte_cryptodev *dev,
49 struct otx2_cpt_vf *vf = dev->data->dev_private;
50 struct otx2_dev *otx2_dev = &vf->otx2_dev;
51 struct free_rsrcs_rsp *rsp;
54 otx2_mbox_alloc_msg_free_rsrc_cnt(otx2_dev->mbox);
56 ret = otx2_mbox_process_msg(otx2_dev->mbox, (void *)&rsp);
60 *nb_queues = rsp->cpt;
65 otx2_cpt_queues_attach(const struct rte_cryptodev *dev, uint8_t nb_queues)
67 struct otx2_cpt_vf *vf = dev->data->dev_private;
68 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
69 struct rsrc_attach_req *req;
71 /* Ask AF to attach required LFs */
73 req = otx2_mbox_alloc_msg_attach_resources(mbox);
76 req->cptlfs = nb_queues;
78 if (otx2_mbox_process(mbox) < 0)
81 /* Update number of attached queues */
82 vf->nb_queues = nb_queues;
88 otx2_cpt_queues_detach(const struct rte_cryptodev *dev)
90 struct otx2_cpt_vf *vf = dev->data->dev_private;
91 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
92 struct rsrc_detach_req *req;
94 req = otx2_mbox_alloc_msg_detach_resources(mbox);
97 if (otx2_mbox_process(mbox) < 0)
100 /* Queues have been detached */
107 otx2_cpt_msix_offsets_get(const struct rte_cryptodev *dev)
109 struct otx2_cpt_vf *vf = dev->data->dev_private;
110 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
111 struct msix_offset_rsp *rsp;
114 /* Get CPT MSI-X vector offsets */
116 otx2_mbox_alloc_msg_msix_offset(mbox);
118 ret = otx2_mbox_process_msg(mbox, (void *)&rsp);
122 for (i = 0; i < vf->nb_queues; i++)
123 vf->lf_msixoff[i] = rsp->cptlf_msixoff[i];
129 otx2_cpt_send_mbox_msg(struct otx2_cpt_vf *vf)
131 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
134 otx2_mbox_msg_send(mbox, 0);
136 ret = otx2_mbox_wait_for_rsp(mbox, 0);
138 CPT_LOG_ERR("Could not get mailbox response");
146 otx2_cpt_af_reg_read(const struct rte_cryptodev *dev, uint64_t reg,
149 struct otx2_cpt_vf *vf = dev->data->dev_private;
150 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
151 struct otx2_mbox_dev *mdev = &mbox->dev[0];
152 struct cpt_rd_wr_reg_msg *msg;
155 msg = (struct cpt_rd_wr_reg_msg *)
156 otx2_mbox_alloc_msg_rsp(mbox, 0, sizeof(*msg),
159 CPT_LOG_ERR("Could not allocate mailbox message");
163 msg->hdr.id = MBOX_MSG_CPT_RD_WR_REGISTER;
164 msg->hdr.sig = OTX2_MBOX_REQ_SIG;
165 msg->hdr.pcifunc = vf->otx2_dev.pf_func;
167 msg->reg_offset = reg;
170 ret = otx2_cpt_send_mbox_msg(vf);
174 off = mbox->rx_start +
175 RTE_ALIGN(sizeof(struct mbox_hdr), MBOX_MSG_ALIGN);
176 msg = (struct cpt_rd_wr_reg_msg *) ((uintptr_t)mdev->mbase + off);
184 otx2_cpt_af_reg_write(const struct rte_cryptodev *dev, uint64_t reg,
187 struct otx2_cpt_vf *vf = dev->data->dev_private;
188 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
189 struct cpt_rd_wr_reg_msg *msg;
191 msg = (struct cpt_rd_wr_reg_msg *)
192 otx2_mbox_alloc_msg_rsp(mbox, 0, sizeof(*msg),
195 CPT_LOG_ERR("Could not allocate mailbox message");
199 msg->hdr.id = MBOX_MSG_CPT_RD_WR_REGISTER;
200 msg->hdr.sig = OTX2_MBOX_REQ_SIG;
201 msg->hdr.pcifunc = vf->otx2_dev.pf_func;
203 msg->reg_offset = reg;
206 return otx2_cpt_send_mbox_msg(vf);
210 otx2_cpt_inline_init(const struct rte_cryptodev *dev)
212 struct otx2_cpt_vf *vf = dev->data->dev_private;
213 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
214 struct cpt_rx_inline_lf_cfg_msg *msg;
217 msg = otx2_mbox_alloc_msg_cpt_rx_inline_lf_cfg(mbox);
218 msg->sso_pf_func = otx2_sso_pf_func_get();
220 otx2_mbox_msg_send(mbox, 0);
221 ret = otx2_mbox_process(mbox);
229 otx2_cpt_qp_ethdev_bind(const struct rte_cryptodev *dev, struct otx2_cpt_qp *qp,
232 struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
233 struct otx2_cpt_vf *vf = dev->data->dev_private;
234 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
235 struct cpt_inline_ipsec_cfg_msg *msg;
236 struct otx2_eth_dev *otx2_eth_dev;
239 if (!otx2_eth_dev_is_sec_capable(&rte_eth_devices[port_id]))
242 otx2_eth_dev = otx2_eth_pmd_priv(eth_dev);
244 msg = otx2_mbox_alloc_msg_cpt_inline_ipsec_cfg(mbox);
245 msg->dir = CPT_INLINE_OUTBOUND;
249 msg->nix_pf_func = otx2_eth_dev->pf_func;
251 otx2_mbox_msg_send(mbox, 0);
252 ret = otx2_mbox_process(mbox);