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(num) (FLE_POOL_BUF_SIZE + ((num) * 32))
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,
87 FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
90 DPAA2_SEC_DP_ERR("Proto:SG: Memory alloc failed for SGE");
93 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
94 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
95 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
97 /* Save the shared descriptor */
98 flc = &priv->flc_desc[0].flc;
104 if (likely(bpid < MAX_BPID)) {
105 DPAA2_SET_FD_BPID(fd, bpid);
106 DPAA2_SET_FLE_BPID(op_fle, bpid);
107 DPAA2_SET_FLE_BPID(ip_fle, bpid);
109 DPAA2_SET_FD_IVP(fd);
110 DPAA2_SET_FLE_IVP(op_fle);
111 DPAA2_SET_FLE_IVP(ip_fle);
114 /* Configure FD as a FRAME LIST */
115 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
116 DPAA2_SET_FD_COMPOUND_FMT(fd);
117 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
119 /* Configure Output FLE with Scatter/Gather Entry */
120 DPAA2_SET_FLE_SG_EXT(op_fle);
121 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
123 /* Configure Output SGE for Encap/Decap */
124 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
125 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
128 sge->length = mbuf->data_len;
129 out_len += sge->length;
132 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
133 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
135 /* using buf_len for last buf - so that extra data can be added */
136 sge->length = mbuf->buf_len - mbuf->data_off;
137 out_len += sge->length;
139 DPAA2_SET_FLE_FIN(sge);
140 op_fle->length = out_len;
143 mbuf = sym_op->m_src;
145 /* Configure Input FLE with Scatter/Gather Entry */
146 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
147 DPAA2_SET_FLE_SG_EXT(ip_fle);
148 DPAA2_SET_FLE_FIN(ip_fle);
150 /* Configure input SGE for Encap/Decap */
151 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
152 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
153 sge->length = mbuf->data_len;
154 in_len += sge->length;
160 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
161 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
162 sge->length = mbuf->data_len;
163 in_len += sge->length;
166 ip_fle->length = in_len;
167 DPAA2_SET_FLE_FIN(sge);
169 /* In case of PDCP, per packet HFN is stored in
170 * mbuf priv after sym_op.
172 if (sess->ctxt_type == DPAA2_SEC_PDCP && sess->pdcp.hfn_ovd) {
173 uint32_t hfn_ovd = *((uint8_t *)op + sess->pdcp.hfn_ovd_offset);
174 /*enable HFN override override */
175 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, hfn_ovd);
176 DPAA2_SET_FLE_INTERNAL_JD(op_fle, hfn_ovd);
177 DPAA2_SET_FD_INTERNAL_JD(fd, hfn_ovd);
179 DPAA2_SET_FD_LEN(fd, ip_fle->length);
185 build_proto_compound_fd(dpaa2_sec_session *sess,
186 struct rte_crypto_op *op,
187 struct qbman_fd *fd, uint16_t bpid)
189 struct rte_crypto_sym_op *sym_op = op->sym;
190 struct ctxt_priv *priv = sess->ctxt;
191 struct qbman_fle *fle, *ip_fle, *op_fle;
192 struct sec_flow_context *flc;
193 struct rte_mbuf *src_mbuf = sym_op->m_src;
194 struct rte_mbuf *dst_mbuf = sym_op->m_dst;
200 /* Save the shared descriptor */
201 flc = &priv->flc_desc[0].flc;
203 /* we are using the first FLE entry to store Mbuf */
204 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
206 DPAA2_SEC_DP_ERR("Memory alloc failed");
209 memset(fle, 0, FLE_POOL_BUF_SIZE);
210 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
211 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
216 if (likely(bpid < MAX_BPID)) {
217 DPAA2_SET_FD_BPID(fd, bpid);
218 DPAA2_SET_FLE_BPID(op_fle, bpid);
219 DPAA2_SET_FLE_BPID(ip_fle, bpid);
221 DPAA2_SET_FD_IVP(fd);
222 DPAA2_SET_FLE_IVP(op_fle);
223 DPAA2_SET_FLE_IVP(ip_fle);
226 /* Configure FD as a FRAME LIST */
227 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
228 DPAA2_SET_FD_COMPOUND_FMT(fd);
229 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
231 /* Configure Output FLE with dst mbuf data */
232 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_MBUF_VADDR_TO_IOVA(dst_mbuf));
233 DPAA2_SET_FLE_OFFSET(op_fle, dst_mbuf->data_off);
234 DPAA2_SET_FLE_LEN(op_fle, dst_mbuf->buf_len);
236 /* Configure Input FLE with src mbuf data */
237 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_MBUF_VADDR_TO_IOVA(src_mbuf));
238 DPAA2_SET_FLE_OFFSET(ip_fle, src_mbuf->data_off);
239 DPAA2_SET_FLE_LEN(ip_fle, src_mbuf->pkt_len);
241 DPAA2_SET_FD_LEN(fd, ip_fle->length);
242 DPAA2_SET_FLE_FIN(ip_fle);
244 /* In case of PDCP, per packet HFN is stored in
245 * mbuf priv after sym_op.
247 if (sess->ctxt_type == DPAA2_SEC_PDCP && sess->pdcp.hfn_ovd) {
248 uint32_t hfn_ovd = *((uint8_t *)op + sess->pdcp.hfn_ovd_offset);
249 /*enable HFN override override */
250 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, hfn_ovd);
251 DPAA2_SET_FLE_INTERNAL_JD(op_fle, hfn_ovd);
252 DPAA2_SET_FD_INTERNAL_JD(fd, hfn_ovd);
260 build_proto_fd(dpaa2_sec_session *sess,
261 struct rte_crypto_op *op,
262 struct qbman_fd *fd, uint16_t bpid)
264 struct rte_crypto_sym_op *sym_op = op->sym;
266 return build_proto_compound_fd(sess, op, fd, bpid);
268 struct ctxt_priv *priv = sess->ctxt;
269 struct sec_flow_context *flc;
270 struct rte_mbuf *mbuf = sym_op->m_src;
272 if (likely(bpid < MAX_BPID))
273 DPAA2_SET_FD_BPID(fd, bpid);
275 DPAA2_SET_FD_IVP(fd);
277 /* Save the shared descriptor */
278 flc = &priv->flc_desc[0].flc;
280 DPAA2_SET_FD_ADDR(fd, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
281 DPAA2_SET_FD_OFFSET(fd, sym_op->m_src->data_off);
282 DPAA2_SET_FD_LEN(fd, sym_op->m_src->pkt_len);
283 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
285 /* save physical address of mbuf */
286 op->sym->aead.digest.phys_addr = mbuf->buf_iova;
287 mbuf->buf_iova = (size_t)op;
293 build_authenc_gcm_sg_fd(dpaa2_sec_session *sess,
294 struct rte_crypto_op *op,
295 struct qbman_fd *fd, __rte_unused uint16_t bpid)
297 struct rte_crypto_sym_op *sym_op = op->sym;
298 struct ctxt_priv *priv = sess->ctxt;
299 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
300 struct sec_flow_context *flc;
301 uint32_t auth_only_len = sess->ext_params.aead_ctxt.auth_only_len;
302 int icv_len = sess->digest_length;
304 struct rte_mbuf *mbuf;
305 uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
309 mbuf = sym_op->m_dst;
311 mbuf = sym_op->m_src;
313 /* first FLE entry used to store mbuf and session ctxt */
314 fle = (struct qbman_fle *)rte_malloc(NULL,
315 FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
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(mbuf->nb_segs + sym_op->m_src->nb_segs));
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 *,
459 /* TODO we are using the first FLE entry to store Mbuf and session ctxt.
460 * Currently we donot know which FLE has the mbuf stored.
461 * So while retreiving we can go back 1 FLE from the FD -ADDR
462 * to get the MBUF Addr from the previous FLE.
463 * We can have a better approach to use the inline Mbuf
465 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
467 DPAA2_SEC_ERR("GCM: Memory alloc failed for SGE");
470 memset(fle, 0, FLE_POOL_BUF_SIZE);
471 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
472 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
475 if (likely(bpid < MAX_BPID)) {
476 DPAA2_SET_FD_BPID(fd, bpid);
477 DPAA2_SET_FLE_BPID(fle, bpid);
478 DPAA2_SET_FLE_BPID(fle + 1, bpid);
479 DPAA2_SET_FLE_BPID(sge, bpid);
480 DPAA2_SET_FLE_BPID(sge + 1, bpid);
481 DPAA2_SET_FLE_BPID(sge + 2, bpid);
482 DPAA2_SET_FLE_BPID(sge + 3, bpid);
484 DPAA2_SET_FD_IVP(fd);
485 DPAA2_SET_FLE_IVP(fle);
486 DPAA2_SET_FLE_IVP((fle + 1));
487 DPAA2_SET_FLE_IVP(sge);
488 DPAA2_SET_FLE_IVP((sge + 1));
489 DPAA2_SET_FLE_IVP((sge + 2));
490 DPAA2_SET_FLE_IVP((sge + 3));
493 /* Save the shared descriptor */
494 flc = &priv->flc_desc[0].flc;
495 /* Configure FD as a FRAME LIST */
496 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
497 DPAA2_SET_FD_COMPOUND_FMT(fd);
498 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
500 DPAA2_SEC_DP_DEBUG("GCM: auth_off: 0x%x/length %d, digest-len=%d\n"
501 "iv-len=%d data_off: 0x%x\n",
502 sym_op->aead.data.offset,
503 sym_op->aead.data.length,
506 sym_op->m_src->data_off);
508 /* Configure Output FLE with Scatter/Gather Entry */
509 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
511 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
512 fle->length = (sess->dir == DIR_ENC) ?
513 (sym_op->aead.data.length + icv_len + auth_only_len) :
514 sym_op->aead.data.length + auth_only_len;
516 DPAA2_SET_FLE_SG_EXT(fle);
518 /* Configure Output SGE for Encap/Decap */
519 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(dst));
520 DPAA2_SET_FLE_OFFSET(sge, dst->data_off +
521 RTE_ALIGN_CEIL(auth_only_len, 16) - auth_only_len);
522 sge->length = sym_op->aead.data.length + auth_only_len;
524 if (sess->dir == DIR_ENC) {
526 DPAA2_SET_FLE_ADDR(sge,
527 DPAA2_VADDR_TO_IOVA(sym_op->aead.digest.data));
528 sge->length = sess->digest_length;
529 DPAA2_SET_FD_LEN(fd, (sym_op->aead.data.length +
530 sess->iv.length + auth_only_len));
532 DPAA2_SET_FLE_FIN(sge);
537 /* Configure Input FLE with Scatter/Gather Entry */
538 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
539 DPAA2_SET_FLE_SG_EXT(fle);
540 DPAA2_SET_FLE_FIN(fle);
541 fle->length = (sess->dir == DIR_ENC) ?
542 (sym_op->aead.data.length + sess->iv.length + auth_only_len) :
543 (sym_op->aead.data.length + sess->iv.length + auth_only_len +
544 sess->digest_length);
546 /* Configure Input SGE for Encap/Decap */
547 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(IV_ptr));
548 sge->length = sess->iv.length;
551 DPAA2_SET_FLE_ADDR(sge,
552 DPAA2_VADDR_TO_IOVA(sym_op->aead.aad.data));
553 sge->length = auth_only_len;
554 DPAA2_SET_FLE_BPID(sge, bpid);
558 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
559 DPAA2_SET_FLE_OFFSET(sge, sym_op->aead.data.offset +
560 sym_op->m_src->data_off);
561 sge->length = sym_op->aead.data.length;
562 if (sess->dir == DIR_DEC) {
564 old_icv = (uint8_t *)(sge + 1);
565 memcpy(old_icv, sym_op->aead.digest.data,
566 sess->digest_length);
567 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
568 sge->length = sess->digest_length;
569 DPAA2_SET_FD_LEN(fd, (sym_op->aead.data.length +
570 sess->digest_length +
574 DPAA2_SET_FLE_FIN(sge);
577 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
578 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
585 build_authenc_sg_fd(dpaa2_sec_session *sess,
586 struct rte_crypto_op *op,
587 struct qbman_fd *fd, __rte_unused uint16_t bpid)
589 struct rte_crypto_sym_op *sym_op = op->sym;
590 struct ctxt_priv *priv = sess->ctxt;
591 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
592 struct sec_flow_context *flc;
593 uint32_t auth_only_len = sym_op->auth.data.length -
594 sym_op->cipher.data.length;
595 int icv_len = sess->digest_length;
597 struct rte_mbuf *mbuf;
598 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
602 mbuf = sym_op->m_dst;
604 mbuf = sym_op->m_src;
606 /* first FLE entry used to store mbuf and session ctxt */
607 fle = (struct qbman_fle *)rte_malloc(NULL,
608 FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
609 RTE_CACHE_LINE_SIZE);
610 if (unlikely(!fle)) {
611 DPAA2_SEC_ERR("AUTHENC SG: Memory alloc failed for SGE");
614 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
615 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
616 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
622 /* Save the shared descriptor */
623 flc = &priv->flc_desc[0].flc;
625 /* Configure FD as a FRAME LIST */
626 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
627 DPAA2_SET_FD_COMPOUND_FMT(fd);
628 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
631 "AUTHENC SG: auth_off: 0x%x/length %d, digest-len=%d\n"
632 "cipher_off: 0x%x/length %d, iv-len=%d data_off: 0x%x\n",
633 sym_op->auth.data.offset,
634 sym_op->auth.data.length,
636 sym_op->cipher.data.offset,
637 sym_op->cipher.data.length,
639 sym_op->m_src->data_off);
641 /* Configure Output FLE with Scatter/Gather Entry */
642 DPAA2_SET_FLE_SG_EXT(op_fle);
643 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
646 DPAA2_SET_FLE_INTERNAL_JD(op_fle, auth_only_len);
648 op_fle->length = (sess->dir == DIR_ENC) ?
649 (sym_op->cipher.data.length + icv_len) :
650 sym_op->cipher.data.length;
652 /* Configure Output SGE for Encap/Decap */
653 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
654 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off + sym_op->auth.data.offset);
655 sge->length = mbuf->data_len - sym_op->auth.data.offset;
661 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
662 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
663 sge->length = mbuf->data_len;
666 sge->length -= icv_len;
668 if (sess->dir == DIR_ENC) {
670 DPAA2_SET_FLE_ADDR(sge,
671 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
672 sge->length = icv_len;
674 DPAA2_SET_FLE_FIN(sge);
677 mbuf = sym_op->m_src;
679 /* Configure Input FLE with Scatter/Gather Entry */
680 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
681 DPAA2_SET_FLE_SG_EXT(ip_fle);
682 DPAA2_SET_FLE_FIN(ip_fle);
683 ip_fle->length = (sess->dir == DIR_ENC) ?
684 (sym_op->auth.data.length + sess->iv.length) :
685 (sym_op->auth.data.length + sess->iv.length +
688 /* Configure Input SGE for Encap/Decap */
689 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
690 sge->length = sess->iv.length;
693 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
694 DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset +
696 sge->length = mbuf->data_len - sym_op->auth.data.offset;
702 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
703 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
704 sge->length = mbuf->data_len;
707 sge->length -= icv_len;
709 if (sess->dir == DIR_DEC) {
711 old_icv = (uint8_t *)(sge + 1);
712 memcpy(old_icv, sym_op->auth.digest.data,
714 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
715 sge->length = icv_len;
718 DPAA2_SET_FLE_FIN(sge);
720 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, auth_only_len);
721 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
723 DPAA2_SET_FD_LEN(fd, ip_fle->length);
729 build_authenc_fd(dpaa2_sec_session *sess,
730 struct rte_crypto_op *op,
731 struct qbman_fd *fd, uint16_t bpid)
733 struct rte_crypto_sym_op *sym_op = op->sym;
734 struct ctxt_priv *priv = sess->ctxt;
735 struct qbman_fle *fle, *sge;
736 struct sec_flow_context *flc;
737 uint32_t auth_only_len = sym_op->auth.data.length -
738 sym_op->cipher.data.length;
739 int icv_len = sess->digest_length, retval;
741 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
743 struct rte_mbuf *dst;
750 /* we are using the first FLE entry to store Mbuf.
751 * Currently we donot know which FLE has the mbuf stored.
752 * So while retreiving we can go back 1 FLE from the FD -ADDR
753 * to get the MBUF Addr from the previous FLE.
754 * We can have a better approach to use the inline Mbuf
756 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
758 DPAA2_SEC_ERR("Memory alloc failed for SGE");
761 memset(fle, 0, FLE_POOL_BUF_SIZE);
762 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
763 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
766 if (likely(bpid < MAX_BPID)) {
767 DPAA2_SET_FD_BPID(fd, bpid);
768 DPAA2_SET_FLE_BPID(fle, bpid);
769 DPAA2_SET_FLE_BPID(fle + 1, bpid);
770 DPAA2_SET_FLE_BPID(sge, bpid);
771 DPAA2_SET_FLE_BPID(sge + 1, bpid);
772 DPAA2_SET_FLE_BPID(sge + 2, bpid);
773 DPAA2_SET_FLE_BPID(sge + 3, bpid);
775 DPAA2_SET_FD_IVP(fd);
776 DPAA2_SET_FLE_IVP(fle);
777 DPAA2_SET_FLE_IVP((fle + 1));
778 DPAA2_SET_FLE_IVP(sge);
779 DPAA2_SET_FLE_IVP((sge + 1));
780 DPAA2_SET_FLE_IVP((sge + 2));
781 DPAA2_SET_FLE_IVP((sge + 3));
784 /* Save the shared descriptor */
785 flc = &priv->flc_desc[0].flc;
786 /* Configure FD as a FRAME LIST */
787 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
788 DPAA2_SET_FD_COMPOUND_FMT(fd);
789 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
792 "AUTHENC: auth_off: 0x%x/length %d, digest-len=%d\n"
793 "cipher_off: 0x%x/length %d, iv-len=%d data_off: 0x%x\n",
794 sym_op->auth.data.offset,
795 sym_op->auth.data.length,
797 sym_op->cipher.data.offset,
798 sym_op->cipher.data.length,
800 sym_op->m_src->data_off);
802 /* Configure Output FLE with Scatter/Gather Entry */
803 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
805 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
806 fle->length = (sess->dir == DIR_ENC) ?
807 (sym_op->cipher.data.length + icv_len) :
808 sym_op->cipher.data.length;
810 DPAA2_SET_FLE_SG_EXT(fle);
812 /* Configure Output SGE for Encap/Decap */
813 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(dst));
814 DPAA2_SET_FLE_OFFSET(sge, sym_op->cipher.data.offset +
816 sge->length = sym_op->cipher.data.length;
818 if (sess->dir == DIR_ENC) {
820 DPAA2_SET_FLE_ADDR(sge,
821 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
822 sge->length = sess->digest_length;
823 DPAA2_SET_FD_LEN(fd, (sym_op->auth.data.length +
826 DPAA2_SET_FLE_FIN(sge);
831 /* Configure Input FLE with Scatter/Gather Entry */
832 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
833 DPAA2_SET_FLE_SG_EXT(fle);
834 DPAA2_SET_FLE_FIN(fle);
835 fle->length = (sess->dir == DIR_ENC) ?
836 (sym_op->auth.data.length + sess->iv.length) :
837 (sym_op->auth.data.length + sess->iv.length +
838 sess->digest_length);
840 /* Configure Input SGE for Encap/Decap */
841 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
842 sge->length = sess->iv.length;
845 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
846 DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset +
847 sym_op->m_src->data_off);
848 sge->length = sym_op->auth.data.length;
849 if (sess->dir == DIR_DEC) {
851 old_icv = (uint8_t *)(sge + 1);
852 memcpy(old_icv, sym_op->auth.digest.data,
853 sess->digest_length);
854 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
855 sge->length = sess->digest_length;
856 DPAA2_SET_FD_LEN(fd, (sym_op->auth.data.length +
857 sess->digest_length +
860 DPAA2_SET_FLE_FIN(sge);
862 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
863 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
868 static inline int build_auth_sg_fd(
869 dpaa2_sec_session *sess,
870 struct rte_crypto_op *op,
872 __rte_unused uint16_t bpid)
874 struct rte_crypto_sym_op *sym_op = op->sym;
875 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
876 struct sec_flow_context *flc;
877 struct ctxt_priv *priv = sess->ctxt;
878 int data_len, data_offset;
880 struct rte_mbuf *mbuf;
882 data_len = sym_op->auth.data.length;
883 data_offset = sym_op->auth.data.offset;
885 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
886 sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
887 if ((data_len & 7) || (data_offset & 7)) {
888 DPAA2_SEC_ERR("AUTH: len/offset must be full bytes");
892 data_len = data_len >> 3;
893 data_offset = data_offset >> 3;
896 mbuf = sym_op->m_src;
897 fle = (struct qbman_fle *)rte_malloc(NULL,
898 FLE_SG_MEM_SIZE(mbuf->nb_segs),
899 RTE_CACHE_LINE_SIZE);
900 if (unlikely(!fle)) {
901 DPAA2_SEC_ERR("AUTH SG: Memory alloc failed for SGE");
904 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs));
905 /* first FLE entry used to store mbuf and session ctxt */
906 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
907 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
912 flc = &priv->flc_desc[DESC_INITFINAL].flc;
914 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
915 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
916 DPAA2_SET_FD_COMPOUND_FMT(fd);
919 DPAA2_SET_FLE_ADDR(op_fle,
920 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
921 op_fle->length = sess->digest_length;
924 DPAA2_SET_FLE_SG_EXT(ip_fle);
925 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
926 ip_fle->length = data_len;
928 if (sess->iv.length) {
931 iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
934 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2) {
935 iv_ptr = conv_to_snow_f9_iv(iv_ptr);
937 } else if (sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
938 iv_ptr = conv_to_zuc_eia_iv(iv_ptr);
941 sge->length = sess->iv.length;
943 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
944 ip_fle->length += sge->length;
948 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
949 DPAA2_SET_FLE_OFFSET(sge, data_offset + mbuf->data_off);
951 if (data_len <= (mbuf->data_len - data_offset)) {
952 sge->length = data_len;
955 sge->length = mbuf->data_len - data_offset;
957 /* remaining i/p segs */
958 while ((data_len = data_len - sge->length) &&
959 (mbuf = mbuf->next)) {
961 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
962 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
963 if (data_len > mbuf->data_len)
964 sge->length = mbuf->data_len;
966 sge->length = data_len;
970 if (sess->dir == DIR_DEC) {
971 /* Digest verification case */
973 old_digest = (uint8_t *)(sge + 1);
974 rte_memcpy(old_digest, sym_op->auth.digest.data,
975 sess->digest_length);
976 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_digest));
977 sge->length = sess->digest_length;
978 ip_fle->length += sess->digest_length;
980 DPAA2_SET_FLE_FIN(sge);
981 DPAA2_SET_FLE_FIN(ip_fle);
982 DPAA2_SET_FD_LEN(fd, ip_fle->length);
988 build_auth_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
989 struct qbman_fd *fd, uint16_t bpid)
991 struct rte_crypto_sym_op *sym_op = op->sym;
992 struct qbman_fle *fle, *sge;
993 struct sec_flow_context *flc;
994 struct ctxt_priv *priv = sess->ctxt;
995 int data_len, data_offset;
999 data_len = sym_op->auth.data.length;
1000 data_offset = sym_op->auth.data.offset;
1002 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
1003 sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
1004 if ((data_len & 7) || (data_offset & 7)) {
1005 DPAA2_SEC_ERR("AUTH: len/offset must be full bytes");
1009 data_len = data_len >> 3;
1010 data_offset = data_offset >> 3;
1013 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
1015 DPAA2_SEC_ERR("AUTH Memory alloc failed for SGE");
1018 memset(fle, 0, FLE_POOL_BUF_SIZE);
1019 /* TODO we are using the first FLE entry to store Mbuf.
1020 * Currently we donot know which FLE has the mbuf stored.
1021 * So while retreiving we can go back 1 FLE from the FD -ADDR
1022 * to get the MBUF Addr from the previous FLE.
1023 * We can have a better approach to use the inline Mbuf
1025 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
1026 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
1030 if (likely(bpid < MAX_BPID)) {
1031 DPAA2_SET_FD_BPID(fd, bpid);
1032 DPAA2_SET_FLE_BPID(fle, bpid);
1033 DPAA2_SET_FLE_BPID(fle + 1, bpid);
1034 DPAA2_SET_FLE_BPID(sge, bpid);
1035 DPAA2_SET_FLE_BPID(sge + 1, bpid);
1037 DPAA2_SET_FD_IVP(fd);
1038 DPAA2_SET_FLE_IVP(fle);
1039 DPAA2_SET_FLE_IVP((fle + 1));
1040 DPAA2_SET_FLE_IVP(sge);
1041 DPAA2_SET_FLE_IVP((sge + 1));
1044 flc = &priv->flc_desc[DESC_INITFINAL].flc;
1045 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
1046 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
1047 DPAA2_SET_FD_COMPOUND_FMT(fd);
1049 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
1050 fle->length = sess->digest_length;
1053 /* Setting input FLE */
1054 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
1055 DPAA2_SET_FLE_SG_EXT(fle);
1056 fle->length = data_len;
1058 if (sess->iv.length) {
1061 iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1064 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2) {
1065 iv_ptr = conv_to_snow_f9_iv(iv_ptr);
1067 } else if (sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
1068 iv_ptr = conv_to_zuc_eia_iv(iv_ptr);
1071 sge->length = sess->iv.length;
1074 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
1075 fle->length = fle->length + sge->length;
1079 /* Setting data to authenticate */
1080 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
1081 DPAA2_SET_FLE_OFFSET(sge, data_offset + sym_op->m_src->data_off);
1082 sge->length = data_len;
1084 if (sess->dir == DIR_DEC) {
1086 old_digest = (uint8_t *)(sge + 1);
1087 rte_memcpy(old_digest, sym_op->auth.digest.data,
1088 sess->digest_length);
1089 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_digest));
1090 sge->length = sess->digest_length;
1091 fle->length = fle->length + sess->digest_length;
1094 DPAA2_SET_FLE_FIN(sge);
1095 DPAA2_SET_FLE_FIN(fle);
1096 DPAA2_SET_FD_LEN(fd, fle->length);
1102 build_cipher_sg_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
1103 struct qbman_fd *fd, __rte_unused uint16_t bpid)
1105 struct rte_crypto_sym_op *sym_op = op->sym;
1106 struct qbman_fle *ip_fle, *op_fle, *sge, *fle;
1107 int data_len, data_offset;
1108 struct sec_flow_context *flc;
1109 struct ctxt_priv *priv = sess->ctxt;
1110 struct rte_mbuf *mbuf;
1111 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1114 data_len = sym_op->cipher.data.length;
1115 data_offset = sym_op->cipher.data.offset;
1117 if (sess->cipher_alg == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
1118 sess->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
1119 if ((data_len & 7) || (data_offset & 7)) {
1120 DPAA2_SEC_ERR("CIPHER: len/offset must be full bytes");
1124 data_len = data_len >> 3;
1125 data_offset = data_offset >> 3;
1129 mbuf = sym_op->m_dst;
1131 mbuf = sym_op->m_src;
1133 /* first FLE entry used to store mbuf and session ctxt */
1134 fle = (struct qbman_fle *)rte_malloc(NULL,
1135 FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
1136 RTE_CACHE_LINE_SIZE);
1138 DPAA2_SEC_ERR("CIPHER SG: Memory alloc failed for SGE");
1141 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
1142 /* first FLE entry used to store mbuf and session ctxt */
1143 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
1144 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
1150 flc = &priv->flc_desc[0].flc;
1153 "CIPHER SG: cipher_off: 0x%x/length %d, ivlen=%d"
1154 " data_off: 0x%x\n",
1158 sym_op->m_src->data_off);
1161 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
1162 op_fle->length = data_len;
1163 DPAA2_SET_FLE_SG_EXT(op_fle);
1166 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1167 DPAA2_SET_FLE_OFFSET(sge, data_offset + mbuf->data_off);
1168 sge->length = mbuf->data_len - data_offset;
1174 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1175 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
1176 sge->length = mbuf->data_len;
1179 DPAA2_SET_FLE_FIN(sge);
1182 "CIPHER SG: 1 - flc = %p, fle = %p FLEaddr = %x-%x, len %d\n",
1183 flc, fle, fle->addr_hi, fle->addr_lo,
1187 mbuf = sym_op->m_src;
1189 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
1190 ip_fle->length = sess->iv.length + data_len;
1191 DPAA2_SET_FLE_SG_EXT(ip_fle);
1194 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
1195 DPAA2_SET_FLE_OFFSET(sge, 0);
1196 sge->length = sess->iv.length;
1201 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1202 DPAA2_SET_FLE_OFFSET(sge, data_offset + mbuf->data_off);
1203 sge->length = mbuf->data_len - data_offset;
1209 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1210 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
1211 sge->length = mbuf->data_len;
1214 DPAA2_SET_FLE_FIN(sge);
1215 DPAA2_SET_FLE_FIN(ip_fle);
1218 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
1219 DPAA2_SET_FD_LEN(fd, ip_fle->length);
1220 DPAA2_SET_FD_COMPOUND_FMT(fd);
1221 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
1224 "CIPHER SG: fdaddr =%" PRIx64 " bpid =%d meta =%d"
1225 " off =%d, len =%d\n",
1226 DPAA2_GET_FD_ADDR(fd),
1227 DPAA2_GET_FD_BPID(fd),
1228 rte_dpaa2_bpid_info[bpid].meta_data_size,
1229 DPAA2_GET_FD_OFFSET(fd),
1230 DPAA2_GET_FD_LEN(fd));
1235 build_cipher_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
1236 struct qbman_fd *fd, uint16_t bpid)
1238 struct rte_crypto_sym_op *sym_op = op->sym;
1239 struct qbman_fle *fle, *sge;
1240 int retval, data_len, data_offset;
1241 struct sec_flow_context *flc;
1242 struct ctxt_priv *priv = sess->ctxt;
1243 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1245 struct rte_mbuf *dst;
1247 data_len = sym_op->cipher.data.length;
1248 data_offset = sym_op->cipher.data.offset;
1250 if (sess->cipher_alg == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
1251 sess->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
1252 if ((data_len & 7) || (data_offset & 7)) {
1253 DPAA2_SEC_ERR("CIPHER: len/offset must be full bytes");
1257 data_len = data_len >> 3;
1258 data_offset = data_offset >> 3;
1262 dst = sym_op->m_dst;
1264 dst = sym_op->m_src;
1266 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
1268 DPAA2_SEC_ERR("CIPHER: Memory alloc failed for SGE");
1271 memset(fle, 0, FLE_POOL_BUF_SIZE);
1272 /* TODO we are using the first FLE entry to store Mbuf.
1273 * Currently we donot know which FLE has the mbuf stored.
1274 * So while retreiving we can go back 1 FLE from the FD -ADDR
1275 * to get the MBUF Addr from the previous FLE.
1276 * We can have a better approach to use the inline Mbuf
1278 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
1279 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
1283 if (likely(bpid < MAX_BPID)) {
1284 DPAA2_SET_FD_BPID(fd, bpid);
1285 DPAA2_SET_FLE_BPID(fle, bpid);
1286 DPAA2_SET_FLE_BPID(fle + 1, bpid);
1287 DPAA2_SET_FLE_BPID(sge, bpid);
1288 DPAA2_SET_FLE_BPID(sge + 1, bpid);
1290 DPAA2_SET_FD_IVP(fd);
1291 DPAA2_SET_FLE_IVP(fle);
1292 DPAA2_SET_FLE_IVP((fle + 1));
1293 DPAA2_SET_FLE_IVP(sge);
1294 DPAA2_SET_FLE_IVP((sge + 1));
1297 flc = &priv->flc_desc[0].flc;
1298 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
1299 DPAA2_SET_FD_LEN(fd, data_len + sess->iv.length);
1300 DPAA2_SET_FD_COMPOUND_FMT(fd);
1301 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
1304 "CIPHER: cipher_off: 0x%x/length %d, ivlen=%d,"
1305 " data_off: 0x%x\n",
1309 sym_op->m_src->data_off);
1311 DPAA2_SET_FLE_ADDR(fle, DPAA2_MBUF_VADDR_TO_IOVA(dst));
1312 DPAA2_SET_FLE_OFFSET(fle, data_offset + dst->data_off);
1314 fle->length = data_len + sess->iv.length;
1317 "CIPHER: 1 - flc = %p, fle = %p FLEaddr = %x-%x, length %d\n",
1318 flc, fle, fle->addr_hi, fle->addr_lo,
1323 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
1324 fle->length = data_len + sess->iv.length;
1326 DPAA2_SET_FLE_SG_EXT(fle);
1328 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
1329 sge->length = sess->iv.length;
1332 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
1333 DPAA2_SET_FLE_OFFSET(sge, data_offset + sym_op->m_src->data_off);
1335 sge->length = data_len;
1336 DPAA2_SET_FLE_FIN(sge);
1337 DPAA2_SET_FLE_FIN(fle);
1340 "CIPHER: fdaddr =%" PRIx64 " bpid =%d meta =%d"
1341 " off =%d, len =%d\n",
1342 DPAA2_GET_FD_ADDR(fd),
1343 DPAA2_GET_FD_BPID(fd),
1344 rte_dpaa2_bpid_info[bpid].meta_data_size,
1345 DPAA2_GET_FD_OFFSET(fd),
1346 DPAA2_GET_FD_LEN(fd));
1352 build_sec_fd(struct rte_crypto_op *op,
1353 struct qbman_fd *fd, uint16_t bpid)
1356 dpaa2_sec_session *sess;
1358 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION)
1359 sess = (dpaa2_sec_session *)get_sym_session_private_data(
1360 op->sym->session, cryptodev_driver_id);
1361 else if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION)
1362 sess = (dpaa2_sec_session *)get_sec_session_private_data(
1363 op->sym->sec_session);
1367 /* Any of the buffer is segmented*/
1368 if (!rte_pktmbuf_is_contiguous(op->sym->m_src) ||
1369 ((op->sym->m_dst != NULL) &&
1370 !rte_pktmbuf_is_contiguous(op->sym->m_dst))) {
1371 switch (sess->ctxt_type) {
1372 case DPAA2_SEC_CIPHER:
1373 ret = build_cipher_sg_fd(sess, op, fd, bpid);
1375 case DPAA2_SEC_AUTH:
1376 ret = build_auth_sg_fd(sess, op, fd, bpid);
1378 case DPAA2_SEC_AEAD:
1379 ret = build_authenc_gcm_sg_fd(sess, op, fd, bpid);
1381 case DPAA2_SEC_CIPHER_HASH:
1382 ret = build_authenc_sg_fd(sess, op, fd, bpid);
1384 case DPAA2_SEC_IPSEC:
1385 case DPAA2_SEC_PDCP:
1386 ret = build_proto_compound_sg_fd(sess, op, fd, bpid);
1388 case DPAA2_SEC_HASH_CIPHER:
1390 DPAA2_SEC_ERR("error: Unsupported session");
1393 switch (sess->ctxt_type) {
1394 case DPAA2_SEC_CIPHER:
1395 ret = build_cipher_fd(sess, op, fd, bpid);
1397 case DPAA2_SEC_AUTH:
1398 ret = build_auth_fd(sess, op, fd, bpid);
1400 case DPAA2_SEC_AEAD:
1401 ret = build_authenc_gcm_fd(sess, op, fd, bpid);
1403 case DPAA2_SEC_CIPHER_HASH:
1404 ret = build_authenc_fd(sess, op, fd, bpid);
1406 case DPAA2_SEC_IPSEC:
1407 ret = build_proto_fd(sess, op, fd, bpid);
1409 case DPAA2_SEC_PDCP:
1410 ret = build_proto_compound_fd(sess, op, fd, bpid);
1412 case DPAA2_SEC_HASH_CIPHER:
1414 DPAA2_SEC_ERR("error: Unsupported session");
1421 dpaa2_sec_enqueue_burst(void *qp, struct rte_crypto_op **ops,
1424 /* Function to transmit the frames to given device and VQ*/
1427 struct qbman_fd fd_arr[MAX_TX_RING_SLOTS];
1428 uint32_t frames_to_send;
1429 struct qbman_eq_desc eqdesc;
1430 struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
1431 struct qbman_swp *swp;
1432 uint16_t num_tx = 0;
1433 uint32_t flags[MAX_TX_RING_SLOTS] = {0};
1434 /*todo - need to support multiple buffer pools */
1436 struct rte_mempool *mb_pool;
1438 if (unlikely(nb_ops == 0))
1441 if (ops[0]->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
1442 DPAA2_SEC_ERR("sessionless crypto op not supported");
1445 /*Prepare enqueue descriptor*/
1446 qbman_eq_desc_clear(&eqdesc);
1447 qbman_eq_desc_set_no_orp(&eqdesc, DPAA2_EQ_RESP_ERR_FQ);
1448 qbman_eq_desc_set_response(&eqdesc, 0, 0);
1449 qbman_eq_desc_set_fq(&eqdesc, dpaa2_qp->tx_vq.fqid);
1451 if (!DPAA2_PER_LCORE_DPIO) {
1452 ret = dpaa2_affine_qbman_swp();
1454 DPAA2_SEC_ERR("Failure in affining portal");
1458 swp = DPAA2_PER_LCORE_PORTAL;
1461 frames_to_send = (nb_ops > dpaa2_eqcr_size) ?
1462 dpaa2_eqcr_size : nb_ops;
1464 for (loop = 0; loop < frames_to_send; loop++) {
1465 if ((*ops)->sym->m_src->seqn) {
1466 uint8_t dqrr_index = (*ops)->sym->m_src->seqn - 1;
1468 flags[loop] = QBMAN_ENQUEUE_FLAG_DCA | dqrr_index;
1469 DPAA2_PER_LCORE_DQRR_SIZE--;
1470 DPAA2_PER_LCORE_DQRR_HELD &= ~(1 << dqrr_index);
1471 (*ops)->sym->m_src->seqn = DPAA2_INVALID_MBUF_SEQN;
1474 /*Clear the unused FD fields before sending*/
1475 memset(&fd_arr[loop], 0, sizeof(struct qbman_fd));
1476 mb_pool = (*ops)->sym->m_src->pool;
1477 bpid = mempool_to_bpid(mb_pool);
1478 ret = build_sec_fd(*ops, &fd_arr[loop], bpid);
1480 DPAA2_SEC_ERR("error: Improper packet contents"
1481 " for crypto operation");
1487 while (loop < frames_to_send) {
1488 loop += qbman_swp_enqueue_multiple(swp, &eqdesc,
1491 frames_to_send - loop);
1494 num_tx += frames_to_send;
1495 nb_ops -= frames_to_send;
1498 dpaa2_qp->tx_vq.tx_pkts += num_tx;
1499 dpaa2_qp->tx_vq.err_pkts += nb_ops;
1503 static inline struct rte_crypto_op *
1504 sec_simple_fd_to_mbuf(const struct qbman_fd *fd)
1506 struct rte_crypto_op *op;
1507 uint16_t len = DPAA2_GET_FD_LEN(fd);
1509 dpaa2_sec_session *sess_priv;
1511 struct rte_mbuf *mbuf = DPAA2_INLINE_MBUF_FROM_BUF(
1512 DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd)),
1513 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size);
1515 diff = len - mbuf->pkt_len;
1516 mbuf->pkt_len += diff;
1517 mbuf->data_len += diff;
1518 op = (struct rte_crypto_op *)(size_t)mbuf->buf_iova;
1519 mbuf->buf_iova = op->sym->aead.digest.phys_addr;
1520 op->sym->aead.digest.phys_addr = 0L;
1522 sess_priv = (dpaa2_sec_session *)get_sec_session_private_data(
1523 op->sym->sec_session);
1524 if (sess_priv->dir == DIR_ENC)
1525 mbuf->data_off += SEC_FLC_DHR_OUTBOUND;
1527 mbuf->data_off += SEC_FLC_DHR_INBOUND;
1532 static inline struct rte_crypto_op *
1533 sec_fd_to_mbuf(const struct qbman_fd *fd)
1535 struct qbman_fle *fle;
1536 struct rte_crypto_op *op;
1537 struct ctxt_priv *priv;
1538 struct rte_mbuf *dst, *src;
1540 if (DPAA2_FD_GET_FORMAT(fd) == qbman_fd_single)
1541 return sec_simple_fd_to_mbuf(fd);
1543 fle = (struct qbman_fle *)DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd));
1545 DPAA2_SEC_DP_DEBUG("FLE addr = %x - %x, offset = %x\n",
1546 fle->addr_hi, fle->addr_lo, fle->fin_bpid_offset);
1548 /* we are using the first FLE entry to store Mbuf.
1549 * Currently we donot know which FLE has the mbuf stored.
1550 * So while retreiving we can go back 1 FLE from the FD -ADDR
1551 * to get the MBUF Addr from the previous FLE.
1552 * We can have a better approach to use the inline Mbuf
1555 if (unlikely(DPAA2_GET_FD_IVP(fd))) {
1556 /* TODO complete it. */
1557 DPAA2_SEC_ERR("error: non inline buffer");
1560 op = (struct rte_crypto_op *)DPAA2_GET_FLE_ADDR((fle - 1));
1563 src = op->sym->m_src;
1566 if (op->sym->m_dst) {
1567 dst = op->sym->m_dst;
1572 if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
1573 dpaa2_sec_session *sess = (dpaa2_sec_session *)
1574 get_sec_session_private_data(op->sym->sec_session);
1575 if (sess->ctxt_type == DPAA2_SEC_IPSEC ||
1576 sess->ctxt_type == DPAA2_SEC_PDCP) {
1577 uint16_t len = DPAA2_GET_FD_LEN(fd);
1579 while (dst->next != NULL) {
1580 len -= dst->data_len;
1583 dst->data_len = len;
1587 DPAA2_SEC_DP_DEBUG("mbuf %p BMAN buf addr %p,"
1588 " fdaddr =%" PRIx64 " bpid =%d meta =%d off =%d, len =%d\n",
1591 DPAA2_GET_FD_ADDR(fd),
1592 DPAA2_GET_FD_BPID(fd),
1593 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size,
1594 DPAA2_GET_FD_OFFSET(fd),
1595 DPAA2_GET_FD_LEN(fd));
1597 /* free the fle memory */
1598 if (likely(rte_pktmbuf_is_contiguous(src))) {
1599 priv = (struct ctxt_priv *)(size_t)DPAA2_GET_FLE_CTXT(fle - 1);
1600 rte_mempool_put(priv->fle_pool, (void *)(fle-1));
1602 rte_free((void *)(fle-1));
1608 dpaa2_sec_dequeue_burst(void *qp, struct rte_crypto_op **ops,
1611 /* Function is responsible to receive frames for a given device and VQ*/
1612 struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
1613 struct qbman_result *dq_storage;
1614 uint32_t fqid = dpaa2_qp->rx_vq.fqid;
1615 int ret, num_rx = 0;
1616 uint8_t is_last = 0, status;
1617 struct qbman_swp *swp;
1618 const struct qbman_fd *fd;
1619 struct qbman_pull_desc pulldesc;
1621 if (!DPAA2_PER_LCORE_DPIO) {
1622 ret = dpaa2_affine_qbman_swp();
1624 DPAA2_SEC_ERR("Failure in affining portal");
1628 swp = DPAA2_PER_LCORE_PORTAL;
1629 dq_storage = dpaa2_qp->rx_vq.q_storage->dq_storage[0];
1631 qbman_pull_desc_clear(&pulldesc);
1632 qbman_pull_desc_set_numframes(&pulldesc,
1633 (nb_ops > dpaa2_dqrr_size) ?
1634 dpaa2_dqrr_size : nb_ops);
1635 qbman_pull_desc_set_fq(&pulldesc, fqid);
1636 qbman_pull_desc_set_storage(&pulldesc, dq_storage,
1637 (dma_addr_t)DPAA2_VADDR_TO_IOVA(dq_storage),
1640 /*Issue a volatile dequeue command. */
1642 if (qbman_swp_pull(swp, &pulldesc)) {
1644 "SEC VDQ command is not issued : QBMAN busy");
1645 /* Portal was busy, try again */
1651 /* Receive the packets till Last Dequeue entry is found with
1652 * respect to the above issues PULL command.
1655 /* Check if the previous issued command is completed.
1656 * Also seems like the SWP is shared between the Ethernet Driver
1657 * and the SEC driver.
1659 while (!qbman_check_command_complete(dq_storage))
1662 /* Loop until the dq_storage is updated with
1663 * new token by QBMAN
1665 while (!qbman_check_new_result(dq_storage))
1667 /* Check whether Last Pull command is Expired and
1668 * setting Condition for Loop termination
1670 if (qbman_result_DQ_is_pull_complete(dq_storage)) {
1672 /* Check for valid frame. */
1673 status = (uint8_t)qbman_result_DQ_flags(dq_storage);
1675 (status & QBMAN_DQ_STAT_VALIDFRAME) == 0)) {
1676 DPAA2_SEC_DP_DEBUG("No frame is delivered\n");
1681 fd = qbman_result_DQ_fd(dq_storage);
1682 ops[num_rx] = sec_fd_to_mbuf(fd);
1684 if (unlikely(fd->simple.frc)) {
1685 /* TODO Parse SEC errors */
1686 DPAA2_SEC_ERR("SEC returned Error - %x",
1688 ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_ERROR;
1690 ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
1695 } /* End of Packet Rx loop */
1697 dpaa2_qp->rx_vq.rx_pkts += num_rx;
1699 DPAA2_SEC_DP_DEBUG("SEC Received %d Packets\n", num_rx);
1700 /*Return the total number of packets received to DPAA2 app*/
1704 /** Release queue pair */
1706 dpaa2_sec_queue_pair_release(struct rte_cryptodev *dev, uint16_t queue_pair_id)
1708 struct dpaa2_sec_qp *qp =
1709 (struct dpaa2_sec_qp *)dev->data->queue_pairs[queue_pair_id];
1711 PMD_INIT_FUNC_TRACE();
1713 if (qp->rx_vq.q_storage) {
1714 dpaa2_free_dq_storage(qp->rx_vq.q_storage);
1715 rte_free(qp->rx_vq.q_storage);
1719 dev->data->queue_pairs[queue_pair_id] = NULL;
1724 /** Setup a queue pair */
1726 dpaa2_sec_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
1727 __rte_unused const struct rte_cryptodev_qp_conf *qp_conf,
1728 __rte_unused int socket_id)
1730 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
1731 struct dpaa2_sec_qp *qp;
1732 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
1733 struct dpseci_rx_queue_cfg cfg;
1736 PMD_INIT_FUNC_TRACE();
1738 /* If qp is already in use free ring memory and qp metadata. */
1739 if (dev->data->queue_pairs[qp_id] != NULL) {
1740 DPAA2_SEC_INFO("QP already setup");
1744 DPAA2_SEC_DEBUG("dev =%p, queue =%d, conf =%p",
1745 dev, qp_id, qp_conf);
1747 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
1749 qp = rte_malloc(NULL, sizeof(struct dpaa2_sec_qp),
1750 RTE_CACHE_LINE_SIZE);
1752 DPAA2_SEC_ERR("malloc failed for rx/tx queues");
1756 qp->rx_vq.crypto_data = dev->data;
1757 qp->tx_vq.crypto_data = dev->data;
1758 qp->rx_vq.q_storage = rte_malloc("sec dq storage",
1759 sizeof(struct queue_storage_info_t),
1760 RTE_CACHE_LINE_SIZE);
1761 if (!qp->rx_vq.q_storage) {
1762 DPAA2_SEC_ERR("malloc failed for q_storage");
1765 memset(qp->rx_vq.q_storage, 0, sizeof(struct queue_storage_info_t));
1767 if (dpaa2_alloc_dq_storage(qp->rx_vq.q_storage)) {
1768 DPAA2_SEC_ERR("Unable to allocate dequeue storage");
1772 dev->data->queue_pairs[qp_id] = qp;
1774 cfg.options = cfg.options | DPSECI_QUEUE_OPT_USER_CTX;
1775 cfg.user_ctx = (size_t)(&qp->rx_vq);
1776 retcode = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
1781 /** Return the number of allocated queue pairs */
1783 dpaa2_sec_queue_pair_count(struct rte_cryptodev *dev)
1785 PMD_INIT_FUNC_TRACE();
1787 return dev->data->nb_queue_pairs;
1790 /** Returns the size of the aesni gcm session structure */
1792 dpaa2_sec_sym_session_get_size(struct rte_cryptodev *dev __rte_unused)
1794 PMD_INIT_FUNC_TRACE();
1796 return sizeof(dpaa2_sec_session);
1800 dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
1801 struct rte_crypto_sym_xform *xform,
1802 dpaa2_sec_session *session)
1804 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
1805 struct alginfo cipherdata;
1807 struct ctxt_priv *priv;
1808 struct sec_flow_context *flc;
1810 PMD_INIT_FUNC_TRACE();
1812 /* For SEC CIPHER only one descriptor is required. */
1813 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
1814 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
1815 RTE_CACHE_LINE_SIZE);
1817 DPAA2_SEC_ERR("No Memory for priv CTXT");
1821 priv->fle_pool = dev_priv->fle_pool;
1823 flc = &priv->flc_desc[0].flc;
1825 session->cipher_key.data = rte_zmalloc(NULL, xform->cipher.key.length,
1826 RTE_CACHE_LINE_SIZE);
1827 if (session->cipher_key.data == NULL) {
1828 DPAA2_SEC_ERR("No Memory for cipher key");
1832 session->cipher_key.length = xform->cipher.key.length;
1834 memcpy(session->cipher_key.data, xform->cipher.key.data,
1835 xform->cipher.key.length);
1836 cipherdata.key = (size_t)session->cipher_key.data;
1837 cipherdata.keylen = session->cipher_key.length;
1838 cipherdata.key_enc_flags = 0;
1839 cipherdata.key_type = RTA_DATA_IMM;
1841 /* Set IV parameters */
1842 session->iv.offset = xform->cipher.iv.offset;
1843 session->iv.length = xform->cipher.iv.length;
1844 session->dir = (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
1847 switch (xform->cipher.algo) {
1848 case RTE_CRYPTO_CIPHER_AES_CBC:
1849 cipherdata.algtype = OP_ALG_ALGSEL_AES;
1850 cipherdata.algmode = OP_ALG_AAI_CBC;
1851 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
1852 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
1853 SHR_NEVER, &cipherdata, NULL,
1857 case RTE_CRYPTO_CIPHER_3DES_CBC:
1858 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
1859 cipherdata.algmode = OP_ALG_AAI_CBC;
1860 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
1861 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
1862 SHR_NEVER, &cipherdata, NULL,
1866 case RTE_CRYPTO_CIPHER_AES_CTR:
1867 cipherdata.algtype = OP_ALG_ALGSEL_AES;
1868 cipherdata.algmode = OP_ALG_AAI_CTR;
1869 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
1870 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
1871 SHR_NEVER, &cipherdata, NULL,
1875 case RTE_CRYPTO_CIPHER_3DES_CTR:
1876 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
1877 cipherdata.algmode = OP_ALG_AAI_CTR;
1878 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CTR;
1879 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
1880 SHR_NEVER, &cipherdata, NULL,
1884 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
1885 cipherdata.algtype = OP_ALG_ALGSEL_SNOW_F8;
1886 session->cipher_alg = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1887 bufsize = cnstr_shdsc_snow_f8(priv->flc_desc[0].desc, 1, 0,
1891 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
1892 cipherdata.algtype = OP_ALG_ALGSEL_ZUCE;
1893 session->cipher_alg = RTE_CRYPTO_CIPHER_ZUC_EEA3;
1894 bufsize = cnstr_shdsc_zuce(priv->flc_desc[0].desc, 1, 0,
1898 case RTE_CRYPTO_CIPHER_KASUMI_F8:
1899 case RTE_CRYPTO_CIPHER_AES_F8:
1900 case RTE_CRYPTO_CIPHER_AES_ECB:
1901 case RTE_CRYPTO_CIPHER_3DES_ECB:
1902 case RTE_CRYPTO_CIPHER_AES_XTS:
1903 case RTE_CRYPTO_CIPHER_ARC4:
1904 case RTE_CRYPTO_CIPHER_NULL:
1905 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
1906 xform->cipher.algo);
1909 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
1910 xform->cipher.algo);
1915 DPAA2_SEC_ERR("Crypto: Descriptor build failed");
1919 flc->word1_sdl = (uint8_t)bufsize;
1920 session->ctxt = priv;
1922 #ifdef CAAM_DESC_DEBUG
1924 for (i = 0; i < bufsize; i++)
1925 DPAA2_SEC_DEBUG("DESC[%d]:0x%x", i, priv->flc_desc[0].desc[i]);
1930 rte_free(session->cipher_key.data);
1936 dpaa2_sec_auth_init(struct rte_cryptodev *dev,
1937 struct rte_crypto_sym_xform *xform,
1938 dpaa2_sec_session *session)
1940 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
1941 struct alginfo authdata;
1943 struct ctxt_priv *priv;
1944 struct sec_flow_context *flc;
1946 PMD_INIT_FUNC_TRACE();
1948 /* For SEC AUTH three descriptors are required for various stages */
1949 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
1950 sizeof(struct ctxt_priv) + 3 *
1951 sizeof(struct sec_flc_desc),
1952 RTE_CACHE_LINE_SIZE);
1954 DPAA2_SEC_ERR("No Memory for priv CTXT");
1958 priv->fle_pool = dev_priv->fle_pool;
1959 flc = &priv->flc_desc[DESC_INITFINAL].flc;
1961 session->auth_key.data = rte_zmalloc(NULL, xform->auth.key.length,
1962 RTE_CACHE_LINE_SIZE);
1963 if (session->auth_key.data == NULL) {
1964 DPAA2_SEC_ERR("Unable to allocate memory for auth key");
1968 session->auth_key.length = xform->auth.key.length;
1970 memcpy(session->auth_key.data, xform->auth.key.data,
1971 xform->auth.key.length);
1972 authdata.key = (size_t)session->auth_key.data;
1973 authdata.keylen = session->auth_key.length;
1974 authdata.key_enc_flags = 0;
1975 authdata.key_type = RTA_DATA_IMM;
1977 session->digest_length = xform->auth.digest_length;
1978 session->dir = (xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE) ?
1981 switch (xform->auth.algo) {
1982 case RTE_CRYPTO_AUTH_SHA1_HMAC:
1983 authdata.algtype = OP_ALG_ALGSEL_SHA1;
1984 authdata.algmode = OP_ALG_AAI_HMAC;
1985 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
1986 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
1987 1, 0, SHR_NEVER, &authdata,
1989 session->digest_length);
1991 case RTE_CRYPTO_AUTH_MD5_HMAC:
1992 authdata.algtype = OP_ALG_ALGSEL_MD5;
1993 authdata.algmode = OP_ALG_AAI_HMAC;
1994 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
1995 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
1996 1, 0, SHR_NEVER, &authdata,
1998 session->digest_length);
2000 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2001 authdata.algtype = OP_ALG_ALGSEL_SHA256;
2002 authdata.algmode = OP_ALG_AAI_HMAC;
2003 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
2004 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2005 1, 0, SHR_NEVER, &authdata,
2007 session->digest_length);
2009 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2010 authdata.algtype = OP_ALG_ALGSEL_SHA384;
2011 authdata.algmode = OP_ALG_AAI_HMAC;
2012 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
2013 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2014 1, 0, SHR_NEVER, &authdata,
2016 session->digest_length);
2018 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2019 authdata.algtype = OP_ALG_ALGSEL_SHA512;
2020 authdata.algmode = OP_ALG_AAI_HMAC;
2021 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
2022 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2023 1, 0, SHR_NEVER, &authdata,
2025 session->digest_length);
2027 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2028 authdata.algtype = OP_ALG_ALGSEL_SHA224;
2029 authdata.algmode = OP_ALG_AAI_HMAC;
2030 session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
2031 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2032 1, 0, SHR_NEVER, &authdata,
2034 session->digest_length);
2036 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2037 authdata.algtype = OP_ALG_ALGSEL_SNOW_F9;
2038 authdata.algmode = OP_ALG_AAI_F9;
2039 session->auth_alg = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2040 session->iv.offset = xform->auth.iv.offset;
2041 session->iv.length = xform->auth.iv.length;
2042 bufsize = cnstr_shdsc_snow_f9(priv->flc_desc[DESC_INITFINAL].desc,
2045 session->digest_length);
2047 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2048 authdata.algtype = OP_ALG_ALGSEL_ZUCA;
2049 authdata.algmode = OP_ALG_AAI_F9;
2050 session->auth_alg = RTE_CRYPTO_AUTH_ZUC_EIA3;
2051 session->iv.offset = xform->auth.iv.offset;
2052 session->iv.length = xform->auth.iv.length;
2053 bufsize = cnstr_shdsc_zuca(priv->flc_desc[DESC_INITFINAL].desc,
2056 session->digest_length);
2058 case RTE_CRYPTO_AUTH_KASUMI_F9:
2059 case RTE_CRYPTO_AUTH_NULL:
2060 case RTE_CRYPTO_AUTH_SHA1:
2061 case RTE_CRYPTO_AUTH_SHA256:
2062 case RTE_CRYPTO_AUTH_SHA512:
2063 case RTE_CRYPTO_AUTH_SHA224:
2064 case RTE_CRYPTO_AUTH_SHA384:
2065 case RTE_CRYPTO_AUTH_MD5:
2066 case RTE_CRYPTO_AUTH_AES_GMAC:
2067 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2068 case RTE_CRYPTO_AUTH_AES_CMAC:
2069 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2070 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %un",
2074 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2080 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2084 flc->word1_sdl = (uint8_t)bufsize;
2085 session->ctxt = priv;
2086 #ifdef CAAM_DESC_DEBUG
2088 for (i = 0; i < bufsize; i++)
2089 DPAA2_SEC_DEBUG("DESC[%d]:0x%x",
2090 i, priv->flc_desc[DESC_INITFINAL].desc[i]);
2096 rte_free(session->auth_key.data);
2102 dpaa2_sec_aead_init(struct rte_cryptodev *dev,
2103 struct rte_crypto_sym_xform *xform,
2104 dpaa2_sec_session *session)
2106 struct dpaa2_sec_aead_ctxt *ctxt = &session->ext_params.aead_ctxt;
2107 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2108 struct alginfo aeaddata;
2110 struct ctxt_priv *priv;
2111 struct sec_flow_context *flc;
2112 struct rte_crypto_aead_xform *aead_xform = &xform->aead;
2115 PMD_INIT_FUNC_TRACE();
2117 /* Set IV parameters */
2118 session->iv.offset = aead_xform->iv.offset;
2119 session->iv.length = aead_xform->iv.length;
2120 session->ctxt_type = DPAA2_SEC_AEAD;
2122 /* For SEC AEAD only one descriptor is required */
2123 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2124 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
2125 RTE_CACHE_LINE_SIZE);
2127 DPAA2_SEC_ERR("No Memory for priv CTXT");
2131 priv->fle_pool = dev_priv->fle_pool;
2132 flc = &priv->flc_desc[0].flc;
2134 session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length,
2135 RTE_CACHE_LINE_SIZE);
2136 if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
2137 DPAA2_SEC_ERR("No Memory for aead key");
2141 memcpy(session->aead_key.data, aead_xform->key.data,
2142 aead_xform->key.length);
2144 session->digest_length = aead_xform->digest_length;
2145 session->aead_key.length = aead_xform->key.length;
2146 ctxt->auth_only_len = aead_xform->aad_length;
2148 aeaddata.key = (size_t)session->aead_key.data;
2149 aeaddata.keylen = session->aead_key.length;
2150 aeaddata.key_enc_flags = 0;
2151 aeaddata.key_type = RTA_DATA_IMM;
2153 switch (aead_xform->algo) {
2154 case RTE_CRYPTO_AEAD_AES_GCM:
2155 aeaddata.algtype = OP_ALG_ALGSEL_AES;
2156 aeaddata.algmode = OP_ALG_AAI_GCM;
2157 session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM;
2159 case RTE_CRYPTO_AEAD_AES_CCM:
2160 DPAA2_SEC_ERR("Crypto: Unsupported AEAD alg %u",
2164 DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
2168 session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
2171 priv->flc_desc[0].desc[0] = aeaddata.keylen;
2172 err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
2174 (unsigned int *)priv->flc_desc[0].desc,
2175 &priv->flc_desc[0].desc[1], 1);
2178 DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
2181 if (priv->flc_desc[0].desc[1] & 1) {
2182 aeaddata.key_type = RTA_DATA_IMM;
2184 aeaddata.key = DPAA2_VADDR_TO_IOVA(aeaddata.key);
2185 aeaddata.key_type = RTA_DATA_PTR;
2187 priv->flc_desc[0].desc[0] = 0;
2188 priv->flc_desc[0].desc[1] = 0;
2190 if (session->dir == DIR_ENC)
2191 bufsize = cnstr_shdsc_gcm_encap(
2192 priv->flc_desc[0].desc, 1, 0, SHR_NEVER,
2193 &aeaddata, session->iv.length,
2194 session->digest_length);
2196 bufsize = cnstr_shdsc_gcm_decap(
2197 priv->flc_desc[0].desc, 1, 0, SHR_NEVER,
2198 &aeaddata, session->iv.length,
2199 session->digest_length);
2201 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2205 flc->word1_sdl = (uint8_t)bufsize;
2206 session->ctxt = priv;
2207 #ifdef CAAM_DESC_DEBUG
2209 for (i = 0; i < bufsize; i++)
2210 DPAA2_SEC_DEBUG("DESC[%d]:0x%x\n",
2211 i, priv->flc_desc[0].desc[i]);
2216 rte_free(session->aead_key.data);
2223 dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
2224 struct rte_crypto_sym_xform *xform,
2225 dpaa2_sec_session *session)
2227 struct dpaa2_sec_aead_ctxt *ctxt = &session->ext_params.aead_ctxt;
2228 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2229 struct alginfo authdata, cipherdata;
2231 struct ctxt_priv *priv;
2232 struct sec_flow_context *flc;
2233 struct rte_crypto_cipher_xform *cipher_xform;
2234 struct rte_crypto_auth_xform *auth_xform;
2237 PMD_INIT_FUNC_TRACE();
2239 if (session->ext_params.aead_ctxt.auth_cipher_text) {
2240 cipher_xform = &xform->cipher;
2241 auth_xform = &xform->next->auth;
2242 session->ctxt_type =
2243 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2244 DPAA2_SEC_CIPHER_HASH : DPAA2_SEC_HASH_CIPHER;
2246 cipher_xform = &xform->next->cipher;
2247 auth_xform = &xform->auth;
2248 session->ctxt_type =
2249 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2250 DPAA2_SEC_HASH_CIPHER : DPAA2_SEC_CIPHER_HASH;
2253 /* Set IV parameters */
2254 session->iv.offset = cipher_xform->iv.offset;
2255 session->iv.length = cipher_xform->iv.length;
2257 /* For SEC AEAD only one descriptor is required */
2258 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2259 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
2260 RTE_CACHE_LINE_SIZE);
2262 DPAA2_SEC_ERR("No Memory for priv CTXT");
2266 priv->fle_pool = dev_priv->fle_pool;
2267 flc = &priv->flc_desc[0].flc;
2269 session->cipher_key.data = rte_zmalloc(NULL, cipher_xform->key.length,
2270 RTE_CACHE_LINE_SIZE);
2271 if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) {
2272 DPAA2_SEC_ERR("No Memory for cipher key");
2276 session->cipher_key.length = cipher_xform->key.length;
2277 session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length,
2278 RTE_CACHE_LINE_SIZE);
2279 if (session->auth_key.data == NULL && auth_xform->key.length > 0) {
2280 DPAA2_SEC_ERR("No Memory for auth key");
2281 rte_free(session->cipher_key.data);
2285 session->auth_key.length = auth_xform->key.length;
2286 memcpy(session->cipher_key.data, cipher_xform->key.data,
2287 cipher_xform->key.length);
2288 memcpy(session->auth_key.data, auth_xform->key.data,
2289 auth_xform->key.length);
2291 authdata.key = (size_t)session->auth_key.data;
2292 authdata.keylen = session->auth_key.length;
2293 authdata.key_enc_flags = 0;
2294 authdata.key_type = RTA_DATA_IMM;
2296 session->digest_length = auth_xform->digest_length;
2298 switch (auth_xform->algo) {
2299 case RTE_CRYPTO_AUTH_SHA1_HMAC:
2300 authdata.algtype = OP_ALG_ALGSEL_SHA1;
2301 authdata.algmode = OP_ALG_AAI_HMAC;
2302 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
2304 case RTE_CRYPTO_AUTH_MD5_HMAC:
2305 authdata.algtype = OP_ALG_ALGSEL_MD5;
2306 authdata.algmode = OP_ALG_AAI_HMAC;
2307 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
2309 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2310 authdata.algtype = OP_ALG_ALGSEL_SHA224;
2311 authdata.algmode = OP_ALG_AAI_HMAC;
2312 session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
2314 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2315 authdata.algtype = OP_ALG_ALGSEL_SHA256;
2316 authdata.algmode = OP_ALG_AAI_HMAC;
2317 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
2319 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2320 authdata.algtype = OP_ALG_ALGSEL_SHA384;
2321 authdata.algmode = OP_ALG_AAI_HMAC;
2322 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
2324 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2325 authdata.algtype = OP_ALG_ALGSEL_SHA512;
2326 authdata.algmode = OP_ALG_AAI_HMAC;
2327 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
2329 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2330 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2331 case RTE_CRYPTO_AUTH_NULL:
2332 case RTE_CRYPTO_AUTH_SHA1:
2333 case RTE_CRYPTO_AUTH_SHA256:
2334 case RTE_CRYPTO_AUTH_SHA512:
2335 case RTE_CRYPTO_AUTH_SHA224:
2336 case RTE_CRYPTO_AUTH_SHA384:
2337 case RTE_CRYPTO_AUTH_MD5:
2338 case RTE_CRYPTO_AUTH_AES_GMAC:
2339 case RTE_CRYPTO_AUTH_KASUMI_F9:
2340 case RTE_CRYPTO_AUTH_AES_CMAC:
2341 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2342 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2343 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
2347 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2351 cipherdata.key = (size_t)session->cipher_key.data;
2352 cipherdata.keylen = session->cipher_key.length;
2353 cipherdata.key_enc_flags = 0;
2354 cipherdata.key_type = RTA_DATA_IMM;
2356 switch (cipher_xform->algo) {
2357 case RTE_CRYPTO_CIPHER_AES_CBC:
2358 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2359 cipherdata.algmode = OP_ALG_AAI_CBC;
2360 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
2362 case RTE_CRYPTO_CIPHER_3DES_CBC:
2363 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
2364 cipherdata.algmode = OP_ALG_AAI_CBC;
2365 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
2367 case RTE_CRYPTO_CIPHER_AES_CTR:
2368 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2369 cipherdata.algmode = OP_ALG_AAI_CTR;
2370 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
2372 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2373 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
2374 case RTE_CRYPTO_CIPHER_NULL:
2375 case RTE_CRYPTO_CIPHER_3DES_ECB:
2376 case RTE_CRYPTO_CIPHER_AES_ECB:
2377 case RTE_CRYPTO_CIPHER_KASUMI_F8:
2378 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
2379 cipher_xform->algo);
2382 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2383 cipher_xform->algo);
2386 session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2389 priv->flc_desc[0].desc[0] = cipherdata.keylen;
2390 priv->flc_desc[0].desc[1] = authdata.keylen;
2391 err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
2393 (unsigned int *)priv->flc_desc[0].desc,
2394 &priv->flc_desc[0].desc[2], 2);
2397 DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
2400 if (priv->flc_desc[0].desc[2] & 1) {
2401 cipherdata.key_type = RTA_DATA_IMM;
2403 cipherdata.key = DPAA2_VADDR_TO_IOVA(cipherdata.key);
2404 cipherdata.key_type = RTA_DATA_PTR;
2406 if (priv->flc_desc[0].desc[2] & (1 << 1)) {
2407 authdata.key_type = RTA_DATA_IMM;
2409 authdata.key = DPAA2_VADDR_TO_IOVA(authdata.key);
2410 authdata.key_type = RTA_DATA_PTR;
2412 priv->flc_desc[0].desc[0] = 0;
2413 priv->flc_desc[0].desc[1] = 0;
2414 priv->flc_desc[0].desc[2] = 0;
2416 if (session->ctxt_type == DPAA2_SEC_CIPHER_HASH) {
2417 bufsize = cnstr_shdsc_authenc(priv->flc_desc[0].desc, 1,
2419 &cipherdata, &authdata,
2421 ctxt->auth_only_len,
2422 session->digest_length,
2425 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2429 DPAA2_SEC_ERR("Hash before cipher not supported");
2433 flc->word1_sdl = (uint8_t)bufsize;
2434 session->ctxt = priv;
2435 #ifdef CAAM_DESC_DEBUG
2437 for (i = 0; i < bufsize; i++)
2438 DPAA2_SEC_DEBUG("DESC[%d]:0x%x",
2439 i, priv->flc_desc[0].desc[i]);
2445 rte_free(session->cipher_key.data);
2446 rte_free(session->auth_key.data);
2452 dpaa2_sec_set_session_parameters(struct rte_cryptodev *dev,
2453 struct rte_crypto_sym_xform *xform, void *sess)
2455 dpaa2_sec_session *session = sess;
2458 PMD_INIT_FUNC_TRACE();
2460 if (unlikely(sess == NULL)) {
2461 DPAA2_SEC_ERR("Invalid session struct");
2465 memset(session, 0, sizeof(dpaa2_sec_session));
2466 /* Default IV length = 0 */
2467 session->iv.length = 0;
2470 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
2471 session->ctxt_type = DPAA2_SEC_CIPHER;
2472 ret = dpaa2_sec_cipher_init(dev, xform, session);
2474 /* Authentication Only */
2475 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2476 xform->next == NULL) {
2477 session->ctxt_type = DPAA2_SEC_AUTH;
2478 ret = dpaa2_sec_auth_init(dev, xform, session);
2480 /* Cipher then Authenticate */
2481 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
2482 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2483 session->ext_params.aead_ctxt.auth_cipher_text = true;
2484 ret = dpaa2_sec_aead_chain_init(dev, xform, session);
2486 /* Authenticate then Cipher */
2487 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2488 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2489 session->ext_params.aead_ctxt.auth_cipher_text = false;
2490 ret = dpaa2_sec_aead_chain_init(dev, xform, session);
2492 /* AEAD operation for AES-GCM kind of Algorithms */
2493 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD &&
2494 xform->next == NULL) {
2495 ret = dpaa2_sec_aead_init(dev, xform, session);
2498 DPAA2_SEC_ERR("Invalid crypto type");
2506 dpaa2_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
2507 dpaa2_sec_session *session,
2508 struct alginfo *aeaddata)
2510 PMD_INIT_FUNC_TRACE();
2512 session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length,
2513 RTE_CACHE_LINE_SIZE);
2514 if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
2515 DPAA2_SEC_ERR("No Memory for aead key");
2518 memcpy(session->aead_key.data, aead_xform->key.data,
2519 aead_xform->key.length);
2521 session->digest_length = aead_xform->digest_length;
2522 session->aead_key.length = aead_xform->key.length;
2524 aeaddata->key = (size_t)session->aead_key.data;
2525 aeaddata->keylen = session->aead_key.length;
2526 aeaddata->key_enc_flags = 0;
2527 aeaddata->key_type = RTA_DATA_IMM;
2529 switch (aead_xform->algo) {
2530 case RTE_CRYPTO_AEAD_AES_GCM:
2531 aeaddata->algtype = OP_ALG_ALGSEL_AES;
2532 aeaddata->algmode = OP_ALG_AAI_GCM;
2533 session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM;
2535 case RTE_CRYPTO_AEAD_AES_CCM:
2536 aeaddata->algtype = OP_ALG_ALGSEL_AES;
2537 aeaddata->algmode = OP_ALG_AAI_CCM;
2538 session->aead_alg = RTE_CRYPTO_AEAD_AES_CCM;
2541 DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
2545 session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
2552 dpaa2_sec_ipsec_proto_init(struct rte_crypto_cipher_xform *cipher_xform,
2553 struct rte_crypto_auth_xform *auth_xform,
2554 dpaa2_sec_session *session,
2555 struct alginfo *cipherdata,
2556 struct alginfo *authdata)
2559 session->cipher_key.data = rte_zmalloc(NULL,
2560 cipher_xform->key.length,
2561 RTE_CACHE_LINE_SIZE);
2562 if (session->cipher_key.data == NULL &&
2563 cipher_xform->key.length > 0) {
2564 DPAA2_SEC_ERR("No Memory for cipher key");
2568 session->cipher_key.length = cipher_xform->key.length;
2569 memcpy(session->cipher_key.data, cipher_xform->key.data,
2570 cipher_xform->key.length);
2571 session->cipher_alg = cipher_xform->algo;
2573 session->cipher_key.data = NULL;
2574 session->cipher_key.length = 0;
2575 session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
2579 session->auth_key.data = rte_zmalloc(NULL,
2580 auth_xform->key.length,
2581 RTE_CACHE_LINE_SIZE);
2582 if (session->auth_key.data == NULL &&
2583 auth_xform->key.length > 0) {
2584 DPAA2_SEC_ERR("No Memory for auth key");
2587 session->auth_key.length = auth_xform->key.length;
2588 memcpy(session->auth_key.data, auth_xform->key.data,
2589 auth_xform->key.length);
2590 session->auth_alg = auth_xform->algo;
2592 session->auth_key.data = NULL;
2593 session->auth_key.length = 0;
2594 session->auth_alg = RTE_CRYPTO_AUTH_NULL;
2597 authdata->key = (size_t)session->auth_key.data;
2598 authdata->keylen = session->auth_key.length;
2599 authdata->key_enc_flags = 0;
2600 authdata->key_type = RTA_DATA_IMM;
2601 switch (session->auth_alg) {
2602 case RTE_CRYPTO_AUTH_SHA1_HMAC:
2603 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA1_96;
2604 authdata->algmode = OP_ALG_AAI_HMAC;
2606 case RTE_CRYPTO_AUTH_MD5_HMAC:
2607 authdata->algtype = OP_PCL_IPSEC_HMAC_MD5_96;
2608 authdata->algmode = OP_ALG_AAI_HMAC;
2610 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2611 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_256_128;
2612 authdata->algmode = OP_ALG_AAI_HMAC;
2614 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2615 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_384_192;
2616 authdata->algmode = OP_ALG_AAI_HMAC;
2618 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2619 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_512_256;
2620 authdata->algmode = OP_ALG_AAI_HMAC;
2622 case RTE_CRYPTO_AUTH_AES_CMAC:
2623 authdata->algtype = OP_PCL_IPSEC_AES_CMAC_96;
2625 case RTE_CRYPTO_AUTH_NULL:
2626 authdata->algtype = OP_PCL_IPSEC_HMAC_NULL;
2628 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2629 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2630 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2631 case RTE_CRYPTO_AUTH_SHA1:
2632 case RTE_CRYPTO_AUTH_SHA256:
2633 case RTE_CRYPTO_AUTH_SHA512:
2634 case RTE_CRYPTO_AUTH_SHA224:
2635 case RTE_CRYPTO_AUTH_SHA384:
2636 case RTE_CRYPTO_AUTH_MD5:
2637 case RTE_CRYPTO_AUTH_AES_GMAC:
2638 case RTE_CRYPTO_AUTH_KASUMI_F9:
2639 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2640 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2641 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
2645 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2649 cipherdata->key = (size_t)session->cipher_key.data;
2650 cipherdata->keylen = session->cipher_key.length;
2651 cipherdata->key_enc_flags = 0;
2652 cipherdata->key_type = RTA_DATA_IMM;
2654 switch (session->cipher_alg) {
2655 case RTE_CRYPTO_CIPHER_AES_CBC:
2656 cipherdata->algtype = OP_PCL_IPSEC_AES_CBC;
2657 cipherdata->algmode = OP_ALG_AAI_CBC;
2659 case RTE_CRYPTO_CIPHER_3DES_CBC:
2660 cipherdata->algtype = OP_PCL_IPSEC_3DES;
2661 cipherdata->algmode = OP_ALG_AAI_CBC;
2663 case RTE_CRYPTO_CIPHER_AES_CTR:
2664 cipherdata->algtype = OP_PCL_IPSEC_AES_CTR;
2665 cipherdata->algmode = OP_ALG_AAI_CTR;
2667 case RTE_CRYPTO_CIPHER_NULL:
2668 cipherdata->algtype = OP_PCL_IPSEC_NULL;
2670 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2671 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
2672 case RTE_CRYPTO_CIPHER_3DES_ECB:
2673 case RTE_CRYPTO_CIPHER_AES_ECB:
2674 case RTE_CRYPTO_CIPHER_KASUMI_F8:
2675 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
2676 session->cipher_alg);
2679 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2680 session->cipher_alg);
2687 #ifdef RTE_LIBRTE_SECURITY_TEST
2688 static uint8_t aes_cbc_iv[] = {
2689 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2690 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
2694 dpaa2_sec_set_ipsec_session(struct rte_cryptodev *dev,
2695 struct rte_security_session_conf *conf,
2698 struct rte_security_ipsec_xform *ipsec_xform = &conf->ipsec;
2699 struct rte_crypto_cipher_xform *cipher_xform = NULL;
2700 struct rte_crypto_auth_xform *auth_xform = NULL;
2701 struct rte_crypto_aead_xform *aead_xform = NULL;
2702 dpaa2_sec_session *session = (dpaa2_sec_session *)sess;
2703 struct ctxt_priv *priv;
2704 struct ipsec_encap_pdb encap_pdb;
2705 struct ipsec_decap_pdb decap_pdb;
2706 struct alginfo authdata, cipherdata;
2708 struct sec_flow_context *flc;
2709 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2712 PMD_INIT_FUNC_TRACE();
2714 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2715 sizeof(struct ctxt_priv) +
2716 sizeof(struct sec_flc_desc),
2717 RTE_CACHE_LINE_SIZE);
2720 DPAA2_SEC_ERR("No memory for priv CTXT");
2724 priv->fle_pool = dev_priv->fle_pool;
2725 flc = &priv->flc_desc[0].flc;
2727 memset(session, 0, sizeof(dpaa2_sec_session));
2729 if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2730 cipher_xform = &conf->crypto_xform->cipher;
2731 if (conf->crypto_xform->next)
2732 auth_xform = &conf->crypto_xform->next->auth;
2733 ret = dpaa2_sec_ipsec_proto_init(cipher_xform, auth_xform,
2734 session, &cipherdata, &authdata);
2735 } else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2736 auth_xform = &conf->crypto_xform->auth;
2737 if (conf->crypto_xform->next)
2738 cipher_xform = &conf->crypto_xform->next->cipher;
2739 ret = dpaa2_sec_ipsec_proto_init(cipher_xform, auth_xform,
2740 session, &cipherdata, &authdata);
2741 } else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
2742 aead_xform = &conf->crypto_xform->aead;
2743 ret = dpaa2_sec_ipsec_aead_init(aead_xform,
2744 session, &cipherdata);
2746 DPAA2_SEC_ERR("XFORM not specified");
2751 DPAA2_SEC_ERR("Failed to process xform");
2755 session->ctxt_type = DPAA2_SEC_IPSEC;
2756 if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
2757 uint8_t *hdr = NULL;
2759 struct rte_ipv6_hdr ip6_hdr;
2761 flc->dhr = SEC_FLC_DHR_OUTBOUND;
2762 /* For Sec Proto only one descriptor is required. */
2763 memset(&encap_pdb, 0, sizeof(struct ipsec_encap_pdb));
2764 encap_pdb.options = (IPVERSION << PDBNH_ESP_ENCAP_SHIFT) |
2765 PDBOPTS_ESP_OIHI_PDB_INL |
2767 PDBHMO_ESP_ENCAP_DTTL |
2769 if (ipsec_xform->options.esn)
2770 encap_pdb.options |= PDBOPTS_ESP_ESN;
2771 encap_pdb.spi = ipsec_xform->spi;
2772 session->dir = DIR_ENC;
2773 if (ipsec_xform->tunnel.type ==
2774 RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
2775 encap_pdb.ip_hdr_len = sizeof(struct ip);
2776 ip4_hdr.ip_v = IPVERSION;
2778 ip4_hdr.ip_len = rte_cpu_to_be_16(sizeof(ip4_hdr));
2779 ip4_hdr.ip_tos = ipsec_xform->tunnel.ipv4.dscp;
2782 ip4_hdr.ip_ttl = ipsec_xform->tunnel.ipv4.ttl;
2783 ip4_hdr.ip_p = IPPROTO_ESP;
2785 ip4_hdr.ip_src = ipsec_xform->tunnel.ipv4.src_ip;
2786 ip4_hdr.ip_dst = ipsec_xform->tunnel.ipv4.dst_ip;
2787 ip4_hdr.ip_sum = calc_chksum((uint16_t *)(void *)
2788 &ip4_hdr, sizeof(struct ip));
2789 hdr = (uint8_t *)&ip4_hdr;
2790 } else if (ipsec_xform->tunnel.type ==
2791 RTE_SECURITY_IPSEC_TUNNEL_IPV6) {
2792 ip6_hdr.vtc_flow = rte_cpu_to_be_32(
2793 DPAA2_IPv6_DEFAULT_VTC_FLOW |
2794 ((ipsec_xform->tunnel.ipv6.dscp <<
2795 RTE_IPV6_HDR_TC_SHIFT) &
2796 RTE_IPV6_HDR_TC_MASK) |
2797 ((ipsec_xform->tunnel.ipv6.flabel <<
2798 RTE_IPV6_HDR_FL_SHIFT) &
2799 RTE_IPV6_HDR_FL_MASK));
2800 /* Payload length will be updated by HW */
2801 ip6_hdr.payload_len = 0;
2802 ip6_hdr.hop_limits =
2803 ipsec_xform->tunnel.ipv6.hlimit;
2804 ip6_hdr.proto = (ipsec_xform->proto ==
2805 RTE_SECURITY_IPSEC_SA_PROTO_ESP) ?
2806 IPPROTO_ESP : IPPROTO_AH;
2807 memcpy(&ip6_hdr.src_addr,
2808 &ipsec_xform->tunnel.ipv6.src_addr, 16);
2809 memcpy(&ip6_hdr.dst_addr,
2810 &ipsec_xform->tunnel.ipv6.dst_addr, 16);
2811 encap_pdb.ip_hdr_len = sizeof(struct rte_ipv6_hdr);
2812 hdr = (uint8_t *)&ip6_hdr;
2815 bufsize = cnstr_shdsc_ipsec_new_encap(priv->flc_desc[0].desc,
2816 1, 0, SHR_SERIAL, &encap_pdb,
2817 hdr, &cipherdata, &authdata);
2818 } else if (ipsec_xform->direction ==
2819 RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
2820 flc->dhr = SEC_FLC_DHR_INBOUND;
2821 memset(&decap_pdb, 0, sizeof(struct ipsec_decap_pdb));
2822 decap_pdb.options = sizeof(struct ip) << 16;
2823 if (ipsec_xform->options.esn)
2824 decap_pdb.options |= PDBOPTS_ESP_ESN;
2825 decap_pdb.options = (ipsec_xform->tunnel.type ==
2826 RTE_SECURITY_IPSEC_TUNNEL_IPV4) ?
2827 sizeof(struct ip) << 16 :
2828 sizeof(struct rte_ipv6_hdr) << 16;
2829 session->dir = DIR_DEC;
2830 bufsize = cnstr_shdsc_ipsec_new_decap(priv->flc_desc[0].desc,
2832 &decap_pdb, &cipherdata, &authdata);
2837 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2841 flc->word1_sdl = (uint8_t)bufsize;
2843 /* Enable the stashing control bit */
2844 DPAA2_SET_FLC_RSC(flc);
2845 flc->word2_rflc_31_0 = lower_32_bits(
2846 (size_t)&(((struct dpaa2_sec_qp *)
2847 dev->data->queue_pairs[0])->rx_vq) | 0x14);
2848 flc->word3_rflc_63_32 = upper_32_bits(
2849 (size_t)&(((struct dpaa2_sec_qp *)
2850 dev->data->queue_pairs[0])->rx_vq));
2852 /* Set EWS bit i.e. enable write-safe */
2853 DPAA2_SET_FLC_EWS(flc);
2854 /* Set BS = 1 i.e reuse input buffers as output buffers */
2855 DPAA2_SET_FLC_REUSE_BS(flc);
2856 /* Set FF = 10; reuse input buffers if they provide sufficient space */
2857 DPAA2_SET_FLC_REUSE_FF(flc);
2859 session->ctxt = priv;
2863 rte_free(session->auth_key.data);
2864 rte_free(session->cipher_key.data);
2870 dpaa2_sec_set_pdcp_session(struct rte_cryptodev *dev,
2871 struct rte_security_session_conf *conf,
2874 struct rte_security_pdcp_xform *pdcp_xform = &conf->pdcp;
2875 struct rte_crypto_sym_xform *xform = conf->crypto_xform;
2876 struct rte_crypto_auth_xform *auth_xform = NULL;
2877 struct rte_crypto_cipher_xform *cipher_xform;
2878 dpaa2_sec_session *session = (dpaa2_sec_session *)sess;
2879 struct ctxt_priv *priv;
2880 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2881 struct alginfo authdata, cipherdata;
2882 struct alginfo *p_authdata = NULL;
2884 struct sec_flow_context *flc;
2885 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
2891 PMD_INIT_FUNC_TRACE();
2893 memset(session, 0, sizeof(dpaa2_sec_session));
2895 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2896 sizeof(struct ctxt_priv) +
2897 sizeof(struct sec_flc_desc),
2898 RTE_CACHE_LINE_SIZE);
2901 DPAA2_SEC_ERR("No memory for priv CTXT");
2905 priv->fle_pool = dev_priv->fle_pool;
2906 flc = &priv->flc_desc[0].flc;
2908 /* find xfrm types */
2909 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
2910 cipher_xform = &xform->cipher;
2911 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
2912 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2913 session->ext_params.aead_ctxt.auth_cipher_text = true;
2914 cipher_xform = &xform->cipher;
2915 auth_xform = &xform->next->auth;
2916 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2917 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2918 session->ext_params.aead_ctxt.auth_cipher_text = false;
2919 cipher_xform = &xform->next->cipher;
2920 auth_xform = &xform->auth;
2922 DPAA2_SEC_ERR("Invalid crypto type");
2926 session->ctxt_type = DPAA2_SEC_PDCP;
2928 session->cipher_key.data = rte_zmalloc(NULL,
2929 cipher_xform->key.length,
2930 RTE_CACHE_LINE_SIZE);
2931 if (session->cipher_key.data == NULL &&
2932 cipher_xform->key.length > 0) {
2933 DPAA2_SEC_ERR("No Memory for cipher key");
2937 session->cipher_key.length = cipher_xform->key.length;
2938 memcpy(session->cipher_key.data, cipher_xform->key.data,
2939 cipher_xform->key.length);
2941 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2943 session->cipher_alg = cipher_xform->algo;
2945 session->cipher_key.data = NULL;
2946 session->cipher_key.length = 0;
2947 session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
2948 session->dir = DIR_ENC;
2951 session->pdcp.domain = pdcp_xform->domain;
2952 session->pdcp.bearer = pdcp_xform->bearer;
2953 session->pdcp.pkt_dir = pdcp_xform->pkt_dir;
2954 session->pdcp.sn_size = pdcp_xform->sn_size;
2955 session->pdcp.hfn = pdcp_xform->hfn;
2956 session->pdcp.hfn_threshold = pdcp_xform->hfn_threshold;
2957 session->pdcp.hfn_ovd = pdcp_xform->hfn_ovrd;
2958 /* hfv ovd offset location is stored in iv.offset value*/
2959 session->pdcp.hfn_ovd_offset = cipher_xform->iv.offset;
2961 cipherdata.key = (size_t)session->cipher_key.data;
2962 cipherdata.keylen = session->cipher_key.length;
2963 cipherdata.key_enc_flags = 0;
2964 cipherdata.key_type = RTA_DATA_IMM;
2966 switch (session->cipher_alg) {
2967 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2968 cipherdata.algtype = PDCP_CIPHER_TYPE_SNOW;
2970 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
2971 cipherdata.algtype = PDCP_CIPHER_TYPE_ZUC;
2973 case RTE_CRYPTO_CIPHER_AES_CTR:
2974 cipherdata.algtype = PDCP_CIPHER_TYPE_AES;
2976 case RTE_CRYPTO_CIPHER_NULL:
2977 cipherdata.algtype = PDCP_CIPHER_TYPE_NULL;
2980 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2981 session->cipher_alg);
2986 session->auth_key.data = rte_zmalloc(NULL,
2987 auth_xform->key.length,
2988 RTE_CACHE_LINE_SIZE);
2989 if (!session->auth_key.data &&
2990 auth_xform->key.length > 0) {
2991 DPAA2_SEC_ERR("No Memory for auth key");
2992 rte_free(session->cipher_key.data);
2996 session->auth_key.length = auth_xform->key.length;
2997 memcpy(session->auth_key.data, auth_xform->key.data,
2998 auth_xform->key.length);
2999 session->auth_alg = auth_xform->algo;
3001 session->auth_key.data = NULL;
3002 session->auth_key.length = 0;
3003 session->auth_alg = 0;
3005 authdata.key = (size_t)session->auth_key.data;
3006 authdata.keylen = session->auth_key.length;
3007 authdata.key_enc_flags = 0;
3008 authdata.key_type = RTA_DATA_IMM;
3010 if (session->auth_alg) {
3011 switch (session->auth_alg) {
3012 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
3013 authdata.algtype = PDCP_AUTH_TYPE_SNOW;
3015 case RTE_CRYPTO_AUTH_ZUC_EIA3:
3016 authdata.algtype = PDCP_AUTH_TYPE_ZUC;
3018 case RTE_CRYPTO_AUTH_AES_CMAC:
3019 authdata.algtype = PDCP_AUTH_TYPE_AES;
3021 case RTE_CRYPTO_AUTH_NULL:
3022 authdata.algtype = PDCP_AUTH_TYPE_NULL;
3025 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
3030 p_authdata = &authdata;
3031 } else if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
3032 DPAA2_SEC_ERR("Crypto: Integrity must for c-plane");
3036 if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
3037 if (session->dir == DIR_ENC)
3038 bufsize = cnstr_shdsc_pdcp_c_plane_encap(
3039 priv->flc_desc[0].desc, 1, swap,
3041 session->pdcp.sn_size,
3043 pdcp_xform->pkt_dir,
3044 pdcp_xform->hfn_threshold,
3045 &cipherdata, &authdata,
3047 else if (session->dir == DIR_DEC)
3048 bufsize = cnstr_shdsc_pdcp_c_plane_decap(
3049 priv->flc_desc[0].desc, 1, swap,
3051 session->pdcp.sn_size,
3053 pdcp_xform->pkt_dir,
3054 pdcp_xform->hfn_threshold,
3055 &cipherdata, &authdata,
3058 if (session->dir == DIR_ENC)
3059 bufsize = cnstr_shdsc_pdcp_u_plane_encap(
3060 priv->flc_desc[0].desc, 1, swap,
3061 session->pdcp.sn_size,
3064 pdcp_xform->pkt_dir,
3065 pdcp_xform->hfn_threshold,
3066 &cipherdata, p_authdata, 0);
3067 else if (session->dir == DIR_DEC)
3068 bufsize = cnstr_shdsc_pdcp_u_plane_decap(
3069 priv->flc_desc[0].desc, 1, swap,
3070 session->pdcp.sn_size,
3073 pdcp_xform->pkt_dir,
3074 pdcp_xform->hfn_threshold,
3075 &cipherdata, p_authdata, 0);
3079 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
3083 /* Enable the stashing control bit */
3084 DPAA2_SET_FLC_RSC(flc);
3085 flc->word2_rflc_31_0 = lower_32_bits(
3086 (size_t)&(((struct dpaa2_sec_qp *)
3087 dev->data->queue_pairs[0])->rx_vq) | 0x14);
3088 flc->word3_rflc_63_32 = upper_32_bits(
3089 (size_t)&(((struct dpaa2_sec_qp *)
3090 dev->data->queue_pairs[0])->rx_vq));
3092 flc->word1_sdl = (uint8_t)bufsize;
3094 /* TODO - check the perf impact or
3095 * align as per descriptor type
3096 * Set EWS bit i.e. enable write-safe
3097 * DPAA2_SET_FLC_EWS(flc);
3100 /* Set BS = 1 i.e reuse input buffers as output buffers */
3101 DPAA2_SET_FLC_REUSE_BS(flc);
3102 /* Set FF = 10; reuse input buffers if they provide sufficient space */
3103 DPAA2_SET_FLC_REUSE_FF(flc);
3105 session->ctxt = priv;
3109 rte_free(session->auth_key.data);
3110 rte_free(session->cipher_key.data);
3116 dpaa2_sec_security_session_create(void *dev,
3117 struct rte_security_session_conf *conf,
3118 struct rte_security_session *sess,
3119 struct rte_mempool *mempool)
3121 void *sess_private_data;
3122 struct rte_cryptodev *cdev = (struct rte_cryptodev *)dev;
3125 if (rte_mempool_get(mempool, &sess_private_data)) {
3126 DPAA2_SEC_ERR("Couldn't get object from session mempool");
3130 switch (conf->protocol) {
3131 case RTE_SECURITY_PROTOCOL_IPSEC:
3132 ret = dpaa2_sec_set_ipsec_session(cdev, conf,
3135 case RTE_SECURITY_PROTOCOL_MACSEC:
3137 case RTE_SECURITY_PROTOCOL_PDCP:
3138 ret = dpaa2_sec_set_pdcp_session(cdev, conf,
3145 DPAA2_SEC_ERR("Failed to configure session parameters");
3146 /* Return session to mempool */
3147 rte_mempool_put(mempool, sess_private_data);
3151 set_sec_session_private_data(sess, sess_private_data);
3156 /** Clear the memory of session so it doesn't leave key material behind */
3158 dpaa2_sec_security_session_destroy(void *dev __rte_unused,
3159 struct rte_security_session *sess)
3161 PMD_INIT_FUNC_TRACE();
3162 void *sess_priv = get_sec_session_private_data(sess);
3164 dpaa2_sec_session *s = (dpaa2_sec_session *)sess_priv;
3167 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
3170 rte_free(s->cipher_key.data);
3171 rte_free(s->auth_key.data);
3172 memset(s, 0, sizeof(dpaa2_sec_session));
3173 set_sec_session_private_data(sess, NULL);
3174 rte_mempool_put(sess_mp, sess_priv);
3180 dpaa2_sec_sym_session_configure(struct rte_cryptodev *dev,
3181 struct rte_crypto_sym_xform *xform,
3182 struct rte_cryptodev_sym_session *sess,
3183 struct rte_mempool *mempool)
3185 void *sess_private_data;
3188 if (rte_mempool_get(mempool, &sess_private_data)) {
3189 DPAA2_SEC_ERR("Couldn't get object from session mempool");
3193 ret = dpaa2_sec_set_session_parameters(dev, xform, sess_private_data);
3195 DPAA2_SEC_ERR("Failed to configure session parameters");
3196 /* Return session to mempool */
3197 rte_mempool_put(mempool, sess_private_data);
3201 set_sym_session_private_data(sess, dev->driver_id,
3207 /** Clear the memory of session so it doesn't leave key material behind */
3209 dpaa2_sec_sym_session_clear(struct rte_cryptodev *dev,
3210 struct rte_cryptodev_sym_session *sess)
3212 PMD_INIT_FUNC_TRACE();
3213 uint8_t index = dev->driver_id;
3214 void *sess_priv = get_sym_session_private_data(sess, index);
3215 dpaa2_sec_session *s = (dpaa2_sec_session *)sess_priv;
3219 rte_free(s->cipher_key.data);
3220 rte_free(s->auth_key.data);
3221 memset(s, 0, sizeof(dpaa2_sec_session));
3222 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
3223 set_sym_session_private_data(sess, index, NULL);
3224 rte_mempool_put(sess_mp, sess_priv);
3229 dpaa2_sec_dev_configure(struct rte_cryptodev *dev __rte_unused,
3230 struct rte_cryptodev_config *config __rte_unused)
3232 PMD_INIT_FUNC_TRACE();
3238 dpaa2_sec_dev_start(struct rte_cryptodev *dev)
3240 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3241 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3242 struct dpseci_attr attr;
3243 struct dpaa2_queue *dpaa2_q;
3244 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3245 dev->data->queue_pairs;
3246 struct dpseci_rx_queue_attr rx_attr;
3247 struct dpseci_tx_queue_attr tx_attr;
3250 PMD_INIT_FUNC_TRACE();
3252 memset(&attr, 0, sizeof(struct dpseci_attr));
3254 ret = dpseci_enable(dpseci, CMD_PRI_LOW, priv->token);
3256 DPAA2_SEC_ERR("DPSECI with HW_ID = %d ENABLE FAILED",
3258 goto get_attr_failure;
3260 ret = dpseci_get_attributes(dpseci, CMD_PRI_LOW, priv->token, &attr);
3262 DPAA2_SEC_ERR("DPSEC ATTRIBUTE READ FAILED, disabling DPSEC");
3263 goto get_attr_failure;
3265 for (i = 0; i < attr.num_rx_queues && qp[i]; i++) {
3266 dpaa2_q = &qp[i]->rx_vq;
3267 dpseci_get_rx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
3269 dpaa2_q->fqid = rx_attr.fqid;
3270 DPAA2_SEC_DEBUG("rx_fqid: %d", dpaa2_q->fqid);
3272 for (i = 0; i < attr.num_tx_queues && qp[i]; i++) {
3273 dpaa2_q = &qp[i]->tx_vq;
3274 dpseci_get_tx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
3276 dpaa2_q->fqid = tx_attr.fqid;
3277 DPAA2_SEC_DEBUG("tx_fqid: %d", dpaa2_q->fqid);
3282 dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
3287 dpaa2_sec_dev_stop(struct rte_cryptodev *dev)
3289 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3290 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3293 PMD_INIT_FUNC_TRACE();
3295 ret = dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
3297 DPAA2_SEC_ERR("Failure in disabling dpseci %d device",
3302 ret = dpseci_reset(dpseci, CMD_PRI_LOW, priv->token);
3304 DPAA2_SEC_ERR("SEC Device cannot be reset:Error = %0x", ret);
3310 dpaa2_sec_dev_close(struct rte_cryptodev *dev)
3312 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3313 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3316 PMD_INIT_FUNC_TRACE();
3318 /* Function is reverse of dpaa2_sec_dev_init.
3319 * It does the following:
3320 * 1. Detach a DPSECI from attached resources i.e. buffer pools, dpbp_id
3321 * 2. Close the DPSECI device
3322 * 3. Free the allocated resources.
3325 /*Close the device at underlying layer*/
3326 ret = dpseci_close(dpseci, CMD_PRI_LOW, priv->token);
3328 DPAA2_SEC_ERR("Failure closing dpseci device: err(%d)", ret);
3332 /*Free the allocated memory for ethernet private data and dpseci*/
3340 dpaa2_sec_dev_infos_get(struct rte_cryptodev *dev,
3341 struct rte_cryptodev_info *info)
3343 struct dpaa2_sec_dev_private *internals = dev->data->dev_private;
3345 PMD_INIT_FUNC_TRACE();
3347 info->max_nb_queue_pairs = internals->max_nb_queue_pairs;
3348 info->feature_flags = dev->feature_flags;
3349 info->capabilities = dpaa2_sec_capabilities;
3350 /* No limit of number of sessions */
3351 info->sym.max_nb_sessions = 0;
3352 info->driver_id = cryptodev_driver_id;
3357 void dpaa2_sec_stats_get(struct rte_cryptodev *dev,
3358 struct rte_cryptodev_stats *stats)
3360 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3361 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3362 struct dpseci_sec_counters counters = {0};
3363 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3364 dev->data->queue_pairs;
3367 PMD_INIT_FUNC_TRACE();
3368 if (stats == NULL) {
3369 DPAA2_SEC_ERR("Invalid stats ptr NULL");
3372 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
3373 if (qp[i] == NULL) {
3374 DPAA2_SEC_DEBUG("Uninitialised queue pair");
3378 stats->enqueued_count += qp[i]->tx_vq.tx_pkts;
3379 stats->dequeued_count += qp[i]->rx_vq.rx_pkts;
3380 stats->enqueue_err_count += qp[i]->tx_vq.err_pkts;
3381 stats->dequeue_err_count += qp[i]->rx_vq.err_pkts;
3384 ret = dpseci_get_sec_counters(dpseci, CMD_PRI_LOW, priv->token,
3387 DPAA2_SEC_ERR("SEC counters failed");
3389 DPAA2_SEC_INFO("dpseci hardware stats:"
3390 "\n\tNum of Requests Dequeued = %" PRIu64
3391 "\n\tNum of Outbound Encrypt Requests = %" PRIu64
3392 "\n\tNum of Inbound Decrypt Requests = %" PRIu64
3393 "\n\tNum of Outbound Bytes Encrypted = %" PRIu64
3394 "\n\tNum of Outbound Bytes Protected = %" PRIu64
3395 "\n\tNum of Inbound Bytes Decrypted = %" PRIu64
3396 "\n\tNum of Inbound Bytes Validated = %" PRIu64,
3397 counters.dequeued_requests,
3398 counters.ob_enc_requests,
3399 counters.ib_dec_requests,
3400 counters.ob_enc_bytes,
3401 counters.ob_prot_bytes,
3402 counters.ib_dec_bytes,
3403 counters.ib_valid_bytes);
3408 void dpaa2_sec_stats_reset(struct rte_cryptodev *dev)
3411 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3412 (dev->data->queue_pairs);
3414 PMD_INIT_FUNC_TRACE();
3416 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
3417 if (qp[i] == NULL) {
3418 DPAA2_SEC_DEBUG("Uninitialised queue pair");
3421 qp[i]->tx_vq.rx_pkts = 0;
3422 qp[i]->tx_vq.tx_pkts = 0;
3423 qp[i]->tx_vq.err_pkts = 0;
3424 qp[i]->rx_vq.rx_pkts = 0;
3425 qp[i]->rx_vq.tx_pkts = 0;
3426 qp[i]->rx_vq.err_pkts = 0;
3430 static void __attribute__((hot))
3431 dpaa2_sec_process_parallel_event(struct qbman_swp *swp,
3432 const struct qbman_fd *fd,
3433 const struct qbman_result *dq,
3434 struct dpaa2_queue *rxq,
3435 struct rte_event *ev)
3437 /* Prefetching mbuf */
3438 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-
3439 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size));
3441 /* Prefetching ipsec crypto_op stored in priv data of mbuf */
3442 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-64));
3444 ev->flow_id = rxq->ev.flow_id;
3445 ev->sub_event_type = rxq->ev.sub_event_type;
3446 ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
3447 ev->op = RTE_EVENT_OP_NEW;
3448 ev->sched_type = rxq->ev.sched_type;
3449 ev->queue_id = rxq->ev.queue_id;
3450 ev->priority = rxq->ev.priority;
3451 ev->event_ptr = sec_fd_to_mbuf(fd);
3453 qbman_swp_dqrr_consume(swp, dq);
3456 dpaa2_sec_process_atomic_event(struct qbman_swp *swp __attribute__((unused)),
3457 const struct qbman_fd *fd,
3458 const struct qbman_result *dq,
3459 struct dpaa2_queue *rxq,
3460 struct rte_event *ev)
3463 struct rte_crypto_op *crypto_op = (struct rte_crypto_op *)ev->event_ptr;
3464 /* Prefetching mbuf */
3465 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-
3466 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size));
3468 /* Prefetching ipsec crypto_op stored in priv data of mbuf */
3469 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-64));
3471 ev->flow_id = rxq->ev.flow_id;
3472 ev->sub_event_type = rxq->ev.sub_event_type;
3473 ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
3474 ev->op = RTE_EVENT_OP_NEW;
3475 ev->sched_type = rxq->ev.sched_type;
3476 ev->queue_id = rxq->ev.queue_id;
3477 ev->priority = rxq->ev.priority;
3479 ev->event_ptr = sec_fd_to_mbuf(fd);
3480 dqrr_index = qbman_get_dqrr_idx(dq);
3481 crypto_op->sym->m_src->seqn = dqrr_index + 1;
3482 DPAA2_PER_LCORE_DQRR_SIZE++;
3483 DPAA2_PER_LCORE_DQRR_HELD |= 1 << dqrr_index;
3484 DPAA2_PER_LCORE_DQRR_MBUF(dqrr_index) = crypto_op->sym->m_src;
3488 dpaa2_sec_eventq_attach(const struct rte_cryptodev *dev,
3490 struct dpaa2_dpcon_dev *dpcon,
3491 const struct rte_event *event)
3493 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3494 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3495 struct dpaa2_sec_qp *qp = dev->data->queue_pairs[qp_id];
3496 struct dpseci_rx_queue_cfg cfg;
3500 if (event->sched_type == RTE_SCHED_TYPE_PARALLEL)
3501 qp->rx_vq.cb = dpaa2_sec_process_parallel_event;
3502 else if (event->sched_type == RTE_SCHED_TYPE_ATOMIC)
3503 qp->rx_vq.cb = dpaa2_sec_process_atomic_event;
3507 priority = (RTE_EVENT_DEV_PRIORITY_LOWEST / event->priority) *
3508 (dpcon->num_priorities - 1);
3510 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
3511 cfg.options = DPSECI_QUEUE_OPT_DEST;
3512 cfg.dest_cfg.dest_type = DPSECI_DEST_DPCON;
3513 cfg.dest_cfg.dest_id = dpcon->dpcon_id;
3514 cfg.dest_cfg.priority = priority;
3516 cfg.options |= DPSECI_QUEUE_OPT_USER_CTX;
3517 cfg.user_ctx = (size_t)(qp);
3518 if (event->sched_type == RTE_SCHED_TYPE_ATOMIC) {
3519 cfg.options |= DPSECI_QUEUE_OPT_ORDER_PRESERVATION;
3520 cfg.order_preservation_en = 1;
3522 ret = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
3525 RTE_LOG(ERR, PMD, "Error in dpseci_set_queue: ret: %d\n", ret);
3529 memcpy(&qp->rx_vq.ev, event, sizeof(struct rte_event));
3535 dpaa2_sec_eventq_detach(const struct rte_cryptodev *dev,
3538 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3539 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3540 struct dpseci_rx_queue_cfg cfg;
3543 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
3544 cfg.options = DPSECI_QUEUE_OPT_DEST;
3545 cfg.dest_cfg.dest_type = DPSECI_DEST_NONE;
3547 ret = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
3550 RTE_LOG(ERR, PMD, "Error in dpseci_set_queue: ret: %d\n", ret);
3555 static struct rte_cryptodev_ops crypto_ops = {
3556 .dev_configure = dpaa2_sec_dev_configure,
3557 .dev_start = dpaa2_sec_dev_start,
3558 .dev_stop = dpaa2_sec_dev_stop,
3559 .dev_close = dpaa2_sec_dev_close,
3560 .dev_infos_get = dpaa2_sec_dev_infos_get,
3561 .stats_get = dpaa2_sec_stats_get,
3562 .stats_reset = dpaa2_sec_stats_reset,
3563 .queue_pair_setup = dpaa2_sec_queue_pair_setup,
3564 .queue_pair_release = dpaa2_sec_queue_pair_release,
3565 .queue_pair_count = dpaa2_sec_queue_pair_count,
3566 .sym_session_get_size = dpaa2_sec_sym_session_get_size,
3567 .sym_session_configure = dpaa2_sec_sym_session_configure,
3568 .sym_session_clear = dpaa2_sec_sym_session_clear,
3571 static const struct rte_security_capability *
3572 dpaa2_sec_capabilities_get(void *device __rte_unused)
3574 return dpaa2_sec_security_cap;
3577 static const struct rte_security_ops dpaa2_sec_security_ops = {
3578 .session_create = dpaa2_sec_security_session_create,
3579 .session_update = NULL,
3580 .session_stats_get = NULL,
3581 .session_destroy = dpaa2_sec_security_session_destroy,
3582 .set_pkt_metadata = NULL,
3583 .capabilities_get = dpaa2_sec_capabilities_get
3587 dpaa2_sec_uninit(const struct rte_cryptodev *dev)
3589 struct dpaa2_sec_dev_private *internals = dev->data->dev_private;
3591 rte_free(dev->security_ctx);
3593 rte_mempool_free(internals->fle_pool);
3595 DPAA2_SEC_INFO("Closing DPAA2_SEC device %s on numa socket %u",
3596 dev->data->name, rte_socket_id());
3602 dpaa2_sec_dev_init(struct rte_cryptodev *cryptodev)
3604 struct dpaa2_sec_dev_private *internals;
3605 struct rte_device *dev = cryptodev->device;
3606 struct rte_dpaa2_device *dpaa2_dev;
3607 struct rte_security_ctx *security_instance;
3608 struct fsl_mc_io *dpseci;
3610 struct dpseci_attr attr;
3614 PMD_INIT_FUNC_TRACE();
3615 dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
3616 if (dpaa2_dev == NULL) {
3617 DPAA2_SEC_ERR("DPAA2 SEC device not found");
3620 hw_id = dpaa2_dev->object_id;
3622 cryptodev->driver_id = cryptodev_driver_id;
3623 cryptodev->dev_ops = &crypto_ops;
3625 cryptodev->enqueue_burst = dpaa2_sec_enqueue_burst;
3626 cryptodev->dequeue_burst = dpaa2_sec_dequeue_burst;
3627 cryptodev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
3628 RTE_CRYPTODEV_FF_HW_ACCELERATED |
3629 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
3630 RTE_CRYPTODEV_FF_SECURITY |
3631 RTE_CRYPTODEV_FF_IN_PLACE_SGL |
3632 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT |
3633 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
3634 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT |
3635 RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT;
3637 internals = cryptodev->data->dev_private;
3640 * For secondary processes, we don't initialise any further as primary
3641 * has already done this work. Only check we don't need a different
3644 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
3645 DPAA2_SEC_DEBUG("Device already init by primary process");
3649 /* Initialize security_ctx only for primary process*/
3650 security_instance = rte_malloc("rte_security_instances_ops",
3651 sizeof(struct rte_security_ctx), 0);
3652 if (security_instance == NULL)
3654 security_instance->device = (void *)cryptodev;
3655 security_instance->ops = &dpaa2_sec_security_ops;
3656 security_instance->sess_cnt = 0;
3657 cryptodev->security_ctx = security_instance;
3659 /*Open the rte device via MC and save the handle for further use*/
3660 dpseci = (struct fsl_mc_io *)rte_calloc(NULL, 1,
3661 sizeof(struct fsl_mc_io), 0);
3664 "Error in allocating the memory for dpsec object");
3667 dpseci->regs = rte_mcp_ptr_list[0];
3669 retcode = dpseci_open(dpseci, CMD_PRI_LOW, hw_id, &token);
3671 DPAA2_SEC_ERR("Cannot open the dpsec device: Error = %x",
3675 retcode = dpseci_get_attributes(dpseci, CMD_PRI_LOW, token, &attr);
3678 "Cannot get dpsec device attributed: Error = %x",
3682 snprintf(cryptodev->data->name, sizeof(cryptodev->data->name),
3685 internals->max_nb_queue_pairs = attr.num_tx_queues;
3686 cryptodev->data->nb_queue_pairs = internals->max_nb_queue_pairs;
3687 internals->hw = dpseci;
3688 internals->token = token;
3690 snprintf(str, sizeof(str), "sec_fle_pool_p%d_%d",
3691 getpid(), cryptodev->data->dev_id);
3692 internals->fle_pool = rte_mempool_create((const char *)str,
3695 FLE_POOL_CACHE_SIZE, 0,
3696 NULL, NULL, NULL, NULL,
3698 if (!internals->fle_pool) {
3699 DPAA2_SEC_ERR("Mempool (%s) creation failed", str);
3703 DPAA2_SEC_INFO("driver %s: created", cryptodev->data->name);
3707 DPAA2_SEC_ERR("driver %s: create failed", cryptodev->data->name);
3709 /* dpaa2_sec_uninit(crypto_dev_name); */
3714 cryptodev_dpaa2_sec_probe(struct rte_dpaa2_driver *dpaa2_drv __rte_unused,
3715 struct rte_dpaa2_device *dpaa2_dev)
3717 struct rte_cryptodev *cryptodev;
3718 char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
3722 snprintf(cryptodev_name, sizeof(cryptodev_name), "dpsec-%d",
3723 dpaa2_dev->object_id);
3725 cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
3726 if (cryptodev == NULL)
3729 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
3730 cryptodev->data->dev_private = rte_zmalloc_socket(
3731 "cryptodev private structure",
3732 sizeof(struct dpaa2_sec_dev_private),
3733 RTE_CACHE_LINE_SIZE,
3736 if (cryptodev->data->dev_private == NULL)
3737 rte_panic("Cannot allocate memzone for private "
3741 dpaa2_dev->cryptodev = cryptodev;
3742 cryptodev->device = &dpaa2_dev->device;
3744 /* init user callbacks */
3745 TAILQ_INIT(&(cryptodev->link_intr_cbs));
3747 if (dpaa2_svr_family == SVR_LX2160A)
3748 rta_set_sec_era(RTA_SEC_ERA_10);
3750 DPAA2_SEC_INFO("2-SEC ERA is %d", rta_get_sec_era());
3752 /* Invoke PMD device initialization function */
3753 retval = dpaa2_sec_dev_init(cryptodev);
3757 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
3758 rte_free(cryptodev->data->dev_private);
3760 cryptodev->attached = RTE_CRYPTODEV_DETACHED;
3766 cryptodev_dpaa2_sec_remove(struct rte_dpaa2_device *dpaa2_dev)
3768 struct rte_cryptodev *cryptodev;
3771 cryptodev = dpaa2_dev->cryptodev;
3772 if (cryptodev == NULL)
3775 ret = dpaa2_sec_uninit(cryptodev);
3779 return rte_cryptodev_pmd_destroy(cryptodev);
3782 static struct rte_dpaa2_driver rte_dpaa2_sec_driver = {
3783 .drv_flags = RTE_DPAA2_DRV_IOVA_AS_VA,
3784 .drv_type = DPAA2_CRYPTO,
3786 .name = "DPAA2 SEC PMD"
3788 .probe = cryptodev_dpaa2_sec_probe,
3789 .remove = cryptodev_dpaa2_sec_remove,
3792 static struct cryptodev_driver dpaa2_sec_crypto_drv;
3794 RTE_PMD_REGISTER_DPAA2(CRYPTODEV_NAME_DPAA2_SEC_PMD, rte_dpaa2_sec_driver);
3795 RTE_PMD_REGISTER_CRYPTO_DRIVER(dpaa2_sec_crypto_drv,
3796 rte_dpaa2_sec_driver.driver, cryptodev_driver_id);
3798 RTE_INIT(dpaa2_sec_init_log)
3800 /* Bus level logs */
3801 dpaa2_logtype_sec = rte_log_register("pmd.crypto.dpaa2");
3802 if (dpaa2_logtype_sec >= 0)
3803 rte_log_set_level(dpaa2_logtype_sec, RTE_LOG_NOTICE);