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