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;
883 int data_len, data_offset;
885 struct rte_mbuf *mbuf;
887 PMD_INIT_FUNC_TRACE();
889 data_len = sym_op->auth.data.length;
890 data_offset = sym_op->auth.data.offset;
892 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
893 sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
894 if ((data_len & 7) || (data_offset & 7)) {
895 DPAA2_SEC_ERR("AUTH: len/offset must be full bytes");
899 data_len = data_len >> 3;
900 data_offset = data_offset >> 3;
903 mbuf = sym_op->m_src;
904 fle = (struct qbman_fle *)rte_malloc(NULL, FLE_SG_MEM_SIZE,
905 RTE_CACHE_LINE_SIZE);
906 if (unlikely(!fle)) {
907 DPAA2_SEC_ERR("AUTH SG: Memory alloc failed for SGE");
910 memset(fle, 0, FLE_SG_MEM_SIZE);
911 /* first FLE entry used to store mbuf and session ctxt */
912 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
913 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
918 flc = &priv->flc_desc[DESC_INITFINAL].flc;
920 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
921 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
922 DPAA2_SET_FD_COMPOUND_FMT(fd);
925 DPAA2_SET_FLE_ADDR(op_fle,
926 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
927 op_fle->length = sess->digest_length;
930 DPAA2_SET_FLE_SG_EXT(ip_fle);
931 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
932 ip_fle->length = data_len;
934 if (sess->iv.length) {
937 iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
940 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2) {
941 iv_ptr = conv_to_snow_f9_iv(iv_ptr);
943 } else if (sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
944 iv_ptr = conv_to_zuc_eia_iv(iv_ptr);
947 sge->length = sess->iv.length;
949 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
950 ip_fle->length += sge->length;
954 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
955 DPAA2_SET_FLE_OFFSET(sge, data_offset + mbuf->data_off);
957 if (data_len <= (mbuf->data_len - data_offset)) {
958 sge->length = data_len;
961 sge->length = mbuf->data_len - data_offset;
963 /* remaining i/p segs */
964 while ((data_len = data_len - sge->length) &&
965 (mbuf = mbuf->next)) {
967 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
968 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
969 if (data_len > mbuf->data_len)
970 sge->length = mbuf->data_len;
972 sge->length = data_len;
976 if (sess->dir == DIR_DEC) {
977 /* Digest verification case */
979 old_digest = (uint8_t *)(sge + 1);
980 rte_memcpy(old_digest, sym_op->auth.digest.data,
981 sess->digest_length);
982 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_digest));
983 sge->length = sess->digest_length;
984 ip_fle->length += sess->digest_length;
986 DPAA2_SET_FLE_FIN(sge);
987 DPAA2_SET_FLE_FIN(ip_fle);
988 DPAA2_SET_FD_LEN(fd, ip_fle->length);
994 build_auth_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
995 struct qbman_fd *fd, uint16_t bpid)
997 struct rte_crypto_sym_op *sym_op = op->sym;
998 struct qbman_fle *fle, *sge;
999 struct sec_flow_context *flc;
1000 struct ctxt_priv *priv = sess->ctxt;
1001 int data_len, data_offset;
1002 uint8_t *old_digest;
1005 PMD_INIT_FUNC_TRACE();
1007 data_len = sym_op->auth.data.length;
1008 data_offset = sym_op->auth.data.offset;
1010 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
1011 sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
1012 if ((data_len & 7) || (data_offset & 7)) {
1013 DPAA2_SEC_ERR("AUTH: len/offset must be full bytes");
1017 data_len = data_len >> 3;
1018 data_offset = data_offset >> 3;
1021 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
1023 DPAA2_SEC_ERR("AUTH Memory alloc failed for SGE");
1026 memset(fle, 0, FLE_POOL_BUF_SIZE);
1027 /* TODO we are using the first FLE entry to store Mbuf.
1028 * Currently we donot know which FLE has the mbuf stored.
1029 * So while retreiving we can go back 1 FLE from the FD -ADDR
1030 * to get the MBUF Addr from the previous FLE.
1031 * We can have a better approach to use the inline Mbuf
1033 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
1034 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
1038 if (likely(bpid < MAX_BPID)) {
1039 DPAA2_SET_FD_BPID(fd, bpid);
1040 DPAA2_SET_FLE_BPID(fle, bpid);
1041 DPAA2_SET_FLE_BPID(fle + 1, bpid);
1042 DPAA2_SET_FLE_BPID(sge, bpid);
1043 DPAA2_SET_FLE_BPID(sge + 1, bpid);
1045 DPAA2_SET_FD_IVP(fd);
1046 DPAA2_SET_FLE_IVP(fle);
1047 DPAA2_SET_FLE_IVP((fle + 1));
1048 DPAA2_SET_FLE_IVP(sge);
1049 DPAA2_SET_FLE_IVP((sge + 1));
1052 flc = &priv->flc_desc[DESC_INITFINAL].flc;
1053 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
1054 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
1055 DPAA2_SET_FD_COMPOUND_FMT(fd);
1057 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
1058 fle->length = sess->digest_length;
1061 /* Setting input FLE */
1062 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
1063 DPAA2_SET_FLE_SG_EXT(fle);
1064 fle->length = data_len;
1066 if (sess->iv.length) {
1069 iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1072 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2) {
1073 iv_ptr = conv_to_snow_f9_iv(iv_ptr);
1075 } else if (sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
1076 iv_ptr = conv_to_zuc_eia_iv(iv_ptr);
1079 sge->length = sess->iv.length;
1082 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
1083 fle->length = fle->length + sge->length;
1087 /* Setting data to authenticate */
1088 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
1089 DPAA2_SET_FLE_OFFSET(sge, data_offset + sym_op->m_src->data_off);
1090 sge->length = data_len;
1092 if (sess->dir == DIR_DEC) {
1094 old_digest = (uint8_t *)(sge + 1);
1095 rte_memcpy(old_digest, sym_op->auth.digest.data,
1096 sess->digest_length);
1097 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_digest));
1098 sge->length = sess->digest_length;
1099 fle->length = fle->length + sess->digest_length;
1102 DPAA2_SET_FLE_FIN(sge);
1103 DPAA2_SET_FLE_FIN(fle);
1104 DPAA2_SET_FD_LEN(fd, fle->length);
1110 build_cipher_sg_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
1111 struct qbman_fd *fd, __rte_unused uint16_t bpid)
1113 struct rte_crypto_sym_op *sym_op = op->sym;
1114 struct qbman_fle *ip_fle, *op_fle, *sge, *fle;
1115 int data_len, data_offset;
1116 struct sec_flow_context *flc;
1117 struct ctxt_priv *priv = sess->ctxt;
1118 struct rte_mbuf *mbuf;
1119 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1122 PMD_INIT_FUNC_TRACE();
1124 data_len = sym_op->cipher.data.length;
1125 data_offset = sym_op->cipher.data.offset;
1127 if (sess->cipher_alg == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
1128 sess->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
1129 if ((data_len & 7) || (data_offset & 7)) {
1130 DPAA2_SEC_ERR("CIPHER: len/offset must be full bytes");
1134 data_len = data_len >> 3;
1135 data_offset = data_offset >> 3;
1139 mbuf = sym_op->m_dst;
1141 mbuf = sym_op->m_src;
1143 fle = (struct qbman_fle *)rte_malloc(NULL, FLE_SG_MEM_SIZE,
1144 RTE_CACHE_LINE_SIZE);
1146 DPAA2_SEC_ERR("CIPHER SG: Memory alloc failed for SGE");
1149 memset(fle, 0, FLE_SG_MEM_SIZE);
1150 /* first FLE entry used to store mbuf and session ctxt */
1151 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
1152 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
1158 flc = &priv->flc_desc[0].flc;
1161 "CIPHER SG: cipher_off: 0x%x/length %d, ivlen=%d"
1162 " data_off: 0x%x\n",
1166 sym_op->m_src->data_off);
1169 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
1170 op_fle->length = data_len;
1171 DPAA2_SET_FLE_SG_EXT(op_fle);
1174 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1175 DPAA2_SET_FLE_OFFSET(sge, data_offset + mbuf->data_off);
1176 sge->length = mbuf->data_len - data_offset;
1182 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1183 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
1184 sge->length = mbuf->data_len;
1187 DPAA2_SET_FLE_FIN(sge);
1190 "CIPHER SG: 1 - flc = %p, fle = %p FLEaddr = %x-%x, len %d\n",
1191 flc, fle, fle->addr_hi, fle->addr_lo,
1195 mbuf = sym_op->m_src;
1197 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
1198 ip_fle->length = sess->iv.length + data_len;
1199 DPAA2_SET_FLE_SG_EXT(ip_fle);
1202 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
1203 DPAA2_SET_FLE_OFFSET(sge, 0);
1204 sge->length = sess->iv.length;
1209 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1210 DPAA2_SET_FLE_OFFSET(sge, data_offset + mbuf->data_off);
1211 sge->length = mbuf->data_len - data_offset;
1217 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1218 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
1219 sge->length = mbuf->data_len;
1222 DPAA2_SET_FLE_FIN(sge);
1223 DPAA2_SET_FLE_FIN(ip_fle);
1226 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
1227 DPAA2_SET_FD_LEN(fd, ip_fle->length);
1228 DPAA2_SET_FD_COMPOUND_FMT(fd);
1229 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
1232 "CIPHER SG: fdaddr =%" PRIx64 " bpid =%d meta =%d"
1233 " off =%d, len =%d\n",
1234 DPAA2_GET_FD_ADDR(fd),
1235 DPAA2_GET_FD_BPID(fd),
1236 rte_dpaa2_bpid_info[bpid].meta_data_size,
1237 DPAA2_GET_FD_OFFSET(fd),
1238 DPAA2_GET_FD_LEN(fd));
1243 build_cipher_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
1244 struct qbman_fd *fd, uint16_t bpid)
1246 struct rte_crypto_sym_op *sym_op = op->sym;
1247 struct qbman_fle *fle, *sge;
1248 int retval, data_len, data_offset;
1249 struct sec_flow_context *flc;
1250 struct ctxt_priv *priv = sess->ctxt;
1251 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1253 struct rte_mbuf *dst;
1255 PMD_INIT_FUNC_TRACE();
1257 data_len = sym_op->cipher.data.length;
1258 data_offset = sym_op->cipher.data.offset;
1260 if (sess->cipher_alg == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
1261 sess->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
1262 if ((data_len & 7) || (data_offset & 7)) {
1263 DPAA2_SEC_ERR("CIPHER: len/offset must be full bytes");
1267 data_len = data_len >> 3;
1268 data_offset = data_offset >> 3;
1272 dst = sym_op->m_dst;
1274 dst = sym_op->m_src;
1276 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
1278 DPAA2_SEC_ERR("CIPHER: Memory alloc failed for SGE");
1281 memset(fle, 0, FLE_POOL_BUF_SIZE);
1282 /* TODO we are using the first FLE entry to store Mbuf.
1283 * Currently we donot know which FLE has the mbuf stored.
1284 * So while retreiving we can go back 1 FLE from the FD -ADDR
1285 * to get the MBUF Addr from the previous FLE.
1286 * We can have a better approach to use the inline Mbuf
1288 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
1289 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
1293 if (likely(bpid < MAX_BPID)) {
1294 DPAA2_SET_FD_BPID(fd, bpid);
1295 DPAA2_SET_FLE_BPID(fle, bpid);
1296 DPAA2_SET_FLE_BPID(fle + 1, bpid);
1297 DPAA2_SET_FLE_BPID(sge, bpid);
1298 DPAA2_SET_FLE_BPID(sge + 1, bpid);
1300 DPAA2_SET_FD_IVP(fd);
1301 DPAA2_SET_FLE_IVP(fle);
1302 DPAA2_SET_FLE_IVP((fle + 1));
1303 DPAA2_SET_FLE_IVP(sge);
1304 DPAA2_SET_FLE_IVP((sge + 1));
1307 flc = &priv->flc_desc[0].flc;
1308 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
1309 DPAA2_SET_FD_LEN(fd, data_len + sess->iv.length);
1310 DPAA2_SET_FD_COMPOUND_FMT(fd);
1311 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
1314 "CIPHER: cipher_off: 0x%x/length %d, ivlen=%d,"
1315 " data_off: 0x%x\n",
1319 sym_op->m_src->data_off);
1321 DPAA2_SET_FLE_ADDR(fle, DPAA2_MBUF_VADDR_TO_IOVA(dst));
1322 DPAA2_SET_FLE_OFFSET(fle, data_offset + dst->data_off);
1324 fle->length = data_len + sess->iv.length;
1327 "CIPHER: 1 - flc = %p, fle = %p FLEaddr = %x-%x, length %d\n",
1328 flc, fle, fle->addr_hi, fle->addr_lo,
1333 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
1334 fle->length = data_len + sess->iv.length;
1336 DPAA2_SET_FLE_SG_EXT(fle);
1338 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
1339 sge->length = sess->iv.length;
1342 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
1343 DPAA2_SET_FLE_OFFSET(sge, data_offset + sym_op->m_src->data_off);
1345 sge->length = data_len;
1346 DPAA2_SET_FLE_FIN(sge);
1347 DPAA2_SET_FLE_FIN(fle);
1350 "CIPHER: fdaddr =%" PRIx64 " bpid =%d meta =%d"
1351 " off =%d, len =%d\n",
1352 DPAA2_GET_FD_ADDR(fd),
1353 DPAA2_GET_FD_BPID(fd),
1354 rte_dpaa2_bpid_info[bpid].meta_data_size,
1355 DPAA2_GET_FD_OFFSET(fd),
1356 DPAA2_GET_FD_LEN(fd));
1362 build_sec_fd(struct rte_crypto_op *op,
1363 struct qbman_fd *fd, uint16_t bpid)
1366 dpaa2_sec_session *sess;
1368 PMD_INIT_FUNC_TRACE();
1370 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION)
1371 sess = (dpaa2_sec_session *)get_sym_session_private_data(
1372 op->sym->session, cryptodev_driver_id);
1373 else if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION)
1374 sess = (dpaa2_sec_session *)get_sec_session_private_data(
1375 op->sym->sec_session);
1379 /* Any of the buffer is segmented*/
1380 if (!rte_pktmbuf_is_contiguous(op->sym->m_src) ||
1381 ((op->sym->m_dst != NULL) &&
1382 !rte_pktmbuf_is_contiguous(op->sym->m_dst))) {
1383 switch (sess->ctxt_type) {
1384 case DPAA2_SEC_CIPHER:
1385 ret = build_cipher_sg_fd(sess, op, fd, bpid);
1387 case DPAA2_SEC_AUTH:
1388 ret = build_auth_sg_fd(sess, op, fd, bpid);
1390 case DPAA2_SEC_AEAD:
1391 ret = build_authenc_gcm_sg_fd(sess, op, fd, bpid);
1393 case DPAA2_SEC_CIPHER_HASH:
1394 ret = build_authenc_sg_fd(sess, op, fd, bpid);
1396 case DPAA2_SEC_IPSEC:
1397 case DPAA2_SEC_PDCP:
1398 ret = build_proto_compound_sg_fd(sess, op, fd, bpid);
1400 case DPAA2_SEC_HASH_CIPHER:
1402 DPAA2_SEC_ERR("error: Unsupported session");
1405 switch (sess->ctxt_type) {
1406 case DPAA2_SEC_CIPHER:
1407 ret = build_cipher_fd(sess, op, fd, bpid);
1409 case DPAA2_SEC_AUTH:
1410 ret = build_auth_fd(sess, op, fd, bpid);
1412 case DPAA2_SEC_AEAD:
1413 ret = build_authenc_gcm_fd(sess, op, fd, bpid);
1415 case DPAA2_SEC_CIPHER_HASH:
1416 ret = build_authenc_fd(sess, op, fd, bpid);
1418 case DPAA2_SEC_IPSEC:
1419 ret = build_proto_fd(sess, op, fd, bpid);
1421 case DPAA2_SEC_PDCP:
1422 ret = build_proto_compound_fd(sess, op, fd, bpid);
1424 case DPAA2_SEC_HASH_CIPHER:
1426 DPAA2_SEC_ERR("error: Unsupported session");
1433 dpaa2_sec_enqueue_burst(void *qp, struct rte_crypto_op **ops,
1436 /* Function to transmit the frames to given device and VQ*/
1439 struct qbman_fd fd_arr[MAX_TX_RING_SLOTS];
1440 uint32_t frames_to_send;
1441 struct qbman_eq_desc eqdesc;
1442 struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
1443 struct qbman_swp *swp;
1444 uint16_t num_tx = 0;
1445 uint32_t flags[MAX_TX_RING_SLOTS] = {0};
1446 /*todo - need to support multiple buffer pools */
1448 struct rte_mempool *mb_pool;
1450 if (unlikely(nb_ops == 0))
1453 if (ops[0]->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
1454 DPAA2_SEC_ERR("sessionless crypto op not supported");
1457 /*Prepare enqueue descriptor*/
1458 qbman_eq_desc_clear(&eqdesc);
1459 qbman_eq_desc_set_no_orp(&eqdesc, DPAA2_EQ_RESP_ERR_FQ);
1460 qbman_eq_desc_set_response(&eqdesc, 0, 0);
1461 qbman_eq_desc_set_fq(&eqdesc, dpaa2_qp->tx_vq.fqid);
1463 if (!DPAA2_PER_LCORE_DPIO) {
1464 ret = dpaa2_affine_qbman_swp();
1466 DPAA2_SEC_ERR("Failure in affining portal");
1470 swp = DPAA2_PER_LCORE_PORTAL;
1473 frames_to_send = (nb_ops > dpaa2_eqcr_size) ?
1474 dpaa2_eqcr_size : nb_ops;
1476 for (loop = 0; loop < frames_to_send; loop++) {
1477 if ((*ops)->sym->m_src->seqn) {
1478 uint8_t dqrr_index = (*ops)->sym->m_src->seqn - 1;
1480 flags[loop] = QBMAN_ENQUEUE_FLAG_DCA | dqrr_index;
1481 DPAA2_PER_LCORE_DQRR_SIZE--;
1482 DPAA2_PER_LCORE_DQRR_HELD &= ~(1 << dqrr_index);
1483 (*ops)->sym->m_src->seqn = DPAA2_INVALID_MBUF_SEQN;
1486 /*Clear the unused FD fields before sending*/
1487 memset(&fd_arr[loop], 0, sizeof(struct qbman_fd));
1488 mb_pool = (*ops)->sym->m_src->pool;
1489 bpid = mempool_to_bpid(mb_pool);
1490 ret = build_sec_fd(*ops, &fd_arr[loop], bpid);
1492 DPAA2_SEC_ERR("error: Improper packet contents"
1493 " for crypto operation");
1499 while (loop < frames_to_send) {
1500 loop += qbman_swp_enqueue_multiple(swp, &eqdesc,
1503 frames_to_send - loop);
1506 num_tx += frames_to_send;
1507 nb_ops -= frames_to_send;
1510 dpaa2_qp->tx_vq.tx_pkts += num_tx;
1511 dpaa2_qp->tx_vq.err_pkts += nb_ops;
1515 static inline struct rte_crypto_op *
1516 sec_simple_fd_to_mbuf(const struct qbman_fd *fd)
1518 struct rte_crypto_op *op;
1519 uint16_t len = DPAA2_GET_FD_LEN(fd);
1521 dpaa2_sec_session *sess_priv;
1523 struct rte_mbuf *mbuf = DPAA2_INLINE_MBUF_FROM_BUF(
1524 DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd)),
1525 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size);
1527 diff = len - mbuf->pkt_len;
1528 mbuf->pkt_len += diff;
1529 mbuf->data_len += diff;
1530 op = (struct rte_crypto_op *)(size_t)mbuf->buf_iova;
1531 mbuf->buf_iova = op->sym->aead.digest.phys_addr;
1532 op->sym->aead.digest.phys_addr = 0L;
1534 sess_priv = (dpaa2_sec_session *)get_sec_session_private_data(
1535 op->sym->sec_session);
1536 if (sess_priv->dir == DIR_ENC)
1537 mbuf->data_off += SEC_FLC_DHR_OUTBOUND;
1539 mbuf->data_off += SEC_FLC_DHR_INBOUND;
1544 static inline struct rte_crypto_op *
1545 sec_fd_to_mbuf(const struct qbman_fd *fd)
1547 struct qbman_fle *fle;
1548 struct rte_crypto_op *op;
1549 struct ctxt_priv *priv;
1550 struct rte_mbuf *dst, *src;
1552 if (DPAA2_FD_GET_FORMAT(fd) == qbman_fd_single)
1553 return sec_simple_fd_to_mbuf(fd);
1555 fle = (struct qbman_fle *)DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd));
1557 DPAA2_SEC_DP_DEBUG("FLE addr = %x - %x, offset = %x\n",
1558 fle->addr_hi, fle->addr_lo, fle->fin_bpid_offset);
1560 /* we are using the first FLE entry to store Mbuf.
1561 * Currently we donot know which FLE has the mbuf stored.
1562 * So while retreiving we can go back 1 FLE from the FD -ADDR
1563 * to get the MBUF Addr from the previous FLE.
1564 * We can have a better approach to use the inline Mbuf
1567 if (unlikely(DPAA2_GET_FD_IVP(fd))) {
1568 /* TODO complete it. */
1569 DPAA2_SEC_ERR("error: non inline buffer");
1572 op = (struct rte_crypto_op *)DPAA2_GET_FLE_ADDR((fle - 1));
1575 src = op->sym->m_src;
1578 if (op->sym->m_dst) {
1579 dst = op->sym->m_dst;
1584 if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
1585 dpaa2_sec_session *sess = (dpaa2_sec_session *)
1586 get_sec_session_private_data(op->sym->sec_session);
1587 if (sess->ctxt_type == DPAA2_SEC_IPSEC ||
1588 sess->ctxt_type == DPAA2_SEC_PDCP) {
1589 uint16_t len = DPAA2_GET_FD_LEN(fd);
1591 while (dst->next != NULL) {
1592 len -= dst->data_len;
1595 dst->data_len = len;
1599 DPAA2_SEC_DP_DEBUG("mbuf %p BMAN buf addr %p,"
1600 " fdaddr =%" PRIx64 " bpid =%d meta =%d off =%d, len =%d\n",
1603 DPAA2_GET_FD_ADDR(fd),
1604 DPAA2_GET_FD_BPID(fd),
1605 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size,
1606 DPAA2_GET_FD_OFFSET(fd),
1607 DPAA2_GET_FD_LEN(fd));
1609 /* free the fle memory */
1610 if (likely(rte_pktmbuf_is_contiguous(src))) {
1611 priv = (struct ctxt_priv *)(size_t)DPAA2_GET_FLE_CTXT(fle - 1);
1612 rte_mempool_put(priv->fle_pool, (void *)(fle-1));
1614 rte_free((void *)(fle-1));
1620 dpaa2_sec_dequeue_burst(void *qp, struct rte_crypto_op **ops,
1623 /* Function is responsible to receive frames for a given device and VQ*/
1624 struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
1625 struct qbman_result *dq_storage;
1626 uint32_t fqid = dpaa2_qp->rx_vq.fqid;
1627 int ret, num_rx = 0;
1628 uint8_t is_last = 0, status;
1629 struct qbman_swp *swp;
1630 const struct qbman_fd *fd;
1631 struct qbman_pull_desc pulldesc;
1633 if (!DPAA2_PER_LCORE_DPIO) {
1634 ret = dpaa2_affine_qbman_swp();
1636 DPAA2_SEC_ERR("Failure in affining portal");
1640 swp = DPAA2_PER_LCORE_PORTAL;
1641 dq_storage = dpaa2_qp->rx_vq.q_storage->dq_storage[0];
1643 qbman_pull_desc_clear(&pulldesc);
1644 qbman_pull_desc_set_numframes(&pulldesc,
1645 (nb_ops > dpaa2_dqrr_size) ?
1646 dpaa2_dqrr_size : nb_ops);
1647 qbman_pull_desc_set_fq(&pulldesc, fqid);
1648 qbman_pull_desc_set_storage(&pulldesc, dq_storage,
1649 (dma_addr_t)DPAA2_VADDR_TO_IOVA(dq_storage),
1652 /*Issue a volatile dequeue command. */
1654 if (qbman_swp_pull(swp, &pulldesc)) {
1656 "SEC VDQ command is not issued : QBMAN busy");
1657 /* Portal was busy, try again */
1663 /* Receive the packets till Last Dequeue entry is found with
1664 * respect to the above issues PULL command.
1667 /* Check if the previous issued command is completed.
1668 * Also seems like the SWP is shared between the Ethernet Driver
1669 * and the SEC driver.
1671 while (!qbman_check_command_complete(dq_storage))
1674 /* Loop until the dq_storage is updated with
1675 * new token by QBMAN
1677 while (!qbman_check_new_result(dq_storage))
1679 /* Check whether Last Pull command is Expired and
1680 * setting Condition for Loop termination
1682 if (qbman_result_DQ_is_pull_complete(dq_storage)) {
1684 /* Check for valid frame. */
1685 status = (uint8_t)qbman_result_DQ_flags(dq_storage);
1687 (status & QBMAN_DQ_STAT_VALIDFRAME) == 0)) {
1688 DPAA2_SEC_DP_DEBUG("No frame is delivered\n");
1693 fd = qbman_result_DQ_fd(dq_storage);
1694 ops[num_rx] = sec_fd_to_mbuf(fd);
1696 if (unlikely(fd->simple.frc)) {
1697 /* TODO Parse SEC errors */
1698 DPAA2_SEC_ERR("SEC returned Error - %x",
1700 ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_ERROR;
1702 ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
1707 } /* End of Packet Rx loop */
1709 dpaa2_qp->rx_vq.rx_pkts += num_rx;
1711 DPAA2_SEC_DP_DEBUG("SEC Received %d Packets\n", num_rx);
1712 /*Return the total number of packets received to DPAA2 app*/
1716 /** Release queue pair */
1718 dpaa2_sec_queue_pair_release(struct rte_cryptodev *dev, uint16_t queue_pair_id)
1720 struct dpaa2_sec_qp *qp =
1721 (struct dpaa2_sec_qp *)dev->data->queue_pairs[queue_pair_id];
1723 PMD_INIT_FUNC_TRACE();
1725 if (qp->rx_vq.q_storage) {
1726 dpaa2_free_dq_storage(qp->rx_vq.q_storage);
1727 rte_free(qp->rx_vq.q_storage);
1731 dev->data->queue_pairs[queue_pair_id] = NULL;
1736 /** Setup a queue pair */
1738 dpaa2_sec_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
1739 __rte_unused const struct rte_cryptodev_qp_conf *qp_conf,
1740 __rte_unused int socket_id)
1742 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
1743 struct dpaa2_sec_qp *qp;
1744 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
1745 struct dpseci_rx_queue_cfg cfg;
1748 PMD_INIT_FUNC_TRACE();
1750 /* If qp is already in use free ring memory and qp metadata. */
1751 if (dev->data->queue_pairs[qp_id] != NULL) {
1752 DPAA2_SEC_INFO("QP already setup");
1756 DPAA2_SEC_DEBUG("dev =%p, queue =%d, conf =%p",
1757 dev, qp_id, qp_conf);
1759 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
1761 qp = rte_malloc(NULL, sizeof(struct dpaa2_sec_qp),
1762 RTE_CACHE_LINE_SIZE);
1764 DPAA2_SEC_ERR("malloc failed for rx/tx queues");
1768 qp->rx_vq.crypto_data = dev->data;
1769 qp->tx_vq.crypto_data = dev->data;
1770 qp->rx_vq.q_storage = rte_malloc("sec dq storage",
1771 sizeof(struct queue_storage_info_t),
1772 RTE_CACHE_LINE_SIZE);
1773 if (!qp->rx_vq.q_storage) {
1774 DPAA2_SEC_ERR("malloc failed for q_storage");
1777 memset(qp->rx_vq.q_storage, 0, sizeof(struct queue_storage_info_t));
1779 if (dpaa2_alloc_dq_storage(qp->rx_vq.q_storage)) {
1780 DPAA2_SEC_ERR("Unable to allocate dequeue storage");
1784 dev->data->queue_pairs[qp_id] = qp;
1786 cfg.options = cfg.options | DPSECI_QUEUE_OPT_USER_CTX;
1787 cfg.user_ctx = (size_t)(&qp->rx_vq);
1788 retcode = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
1793 /** Return the number of allocated queue pairs */
1795 dpaa2_sec_queue_pair_count(struct rte_cryptodev *dev)
1797 PMD_INIT_FUNC_TRACE();
1799 return dev->data->nb_queue_pairs;
1802 /** Returns the size of the aesni gcm session structure */
1804 dpaa2_sec_sym_session_get_size(struct rte_cryptodev *dev __rte_unused)
1806 PMD_INIT_FUNC_TRACE();
1808 return sizeof(dpaa2_sec_session);
1812 dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
1813 struct rte_crypto_sym_xform *xform,
1814 dpaa2_sec_session *session)
1816 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
1817 struct alginfo cipherdata;
1819 struct ctxt_priv *priv;
1820 struct sec_flow_context *flc;
1822 PMD_INIT_FUNC_TRACE();
1824 /* For SEC CIPHER only one descriptor is required. */
1825 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
1826 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
1827 RTE_CACHE_LINE_SIZE);
1829 DPAA2_SEC_ERR("No Memory for priv CTXT");
1833 priv->fle_pool = dev_priv->fle_pool;
1835 flc = &priv->flc_desc[0].flc;
1837 session->cipher_key.data = rte_zmalloc(NULL, xform->cipher.key.length,
1838 RTE_CACHE_LINE_SIZE);
1839 if (session->cipher_key.data == NULL) {
1840 DPAA2_SEC_ERR("No Memory for cipher key");
1844 session->cipher_key.length = xform->cipher.key.length;
1846 memcpy(session->cipher_key.data, xform->cipher.key.data,
1847 xform->cipher.key.length);
1848 cipherdata.key = (size_t)session->cipher_key.data;
1849 cipherdata.keylen = session->cipher_key.length;
1850 cipherdata.key_enc_flags = 0;
1851 cipherdata.key_type = RTA_DATA_IMM;
1853 /* Set IV parameters */
1854 session->iv.offset = xform->cipher.iv.offset;
1855 session->iv.length = xform->cipher.iv.length;
1856 session->dir = (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
1859 switch (xform->cipher.algo) {
1860 case RTE_CRYPTO_CIPHER_AES_CBC:
1861 cipherdata.algtype = OP_ALG_ALGSEL_AES;
1862 cipherdata.algmode = OP_ALG_AAI_CBC;
1863 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
1864 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
1865 SHR_NEVER, &cipherdata, NULL,
1869 case RTE_CRYPTO_CIPHER_3DES_CBC:
1870 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
1871 cipherdata.algmode = OP_ALG_AAI_CBC;
1872 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
1873 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
1874 SHR_NEVER, &cipherdata, NULL,
1878 case RTE_CRYPTO_CIPHER_AES_CTR:
1879 cipherdata.algtype = OP_ALG_ALGSEL_AES;
1880 cipherdata.algmode = OP_ALG_AAI_CTR;
1881 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
1882 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
1883 SHR_NEVER, &cipherdata, NULL,
1887 case RTE_CRYPTO_CIPHER_3DES_CTR:
1888 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
1889 cipherdata.algmode = OP_ALG_AAI_CTR;
1890 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CTR;
1891 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
1892 SHR_NEVER, &cipherdata, NULL,
1896 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
1897 cipherdata.algtype = OP_ALG_ALGSEL_SNOW_F8;
1898 session->cipher_alg = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1899 bufsize = cnstr_shdsc_snow_f8(priv->flc_desc[0].desc, 1, 0,
1903 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
1904 cipherdata.algtype = OP_ALG_ALGSEL_ZUCE;
1905 session->cipher_alg = RTE_CRYPTO_CIPHER_ZUC_EEA3;
1906 bufsize = cnstr_shdsc_zuce(priv->flc_desc[0].desc, 1, 0,
1910 case RTE_CRYPTO_CIPHER_KASUMI_F8:
1911 case RTE_CRYPTO_CIPHER_AES_F8:
1912 case RTE_CRYPTO_CIPHER_AES_ECB:
1913 case RTE_CRYPTO_CIPHER_3DES_ECB:
1914 case RTE_CRYPTO_CIPHER_AES_XTS:
1915 case RTE_CRYPTO_CIPHER_ARC4:
1916 case RTE_CRYPTO_CIPHER_NULL:
1917 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
1918 xform->cipher.algo);
1921 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
1922 xform->cipher.algo);
1927 DPAA2_SEC_ERR("Crypto: Descriptor build failed");
1931 flc->word1_sdl = (uint8_t)bufsize;
1932 session->ctxt = priv;
1934 for (i = 0; i < bufsize; i++)
1935 DPAA2_SEC_DEBUG("DESC[%d]:0x%x", i, priv->flc_desc[0].desc[i]);
1940 rte_free(session->cipher_key.data);
1946 dpaa2_sec_auth_init(struct rte_cryptodev *dev,
1947 struct rte_crypto_sym_xform *xform,
1948 dpaa2_sec_session *session)
1950 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
1951 struct alginfo authdata;
1953 struct ctxt_priv *priv;
1954 struct sec_flow_context *flc;
1956 PMD_INIT_FUNC_TRACE();
1958 /* For SEC AUTH three descriptors are required for various stages */
1959 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
1960 sizeof(struct ctxt_priv) + 3 *
1961 sizeof(struct sec_flc_desc),
1962 RTE_CACHE_LINE_SIZE);
1964 DPAA2_SEC_ERR("No Memory for priv CTXT");
1968 priv->fle_pool = dev_priv->fle_pool;
1969 flc = &priv->flc_desc[DESC_INITFINAL].flc;
1971 session->auth_key.data = rte_zmalloc(NULL, xform->auth.key.length,
1972 RTE_CACHE_LINE_SIZE);
1973 if (session->auth_key.data == NULL) {
1974 DPAA2_SEC_ERR("Unable to allocate memory for auth key");
1978 session->auth_key.length = xform->auth.key.length;
1980 memcpy(session->auth_key.data, xform->auth.key.data,
1981 xform->auth.key.length);
1982 authdata.key = (size_t)session->auth_key.data;
1983 authdata.keylen = session->auth_key.length;
1984 authdata.key_enc_flags = 0;
1985 authdata.key_type = RTA_DATA_IMM;
1987 session->digest_length = xform->auth.digest_length;
1988 session->dir = (xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE) ?
1991 switch (xform->auth.algo) {
1992 case RTE_CRYPTO_AUTH_SHA1_HMAC:
1993 authdata.algtype = OP_ALG_ALGSEL_SHA1;
1994 authdata.algmode = OP_ALG_AAI_HMAC;
1995 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
1996 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
1997 1, 0, SHR_NEVER, &authdata,
1999 session->digest_length);
2001 case RTE_CRYPTO_AUTH_MD5_HMAC:
2002 authdata.algtype = OP_ALG_ALGSEL_MD5;
2003 authdata.algmode = OP_ALG_AAI_HMAC;
2004 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
2005 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2006 1, 0, SHR_NEVER, &authdata,
2008 session->digest_length);
2010 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2011 authdata.algtype = OP_ALG_ALGSEL_SHA256;
2012 authdata.algmode = OP_ALG_AAI_HMAC;
2013 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
2014 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2015 1, 0, SHR_NEVER, &authdata,
2017 session->digest_length);
2019 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2020 authdata.algtype = OP_ALG_ALGSEL_SHA384;
2021 authdata.algmode = OP_ALG_AAI_HMAC;
2022 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
2023 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2024 1, 0, SHR_NEVER, &authdata,
2026 session->digest_length);
2028 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2029 authdata.algtype = OP_ALG_ALGSEL_SHA512;
2030 authdata.algmode = OP_ALG_AAI_HMAC;
2031 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
2032 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2033 1, 0, SHR_NEVER, &authdata,
2035 session->digest_length);
2037 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2038 authdata.algtype = OP_ALG_ALGSEL_SHA224;
2039 authdata.algmode = OP_ALG_AAI_HMAC;
2040 session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
2041 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2042 1, 0, SHR_NEVER, &authdata,
2044 session->digest_length);
2046 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2047 authdata.algtype = OP_ALG_ALGSEL_SNOW_F9;
2048 authdata.algmode = OP_ALG_AAI_F9;
2049 session->auth_alg = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2050 session->iv.offset = xform->auth.iv.offset;
2051 session->iv.length = xform->auth.iv.length;
2052 bufsize = cnstr_shdsc_snow_f9(priv->flc_desc[DESC_INITFINAL].desc,
2055 session->digest_length);
2057 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2058 authdata.algtype = OP_ALG_ALGSEL_ZUCA;
2059 authdata.algmode = OP_ALG_AAI_F9;
2060 session->auth_alg = RTE_CRYPTO_AUTH_ZUC_EIA3;
2061 session->iv.offset = xform->auth.iv.offset;
2062 session->iv.length = xform->auth.iv.length;
2063 bufsize = cnstr_shdsc_zuca(priv->flc_desc[DESC_INITFINAL].desc,
2066 session->digest_length);
2068 case RTE_CRYPTO_AUTH_KASUMI_F9:
2069 case RTE_CRYPTO_AUTH_NULL:
2070 case RTE_CRYPTO_AUTH_SHA1:
2071 case RTE_CRYPTO_AUTH_SHA256:
2072 case RTE_CRYPTO_AUTH_SHA512:
2073 case RTE_CRYPTO_AUTH_SHA224:
2074 case RTE_CRYPTO_AUTH_SHA384:
2075 case RTE_CRYPTO_AUTH_MD5:
2076 case RTE_CRYPTO_AUTH_AES_GMAC:
2077 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2078 case RTE_CRYPTO_AUTH_AES_CMAC:
2079 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2080 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %un",
2084 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2090 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2094 flc->word1_sdl = (uint8_t)bufsize;
2095 session->ctxt = priv;
2096 for (i = 0; i < bufsize; i++)
2097 DPAA2_SEC_DEBUG("DESC[%d]:0x%x",
2098 i, priv->flc_desc[DESC_INITFINAL].desc[i]);
2104 rte_free(session->auth_key.data);
2110 dpaa2_sec_aead_init(struct rte_cryptodev *dev,
2111 struct rte_crypto_sym_xform *xform,
2112 dpaa2_sec_session *session)
2114 struct dpaa2_sec_aead_ctxt *ctxt = &session->ext_params.aead_ctxt;
2115 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2116 struct alginfo aeaddata;
2118 struct ctxt_priv *priv;
2119 struct sec_flow_context *flc;
2120 struct rte_crypto_aead_xform *aead_xform = &xform->aead;
2123 PMD_INIT_FUNC_TRACE();
2125 /* Set IV parameters */
2126 session->iv.offset = aead_xform->iv.offset;
2127 session->iv.length = aead_xform->iv.length;
2128 session->ctxt_type = DPAA2_SEC_AEAD;
2130 /* For SEC AEAD only one descriptor is required */
2131 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2132 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
2133 RTE_CACHE_LINE_SIZE);
2135 DPAA2_SEC_ERR("No Memory for priv CTXT");
2139 priv->fle_pool = dev_priv->fle_pool;
2140 flc = &priv->flc_desc[0].flc;
2142 session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length,
2143 RTE_CACHE_LINE_SIZE);
2144 if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
2145 DPAA2_SEC_ERR("No Memory for aead key");
2149 memcpy(session->aead_key.data, aead_xform->key.data,
2150 aead_xform->key.length);
2152 session->digest_length = aead_xform->digest_length;
2153 session->aead_key.length = aead_xform->key.length;
2154 ctxt->auth_only_len = aead_xform->aad_length;
2156 aeaddata.key = (size_t)session->aead_key.data;
2157 aeaddata.keylen = session->aead_key.length;
2158 aeaddata.key_enc_flags = 0;
2159 aeaddata.key_type = RTA_DATA_IMM;
2161 switch (aead_xform->algo) {
2162 case RTE_CRYPTO_AEAD_AES_GCM:
2163 aeaddata.algtype = OP_ALG_ALGSEL_AES;
2164 aeaddata.algmode = OP_ALG_AAI_GCM;
2165 session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM;
2167 case RTE_CRYPTO_AEAD_AES_CCM:
2168 DPAA2_SEC_ERR("Crypto: Unsupported AEAD alg %u",
2172 DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
2176 session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
2179 priv->flc_desc[0].desc[0] = aeaddata.keylen;
2180 err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
2182 (unsigned int *)priv->flc_desc[0].desc,
2183 &priv->flc_desc[0].desc[1], 1);
2186 DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
2189 if (priv->flc_desc[0].desc[1] & 1) {
2190 aeaddata.key_type = RTA_DATA_IMM;
2192 aeaddata.key = DPAA2_VADDR_TO_IOVA(aeaddata.key);
2193 aeaddata.key_type = RTA_DATA_PTR;
2195 priv->flc_desc[0].desc[0] = 0;
2196 priv->flc_desc[0].desc[1] = 0;
2198 if (session->dir == DIR_ENC)
2199 bufsize = cnstr_shdsc_gcm_encap(
2200 priv->flc_desc[0].desc, 1, 0, SHR_NEVER,
2201 &aeaddata, session->iv.length,
2202 session->digest_length);
2204 bufsize = cnstr_shdsc_gcm_decap(
2205 priv->flc_desc[0].desc, 1, 0, SHR_NEVER,
2206 &aeaddata, session->iv.length,
2207 session->digest_length);
2209 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2213 flc->word1_sdl = (uint8_t)bufsize;
2214 session->ctxt = priv;
2215 for (i = 0; i < bufsize; i++)
2216 DPAA2_SEC_DEBUG("DESC[%d]:0x%x\n",
2217 i, priv->flc_desc[0].desc[i]);
2222 rte_free(session->aead_key.data);
2229 dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
2230 struct rte_crypto_sym_xform *xform,
2231 dpaa2_sec_session *session)
2233 struct dpaa2_sec_aead_ctxt *ctxt = &session->ext_params.aead_ctxt;
2234 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2235 struct alginfo authdata, cipherdata;
2237 struct ctxt_priv *priv;
2238 struct sec_flow_context *flc;
2239 struct rte_crypto_cipher_xform *cipher_xform;
2240 struct rte_crypto_auth_xform *auth_xform;
2243 PMD_INIT_FUNC_TRACE();
2245 if (session->ext_params.aead_ctxt.auth_cipher_text) {
2246 cipher_xform = &xform->cipher;
2247 auth_xform = &xform->next->auth;
2248 session->ctxt_type =
2249 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2250 DPAA2_SEC_CIPHER_HASH : DPAA2_SEC_HASH_CIPHER;
2252 cipher_xform = &xform->next->cipher;
2253 auth_xform = &xform->auth;
2254 session->ctxt_type =
2255 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2256 DPAA2_SEC_HASH_CIPHER : DPAA2_SEC_CIPHER_HASH;
2259 /* Set IV parameters */
2260 session->iv.offset = cipher_xform->iv.offset;
2261 session->iv.length = cipher_xform->iv.length;
2263 /* For SEC AEAD only one descriptor is required */
2264 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2265 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
2266 RTE_CACHE_LINE_SIZE);
2268 DPAA2_SEC_ERR("No Memory for priv CTXT");
2272 priv->fle_pool = dev_priv->fle_pool;
2273 flc = &priv->flc_desc[0].flc;
2275 session->cipher_key.data = rte_zmalloc(NULL, cipher_xform->key.length,
2276 RTE_CACHE_LINE_SIZE);
2277 if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) {
2278 DPAA2_SEC_ERR("No Memory for cipher key");
2282 session->cipher_key.length = cipher_xform->key.length;
2283 session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length,
2284 RTE_CACHE_LINE_SIZE);
2285 if (session->auth_key.data == NULL && auth_xform->key.length > 0) {
2286 DPAA2_SEC_ERR("No Memory for auth key");
2287 rte_free(session->cipher_key.data);
2291 session->auth_key.length = auth_xform->key.length;
2292 memcpy(session->cipher_key.data, cipher_xform->key.data,
2293 cipher_xform->key.length);
2294 memcpy(session->auth_key.data, auth_xform->key.data,
2295 auth_xform->key.length);
2297 authdata.key = (size_t)session->auth_key.data;
2298 authdata.keylen = session->auth_key.length;
2299 authdata.key_enc_flags = 0;
2300 authdata.key_type = RTA_DATA_IMM;
2302 session->digest_length = auth_xform->digest_length;
2304 switch (auth_xform->algo) {
2305 case RTE_CRYPTO_AUTH_SHA1_HMAC:
2306 authdata.algtype = OP_ALG_ALGSEL_SHA1;
2307 authdata.algmode = OP_ALG_AAI_HMAC;
2308 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
2310 case RTE_CRYPTO_AUTH_MD5_HMAC:
2311 authdata.algtype = OP_ALG_ALGSEL_MD5;
2312 authdata.algmode = OP_ALG_AAI_HMAC;
2313 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
2315 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2316 authdata.algtype = OP_ALG_ALGSEL_SHA224;
2317 authdata.algmode = OP_ALG_AAI_HMAC;
2318 session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
2320 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2321 authdata.algtype = OP_ALG_ALGSEL_SHA256;
2322 authdata.algmode = OP_ALG_AAI_HMAC;
2323 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
2325 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2326 authdata.algtype = OP_ALG_ALGSEL_SHA384;
2327 authdata.algmode = OP_ALG_AAI_HMAC;
2328 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
2330 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2331 authdata.algtype = OP_ALG_ALGSEL_SHA512;
2332 authdata.algmode = OP_ALG_AAI_HMAC;
2333 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
2335 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2336 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2337 case RTE_CRYPTO_AUTH_NULL:
2338 case RTE_CRYPTO_AUTH_SHA1:
2339 case RTE_CRYPTO_AUTH_SHA256:
2340 case RTE_CRYPTO_AUTH_SHA512:
2341 case RTE_CRYPTO_AUTH_SHA224:
2342 case RTE_CRYPTO_AUTH_SHA384:
2343 case RTE_CRYPTO_AUTH_MD5:
2344 case RTE_CRYPTO_AUTH_AES_GMAC:
2345 case RTE_CRYPTO_AUTH_KASUMI_F9:
2346 case RTE_CRYPTO_AUTH_AES_CMAC:
2347 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2348 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2349 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
2353 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2357 cipherdata.key = (size_t)session->cipher_key.data;
2358 cipherdata.keylen = session->cipher_key.length;
2359 cipherdata.key_enc_flags = 0;
2360 cipherdata.key_type = RTA_DATA_IMM;
2362 switch (cipher_xform->algo) {
2363 case RTE_CRYPTO_CIPHER_AES_CBC:
2364 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2365 cipherdata.algmode = OP_ALG_AAI_CBC;
2366 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
2368 case RTE_CRYPTO_CIPHER_3DES_CBC:
2369 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
2370 cipherdata.algmode = OP_ALG_AAI_CBC;
2371 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
2373 case RTE_CRYPTO_CIPHER_AES_CTR:
2374 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2375 cipherdata.algmode = OP_ALG_AAI_CTR;
2376 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
2378 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2379 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
2380 case RTE_CRYPTO_CIPHER_NULL:
2381 case RTE_CRYPTO_CIPHER_3DES_ECB:
2382 case RTE_CRYPTO_CIPHER_AES_ECB:
2383 case RTE_CRYPTO_CIPHER_KASUMI_F8:
2384 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
2385 cipher_xform->algo);
2388 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2389 cipher_xform->algo);
2392 session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2395 priv->flc_desc[0].desc[0] = cipherdata.keylen;
2396 priv->flc_desc[0].desc[1] = authdata.keylen;
2397 err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
2399 (unsigned int *)priv->flc_desc[0].desc,
2400 &priv->flc_desc[0].desc[2], 2);
2403 DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
2406 if (priv->flc_desc[0].desc[2] & 1) {
2407 cipherdata.key_type = RTA_DATA_IMM;
2409 cipherdata.key = DPAA2_VADDR_TO_IOVA(cipherdata.key);
2410 cipherdata.key_type = RTA_DATA_PTR;
2412 if (priv->flc_desc[0].desc[2] & (1 << 1)) {
2413 authdata.key_type = RTA_DATA_IMM;
2415 authdata.key = DPAA2_VADDR_TO_IOVA(authdata.key);
2416 authdata.key_type = RTA_DATA_PTR;
2418 priv->flc_desc[0].desc[0] = 0;
2419 priv->flc_desc[0].desc[1] = 0;
2420 priv->flc_desc[0].desc[2] = 0;
2422 if (session->ctxt_type == DPAA2_SEC_CIPHER_HASH) {
2423 bufsize = cnstr_shdsc_authenc(priv->flc_desc[0].desc, 1,
2425 &cipherdata, &authdata,
2427 ctxt->auth_only_len,
2428 session->digest_length,
2431 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2435 DPAA2_SEC_ERR("Hash before cipher not supported");
2439 flc->word1_sdl = (uint8_t)bufsize;
2440 session->ctxt = priv;
2441 for (i = 0; i < bufsize; i++)
2442 DPAA2_SEC_DEBUG("DESC[%d]:0x%x",
2443 i, priv->flc_desc[0].desc[i]);
2448 rte_free(session->cipher_key.data);
2449 rte_free(session->auth_key.data);
2455 dpaa2_sec_set_session_parameters(struct rte_cryptodev *dev,
2456 struct rte_crypto_sym_xform *xform, void *sess)
2458 dpaa2_sec_session *session = sess;
2461 PMD_INIT_FUNC_TRACE();
2463 if (unlikely(sess == NULL)) {
2464 DPAA2_SEC_ERR("Invalid session struct");
2468 memset(session, 0, sizeof(dpaa2_sec_session));
2469 /* Default IV length = 0 */
2470 session->iv.length = 0;
2473 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
2474 session->ctxt_type = DPAA2_SEC_CIPHER;
2475 ret = dpaa2_sec_cipher_init(dev, xform, session);
2477 /* Authentication Only */
2478 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2479 xform->next == NULL) {
2480 session->ctxt_type = DPAA2_SEC_AUTH;
2481 ret = dpaa2_sec_auth_init(dev, xform, session);
2483 /* Cipher then Authenticate */
2484 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
2485 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2486 session->ext_params.aead_ctxt.auth_cipher_text = true;
2487 ret = dpaa2_sec_aead_chain_init(dev, xform, session);
2489 /* Authenticate then Cipher */
2490 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2491 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2492 session->ext_params.aead_ctxt.auth_cipher_text = false;
2493 ret = dpaa2_sec_aead_chain_init(dev, xform, session);
2495 /* AEAD operation for AES-GCM kind of Algorithms */
2496 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD &&
2497 xform->next == NULL) {
2498 ret = dpaa2_sec_aead_init(dev, xform, session);
2501 DPAA2_SEC_ERR("Invalid crypto type");
2509 dpaa2_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
2510 dpaa2_sec_session *session,
2511 struct alginfo *aeaddata)
2513 PMD_INIT_FUNC_TRACE();
2515 session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length,
2516 RTE_CACHE_LINE_SIZE);
2517 if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
2518 DPAA2_SEC_ERR("No Memory for aead key");
2521 memcpy(session->aead_key.data, aead_xform->key.data,
2522 aead_xform->key.length);
2524 session->digest_length = aead_xform->digest_length;
2525 session->aead_key.length = aead_xform->key.length;
2527 aeaddata->key = (size_t)session->aead_key.data;
2528 aeaddata->keylen = session->aead_key.length;
2529 aeaddata->key_enc_flags = 0;
2530 aeaddata->key_type = RTA_DATA_IMM;
2532 switch (aead_xform->algo) {
2533 case RTE_CRYPTO_AEAD_AES_GCM:
2534 aeaddata->algtype = OP_ALG_ALGSEL_AES;
2535 aeaddata->algmode = OP_ALG_AAI_GCM;
2536 session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM;
2538 case RTE_CRYPTO_AEAD_AES_CCM:
2539 aeaddata->algtype = OP_ALG_ALGSEL_AES;
2540 aeaddata->algmode = OP_ALG_AAI_CCM;
2541 session->aead_alg = RTE_CRYPTO_AEAD_AES_CCM;
2544 DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
2548 session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
2555 dpaa2_sec_ipsec_proto_init(struct rte_crypto_cipher_xform *cipher_xform,
2556 struct rte_crypto_auth_xform *auth_xform,
2557 dpaa2_sec_session *session,
2558 struct alginfo *cipherdata,
2559 struct alginfo *authdata)
2562 session->cipher_key.data = rte_zmalloc(NULL,
2563 cipher_xform->key.length,
2564 RTE_CACHE_LINE_SIZE);
2565 if (session->cipher_key.data == NULL &&
2566 cipher_xform->key.length > 0) {
2567 DPAA2_SEC_ERR("No Memory for cipher key");
2571 session->cipher_key.length = cipher_xform->key.length;
2572 memcpy(session->cipher_key.data, cipher_xform->key.data,
2573 cipher_xform->key.length);
2574 session->cipher_alg = cipher_xform->algo;
2576 session->cipher_key.data = NULL;
2577 session->cipher_key.length = 0;
2578 session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
2582 session->auth_key.data = rte_zmalloc(NULL,
2583 auth_xform->key.length,
2584 RTE_CACHE_LINE_SIZE);
2585 if (session->auth_key.data == NULL &&
2586 auth_xform->key.length > 0) {
2587 DPAA2_SEC_ERR("No Memory for auth key");
2590 session->auth_key.length = auth_xform->key.length;
2591 memcpy(session->auth_key.data, auth_xform->key.data,
2592 auth_xform->key.length);
2593 session->auth_alg = auth_xform->algo;
2595 session->auth_key.data = NULL;
2596 session->auth_key.length = 0;
2597 session->auth_alg = RTE_CRYPTO_AUTH_NULL;
2600 authdata->key = (size_t)session->auth_key.data;
2601 authdata->keylen = session->auth_key.length;
2602 authdata->key_enc_flags = 0;
2603 authdata->key_type = RTA_DATA_IMM;
2604 switch (session->auth_alg) {
2605 case RTE_CRYPTO_AUTH_SHA1_HMAC:
2606 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA1_96;
2607 authdata->algmode = OP_ALG_AAI_HMAC;
2609 case RTE_CRYPTO_AUTH_MD5_HMAC:
2610 authdata->algtype = OP_PCL_IPSEC_HMAC_MD5_96;
2611 authdata->algmode = OP_ALG_AAI_HMAC;
2613 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2614 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_256_128;
2615 authdata->algmode = OP_ALG_AAI_HMAC;
2617 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2618 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_384_192;
2619 authdata->algmode = OP_ALG_AAI_HMAC;
2621 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2622 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_512_256;
2623 authdata->algmode = OP_ALG_AAI_HMAC;
2625 case RTE_CRYPTO_AUTH_AES_CMAC:
2626 authdata->algtype = OP_PCL_IPSEC_AES_CMAC_96;
2628 case RTE_CRYPTO_AUTH_NULL:
2629 authdata->algtype = OP_PCL_IPSEC_HMAC_NULL;
2631 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2632 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2633 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2634 case RTE_CRYPTO_AUTH_SHA1:
2635 case RTE_CRYPTO_AUTH_SHA256:
2636 case RTE_CRYPTO_AUTH_SHA512:
2637 case RTE_CRYPTO_AUTH_SHA224:
2638 case RTE_CRYPTO_AUTH_SHA384:
2639 case RTE_CRYPTO_AUTH_MD5:
2640 case RTE_CRYPTO_AUTH_AES_GMAC:
2641 case RTE_CRYPTO_AUTH_KASUMI_F9:
2642 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2643 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2644 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
2648 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2652 cipherdata->key = (size_t)session->cipher_key.data;
2653 cipherdata->keylen = session->cipher_key.length;
2654 cipherdata->key_enc_flags = 0;
2655 cipherdata->key_type = RTA_DATA_IMM;
2657 switch (session->cipher_alg) {
2658 case RTE_CRYPTO_CIPHER_AES_CBC:
2659 cipherdata->algtype = OP_PCL_IPSEC_AES_CBC;
2660 cipherdata->algmode = OP_ALG_AAI_CBC;
2662 case RTE_CRYPTO_CIPHER_3DES_CBC:
2663 cipherdata->algtype = OP_PCL_IPSEC_3DES;
2664 cipherdata->algmode = OP_ALG_AAI_CBC;
2666 case RTE_CRYPTO_CIPHER_AES_CTR:
2667 cipherdata->algtype = OP_PCL_IPSEC_AES_CTR;
2668 cipherdata->algmode = OP_ALG_AAI_CTR;
2670 case RTE_CRYPTO_CIPHER_NULL:
2671 cipherdata->algtype = OP_PCL_IPSEC_NULL;
2673 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2674 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
2675 case RTE_CRYPTO_CIPHER_3DES_ECB:
2676 case RTE_CRYPTO_CIPHER_AES_ECB:
2677 case RTE_CRYPTO_CIPHER_KASUMI_F8:
2678 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
2679 session->cipher_alg);
2682 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2683 session->cipher_alg);
2690 #ifdef RTE_LIBRTE_SECURITY_TEST
2691 static uint8_t aes_cbc_iv[] = {
2692 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2693 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
2697 dpaa2_sec_set_ipsec_session(struct rte_cryptodev *dev,
2698 struct rte_security_session_conf *conf,
2701 struct rte_security_ipsec_xform *ipsec_xform = &conf->ipsec;
2702 struct rte_crypto_cipher_xform *cipher_xform = NULL;
2703 struct rte_crypto_auth_xform *auth_xform = NULL;
2704 struct rte_crypto_aead_xform *aead_xform = NULL;
2705 dpaa2_sec_session *session = (dpaa2_sec_session *)sess;
2706 struct ctxt_priv *priv;
2707 struct ipsec_encap_pdb encap_pdb;
2708 struct ipsec_decap_pdb decap_pdb;
2709 struct alginfo authdata, cipherdata;
2711 struct sec_flow_context *flc;
2712 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2715 PMD_INIT_FUNC_TRACE();
2717 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2718 sizeof(struct ctxt_priv) +
2719 sizeof(struct sec_flc_desc),
2720 RTE_CACHE_LINE_SIZE);
2723 DPAA2_SEC_ERR("No memory for priv CTXT");
2727 priv->fle_pool = dev_priv->fle_pool;
2728 flc = &priv->flc_desc[0].flc;
2730 memset(session, 0, sizeof(dpaa2_sec_session));
2732 if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2733 cipher_xform = &conf->crypto_xform->cipher;
2734 if (conf->crypto_xform->next)
2735 auth_xform = &conf->crypto_xform->next->auth;
2736 ret = dpaa2_sec_ipsec_proto_init(cipher_xform, auth_xform,
2737 session, &cipherdata, &authdata);
2738 } else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2739 auth_xform = &conf->crypto_xform->auth;
2740 if (conf->crypto_xform->next)
2741 cipher_xform = &conf->crypto_xform->next->cipher;
2742 ret = dpaa2_sec_ipsec_proto_init(cipher_xform, auth_xform,
2743 session, &cipherdata, &authdata);
2744 } else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
2745 aead_xform = &conf->crypto_xform->aead;
2746 ret = dpaa2_sec_ipsec_aead_init(aead_xform,
2747 session, &cipherdata);
2749 DPAA2_SEC_ERR("XFORM not specified");
2754 DPAA2_SEC_ERR("Failed to process xform");
2758 session->ctxt_type = DPAA2_SEC_IPSEC;
2759 if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
2760 uint8_t *hdr = NULL;
2762 struct rte_ipv6_hdr ip6_hdr;
2764 flc->dhr = SEC_FLC_DHR_OUTBOUND;
2765 /* For Sec Proto only one descriptor is required. */
2766 memset(&encap_pdb, 0, sizeof(struct ipsec_encap_pdb));
2767 encap_pdb.options = (IPVERSION << PDBNH_ESP_ENCAP_SHIFT) |
2768 PDBOPTS_ESP_OIHI_PDB_INL |
2770 PDBHMO_ESP_ENCAP_DTTL |
2772 if (ipsec_xform->options.esn)
2773 encap_pdb.options |= PDBOPTS_ESP_ESN;
2774 encap_pdb.spi = ipsec_xform->spi;
2775 session->dir = DIR_ENC;
2776 if (ipsec_xform->tunnel.type ==
2777 RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
2778 encap_pdb.ip_hdr_len = sizeof(struct ip);
2779 ip4_hdr.ip_v = IPVERSION;
2781 ip4_hdr.ip_len = rte_cpu_to_be_16(sizeof(ip4_hdr));
2782 ip4_hdr.ip_tos = ipsec_xform->tunnel.ipv4.dscp;
2785 ip4_hdr.ip_ttl = ipsec_xform->tunnel.ipv4.ttl;
2786 ip4_hdr.ip_p = IPPROTO_ESP;
2788 ip4_hdr.ip_src = ipsec_xform->tunnel.ipv4.src_ip;
2789 ip4_hdr.ip_dst = ipsec_xform->tunnel.ipv4.dst_ip;
2790 ip4_hdr.ip_sum = calc_chksum((uint16_t *)(void *)
2791 &ip4_hdr, sizeof(struct ip));
2792 hdr = (uint8_t *)&ip4_hdr;
2793 } else if (ipsec_xform->tunnel.type ==
2794 RTE_SECURITY_IPSEC_TUNNEL_IPV6) {
2795 ip6_hdr.vtc_flow = rte_cpu_to_be_32(
2796 DPAA2_IPv6_DEFAULT_VTC_FLOW |
2797 ((ipsec_xform->tunnel.ipv6.dscp <<
2798 RTE_IPV6_HDR_TC_SHIFT) &
2799 RTE_IPV6_HDR_TC_MASK) |
2800 ((ipsec_xform->tunnel.ipv6.flabel <<
2801 RTE_IPV6_HDR_FL_SHIFT) &
2802 RTE_IPV6_HDR_FL_MASK));
2803 /* Payload length will be updated by HW */
2804 ip6_hdr.payload_len = 0;
2805 ip6_hdr.hop_limits =
2806 ipsec_xform->tunnel.ipv6.hlimit;
2807 ip6_hdr.proto = (ipsec_xform->proto ==
2808 RTE_SECURITY_IPSEC_SA_PROTO_ESP) ?
2809 IPPROTO_ESP : IPPROTO_AH;
2810 memcpy(&ip6_hdr.src_addr,
2811 &ipsec_xform->tunnel.ipv6.src_addr, 16);
2812 memcpy(&ip6_hdr.dst_addr,
2813 &ipsec_xform->tunnel.ipv6.dst_addr, 16);
2814 encap_pdb.ip_hdr_len = sizeof(struct rte_ipv6_hdr);
2815 hdr = (uint8_t *)&ip6_hdr;
2818 bufsize = cnstr_shdsc_ipsec_new_encap(priv->flc_desc[0].desc,
2819 1, 0, SHR_SERIAL, &encap_pdb,
2820 hdr, &cipherdata, &authdata);
2821 } else if (ipsec_xform->direction ==
2822 RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
2823 flc->dhr = SEC_FLC_DHR_INBOUND;
2824 memset(&decap_pdb, 0, sizeof(struct ipsec_decap_pdb));
2825 decap_pdb.options = sizeof(struct ip) << 16;
2826 if (ipsec_xform->options.esn)
2827 decap_pdb.options |= PDBOPTS_ESP_ESN;
2828 decap_pdb.options = (ipsec_xform->tunnel.type ==
2829 RTE_SECURITY_IPSEC_TUNNEL_IPV4) ?
2830 sizeof(struct ip) << 16 :
2831 sizeof(struct rte_ipv6_hdr) << 16;
2832 session->dir = DIR_DEC;
2833 bufsize = cnstr_shdsc_ipsec_new_decap(priv->flc_desc[0].desc,
2835 &decap_pdb, &cipherdata, &authdata);
2840 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2844 flc->word1_sdl = (uint8_t)bufsize;
2846 /* Enable the stashing control bit */
2847 DPAA2_SET_FLC_RSC(flc);
2848 flc->word2_rflc_31_0 = lower_32_bits(
2849 (size_t)&(((struct dpaa2_sec_qp *)
2850 dev->data->queue_pairs[0])->rx_vq) | 0x14);
2851 flc->word3_rflc_63_32 = upper_32_bits(
2852 (size_t)&(((struct dpaa2_sec_qp *)
2853 dev->data->queue_pairs[0])->rx_vq));
2855 /* Set EWS bit i.e. enable write-safe */
2856 DPAA2_SET_FLC_EWS(flc);
2857 /* Set BS = 1 i.e reuse input buffers as output buffers */
2858 DPAA2_SET_FLC_REUSE_BS(flc);
2859 /* Set FF = 10; reuse input buffers if they provide sufficient space */
2860 DPAA2_SET_FLC_REUSE_FF(flc);
2862 session->ctxt = priv;
2866 rte_free(session->auth_key.data);
2867 rte_free(session->cipher_key.data);
2873 dpaa2_sec_set_pdcp_session(struct rte_cryptodev *dev,
2874 struct rte_security_session_conf *conf,
2877 struct rte_security_pdcp_xform *pdcp_xform = &conf->pdcp;
2878 struct rte_crypto_sym_xform *xform = conf->crypto_xform;
2879 struct rte_crypto_auth_xform *auth_xform = NULL;
2880 struct rte_crypto_cipher_xform *cipher_xform;
2881 dpaa2_sec_session *session = (dpaa2_sec_session *)sess;
2882 struct ctxt_priv *priv;
2883 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2884 struct alginfo authdata, cipherdata;
2885 struct alginfo *p_authdata = NULL;
2887 struct sec_flow_context *flc;
2888 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
2894 PMD_INIT_FUNC_TRACE();
2896 memset(session, 0, sizeof(dpaa2_sec_session));
2898 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2899 sizeof(struct ctxt_priv) +
2900 sizeof(struct sec_flc_desc),
2901 RTE_CACHE_LINE_SIZE);
2904 DPAA2_SEC_ERR("No memory for priv CTXT");
2908 priv->fle_pool = dev_priv->fle_pool;
2909 flc = &priv->flc_desc[0].flc;
2911 /* find xfrm types */
2912 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
2913 cipher_xform = &xform->cipher;
2914 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
2915 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2916 session->ext_params.aead_ctxt.auth_cipher_text = true;
2917 cipher_xform = &xform->cipher;
2918 auth_xform = &xform->next->auth;
2919 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2920 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2921 session->ext_params.aead_ctxt.auth_cipher_text = false;
2922 cipher_xform = &xform->next->cipher;
2923 auth_xform = &xform->auth;
2925 DPAA2_SEC_ERR("Invalid crypto type");
2929 session->ctxt_type = DPAA2_SEC_PDCP;
2931 session->cipher_key.data = rte_zmalloc(NULL,
2932 cipher_xform->key.length,
2933 RTE_CACHE_LINE_SIZE);
2934 if (session->cipher_key.data == NULL &&
2935 cipher_xform->key.length > 0) {
2936 DPAA2_SEC_ERR("No Memory for cipher key");
2940 session->cipher_key.length = cipher_xform->key.length;
2941 memcpy(session->cipher_key.data, cipher_xform->key.data,
2942 cipher_xform->key.length);
2944 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2946 session->cipher_alg = cipher_xform->algo;
2948 session->cipher_key.data = NULL;
2949 session->cipher_key.length = 0;
2950 session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
2951 session->dir = DIR_ENC;
2954 session->pdcp.domain = pdcp_xform->domain;
2955 session->pdcp.bearer = pdcp_xform->bearer;
2956 session->pdcp.pkt_dir = pdcp_xform->pkt_dir;
2957 session->pdcp.sn_size = pdcp_xform->sn_size;
2958 session->pdcp.hfn = pdcp_xform->hfn;
2959 session->pdcp.hfn_threshold = pdcp_xform->hfn_threshold;
2960 session->pdcp.hfn_ovd = pdcp_xform->hfn_ovrd;
2961 /* hfv ovd offset location is stored in iv.offset value*/
2962 session->pdcp.hfn_ovd_offset = cipher_xform->iv.offset;
2964 cipherdata.key = (size_t)session->cipher_key.data;
2965 cipherdata.keylen = session->cipher_key.length;
2966 cipherdata.key_enc_flags = 0;
2967 cipherdata.key_type = RTA_DATA_IMM;
2969 switch (session->cipher_alg) {
2970 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2971 cipherdata.algtype = PDCP_CIPHER_TYPE_SNOW;
2973 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
2974 cipherdata.algtype = PDCP_CIPHER_TYPE_ZUC;
2976 case RTE_CRYPTO_CIPHER_AES_CTR:
2977 cipherdata.algtype = PDCP_CIPHER_TYPE_AES;
2979 case RTE_CRYPTO_CIPHER_NULL:
2980 cipherdata.algtype = PDCP_CIPHER_TYPE_NULL;
2983 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2984 session->cipher_alg);
2989 session->auth_key.data = rte_zmalloc(NULL,
2990 auth_xform->key.length,
2991 RTE_CACHE_LINE_SIZE);
2992 if (!session->auth_key.data &&
2993 auth_xform->key.length > 0) {
2994 DPAA2_SEC_ERR("No Memory for auth key");
2995 rte_free(session->cipher_key.data);
2999 session->auth_key.length = auth_xform->key.length;
3000 memcpy(session->auth_key.data, auth_xform->key.data,
3001 auth_xform->key.length);
3002 session->auth_alg = auth_xform->algo;
3004 session->auth_key.data = NULL;
3005 session->auth_key.length = 0;
3006 session->auth_alg = 0;
3008 authdata.key = (size_t)session->auth_key.data;
3009 authdata.keylen = session->auth_key.length;
3010 authdata.key_enc_flags = 0;
3011 authdata.key_type = RTA_DATA_IMM;
3013 if (session->auth_alg) {
3014 switch (session->auth_alg) {
3015 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
3016 authdata.algtype = PDCP_AUTH_TYPE_SNOW;
3018 case RTE_CRYPTO_AUTH_ZUC_EIA3:
3019 authdata.algtype = PDCP_AUTH_TYPE_ZUC;
3021 case RTE_CRYPTO_AUTH_AES_CMAC:
3022 authdata.algtype = PDCP_AUTH_TYPE_AES;
3024 case RTE_CRYPTO_AUTH_NULL:
3025 authdata.algtype = PDCP_AUTH_TYPE_NULL;
3028 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
3033 p_authdata = &authdata;
3034 } else if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
3035 DPAA2_SEC_ERR("Crypto: Integrity must for c-plane");
3039 if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
3040 if (session->dir == DIR_ENC)
3041 bufsize = cnstr_shdsc_pdcp_c_plane_encap(
3042 priv->flc_desc[0].desc, 1, swap,
3044 session->pdcp.sn_size,
3046 pdcp_xform->pkt_dir,
3047 pdcp_xform->hfn_threshold,
3048 &cipherdata, &authdata,
3050 else if (session->dir == DIR_DEC)
3051 bufsize = cnstr_shdsc_pdcp_c_plane_decap(
3052 priv->flc_desc[0].desc, 1, swap,
3054 session->pdcp.sn_size,
3056 pdcp_xform->pkt_dir,
3057 pdcp_xform->hfn_threshold,
3058 &cipherdata, &authdata,
3061 if (session->dir == DIR_ENC)
3062 bufsize = cnstr_shdsc_pdcp_u_plane_encap(
3063 priv->flc_desc[0].desc, 1, swap,
3064 session->pdcp.sn_size,
3067 pdcp_xform->pkt_dir,
3068 pdcp_xform->hfn_threshold,
3069 &cipherdata, p_authdata, 0);
3070 else if (session->dir == DIR_DEC)
3071 bufsize = cnstr_shdsc_pdcp_u_plane_decap(
3072 priv->flc_desc[0].desc, 1, swap,
3073 session->pdcp.sn_size,
3076 pdcp_xform->pkt_dir,
3077 pdcp_xform->hfn_threshold,
3078 &cipherdata, p_authdata, 0);
3082 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
3086 /* Enable the stashing control bit */
3087 DPAA2_SET_FLC_RSC(flc);
3088 flc->word2_rflc_31_0 = lower_32_bits(
3089 (size_t)&(((struct dpaa2_sec_qp *)
3090 dev->data->queue_pairs[0])->rx_vq) | 0x14);
3091 flc->word3_rflc_63_32 = upper_32_bits(
3092 (size_t)&(((struct dpaa2_sec_qp *)
3093 dev->data->queue_pairs[0])->rx_vq));
3095 flc->word1_sdl = (uint8_t)bufsize;
3097 /* TODO - check the perf impact or
3098 * align as per descriptor type
3099 * Set EWS bit i.e. enable write-safe
3100 * DPAA2_SET_FLC_EWS(flc);
3103 /* Set BS = 1 i.e reuse input buffers as output buffers */
3104 DPAA2_SET_FLC_REUSE_BS(flc);
3105 /* Set FF = 10; reuse input buffers if they provide sufficient space */
3106 DPAA2_SET_FLC_REUSE_FF(flc);
3108 session->ctxt = priv;
3112 rte_free(session->auth_key.data);
3113 rte_free(session->cipher_key.data);
3119 dpaa2_sec_security_session_create(void *dev,
3120 struct rte_security_session_conf *conf,
3121 struct rte_security_session *sess,
3122 struct rte_mempool *mempool)
3124 void *sess_private_data;
3125 struct rte_cryptodev *cdev = (struct rte_cryptodev *)dev;
3128 if (rte_mempool_get(mempool, &sess_private_data)) {
3129 DPAA2_SEC_ERR("Couldn't get object from session mempool");
3133 switch (conf->protocol) {
3134 case RTE_SECURITY_PROTOCOL_IPSEC:
3135 ret = dpaa2_sec_set_ipsec_session(cdev, conf,
3138 case RTE_SECURITY_PROTOCOL_MACSEC:
3140 case RTE_SECURITY_PROTOCOL_PDCP:
3141 ret = dpaa2_sec_set_pdcp_session(cdev, conf,
3148 DPAA2_SEC_ERR("Failed to configure session parameters");
3149 /* Return session to mempool */
3150 rte_mempool_put(mempool, sess_private_data);
3154 set_sec_session_private_data(sess, sess_private_data);
3159 /** Clear the memory of session so it doesn't leave key material behind */
3161 dpaa2_sec_security_session_destroy(void *dev __rte_unused,
3162 struct rte_security_session *sess)
3164 PMD_INIT_FUNC_TRACE();
3165 void *sess_priv = get_sec_session_private_data(sess);
3167 dpaa2_sec_session *s = (dpaa2_sec_session *)sess_priv;
3170 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
3173 rte_free(s->cipher_key.data);
3174 rte_free(s->auth_key.data);
3175 memset(s, 0, sizeof(dpaa2_sec_session));
3176 set_sec_session_private_data(sess, NULL);
3177 rte_mempool_put(sess_mp, sess_priv);
3183 dpaa2_sec_sym_session_configure(struct rte_cryptodev *dev,
3184 struct rte_crypto_sym_xform *xform,
3185 struct rte_cryptodev_sym_session *sess,
3186 struct rte_mempool *mempool)
3188 void *sess_private_data;
3191 if (rte_mempool_get(mempool, &sess_private_data)) {
3192 DPAA2_SEC_ERR("Couldn't get object from session mempool");
3196 ret = dpaa2_sec_set_session_parameters(dev, xform, sess_private_data);
3198 DPAA2_SEC_ERR("Failed to configure session parameters");
3199 /* Return session to mempool */
3200 rte_mempool_put(mempool, sess_private_data);
3204 set_sym_session_private_data(sess, dev->driver_id,
3210 /** Clear the memory of session so it doesn't leave key material behind */
3212 dpaa2_sec_sym_session_clear(struct rte_cryptodev *dev,
3213 struct rte_cryptodev_sym_session *sess)
3215 PMD_INIT_FUNC_TRACE();
3216 uint8_t index = dev->driver_id;
3217 void *sess_priv = get_sym_session_private_data(sess, index);
3218 dpaa2_sec_session *s = (dpaa2_sec_session *)sess_priv;
3222 rte_free(s->cipher_key.data);
3223 rte_free(s->auth_key.data);
3224 memset(s, 0, sizeof(dpaa2_sec_session));
3225 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
3226 set_sym_session_private_data(sess, index, NULL);
3227 rte_mempool_put(sess_mp, sess_priv);
3232 dpaa2_sec_dev_configure(struct rte_cryptodev *dev __rte_unused,
3233 struct rte_cryptodev_config *config __rte_unused)
3235 PMD_INIT_FUNC_TRACE();
3241 dpaa2_sec_dev_start(struct rte_cryptodev *dev)
3243 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3244 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3245 struct dpseci_attr attr;
3246 struct dpaa2_queue *dpaa2_q;
3247 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3248 dev->data->queue_pairs;
3249 struct dpseci_rx_queue_attr rx_attr;
3250 struct dpseci_tx_queue_attr tx_attr;
3253 PMD_INIT_FUNC_TRACE();
3255 memset(&attr, 0, sizeof(struct dpseci_attr));
3257 ret = dpseci_enable(dpseci, CMD_PRI_LOW, priv->token);
3259 DPAA2_SEC_ERR("DPSECI with HW_ID = %d ENABLE FAILED",
3261 goto get_attr_failure;
3263 ret = dpseci_get_attributes(dpseci, CMD_PRI_LOW, priv->token, &attr);
3265 DPAA2_SEC_ERR("DPSEC ATTRIBUTE READ FAILED, disabling DPSEC");
3266 goto get_attr_failure;
3268 for (i = 0; i < attr.num_rx_queues && qp[i]; i++) {
3269 dpaa2_q = &qp[i]->rx_vq;
3270 dpseci_get_rx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
3272 dpaa2_q->fqid = rx_attr.fqid;
3273 DPAA2_SEC_DEBUG("rx_fqid: %d", dpaa2_q->fqid);
3275 for (i = 0; i < attr.num_tx_queues && qp[i]; i++) {
3276 dpaa2_q = &qp[i]->tx_vq;
3277 dpseci_get_tx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
3279 dpaa2_q->fqid = tx_attr.fqid;
3280 DPAA2_SEC_DEBUG("tx_fqid: %d", dpaa2_q->fqid);
3285 dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
3290 dpaa2_sec_dev_stop(struct rte_cryptodev *dev)
3292 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3293 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3296 PMD_INIT_FUNC_TRACE();
3298 ret = dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
3300 DPAA2_SEC_ERR("Failure in disabling dpseci %d device",
3305 ret = dpseci_reset(dpseci, CMD_PRI_LOW, priv->token);
3307 DPAA2_SEC_ERR("SEC Device cannot be reset:Error = %0x", ret);
3313 dpaa2_sec_dev_close(struct rte_cryptodev *dev)
3315 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3316 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3319 PMD_INIT_FUNC_TRACE();
3321 /* Function is reverse of dpaa2_sec_dev_init.
3322 * It does the following:
3323 * 1. Detach a DPSECI from attached resources i.e. buffer pools, dpbp_id
3324 * 2. Close the DPSECI device
3325 * 3. Free the allocated resources.
3328 /*Close the device at underlying layer*/
3329 ret = dpseci_close(dpseci, CMD_PRI_LOW, priv->token);
3331 DPAA2_SEC_ERR("Failure closing dpseci device: err(%d)", ret);
3335 /*Free the allocated memory for ethernet private data and dpseci*/
3343 dpaa2_sec_dev_infos_get(struct rte_cryptodev *dev,
3344 struct rte_cryptodev_info *info)
3346 struct dpaa2_sec_dev_private *internals = dev->data->dev_private;
3348 PMD_INIT_FUNC_TRACE();
3350 info->max_nb_queue_pairs = internals->max_nb_queue_pairs;
3351 info->feature_flags = dev->feature_flags;
3352 info->capabilities = dpaa2_sec_capabilities;
3353 /* No limit of number of sessions */
3354 info->sym.max_nb_sessions = 0;
3355 info->driver_id = cryptodev_driver_id;
3360 void dpaa2_sec_stats_get(struct rte_cryptodev *dev,
3361 struct rte_cryptodev_stats *stats)
3363 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3364 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3365 struct dpseci_sec_counters counters = {0};
3366 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3367 dev->data->queue_pairs;
3370 PMD_INIT_FUNC_TRACE();
3371 if (stats == NULL) {
3372 DPAA2_SEC_ERR("Invalid stats ptr NULL");
3375 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
3376 if (qp[i] == NULL) {
3377 DPAA2_SEC_DEBUG("Uninitialised queue pair");
3381 stats->enqueued_count += qp[i]->tx_vq.tx_pkts;
3382 stats->dequeued_count += qp[i]->rx_vq.rx_pkts;
3383 stats->enqueue_err_count += qp[i]->tx_vq.err_pkts;
3384 stats->dequeue_err_count += qp[i]->rx_vq.err_pkts;
3387 ret = dpseci_get_sec_counters(dpseci, CMD_PRI_LOW, priv->token,
3390 DPAA2_SEC_ERR("SEC counters failed");
3392 DPAA2_SEC_INFO("dpseci hardware stats:"
3393 "\n\tNum of Requests Dequeued = %" PRIu64
3394 "\n\tNum of Outbound Encrypt Requests = %" PRIu64
3395 "\n\tNum of Inbound Decrypt Requests = %" PRIu64
3396 "\n\tNum of Outbound Bytes Encrypted = %" PRIu64
3397 "\n\tNum of Outbound Bytes Protected = %" PRIu64
3398 "\n\tNum of Inbound Bytes Decrypted = %" PRIu64
3399 "\n\tNum of Inbound Bytes Validated = %" PRIu64,
3400 counters.dequeued_requests,
3401 counters.ob_enc_requests,
3402 counters.ib_dec_requests,
3403 counters.ob_enc_bytes,
3404 counters.ob_prot_bytes,
3405 counters.ib_dec_bytes,
3406 counters.ib_valid_bytes);
3411 void dpaa2_sec_stats_reset(struct rte_cryptodev *dev)
3414 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3415 (dev->data->queue_pairs);
3417 PMD_INIT_FUNC_TRACE();
3419 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
3420 if (qp[i] == NULL) {
3421 DPAA2_SEC_DEBUG("Uninitialised queue pair");
3424 qp[i]->tx_vq.rx_pkts = 0;
3425 qp[i]->tx_vq.tx_pkts = 0;
3426 qp[i]->tx_vq.err_pkts = 0;
3427 qp[i]->rx_vq.rx_pkts = 0;
3428 qp[i]->rx_vq.tx_pkts = 0;
3429 qp[i]->rx_vq.err_pkts = 0;
3433 static void __attribute__((hot))
3434 dpaa2_sec_process_parallel_event(struct qbman_swp *swp,
3435 const struct qbman_fd *fd,
3436 const struct qbman_result *dq,
3437 struct dpaa2_queue *rxq,
3438 struct rte_event *ev)
3440 /* Prefetching mbuf */
3441 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-
3442 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size));
3444 /* Prefetching ipsec crypto_op stored in priv data of mbuf */
3445 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-64));
3447 ev->flow_id = rxq->ev.flow_id;
3448 ev->sub_event_type = rxq->ev.sub_event_type;
3449 ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
3450 ev->op = RTE_EVENT_OP_NEW;
3451 ev->sched_type = rxq->ev.sched_type;
3452 ev->queue_id = rxq->ev.queue_id;
3453 ev->priority = rxq->ev.priority;
3454 ev->event_ptr = sec_fd_to_mbuf(fd);
3456 qbman_swp_dqrr_consume(swp, dq);
3459 dpaa2_sec_process_atomic_event(struct qbman_swp *swp __attribute__((unused)),
3460 const struct qbman_fd *fd,
3461 const struct qbman_result *dq,
3462 struct dpaa2_queue *rxq,
3463 struct rte_event *ev)
3466 struct rte_crypto_op *crypto_op = (struct rte_crypto_op *)ev->event_ptr;
3467 /* Prefetching mbuf */
3468 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-
3469 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size));
3471 /* Prefetching ipsec crypto_op stored in priv data of mbuf */
3472 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-64));
3474 ev->flow_id = rxq->ev.flow_id;
3475 ev->sub_event_type = rxq->ev.sub_event_type;
3476 ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
3477 ev->op = RTE_EVENT_OP_NEW;
3478 ev->sched_type = rxq->ev.sched_type;
3479 ev->queue_id = rxq->ev.queue_id;
3480 ev->priority = rxq->ev.priority;
3482 ev->event_ptr = sec_fd_to_mbuf(fd);
3483 dqrr_index = qbman_get_dqrr_idx(dq);
3484 crypto_op->sym->m_src->seqn = dqrr_index + 1;
3485 DPAA2_PER_LCORE_DQRR_SIZE++;
3486 DPAA2_PER_LCORE_DQRR_HELD |= 1 << dqrr_index;
3487 DPAA2_PER_LCORE_DQRR_MBUF(dqrr_index) = crypto_op->sym->m_src;
3491 dpaa2_sec_eventq_attach(const struct rte_cryptodev *dev,
3494 const struct rte_event *event)
3496 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3497 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3498 struct dpaa2_sec_qp *qp = dev->data->queue_pairs[qp_id];
3499 struct dpseci_rx_queue_cfg cfg;
3502 if (event->sched_type == RTE_SCHED_TYPE_PARALLEL)
3503 qp->rx_vq.cb = dpaa2_sec_process_parallel_event;
3504 else if (event->sched_type == RTE_SCHED_TYPE_ATOMIC)
3505 qp->rx_vq.cb = dpaa2_sec_process_atomic_event;
3509 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
3510 cfg.options = DPSECI_QUEUE_OPT_DEST;
3511 cfg.dest_cfg.dest_type = DPSECI_DEST_DPCON;
3512 cfg.dest_cfg.dest_id = dpcon_id;
3513 cfg.dest_cfg.priority = event->priority;
3515 cfg.options |= DPSECI_QUEUE_OPT_USER_CTX;
3516 cfg.user_ctx = (size_t)(qp);
3517 if (event->sched_type == RTE_SCHED_TYPE_ATOMIC) {
3518 cfg.options |= DPSECI_QUEUE_OPT_ORDER_PRESERVATION;
3519 cfg.order_preservation_en = 1;
3521 ret = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
3524 RTE_LOG(ERR, PMD, "Error in dpseci_set_queue: ret: %d\n", ret);
3528 memcpy(&qp->rx_vq.ev, event, sizeof(struct rte_event));
3534 dpaa2_sec_eventq_detach(const struct rte_cryptodev *dev,
3537 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3538 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3539 struct dpseci_rx_queue_cfg cfg;
3542 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
3543 cfg.options = DPSECI_QUEUE_OPT_DEST;
3544 cfg.dest_cfg.dest_type = DPSECI_DEST_NONE;
3546 ret = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
3549 RTE_LOG(ERR, PMD, "Error in dpseci_set_queue: ret: %d\n", ret);
3554 static struct rte_cryptodev_ops crypto_ops = {
3555 .dev_configure = dpaa2_sec_dev_configure,
3556 .dev_start = dpaa2_sec_dev_start,
3557 .dev_stop = dpaa2_sec_dev_stop,
3558 .dev_close = dpaa2_sec_dev_close,
3559 .dev_infos_get = dpaa2_sec_dev_infos_get,
3560 .stats_get = dpaa2_sec_stats_get,
3561 .stats_reset = dpaa2_sec_stats_reset,
3562 .queue_pair_setup = dpaa2_sec_queue_pair_setup,
3563 .queue_pair_release = dpaa2_sec_queue_pair_release,
3564 .queue_pair_count = dpaa2_sec_queue_pair_count,
3565 .sym_session_get_size = dpaa2_sec_sym_session_get_size,
3566 .sym_session_configure = dpaa2_sec_sym_session_configure,
3567 .sym_session_clear = dpaa2_sec_sym_session_clear,
3570 static const struct rte_security_capability *
3571 dpaa2_sec_capabilities_get(void *device __rte_unused)
3573 return dpaa2_sec_security_cap;
3576 static const struct rte_security_ops dpaa2_sec_security_ops = {
3577 .session_create = dpaa2_sec_security_session_create,
3578 .session_update = NULL,
3579 .session_stats_get = NULL,
3580 .session_destroy = dpaa2_sec_security_session_destroy,
3581 .set_pkt_metadata = NULL,
3582 .capabilities_get = dpaa2_sec_capabilities_get
3586 dpaa2_sec_uninit(const struct rte_cryptodev *dev)
3588 struct dpaa2_sec_dev_private *internals = dev->data->dev_private;
3590 rte_free(dev->security_ctx);
3592 rte_mempool_free(internals->fle_pool);
3594 DPAA2_SEC_INFO("Closing DPAA2_SEC device %s on numa socket %u",
3595 dev->data->name, rte_socket_id());
3601 dpaa2_sec_dev_init(struct rte_cryptodev *cryptodev)
3603 struct dpaa2_sec_dev_private *internals;
3604 struct rte_device *dev = cryptodev->device;
3605 struct rte_dpaa2_device *dpaa2_dev;
3606 struct rte_security_ctx *security_instance;
3607 struct fsl_mc_io *dpseci;
3609 struct dpseci_attr attr;
3613 PMD_INIT_FUNC_TRACE();
3614 dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
3615 if (dpaa2_dev == NULL) {
3616 DPAA2_SEC_ERR("DPAA2 SEC device not found");
3619 hw_id = dpaa2_dev->object_id;
3621 cryptodev->driver_id = cryptodev_driver_id;
3622 cryptodev->dev_ops = &crypto_ops;
3624 cryptodev->enqueue_burst = dpaa2_sec_enqueue_burst;
3625 cryptodev->dequeue_burst = dpaa2_sec_dequeue_burst;
3626 cryptodev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
3627 RTE_CRYPTODEV_FF_HW_ACCELERATED |
3628 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
3629 RTE_CRYPTODEV_FF_SECURITY |
3630 RTE_CRYPTODEV_FF_IN_PLACE_SGL |
3631 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT |
3632 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
3633 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT |
3634 RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT;
3636 internals = cryptodev->data->dev_private;
3639 * For secondary processes, we don't initialise any further as primary
3640 * has already done this work. Only check we don't need a different
3643 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
3644 DPAA2_SEC_DEBUG("Device already init by primary process");
3648 /* Initialize security_ctx only for primary process*/
3649 security_instance = rte_malloc("rte_security_instances_ops",
3650 sizeof(struct rte_security_ctx), 0);
3651 if (security_instance == NULL)
3653 security_instance->device = (void *)cryptodev;
3654 security_instance->ops = &dpaa2_sec_security_ops;
3655 security_instance->sess_cnt = 0;
3656 cryptodev->security_ctx = security_instance;
3658 /*Open the rte device via MC and save the handle for further use*/
3659 dpseci = (struct fsl_mc_io *)rte_calloc(NULL, 1,
3660 sizeof(struct fsl_mc_io), 0);
3663 "Error in allocating the memory for dpsec object");
3666 dpseci->regs = rte_mcp_ptr_list[0];
3668 retcode = dpseci_open(dpseci, CMD_PRI_LOW, hw_id, &token);
3670 DPAA2_SEC_ERR("Cannot open the dpsec device: Error = %x",
3674 retcode = dpseci_get_attributes(dpseci, CMD_PRI_LOW, token, &attr);
3677 "Cannot get dpsec device attributed: Error = %x",
3681 snprintf(cryptodev->data->name, sizeof(cryptodev->data->name),
3684 internals->max_nb_queue_pairs = attr.num_tx_queues;
3685 cryptodev->data->nb_queue_pairs = internals->max_nb_queue_pairs;
3686 internals->hw = dpseci;
3687 internals->token = token;
3689 snprintf(str, sizeof(str), "sec_fle_pool_p%d_%d",
3690 getpid(), cryptodev->data->dev_id);
3691 internals->fle_pool = rte_mempool_create((const char *)str,
3694 FLE_POOL_CACHE_SIZE, 0,
3695 NULL, NULL, NULL, NULL,
3697 if (!internals->fle_pool) {
3698 DPAA2_SEC_ERR("Mempool (%s) creation failed", str);
3702 DPAA2_SEC_INFO("driver %s: created", cryptodev->data->name);
3706 DPAA2_SEC_ERR("driver %s: create failed", cryptodev->data->name);
3708 /* dpaa2_sec_uninit(crypto_dev_name); */
3713 cryptodev_dpaa2_sec_probe(struct rte_dpaa2_driver *dpaa2_drv __rte_unused,
3714 struct rte_dpaa2_device *dpaa2_dev)
3716 struct rte_cryptodev *cryptodev;
3717 char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
3721 snprintf(cryptodev_name, sizeof(cryptodev_name), "dpsec-%d",
3722 dpaa2_dev->object_id);
3724 cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
3725 if (cryptodev == NULL)
3728 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
3729 cryptodev->data->dev_private = rte_zmalloc_socket(
3730 "cryptodev private structure",
3731 sizeof(struct dpaa2_sec_dev_private),
3732 RTE_CACHE_LINE_SIZE,
3735 if (cryptodev->data->dev_private == NULL)
3736 rte_panic("Cannot allocate memzone for private "
3740 dpaa2_dev->cryptodev = cryptodev;
3741 cryptodev->device = &dpaa2_dev->device;
3743 /* init user callbacks */
3744 TAILQ_INIT(&(cryptodev->link_intr_cbs));
3746 if (dpaa2_svr_family == SVR_LX2160A)
3747 rta_set_sec_era(RTA_SEC_ERA_10);
3749 DPAA2_SEC_INFO("2-SEC ERA is %d", rta_get_sec_era());
3751 /* Invoke PMD device initialization function */
3752 retval = dpaa2_sec_dev_init(cryptodev);
3756 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
3757 rte_free(cryptodev->data->dev_private);
3759 cryptodev->attached = RTE_CRYPTODEV_DETACHED;
3765 cryptodev_dpaa2_sec_remove(struct rte_dpaa2_device *dpaa2_dev)
3767 struct rte_cryptodev *cryptodev;
3770 cryptodev = dpaa2_dev->cryptodev;
3771 if (cryptodev == NULL)
3774 ret = dpaa2_sec_uninit(cryptodev);
3778 return rte_cryptodev_pmd_destroy(cryptodev);
3781 static struct rte_dpaa2_driver rte_dpaa2_sec_driver = {
3782 .drv_flags = RTE_DPAA2_DRV_IOVA_AS_VA,
3783 .drv_type = DPAA2_CRYPTO,
3785 .name = "DPAA2 SEC PMD"
3787 .probe = cryptodev_dpaa2_sec_probe,
3788 .remove = cryptodev_dpaa2_sec_remove,
3791 static struct cryptodev_driver dpaa2_sec_crypto_drv;
3793 RTE_PMD_REGISTER_DPAA2(CRYPTODEV_NAME_DPAA2_SEC_PMD, rte_dpaa2_sec_driver);
3794 RTE_PMD_REGISTER_CRYPTO_DRIVER(dpaa2_sec_crypto_drv,
3795 rte_dpaa2_sec_driver.driver, cryptodev_driver_id);
3797 RTE_INIT(dpaa2_sec_init_log)
3799 /* Bus level logs */
3800 dpaa2_logtype_sec = rte_log_register("pmd.crypto.dpaa2");
3801 if (dpaa2_logtype_sec >= 0)
3802 rte_log_set_level(dpaa2_logtype_sec, RTE_LOG_NOTICE);