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 RTE_SET_USED(infl_req);
59 cn10k_cpt_fill_inst(struct cnxk_cpt_qp *qp, struct rte_crypto_op *ops[],
60 struct cpt_inst_s inst[], struct cpt_inflight_req *infl_req)
62 struct rte_crypto_sym_op *sym_op;
63 struct cnxk_se_sess *sess;
64 struct rte_crypto_op *op;
76 if (op->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
77 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
78 sess = get_sym_session_private_data(
79 sym_op->session, cn10k_cryptodev_driver_id);
80 ret = cpt_sym_inst_fill(qp, op, sess, infl_req,
84 w7 = sess->cpt_inst_w7;
86 sess = cn10k_cpt_sym_temp_sess_create(qp, op);
87 if (unlikely(sess == NULL)) {
88 plt_dp_err("Could not create temp session");
92 ret = cpt_sym_inst_fill(qp, op, sess, infl_req,
95 sym_session_clear(cn10k_cryptodev_driver_id,
97 rte_mempool_put(qp->sess_mp, op->sym->session);
100 w7 = sess->cpt_inst_w7;
103 plt_dp_err("Unsupported op type");
107 inst[0].res_addr = (uint64_t)&infl_req->res;
108 infl_req->res.cn10k.compcode = CPT_COMP_NOT_DONE;
116 #define PKTS_PER_LOOP 32
117 #define PKTS_PER_STEORL 16
120 cn10k_cpt_enqueue_burst(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
122 uint64_t lmt_base, lmt_arg, io_addr;
123 struct cpt_inflight_req *infl_req;
124 uint16_t nb_allowed, count = 0;
125 struct cnxk_cpt_qp *qp = qptr;
126 struct pending_queue *pend_q;
127 struct cpt_inst_s *inst;
131 pend_q = &qp->pend_q;
133 nb_allowed = qp->lf.nb_desc - pend_q->pending_count;
134 nb_ops = RTE_MIN(nb_ops, nb_allowed);
136 if (unlikely(nb_ops == 0))
139 lmt_base = qp->lmtline.lmt_base;
140 io_addr = qp->lmtline.io_addr;
142 ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
143 inst = (struct cpt_inst_s *)lmt_base;
146 for (i = 0; i < RTE_MIN(PKTS_PER_LOOP, nb_ops); i++) {
147 infl_req = &pend_q->req_queue[pend_q->enq_tail];
148 infl_req->op_flags = 0;
150 ret = cn10k_cpt_fill_inst(qp, ops + i, &inst[2 * i], infl_req);
151 if (unlikely(ret != 1)) {
152 plt_dp_err("Could not process op: %p", ops + i);
158 MOD_INC(pend_q->enq_tail, qp->lf.nb_desc);
161 if (i > PKTS_PER_STEORL) {
162 lmt_arg = ROC_CN10K_CPT_LMT_ARG | (PKTS_PER_STEORL - 1) << 12 |
164 roc_lmt_submit_steorl(lmt_arg, io_addr);
165 lmt_arg = ROC_CN10K_CPT_LMT_ARG |
166 (i - PKTS_PER_STEORL - 1) << 12 |
167 (uint64_t)(lmt_id + PKTS_PER_STEORL);
168 roc_lmt_submit_steorl(lmt_arg, io_addr);
170 lmt_arg = ROC_CN10K_CPT_LMT_ARG | (i - 1) << 12 |
172 roc_lmt_submit_steorl(lmt_arg, io_addr);
177 if (nb_ops - i > 0 && i == PKTS_PER_LOOP) {
185 pend_q->pending_count += count + i;
187 pend_q->time_out = rte_get_timer_cycles() +
188 DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
194 cn10k_cpt_set_enqdeq_fns(struct rte_cryptodev *dev)
196 dev->enqueue_burst = cn10k_cpt_enqueue_burst;
202 cn10k_cpt_dev_info_get(struct rte_cryptodev *dev,
203 struct rte_cryptodev_info *info)
206 cnxk_cpt_dev_info_get(dev, info);
207 info->driver_id = cn10k_cryptodev_driver_id;
211 struct rte_cryptodev_ops cn10k_cpt_ops = {
212 /* Device control ops */
213 .dev_configure = cnxk_cpt_dev_config,
214 .dev_start = cnxk_cpt_dev_start,
215 .dev_stop = cnxk_cpt_dev_stop,
216 .dev_close = cnxk_cpt_dev_close,
217 .dev_infos_get = cn10k_cpt_dev_info_get,
221 .queue_pair_setup = cnxk_cpt_queue_pair_setup,
222 .queue_pair_release = cnxk_cpt_queue_pair_release,
224 /* Symmetric crypto ops */
225 .sym_session_get_size = cnxk_cpt_sym_session_get_size,
226 .sym_session_configure = cnxk_cpt_sym_session_configure,
227 .sym_session_clear = cnxk_cpt_sym_session_clear,
229 /* Asymmetric crypto ops */
230 .asym_session_get_size = NULL,
231 .asym_session_configure = NULL,
232 .asym_session_clear = NULL,