1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
4 * Copyright 2016-2018 NXP
14 #include <rte_cryptodev.h>
15 #include <rte_malloc.h>
16 #include <rte_memcpy.h>
17 #include <rte_string_fns.h>
18 #include <rte_cycles.h>
19 #include <rte_kvargs.h>
21 #include <rte_cryptodev_pmd.h>
22 #include <rte_common.h>
23 #include <rte_fslmc.h>
24 #include <fslmc_vfio.h>
25 #include <dpaa2_hw_pvt.h>
26 #include <dpaa2_hw_dpio.h>
27 #include <dpaa2_hw_mempool.h>
28 #include <fsl_dpopr.h>
29 #include <fsl_dpseci.h>
30 #include <fsl_mc_sys.h>
32 #include "dpaa2_sec_priv.h"
33 #include "dpaa2_sec_event.h"
34 #include "dpaa2_sec_logs.h"
37 typedef uint64_t dma_addr_t;
39 /* RTA header files */
40 #include <hw/desc/ipsec.h>
41 #include <hw/desc/pdcp.h>
42 #include <hw/desc/algo.h>
44 /* Minimum job descriptor consists of a oneword job descriptor HEADER and
45 * a pointer to the shared descriptor
47 #define MIN_JOB_DESC_SIZE (CAAM_CMD_SZ + CAAM_PTR_SZ)
48 #define FSL_VENDOR_ID 0x1957
49 #define FSL_DEVICE_ID 0x410
50 #define FSL_SUBSYSTEM_SEC 1
51 #define FSL_MC_DPSECI_DEVID 3
54 /* FLE_POOL_NUM_BUFS is set as per the ipsec-secgw application */
55 #define FLE_POOL_NUM_BUFS 32000
56 #define FLE_POOL_BUF_SIZE 256
57 #define FLE_POOL_CACHE_SIZE 512
58 #define FLE_SG_MEM_SIZE 2048
59 #define SEC_FLC_DHR_OUTBOUND -114
60 #define SEC_FLC_DHR_INBOUND 0
62 enum rta_sec_era rta_sec_era = RTA_SEC_ERA_8;
64 static uint8_t cryptodev_driver_id;
66 int dpaa2_logtype_sec;
69 build_proto_compound_sg_fd(dpaa2_sec_session *sess,
70 struct rte_crypto_op *op,
71 struct qbman_fd *fd, uint16_t bpid)
73 struct rte_crypto_sym_op *sym_op = op->sym;
74 struct ctxt_priv *priv = sess->ctxt;
75 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
76 struct sec_flow_context *flc;
77 struct rte_mbuf *mbuf;
78 uint32_t in_len = 0, out_len = 0;
85 /* first FLE entry used to store mbuf and session ctxt */
86 fle = (struct qbman_fle *)rte_malloc(NULL, FLE_SG_MEM_SIZE,
89 DPAA2_SEC_DP_ERR("Proto:SG: Memory alloc failed for SGE");
92 memset(fle, 0, FLE_SG_MEM_SIZE);
93 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
94 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
96 /* Save the shared descriptor */
97 flc = &priv->flc_desc[0].flc;
103 if (likely(bpid < MAX_BPID)) {
104 DPAA2_SET_FD_BPID(fd, bpid);
105 DPAA2_SET_FLE_BPID(op_fle, bpid);
106 DPAA2_SET_FLE_BPID(ip_fle, bpid);
108 DPAA2_SET_FD_IVP(fd);
109 DPAA2_SET_FLE_IVP(op_fle);
110 DPAA2_SET_FLE_IVP(ip_fle);
113 /* Configure FD as a FRAME LIST */
114 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
115 DPAA2_SET_FD_COMPOUND_FMT(fd);
116 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
118 /* Configure Output FLE with Scatter/Gather Entry */
119 DPAA2_SET_FLE_SG_EXT(op_fle);
120 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
122 /* Configure Output SGE for Encap/Decap */
123 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
124 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
127 sge->length = mbuf->data_len;
128 out_len += sge->length;
131 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
132 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
134 /* using buf_len for last buf - so that extra data can be added */
135 sge->length = mbuf->buf_len - mbuf->data_off;
136 out_len += sge->length;
138 DPAA2_SET_FLE_FIN(sge);
139 op_fle->length = out_len;
142 mbuf = sym_op->m_src;
144 /* Configure Input FLE with Scatter/Gather Entry */
145 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
146 DPAA2_SET_FLE_SG_EXT(ip_fle);
147 DPAA2_SET_FLE_FIN(ip_fle);
149 /* Configure input SGE for Encap/Decap */
150 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
151 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
152 sge->length = mbuf->data_len;
153 in_len += sge->length;
159 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
160 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
161 sge->length = mbuf->data_len;
162 in_len += sge->length;
165 ip_fle->length = in_len;
166 DPAA2_SET_FLE_FIN(sge);
168 /* In case of PDCP, per packet HFN is stored in
169 * mbuf priv after sym_op.
171 if (sess->ctxt_type == DPAA2_SEC_PDCP && sess->pdcp.hfn_ovd) {
172 uint32_t hfn_ovd = *((uint8_t *)op + sess->pdcp.hfn_ovd_offset);
173 /*enable HFN override override */
174 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, hfn_ovd);
175 DPAA2_SET_FLE_INTERNAL_JD(op_fle, hfn_ovd);
176 DPAA2_SET_FD_INTERNAL_JD(fd, hfn_ovd);
178 DPAA2_SET_FD_LEN(fd, ip_fle->length);
184 build_proto_compound_fd(dpaa2_sec_session *sess,
185 struct rte_crypto_op *op,
186 struct qbman_fd *fd, uint16_t bpid)
188 struct rte_crypto_sym_op *sym_op = op->sym;
189 struct ctxt_priv *priv = sess->ctxt;
190 struct qbman_fle *fle, *ip_fle, *op_fle;
191 struct sec_flow_context *flc;
192 struct rte_mbuf *src_mbuf = sym_op->m_src;
193 struct rte_mbuf *dst_mbuf = sym_op->m_dst;
199 /* Save the shared descriptor */
200 flc = &priv->flc_desc[0].flc;
202 /* we are using the first FLE entry to store Mbuf */
203 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
205 DPAA2_SEC_DP_ERR("Memory alloc failed");
208 memset(fle, 0, FLE_POOL_BUF_SIZE);
209 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
210 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
215 if (likely(bpid < MAX_BPID)) {
216 DPAA2_SET_FD_BPID(fd, bpid);
217 DPAA2_SET_FLE_BPID(op_fle, bpid);
218 DPAA2_SET_FLE_BPID(ip_fle, bpid);
220 DPAA2_SET_FD_IVP(fd);
221 DPAA2_SET_FLE_IVP(op_fle);
222 DPAA2_SET_FLE_IVP(ip_fle);
225 /* Configure FD as a FRAME LIST */
226 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
227 DPAA2_SET_FD_COMPOUND_FMT(fd);
228 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
230 /* Configure Output FLE with dst mbuf data */
231 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_MBUF_VADDR_TO_IOVA(dst_mbuf));
232 DPAA2_SET_FLE_OFFSET(op_fle, dst_mbuf->data_off);
233 DPAA2_SET_FLE_LEN(op_fle, dst_mbuf->buf_len);
235 /* Configure Input FLE with src mbuf data */
236 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_MBUF_VADDR_TO_IOVA(src_mbuf));
237 DPAA2_SET_FLE_OFFSET(ip_fle, src_mbuf->data_off);
238 DPAA2_SET_FLE_LEN(ip_fle, src_mbuf->pkt_len);
240 DPAA2_SET_FD_LEN(fd, ip_fle->length);
241 DPAA2_SET_FLE_FIN(ip_fle);
243 /* In case of PDCP, per packet HFN is stored in
244 * mbuf priv after sym_op.
246 if (sess->ctxt_type == DPAA2_SEC_PDCP && sess->pdcp.hfn_ovd) {
247 uint32_t hfn_ovd = *((uint8_t *)op + sess->pdcp.hfn_ovd_offset);
248 /*enable HFN override override */
249 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, hfn_ovd);
250 DPAA2_SET_FLE_INTERNAL_JD(op_fle, hfn_ovd);
251 DPAA2_SET_FD_INTERNAL_JD(fd, hfn_ovd);
259 build_proto_fd(dpaa2_sec_session *sess,
260 struct rte_crypto_op *op,
261 struct qbman_fd *fd, uint16_t bpid)
263 struct rte_crypto_sym_op *sym_op = op->sym;
265 return build_proto_compound_fd(sess, op, fd, bpid);
267 struct ctxt_priv *priv = sess->ctxt;
268 struct sec_flow_context *flc;
269 struct rte_mbuf *mbuf = sym_op->m_src;
271 if (likely(bpid < MAX_BPID))
272 DPAA2_SET_FD_BPID(fd, bpid);
274 DPAA2_SET_FD_IVP(fd);
276 /* Save the shared descriptor */
277 flc = &priv->flc_desc[0].flc;
279 DPAA2_SET_FD_ADDR(fd, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
280 DPAA2_SET_FD_OFFSET(fd, sym_op->m_src->data_off);
281 DPAA2_SET_FD_LEN(fd, sym_op->m_src->pkt_len);
282 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
284 /* save physical address of mbuf */
285 op->sym->aead.digest.phys_addr = mbuf->buf_iova;
286 mbuf->buf_iova = (size_t)op;
292 build_authenc_gcm_sg_fd(dpaa2_sec_session *sess,
293 struct rte_crypto_op *op,
294 struct qbman_fd *fd, __rte_unused uint16_t bpid)
296 struct rte_crypto_sym_op *sym_op = op->sym;
297 struct ctxt_priv *priv = sess->ctxt;
298 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
299 struct sec_flow_context *flc;
300 uint32_t auth_only_len = sess->ext_params.aead_ctxt.auth_only_len;
301 int icv_len = sess->digest_length;
303 struct rte_mbuf *mbuf;
304 uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
307 PMD_INIT_FUNC_TRACE();
310 mbuf = sym_op->m_dst;
312 mbuf = sym_op->m_src;
314 /* first FLE entry used to store mbuf and session ctxt */
315 fle = (struct qbman_fle *)rte_malloc(NULL, FLE_SG_MEM_SIZE,
316 RTE_CACHE_LINE_SIZE);
317 if (unlikely(!fle)) {
318 DPAA2_SEC_ERR("GCM SG: Memory alloc failed for SGE");
321 memset(fle, 0, FLE_SG_MEM_SIZE);
322 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
323 DPAA2_FLE_SAVE_CTXT(fle, (size_t)priv);
329 /* Save the shared descriptor */
330 flc = &priv->flc_desc[0].flc;
332 /* Configure FD as a FRAME LIST */
333 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
334 DPAA2_SET_FD_COMPOUND_FMT(fd);
335 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
337 DPAA2_SEC_DP_DEBUG("GCM SG: auth_off: 0x%x/length %d, digest-len=%d\n"
338 "iv-len=%d data_off: 0x%x\n",
339 sym_op->aead.data.offset,
340 sym_op->aead.data.length,
343 sym_op->m_src->data_off);
345 /* Configure Output FLE with Scatter/Gather Entry */
346 DPAA2_SET_FLE_SG_EXT(op_fle);
347 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
350 DPAA2_SET_FLE_INTERNAL_JD(op_fle, auth_only_len);
352 op_fle->length = (sess->dir == DIR_ENC) ?
353 (sym_op->aead.data.length + icv_len + auth_only_len) :
354 sym_op->aead.data.length + auth_only_len;
356 /* Configure Output SGE for Encap/Decap */
357 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
358 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off +
359 RTE_ALIGN_CEIL(auth_only_len, 16) - auth_only_len);
360 sge->length = mbuf->data_len - sym_op->aead.data.offset + auth_only_len;
366 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
367 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
368 sge->length = mbuf->data_len;
371 sge->length -= icv_len;
373 if (sess->dir == DIR_ENC) {
375 DPAA2_SET_FLE_ADDR(sge,
376 DPAA2_VADDR_TO_IOVA(sym_op->aead.digest.data));
377 sge->length = icv_len;
379 DPAA2_SET_FLE_FIN(sge);
382 mbuf = sym_op->m_src;
384 /* Configure Input FLE with Scatter/Gather Entry */
385 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
386 DPAA2_SET_FLE_SG_EXT(ip_fle);
387 DPAA2_SET_FLE_FIN(ip_fle);
388 ip_fle->length = (sess->dir == DIR_ENC) ?
389 (sym_op->aead.data.length + sess->iv.length + auth_only_len) :
390 (sym_op->aead.data.length + sess->iv.length + auth_only_len +
393 /* Configure Input SGE for Encap/Decap */
394 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(IV_ptr));
395 sge->length = sess->iv.length;
399 DPAA2_SET_FLE_ADDR(sge,
400 DPAA2_VADDR_TO_IOVA(sym_op->aead.aad.data));
401 sge->length = auth_only_len;
405 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
406 DPAA2_SET_FLE_OFFSET(sge, sym_op->aead.data.offset +
408 sge->length = mbuf->data_len - sym_op->aead.data.offset;
414 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
415 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
416 sge->length = mbuf->data_len;
420 if (sess->dir == DIR_DEC) {
422 old_icv = (uint8_t *)(sge + 1);
423 memcpy(old_icv, sym_op->aead.digest.data, icv_len);
424 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
425 sge->length = icv_len;
428 DPAA2_SET_FLE_FIN(sge);
430 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, auth_only_len);
431 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
433 DPAA2_SET_FD_LEN(fd, ip_fle->length);
439 build_authenc_gcm_fd(dpaa2_sec_session *sess,
440 struct rte_crypto_op *op,
441 struct qbman_fd *fd, uint16_t bpid)
443 struct rte_crypto_sym_op *sym_op = op->sym;
444 struct ctxt_priv *priv = sess->ctxt;
445 struct qbman_fle *fle, *sge;
446 struct sec_flow_context *flc;
447 uint32_t auth_only_len = sess->ext_params.aead_ctxt.auth_only_len;
448 int icv_len = sess->digest_length, retval;
450 struct rte_mbuf *dst;
451 uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
454 PMD_INIT_FUNC_TRACE();
461 /* TODO we are using the first FLE entry to store Mbuf and session ctxt.
462 * Currently we donot know which FLE has the mbuf stored.
463 * So while retreiving we can go back 1 FLE from the FD -ADDR
464 * to get the MBUF Addr from the previous FLE.
465 * We can have a better approach to use the inline Mbuf
467 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
469 DPAA2_SEC_ERR("GCM: Memory alloc failed for SGE");
472 memset(fle, 0, FLE_POOL_BUF_SIZE);
473 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
474 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
477 if (likely(bpid < MAX_BPID)) {
478 DPAA2_SET_FD_BPID(fd, bpid);
479 DPAA2_SET_FLE_BPID(fle, bpid);
480 DPAA2_SET_FLE_BPID(fle + 1, bpid);
481 DPAA2_SET_FLE_BPID(sge, bpid);
482 DPAA2_SET_FLE_BPID(sge + 1, bpid);
483 DPAA2_SET_FLE_BPID(sge + 2, bpid);
484 DPAA2_SET_FLE_BPID(sge + 3, bpid);
486 DPAA2_SET_FD_IVP(fd);
487 DPAA2_SET_FLE_IVP(fle);
488 DPAA2_SET_FLE_IVP((fle + 1));
489 DPAA2_SET_FLE_IVP(sge);
490 DPAA2_SET_FLE_IVP((sge + 1));
491 DPAA2_SET_FLE_IVP((sge + 2));
492 DPAA2_SET_FLE_IVP((sge + 3));
495 /* Save the shared descriptor */
496 flc = &priv->flc_desc[0].flc;
497 /* Configure FD as a FRAME LIST */
498 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
499 DPAA2_SET_FD_COMPOUND_FMT(fd);
500 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
502 DPAA2_SEC_DP_DEBUG("GCM: auth_off: 0x%x/length %d, digest-len=%d\n"
503 "iv-len=%d data_off: 0x%x\n",
504 sym_op->aead.data.offset,
505 sym_op->aead.data.length,
508 sym_op->m_src->data_off);
510 /* Configure Output FLE with Scatter/Gather Entry */
511 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
513 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
514 fle->length = (sess->dir == DIR_ENC) ?
515 (sym_op->aead.data.length + icv_len + auth_only_len) :
516 sym_op->aead.data.length + auth_only_len;
518 DPAA2_SET_FLE_SG_EXT(fle);
520 /* Configure Output SGE for Encap/Decap */
521 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(dst));
522 DPAA2_SET_FLE_OFFSET(sge, dst->data_off +
523 RTE_ALIGN_CEIL(auth_only_len, 16) - auth_only_len);
524 sge->length = sym_op->aead.data.length + auth_only_len;
526 if (sess->dir == DIR_ENC) {
528 DPAA2_SET_FLE_ADDR(sge,
529 DPAA2_VADDR_TO_IOVA(sym_op->aead.digest.data));
530 sge->length = sess->digest_length;
531 DPAA2_SET_FD_LEN(fd, (sym_op->aead.data.length +
532 sess->iv.length + auth_only_len));
534 DPAA2_SET_FLE_FIN(sge);
539 /* Configure Input FLE with Scatter/Gather Entry */
540 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
541 DPAA2_SET_FLE_SG_EXT(fle);
542 DPAA2_SET_FLE_FIN(fle);
543 fle->length = (sess->dir == DIR_ENC) ?
544 (sym_op->aead.data.length + sess->iv.length + auth_only_len) :
545 (sym_op->aead.data.length + sess->iv.length + auth_only_len +
546 sess->digest_length);
548 /* Configure Input SGE for Encap/Decap */
549 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(IV_ptr));
550 sge->length = sess->iv.length;
553 DPAA2_SET_FLE_ADDR(sge,
554 DPAA2_VADDR_TO_IOVA(sym_op->aead.aad.data));
555 sge->length = auth_only_len;
556 DPAA2_SET_FLE_BPID(sge, bpid);
560 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
561 DPAA2_SET_FLE_OFFSET(sge, sym_op->aead.data.offset +
562 sym_op->m_src->data_off);
563 sge->length = sym_op->aead.data.length;
564 if (sess->dir == DIR_DEC) {
566 old_icv = (uint8_t *)(sge + 1);
567 memcpy(old_icv, sym_op->aead.digest.data,
568 sess->digest_length);
569 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
570 sge->length = sess->digest_length;
571 DPAA2_SET_FD_LEN(fd, (sym_op->aead.data.length +
572 sess->digest_length +
576 DPAA2_SET_FLE_FIN(sge);
579 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
580 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
587 build_authenc_sg_fd(dpaa2_sec_session *sess,
588 struct rte_crypto_op *op,
589 struct qbman_fd *fd, __rte_unused uint16_t bpid)
591 struct rte_crypto_sym_op *sym_op = op->sym;
592 struct ctxt_priv *priv = sess->ctxt;
593 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
594 struct sec_flow_context *flc;
595 uint32_t auth_only_len = sym_op->auth.data.length -
596 sym_op->cipher.data.length;
597 int icv_len = sess->digest_length;
599 struct rte_mbuf *mbuf;
600 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
603 PMD_INIT_FUNC_TRACE();
606 mbuf = sym_op->m_dst;
608 mbuf = sym_op->m_src;
610 /* first FLE entry used to store mbuf and session ctxt */
611 fle = (struct qbman_fle *)rte_malloc(NULL, FLE_SG_MEM_SIZE,
612 RTE_CACHE_LINE_SIZE);
613 if (unlikely(!fle)) {
614 DPAA2_SEC_ERR("AUTHENC SG: Memory alloc failed for SGE");
617 memset(fle, 0, FLE_SG_MEM_SIZE);
618 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
619 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
625 /* Save the shared descriptor */
626 flc = &priv->flc_desc[0].flc;
628 /* Configure FD as a FRAME LIST */
629 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
630 DPAA2_SET_FD_COMPOUND_FMT(fd);
631 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
634 "AUTHENC SG: auth_off: 0x%x/length %d, digest-len=%d\n"
635 "cipher_off: 0x%x/length %d, iv-len=%d data_off: 0x%x\n",
636 sym_op->auth.data.offset,
637 sym_op->auth.data.length,
639 sym_op->cipher.data.offset,
640 sym_op->cipher.data.length,
642 sym_op->m_src->data_off);
644 /* Configure Output FLE with Scatter/Gather Entry */
645 DPAA2_SET_FLE_SG_EXT(op_fle);
646 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
649 DPAA2_SET_FLE_INTERNAL_JD(op_fle, auth_only_len);
651 op_fle->length = (sess->dir == DIR_ENC) ?
652 (sym_op->cipher.data.length + icv_len) :
653 sym_op->cipher.data.length;
655 /* Configure Output SGE for Encap/Decap */
656 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
657 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off + sym_op->auth.data.offset);
658 sge->length = mbuf->data_len - sym_op->auth.data.offset;
664 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
665 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
666 sge->length = mbuf->data_len;
669 sge->length -= icv_len;
671 if (sess->dir == DIR_ENC) {
673 DPAA2_SET_FLE_ADDR(sge,
674 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
675 sge->length = icv_len;
677 DPAA2_SET_FLE_FIN(sge);
680 mbuf = sym_op->m_src;
682 /* Configure Input FLE with Scatter/Gather Entry */
683 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
684 DPAA2_SET_FLE_SG_EXT(ip_fle);
685 DPAA2_SET_FLE_FIN(ip_fle);
686 ip_fle->length = (sess->dir == DIR_ENC) ?
687 (sym_op->auth.data.length + sess->iv.length) :
688 (sym_op->auth.data.length + sess->iv.length +
691 /* Configure Input SGE for Encap/Decap */
692 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
693 sge->length = sess->iv.length;
696 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
697 DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset +
699 sge->length = mbuf->data_len - sym_op->auth.data.offset;
705 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
706 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
707 sge->length = mbuf->data_len;
710 sge->length -= icv_len;
712 if (sess->dir == DIR_DEC) {
714 old_icv = (uint8_t *)(sge + 1);
715 memcpy(old_icv, sym_op->auth.digest.data,
717 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
718 sge->length = icv_len;
721 DPAA2_SET_FLE_FIN(sge);
723 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, auth_only_len);
724 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
726 DPAA2_SET_FD_LEN(fd, ip_fle->length);
732 build_authenc_fd(dpaa2_sec_session *sess,
733 struct rte_crypto_op *op,
734 struct qbman_fd *fd, uint16_t bpid)
736 struct rte_crypto_sym_op *sym_op = op->sym;
737 struct ctxt_priv *priv = sess->ctxt;
738 struct qbman_fle *fle, *sge;
739 struct sec_flow_context *flc;
740 uint32_t auth_only_len = sym_op->auth.data.length -
741 sym_op->cipher.data.length;
742 int icv_len = sess->digest_length, retval;
744 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
746 struct rte_mbuf *dst;
748 PMD_INIT_FUNC_TRACE();
755 /* we are using the first FLE entry to store Mbuf.
756 * Currently we donot know which FLE has the mbuf stored.
757 * So while retreiving we can go back 1 FLE from the FD -ADDR
758 * to get the MBUF Addr from the previous FLE.
759 * We can have a better approach to use the inline Mbuf
761 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
763 DPAA2_SEC_ERR("Memory alloc failed for SGE");
766 memset(fle, 0, FLE_POOL_BUF_SIZE);
767 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
768 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
771 if (likely(bpid < MAX_BPID)) {
772 DPAA2_SET_FD_BPID(fd, bpid);
773 DPAA2_SET_FLE_BPID(fle, bpid);
774 DPAA2_SET_FLE_BPID(fle + 1, bpid);
775 DPAA2_SET_FLE_BPID(sge, bpid);
776 DPAA2_SET_FLE_BPID(sge + 1, bpid);
777 DPAA2_SET_FLE_BPID(sge + 2, bpid);
778 DPAA2_SET_FLE_BPID(sge + 3, bpid);
780 DPAA2_SET_FD_IVP(fd);
781 DPAA2_SET_FLE_IVP(fle);
782 DPAA2_SET_FLE_IVP((fle + 1));
783 DPAA2_SET_FLE_IVP(sge);
784 DPAA2_SET_FLE_IVP((sge + 1));
785 DPAA2_SET_FLE_IVP((sge + 2));
786 DPAA2_SET_FLE_IVP((sge + 3));
789 /* Save the shared descriptor */
790 flc = &priv->flc_desc[0].flc;
791 /* Configure FD as a FRAME LIST */
792 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
793 DPAA2_SET_FD_COMPOUND_FMT(fd);
794 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
797 "AUTHENC: auth_off: 0x%x/length %d, digest-len=%d\n"
798 "cipher_off: 0x%x/length %d, iv-len=%d data_off: 0x%x\n",
799 sym_op->auth.data.offset,
800 sym_op->auth.data.length,
802 sym_op->cipher.data.offset,
803 sym_op->cipher.data.length,
805 sym_op->m_src->data_off);
807 /* Configure Output FLE with Scatter/Gather Entry */
808 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
810 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
811 fle->length = (sess->dir == DIR_ENC) ?
812 (sym_op->cipher.data.length + icv_len) :
813 sym_op->cipher.data.length;
815 DPAA2_SET_FLE_SG_EXT(fle);
817 /* Configure Output SGE for Encap/Decap */
818 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(dst));
819 DPAA2_SET_FLE_OFFSET(sge, sym_op->cipher.data.offset +
821 sge->length = sym_op->cipher.data.length;
823 if (sess->dir == DIR_ENC) {
825 DPAA2_SET_FLE_ADDR(sge,
826 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
827 sge->length = sess->digest_length;
828 DPAA2_SET_FD_LEN(fd, (sym_op->auth.data.length +
831 DPAA2_SET_FLE_FIN(sge);
836 /* Configure Input FLE with Scatter/Gather Entry */
837 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
838 DPAA2_SET_FLE_SG_EXT(fle);
839 DPAA2_SET_FLE_FIN(fle);
840 fle->length = (sess->dir == DIR_ENC) ?
841 (sym_op->auth.data.length + sess->iv.length) :
842 (sym_op->auth.data.length + sess->iv.length +
843 sess->digest_length);
845 /* Configure Input SGE for Encap/Decap */
846 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
847 sge->length = sess->iv.length;
850 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
851 DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset +
852 sym_op->m_src->data_off);
853 sge->length = sym_op->auth.data.length;
854 if (sess->dir == DIR_DEC) {
856 old_icv = (uint8_t *)(sge + 1);
857 memcpy(old_icv, sym_op->auth.digest.data,
858 sess->digest_length);
859 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
860 sge->length = sess->digest_length;
861 DPAA2_SET_FD_LEN(fd, (sym_op->auth.data.length +
862 sess->digest_length +
865 DPAA2_SET_FLE_FIN(sge);
867 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
868 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
873 static inline int build_auth_sg_fd(
874 dpaa2_sec_session *sess,
875 struct rte_crypto_op *op,
877 __rte_unused uint16_t bpid)
879 struct rte_crypto_sym_op *sym_op = op->sym;
880 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
881 struct sec_flow_context *flc;
882 struct ctxt_priv *priv = sess->ctxt;
884 struct rte_mbuf *mbuf;
886 PMD_INIT_FUNC_TRACE();
888 mbuf = sym_op->m_src;
889 fle = (struct qbman_fle *)rte_malloc(NULL, FLE_SG_MEM_SIZE,
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);
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));
918 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
919 DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset + mbuf->data_off);
920 sge->length = mbuf->data_len - sym_op->auth.data.offset;
926 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
927 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
928 sge->length = mbuf->data_len;
931 if (sess->dir == DIR_ENC) {
932 /* Digest calculation case */
933 sge->length -= sess->digest_length;
934 ip_fle->length = sym_op->auth.data.length;
936 /* Digest verification case */
938 old_digest = (uint8_t *)(sge + 1);
939 rte_memcpy(old_digest, sym_op->auth.digest.data,
940 sess->digest_length);
941 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_digest));
942 sge->length = sess->digest_length;
943 ip_fle->length = sym_op->auth.data.length +
946 DPAA2_SET_FLE_FIN(sge);
947 DPAA2_SET_FLE_FIN(ip_fle);
948 DPAA2_SET_FD_LEN(fd, ip_fle->length);
954 build_auth_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
955 struct qbman_fd *fd, uint16_t bpid)
957 struct rte_crypto_sym_op *sym_op = op->sym;
958 struct qbman_fle *fle, *sge;
959 struct sec_flow_context *flc;
960 struct ctxt_priv *priv = sess->ctxt;
964 PMD_INIT_FUNC_TRACE();
966 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
968 DPAA2_SEC_ERR("AUTH Memory alloc failed for SGE");
971 memset(fle, 0, FLE_POOL_BUF_SIZE);
972 /* TODO we are using the first FLE entry to store Mbuf.
973 * Currently we donot know which FLE has the mbuf stored.
974 * So while retreiving we can go back 1 FLE from the FD -ADDR
975 * to get the MBUF Addr from the previous FLE.
976 * We can have a better approach to use the inline Mbuf
978 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
979 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
982 if (likely(bpid < MAX_BPID)) {
983 DPAA2_SET_FD_BPID(fd, bpid);
984 DPAA2_SET_FLE_BPID(fle, bpid);
985 DPAA2_SET_FLE_BPID(fle + 1, bpid);
987 DPAA2_SET_FD_IVP(fd);
988 DPAA2_SET_FLE_IVP(fle);
989 DPAA2_SET_FLE_IVP((fle + 1));
991 flc = &priv->flc_desc[DESC_INITFINAL].flc;
992 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
994 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
995 fle->length = sess->digest_length;
997 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
998 DPAA2_SET_FD_COMPOUND_FMT(fd);
1001 if (sess->dir == DIR_ENC) {
1002 DPAA2_SET_FLE_ADDR(fle,
1003 DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
1004 DPAA2_SET_FLE_OFFSET(fle, sym_op->auth.data.offset +
1005 sym_op->m_src->data_off);
1006 DPAA2_SET_FD_LEN(fd, sym_op->auth.data.length);
1007 fle->length = sym_op->auth.data.length;
1010 DPAA2_SET_FLE_SG_EXT(fle);
1011 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
1013 if (likely(bpid < MAX_BPID)) {
1014 DPAA2_SET_FLE_BPID(sge, bpid);
1015 DPAA2_SET_FLE_BPID(sge + 1, bpid);
1017 DPAA2_SET_FLE_IVP(sge);
1018 DPAA2_SET_FLE_IVP((sge + 1));
1020 DPAA2_SET_FLE_ADDR(sge,
1021 DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
1022 DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset +
1023 sym_op->m_src->data_off);
1025 DPAA2_SET_FD_LEN(fd, sym_op->auth.data.length +
1026 sess->digest_length);
1027 sge->length = sym_op->auth.data.length;
1029 old_digest = (uint8_t *)(sge + 1);
1030 rte_memcpy(old_digest, sym_op->auth.digest.data,
1031 sess->digest_length);
1032 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_digest));
1033 sge->length = sess->digest_length;
1034 fle->length = sym_op->auth.data.length +
1035 sess->digest_length;
1036 DPAA2_SET_FLE_FIN(sge);
1038 DPAA2_SET_FLE_FIN(fle);
1044 build_cipher_sg_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
1045 struct qbman_fd *fd, __rte_unused uint16_t bpid)
1047 struct rte_crypto_sym_op *sym_op = op->sym;
1048 struct qbman_fle *ip_fle, *op_fle, *sge, *fle;
1049 struct sec_flow_context *flc;
1050 struct ctxt_priv *priv = sess->ctxt;
1051 struct rte_mbuf *mbuf;
1052 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1055 PMD_INIT_FUNC_TRACE();
1058 mbuf = sym_op->m_dst;
1060 mbuf = sym_op->m_src;
1062 fle = (struct qbman_fle *)rte_malloc(NULL, FLE_SG_MEM_SIZE,
1063 RTE_CACHE_LINE_SIZE);
1065 DPAA2_SEC_ERR("CIPHER SG: Memory alloc failed for SGE");
1068 memset(fle, 0, FLE_SG_MEM_SIZE);
1069 /* first FLE entry used to store mbuf and session ctxt */
1070 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
1071 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
1077 flc = &priv->flc_desc[0].flc;
1080 "CIPHER SG: cipher_off: 0x%x/length %d, ivlen=%d"
1081 " data_off: 0x%x\n",
1082 sym_op->cipher.data.offset,
1083 sym_op->cipher.data.length,
1085 sym_op->m_src->data_off);
1088 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
1089 op_fle->length = sym_op->cipher.data.length;
1090 DPAA2_SET_FLE_SG_EXT(op_fle);
1093 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1094 DPAA2_SET_FLE_OFFSET(sge, sym_op->cipher.data.offset + mbuf->data_off);
1095 sge->length = mbuf->data_len - sym_op->cipher.data.offset;
1101 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1102 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
1103 sge->length = mbuf->data_len;
1106 DPAA2_SET_FLE_FIN(sge);
1109 "CIPHER SG: 1 - flc = %p, fle = %p FLEaddr = %x-%x, len %d\n",
1110 flc, fle, fle->addr_hi, fle->addr_lo,
1114 mbuf = sym_op->m_src;
1116 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
1117 ip_fle->length = sess->iv.length + sym_op->cipher.data.length;
1118 DPAA2_SET_FLE_SG_EXT(ip_fle);
1121 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
1122 DPAA2_SET_FLE_OFFSET(sge, 0);
1123 sge->length = sess->iv.length;
1128 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1129 DPAA2_SET_FLE_OFFSET(sge, sym_op->cipher.data.offset +
1131 sge->length = mbuf->data_len - sym_op->cipher.data.offset;
1137 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1138 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
1139 sge->length = mbuf->data_len;
1142 DPAA2_SET_FLE_FIN(sge);
1143 DPAA2_SET_FLE_FIN(ip_fle);
1146 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
1147 DPAA2_SET_FD_LEN(fd, ip_fle->length);
1148 DPAA2_SET_FD_COMPOUND_FMT(fd);
1149 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
1152 "CIPHER SG: fdaddr =%" PRIx64 " bpid =%d meta =%d"
1153 " off =%d, len =%d\n",
1154 DPAA2_GET_FD_ADDR(fd),
1155 DPAA2_GET_FD_BPID(fd),
1156 rte_dpaa2_bpid_info[bpid].meta_data_size,
1157 DPAA2_GET_FD_OFFSET(fd),
1158 DPAA2_GET_FD_LEN(fd));
1163 build_cipher_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
1164 struct qbman_fd *fd, uint16_t bpid)
1166 struct rte_crypto_sym_op *sym_op = op->sym;
1167 struct qbman_fle *fle, *sge;
1169 struct sec_flow_context *flc;
1170 struct ctxt_priv *priv = sess->ctxt;
1171 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1173 struct rte_mbuf *dst;
1175 PMD_INIT_FUNC_TRACE();
1178 dst = sym_op->m_dst;
1180 dst = sym_op->m_src;
1182 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
1184 DPAA2_SEC_ERR("CIPHER: Memory alloc failed for SGE");
1187 memset(fle, 0, FLE_POOL_BUF_SIZE);
1188 /* TODO we are using the first FLE entry to store Mbuf.
1189 * Currently we donot know which FLE has the mbuf stored.
1190 * So while retreiving we can go back 1 FLE from the FD -ADDR
1191 * to get the MBUF Addr from the previous FLE.
1192 * We can have a better approach to use the inline Mbuf
1194 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
1195 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
1199 if (likely(bpid < MAX_BPID)) {
1200 DPAA2_SET_FD_BPID(fd, bpid);
1201 DPAA2_SET_FLE_BPID(fle, bpid);
1202 DPAA2_SET_FLE_BPID(fle + 1, bpid);
1203 DPAA2_SET_FLE_BPID(sge, bpid);
1204 DPAA2_SET_FLE_BPID(sge + 1, bpid);
1206 DPAA2_SET_FD_IVP(fd);
1207 DPAA2_SET_FLE_IVP(fle);
1208 DPAA2_SET_FLE_IVP((fle + 1));
1209 DPAA2_SET_FLE_IVP(sge);
1210 DPAA2_SET_FLE_IVP((sge + 1));
1213 flc = &priv->flc_desc[0].flc;
1214 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
1215 DPAA2_SET_FD_LEN(fd, sym_op->cipher.data.length +
1217 DPAA2_SET_FD_COMPOUND_FMT(fd);
1218 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
1221 "CIPHER: cipher_off: 0x%x/length %d, ivlen=%d,"
1222 " data_off: 0x%x\n",
1223 sym_op->cipher.data.offset,
1224 sym_op->cipher.data.length,
1226 sym_op->m_src->data_off);
1228 DPAA2_SET_FLE_ADDR(fle, DPAA2_MBUF_VADDR_TO_IOVA(dst));
1229 DPAA2_SET_FLE_OFFSET(fle, sym_op->cipher.data.offset +
1232 fle->length = sym_op->cipher.data.length + sess->iv.length;
1235 "CIPHER: 1 - flc = %p, fle = %p FLEaddr = %x-%x, length %d\n",
1236 flc, fle, fle->addr_hi, fle->addr_lo,
1241 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
1242 fle->length = sym_op->cipher.data.length + sess->iv.length;
1244 DPAA2_SET_FLE_SG_EXT(fle);
1246 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
1247 sge->length = sess->iv.length;
1250 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
1251 DPAA2_SET_FLE_OFFSET(sge, sym_op->cipher.data.offset +
1252 sym_op->m_src->data_off);
1254 sge->length = sym_op->cipher.data.length;
1255 DPAA2_SET_FLE_FIN(sge);
1256 DPAA2_SET_FLE_FIN(fle);
1259 "CIPHER: fdaddr =%" PRIx64 " bpid =%d meta =%d"
1260 " off =%d, len =%d\n",
1261 DPAA2_GET_FD_ADDR(fd),
1262 DPAA2_GET_FD_BPID(fd),
1263 rte_dpaa2_bpid_info[bpid].meta_data_size,
1264 DPAA2_GET_FD_OFFSET(fd),
1265 DPAA2_GET_FD_LEN(fd));
1271 build_sec_fd(struct rte_crypto_op *op,
1272 struct qbman_fd *fd, uint16_t bpid)
1275 dpaa2_sec_session *sess;
1277 PMD_INIT_FUNC_TRACE();
1279 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION)
1280 sess = (dpaa2_sec_session *)get_sym_session_private_data(
1281 op->sym->session, cryptodev_driver_id);
1282 else if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION)
1283 sess = (dpaa2_sec_session *)get_sec_session_private_data(
1284 op->sym->sec_session);
1288 /* Any of the buffer is segmented*/
1289 if (!rte_pktmbuf_is_contiguous(op->sym->m_src) ||
1290 ((op->sym->m_dst != NULL) &&
1291 !rte_pktmbuf_is_contiguous(op->sym->m_dst))) {
1292 switch (sess->ctxt_type) {
1293 case DPAA2_SEC_CIPHER:
1294 ret = build_cipher_sg_fd(sess, op, fd, bpid);
1296 case DPAA2_SEC_AUTH:
1297 ret = build_auth_sg_fd(sess, op, fd, bpid);
1299 case DPAA2_SEC_AEAD:
1300 ret = build_authenc_gcm_sg_fd(sess, op, fd, bpid);
1302 case DPAA2_SEC_CIPHER_HASH:
1303 ret = build_authenc_sg_fd(sess, op, fd, bpid);
1305 case DPAA2_SEC_IPSEC:
1306 case DPAA2_SEC_PDCP:
1307 ret = build_proto_compound_sg_fd(sess, op, fd, bpid);
1309 case DPAA2_SEC_HASH_CIPHER:
1311 DPAA2_SEC_ERR("error: Unsupported session");
1314 switch (sess->ctxt_type) {
1315 case DPAA2_SEC_CIPHER:
1316 ret = build_cipher_fd(sess, op, fd, bpid);
1318 case DPAA2_SEC_AUTH:
1319 ret = build_auth_fd(sess, op, fd, bpid);
1321 case DPAA2_SEC_AEAD:
1322 ret = build_authenc_gcm_fd(sess, op, fd, bpid);
1324 case DPAA2_SEC_CIPHER_HASH:
1325 ret = build_authenc_fd(sess, op, fd, bpid);
1327 case DPAA2_SEC_IPSEC:
1328 ret = build_proto_fd(sess, op, fd, bpid);
1330 case DPAA2_SEC_PDCP:
1331 ret = build_proto_compound_fd(sess, op, fd, bpid);
1333 case DPAA2_SEC_HASH_CIPHER:
1335 DPAA2_SEC_ERR("error: Unsupported session");
1342 dpaa2_sec_enqueue_burst(void *qp, struct rte_crypto_op **ops,
1345 /* Function to transmit the frames to given device and VQ*/
1348 struct qbman_fd fd_arr[MAX_TX_RING_SLOTS];
1349 uint32_t frames_to_send;
1350 struct qbman_eq_desc eqdesc;
1351 struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
1352 struct qbman_swp *swp;
1353 uint16_t num_tx = 0;
1354 uint32_t flags[MAX_TX_RING_SLOTS] = {0};
1355 /*todo - need to support multiple buffer pools */
1357 struct rte_mempool *mb_pool;
1359 if (unlikely(nb_ops == 0))
1362 if (ops[0]->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
1363 DPAA2_SEC_ERR("sessionless crypto op not supported");
1366 /*Prepare enqueue descriptor*/
1367 qbman_eq_desc_clear(&eqdesc);
1368 qbman_eq_desc_set_no_orp(&eqdesc, DPAA2_EQ_RESP_ERR_FQ);
1369 qbman_eq_desc_set_response(&eqdesc, 0, 0);
1370 qbman_eq_desc_set_fq(&eqdesc, dpaa2_qp->tx_vq.fqid);
1372 if (!DPAA2_PER_LCORE_DPIO) {
1373 ret = dpaa2_affine_qbman_swp();
1375 DPAA2_SEC_ERR("Failure in affining portal");
1379 swp = DPAA2_PER_LCORE_PORTAL;
1382 frames_to_send = (nb_ops > dpaa2_eqcr_size) ?
1383 dpaa2_eqcr_size : nb_ops;
1385 for (loop = 0; loop < frames_to_send; loop++) {
1386 if ((*ops)->sym->m_src->seqn) {
1387 uint8_t dqrr_index = (*ops)->sym->m_src->seqn - 1;
1389 flags[loop] = QBMAN_ENQUEUE_FLAG_DCA | dqrr_index;
1390 DPAA2_PER_LCORE_DQRR_SIZE--;
1391 DPAA2_PER_LCORE_DQRR_HELD &= ~(1 << dqrr_index);
1392 (*ops)->sym->m_src->seqn = DPAA2_INVALID_MBUF_SEQN;
1395 /*Clear the unused FD fields before sending*/
1396 memset(&fd_arr[loop], 0, sizeof(struct qbman_fd));
1397 mb_pool = (*ops)->sym->m_src->pool;
1398 bpid = mempool_to_bpid(mb_pool);
1399 ret = build_sec_fd(*ops, &fd_arr[loop], bpid);
1401 DPAA2_SEC_ERR("error: Improper packet contents"
1402 " for crypto operation");
1408 while (loop < frames_to_send) {
1409 loop += qbman_swp_enqueue_multiple(swp, &eqdesc,
1412 frames_to_send - loop);
1415 num_tx += frames_to_send;
1416 nb_ops -= frames_to_send;
1419 dpaa2_qp->tx_vq.tx_pkts += num_tx;
1420 dpaa2_qp->tx_vq.err_pkts += nb_ops;
1424 static inline struct rte_crypto_op *
1425 sec_simple_fd_to_mbuf(const struct qbman_fd *fd)
1427 struct rte_crypto_op *op;
1428 uint16_t len = DPAA2_GET_FD_LEN(fd);
1430 dpaa2_sec_session *sess_priv;
1432 struct rte_mbuf *mbuf = DPAA2_INLINE_MBUF_FROM_BUF(
1433 DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd)),
1434 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size);
1436 diff = len - mbuf->pkt_len;
1437 mbuf->pkt_len += diff;
1438 mbuf->data_len += diff;
1439 op = (struct rte_crypto_op *)(size_t)mbuf->buf_iova;
1440 mbuf->buf_iova = op->sym->aead.digest.phys_addr;
1441 op->sym->aead.digest.phys_addr = 0L;
1443 sess_priv = (dpaa2_sec_session *)get_sec_session_private_data(
1444 op->sym->sec_session);
1445 if (sess_priv->dir == DIR_ENC)
1446 mbuf->data_off += SEC_FLC_DHR_OUTBOUND;
1448 mbuf->data_off += SEC_FLC_DHR_INBOUND;
1453 static inline struct rte_crypto_op *
1454 sec_fd_to_mbuf(const struct qbman_fd *fd)
1456 struct qbman_fle *fle;
1457 struct rte_crypto_op *op;
1458 struct ctxt_priv *priv;
1459 struct rte_mbuf *dst, *src;
1461 if (DPAA2_FD_GET_FORMAT(fd) == qbman_fd_single)
1462 return sec_simple_fd_to_mbuf(fd);
1464 fle = (struct qbman_fle *)DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd));
1466 DPAA2_SEC_DP_DEBUG("FLE addr = %x - %x, offset = %x\n",
1467 fle->addr_hi, fle->addr_lo, fle->fin_bpid_offset);
1469 /* we are using the first FLE entry to store Mbuf.
1470 * Currently we donot know which FLE has the mbuf stored.
1471 * So while retreiving we can go back 1 FLE from the FD -ADDR
1472 * to get the MBUF Addr from the previous FLE.
1473 * We can have a better approach to use the inline Mbuf
1476 if (unlikely(DPAA2_GET_FD_IVP(fd))) {
1477 /* TODO complete it. */
1478 DPAA2_SEC_ERR("error: non inline buffer");
1481 op = (struct rte_crypto_op *)DPAA2_GET_FLE_ADDR((fle - 1));
1484 src = op->sym->m_src;
1487 if (op->sym->m_dst) {
1488 dst = op->sym->m_dst;
1493 if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
1494 dpaa2_sec_session *sess = (dpaa2_sec_session *)
1495 get_sec_session_private_data(op->sym->sec_session);
1496 if (sess->ctxt_type == DPAA2_SEC_IPSEC ||
1497 sess->ctxt_type == DPAA2_SEC_PDCP) {
1498 uint16_t len = DPAA2_GET_FD_LEN(fd);
1500 while (dst->next != NULL) {
1501 len -= dst->data_len;
1504 dst->data_len = len;
1508 DPAA2_SEC_DP_DEBUG("mbuf %p BMAN buf addr %p,"
1509 " fdaddr =%" PRIx64 " bpid =%d meta =%d off =%d, len =%d\n",
1512 DPAA2_GET_FD_ADDR(fd),
1513 DPAA2_GET_FD_BPID(fd),
1514 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size,
1515 DPAA2_GET_FD_OFFSET(fd),
1516 DPAA2_GET_FD_LEN(fd));
1518 /* free the fle memory */
1519 if (likely(rte_pktmbuf_is_contiguous(src))) {
1520 priv = (struct ctxt_priv *)(size_t)DPAA2_GET_FLE_CTXT(fle - 1);
1521 rte_mempool_put(priv->fle_pool, (void *)(fle-1));
1523 rte_free((void *)(fle-1));
1529 dpaa2_sec_dequeue_burst(void *qp, struct rte_crypto_op **ops,
1532 /* Function is responsible to receive frames for a given device and VQ*/
1533 struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
1534 struct qbman_result *dq_storage;
1535 uint32_t fqid = dpaa2_qp->rx_vq.fqid;
1536 int ret, num_rx = 0;
1537 uint8_t is_last = 0, status;
1538 struct qbman_swp *swp;
1539 const struct qbman_fd *fd;
1540 struct qbman_pull_desc pulldesc;
1542 if (!DPAA2_PER_LCORE_DPIO) {
1543 ret = dpaa2_affine_qbman_swp();
1545 DPAA2_SEC_ERR("Failure in affining portal");
1549 swp = DPAA2_PER_LCORE_PORTAL;
1550 dq_storage = dpaa2_qp->rx_vq.q_storage->dq_storage[0];
1552 qbman_pull_desc_clear(&pulldesc);
1553 qbman_pull_desc_set_numframes(&pulldesc,
1554 (nb_ops > dpaa2_dqrr_size) ?
1555 dpaa2_dqrr_size : nb_ops);
1556 qbman_pull_desc_set_fq(&pulldesc, fqid);
1557 qbman_pull_desc_set_storage(&pulldesc, dq_storage,
1558 (dma_addr_t)DPAA2_VADDR_TO_IOVA(dq_storage),
1561 /*Issue a volatile dequeue command. */
1563 if (qbman_swp_pull(swp, &pulldesc)) {
1565 "SEC VDQ command is not issued : QBMAN busy");
1566 /* Portal was busy, try again */
1572 /* Receive the packets till Last Dequeue entry is found with
1573 * respect to the above issues PULL command.
1576 /* Check if the previous issued command is completed.
1577 * Also seems like the SWP is shared between the Ethernet Driver
1578 * and the SEC driver.
1580 while (!qbman_check_command_complete(dq_storage))
1583 /* Loop until the dq_storage is updated with
1584 * new token by QBMAN
1586 while (!qbman_check_new_result(dq_storage))
1588 /* Check whether Last Pull command is Expired and
1589 * setting Condition for Loop termination
1591 if (qbman_result_DQ_is_pull_complete(dq_storage)) {
1593 /* Check for valid frame. */
1594 status = (uint8_t)qbman_result_DQ_flags(dq_storage);
1596 (status & QBMAN_DQ_STAT_VALIDFRAME) == 0)) {
1597 DPAA2_SEC_DP_DEBUG("No frame is delivered\n");
1602 fd = qbman_result_DQ_fd(dq_storage);
1603 ops[num_rx] = sec_fd_to_mbuf(fd);
1605 if (unlikely(fd->simple.frc)) {
1606 /* TODO Parse SEC errors */
1607 DPAA2_SEC_ERR("SEC returned Error - %x",
1609 ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_ERROR;
1611 ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
1616 } /* End of Packet Rx loop */
1618 dpaa2_qp->rx_vq.rx_pkts += num_rx;
1620 DPAA2_SEC_DP_DEBUG("SEC Received %d Packets\n", num_rx);
1621 /*Return the total number of packets received to DPAA2 app*/
1625 /** Release queue pair */
1627 dpaa2_sec_queue_pair_release(struct rte_cryptodev *dev, uint16_t queue_pair_id)
1629 struct dpaa2_sec_qp *qp =
1630 (struct dpaa2_sec_qp *)dev->data->queue_pairs[queue_pair_id];
1632 PMD_INIT_FUNC_TRACE();
1634 if (qp->rx_vq.q_storage) {
1635 dpaa2_free_dq_storage(qp->rx_vq.q_storage);
1636 rte_free(qp->rx_vq.q_storage);
1640 dev->data->queue_pairs[queue_pair_id] = NULL;
1645 /** Setup a queue pair */
1647 dpaa2_sec_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
1648 __rte_unused const struct rte_cryptodev_qp_conf *qp_conf,
1649 __rte_unused int socket_id)
1651 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
1652 struct dpaa2_sec_qp *qp;
1653 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
1654 struct dpseci_rx_queue_cfg cfg;
1657 PMD_INIT_FUNC_TRACE();
1659 /* If qp is already in use free ring memory and qp metadata. */
1660 if (dev->data->queue_pairs[qp_id] != NULL) {
1661 DPAA2_SEC_INFO("QP already setup");
1665 DPAA2_SEC_DEBUG("dev =%p, queue =%d, conf =%p",
1666 dev, qp_id, qp_conf);
1668 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
1670 qp = rte_malloc(NULL, sizeof(struct dpaa2_sec_qp),
1671 RTE_CACHE_LINE_SIZE);
1673 DPAA2_SEC_ERR("malloc failed for rx/tx queues");
1677 qp->rx_vq.crypto_data = dev->data;
1678 qp->tx_vq.crypto_data = dev->data;
1679 qp->rx_vq.q_storage = rte_malloc("sec dq storage",
1680 sizeof(struct queue_storage_info_t),
1681 RTE_CACHE_LINE_SIZE);
1682 if (!qp->rx_vq.q_storage) {
1683 DPAA2_SEC_ERR("malloc failed for q_storage");
1686 memset(qp->rx_vq.q_storage, 0, sizeof(struct queue_storage_info_t));
1688 if (dpaa2_alloc_dq_storage(qp->rx_vq.q_storage)) {
1689 DPAA2_SEC_ERR("Unable to allocate dequeue storage");
1693 dev->data->queue_pairs[qp_id] = qp;
1695 cfg.options = cfg.options | DPSECI_QUEUE_OPT_USER_CTX;
1696 cfg.user_ctx = (size_t)(&qp->rx_vq);
1697 retcode = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
1702 /** Return the number of allocated queue pairs */
1704 dpaa2_sec_queue_pair_count(struct rte_cryptodev *dev)
1706 PMD_INIT_FUNC_TRACE();
1708 return dev->data->nb_queue_pairs;
1711 /** Returns the size of the aesni gcm session structure */
1713 dpaa2_sec_sym_session_get_size(struct rte_cryptodev *dev __rte_unused)
1715 PMD_INIT_FUNC_TRACE();
1717 return sizeof(dpaa2_sec_session);
1721 dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
1722 struct rte_crypto_sym_xform *xform,
1723 dpaa2_sec_session *session)
1725 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
1726 struct alginfo cipherdata;
1728 struct ctxt_priv *priv;
1729 struct sec_flow_context *flc;
1731 PMD_INIT_FUNC_TRACE();
1733 /* For SEC CIPHER only one descriptor is required. */
1734 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
1735 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
1736 RTE_CACHE_LINE_SIZE);
1738 DPAA2_SEC_ERR("No Memory for priv CTXT");
1742 priv->fle_pool = dev_priv->fle_pool;
1744 flc = &priv->flc_desc[0].flc;
1746 session->cipher_key.data = rte_zmalloc(NULL, xform->cipher.key.length,
1747 RTE_CACHE_LINE_SIZE);
1748 if (session->cipher_key.data == NULL) {
1749 DPAA2_SEC_ERR("No Memory for cipher key");
1753 session->cipher_key.length = xform->cipher.key.length;
1755 memcpy(session->cipher_key.data, xform->cipher.key.data,
1756 xform->cipher.key.length);
1757 cipherdata.key = (size_t)session->cipher_key.data;
1758 cipherdata.keylen = session->cipher_key.length;
1759 cipherdata.key_enc_flags = 0;
1760 cipherdata.key_type = RTA_DATA_IMM;
1762 /* Set IV parameters */
1763 session->iv.offset = xform->cipher.iv.offset;
1764 session->iv.length = xform->cipher.iv.length;
1766 switch (xform->cipher.algo) {
1767 case RTE_CRYPTO_CIPHER_AES_CBC:
1768 cipherdata.algtype = OP_ALG_ALGSEL_AES;
1769 cipherdata.algmode = OP_ALG_AAI_CBC;
1770 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
1772 case RTE_CRYPTO_CIPHER_3DES_CBC:
1773 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
1774 cipherdata.algmode = OP_ALG_AAI_CBC;
1775 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
1777 case RTE_CRYPTO_CIPHER_AES_CTR:
1778 cipherdata.algtype = OP_ALG_ALGSEL_AES;
1779 cipherdata.algmode = OP_ALG_AAI_CTR;
1780 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
1782 case RTE_CRYPTO_CIPHER_3DES_CTR:
1783 case RTE_CRYPTO_CIPHER_AES_ECB:
1784 case RTE_CRYPTO_CIPHER_3DES_ECB:
1785 case RTE_CRYPTO_CIPHER_AES_XTS:
1786 case RTE_CRYPTO_CIPHER_AES_F8:
1787 case RTE_CRYPTO_CIPHER_ARC4:
1788 case RTE_CRYPTO_CIPHER_KASUMI_F8:
1789 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
1790 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
1791 case RTE_CRYPTO_CIPHER_NULL:
1792 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
1793 xform->cipher.algo);
1796 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
1797 xform->cipher.algo);
1800 session->dir = (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
1803 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0, SHR_NEVER,
1804 &cipherdata, NULL, session->iv.length,
1807 DPAA2_SEC_ERR("Crypto: Descriptor build failed");
1811 flc->word1_sdl = (uint8_t)bufsize;
1812 session->ctxt = priv;
1814 for (i = 0; i < bufsize; i++)
1815 DPAA2_SEC_DEBUG("DESC[%d]:0x%x", i, priv->flc_desc[0].desc[i]);
1820 rte_free(session->cipher_key.data);
1826 dpaa2_sec_auth_init(struct rte_cryptodev *dev,
1827 struct rte_crypto_sym_xform *xform,
1828 dpaa2_sec_session *session)
1830 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
1831 struct alginfo authdata;
1833 struct ctxt_priv *priv;
1834 struct sec_flow_context *flc;
1836 PMD_INIT_FUNC_TRACE();
1838 /* For SEC AUTH three descriptors are required for various stages */
1839 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
1840 sizeof(struct ctxt_priv) + 3 *
1841 sizeof(struct sec_flc_desc),
1842 RTE_CACHE_LINE_SIZE);
1844 DPAA2_SEC_ERR("No Memory for priv CTXT");
1848 priv->fle_pool = dev_priv->fle_pool;
1849 flc = &priv->flc_desc[DESC_INITFINAL].flc;
1851 session->auth_key.data = rte_zmalloc(NULL, xform->auth.key.length,
1852 RTE_CACHE_LINE_SIZE);
1853 if (session->auth_key.data == NULL) {
1854 DPAA2_SEC_ERR("Unable to allocate memory for auth key");
1858 session->auth_key.length = xform->auth.key.length;
1860 memcpy(session->auth_key.data, xform->auth.key.data,
1861 xform->auth.key.length);
1862 authdata.key = (size_t)session->auth_key.data;
1863 authdata.keylen = session->auth_key.length;
1864 authdata.key_enc_flags = 0;
1865 authdata.key_type = RTA_DATA_IMM;
1867 session->digest_length = xform->auth.digest_length;
1869 switch (xform->auth.algo) {
1870 case RTE_CRYPTO_AUTH_SHA1_HMAC:
1871 authdata.algtype = OP_ALG_ALGSEL_SHA1;
1872 authdata.algmode = OP_ALG_AAI_HMAC;
1873 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
1875 case RTE_CRYPTO_AUTH_MD5_HMAC:
1876 authdata.algtype = OP_ALG_ALGSEL_MD5;
1877 authdata.algmode = OP_ALG_AAI_HMAC;
1878 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
1880 case RTE_CRYPTO_AUTH_SHA256_HMAC:
1881 authdata.algtype = OP_ALG_ALGSEL_SHA256;
1882 authdata.algmode = OP_ALG_AAI_HMAC;
1883 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
1885 case RTE_CRYPTO_AUTH_SHA384_HMAC:
1886 authdata.algtype = OP_ALG_ALGSEL_SHA384;
1887 authdata.algmode = OP_ALG_AAI_HMAC;
1888 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
1890 case RTE_CRYPTO_AUTH_SHA512_HMAC:
1891 authdata.algtype = OP_ALG_ALGSEL_SHA512;
1892 authdata.algmode = OP_ALG_AAI_HMAC;
1893 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
1895 case RTE_CRYPTO_AUTH_SHA224_HMAC:
1896 authdata.algtype = OP_ALG_ALGSEL_SHA224;
1897 authdata.algmode = OP_ALG_AAI_HMAC;
1898 session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
1900 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
1901 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
1902 case RTE_CRYPTO_AUTH_NULL:
1903 case RTE_CRYPTO_AUTH_SHA1:
1904 case RTE_CRYPTO_AUTH_SHA256:
1905 case RTE_CRYPTO_AUTH_SHA512:
1906 case RTE_CRYPTO_AUTH_SHA224:
1907 case RTE_CRYPTO_AUTH_SHA384:
1908 case RTE_CRYPTO_AUTH_MD5:
1909 case RTE_CRYPTO_AUTH_AES_GMAC:
1910 case RTE_CRYPTO_AUTH_KASUMI_F9:
1911 case RTE_CRYPTO_AUTH_AES_CMAC:
1912 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
1913 case RTE_CRYPTO_AUTH_ZUC_EIA3:
1914 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %un",
1918 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
1922 session->dir = (xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE) ?
1925 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
1926 1, 0, SHR_NEVER, &authdata, !session->dir,
1927 session->digest_length);
1929 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
1933 flc->word1_sdl = (uint8_t)bufsize;
1934 session->ctxt = priv;
1935 for (i = 0; i < bufsize; i++)
1936 DPAA2_SEC_DEBUG("DESC[%d]:0x%x",
1937 i, priv->flc_desc[DESC_INITFINAL].desc[i]);
1943 rte_free(session->auth_key.data);
1949 dpaa2_sec_aead_init(struct rte_cryptodev *dev,
1950 struct rte_crypto_sym_xform *xform,
1951 dpaa2_sec_session *session)
1953 struct dpaa2_sec_aead_ctxt *ctxt = &session->ext_params.aead_ctxt;
1954 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
1955 struct alginfo aeaddata;
1957 struct ctxt_priv *priv;
1958 struct sec_flow_context *flc;
1959 struct rte_crypto_aead_xform *aead_xform = &xform->aead;
1962 PMD_INIT_FUNC_TRACE();
1964 /* Set IV parameters */
1965 session->iv.offset = aead_xform->iv.offset;
1966 session->iv.length = aead_xform->iv.length;
1967 session->ctxt_type = DPAA2_SEC_AEAD;
1969 /* For SEC AEAD only one descriptor is required */
1970 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
1971 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
1972 RTE_CACHE_LINE_SIZE);
1974 DPAA2_SEC_ERR("No Memory for priv CTXT");
1978 priv->fle_pool = dev_priv->fle_pool;
1979 flc = &priv->flc_desc[0].flc;
1981 session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length,
1982 RTE_CACHE_LINE_SIZE);
1983 if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
1984 DPAA2_SEC_ERR("No Memory for aead key");
1988 memcpy(session->aead_key.data, aead_xform->key.data,
1989 aead_xform->key.length);
1991 session->digest_length = aead_xform->digest_length;
1992 session->aead_key.length = aead_xform->key.length;
1993 ctxt->auth_only_len = aead_xform->aad_length;
1995 aeaddata.key = (size_t)session->aead_key.data;
1996 aeaddata.keylen = session->aead_key.length;
1997 aeaddata.key_enc_flags = 0;
1998 aeaddata.key_type = RTA_DATA_IMM;
2000 switch (aead_xform->algo) {
2001 case RTE_CRYPTO_AEAD_AES_GCM:
2002 aeaddata.algtype = OP_ALG_ALGSEL_AES;
2003 aeaddata.algmode = OP_ALG_AAI_GCM;
2004 session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM;
2006 case RTE_CRYPTO_AEAD_AES_CCM:
2007 DPAA2_SEC_ERR("Crypto: Unsupported AEAD alg %u",
2011 DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
2015 session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
2018 priv->flc_desc[0].desc[0] = aeaddata.keylen;
2019 err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
2021 (unsigned int *)priv->flc_desc[0].desc,
2022 &priv->flc_desc[0].desc[1], 1);
2025 DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
2028 if (priv->flc_desc[0].desc[1] & 1) {
2029 aeaddata.key_type = RTA_DATA_IMM;
2031 aeaddata.key = DPAA2_VADDR_TO_IOVA(aeaddata.key);
2032 aeaddata.key_type = RTA_DATA_PTR;
2034 priv->flc_desc[0].desc[0] = 0;
2035 priv->flc_desc[0].desc[1] = 0;
2037 if (session->dir == DIR_ENC)
2038 bufsize = cnstr_shdsc_gcm_encap(
2039 priv->flc_desc[0].desc, 1, 0, SHR_NEVER,
2040 &aeaddata, session->iv.length,
2041 session->digest_length);
2043 bufsize = cnstr_shdsc_gcm_decap(
2044 priv->flc_desc[0].desc, 1, 0, SHR_NEVER,
2045 &aeaddata, session->iv.length,
2046 session->digest_length);
2048 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2052 flc->word1_sdl = (uint8_t)bufsize;
2053 session->ctxt = priv;
2054 for (i = 0; i < bufsize; i++)
2055 DPAA2_SEC_DEBUG("DESC[%d]:0x%x\n",
2056 i, priv->flc_desc[0].desc[i]);
2061 rte_free(session->aead_key.data);
2068 dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
2069 struct rte_crypto_sym_xform *xform,
2070 dpaa2_sec_session *session)
2072 struct dpaa2_sec_aead_ctxt *ctxt = &session->ext_params.aead_ctxt;
2073 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2074 struct alginfo authdata, cipherdata;
2076 struct ctxt_priv *priv;
2077 struct sec_flow_context *flc;
2078 struct rte_crypto_cipher_xform *cipher_xform;
2079 struct rte_crypto_auth_xform *auth_xform;
2082 PMD_INIT_FUNC_TRACE();
2084 if (session->ext_params.aead_ctxt.auth_cipher_text) {
2085 cipher_xform = &xform->cipher;
2086 auth_xform = &xform->next->auth;
2087 session->ctxt_type =
2088 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2089 DPAA2_SEC_CIPHER_HASH : DPAA2_SEC_HASH_CIPHER;
2091 cipher_xform = &xform->next->cipher;
2092 auth_xform = &xform->auth;
2093 session->ctxt_type =
2094 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2095 DPAA2_SEC_HASH_CIPHER : DPAA2_SEC_CIPHER_HASH;
2098 /* Set IV parameters */
2099 session->iv.offset = cipher_xform->iv.offset;
2100 session->iv.length = cipher_xform->iv.length;
2102 /* For SEC AEAD only one descriptor is required */
2103 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2104 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
2105 RTE_CACHE_LINE_SIZE);
2107 DPAA2_SEC_ERR("No Memory for priv CTXT");
2111 priv->fle_pool = dev_priv->fle_pool;
2112 flc = &priv->flc_desc[0].flc;
2114 session->cipher_key.data = rte_zmalloc(NULL, cipher_xform->key.length,
2115 RTE_CACHE_LINE_SIZE);
2116 if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) {
2117 DPAA2_SEC_ERR("No Memory for cipher key");
2121 session->cipher_key.length = cipher_xform->key.length;
2122 session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length,
2123 RTE_CACHE_LINE_SIZE);
2124 if (session->auth_key.data == NULL && auth_xform->key.length > 0) {
2125 DPAA2_SEC_ERR("No Memory for auth key");
2126 rte_free(session->cipher_key.data);
2130 session->auth_key.length = auth_xform->key.length;
2131 memcpy(session->cipher_key.data, cipher_xform->key.data,
2132 cipher_xform->key.length);
2133 memcpy(session->auth_key.data, auth_xform->key.data,
2134 auth_xform->key.length);
2136 authdata.key = (size_t)session->auth_key.data;
2137 authdata.keylen = session->auth_key.length;
2138 authdata.key_enc_flags = 0;
2139 authdata.key_type = RTA_DATA_IMM;
2141 session->digest_length = auth_xform->digest_length;
2143 switch (auth_xform->algo) {
2144 case RTE_CRYPTO_AUTH_SHA1_HMAC:
2145 authdata.algtype = OP_ALG_ALGSEL_SHA1;
2146 authdata.algmode = OP_ALG_AAI_HMAC;
2147 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
2149 case RTE_CRYPTO_AUTH_MD5_HMAC:
2150 authdata.algtype = OP_ALG_ALGSEL_MD5;
2151 authdata.algmode = OP_ALG_AAI_HMAC;
2152 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
2154 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2155 authdata.algtype = OP_ALG_ALGSEL_SHA224;
2156 authdata.algmode = OP_ALG_AAI_HMAC;
2157 session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
2159 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2160 authdata.algtype = OP_ALG_ALGSEL_SHA256;
2161 authdata.algmode = OP_ALG_AAI_HMAC;
2162 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
2164 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2165 authdata.algtype = OP_ALG_ALGSEL_SHA384;
2166 authdata.algmode = OP_ALG_AAI_HMAC;
2167 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
2169 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2170 authdata.algtype = OP_ALG_ALGSEL_SHA512;
2171 authdata.algmode = OP_ALG_AAI_HMAC;
2172 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
2174 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2175 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2176 case RTE_CRYPTO_AUTH_NULL:
2177 case RTE_CRYPTO_AUTH_SHA1:
2178 case RTE_CRYPTO_AUTH_SHA256:
2179 case RTE_CRYPTO_AUTH_SHA512:
2180 case RTE_CRYPTO_AUTH_SHA224:
2181 case RTE_CRYPTO_AUTH_SHA384:
2182 case RTE_CRYPTO_AUTH_MD5:
2183 case RTE_CRYPTO_AUTH_AES_GMAC:
2184 case RTE_CRYPTO_AUTH_KASUMI_F9:
2185 case RTE_CRYPTO_AUTH_AES_CMAC:
2186 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2187 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2188 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
2192 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2196 cipherdata.key = (size_t)session->cipher_key.data;
2197 cipherdata.keylen = session->cipher_key.length;
2198 cipherdata.key_enc_flags = 0;
2199 cipherdata.key_type = RTA_DATA_IMM;
2201 switch (cipher_xform->algo) {
2202 case RTE_CRYPTO_CIPHER_AES_CBC:
2203 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2204 cipherdata.algmode = OP_ALG_AAI_CBC;
2205 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
2207 case RTE_CRYPTO_CIPHER_3DES_CBC:
2208 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
2209 cipherdata.algmode = OP_ALG_AAI_CBC;
2210 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
2212 case RTE_CRYPTO_CIPHER_AES_CTR:
2213 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2214 cipherdata.algmode = OP_ALG_AAI_CTR;
2215 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
2217 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2218 case RTE_CRYPTO_CIPHER_NULL:
2219 case RTE_CRYPTO_CIPHER_3DES_ECB:
2220 case RTE_CRYPTO_CIPHER_AES_ECB:
2221 case RTE_CRYPTO_CIPHER_KASUMI_F8:
2222 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
2223 cipher_xform->algo);
2226 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2227 cipher_xform->algo);
2230 session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2233 priv->flc_desc[0].desc[0] = cipherdata.keylen;
2234 priv->flc_desc[0].desc[1] = authdata.keylen;
2235 err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
2237 (unsigned int *)priv->flc_desc[0].desc,
2238 &priv->flc_desc[0].desc[2], 2);
2241 DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
2244 if (priv->flc_desc[0].desc[2] & 1) {
2245 cipherdata.key_type = RTA_DATA_IMM;
2247 cipherdata.key = DPAA2_VADDR_TO_IOVA(cipherdata.key);
2248 cipherdata.key_type = RTA_DATA_PTR;
2250 if (priv->flc_desc[0].desc[2] & (1 << 1)) {
2251 authdata.key_type = RTA_DATA_IMM;
2253 authdata.key = DPAA2_VADDR_TO_IOVA(authdata.key);
2254 authdata.key_type = RTA_DATA_PTR;
2256 priv->flc_desc[0].desc[0] = 0;
2257 priv->flc_desc[0].desc[1] = 0;
2258 priv->flc_desc[0].desc[2] = 0;
2260 if (session->ctxt_type == DPAA2_SEC_CIPHER_HASH) {
2261 bufsize = cnstr_shdsc_authenc(priv->flc_desc[0].desc, 1,
2263 &cipherdata, &authdata,
2265 ctxt->auth_only_len,
2266 session->digest_length,
2269 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2273 DPAA2_SEC_ERR("Hash before cipher not supported");
2277 flc->word1_sdl = (uint8_t)bufsize;
2278 session->ctxt = priv;
2279 for (i = 0; i < bufsize; i++)
2280 DPAA2_SEC_DEBUG("DESC[%d]:0x%x",
2281 i, priv->flc_desc[0].desc[i]);
2286 rte_free(session->cipher_key.data);
2287 rte_free(session->auth_key.data);
2293 dpaa2_sec_set_session_parameters(struct rte_cryptodev *dev,
2294 struct rte_crypto_sym_xform *xform, void *sess)
2296 dpaa2_sec_session *session = sess;
2299 PMD_INIT_FUNC_TRACE();
2301 if (unlikely(sess == NULL)) {
2302 DPAA2_SEC_ERR("Invalid session struct");
2306 memset(session, 0, sizeof(dpaa2_sec_session));
2307 /* Default IV length = 0 */
2308 session->iv.length = 0;
2311 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
2312 session->ctxt_type = DPAA2_SEC_CIPHER;
2313 ret = dpaa2_sec_cipher_init(dev, xform, session);
2315 /* Authentication Only */
2316 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2317 xform->next == NULL) {
2318 session->ctxt_type = DPAA2_SEC_AUTH;
2319 ret = dpaa2_sec_auth_init(dev, xform, session);
2321 /* Cipher then Authenticate */
2322 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
2323 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2324 session->ext_params.aead_ctxt.auth_cipher_text = true;
2325 ret = dpaa2_sec_aead_chain_init(dev, xform, session);
2327 /* Authenticate then Cipher */
2328 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2329 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2330 session->ext_params.aead_ctxt.auth_cipher_text = false;
2331 ret = dpaa2_sec_aead_chain_init(dev, xform, session);
2333 /* AEAD operation for AES-GCM kind of Algorithms */
2334 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD &&
2335 xform->next == NULL) {
2336 ret = dpaa2_sec_aead_init(dev, xform, session);
2339 DPAA2_SEC_ERR("Invalid crypto type");
2347 dpaa2_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
2348 dpaa2_sec_session *session,
2349 struct alginfo *aeaddata)
2351 PMD_INIT_FUNC_TRACE();
2353 session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length,
2354 RTE_CACHE_LINE_SIZE);
2355 if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
2356 DPAA2_SEC_ERR("No Memory for aead key");
2359 memcpy(session->aead_key.data, aead_xform->key.data,
2360 aead_xform->key.length);
2362 session->digest_length = aead_xform->digest_length;
2363 session->aead_key.length = aead_xform->key.length;
2365 aeaddata->key = (size_t)session->aead_key.data;
2366 aeaddata->keylen = session->aead_key.length;
2367 aeaddata->key_enc_flags = 0;
2368 aeaddata->key_type = RTA_DATA_IMM;
2370 switch (aead_xform->algo) {
2371 case RTE_CRYPTO_AEAD_AES_GCM:
2372 aeaddata->algtype = OP_ALG_ALGSEL_AES;
2373 aeaddata->algmode = OP_ALG_AAI_GCM;
2374 session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM;
2376 case RTE_CRYPTO_AEAD_AES_CCM:
2377 aeaddata->algtype = OP_ALG_ALGSEL_AES;
2378 aeaddata->algmode = OP_ALG_AAI_CCM;
2379 session->aead_alg = RTE_CRYPTO_AEAD_AES_CCM;
2382 DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
2386 session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
2393 dpaa2_sec_ipsec_proto_init(struct rte_crypto_cipher_xform *cipher_xform,
2394 struct rte_crypto_auth_xform *auth_xform,
2395 dpaa2_sec_session *session,
2396 struct alginfo *cipherdata,
2397 struct alginfo *authdata)
2400 session->cipher_key.data = rte_zmalloc(NULL,
2401 cipher_xform->key.length,
2402 RTE_CACHE_LINE_SIZE);
2403 if (session->cipher_key.data == NULL &&
2404 cipher_xform->key.length > 0) {
2405 DPAA2_SEC_ERR("No Memory for cipher key");
2409 session->cipher_key.length = cipher_xform->key.length;
2410 memcpy(session->cipher_key.data, cipher_xform->key.data,
2411 cipher_xform->key.length);
2412 session->cipher_alg = cipher_xform->algo;
2414 session->cipher_key.data = NULL;
2415 session->cipher_key.length = 0;
2416 session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
2420 session->auth_key.data = rte_zmalloc(NULL,
2421 auth_xform->key.length,
2422 RTE_CACHE_LINE_SIZE);
2423 if (session->auth_key.data == NULL &&
2424 auth_xform->key.length > 0) {
2425 DPAA2_SEC_ERR("No Memory for auth key");
2428 session->auth_key.length = auth_xform->key.length;
2429 memcpy(session->auth_key.data, auth_xform->key.data,
2430 auth_xform->key.length);
2431 session->auth_alg = auth_xform->algo;
2433 session->auth_key.data = NULL;
2434 session->auth_key.length = 0;
2435 session->auth_alg = RTE_CRYPTO_AUTH_NULL;
2438 authdata->key = (size_t)session->auth_key.data;
2439 authdata->keylen = session->auth_key.length;
2440 authdata->key_enc_flags = 0;
2441 authdata->key_type = RTA_DATA_IMM;
2442 switch (session->auth_alg) {
2443 case RTE_CRYPTO_AUTH_SHA1_HMAC:
2444 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA1_96;
2445 authdata->algmode = OP_ALG_AAI_HMAC;
2447 case RTE_CRYPTO_AUTH_MD5_HMAC:
2448 authdata->algtype = OP_PCL_IPSEC_HMAC_MD5_96;
2449 authdata->algmode = OP_ALG_AAI_HMAC;
2451 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2452 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_256_128;
2453 authdata->algmode = OP_ALG_AAI_HMAC;
2455 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2456 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_384_192;
2457 authdata->algmode = OP_ALG_AAI_HMAC;
2459 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2460 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_512_256;
2461 authdata->algmode = OP_ALG_AAI_HMAC;
2463 case RTE_CRYPTO_AUTH_AES_CMAC:
2464 authdata->algtype = OP_PCL_IPSEC_AES_CMAC_96;
2466 case RTE_CRYPTO_AUTH_NULL:
2467 authdata->algtype = OP_PCL_IPSEC_HMAC_NULL;
2469 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2470 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2471 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2472 case RTE_CRYPTO_AUTH_SHA1:
2473 case RTE_CRYPTO_AUTH_SHA256:
2474 case RTE_CRYPTO_AUTH_SHA512:
2475 case RTE_CRYPTO_AUTH_SHA224:
2476 case RTE_CRYPTO_AUTH_SHA384:
2477 case RTE_CRYPTO_AUTH_MD5:
2478 case RTE_CRYPTO_AUTH_AES_GMAC:
2479 case RTE_CRYPTO_AUTH_KASUMI_F9:
2480 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2481 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2482 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
2486 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2490 cipherdata->key = (size_t)session->cipher_key.data;
2491 cipherdata->keylen = session->cipher_key.length;
2492 cipherdata->key_enc_flags = 0;
2493 cipherdata->key_type = RTA_DATA_IMM;
2495 switch (session->cipher_alg) {
2496 case RTE_CRYPTO_CIPHER_AES_CBC:
2497 cipherdata->algtype = OP_PCL_IPSEC_AES_CBC;
2498 cipherdata->algmode = OP_ALG_AAI_CBC;
2500 case RTE_CRYPTO_CIPHER_3DES_CBC:
2501 cipherdata->algtype = OP_PCL_IPSEC_3DES;
2502 cipherdata->algmode = OP_ALG_AAI_CBC;
2504 case RTE_CRYPTO_CIPHER_AES_CTR:
2505 cipherdata->algtype = OP_PCL_IPSEC_AES_CTR;
2506 cipherdata->algmode = OP_ALG_AAI_CTR;
2508 case RTE_CRYPTO_CIPHER_NULL:
2509 cipherdata->algtype = OP_PCL_IPSEC_NULL;
2511 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2512 case RTE_CRYPTO_CIPHER_3DES_ECB:
2513 case RTE_CRYPTO_CIPHER_AES_ECB:
2514 case RTE_CRYPTO_CIPHER_KASUMI_F8:
2515 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
2516 session->cipher_alg);
2519 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2520 session->cipher_alg);
2527 #ifdef RTE_LIBRTE_SECURITY_TEST
2528 static uint8_t aes_cbc_iv[] = {
2529 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2530 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
2534 dpaa2_sec_set_ipsec_session(struct rte_cryptodev *dev,
2535 struct rte_security_session_conf *conf,
2538 struct rte_security_ipsec_xform *ipsec_xform = &conf->ipsec;
2539 struct rte_crypto_cipher_xform *cipher_xform = NULL;
2540 struct rte_crypto_auth_xform *auth_xform = NULL;
2541 struct rte_crypto_aead_xform *aead_xform = NULL;
2542 dpaa2_sec_session *session = (dpaa2_sec_session *)sess;
2543 struct ctxt_priv *priv;
2544 struct ipsec_encap_pdb encap_pdb;
2545 struct ipsec_decap_pdb decap_pdb;
2546 struct alginfo authdata, cipherdata;
2548 struct sec_flow_context *flc;
2549 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2552 PMD_INIT_FUNC_TRACE();
2554 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2555 sizeof(struct ctxt_priv) +
2556 sizeof(struct sec_flc_desc),
2557 RTE_CACHE_LINE_SIZE);
2560 DPAA2_SEC_ERR("No memory for priv CTXT");
2564 priv->fle_pool = dev_priv->fle_pool;
2565 flc = &priv->flc_desc[0].flc;
2567 memset(session, 0, sizeof(dpaa2_sec_session));
2569 if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2570 cipher_xform = &conf->crypto_xform->cipher;
2571 if (conf->crypto_xform->next)
2572 auth_xform = &conf->crypto_xform->next->auth;
2573 ret = dpaa2_sec_ipsec_proto_init(cipher_xform, auth_xform,
2574 session, &cipherdata, &authdata);
2575 } else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2576 auth_xform = &conf->crypto_xform->auth;
2577 if (conf->crypto_xform->next)
2578 cipher_xform = &conf->crypto_xform->next->cipher;
2579 ret = dpaa2_sec_ipsec_proto_init(cipher_xform, auth_xform,
2580 session, &cipherdata, &authdata);
2581 } else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
2582 aead_xform = &conf->crypto_xform->aead;
2583 ret = dpaa2_sec_ipsec_aead_init(aead_xform,
2584 session, &cipherdata);
2586 DPAA2_SEC_ERR("XFORM not specified");
2591 DPAA2_SEC_ERR("Failed to process xform");
2595 session->ctxt_type = DPAA2_SEC_IPSEC;
2596 if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
2597 uint8_t *hdr = NULL;
2599 struct rte_ipv6_hdr ip6_hdr;
2601 flc->dhr = SEC_FLC_DHR_OUTBOUND;
2602 /* For Sec Proto only one descriptor is required. */
2603 memset(&encap_pdb, 0, sizeof(struct ipsec_encap_pdb));
2604 encap_pdb.options = (IPVERSION << PDBNH_ESP_ENCAP_SHIFT) |
2605 PDBOPTS_ESP_OIHI_PDB_INL |
2607 PDBHMO_ESP_ENCAP_DTTL |
2609 if (ipsec_xform->options.esn)
2610 encap_pdb.options |= PDBOPTS_ESP_ESN;
2611 encap_pdb.spi = ipsec_xform->spi;
2612 session->dir = DIR_ENC;
2613 if (ipsec_xform->tunnel.type ==
2614 RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
2615 encap_pdb.ip_hdr_len = sizeof(struct ip);
2616 ip4_hdr.ip_v = IPVERSION;
2618 ip4_hdr.ip_len = rte_cpu_to_be_16(sizeof(ip4_hdr));
2619 ip4_hdr.ip_tos = ipsec_xform->tunnel.ipv4.dscp;
2622 ip4_hdr.ip_ttl = ipsec_xform->tunnel.ipv4.ttl;
2623 ip4_hdr.ip_p = IPPROTO_ESP;
2625 ip4_hdr.ip_src = ipsec_xform->tunnel.ipv4.src_ip;
2626 ip4_hdr.ip_dst = ipsec_xform->tunnel.ipv4.dst_ip;
2627 ip4_hdr.ip_sum = calc_chksum((uint16_t *)(void *)
2628 &ip4_hdr, sizeof(struct ip));
2629 hdr = (uint8_t *)&ip4_hdr;
2630 } else if (ipsec_xform->tunnel.type ==
2631 RTE_SECURITY_IPSEC_TUNNEL_IPV6) {
2632 ip6_hdr.vtc_flow = rte_cpu_to_be_32(
2633 DPAA2_IPv6_DEFAULT_VTC_FLOW |
2634 ((ipsec_xform->tunnel.ipv6.dscp <<
2635 RTE_IPV6_HDR_TC_SHIFT) &
2636 RTE_IPV6_HDR_TC_MASK) |
2637 ((ipsec_xform->tunnel.ipv6.flabel <<
2638 RTE_IPV6_HDR_FL_SHIFT) &
2639 RTE_IPV6_HDR_FL_MASK));
2640 /* Payload length will be updated by HW */
2641 ip6_hdr.payload_len = 0;
2642 ip6_hdr.hop_limits =
2643 ipsec_xform->tunnel.ipv6.hlimit;
2644 ip6_hdr.proto = (ipsec_xform->proto ==
2645 RTE_SECURITY_IPSEC_SA_PROTO_ESP) ?
2646 IPPROTO_ESP : IPPROTO_AH;
2647 memcpy(&ip6_hdr.src_addr,
2648 &ipsec_xform->tunnel.ipv6.src_addr, 16);
2649 memcpy(&ip6_hdr.dst_addr,
2650 &ipsec_xform->tunnel.ipv6.dst_addr, 16);
2651 encap_pdb.ip_hdr_len = sizeof(struct rte_ipv6_hdr);
2652 hdr = (uint8_t *)&ip6_hdr;
2655 bufsize = cnstr_shdsc_ipsec_new_encap(priv->flc_desc[0].desc,
2656 1, 0, SHR_SERIAL, &encap_pdb,
2657 hdr, &cipherdata, &authdata);
2658 } else if (ipsec_xform->direction ==
2659 RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
2660 flc->dhr = SEC_FLC_DHR_INBOUND;
2661 memset(&decap_pdb, 0, sizeof(struct ipsec_decap_pdb));
2662 decap_pdb.options = sizeof(struct ip) << 16;
2663 if (ipsec_xform->options.esn)
2664 decap_pdb.options |= PDBOPTS_ESP_ESN;
2665 decap_pdb.options = (ipsec_xform->tunnel.type ==
2666 RTE_SECURITY_IPSEC_TUNNEL_IPV4) ?
2667 sizeof(struct ip) << 16 :
2668 sizeof(struct rte_ipv6_hdr) << 16;
2669 session->dir = DIR_DEC;
2670 bufsize = cnstr_shdsc_ipsec_new_decap(priv->flc_desc[0].desc,
2672 &decap_pdb, &cipherdata, &authdata);
2677 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2681 flc->word1_sdl = (uint8_t)bufsize;
2683 /* Enable the stashing control bit */
2684 DPAA2_SET_FLC_RSC(flc);
2685 flc->word2_rflc_31_0 = lower_32_bits(
2686 (size_t)&(((struct dpaa2_sec_qp *)
2687 dev->data->queue_pairs[0])->rx_vq) | 0x14);
2688 flc->word3_rflc_63_32 = upper_32_bits(
2689 (size_t)&(((struct dpaa2_sec_qp *)
2690 dev->data->queue_pairs[0])->rx_vq));
2692 /* Set EWS bit i.e. enable write-safe */
2693 DPAA2_SET_FLC_EWS(flc);
2694 /* Set BS = 1 i.e reuse input buffers as output buffers */
2695 DPAA2_SET_FLC_REUSE_BS(flc);
2696 /* Set FF = 10; reuse input buffers if they provide sufficient space */
2697 DPAA2_SET_FLC_REUSE_FF(flc);
2699 session->ctxt = priv;
2703 rte_free(session->auth_key.data);
2704 rte_free(session->cipher_key.data);
2710 dpaa2_sec_set_pdcp_session(struct rte_cryptodev *dev,
2711 struct rte_security_session_conf *conf,
2714 struct rte_security_pdcp_xform *pdcp_xform = &conf->pdcp;
2715 struct rte_crypto_sym_xform *xform = conf->crypto_xform;
2716 struct rte_crypto_auth_xform *auth_xform = NULL;
2717 struct rte_crypto_cipher_xform *cipher_xform;
2718 dpaa2_sec_session *session = (dpaa2_sec_session *)sess;
2719 struct ctxt_priv *priv;
2720 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2721 struct alginfo authdata, cipherdata;
2722 struct alginfo *p_authdata = NULL;
2724 struct sec_flow_context *flc;
2725 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
2731 PMD_INIT_FUNC_TRACE();
2733 memset(session, 0, sizeof(dpaa2_sec_session));
2735 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2736 sizeof(struct ctxt_priv) +
2737 sizeof(struct sec_flc_desc),
2738 RTE_CACHE_LINE_SIZE);
2741 DPAA2_SEC_ERR("No memory for priv CTXT");
2745 priv->fle_pool = dev_priv->fle_pool;
2746 flc = &priv->flc_desc[0].flc;
2748 /* find xfrm types */
2749 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
2750 cipher_xform = &xform->cipher;
2751 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
2752 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2753 session->ext_params.aead_ctxt.auth_cipher_text = true;
2754 cipher_xform = &xform->cipher;
2755 auth_xform = &xform->next->auth;
2756 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2757 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2758 session->ext_params.aead_ctxt.auth_cipher_text = false;
2759 cipher_xform = &xform->next->cipher;
2760 auth_xform = &xform->auth;
2762 DPAA2_SEC_ERR("Invalid crypto type");
2766 session->ctxt_type = DPAA2_SEC_PDCP;
2768 session->cipher_key.data = rte_zmalloc(NULL,
2769 cipher_xform->key.length,
2770 RTE_CACHE_LINE_SIZE);
2771 if (session->cipher_key.data == NULL &&
2772 cipher_xform->key.length > 0) {
2773 DPAA2_SEC_ERR("No Memory for cipher key");
2777 session->cipher_key.length = cipher_xform->key.length;
2778 memcpy(session->cipher_key.data, cipher_xform->key.data,
2779 cipher_xform->key.length);
2781 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2783 session->cipher_alg = cipher_xform->algo;
2785 session->cipher_key.data = NULL;
2786 session->cipher_key.length = 0;
2787 session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
2788 session->dir = DIR_ENC;
2791 session->pdcp.domain = pdcp_xform->domain;
2792 session->pdcp.bearer = pdcp_xform->bearer;
2793 session->pdcp.pkt_dir = pdcp_xform->pkt_dir;
2794 session->pdcp.sn_size = pdcp_xform->sn_size;
2795 session->pdcp.hfn = pdcp_xform->hfn;
2796 session->pdcp.hfn_threshold = pdcp_xform->hfn_threshold;
2797 session->pdcp.hfn_ovd = pdcp_xform->hfn_ovrd;
2798 /* hfv ovd offset location is stored in iv.offset value*/
2799 session->pdcp.hfn_ovd_offset = cipher_xform->iv.offset;
2801 cipherdata.key = (size_t)session->cipher_key.data;
2802 cipherdata.keylen = session->cipher_key.length;
2803 cipherdata.key_enc_flags = 0;
2804 cipherdata.key_type = RTA_DATA_IMM;
2806 switch (session->cipher_alg) {
2807 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2808 cipherdata.algtype = PDCP_CIPHER_TYPE_SNOW;
2810 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
2811 cipherdata.algtype = PDCP_CIPHER_TYPE_ZUC;
2813 case RTE_CRYPTO_CIPHER_AES_CTR:
2814 cipherdata.algtype = PDCP_CIPHER_TYPE_AES;
2816 case RTE_CRYPTO_CIPHER_NULL:
2817 cipherdata.algtype = PDCP_CIPHER_TYPE_NULL;
2820 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2821 session->cipher_alg);
2826 session->auth_key.data = rte_zmalloc(NULL,
2827 auth_xform->key.length,
2828 RTE_CACHE_LINE_SIZE);
2829 if (!session->auth_key.data &&
2830 auth_xform->key.length > 0) {
2831 DPAA2_SEC_ERR("No Memory for auth key");
2832 rte_free(session->cipher_key.data);
2836 session->auth_key.length = auth_xform->key.length;
2837 memcpy(session->auth_key.data, auth_xform->key.data,
2838 auth_xform->key.length);
2839 session->auth_alg = auth_xform->algo;
2841 session->auth_key.data = NULL;
2842 session->auth_key.length = 0;
2843 session->auth_alg = 0;
2845 authdata.key = (size_t)session->auth_key.data;
2846 authdata.keylen = session->auth_key.length;
2847 authdata.key_enc_flags = 0;
2848 authdata.key_type = RTA_DATA_IMM;
2850 if (session->auth_alg) {
2851 switch (session->auth_alg) {
2852 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2853 authdata.algtype = PDCP_AUTH_TYPE_SNOW;
2855 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2856 authdata.algtype = PDCP_AUTH_TYPE_ZUC;
2858 case RTE_CRYPTO_AUTH_AES_CMAC:
2859 authdata.algtype = PDCP_AUTH_TYPE_AES;
2861 case RTE_CRYPTO_AUTH_NULL:
2862 authdata.algtype = PDCP_AUTH_TYPE_NULL;
2865 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
2870 p_authdata = &authdata;
2871 } else if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
2872 DPAA2_SEC_ERR("Crypto: Integrity must for c-plane");
2876 if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
2877 if (session->dir == DIR_ENC)
2878 bufsize = cnstr_shdsc_pdcp_c_plane_encap(
2879 priv->flc_desc[0].desc, 1, swap,
2881 session->pdcp.sn_size,
2883 pdcp_xform->pkt_dir,
2884 pdcp_xform->hfn_threshold,
2885 &cipherdata, &authdata,
2887 else if (session->dir == DIR_DEC)
2888 bufsize = cnstr_shdsc_pdcp_c_plane_decap(
2889 priv->flc_desc[0].desc, 1, swap,
2891 session->pdcp.sn_size,
2893 pdcp_xform->pkt_dir,
2894 pdcp_xform->hfn_threshold,
2895 &cipherdata, &authdata,
2898 if (session->dir == DIR_ENC)
2899 bufsize = cnstr_shdsc_pdcp_u_plane_encap(
2900 priv->flc_desc[0].desc, 1, swap,
2901 session->pdcp.sn_size,
2904 pdcp_xform->pkt_dir,
2905 pdcp_xform->hfn_threshold,
2906 &cipherdata, p_authdata, 0);
2907 else if (session->dir == DIR_DEC)
2908 bufsize = cnstr_shdsc_pdcp_u_plane_decap(
2909 priv->flc_desc[0].desc, 1, swap,
2910 session->pdcp.sn_size,
2913 pdcp_xform->pkt_dir,
2914 pdcp_xform->hfn_threshold,
2915 &cipherdata, p_authdata, 0);
2919 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2923 /* Enable the stashing control bit */
2924 DPAA2_SET_FLC_RSC(flc);
2925 flc->word2_rflc_31_0 = lower_32_bits(
2926 (size_t)&(((struct dpaa2_sec_qp *)
2927 dev->data->queue_pairs[0])->rx_vq) | 0x14);
2928 flc->word3_rflc_63_32 = upper_32_bits(
2929 (size_t)&(((struct dpaa2_sec_qp *)
2930 dev->data->queue_pairs[0])->rx_vq));
2932 flc->word1_sdl = (uint8_t)bufsize;
2934 /* Set EWS bit i.e. enable write-safe */
2935 DPAA2_SET_FLC_EWS(flc);
2936 /* Set BS = 1 i.e reuse input buffers as output buffers */
2937 DPAA2_SET_FLC_REUSE_BS(flc);
2938 /* Set FF = 10; reuse input buffers if they provide sufficient space */
2939 DPAA2_SET_FLC_REUSE_FF(flc);
2941 session->ctxt = priv;
2945 rte_free(session->auth_key.data);
2946 rte_free(session->cipher_key.data);
2952 dpaa2_sec_security_session_create(void *dev,
2953 struct rte_security_session_conf *conf,
2954 struct rte_security_session *sess,
2955 struct rte_mempool *mempool)
2957 void *sess_private_data;
2958 struct rte_cryptodev *cdev = (struct rte_cryptodev *)dev;
2961 if (rte_mempool_get(mempool, &sess_private_data)) {
2962 DPAA2_SEC_ERR("Couldn't get object from session mempool");
2966 switch (conf->protocol) {
2967 case RTE_SECURITY_PROTOCOL_IPSEC:
2968 ret = dpaa2_sec_set_ipsec_session(cdev, conf,
2971 case RTE_SECURITY_PROTOCOL_MACSEC:
2973 case RTE_SECURITY_PROTOCOL_PDCP:
2974 ret = dpaa2_sec_set_pdcp_session(cdev, conf,
2981 DPAA2_SEC_ERR("Failed to configure session parameters");
2982 /* Return session to mempool */
2983 rte_mempool_put(mempool, sess_private_data);
2987 set_sec_session_private_data(sess, sess_private_data);
2992 /** Clear the memory of session so it doesn't leave key material behind */
2994 dpaa2_sec_security_session_destroy(void *dev __rte_unused,
2995 struct rte_security_session *sess)
2997 PMD_INIT_FUNC_TRACE();
2998 void *sess_priv = get_sec_session_private_data(sess);
3000 dpaa2_sec_session *s = (dpaa2_sec_session *)sess_priv;
3003 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
3006 rte_free(s->cipher_key.data);
3007 rte_free(s->auth_key.data);
3008 memset(s, 0, sizeof(dpaa2_sec_session));
3009 set_sec_session_private_data(sess, NULL);
3010 rte_mempool_put(sess_mp, sess_priv);
3016 dpaa2_sec_sym_session_configure(struct rte_cryptodev *dev,
3017 struct rte_crypto_sym_xform *xform,
3018 struct rte_cryptodev_sym_session *sess,
3019 struct rte_mempool *mempool)
3021 void *sess_private_data;
3024 if (rte_mempool_get(mempool, &sess_private_data)) {
3025 DPAA2_SEC_ERR("Couldn't get object from session mempool");
3029 ret = dpaa2_sec_set_session_parameters(dev, xform, sess_private_data);
3031 DPAA2_SEC_ERR("Failed to configure session parameters");
3032 /* Return session to mempool */
3033 rte_mempool_put(mempool, sess_private_data);
3037 set_sym_session_private_data(sess, dev->driver_id,
3043 /** Clear the memory of session so it doesn't leave key material behind */
3045 dpaa2_sec_sym_session_clear(struct rte_cryptodev *dev,
3046 struct rte_cryptodev_sym_session *sess)
3048 PMD_INIT_FUNC_TRACE();
3049 uint8_t index = dev->driver_id;
3050 void *sess_priv = get_sym_session_private_data(sess, index);
3051 dpaa2_sec_session *s = (dpaa2_sec_session *)sess_priv;
3055 rte_free(s->cipher_key.data);
3056 rte_free(s->auth_key.data);
3057 memset(s, 0, sizeof(dpaa2_sec_session));
3058 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
3059 set_sym_session_private_data(sess, index, NULL);
3060 rte_mempool_put(sess_mp, sess_priv);
3065 dpaa2_sec_dev_configure(struct rte_cryptodev *dev __rte_unused,
3066 struct rte_cryptodev_config *config __rte_unused)
3068 PMD_INIT_FUNC_TRACE();
3074 dpaa2_sec_dev_start(struct rte_cryptodev *dev)
3076 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3077 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3078 struct dpseci_attr attr;
3079 struct dpaa2_queue *dpaa2_q;
3080 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3081 dev->data->queue_pairs;
3082 struct dpseci_rx_queue_attr rx_attr;
3083 struct dpseci_tx_queue_attr tx_attr;
3086 PMD_INIT_FUNC_TRACE();
3088 memset(&attr, 0, sizeof(struct dpseci_attr));
3090 ret = dpseci_enable(dpseci, CMD_PRI_LOW, priv->token);
3092 DPAA2_SEC_ERR("DPSECI with HW_ID = %d ENABLE FAILED",
3094 goto get_attr_failure;
3096 ret = dpseci_get_attributes(dpseci, CMD_PRI_LOW, priv->token, &attr);
3098 DPAA2_SEC_ERR("DPSEC ATTRIBUTE READ FAILED, disabling DPSEC");
3099 goto get_attr_failure;
3101 for (i = 0; i < attr.num_rx_queues && qp[i]; i++) {
3102 dpaa2_q = &qp[i]->rx_vq;
3103 dpseci_get_rx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
3105 dpaa2_q->fqid = rx_attr.fqid;
3106 DPAA2_SEC_DEBUG("rx_fqid: %d", dpaa2_q->fqid);
3108 for (i = 0; i < attr.num_tx_queues && qp[i]; i++) {
3109 dpaa2_q = &qp[i]->tx_vq;
3110 dpseci_get_tx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
3112 dpaa2_q->fqid = tx_attr.fqid;
3113 DPAA2_SEC_DEBUG("tx_fqid: %d", dpaa2_q->fqid);
3118 dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
3123 dpaa2_sec_dev_stop(struct rte_cryptodev *dev)
3125 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3126 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3129 PMD_INIT_FUNC_TRACE();
3131 ret = dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
3133 DPAA2_SEC_ERR("Failure in disabling dpseci %d device",
3138 ret = dpseci_reset(dpseci, CMD_PRI_LOW, priv->token);
3140 DPAA2_SEC_ERR("SEC Device cannot be reset:Error = %0x", ret);
3146 dpaa2_sec_dev_close(struct rte_cryptodev *dev)
3148 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3149 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3152 PMD_INIT_FUNC_TRACE();
3154 /* Function is reverse of dpaa2_sec_dev_init.
3155 * It does the following:
3156 * 1. Detach a DPSECI from attached resources i.e. buffer pools, dpbp_id
3157 * 2. Close the DPSECI device
3158 * 3. Free the allocated resources.
3161 /*Close the device at underlying layer*/
3162 ret = dpseci_close(dpseci, CMD_PRI_LOW, priv->token);
3164 DPAA2_SEC_ERR("Failure closing dpseci device: err(%d)", ret);
3168 /*Free the allocated memory for ethernet private data and dpseci*/
3176 dpaa2_sec_dev_infos_get(struct rte_cryptodev *dev,
3177 struct rte_cryptodev_info *info)
3179 struct dpaa2_sec_dev_private *internals = dev->data->dev_private;
3181 PMD_INIT_FUNC_TRACE();
3183 info->max_nb_queue_pairs = internals->max_nb_queue_pairs;
3184 info->feature_flags = dev->feature_flags;
3185 info->capabilities = dpaa2_sec_capabilities;
3186 /* No limit of number of sessions */
3187 info->sym.max_nb_sessions = 0;
3188 info->driver_id = cryptodev_driver_id;
3193 void dpaa2_sec_stats_get(struct rte_cryptodev *dev,
3194 struct rte_cryptodev_stats *stats)
3196 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3197 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3198 struct dpseci_sec_counters counters = {0};
3199 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3200 dev->data->queue_pairs;
3203 PMD_INIT_FUNC_TRACE();
3204 if (stats == NULL) {
3205 DPAA2_SEC_ERR("Invalid stats ptr NULL");
3208 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
3209 if (qp[i] == NULL) {
3210 DPAA2_SEC_DEBUG("Uninitialised queue pair");
3214 stats->enqueued_count += qp[i]->tx_vq.tx_pkts;
3215 stats->dequeued_count += qp[i]->rx_vq.rx_pkts;
3216 stats->enqueue_err_count += qp[i]->tx_vq.err_pkts;
3217 stats->dequeue_err_count += qp[i]->rx_vq.err_pkts;
3220 ret = dpseci_get_sec_counters(dpseci, CMD_PRI_LOW, priv->token,
3223 DPAA2_SEC_ERR("SEC counters failed");
3225 DPAA2_SEC_INFO("dpseci hardware stats:"
3226 "\n\tNum of Requests Dequeued = %" PRIu64
3227 "\n\tNum of Outbound Encrypt Requests = %" PRIu64
3228 "\n\tNum of Inbound Decrypt Requests = %" PRIu64
3229 "\n\tNum of Outbound Bytes Encrypted = %" PRIu64
3230 "\n\tNum of Outbound Bytes Protected = %" PRIu64
3231 "\n\tNum of Inbound Bytes Decrypted = %" PRIu64
3232 "\n\tNum of Inbound Bytes Validated = %" PRIu64,
3233 counters.dequeued_requests,
3234 counters.ob_enc_requests,
3235 counters.ib_dec_requests,
3236 counters.ob_enc_bytes,
3237 counters.ob_prot_bytes,
3238 counters.ib_dec_bytes,
3239 counters.ib_valid_bytes);
3244 void dpaa2_sec_stats_reset(struct rte_cryptodev *dev)
3247 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3248 (dev->data->queue_pairs);
3250 PMD_INIT_FUNC_TRACE();
3252 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
3253 if (qp[i] == NULL) {
3254 DPAA2_SEC_DEBUG("Uninitialised queue pair");
3257 qp[i]->tx_vq.rx_pkts = 0;
3258 qp[i]->tx_vq.tx_pkts = 0;
3259 qp[i]->tx_vq.err_pkts = 0;
3260 qp[i]->rx_vq.rx_pkts = 0;
3261 qp[i]->rx_vq.tx_pkts = 0;
3262 qp[i]->rx_vq.err_pkts = 0;
3266 static void __attribute__((hot))
3267 dpaa2_sec_process_parallel_event(struct qbman_swp *swp,
3268 const struct qbman_fd *fd,
3269 const struct qbman_result *dq,
3270 struct dpaa2_queue *rxq,
3271 struct rte_event *ev)
3273 /* Prefetching mbuf */
3274 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-
3275 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size));
3277 /* Prefetching ipsec crypto_op stored in priv data of mbuf */
3278 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-64));
3280 ev->flow_id = rxq->ev.flow_id;
3281 ev->sub_event_type = rxq->ev.sub_event_type;
3282 ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
3283 ev->op = RTE_EVENT_OP_NEW;
3284 ev->sched_type = rxq->ev.sched_type;
3285 ev->queue_id = rxq->ev.queue_id;
3286 ev->priority = rxq->ev.priority;
3287 ev->event_ptr = sec_fd_to_mbuf(fd);
3289 qbman_swp_dqrr_consume(swp, dq);
3292 dpaa2_sec_process_atomic_event(struct qbman_swp *swp __attribute__((unused)),
3293 const struct qbman_fd *fd,
3294 const struct qbman_result *dq,
3295 struct dpaa2_queue *rxq,
3296 struct rte_event *ev)
3299 struct rte_crypto_op *crypto_op = (struct rte_crypto_op *)ev->event_ptr;
3300 /* Prefetching mbuf */
3301 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-
3302 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size));
3304 /* Prefetching ipsec crypto_op stored in priv data of mbuf */
3305 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-64));
3307 ev->flow_id = rxq->ev.flow_id;
3308 ev->sub_event_type = rxq->ev.sub_event_type;
3309 ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
3310 ev->op = RTE_EVENT_OP_NEW;
3311 ev->sched_type = rxq->ev.sched_type;
3312 ev->queue_id = rxq->ev.queue_id;
3313 ev->priority = rxq->ev.priority;
3315 ev->event_ptr = sec_fd_to_mbuf(fd);
3316 dqrr_index = qbman_get_dqrr_idx(dq);
3317 crypto_op->sym->m_src->seqn = dqrr_index + 1;
3318 DPAA2_PER_LCORE_DQRR_SIZE++;
3319 DPAA2_PER_LCORE_DQRR_HELD |= 1 << dqrr_index;
3320 DPAA2_PER_LCORE_DQRR_MBUF(dqrr_index) = crypto_op->sym->m_src;
3324 dpaa2_sec_eventq_attach(const struct rte_cryptodev *dev,
3327 const struct rte_event *event)
3329 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3330 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3331 struct dpaa2_sec_qp *qp = dev->data->queue_pairs[qp_id];
3332 struct dpseci_rx_queue_cfg cfg;
3335 if (event->sched_type == RTE_SCHED_TYPE_PARALLEL)
3336 qp->rx_vq.cb = dpaa2_sec_process_parallel_event;
3337 else if (event->sched_type == RTE_SCHED_TYPE_ATOMIC)
3338 qp->rx_vq.cb = dpaa2_sec_process_atomic_event;
3342 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
3343 cfg.options = DPSECI_QUEUE_OPT_DEST;
3344 cfg.dest_cfg.dest_type = DPSECI_DEST_DPCON;
3345 cfg.dest_cfg.dest_id = dpcon_id;
3346 cfg.dest_cfg.priority = event->priority;
3348 cfg.options |= DPSECI_QUEUE_OPT_USER_CTX;
3349 cfg.user_ctx = (size_t)(qp);
3350 if (event->sched_type == RTE_SCHED_TYPE_ATOMIC) {
3351 cfg.options |= DPSECI_QUEUE_OPT_ORDER_PRESERVATION;
3352 cfg.order_preservation_en = 1;
3354 ret = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
3357 RTE_LOG(ERR, PMD, "Error in dpseci_set_queue: ret: %d\n", ret);
3361 memcpy(&qp->rx_vq.ev, event, sizeof(struct rte_event));
3367 dpaa2_sec_eventq_detach(const struct rte_cryptodev *dev,
3370 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3371 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3372 struct dpseci_rx_queue_cfg cfg;
3375 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
3376 cfg.options = DPSECI_QUEUE_OPT_DEST;
3377 cfg.dest_cfg.dest_type = DPSECI_DEST_NONE;
3379 ret = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
3382 RTE_LOG(ERR, PMD, "Error in dpseci_set_queue: ret: %d\n", ret);
3387 static struct rte_cryptodev_ops crypto_ops = {
3388 .dev_configure = dpaa2_sec_dev_configure,
3389 .dev_start = dpaa2_sec_dev_start,
3390 .dev_stop = dpaa2_sec_dev_stop,
3391 .dev_close = dpaa2_sec_dev_close,
3392 .dev_infos_get = dpaa2_sec_dev_infos_get,
3393 .stats_get = dpaa2_sec_stats_get,
3394 .stats_reset = dpaa2_sec_stats_reset,
3395 .queue_pair_setup = dpaa2_sec_queue_pair_setup,
3396 .queue_pair_release = dpaa2_sec_queue_pair_release,
3397 .queue_pair_count = dpaa2_sec_queue_pair_count,
3398 .sym_session_get_size = dpaa2_sec_sym_session_get_size,
3399 .sym_session_configure = dpaa2_sec_sym_session_configure,
3400 .sym_session_clear = dpaa2_sec_sym_session_clear,
3403 static const struct rte_security_capability *
3404 dpaa2_sec_capabilities_get(void *device __rte_unused)
3406 return dpaa2_sec_security_cap;
3409 static const struct rte_security_ops dpaa2_sec_security_ops = {
3410 .session_create = dpaa2_sec_security_session_create,
3411 .session_update = NULL,
3412 .session_stats_get = NULL,
3413 .session_destroy = dpaa2_sec_security_session_destroy,
3414 .set_pkt_metadata = NULL,
3415 .capabilities_get = dpaa2_sec_capabilities_get
3419 dpaa2_sec_uninit(const struct rte_cryptodev *dev)
3421 struct dpaa2_sec_dev_private *internals = dev->data->dev_private;
3423 rte_free(dev->security_ctx);
3425 rte_mempool_free(internals->fle_pool);
3427 DPAA2_SEC_INFO("Closing DPAA2_SEC device %s on numa socket %u",
3428 dev->data->name, rte_socket_id());
3434 dpaa2_sec_dev_init(struct rte_cryptodev *cryptodev)
3436 struct dpaa2_sec_dev_private *internals;
3437 struct rte_device *dev = cryptodev->device;
3438 struct rte_dpaa2_device *dpaa2_dev;
3439 struct rte_security_ctx *security_instance;
3440 struct fsl_mc_io *dpseci;
3442 struct dpseci_attr attr;
3446 PMD_INIT_FUNC_TRACE();
3447 dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
3448 if (dpaa2_dev == NULL) {
3449 DPAA2_SEC_ERR("DPAA2 SEC device not found");
3452 hw_id = dpaa2_dev->object_id;
3454 cryptodev->driver_id = cryptodev_driver_id;
3455 cryptodev->dev_ops = &crypto_ops;
3457 cryptodev->enqueue_burst = dpaa2_sec_enqueue_burst;
3458 cryptodev->dequeue_burst = dpaa2_sec_dequeue_burst;
3459 cryptodev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
3460 RTE_CRYPTODEV_FF_HW_ACCELERATED |
3461 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
3462 RTE_CRYPTODEV_FF_SECURITY |
3463 RTE_CRYPTODEV_FF_IN_PLACE_SGL |
3464 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT |
3465 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
3466 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT |
3467 RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT;
3469 internals = cryptodev->data->dev_private;
3472 * For secondary processes, we don't initialise any further as primary
3473 * has already done this work. Only check we don't need a different
3476 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
3477 DPAA2_SEC_DEBUG("Device already init by primary process");
3481 /* Initialize security_ctx only for primary process*/
3482 security_instance = rte_malloc("rte_security_instances_ops",
3483 sizeof(struct rte_security_ctx), 0);
3484 if (security_instance == NULL)
3486 security_instance->device = (void *)cryptodev;
3487 security_instance->ops = &dpaa2_sec_security_ops;
3488 security_instance->sess_cnt = 0;
3489 cryptodev->security_ctx = security_instance;
3491 /*Open the rte device via MC and save the handle for further use*/
3492 dpseci = (struct fsl_mc_io *)rte_calloc(NULL, 1,
3493 sizeof(struct fsl_mc_io), 0);
3496 "Error in allocating the memory for dpsec object");
3499 dpseci->regs = rte_mcp_ptr_list[0];
3501 retcode = dpseci_open(dpseci, CMD_PRI_LOW, hw_id, &token);
3503 DPAA2_SEC_ERR("Cannot open the dpsec device: Error = %x",
3507 retcode = dpseci_get_attributes(dpseci, CMD_PRI_LOW, token, &attr);
3510 "Cannot get dpsec device attributed: Error = %x",
3514 snprintf(cryptodev->data->name, sizeof(cryptodev->data->name),
3517 internals->max_nb_queue_pairs = attr.num_tx_queues;
3518 cryptodev->data->nb_queue_pairs = internals->max_nb_queue_pairs;
3519 internals->hw = dpseci;
3520 internals->token = token;
3522 snprintf(str, sizeof(str), "sec_fle_pool_p%d_%d",
3523 getpid(), cryptodev->data->dev_id);
3524 internals->fle_pool = rte_mempool_create((const char *)str,
3527 FLE_POOL_CACHE_SIZE, 0,
3528 NULL, NULL, NULL, NULL,
3530 if (!internals->fle_pool) {
3531 DPAA2_SEC_ERR("Mempool (%s) creation failed", str);
3535 DPAA2_SEC_INFO("driver %s: created", cryptodev->data->name);
3539 DPAA2_SEC_ERR("driver %s: create failed", cryptodev->data->name);
3541 /* dpaa2_sec_uninit(crypto_dev_name); */
3546 cryptodev_dpaa2_sec_probe(struct rte_dpaa2_driver *dpaa2_drv __rte_unused,
3547 struct rte_dpaa2_device *dpaa2_dev)
3549 struct rte_cryptodev *cryptodev;
3550 char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
3554 snprintf(cryptodev_name, sizeof(cryptodev_name), "dpsec-%d",
3555 dpaa2_dev->object_id);
3557 cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
3558 if (cryptodev == NULL)
3561 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
3562 cryptodev->data->dev_private = rte_zmalloc_socket(
3563 "cryptodev private structure",
3564 sizeof(struct dpaa2_sec_dev_private),
3565 RTE_CACHE_LINE_SIZE,
3568 if (cryptodev->data->dev_private == NULL)
3569 rte_panic("Cannot allocate memzone for private "
3573 dpaa2_dev->cryptodev = cryptodev;
3574 cryptodev->device = &dpaa2_dev->device;
3576 /* init user callbacks */
3577 TAILQ_INIT(&(cryptodev->link_intr_cbs));
3579 if (dpaa2_svr_family == SVR_LX2160A)
3580 rta_set_sec_era(RTA_SEC_ERA_10);
3582 DPAA2_SEC_INFO("2-SEC ERA is %d", rta_get_sec_era());
3584 /* Invoke PMD device initialization function */
3585 retval = dpaa2_sec_dev_init(cryptodev);
3589 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
3590 rte_free(cryptodev->data->dev_private);
3592 cryptodev->attached = RTE_CRYPTODEV_DETACHED;
3598 cryptodev_dpaa2_sec_remove(struct rte_dpaa2_device *dpaa2_dev)
3600 struct rte_cryptodev *cryptodev;
3603 cryptodev = dpaa2_dev->cryptodev;
3604 if (cryptodev == NULL)
3607 ret = dpaa2_sec_uninit(cryptodev);
3611 return rte_cryptodev_pmd_destroy(cryptodev);
3614 static struct rte_dpaa2_driver rte_dpaa2_sec_driver = {
3615 .drv_flags = RTE_DPAA2_DRV_IOVA_AS_VA,
3616 .drv_type = DPAA2_CRYPTO,
3618 .name = "DPAA2 SEC PMD"
3620 .probe = cryptodev_dpaa2_sec_probe,
3621 .remove = cryptodev_dpaa2_sec_remove,
3624 static struct cryptodev_driver dpaa2_sec_crypto_drv;
3626 RTE_PMD_REGISTER_DPAA2(CRYPTODEV_NAME_DPAA2_SEC_PMD, rte_dpaa2_sec_driver);
3627 RTE_PMD_REGISTER_CRYPTO_DRIVER(dpaa2_sec_crypto_drv,
3628 rte_dpaa2_sec_driver.driver, cryptodev_driver_id);
3630 RTE_INIT(dpaa2_sec_init_log)
3632 /* Bus level logs */
3633 dpaa2_logtype_sec = rte_log_register("pmd.crypto.dpaa2");
3634 if (dpaa2_logtype_sec >= 0)
3635 rte_log_set_level(dpaa2_logtype_sec, RTE_LOG_NOTICE);