1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
4 * Copyright 2016-2022 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 <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>
31 #include <rte_hexdump.h>
33 #include "dpaa2_sec_priv.h"
34 #include "dpaa2_sec_event.h"
35 #include "dpaa2_sec_logs.h"
37 /* RTA header files */
38 #include <desc/ipsec.h>
39 #include <desc/pdcp.h>
40 #include <desc/sdap.h>
41 #include <desc/algo.h>
43 /* Minimum job descriptor consists of a oneword job descriptor HEADER and
44 * a pointer to the shared descriptor
46 #define MIN_JOB_DESC_SIZE (CAAM_CMD_SZ + CAAM_PTR_SZ)
47 #define FSL_VENDOR_ID 0x1957
48 #define FSL_DEVICE_ID 0x410
49 #define FSL_SUBSYSTEM_SEC 1
50 #define FSL_MC_DPSECI_DEVID 3
54 #define DRIVER_DUMP_MODE "drv_dump_mode"
55 #define DRIVER_STRICT_ORDER "drv_strict_order"
57 /* DPAA2_SEC_DP_DUMP levels */
58 enum dpaa2_sec_dump_levels {
60 DPAA2_SEC_DP_ERR_DUMP,
61 DPAA2_SEC_DP_FULL_DUMP
64 uint8_t cryptodev_driver_id;
65 uint8_t dpaa2_sec_dp_dump = DPAA2_SEC_DP_ERR_DUMP;
68 free_fle(const struct qbman_fd *fd)
70 struct qbman_fle *fle;
71 struct rte_crypto_op *op;
72 struct ctxt_priv *priv;
74 #ifdef RTE_LIB_SECURITY
75 if (DPAA2_FD_GET_FORMAT(fd) == qbman_fd_single)
78 fle = (struct qbman_fle *)DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd));
79 op = (struct rte_crypto_op *)DPAA2_GET_FLE_ADDR((fle - 1));
80 /* free the fle memory */
81 if (likely(rte_pktmbuf_is_contiguous(op->sym->m_src))) {
82 priv = (struct ctxt_priv *)(size_t)DPAA2_GET_FLE_CTXT(fle - 1);
83 rte_mempool_put(priv->fle_pool, (void *)(fle-1));
85 rte_free((void *)(fle-1));
88 #ifdef RTE_LIB_SECURITY
90 build_proto_compound_sg_fd(dpaa2_sec_session *sess,
91 struct rte_crypto_op *op,
92 struct qbman_fd *fd, uint16_t bpid)
94 struct rte_crypto_sym_op *sym_op = op->sym;
95 struct ctxt_priv *priv = sess->ctxt;
96 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
97 struct sec_flow_context *flc;
98 struct rte_mbuf *mbuf;
99 uint32_t in_len = 0, out_len = 0;
102 mbuf = sym_op->m_dst;
104 mbuf = sym_op->m_src;
106 /* first FLE entry used to store mbuf and session ctxt */
107 fle = (struct qbman_fle *)rte_malloc(NULL,
108 FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
109 RTE_CACHE_LINE_SIZE);
110 if (unlikely(!fle)) {
111 DPAA2_SEC_DP_ERR("Proto:SG: Memory alloc failed for SGE");
114 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
115 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
116 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
118 /* Save the shared descriptor */
119 flc = &priv->flc_desc[0].flc;
125 if (likely(bpid < MAX_BPID)) {
126 DPAA2_SET_FD_BPID(fd, bpid);
127 DPAA2_SET_FLE_BPID(op_fle, bpid);
128 DPAA2_SET_FLE_BPID(ip_fle, bpid);
130 DPAA2_SET_FD_IVP(fd);
131 DPAA2_SET_FLE_IVP(op_fle);
132 DPAA2_SET_FLE_IVP(ip_fle);
135 /* Configure FD as a FRAME LIST */
136 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
137 DPAA2_SET_FD_COMPOUND_FMT(fd);
138 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
140 /* Configure Output FLE with Scatter/Gather Entry */
141 DPAA2_SET_FLE_SG_EXT(op_fle);
142 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
144 /* Configure Output SGE for Encap/Decap */
145 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
146 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
149 sge->length = mbuf->data_len;
150 out_len += sge->length;
153 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
154 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
156 /* using buf_len for last buf - so that extra data can be added */
157 sge->length = mbuf->buf_len - mbuf->data_off;
158 out_len += sge->length;
160 DPAA2_SET_FLE_FIN(sge);
161 op_fle->length = out_len;
164 mbuf = sym_op->m_src;
166 /* Configure Input FLE with Scatter/Gather Entry */
167 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
168 DPAA2_SET_FLE_SG_EXT(ip_fle);
169 DPAA2_SET_FLE_FIN(ip_fle);
171 /* Configure input SGE for Encap/Decap */
172 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
173 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
174 sge->length = mbuf->data_len;
175 in_len += sge->length;
181 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
182 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
183 sge->length = mbuf->data_len;
184 in_len += sge->length;
187 ip_fle->length = in_len;
188 DPAA2_SET_FLE_FIN(sge);
190 /* In case of PDCP, per packet HFN is stored in
191 * mbuf priv after sym_op.
193 if (sess->ctxt_type == DPAA2_SEC_PDCP && sess->pdcp.hfn_ovd) {
194 uint32_t hfn_ovd = *(uint32_t *)((uint8_t *)op +
195 sess->pdcp.hfn_ovd_offset);
196 /*enable HFN override override */
197 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, hfn_ovd);
198 DPAA2_SET_FLE_INTERNAL_JD(op_fle, hfn_ovd);
199 DPAA2_SET_FD_INTERNAL_JD(fd, hfn_ovd);
201 DPAA2_SET_FD_LEN(fd, ip_fle->length);
207 build_proto_compound_fd(dpaa2_sec_session *sess,
208 struct rte_crypto_op *op,
209 struct qbman_fd *fd, uint16_t bpid)
211 struct rte_crypto_sym_op *sym_op = op->sym;
212 struct ctxt_priv *priv = sess->ctxt;
213 struct qbman_fle *fle, *ip_fle, *op_fle;
214 struct sec_flow_context *flc;
215 struct rte_mbuf *src_mbuf = sym_op->m_src;
216 struct rte_mbuf *dst_mbuf = sym_op->m_dst;
222 /* Save the shared descriptor */
223 flc = &priv->flc_desc[0].flc;
225 /* we are using the first FLE entry to store Mbuf */
226 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
228 DPAA2_SEC_DP_ERR("Memory alloc failed");
231 memset(fle, 0, FLE_POOL_BUF_SIZE);
232 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
233 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
238 if (likely(bpid < MAX_BPID)) {
239 DPAA2_SET_FD_BPID(fd, bpid);
240 DPAA2_SET_FLE_BPID(op_fle, bpid);
241 DPAA2_SET_FLE_BPID(ip_fle, bpid);
243 DPAA2_SET_FD_IVP(fd);
244 DPAA2_SET_FLE_IVP(op_fle);
245 DPAA2_SET_FLE_IVP(ip_fle);
248 /* Configure FD as a FRAME LIST */
249 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
250 DPAA2_SET_FD_COMPOUND_FMT(fd);
251 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
253 /* Configure Output FLE with dst mbuf data */
254 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_MBUF_VADDR_TO_IOVA(dst_mbuf));
255 DPAA2_SET_FLE_OFFSET(op_fle, dst_mbuf->data_off);
256 DPAA2_SET_FLE_LEN(op_fle, dst_mbuf->buf_len);
258 /* Configure Input FLE with src mbuf data */
259 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_MBUF_VADDR_TO_IOVA(src_mbuf));
260 DPAA2_SET_FLE_OFFSET(ip_fle, src_mbuf->data_off);
261 DPAA2_SET_FLE_LEN(ip_fle, src_mbuf->pkt_len);
263 DPAA2_SET_FD_LEN(fd, ip_fle->length);
264 DPAA2_SET_FLE_FIN(ip_fle);
266 /* In case of PDCP, per packet HFN is stored in
267 * mbuf priv after sym_op.
269 if (sess->ctxt_type == DPAA2_SEC_PDCP && sess->pdcp.hfn_ovd) {
270 uint32_t hfn_ovd = *(uint32_t *)((uint8_t *)op +
271 sess->pdcp.hfn_ovd_offset);
272 /*enable HFN override override */
273 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, hfn_ovd);
274 DPAA2_SET_FLE_INTERNAL_JD(op_fle, hfn_ovd);
275 DPAA2_SET_FD_INTERNAL_JD(fd, hfn_ovd);
283 build_proto_fd(dpaa2_sec_session *sess,
284 struct rte_crypto_op *op,
285 struct qbman_fd *fd, uint16_t bpid)
287 struct rte_crypto_sym_op *sym_op = op->sym;
289 return build_proto_compound_fd(sess, op, fd, bpid);
291 struct ctxt_priv *priv = sess->ctxt;
292 struct sec_flow_context *flc;
293 struct rte_mbuf *mbuf = sym_op->m_src;
295 if (likely(bpid < MAX_BPID))
296 DPAA2_SET_FD_BPID(fd, bpid);
298 DPAA2_SET_FD_IVP(fd);
300 /* Save the shared descriptor */
301 flc = &priv->flc_desc[0].flc;
303 DPAA2_SET_FD_ADDR(fd, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
304 DPAA2_SET_FD_OFFSET(fd, sym_op->m_src->data_off);
305 DPAA2_SET_FD_LEN(fd, sym_op->m_src->pkt_len);
306 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
308 /* save physical address of mbuf */
309 op->sym->aead.digest.phys_addr = mbuf->buf_iova;
310 mbuf->buf_iova = (size_t)op;
317 build_authenc_gcm_sg_fd(dpaa2_sec_session *sess,
318 struct rte_crypto_op *op,
319 struct qbman_fd *fd, __rte_unused uint16_t bpid)
321 struct rte_crypto_sym_op *sym_op = op->sym;
322 struct ctxt_priv *priv = sess->ctxt;
323 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
324 struct sec_flow_context *flc;
325 uint32_t auth_only_len = sess->ext_params.aead_ctxt.auth_only_len;
326 int icv_len = sess->digest_length;
328 struct rte_mbuf *mbuf;
329 uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
333 mbuf = sym_op->m_dst;
335 mbuf = sym_op->m_src;
337 /* first FLE entry used to store mbuf and session ctxt */
338 fle = (struct qbman_fle *)rte_malloc(NULL,
339 FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
340 RTE_CACHE_LINE_SIZE);
341 if (unlikely(!fle)) {
342 DPAA2_SEC_ERR("GCM SG: Memory alloc failed for SGE");
345 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
346 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
347 DPAA2_FLE_SAVE_CTXT(fle, (size_t)priv);
353 /* Save the shared descriptor */
354 flc = &priv->flc_desc[0].flc;
356 /* Configure FD as a FRAME LIST */
357 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
358 DPAA2_SET_FD_COMPOUND_FMT(fd);
359 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
361 DPAA2_SEC_DP_DEBUG("GCM SG: auth_off: 0x%x/length %d, digest-len=%d\n"
362 "iv-len=%d data_off: 0x%x\n",
363 sym_op->aead.data.offset,
364 sym_op->aead.data.length,
367 sym_op->m_src->data_off);
369 /* Configure Output FLE with Scatter/Gather Entry */
370 DPAA2_SET_FLE_SG_EXT(op_fle);
371 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
374 DPAA2_SET_FLE_INTERNAL_JD(op_fle, auth_only_len);
376 op_fle->length = (sess->dir == DIR_ENC) ?
377 (sym_op->aead.data.length + icv_len) :
378 sym_op->aead.data.length;
380 /* Configure Output SGE for Encap/Decap */
381 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
382 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off + sym_op->aead.data.offset);
383 sge->length = mbuf->data_len - sym_op->aead.data.offset;
389 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
390 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
391 sge->length = mbuf->data_len;
394 sge->length -= icv_len;
396 if (sess->dir == DIR_ENC) {
398 DPAA2_SET_FLE_ADDR(sge,
399 DPAA2_VADDR_TO_IOVA(sym_op->aead.digest.data));
400 sge->length = icv_len;
402 DPAA2_SET_FLE_FIN(sge);
405 mbuf = sym_op->m_src;
407 /* Configure Input FLE with Scatter/Gather Entry */
408 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
409 DPAA2_SET_FLE_SG_EXT(ip_fle);
410 DPAA2_SET_FLE_FIN(ip_fle);
411 ip_fle->length = (sess->dir == DIR_ENC) ?
412 (sym_op->aead.data.length + sess->iv.length + auth_only_len) :
413 (sym_op->aead.data.length + sess->iv.length + auth_only_len +
416 /* Configure Input SGE for Encap/Decap */
417 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(IV_ptr));
418 sge->length = sess->iv.length;
422 DPAA2_SET_FLE_ADDR(sge,
423 DPAA2_VADDR_TO_IOVA(sym_op->aead.aad.data));
424 sge->length = auth_only_len;
428 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
429 DPAA2_SET_FLE_OFFSET(sge, sym_op->aead.data.offset +
431 sge->length = mbuf->data_len - sym_op->aead.data.offset;
437 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
438 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
439 sge->length = mbuf->data_len;
443 if (sess->dir == DIR_DEC) {
445 old_icv = (uint8_t *)(sge + 1);
446 memcpy(old_icv, sym_op->aead.digest.data, icv_len);
447 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
448 sge->length = icv_len;
451 DPAA2_SET_FLE_FIN(sge);
453 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, auth_only_len);
454 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
456 DPAA2_SET_FD_LEN(fd, ip_fle->length);
462 build_authenc_gcm_fd(dpaa2_sec_session *sess,
463 struct rte_crypto_op *op,
464 struct qbman_fd *fd, uint16_t bpid)
466 struct rte_crypto_sym_op *sym_op = op->sym;
467 struct ctxt_priv *priv = sess->ctxt;
468 struct qbman_fle *fle, *sge;
469 struct sec_flow_context *flc;
470 uint32_t auth_only_len = sess->ext_params.aead_ctxt.auth_only_len;
471 int icv_len = sess->digest_length, retval;
473 struct rte_mbuf *dst;
474 uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
482 /* TODO we are using the first FLE entry to store Mbuf and session ctxt.
483 * Currently we donot know which FLE has the mbuf stored.
484 * So while retreiving we can go back 1 FLE from the FD -ADDR
485 * to get the MBUF Addr from the previous FLE.
486 * We can have a better approach to use the inline Mbuf
488 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
490 DPAA2_SEC_ERR("GCM: Memory alloc failed for SGE");
493 memset(fle, 0, FLE_POOL_BUF_SIZE);
494 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
495 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
498 if (likely(bpid < MAX_BPID)) {
499 DPAA2_SET_FD_BPID(fd, bpid);
500 DPAA2_SET_FLE_BPID(fle, bpid);
501 DPAA2_SET_FLE_BPID(fle + 1, bpid);
502 DPAA2_SET_FLE_BPID(sge, bpid);
503 DPAA2_SET_FLE_BPID(sge + 1, bpid);
504 DPAA2_SET_FLE_BPID(sge + 2, bpid);
505 DPAA2_SET_FLE_BPID(sge + 3, bpid);
507 DPAA2_SET_FD_IVP(fd);
508 DPAA2_SET_FLE_IVP(fle);
509 DPAA2_SET_FLE_IVP((fle + 1));
510 DPAA2_SET_FLE_IVP(sge);
511 DPAA2_SET_FLE_IVP((sge + 1));
512 DPAA2_SET_FLE_IVP((sge + 2));
513 DPAA2_SET_FLE_IVP((sge + 3));
516 /* Save the shared descriptor */
517 flc = &priv->flc_desc[0].flc;
518 /* Configure FD as a FRAME LIST */
519 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
520 DPAA2_SET_FD_COMPOUND_FMT(fd);
521 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
523 DPAA2_SEC_DP_DEBUG("GCM: auth_off: 0x%x/length %d, digest-len=%d\n"
524 "iv-len=%d data_off: 0x%x\n",
525 sym_op->aead.data.offset,
526 sym_op->aead.data.length,
529 sym_op->m_src->data_off);
531 /* Configure Output FLE with Scatter/Gather Entry */
532 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
534 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
535 fle->length = (sess->dir == DIR_ENC) ?
536 (sym_op->aead.data.length + icv_len) :
537 sym_op->aead.data.length;
539 DPAA2_SET_FLE_SG_EXT(fle);
541 /* Configure Output SGE for Encap/Decap */
542 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(dst));
543 DPAA2_SET_FLE_OFFSET(sge, dst->data_off + sym_op->aead.data.offset);
544 sge->length = sym_op->aead.data.length;
546 if (sess->dir == DIR_ENC) {
548 DPAA2_SET_FLE_ADDR(sge,
549 DPAA2_VADDR_TO_IOVA(sym_op->aead.digest.data));
550 sge->length = sess->digest_length;
552 DPAA2_SET_FLE_FIN(sge);
557 /* Configure Input FLE with Scatter/Gather Entry */
558 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
559 DPAA2_SET_FLE_SG_EXT(fle);
560 DPAA2_SET_FLE_FIN(fle);
561 fle->length = (sess->dir == DIR_ENC) ?
562 (sym_op->aead.data.length + sess->iv.length + auth_only_len) :
563 (sym_op->aead.data.length + sess->iv.length + auth_only_len +
564 sess->digest_length);
566 /* Configure Input SGE for Encap/Decap */
567 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(IV_ptr));
568 sge->length = sess->iv.length;
571 DPAA2_SET_FLE_ADDR(sge,
572 DPAA2_VADDR_TO_IOVA(sym_op->aead.aad.data));
573 sge->length = auth_only_len;
574 DPAA2_SET_FLE_BPID(sge, bpid);
578 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
579 DPAA2_SET_FLE_OFFSET(sge, sym_op->aead.data.offset +
580 sym_op->m_src->data_off);
581 sge->length = sym_op->aead.data.length;
582 if (sess->dir == DIR_DEC) {
584 old_icv = (uint8_t *)(sge + 1);
585 memcpy(old_icv, sym_op->aead.digest.data,
586 sess->digest_length);
587 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
588 sge->length = sess->digest_length;
590 DPAA2_SET_FLE_FIN(sge);
593 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
594 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
597 DPAA2_SET_FD_LEN(fd, fle->length);
602 build_authenc_sg_fd(dpaa2_sec_session *sess,
603 struct rte_crypto_op *op,
604 struct qbman_fd *fd, __rte_unused uint16_t bpid)
606 struct rte_crypto_sym_op *sym_op = op->sym;
607 struct ctxt_priv *priv = sess->ctxt;
608 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
609 struct sec_flow_context *flc;
610 uint16_t auth_hdr_len = sym_op->cipher.data.offset -
611 sym_op->auth.data.offset;
612 uint16_t auth_tail_len = sym_op->auth.data.length -
613 sym_op->cipher.data.length - auth_hdr_len;
614 uint32_t auth_only_len = (auth_tail_len << 16) | auth_hdr_len;
615 int icv_len = sess->digest_length;
617 struct rte_mbuf *mbuf;
618 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
622 mbuf = sym_op->m_dst;
624 mbuf = sym_op->m_src;
626 /* first FLE entry used to store mbuf and session ctxt */
627 fle = (struct qbman_fle *)rte_malloc(NULL,
628 FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
629 RTE_CACHE_LINE_SIZE);
630 if (unlikely(!fle)) {
631 DPAA2_SEC_ERR("AUTHENC SG: Memory alloc failed for SGE");
634 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
635 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
636 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
642 /* Save the shared descriptor */
643 flc = &priv->flc_desc[0].flc;
645 /* Configure FD as a FRAME LIST */
646 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
647 DPAA2_SET_FD_COMPOUND_FMT(fd);
648 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
651 "AUTHENC SG: auth_off: 0x%x/length %d, digest-len=%d\n"
652 "cipher_off: 0x%x/length %d, iv-len=%d data_off: 0x%x\n",
653 sym_op->auth.data.offset,
654 sym_op->auth.data.length,
656 sym_op->cipher.data.offset,
657 sym_op->cipher.data.length,
659 sym_op->m_src->data_off);
661 /* Configure Output FLE with Scatter/Gather Entry */
662 DPAA2_SET_FLE_SG_EXT(op_fle);
663 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
666 DPAA2_SET_FLE_INTERNAL_JD(op_fle, auth_only_len);
668 op_fle->length = (sess->dir == DIR_ENC) ?
669 (sym_op->cipher.data.length + icv_len) :
670 sym_op->cipher.data.length;
672 /* Configure Output SGE for Encap/Decap */
673 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
674 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off + sym_op->auth.data.offset);
675 sge->length = mbuf->data_len - sym_op->auth.data.offset;
681 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
682 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
683 sge->length = mbuf->data_len;
686 sge->length -= icv_len;
688 if (sess->dir == DIR_ENC) {
690 DPAA2_SET_FLE_ADDR(sge,
691 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
692 sge->length = icv_len;
694 DPAA2_SET_FLE_FIN(sge);
697 mbuf = sym_op->m_src;
699 /* Configure Input FLE with Scatter/Gather Entry */
700 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
701 DPAA2_SET_FLE_SG_EXT(ip_fle);
702 DPAA2_SET_FLE_FIN(ip_fle);
703 ip_fle->length = (sess->dir == DIR_ENC) ?
704 (sym_op->auth.data.length + sess->iv.length) :
705 (sym_op->auth.data.length + sess->iv.length +
708 /* Configure Input SGE for Encap/Decap */
709 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
710 sge->length = sess->iv.length;
713 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
714 DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset +
716 sge->length = mbuf->data_len - sym_op->auth.data.offset;
722 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
723 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
724 sge->length = mbuf->data_len;
727 sge->length -= icv_len;
729 if (sess->dir == DIR_DEC) {
731 old_icv = (uint8_t *)(sge + 1);
732 memcpy(old_icv, sym_op->auth.digest.data,
734 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
735 sge->length = icv_len;
738 DPAA2_SET_FLE_FIN(sge);
740 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, auth_only_len);
741 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
743 DPAA2_SET_FD_LEN(fd, ip_fle->length);
749 build_authenc_fd(dpaa2_sec_session *sess,
750 struct rte_crypto_op *op,
751 struct qbman_fd *fd, uint16_t bpid)
753 struct rte_crypto_sym_op *sym_op = op->sym;
754 struct ctxt_priv *priv = sess->ctxt;
755 struct qbman_fle *fle, *sge;
756 struct sec_flow_context *flc;
757 uint16_t auth_hdr_len = sym_op->cipher.data.offset -
758 sym_op->auth.data.offset;
759 uint16_t auth_tail_len = sym_op->auth.data.length -
760 sym_op->cipher.data.length - auth_hdr_len;
761 uint32_t auth_only_len = (auth_tail_len << 16) | auth_hdr_len;
763 int icv_len = sess->digest_length, retval;
765 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
767 struct rte_mbuf *dst;
774 /* we are using the first FLE entry to store Mbuf.
775 * Currently we donot know which FLE has the mbuf stored.
776 * So while retreiving we can go back 1 FLE from the FD -ADDR
777 * to get the MBUF Addr from the previous FLE.
778 * We can have a better approach to use the inline Mbuf
780 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
782 DPAA2_SEC_ERR("Memory alloc failed for SGE");
785 memset(fle, 0, FLE_POOL_BUF_SIZE);
786 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
787 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
790 if (likely(bpid < MAX_BPID)) {
791 DPAA2_SET_FD_BPID(fd, bpid);
792 DPAA2_SET_FLE_BPID(fle, bpid);
793 DPAA2_SET_FLE_BPID(fle + 1, bpid);
794 DPAA2_SET_FLE_BPID(sge, bpid);
795 DPAA2_SET_FLE_BPID(sge + 1, bpid);
796 DPAA2_SET_FLE_BPID(sge + 2, bpid);
797 DPAA2_SET_FLE_BPID(sge + 3, bpid);
799 DPAA2_SET_FD_IVP(fd);
800 DPAA2_SET_FLE_IVP(fle);
801 DPAA2_SET_FLE_IVP((fle + 1));
802 DPAA2_SET_FLE_IVP(sge);
803 DPAA2_SET_FLE_IVP((sge + 1));
804 DPAA2_SET_FLE_IVP((sge + 2));
805 DPAA2_SET_FLE_IVP((sge + 3));
808 /* Save the shared descriptor */
809 flc = &priv->flc_desc[0].flc;
810 /* Configure FD as a FRAME LIST */
811 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
812 DPAA2_SET_FD_COMPOUND_FMT(fd);
813 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
816 "AUTHENC: auth_off: 0x%x/length %d, digest-len=%d\n"
817 "cipher_off: 0x%x/length %d, iv-len=%d data_off: 0x%x\n",
818 sym_op->auth.data.offset,
819 sym_op->auth.data.length,
821 sym_op->cipher.data.offset,
822 sym_op->cipher.data.length,
824 sym_op->m_src->data_off);
826 /* Configure Output FLE with Scatter/Gather Entry */
827 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
829 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
830 fle->length = (sess->dir == DIR_ENC) ?
831 (sym_op->cipher.data.length + icv_len) :
832 sym_op->cipher.data.length;
834 DPAA2_SET_FLE_SG_EXT(fle);
836 /* Configure Output SGE for Encap/Decap */
837 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(dst));
838 DPAA2_SET_FLE_OFFSET(sge, sym_op->cipher.data.offset +
840 sge->length = sym_op->cipher.data.length;
842 if (sess->dir == DIR_ENC) {
844 DPAA2_SET_FLE_ADDR(sge,
845 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
846 sge->length = sess->digest_length;
847 DPAA2_SET_FD_LEN(fd, (sym_op->auth.data.length +
850 DPAA2_SET_FLE_FIN(sge);
855 /* Configure Input FLE with Scatter/Gather Entry */
856 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
857 DPAA2_SET_FLE_SG_EXT(fle);
858 DPAA2_SET_FLE_FIN(fle);
859 fle->length = (sess->dir == DIR_ENC) ?
860 (sym_op->auth.data.length + sess->iv.length) :
861 (sym_op->auth.data.length + sess->iv.length +
862 sess->digest_length);
864 /* Configure Input SGE for Encap/Decap */
865 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
866 sge->length = sess->iv.length;
869 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
870 DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset +
871 sym_op->m_src->data_off);
872 sge->length = sym_op->auth.data.length;
873 if (sess->dir == DIR_DEC) {
875 old_icv = (uint8_t *)(sge + 1);
876 memcpy(old_icv, sym_op->auth.digest.data,
877 sess->digest_length);
878 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
879 sge->length = sess->digest_length;
880 DPAA2_SET_FD_LEN(fd, (sym_op->auth.data.length +
881 sess->digest_length +
884 DPAA2_SET_FLE_FIN(sge);
886 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
887 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
892 static inline int build_auth_sg_fd(
893 dpaa2_sec_session *sess,
894 struct rte_crypto_op *op,
896 __rte_unused uint16_t bpid)
898 struct rte_crypto_sym_op *sym_op = op->sym;
899 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
900 struct sec_flow_context *flc;
901 struct ctxt_priv *priv = sess->ctxt;
902 int data_len, data_offset;
904 struct rte_mbuf *mbuf;
906 data_len = sym_op->auth.data.length;
907 data_offset = sym_op->auth.data.offset;
909 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
910 sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
911 if ((data_len & 7) || (data_offset & 7)) {
912 DPAA2_SEC_ERR("AUTH: len/offset must be full bytes");
916 data_len = data_len >> 3;
917 data_offset = data_offset >> 3;
920 mbuf = sym_op->m_src;
921 fle = (struct qbman_fle *)rte_malloc(NULL,
922 FLE_SG_MEM_SIZE(mbuf->nb_segs),
923 RTE_CACHE_LINE_SIZE);
924 if (unlikely(!fle)) {
925 DPAA2_SEC_ERR("AUTH SG: Memory alloc failed for SGE");
928 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs));
929 /* first FLE entry used to store mbuf and session ctxt */
930 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
931 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
936 flc = &priv->flc_desc[DESC_INITFINAL].flc;
938 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
939 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
940 DPAA2_SET_FD_COMPOUND_FMT(fd);
943 DPAA2_SET_FLE_ADDR(op_fle,
944 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
945 op_fle->length = sess->digest_length;
948 DPAA2_SET_FLE_SG_EXT(ip_fle);
949 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
950 ip_fle->length = data_len;
952 if (sess->iv.length) {
955 iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
958 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2) {
959 iv_ptr = conv_to_snow_f9_iv(iv_ptr);
961 } else if (sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
962 iv_ptr = conv_to_zuc_eia_iv(iv_ptr);
965 sge->length = sess->iv.length;
967 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
968 ip_fle->length += sge->length;
972 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
973 DPAA2_SET_FLE_OFFSET(sge, data_offset + mbuf->data_off);
975 if (data_len <= (mbuf->data_len - data_offset)) {
976 sge->length = data_len;
979 sge->length = mbuf->data_len - data_offset;
981 /* remaining i/p segs */
982 while ((data_len = data_len - sge->length) &&
983 (mbuf = mbuf->next)) {
985 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
986 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
987 if (data_len > mbuf->data_len)
988 sge->length = mbuf->data_len;
990 sge->length = data_len;
994 if (sess->dir == DIR_DEC) {
995 /* Digest verification case */
997 old_digest = (uint8_t *)(sge + 1);
998 rte_memcpy(old_digest, sym_op->auth.digest.data,
999 sess->digest_length);
1000 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_digest));
1001 sge->length = sess->digest_length;
1002 ip_fle->length += sess->digest_length;
1004 DPAA2_SET_FLE_FIN(sge);
1005 DPAA2_SET_FLE_FIN(ip_fle);
1006 DPAA2_SET_FD_LEN(fd, ip_fle->length);
1012 build_auth_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
1013 struct qbman_fd *fd, uint16_t bpid)
1015 struct rte_crypto_sym_op *sym_op = op->sym;
1016 struct qbman_fle *fle, *sge;
1017 struct sec_flow_context *flc;
1018 struct ctxt_priv *priv = sess->ctxt;
1019 int data_len, data_offset;
1020 uint8_t *old_digest;
1023 data_len = sym_op->auth.data.length;
1024 data_offset = sym_op->auth.data.offset;
1026 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
1027 sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
1028 if ((data_len & 7) || (data_offset & 7)) {
1029 DPAA2_SEC_ERR("AUTH: len/offset must be full bytes");
1033 data_len = data_len >> 3;
1034 data_offset = data_offset >> 3;
1037 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
1039 DPAA2_SEC_ERR("AUTH Memory alloc failed for SGE");
1042 memset(fle, 0, FLE_POOL_BUF_SIZE);
1043 /* TODO we are using the first FLE entry to store Mbuf.
1044 * Currently we donot know which FLE has the mbuf stored.
1045 * So while retreiving we can go back 1 FLE from the FD -ADDR
1046 * to get the MBUF Addr from the previous FLE.
1047 * We can have a better approach to use the inline Mbuf
1049 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
1050 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
1054 if (likely(bpid < MAX_BPID)) {
1055 DPAA2_SET_FD_BPID(fd, bpid);
1056 DPAA2_SET_FLE_BPID(fle, bpid);
1057 DPAA2_SET_FLE_BPID(fle + 1, bpid);
1058 DPAA2_SET_FLE_BPID(sge, bpid);
1059 DPAA2_SET_FLE_BPID(sge + 1, bpid);
1061 DPAA2_SET_FD_IVP(fd);
1062 DPAA2_SET_FLE_IVP(fle);
1063 DPAA2_SET_FLE_IVP((fle + 1));
1064 DPAA2_SET_FLE_IVP(sge);
1065 DPAA2_SET_FLE_IVP((sge + 1));
1068 flc = &priv->flc_desc[DESC_INITFINAL].flc;
1069 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
1070 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
1071 DPAA2_SET_FD_COMPOUND_FMT(fd);
1073 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
1074 fle->length = sess->digest_length;
1077 /* Setting input FLE */
1078 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
1079 DPAA2_SET_FLE_SG_EXT(fle);
1080 fle->length = data_len;
1082 if (sess->iv.length) {
1085 iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1088 if (sess->auth_alg == RTE_CRYPTO_AUTH_SNOW3G_UIA2) {
1089 iv_ptr = conv_to_snow_f9_iv(iv_ptr);
1091 } else if (sess->auth_alg == RTE_CRYPTO_AUTH_ZUC_EIA3) {
1092 iv_ptr = conv_to_zuc_eia_iv(iv_ptr);
1095 sge->length = sess->iv.length;
1098 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
1099 fle->length = fle->length + sge->length;
1103 /* Setting data to authenticate */
1104 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
1105 DPAA2_SET_FLE_OFFSET(sge, data_offset + sym_op->m_src->data_off);
1106 sge->length = data_len;
1108 if (sess->dir == DIR_DEC) {
1110 old_digest = (uint8_t *)(sge + 1);
1111 rte_memcpy(old_digest, sym_op->auth.digest.data,
1112 sess->digest_length);
1113 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_digest));
1114 sge->length = sess->digest_length;
1115 fle->length = fle->length + sess->digest_length;
1118 DPAA2_SET_FLE_FIN(sge);
1119 DPAA2_SET_FLE_FIN(fle);
1120 DPAA2_SET_FD_LEN(fd, fle->length);
1126 build_cipher_sg_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
1127 struct qbman_fd *fd, __rte_unused uint16_t bpid)
1129 struct rte_crypto_sym_op *sym_op = op->sym;
1130 struct qbman_fle *ip_fle, *op_fle, *sge, *fle;
1131 int data_len, data_offset;
1132 struct sec_flow_context *flc;
1133 struct ctxt_priv *priv = sess->ctxt;
1134 struct rte_mbuf *mbuf;
1135 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1138 data_len = sym_op->cipher.data.length;
1139 data_offset = sym_op->cipher.data.offset;
1141 if (sess->cipher_alg == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
1142 sess->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
1143 if ((data_len & 7) || (data_offset & 7)) {
1144 DPAA2_SEC_ERR("CIPHER: len/offset must be full bytes");
1148 data_len = data_len >> 3;
1149 data_offset = data_offset >> 3;
1153 mbuf = sym_op->m_dst;
1155 mbuf = sym_op->m_src;
1157 /* first FLE entry used to store mbuf and session ctxt */
1158 fle = (struct qbman_fle *)rte_malloc(NULL,
1159 FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs),
1160 RTE_CACHE_LINE_SIZE);
1162 DPAA2_SEC_ERR("CIPHER SG: Memory alloc failed for SGE");
1165 memset(fle, 0, FLE_SG_MEM_SIZE(mbuf->nb_segs + sym_op->m_src->nb_segs));
1166 /* first FLE entry used to store mbuf and session ctxt */
1167 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
1168 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
1174 flc = &priv->flc_desc[0].flc;
1177 "CIPHER SG: cipher_off: 0x%x/length %d, ivlen=%d"
1178 " data_off: 0x%x\n",
1182 sym_op->m_src->data_off);
1185 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
1186 op_fle->length = data_len;
1187 DPAA2_SET_FLE_SG_EXT(op_fle);
1190 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1191 DPAA2_SET_FLE_OFFSET(sge, data_offset + mbuf->data_off);
1192 sge->length = mbuf->data_len - data_offset;
1198 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1199 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
1200 sge->length = mbuf->data_len;
1203 DPAA2_SET_FLE_FIN(sge);
1206 "CIPHER SG: 1 - flc = %p, fle = %p FLEaddr = %x-%x, len %d\n",
1207 flc, fle, fle->addr_hi, fle->addr_lo,
1211 mbuf = sym_op->m_src;
1213 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
1214 ip_fle->length = sess->iv.length + data_len;
1215 DPAA2_SET_FLE_SG_EXT(ip_fle);
1218 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
1219 DPAA2_SET_FLE_OFFSET(sge, 0);
1220 sge->length = sess->iv.length;
1225 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1226 DPAA2_SET_FLE_OFFSET(sge, data_offset + mbuf->data_off);
1227 sge->length = mbuf->data_len - data_offset;
1233 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1234 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
1235 sge->length = mbuf->data_len;
1238 DPAA2_SET_FLE_FIN(sge);
1239 DPAA2_SET_FLE_FIN(ip_fle);
1242 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
1243 DPAA2_SET_FD_LEN(fd, ip_fle->length);
1244 DPAA2_SET_FD_COMPOUND_FMT(fd);
1245 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
1248 "CIPHER SG: fdaddr =%" PRIx64 " bpid =%d meta =%d"
1249 " off =%d, len =%d\n",
1250 DPAA2_GET_FD_ADDR(fd),
1251 DPAA2_GET_FD_BPID(fd),
1252 rte_dpaa2_bpid_info[bpid].meta_data_size,
1253 DPAA2_GET_FD_OFFSET(fd),
1254 DPAA2_GET_FD_LEN(fd));
1259 build_cipher_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
1260 struct qbman_fd *fd, uint16_t bpid)
1262 struct rte_crypto_sym_op *sym_op = op->sym;
1263 struct qbman_fle *fle, *sge;
1264 int retval, data_len, data_offset;
1265 struct sec_flow_context *flc;
1266 struct ctxt_priv *priv = sess->ctxt;
1267 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1269 struct rte_mbuf *dst;
1271 data_len = sym_op->cipher.data.length;
1272 data_offset = sym_op->cipher.data.offset;
1274 if (sess->cipher_alg == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
1275 sess->cipher_alg == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
1276 if ((data_len & 7) || (data_offset & 7)) {
1277 DPAA2_SEC_ERR("CIPHER: len/offset must be full bytes");
1281 data_len = data_len >> 3;
1282 data_offset = data_offset >> 3;
1286 dst = sym_op->m_dst;
1288 dst = sym_op->m_src;
1290 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
1292 DPAA2_SEC_ERR("CIPHER: Memory alloc failed for SGE");
1295 memset(fle, 0, FLE_POOL_BUF_SIZE);
1296 /* TODO we are using the first FLE entry to store Mbuf.
1297 * Currently we donot know which FLE has the mbuf stored.
1298 * So while retreiving we can go back 1 FLE from the FD -ADDR
1299 * to get the MBUF Addr from the previous FLE.
1300 * We can have a better approach to use the inline Mbuf
1302 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
1303 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
1307 if (likely(bpid < MAX_BPID)) {
1308 DPAA2_SET_FD_BPID(fd, bpid);
1309 DPAA2_SET_FLE_BPID(fle, bpid);
1310 DPAA2_SET_FLE_BPID(fle + 1, bpid);
1311 DPAA2_SET_FLE_BPID(sge, bpid);
1312 DPAA2_SET_FLE_BPID(sge + 1, bpid);
1314 DPAA2_SET_FD_IVP(fd);
1315 DPAA2_SET_FLE_IVP(fle);
1316 DPAA2_SET_FLE_IVP((fle + 1));
1317 DPAA2_SET_FLE_IVP(sge);
1318 DPAA2_SET_FLE_IVP((sge + 1));
1321 flc = &priv->flc_desc[0].flc;
1322 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
1323 DPAA2_SET_FD_LEN(fd, data_len + sess->iv.length);
1324 DPAA2_SET_FD_COMPOUND_FMT(fd);
1325 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
1328 "CIPHER: cipher_off: 0x%x/length %d, ivlen=%d,"
1329 " data_off: 0x%x\n",
1333 sym_op->m_src->data_off);
1335 DPAA2_SET_FLE_ADDR(fle, DPAA2_MBUF_VADDR_TO_IOVA(dst));
1336 DPAA2_SET_FLE_OFFSET(fle, data_offset + dst->data_off);
1338 fle->length = data_len + sess->iv.length;
1341 "CIPHER: 1 - flc = %p, fle = %p FLEaddr = %x-%x, length %d\n",
1342 flc, fle, fle->addr_hi, fle->addr_lo,
1347 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
1348 fle->length = data_len + sess->iv.length;
1350 DPAA2_SET_FLE_SG_EXT(fle);
1352 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
1353 sge->length = sess->iv.length;
1356 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
1357 DPAA2_SET_FLE_OFFSET(sge, data_offset + sym_op->m_src->data_off);
1359 sge->length = data_len;
1360 DPAA2_SET_FLE_FIN(sge);
1361 DPAA2_SET_FLE_FIN(fle);
1364 "CIPHER: fdaddr =%" PRIx64 " bpid =%d meta =%d"
1365 " off =%d, len =%d\n",
1366 DPAA2_GET_FD_ADDR(fd),
1367 DPAA2_GET_FD_BPID(fd),
1368 rte_dpaa2_bpid_info[bpid].meta_data_size,
1369 DPAA2_GET_FD_OFFSET(fd),
1370 DPAA2_GET_FD_LEN(fd));
1376 build_sec_fd(struct rte_crypto_op *op,
1377 struct qbman_fd *fd, uint16_t bpid)
1380 dpaa2_sec_session *sess;
1382 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION)
1383 sess = (dpaa2_sec_session *)get_sym_session_private_data(
1384 op->sym->session, cryptodev_driver_id);
1385 #ifdef RTE_LIB_SECURITY
1386 else if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION)
1387 sess = (dpaa2_sec_session *)get_sec_session_private_data(
1388 op->sym->sec_session);
1396 /* Any of the buffer is segmented*/
1397 if (!rte_pktmbuf_is_contiguous(op->sym->m_src) ||
1398 ((op->sym->m_dst != NULL) &&
1399 !rte_pktmbuf_is_contiguous(op->sym->m_dst))) {
1400 switch (sess->ctxt_type) {
1401 case DPAA2_SEC_CIPHER:
1402 ret = build_cipher_sg_fd(sess, op, fd, bpid);
1404 case DPAA2_SEC_AUTH:
1405 ret = build_auth_sg_fd(sess, op, fd, bpid);
1407 case DPAA2_SEC_AEAD:
1408 ret = build_authenc_gcm_sg_fd(sess, op, fd, bpid);
1410 case DPAA2_SEC_CIPHER_HASH:
1411 ret = build_authenc_sg_fd(sess, op, fd, bpid);
1413 #ifdef RTE_LIB_SECURITY
1414 case DPAA2_SEC_IPSEC:
1415 case DPAA2_SEC_PDCP:
1416 ret = build_proto_compound_sg_fd(sess, op, fd, bpid);
1419 case DPAA2_SEC_HASH_CIPHER:
1421 DPAA2_SEC_ERR("error: Unsupported session");
1424 switch (sess->ctxt_type) {
1425 case DPAA2_SEC_CIPHER:
1426 ret = build_cipher_fd(sess, op, fd, bpid);
1428 case DPAA2_SEC_AUTH:
1429 ret = build_auth_fd(sess, op, fd, bpid);
1431 case DPAA2_SEC_AEAD:
1432 ret = build_authenc_gcm_fd(sess, op, fd, bpid);
1434 case DPAA2_SEC_CIPHER_HASH:
1435 ret = build_authenc_fd(sess, op, fd, bpid);
1437 #ifdef RTE_LIB_SECURITY
1438 case DPAA2_SEC_IPSEC:
1439 ret = build_proto_fd(sess, op, fd, bpid);
1441 case DPAA2_SEC_PDCP:
1442 ret = build_proto_compound_fd(sess, op, fd, bpid);
1445 case DPAA2_SEC_HASH_CIPHER:
1447 DPAA2_SEC_ERR("error: Unsupported session");
1455 dpaa2_sec_enqueue_burst(void *qp, struct rte_crypto_op **ops,
1458 /* Function to transmit the frames to given device and VQ*/
1461 struct qbman_fd fd_arr[MAX_TX_RING_SLOTS];
1462 uint32_t frames_to_send, retry_count;
1463 struct qbman_eq_desc eqdesc;
1464 struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
1465 struct qbman_swp *swp;
1466 uint16_t num_tx = 0;
1467 uint32_t flags[MAX_TX_RING_SLOTS] = {0};
1468 /*todo - need to support multiple buffer pools */
1470 struct rte_mempool *mb_pool;
1472 if (unlikely(nb_ops == 0))
1475 if (ops[0]->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
1476 DPAA2_SEC_ERR("sessionless crypto op not supported");
1479 /*Prepare enqueue descriptor*/
1480 qbman_eq_desc_clear(&eqdesc);
1481 qbman_eq_desc_set_no_orp(&eqdesc, DPAA2_EQ_RESP_ERR_FQ);
1482 qbman_eq_desc_set_response(&eqdesc, 0, 0);
1483 qbman_eq_desc_set_fq(&eqdesc, dpaa2_qp->tx_vq.fqid);
1485 if (!DPAA2_PER_LCORE_DPIO) {
1486 ret = dpaa2_affine_qbman_swp();
1489 "Failed to allocate IO portal, tid: %d\n",
1494 swp = DPAA2_PER_LCORE_PORTAL;
1497 frames_to_send = (nb_ops > dpaa2_eqcr_size) ?
1498 dpaa2_eqcr_size : nb_ops;
1500 for (loop = 0; loop < frames_to_send; loop++) {
1501 if (*dpaa2_seqn((*ops)->sym->m_src)) {
1502 if (*dpaa2_seqn((*ops)->sym->m_src) & QBMAN_ENQUEUE_FLAG_DCA) {
1503 DPAA2_PER_LCORE_DQRR_SIZE--;
1504 DPAA2_PER_LCORE_DQRR_HELD &= ~(1 <<
1505 *dpaa2_seqn((*ops)->sym->m_src) &
1506 QBMAN_EQCR_DCA_IDXMASK);
1508 flags[loop] = *dpaa2_seqn((*ops)->sym->m_src);
1509 *dpaa2_seqn((*ops)->sym->m_src) = DPAA2_INVALID_MBUF_SEQN;
1512 /*Clear the unused FD fields before sending*/
1513 memset(&fd_arr[loop], 0, sizeof(struct qbman_fd));
1514 mb_pool = (*ops)->sym->m_src->pool;
1515 bpid = mempool_to_bpid(mb_pool);
1516 ret = build_sec_fd(*ops, &fd_arr[loop], bpid);
1518 DPAA2_SEC_ERR("error: Improper packet contents"
1519 " for crypto operation");
1527 while (loop < frames_to_send) {
1528 ret = qbman_swp_enqueue_multiple(swp, &eqdesc,
1531 frames_to_send - loop);
1532 if (unlikely(ret < 0)) {
1534 if (retry_count > DPAA2_MAX_TX_RETRY_COUNT) {
1537 DPAA2_SEC_DP_DEBUG("Enqueue fail\n");
1538 /* freeing the fle buffers */
1539 while (loop < frames_to_send) {
1540 free_fle(&fd_arr[loop]);
1555 dpaa2_qp->tx_vq.tx_pkts += num_tx;
1556 dpaa2_qp->tx_vq.err_pkts += nb_ops;
1560 #ifdef RTE_LIB_SECURITY
1561 static inline struct rte_crypto_op *
1562 sec_simple_fd_to_mbuf(const struct qbman_fd *fd)
1564 struct rte_crypto_op *op;
1565 uint16_t len = DPAA2_GET_FD_LEN(fd);
1567 dpaa2_sec_session *sess_priv __rte_unused;
1569 struct rte_mbuf *mbuf = DPAA2_INLINE_MBUF_FROM_BUF(
1570 DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd)),
1571 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size);
1573 diff = len - mbuf->pkt_len;
1574 mbuf->pkt_len += diff;
1575 mbuf->data_len += diff;
1576 op = (struct rte_crypto_op *)(size_t)mbuf->buf_iova;
1577 mbuf->buf_iova = op->sym->aead.digest.phys_addr;
1578 op->sym->aead.digest.phys_addr = 0L;
1580 sess_priv = (dpaa2_sec_session *)get_sec_session_private_data(
1581 op->sym->sec_session);
1582 if (sess_priv->dir == DIR_ENC)
1583 mbuf->data_off += SEC_FLC_DHR_OUTBOUND;
1585 mbuf->data_off += SEC_FLC_DHR_INBOUND;
1591 static inline struct rte_crypto_op *
1592 sec_fd_to_mbuf(const struct qbman_fd *fd)
1594 struct qbman_fle *fle;
1595 struct rte_crypto_op *op;
1596 struct ctxt_priv *priv;
1597 struct rte_mbuf *dst, *src;
1599 #ifdef RTE_LIB_SECURITY
1600 if (DPAA2_FD_GET_FORMAT(fd) == qbman_fd_single)
1601 return sec_simple_fd_to_mbuf(fd);
1603 fle = (struct qbman_fle *)DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd));
1605 DPAA2_SEC_DP_DEBUG("FLE addr = %x - %x, offset = %x\n",
1606 fle->addr_hi, fle->addr_lo, fle->fin_bpid_offset);
1608 /* we are using the first FLE entry to store Mbuf.
1609 * Currently we donot know which FLE has the mbuf stored.
1610 * So while retreiving we can go back 1 FLE from the FD -ADDR
1611 * to get the MBUF Addr from the previous FLE.
1612 * We can have a better approach to use the inline Mbuf
1615 if (unlikely(DPAA2_GET_FD_IVP(fd))) {
1616 /* TODO complete it. */
1617 DPAA2_SEC_ERR("error: non inline buffer");
1620 op = (struct rte_crypto_op *)DPAA2_GET_FLE_ADDR((fle - 1));
1623 src = op->sym->m_src;
1626 if (op->sym->m_dst) {
1627 dst = op->sym->m_dst;
1632 #ifdef RTE_LIB_SECURITY
1633 if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
1634 uint16_t len = DPAA2_GET_FD_LEN(fd);
1636 while (dst->next != NULL) {
1637 len -= dst->data_len;
1640 dst->data_len = len;
1643 DPAA2_SEC_DP_DEBUG("mbuf %p BMAN buf addr %p,"
1644 " fdaddr =%" PRIx64 " bpid =%d meta =%d off =%d, len =%d\n",
1647 DPAA2_GET_FD_ADDR(fd),
1648 DPAA2_GET_FD_BPID(fd),
1649 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size,
1650 DPAA2_GET_FD_OFFSET(fd),
1651 DPAA2_GET_FD_LEN(fd));
1653 /* free the fle memory */
1654 if (likely(rte_pktmbuf_is_contiguous(src))) {
1655 priv = (struct ctxt_priv *)(size_t)DPAA2_GET_FLE_CTXT(fle - 1);
1656 rte_mempool_put(priv->fle_pool, (void *)(fle-1));
1658 rte_free((void *)(fle-1));
1664 dpaa2_sec_dump(struct rte_crypto_op *op)
1667 dpaa2_sec_session *sess = NULL;
1668 struct ctxt_priv *priv;
1670 struct rte_crypto_sym_op *sym_op;
1672 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION)
1673 sess = (dpaa2_sec_session *)get_sym_session_private_data(
1674 op->sym->session, cryptodev_driver_id);
1675 #ifdef RTE_LIBRTE_SECURITY
1676 else if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION)
1677 sess = (dpaa2_sec_session *)get_sec_session_private_data(
1678 op->sym->sec_session);
1684 priv = (struct ctxt_priv *)sess->ctxt;
1685 printf("\n****************************************\n"
1686 "session params:\n\tContext type:\t%d\n\tDirection:\t%s\n"
1687 "\tCipher alg:\t%d\n\tAuth alg:\t%d\n\tAead alg:\t%d\n"
1688 "\tCipher key len:\t%zd\n", sess->ctxt_type,
1689 (sess->dir == DIR_ENC) ? "DIR_ENC" : "DIR_DEC",
1690 sess->cipher_alg, sess->auth_alg, sess->aead_alg,
1691 sess->cipher_key.length);
1692 rte_hexdump(stdout, "cipher key", sess->cipher_key.data,
1693 sess->cipher_key.length);
1694 rte_hexdump(stdout, "auth key", sess->auth_key.data,
1695 sess->auth_key.length);
1696 printf("\tAuth key len:\t%zd\n\tIV len:\t\t%d\n\tIV offset:\t%d\n"
1697 "\tdigest length:\t%d\n\tstatus:\t\t%d\n\taead auth only"
1698 " len:\t%d\n\taead cipher text:\t%d\n",
1699 sess->auth_key.length, sess->iv.length, sess->iv.offset,
1700 sess->digest_length, sess->status,
1701 sess->ext_params.aead_ctxt.auth_only_len,
1702 sess->ext_params.aead_ctxt.auth_cipher_text);
1703 #ifdef RTE_LIBRTE_SECURITY
1704 printf("PDCP session params:\n"
1705 "\tDomain:\t\t%d\n\tBearer:\t\t%d\n\tpkt_dir:\t%d\n\thfn_ovd:"
1706 "\t%d\n\tsn_size:\t%d\n\thfn_ovd_offset:\t%d\n\thfn:\t\t%d\n"
1707 "\thfn_threshold:\t0x%x\n", sess->pdcp.domain,
1708 sess->pdcp.bearer, sess->pdcp.pkt_dir, sess->pdcp.hfn_ovd,
1709 sess->pdcp.sn_size, sess->pdcp.hfn_ovd_offset, sess->pdcp.hfn,
1710 sess->pdcp.hfn_threshold);
1713 bufsize = (uint8_t)priv->flc_desc[0].flc.word1_sdl;
1714 printf("Descriptor Dump:\n");
1715 for (i = 0; i < bufsize; i++)
1716 printf("\tDESC[%d]:0x%x\n", i, priv->flc_desc[0].desc[i]);
1721 if (sym_op->m_src) {
1722 printf("Source mbuf:\n");
1723 rte_pktmbuf_dump(stdout, sym_op->m_src, sym_op->m_src->data_len);
1725 if (sym_op->m_dst) {
1726 printf("Destination mbuf:\n");
1727 rte_pktmbuf_dump(stdout, sym_op->m_dst, sym_op->m_dst->data_len);
1730 printf("Session address = %p\ncipher offset: %d, length: %d\n"
1731 "auth offset: %d, length: %d\n aead offset: %d, length: %d\n"
1733 sym_op->cipher.data.offset, sym_op->cipher.data.length,
1734 sym_op->auth.data.offset, sym_op->auth.data.length,
1735 sym_op->aead.data.offset, sym_op->aead.data.length);
1741 dpaa2_sec_free_eqresp_buf(uint16_t eqresp_ci)
1743 struct dpaa2_dpio_dev *dpio_dev = DPAA2_PER_LCORE_DPIO;
1744 struct rte_crypto_op *op;
1745 struct qbman_fd *fd;
1747 fd = qbman_result_eqresp_fd(&dpio_dev->eqresp[eqresp_ci]);
1748 op = sec_fd_to_mbuf(fd);
1749 /* Instead of freeing, enqueue it to the sec tx queue (sec->core)
1750 * after setting an error in FD. But this will have performance impact.
1752 rte_pktmbuf_free(op->sym->m_src);
1756 dpaa2_sec_set_enqueue_descriptor(struct dpaa2_queue *dpaa2_q,
1758 struct qbman_eq_desc *eqdesc)
1760 struct dpaa2_dpio_dev *dpio_dev = DPAA2_PER_LCORE_DPIO;
1761 struct eqresp_metadata *eqresp_meta;
1762 struct dpaa2_sec_dev_private *priv = dpaa2_q->crypto_data->dev_private;
1763 uint16_t orpid, seqnum;
1766 if (*dpaa2_seqn(m) & DPAA2_ENQUEUE_FLAG_ORP) {
1767 orpid = (*dpaa2_seqn(m) & DPAA2_EQCR_OPRID_MASK) >>
1768 DPAA2_EQCR_OPRID_SHIFT;
1769 seqnum = (*dpaa2_seqn(m) & DPAA2_EQCR_SEQNUM_MASK) >>
1770 DPAA2_EQCR_SEQNUM_SHIFT;
1773 if (!priv->en_loose_ordered) {
1774 qbman_eq_desc_set_orp(eqdesc, 1, orpid, seqnum, 0);
1775 qbman_eq_desc_set_response(eqdesc, (uint64_t)
1776 DPAA2_VADDR_TO_IOVA(&dpio_dev->eqresp[
1777 dpio_dev->eqresp_pi]), 1);
1778 qbman_eq_desc_set_token(eqdesc, 1);
1780 eqresp_meta = &dpio_dev->eqresp_meta[dpio_dev->eqresp_pi];
1781 eqresp_meta->dpaa2_q = dpaa2_q;
1782 eqresp_meta->mp = m->pool;
1784 dpio_dev->eqresp_pi + 1 < MAX_EQ_RESP_ENTRIES ?
1785 dpio_dev->eqresp_pi++ : (dpio_dev->eqresp_pi = 0);
1787 qbman_eq_desc_set_orp(eqdesc, 0, orpid, seqnum, 0);
1790 dq_idx = *dpaa2_seqn(m) - 1;
1791 qbman_eq_desc_set_dca(eqdesc, 1, dq_idx, 0);
1792 DPAA2_PER_LCORE_DQRR_SIZE--;
1793 DPAA2_PER_LCORE_DQRR_HELD &= ~(1 << dq_idx);
1795 *dpaa2_seqn(m) = DPAA2_INVALID_MBUF_SEQN;
1800 dpaa2_sec_enqueue_burst_ordered(void *qp, struct rte_crypto_op **ops,
1803 /* Function to transmit the frames to given device and VQ*/
1806 struct qbman_fd fd_arr[MAX_TX_RING_SLOTS];
1807 uint32_t frames_to_send, num_free_eq_desc, retry_count;
1808 struct qbman_eq_desc eqdesc[MAX_TX_RING_SLOTS];
1809 struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
1810 struct qbman_swp *swp;
1811 uint16_t num_tx = 0;
1813 struct rte_mempool *mb_pool;
1814 struct dpaa2_sec_dev_private *priv =
1815 dpaa2_qp->tx_vq.crypto_data->dev_private;
1817 if (unlikely(nb_ops == 0))
1820 if (ops[0]->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
1821 DPAA2_SEC_ERR("sessionless crypto op not supported");
1825 if (!DPAA2_PER_LCORE_DPIO) {
1826 ret = dpaa2_affine_qbman_swp();
1828 DPAA2_SEC_ERR("Failure in affining portal");
1832 swp = DPAA2_PER_LCORE_PORTAL;
1835 frames_to_send = (nb_ops > dpaa2_eqcr_size) ?
1836 dpaa2_eqcr_size : nb_ops;
1838 if (!priv->en_loose_ordered) {
1839 if (*dpaa2_seqn((*ops)->sym->m_src)) {
1840 num_free_eq_desc = dpaa2_free_eq_descriptors();
1841 if (num_free_eq_desc < frames_to_send)
1842 frames_to_send = num_free_eq_desc;
1846 for (loop = 0; loop < frames_to_send; loop++) {
1847 /*Prepare enqueue descriptor*/
1848 qbman_eq_desc_clear(&eqdesc[loop]);
1849 qbman_eq_desc_set_fq(&eqdesc[loop], dpaa2_qp->tx_vq.fqid);
1851 if (*dpaa2_seqn((*ops)->sym->m_src))
1852 dpaa2_sec_set_enqueue_descriptor(
1857 qbman_eq_desc_set_no_orp(&eqdesc[loop],
1858 DPAA2_EQ_RESP_ERR_FQ);
1860 /*Clear the unused FD fields before sending*/
1861 memset(&fd_arr[loop], 0, sizeof(struct qbman_fd));
1862 mb_pool = (*ops)->sym->m_src->pool;
1863 bpid = mempool_to_bpid(mb_pool);
1864 ret = build_sec_fd(*ops, &fd_arr[loop], bpid);
1866 DPAA2_SEC_ERR("error: Improper packet contents"
1867 " for crypto operation");
1875 while (loop < frames_to_send) {
1876 ret = qbman_swp_enqueue_multiple_desc(swp,
1877 &eqdesc[loop], &fd_arr[loop],
1878 frames_to_send - loop);
1879 if (unlikely(ret < 0)) {
1881 if (retry_count > DPAA2_MAX_TX_RETRY_COUNT) {
1884 DPAA2_SEC_DP_DEBUG("Enqueue fail\n");
1885 /* freeing the fle buffers */
1886 while (loop < frames_to_send) {
1887 free_fle(&fd_arr[loop]);
1903 dpaa2_qp->tx_vq.tx_pkts += num_tx;
1904 dpaa2_qp->tx_vq.err_pkts += nb_ops;
1909 dpaa2_sec_dequeue_burst(void *qp, struct rte_crypto_op **ops,
1912 /* Function is responsible to receive frames for a given device and VQ*/
1913 struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
1914 struct qbman_result *dq_storage;
1915 uint32_t fqid = dpaa2_qp->rx_vq.fqid;
1916 int ret, num_rx = 0;
1917 uint8_t is_last = 0, status;
1918 struct qbman_swp *swp;
1919 const struct qbman_fd *fd;
1920 struct qbman_pull_desc pulldesc;
1922 if (!DPAA2_PER_LCORE_DPIO) {
1923 ret = dpaa2_affine_qbman_swp();
1926 "Failed to allocate IO portal, tid: %d\n",
1931 swp = DPAA2_PER_LCORE_PORTAL;
1932 dq_storage = dpaa2_qp->rx_vq.q_storage->dq_storage[0];
1934 qbman_pull_desc_clear(&pulldesc);
1935 qbman_pull_desc_set_numframes(&pulldesc,
1936 (nb_ops > dpaa2_dqrr_size) ?
1937 dpaa2_dqrr_size : nb_ops);
1938 qbman_pull_desc_set_fq(&pulldesc, fqid);
1939 qbman_pull_desc_set_storage(&pulldesc, dq_storage,
1940 (dma_addr_t)DPAA2_VADDR_TO_IOVA(dq_storage),
1943 /*Issue a volatile dequeue command. */
1945 if (qbman_swp_pull(swp, &pulldesc)) {
1947 "SEC VDQ command is not issued : QBMAN busy");
1948 /* Portal was busy, try again */
1954 /* Receive the packets till Last Dequeue entry is found with
1955 * respect to the above issues PULL command.
1958 /* Check if the previous issued command is completed.
1959 * Also seems like the SWP is shared between the Ethernet Driver
1960 * and the SEC driver.
1962 while (!qbman_check_command_complete(dq_storage))
1965 /* Loop until the dq_storage is updated with
1966 * new token by QBMAN
1968 while (!qbman_check_new_result(dq_storage))
1970 /* Check whether Last Pull command is Expired and
1971 * setting Condition for Loop termination
1973 if (qbman_result_DQ_is_pull_complete(dq_storage)) {
1975 /* Check for valid frame. */
1976 status = (uint8_t)qbman_result_DQ_flags(dq_storage);
1978 (status & QBMAN_DQ_STAT_VALIDFRAME) == 0)) {
1979 DPAA2_SEC_DP_DEBUG("No frame is delivered\n");
1984 fd = qbman_result_DQ_fd(dq_storage);
1985 ops[num_rx] = sec_fd_to_mbuf(fd);
1987 if (unlikely(fd->simple.frc)) {
1988 /* TODO Parse SEC errors */
1989 if (dpaa2_sec_dp_dump > DPAA2_SEC_DP_NO_DUMP) {
1990 DPAA2_SEC_DP_ERR("SEC returned Error - %x\n",
1992 if (dpaa2_sec_dp_dump > DPAA2_SEC_DP_ERR_DUMP)
1993 dpaa2_sec_dump(ops[num_rx]);
1996 dpaa2_qp->rx_vq.err_pkts += 1;
1997 ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_ERROR;
1999 ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
2004 } /* End of Packet Rx loop */
2006 dpaa2_qp->rx_vq.rx_pkts += num_rx;
2008 DPAA2_SEC_DP_DEBUG("SEC RX pkts %d err pkts %" PRIu64 "\n", num_rx,
2009 dpaa2_qp->rx_vq.err_pkts);
2010 /*Return the total number of packets received to DPAA2 app*/
2014 /** Release queue pair */
2016 dpaa2_sec_queue_pair_release(struct rte_cryptodev *dev, uint16_t queue_pair_id)
2018 struct dpaa2_sec_qp *qp =
2019 (struct dpaa2_sec_qp *)dev->data->queue_pairs[queue_pair_id];
2021 PMD_INIT_FUNC_TRACE();
2023 if (qp->rx_vq.q_storage) {
2024 dpaa2_free_dq_storage(qp->rx_vq.q_storage);
2025 rte_free(qp->rx_vq.q_storage);
2029 dev->data->queue_pairs[queue_pair_id] = NULL;
2034 /** Setup a queue pair */
2036 dpaa2_sec_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
2037 __rte_unused const struct rte_cryptodev_qp_conf *qp_conf,
2038 __rte_unused int socket_id)
2040 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
2041 struct dpaa2_sec_qp *qp;
2042 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
2043 struct dpseci_rx_queue_cfg cfg;
2046 PMD_INIT_FUNC_TRACE();
2048 /* If qp is already in use free ring memory and qp metadata. */
2049 if (dev->data->queue_pairs[qp_id] != NULL) {
2050 DPAA2_SEC_INFO("QP already setup");
2054 DPAA2_SEC_DEBUG("dev =%p, queue =%d, conf =%p",
2055 dev, qp_id, qp_conf);
2057 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
2059 qp = rte_malloc(NULL, sizeof(struct dpaa2_sec_qp),
2060 RTE_CACHE_LINE_SIZE);
2062 DPAA2_SEC_ERR("malloc failed for rx/tx queues");
2066 qp->rx_vq.crypto_data = dev->data;
2067 qp->tx_vq.crypto_data = dev->data;
2068 qp->rx_vq.q_storage = rte_malloc("sec dq storage",
2069 sizeof(struct queue_storage_info_t),
2070 RTE_CACHE_LINE_SIZE);
2071 if (!qp->rx_vq.q_storage) {
2072 DPAA2_SEC_ERR("malloc failed for q_storage");
2075 memset(qp->rx_vq.q_storage, 0, sizeof(struct queue_storage_info_t));
2077 if (dpaa2_alloc_dq_storage(qp->rx_vq.q_storage)) {
2078 DPAA2_SEC_ERR("Unable to allocate dequeue storage");
2082 dev->data->queue_pairs[qp_id] = qp;
2084 cfg.options = cfg.options | DPSECI_QUEUE_OPT_USER_CTX;
2085 cfg.user_ctx = (size_t)(&qp->rx_vq);
2086 retcode = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
2091 /** Returns the size of the aesni gcm session structure */
2093 dpaa2_sec_sym_session_get_size(struct rte_cryptodev *dev __rte_unused)
2095 PMD_INIT_FUNC_TRACE();
2097 return sizeof(dpaa2_sec_session);
2101 dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
2102 struct rte_crypto_sym_xform *xform,
2103 dpaa2_sec_session *session)
2105 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2106 struct alginfo cipherdata;
2107 int bufsize, ret = 0;
2108 struct ctxt_priv *priv;
2109 struct sec_flow_context *flc;
2111 PMD_INIT_FUNC_TRACE();
2113 /* For SEC CIPHER only one descriptor is required. */
2114 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2115 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
2116 RTE_CACHE_LINE_SIZE);
2118 DPAA2_SEC_ERR("No Memory for priv CTXT");
2122 priv->fle_pool = dev_priv->fle_pool;
2124 flc = &priv->flc_desc[0].flc;
2126 session->ctxt_type = DPAA2_SEC_CIPHER;
2127 session->cipher_key.data = rte_zmalloc(NULL, xform->cipher.key.length,
2128 RTE_CACHE_LINE_SIZE);
2129 if (session->cipher_key.data == NULL && xform->cipher.key.length > 0) {
2130 DPAA2_SEC_ERR("No Memory for cipher key");
2134 session->cipher_key.length = xform->cipher.key.length;
2136 memcpy(session->cipher_key.data, xform->cipher.key.data,
2137 xform->cipher.key.length);
2138 cipherdata.key = (size_t)session->cipher_key.data;
2139 cipherdata.keylen = session->cipher_key.length;
2140 cipherdata.key_enc_flags = 0;
2141 cipherdata.key_type = RTA_DATA_IMM;
2143 /* Set IV parameters */
2144 session->iv.offset = xform->cipher.iv.offset;
2145 session->iv.length = xform->cipher.iv.length;
2146 session->dir = (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2149 switch (xform->cipher.algo) {
2150 case RTE_CRYPTO_CIPHER_AES_CBC:
2151 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2152 cipherdata.algmode = OP_ALG_AAI_CBC;
2153 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
2154 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
2155 SHR_NEVER, &cipherdata,
2159 case RTE_CRYPTO_CIPHER_3DES_CBC:
2160 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
2161 cipherdata.algmode = OP_ALG_AAI_CBC;
2162 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
2163 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
2164 SHR_NEVER, &cipherdata,
2168 case RTE_CRYPTO_CIPHER_DES_CBC:
2169 cipherdata.algtype = OP_ALG_ALGSEL_DES;
2170 cipherdata.algmode = OP_ALG_AAI_CBC;
2171 session->cipher_alg = RTE_CRYPTO_CIPHER_DES_CBC;
2172 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
2173 SHR_NEVER, &cipherdata,
2177 case RTE_CRYPTO_CIPHER_AES_CTR:
2178 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2179 cipherdata.algmode = OP_ALG_AAI_CTR;
2180 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
2181 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
2182 SHR_NEVER, &cipherdata,
2186 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2187 cipherdata.algtype = OP_ALG_ALGSEL_SNOW_F8;
2188 session->cipher_alg = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
2189 bufsize = cnstr_shdsc_snow_f8(priv->flc_desc[0].desc, 1, 0,
2193 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
2194 cipherdata.algtype = OP_ALG_ALGSEL_ZUCE;
2195 session->cipher_alg = RTE_CRYPTO_CIPHER_ZUC_EEA3;
2196 bufsize = cnstr_shdsc_zuce(priv->flc_desc[0].desc, 1, 0,
2200 case RTE_CRYPTO_CIPHER_KASUMI_F8:
2201 case RTE_CRYPTO_CIPHER_AES_F8:
2202 case RTE_CRYPTO_CIPHER_AES_ECB:
2203 case RTE_CRYPTO_CIPHER_3DES_ECB:
2204 case RTE_CRYPTO_CIPHER_3DES_CTR:
2205 case RTE_CRYPTO_CIPHER_AES_XTS:
2206 case RTE_CRYPTO_CIPHER_ARC4:
2207 case RTE_CRYPTO_CIPHER_NULL:
2208 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
2209 xform->cipher.algo);
2213 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2214 xform->cipher.algo);
2220 DPAA2_SEC_ERR("Crypto: Descriptor build failed");
2225 flc->word1_sdl = (uint8_t)bufsize;
2226 session->ctxt = priv;
2228 #ifdef CAAM_DESC_DEBUG
2230 for (i = 0; i < bufsize; i++)
2231 DPAA2_SEC_DEBUG("DESC[%d]:0x%x", i, priv->flc_desc[0].desc[i]);
2236 rte_free(session->cipher_key.data);
2242 dpaa2_sec_auth_init(struct rte_cryptodev *dev,
2243 struct rte_crypto_sym_xform *xform,
2244 dpaa2_sec_session *session)
2246 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2247 struct alginfo authdata;
2248 int bufsize, ret = 0;
2249 struct ctxt_priv *priv;
2250 struct sec_flow_context *flc;
2252 PMD_INIT_FUNC_TRACE();
2254 /* For SEC AUTH three descriptors are required for various stages */
2255 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2256 sizeof(struct ctxt_priv) + 3 *
2257 sizeof(struct sec_flc_desc),
2258 RTE_CACHE_LINE_SIZE);
2260 DPAA2_SEC_ERR("No Memory for priv CTXT");
2264 priv->fle_pool = dev_priv->fle_pool;
2265 flc = &priv->flc_desc[DESC_INITFINAL].flc;
2267 session->ctxt_type = DPAA2_SEC_AUTH;
2268 session->auth_key.length = xform->auth.key.length;
2269 if (xform->auth.key.length) {
2270 session->auth_key.data = rte_zmalloc(NULL,
2271 xform->auth.key.length,
2272 RTE_CACHE_LINE_SIZE);
2273 if (session->auth_key.data == NULL) {
2274 DPAA2_SEC_ERR("Unable to allocate memory for auth key");
2278 memcpy(session->auth_key.data, xform->auth.key.data,
2279 xform->auth.key.length);
2280 authdata.key = (size_t)session->auth_key.data;
2281 authdata.key_enc_flags = 0;
2282 authdata.key_type = RTA_DATA_IMM;
2284 authdata.keylen = session->auth_key.length;
2286 session->digest_length = xform->auth.digest_length;
2287 session->dir = (xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE) ?
2290 switch (xform->auth.algo) {
2291 case RTE_CRYPTO_AUTH_SHA1_HMAC:
2292 authdata.algtype = OP_ALG_ALGSEL_SHA1;
2293 authdata.algmode = OP_ALG_AAI_HMAC;
2294 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
2295 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2296 1, 0, SHR_NEVER, &authdata,
2298 session->digest_length);
2300 case RTE_CRYPTO_AUTH_MD5_HMAC:
2301 authdata.algtype = OP_ALG_ALGSEL_MD5;
2302 authdata.algmode = OP_ALG_AAI_HMAC;
2303 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
2304 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2305 1, 0, SHR_NEVER, &authdata,
2307 session->digest_length);
2309 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2310 authdata.algtype = OP_ALG_ALGSEL_SHA256;
2311 authdata.algmode = OP_ALG_AAI_HMAC;
2312 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
2313 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2314 1, 0, SHR_NEVER, &authdata,
2316 session->digest_length);
2318 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2319 authdata.algtype = OP_ALG_ALGSEL_SHA384;
2320 authdata.algmode = OP_ALG_AAI_HMAC;
2321 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
2322 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2323 1, 0, SHR_NEVER, &authdata,
2325 session->digest_length);
2327 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2328 authdata.algtype = OP_ALG_ALGSEL_SHA512;
2329 authdata.algmode = OP_ALG_AAI_HMAC;
2330 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
2331 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2332 1, 0, SHR_NEVER, &authdata,
2334 session->digest_length);
2336 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2337 authdata.algtype = OP_ALG_ALGSEL_SHA224;
2338 authdata.algmode = OP_ALG_AAI_HMAC;
2339 session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
2340 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2341 1, 0, SHR_NEVER, &authdata,
2343 session->digest_length);
2345 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2346 authdata.algtype = OP_ALG_ALGSEL_SNOW_F9;
2347 authdata.algmode = OP_ALG_AAI_F9;
2348 session->auth_alg = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2349 session->iv.offset = xform->auth.iv.offset;
2350 session->iv.length = xform->auth.iv.length;
2351 bufsize = cnstr_shdsc_snow_f9(priv->flc_desc[DESC_INITFINAL].desc,
2354 session->digest_length);
2356 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2357 authdata.algtype = OP_ALG_ALGSEL_ZUCA;
2358 authdata.algmode = OP_ALG_AAI_F9;
2359 session->auth_alg = RTE_CRYPTO_AUTH_ZUC_EIA3;
2360 session->iv.offset = xform->auth.iv.offset;
2361 session->iv.length = xform->auth.iv.length;
2362 bufsize = cnstr_shdsc_zuca(priv->flc_desc[DESC_INITFINAL].desc,
2365 session->digest_length);
2367 case RTE_CRYPTO_AUTH_SHA1:
2368 authdata.algtype = OP_ALG_ALGSEL_SHA1;
2369 authdata.algmode = OP_ALG_AAI_HASH;
2370 session->auth_alg = RTE_CRYPTO_AUTH_SHA1;
2371 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2372 1, 0, SHR_NEVER, &authdata,
2374 session->digest_length);
2376 case RTE_CRYPTO_AUTH_MD5:
2377 authdata.algtype = OP_ALG_ALGSEL_MD5;
2378 authdata.algmode = OP_ALG_AAI_HASH;
2379 session->auth_alg = RTE_CRYPTO_AUTH_MD5;
2380 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2381 1, 0, SHR_NEVER, &authdata,
2383 session->digest_length);
2385 case RTE_CRYPTO_AUTH_SHA256:
2386 authdata.algtype = OP_ALG_ALGSEL_SHA256;
2387 authdata.algmode = OP_ALG_AAI_HASH;
2388 session->auth_alg = RTE_CRYPTO_AUTH_SHA256;
2389 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2390 1, 0, SHR_NEVER, &authdata,
2392 session->digest_length);
2394 case RTE_CRYPTO_AUTH_SHA384:
2395 authdata.algtype = OP_ALG_ALGSEL_SHA384;
2396 authdata.algmode = OP_ALG_AAI_HASH;
2397 session->auth_alg = RTE_CRYPTO_AUTH_SHA384;
2398 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2399 1, 0, SHR_NEVER, &authdata,
2401 session->digest_length);
2403 case RTE_CRYPTO_AUTH_SHA512:
2404 authdata.algtype = OP_ALG_ALGSEL_SHA512;
2405 authdata.algmode = OP_ALG_AAI_HASH;
2406 session->auth_alg = RTE_CRYPTO_AUTH_SHA512;
2407 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2408 1, 0, SHR_NEVER, &authdata,
2410 session->digest_length);
2412 case RTE_CRYPTO_AUTH_SHA224:
2413 authdata.algtype = OP_ALG_ALGSEL_SHA224;
2414 authdata.algmode = OP_ALG_AAI_HASH;
2415 session->auth_alg = RTE_CRYPTO_AUTH_SHA224;
2416 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2417 1, 0, SHR_NEVER, &authdata,
2419 session->digest_length);
2421 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2422 authdata.algtype = OP_ALG_ALGSEL_AES;
2423 authdata.algmode = OP_ALG_AAI_XCBC_MAC;
2424 session->auth_alg = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
2425 bufsize = cnstr_shdsc_aes_mac(
2426 priv->flc_desc[DESC_INITFINAL].desc,
2427 1, 0, SHR_NEVER, &authdata,
2429 session->digest_length);
2431 case RTE_CRYPTO_AUTH_AES_CMAC:
2432 authdata.algtype = OP_ALG_ALGSEL_AES;
2433 authdata.algmode = OP_ALG_AAI_CMAC;
2434 session->auth_alg = RTE_CRYPTO_AUTH_AES_CMAC;
2435 bufsize = cnstr_shdsc_aes_mac(
2436 priv->flc_desc[DESC_INITFINAL].desc,
2437 1, 0, SHR_NEVER, &authdata,
2439 session->digest_length);
2441 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2442 case RTE_CRYPTO_AUTH_AES_GMAC:
2443 case RTE_CRYPTO_AUTH_KASUMI_F9:
2444 case RTE_CRYPTO_AUTH_NULL:
2445 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %un",
2450 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2457 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2462 flc->word1_sdl = (uint8_t)bufsize;
2463 session->ctxt = priv;
2464 #ifdef CAAM_DESC_DEBUG
2466 for (i = 0; i < bufsize; i++)
2467 DPAA2_SEC_DEBUG("DESC[%d]:0x%x",
2468 i, priv->flc_desc[DESC_INITFINAL].desc[i]);
2474 rte_free(session->auth_key.data);
2480 dpaa2_sec_aead_init(struct rte_cryptodev *dev,
2481 struct rte_crypto_sym_xform *xform,
2482 dpaa2_sec_session *session)
2484 struct dpaa2_sec_aead_ctxt *ctxt = &session->ext_params.aead_ctxt;
2485 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2486 struct alginfo aeaddata;
2488 struct ctxt_priv *priv;
2489 struct sec_flow_context *flc;
2490 struct rte_crypto_aead_xform *aead_xform = &xform->aead;
2493 PMD_INIT_FUNC_TRACE();
2495 /* Set IV parameters */
2496 session->iv.offset = aead_xform->iv.offset;
2497 session->iv.length = aead_xform->iv.length;
2498 session->ctxt_type = DPAA2_SEC_AEAD;
2500 /* For SEC AEAD only one descriptor is required */
2501 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2502 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
2503 RTE_CACHE_LINE_SIZE);
2505 DPAA2_SEC_ERR("No Memory for priv CTXT");
2509 priv->fle_pool = dev_priv->fle_pool;
2510 flc = &priv->flc_desc[0].flc;
2512 session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length,
2513 RTE_CACHE_LINE_SIZE);
2514 if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
2515 DPAA2_SEC_ERR("No Memory for aead key");
2519 memcpy(session->aead_key.data, aead_xform->key.data,
2520 aead_xform->key.length);
2522 session->digest_length = aead_xform->digest_length;
2523 session->aead_key.length = aead_xform->key.length;
2524 ctxt->auth_only_len = aead_xform->aad_length;
2526 aeaddata.key = (size_t)session->aead_key.data;
2527 aeaddata.keylen = session->aead_key.length;
2528 aeaddata.key_enc_flags = 0;
2529 aeaddata.key_type = RTA_DATA_IMM;
2531 switch (aead_xform->algo) {
2532 case RTE_CRYPTO_AEAD_AES_GCM:
2533 aeaddata.algtype = OP_ALG_ALGSEL_AES;
2534 aeaddata.algmode = OP_ALG_AAI_GCM;
2535 session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM;
2537 case RTE_CRYPTO_AEAD_AES_CCM:
2538 DPAA2_SEC_ERR("Crypto: Unsupported AEAD alg %u",
2543 DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
2548 session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
2551 priv->flc_desc[0].desc[0] = aeaddata.keylen;
2552 err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
2554 (unsigned int *)priv->flc_desc[0].desc,
2555 &priv->flc_desc[0].desc[1], 1);
2558 DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
2562 if (priv->flc_desc[0].desc[1] & 1) {
2563 aeaddata.key_type = RTA_DATA_IMM;
2565 aeaddata.key = DPAA2_VADDR_TO_IOVA(aeaddata.key);
2566 aeaddata.key_type = RTA_DATA_PTR;
2568 priv->flc_desc[0].desc[0] = 0;
2569 priv->flc_desc[0].desc[1] = 0;
2571 if (session->dir == DIR_ENC)
2572 bufsize = cnstr_shdsc_gcm_encap(
2573 priv->flc_desc[0].desc, 1, 0, SHR_NEVER,
2574 &aeaddata, session->iv.length,
2575 session->digest_length);
2577 bufsize = cnstr_shdsc_gcm_decap(
2578 priv->flc_desc[0].desc, 1, 0, SHR_NEVER,
2579 &aeaddata, session->iv.length,
2580 session->digest_length);
2582 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2587 flc->word1_sdl = (uint8_t)bufsize;
2588 session->ctxt = priv;
2589 #ifdef CAAM_DESC_DEBUG
2591 for (i = 0; i < bufsize; i++)
2592 DPAA2_SEC_DEBUG("DESC[%d]:0x%x\n",
2593 i, priv->flc_desc[0].desc[i]);
2598 rte_free(session->aead_key.data);
2605 dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
2606 struct rte_crypto_sym_xform *xform,
2607 dpaa2_sec_session *session)
2609 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2610 struct alginfo authdata, cipherdata;
2612 struct ctxt_priv *priv;
2613 struct sec_flow_context *flc;
2614 struct rte_crypto_cipher_xform *cipher_xform;
2615 struct rte_crypto_auth_xform *auth_xform;
2618 PMD_INIT_FUNC_TRACE();
2620 if (session->ext_params.aead_ctxt.auth_cipher_text) {
2621 cipher_xform = &xform->cipher;
2622 auth_xform = &xform->next->auth;
2623 session->ctxt_type =
2624 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2625 DPAA2_SEC_CIPHER_HASH : DPAA2_SEC_HASH_CIPHER;
2627 cipher_xform = &xform->next->cipher;
2628 auth_xform = &xform->auth;
2629 session->ctxt_type =
2630 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2631 DPAA2_SEC_HASH_CIPHER : DPAA2_SEC_CIPHER_HASH;
2634 /* Set IV parameters */
2635 session->iv.offset = cipher_xform->iv.offset;
2636 session->iv.length = cipher_xform->iv.length;
2638 /* For SEC AEAD only one descriptor is required */
2639 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2640 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
2641 RTE_CACHE_LINE_SIZE);
2643 DPAA2_SEC_ERR("No Memory for priv CTXT");
2647 priv->fle_pool = dev_priv->fle_pool;
2648 flc = &priv->flc_desc[0].flc;
2650 session->cipher_key.data = rte_zmalloc(NULL, cipher_xform->key.length,
2651 RTE_CACHE_LINE_SIZE);
2652 if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) {
2653 DPAA2_SEC_ERR("No Memory for cipher key");
2657 session->cipher_key.length = cipher_xform->key.length;
2658 session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length,
2659 RTE_CACHE_LINE_SIZE);
2660 if (session->auth_key.data == NULL && auth_xform->key.length > 0) {
2661 DPAA2_SEC_ERR("No Memory for auth key");
2662 rte_free(session->cipher_key.data);
2666 session->auth_key.length = auth_xform->key.length;
2667 memcpy(session->cipher_key.data, cipher_xform->key.data,
2668 cipher_xform->key.length);
2669 memcpy(session->auth_key.data, auth_xform->key.data,
2670 auth_xform->key.length);
2672 authdata.key = (size_t)session->auth_key.data;
2673 authdata.keylen = session->auth_key.length;
2674 authdata.key_enc_flags = 0;
2675 authdata.key_type = RTA_DATA_IMM;
2677 session->digest_length = auth_xform->digest_length;
2679 switch (auth_xform->algo) {
2680 case RTE_CRYPTO_AUTH_SHA1_HMAC:
2681 authdata.algtype = OP_ALG_ALGSEL_SHA1;
2682 authdata.algmode = OP_ALG_AAI_HMAC;
2683 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
2685 case RTE_CRYPTO_AUTH_MD5_HMAC:
2686 authdata.algtype = OP_ALG_ALGSEL_MD5;
2687 authdata.algmode = OP_ALG_AAI_HMAC;
2688 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
2690 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2691 authdata.algtype = OP_ALG_ALGSEL_SHA224;
2692 authdata.algmode = OP_ALG_AAI_HMAC;
2693 session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
2695 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2696 authdata.algtype = OP_ALG_ALGSEL_SHA256;
2697 authdata.algmode = OP_ALG_AAI_HMAC;
2698 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
2700 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2701 authdata.algtype = OP_ALG_ALGSEL_SHA384;
2702 authdata.algmode = OP_ALG_AAI_HMAC;
2703 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
2705 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2706 authdata.algtype = OP_ALG_ALGSEL_SHA512;
2707 authdata.algmode = OP_ALG_AAI_HMAC;
2708 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
2710 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2711 authdata.algtype = OP_ALG_ALGSEL_AES;
2712 authdata.algmode = OP_ALG_AAI_XCBC_MAC;
2713 session->auth_alg = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
2715 case RTE_CRYPTO_AUTH_AES_CMAC:
2716 authdata.algtype = OP_ALG_ALGSEL_AES;
2717 authdata.algmode = OP_ALG_AAI_CMAC;
2718 session->auth_alg = RTE_CRYPTO_AUTH_AES_CMAC;
2720 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2721 case RTE_CRYPTO_AUTH_AES_GMAC:
2722 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2723 case RTE_CRYPTO_AUTH_NULL:
2724 case RTE_CRYPTO_AUTH_SHA1:
2725 case RTE_CRYPTO_AUTH_SHA256:
2726 case RTE_CRYPTO_AUTH_SHA512:
2727 case RTE_CRYPTO_AUTH_SHA224:
2728 case RTE_CRYPTO_AUTH_SHA384:
2729 case RTE_CRYPTO_AUTH_MD5:
2730 case RTE_CRYPTO_AUTH_KASUMI_F9:
2731 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2732 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
2737 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2742 cipherdata.key = (size_t)session->cipher_key.data;
2743 cipherdata.keylen = session->cipher_key.length;
2744 cipherdata.key_enc_flags = 0;
2745 cipherdata.key_type = RTA_DATA_IMM;
2747 switch (cipher_xform->algo) {
2748 case RTE_CRYPTO_CIPHER_AES_CBC:
2749 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2750 cipherdata.algmode = OP_ALG_AAI_CBC;
2751 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
2753 case RTE_CRYPTO_CIPHER_3DES_CBC:
2754 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
2755 cipherdata.algmode = OP_ALG_AAI_CBC;
2756 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
2758 case RTE_CRYPTO_CIPHER_DES_CBC:
2759 cipherdata.algtype = OP_ALG_ALGSEL_DES;
2760 cipherdata.algmode = OP_ALG_AAI_CBC;
2761 session->cipher_alg = RTE_CRYPTO_CIPHER_DES_CBC;
2763 case RTE_CRYPTO_CIPHER_AES_CTR:
2764 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2765 cipherdata.algmode = OP_ALG_AAI_CTR;
2766 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
2768 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2769 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
2770 case RTE_CRYPTO_CIPHER_NULL:
2771 case RTE_CRYPTO_CIPHER_3DES_ECB:
2772 case RTE_CRYPTO_CIPHER_3DES_CTR:
2773 case RTE_CRYPTO_CIPHER_AES_ECB:
2774 case RTE_CRYPTO_CIPHER_KASUMI_F8:
2775 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
2776 cipher_xform->algo);
2780 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2781 cipher_xform->algo);
2785 session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2788 priv->flc_desc[0].desc[0] = cipherdata.keylen;
2789 priv->flc_desc[0].desc[1] = authdata.keylen;
2790 err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
2792 (unsigned int *)priv->flc_desc[0].desc,
2793 &priv->flc_desc[0].desc[2], 2);
2796 DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
2800 if (priv->flc_desc[0].desc[2] & 1) {
2801 cipherdata.key_type = RTA_DATA_IMM;
2803 cipherdata.key = DPAA2_VADDR_TO_IOVA(cipherdata.key);
2804 cipherdata.key_type = RTA_DATA_PTR;
2806 if (priv->flc_desc[0].desc[2] & (1 << 1)) {
2807 authdata.key_type = RTA_DATA_IMM;
2809 authdata.key = DPAA2_VADDR_TO_IOVA(authdata.key);
2810 authdata.key_type = RTA_DATA_PTR;
2812 priv->flc_desc[0].desc[0] = 0;
2813 priv->flc_desc[0].desc[1] = 0;
2814 priv->flc_desc[0].desc[2] = 0;
2816 if (session->ctxt_type == DPAA2_SEC_CIPHER_HASH) {
2817 bufsize = cnstr_shdsc_authenc(priv->flc_desc[0].desc, 1,
2819 &cipherdata, &authdata,
2821 session->digest_length,
2824 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2829 DPAA2_SEC_ERR("Hash before cipher not supported");
2834 flc->word1_sdl = (uint8_t)bufsize;
2835 session->ctxt = priv;
2836 #ifdef CAAM_DESC_DEBUG
2838 for (i = 0; i < bufsize; i++)
2839 DPAA2_SEC_DEBUG("DESC[%d]:0x%x",
2840 i, priv->flc_desc[0].desc[i]);
2846 rte_free(session->cipher_key.data);
2847 rte_free(session->auth_key.data);
2853 dpaa2_sec_set_session_parameters(struct rte_cryptodev *dev,
2854 struct rte_crypto_sym_xform *xform, void *sess)
2856 dpaa2_sec_session *session = sess;
2859 PMD_INIT_FUNC_TRACE();
2861 if (unlikely(sess == NULL)) {
2862 DPAA2_SEC_ERR("Invalid session struct");
2866 memset(session, 0, sizeof(dpaa2_sec_session));
2867 /* Default IV length = 0 */
2868 session->iv.length = 0;
2871 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
2872 ret = dpaa2_sec_cipher_init(dev, xform, session);
2874 /* Authentication Only */
2875 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2876 xform->next == NULL) {
2877 ret = dpaa2_sec_auth_init(dev, xform, session);
2879 /* Cipher then Authenticate */
2880 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
2881 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2882 session->ext_params.aead_ctxt.auth_cipher_text = true;
2883 if (xform->cipher.algo == RTE_CRYPTO_CIPHER_NULL)
2884 ret = dpaa2_sec_auth_init(dev, xform, session);
2885 else if (xform->next->auth.algo == RTE_CRYPTO_AUTH_NULL)
2886 ret = dpaa2_sec_cipher_init(dev, xform, session);
2888 ret = dpaa2_sec_aead_chain_init(dev, xform, session);
2889 /* Authenticate then Cipher */
2890 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2891 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2892 session->ext_params.aead_ctxt.auth_cipher_text = false;
2893 if (xform->auth.algo == RTE_CRYPTO_AUTH_NULL)
2894 ret = dpaa2_sec_cipher_init(dev, xform, session);
2895 else if (xform->next->cipher.algo == RTE_CRYPTO_CIPHER_NULL)
2896 ret = dpaa2_sec_auth_init(dev, xform, session);
2898 ret = dpaa2_sec_aead_chain_init(dev, xform, session);
2899 /* AEAD operation for AES-GCM kind of Algorithms */
2900 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD &&
2901 xform->next == NULL) {
2902 ret = dpaa2_sec_aead_init(dev, xform, session);
2905 DPAA2_SEC_ERR("Invalid crypto type");
2912 #ifdef RTE_LIB_SECURITY
2914 dpaa2_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
2915 dpaa2_sec_session *session,
2916 struct alginfo *aeaddata)
2918 PMD_INIT_FUNC_TRACE();
2920 session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length,
2921 RTE_CACHE_LINE_SIZE);
2922 if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
2923 DPAA2_SEC_ERR("No Memory for aead key");
2926 memcpy(session->aead_key.data, aead_xform->key.data,
2927 aead_xform->key.length);
2929 session->digest_length = aead_xform->digest_length;
2930 session->aead_key.length = aead_xform->key.length;
2932 aeaddata->key = (size_t)session->aead_key.data;
2933 aeaddata->keylen = session->aead_key.length;
2934 aeaddata->key_enc_flags = 0;
2935 aeaddata->key_type = RTA_DATA_IMM;
2937 switch (aead_xform->algo) {
2938 case RTE_CRYPTO_AEAD_AES_GCM:
2939 switch (session->digest_length) {
2941 aeaddata->algtype = OP_PCL_IPSEC_AES_GCM8;
2944 aeaddata->algtype = OP_PCL_IPSEC_AES_GCM12;
2947 aeaddata->algtype = OP_PCL_IPSEC_AES_GCM16;
2950 DPAA2_SEC_ERR("Crypto: Undefined GCM digest %d",
2951 session->digest_length);
2954 aeaddata->algmode = OP_ALG_AAI_GCM;
2955 session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM;
2957 case RTE_CRYPTO_AEAD_AES_CCM:
2958 switch (session->digest_length) {
2960 aeaddata->algtype = OP_PCL_IPSEC_AES_CCM8;
2963 aeaddata->algtype = OP_PCL_IPSEC_AES_CCM12;
2966 aeaddata->algtype = OP_PCL_IPSEC_AES_CCM16;
2969 DPAA2_SEC_ERR("Crypto: Undefined CCM digest %d",
2970 session->digest_length);
2973 aeaddata->algmode = OP_ALG_AAI_CCM;
2974 session->aead_alg = RTE_CRYPTO_AEAD_AES_CCM;
2977 DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
2981 session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
2988 dpaa2_sec_ipsec_proto_init(struct rte_crypto_cipher_xform *cipher_xform,
2989 struct rte_crypto_auth_xform *auth_xform,
2990 dpaa2_sec_session *session,
2991 struct alginfo *cipherdata,
2992 struct alginfo *authdata)
2995 session->cipher_key.data = rte_zmalloc(NULL,
2996 cipher_xform->key.length,
2997 RTE_CACHE_LINE_SIZE);
2998 if (session->cipher_key.data == NULL &&
2999 cipher_xform->key.length > 0) {
3000 DPAA2_SEC_ERR("No Memory for cipher key");
3004 session->cipher_key.length = cipher_xform->key.length;
3005 memcpy(session->cipher_key.data, cipher_xform->key.data,
3006 cipher_xform->key.length);
3007 session->cipher_alg = cipher_xform->algo;
3009 session->cipher_key.data = NULL;
3010 session->cipher_key.length = 0;
3011 session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
3015 session->auth_key.data = rte_zmalloc(NULL,
3016 auth_xform->key.length,
3017 RTE_CACHE_LINE_SIZE);
3018 if (session->auth_key.data == NULL &&
3019 auth_xform->key.length > 0) {
3020 DPAA2_SEC_ERR("No Memory for auth key");
3023 session->auth_key.length = auth_xform->key.length;
3024 memcpy(session->auth_key.data, auth_xform->key.data,
3025 auth_xform->key.length);
3026 session->auth_alg = auth_xform->algo;
3027 session->digest_length = auth_xform->digest_length;
3029 session->auth_key.data = NULL;
3030 session->auth_key.length = 0;
3031 session->auth_alg = RTE_CRYPTO_AUTH_NULL;
3034 authdata->key = (size_t)session->auth_key.data;
3035 authdata->keylen = session->auth_key.length;
3036 authdata->key_enc_flags = 0;
3037 authdata->key_type = RTA_DATA_IMM;
3038 switch (session->auth_alg) {
3039 case RTE_CRYPTO_AUTH_SHA1_HMAC:
3040 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA1_96;
3041 authdata->algmode = OP_ALG_AAI_HMAC;
3043 case RTE_CRYPTO_AUTH_MD5_HMAC:
3044 authdata->algtype = OP_PCL_IPSEC_HMAC_MD5_96;
3045 authdata->algmode = OP_ALG_AAI_HMAC;
3047 case RTE_CRYPTO_AUTH_SHA256_HMAC:
3048 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_256_128;
3049 authdata->algmode = OP_ALG_AAI_HMAC;
3050 if (session->digest_length != 16)
3052 "+++Using sha256-hmac truncated len is non-standard,"
3053 "it will not work with lookaside proto");
3055 case RTE_CRYPTO_AUTH_SHA384_HMAC:
3056 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_384_192;
3057 authdata->algmode = OP_ALG_AAI_HMAC;
3059 case RTE_CRYPTO_AUTH_SHA512_HMAC:
3060 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_512_256;
3061 authdata->algmode = OP_ALG_AAI_HMAC;
3063 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
3064 authdata->algtype = OP_PCL_IPSEC_AES_XCBC_MAC_96;
3065 authdata->algmode = OP_ALG_AAI_XCBC_MAC;
3067 case RTE_CRYPTO_AUTH_AES_CMAC:
3068 authdata->algtype = OP_PCL_IPSEC_AES_CMAC_96;
3069 authdata->algmode = OP_ALG_AAI_CMAC;
3071 case RTE_CRYPTO_AUTH_NULL:
3072 authdata->algtype = OP_PCL_IPSEC_HMAC_NULL;
3074 case RTE_CRYPTO_AUTH_SHA224_HMAC:
3075 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
3076 case RTE_CRYPTO_AUTH_SHA1:
3077 case RTE_CRYPTO_AUTH_SHA256:
3078 case RTE_CRYPTO_AUTH_SHA512:
3079 case RTE_CRYPTO_AUTH_SHA224:
3080 case RTE_CRYPTO_AUTH_SHA384:
3081 case RTE_CRYPTO_AUTH_MD5:
3082 case RTE_CRYPTO_AUTH_AES_GMAC:
3083 case RTE_CRYPTO_AUTH_KASUMI_F9:
3084 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
3085 case RTE_CRYPTO_AUTH_ZUC_EIA3:
3086 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
3090 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
3094 cipherdata->key = (size_t)session->cipher_key.data;
3095 cipherdata->keylen = session->cipher_key.length;
3096 cipherdata->key_enc_flags = 0;
3097 cipherdata->key_type = RTA_DATA_IMM;
3099 switch (session->cipher_alg) {
3100 case RTE_CRYPTO_CIPHER_AES_CBC:
3101 cipherdata->algtype = OP_PCL_IPSEC_AES_CBC;
3102 cipherdata->algmode = OP_ALG_AAI_CBC;
3104 case RTE_CRYPTO_CIPHER_3DES_CBC:
3105 cipherdata->algtype = OP_PCL_IPSEC_3DES;
3106 cipherdata->algmode = OP_ALG_AAI_CBC;
3108 case RTE_CRYPTO_CIPHER_DES_CBC:
3109 cipherdata->algtype = OP_PCL_IPSEC_DES;
3110 cipherdata->algmode = OP_ALG_AAI_CBC;
3112 case RTE_CRYPTO_CIPHER_AES_CTR:
3113 cipherdata->algtype = OP_PCL_IPSEC_AES_CTR;
3114 cipherdata->algmode = OP_ALG_AAI_CTR;
3116 case RTE_CRYPTO_CIPHER_NULL:
3117 cipherdata->algtype = OP_PCL_IPSEC_NULL;
3119 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
3120 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
3121 case RTE_CRYPTO_CIPHER_3DES_ECB:
3122 case RTE_CRYPTO_CIPHER_3DES_CTR:
3123 case RTE_CRYPTO_CIPHER_AES_ECB:
3124 case RTE_CRYPTO_CIPHER_KASUMI_F8:
3125 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
3126 session->cipher_alg);
3129 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
3130 session->cipher_alg);
3138 dpaa2_sec_set_ipsec_session(struct rte_cryptodev *dev,
3139 struct rte_security_session_conf *conf,
3142 struct rte_security_ipsec_xform *ipsec_xform = &conf->ipsec;
3143 struct rte_crypto_cipher_xform *cipher_xform = NULL;
3144 struct rte_crypto_auth_xform *auth_xform = NULL;
3145 struct rte_crypto_aead_xform *aead_xform = NULL;
3146 dpaa2_sec_session *session = (dpaa2_sec_session *)sess;
3147 struct ctxt_priv *priv;
3148 struct alginfo authdata, cipherdata;
3150 struct sec_flow_context *flc;
3151 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
3154 PMD_INIT_FUNC_TRACE();
3156 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
3157 sizeof(struct ctxt_priv) +
3158 sizeof(struct sec_flc_desc),
3159 RTE_CACHE_LINE_SIZE);
3162 DPAA2_SEC_ERR("No memory for priv CTXT");
3166 priv->fle_pool = dev_priv->fle_pool;
3167 flc = &priv->flc_desc[0].flc;
3169 if (ipsec_xform->life.bytes_hard_limit != 0 ||
3170 ipsec_xform->life.bytes_soft_limit != 0 ||
3171 ipsec_xform->life.packets_hard_limit != 0 ||
3172 ipsec_xform->life.packets_soft_limit != 0)
3175 memset(session, 0, sizeof(dpaa2_sec_session));
3177 if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
3178 cipher_xform = &conf->crypto_xform->cipher;
3179 if (conf->crypto_xform->next)
3180 auth_xform = &conf->crypto_xform->next->auth;
3181 ret = dpaa2_sec_ipsec_proto_init(cipher_xform, auth_xform,
3182 session, &cipherdata, &authdata);
3183 } else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
3184 auth_xform = &conf->crypto_xform->auth;
3185 if (conf->crypto_xform->next)
3186 cipher_xform = &conf->crypto_xform->next->cipher;
3187 ret = dpaa2_sec_ipsec_proto_init(cipher_xform, auth_xform,
3188 session, &cipherdata, &authdata);
3189 } else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
3190 aead_xform = &conf->crypto_xform->aead;
3191 ret = dpaa2_sec_ipsec_aead_init(aead_xform,
3192 session, &cipherdata);
3193 authdata.keylen = 0;
3194 authdata.algtype = 0;
3196 DPAA2_SEC_ERR("XFORM not specified");
3201 DPAA2_SEC_ERR("Failed to process xform");
3205 session->ctxt_type = DPAA2_SEC_IPSEC;
3206 if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
3207 uint8_t *hdr = NULL;
3209 struct rte_ipv6_hdr ip6_hdr;
3210 struct ipsec_encap_pdb encap_pdb;
3212 flc->dhr = SEC_FLC_DHR_OUTBOUND;
3213 /* For Sec Proto only one descriptor is required. */
3214 memset(&encap_pdb, 0, sizeof(struct ipsec_encap_pdb));
3216 /* copy algo specific data to PDB */
3217 switch (cipherdata.algtype) {
3218 case OP_PCL_IPSEC_AES_CTR:
3219 encap_pdb.ctr.ctr_initial = 0x00000001;
3220 encap_pdb.ctr.ctr_nonce = ipsec_xform->salt;
3222 case OP_PCL_IPSEC_AES_GCM8:
3223 case OP_PCL_IPSEC_AES_GCM12:
3224 case OP_PCL_IPSEC_AES_GCM16:
3225 memcpy(encap_pdb.gcm.salt,
3226 (uint8_t *)&(ipsec_xform->salt), 4);
3230 encap_pdb.options = (IPVERSION << PDBNH_ESP_ENCAP_SHIFT) |
3231 PDBOPTS_ESP_OIHI_PDB_INL |
3234 if (ipsec_xform->options.dec_ttl)
3235 encap_pdb.options |= PDBHMO_ESP_ENCAP_DTTL;
3236 if (ipsec_xform->options.esn)
3237 encap_pdb.options |= PDBOPTS_ESP_ESN;
3238 encap_pdb.spi = ipsec_xform->spi;
3239 session->dir = DIR_ENC;
3240 if (ipsec_xform->tunnel.type ==
3241 RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
3242 encap_pdb.ip_hdr_len = sizeof(struct ip);
3243 ip4_hdr.ip_v = IPVERSION;
3245 ip4_hdr.ip_len = rte_cpu_to_be_16(sizeof(ip4_hdr));
3246 ip4_hdr.ip_tos = ipsec_xform->tunnel.ipv4.dscp;
3249 ip4_hdr.ip_ttl = ipsec_xform->tunnel.ipv4.ttl;
3250 ip4_hdr.ip_p = IPPROTO_ESP;
3252 ip4_hdr.ip_src = ipsec_xform->tunnel.ipv4.src_ip;
3253 ip4_hdr.ip_dst = ipsec_xform->tunnel.ipv4.dst_ip;
3254 ip4_hdr.ip_sum = calc_chksum((uint16_t *)(void *)
3255 &ip4_hdr, sizeof(struct ip));
3256 hdr = (uint8_t *)&ip4_hdr;
3257 } else if (ipsec_xform->tunnel.type ==
3258 RTE_SECURITY_IPSEC_TUNNEL_IPV6) {
3259 ip6_hdr.vtc_flow = rte_cpu_to_be_32(
3260 DPAA2_IPv6_DEFAULT_VTC_FLOW |
3261 ((ipsec_xform->tunnel.ipv6.dscp <<
3262 RTE_IPV6_HDR_TC_SHIFT) &
3263 RTE_IPV6_HDR_TC_MASK) |
3264 ((ipsec_xform->tunnel.ipv6.flabel <<
3265 RTE_IPV6_HDR_FL_SHIFT) &
3266 RTE_IPV6_HDR_FL_MASK));
3267 /* Payload length will be updated by HW */
3268 ip6_hdr.payload_len = 0;
3269 ip6_hdr.hop_limits =
3270 ipsec_xform->tunnel.ipv6.hlimit;
3271 ip6_hdr.proto = (ipsec_xform->proto ==
3272 RTE_SECURITY_IPSEC_SA_PROTO_ESP) ?
3273 IPPROTO_ESP : IPPROTO_AH;
3274 memcpy(&ip6_hdr.src_addr,
3275 &ipsec_xform->tunnel.ipv6.src_addr, 16);
3276 memcpy(&ip6_hdr.dst_addr,
3277 &ipsec_xform->tunnel.ipv6.dst_addr, 16);
3278 encap_pdb.ip_hdr_len = sizeof(struct rte_ipv6_hdr);
3279 hdr = (uint8_t *)&ip6_hdr;
3282 bufsize = cnstr_shdsc_ipsec_new_encap(priv->flc_desc[0].desc,
3283 1, 0, (rta_sec_era >= RTA_SEC_ERA_10) ?
3284 SHR_WAIT : SHR_SERIAL, &encap_pdb,
3285 hdr, &cipherdata, &authdata);
3286 } else if (ipsec_xform->direction ==
3287 RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
3288 struct ipsec_decap_pdb decap_pdb;
3290 flc->dhr = SEC_FLC_DHR_INBOUND;
3291 memset(&decap_pdb, 0, sizeof(struct ipsec_decap_pdb));
3292 /* copy algo specific data to PDB */
3293 switch (cipherdata.algtype) {
3294 case OP_PCL_IPSEC_AES_CTR:
3295 decap_pdb.ctr.ctr_initial = 0x00000001;
3296 decap_pdb.ctr.ctr_nonce = ipsec_xform->salt;
3298 case OP_PCL_IPSEC_AES_GCM8:
3299 case OP_PCL_IPSEC_AES_GCM12:
3300 case OP_PCL_IPSEC_AES_GCM16:
3301 memcpy(decap_pdb.gcm.salt,
3302 (uint8_t *)&(ipsec_xform->salt), 4);
3306 decap_pdb.options = (ipsec_xform->tunnel.type ==
3307 RTE_SECURITY_IPSEC_TUNNEL_IPV4) ?
3308 sizeof(struct ip) << 16 :
3309 sizeof(struct rte_ipv6_hdr) << 16;
3310 if (ipsec_xform->options.esn)
3311 decap_pdb.options |= PDBOPTS_ESP_ESN;
3313 if (ipsec_xform->replay_win_sz) {
3315 win_sz = rte_align32pow2(ipsec_xform->replay_win_sz);
3317 if (rta_sec_era < RTA_SEC_ERA_10 && win_sz > 128) {
3318 DPAA2_SEC_INFO("Max Anti replay Win sz = 128");
3328 decap_pdb.options |= PDBOPTS_ESP_ARS32;
3331 decap_pdb.options |= PDBOPTS_ESP_ARS64;
3334 decap_pdb.options |= PDBOPTS_ESP_ARS256;
3337 decap_pdb.options |= PDBOPTS_ESP_ARS512;
3340 decap_pdb.options |= PDBOPTS_ESP_ARS1024;
3344 decap_pdb.options |= PDBOPTS_ESP_ARS128;
3347 session->dir = DIR_DEC;
3348 bufsize = cnstr_shdsc_ipsec_new_decap(priv->flc_desc[0].desc,
3349 1, 0, (rta_sec_era >= RTA_SEC_ERA_10) ?
3350 SHR_WAIT : SHR_SERIAL,
3351 &decap_pdb, &cipherdata, &authdata);
3356 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
3360 flc->word1_sdl = (uint8_t)bufsize;
3362 /* Enable the stashing control bit */
3363 DPAA2_SET_FLC_RSC(flc);
3364 flc->word2_rflc_31_0 = lower_32_bits(
3365 (size_t)&(((struct dpaa2_sec_qp *)
3366 dev->data->queue_pairs[0])->rx_vq) | 0x14);
3367 flc->word3_rflc_63_32 = upper_32_bits(
3368 (size_t)&(((struct dpaa2_sec_qp *)
3369 dev->data->queue_pairs[0])->rx_vq));
3371 /* Set EWS bit i.e. enable write-safe */
3372 DPAA2_SET_FLC_EWS(flc);
3373 /* Set BS = 1 i.e reuse input buffers as output buffers */
3374 DPAA2_SET_FLC_REUSE_BS(flc);
3375 /* Set FF = 10; reuse input buffers if they provide sufficient space */
3376 DPAA2_SET_FLC_REUSE_FF(flc);
3378 session->ctxt = priv;
3382 rte_free(session->auth_key.data);
3383 rte_free(session->cipher_key.data);
3389 dpaa2_sec_set_pdcp_session(struct rte_cryptodev *dev,
3390 struct rte_security_session_conf *conf,
3393 struct rte_security_pdcp_xform *pdcp_xform = &conf->pdcp;
3394 struct rte_crypto_sym_xform *xform = conf->crypto_xform;
3395 struct rte_crypto_auth_xform *auth_xform = NULL;
3396 struct rte_crypto_cipher_xform *cipher_xform = NULL;
3397 dpaa2_sec_session *session = (dpaa2_sec_session *)sess;
3398 struct ctxt_priv *priv;
3399 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
3400 struct alginfo authdata, cipherdata;
3401 struct alginfo *p_authdata = NULL;
3403 struct sec_flow_context *flc;
3404 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
3410 PMD_INIT_FUNC_TRACE();
3412 memset(session, 0, sizeof(dpaa2_sec_session));
3414 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
3415 sizeof(struct ctxt_priv) +
3416 sizeof(struct sec_flc_desc),
3417 RTE_CACHE_LINE_SIZE);
3420 DPAA2_SEC_ERR("No memory for priv CTXT");
3424 priv->fle_pool = dev_priv->fle_pool;
3425 flc = &priv->flc_desc[0].flc;
3427 /* find xfrm types */
3428 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
3429 cipher_xform = &xform->cipher;
3430 if (xform->next != NULL &&
3431 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
3432 session->ext_params.aead_ctxt.auth_cipher_text = true;
3433 auth_xform = &xform->next->auth;
3435 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
3436 auth_xform = &xform->auth;
3437 if (xform->next != NULL &&
3438 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
3439 session->ext_params.aead_ctxt.auth_cipher_text = false;
3440 cipher_xform = &xform->next->cipher;
3443 DPAA2_SEC_ERR("Invalid crypto type");
3447 session->ctxt_type = DPAA2_SEC_PDCP;
3449 session->cipher_key.data = rte_zmalloc(NULL,
3450 cipher_xform->key.length,
3451 RTE_CACHE_LINE_SIZE);
3452 if (session->cipher_key.data == NULL &&
3453 cipher_xform->key.length > 0) {
3454 DPAA2_SEC_ERR("No Memory for cipher key");
3458 session->cipher_key.length = cipher_xform->key.length;
3459 memcpy(session->cipher_key.data, cipher_xform->key.data,
3460 cipher_xform->key.length);
3462 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
3464 session->cipher_alg = cipher_xform->algo;
3466 session->cipher_key.data = NULL;
3467 session->cipher_key.length = 0;
3468 session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
3469 session->dir = DIR_ENC;
3472 session->pdcp.domain = pdcp_xform->domain;
3473 session->pdcp.bearer = pdcp_xform->bearer;
3474 session->pdcp.pkt_dir = pdcp_xform->pkt_dir;
3475 session->pdcp.sn_size = pdcp_xform->sn_size;
3476 session->pdcp.hfn = pdcp_xform->hfn;
3477 session->pdcp.hfn_threshold = pdcp_xform->hfn_threshold;
3478 session->pdcp.hfn_ovd = pdcp_xform->hfn_ovrd;
3479 /* hfv ovd offset location is stored in iv.offset value*/
3481 session->pdcp.hfn_ovd_offset = cipher_xform->iv.offset;
3483 cipherdata.key = (size_t)session->cipher_key.data;
3484 cipherdata.keylen = session->cipher_key.length;
3485 cipherdata.key_enc_flags = 0;
3486 cipherdata.key_type = RTA_DATA_IMM;
3488 switch (session->cipher_alg) {
3489 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
3490 cipherdata.algtype = PDCP_CIPHER_TYPE_SNOW;
3492 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
3493 cipherdata.algtype = PDCP_CIPHER_TYPE_ZUC;
3495 case RTE_CRYPTO_CIPHER_AES_CTR:
3496 cipherdata.algtype = PDCP_CIPHER_TYPE_AES;
3498 case RTE_CRYPTO_CIPHER_NULL:
3499 cipherdata.algtype = PDCP_CIPHER_TYPE_NULL;
3502 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
3503 session->cipher_alg);
3508 session->auth_key.data = rte_zmalloc(NULL,
3509 auth_xform->key.length,
3510 RTE_CACHE_LINE_SIZE);
3511 if (!session->auth_key.data &&
3512 auth_xform->key.length > 0) {
3513 DPAA2_SEC_ERR("No Memory for auth key");
3514 rte_free(session->cipher_key.data);
3518 session->auth_key.length = auth_xform->key.length;
3519 memcpy(session->auth_key.data, auth_xform->key.data,
3520 auth_xform->key.length);
3521 session->auth_alg = auth_xform->algo;
3523 session->auth_key.data = NULL;
3524 session->auth_key.length = 0;
3525 session->auth_alg = 0;
3527 authdata.key = (size_t)session->auth_key.data;
3528 authdata.keylen = session->auth_key.length;
3529 authdata.key_enc_flags = 0;
3530 authdata.key_type = RTA_DATA_IMM;
3532 if (session->auth_alg) {
3533 switch (session->auth_alg) {
3534 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
3535 authdata.algtype = PDCP_AUTH_TYPE_SNOW;
3537 case RTE_CRYPTO_AUTH_ZUC_EIA3:
3538 authdata.algtype = PDCP_AUTH_TYPE_ZUC;
3540 case RTE_CRYPTO_AUTH_AES_CMAC:
3541 authdata.algtype = PDCP_AUTH_TYPE_AES;
3543 case RTE_CRYPTO_AUTH_NULL:
3544 authdata.algtype = PDCP_AUTH_TYPE_NULL;
3547 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
3552 p_authdata = &authdata;
3553 } else if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
3554 DPAA2_SEC_ERR("Crypto: Integrity must for c-plane");
3558 if (pdcp_xform->sdap_enabled) {
3559 int nb_keys_to_inline =
3560 rta_inline_pdcp_sdap_query(authdata.algtype,
3562 session->pdcp.sn_size,
3563 session->pdcp.hfn_ovd);
3564 if (nb_keys_to_inline >= 1) {
3565 cipherdata.key = DPAA2_VADDR_TO_IOVA(cipherdata.key);
3566 cipherdata.key_type = RTA_DATA_PTR;
3568 if (nb_keys_to_inline >= 2) {
3569 authdata.key = DPAA2_VADDR_TO_IOVA(authdata.key);
3570 authdata.key_type = RTA_DATA_PTR;
3573 if (rta_inline_pdcp_query(authdata.algtype,
3575 session->pdcp.sn_size,
3576 session->pdcp.hfn_ovd)) {
3577 cipherdata.key = DPAA2_VADDR_TO_IOVA(cipherdata.key);
3578 cipherdata.key_type = RTA_DATA_PTR;
3582 if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
3583 if (session->dir == DIR_ENC)
3584 bufsize = cnstr_shdsc_pdcp_c_plane_encap(
3585 priv->flc_desc[0].desc, 1, swap,
3587 session->pdcp.sn_size,
3589 pdcp_xform->pkt_dir,
3590 pdcp_xform->hfn_threshold,
3591 &cipherdata, &authdata);
3592 else if (session->dir == DIR_DEC)
3593 bufsize = cnstr_shdsc_pdcp_c_plane_decap(
3594 priv->flc_desc[0].desc, 1, swap,
3596 session->pdcp.sn_size,
3598 pdcp_xform->pkt_dir,
3599 pdcp_xform->hfn_threshold,
3600 &cipherdata, &authdata);
3602 } else if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_SHORT_MAC) {
3603 bufsize = cnstr_shdsc_pdcp_short_mac(priv->flc_desc[0].desc,
3604 1, swap, &authdata);
3606 if (session->dir == DIR_ENC) {
3607 if (pdcp_xform->sdap_enabled)
3608 bufsize = cnstr_shdsc_pdcp_sdap_u_plane_encap(
3609 priv->flc_desc[0].desc, 1, swap,
3610 session->pdcp.sn_size,
3613 pdcp_xform->pkt_dir,
3614 pdcp_xform->hfn_threshold,
3615 &cipherdata, p_authdata);
3617 bufsize = cnstr_shdsc_pdcp_u_plane_encap(
3618 priv->flc_desc[0].desc, 1, swap,
3619 session->pdcp.sn_size,
3622 pdcp_xform->pkt_dir,
3623 pdcp_xform->hfn_threshold,
3624 &cipherdata, p_authdata);
3625 } else if (session->dir == DIR_DEC) {
3626 if (pdcp_xform->sdap_enabled)
3627 bufsize = cnstr_shdsc_pdcp_sdap_u_plane_decap(
3628 priv->flc_desc[0].desc, 1, swap,
3629 session->pdcp.sn_size,
3632 pdcp_xform->pkt_dir,
3633 pdcp_xform->hfn_threshold,
3634 &cipherdata, p_authdata);
3636 bufsize = cnstr_shdsc_pdcp_u_plane_decap(
3637 priv->flc_desc[0].desc, 1, swap,
3638 session->pdcp.sn_size,
3641 pdcp_xform->pkt_dir,
3642 pdcp_xform->hfn_threshold,
3643 &cipherdata, p_authdata);
3648 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
3652 /* Enable the stashing control bit */
3653 DPAA2_SET_FLC_RSC(flc);
3654 flc->word2_rflc_31_0 = lower_32_bits(
3655 (size_t)&(((struct dpaa2_sec_qp *)
3656 dev->data->queue_pairs[0])->rx_vq) | 0x14);
3657 flc->word3_rflc_63_32 = upper_32_bits(
3658 (size_t)&(((struct dpaa2_sec_qp *)
3659 dev->data->queue_pairs[0])->rx_vq));
3661 flc->word1_sdl = (uint8_t)bufsize;
3663 /* TODO - check the perf impact or
3664 * align as per descriptor type
3665 * Set EWS bit i.e. enable write-safe
3666 * DPAA2_SET_FLC_EWS(flc);
3669 /* Set BS = 1 i.e reuse input buffers as output buffers */
3670 DPAA2_SET_FLC_REUSE_BS(flc);
3671 /* Set FF = 10; reuse input buffers if they provide sufficient space */
3672 DPAA2_SET_FLC_REUSE_FF(flc);
3674 session->ctxt = priv;
3678 rte_free(session->auth_key.data);
3679 rte_free(session->cipher_key.data);
3685 dpaa2_sec_security_session_create(void *dev,
3686 struct rte_security_session_conf *conf,
3687 struct rte_security_session *sess,
3688 struct rte_mempool *mempool)
3690 void *sess_private_data;
3691 struct rte_cryptodev *cdev = (struct rte_cryptodev *)dev;
3694 if (rte_mempool_get(mempool, &sess_private_data)) {
3695 DPAA2_SEC_ERR("Couldn't get object from session mempool");
3699 switch (conf->protocol) {
3700 case RTE_SECURITY_PROTOCOL_IPSEC:
3701 ret = dpaa2_sec_set_ipsec_session(cdev, conf,
3704 case RTE_SECURITY_PROTOCOL_MACSEC:
3706 case RTE_SECURITY_PROTOCOL_PDCP:
3707 ret = dpaa2_sec_set_pdcp_session(cdev, conf,
3714 DPAA2_SEC_ERR("Failed to configure session parameters");
3715 /* Return session to mempool */
3716 rte_mempool_put(mempool, sess_private_data);
3720 set_sec_session_private_data(sess, sess_private_data);
3725 /** Clear the memory of session so it doesn't leave key material behind */
3727 dpaa2_sec_security_session_destroy(void *dev __rte_unused,
3728 struct rte_security_session *sess)
3730 PMD_INIT_FUNC_TRACE();
3731 void *sess_priv = get_sec_session_private_data(sess);
3733 dpaa2_sec_session *s = (dpaa2_sec_session *)sess_priv;
3736 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
3739 rte_free(s->cipher_key.data);
3740 rte_free(s->auth_key.data);
3741 memset(s, 0, sizeof(dpaa2_sec_session));
3742 set_sec_session_private_data(sess, NULL);
3743 rte_mempool_put(sess_mp, sess_priv);
3749 dpaa2_sec_sym_session_configure(struct rte_cryptodev *dev,
3750 struct rte_crypto_sym_xform *xform,
3751 struct rte_cryptodev_sym_session *sess,
3752 struct rte_mempool *mempool)
3754 void *sess_private_data;
3757 if (rte_mempool_get(mempool, &sess_private_data)) {
3758 DPAA2_SEC_ERR("Couldn't get object from session mempool");
3762 ret = dpaa2_sec_set_session_parameters(dev, xform, sess_private_data);
3764 DPAA2_SEC_ERR("Failed to configure session parameters");
3765 /* Return session to mempool */
3766 rte_mempool_put(mempool, sess_private_data);
3770 set_sym_session_private_data(sess, dev->driver_id,
3776 /** Clear the memory of session so it doesn't leave key material behind */
3778 dpaa2_sec_sym_session_clear(struct rte_cryptodev *dev,
3779 struct rte_cryptodev_sym_session *sess)
3781 PMD_INIT_FUNC_TRACE();
3782 uint8_t index = dev->driver_id;
3783 void *sess_priv = get_sym_session_private_data(sess, index);
3784 dpaa2_sec_session *s = (dpaa2_sec_session *)sess_priv;
3788 rte_free(s->cipher_key.data);
3789 rte_free(s->auth_key.data);
3790 memset(s, 0, sizeof(dpaa2_sec_session));
3791 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
3792 set_sym_session_private_data(sess, index, NULL);
3793 rte_mempool_put(sess_mp, sess_priv);
3798 dpaa2_sec_dev_configure(struct rte_cryptodev *dev __rte_unused,
3799 struct rte_cryptodev_config *config __rte_unused)
3801 PMD_INIT_FUNC_TRACE();
3807 dpaa2_sec_dev_start(struct rte_cryptodev *dev)
3809 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3810 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3811 struct dpseci_attr attr;
3812 struct dpaa2_queue *dpaa2_q;
3813 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3814 dev->data->queue_pairs;
3815 struct dpseci_rx_queue_attr rx_attr;
3816 struct dpseci_tx_queue_attr tx_attr;
3819 PMD_INIT_FUNC_TRACE();
3821 /* Change the tx burst function if ordered queues are used */
3822 if (priv->en_ordered)
3823 dev->enqueue_burst = dpaa2_sec_enqueue_burst_ordered;
3825 memset(&attr, 0, sizeof(struct dpseci_attr));
3827 ret = dpseci_enable(dpseci, CMD_PRI_LOW, priv->token);
3829 DPAA2_SEC_ERR("DPSECI with HW_ID = %d ENABLE FAILED",
3831 goto get_attr_failure;
3833 ret = dpseci_get_attributes(dpseci, CMD_PRI_LOW, priv->token, &attr);
3835 DPAA2_SEC_ERR("DPSEC ATTRIBUTE READ FAILED, disabling DPSEC");
3836 goto get_attr_failure;
3838 for (i = 0; i < attr.num_rx_queues && qp[i]; i++) {
3839 dpaa2_q = &qp[i]->rx_vq;
3840 dpseci_get_rx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
3842 dpaa2_q->fqid = rx_attr.fqid;
3843 DPAA2_SEC_DEBUG("rx_fqid: %d", dpaa2_q->fqid);
3845 for (i = 0; i < attr.num_tx_queues && qp[i]; i++) {
3846 dpaa2_q = &qp[i]->tx_vq;
3847 dpseci_get_tx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
3849 dpaa2_q->fqid = tx_attr.fqid;
3850 DPAA2_SEC_DEBUG("tx_fqid: %d", dpaa2_q->fqid);
3855 dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
3860 dpaa2_sec_dev_stop(struct rte_cryptodev *dev)
3862 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3863 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3866 PMD_INIT_FUNC_TRACE();
3868 ret = dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
3870 DPAA2_SEC_ERR("Failure in disabling dpseci %d device",
3875 ret = dpseci_reset(dpseci, CMD_PRI_LOW, priv->token);
3877 DPAA2_SEC_ERR("SEC Device cannot be reset:Error = %0x", ret);
3883 dpaa2_sec_dev_close(struct rte_cryptodev *dev __rte_unused)
3885 PMD_INIT_FUNC_TRACE();
3891 dpaa2_sec_dev_infos_get(struct rte_cryptodev *dev,
3892 struct rte_cryptodev_info *info)
3894 struct dpaa2_sec_dev_private *internals = dev->data->dev_private;
3896 PMD_INIT_FUNC_TRACE();
3898 info->max_nb_queue_pairs = internals->max_nb_queue_pairs;
3899 info->feature_flags = dev->feature_flags;
3900 info->capabilities = dpaa2_sec_capabilities;
3901 /* No limit of number of sessions */
3902 info->sym.max_nb_sessions = 0;
3903 info->driver_id = cryptodev_driver_id;
3908 void dpaa2_sec_stats_get(struct rte_cryptodev *dev,
3909 struct rte_cryptodev_stats *stats)
3911 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3912 struct fsl_mc_io dpseci;
3913 struct dpseci_sec_counters counters = {0};
3914 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3915 dev->data->queue_pairs;
3918 PMD_INIT_FUNC_TRACE();
3919 if (stats == NULL) {
3920 DPAA2_SEC_ERR("Invalid stats ptr NULL");
3923 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
3924 if (qp == NULL || qp[i] == NULL) {
3925 DPAA2_SEC_DEBUG("Uninitialised queue pair");
3929 stats->enqueued_count += qp[i]->tx_vq.tx_pkts;
3930 stats->dequeued_count += qp[i]->rx_vq.rx_pkts;
3931 stats->enqueue_err_count += qp[i]->tx_vq.err_pkts;
3932 stats->dequeue_err_count += qp[i]->rx_vq.err_pkts;
3935 /* In case as secondary process access stats, MCP portal in priv-hw
3936 * may have primary process address. Need the secondary process
3937 * based MCP portal address for this object.
3939 dpseci.regs = dpaa2_get_mcp_ptr(MC_PORTAL_INDEX);
3940 ret = dpseci_get_sec_counters(&dpseci, CMD_PRI_LOW, priv->token,
3943 DPAA2_SEC_ERR("SEC counters failed");
3945 DPAA2_SEC_INFO("dpseci hardware stats:"
3946 "\n\tNum of Requests Dequeued = %" PRIu64
3947 "\n\tNum of Outbound Encrypt Requests = %" PRIu64
3948 "\n\tNum of Inbound Decrypt Requests = %" PRIu64
3949 "\n\tNum of Outbound Bytes Encrypted = %" PRIu64
3950 "\n\tNum of Outbound Bytes Protected = %" PRIu64
3951 "\n\tNum of Inbound Bytes Decrypted = %" PRIu64
3952 "\n\tNum of Inbound Bytes Validated = %" PRIu64,
3953 counters.dequeued_requests,
3954 counters.ob_enc_requests,
3955 counters.ib_dec_requests,
3956 counters.ob_enc_bytes,
3957 counters.ob_prot_bytes,
3958 counters.ib_dec_bytes,
3959 counters.ib_valid_bytes);
3964 void dpaa2_sec_stats_reset(struct rte_cryptodev *dev)
3967 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3968 (dev->data->queue_pairs);
3970 PMD_INIT_FUNC_TRACE();
3972 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
3973 if (qp[i] == NULL) {
3974 DPAA2_SEC_DEBUG("Uninitialised queue pair");
3977 qp[i]->tx_vq.rx_pkts = 0;
3978 qp[i]->tx_vq.tx_pkts = 0;
3979 qp[i]->tx_vq.err_pkts = 0;
3980 qp[i]->rx_vq.rx_pkts = 0;
3981 qp[i]->rx_vq.tx_pkts = 0;
3982 qp[i]->rx_vq.err_pkts = 0;
3986 static void __rte_hot
3987 dpaa2_sec_process_parallel_event(struct qbman_swp *swp,
3988 const struct qbman_fd *fd,
3989 const struct qbman_result *dq,
3990 struct dpaa2_queue *rxq,
3991 struct rte_event *ev)
3993 /* Prefetching mbuf */
3994 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-
3995 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size));
3997 /* Prefetching ipsec crypto_op stored in priv data of mbuf */
3998 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-64));
4000 ev->flow_id = rxq->ev.flow_id;
4001 ev->sub_event_type = rxq->ev.sub_event_type;
4002 ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
4003 ev->op = RTE_EVENT_OP_NEW;
4004 ev->sched_type = rxq->ev.sched_type;
4005 ev->queue_id = rxq->ev.queue_id;
4006 ev->priority = rxq->ev.priority;
4007 ev->event_ptr = sec_fd_to_mbuf(fd);
4009 qbman_swp_dqrr_consume(swp, dq);
4012 dpaa2_sec_process_atomic_event(struct qbman_swp *swp __rte_unused,
4013 const struct qbman_fd *fd,
4014 const struct qbman_result *dq,
4015 struct dpaa2_queue *rxq,
4016 struct rte_event *ev)
4019 struct rte_crypto_op *crypto_op = (struct rte_crypto_op *)ev->event_ptr;
4020 /* Prefetching mbuf */
4021 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-
4022 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size));
4024 /* Prefetching ipsec crypto_op stored in priv data of mbuf */
4025 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-64));
4027 ev->flow_id = rxq->ev.flow_id;
4028 ev->sub_event_type = rxq->ev.sub_event_type;
4029 ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
4030 ev->op = RTE_EVENT_OP_NEW;
4031 ev->sched_type = rxq->ev.sched_type;
4032 ev->queue_id = rxq->ev.queue_id;
4033 ev->priority = rxq->ev.priority;
4035 ev->event_ptr = sec_fd_to_mbuf(fd);
4036 dqrr_index = qbman_get_dqrr_idx(dq);
4037 *dpaa2_seqn(crypto_op->sym->m_src) = QBMAN_ENQUEUE_FLAG_DCA | dqrr_index;
4038 DPAA2_PER_LCORE_DQRR_SIZE++;
4039 DPAA2_PER_LCORE_DQRR_HELD |= 1 << dqrr_index;
4040 DPAA2_PER_LCORE_DQRR_MBUF(dqrr_index) = crypto_op->sym->m_src;
4043 static void __rte_hot
4044 dpaa2_sec_process_ordered_event(struct qbman_swp *swp,
4045 const struct qbman_fd *fd,
4046 const struct qbman_result *dq,
4047 struct dpaa2_queue *rxq,
4048 struct rte_event *ev)
4050 struct rte_crypto_op *crypto_op = (struct rte_crypto_op *)ev->event_ptr;
4052 /* Prefetching mbuf */
4053 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-
4054 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size));
4056 /* Prefetching ipsec crypto_op stored in priv data of mbuf */
4057 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-64));
4059 ev->flow_id = rxq->ev.flow_id;
4060 ev->sub_event_type = rxq->ev.sub_event_type;
4061 ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
4062 ev->op = RTE_EVENT_OP_NEW;
4063 ev->sched_type = rxq->ev.sched_type;
4064 ev->queue_id = rxq->ev.queue_id;
4065 ev->priority = rxq->ev.priority;
4066 ev->event_ptr = sec_fd_to_mbuf(fd);
4068 *dpaa2_seqn(crypto_op->sym->m_src) = DPAA2_ENQUEUE_FLAG_ORP;
4069 *dpaa2_seqn(crypto_op->sym->m_src) |= qbman_result_DQ_odpid(dq) <<
4070 DPAA2_EQCR_OPRID_SHIFT;
4071 *dpaa2_seqn(crypto_op->sym->m_src) |= qbman_result_DQ_seqnum(dq) <<
4072 DPAA2_EQCR_SEQNUM_SHIFT;
4074 qbman_swp_dqrr_consume(swp, dq);
4078 dpaa2_sec_eventq_attach(const struct rte_cryptodev *dev,
4080 struct dpaa2_dpcon_dev *dpcon,
4081 const struct rte_event *event)
4083 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
4084 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
4085 struct dpaa2_sec_qp *qp = dev->data->queue_pairs[qp_id];
4086 struct dpseci_rx_queue_cfg cfg;
4090 if (event->sched_type == RTE_SCHED_TYPE_PARALLEL)
4091 qp->rx_vq.cb = dpaa2_sec_process_parallel_event;
4092 else if (event->sched_type == RTE_SCHED_TYPE_ATOMIC)
4093 qp->rx_vq.cb = dpaa2_sec_process_atomic_event;
4094 else if (event->sched_type == RTE_SCHED_TYPE_ORDERED)
4095 qp->rx_vq.cb = dpaa2_sec_process_ordered_event;
4099 priority = (RTE_EVENT_DEV_PRIORITY_LOWEST / event->priority) *
4100 (dpcon->num_priorities - 1);
4102 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
4103 cfg.options = DPSECI_QUEUE_OPT_DEST;
4104 cfg.dest_cfg.dest_type = DPSECI_DEST_DPCON;
4105 cfg.dest_cfg.dest_id = dpcon->dpcon_id;
4106 cfg.dest_cfg.priority = priority;
4108 cfg.options |= DPSECI_QUEUE_OPT_USER_CTX;
4109 cfg.user_ctx = (size_t)(qp);
4110 if (event->sched_type == RTE_SCHED_TYPE_ATOMIC) {
4111 cfg.options |= DPSECI_QUEUE_OPT_ORDER_PRESERVATION;
4112 cfg.order_preservation_en = 1;
4115 if (event->sched_type == RTE_SCHED_TYPE_ORDERED) {
4116 struct opr_cfg ocfg;
4118 /* Restoration window size = 256 frames */
4120 /* Restoration window size = 512 frames for LX2 */
4121 if (dpaa2_svr_family == SVR_LX2160A)
4123 /* Auto advance NESN window enabled */
4125 /* Late arrival window size disabled */
4127 /* ORL resource exhaustaion advance NESN disabled */
4130 if (priv->en_loose_ordered)
4135 ret = dpseci_set_opr(dpseci, CMD_PRI_LOW, priv->token,
4136 qp_id, OPR_OPT_CREATE, &ocfg);
4138 RTE_LOG(ERR, PMD, "Error setting opr: ret: %d\n", ret);
4141 qp->tx_vq.cb_eqresp_free = dpaa2_sec_free_eqresp_buf;
4142 priv->en_ordered = 1;
4145 ret = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
4148 RTE_LOG(ERR, PMD, "Error in dpseci_set_queue: ret: %d\n", ret);
4152 memcpy(&qp->rx_vq.ev, event, sizeof(struct rte_event));
4158 dpaa2_sec_eventq_detach(const struct rte_cryptodev *dev,
4161 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
4162 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
4163 struct dpseci_rx_queue_cfg cfg;
4166 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
4167 cfg.options = DPSECI_QUEUE_OPT_DEST;
4168 cfg.dest_cfg.dest_type = DPSECI_DEST_NONE;
4170 ret = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
4173 RTE_LOG(ERR, PMD, "Error in dpseci_set_queue: ret: %d\n", ret);
4178 static struct rte_cryptodev_ops crypto_ops = {
4179 .dev_configure = dpaa2_sec_dev_configure,
4180 .dev_start = dpaa2_sec_dev_start,
4181 .dev_stop = dpaa2_sec_dev_stop,
4182 .dev_close = dpaa2_sec_dev_close,
4183 .dev_infos_get = dpaa2_sec_dev_infos_get,
4184 .stats_get = dpaa2_sec_stats_get,
4185 .stats_reset = dpaa2_sec_stats_reset,
4186 .queue_pair_setup = dpaa2_sec_queue_pair_setup,
4187 .queue_pair_release = dpaa2_sec_queue_pair_release,
4188 .sym_session_get_size = dpaa2_sec_sym_session_get_size,
4189 .sym_session_configure = dpaa2_sec_sym_session_configure,
4190 .sym_session_clear = dpaa2_sec_sym_session_clear,
4191 /* Raw data-path API related operations */
4192 .sym_get_raw_dp_ctx_size = dpaa2_sec_get_dp_ctx_size,
4193 .sym_configure_raw_dp_ctx = dpaa2_sec_configure_raw_dp_ctx,
4196 #ifdef RTE_LIB_SECURITY
4197 static const struct rte_security_capability *
4198 dpaa2_sec_capabilities_get(void *device __rte_unused)
4200 return dpaa2_sec_security_cap;
4203 static const struct rte_security_ops dpaa2_sec_security_ops = {
4204 .session_create = dpaa2_sec_security_session_create,
4205 .session_update = NULL,
4206 .session_stats_get = NULL,
4207 .session_destroy = dpaa2_sec_security_session_destroy,
4208 .set_pkt_metadata = NULL,
4209 .capabilities_get = dpaa2_sec_capabilities_get
4214 dpaa2_sec_uninit(const struct rte_cryptodev *dev)
4216 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
4217 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
4220 PMD_INIT_FUNC_TRACE();
4222 /* Function is reverse of dpaa2_sec_dev_init.
4223 * It does the following:
4224 * 1. Detach a DPSECI from attached resources i.e. buffer pools, dpbp_id
4225 * 2. Close the DPSECI device
4226 * 3. Free the allocated resources.
4229 /*Close the device at underlying layer*/
4230 ret = dpseci_close(dpseci, CMD_PRI_LOW, priv->token);
4232 DPAA2_SEC_ERR("Failure closing dpseci device: err(%d)", ret);
4236 /*Free the allocated memory for ethernet private data and dpseci*/
4239 rte_free(dev->security_ctx);
4240 rte_mempool_free(priv->fle_pool);
4242 DPAA2_SEC_INFO("Closing DPAA2_SEC device %s on numa socket %u",
4243 dev->data->name, rte_socket_id());
4249 check_devargs_handler(const char *key, const char *value,
4252 struct rte_cryptodev *dev = (struct rte_cryptodev *)opaque;
4253 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
4255 if (!strcmp(key, "drv_strict_order")) {
4256 priv->en_loose_ordered = false;
4257 } else if (!strcmp(key, "drv_dump_mode")) {
4258 dpaa2_sec_dp_dump = atoi(value);
4259 if (dpaa2_sec_dp_dump > DPAA2_SEC_DP_FULL_DUMP) {
4260 DPAA2_SEC_WARN("WARN: DPAA2_SEC_DP_DUMP_LEVEL is not "
4261 "supported, changing to FULL error"
4263 dpaa2_sec_dp_dump = DPAA2_SEC_DP_FULL_DUMP;
4272 dpaa2_sec_get_devargs(struct rte_cryptodev *cryptodev, const char *key)
4274 struct rte_kvargs *kvlist;
4275 struct rte_devargs *devargs;
4277 devargs = cryptodev->device->devargs;
4281 kvlist = rte_kvargs_parse(devargs->args, NULL);
4285 if (!rte_kvargs_count(kvlist, key)) {
4286 rte_kvargs_free(kvlist);
4290 rte_kvargs_process(kvlist, key,
4291 check_devargs_handler, (void *)cryptodev);
4292 rte_kvargs_free(kvlist);
4296 dpaa2_sec_dev_init(struct rte_cryptodev *cryptodev)
4298 struct dpaa2_sec_dev_private *internals;
4299 struct rte_device *dev = cryptodev->device;
4300 struct rte_dpaa2_device *dpaa2_dev;
4301 #ifdef RTE_LIB_SECURITY
4302 struct rte_security_ctx *security_instance;
4304 struct fsl_mc_io *dpseci;
4306 struct dpseci_attr attr;
4310 PMD_INIT_FUNC_TRACE();
4311 dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
4312 hw_id = dpaa2_dev->object_id;
4314 cryptodev->driver_id = cryptodev_driver_id;
4315 cryptodev->dev_ops = &crypto_ops;
4317 cryptodev->enqueue_burst = dpaa2_sec_enqueue_burst;
4318 cryptodev->dequeue_burst = dpaa2_sec_dequeue_burst;
4319 cryptodev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
4320 RTE_CRYPTODEV_FF_HW_ACCELERATED |
4321 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
4322 RTE_CRYPTODEV_FF_SECURITY |
4323 RTE_CRYPTODEV_FF_SYM_RAW_DP |
4324 RTE_CRYPTODEV_FF_IN_PLACE_SGL |
4325 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT |
4326 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
4327 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT |
4328 RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT;
4330 internals = cryptodev->data->dev_private;
4333 * For secondary processes, we don't initialise any further as primary
4334 * has already done this work. Only check we don't need a different
4337 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
4338 DPAA2_SEC_DEBUG("Device already init by primary process");
4341 #ifdef RTE_LIB_SECURITY
4342 /* Initialize security_ctx only for primary process*/
4343 security_instance = rte_malloc("rte_security_instances_ops",
4344 sizeof(struct rte_security_ctx), 0);
4345 if (security_instance == NULL)
4347 security_instance->device = (void *)cryptodev;
4348 security_instance->ops = &dpaa2_sec_security_ops;
4349 security_instance->sess_cnt = 0;
4350 cryptodev->security_ctx = security_instance;
4352 /*Open the rte device via MC and save the handle for further use*/
4353 dpseci = (struct fsl_mc_io *)rte_calloc(NULL, 1,
4354 sizeof(struct fsl_mc_io), 0);
4357 "Error in allocating the memory for dpsec object");
4360 dpseci->regs = dpaa2_get_mcp_ptr(MC_PORTAL_INDEX);
4362 retcode = dpseci_open(dpseci, CMD_PRI_LOW, hw_id, &token);
4364 DPAA2_SEC_ERR("Cannot open the dpsec device: Error = %x",
4368 retcode = dpseci_get_attributes(dpseci, CMD_PRI_LOW, token, &attr);
4371 "Cannot get dpsec device attributed: Error = %x",
4375 snprintf(cryptodev->data->name, sizeof(cryptodev->data->name),
4378 internals->max_nb_queue_pairs = attr.num_tx_queues;
4379 cryptodev->data->nb_queue_pairs = internals->max_nb_queue_pairs;
4380 internals->hw = dpseci;
4381 internals->token = token;
4382 internals->en_loose_ordered = true;
4384 snprintf(str, sizeof(str), "sec_fle_pool_p%d_%d",
4385 getpid(), cryptodev->data->dev_id);
4386 internals->fle_pool = rte_mempool_create((const char *)str,
4389 FLE_POOL_CACHE_SIZE, 0,
4390 NULL, NULL, NULL, NULL,
4392 if (!internals->fle_pool) {
4393 DPAA2_SEC_ERR("Mempool (%s) creation failed", str);
4397 dpaa2_sec_get_devargs(cryptodev, DRIVER_DUMP_MODE);
4398 dpaa2_sec_get_devargs(cryptodev, DRIVER_STRICT_ORDER);
4399 DPAA2_SEC_INFO("driver %s: created", cryptodev->data->name);
4403 DPAA2_SEC_ERR("driver %s: create failed", cryptodev->data->name);
4405 /* dpaa2_sec_uninit(crypto_dev_name); */
4410 cryptodev_dpaa2_sec_probe(struct rte_dpaa2_driver *dpaa2_drv __rte_unused,
4411 struct rte_dpaa2_device *dpaa2_dev)
4413 struct rte_cryptodev *cryptodev;
4414 char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
4418 snprintf(cryptodev_name, sizeof(cryptodev_name), "dpsec-%d",
4419 dpaa2_dev->object_id);
4421 cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
4422 if (cryptodev == NULL)
4425 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
4426 cryptodev->data->dev_private = rte_zmalloc_socket(
4427 "cryptodev private structure",
4428 sizeof(struct dpaa2_sec_dev_private),
4429 RTE_CACHE_LINE_SIZE,
4432 if (cryptodev->data->dev_private == NULL)
4433 rte_panic("Cannot allocate memzone for private "
4437 dpaa2_dev->cryptodev = cryptodev;
4438 cryptodev->device = &dpaa2_dev->device;
4440 /* init user callbacks */
4441 TAILQ_INIT(&(cryptodev->link_intr_cbs));
4443 if (dpaa2_svr_family == SVR_LX2160A)
4444 rta_set_sec_era(RTA_SEC_ERA_10);
4446 rta_set_sec_era(RTA_SEC_ERA_8);
4448 DPAA2_SEC_INFO("2-SEC ERA is %d", rta_get_sec_era());
4450 /* Invoke PMD device initialization function */
4451 retval = dpaa2_sec_dev_init(cryptodev);
4453 rte_cryptodev_pmd_probing_finish(cryptodev);
4457 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
4458 rte_free(cryptodev->data->dev_private);
4460 cryptodev->attached = RTE_CRYPTODEV_DETACHED;
4466 cryptodev_dpaa2_sec_remove(struct rte_dpaa2_device *dpaa2_dev)
4468 struct rte_cryptodev *cryptodev;
4471 cryptodev = dpaa2_dev->cryptodev;
4472 if (cryptodev == NULL)
4475 ret = dpaa2_sec_uninit(cryptodev);
4479 return rte_cryptodev_pmd_destroy(cryptodev);
4482 static struct rte_dpaa2_driver rte_dpaa2_sec_driver = {
4483 .drv_flags = RTE_DPAA2_DRV_IOVA_AS_VA,
4484 .drv_type = DPAA2_CRYPTO,
4486 .name = "DPAA2 SEC PMD"
4488 .probe = cryptodev_dpaa2_sec_probe,
4489 .remove = cryptodev_dpaa2_sec_remove,
4492 static struct cryptodev_driver dpaa2_sec_crypto_drv;
4494 RTE_PMD_REGISTER_DPAA2(CRYPTODEV_NAME_DPAA2_SEC_PMD, rte_dpaa2_sec_driver);
4495 RTE_PMD_REGISTER_CRYPTO_DRIVER(dpaa2_sec_crypto_drv,
4496 rte_dpaa2_sec_driver.driver, cryptodev_driver_id);
4497 RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_DPAA2_SEC_PMD,
4498 DRIVER_STRICT_ORDER "=<int>"
4499 DRIVER_DUMP_MODE "=<int>");
4500 RTE_LOG_REGISTER(dpaa2_logtype_sec, pmd.crypto.dpaa2, NOTICE);