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 if (unlikely(DPAA2_GET_FD_IVP(fd))) {
1570 DPAA2_SEC_ERR("error: non inline buffer");
1573 struct rte_mbuf *mbuf = DPAA2_INLINE_MBUF_FROM_BUF(
1574 DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd)),
1575 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size);
1577 diff = len - mbuf->pkt_len;
1578 mbuf->pkt_len += diff;
1579 mbuf->data_len += diff;
1580 op = (struct rte_crypto_op *)(size_t)mbuf->buf_iova;
1581 mbuf->buf_iova = op->sym->aead.digest.phys_addr;
1582 op->sym->aead.digest.phys_addr = 0L;
1584 sess_priv = (dpaa2_sec_session *)get_sec_session_private_data(
1585 op->sym->sec_session);
1586 if (sess_priv->dir == DIR_ENC)
1587 mbuf->data_off += SEC_FLC_DHR_OUTBOUND;
1589 mbuf->data_off += SEC_FLC_DHR_INBOUND;
1595 static inline struct rte_crypto_op *
1596 sec_fd_to_mbuf(const struct qbman_fd *fd)
1598 struct qbman_fle *fle;
1599 struct rte_crypto_op *op;
1600 struct ctxt_priv *priv;
1601 struct rte_mbuf *dst, *src;
1603 #ifdef RTE_LIB_SECURITY
1604 if (DPAA2_FD_GET_FORMAT(fd) == qbman_fd_single)
1605 return sec_simple_fd_to_mbuf(fd);
1607 fle = (struct qbman_fle *)DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd));
1609 DPAA2_SEC_DP_DEBUG("FLE addr = %x - %x, offset = %x\n",
1610 fle->addr_hi, fle->addr_lo, fle->fin_bpid_offset);
1612 /* we are using the first FLE entry to store Mbuf.
1613 * Currently we donot know which FLE has the mbuf stored.
1614 * So while retreiving we can go back 1 FLE from the FD -ADDR
1615 * to get the MBUF Addr from the previous FLE.
1616 * We can have a better approach to use the inline Mbuf
1619 op = (struct rte_crypto_op *)DPAA2_GET_FLE_ADDR((fle - 1));
1622 src = op->sym->m_src;
1625 if (op->sym->m_dst) {
1626 dst = op->sym->m_dst;
1631 #ifdef RTE_LIB_SECURITY
1632 if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
1633 uint16_t len = DPAA2_GET_FD_LEN(fd);
1635 while (dst->next != NULL) {
1636 len -= dst->data_len;
1639 dst->data_len = len;
1642 DPAA2_SEC_DP_DEBUG("mbuf %p BMAN buf addr %p,"
1643 " fdaddr =%" PRIx64 " bpid =%d meta =%d off =%d, len =%d\n",
1646 DPAA2_GET_FD_ADDR(fd),
1647 DPAA2_GET_FD_BPID(fd),
1648 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size,
1649 DPAA2_GET_FD_OFFSET(fd),
1650 DPAA2_GET_FD_LEN(fd));
1652 /* free the fle memory */
1653 if (likely(rte_pktmbuf_is_contiguous(src))) {
1654 priv = (struct ctxt_priv *)(size_t)DPAA2_GET_FLE_CTXT(fle - 1);
1655 rte_mempool_put(priv->fle_pool, (void *)(fle-1));
1657 rte_free((void *)(fle-1));
1663 dpaa2_sec_dump(struct rte_crypto_op *op)
1666 dpaa2_sec_session *sess = NULL;
1667 struct ctxt_priv *priv;
1669 struct rte_crypto_sym_op *sym_op;
1671 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION)
1672 sess = (dpaa2_sec_session *)get_sym_session_private_data(
1673 op->sym->session, cryptodev_driver_id);
1674 #ifdef RTE_LIBRTE_SECURITY
1675 else if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION)
1676 sess = (dpaa2_sec_session *)get_sec_session_private_data(
1677 op->sym->sec_session);
1683 priv = (struct ctxt_priv *)sess->ctxt;
1684 printf("\n****************************************\n"
1685 "session params:\n\tContext type:\t%d\n\tDirection:\t%s\n"
1686 "\tCipher alg:\t%d\n\tAuth alg:\t%d\n\tAead alg:\t%d\n"
1687 "\tCipher key len:\t%zd\n", sess->ctxt_type,
1688 (sess->dir == DIR_ENC) ? "DIR_ENC" : "DIR_DEC",
1689 sess->cipher_alg, sess->auth_alg, sess->aead_alg,
1690 sess->cipher_key.length);
1691 rte_hexdump(stdout, "cipher key", sess->cipher_key.data,
1692 sess->cipher_key.length);
1693 rte_hexdump(stdout, "auth key", sess->auth_key.data,
1694 sess->auth_key.length);
1695 printf("\tAuth key len:\t%zd\n\tIV len:\t\t%d\n\tIV offset:\t%d\n"
1696 "\tdigest length:\t%d\n\tstatus:\t\t%d\n\taead auth only"
1697 " len:\t%d\n\taead cipher text:\t%d\n",
1698 sess->auth_key.length, sess->iv.length, sess->iv.offset,
1699 sess->digest_length, sess->status,
1700 sess->ext_params.aead_ctxt.auth_only_len,
1701 sess->ext_params.aead_ctxt.auth_cipher_text);
1702 #ifdef RTE_LIBRTE_SECURITY
1703 printf("PDCP session params:\n"
1704 "\tDomain:\t\t%d\n\tBearer:\t\t%d\n\tpkt_dir:\t%d\n\thfn_ovd:"
1705 "\t%d\n\tsn_size:\t%d\n\thfn_ovd_offset:\t%d\n\thfn:\t\t%d\n"
1706 "\thfn_threshold:\t0x%x\n", sess->pdcp.domain,
1707 sess->pdcp.bearer, sess->pdcp.pkt_dir, sess->pdcp.hfn_ovd,
1708 sess->pdcp.sn_size, sess->pdcp.hfn_ovd_offset, sess->pdcp.hfn,
1709 sess->pdcp.hfn_threshold);
1712 bufsize = (uint8_t)priv->flc_desc[0].flc.word1_sdl;
1713 printf("Descriptor Dump:\n");
1714 for (i = 0; i < bufsize; i++)
1715 printf("\tDESC[%d]:0x%x\n", i, priv->flc_desc[0].desc[i]);
1720 if (sym_op->m_src) {
1721 printf("Source mbuf:\n");
1722 rte_pktmbuf_dump(stdout, sym_op->m_src, sym_op->m_src->data_len);
1724 if (sym_op->m_dst) {
1725 printf("Destination mbuf:\n");
1726 rte_pktmbuf_dump(stdout, sym_op->m_dst, sym_op->m_dst->data_len);
1729 printf("Session address = %p\ncipher offset: %d, length: %d\n"
1730 "auth offset: %d, length: %d\n aead offset: %d, length: %d\n"
1732 sym_op->cipher.data.offset, sym_op->cipher.data.length,
1733 sym_op->auth.data.offset, sym_op->auth.data.length,
1734 sym_op->aead.data.offset, sym_op->aead.data.length);
1740 dpaa2_sec_free_eqresp_buf(uint16_t eqresp_ci)
1742 struct dpaa2_dpio_dev *dpio_dev = DPAA2_PER_LCORE_DPIO;
1743 struct rte_crypto_op *op;
1744 struct qbman_fd *fd;
1746 fd = qbman_result_eqresp_fd(&dpio_dev->eqresp[eqresp_ci]);
1747 op = sec_fd_to_mbuf(fd);
1748 /* Instead of freeing, enqueue it to the sec tx queue (sec->core)
1749 * after setting an error in FD. But this will have performance impact.
1751 rte_pktmbuf_free(op->sym->m_src);
1755 dpaa2_sec_set_enqueue_descriptor(struct dpaa2_queue *dpaa2_q,
1757 struct qbman_eq_desc *eqdesc)
1759 struct dpaa2_dpio_dev *dpio_dev = DPAA2_PER_LCORE_DPIO;
1760 struct eqresp_metadata *eqresp_meta;
1761 struct dpaa2_sec_dev_private *priv = dpaa2_q->crypto_data->dev_private;
1762 uint16_t orpid, seqnum;
1765 if (*dpaa2_seqn(m) & DPAA2_ENQUEUE_FLAG_ORP) {
1766 orpid = (*dpaa2_seqn(m) & DPAA2_EQCR_OPRID_MASK) >>
1767 DPAA2_EQCR_OPRID_SHIFT;
1768 seqnum = (*dpaa2_seqn(m) & DPAA2_EQCR_SEQNUM_MASK) >>
1769 DPAA2_EQCR_SEQNUM_SHIFT;
1772 if (!priv->en_loose_ordered) {
1773 qbman_eq_desc_set_orp(eqdesc, 1, orpid, seqnum, 0);
1774 qbman_eq_desc_set_response(eqdesc, (uint64_t)
1775 DPAA2_VADDR_TO_IOVA(&dpio_dev->eqresp[
1776 dpio_dev->eqresp_pi]), 1);
1777 qbman_eq_desc_set_token(eqdesc, 1);
1779 eqresp_meta = &dpio_dev->eqresp_meta[dpio_dev->eqresp_pi];
1780 eqresp_meta->dpaa2_q = dpaa2_q;
1781 eqresp_meta->mp = m->pool;
1783 dpio_dev->eqresp_pi + 1 < MAX_EQ_RESP_ENTRIES ?
1784 dpio_dev->eqresp_pi++ : (dpio_dev->eqresp_pi = 0);
1786 qbman_eq_desc_set_orp(eqdesc, 0, orpid, seqnum, 0);
1789 dq_idx = *dpaa2_seqn(m) - 1;
1790 qbman_eq_desc_set_dca(eqdesc, 1, dq_idx, 0);
1791 DPAA2_PER_LCORE_DQRR_SIZE--;
1792 DPAA2_PER_LCORE_DQRR_HELD &= ~(1 << dq_idx);
1794 *dpaa2_seqn(m) = DPAA2_INVALID_MBUF_SEQN;
1799 dpaa2_sec_enqueue_burst_ordered(void *qp, struct rte_crypto_op **ops,
1802 /* Function to transmit the frames to given device and VQ*/
1805 struct qbman_fd fd_arr[MAX_TX_RING_SLOTS];
1806 uint32_t frames_to_send, num_free_eq_desc, retry_count;
1807 struct qbman_eq_desc eqdesc[MAX_TX_RING_SLOTS];
1808 struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
1809 struct qbman_swp *swp;
1810 uint16_t num_tx = 0;
1812 struct rte_mempool *mb_pool;
1813 struct dpaa2_sec_dev_private *priv =
1814 dpaa2_qp->tx_vq.crypto_data->dev_private;
1816 if (unlikely(nb_ops == 0))
1819 if (ops[0]->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
1820 DPAA2_SEC_ERR("sessionless crypto op not supported");
1824 if (!DPAA2_PER_LCORE_DPIO) {
1825 ret = dpaa2_affine_qbman_swp();
1827 DPAA2_SEC_ERR("Failure in affining portal");
1831 swp = DPAA2_PER_LCORE_PORTAL;
1834 frames_to_send = (nb_ops > dpaa2_eqcr_size) ?
1835 dpaa2_eqcr_size : nb_ops;
1837 if (!priv->en_loose_ordered) {
1838 if (*dpaa2_seqn((*ops)->sym->m_src)) {
1839 num_free_eq_desc = dpaa2_free_eq_descriptors();
1840 if (num_free_eq_desc < frames_to_send)
1841 frames_to_send = num_free_eq_desc;
1845 for (loop = 0; loop < frames_to_send; loop++) {
1846 /*Prepare enqueue descriptor*/
1847 qbman_eq_desc_clear(&eqdesc[loop]);
1848 qbman_eq_desc_set_fq(&eqdesc[loop], dpaa2_qp->tx_vq.fqid);
1850 if (*dpaa2_seqn((*ops)->sym->m_src))
1851 dpaa2_sec_set_enqueue_descriptor(
1856 qbman_eq_desc_set_no_orp(&eqdesc[loop],
1857 DPAA2_EQ_RESP_ERR_FQ);
1859 /*Clear the unused FD fields before sending*/
1860 memset(&fd_arr[loop], 0, sizeof(struct qbman_fd));
1861 mb_pool = (*ops)->sym->m_src->pool;
1862 bpid = mempool_to_bpid(mb_pool);
1863 ret = build_sec_fd(*ops, &fd_arr[loop], bpid);
1865 DPAA2_SEC_ERR("error: Improper packet contents"
1866 " for crypto operation");
1874 while (loop < frames_to_send) {
1875 ret = qbman_swp_enqueue_multiple_desc(swp,
1876 &eqdesc[loop], &fd_arr[loop],
1877 frames_to_send - loop);
1878 if (unlikely(ret < 0)) {
1880 if (retry_count > DPAA2_MAX_TX_RETRY_COUNT) {
1883 DPAA2_SEC_DP_DEBUG("Enqueue fail\n");
1884 /* freeing the fle buffers */
1885 while (loop < frames_to_send) {
1886 free_fle(&fd_arr[loop]);
1902 dpaa2_qp->tx_vq.tx_pkts += num_tx;
1903 dpaa2_qp->tx_vq.err_pkts += nb_ops;
1908 dpaa2_sec_dequeue_burst(void *qp, struct rte_crypto_op **ops,
1911 /* Function is responsible to receive frames for a given device and VQ*/
1912 struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
1913 struct qbman_result *dq_storage;
1914 uint32_t fqid = dpaa2_qp->rx_vq.fqid;
1915 int ret, num_rx = 0;
1916 uint8_t is_last = 0, status;
1917 struct qbman_swp *swp;
1918 const struct qbman_fd *fd;
1919 struct qbman_pull_desc pulldesc;
1921 if (!DPAA2_PER_LCORE_DPIO) {
1922 ret = dpaa2_affine_qbman_swp();
1925 "Failed to allocate IO portal, tid: %d\n",
1930 swp = DPAA2_PER_LCORE_PORTAL;
1931 dq_storage = dpaa2_qp->rx_vq.q_storage->dq_storage[0];
1933 qbman_pull_desc_clear(&pulldesc);
1934 qbman_pull_desc_set_numframes(&pulldesc,
1935 (nb_ops > dpaa2_dqrr_size) ?
1936 dpaa2_dqrr_size : nb_ops);
1937 qbman_pull_desc_set_fq(&pulldesc, fqid);
1938 qbman_pull_desc_set_storage(&pulldesc, dq_storage,
1939 (dma_addr_t)DPAA2_VADDR_TO_IOVA(dq_storage),
1942 /*Issue a volatile dequeue command. */
1944 if (qbman_swp_pull(swp, &pulldesc)) {
1946 "SEC VDQ command is not issued : QBMAN busy");
1947 /* Portal was busy, try again */
1953 /* Receive the packets till Last Dequeue entry is found with
1954 * respect to the above issues PULL command.
1957 /* Check if the previous issued command is completed.
1958 * Also seems like the SWP is shared between the Ethernet Driver
1959 * and the SEC driver.
1961 while (!qbman_check_command_complete(dq_storage))
1964 /* Loop until the dq_storage is updated with
1965 * new token by QBMAN
1967 while (!qbman_check_new_result(dq_storage))
1969 /* Check whether Last Pull command is Expired and
1970 * setting Condition for Loop termination
1972 if (qbman_result_DQ_is_pull_complete(dq_storage)) {
1974 /* Check for valid frame. */
1975 status = (uint8_t)qbman_result_DQ_flags(dq_storage);
1977 (status & QBMAN_DQ_STAT_VALIDFRAME) == 0)) {
1978 DPAA2_SEC_DP_DEBUG("No frame is delivered\n");
1983 fd = qbman_result_DQ_fd(dq_storage);
1984 ops[num_rx] = sec_fd_to_mbuf(fd);
1986 if (unlikely(fd->simple.frc)) {
1987 /* TODO Parse SEC errors */
1988 if (dpaa2_sec_dp_dump > DPAA2_SEC_DP_NO_DUMP) {
1989 DPAA2_SEC_DP_ERR("SEC returned Error - %x\n",
1991 if (dpaa2_sec_dp_dump > DPAA2_SEC_DP_ERR_DUMP)
1992 dpaa2_sec_dump(ops[num_rx]);
1995 dpaa2_qp->rx_vq.err_pkts += 1;
1996 ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_ERROR;
1998 ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
2003 } /* End of Packet Rx loop */
2005 dpaa2_qp->rx_vq.rx_pkts += num_rx;
2007 DPAA2_SEC_DP_DEBUG("SEC RX pkts %d err pkts %" PRIu64 "\n", num_rx,
2008 dpaa2_qp->rx_vq.err_pkts);
2009 /*Return the total number of packets received to DPAA2 app*/
2013 /** Release queue pair */
2015 dpaa2_sec_queue_pair_release(struct rte_cryptodev *dev, uint16_t queue_pair_id)
2017 struct dpaa2_sec_qp *qp =
2018 (struct dpaa2_sec_qp *)dev->data->queue_pairs[queue_pair_id];
2020 PMD_INIT_FUNC_TRACE();
2022 if (qp->rx_vq.q_storage) {
2023 dpaa2_free_dq_storage(qp->rx_vq.q_storage);
2024 rte_free(qp->rx_vq.q_storage);
2028 dev->data->queue_pairs[queue_pair_id] = NULL;
2033 /** Setup a queue pair */
2035 dpaa2_sec_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
2036 __rte_unused const struct rte_cryptodev_qp_conf *qp_conf,
2037 __rte_unused int socket_id)
2039 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
2040 struct dpaa2_sec_qp *qp;
2041 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
2042 struct dpseci_rx_queue_cfg cfg;
2045 PMD_INIT_FUNC_TRACE();
2047 /* If qp is already in use free ring memory and qp metadata. */
2048 if (dev->data->queue_pairs[qp_id] != NULL) {
2049 DPAA2_SEC_INFO("QP already setup");
2053 DPAA2_SEC_DEBUG("dev =%p, queue =%d, conf =%p",
2054 dev, qp_id, qp_conf);
2056 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
2058 qp = rte_malloc(NULL, sizeof(struct dpaa2_sec_qp),
2059 RTE_CACHE_LINE_SIZE);
2061 DPAA2_SEC_ERR("malloc failed for rx/tx queues");
2065 qp->rx_vq.crypto_data = dev->data;
2066 qp->tx_vq.crypto_data = dev->data;
2067 qp->rx_vq.q_storage = rte_malloc("sec dq storage",
2068 sizeof(struct queue_storage_info_t),
2069 RTE_CACHE_LINE_SIZE);
2070 if (!qp->rx_vq.q_storage) {
2071 DPAA2_SEC_ERR("malloc failed for q_storage");
2074 memset(qp->rx_vq.q_storage, 0, sizeof(struct queue_storage_info_t));
2076 if (dpaa2_alloc_dq_storage(qp->rx_vq.q_storage)) {
2077 DPAA2_SEC_ERR("Unable to allocate dequeue storage");
2081 dev->data->queue_pairs[qp_id] = qp;
2083 cfg.options = cfg.options | DPSECI_QUEUE_OPT_USER_CTX;
2084 cfg.user_ctx = (size_t)(&qp->rx_vq);
2085 retcode = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
2090 /** Returns the size of the aesni gcm session structure */
2092 dpaa2_sec_sym_session_get_size(struct rte_cryptodev *dev __rte_unused)
2094 PMD_INIT_FUNC_TRACE();
2096 return sizeof(dpaa2_sec_session);
2100 dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
2101 struct rte_crypto_sym_xform *xform,
2102 dpaa2_sec_session *session)
2104 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2105 struct alginfo cipherdata;
2106 int bufsize, ret = 0;
2107 struct ctxt_priv *priv;
2108 struct sec_flow_context *flc;
2110 PMD_INIT_FUNC_TRACE();
2112 /* For SEC CIPHER only one descriptor is required. */
2113 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2114 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
2115 RTE_CACHE_LINE_SIZE);
2117 DPAA2_SEC_ERR("No Memory for priv CTXT");
2121 priv->fle_pool = dev_priv->fle_pool;
2123 flc = &priv->flc_desc[0].flc;
2125 session->ctxt_type = DPAA2_SEC_CIPHER;
2126 session->cipher_key.data = rte_zmalloc(NULL, xform->cipher.key.length,
2127 RTE_CACHE_LINE_SIZE);
2128 if (session->cipher_key.data == NULL && xform->cipher.key.length > 0) {
2129 DPAA2_SEC_ERR("No Memory for cipher key");
2133 session->cipher_key.length = xform->cipher.key.length;
2135 memcpy(session->cipher_key.data, xform->cipher.key.data,
2136 xform->cipher.key.length);
2137 cipherdata.key = (size_t)session->cipher_key.data;
2138 cipherdata.keylen = session->cipher_key.length;
2139 cipherdata.key_enc_flags = 0;
2140 cipherdata.key_type = RTA_DATA_IMM;
2142 /* Set IV parameters */
2143 session->iv.offset = xform->cipher.iv.offset;
2144 session->iv.length = xform->cipher.iv.length;
2145 session->dir = (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2148 switch (xform->cipher.algo) {
2149 case RTE_CRYPTO_CIPHER_AES_CBC:
2150 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2151 cipherdata.algmode = OP_ALG_AAI_CBC;
2152 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
2153 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
2154 SHR_NEVER, &cipherdata,
2158 case RTE_CRYPTO_CIPHER_3DES_CBC:
2159 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
2160 cipherdata.algmode = OP_ALG_AAI_CBC;
2161 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
2162 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
2163 SHR_NEVER, &cipherdata,
2167 case RTE_CRYPTO_CIPHER_DES_CBC:
2168 cipherdata.algtype = OP_ALG_ALGSEL_DES;
2169 cipherdata.algmode = OP_ALG_AAI_CBC;
2170 session->cipher_alg = RTE_CRYPTO_CIPHER_DES_CBC;
2171 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
2172 SHR_NEVER, &cipherdata,
2176 case RTE_CRYPTO_CIPHER_AES_CTR:
2177 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2178 cipherdata.algmode = OP_ALG_AAI_CTR;
2179 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
2180 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
2181 SHR_NEVER, &cipherdata,
2185 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2186 cipherdata.algtype = OP_ALG_ALGSEL_SNOW_F8;
2187 session->cipher_alg = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
2188 bufsize = cnstr_shdsc_snow_f8(priv->flc_desc[0].desc, 1, 0,
2192 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
2193 cipherdata.algtype = OP_ALG_ALGSEL_ZUCE;
2194 session->cipher_alg = RTE_CRYPTO_CIPHER_ZUC_EEA3;
2195 bufsize = cnstr_shdsc_zuce(priv->flc_desc[0].desc, 1, 0,
2199 case RTE_CRYPTO_CIPHER_KASUMI_F8:
2200 case RTE_CRYPTO_CIPHER_AES_F8:
2201 case RTE_CRYPTO_CIPHER_AES_ECB:
2202 case RTE_CRYPTO_CIPHER_3DES_ECB:
2203 case RTE_CRYPTO_CIPHER_3DES_CTR:
2204 case RTE_CRYPTO_CIPHER_AES_XTS:
2205 case RTE_CRYPTO_CIPHER_ARC4:
2206 case RTE_CRYPTO_CIPHER_NULL:
2207 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
2208 xform->cipher.algo);
2212 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2213 xform->cipher.algo);
2219 DPAA2_SEC_ERR("Crypto: Descriptor build failed");
2224 flc->word1_sdl = (uint8_t)bufsize;
2225 session->ctxt = priv;
2227 #ifdef CAAM_DESC_DEBUG
2229 for (i = 0; i < bufsize; i++)
2230 DPAA2_SEC_DEBUG("DESC[%d]:0x%x", i, priv->flc_desc[0].desc[i]);
2235 rte_free(session->cipher_key.data);
2241 dpaa2_sec_auth_init(struct rte_cryptodev *dev,
2242 struct rte_crypto_sym_xform *xform,
2243 dpaa2_sec_session *session)
2245 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2246 struct alginfo authdata;
2247 int bufsize, ret = 0;
2248 struct ctxt_priv *priv;
2249 struct sec_flow_context *flc;
2251 PMD_INIT_FUNC_TRACE();
2253 /* For SEC AUTH three descriptors are required for various stages */
2254 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2255 sizeof(struct ctxt_priv) + 3 *
2256 sizeof(struct sec_flc_desc),
2257 RTE_CACHE_LINE_SIZE);
2259 DPAA2_SEC_ERR("No Memory for priv CTXT");
2263 priv->fle_pool = dev_priv->fle_pool;
2264 flc = &priv->flc_desc[DESC_INITFINAL].flc;
2266 session->ctxt_type = DPAA2_SEC_AUTH;
2267 session->auth_key.length = xform->auth.key.length;
2268 if (xform->auth.key.length) {
2269 session->auth_key.data = rte_zmalloc(NULL,
2270 xform->auth.key.length,
2271 RTE_CACHE_LINE_SIZE);
2272 if (session->auth_key.data == NULL) {
2273 DPAA2_SEC_ERR("Unable to allocate memory for auth key");
2277 memcpy(session->auth_key.data, xform->auth.key.data,
2278 xform->auth.key.length);
2279 authdata.key = (size_t)session->auth_key.data;
2280 authdata.key_enc_flags = 0;
2281 authdata.key_type = RTA_DATA_IMM;
2283 authdata.keylen = session->auth_key.length;
2285 session->digest_length = xform->auth.digest_length;
2286 session->dir = (xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE) ?
2289 switch (xform->auth.algo) {
2290 case RTE_CRYPTO_AUTH_SHA1_HMAC:
2291 authdata.algtype = OP_ALG_ALGSEL_SHA1;
2292 authdata.algmode = OP_ALG_AAI_HMAC;
2293 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
2294 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2295 1, 0, SHR_NEVER, &authdata,
2297 session->digest_length);
2299 case RTE_CRYPTO_AUTH_MD5_HMAC:
2300 authdata.algtype = OP_ALG_ALGSEL_MD5;
2301 authdata.algmode = OP_ALG_AAI_HMAC;
2302 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
2303 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2304 1, 0, SHR_NEVER, &authdata,
2306 session->digest_length);
2308 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2309 authdata.algtype = OP_ALG_ALGSEL_SHA256;
2310 authdata.algmode = OP_ALG_AAI_HMAC;
2311 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
2312 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2313 1, 0, SHR_NEVER, &authdata,
2315 session->digest_length);
2317 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2318 authdata.algtype = OP_ALG_ALGSEL_SHA384;
2319 authdata.algmode = OP_ALG_AAI_HMAC;
2320 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
2321 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2322 1, 0, SHR_NEVER, &authdata,
2324 session->digest_length);
2326 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2327 authdata.algtype = OP_ALG_ALGSEL_SHA512;
2328 authdata.algmode = OP_ALG_AAI_HMAC;
2329 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
2330 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2331 1, 0, SHR_NEVER, &authdata,
2333 session->digest_length);
2335 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2336 authdata.algtype = OP_ALG_ALGSEL_SHA224;
2337 authdata.algmode = OP_ALG_AAI_HMAC;
2338 session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
2339 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
2340 1, 0, SHR_NEVER, &authdata,
2342 session->digest_length);
2344 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2345 authdata.algtype = OP_ALG_ALGSEL_SNOW_F9;
2346 authdata.algmode = OP_ALG_AAI_F9;
2347 session->auth_alg = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2348 session->iv.offset = xform->auth.iv.offset;
2349 session->iv.length = xform->auth.iv.length;
2350 bufsize = cnstr_shdsc_snow_f9(priv->flc_desc[DESC_INITFINAL].desc,
2353 session->digest_length);
2355 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2356 authdata.algtype = OP_ALG_ALGSEL_ZUCA;
2357 authdata.algmode = OP_ALG_AAI_F9;
2358 session->auth_alg = RTE_CRYPTO_AUTH_ZUC_EIA3;
2359 session->iv.offset = xform->auth.iv.offset;
2360 session->iv.length = xform->auth.iv.length;
2361 bufsize = cnstr_shdsc_zuca(priv->flc_desc[DESC_INITFINAL].desc,
2364 session->digest_length);
2366 case RTE_CRYPTO_AUTH_SHA1:
2367 authdata.algtype = OP_ALG_ALGSEL_SHA1;
2368 authdata.algmode = OP_ALG_AAI_HASH;
2369 session->auth_alg = RTE_CRYPTO_AUTH_SHA1;
2370 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2371 1, 0, SHR_NEVER, &authdata,
2373 session->digest_length);
2375 case RTE_CRYPTO_AUTH_MD5:
2376 authdata.algtype = OP_ALG_ALGSEL_MD5;
2377 authdata.algmode = OP_ALG_AAI_HASH;
2378 session->auth_alg = RTE_CRYPTO_AUTH_MD5;
2379 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2380 1, 0, SHR_NEVER, &authdata,
2382 session->digest_length);
2384 case RTE_CRYPTO_AUTH_SHA256:
2385 authdata.algtype = OP_ALG_ALGSEL_SHA256;
2386 authdata.algmode = OP_ALG_AAI_HASH;
2387 session->auth_alg = RTE_CRYPTO_AUTH_SHA256;
2388 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2389 1, 0, SHR_NEVER, &authdata,
2391 session->digest_length);
2393 case RTE_CRYPTO_AUTH_SHA384:
2394 authdata.algtype = OP_ALG_ALGSEL_SHA384;
2395 authdata.algmode = OP_ALG_AAI_HASH;
2396 session->auth_alg = RTE_CRYPTO_AUTH_SHA384;
2397 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2398 1, 0, SHR_NEVER, &authdata,
2400 session->digest_length);
2402 case RTE_CRYPTO_AUTH_SHA512:
2403 authdata.algtype = OP_ALG_ALGSEL_SHA512;
2404 authdata.algmode = OP_ALG_AAI_HASH;
2405 session->auth_alg = RTE_CRYPTO_AUTH_SHA512;
2406 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2407 1, 0, SHR_NEVER, &authdata,
2409 session->digest_length);
2411 case RTE_CRYPTO_AUTH_SHA224:
2412 authdata.algtype = OP_ALG_ALGSEL_SHA224;
2413 authdata.algmode = OP_ALG_AAI_HASH;
2414 session->auth_alg = RTE_CRYPTO_AUTH_SHA224;
2415 bufsize = cnstr_shdsc_hash(priv->flc_desc[DESC_INITFINAL].desc,
2416 1, 0, SHR_NEVER, &authdata,
2418 session->digest_length);
2420 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2421 authdata.algtype = OP_ALG_ALGSEL_AES;
2422 authdata.algmode = OP_ALG_AAI_XCBC_MAC;
2423 session->auth_alg = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
2424 bufsize = cnstr_shdsc_aes_mac(
2425 priv->flc_desc[DESC_INITFINAL].desc,
2426 1, 0, SHR_NEVER, &authdata,
2428 session->digest_length);
2430 case RTE_CRYPTO_AUTH_AES_CMAC:
2431 authdata.algtype = OP_ALG_ALGSEL_AES;
2432 authdata.algmode = OP_ALG_AAI_CMAC;
2433 session->auth_alg = RTE_CRYPTO_AUTH_AES_CMAC;
2434 bufsize = cnstr_shdsc_aes_mac(
2435 priv->flc_desc[DESC_INITFINAL].desc,
2436 1, 0, SHR_NEVER, &authdata,
2438 session->digest_length);
2440 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2441 case RTE_CRYPTO_AUTH_AES_GMAC:
2442 case RTE_CRYPTO_AUTH_KASUMI_F9:
2443 case RTE_CRYPTO_AUTH_NULL:
2444 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %un",
2449 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2456 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2461 flc->word1_sdl = (uint8_t)bufsize;
2462 session->ctxt = priv;
2463 #ifdef CAAM_DESC_DEBUG
2465 for (i = 0; i < bufsize; i++)
2466 DPAA2_SEC_DEBUG("DESC[%d]:0x%x",
2467 i, priv->flc_desc[DESC_INITFINAL].desc[i]);
2473 rte_free(session->auth_key.data);
2479 dpaa2_sec_aead_init(struct rte_cryptodev *dev,
2480 struct rte_crypto_sym_xform *xform,
2481 dpaa2_sec_session *session)
2483 struct dpaa2_sec_aead_ctxt *ctxt = &session->ext_params.aead_ctxt;
2484 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2485 struct alginfo aeaddata;
2487 struct ctxt_priv *priv;
2488 struct sec_flow_context *flc;
2489 struct rte_crypto_aead_xform *aead_xform = &xform->aead;
2492 PMD_INIT_FUNC_TRACE();
2494 /* Set IV parameters */
2495 session->iv.offset = aead_xform->iv.offset;
2496 session->iv.length = aead_xform->iv.length;
2497 session->ctxt_type = DPAA2_SEC_AEAD;
2499 /* For SEC AEAD only one descriptor is required */
2500 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2501 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
2502 RTE_CACHE_LINE_SIZE);
2504 DPAA2_SEC_ERR("No Memory for priv CTXT");
2508 priv->fle_pool = dev_priv->fle_pool;
2509 flc = &priv->flc_desc[0].flc;
2511 session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length,
2512 RTE_CACHE_LINE_SIZE);
2513 if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
2514 DPAA2_SEC_ERR("No Memory for aead key");
2518 memcpy(session->aead_key.data, aead_xform->key.data,
2519 aead_xform->key.length);
2521 session->digest_length = aead_xform->digest_length;
2522 session->aead_key.length = aead_xform->key.length;
2523 ctxt->auth_only_len = aead_xform->aad_length;
2525 aeaddata.key = (size_t)session->aead_key.data;
2526 aeaddata.keylen = session->aead_key.length;
2527 aeaddata.key_enc_flags = 0;
2528 aeaddata.key_type = RTA_DATA_IMM;
2530 switch (aead_xform->algo) {
2531 case RTE_CRYPTO_AEAD_AES_GCM:
2532 aeaddata.algtype = OP_ALG_ALGSEL_AES;
2533 aeaddata.algmode = OP_ALG_AAI_GCM;
2534 session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM;
2536 case RTE_CRYPTO_AEAD_AES_CCM:
2537 DPAA2_SEC_ERR("Crypto: Unsupported AEAD alg %u",
2542 DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
2547 session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
2550 priv->flc_desc[0].desc[0] = aeaddata.keylen;
2551 err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
2553 (unsigned int *)priv->flc_desc[0].desc,
2554 &priv->flc_desc[0].desc[1], 1);
2557 DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
2561 if (priv->flc_desc[0].desc[1] & 1) {
2562 aeaddata.key_type = RTA_DATA_IMM;
2564 aeaddata.key = DPAA2_VADDR_TO_IOVA(aeaddata.key);
2565 aeaddata.key_type = RTA_DATA_PTR;
2567 priv->flc_desc[0].desc[0] = 0;
2568 priv->flc_desc[0].desc[1] = 0;
2570 if (session->dir == DIR_ENC)
2571 bufsize = cnstr_shdsc_gcm_encap(
2572 priv->flc_desc[0].desc, 1, 0, SHR_NEVER,
2573 &aeaddata, session->iv.length,
2574 session->digest_length);
2576 bufsize = cnstr_shdsc_gcm_decap(
2577 priv->flc_desc[0].desc, 1, 0, SHR_NEVER,
2578 &aeaddata, session->iv.length,
2579 session->digest_length);
2581 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2586 flc->word1_sdl = (uint8_t)bufsize;
2587 session->ctxt = priv;
2588 #ifdef CAAM_DESC_DEBUG
2590 for (i = 0; i < bufsize; i++)
2591 DPAA2_SEC_DEBUG("DESC[%d]:0x%x\n",
2592 i, priv->flc_desc[0].desc[i]);
2597 rte_free(session->aead_key.data);
2604 dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
2605 struct rte_crypto_sym_xform *xform,
2606 dpaa2_sec_session *session)
2608 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2609 struct alginfo authdata, cipherdata;
2611 struct ctxt_priv *priv;
2612 struct sec_flow_context *flc;
2613 struct rte_crypto_cipher_xform *cipher_xform;
2614 struct rte_crypto_auth_xform *auth_xform;
2617 PMD_INIT_FUNC_TRACE();
2619 if (session->ext_params.aead_ctxt.auth_cipher_text) {
2620 cipher_xform = &xform->cipher;
2621 auth_xform = &xform->next->auth;
2622 session->ctxt_type =
2623 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2624 DPAA2_SEC_CIPHER_HASH : DPAA2_SEC_HASH_CIPHER;
2626 cipher_xform = &xform->next->cipher;
2627 auth_xform = &xform->auth;
2628 session->ctxt_type =
2629 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2630 DPAA2_SEC_HASH_CIPHER : DPAA2_SEC_CIPHER_HASH;
2633 /* Set IV parameters */
2634 session->iv.offset = cipher_xform->iv.offset;
2635 session->iv.length = cipher_xform->iv.length;
2637 /* For SEC AEAD only one descriptor is required */
2638 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2639 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
2640 RTE_CACHE_LINE_SIZE);
2642 DPAA2_SEC_ERR("No Memory for priv CTXT");
2646 priv->fle_pool = dev_priv->fle_pool;
2647 flc = &priv->flc_desc[0].flc;
2649 session->cipher_key.data = rte_zmalloc(NULL, cipher_xform->key.length,
2650 RTE_CACHE_LINE_SIZE);
2651 if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) {
2652 DPAA2_SEC_ERR("No Memory for cipher key");
2656 session->cipher_key.length = cipher_xform->key.length;
2657 session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length,
2658 RTE_CACHE_LINE_SIZE);
2659 if (session->auth_key.data == NULL && auth_xform->key.length > 0) {
2660 DPAA2_SEC_ERR("No Memory for auth key");
2661 rte_free(session->cipher_key.data);
2665 session->auth_key.length = auth_xform->key.length;
2666 memcpy(session->cipher_key.data, cipher_xform->key.data,
2667 cipher_xform->key.length);
2668 memcpy(session->auth_key.data, auth_xform->key.data,
2669 auth_xform->key.length);
2671 authdata.key = (size_t)session->auth_key.data;
2672 authdata.keylen = session->auth_key.length;
2673 authdata.key_enc_flags = 0;
2674 authdata.key_type = RTA_DATA_IMM;
2676 session->digest_length = auth_xform->digest_length;
2678 switch (auth_xform->algo) {
2679 case RTE_CRYPTO_AUTH_SHA1_HMAC:
2680 authdata.algtype = OP_ALG_ALGSEL_SHA1;
2681 authdata.algmode = OP_ALG_AAI_HMAC;
2682 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
2684 case RTE_CRYPTO_AUTH_MD5_HMAC:
2685 authdata.algtype = OP_ALG_ALGSEL_MD5;
2686 authdata.algmode = OP_ALG_AAI_HMAC;
2687 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
2689 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2690 authdata.algtype = OP_ALG_ALGSEL_SHA224;
2691 authdata.algmode = OP_ALG_AAI_HMAC;
2692 session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
2694 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2695 authdata.algtype = OP_ALG_ALGSEL_SHA256;
2696 authdata.algmode = OP_ALG_AAI_HMAC;
2697 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
2699 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2700 authdata.algtype = OP_ALG_ALGSEL_SHA384;
2701 authdata.algmode = OP_ALG_AAI_HMAC;
2702 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
2704 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2705 authdata.algtype = OP_ALG_ALGSEL_SHA512;
2706 authdata.algmode = OP_ALG_AAI_HMAC;
2707 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
2709 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2710 authdata.algtype = OP_ALG_ALGSEL_AES;
2711 authdata.algmode = OP_ALG_AAI_XCBC_MAC;
2712 session->auth_alg = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
2714 case RTE_CRYPTO_AUTH_AES_CMAC:
2715 authdata.algtype = OP_ALG_ALGSEL_AES;
2716 authdata.algmode = OP_ALG_AAI_CMAC;
2717 session->auth_alg = RTE_CRYPTO_AUTH_AES_CMAC;
2719 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2720 case RTE_CRYPTO_AUTH_AES_GMAC:
2721 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2722 case RTE_CRYPTO_AUTH_NULL:
2723 case RTE_CRYPTO_AUTH_SHA1:
2724 case RTE_CRYPTO_AUTH_SHA256:
2725 case RTE_CRYPTO_AUTH_SHA512:
2726 case RTE_CRYPTO_AUTH_SHA224:
2727 case RTE_CRYPTO_AUTH_SHA384:
2728 case RTE_CRYPTO_AUTH_MD5:
2729 case RTE_CRYPTO_AUTH_KASUMI_F9:
2730 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2731 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
2736 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2741 cipherdata.key = (size_t)session->cipher_key.data;
2742 cipherdata.keylen = session->cipher_key.length;
2743 cipherdata.key_enc_flags = 0;
2744 cipherdata.key_type = RTA_DATA_IMM;
2746 switch (cipher_xform->algo) {
2747 case RTE_CRYPTO_CIPHER_AES_CBC:
2748 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2749 cipherdata.algmode = OP_ALG_AAI_CBC;
2750 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
2752 case RTE_CRYPTO_CIPHER_3DES_CBC:
2753 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
2754 cipherdata.algmode = OP_ALG_AAI_CBC;
2755 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
2757 case RTE_CRYPTO_CIPHER_DES_CBC:
2758 cipherdata.algtype = OP_ALG_ALGSEL_DES;
2759 cipherdata.algmode = OP_ALG_AAI_CBC;
2760 session->cipher_alg = RTE_CRYPTO_CIPHER_DES_CBC;
2762 case RTE_CRYPTO_CIPHER_AES_CTR:
2763 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2764 cipherdata.algmode = OP_ALG_AAI_CTR;
2765 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
2767 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2768 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
2769 case RTE_CRYPTO_CIPHER_NULL:
2770 case RTE_CRYPTO_CIPHER_3DES_ECB:
2771 case RTE_CRYPTO_CIPHER_3DES_CTR:
2772 case RTE_CRYPTO_CIPHER_AES_ECB:
2773 case RTE_CRYPTO_CIPHER_KASUMI_F8:
2774 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
2775 cipher_xform->algo);
2779 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2780 cipher_xform->algo);
2784 session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2787 priv->flc_desc[0].desc[0] = cipherdata.keylen;
2788 priv->flc_desc[0].desc[1] = authdata.keylen;
2789 err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
2791 (unsigned int *)priv->flc_desc[0].desc,
2792 &priv->flc_desc[0].desc[2], 2);
2795 DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
2799 if (priv->flc_desc[0].desc[2] & 1) {
2800 cipherdata.key_type = RTA_DATA_IMM;
2802 cipherdata.key = DPAA2_VADDR_TO_IOVA(cipherdata.key);
2803 cipherdata.key_type = RTA_DATA_PTR;
2805 if (priv->flc_desc[0].desc[2] & (1 << 1)) {
2806 authdata.key_type = RTA_DATA_IMM;
2808 authdata.key = DPAA2_VADDR_TO_IOVA(authdata.key);
2809 authdata.key_type = RTA_DATA_PTR;
2811 priv->flc_desc[0].desc[0] = 0;
2812 priv->flc_desc[0].desc[1] = 0;
2813 priv->flc_desc[0].desc[2] = 0;
2815 if (session->ctxt_type == DPAA2_SEC_CIPHER_HASH) {
2816 bufsize = cnstr_shdsc_authenc(priv->flc_desc[0].desc, 1,
2818 &cipherdata, &authdata,
2820 session->digest_length,
2823 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2828 DPAA2_SEC_ERR("Hash before cipher not supported");
2833 flc->word1_sdl = (uint8_t)bufsize;
2834 session->ctxt = priv;
2835 #ifdef CAAM_DESC_DEBUG
2837 for (i = 0; i < bufsize; i++)
2838 DPAA2_SEC_DEBUG("DESC[%d]:0x%x",
2839 i, priv->flc_desc[0].desc[i]);
2845 rte_free(session->cipher_key.data);
2846 rte_free(session->auth_key.data);
2852 dpaa2_sec_set_session_parameters(struct rte_cryptodev *dev,
2853 struct rte_crypto_sym_xform *xform, void *sess)
2855 dpaa2_sec_session *session = sess;
2858 PMD_INIT_FUNC_TRACE();
2860 if (unlikely(sess == NULL)) {
2861 DPAA2_SEC_ERR("Invalid session struct");
2865 memset(session, 0, sizeof(dpaa2_sec_session));
2866 /* Default IV length = 0 */
2867 session->iv.length = 0;
2870 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
2871 ret = dpaa2_sec_cipher_init(dev, xform, session);
2873 /* Authentication Only */
2874 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2875 xform->next == NULL) {
2876 ret = dpaa2_sec_auth_init(dev, xform, session);
2878 /* Cipher then Authenticate */
2879 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
2880 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2881 session->ext_params.aead_ctxt.auth_cipher_text = true;
2882 if (xform->cipher.algo == RTE_CRYPTO_CIPHER_NULL)
2883 ret = dpaa2_sec_auth_init(dev, xform, session);
2884 else if (xform->next->auth.algo == RTE_CRYPTO_AUTH_NULL)
2885 ret = dpaa2_sec_cipher_init(dev, xform, session);
2887 ret = dpaa2_sec_aead_chain_init(dev, xform, session);
2888 /* Authenticate then Cipher */
2889 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2890 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2891 session->ext_params.aead_ctxt.auth_cipher_text = false;
2892 if (xform->auth.algo == RTE_CRYPTO_AUTH_NULL)
2893 ret = dpaa2_sec_cipher_init(dev, xform, session);
2894 else if (xform->next->cipher.algo == RTE_CRYPTO_CIPHER_NULL)
2895 ret = dpaa2_sec_auth_init(dev, xform, session);
2897 ret = dpaa2_sec_aead_chain_init(dev, xform, session);
2898 /* AEAD operation for AES-GCM kind of Algorithms */
2899 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD &&
2900 xform->next == NULL) {
2901 ret = dpaa2_sec_aead_init(dev, xform, session);
2904 DPAA2_SEC_ERR("Invalid crypto type");
2911 #ifdef RTE_LIB_SECURITY
2913 dpaa2_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
2914 dpaa2_sec_session *session,
2915 struct alginfo *aeaddata)
2917 PMD_INIT_FUNC_TRACE();
2919 session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length,
2920 RTE_CACHE_LINE_SIZE);
2921 if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
2922 DPAA2_SEC_ERR("No Memory for aead key");
2925 memcpy(session->aead_key.data, aead_xform->key.data,
2926 aead_xform->key.length);
2928 session->digest_length = aead_xform->digest_length;
2929 session->aead_key.length = aead_xform->key.length;
2931 aeaddata->key = (size_t)session->aead_key.data;
2932 aeaddata->keylen = session->aead_key.length;
2933 aeaddata->key_enc_flags = 0;
2934 aeaddata->key_type = RTA_DATA_IMM;
2936 switch (aead_xform->algo) {
2937 case RTE_CRYPTO_AEAD_AES_GCM:
2938 switch (session->digest_length) {
2940 aeaddata->algtype = OP_PCL_IPSEC_AES_GCM8;
2943 aeaddata->algtype = OP_PCL_IPSEC_AES_GCM12;
2946 aeaddata->algtype = OP_PCL_IPSEC_AES_GCM16;
2949 DPAA2_SEC_ERR("Crypto: Undefined GCM digest %d",
2950 session->digest_length);
2953 aeaddata->algmode = OP_ALG_AAI_GCM;
2954 session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM;
2956 case RTE_CRYPTO_AEAD_AES_CCM:
2957 switch (session->digest_length) {
2959 aeaddata->algtype = OP_PCL_IPSEC_AES_CCM8;
2962 aeaddata->algtype = OP_PCL_IPSEC_AES_CCM12;
2965 aeaddata->algtype = OP_PCL_IPSEC_AES_CCM16;
2968 DPAA2_SEC_ERR("Crypto: Undefined CCM digest %d",
2969 session->digest_length);
2972 aeaddata->algmode = OP_ALG_AAI_CCM;
2973 session->aead_alg = RTE_CRYPTO_AEAD_AES_CCM;
2976 DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
2980 session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
2987 dpaa2_sec_ipsec_proto_init(struct rte_crypto_cipher_xform *cipher_xform,
2988 struct rte_crypto_auth_xform *auth_xform,
2989 dpaa2_sec_session *session,
2990 struct alginfo *cipherdata,
2991 struct alginfo *authdata)
2994 session->cipher_key.data = rte_zmalloc(NULL,
2995 cipher_xform->key.length,
2996 RTE_CACHE_LINE_SIZE);
2997 if (session->cipher_key.data == NULL &&
2998 cipher_xform->key.length > 0) {
2999 DPAA2_SEC_ERR("No Memory for cipher key");
3003 session->cipher_key.length = cipher_xform->key.length;
3004 memcpy(session->cipher_key.data, cipher_xform->key.data,
3005 cipher_xform->key.length);
3006 session->cipher_alg = cipher_xform->algo;
3008 session->cipher_key.data = NULL;
3009 session->cipher_key.length = 0;
3010 session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
3014 session->auth_key.data = rte_zmalloc(NULL,
3015 auth_xform->key.length,
3016 RTE_CACHE_LINE_SIZE);
3017 if (session->auth_key.data == NULL &&
3018 auth_xform->key.length > 0) {
3019 DPAA2_SEC_ERR("No Memory for auth key");
3022 session->auth_key.length = auth_xform->key.length;
3023 memcpy(session->auth_key.data, auth_xform->key.data,
3024 auth_xform->key.length);
3025 session->auth_alg = auth_xform->algo;
3026 session->digest_length = auth_xform->digest_length;
3028 session->auth_key.data = NULL;
3029 session->auth_key.length = 0;
3030 session->auth_alg = RTE_CRYPTO_AUTH_NULL;
3033 authdata->key = (size_t)session->auth_key.data;
3034 authdata->keylen = session->auth_key.length;
3035 authdata->key_enc_flags = 0;
3036 authdata->key_type = RTA_DATA_IMM;
3037 switch (session->auth_alg) {
3038 case RTE_CRYPTO_AUTH_SHA1_HMAC:
3039 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA1_96;
3040 authdata->algmode = OP_ALG_AAI_HMAC;
3042 case RTE_CRYPTO_AUTH_MD5_HMAC:
3043 authdata->algtype = OP_PCL_IPSEC_HMAC_MD5_96;
3044 authdata->algmode = OP_ALG_AAI_HMAC;
3046 case RTE_CRYPTO_AUTH_SHA256_HMAC:
3047 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_256_128;
3048 authdata->algmode = OP_ALG_AAI_HMAC;
3049 if (session->digest_length != 16)
3051 "+++Using sha256-hmac truncated len is non-standard,"
3052 "it will not work with lookaside proto");
3054 case RTE_CRYPTO_AUTH_SHA384_HMAC:
3055 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_384_192;
3056 authdata->algmode = OP_ALG_AAI_HMAC;
3058 case RTE_CRYPTO_AUTH_SHA512_HMAC:
3059 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_512_256;
3060 authdata->algmode = OP_ALG_AAI_HMAC;
3062 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
3063 authdata->algtype = OP_PCL_IPSEC_AES_XCBC_MAC_96;
3064 authdata->algmode = OP_ALG_AAI_XCBC_MAC;
3066 case RTE_CRYPTO_AUTH_AES_CMAC:
3067 authdata->algtype = OP_PCL_IPSEC_AES_CMAC_96;
3068 authdata->algmode = OP_ALG_AAI_CMAC;
3070 case RTE_CRYPTO_AUTH_NULL:
3071 authdata->algtype = OP_PCL_IPSEC_HMAC_NULL;
3073 case RTE_CRYPTO_AUTH_SHA224_HMAC:
3074 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
3075 case RTE_CRYPTO_AUTH_SHA1:
3076 case RTE_CRYPTO_AUTH_SHA256:
3077 case RTE_CRYPTO_AUTH_SHA512:
3078 case RTE_CRYPTO_AUTH_SHA224:
3079 case RTE_CRYPTO_AUTH_SHA384:
3080 case RTE_CRYPTO_AUTH_MD5:
3081 case RTE_CRYPTO_AUTH_AES_GMAC:
3082 case RTE_CRYPTO_AUTH_KASUMI_F9:
3083 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
3084 case RTE_CRYPTO_AUTH_ZUC_EIA3:
3085 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
3089 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
3093 cipherdata->key = (size_t)session->cipher_key.data;
3094 cipherdata->keylen = session->cipher_key.length;
3095 cipherdata->key_enc_flags = 0;
3096 cipherdata->key_type = RTA_DATA_IMM;
3098 switch (session->cipher_alg) {
3099 case RTE_CRYPTO_CIPHER_AES_CBC:
3100 cipherdata->algtype = OP_PCL_IPSEC_AES_CBC;
3101 cipherdata->algmode = OP_ALG_AAI_CBC;
3103 case RTE_CRYPTO_CIPHER_3DES_CBC:
3104 cipherdata->algtype = OP_PCL_IPSEC_3DES;
3105 cipherdata->algmode = OP_ALG_AAI_CBC;
3107 case RTE_CRYPTO_CIPHER_DES_CBC:
3108 cipherdata->algtype = OP_PCL_IPSEC_DES;
3109 cipherdata->algmode = OP_ALG_AAI_CBC;
3111 case RTE_CRYPTO_CIPHER_AES_CTR:
3112 cipherdata->algtype = OP_PCL_IPSEC_AES_CTR;
3113 cipherdata->algmode = OP_ALG_AAI_CTR;
3115 case RTE_CRYPTO_CIPHER_NULL:
3116 cipherdata->algtype = OP_PCL_IPSEC_NULL;
3118 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
3119 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
3120 case RTE_CRYPTO_CIPHER_3DES_ECB:
3121 case RTE_CRYPTO_CIPHER_3DES_CTR:
3122 case RTE_CRYPTO_CIPHER_AES_ECB:
3123 case RTE_CRYPTO_CIPHER_KASUMI_F8:
3124 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
3125 session->cipher_alg);
3128 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
3129 session->cipher_alg);
3137 dpaa2_sec_set_ipsec_session(struct rte_cryptodev *dev,
3138 struct rte_security_session_conf *conf,
3141 struct rte_security_ipsec_xform *ipsec_xform = &conf->ipsec;
3142 struct rte_crypto_cipher_xform *cipher_xform = NULL;
3143 struct rte_crypto_auth_xform *auth_xform = NULL;
3144 struct rte_crypto_aead_xform *aead_xform = NULL;
3145 dpaa2_sec_session *session = (dpaa2_sec_session *)sess;
3146 struct ctxt_priv *priv;
3147 struct alginfo authdata, cipherdata;
3149 struct sec_flow_context *flc;
3150 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
3153 PMD_INIT_FUNC_TRACE();
3155 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
3156 sizeof(struct ctxt_priv) +
3157 sizeof(struct sec_flc_desc),
3158 RTE_CACHE_LINE_SIZE);
3161 DPAA2_SEC_ERR("No memory for priv CTXT");
3165 priv->fle_pool = dev_priv->fle_pool;
3166 flc = &priv->flc_desc[0].flc;
3168 if (ipsec_xform->life.bytes_hard_limit != 0 ||
3169 ipsec_xform->life.bytes_soft_limit != 0 ||
3170 ipsec_xform->life.packets_hard_limit != 0 ||
3171 ipsec_xform->life.packets_soft_limit != 0)
3174 memset(session, 0, sizeof(dpaa2_sec_session));
3176 if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
3177 cipher_xform = &conf->crypto_xform->cipher;
3178 if (conf->crypto_xform->next)
3179 auth_xform = &conf->crypto_xform->next->auth;
3180 ret = dpaa2_sec_ipsec_proto_init(cipher_xform, auth_xform,
3181 session, &cipherdata, &authdata);
3182 } else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
3183 auth_xform = &conf->crypto_xform->auth;
3184 if (conf->crypto_xform->next)
3185 cipher_xform = &conf->crypto_xform->next->cipher;
3186 ret = dpaa2_sec_ipsec_proto_init(cipher_xform, auth_xform,
3187 session, &cipherdata, &authdata);
3188 } else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
3189 aead_xform = &conf->crypto_xform->aead;
3190 ret = dpaa2_sec_ipsec_aead_init(aead_xform,
3191 session, &cipherdata);
3192 authdata.keylen = 0;
3193 authdata.algtype = 0;
3195 DPAA2_SEC_ERR("XFORM not specified");
3200 DPAA2_SEC_ERR("Failed to process xform");
3204 session->ctxt_type = DPAA2_SEC_IPSEC;
3205 if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
3206 uint8_t *hdr = NULL;
3208 struct rte_ipv6_hdr ip6_hdr;
3209 struct ipsec_encap_pdb encap_pdb;
3211 flc->dhr = SEC_FLC_DHR_OUTBOUND;
3212 /* For Sec Proto only one descriptor is required. */
3213 memset(&encap_pdb, 0, sizeof(struct ipsec_encap_pdb));
3215 /* copy algo specific data to PDB */
3216 switch (cipherdata.algtype) {
3217 case OP_PCL_IPSEC_AES_CTR:
3218 encap_pdb.ctr.ctr_initial = 0x00000001;
3219 encap_pdb.ctr.ctr_nonce = ipsec_xform->salt;
3221 case OP_PCL_IPSEC_AES_GCM8:
3222 case OP_PCL_IPSEC_AES_GCM12:
3223 case OP_PCL_IPSEC_AES_GCM16:
3224 memcpy(encap_pdb.gcm.salt,
3225 (uint8_t *)&(ipsec_xform->salt), 4);
3229 encap_pdb.options = (IPVERSION << PDBNH_ESP_ENCAP_SHIFT) |
3230 PDBOPTS_ESP_OIHI_PDB_INL |
3233 if (ipsec_xform->options.dec_ttl)
3234 encap_pdb.options |= PDBHMO_ESP_ENCAP_DTTL;
3235 if (ipsec_xform->options.esn)
3236 encap_pdb.options |= PDBOPTS_ESP_ESN;
3237 encap_pdb.spi = ipsec_xform->spi;
3238 session->dir = DIR_ENC;
3239 if (ipsec_xform->tunnel.type ==
3240 RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
3241 encap_pdb.ip_hdr_len = sizeof(struct ip);
3242 ip4_hdr.ip_v = IPVERSION;
3244 ip4_hdr.ip_len = rte_cpu_to_be_16(sizeof(ip4_hdr));
3245 ip4_hdr.ip_tos = ipsec_xform->tunnel.ipv4.dscp;
3248 ip4_hdr.ip_ttl = ipsec_xform->tunnel.ipv4.ttl;
3249 ip4_hdr.ip_p = IPPROTO_ESP;
3251 ip4_hdr.ip_src = ipsec_xform->tunnel.ipv4.src_ip;
3252 ip4_hdr.ip_dst = ipsec_xform->tunnel.ipv4.dst_ip;
3253 ip4_hdr.ip_sum = calc_chksum((uint16_t *)(void *)
3254 &ip4_hdr, sizeof(struct ip));
3255 hdr = (uint8_t *)&ip4_hdr;
3256 } else if (ipsec_xform->tunnel.type ==
3257 RTE_SECURITY_IPSEC_TUNNEL_IPV6) {
3258 ip6_hdr.vtc_flow = rte_cpu_to_be_32(
3259 DPAA2_IPv6_DEFAULT_VTC_FLOW |
3260 ((ipsec_xform->tunnel.ipv6.dscp <<
3261 RTE_IPV6_HDR_TC_SHIFT) &
3262 RTE_IPV6_HDR_TC_MASK) |
3263 ((ipsec_xform->tunnel.ipv6.flabel <<
3264 RTE_IPV6_HDR_FL_SHIFT) &
3265 RTE_IPV6_HDR_FL_MASK));
3266 /* Payload length will be updated by HW */
3267 ip6_hdr.payload_len = 0;
3268 ip6_hdr.hop_limits =
3269 ipsec_xform->tunnel.ipv6.hlimit;
3270 ip6_hdr.proto = (ipsec_xform->proto ==
3271 RTE_SECURITY_IPSEC_SA_PROTO_ESP) ?
3272 IPPROTO_ESP : IPPROTO_AH;
3273 memcpy(&ip6_hdr.src_addr,
3274 &ipsec_xform->tunnel.ipv6.src_addr, 16);
3275 memcpy(&ip6_hdr.dst_addr,
3276 &ipsec_xform->tunnel.ipv6.dst_addr, 16);
3277 encap_pdb.ip_hdr_len = sizeof(struct rte_ipv6_hdr);
3278 hdr = (uint8_t *)&ip6_hdr;
3281 bufsize = cnstr_shdsc_ipsec_new_encap(priv->flc_desc[0].desc,
3282 1, 0, (rta_sec_era >= RTA_SEC_ERA_10) ?
3283 SHR_WAIT : SHR_SERIAL, &encap_pdb,
3284 hdr, &cipherdata, &authdata);
3285 } else if (ipsec_xform->direction ==
3286 RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
3287 struct ipsec_decap_pdb decap_pdb;
3289 flc->dhr = SEC_FLC_DHR_INBOUND;
3290 memset(&decap_pdb, 0, sizeof(struct ipsec_decap_pdb));
3291 /* copy algo specific data to PDB */
3292 switch (cipherdata.algtype) {
3293 case OP_PCL_IPSEC_AES_CTR:
3294 decap_pdb.ctr.ctr_initial = 0x00000001;
3295 decap_pdb.ctr.ctr_nonce = ipsec_xform->salt;
3297 case OP_PCL_IPSEC_AES_GCM8:
3298 case OP_PCL_IPSEC_AES_GCM12:
3299 case OP_PCL_IPSEC_AES_GCM16:
3300 memcpy(decap_pdb.gcm.salt,
3301 (uint8_t *)&(ipsec_xform->salt), 4);
3305 decap_pdb.options = (ipsec_xform->tunnel.type ==
3306 RTE_SECURITY_IPSEC_TUNNEL_IPV4) ?
3307 sizeof(struct ip) << 16 :
3308 sizeof(struct rte_ipv6_hdr) << 16;
3309 if (ipsec_xform->options.esn)
3310 decap_pdb.options |= PDBOPTS_ESP_ESN;
3312 if (ipsec_xform->replay_win_sz) {
3314 win_sz = rte_align32pow2(ipsec_xform->replay_win_sz);
3316 if (rta_sec_era < RTA_SEC_ERA_10 && win_sz > 128) {
3317 DPAA2_SEC_INFO("Max Anti replay Win sz = 128");
3327 decap_pdb.options |= PDBOPTS_ESP_ARS32;
3330 decap_pdb.options |= PDBOPTS_ESP_ARS64;
3333 decap_pdb.options |= PDBOPTS_ESP_ARS256;
3336 decap_pdb.options |= PDBOPTS_ESP_ARS512;
3339 decap_pdb.options |= PDBOPTS_ESP_ARS1024;
3343 decap_pdb.options |= PDBOPTS_ESP_ARS128;
3346 session->dir = DIR_DEC;
3347 bufsize = cnstr_shdsc_ipsec_new_decap(priv->flc_desc[0].desc,
3348 1, 0, (rta_sec_era >= RTA_SEC_ERA_10) ?
3349 SHR_WAIT : SHR_SERIAL,
3350 &decap_pdb, &cipherdata, &authdata);
3355 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
3359 flc->word1_sdl = (uint8_t)bufsize;
3361 /* Enable the stashing control bit */
3362 DPAA2_SET_FLC_RSC(flc);
3363 flc->word2_rflc_31_0 = lower_32_bits(
3364 (size_t)&(((struct dpaa2_sec_qp *)
3365 dev->data->queue_pairs[0])->rx_vq) | 0x14);
3366 flc->word3_rflc_63_32 = upper_32_bits(
3367 (size_t)&(((struct dpaa2_sec_qp *)
3368 dev->data->queue_pairs[0])->rx_vq));
3370 /* Set EWS bit i.e. enable write-safe */
3371 DPAA2_SET_FLC_EWS(flc);
3372 /* Set BS = 1 i.e reuse input buffers as output buffers */
3373 DPAA2_SET_FLC_REUSE_BS(flc);
3374 /* Set FF = 10; reuse input buffers if they provide sufficient space */
3375 DPAA2_SET_FLC_REUSE_FF(flc);
3377 session->ctxt = priv;
3381 rte_free(session->auth_key.data);
3382 rte_free(session->cipher_key.data);
3388 dpaa2_sec_set_pdcp_session(struct rte_cryptodev *dev,
3389 struct rte_security_session_conf *conf,
3392 struct rte_security_pdcp_xform *pdcp_xform = &conf->pdcp;
3393 struct rte_crypto_sym_xform *xform = conf->crypto_xform;
3394 struct rte_crypto_auth_xform *auth_xform = NULL;
3395 struct rte_crypto_cipher_xform *cipher_xform = NULL;
3396 dpaa2_sec_session *session = (dpaa2_sec_session *)sess;
3397 struct ctxt_priv *priv;
3398 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
3399 struct alginfo authdata, cipherdata;
3400 struct alginfo *p_authdata = NULL;
3402 struct sec_flow_context *flc;
3403 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
3409 PMD_INIT_FUNC_TRACE();
3411 memset(session, 0, sizeof(dpaa2_sec_session));
3413 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
3414 sizeof(struct ctxt_priv) +
3415 sizeof(struct sec_flc_desc),
3416 RTE_CACHE_LINE_SIZE);
3419 DPAA2_SEC_ERR("No memory for priv CTXT");
3423 priv->fle_pool = dev_priv->fle_pool;
3424 flc = &priv->flc_desc[0].flc;
3426 /* find xfrm types */
3427 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
3428 cipher_xform = &xform->cipher;
3429 if (xform->next != NULL &&
3430 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
3431 session->ext_params.aead_ctxt.auth_cipher_text = true;
3432 auth_xform = &xform->next->auth;
3434 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
3435 auth_xform = &xform->auth;
3436 if (xform->next != NULL &&
3437 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
3438 session->ext_params.aead_ctxt.auth_cipher_text = false;
3439 cipher_xform = &xform->next->cipher;
3442 DPAA2_SEC_ERR("Invalid crypto type");
3446 session->ctxt_type = DPAA2_SEC_PDCP;
3448 session->cipher_key.data = rte_zmalloc(NULL,
3449 cipher_xform->key.length,
3450 RTE_CACHE_LINE_SIZE);
3451 if (session->cipher_key.data == NULL &&
3452 cipher_xform->key.length > 0) {
3453 DPAA2_SEC_ERR("No Memory for cipher key");
3457 session->cipher_key.length = cipher_xform->key.length;
3458 memcpy(session->cipher_key.data, cipher_xform->key.data,
3459 cipher_xform->key.length);
3461 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
3463 session->cipher_alg = cipher_xform->algo;
3465 session->cipher_key.data = NULL;
3466 session->cipher_key.length = 0;
3467 session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
3468 session->dir = DIR_ENC;
3471 session->pdcp.domain = pdcp_xform->domain;
3472 session->pdcp.bearer = pdcp_xform->bearer;
3473 session->pdcp.pkt_dir = pdcp_xform->pkt_dir;
3474 session->pdcp.sn_size = pdcp_xform->sn_size;
3475 session->pdcp.hfn = pdcp_xform->hfn;
3476 session->pdcp.hfn_threshold = pdcp_xform->hfn_threshold;
3477 session->pdcp.hfn_ovd = pdcp_xform->hfn_ovrd;
3478 /* hfv ovd offset location is stored in iv.offset value*/
3480 session->pdcp.hfn_ovd_offset = cipher_xform->iv.offset;
3482 cipherdata.key = (size_t)session->cipher_key.data;
3483 cipherdata.keylen = session->cipher_key.length;
3484 cipherdata.key_enc_flags = 0;
3485 cipherdata.key_type = RTA_DATA_IMM;
3487 switch (session->cipher_alg) {
3488 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
3489 cipherdata.algtype = PDCP_CIPHER_TYPE_SNOW;
3491 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
3492 cipherdata.algtype = PDCP_CIPHER_TYPE_ZUC;
3494 case RTE_CRYPTO_CIPHER_AES_CTR:
3495 cipherdata.algtype = PDCP_CIPHER_TYPE_AES;
3497 case RTE_CRYPTO_CIPHER_NULL:
3498 cipherdata.algtype = PDCP_CIPHER_TYPE_NULL;
3501 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
3502 session->cipher_alg);
3507 session->auth_key.data = rte_zmalloc(NULL,
3508 auth_xform->key.length,
3509 RTE_CACHE_LINE_SIZE);
3510 if (!session->auth_key.data &&
3511 auth_xform->key.length > 0) {
3512 DPAA2_SEC_ERR("No Memory for auth key");
3513 rte_free(session->cipher_key.data);
3517 session->auth_key.length = auth_xform->key.length;
3518 memcpy(session->auth_key.data, auth_xform->key.data,
3519 auth_xform->key.length);
3520 session->auth_alg = auth_xform->algo;
3522 session->auth_key.data = NULL;
3523 session->auth_key.length = 0;
3524 session->auth_alg = 0;
3526 authdata.key = (size_t)session->auth_key.data;
3527 authdata.keylen = session->auth_key.length;
3528 authdata.key_enc_flags = 0;
3529 authdata.key_type = RTA_DATA_IMM;
3531 if (session->auth_alg) {
3532 switch (session->auth_alg) {
3533 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
3534 authdata.algtype = PDCP_AUTH_TYPE_SNOW;
3536 case RTE_CRYPTO_AUTH_ZUC_EIA3:
3537 authdata.algtype = PDCP_AUTH_TYPE_ZUC;
3539 case RTE_CRYPTO_AUTH_AES_CMAC:
3540 authdata.algtype = PDCP_AUTH_TYPE_AES;
3542 case RTE_CRYPTO_AUTH_NULL:
3543 authdata.algtype = PDCP_AUTH_TYPE_NULL;
3546 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
3551 p_authdata = &authdata;
3552 } else if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
3553 DPAA2_SEC_ERR("Crypto: Integrity must for c-plane");
3557 if (pdcp_xform->sdap_enabled) {
3558 int nb_keys_to_inline =
3559 rta_inline_pdcp_sdap_query(authdata.algtype,
3561 session->pdcp.sn_size,
3562 session->pdcp.hfn_ovd);
3563 if (nb_keys_to_inline >= 1) {
3564 cipherdata.key = DPAA2_VADDR_TO_IOVA(cipherdata.key);
3565 cipherdata.key_type = RTA_DATA_PTR;
3567 if (nb_keys_to_inline >= 2) {
3568 authdata.key = DPAA2_VADDR_TO_IOVA(authdata.key);
3569 authdata.key_type = RTA_DATA_PTR;
3572 if (rta_inline_pdcp_query(authdata.algtype,
3574 session->pdcp.sn_size,
3575 session->pdcp.hfn_ovd)) {
3576 cipherdata.key = DPAA2_VADDR_TO_IOVA(cipherdata.key);
3577 cipherdata.key_type = RTA_DATA_PTR;
3581 if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_CONTROL) {
3582 if (session->dir == DIR_ENC)
3583 bufsize = cnstr_shdsc_pdcp_c_plane_encap(
3584 priv->flc_desc[0].desc, 1, swap,
3586 session->pdcp.sn_size,
3588 pdcp_xform->pkt_dir,
3589 pdcp_xform->hfn_threshold,
3590 &cipherdata, &authdata);
3591 else if (session->dir == DIR_DEC)
3592 bufsize = cnstr_shdsc_pdcp_c_plane_decap(
3593 priv->flc_desc[0].desc, 1, swap,
3595 session->pdcp.sn_size,
3597 pdcp_xform->pkt_dir,
3598 pdcp_xform->hfn_threshold,
3599 &cipherdata, &authdata);
3601 } else if (pdcp_xform->domain == RTE_SECURITY_PDCP_MODE_SHORT_MAC) {
3602 bufsize = cnstr_shdsc_pdcp_short_mac(priv->flc_desc[0].desc,
3603 1, swap, &authdata);
3605 if (session->dir == DIR_ENC) {
3606 if (pdcp_xform->sdap_enabled)
3607 bufsize = cnstr_shdsc_pdcp_sdap_u_plane_encap(
3608 priv->flc_desc[0].desc, 1, swap,
3609 session->pdcp.sn_size,
3612 pdcp_xform->pkt_dir,
3613 pdcp_xform->hfn_threshold,
3614 &cipherdata, p_authdata);
3616 bufsize = cnstr_shdsc_pdcp_u_plane_encap(
3617 priv->flc_desc[0].desc, 1, swap,
3618 session->pdcp.sn_size,
3621 pdcp_xform->pkt_dir,
3622 pdcp_xform->hfn_threshold,
3623 &cipherdata, p_authdata);
3624 } else if (session->dir == DIR_DEC) {
3625 if (pdcp_xform->sdap_enabled)
3626 bufsize = cnstr_shdsc_pdcp_sdap_u_plane_decap(
3627 priv->flc_desc[0].desc, 1, swap,
3628 session->pdcp.sn_size,
3631 pdcp_xform->pkt_dir,
3632 pdcp_xform->hfn_threshold,
3633 &cipherdata, p_authdata);
3635 bufsize = cnstr_shdsc_pdcp_u_plane_decap(
3636 priv->flc_desc[0].desc, 1, swap,
3637 session->pdcp.sn_size,
3640 pdcp_xform->pkt_dir,
3641 pdcp_xform->hfn_threshold,
3642 &cipherdata, p_authdata);
3647 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
3651 /* Enable the stashing control bit */
3652 DPAA2_SET_FLC_RSC(flc);
3653 flc->word2_rflc_31_0 = lower_32_bits(
3654 (size_t)&(((struct dpaa2_sec_qp *)
3655 dev->data->queue_pairs[0])->rx_vq) | 0x14);
3656 flc->word3_rflc_63_32 = upper_32_bits(
3657 (size_t)&(((struct dpaa2_sec_qp *)
3658 dev->data->queue_pairs[0])->rx_vq));
3660 flc->word1_sdl = (uint8_t)bufsize;
3662 /* TODO - check the perf impact or
3663 * align as per descriptor type
3664 * Set EWS bit i.e. enable write-safe
3665 * DPAA2_SET_FLC_EWS(flc);
3668 /* Set BS = 1 i.e reuse input buffers as output buffers */
3669 DPAA2_SET_FLC_REUSE_BS(flc);
3670 /* Set FF = 10; reuse input buffers if they provide sufficient space */
3671 DPAA2_SET_FLC_REUSE_FF(flc);
3673 session->ctxt = priv;
3677 rte_free(session->auth_key.data);
3678 rte_free(session->cipher_key.data);
3684 dpaa2_sec_security_session_create(void *dev,
3685 struct rte_security_session_conf *conf,
3686 struct rte_security_session *sess,
3687 struct rte_mempool *mempool)
3689 void *sess_private_data;
3690 struct rte_cryptodev *cdev = (struct rte_cryptodev *)dev;
3693 if (rte_mempool_get(mempool, &sess_private_data)) {
3694 DPAA2_SEC_ERR("Couldn't get object from session mempool");
3698 switch (conf->protocol) {
3699 case RTE_SECURITY_PROTOCOL_IPSEC:
3700 ret = dpaa2_sec_set_ipsec_session(cdev, conf,
3703 case RTE_SECURITY_PROTOCOL_MACSEC:
3705 case RTE_SECURITY_PROTOCOL_PDCP:
3706 ret = dpaa2_sec_set_pdcp_session(cdev, conf,
3713 DPAA2_SEC_ERR("Failed to configure session parameters");
3714 /* Return session to mempool */
3715 rte_mempool_put(mempool, sess_private_data);
3719 set_sec_session_private_data(sess, sess_private_data);
3724 /** Clear the memory of session so it doesn't leave key material behind */
3726 dpaa2_sec_security_session_destroy(void *dev __rte_unused,
3727 struct rte_security_session *sess)
3729 PMD_INIT_FUNC_TRACE();
3730 void *sess_priv = get_sec_session_private_data(sess);
3732 dpaa2_sec_session *s = (dpaa2_sec_session *)sess_priv;
3735 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
3738 rte_free(s->cipher_key.data);
3739 rte_free(s->auth_key.data);
3740 memset(s, 0, sizeof(dpaa2_sec_session));
3741 set_sec_session_private_data(sess, NULL);
3742 rte_mempool_put(sess_mp, sess_priv);
3748 dpaa2_sec_sym_session_configure(struct rte_cryptodev *dev,
3749 struct rte_crypto_sym_xform *xform,
3750 struct rte_cryptodev_sym_session *sess,
3751 struct rte_mempool *mempool)
3753 void *sess_private_data;
3756 if (rte_mempool_get(mempool, &sess_private_data)) {
3757 DPAA2_SEC_ERR("Couldn't get object from session mempool");
3761 ret = dpaa2_sec_set_session_parameters(dev, xform, sess_private_data);
3763 DPAA2_SEC_ERR("Failed to configure session parameters");
3764 /* Return session to mempool */
3765 rte_mempool_put(mempool, sess_private_data);
3769 set_sym_session_private_data(sess, dev->driver_id,
3775 /** Clear the memory of session so it doesn't leave key material behind */
3777 dpaa2_sec_sym_session_clear(struct rte_cryptodev *dev,
3778 struct rte_cryptodev_sym_session *sess)
3780 PMD_INIT_FUNC_TRACE();
3781 uint8_t index = dev->driver_id;
3782 void *sess_priv = get_sym_session_private_data(sess, index);
3783 dpaa2_sec_session *s = (dpaa2_sec_session *)sess_priv;
3787 rte_free(s->cipher_key.data);
3788 rte_free(s->auth_key.data);
3789 memset(s, 0, sizeof(dpaa2_sec_session));
3790 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
3791 set_sym_session_private_data(sess, index, NULL);
3792 rte_mempool_put(sess_mp, sess_priv);
3797 dpaa2_sec_dev_configure(struct rte_cryptodev *dev __rte_unused,
3798 struct rte_cryptodev_config *config __rte_unused)
3800 PMD_INIT_FUNC_TRACE();
3806 dpaa2_sec_dev_start(struct rte_cryptodev *dev)
3808 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3809 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3810 struct dpseci_attr attr;
3811 struct dpaa2_queue *dpaa2_q;
3812 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3813 dev->data->queue_pairs;
3814 struct dpseci_rx_queue_attr rx_attr;
3815 struct dpseci_tx_queue_attr tx_attr;
3818 PMD_INIT_FUNC_TRACE();
3820 /* Change the tx burst function if ordered queues are used */
3821 if (priv->en_ordered)
3822 dev->enqueue_burst = dpaa2_sec_enqueue_burst_ordered;
3824 memset(&attr, 0, sizeof(struct dpseci_attr));
3826 ret = dpseci_enable(dpseci, CMD_PRI_LOW, priv->token);
3828 DPAA2_SEC_ERR("DPSECI with HW_ID = %d ENABLE FAILED",
3830 goto get_attr_failure;
3832 ret = dpseci_get_attributes(dpseci, CMD_PRI_LOW, priv->token, &attr);
3834 DPAA2_SEC_ERR("DPSEC ATTRIBUTE READ FAILED, disabling DPSEC");
3835 goto get_attr_failure;
3837 for (i = 0; i < attr.num_rx_queues && qp[i]; i++) {
3838 dpaa2_q = &qp[i]->rx_vq;
3839 dpseci_get_rx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
3841 dpaa2_q->fqid = rx_attr.fqid;
3842 DPAA2_SEC_DEBUG("rx_fqid: %d", dpaa2_q->fqid);
3844 for (i = 0; i < attr.num_tx_queues && qp[i]; i++) {
3845 dpaa2_q = &qp[i]->tx_vq;
3846 dpseci_get_tx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
3848 dpaa2_q->fqid = tx_attr.fqid;
3849 DPAA2_SEC_DEBUG("tx_fqid: %d", dpaa2_q->fqid);
3854 dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
3859 dpaa2_sec_dev_stop(struct rte_cryptodev *dev)
3861 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3862 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
3865 PMD_INIT_FUNC_TRACE();
3867 ret = dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
3869 DPAA2_SEC_ERR("Failure in disabling dpseci %d device",
3874 ret = dpseci_reset(dpseci, CMD_PRI_LOW, priv->token);
3876 DPAA2_SEC_ERR("SEC Device cannot be reset:Error = %0x", ret);
3882 dpaa2_sec_dev_close(struct rte_cryptodev *dev __rte_unused)
3884 PMD_INIT_FUNC_TRACE();
3890 dpaa2_sec_dev_infos_get(struct rte_cryptodev *dev,
3891 struct rte_cryptodev_info *info)
3893 struct dpaa2_sec_dev_private *internals = dev->data->dev_private;
3895 PMD_INIT_FUNC_TRACE();
3897 info->max_nb_queue_pairs = internals->max_nb_queue_pairs;
3898 info->feature_flags = dev->feature_flags;
3899 info->capabilities = dpaa2_sec_capabilities;
3900 /* No limit of number of sessions */
3901 info->sym.max_nb_sessions = 0;
3902 info->driver_id = cryptodev_driver_id;
3907 void dpaa2_sec_stats_get(struct rte_cryptodev *dev,
3908 struct rte_cryptodev_stats *stats)
3910 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
3911 struct fsl_mc_io dpseci;
3912 struct dpseci_sec_counters counters = {0};
3913 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3914 dev->data->queue_pairs;
3917 PMD_INIT_FUNC_TRACE();
3918 if (stats == NULL) {
3919 DPAA2_SEC_ERR("Invalid stats ptr NULL");
3922 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
3923 if (qp == NULL || qp[i] == NULL) {
3924 DPAA2_SEC_DEBUG("Uninitialised queue pair");
3928 stats->enqueued_count += qp[i]->tx_vq.tx_pkts;
3929 stats->dequeued_count += qp[i]->rx_vq.rx_pkts;
3930 stats->enqueue_err_count += qp[i]->tx_vq.err_pkts;
3931 stats->dequeue_err_count += qp[i]->rx_vq.err_pkts;
3934 /* In case as secondary process access stats, MCP portal in priv-hw
3935 * may have primary process address. Need the secondary process
3936 * based MCP portal address for this object.
3938 dpseci.regs = dpaa2_get_mcp_ptr(MC_PORTAL_INDEX);
3939 ret = dpseci_get_sec_counters(&dpseci, CMD_PRI_LOW, priv->token,
3942 DPAA2_SEC_ERR("SEC counters failed");
3944 DPAA2_SEC_INFO("dpseci hardware stats:"
3945 "\n\tNum of Requests Dequeued = %" PRIu64
3946 "\n\tNum of Outbound Encrypt Requests = %" PRIu64
3947 "\n\tNum of Inbound Decrypt Requests = %" PRIu64
3948 "\n\tNum of Outbound Bytes Encrypted = %" PRIu64
3949 "\n\tNum of Outbound Bytes Protected = %" PRIu64
3950 "\n\tNum of Inbound Bytes Decrypted = %" PRIu64
3951 "\n\tNum of Inbound Bytes Validated = %" PRIu64,
3952 counters.dequeued_requests,
3953 counters.ob_enc_requests,
3954 counters.ib_dec_requests,
3955 counters.ob_enc_bytes,
3956 counters.ob_prot_bytes,
3957 counters.ib_dec_bytes,
3958 counters.ib_valid_bytes);
3963 void dpaa2_sec_stats_reset(struct rte_cryptodev *dev)
3966 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
3967 (dev->data->queue_pairs);
3969 PMD_INIT_FUNC_TRACE();
3971 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
3972 if (qp[i] == NULL) {
3973 DPAA2_SEC_DEBUG("Uninitialised queue pair");
3976 qp[i]->tx_vq.rx_pkts = 0;
3977 qp[i]->tx_vq.tx_pkts = 0;
3978 qp[i]->tx_vq.err_pkts = 0;
3979 qp[i]->rx_vq.rx_pkts = 0;
3980 qp[i]->rx_vq.tx_pkts = 0;
3981 qp[i]->rx_vq.err_pkts = 0;
3985 static void __rte_hot
3986 dpaa2_sec_process_parallel_event(struct qbman_swp *swp,
3987 const struct qbman_fd *fd,
3988 const struct qbman_result *dq,
3989 struct dpaa2_queue *rxq,
3990 struct rte_event *ev)
3992 /* Prefetching mbuf */
3993 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-
3994 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size));
3996 /* Prefetching ipsec crypto_op stored in priv data of mbuf */
3997 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-64));
3999 ev->flow_id = rxq->ev.flow_id;
4000 ev->sub_event_type = rxq->ev.sub_event_type;
4001 ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
4002 ev->op = RTE_EVENT_OP_NEW;
4003 ev->sched_type = rxq->ev.sched_type;
4004 ev->queue_id = rxq->ev.queue_id;
4005 ev->priority = rxq->ev.priority;
4006 ev->event_ptr = sec_fd_to_mbuf(fd);
4008 qbman_swp_dqrr_consume(swp, dq);
4011 dpaa2_sec_process_atomic_event(struct qbman_swp *swp __rte_unused,
4012 const struct qbman_fd *fd,
4013 const struct qbman_result *dq,
4014 struct dpaa2_queue *rxq,
4015 struct rte_event *ev)
4018 struct rte_crypto_op *crypto_op = (struct rte_crypto_op *)ev->event_ptr;
4019 /* Prefetching mbuf */
4020 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-
4021 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size));
4023 /* Prefetching ipsec crypto_op stored in priv data of mbuf */
4024 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-64));
4026 ev->flow_id = rxq->ev.flow_id;
4027 ev->sub_event_type = rxq->ev.sub_event_type;
4028 ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
4029 ev->op = RTE_EVENT_OP_NEW;
4030 ev->sched_type = rxq->ev.sched_type;
4031 ev->queue_id = rxq->ev.queue_id;
4032 ev->priority = rxq->ev.priority;
4034 ev->event_ptr = sec_fd_to_mbuf(fd);
4035 dqrr_index = qbman_get_dqrr_idx(dq);
4036 *dpaa2_seqn(crypto_op->sym->m_src) = QBMAN_ENQUEUE_FLAG_DCA | dqrr_index;
4037 DPAA2_PER_LCORE_DQRR_SIZE++;
4038 DPAA2_PER_LCORE_DQRR_HELD |= 1 << dqrr_index;
4039 DPAA2_PER_LCORE_DQRR_MBUF(dqrr_index) = crypto_op->sym->m_src;
4042 static void __rte_hot
4043 dpaa2_sec_process_ordered_event(struct qbman_swp *swp,
4044 const struct qbman_fd *fd,
4045 const struct qbman_result *dq,
4046 struct dpaa2_queue *rxq,
4047 struct rte_event *ev)
4049 struct rte_crypto_op *crypto_op = (struct rte_crypto_op *)ev->event_ptr;
4051 /* Prefetching mbuf */
4052 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-
4053 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size));
4055 /* Prefetching ipsec crypto_op stored in priv data of mbuf */
4056 rte_prefetch0((void *)(size_t)(DPAA2_GET_FD_ADDR(fd)-64));
4058 ev->flow_id = rxq->ev.flow_id;
4059 ev->sub_event_type = rxq->ev.sub_event_type;
4060 ev->event_type = RTE_EVENT_TYPE_CRYPTODEV;
4061 ev->op = RTE_EVENT_OP_NEW;
4062 ev->sched_type = rxq->ev.sched_type;
4063 ev->queue_id = rxq->ev.queue_id;
4064 ev->priority = rxq->ev.priority;
4065 ev->event_ptr = sec_fd_to_mbuf(fd);
4067 *dpaa2_seqn(crypto_op->sym->m_src) = DPAA2_ENQUEUE_FLAG_ORP;
4068 *dpaa2_seqn(crypto_op->sym->m_src) |= qbman_result_DQ_odpid(dq) <<
4069 DPAA2_EQCR_OPRID_SHIFT;
4070 *dpaa2_seqn(crypto_op->sym->m_src) |= qbman_result_DQ_seqnum(dq) <<
4071 DPAA2_EQCR_SEQNUM_SHIFT;
4073 qbman_swp_dqrr_consume(swp, dq);
4077 dpaa2_sec_eventq_attach(const struct rte_cryptodev *dev,
4079 struct dpaa2_dpcon_dev *dpcon,
4080 const struct rte_event *event)
4082 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
4083 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
4084 struct dpaa2_sec_qp *qp = dev->data->queue_pairs[qp_id];
4085 struct dpseci_rx_queue_cfg cfg;
4089 if (event->sched_type == RTE_SCHED_TYPE_PARALLEL)
4090 qp->rx_vq.cb = dpaa2_sec_process_parallel_event;
4091 else if (event->sched_type == RTE_SCHED_TYPE_ATOMIC)
4092 qp->rx_vq.cb = dpaa2_sec_process_atomic_event;
4093 else if (event->sched_type == RTE_SCHED_TYPE_ORDERED)
4094 qp->rx_vq.cb = dpaa2_sec_process_ordered_event;
4098 priority = (RTE_EVENT_DEV_PRIORITY_LOWEST / event->priority) *
4099 (dpcon->num_priorities - 1);
4101 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
4102 cfg.options = DPSECI_QUEUE_OPT_DEST;
4103 cfg.dest_cfg.dest_type = DPSECI_DEST_DPCON;
4104 cfg.dest_cfg.dest_id = dpcon->dpcon_id;
4105 cfg.dest_cfg.priority = priority;
4107 cfg.options |= DPSECI_QUEUE_OPT_USER_CTX;
4108 cfg.user_ctx = (size_t)(qp);
4109 if (event->sched_type == RTE_SCHED_TYPE_ATOMIC) {
4110 cfg.options |= DPSECI_QUEUE_OPT_ORDER_PRESERVATION;
4111 cfg.order_preservation_en = 1;
4114 if (event->sched_type == RTE_SCHED_TYPE_ORDERED) {
4115 struct opr_cfg ocfg;
4117 /* Restoration window size = 256 frames */
4119 /* Restoration window size = 512 frames for LX2 */
4120 if (dpaa2_svr_family == SVR_LX2160A)
4122 /* Auto advance NESN window enabled */
4124 /* Late arrival window size disabled */
4126 /* ORL resource exhaustaion advance NESN disabled */
4129 if (priv->en_loose_ordered)
4134 ret = dpseci_set_opr(dpseci, CMD_PRI_LOW, priv->token,
4135 qp_id, OPR_OPT_CREATE, &ocfg);
4137 RTE_LOG(ERR, PMD, "Error setting opr: ret: %d\n", ret);
4140 qp->tx_vq.cb_eqresp_free = dpaa2_sec_free_eqresp_buf;
4141 priv->en_ordered = 1;
4144 ret = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
4147 RTE_LOG(ERR, PMD, "Error in dpseci_set_queue: ret: %d\n", ret);
4151 memcpy(&qp->rx_vq.ev, event, sizeof(struct rte_event));
4157 dpaa2_sec_eventq_detach(const struct rte_cryptodev *dev,
4160 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
4161 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
4162 struct dpseci_rx_queue_cfg cfg;
4165 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
4166 cfg.options = DPSECI_QUEUE_OPT_DEST;
4167 cfg.dest_cfg.dest_type = DPSECI_DEST_NONE;
4169 ret = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
4172 RTE_LOG(ERR, PMD, "Error in dpseci_set_queue: ret: %d\n", ret);
4177 static struct rte_cryptodev_ops crypto_ops = {
4178 .dev_configure = dpaa2_sec_dev_configure,
4179 .dev_start = dpaa2_sec_dev_start,
4180 .dev_stop = dpaa2_sec_dev_stop,
4181 .dev_close = dpaa2_sec_dev_close,
4182 .dev_infos_get = dpaa2_sec_dev_infos_get,
4183 .stats_get = dpaa2_sec_stats_get,
4184 .stats_reset = dpaa2_sec_stats_reset,
4185 .queue_pair_setup = dpaa2_sec_queue_pair_setup,
4186 .queue_pair_release = dpaa2_sec_queue_pair_release,
4187 .sym_session_get_size = dpaa2_sec_sym_session_get_size,
4188 .sym_session_configure = dpaa2_sec_sym_session_configure,
4189 .sym_session_clear = dpaa2_sec_sym_session_clear,
4190 /* Raw data-path API related operations */
4191 .sym_get_raw_dp_ctx_size = dpaa2_sec_get_dp_ctx_size,
4192 .sym_configure_raw_dp_ctx = dpaa2_sec_configure_raw_dp_ctx,
4195 #ifdef RTE_LIB_SECURITY
4196 static const struct rte_security_capability *
4197 dpaa2_sec_capabilities_get(void *device __rte_unused)
4199 return dpaa2_sec_security_cap;
4202 static const struct rte_security_ops dpaa2_sec_security_ops = {
4203 .session_create = dpaa2_sec_security_session_create,
4204 .session_update = NULL,
4205 .session_stats_get = NULL,
4206 .session_destroy = dpaa2_sec_security_session_destroy,
4207 .set_pkt_metadata = NULL,
4208 .capabilities_get = dpaa2_sec_capabilities_get
4213 dpaa2_sec_uninit(const struct rte_cryptodev *dev)
4215 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
4216 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
4219 PMD_INIT_FUNC_TRACE();
4221 /* Function is reverse of dpaa2_sec_dev_init.
4222 * It does the following:
4223 * 1. Detach a DPSECI from attached resources i.e. buffer pools, dpbp_id
4224 * 2. Close the DPSECI device
4225 * 3. Free the allocated resources.
4228 /*Close the device at underlying layer*/
4229 ret = dpseci_close(dpseci, CMD_PRI_LOW, priv->token);
4231 DPAA2_SEC_ERR("Failure closing dpseci device: err(%d)", ret);
4235 /*Free the allocated memory for ethernet private data and dpseci*/
4238 rte_free(dev->security_ctx);
4239 rte_mempool_free(priv->fle_pool);
4241 DPAA2_SEC_INFO("Closing DPAA2_SEC device %s on numa socket %u",
4242 dev->data->name, rte_socket_id());
4248 check_devargs_handler(const char *key, const char *value,
4251 struct rte_cryptodev *dev = (struct rte_cryptodev *)opaque;
4252 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
4254 if (!strcmp(key, "drv_strict_order")) {
4255 priv->en_loose_ordered = false;
4256 } else if (!strcmp(key, "drv_dump_mode")) {
4257 dpaa2_sec_dp_dump = atoi(value);
4258 if (dpaa2_sec_dp_dump > DPAA2_SEC_DP_FULL_DUMP) {
4259 DPAA2_SEC_WARN("WARN: DPAA2_SEC_DP_DUMP_LEVEL is not "
4260 "supported, changing to FULL error"
4262 dpaa2_sec_dp_dump = DPAA2_SEC_DP_FULL_DUMP;
4271 dpaa2_sec_get_devargs(struct rte_cryptodev *cryptodev, const char *key)
4273 struct rte_kvargs *kvlist;
4274 struct rte_devargs *devargs;
4276 devargs = cryptodev->device->devargs;
4280 kvlist = rte_kvargs_parse(devargs->args, NULL);
4284 if (!rte_kvargs_count(kvlist, key)) {
4285 rte_kvargs_free(kvlist);
4289 rte_kvargs_process(kvlist, key,
4290 check_devargs_handler, (void *)cryptodev);
4291 rte_kvargs_free(kvlist);
4295 dpaa2_sec_dev_init(struct rte_cryptodev *cryptodev)
4297 struct dpaa2_sec_dev_private *internals;
4298 struct rte_device *dev = cryptodev->device;
4299 struct rte_dpaa2_device *dpaa2_dev;
4300 #ifdef RTE_LIB_SECURITY
4301 struct rte_security_ctx *security_instance;
4303 struct fsl_mc_io *dpseci;
4305 struct dpseci_attr attr;
4309 PMD_INIT_FUNC_TRACE();
4310 dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
4311 hw_id = dpaa2_dev->object_id;
4313 cryptodev->driver_id = cryptodev_driver_id;
4314 cryptodev->dev_ops = &crypto_ops;
4316 cryptodev->enqueue_burst = dpaa2_sec_enqueue_burst;
4317 cryptodev->dequeue_burst = dpaa2_sec_dequeue_burst;
4318 cryptodev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
4319 RTE_CRYPTODEV_FF_HW_ACCELERATED |
4320 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
4321 RTE_CRYPTODEV_FF_SECURITY |
4322 RTE_CRYPTODEV_FF_SYM_RAW_DP |
4323 RTE_CRYPTODEV_FF_IN_PLACE_SGL |
4324 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT |
4325 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
4326 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT |
4327 RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT;
4329 internals = cryptodev->data->dev_private;
4332 * For secondary processes, we don't initialise any further as primary
4333 * has already done this work. Only check we don't need a different
4336 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
4337 DPAA2_SEC_DEBUG("Device already init by primary process");
4340 #ifdef RTE_LIB_SECURITY
4341 /* Initialize security_ctx only for primary process*/
4342 security_instance = rte_malloc("rte_security_instances_ops",
4343 sizeof(struct rte_security_ctx), 0);
4344 if (security_instance == NULL)
4346 security_instance->device = (void *)cryptodev;
4347 security_instance->ops = &dpaa2_sec_security_ops;
4348 security_instance->sess_cnt = 0;
4349 cryptodev->security_ctx = security_instance;
4351 /*Open the rte device via MC and save the handle for further use*/
4352 dpseci = (struct fsl_mc_io *)rte_calloc(NULL, 1,
4353 sizeof(struct fsl_mc_io), 0);
4356 "Error in allocating the memory for dpsec object");
4359 dpseci->regs = dpaa2_get_mcp_ptr(MC_PORTAL_INDEX);
4361 retcode = dpseci_open(dpseci, CMD_PRI_LOW, hw_id, &token);
4363 DPAA2_SEC_ERR("Cannot open the dpsec device: Error = %x",
4367 retcode = dpseci_get_attributes(dpseci, CMD_PRI_LOW, token, &attr);
4370 "Cannot get dpsec device attributed: Error = %x",
4374 snprintf(cryptodev->data->name, sizeof(cryptodev->data->name),
4377 internals->max_nb_queue_pairs = attr.num_tx_queues;
4378 cryptodev->data->nb_queue_pairs = internals->max_nb_queue_pairs;
4379 internals->hw = dpseci;
4380 internals->token = token;
4381 internals->en_loose_ordered = true;
4383 snprintf(str, sizeof(str), "sec_fle_pool_p%d_%d",
4384 getpid(), cryptodev->data->dev_id);
4385 internals->fle_pool = rte_mempool_create((const char *)str,
4388 FLE_POOL_CACHE_SIZE, 0,
4389 NULL, NULL, NULL, NULL,
4391 if (!internals->fle_pool) {
4392 DPAA2_SEC_ERR("Mempool (%s) creation failed", str);
4396 dpaa2_sec_get_devargs(cryptodev, DRIVER_DUMP_MODE);
4397 dpaa2_sec_get_devargs(cryptodev, DRIVER_STRICT_ORDER);
4398 DPAA2_SEC_INFO("driver %s: created", cryptodev->data->name);
4402 DPAA2_SEC_ERR("driver %s: create failed", cryptodev->data->name);
4404 /* dpaa2_sec_uninit(crypto_dev_name); */
4409 cryptodev_dpaa2_sec_probe(struct rte_dpaa2_driver *dpaa2_drv __rte_unused,
4410 struct rte_dpaa2_device *dpaa2_dev)
4412 struct rte_cryptodev *cryptodev;
4413 char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
4417 snprintf(cryptodev_name, sizeof(cryptodev_name), "dpsec-%d",
4418 dpaa2_dev->object_id);
4420 cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
4421 if (cryptodev == NULL)
4424 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
4425 cryptodev->data->dev_private = rte_zmalloc_socket(
4426 "cryptodev private structure",
4427 sizeof(struct dpaa2_sec_dev_private),
4428 RTE_CACHE_LINE_SIZE,
4431 if (cryptodev->data->dev_private == NULL)
4432 rte_panic("Cannot allocate memzone for private "
4436 dpaa2_dev->cryptodev = cryptodev;
4437 cryptodev->device = &dpaa2_dev->device;
4439 /* init user callbacks */
4440 TAILQ_INIT(&(cryptodev->link_intr_cbs));
4442 if (dpaa2_svr_family == SVR_LX2160A)
4443 rta_set_sec_era(RTA_SEC_ERA_10);
4445 rta_set_sec_era(RTA_SEC_ERA_8);
4447 DPAA2_SEC_INFO("2-SEC ERA is %d", rta_get_sec_era());
4449 /* Invoke PMD device initialization function */
4450 retval = dpaa2_sec_dev_init(cryptodev);
4452 rte_cryptodev_pmd_probing_finish(cryptodev);
4456 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
4457 rte_free(cryptodev->data->dev_private);
4459 cryptodev->attached = RTE_CRYPTODEV_DETACHED;
4465 cryptodev_dpaa2_sec_remove(struct rte_dpaa2_device *dpaa2_dev)
4467 struct rte_cryptodev *cryptodev;
4470 cryptodev = dpaa2_dev->cryptodev;
4471 if (cryptodev == NULL)
4474 ret = dpaa2_sec_uninit(cryptodev);
4478 return rte_cryptodev_pmd_destroy(cryptodev);
4481 static struct rte_dpaa2_driver rte_dpaa2_sec_driver = {
4482 .drv_flags = RTE_DPAA2_DRV_IOVA_AS_VA,
4483 .drv_type = DPAA2_CRYPTO,
4485 .name = "DPAA2 SEC PMD"
4487 .probe = cryptodev_dpaa2_sec_probe,
4488 .remove = cryptodev_dpaa2_sec_remove,
4491 static struct cryptodev_driver dpaa2_sec_crypto_drv;
4493 RTE_PMD_REGISTER_DPAA2(CRYPTODEV_NAME_DPAA2_SEC_PMD, rte_dpaa2_sec_driver);
4494 RTE_PMD_REGISTER_CRYPTO_DRIVER(dpaa2_sec_crypto_drv,
4495 rte_dpaa2_sec_driver.driver, cryptodev_driver_id);
4496 RTE_PMD_REGISTER_PARAM_STRING(CRYPTODEV_NAME_DPAA2_SEC_PMD,
4497 DRIVER_STRICT_ORDER "=<int>"
4498 DRIVER_DUMP_MODE "=<int>");
4499 RTE_LOG_REGISTER(dpaa2_logtype_sec, pmd.crypto.dpaa2, NOTICE);