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 = qp->inst_cq_ena;
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 : :
708 [ # # # # ]: 0 : if (trim_len > m_len || m_len > mbuf->pkt_len) {
709 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
710 : 0 : cop->aux_flags = res->uc_compcode;
711 : 0 : return;
712 : : }
713 : :
714 : 0 : mac_offset = m_len - trim_len;
715 : 0 : pad_offset = mac_offset + mac_len;
716 : :
717 : : /* Handle Direct Mode */
718 [ # # ]: 0 : if (mbuf->next == NULL) {
719 : 0 : uint8_t *ptr = rte_pktmbuf_mtod_offset(mbuf, uint8_t *, pad_offset);
720 : :
721 [ # # ]: 0 : for (i = 0; i < pad_len; i++)
722 : 0 : pad_res |= ptr[i] ^ pad_val;
723 : :
724 [ # # ]: 0 : if (pad_res) {
725 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
726 : 0 : cop->aux_flags = res->uc_compcode;
727 : : }
728 : 0 : mbuf->pkt_len = m_len - trim_len;
729 : 0 : mbuf->data_len = m_len - trim_len;
730 : :
731 : 0 : return;
732 : : }
733 : :
734 : : /* Handle SG mode */
735 : : seg = mbuf;
736 [ # # ]: 0 : while (mac_offset >= seg->data_len) {
737 : 0 : mac_offset -= seg->data_len;
738 : 0 : seg = seg->next;
739 : : }
740 : :
741 : 0 : pad_offset = mac_offset + mac_len;
742 [ # # ]: 0 : while (pad_offset >= seg->data_len) {
743 : 0 : pad_offset -= seg->data_len;
744 : 0 : seg = seg->next;
745 : : }
746 : :
747 [ # # ]: 0 : while (pad_len != 0) {
748 : 0 : uint8_t *ptr = rte_pktmbuf_mtod_offset(seg, uint8_t *, pad_offset);
749 : 0 : uint8_t len = RTE_MIN(seg->data_len - pad_offset, pad_len);
750 : :
751 [ # # ]: 0 : for (i = 0; i < len; i++)
752 : 0 : pad_res |= ptr[i] ^ pad_val;
753 : :
754 : : pad_offset = 0;
755 : 0 : pad_len -= len;
756 : 0 : seg = seg->next;
757 : : }
758 : :
759 [ # # ]: 0 : if (pad_res) {
760 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
761 : 0 : cop->aux_flags = res->uc_compcode;
762 : : }
763 : :
764 : 0 : len_to_trim = mbuf->pkt_len - (m_len - trim_len);
765 : :
766 : : pktmbuf_trim_chain(mbuf, len_to_trim);
767 : : }
768 : :
769 : : /* TLS-1.3:
770 : : * Read from last until a non-zero value is encountered.
771 : : * Return the non zero value as the content type.
772 : : * Remove the MAC and content type and padding bytes.
773 : : */
774 : : static inline void
775 : 0 : cn20k_cpt_tls13_trim_mac(struct rte_crypto_op *cop, struct cpt_cn20k_res_s *res)
776 : : {
777 : 0 : uint16_t m_len = res->rlen, len_to_trim;
778 : 0 : struct rte_mbuf *mbuf = cop->sym->m_src;
779 : : struct rte_mbuf *seg = mbuf;
780 : : uint8_t *ptr, type = 0x0;
781 : : int len, i;
782 : :
783 [ # # ]: 0 : while (m_len && !type) {
784 : 0 : len = m_len;
785 : : seg = mbuf;
786 : :
787 : : /* get the last seg */
788 [ # # ]: 0 : while (len > seg->data_len) {
789 : 0 : len -= seg->data_len;
790 : 0 : seg = seg->next;
791 : : }
792 : :
793 : : /* walkthrough from last until a non zero value is found */
794 : 0 : ptr = rte_pktmbuf_mtod(seg, uint8_t *);
795 : : i = len;
796 [ # # # # ]: 0 : while (i && (ptr[--i] == 0))
797 : : ;
798 : :
799 : 0 : type = ptr[i];
800 : 0 : m_len -= len;
801 : : }
802 : :
803 : 0 : len_to_trim = mbuf->pkt_len - i;
804 : :
805 [ # # ]: 0 : if (type) {
806 : : pktmbuf_trim_chain(mbuf, len_to_trim);
807 : 0 : cop->param1.tls_record.content_type = type;
808 : : } else
809 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
810 : 0 : }
811 : :
812 : : static inline void
813 : 0 : cn20k_cpt_tls_post_process(struct rte_crypto_op *cop, struct cpt_cn20k_res_s *res,
814 : : struct cn20k_sec_session *sess)
815 : : {
816 : 0 : struct cn20k_tls_opt tls_opt = sess->tls_opt;
817 : 0 : struct rte_mbuf *mbuf = cop->sym->m_src;
818 : 0 : uint16_t m_len = res->rlen;
819 : :
820 [ # # ]: 0 : if (!res->uc_compcode) {
821 [ # # ]: 0 : if (mbuf->next == NULL)
822 : 0 : mbuf->data_len = m_len;
823 : 0 : mbuf->pkt_len = m_len;
824 : 0 : cop->param1.tls_record.content_type = (res->spi >> 24) & 0xff;
825 : 0 : return;
826 : : }
827 : :
828 : : /* Any error other than post process */
829 [ # # ]: 0 : if (res->uc_compcode != ROC_SE_ERR_SSL_POST_PROCESS) {
830 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
831 : 0 : cop->aux_flags = res->uc_compcode;
832 : 0 : plt_err("crypto op failed with UC compcode: 0x%x", res->uc_compcode);
833 : 0 : return;
834 : : }
835 : :
836 : : /* Extra padding scenario: Verify padding. Remove padding and MAC */
837 [ # # ]: 0 : if (tls_opt.tls_ver != RTE_SECURITY_VERSION_TLS_1_3)
838 : 0 : cn20k_cpt_tls12_trim_mac(cop, res, (uint8_t)tls_opt.mac_len);
839 : : else
840 : 0 : cn20k_cpt_tls13_trim_mac(cop, res);
841 : : }
842 : :
843 : : static inline void
844 : 0 : cn20k_cpt_sec_post_process(struct rte_crypto_op *cop, struct cpt_cn20k_res_s *res)
845 : : {
846 : : struct rte_crypto_sym_op *sym_op = cop->sym;
847 : : struct cn20k_sec_session *sess;
848 : :
849 : 0 : sess = sym_op->session;
850 [ # # ]: 0 : if (sess->proto == RTE_SECURITY_PROTOCOL_IPSEC)
851 : 0 : cn20k_cpt_ipsec_post_process(cop, res);
852 [ # # ]: 0 : else if (sess->proto == RTE_SECURITY_PROTOCOL_TLS_RECORD)
853 : 0 : cn20k_cpt_tls_post_process(cop, res, sess);
854 : 0 : }
855 : :
856 : : static inline void
857 : 0 : cn20k_cpt_dequeue_post_process(struct cnxk_cpt_qp *qp, struct rte_crypto_op *cop,
858 : : struct cpt_inflight_req *infl_req, struct cpt_cn20k_res_s *res)
859 : : {
860 : 0 : const uint8_t uc_compcode = res->uc_compcode;
861 : 0 : const uint8_t compcode = res->compcode;
862 : :
863 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
864 : :
865 [ # # ]: 0 : if (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
866 : : cop->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
867 [ # # ]: 0 : if (likely(compcode == CPT_COMP_GOOD || compcode == CPT_COMP_WARN)) {
868 : : /* Success with additional info */
869 : 0 : cn20k_cpt_sec_post_process(cop, res);
870 : : } else {
871 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
872 : 0 : plt_dp_info("HW completion code 0x%x", res->compcode);
873 [ # # ]: 0 : if (compcode == CPT_COMP_GOOD) {
874 : 0 : plt_dp_info("Request failed with microcode error");
875 : 0 : plt_dp_info("MC completion code 0x%x", uc_compcode);
876 : : }
877 : : }
878 : :
879 : 0 : return;
880 [ # # ]: 0 : } else if (cop->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC &&
881 : : cop->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
882 : : struct cnxk_ae_sess *sess;
883 : :
884 : 0 : sess = (struct cnxk_ae_sess *)cop->asym->session;
885 [ # # ]: 0 : if (sess->xfrm_type == RTE_CRYPTO_ASYM_XFORM_ECDH &&
886 [ # # ]: 0 : cop->asym->ecdh.ke_type == RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY) {
887 [ # # ]: 0 : if (likely(compcode == CPT_COMP_GOOD)) {
888 [ # # ]: 0 : if (uc_compcode == ROC_AE_ERR_ECC_POINT_NOT_ON_CURVE) {
889 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
890 : 0 : return;
891 [ # # ]: 0 : } else if (uc_compcode == ROC_AE_ERR_ECC_PAI) {
892 : : cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
893 : : return;
894 : : }
895 : : }
896 : : }
897 : : }
898 : :
899 [ # # ]: 0 : if (likely(compcode == CPT_COMP_GOOD)) {
900 : : #ifdef CPT_INST_DEBUG_ENABLE
901 : : cnxk_cpt_request_data_sgv2_mode_dump(infl_req->rptr, 0, infl_req->scatter_sz);
902 : : #endif
903 : :
904 [ # # ]: 0 : if (unlikely(uc_compcode)) {
905 [ # # ]: 0 : if (uc_compcode == ROC_SE_ERR_GC_ICV_MISCOMPARE)
906 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
907 : : else
908 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
909 : :
910 : 0 : plt_dp_info("Request failed with microcode error");
911 : 0 : plt_dp_info("MC completion code 0x%x", res->uc_compcode);
912 : 0 : cop->aux_flags = uc_compcode;
913 : 0 : goto temp_sess_free;
914 : : }
915 : :
916 [ # # ]: 0 : if (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
917 : : /* Verify authentication data if required */
918 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_AUTH_VERIFY)) {
919 : 0 : uintptr_t *rsp = infl_req->mdata;
920 : :
921 [ # # ]: 0 : compl_auth_verify(cop, (uint8_t *)rsp[0], rsp[1]);
922 : : }
923 [ # # ]: 0 : } else if (cop->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
924 : : struct rte_crypto_asym_op *op = cop->asym;
925 : 0 : uintptr_t *mdata = infl_req->mdata;
926 : 0 : struct cnxk_ae_sess *sess = (struct cnxk_ae_sess *)op->session;
927 : :
928 [ # # # # : 0 : cnxk_ae_post_process(cop, sess, (uint8_t *)mdata[0]);
# # # # #
# ]
929 : : }
930 : : } else {
931 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
932 : 0 : plt_dp_info("HW completion code 0x%x", res->compcode);
933 : :
934 [ # # # # ]: 0 : switch (compcode) {
935 : 0 : case CPT_COMP_INSTERR:
936 : 0 : plt_dp_err("Request failed with instruction error");
937 : 0 : break;
938 : 0 : case CPT_COMP_FAULT:
939 : 0 : plt_dp_err("Request failed with DMA fault");
940 : 0 : break;
941 : 0 : case CPT_COMP_HWERR:
942 : 0 : plt_dp_err("Request failed with hardware error");
943 : 0 : break;
944 : 0 : default:
945 : 0 : plt_dp_err("Request failed with unknown completion code");
946 : : }
947 : : }
948 : :
949 : 0 : temp_sess_free:
950 [ # # ]: 0 : if (unlikely(cop->sess_type == RTE_CRYPTO_OP_SESSIONLESS)) {
951 [ # # ]: 0 : if (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
952 : 0 : sym_session_clear(cop->sym->session, true);
953 [ # # ]: 0 : rte_mempool_put(qp->sess_mp, cop->sym->session);
954 : 0 : cop->sym->session = NULL;
955 : : }
956 [ # # ]: 0 : if (cop->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
957 : 0 : cnxk_ae_session_clear(NULL, cop->asym->session);
958 [ # # ]: 0 : rte_mempool_put(qp->sess_mp, cop->asym->session);
959 : 0 : cop->asym->session = NULL;
960 : : }
961 : : }
962 : : }
963 : :
964 : : RTE_EXPORT_INTERNAL_SYMBOL(cn20k_cpt_crypto_adapter_dequeue)
965 : : uintptr_t
966 : 0 : cn20k_cpt_crypto_adapter_dequeue(uintptr_t get_work1)
967 : : {
968 : : struct cpt_inflight_req *infl_req;
969 : : struct rte_crypto_op *cop;
970 : : struct cnxk_cpt_qp *qp;
971 : : union cpt_res_s res;
972 : :
973 : 0 : infl_req = (struct cpt_inflight_req *)(get_work1);
974 : 0 : cop = infl_req->cop;
975 : 0 : qp = infl_req->qp;
976 : :
977 : 0 : res.u64[0] = rte_atomic_load_explicit((RTE_ATOMIC(uint64_t) *)(&infl_req->res.u64[0]),
978 : : rte_memory_order_relaxed);
979 : :
980 : 0 : cn20k_cpt_dequeue_post_process(qp, infl_req->cop, infl_req, &res.cn20k);
981 : :
982 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
983 [ # # ]: 0 : rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
984 : :
985 [ # # ]: 0 : rte_mempool_put(qp->ca.req_mp, infl_req);
986 : 0 : return (uintptr_t)cop;
987 : : }
988 : :
989 : : RTE_EXPORT_INTERNAL_SYMBOL(cn20k_cpt_crypto_adapter_vector_dequeue)
990 : : uintptr_t
991 : 0 : cn20k_cpt_crypto_adapter_vector_dequeue(uintptr_t get_work1)
992 : : {
993 : : struct rte_mempool *meta_mp, *req_mp;
994 : : struct cpt_inflight_req *infl_req;
995 : : struct rte_event_vector *vec;
996 : : struct rte_crypto_op *cop;
997 : : struct cnxk_cpt_qp *qp;
998 : : union cpt_res_s res;
999 : : int i;
1000 : :
1001 : 0 : vec = (struct rte_event_vector *)(get_work1);
1002 : :
1003 [ # # ]: 0 : for (i = 0; i < vec->nb_elem; i++) {
1004 : 0 : infl_req = vec->ptrs[i];
1005 : 0 : cop = infl_req->cop;
1006 : 0 : qp = infl_req->qp;
1007 : 0 : meta_mp = qp->meta_info.pool;
1008 : 0 : req_mp = qp->ca.req_mp;
1009 : :
1010 : 0 : res.u64[0] = rte_atomic_load_explicit(
1011 : : (RTE_ATOMIC(uint64_t) *)(&infl_req->res.u64[0]), rte_memory_order_relaxed);
1012 : 0 : cn20k_cpt_dequeue_post_process(qp, cop, infl_req, &res.cn20k);
1013 : :
1014 : 0 : vec->ptrs[i] = cop;
1015 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
1016 [ # # ]: 0 : rte_mempool_put(meta_mp, infl_req->mdata);
1017 : :
1018 : 0 : rte_mempool_put(req_mp, infl_req);
1019 : : }
1020 : :
1021 : 0 : return (uintptr_t)vec;
1022 : : }
1023 : :
1024 : : static uint16_t
1025 : 0 : cn20k_cpt_dequeue_burst(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
1026 : : {
1027 : : struct cpt_inflight_req *infl_req;
1028 : : struct cnxk_cpt_qp *qp = qptr;
1029 : : struct pending_queue *pend_q;
1030 : : uint64_t infl_cnt, pq_tail;
1031 : : struct rte_crypto_op *cop;
1032 : : union cpt_res_s res;
1033 : : int i;
1034 : :
1035 : : pend_q = &qp->pend_q;
1036 : :
1037 : 0 : const uint64_t pq_mask = pend_q->pq_mask;
1038 : :
1039 : 0 : pq_tail = pend_q->tail;
1040 : 0 : infl_cnt = pending_queue_infl_cnt(pend_q->head, pq_tail, pq_mask);
1041 : 0 : nb_ops = RTE_MIN(nb_ops, infl_cnt);
1042 : :
1043 : : /* Ensure infl_cnt isn't read before data lands */
1044 : : rte_atomic_thread_fence(rte_memory_order_acquire);
1045 : :
1046 [ # # ]: 0 : for (i = 0; i < nb_ops; i++) {
1047 : 0 : infl_req = &pend_q->req_queue[pq_tail];
1048 : :
1049 : 0 : res.u64[0] = rte_atomic_load_explicit(
1050 : : (RTE_ATOMIC(uint64_t) *)(&infl_req->res.u64[0]), rte_memory_order_relaxed);
1051 : :
1052 [ # # ]: 0 : if (unlikely(res.cn20k.compcode == CPT_COMP_NOT_DONE)) {
1053 [ # # ]: 0 : if (unlikely(rte_get_timer_cycles() > pend_q->time_out)) {
1054 : 0 : plt_err("Request timed out");
1055 : 0 : cnxk_cpt_dump_on_err(qp);
1056 : 0 : pend_q->time_out = rte_get_timer_cycles() +
1057 : 0 : DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
1058 : : }
1059 : : break;
1060 : : }
1061 : :
1062 : : pending_queue_advance(&pq_tail, pq_mask);
1063 : :
1064 : 0 : cop = infl_req->cop;
1065 : :
1066 : 0 : ops[i] = cop;
1067 : :
1068 : 0 : cn20k_cpt_dequeue_post_process(qp, cop, infl_req, &res.cn20k);
1069 : :
1070 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
1071 [ # # ]: 0 : rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
1072 : : }
1073 : :
1074 : 0 : pend_q->tail = pq_tail;
1075 : :
1076 : 0 : return i;
1077 : : }
1078 : :
1079 : : void
1080 : 0 : cn20k_cpt_set_enqdeq_fns(struct rte_cryptodev *dev)
1081 : : {
1082 : 0 : dev->enqueue_burst = cn20k_cpt_enqueue_burst;
1083 : 0 : dev->dequeue_burst = cn20k_cpt_dequeue_burst;
1084 : :
1085 : : rte_mb();
1086 : 0 : }
1087 : :
1088 : : static void
1089 : 0 : cn20k_cpt_dev_info_get(struct rte_cryptodev *dev, struct rte_cryptodev_info *info)
1090 : : {
1091 [ # # ]: 0 : if (info != NULL) {
1092 : 0 : cnxk_cpt_dev_info_get(dev, info);
1093 : 0 : info->driver_id = cn20k_cryptodev_driver_id;
1094 : : }
1095 : 0 : }
1096 : :
1097 : : static inline int
1098 : 0 : cn20k_cpt_raw_fill_inst(struct cnxk_iov *iov, struct cnxk_cpt_qp *qp,
1099 : : struct cnxk_sym_dp_ctx *dp_ctx, struct cpt_inst_s inst[],
1100 : : struct cpt_inflight_req *infl_req, void *opaque)
1101 : : {
1102 : : struct cnxk_se_sess *sess;
1103 : : int ret;
1104 : :
1105 : : const union cpt_res_s res = {
1106 : : .cn20k.compcode = CPT_COMP_NOT_DONE,
1107 : : };
1108 : :
1109 : 0 : inst[0].w0.u64 = 0;
1110 : 0 : inst[0].w2.u64 = 0;
1111 : 0 : inst[0].w3.u64 = 0;
1112 : :
1113 : 0 : sess = dp_ctx->sess;
1114 : :
1115 [ # # # # : 0 : switch (sess->dp_thr_type) {
# ]
1116 : 0 : case CPT_DP_THREAD_TYPE_PT:
1117 : 0 : ret = fill_raw_passthrough_params(iov, inst);
1118 : 0 : break;
1119 [ # # ]: 0 : case CPT_DP_THREAD_TYPE_FC_CHAIN:
1120 : : ret = fill_raw_fc_params(iov, sess, &qp->meta_info, infl_req, &inst[0], false,
1121 : : false, true);
1122 : 0 : break;
1123 [ # # ]: 0 : case CPT_DP_THREAD_TYPE_FC_AEAD:
1124 : : ret = fill_raw_fc_params(iov, sess, &qp->meta_info, infl_req, &inst[0], false, true,
1125 : : true);
1126 : 0 : break;
1127 [ # # ]: 0 : case CPT_DP_THREAD_AUTH_ONLY:
1128 : : ret = fill_raw_digest_params(iov, sess, &qp->meta_info, infl_req, &inst[0], true,
1129 : : true);
1130 : 0 : break;
1131 : : default:
1132 : : ret = -EINVAL;
1133 : : }
1134 : :
1135 [ # # ]: 0 : if (unlikely(ret))
1136 : : return 0;
1137 : :
1138 : 0 : inst[0].res_addr = (uint64_t)&infl_req->res;
1139 : 0 : rte_atomic_store_explicit((RTE_ATOMIC(uint64_t) *)(&infl_req->res.u64[0]), res.u64[0],
1140 : : rte_memory_order_relaxed);
1141 : 0 : infl_req->opaque = opaque;
1142 : :
1143 : 0 : inst[0].w7.u64 = sess->cpt_inst_w7;
1144 : :
1145 : 0 : return 1;
1146 : : }
1147 : :
1148 : : static uint32_t
1149 : 0 : cn20k_cpt_raw_enqueue_burst(void *qpair, uint8_t *drv_ctx, struct rte_crypto_sym_vec *vec,
1150 : : union rte_crypto_sym_ofs ofs, void *user_data[], int *enqueue_status)
1151 : : {
1152 : 0 : uint16_t lmt_id, nb_allowed, nb_ops = vec->num;
1153 : : struct cpt_inflight_req *infl_req;
1154 : : uint64_t lmt_base, io_addr, head;
1155 : : struct cnxk_cpt_qp *qp = qpair;
1156 : : struct cnxk_sym_dp_ctx *dp_ctx;
1157 : : struct pending_queue *pend_q;
1158 : : uint32_t count = 0, index;
1159 : : union cpt_fc_write_s fc;
1160 : : struct cpt_inst_s *inst;
1161 : : uint64_t *fc_addr;
1162 : : int ret, i;
1163 : :
1164 : : pend_q = &qp->pend_q;
1165 : 0 : const uint64_t pq_mask = pend_q->pq_mask;
1166 : :
1167 : 0 : head = pend_q->head;
1168 [ # # ]: 0 : nb_allowed = pending_queue_free_cnt(head, pend_q->tail, pq_mask);
1169 : 0 : nb_ops = RTE_MIN(nb_ops, nb_allowed);
1170 : :
1171 [ # # ]: 0 : if (unlikely(nb_ops == 0))
1172 : : return 0;
1173 : :
1174 : 0 : lmt_base = qp->lmtline.lmt_base;
1175 : : io_addr = qp->lmtline.io_addr;
1176 : 0 : fc_addr = qp->lmtline.fc_addr;
1177 : :
1178 : 0 : const uint32_t fc_thresh = qp->lmtline.fc_thresh;
1179 : :
1180 : : ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
1181 : 0 : inst = (struct cpt_inst_s *)lmt_base;
1182 : :
1183 : : dp_ctx = (struct cnxk_sym_dp_ctx *)drv_ctx;
1184 : 0 : again:
1185 : : fc.u64[0] =
1186 : 0 : rte_atomic_load_explicit((RTE_ATOMIC(uint64_t) *)fc_addr, rte_memory_order_relaxed);
1187 [ # # ]: 0 : if (unlikely(fc.s.qsize > fc_thresh)) {
1188 : : i = 0;
1189 : 0 : goto pend_q_commit;
1190 : : }
1191 : :
1192 [ # # ]: 0 : for (i = 0; i < RTE_MIN(CN20K_CPT_PKTS_PER_LOOP, nb_ops); i++) {
1193 : : struct cnxk_iov iov;
1194 : :
1195 : 0 : index = count + i;
1196 : 0 : infl_req = &pend_q->req_queue[head];
1197 : 0 : infl_req->op_flags = 0;
1198 : :
1199 [ # # ]: 0 : ret = cnxk_raw_burst_to_iov(vec, &ofs, index, &iov);
1200 [ # # ]: 0 : if (unlikely(ret != 0)) {
1201 : 0 : plt_dp_err("Failed to convert raw to iov: %d", index);
1202 [ # # ]: 0 : if (i == 0 && count == 0) {
1203 : 0 : *enqueue_status = ret;
1204 : 0 : return 0;
1205 [ # # ]: 0 : } else if (i == 0) {
1206 : 0 : goto pend_q_commit;
1207 : : } else {
1208 : : break;
1209 : : }
1210 : : }
1211 : 0 : ret = cn20k_cpt_raw_fill_inst(&iov, qp, dp_ctx, &inst[i], infl_req,
1212 : 0 : user_data[index]);
1213 [ # # ]: 0 : if (unlikely(ret != 1)) {
1214 : 0 : plt_dp_err("Could not process vec: %d", index);
1215 [ # # ]: 0 : if (i == 0 && count == 0) {
1216 : 0 : *enqueue_status = -EINVAL;
1217 : 0 : return 0;
1218 [ # # ]: 0 : } else if (i == 0) {
1219 : 0 : goto pend_q_commit;
1220 : : } else {
1221 : : break;
1222 : : }
1223 : : }
1224 : : pending_queue_advance(&head, pq_mask);
1225 : : }
1226 : :
1227 : : cn20k_cpt_lmtst_dual_submit(&io_addr, lmt_id, &i);
1228 : :
1229 [ # # # # ]: 0 : if (nb_ops - i > 0 && i == CN20K_CPT_PKTS_PER_LOOP) {
1230 : 0 : nb_ops -= i;
1231 : 0 : count += i;
1232 : 0 : goto again;
1233 : : }
1234 : :
1235 : 0 : pend_q_commit:
1236 : : rte_atomic_thread_fence(rte_memory_order_release);
1237 : :
1238 : 0 : pend_q->head = head;
1239 : 0 : pend_q->time_out = rte_get_timer_cycles() + DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
1240 : :
1241 : 0 : *enqueue_status = 1;
1242 : 0 : return count + i;
1243 : : }
1244 : :
1245 : : static int
1246 : 0 : cn20k_cpt_raw_enqueue(void *qpair, uint8_t *drv_ctx, struct rte_crypto_vec *data_vec,
1247 : : uint16_t n_data_vecs, union rte_crypto_sym_ofs ofs,
1248 : : struct rte_crypto_va_iova_ptr *iv, struct rte_crypto_va_iova_ptr *digest,
1249 : : struct rte_crypto_va_iova_ptr *aad_or_auth_iv, void *user_data)
1250 : : {
1251 : : struct cpt_inflight_req *infl_req;
1252 : : uint64_t lmt_base, io_addr, head;
1253 : : struct cnxk_cpt_qp *qp = qpair;
1254 : : struct cnxk_sym_dp_ctx *dp_ctx;
1255 : : uint16_t lmt_id, nb_allowed;
1256 : : struct cpt_inst_s *inst;
1257 : : union cpt_fc_write_s fc;
1258 : : struct cnxk_iov iov;
1259 : : uint64_t *fc_addr;
1260 : : int ret, i = 1;
1261 : :
1262 : : struct pending_queue *pend_q = &qp->pend_q;
1263 : 0 : const uint64_t pq_mask = pend_q->pq_mask;
1264 : 0 : const uint32_t fc_thresh = qp->lmtline.fc_thresh;
1265 : :
1266 : 0 : head = pend_q->head;
1267 [ # # ]: 0 : nb_allowed = pending_queue_free_cnt(head, pend_q->tail, pq_mask);
1268 : :
1269 [ # # ]: 0 : if (unlikely(nb_allowed == 0))
1270 : : return -1;
1271 : :
1272 [ # # ]: 0 : ret = cnxk_raw_to_iov(data_vec, n_data_vecs, &ofs, iv, digest, aad_or_auth_iv, &iov);
1273 [ # # ]: 0 : if (unlikely(ret != 0)) {
1274 : 0 : plt_dp_err("Failed to convert raw to iov");
1275 : 0 : return -1;
1276 : : }
1277 : :
1278 : 0 : lmt_base = qp->lmtline.lmt_base;
1279 : : io_addr = qp->lmtline.io_addr;
1280 : 0 : fc_addr = qp->lmtline.fc_addr;
1281 : :
1282 : : ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
1283 : 0 : inst = (struct cpt_inst_s *)lmt_base;
1284 : :
1285 : : fc.u64[0] =
1286 : 0 : rte_atomic_load_explicit((RTE_ATOMIC(uint64_t) *)fc_addr, rte_memory_order_relaxed);
1287 [ # # ]: 0 : if (unlikely(fc.s.qsize > fc_thresh))
1288 : : return -1;
1289 : :
1290 : : dp_ctx = (struct cnxk_sym_dp_ctx *)drv_ctx;
1291 : 0 : infl_req = &pend_q->req_queue[head];
1292 : 0 : infl_req->op_flags = 0;
1293 : :
1294 : 0 : ret = cn20k_cpt_raw_fill_inst(&iov, qp, dp_ctx, &inst[0], infl_req, user_data);
1295 [ # # ]: 0 : if (unlikely(ret != 1)) {
1296 : 0 : plt_dp_err("Could not process vec");
1297 : 0 : return -1;
1298 : : }
1299 : :
1300 : : pending_queue_advance(&head, pq_mask);
1301 : :
1302 : : cn20k_cpt_lmtst_dual_submit(&io_addr, lmt_id, &i);
1303 : :
1304 : 0 : pend_q->head = head;
1305 : 0 : pend_q->time_out = rte_get_timer_cycles() + DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
1306 : :
1307 : 0 : return 1;
1308 : : }
1309 : :
1310 : : static inline int
1311 : 0 : cn20k_cpt_raw_dequeue_post_process(struct cpt_cn20k_res_s *res)
1312 : : {
1313 : 0 : const uint8_t uc_compcode = res->uc_compcode;
1314 : 0 : const uint8_t compcode = res->compcode;
1315 : : int ret = 1;
1316 : :
1317 [ # # ]: 0 : if (likely(compcode == CPT_COMP_GOOD)) {
1318 [ # # ]: 0 : if (unlikely(uc_compcode))
1319 : 0 : plt_dp_info("Request failed with microcode error: 0x%x", res->uc_compcode);
1320 : : else
1321 : : ret = 0;
1322 : : }
1323 : :
1324 : 0 : return ret;
1325 : : }
1326 : :
1327 : : static uint32_t
1328 : 0 : cn20k_cpt_sym_raw_dequeue_burst(void *qptr, uint8_t *drv_ctx,
1329 : : rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
1330 : : uint32_t max_nb_to_dequeue,
1331 : : rte_cryptodev_raw_post_dequeue_t post_dequeue, void **out_user_data,
1332 : : uint8_t is_user_data_array, uint32_t *n_success,
1333 : : int *dequeue_status)
1334 : : {
1335 : : struct cpt_inflight_req *infl_req;
1336 : : struct cnxk_cpt_qp *qp = qptr;
1337 : : struct pending_queue *pend_q;
1338 : : uint64_t infl_cnt, pq_tail;
1339 : : union cpt_res_s res;
1340 : : int is_op_success;
1341 : : uint16_t nb_ops;
1342 : : void *opaque;
1343 : : int i = 0;
1344 : :
1345 : : pend_q = &qp->pend_q;
1346 : :
1347 : 0 : const uint64_t pq_mask = pend_q->pq_mask;
1348 : :
1349 : : RTE_SET_USED(drv_ctx);
1350 : 0 : pq_tail = pend_q->tail;
1351 [ # # ]: 0 : infl_cnt = pending_queue_infl_cnt(pend_q->head, pq_tail, pq_mask);
1352 : :
1353 : : /* Ensure infl_cnt isn't read before data lands */
1354 : : rte_atomic_thread_fence(rte_memory_order_acquire);
1355 : :
1356 : 0 : infl_req = &pend_q->req_queue[pq_tail];
1357 : :
1358 : 0 : opaque = infl_req->opaque;
1359 [ # # ]: 0 : if (get_dequeue_count)
1360 : 0 : nb_ops = get_dequeue_count(opaque);
1361 : : else
1362 : 0 : nb_ops = max_nb_to_dequeue;
1363 : 0 : nb_ops = RTE_MIN(nb_ops, infl_cnt);
1364 : :
1365 [ # # ]: 0 : for (i = 0; i < nb_ops; i++) {
1366 : : is_op_success = 0;
1367 : 0 : infl_req = &pend_q->req_queue[pq_tail];
1368 : :
1369 : 0 : res.u64[0] = rte_atomic_load_explicit(
1370 : : (RTE_ATOMIC(uint64_t) *)(&infl_req->res.u64[0]), rte_memory_order_relaxed);
1371 : :
1372 [ # # ]: 0 : if (unlikely(res.cn20k.compcode == CPT_COMP_NOT_DONE)) {
1373 [ # # ]: 0 : if (unlikely(rte_get_timer_cycles() > pend_q->time_out)) {
1374 : 0 : plt_err("Request timed out");
1375 : 0 : cnxk_cpt_dump_on_err(qp);
1376 : 0 : pend_q->time_out = rte_get_timer_cycles() +
1377 : 0 : DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
1378 : : }
1379 : : break;
1380 : : }
1381 : :
1382 : : pending_queue_advance(&pq_tail, pq_mask);
1383 : :
1384 [ # # ]: 0 : if (!cn20k_cpt_raw_dequeue_post_process(&res.cn20k)) {
1385 : : is_op_success = 1;
1386 : 0 : *n_success += 1;
1387 : : }
1388 : :
1389 [ # # ]: 0 : if (is_user_data_array) {
1390 : 0 : out_user_data[i] = infl_req->opaque;
1391 : 0 : post_dequeue(out_user_data[i], i, is_op_success);
1392 : : } else {
1393 [ # # ]: 0 : if (i == 0)
1394 : 0 : out_user_data[0] = opaque;
1395 : 0 : post_dequeue(out_user_data[0], i, is_op_success);
1396 : : }
1397 : :
1398 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
1399 [ # # ]: 0 : rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
1400 : : }
1401 : :
1402 : 0 : pend_q->tail = pq_tail;
1403 : 0 : *dequeue_status = 1;
1404 : :
1405 : 0 : return i;
1406 : : }
1407 : :
1408 : : static void *
1409 : 0 : cn20k_cpt_sym_raw_dequeue(void *qptr, uint8_t *drv_ctx, int *dequeue_status,
1410 : : enum rte_crypto_op_status *op_status)
1411 : : {
1412 : : struct cpt_inflight_req *infl_req;
1413 : : struct cnxk_cpt_qp *qp = qptr;
1414 : : struct pending_queue *pend_q;
1415 : : uint64_t pq_tail;
1416 : : union cpt_res_s res;
1417 : : void *opaque = NULL;
1418 : :
1419 : : pend_q = &qp->pend_q;
1420 : :
1421 : 0 : const uint64_t pq_mask = pend_q->pq_mask;
1422 : :
1423 : : RTE_SET_USED(drv_ctx);
1424 : :
1425 [ # # ]: 0 : pq_tail = pend_q->tail;
1426 : :
1427 : : rte_atomic_thread_fence(rte_memory_order_acquire);
1428 : :
1429 : 0 : infl_req = &pend_q->req_queue[pq_tail];
1430 : :
1431 : 0 : res.u64[0] = rte_atomic_load_explicit(
1432 : : (RTE_ATOMIC(uint64_t) *)(&infl_req->res.u64[0]), rte_memory_order_relaxed);
1433 : :
1434 [ # # ]: 0 : if (unlikely(res.cn20k.compcode == CPT_COMP_NOT_DONE)) {
1435 [ # # ]: 0 : if (unlikely(rte_get_timer_cycles() > pend_q->time_out)) {
1436 : 0 : plt_err("Request timed out");
1437 : 0 : cnxk_cpt_dump_on_err(qp);
1438 : 0 : pend_q->time_out = rte_get_timer_cycles() +
1439 : 0 : DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
1440 : : }
1441 : 0 : goto exit;
1442 : : }
1443 : :
1444 : : pending_queue_advance(&pq_tail, pq_mask);
1445 : :
1446 : 0 : opaque = infl_req->opaque;
1447 : :
1448 [ # # ]: 0 : if (!cn20k_cpt_raw_dequeue_post_process(&res.cn20k))
1449 : 0 : *op_status = RTE_CRYPTO_OP_STATUS_SUCCESS;
1450 : : else
1451 : 0 : *op_status = RTE_CRYPTO_OP_STATUS_ERROR;
1452 : :
1453 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
1454 [ # # ]: 0 : rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
1455 : :
1456 : 0 : pend_q->tail = pq_tail;
1457 : 0 : *dequeue_status = 1;
1458 : 0 : exit:
1459 : 0 : return opaque;
1460 : : }
1461 : :
1462 : : static int
1463 : 0 : cn20k_sym_get_raw_dp_ctx_size(struct rte_cryptodev *dev __rte_unused)
1464 : : {
1465 : 0 : return sizeof(struct cnxk_sym_dp_ctx);
1466 : : }
1467 : :
1468 : : static int
1469 : 0 : cn20k_sym_configure_raw_dp_ctx(struct rte_cryptodev *dev, uint16_t qp_id,
1470 : : struct rte_crypto_raw_dp_ctx *raw_dp_ctx,
1471 : : enum rte_crypto_op_sess_type sess_type,
1472 : : union rte_cryptodev_session_ctx session_ctx, uint8_t is_update)
1473 : : {
1474 : 0 : struct cnxk_se_sess *sess = (struct cnxk_se_sess *)session_ctx.crypto_sess;
1475 : : struct cnxk_sym_dp_ctx *dp_ctx;
1476 : :
1477 [ # # ]: 0 : if (sess_type != RTE_CRYPTO_OP_WITH_SESSION)
1478 : : return -ENOTSUP;
1479 : :
1480 [ # # # # ]: 0 : if (sess == NULL || sess->roc_se_ctx == NULL)
1481 : : return -EINVAL;
1482 : :
1483 : 0 : if ((sess->dp_thr_type == CPT_DP_THREAD_TYPE_PDCP) ||
1484 : : (sess->dp_thr_type == CPT_DP_THREAD_TYPE_PDCP_CHAIN) ||
1485 [ # # ]: 0 : (sess->dp_thr_type == CPT_DP_THREAD_TYPE_KASUMI) ||
1486 : : (sess->dp_thr_type == CPT_DP_THREAD_TYPE_SM))
1487 : : return -ENOTSUP;
1488 : :
1489 [ # # ]: 0 : if ((sess->dp_thr_type == CPT_DP_THREAD_AUTH_ONLY) &&
1490 [ # # ]: 0 : ((sess->roc_se_ctx->fc_type == ROC_SE_KASUMI) ||
1491 : : (sess->roc_se_ctx->fc_type == ROC_SE_PDCP)))
1492 : : return -ENOTSUP;
1493 : :
1494 [ # # ]: 0 : if (sess->roc_se_ctx->hash_type == ROC_SE_SHA1_TYPE)
1495 : : return -ENOTSUP;
1496 : :
1497 : : dp_ctx = (struct cnxk_sym_dp_ctx *)raw_dp_ctx->drv_ctx_data;
1498 : 0 : dp_ctx->sess = sess;
1499 : :
1500 [ # # ]: 0 : if (!is_update) {
1501 : 0 : raw_dp_ctx->qp_data = (struct cnxk_cpt_qp *)dev->data->queue_pairs[qp_id];
1502 : 0 : raw_dp_ctx->dequeue = cn20k_cpt_sym_raw_dequeue;
1503 : 0 : raw_dp_ctx->dequeue_burst = cn20k_cpt_sym_raw_dequeue_burst;
1504 : 0 : raw_dp_ctx->enqueue = cn20k_cpt_raw_enqueue;
1505 : 0 : raw_dp_ctx->enqueue_burst = cn20k_cpt_raw_enqueue_burst;
1506 : : }
1507 : :
1508 : : return 0;
1509 : : }
1510 : :
1511 : : #if defined(RTE_ARCH_ARM64)
1512 : : RTE_EXPORT_INTERNAL_SYMBOL(cn20k_cryptodev_sec_inb_rx_inject)
1513 : : uint16_t __rte_hot
1514 : : cn20k_cryptodev_sec_inb_rx_inject(void *dev, struct rte_mbuf **pkts,
1515 : : struct rte_security_session **sess, uint16_t nb_pkts)
1516 : : {
1517 : : uint64_t lmt_base, io_addr, u64_0, u64_1, l2_len, pf_func;
1518 : : uint64x2_t inst_01, inst_23, inst_45, inst_67;
1519 : : struct cn20k_sec_session *sec_sess;
1520 : : struct rte_cryptodev *cdev = dev;
1521 : : union cpt_res_s *hw_res = NULL;
1522 : : uint16_t lmt_id, count = 0;
1523 : : struct cpt_inst_s *inst;
1524 : : union cpt_fc_write_s fc;
1525 : : struct cnxk_cpt_vf *vf;
1526 : : struct rte_mbuf *m;
1527 : : uint64_t u64_dptr;
1528 : : uint64_t *fc_addr;
1529 : : int i;
1530 : :
1531 : : vf = cdev->data->dev_private;
1532 : :
1533 : : lmt_base = vf->rx_inj_lmtline.lmt_base;
1534 : : io_addr = vf->rx_inj_lmtline.io_addr;
1535 : : fc_addr = vf->rx_inj_lmtline.fc_addr;
1536 : :
1537 : : ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
1538 : : pf_func = vf->rx_inj_sso_pf_func;
1539 : :
1540 : : const uint32_t fc_thresh = vf->rx_inj_lmtline.fc_thresh;
1541 : :
1542 : : again:
1543 : : fc.u64[0] =
1544 : : rte_atomic_load_explicit((RTE_ATOMIC(uint64_t) *)fc_addr, rte_memory_order_relaxed);
1545 : : inst = (struct cpt_inst_s *)lmt_base;
1546 : :
1547 : : i = 0;
1548 : :
1549 : : if (unlikely(fc.s.qsize > fc_thresh))
1550 : : goto exit;
1551 : :
1552 : : for (; i < RTE_MIN(CN20K_CPT_PKTS_PER_LOOP, nb_pkts); i++) {
1553 : :
1554 : : m = pkts[i];
1555 : : sec_sess = (struct cn20k_sec_session *)sess[i];
1556 : :
1557 : : if (unlikely(rte_pktmbuf_headroom(m) < 32)) {
1558 : : plt_dp_err("No space for CPT res_s");
1559 : : break;
1560 : : }
1561 : :
1562 : : l2_len = m->l2_len;
1563 : :
1564 : : *rte_security_dynfield(m) = (uint64_t)sec_sess->userdata;
1565 : :
1566 : : hw_res = rte_pktmbuf_mtod(m, void *);
1567 : : hw_res = RTE_PTR_SUB(hw_res, 32);
1568 : : hw_res = RTE_PTR_ALIGN_CEIL(hw_res, 16);
1569 : :
1570 : : /* Prepare CPT instruction */
1571 : : if (m->nb_segs > 1) {
1572 : : struct rte_mbuf *last = rte_pktmbuf_lastseg(m);
1573 : : uintptr_t dptr, rxphdr, wqe_hdr;
1574 : : uint16_t i;
1575 : :
1576 : : if ((m->nb_segs > CNXK_CPT_MAX_SG_SEGS) ||
1577 : : (rte_pktmbuf_tailroom(m) < CNXK_CPT_MIN_TAILROOM_REQ))
1578 : : goto exit;
1579 : :
1580 : : wqe_hdr = rte_pktmbuf_mtod_offset(last, uintptr_t, last->data_len);
1581 : : wqe_hdr += BIT_ULL(7);
1582 : : wqe_hdr = (wqe_hdr - 1) & ~(BIT_ULL(7) - 1);
1583 : :
1584 : : /* Pointer to WQE header */
1585 : : *(uint64_t *)(m + 1) = wqe_hdr;
1586 : :
1587 : : /* Reserve SG list after end of last mbuf data location. */
1588 : : rxphdr = wqe_hdr + 8;
1589 : : dptr = rxphdr + 7 * 8;
1590 : :
1591 : : /* Prepare Multiseg SG list */
1592 : : i = fill_sg2_comp_from_pkt((struct roc_sg2list_comp *)dptr, 0, m);
1593 : : u64_dptr = dptr | ((uint64_t)(i) << 60);
1594 : : } else {
1595 : : struct roc_sg2list_comp *sg2;
1596 : : uintptr_t dptr, wqe_hdr;
1597 : :
1598 : : /* Reserve space for WQE, NIX_RX_PARSE_S and SG_S.
1599 : : * Populate SG_S with num segs and seg length
1600 : : */
1601 : : wqe_hdr = (uintptr_t)(m + 1);
1602 : : *(uint64_t *)(m + 1) = wqe_hdr;
1603 : :
1604 : : sg2 = (struct roc_sg2list_comp *)(wqe_hdr + 8 * 8);
1605 : : sg2->u.s.len[0] = rte_pktmbuf_pkt_len(m);
1606 : : sg2->u.s.valid_segs = 1;
1607 : :
1608 : : dptr = (uint64_t)rte_pktmbuf_iova(m);
1609 : : u64_dptr = dptr;
1610 : : }
1611 : :
1612 : : /* Word 0 and 1 */
1613 : : inst_01 = vdupq_n_u64(0);
1614 : : u64_0 = pf_func << 48 | *(vf->rx_chan_base + m->port) << 4 | (l2_len - 2) << 24 |
1615 : : l2_len << 16;
1616 : : inst_01 = vsetq_lane_u64(u64_0, inst_01, 0);
1617 : : inst_01 = vsetq_lane_u64((uint64_t)hw_res, inst_01, 1);
1618 : : vst1q_u64(&inst->w0.u64, inst_01);
1619 : :
1620 : : /* Word 2 and 3 */
1621 : : inst_23 = vdupq_n_u64(0);
1622 : : u64_1 = (((uint64_t)m + sizeof(struct rte_mbuf)) >> 3) << 3 | 1;
1623 : : inst_23 = vsetq_lane_u64(u64_1, inst_23, 1);
1624 : : vst1q_u64(&inst->w2.u64, inst_23);
1625 : :
1626 : : /* Word 4 and 5 */
1627 : : inst_45 = vdupq_n_u64(0);
1628 : : u64_0 = sec_sess->inst.w4 | (rte_pktmbuf_pkt_len(m));
1629 : : inst_45 = vsetq_lane_u64(u64_0, inst_45, 0);
1630 : : inst_45 = vsetq_lane_u64(u64_dptr, inst_45, 1);
1631 : : vst1q_u64(&inst->w4.u64, inst_45);
1632 : :
1633 : : /* Word 6 and 7 */
1634 : : inst_67 = vdupq_n_u64(0);
1635 : : u64_1 = sec_sess->inst.w7;
1636 : : inst_67 = vsetq_lane_u64(u64_1, inst_67, 1);
1637 : : vst1q_u64(&inst->w6.u64, inst_67);
1638 : :
1639 : : inst++;
1640 : : }
1641 : :
1642 : : cn20k_cpt_lmtst_dual_submit(&io_addr, lmt_id, &i);
1643 : :
1644 : : if (nb_pkts - i > 0 && i == CN20K_CPT_PKTS_PER_LOOP) {
1645 : : nb_pkts -= CN20K_CPT_PKTS_PER_LOOP;
1646 : : pkts += CN20K_CPT_PKTS_PER_LOOP;
1647 : : count += CN20K_CPT_PKTS_PER_LOOP;
1648 : : sess += CN20K_CPT_PKTS_PER_LOOP;
1649 : : goto again;
1650 : : }
1651 : :
1652 : : exit:
1653 : : return count + i;
1654 : : }
1655 : : #else
1656 : : RTE_EXPORT_INTERNAL_SYMBOL(cn20k_cryptodev_sec_inb_rx_inject)
1657 : : uint16_t __rte_hot
1658 : 0 : cn20k_cryptodev_sec_inb_rx_inject(void *dev, struct rte_mbuf **pkts,
1659 : : struct rte_security_session **sess, uint16_t nb_pkts)
1660 : : {
1661 : : RTE_SET_USED(dev);
1662 : : RTE_SET_USED(pkts);
1663 : : RTE_SET_USED(sess);
1664 : : RTE_SET_USED(nb_pkts);
1665 : 0 : return 0;
1666 : : }
1667 : : #endif
1668 : :
1669 : : RTE_EXPORT_INTERNAL_SYMBOL(cn20k_cryptodev_sec_rx_inject_configure)
1670 : : int
1671 : 0 : cn20k_cryptodev_sec_rx_inject_configure(void *device, uint16_t port_id, bool enable)
1672 : : {
1673 : : struct rte_cryptodev *crypto_dev = device;
1674 : : struct rte_eth_dev *eth_dev;
1675 : : int ret;
1676 : :
1677 [ # # ]: 0 : if (!rte_eth_dev_is_valid_port(port_id))
1678 : : return -EINVAL;
1679 : :
1680 [ # # ]: 0 : if (!(crypto_dev->feature_flags & RTE_CRYPTODEV_FF_SECURITY_RX_INJECT))
1681 : : return -ENOTSUP;
1682 : :
1683 : : eth_dev = &rte_eth_devices[port_id];
1684 : :
1685 : 0 : ret = strncmp(eth_dev->device->driver->name, "net_cn20k", 8);
1686 [ # # ]: 0 : if (ret)
1687 : : return -ENOTSUP;
1688 : :
1689 : 0 : roc_idev_nix_rx_inject_set(port_id, enable);
1690 : :
1691 : 0 : return 0;
1692 : : }
1693 : :
1694 : : struct rte_cryptodev_ops cn20k_cpt_ops = {
1695 : : /* Device control ops */
1696 : : .dev_configure = cnxk_cpt_dev_config,
1697 : : .dev_start = cnxk_cpt_dev_start,
1698 : : .dev_stop = cnxk_cpt_dev_stop,
1699 : : .dev_close = cnxk_cpt_dev_close,
1700 : : .dev_infos_get = cn20k_cpt_dev_info_get,
1701 : :
1702 : : .stats_get = NULL,
1703 : : .stats_reset = NULL,
1704 : : .queue_pair_setup = cnxk_cpt_queue_pair_setup,
1705 : : .queue_pair_release = cnxk_cpt_queue_pair_release,
1706 : : .queue_pair_reset = cnxk_cpt_queue_pair_reset,
1707 : :
1708 : : /* Symmetric crypto ops */
1709 : : .sym_session_get_size = cnxk_cpt_sym_session_get_size,
1710 : : .sym_session_configure = cnxk_cpt_sym_session_configure,
1711 : : .sym_session_clear = cnxk_cpt_sym_session_clear,
1712 : :
1713 : : /* Asymmetric crypto ops */
1714 : : .asym_session_get_size = cnxk_ae_session_size_get,
1715 : : .asym_session_configure = cnxk_ae_session_cfg,
1716 : : .asym_session_clear = cnxk_ae_session_clear,
1717 : :
1718 : : /* Event crypto ops */
1719 : : .session_ev_mdata_set = cn20k_cpt_crypto_adapter_ev_mdata_set,
1720 : : .queue_pair_event_error_query = cnxk_cpt_queue_pair_event_error_query,
1721 : :
1722 : : /* Raw data-path API related operations */
1723 : : .sym_get_raw_dp_ctx_size = cn20k_sym_get_raw_dp_ctx_size,
1724 : : .sym_configure_raw_dp_ctx = cn20k_sym_configure_raw_dp_ctx,
1725 : : };
|