1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
4 * Copyright 2016-2021 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 <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
53 uint8_t cryptodev_driver_id;
55 #ifdef RTE_LIB_SECURITY
57 build_proto_compound_sg_fd(dpaa2_sec_session *sess,
58 struct rte_crypto_op *op,
59 struct qbman_fd *fd, uint16_t bpid)
61 struct rte_crypto_sym_op *sym_op = op->sym;
62 struct ctxt_priv *priv = sess->ctxt;
63 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
64 struct sec_flow_context *flc;
65 struct rte_mbuf *mbuf;
66 uint32_t in_len = 0, out_len = 0;
73 /* first FLE entry used to store mbuf and session ctxt */
74 fle = (struct qbman_fle *)rte_malloc(NULL,
75 FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
78 DPAA2_SEC_DP_ERR("Proto:SG: Memory alloc failed for SGE");
81 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
82 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
83 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
85 /* Save the shared descriptor */
86 flc = &priv->flc_desc[0].flc;
92 if (likely(bpid < MAX_BPID)) {
93 DPAA2_SET_FD_BPID(fd, bpid);
94 DPAA2_SET_FLE_BPID(op_fle, bpid);
95 DPAA2_SET_FLE_BPID(ip_fle, bpid);
98 DPAA2_SET_FLE_IVP(op_fle);
99 DPAA2_SET_FLE_IVP(ip_fle);
102 /* Configure FD as a FRAME LIST */
103 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
104 DPAA2_SET_FD_COMPOUND_FMT(fd);
105 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
107 /* Configure Output FLE with Scatter/Gather Entry */
108 DPAA2_SET_FLE_SG_EXT(op_fle);
109 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
111 /* Configure Output SGE for Encap/Decap */
112 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
113 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
116 sge->length = mbuf->data_len;
117 out_len += sge->length;
120 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
121 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
123 /* using buf_len for last buf - so that extra data can be added */
124 sge->length = mbuf->buf_len - mbuf->data_off;
125 out_len += sge->length;
127 DPAA2_SET_FLE_FIN(sge);
128 op_fle->length = out_len;
131 mbuf = sym_op->m_src;
133 /* Configure Input FLE with Scatter/Gather Entry */
134 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
135 DPAA2_SET_FLE_SG_EXT(ip_fle);
136 DPAA2_SET_FLE_FIN(ip_fle);
138 /* Configure input SGE for Encap/Decap */
139 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
140 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
141 sge->length = mbuf->data_len;
142 in_len += sge->length;
148 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
149 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
150 sge->length = mbuf->data_len;
151 in_len += sge->length;
154 ip_fle->length = in_len;
155 DPAA2_SET_FLE_FIN(sge);
157 /* In case of PDCP, per packet HFN is stored in
158 * mbuf priv after sym_op.
160 if (sess->ctxt_type == DPAA2_SEC_PDCP && sess->pdcp.hfn_ovd) {
161 uint32_t hfn_ovd = *(uint32_t *)((uint8_t *)op +
162 sess->pdcp.hfn_ovd_offset);
163 /*enable HFN override override */
164 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, hfn_ovd);
165 DPAA2_SET_FLE_INTERNAL_JD(op_fle, hfn_ovd);
166 DPAA2_SET_FD_INTERNAL_JD(fd, hfn_ovd);
168 DPAA2_SET_FD_LEN(fd, ip_fle->length);
174 build_proto_compound_fd(dpaa2_sec_session *sess,
175 struct rte_crypto_op *op,
176 struct qbman_fd *fd, uint16_t bpid)
178 struct rte_crypto_sym_op *sym_op = op->sym;
179 struct ctxt_priv *priv = sess->ctxt;
180 struct qbman_fle *fle, *ip_fle, *op_fle;
181 struct sec_flow_context *flc;
182 struct rte_mbuf *src_mbuf = sym_op->m_src;
183 struct rte_mbuf *dst_mbuf = sym_op->m_dst;
189 /* Save the shared descriptor */
190 flc = &priv->flc_desc[0].flc;
192 /* we are using the first FLE entry to store Mbuf */
193 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
195 DPAA2_SEC_DP_ERR("Memory alloc failed");
198 memset(fle, 0, FLE_POOL_BUF_SIZE);
199 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
200 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
205 if (likely(bpid < MAX_BPID)) {
206 DPAA2_SET_FD_BPID(fd, bpid);
207 DPAA2_SET_FLE_BPID(op_fle, bpid);
208 DPAA2_SET_FLE_BPID(ip_fle, bpid);
210 DPAA2_SET_FD_IVP(fd);
211 DPAA2_SET_FLE_IVP(op_fle);
212 DPAA2_SET_FLE_IVP(ip_fle);
215 /* Configure FD as a FRAME LIST */
216 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
217 DPAA2_SET_FD_COMPOUND_FMT(fd);
218 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
220 /* Configure Output FLE with dst mbuf data */
221 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_MBUF_VADDR_TO_IOVA(dst_mbuf));
222 DPAA2_SET_FLE_OFFSET(op_fle, dst_mbuf->data_off);
223 DPAA2_SET_FLE_LEN(op_fle, dst_mbuf->buf_len);
225 /* Configure Input FLE with src mbuf data */
226 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_MBUF_VADDR_TO_IOVA(src_mbuf));
227 DPAA2_SET_FLE_OFFSET(ip_fle, src_mbuf->data_off);
228 DPAA2_SET_FLE_LEN(ip_fle, src_mbuf->pkt_len);
230 DPAA2_SET_FD_LEN(fd, ip_fle->length);
231 DPAA2_SET_FLE_FIN(ip_fle);
233 /* In case of PDCP, per packet HFN is stored in
234 * mbuf priv after sym_op.
236 if (sess->ctxt_type == DPAA2_SEC_PDCP && sess->pdcp.hfn_ovd) {
237 uint32_t hfn_ovd = *(uint32_t *)((uint8_t *)op +
238 sess->pdcp.hfn_ovd_offset);
239 /*enable HFN override override */
240 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, hfn_ovd);
241 DPAA2_SET_FLE_INTERNAL_JD(op_fle, hfn_ovd);
242 DPAA2_SET_FD_INTERNAL_JD(fd, hfn_ovd);
250 build_proto_fd(dpaa2_sec_session *sess,
251 struct rte_crypto_op *op,
252 struct qbman_fd *fd, uint16_t bpid)
254 struct rte_crypto_sym_op *sym_op = op->sym;
256 return build_proto_compound_fd(sess, op, fd, bpid);
258 struct ctxt_priv *priv = sess->ctxt;
259 struct sec_flow_context *flc;
260 struct rte_mbuf *mbuf = sym_op->m_src;
262 if (likely(bpid < MAX_BPID))
263 DPAA2_SET_FD_BPID(fd, bpid);
265 DPAA2_SET_FD_IVP(fd);
267 /* Save the shared descriptor */
268 flc = &priv->flc_desc[0].flc;
270 DPAA2_SET_FD_ADDR(fd, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
271 DPAA2_SET_FD_OFFSET(fd, sym_op->m_src->data_off);
272 DPAA2_SET_FD_LEN(fd, sym_op->m_src->pkt_len);
273 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
275 /* save physical address of mbuf */
276 op->sym->aead.digest.phys_addr = mbuf->buf_iova;
277 mbuf->buf_iova = (size_t)op;
284 build_authenc_gcm_sg_fd(dpaa2_sec_session *sess,
285 struct rte_crypto_op *op,
286 struct qbman_fd *fd, __rte_unused uint16_t bpid)
288 struct rte_crypto_sym_op *sym_op = op->sym;
289 struct ctxt_priv *priv = sess->ctxt;
290 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
291 struct sec_flow_context *flc;
292 uint32_t auth_only_len = sess->ext_params.aead_ctxt.auth_only_len;
293 int icv_len = sess->digest_length;
295 struct rte_mbuf *mbuf;
296 uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
300 mbuf = sym_op->m_dst;
302 mbuf = sym_op->m_src;
304 /* first FLE entry used to store mbuf and session ctxt */
305 fle = (struct qbman_fle *)rte_malloc(NULL,
306 FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
307 RTE_CACHE_LINE_SIZE);
308 if (unlikely(!fle)) {
309 DPAA2_SEC_ERR("GCM SG: Memory alloc failed for SGE");
312 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
313 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
314 DPAA2_FLE_SAVE_CTXT(fle, (size_t)priv);
320 /* Save the shared descriptor */
321 flc = &priv->flc_desc[0].flc;
323 /* Configure FD as a FRAME LIST */
324 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
325 DPAA2_SET_FD_COMPOUND_FMT(fd);
326 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
328 DPAA2_SEC_DP_DEBUG("GCM SG: auth_off: 0x%x/length %d, digest-len=%d\n"
329 "iv-len=%d data_off: 0x%x\n",
330 sym_op->aead.data.offset,
331 sym_op->aead.data.length,
334 sym_op->m_src->data_off);
336 /* Configure Output FLE with Scatter/Gather Entry */
337 DPAA2_SET_FLE_SG_EXT(op_fle);
338 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
341 DPAA2_SET_FLE_INTERNAL_JD(op_fle, auth_only_len);
343 op_fle->length = (sess->dir == DIR_ENC) ?
344 (sym_op->aead.data.length + icv_len) :
345 sym_op->aead.data.length;
347 /* Configure Output SGE for Encap/Decap */
348 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
349 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off + sym_op->aead.data.offset);
350 sge->length = mbuf->data_len - sym_op->aead.data.offset;
356 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
357 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
358 sge->length = mbuf->data_len;
361 sge->length -= icv_len;
363 if (sess->dir == DIR_ENC) {
365 DPAA2_SET_FLE_ADDR(sge,
366 DPAA2_VADDR_TO_IOVA(sym_op->aead.digest.data));
367 sge->length = icv_len;
369 DPAA2_SET_FLE_FIN(sge);
372 mbuf = sym_op->m_src;
374 /* Configure Input FLE with Scatter/Gather Entry */
375 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
376 DPAA2_SET_FLE_SG_EXT(ip_fle);
377 DPAA2_SET_FLE_FIN(ip_fle);
378 ip_fle->length = (sess->dir == DIR_ENC) ?
379 (sym_op->aead.data.length + sess->iv.length + auth_only_len) :
380 (sym_op->aead.data.length + sess->iv.length + auth_only_len +
383 /* Configure Input SGE for Encap/Decap */
384 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(IV_ptr));
385 sge->length = sess->iv.length;
389 DPAA2_SET_FLE_ADDR(sge,
390 DPAA2_VADDR_TO_IOVA(sym_op->aead.aad.data));
391 sge->length = auth_only_len;
395 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
396 DPAA2_SET_FLE_OFFSET(sge, sym_op->aead.data.offset +
398 sge->length = mbuf->data_len - sym_op->aead.data.offset;
404 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
405 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
406 sge->length = mbuf->data_len;
410 if (sess->dir == DIR_DEC) {
412 old_icv = (uint8_t *)(sge + 1);
413 memcpy(old_icv, sym_op->aead.digest.data, icv_len);
414 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
415 sge->length = icv_len;
418 DPAA2_SET_FLE_FIN(sge);
420 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, auth_only_len);
421 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
423 DPAA2_SET_FD_LEN(fd, ip_fle->length);
429 build_authenc_gcm_fd(dpaa2_sec_session *sess,
430 struct rte_crypto_op *op,
431 struct qbman_fd *fd, uint16_t bpid)
433 struct rte_crypto_sym_op *sym_op = op->sym;
434 struct ctxt_priv *priv = sess->ctxt;
435 struct qbman_fle *fle, *sge;
436 struct sec_flow_context *flc;
437 uint32_t auth_only_len = sess->ext_params.aead_ctxt.auth_only_len;
438 int icv_len = sess->digest_length, retval;
440 struct rte_mbuf *dst;
441 uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
449 /* TODO we are using the first FLE entry to store Mbuf and session ctxt.
450 * Currently we donot know which FLE has the mbuf stored.
451 * So while retreiving we can go back 1 FLE from the FD -ADDR
452 * to get the MBUF Addr from the previous FLE.
453 * We can have a better approach to use the inline Mbuf
455 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
457 DPAA2_SEC_ERR("GCM: Memory alloc failed for SGE");
460 memset(fle, 0, FLE_POOL_BUF_SIZE);
461 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
462 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
465 if (likely(bpid < MAX_BPID)) {
466 DPAA2_SET_FD_BPID(fd, bpid);
467 DPAA2_SET_FLE_BPID(fle, bpid);
468 DPAA2_SET_FLE_BPID(fle + 1, bpid);
469 DPAA2_SET_FLE_BPID(sge, bpid);
470 DPAA2_SET_FLE_BPID(sge + 1, bpid);
471 DPAA2_SET_FLE_BPID(sge + 2, bpid);
472 DPAA2_SET_FLE_BPID(sge + 3, bpid);
474 DPAA2_SET_FD_IVP(fd);
475 DPAA2_SET_FLE_IVP(fle);
476 DPAA2_SET_FLE_IVP((fle + 1));
477 DPAA2_SET_FLE_IVP(sge);
478 DPAA2_SET_FLE_IVP((sge + 1));
479 DPAA2_SET_FLE_IVP((sge + 2));
480 DPAA2_SET_FLE_IVP((sge + 3));
483 /* Save the shared descriptor */
484 flc = &priv->flc_desc[0].flc;
485 /* Configure FD as a FRAME LIST */
486 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
487 DPAA2_SET_FD_COMPOUND_FMT(fd);
488 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
490 DPAA2_SEC_DP_DEBUG("GCM: auth_off: 0x%x/length %d, digest-len=%d\n"
491 "iv-len=%d data_off: 0x%x\n",
492 sym_op->aead.data.offset,
493 sym_op->aead.data.length,
496 sym_op->m_src->data_off);
498 /* Configure Output FLE with Scatter/Gather Entry */
499 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
501 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
502 fle->length = (sess->dir == DIR_ENC) ?
503 (sym_op->aead.data.length + icv_len) :
504 sym_op->aead.data.length;
506 DPAA2_SET_FLE_SG_EXT(fle);
508 /* Configure Output SGE for Encap/Decap */
509 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(dst));
510 DPAA2_SET_FLE_OFFSET(sge, dst->data_off + sym_op->aead.data.offset);
511 sge->length = sym_op->aead.data.length;
513 if (sess->dir == DIR_ENC) {
515 DPAA2_SET_FLE_ADDR(sge,
516 DPAA2_VADDR_TO_IOVA(sym_op->aead.digest.data));
517 sge->length = sess->digest_length;
519 DPAA2_SET_FLE_FIN(sge);
524 /* Configure Input FLE with Scatter/Gather Entry */
525 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
526 DPAA2_SET_FLE_SG_EXT(fle);
527 DPAA2_SET_FLE_FIN(fle);
528 fle->length = (sess->dir == DIR_ENC) ?
529 (sym_op->aead.data.length + sess->iv.length + auth_only_len) :
530 (sym_op->aead.data.length + sess->iv.length + auth_only_len +
531 sess->digest_length);
533 /* Configure Input SGE for Encap/Decap */
534 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(IV_ptr));
535 sge->length = sess->iv.length;
538 DPAA2_SET_FLE_ADDR(sge,
539 DPAA2_VADDR_TO_IOVA(sym_op->aead.aad.data));
540 sge->length = auth_only_len;
541 DPAA2_SET_FLE_BPID(sge, bpid);
545 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
546 DPAA2_SET_FLE_OFFSET(sge, sym_op->aead.data.offset +
547 sym_op->m_src->data_off);
548 sge->length = sym_op->aead.data.length;
549 if (sess->dir == DIR_DEC) {
551 old_icv = (uint8_t *)(sge + 1);
552 memcpy(old_icv, sym_op->aead.digest.data,
553 sess->digest_length);
554 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
555 sge->length = sess->digest_length;
557 DPAA2_SET_FLE_FIN(sge);
560 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
561 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
564 DPAA2_SET_FD_LEN(fd, fle->length);
569 build_authenc_sg_fd(dpaa2_sec_session *sess,
570 struct rte_crypto_op *op,
571 struct qbman_fd *fd, __rte_unused uint16_t bpid)
573 struct rte_crypto_sym_op *sym_op = op->sym;
574 struct ctxt_priv *priv = sess->ctxt;
575 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
576 struct sec_flow_context *flc;
577 uint16_t auth_hdr_len = sym_op->cipher.data.offset -
578 sym_op->auth.data.offset;
579 uint16_t auth_tail_len = sym_op->auth.data.length -
580 sym_op->cipher.data.length - auth_hdr_len;
581 uint32_t auth_only_len = (auth_tail_len << 16) | auth_hdr_len;
582 int icv_len = sess->digest_length;
584 struct rte_mbuf *mbuf;
585 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
589 mbuf = sym_op->m_dst;
591 mbuf = sym_op->m_src;
593 /* first FLE entry used to store mbuf and session ctxt */
594 fle = (struct qbman_fle *)rte_malloc(NULL,
595 FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
596 RTE_CACHE_LINE_SIZE);
597 if (unlikely(!fle)) {
598 DPAA2_SEC_ERR("AUTHENC SG: Memory alloc failed for SGE");
601 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
602 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
603 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
609 /* Save the shared descriptor */
610 flc = &priv->flc_desc[0].flc;
612 /* Configure FD as a FRAME LIST */
613 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
614 DPAA2_SET_FD_COMPOUND_FMT(fd);
615 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
618 "AUTHENC SG: auth_off: 0x%x/length %d, digest-len=%d\n"
619 "cipher_off: 0x%x/length %d, iv-len=%d data_off: 0x%x\n",
620 sym_op->auth.data.offset,
621 sym_op->auth.data.length,
623 sym_op->cipher.data.offset,
624 sym_op->cipher.data.length,
626 sym_op->m_src->data_off);
628 /* Configure Output FLE with Scatter/Gather Entry */
629 DPAA2_SET_FLE_SG_EXT(op_fle);
630 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
633 DPAA2_SET_FLE_INTERNAL_JD(op_fle, auth_only_len);
635 op_fle->length = (sess->dir == DIR_ENC) ?
636 (sym_op->cipher.data.length + icv_len) :
637 sym_op->cipher.data.length;
639 /* Configure Output SGE for Encap/Decap */
640 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
641 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off + sym_op->auth.data.offset);
642 sge->length = mbuf->data_len - sym_op->auth.data.offset;
648 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
649 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
650 sge->length = mbuf->data_len;
653 sge->length -= icv_len;
655 if (sess->dir == DIR_ENC) {
657 DPAA2_SET_FLE_ADDR(sge,
658 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
659 sge->length = icv_len;
661 DPAA2_SET_FLE_FIN(sge);
664 mbuf = sym_op->m_src;
666 /* Configure Input FLE with Scatter/Gather Entry */
667 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
668 DPAA2_SET_FLE_SG_EXT(ip_fle);
669 DPAA2_SET_FLE_FIN(ip_fle);
670 ip_fle->length = (sess->dir == DIR_ENC) ?
671 (sym_op->auth.data.length + sess->iv.length) :
672 (sym_op->auth.data.length + sess->iv.length +
675 /* Configure Input SGE for Encap/Decap */
676 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
677 sge->length = sess->iv.length;
680 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
681 DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset +
683 sge->length = mbuf->data_len - sym_op->auth.data.offset;
689 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
690 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
691 sge->length = mbuf->data_len;
694 sge->length -= icv_len;
696 if (sess->dir == DIR_DEC) {
698 old_icv = (uint8_t *)(sge + 1);
699 memcpy(old_icv, sym_op->auth.digest.data,
701 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
702 sge->length = icv_len;
705 DPAA2_SET_FLE_FIN(sge);
707 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, auth_only_len);
708 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
710 DPAA2_SET_FD_LEN(fd, ip_fle->length);
716 build_authenc_fd(dpaa2_sec_session *sess,
717 struct rte_crypto_op *op,
718 struct qbman_fd *fd, uint16_t bpid)
720 struct rte_crypto_sym_op *sym_op = op->sym;
721 struct ctxt_priv *priv = sess->ctxt;
722 struct qbman_fle *fle, *sge;
723 struct sec_flow_context *flc;
724 uint16_t auth_hdr_len = sym_op->cipher.data.offset -
725 sym_op->auth.data.offset;
726 uint16_t auth_tail_len = sym_op->auth.data.length -
727 sym_op->cipher.data.length - auth_hdr_len;
728 uint32_t auth_only_len = (auth_tail_len << 16) | auth_hdr_len;
730 int icv_len = sess->digest_length, retval;
732 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
734 struct rte_mbuf *dst;
741 /* we are using the first FLE entry to store Mbuf.
742 * Currently we donot know which FLE has the mbuf stored.
743 * So while retreiving we can go back 1 FLE from the FD -ADDR
744 * to get the MBUF Addr from the previous FLE.
745 * We can have a better approach to use the inline Mbuf
747 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
749 DPAA2_SEC_ERR("Memory alloc failed for SGE");
752 memset(fle, 0, FLE_POOL_BUF_SIZE);
753 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
754 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
757 if (likely(bpid < MAX_BPID)) {
758 DPAA2_SET_FD_BPID(fd, bpid);
759 DPAA2_SET_FLE_BPID(fle, bpid);
760 DPAA2_SET_FLE_BPID(fle + 1, bpid);
761 DPAA2_SET_FLE_BPID(sge, bpid);
762 DPAA2_SET_FLE_BPID(sge + 1, bpid);
763 DPAA2_SET_FLE_BPID(sge + 2, bpid);
764 DPAA2_SET_FLE_BPID(sge + 3, bpid);
766 DPAA2_SET_FD_IVP(fd);
767 DPAA2_SET_FLE_IVP(fle);
768 DPAA2_SET_FLE_IVP((fle + 1));
769 DPAA2_SET_FLE_IVP(sge);
770 DPAA2_SET_FLE_IVP((sge + 1));
771 DPAA2_SET_FLE_IVP((sge + 2));
772 DPAA2_SET_FLE_IVP((sge + 3));
775 /* Save the shared descriptor */
776 flc = &priv->flc_desc[0].flc;
777 /* Configure FD as a FRAME LIST */
778 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
779 DPAA2_SET_FD_COMPOUND_FMT(fd);
780 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
783 "AUTHENC: auth_off: 0x%x/length %d, digest-len=%d\n"
784 "cipher_off: 0x%x/length %d, iv-len=%d data_off: 0x%x\n",
785 sym_op->auth.data.offset,
786 sym_op->auth.data.length,
788 sym_op->cipher.data.offset,
789 sym_op->cipher.data.length,
791 sym_op->m_src->data_off);
793 /* Configure Output FLE with Scatter/Gather Entry */
794 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
796 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
797 fle->length = (sess->dir == DIR_ENC) ?
798 (sym_op->cipher.data.length + icv_len) :
799 sym_op->cipher.data.length;
801 DPAA2_SET_FLE_SG_EXT(fle);
803 /* Configure Output SGE for Encap/Decap */
804 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(dst));
805 DPAA2_SET_FLE_OFFSET(sge, sym_op->cipher.data.offset +
807 sge->length = sym_op->cipher.data.length;
809 if (sess->dir == DIR_ENC) {
811 DPAA2_SET_FLE_ADDR(sge,
812 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
813 sge->length = sess->digest_length;
814 DPAA2_SET_FD_LEN(fd, (sym_op->auth.data.length +
817 DPAA2_SET_FLE_FIN(sge);
822 /* Configure Input FLE with Scatter/Gather Entry */
823 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
824 DPAA2_SET_FLE_SG_EXT(fle);
825 DPAA2_SET_FLE_FIN(fle);
826 fle->length = (sess->dir == DIR_ENC) ?
827 (sym_op->auth.data.length + sess->iv.length) :
828 (sym_op->auth.data.length + sess->iv.length +
829 sess->digest_length);
831 /* Configure Input SGE for Encap/Decap */
832 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
833 sge->length = sess->iv.length;
836 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
837 DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset +
838 sym_op->m_src->data_off);
839 sge->length = sym_op->auth.data.length;
840 if (sess->dir == DIR_DEC) {
842 old_icv = (uint8_t *)(sge + 1);
843 memcpy(old_icv, sym_op->auth.digest.data,
844 sess->digest_length);
845 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
846 sge->length = sess->digest_length;
847 DPAA2_SET_FD_LEN(fd, (sym_op->auth.data.length +
848 sess->digest_length +
851 DPAA2_SET_FLE_FIN(sge);
853 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
854 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
859 static inline int build_auth_sg_fd(
860 dpaa2_sec_session *sess,
861 struct rte_crypto_op *op,
863 __rte_unused uint16_t bpid)
865 struct rte_crypto_sym_op *sym_op = op->sym;
866 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
867 struct sec_flow_context *flc;
868 struct ctxt_priv *priv = sess->ctxt;
869 int data_len, data_offset;
871 struct rte_mbuf *mbuf;
873 data_len = sym_op->auth.data.length;
874 data_offset = sym_op->auth.data.offset;
876 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
877 sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
878 if ((data_len & 7) || (data_offset & 7)) {
879 DPAA2_SEC_ERR("AUTH: len/offset must be full bytes");
883 data_len = data_len >> 3;
884 data_offset = data_offset >> 3;
887 mbuf = sym_op->m_src;
888 fle = (struct qbman_fle *)rte_malloc(NULL,
889 FLE_SG_MEM_SIZE(mbuf->nb_segs),
890 RTE_CACHE_LINE_SIZE);
891 if (unlikely(!fle)) {
892 DPAA2_SEC_ERR("AUTH SG: Memory alloc failed for SGE");
895 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs));
896 /* first FLE entry used to store mbuf and session ctxt */
897 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
898 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
903 flc = &priv->flc_desc[DESC_INITFINAL].flc;
905 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
906 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
907 DPAA2_SET_FD_COMPOUND_FMT(fd);
910 DPAA2_SET_FLE_ADDR(op_fle,
911 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
912 op_fle->length = sess->digest_length;
915 DPAA2_SET_FLE_SG_EXT(ip_fle);
916 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
917 ip_fle->length = data_len;
919 if (sess->iv.length) {
922 iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
925 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2) {
926 iv_ptr = conv_to_snow_f9_iv(iv_ptr);
928 } else if (sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
929 iv_ptr = conv_to_zuc_eia_iv(iv_ptr);
932 sge->length = sess->iv.length;
934 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
935 ip_fle->length += sge->length;
939 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
940 DPAA2_SET_FLE_OFFSET(sge, data_offset + mbuf->data_off);
942 if (data_len <= (mbuf->data_len - data_offset)) {
943 sge->length = data_len;
946 sge->length = mbuf->data_len - data_offset;
948 /* remaining i/p segs */
949 while ((data_len = data_len - sge->length) &&
950 (mbuf = mbuf->next)) {
952 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
953 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
954 if (data_len > mbuf->data_len)
955 sge->length = mbuf->data_len;
957 sge->length = data_len;
961 if (sess->dir == DIR_DEC) {
962 /* Digest verification case */
964 old_digest = (uint8_t *)(sge + 1);
965 rte_memcpy(old_digest, sym_op->auth.digest.data,
966 sess->digest_length);
967 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_digest));
968 sge->length = sess->digest_length;
969 ip_fle->length += sess->digest_length;
971 DPAA2_SET_FLE_FIN(sge);
972 DPAA2_SET_FLE_FIN(ip_fle);
973 DPAA2_SET_FD_LEN(fd, ip_fle->length);
979 build_auth_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
980 struct qbman_fd *fd, uint16_t bpid)
982 struct rte_crypto_sym_op *sym_op = op->sym;
983 struct qbman_fle *fle, *sge;
984 struct sec_flow_context *flc;
985 struct ctxt_priv *priv = sess->ctxt;
986 int data_len, data_offset;
990 data_len = sym_op->auth.data.length;
991 data_offset = sym_op->auth.data.offset;
993 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
994 sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
995 if ((data_len & 7) || (data_offset & 7)) {
996 DPAA2_SEC_ERR("AUTH: len/offset must be full bytes");
1000 data_len = data_len >> 3;
1001 data_offset = data_offset >> 3;
1004 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
1006 DPAA2_SEC_ERR("AUTH Memory alloc failed for SGE");
1009 memset(fle, 0, FLE_POOL_BUF_SIZE);
1010 /* TODO we are using the first FLE entry to store Mbuf.
1011 * Currently we donot know which FLE has the mbuf stored.
1012 * So while retreiving we can go back 1 FLE from the FD -ADDR
1013 * to get the MBUF Addr from the previous FLE.
1014 * We can have a better approach to use the inline Mbuf
1016 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
1017 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
1021 if (likely(bpid < MAX_BPID)) {
1022 DPAA2_SET_FD_BPID(fd, bpid);
1023 DPAA2_SET_FLE_BPID(fle, bpid);
1024 DPAA2_SET_FLE_BPID(fle + 1, bpid);
1025 DPAA2_SET_FLE_BPID(sge, bpid);
1026 DPAA2_SET_FLE_BPID(sge + 1, bpid);
1028 DPAA2_SET_FD_IVP(fd);
1029 DPAA2_SET_FLE_IVP(fle);
1030 DPAA2_SET_FLE_IVP((fle + 1));
1031 DPAA2_SET_FLE_IVP(sge);
1032 DPAA2_SET_FLE_IVP((sge + 1));
1035 flc = &priv->flc_desc[DESC_INITFINAL].flc;
1036 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
1037 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
1038 DPAA2_SET_FD_COMPOUND_FMT(fd);
1040 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
1041 fle->length = sess->digest_length;
1044 /* Setting input FLE */
1045 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
1046 DPAA2_SET_FLE_SG_EXT(fle);
1047 fle->length = data_len;
1049 if (sess->iv.length) {
1052 iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1055 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2) {
1056 iv_ptr = conv_to_snow_f9_iv(iv_ptr);
1058 } else if (sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
1059 iv_ptr = conv_to_zuc_eia_iv(iv_ptr);
1062 sge->length = sess->iv.length;
1065 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
1066 fle->length = fle->length + sge->length;
1070 /* Setting data to authenticate */
1071 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
1072 DPAA2_SET_FLE_OFFSET(sge, data_offset + sym_op->m_src->data_off);
1073 sge->length = data_len;
1075 if (sess->dir == DIR_DEC) {
1077 old_digest = (uint8_t *)(sge + 1);
1078 rte_memcpy(old_digest, sym_op->auth.digest.data,
1079 sess->digest_length);
1080 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_digest));
1081 sge->length = sess->digest_length;
1082 fle->length = fle->length + sess->digest_length;
1085 DPAA2_SET_FLE_FIN(sge);
1086 DPAA2_SET_FLE_FIN(fle);
1087 DPAA2_SET_FD_LEN(fd, fle->length);
1093 build_cipher_sg_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
1094 struct qbman_fd *fd, __rte_unused uint16_t bpid)
1096 struct rte_crypto_sym_op *sym_op = op->sym;
1097 struct qbman_fle *ip_fle, *op_fle, *sge, *fle;
1098 int data_len, data_offset;
1099 struct sec_flow_context *flc;
1100 struct ctxt_priv *priv = sess->ctxt;
1101 struct rte_mbuf *mbuf;
1102 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1105 data_len = sym_op->cipher.data.length;
1106 data_offset = sym_op->cipher.data.offset;
1108 if (sess->cipher_alg == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
1109 sess->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
1110 if ((data_len & 7) || (data_offset & 7)) {
1111 DPAA2_SEC_ERR("CIPHER: len/offset must be full bytes");
1115 data_len = data_len >> 3;
1116 data_offset = data_offset >> 3;
1120 mbuf = sym_op->m_dst;
1122 mbuf = sym_op->m_src;
1124 /* first FLE entry used to store mbuf and session ctxt */
1125 fle = (struct qbman_fle *)rte_malloc(NULL,
1126 FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
1127 RTE_CACHE_LINE_SIZE);
1129 DPAA2_SEC_ERR("CIPHER SG: Memory alloc failed for SGE");
1132 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
1133 /* first FLE entry used to store mbuf and session ctxt */
1134 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
1135 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
1141 flc = &priv->flc_desc[0].flc;
1144 "CIPHER SG: cipher_off: 0x%x/length %d, ivlen=%d"
1145 " data_off: 0x%x\n",
1149 sym_op->m_src->data_off);
1152 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
1153 op_fle->length = data_len;
1154 DPAA2_SET_FLE_SG_EXT(op_fle);
1157 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1158 DPAA2_SET_FLE_OFFSET(sge, data_offset + mbuf->data_off);
1159 sge->length = mbuf->data_len - data_offset;
1165 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1166 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
1167 sge->length = mbuf->data_len;
1170 DPAA2_SET_FLE_FIN(sge);
1173 "CIPHER SG: 1 - flc = %p, fle = %p FLEaddr = %x-%x, len %d\n",
1174 flc, fle, fle->addr_hi, fle->addr_lo,
1178 mbuf = sym_op->m_src;
1180 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
1181 ip_fle->length = sess->iv.length + data_len;
1182 DPAA2_SET_FLE_SG_EXT(ip_fle);
1185 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
1186 DPAA2_SET_FLE_OFFSET(sge, 0);
1187 sge->length = sess->iv.length;
1192 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1193 DPAA2_SET_FLE_OFFSET(sge, data_offset + mbuf->data_off);
1194 sge->length = mbuf->data_len - data_offset;
1200 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1201 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
1202 sge->length = mbuf->data_len;
1205 DPAA2_SET_FLE_FIN(sge);
1206 DPAA2_SET_FLE_FIN(ip_fle);
1209 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
1210 DPAA2_SET_FD_LEN(fd, ip_fle->length);
1211 DPAA2_SET_FD_COMPOUND_FMT(fd);
1212 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
1215 "CIPHER SG: fdaddr =%" PRIx64 " bpid =%d meta =%d"
1216 " off =%d, len =%d\n",
1217 DPAA2_GET_FD_ADDR(fd),
1218 DPAA2_GET_FD_BPID(fd),
1219 rte_dpaa2_bpid_info[bpid].meta_data_size,
1220 DPAA2_GET_FD_OFFSET(fd),
1221 DPAA2_GET_FD_LEN(fd));
1226 build_cipher_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
1227 struct qbman_fd *fd, uint16_t bpid)
1229 struct rte_crypto_sym_op *sym_op = op->sym;
1230 struct qbman_fle *fle, *sge;
1231 int retval, data_len, data_offset;
1232 struct sec_flow_context *flc;
1233 struct ctxt_priv *priv = sess->ctxt;
1234 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1236 struct rte_mbuf *dst;
1238 data_len = sym_op->cipher.data.length;
1239 data_offset = sym_op->cipher.data.offset;
1241 if (sess->cipher_alg == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
1242 sess->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
1243 if ((data_len & 7) || (data_offset & 7)) {
1244 DPAA2_SEC_ERR("CIPHER: len/offset must be full bytes");
1248 data_len = data_len >> 3;
1249 data_offset = data_offset >> 3;
1253 dst = sym_op->m_dst;
1255 dst = sym_op->m_src;
1257 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
1259 DPAA2_SEC_ERR("CIPHER: Memory alloc failed for SGE");
1262 memset(fle, 0, FLE_POOL_BUF_SIZE);
1263 /* TODO we are using the first FLE entry to store Mbuf.
1264 * Currently we donot know which FLE has the mbuf stored.
1265 * So while retreiving we can go back 1 FLE from the FD -ADDR
1266 * to get the MBUF Addr from the previous FLE.
1267 * We can have a better approach to use the inline Mbuf
1269 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
1270 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
1274 if (likely(bpid < MAX_BPID)) {
1275 DPAA2_SET_FD_BPID(fd, bpid);
1276 DPAA2_SET_FLE_BPID(fle, bpid);
1277 DPAA2_SET_FLE_BPID(fle + 1, bpid);
1278 DPAA2_SET_FLE_BPID(sge, bpid);
1279 DPAA2_SET_FLE_BPID(sge + 1, bpid);
1281 DPAA2_SET_FD_IVP(fd);
1282 DPAA2_SET_FLE_IVP(fle);
1283 DPAA2_SET_FLE_IVP((fle + 1));
1284 DPAA2_SET_FLE_IVP(sge);
1285 DPAA2_SET_FLE_IVP((sge + 1));
1288 flc = &priv->flc_desc[0].flc;
1289 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
1290 DPAA2_SET_FD_LEN(fd, data_len + sess->iv.length);
1291 DPAA2_SET_FD_COMPOUND_FMT(fd);
1292 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
1295 "CIPHER: cipher_off: 0x%x/length %d, ivlen=%d,"
1296 " data_off: 0x%x\n",
1300 sym_op->m_src->data_off);
1302 DPAA2_SET_FLE_ADDR(fle, DPAA2_MBUF_VADDR_TO_IOVA(dst));
1303 DPAA2_SET_FLE_OFFSET(fle, data_offset + dst->data_off);
1305 fle->length = data_len + sess->iv.length;
1308 "CIPHER: 1 - flc = %p, fle = %p FLEaddr = %x-%x, length %d\n",
1309 flc, fle, fle->addr_hi, fle->addr_lo,
1314 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
1315 fle->length = data_len + sess->iv.length;
1317 DPAA2_SET_FLE_SG_EXT(fle);
1319 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
1320 sge->length = sess->iv.length;
1323 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
1324 DPAA2_SET_FLE_OFFSET(sge, data_offset + sym_op->m_src->data_off);
1326 sge->length = data_len;
1327 DPAA2_SET_FLE_FIN(sge);
1328 DPAA2_SET_FLE_FIN(fle);
1331 "CIPHER: fdaddr =%" PRIx64 " bpid =%d meta =%d"
1332 " off =%d, len =%d\n",
1333 DPAA2_GET_FD_ADDR(fd),
1334 DPAA2_GET_FD_BPID(fd),
1335 rte_dpaa2_bpid_info[bpid].meta_data_size,
1336 DPAA2_GET_FD_OFFSET(fd),
1337 DPAA2_GET_FD_LEN(fd));
1343 build_sec_fd(struct rte_crypto_op *op,
1344 struct qbman_fd *fd, uint16_t bpid)
1347 dpaa2_sec_session *sess;
1349 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION)
1350 sess = (dpaa2_sec_session *)get_sym_session_private_data(
1351 op->sym->session, cryptodev_driver_id);
1352 #ifdef RTE_LIB_SECURITY
1353 else if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION)
1354 sess = (dpaa2_sec_session *)get_sec_session_private_data(
1355 op->sym->sec_session);
1363 /* Any of the buffer is segmented*/
1364 if (!rte_pktmbuf_is_contiguous(op->sym->m_src) ||
1365 ((op->sym->m_dst != NULL) &&
1366 !rte_pktmbuf_is_contiguous(op->sym->m_dst))) {
1367 switch (sess->ctxt_type) {
1368 case DPAA2_SEC_CIPHER:
1369 ret = build_cipher_sg_fd(sess, op, fd, bpid);
1371 case DPAA2_SEC_AUTH:
1372 ret = build_auth_sg_fd(sess, op, fd, bpid);
1374 case DPAA2_SEC_AEAD:
1375 ret = build_authenc_gcm_sg_fd(sess, op, fd, bpid);
1377 case DPAA2_SEC_CIPHER_HASH:
1378 ret = build_authenc_sg_fd(sess, op, fd, bpid);
1380 #ifdef RTE_LIB_SECURITY
1381 case DPAA2_SEC_IPSEC:
1382 case DPAA2_SEC_PDCP:
1383 ret = build_proto_compound_sg_fd(sess, op, fd, bpid);
1386 case DPAA2_SEC_HASH_CIPHER:
1388 DPAA2_SEC_ERR("error: Unsupported session");
1391 switch (sess->ctxt_type) {
1392 case DPAA2_SEC_CIPHER:
1393 ret = build_cipher_fd(sess, op, fd, bpid);
1395 case DPAA2_SEC_AUTH:
1396 ret = build_auth_fd(sess, op, fd, bpid);
1398 case DPAA2_SEC_AEAD:
1399 ret = build_authenc_gcm_fd(sess, op, fd, bpid);
1401 case DPAA2_SEC_CIPHER_HASH:
1402 ret = build_authenc_fd(sess, op, fd, bpid);
1404 #ifdef RTE_LIB_SECURITY
1405 case DPAA2_SEC_IPSEC:
1406 ret = build_proto_fd(sess, op, fd, bpid);
1408 case DPAA2_SEC_PDCP:
1409 ret = build_proto_compound_fd(sess, op, fd, bpid);
1412 case DPAA2_SEC_HASH_CIPHER:
1414 DPAA2_SEC_ERR("error: Unsupported session");
1422 dpaa2_sec_enqueue_burst(void *qp, struct rte_crypto_op **ops,
1425 /* Function to transmit the frames to given device and VQ*/
1428 struct qbman_fd fd_arr[MAX_TX_RING_SLOTS];
1429 uint32_t frames_to_send, retry_count;
1430 struct qbman_eq_desc eqdesc;
1431 struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
1432 struct qbman_swp *swp;
1433 uint16_t num_tx = 0;
1434 uint32_t flags[MAX_TX_RING_SLOTS] = {0};
1435 /*todo - need to support multiple buffer pools */
1437 struct rte_mempool *mb_pool;
1439 if (unlikely(nb_ops == 0))
1442 if (ops[0]->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
1443 DPAA2_SEC_ERR("sessionless crypto op not supported");
1446 /*Prepare enqueue descriptor*/
1447 qbman_eq_desc_clear(&eqdesc);
1448 qbman_eq_desc_set_no_orp(&eqdesc, DPAA2_EQ_RESP_ERR_FQ);
1449 qbman_eq_desc_set_response(&eqdesc, 0, 0);
1450 qbman_eq_desc_set_fq(&eqdesc, dpaa2_qp->tx_vq.fqid);
1452 if (!DPAA2_PER_LCORE_DPIO) {
1453 ret = dpaa2_affine_qbman_swp();
1456 "Failed to allocate IO portal, tid: %d\n",
1461 swp = DPAA2_PER_LCORE_PORTAL;
1464 frames_to_send = (nb_ops > dpaa2_eqcr_size) ?
1465 dpaa2_eqcr_size : nb_ops;
1467 for (loop = 0; loop < frames_to_send; loop++) {
1468 if (*dpaa2_seqn((*ops)->sym->m_src)) {
1469 uint8_t dqrr_index =
1470 *dpaa2_seqn((*ops)->sym->m_src) - 1;
1472 flags[loop] = QBMAN_ENQUEUE_FLAG_DCA | dqrr_index;
1473 DPAA2_PER_LCORE_DQRR_SIZE--;
1474 DPAA2_PER_LCORE_DQRR_HELD &= ~(1 << dqrr_index);
1475 *dpaa2_seqn((*ops)->sym->m_src) =
1476 DPAA2_INVALID_MBUF_SEQN;
1479 /*Clear the unused FD fields before sending*/
1480 memset(&fd_arr[loop], 0, sizeof(struct qbman_fd));
1481 mb_pool = (*ops)->sym->m_src->pool;
1482 bpid = mempool_to_bpid(mb_pool);
1483 ret = build_sec_fd(*ops, &fd_arr[loop], bpid);
1485 DPAA2_SEC_ERR("error: Improper packet contents"
1486 " for crypto operation");
1494 while (loop < frames_to_send) {
1495 ret = qbman_swp_enqueue_multiple(swp, &eqdesc,
1498 frames_to_send - loop);
1499 if (unlikely(ret < 0)) {
1501 if (retry_count > DPAA2_MAX_TX_RETRY_COUNT) {
1516 dpaa2_qp->tx_vq.tx_pkts += num_tx;
1517 dpaa2_qp->tx_vq.err_pkts += nb_ops;
1521 #ifdef RTE_LIB_SECURITY
1522 static inline struct rte_crypto_op *
1523 sec_simple_fd_to_mbuf(const struct qbman_fd *fd)
1525 struct rte_crypto_op *op;
1526 uint16_t len = DPAA2_GET_FD_LEN(fd);
1528 dpaa2_sec_session *sess_priv __rte_unused;
1530 struct rte_mbuf *mbuf = DPAA2_INLINE_MBUF_FROM_BUF(
1531 DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd)),
1532 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size);
1534 diff = len - mbuf->pkt_len;
1535 mbuf->pkt_len += diff;
1536 mbuf->data_len += diff;
1537 op = (struct rte_crypto_op *)(size_t)mbuf->buf_iova;
1538 mbuf->buf_iova = op->sym->aead.digest.phys_addr;
1539 op->sym->aead.digest.phys_addr = 0L;
1541 sess_priv = (dpaa2_sec_session *)get_sec_session_private_data(
1542 op->sym->sec_session);
1543 if (sess_priv->dir == DIR_ENC)
1544 mbuf->data_off += SEC_FLC_DHR_OUTBOUND;
1546 mbuf->data_off += SEC_FLC_DHR_INBOUND;
1552 static inline struct rte_crypto_op *
1553 sec_fd_to_mbuf(const struct qbman_fd *fd)
1555 struct qbman_fle *fle;
1556 struct rte_crypto_op *op;
1557 struct ctxt_priv *priv;
1558 struct rte_mbuf *dst, *src;
1560 #ifdef RTE_LIB_SECURITY
1561 if (DPAA2_FD_GET_FORMAT(fd) == qbman_fd_single)
1562 return sec_simple_fd_to_mbuf(fd);
1564 fle = (struct qbman_fle *)DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd));
1566 DPAA2_SEC_DP_DEBUG("FLE addr = %x - %x, offset = %x\n",
1567 fle->addr_hi, fle->addr_lo, fle->fin_bpid_offset);
1569 /* we are using the first FLE entry to store Mbuf.
1570 * Currently we donot know which FLE has the mbuf stored.
1571 * So while retreiving we can go back 1 FLE from the FD -ADDR
1572 * to get the MBUF Addr from the previous FLE.
1573 * We can have a better approach to use the inline Mbuf
1576 if (unlikely(DPAA2_GET_FD_IVP(fd))) {
1577 /* TODO complete it. */
1578 DPAA2_SEC_ERR("error: non inline buffer");
1581 op = (struct rte_crypto_op *)DPAA2_GET_FLE_ADDR((fle - 1));
1584 src = op->sym->m_src;
1587 if (op->sym->m_dst) {
1588 dst = op->sym->m_dst;
1593 #ifdef RTE_LIB_SECURITY
1594 if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
1595 uint16_t len = DPAA2_GET_FD_LEN(fd);
1597 while (dst->next != NULL) {
1598 len -= dst->data_len;
1601 dst->data_len = len;
1604 DPAA2_SEC_DP_DEBUG("mbuf %p BMAN buf addr %p,"
1605 " fdaddr =%" PRIx64 " bpid =%d meta =%d off =%d, len =%d\n",
1608 DPAA2_GET_FD_ADDR(fd),
1609 DPAA2_GET_FD_BPID(fd),
1610 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size,
1611 DPAA2_GET_FD_OFFSET(fd),
1612 DPAA2_GET_FD_LEN(fd));
1614 /* free the fle memory */
1615 if (likely(rte_pktmbuf_is_contiguous(src))) {
1616 priv = (struct ctxt_priv *)(size_t)DPAA2_GET_FLE_CTXT(fle - 1);
1617 rte_mempool_put(priv->fle_pool, (void *)(fle-1));
1619 rte_free((void *)(fle-1));
1625 dpaa2_sec_dequeue_burst(void *qp, struct rte_crypto_op **ops,
1628 /* Function is responsible to receive frames for a given device and VQ*/
1629 struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
1630 struct qbman_result *dq_storage;
1631 uint32_t fqid = dpaa2_qp->rx_vq.fqid;
1632 int ret, num_rx = 0;
1633 uint8_t is_last = 0, status;
1634 struct qbman_swp *swp;
1635 const struct qbman_fd *fd;
1636 struct qbman_pull_desc pulldesc;
1638 if (!DPAA2_PER_LCORE_DPIO) {
1639 ret = dpaa2_affine_qbman_swp();
1642 "Failed to allocate IO portal, tid: %d\n",
1647 swp = DPAA2_PER_LCORE_PORTAL;
1648 dq_storage = dpaa2_qp->rx_vq.q_storage->dq_storage[0];
1650 qbman_pull_desc_clear(&pulldesc);
1651 qbman_pull_desc_set_numframes(&pulldesc,
1652 (nb_ops > dpaa2_dqrr_size) ?
1653 dpaa2_dqrr_size : nb_ops);
1654 qbman_pull_desc_set_fq(&pulldesc, fqid);
1655 qbman_pull_desc_set_storage(&pulldesc, dq_storage,
1656 (dma_addr_t)DPAA2_VADDR_TO_IOVA(dq_storage),
1659 /*Issue a volatile dequeue command. */
1661 if (qbman_swp_pull(swp, &pulldesc)) {
1663 "SEC VDQ command is not issued : QBMAN busy");
1664 /* Portal was busy, try again */
1670 /* Receive the packets till Last Dequeue entry is found with
1671 * respect to the above issues PULL command.
1674 /* Check if the previous issued command is completed.
1675 * Also seems like the SWP is shared between the Ethernet Driver
1676 * and the SEC driver.
1678 while (!qbman_check_command_complete(dq_storage))
1681 /* Loop until the dq_storage is updated with
1682 * new token by QBMAN
1684 while (!qbman_check_new_result(dq_storage))
1686 /* Check whether Last Pull command is Expired and
1687 * setting Condition for Loop termination
1689 if (qbman_result_DQ_is_pull_complete(dq_storage)) {
1691 /* Check for valid frame. */
1692 status = (uint8_t)qbman_result_DQ_flags(dq_storage);
1694 (status & QBMAN_DQ_STAT_VALIDFRAME) == 0)) {
1695 DPAA2_SEC_DP_DEBUG("No frame is delivered\n");
1700 fd = qbman_result_DQ_fd(dq_storage);
1701 ops[num_rx] = sec_fd_to_mbuf(fd);
1703 if (unlikely(fd->simple.frc)) {
1704 /* TODO Parse SEC errors */
1705 DPAA2_SEC_DP_ERR("SEC returned Error - %x\n",
1707 dpaa2_qp->rx_vq.err_pkts += 1;
1708 ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_ERROR;
1710 ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
1715 } /* End of Packet Rx loop */
1717 dpaa2_qp->rx_vq.rx_pkts += num_rx;
1719 DPAA2_SEC_DP_DEBUG("SEC RX pkts %d err pkts %" PRIu64 "\n", num_rx,
1720 dpaa2_qp->rx_vq.err_pkts);
1721 /*Return the total number of packets received to DPAA2 app*/
1725 /** Release queue pair */
1727 dpaa2_sec_queue_pair_release(struct rte_cryptodev *dev, uint16_t queue_pair_id)
1729 struct dpaa2_sec_qp *qp =
1730 (struct dpaa2_sec_qp *)dev->data->queue_pairs[queue_pair_id];
1732 PMD_INIT_FUNC_TRACE();
1734 if (qp->rx_vq.q_storage) {
1735 dpaa2_free_dq_storage(qp->rx_vq.q_storage);
1736 rte_free(qp->rx_vq.q_storage);
1740 dev->data->queue_pairs[queue_pair_id] = NULL;
1745 /** Setup a queue pair */
1747 dpaa2_sec_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
1748 __rte_unused const struct rte_cryptodev_qp_conf *qp_conf,
1749 __rte_unused int socket_id)
1751 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
1752 struct dpaa2_sec_qp *qp;
1753 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
1754 struct dpseci_rx_queue_cfg cfg;
1757 PMD_INIT_FUNC_TRACE();
1759 /* If qp is already in use free ring memory and qp metadata. */
1760 if (dev->data->queue_pairs[qp_id] != NULL) {
1761 DPAA2_SEC_INFO("QP already setup");
1765 DPAA2_SEC_DEBUG("dev =%p, queue =%d, conf =%p",
1766 dev, qp_id, qp_conf);
1768 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
1770 qp = rte_malloc(NULL, sizeof(struct dpaa2_sec_qp),
1771 RTE_CACHE_LINE_SIZE);
1773 DPAA2_SEC_ERR("malloc failed for rx/tx queues");
1777 qp->rx_vq.crypto_data = dev->data;
1778 qp->tx_vq.crypto_data = dev->data;
1779 qp->rx_vq.q_storage = rte_malloc("sec dq storage",
1780 sizeof(struct queue_storage_info_t),
1781 RTE_CACHE_LINE_SIZE);
1782 if (!qp->rx_vq.q_storage) {
1783 DPAA2_SEC_ERR("malloc failed for q_storage");
1786 memset(qp->rx_vq.q_storage, 0, sizeof(struct queue_storage_info_t));
1788 if (dpaa2_alloc_dq_storage(qp->rx_vq.q_storage)) {
1789 DPAA2_SEC_ERR("Unable to allocate dequeue storage");
1793 dev->data->queue_pairs[qp_id] = qp;
1795 cfg.options = cfg.options | DPSECI_QUEUE_OPT_USER_CTX;
1796 cfg.user_ctx = (size_t)(&qp->rx_vq);
1797 retcode = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
1802 /** Returns the size of the aesni gcm session structure */
1804 dpaa2_sec_sym_session_get_size(struct rte_cryptodev *dev __rte_unused)
1806 PMD_INIT_FUNC_TRACE();
1808 return sizeof(dpaa2_sec_session);
1812 dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
1813 struct rte_crypto_sym_xform *xform,
1814 dpaa2_sec_session *session)
1816 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
1817 struct alginfo cipherdata;
1818 int bufsize, ret = 0;
1819 struct ctxt_priv *priv;
1820 struct sec_flow_context *flc;
1822 PMD_INIT_FUNC_TRACE();
1824 /* For SEC CIPHER only one descriptor is required. */
1825 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
1826 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
1827 RTE_CACHE_LINE_SIZE);
1829 DPAA2_SEC_ERR("No Memory for priv CTXT");
1833 priv->fle_pool = dev_priv->fle_pool;
1835 flc = &priv->flc_desc[0].flc;
1837 session->ctxt_type = DPAA2_SEC_CIPHER;
1838 session->cipher_key.data = rte_zmalloc(NULL, xform->cipher.key.length,
1839 RTE_CACHE_LINE_SIZE);
1840 if (session->cipher_key.data == NULL && xform->cipher.key.length > 0) {
1841 DPAA2_SEC_ERR("No Memory for cipher key");
1845 session->cipher_key.length = xform->cipher.key.length;
1847 memcpy(session->cipher_key.data, xform->cipher.key.data,
1848 xform->cipher.key.length);
1849 cipherdata.key = (size_t)session->cipher_key.data;
1850 cipherdata.keylen = session->cipher_key.length;
1851 cipherdata.key_enc_flags = 0;
1852 cipherdata.key_type = RTA_DATA_IMM;
1854 /* Set IV parameters */
1855 session->iv.offset = xform->cipher.iv.offset;
1856 session->iv.length = xform->cipher.iv.length;
1857 session->dir = (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
1860 switch (xform->cipher.algo) {
1861 case RTE_CRYPTO_CIPHER_AES_CBC:
1862 cipherdata.algtype = OP_ALG_ALGSEL_AES;
1863 cipherdata.algmode = OP_ALG_AAI_CBC;
1864 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
1865 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
1866 SHR_NEVER, &cipherdata,
1870 case RTE_CRYPTO_CIPHER_3DES_CBC:
1871 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
1872 cipherdata.algmode = OP_ALG_AAI_CBC;
1873 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
1874 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
1875 SHR_NEVER, &cipherdata,
1879 case RTE_CRYPTO_CIPHER_DES_CBC:
1880 cipherdata.algtype = OP_ALG_ALGSEL_DES;
1881 cipherdata.algmode = OP_ALG_AAI_CBC;
1882 session->cipher_alg = RTE_CRYPTO_CIPHER_DES_CBC;
1883 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
1884 SHR_NEVER, &cipherdata,
1888 case RTE_CRYPTO_CIPHER_AES_CTR:
1889 cipherdata.algtype = OP_ALG_ALGSEL_AES;
1890 cipherdata.algmode = OP_ALG_AAI_CTR;
1891 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
1892 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
1893 SHR_NEVER, &cipherdata,
1897 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
1898 cipherdata.algtype = OP_ALG_ALGSEL_SNOW_F8;
1899 session->cipher_alg = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1900 bufsize = cnstr_shdsc_snow_f8(priv->flc_desc[0].desc, 1, 0,
1904 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
1905 cipherdata.algtype = OP_ALG_ALGSEL_ZUCE;
1906 session->cipher_alg = RTE_CRYPTO_CIPHER_ZUC_EEA3;
1907 bufsize = cnstr_shdsc_zuce(priv->flc_desc[0].desc, 1, 0,
1911 case RTE_CRYPTO_CIPHER_KASUMI_F8:
1912 case RTE_CRYPTO_CIPHER_AES_F8:
1913 case RTE_CRYPTO_CIPHER_AES_ECB:
1914 case RTE_CRYPTO_CIPHER_3DES_ECB:
1915 case RTE_CRYPTO_CIPHER_3DES_CTR:
1916 case RTE_CRYPTO_CIPHER_AES_XTS:
1917 case RTE_CRYPTO_CIPHER_ARC4:
1918 case RTE_CRYPTO_CIPHER_NULL:
1919 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
1920 xform->cipher.algo);
1924 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
1925 xform->cipher.algo);
1931 DPAA2_SEC_ERR("Crypto: Descriptor build failed");
1936 flc->word1_sdl = (uint8_t)bufsize;
1937 session->ctxt = priv;
1939 #ifdef CAAM_DESC_DEBUG
1941 for (i = 0; i < bufsize; i++)
1942 DPAA2_SEC_DEBUG("DESC[%d]:0x%x", i, priv->flc_desc[0].desc[i]);
1947 rte_free(session->cipher_key.data);
1953 dpaa2_sec_auth_init(struct rte_cryptodev *dev,
1954 struct rte_crypto_sym_xform *xform,
1955 dpaa2_sec_session *session)
1957 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
1958 struct alginfo authdata;
1959 int bufsize, ret = 0;
1960 struct ctxt_priv *priv;
1961 struct sec_flow_context *flc;
1963 PMD_INIT_FUNC_TRACE();
1965 /* For SEC AUTH three descriptors are required for various stages */
1966 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
1967 sizeof(struct ctxt_priv) + 3 *
1968 sizeof(struct sec_flc_desc),
1969 RTE_CACHE_LINE_SIZE);
1971 DPAA2_SEC_ERR("No Memory for priv CTXT");
1975 priv->fle_pool = dev_priv->fle_pool;
1976 flc = &priv->flc_desc[DESC_INITFINAL].flc;
1978 session->ctxt_type = DPAA2_SEC_AUTH;
1979 session->auth_key.length = xform->auth.key.length;
1980 if (xform->auth.key.length) {
1981 session->auth_key.data = rte_zmalloc(NULL,
1982 xform->auth.key.length,
1983 RTE_CACHE_LINE_SIZE);
1984 if (session->auth_key.data == NULL) {
1985 DPAA2_SEC_ERR("Unable to allocate memory for auth key");
1989 memcpy(session->auth_key.data, xform->auth.key.data,
1990 xform->auth.key.length);
1991 authdata.key = (size_t)session->auth_key.data;
1992 authdata.key_enc_flags = 0;
1993 authdata.key_type = RTA_DATA_IMM;
1995 authdata.keylen = session->auth_key.length;
1997 session->digest_length = xform->auth.digest_length;
1998 session->dir = (xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE) ?
2001 switch (xform->auth.algo) {
2002 case RTE_CRYPTO_AUTH_SHA1_HMAC:
2003 authdata.algtype = OP_ALG_ALGSEL_SHA1;
2004 authdata.algmode = OP_ALG_AAI_HMAC;
2005 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
2006 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2007 1, 0, SHR_NEVER, &authdata,
2009 session->digest_length);
2011 case RTE_CRYPTO_AUTH_MD5_HMAC:
2012 authdata.algtype = OP_ALG_ALGSEL_MD5;
2013 authdata.algmode = OP_ALG_AAI_HMAC;
2014 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
2015 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2016 1, 0, SHR_NEVER, &authdata,
2018 session->digest_length);
2020 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2021 authdata.algtype = OP_ALG_ALGSEL_SHA256;
2022 authdata.algmode = OP_ALG_AAI_HMAC;
2023 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
2024 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2025 1, 0, SHR_NEVER, &authdata,
2027 session->digest_length);
2029 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2030 authdata.algtype = OP_ALG_ALGSEL_SHA384;
2031 authdata.algmode = OP_ALG_AAI_HMAC;
2032 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
2033 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2034 1, 0, SHR_NEVER, &authdata,
2036 session->digest_length);
2038 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2039 authdata.algtype = OP_ALG_ALGSEL_SHA512;
2040 authdata.algmode = OP_ALG_AAI_HMAC;
2041 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
2042 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2043 1, 0, SHR_NEVER, &authdata,
2045 session->digest_length);
2047 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2048 authdata.algtype = OP_ALG_ALGSEL_SHA224;
2049 authdata.algmode = OP_ALG_AAI_HMAC;
2050 session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
2051 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2052 1, 0, SHR_NEVER, &authdata,
2054 session->digest_length);
2056 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2057 authdata.algtype = OP_ALG_ALGSEL_SNOW_F9;
2058 authdata.algmode = OP_ALG_AAI_F9;
2059 session->auth_alg = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2060 session->iv.offset = xform->auth.iv.offset;
2061 session->iv.length = xform->auth.iv.length;
2062 bufsize = cnstr_shdsc_snow_f9(priv->flc_desc[DESC_INITFINAL].desc,
2065 session->digest_length);
2067 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2068 authdata.algtype = OP_ALG_ALGSEL_ZUCA;
2069 authdata.algmode = OP_ALG_AAI_F9;
2070 session->auth_alg = RTE_CRYPTO_AUTH_ZUC_EIA3;
2071 session->iv.offset = xform->auth.iv.offset;
2072 session->iv.length = xform->auth.iv.length;
2073 bufsize = cnstr_shdsc_zuca(priv->flc_desc[DESC_INITFINAL].desc,
2076 session->digest_length);
2078 case RTE_CRYPTO_AUTH_SHA1:
2079 authdata.algtype = OP_ALG_ALGSEL_SHA1;
2080 authdata.algmode = OP_ALG_AAI_HASH;
2081 session->auth_alg = RTE_CRYPTO_AUTH_SHA1;
2082 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2083 1, 0, SHR_NEVER, &authdata,
2085 session->digest_length);
2087 case RTE_CRYPTO_AUTH_MD5:
2088 authdata.algtype = OP_ALG_ALGSEL_MD5;
2089 authdata.algmode = OP_ALG_AAI_HASH;
2090 session->auth_alg = RTE_CRYPTO_AUTH_MD5;
2091 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2092 1, 0, SHR_NEVER, &authdata,
2094 session->digest_length);
2096 case RTE_CRYPTO_AUTH_SHA256:
2097 authdata.algtype = OP_ALG_ALGSEL_SHA256;
2098 authdata.algmode = OP_ALG_AAI_HASH;
2099 session->auth_alg = RTE_CRYPTO_AUTH_SHA256;
2100 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2101 1, 0, SHR_NEVER, &authdata,
2103 session->digest_length);
2105 case RTE_CRYPTO_AUTH_SHA384:
2106 authdata.algtype = OP_ALG_ALGSEL_SHA384;
2107 authdata.algmode = OP_ALG_AAI_HASH;
2108 session->auth_alg = RTE_CRYPTO_AUTH_SHA384;
2109 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2110 1, 0, SHR_NEVER, &authdata,
2112 session->digest_length);
2114 case RTE_CRYPTO_AUTH_SHA512:
2115 authdata.algtype = OP_ALG_ALGSEL_SHA512;
2116 authdata.algmode = OP_ALG_AAI_HASH;
2117 session->auth_alg = RTE_CRYPTO_AUTH_SHA512;
2118 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2119 1, 0, SHR_NEVER, &authdata,
2121 session->digest_length);
2123 case RTE_CRYPTO_AUTH_SHA224:
2124 authdata.algtype = OP_ALG_ALGSEL_SHA224;
2125 authdata.algmode = OP_ALG_AAI_HASH;
2126 session->auth_alg = RTE_CRYPTO_AUTH_SHA224;
2127 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2128 1, 0, SHR_NEVER, &authdata,
2130 session->digest_length);
2132 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2133 authdata.algtype = OP_ALG_ALGSEL_AES;
2134 authdata.algmode = OP_ALG_AAI_XCBC_MAC;
2135 session->auth_alg = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
2136 bufsize = cnstr_shdsc_aes_mac(
2137 priv->flc_desc[DESC_INITFINAL].desc,
2138 1, 0, SHR_NEVER, &authdata,
2140 session->digest_length);
2142 case RTE_CRYPTO_AUTH_AES_CMAC:
2143 authdata.algtype = OP_ALG_ALGSEL_AES;
2144 authdata.algmode = OP_ALG_AAI_CMAC;
2145 session->auth_alg = RTE_CRYPTO_AUTH_AES_CMAC;
2146 bufsize = cnstr_shdsc_aes_mac(
2147 priv->flc_desc[DESC_INITFINAL].desc,
2148 1, 0, SHR_NEVER, &authdata,
2150 session->digest_length);
2152 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2153 case RTE_CRYPTO_AUTH_AES_GMAC:
2154 case RTE_CRYPTO_AUTH_KASUMI_F9:
2155 case RTE_CRYPTO_AUTH_NULL:
2156 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %un",
2161 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2168 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2173 flc->word1_sdl = (uint8_t)bufsize;
2174 session->ctxt = priv;
2175 #ifdef CAAM_DESC_DEBUG
2177 for (i = 0; i < bufsize; i++)
2178 DPAA2_SEC_DEBUG("DESC[%d]:0x%x",
2179 i, priv->flc_desc[DESC_INITFINAL].desc[i]);
2185 rte_free(session->auth_key.data);
2191 dpaa2_sec_aead_init(struct rte_cryptodev *dev,
2192 struct rte_crypto_sym_xform *xform,
2193 dpaa2_sec_session *session)
2195 struct dpaa2_sec_aead_ctxt *ctxt = &session->ext_params.aead_ctxt;
2196 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2197 struct alginfo aeaddata;
2199 struct ctxt_priv *priv;
2200 struct sec_flow_context *flc;
2201 struct rte_crypto_aead_xform *aead_xform = &xform->aead;
2204 PMD_INIT_FUNC_TRACE();
2206 /* Set IV parameters */
2207 session->iv.offset = aead_xform->iv.offset;
2208 session->iv.length = aead_xform->iv.length;
2209 session->ctxt_type = DPAA2_SEC_AEAD;
2211 /* For SEC AEAD only one descriptor is required */
2212 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2213 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
2214 RTE_CACHE_LINE_SIZE);
2216 DPAA2_SEC_ERR("No Memory for priv CTXT");
2220 priv->fle_pool = dev_priv->fle_pool;
2221 flc = &priv->flc_desc[0].flc;
2223 session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length,
2224 RTE_CACHE_LINE_SIZE);
2225 if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
2226 DPAA2_SEC_ERR("No Memory for aead key");
2230 memcpy(session->aead_key.data, aead_xform->key.data,
2231 aead_xform->key.length);
2233 session->digest_length = aead_xform->digest_length;
2234 session->aead_key.length = aead_xform->key.length;
2235 ctxt->auth_only_len = aead_xform->aad_length;
2237 aeaddata.key = (size_t)session->aead_key.data;
2238 aeaddata.keylen = session->aead_key.length;
2239 aeaddata.key_enc_flags = 0;
2240 aeaddata.key_type = RTA_DATA_IMM;
2242 switch (aead_xform->algo) {
2243 case RTE_CRYPTO_AEAD_AES_GCM:
2244 aeaddata.algtype = OP_ALG_ALGSEL_AES;
2245 aeaddata.algmode = OP_ALG_AAI_GCM;
2246 session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM;
2248 case RTE_CRYPTO_AEAD_AES_CCM:
2249 DPAA2_SEC_ERR("Crypto: Unsupported AEAD alg %u",
2254 DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
2259 session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
2262 priv->flc_desc[0].desc[0] = aeaddata.keylen;
2263 err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
2265 (unsigned int *)priv->flc_desc[0].desc,
2266 &priv->flc_desc[0].desc[1], 1);
2269 DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
2273 if (priv->flc_desc[0].desc[1] & 1) {
2274 aeaddata.key_type = RTA_DATA_IMM;
2276 aeaddata.key = DPAA2_VADDR_TO_IOVA(aeaddata.key);
2277 aeaddata.key_type = RTA_DATA_PTR;
2279 priv->flc_desc[0].desc[0] = 0;
2280 priv->flc_desc[0].desc[1] = 0;
2282 if (session->dir == DIR_ENC)
2283 bufsize = cnstr_shdsc_gcm_encap(
2284 priv->flc_desc[0].desc, 1, 0, SHR_NEVER,
2285 &aeaddata, session->iv.length,
2286 session->digest_length);
2288 bufsize = cnstr_shdsc_gcm_decap(
2289 priv->flc_desc[0].desc, 1, 0, SHR_NEVER,
2290 &aeaddata, session->iv.length,
2291 session->digest_length);
2293 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2298 flc->word1_sdl = (uint8_t)bufsize;
2299 session->ctxt = priv;
2300 #ifdef CAAM_DESC_DEBUG
2302 for (i = 0; i < bufsize; i++)
2303 DPAA2_SEC_DEBUG("DESC[%d]:0x%x\n",
2304 i, priv->flc_desc[0].desc[i]);
2309 rte_free(session->aead_key.data);
2316 dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
2317 struct rte_crypto_sym_xform *xform,
2318 dpaa2_sec_session *session)
2320 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2321 struct alginfo authdata, cipherdata;
2323 struct ctxt_priv *priv;
2324 struct sec_flow_context *flc;
2325 struct rte_crypto_cipher_xform *cipher_xform;
2326 struct rte_crypto_auth_xform *auth_xform;
2329 PMD_INIT_FUNC_TRACE();
2331 if (session->ext_params.aead_ctxt.auth_cipher_text) {
2332 cipher_xform = &xform->cipher;
2333 auth_xform = &xform->next->auth;
2334 session->ctxt_type =
2335 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2336 DPAA2_SEC_CIPHER_HASH : DPAA2_SEC_HASH_CIPHER;
2338 cipher_xform = &xform->next->cipher;
2339 auth_xform = &xform->auth;
2340 session->ctxt_type =
2341 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2342 DPAA2_SEC_HASH_CIPHER : DPAA2_SEC_CIPHER_HASH;
2345 /* Set IV parameters */
2346 session->iv.offset = cipher_xform->iv.offset;
2347 session->iv.length = cipher_xform->iv.length;
2349 /* For SEC AEAD only one descriptor is required */
2350 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2351 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
2352 RTE_CACHE_LINE_SIZE);
2354 DPAA2_SEC_ERR("No Memory for priv CTXT");
2358 priv->fle_pool = dev_priv->fle_pool;
2359 flc = &priv->flc_desc[0].flc;
2361 session->cipher_key.data = rte_zmalloc(NULL, cipher_xform->key.length,
2362 RTE_CACHE_LINE_SIZE);
2363 if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) {
2364 DPAA2_SEC_ERR("No Memory for cipher key");
2368 session->cipher_key.length = cipher_xform->key.length;
2369 session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length,
2370 RTE_CACHE_LINE_SIZE);
2371 if (session->auth_key.data == NULL && auth_xform->key.length > 0) {
2372 DPAA2_SEC_ERR("No Memory for auth key");
2373 rte_free(session->cipher_key.data);
2377 session->auth_key.length = auth_xform->key.length;
2378 memcpy(session->cipher_key.data, cipher_xform->key.data,
2379 cipher_xform->key.length);
2380 memcpy(session->auth_key.data, auth_xform->key.data,
2381 auth_xform->key.length);
2383 authdata.key = (size_t)session->auth_key.data;
2384 authdata.keylen = session->auth_key.length;
2385 authdata.key_enc_flags = 0;
2386 authdata.key_type = RTA_DATA_IMM;
2388 session->digest_length = auth_xform->digest_length;
2390 switch (auth_xform->algo) {
2391 case RTE_CRYPTO_AUTH_SHA1_HMAC:
2392 authdata.algtype = OP_ALG_ALGSEL_SHA1;
2393 authdata.algmode = OP_ALG_AAI_HMAC;
2394 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
2396 case RTE_CRYPTO_AUTH_MD5_HMAC:
2397 authdata.algtype = OP_ALG_ALGSEL_MD5;
2398 authdata.algmode = OP_ALG_AAI_HMAC;
2399 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
2401 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2402 authdata.algtype = OP_ALG_ALGSEL_SHA224;
2403 authdata.algmode = OP_ALG_AAI_HMAC;
2404 session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
2406 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2407 authdata.algtype = OP_ALG_ALGSEL_SHA256;
2408 authdata.algmode = OP_ALG_AAI_HMAC;
2409 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
2411 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2412 authdata.algtype = OP_ALG_ALGSEL_SHA384;
2413 authdata.algmode = OP_ALG_AAI_HMAC;
2414 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
2416 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2417 authdata.algtype = OP_ALG_ALGSEL_SHA512;
2418 authdata.algmode = OP_ALG_AAI_HMAC;
2419 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
2421 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2422 authdata.algtype = OP_ALG_ALGSEL_AES;
2423 authdata.algmode = OP_ALG_AAI_XCBC_MAC;
2424 session->auth_alg = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
2426 case RTE_CRYPTO_AUTH_AES_CMAC:
2427 authdata.algtype = OP_ALG_ALGSEL_AES;
2428 authdata.algmode = OP_ALG_AAI_CMAC;
2429 session->auth_alg = RTE_CRYPTO_AUTH_AES_CMAC;
2431 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2432 case RTE_CRYPTO_AUTH_AES_GMAC:
2433 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2434 case RTE_CRYPTO_AUTH_NULL:
2435 case RTE_CRYPTO_AUTH_SHA1:
2436 case RTE_CRYPTO_AUTH_SHA256:
2437 case RTE_CRYPTO_AUTH_SHA512:
2438 case RTE_CRYPTO_AUTH_SHA224:
2439 case RTE_CRYPTO_AUTH_SHA384:
2440 case RTE_CRYPTO_AUTH_MD5:
2441 case RTE_CRYPTO_AUTH_KASUMI_F9:
2442 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2443 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
2448 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2453 cipherdata.key = (size_t)session->cipher_key.data;
2454 cipherdata.keylen = session->cipher_key.length;
2455 cipherdata.key_enc_flags = 0;
2456 cipherdata.key_type = RTA_DATA_IMM;
2458 switch (cipher_xform->algo) {
2459 case RTE_CRYPTO_CIPHER_AES_CBC:
2460 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2461 cipherdata.algmode = OP_ALG_AAI_CBC;
2462 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
2464 case RTE_CRYPTO_CIPHER_3DES_CBC:
2465 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
2466 cipherdata.algmode = OP_ALG_AAI_CBC;
2467 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
2469 case RTE_CRYPTO_CIPHER_DES_CBC:
2470 cipherdata.algtype = OP_ALG_ALGSEL_DES;
2471 cipherdata.algmode = OP_ALG_AAI_CBC;
2472 session->cipher_alg = RTE_CRYPTO_CIPHER_DES_CBC;
2474 case RTE_CRYPTO_CIPHER_AES_CTR:
2475 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2476 cipherdata.algmode = OP_ALG_AAI_CTR;
2477 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
2479 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2480 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
2481 case RTE_CRYPTO_CIPHER_NULL:
2482 case RTE_CRYPTO_CIPHER_3DES_ECB:
2483 case RTE_CRYPTO_CIPHER_3DES_CTR:
2484 case RTE_CRYPTO_CIPHER_AES_ECB:
2485 case RTE_CRYPTO_CIPHER_KASUMI_F8:
2486 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
2487 cipher_xform->algo);
2491 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2492 cipher_xform->algo);
2496 session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2499 priv->flc_desc[0].desc[0] = cipherdata.keylen;
2500 priv->flc_desc[0].desc[1] = authdata.keylen;
2501 err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
2503 (unsigned int *)priv->flc_desc[0].desc,
2504 &priv->flc_desc[0].desc[2], 2);
2507 DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
2511 if (priv->flc_desc[0].desc[2] & 1) {
2512 cipherdata.key_type = RTA_DATA_IMM;
2514 cipherdata.key = DPAA2_VADDR_TO_IOVA(cipherdata.key);
2515 cipherdata.key_type = RTA_DATA_PTR;
2517 if (priv->flc_desc[0].desc[2] & (1 << 1)) {
2518 authdata.key_type = RTA_DATA_IMM;
2520 authdata.key = DPAA2_VADDR_TO_IOVA(authdata.key);
2521 authdata.key_type = RTA_DATA_PTR;
2523 priv->flc_desc[0].desc[0] = 0;
2524 priv->flc_desc[0].desc[1] = 0;
2525 priv->flc_desc[0].desc[2] = 0;
2527 if (session->ctxt_type == DPAA2_SEC_CIPHER_HASH) {
2528 bufsize = cnstr_shdsc_authenc(priv->flc_desc[0].desc, 1,
2530 &cipherdata, &authdata,
2532 session->digest_length,
2535 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2540 DPAA2_SEC_ERR("Hash before cipher not supported");
2545 flc->word1_sdl = (uint8_t)bufsize;
2546 session->ctxt = priv;
2547 #ifdef CAAM_DESC_DEBUG
2549 for (i = 0; i < bufsize; i++)
2550 DPAA2_SEC_DEBUG("DESC[%d]:0x%x",
2551 i, priv->flc_desc[0].desc[i]);
2557 rte_free(session->cipher_key.data);
2558 rte_free(session->auth_key.data);
2564 dpaa2_sec_set_session_parameters(struct rte_cryptodev *dev,
2565 struct rte_crypto_sym_xform *xform, void *sess)
2567 dpaa2_sec_session *session = sess;
2570 PMD_INIT_FUNC_TRACE();
2572 if (unlikely(sess == NULL)) {
2573 DPAA2_SEC_ERR("Invalid session struct");
2577 memset(session, 0, sizeof(dpaa2_sec_session));
2578 /* Default IV length = 0 */
2579 session->iv.length = 0;
2582 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
2583 ret = dpaa2_sec_cipher_init(dev, xform, session);
2585 /* Authentication Only */
2586 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2587 xform->next == NULL) {
2588 ret = dpaa2_sec_auth_init(dev, xform, session);
2590 /* Cipher then Authenticate */
2591 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
2592 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2593 session->ext_params.aead_ctxt.auth_cipher_text = true;
2594 if (xform->cipher.algo == RTE_CRYPTO_CIPHER_NULL)
2595 ret = dpaa2_sec_auth_init(dev, xform, session);
2596 else if (xform->next->auth.algo == RTE_CRYPTO_AUTH_NULL)
2597 ret = dpaa2_sec_cipher_init(dev, xform, session);
2599 ret = dpaa2_sec_aead_chain_init(dev, xform, session);
2600 /* Authenticate then Cipher */
2601 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2602 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2603 session->ext_params.aead_ctxt.auth_cipher_text = false;
2604 if (xform->auth.algo == RTE_CRYPTO_AUTH_NULL)
2605 ret = dpaa2_sec_cipher_init(dev, xform, session);
2606 else if (xform->next->cipher.algo == RTE_CRYPTO_CIPHER_NULL)
2607 ret = dpaa2_sec_auth_init(dev, xform, session);
2609 ret = dpaa2_sec_aead_chain_init(dev, xform, session);
2610 /* AEAD operation for AES-GCM kind of Algorithms */
2611 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD &&
2612 xform->next == NULL) {
2613 ret = dpaa2_sec_aead_init(dev, xform, session);
2616 DPAA2_SEC_ERR("Invalid crypto type");
2623 #ifdef RTE_LIB_SECURITY
2625 dpaa2_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
2626 dpaa2_sec_session *session,
2627 struct alginfo *aeaddata)
2629 PMD_INIT_FUNC_TRACE();
2631 session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length,
2632 RTE_CACHE_LINE_SIZE);
2633 if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
2634 DPAA2_SEC_ERR("No Memory for aead key");
2637 memcpy(session->aead_key.data, aead_xform->key.data,
2638 aead_xform->key.length);
2640 session->digest_length = aead_xform->digest_length;
2641 session->aead_key.length = aead_xform->key.length;
2643 aeaddata->key = (size_t)session->aead_key.data;
2644 aeaddata->keylen = session->aead_key.length;
2645 aeaddata->key_enc_flags = 0;
2646 aeaddata->key_type = RTA_DATA_IMM;
2648 switch (aead_xform->algo) {
2649 case RTE_CRYPTO_AEAD_AES_GCM:
2650 switch (session->digest_length) {
2652 aeaddata->algtype = OP_PCL_IPSEC_AES_GCM8;
2655 aeaddata->algtype = OP_PCL_IPSEC_AES_GCM12;
2658 aeaddata->algtype = OP_PCL_IPSEC_AES_GCM16;
2661 DPAA2_SEC_ERR("Crypto: Undefined GCM digest %d",
2662 session->digest_length);
2665 aeaddata->algmode = OP_ALG_AAI_GCM;
2666 session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM;
2668 case RTE_CRYPTO_AEAD_AES_CCM:
2669 switch (session->digest_length) {
2671 aeaddata->algtype = OP_PCL_IPSEC_AES_CCM8;
2674 aeaddata->algtype = OP_PCL_IPSEC_AES_CCM12;
2677 aeaddata->algtype = OP_PCL_IPSEC_AES_CCM16;
2680 DPAA2_SEC_ERR("Crypto: Undefined CCM digest %d",
2681 session->digest_length);
2684 aeaddata->algmode = OP_ALG_AAI_CCM;
2685 session->aead_alg = RTE_CRYPTO_AEAD_AES_CCM;
2688 DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
2692 session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
2699 dpaa2_sec_ipsec_proto_init(struct rte_crypto_cipher_xform *cipher_xform,
2700 struct rte_crypto_auth_xform *auth_xform,
2701 dpaa2_sec_session *session,
2702 struct alginfo *cipherdata,
2703 struct alginfo *authdata)
2706 session->cipher_key.data = rte_zmalloc(NULL,
2707 cipher_xform->key.length,
2708 RTE_CACHE_LINE_SIZE);
2709 if (session->cipher_key.data == NULL &&
2710 cipher_xform->key.length > 0) {
2711 DPAA2_SEC_ERR("No Memory for cipher key");
2715 session->cipher_key.length = cipher_xform->key.length;
2716 memcpy(session->cipher_key.data, cipher_xform->key.data,
2717 cipher_xform->key.length);
2718 session->cipher_alg = cipher_xform->algo;
2720 session->cipher_key.data = NULL;
2721 session->cipher_key.length = 0;
2722 session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
2726 session->auth_key.data = rte_zmalloc(NULL,
2727 auth_xform->key.length,
2728 RTE_CACHE_LINE_SIZE);
2729 if (session->auth_key.data == NULL &&
2730 auth_xform->key.length > 0) {
2731 DPAA2_SEC_ERR("No Memory for auth key");
2734 session->auth_key.length = auth_xform->key.length;
2735 memcpy(session->auth_key.data, auth_xform->key.data,
2736 auth_xform->key.length);
2737 session->auth_alg = auth_xform->algo;
2738 session->digest_length = auth_xform->digest_length;
2740 session->auth_key.data = NULL;
2741 session->auth_key.length = 0;
2742 session->auth_alg = RTE_CRYPTO_AUTH_NULL;
2745 authdata->key = (size_t)session->auth_key.data;
2746 authdata->keylen = session->auth_key.length;
2747 authdata->key_enc_flags = 0;
2748 authdata->key_type = RTA_DATA_IMM;
2749 switch (session->auth_alg) {
2750 case RTE_CRYPTO_AUTH_SHA1_HMAC:
2751 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA1_96;
2752 authdata->algmode = OP_ALG_AAI_HMAC;
2754 case RTE_CRYPTO_AUTH_MD5_HMAC:
2755 authdata->algtype = OP_PCL_IPSEC_HMAC_MD5_96;
2756 authdata->algmode = OP_ALG_AAI_HMAC;
2758 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2759 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_256_128;
2760 authdata->algmode = OP_ALG_AAI_HMAC;
2761 if (session->digest_length != 16)
2763 "+++Using sha256-hmac truncated len is non-standard,"
2764 "it will not work with lookaside proto");
2766 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2767 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_384_192;
2768 authdata->algmode = OP_ALG_AAI_HMAC;
2770 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2771 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_512_256;
2772 authdata->algmode = OP_ALG_AAI_HMAC;
2774 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2775 authdata->algtype = OP_PCL_IPSEC_AES_XCBC_MAC_96;
2776 authdata->algmode = OP_ALG_AAI_XCBC_MAC;
2778 case RTE_CRYPTO_AUTH_AES_CMAC:
2779 authdata->algtype = OP_PCL_IPSEC_AES_CMAC_96;
2780 authdata->algmode = OP_ALG_AAI_CMAC;
2782 case RTE_CRYPTO_AUTH_NULL:
2783 authdata->algtype = OP_PCL_IPSEC_HMAC_NULL;
2785 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2786 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2787 case RTE_CRYPTO_AUTH_SHA1:
2788 case RTE_CRYPTO_AUTH_SHA256:
2789 case RTE_CRYPTO_AUTH_SHA512:
2790 case RTE_CRYPTO_AUTH_SHA224:
2791 case RTE_CRYPTO_AUTH_SHA384:
2792 case RTE_CRYPTO_AUTH_MD5:
2793 case RTE_CRYPTO_AUTH_AES_GMAC:
2794 case RTE_CRYPTO_AUTH_KASUMI_F9:
2795 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2796 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2797 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
2801 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2805 cipherdata->key = (size_t)session->cipher_key.data;
2806 cipherdata->keylen = session->cipher_key.length;
2807 cipherdata->key_enc_flags = 0;
2808 cipherdata->key_type = RTA_DATA_IMM;
2810 switch (session->cipher_alg) {
2811 case RTE_CRYPTO_CIPHER_AES_CBC:
2812 cipherdata->algtype = OP_PCL_IPSEC_AES_CBC;
2813 cipherdata->algmode = OP_ALG_AAI_CBC;
2815 case RTE_CRYPTO_CIPHER_3DES_CBC:
2816 cipherdata->algtype = OP_PCL_IPSEC_3DES;
2817 cipherdata->algmode = OP_ALG_AAI_CBC;
2819 case RTE_CRYPTO_CIPHER_DES_CBC:
2820 cipherdata->algtype = OP_PCL_IPSEC_DES;
2821 cipherdata->algmode = OP_ALG_AAI_CBC;
2823 case RTE_CRYPTO_CIPHER_AES_CTR:
2824 cipherdata->algtype = OP_PCL_IPSEC_AES_CTR;
2825 cipherdata->algmode = OP_ALG_AAI_CTR;
2827 case RTE_CRYPTO_CIPHER_NULL:
2828 cipherdata->algtype = OP_PCL_IPSEC_NULL;
2830 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2831 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
2832 case RTE_CRYPTO_CIPHER_3DES_ECB:
2833 case RTE_CRYPTO_CIPHER_3DES_CTR:
2834 case RTE_CRYPTO_CIPHER_AES_ECB:
2835 case RTE_CRYPTO_CIPHER_KASUMI_F8:
2836 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
2837 session->cipher_alg);
2840 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2841 session->cipher_alg);
2849 dpaa2_sec_set_ipsec_session(struct rte_cryptodev *dev,
2850 struct rte_security_session_conf *conf,
2853 struct rte_security_ipsec_xform *ipsec_xform = &conf->ipsec;
2854 struct rte_crypto_cipher_xform *cipher_xform = NULL;
2855 struct rte_crypto_auth_xform *auth_xform = NULL;
2856 struct rte_crypto_aead_xform *aead_xform = NULL;
2857 dpaa2_sec_session *session = (dpaa2_sec_session *)sess;
2858 struct ctxt_priv *priv;
2859 struct alginfo authdata, cipherdata;
2861 struct sec_flow_context *flc;
2862 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2865 PMD_INIT_FUNC_TRACE();
2867 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2868 sizeof(struct ctxt_priv) +
2869 sizeof(struct sec_flc_desc),
2870 RTE_CACHE_LINE_SIZE);
2873 DPAA2_SEC_ERR("No memory for priv CTXT");
2877 priv->fle_pool = dev_priv->fle_pool;
2878 flc = &priv->flc_desc[0].flc;
2880 if (ipsec_xform->life.bytes_hard_limit != 0 ||
2881 ipsec_xform->life.bytes_soft_limit != 0 ||
2882 ipsec_xform->life.packets_hard_limit != 0 ||
2883 ipsec_xform->life.packets_soft_limit != 0)
2886 memset(session, 0, sizeof(dpaa2_sec_session));
2888 if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2889 cipher_xform = &conf->crypto_xform->cipher;
2890 if (conf->crypto_xform->next)
2891 auth_xform = &conf->crypto_xform->next->auth;
2892 ret = dpaa2_sec_ipsec_proto_init(cipher_xform, auth_xform,
2893 session, &cipherdata, &authdata);
2894 } else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2895 auth_xform = &conf->crypto_xform->auth;
2896 if (conf->crypto_xform->next)
2897 cipher_xform = &conf->crypto_xform->next->cipher;
2898 ret = dpaa2_sec_ipsec_proto_init(cipher_xform, auth_xform,
2899 session, &cipherdata, &authdata);
2900 } else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
2901 aead_xform = &conf->crypto_xform->aead;
2902 ret = dpaa2_sec_ipsec_aead_init(aead_xform,
2903 session, &cipherdata);
2904 authdata.keylen = 0;
2905 authdata.algtype = 0;
2907 DPAA2_SEC_ERR("XFORM not specified");
2912 DPAA2_SEC_ERR("Failed to process xform");
2916 session->ctxt_type = DPAA2_SEC_IPSEC;
2917 if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
2918 uint8_t *hdr = NULL;
2920 struct rte_ipv6_hdr ip6_hdr;
2921 struct ipsec_encap_pdb encap_pdb;
2923 flc->dhr = SEC_FLC_DHR_OUTBOUND;
2924 /* For Sec Proto only one descriptor is required. */
2925 memset(&encap_pdb, 0, sizeof(struct ipsec_encap_pdb));
2927 /* copy algo specific data to PDB */
2928 switch (cipherdata.algtype) {
2929 case OP_PCL_IPSEC_AES_CTR:
2930 encap_pdb.ctr.ctr_initial = 0x00000001;
2931 encap_pdb.ctr.ctr_nonce = ipsec_xform->salt;
2933 case OP_PCL_IPSEC_AES_GCM8:
2934 case OP_PCL_IPSEC_AES_GCM12:
2935 case OP_PCL_IPSEC_AES_GCM16:
2936 memcpy(encap_pdb.gcm.salt,
2937 (uint8_t *)&(ipsec_xform->salt), 4);
2941 encap_pdb.options = (IPVERSION << PDBNH_ESP_ENCAP_SHIFT) |
2942 PDBOPTS_ESP_OIHI_PDB_INL |
2945 if (ipsec_xform->options.dec_ttl)
2946 encap_pdb.options |= PDBHMO_ESP_ENCAP_DTTL;
2947 if (ipsec_xform->options.esn)
2948 encap_pdb.options |= PDBOPTS_ESP_ESN;
2949 encap_pdb.spi = ipsec_xform->spi;
2950 session->dir = DIR_ENC;
2951 if (ipsec_xform->tunnel.type ==
2952 RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
2953 encap_pdb.ip_hdr_len = sizeof(struct ip);
2954 ip4_hdr.ip_v = IPVERSION;
2956 ip4_hdr.ip_len = rte_cpu_to_be_16(sizeof(ip4_hdr));
2957 ip4_hdr.ip_tos = ipsec_xform->tunnel.ipv4.dscp;
2960 ip4_hdr.ip_ttl = ipsec_xform->tunnel.ipv4.ttl;
2961 ip4_hdr.ip_p = IPPROTO_ESP;
2963 ip4_hdr.ip_src = ipsec_xform->tunnel.ipv4.src_ip;
2964 ip4_hdr.ip_dst = ipsec_xform->tunnel.ipv4.dst_ip;
2965 ip4_hdr.ip_sum = calc_chksum((uint16_t *)(void *)
2966 &ip4_hdr, sizeof(struct ip));
2967 hdr = (uint8_t *)&ip4_hdr;
2968 } else if (ipsec_xform->tunnel.type ==
2969 RTE_SECURITY_IPSEC_TUNNEL_IPV6) {
2970 ip6_hdr.vtc_flow = rte_cpu_to_be_32(
2971 DPAA2_IPv6_DEFAULT_VTC_FLOW |
2972 ((ipsec_xform->tunnel.ipv6.dscp <<
2973 RTE_IPV6_HDR_TC_SHIFT) &
2974 RTE_IPV6_HDR_TC_MASK) |
2975 ((ipsec_xform->tunnel.ipv6.flabel <<
2976 RTE_IPV6_HDR_FL_SHIFT) &
2977 RTE_IPV6_HDR_FL_MASK));
2978 /* Payload length will be updated by HW */
2979 ip6_hdr.payload_len = 0;
2980 ip6_hdr.hop_limits =
2981 ipsec_xform->tunnel.ipv6.hlimit;
2982 ip6_hdr.proto = (ipsec_xform->proto ==
2983 RTE_SECURITY_IPSEC_SA_PROTO_ESP) ?
2984 IPPROTO_ESP : IPPROTO_AH;
2985 memcpy(&ip6_hdr.src_addr,
2986 &ipsec_xform->tunnel.ipv6.src_addr, 16);
2987 memcpy(&ip6_hdr.dst_addr,
2988 &ipsec_xform->tunnel.ipv6.dst_addr, 16);
2989 encap_pdb.ip_hdr_len = sizeof(struct rte_ipv6_hdr);
2990 hdr = (uint8_t *)&ip6_hdr;
2993 bufsize = cnstr_shdsc_ipsec_new_encap(priv->flc_desc[0].desc,
2994 1, 0, (rta_sec_era >= RTA_SEC_ERA_10) ?
2995 SHR_WAIT : SHR_SERIAL, &encap_pdb,
2996 hdr, &cipherdata, &authdata);
2997 } else if (ipsec_xform->direction ==
2998 RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
2999 struct ipsec_decap_pdb decap_pdb;
3001 flc->dhr = SEC_FLC_DHR_INBOUND;
3002 memset(&decap_pdb, 0, sizeof(struct ipsec_decap_pdb));
3003 /* copy algo specific data to PDB */
3004 switch (cipherdata.algtype) {
3005 case OP_PCL_IPSEC_AES_CTR:
3006 decap_pdb.ctr.ctr_initial = 0x00000001;
3007 decap_pdb.ctr.ctr_nonce = ipsec_xform->salt;
3009 case OP_PCL_IPSEC_AES_GCM8:
3010 case OP_PCL_IPSEC_AES_GCM12:
3011 case OP_PCL_IPSEC_AES_GCM16:
3012 memcpy(decap_pdb.gcm.salt,
3013 (uint8_t *)&(ipsec_xform->salt), 4);
3017 decap_pdb.options = (ipsec_xform->tunnel.type ==
3018 RTE_SECURITY_IPSEC_TUNNEL_IPV4) ?
3019 sizeof(struct ip) << 16 :
3020 sizeof(struct rte_ipv6_hdr) << 16;
3021 if (ipsec_xform->options.esn)
3022 decap_pdb.options |= PDBOPTS_ESP_ESN;
3024 if (ipsec_xform->replay_win_sz) {
3026 win_sz = rte_align32pow2(ipsec_xform->replay_win_sz);
3028 if (rta_sec_era < RTA_SEC_ERA_10 && win_sz > 128) {
3029 DPAA2_SEC_INFO("Max Anti replay Win sz = 128");
3039 decap_pdb.options |= PDBOPTS_ESP_ARS32;
3042 decap_pdb.options |= PDBOPTS_ESP_ARS64;
3045 decap_pdb.options |= PDBOPTS_ESP_ARS256;
3048 decap_pdb.options |= PDBOPTS_ESP_ARS512;
3051 decap_pdb.options |= PDBOPTS_ESP_ARS1024;
3055 decap_pdb.options |= PDBOPTS_ESP_ARS128;
3058 session->dir = DIR_DEC;
3059 bufsize = cnstr_shdsc_ipsec_new_decap(priv->flc_desc[0].desc,
3060 1, 0, (rta_sec_era >= RTA_SEC_ERA_10) ?
3061 SHR_WAIT : SHR_SERIAL,
3062 &decap_pdb, &cipherdata, &authdata);
3067 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
3071 flc->word1_sdl = (uint8_t)bufsize;
3073 /* Enable the stashing control bit */
3074 DPAA2_SET_FLC_RSC(flc);
3075 flc->word2_rflc_31_0 = lower_32_bits(
3076 (size_t)&(((struct dpaa2_sec_qp *)
3077 dev->data->queue_pairs[0])->rx_vq) | 0x14);
3078 flc->word3_rflc_63_32 = upper_32_bits(
3079 (size_t)&(((struct dpaa2_sec_qp *)
3080 dev->data->queue_pairs[0])->rx_vq));
3082 /* Set EWS bit i.e. enable write-safe */
3083 DPAA2_SET_FLC_EWS(flc);
3084 /* Set BS = 1 i.e reuse input buffers as output buffers */
3085 DPAA2_SET_FLC_REUSE_BS(flc);
3086 /* Set FF = 10; reuse input buffers if they provide sufficient space */
3087 DPAA2_SET_FLC_REUSE_FF(flc);
3089 session->ctxt = priv;
3093 rte_free(session->auth_key.data);
3094 rte_free(session->cipher_key.data);
3100 dpaa2_sec_set_pdcp_session(struct rte_cryptodev *dev,
3101 struct rte_security_session_conf *conf,
3104 struct rte_security_pdcp_xform *pdcp_xform = &conf->pdcp;
3105 struct rte_crypto_sym_xform *xform = conf->crypto_xform;
3106 struct rte_crypto_auth_xform *auth_xform = NULL;
3107 struct rte_crypto_cipher_xform *cipher_xform = NULL;
3108 dpaa2_sec_session *session = (dpaa2_sec_session *)sess;
3109 struct ctxt_priv *priv;
3110 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
3111 struct alginfo authdata, cipherdata;
3112 struct alginfo *p_authdata = NULL;
3114 struct sec_flow_context *flc;
3115 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
3121 PMD_INIT_FUNC_TRACE();
3123 memset(session, 0, sizeof(dpaa2_sec_session));
3125 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
3126 sizeof(struct ctxt_priv) +
3127 sizeof(struct sec_flc_desc),
3128 RTE_CACHE_LINE_SIZE);
3131 DPAA2_SEC_ERR("No memory for priv CTXT");
3135 priv->fle_pool = dev_priv->fle_pool;
3136 flc = &priv->flc_desc[0].flc;
3138 /* find xfrm types */
3139 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
3140 cipher_xform = &xform->cipher;
3141 if (xform->next != NULL) {
3142 session->ext_params.aead_ctxt.auth_cipher_text = true;
3143 auth_xform = &xform->next->auth;
3145 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
3146 auth_xform = &xform->auth;
3147 if (xform->next != NULL) {
3148 session->ext_params.aead_ctxt.auth_cipher_text = false;
3149 cipher_xform = &xform->next->cipher;
3152 DPAA2_SEC_ERR("Invalid crypto type");
3156 session->ctxt_type = DPAA2_SEC_PDCP;
3158 session->cipher_key.data = rte_zmalloc(NULL,
3159 cipher_xform->key.length,
3160 RTE_CACHE_LINE_SIZE);
3161 if (session->cipher_key.data == NULL &&
3162 cipher_xform->key.length > 0) {
3163 DPAA2_SEC_ERR("No Memory for cipher key");
3167 session->cipher_key.length = cipher_xform->key.length;
3168 memcpy(session->cipher_key.data, cipher_xform->key.data,
3169 cipher_xform->key.length);
3171 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
3173 session->cipher_alg = cipher_xform->algo;
3175 session->cipher_key.data = NULL;
3176 session->cipher_key.length = 0;
3177 session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
3178 session->dir = DIR_ENC;
3181 session->pdcp.domain = pdcp_xform->domain;
3182 session->pdcp.bearer = pdcp_xform->bearer;
3183 session->pdcp.pkt_dir = pdcp_xform->pkt_dir;
3184 session->pdcp.sn_size = pdcp_xform->sn_size;
3185 session->pdcp.hfn = pdcp_xform->hfn;
3186 session->pdcp.hfn_threshold = pdcp_xform->hfn_threshold;
3187 session->pdcp.hfn_ovd = pdcp_xform->hfn_ovrd;
3188 /* hfv ovd offset location is stored in iv.offset value*/
3190 session->pdcp.hfn_ovd_offset = cipher_xform->iv.offset;
3192 cipherdata.key = (size_t)session->cipher_key.data;
3193 cipherdata.keylen = session->cipher_key.length;
3194 cipherdata.key_enc_flags = 0;
3195 cipherdata.key_type = RTA_DATA_IMM;
3197 switch (session->cipher_alg) {
3198 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
3199 cipherdata.algtype = PDCP_CIPHER_TYPE_SNOW;
3201 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
3202 cipherdata.algtype = PDCP_CIPHER_TYPE_ZUC;
3204 case RTE_CRYPTO_CIPHER_AES_CTR:
3205 cipherdata.algtype = PDCP_CIPHER_TYPE_AES;
3207 case RTE_CRYPTO_CIPHER_NULL:
3208 cipherdata.algtype = PDCP_CIPHER_TYPE_NULL;
3211 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
3212 session->cipher_alg);
3217 session->auth_key.data = rte_zmalloc(NULL,
3218 auth_xform->key.length,
3219 RTE_CACHE_LINE_SIZE);
3220 if (!session->auth_key.data &&
3221 auth_xform->key.length > 0) {
3222 DPAA2_SEC_ERR("No Memory for auth key");
3223 rte_free(session->cipher_key.data);
3227 session->auth_key.length = auth_xform->key.length;
3228 memcpy(session->auth_key.data, auth_xform->key.data,
3229 auth_xform->key.length);
3230 session->auth_alg = auth_xform->algo;
3232 session->auth_key.data = NULL;
3233 session->auth_key.length = 0;
3234 session->auth_alg = 0;
3236 authdata.key = (size_t)session->auth_key.data;
3237 authdata.keylen = session->auth_key.length;
3238 authdata.key_enc_flags = 0;
3239 authdata.key_type = RTA_DATA_IMM;
3241 if (session->auth_alg) {
3242 switch (session->auth_alg) {
3243 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
3244 authdata.algtype = PDCP_AUTH_TYPE_SNOW;
3246 case RTE_CRYPTO_AUTH_ZUC_EIA3:
3247 authdata.algtype = PDCP_AUTH_TYPE_ZUC;
3249 case RTE_CRYPTO_AUTH_AES_CMAC:
3250 authdata.algtype = PDCP_AUTH_TYPE_AES;
3252 case RTE_CRYPTO_AUTH_NULL:
3253 authdata.algtype = PDCP_AUTH_TYPE_NULL;
3256 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
3261 p_authdata = &authdata;
3262 } else if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
3263 DPAA2_SEC_ERR("Crypto: Integrity must for c-plane");
3267 if (pdcp_xform->sdap_enabled) {
3268 int nb_keys_to_inline =
3269 rta_inline_pdcp_sdap_query(authdata.algtype,
3271 session->pdcp.sn_size,
3272 session->pdcp.hfn_ovd);
3273 if (nb_keys_to_inline >= 1) {
3274 cipherdata.key = DPAA2_VADDR_TO_IOVA(cipherdata.key);
3275 cipherdata.key_type = RTA_DATA_PTR;
3277 if (nb_keys_to_inline >= 2) {
3278 authdata.key = DPAA2_VADDR_TO_IOVA(authdata.key);
3279 authdata.key_type = RTA_DATA_PTR;
3282 if (rta_inline_pdcp_query(authdata.algtype,
3284 session->pdcp.sn_size,
3285 session->pdcp.hfn_ovd)) {
3286 cipherdata.key = DPAA2_VADDR_TO_IOVA(cipherdata.key);
3287 cipherdata.key_type = RTA_DATA_PTR;
3291 if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
3292 if (session->dir == DIR_ENC)
3293 bufsize = cnstr_shdsc_pdcp_c_plane_encap(
3294 priv->flc_desc[0].desc, 1, swap,
3296 session->pdcp.sn_size,
3298 pdcp_xform->pkt_dir,
3299 pdcp_xform->hfn_threshold,
3300 &cipherdata, &authdata);
3301 else if (session->dir == DIR_DEC)
3302 bufsize = cnstr_shdsc_pdcp_c_plane_decap(
3303 priv->flc_desc[0].desc, 1, swap,
3305 session->pdcp.sn_size,
3307 pdcp_xform->pkt_dir,
3308 pdcp_xform->hfn_threshold,
3309 &cipherdata, &authdata);
3311 } else if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_SHORT_MAC) {
3312 bufsize = cnstr_shdsc_pdcp_short_mac(priv->flc_desc[0].desc,
3313 1, swap, &authdata);
3315 if (session->dir == DIR_ENC) {
3316 if (pdcp_xform->sdap_enabled)
3317 bufsize = cnstr_shdsc_pdcp_sdap_u_plane_encap(
3318 priv->flc_desc[0].desc, 1, swap,
3319 session->pdcp.sn_size,
3322 pdcp_xform->pkt_dir,
3323 pdcp_xform->hfn_threshold,
3324 &cipherdata, p_authdata);
3326 bufsize = cnstr_shdsc_pdcp_u_plane_encap(
3327 priv->flc_desc[0].desc, 1, swap,
3328 session->pdcp.sn_size,
3331 pdcp_xform->pkt_dir,
3332 pdcp_xform->hfn_threshold,
3333 &cipherdata, p_authdata);
3334 } else if (session->dir == DIR_DEC) {
3335 if (pdcp_xform->sdap_enabled)
3336 bufsize = cnstr_shdsc_pdcp_sdap_u_plane_decap(
3337 priv->flc_desc[0].desc, 1, swap,
3338 session->pdcp.sn_size,
3341 pdcp_xform->pkt_dir,
3342 pdcp_xform->hfn_threshold,
3343 &cipherdata, p_authdata);
3345 bufsize = cnstr_shdsc_pdcp_u_plane_decap(
3346 priv->flc_desc[0].desc, 1, swap,
3347 session->pdcp.sn_size,
3350 pdcp_xform->pkt_dir,
3351 pdcp_xform->hfn_threshold,
3352 &cipherdata, p_authdata);
3357 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
3361 /* Enable the stashing control bit */
3362 DPAA2_SET_FLC_RSC(flc);
3363 flc->word2_rflc_31_0 = lower_32_bits(
3364 (size_t)&(((struct dpaa2_sec_qp *)
3365 dev->data->queue_pairs[0])->rx_vq) | 0x14);
3366 flc->word3_rflc_63_32 = upper_32_bits(
3367 (size_t)&(((struct dpaa2_sec_qp *)
3368 dev->data->queue_pairs[0])->rx_vq));
3370 flc->word1_sdl = (uint8_t)bufsize;
3372 /* TODO - check the perf impact or
3373 * align as per descriptor type
3374 * Set EWS bit i.e. enable write-safe
3375 * DPAA2_SET_FLC_EWS(flc);
3378 /* Set BS = 1 i.e reuse input buffers as output buffers */
3379 DPAA2_SET_FLC_REUSE_BS(flc);
3380 /* Set FF = 10; reuse input buffers if they provide sufficient space */
3381 DPAA2_SET_FLC_REUSE_FF(flc);
3383 session->ctxt = priv;
3387 rte_free(session->auth_key.data);
3388 rte_free(session->cipher_key.data);
3394 dpaa2_sec_security_session_create(void *dev,
3395 struct rte_security_session_conf *conf,
3396 struct rte_security_session *sess,
3397 struct rte_mempool *mempool)
3399 void *sess_private_data;
3400 struct rte_cryptodev *cdev = (struct rte_cryptodev *)dev;
3403 if (rte_mempool_get(mempool, &sess_private_data)) {
3404 DPAA2_SEC_ERR("Couldn't get object from session mempool");
3408 switch (conf->protocol) {
3409 case RTE_SECURITY_PROTOCOL_IPSEC:
3410 ret = dpaa2_sec_set_ipsec_session(cdev, conf,
3413 case RTE_SECURITY_PROTOCOL_MACSEC:
3415 case RTE_SECURITY_PROTOCOL_PDCP:
3416 ret = dpaa2_sec_set_pdcp_session(cdev, conf,
3423 DPAA2_SEC_ERR("Failed to configure session parameters");
3424 /* Return session to mempool */
3425 rte_mempool_put(mempool, sess_private_data);
3429 set_sec_session_private_data(sess, sess_private_data);
3434 /** Clear the memory of session so it doesn't leave key material behind */
3436 dpaa2_sec_security_session_destroy(void *dev __rte_unused,
3437 struct rte_security_session *sess)
3439 PMD_INIT_FUNC_TRACE();
3440 void *sess_priv = get_sec_session_private_data(sess);
3442 dpaa2_sec_session *s = (dpaa2_sec_session *)sess_priv;
3445 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
3448 rte_free(s->cipher_key.data);
3449 rte_free(s->auth_key.data);
3450 memset(s, 0, sizeof(dpaa2_sec_session));
3451 set_sec_session_private_data(sess, NULL);
3452 rte_mempool_put(sess_mp, sess_priv);
3458 dpaa2_sec_sym_session_configure(struct rte_cryptodev *dev,
3459 struct rte_crypto_sym_xform *xform,
3460 struct rte_cryptodev_sym_session *sess,
3461 struct rte_mempool *mempool)
3463 void *sess_private_data;
3466 if (rte_mempool_get(mempool, &sess_private_data)) {
3467 DPAA2_SEC_ERR("Couldn't get object from session mempool");
3471 ret = dpaa2_sec_set_session_parameters(dev, xform, sess_private_data);
3473 DPAA2_SEC_ERR("Failed to configure session parameters");
3474 /* Return session to mempool */
3475 rte_mempool_put(mempool, sess_private_data);
3479 set_sym_session_private_data(sess, dev->driver_id,
3485 /** Clear the memory of session so it doesn't leave key material behind */
3487 dpaa2_sec_sym_session_clear(struct rte_cryptodev *dev,
3488 struct rte_cryptodev_sym_session *sess)
3490 PMD_INIT_FUNC_TRACE();
3491 uint8_t index = dev->driver_id;
3492 void *sess_priv = get_sym_session_private_data(sess, index);
3493 dpaa2_sec_session *s = (dpaa2_sec_session *)sess_priv;
3497 rte_free(s->cipher_key.data);
3498 rte_free(s->auth_key.data);
3499 memset(s, 0, sizeof(dpaa2_sec_session));
3500 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
3501 set_sym_session_private_data(sess, index, NULL);
3502 rte_mempool_put(sess_mp, sess_priv);
3507 dpaa2_sec_dev_configure(struct rte_cryptodev *dev __rte_unused,
3508 struct rte_cryptodev_config *config __rte_unused)
3510 PMD_INIT_FUNC_TRACE();
3516 dpaa2_sec_dev_start(struct rte_cryptodev *dev)
3518 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3519 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3520 struct dpseci_attr attr;
3521 struct dpaa2_queue *dpaa2_q;
3522 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3523 dev->data->queue_pairs;
3524 struct dpseci_rx_queue_attr rx_attr;
3525 struct dpseci_tx_queue_attr tx_attr;
3528 PMD_INIT_FUNC_TRACE();
3530 memset(&attr, 0, sizeof(struct dpseci_attr));
3532 ret = dpseci_enable(dpseci, CMD_PRI_LOW, priv->token);
3534 DPAA2_SEC_ERR("DPSECI with HW_ID = %d ENABLE FAILED",
3536 goto get_attr_failure;
3538 ret = dpseci_get_attributes(dpseci, CMD_PRI_LOW, priv->token, &attr);
3540 DPAA2_SEC_ERR("DPSEC ATTRIBUTE READ FAILED, disabling DPSEC");
3541 goto get_attr_failure;
3543 for (i = 0; i < attr.num_rx_queues && qp[i]; i++) {
3544 dpaa2_q = &qp[i]->rx_vq;
3545 dpseci_get_rx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
3547 dpaa2_q->fqid = rx_attr.fqid;
3548 DPAA2_SEC_DEBUG("rx_fqid: %d", dpaa2_q->fqid);
3550 for (i = 0; i < attr.num_tx_queues && qp[i]; i++) {
3551 dpaa2_q = &qp[i]->tx_vq;
3552 dpseci_get_tx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
3554 dpaa2_q->fqid = tx_attr.fqid;
3555 DPAA2_SEC_DEBUG("tx_fqid: %d", dpaa2_q->fqid);
3560 dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
3565 dpaa2_sec_dev_stop(struct rte_cryptodev *dev)
3567 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3568 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3571 PMD_INIT_FUNC_TRACE();
3573 ret = dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
3575 DPAA2_SEC_ERR("Failure in disabling dpseci %d device",
3580 ret = dpseci_reset(dpseci, CMD_PRI_LOW, priv->token);
3582 DPAA2_SEC_ERR("SEC Device cannot be reset:Error = %0x", ret);
3588 dpaa2_sec_dev_close(struct rte_cryptodev *dev __rte_unused)
3590 PMD_INIT_FUNC_TRACE();
3596 dpaa2_sec_dev_infos_get(struct rte_cryptodev *dev,
3597 struct rte_cryptodev_info *info)
3599 struct dpaa2_sec_dev_private *internals = dev->data->dev_private;
3601 PMD_INIT_FUNC_TRACE();
3603 info->max_nb_queue_pairs = internals->max_nb_queue_pairs;
3604 info->feature_flags = dev->feature_flags;
3605 info->capabilities = dpaa2_sec_capabilities;
3606 /* No limit of number of sessions */
3607 info->sym.max_nb_sessions = 0;
3608 info->driver_id = cryptodev_driver_id;
3613 void dpaa2_sec_stats_get(struct rte_cryptodev *dev,
3614 struct rte_cryptodev_stats *stats)
3616 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3617 struct fsl_mc_io dpseci;
3618 struct dpseci_sec_counters counters = {0};
3619 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3620 dev->data->queue_pairs;
3623 PMD_INIT_FUNC_TRACE();
3624 if (stats == NULL) {
3625 DPAA2_SEC_ERR("Invalid stats ptr NULL");
3628 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
3629 if (qp == NULL || qp[i] == NULL) {
3630 DPAA2_SEC_DEBUG("Uninitialised queue pair");
3634 stats->enqueued_count += qp[i]->tx_vq.tx_pkts;
3635 stats->dequeued_count += qp[i]->rx_vq.rx_pkts;
3636 stats->enqueue_err_count += qp[i]->tx_vq.err_pkts;
3637 stats->dequeue_err_count += qp[i]->rx_vq.err_pkts;
3640 /* In case as secondary process access stats, MCP portal in priv-hw
3641 * may have primary process address. Need the secondary process
3642 * based MCP portal address for this object.
3644 dpseci.regs = dpaa2_get_mcp_ptr(MC_PORTAL_INDEX);
3645 ret = dpseci_get_sec_counters(&dpseci, CMD_PRI_LOW, priv->token,
3648 DPAA2_SEC_ERR("SEC counters failed");
3650 DPAA2_SEC_INFO("dpseci hardware stats:"
3651 "\n\tNum of Requests Dequeued = %" PRIu64
3652 "\n\tNum of Outbound Encrypt Requests = %" PRIu64
3653 "\n\tNum of Inbound Decrypt Requests = %" PRIu64
3654 "\n\tNum of Outbound Bytes Encrypted = %" PRIu64
3655 "\n\tNum of Outbound Bytes Protected = %" PRIu64
3656 "\n\tNum of Inbound Bytes Decrypted = %" PRIu64
3657 "\n\tNum of Inbound Bytes Validated = %" PRIu64,
3658 counters.dequeued_requests,
3659 counters.ob_enc_requests,
3660 counters.ib_dec_requests,
3661 counters.ob_enc_bytes,
3662 counters.ob_prot_bytes,
3663 counters.ib_dec_bytes,
3664 counters.ib_valid_bytes);
3669 void dpaa2_sec_stats_reset(struct rte_cryptodev *dev)
3672 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3673 (dev->data->queue_pairs);
3675 PMD_INIT_FUNC_TRACE();
3677 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
3678 if (qp[i] == NULL) {
3679 DPAA2_SEC_DEBUG("Uninitialised queue pair");
3682 qp[i]->tx_vq.rx_pkts = 0;
3683 qp[i]->tx_vq.tx_pkts = 0;
3684 qp[i]->tx_vq.err_pkts = 0;
3685 qp[i]->rx_vq.rx_pkts = 0;
3686 qp[i]->rx_vq.tx_pkts = 0;
3687 qp[i]->rx_vq.err_pkts = 0;
3691 static void __rte_hot
3692 dpaa2_sec_process_parallel_event(struct qbman_swp *swp,
3693 const struct qbman_fd *fd,
3694 const struct qbman_result *dq,
3695 struct dpaa2_queue *rxq,
3696 struct rte_event *ev)
3698 /* Prefetching mbuf */
3699 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-
3700 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size));
3702 /* Prefetching ipsec crypto_op stored in priv data of mbuf */
3703 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-64));
3705 ev->flow_id = rxq->ev.flow_id;
3706 ev->sub_event_type = rxq->ev.sub_event_type;
3707 ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
3708 ev->op = RTE_EVENT_OP_NEW;
3709 ev->sched_type = rxq->ev.sched_type;
3710 ev->queue_id = rxq->ev.queue_id;
3711 ev->priority = rxq->ev.priority;
3712 ev->event_ptr = sec_fd_to_mbuf(fd);
3714 qbman_swp_dqrr_consume(swp, dq);
3717 dpaa2_sec_process_atomic_event(struct qbman_swp *swp __rte_unused,
3718 const struct qbman_fd *fd,
3719 const struct qbman_result *dq,
3720 struct dpaa2_queue *rxq,
3721 struct rte_event *ev)
3724 struct rte_crypto_op *crypto_op = (struct rte_crypto_op *)ev->event_ptr;
3725 /* Prefetching mbuf */
3726 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-
3727 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size));
3729 /* Prefetching ipsec crypto_op stored in priv data of mbuf */
3730 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-64));
3732 ev->flow_id = rxq->ev.flow_id;
3733 ev->sub_event_type = rxq->ev.sub_event_type;
3734 ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
3735 ev->op = RTE_EVENT_OP_NEW;
3736 ev->sched_type = rxq->ev.sched_type;
3737 ev->queue_id = rxq->ev.queue_id;
3738 ev->priority = rxq->ev.priority;
3740 ev->event_ptr = sec_fd_to_mbuf(fd);
3741 dqrr_index = qbman_get_dqrr_idx(dq);
3742 *dpaa2_seqn(crypto_op->sym->m_src) = dqrr_index + 1;
3743 DPAA2_PER_LCORE_DQRR_SIZE++;
3744 DPAA2_PER_LCORE_DQRR_HELD |= 1 << dqrr_index;
3745 DPAA2_PER_LCORE_DQRR_MBUF(dqrr_index) = crypto_op->sym->m_src;
3749 dpaa2_sec_eventq_attach(const struct rte_cryptodev *dev,
3751 struct dpaa2_dpcon_dev *dpcon,
3752 const struct rte_event *event)
3754 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3755 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3756 struct dpaa2_sec_qp *qp = dev->data->queue_pairs[qp_id];
3757 struct dpseci_rx_queue_cfg cfg;
3761 if (event->sched_type == RTE_SCHED_TYPE_PARALLEL)
3762 qp->rx_vq.cb = dpaa2_sec_process_parallel_event;
3763 else if (event->sched_type == RTE_SCHED_TYPE_ATOMIC)
3764 qp->rx_vq.cb = dpaa2_sec_process_atomic_event;
3768 priority = (RTE_EVENT_DEV_PRIORITY_LOWEST / event->priority) *
3769 (dpcon->num_priorities - 1);
3771 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
3772 cfg.options = DPSECI_QUEUE_OPT_DEST;
3773 cfg.dest_cfg.dest_type = DPSECI_DEST_DPCON;
3774 cfg.dest_cfg.dest_id = dpcon->dpcon_id;
3775 cfg.dest_cfg.priority = priority;
3777 cfg.options |= DPSECI_QUEUE_OPT_USER_CTX;
3778 cfg.user_ctx = (size_t)(qp);
3779 if (event->sched_type == RTE_SCHED_TYPE_ATOMIC) {
3780 cfg.options |= DPSECI_QUEUE_OPT_ORDER_PRESERVATION;
3781 cfg.order_preservation_en = 1;
3783 ret = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
3786 RTE_LOG(ERR, PMD, "Error in dpseci_set_queue: ret: %d\n", ret);
3790 memcpy(&qp->rx_vq.ev, event, sizeof(struct rte_event));
3796 dpaa2_sec_eventq_detach(const struct rte_cryptodev *dev,
3799 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3800 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3801 struct dpseci_rx_queue_cfg cfg;
3804 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
3805 cfg.options = DPSECI_QUEUE_OPT_DEST;
3806 cfg.dest_cfg.dest_type = DPSECI_DEST_NONE;
3808 ret = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
3811 RTE_LOG(ERR, PMD, "Error in dpseci_set_queue: ret: %d\n", ret);
3816 static struct rte_cryptodev_ops crypto_ops = {
3817 .dev_configure = dpaa2_sec_dev_configure,
3818 .dev_start = dpaa2_sec_dev_start,
3819 .dev_stop = dpaa2_sec_dev_stop,
3820 .dev_close = dpaa2_sec_dev_close,
3821 .dev_infos_get = dpaa2_sec_dev_infos_get,
3822 .stats_get = dpaa2_sec_stats_get,
3823 .stats_reset = dpaa2_sec_stats_reset,
3824 .queue_pair_setup = dpaa2_sec_queue_pair_setup,
3825 .queue_pair_release = dpaa2_sec_queue_pair_release,
3826 .sym_session_get_size = dpaa2_sec_sym_session_get_size,
3827 .sym_session_configure = dpaa2_sec_sym_session_configure,
3828 .sym_session_clear = dpaa2_sec_sym_session_clear,
3829 /* Raw data-path API related operations */
3830 .sym_get_raw_dp_ctx_size = dpaa2_sec_get_dp_ctx_size,
3831 .sym_configure_raw_dp_ctx = dpaa2_sec_configure_raw_dp_ctx,
3834 #ifdef RTE_LIB_SECURITY
3835 static const struct rte_security_capability *
3836 dpaa2_sec_capabilities_get(void *device __rte_unused)
3838 return dpaa2_sec_security_cap;
3841 static const struct rte_security_ops dpaa2_sec_security_ops = {
3842 .session_create = dpaa2_sec_security_session_create,
3843 .session_update = NULL,
3844 .session_stats_get = NULL,
3845 .session_destroy = dpaa2_sec_security_session_destroy,
3846 .set_pkt_metadata = NULL,
3847 .capabilities_get = dpaa2_sec_capabilities_get
3852 dpaa2_sec_uninit(const struct rte_cryptodev *dev)
3854 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3855 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3858 PMD_INIT_FUNC_TRACE();
3860 /* Function is reverse of dpaa2_sec_dev_init.
3861 * It does the following:
3862 * 1. Detach a DPSECI from attached resources i.e. buffer pools, dpbp_id
3863 * 2. Close the DPSECI device
3864 * 3. Free the allocated resources.
3867 /*Close the device at underlying layer*/
3868 ret = dpseci_close(dpseci, CMD_PRI_LOW, priv->token);
3870 DPAA2_SEC_ERR("Failure closing dpseci device: err(%d)", ret);
3874 /*Free the allocated memory for ethernet private data and dpseci*/
3877 rte_free(dev->security_ctx);
3878 rte_mempool_free(priv->fle_pool);
3880 DPAA2_SEC_INFO("Closing DPAA2_SEC device %s on numa socket %u",
3881 dev->data->name, rte_socket_id());
3887 dpaa2_sec_dev_init(struct rte_cryptodev *cryptodev)
3889 struct dpaa2_sec_dev_private *internals;
3890 struct rte_device *dev = cryptodev->device;
3891 struct rte_dpaa2_device *dpaa2_dev;
3892 #ifdef RTE_LIB_SECURITY
3893 struct rte_security_ctx *security_instance;
3895 struct fsl_mc_io *dpseci;
3897 struct dpseci_attr attr;
3901 PMD_INIT_FUNC_TRACE();
3902 dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
3903 hw_id = dpaa2_dev->object_id;
3905 cryptodev->driver_id = cryptodev_driver_id;
3906 cryptodev->dev_ops = &crypto_ops;
3908 cryptodev->enqueue_burst = dpaa2_sec_enqueue_burst;
3909 cryptodev->dequeue_burst = dpaa2_sec_dequeue_burst;
3910 cryptodev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
3911 RTE_CRYPTODEV_FF_HW_ACCELERATED |
3912 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
3913 RTE_CRYPTODEV_FF_SECURITY |
3914 RTE_CRYPTODEV_FF_SYM_RAW_DP |
3915 RTE_CRYPTODEV_FF_IN_PLACE_SGL |
3916 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT |
3917 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
3918 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT |
3919 RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT;
3921 internals = cryptodev->data->dev_private;
3924 * For secondary processes, we don't initialise any further as primary
3925 * has already done this work. Only check we don't need a different
3928 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
3929 DPAA2_SEC_DEBUG("Device already init by primary process");
3932 #ifdef RTE_LIB_SECURITY
3933 /* Initialize security_ctx only for primary process*/
3934 security_instance = rte_malloc("rte_security_instances_ops",
3935 sizeof(struct rte_security_ctx), 0);
3936 if (security_instance == NULL)
3938 security_instance->device = (void *)cryptodev;
3939 security_instance->ops = &dpaa2_sec_security_ops;
3940 security_instance->sess_cnt = 0;
3941 cryptodev->security_ctx = security_instance;
3943 /*Open the rte device via MC and save the handle for further use*/
3944 dpseci = (struct fsl_mc_io *)rte_calloc(NULL, 1,
3945 sizeof(struct fsl_mc_io), 0);
3948 "Error in allocating the memory for dpsec object");
3951 dpseci->regs = dpaa2_get_mcp_ptr(MC_PORTAL_INDEX);
3953 retcode = dpseci_open(dpseci, CMD_PRI_LOW, hw_id, &token);
3955 DPAA2_SEC_ERR("Cannot open the dpsec device: Error = %x",
3959 retcode = dpseci_get_attributes(dpseci, CMD_PRI_LOW, token, &attr);
3962 "Cannot get dpsec device attributed: Error = %x",
3966 snprintf(cryptodev->data->name, sizeof(cryptodev->data->name),
3969 internals->max_nb_queue_pairs = attr.num_tx_queues;
3970 cryptodev->data->nb_queue_pairs = internals->max_nb_queue_pairs;
3971 internals->hw = dpseci;
3972 internals->token = token;
3974 snprintf(str, sizeof(str), "sec_fle_pool_p%d_%d",
3975 getpid(), cryptodev->data->dev_id);
3976 internals->fle_pool = rte_mempool_create((const char *)str,
3979 FLE_POOL_CACHE_SIZE, 0,
3980 NULL, NULL, NULL, NULL,
3982 if (!internals->fle_pool) {
3983 DPAA2_SEC_ERR("Mempool (%s) creation failed", str);
3987 DPAA2_SEC_INFO("driver %s: created", cryptodev->data->name);
3991 DPAA2_SEC_ERR("driver %s: create failed", cryptodev->data->name);
3993 /* dpaa2_sec_uninit(crypto_dev_name); */
3998 cryptodev_dpaa2_sec_probe(struct rte_dpaa2_driver *dpaa2_drv __rte_unused,
3999 struct rte_dpaa2_device *dpaa2_dev)
4001 struct rte_cryptodev *cryptodev;
4002 char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
4006 snprintf(cryptodev_name, sizeof(cryptodev_name), "dpsec-%d",
4007 dpaa2_dev->object_id);
4009 cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
4010 if (cryptodev == NULL)
4013 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
4014 cryptodev->data->dev_private = rte_zmalloc_socket(
4015 "cryptodev private structure",
4016 sizeof(struct dpaa2_sec_dev_private),
4017 RTE_CACHE_LINE_SIZE,
4020 if (cryptodev->data->dev_private == NULL)
4021 rte_panic("Cannot allocate memzone for private "
4025 dpaa2_dev->cryptodev = cryptodev;
4026 cryptodev->device = &dpaa2_dev->device;
4028 /* init user callbacks */
4029 TAILQ_INIT(&(cryptodev->link_intr_cbs));
4031 if (dpaa2_svr_family == SVR_LX2160A)
4032 rta_set_sec_era(RTA_SEC_ERA_10);
4034 rta_set_sec_era(RTA_SEC_ERA_8);
4036 DPAA2_SEC_INFO("2-SEC ERA is %d", rta_get_sec_era());
4038 /* Invoke PMD device initialization function */
4039 retval = dpaa2_sec_dev_init(cryptodev);
4041 rte_cryptodev_pmd_probing_finish(cryptodev);
4045 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
4046 rte_free(cryptodev->data->dev_private);
4048 cryptodev->attached = RTE_CRYPTODEV_DETACHED;
4054 cryptodev_dpaa2_sec_remove(struct rte_dpaa2_device *dpaa2_dev)
4056 struct rte_cryptodev *cryptodev;
4059 cryptodev = dpaa2_dev->cryptodev;
4060 if (cryptodev == NULL)
4063 ret = dpaa2_sec_uninit(cryptodev);
4067 return rte_cryptodev_pmd_destroy(cryptodev);
4070 static struct rte_dpaa2_driver rte_dpaa2_sec_driver = {
4071 .drv_flags = RTE_DPAA2_DRV_IOVA_AS_VA,
4072 .drv_type = DPAA2_CRYPTO,
4074 .name = "DPAA2 SEC PMD"
4076 .probe = cryptodev_dpaa2_sec_probe,
4077 .remove = cryptodev_dpaa2_sec_remove,
4080 static struct cryptodev_driver dpaa2_sec_crypto_drv;
4082 RTE_PMD_REGISTER_DPAA2(CRYPTODEV_NAME_DPAA2_SEC_PMD, rte_dpaa2_sec_driver);
4083 RTE_PMD_REGISTER_CRYPTO_DRIVER(dpaa2_sec_crypto_drv,
4084 rte_dpaa2_sec_driver.driver, cryptodev_driver_id);
4085 RTE_LOG_REGISTER(dpaa2_logtype_sec, pmd.crypto.dpaa2, NOTICE);