1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
12 #include <rte_cryptodev.h>
13 #include <rte_security_driver.h>
14 #include <rte_malloc.h>
15 #include <rte_memcpy.h>
16 #include <rte_string_fns.h>
17 #include <rte_cycles.h>
18 #include <rte_kvargs.h>
20 #include <rte_cryptodev_pmd.h>
21 #include <rte_common.h>
22 #include <rte_fslmc.h>
23 #include <fslmc_vfio.h>
24 #include <dpaa2_hw_pvt.h>
25 #include <dpaa2_hw_dpio.h>
26 #include <dpaa2_hw_mempool.h>
27 #include <fsl_dpopr.h>
28 #include <fsl_dpseci.h>
29 #include <fsl_mc_sys.h>
31 #include "dpaa2_sec_priv.h"
32 #include "dpaa2_sec_logs.h"
35 typedef uint64_t dma_addr_t;
37 /* RTA header files */
38 #include <hw/desc/ipsec.h>
39 #include <hw/desc/algo.h>
41 /* Minimum job descriptor consists of a oneword job descriptor HEADER and
42 * a pointer to the shared descriptor
44 #define MIN_JOB_DESC_SIZE (CAAM_CMD_SZ + CAAM_PTR_SZ)
45 #define FSL_VENDOR_ID 0x1957
46 #define FSL_DEVICE_ID 0x410
47 #define FSL_SUBSYSTEM_SEC 1
48 #define FSL_MC_DPSECI_DEVID 3
51 /* FLE_POOL_NUM_BUFS is set as per the ipsec-secgw application */
52 #define FLE_POOL_NUM_BUFS 32000
53 #define FLE_POOL_BUF_SIZE 256
54 #define FLE_POOL_CACHE_SIZE 512
55 #define FLE_SG_MEM_SIZE 2048
56 #define SEC_FLC_DHR_OUTBOUND -114
57 #define SEC_FLC_DHR_INBOUND 0
59 enum rta_sec_era rta_sec_era = RTA_SEC_ERA_8;
61 static uint8_t cryptodev_driver_id;
63 int dpaa2_logtype_sec;
66 build_proto_compound_fd(dpaa2_sec_session *sess,
67 struct rte_crypto_op *op,
68 struct qbman_fd *fd, uint16_t bpid)
70 struct rte_crypto_sym_op *sym_op = op->sym;
71 struct ctxt_priv *priv = sess->ctxt;
72 struct qbman_fle *fle, *ip_fle, *op_fle;
73 struct sec_flow_context *flc;
74 struct rte_mbuf *src_mbuf = sym_op->m_src;
75 struct rte_mbuf *dst_mbuf = sym_op->m_dst;
78 /* Save the shared descriptor */
79 flc = &priv->flc_desc[0].flc;
81 /* we are using the first FLE entry to store Mbuf */
82 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
84 DPAA2_SEC_ERR("Memory alloc failed");
87 memset(fle, 0, FLE_POOL_BUF_SIZE);
88 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
89 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
94 if (likely(bpid < MAX_BPID)) {
95 DPAA2_SET_FD_BPID(fd, bpid);
96 DPAA2_SET_FLE_BPID(op_fle, bpid);
97 DPAA2_SET_FLE_BPID(ip_fle, bpid);
100 DPAA2_SET_FLE_IVP(op_fle);
101 DPAA2_SET_FLE_IVP(ip_fle);
104 /* Configure FD as a FRAME LIST */
105 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
106 DPAA2_SET_FD_COMPOUND_FMT(fd);
107 DPAA2_SET_FD_FLC(fd, (ptrdiff_t)flc);
109 /* Configure Output FLE with dst mbuf data */
110 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_MBUF_VADDR_TO_IOVA(dst_mbuf));
111 DPAA2_SET_FLE_OFFSET(op_fle, dst_mbuf->data_off);
112 DPAA2_SET_FLE_LEN(op_fle, dst_mbuf->buf_len);
114 /* Configure Input FLE with src mbuf data */
115 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_MBUF_VADDR_TO_IOVA(src_mbuf));
116 DPAA2_SET_FLE_OFFSET(ip_fle, src_mbuf->data_off);
117 DPAA2_SET_FLE_LEN(ip_fle, src_mbuf->pkt_len);
119 DPAA2_SET_FD_LEN(fd, ip_fle->length);
120 DPAA2_SET_FLE_FIN(ip_fle);
127 build_proto_fd(dpaa2_sec_session *sess,
128 struct rte_crypto_op *op,
129 struct qbman_fd *fd, uint16_t bpid)
131 struct rte_crypto_sym_op *sym_op = op->sym;
133 return build_proto_compound_fd(sess, op, fd, bpid);
135 struct ctxt_priv *priv = sess->ctxt;
136 struct sec_flow_context *flc;
137 struct rte_mbuf *mbuf = sym_op->m_src;
139 if (likely(bpid < MAX_BPID))
140 DPAA2_SET_FD_BPID(fd, bpid);
142 DPAA2_SET_FD_IVP(fd);
144 /* Save the shared descriptor */
145 flc = &priv->flc_desc[0].flc;
147 DPAA2_SET_FD_ADDR(fd, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
148 DPAA2_SET_FD_OFFSET(fd, sym_op->m_src->data_off);
149 DPAA2_SET_FD_LEN(fd, sym_op->m_src->pkt_len);
150 DPAA2_SET_FD_FLC(fd, (ptrdiff_t)flc);
152 /* save physical address of mbuf */
153 op->sym->aead.digest.phys_addr = mbuf->buf_iova;
154 mbuf->buf_iova = (size_t)op;
160 build_authenc_gcm_sg_fd(dpaa2_sec_session *sess,
161 struct rte_crypto_op *op,
162 struct qbman_fd *fd, __rte_unused uint16_t bpid)
164 struct rte_crypto_sym_op *sym_op = op->sym;
165 struct ctxt_priv *priv = sess->ctxt;
166 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
167 struct sec_flow_context *flc;
168 uint32_t auth_only_len = sess->ext_params.aead_ctxt.auth_only_len;
169 int icv_len = sess->digest_length;
171 struct rte_mbuf *mbuf;
172 uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
175 PMD_INIT_FUNC_TRACE();
178 mbuf = sym_op->m_dst;
180 mbuf = sym_op->m_src;
182 /* first FLE entry used to store mbuf and session ctxt */
183 fle = (struct qbman_fle *)rte_malloc(NULL, FLE_SG_MEM_SIZE,
184 RTE_CACHE_LINE_SIZE);
185 if (unlikely(!fle)) {
186 DPAA2_SEC_ERR("GCM SG: Memory alloc failed for SGE");
189 memset(fle, 0, FLE_SG_MEM_SIZE);
190 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
191 DPAA2_FLE_SAVE_CTXT(fle, (size_t)priv);
197 /* Save the shared descriptor */
198 flc = &priv->flc_desc[0].flc;
200 /* Configure FD as a FRAME LIST */
201 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
202 DPAA2_SET_FD_COMPOUND_FMT(fd);
203 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
205 DPAA2_SEC_DP_DEBUG("GCM SG: auth_off: 0x%x/length %d, digest-len=%d\n"
206 "iv-len=%d data_off: 0x%x\n",
207 sym_op->aead.data.offset,
208 sym_op->aead.data.length,
211 sym_op->m_src->data_off);
213 /* Configure Output FLE with Scatter/Gather Entry */
214 DPAA2_SET_FLE_SG_EXT(op_fle);
215 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
218 DPAA2_SET_FLE_INTERNAL_JD(op_fle, auth_only_len);
220 op_fle->length = (sess->dir == DIR_ENC) ?
221 (sym_op->aead.data.length + icv_len + auth_only_len) :
222 sym_op->aead.data.length + auth_only_len;
224 /* Configure Output SGE for Encap/Decap */
225 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
226 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off + sym_op->aead.data.offset -
228 sge->length = mbuf->data_len - sym_op->aead.data.offset + auth_only_len;
234 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
235 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
236 sge->length = mbuf->data_len;
239 sge->length -= icv_len;
241 if (sess->dir == DIR_ENC) {
243 DPAA2_SET_FLE_ADDR(sge,
244 DPAA2_VADDR_TO_IOVA(sym_op->aead.digest.data));
245 sge->length = icv_len;
247 DPAA2_SET_FLE_FIN(sge);
250 mbuf = sym_op->m_src;
252 /* Configure Input FLE with Scatter/Gather Entry */
253 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
254 DPAA2_SET_FLE_SG_EXT(ip_fle);
255 DPAA2_SET_FLE_FIN(ip_fle);
256 ip_fle->length = (sess->dir == DIR_ENC) ?
257 (sym_op->aead.data.length + sess->iv.length + auth_only_len) :
258 (sym_op->aead.data.length + sess->iv.length + auth_only_len +
261 /* Configure Input SGE for Encap/Decap */
262 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(IV_ptr));
263 sge->length = sess->iv.length;
267 DPAA2_SET_FLE_ADDR(sge,
268 DPAA2_VADDR_TO_IOVA(sym_op->aead.aad.data));
269 sge->length = auth_only_len;
273 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
274 DPAA2_SET_FLE_OFFSET(sge, sym_op->aead.data.offset +
276 sge->length = mbuf->data_len - sym_op->aead.data.offset;
282 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
283 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
284 sge->length = mbuf->data_len;
288 if (sess->dir == DIR_DEC) {
290 old_icv = (uint8_t *)(sge + 1);
291 memcpy(old_icv, sym_op->aead.digest.data, icv_len);
292 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
293 sge->length = icv_len;
296 DPAA2_SET_FLE_FIN(sge);
298 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, auth_only_len);
299 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
301 DPAA2_SET_FD_LEN(fd, ip_fle->length);
307 build_authenc_gcm_fd(dpaa2_sec_session *sess,
308 struct rte_crypto_op *op,
309 struct qbman_fd *fd, uint16_t bpid)
311 struct rte_crypto_sym_op *sym_op = op->sym;
312 struct ctxt_priv *priv = sess->ctxt;
313 struct qbman_fle *fle, *sge;
314 struct sec_flow_context *flc;
315 uint32_t auth_only_len = sess->ext_params.aead_ctxt.auth_only_len;
316 int icv_len = sess->digest_length, retval;
318 struct rte_mbuf *dst;
319 uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
322 PMD_INIT_FUNC_TRACE();
329 /* TODO we are using the first FLE entry to store Mbuf and session ctxt.
330 * Currently we donot know which FLE has the mbuf stored.
331 * So while retreiving we can go back 1 FLE from the FD -ADDR
332 * to get the MBUF Addr from the previous FLE.
333 * We can have a better approach to use the inline Mbuf
335 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
337 DPAA2_SEC_ERR("GCM: Memory alloc failed for SGE");
340 memset(fle, 0, FLE_POOL_BUF_SIZE);
341 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
342 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
345 if (likely(bpid < MAX_BPID)) {
346 DPAA2_SET_FD_BPID(fd, bpid);
347 DPAA2_SET_FLE_BPID(fle, bpid);
348 DPAA2_SET_FLE_BPID(fle + 1, bpid);
349 DPAA2_SET_FLE_BPID(sge, bpid);
350 DPAA2_SET_FLE_BPID(sge + 1, bpid);
351 DPAA2_SET_FLE_BPID(sge + 2, bpid);
352 DPAA2_SET_FLE_BPID(sge + 3, bpid);
354 DPAA2_SET_FD_IVP(fd);
355 DPAA2_SET_FLE_IVP(fle);
356 DPAA2_SET_FLE_IVP((fle + 1));
357 DPAA2_SET_FLE_IVP(sge);
358 DPAA2_SET_FLE_IVP((sge + 1));
359 DPAA2_SET_FLE_IVP((sge + 2));
360 DPAA2_SET_FLE_IVP((sge + 3));
363 /* Save the shared descriptor */
364 flc = &priv->flc_desc[0].flc;
365 /* Configure FD as a FRAME LIST */
366 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
367 DPAA2_SET_FD_COMPOUND_FMT(fd);
368 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
370 DPAA2_SEC_DP_DEBUG("GCM: auth_off: 0x%x/length %d, digest-len=%d\n"
371 "iv-len=%d data_off: 0x%x\n",
372 sym_op->aead.data.offset,
373 sym_op->aead.data.length,
376 sym_op->m_src->data_off);
378 /* Configure Output FLE with Scatter/Gather Entry */
379 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
381 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
382 fle->length = (sess->dir == DIR_ENC) ?
383 (sym_op->aead.data.length + icv_len + auth_only_len) :
384 sym_op->aead.data.length + auth_only_len;
386 DPAA2_SET_FLE_SG_EXT(fle);
388 /* Configure Output SGE for Encap/Decap */
389 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(dst));
390 DPAA2_SET_FLE_OFFSET(sge, sym_op->aead.data.offset +
391 dst->data_off - auth_only_len);
392 sge->length = sym_op->aead.data.length + auth_only_len;
394 if (sess->dir == DIR_ENC) {
396 DPAA2_SET_FLE_ADDR(sge,
397 DPAA2_VADDR_TO_IOVA(sym_op->aead.digest.data));
398 sge->length = sess->digest_length;
399 DPAA2_SET_FD_LEN(fd, (sym_op->aead.data.length +
400 sess->iv.length + auth_only_len));
402 DPAA2_SET_FLE_FIN(sge);
407 /* Configure Input FLE with Scatter/Gather Entry */
408 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
409 DPAA2_SET_FLE_SG_EXT(fle);
410 DPAA2_SET_FLE_FIN(fle);
411 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 +
414 sess->digest_length);
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;
421 DPAA2_SET_FLE_ADDR(sge,
422 DPAA2_VADDR_TO_IOVA(sym_op->aead.aad.data));
423 sge->length = auth_only_len;
424 DPAA2_SET_FLE_BPID(sge, bpid);
428 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
429 DPAA2_SET_FLE_OFFSET(sge, sym_op->aead.data.offset +
430 sym_op->m_src->data_off);
431 sge->length = sym_op->aead.data.length;
432 if (sess->dir == DIR_DEC) {
434 old_icv = (uint8_t *)(sge + 1);
435 memcpy(old_icv, sym_op->aead.digest.data,
436 sess->digest_length);
437 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
438 sge->length = sess->digest_length;
439 DPAA2_SET_FD_LEN(fd, (sym_op->aead.data.length +
440 sess->digest_length +
444 DPAA2_SET_FLE_FIN(sge);
447 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
448 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
455 build_authenc_sg_fd(dpaa2_sec_session *sess,
456 struct rte_crypto_op *op,
457 struct qbman_fd *fd, __rte_unused uint16_t bpid)
459 struct rte_crypto_sym_op *sym_op = op->sym;
460 struct ctxt_priv *priv = sess->ctxt;
461 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
462 struct sec_flow_context *flc;
463 uint32_t auth_only_len = sym_op->auth.data.length -
464 sym_op->cipher.data.length;
465 int icv_len = sess->digest_length;
467 struct rte_mbuf *mbuf;
468 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
471 PMD_INIT_FUNC_TRACE();
474 mbuf = sym_op->m_dst;
476 mbuf = sym_op->m_src;
478 /* first FLE entry used to store mbuf and session ctxt */
479 fle = (struct qbman_fle *)rte_malloc(NULL, FLE_SG_MEM_SIZE,
480 RTE_CACHE_LINE_SIZE);
481 if (unlikely(!fle)) {
482 DPAA2_SEC_ERR("AUTHENC SG: Memory alloc failed for SGE");
485 memset(fle, 0, FLE_SG_MEM_SIZE);
486 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
487 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
493 /* Save the shared descriptor */
494 flc = &priv->flc_desc[0].flc;
496 /* Configure FD as a FRAME LIST */
497 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
498 DPAA2_SET_FD_COMPOUND_FMT(fd);
499 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
502 "AUTHENC SG: auth_off: 0x%x/length %d, digest-len=%d\n"
503 "cipher_off: 0x%x/length %d, iv-len=%d data_off: 0x%x\n",
504 sym_op->auth.data.offset,
505 sym_op->auth.data.length,
507 sym_op->cipher.data.offset,
508 sym_op->cipher.data.length,
510 sym_op->m_src->data_off);
512 /* Configure Output FLE with Scatter/Gather Entry */
513 DPAA2_SET_FLE_SG_EXT(op_fle);
514 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
517 DPAA2_SET_FLE_INTERNAL_JD(op_fle, auth_only_len);
519 op_fle->length = (sess->dir == DIR_ENC) ?
520 (sym_op->cipher.data.length + icv_len) :
521 sym_op->cipher.data.length;
523 /* Configure Output SGE for Encap/Decap */
524 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
525 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off + sym_op->auth.data.offset);
526 sge->length = mbuf->data_len - sym_op->auth.data.offset;
532 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
533 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
534 sge->length = mbuf->data_len;
537 sge->length -= icv_len;
539 if (sess->dir == DIR_ENC) {
541 DPAA2_SET_FLE_ADDR(sge,
542 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
543 sge->length = icv_len;
545 DPAA2_SET_FLE_FIN(sge);
548 mbuf = sym_op->m_src;
550 /* Configure Input FLE with Scatter/Gather Entry */
551 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
552 DPAA2_SET_FLE_SG_EXT(ip_fle);
553 DPAA2_SET_FLE_FIN(ip_fle);
554 ip_fle->length = (sess->dir == DIR_ENC) ?
555 (sym_op->auth.data.length + sess->iv.length) :
556 (sym_op->auth.data.length + sess->iv.length +
559 /* Configure Input SGE for Encap/Decap */
560 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
561 sge->length = sess->iv.length;
564 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
565 DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset +
567 sge->length = mbuf->data_len - sym_op->auth.data.offset;
573 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
574 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
575 sge->length = mbuf->data_len;
578 sge->length -= icv_len;
580 if (sess->dir == DIR_DEC) {
582 old_icv = (uint8_t *)(sge + 1);
583 memcpy(old_icv, sym_op->auth.digest.data,
585 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
586 sge->length = icv_len;
589 DPAA2_SET_FLE_FIN(sge);
591 DPAA2_SET_FLE_INTERNAL_JD(ip_fle, auth_only_len);
592 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
594 DPAA2_SET_FD_LEN(fd, ip_fle->length);
600 build_authenc_fd(dpaa2_sec_session *sess,
601 struct rte_crypto_op *op,
602 struct qbman_fd *fd, uint16_t bpid)
604 struct rte_crypto_sym_op *sym_op = op->sym;
605 struct ctxt_priv *priv = sess->ctxt;
606 struct qbman_fle *fle, *sge;
607 struct sec_flow_context *flc;
608 uint32_t auth_only_len = sym_op->auth.data.length -
609 sym_op->cipher.data.length;
610 int icv_len = sess->digest_length, retval;
612 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
614 struct rte_mbuf *dst;
616 PMD_INIT_FUNC_TRACE();
623 /* we are using the first FLE entry to store Mbuf.
624 * Currently we donot know which FLE has the mbuf stored.
625 * So while retreiving we can go back 1 FLE from the FD -ADDR
626 * to get the MBUF Addr from the previous FLE.
627 * We can have a better approach to use the inline Mbuf
629 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
631 DPAA2_SEC_ERR("Memory alloc failed for SGE");
634 memset(fle, 0, FLE_POOL_BUF_SIZE);
635 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
636 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
639 if (likely(bpid < MAX_BPID)) {
640 DPAA2_SET_FD_BPID(fd, bpid);
641 DPAA2_SET_FLE_BPID(fle, bpid);
642 DPAA2_SET_FLE_BPID(fle + 1, bpid);
643 DPAA2_SET_FLE_BPID(sge, bpid);
644 DPAA2_SET_FLE_BPID(sge + 1, bpid);
645 DPAA2_SET_FLE_BPID(sge + 2, bpid);
646 DPAA2_SET_FLE_BPID(sge + 3, bpid);
648 DPAA2_SET_FD_IVP(fd);
649 DPAA2_SET_FLE_IVP(fle);
650 DPAA2_SET_FLE_IVP((fle + 1));
651 DPAA2_SET_FLE_IVP(sge);
652 DPAA2_SET_FLE_IVP((sge + 1));
653 DPAA2_SET_FLE_IVP((sge + 2));
654 DPAA2_SET_FLE_IVP((sge + 3));
657 /* Save the shared descriptor */
658 flc = &priv->flc_desc[0].flc;
659 /* Configure FD as a FRAME LIST */
660 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
661 DPAA2_SET_FD_COMPOUND_FMT(fd);
662 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
665 "AUTHENC: auth_off: 0x%x/length %d, digest-len=%d\n"
666 "cipher_off: 0x%x/length %d, iv-len=%d data_off: 0x%x\n",
667 sym_op->auth.data.offset,
668 sym_op->auth.data.length,
670 sym_op->cipher.data.offset,
671 sym_op->cipher.data.length,
673 sym_op->m_src->data_off);
675 /* Configure Output FLE with Scatter/Gather Entry */
676 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
678 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
679 fle->length = (sess->dir == DIR_ENC) ?
680 (sym_op->cipher.data.length + icv_len) :
681 sym_op->cipher.data.length;
683 DPAA2_SET_FLE_SG_EXT(fle);
685 /* Configure Output SGE for Encap/Decap */
686 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(dst));
687 DPAA2_SET_FLE_OFFSET(sge, sym_op->cipher.data.offset +
689 sge->length = sym_op->cipher.data.length;
691 if (sess->dir == DIR_ENC) {
693 DPAA2_SET_FLE_ADDR(sge,
694 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
695 sge->length = sess->digest_length;
696 DPAA2_SET_FD_LEN(fd, (sym_op->auth.data.length +
699 DPAA2_SET_FLE_FIN(sge);
704 /* Configure Input FLE with Scatter/Gather Entry */
705 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
706 DPAA2_SET_FLE_SG_EXT(fle);
707 DPAA2_SET_FLE_FIN(fle);
708 fle->length = (sess->dir == DIR_ENC) ?
709 (sym_op->auth.data.length + sess->iv.length) :
710 (sym_op->auth.data.length + sess->iv.length +
711 sess->digest_length);
713 /* Configure Input SGE for Encap/Decap */
714 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
715 sge->length = sess->iv.length;
718 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
719 DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset +
720 sym_op->m_src->data_off);
721 sge->length = sym_op->auth.data.length;
722 if (sess->dir == DIR_DEC) {
724 old_icv = (uint8_t *)(sge + 1);
725 memcpy(old_icv, sym_op->auth.digest.data,
726 sess->digest_length);
727 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
728 sge->length = sess->digest_length;
729 DPAA2_SET_FD_LEN(fd, (sym_op->auth.data.length +
730 sess->digest_length +
733 DPAA2_SET_FLE_FIN(sge);
735 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
736 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
741 static inline int build_auth_sg_fd(
742 dpaa2_sec_session *sess,
743 struct rte_crypto_op *op,
745 __rte_unused uint16_t bpid)
747 struct rte_crypto_sym_op *sym_op = op->sym;
748 struct qbman_fle *fle, *sge, *ip_fle, *op_fle;
749 struct sec_flow_context *flc;
750 struct ctxt_priv *priv = sess->ctxt;
752 struct rte_mbuf *mbuf;
754 PMD_INIT_FUNC_TRACE();
756 mbuf = sym_op->m_src;
757 fle = (struct qbman_fle *)rte_malloc(NULL, FLE_SG_MEM_SIZE,
758 RTE_CACHE_LINE_SIZE);
759 if (unlikely(!fle)) {
760 DPAA2_SEC_ERR("AUTH SG: Memory alloc failed for SGE");
763 memset(fle, 0, FLE_SG_MEM_SIZE);
764 /* first FLE entry used to store mbuf and session ctxt */
765 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
766 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
771 flc = &priv->flc_desc[DESC_INITFINAL].flc;
773 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
774 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
775 DPAA2_SET_FD_COMPOUND_FMT(fd);
778 DPAA2_SET_FLE_ADDR(op_fle,
779 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
780 op_fle->length = sess->digest_length;
783 DPAA2_SET_FLE_SG_EXT(ip_fle);
784 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
786 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
787 DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset + mbuf->data_off);
788 sge->length = mbuf->data_len - sym_op->auth.data.offset;
794 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
795 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
796 sge->length = mbuf->data_len;
799 if (sess->dir == DIR_ENC) {
800 /* Digest calculation case */
801 sge->length -= sess->digest_length;
802 ip_fle->length = sym_op->auth.data.length;
804 /* Digest verification case */
806 old_digest = (uint8_t *)(sge + 1);
807 rte_memcpy(old_digest, sym_op->auth.digest.data,
808 sess->digest_length);
809 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_digest));
810 sge->length = sess->digest_length;
811 ip_fle->length = sym_op->auth.data.length +
814 DPAA2_SET_FLE_FIN(sge);
815 DPAA2_SET_FLE_FIN(ip_fle);
816 DPAA2_SET_FD_LEN(fd, ip_fle->length);
822 build_auth_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
823 struct qbman_fd *fd, uint16_t bpid)
825 struct rte_crypto_sym_op *sym_op = op->sym;
826 struct qbman_fle *fle, *sge;
827 struct sec_flow_context *flc;
828 struct ctxt_priv *priv = sess->ctxt;
832 PMD_INIT_FUNC_TRACE();
834 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
836 DPAA2_SEC_ERR("AUTH Memory alloc failed for SGE");
839 memset(fle, 0, FLE_POOL_BUF_SIZE);
840 /* TODO we are using the first FLE entry to store Mbuf.
841 * Currently we donot know which FLE has the mbuf stored.
842 * So while retreiving we can go back 1 FLE from the FD -ADDR
843 * to get the MBUF Addr from the previous FLE.
844 * We can have a better approach to use the inline Mbuf
846 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
847 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
850 if (likely(bpid < MAX_BPID)) {
851 DPAA2_SET_FD_BPID(fd, bpid);
852 DPAA2_SET_FLE_BPID(fle, bpid);
853 DPAA2_SET_FLE_BPID(fle + 1, bpid);
855 DPAA2_SET_FD_IVP(fd);
856 DPAA2_SET_FLE_IVP(fle);
857 DPAA2_SET_FLE_IVP((fle + 1));
859 flc = &priv->flc_desc[DESC_INITFINAL].flc;
860 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
862 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
863 fle->length = sess->digest_length;
865 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
866 DPAA2_SET_FD_COMPOUND_FMT(fd);
869 if (sess->dir == DIR_ENC) {
870 DPAA2_SET_FLE_ADDR(fle,
871 DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
872 DPAA2_SET_FLE_OFFSET(fle, sym_op->auth.data.offset +
873 sym_op->m_src->data_off);
874 DPAA2_SET_FD_LEN(fd, sym_op->auth.data.length);
875 fle->length = sym_op->auth.data.length;
878 DPAA2_SET_FLE_SG_EXT(fle);
879 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
881 if (likely(bpid < MAX_BPID)) {
882 DPAA2_SET_FLE_BPID(sge, bpid);
883 DPAA2_SET_FLE_BPID(sge + 1, bpid);
885 DPAA2_SET_FLE_IVP(sge);
886 DPAA2_SET_FLE_IVP((sge + 1));
888 DPAA2_SET_FLE_ADDR(sge,
889 DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
890 DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset +
891 sym_op->m_src->data_off);
893 DPAA2_SET_FD_LEN(fd, sym_op->auth.data.length +
894 sess->digest_length);
895 sge->length = sym_op->auth.data.length;
897 old_digest = (uint8_t *)(sge + 1);
898 rte_memcpy(old_digest, sym_op->auth.digest.data,
899 sess->digest_length);
900 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_digest));
901 sge->length = sess->digest_length;
902 fle->length = sym_op->auth.data.length +
904 DPAA2_SET_FLE_FIN(sge);
906 DPAA2_SET_FLE_FIN(fle);
912 build_cipher_sg_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
913 struct qbman_fd *fd, __rte_unused uint16_t bpid)
915 struct rte_crypto_sym_op *sym_op = op->sym;
916 struct qbman_fle *ip_fle, *op_fle, *sge, *fle;
917 struct sec_flow_context *flc;
918 struct ctxt_priv *priv = sess->ctxt;
919 struct rte_mbuf *mbuf;
920 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
923 PMD_INIT_FUNC_TRACE();
926 mbuf = sym_op->m_dst;
928 mbuf = sym_op->m_src;
930 fle = (struct qbman_fle *)rte_malloc(NULL, FLE_SG_MEM_SIZE,
931 RTE_CACHE_LINE_SIZE);
933 DPAA2_SEC_ERR("CIPHER SG: Memory alloc failed for SGE");
936 memset(fle, 0, FLE_SG_MEM_SIZE);
937 /* first FLE entry used to store mbuf and session ctxt */
938 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
939 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
945 flc = &priv->flc_desc[0].flc;
948 "CIPHER SG: cipher_off: 0x%x/length %d, ivlen=%d"
950 sym_op->cipher.data.offset,
951 sym_op->cipher.data.length,
953 sym_op->m_src->data_off);
956 DPAA2_SET_FLE_ADDR(op_fle, DPAA2_VADDR_TO_IOVA(sge));
957 op_fle->length = sym_op->cipher.data.length;
958 DPAA2_SET_FLE_SG_EXT(op_fle);
961 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
962 DPAA2_SET_FLE_OFFSET(sge, sym_op->cipher.data.offset + mbuf->data_off);
963 sge->length = mbuf->data_len - sym_op->cipher.data.offset;
969 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
970 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
971 sge->length = mbuf->data_len;
974 DPAA2_SET_FLE_FIN(sge);
977 "CIPHER SG: 1 - flc = %p, fle = %p FLEaddr = %x-%x, len %d\n",
978 flc, fle, fle->addr_hi, fle->addr_lo,
982 mbuf = sym_op->m_src;
984 DPAA2_SET_FLE_ADDR(ip_fle, DPAA2_VADDR_TO_IOVA(sge));
985 ip_fle->length = sess->iv.length + sym_op->cipher.data.length;
986 DPAA2_SET_FLE_SG_EXT(ip_fle);
989 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
990 DPAA2_SET_FLE_OFFSET(sge, 0);
991 sge->length = sess->iv.length;
996 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
997 DPAA2_SET_FLE_OFFSET(sge, sym_op->cipher.data.offset +
999 sge->length = mbuf->data_len - sym_op->cipher.data.offset;
1005 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(mbuf));
1006 DPAA2_SET_FLE_OFFSET(sge, mbuf->data_off);
1007 sge->length = mbuf->data_len;
1010 DPAA2_SET_FLE_FIN(sge);
1011 DPAA2_SET_FLE_FIN(ip_fle);
1014 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(op_fle));
1015 DPAA2_SET_FD_LEN(fd, ip_fle->length);
1016 DPAA2_SET_FD_COMPOUND_FMT(fd);
1017 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
1020 "CIPHER SG: fdaddr =%" PRIx64 " bpid =%d meta =%d"
1021 " off =%d, len =%d\n",
1022 DPAA2_GET_FD_ADDR(fd),
1023 DPAA2_GET_FD_BPID(fd),
1024 rte_dpaa2_bpid_info[bpid].meta_data_size,
1025 DPAA2_GET_FD_OFFSET(fd),
1026 DPAA2_GET_FD_LEN(fd));
1031 build_cipher_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
1032 struct qbman_fd *fd, uint16_t bpid)
1034 struct rte_crypto_sym_op *sym_op = op->sym;
1035 struct qbman_fle *fle, *sge;
1037 struct sec_flow_context *flc;
1038 struct ctxt_priv *priv = sess->ctxt;
1039 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1041 struct rte_mbuf *dst;
1043 PMD_INIT_FUNC_TRACE();
1046 dst = sym_op->m_dst;
1048 dst = sym_op->m_src;
1050 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
1052 DPAA2_SEC_ERR("CIPHER: Memory alloc failed for SGE");
1055 memset(fle, 0, FLE_POOL_BUF_SIZE);
1056 /* TODO we are using the first FLE entry to store Mbuf.
1057 * Currently we donot know which FLE has the mbuf stored.
1058 * So while retreiving we can go back 1 FLE from the FD -ADDR
1059 * to get the MBUF Addr from the previous FLE.
1060 * We can have a better approach to use the inline Mbuf
1062 DPAA2_SET_FLE_ADDR(fle, (size_t)op);
1063 DPAA2_FLE_SAVE_CTXT(fle, (ptrdiff_t)priv);
1067 if (likely(bpid < MAX_BPID)) {
1068 DPAA2_SET_FD_BPID(fd, bpid);
1069 DPAA2_SET_FLE_BPID(fle, bpid);
1070 DPAA2_SET_FLE_BPID(fle + 1, bpid);
1071 DPAA2_SET_FLE_BPID(sge, bpid);
1072 DPAA2_SET_FLE_BPID(sge + 1, bpid);
1074 DPAA2_SET_FD_IVP(fd);
1075 DPAA2_SET_FLE_IVP(fle);
1076 DPAA2_SET_FLE_IVP((fle + 1));
1077 DPAA2_SET_FLE_IVP(sge);
1078 DPAA2_SET_FLE_IVP((sge + 1));
1081 flc = &priv->flc_desc[0].flc;
1082 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
1083 DPAA2_SET_FD_LEN(fd, sym_op->cipher.data.length +
1085 DPAA2_SET_FD_COMPOUND_FMT(fd);
1086 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
1089 "CIPHER: cipher_off: 0x%x/length %d, ivlen=%d,"
1090 " data_off: 0x%x\n",
1091 sym_op->cipher.data.offset,
1092 sym_op->cipher.data.length,
1094 sym_op->m_src->data_off);
1096 DPAA2_SET_FLE_ADDR(fle, DPAA2_MBUF_VADDR_TO_IOVA(dst));
1097 DPAA2_SET_FLE_OFFSET(fle, sym_op->cipher.data.offset +
1100 fle->length = sym_op->cipher.data.length + sess->iv.length;
1103 "CIPHER: 1 - flc = %p, fle = %p FLEaddr = %x-%x, length %d\n",
1104 flc, fle, fle->addr_hi, fle->addr_lo,
1109 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
1110 fle->length = sym_op->cipher.data.length + sess->iv.length;
1112 DPAA2_SET_FLE_SG_EXT(fle);
1114 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
1115 sge->length = sess->iv.length;
1118 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
1119 DPAA2_SET_FLE_OFFSET(sge, sym_op->cipher.data.offset +
1120 sym_op->m_src->data_off);
1122 sge->length = sym_op->cipher.data.length;
1123 DPAA2_SET_FLE_FIN(sge);
1124 DPAA2_SET_FLE_FIN(fle);
1127 "CIPHER: fdaddr =%" PRIx64 " bpid =%d meta =%d"
1128 " off =%d, len =%d\n",
1129 DPAA2_GET_FD_ADDR(fd),
1130 DPAA2_GET_FD_BPID(fd),
1131 rte_dpaa2_bpid_info[bpid].meta_data_size,
1132 DPAA2_GET_FD_OFFSET(fd),
1133 DPAA2_GET_FD_LEN(fd));
1139 build_sec_fd(struct rte_crypto_op *op,
1140 struct qbman_fd *fd, uint16_t bpid)
1143 dpaa2_sec_session *sess;
1145 PMD_INIT_FUNC_TRACE();
1147 if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION)
1148 sess = (dpaa2_sec_session *)get_sym_session_private_data(
1149 op->sym->session, cryptodev_driver_id);
1150 else if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION)
1151 sess = (dpaa2_sec_session *)get_sec_session_private_data(
1152 op->sym->sec_session);
1156 /* Segmented buffer */
1157 if (unlikely(!rte_pktmbuf_is_contiguous(op->sym->m_src))) {
1158 switch (sess->ctxt_type) {
1159 case DPAA2_SEC_CIPHER:
1160 ret = build_cipher_sg_fd(sess, op, fd, bpid);
1162 case DPAA2_SEC_AUTH:
1163 ret = build_auth_sg_fd(sess, op, fd, bpid);
1165 case DPAA2_SEC_AEAD:
1166 ret = build_authenc_gcm_sg_fd(sess, op, fd, bpid);
1168 case DPAA2_SEC_CIPHER_HASH:
1169 ret = build_authenc_sg_fd(sess, op, fd, bpid);
1171 case DPAA2_SEC_HASH_CIPHER:
1173 DPAA2_SEC_ERR("error: Unsupported session");
1176 switch (sess->ctxt_type) {
1177 case DPAA2_SEC_CIPHER:
1178 ret = build_cipher_fd(sess, op, fd, bpid);
1180 case DPAA2_SEC_AUTH:
1181 ret = build_auth_fd(sess, op, fd, bpid);
1183 case DPAA2_SEC_AEAD:
1184 ret = build_authenc_gcm_fd(sess, op, fd, bpid);
1186 case DPAA2_SEC_CIPHER_HASH:
1187 ret = build_authenc_fd(sess, op, fd, bpid);
1189 case DPAA2_SEC_IPSEC:
1190 ret = build_proto_fd(sess, op, fd, bpid);
1192 case DPAA2_SEC_HASH_CIPHER:
1194 DPAA2_SEC_ERR("error: Unsupported session");
1201 dpaa2_sec_enqueue_burst(void *qp, struct rte_crypto_op **ops,
1204 /* Function to transmit the frames to given device and VQ*/
1207 struct qbman_fd fd_arr[MAX_TX_RING_SLOTS];
1208 uint32_t frames_to_send;
1209 struct qbman_eq_desc eqdesc;
1210 struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
1211 struct qbman_swp *swp;
1212 uint16_t num_tx = 0;
1213 /*todo - need to support multiple buffer pools */
1215 struct rte_mempool *mb_pool;
1217 if (unlikely(nb_ops == 0))
1220 if (ops[0]->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
1221 DPAA2_SEC_ERR("sessionless crypto op not supported");
1224 /*Prepare enqueue descriptor*/
1225 qbman_eq_desc_clear(&eqdesc);
1226 qbman_eq_desc_set_no_orp(&eqdesc, DPAA2_EQ_RESP_ERR_FQ);
1227 qbman_eq_desc_set_response(&eqdesc, 0, 0);
1228 qbman_eq_desc_set_fq(&eqdesc, dpaa2_qp->tx_vq.fqid);
1230 if (!DPAA2_PER_LCORE_DPIO) {
1231 ret = dpaa2_affine_qbman_swp();
1233 DPAA2_SEC_ERR("Failure in affining portal");
1237 swp = DPAA2_PER_LCORE_PORTAL;
1240 frames_to_send = (nb_ops >> 3) ? MAX_TX_RING_SLOTS : nb_ops;
1242 for (loop = 0; loop < frames_to_send; loop++) {
1243 /*Clear the unused FD fields before sending*/
1244 memset(&fd_arr[loop], 0, sizeof(struct qbman_fd));
1245 mb_pool = (*ops)->sym->m_src->pool;
1246 bpid = mempool_to_bpid(mb_pool);
1247 ret = build_sec_fd(*ops, &fd_arr[loop], bpid);
1249 DPAA2_SEC_ERR("error: Improper packet contents"
1250 " for crypto operation");
1256 while (loop < frames_to_send) {
1257 loop += qbman_swp_enqueue_multiple(swp, &eqdesc,
1260 frames_to_send - loop);
1263 num_tx += frames_to_send;
1264 nb_ops -= frames_to_send;
1267 dpaa2_qp->tx_vq.tx_pkts += num_tx;
1268 dpaa2_qp->tx_vq.err_pkts += nb_ops;
1272 static inline struct rte_crypto_op *
1273 sec_simple_fd_to_mbuf(const struct qbman_fd *fd, __rte_unused uint8_t id)
1275 struct rte_crypto_op *op;
1276 uint16_t len = DPAA2_GET_FD_LEN(fd);
1278 dpaa2_sec_session *sess_priv;
1280 struct rte_mbuf *mbuf = DPAA2_INLINE_MBUF_FROM_BUF(
1281 DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd)),
1282 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size);
1284 op = (struct rte_crypto_op *)(size_t)mbuf->buf_iova;
1285 mbuf->buf_iova = op->sym->aead.digest.phys_addr;
1286 op->sym->aead.digest.phys_addr = 0L;
1288 sess_priv = (dpaa2_sec_session *)get_sec_session_private_data(
1289 op->sym->sec_session);
1290 if (sess_priv->dir == DIR_ENC)
1291 mbuf->data_off += SEC_FLC_DHR_OUTBOUND;
1293 mbuf->data_off += SEC_FLC_DHR_INBOUND;
1294 diff = len - mbuf->pkt_len;
1295 mbuf->pkt_len += diff;
1296 mbuf->data_len += diff;
1301 static inline struct rte_crypto_op *
1302 sec_fd_to_mbuf(const struct qbman_fd *fd, uint8_t driver_id)
1304 struct qbman_fle *fle;
1305 struct rte_crypto_op *op;
1306 struct ctxt_priv *priv;
1307 struct rte_mbuf *dst, *src;
1309 if (DPAA2_FD_GET_FORMAT(fd) == qbman_fd_single)
1310 return sec_simple_fd_to_mbuf(fd, driver_id);
1312 fle = (struct qbman_fle *)DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd));
1314 DPAA2_SEC_DP_DEBUG("FLE addr = %x - %x, offset = %x\n",
1315 fle->addr_hi, fle->addr_lo, fle->fin_bpid_offset);
1317 /* we are using the first FLE entry to store Mbuf.
1318 * Currently we donot know which FLE has the mbuf stored.
1319 * So while retreiving we can go back 1 FLE from the FD -ADDR
1320 * to get the MBUF Addr from the previous FLE.
1321 * We can have a better approach to use the inline Mbuf
1324 if (unlikely(DPAA2_GET_FD_IVP(fd))) {
1325 /* TODO complete it. */
1326 DPAA2_SEC_ERR("error: non inline buffer");
1329 op = (struct rte_crypto_op *)DPAA2_GET_FLE_ADDR((fle - 1));
1332 src = op->sym->m_src;
1335 if (op->sym->m_dst) {
1336 dst = op->sym->m_dst;
1341 if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
1342 dpaa2_sec_session *sess = (dpaa2_sec_session *)
1343 get_sec_session_private_data(op->sym->sec_session);
1344 if (sess->ctxt_type == DPAA2_SEC_IPSEC) {
1345 uint16_t len = DPAA2_GET_FD_LEN(fd);
1347 dst->data_len = len;
1351 DPAA2_SEC_DP_DEBUG("mbuf %p BMAN buf addr %p,"
1352 " fdaddr =%" PRIx64 " bpid =%d meta =%d off =%d, len =%d\n",
1355 DPAA2_GET_FD_ADDR(fd),
1356 DPAA2_GET_FD_BPID(fd),
1357 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size,
1358 DPAA2_GET_FD_OFFSET(fd),
1359 DPAA2_GET_FD_LEN(fd));
1361 /* free the fle memory */
1362 if (likely(rte_pktmbuf_is_contiguous(src))) {
1363 priv = (struct ctxt_priv *)(size_t)DPAA2_GET_FLE_CTXT(fle - 1);
1364 rte_mempool_put(priv->fle_pool, (void *)(fle-1));
1366 rte_free((void *)(fle-1));
1372 dpaa2_sec_dequeue_burst(void *qp, struct rte_crypto_op **ops,
1375 /* Function is responsible to receive frames for a given device and VQ*/
1376 struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
1377 struct rte_cryptodev *dev =
1378 (struct rte_cryptodev *)(dpaa2_qp->rx_vq.dev);
1379 struct qbman_result *dq_storage;
1380 uint32_t fqid = dpaa2_qp->rx_vq.fqid;
1381 int ret, num_rx = 0;
1382 uint8_t is_last = 0, status;
1383 struct qbman_swp *swp;
1384 const struct qbman_fd *fd;
1385 struct qbman_pull_desc pulldesc;
1387 if (!DPAA2_PER_LCORE_DPIO) {
1388 ret = dpaa2_affine_qbman_swp();
1390 DPAA2_SEC_ERR("Failure in affining portal");
1394 swp = DPAA2_PER_LCORE_PORTAL;
1395 dq_storage = dpaa2_qp->rx_vq.q_storage->dq_storage[0];
1397 qbman_pull_desc_clear(&pulldesc);
1398 qbman_pull_desc_set_numframes(&pulldesc,
1399 (nb_ops > DPAA2_DQRR_RING_SIZE) ?
1400 DPAA2_DQRR_RING_SIZE : nb_ops);
1401 qbman_pull_desc_set_fq(&pulldesc, fqid);
1402 qbman_pull_desc_set_storage(&pulldesc, dq_storage,
1403 (dma_addr_t)DPAA2_VADDR_TO_IOVA(dq_storage),
1406 /*Issue a volatile dequeue command. */
1408 if (qbman_swp_pull(swp, &pulldesc)) {
1410 "SEC VDQ command is not issued : QBMAN busy");
1411 /* Portal was busy, try again */
1417 /* Receive the packets till Last Dequeue entry is found with
1418 * respect to the above issues PULL command.
1421 /* Check if the previous issued command is completed.
1422 * Also seems like the SWP is shared between the Ethernet Driver
1423 * and the SEC driver.
1425 while (!qbman_check_command_complete(dq_storage))
1428 /* Loop until the dq_storage is updated with
1429 * new token by QBMAN
1431 while (!qbman_check_new_result(dq_storage))
1433 /* Check whether Last Pull command is Expired and
1434 * setting Condition for Loop termination
1436 if (qbman_result_DQ_is_pull_complete(dq_storage)) {
1438 /* Check for valid frame. */
1439 status = (uint8_t)qbman_result_DQ_flags(dq_storage);
1441 (status & QBMAN_DQ_STAT_VALIDFRAME) == 0)) {
1442 DPAA2_SEC_DP_DEBUG("No frame is delivered\n");
1447 fd = qbman_result_DQ_fd(dq_storage);
1448 ops[num_rx] = sec_fd_to_mbuf(fd, dev->driver_id);
1450 if (unlikely(fd->simple.frc)) {
1451 /* TODO Parse SEC errors */
1452 DPAA2_SEC_ERR("SEC returned Error - %x",
1454 ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_ERROR;
1456 ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
1461 } /* End of Packet Rx loop */
1463 dpaa2_qp->rx_vq.rx_pkts += num_rx;
1465 DPAA2_SEC_DP_DEBUG("SEC Received %d Packets\n", num_rx);
1466 /*Return the total number of packets received to DPAA2 app*/
1470 /** Release queue pair */
1472 dpaa2_sec_queue_pair_release(struct rte_cryptodev *dev, uint16_t queue_pair_id)
1474 struct dpaa2_sec_qp *qp =
1475 (struct dpaa2_sec_qp *)dev->data->queue_pairs[queue_pair_id];
1477 PMD_INIT_FUNC_TRACE();
1479 if (qp->rx_vq.q_storage) {
1480 dpaa2_free_dq_storage(qp->rx_vq.q_storage);
1481 rte_free(qp->rx_vq.q_storage);
1485 dev->data->queue_pairs[queue_pair_id] = NULL;
1490 /** Setup a queue pair */
1492 dpaa2_sec_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
1493 __rte_unused const struct rte_cryptodev_qp_conf *qp_conf,
1494 __rte_unused int socket_id,
1495 __rte_unused struct rte_mempool *session_pool)
1497 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
1498 struct dpaa2_sec_qp *qp;
1499 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
1500 struct dpseci_rx_queue_cfg cfg;
1503 PMD_INIT_FUNC_TRACE();
1505 /* If qp is already in use free ring memory and qp metadata. */
1506 if (dev->data->queue_pairs[qp_id] != NULL) {
1507 DPAA2_SEC_INFO("QP already setup");
1511 DPAA2_SEC_DEBUG("dev =%p, queue =%d, conf =%p",
1512 dev, qp_id, qp_conf);
1514 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
1516 qp = rte_malloc(NULL, sizeof(struct dpaa2_sec_qp),
1517 RTE_CACHE_LINE_SIZE);
1519 DPAA2_SEC_ERR("malloc failed for rx/tx queues");
1523 qp->rx_vq.dev = dev;
1524 qp->tx_vq.dev = dev;
1525 qp->rx_vq.q_storage = rte_malloc("sec dq storage",
1526 sizeof(struct queue_storage_info_t),
1527 RTE_CACHE_LINE_SIZE);
1528 if (!qp->rx_vq.q_storage) {
1529 DPAA2_SEC_ERR("malloc failed for q_storage");
1532 memset(qp->rx_vq.q_storage, 0, sizeof(struct queue_storage_info_t));
1534 if (dpaa2_alloc_dq_storage(qp->rx_vq.q_storage)) {
1535 DPAA2_SEC_ERR("Unable to allocate dequeue storage");
1539 dev->data->queue_pairs[qp_id] = qp;
1541 cfg.options = cfg.options | DPSECI_QUEUE_OPT_USER_CTX;
1542 cfg.user_ctx = (size_t)(&qp->rx_vq);
1543 retcode = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
1548 /** Return the number of allocated queue pairs */
1550 dpaa2_sec_queue_pair_count(struct rte_cryptodev *dev)
1552 PMD_INIT_FUNC_TRACE();
1554 return dev->data->nb_queue_pairs;
1557 /** Returns the size of the aesni gcm session structure */
1559 dpaa2_sec_sym_session_get_size(struct rte_cryptodev *dev __rte_unused)
1561 PMD_INIT_FUNC_TRACE();
1563 return sizeof(dpaa2_sec_session);
1567 dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
1568 struct rte_crypto_sym_xform *xform,
1569 dpaa2_sec_session *session)
1571 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
1572 struct alginfo cipherdata;
1574 struct ctxt_priv *priv;
1575 struct sec_flow_context *flc;
1577 PMD_INIT_FUNC_TRACE();
1579 /* For SEC CIPHER only one descriptor is required. */
1580 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
1581 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
1582 RTE_CACHE_LINE_SIZE);
1584 DPAA2_SEC_ERR("No Memory for priv CTXT");
1588 priv->fle_pool = dev_priv->fle_pool;
1590 flc = &priv->flc_desc[0].flc;
1592 session->cipher_key.data = rte_zmalloc(NULL, xform->cipher.key.length,
1593 RTE_CACHE_LINE_SIZE);
1594 if (session->cipher_key.data == NULL) {
1595 DPAA2_SEC_ERR("No Memory for cipher key");
1599 session->cipher_key.length = xform->cipher.key.length;
1601 memcpy(session->cipher_key.data, xform->cipher.key.data,
1602 xform->cipher.key.length);
1603 cipherdata.key = (size_t)session->cipher_key.data;
1604 cipherdata.keylen = session->cipher_key.length;
1605 cipherdata.key_enc_flags = 0;
1606 cipherdata.key_type = RTA_DATA_IMM;
1608 /* Set IV parameters */
1609 session->iv.offset = xform->cipher.iv.offset;
1610 session->iv.length = xform->cipher.iv.length;
1612 switch (xform->cipher.algo) {
1613 case RTE_CRYPTO_CIPHER_AES_CBC:
1614 cipherdata.algtype = OP_ALG_ALGSEL_AES;
1615 cipherdata.algmode = OP_ALG_AAI_CBC;
1616 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
1618 case RTE_CRYPTO_CIPHER_3DES_CBC:
1619 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
1620 cipherdata.algmode = OP_ALG_AAI_CBC;
1621 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
1623 case RTE_CRYPTO_CIPHER_AES_CTR:
1624 cipherdata.algtype = OP_ALG_ALGSEL_AES;
1625 cipherdata.algmode = OP_ALG_AAI_CTR;
1626 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
1628 case RTE_CRYPTO_CIPHER_3DES_CTR:
1629 case RTE_CRYPTO_CIPHER_AES_ECB:
1630 case RTE_CRYPTO_CIPHER_3DES_ECB:
1631 case RTE_CRYPTO_CIPHER_AES_XTS:
1632 case RTE_CRYPTO_CIPHER_AES_F8:
1633 case RTE_CRYPTO_CIPHER_ARC4:
1634 case RTE_CRYPTO_CIPHER_KASUMI_F8:
1635 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
1636 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
1637 case RTE_CRYPTO_CIPHER_NULL:
1638 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
1639 xform->cipher.algo);
1642 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
1643 xform->cipher.algo);
1646 session->dir = (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
1649 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
1650 &cipherdata, NULL, session->iv.length,
1653 DPAA2_SEC_ERR("Crypto: Descriptor build failed");
1658 flc->mode_bits = 0x8000;
1660 flc->word1_sdl = (uint8_t)bufsize;
1661 flc->word2_rflc_31_0 = lower_32_bits(
1662 (size_t)&(((struct dpaa2_sec_qp *)
1663 dev->data->queue_pairs[0])->rx_vq));
1664 flc->word3_rflc_63_32 = upper_32_bits(
1665 (size_t)&(((struct dpaa2_sec_qp *)
1666 dev->data->queue_pairs[0])->rx_vq));
1667 session->ctxt = priv;
1669 for (i = 0; i < bufsize; i++)
1670 DPAA2_SEC_DEBUG("DESC[%d]:0x%x", i, priv->flc_desc[0].desc[i]);
1675 rte_free(session->cipher_key.data);
1681 dpaa2_sec_auth_init(struct rte_cryptodev *dev,
1682 struct rte_crypto_sym_xform *xform,
1683 dpaa2_sec_session *session)
1685 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
1686 struct alginfo authdata;
1688 struct ctxt_priv *priv;
1689 struct sec_flow_context *flc;
1691 PMD_INIT_FUNC_TRACE();
1693 /* For SEC AUTH three descriptors are required for various stages */
1694 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
1695 sizeof(struct ctxt_priv) + 3 *
1696 sizeof(struct sec_flc_desc),
1697 RTE_CACHE_LINE_SIZE);
1699 DPAA2_SEC_ERR("No Memory for priv CTXT");
1703 priv->fle_pool = dev_priv->fle_pool;
1704 flc = &priv->flc_desc[DESC_INITFINAL].flc;
1706 session->auth_key.data = rte_zmalloc(NULL, xform->auth.key.length,
1707 RTE_CACHE_LINE_SIZE);
1708 if (session->auth_key.data == NULL) {
1709 DPAA2_SEC_ERR("Unable to allocate memory for auth key");
1713 session->auth_key.length = xform->auth.key.length;
1715 memcpy(session->auth_key.data, xform->auth.key.data,
1716 xform->auth.key.length);
1717 authdata.key = (size_t)session->auth_key.data;
1718 authdata.keylen = session->auth_key.length;
1719 authdata.key_enc_flags = 0;
1720 authdata.key_type = RTA_DATA_IMM;
1722 session->digest_length = xform->auth.digest_length;
1724 switch (xform->auth.algo) {
1725 case RTE_CRYPTO_AUTH_SHA1_HMAC:
1726 authdata.algtype = OP_ALG_ALGSEL_SHA1;
1727 authdata.algmode = OP_ALG_AAI_HMAC;
1728 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
1730 case RTE_CRYPTO_AUTH_MD5_HMAC:
1731 authdata.algtype = OP_ALG_ALGSEL_MD5;
1732 authdata.algmode = OP_ALG_AAI_HMAC;
1733 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
1735 case RTE_CRYPTO_AUTH_SHA256_HMAC:
1736 authdata.algtype = OP_ALG_ALGSEL_SHA256;
1737 authdata.algmode = OP_ALG_AAI_HMAC;
1738 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
1740 case RTE_CRYPTO_AUTH_SHA384_HMAC:
1741 authdata.algtype = OP_ALG_ALGSEL_SHA384;
1742 authdata.algmode = OP_ALG_AAI_HMAC;
1743 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
1745 case RTE_CRYPTO_AUTH_SHA512_HMAC:
1746 authdata.algtype = OP_ALG_ALGSEL_SHA512;
1747 authdata.algmode = OP_ALG_AAI_HMAC;
1748 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
1750 case RTE_CRYPTO_AUTH_SHA224_HMAC:
1751 authdata.algtype = OP_ALG_ALGSEL_SHA224;
1752 authdata.algmode = OP_ALG_AAI_HMAC;
1753 session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
1755 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
1756 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
1757 case RTE_CRYPTO_AUTH_NULL:
1758 case RTE_CRYPTO_AUTH_SHA1:
1759 case RTE_CRYPTO_AUTH_SHA256:
1760 case RTE_CRYPTO_AUTH_SHA512:
1761 case RTE_CRYPTO_AUTH_SHA224:
1762 case RTE_CRYPTO_AUTH_SHA384:
1763 case RTE_CRYPTO_AUTH_MD5:
1764 case RTE_CRYPTO_AUTH_AES_GMAC:
1765 case RTE_CRYPTO_AUTH_KASUMI_F9:
1766 case RTE_CRYPTO_AUTH_AES_CMAC:
1767 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
1768 case RTE_CRYPTO_AUTH_ZUC_EIA3:
1769 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %un",
1773 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
1777 session->dir = (xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE) ?
1780 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
1781 1, 0, &authdata, !session->dir,
1782 session->digest_length);
1784 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
1788 flc->word1_sdl = (uint8_t)bufsize;
1789 flc->word2_rflc_31_0 = lower_32_bits(
1790 (size_t)&(((struct dpaa2_sec_qp *)
1791 dev->data->queue_pairs[0])->rx_vq));
1792 flc->word3_rflc_63_32 = upper_32_bits(
1793 (size_t)&(((struct dpaa2_sec_qp *)
1794 dev->data->queue_pairs[0])->rx_vq));
1795 session->ctxt = priv;
1796 for (i = 0; i < bufsize; i++)
1797 DPAA2_SEC_DEBUG("DESC[%d]:0x%x",
1798 i, priv->flc_desc[DESC_INITFINAL].desc[i]);
1804 rte_free(session->auth_key.data);
1810 dpaa2_sec_aead_init(struct rte_cryptodev *dev,
1811 struct rte_crypto_sym_xform *xform,
1812 dpaa2_sec_session *session)
1814 struct dpaa2_sec_aead_ctxt *ctxt = &session->ext_params.aead_ctxt;
1815 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
1816 struct alginfo aeaddata;
1818 struct ctxt_priv *priv;
1819 struct sec_flow_context *flc;
1820 struct rte_crypto_aead_xform *aead_xform = &xform->aead;
1823 PMD_INIT_FUNC_TRACE();
1825 /* Set IV parameters */
1826 session->iv.offset = aead_xform->iv.offset;
1827 session->iv.length = aead_xform->iv.length;
1828 session->ctxt_type = DPAA2_SEC_AEAD;
1830 /* For SEC AEAD only one descriptor is required */
1831 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
1832 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
1833 RTE_CACHE_LINE_SIZE);
1835 DPAA2_SEC_ERR("No Memory for priv CTXT");
1839 priv->fle_pool = dev_priv->fle_pool;
1840 flc = &priv->flc_desc[0].flc;
1842 session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length,
1843 RTE_CACHE_LINE_SIZE);
1844 if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
1845 DPAA2_SEC_ERR("No Memory for aead key");
1849 memcpy(session->aead_key.data, aead_xform->key.data,
1850 aead_xform->key.length);
1852 session->digest_length = aead_xform->digest_length;
1853 session->aead_key.length = aead_xform->key.length;
1854 ctxt->auth_only_len = aead_xform->aad_length;
1856 aeaddata.key = (size_t)session->aead_key.data;
1857 aeaddata.keylen = session->aead_key.length;
1858 aeaddata.key_enc_flags = 0;
1859 aeaddata.key_type = RTA_DATA_IMM;
1861 switch (aead_xform->algo) {
1862 case RTE_CRYPTO_AEAD_AES_GCM:
1863 aeaddata.algtype = OP_ALG_ALGSEL_AES;
1864 aeaddata.algmode = OP_ALG_AAI_GCM;
1865 session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM;
1867 case RTE_CRYPTO_AEAD_AES_CCM:
1868 DPAA2_SEC_ERR("Crypto: Unsupported AEAD alg %u",
1872 DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
1876 session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
1879 priv->flc_desc[0].desc[0] = aeaddata.keylen;
1880 err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
1882 (unsigned int *)priv->flc_desc[0].desc,
1883 &priv->flc_desc[0].desc[1], 1);
1886 DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
1889 if (priv->flc_desc[0].desc[1] & 1) {
1890 aeaddata.key_type = RTA_DATA_IMM;
1892 aeaddata.key = DPAA2_VADDR_TO_IOVA(aeaddata.key);
1893 aeaddata.key_type = RTA_DATA_PTR;
1895 priv->flc_desc[0].desc[0] = 0;
1896 priv->flc_desc[0].desc[1] = 0;
1898 if (session->dir == DIR_ENC)
1899 bufsize = cnstr_shdsc_gcm_encap(
1900 priv->flc_desc[0].desc, 1, 0,
1901 &aeaddata, session->iv.length,
1902 session->digest_length);
1904 bufsize = cnstr_shdsc_gcm_decap(
1905 priv->flc_desc[0].desc, 1, 0,
1906 &aeaddata, session->iv.length,
1907 session->digest_length);
1909 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
1913 flc->word1_sdl = (uint8_t)bufsize;
1914 flc->word2_rflc_31_0 = lower_32_bits(
1915 (size_t)&(((struct dpaa2_sec_qp *)
1916 dev->data->queue_pairs[0])->rx_vq));
1917 flc->word3_rflc_63_32 = upper_32_bits(
1918 (size_t)&(((struct dpaa2_sec_qp *)
1919 dev->data->queue_pairs[0])->rx_vq));
1920 session->ctxt = priv;
1921 for (i = 0; i < bufsize; i++)
1922 DPAA2_SEC_DEBUG("DESC[%d]:0x%x\n",
1923 i, priv->flc_desc[0].desc[i]);
1928 rte_free(session->aead_key.data);
1935 dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
1936 struct rte_crypto_sym_xform *xform,
1937 dpaa2_sec_session *session)
1939 struct dpaa2_sec_aead_ctxt *ctxt = &session->ext_params.aead_ctxt;
1940 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
1941 struct alginfo authdata, cipherdata;
1943 struct ctxt_priv *priv;
1944 struct sec_flow_context *flc;
1945 struct rte_crypto_cipher_xform *cipher_xform;
1946 struct rte_crypto_auth_xform *auth_xform;
1949 PMD_INIT_FUNC_TRACE();
1951 if (session->ext_params.aead_ctxt.auth_cipher_text) {
1952 cipher_xform = &xform->cipher;
1953 auth_xform = &xform->next->auth;
1954 session->ctxt_type =
1955 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
1956 DPAA2_SEC_CIPHER_HASH : DPAA2_SEC_HASH_CIPHER;
1958 cipher_xform = &xform->next->cipher;
1959 auth_xform = &xform->auth;
1960 session->ctxt_type =
1961 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
1962 DPAA2_SEC_HASH_CIPHER : DPAA2_SEC_CIPHER_HASH;
1965 /* Set IV parameters */
1966 session->iv.offset = cipher_xform->iv.offset;
1967 session->iv.length = cipher_xform->iv.length;
1969 /* For SEC AEAD only one descriptor is required */
1970 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
1971 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
1972 RTE_CACHE_LINE_SIZE);
1974 DPAA2_SEC_ERR("No Memory for priv CTXT");
1978 priv->fle_pool = dev_priv->fle_pool;
1979 flc = &priv->flc_desc[0].flc;
1981 session->cipher_key.data = rte_zmalloc(NULL, cipher_xform->key.length,
1982 RTE_CACHE_LINE_SIZE);
1983 if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) {
1984 DPAA2_SEC_ERR("No Memory for cipher key");
1988 session->cipher_key.length = cipher_xform->key.length;
1989 session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length,
1990 RTE_CACHE_LINE_SIZE);
1991 if (session->auth_key.data == NULL && auth_xform->key.length > 0) {
1992 DPAA2_SEC_ERR("No Memory for auth key");
1993 rte_free(session->cipher_key.data);
1997 session->auth_key.length = auth_xform->key.length;
1998 memcpy(session->cipher_key.data, cipher_xform->key.data,
1999 cipher_xform->key.length);
2000 memcpy(session->auth_key.data, auth_xform->key.data,
2001 auth_xform->key.length);
2003 authdata.key = (size_t)session->auth_key.data;
2004 authdata.keylen = session->auth_key.length;
2005 authdata.key_enc_flags = 0;
2006 authdata.key_type = RTA_DATA_IMM;
2008 session->digest_length = auth_xform->digest_length;
2010 switch (auth_xform->algo) {
2011 case RTE_CRYPTO_AUTH_SHA1_HMAC:
2012 authdata.algtype = OP_ALG_ALGSEL_SHA1;
2013 authdata.algmode = OP_ALG_AAI_HMAC;
2014 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
2016 case RTE_CRYPTO_AUTH_MD5_HMAC:
2017 authdata.algtype = OP_ALG_ALGSEL_MD5;
2018 authdata.algmode = OP_ALG_AAI_HMAC;
2019 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
2021 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2022 authdata.algtype = OP_ALG_ALGSEL_SHA224;
2023 authdata.algmode = OP_ALG_AAI_HMAC;
2024 session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
2026 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2027 authdata.algtype = OP_ALG_ALGSEL_SHA256;
2028 authdata.algmode = OP_ALG_AAI_HMAC;
2029 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
2031 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2032 authdata.algtype = OP_ALG_ALGSEL_SHA384;
2033 authdata.algmode = OP_ALG_AAI_HMAC;
2034 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
2036 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2037 authdata.algtype = OP_ALG_ALGSEL_SHA512;
2038 authdata.algmode = OP_ALG_AAI_HMAC;
2039 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
2041 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2042 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2043 case RTE_CRYPTO_AUTH_NULL:
2044 case RTE_CRYPTO_AUTH_SHA1:
2045 case RTE_CRYPTO_AUTH_SHA256:
2046 case RTE_CRYPTO_AUTH_SHA512:
2047 case RTE_CRYPTO_AUTH_SHA224:
2048 case RTE_CRYPTO_AUTH_SHA384:
2049 case RTE_CRYPTO_AUTH_MD5:
2050 case RTE_CRYPTO_AUTH_AES_GMAC:
2051 case RTE_CRYPTO_AUTH_KASUMI_F9:
2052 case RTE_CRYPTO_AUTH_AES_CMAC:
2053 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2054 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2055 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
2059 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2063 cipherdata.key = (size_t)session->cipher_key.data;
2064 cipherdata.keylen = session->cipher_key.length;
2065 cipherdata.key_enc_flags = 0;
2066 cipherdata.key_type = RTA_DATA_IMM;
2068 switch (cipher_xform->algo) {
2069 case RTE_CRYPTO_CIPHER_AES_CBC:
2070 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2071 cipherdata.algmode = OP_ALG_AAI_CBC;
2072 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
2074 case RTE_CRYPTO_CIPHER_3DES_CBC:
2075 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
2076 cipherdata.algmode = OP_ALG_AAI_CBC;
2077 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
2079 case RTE_CRYPTO_CIPHER_AES_CTR:
2080 cipherdata.algtype = OP_ALG_ALGSEL_AES;
2081 cipherdata.algmode = OP_ALG_AAI_CTR;
2082 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
2084 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2085 case RTE_CRYPTO_CIPHER_NULL:
2086 case RTE_CRYPTO_CIPHER_3DES_ECB:
2087 case RTE_CRYPTO_CIPHER_AES_ECB:
2088 case RTE_CRYPTO_CIPHER_KASUMI_F8:
2089 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
2090 cipher_xform->algo);
2093 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2094 cipher_xform->algo);
2097 session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
2100 priv->flc_desc[0].desc[0] = cipherdata.keylen;
2101 priv->flc_desc[0].desc[1] = authdata.keylen;
2102 err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
2104 (unsigned int *)priv->flc_desc[0].desc,
2105 &priv->flc_desc[0].desc[2], 2);
2108 DPAA2_SEC_ERR("Crypto: Incorrect key lengths");
2111 if (priv->flc_desc[0].desc[2] & 1) {
2112 cipherdata.key_type = RTA_DATA_IMM;
2114 cipherdata.key = DPAA2_VADDR_TO_IOVA(cipherdata.key);
2115 cipherdata.key_type = RTA_DATA_PTR;
2117 if (priv->flc_desc[0].desc[2] & (1 << 1)) {
2118 authdata.key_type = RTA_DATA_IMM;
2120 authdata.key = DPAA2_VADDR_TO_IOVA(authdata.key);
2121 authdata.key_type = RTA_DATA_PTR;
2123 priv->flc_desc[0].desc[0] = 0;
2124 priv->flc_desc[0].desc[1] = 0;
2125 priv->flc_desc[0].desc[2] = 0;
2127 if (session->ctxt_type == DPAA2_SEC_CIPHER_HASH) {
2128 bufsize = cnstr_shdsc_authenc(priv->flc_desc[0].desc, 1,
2129 0, &cipherdata, &authdata,
2131 ctxt->auth_only_len,
2132 session->digest_length,
2135 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2139 DPAA2_SEC_ERR("Hash before cipher not supported");
2143 flc->word1_sdl = (uint8_t)bufsize;
2144 flc->word2_rflc_31_0 = lower_32_bits(
2145 (size_t)&(((struct dpaa2_sec_qp *)
2146 dev->data->queue_pairs[0])->rx_vq));
2147 flc->word3_rflc_63_32 = upper_32_bits(
2148 (size_t)&(((struct dpaa2_sec_qp *)
2149 dev->data->queue_pairs[0])->rx_vq));
2150 session->ctxt = priv;
2151 for (i = 0; i < bufsize; i++)
2152 DPAA2_SEC_DEBUG("DESC[%d]:0x%x",
2153 i, priv->flc_desc[0].desc[i]);
2158 rte_free(session->cipher_key.data);
2159 rte_free(session->auth_key.data);
2165 dpaa2_sec_set_session_parameters(struct rte_cryptodev *dev,
2166 struct rte_crypto_sym_xform *xform, void *sess)
2168 dpaa2_sec_session *session = sess;
2170 PMD_INIT_FUNC_TRACE();
2172 if (unlikely(sess == NULL)) {
2173 DPAA2_SEC_ERR("Invalid session struct");
2177 memset(session, 0, sizeof(dpaa2_sec_session));
2178 /* Default IV length = 0 */
2179 session->iv.length = 0;
2182 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
2183 session->ctxt_type = DPAA2_SEC_CIPHER;
2184 dpaa2_sec_cipher_init(dev, xform, session);
2186 /* Authentication Only */
2187 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2188 xform->next == NULL) {
2189 session->ctxt_type = DPAA2_SEC_AUTH;
2190 dpaa2_sec_auth_init(dev, xform, session);
2192 /* Cipher then Authenticate */
2193 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
2194 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2195 session->ext_params.aead_ctxt.auth_cipher_text = true;
2196 dpaa2_sec_aead_chain_init(dev, xform, session);
2198 /* Authenticate then Cipher */
2199 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
2200 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2201 session->ext_params.aead_ctxt.auth_cipher_text = false;
2202 dpaa2_sec_aead_chain_init(dev, xform, session);
2204 /* AEAD operation for AES-GCM kind of Algorithms */
2205 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD &&
2206 xform->next == NULL) {
2207 dpaa2_sec_aead_init(dev, xform, session);
2210 DPAA2_SEC_ERR("Invalid crypto type");
2218 dpaa2_sec_ipsec_aead_init(struct rte_crypto_aead_xform *aead_xform,
2219 dpaa2_sec_session *session,
2220 struct alginfo *aeaddata)
2222 PMD_INIT_FUNC_TRACE();
2224 session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length,
2225 RTE_CACHE_LINE_SIZE);
2226 if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
2227 DPAA2_SEC_ERR("No Memory for aead key");
2230 memcpy(session->aead_key.data, aead_xform->key.data,
2231 aead_xform->key.length);
2233 session->digest_length = aead_xform->digest_length;
2234 session->aead_key.length = aead_xform->key.length;
2236 aeaddata->key = (size_t)session->aead_key.data;
2237 aeaddata->keylen = session->aead_key.length;
2238 aeaddata->key_enc_flags = 0;
2239 aeaddata->key_type = RTA_DATA_IMM;
2241 switch (aead_xform->algo) {
2242 case RTE_CRYPTO_AEAD_AES_GCM:
2243 aeaddata->algtype = OP_ALG_ALGSEL_AES;
2244 aeaddata->algmode = OP_ALG_AAI_GCM;
2245 session->aead_alg = RTE_CRYPTO_AEAD_AES_GCM;
2247 case RTE_CRYPTO_AEAD_AES_CCM:
2248 aeaddata->algtype = OP_ALG_ALGSEL_AES;
2249 aeaddata->algmode = OP_ALG_AAI_CCM;
2250 session->aead_alg = RTE_CRYPTO_AEAD_AES_CCM;
2253 DPAA2_SEC_ERR("Crypto: Undefined AEAD specified %u",
2257 session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
2264 dpaa2_sec_ipsec_proto_init(struct rte_crypto_cipher_xform *cipher_xform,
2265 struct rte_crypto_auth_xform *auth_xform,
2266 dpaa2_sec_session *session,
2267 struct alginfo *cipherdata,
2268 struct alginfo *authdata)
2271 session->cipher_key.data = rte_zmalloc(NULL,
2272 cipher_xform->key.length,
2273 RTE_CACHE_LINE_SIZE);
2274 if (session->cipher_key.data == NULL &&
2275 cipher_xform->key.length > 0) {
2276 DPAA2_SEC_ERR("No Memory for cipher key");
2280 session->cipher_key.length = cipher_xform->key.length;
2281 memcpy(session->cipher_key.data, cipher_xform->key.data,
2282 cipher_xform->key.length);
2283 session->cipher_alg = cipher_xform->algo;
2285 session->cipher_key.data = NULL;
2286 session->cipher_key.length = 0;
2287 session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
2291 session->auth_key.data = rte_zmalloc(NULL,
2292 auth_xform->key.length,
2293 RTE_CACHE_LINE_SIZE);
2294 if (session->auth_key.data == NULL &&
2295 auth_xform->key.length > 0) {
2296 DPAA2_SEC_ERR("No Memory for auth key");
2299 session->auth_key.length = auth_xform->key.length;
2300 memcpy(session->auth_key.data, auth_xform->key.data,
2301 auth_xform->key.length);
2302 session->auth_alg = auth_xform->algo;
2304 session->auth_key.data = NULL;
2305 session->auth_key.length = 0;
2306 session->auth_alg = RTE_CRYPTO_AUTH_NULL;
2309 authdata->key = (size_t)session->auth_key.data;
2310 authdata->keylen = session->auth_key.length;
2311 authdata->key_enc_flags = 0;
2312 authdata->key_type = RTA_DATA_IMM;
2313 switch (session->auth_alg) {
2314 case RTE_CRYPTO_AUTH_SHA1_HMAC:
2315 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA1_96;
2316 authdata->algmode = OP_ALG_AAI_HMAC;
2318 case RTE_CRYPTO_AUTH_MD5_HMAC:
2319 authdata->algtype = OP_PCL_IPSEC_HMAC_MD5_96;
2320 authdata->algmode = OP_ALG_AAI_HMAC;
2322 case RTE_CRYPTO_AUTH_SHA256_HMAC:
2323 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_256_128;
2324 authdata->algmode = OP_ALG_AAI_HMAC;
2326 case RTE_CRYPTO_AUTH_SHA384_HMAC:
2327 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_384_192;
2328 authdata->algmode = OP_ALG_AAI_HMAC;
2330 case RTE_CRYPTO_AUTH_SHA512_HMAC:
2331 authdata->algtype = OP_PCL_IPSEC_HMAC_SHA2_512_256;
2332 authdata->algmode = OP_ALG_AAI_HMAC;
2334 case RTE_CRYPTO_AUTH_AES_CMAC:
2335 authdata->algtype = OP_PCL_IPSEC_AES_CMAC_96;
2337 case RTE_CRYPTO_AUTH_NULL:
2338 authdata->algtype = OP_PCL_IPSEC_HMAC_NULL;
2340 case RTE_CRYPTO_AUTH_SHA224_HMAC:
2341 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
2342 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
2343 case RTE_CRYPTO_AUTH_SHA1:
2344 case RTE_CRYPTO_AUTH_SHA256:
2345 case RTE_CRYPTO_AUTH_SHA512:
2346 case RTE_CRYPTO_AUTH_SHA224:
2347 case RTE_CRYPTO_AUTH_SHA384:
2348 case RTE_CRYPTO_AUTH_MD5:
2349 case RTE_CRYPTO_AUTH_AES_GMAC:
2350 case RTE_CRYPTO_AUTH_KASUMI_F9:
2351 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
2352 case RTE_CRYPTO_AUTH_ZUC_EIA3:
2353 DPAA2_SEC_ERR("Crypto: Unsupported auth alg %u",
2357 DPAA2_SEC_ERR("Crypto: Undefined Auth specified %u",
2361 cipherdata->key = (size_t)session->cipher_key.data;
2362 cipherdata->keylen = session->cipher_key.length;
2363 cipherdata->key_enc_flags = 0;
2364 cipherdata->key_type = RTA_DATA_IMM;
2366 switch (session->cipher_alg) {
2367 case RTE_CRYPTO_CIPHER_AES_CBC:
2368 cipherdata->algtype = OP_PCL_IPSEC_AES_CBC;
2369 cipherdata->algmode = OP_ALG_AAI_CBC;
2371 case RTE_CRYPTO_CIPHER_3DES_CBC:
2372 cipherdata->algtype = OP_PCL_IPSEC_3DES;
2373 cipherdata->algmode = OP_ALG_AAI_CBC;
2375 case RTE_CRYPTO_CIPHER_AES_CTR:
2376 cipherdata->algtype = OP_PCL_IPSEC_AES_CTR;
2377 cipherdata->algmode = OP_ALG_AAI_CTR;
2379 case RTE_CRYPTO_CIPHER_NULL:
2380 cipherdata->algtype = OP_PCL_IPSEC_NULL;
2382 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
2383 case RTE_CRYPTO_CIPHER_3DES_ECB:
2384 case RTE_CRYPTO_CIPHER_AES_ECB:
2385 case RTE_CRYPTO_CIPHER_KASUMI_F8:
2386 DPAA2_SEC_ERR("Crypto: Unsupported Cipher alg %u",
2387 session->cipher_alg);
2390 DPAA2_SEC_ERR("Crypto: Undefined Cipher specified %u",
2391 session->cipher_alg);
2398 #ifdef RTE_LIBRTE_SECURITY_TEST
2399 static uint8_t aes_cbc_iv[] = {
2400 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
2401 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
2405 dpaa2_sec_set_ipsec_session(struct rte_cryptodev *dev,
2406 struct rte_security_session_conf *conf,
2409 struct rte_security_ipsec_xform *ipsec_xform = &conf->ipsec;
2410 struct rte_crypto_cipher_xform *cipher_xform = NULL;
2411 struct rte_crypto_auth_xform *auth_xform = NULL;
2412 struct rte_crypto_aead_xform *aead_xform = NULL;
2413 dpaa2_sec_session *session = (dpaa2_sec_session *)sess;
2414 struct ctxt_priv *priv;
2415 struct ipsec_encap_pdb encap_pdb;
2416 struct ipsec_decap_pdb decap_pdb;
2417 struct alginfo authdata, cipherdata;
2419 struct sec_flow_context *flc;
2420 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
2423 PMD_INIT_FUNC_TRACE();
2425 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
2426 sizeof(struct ctxt_priv) +
2427 sizeof(struct sec_flc_desc),
2428 RTE_CACHE_LINE_SIZE);
2431 DPAA2_SEC_ERR("No memory for priv CTXT");
2435 priv->fle_pool = dev_priv->fle_pool;
2436 flc = &priv->flc_desc[0].flc;
2438 memset(session, 0, sizeof(dpaa2_sec_session));
2440 if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
2441 cipher_xform = &conf->crypto_xform->cipher;
2442 if (conf->crypto_xform->next)
2443 auth_xform = &conf->crypto_xform->next->auth;
2444 ret = dpaa2_sec_ipsec_proto_init(cipher_xform, auth_xform,
2445 session, &cipherdata, &authdata);
2446 } else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
2447 auth_xform = &conf->crypto_xform->auth;
2448 if (conf->crypto_xform->next)
2449 cipher_xform = &conf->crypto_xform->next->cipher;
2450 ret = dpaa2_sec_ipsec_proto_init(cipher_xform, auth_xform,
2451 session, &cipherdata, &authdata);
2452 } else if (conf->crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
2453 aead_xform = &conf->crypto_xform->aead;
2454 ret = dpaa2_sec_ipsec_aead_init(aead_xform,
2455 session, &cipherdata);
2457 DPAA2_SEC_ERR("XFORM not specified");
2462 DPAA2_SEC_ERR("Failed to process xform");
2466 session->ctxt_type = DPAA2_SEC_IPSEC;
2467 if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
2470 flc->dhr = SEC_FLC_DHR_OUTBOUND;
2471 ip4_hdr.ip_v = IPVERSION;
2473 ip4_hdr.ip_len = rte_cpu_to_be_16(sizeof(ip4_hdr));
2474 ip4_hdr.ip_tos = ipsec_xform->tunnel.ipv4.dscp;
2477 ip4_hdr.ip_ttl = ipsec_xform->tunnel.ipv4.ttl;
2478 ip4_hdr.ip_p = IPPROTO_ESP;
2480 ip4_hdr.ip_src = ipsec_xform->tunnel.ipv4.src_ip;
2481 ip4_hdr.ip_dst = ipsec_xform->tunnel.ipv4.dst_ip;
2482 ip4_hdr.ip_sum = calc_chksum((uint16_t *)(void *)&ip4_hdr,
2485 /* For Sec Proto only one descriptor is required. */
2486 memset(&encap_pdb, 0, sizeof(struct ipsec_encap_pdb));
2487 encap_pdb.options = (IPVERSION << PDBNH_ESP_ENCAP_SHIFT) |
2488 PDBOPTS_ESP_OIHI_PDB_INL |
2490 PDBHMO_ESP_ENCAP_DTTL |
2492 encap_pdb.spi = ipsec_xform->spi;
2493 encap_pdb.ip_hdr_len = sizeof(struct ip);
2495 session->dir = DIR_ENC;
2496 bufsize = cnstr_shdsc_ipsec_new_encap(priv->flc_desc[0].desc,
2497 1, 0, SHR_SERIAL, &encap_pdb,
2498 (uint8_t *)&ip4_hdr,
2499 &cipherdata, &authdata);
2500 } else if (ipsec_xform->direction ==
2501 RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
2502 flc->dhr = SEC_FLC_DHR_INBOUND;
2503 memset(&decap_pdb, 0, sizeof(struct ipsec_decap_pdb));
2504 decap_pdb.options = sizeof(struct ip) << 16;
2505 session->dir = DIR_DEC;
2506 bufsize = cnstr_shdsc_ipsec_new_decap(priv->flc_desc[0].desc,
2508 &decap_pdb, &cipherdata, &authdata);
2513 DPAA2_SEC_ERR("Crypto: Invalid buffer length");
2517 flc->word1_sdl = (uint8_t)bufsize;
2519 /* Enable the stashing control bit */
2520 DPAA2_SET_FLC_RSC(flc);
2521 flc->word2_rflc_31_0 = lower_32_bits(
2522 (size_t)&(((struct dpaa2_sec_qp *)
2523 dev->data->queue_pairs[0])->rx_vq) | 0x14);
2524 flc->word3_rflc_63_32 = upper_32_bits(
2525 (size_t)&(((struct dpaa2_sec_qp *)
2526 dev->data->queue_pairs[0])->rx_vq));
2528 /* Set EWS bit i.e. enable write-safe */
2529 DPAA2_SET_FLC_EWS(flc);
2530 /* Set BS = 1 i.e reuse input buffers as output buffers */
2531 DPAA2_SET_FLC_REUSE_BS(flc);
2532 /* Set FF = 10; reuse input buffers if they provide sufficient space */
2533 DPAA2_SET_FLC_REUSE_FF(flc);
2535 session->ctxt = priv;
2539 rte_free(session->auth_key.data);
2540 rte_free(session->cipher_key.data);
2546 dpaa2_sec_security_session_create(void *dev,
2547 struct rte_security_session_conf *conf,
2548 struct rte_security_session *sess,
2549 struct rte_mempool *mempool)
2551 void *sess_private_data;
2552 struct rte_cryptodev *cdev = (struct rte_cryptodev *)dev;
2555 if (rte_mempool_get(mempool, &sess_private_data)) {
2556 DPAA2_SEC_ERR("Couldn't get object from session mempool");
2560 switch (conf->protocol) {
2561 case RTE_SECURITY_PROTOCOL_IPSEC:
2562 ret = dpaa2_sec_set_ipsec_session(cdev, conf,
2565 case RTE_SECURITY_PROTOCOL_MACSEC:
2571 DPAA2_SEC_ERR("Failed to configure session parameters");
2572 /* Return session to mempool */
2573 rte_mempool_put(mempool, sess_private_data);
2577 set_sec_session_private_data(sess, sess_private_data);
2582 /** Clear the memory of session so it doesn't leave key material behind */
2584 dpaa2_sec_security_session_destroy(void *dev __rte_unused,
2585 struct rte_security_session *sess)
2587 PMD_INIT_FUNC_TRACE();
2588 void *sess_priv = get_sec_session_private_data(sess);
2590 dpaa2_sec_session *s = (dpaa2_sec_session *)sess_priv;
2593 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
2596 rte_free(s->cipher_key.data);
2597 rte_free(s->auth_key.data);
2598 memset(sess, 0, sizeof(dpaa2_sec_session));
2599 set_sec_session_private_data(sess, NULL);
2600 rte_mempool_put(sess_mp, sess_priv);
2606 dpaa2_sec_sym_session_configure(struct rte_cryptodev *dev,
2607 struct rte_crypto_sym_xform *xform,
2608 struct rte_cryptodev_sym_session *sess,
2609 struct rte_mempool *mempool)
2611 void *sess_private_data;
2614 if (rte_mempool_get(mempool, &sess_private_data)) {
2615 DPAA2_SEC_ERR("Couldn't get object from session mempool");
2619 ret = dpaa2_sec_set_session_parameters(dev, xform, sess_private_data);
2621 DPAA2_SEC_ERR("Failed to configure session parameters");
2622 /* Return session to mempool */
2623 rte_mempool_put(mempool, sess_private_data);
2627 set_sym_session_private_data(sess, dev->driver_id,
2633 /** Clear the memory of session so it doesn't leave key material behind */
2635 dpaa2_sec_sym_session_clear(struct rte_cryptodev *dev,
2636 struct rte_cryptodev_sym_session *sess)
2638 PMD_INIT_FUNC_TRACE();
2639 uint8_t index = dev->driver_id;
2640 void *sess_priv = get_sym_session_private_data(sess, index);
2641 dpaa2_sec_session *s = (dpaa2_sec_session *)sess_priv;
2645 rte_free(s->cipher_key.data);
2646 rte_free(s->auth_key.data);
2647 memset(sess, 0, sizeof(dpaa2_sec_session));
2648 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
2649 set_sym_session_private_data(sess, index, NULL);
2650 rte_mempool_put(sess_mp, sess_priv);
2655 dpaa2_sec_dev_configure(struct rte_cryptodev *dev __rte_unused,
2656 struct rte_cryptodev_config *config __rte_unused)
2658 PMD_INIT_FUNC_TRACE();
2664 dpaa2_sec_dev_start(struct rte_cryptodev *dev)
2666 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
2667 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
2668 struct dpseci_attr attr;
2669 struct dpaa2_queue *dpaa2_q;
2670 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
2671 dev->data->queue_pairs;
2672 struct dpseci_rx_queue_attr rx_attr;
2673 struct dpseci_tx_queue_attr tx_attr;
2676 PMD_INIT_FUNC_TRACE();
2678 memset(&attr, 0, sizeof(struct dpseci_attr));
2680 ret = dpseci_enable(dpseci, CMD_PRI_LOW, priv->token);
2682 DPAA2_SEC_ERR("DPSECI with HW_ID = %d ENABLE FAILED",
2684 goto get_attr_failure;
2686 ret = dpseci_get_attributes(dpseci, CMD_PRI_LOW, priv->token, &attr);
2688 DPAA2_SEC_ERR("DPSEC ATTRIBUTE READ FAILED, disabling DPSEC");
2689 goto get_attr_failure;
2691 for (i = 0; i < attr.num_rx_queues && qp[i]; i++) {
2692 dpaa2_q = &qp[i]->rx_vq;
2693 dpseci_get_rx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
2695 dpaa2_q->fqid = rx_attr.fqid;
2696 DPAA2_SEC_DEBUG("rx_fqid: %d", dpaa2_q->fqid);
2698 for (i = 0; i < attr.num_tx_queues && qp[i]; i++) {
2699 dpaa2_q = &qp[i]->tx_vq;
2700 dpseci_get_tx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
2702 dpaa2_q->fqid = tx_attr.fqid;
2703 DPAA2_SEC_DEBUG("tx_fqid: %d", dpaa2_q->fqid);
2708 dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
2713 dpaa2_sec_dev_stop(struct rte_cryptodev *dev)
2715 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
2716 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
2719 PMD_INIT_FUNC_TRACE();
2721 ret = dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
2723 DPAA2_SEC_ERR("Failure in disabling dpseci %d device",
2728 ret = dpseci_reset(dpseci, CMD_PRI_LOW, priv->token);
2730 DPAA2_SEC_ERR("SEC Device cannot be reset:Error = %0x", ret);
2736 dpaa2_sec_dev_close(struct rte_cryptodev *dev)
2738 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
2739 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
2742 PMD_INIT_FUNC_TRACE();
2744 /* Function is reverse of dpaa2_sec_dev_init.
2745 * It does the following:
2746 * 1. Detach a DPSECI from attached resources i.e. buffer pools, dpbp_id
2747 * 2. Close the DPSECI device
2748 * 3. Free the allocated resources.
2751 /*Close the device at underlying layer*/
2752 ret = dpseci_close(dpseci, CMD_PRI_LOW, priv->token);
2754 DPAA2_SEC_ERR("Failure closing dpseci device: err(%d)", ret);
2758 /*Free the allocated memory for ethernet private data and dpseci*/
2766 dpaa2_sec_dev_infos_get(struct rte_cryptodev *dev,
2767 struct rte_cryptodev_info *info)
2769 struct dpaa2_sec_dev_private *internals = dev->data->dev_private;
2771 PMD_INIT_FUNC_TRACE();
2773 info->max_nb_queue_pairs = internals->max_nb_queue_pairs;
2774 info->feature_flags = dev->feature_flags;
2775 info->capabilities = dpaa2_sec_capabilities;
2776 /* No limit of number of sessions */
2777 info->sym.max_nb_sessions = 0;
2778 info->driver_id = cryptodev_driver_id;
2783 void dpaa2_sec_stats_get(struct rte_cryptodev *dev,
2784 struct rte_cryptodev_stats *stats)
2786 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
2787 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
2788 struct dpseci_sec_counters counters = {0};
2789 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
2790 dev->data->queue_pairs;
2793 PMD_INIT_FUNC_TRACE();
2794 if (stats == NULL) {
2795 DPAA2_SEC_ERR("Invalid stats ptr NULL");
2798 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
2799 if (qp[i] == NULL) {
2800 DPAA2_SEC_DEBUG("Uninitialised queue pair");
2804 stats->enqueued_count += qp[i]->tx_vq.tx_pkts;
2805 stats->dequeued_count += qp[i]->rx_vq.rx_pkts;
2806 stats->enqueue_err_count += qp[i]->tx_vq.err_pkts;
2807 stats->dequeue_err_count += qp[i]->rx_vq.err_pkts;
2810 ret = dpseci_get_sec_counters(dpseci, CMD_PRI_LOW, priv->token,
2813 DPAA2_SEC_ERR("SEC counters failed");
2815 DPAA2_SEC_INFO("dpseci hardware stats:"
2816 "\n\tNum of Requests Dequeued = %" PRIu64
2817 "\n\tNum of Outbound Encrypt Requests = %" PRIu64
2818 "\n\tNum of Inbound Decrypt Requests = %" PRIu64
2819 "\n\tNum of Outbound Bytes Encrypted = %" PRIu64
2820 "\n\tNum of Outbound Bytes Protected = %" PRIu64
2821 "\n\tNum of Inbound Bytes Decrypted = %" PRIu64
2822 "\n\tNum of Inbound Bytes Validated = %" PRIu64,
2823 counters.dequeued_requests,
2824 counters.ob_enc_requests,
2825 counters.ib_dec_requests,
2826 counters.ob_enc_bytes,
2827 counters.ob_prot_bytes,
2828 counters.ib_dec_bytes,
2829 counters.ib_valid_bytes);
2834 void dpaa2_sec_stats_reset(struct rte_cryptodev *dev)
2837 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
2838 (dev->data->queue_pairs);
2840 PMD_INIT_FUNC_TRACE();
2842 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
2843 if (qp[i] == NULL) {
2844 DPAA2_SEC_DEBUG("Uninitialised queue pair");
2847 qp[i]->tx_vq.rx_pkts = 0;
2848 qp[i]->tx_vq.tx_pkts = 0;
2849 qp[i]->tx_vq.err_pkts = 0;
2850 qp[i]->rx_vq.rx_pkts = 0;
2851 qp[i]->rx_vq.tx_pkts = 0;
2852 qp[i]->rx_vq.err_pkts = 0;
2856 static struct rte_cryptodev_ops crypto_ops = {
2857 .dev_configure = dpaa2_sec_dev_configure,
2858 .dev_start = dpaa2_sec_dev_start,
2859 .dev_stop = dpaa2_sec_dev_stop,
2860 .dev_close = dpaa2_sec_dev_close,
2861 .dev_infos_get = dpaa2_sec_dev_infos_get,
2862 .stats_get = dpaa2_sec_stats_get,
2863 .stats_reset = dpaa2_sec_stats_reset,
2864 .queue_pair_setup = dpaa2_sec_queue_pair_setup,
2865 .queue_pair_release = dpaa2_sec_queue_pair_release,
2866 .queue_pair_count = dpaa2_sec_queue_pair_count,
2867 .sym_session_get_size = dpaa2_sec_sym_session_get_size,
2868 .sym_session_configure = dpaa2_sec_sym_session_configure,
2869 .sym_session_clear = dpaa2_sec_sym_session_clear,
2872 static const struct rte_security_capability *
2873 dpaa2_sec_capabilities_get(void *device __rte_unused)
2875 return dpaa2_sec_security_cap;
2878 struct rte_security_ops dpaa2_sec_security_ops = {
2879 .session_create = dpaa2_sec_security_session_create,
2880 .session_update = NULL,
2881 .session_stats_get = NULL,
2882 .session_destroy = dpaa2_sec_security_session_destroy,
2883 .set_pkt_metadata = NULL,
2884 .capabilities_get = dpaa2_sec_capabilities_get
2888 dpaa2_sec_uninit(const struct rte_cryptodev *dev)
2890 struct dpaa2_sec_dev_private *internals = dev->data->dev_private;
2892 rte_free(dev->security_ctx);
2894 rte_mempool_free(internals->fle_pool);
2896 DPAA2_SEC_INFO("Closing DPAA2_SEC device %s on numa socket %u",
2897 dev->data->name, rte_socket_id());
2903 dpaa2_sec_dev_init(struct rte_cryptodev *cryptodev)
2905 struct dpaa2_sec_dev_private *internals;
2906 struct rte_device *dev = cryptodev->device;
2907 struct rte_dpaa2_device *dpaa2_dev;
2908 struct rte_security_ctx *security_instance;
2909 struct fsl_mc_io *dpseci;
2911 struct dpseci_attr attr;
2915 PMD_INIT_FUNC_TRACE();
2916 dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
2917 if (dpaa2_dev == NULL) {
2918 DPAA2_SEC_ERR("DPAA2 SEC device not found");
2921 hw_id = dpaa2_dev->object_id;
2923 cryptodev->driver_id = cryptodev_driver_id;
2924 cryptodev->dev_ops = &crypto_ops;
2926 cryptodev->enqueue_burst = dpaa2_sec_enqueue_burst;
2927 cryptodev->dequeue_burst = dpaa2_sec_dequeue_burst;
2928 cryptodev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
2929 RTE_CRYPTODEV_FF_HW_ACCELERATED |
2930 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
2931 RTE_CRYPTODEV_FF_SECURITY |
2932 RTE_CRYPTODEV_FF_IN_PLACE_SGL |
2933 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT |
2934 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
2935 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT |
2936 RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT;
2938 internals = cryptodev->data->dev_private;
2941 * For secondary processes, we don't initialise any further as primary
2942 * has already done this work. Only check we don't need a different
2945 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2946 DPAA2_SEC_DEBUG("Device already init by primary process");
2950 /* Initialize security_ctx only for primary process*/
2951 security_instance = rte_malloc("rte_security_instances_ops",
2952 sizeof(struct rte_security_ctx), 0);
2953 if (security_instance == NULL)
2955 security_instance->device = (void *)cryptodev;
2956 security_instance->ops = &dpaa2_sec_security_ops;
2957 security_instance->sess_cnt = 0;
2958 cryptodev->security_ctx = security_instance;
2960 /*Open the rte device via MC and save the handle for further use*/
2961 dpseci = (struct fsl_mc_io *)rte_calloc(NULL, 1,
2962 sizeof(struct fsl_mc_io), 0);
2965 "Error in allocating the memory for dpsec object");
2968 dpseci->regs = rte_mcp_ptr_list[0];
2970 retcode = dpseci_open(dpseci, CMD_PRI_LOW, hw_id, &token);
2972 DPAA2_SEC_ERR("Cannot open the dpsec device: Error = %x",
2976 retcode = dpseci_get_attributes(dpseci, CMD_PRI_LOW, token, &attr);
2979 "Cannot get dpsec device attributed: Error = %x",
2983 sprintf(cryptodev->data->name, "dpsec-%u", hw_id);
2985 internals->max_nb_queue_pairs = attr.num_tx_queues;
2986 cryptodev->data->nb_queue_pairs = internals->max_nb_queue_pairs;
2987 internals->hw = dpseci;
2988 internals->token = token;
2990 sprintf(str, "fle_pool_%d", cryptodev->data->dev_id);
2991 internals->fle_pool = rte_mempool_create((const char *)str,
2994 FLE_POOL_CACHE_SIZE, 0,
2995 NULL, NULL, NULL, NULL,
2997 if (!internals->fle_pool) {
2998 DPAA2_SEC_ERR("Mempool (%s) creation failed", str);
3002 DPAA2_SEC_INFO("driver %s: created", cryptodev->data->name);
3006 DPAA2_SEC_ERR("driver %s: create failed", cryptodev->data->name);
3008 /* dpaa2_sec_uninit(crypto_dev_name); */
3013 cryptodev_dpaa2_sec_probe(struct rte_dpaa2_driver *dpaa2_drv __rte_unused,
3014 struct rte_dpaa2_device *dpaa2_dev)
3016 struct rte_cryptodev *cryptodev;
3017 char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
3021 sprintf(cryptodev_name, "dpsec-%d", dpaa2_dev->object_id);
3023 cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
3024 if (cryptodev == NULL)
3027 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
3028 cryptodev->data->dev_private = rte_zmalloc_socket(
3029 "cryptodev private structure",
3030 sizeof(struct dpaa2_sec_dev_private),
3031 RTE_CACHE_LINE_SIZE,
3034 if (cryptodev->data->dev_private == NULL)
3035 rte_panic("Cannot allocate memzone for private "
3039 dpaa2_dev->cryptodev = cryptodev;
3040 cryptodev->device = &dpaa2_dev->device;
3042 /* init user callbacks */
3043 TAILQ_INIT(&(cryptodev->link_intr_cbs));
3045 /* Invoke PMD device initialization function */
3046 retval = dpaa2_sec_dev_init(cryptodev);
3050 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
3051 rte_free(cryptodev->data->dev_private);
3053 cryptodev->attached = RTE_CRYPTODEV_DETACHED;
3059 cryptodev_dpaa2_sec_remove(struct rte_dpaa2_device *dpaa2_dev)
3061 struct rte_cryptodev *cryptodev;
3064 cryptodev = dpaa2_dev->cryptodev;
3065 if (cryptodev == NULL)
3068 ret = dpaa2_sec_uninit(cryptodev);
3072 return rte_cryptodev_pmd_destroy(cryptodev);
3075 static struct rte_dpaa2_driver rte_dpaa2_sec_driver = {
3076 .drv_flags = RTE_DPAA2_DRV_IOVA_AS_VA,
3077 .drv_type = DPAA2_CRYPTO,
3079 .name = "DPAA2 SEC PMD"
3081 .probe = cryptodev_dpaa2_sec_probe,
3082 .remove = cryptodev_dpaa2_sec_remove,
3085 static struct cryptodev_driver dpaa2_sec_crypto_drv;
3087 RTE_PMD_REGISTER_DPAA2(CRYPTODEV_NAME_DPAA2_SEC_PMD, rte_dpaa2_sec_driver);
3088 RTE_PMD_REGISTER_CRYPTO_DRIVER(dpaa2_sec_crypto_drv,
3089 rte_dpaa2_sec_driver.driver, cryptodev_driver_id);
3091 RTE_INIT(dpaa2_sec_init_log)
3093 /* Bus level logs */
3094 dpaa2_logtype_sec = rte_log_register("pmd.crypto.dpaa2");
3095 if (dpaa2_logtype_sec >= 0)
3096 rte_log_set_level(dpaa2_logtype_sec, RTE_LOG_NOTICE);