1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
4 * Copyright 2016-2020 NXP
14 #include <rte_cryptodev.h>
15 #include <rte_malloc.h>
16 #include <rte_memcpy.h>
17 #include <rte_string_fns.h>
18 #include <rte_cycles.h>
19 #include <rte_kvargs.h>
21 #include <rte_cryptodev_pmd.h>
22 #include <rte_common.h>
23 #include <rte_fslmc.h>
24 #include <fslmc_vfio.h>
25 #include <dpaa2_hw_pvt.h>
26 #include <dpaa2_hw_dpio.h>
27 #include <dpaa2_hw_mempool.h>
28 #include <fsl_dpopr.h>
29 #include <fsl_dpseci.h>
30 #include <fsl_mc_sys.h>
32 #include "dpaa2_sec_priv.h"
33 #include "dpaa2_sec_event.h"
34 #include "dpaa2_sec_logs.h"
36 /* RTA header files */
37 #include <desc/ipsec.h>
38 #include <desc/pdcp.h>
39 #include <desc/sdap.h>
40 #include <desc/algo.h>
42 /* Minimum job descriptor consists of a oneword job descriptor HEADER and
43 * a pointer to the shared descriptor
45 #define MIN_JOB_DESC_SIZE (CAAM_CMD_SZ + CAAM_PTR_SZ)
46 #define FSL_VENDOR_ID 0x1957
47 #define FSL_DEVICE_ID 0x410
48 #define FSL_SUBSYSTEM_SEC 1
49 #define FSL_MC_DPSECI_DEVID 3
52 /* FLE_POOL_NUM_BUFS is set as per the ipsec-secgw application */
53 #define FLE_POOL_NUM_BUFS 32000
54 #define FLE_POOL_BUF_SIZE 256
55 #define FLE_POOL_CACHE_SIZE 512
56 #define FLE_SG_MEM_SIZE(num) (FLE_POOL_BUF_SIZE + ((num) * 32))
57 #define SEC_FLC_DHR_OUTBOUND -114
58 #define SEC_FLC_DHR_INBOUND 0
60 static uint8_t cryptodev_driver_id;
62 #ifdef RTE_LIB_SECURITY
64 build_proto_compound_sg_fd(dpaa2_sec_session *sess,
65 struct rte_crypto_op *op,
66 struct qbman_fd *fd, uint16_t bpid)
68 struct rte_crypto_sym_op *sym_op = op->sym;
69 struct ctxt_priv *priv = sess->ctxt;
70 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
71 struct sec_flow_context *flc;
72 struct rte_mbuf *mbuf;
73 uint32_t in_len = 0, out_len = 0;
80 /* first FLE entry used to store mbuf and session ctxt */
81 fle = (struct qbman_fle *)rte_malloc(NULL,
82 FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
85 DPAA2_SEC_DP_ERR("Proto:SG: Memory alloc failed for SGE");
88 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
89 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
90 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
92 /* Save the shared descriptor */
93 flc = &priv->flc_desc[0].flc;
99 if (likely(bpid < MAX_BPID)) {
100 DPAA2_SET_FD_BPID(fd, bpid);
101 DPAA2_SET_FLE_BPID(op_fle, bpid);
102 DPAA2_SET_FLE_BPID(ip_fle, bpid);
104 DPAA2_SET_FD_IVP(fd);
105 DPAA2_SET_FLE_IVP(op_fle);
106 DPAA2_SET_FLE_IVP(ip_fle);
109 /* Configure FD as a FRAME LIST */
110 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
111 DPAA2_SET_FD_COMPOUND_FMT(fd);
112 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
114 /* Configure Output FLE with Scatter/Gather Entry */
115 DPAA2_SET_FLE_SG_EXT(op_fle);
116 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
118 /* Configure Output SGE for Encap/Decap */
119 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
120 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
123 sge->length = mbuf->data_len;
124 out_len += sge->length;
127 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
128 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
130 /* using buf_len for last buf - so that extra data can be added */
131 sge->length = mbuf->buf_len - mbuf->data_off;
132 out_len += sge->length;
134 DPAA2_SET_FLE_FIN(sge);
135 op_fle->length = out_len;
138 mbuf = sym_op->m_src;
140 /* Configure Input FLE with Scatter/Gather Entry */
141 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
142 DPAA2_SET_FLE_SG_EXT(ip_fle);
143 DPAA2_SET_FLE_FIN(ip_fle);
145 /* Configure input SGE for Encap/Decap */
146 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
147 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
148 sge->length = mbuf->data_len;
149 in_len += sge->length;
155 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
156 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
157 sge->length = mbuf->data_len;
158 in_len += sge->length;
161 ip_fle->length = in_len;
162 DPAA2_SET_FLE_FIN(sge);
164 /* In case of PDCP, per packet HFN is stored in
165 * mbuf priv after sym_op.
167 if (sess->ctxt_type == DPAA2_SEC_PDCP && sess->pdcp.hfn_ovd) {
168 uint32_t hfn_ovd = *(uint32_t *)((uint8_t *)op +
169 sess->pdcp.hfn_ovd_offset);
170 /*enable HFN override override */
171 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, hfn_ovd);
172 DPAA2_SET_FLE_INTERNAL_JD(op_fle, hfn_ovd);
173 DPAA2_SET_FD_INTERNAL_JD(fd, hfn_ovd);
175 DPAA2_SET_FD_LEN(fd, ip_fle->length);
181 build_proto_compound_fd(dpaa2_sec_session *sess,
182 struct rte_crypto_op *op,
183 struct qbman_fd *fd, uint16_t bpid)
185 struct rte_crypto_sym_op *sym_op = op->sym;
186 struct ctxt_priv *priv = sess->ctxt;
187 struct qbman_fle *fle, *ip_fle, *op_fle;
188 struct sec_flow_context *flc;
189 struct rte_mbuf *src_mbuf = sym_op->m_src;
190 struct rte_mbuf *dst_mbuf = sym_op->m_dst;
196 /* Save the shared descriptor */
197 flc = &priv->flc_desc[0].flc;
199 /* we are using the first FLE entry to store Mbuf */
200 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
202 DPAA2_SEC_DP_ERR("Memory alloc failed");
205 memset(fle, 0, FLE_POOL_BUF_SIZE);
206 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
207 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
212 if (likely(bpid < MAX_BPID)) {
213 DPAA2_SET_FD_BPID(fd, bpid);
214 DPAA2_SET_FLE_BPID(op_fle, bpid);
215 DPAA2_SET_FLE_BPID(ip_fle, bpid);
217 DPAA2_SET_FD_IVP(fd);
218 DPAA2_SET_FLE_IVP(op_fle);
219 DPAA2_SET_FLE_IVP(ip_fle);
222 /* Configure FD as a FRAME LIST */
223 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
224 DPAA2_SET_FD_COMPOUND_FMT(fd);
225 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
227 /* Configure Output FLE with dst mbuf data */
228 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_MBUF_VADDR_TO_IOVA(dst_mbuf));
229 DPAA2_SET_FLE_OFFSET(op_fle, dst_mbuf->data_off);
230 DPAA2_SET_FLE_LEN(op_fle, dst_mbuf->buf_len);
232 /* Configure Input FLE with src mbuf data */
233 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_MBUF_VADDR_TO_IOVA(src_mbuf));
234 DPAA2_SET_FLE_OFFSET(ip_fle, src_mbuf->data_off);
235 DPAA2_SET_FLE_LEN(ip_fle, src_mbuf->pkt_len);
237 DPAA2_SET_FD_LEN(fd, ip_fle->length);
238 DPAA2_SET_FLE_FIN(ip_fle);
240 /* In case of PDCP, per packet HFN is stored in
241 * mbuf priv after sym_op.
243 if (sess->ctxt_type == DPAA2_SEC_PDCP && sess->pdcp.hfn_ovd) {
244 uint32_t hfn_ovd = *(uint32_t *)((uint8_t *)op +
245 sess->pdcp.hfn_ovd_offset);
246 /*enable HFN override override */
247 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, hfn_ovd);
248 DPAA2_SET_FLE_INTERNAL_JD(op_fle, hfn_ovd);
249 DPAA2_SET_FD_INTERNAL_JD(fd, hfn_ovd);
257 build_proto_fd(dpaa2_sec_session *sess,
258 struct rte_crypto_op *op,
259 struct qbman_fd *fd, uint16_t bpid)
261 struct rte_crypto_sym_op *sym_op = op->sym;
263 return build_proto_compound_fd(sess, op, fd, bpid);
265 struct ctxt_priv *priv = sess->ctxt;
266 struct sec_flow_context *flc;
267 struct rte_mbuf *mbuf = sym_op->m_src;
269 if (likely(bpid < MAX_BPID))
270 DPAA2_SET_FD_BPID(fd, bpid);
272 DPAA2_SET_FD_IVP(fd);
274 /* Save the shared descriptor */
275 flc = &priv->flc_desc[0].flc;
277 DPAA2_SET_FD_ADDR(fd, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
278 DPAA2_SET_FD_OFFSET(fd, sym_op->m_src->data_off);
279 DPAA2_SET_FD_LEN(fd, sym_op->m_src->pkt_len);
280 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
282 /* save physical address of mbuf */
283 op->sym->aead.digest.phys_addr = mbuf->buf_iova;
284 mbuf->buf_iova = (size_t)op;
291 build_authenc_gcm_sg_fd(dpaa2_sec_session *sess,
292 struct rte_crypto_op *op,
293 struct qbman_fd *fd, __rte_unused uint16_t bpid)
295 struct rte_crypto_sym_op *sym_op = op->sym;
296 struct ctxt_priv *priv = sess->ctxt;
297 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
298 struct sec_flow_context *flc;
299 uint32_t auth_only_len = sess->ext_params.aead_ctxt.auth_only_len;
300 int icv_len = sess->digest_length;
302 struct rte_mbuf *mbuf;
303 uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
307 mbuf = sym_op->m_dst;
309 mbuf = sym_op->m_src;
311 /* first FLE entry used to store mbuf and session ctxt */
312 fle = (struct qbman_fle *)rte_malloc(NULL,
313 FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
314 RTE_CACHE_LINE_SIZE);
315 if (unlikely(!fle)) {
316 DPAA2_SEC_ERR("GCM SG: Memory alloc failed for SGE");
319 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
320 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
321 DPAA2_FLE_SAVE_CTXT(fle, (size_t)priv);
327 /* Save the shared descriptor */
328 flc = &priv->flc_desc[0].flc;
330 /* Configure FD as a FRAME LIST */
331 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
332 DPAA2_SET_FD_COMPOUND_FMT(fd);
333 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
335 DPAA2_SEC_DP_DEBUG("GCM SG: auth_off: 0x%x/length %d, digest-len=%d\n"
336 "iv-len=%d data_off: 0x%x\n",
337 sym_op->aead.data.offset,
338 sym_op->aead.data.length,
341 sym_op->m_src->data_off);
343 /* Configure Output FLE with Scatter/Gather Entry */
344 DPAA2_SET_FLE_SG_EXT(op_fle);
345 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
348 DPAA2_SET_FLE_INTERNAL_JD(op_fle, auth_only_len);
350 op_fle->length = (sess->dir == DIR_ENC) ?
351 (sym_op->aead.data.length + icv_len) :
352 sym_op->aead.data.length;
354 /* Configure Output SGE for Encap/Decap */
355 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
356 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off + sym_op->aead.data.offset);
357 sge->length = mbuf->data_len - sym_op->aead.data.offset;
363 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
364 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
365 sge->length = mbuf->data_len;
368 sge->length -= icv_len;
370 if (sess->dir == DIR_ENC) {
372 DPAA2_SET_FLE_ADDR(sge,
373 DPAA2_VADDR_TO_IOVA(sym_op->aead.digest.data));
374 sge->length = icv_len;
376 DPAA2_SET_FLE_FIN(sge);
379 mbuf = sym_op->m_src;
381 /* Configure Input FLE with Scatter/Gather Entry */
382 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
383 DPAA2_SET_FLE_SG_EXT(ip_fle);
384 DPAA2_SET_FLE_FIN(ip_fle);
385 ip_fle->length = (sess->dir == DIR_ENC) ?
386 (sym_op->aead.data.length + sess->iv.length + auth_only_len) :
387 (sym_op->aead.data.length + sess->iv.length + auth_only_len +
390 /* Configure Input SGE for Encap/Decap */
391 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(IV_ptr));
392 sge->length = sess->iv.length;
396 DPAA2_SET_FLE_ADDR(sge,
397 DPAA2_VADDR_TO_IOVA(sym_op->aead.aad.data));
398 sge->length = auth_only_len;
402 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
403 DPAA2_SET_FLE_OFFSET(sge, sym_op->aead.data.offset +
405 sge->length = mbuf->data_len - sym_op->aead.data.offset;
411 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
412 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
413 sge->length = mbuf->data_len;
417 if (sess->dir == DIR_DEC) {
419 old_icv = (uint8_t *)(sge + 1);
420 memcpy(old_icv, sym_op->aead.digest.data, icv_len);
421 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
422 sge->length = icv_len;
425 DPAA2_SET_FLE_FIN(sge);
427 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, auth_only_len);
428 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
430 DPAA2_SET_FD_LEN(fd, ip_fle->length);
436 build_authenc_gcm_fd(dpaa2_sec_session *sess,
437 struct rte_crypto_op *op,
438 struct qbman_fd *fd, uint16_t bpid)
440 struct rte_crypto_sym_op *sym_op = op->sym;
441 struct ctxt_priv *priv = sess->ctxt;
442 struct qbman_fle *fle, *sge;
443 struct sec_flow_context *flc;
444 uint32_t auth_only_len = sess->ext_params.aead_ctxt.auth_only_len;
445 int icv_len = sess->digest_length, retval;
447 struct rte_mbuf *dst;
448 uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
456 /* TODO we are using the first FLE entry to store Mbuf and session ctxt.
457 * Currently we donot know which FLE has the mbuf stored.
458 * So while retreiving we can go back 1 FLE from the FD -ADDR
459 * to get the MBUF Addr from the previous FLE.
460 * We can have a better approach to use the inline Mbuf
462 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
464 DPAA2_SEC_ERR("GCM: Memory alloc failed for SGE");
467 memset(fle, 0, FLE_POOL_BUF_SIZE);
468 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
469 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
472 if (likely(bpid < MAX_BPID)) {
473 DPAA2_SET_FD_BPID(fd, bpid);
474 DPAA2_SET_FLE_BPID(fle, bpid);
475 DPAA2_SET_FLE_BPID(fle + 1, bpid);
476 DPAA2_SET_FLE_BPID(sge, bpid);
477 DPAA2_SET_FLE_BPID(sge + 1, bpid);
478 DPAA2_SET_FLE_BPID(sge + 2, bpid);
479 DPAA2_SET_FLE_BPID(sge + 3, bpid);
481 DPAA2_SET_FD_IVP(fd);
482 DPAA2_SET_FLE_IVP(fle);
483 DPAA2_SET_FLE_IVP((fle + 1));
484 DPAA2_SET_FLE_IVP(sge);
485 DPAA2_SET_FLE_IVP((sge + 1));
486 DPAA2_SET_FLE_IVP((sge + 2));
487 DPAA2_SET_FLE_IVP((sge + 3));
490 /* Save the shared descriptor */
491 flc = &priv->flc_desc[0].flc;
492 /* Configure FD as a FRAME LIST */
493 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
494 DPAA2_SET_FD_COMPOUND_FMT(fd);
495 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
497 DPAA2_SEC_DP_DEBUG("GCM: auth_off: 0x%x/length %d, digest-len=%d\n"
498 "iv-len=%d data_off: 0x%x\n",
499 sym_op->aead.data.offset,
500 sym_op->aead.data.length,
503 sym_op->m_src->data_off);
505 /* Configure Output FLE with Scatter/Gather Entry */
506 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
508 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
509 fle->length = (sess->dir == DIR_ENC) ?
510 (sym_op->aead.data.length + icv_len) :
511 sym_op->aead.data.length;
513 DPAA2_SET_FLE_SG_EXT(fle);
515 /* Configure Output SGE for Encap/Decap */
516 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(dst));
517 DPAA2_SET_FLE_OFFSET(sge, dst->data_off + sym_op->aead.data.offset);
518 sge->length = sym_op->aead.data.length;
520 if (sess->dir == DIR_ENC) {
522 DPAA2_SET_FLE_ADDR(sge,
523 DPAA2_VADDR_TO_IOVA(sym_op->aead.digest.data));
524 sge->length = sess->digest_length;
526 DPAA2_SET_FLE_FIN(sge);
531 /* Configure Input FLE with Scatter/Gather Entry */
532 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
533 DPAA2_SET_FLE_SG_EXT(fle);
534 DPAA2_SET_FLE_FIN(fle);
535 fle->length = (sess->dir == DIR_ENC) ?
536 (sym_op->aead.data.length + sess->iv.length + auth_only_len) :
537 (sym_op->aead.data.length + sess->iv.length + auth_only_len +
538 sess->digest_length);
540 /* Configure Input SGE for Encap/Decap */
541 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(IV_ptr));
542 sge->length = sess->iv.length;
545 DPAA2_SET_FLE_ADDR(sge,
546 DPAA2_VADDR_TO_IOVA(sym_op->aead.aad.data));
547 sge->length = auth_only_len;
548 DPAA2_SET_FLE_BPID(sge, bpid);
552 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
553 DPAA2_SET_FLE_OFFSET(sge, sym_op->aead.data.offset +
554 sym_op->m_src->data_off);
555 sge->length = sym_op->aead.data.length;
556 if (sess->dir == DIR_DEC) {
558 old_icv = (uint8_t *)(sge + 1);
559 memcpy(old_icv, sym_op->aead.digest.data,
560 sess->digest_length);
561 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
562 sge->length = sess->digest_length;
564 DPAA2_SET_FLE_FIN(sge);
567 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
568 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
571 DPAA2_SET_FD_LEN(fd, fle->length);
576 build_authenc_sg_fd(dpaa2_sec_session *sess,
577 struct rte_crypto_op *op,
578 struct qbman_fd *fd, __rte_unused uint16_t bpid)
580 struct rte_crypto_sym_op *sym_op = op->sym;
581 struct ctxt_priv *priv = sess->ctxt;
582 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
583 struct sec_flow_context *flc;
584 uint16_t auth_hdr_len = sym_op->cipher.data.offset -
585 sym_op->auth.data.offset;
586 uint16_t auth_tail_len = sym_op->auth.data.length -
587 sym_op->cipher.data.length - auth_hdr_len;
588 uint32_t auth_only_len = (auth_tail_len << 16) | auth_hdr_len;
589 int icv_len = sess->digest_length;
591 struct rte_mbuf *mbuf;
592 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
596 mbuf = sym_op->m_dst;
598 mbuf = sym_op->m_src;
600 /* first FLE entry used to store mbuf and session ctxt */
601 fle = (struct qbman_fle *)rte_malloc(NULL,
602 FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
603 RTE_CACHE_LINE_SIZE);
604 if (unlikely(!fle)) {
605 DPAA2_SEC_ERR("AUTHENC SG: Memory alloc failed for SGE");
608 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
609 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
610 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
616 /* Save the shared descriptor */
617 flc = &priv->flc_desc[0].flc;
619 /* Configure FD as a FRAME LIST */
620 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
621 DPAA2_SET_FD_COMPOUND_FMT(fd);
622 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
625 "AUTHENC SG: auth_off: 0x%x/length %d, digest-len=%d\n"
626 "cipher_off: 0x%x/length %d, iv-len=%d data_off: 0x%x\n",
627 sym_op->auth.data.offset,
628 sym_op->auth.data.length,
630 sym_op->cipher.data.offset,
631 sym_op->cipher.data.length,
633 sym_op->m_src->data_off);
635 /* Configure Output FLE with Scatter/Gather Entry */
636 DPAA2_SET_FLE_SG_EXT(op_fle);
637 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
640 DPAA2_SET_FLE_INTERNAL_JD(op_fle, auth_only_len);
642 op_fle->length = (sess->dir == DIR_ENC) ?
643 (sym_op->cipher.data.length + icv_len) :
644 sym_op->cipher.data.length;
646 /* Configure Output SGE for Encap/Decap */
647 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
648 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off + sym_op->auth.data.offset);
649 sge->length = mbuf->data_len - sym_op->auth.data.offset;
655 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
656 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
657 sge->length = mbuf->data_len;
660 sge->length -= icv_len;
662 if (sess->dir == DIR_ENC) {
664 DPAA2_SET_FLE_ADDR(sge,
665 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
666 sge->length = icv_len;
668 DPAA2_SET_FLE_FIN(sge);
671 mbuf = sym_op->m_src;
673 /* Configure Input FLE with Scatter/Gather Entry */
674 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
675 DPAA2_SET_FLE_SG_EXT(ip_fle);
676 DPAA2_SET_FLE_FIN(ip_fle);
677 ip_fle->length = (sess->dir == DIR_ENC) ?
678 (sym_op->auth.data.length + sess->iv.length) :
679 (sym_op->auth.data.length + sess->iv.length +
682 /* Configure Input SGE for Encap/Decap */
683 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
684 sge->length = sess->iv.length;
687 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
688 DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset +
690 sge->length = mbuf->data_len - sym_op->auth.data.offset;
696 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
697 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
698 sge->length = mbuf->data_len;
701 sge->length -= icv_len;
703 if (sess->dir == DIR_DEC) {
705 old_icv = (uint8_t *)(sge + 1);
706 memcpy(old_icv, sym_op->auth.digest.data,
708 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
709 sge->length = icv_len;
712 DPAA2_SET_FLE_FIN(sge);
714 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, auth_only_len);
715 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
717 DPAA2_SET_FD_LEN(fd, ip_fle->length);
723 build_authenc_fd(dpaa2_sec_session *sess,
724 struct rte_crypto_op *op,
725 struct qbman_fd *fd, uint16_t bpid)
727 struct rte_crypto_sym_op *sym_op = op->sym;
728 struct ctxt_priv *priv = sess->ctxt;
729 struct qbman_fle *fle, *sge;
730 struct sec_flow_context *flc;
731 uint16_t auth_hdr_len = sym_op->cipher.data.offset -
732 sym_op->auth.data.offset;
733 uint16_t auth_tail_len = sym_op->auth.data.length -
734 sym_op->cipher.data.length - auth_hdr_len;
735 uint32_t auth_only_len = (auth_tail_len << 16) | auth_hdr_len;
737 int icv_len = sess->digest_length, retval;
739 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
741 struct rte_mbuf *dst;
748 /* we are using the first FLE entry to store Mbuf.
749 * Currently we donot know which FLE has the mbuf stored.
750 * So while retreiving we can go back 1 FLE from the FD -ADDR
751 * to get the MBUF Addr from the previous FLE.
752 * We can have a better approach to use the inline Mbuf
754 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
756 DPAA2_SEC_ERR("Memory alloc failed for SGE");
759 memset(fle, 0, FLE_POOL_BUF_SIZE);
760 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
761 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
764 if (likely(bpid < MAX_BPID)) {
765 DPAA2_SET_FD_BPID(fd, bpid);
766 DPAA2_SET_FLE_BPID(fle, bpid);
767 DPAA2_SET_FLE_BPID(fle + 1, bpid);
768 DPAA2_SET_FLE_BPID(sge, bpid);
769 DPAA2_SET_FLE_BPID(sge + 1, bpid);
770 DPAA2_SET_FLE_BPID(sge + 2, bpid);
771 DPAA2_SET_FLE_BPID(sge + 3, bpid);
773 DPAA2_SET_FD_IVP(fd);
774 DPAA2_SET_FLE_IVP(fle);
775 DPAA2_SET_FLE_IVP((fle + 1));
776 DPAA2_SET_FLE_IVP(sge);
777 DPAA2_SET_FLE_IVP((sge + 1));
778 DPAA2_SET_FLE_IVP((sge + 2));
779 DPAA2_SET_FLE_IVP((sge + 3));
782 /* Save the shared descriptor */
783 flc = &priv->flc_desc[0].flc;
784 /* Configure FD as a FRAME LIST */
785 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
786 DPAA2_SET_FD_COMPOUND_FMT(fd);
787 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
790 "AUTHENC: auth_off: 0x%x/length %d, digest-len=%d\n"
791 "cipher_off: 0x%x/length %d, iv-len=%d data_off: 0x%x\n",
792 sym_op->auth.data.offset,
793 sym_op->auth.data.length,
795 sym_op->cipher.data.offset,
796 sym_op->cipher.data.length,
798 sym_op->m_src->data_off);
800 /* Configure Output FLE with Scatter/Gather Entry */
801 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
803 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
804 fle->length = (sess->dir == DIR_ENC) ?
805 (sym_op->cipher.data.length + icv_len) :
806 sym_op->cipher.data.length;
808 DPAA2_SET_FLE_SG_EXT(fle);
810 /* Configure Output SGE for Encap/Decap */
811 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(dst));
812 DPAA2_SET_FLE_OFFSET(sge, sym_op->cipher.data.offset +
814 sge->length = sym_op->cipher.data.length;
816 if (sess->dir == DIR_ENC) {
818 DPAA2_SET_FLE_ADDR(sge,
819 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
820 sge->length = sess->digest_length;
821 DPAA2_SET_FD_LEN(fd, (sym_op->auth.data.length +
824 DPAA2_SET_FLE_FIN(sge);
829 /* Configure Input FLE with Scatter/Gather Entry */
830 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
831 DPAA2_SET_FLE_SG_EXT(fle);
832 DPAA2_SET_FLE_FIN(fle);
833 fle->length = (sess->dir == DIR_ENC) ?
834 (sym_op->auth.data.length + sess->iv.length) :
835 (sym_op->auth.data.length + sess->iv.length +
836 sess->digest_length);
838 /* Configure Input SGE for Encap/Decap */
839 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
840 sge->length = sess->iv.length;
843 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
844 DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset +
845 sym_op->m_src->data_off);
846 sge->length = sym_op->auth.data.length;
847 if (sess->dir == DIR_DEC) {
849 old_icv = (uint8_t *)(sge + 1);
850 memcpy(old_icv, sym_op->auth.digest.data,
851 sess->digest_length);
852 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
853 sge->length = sess->digest_length;
854 DPAA2_SET_FD_LEN(fd, (sym_op->auth.data.length +
855 sess->digest_length +
858 DPAA2_SET_FLE_FIN(sge);
860 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
861 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
866 static inline int build_auth_sg_fd(
867 dpaa2_sec_session *sess,
868 struct rte_crypto_op *op,
870 __rte_unused uint16_t bpid)
872 struct rte_crypto_sym_op *sym_op = op->sym;
873 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
874 struct sec_flow_context *flc;
875 struct ctxt_priv *priv = sess->ctxt;
876 int data_len, data_offset;
878 struct rte_mbuf *mbuf;
880 data_len = sym_op->auth.data.length;
881 data_offset = sym_op->auth.data.offset;
883 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
884 sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
885 if ((data_len & 7) || (data_offset & 7)) {
886 DPAA2_SEC_ERR("AUTH: len/offset must be full bytes");
890 data_len = data_len >> 3;
891 data_offset = data_offset >> 3;
894 mbuf = sym_op->m_src;
895 fle = (struct qbman_fle *)rte_malloc(NULL,
896 FLE_SG_MEM_SIZE(mbuf->nb_segs),
897 RTE_CACHE_LINE_SIZE);
898 if (unlikely(!fle)) {
899 DPAA2_SEC_ERR("AUTH SG: Memory alloc failed for SGE");
902 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs));
903 /* first FLE entry used to store mbuf and session ctxt */
904 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
905 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
910 flc = &priv->flc_desc[DESC_INITFINAL].flc;
912 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
913 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
914 DPAA2_SET_FD_COMPOUND_FMT(fd);
917 DPAA2_SET_FLE_ADDR(op_fle,
918 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
919 op_fle->length = sess->digest_length;
922 DPAA2_SET_FLE_SG_EXT(ip_fle);
923 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
924 ip_fle->length = data_len;
926 if (sess->iv.length) {
929 iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
932 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2) {
933 iv_ptr = conv_to_snow_f9_iv(iv_ptr);
935 } else if (sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
936 iv_ptr = conv_to_zuc_eia_iv(iv_ptr);
939 sge->length = sess->iv.length;
941 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
942 ip_fle->length += sge->length;
946 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
947 DPAA2_SET_FLE_OFFSET(sge, data_offset + mbuf->data_off);
949 if (data_len <= (mbuf->data_len - data_offset)) {
950 sge->length = data_len;
953 sge->length = mbuf->data_len - data_offset;
955 /* remaining i/p segs */
956 while ((data_len = data_len - sge->length) &&
957 (mbuf = mbuf->next)) {
959 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
960 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
961 if (data_len > mbuf->data_len)
962 sge->length = mbuf->data_len;
964 sge->length = data_len;
968 if (sess->dir == DIR_DEC) {
969 /* Digest verification case */
971 old_digest = (uint8_t *)(sge + 1);
972 rte_memcpy(old_digest, sym_op->auth.digest.data,
973 sess->digest_length);
974 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_digest));
975 sge->length = sess->digest_length;
976 ip_fle->length += sess->digest_length;
978 DPAA2_SET_FLE_FIN(sge);
979 DPAA2_SET_FLE_FIN(ip_fle);
980 DPAA2_SET_FD_LEN(fd, ip_fle->length);
986 build_auth_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
987 struct qbman_fd *fd, uint16_t bpid)
989 struct rte_crypto_sym_op *sym_op = op->sym;
990 struct qbman_fle *fle, *sge;
991 struct sec_flow_context *flc;
992 struct ctxt_priv *priv = sess->ctxt;
993 int data_len, data_offset;
997 data_len = sym_op->auth.data.length;
998 data_offset = sym_op->auth.data.offset;
1000 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
1001 sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
1002 if ((data_len & 7) || (data_offset & 7)) {
1003 DPAA2_SEC_ERR("AUTH: len/offset must be full bytes");
1007 data_len = data_len >> 3;
1008 data_offset = data_offset >> 3;
1011 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
1013 DPAA2_SEC_ERR("AUTH Memory alloc failed for SGE");
1016 memset(fle, 0, FLE_POOL_BUF_SIZE);
1017 /* TODO we are using the first FLE entry to store Mbuf.
1018 * Currently we donot know which FLE has the mbuf stored.
1019 * So while retreiving we can go back 1 FLE from the FD -ADDR
1020 * to get the MBUF Addr from the previous FLE.
1021 * We can have a better approach to use the inline Mbuf
1023 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
1024 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
1028 if (likely(bpid < MAX_BPID)) {
1029 DPAA2_SET_FD_BPID(fd, bpid);
1030 DPAA2_SET_FLE_BPID(fle, bpid);
1031 DPAA2_SET_FLE_BPID(fle + 1, bpid);
1032 DPAA2_SET_FLE_BPID(sge, bpid);
1033 DPAA2_SET_FLE_BPID(sge + 1, bpid);
1035 DPAA2_SET_FD_IVP(fd);
1036 DPAA2_SET_FLE_IVP(fle);
1037 DPAA2_SET_FLE_IVP((fle + 1));
1038 DPAA2_SET_FLE_IVP(sge);
1039 DPAA2_SET_FLE_IVP((sge + 1));
1042 flc = &priv->flc_desc[DESC_INITFINAL].flc;
1043 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
1044 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
1045 DPAA2_SET_FD_COMPOUND_FMT(fd);
1047 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
1048 fle->length = sess->digest_length;
1051 /* Setting input FLE */
1052 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
1053 DPAA2_SET_FLE_SG_EXT(fle);
1054 fle->length = data_len;
1056 if (sess->iv.length) {
1059 iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1062 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2) {
1063 iv_ptr = conv_to_snow_f9_iv(iv_ptr);
1065 } else if (sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
1066 iv_ptr = conv_to_zuc_eia_iv(iv_ptr);
1069 sge->length = sess->iv.length;
1072 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
1073 fle->length = fle->length + sge->length;
1077 /* Setting data to authenticate */
1078 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
1079 DPAA2_SET_FLE_OFFSET(sge, data_offset + sym_op->m_src->data_off);
1080 sge->length = data_len;
1082 if (sess->dir == DIR_DEC) {
1084 old_digest = (uint8_t *)(sge + 1);
1085 rte_memcpy(old_digest, sym_op->auth.digest.data,
1086 sess->digest_length);
1087 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_digest));
1088 sge->length = sess->digest_length;
1089 fle->length = fle->length + sess->digest_length;
1092 DPAA2_SET_FLE_FIN(sge);
1093 DPAA2_SET_FLE_FIN(fle);
1094 DPAA2_SET_FD_LEN(fd, fle->length);
1100 build_cipher_sg_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
1101 struct qbman_fd *fd, __rte_unused uint16_t bpid)
1103 struct rte_crypto_sym_op *sym_op = op->sym;
1104 struct qbman_fle *ip_fle, *op_fle, *sge, *fle;
1105 int data_len, data_offset;
1106 struct sec_flow_context *flc;
1107 struct ctxt_priv *priv = sess->ctxt;
1108 struct rte_mbuf *mbuf;
1109 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1112 data_len = sym_op->cipher.data.length;
1113 data_offset = sym_op->cipher.data.offset;
1115 if (sess->cipher_alg == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
1116 sess->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
1117 if ((data_len & 7) || (data_offset & 7)) {
1118 DPAA2_SEC_ERR("CIPHER: len/offset must be full bytes");
1122 data_len = data_len >> 3;
1123 data_offset = data_offset >> 3;
1127 mbuf = sym_op->m_dst;
1129 mbuf = sym_op->m_src;
1131 /* first FLE entry used to store mbuf and session ctxt */
1132 fle = (struct qbman_fle *)rte_malloc(NULL,
1133 FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
1134 RTE_CACHE_LINE_SIZE);
1136 DPAA2_SEC_ERR("CIPHER SG: Memory alloc failed for SGE");
1139 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
1140 /* first FLE entry used to store mbuf and session ctxt */
1141 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
1142 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
1148 flc = &priv->flc_desc[0].flc;
1151 "CIPHER SG: cipher_off: 0x%x/length %d, ivlen=%d"
1152 " data_off: 0x%x\n",
1156 sym_op->m_src->data_off);
1159 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
1160 op_fle->length = data_len;
1161 DPAA2_SET_FLE_SG_EXT(op_fle);
1164 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1165 DPAA2_SET_FLE_OFFSET(sge, data_offset + mbuf->data_off);
1166 sge->length = mbuf->data_len - data_offset;
1172 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1173 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
1174 sge->length = mbuf->data_len;
1177 DPAA2_SET_FLE_FIN(sge);
1180 "CIPHER SG: 1 - flc = %p, fle = %p FLEaddr = %x-%x, len %d\n",
1181 flc, fle, fle->addr_hi, fle->addr_lo,
1185 mbuf = sym_op->m_src;
1187 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
1188 ip_fle->length = sess->iv.length + data_len;
1189 DPAA2_SET_FLE_SG_EXT(ip_fle);
1192 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
1193 DPAA2_SET_FLE_OFFSET(sge, 0);
1194 sge->length = sess->iv.length;
1199 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1200 DPAA2_SET_FLE_OFFSET(sge, data_offset + mbuf->data_off);
1201 sge->length = mbuf->data_len - data_offset;
1207 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1208 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
1209 sge->length = mbuf->data_len;
1212 DPAA2_SET_FLE_FIN(sge);
1213 DPAA2_SET_FLE_FIN(ip_fle);
1216 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
1217 DPAA2_SET_FD_LEN(fd, ip_fle->length);
1218 DPAA2_SET_FD_COMPOUND_FMT(fd);
1219 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
1222 "CIPHER SG: fdaddr =%" PRIx64 " bpid =%d meta =%d"
1223 " off =%d, len =%d\n",
1224 DPAA2_GET_FD_ADDR(fd),
1225 DPAA2_GET_FD_BPID(fd),
1226 rte_dpaa2_bpid_info[bpid].meta_data_size,
1227 DPAA2_GET_FD_OFFSET(fd),
1228 DPAA2_GET_FD_LEN(fd));
1233 build_cipher_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
1234 struct qbman_fd *fd, uint16_t bpid)
1236 struct rte_crypto_sym_op *sym_op = op->sym;
1237 struct qbman_fle *fle, *sge;
1238 int retval, data_len, data_offset;
1239 struct sec_flow_context *flc;
1240 struct ctxt_priv *priv = sess->ctxt;
1241 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1243 struct rte_mbuf *dst;
1245 data_len = sym_op->cipher.data.length;
1246 data_offset = sym_op->cipher.data.offset;
1248 if (sess->cipher_alg == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
1249 sess->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
1250 if ((data_len & 7) || (data_offset & 7)) {
1251 DPAA2_SEC_ERR("CIPHER: len/offset must be full bytes");
1255 data_len = data_len >> 3;
1256 data_offset = data_offset >> 3;
1260 dst = sym_op->m_dst;
1262 dst = sym_op->m_src;
1264 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
1266 DPAA2_SEC_ERR("CIPHER: Memory alloc failed for SGE");
1269 memset(fle, 0, FLE_POOL_BUF_SIZE);
1270 /* TODO we are using the first FLE entry to store Mbuf.
1271 * Currently we donot know which FLE has the mbuf stored.
1272 * So while retreiving we can go back 1 FLE from the FD -ADDR
1273 * to get the MBUF Addr from the previous FLE.
1274 * We can have a better approach to use the inline Mbuf
1276 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
1277 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
1281 if (likely(bpid < MAX_BPID)) {
1282 DPAA2_SET_FD_BPID(fd, bpid);
1283 DPAA2_SET_FLE_BPID(fle, bpid);
1284 DPAA2_SET_FLE_BPID(fle + 1, bpid);
1285 DPAA2_SET_FLE_BPID(sge, bpid);
1286 DPAA2_SET_FLE_BPID(sge + 1, bpid);
1288 DPAA2_SET_FD_IVP(fd);
1289 DPAA2_SET_FLE_IVP(fle);
1290 DPAA2_SET_FLE_IVP((fle + 1));
1291 DPAA2_SET_FLE_IVP(sge);
1292 DPAA2_SET_FLE_IVP((sge + 1));
1295 flc = &priv->flc_desc[0].flc;
1296 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
1297 DPAA2_SET_FD_LEN(fd, data_len + sess->iv.length);
1298 DPAA2_SET_FD_COMPOUND_FMT(fd);
1299 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
1302 "CIPHER: cipher_off: 0x%x/length %d, ivlen=%d,"
1303 " data_off: 0x%x\n",
1307 sym_op->m_src->data_off);
1309 DPAA2_SET_FLE_ADDR(fle, DPAA2_MBUF_VADDR_TO_IOVA(dst));
1310 DPAA2_SET_FLE_OFFSET(fle, data_offset + dst->data_off);
1312 fle->length = data_len + sess->iv.length;
1315 "CIPHER: 1 - flc = %p, fle = %p FLEaddr = %x-%x, length %d\n",
1316 flc, fle, fle->addr_hi, fle->addr_lo,
1321 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
1322 fle->length = data_len + sess->iv.length;
1324 DPAA2_SET_FLE_SG_EXT(fle);
1326 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
1327 sge->length = sess->iv.length;
1330 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
1331 DPAA2_SET_FLE_OFFSET(sge, data_offset + sym_op->m_src->data_off);
1333 sge->length = data_len;
1334 DPAA2_SET_FLE_FIN(sge);
1335 DPAA2_SET_FLE_FIN(fle);
1338 "CIPHER: fdaddr =%" PRIx64 " bpid =%d meta =%d"
1339 " off =%d, len =%d\n",
1340 DPAA2_GET_FD_ADDR(fd),
1341 DPAA2_GET_FD_BPID(fd),
1342 rte_dpaa2_bpid_info[bpid].meta_data_size,
1343 DPAA2_GET_FD_OFFSET(fd),
1344 DPAA2_GET_FD_LEN(fd));
1350 build_sec_fd(struct rte_crypto_op *op,
1351 struct qbman_fd *fd, uint16_t bpid)
1354 dpaa2_sec_session *sess;
1356 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION)
1357 sess = (dpaa2_sec_session *)get_sym_session_private_data(
1358 op->sym->session, cryptodev_driver_id);
1359 #ifdef RTE_LIB_SECURITY
1360 else if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION)
1361 sess = (dpaa2_sec_session *)get_sec_session_private_data(
1362 op->sym->sec_session);
1370 /* Any of the buffer is segmented*/
1371 if (!rte_pktmbuf_is_contiguous(op->sym->m_src) ||
1372 ((op->sym->m_dst != NULL) &&
1373 !rte_pktmbuf_is_contiguous(op->sym->m_dst))) {
1374 switch (sess->ctxt_type) {
1375 case DPAA2_SEC_CIPHER:
1376 ret = build_cipher_sg_fd(sess, op, fd, bpid);
1378 case DPAA2_SEC_AUTH:
1379 ret = build_auth_sg_fd(sess, op, fd, bpid);
1381 case DPAA2_SEC_AEAD:
1382 ret = build_authenc_gcm_sg_fd(sess, op, fd, bpid);
1384 case DPAA2_SEC_CIPHER_HASH:
1385 ret = build_authenc_sg_fd(sess, op, fd, bpid);
1387 #ifdef RTE_LIB_SECURITY
1388 case DPAA2_SEC_IPSEC:
1389 case DPAA2_SEC_PDCP:
1390 ret = build_proto_compound_sg_fd(sess, op, fd, bpid);
1393 case DPAA2_SEC_HASH_CIPHER:
1395 DPAA2_SEC_ERR("error: Unsupported session");
1398 switch (sess->ctxt_type) {
1399 case DPAA2_SEC_CIPHER:
1400 ret = build_cipher_fd(sess, op, fd, bpid);
1402 case DPAA2_SEC_AUTH:
1403 ret = build_auth_fd(sess, op, fd, bpid);
1405 case DPAA2_SEC_AEAD:
1406 ret = build_authenc_gcm_fd(sess, op, fd, bpid);
1408 case DPAA2_SEC_CIPHER_HASH:
1409 ret = build_authenc_fd(sess, op, fd, bpid);
1411 #ifdef RTE_LIB_SECURITY
1412 case DPAA2_SEC_IPSEC:
1413 ret = build_proto_fd(sess, op, fd, bpid);
1415 case DPAA2_SEC_PDCP:
1416 ret = build_proto_compound_fd(sess, op, fd, bpid);
1419 case DPAA2_SEC_HASH_CIPHER:
1421 DPAA2_SEC_ERR("error: Unsupported session");
1429 dpaa2_sec_enqueue_burst(void *qp, struct rte_crypto_op **ops,
1432 /* Function to transmit the frames to given device and VQ*/
1435 struct qbman_fd fd_arr[MAX_TX_RING_SLOTS];
1436 uint32_t frames_to_send, retry_count;
1437 struct qbman_eq_desc eqdesc;
1438 struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
1439 struct qbman_swp *swp;
1440 uint16_t num_tx = 0;
1441 uint32_t flags[MAX_TX_RING_SLOTS] = {0};
1442 /*todo - need to support multiple buffer pools */
1444 struct rte_mempool *mb_pool;
1446 if (unlikely(nb_ops == 0))
1449 if (ops[0]->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
1450 DPAA2_SEC_ERR("sessionless crypto op not supported");
1453 /*Prepare enqueue descriptor*/
1454 qbman_eq_desc_clear(&eqdesc);
1455 qbman_eq_desc_set_no_orp(&eqdesc, DPAA2_EQ_RESP_ERR_FQ);
1456 qbman_eq_desc_set_response(&eqdesc, 0, 0);
1457 qbman_eq_desc_set_fq(&eqdesc, dpaa2_qp->tx_vq.fqid);
1459 if (!DPAA2_PER_LCORE_DPIO) {
1460 ret = dpaa2_affine_qbman_swp();
1463 "Failed to allocate IO portal, tid: %d\n",
1468 swp = DPAA2_PER_LCORE_PORTAL;
1471 frames_to_send = (nb_ops > dpaa2_eqcr_size) ?
1472 dpaa2_eqcr_size : nb_ops;
1474 for (loop = 0; loop < frames_to_send; loop++) {
1475 if (*dpaa2_seqn((*ops)->sym->m_src)) {
1476 uint8_t dqrr_index =
1477 *dpaa2_seqn((*ops)->sym->m_src) - 1;
1479 flags[loop] = QBMAN_ENQUEUE_FLAG_DCA | dqrr_index;
1480 DPAA2_PER_LCORE_DQRR_SIZE--;
1481 DPAA2_PER_LCORE_DQRR_HELD &= ~(1 << dqrr_index);
1482 *dpaa2_seqn((*ops)->sym->m_src) =
1483 DPAA2_INVALID_MBUF_SEQN;
1486 /*Clear the unused FD fields before sending*/
1487 memset(&fd_arr[loop], 0, sizeof(struct qbman_fd));
1488 mb_pool = (*ops)->sym->m_src->pool;
1489 bpid = mempool_to_bpid(mb_pool);
1490 ret = build_sec_fd(*ops, &fd_arr[loop], bpid);
1492 DPAA2_SEC_ERR("error: Improper packet contents"
1493 " for crypto operation");
1501 while (loop < frames_to_send) {
1502 ret = qbman_swp_enqueue_multiple(swp, &eqdesc,
1505 frames_to_send - loop);
1506 if (unlikely(ret < 0)) {
1508 if (retry_count > DPAA2_MAX_TX_RETRY_COUNT) {
1523 dpaa2_qp->tx_vq.tx_pkts += num_tx;
1524 dpaa2_qp->tx_vq.err_pkts += nb_ops;
1528 #ifdef RTE_LIB_SECURITY
1529 static inline struct rte_crypto_op *
1530 sec_simple_fd_to_mbuf(const struct qbman_fd *fd)
1532 struct rte_crypto_op *op;
1533 uint16_t len = DPAA2_GET_FD_LEN(fd);
1535 dpaa2_sec_session *sess_priv __rte_unused;
1537 struct rte_mbuf *mbuf = DPAA2_INLINE_MBUF_FROM_BUF(
1538 DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd)),
1539 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size);
1541 diff = len - mbuf->pkt_len;
1542 mbuf->pkt_len += diff;
1543 mbuf->data_len += diff;
1544 op = (struct rte_crypto_op *)(size_t)mbuf->buf_iova;
1545 mbuf->buf_iova = op->sym->aead.digest.phys_addr;
1546 op->sym->aead.digest.phys_addr = 0L;
1548 sess_priv = (dpaa2_sec_session *)get_sec_session_private_data(
1549 op->sym->sec_session);
1550 if (sess_priv->dir == DIR_ENC)
1551 mbuf->data_off += SEC_FLC_DHR_OUTBOUND;
1553 mbuf->data_off += SEC_FLC_DHR_INBOUND;
1559 static inline struct rte_crypto_op *
1560 sec_fd_to_mbuf(const struct qbman_fd *fd)
1562 struct qbman_fle *fle;
1563 struct rte_crypto_op *op;
1564 struct ctxt_priv *priv;
1565 struct rte_mbuf *dst, *src;
1567 #ifdef RTE_LIB_SECURITY
1568 if (DPAA2_FD_GET_FORMAT(fd) == qbman_fd_single)
1569 return sec_simple_fd_to_mbuf(fd);
1571 fle = (struct qbman_fle *)DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd));
1573 DPAA2_SEC_DP_DEBUG("FLE addr = %x - %x, offset = %x\n",
1574 fle->addr_hi, fle->addr_lo, fle->fin_bpid_offset);
1576 /* we are using the first FLE entry to store Mbuf.
1577 * Currently we donot know which FLE has the mbuf stored.
1578 * So while retreiving we can go back 1 FLE from the FD -ADDR
1579 * to get the MBUF Addr from the previous FLE.
1580 * We can have a better approach to use the inline Mbuf
1583 if (unlikely(DPAA2_GET_FD_IVP(fd))) {
1584 /* TODO complete it. */
1585 DPAA2_SEC_ERR("error: non inline buffer");
1588 op = (struct rte_crypto_op *)DPAA2_GET_FLE_ADDR((fle - 1));
1591 src = op->sym->m_src;
1594 if (op->sym->m_dst) {
1595 dst = op->sym->m_dst;
1600 #ifdef RTE_LIB_SECURITY
1601 if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
1602 uint16_t len = DPAA2_GET_FD_LEN(fd);
1604 while (dst->next != NULL) {
1605 len -= dst->data_len;
1608 dst->data_len = len;
1611 DPAA2_SEC_DP_DEBUG("mbuf %p BMAN buf addr %p,"
1612 " fdaddr =%" PRIx64 " bpid =%d meta =%d off =%d, len =%d\n",
1615 DPAA2_GET_FD_ADDR(fd),
1616 DPAA2_GET_FD_BPID(fd),
1617 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size,
1618 DPAA2_GET_FD_OFFSET(fd),
1619 DPAA2_GET_FD_LEN(fd));
1621 /* free the fle memory */
1622 if (likely(rte_pktmbuf_is_contiguous(src))) {
1623 priv = (struct ctxt_priv *)(size_t)DPAA2_GET_FLE_CTXT(fle - 1);
1624 rte_mempool_put(priv->fle_pool, (void *)(fle-1));
1626 rte_free((void *)(fle-1));
1632 dpaa2_sec_dequeue_burst(void *qp, struct rte_crypto_op **ops,
1635 /* Function is responsible to receive frames for a given device and VQ*/
1636 struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
1637 struct qbman_result *dq_storage;
1638 uint32_t fqid = dpaa2_qp->rx_vq.fqid;
1639 int ret, num_rx = 0;
1640 uint8_t is_last = 0, status;
1641 struct qbman_swp *swp;
1642 const struct qbman_fd *fd;
1643 struct qbman_pull_desc pulldesc;
1645 if (!DPAA2_PER_LCORE_DPIO) {
1646 ret = dpaa2_affine_qbman_swp();
1649 "Failed to allocate IO portal, tid: %d\n",
1654 swp = DPAA2_PER_LCORE_PORTAL;
1655 dq_storage = dpaa2_qp->rx_vq.q_storage->dq_storage[0];
1657 qbman_pull_desc_clear(&pulldesc);
1658 qbman_pull_desc_set_numframes(&pulldesc,
1659 (nb_ops > dpaa2_dqrr_size) ?
1660 dpaa2_dqrr_size : nb_ops);
1661 qbman_pull_desc_set_fq(&pulldesc, fqid);
1662 qbman_pull_desc_set_storage(&pulldesc, dq_storage,
1663 (dma_addr_t)DPAA2_VADDR_TO_IOVA(dq_storage),
1666 /*Issue a volatile dequeue command. */
1668 if (qbman_swp_pull(swp, &pulldesc)) {
1670 "SEC VDQ command is not issued : QBMAN busy");
1671 /* Portal was busy, try again */
1677 /* Receive the packets till Last Dequeue entry is found with
1678 * respect to the above issues PULL command.
1681 /* Check if the previous issued command is completed.
1682 * Also seems like the SWP is shared between the Ethernet Driver
1683 * and the SEC driver.
1685 while (!qbman_check_command_complete(dq_storage))
1688 /* Loop until the dq_storage is updated with
1689 * new token by QBMAN
1691 while (!qbman_check_new_result(dq_storage))
1693 /* Check whether Last Pull command is Expired and
1694 * setting Condition for Loop termination
1696 if (qbman_result_DQ_is_pull_complete(dq_storage)) {
1698 /* Check for valid frame. */
1699 status = (uint8_t)qbman_result_DQ_flags(dq_storage);
1701 (status & QBMAN_DQ_STAT_VALIDFRAME) == 0)) {
1702 DPAA2_SEC_DP_DEBUG("No frame is delivered\n");
1707 fd = qbman_result_DQ_fd(dq_storage);
1708 ops[num_rx] = sec_fd_to_mbuf(fd);
1710 if (unlikely(fd->simple.frc)) {
1711 /* TODO Parse SEC errors */
1712 DPAA2_SEC_ERR("SEC returned Error - %x",
1714 ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_ERROR;
1716 ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
1721 } /* End of Packet Rx loop */
1723 dpaa2_qp->rx_vq.rx_pkts += num_rx;
1725 DPAA2_SEC_DP_DEBUG("SEC Received %d Packets\n", num_rx);
1726 /*Return the total number of packets received to DPAA2 app*/
1730 /** Release queue pair */
1732 dpaa2_sec_queue_pair_release(struct rte_cryptodev *dev, uint16_t queue_pair_id)
1734 struct dpaa2_sec_qp *qp =
1735 (struct dpaa2_sec_qp *)dev->data->queue_pairs[queue_pair_id];
1737 PMD_INIT_FUNC_TRACE();
1739 if (qp->rx_vq.q_storage) {
1740 dpaa2_free_dq_storage(qp->rx_vq.q_storage);
1741 rte_free(qp->rx_vq.q_storage);
1745 dev->data->queue_pairs[queue_pair_id] = NULL;
1750 /** Setup a queue pair */
1752 dpaa2_sec_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
1753 __rte_unused const struct rte_cryptodev_qp_conf *qp_conf,
1754 __rte_unused int socket_id)
1756 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
1757 struct dpaa2_sec_qp *qp;
1758 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
1759 struct dpseci_rx_queue_cfg cfg;
1762 PMD_INIT_FUNC_TRACE();
1764 /* If qp is already in use free ring memory and qp metadata. */
1765 if (dev->data->queue_pairs[qp_id] != NULL) {
1766 DPAA2_SEC_INFO("QP already setup");
1770 DPAA2_SEC_DEBUG("dev =%p, queue =%d, conf =%p",
1771 dev, qp_id, qp_conf);
1773 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
1775 qp = rte_malloc(NULL, sizeof(struct dpaa2_sec_qp),
1776 RTE_CACHE_LINE_SIZE);
1778 DPAA2_SEC_ERR("malloc failed for rx/tx queues");
1782 qp->rx_vq.crypto_data = dev->data;
1783 qp->tx_vq.crypto_data = dev->data;
1784 qp->rx_vq.q_storage = rte_malloc("sec dq storage",
1785 sizeof(struct queue_storage_info_t),
1786 RTE_CACHE_LINE_SIZE);
1787 if (!qp->rx_vq.q_storage) {
1788 DPAA2_SEC_ERR("malloc failed for q_storage");
1791 memset(qp->rx_vq.q_storage, 0, sizeof(struct queue_storage_info_t));
1793 if (dpaa2_alloc_dq_storage(qp->rx_vq.q_storage)) {
1794 DPAA2_SEC_ERR("Unable to allocate dequeue storage");
1798 dev->data->queue_pairs[qp_id] = qp;
1800 cfg.options = cfg.options | DPSECI_QUEUE_OPT_USER_CTX;
1801 cfg.user_ctx = (size_t)(&qp->rx_vq);
1802 retcode = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
1807 /** Returns the size of the aesni gcm session structure */
1809 dpaa2_sec_sym_session_get_size(struct rte_cryptodev *dev __rte_unused)
1811 PMD_INIT_FUNC_TRACE();
1813 return sizeof(dpaa2_sec_session);
1817 dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
1818 struct rte_crypto_sym_xform *xform,
1819 dpaa2_sec_session *session)
1821 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
1822 struct alginfo cipherdata;
1823 int bufsize, ret = 0;
1824 struct ctxt_priv *priv;
1825 struct sec_flow_context *flc;
1827 PMD_INIT_FUNC_TRACE();
1829 /* For SEC CIPHER only one descriptor is required. */
1830 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
1831 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
1832 RTE_CACHE_LINE_SIZE);
1834 DPAA2_SEC_ERR("No Memory for priv CTXT");
1838 priv->fle_pool = dev_priv->fle_pool;
1840 flc = &priv->flc_desc[0].flc;
1842 session->ctxt_type = DPAA2_SEC_CIPHER;
1843 session->cipher_key.data = rte_zmalloc(NULL, xform->cipher.key.length,
1844 RTE_CACHE_LINE_SIZE);
1845 if (session->cipher_key.data == NULL) {
1846 DPAA2_SEC_ERR("No Memory for cipher key");
1850 session->cipher_key.length = xform->cipher.key.length;
1852 memcpy(session->cipher_key.data, xform->cipher.key.data,
1853 xform->cipher.key.length);
1854 cipherdata.key = (size_t)session->cipher_key.data;
1855 cipherdata.keylen = session->cipher_key.length;
1856 cipherdata.key_enc_flags = 0;
1857 cipherdata.key_type = RTA_DATA_IMM;
1859 /* Set IV parameters */
1860 session->iv.offset = xform->cipher.iv.offset;
1861 session->iv.length = xform->cipher.iv.length;
1862 session->dir = (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
1865 switch (xform->cipher.algo) {
1866 case RTE_CRYPTO_CIPHER_AES_CBC:
1867 cipherdata.algtype = OP_ALG_ALGSEL_AES;
1868 cipherdata.algmode = OP_ALG_AAI_CBC;
1869 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
1870 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
1871 SHR_NEVER, &cipherdata,
1875 case RTE_CRYPTO_CIPHER_3DES_CBC:
1876 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
1877 cipherdata.algmode = OP_ALG_AAI_CBC;
1878 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
1879 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
1880 SHR_NEVER, &cipherdata,
1884 case RTE_CRYPTO_CIPHER_DES_CBC:
1885 cipherdata.algtype = OP_ALG_ALGSEL_DES;
1886 cipherdata.algmode = OP_ALG_AAI_CBC;
1887 session->cipher_alg = RTE_CRYPTO_CIPHER_DES_CBC;
1888 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
1889 SHR_NEVER, &cipherdata,
1893 case RTE_CRYPTO_CIPHER_AES_CTR:
1894 cipherdata.algtype = OP_ALG_ALGSEL_AES;
1895 cipherdata.algmode = OP_ALG_AAI_CTR;
1896 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
1897 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
1898 SHR_NEVER, &cipherdata,
1902 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
1903 cipherdata.algtype = OP_ALG_ALGSEL_SNOW_F8;
1904 session->cipher_alg = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1905 bufsize = cnstr_shdsc_snow_f8(priv->flc_desc[0].desc, 1, 0,
1909 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
1910 cipherdata.algtype = OP_ALG_ALGSEL_ZUCE;
1911 session->cipher_alg = RTE_CRYPTO_CIPHER_ZUC_EEA3;
1912 bufsize = cnstr_shdsc_zuce(priv->flc_desc[0].desc, 1, 0,
1916 case RTE_CRYPTO_CIPHER_KASUMI_F8:
1917 case RTE_CRYPTO_CIPHER_AES_F8:
1918 case RTE_CRYPTO_CIPHER_AES_ECB:
1919 case RTE_CRYPTO_CIPHER_3DES_ECB:
1920 case RTE_CRYPTO_CIPHER_3DES_CTR:
1921 case RTE_CRYPTO_CIPHER_AES_XTS:
1922 case RTE_CRYPTO_CIPHER_ARC4:
1923 case RTE_CRYPTO_CIPHER_NULL:
1924 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
1925 xform->cipher.algo);
1929 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
1930 xform->cipher.algo);
1936 DPAA2_SEC_ERR("Crypto: Descriptor build failed");
1941 flc->word1_sdl = (uint8_t)bufsize;
1942 session->ctxt = priv;
1944 #ifdef CAAM_DESC_DEBUG
1946 for (i = 0; i < bufsize; i++)
1947 DPAA2_SEC_DEBUG("DESC[%d]:0x%x", i, priv->flc_desc[0].desc[i]);
1952 rte_free(session->cipher_key.data);
1958 dpaa2_sec_auth_init(struct rte_cryptodev *dev,
1959 struct rte_crypto_sym_xform *xform,
1960 dpaa2_sec_session *session)
1962 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
1963 struct alginfo authdata;
1964 int bufsize, ret = 0;
1965 struct ctxt_priv *priv;
1966 struct sec_flow_context *flc;
1968 PMD_INIT_FUNC_TRACE();
1970 /* For SEC AUTH three descriptors are required for various stages */
1971 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
1972 sizeof(struct ctxt_priv) + 3 *
1973 sizeof(struct sec_flc_desc),
1974 RTE_CACHE_LINE_SIZE);
1976 DPAA2_SEC_ERR("No Memory for priv CTXT");
1980 priv->fle_pool = dev_priv->fle_pool;
1981 flc = &priv->flc_desc[DESC_INITFINAL].flc;
1983 session->ctxt_type = DPAA2_SEC_AUTH;
1984 session->auth_key.length = xform->auth.key.length;
1985 if (xform->auth.key.length) {
1986 session->auth_key.data = rte_zmalloc(NULL,
1987 xform->auth.key.length,
1988 RTE_CACHE_LINE_SIZE);
1989 if (session->auth_key.data == NULL) {
1990 DPAA2_SEC_ERR("Unable to allocate memory for auth key");
1994 memcpy(session->auth_key.data, xform->auth.key.data,
1995 xform->auth.key.length);
1996 authdata.key = (size_t)session->auth_key.data;
1997 authdata.key_enc_flags = 0;
1998 authdata.key_type = RTA_DATA_IMM;
2000 authdata.keylen = session->auth_key.length;
2002 session->digest_length = xform->auth.digest_length;
2003 session->dir = (xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE) ?
2006 switch (xform->auth.algo) {
2007 case RTE_CRYPTO_AUTH_SHA1_HMAC:
2008 authdata.algtype = OP_ALG_ALGSEL_SHA1;
2009 authdata.algmode = OP_ALG_AAI_HMAC;
2010 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
2011 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2012 1, 0, SHR_NEVER, &authdata,
2014 session->digest_length);
2016 case RTE_CRYPTO_AUTH_MD5_HMAC:
2017 authdata.algtype = OP_ALG_ALGSEL_MD5;
2018 authdata.algmode = OP_ALG_AAI_HMAC;
2019 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
2020 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2021 1, 0, SHR_NEVER, &authdata,
2023 session->digest_length);
2025 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2026 authdata.algtype = OP_ALG_ALGSEL_SHA256;
2027 authdata.algmode = OP_ALG_AAI_HMAC;
2028 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
2029 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2030 1, 0, SHR_NEVER, &authdata,
2032 session->digest_length);
2034 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2035 authdata.algtype = OP_ALG_ALGSEL_SHA384;
2036 authdata.algmode = OP_ALG_AAI_HMAC;
2037 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
2038 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2039 1, 0, SHR_NEVER, &authdata,
2041 session->digest_length);
2043 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2044 authdata.algtype = OP_ALG_ALGSEL_SHA512;
2045 authdata.algmode = OP_ALG_AAI_HMAC;
2046 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
2047 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2048 1, 0, SHR_NEVER, &authdata,
2050 session->digest_length);
2052 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2053 authdata.algtype = OP_ALG_ALGSEL_SHA224;
2054 authdata.algmode = OP_ALG_AAI_HMAC;
2055 session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
2056 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2057 1, 0, SHR_NEVER, &authdata,
2059 session->digest_length);
2061 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2062 authdata.algtype = OP_ALG_ALGSEL_SNOW_F9;
2063 authdata.algmode = OP_ALG_AAI_F9;
2064 session->auth_alg = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2065 session->iv.offset = xform->auth.iv.offset;
2066 session->iv.length = xform->auth.iv.length;
2067 bufsize = cnstr_shdsc_snow_f9(priv->flc_desc[DESC_INITFINAL].desc,
2070 session->digest_length);
2072 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2073 authdata.algtype = OP_ALG_ALGSEL_ZUCA;
2074 authdata.algmode = OP_ALG_AAI_F9;
2075 session->auth_alg = RTE_CRYPTO_AUTH_ZUC_EIA3;
2076 session->iv.offset = xform->auth.iv.offset;
2077 session->iv.length = xform->auth.iv.length;
2078 bufsize = cnstr_shdsc_zuca(priv->flc_desc[DESC_INITFINAL].desc,
2081 session->digest_length);
2083 case RTE_CRYPTO_AUTH_SHA1:
2084 authdata.algtype = OP_ALG_ALGSEL_SHA1;
2085 authdata.algmode = OP_ALG_AAI_HASH;
2086 session->auth_alg = RTE_CRYPTO_AUTH_SHA1;
2087 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2088 1, 0, SHR_NEVER, &authdata,
2090 session->digest_length);
2092 case RTE_CRYPTO_AUTH_MD5:
2093 authdata.algtype = OP_ALG_ALGSEL_MD5;
2094 authdata.algmode = OP_ALG_AAI_HASH;
2095 session->auth_alg = RTE_CRYPTO_AUTH_MD5;
2096 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2097 1, 0, SHR_NEVER, &authdata,
2099 session->digest_length);
2101 case RTE_CRYPTO_AUTH_SHA256:
2102 authdata.algtype = OP_ALG_ALGSEL_SHA256;
2103 authdata.algmode = OP_ALG_AAI_HASH;
2104 session->auth_alg = RTE_CRYPTO_AUTH_SHA256;
2105 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2106 1, 0, SHR_NEVER, &authdata,
2108 session->digest_length);
2110 case RTE_CRYPTO_AUTH_SHA384:
2111 authdata.algtype = OP_ALG_ALGSEL_SHA384;
2112 authdata.algmode = OP_ALG_AAI_HASH;
2113 session->auth_alg = RTE_CRYPTO_AUTH_SHA384;
2114 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2115 1, 0, SHR_NEVER, &authdata,
2117 session->digest_length);
2119 case RTE_CRYPTO_AUTH_SHA512:
2120 authdata.algtype = OP_ALG_ALGSEL_SHA512;
2121 authdata.algmode = OP_ALG_AAI_HASH;
2122 session->auth_alg = RTE_CRYPTO_AUTH_SHA512;
2123 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2124 1, 0, SHR_NEVER, &authdata,
2126 session->digest_length);
2128 case RTE_CRYPTO_AUTH_SHA224:
2129 authdata.algtype = OP_ALG_ALGSEL_SHA224;
2130 authdata.algmode = OP_ALG_AAI_HASH;
2131 session->auth_alg = RTE_CRYPTO_AUTH_SHA224;
2132 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2133 1, 0, SHR_NEVER, &authdata,
2135 session->digest_length);
2137 case RTE_CRYPTO_AUTH_AES_GMAC:
2138 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2139 case RTE_CRYPTO_AUTH_AES_CMAC:
2140 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2141 case RTE_CRYPTO_AUTH_KASUMI_F9:
2142 case RTE_CRYPTO_AUTH_NULL:
2143 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %un",
2148 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2155 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2160 flc->word1_sdl = (uint8_t)bufsize;
2161 session->ctxt = priv;
2162 #ifdef CAAM_DESC_DEBUG
2164 for (i = 0; i < bufsize; i++)
2165 DPAA2_SEC_DEBUG("DESC[%d]:0x%x",
2166 i, priv->flc_desc[DESC_INITFINAL].desc[i]);
2172 rte_free(session->auth_key.data);
2178 dpaa2_sec_aead_init(struct rte_cryptodev *dev,
2179 struct rte_crypto_sym_xform *xform,
2180 dpaa2_sec_session *session)
2182 struct dpaa2_sec_aead_ctxt *ctxt = &session->ext_params.aead_ctxt;
2183 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2184 struct alginfo aeaddata;
2186 struct ctxt_priv *priv;
2187 struct sec_flow_context *flc;
2188 struct rte_crypto_aead_xform *aead_xform = &xform->aead;
2191 PMD_INIT_FUNC_TRACE();
2193 /* Set IV parameters */
2194 session->iv.offset = aead_xform->iv.offset;
2195 session->iv.length = aead_xform->iv.length;
2196 session->ctxt_type = DPAA2_SEC_AEAD;
2198 /* For SEC AEAD only one descriptor is required */
2199 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2200 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
2201 RTE_CACHE_LINE_SIZE);
2203 DPAA2_SEC_ERR("No Memory for priv CTXT");
2207 priv->fle_pool = dev_priv->fle_pool;
2208 flc = &priv->flc_desc[0].flc;
2210 session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length,
2211 RTE_CACHE_LINE_SIZE);
2212 if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
2213 DPAA2_SEC_ERR("No Memory for aead key");
2217 memcpy(session->aead_key.data, aead_xform->key.data,
2218 aead_xform->key.length);
2220 session->digest_length = aead_xform->digest_length;
2221 session->aead_key.length = aead_xform->key.length;
2222 ctxt->auth_only_len = aead_xform->aad_length;
2224 aeaddata.key = (size_t)session->aead_key.data;
2225 aeaddata.keylen = session->aead_key.length;
2226 aeaddata.key_enc_flags = 0;
2227 aeaddata.key_type = RTA_DATA_IMM;
2229 switch (aead_xform->algo) {
2230 case RTE_CRYPTO_AEAD_AES_GCM:
2231 aeaddata.algtype = OP_ALG_ALGSEL_AES;
2232 aeaddata.algmode = OP_ALG_AAI_GCM;
2233 session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM;
2235 case RTE_CRYPTO_AEAD_AES_CCM:
2236 DPAA2_SEC_ERR("Crypto: Unsupported AEAD alg %u",
2241 DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
2246 session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
2249 priv->flc_desc[0].desc[0] = aeaddata.keylen;
2250 err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
2252 (unsigned int *)priv->flc_desc[0].desc,
2253 &priv->flc_desc[0].desc[1], 1);
2256 DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
2260 if (priv->flc_desc[0].desc[1] & 1) {
2261 aeaddata.key_type = RTA_DATA_IMM;
2263 aeaddata.key = DPAA2_VADDR_TO_IOVA(aeaddata.key);
2264 aeaddata.key_type = RTA_DATA_PTR;
2266 priv->flc_desc[0].desc[0] = 0;
2267 priv->flc_desc[0].desc[1] = 0;
2269 if (session->dir == DIR_ENC)
2270 bufsize = cnstr_shdsc_gcm_encap(
2271 priv->flc_desc[0].desc, 1, 0, SHR_NEVER,
2272 &aeaddata, session->iv.length,
2273 session->digest_length);
2275 bufsize = cnstr_shdsc_gcm_decap(
2276 priv->flc_desc[0].desc, 1, 0, SHR_NEVER,
2277 &aeaddata, session->iv.length,
2278 session->digest_length);
2280 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2285 flc->word1_sdl = (uint8_t)bufsize;
2286 session->ctxt = priv;
2287 #ifdef CAAM_DESC_DEBUG
2289 for (i = 0; i < bufsize; i++)
2290 DPAA2_SEC_DEBUG("DESC[%d]:0x%x\n",
2291 i, priv->flc_desc[0].desc[i]);
2296 rte_free(session->aead_key.data);
2303 dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
2304 struct rte_crypto_sym_xform *xform,
2305 dpaa2_sec_session *session)
2307 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2308 struct alginfo authdata, cipherdata;
2310 struct ctxt_priv *priv;
2311 struct sec_flow_context *flc;
2312 struct rte_crypto_cipher_xform *cipher_xform;
2313 struct rte_crypto_auth_xform *auth_xform;
2316 PMD_INIT_FUNC_TRACE();
2318 if (session->ext_params.aead_ctxt.auth_cipher_text) {
2319 cipher_xform = &xform->cipher;
2320 auth_xform = &xform->next->auth;
2321 session->ctxt_type =
2322 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2323 DPAA2_SEC_CIPHER_HASH : DPAA2_SEC_HASH_CIPHER;
2325 cipher_xform = &xform->next->cipher;
2326 auth_xform = &xform->auth;
2327 session->ctxt_type =
2328 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2329 DPAA2_SEC_HASH_CIPHER : DPAA2_SEC_CIPHER_HASH;
2332 /* Set IV parameters */
2333 session->iv.offset = cipher_xform->iv.offset;
2334 session->iv.length = cipher_xform->iv.length;
2336 /* For SEC AEAD only one descriptor is required */
2337 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2338 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
2339 RTE_CACHE_LINE_SIZE);
2341 DPAA2_SEC_ERR("No Memory for priv CTXT");
2345 priv->fle_pool = dev_priv->fle_pool;
2346 flc = &priv->flc_desc[0].flc;
2348 session->cipher_key.data = rte_zmalloc(NULL, cipher_xform->key.length,
2349 RTE_CACHE_LINE_SIZE);
2350 if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) {
2351 DPAA2_SEC_ERR("No Memory for cipher key");
2355 session->cipher_key.length = cipher_xform->key.length;
2356 session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length,
2357 RTE_CACHE_LINE_SIZE);
2358 if (session->auth_key.data == NULL && auth_xform->key.length > 0) {
2359 DPAA2_SEC_ERR("No Memory for auth key");
2360 rte_free(session->cipher_key.data);
2364 session->auth_key.length = auth_xform->key.length;
2365 memcpy(session->cipher_key.data, cipher_xform->key.data,
2366 cipher_xform->key.length);
2367 memcpy(session->auth_key.data, auth_xform->key.data,
2368 auth_xform->key.length);
2370 authdata.key = (size_t)session->auth_key.data;
2371 authdata.keylen = session->auth_key.length;
2372 authdata.key_enc_flags = 0;
2373 authdata.key_type = RTA_DATA_IMM;
2375 session->digest_length = auth_xform->digest_length;
2377 switch (auth_xform->algo) {
2378 case RTE_CRYPTO_AUTH_SHA1_HMAC:
2379 authdata.algtype = OP_ALG_ALGSEL_SHA1;
2380 authdata.algmode = OP_ALG_AAI_HMAC;
2381 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
2383 case RTE_CRYPTO_AUTH_MD5_HMAC:
2384 authdata.algtype = OP_ALG_ALGSEL_MD5;
2385 authdata.algmode = OP_ALG_AAI_HMAC;
2386 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
2388 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2389 authdata.algtype = OP_ALG_ALGSEL_SHA224;
2390 authdata.algmode = OP_ALG_AAI_HMAC;
2391 session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
2393 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2394 authdata.algtype = OP_ALG_ALGSEL_SHA256;
2395 authdata.algmode = OP_ALG_AAI_HMAC;
2396 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
2398 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2399 authdata.algtype = OP_ALG_ALGSEL_SHA384;
2400 authdata.algmode = OP_ALG_AAI_HMAC;
2401 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
2403 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2404 authdata.algtype = OP_ALG_ALGSEL_SHA512;
2405 authdata.algmode = OP_ALG_AAI_HMAC;
2406 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
2408 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2409 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2410 case RTE_CRYPTO_AUTH_NULL:
2411 case RTE_CRYPTO_AUTH_SHA1:
2412 case RTE_CRYPTO_AUTH_SHA256:
2413 case RTE_CRYPTO_AUTH_SHA512:
2414 case RTE_CRYPTO_AUTH_SHA224:
2415 case RTE_CRYPTO_AUTH_SHA384:
2416 case RTE_CRYPTO_AUTH_MD5:
2417 case RTE_CRYPTO_AUTH_AES_GMAC:
2418 case RTE_CRYPTO_AUTH_KASUMI_F9:
2419 case RTE_CRYPTO_AUTH_AES_CMAC:
2420 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2421 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2422 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
2427 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2432 cipherdata.key = (size_t)session->cipher_key.data;
2433 cipherdata.keylen = session->cipher_key.length;
2434 cipherdata.key_enc_flags = 0;
2435 cipherdata.key_type = RTA_DATA_IMM;
2437 switch (cipher_xform->algo) {
2438 case RTE_CRYPTO_CIPHER_AES_CBC:
2439 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2440 cipherdata.algmode = OP_ALG_AAI_CBC;
2441 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
2443 case RTE_CRYPTO_CIPHER_3DES_CBC:
2444 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
2445 cipherdata.algmode = OP_ALG_AAI_CBC;
2446 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
2448 case RTE_CRYPTO_CIPHER_DES_CBC:
2449 cipherdata.algtype = OP_ALG_ALGSEL_DES;
2450 cipherdata.algmode = OP_ALG_AAI_CBC;
2451 session->cipher_alg = RTE_CRYPTO_CIPHER_DES_CBC;
2453 case RTE_CRYPTO_CIPHER_AES_CTR:
2454 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2455 cipherdata.algmode = OP_ALG_AAI_CTR;
2456 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
2458 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2459 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
2460 case RTE_CRYPTO_CIPHER_NULL:
2461 case RTE_CRYPTO_CIPHER_3DES_ECB:
2462 case RTE_CRYPTO_CIPHER_3DES_CTR:
2463 case RTE_CRYPTO_CIPHER_AES_ECB:
2464 case RTE_CRYPTO_CIPHER_KASUMI_F8:
2465 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
2466 cipher_xform->algo);
2470 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2471 cipher_xform->algo);
2475 session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2478 priv->flc_desc[0].desc[0] = cipherdata.keylen;
2479 priv->flc_desc[0].desc[1] = authdata.keylen;
2480 err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
2482 (unsigned int *)priv->flc_desc[0].desc,
2483 &priv->flc_desc[0].desc[2], 2);
2486 DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
2490 if (priv->flc_desc[0].desc[2] & 1) {
2491 cipherdata.key_type = RTA_DATA_IMM;
2493 cipherdata.key = DPAA2_VADDR_TO_IOVA(cipherdata.key);
2494 cipherdata.key_type = RTA_DATA_PTR;
2496 if (priv->flc_desc[0].desc[2] & (1 << 1)) {
2497 authdata.key_type = RTA_DATA_IMM;
2499 authdata.key = DPAA2_VADDR_TO_IOVA(authdata.key);
2500 authdata.key_type = RTA_DATA_PTR;
2502 priv->flc_desc[0].desc[0] = 0;
2503 priv->flc_desc[0].desc[1] = 0;
2504 priv->flc_desc[0].desc[2] = 0;
2506 if (session->ctxt_type == DPAA2_SEC_CIPHER_HASH) {
2507 bufsize = cnstr_shdsc_authenc(priv->flc_desc[0].desc, 1,
2509 &cipherdata, &authdata,
2511 session->digest_length,
2514 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2519 DPAA2_SEC_ERR("Hash before cipher not supported");
2524 flc->word1_sdl = (uint8_t)bufsize;
2525 session->ctxt = priv;
2526 #ifdef CAAM_DESC_DEBUG
2528 for (i = 0; i < bufsize; i++)
2529 DPAA2_SEC_DEBUG("DESC[%d]:0x%x",
2530 i, priv->flc_desc[0].desc[i]);
2536 rte_free(session->cipher_key.data);
2537 rte_free(session->auth_key.data);
2543 dpaa2_sec_set_session_parameters(struct rte_cryptodev *dev,
2544 struct rte_crypto_sym_xform *xform, void *sess)
2546 dpaa2_sec_session *session = sess;
2549 PMD_INIT_FUNC_TRACE();
2551 if (unlikely(sess == NULL)) {
2552 DPAA2_SEC_ERR("Invalid session struct");
2556 memset(session, 0, sizeof(dpaa2_sec_session));
2557 /* Default IV length = 0 */
2558 session->iv.length = 0;
2561 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
2562 ret = dpaa2_sec_cipher_init(dev, xform, session);
2564 /* Authentication Only */
2565 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2566 xform->next == NULL) {
2567 ret = dpaa2_sec_auth_init(dev, xform, session);
2569 /* Cipher then Authenticate */
2570 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
2571 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2572 session->ext_params.aead_ctxt.auth_cipher_text = true;
2573 if (xform->cipher.algo == RTE_CRYPTO_CIPHER_NULL)
2574 ret = dpaa2_sec_auth_init(dev, xform, session);
2575 else if (xform->next->auth.algo == RTE_CRYPTO_AUTH_NULL)
2576 ret = dpaa2_sec_cipher_init(dev, xform, session);
2578 ret = dpaa2_sec_aead_chain_init(dev, xform, session);
2579 /* Authenticate then Cipher */
2580 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2581 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2582 session->ext_params.aead_ctxt.auth_cipher_text = false;
2583 if (xform->auth.algo == RTE_CRYPTO_AUTH_NULL)
2584 ret = dpaa2_sec_cipher_init(dev, xform, session);
2585 else if (xform->next->cipher.algo == RTE_CRYPTO_CIPHER_NULL)
2586 ret = dpaa2_sec_auth_init(dev, xform, session);
2588 ret = dpaa2_sec_aead_chain_init(dev, xform, session);
2589 /* AEAD operation for AES-GCM kind of Algorithms */
2590 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD &&
2591 xform->next == NULL) {
2592 ret = dpaa2_sec_aead_init(dev, xform, session);
2595 DPAA2_SEC_ERR("Invalid crypto type");
2602 #ifdef RTE_LIB_SECURITY
2604 dpaa2_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
2605 dpaa2_sec_session *session,
2606 struct alginfo *aeaddata)
2608 PMD_INIT_FUNC_TRACE();
2610 session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length,
2611 RTE_CACHE_LINE_SIZE);
2612 if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
2613 DPAA2_SEC_ERR("No Memory for aead key");
2616 memcpy(session->aead_key.data, aead_xform->key.data,
2617 aead_xform->key.length);
2619 session->digest_length = aead_xform->digest_length;
2620 session->aead_key.length = aead_xform->key.length;
2622 aeaddata->key = (size_t)session->aead_key.data;
2623 aeaddata->keylen = session->aead_key.length;
2624 aeaddata->key_enc_flags = 0;
2625 aeaddata->key_type = RTA_DATA_IMM;
2627 switch (aead_xform->algo) {
2628 case RTE_CRYPTO_AEAD_AES_GCM:
2629 switch (session->digest_length) {
2631 aeaddata->algtype = OP_PCL_IPSEC_AES_GCM8;
2634 aeaddata->algtype = OP_PCL_IPSEC_AES_GCM12;
2637 aeaddata->algtype = OP_PCL_IPSEC_AES_GCM16;
2640 DPAA2_SEC_ERR("Crypto: Undefined GCM digest %d",
2641 session->digest_length);
2644 aeaddata->algmode = OP_ALG_AAI_GCM;
2645 session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM;
2647 case RTE_CRYPTO_AEAD_AES_CCM:
2648 switch (session->digest_length) {
2650 aeaddata->algtype = OP_PCL_IPSEC_AES_CCM8;
2653 aeaddata->algtype = OP_PCL_IPSEC_AES_CCM12;
2656 aeaddata->algtype = OP_PCL_IPSEC_AES_CCM16;
2659 DPAA2_SEC_ERR("Crypto: Undefined CCM digest %d",
2660 session->digest_length);
2663 aeaddata->algmode = OP_ALG_AAI_CCM;
2664 session->aead_alg = RTE_CRYPTO_AEAD_AES_CCM;
2667 DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
2671 session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
2678 dpaa2_sec_ipsec_proto_init(struct rte_crypto_cipher_xform *cipher_xform,
2679 struct rte_crypto_auth_xform *auth_xform,
2680 dpaa2_sec_session *session,
2681 struct alginfo *cipherdata,
2682 struct alginfo *authdata)
2685 session->cipher_key.data = rte_zmalloc(NULL,
2686 cipher_xform->key.length,
2687 RTE_CACHE_LINE_SIZE);
2688 if (session->cipher_key.data == NULL &&
2689 cipher_xform->key.length > 0) {
2690 DPAA2_SEC_ERR("No Memory for cipher key");
2694 session->cipher_key.length = cipher_xform->key.length;
2695 memcpy(session->cipher_key.data, cipher_xform->key.data,
2696 cipher_xform->key.length);
2697 session->cipher_alg = cipher_xform->algo;
2699 session->cipher_key.data = NULL;
2700 session->cipher_key.length = 0;
2701 session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
2705 session->auth_key.data = rte_zmalloc(NULL,
2706 auth_xform->key.length,
2707 RTE_CACHE_LINE_SIZE);
2708 if (session->auth_key.data == NULL &&
2709 auth_xform->key.length > 0) {
2710 DPAA2_SEC_ERR("No Memory for auth key");
2713 session->auth_key.length = auth_xform->key.length;
2714 memcpy(session->auth_key.data, auth_xform->key.data,
2715 auth_xform->key.length);
2716 session->auth_alg = auth_xform->algo;
2717 session->digest_length = auth_xform->digest_length;
2719 session->auth_key.data = NULL;
2720 session->auth_key.length = 0;
2721 session->auth_alg = RTE_CRYPTO_AUTH_NULL;
2724 authdata->key = (size_t)session->auth_key.data;
2725 authdata->keylen = session->auth_key.length;
2726 authdata->key_enc_flags = 0;
2727 authdata->key_type = RTA_DATA_IMM;
2728 switch (session->auth_alg) {
2729 case RTE_CRYPTO_AUTH_SHA1_HMAC:
2730 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA1_96;
2731 authdata->algmode = OP_ALG_AAI_HMAC;
2733 case RTE_CRYPTO_AUTH_MD5_HMAC:
2734 authdata->algtype = OP_PCL_IPSEC_HMAC_MD5_96;
2735 authdata->algmode = OP_ALG_AAI_HMAC;
2737 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2738 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_256_128;
2739 authdata->algmode = OP_ALG_AAI_HMAC;
2740 if (session->digest_length != 16)
2742 "+++Using sha256-hmac truncated len is non-standard,"
2743 "it will not work with lookaside proto");
2745 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2746 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_384_192;
2747 authdata->algmode = OP_ALG_AAI_HMAC;
2749 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2750 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_512_256;
2751 authdata->algmode = OP_ALG_AAI_HMAC;
2753 case RTE_CRYPTO_AUTH_AES_CMAC:
2754 authdata->algtype = OP_PCL_IPSEC_AES_CMAC_96;
2756 case RTE_CRYPTO_AUTH_NULL:
2757 authdata->algtype = OP_PCL_IPSEC_HMAC_NULL;
2759 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2760 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2761 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2762 case RTE_CRYPTO_AUTH_SHA1:
2763 case RTE_CRYPTO_AUTH_SHA256:
2764 case RTE_CRYPTO_AUTH_SHA512:
2765 case RTE_CRYPTO_AUTH_SHA224:
2766 case RTE_CRYPTO_AUTH_SHA384:
2767 case RTE_CRYPTO_AUTH_MD5:
2768 case RTE_CRYPTO_AUTH_AES_GMAC:
2769 case RTE_CRYPTO_AUTH_KASUMI_F9:
2770 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2771 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2772 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
2776 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2780 cipherdata->key = (size_t)session->cipher_key.data;
2781 cipherdata->keylen = session->cipher_key.length;
2782 cipherdata->key_enc_flags = 0;
2783 cipherdata->key_type = RTA_DATA_IMM;
2785 switch (session->cipher_alg) {
2786 case RTE_CRYPTO_CIPHER_AES_CBC:
2787 cipherdata->algtype = OP_PCL_IPSEC_AES_CBC;
2788 cipherdata->algmode = OP_ALG_AAI_CBC;
2790 case RTE_CRYPTO_CIPHER_3DES_CBC:
2791 cipherdata->algtype = OP_PCL_IPSEC_3DES;
2792 cipherdata->algmode = OP_ALG_AAI_CBC;
2794 case RTE_CRYPTO_CIPHER_DES_CBC:
2795 cipherdata->algtype = OP_PCL_IPSEC_DES;
2796 cipherdata->algmode = OP_ALG_AAI_CBC;
2798 case RTE_CRYPTO_CIPHER_AES_CTR:
2799 cipherdata->algtype = OP_PCL_IPSEC_AES_CTR;
2800 cipherdata->algmode = OP_ALG_AAI_CTR;
2802 case RTE_CRYPTO_CIPHER_NULL:
2803 cipherdata->algtype = OP_PCL_IPSEC_NULL;
2805 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2806 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
2807 case RTE_CRYPTO_CIPHER_3DES_ECB:
2808 case RTE_CRYPTO_CIPHER_3DES_CTR:
2809 case RTE_CRYPTO_CIPHER_AES_ECB:
2810 case RTE_CRYPTO_CIPHER_KASUMI_F8:
2811 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
2812 session->cipher_alg);
2815 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2816 session->cipher_alg);
2823 #ifdef RTE_LIBRTE_SECURITY_TEST
2824 static uint8_t aes_cbc_iv[] = {
2825 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2826 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
2830 dpaa2_sec_set_ipsec_session(struct rte_cryptodev *dev,
2831 struct rte_security_session_conf *conf,
2834 struct rte_security_ipsec_xform *ipsec_xform = &conf->ipsec;
2835 struct rte_crypto_cipher_xform *cipher_xform = NULL;
2836 struct rte_crypto_auth_xform *auth_xform = NULL;
2837 struct rte_crypto_aead_xform *aead_xform = NULL;
2838 dpaa2_sec_session *session = (dpaa2_sec_session *)sess;
2839 struct ctxt_priv *priv;
2840 struct alginfo authdata, cipherdata;
2842 struct sec_flow_context *flc;
2843 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2846 PMD_INIT_FUNC_TRACE();
2848 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2849 sizeof(struct ctxt_priv) +
2850 sizeof(struct sec_flc_desc),
2851 RTE_CACHE_LINE_SIZE);
2854 DPAA2_SEC_ERR("No memory for priv CTXT");
2858 priv->fle_pool = dev_priv->fle_pool;
2859 flc = &priv->flc_desc[0].flc;
2861 memset(session, 0, sizeof(dpaa2_sec_session));
2863 if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2864 cipher_xform = &conf->crypto_xform->cipher;
2865 if (conf->crypto_xform->next)
2866 auth_xform = &conf->crypto_xform->next->auth;
2867 ret = dpaa2_sec_ipsec_proto_init(cipher_xform, auth_xform,
2868 session, &cipherdata, &authdata);
2869 } else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2870 auth_xform = &conf->crypto_xform->auth;
2871 if (conf->crypto_xform->next)
2872 cipher_xform = &conf->crypto_xform->next->cipher;
2873 ret = dpaa2_sec_ipsec_proto_init(cipher_xform, auth_xform,
2874 session, &cipherdata, &authdata);
2875 } else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
2876 aead_xform = &conf->crypto_xform->aead;
2877 ret = dpaa2_sec_ipsec_aead_init(aead_xform,
2878 session, &cipherdata);
2879 authdata.keylen = 0;
2880 authdata.algtype = 0;
2882 DPAA2_SEC_ERR("XFORM not specified");
2887 DPAA2_SEC_ERR("Failed to process xform");
2891 session->ctxt_type = DPAA2_SEC_IPSEC;
2892 if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
2893 uint8_t *hdr = NULL;
2895 struct rte_ipv6_hdr ip6_hdr;
2896 struct ipsec_encap_pdb encap_pdb;
2898 flc->dhr = SEC_FLC_DHR_OUTBOUND;
2899 /* For Sec Proto only one descriptor is required. */
2900 memset(&encap_pdb, 0, sizeof(struct ipsec_encap_pdb));
2902 /* copy algo specific data to PDB */
2903 switch (cipherdata.algtype) {
2904 case OP_PCL_IPSEC_AES_CTR:
2905 encap_pdb.ctr.ctr_initial = 0x00000001;
2906 encap_pdb.ctr.ctr_nonce = ipsec_xform->salt;
2908 case OP_PCL_IPSEC_AES_GCM8:
2909 case OP_PCL_IPSEC_AES_GCM12:
2910 case OP_PCL_IPSEC_AES_GCM16:
2911 memcpy(encap_pdb.gcm.salt,
2912 (uint8_t *)&(ipsec_xform->salt), 4);
2916 encap_pdb.options = (IPVERSION << PDBNH_ESP_ENCAP_SHIFT) |
2917 PDBOPTS_ESP_OIHI_PDB_INL |
2919 PDBHMO_ESP_ENCAP_DTTL |
2921 if (ipsec_xform->options.esn)
2922 encap_pdb.options |= PDBOPTS_ESP_ESN;
2923 encap_pdb.spi = ipsec_xform->spi;
2924 session->dir = DIR_ENC;
2925 if (ipsec_xform->tunnel.type ==
2926 RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
2927 encap_pdb.ip_hdr_len = sizeof(struct ip);
2928 ip4_hdr.ip_v = IPVERSION;
2930 ip4_hdr.ip_len = rte_cpu_to_be_16(sizeof(ip4_hdr));
2931 ip4_hdr.ip_tos = ipsec_xform->tunnel.ipv4.dscp;
2934 ip4_hdr.ip_ttl = ipsec_xform->tunnel.ipv4.ttl;
2935 ip4_hdr.ip_p = IPPROTO_ESP;
2937 ip4_hdr.ip_src = ipsec_xform->tunnel.ipv4.src_ip;
2938 ip4_hdr.ip_dst = ipsec_xform->tunnel.ipv4.dst_ip;
2939 ip4_hdr.ip_sum = calc_chksum((uint16_t *)(void *)
2940 &ip4_hdr, sizeof(struct ip));
2941 hdr = (uint8_t *)&ip4_hdr;
2942 } else if (ipsec_xform->tunnel.type ==
2943 RTE_SECURITY_IPSEC_TUNNEL_IPV6) {
2944 ip6_hdr.vtc_flow = rte_cpu_to_be_32(
2945 DPAA2_IPv6_DEFAULT_VTC_FLOW |
2946 ((ipsec_xform->tunnel.ipv6.dscp <<
2947 RTE_IPV6_HDR_TC_SHIFT) &
2948 RTE_IPV6_HDR_TC_MASK) |
2949 ((ipsec_xform->tunnel.ipv6.flabel <<
2950 RTE_IPV6_HDR_FL_SHIFT) &
2951 RTE_IPV6_HDR_FL_MASK));
2952 /* Payload length will be updated by HW */
2953 ip6_hdr.payload_len = 0;
2954 ip6_hdr.hop_limits =
2955 ipsec_xform->tunnel.ipv6.hlimit;
2956 ip6_hdr.proto = (ipsec_xform->proto ==
2957 RTE_SECURITY_IPSEC_SA_PROTO_ESP) ?
2958 IPPROTO_ESP : IPPROTO_AH;
2959 memcpy(&ip6_hdr.src_addr,
2960 &ipsec_xform->tunnel.ipv6.src_addr, 16);
2961 memcpy(&ip6_hdr.dst_addr,
2962 &ipsec_xform->tunnel.ipv6.dst_addr, 16);
2963 encap_pdb.ip_hdr_len = sizeof(struct rte_ipv6_hdr);
2964 hdr = (uint8_t *)&ip6_hdr;
2967 bufsize = cnstr_shdsc_ipsec_new_encap(priv->flc_desc[0].desc,
2968 1, 0, (rta_sec_era >= RTA_SEC_ERA_10) ?
2969 SHR_WAIT : SHR_SERIAL, &encap_pdb,
2970 hdr, &cipherdata, &authdata);
2971 } else if (ipsec_xform->direction ==
2972 RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
2973 struct ipsec_decap_pdb decap_pdb;
2975 flc->dhr = SEC_FLC_DHR_INBOUND;
2976 memset(&decap_pdb, 0, sizeof(struct ipsec_decap_pdb));
2977 /* copy algo specific data to PDB */
2978 switch (cipherdata.algtype) {
2979 case OP_PCL_IPSEC_AES_CTR:
2980 decap_pdb.ctr.ctr_initial = 0x00000001;
2981 decap_pdb.ctr.ctr_nonce = ipsec_xform->salt;
2983 case OP_PCL_IPSEC_AES_GCM8:
2984 case OP_PCL_IPSEC_AES_GCM12:
2985 case OP_PCL_IPSEC_AES_GCM16:
2986 memcpy(decap_pdb.gcm.salt,
2987 (uint8_t *)&(ipsec_xform->salt), 4);
2991 decap_pdb.options = (ipsec_xform->tunnel.type ==
2992 RTE_SECURITY_IPSEC_TUNNEL_IPV4) ?
2993 sizeof(struct ip) << 16 :
2994 sizeof(struct rte_ipv6_hdr) << 16;
2995 if (ipsec_xform->options.esn)
2996 decap_pdb.options |= PDBOPTS_ESP_ESN;
2998 if (ipsec_xform->replay_win_sz) {
3000 win_sz = rte_align32pow2(ipsec_xform->replay_win_sz);
3002 if (rta_sec_era < RTA_SEC_ERA_10 && win_sz > 128) {
3003 DPAA2_SEC_INFO("Max Anti replay Win sz = 128");
3013 decap_pdb.options |= PDBOPTS_ESP_ARS32;
3016 decap_pdb.options |= PDBOPTS_ESP_ARS64;
3019 decap_pdb.options |= PDBOPTS_ESP_ARS256;
3022 decap_pdb.options |= PDBOPTS_ESP_ARS512;
3025 decap_pdb.options |= PDBOPTS_ESP_ARS1024;
3029 decap_pdb.options |= PDBOPTS_ESP_ARS128;
3032 session->dir = DIR_DEC;
3033 bufsize = cnstr_shdsc_ipsec_new_decap(priv->flc_desc[0].desc,
3034 1, 0, (rta_sec_era >= RTA_SEC_ERA_10) ?
3035 SHR_WAIT : SHR_SERIAL,
3036 &decap_pdb, &cipherdata, &authdata);
3041 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
3045 flc->word1_sdl = (uint8_t)bufsize;
3047 /* Enable the stashing control bit */
3048 DPAA2_SET_FLC_RSC(flc);
3049 flc->word2_rflc_31_0 = lower_32_bits(
3050 (size_t)&(((struct dpaa2_sec_qp *)
3051 dev->data->queue_pairs[0])->rx_vq) | 0x14);
3052 flc->word3_rflc_63_32 = upper_32_bits(
3053 (size_t)&(((struct dpaa2_sec_qp *)
3054 dev->data->queue_pairs[0])->rx_vq));
3056 /* Set EWS bit i.e. enable write-safe */
3057 DPAA2_SET_FLC_EWS(flc);
3058 /* Set BS = 1 i.e reuse input buffers as output buffers */
3059 DPAA2_SET_FLC_REUSE_BS(flc);
3060 /* Set FF = 10; reuse input buffers if they provide sufficient space */
3061 DPAA2_SET_FLC_REUSE_FF(flc);
3063 session->ctxt = priv;
3067 rte_free(session->auth_key.data);
3068 rte_free(session->cipher_key.data);
3074 dpaa2_sec_set_pdcp_session(struct rte_cryptodev *dev,
3075 struct rte_security_session_conf *conf,
3078 struct rte_security_pdcp_xform *pdcp_xform = &conf->pdcp;
3079 struct rte_crypto_sym_xform *xform = conf->crypto_xform;
3080 struct rte_crypto_auth_xform *auth_xform = NULL;
3081 struct rte_crypto_cipher_xform *cipher_xform;
3082 dpaa2_sec_session *session = (dpaa2_sec_session *)sess;
3083 struct ctxt_priv *priv;
3084 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
3085 struct alginfo authdata, cipherdata;
3086 struct alginfo *p_authdata = NULL;
3088 struct sec_flow_context *flc;
3089 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
3095 PMD_INIT_FUNC_TRACE();
3097 memset(session, 0, sizeof(dpaa2_sec_session));
3099 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
3100 sizeof(struct ctxt_priv) +
3101 sizeof(struct sec_flc_desc),
3102 RTE_CACHE_LINE_SIZE);
3105 DPAA2_SEC_ERR("No memory for priv CTXT");
3109 priv->fle_pool = dev_priv->fle_pool;
3110 flc = &priv->flc_desc[0].flc;
3112 /* find xfrm types */
3113 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
3114 cipher_xform = &xform->cipher;
3115 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
3116 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
3117 session->ext_params.aead_ctxt.auth_cipher_text = true;
3118 cipher_xform = &xform->cipher;
3119 auth_xform = &xform->next->auth;
3120 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
3121 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
3122 session->ext_params.aead_ctxt.auth_cipher_text = false;
3123 cipher_xform = &xform->next->cipher;
3124 auth_xform = &xform->auth;
3126 DPAA2_SEC_ERR("Invalid crypto type");
3130 session->ctxt_type = DPAA2_SEC_PDCP;
3132 session->cipher_key.data = rte_zmalloc(NULL,
3133 cipher_xform->key.length,
3134 RTE_CACHE_LINE_SIZE);
3135 if (session->cipher_key.data == NULL &&
3136 cipher_xform->key.length > 0) {
3137 DPAA2_SEC_ERR("No Memory for cipher key");
3141 session->cipher_key.length = cipher_xform->key.length;
3142 memcpy(session->cipher_key.data, cipher_xform->key.data,
3143 cipher_xform->key.length);
3145 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
3147 session->cipher_alg = cipher_xform->algo;
3149 session->cipher_key.data = NULL;
3150 session->cipher_key.length = 0;
3151 session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
3152 session->dir = DIR_ENC;
3155 session->pdcp.domain = pdcp_xform->domain;
3156 session->pdcp.bearer = pdcp_xform->bearer;
3157 session->pdcp.pkt_dir = pdcp_xform->pkt_dir;
3158 session->pdcp.sn_size = pdcp_xform->sn_size;
3159 session->pdcp.hfn = pdcp_xform->hfn;
3160 session->pdcp.hfn_threshold = pdcp_xform->hfn_threshold;
3161 session->pdcp.hfn_ovd = pdcp_xform->hfn_ovrd;
3162 /* hfv ovd offset location is stored in iv.offset value*/
3163 session->pdcp.hfn_ovd_offset = cipher_xform->iv.offset;
3165 cipherdata.key = (size_t)session->cipher_key.data;
3166 cipherdata.keylen = session->cipher_key.length;
3167 cipherdata.key_enc_flags = 0;
3168 cipherdata.key_type = RTA_DATA_IMM;
3170 switch (session->cipher_alg) {
3171 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
3172 cipherdata.algtype = PDCP_CIPHER_TYPE_SNOW;
3174 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
3175 cipherdata.algtype = PDCP_CIPHER_TYPE_ZUC;
3177 case RTE_CRYPTO_CIPHER_AES_CTR:
3178 cipherdata.algtype = PDCP_CIPHER_TYPE_AES;
3180 case RTE_CRYPTO_CIPHER_NULL:
3181 cipherdata.algtype = PDCP_CIPHER_TYPE_NULL;
3184 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
3185 session->cipher_alg);
3190 session->auth_key.data = rte_zmalloc(NULL,
3191 auth_xform->key.length,
3192 RTE_CACHE_LINE_SIZE);
3193 if (!session->auth_key.data &&
3194 auth_xform->key.length > 0) {
3195 DPAA2_SEC_ERR("No Memory for auth key");
3196 rte_free(session->cipher_key.data);
3200 session->auth_key.length = auth_xform->key.length;
3201 memcpy(session->auth_key.data, auth_xform->key.data,
3202 auth_xform->key.length);
3203 session->auth_alg = auth_xform->algo;
3205 session->auth_key.data = NULL;
3206 session->auth_key.length = 0;
3207 session->auth_alg = 0;
3209 authdata.key = (size_t)session->auth_key.data;
3210 authdata.keylen = session->auth_key.length;
3211 authdata.key_enc_flags = 0;
3212 authdata.key_type = RTA_DATA_IMM;
3214 if (session->auth_alg) {
3215 switch (session->auth_alg) {
3216 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
3217 authdata.algtype = PDCP_AUTH_TYPE_SNOW;
3219 case RTE_CRYPTO_AUTH_ZUC_EIA3:
3220 authdata.algtype = PDCP_AUTH_TYPE_ZUC;
3222 case RTE_CRYPTO_AUTH_AES_CMAC:
3223 authdata.algtype = PDCP_AUTH_TYPE_AES;
3225 case RTE_CRYPTO_AUTH_NULL:
3226 authdata.algtype = PDCP_AUTH_TYPE_NULL;
3229 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
3234 p_authdata = &authdata;
3235 } else if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
3236 DPAA2_SEC_ERR("Crypto: Integrity must for c-plane");
3240 if (rta_inline_pdcp_query(authdata.algtype,
3242 session->pdcp.sn_size,
3243 session->pdcp.hfn_ovd)) {
3244 cipherdata.key = DPAA2_VADDR_TO_IOVA(cipherdata.key);
3245 cipherdata.key_type = RTA_DATA_PTR;
3248 if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
3249 if (session->dir == DIR_ENC)
3250 bufsize = cnstr_shdsc_pdcp_c_plane_encap(
3251 priv->flc_desc[0].desc, 1, swap,
3253 session->pdcp.sn_size,
3255 pdcp_xform->pkt_dir,
3256 pdcp_xform->hfn_threshold,
3257 &cipherdata, &authdata,
3259 else if (session->dir == DIR_DEC)
3260 bufsize = cnstr_shdsc_pdcp_c_plane_decap(
3261 priv->flc_desc[0].desc, 1, swap,
3263 session->pdcp.sn_size,
3265 pdcp_xform->pkt_dir,
3266 pdcp_xform->hfn_threshold,
3267 &cipherdata, &authdata,
3270 if (session->dir == DIR_ENC) {
3271 if (pdcp_xform->sdap_enabled)
3272 bufsize = cnstr_shdsc_pdcp_sdap_u_plane_encap(
3273 priv->flc_desc[0].desc, 1, swap,
3274 session->pdcp.sn_size,
3277 pdcp_xform->pkt_dir,
3278 pdcp_xform->hfn_threshold,
3279 &cipherdata, p_authdata, 0);
3281 bufsize = cnstr_shdsc_pdcp_u_plane_encap(
3282 priv->flc_desc[0].desc, 1, swap,
3283 session->pdcp.sn_size,
3286 pdcp_xform->pkt_dir,
3287 pdcp_xform->hfn_threshold,
3288 &cipherdata, p_authdata, 0);
3289 } else if (session->dir == DIR_DEC) {
3290 if (pdcp_xform->sdap_enabled)
3291 bufsize = cnstr_shdsc_pdcp_sdap_u_plane_decap(
3292 priv->flc_desc[0].desc, 1, swap,
3293 session->pdcp.sn_size,
3296 pdcp_xform->pkt_dir,
3297 pdcp_xform->hfn_threshold,
3298 &cipherdata, p_authdata, 0);
3300 bufsize = cnstr_shdsc_pdcp_u_plane_decap(
3301 priv->flc_desc[0].desc, 1, swap,
3302 session->pdcp.sn_size,
3305 pdcp_xform->pkt_dir,
3306 pdcp_xform->hfn_threshold,
3307 &cipherdata, p_authdata, 0);
3312 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
3316 /* Enable the stashing control bit */
3317 DPAA2_SET_FLC_RSC(flc);
3318 flc->word2_rflc_31_0 = lower_32_bits(
3319 (size_t)&(((struct dpaa2_sec_qp *)
3320 dev->data->queue_pairs[0])->rx_vq) | 0x14);
3321 flc->word3_rflc_63_32 = upper_32_bits(
3322 (size_t)&(((struct dpaa2_sec_qp *)
3323 dev->data->queue_pairs[0])->rx_vq));
3325 flc->word1_sdl = (uint8_t)bufsize;
3327 /* TODO - check the perf impact or
3328 * align as per descriptor type
3329 * Set EWS bit i.e. enable write-safe
3330 * DPAA2_SET_FLC_EWS(flc);
3333 /* Set BS = 1 i.e reuse input buffers as output buffers */
3334 DPAA2_SET_FLC_REUSE_BS(flc);
3335 /* Set FF = 10; reuse input buffers if they provide sufficient space */
3336 DPAA2_SET_FLC_REUSE_FF(flc);
3338 session->ctxt = priv;
3342 rte_free(session->auth_key.data);
3343 rte_free(session->cipher_key.data);
3349 dpaa2_sec_security_session_create(void *dev,
3350 struct rte_security_session_conf *conf,
3351 struct rte_security_session *sess,
3352 struct rte_mempool *mempool)
3354 void *sess_private_data;
3355 struct rte_cryptodev *cdev = (struct rte_cryptodev *)dev;
3358 if (rte_mempool_get(mempool, &sess_private_data)) {
3359 DPAA2_SEC_ERR("Couldn't get object from session mempool");
3363 switch (conf->protocol) {
3364 case RTE_SECURITY_PROTOCOL_IPSEC:
3365 ret = dpaa2_sec_set_ipsec_session(cdev, conf,
3368 case RTE_SECURITY_PROTOCOL_MACSEC:
3370 case RTE_SECURITY_PROTOCOL_PDCP:
3371 ret = dpaa2_sec_set_pdcp_session(cdev, conf,
3378 DPAA2_SEC_ERR("Failed to configure session parameters");
3379 /* Return session to mempool */
3380 rte_mempool_put(mempool, sess_private_data);
3384 set_sec_session_private_data(sess, sess_private_data);
3389 /** Clear the memory of session so it doesn't leave key material behind */
3391 dpaa2_sec_security_session_destroy(void *dev __rte_unused,
3392 struct rte_security_session *sess)
3394 PMD_INIT_FUNC_TRACE();
3395 void *sess_priv = get_sec_session_private_data(sess);
3397 dpaa2_sec_session *s = (dpaa2_sec_session *)sess_priv;
3400 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
3403 rte_free(s->cipher_key.data);
3404 rte_free(s->auth_key.data);
3405 memset(s, 0, sizeof(dpaa2_sec_session));
3406 set_sec_session_private_data(sess, NULL);
3407 rte_mempool_put(sess_mp, sess_priv);
3413 dpaa2_sec_sym_session_configure(struct rte_cryptodev *dev,
3414 struct rte_crypto_sym_xform *xform,
3415 struct rte_cryptodev_sym_session *sess,
3416 struct rte_mempool *mempool)
3418 void *sess_private_data;
3421 if (rte_mempool_get(mempool, &sess_private_data)) {
3422 DPAA2_SEC_ERR("Couldn't get object from session mempool");
3426 ret = dpaa2_sec_set_session_parameters(dev, xform, sess_private_data);
3428 DPAA2_SEC_ERR("Failed to configure session parameters");
3429 /* Return session to mempool */
3430 rte_mempool_put(mempool, sess_private_data);
3434 set_sym_session_private_data(sess, dev->driver_id,
3440 /** Clear the memory of session so it doesn't leave key material behind */
3442 dpaa2_sec_sym_session_clear(struct rte_cryptodev *dev,
3443 struct rte_cryptodev_sym_session *sess)
3445 PMD_INIT_FUNC_TRACE();
3446 uint8_t index = dev->driver_id;
3447 void *sess_priv = get_sym_session_private_data(sess, index);
3448 dpaa2_sec_session *s = (dpaa2_sec_session *)sess_priv;
3452 rte_free(s->cipher_key.data);
3453 rte_free(s->auth_key.data);
3454 memset(s, 0, sizeof(dpaa2_sec_session));
3455 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
3456 set_sym_session_private_data(sess, index, NULL);
3457 rte_mempool_put(sess_mp, sess_priv);
3462 dpaa2_sec_dev_configure(struct rte_cryptodev *dev __rte_unused,
3463 struct rte_cryptodev_config *config __rte_unused)
3465 PMD_INIT_FUNC_TRACE();
3471 dpaa2_sec_dev_start(struct rte_cryptodev *dev)
3473 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3474 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3475 struct dpseci_attr attr;
3476 struct dpaa2_queue *dpaa2_q;
3477 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3478 dev->data->queue_pairs;
3479 struct dpseci_rx_queue_attr rx_attr;
3480 struct dpseci_tx_queue_attr tx_attr;
3483 PMD_INIT_FUNC_TRACE();
3485 memset(&attr, 0, sizeof(struct dpseci_attr));
3487 ret = dpseci_enable(dpseci, CMD_PRI_LOW, priv->token);
3489 DPAA2_SEC_ERR("DPSECI with HW_ID = %d ENABLE FAILED",
3491 goto get_attr_failure;
3493 ret = dpseci_get_attributes(dpseci, CMD_PRI_LOW, priv->token, &attr);
3495 DPAA2_SEC_ERR("DPSEC ATTRIBUTE READ FAILED, disabling DPSEC");
3496 goto get_attr_failure;
3498 for (i = 0; i < attr.num_rx_queues && qp[i]; i++) {
3499 dpaa2_q = &qp[i]->rx_vq;
3500 dpseci_get_rx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
3502 dpaa2_q->fqid = rx_attr.fqid;
3503 DPAA2_SEC_DEBUG("rx_fqid: %d", dpaa2_q->fqid);
3505 for (i = 0; i < attr.num_tx_queues && qp[i]; i++) {
3506 dpaa2_q = &qp[i]->tx_vq;
3507 dpseci_get_tx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
3509 dpaa2_q->fqid = tx_attr.fqid;
3510 DPAA2_SEC_DEBUG("tx_fqid: %d", dpaa2_q->fqid);
3515 dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
3520 dpaa2_sec_dev_stop(struct rte_cryptodev *dev)
3522 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3523 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3526 PMD_INIT_FUNC_TRACE();
3528 ret = dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
3530 DPAA2_SEC_ERR("Failure in disabling dpseci %d device",
3535 ret = dpseci_reset(dpseci, CMD_PRI_LOW, priv->token);
3537 DPAA2_SEC_ERR("SEC Device cannot be reset:Error = %0x", ret);
3543 dpaa2_sec_dev_close(struct rte_cryptodev *dev)
3545 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3546 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3549 PMD_INIT_FUNC_TRACE();
3551 /* Function is reverse of dpaa2_sec_dev_init.
3552 * It does the following:
3553 * 1. Detach a DPSECI from attached resources i.e. buffer pools, dpbp_id
3554 * 2. Close the DPSECI device
3555 * 3. Free the allocated resources.
3558 /*Close the device at underlying layer*/
3559 ret = dpseci_close(dpseci, CMD_PRI_LOW, priv->token);
3561 DPAA2_SEC_ERR("Failure closing dpseci device: err(%d)", ret);
3565 /*Free the allocated memory for ethernet private data and dpseci*/
3573 dpaa2_sec_dev_infos_get(struct rte_cryptodev *dev,
3574 struct rte_cryptodev_info *info)
3576 struct dpaa2_sec_dev_private *internals = dev->data->dev_private;
3578 PMD_INIT_FUNC_TRACE();
3580 info->max_nb_queue_pairs = internals->max_nb_queue_pairs;
3581 info->feature_flags = dev->feature_flags;
3582 info->capabilities = dpaa2_sec_capabilities;
3583 /* No limit of number of sessions */
3584 info->sym.max_nb_sessions = 0;
3585 info->driver_id = cryptodev_driver_id;
3590 void dpaa2_sec_stats_get(struct rte_cryptodev *dev,
3591 struct rte_cryptodev_stats *stats)
3593 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3594 struct fsl_mc_io dpseci;
3595 struct dpseci_sec_counters counters = {0};
3596 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3597 dev->data->queue_pairs;
3600 PMD_INIT_FUNC_TRACE();
3601 if (stats == NULL) {
3602 DPAA2_SEC_ERR("Invalid stats ptr NULL");
3605 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
3606 if (qp == NULL || qp[i] == NULL) {
3607 DPAA2_SEC_DEBUG("Uninitialised queue pair");
3611 stats->enqueued_count += qp[i]->tx_vq.tx_pkts;
3612 stats->dequeued_count += qp[i]->rx_vq.rx_pkts;
3613 stats->enqueue_err_count += qp[i]->tx_vq.err_pkts;
3614 stats->dequeue_err_count += qp[i]->rx_vq.err_pkts;
3617 /* In case as secondary process access stats, MCP portal in priv-hw
3618 * may have primary process address. Need the secondary process
3619 * based MCP portal address for this object.
3621 dpseci.regs = dpaa2_get_mcp_ptr(MC_PORTAL_INDEX);
3622 ret = dpseci_get_sec_counters(&dpseci, CMD_PRI_LOW, priv->token,
3625 DPAA2_SEC_ERR("SEC counters failed");
3627 DPAA2_SEC_INFO("dpseci hardware stats:"
3628 "\n\tNum of Requests Dequeued = %" PRIu64
3629 "\n\tNum of Outbound Encrypt Requests = %" PRIu64
3630 "\n\tNum of Inbound Decrypt Requests = %" PRIu64
3631 "\n\tNum of Outbound Bytes Encrypted = %" PRIu64
3632 "\n\tNum of Outbound Bytes Protected = %" PRIu64
3633 "\n\tNum of Inbound Bytes Decrypted = %" PRIu64
3634 "\n\tNum of Inbound Bytes Validated = %" PRIu64,
3635 counters.dequeued_requests,
3636 counters.ob_enc_requests,
3637 counters.ib_dec_requests,
3638 counters.ob_enc_bytes,
3639 counters.ob_prot_bytes,
3640 counters.ib_dec_bytes,
3641 counters.ib_valid_bytes);
3646 void dpaa2_sec_stats_reset(struct rte_cryptodev *dev)
3649 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3650 (dev->data->queue_pairs);
3652 PMD_INIT_FUNC_TRACE();
3654 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
3655 if (qp[i] == NULL) {
3656 DPAA2_SEC_DEBUG("Uninitialised queue pair");
3659 qp[i]->tx_vq.rx_pkts = 0;
3660 qp[i]->tx_vq.tx_pkts = 0;
3661 qp[i]->tx_vq.err_pkts = 0;
3662 qp[i]->rx_vq.rx_pkts = 0;
3663 qp[i]->rx_vq.tx_pkts = 0;
3664 qp[i]->rx_vq.err_pkts = 0;
3668 static void __rte_hot
3669 dpaa2_sec_process_parallel_event(struct qbman_swp *swp,
3670 const struct qbman_fd *fd,
3671 const struct qbman_result *dq,
3672 struct dpaa2_queue *rxq,
3673 struct rte_event *ev)
3675 /* Prefetching mbuf */
3676 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-
3677 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size));
3679 /* Prefetching ipsec crypto_op stored in priv data of mbuf */
3680 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-64));
3682 ev->flow_id = rxq->ev.flow_id;
3683 ev->sub_event_type = rxq->ev.sub_event_type;
3684 ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
3685 ev->op = RTE_EVENT_OP_NEW;
3686 ev->sched_type = rxq->ev.sched_type;
3687 ev->queue_id = rxq->ev.queue_id;
3688 ev->priority = rxq->ev.priority;
3689 ev->event_ptr = sec_fd_to_mbuf(fd);
3691 qbman_swp_dqrr_consume(swp, dq);
3694 dpaa2_sec_process_atomic_event(struct qbman_swp *swp __rte_unused,
3695 const struct qbman_fd *fd,
3696 const struct qbman_result *dq,
3697 struct dpaa2_queue *rxq,
3698 struct rte_event *ev)
3701 struct rte_crypto_op *crypto_op = (struct rte_crypto_op *)ev->event_ptr;
3702 /* Prefetching mbuf */
3703 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-
3704 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size));
3706 /* Prefetching ipsec crypto_op stored in priv data of mbuf */
3707 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-64));
3709 ev->flow_id = rxq->ev.flow_id;
3710 ev->sub_event_type = rxq->ev.sub_event_type;
3711 ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
3712 ev->op = RTE_EVENT_OP_NEW;
3713 ev->sched_type = rxq->ev.sched_type;
3714 ev->queue_id = rxq->ev.queue_id;
3715 ev->priority = rxq->ev.priority;
3717 ev->event_ptr = sec_fd_to_mbuf(fd);
3718 dqrr_index = qbman_get_dqrr_idx(dq);
3719 *dpaa2_seqn(crypto_op->sym->m_src) = dqrr_index + 1;
3720 DPAA2_PER_LCORE_DQRR_SIZE++;
3721 DPAA2_PER_LCORE_DQRR_HELD |= 1 << dqrr_index;
3722 DPAA2_PER_LCORE_DQRR_MBUF(dqrr_index) = crypto_op->sym->m_src;
3726 dpaa2_sec_eventq_attach(const struct rte_cryptodev *dev,
3728 struct dpaa2_dpcon_dev *dpcon,
3729 const struct rte_event *event)
3731 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3732 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3733 struct dpaa2_sec_qp *qp = dev->data->queue_pairs[qp_id];
3734 struct dpseci_rx_queue_cfg cfg;
3738 if (event->sched_type == RTE_SCHED_TYPE_PARALLEL)
3739 qp->rx_vq.cb = dpaa2_sec_process_parallel_event;
3740 else if (event->sched_type == RTE_SCHED_TYPE_ATOMIC)
3741 qp->rx_vq.cb = dpaa2_sec_process_atomic_event;
3745 priority = (RTE_EVENT_DEV_PRIORITY_LOWEST / event->priority) *
3746 (dpcon->num_priorities - 1);
3748 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
3749 cfg.options = DPSECI_QUEUE_OPT_DEST;
3750 cfg.dest_cfg.dest_type = DPSECI_DEST_DPCON;
3751 cfg.dest_cfg.dest_id = dpcon->dpcon_id;
3752 cfg.dest_cfg.priority = priority;
3754 cfg.options |= DPSECI_QUEUE_OPT_USER_CTX;
3755 cfg.user_ctx = (size_t)(qp);
3756 if (event->sched_type == RTE_SCHED_TYPE_ATOMIC) {
3757 cfg.options |= DPSECI_QUEUE_OPT_ORDER_PRESERVATION;
3758 cfg.order_preservation_en = 1;
3760 ret = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
3763 RTE_LOG(ERR, PMD, "Error in dpseci_set_queue: ret: %d\n", ret);
3767 memcpy(&qp->rx_vq.ev, event, sizeof(struct rte_event));
3773 dpaa2_sec_eventq_detach(const struct rte_cryptodev *dev,
3776 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3777 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3778 struct dpseci_rx_queue_cfg cfg;
3781 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
3782 cfg.options = DPSECI_QUEUE_OPT_DEST;
3783 cfg.dest_cfg.dest_type = DPSECI_DEST_NONE;
3785 ret = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
3788 RTE_LOG(ERR, PMD, "Error in dpseci_set_queue: ret: %d\n", ret);
3793 static struct rte_cryptodev_ops crypto_ops = {
3794 .dev_configure = dpaa2_sec_dev_configure,
3795 .dev_start = dpaa2_sec_dev_start,
3796 .dev_stop = dpaa2_sec_dev_stop,
3797 .dev_close = dpaa2_sec_dev_close,
3798 .dev_infos_get = dpaa2_sec_dev_infos_get,
3799 .stats_get = dpaa2_sec_stats_get,
3800 .stats_reset = dpaa2_sec_stats_reset,
3801 .queue_pair_setup = dpaa2_sec_queue_pair_setup,
3802 .queue_pair_release = dpaa2_sec_queue_pair_release,
3803 .sym_session_get_size = dpaa2_sec_sym_session_get_size,
3804 .sym_session_configure = dpaa2_sec_sym_session_configure,
3805 .sym_session_clear = dpaa2_sec_sym_session_clear,
3808 #ifdef RTE_LIB_SECURITY
3809 static const struct rte_security_capability *
3810 dpaa2_sec_capabilities_get(void *device __rte_unused)
3812 return dpaa2_sec_security_cap;
3815 static const struct rte_security_ops dpaa2_sec_security_ops = {
3816 .session_create = dpaa2_sec_security_session_create,
3817 .session_update = NULL,
3818 .session_stats_get = NULL,
3819 .session_destroy = dpaa2_sec_security_session_destroy,
3820 .set_pkt_metadata = NULL,
3821 .capabilities_get = dpaa2_sec_capabilities_get
3826 dpaa2_sec_uninit(const struct rte_cryptodev *dev)
3828 struct dpaa2_sec_dev_private *internals = dev->data->dev_private;
3830 rte_free(dev->security_ctx);
3832 rte_mempool_free(internals->fle_pool);
3834 DPAA2_SEC_INFO("Closing DPAA2_SEC device %s on numa socket %u",
3835 dev->data->name, rte_socket_id());
3841 dpaa2_sec_dev_init(struct rte_cryptodev *cryptodev)
3843 struct dpaa2_sec_dev_private *internals;
3844 struct rte_device *dev = cryptodev->device;
3845 struct rte_dpaa2_device *dpaa2_dev;
3846 #ifdef RTE_LIB_SECURITY
3847 struct rte_security_ctx *security_instance;
3849 struct fsl_mc_io *dpseci;
3851 struct dpseci_attr attr;
3855 PMD_INIT_FUNC_TRACE();
3856 dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
3857 hw_id = dpaa2_dev->object_id;
3859 cryptodev->driver_id = cryptodev_driver_id;
3860 cryptodev->dev_ops = &crypto_ops;
3862 cryptodev->enqueue_burst = dpaa2_sec_enqueue_burst;
3863 cryptodev->dequeue_burst = dpaa2_sec_dequeue_burst;
3864 cryptodev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
3865 RTE_CRYPTODEV_FF_HW_ACCELERATED |
3866 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
3867 RTE_CRYPTODEV_FF_SECURITY |
3868 RTE_CRYPTODEV_FF_IN_PLACE_SGL |
3869 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT |
3870 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
3871 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT |
3872 RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT;
3874 internals = cryptodev->data->dev_private;
3877 * For secondary processes, we don't initialise any further as primary
3878 * has already done this work. Only check we don't need a different
3881 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
3882 DPAA2_SEC_DEBUG("Device already init by primary process");
3885 #ifdef RTE_LIB_SECURITY
3886 /* Initialize security_ctx only for primary process*/
3887 security_instance = rte_malloc("rte_security_instances_ops",
3888 sizeof(struct rte_security_ctx), 0);
3889 if (security_instance == NULL)
3891 security_instance->device = (void *)cryptodev;
3892 security_instance->ops = &dpaa2_sec_security_ops;
3893 security_instance->sess_cnt = 0;
3894 cryptodev->security_ctx = security_instance;
3896 /*Open the rte device via MC and save the handle for further use*/
3897 dpseci = (struct fsl_mc_io *)rte_calloc(NULL, 1,
3898 sizeof(struct fsl_mc_io), 0);
3901 "Error in allocating the memory for dpsec object");
3904 dpseci->regs = dpaa2_get_mcp_ptr(MC_PORTAL_INDEX);
3906 retcode = dpseci_open(dpseci, CMD_PRI_LOW, hw_id, &token);
3908 DPAA2_SEC_ERR("Cannot open the dpsec device: Error = %x",
3912 retcode = dpseci_get_attributes(dpseci, CMD_PRI_LOW, token, &attr);
3915 "Cannot get dpsec device attributed: Error = %x",
3919 snprintf(cryptodev->data->name, sizeof(cryptodev->data->name),
3922 internals->max_nb_queue_pairs = attr.num_tx_queues;
3923 cryptodev->data->nb_queue_pairs = internals->max_nb_queue_pairs;
3924 internals->hw = dpseci;
3925 internals->token = token;
3927 snprintf(str, sizeof(str), "sec_fle_pool_p%d_%d",
3928 getpid(), cryptodev->data->dev_id);
3929 internals->fle_pool = rte_mempool_create((const char *)str,
3932 FLE_POOL_CACHE_SIZE, 0,
3933 NULL, NULL, NULL, NULL,
3935 if (!internals->fle_pool) {
3936 DPAA2_SEC_ERR("Mempool (%s) creation failed", str);
3940 DPAA2_SEC_INFO("driver %s: created", cryptodev->data->name);
3944 DPAA2_SEC_ERR("driver %s: create failed", cryptodev->data->name);
3946 /* dpaa2_sec_uninit(crypto_dev_name); */
3951 cryptodev_dpaa2_sec_probe(struct rte_dpaa2_driver *dpaa2_drv __rte_unused,
3952 struct rte_dpaa2_device *dpaa2_dev)
3954 struct rte_cryptodev *cryptodev;
3955 char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
3959 snprintf(cryptodev_name, sizeof(cryptodev_name), "dpsec-%d",
3960 dpaa2_dev->object_id);
3962 cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
3963 if (cryptodev == NULL)
3966 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
3967 cryptodev->data->dev_private = rte_zmalloc_socket(
3968 "cryptodev private structure",
3969 sizeof(struct dpaa2_sec_dev_private),
3970 RTE_CACHE_LINE_SIZE,
3973 if (cryptodev->data->dev_private == NULL)
3974 rte_panic("Cannot allocate memzone for private "
3978 dpaa2_dev->cryptodev = cryptodev;
3979 cryptodev->device = &dpaa2_dev->device;
3981 /* init user callbacks */
3982 TAILQ_INIT(&(cryptodev->link_intr_cbs));
3984 if (dpaa2_svr_family == SVR_LX2160A)
3985 rta_set_sec_era(RTA_SEC_ERA_10);
3987 rta_set_sec_era(RTA_SEC_ERA_8);
3989 DPAA2_SEC_INFO("2-SEC ERA is %d", rta_get_sec_era());
3991 /* Invoke PMD device initialization function */
3992 retval = dpaa2_sec_dev_init(cryptodev);
3996 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
3997 rte_free(cryptodev->data->dev_private);
3999 cryptodev->attached = RTE_CRYPTODEV_DETACHED;
4005 cryptodev_dpaa2_sec_remove(struct rte_dpaa2_device *dpaa2_dev)
4007 struct rte_cryptodev *cryptodev;
4010 cryptodev = dpaa2_dev->cryptodev;
4011 if (cryptodev == NULL)
4014 ret = dpaa2_sec_uninit(cryptodev);
4018 return rte_cryptodev_pmd_destroy(cryptodev);
4021 static struct rte_dpaa2_driver rte_dpaa2_sec_driver = {
4022 .drv_flags = RTE_DPAA2_DRV_IOVA_AS_VA,
4023 .drv_type = DPAA2_CRYPTO,
4025 .name = "DPAA2 SEC PMD"
4027 .probe = cryptodev_dpaa2_sec_probe,
4028 .remove = cryptodev_dpaa2_sec_remove,
4031 static struct cryptodev_driver dpaa2_sec_crypto_drv;
4033 RTE_PMD_REGISTER_DPAA2(CRYPTODEV_NAME_DPAA2_SEC_PMD, rte_dpaa2_sec_driver);
4034 RTE_PMD_REGISTER_CRYPTO_DRIVER(dpaa2_sec_crypto_drv,
4035 rte_dpaa2_sec_driver.driver, cryptodev_driver_id);
4036 RTE_LOG_REGISTER(dpaa2_logtype_sec, pmd.crypto.dpaa2, NOTICE);