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) :
354 sym_op->aead.data.length;
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 + sym_op->aead.data.offset);
359 sge->length = mbuf->data_len - sym_op->aead.data.offset;
365 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
366 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
367 sge->length = mbuf->data_len;
370 sge->length -= icv_len;
372 if (sess->dir == DIR_ENC) {
374 DPAA2_SET_FLE_ADDR(sge,
375 DPAA2_VADDR_TO_IOVA(sym_op->aead.digest.data));
376 sge->length = icv_len;
378 DPAA2_SET_FLE_FIN(sge);
381 mbuf = sym_op->m_src;
383 /* Configure Input FLE with Scatter/Gather Entry */
384 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
385 DPAA2_SET_FLE_SG_EXT(ip_fle);
386 DPAA2_SET_FLE_FIN(ip_fle);
387 ip_fle->length = (sess->dir == DIR_ENC) ?
388 (sym_op->aead.data.length + sess->iv.length + auth_only_len) :
389 (sym_op->aead.data.length + sess->iv.length + auth_only_len +
392 /* Configure Input SGE for Encap/Decap */
393 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(IV_ptr));
394 sge->length = sess->iv.length;
398 DPAA2_SET_FLE_ADDR(sge,
399 DPAA2_VADDR_TO_IOVA(sym_op->aead.aad.data));
400 sge->length = auth_only_len;
404 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
405 DPAA2_SET_FLE_OFFSET(sge, sym_op->aead.data.offset +
407 sge->length = mbuf->data_len - sym_op->aead.data.offset;
413 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
414 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
415 sge->length = mbuf->data_len;
419 if (sess->dir == DIR_DEC) {
421 old_icv = (uint8_t *)(sge + 1);
422 memcpy(old_icv, sym_op->aead.digest.data, icv_len);
423 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
424 sge->length = icv_len;
427 DPAA2_SET_FLE_FIN(sge);
429 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, auth_only_len);
430 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
432 DPAA2_SET_FD_LEN(fd, ip_fle->length);
438 build_authenc_gcm_fd(dpaa2_sec_session *sess,
439 struct rte_crypto_op *op,
440 struct qbman_fd *fd, uint16_t bpid)
442 struct rte_crypto_sym_op *sym_op = op->sym;
443 struct ctxt_priv *priv = sess->ctxt;
444 struct qbman_fle *fle, *sge;
445 struct sec_flow_context *flc;
446 uint32_t auth_only_len = sess->ext_params.aead_ctxt.auth_only_len;
447 int icv_len = sess->digest_length, retval;
449 struct rte_mbuf *dst;
450 uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
458 /* TODO we are using the first FLE entry to store Mbuf and session ctxt.
459 * Currently we donot know which FLE has the mbuf stored.
460 * So while retreiving we can go back 1 FLE from the FD -ADDR
461 * to get the MBUF Addr from the previous FLE.
462 * We can have a better approach to use the inline Mbuf
464 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
466 DPAA2_SEC_ERR("GCM: Memory alloc failed for SGE");
469 memset(fle, 0, FLE_POOL_BUF_SIZE);
470 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
471 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
474 if (likely(bpid < MAX_BPID)) {
475 DPAA2_SET_FD_BPID(fd, bpid);
476 DPAA2_SET_FLE_BPID(fle, bpid);
477 DPAA2_SET_FLE_BPID(fle + 1, bpid);
478 DPAA2_SET_FLE_BPID(sge, bpid);
479 DPAA2_SET_FLE_BPID(sge + 1, bpid);
480 DPAA2_SET_FLE_BPID(sge + 2, bpid);
481 DPAA2_SET_FLE_BPID(sge + 3, bpid);
483 DPAA2_SET_FD_IVP(fd);
484 DPAA2_SET_FLE_IVP(fle);
485 DPAA2_SET_FLE_IVP((fle + 1));
486 DPAA2_SET_FLE_IVP(sge);
487 DPAA2_SET_FLE_IVP((sge + 1));
488 DPAA2_SET_FLE_IVP((sge + 2));
489 DPAA2_SET_FLE_IVP((sge + 3));
492 /* Save the shared descriptor */
493 flc = &priv->flc_desc[0].flc;
494 /* Configure FD as a FRAME LIST */
495 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
496 DPAA2_SET_FD_COMPOUND_FMT(fd);
497 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
499 DPAA2_SEC_DP_DEBUG("GCM: auth_off: 0x%x/length %d, digest-len=%d\n"
500 "iv-len=%d data_off: 0x%x\n",
501 sym_op->aead.data.offset,
502 sym_op->aead.data.length,
505 sym_op->m_src->data_off);
507 /* Configure Output FLE with Scatter/Gather Entry */
508 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
510 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
511 fle->length = (sess->dir == DIR_ENC) ?
512 (sym_op->aead.data.length + icv_len) :
513 sym_op->aead.data.length;
515 DPAA2_SET_FLE_SG_EXT(fle);
517 /* Configure Output SGE for Encap/Decap */
518 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(dst));
519 DPAA2_SET_FLE_OFFSET(sge, dst->data_off + sym_op->aead.data.offset);
520 sge->length = sym_op->aead.data.length;
522 if (sess->dir == DIR_ENC) {
524 DPAA2_SET_FLE_ADDR(sge,
525 DPAA2_VADDR_TO_IOVA(sym_op->aead.digest.data));
526 sge->length = sess->digest_length;
528 DPAA2_SET_FLE_FIN(sge);
533 /* Configure Input FLE with Scatter/Gather Entry */
534 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
535 DPAA2_SET_FLE_SG_EXT(fle);
536 DPAA2_SET_FLE_FIN(fle);
537 fle->length = (sess->dir == DIR_ENC) ?
538 (sym_op->aead.data.length + sess->iv.length + auth_only_len) :
539 (sym_op->aead.data.length + sess->iv.length + auth_only_len +
540 sess->digest_length);
542 /* Configure Input SGE for Encap/Decap */
543 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(IV_ptr));
544 sge->length = sess->iv.length;
547 DPAA2_SET_FLE_ADDR(sge,
548 DPAA2_VADDR_TO_IOVA(sym_op->aead.aad.data));
549 sge->length = auth_only_len;
550 DPAA2_SET_FLE_BPID(sge, bpid);
554 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
555 DPAA2_SET_FLE_OFFSET(sge, sym_op->aead.data.offset +
556 sym_op->m_src->data_off);
557 sge->length = sym_op->aead.data.length;
558 if (sess->dir == DIR_DEC) {
560 old_icv = (uint8_t *)(sge + 1);
561 memcpy(old_icv, sym_op->aead.digest.data,
562 sess->digest_length);
563 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
564 sge->length = sess->digest_length;
566 DPAA2_SET_FLE_FIN(sge);
569 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
570 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
573 DPAA2_SET_FD_LEN(fd, fle->length);
578 build_authenc_sg_fd(dpaa2_sec_session *sess,
579 struct rte_crypto_op *op,
580 struct qbman_fd *fd, __rte_unused uint16_t bpid)
582 struct rte_crypto_sym_op *sym_op = op->sym;
583 struct ctxt_priv *priv = sess->ctxt;
584 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
585 struct sec_flow_context *flc;
586 uint16_t auth_hdr_len = sym_op->cipher.data.offset -
587 sym_op->auth.data.offset;
588 uint16_t auth_tail_len = sym_op->auth.data.length -
589 sym_op->cipher.data.length - auth_hdr_len;
590 uint32_t auth_only_len = (auth_tail_len << 16) | auth_hdr_len;
591 int icv_len = sess->digest_length;
593 struct rte_mbuf *mbuf;
594 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
598 mbuf = sym_op->m_dst;
600 mbuf = sym_op->m_src;
602 /* first FLE entry used to store mbuf and session ctxt */
603 fle = (struct qbman_fle *)rte_malloc(NULL,
604 FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
605 RTE_CACHE_LINE_SIZE);
606 if (unlikely(!fle)) {
607 DPAA2_SEC_ERR("AUTHENC SG: Memory alloc failed for SGE");
610 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
611 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
612 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
618 /* Save the shared descriptor */
619 flc = &priv->flc_desc[0].flc;
621 /* Configure FD as a FRAME LIST */
622 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
623 DPAA2_SET_FD_COMPOUND_FMT(fd);
624 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
627 "AUTHENC SG: auth_off: 0x%x/length %d, digest-len=%d\n"
628 "cipher_off: 0x%x/length %d, iv-len=%d data_off: 0x%x\n",
629 sym_op->auth.data.offset,
630 sym_op->auth.data.length,
632 sym_op->cipher.data.offset,
633 sym_op->cipher.data.length,
635 sym_op->m_src->data_off);
637 /* Configure Output FLE with Scatter/Gather Entry */
638 DPAA2_SET_FLE_SG_EXT(op_fle);
639 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
642 DPAA2_SET_FLE_INTERNAL_JD(op_fle, auth_only_len);
644 op_fle->length = (sess->dir == DIR_ENC) ?
645 (sym_op->cipher.data.length + icv_len) :
646 sym_op->cipher.data.length;
648 /* Configure Output SGE for Encap/Decap */
649 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
650 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off + sym_op->auth.data.offset);
651 sge->length = mbuf->data_len - sym_op->auth.data.offset;
657 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
658 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
659 sge->length = mbuf->data_len;
662 sge->length -= icv_len;
664 if (sess->dir == DIR_ENC) {
666 DPAA2_SET_FLE_ADDR(sge,
667 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
668 sge->length = icv_len;
670 DPAA2_SET_FLE_FIN(sge);
673 mbuf = sym_op->m_src;
675 /* Configure Input FLE with Scatter/Gather Entry */
676 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
677 DPAA2_SET_FLE_SG_EXT(ip_fle);
678 DPAA2_SET_FLE_FIN(ip_fle);
679 ip_fle->length = (sess->dir == DIR_ENC) ?
680 (sym_op->auth.data.length + sess->iv.length) :
681 (sym_op->auth.data.length + sess->iv.length +
684 /* Configure Input SGE for Encap/Decap */
685 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
686 sge->length = sess->iv.length;
689 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
690 DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset +
692 sge->length = mbuf->data_len - sym_op->auth.data.offset;
698 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
699 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
700 sge->length = mbuf->data_len;
703 sge->length -= icv_len;
705 if (sess->dir == DIR_DEC) {
707 old_icv = (uint8_t *)(sge + 1);
708 memcpy(old_icv, sym_op->auth.digest.data,
710 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
711 sge->length = icv_len;
714 DPAA2_SET_FLE_FIN(sge);
716 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, auth_only_len);
717 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
719 DPAA2_SET_FD_LEN(fd, ip_fle->length);
725 build_authenc_fd(dpaa2_sec_session *sess,
726 struct rte_crypto_op *op,
727 struct qbman_fd *fd, uint16_t bpid)
729 struct rte_crypto_sym_op *sym_op = op->sym;
730 struct ctxt_priv *priv = sess->ctxt;
731 struct qbman_fle *fle, *sge;
732 struct sec_flow_context *flc;
733 uint16_t auth_hdr_len = sym_op->cipher.data.offset -
734 sym_op->auth.data.offset;
735 uint16_t auth_tail_len = sym_op->auth.data.length -
736 sym_op->cipher.data.length - auth_hdr_len;
737 uint32_t auth_only_len = (auth_tail_len << 16) | auth_hdr_len;
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_dev_private *dev_priv = dev->data->dev_private;
2228 struct alginfo authdata, cipherdata;
2230 struct ctxt_priv *priv;
2231 struct sec_flow_context *flc;
2232 struct rte_crypto_cipher_xform *cipher_xform;
2233 struct rte_crypto_auth_xform *auth_xform;
2236 PMD_INIT_FUNC_TRACE();
2238 if (session->ext_params.aead_ctxt.auth_cipher_text) {
2239 cipher_xform = &xform->cipher;
2240 auth_xform = &xform->next->auth;
2241 session->ctxt_type =
2242 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2243 DPAA2_SEC_CIPHER_HASH : DPAA2_SEC_HASH_CIPHER;
2245 cipher_xform = &xform->next->cipher;
2246 auth_xform = &xform->auth;
2247 session->ctxt_type =
2248 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2249 DPAA2_SEC_HASH_CIPHER : DPAA2_SEC_CIPHER_HASH;
2252 /* Set IV parameters */
2253 session->iv.offset = cipher_xform->iv.offset;
2254 session->iv.length = cipher_xform->iv.length;
2256 /* For SEC AEAD only one descriptor is required */
2257 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2258 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
2259 RTE_CACHE_LINE_SIZE);
2261 DPAA2_SEC_ERR("No Memory for priv CTXT");
2265 priv->fle_pool = dev_priv->fle_pool;
2266 flc = &priv->flc_desc[0].flc;
2268 session->cipher_key.data = rte_zmalloc(NULL, cipher_xform->key.length,
2269 RTE_CACHE_LINE_SIZE);
2270 if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) {
2271 DPAA2_SEC_ERR("No Memory for cipher key");
2275 session->cipher_key.length = cipher_xform->key.length;
2276 session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length,
2277 RTE_CACHE_LINE_SIZE);
2278 if (session->auth_key.data == NULL && auth_xform->key.length > 0) {
2279 DPAA2_SEC_ERR("No Memory for auth key");
2280 rte_free(session->cipher_key.data);
2284 session->auth_key.length = auth_xform->key.length;
2285 memcpy(session->cipher_key.data, cipher_xform->key.data,
2286 cipher_xform->key.length);
2287 memcpy(session->auth_key.data, auth_xform->key.data,
2288 auth_xform->key.length);
2290 authdata.key = (size_t)session->auth_key.data;
2291 authdata.keylen = session->auth_key.length;
2292 authdata.key_enc_flags = 0;
2293 authdata.key_type = RTA_DATA_IMM;
2295 session->digest_length = auth_xform->digest_length;
2297 switch (auth_xform->algo) {
2298 case RTE_CRYPTO_AUTH_SHA1_HMAC:
2299 authdata.algtype = OP_ALG_ALGSEL_SHA1;
2300 authdata.algmode = OP_ALG_AAI_HMAC;
2301 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
2303 case RTE_CRYPTO_AUTH_MD5_HMAC:
2304 authdata.algtype = OP_ALG_ALGSEL_MD5;
2305 authdata.algmode = OP_ALG_AAI_HMAC;
2306 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
2308 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2309 authdata.algtype = OP_ALG_ALGSEL_SHA224;
2310 authdata.algmode = OP_ALG_AAI_HMAC;
2311 session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
2313 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2314 authdata.algtype = OP_ALG_ALGSEL_SHA256;
2315 authdata.algmode = OP_ALG_AAI_HMAC;
2316 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
2318 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2319 authdata.algtype = OP_ALG_ALGSEL_SHA384;
2320 authdata.algmode = OP_ALG_AAI_HMAC;
2321 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
2323 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2324 authdata.algtype = OP_ALG_ALGSEL_SHA512;
2325 authdata.algmode = OP_ALG_AAI_HMAC;
2326 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
2328 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2329 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2330 case RTE_CRYPTO_AUTH_NULL:
2331 case RTE_CRYPTO_AUTH_SHA1:
2332 case RTE_CRYPTO_AUTH_SHA256:
2333 case RTE_CRYPTO_AUTH_SHA512:
2334 case RTE_CRYPTO_AUTH_SHA224:
2335 case RTE_CRYPTO_AUTH_SHA384:
2336 case RTE_CRYPTO_AUTH_MD5:
2337 case RTE_CRYPTO_AUTH_AES_GMAC:
2338 case RTE_CRYPTO_AUTH_KASUMI_F9:
2339 case RTE_CRYPTO_AUTH_AES_CMAC:
2340 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2341 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2342 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
2346 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2350 cipherdata.key = (size_t)session->cipher_key.data;
2351 cipherdata.keylen = session->cipher_key.length;
2352 cipherdata.key_enc_flags = 0;
2353 cipherdata.key_type = RTA_DATA_IMM;
2355 switch (cipher_xform->algo) {
2356 case RTE_CRYPTO_CIPHER_AES_CBC:
2357 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2358 cipherdata.algmode = OP_ALG_AAI_CBC;
2359 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
2361 case RTE_CRYPTO_CIPHER_3DES_CBC:
2362 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
2363 cipherdata.algmode = OP_ALG_AAI_CBC;
2364 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
2366 case RTE_CRYPTO_CIPHER_AES_CTR:
2367 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2368 cipherdata.algmode = OP_ALG_AAI_CTR;
2369 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
2371 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2372 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
2373 case RTE_CRYPTO_CIPHER_NULL:
2374 case RTE_CRYPTO_CIPHER_3DES_ECB:
2375 case RTE_CRYPTO_CIPHER_AES_ECB:
2376 case RTE_CRYPTO_CIPHER_KASUMI_F8:
2377 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
2378 cipher_xform->algo);
2381 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2382 cipher_xform->algo);
2385 session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2388 priv->flc_desc[0].desc[0] = cipherdata.keylen;
2389 priv->flc_desc[0].desc[1] = authdata.keylen;
2390 err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
2392 (unsigned int *)priv->flc_desc[0].desc,
2393 &priv->flc_desc[0].desc[2], 2);
2396 DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
2399 if (priv->flc_desc[0].desc[2] & 1) {
2400 cipherdata.key_type = RTA_DATA_IMM;
2402 cipherdata.key = DPAA2_VADDR_TO_IOVA(cipherdata.key);
2403 cipherdata.key_type = RTA_DATA_PTR;
2405 if (priv->flc_desc[0].desc[2] & (1 << 1)) {
2406 authdata.key_type = RTA_DATA_IMM;
2408 authdata.key = DPAA2_VADDR_TO_IOVA(authdata.key);
2409 authdata.key_type = RTA_DATA_PTR;
2411 priv->flc_desc[0].desc[0] = 0;
2412 priv->flc_desc[0].desc[1] = 0;
2413 priv->flc_desc[0].desc[2] = 0;
2415 if (session->ctxt_type == DPAA2_SEC_CIPHER_HASH) {
2416 bufsize = cnstr_shdsc_authenc(priv->flc_desc[0].desc, 1,
2418 &cipherdata, &authdata,
2420 session->digest_length,
2423 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2427 DPAA2_SEC_ERR("Hash before cipher not supported");
2431 flc->word1_sdl = (uint8_t)bufsize;
2432 session->ctxt = priv;
2433 #ifdef CAAM_DESC_DEBUG
2435 for (i = 0; i < bufsize; i++)
2436 DPAA2_SEC_DEBUG("DESC[%d]:0x%x",
2437 i, priv->flc_desc[0].desc[i]);
2443 rte_free(session->cipher_key.data);
2444 rte_free(session->auth_key.data);
2450 dpaa2_sec_set_session_parameters(struct rte_cryptodev *dev,
2451 struct rte_crypto_sym_xform *xform, void *sess)
2453 dpaa2_sec_session *session = sess;
2456 PMD_INIT_FUNC_TRACE();
2458 if (unlikely(sess == NULL)) {
2459 DPAA2_SEC_ERR("Invalid session struct");
2463 memset(session, 0, sizeof(dpaa2_sec_session));
2464 /* Default IV length = 0 */
2465 session->iv.length = 0;
2468 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
2469 session->ctxt_type = DPAA2_SEC_CIPHER;
2470 ret = dpaa2_sec_cipher_init(dev, xform, session);
2472 /* Authentication Only */
2473 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2474 xform->next == NULL) {
2475 session->ctxt_type = DPAA2_SEC_AUTH;
2476 ret = dpaa2_sec_auth_init(dev, xform, session);
2478 /* Cipher then Authenticate */
2479 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
2480 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2481 session->ext_params.aead_ctxt.auth_cipher_text = true;
2482 ret = dpaa2_sec_aead_chain_init(dev, xform, session);
2484 /* Authenticate then Cipher */
2485 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2486 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2487 session->ext_params.aead_ctxt.auth_cipher_text = false;
2488 ret = dpaa2_sec_aead_chain_init(dev, xform, session);
2490 /* AEAD operation for AES-GCM kind of Algorithms */
2491 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD &&
2492 xform->next == NULL) {
2493 ret = dpaa2_sec_aead_init(dev, xform, session);
2496 DPAA2_SEC_ERR("Invalid crypto type");
2504 dpaa2_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
2505 dpaa2_sec_session *session,
2506 struct alginfo *aeaddata)
2508 PMD_INIT_FUNC_TRACE();
2510 session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length,
2511 RTE_CACHE_LINE_SIZE);
2512 if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
2513 DPAA2_SEC_ERR("No Memory for aead key");
2516 memcpy(session->aead_key.data, aead_xform->key.data,
2517 aead_xform->key.length);
2519 session->digest_length = aead_xform->digest_length;
2520 session->aead_key.length = aead_xform->key.length;
2522 aeaddata->key = (size_t)session->aead_key.data;
2523 aeaddata->keylen = session->aead_key.length;
2524 aeaddata->key_enc_flags = 0;
2525 aeaddata->key_type = RTA_DATA_IMM;
2527 switch (aead_xform->algo) {
2528 case RTE_CRYPTO_AEAD_AES_GCM:
2529 aeaddata->algtype = OP_ALG_ALGSEL_AES;
2530 aeaddata->algmode = OP_ALG_AAI_GCM;
2531 session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM;
2533 case RTE_CRYPTO_AEAD_AES_CCM:
2534 aeaddata->algtype = OP_ALG_ALGSEL_AES;
2535 aeaddata->algmode = OP_ALG_AAI_CCM;
2536 session->aead_alg = RTE_CRYPTO_AEAD_AES_CCM;
2539 DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
2543 session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
2550 dpaa2_sec_ipsec_proto_init(struct rte_crypto_cipher_xform *cipher_xform,
2551 struct rte_crypto_auth_xform *auth_xform,
2552 dpaa2_sec_session *session,
2553 struct alginfo *cipherdata,
2554 struct alginfo *authdata)
2557 session->cipher_key.data = rte_zmalloc(NULL,
2558 cipher_xform->key.length,
2559 RTE_CACHE_LINE_SIZE);
2560 if (session->cipher_key.data == NULL &&
2561 cipher_xform->key.length > 0) {
2562 DPAA2_SEC_ERR("No Memory for cipher key");
2566 session->cipher_key.length = cipher_xform->key.length;
2567 memcpy(session->cipher_key.data, cipher_xform->key.data,
2568 cipher_xform->key.length);
2569 session->cipher_alg = cipher_xform->algo;
2571 session->cipher_key.data = NULL;
2572 session->cipher_key.length = 0;
2573 session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
2577 session->auth_key.data = rte_zmalloc(NULL,
2578 auth_xform->key.length,
2579 RTE_CACHE_LINE_SIZE);
2580 if (session->auth_key.data == NULL &&
2581 auth_xform->key.length > 0) {
2582 DPAA2_SEC_ERR("No Memory for auth key");
2585 session->auth_key.length = auth_xform->key.length;
2586 memcpy(session->auth_key.data, auth_xform->key.data,
2587 auth_xform->key.length);
2588 session->auth_alg = auth_xform->algo;
2590 session->auth_key.data = NULL;
2591 session->auth_key.length = 0;
2592 session->auth_alg = RTE_CRYPTO_AUTH_NULL;
2595 authdata->key = (size_t)session->auth_key.data;
2596 authdata->keylen = session->auth_key.length;
2597 authdata->key_enc_flags = 0;
2598 authdata->key_type = RTA_DATA_IMM;
2599 switch (session->auth_alg) {
2600 case RTE_CRYPTO_AUTH_SHA1_HMAC:
2601 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA1_96;
2602 authdata->algmode = OP_ALG_AAI_HMAC;
2604 case RTE_CRYPTO_AUTH_MD5_HMAC:
2605 authdata->algtype = OP_PCL_IPSEC_HMAC_MD5_96;
2606 authdata->algmode = OP_ALG_AAI_HMAC;
2608 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2609 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_256_128;
2610 authdata->algmode = OP_ALG_AAI_HMAC;
2612 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2613 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_384_192;
2614 authdata->algmode = OP_ALG_AAI_HMAC;
2616 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2617 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_512_256;
2618 authdata->algmode = OP_ALG_AAI_HMAC;
2620 case RTE_CRYPTO_AUTH_AES_CMAC:
2621 authdata->algtype = OP_PCL_IPSEC_AES_CMAC_96;
2623 case RTE_CRYPTO_AUTH_NULL:
2624 authdata->algtype = OP_PCL_IPSEC_HMAC_NULL;
2626 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2627 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2628 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2629 case RTE_CRYPTO_AUTH_SHA1:
2630 case RTE_CRYPTO_AUTH_SHA256:
2631 case RTE_CRYPTO_AUTH_SHA512:
2632 case RTE_CRYPTO_AUTH_SHA224:
2633 case RTE_CRYPTO_AUTH_SHA384:
2634 case RTE_CRYPTO_AUTH_MD5:
2635 case RTE_CRYPTO_AUTH_AES_GMAC:
2636 case RTE_CRYPTO_AUTH_KASUMI_F9:
2637 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2638 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2639 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
2643 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2647 cipherdata->key = (size_t)session->cipher_key.data;
2648 cipherdata->keylen = session->cipher_key.length;
2649 cipherdata->key_enc_flags = 0;
2650 cipherdata->key_type = RTA_DATA_IMM;
2652 switch (session->cipher_alg) {
2653 case RTE_CRYPTO_CIPHER_AES_CBC:
2654 cipherdata->algtype = OP_PCL_IPSEC_AES_CBC;
2655 cipherdata->algmode = OP_ALG_AAI_CBC;
2657 case RTE_CRYPTO_CIPHER_3DES_CBC:
2658 cipherdata->algtype = OP_PCL_IPSEC_3DES;
2659 cipherdata->algmode = OP_ALG_AAI_CBC;
2661 case RTE_CRYPTO_CIPHER_AES_CTR:
2662 cipherdata->algtype = OP_PCL_IPSEC_AES_CTR;
2663 cipherdata->algmode = OP_ALG_AAI_CTR;
2665 case RTE_CRYPTO_CIPHER_NULL:
2666 cipherdata->algtype = OP_PCL_IPSEC_NULL;
2668 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2669 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
2670 case RTE_CRYPTO_CIPHER_3DES_ECB:
2671 case RTE_CRYPTO_CIPHER_AES_ECB:
2672 case RTE_CRYPTO_CIPHER_KASUMI_F8:
2673 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
2674 session->cipher_alg);
2677 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2678 session->cipher_alg);
2685 #ifdef RTE_LIBRTE_SECURITY_TEST
2686 static uint8_t aes_cbc_iv[] = {
2687 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2688 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
2692 dpaa2_sec_set_ipsec_session(struct rte_cryptodev *dev,
2693 struct rte_security_session_conf *conf,
2696 struct rte_security_ipsec_xform *ipsec_xform = &conf->ipsec;
2697 struct rte_crypto_cipher_xform *cipher_xform = NULL;
2698 struct rte_crypto_auth_xform *auth_xform = NULL;
2699 struct rte_crypto_aead_xform *aead_xform = NULL;
2700 dpaa2_sec_session *session = (dpaa2_sec_session *)sess;
2701 struct ctxt_priv *priv;
2702 struct ipsec_encap_pdb encap_pdb;
2703 struct ipsec_decap_pdb decap_pdb;
2704 struct alginfo authdata, cipherdata;
2706 struct sec_flow_context *flc;
2707 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2710 PMD_INIT_FUNC_TRACE();
2712 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2713 sizeof(struct ctxt_priv) +
2714 sizeof(struct sec_flc_desc),
2715 RTE_CACHE_LINE_SIZE);
2718 DPAA2_SEC_ERR("No memory for priv CTXT");
2722 priv->fle_pool = dev_priv->fle_pool;
2723 flc = &priv->flc_desc[0].flc;
2725 memset(session, 0, sizeof(dpaa2_sec_session));
2727 if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2728 cipher_xform = &conf->crypto_xform->cipher;
2729 if (conf->crypto_xform->next)
2730 auth_xform = &conf->crypto_xform->next->auth;
2731 ret = dpaa2_sec_ipsec_proto_init(cipher_xform, auth_xform,
2732 session, &cipherdata, &authdata);
2733 } else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2734 auth_xform = &conf->crypto_xform->auth;
2735 if (conf->crypto_xform->next)
2736 cipher_xform = &conf->crypto_xform->next->cipher;
2737 ret = dpaa2_sec_ipsec_proto_init(cipher_xform, auth_xform,
2738 session, &cipherdata, &authdata);
2739 } else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
2740 aead_xform = &conf->crypto_xform->aead;
2741 ret = dpaa2_sec_ipsec_aead_init(aead_xform,
2742 session, &cipherdata);
2744 DPAA2_SEC_ERR("XFORM not specified");
2749 DPAA2_SEC_ERR("Failed to process xform");
2753 session->ctxt_type = DPAA2_SEC_IPSEC;
2754 if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
2755 uint8_t *hdr = NULL;
2757 struct rte_ipv6_hdr ip6_hdr;
2759 flc->dhr = SEC_FLC_DHR_OUTBOUND;
2760 /* For Sec Proto only one descriptor is required. */
2761 memset(&encap_pdb, 0, sizeof(struct ipsec_encap_pdb));
2762 encap_pdb.options = (IPVERSION << PDBNH_ESP_ENCAP_SHIFT) |
2763 PDBOPTS_ESP_OIHI_PDB_INL |
2765 PDBHMO_ESP_ENCAP_DTTL |
2767 if (ipsec_xform->options.esn)
2768 encap_pdb.options |= PDBOPTS_ESP_ESN;
2769 encap_pdb.spi = ipsec_xform->spi;
2770 session->dir = DIR_ENC;
2771 if (ipsec_xform->tunnel.type ==
2772 RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
2773 encap_pdb.ip_hdr_len = sizeof(struct ip);
2774 ip4_hdr.ip_v = IPVERSION;
2776 ip4_hdr.ip_len = rte_cpu_to_be_16(sizeof(ip4_hdr));
2777 ip4_hdr.ip_tos = ipsec_xform->tunnel.ipv4.dscp;
2780 ip4_hdr.ip_ttl = ipsec_xform->tunnel.ipv4.ttl;
2781 ip4_hdr.ip_p = IPPROTO_ESP;
2783 ip4_hdr.ip_src = ipsec_xform->tunnel.ipv4.src_ip;
2784 ip4_hdr.ip_dst = ipsec_xform->tunnel.ipv4.dst_ip;
2785 ip4_hdr.ip_sum = calc_chksum((uint16_t *)(void *)
2786 &ip4_hdr, sizeof(struct ip));
2787 hdr = (uint8_t *)&ip4_hdr;
2788 } else if (ipsec_xform->tunnel.type ==
2789 RTE_SECURITY_IPSEC_TUNNEL_IPV6) {
2790 ip6_hdr.vtc_flow = rte_cpu_to_be_32(
2791 DPAA2_IPv6_DEFAULT_VTC_FLOW |
2792 ((ipsec_xform->tunnel.ipv6.dscp <<
2793 RTE_IPV6_HDR_TC_SHIFT) &
2794 RTE_IPV6_HDR_TC_MASK) |
2795 ((ipsec_xform->tunnel.ipv6.flabel <<
2796 RTE_IPV6_HDR_FL_SHIFT) &
2797 RTE_IPV6_HDR_FL_MASK));
2798 /* Payload length will be updated by HW */
2799 ip6_hdr.payload_len = 0;
2800 ip6_hdr.hop_limits =
2801 ipsec_xform->tunnel.ipv6.hlimit;
2802 ip6_hdr.proto = (ipsec_xform->proto ==
2803 RTE_SECURITY_IPSEC_SA_PROTO_ESP) ?
2804 IPPROTO_ESP : IPPROTO_AH;
2805 memcpy(&ip6_hdr.src_addr,
2806 &ipsec_xform->tunnel.ipv6.src_addr, 16);
2807 memcpy(&ip6_hdr.dst_addr,
2808 &ipsec_xform->tunnel.ipv6.dst_addr, 16);
2809 encap_pdb.ip_hdr_len = sizeof(struct rte_ipv6_hdr);
2810 hdr = (uint8_t *)&ip6_hdr;
2813 bufsize = cnstr_shdsc_ipsec_new_encap(priv->flc_desc[0].desc,
2814 1, 0, SHR_SERIAL, &encap_pdb,
2815 hdr, &cipherdata, &authdata);
2816 } else if (ipsec_xform->direction ==
2817 RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
2818 flc->dhr = SEC_FLC_DHR_INBOUND;
2819 memset(&decap_pdb, 0, sizeof(struct ipsec_decap_pdb));
2820 decap_pdb.options = (ipsec_xform->tunnel.type ==
2821 RTE_SECURITY_IPSEC_TUNNEL_IPV4) ?
2822 sizeof(struct ip) << 16 :
2823 sizeof(struct rte_ipv6_hdr) << 16;
2824 if (ipsec_xform->options.esn)
2825 decap_pdb.options |= PDBOPTS_ESP_ESN;
2826 session->dir = DIR_DEC;
2827 bufsize = cnstr_shdsc_ipsec_new_decap(priv->flc_desc[0].desc,
2829 &decap_pdb, &cipherdata, &authdata);
2834 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2838 flc->word1_sdl = (uint8_t)bufsize;
2840 /* Enable the stashing control bit */
2841 DPAA2_SET_FLC_RSC(flc);
2842 flc->word2_rflc_31_0 = lower_32_bits(
2843 (size_t)&(((struct dpaa2_sec_qp *)
2844 dev->data->queue_pairs[0])->rx_vq) | 0x14);
2845 flc->word3_rflc_63_32 = upper_32_bits(
2846 (size_t)&(((struct dpaa2_sec_qp *)
2847 dev->data->queue_pairs[0])->rx_vq));
2849 /* Set EWS bit i.e. enable write-safe */
2850 DPAA2_SET_FLC_EWS(flc);
2851 /* Set BS = 1 i.e reuse input buffers as output buffers */
2852 DPAA2_SET_FLC_REUSE_BS(flc);
2853 /* Set FF = 10; reuse input buffers if they provide sufficient space */
2854 DPAA2_SET_FLC_REUSE_FF(flc);
2856 session->ctxt = priv;
2860 rte_free(session->auth_key.data);
2861 rte_free(session->cipher_key.data);
2867 dpaa2_sec_set_pdcp_session(struct rte_cryptodev *dev,
2868 struct rte_security_session_conf *conf,
2871 struct rte_security_pdcp_xform *pdcp_xform = &conf->pdcp;
2872 struct rte_crypto_sym_xform *xform = conf->crypto_xform;
2873 struct rte_crypto_auth_xform *auth_xform = NULL;
2874 struct rte_crypto_cipher_xform *cipher_xform;
2875 dpaa2_sec_session *session = (dpaa2_sec_session *)sess;
2876 struct ctxt_priv *priv;
2877 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2878 struct alginfo authdata, cipherdata;
2879 struct alginfo *p_authdata = NULL;
2881 struct sec_flow_context *flc;
2882 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
2888 PMD_INIT_FUNC_TRACE();
2890 memset(session, 0, sizeof(dpaa2_sec_session));
2892 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2893 sizeof(struct ctxt_priv) +
2894 sizeof(struct sec_flc_desc),
2895 RTE_CACHE_LINE_SIZE);
2898 DPAA2_SEC_ERR("No memory for priv CTXT");
2902 priv->fle_pool = dev_priv->fle_pool;
2903 flc = &priv->flc_desc[0].flc;
2905 /* find xfrm types */
2906 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
2907 cipher_xform = &xform->cipher;
2908 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
2909 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2910 session->ext_params.aead_ctxt.auth_cipher_text = true;
2911 cipher_xform = &xform->cipher;
2912 auth_xform = &xform->next->auth;
2913 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2914 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2915 session->ext_params.aead_ctxt.auth_cipher_text = false;
2916 cipher_xform = &xform->next->cipher;
2917 auth_xform = &xform->auth;
2919 DPAA2_SEC_ERR("Invalid crypto type");
2923 session->ctxt_type = DPAA2_SEC_PDCP;
2925 session->cipher_key.data = rte_zmalloc(NULL,
2926 cipher_xform->key.length,
2927 RTE_CACHE_LINE_SIZE);
2928 if (session->cipher_key.data == NULL &&
2929 cipher_xform->key.length > 0) {
2930 DPAA2_SEC_ERR("No Memory for cipher key");
2934 session->cipher_key.length = cipher_xform->key.length;
2935 memcpy(session->cipher_key.data, cipher_xform->key.data,
2936 cipher_xform->key.length);
2938 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2940 session->cipher_alg = cipher_xform->algo;
2942 session->cipher_key.data = NULL;
2943 session->cipher_key.length = 0;
2944 session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
2945 session->dir = DIR_ENC;
2948 session->pdcp.domain = pdcp_xform->domain;
2949 session->pdcp.bearer = pdcp_xform->bearer;
2950 session->pdcp.pkt_dir = pdcp_xform->pkt_dir;
2951 session->pdcp.sn_size = pdcp_xform->sn_size;
2952 session->pdcp.hfn = pdcp_xform->hfn;
2953 session->pdcp.hfn_threshold = pdcp_xform->hfn_threshold;
2954 session->pdcp.hfn_ovd = pdcp_xform->hfn_ovrd;
2955 /* hfv ovd offset location is stored in iv.offset value*/
2956 session->pdcp.hfn_ovd_offset = cipher_xform->iv.offset;
2958 cipherdata.key = (size_t)session->cipher_key.data;
2959 cipherdata.keylen = session->cipher_key.length;
2960 cipherdata.key_enc_flags = 0;
2961 cipherdata.key_type = RTA_DATA_IMM;
2963 switch (session->cipher_alg) {
2964 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2965 cipherdata.algtype = PDCP_CIPHER_TYPE_SNOW;
2967 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
2968 cipherdata.algtype = PDCP_CIPHER_TYPE_ZUC;
2970 case RTE_CRYPTO_CIPHER_AES_CTR:
2971 cipherdata.algtype = PDCP_CIPHER_TYPE_AES;
2973 case RTE_CRYPTO_CIPHER_NULL:
2974 cipherdata.algtype = PDCP_CIPHER_TYPE_NULL;
2977 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2978 session->cipher_alg);
2983 session->auth_key.data = rte_zmalloc(NULL,
2984 auth_xform->key.length,
2985 RTE_CACHE_LINE_SIZE);
2986 if (!session->auth_key.data &&
2987 auth_xform->key.length > 0) {
2988 DPAA2_SEC_ERR("No Memory for auth key");
2989 rte_free(session->cipher_key.data);
2993 session->auth_key.length = auth_xform->key.length;
2994 memcpy(session->auth_key.data, auth_xform->key.data,
2995 auth_xform->key.length);
2996 session->auth_alg = auth_xform->algo;
2998 session->auth_key.data = NULL;
2999 session->auth_key.length = 0;
3000 session->auth_alg = 0;
3002 authdata.key = (size_t)session->auth_key.data;
3003 authdata.keylen = session->auth_key.length;
3004 authdata.key_enc_flags = 0;
3005 authdata.key_type = RTA_DATA_IMM;
3007 if (session->auth_alg) {
3008 switch (session->auth_alg) {
3009 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
3010 authdata.algtype = PDCP_AUTH_TYPE_SNOW;
3012 case RTE_CRYPTO_AUTH_ZUC_EIA3:
3013 authdata.algtype = PDCP_AUTH_TYPE_ZUC;
3015 case RTE_CRYPTO_AUTH_AES_CMAC:
3016 authdata.algtype = PDCP_AUTH_TYPE_AES;
3018 case RTE_CRYPTO_AUTH_NULL:
3019 authdata.algtype = PDCP_AUTH_TYPE_NULL;
3022 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
3027 p_authdata = &authdata;
3028 } else if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
3029 DPAA2_SEC_ERR("Crypto: Integrity must for c-plane");
3033 if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
3034 if (session->dir == DIR_ENC)
3035 bufsize = cnstr_shdsc_pdcp_c_plane_encap(
3036 priv->flc_desc[0].desc, 1, swap,
3038 session->pdcp.sn_size,
3040 pdcp_xform->pkt_dir,
3041 pdcp_xform->hfn_threshold,
3042 &cipherdata, &authdata,
3044 else if (session->dir == DIR_DEC)
3045 bufsize = cnstr_shdsc_pdcp_c_plane_decap(
3046 priv->flc_desc[0].desc, 1, swap,
3048 session->pdcp.sn_size,
3050 pdcp_xform->pkt_dir,
3051 pdcp_xform->hfn_threshold,
3052 &cipherdata, &authdata,
3055 if (session->dir == DIR_ENC)
3056 bufsize = cnstr_shdsc_pdcp_u_plane_encap(
3057 priv->flc_desc[0].desc, 1, swap,
3058 session->pdcp.sn_size,
3061 pdcp_xform->pkt_dir,
3062 pdcp_xform->hfn_threshold,
3063 &cipherdata, p_authdata, 0);
3064 else if (session->dir == DIR_DEC)
3065 bufsize = cnstr_shdsc_pdcp_u_plane_decap(
3066 priv->flc_desc[0].desc, 1, swap,
3067 session->pdcp.sn_size,
3070 pdcp_xform->pkt_dir,
3071 pdcp_xform->hfn_threshold,
3072 &cipherdata, p_authdata, 0);
3076 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
3080 /* Enable the stashing control bit */
3081 DPAA2_SET_FLC_RSC(flc);
3082 flc->word2_rflc_31_0 = lower_32_bits(
3083 (size_t)&(((struct dpaa2_sec_qp *)
3084 dev->data->queue_pairs[0])->rx_vq) | 0x14);
3085 flc->word3_rflc_63_32 = upper_32_bits(
3086 (size_t)&(((struct dpaa2_sec_qp *)
3087 dev->data->queue_pairs[0])->rx_vq));
3089 flc->word1_sdl = (uint8_t)bufsize;
3091 /* TODO - check the perf impact or
3092 * align as per descriptor type
3093 * Set EWS bit i.e. enable write-safe
3094 * DPAA2_SET_FLC_EWS(flc);
3097 /* Set BS = 1 i.e reuse input buffers as output buffers */
3098 DPAA2_SET_FLC_REUSE_BS(flc);
3099 /* Set FF = 10; reuse input buffers if they provide sufficient space */
3100 DPAA2_SET_FLC_REUSE_FF(flc);
3102 session->ctxt = priv;
3106 rte_free(session->auth_key.data);
3107 rte_free(session->cipher_key.data);
3113 dpaa2_sec_security_session_create(void *dev,
3114 struct rte_security_session_conf *conf,
3115 struct rte_security_session *sess,
3116 struct rte_mempool *mempool)
3118 void *sess_private_data;
3119 struct rte_cryptodev *cdev = (struct rte_cryptodev *)dev;
3122 if (rte_mempool_get(mempool, &sess_private_data)) {
3123 DPAA2_SEC_ERR("Couldn't get object from session mempool");
3127 switch (conf->protocol) {
3128 case RTE_SECURITY_PROTOCOL_IPSEC:
3129 ret = dpaa2_sec_set_ipsec_session(cdev, conf,
3132 case RTE_SECURITY_PROTOCOL_MACSEC:
3134 case RTE_SECURITY_PROTOCOL_PDCP:
3135 ret = dpaa2_sec_set_pdcp_session(cdev, conf,
3142 DPAA2_SEC_ERR("Failed to configure session parameters");
3143 /* Return session to mempool */
3144 rte_mempool_put(mempool, sess_private_data);
3148 set_sec_session_private_data(sess, sess_private_data);
3153 /** Clear the memory of session so it doesn't leave key material behind */
3155 dpaa2_sec_security_session_destroy(void *dev __rte_unused,
3156 struct rte_security_session *sess)
3158 PMD_INIT_FUNC_TRACE();
3159 void *sess_priv = get_sec_session_private_data(sess);
3161 dpaa2_sec_session *s = (dpaa2_sec_session *)sess_priv;
3164 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
3167 rte_free(s->cipher_key.data);
3168 rte_free(s->auth_key.data);
3169 memset(s, 0, sizeof(dpaa2_sec_session));
3170 set_sec_session_private_data(sess, NULL);
3171 rte_mempool_put(sess_mp, sess_priv);
3177 dpaa2_sec_sym_session_configure(struct rte_cryptodev *dev,
3178 struct rte_crypto_sym_xform *xform,
3179 struct rte_cryptodev_sym_session *sess,
3180 struct rte_mempool *mempool)
3182 void *sess_private_data;
3185 if (rte_mempool_get(mempool, &sess_private_data)) {
3186 DPAA2_SEC_ERR("Couldn't get object from session mempool");
3190 ret = dpaa2_sec_set_session_parameters(dev, xform, sess_private_data);
3192 DPAA2_SEC_ERR("Failed to configure session parameters");
3193 /* Return session to mempool */
3194 rte_mempool_put(mempool, sess_private_data);
3198 set_sym_session_private_data(sess, dev->driver_id,
3204 /** Clear the memory of session so it doesn't leave key material behind */
3206 dpaa2_sec_sym_session_clear(struct rte_cryptodev *dev,
3207 struct rte_cryptodev_sym_session *sess)
3209 PMD_INIT_FUNC_TRACE();
3210 uint8_t index = dev->driver_id;
3211 void *sess_priv = get_sym_session_private_data(sess, index);
3212 dpaa2_sec_session *s = (dpaa2_sec_session *)sess_priv;
3216 rte_free(s->cipher_key.data);
3217 rte_free(s->auth_key.data);
3218 memset(s, 0, sizeof(dpaa2_sec_session));
3219 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
3220 set_sym_session_private_data(sess, index, NULL);
3221 rte_mempool_put(sess_mp, sess_priv);
3226 dpaa2_sec_dev_configure(struct rte_cryptodev *dev __rte_unused,
3227 struct rte_cryptodev_config *config __rte_unused)
3229 PMD_INIT_FUNC_TRACE();
3235 dpaa2_sec_dev_start(struct rte_cryptodev *dev)
3237 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3238 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3239 struct dpseci_attr attr;
3240 struct dpaa2_queue *dpaa2_q;
3241 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3242 dev->data->queue_pairs;
3243 struct dpseci_rx_queue_attr rx_attr;
3244 struct dpseci_tx_queue_attr tx_attr;
3247 PMD_INIT_FUNC_TRACE();
3249 memset(&attr, 0, sizeof(struct dpseci_attr));
3251 ret = dpseci_enable(dpseci, CMD_PRI_LOW, priv->token);
3253 DPAA2_SEC_ERR("DPSECI with HW_ID = %d ENABLE FAILED",
3255 goto get_attr_failure;
3257 ret = dpseci_get_attributes(dpseci, CMD_PRI_LOW, priv->token, &attr);
3259 DPAA2_SEC_ERR("DPSEC ATTRIBUTE READ FAILED, disabling DPSEC");
3260 goto get_attr_failure;
3262 for (i = 0; i < attr.num_rx_queues && qp[i]; i++) {
3263 dpaa2_q = &qp[i]->rx_vq;
3264 dpseci_get_rx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
3266 dpaa2_q->fqid = rx_attr.fqid;
3267 DPAA2_SEC_DEBUG("rx_fqid: %d", dpaa2_q->fqid);
3269 for (i = 0; i < attr.num_tx_queues && qp[i]; i++) {
3270 dpaa2_q = &qp[i]->tx_vq;
3271 dpseci_get_tx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
3273 dpaa2_q->fqid = tx_attr.fqid;
3274 DPAA2_SEC_DEBUG("tx_fqid: %d", dpaa2_q->fqid);
3279 dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
3284 dpaa2_sec_dev_stop(struct rte_cryptodev *dev)
3286 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3287 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3290 PMD_INIT_FUNC_TRACE();
3292 ret = dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
3294 DPAA2_SEC_ERR("Failure in disabling dpseci %d device",
3299 ret = dpseci_reset(dpseci, CMD_PRI_LOW, priv->token);
3301 DPAA2_SEC_ERR("SEC Device cannot be reset:Error = %0x", ret);
3307 dpaa2_sec_dev_close(struct rte_cryptodev *dev)
3309 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3310 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3313 PMD_INIT_FUNC_TRACE();
3315 /* Function is reverse of dpaa2_sec_dev_init.
3316 * It does the following:
3317 * 1. Detach a DPSECI from attached resources i.e. buffer pools, dpbp_id
3318 * 2. Close the DPSECI device
3319 * 3. Free the allocated resources.
3322 /*Close the device at underlying layer*/
3323 ret = dpseci_close(dpseci, CMD_PRI_LOW, priv->token);
3325 DPAA2_SEC_ERR("Failure closing dpseci device: err(%d)", ret);
3329 /*Free the allocated memory for ethernet private data and dpseci*/
3337 dpaa2_sec_dev_infos_get(struct rte_cryptodev *dev,
3338 struct rte_cryptodev_info *info)
3340 struct dpaa2_sec_dev_private *internals = dev->data->dev_private;
3342 PMD_INIT_FUNC_TRACE();
3344 info->max_nb_queue_pairs = internals->max_nb_queue_pairs;
3345 info->feature_flags = dev->feature_flags;
3346 info->capabilities = dpaa2_sec_capabilities;
3347 /* No limit of number of sessions */
3348 info->sym.max_nb_sessions = 0;
3349 info->driver_id = cryptodev_driver_id;
3354 void dpaa2_sec_stats_get(struct rte_cryptodev *dev,
3355 struct rte_cryptodev_stats *stats)
3357 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3358 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3359 struct dpseci_sec_counters counters = {0};
3360 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3361 dev->data->queue_pairs;
3364 PMD_INIT_FUNC_TRACE();
3365 if (stats == NULL) {
3366 DPAA2_SEC_ERR("Invalid stats ptr NULL");
3369 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
3370 if (qp[i] == NULL) {
3371 DPAA2_SEC_DEBUG("Uninitialised queue pair");
3375 stats->enqueued_count += qp[i]->tx_vq.tx_pkts;
3376 stats->dequeued_count += qp[i]->rx_vq.rx_pkts;
3377 stats->enqueue_err_count += qp[i]->tx_vq.err_pkts;
3378 stats->dequeue_err_count += qp[i]->rx_vq.err_pkts;
3381 ret = dpseci_get_sec_counters(dpseci, CMD_PRI_LOW, priv->token,
3384 DPAA2_SEC_ERR("SEC counters failed");
3386 DPAA2_SEC_INFO("dpseci hardware stats:"
3387 "\n\tNum of Requests Dequeued = %" PRIu64
3388 "\n\tNum of Outbound Encrypt Requests = %" PRIu64
3389 "\n\tNum of Inbound Decrypt Requests = %" PRIu64
3390 "\n\tNum of Outbound Bytes Encrypted = %" PRIu64
3391 "\n\tNum of Outbound Bytes Protected = %" PRIu64
3392 "\n\tNum of Inbound Bytes Decrypted = %" PRIu64
3393 "\n\tNum of Inbound Bytes Validated = %" PRIu64,
3394 counters.dequeued_requests,
3395 counters.ob_enc_requests,
3396 counters.ib_dec_requests,
3397 counters.ob_enc_bytes,
3398 counters.ob_prot_bytes,
3399 counters.ib_dec_bytes,
3400 counters.ib_valid_bytes);
3405 void dpaa2_sec_stats_reset(struct rte_cryptodev *dev)
3408 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3409 (dev->data->queue_pairs);
3411 PMD_INIT_FUNC_TRACE();
3413 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
3414 if (qp[i] == NULL) {
3415 DPAA2_SEC_DEBUG("Uninitialised queue pair");
3418 qp[i]->tx_vq.rx_pkts = 0;
3419 qp[i]->tx_vq.tx_pkts = 0;
3420 qp[i]->tx_vq.err_pkts = 0;
3421 qp[i]->rx_vq.rx_pkts = 0;
3422 qp[i]->rx_vq.tx_pkts = 0;
3423 qp[i]->rx_vq.err_pkts = 0;
3427 static void __attribute__((hot))
3428 dpaa2_sec_process_parallel_event(struct qbman_swp *swp,
3429 const struct qbman_fd *fd,
3430 const struct qbman_result *dq,
3431 struct dpaa2_queue *rxq,
3432 struct rte_event *ev)
3434 /* Prefetching mbuf */
3435 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-
3436 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size));
3438 /* Prefetching ipsec crypto_op stored in priv data of mbuf */
3439 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-64));
3441 ev->flow_id = rxq->ev.flow_id;
3442 ev->sub_event_type = rxq->ev.sub_event_type;
3443 ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
3444 ev->op = RTE_EVENT_OP_NEW;
3445 ev->sched_type = rxq->ev.sched_type;
3446 ev->queue_id = rxq->ev.queue_id;
3447 ev->priority = rxq->ev.priority;
3448 ev->event_ptr = sec_fd_to_mbuf(fd);
3450 qbman_swp_dqrr_consume(swp, dq);
3453 dpaa2_sec_process_atomic_event(struct qbman_swp *swp __attribute__((unused)),
3454 const struct qbman_fd *fd,
3455 const struct qbman_result *dq,
3456 struct dpaa2_queue *rxq,
3457 struct rte_event *ev)
3460 struct rte_crypto_op *crypto_op = (struct rte_crypto_op *)ev->event_ptr;
3461 /* Prefetching mbuf */
3462 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-
3463 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size));
3465 /* Prefetching ipsec crypto_op stored in priv data of mbuf */
3466 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-64));
3468 ev->flow_id = rxq->ev.flow_id;
3469 ev->sub_event_type = rxq->ev.sub_event_type;
3470 ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
3471 ev->op = RTE_EVENT_OP_NEW;
3472 ev->sched_type = rxq->ev.sched_type;
3473 ev->queue_id = rxq->ev.queue_id;
3474 ev->priority = rxq->ev.priority;
3476 ev->event_ptr = sec_fd_to_mbuf(fd);
3477 dqrr_index = qbman_get_dqrr_idx(dq);
3478 crypto_op->sym->m_src->seqn = dqrr_index + 1;
3479 DPAA2_PER_LCORE_DQRR_SIZE++;
3480 DPAA2_PER_LCORE_DQRR_HELD |= 1 << dqrr_index;
3481 DPAA2_PER_LCORE_DQRR_MBUF(dqrr_index) = crypto_op->sym->m_src;
3485 dpaa2_sec_eventq_attach(const struct rte_cryptodev *dev,
3487 struct dpaa2_dpcon_dev *dpcon,
3488 const struct rte_event *event)
3490 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3491 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3492 struct dpaa2_sec_qp *qp = dev->data->queue_pairs[qp_id];
3493 struct dpseci_rx_queue_cfg cfg;
3497 if (event->sched_type == RTE_SCHED_TYPE_PARALLEL)
3498 qp->rx_vq.cb = dpaa2_sec_process_parallel_event;
3499 else if (event->sched_type == RTE_SCHED_TYPE_ATOMIC)
3500 qp->rx_vq.cb = dpaa2_sec_process_atomic_event;
3504 priority = (RTE_EVENT_DEV_PRIORITY_LOWEST / event->priority) *
3505 (dpcon->num_priorities - 1);
3507 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
3508 cfg.options = DPSECI_QUEUE_OPT_DEST;
3509 cfg.dest_cfg.dest_type = DPSECI_DEST_DPCON;
3510 cfg.dest_cfg.dest_id = dpcon->dpcon_id;
3511 cfg.dest_cfg.priority = priority;
3513 cfg.options |= DPSECI_QUEUE_OPT_USER_CTX;
3514 cfg.user_ctx = (size_t)(qp);
3515 if (event->sched_type == RTE_SCHED_TYPE_ATOMIC) {
3516 cfg.options |= DPSECI_QUEUE_OPT_ORDER_PRESERVATION;
3517 cfg.order_preservation_en = 1;
3519 ret = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
3522 RTE_LOG(ERR, PMD, "Error in dpseci_set_queue: ret: %d\n", ret);
3526 memcpy(&qp->rx_vq.ev, event, sizeof(struct rte_event));
3532 dpaa2_sec_eventq_detach(const struct rte_cryptodev *dev,
3535 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3536 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3537 struct dpseci_rx_queue_cfg cfg;
3540 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
3541 cfg.options = DPSECI_QUEUE_OPT_DEST;
3542 cfg.dest_cfg.dest_type = DPSECI_DEST_NONE;
3544 ret = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
3547 RTE_LOG(ERR, PMD, "Error in dpseci_set_queue: ret: %d\n", ret);
3552 static struct rte_cryptodev_ops crypto_ops = {
3553 .dev_configure = dpaa2_sec_dev_configure,
3554 .dev_start = dpaa2_sec_dev_start,
3555 .dev_stop = dpaa2_sec_dev_stop,
3556 .dev_close = dpaa2_sec_dev_close,
3557 .dev_infos_get = dpaa2_sec_dev_infos_get,
3558 .stats_get = dpaa2_sec_stats_get,
3559 .stats_reset = dpaa2_sec_stats_reset,
3560 .queue_pair_setup = dpaa2_sec_queue_pair_setup,
3561 .queue_pair_release = dpaa2_sec_queue_pair_release,
3562 .queue_pair_count = dpaa2_sec_queue_pair_count,
3563 .sym_session_get_size = dpaa2_sec_sym_session_get_size,
3564 .sym_session_configure = dpaa2_sec_sym_session_configure,
3565 .sym_session_clear = dpaa2_sec_sym_session_clear,
3568 static const struct rte_security_capability *
3569 dpaa2_sec_capabilities_get(void *device __rte_unused)
3571 return dpaa2_sec_security_cap;
3574 static const struct rte_security_ops dpaa2_sec_security_ops = {
3575 .session_create = dpaa2_sec_security_session_create,
3576 .session_update = NULL,
3577 .session_stats_get = NULL,
3578 .session_destroy = dpaa2_sec_security_session_destroy,
3579 .set_pkt_metadata = NULL,
3580 .capabilities_get = dpaa2_sec_capabilities_get
3584 dpaa2_sec_uninit(const struct rte_cryptodev *dev)
3586 struct dpaa2_sec_dev_private *internals = dev->data->dev_private;
3588 rte_free(dev->security_ctx);
3590 rte_mempool_free(internals->fle_pool);
3592 DPAA2_SEC_INFO("Closing DPAA2_SEC device %s on numa socket %u",
3593 dev->data->name, rte_socket_id());
3599 dpaa2_sec_dev_init(struct rte_cryptodev *cryptodev)
3601 struct dpaa2_sec_dev_private *internals;
3602 struct rte_device *dev = cryptodev->device;
3603 struct rte_dpaa2_device *dpaa2_dev;
3604 struct rte_security_ctx *security_instance;
3605 struct fsl_mc_io *dpseci;
3607 struct dpseci_attr attr;
3611 PMD_INIT_FUNC_TRACE();
3612 dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
3613 if (dpaa2_dev == NULL) {
3614 DPAA2_SEC_ERR("DPAA2 SEC device not found");
3617 hw_id = dpaa2_dev->object_id;
3619 cryptodev->driver_id = cryptodev_driver_id;
3620 cryptodev->dev_ops = &crypto_ops;
3622 cryptodev->enqueue_burst = dpaa2_sec_enqueue_burst;
3623 cryptodev->dequeue_burst = dpaa2_sec_dequeue_burst;
3624 cryptodev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
3625 RTE_CRYPTODEV_FF_HW_ACCELERATED |
3626 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
3627 RTE_CRYPTODEV_FF_SECURITY |
3628 RTE_CRYPTODEV_FF_IN_PLACE_SGL |
3629 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT |
3630 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
3631 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT |
3632 RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT;
3634 internals = cryptodev->data->dev_private;
3637 * For secondary processes, we don't initialise any further as primary
3638 * has already done this work. Only check we don't need a different
3641 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
3642 DPAA2_SEC_DEBUG("Device already init by primary process");
3646 /* Initialize security_ctx only for primary process*/
3647 security_instance = rte_malloc("rte_security_instances_ops",
3648 sizeof(struct rte_security_ctx), 0);
3649 if (security_instance == NULL)
3651 security_instance->device = (void *)cryptodev;
3652 security_instance->ops = &dpaa2_sec_security_ops;
3653 security_instance->sess_cnt = 0;
3654 cryptodev->security_ctx = security_instance;
3656 /*Open the rte device via MC and save the handle for further use*/
3657 dpseci = (struct fsl_mc_io *)rte_calloc(NULL, 1,
3658 sizeof(struct fsl_mc_io), 0);
3661 "Error in allocating the memory for dpsec object");
3664 dpseci->regs = rte_mcp_ptr_list[0];
3666 retcode = dpseci_open(dpseci, CMD_PRI_LOW, hw_id, &token);
3668 DPAA2_SEC_ERR("Cannot open the dpsec device: Error = %x",
3672 retcode = dpseci_get_attributes(dpseci, CMD_PRI_LOW, token, &attr);
3675 "Cannot get dpsec device attributed: Error = %x",
3679 snprintf(cryptodev->data->name, sizeof(cryptodev->data->name),
3682 internals->max_nb_queue_pairs = attr.num_tx_queues;
3683 cryptodev->data->nb_queue_pairs = internals->max_nb_queue_pairs;
3684 internals->hw = dpseci;
3685 internals->token = token;
3687 snprintf(str, sizeof(str), "sec_fle_pool_p%d_%d",
3688 getpid(), cryptodev->data->dev_id);
3689 internals->fle_pool = rte_mempool_create((const char *)str,
3692 FLE_POOL_CACHE_SIZE, 0,
3693 NULL, NULL, NULL, NULL,
3695 if (!internals->fle_pool) {
3696 DPAA2_SEC_ERR("Mempool (%s) creation failed", str);
3700 DPAA2_SEC_INFO("driver %s: created", cryptodev->data->name);
3704 DPAA2_SEC_ERR("driver %s: create failed", cryptodev->data->name);
3706 /* dpaa2_sec_uninit(crypto_dev_name); */
3711 cryptodev_dpaa2_sec_probe(struct rte_dpaa2_driver *dpaa2_drv __rte_unused,
3712 struct rte_dpaa2_device *dpaa2_dev)
3714 struct rte_cryptodev *cryptodev;
3715 char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
3719 snprintf(cryptodev_name, sizeof(cryptodev_name), "dpsec-%d",
3720 dpaa2_dev->object_id);
3722 cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
3723 if (cryptodev == NULL)
3726 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
3727 cryptodev->data->dev_private = rte_zmalloc_socket(
3728 "cryptodev private structure",
3729 sizeof(struct dpaa2_sec_dev_private),
3730 RTE_CACHE_LINE_SIZE,
3733 if (cryptodev->data->dev_private == NULL)
3734 rte_panic("Cannot allocate memzone for private "
3738 dpaa2_dev->cryptodev = cryptodev;
3739 cryptodev->device = &dpaa2_dev->device;
3741 /* init user callbacks */
3742 TAILQ_INIT(&(cryptodev->link_intr_cbs));
3744 if (dpaa2_svr_family == SVR_LX2160A)
3745 rta_set_sec_era(RTA_SEC_ERA_10);
3747 DPAA2_SEC_INFO("2-SEC ERA is %d", rta_get_sec_era());
3749 /* Invoke PMD device initialization function */
3750 retval = dpaa2_sec_dev_init(cryptodev);
3754 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
3755 rte_free(cryptodev->data->dev_private);
3757 cryptodev->attached = RTE_CRYPTODEV_DETACHED;
3763 cryptodev_dpaa2_sec_remove(struct rte_dpaa2_device *dpaa2_dev)
3765 struct rte_cryptodev *cryptodev;
3768 cryptodev = dpaa2_dev->cryptodev;
3769 if (cryptodev == NULL)
3772 ret = dpaa2_sec_uninit(cryptodev);
3776 return rte_cryptodev_pmd_destroy(cryptodev);
3779 static struct rte_dpaa2_driver rte_dpaa2_sec_driver = {
3780 .drv_flags = RTE_DPAA2_DRV_IOVA_AS_VA,
3781 .drv_type = DPAA2_CRYPTO,
3783 .name = "DPAA2 SEC PMD"
3785 .probe = cryptodev_dpaa2_sec_probe,
3786 .remove = cryptodev_dpaa2_sec_remove,
3789 static struct cryptodev_driver dpaa2_sec_crypto_drv;
3791 RTE_PMD_REGISTER_DPAA2(CRYPTODEV_NAME_DPAA2_SEC_PMD, rte_dpaa2_sec_driver);
3792 RTE_PMD_REGISTER_CRYPTO_DRIVER(dpaa2_sec_crypto_drv,
3793 rte_dpaa2_sec_driver.driver, cryptodev_driver_id);
3795 RTE_INIT(dpaa2_sec_init_log)
3797 /* Bus level logs */
3798 dpaa2_logtype_sec = rte_log_register("pmd.crypto.dpaa2");
3799 if (dpaa2_logtype_sec >= 0)
3800 rte_log_set_level(dpaa2_logtype_sec, RTE_LOG_NOTICE);