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 memcpy(hw_caps, rsp->eng_caps,
33 sizeof(union cpt_eng_caps) * CPT_MAX_ENG_TYPES);
39 otx2_cpt_available_queues_get(const struct rte_cryptodev *dev,
42 struct otx2_cpt_vf *vf = dev->data->dev_private;
43 struct otx2_dev *otx2_dev = &vf->otx2_dev;
44 struct free_rsrcs_rsp *rsp;
47 otx2_mbox_alloc_msg_free_rsrc_cnt(otx2_dev->mbox);
49 ret = otx2_mbox_process_msg(otx2_dev->mbox, (void *)&rsp);
53 *nb_queues = rsp->cpt;
58 otx2_cpt_queues_attach(const struct rte_cryptodev *dev, uint8_t nb_queues)
60 struct otx2_cpt_vf *vf = dev->data->dev_private;
61 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
62 struct rsrc_attach_req *req;
64 /* Ask AF to attach required LFs */
66 req = otx2_mbox_alloc_msg_attach_resources(mbox);
69 req->cptlfs = nb_queues;
71 if (otx2_mbox_process(mbox) < 0)
74 /* Update number of attached queues */
75 vf->nb_queues = nb_queues;
81 otx2_cpt_queues_detach(const struct rte_cryptodev *dev)
83 struct otx2_cpt_vf *vf = dev->data->dev_private;
84 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
85 struct rsrc_detach_req *req;
87 req = otx2_mbox_alloc_msg_detach_resources(mbox);
90 if (otx2_mbox_process(mbox) < 0)
93 /* Queues have been detached */
100 otx2_cpt_msix_offsets_get(const struct rte_cryptodev *dev)
102 struct otx2_cpt_vf *vf = dev->data->dev_private;
103 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
104 struct msix_offset_rsp *rsp;
107 /* Get CPT MSI-X vector offsets */
109 otx2_mbox_alloc_msg_msix_offset(mbox);
111 ret = otx2_mbox_process_msg(mbox, (void *)&rsp);
115 for (i = 0; i < vf->nb_queues; i++)
116 vf->lf_msixoff[i] = rsp->cptlf_msixoff[i];
122 otx2_cpt_send_mbox_msg(struct otx2_cpt_vf *vf)
124 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
127 otx2_mbox_msg_send(mbox, 0);
129 ret = otx2_mbox_wait_for_rsp(mbox, 0);
131 CPT_LOG_ERR("Could not get mailbox response");
139 otx2_cpt_af_reg_read(const struct rte_cryptodev *dev, uint64_t reg,
142 struct otx2_cpt_vf *vf = dev->data->dev_private;
143 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
144 struct otx2_mbox_dev *mdev = &mbox->dev[0];
145 struct cpt_rd_wr_reg_msg *msg;
148 msg = (struct cpt_rd_wr_reg_msg *)
149 otx2_mbox_alloc_msg_rsp(mbox, 0, sizeof(*msg),
152 CPT_LOG_ERR("Could not allocate mailbox message");
156 msg->hdr.id = MBOX_MSG_CPT_RD_WR_REGISTER;
157 msg->hdr.sig = OTX2_MBOX_REQ_SIG;
158 msg->hdr.pcifunc = vf->otx2_dev.pf_func;
160 msg->reg_offset = reg;
163 ret = otx2_cpt_send_mbox_msg(vf);
167 off = mbox->rx_start +
168 RTE_ALIGN(sizeof(struct mbox_hdr), MBOX_MSG_ALIGN);
169 msg = (struct cpt_rd_wr_reg_msg *) ((uintptr_t)mdev->mbase + off);
177 otx2_cpt_af_reg_write(const struct rte_cryptodev *dev, uint64_t reg,
180 struct otx2_cpt_vf *vf = dev->data->dev_private;
181 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
182 struct cpt_rd_wr_reg_msg *msg;
184 msg = (struct cpt_rd_wr_reg_msg *)
185 otx2_mbox_alloc_msg_rsp(mbox, 0, sizeof(*msg),
188 CPT_LOG_ERR("Could not allocate mailbox message");
192 msg->hdr.id = MBOX_MSG_CPT_RD_WR_REGISTER;
193 msg->hdr.sig = OTX2_MBOX_REQ_SIG;
194 msg->hdr.pcifunc = vf->otx2_dev.pf_func;
196 msg->reg_offset = reg;
199 return otx2_cpt_send_mbox_msg(vf);
203 otx2_cpt_inline_init(const struct rte_cryptodev *dev)
205 struct otx2_cpt_vf *vf = dev->data->dev_private;
206 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
207 struct cpt_rx_inline_lf_cfg_msg *msg;
210 msg = otx2_mbox_alloc_msg_cpt_rx_inline_lf_cfg(mbox);
211 msg->sso_pf_func = otx2_sso_pf_func_get();
213 otx2_mbox_msg_send(mbox, 0);
214 ret = otx2_mbox_process(mbox);
222 otx2_cpt_qp_ethdev_bind(const struct rte_cryptodev *dev, struct otx2_cpt_qp *qp,
225 struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id];
226 struct otx2_cpt_vf *vf = dev->data->dev_private;
227 struct otx2_mbox *mbox = vf->otx2_dev.mbox;
228 struct cpt_inline_ipsec_cfg_msg *msg;
229 struct otx2_eth_dev *otx2_eth_dev;
232 if (!otx2_eth_dev_is_sec_capable(&rte_eth_devices[port_id]))
235 otx2_eth_dev = otx2_eth_pmd_priv(eth_dev);
237 msg = otx2_mbox_alloc_msg_cpt_inline_ipsec_cfg(mbox);
238 msg->dir = CPT_INLINE_OUTBOUND;
242 msg->nix_pf_func = otx2_eth_dev->pf_func;
244 otx2_mbox_msg_send(mbox, 0);
245 ret = otx2_mbox_process(mbox);