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