1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
4 * Copyright 2016-2019 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"
36 /* RTA header files */
37 #include <desc/ipsec.h>
38 #include <desc/pdcp.h>
39 #include <desc/algo.h>
41 /* Minimum job descriptor consists of a oneword job descriptor HEADER and
42 * a pointer to the shared descriptor
44 #define MIN_JOB_DESC_SIZE (CAAM_CMD_SZ + CAAM_PTR_SZ)
45 #define FSL_VENDOR_ID 0x1957
46 #define FSL_DEVICE_ID 0x410
47 #define FSL_SUBSYSTEM_SEC 1
48 #define FSL_MC_DPSECI_DEVID 3
51 /* FLE_POOL_NUM_BUFS is set as per the ipsec-secgw application */
52 #define FLE_POOL_NUM_BUFS 32000
53 #define FLE_POOL_BUF_SIZE 256
54 #define FLE_POOL_CACHE_SIZE 512
55 #define FLE_SG_MEM_SIZE(num) (FLE_POOL_BUF_SIZE + ((num) * 32))
56 #define SEC_FLC_DHR_OUTBOUND -114
57 #define SEC_FLC_DHR_INBOUND 0
59 enum rta_sec_era rta_sec_era = RTA_SEC_ERA_8;
61 static uint8_t cryptodev_driver_id;
63 int dpaa2_logtype_sec;
65 #ifdef RTE_LIBRTE_SECURITY
67 build_proto_compound_sg_fd(dpaa2_sec_session *sess,
68 struct rte_crypto_op *op,
69 struct qbman_fd *fd, uint16_t bpid)
71 struct rte_crypto_sym_op *sym_op = op->sym;
72 struct ctxt_priv *priv = sess->ctxt;
73 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
74 struct sec_flow_context *flc;
75 struct rte_mbuf *mbuf;
76 uint32_t in_len = 0, out_len = 0;
83 /* first FLE entry used to store mbuf and session ctxt */
84 fle = (struct qbman_fle *)rte_malloc(NULL,
85 FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
88 DPAA2_SEC_DP_ERR("Proto:SG: Memory alloc failed for SGE");
91 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
92 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
93 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
95 /* Save the shared descriptor */
96 flc = &priv->flc_desc[0].flc;
102 if (likely(bpid < MAX_BPID)) {
103 DPAA2_SET_FD_BPID(fd, bpid);
104 DPAA2_SET_FLE_BPID(op_fle, bpid);
105 DPAA2_SET_FLE_BPID(ip_fle, bpid);
107 DPAA2_SET_FD_IVP(fd);
108 DPAA2_SET_FLE_IVP(op_fle);
109 DPAA2_SET_FLE_IVP(ip_fle);
112 /* Configure FD as a FRAME LIST */
113 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
114 DPAA2_SET_FD_COMPOUND_FMT(fd);
115 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
117 /* Configure Output FLE with Scatter/Gather Entry */
118 DPAA2_SET_FLE_SG_EXT(op_fle);
119 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
121 /* Configure Output SGE for Encap/Decap */
122 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
123 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
126 sge->length = mbuf->data_len;
127 out_len += sge->length;
130 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
131 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
133 /* using buf_len for last buf - so that extra data can be added */
134 sge->length = mbuf->buf_len - mbuf->data_off;
135 out_len += sge->length;
137 DPAA2_SET_FLE_FIN(sge);
138 op_fle->length = out_len;
141 mbuf = sym_op->m_src;
143 /* Configure Input FLE with Scatter/Gather Entry */
144 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
145 DPAA2_SET_FLE_SG_EXT(ip_fle);
146 DPAA2_SET_FLE_FIN(ip_fle);
148 /* Configure input SGE for Encap/Decap */
149 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
150 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
151 sge->length = mbuf->data_len;
152 in_len += sge->length;
158 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
159 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
160 sge->length = mbuf->data_len;
161 in_len += sge->length;
164 ip_fle->length = in_len;
165 DPAA2_SET_FLE_FIN(sge);
167 /* In case of PDCP, per packet HFN is stored in
168 * mbuf priv after sym_op.
170 if (sess->ctxt_type == DPAA2_SEC_PDCP && sess->pdcp.hfn_ovd) {
171 uint32_t hfn_ovd = *((uint8_t *)op + sess->pdcp.hfn_ovd_offset);
172 /*enable HFN override override */
173 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, hfn_ovd);
174 DPAA2_SET_FLE_INTERNAL_JD(op_fle, hfn_ovd);
175 DPAA2_SET_FD_INTERNAL_JD(fd, hfn_ovd);
177 DPAA2_SET_FD_LEN(fd, ip_fle->length);
183 build_proto_compound_fd(dpaa2_sec_session *sess,
184 struct rte_crypto_op *op,
185 struct qbman_fd *fd, uint16_t bpid)
187 struct rte_crypto_sym_op *sym_op = op->sym;
188 struct ctxt_priv *priv = sess->ctxt;
189 struct qbman_fle *fle, *ip_fle, *op_fle;
190 struct sec_flow_context *flc;
191 struct rte_mbuf *src_mbuf = sym_op->m_src;
192 struct rte_mbuf *dst_mbuf = sym_op->m_dst;
198 /* Save the shared descriptor */
199 flc = &priv->flc_desc[0].flc;
201 /* we are using the first FLE entry to store Mbuf */
202 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
204 DPAA2_SEC_DP_ERR("Memory alloc failed");
207 memset(fle, 0, FLE_POOL_BUF_SIZE);
208 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
209 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
214 if (likely(bpid < MAX_BPID)) {
215 DPAA2_SET_FD_BPID(fd, bpid);
216 DPAA2_SET_FLE_BPID(op_fle, bpid);
217 DPAA2_SET_FLE_BPID(ip_fle, bpid);
219 DPAA2_SET_FD_IVP(fd);
220 DPAA2_SET_FLE_IVP(op_fle);
221 DPAA2_SET_FLE_IVP(ip_fle);
224 /* Configure FD as a FRAME LIST */
225 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
226 DPAA2_SET_FD_COMPOUND_FMT(fd);
227 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
229 /* Configure Output FLE with dst mbuf data */
230 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_MBUF_VADDR_TO_IOVA(dst_mbuf));
231 DPAA2_SET_FLE_OFFSET(op_fle, dst_mbuf->data_off);
232 DPAA2_SET_FLE_LEN(op_fle, dst_mbuf->buf_len);
234 /* Configure Input FLE with src mbuf data */
235 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_MBUF_VADDR_TO_IOVA(src_mbuf));
236 DPAA2_SET_FLE_OFFSET(ip_fle, src_mbuf->data_off);
237 DPAA2_SET_FLE_LEN(ip_fle, src_mbuf->pkt_len);
239 DPAA2_SET_FD_LEN(fd, ip_fle->length);
240 DPAA2_SET_FLE_FIN(ip_fle);
242 /* In case of PDCP, per packet HFN is stored in
243 * mbuf priv after sym_op.
245 if (sess->ctxt_type == DPAA2_SEC_PDCP && sess->pdcp.hfn_ovd) {
246 uint32_t hfn_ovd = *((uint8_t *)op + sess->pdcp.hfn_ovd_offset);
247 /*enable HFN override override */
248 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, hfn_ovd);
249 DPAA2_SET_FLE_INTERNAL_JD(op_fle, hfn_ovd);
250 DPAA2_SET_FD_INTERNAL_JD(fd, hfn_ovd);
258 build_proto_fd(dpaa2_sec_session *sess,
259 struct rte_crypto_op *op,
260 struct qbman_fd *fd, uint16_t bpid)
262 struct rte_crypto_sym_op *sym_op = op->sym;
264 return build_proto_compound_fd(sess, op, fd, bpid);
266 struct ctxt_priv *priv = sess->ctxt;
267 struct sec_flow_context *flc;
268 struct rte_mbuf *mbuf = sym_op->m_src;
270 if (likely(bpid < MAX_BPID))
271 DPAA2_SET_FD_BPID(fd, bpid);
273 DPAA2_SET_FD_IVP(fd);
275 /* Save the shared descriptor */
276 flc = &priv->flc_desc[0].flc;
278 DPAA2_SET_FD_ADDR(fd, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
279 DPAA2_SET_FD_OFFSET(fd, sym_op->m_src->data_off);
280 DPAA2_SET_FD_LEN(fd, sym_op->m_src->pkt_len);
281 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
283 /* save physical address of mbuf */
284 op->sym->aead.digest.phys_addr = mbuf->buf_iova;
285 mbuf->buf_iova = (size_t)op;
292 build_authenc_gcm_sg_fd(dpaa2_sec_session *sess,
293 struct rte_crypto_op *op,
294 struct qbman_fd *fd, __rte_unused uint16_t bpid)
296 struct rte_crypto_sym_op *sym_op = op->sym;
297 struct ctxt_priv *priv = sess->ctxt;
298 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
299 struct sec_flow_context *flc;
300 uint32_t auth_only_len = sess->ext_params.aead_ctxt.auth_only_len;
301 int icv_len = sess->digest_length;
303 struct rte_mbuf *mbuf;
304 uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
308 mbuf = sym_op->m_dst;
310 mbuf = sym_op->m_src;
312 /* first FLE entry used to store mbuf and session ctxt */
313 fle = (struct qbman_fle *)rte_malloc(NULL,
314 FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
315 RTE_CACHE_LINE_SIZE);
316 if (unlikely(!fle)) {
317 DPAA2_SEC_ERR("GCM SG: Memory alloc failed for SGE");
320 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
321 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
322 DPAA2_FLE_SAVE_CTXT(fle, (size_t)priv);
328 /* Save the shared descriptor */
329 flc = &priv->flc_desc[0].flc;
331 /* Configure FD as a FRAME LIST */
332 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
333 DPAA2_SET_FD_COMPOUND_FMT(fd);
334 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
336 DPAA2_SEC_DP_DEBUG("GCM SG: auth_off: 0x%x/length %d, digest-len=%d\n"
337 "iv-len=%d data_off: 0x%x\n",
338 sym_op->aead.data.offset,
339 sym_op->aead.data.length,
342 sym_op->m_src->data_off);
344 /* Configure Output FLE with Scatter/Gather Entry */
345 DPAA2_SET_FLE_SG_EXT(op_fle);
346 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
349 DPAA2_SET_FLE_INTERNAL_JD(op_fle, auth_only_len);
351 op_fle->length = (sess->dir == DIR_ENC) ?
352 (sym_op->aead.data.length + icv_len) :
353 sym_op->aead.data.length;
355 /* Configure Output SGE for Encap/Decap */
356 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
357 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off + sym_op->aead.data.offset);
358 sge->length = mbuf->data_len - sym_op->aead.data.offset;
364 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
365 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
366 sge->length = mbuf->data_len;
369 sge->length -= icv_len;
371 if (sess->dir == DIR_ENC) {
373 DPAA2_SET_FLE_ADDR(sge,
374 DPAA2_VADDR_TO_IOVA(sym_op->aead.digest.data));
375 sge->length = icv_len;
377 DPAA2_SET_FLE_FIN(sge);
380 mbuf = sym_op->m_src;
382 /* Configure Input FLE with Scatter/Gather Entry */
383 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
384 DPAA2_SET_FLE_SG_EXT(ip_fle);
385 DPAA2_SET_FLE_FIN(ip_fle);
386 ip_fle->length = (sess->dir == DIR_ENC) ?
387 (sym_op->aead.data.length + sess->iv.length + auth_only_len) :
388 (sym_op->aead.data.length + sess->iv.length + auth_only_len +
391 /* Configure Input SGE for Encap/Decap */
392 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(IV_ptr));
393 sge->length = sess->iv.length;
397 DPAA2_SET_FLE_ADDR(sge,
398 DPAA2_VADDR_TO_IOVA(sym_op->aead.aad.data));
399 sge->length = auth_only_len;
403 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
404 DPAA2_SET_FLE_OFFSET(sge, sym_op->aead.data.offset +
406 sge->length = mbuf->data_len - sym_op->aead.data.offset;
412 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
413 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
414 sge->length = mbuf->data_len;
418 if (sess->dir == DIR_DEC) {
420 old_icv = (uint8_t *)(sge + 1);
421 memcpy(old_icv, sym_op->aead.digest.data, icv_len);
422 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
423 sge->length = icv_len;
426 DPAA2_SET_FLE_FIN(sge);
428 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, auth_only_len);
429 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
431 DPAA2_SET_FD_LEN(fd, ip_fle->length);
437 build_authenc_gcm_fd(dpaa2_sec_session *sess,
438 struct rte_crypto_op *op,
439 struct qbman_fd *fd, uint16_t bpid)
441 struct rte_crypto_sym_op *sym_op = op->sym;
442 struct ctxt_priv *priv = sess->ctxt;
443 struct qbman_fle *fle, *sge;
444 struct sec_flow_context *flc;
445 uint32_t auth_only_len = sess->ext_params.aead_ctxt.auth_only_len;
446 int icv_len = sess->digest_length, retval;
448 struct rte_mbuf *dst;
449 uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
457 /* TODO we are using the first FLE entry to store Mbuf and session ctxt.
458 * Currently we donot know which FLE has the mbuf stored.
459 * So while retreiving we can go back 1 FLE from the FD -ADDR
460 * to get the MBUF Addr from the previous FLE.
461 * We can have a better approach to use the inline Mbuf
463 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
465 DPAA2_SEC_ERR("GCM: Memory alloc failed for SGE");
468 memset(fle, 0, FLE_POOL_BUF_SIZE);
469 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
470 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
473 if (likely(bpid < MAX_BPID)) {
474 DPAA2_SET_FD_BPID(fd, bpid);
475 DPAA2_SET_FLE_BPID(fle, bpid);
476 DPAA2_SET_FLE_BPID(fle + 1, bpid);
477 DPAA2_SET_FLE_BPID(sge, bpid);
478 DPAA2_SET_FLE_BPID(sge + 1, bpid);
479 DPAA2_SET_FLE_BPID(sge + 2, bpid);
480 DPAA2_SET_FLE_BPID(sge + 3, bpid);
482 DPAA2_SET_FD_IVP(fd);
483 DPAA2_SET_FLE_IVP(fle);
484 DPAA2_SET_FLE_IVP((fle + 1));
485 DPAA2_SET_FLE_IVP(sge);
486 DPAA2_SET_FLE_IVP((sge + 1));
487 DPAA2_SET_FLE_IVP((sge + 2));
488 DPAA2_SET_FLE_IVP((sge + 3));
491 /* Save the shared descriptor */
492 flc = &priv->flc_desc[0].flc;
493 /* Configure FD as a FRAME LIST */
494 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
495 DPAA2_SET_FD_COMPOUND_FMT(fd);
496 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
498 DPAA2_SEC_DP_DEBUG("GCM: auth_off: 0x%x/length %d, digest-len=%d\n"
499 "iv-len=%d data_off: 0x%x\n",
500 sym_op->aead.data.offset,
501 sym_op->aead.data.length,
504 sym_op->m_src->data_off);
506 /* Configure Output FLE with Scatter/Gather Entry */
507 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
509 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
510 fle->length = (sess->dir == DIR_ENC) ?
511 (sym_op->aead.data.length + icv_len) :
512 sym_op->aead.data.length;
514 DPAA2_SET_FLE_SG_EXT(fle);
516 /* Configure Output SGE for Encap/Decap */
517 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(dst));
518 DPAA2_SET_FLE_OFFSET(sge, dst->data_off + sym_op->aead.data.offset);
519 sge->length = sym_op->aead.data.length;
521 if (sess->dir == DIR_ENC) {
523 DPAA2_SET_FLE_ADDR(sge,
524 DPAA2_VADDR_TO_IOVA(sym_op->aead.digest.data));
525 sge->length = sess->digest_length;
527 DPAA2_SET_FLE_FIN(sge);
532 /* Configure Input FLE with Scatter/Gather Entry */
533 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
534 DPAA2_SET_FLE_SG_EXT(fle);
535 DPAA2_SET_FLE_FIN(fle);
536 fle->length = (sess->dir == DIR_ENC) ?
537 (sym_op->aead.data.length + sess->iv.length + auth_only_len) :
538 (sym_op->aead.data.length + sess->iv.length + auth_only_len +
539 sess->digest_length);
541 /* Configure Input SGE for Encap/Decap */
542 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(IV_ptr));
543 sge->length = sess->iv.length;
546 DPAA2_SET_FLE_ADDR(sge,
547 DPAA2_VADDR_TO_IOVA(sym_op->aead.aad.data));
548 sge->length = auth_only_len;
549 DPAA2_SET_FLE_BPID(sge, bpid);
553 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
554 DPAA2_SET_FLE_OFFSET(sge, sym_op->aead.data.offset +
555 sym_op->m_src->data_off);
556 sge->length = sym_op->aead.data.length;
557 if (sess->dir == DIR_DEC) {
559 old_icv = (uint8_t *)(sge + 1);
560 memcpy(old_icv, sym_op->aead.digest.data,
561 sess->digest_length);
562 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
563 sge->length = sess->digest_length;
565 DPAA2_SET_FLE_FIN(sge);
568 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
569 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
572 DPAA2_SET_FD_LEN(fd, fle->length);
577 build_authenc_sg_fd(dpaa2_sec_session *sess,
578 struct rte_crypto_op *op,
579 struct qbman_fd *fd, __rte_unused uint16_t bpid)
581 struct rte_crypto_sym_op *sym_op = op->sym;
582 struct ctxt_priv *priv = sess->ctxt;
583 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
584 struct sec_flow_context *flc;
585 uint16_t auth_hdr_len = sym_op->cipher.data.offset -
586 sym_op->auth.data.offset;
587 uint16_t auth_tail_len = sym_op->auth.data.length -
588 sym_op->cipher.data.length - auth_hdr_len;
589 uint32_t auth_only_len = (auth_tail_len << 16) | auth_hdr_len;
590 int icv_len = sess->digest_length;
592 struct rte_mbuf *mbuf;
593 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
597 mbuf = sym_op->m_dst;
599 mbuf = sym_op->m_src;
601 /* first FLE entry used to store mbuf and session ctxt */
602 fle = (struct qbman_fle *)rte_malloc(NULL,
603 FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
604 RTE_CACHE_LINE_SIZE);
605 if (unlikely(!fle)) {
606 DPAA2_SEC_ERR("AUTHENC SG: Memory alloc failed for SGE");
609 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
610 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
611 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
617 /* Save the shared descriptor */
618 flc = &priv->flc_desc[0].flc;
620 /* Configure FD as a FRAME LIST */
621 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
622 DPAA2_SET_FD_COMPOUND_FMT(fd);
623 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
626 "AUTHENC SG: auth_off: 0x%x/length %d, digest-len=%d\n"
627 "cipher_off: 0x%x/length %d, iv-len=%d data_off: 0x%x\n",
628 sym_op->auth.data.offset,
629 sym_op->auth.data.length,
631 sym_op->cipher.data.offset,
632 sym_op->cipher.data.length,
634 sym_op->m_src->data_off);
636 /* Configure Output FLE with Scatter/Gather Entry */
637 DPAA2_SET_FLE_SG_EXT(op_fle);
638 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
641 DPAA2_SET_FLE_INTERNAL_JD(op_fle, auth_only_len);
643 op_fle->length = (sess->dir == DIR_ENC) ?
644 (sym_op->cipher.data.length + icv_len) :
645 sym_op->cipher.data.length;
647 /* Configure Output SGE for Encap/Decap */
648 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
649 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off + sym_op->auth.data.offset);
650 sge->length = mbuf->data_len - sym_op->auth.data.offset;
656 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
657 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
658 sge->length = mbuf->data_len;
661 sge->length -= icv_len;
663 if (sess->dir == DIR_ENC) {
665 DPAA2_SET_FLE_ADDR(sge,
666 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
667 sge->length = icv_len;
669 DPAA2_SET_FLE_FIN(sge);
672 mbuf = sym_op->m_src;
674 /* Configure Input FLE with Scatter/Gather Entry */
675 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
676 DPAA2_SET_FLE_SG_EXT(ip_fle);
677 DPAA2_SET_FLE_FIN(ip_fle);
678 ip_fle->length = (sess->dir == DIR_ENC) ?
679 (sym_op->auth.data.length + sess->iv.length) :
680 (sym_op->auth.data.length + sess->iv.length +
683 /* Configure Input SGE for Encap/Decap */
684 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
685 sge->length = sess->iv.length;
688 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
689 DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset +
691 sge->length = mbuf->data_len - sym_op->auth.data.offset;
697 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
698 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
699 sge->length = mbuf->data_len;
702 sge->length -= icv_len;
704 if (sess->dir == DIR_DEC) {
706 old_icv = (uint8_t *)(sge + 1);
707 memcpy(old_icv, sym_op->auth.digest.data,
709 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
710 sge->length = icv_len;
713 DPAA2_SET_FLE_FIN(sge);
715 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, auth_only_len);
716 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
718 DPAA2_SET_FD_LEN(fd, ip_fle->length);
724 build_authenc_fd(dpaa2_sec_session *sess,
725 struct rte_crypto_op *op,
726 struct qbman_fd *fd, uint16_t bpid)
728 struct rte_crypto_sym_op *sym_op = op->sym;
729 struct ctxt_priv *priv = sess->ctxt;
730 struct qbman_fle *fle, *sge;
731 struct sec_flow_context *flc;
732 uint16_t auth_hdr_len = sym_op->cipher.data.offset -
733 sym_op->auth.data.offset;
734 uint16_t auth_tail_len = sym_op->auth.data.length -
735 sym_op->cipher.data.length - auth_hdr_len;
736 uint32_t auth_only_len = (auth_tail_len << 16) | auth_hdr_len;
738 int icv_len = sess->digest_length, retval;
740 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
742 struct rte_mbuf *dst;
749 /* we are using the first FLE entry to store Mbuf.
750 * Currently we donot know which FLE has the mbuf stored.
751 * So while retreiving we can go back 1 FLE from the FD -ADDR
752 * to get the MBUF Addr from the previous FLE.
753 * We can have a better approach to use the inline Mbuf
755 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
757 DPAA2_SEC_ERR("Memory alloc failed for SGE");
760 memset(fle, 0, FLE_POOL_BUF_SIZE);
761 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
762 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
765 if (likely(bpid < MAX_BPID)) {
766 DPAA2_SET_FD_BPID(fd, bpid);
767 DPAA2_SET_FLE_BPID(fle, bpid);
768 DPAA2_SET_FLE_BPID(fle + 1, bpid);
769 DPAA2_SET_FLE_BPID(sge, bpid);
770 DPAA2_SET_FLE_BPID(sge + 1, bpid);
771 DPAA2_SET_FLE_BPID(sge + 2, bpid);
772 DPAA2_SET_FLE_BPID(sge + 3, bpid);
774 DPAA2_SET_FD_IVP(fd);
775 DPAA2_SET_FLE_IVP(fle);
776 DPAA2_SET_FLE_IVP((fle + 1));
777 DPAA2_SET_FLE_IVP(sge);
778 DPAA2_SET_FLE_IVP((sge + 1));
779 DPAA2_SET_FLE_IVP((sge + 2));
780 DPAA2_SET_FLE_IVP((sge + 3));
783 /* Save the shared descriptor */
784 flc = &priv->flc_desc[0].flc;
785 /* Configure FD as a FRAME LIST */
786 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
787 DPAA2_SET_FD_COMPOUND_FMT(fd);
788 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
791 "AUTHENC: auth_off: 0x%x/length %d, digest-len=%d\n"
792 "cipher_off: 0x%x/length %d, iv-len=%d data_off: 0x%x\n",
793 sym_op->auth.data.offset,
794 sym_op->auth.data.length,
796 sym_op->cipher.data.offset,
797 sym_op->cipher.data.length,
799 sym_op->m_src->data_off);
801 /* Configure Output FLE with Scatter/Gather Entry */
802 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
804 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
805 fle->length = (sess->dir == DIR_ENC) ?
806 (sym_op->cipher.data.length + icv_len) :
807 sym_op->cipher.data.length;
809 DPAA2_SET_FLE_SG_EXT(fle);
811 /* Configure Output SGE for Encap/Decap */
812 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(dst));
813 DPAA2_SET_FLE_OFFSET(sge, sym_op->cipher.data.offset +
815 sge->length = sym_op->cipher.data.length;
817 if (sess->dir == DIR_ENC) {
819 DPAA2_SET_FLE_ADDR(sge,
820 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
821 sge->length = sess->digest_length;
822 DPAA2_SET_FD_LEN(fd, (sym_op->auth.data.length +
825 DPAA2_SET_FLE_FIN(sge);
830 /* Configure Input FLE with Scatter/Gather Entry */
831 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
832 DPAA2_SET_FLE_SG_EXT(fle);
833 DPAA2_SET_FLE_FIN(fle);
834 fle->length = (sess->dir == DIR_ENC) ?
835 (sym_op->auth.data.length + sess->iv.length) :
836 (sym_op->auth.data.length + sess->iv.length +
837 sess->digest_length);
839 /* Configure Input SGE for Encap/Decap */
840 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
841 sge->length = sess->iv.length;
844 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
845 DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset +
846 sym_op->m_src->data_off);
847 sge->length = sym_op->auth.data.length;
848 if (sess->dir == DIR_DEC) {
850 old_icv = (uint8_t *)(sge + 1);
851 memcpy(old_icv, sym_op->auth.digest.data,
852 sess->digest_length);
853 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
854 sge->length = sess->digest_length;
855 DPAA2_SET_FD_LEN(fd, (sym_op->auth.data.length +
856 sess->digest_length +
859 DPAA2_SET_FLE_FIN(sge);
861 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
862 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
867 static inline int build_auth_sg_fd(
868 dpaa2_sec_session *sess,
869 struct rte_crypto_op *op,
871 __rte_unused uint16_t bpid)
873 struct rte_crypto_sym_op *sym_op = op->sym;
874 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
875 struct sec_flow_context *flc;
876 struct ctxt_priv *priv = sess->ctxt;
877 int data_len, data_offset;
879 struct rte_mbuf *mbuf;
881 data_len = sym_op->auth.data.length;
882 data_offset = sym_op->auth.data.offset;
884 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
885 sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
886 if ((data_len & 7) || (data_offset & 7)) {
887 DPAA2_SEC_ERR("AUTH: len/offset must be full bytes");
891 data_len = data_len >> 3;
892 data_offset = data_offset >> 3;
895 mbuf = sym_op->m_src;
896 fle = (struct qbman_fle *)rte_malloc(NULL,
897 FLE_SG_MEM_SIZE(mbuf->nb_segs),
898 RTE_CACHE_LINE_SIZE);
899 if (unlikely(!fle)) {
900 DPAA2_SEC_ERR("AUTH SG: Memory alloc failed for SGE");
903 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs));
904 /* first FLE entry used to store mbuf and session ctxt */
905 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
906 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
911 flc = &priv->flc_desc[DESC_INITFINAL].flc;
913 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
914 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
915 DPAA2_SET_FD_COMPOUND_FMT(fd);
918 DPAA2_SET_FLE_ADDR(op_fle,
919 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
920 op_fle->length = sess->digest_length;
923 DPAA2_SET_FLE_SG_EXT(ip_fle);
924 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
925 ip_fle->length = data_len;
927 if (sess->iv.length) {
930 iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
933 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2) {
934 iv_ptr = conv_to_snow_f9_iv(iv_ptr);
936 } else if (sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
937 iv_ptr = conv_to_zuc_eia_iv(iv_ptr);
940 sge->length = sess->iv.length;
942 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
943 ip_fle->length += sge->length;
947 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
948 DPAA2_SET_FLE_OFFSET(sge, data_offset + mbuf->data_off);
950 if (data_len <= (mbuf->data_len - data_offset)) {
951 sge->length = data_len;
954 sge->length = mbuf->data_len - data_offset;
956 /* remaining i/p segs */
957 while ((data_len = data_len - sge->length) &&
958 (mbuf = mbuf->next)) {
960 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
961 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
962 if (data_len > mbuf->data_len)
963 sge->length = mbuf->data_len;
965 sge->length = data_len;
969 if (sess->dir == DIR_DEC) {
970 /* Digest verification case */
972 old_digest = (uint8_t *)(sge + 1);
973 rte_memcpy(old_digest, sym_op->auth.digest.data,
974 sess->digest_length);
975 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_digest));
976 sge->length = sess->digest_length;
977 ip_fle->length += sess->digest_length;
979 DPAA2_SET_FLE_FIN(sge);
980 DPAA2_SET_FLE_FIN(ip_fle);
981 DPAA2_SET_FD_LEN(fd, ip_fle->length);
987 build_auth_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
988 struct qbman_fd *fd, uint16_t bpid)
990 struct rte_crypto_sym_op *sym_op = op->sym;
991 struct qbman_fle *fle, *sge;
992 struct sec_flow_context *flc;
993 struct ctxt_priv *priv = sess->ctxt;
994 int data_len, data_offset;
998 data_len = sym_op->auth.data.length;
999 data_offset = sym_op->auth.data.offset;
1001 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
1002 sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
1003 if ((data_len & 7) || (data_offset & 7)) {
1004 DPAA2_SEC_ERR("AUTH: len/offset must be full bytes");
1008 data_len = data_len >> 3;
1009 data_offset = data_offset >> 3;
1012 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
1014 DPAA2_SEC_ERR("AUTH Memory alloc failed for SGE");
1017 memset(fle, 0, FLE_POOL_BUF_SIZE);
1018 /* TODO we are using the first FLE entry to store Mbuf.
1019 * Currently we donot know which FLE has the mbuf stored.
1020 * So while retreiving we can go back 1 FLE from the FD -ADDR
1021 * to get the MBUF Addr from the previous FLE.
1022 * We can have a better approach to use the inline Mbuf
1024 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
1025 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
1029 if (likely(bpid < MAX_BPID)) {
1030 DPAA2_SET_FD_BPID(fd, bpid);
1031 DPAA2_SET_FLE_BPID(fle, bpid);
1032 DPAA2_SET_FLE_BPID(fle + 1, bpid);
1033 DPAA2_SET_FLE_BPID(sge, bpid);
1034 DPAA2_SET_FLE_BPID(sge + 1, bpid);
1036 DPAA2_SET_FD_IVP(fd);
1037 DPAA2_SET_FLE_IVP(fle);
1038 DPAA2_SET_FLE_IVP((fle + 1));
1039 DPAA2_SET_FLE_IVP(sge);
1040 DPAA2_SET_FLE_IVP((sge + 1));
1043 flc = &priv->flc_desc[DESC_INITFINAL].flc;
1044 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
1045 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
1046 DPAA2_SET_FD_COMPOUND_FMT(fd);
1048 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
1049 fle->length = sess->digest_length;
1052 /* Setting input FLE */
1053 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
1054 DPAA2_SET_FLE_SG_EXT(fle);
1055 fle->length = data_len;
1057 if (sess->iv.length) {
1060 iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1063 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2) {
1064 iv_ptr = conv_to_snow_f9_iv(iv_ptr);
1066 } else if (sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
1067 iv_ptr = conv_to_zuc_eia_iv(iv_ptr);
1070 sge->length = sess->iv.length;
1073 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
1074 fle->length = fle->length + sge->length;
1078 /* Setting data to authenticate */
1079 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
1080 DPAA2_SET_FLE_OFFSET(sge, data_offset + sym_op->m_src->data_off);
1081 sge->length = data_len;
1083 if (sess->dir == DIR_DEC) {
1085 old_digest = (uint8_t *)(sge + 1);
1086 rte_memcpy(old_digest, sym_op->auth.digest.data,
1087 sess->digest_length);
1088 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_digest));
1089 sge->length = sess->digest_length;
1090 fle->length = fle->length + sess->digest_length;
1093 DPAA2_SET_FLE_FIN(sge);
1094 DPAA2_SET_FLE_FIN(fle);
1095 DPAA2_SET_FD_LEN(fd, fle->length);
1101 build_cipher_sg_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
1102 struct qbman_fd *fd, __rte_unused uint16_t bpid)
1104 struct rte_crypto_sym_op *sym_op = op->sym;
1105 struct qbman_fle *ip_fle, *op_fle, *sge, *fle;
1106 int data_len, data_offset;
1107 struct sec_flow_context *flc;
1108 struct ctxt_priv *priv = sess->ctxt;
1109 struct rte_mbuf *mbuf;
1110 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1113 data_len = sym_op->cipher.data.length;
1114 data_offset = sym_op->cipher.data.offset;
1116 if (sess->cipher_alg == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
1117 sess->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
1118 if ((data_len & 7) || (data_offset & 7)) {
1119 DPAA2_SEC_ERR("CIPHER: len/offset must be full bytes");
1123 data_len = data_len >> 3;
1124 data_offset = data_offset >> 3;
1128 mbuf = sym_op->m_dst;
1130 mbuf = sym_op->m_src;
1132 /* first FLE entry used to store mbuf and session ctxt */
1133 fle = (struct qbman_fle *)rte_malloc(NULL,
1134 FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
1135 RTE_CACHE_LINE_SIZE);
1137 DPAA2_SEC_ERR("CIPHER SG: Memory alloc failed for SGE");
1140 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
1141 /* first FLE entry used to store mbuf and session ctxt */
1142 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
1143 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
1149 flc = &priv->flc_desc[0].flc;
1152 "CIPHER SG: cipher_off: 0x%x/length %d, ivlen=%d"
1153 " data_off: 0x%x\n",
1157 sym_op->m_src->data_off);
1160 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
1161 op_fle->length = data_len;
1162 DPAA2_SET_FLE_SG_EXT(op_fle);
1165 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1166 DPAA2_SET_FLE_OFFSET(sge, data_offset + mbuf->data_off);
1167 sge->length = mbuf->data_len - data_offset;
1173 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1174 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
1175 sge->length = mbuf->data_len;
1178 DPAA2_SET_FLE_FIN(sge);
1181 "CIPHER SG: 1 - flc = %p, fle = %p FLEaddr = %x-%x, len %d\n",
1182 flc, fle, fle->addr_hi, fle->addr_lo,
1186 mbuf = sym_op->m_src;
1188 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
1189 ip_fle->length = sess->iv.length + data_len;
1190 DPAA2_SET_FLE_SG_EXT(ip_fle);
1193 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
1194 DPAA2_SET_FLE_OFFSET(sge, 0);
1195 sge->length = sess->iv.length;
1200 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1201 DPAA2_SET_FLE_OFFSET(sge, data_offset + mbuf->data_off);
1202 sge->length = mbuf->data_len - data_offset;
1208 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1209 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
1210 sge->length = mbuf->data_len;
1213 DPAA2_SET_FLE_FIN(sge);
1214 DPAA2_SET_FLE_FIN(ip_fle);
1217 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
1218 DPAA2_SET_FD_LEN(fd, ip_fle->length);
1219 DPAA2_SET_FD_COMPOUND_FMT(fd);
1220 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
1223 "CIPHER SG: fdaddr =%" PRIx64 " bpid =%d meta =%d"
1224 " off =%d, len =%d\n",
1225 DPAA2_GET_FD_ADDR(fd),
1226 DPAA2_GET_FD_BPID(fd),
1227 rte_dpaa2_bpid_info[bpid].meta_data_size,
1228 DPAA2_GET_FD_OFFSET(fd),
1229 DPAA2_GET_FD_LEN(fd));
1234 build_cipher_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
1235 struct qbman_fd *fd, uint16_t bpid)
1237 struct rte_crypto_sym_op *sym_op = op->sym;
1238 struct qbman_fle *fle, *sge;
1239 int retval, data_len, data_offset;
1240 struct sec_flow_context *flc;
1241 struct ctxt_priv *priv = sess->ctxt;
1242 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1244 struct rte_mbuf *dst;
1246 data_len = sym_op->cipher.data.length;
1247 data_offset = sym_op->cipher.data.offset;
1249 if (sess->cipher_alg == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
1250 sess->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
1251 if ((data_len & 7) || (data_offset & 7)) {
1252 DPAA2_SEC_ERR("CIPHER: len/offset must be full bytes");
1256 data_len = data_len >> 3;
1257 data_offset = data_offset >> 3;
1261 dst = sym_op->m_dst;
1263 dst = sym_op->m_src;
1265 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
1267 DPAA2_SEC_ERR("CIPHER: Memory alloc failed for SGE");
1270 memset(fle, 0, FLE_POOL_BUF_SIZE);
1271 /* TODO we are using the first FLE entry to store Mbuf.
1272 * Currently we donot know which FLE has the mbuf stored.
1273 * So while retreiving we can go back 1 FLE from the FD -ADDR
1274 * to get the MBUF Addr from the previous FLE.
1275 * We can have a better approach to use the inline Mbuf
1277 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
1278 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
1282 if (likely(bpid < MAX_BPID)) {
1283 DPAA2_SET_FD_BPID(fd, bpid);
1284 DPAA2_SET_FLE_BPID(fle, bpid);
1285 DPAA2_SET_FLE_BPID(fle + 1, bpid);
1286 DPAA2_SET_FLE_BPID(sge, bpid);
1287 DPAA2_SET_FLE_BPID(sge + 1, bpid);
1289 DPAA2_SET_FD_IVP(fd);
1290 DPAA2_SET_FLE_IVP(fle);
1291 DPAA2_SET_FLE_IVP((fle + 1));
1292 DPAA2_SET_FLE_IVP(sge);
1293 DPAA2_SET_FLE_IVP((sge + 1));
1296 flc = &priv->flc_desc[0].flc;
1297 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
1298 DPAA2_SET_FD_LEN(fd, data_len + sess->iv.length);
1299 DPAA2_SET_FD_COMPOUND_FMT(fd);
1300 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
1303 "CIPHER: cipher_off: 0x%x/length %d, ivlen=%d,"
1304 " data_off: 0x%x\n",
1308 sym_op->m_src->data_off);
1310 DPAA2_SET_FLE_ADDR(fle, DPAA2_MBUF_VADDR_TO_IOVA(dst));
1311 DPAA2_SET_FLE_OFFSET(fle, data_offset + dst->data_off);
1313 fle->length = data_len + sess->iv.length;
1316 "CIPHER: 1 - flc = %p, fle = %p FLEaddr = %x-%x, length %d\n",
1317 flc, fle, fle->addr_hi, fle->addr_lo,
1322 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
1323 fle->length = data_len + sess->iv.length;
1325 DPAA2_SET_FLE_SG_EXT(fle);
1327 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
1328 sge->length = sess->iv.length;
1331 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
1332 DPAA2_SET_FLE_OFFSET(sge, data_offset + sym_op->m_src->data_off);
1334 sge->length = data_len;
1335 DPAA2_SET_FLE_FIN(sge);
1336 DPAA2_SET_FLE_FIN(fle);
1339 "CIPHER: fdaddr =%" PRIx64 " bpid =%d meta =%d"
1340 " off =%d, len =%d\n",
1341 DPAA2_GET_FD_ADDR(fd),
1342 DPAA2_GET_FD_BPID(fd),
1343 rte_dpaa2_bpid_info[bpid].meta_data_size,
1344 DPAA2_GET_FD_OFFSET(fd),
1345 DPAA2_GET_FD_LEN(fd));
1351 build_sec_fd(struct rte_crypto_op *op,
1352 struct qbman_fd *fd, uint16_t bpid)
1355 dpaa2_sec_session *sess;
1357 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION)
1358 sess = (dpaa2_sec_session *)get_sym_session_private_data(
1359 op->sym->session, cryptodev_driver_id);
1360 #ifdef RTE_LIBRTE_SECURITY
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);
1371 /* Any of the buffer is segmented*/
1372 if (!rte_pktmbuf_is_contiguous(op->sym->m_src) ||
1373 ((op->sym->m_dst != NULL) &&
1374 !rte_pktmbuf_is_contiguous(op->sym->m_dst))) {
1375 switch (sess->ctxt_type) {
1376 case DPAA2_SEC_CIPHER:
1377 ret = build_cipher_sg_fd(sess, op, fd, bpid);
1379 case DPAA2_SEC_AUTH:
1380 ret = build_auth_sg_fd(sess, op, fd, bpid);
1382 case DPAA2_SEC_AEAD:
1383 ret = build_authenc_gcm_sg_fd(sess, op, fd, bpid);
1385 case DPAA2_SEC_CIPHER_HASH:
1386 ret = build_authenc_sg_fd(sess, op, fd, bpid);
1388 #ifdef RTE_LIBRTE_SECURITY
1389 case DPAA2_SEC_IPSEC:
1390 case DPAA2_SEC_PDCP:
1391 ret = build_proto_compound_sg_fd(sess, op, fd, bpid);
1394 case DPAA2_SEC_HASH_CIPHER:
1396 DPAA2_SEC_ERR("error: Unsupported session");
1399 switch (sess->ctxt_type) {
1400 case DPAA2_SEC_CIPHER:
1401 ret = build_cipher_fd(sess, op, fd, bpid);
1403 case DPAA2_SEC_AUTH:
1404 ret = build_auth_fd(sess, op, fd, bpid);
1406 case DPAA2_SEC_AEAD:
1407 ret = build_authenc_gcm_fd(sess, op, fd, bpid);
1409 case DPAA2_SEC_CIPHER_HASH:
1410 ret = build_authenc_fd(sess, op, fd, bpid);
1412 #ifdef RTE_LIBRTE_SECURITY
1413 case DPAA2_SEC_IPSEC:
1414 ret = build_proto_fd(sess, op, fd, bpid);
1416 case DPAA2_SEC_PDCP:
1417 ret = build_proto_compound_fd(sess, op, fd, bpid);
1420 case DPAA2_SEC_HASH_CIPHER:
1422 DPAA2_SEC_ERR("error: Unsupported session");
1429 dpaa2_sec_enqueue_burst(void *qp, struct rte_crypto_op **ops,
1432 /* Function to transmit the frames to given device and VQ*/
1435 struct qbman_fd fd_arr[MAX_TX_RING_SLOTS];
1436 uint32_t frames_to_send, retry_count;
1437 struct qbman_eq_desc eqdesc;
1438 struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
1439 struct qbman_swp *swp;
1440 uint16_t num_tx = 0;
1441 uint32_t flags[MAX_TX_RING_SLOTS] = {0};
1442 /*todo - need to support multiple buffer pools */
1444 struct rte_mempool *mb_pool;
1446 if (unlikely(nb_ops == 0))
1449 if (ops[0]->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
1450 DPAA2_SEC_ERR("sessionless crypto op not supported");
1453 /*Prepare enqueue descriptor*/
1454 qbman_eq_desc_clear(&eqdesc);
1455 qbman_eq_desc_set_no_orp(&eqdesc, DPAA2_EQ_RESP_ERR_FQ);
1456 qbman_eq_desc_set_response(&eqdesc, 0, 0);
1457 qbman_eq_desc_set_fq(&eqdesc, dpaa2_qp->tx_vq.fqid);
1459 if (!DPAA2_PER_LCORE_DPIO) {
1460 ret = dpaa2_affine_qbman_swp();
1462 DPAA2_SEC_ERR("Failure in affining portal");
1466 swp = DPAA2_PER_LCORE_PORTAL;
1469 frames_to_send = (nb_ops > dpaa2_eqcr_size) ?
1470 dpaa2_eqcr_size : nb_ops;
1472 for (loop = 0; loop < frames_to_send; loop++) {
1473 if ((*ops)->sym->m_src->seqn) {
1474 uint8_t dqrr_index = (*ops)->sym->m_src->seqn - 1;
1476 flags[loop] = QBMAN_ENQUEUE_FLAG_DCA | dqrr_index;
1477 DPAA2_PER_LCORE_DQRR_SIZE--;
1478 DPAA2_PER_LCORE_DQRR_HELD &= ~(1 << dqrr_index);
1479 (*ops)->sym->m_src->seqn = DPAA2_INVALID_MBUF_SEQN;
1482 /*Clear the unused FD fields before sending*/
1483 memset(&fd_arr[loop], 0, sizeof(struct qbman_fd));
1484 mb_pool = (*ops)->sym->m_src->pool;
1485 bpid = mempool_to_bpid(mb_pool);
1486 ret = build_sec_fd(*ops, &fd_arr[loop], bpid);
1488 DPAA2_SEC_ERR("error: Improper packet contents"
1489 " for crypto operation");
1497 while (loop < frames_to_send) {
1498 ret = qbman_swp_enqueue_multiple(swp, &eqdesc,
1501 frames_to_send - loop);
1502 if (unlikely(ret < 0)) {
1504 if (retry_count > DPAA2_MAX_TX_RETRY_COUNT) {
1519 dpaa2_qp->tx_vq.tx_pkts += num_tx;
1520 dpaa2_qp->tx_vq.err_pkts += nb_ops;
1524 #ifdef RTE_LIBRTE_SECURITY
1525 static inline struct rte_crypto_op *
1526 sec_simple_fd_to_mbuf(const struct qbman_fd *fd)
1528 struct rte_crypto_op *op;
1529 uint16_t len = DPAA2_GET_FD_LEN(fd);
1531 dpaa2_sec_session *sess_priv __rte_unused;
1533 struct rte_mbuf *mbuf = DPAA2_INLINE_MBUF_FROM_BUF(
1534 DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd)),
1535 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size);
1537 diff = len - mbuf->pkt_len;
1538 mbuf->pkt_len += diff;
1539 mbuf->data_len += diff;
1540 op = (struct rte_crypto_op *)(size_t)mbuf->buf_iova;
1541 mbuf->buf_iova = op->sym->aead.digest.phys_addr;
1542 op->sym->aead.digest.phys_addr = 0L;
1544 sess_priv = (dpaa2_sec_session *)get_sec_session_private_data(
1545 op->sym->sec_session);
1546 if (sess_priv->dir == DIR_ENC)
1547 mbuf->data_off += SEC_FLC_DHR_OUTBOUND;
1549 mbuf->data_off += SEC_FLC_DHR_INBOUND;
1555 static inline struct rte_crypto_op *
1556 sec_fd_to_mbuf(const struct qbman_fd *fd)
1558 struct qbman_fle *fle;
1559 struct rte_crypto_op *op;
1560 struct ctxt_priv *priv;
1561 struct rte_mbuf *dst, *src;
1563 #ifdef RTE_LIBRTE_SECURITY
1564 if (DPAA2_FD_GET_FORMAT(fd) == qbman_fd_single)
1565 return sec_simple_fd_to_mbuf(fd);
1567 fle = (struct qbman_fle *)DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd));
1569 DPAA2_SEC_DP_DEBUG("FLE addr = %x - %x, offset = %x\n",
1570 fle->addr_hi, fle->addr_lo, fle->fin_bpid_offset);
1572 /* we are using the first FLE entry to store Mbuf.
1573 * Currently we donot know which FLE has the mbuf stored.
1574 * So while retreiving we can go back 1 FLE from the FD -ADDR
1575 * to get the MBUF Addr from the previous FLE.
1576 * We can have a better approach to use the inline Mbuf
1579 if (unlikely(DPAA2_GET_FD_IVP(fd))) {
1580 /* TODO complete it. */
1581 DPAA2_SEC_ERR("error: non inline buffer");
1584 op = (struct rte_crypto_op *)DPAA2_GET_FLE_ADDR((fle - 1));
1587 src = op->sym->m_src;
1590 if (op->sym->m_dst) {
1591 dst = op->sym->m_dst;
1596 #ifdef RTE_LIBRTE_SECURITY
1597 if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
1598 uint16_t len = DPAA2_GET_FD_LEN(fd);
1600 while (dst->next != NULL) {
1601 len -= dst->data_len;
1604 dst->data_len = len;
1607 DPAA2_SEC_DP_DEBUG("mbuf %p BMAN buf addr %p,"
1608 " fdaddr =%" PRIx64 " bpid =%d meta =%d off =%d, len =%d\n",
1611 DPAA2_GET_FD_ADDR(fd),
1612 DPAA2_GET_FD_BPID(fd),
1613 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size,
1614 DPAA2_GET_FD_OFFSET(fd),
1615 DPAA2_GET_FD_LEN(fd));
1617 /* free the fle memory */
1618 if (likely(rte_pktmbuf_is_contiguous(src))) {
1619 priv = (struct ctxt_priv *)(size_t)DPAA2_GET_FLE_CTXT(fle - 1);
1620 rte_mempool_put(priv->fle_pool, (void *)(fle-1));
1622 rte_free((void *)(fle-1));
1628 dpaa2_sec_dequeue_burst(void *qp, struct rte_crypto_op **ops,
1631 /* Function is responsible to receive frames for a given device and VQ*/
1632 struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
1633 struct qbman_result *dq_storage;
1634 uint32_t fqid = dpaa2_qp->rx_vq.fqid;
1635 int ret, num_rx = 0;
1636 uint8_t is_last = 0, status;
1637 struct qbman_swp *swp;
1638 const struct qbman_fd *fd;
1639 struct qbman_pull_desc pulldesc;
1641 if (!DPAA2_PER_LCORE_DPIO) {
1642 ret = dpaa2_affine_qbman_swp();
1644 DPAA2_SEC_ERR("Failure in affining portal");
1648 swp = DPAA2_PER_LCORE_PORTAL;
1649 dq_storage = dpaa2_qp->rx_vq.q_storage->dq_storage[0];
1651 qbman_pull_desc_clear(&pulldesc);
1652 qbman_pull_desc_set_numframes(&pulldesc,
1653 (nb_ops > dpaa2_dqrr_size) ?
1654 dpaa2_dqrr_size : nb_ops);
1655 qbman_pull_desc_set_fq(&pulldesc, fqid);
1656 qbman_pull_desc_set_storage(&pulldesc, dq_storage,
1657 (dma_addr_t)DPAA2_VADDR_TO_IOVA(dq_storage),
1660 /*Issue a volatile dequeue command. */
1662 if (qbman_swp_pull(swp, &pulldesc)) {
1664 "SEC VDQ command is not issued : QBMAN busy");
1665 /* Portal was busy, try again */
1671 /* Receive the packets till Last Dequeue entry is found with
1672 * respect to the above issues PULL command.
1675 /* Check if the previous issued command is completed.
1676 * Also seems like the SWP is shared between the Ethernet Driver
1677 * and the SEC driver.
1679 while (!qbman_check_command_complete(dq_storage))
1682 /* Loop until the dq_storage is updated with
1683 * new token by QBMAN
1685 while (!qbman_check_new_result(dq_storage))
1687 /* Check whether Last Pull command is Expired and
1688 * setting Condition for Loop termination
1690 if (qbman_result_DQ_is_pull_complete(dq_storage)) {
1692 /* Check for valid frame. */
1693 status = (uint8_t)qbman_result_DQ_flags(dq_storage);
1695 (status & QBMAN_DQ_STAT_VALIDFRAME) == 0)) {
1696 DPAA2_SEC_DP_DEBUG("No frame is delivered\n");
1701 fd = qbman_result_DQ_fd(dq_storage);
1702 ops[num_rx] = sec_fd_to_mbuf(fd);
1704 if (unlikely(fd->simple.frc)) {
1705 /* TODO Parse SEC errors */
1706 DPAA2_SEC_ERR("SEC returned Error - %x",
1708 ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_ERROR;
1710 ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
1715 } /* End of Packet Rx loop */
1717 dpaa2_qp->rx_vq.rx_pkts += num_rx;
1719 DPAA2_SEC_DP_DEBUG("SEC Received %d Packets\n", num_rx);
1720 /*Return the total number of packets received to DPAA2 app*/
1724 /** Release queue pair */
1726 dpaa2_sec_queue_pair_release(struct rte_cryptodev *dev, uint16_t queue_pair_id)
1728 struct dpaa2_sec_qp *qp =
1729 (struct dpaa2_sec_qp *)dev->data->queue_pairs[queue_pair_id];
1731 PMD_INIT_FUNC_TRACE();
1733 if (qp->rx_vq.q_storage) {
1734 dpaa2_free_dq_storage(qp->rx_vq.q_storage);
1735 rte_free(qp->rx_vq.q_storage);
1739 dev->data->queue_pairs[queue_pair_id] = NULL;
1744 /** Setup a queue pair */
1746 dpaa2_sec_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
1747 __rte_unused const struct rte_cryptodev_qp_conf *qp_conf,
1748 __rte_unused int socket_id)
1750 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
1751 struct dpaa2_sec_qp *qp;
1752 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
1753 struct dpseci_rx_queue_cfg cfg;
1756 PMD_INIT_FUNC_TRACE();
1758 /* If qp is already in use free ring memory and qp metadata. */
1759 if (dev->data->queue_pairs[qp_id] != NULL) {
1760 DPAA2_SEC_INFO("QP already setup");
1764 DPAA2_SEC_DEBUG("dev =%p, queue =%d, conf =%p",
1765 dev, qp_id, qp_conf);
1767 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
1769 qp = rte_malloc(NULL, sizeof(struct dpaa2_sec_qp),
1770 RTE_CACHE_LINE_SIZE);
1772 DPAA2_SEC_ERR("malloc failed for rx/tx queues");
1776 qp->rx_vq.crypto_data = dev->data;
1777 qp->tx_vq.crypto_data = dev->data;
1778 qp->rx_vq.q_storage = rte_malloc("sec dq storage",
1779 sizeof(struct queue_storage_info_t),
1780 RTE_CACHE_LINE_SIZE);
1781 if (!qp->rx_vq.q_storage) {
1782 DPAA2_SEC_ERR("malloc failed for q_storage");
1785 memset(qp->rx_vq.q_storage, 0, sizeof(struct queue_storage_info_t));
1787 if (dpaa2_alloc_dq_storage(qp->rx_vq.q_storage)) {
1788 DPAA2_SEC_ERR("Unable to allocate dequeue storage");
1792 dev->data->queue_pairs[qp_id] = qp;
1794 cfg.options = cfg.options | DPSECI_QUEUE_OPT_USER_CTX;
1795 cfg.user_ctx = (size_t)(&qp->rx_vq);
1796 retcode = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
1801 /** Return the number of allocated queue pairs */
1803 dpaa2_sec_queue_pair_count(struct rte_cryptodev *dev)
1805 PMD_INIT_FUNC_TRACE();
1807 return dev->data->nb_queue_pairs;
1810 /** Returns the size of the aesni gcm session structure */
1812 dpaa2_sec_sym_session_get_size(struct rte_cryptodev *dev __rte_unused)
1814 PMD_INIT_FUNC_TRACE();
1816 return sizeof(dpaa2_sec_session);
1820 dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
1821 struct rte_crypto_sym_xform *xform,
1822 dpaa2_sec_session *session)
1824 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
1825 struct alginfo cipherdata;
1827 struct ctxt_priv *priv;
1828 struct sec_flow_context *flc;
1830 PMD_INIT_FUNC_TRACE();
1832 /* For SEC CIPHER only one descriptor is required. */
1833 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
1834 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
1835 RTE_CACHE_LINE_SIZE);
1837 DPAA2_SEC_ERR("No Memory for priv CTXT");
1841 priv->fle_pool = dev_priv->fle_pool;
1843 flc = &priv->flc_desc[0].flc;
1845 session->ctxt_type = DPAA2_SEC_CIPHER;
1846 session->cipher_key.data = rte_zmalloc(NULL, xform->cipher.key.length,
1847 RTE_CACHE_LINE_SIZE);
1848 if (session->cipher_key.data == NULL) {
1849 DPAA2_SEC_ERR("No Memory for cipher key");
1853 session->cipher_key.length = xform->cipher.key.length;
1855 memcpy(session->cipher_key.data, xform->cipher.key.data,
1856 xform->cipher.key.length);
1857 cipherdata.key = (size_t)session->cipher_key.data;
1858 cipherdata.keylen = session->cipher_key.length;
1859 cipherdata.key_enc_flags = 0;
1860 cipherdata.key_type = RTA_DATA_IMM;
1862 /* Set IV parameters */
1863 session->iv.offset = xform->cipher.iv.offset;
1864 session->iv.length = xform->cipher.iv.length;
1865 session->dir = (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
1868 switch (xform->cipher.algo) {
1869 case RTE_CRYPTO_CIPHER_AES_CBC:
1870 cipherdata.algtype = OP_ALG_ALGSEL_AES;
1871 cipherdata.algmode = OP_ALG_AAI_CBC;
1872 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
1873 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
1874 SHR_NEVER, &cipherdata,
1878 case RTE_CRYPTO_CIPHER_3DES_CBC:
1879 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
1880 cipherdata.algmode = OP_ALG_AAI_CBC;
1881 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
1882 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
1883 SHR_NEVER, &cipherdata,
1887 case RTE_CRYPTO_CIPHER_AES_CTR:
1888 cipherdata.algtype = OP_ALG_ALGSEL_AES;
1889 cipherdata.algmode = OP_ALG_AAI_CTR;
1890 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
1891 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
1892 SHR_NEVER, &cipherdata,
1896 case RTE_CRYPTO_CIPHER_3DES_CTR:
1897 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
1898 cipherdata.algmode = OP_ALG_AAI_CTR;
1899 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CTR;
1900 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
1901 SHR_NEVER, &cipherdata,
1905 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
1906 cipherdata.algtype = OP_ALG_ALGSEL_SNOW_F8;
1907 session->cipher_alg = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1908 bufsize = cnstr_shdsc_snow_f8(priv->flc_desc[0].desc, 1, 0,
1912 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
1913 cipherdata.algtype = OP_ALG_ALGSEL_ZUCE;
1914 session->cipher_alg = RTE_CRYPTO_CIPHER_ZUC_EEA3;
1915 bufsize = cnstr_shdsc_zuce(priv->flc_desc[0].desc, 1, 0,
1919 case RTE_CRYPTO_CIPHER_KASUMI_F8:
1920 case RTE_CRYPTO_CIPHER_AES_F8:
1921 case RTE_CRYPTO_CIPHER_AES_ECB:
1922 case RTE_CRYPTO_CIPHER_3DES_ECB:
1923 case RTE_CRYPTO_CIPHER_AES_XTS:
1924 case RTE_CRYPTO_CIPHER_ARC4:
1925 case RTE_CRYPTO_CIPHER_NULL:
1926 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
1927 xform->cipher.algo);
1930 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
1931 xform->cipher.algo);
1936 DPAA2_SEC_ERR("Crypto: Descriptor build failed");
1940 flc->word1_sdl = (uint8_t)bufsize;
1941 session->ctxt = priv;
1943 #ifdef CAAM_DESC_DEBUG
1945 for (i = 0; i < bufsize; i++)
1946 DPAA2_SEC_DEBUG("DESC[%d]:0x%x", i, priv->flc_desc[0].desc[i]);
1951 rte_free(session->cipher_key.data);
1957 dpaa2_sec_auth_init(struct rte_cryptodev *dev,
1958 struct rte_crypto_sym_xform *xform,
1959 dpaa2_sec_session *session)
1961 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
1962 struct alginfo authdata;
1964 struct ctxt_priv *priv;
1965 struct sec_flow_context *flc;
1967 PMD_INIT_FUNC_TRACE();
1969 /* For SEC AUTH three descriptors are required for various stages */
1970 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
1971 sizeof(struct ctxt_priv) + 3 *
1972 sizeof(struct sec_flc_desc),
1973 RTE_CACHE_LINE_SIZE);
1975 DPAA2_SEC_ERR("No Memory for priv CTXT");
1979 priv->fle_pool = dev_priv->fle_pool;
1980 flc = &priv->flc_desc[DESC_INITFINAL].flc;
1982 session->ctxt_type = DPAA2_SEC_AUTH;
1983 session->auth_key.data = rte_zmalloc(NULL, xform->auth.key.length,
1984 RTE_CACHE_LINE_SIZE);
1985 if (session->auth_key.data == NULL) {
1986 DPAA2_SEC_ERR("Unable to allocate memory for auth key");
1990 session->auth_key.length = xform->auth.key.length;
1992 memcpy(session->auth_key.data, xform->auth.key.data,
1993 xform->auth.key.length);
1994 authdata.key = (size_t)session->auth_key.data;
1995 authdata.keylen = session->auth_key.length;
1996 authdata.key_enc_flags = 0;
1997 authdata.key_type = RTA_DATA_IMM;
1999 session->digest_length = xform->auth.digest_length;
2000 session->dir = (xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE) ?
2003 switch (xform->auth.algo) {
2004 case RTE_CRYPTO_AUTH_SHA1_HMAC:
2005 authdata.algtype = OP_ALG_ALGSEL_SHA1;
2006 authdata.algmode = OP_ALG_AAI_HMAC;
2007 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
2008 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2009 1, 0, SHR_NEVER, &authdata,
2011 session->digest_length);
2013 case RTE_CRYPTO_AUTH_MD5_HMAC:
2014 authdata.algtype = OP_ALG_ALGSEL_MD5;
2015 authdata.algmode = OP_ALG_AAI_HMAC;
2016 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
2017 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2018 1, 0, SHR_NEVER, &authdata,
2020 session->digest_length);
2022 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2023 authdata.algtype = OP_ALG_ALGSEL_SHA256;
2024 authdata.algmode = OP_ALG_AAI_HMAC;
2025 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
2026 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2027 1, 0, SHR_NEVER, &authdata,
2029 session->digest_length);
2031 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2032 authdata.algtype = OP_ALG_ALGSEL_SHA384;
2033 authdata.algmode = OP_ALG_AAI_HMAC;
2034 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
2035 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2036 1, 0, SHR_NEVER, &authdata,
2038 session->digest_length);
2040 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2041 authdata.algtype = OP_ALG_ALGSEL_SHA512;
2042 authdata.algmode = OP_ALG_AAI_HMAC;
2043 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
2044 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2045 1, 0, SHR_NEVER, &authdata,
2047 session->digest_length);
2049 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2050 authdata.algtype = OP_ALG_ALGSEL_SHA224;
2051 authdata.algmode = OP_ALG_AAI_HMAC;
2052 session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
2053 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2054 1, 0, SHR_NEVER, &authdata,
2056 session->digest_length);
2058 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2059 authdata.algtype = OP_ALG_ALGSEL_SNOW_F9;
2060 authdata.algmode = OP_ALG_AAI_F9;
2061 session->auth_alg = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2062 session->iv.offset = xform->auth.iv.offset;
2063 session->iv.length = xform->auth.iv.length;
2064 bufsize = cnstr_shdsc_snow_f9(priv->flc_desc[DESC_INITFINAL].desc,
2067 session->digest_length);
2069 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2070 authdata.algtype = OP_ALG_ALGSEL_ZUCA;
2071 authdata.algmode = OP_ALG_AAI_F9;
2072 session->auth_alg = RTE_CRYPTO_AUTH_ZUC_EIA3;
2073 session->iv.offset = xform->auth.iv.offset;
2074 session->iv.length = xform->auth.iv.length;
2075 bufsize = cnstr_shdsc_zuca(priv->flc_desc[DESC_INITFINAL].desc,
2078 session->digest_length);
2080 case RTE_CRYPTO_AUTH_KASUMI_F9:
2081 case RTE_CRYPTO_AUTH_NULL:
2082 case RTE_CRYPTO_AUTH_SHA1:
2083 case RTE_CRYPTO_AUTH_SHA256:
2084 case RTE_CRYPTO_AUTH_SHA512:
2085 case RTE_CRYPTO_AUTH_SHA224:
2086 case RTE_CRYPTO_AUTH_SHA384:
2087 case RTE_CRYPTO_AUTH_MD5:
2088 case RTE_CRYPTO_AUTH_AES_GMAC:
2089 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2090 case RTE_CRYPTO_AUTH_AES_CMAC:
2091 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2092 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %un",
2096 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2102 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2106 flc->word1_sdl = (uint8_t)bufsize;
2107 session->ctxt = priv;
2108 #ifdef CAAM_DESC_DEBUG
2110 for (i = 0; i < bufsize; i++)
2111 DPAA2_SEC_DEBUG("DESC[%d]:0x%x",
2112 i, priv->flc_desc[DESC_INITFINAL].desc[i]);
2118 rte_free(session->auth_key.data);
2124 dpaa2_sec_aead_init(struct rte_cryptodev *dev,
2125 struct rte_crypto_sym_xform *xform,
2126 dpaa2_sec_session *session)
2128 struct dpaa2_sec_aead_ctxt *ctxt = &session->ext_params.aead_ctxt;
2129 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2130 struct alginfo aeaddata;
2132 struct ctxt_priv *priv;
2133 struct sec_flow_context *flc;
2134 struct rte_crypto_aead_xform *aead_xform = &xform->aead;
2137 PMD_INIT_FUNC_TRACE();
2139 /* Set IV parameters */
2140 session->iv.offset = aead_xform->iv.offset;
2141 session->iv.length = aead_xform->iv.length;
2142 session->ctxt_type = DPAA2_SEC_AEAD;
2144 /* For SEC AEAD only one descriptor is required */
2145 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2146 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
2147 RTE_CACHE_LINE_SIZE);
2149 DPAA2_SEC_ERR("No Memory for priv CTXT");
2153 priv->fle_pool = dev_priv->fle_pool;
2154 flc = &priv->flc_desc[0].flc;
2156 session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length,
2157 RTE_CACHE_LINE_SIZE);
2158 if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
2159 DPAA2_SEC_ERR("No Memory for aead key");
2163 memcpy(session->aead_key.data, aead_xform->key.data,
2164 aead_xform->key.length);
2166 session->digest_length = aead_xform->digest_length;
2167 session->aead_key.length = aead_xform->key.length;
2168 ctxt->auth_only_len = aead_xform->aad_length;
2170 aeaddata.key = (size_t)session->aead_key.data;
2171 aeaddata.keylen = session->aead_key.length;
2172 aeaddata.key_enc_flags = 0;
2173 aeaddata.key_type = RTA_DATA_IMM;
2175 switch (aead_xform->algo) {
2176 case RTE_CRYPTO_AEAD_AES_GCM:
2177 aeaddata.algtype = OP_ALG_ALGSEL_AES;
2178 aeaddata.algmode = OP_ALG_AAI_GCM;
2179 session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM;
2181 case RTE_CRYPTO_AEAD_AES_CCM:
2182 DPAA2_SEC_ERR("Crypto: Unsupported AEAD alg %u",
2186 DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
2190 session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
2193 priv->flc_desc[0].desc[0] = aeaddata.keylen;
2194 err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
2196 (unsigned int *)priv->flc_desc[0].desc,
2197 &priv->flc_desc[0].desc[1], 1);
2200 DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
2203 if (priv->flc_desc[0].desc[1] & 1) {
2204 aeaddata.key_type = RTA_DATA_IMM;
2206 aeaddata.key = DPAA2_VADDR_TO_IOVA(aeaddata.key);
2207 aeaddata.key_type = RTA_DATA_PTR;
2209 priv->flc_desc[0].desc[0] = 0;
2210 priv->flc_desc[0].desc[1] = 0;
2212 if (session->dir == DIR_ENC)
2213 bufsize = cnstr_shdsc_gcm_encap(
2214 priv->flc_desc[0].desc, 1, 0, SHR_NEVER,
2215 &aeaddata, session->iv.length,
2216 session->digest_length);
2218 bufsize = cnstr_shdsc_gcm_decap(
2219 priv->flc_desc[0].desc, 1, 0, SHR_NEVER,
2220 &aeaddata, session->iv.length,
2221 session->digest_length);
2223 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2227 flc->word1_sdl = (uint8_t)bufsize;
2228 session->ctxt = priv;
2229 #ifdef CAAM_DESC_DEBUG
2231 for (i = 0; i < bufsize; i++)
2232 DPAA2_SEC_DEBUG("DESC[%d]:0x%x\n",
2233 i, priv->flc_desc[0].desc[i]);
2238 rte_free(session->aead_key.data);
2245 dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
2246 struct rte_crypto_sym_xform *xform,
2247 dpaa2_sec_session *session)
2249 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2250 struct alginfo authdata, cipherdata;
2252 struct ctxt_priv *priv;
2253 struct sec_flow_context *flc;
2254 struct rte_crypto_cipher_xform *cipher_xform;
2255 struct rte_crypto_auth_xform *auth_xform;
2258 PMD_INIT_FUNC_TRACE();
2260 if (session->ext_params.aead_ctxt.auth_cipher_text) {
2261 cipher_xform = &xform->cipher;
2262 auth_xform = &xform->next->auth;
2263 session->ctxt_type =
2264 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2265 DPAA2_SEC_CIPHER_HASH : DPAA2_SEC_HASH_CIPHER;
2267 cipher_xform = &xform->next->cipher;
2268 auth_xform = &xform->auth;
2269 session->ctxt_type =
2270 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2271 DPAA2_SEC_HASH_CIPHER : DPAA2_SEC_CIPHER_HASH;
2274 /* Set IV parameters */
2275 session->iv.offset = cipher_xform->iv.offset;
2276 session->iv.length = cipher_xform->iv.length;
2278 /* For SEC AEAD only one descriptor is required */
2279 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2280 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
2281 RTE_CACHE_LINE_SIZE);
2283 DPAA2_SEC_ERR("No Memory for priv CTXT");
2287 priv->fle_pool = dev_priv->fle_pool;
2288 flc = &priv->flc_desc[0].flc;
2290 session->cipher_key.data = rte_zmalloc(NULL, cipher_xform->key.length,
2291 RTE_CACHE_LINE_SIZE);
2292 if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) {
2293 DPAA2_SEC_ERR("No Memory for cipher key");
2297 session->cipher_key.length = cipher_xform->key.length;
2298 session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length,
2299 RTE_CACHE_LINE_SIZE);
2300 if (session->auth_key.data == NULL && auth_xform->key.length > 0) {
2301 DPAA2_SEC_ERR("No Memory for auth key");
2302 rte_free(session->cipher_key.data);
2306 session->auth_key.length = auth_xform->key.length;
2307 memcpy(session->cipher_key.data, cipher_xform->key.data,
2308 cipher_xform->key.length);
2309 memcpy(session->auth_key.data, auth_xform->key.data,
2310 auth_xform->key.length);
2312 authdata.key = (size_t)session->auth_key.data;
2313 authdata.keylen = session->auth_key.length;
2314 authdata.key_enc_flags = 0;
2315 authdata.key_type = RTA_DATA_IMM;
2317 session->digest_length = auth_xform->digest_length;
2319 switch (auth_xform->algo) {
2320 case RTE_CRYPTO_AUTH_SHA1_HMAC:
2321 authdata.algtype = OP_ALG_ALGSEL_SHA1;
2322 authdata.algmode = OP_ALG_AAI_HMAC;
2323 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
2325 case RTE_CRYPTO_AUTH_MD5_HMAC:
2326 authdata.algtype = OP_ALG_ALGSEL_MD5;
2327 authdata.algmode = OP_ALG_AAI_HMAC;
2328 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
2330 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2331 authdata.algtype = OP_ALG_ALGSEL_SHA224;
2332 authdata.algmode = OP_ALG_AAI_HMAC;
2333 session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
2335 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2336 authdata.algtype = OP_ALG_ALGSEL_SHA256;
2337 authdata.algmode = OP_ALG_AAI_HMAC;
2338 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
2340 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2341 authdata.algtype = OP_ALG_ALGSEL_SHA384;
2342 authdata.algmode = OP_ALG_AAI_HMAC;
2343 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
2345 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2346 authdata.algtype = OP_ALG_ALGSEL_SHA512;
2347 authdata.algmode = OP_ALG_AAI_HMAC;
2348 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
2350 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2351 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2352 case RTE_CRYPTO_AUTH_NULL:
2353 case RTE_CRYPTO_AUTH_SHA1:
2354 case RTE_CRYPTO_AUTH_SHA256:
2355 case RTE_CRYPTO_AUTH_SHA512:
2356 case RTE_CRYPTO_AUTH_SHA224:
2357 case RTE_CRYPTO_AUTH_SHA384:
2358 case RTE_CRYPTO_AUTH_MD5:
2359 case RTE_CRYPTO_AUTH_AES_GMAC:
2360 case RTE_CRYPTO_AUTH_KASUMI_F9:
2361 case RTE_CRYPTO_AUTH_AES_CMAC:
2362 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2363 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2364 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
2368 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2372 cipherdata.key = (size_t)session->cipher_key.data;
2373 cipherdata.keylen = session->cipher_key.length;
2374 cipherdata.key_enc_flags = 0;
2375 cipherdata.key_type = RTA_DATA_IMM;
2377 switch (cipher_xform->algo) {
2378 case RTE_CRYPTO_CIPHER_AES_CBC:
2379 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2380 cipherdata.algmode = OP_ALG_AAI_CBC;
2381 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
2383 case RTE_CRYPTO_CIPHER_3DES_CBC:
2384 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
2385 cipherdata.algmode = OP_ALG_AAI_CBC;
2386 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
2388 case RTE_CRYPTO_CIPHER_AES_CTR:
2389 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2390 cipherdata.algmode = OP_ALG_AAI_CTR;
2391 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
2393 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2394 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
2395 case RTE_CRYPTO_CIPHER_NULL:
2396 case RTE_CRYPTO_CIPHER_3DES_ECB:
2397 case RTE_CRYPTO_CIPHER_AES_ECB:
2398 case RTE_CRYPTO_CIPHER_KASUMI_F8:
2399 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
2400 cipher_xform->algo);
2403 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2404 cipher_xform->algo);
2407 session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2410 priv->flc_desc[0].desc[0] = cipherdata.keylen;
2411 priv->flc_desc[0].desc[1] = authdata.keylen;
2412 err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
2414 (unsigned int *)priv->flc_desc[0].desc,
2415 &priv->flc_desc[0].desc[2], 2);
2418 DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
2421 if (priv->flc_desc[0].desc[2] & 1) {
2422 cipherdata.key_type = RTA_DATA_IMM;
2424 cipherdata.key = DPAA2_VADDR_TO_IOVA(cipherdata.key);
2425 cipherdata.key_type = RTA_DATA_PTR;
2427 if (priv->flc_desc[0].desc[2] & (1 << 1)) {
2428 authdata.key_type = RTA_DATA_IMM;
2430 authdata.key = DPAA2_VADDR_TO_IOVA(authdata.key);
2431 authdata.key_type = RTA_DATA_PTR;
2433 priv->flc_desc[0].desc[0] = 0;
2434 priv->flc_desc[0].desc[1] = 0;
2435 priv->flc_desc[0].desc[2] = 0;
2437 if (session->ctxt_type == DPAA2_SEC_CIPHER_HASH) {
2438 bufsize = cnstr_shdsc_authenc(priv->flc_desc[0].desc, 1,
2440 &cipherdata, &authdata,
2442 session->digest_length,
2445 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2449 DPAA2_SEC_ERR("Hash before cipher not supported");
2453 flc->word1_sdl = (uint8_t)bufsize;
2454 session->ctxt = priv;
2455 #ifdef CAAM_DESC_DEBUG
2457 for (i = 0; i < bufsize; i++)
2458 DPAA2_SEC_DEBUG("DESC[%d]:0x%x",
2459 i, priv->flc_desc[0].desc[i]);
2465 rte_free(session->cipher_key.data);
2466 rte_free(session->auth_key.data);
2472 dpaa2_sec_set_session_parameters(struct rte_cryptodev *dev,
2473 struct rte_crypto_sym_xform *xform, void *sess)
2475 dpaa2_sec_session *session = sess;
2478 PMD_INIT_FUNC_TRACE();
2480 if (unlikely(sess == NULL)) {
2481 DPAA2_SEC_ERR("Invalid session struct");
2485 memset(session, 0, sizeof(dpaa2_sec_session));
2486 /* Default IV length = 0 */
2487 session->iv.length = 0;
2490 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
2491 ret = dpaa2_sec_cipher_init(dev, xform, session);
2493 /* Authentication Only */
2494 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2495 xform->next == NULL) {
2496 ret = dpaa2_sec_auth_init(dev, xform, session);
2498 /* Cipher then Authenticate */
2499 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
2500 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2501 session->ext_params.aead_ctxt.auth_cipher_text = true;
2502 if (xform->cipher.algo == RTE_CRYPTO_CIPHER_NULL)
2503 ret = dpaa2_sec_auth_init(dev, xform, session);
2504 else if (xform->next->auth.algo == RTE_CRYPTO_AUTH_NULL)
2505 ret = dpaa2_sec_cipher_init(dev, xform, session);
2507 ret = dpaa2_sec_aead_chain_init(dev, xform, session);
2508 /* Authenticate then Cipher */
2509 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2510 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2511 session->ext_params.aead_ctxt.auth_cipher_text = false;
2512 if (xform->auth.algo == RTE_CRYPTO_AUTH_NULL)
2513 ret = dpaa2_sec_cipher_init(dev, xform, session);
2514 else if (xform->next->cipher.algo == RTE_CRYPTO_CIPHER_NULL)
2515 ret = dpaa2_sec_auth_init(dev, xform, session);
2517 ret = dpaa2_sec_aead_chain_init(dev, xform, session);
2518 /* AEAD operation for AES-GCM kind of Algorithms */
2519 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD &&
2520 xform->next == NULL) {
2521 ret = dpaa2_sec_aead_init(dev, xform, session);
2524 DPAA2_SEC_ERR("Invalid crypto type");
2531 #ifdef RTE_LIBRTE_SECURITY
2533 dpaa2_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
2534 dpaa2_sec_session *session,
2535 struct alginfo *aeaddata)
2537 PMD_INIT_FUNC_TRACE();
2539 session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length,
2540 RTE_CACHE_LINE_SIZE);
2541 if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
2542 DPAA2_SEC_ERR("No Memory for aead key");
2545 memcpy(session->aead_key.data, aead_xform->key.data,
2546 aead_xform->key.length);
2548 session->digest_length = aead_xform->digest_length;
2549 session->aead_key.length = aead_xform->key.length;
2551 aeaddata->key = (size_t)session->aead_key.data;
2552 aeaddata->keylen = session->aead_key.length;
2553 aeaddata->key_enc_flags = 0;
2554 aeaddata->key_type = RTA_DATA_IMM;
2556 switch (aead_xform->algo) {
2557 case RTE_CRYPTO_AEAD_AES_GCM:
2558 switch (session->digest_length) {
2560 aeaddata->algtype = OP_PCL_IPSEC_AES_GCM8;
2563 aeaddata->algtype = OP_PCL_IPSEC_AES_GCM12;
2566 aeaddata->algtype = OP_PCL_IPSEC_AES_GCM16;
2569 DPAA2_SEC_ERR("Crypto: Undefined GCM digest %d",
2570 session->digest_length);
2573 aeaddata->algmode = OP_ALG_AAI_GCM;
2574 session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM;
2576 case RTE_CRYPTO_AEAD_AES_CCM:
2577 switch (session->digest_length) {
2579 aeaddata->algtype = OP_PCL_IPSEC_AES_CCM8;
2582 aeaddata->algtype = OP_PCL_IPSEC_AES_CCM12;
2585 aeaddata->algtype = OP_PCL_IPSEC_AES_CCM16;
2588 DPAA2_SEC_ERR("Crypto: Undefined CCM digest %d",
2589 session->digest_length);
2592 aeaddata->algmode = OP_ALG_AAI_CCM;
2593 session->aead_alg = RTE_CRYPTO_AEAD_AES_CCM;
2596 DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
2600 session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
2607 dpaa2_sec_ipsec_proto_init(struct rte_crypto_cipher_xform *cipher_xform,
2608 struct rte_crypto_auth_xform *auth_xform,
2609 dpaa2_sec_session *session,
2610 struct alginfo *cipherdata,
2611 struct alginfo *authdata)
2614 session->cipher_key.data = rte_zmalloc(NULL,
2615 cipher_xform->key.length,
2616 RTE_CACHE_LINE_SIZE);
2617 if (session->cipher_key.data == NULL &&
2618 cipher_xform->key.length > 0) {
2619 DPAA2_SEC_ERR("No Memory for cipher key");
2623 session->cipher_key.length = cipher_xform->key.length;
2624 memcpy(session->cipher_key.data, cipher_xform->key.data,
2625 cipher_xform->key.length);
2626 session->cipher_alg = cipher_xform->algo;
2628 session->cipher_key.data = NULL;
2629 session->cipher_key.length = 0;
2630 session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
2634 session->auth_key.data = rte_zmalloc(NULL,
2635 auth_xform->key.length,
2636 RTE_CACHE_LINE_SIZE);
2637 if (session->auth_key.data == NULL &&
2638 auth_xform->key.length > 0) {
2639 DPAA2_SEC_ERR("No Memory for auth key");
2642 session->auth_key.length = auth_xform->key.length;
2643 memcpy(session->auth_key.data, auth_xform->key.data,
2644 auth_xform->key.length);
2645 session->auth_alg = auth_xform->algo;
2646 session->digest_length = auth_xform->digest_length;
2648 session->auth_key.data = NULL;
2649 session->auth_key.length = 0;
2650 session->auth_alg = RTE_CRYPTO_AUTH_NULL;
2653 authdata->key = (size_t)session->auth_key.data;
2654 authdata->keylen = session->auth_key.length;
2655 authdata->key_enc_flags = 0;
2656 authdata->key_type = RTA_DATA_IMM;
2657 switch (session->auth_alg) {
2658 case RTE_CRYPTO_AUTH_SHA1_HMAC:
2659 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA1_96;
2660 authdata->algmode = OP_ALG_AAI_HMAC;
2662 case RTE_CRYPTO_AUTH_MD5_HMAC:
2663 authdata->algtype = OP_PCL_IPSEC_HMAC_MD5_96;
2664 authdata->algmode = OP_ALG_AAI_HMAC;
2666 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2667 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_256_128;
2668 authdata->algmode = OP_ALG_AAI_HMAC;
2669 if (session->digest_length != 16)
2671 "+++Using sha256-hmac truncated len is non-standard,"
2672 "it will not work with lookaside proto");
2674 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2675 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_384_192;
2676 authdata->algmode = OP_ALG_AAI_HMAC;
2678 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2679 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_512_256;
2680 authdata->algmode = OP_ALG_AAI_HMAC;
2682 case RTE_CRYPTO_AUTH_AES_CMAC:
2683 authdata->algtype = OP_PCL_IPSEC_AES_CMAC_96;
2685 case RTE_CRYPTO_AUTH_NULL:
2686 authdata->algtype = OP_PCL_IPSEC_HMAC_NULL;
2688 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2689 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2690 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2691 case RTE_CRYPTO_AUTH_SHA1:
2692 case RTE_CRYPTO_AUTH_SHA256:
2693 case RTE_CRYPTO_AUTH_SHA512:
2694 case RTE_CRYPTO_AUTH_SHA224:
2695 case RTE_CRYPTO_AUTH_SHA384:
2696 case RTE_CRYPTO_AUTH_MD5:
2697 case RTE_CRYPTO_AUTH_AES_GMAC:
2698 case RTE_CRYPTO_AUTH_KASUMI_F9:
2699 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2700 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2701 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
2705 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2709 cipherdata->key = (size_t)session->cipher_key.data;
2710 cipherdata->keylen = session->cipher_key.length;
2711 cipherdata->key_enc_flags = 0;
2712 cipherdata->key_type = RTA_DATA_IMM;
2714 switch (session->cipher_alg) {
2715 case RTE_CRYPTO_CIPHER_AES_CBC:
2716 cipherdata->algtype = OP_PCL_IPSEC_AES_CBC;
2717 cipherdata->algmode = OP_ALG_AAI_CBC;
2719 case RTE_CRYPTO_CIPHER_3DES_CBC:
2720 cipherdata->algtype = OP_PCL_IPSEC_3DES;
2721 cipherdata->algmode = OP_ALG_AAI_CBC;
2723 case RTE_CRYPTO_CIPHER_AES_CTR:
2724 cipherdata->algtype = OP_PCL_IPSEC_AES_CTR;
2725 cipherdata->algmode = OP_ALG_AAI_CTR;
2727 case RTE_CRYPTO_CIPHER_NULL:
2728 cipherdata->algtype = OP_PCL_IPSEC_NULL;
2730 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2731 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
2732 case RTE_CRYPTO_CIPHER_3DES_ECB:
2733 case RTE_CRYPTO_CIPHER_AES_ECB:
2734 case RTE_CRYPTO_CIPHER_KASUMI_F8:
2735 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
2736 session->cipher_alg);
2739 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2740 session->cipher_alg);
2747 #ifdef RTE_LIBRTE_SECURITY_TEST
2748 static uint8_t aes_cbc_iv[] = {
2749 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2750 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
2754 dpaa2_sec_set_ipsec_session(struct rte_cryptodev *dev,
2755 struct rte_security_session_conf *conf,
2758 struct rte_security_ipsec_xform *ipsec_xform = &conf->ipsec;
2759 struct rte_crypto_cipher_xform *cipher_xform = NULL;
2760 struct rte_crypto_auth_xform *auth_xform = NULL;
2761 struct rte_crypto_aead_xform *aead_xform = NULL;
2762 dpaa2_sec_session *session = (dpaa2_sec_session *)sess;
2763 struct ctxt_priv *priv;
2764 struct alginfo authdata, cipherdata;
2766 struct sec_flow_context *flc;
2767 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2770 PMD_INIT_FUNC_TRACE();
2772 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2773 sizeof(struct ctxt_priv) +
2774 sizeof(struct sec_flc_desc),
2775 RTE_CACHE_LINE_SIZE);
2778 DPAA2_SEC_ERR("No memory for priv CTXT");
2782 priv->fle_pool = dev_priv->fle_pool;
2783 flc = &priv->flc_desc[0].flc;
2785 memset(session, 0, sizeof(dpaa2_sec_session));
2787 if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2788 cipher_xform = &conf->crypto_xform->cipher;
2789 if (conf->crypto_xform->next)
2790 auth_xform = &conf->crypto_xform->next->auth;
2791 ret = dpaa2_sec_ipsec_proto_init(cipher_xform, auth_xform,
2792 session, &cipherdata, &authdata);
2793 } else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2794 auth_xform = &conf->crypto_xform->auth;
2795 if (conf->crypto_xform->next)
2796 cipher_xform = &conf->crypto_xform->next->cipher;
2797 ret = dpaa2_sec_ipsec_proto_init(cipher_xform, auth_xform,
2798 session, &cipherdata, &authdata);
2799 } else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
2800 aead_xform = &conf->crypto_xform->aead;
2801 ret = dpaa2_sec_ipsec_aead_init(aead_xform,
2802 session, &cipherdata);
2803 authdata.keylen = 0;
2804 authdata.algtype = 0;
2806 DPAA2_SEC_ERR("XFORM not specified");
2811 DPAA2_SEC_ERR("Failed to process xform");
2815 session->ctxt_type = DPAA2_SEC_IPSEC;
2816 if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
2817 uint8_t *hdr = NULL;
2819 struct rte_ipv6_hdr ip6_hdr;
2820 struct ipsec_encap_pdb encap_pdb;
2822 flc->dhr = SEC_FLC_DHR_OUTBOUND;
2823 /* For Sec Proto only one descriptor is required. */
2824 memset(&encap_pdb, 0, sizeof(struct ipsec_encap_pdb));
2826 /* copy algo specific data to PDB */
2827 switch (cipherdata.algtype) {
2828 case OP_PCL_IPSEC_AES_CTR:
2829 encap_pdb.ctr.ctr_initial = 0x00000001;
2830 encap_pdb.ctr.ctr_nonce = ipsec_xform->salt;
2832 case OP_PCL_IPSEC_AES_GCM8:
2833 case OP_PCL_IPSEC_AES_GCM12:
2834 case OP_PCL_IPSEC_AES_GCM16:
2835 memcpy(encap_pdb.gcm.salt,
2836 (uint8_t *)&(ipsec_xform->salt), 4);
2840 encap_pdb.options = (IPVERSION << PDBNH_ESP_ENCAP_SHIFT) |
2841 PDBOPTS_ESP_OIHI_PDB_INL |
2843 PDBHMO_ESP_ENCAP_DTTL |
2845 if (ipsec_xform->options.esn)
2846 encap_pdb.options |= PDBOPTS_ESP_ESN;
2847 encap_pdb.spi = ipsec_xform->spi;
2848 session->dir = DIR_ENC;
2849 if (ipsec_xform->tunnel.type ==
2850 RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
2851 encap_pdb.ip_hdr_len = sizeof(struct ip);
2852 ip4_hdr.ip_v = IPVERSION;
2854 ip4_hdr.ip_len = rte_cpu_to_be_16(sizeof(ip4_hdr));
2855 ip4_hdr.ip_tos = ipsec_xform->tunnel.ipv4.dscp;
2858 ip4_hdr.ip_ttl = ipsec_xform->tunnel.ipv4.ttl;
2859 ip4_hdr.ip_p = IPPROTO_ESP;
2861 ip4_hdr.ip_src = ipsec_xform->tunnel.ipv4.src_ip;
2862 ip4_hdr.ip_dst = ipsec_xform->tunnel.ipv4.dst_ip;
2863 ip4_hdr.ip_sum = calc_chksum((uint16_t *)(void *)
2864 &ip4_hdr, sizeof(struct ip));
2865 hdr = (uint8_t *)&ip4_hdr;
2866 } else if (ipsec_xform->tunnel.type ==
2867 RTE_SECURITY_IPSEC_TUNNEL_IPV6) {
2868 ip6_hdr.vtc_flow = rte_cpu_to_be_32(
2869 DPAA2_IPv6_DEFAULT_VTC_FLOW |
2870 ((ipsec_xform->tunnel.ipv6.dscp <<
2871 RTE_IPV6_HDR_TC_SHIFT) &
2872 RTE_IPV6_HDR_TC_MASK) |
2873 ((ipsec_xform->tunnel.ipv6.flabel <<
2874 RTE_IPV6_HDR_FL_SHIFT) &
2875 RTE_IPV6_HDR_FL_MASK));
2876 /* Payload length will be updated by HW */
2877 ip6_hdr.payload_len = 0;
2878 ip6_hdr.hop_limits =
2879 ipsec_xform->tunnel.ipv6.hlimit;
2880 ip6_hdr.proto = (ipsec_xform->proto ==
2881 RTE_SECURITY_IPSEC_SA_PROTO_ESP) ?
2882 IPPROTO_ESP : IPPROTO_AH;
2883 memcpy(&ip6_hdr.src_addr,
2884 &ipsec_xform->tunnel.ipv6.src_addr, 16);
2885 memcpy(&ip6_hdr.dst_addr,
2886 &ipsec_xform->tunnel.ipv6.dst_addr, 16);
2887 encap_pdb.ip_hdr_len = sizeof(struct rte_ipv6_hdr);
2888 hdr = (uint8_t *)&ip6_hdr;
2891 bufsize = cnstr_shdsc_ipsec_new_encap(priv->flc_desc[0].desc,
2892 1, 0, SHR_SERIAL, &encap_pdb,
2893 hdr, &cipherdata, &authdata);
2894 } else if (ipsec_xform->direction ==
2895 RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
2896 struct ipsec_decap_pdb decap_pdb;
2898 flc->dhr = SEC_FLC_DHR_INBOUND;
2899 memset(&decap_pdb, 0, sizeof(struct ipsec_decap_pdb));
2900 /* copy algo specific data to PDB */
2901 switch (cipherdata.algtype) {
2902 case OP_PCL_IPSEC_AES_CTR:
2903 decap_pdb.ctr.ctr_initial = 0x00000001;
2904 decap_pdb.ctr.ctr_nonce = ipsec_xform->salt;
2906 case OP_PCL_IPSEC_AES_GCM8:
2907 case OP_PCL_IPSEC_AES_GCM12:
2908 case OP_PCL_IPSEC_AES_GCM16:
2909 memcpy(decap_pdb.gcm.salt,
2910 (uint8_t *)&(ipsec_xform->salt), 4);
2914 decap_pdb.options = (ipsec_xform->tunnel.type ==
2915 RTE_SECURITY_IPSEC_TUNNEL_IPV4) ?
2916 sizeof(struct ip) << 16 :
2917 sizeof(struct rte_ipv6_hdr) << 16;
2918 if (ipsec_xform->options.esn)
2919 decap_pdb.options |= PDBOPTS_ESP_ESN;
2921 if (ipsec_xform->replay_win_sz) {
2923 win_sz = rte_align32pow2(ipsec_xform->replay_win_sz);
2932 decap_pdb.options |= PDBOPTS_ESP_ARS32;
2935 decap_pdb.options |= PDBOPTS_ESP_ARS64;
2938 decap_pdb.options |= PDBOPTS_ESP_ARS128;
2941 session->dir = DIR_DEC;
2942 bufsize = cnstr_shdsc_ipsec_new_decap(priv->flc_desc[0].desc,
2944 &decap_pdb, &cipherdata, &authdata);
2949 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2953 flc->word1_sdl = (uint8_t)bufsize;
2955 /* Enable the stashing control bit */
2956 DPAA2_SET_FLC_RSC(flc);
2957 flc->word2_rflc_31_0 = lower_32_bits(
2958 (size_t)&(((struct dpaa2_sec_qp *)
2959 dev->data->queue_pairs[0])->rx_vq) | 0x14);
2960 flc->word3_rflc_63_32 = upper_32_bits(
2961 (size_t)&(((struct dpaa2_sec_qp *)
2962 dev->data->queue_pairs[0])->rx_vq));
2964 /* Set EWS bit i.e. enable write-safe */
2965 DPAA2_SET_FLC_EWS(flc);
2966 /* Set BS = 1 i.e reuse input buffers as output buffers */
2967 DPAA2_SET_FLC_REUSE_BS(flc);
2968 /* Set FF = 10; reuse input buffers if they provide sufficient space */
2969 DPAA2_SET_FLC_REUSE_FF(flc);
2971 session->ctxt = priv;
2975 rte_free(session->auth_key.data);
2976 rte_free(session->cipher_key.data);
2982 dpaa2_sec_set_pdcp_session(struct rte_cryptodev *dev,
2983 struct rte_security_session_conf *conf,
2986 struct rte_security_pdcp_xform *pdcp_xform = &conf->pdcp;
2987 struct rte_crypto_sym_xform *xform = conf->crypto_xform;
2988 struct rte_crypto_auth_xform *auth_xform = NULL;
2989 struct rte_crypto_cipher_xform *cipher_xform;
2990 dpaa2_sec_session *session = (dpaa2_sec_session *)sess;
2991 struct ctxt_priv *priv;
2992 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2993 struct alginfo authdata, cipherdata;
2994 struct alginfo *p_authdata = NULL;
2996 struct sec_flow_context *flc;
2997 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
3003 PMD_INIT_FUNC_TRACE();
3005 memset(session, 0, sizeof(dpaa2_sec_session));
3007 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
3008 sizeof(struct ctxt_priv) +
3009 sizeof(struct sec_flc_desc),
3010 RTE_CACHE_LINE_SIZE);
3013 DPAA2_SEC_ERR("No memory for priv CTXT");
3017 priv->fle_pool = dev_priv->fle_pool;
3018 flc = &priv->flc_desc[0].flc;
3020 /* find xfrm types */
3021 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
3022 cipher_xform = &xform->cipher;
3023 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
3024 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
3025 session->ext_params.aead_ctxt.auth_cipher_text = true;
3026 cipher_xform = &xform->cipher;
3027 auth_xform = &xform->next->auth;
3028 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
3029 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
3030 session->ext_params.aead_ctxt.auth_cipher_text = false;
3031 cipher_xform = &xform->next->cipher;
3032 auth_xform = &xform->auth;
3034 DPAA2_SEC_ERR("Invalid crypto type");
3038 session->ctxt_type = DPAA2_SEC_PDCP;
3040 session->cipher_key.data = rte_zmalloc(NULL,
3041 cipher_xform->key.length,
3042 RTE_CACHE_LINE_SIZE);
3043 if (session->cipher_key.data == NULL &&
3044 cipher_xform->key.length > 0) {
3045 DPAA2_SEC_ERR("No Memory for cipher key");
3049 session->cipher_key.length = cipher_xform->key.length;
3050 memcpy(session->cipher_key.data, cipher_xform->key.data,
3051 cipher_xform->key.length);
3053 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
3055 session->cipher_alg = cipher_xform->algo;
3057 session->cipher_key.data = NULL;
3058 session->cipher_key.length = 0;
3059 session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
3060 session->dir = DIR_ENC;
3063 session->pdcp.domain = pdcp_xform->domain;
3064 session->pdcp.bearer = pdcp_xform->bearer;
3065 session->pdcp.pkt_dir = pdcp_xform->pkt_dir;
3066 session->pdcp.sn_size = pdcp_xform->sn_size;
3067 session->pdcp.hfn = pdcp_xform->hfn;
3068 session->pdcp.hfn_threshold = pdcp_xform->hfn_threshold;
3069 session->pdcp.hfn_ovd = pdcp_xform->hfn_ovrd;
3070 /* hfv ovd offset location is stored in iv.offset value*/
3071 session->pdcp.hfn_ovd_offset = cipher_xform->iv.offset;
3073 cipherdata.key = (size_t)session->cipher_key.data;
3074 cipherdata.keylen = session->cipher_key.length;
3075 cipherdata.key_enc_flags = 0;
3076 cipherdata.key_type = RTA_DATA_IMM;
3078 switch (session->cipher_alg) {
3079 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
3080 cipherdata.algtype = PDCP_CIPHER_TYPE_SNOW;
3082 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
3083 cipherdata.algtype = PDCP_CIPHER_TYPE_ZUC;
3085 case RTE_CRYPTO_CIPHER_AES_CTR:
3086 cipherdata.algtype = PDCP_CIPHER_TYPE_AES;
3088 case RTE_CRYPTO_CIPHER_NULL:
3089 cipherdata.algtype = PDCP_CIPHER_TYPE_NULL;
3092 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
3093 session->cipher_alg);
3098 session->auth_key.data = rte_zmalloc(NULL,
3099 auth_xform->key.length,
3100 RTE_CACHE_LINE_SIZE);
3101 if (!session->auth_key.data &&
3102 auth_xform->key.length > 0) {
3103 DPAA2_SEC_ERR("No Memory for auth key");
3104 rte_free(session->cipher_key.data);
3108 session->auth_key.length = auth_xform->key.length;
3109 memcpy(session->auth_key.data, auth_xform->key.data,
3110 auth_xform->key.length);
3111 session->auth_alg = auth_xform->algo;
3113 session->auth_key.data = NULL;
3114 session->auth_key.length = 0;
3115 session->auth_alg = 0;
3117 authdata.key = (size_t)session->auth_key.data;
3118 authdata.keylen = session->auth_key.length;
3119 authdata.key_enc_flags = 0;
3120 authdata.key_type = RTA_DATA_IMM;
3122 if (session->auth_alg) {
3123 switch (session->auth_alg) {
3124 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
3125 authdata.algtype = PDCP_AUTH_TYPE_SNOW;
3127 case RTE_CRYPTO_AUTH_ZUC_EIA3:
3128 authdata.algtype = PDCP_AUTH_TYPE_ZUC;
3130 case RTE_CRYPTO_AUTH_AES_CMAC:
3131 authdata.algtype = PDCP_AUTH_TYPE_AES;
3133 case RTE_CRYPTO_AUTH_NULL:
3134 authdata.algtype = PDCP_AUTH_TYPE_NULL;
3137 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
3142 p_authdata = &authdata;
3143 } else if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
3144 DPAA2_SEC_ERR("Crypto: Integrity must for c-plane");
3148 if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
3149 if (session->dir == DIR_ENC)
3150 bufsize = cnstr_shdsc_pdcp_c_plane_encap(
3151 priv->flc_desc[0].desc, 1, swap,
3153 session->pdcp.sn_size,
3155 pdcp_xform->pkt_dir,
3156 pdcp_xform->hfn_threshold,
3157 &cipherdata, &authdata,
3159 else if (session->dir == DIR_DEC)
3160 bufsize = cnstr_shdsc_pdcp_c_plane_decap(
3161 priv->flc_desc[0].desc, 1, swap,
3163 session->pdcp.sn_size,
3165 pdcp_xform->pkt_dir,
3166 pdcp_xform->hfn_threshold,
3167 &cipherdata, &authdata,
3170 if (session->dir == DIR_ENC)
3171 bufsize = cnstr_shdsc_pdcp_u_plane_encap(
3172 priv->flc_desc[0].desc, 1, swap,
3173 session->pdcp.sn_size,
3176 pdcp_xform->pkt_dir,
3177 pdcp_xform->hfn_threshold,
3178 &cipherdata, p_authdata, 0);
3179 else if (session->dir == DIR_DEC)
3180 bufsize = cnstr_shdsc_pdcp_u_plane_decap(
3181 priv->flc_desc[0].desc, 1, swap,
3182 session->pdcp.sn_size,
3185 pdcp_xform->pkt_dir,
3186 pdcp_xform->hfn_threshold,
3187 &cipherdata, p_authdata, 0);
3191 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
3195 /* Enable the stashing control bit */
3196 DPAA2_SET_FLC_RSC(flc);
3197 flc->word2_rflc_31_0 = lower_32_bits(
3198 (size_t)&(((struct dpaa2_sec_qp *)
3199 dev->data->queue_pairs[0])->rx_vq) | 0x14);
3200 flc->word3_rflc_63_32 = upper_32_bits(
3201 (size_t)&(((struct dpaa2_sec_qp *)
3202 dev->data->queue_pairs[0])->rx_vq));
3204 flc->word1_sdl = (uint8_t)bufsize;
3206 /* TODO - check the perf impact or
3207 * align as per descriptor type
3208 * Set EWS bit i.e. enable write-safe
3209 * DPAA2_SET_FLC_EWS(flc);
3212 /* Set BS = 1 i.e reuse input buffers as output buffers */
3213 DPAA2_SET_FLC_REUSE_BS(flc);
3214 /* Set FF = 10; reuse input buffers if they provide sufficient space */
3215 DPAA2_SET_FLC_REUSE_FF(flc);
3217 session->ctxt = priv;
3221 rte_free(session->auth_key.data);
3222 rte_free(session->cipher_key.data);
3228 dpaa2_sec_security_session_create(void *dev,
3229 struct rte_security_session_conf *conf,
3230 struct rte_security_session *sess,
3231 struct rte_mempool *mempool)
3233 void *sess_private_data;
3234 struct rte_cryptodev *cdev = (struct rte_cryptodev *)dev;
3237 if (rte_mempool_get(mempool, &sess_private_data)) {
3238 DPAA2_SEC_ERR("Couldn't get object from session mempool");
3242 switch (conf->protocol) {
3243 case RTE_SECURITY_PROTOCOL_IPSEC:
3244 ret = dpaa2_sec_set_ipsec_session(cdev, conf,
3247 case RTE_SECURITY_PROTOCOL_MACSEC:
3249 case RTE_SECURITY_PROTOCOL_PDCP:
3250 ret = dpaa2_sec_set_pdcp_session(cdev, conf,
3257 DPAA2_SEC_ERR("Failed to configure session parameters");
3258 /* Return session to mempool */
3259 rte_mempool_put(mempool, sess_private_data);
3263 set_sec_session_private_data(sess, sess_private_data);
3268 /** Clear the memory of session so it doesn't leave key material behind */
3270 dpaa2_sec_security_session_destroy(void *dev __rte_unused,
3271 struct rte_security_session *sess)
3273 PMD_INIT_FUNC_TRACE();
3274 void *sess_priv = get_sec_session_private_data(sess);
3276 dpaa2_sec_session *s = (dpaa2_sec_session *)sess_priv;
3279 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
3282 rte_free(s->cipher_key.data);
3283 rte_free(s->auth_key.data);
3284 memset(s, 0, sizeof(dpaa2_sec_session));
3285 set_sec_session_private_data(sess, NULL);
3286 rte_mempool_put(sess_mp, sess_priv);
3292 dpaa2_sec_sym_session_configure(struct rte_cryptodev *dev,
3293 struct rte_crypto_sym_xform *xform,
3294 struct rte_cryptodev_sym_session *sess,
3295 struct rte_mempool *mempool)
3297 void *sess_private_data;
3300 if (rte_mempool_get(mempool, &sess_private_data)) {
3301 DPAA2_SEC_ERR("Couldn't get object from session mempool");
3305 ret = dpaa2_sec_set_session_parameters(dev, xform, sess_private_data);
3307 DPAA2_SEC_ERR("Failed to configure session parameters");
3308 /* Return session to mempool */
3309 rte_mempool_put(mempool, sess_private_data);
3313 set_sym_session_private_data(sess, dev->driver_id,
3319 /** Clear the memory of session so it doesn't leave key material behind */
3321 dpaa2_sec_sym_session_clear(struct rte_cryptodev *dev,
3322 struct rte_cryptodev_sym_session *sess)
3324 PMD_INIT_FUNC_TRACE();
3325 uint8_t index = dev->driver_id;
3326 void *sess_priv = get_sym_session_private_data(sess, index);
3327 dpaa2_sec_session *s = (dpaa2_sec_session *)sess_priv;
3331 rte_free(s->cipher_key.data);
3332 rte_free(s->auth_key.data);
3333 memset(s, 0, sizeof(dpaa2_sec_session));
3334 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
3335 set_sym_session_private_data(sess, index, NULL);
3336 rte_mempool_put(sess_mp, sess_priv);
3341 dpaa2_sec_dev_configure(struct rte_cryptodev *dev __rte_unused,
3342 struct rte_cryptodev_config *config __rte_unused)
3344 PMD_INIT_FUNC_TRACE();
3350 dpaa2_sec_dev_start(struct rte_cryptodev *dev)
3352 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3353 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3354 struct dpseci_attr attr;
3355 struct dpaa2_queue *dpaa2_q;
3356 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3357 dev->data->queue_pairs;
3358 struct dpseci_rx_queue_attr rx_attr;
3359 struct dpseci_tx_queue_attr tx_attr;
3362 PMD_INIT_FUNC_TRACE();
3364 memset(&attr, 0, sizeof(struct dpseci_attr));
3366 ret = dpseci_enable(dpseci, CMD_PRI_LOW, priv->token);
3368 DPAA2_SEC_ERR("DPSECI with HW_ID = %d ENABLE FAILED",
3370 goto get_attr_failure;
3372 ret = dpseci_get_attributes(dpseci, CMD_PRI_LOW, priv->token, &attr);
3374 DPAA2_SEC_ERR("DPSEC ATTRIBUTE READ FAILED, disabling DPSEC");
3375 goto get_attr_failure;
3377 for (i = 0; i < attr.num_rx_queues && qp[i]; i++) {
3378 dpaa2_q = &qp[i]->rx_vq;
3379 dpseci_get_rx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
3381 dpaa2_q->fqid = rx_attr.fqid;
3382 DPAA2_SEC_DEBUG("rx_fqid: %d", dpaa2_q->fqid);
3384 for (i = 0; i < attr.num_tx_queues && qp[i]; i++) {
3385 dpaa2_q = &qp[i]->tx_vq;
3386 dpseci_get_tx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
3388 dpaa2_q->fqid = tx_attr.fqid;
3389 DPAA2_SEC_DEBUG("tx_fqid: %d", dpaa2_q->fqid);
3394 dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
3399 dpaa2_sec_dev_stop(struct rte_cryptodev *dev)
3401 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3402 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3405 PMD_INIT_FUNC_TRACE();
3407 ret = dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
3409 DPAA2_SEC_ERR("Failure in disabling dpseci %d device",
3414 ret = dpseci_reset(dpseci, CMD_PRI_LOW, priv->token);
3416 DPAA2_SEC_ERR("SEC Device cannot be reset:Error = %0x", ret);
3422 dpaa2_sec_dev_close(struct rte_cryptodev *dev)
3424 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3425 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3428 PMD_INIT_FUNC_TRACE();
3430 /* Function is reverse of dpaa2_sec_dev_init.
3431 * It does the following:
3432 * 1. Detach a DPSECI from attached resources i.e. buffer pools, dpbp_id
3433 * 2. Close the DPSECI device
3434 * 3. Free the allocated resources.
3437 /*Close the device at underlying layer*/
3438 ret = dpseci_close(dpseci, CMD_PRI_LOW, priv->token);
3440 DPAA2_SEC_ERR("Failure closing dpseci device: err(%d)", ret);
3444 /*Free the allocated memory for ethernet private data and dpseci*/
3452 dpaa2_sec_dev_infos_get(struct rte_cryptodev *dev,
3453 struct rte_cryptodev_info *info)
3455 struct dpaa2_sec_dev_private *internals = dev->data->dev_private;
3457 PMD_INIT_FUNC_TRACE();
3459 info->max_nb_queue_pairs = internals->max_nb_queue_pairs;
3460 info->feature_flags = dev->feature_flags;
3461 info->capabilities = dpaa2_sec_capabilities;
3462 /* No limit of number of sessions */
3463 info->sym.max_nb_sessions = 0;
3464 info->driver_id = cryptodev_driver_id;
3469 void dpaa2_sec_stats_get(struct rte_cryptodev *dev,
3470 struct rte_cryptodev_stats *stats)
3472 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3473 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3474 struct dpseci_sec_counters counters = {0};
3475 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3476 dev->data->queue_pairs;
3479 PMD_INIT_FUNC_TRACE();
3480 if (stats == NULL) {
3481 DPAA2_SEC_ERR("Invalid stats ptr NULL");
3484 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
3485 if (qp[i] == NULL) {
3486 DPAA2_SEC_DEBUG("Uninitialised queue pair");
3490 stats->enqueued_count += qp[i]->tx_vq.tx_pkts;
3491 stats->dequeued_count += qp[i]->rx_vq.rx_pkts;
3492 stats->enqueue_err_count += qp[i]->tx_vq.err_pkts;
3493 stats->dequeue_err_count += qp[i]->rx_vq.err_pkts;
3496 ret = dpseci_get_sec_counters(dpseci, CMD_PRI_LOW, priv->token,
3499 DPAA2_SEC_ERR("SEC counters failed");
3501 DPAA2_SEC_INFO("dpseci hardware stats:"
3502 "\n\tNum of Requests Dequeued = %" PRIu64
3503 "\n\tNum of Outbound Encrypt Requests = %" PRIu64
3504 "\n\tNum of Inbound Decrypt Requests = %" PRIu64
3505 "\n\tNum of Outbound Bytes Encrypted = %" PRIu64
3506 "\n\tNum of Outbound Bytes Protected = %" PRIu64
3507 "\n\tNum of Inbound Bytes Decrypted = %" PRIu64
3508 "\n\tNum of Inbound Bytes Validated = %" PRIu64,
3509 counters.dequeued_requests,
3510 counters.ob_enc_requests,
3511 counters.ib_dec_requests,
3512 counters.ob_enc_bytes,
3513 counters.ob_prot_bytes,
3514 counters.ib_dec_bytes,
3515 counters.ib_valid_bytes);
3520 void dpaa2_sec_stats_reset(struct rte_cryptodev *dev)
3523 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3524 (dev->data->queue_pairs);
3526 PMD_INIT_FUNC_TRACE();
3528 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
3529 if (qp[i] == NULL) {
3530 DPAA2_SEC_DEBUG("Uninitialised queue pair");
3533 qp[i]->tx_vq.rx_pkts = 0;
3534 qp[i]->tx_vq.tx_pkts = 0;
3535 qp[i]->tx_vq.err_pkts = 0;
3536 qp[i]->rx_vq.rx_pkts = 0;
3537 qp[i]->rx_vq.tx_pkts = 0;
3538 qp[i]->rx_vq.err_pkts = 0;
3542 static void __attribute__((hot))
3543 dpaa2_sec_process_parallel_event(struct qbman_swp *swp,
3544 const struct qbman_fd *fd,
3545 const struct qbman_result *dq,
3546 struct dpaa2_queue *rxq,
3547 struct rte_event *ev)
3549 /* Prefetching mbuf */
3550 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-
3551 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size));
3553 /* Prefetching ipsec crypto_op stored in priv data of mbuf */
3554 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-64));
3556 ev->flow_id = rxq->ev.flow_id;
3557 ev->sub_event_type = rxq->ev.sub_event_type;
3558 ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
3559 ev->op = RTE_EVENT_OP_NEW;
3560 ev->sched_type = rxq->ev.sched_type;
3561 ev->queue_id = rxq->ev.queue_id;
3562 ev->priority = rxq->ev.priority;
3563 ev->event_ptr = sec_fd_to_mbuf(fd);
3565 qbman_swp_dqrr_consume(swp, dq);
3568 dpaa2_sec_process_atomic_event(struct qbman_swp *swp __attribute__((unused)),
3569 const struct qbman_fd *fd,
3570 const struct qbman_result *dq,
3571 struct dpaa2_queue *rxq,
3572 struct rte_event *ev)
3575 struct rte_crypto_op *crypto_op = (struct rte_crypto_op *)ev->event_ptr;
3576 /* Prefetching mbuf */
3577 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-
3578 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size));
3580 /* Prefetching ipsec crypto_op stored in priv data of mbuf */
3581 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-64));
3583 ev->flow_id = rxq->ev.flow_id;
3584 ev->sub_event_type = rxq->ev.sub_event_type;
3585 ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
3586 ev->op = RTE_EVENT_OP_NEW;
3587 ev->sched_type = rxq->ev.sched_type;
3588 ev->queue_id = rxq->ev.queue_id;
3589 ev->priority = rxq->ev.priority;
3591 ev->event_ptr = sec_fd_to_mbuf(fd);
3592 dqrr_index = qbman_get_dqrr_idx(dq);
3593 crypto_op->sym->m_src->seqn = dqrr_index + 1;
3594 DPAA2_PER_LCORE_DQRR_SIZE++;
3595 DPAA2_PER_LCORE_DQRR_HELD |= 1 << dqrr_index;
3596 DPAA2_PER_LCORE_DQRR_MBUF(dqrr_index) = crypto_op->sym->m_src;
3600 dpaa2_sec_eventq_attach(const struct rte_cryptodev *dev,
3602 struct dpaa2_dpcon_dev *dpcon,
3603 const struct rte_event *event)
3605 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3606 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3607 struct dpaa2_sec_qp *qp = dev->data->queue_pairs[qp_id];
3608 struct dpseci_rx_queue_cfg cfg;
3612 if (event->sched_type == RTE_SCHED_TYPE_PARALLEL)
3613 qp->rx_vq.cb = dpaa2_sec_process_parallel_event;
3614 else if (event->sched_type == RTE_SCHED_TYPE_ATOMIC)
3615 qp->rx_vq.cb = dpaa2_sec_process_atomic_event;
3619 priority = (RTE_EVENT_DEV_PRIORITY_LOWEST / event->priority) *
3620 (dpcon->num_priorities - 1);
3622 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
3623 cfg.options = DPSECI_QUEUE_OPT_DEST;
3624 cfg.dest_cfg.dest_type = DPSECI_DEST_DPCON;
3625 cfg.dest_cfg.dest_id = dpcon->dpcon_id;
3626 cfg.dest_cfg.priority = priority;
3628 cfg.options |= DPSECI_QUEUE_OPT_USER_CTX;
3629 cfg.user_ctx = (size_t)(qp);
3630 if (event->sched_type == RTE_SCHED_TYPE_ATOMIC) {
3631 cfg.options |= DPSECI_QUEUE_OPT_ORDER_PRESERVATION;
3632 cfg.order_preservation_en = 1;
3634 ret = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
3637 RTE_LOG(ERR, PMD, "Error in dpseci_set_queue: ret: %d\n", ret);
3641 memcpy(&qp->rx_vq.ev, event, sizeof(struct rte_event));
3647 dpaa2_sec_eventq_detach(const struct rte_cryptodev *dev,
3650 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3651 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3652 struct dpseci_rx_queue_cfg cfg;
3655 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
3656 cfg.options = DPSECI_QUEUE_OPT_DEST;
3657 cfg.dest_cfg.dest_type = DPSECI_DEST_NONE;
3659 ret = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
3662 RTE_LOG(ERR, PMD, "Error in dpseci_set_queue: ret: %d\n", ret);
3667 static struct rte_cryptodev_ops crypto_ops = {
3668 .dev_configure = dpaa2_sec_dev_configure,
3669 .dev_start = dpaa2_sec_dev_start,
3670 .dev_stop = dpaa2_sec_dev_stop,
3671 .dev_close = dpaa2_sec_dev_close,
3672 .dev_infos_get = dpaa2_sec_dev_infos_get,
3673 .stats_get = dpaa2_sec_stats_get,
3674 .stats_reset = dpaa2_sec_stats_reset,
3675 .queue_pair_setup = dpaa2_sec_queue_pair_setup,
3676 .queue_pair_release = dpaa2_sec_queue_pair_release,
3677 .queue_pair_count = dpaa2_sec_queue_pair_count,
3678 .sym_session_get_size = dpaa2_sec_sym_session_get_size,
3679 .sym_session_configure = dpaa2_sec_sym_session_configure,
3680 .sym_session_clear = dpaa2_sec_sym_session_clear,
3683 #ifdef RTE_LIBRTE_SECURITY
3684 static const struct rte_security_capability *
3685 dpaa2_sec_capabilities_get(void *device __rte_unused)
3687 return dpaa2_sec_security_cap;
3690 static const struct rte_security_ops dpaa2_sec_security_ops = {
3691 .session_create = dpaa2_sec_security_session_create,
3692 .session_update = NULL,
3693 .session_stats_get = NULL,
3694 .session_destroy = dpaa2_sec_security_session_destroy,
3695 .set_pkt_metadata = NULL,
3696 .capabilities_get = dpaa2_sec_capabilities_get
3701 dpaa2_sec_uninit(const struct rte_cryptodev *dev)
3703 struct dpaa2_sec_dev_private *internals = dev->data->dev_private;
3705 rte_free(dev->security_ctx);
3707 rte_mempool_free(internals->fle_pool);
3709 DPAA2_SEC_INFO("Closing DPAA2_SEC device %s on numa socket %u",
3710 dev->data->name, rte_socket_id());
3716 dpaa2_sec_dev_init(struct rte_cryptodev *cryptodev)
3718 struct dpaa2_sec_dev_private *internals;
3719 struct rte_device *dev = cryptodev->device;
3720 struct rte_dpaa2_device *dpaa2_dev;
3721 #ifdef RTE_LIBRTE_SECURITY
3722 struct rte_security_ctx *security_instance;
3724 struct fsl_mc_io *dpseci;
3726 struct dpseci_attr attr;
3730 PMD_INIT_FUNC_TRACE();
3731 dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
3732 if (dpaa2_dev == NULL) {
3733 DPAA2_SEC_ERR("DPAA2 SEC device not found");
3736 hw_id = dpaa2_dev->object_id;
3738 cryptodev->driver_id = cryptodev_driver_id;
3739 cryptodev->dev_ops = &crypto_ops;
3741 cryptodev->enqueue_burst = dpaa2_sec_enqueue_burst;
3742 cryptodev->dequeue_burst = dpaa2_sec_dequeue_burst;
3743 cryptodev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
3744 RTE_CRYPTODEV_FF_HW_ACCELERATED |
3745 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
3746 RTE_CRYPTODEV_FF_SECURITY |
3747 RTE_CRYPTODEV_FF_IN_PLACE_SGL |
3748 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT |
3749 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
3750 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT |
3751 RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT;
3753 internals = cryptodev->data->dev_private;
3756 * For secondary processes, we don't initialise any further as primary
3757 * has already done this work. Only check we don't need a different
3760 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
3761 DPAA2_SEC_DEBUG("Device already init by primary process");
3764 #ifdef RTE_LIBRTE_SECURITY
3765 /* Initialize security_ctx only for primary process*/
3766 security_instance = rte_malloc("rte_security_instances_ops",
3767 sizeof(struct rte_security_ctx), 0);
3768 if (security_instance == NULL)
3770 security_instance->device = (void *)cryptodev;
3771 security_instance->ops = &dpaa2_sec_security_ops;
3772 security_instance->sess_cnt = 0;
3773 cryptodev->security_ctx = security_instance;
3775 /*Open the rte device via MC and save the handle for further use*/
3776 dpseci = (struct fsl_mc_io *)rte_calloc(NULL, 1,
3777 sizeof(struct fsl_mc_io), 0);
3780 "Error in allocating the memory for dpsec object");
3783 dpseci->regs = rte_mcp_ptr_list[0];
3785 retcode = dpseci_open(dpseci, CMD_PRI_LOW, hw_id, &token);
3787 DPAA2_SEC_ERR("Cannot open the dpsec device: Error = %x",
3791 retcode = dpseci_get_attributes(dpseci, CMD_PRI_LOW, token, &attr);
3794 "Cannot get dpsec device attributed: Error = %x",
3798 snprintf(cryptodev->data->name, sizeof(cryptodev->data->name),
3801 internals->max_nb_queue_pairs = attr.num_tx_queues;
3802 cryptodev->data->nb_queue_pairs = internals->max_nb_queue_pairs;
3803 internals->hw = dpseci;
3804 internals->token = token;
3806 snprintf(str, sizeof(str), "sec_fle_pool_p%d_%d",
3807 getpid(), cryptodev->data->dev_id);
3808 internals->fle_pool = rte_mempool_create((const char *)str,
3811 FLE_POOL_CACHE_SIZE, 0,
3812 NULL, NULL, NULL, NULL,
3814 if (!internals->fle_pool) {
3815 DPAA2_SEC_ERR("Mempool (%s) creation failed", str);
3819 DPAA2_SEC_INFO("driver %s: created", cryptodev->data->name);
3823 DPAA2_SEC_ERR("driver %s: create failed", cryptodev->data->name);
3825 /* dpaa2_sec_uninit(crypto_dev_name); */
3830 cryptodev_dpaa2_sec_probe(struct rte_dpaa2_driver *dpaa2_drv __rte_unused,
3831 struct rte_dpaa2_device *dpaa2_dev)
3833 struct rte_cryptodev *cryptodev;
3834 char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
3838 snprintf(cryptodev_name, sizeof(cryptodev_name), "dpsec-%d",
3839 dpaa2_dev->object_id);
3841 cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
3842 if (cryptodev == NULL)
3845 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
3846 cryptodev->data->dev_private = rte_zmalloc_socket(
3847 "cryptodev private structure",
3848 sizeof(struct dpaa2_sec_dev_private),
3849 RTE_CACHE_LINE_SIZE,
3852 if (cryptodev->data->dev_private == NULL)
3853 rte_panic("Cannot allocate memzone for private "
3857 dpaa2_dev->cryptodev = cryptodev;
3858 cryptodev->device = &dpaa2_dev->device;
3860 /* init user callbacks */
3861 TAILQ_INIT(&(cryptodev->link_intr_cbs));
3863 if (dpaa2_svr_family == SVR_LX2160A)
3864 rta_set_sec_era(RTA_SEC_ERA_10);
3866 DPAA2_SEC_INFO("2-SEC ERA is %d", rta_get_sec_era());
3868 /* Invoke PMD device initialization function */
3869 retval = dpaa2_sec_dev_init(cryptodev);
3873 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
3874 rte_free(cryptodev->data->dev_private);
3876 cryptodev->attached = RTE_CRYPTODEV_DETACHED;
3882 cryptodev_dpaa2_sec_remove(struct rte_dpaa2_device *dpaa2_dev)
3884 struct rte_cryptodev *cryptodev;
3887 cryptodev = dpaa2_dev->cryptodev;
3888 if (cryptodev == NULL)
3891 ret = dpaa2_sec_uninit(cryptodev);
3895 return rte_cryptodev_pmd_destroy(cryptodev);
3898 static struct rte_dpaa2_driver rte_dpaa2_sec_driver = {
3899 .drv_flags = RTE_DPAA2_DRV_IOVA_AS_VA,
3900 .drv_type = DPAA2_CRYPTO,
3902 .name = "DPAA2 SEC PMD"
3904 .probe = cryptodev_dpaa2_sec_probe,
3905 .remove = cryptodev_dpaa2_sec_remove,
3908 static struct cryptodev_driver dpaa2_sec_crypto_drv;
3910 RTE_PMD_REGISTER_DPAA2(CRYPTODEV_NAME_DPAA2_SEC_PMD, rte_dpaa2_sec_driver);
3911 RTE_PMD_REGISTER_CRYPTO_DRIVER(dpaa2_sec_crypto_drv,
3912 rte_dpaa2_sec_driver.driver, cryptodev_driver_id);
3914 RTE_INIT(dpaa2_sec_init_log)
3916 /* Bus level logs */
3917 dpaa2_logtype_sec = rte_log_register("pmd.crypto.dpaa2");
3918 if (dpaa2_logtype_sec >= 0)
3919 rte_log_set_level(dpaa2_logtype_sec, RTE_LOG_NOTICE);