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 : :
946 [ # # # # ]: 0 : if (trim_len > m_len || m_len > mbuf->pkt_len) {
947 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
948 : 0 : cop->aux_flags = res->uc_compcode;
949 : 0 : return;
950 : : }
951 : :
952 : 0 : mac_offset = m_len - trim_len;
953 : 0 : pad_offset = mac_offset + mac_len;
954 : :
955 : : /* Handle Direct Mode */
956 [ # # ]: 0 : if (mbuf->next == NULL) {
957 : 0 : uint8_t *ptr = rte_pktmbuf_mtod_offset(mbuf, uint8_t *, pad_offset);
958 : :
959 [ # # ]: 0 : for (i = 0; i < pad_len; i++)
960 : 0 : pad_res |= ptr[i] ^ pad_val;
961 : :
962 [ # # ]: 0 : if (pad_res) {
963 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
964 : 0 : cop->aux_flags = res->uc_compcode;
965 : : }
966 : 0 : mbuf->pkt_len = m_len - trim_len;
967 : 0 : mbuf->data_len = m_len - trim_len;
968 : :
969 : 0 : return;
970 : : }
971 : :
972 : : /* Handle SG mode */
973 : : seg = mbuf;
974 [ # # ]: 0 : while (mac_offset >= seg->data_len) {
975 : 0 : mac_offset -= seg->data_len;
976 : 0 : seg = seg->next;
977 : : }
978 : :
979 : 0 : pad_offset = mac_offset + mac_len;
980 [ # # ]: 0 : while (pad_offset >= seg->data_len) {
981 : 0 : pad_offset -= seg->data_len;
982 : 0 : seg = seg->next;
983 : : }
984 : :
985 [ # # ]: 0 : while (pad_len != 0) {
986 : 0 : uint8_t *ptr = rte_pktmbuf_mtod_offset(seg, uint8_t *, pad_offset);
987 : 0 : uint8_t len = RTE_MIN(seg->data_len - pad_offset, pad_len);
988 : :
989 [ # # ]: 0 : for (i = 0; i < len; i++)
990 : 0 : pad_res |= ptr[i] ^ pad_val;
991 : :
992 : : pad_offset = 0;
993 : 0 : pad_len -= len;
994 : 0 : seg = seg->next;
995 : : }
996 : :
997 [ # # ]: 0 : if (pad_res) {
998 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
999 : 0 : cop->aux_flags = res->uc_compcode;
1000 : : }
1001 : :
1002 : 0 : len_to_trim = mbuf->pkt_len - (m_len - trim_len);
1003 : :
1004 : : pktmbuf_trim_chain(mbuf, len_to_trim);
1005 : : }
1006 : :
1007 : : /* TLS-1.3:
1008 : : * Read from last until a non-zero value is encountered.
1009 : : * Return the non zero value as the content type.
1010 : : * Remove the MAC and content type and padding bytes.
1011 : : */
1012 : : static inline void
1013 : 0 : cn10k_cpt_tls13_trim_mac(struct rte_crypto_op *cop, struct cpt_cn10k_res_s *res)
1014 : : {
1015 : 0 : uint16_t m_len = res->rlen, len_to_trim;
1016 : 0 : struct rte_mbuf *mbuf = cop->sym->m_src;
1017 : : struct rte_mbuf *seg = mbuf;
1018 : : uint8_t *ptr, type = 0x0;
1019 : : int len, i;
1020 : :
1021 [ # # ]: 0 : while (m_len && !type) {
1022 : 0 : len = m_len;
1023 : : seg = mbuf;
1024 : :
1025 : : /* get the last seg */
1026 [ # # ]: 0 : while (len > seg->data_len) {
1027 : 0 : len -= seg->data_len;
1028 : 0 : seg = seg->next;
1029 : : }
1030 : :
1031 : : /* walkthrough from last until a non zero value is found */
1032 : 0 : ptr = rte_pktmbuf_mtod(seg, uint8_t *);
1033 : : i = len;
1034 [ # # # # ]: 0 : while (i && (ptr[--i] == 0))
1035 : : ;
1036 : :
1037 : 0 : type = ptr[i];
1038 : 0 : m_len -= len;
1039 : : }
1040 : :
1041 : 0 : len_to_trim = mbuf->pkt_len - i;
1042 : :
1043 [ # # ]: 0 : if (type) {
1044 : : pktmbuf_trim_chain(mbuf, len_to_trim);
1045 : 0 : cop->param1.tls_record.content_type = type;
1046 : :
1047 : : } else
1048 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
1049 : 0 : }
1050 : :
1051 : : static inline void
1052 : 0 : cn10k_cpt_tls_post_process(struct rte_crypto_op *cop, struct cpt_cn10k_res_s *res,
1053 : : struct cn10k_sec_session *sess)
1054 : : {
1055 : 0 : struct cn10k_tls_opt tls_opt = sess->tls_opt;
1056 : 0 : struct rte_mbuf *mbuf = cop->sym->m_src;
1057 : 0 : uint16_t m_len = res->rlen;
1058 : :
1059 [ # # ]: 0 : if (!res->uc_compcode) {
1060 [ # # ]: 0 : if (mbuf->next == NULL)
1061 : 0 : mbuf->data_len = m_len;
1062 : 0 : mbuf->pkt_len = m_len;
1063 : 0 : cop->param1.tls_record.content_type = (res->spi >> 24) & 0xff;
1064 : 0 : return;
1065 : : }
1066 : :
1067 : : /* Any error other than post process */
1068 [ # # ]: 0 : if (res->uc_compcode != ROC_SE_ERR_SSL_POST_PROCESS) {
1069 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
1070 : 0 : cop->aux_flags = res->uc_compcode;
1071 : 0 : plt_err("crypto op failed with UC compcode: 0x%x", res->uc_compcode);
1072 : 0 : return;
1073 : : }
1074 : :
1075 : : /* Extra padding scenario: Verify padding. Remove padding and MAC */
1076 [ # # ]: 0 : if (tls_opt.tls_ver != RTE_SECURITY_VERSION_TLS_1_3)
1077 : 0 : cn10k_cpt_tls12_trim_mac(cop, res, (uint8_t)tls_opt.mac_len);
1078 : : else
1079 : 0 : cn10k_cpt_tls13_trim_mac(cop, res);
1080 : : }
1081 : :
1082 : : static inline void
1083 : 0 : cn10k_cpt_sec_post_process(struct rte_crypto_op *cop, struct cpt_cn10k_res_s *res)
1084 : : {
1085 : : struct rte_crypto_sym_op *sym_op = cop->sym;
1086 : : struct cn10k_sec_session *sess;
1087 : :
1088 : 0 : sess = sym_op->session;
1089 [ # # ]: 0 : if (sess->proto == RTE_SECURITY_PROTOCOL_IPSEC)
1090 : 0 : cn10k_cpt_ipsec_post_process(cop, res);
1091 [ # # ]: 0 : else if (sess->proto == RTE_SECURITY_PROTOCOL_TLS_RECORD)
1092 : 0 : cn10k_cpt_tls_post_process(cop, res, sess);
1093 : 0 : }
1094 : :
1095 : : static inline void
1096 : 0 : cn10k_cpt_dequeue_post_process(struct cnxk_cpt_qp *qp, struct rte_crypto_op *cop,
1097 : : struct cpt_inflight_req *infl_req, struct cpt_cn10k_res_s *res)
1098 : : {
1099 : 0 : const uint8_t uc_compcode = res->uc_compcode;
1100 : 0 : const uint8_t compcode = res->compcode;
1101 : :
1102 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
1103 : :
1104 [ # # ]: 0 : if (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
1105 : : cop->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
1106 [ # # ]: 0 : if (likely(compcode == CPT_COMP_GOOD || compcode == CPT_COMP_WARN)) {
1107 : : /* Success with additional info */
1108 : 0 : cn10k_cpt_sec_post_process(cop, res);
1109 : : } else {
1110 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
1111 : 0 : plt_dp_info("HW completion code 0x%x", res->compcode);
1112 [ # # ]: 0 : if (compcode == CPT_COMP_GOOD) {
1113 : 0 : plt_dp_info(
1114 : : "Request failed with microcode error");
1115 : 0 : plt_dp_info("MC completion code 0x%x",
1116 : : uc_compcode);
1117 : : }
1118 : : }
1119 : :
1120 : 0 : return;
1121 [ # # ]: 0 : } else if (cop->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC &&
1122 : : cop->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
1123 : : struct cnxk_ae_sess *sess;
1124 : :
1125 : 0 : sess = (struct cnxk_ae_sess *)cop->asym->session;
1126 [ # # ]: 0 : if (sess->xfrm_type == RTE_CRYPTO_ASYM_XFORM_ECDH &&
1127 [ # # ]: 0 : cop->asym->ecdh.ke_type == RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY) {
1128 [ # # ]: 0 : if (likely(compcode == CPT_COMP_GOOD)) {
1129 [ # # ]: 0 : if (uc_compcode == ROC_AE_ERR_ECC_POINT_NOT_ON_CURVE) {
1130 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
1131 : 0 : return;
1132 [ # # ]: 0 : } else if (uc_compcode == ROC_AE_ERR_ECC_PAI) {
1133 : : cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
1134 : : return;
1135 : : }
1136 : : }
1137 : : }
1138 : : }
1139 : :
1140 [ # # ]: 0 : if (likely(compcode == CPT_COMP_GOOD)) {
1141 : : #ifdef CPT_INST_DEBUG_ENABLE
1142 : : if (infl_req->is_sg_ver2)
1143 : : cnxk_cpt_request_data_sgv2_mode_dump(infl_req->rptr, 0,
1144 : : infl_req->scatter_sz);
1145 : : else {
1146 : : if (infl_req->opcode_major >> 7)
1147 : : cnxk_cpt_request_data_sg_mode_dump(infl_req->dptr, 0);
1148 : : }
1149 : : #endif
1150 : :
1151 [ # # ]: 0 : if (unlikely(uc_compcode)) {
1152 [ # # ]: 0 : if (uc_compcode == ROC_SE_ERR_GC_ICV_MISCOMPARE)
1153 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
1154 : : else
1155 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
1156 : :
1157 : 0 : plt_dp_info("Request failed with microcode error");
1158 : 0 : plt_dp_info("MC completion code 0x%x",
1159 : : res->uc_compcode);
1160 : 0 : cop->aux_flags = uc_compcode;
1161 : 0 : goto temp_sess_free;
1162 : : }
1163 : :
1164 [ # # ]: 0 : if (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
1165 : : /* Verify authentication data if required */
1166 [ # # ]: 0 : if (unlikely(infl_req->op_flags &
1167 : : CPT_OP_FLAGS_AUTH_VERIFY)) {
1168 : 0 : uintptr_t *rsp = infl_req->mdata;
1169 [ # # ]: 0 : compl_auth_verify(cop, (uint8_t *)rsp[0],
1170 : : rsp[1]);
1171 : : }
1172 [ # # ]: 0 : } else if (cop->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
1173 : : struct rte_crypto_asym_op *op = cop->asym;
1174 : 0 : uintptr_t *mdata = infl_req->mdata;
1175 : 0 : struct cnxk_ae_sess *sess = (struct cnxk_ae_sess *)op->session;
1176 : :
1177 [ # # # # : 0 : cnxk_ae_post_process(cop, sess, (uint8_t *)mdata[0]);
# # # # #
# ]
1178 : : }
1179 : : } else {
1180 : 0 : cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
1181 : 0 : plt_dp_info("HW completion code 0x%x", res->compcode);
1182 : :
1183 [ # # # # ]: 0 : switch (compcode) {
1184 : 0 : case CPT_COMP_INSTERR:
1185 : 0 : plt_dp_err("Request failed with instruction error");
1186 : 0 : break;
1187 : 0 : case CPT_COMP_FAULT:
1188 : 0 : plt_dp_err("Request failed with DMA fault");
1189 : 0 : break;
1190 : 0 : case CPT_COMP_HWERR:
1191 : 0 : plt_dp_err("Request failed with hardware error");
1192 : 0 : break;
1193 : 0 : default:
1194 : 0 : plt_dp_err(
1195 : : "Request failed with unknown completion code");
1196 : : }
1197 : : }
1198 : :
1199 : 0 : temp_sess_free:
1200 [ # # ]: 0 : if (unlikely(cop->sess_type == RTE_CRYPTO_OP_SESSIONLESS)) {
1201 [ # # ]: 0 : if (cop->type == RTE_CRYPTO_OP_TYPE_SYMMETRIC) {
1202 : 0 : sym_session_clear(cop->sym->session, true);
1203 [ # # ]: 0 : rte_mempool_put(qp->sess_mp, cop->sym->session);
1204 : 0 : cop->sym->session = NULL;
1205 : : }
1206 [ # # ]: 0 : if (cop->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
1207 : 0 : cnxk_ae_session_clear(NULL, cop->asym->session);
1208 [ # # ]: 0 : rte_mempool_put(qp->sess_mp, cop->asym->session);
1209 : 0 : cop->asym->session = NULL;
1210 : : }
1211 : : }
1212 : : }
1213 : :
1214 : : RTE_EXPORT_INTERNAL_SYMBOL(cn10k_cpt_crypto_adapter_dequeue)
1215 : : uintptr_t
1216 : 0 : cn10k_cpt_crypto_adapter_dequeue(uintptr_t get_work1)
1217 : : {
1218 : : struct cpt_inflight_req *infl_req;
1219 : : struct rte_crypto_op *cop;
1220 : : struct cnxk_cpt_qp *qp;
1221 : : union cpt_res_s res;
1222 : :
1223 : 0 : infl_req = (struct cpt_inflight_req *)(get_work1);
1224 : 0 : cop = infl_req->cop;
1225 : 0 : qp = infl_req->qp;
1226 : :
1227 : 0 : res.u64[0] = rte_atomic_load_explicit((uint64_t __rte_atomic *)&infl_req->res.u64[0],
1228 : : rte_memory_order_relaxed);
1229 : :
1230 : 0 : cn10k_cpt_dequeue_post_process(qp, infl_req->cop, infl_req, &res.cn10k);
1231 : :
1232 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
1233 [ # # ]: 0 : rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
1234 : :
1235 [ # # ]: 0 : rte_mempool_put(qp->ca.req_mp, infl_req);
1236 : 0 : return (uintptr_t)cop;
1237 : : }
1238 : :
1239 : : RTE_EXPORT_INTERNAL_SYMBOL(cn10k_cpt_crypto_adapter_vector_dequeue)
1240 : : uintptr_t
1241 : 0 : cn10k_cpt_crypto_adapter_vector_dequeue(uintptr_t get_work1)
1242 : : {
1243 : : struct cpt_inflight_req *infl_req, *vec_infl_req;
1244 : : struct rte_mempool *meta_mp, *req_mp;
1245 : : struct rte_event_vector *vec;
1246 : : struct rte_crypto_op *cop;
1247 : : struct cnxk_cpt_qp *qp;
1248 : : union cpt_res_s res;
1249 : : int i;
1250 : :
1251 : 0 : vec_infl_req = (struct cpt_inflight_req *)(get_work1);
1252 : :
1253 : 0 : vec = vec_infl_req->vec;
1254 : 0 : qp = vec_infl_req->qp;
1255 : 0 : meta_mp = qp->meta_info.pool;
1256 : 0 : req_mp = qp->ca.req_mp;
1257 : :
1258 : : #ifdef CNXK_CRYPTODEV_DEBUG
1259 : : res.u64[0] = rte_atomic_load_explicit((uint64_t __rte_atomic *)&vec_infl_req->res.u64[0],
1260 : : rte_memory_order_relaxed);
1261 : : PLT_ASSERT(res.cn10k.compcode == CPT_COMP_GOOD);
1262 : : PLT_ASSERT(res.cn10k.uc_compcode == 0);
1263 : : #endif
1264 : :
1265 [ # # ]: 0 : for (i = 0; i < vec->nb_elem; i++) {
1266 : 0 : infl_req = vec->ptrs[i];
1267 : 0 : cop = infl_req->cop;
1268 : :
1269 : 0 : res.u64[0] = rte_atomic_load_explicit(
1270 : : (uint64_t __rte_atomic *)&infl_req->res.u64[0], rte_memory_order_relaxed);
1271 : 0 : cn10k_cpt_dequeue_post_process(qp, cop, infl_req, &res.cn10k);
1272 : :
1273 : 0 : vec->ptrs[i] = cop;
1274 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
1275 [ # # ]: 0 : rte_mempool_put(meta_mp, infl_req->mdata);
1276 : :
1277 : 0 : rte_mempool_put(req_mp, infl_req);
1278 : : }
1279 : :
1280 : 0 : rte_mempool_put(req_mp, vec_infl_req);
1281 : :
1282 : 0 : return (uintptr_t)vec;
1283 : : }
1284 : :
1285 : : static uint16_t
1286 : 0 : cn10k_cpt_dequeue_burst(void *qptr, struct rte_crypto_op **ops, uint16_t nb_ops)
1287 : : {
1288 : : struct cpt_inflight_req *infl_req;
1289 : : struct cnxk_cpt_qp *qp = qptr;
1290 : : struct pending_queue *pend_q;
1291 : : uint64_t infl_cnt, pq_tail;
1292 : : struct rte_crypto_op *cop;
1293 : : union cpt_res_s res;
1294 : : int i;
1295 : :
1296 : : pend_q = &qp->pend_q;
1297 : :
1298 : 0 : const uint64_t pq_mask = pend_q->pq_mask;
1299 : :
1300 : 0 : pq_tail = pend_q->tail;
1301 : 0 : infl_cnt = pending_queue_infl_cnt(pend_q->head, pq_tail, pq_mask);
1302 : 0 : nb_ops = RTE_MIN(nb_ops, infl_cnt);
1303 : :
1304 : : /* Ensure infl_cnt isn't read before data lands */
1305 : : rte_atomic_thread_fence(__ATOMIC_ACQUIRE);
1306 : :
1307 [ # # ]: 0 : for (i = 0; i < nb_ops; i++) {
1308 : 0 : infl_req = &pend_q->req_queue[pq_tail];
1309 : :
1310 : 0 : res.u64[0] = rte_atomic_load_explicit(
1311 : : (uint64_t __rte_atomic *)&infl_req->res.u64[0], rte_memory_order_relaxed);
1312 : :
1313 [ # # ]: 0 : if (unlikely(res.cn10k.compcode == CPT_COMP_NOT_DONE)) {
1314 [ # # ]: 0 : if (unlikely(rte_get_timer_cycles() >
1315 : : pend_q->time_out)) {
1316 : 0 : plt_err("Request timed out");
1317 : 0 : cnxk_cpt_dump_on_err(qp);
1318 : 0 : pend_q->time_out = rte_get_timer_cycles() +
1319 : 0 : DEFAULT_COMMAND_TIMEOUT *
1320 : : rte_get_timer_hz();
1321 : : }
1322 : : break;
1323 : : }
1324 : :
1325 : : pending_queue_advance(&pq_tail, pq_mask);
1326 : :
1327 : 0 : cop = infl_req->cop;
1328 : :
1329 : 0 : ops[i] = cop;
1330 : :
1331 : 0 : cn10k_cpt_dequeue_post_process(qp, cop, infl_req, &res.cn10k);
1332 : :
1333 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
1334 [ # # ]: 0 : rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
1335 : : }
1336 : :
1337 : 0 : pend_q->tail = pq_tail;
1338 : :
1339 : 0 : return i;
1340 : : }
1341 : :
1342 : : #if defined(RTE_ARCH_ARM64)
1343 : : RTE_EXPORT_INTERNAL_SYMBOL(cn10k_cryptodev_sec_inb_rx_inject)
1344 : : uint16_t __rte_hot
1345 : : cn10k_cryptodev_sec_inb_rx_inject(void *dev, struct rte_mbuf **pkts,
1346 : : struct rte_security_session **sess, uint16_t nb_pkts)
1347 : : {
1348 : : uint64_t lmt_base, io_addr, u64_0, u64_1, l2_len, pf_func;
1349 : : uint64x2_t inst_01, inst_23, inst_45, inst_67;
1350 : : struct cn10k_sec_session *sec_sess;
1351 : : struct rte_cryptodev *cdev = dev;
1352 : : union cpt_res_s *hw_res = NULL;
1353 : : uint16_t lmt_id, count = 0;
1354 : : struct cpt_inst_s *inst;
1355 : : union cpt_fc_write_s fc;
1356 : : struct cnxk_cpt_vf *vf;
1357 : : struct rte_mbuf *m;
1358 : : uint64_t u64_dptr;
1359 : : uint64_t *fc_addr;
1360 : : int i;
1361 : :
1362 : : vf = cdev->data->dev_private;
1363 : :
1364 : : lmt_base = vf->rx_inj_lmtline.lmt_base;
1365 : : io_addr = vf->rx_inj_lmtline.io_addr;
1366 : : fc_addr = vf->rx_inj_lmtline.fc_addr;
1367 : :
1368 : : ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
1369 : : pf_func = vf->rx_inj_sso_pf_func;
1370 : :
1371 : : const uint32_t fc_thresh = vf->rx_inj_lmtline.fc_thresh;
1372 : :
1373 : : again:
1374 : : fc.u64[0] =
1375 : : rte_atomic_load_explicit((RTE_ATOMIC(uint64_t) *)fc_addr, rte_memory_order_relaxed);
1376 : : inst = (struct cpt_inst_s *)lmt_base;
1377 : :
1378 : : i = 0;
1379 : :
1380 : : if (unlikely(fc.s.qsize > fc_thresh))
1381 : : goto exit;
1382 : :
1383 : : for (; i < RTE_MIN(CN10K_CPT_PKTS_PER_LOOP, nb_pkts); i++) {
1384 : :
1385 : : m = pkts[i];
1386 : : sec_sess = (struct cn10k_sec_session *)sess[i];
1387 : :
1388 : : if (unlikely(rte_pktmbuf_headroom(m) < 32)) {
1389 : : plt_dp_err("No space for CPT res_s");
1390 : : break;
1391 : : }
1392 : :
1393 : : l2_len = m->l2_len;
1394 : :
1395 : : *rte_security_dynfield(m) = (uint64_t)sec_sess->userdata;
1396 : :
1397 : : hw_res = rte_pktmbuf_mtod(m, void *);
1398 : : hw_res = RTE_PTR_SUB(hw_res, 32);
1399 : : hw_res = RTE_PTR_ALIGN_CEIL(hw_res, 16);
1400 : :
1401 : : /* Prepare CPT instruction */
1402 : : if (m->nb_segs > 1) {
1403 : : struct rte_mbuf *last = rte_pktmbuf_lastseg(m);
1404 : : uintptr_t dptr, rxphdr, wqe_hdr;
1405 : : uint16_t i;
1406 : :
1407 : : if ((m->nb_segs > CNXK_CPT_MAX_SG_SEGS) ||
1408 : : (rte_pktmbuf_tailroom(m) < CNXK_CPT_MIN_TAILROOM_REQ))
1409 : : goto exit;
1410 : :
1411 : : wqe_hdr = rte_pktmbuf_mtod_offset(last, uintptr_t, last->data_len);
1412 : : wqe_hdr += BIT_ULL(7);
1413 : : wqe_hdr = (wqe_hdr - 1) & ~(BIT_ULL(7) - 1);
1414 : :
1415 : : /* Pointer to WQE header */
1416 : : *(uint64_t *)(m + 1) = wqe_hdr;
1417 : :
1418 : : /* Reserve SG list after end of last mbuf data location. */
1419 : : rxphdr = wqe_hdr + 8;
1420 : : dptr = rxphdr + 7 * 8;
1421 : :
1422 : : /* Prepare Multiseg SG list */
1423 : : i = fill_sg2_comp_from_pkt((struct roc_sg2list_comp *)dptr, 0, m);
1424 : : u64_dptr = dptr | ((uint64_t)(i) << 60);
1425 : : } else {
1426 : : struct roc_sg2list_comp *sg2;
1427 : : uintptr_t dptr, wqe_hdr;
1428 : :
1429 : : /* Reserve space for WQE, NIX_RX_PARSE_S and SG_S.
1430 : : * Populate SG_S with num segs and seg length
1431 : : */
1432 : : wqe_hdr = (uintptr_t)(m + 1);
1433 : : *(uint64_t *)(m + 1) = wqe_hdr;
1434 : :
1435 : : sg2 = (struct roc_sg2list_comp *)(wqe_hdr + 8 * 8);
1436 : : sg2->u.s.len[0] = rte_pktmbuf_pkt_len(m);
1437 : : sg2->u.s.valid_segs = 1;
1438 : :
1439 : : dptr = (uint64_t)rte_pktmbuf_iova(m);
1440 : : u64_dptr = dptr;
1441 : : }
1442 : :
1443 : : /* Word 0 and 1 */
1444 : : inst_01 = vdupq_n_u64(0);
1445 : : u64_0 = pf_func << 48 | *(vf->rx_chan_base + m->port) << 4 | (l2_len - 2) << 24 |
1446 : : l2_len << 16;
1447 : : inst_01 = vsetq_lane_u64(u64_0, inst_01, 0);
1448 : : inst_01 = vsetq_lane_u64((uint64_t)hw_res, inst_01, 1);
1449 : : vst1q_u64(&inst->w0.u64, inst_01);
1450 : :
1451 : : /* Word 2 and 3 */
1452 : : inst_23 = vdupq_n_u64(0);
1453 : : u64_1 = (((uint64_t)m + sizeof(struct rte_mbuf)) >> 3) << 3 | 1;
1454 : : inst_23 = vsetq_lane_u64(u64_1, inst_23, 1);
1455 : : vst1q_u64(&inst->w2.u64, inst_23);
1456 : :
1457 : : /* Word 4 and 5 */
1458 : : inst_45 = vdupq_n_u64(0);
1459 : : u64_0 = sec_sess->inst.w4 | (rte_pktmbuf_pkt_len(m));
1460 : : inst_45 = vsetq_lane_u64(u64_0, inst_45, 0);
1461 : : inst_45 = vsetq_lane_u64(u64_dptr, inst_45, 1);
1462 : : vst1q_u64(&inst->w4.u64, inst_45);
1463 : :
1464 : : /* Word 6 and 7 */
1465 : : inst_67 = vdupq_n_u64(0);
1466 : : u64_1 = sec_sess->inst.w7;
1467 : : inst_67 = vsetq_lane_u64(u64_1, inst_67, 1);
1468 : : vst1q_u64(&inst->w6.u64, inst_67);
1469 : :
1470 : : inst++;
1471 : : }
1472 : :
1473 : : cn10k_cpt_lmtst_dual_submit(&io_addr, lmt_id, &i);
1474 : :
1475 : : if (nb_pkts - i > 0 && i == CN10K_CPT_PKTS_PER_LOOP) {
1476 : : nb_pkts -= CN10K_CPT_PKTS_PER_LOOP;
1477 : : pkts += CN10K_CPT_PKTS_PER_LOOP;
1478 : : count += CN10K_CPT_PKTS_PER_LOOP;
1479 : : sess += CN10K_CPT_PKTS_PER_LOOP;
1480 : : goto again;
1481 : : }
1482 : :
1483 : : exit:
1484 : : return count + i;
1485 : : }
1486 : : #else
1487 : : RTE_EXPORT_INTERNAL_SYMBOL(cn10k_cryptodev_sec_inb_rx_inject)
1488 : : uint16_t __rte_hot
1489 : 0 : cn10k_cryptodev_sec_inb_rx_inject(void *dev, struct rte_mbuf **pkts,
1490 : : struct rte_security_session **sess, uint16_t nb_pkts)
1491 : : {
1492 : : RTE_SET_USED(dev);
1493 : : RTE_SET_USED(pkts);
1494 : : RTE_SET_USED(sess);
1495 : : RTE_SET_USED(nb_pkts);
1496 : 0 : return 0;
1497 : : }
1498 : : #endif
1499 : :
1500 : : void
1501 : 0 : cn10k_cpt_set_enqdeq_fns(struct rte_cryptodev *dev, struct cnxk_cpt_vf *vf)
1502 : : {
1503 [ # # # # ]: 0 : if (vf->cpt.hw_caps[CPT_ENG_TYPE_SE].sg_ver2 && vf->cpt.hw_caps[CPT_ENG_TYPE_IE].sg_ver2)
1504 : 0 : dev->enqueue_burst = cn10k_cpt_sg_ver2_enqueue_burst;
1505 : : else
1506 : 0 : dev->enqueue_burst = cn10k_cpt_sg_ver1_enqueue_burst;
1507 : :
1508 : 0 : dev->dequeue_burst = cn10k_cpt_dequeue_burst;
1509 : :
1510 : : rte_mb();
1511 : 0 : }
1512 : :
1513 : : static void
1514 : 0 : cn10k_cpt_dev_info_get(struct rte_cryptodev *dev,
1515 : : struct rte_cryptodev_info *info)
1516 : : {
1517 [ # # ]: 0 : if (info != NULL) {
1518 : 0 : cnxk_cpt_dev_info_get(dev, info);
1519 : 0 : info->driver_id = cn10k_cryptodev_driver_id;
1520 : : }
1521 : 0 : }
1522 : :
1523 : : static inline int
1524 : 0 : cn10k_cpt_raw_fill_inst(struct cnxk_iov *iov, struct cnxk_cpt_qp *qp,
1525 : : struct cnxk_sym_dp_ctx *dp_ctx, struct cpt_inst_s inst[],
1526 : : struct cpt_inflight_req *infl_req, void *opaque, const bool is_sg_ver2)
1527 : : {
1528 : : struct cnxk_se_sess *sess;
1529 : : int ret;
1530 : :
1531 : : const union cpt_res_s res = {
1532 : : .cn10k.compcode = CPT_COMP_NOT_DONE,
1533 : : };
1534 : :
1535 : 0 : inst[0].w0.u64 = 0;
1536 : 0 : inst[0].w2.u64 = 0;
1537 : 0 : inst[0].w3.u64 = 0;
1538 : :
1539 : 0 : sess = dp_ctx->sess;
1540 : :
1541 [ # # # # : 0 : switch (sess->dp_thr_type) {
# ]
1542 : 0 : case CPT_DP_THREAD_TYPE_PT:
1543 : 0 : ret = fill_raw_passthrough_params(iov, inst);
1544 : 0 : break;
1545 [ # # ]: 0 : case CPT_DP_THREAD_TYPE_FC_CHAIN:
1546 : : ret = fill_raw_fc_params(iov, sess, &qp->meta_info, infl_req, &inst[0], false,
1547 : : false, is_sg_ver2);
1548 : 0 : break;
1549 [ # # ]: 0 : case CPT_DP_THREAD_TYPE_FC_AEAD:
1550 : : ret = fill_raw_fc_params(iov, sess, &qp->meta_info, infl_req, &inst[0], false, true,
1551 : : is_sg_ver2);
1552 : 0 : break;
1553 [ # # ]: 0 : case CPT_DP_THREAD_AUTH_ONLY:
1554 : : ret = fill_raw_digest_params(iov, sess, &qp->meta_info, infl_req, &inst[0],
1555 : : is_sg_ver2, false);
1556 : 0 : break;
1557 : : default:
1558 : : ret = -EINVAL;
1559 : : }
1560 : :
1561 [ # # ]: 0 : if (unlikely(ret))
1562 : : return 0;
1563 : :
1564 : 0 : inst[0].res_addr = (uint64_t)&infl_req->res;
1565 : 0 : rte_atomic_store_explicit((uint64_t __rte_atomic *)&infl_req->res.u64[0], res.u64[0],
1566 : : rte_memory_order_relaxed);
1567 : 0 : infl_req->opaque = opaque;
1568 : :
1569 : 0 : inst[0].w7.u64 = sess->cpt_inst_w7;
1570 : :
1571 : 0 : return 1;
1572 : : }
1573 : :
1574 : : static uint32_t
1575 : 0 : cn10k_cpt_raw_enqueue_burst(void *qpair, uint8_t *drv_ctx, struct rte_crypto_sym_vec *vec,
1576 : : union rte_crypto_sym_ofs ofs, void *user_data[], int *enqueue_status,
1577 : : const bool is_sgv2)
1578 : : {
1579 : 0 : uint16_t lmt_id, nb_allowed, nb_ops = vec->num;
1580 : : struct cpt_inflight_req *infl_req;
1581 : : uint64_t lmt_base, io_addr, head;
1582 : : struct cnxk_cpt_qp *qp = qpair;
1583 : : struct cnxk_sym_dp_ctx *dp_ctx;
1584 : : uint64_t __rte_atomic *fc_addr;
1585 : : struct pending_queue *pend_q;
1586 : : uint32_t count = 0, index;
1587 : : union cpt_fc_write_s fc;
1588 : : struct cpt_inst_s *inst;
1589 : : int ret, i;
1590 : :
1591 : : pend_q = &qp->pend_q;
1592 : 0 : const uint64_t pq_mask = pend_q->pq_mask;
1593 : :
1594 : 0 : head = pend_q->head;
1595 [ # # ]: 0 : nb_allowed = pending_queue_free_cnt(head, pend_q->tail, pq_mask);
1596 : 0 : nb_ops = RTE_MIN(nb_ops, nb_allowed);
1597 : :
1598 [ # # ]: 0 : if (unlikely(nb_ops == 0))
1599 : : return 0;
1600 : :
1601 : 0 : lmt_base = qp->lmtline.lmt_base;
1602 : : io_addr = qp->lmtline.io_addr;
1603 : 0 : fc_addr = (uint64_t __rte_atomic *)qp->lmtline.fc_addr;
1604 : :
1605 : 0 : const uint32_t fc_thresh = qp->lmtline.fc_thresh;
1606 : :
1607 : : ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
1608 : 0 : inst = (struct cpt_inst_s *)lmt_base;
1609 : :
1610 : : dp_ctx = (struct cnxk_sym_dp_ctx *)drv_ctx;
1611 : 0 : again:
1612 : 0 : fc.u64[0] = rte_atomic_load_explicit(fc_addr, rte_memory_order_relaxed);
1613 [ # # ]: 0 : if (unlikely(fc.s.qsize > fc_thresh)) {
1614 : : i = 0;
1615 : 0 : goto pend_q_commit;
1616 : : }
1617 : :
1618 [ # # ]: 0 : for (i = 0; i < RTE_MIN(CN10K_CPT_PKTS_PER_LOOP, nb_ops); i++) {
1619 : : struct cnxk_iov iov;
1620 : :
1621 : 0 : index = count + i;
1622 : 0 : infl_req = &pend_q->req_queue[head];
1623 : 0 : infl_req->op_flags = 0;
1624 : :
1625 [ # # ]: 0 : ret = cnxk_raw_burst_to_iov(vec, &ofs, index, &iov);
1626 [ # # ]: 0 : if (unlikely(ret != 0)) {
1627 : 0 : plt_dp_err("Failed to convert raw to iov: %d", index);
1628 [ # # ]: 0 : if (i == 0 && count == 0) {
1629 : 0 : *enqueue_status = ret;
1630 : 0 : return 0;
1631 [ # # ]: 0 : } else if (i == 0) {
1632 : 0 : goto pend_q_commit;
1633 : : } else {
1634 : : break;
1635 : : }
1636 : : }
1637 : 0 : ret = cn10k_cpt_raw_fill_inst(&iov, qp, dp_ctx, &inst[i], infl_req,
1638 : 0 : user_data[index], is_sgv2);
1639 [ # # ]: 0 : if (unlikely(ret != 1)) {
1640 : 0 : plt_dp_err("Could not process vec: %d", index);
1641 [ # # ]: 0 : if (i == 0 && count == 0) {
1642 : 0 : *enqueue_status = -EINVAL;
1643 : 0 : return 0;
1644 [ # # ]: 0 : } else if (i == 0) {
1645 : 0 : goto pend_q_commit;
1646 : : } else {
1647 : : break;
1648 : : }
1649 : : }
1650 : : pending_queue_advance(&head, pq_mask);
1651 : : }
1652 : :
1653 : : cn10k_cpt_lmtst_dual_submit(&io_addr, lmt_id, &i);
1654 : :
1655 [ # # # # ]: 0 : if (nb_ops - i > 0 && i == CN10K_CPT_PKTS_PER_LOOP) {
1656 : 0 : nb_ops -= i;
1657 : 0 : count += i;
1658 : 0 : goto again;
1659 : : }
1660 : :
1661 : 0 : pend_q_commit:
1662 : : rte_atomic_thread_fence(__ATOMIC_RELEASE);
1663 : :
1664 : 0 : pend_q->head = head;
1665 : 0 : pend_q->time_out = rte_get_timer_cycles() + DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
1666 : :
1667 : 0 : *enqueue_status = 1;
1668 : 0 : return count + i;
1669 : : }
1670 : :
1671 : : static uint32_t
1672 : 0 : cn10k_cpt_raw_enqueue_burst_sgv2(void *qpair, uint8_t *drv_ctx, struct rte_crypto_sym_vec *vec,
1673 : : union rte_crypto_sym_ofs ofs, void *user_data[],
1674 : : int *enqueue_status)
1675 : : {
1676 : 0 : return cn10k_cpt_raw_enqueue_burst(qpair, drv_ctx, vec, ofs, user_data, enqueue_status,
1677 : : true);
1678 : : }
1679 : :
1680 : : static uint32_t
1681 : 0 : cn10k_cpt_raw_enqueue_burst_sgv1(void *qpair, uint8_t *drv_ctx, struct rte_crypto_sym_vec *vec,
1682 : : union rte_crypto_sym_ofs ofs, void *user_data[],
1683 : : int *enqueue_status)
1684 : : {
1685 : 0 : return cn10k_cpt_raw_enqueue_burst(qpair, drv_ctx, vec, ofs, user_data, enqueue_status,
1686 : : false);
1687 : : }
1688 : :
1689 : : static int
1690 : 0 : cn10k_cpt_raw_enqueue(void *qpair, uint8_t *drv_ctx, struct rte_crypto_vec *data_vec,
1691 : : uint16_t n_data_vecs, union rte_crypto_sym_ofs ofs,
1692 : : struct rte_crypto_va_iova_ptr *iv, struct rte_crypto_va_iova_ptr *digest,
1693 : : struct rte_crypto_va_iova_ptr *aad_or_auth_iv, void *user_data,
1694 : : const bool is_sgv2)
1695 : : {
1696 : : struct cpt_inflight_req *infl_req;
1697 : : uint64_t lmt_base, io_addr, head;
1698 : : struct cnxk_cpt_qp *qp = qpair;
1699 : : struct cnxk_sym_dp_ctx *dp_ctx;
1700 : : uint64_t __rte_atomic *fc_addr;
1701 : : uint16_t lmt_id, nb_allowed;
1702 : : struct cpt_inst_s *inst;
1703 : : union cpt_fc_write_s fc;
1704 : : struct cnxk_iov iov;
1705 : : int ret, i = 1;
1706 : :
1707 : : struct pending_queue *pend_q = &qp->pend_q;
1708 : 0 : const uint64_t pq_mask = pend_q->pq_mask;
1709 : 0 : const uint32_t fc_thresh = qp->lmtline.fc_thresh;
1710 : :
1711 : 0 : head = pend_q->head;
1712 [ # # ]: 0 : nb_allowed = pending_queue_free_cnt(head, pend_q->tail, pq_mask);
1713 : :
1714 [ # # ]: 0 : if (unlikely(nb_allowed == 0))
1715 : : return -1;
1716 : :
1717 [ # # ]: 0 : ret = cnxk_raw_to_iov(data_vec, n_data_vecs, &ofs, iv, digest, aad_or_auth_iv, &iov);
1718 [ # # ]: 0 : if (unlikely(ret != 0)) {
1719 : 0 : plt_dp_err("Failed to convert raw to iov");
1720 : 0 : return -1;
1721 : : }
1722 : :
1723 : 0 : lmt_base = qp->lmtline.lmt_base;
1724 : : io_addr = qp->lmtline.io_addr;
1725 : 0 : fc_addr = (uint64_t __rte_atomic *)qp->lmtline.fc_addr;
1726 : :
1727 : : ROC_LMT_BASE_ID_GET(lmt_base, lmt_id);
1728 : 0 : inst = (struct cpt_inst_s *)lmt_base;
1729 : :
1730 : 0 : fc.u64[0] = rte_atomic_load_explicit(fc_addr, rte_memory_order_relaxed);
1731 [ # # ]: 0 : if (unlikely(fc.s.qsize > fc_thresh))
1732 : : return -1;
1733 : :
1734 : : dp_ctx = (struct cnxk_sym_dp_ctx *)drv_ctx;
1735 : 0 : infl_req = &pend_q->req_queue[head];
1736 : 0 : infl_req->op_flags = 0;
1737 : :
1738 : 0 : ret = cn10k_cpt_raw_fill_inst(&iov, qp, dp_ctx, &inst[0], infl_req, user_data, is_sgv2);
1739 [ # # ]: 0 : if (unlikely(ret != 1)) {
1740 : 0 : plt_dp_err("Could not process vec");
1741 : 0 : return -1;
1742 : : }
1743 : :
1744 : : pending_queue_advance(&head, pq_mask);
1745 : :
1746 : : cn10k_cpt_lmtst_dual_submit(&io_addr, lmt_id, &i);
1747 : :
1748 : 0 : pend_q->head = head;
1749 : 0 : pend_q->time_out = rte_get_timer_cycles() + DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
1750 : :
1751 : 0 : return 1;
1752 : : }
1753 : :
1754 : : static int
1755 : 0 : cn10k_cpt_raw_enqueue_sgv2(void *qpair, uint8_t *drv_ctx, struct rte_crypto_vec *data_vec,
1756 : : uint16_t n_data_vecs, union rte_crypto_sym_ofs ofs,
1757 : : struct rte_crypto_va_iova_ptr *iv, struct rte_crypto_va_iova_ptr *digest,
1758 : : struct rte_crypto_va_iova_ptr *aad_or_auth_iv, void *user_data)
1759 : : {
1760 : 0 : return cn10k_cpt_raw_enqueue(qpair, drv_ctx, data_vec, n_data_vecs, ofs, iv, digest,
1761 : : aad_or_auth_iv, user_data, true);
1762 : : }
1763 : :
1764 : : static int
1765 : 0 : cn10k_cpt_raw_enqueue_sgv1(void *qpair, uint8_t *drv_ctx, struct rte_crypto_vec *data_vec,
1766 : : uint16_t n_data_vecs, union rte_crypto_sym_ofs ofs,
1767 : : struct rte_crypto_va_iova_ptr *iv, struct rte_crypto_va_iova_ptr *digest,
1768 : : struct rte_crypto_va_iova_ptr *aad_or_auth_iv, void *user_data)
1769 : : {
1770 : 0 : return cn10k_cpt_raw_enqueue(qpair, drv_ctx, data_vec, n_data_vecs, ofs, iv, digest,
1771 : : aad_or_auth_iv, user_data, false);
1772 : : }
1773 : :
1774 : : static inline int
1775 : 0 : cn10k_cpt_raw_dequeue_post_process(struct cpt_cn10k_res_s *res)
1776 : : {
1777 : 0 : const uint8_t uc_compcode = res->uc_compcode;
1778 : 0 : const uint8_t compcode = res->compcode;
1779 : : int ret = 1;
1780 : :
1781 [ # # ]: 0 : if (likely(compcode == CPT_COMP_GOOD)) {
1782 [ # # ]: 0 : if (unlikely(uc_compcode))
1783 : 0 : plt_dp_info("Request failed with microcode error: 0x%x", res->uc_compcode);
1784 : : else
1785 : : ret = 0;
1786 : : }
1787 : :
1788 : 0 : return ret;
1789 : : }
1790 : :
1791 : : static uint32_t
1792 : 0 : cn10k_cpt_sym_raw_dequeue_burst(void *qptr, uint8_t *drv_ctx,
1793 : : rte_cryptodev_raw_get_dequeue_count_t get_dequeue_count,
1794 : : uint32_t max_nb_to_dequeue,
1795 : : rte_cryptodev_raw_post_dequeue_t post_dequeue, void **out_user_data,
1796 : : uint8_t is_user_data_array, uint32_t *n_success,
1797 : : int *dequeue_status)
1798 : : {
1799 : : struct cpt_inflight_req *infl_req;
1800 : : struct cnxk_cpt_qp *qp = qptr;
1801 : : struct pending_queue *pend_q;
1802 : : uint64_t infl_cnt, pq_tail;
1803 : : union cpt_res_s res;
1804 : : int is_op_success;
1805 : : uint16_t nb_ops;
1806 : : void *opaque;
1807 : : int i = 0;
1808 : :
1809 : : pend_q = &qp->pend_q;
1810 : :
1811 : 0 : const uint64_t pq_mask = pend_q->pq_mask;
1812 : :
1813 : : RTE_SET_USED(drv_ctx);
1814 : 0 : pq_tail = pend_q->tail;
1815 [ # # ]: 0 : infl_cnt = pending_queue_infl_cnt(pend_q->head, pq_tail, pq_mask);
1816 : :
1817 : : /* Ensure infl_cnt isn't read before data lands */
1818 : : rte_atomic_thread_fence(__ATOMIC_ACQUIRE);
1819 : :
1820 : 0 : infl_req = &pend_q->req_queue[pq_tail];
1821 : :
1822 : 0 : opaque = infl_req->opaque;
1823 [ # # ]: 0 : if (get_dequeue_count)
1824 : 0 : nb_ops = get_dequeue_count(opaque);
1825 : : else
1826 : 0 : nb_ops = max_nb_to_dequeue;
1827 : 0 : nb_ops = RTE_MIN(nb_ops, infl_cnt);
1828 : :
1829 [ # # ]: 0 : for (i = 0; i < nb_ops; i++) {
1830 : : is_op_success = 0;
1831 : 0 : infl_req = &pend_q->req_queue[pq_tail];
1832 : :
1833 : 0 : res.u64[0] = rte_atomic_load_explicit(
1834 : : (uint64_t __rte_atomic *)&infl_req->res.u64[0], rte_memory_order_relaxed);
1835 : :
1836 [ # # ]: 0 : if (unlikely(res.cn10k.compcode == CPT_COMP_NOT_DONE)) {
1837 [ # # ]: 0 : if (unlikely(rte_get_timer_cycles() > pend_q->time_out)) {
1838 : 0 : plt_err("Request timed out");
1839 : 0 : cnxk_cpt_dump_on_err(qp);
1840 : 0 : pend_q->time_out = rte_get_timer_cycles() +
1841 : 0 : DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
1842 : : }
1843 : : break;
1844 : : }
1845 : :
1846 : : pending_queue_advance(&pq_tail, pq_mask);
1847 : :
1848 [ # # ]: 0 : if (!cn10k_cpt_raw_dequeue_post_process(&res.cn10k)) {
1849 : : is_op_success = 1;
1850 : 0 : *n_success += 1;
1851 : : }
1852 : :
1853 [ # # ]: 0 : if (is_user_data_array) {
1854 : 0 : out_user_data[i] = infl_req->opaque;
1855 : 0 : post_dequeue(out_user_data[i], i, is_op_success);
1856 : : } else {
1857 [ # # ]: 0 : if (i == 0)
1858 : 0 : out_user_data[0] = opaque;
1859 : 0 : post_dequeue(out_user_data[0], i, is_op_success);
1860 : : }
1861 : :
1862 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
1863 [ # # ]: 0 : rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
1864 : : }
1865 : :
1866 : 0 : pend_q->tail = pq_tail;
1867 : 0 : *dequeue_status = 1;
1868 : :
1869 : 0 : return i;
1870 : : }
1871 : :
1872 : : static void *
1873 : 0 : cn10k_cpt_sym_raw_dequeue(void *qptr, uint8_t *drv_ctx, int *dequeue_status,
1874 : : enum rte_crypto_op_status *op_status)
1875 : : {
1876 : : struct cpt_inflight_req *infl_req;
1877 : : struct cnxk_cpt_qp *qp = qptr;
1878 : : struct pending_queue *pend_q;
1879 : : union cpt_res_s res;
1880 : : void *opaque = NULL;
1881 : : uint64_t pq_tail;
1882 : :
1883 : : pend_q = &qp->pend_q;
1884 : :
1885 : : const uint64_t pq_mask = pend_q->pq_mask;
1886 : :
1887 : : RTE_SET_USED(drv_ctx);
1888 : :
1889 [ # # ]: 0 : pq_tail = pend_q->tail;
1890 : :
1891 : : rte_atomic_thread_fence(__ATOMIC_ACQUIRE);
1892 : :
1893 : 0 : infl_req = &pend_q->req_queue[pq_tail];
1894 : :
1895 : 0 : res.u64[0] = rte_atomic_load_explicit((uint64_t __rte_atomic *)&infl_req->res.u64[0],
1896 : : rte_memory_order_relaxed);
1897 : :
1898 [ # # ]: 0 : if (unlikely(res.cn10k.compcode == CPT_COMP_NOT_DONE)) {
1899 [ # # ]: 0 : if (unlikely(rte_get_timer_cycles() > pend_q->time_out)) {
1900 : 0 : plt_err("Request timed out");
1901 : 0 : cnxk_cpt_dump_on_err(qp);
1902 : 0 : pend_q->time_out = rte_get_timer_cycles() +
1903 : 0 : DEFAULT_COMMAND_TIMEOUT * rte_get_timer_hz();
1904 : : }
1905 : 0 : goto exit;
1906 : : }
1907 : :
1908 : : pending_queue_advance(&pq_tail, pq_mask);
1909 : :
1910 : 0 : opaque = infl_req->opaque;
1911 : :
1912 [ # # ]: 0 : if (!cn10k_cpt_raw_dequeue_post_process(&res.cn10k))
1913 : 0 : *op_status = RTE_CRYPTO_OP_STATUS_SUCCESS;
1914 : : else
1915 : 0 : *op_status = RTE_CRYPTO_OP_STATUS_ERROR;
1916 : :
1917 [ # # ]: 0 : if (unlikely(infl_req->op_flags & CPT_OP_FLAGS_METABUF))
1918 [ # # ]: 0 : rte_mempool_put(qp->meta_info.pool, infl_req->mdata);
1919 : :
1920 : 0 : *dequeue_status = 1;
1921 : 0 : exit:
1922 : 0 : return opaque;
1923 : : }
1924 : :
1925 : : static int
1926 : 0 : cn10k_sym_get_raw_dp_ctx_size(struct rte_cryptodev *dev __rte_unused)
1927 : : {
1928 : 0 : return sizeof(struct cnxk_sym_dp_ctx);
1929 : : }
1930 : :
1931 : : static int
1932 : 0 : cn10k_sym_configure_raw_dp_ctx(struct rte_cryptodev *dev, uint16_t qp_id,
1933 : : struct rte_crypto_raw_dp_ctx *raw_dp_ctx,
1934 : : enum rte_crypto_op_sess_type sess_type,
1935 : : union rte_cryptodev_session_ctx session_ctx, uint8_t is_update)
1936 : : {
1937 : 0 : struct cnxk_se_sess *sess = (struct cnxk_se_sess *)session_ctx.crypto_sess;
1938 : : struct cnxk_sym_dp_ctx *dp_ctx;
1939 : :
1940 [ # # ]: 0 : if (sess_type != RTE_CRYPTO_OP_WITH_SESSION)
1941 : : return -ENOTSUP;
1942 : :
1943 [ # # # # ]: 0 : if (sess == NULL || sess->roc_se_ctx == NULL)
1944 : : return -EINVAL;
1945 : :
1946 : 0 : if ((sess->dp_thr_type == CPT_DP_THREAD_TYPE_PDCP) ||
1947 : : (sess->dp_thr_type == CPT_DP_THREAD_TYPE_PDCP_CHAIN) ||
1948 [ # # ]: 0 : (sess->dp_thr_type == CPT_DP_THREAD_TYPE_KASUMI) ||
1949 : : (sess->dp_thr_type == CPT_DP_THREAD_TYPE_SM))
1950 : : return -ENOTSUP;
1951 : :
1952 [ # # ]: 0 : if ((sess->dp_thr_type == CPT_DP_THREAD_AUTH_ONLY) &&
1953 [ # # ]: 0 : ((sess->roc_se_ctx->fc_type == ROC_SE_KASUMI) ||
1954 : : (sess->roc_se_ctx->fc_type == ROC_SE_PDCP)))
1955 : : return -ENOTSUP;
1956 : :
1957 [ # # ]: 0 : if (sess->roc_se_ctx->hash_type == ROC_SE_SHA1_TYPE)
1958 : : return -ENOTSUP;
1959 : :
1960 : : dp_ctx = (struct cnxk_sym_dp_ctx *)raw_dp_ctx->drv_ctx_data;
1961 : 0 : dp_ctx->sess = sess;
1962 : :
1963 [ # # ]: 0 : if (!is_update) {
1964 : : struct cnxk_cpt_vf *vf;
1965 : :
1966 : 0 : raw_dp_ctx->qp_data = (struct cnxk_cpt_qp *)dev->data->queue_pairs[qp_id];
1967 : 0 : raw_dp_ctx->dequeue = cn10k_cpt_sym_raw_dequeue;
1968 : 0 : raw_dp_ctx->dequeue_burst = cn10k_cpt_sym_raw_dequeue_burst;
1969 : :
1970 : 0 : vf = dev->data->dev_private;
1971 [ # # ]: 0 : if (vf->cpt.hw_caps[CPT_ENG_TYPE_SE].sg_ver2 &&
1972 [ # # ]: 0 : vf->cpt.hw_caps[CPT_ENG_TYPE_IE].sg_ver2) {
1973 : 0 : raw_dp_ctx->enqueue = cn10k_cpt_raw_enqueue_sgv2;
1974 : 0 : raw_dp_ctx->enqueue_burst = cn10k_cpt_raw_enqueue_burst_sgv2;
1975 : : } else {
1976 : 0 : raw_dp_ctx->enqueue = cn10k_cpt_raw_enqueue_sgv1;
1977 : 0 : raw_dp_ctx->enqueue_burst = cn10k_cpt_raw_enqueue_burst_sgv1;
1978 : : }
1979 : : }
1980 : :
1981 : : return 0;
1982 : : }
1983 : :
1984 : : RTE_EXPORT_INTERNAL_SYMBOL(cn10k_cryptodev_sec_rx_inject_configure)
1985 : : int
1986 : 0 : cn10k_cryptodev_sec_rx_inject_configure(void *device, uint16_t port_id, bool enable)
1987 : : {
1988 : : struct rte_cryptodev *crypto_dev = device;
1989 : : struct rte_eth_dev *eth_dev;
1990 : : struct cnxk_cpt_vf *vf;
1991 : : int ret;
1992 : :
1993 [ # # ]: 0 : if (!rte_eth_dev_is_valid_port(port_id))
1994 : : return -EINVAL;
1995 : :
1996 [ # # ]: 0 : if (!(crypto_dev->feature_flags & RTE_CRYPTODEV_FF_SECURITY_RX_INJECT))
1997 : : return -ENOTSUP;
1998 : :
1999 : : /* Rx Inject is supported only with CPT05. sg_ver2 indicates that CPT05 is loaded */
2000 : 0 : vf = crypto_dev->data->dev_private;
2001 [ # # # # ]: 0 : if (!(vf->cpt.hw_caps[CPT_ENG_TYPE_SE].sg_ver2 && vf->cpt.hw_caps[CPT_ENG_TYPE_IE].sg_ver2))
2002 : : return -ENOTSUP;
2003 : :
2004 : : eth_dev = &rte_eth_devices[port_id];
2005 : :
2006 : 0 : ret = strncmp(eth_dev->device->driver->name, "net_cn10k", 8);
2007 [ # # ]: 0 : if (ret)
2008 : : return -ENOTSUP;
2009 : :
2010 : 0 : roc_idev_nix_rx_inject_set(port_id, enable);
2011 : :
2012 : 0 : return 0;
2013 : : }
2014 : :
2015 : : struct rte_cryptodev_ops cn10k_cpt_ops = {
2016 : : /* Device control ops */
2017 : : .dev_configure = cnxk_cpt_dev_config,
2018 : : .dev_start = cnxk_cpt_dev_start,
2019 : : .dev_stop = cnxk_cpt_dev_stop,
2020 : : .dev_close = cnxk_cpt_dev_close,
2021 : : .dev_infos_get = cn10k_cpt_dev_info_get,
2022 : :
2023 : : .stats_get = NULL,
2024 : : .stats_reset = NULL,
2025 : : .queue_pair_setup = cnxk_cpt_queue_pair_setup,
2026 : : .queue_pair_release = cnxk_cpt_queue_pair_release,
2027 : : .queue_pair_reset = cnxk_cpt_queue_pair_reset,
2028 : :
2029 : : /* Symmetric crypto ops */
2030 : : .sym_session_get_size = cnxk_cpt_sym_session_get_size,
2031 : : .sym_session_configure = cnxk_cpt_sym_session_configure,
2032 : : .sym_session_clear = cnxk_cpt_sym_session_clear,
2033 : :
2034 : : /* Asymmetric crypto ops */
2035 : : .asym_session_get_size = cnxk_ae_session_size_get,
2036 : : .asym_session_configure = cnxk_ae_session_cfg,
2037 : : .asym_session_clear = cnxk_ae_session_clear,
2038 : :
2039 : : /* Event crypto ops */
2040 : : .session_ev_mdata_set = cn10k_cpt_crypto_adapter_ev_mdata_set,
2041 : : .queue_pair_event_error_query = cnxk_cpt_queue_pair_event_error_query,
2042 : :
2043 : : /* Raw data-path API related operations */
2044 : : .sym_get_raw_dp_ctx_size = cn10k_sym_get_raw_dp_ctx_size,
2045 : : .sym_configure_raw_dp_ctx = cn10k_sym_configure_raw_dp_ctx,
2046 : : };
|