1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2021 Marvell.
5 #include <rte_cryptodev.h>
6 #include <rte_cryptodev_pmd.h>
8 #include "cn10k_cryptodev.h"
9 #include "cn10k_cryptodev_ops.h"
10 #include "cnxk_cryptodev.h"
11 #include "cnxk_cryptodev_ops.h"
14 static inline struct cnxk_se_sess *
15 cn10k_cpt_sym_temp_sess_create(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op)
17 const int driver_id = cn10k_cryptodev_driver_id;
18 struct rte_crypto_sym_op *sym_op = op->sym;
19 struct rte_cryptodev_sym_session *sess;
20 struct cnxk_se_sess *priv;
23 /* Create temporary session */
24 sess = rte_cryptodev_sym_session_create(qp->sess_mp);
28 ret = sym_session_configure(qp->lf.roc_cpt, driver_id, sym_op->xform,
29 sess, qp->sess_mp_priv);
33 priv = get_sym_session_private_data(sess, driver_id);
35 sym_op->session = sess;
40 rte_mempool_put(qp->sess_mp, sess);
44 static __rte_always_inline int __rte_hot
45 cpt_sym_inst_fill(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op,
46 struct cnxk_se_sess *sess, struct cpt_inflight_req *infl_req,
47 struct cpt_inst_s *inst)
52 cpt_op = sess->cpt_op;
54 if (cpt_op & ROC_SE_OP_CIPHER_MASK)
55 ret = fill_fc_params(op, sess, &qp->meta_info, infl_req, inst);
61 cn10k_cpt_fill_inst(struct cnxk_cpt_qp *qp, struct rte_crypto_op *ops[],
62 struct cpt_inst_s inst[], struct cpt_inflight_req *infl_req)
64 struct rte_crypto_sym_op *sym_op;
65 struct cnxk_se_sess *sess;
66 struct rte_crypto_op *op;
78 if (op->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
79 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
80 sess = get_sym_session_private_data(
81 sym_op->session, cn10k_cryptodev_driver_id);
82 ret = cpt_sym_inst_fill(qp, op, sess, infl_req,
86 w7 = sess->cpt_inst_w7;
88 sess = cn10k_cpt_sym_temp_sess_create(qp, op);
89 if (unlikely(sess == NULL)) {
90 plt_dp_err("Could not create temp session");
94 ret = cpt_sym_inst_fill(qp, op, sess, infl_req,
97 sym_session_clear(cn10k_cryptodev_driver_id,
99 rte_mempool_put(qp->sess_mp, op->sym->session);
102 w7 = sess->cpt_inst_w7;
105 plt_dp_err("Unsupported op type");
109 inst[0].res_addr = (uint64_t)&infl_req->res;
110 infl_req->res.cn10k.compcode = CPT_COMP_NOT_DONE;
118 #define PKTS_PER_LOOP 32
119 #define PKTS_PER_STEORL 16
122 cn10k_cpt_enqueue_burst(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
124 uint64_t lmt_base, lmt_arg, io_addr;
125 struct cpt_inflight_req *infl_req;
126 uint16_t nb_allowed, count = 0;
127 struct cnxk_cpt_qp *qp = qptr;
128 struct pending_queue *pend_q;
129 struct cpt_inst_s *inst;
133 pend_q = &qp->pend_q;
135 nb_allowed = qp->lf.nb_desc - pend_q->pending_count;
136 nb_ops = RTE_MIN(nb_ops, nb_allowed);
138 if (unlikely(nb_ops == 0))
141 lmt_base = qp->lmtline.lmt_base;
142 io_addr = qp->lmtline.io_addr;
144 ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
145 inst = (struct cpt_inst_s *)lmt_base;
148 for (i = 0; i < RTE_MIN(PKTS_PER_LOOP, nb_ops); i++) {
149 infl_req = &pend_q->req_queue[pend_q->enq_tail];
150 infl_req->op_flags = 0;
152 ret = cn10k_cpt_fill_inst(qp, ops + i, &inst[2 * i], infl_req);
153 if (unlikely(ret != 1)) {
154 plt_dp_err("Could not process op: %p", ops + i);
160 MOD_INC(pend_q->enq_tail, qp->lf.nb_desc);
163 if (i > PKTS_PER_STEORL) {
164 lmt_arg = ROC_CN10K_CPT_LMT_ARG | (PKTS_PER_STEORL - 1) << 12 |
166 roc_lmt_submit_steorl(lmt_arg, io_addr);
167 lmt_arg = ROC_CN10K_CPT_LMT_ARG |
168 (i - PKTS_PER_STEORL - 1) << 12 |
169 (uint64_t)(lmt_id + PKTS_PER_STEORL);
170 roc_lmt_submit_steorl(lmt_arg, io_addr);
172 lmt_arg = ROC_CN10K_CPT_LMT_ARG | (i - 1) << 12 |
174 roc_lmt_submit_steorl(lmt_arg, io_addr);
179 if (nb_ops - i > 0 && i == PKTS_PER_LOOP) {
187 pend_q->pending_count += count + i;
189 pend_q->time_out = rte_get_timer_cycles() +
190 DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
196 cn10k_cpt_dequeue_post_process(struct cnxk_cpt_qp *qp,
197 struct rte_crypto_op *cop,
198 struct cpt_inflight_req *infl_req)
200 struct cpt_cn10k_res_s *res = (struct cpt_cn10k_res_s *)&infl_req->res;
203 if (likely(res->compcode == CPT_COMP_GOOD ||
204 res->compcode == CPT_COMP_WARN)) {
205 if (unlikely(res->uc_compcode)) {
206 cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
208 plt_dp_info("Request failed with microcode error");
209 plt_dp_info("MC completion code 0x%x",
214 cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
216 cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
217 plt_dp_info("HW completion code 0x%x", res->compcode);
219 switch (res->compcode) {
220 case CPT_COMP_INSTERR:
221 plt_dp_err("Request failed with instruction error");
224 plt_dp_err("Request failed with DMA fault");
227 plt_dp_err("Request failed with hardware error");
231 "Request failed with unknown completion code");
236 if (unlikely(cop->sess_type == RTE_CRYPTO_OP_SESSIONLESS)) {
237 if (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
238 sym_session_clear(cn10k_cryptodev_driver_id,
240 sz = rte_cryptodev_sym_get_existing_header_session_size(
242 memset(cop->sym->session, 0, sz);
243 rte_mempool_put(qp->sess_mp, cop->sym->session);
244 cop->sym->session = NULL;
250 cn10k_cpt_dequeue_burst(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
252 struct cpt_inflight_req *infl_req;
253 struct cnxk_cpt_qp *qp = qptr;
254 struct pending_queue *pend_q;
255 struct cpt_cn10k_res_s *res;
256 struct rte_crypto_op *cop;
259 pend_q = &qp->pend_q;
261 nb_pending = pend_q->pending_count;
263 if (nb_ops > nb_pending)
266 for (i = 0; i < nb_ops; i++) {
267 infl_req = &pend_q->req_queue[pend_q->deq_head];
269 res = (struct cpt_cn10k_res_s *)&infl_req->res;
271 if (unlikely(res->compcode == CPT_COMP_NOT_DONE)) {
272 if (unlikely(rte_get_timer_cycles() >
274 plt_err("Request timed out");
275 pend_q->time_out = rte_get_timer_cycles() +
276 DEFAULT_COMMAND_TIMEOUT *
282 MOD_INC(pend_q->deq_head, qp->lf.nb_desc);
288 cn10k_cpt_dequeue_post_process(qp, cop, infl_req);
290 if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
291 rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
294 pend_q->pending_count -= i;
300 cn10k_cpt_set_enqdeq_fns(struct rte_cryptodev *dev)
302 dev->enqueue_burst = cn10k_cpt_enqueue_burst;
303 dev->dequeue_burst = cn10k_cpt_dequeue_burst;
309 cn10k_cpt_dev_info_get(struct rte_cryptodev *dev,
310 struct rte_cryptodev_info *info)
313 cnxk_cpt_dev_info_get(dev, info);
314 info->driver_id = cn10k_cryptodev_driver_id;
318 struct rte_cryptodev_ops cn10k_cpt_ops = {
319 /* Device control ops */
320 .dev_configure = cnxk_cpt_dev_config,
321 .dev_start = cnxk_cpt_dev_start,
322 .dev_stop = cnxk_cpt_dev_stop,
323 .dev_close = cnxk_cpt_dev_close,
324 .dev_infos_get = cn10k_cpt_dev_info_get,
328 .queue_pair_setup = cnxk_cpt_queue_pair_setup,
329 .queue_pair_release = cnxk_cpt_queue_pair_release,
331 /* Symmetric crypto ops */
332 .sym_session_get_size = cnxk_cpt_sym_session_get_size,
333 .sym_session_configure = cnxk_cpt_sym_session_configure,
334 .sym_session_clear = cnxk_cpt_sym_session_clear,
336 /* Asymmetric crypto ops */
337 .asym_session_get_size = NULL,
338 .asym_session_configure = NULL,
339 .asym_session_clear = NULL,