Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2025 Marvell.
3 : : */
4 : :
5 : : #include <cryptodev_pmd.h>
6 : : #include <eal_export.h>
7 : : #include <ethdev_driver.h>
8 : : #include <rte_cryptodev.h>
9 : : #include <rte_hexdump.h>
10 : : #include <rte_vect.h>
11 : :
12 : : #include "hw/nix.h"
13 : : #include "hw/npa.h"
14 : : #include "hw/tim.h"
15 : : #include "roc_cpt.h"
16 : : #include "roc_idev.h"
17 : : #include "roc_mbox.h"
18 : : #include "roc_sso.h"
19 : : #include "roc_sso_dp.h"
20 : : #include "roc_tim.h"
21 : :
22 : : #include "cn20k_cryptodev.h"
23 : : #include "cn20k_cryptodev_event_dp.h"
24 : : #include "cn20k_cryptodev_ops.h"
25 : : #include "cn20k_cryptodev_sec.h"
26 : : #include "cn20k_eventdev.h"
27 : : #include "cn20k_ipsec_la_ops.h"
28 : : #include "cn20k_tls_ops.h"
29 : : #include "cnxk_ae.h"
30 : : #include "cnxk_cryptodev.h"
31 : : #include "cnxk_cryptodev_ops.h"
32 : : #include "cnxk_eventdev.h"
33 : : #include "cnxk_se.h"
34 : :
35 : : #include "rte_pmd_cnxk_crypto.h"
36 : :
37 : : /* Holds information required to send crypto operations in one burst */
38 : : struct ops_burst {
39 : : struct rte_crypto_op *op[CN20K_CPT_PKTS_PER_LOOP];
40 : : uint64_t w2[CN20K_CPT_PKTS_PER_LOOP];
41 : : struct cn20k_sso_hws *ws;
42 : : struct cnxk_cpt_qp *qp;
43 : : uint16_t nb_ops;
44 : : };
45 : :
46 : : /* Holds information required to send vector of operations */
47 : : struct vec_request {
48 : : struct cpt_inflight_req *req;
49 : : struct rte_event_vector *vec;
50 : : union cpt_inst_w7 w7;
51 : : uint64_t w2;
52 : : };
53 : :
54 : : static inline struct cnxk_se_sess *
55 : 0 : cn20k_cpt_sym_temp_sess_create(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op)
56 : : {
57 : : struct rte_crypto_sym_op *sym_op = op->sym;
58 : : struct rte_cryptodev_sym_session *sess;
59 : : struct cnxk_se_sess *priv;
60 : : int ret;
61 : :
62 : : /* Create temporary session */
63 [ # # # # ]: 0 : if (rte_mempool_get(qp->sess_mp, (void **)&sess) < 0)
64 : : return NULL;
65 : :
66 : 0 : ret = sym_session_configure(qp->lf.roc_cpt, sym_op->xform, sess, true);
67 [ # # ]: 0 : if (ret) {
68 [ # # ]: 0 : rte_mempool_put(qp->sess_mp, (void *)sess);
69 : 0 : goto sess_put;
70 : : }
71 : :
72 : 0 : priv = (void *)sess;
73 : 0 : sym_op->session = sess;
74 : :
75 : 0 : return priv;
76 : :
77 : : sess_put:
78 [ # # ]: 0 : rte_mempool_put(qp->sess_mp, sess);
79 : 0 : return NULL;
80 : : }
81 : :
82 : : static inline struct cnxk_ae_sess *
83 : 0 : cn20k_cpt_asym_temp_sess_create(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op)
84 : : {
85 : : struct rte_crypto_asym_op *asym_op = op->asym;
86 : 0 : struct roc_cpt *roc_cpt = qp->lf.roc_cpt;
87 : : struct rte_cryptodev_asym_session *sess;
88 : : struct cnxk_ae_sess *priv;
89 : : struct cnxk_cpt_vf *vf;
90 : : union cpt_inst_w7 w7;
91 : : struct hw_ctx_s *hwc;
92 : :
93 : : /* Create temporary session */
94 [ # # # # ]: 0 : if (rte_mempool_get(qp->sess_mp, (void **)&sess) < 0)
95 : : return NULL;
96 : :
97 : 0 : priv = (struct cnxk_ae_sess *)sess;
98 : 0 : if (cnxk_ae_fill_session_parameters(priv, asym_op->xform))
99 : 0 : goto sess_put;
100 : :
101 [ # # ]: 0 : priv->lf = &qp->lf;
102 : :
103 [ # # ]: 0 : if (roc_errata_cpt_hang_on_mixed_ctx_val()) {
104 : : hwc = &priv->hw_ctx;
105 : 0 : hwc->w0.s.aop_valid = 1;
106 : 0 : hwc->w0.s.ctx_hdr_size = 0;
107 : 0 : hwc->w0.s.ctx_size = 1;
108 : 0 : hwc->w0.s.ctx_push_size = 1;
109 : :
110 : : w7.s.ctx_val = 1;
111 : : w7.s.cptr = (uint64_t)hwc;
112 : : }
113 : :
114 : 0 : w7.u64 = 0;
115 : 0 : w7.s.egrp = roc_cpt->eng_grp[CPT_ENG_TYPE_AE];
116 : :
117 : 0 : vf = container_of(roc_cpt, struct cnxk_cpt_vf, cpt);
118 : 0 : priv->cpt_inst_w7 = w7.u64;
119 : 0 : priv->cnxk_fpm_iova = vf->cnxk_fpm_iova;
120 : 0 : priv->ec_grp = vf->ec_grp;
121 : :
122 : 0 : asym_op->session = sess;
123 : :
124 : 0 : return priv;
125 : :
126 : : sess_put:
127 [ # # ]: 0 : rte_mempool_put(qp->sess_mp, sess);
128 : 0 : return NULL;
129 : : }
130 : :
131 : : static __rte_always_inline int __rte_hot
132 : : cpt_sec_ipsec_inst_fill(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op,
133 : : struct cn20k_sec_session *sess, struct cpt_inst_s *inst,
134 : : struct cpt_inflight_req *infl_req)
135 : : {
136 : : struct rte_crypto_sym_op *sym_op = op->sym;
137 : : int ret;
138 : :
139 [ # # # # ]: 0 : if (unlikely(sym_op->m_dst && sym_op->m_dst != sym_op->m_src)) {
140 : 0 : plt_dp_err("Out of place is not supported");
141 : 0 : return -ENOTSUP;
142 : : }
143 : :
144 [ # # ]: 0 : if (sess->ipsec.is_outbound)
145 : : ret = process_outb_sa(&qp->lf, op, sess, &qp->meta_info, infl_req, inst);
146 : : else
147 : : ret = process_inb_sa(op, sess, inst, &qp->meta_info, infl_req);
148 : :
149 : : return ret;
150 : : }
151 : :
152 : : static __rte_always_inline int __rte_hot
153 : : cpt_sec_tls_inst_fill(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op,
154 : : struct cn20k_sec_session *sess, struct cpt_inst_s *inst,
155 : : struct cpt_inflight_req *infl_req)
156 : : {
157 [ # # ]: 0 : if (sess->tls_opt.is_write)
158 : 0 : return process_tls_write(&qp->lf, op, sess, &qp->meta_info, infl_req, inst);
159 : : else
160 : 0 : return process_tls_read(op, sess, &qp->meta_info, infl_req, inst);
161 : : }
162 : :
163 : : static __rte_always_inline int __rte_hot
164 : : cpt_sec_inst_fill(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op, struct cn20k_sec_session *sess,
165 : : struct cpt_inst_s *inst, struct cpt_inflight_req *infl_req)
166 : : {
167 : :
168 : 0 : if (sess->proto == RTE_SECURITY_PROTOCOL_IPSEC)
169 : : return cpt_sec_ipsec_inst_fill(qp, op, sess, &inst[0], infl_req);
170 [ # # ]: 0 : else if (sess->proto == RTE_SECURITY_PROTOCOL_TLS_RECORD)
171 : : return cpt_sec_tls_inst_fill(qp, op, sess, &inst[0], infl_req);
172 : :
173 : : return 0;
174 : : }
175 : :
176 : : static inline int
177 : 0 : cn20k_cpt_fill_inst(struct cnxk_cpt_qp *qp, struct rte_crypto_op *ops[], struct cpt_inst_s inst[],
178 : : struct cpt_inflight_req *infl_req)
179 : : {
180 : : struct cn20k_sec_session *sec_sess;
181 : : struct rte_crypto_asym_op *asym_op;
182 : : struct rte_crypto_sym_op *sym_op;
183 : : struct cnxk_ae_sess *ae_sess;
184 : : struct cnxk_se_sess *sess;
185 : : struct rte_crypto_op *op;
186 : : uint64_t w7;
187 : : int ret;
188 : :
189 : : const union cpt_res_s res = {
190 : : .cn20k.compcode = CPT_COMP_NOT_DONE,
191 : : };
192 : :
193 : 0 : op = ops[0];
194 : :
195 : 0 : inst[0].w0.u64 = 0;
196 : 0 : inst[0].w2.u64 = 0;
197 : 0 : inst[0].w3.u64 = 0;
198 : :
199 : 0 : inst[0].meta_sz = 0;
200 : 0 : inst[0].cq_ena = 0;
201 : 0 : inst[0].res_addr = 0;
202 : :
203 : : sym_op = op->sym;
204 : :
205 [ # # ]: 0 : if (op->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
206 [ # # ]: 0 : if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
207 [ # # ]: 0 : sec_sess = (struct cn20k_sec_session *)sym_op->session;
208 : : ret = cpt_sec_inst_fill(qp, op, sec_sess, &inst[0], infl_req);
209 [ # # ]: 0 : if (unlikely(ret))
210 : : return 0;
211 : 0 : w7 = sec_sess->inst.w7;
212 [ # # ]: 0 : } else if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
213 [ # # ]: 0 : sess = (struct cnxk_se_sess *)(sym_op->session);
214 : : ret = cpt_sym_inst_fill(qp, op, sess, infl_req, &inst[0], true, true);
215 [ # # ]: 0 : if (unlikely(ret))
216 : : return 0;
217 : 0 : w7 = sess->cpt_inst_w7;
218 : : } else {
219 : 0 : sess = cn20k_cpt_sym_temp_sess_create(qp, op);
220 [ # # ]: 0 : if (unlikely(sess == NULL)) {
221 : 0 : plt_dp_err("Could not create temp session");
222 : 0 : return 0;
223 : : }
224 : :
225 : : ret = cpt_sym_inst_fill(qp, op, sess, infl_req, &inst[0], true, true);
226 [ # # ]: 0 : if (unlikely(ret)) {
227 : 0 : sym_session_clear(op->sym->session, true);
228 [ # # ]: 0 : rte_mempool_put(qp->sess_mp, op->sym->session);
229 : 0 : return 0;
230 : : }
231 : 0 : w7 = sess->cpt_inst_w7;
232 : : }
233 [ # # ]: 0 : } else if (op->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
234 [ # # ]: 0 : if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
235 : : asym_op = op->asym;
236 [ # # ]: 0 : ae_sess = (struct cnxk_ae_sess *)asym_op->session;
237 : : ret = cnxk_ae_enqueue(qp, op, infl_req, &inst[0], ae_sess);
238 [ # # ]: 0 : if (unlikely(ret))
239 : : return 0;
240 : 0 : w7 = ae_sess->cpt_inst_w7;
241 : : } else {
242 : 0 : ae_sess = cn20k_cpt_asym_temp_sess_create(qp, op);
243 [ # # ]: 0 : if (unlikely(ae_sess == NULL)) {
244 : 0 : plt_dp_err("Could not create temp session");
245 : 0 : return 0;
246 : : }
247 : :
248 : : ret = cnxk_ae_enqueue(qp, op, infl_req, &inst[0], ae_sess);
249 [ # # ]: 0 : if (unlikely(ret)) {
250 : 0 : cnxk_ae_session_clear(NULL,
251 : : (struct rte_cryptodev_asym_session *)ae_sess);
252 [ # # ]: 0 : rte_mempool_put(qp->sess_mp, ae_sess);
253 : 0 : return 0;
254 : : }
255 : 0 : w7 = ae_sess->cpt_inst_w7;
256 : : }
257 : :
258 : : } else {
259 : 0 : plt_dp_err("Unsupported op type");
260 : 0 : return 0;
261 : : }
262 : :
263 : 0 : inst[0].res_addr = (uint64_t)&infl_req->res;
264 : 0 : inst[0].cq_ena = 1;
265 : 0 : rte_atomic_store_explicit((RTE_ATOMIC(uint64_t) *)(&infl_req->res.u64[0]), res.u64[0],
266 : : rte_memory_order_relaxed);
267 : 0 : infl_req->cop = op;
268 : :
269 : 0 : inst[0].w7.u64 = w7;
270 : :
271 : : #ifdef CPT_INST_DEBUG_ENABLE
272 : : infl_req->dptr = (uint8_t *)inst[0].dptr;
273 : : infl_req->rptr = (uint8_t *)inst[0].rptr;
274 : : infl_req->scatter_sz = inst[0].w6.s.scatter_sz;
275 : : infl_req->opcode_major = inst[0].w4.s.opcode_major;
276 : :
277 : : rte_hexdump(rte_log_get_stream(), "cptr", (void *)(uint64_t)inst[0].w7.s.cptr, 128);
278 : : plt_err("major opcode:%d", inst[0].w4.s.opcode_major);
279 : : plt_err("minor opcode:%d", inst[0].w4.s.opcode_minor);
280 : : plt_err("param1:%d", inst[0].w4.s.param1);
281 : : plt_err("param2:%d", inst[0].w4.s.param2);
282 : : plt_err("dlen:%d", inst[0].w4.s.dlen);
283 : :
284 : : cnxk_cpt_request_data_sgv2_mode_dump((void *)inst[0].dptr, 1, inst[0].w5.s.gather_sz);
285 : : cnxk_cpt_request_data_sgv2_mode_dump((void *)inst[0].rptr, 0, inst[0].w6.s.scatter_sz);
286 : :
287 : : #endif
288 : :
289 : 0 : return 1;
290 : : }
291 : :
292 : : static uint16_t
293 : 0 : cn20k_cpt_enqueue_burst(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
294 : : {
295 : : struct cpt_inflight_req *infl_req;
296 : : uint64_t head, lmt_base, io_addr;
297 : : uint16_t nb_allowed, count = 0;
298 : : struct cnxk_cpt_qp *qp = qptr;
299 : : struct pending_queue *pend_q;
300 : : struct cpt_inst_s *inst;
301 : : union cpt_fc_write_s fc;
302 : : uint64_t *fc_addr;
303 : : uint16_t lmt_id;
304 : : int ret, i;
305 : :
306 : : pend_q = &qp->pend_q;
307 : :
308 : 0 : const uint64_t pq_mask = pend_q->pq_mask;
309 : :
310 : 0 : head = pend_q->head;
311 [ # # ]: 0 : nb_allowed = pending_queue_free_cnt(head, pend_q->tail, pq_mask);
312 : 0 : nb_ops = RTE_MIN(nb_ops, nb_allowed);
313 : :
314 [ # # ]: 0 : if (unlikely(nb_ops == 0))
315 : : return 0;
316 : :
317 : 0 : lmt_base = qp->lmtline.lmt_base;
318 : : io_addr = qp->lmtline.io_addr;
319 : 0 : fc_addr = qp->lmtline.fc_addr;
320 : :
321 : 0 : const uint32_t fc_thresh = qp->lmtline.fc_thresh;
322 : :
323 : : ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
324 : 0 : inst = (struct cpt_inst_s *)lmt_base;
325 : :
326 : 0 : again:
327 : : fc.u64[0] =
328 : 0 : rte_atomic_load_explicit((RTE_ATOMIC(uint64_t) *)fc_addr, rte_memory_order_relaxed);
329 [ # # ]: 0 : if (unlikely(fc.s.qsize > fc_thresh)) {
330 : : i = 0;
331 : 0 : goto pend_q_commit;
332 : : }
333 : :
334 [ # # ]: 0 : for (i = 0; i < RTE_MIN(CN20K_CPT_PKTS_PER_LOOP, nb_ops); i++) {
335 : 0 : infl_req = &pend_q->req_queue[head];
336 : 0 : infl_req->op_flags = 0;
337 : :
338 : 0 : ret = cn20k_cpt_fill_inst(qp, ops + i, &inst[i], infl_req);
339 [ # # ]: 0 : if (unlikely(ret != 1)) {
340 : 0 : plt_dp_err("Could not process op: %p", ops + i);
341 [ # # ]: 0 : if (i == 0)
342 : 0 : goto pend_q_commit;
343 : : break;
344 : : }
345 : :
346 : : pending_queue_advance(&head, pq_mask);
347 : : }
348 : :
349 : : cn20k_cpt_lmtst_dual_submit(&io_addr, lmt_id, &i);
350 : :
351 [ # # # # ]: 0 : if (nb_ops - i > 0 && i == CN20K_CPT_PKTS_PER_LOOP) {
352 : 0 : nb_ops -= CN20K_CPT_PKTS_PER_LOOP;
353 : 0 : ops += CN20K_CPT_PKTS_PER_LOOP;
354 : 0 : count += CN20K_CPT_PKTS_PER_LOOP;
355 : 0 : goto again;
356 : : }
357 : :
358 : 0 : pend_q_commit:
359 : : rte_atomic_thread_fence(rte_memory_order_release);
360 : :
361 : 0 : pend_q->head = head;
362 : 0 : pend_q->time_out = rte_get_timer_cycles() + DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
363 : :
364 : 0 : return count + i;
365 : : }
366 : :
367 : : static int
368 : 0 : cn20k_cpt_crypto_adapter_ev_mdata_set(struct rte_cryptodev *dev __rte_unused, void *sess,
369 : : enum rte_crypto_op_type op_type,
370 : : enum rte_crypto_op_sess_type sess_type, void *mdata)
371 : : {
372 : : union rte_event_crypto_metadata *ec_mdata = mdata;
373 : : uint32_t tag_mask = 0, stag_mask;
374 : : struct roc_sso_agq_data data;
375 : : struct rte_event *rsp_info;
376 : : struct cnxk_cpt_qp *qp;
377 : : uint64_t w2, tag_type;
378 : : uint8_t cdev_id;
379 : : int16_t qp_id;
380 : : uint32_t agq;
381 : : int rc;
382 : :
383 : : /* Get queue pair */
384 : 0 : cdev_id = ec_mdata->request_info.cdev_id;
385 : 0 : qp_id = ec_mdata->request_info.queue_pair_id;
386 : 0 : qp = rte_cryptodevs[cdev_id].data->queue_pairs[qp_id];
387 : :
388 [ # # ]: 0 : if (!qp->ca.enabled)
389 : : return -EINVAL;
390 : :
391 [ # # ]: 0 : if (qp->ca.vector_sz) {
392 : 0 : tag_mask |= ec_mdata->response_info.flow_id;
393 : : stag_mask = tag_mask;
394 : 0 : tag_mask |= RTE_EVENT_TYPE_CRYPTODEV_VECTOR << 28;
395 : : stag_mask |= RTE_EVENT_TYPE_CRYPTODEV << 28;
396 : :
397 : : memset(&data, 0, sizeof(struct roc_sso_agq_data));
398 : 0 : data.tag = tag_mask;
399 : 0 : data.tt = ec_mdata->response_info.sched_type;
400 : 0 : data.stag = stag_mask >> 20;
401 : 0 : data.vwqe_aura = roc_npa_aura_handle_to_aura(qp->ca.vector_mp->pool_id);
402 : 0 : data.vwqe_max_sz_exp = rte_log2_u32(qp->ca.vector_sz);
403 : 0 : data.vwqe_wait_tmo = qp->ca.vector_timeout_ns / ((SSO_AGGR_DEF_TMO + 1) * 100);
404 : : data.xqe_type = 0;
405 : 0 : agq = UINT32_MAX;
406 : :
407 : 0 : rc = roc_sso_hwgrp_agq_alloc(&qp->evdev->sso, ec_mdata->response_info.queue_id,
408 : : &data, &agq);
409 [ # # ]: 0 : if (rc < 0) {
410 : 0 : plt_err("Failed to allocate aggregator queue");
411 : 0 : return rc;
412 : : }
413 : :
414 : : /* Prepare w2 */
415 : : rsp_info = &ec_mdata->response_info;
416 : 0 : w2 = CNXK_CPT_INST_W2(agq, SSO_TT_AGG, rsp_info->queue_id, 0);
417 : : } else {
418 : : /* Prepare w2 */
419 : : tag_type = RTE_EVENT_TYPE_CRYPTODEV;
420 : : rsp_info = &ec_mdata->response_info;
421 : 0 : w2 = CNXK_CPT_INST_W2((tag_type << 28) | (rsp_info->sub_event_type << 20) |
422 : : rsp_info->flow_id,
423 : : rsp_info->sched_type, rsp_info->queue_id, 0);
424 : : }
425 : :
426 : : /* Set meta according to session type */
427 [ # # ]: 0 : if (op_type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
428 [ # # ]: 0 : if (sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
429 : : struct cn20k_sec_session *sec_sess = (struct cn20k_sec_session *)sess;
430 : :
431 : 0 : sec_sess->qp = qp;
432 : 0 : sec_sess->inst.w2 = w2;
433 [ # # ]: 0 : } else if (sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
434 : : struct cnxk_se_sess *priv;
435 : :
436 : : priv = (struct cnxk_se_sess *)sess;
437 : 0 : priv->qp = qp;
438 : 0 : priv->cpt_inst_w2 = w2;
439 : : } else
440 : : return -EINVAL;
441 [ # # ]: 0 : } else if (op_type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
442 [ # # ]: 0 : if (sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
443 : : struct cnxk_ae_sess *priv;
444 : :
445 : : priv = (struct cnxk_ae_sess *)sess;
446 : 0 : priv->qp = qp;
447 : 0 : priv->cpt_inst_w2 = w2;
448 : : } else
449 : : return -EINVAL;
450 : : } else
451 : : return -EINVAL;
452 : :
453 : : return 0;
454 : : }
455 : :
456 : : static inline int
457 : 0 : cn20k_ca_meta_info_extract(struct rte_crypto_op *op, struct cnxk_cpt_qp **qp, uint64_t *w2)
458 : : {
459 [ # # ]: 0 : if (op->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
460 [ # # ]: 0 : if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
461 : : struct cn20k_sec_session *sec_sess;
462 : :
463 : 0 : sec_sess = (struct cn20k_sec_session *)op->sym->session;
464 : :
465 : 0 : *qp = sec_sess->qp;
466 : 0 : *w2 = sec_sess->inst.w2;
467 [ # # ]: 0 : } else if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
468 : : struct cnxk_se_sess *priv;
469 : :
470 : 0 : priv = (struct cnxk_se_sess *)op->sym->session;
471 : 0 : *qp = priv->qp;
472 : 0 : *w2 = priv->cpt_inst_w2;
473 : : } else {
474 : : union rte_event_crypto_metadata *ec_mdata;
475 : : struct rte_event *rsp_info;
476 : : uint8_t cdev_id;
477 : : uint16_t qp_id;
478 : :
479 [ # # ]: 0 : if (unlikely(op->private_data_offset == 0))
480 : : return -EINVAL;
481 : 0 : ec_mdata = (union rte_event_crypto_metadata *)((uint8_t *)op +
482 : 0 : op->private_data_offset);
483 : : rsp_info = &ec_mdata->response_info;
484 : 0 : cdev_id = ec_mdata->request_info.cdev_id;
485 : 0 : qp_id = ec_mdata->request_info.queue_pair_id;
486 : 0 : *qp = rte_cryptodevs[cdev_id].data->queue_pairs[qp_id];
487 : 0 : *w2 = CNXK_CPT_INST_W2((RTE_EVENT_TYPE_CRYPTODEV << 28) | rsp_info->flow_id,
488 : : rsp_info->sched_type, rsp_info->queue_id, 0);
489 : : }
490 [ # # ]: 0 : } else if (op->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
491 [ # # ]: 0 : if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
492 : : struct cnxk_ae_sess *priv;
493 : :
494 : 0 : priv = (struct cnxk_ae_sess *)op->asym->session;
495 : 0 : *qp = priv->qp;
496 : 0 : *w2 = priv->cpt_inst_w2;
497 : : } else {
498 : : union rte_event_crypto_metadata *ec_mdata;
499 : : struct rte_event *rsp_info;
500 : : uint8_t cdev_id;
501 : : uint16_t qp_id;
502 : :
503 [ # # ]: 0 : if (unlikely(op->private_data_offset == 0))
504 : : return -EINVAL;
505 : 0 : ec_mdata = (union rte_event_crypto_metadata *)((uint8_t *)op +
506 : 0 : op->private_data_offset);
507 : : rsp_info = &ec_mdata->response_info;
508 : 0 : cdev_id = ec_mdata->request_info.cdev_id;
509 : 0 : qp_id = ec_mdata->request_info.queue_pair_id;
510 : 0 : *qp = rte_cryptodevs[cdev_id].data->queue_pairs[qp_id];
511 : 0 : *w2 = CNXK_CPT_INST_W2((RTE_EVENT_TYPE_CRYPTODEV << 28) | rsp_info->flow_id,
512 : : rsp_info->sched_type, rsp_info->queue_id, 0);
513 : : }
514 : : } else
515 : : return -EINVAL;
516 : :
517 : : return 0;
518 : : }
519 : :
520 : : static inline uint16_t
521 : 0 : ca_lmtst_burst_submit(struct ops_burst *burst)
522 : : {
523 : : struct cpt_inflight_req *infl_reqs[CN20K_CPT_PKTS_PER_LOOP];
524 : : struct cpt_inst_s *inst, *inst_base;
525 : : struct cpt_inflight_req *infl_req;
526 : : uint64_t lmt_base, io_addr;
527 : : union cpt_fc_write_s fc;
528 : : struct cnxk_cpt_qp *qp;
529 : : uint64_t *fc_addr;
530 : : uint16_t lmt_id;
531 : : int ret, i, j;
532 : :
533 : 0 : qp = burst->qp;
534 : :
535 : 0 : lmt_base = qp->lmtline.lmt_base;
536 : : io_addr = qp->lmtline.io_addr;
537 : 0 : fc_addr = qp->lmtline.fc_addr;
538 : :
539 : 0 : const uint32_t fc_thresh = qp->lmtline.fc_thresh;
540 : :
541 : : ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
542 : 0 : inst_base = (struct cpt_inst_s *)lmt_base;
543 : :
544 : : #ifdef CNXK_CRYPTODEV_DEBUG
545 : : if (unlikely(!qp->ca.enabled)) {
546 : : rte_errno = EINVAL;
547 : : return 0;
548 : : }
549 : : #endif
550 : :
551 [ # # # # ]: 0 : if (unlikely(rte_mempool_get_bulk(qp->ca.req_mp, (void **)infl_reqs, burst->nb_ops))) {
552 : 0 : rte_errno = ENOMEM;
553 : 0 : return 0;
554 : : }
555 : :
556 [ # # ]: 0 : for (i = 0; i < burst->nb_ops; i++) {
557 : 0 : inst = &inst_base[i];
558 : 0 : infl_req = infl_reqs[i];
559 : 0 : infl_req->op_flags = 0;
560 : :
561 : 0 : ret = cn20k_cpt_fill_inst(qp, &burst->op[i], inst, infl_req);
562 [ # # ]: 0 : if (unlikely(ret != 1)) {
563 : : plt_dp_dbg("Could not process op: %p", burst->op[i]);
564 [ # # ]: 0 : if (i != 0)
565 : 0 : goto submit;
566 : : else
567 : 0 : goto put;
568 : : }
569 : :
570 : 0 : infl_req->res.cn20k.compcode = CPT_COMP_NOT_DONE;
571 : 0 : infl_req->qp = qp;
572 : 0 : inst->w0.u64 = 0;
573 : 0 : inst->res_addr = (uint64_t)&infl_req->res;
574 : 0 : inst->w2.u64 = burst->w2[i];
575 : 0 : inst->w3.u64 = CNXK_CPT_INST_W3(1, infl_req);
576 : : }
577 : :
578 : : fc.u64[0] =
579 : 0 : rte_atomic_load_explicit((RTE_ATOMIC(uint64_t) *)fc_addr, rte_memory_order_relaxed);
580 [ # # ]: 0 : if (unlikely(fc.s.qsize > fc_thresh)) {
581 : 0 : rte_errno = EAGAIN;
582 [ # # ]: 0 : for (j = 0; j < i; j++) {
583 : 0 : infl_req = infl_reqs[j];
584 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
585 [ # # ]: 0 : rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
586 : : }
587 : : i = 0;
588 : 0 : goto put;
589 : : }
590 : :
591 : 0 : submit:
592 [ # # ]: 0 : if (CNXK_TT_FROM_TAG(burst->ws->gw_rdata) == SSO_TT_ORDERED)
593 : 0 : roc_sso_hws_head_wait(burst->ws->base);
594 : :
595 : : cn20k_cpt_lmtst_dual_submit(&io_addr, lmt_id, &i);
596 : :
597 : 0 : put:
598 [ # # ]: 0 : if (unlikely(i != burst->nb_ops))
599 [ # # ]: 0 : rte_mempool_put_bulk(qp->ca.req_mp, (void *)&infl_reqs[i], burst->nb_ops - i);
600 : :
601 : 0 : return i;
602 : : }
603 : :
604 : : RTE_EXPORT_INTERNAL_SYMBOL(cn20k_cpt_crypto_adapter_enqueue)
605 : : uint16_t __rte_hot
606 : 0 : cn20k_cpt_crypto_adapter_enqueue(void *ws, struct rte_event ev[], uint16_t nb_events)
607 : : {
608 : : uint16_t submitted, count = 0;
609 : : struct rte_crypto_op *op;
610 : : struct ops_burst burst;
611 : : struct cnxk_cpt_qp *qp;
612 : : uint64_t w2;
613 : : int ret, i;
614 : :
615 : 0 : burst.ws = ws;
616 : 0 : burst.qp = NULL;
617 : 0 : burst.nb_ops = 0;
618 : :
619 [ # # ]: 0 : for (i = 0; i < nb_events; i++) {
620 : 0 : op = ev[i].event_ptr;
621 : 0 : ret = cn20k_ca_meta_info_extract(op, &qp, &w2);
622 [ # # ]: 0 : if (unlikely(ret)) {
623 : 0 : rte_errno = EINVAL;
624 : 0 : goto exit;
625 : : }
626 : :
627 : : /* Queue pair change check */
628 [ # # ]: 0 : if (qp != burst.qp) {
629 [ # # ]: 0 : if (burst.nb_ops) {
630 : 0 : submitted = ca_lmtst_burst_submit(&burst);
631 : 0 : count += submitted;
632 [ # # ]: 0 : if (unlikely(submitted != burst.nb_ops))
633 : 0 : goto exit;
634 : 0 : burst.nb_ops = 0;
635 : : }
636 : 0 : burst.qp = qp;
637 : : }
638 : 0 : burst.w2[burst.nb_ops] = w2;
639 : 0 : burst.op[burst.nb_ops] = op;
640 : :
641 : : /* Max nb_ops per burst check */
642 [ # # ]: 0 : if (++burst.nb_ops == CN20K_CPT_PKTS_PER_LOOP) {
643 : 0 : submitted = ca_lmtst_burst_submit(&burst);
644 : 0 : count += submitted;
645 [ # # ]: 0 : if (unlikely(submitted != burst.nb_ops))
646 : 0 : goto exit;
647 : 0 : burst.nb_ops = 0;
648 : : }
649 : : }
650 : : /* Submit the rest of crypto operations */
651 [ # # ]: 0 : if (burst.nb_ops)
652 : 0 : count += ca_lmtst_burst_submit(&burst);
653 : :
654 : 0 : exit:
655 : 0 : return count;
656 : : }
657 : :
658 : : static inline void
659 : 0 : cn20k_cpt_ipsec_post_process(struct rte_crypto_op *cop, struct cpt_cn20k_res_s *res)
660 : : {
661 : 0 : struct rte_mbuf *mbuf = cop->sym->m_src;
662 : 0 : const uint16_t m_len = res->rlen;
663 : :
664 [ # # # # : 0 : switch (res->uc_compcode) {
# # ]
665 : 0 : case ROC_IE_OW_UCC_SUCCESS_PKT_IP_BADCSUM:
666 : 0 : mbuf->ol_flags &= ~RTE_MBUF_F_RX_IP_CKSUM_GOOD;
667 : 0 : mbuf->ol_flags |= RTE_MBUF_F_RX_IP_CKSUM_BAD;
668 : 0 : break;
669 : 0 : case ROC_IE_OW_UCC_SUCCESS_PKT_L4_GOODCSUM:
670 : 0 : mbuf->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD | RTE_MBUF_F_RX_IP_CKSUM_GOOD;
671 : 0 : break;
672 : 0 : case ROC_IE_OW_UCC_SUCCESS_PKT_L4_BADCSUM:
673 : 0 : mbuf->ol_flags |= RTE_MBUF_F_RX_L4_CKSUM_BAD | RTE_MBUF_F_RX_IP_CKSUM_GOOD;
674 : 0 : break;
675 : : case ROC_IE_OW_UCC_SUCCESS_PKT_IP_GOODCSUM:
676 : : break;
677 : 0 : case ROC_IE_OW_UCC_SUCCESS_SA_SOFTEXP_FIRST:
678 : : case ROC_IE_OW_UCC_SUCCESS_SA_SOFTEXP_AGAIN:
679 : 0 : cop->aux_flags = RTE_CRYPTO_OP_AUX_FLAGS_IPSEC_SOFT_EXPIRY;
680 : 0 : break;
681 : 0 : default:
682 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
683 : 0 : cop->aux_flags = res->uc_compcode;
684 : 0 : return;
685 : : }
686 : :
687 [ # # ]: 0 : if (mbuf->next == NULL)
688 : 0 : mbuf->data_len = m_len;
689 : :
690 : 0 : mbuf->pkt_len = m_len;
691 : : }
692 : :
693 : : static inline void
694 : 0 : cn20k_cpt_tls12_trim_mac(struct rte_crypto_op *cop, struct cpt_cn20k_res_s *res, uint8_t mac_len)
695 : : {
696 : : uint32_t pad_len, trim_len, mac_offset, pad_offset;
697 : 0 : struct rte_mbuf *mbuf = cop->sym->m_src;
698 : 0 : uint16_t m_len = res->rlen, len_to_trim;
699 : : struct rte_mbuf *seg;
700 : : uint8_t pad_res = 0;
701 : : uint8_t pad_val;
702 : : uint32_t i;
703 : :
704 : 0 : pad_val = ((res->spi >> 16) & 0xff);
705 : 0 : pad_len = pad_val + 1;
706 : 0 : trim_len = pad_len + mac_len;
707 : 0 : mac_offset = m_len - trim_len;
708 : 0 : pad_offset = mac_offset + mac_len;
709 : :
710 : : /* Handle Direct Mode */
711 [ # # ]: 0 : if (mbuf->next == NULL) {
712 : 0 : uint8_t *ptr = rte_pktmbuf_mtod_offset(mbuf, uint8_t *, pad_offset);
713 : :
714 [ # # ]: 0 : for (i = 0; i < pad_len; i++)
715 : 0 : pad_res |= ptr[i] ^ pad_val;
716 : :
717 [ # # ]: 0 : if (pad_res) {
718 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
719 : 0 : cop->aux_flags = res->uc_compcode;
720 : : }
721 : 0 : mbuf->pkt_len = m_len - trim_len;
722 : 0 : mbuf->data_len = m_len - trim_len;
723 : :
724 : 0 : return;
725 : : }
726 : :
727 : : /* Handle SG mode */
728 : : seg = mbuf;
729 [ # # ]: 0 : while (mac_offset >= seg->data_len) {
730 : 0 : mac_offset -= seg->data_len;
731 : 0 : seg = seg->next;
732 : : }
733 : :
734 : 0 : pad_offset = mac_offset + mac_len;
735 [ # # ]: 0 : while (pad_offset >= seg->data_len) {
736 : 0 : pad_offset -= seg->data_len;
737 : 0 : seg = seg->next;
738 : : }
739 : :
740 [ # # ]: 0 : while (pad_len != 0) {
741 : 0 : uint8_t *ptr = rte_pktmbuf_mtod_offset(seg, uint8_t *, pad_offset);
742 : 0 : uint8_t len = RTE_MIN(seg->data_len - pad_offset, pad_len);
743 : :
744 [ # # ]: 0 : for (i = 0; i < len; i++)
745 : 0 : pad_res |= ptr[i] ^ pad_val;
746 : :
747 : : pad_offset = 0;
748 : 0 : pad_len -= len;
749 : 0 : seg = seg->next;
750 : : }
751 : :
752 [ # # ]: 0 : if (pad_res) {
753 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
754 : 0 : cop->aux_flags = res->uc_compcode;
755 : : }
756 : :
757 : 0 : len_to_trim = mbuf->pkt_len - (m_len - trim_len);
758 : :
759 : : pktmbuf_trim_chain(mbuf, len_to_trim);
760 : : }
761 : :
762 : : /* TLS-1.3:
763 : : * Read from last until a non-zero value is encountered.
764 : : * Return the non zero value as the content type.
765 : : * Remove the MAC and content type and padding bytes.
766 : : */
767 : : static inline void
768 : 0 : cn20k_cpt_tls13_trim_mac(struct rte_crypto_op *cop, struct cpt_cn20k_res_s *res)
769 : : {
770 : 0 : uint16_t m_len = res->rlen, len_to_trim;
771 : 0 : struct rte_mbuf *mbuf = cop->sym->m_src;
772 : : struct rte_mbuf *seg = mbuf;
773 : : uint8_t *ptr, type = 0x0;
774 : : int len, i;
775 : :
776 [ # # ]: 0 : while (m_len && !type) {
777 : 0 : len = m_len;
778 : : seg = mbuf;
779 : :
780 : : /* get the last seg */
781 [ # # ]: 0 : while (len > seg->data_len) {
782 : 0 : len -= seg->data_len;
783 : 0 : seg = seg->next;
784 : : }
785 : :
786 : : /* walkthrough from last until a non zero value is found */
787 : 0 : ptr = rte_pktmbuf_mtod(seg, uint8_t *);
788 : : i = len;
789 [ # # # # ]: 0 : while (i && (ptr[--i] == 0))
790 : : ;
791 : :
792 : 0 : type = ptr[i];
793 : 0 : m_len -= len;
794 : : }
795 : :
796 : 0 : len_to_trim = mbuf->pkt_len - i;
797 : :
798 [ # # ]: 0 : if (type) {
799 : : pktmbuf_trim_chain(mbuf, len_to_trim);
800 : 0 : cop->param1.tls_record.content_type = type;
801 : : } else
802 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
803 : 0 : }
804 : :
805 : : static inline void
806 : 0 : cn20k_cpt_tls_post_process(struct rte_crypto_op *cop, struct cpt_cn20k_res_s *res,
807 : : struct cn20k_sec_session *sess)
808 : : {
809 : 0 : struct cn20k_tls_opt tls_opt = sess->tls_opt;
810 : 0 : struct rte_mbuf *mbuf = cop->sym->m_src;
811 : 0 : uint16_t m_len = res->rlen;
812 : :
813 [ # # ]: 0 : if (!res->uc_compcode) {
814 [ # # ]: 0 : if (mbuf->next == NULL)
815 : 0 : mbuf->data_len = m_len;
816 : 0 : mbuf->pkt_len = m_len;
817 : 0 : cop->param1.tls_record.content_type = (res->spi >> 24) & 0xff;
818 : 0 : return;
819 : : }
820 : :
821 : : /* Any error other than post process */
822 [ # # ]: 0 : if (res->uc_compcode != ROC_SE_ERR_SSL_POST_PROCESS) {
823 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
824 : 0 : cop->aux_flags = res->uc_compcode;
825 : 0 : plt_err("crypto op failed with UC compcode: 0x%x", res->uc_compcode);
826 : 0 : return;
827 : : }
828 : :
829 : : /* Extra padding scenario: Verify padding. Remove padding and MAC */
830 [ # # ]: 0 : if (tls_opt.tls_ver != RTE_SECURITY_VERSION_TLS_1_3)
831 : 0 : cn20k_cpt_tls12_trim_mac(cop, res, (uint8_t)tls_opt.mac_len);
832 : : else
833 : 0 : cn20k_cpt_tls13_trim_mac(cop, res);
834 : : }
835 : :
836 : : static inline void
837 : 0 : cn20k_cpt_sec_post_process(struct rte_crypto_op *cop, struct cpt_cn20k_res_s *res)
838 : : {
839 : : struct rte_crypto_sym_op *sym_op = cop->sym;
840 : : struct cn20k_sec_session *sess;
841 : :
842 : 0 : sess = sym_op->session;
843 [ # # ]: 0 : if (sess->proto == RTE_SECURITY_PROTOCOL_IPSEC)
844 : 0 : cn20k_cpt_ipsec_post_process(cop, res);
845 [ # # ]: 0 : else if (sess->proto == RTE_SECURITY_PROTOCOL_TLS_RECORD)
846 : 0 : cn20k_cpt_tls_post_process(cop, res, sess);
847 : 0 : }
848 : :
849 : : static inline void
850 : 0 : cn20k_cpt_dequeue_post_process(struct cnxk_cpt_qp *qp, struct rte_crypto_op *cop,
851 : : struct cpt_inflight_req *infl_req, struct cpt_cn20k_res_s *res)
852 : : {
853 : 0 : const uint8_t uc_compcode = res->uc_compcode;
854 : 0 : const uint8_t compcode = res->compcode;
855 : :
856 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
857 : :
858 [ # # ]: 0 : if (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
859 : : cop->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
860 [ # # ]: 0 : if (likely(compcode == CPT_COMP_GOOD || compcode == CPT_COMP_WARN)) {
861 : : /* Success with additional info */
862 : 0 : cn20k_cpt_sec_post_process(cop, res);
863 : : } else {
864 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
865 : 0 : plt_dp_info("HW completion code 0x%x", res->compcode);
866 [ # # ]: 0 : if (compcode == CPT_COMP_GOOD) {
867 : 0 : plt_dp_info("Request failed with microcode error");
868 : 0 : plt_dp_info("MC completion code 0x%x", uc_compcode);
869 : : }
870 : : }
871 : :
872 : 0 : return;
873 [ # # ]: 0 : } else if (cop->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC &&
874 : : cop->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
875 : : struct cnxk_ae_sess *sess;
876 : :
877 : 0 : sess = (struct cnxk_ae_sess *)cop->asym->session;
878 [ # # ]: 0 : if (sess->xfrm_type == RTE_CRYPTO_ASYM_XFORM_ECDH &&
879 [ # # ]: 0 : cop->asym->ecdh.ke_type == RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY) {
880 [ # # ]: 0 : if (likely(compcode == CPT_COMP_GOOD)) {
881 [ # # ]: 0 : if (uc_compcode == ROC_AE_ERR_ECC_POINT_NOT_ON_CURVE) {
882 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
883 : 0 : return;
884 [ # # ]: 0 : } else if (uc_compcode == ROC_AE_ERR_ECC_PAI) {
885 : : cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
886 : : return;
887 : : }
888 : : }
889 : : }
890 : : }
891 : :
892 [ # # ]: 0 : if (likely(compcode == CPT_COMP_GOOD)) {
893 : : #ifdef CPT_INST_DEBUG_ENABLE
894 : : cnxk_cpt_request_data_sgv2_mode_dump(infl_req->rptr, 0, infl_req->scatter_sz);
895 : : #endif
896 : :
897 [ # # ]: 0 : if (unlikely(uc_compcode)) {
898 [ # # ]: 0 : if (uc_compcode == ROC_SE_ERR_GC_ICV_MISCOMPARE)
899 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
900 : : else
901 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
902 : :
903 : 0 : plt_dp_info("Request failed with microcode error");
904 : 0 : plt_dp_info("MC completion code 0x%x", res->uc_compcode);
905 : 0 : cop->aux_flags = uc_compcode;
906 : 0 : goto temp_sess_free;
907 : : }
908 : :
909 [ # # ]: 0 : if (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
910 : : /* Verify authentication data if required */
911 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_AUTH_VERIFY)) {
912 : 0 : uintptr_t *rsp = infl_req->mdata;
913 : :
914 [ # # ]: 0 : compl_auth_verify(cop, (uint8_t *)rsp[0], rsp[1]);
915 : : }
916 [ # # ]: 0 : } else if (cop->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
917 : : struct rte_crypto_asym_op *op = cop->asym;
918 : 0 : uintptr_t *mdata = infl_req->mdata;
919 : 0 : struct cnxk_ae_sess *sess = (struct cnxk_ae_sess *)op->session;
920 : :
921 [ # # # # : 0 : cnxk_ae_post_process(cop, sess, (uint8_t *)mdata[0]);
# # # # ]
922 : : }
923 : : } else {
924 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
925 : 0 : plt_dp_info("HW completion code 0x%x", res->compcode);
926 : :
927 [ # # # # ]: 0 : switch (compcode) {
928 : 0 : case CPT_COMP_INSTERR:
929 : 0 : plt_dp_err("Request failed with instruction error");
930 : 0 : break;
931 : 0 : case CPT_COMP_FAULT:
932 : 0 : plt_dp_err("Request failed with DMA fault");
933 : 0 : break;
934 : 0 : case CPT_COMP_HWERR:
935 : 0 : plt_dp_err("Request failed with hardware error");
936 : 0 : break;
937 : 0 : default:
938 : 0 : plt_dp_err("Request failed with unknown completion code");
939 : : }
940 : : }
941 : :
942 : 0 : temp_sess_free:
943 [ # # ]: 0 : if (unlikely(cop->sess_type == RTE_CRYPTO_OP_SESSIONLESS)) {
944 [ # # ]: 0 : if (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
945 : 0 : sym_session_clear(cop->sym->session, true);
946 [ # # ]: 0 : rte_mempool_put(qp->sess_mp, cop->sym->session);
947 : 0 : cop->sym->session = NULL;
948 : : }
949 [ # # ]: 0 : if (cop->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
950 : 0 : cnxk_ae_session_clear(NULL, cop->asym->session);
951 [ # # ]: 0 : rte_mempool_put(qp->sess_mp, cop->asym->session);
952 : 0 : cop->asym->session = NULL;
953 : : }
954 : : }
955 : : }
956 : :
957 : : RTE_EXPORT_INTERNAL_SYMBOL(cn20k_cpt_crypto_adapter_dequeue)
958 : : uintptr_t
959 : 0 : cn20k_cpt_crypto_adapter_dequeue(uintptr_t get_work1)
960 : : {
961 : : struct cpt_inflight_req *infl_req;
962 : : struct rte_crypto_op *cop;
963 : : struct cnxk_cpt_qp *qp;
964 : : union cpt_res_s res;
965 : :
966 : 0 : infl_req = (struct cpt_inflight_req *)(get_work1);
967 : 0 : cop = infl_req->cop;
968 : 0 : qp = infl_req->qp;
969 : :
970 : 0 : res.u64[0] = rte_atomic_load_explicit((RTE_ATOMIC(uint64_t) *)(&infl_req->res.u64[0]),
971 : : rte_memory_order_relaxed);
972 : :
973 : 0 : cn20k_cpt_dequeue_post_process(qp, infl_req->cop, infl_req, &res.cn20k);
974 : :
975 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
976 [ # # ]: 0 : rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
977 : :
978 [ # # ]: 0 : rte_mempool_put(qp->ca.req_mp, infl_req);
979 : 0 : return (uintptr_t)cop;
980 : : }
981 : :
982 : : RTE_EXPORT_INTERNAL_SYMBOL(cn20k_cpt_crypto_adapter_vector_dequeue)
983 : : uintptr_t
984 : 0 : cn20k_cpt_crypto_adapter_vector_dequeue(uintptr_t get_work1)
985 : : {
986 : : struct rte_mempool *meta_mp, *req_mp;
987 : : struct cpt_inflight_req *infl_req;
988 : : struct rte_event_vector *vec;
989 : : struct rte_crypto_op *cop;
990 : : struct cnxk_cpt_qp *qp;
991 : : union cpt_res_s res;
992 : : int i;
993 : :
994 : 0 : vec = (struct rte_event_vector *)(get_work1);
995 : :
996 [ # # ]: 0 : for (i = 0; i < vec->nb_elem; i++) {
997 : 0 : infl_req = vec->ptrs[i];
998 : 0 : cop = infl_req->cop;
999 : 0 : qp = infl_req->qp;
1000 : 0 : meta_mp = qp->meta_info.pool;
1001 : 0 : req_mp = qp->ca.req_mp;
1002 : :
1003 : 0 : res.u64[0] = rte_atomic_load_explicit(
1004 : : (RTE_ATOMIC(uint64_t) *)(&infl_req->res.u64[0]), rte_memory_order_relaxed);
1005 : 0 : cn20k_cpt_dequeue_post_process(qp, cop, infl_req, &res.cn20k);
1006 : :
1007 : 0 : vec->ptrs[i] = cop;
1008 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
1009 [ # # ]: 0 : rte_mempool_put(meta_mp, infl_req->mdata);
1010 : :
1011 : 0 : rte_mempool_put(req_mp, infl_req);
1012 : : }
1013 : :
1014 : 0 : return (uintptr_t)vec;
1015 : : }
1016 : :
1017 : : static uint16_t
1018 : 0 : cn20k_cpt_dequeue_burst(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
1019 : : {
1020 : : struct cpt_inflight_req *infl_req;
1021 : : struct cnxk_cpt_qp *qp = qptr;
1022 : : struct pending_queue *pend_q;
1023 : : uint64_t infl_cnt, pq_tail;
1024 : : struct rte_crypto_op *cop;
1025 : : union cpt_res_s res;
1026 : : int i;
1027 : :
1028 : : pend_q = &qp->pend_q;
1029 : :
1030 : 0 : const uint64_t pq_mask = pend_q->pq_mask;
1031 : :
1032 : 0 : pq_tail = pend_q->tail;
1033 : 0 : infl_cnt = pending_queue_infl_cnt(pend_q->head, pq_tail, pq_mask);
1034 : 0 : nb_ops = RTE_MIN(nb_ops, infl_cnt);
1035 : :
1036 : : /* Ensure infl_cnt isn't read before data lands */
1037 : : rte_atomic_thread_fence(rte_memory_order_acquire);
1038 : :
1039 [ # # ]: 0 : for (i = 0; i < nb_ops; i++) {
1040 : 0 : infl_req = &pend_q->req_queue[pq_tail];
1041 : :
1042 : 0 : res.u64[0] = rte_atomic_load_explicit(
1043 : : (RTE_ATOMIC(uint64_t) *)(&infl_req->res.u64[0]), rte_memory_order_relaxed);
1044 : :
1045 [ # # ]: 0 : if (unlikely(res.cn20k.compcode == CPT_COMP_NOT_DONE)) {
1046 [ # # ]: 0 : if (unlikely(rte_get_timer_cycles() > pend_q->time_out)) {
1047 : 0 : plt_err("Request timed out");
1048 : 0 : cnxk_cpt_dump_on_err(qp);
1049 : 0 : pend_q->time_out = rte_get_timer_cycles() +
1050 : 0 : DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
1051 : : }
1052 : : break;
1053 : : }
1054 : :
1055 : : pending_queue_advance(&pq_tail, pq_mask);
1056 : :
1057 : 0 : cop = infl_req->cop;
1058 : :
1059 : 0 : ops[i] = cop;
1060 : :
1061 : 0 : cn20k_cpt_dequeue_post_process(qp, cop, infl_req, &res.cn20k);
1062 : :
1063 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
1064 [ # # ]: 0 : rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
1065 : : }
1066 : :
1067 : 0 : pend_q->tail = pq_tail;
1068 : :
1069 : 0 : return i;
1070 : : }
1071 : :
1072 : : void
1073 : 0 : cn20k_cpt_set_enqdeq_fns(struct rte_cryptodev *dev)
1074 : : {
1075 : 0 : dev->enqueue_burst = cn20k_cpt_enqueue_burst;
1076 : 0 : dev->dequeue_burst = cn20k_cpt_dequeue_burst;
1077 : :
1078 : : rte_mb();
1079 : 0 : }
1080 : :
1081 : : static void
1082 : 0 : cn20k_cpt_dev_info_get(struct rte_cryptodev *dev, struct rte_cryptodev_info *info)
1083 : : {
1084 [ # # ]: 0 : if (info != NULL) {
1085 : 0 : cnxk_cpt_dev_info_get(dev, info);
1086 : 0 : info->driver_id = cn20k_cryptodev_driver_id;
1087 : : }
1088 : 0 : }
1089 : :
1090 : : static inline int
1091 : 0 : cn20k_cpt_raw_fill_inst(struct cnxk_iov *iov, struct cnxk_cpt_qp *qp,
1092 : : struct cnxk_sym_dp_ctx *dp_ctx, struct cpt_inst_s inst[],
1093 : : struct cpt_inflight_req *infl_req, void *opaque)
1094 : : {
1095 : : struct cnxk_se_sess *sess;
1096 : : int ret;
1097 : :
1098 : : const union cpt_res_s res = {
1099 : : .cn20k.compcode = CPT_COMP_NOT_DONE,
1100 : : };
1101 : :
1102 : 0 : inst[0].w0.u64 = 0;
1103 : 0 : inst[0].w2.u64 = 0;
1104 : 0 : inst[0].w3.u64 = 0;
1105 : :
1106 : 0 : sess = dp_ctx->sess;
1107 : :
1108 [ # # # # : 0 : switch (sess->dp_thr_type) {
# ]
1109 : 0 : case CPT_DP_THREAD_TYPE_PT:
1110 : 0 : ret = fill_raw_passthrough_params(iov, inst);
1111 : 0 : break;
1112 [ # # ]: 0 : case CPT_DP_THREAD_TYPE_FC_CHAIN:
1113 : : ret = fill_raw_fc_params(iov, sess, &qp->meta_info, infl_req, &inst[0], false,
1114 : : false, true);
1115 : 0 : break;
1116 [ # # ]: 0 : case CPT_DP_THREAD_TYPE_FC_AEAD:
1117 : : ret = fill_raw_fc_params(iov, sess, &qp->meta_info, infl_req, &inst[0], false, true,
1118 : : true);
1119 : 0 : break;
1120 [ # # ]: 0 : case CPT_DP_THREAD_AUTH_ONLY:
1121 : : ret = fill_raw_digest_params(iov, sess, &qp->meta_info, infl_req, &inst[0], true,
1122 : : true);
1123 : 0 : break;
1124 : : default:
1125 : : ret = -EINVAL;
1126 : : }
1127 : :
1128 [ # # ]: 0 : if (unlikely(ret))
1129 : : return 0;
1130 : :
1131 : 0 : inst[0].res_addr = (uint64_t)&infl_req->res;
1132 : 0 : rte_atomic_store_explicit((RTE_ATOMIC(uint64_t) *)(&infl_req->res.u64[0]), res.u64[0],
1133 : : rte_memory_order_relaxed);
1134 : 0 : infl_req->opaque = opaque;
1135 : :
1136 : 0 : inst[0].w7.u64 = sess->cpt_inst_w7;
1137 : :
1138 : 0 : return 1;
1139 : : }
1140 : :
1141 : : static uint32_t
1142 : 0 : cn20k_cpt_raw_enqueue_burst(void *qpair, uint8_t *drv_ctx, struct rte_crypto_sym_vec *vec,
1143 : : union rte_crypto_sym_ofs ofs, void *user_data[], int *enqueue_status)
1144 : : {
1145 : 0 : uint16_t lmt_id, nb_allowed, nb_ops = vec->num;
1146 : : struct cpt_inflight_req *infl_req;
1147 : : uint64_t lmt_base, io_addr, head;
1148 : : struct cnxk_cpt_qp *qp = qpair;
1149 : : struct cnxk_sym_dp_ctx *dp_ctx;
1150 : : struct pending_queue *pend_q;
1151 : : uint32_t count = 0, index;
1152 : : union cpt_fc_write_s fc;
1153 : : struct cpt_inst_s *inst;
1154 : : uint64_t *fc_addr;
1155 : : int ret, i;
1156 : :
1157 : : pend_q = &qp->pend_q;
1158 : 0 : const uint64_t pq_mask = pend_q->pq_mask;
1159 : :
1160 : 0 : head = pend_q->head;
1161 [ # # ]: 0 : nb_allowed = pending_queue_free_cnt(head, pend_q->tail, pq_mask);
1162 : 0 : nb_ops = RTE_MIN(nb_ops, nb_allowed);
1163 : :
1164 [ # # ]: 0 : if (unlikely(nb_ops == 0))
1165 : : return 0;
1166 : :
1167 : 0 : lmt_base = qp->lmtline.lmt_base;
1168 : : io_addr = qp->lmtline.io_addr;
1169 : 0 : fc_addr = qp->lmtline.fc_addr;
1170 : :
1171 : 0 : const uint32_t fc_thresh = qp->lmtline.fc_thresh;
1172 : :
1173 : : ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
1174 : 0 : inst = (struct cpt_inst_s *)lmt_base;
1175 : :
1176 : : dp_ctx = (struct cnxk_sym_dp_ctx *)drv_ctx;
1177 : 0 : again:
1178 : : fc.u64[0] =
1179 : 0 : rte_atomic_load_explicit((RTE_ATOMIC(uint64_t) *)fc_addr, rte_memory_order_relaxed);
1180 [ # # ]: 0 : if (unlikely(fc.s.qsize > fc_thresh)) {
1181 : : i = 0;
1182 : 0 : goto pend_q_commit;
1183 : : }
1184 : :
1185 [ # # ]: 0 : for (i = 0; i < RTE_MIN(CN20K_CPT_PKTS_PER_LOOP, nb_ops); i++) {
1186 : : struct cnxk_iov iov;
1187 : :
1188 : 0 : index = count + i;
1189 : 0 : infl_req = &pend_q->req_queue[head];
1190 : 0 : infl_req->op_flags = 0;
1191 : :
1192 : 0 : cnxk_raw_burst_to_iov(vec, &ofs, index, &iov);
1193 : 0 : ret = cn20k_cpt_raw_fill_inst(&iov, qp, dp_ctx, &inst[i], infl_req,
1194 : 0 : user_data[index]);
1195 [ # # ]: 0 : if (unlikely(ret != 1)) {
1196 : 0 : plt_dp_err("Could not process vec: %d", index);
1197 [ # # ]: 0 : if (i == 0 && count == 0)
1198 : 0 : return -1;
1199 [ # # ]: 0 : else if (i == 0)
1200 : 0 : goto pend_q_commit;
1201 : : else
1202 : : break;
1203 : : }
1204 : : pending_queue_advance(&head, pq_mask);
1205 : : }
1206 : :
1207 : : cn20k_cpt_lmtst_dual_submit(&io_addr, lmt_id, &i);
1208 : :
1209 [ # # # # ]: 0 : if (nb_ops - i > 0 && i == CN20K_CPT_PKTS_PER_LOOP) {
1210 : 0 : nb_ops -= i;
1211 : 0 : count += i;
1212 : 0 : goto again;
1213 : : }
1214 : :
1215 : 0 : pend_q_commit:
1216 : : rte_atomic_thread_fence(rte_memory_order_release);
1217 : :
1218 : 0 : pend_q->head = head;
1219 : 0 : pend_q->time_out = rte_get_timer_cycles() + DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
1220 : :
1221 : 0 : *enqueue_status = 1;
1222 : 0 : return count + i;
1223 : : }
1224 : :
1225 : : static int
1226 : 0 : cn20k_cpt_raw_enqueue(void *qpair, uint8_t *drv_ctx, struct rte_crypto_vec *data_vec,
1227 : : uint16_t n_data_vecs, union rte_crypto_sym_ofs ofs,
1228 : : struct rte_crypto_va_iova_ptr *iv, struct rte_crypto_va_iova_ptr *digest,
1229 : : struct rte_crypto_va_iova_ptr *aad_or_auth_iv, void *user_data)
1230 : : {
1231 : : struct cpt_inflight_req *infl_req;
1232 : : uint64_t lmt_base, io_addr, head;
1233 : : struct cnxk_cpt_qp *qp = qpair;
1234 : : struct cnxk_sym_dp_ctx *dp_ctx;
1235 : : uint16_t lmt_id, nb_allowed;
1236 : : struct cpt_inst_s *inst;
1237 : : union cpt_fc_write_s fc;
1238 : : struct cnxk_iov iov;
1239 : : uint64_t *fc_addr;
1240 : : int ret, i = 1;
1241 : :
1242 : : struct pending_queue *pend_q = &qp->pend_q;
1243 : 0 : const uint64_t pq_mask = pend_q->pq_mask;
1244 : 0 : const uint32_t fc_thresh = qp->lmtline.fc_thresh;
1245 : :
1246 : 0 : head = pend_q->head;
1247 [ # # ]: 0 : nb_allowed = pending_queue_free_cnt(head, pend_q->tail, pq_mask);
1248 : :
1249 [ # # ]: 0 : if (unlikely(nb_allowed == 0))
1250 : : return -1;
1251 : :
1252 : : cnxk_raw_to_iov(data_vec, n_data_vecs, &ofs, iv, digest, aad_or_auth_iv, &iov);
1253 : :
1254 : 0 : lmt_base = qp->lmtline.lmt_base;
1255 : : io_addr = qp->lmtline.io_addr;
1256 : 0 : fc_addr = qp->lmtline.fc_addr;
1257 : :
1258 : : ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
1259 : 0 : inst = (struct cpt_inst_s *)lmt_base;
1260 : :
1261 : : fc.u64[0] =
1262 : 0 : rte_atomic_load_explicit((RTE_ATOMIC(uint64_t) *)fc_addr, rte_memory_order_relaxed);
1263 [ # # ]: 0 : if (unlikely(fc.s.qsize > fc_thresh))
1264 : : return -1;
1265 : :
1266 : : dp_ctx = (struct cnxk_sym_dp_ctx *)drv_ctx;
1267 : 0 : infl_req = &pend_q->req_queue[head];
1268 : 0 : infl_req->op_flags = 0;
1269 : :
1270 : 0 : ret = cn20k_cpt_raw_fill_inst(&iov, qp, dp_ctx, &inst[0], infl_req, user_data);
1271 [ # # ]: 0 : if (unlikely(ret != 1)) {
1272 : 0 : plt_dp_err("Could not process vec");
1273 : 0 : return -1;
1274 : : }
1275 : :
1276 : : pending_queue_advance(&head, pq_mask);
1277 : :
1278 : : cn20k_cpt_lmtst_dual_submit(&io_addr, lmt_id, &i);
1279 : :
1280 : 0 : pend_q->head = head;
1281 : 0 : pend_q->time_out = rte_get_timer_cycles() + DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
1282 : :
1283 : 0 : return 1;
1284 : : }
1285 : :
1286 : : static inline int
1287 : 0 : cn20k_cpt_raw_dequeue_post_process(struct cpt_cn20k_res_s *res)
1288 : : {
1289 : 0 : const uint8_t uc_compcode = res->uc_compcode;
1290 : 0 : const uint8_t compcode = res->compcode;
1291 : : int ret = 1;
1292 : :
1293 [ # # ]: 0 : if (likely(compcode == CPT_COMP_GOOD)) {
1294 [ # # ]: 0 : if (unlikely(uc_compcode))
1295 : 0 : plt_dp_info("Request failed with microcode error: 0x%x", res->uc_compcode);
1296 : : else
1297 : : ret = 0;
1298 : : }
1299 : :
1300 : 0 : return ret;
1301 : : }
1302 : :
1303 : : static uint32_t
1304 : 0 : cn20k_cpt_sym_raw_dequeue_burst(void *qptr, uint8_t *drv_ctx,
1305 : : rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
1306 : : uint32_t max_nb_to_dequeue,
1307 : : rte_cryptodev_raw_post_dequeue_t post_dequeue, void **out_user_data,
1308 : : uint8_t is_user_data_array, uint32_t *n_success,
1309 : : int *dequeue_status)
1310 : : {
1311 : : struct cpt_inflight_req *infl_req;
1312 : : struct cnxk_cpt_qp *qp = qptr;
1313 : : struct pending_queue *pend_q;
1314 : : uint64_t infl_cnt, pq_tail;
1315 : : union cpt_res_s res;
1316 : : int is_op_success;
1317 : : uint16_t nb_ops;
1318 : : void *opaque;
1319 : : int i = 0;
1320 : :
1321 : : pend_q = &qp->pend_q;
1322 : :
1323 : 0 : const uint64_t pq_mask = pend_q->pq_mask;
1324 : :
1325 : : RTE_SET_USED(drv_ctx);
1326 : 0 : pq_tail = pend_q->tail;
1327 [ # # ]: 0 : infl_cnt = pending_queue_infl_cnt(pend_q->head, pq_tail, pq_mask);
1328 : :
1329 : : /* Ensure infl_cnt isn't read before data lands */
1330 : : rte_atomic_thread_fence(rte_memory_order_acquire);
1331 : :
1332 : 0 : infl_req = &pend_q->req_queue[pq_tail];
1333 : :
1334 : 0 : opaque = infl_req->opaque;
1335 [ # # ]: 0 : if (get_dequeue_count)
1336 : 0 : nb_ops = get_dequeue_count(opaque);
1337 : : else
1338 : 0 : nb_ops = max_nb_to_dequeue;
1339 : 0 : nb_ops = RTE_MIN(nb_ops, infl_cnt);
1340 : :
1341 [ # # ]: 0 : for (i = 0; i < nb_ops; i++) {
1342 : : is_op_success = 0;
1343 : 0 : infl_req = &pend_q->req_queue[pq_tail];
1344 : :
1345 : 0 : res.u64[0] = rte_atomic_load_explicit(
1346 : : (RTE_ATOMIC(uint64_t) *)(&infl_req->res.u64[0]), rte_memory_order_relaxed);
1347 : :
1348 [ # # ]: 0 : if (unlikely(res.cn20k.compcode == CPT_COMP_NOT_DONE)) {
1349 [ # # ]: 0 : if (unlikely(rte_get_timer_cycles() > pend_q->time_out)) {
1350 : 0 : plt_err("Request timed out");
1351 : 0 : cnxk_cpt_dump_on_err(qp);
1352 : 0 : pend_q->time_out = rte_get_timer_cycles() +
1353 : 0 : DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
1354 : : }
1355 : : break;
1356 : : }
1357 : :
1358 : : pending_queue_advance(&pq_tail, pq_mask);
1359 : :
1360 [ # # ]: 0 : if (!cn20k_cpt_raw_dequeue_post_process(&res.cn20k)) {
1361 : : is_op_success = 1;
1362 : 0 : *n_success += 1;
1363 : : }
1364 : :
1365 [ # # ]: 0 : if (is_user_data_array) {
1366 : 0 : out_user_data[i] = infl_req->opaque;
1367 : 0 : post_dequeue(out_user_data[i], i, is_op_success);
1368 : : } else {
1369 [ # # ]: 0 : if (i == 0)
1370 : 0 : out_user_data[0] = opaque;
1371 : 0 : post_dequeue(out_user_data[0], i, is_op_success);
1372 : : }
1373 : :
1374 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
1375 [ # # ]: 0 : rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
1376 : : }
1377 : :
1378 : 0 : pend_q->tail = pq_tail;
1379 : 0 : *dequeue_status = 1;
1380 : :
1381 : 0 : return i;
1382 : : }
1383 : :
1384 : : static void *
1385 : 0 : cn20k_cpt_sym_raw_dequeue(void *qptr, uint8_t *drv_ctx, int *dequeue_status,
1386 : : enum rte_crypto_op_status *op_status)
1387 : : {
1388 : : struct cpt_inflight_req *infl_req;
1389 : : struct cnxk_cpt_qp *qp = qptr;
1390 : : struct pending_queue *pend_q;
1391 : : uint64_t pq_tail;
1392 : : union cpt_res_s res;
1393 : : void *opaque = NULL;
1394 : :
1395 : : pend_q = &qp->pend_q;
1396 : :
1397 : : const uint64_t pq_mask = pend_q->pq_mask;
1398 : :
1399 : : RTE_SET_USED(drv_ctx);
1400 : :
1401 [ # # ]: 0 : pq_tail = pend_q->tail;
1402 : :
1403 : : rte_atomic_thread_fence(rte_memory_order_acquire);
1404 : :
1405 : 0 : infl_req = &pend_q->req_queue[pq_tail];
1406 : :
1407 : 0 : res.u64[0] = rte_atomic_load_explicit(
1408 : : (RTE_ATOMIC(uint64_t) *)(&infl_req->res.u64[0]), rte_memory_order_relaxed);
1409 : :
1410 [ # # ]: 0 : if (unlikely(res.cn20k.compcode == CPT_COMP_NOT_DONE)) {
1411 [ # # ]: 0 : if (unlikely(rte_get_timer_cycles() > pend_q->time_out)) {
1412 : 0 : plt_err("Request timed out");
1413 : 0 : cnxk_cpt_dump_on_err(qp);
1414 : 0 : pend_q->time_out = rte_get_timer_cycles() +
1415 : 0 : DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
1416 : : }
1417 : 0 : goto exit;
1418 : : }
1419 : :
1420 : : pending_queue_advance(&pq_tail, pq_mask);
1421 : :
1422 : 0 : opaque = infl_req->opaque;
1423 : :
1424 [ # # ]: 0 : if (!cn20k_cpt_raw_dequeue_post_process(&res.cn20k))
1425 : 0 : *op_status = RTE_CRYPTO_OP_STATUS_SUCCESS;
1426 : : else
1427 : 0 : *op_status = RTE_CRYPTO_OP_STATUS_ERROR;
1428 : :
1429 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
1430 [ # # ]: 0 : rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
1431 : :
1432 : 0 : *dequeue_status = 1;
1433 : 0 : exit:
1434 : 0 : return opaque;
1435 : : }
1436 : :
1437 : : static int
1438 : 0 : cn20k_sym_get_raw_dp_ctx_size(struct rte_cryptodev *dev __rte_unused)
1439 : : {
1440 : 0 : return sizeof(struct cnxk_sym_dp_ctx);
1441 : : }
1442 : :
1443 : : static int
1444 : 0 : cn20k_sym_configure_raw_dp_ctx(struct rte_cryptodev *dev, uint16_t qp_id,
1445 : : struct rte_crypto_raw_dp_ctx *raw_dp_ctx,
1446 : : enum rte_crypto_op_sess_type sess_type,
1447 : : union rte_cryptodev_session_ctx session_ctx, uint8_t is_update)
1448 : : {
1449 : 0 : struct cnxk_se_sess *sess = (struct cnxk_se_sess *)session_ctx.crypto_sess;
1450 : : struct cnxk_sym_dp_ctx *dp_ctx;
1451 : :
1452 [ # # ]: 0 : if (sess_type != RTE_CRYPTO_OP_WITH_SESSION)
1453 : : return -ENOTSUP;
1454 : :
1455 [ # # # # ]: 0 : if (sess == NULL || sess->roc_se_ctx == NULL)
1456 : : return -EINVAL;
1457 : :
1458 : 0 : if ((sess->dp_thr_type == CPT_DP_THREAD_TYPE_PDCP) ||
1459 : : (sess->dp_thr_type == CPT_DP_THREAD_TYPE_PDCP_CHAIN) ||
1460 [ # # ]: 0 : (sess->dp_thr_type == CPT_DP_THREAD_TYPE_KASUMI) ||
1461 : : (sess->dp_thr_type == CPT_DP_THREAD_TYPE_SM))
1462 : : return -ENOTSUP;
1463 : :
1464 [ # # ]: 0 : if ((sess->dp_thr_type == CPT_DP_THREAD_AUTH_ONLY) &&
1465 [ # # ]: 0 : ((sess->roc_se_ctx->fc_type == ROC_SE_KASUMI) ||
1466 : : (sess->roc_se_ctx->fc_type == ROC_SE_PDCP)))
1467 : : return -ENOTSUP;
1468 : :
1469 [ # # ]: 0 : if (sess->roc_se_ctx->hash_type == ROC_SE_SHA1_TYPE)
1470 : : return -ENOTSUP;
1471 : :
1472 : : dp_ctx = (struct cnxk_sym_dp_ctx *)raw_dp_ctx->drv_ctx_data;
1473 : 0 : dp_ctx->sess = sess;
1474 : :
1475 [ # # ]: 0 : if (!is_update) {
1476 : 0 : raw_dp_ctx->qp_data = (struct cnxk_cpt_qp *)dev->data->queue_pairs[qp_id];
1477 : 0 : raw_dp_ctx->dequeue = cn20k_cpt_sym_raw_dequeue;
1478 : 0 : raw_dp_ctx->dequeue_burst = cn20k_cpt_sym_raw_dequeue_burst;
1479 : 0 : raw_dp_ctx->enqueue = cn20k_cpt_raw_enqueue;
1480 : 0 : raw_dp_ctx->enqueue_burst = cn20k_cpt_raw_enqueue_burst;
1481 : : }
1482 : :
1483 : : return 0;
1484 : : }
1485 : :
1486 : : #if defined(RTE_ARCH_ARM64)
1487 : : RTE_EXPORT_INTERNAL_SYMBOL(cn20k_cryptodev_sec_inb_rx_inject)
1488 : : uint16_t __rte_hot
1489 : : cn20k_cryptodev_sec_inb_rx_inject(void *dev, struct rte_mbuf **pkts,
1490 : : struct rte_security_session **sess, uint16_t nb_pkts)
1491 : : {
1492 : : uint64_t lmt_base, io_addr, u64_0, u64_1, l2_len, pf_func;
1493 : : uint64x2_t inst_01, inst_23, inst_45, inst_67;
1494 : : struct cn20k_sec_session *sec_sess;
1495 : : struct rte_cryptodev *cdev = dev;
1496 : : union cpt_res_s *hw_res = NULL;
1497 : : uint16_t lmt_id, count = 0;
1498 : : struct cpt_inst_s *inst;
1499 : : union cpt_fc_write_s fc;
1500 : : struct cnxk_cpt_vf *vf;
1501 : : struct rte_mbuf *m;
1502 : : uint64_t u64_dptr;
1503 : : uint64_t *fc_addr;
1504 : : int i;
1505 : :
1506 : : vf = cdev->data->dev_private;
1507 : :
1508 : : lmt_base = vf->rx_inj_lmtline.lmt_base;
1509 : : io_addr = vf->rx_inj_lmtline.io_addr;
1510 : : fc_addr = vf->rx_inj_lmtline.fc_addr;
1511 : :
1512 : : ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
1513 : : pf_func = vf->rx_inj_sso_pf_func;
1514 : :
1515 : : const uint32_t fc_thresh = vf->rx_inj_lmtline.fc_thresh;
1516 : :
1517 : : again:
1518 : : fc.u64[0] =
1519 : : rte_atomic_load_explicit((RTE_ATOMIC(uint64_t) *)fc_addr, rte_memory_order_relaxed);
1520 : : inst = (struct cpt_inst_s *)lmt_base;
1521 : :
1522 : : i = 0;
1523 : :
1524 : : if (unlikely(fc.s.qsize > fc_thresh))
1525 : : goto exit;
1526 : :
1527 : : for (; i < RTE_MIN(CN20K_CPT_PKTS_PER_LOOP, nb_pkts); i++) {
1528 : :
1529 : : m = pkts[i];
1530 : : sec_sess = (struct cn20k_sec_session *)sess[i];
1531 : :
1532 : : if (unlikely(rte_pktmbuf_headroom(m) < 32)) {
1533 : : plt_dp_err("No space for CPT res_s");
1534 : : break;
1535 : : }
1536 : :
1537 : : l2_len = m->l2_len;
1538 : :
1539 : : *rte_security_dynfield(m) = (uint64_t)sec_sess->userdata;
1540 : :
1541 : : hw_res = rte_pktmbuf_mtod(m, void *);
1542 : : hw_res = RTE_PTR_SUB(hw_res, 32);
1543 : : hw_res = RTE_PTR_ALIGN_CEIL(hw_res, 16);
1544 : :
1545 : : /* Prepare CPT instruction */
1546 : : if (m->nb_segs > 1) {
1547 : : struct rte_mbuf *last = rte_pktmbuf_lastseg(m);
1548 : : uintptr_t dptr, rxphdr, wqe_hdr;
1549 : : uint16_t i;
1550 : :
1551 : : if ((m->nb_segs > CNXK_CPT_MAX_SG_SEGS) ||
1552 : : (rte_pktmbuf_tailroom(m) < CNXK_CPT_MIN_TAILROOM_REQ))
1553 : : goto exit;
1554 : :
1555 : : wqe_hdr = rte_pktmbuf_mtod_offset(last, uintptr_t, last->data_len);
1556 : : wqe_hdr += BIT_ULL(7);
1557 : : wqe_hdr = (wqe_hdr - 1) & ~(BIT_ULL(7) - 1);
1558 : :
1559 : : /* Pointer to WQE header */
1560 : : *(uint64_t *)(m + 1) = wqe_hdr;
1561 : :
1562 : : /* Reserve SG list after end of last mbuf data location. */
1563 : : rxphdr = wqe_hdr + 8;
1564 : : dptr = rxphdr + 7 * 8;
1565 : :
1566 : : /* Prepare Multiseg SG list */
1567 : : i = fill_sg2_comp_from_pkt((struct roc_sg2list_comp *)dptr, 0, m);
1568 : : u64_dptr = dptr | ((uint64_t)(i) << 60);
1569 : : } else {
1570 : : struct roc_sg2list_comp *sg2;
1571 : : uintptr_t dptr, wqe_hdr;
1572 : :
1573 : : /* Reserve space for WQE, NIX_RX_PARSE_S and SG_S.
1574 : : * Populate SG_S with num segs and seg length
1575 : : */
1576 : : wqe_hdr = (uintptr_t)(m + 1);
1577 : : *(uint64_t *)(m + 1) = wqe_hdr;
1578 : :
1579 : : sg2 = (struct roc_sg2list_comp *)(wqe_hdr + 8 * 8);
1580 : : sg2->u.s.len[0] = rte_pktmbuf_pkt_len(m);
1581 : : sg2->u.s.valid_segs = 1;
1582 : :
1583 : : dptr = (uint64_t)rte_pktmbuf_iova(m);
1584 : : u64_dptr = dptr;
1585 : : }
1586 : :
1587 : : /* Word 0 and 1 */
1588 : : inst_01 = vdupq_n_u64(0);
1589 : : u64_0 = pf_func << 48 | *(vf->rx_chan_base + m->port) << 4 | (l2_len - 2) << 24 |
1590 : : l2_len << 16;
1591 : : inst_01 = vsetq_lane_u64(u64_0, inst_01, 0);
1592 : : inst_01 = vsetq_lane_u64((uint64_t)hw_res, inst_01, 1);
1593 : : vst1q_u64(&inst->w0.u64, inst_01);
1594 : :
1595 : : /* Word 2 and 3 */
1596 : : inst_23 = vdupq_n_u64(0);
1597 : : u64_1 = (((uint64_t)m + sizeof(struct rte_mbuf)) >> 3) << 3 | 1;
1598 : : inst_23 = vsetq_lane_u64(u64_1, inst_23, 1);
1599 : : vst1q_u64(&inst->w2.u64, inst_23);
1600 : :
1601 : : /* Word 4 and 5 */
1602 : : inst_45 = vdupq_n_u64(0);
1603 : : u64_0 = sec_sess->inst.w4 | (rte_pktmbuf_pkt_len(m));
1604 : : inst_45 = vsetq_lane_u64(u64_0, inst_45, 0);
1605 : : inst_45 = vsetq_lane_u64(u64_dptr, inst_45, 1);
1606 : : vst1q_u64(&inst->w4.u64, inst_45);
1607 : :
1608 : : /* Word 6 and 7 */
1609 : : inst_67 = vdupq_n_u64(0);
1610 : : u64_1 = sec_sess->inst.w7;
1611 : : inst_67 = vsetq_lane_u64(u64_1, inst_67, 1);
1612 : : vst1q_u64(&inst->w6.u64, inst_67);
1613 : :
1614 : : inst++;
1615 : : }
1616 : :
1617 : : cn20k_cpt_lmtst_dual_submit(&io_addr, lmt_id, &i);
1618 : :
1619 : : if (nb_pkts - i > 0 && i == CN20K_CPT_PKTS_PER_LOOP) {
1620 : : nb_pkts -= CN20K_CPT_PKTS_PER_LOOP;
1621 : : pkts += CN20K_CPT_PKTS_PER_LOOP;
1622 : : count += CN20K_CPT_PKTS_PER_LOOP;
1623 : : sess += CN20K_CPT_PKTS_PER_LOOP;
1624 : : goto again;
1625 : : }
1626 : :
1627 : : exit:
1628 : : return count + i;
1629 : : }
1630 : : #else
1631 : : RTE_EXPORT_INTERNAL_SYMBOL(cn20k_cryptodev_sec_inb_rx_inject)
1632 : : uint16_t __rte_hot
1633 : 0 : cn20k_cryptodev_sec_inb_rx_inject(void *dev, struct rte_mbuf **pkts,
1634 : : struct rte_security_session **sess, uint16_t nb_pkts)
1635 : : {
1636 : : RTE_SET_USED(dev);
1637 : : RTE_SET_USED(pkts);
1638 : : RTE_SET_USED(sess);
1639 : : RTE_SET_USED(nb_pkts);
1640 : 0 : return 0;
1641 : : }
1642 : : #endif
1643 : :
1644 : : RTE_EXPORT_INTERNAL_SYMBOL(cn20k_cryptodev_sec_rx_inject_configure)
1645 : : int
1646 : 0 : cn20k_cryptodev_sec_rx_inject_configure(void *device, uint16_t port_id, bool enable)
1647 : : {
1648 : : struct rte_cryptodev *crypto_dev = device;
1649 : : struct rte_eth_dev *eth_dev;
1650 : : int ret;
1651 : :
1652 [ # # ]: 0 : if (!rte_eth_dev_is_valid_port(port_id))
1653 : : return -EINVAL;
1654 : :
1655 [ # # ]: 0 : if (!(crypto_dev->feature_flags & RTE_CRYPTODEV_FF_SECURITY_RX_INJECT))
1656 : : return -ENOTSUP;
1657 : :
1658 : : eth_dev = &rte_eth_devices[port_id];
1659 : :
1660 : 0 : ret = strncmp(eth_dev->device->driver->name, "net_cn20k", 8);
1661 [ # # ]: 0 : if (ret)
1662 : : return -ENOTSUP;
1663 : :
1664 : 0 : roc_idev_nix_rx_inject_set(port_id, enable);
1665 : :
1666 : 0 : return 0;
1667 : : }
1668 : :
1669 : : struct rte_cryptodev_ops cn20k_cpt_ops = {
1670 : : /* Device control ops */
1671 : : .dev_configure = cnxk_cpt_dev_config,
1672 : : .dev_start = cnxk_cpt_dev_start,
1673 : : .dev_stop = cnxk_cpt_dev_stop,
1674 : : .dev_close = cnxk_cpt_dev_close,
1675 : : .dev_infos_get = cn20k_cpt_dev_info_get,
1676 : :
1677 : : .stats_get = NULL,
1678 : : .stats_reset = NULL,
1679 : : .queue_pair_setup = cnxk_cpt_queue_pair_setup,
1680 : : .queue_pair_release = cnxk_cpt_queue_pair_release,
1681 : : .queue_pair_reset = cnxk_cpt_queue_pair_reset,
1682 : :
1683 : : /* Symmetric crypto ops */
1684 : : .sym_session_get_size = cnxk_cpt_sym_session_get_size,
1685 : : .sym_session_configure = cnxk_cpt_sym_session_configure,
1686 : : .sym_session_clear = cnxk_cpt_sym_session_clear,
1687 : :
1688 : : /* Asymmetric crypto ops */
1689 : : .asym_session_get_size = cnxk_ae_session_size_get,
1690 : : .asym_session_configure = cnxk_ae_session_cfg,
1691 : : .asym_session_clear = cnxk_ae_session_clear,
1692 : :
1693 : : /* Event crypto ops */
1694 : : .session_ev_mdata_set = cn20k_cpt_crypto_adapter_ev_mdata_set,
1695 : : .queue_pair_event_error_query = cnxk_cpt_queue_pair_event_error_query,
1696 : :
1697 : : /* Raw data-path API related operations */
1698 : : .sym_get_raw_dp_ctx_size = cn20k_sym_get_raw_dp_ctx_size,
1699 : : .sym_configure_raw_dp_ctx = cn20k_sym_configure_raw_dp_ctx,
1700 : : };
|