4 * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
5 * Copyright (c) 2016 NXP. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Freescale Semiconductor, Inc nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <rte_cryptodev.h>
39 #include <rte_malloc.h>
40 #include <rte_memcpy.h>
41 #include <rte_string_fns.h>
42 #include <rte_cycles.h>
43 #include <rte_kvargs.h>
45 #include <rte_cryptodev_pmd.h>
46 #include <rte_common.h>
47 #include <rte_fslmc.h>
48 #include <fslmc_vfio.h>
49 #include <dpaa2_hw_pvt.h>
50 #include <dpaa2_hw_dpio.h>
51 #include <dpaa2_hw_mempool.h>
52 #include <fsl_dpseci.h>
53 #include <fsl_mc_sys.h>
55 #include "dpaa2_sec_priv.h"
56 #include "dpaa2_sec_logs.h"
58 /* RTA header files */
59 #include <hw/desc/ipsec.h>
60 #include <hw/desc/algo.h>
62 /* Minimum job descriptor consists of a oneword job descriptor HEADER and
63 * a pointer to the shared descriptor
65 #define MIN_JOB_DESC_SIZE (CAAM_CMD_SZ + CAAM_PTR_SZ)
66 #define FSL_VENDOR_ID 0x1957
67 #define FSL_DEVICE_ID 0x410
68 #define FSL_SUBSYSTEM_SEC 1
69 #define FSL_MC_DPSECI_DEVID 3
72 #define TDES_CBC_IV_LEN 8
73 #define AES_CBC_IV_LEN 16
74 enum rta_sec_era rta_sec_era = RTA_SEC_ERA_8;
77 build_authenc_fd(dpaa2_sec_session *sess,
78 struct rte_crypto_op *op,
79 struct qbman_fd *fd, uint16_t bpid)
81 struct rte_crypto_sym_op *sym_op = op->sym;
82 struct ctxt_priv *priv = sess->ctxt;
83 struct qbman_fle *fle, *sge;
84 struct sec_flow_context *flc;
85 uint32_t auth_only_len = sym_op->auth.data.length -
86 sym_op->cipher.data.length;
87 int icv_len = sym_op->auth.digest.length;
89 uint32_t mem_len = (7 * sizeof(struct qbman_fle)) + icv_len;
90 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
91 op->sym->cipher.iv.offset);
93 PMD_INIT_FUNC_TRACE();
95 /* we are using the first FLE entry to store Mbuf.
96 * Currently we donot know which FLE has the mbuf stored.
97 * So while retreiving we can go back 1 FLE from the FD -ADDR
98 * to get the MBUF Addr from the previous FLE.
99 * We can have a better approach to use the inline Mbuf
101 fle = rte_zmalloc(NULL, mem_len, RTE_CACHE_LINE_SIZE);
103 RTE_LOG(ERR, PMD, "Memory alloc failed for SGE\n");
106 DPAA2_SET_FLE_ADDR(fle, DPAA2_OP_VADDR_TO_IOVA(op));
109 if (likely(bpid < MAX_BPID)) {
110 DPAA2_SET_FD_BPID(fd, bpid);
111 DPAA2_SET_FLE_BPID(fle, bpid);
112 DPAA2_SET_FLE_BPID(fle + 1, bpid);
113 DPAA2_SET_FLE_BPID(sge, bpid);
114 DPAA2_SET_FLE_BPID(sge + 1, bpid);
115 DPAA2_SET_FLE_BPID(sge + 2, bpid);
116 DPAA2_SET_FLE_BPID(sge + 3, bpid);
118 DPAA2_SET_FD_IVP(fd);
119 DPAA2_SET_FLE_IVP(fle);
120 DPAA2_SET_FLE_IVP((fle + 1));
121 DPAA2_SET_FLE_IVP(sge);
122 DPAA2_SET_FLE_IVP((sge + 1));
123 DPAA2_SET_FLE_IVP((sge + 2));
124 DPAA2_SET_FLE_IVP((sge + 3));
127 /* Save the shared descriptor */
128 flc = &priv->flc_desc[0].flc;
129 /* Configure FD as a FRAME LIST */
130 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
131 DPAA2_SET_FD_COMPOUND_FMT(fd);
132 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
134 PMD_TX_LOG(DEBUG, "auth_off: 0x%x/length %d, digest-len=%d\n"
135 "cipher_off: 0x%x/length %d, iv-len=%d data_off: 0x%x\n",
136 sym_op->auth.data.offset,
137 sym_op->auth.data.length,
138 sym_op->auth.digest.length,
139 sym_op->cipher.data.offset,
140 sym_op->cipher.data.length,
141 sym_op->cipher.iv.length,
142 sym_op->m_src->data_off);
144 /* Configure Output FLE with Scatter/Gather Entry */
145 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
147 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
148 fle->length = (sess->dir == DIR_ENC) ?
149 (sym_op->cipher.data.length + icv_len) :
150 sym_op->cipher.data.length;
152 DPAA2_SET_FLE_SG_EXT(fle);
154 /* Configure Output SGE for Encap/Decap */
155 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
156 DPAA2_SET_FLE_OFFSET(sge, sym_op->cipher.data.offset +
157 sym_op->m_src->data_off);
158 sge->length = sym_op->cipher.data.length;
160 if (sess->dir == DIR_ENC) {
162 DPAA2_SET_FLE_ADDR(sge,
163 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
164 sge->length = sym_op->auth.digest.length;
165 DPAA2_SET_FD_LEN(fd, (sym_op->auth.data.length +
166 sym_op->cipher.iv.length));
168 DPAA2_SET_FLE_FIN(sge);
173 /* Configure Input FLE with Scatter/Gather Entry */
174 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
175 DPAA2_SET_FLE_SG_EXT(fle);
176 DPAA2_SET_FLE_FIN(fle);
177 fle->length = (sess->dir == DIR_ENC) ?
178 (sym_op->auth.data.length + sym_op->cipher.iv.length) :
179 (sym_op->auth.data.length + sym_op->cipher.iv.length +
180 sym_op->auth.digest.length);
182 /* Configure Input SGE for Encap/Decap */
183 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
184 sge->length = sym_op->cipher.iv.length;
187 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
188 DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset +
189 sym_op->m_src->data_off);
190 sge->length = sym_op->auth.data.length;
191 if (sess->dir == DIR_DEC) {
193 old_icv = (uint8_t *)(sge + 1);
194 memcpy(old_icv, sym_op->auth.digest.data,
195 sym_op->auth.digest.length);
196 memset(sym_op->auth.digest.data, 0, sym_op->auth.digest.length);
197 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
198 sge->length = sym_op->auth.digest.length;
199 DPAA2_SET_FD_LEN(fd, (sym_op->auth.data.length +
200 sym_op->auth.digest.length +
201 sym_op->cipher.iv.length));
203 DPAA2_SET_FLE_FIN(sge);
205 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
206 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
212 build_auth_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
213 struct qbman_fd *fd, uint16_t bpid)
215 struct rte_crypto_sym_op *sym_op = op->sym;
216 struct qbman_fle *fle, *sge;
217 uint32_t mem_len = (sess->dir == DIR_ENC) ?
218 (3 * sizeof(struct qbman_fle)) :
219 (5 * sizeof(struct qbman_fle) +
220 sym_op->auth.digest.length);
221 struct sec_flow_context *flc;
222 struct ctxt_priv *priv = sess->ctxt;
225 PMD_INIT_FUNC_TRACE();
227 fle = rte_zmalloc(NULL, mem_len, RTE_CACHE_LINE_SIZE);
229 RTE_LOG(ERR, PMD, "Memory alloc failed for FLE\n");
232 /* TODO we are using the first FLE entry to store Mbuf.
233 * Currently we donot know which FLE has the mbuf stored.
234 * So while retreiving we can go back 1 FLE from the FD -ADDR
235 * to get the MBUF Addr from the previous FLE.
236 * We can have a better approach to use the inline Mbuf
238 DPAA2_SET_FLE_ADDR(fle, DPAA2_OP_VADDR_TO_IOVA(op));
241 if (likely(bpid < MAX_BPID)) {
242 DPAA2_SET_FD_BPID(fd, bpid);
243 DPAA2_SET_FLE_BPID(fle, bpid);
244 DPAA2_SET_FLE_BPID(fle + 1, bpid);
246 DPAA2_SET_FD_IVP(fd);
247 DPAA2_SET_FLE_IVP(fle);
248 DPAA2_SET_FLE_IVP((fle + 1));
250 flc = &priv->flc_desc[DESC_INITFINAL].flc;
251 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
253 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
254 fle->length = sym_op->auth.digest.length;
256 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
257 DPAA2_SET_FD_COMPOUND_FMT(fd);
260 if (sess->dir == DIR_ENC) {
261 DPAA2_SET_FLE_ADDR(fle,
262 DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
263 DPAA2_SET_FLE_OFFSET(fle, sym_op->auth.data.offset +
264 sym_op->m_src->data_off);
265 DPAA2_SET_FD_LEN(fd, sym_op->auth.data.length);
266 fle->length = sym_op->auth.data.length;
269 DPAA2_SET_FLE_SG_EXT(fle);
270 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
272 if (likely(bpid < MAX_BPID)) {
273 DPAA2_SET_FLE_BPID(sge, bpid);
274 DPAA2_SET_FLE_BPID(sge + 1, bpid);
276 DPAA2_SET_FLE_IVP(sge);
277 DPAA2_SET_FLE_IVP((sge + 1));
279 DPAA2_SET_FLE_ADDR(sge,
280 DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
281 DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset +
282 sym_op->m_src->data_off);
284 DPAA2_SET_FD_LEN(fd, sym_op->auth.data.length +
285 sym_op->auth.digest.length);
286 sge->length = sym_op->auth.data.length;
288 old_digest = (uint8_t *)(sge + 1);
289 rte_memcpy(old_digest, sym_op->auth.digest.data,
290 sym_op->auth.digest.length);
291 memset(sym_op->auth.digest.data, 0, sym_op->auth.digest.length);
292 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_digest));
293 sge->length = sym_op->auth.digest.length;
294 fle->length = sym_op->auth.data.length +
295 sym_op->auth.digest.length;
296 DPAA2_SET_FLE_FIN(sge);
298 DPAA2_SET_FLE_FIN(fle);
304 build_cipher_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
305 struct qbman_fd *fd, uint16_t bpid)
307 struct rte_crypto_sym_op *sym_op = op->sym;
308 struct qbman_fle *fle, *sge;
309 uint32_t mem_len = (5 * sizeof(struct qbman_fle));
310 struct sec_flow_context *flc;
311 struct ctxt_priv *priv = sess->ctxt;
312 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
313 op->sym->cipher.iv.offset);
315 PMD_INIT_FUNC_TRACE();
317 /* todo - we can use some mempool to avoid malloc here */
318 fle = rte_zmalloc(NULL, mem_len, RTE_CACHE_LINE_SIZE);
320 RTE_LOG(ERR, PMD, "Memory alloc failed for SGE\n");
323 /* TODO we are using the first FLE entry to store Mbuf.
324 * Currently we donot know which FLE has the mbuf stored.
325 * So while retreiving we can go back 1 FLE from the FD -ADDR
326 * to get the MBUF Addr from the previous FLE.
327 * We can have a better approach to use the inline Mbuf
329 DPAA2_SET_FLE_ADDR(fle, DPAA2_OP_VADDR_TO_IOVA(op));
333 if (likely(bpid < MAX_BPID)) {
334 DPAA2_SET_FD_BPID(fd, bpid);
335 DPAA2_SET_FLE_BPID(fle, bpid);
336 DPAA2_SET_FLE_BPID(fle + 1, bpid);
337 DPAA2_SET_FLE_BPID(sge, bpid);
338 DPAA2_SET_FLE_BPID(sge + 1, bpid);
340 DPAA2_SET_FD_IVP(fd);
341 DPAA2_SET_FLE_IVP(fle);
342 DPAA2_SET_FLE_IVP((fle + 1));
343 DPAA2_SET_FLE_IVP(sge);
344 DPAA2_SET_FLE_IVP((sge + 1));
347 flc = &priv->flc_desc[0].flc;
348 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
349 DPAA2_SET_FD_LEN(fd, sym_op->cipher.data.length +
350 sym_op->cipher.iv.length);
351 DPAA2_SET_FD_COMPOUND_FMT(fd);
352 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
354 PMD_TX_LOG(DEBUG, "cipher_off: 0x%x/length %d,ivlen=%d data_off: 0x%x",
355 sym_op->cipher.data.offset,
356 sym_op->cipher.data.length,
357 sym_op->cipher.iv.length,
358 sym_op->m_src->data_off);
360 DPAA2_SET_FLE_ADDR(fle, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
361 DPAA2_SET_FLE_OFFSET(fle, sym_op->cipher.data.offset +
362 sym_op->m_src->data_off);
364 fle->length = sym_op->cipher.data.length + sym_op->cipher.iv.length;
366 PMD_TX_LOG(DEBUG, "1 - flc = %p, fle = %p FLEaddr = %x-%x, length %d",
367 flc, fle, fle->addr_hi, fle->addr_lo, fle->length);
371 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
372 fle->length = sym_op->cipher.data.length + sym_op->cipher.iv.length;
374 DPAA2_SET_FLE_SG_EXT(fle);
376 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
377 sge->length = sym_op->cipher.iv.length;
380 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
381 DPAA2_SET_FLE_OFFSET(sge, sym_op->cipher.data.offset +
382 sym_op->m_src->data_off);
384 sge->length = sym_op->cipher.data.length;
385 DPAA2_SET_FLE_FIN(sge);
386 DPAA2_SET_FLE_FIN(fle);
388 PMD_TX_LOG(DEBUG, "fdaddr =%p bpid =%d meta =%d off =%d, len =%d",
389 (void *)DPAA2_GET_FD_ADDR(fd),
390 DPAA2_GET_FD_BPID(fd),
391 rte_dpaa2_bpid_info[bpid].meta_data_size,
392 DPAA2_GET_FD_OFFSET(fd),
393 DPAA2_GET_FD_LEN(fd));
399 build_sec_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
400 struct qbman_fd *fd, uint16_t bpid)
404 PMD_INIT_FUNC_TRACE();
406 switch (sess->ctxt_type) {
407 case DPAA2_SEC_CIPHER:
408 ret = build_cipher_fd(sess, op, fd, bpid);
411 ret = build_auth_fd(sess, op, fd, bpid);
413 case DPAA2_SEC_CIPHER_HASH:
414 ret = build_authenc_fd(sess, op, fd, bpid);
416 case DPAA2_SEC_HASH_CIPHER:
418 RTE_LOG(ERR, PMD, "error: Unsupported session\n");
424 dpaa2_sec_enqueue_burst(void *qp, struct rte_crypto_op **ops,
427 /* Function to transmit the frames to given device and VQ*/
430 struct qbman_fd fd_arr[MAX_TX_RING_SLOTS];
431 uint32_t frames_to_send;
432 struct qbman_eq_desc eqdesc;
433 struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
434 struct qbman_swp *swp;
436 /*todo - need to support multiple buffer pools */
438 struct rte_mempool *mb_pool;
439 dpaa2_sec_session *sess;
441 if (unlikely(nb_ops == 0))
444 if (ops[0]->sess_type != RTE_CRYPTO_OP_WITH_SESSION) {
445 RTE_LOG(ERR, PMD, "sessionless crypto op not supported\n");
448 /*Prepare enqueue descriptor*/
449 qbman_eq_desc_clear(&eqdesc);
450 qbman_eq_desc_set_no_orp(&eqdesc, DPAA2_EQ_RESP_ERR_FQ);
451 qbman_eq_desc_set_response(&eqdesc, 0, 0);
452 qbman_eq_desc_set_fq(&eqdesc, dpaa2_qp->tx_vq.fqid);
454 if (!DPAA2_PER_LCORE_SEC_DPIO) {
455 ret = dpaa2_affine_qbman_swp_sec();
457 RTE_LOG(ERR, PMD, "Failure in affining portal\n");
461 swp = DPAA2_PER_LCORE_SEC_PORTAL;
464 frames_to_send = (nb_ops >> 3) ? MAX_TX_RING_SLOTS : nb_ops;
466 for (loop = 0; loop < frames_to_send; loop++) {
467 /*Clear the unused FD fields before sending*/
468 memset(&fd_arr[loop], 0, sizeof(struct qbman_fd));
469 sess = (dpaa2_sec_session *)
470 (*ops)->sym->session->_private;
471 mb_pool = (*ops)->sym->m_src->pool;
472 bpid = mempool_to_bpid(mb_pool);
473 ret = build_sec_fd(sess, *ops, &fd_arr[loop], bpid);
475 PMD_DRV_LOG(ERR, "error: Improper packet"
476 " contents for crypto operation\n");
482 while (loop < frames_to_send) {
483 loop += qbman_swp_send_multiple(swp, &eqdesc,
485 frames_to_send - loop);
488 num_tx += frames_to_send;
489 nb_ops -= frames_to_send;
492 dpaa2_qp->tx_vq.tx_pkts += num_tx;
493 dpaa2_qp->tx_vq.err_pkts += nb_ops;
497 static inline struct rte_crypto_op *
498 sec_fd_to_mbuf(const struct qbman_fd *fd)
500 struct qbman_fle *fle;
501 struct rte_crypto_op *op;
503 fle = (struct qbman_fle *)DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd));
505 PMD_RX_LOG(DEBUG, "FLE addr = %x - %x, offset = %x",
506 fle->addr_hi, fle->addr_lo, fle->fin_bpid_offset);
508 /* we are using the first FLE entry to store Mbuf.
509 * Currently we donot know which FLE has the mbuf stored.
510 * So while retreiving we can go back 1 FLE from the FD -ADDR
511 * to get the MBUF Addr from the previous FLE.
512 * We can have a better approach to use the inline Mbuf
515 if (unlikely(DPAA2_GET_FD_IVP(fd))) {
516 /* TODO complete it. */
517 RTE_LOG(ERR, PMD, "error: Non inline buffer - WHAT to DO?");
520 op = (struct rte_crypto_op *)DPAA2_IOVA_TO_VADDR(
521 DPAA2_GET_FLE_ADDR((fle - 1)));
524 rte_prefetch0(op->sym->m_src);
526 PMD_RX_LOG(DEBUG, "mbuf %p BMAN buf addr %p",
527 (void *)op->sym->m_src, op->sym->m_src->buf_addr);
529 PMD_RX_LOG(DEBUG, "fdaddr =%p bpid =%d meta =%d off =%d, len =%d",
530 (void *)DPAA2_GET_FD_ADDR(fd),
531 DPAA2_GET_FD_BPID(fd),
532 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size,
533 DPAA2_GET_FD_OFFSET(fd),
534 DPAA2_GET_FD_LEN(fd));
536 /* free the fle memory */
543 dpaa2_sec_dequeue_burst(void *qp, struct rte_crypto_op **ops,
546 /* Function is responsible to receive frames for a given device and VQ*/
547 struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
548 struct qbman_result *dq_storage;
549 uint32_t fqid = dpaa2_qp->rx_vq.fqid;
551 uint8_t is_last = 0, status;
552 struct qbman_swp *swp;
553 const struct qbman_fd *fd;
554 struct qbman_pull_desc pulldesc;
556 if (!DPAA2_PER_LCORE_SEC_DPIO) {
557 ret = dpaa2_affine_qbman_swp_sec();
559 RTE_LOG(ERR, PMD, "Failure in affining portal\n");
563 swp = DPAA2_PER_LCORE_SEC_PORTAL;
564 dq_storage = dpaa2_qp->rx_vq.q_storage->dq_storage[0];
566 qbman_pull_desc_clear(&pulldesc);
567 qbman_pull_desc_set_numframes(&pulldesc,
568 (nb_ops > DPAA2_DQRR_RING_SIZE) ?
569 DPAA2_DQRR_RING_SIZE : nb_ops);
570 qbman_pull_desc_set_fq(&pulldesc, fqid);
571 qbman_pull_desc_set_storage(&pulldesc, dq_storage,
572 (dma_addr_t)DPAA2_VADDR_TO_IOVA(dq_storage),
575 /*Issue a volatile dequeue command. */
577 if (qbman_swp_pull(swp, &pulldesc)) {
578 RTE_LOG(WARNING, PMD, "SEC VDQ command is not issued."
580 /* Portal was busy, try again */
586 /* Receive the packets till Last Dequeue entry is found with
587 * respect to the above issues PULL command.
590 /* Check if the previous issued command is completed.
591 * Also seems like the SWP is shared between the Ethernet Driver
592 * and the SEC driver.
594 while (!qbman_check_command_complete(swp, dq_storage))
597 /* Loop until the dq_storage is updated with
600 while (!qbman_result_has_new_result(swp, dq_storage))
602 /* Check whether Last Pull command is Expired and
603 * setting Condition for Loop termination
605 if (qbman_result_DQ_is_pull_complete(dq_storage)) {
607 /* Check for valid frame. */
608 status = (uint8_t)qbman_result_DQ_flags(dq_storage);
610 (status & QBMAN_DQ_STAT_VALIDFRAME) == 0)) {
611 PMD_RX_LOG(DEBUG, "No frame is delivered");
616 fd = qbman_result_DQ_fd(dq_storage);
617 ops[num_rx] = sec_fd_to_mbuf(fd);
619 if (unlikely(fd->simple.frc)) {
620 /* TODO Parse SEC errors */
621 RTE_LOG(ERR, PMD, "SEC returned Error - %x\n",
623 ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_ERROR;
625 ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
630 } /* End of Packet Rx loop */
632 dpaa2_qp->rx_vq.rx_pkts += num_rx;
634 PMD_RX_LOG(DEBUG, "SEC Received %d Packets", num_rx);
635 /*Return the total number of packets received to DPAA2 app*/
639 /** Release queue pair */
641 dpaa2_sec_queue_pair_release(struct rte_cryptodev *dev, uint16_t queue_pair_id)
643 struct dpaa2_sec_qp *qp =
644 (struct dpaa2_sec_qp *)dev->data->queue_pairs[queue_pair_id];
646 PMD_INIT_FUNC_TRACE();
648 if (qp->rx_vq.q_storage) {
649 dpaa2_free_dq_storage(qp->rx_vq.q_storage);
650 rte_free(qp->rx_vq.q_storage);
654 dev->data->queue_pairs[queue_pair_id] = NULL;
659 /** Setup a queue pair */
661 dpaa2_sec_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
662 __rte_unused const struct rte_cryptodev_qp_conf *qp_conf,
663 __rte_unused int socket_id)
665 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
666 struct dpaa2_sec_qp *qp;
667 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
668 struct dpseci_rx_queue_cfg cfg;
671 PMD_INIT_FUNC_TRACE();
673 /* If qp is already in use free ring memory and qp metadata. */
674 if (dev->data->queue_pairs[qp_id] != NULL) {
675 PMD_DRV_LOG(INFO, "QP already setup");
679 PMD_DRV_LOG(DEBUG, "dev =%p, queue =%d, conf =%p",
680 dev, qp_id, qp_conf);
682 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
684 qp = rte_malloc(NULL, sizeof(struct dpaa2_sec_qp),
685 RTE_CACHE_LINE_SIZE);
687 RTE_LOG(ERR, PMD, "malloc failed for rx/tx queues\n");
693 qp->rx_vq.q_storage = rte_malloc("sec dq storage",
694 sizeof(struct queue_storage_info_t),
695 RTE_CACHE_LINE_SIZE);
696 if (!qp->rx_vq.q_storage) {
697 RTE_LOG(ERR, PMD, "malloc failed for q_storage\n");
700 memset(qp->rx_vq.q_storage, 0, sizeof(struct queue_storage_info_t));
702 if (dpaa2_alloc_dq_storage(qp->rx_vq.q_storage)) {
703 RTE_LOG(ERR, PMD, "dpaa2_alloc_dq_storage failed\n");
707 dev->data->queue_pairs[qp_id] = qp;
709 cfg.options = cfg.options | DPSECI_QUEUE_OPT_USER_CTX;
710 cfg.user_ctx = (uint64_t)(&qp->rx_vq);
711 retcode = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
716 /** Start queue pair */
718 dpaa2_sec_queue_pair_start(__rte_unused struct rte_cryptodev *dev,
719 __rte_unused uint16_t queue_pair_id)
721 PMD_INIT_FUNC_TRACE();
726 /** Stop queue pair */
728 dpaa2_sec_queue_pair_stop(__rte_unused struct rte_cryptodev *dev,
729 __rte_unused uint16_t queue_pair_id)
731 PMD_INIT_FUNC_TRACE();
736 /** Return the number of allocated queue pairs */
738 dpaa2_sec_queue_pair_count(struct rte_cryptodev *dev)
740 PMD_INIT_FUNC_TRACE();
742 return dev->data->nb_queue_pairs;
745 /** Returns the size of the aesni gcm session structure */
747 dpaa2_sec_session_get_size(struct rte_cryptodev *dev __rte_unused)
749 PMD_INIT_FUNC_TRACE();
751 return sizeof(dpaa2_sec_session);
755 dpaa2_sec_session_initialize(struct rte_mempool *mp __rte_unused,
756 void *sess __rte_unused)
758 PMD_INIT_FUNC_TRACE();
762 dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
763 struct rte_crypto_sym_xform *xform,
764 dpaa2_sec_session *session)
766 struct dpaa2_sec_cipher_ctxt *ctxt = &session->ext_params.cipher_ctxt;
767 struct alginfo cipherdata;
769 struct ctxt_priv *priv;
770 struct sec_flow_context *flc;
772 PMD_INIT_FUNC_TRACE();
774 /* For SEC CIPHER only one descriptor is required. */
775 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
776 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
777 RTE_CACHE_LINE_SIZE);
779 RTE_LOG(ERR, PMD, "No Memory for priv CTXT");
783 flc = &priv->flc_desc[0].flc;
785 session->cipher_key.data = rte_zmalloc(NULL, xform->cipher.key.length,
786 RTE_CACHE_LINE_SIZE);
787 if (session->cipher_key.data == NULL) {
788 RTE_LOG(ERR, PMD, "No Memory for cipher key");
792 session->cipher_key.length = xform->cipher.key.length;
794 memcpy(session->cipher_key.data, xform->cipher.key.data,
795 xform->cipher.key.length);
796 cipherdata.key = (uint64_t)session->cipher_key.data;
797 cipherdata.keylen = session->cipher_key.length;
798 cipherdata.key_enc_flags = 0;
799 cipherdata.key_type = RTA_DATA_IMM;
801 switch (xform->cipher.algo) {
802 case RTE_CRYPTO_CIPHER_AES_CBC:
803 cipherdata.algtype = OP_ALG_ALGSEL_AES;
804 cipherdata.algmode = OP_ALG_AAI_CBC;
805 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
806 ctxt->iv.length = AES_CBC_IV_LEN;
808 case RTE_CRYPTO_CIPHER_3DES_CBC:
809 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
810 cipherdata.algmode = OP_ALG_AAI_CBC;
811 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
812 ctxt->iv.length = TDES_CBC_IV_LEN;
814 case RTE_CRYPTO_CIPHER_AES_CTR:
815 case RTE_CRYPTO_CIPHER_3DES_CTR:
816 case RTE_CRYPTO_CIPHER_AES_GCM:
817 case RTE_CRYPTO_CIPHER_AES_CCM:
818 case RTE_CRYPTO_CIPHER_AES_ECB:
819 case RTE_CRYPTO_CIPHER_3DES_ECB:
820 case RTE_CRYPTO_CIPHER_AES_XTS:
821 case RTE_CRYPTO_CIPHER_AES_F8:
822 case RTE_CRYPTO_CIPHER_ARC4:
823 case RTE_CRYPTO_CIPHER_KASUMI_F8:
824 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
825 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
826 case RTE_CRYPTO_CIPHER_NULL:
827 RTE_LOG(ERR, PMD, "Crypto: Unsupported Cipher alg %u",
831 RTE_LOG(ERR, PMD, "Crypto: Undefined Cipher specified %u\n",
835 session->dir = (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
838 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
839 &cipherdata, NULL, ctxt->iv.length,
842 RTE_LOG(ERR, PMD, "Crypto: Descriptor build failed\n");
847 flc->mode_bits = 0x8000;
849 flc->word1_sdl = (uint8_t)bufsize;
850 flc->word2_rflc_31_0 = lower_32_bits(
851 (uint64_t)&(((struct dpaa2_sec_qp *)
852 dev->data->queue_pairs[0])->rx_vq));
853 flc->word3_rflc_63_32 = upper_32_bits(
854 (uint64_t)&(((struct dpaa2_sec_qp *)
855 dev->data->queue_pairs[0])->rx_vq));
856 session->ctxt = priv;
858 for (i = 0; i < bufsize; i++)
859 PMD_DRV_LOG(DEBUG, "DESC[%d]:0x%x\n",
860 i, priv->flc_desc[0].desc[i]);
865 rte_free(session->cipher_key.data);
871 dpaa2_sec_auth_init(struct rte_cryptodev *dev,
872 struct rte_crypto_sym_xform *xform,
873 dpaa2_sec_session *session)
875 struct dpaa2_sec_auth_ctxt *ctxt = &session->ext_params.auth_ctxt;
876 struct alginfo authdata;
877 unsigned int bufsize;
878 struct ctxt_priv *priv;
879 struct sec_flow_context *flc;
881 PMD_INIT_FUNC_TRACE();
883 /* For SEC AUTH three descriptors are required for various stages */
884 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
885 sizeof(struct ctxt_priv) + 3 *
886 sizeof(struct sec_flc_desc),
887 RTE_CACHE_LINE_SIZE);
889 RTE_LOG(ERR, PMD, "No Memory for priv CTXT");
893 flc = &priv->flc_desc[DESC_INITFINAL].flc;
895 session->auth_key.data = rte_zmalloc(NULL, xform->auth.key.length,
896 RTE_CACHE_LINE_SIZE);
897 if (session->auth_key.data == NULL) {
898 RTE_LOG(ERR, PMD, "No Memory for auth key");
902 session->auth_key.length = xform->auth.key.length;
904 memcpy(session->auth_key.data, xform->auth.key.data,
905 xform->auth.key.length);
906 authdata.key = (uint64_t)session->auth_key.data;
907 authdata.keylen = session->auth_key.length;
908 authdata.key_enc_flags = 0;
909 authdata.key_type = RTA_DATA_IMM;
911 switch (xform->auth.algo) {
912 case RTE_CRYPTO_AUTH_SHA1_HMAC:
913 authdata.algtype = OP_ALG_ALGSEL_SHA1;
914 authdata.algmode = OP_ALG_AAI_HMAC;
915 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
917 case RTE_CRYPTO_AUTH_MD5_HMAC:
918 authdata.algtype = OP_ALG_ALGSEL_MD5;
919 authdata.algmode = OP_ALG_AAI_HMAC;
920 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
922 case RTE_CRYPTO_AUTH_SHA256_HMAC:
923 authdata.algtype = OP_ALG_ALGSEL_SHA256;
924 authdata.algmode = OP_ALG_AAI_HMAC;
925 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
927 case RTE_CRYPTO_AUTH_SHA384_HMAC:
928 authdata.algtype = OP_ALG_ALGSEL_SHA384;
929 authdata.algmode = OP_ALG_AAI_HMAC;
930 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
932 case RTE_CRYPTO_AUTH_SHA512_HMAC:
933 authdata.algtype = OP_ALG_ALGSEL_SHA512;
934 authdata.algmode = OP_ALG_AAI_HMAC;
935 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
937 case RTE_CRYPTO_AUTH_SHA224_HMAC:
938 authdata.algtype = OP_ALG_ALGSEL_SHA224;
939 authdata.algmode = OP_ALG_AAI_HMAC;
940 session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
942 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
943 case RTE_CRYPTO_AUTH_AES_GCM:
944 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
945 case RTE_CRYPTO_AUTH_NULL:
946 case RTE_CRYPTO_AUTH_SHA1:
947 case RTE_CRYPTO_AUTH_SHA256:
948 case RTE_CRYPTO_AUTH_SHA512:
949 case RTE_CRYPTO_AUTH_SHA224:
950 case RTE_CRYPTO_AUTH_SHA384:
951 case RTE_CRYPTO_AUTH_MD5:
952 case RTE_CRYPTO_AUTH_AES_CCM:
953 case RTE_CRYPTO_AUTH_AES_GMAC:
954 case RTE_CRYPTO_AUTH_KASUMI_F9:
955 case RTE_CRYPTO_AUTH_AES_CMAC:
956 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
957 case RTE_CRYPTO_AUTH_ZUC_EIA3:
958 RTE_LOG(ERR, PMD, "Crypto: Unsupported auth alg %u",
962 RTE_LOG(ERR, PMD, "Crypto: Undefined Auth specified %u\n",
966 session->dir = (xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE) ?
969 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
970 1, 0, &authdata, !session->dir,
973 flc->word1_sdl = (uint8_t)bufsize;
974 flc->word2_rflc_31_0 = lower_32_bits(
975 (uint64_t)&(((struct dpaa2_sec_qp *)
976 dev->data->queue_pairs[0])->rx_vq));
977 flc->word3_rflc_63_32 = upper_32_bits(
978 (uint64_t)&(((struct dpaa2_sec_qp *)
979 dev->data->queue_pairs[0])->rx_vq));
980 session->ctxt = priv;
985 rte_free(session->auth_key.data);
991 dpaa2_sec_aead_init(struct rte_cryptodev *dev,
992 struct rte_crypto_sym_xform *xform,
993 dpaa2_sec_session *session)
995 struct dpaa2_sec_aead_ctxt *ctxt = &session->ext_params.aead_ctxt;
996 struct alginfo authdata, cipherdata;
997 unsigned int bufsize;
998 struct ctxt_priv *priv;
999 struct sec_flow_context *flc;
1000 struct rte_crypto_cipher_xform *cipher_xform;
1001 struct rte_crypto_auth_xform *auth_xform;
1004 PMD_INIT_FUNC_TRACE();
1006 if (session->ext_params.aead_ctxt.auth_cipher_text) {
1007 cipher_xform = &xform->cipher;
1008 auth_xform = &xform->next->auth;
1009 session->ctxt_type =
1010 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
1011 DPAA2_SEC_CIPHER_HASH : DPAA2_SEC_HASH_CIPHER;
1013 cipher_xform = &xform->next->cipher;
1014 auth_xform = &xform->auth;
1015 session->ctxt_type =
1016 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
1017 DPAA2_SEC_HASH_CIPHER : DPAA2_SEC_CIPHER_HASH;
1019 /* For SEC AEAD only one descriptor is required */
1020 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
1021 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
1022 RTE_CACHE_LINE_SIZE);
1024 RTE_LOG(ERR, PMD, "No Memory for priv CTXT");
1028 flc = &priv->flc_desc[0].flc;
1030 session->cipher_key.data = rte_zmalloc(NULL, cipher_xform->key.length,
1031 RTE_CACHE_LINE_SIZE);
1032 if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) {
1033 RTE_LOG(ERR, PMD, "No Memory for cipher key");
1037 session->cipher_key.length = cipher_xform->key.length;
1038 session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length,
1039 RTE_CACHE_LINE_SIZE);
1040 if (session->auth_key.data == NULL && auth_xform->key.length > 0) {
1041 RTE_LOG(ERR, PMD, "No Memory for auth key");
1042 rte_free(session->cipher_key.data);
1046 session->auth_key.length = auth_xform->key.length;
1047 memcpy(session->cipher_key.data, cipher_xform->key.data,
1048 cipher_xform->key.length);
1049 memcpy(session->auth_key.data, auth_xform->key.data,
1050 auth_xform->key.length);
1052 ctxt->trunc_len = auth_xform->digest_length;
1053 authdata.key = (uint64_t)session->auth_key.data;
1054 authdata.keylen = session->auth_key.length;
1055 authdata.key_enc_flags = 0;
1056 authdata.key_type = RTA_DATA_IMM;
1058 switch (auth_xform->algo) {
1059 case RTE_CRYPTO_AUTH_SHA1_HMAC:
1060 authdata.algtype = OP_ALG_ALGSEL_SHA1;
1061 authdata.algmode = OP_ALG_AAI_HMAC;
1062 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
1064 case RTE_CRYPTO_AUTH_MD5_HMAC:
1065 authdata.algtype = OP_ALG_ALGSEL_MD5;
1066 authdata.algmode = OP_ALG_AAI_HMAC;
1067 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
1069 case RTE_CRYPTO_AUTH_SHA224_HMAC:
1070 authdata.algtype = OP_ALG_ALGSEL_SHA224;
1071 authdata.algmode = OP_ALG_AAI_HMAC;
1072 session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
1074 case RTE_CRYPTO_AUTH_SHA256_HMAC:
1075 authdata.algtype = OP_ALG_ALGSEL_SHA256;
1076 authdata.algmode = OP_ALG_AAI_HMAC;
1077 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
1079 case RTE_CRYPTO_AUTH_SHA384_HMAC:
1080 authdata.algtype = OP_ALG_ALGSEL_SHA384;
1081 authdata.algmode = OP_ALG_AAI_HMAC;
1082 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
1084 case RTE_CRYPTO_AUTH_SHA512_HMAC:
1085 authdata.algtype = OP_ALG_ALGSEL_SHA512;
1086 authdata.algmode = OP_ALG_AAI_HMAC;
1087 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
1089 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
1090 case RTE_CRYPTO_AUTH_AES_GCM:
1091 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
1092 case RTE_CRYPTO_AUTH_NULL:
1093 case RTE_CRYPTO_AUTH_SHA1:
1094 case RTE_CRYPTO_AUTH_SHA256:
1095 case RTE_CRYPTO_AUTH_SHA512:
1096 case RTE_CRYPTO_AUTH_SHA224:
1097 case RTE_CRYPTO_AUTH_SHA384:
1098 case RTE_CRYPTO_AUTH_MD5:
1099 case RTE_CRYPTO_AUTH_AES_CCM:
1100 case RTE_CRYPTO_AUTH_AES_GMAC:
1101 case RTE_CRYPTO_AUTH_KASUMI_F9:
1102 case RTE_CRYPTO_AUTH_AES_CMAC:
1103 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
1104 case RTE_CRYPTO_AUTH_ZUC_EIA3:
1105 RTE_LOG(ERR, PMD, "Crypto: Unsupported auth alg %u",
1109 RTE_LOG(ERR, PMD, "Crypto: Undefined Auth specified %u\n",
1113 cipherdata.key = (uint64_t)session->cipher_key.data;
1114 cipherdata.keylen = session->cipher_key.length;
1115 cipherdata.key_enc_flags = 0;
1116 cipherdata.key_type = RTA_DATA_IMM;
1118 switch (cipher_xform->algo) {
1119 case RTE_CRYPTO_CIPHER_AES_CBC:
1120 cipherdata.algtype = OP_ALG_ALGSEL_AES;
1121 cipherdata.algmode = OP_ALG_AAI_CBC;
1122 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
1123 ctxt->iv.length = AES_CBC_IV_LEN;
1125 case RTE_CRYPTO_CIPHER_3DES_CBC:
1126 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
1127 cipherdata.algmode = OP_ALG_AAI_CBC;
1128 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
1129 ctxt->iv.length = TDES_CBC_IV_LEN;
1131 case RTE_CRYPTO_CIPHER_AES_GCM:
1132 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
1133 case RTE_CRYPTO_CIPHER_NULL:
1134 case RTE_CRYPTO_CIPHER_3DES_ECB:
1135 case RTE_CRYPTO_CIPHER_AES_ECB:
1136 case RTE_CRYPTO_CIPHER_AES_CTR:
1137 case RTE_CRYPTO_CIPHER_AES_CCM:
1138 case RTE_CRYPTO_CIPHER_KASUMI_F8:
1139 RTE_LOG(ERR, PMD, "Crypto: Unsupported Cipher alg %u",
1140 cipher_xform->algo);
1143 RTE_LOG(ERR, PMD, "Crypto: Undefined Cipher specified %u\n",
1144 cipher_xform->algo);
1147 session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
1150 priv->flc_desc[0].desc[0] = cipherdata.keylen;
1151 priv->flc_desc[0].desc[1] = authdata.keylen;
1152 err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
1154 (unsigned int *)priv->flc_desc[0].desc,
1155 &priv->flc_desc[0].desc[2], 2);
1158 PMD_DRV_LOG(ERR, "Crypto: Incorrect key lengths");
1161 if (priv->flc_desc[0].desc[2] & 1) {
1162 cipherdata.key_type = RTA_DATA_IMM;
1164 cipherdata.key = DPAA2_VADDR_TO_IOVA(cipherdata.key);
1165 cipherdata.key_type = RTA_DATA_PTR;
1167 if (priv->flc_desc[0].desc[2] & (1 << 1)) {
1168 authdata.key_type = RTA_DATA_IMM;
1170 authdata.key = DPAA2_VADDR_TO_IOVA(authdata.key);
1171 authdata.key_type = RTA_DATA_PTR;
1173 priv->flc_desc[0].desc[0] = 0;
1174 priv->flc_desc[0].desc[1] = 0;
1175 priv->flc_desc[0].desc[2] = 0;
1177 if (session->ctxt_type == DPAA2_SEC_CIPHER_HASH) {
1178 bufsize = cnstr_shdsc_authenc(priv->flc_desc[0].desc, 1,
1179 0, &cipherdata, &authdata,
1181 ctxt->auth_only_len,
1185 RTE_LOG(ERR, PMD, "Hash before cipher not supported");
1189 flc->word1_sdl = (uint8_t)bufsize;
1190 flc->word2_rflc_31_0 = lower_32_bits(
1191 (uint64_t)&(((struct dpaa2_sec_qp *)
1192 dev->data->queue_pairs[0])->rx_vq));
1193 flc->word3_rflc_63_32 = upper_32_bits(
1194 (uint64_t)&(((struct dpaa2_sec_qp *)
1195 dev->data->queue_pairs[0])->rx_vq));
1196 session->ctxt = priv;
1201 rte_free(session->cipher_key.data);
1202 rte_free(session->auth_key.data);
1208 dpaa2_sec_session_configure(struct rte_cryptodev *dev,
1209 struct rte_crypto_sym_xform *xform, void *sess)
1211 dpaa2_sec_session *session = sess;
1213 PMD_INIT_FUNC_TRACE();
1215 if (unlikely(sess == NULL)) {
1216 RTE_LOG(ERR, PMD, "invalid session struct");
1220 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
1221 session->ctxt_type = DPAA2_SEC_CIPHER;
1222 dpaa2_sec_cipher_init(dev, xform, session);
1224 /* Authentication Only */
1225 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
1226 xform->next == NULL) {
1227 session->ctxt_type = DPAA2_SEC_AUTH;
1228 dpaa2_sec_auth_init(dev, xform, session);
1230 /* Cipher then Authenticate */
1231 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
1232 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
1233 session->ext_params.aead_ctxt.auth_cipher_text = true;
1234 dpaa2_sec_aead_init(dev, xform, session);
1236 /* Authenticate then Cipher */
1237 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
1238 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
1239 session->ext_params.aead_ctxt.auth_cipher_text = false;
1240 dpaa2_sec_aead_init(dev, xform, session);
1242 RTE_LOG(ERR, PMD, "Invalid crypto type");
1249 /** Clear the memory of session so it doesn't leave key material behind */
1251 dpaa2_sec_session_clear(struct rte_cryptodev *dev __rte_unused, void *sess)
1253 PMD_INIT_FUNC_TRACE();
1254 dpaa2_sec_session *s = (dpaa2_sec_session *)sess;
1258 rte_free(s->cipher_key.data);
1259 rte_free(s->auth_key.data);
1260 memset(sess, 0, sizeof(dpaa2_sec_session));
1265 dpaa2_sec_dev_configure(struct rte_cryptodev *dev __rte_unused,
1266 struct rte_cryptodev_config *config __rte_unused)
1268 PMD_INIT_FUNC_TRACE();
1274 dpaa2_sec_dev_start(struct rte_cryptodev *dev)
1276 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
1277 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
1278 struct dpseci_attr attr;
1279 struct dpaa2_queue *dpaa2_q;
1280 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
1281 dev->data->queue_pairs;
1282 struct dpseci_rx_queue_attr rx_attr;
1283 struct dpseci_tx_queue_attr tx_attr;
1286 PMD_INIT_FUNC_TRACE();
1288 memset(&attr, 0, sizeof(struct dpseci_attr));
1290 ret = dpseci_enable(dpseci, CMD_PRI_LOW, priv->token);
1292 PMD_INIT_LOG(ERR, "DPSECI with HW_ID = %d ENABLE FAILED\n",
1294 goto get_attr_failure;
1296 ret = dpseci_get_attributes(dpseci, CMD_PRI_LOW, priv->token, &attr);
1299 "DPSEC ATTRIBUTE READ FAILED, disabling DPSEC\n");
1300 goto get_attr_failure;
1302 for (i = 0; i < attr.num_rx_queues && qp[i]; i++) {
1303 dpaa2_q = &qp[i]->rx_vq;
1304 dpseci_get_rx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
1306 dpaa2_q->fqid = rx_attr.fqid;
1307 PMD_INIT_LOG(DEBUG, "rx_fqid: %d", dpaa2_q->fqid);
1309 for (i = 0; i < attr.num_tx_queues && qp[i]; i++) {
1310 dpaa2_q = &qp[i]->tx_vq;
1311 dpseci_get_tx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
1313 dpaa2_q->fqid = tx_attr.fqid;
1314 PMD_INIT_LOG(DEBUG, "tx_fqid: %d", dpaa2_q->fqid);
1319 dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
1324 dpaa2_sec_dev_stop(struct rte_cryptodev *dev)
1326 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
1327 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
1330 PMD_INIT_FUNC_TRACE();
1332 ret = dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
1334 PMD_INIT_LOG(ERR, "Failure in disabling dpseci %d device",
1339 ret = dpseci_reset(dpseci, CMD_PRI_LOW, priv->token);
1341 PMD_INIT_LOG(ERR, "SEC Device cannot be reset:Error = %0x\n",
1348 dpaa2_sec_dev_close(struct rte_cryptodev *dev)
1350 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
1351 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
1354 PMD_INIT_FUNC_TRACE();
1356 /* Function is reverse of dpaa2_sec_dev_init.
1357 * It does the following:
1358 * 1. Detach a DPSECI from attached resources i.e. buffer pools, dpbp_id
1359 * 2. Close the DPSECI device
1360 * 3. Free the allocated resources.
1363 /*Close the device at underlying layer*/
1364 ret = dpseci_close(dpseci, CMD_PRI_LOW, priv->token);
1366 PMD_INIT_LOG(ERR, "Failure closing dpseci device with"
1367 " error code %d\n", ret);
1371 /*Free the allocated memory for ethernet private data and dpseci*/
1379 dpaa2_sec_dev_infos_get(struct rte_cryptodev *dev,
1380 struct rte_cryptodev_info *info)
1382 struct dpaa2_sec_dev_private *internals = dev->data->dev_private;
1384 PMD_INIT_FUNC_TRACE();
1386 info->max_nb_queue_pairs = internals->max_nb_queue_pairs;
1387 info->feature_flags = dev->feature_flags;
1388 info->capabilities = dpaa2_sec_capabilities;
1389 info->sym.max_nb_sessions = internals->max_nb_sessions;
1390 info->dev_type = RTE_CRYPTODEV_DPAA2_SEC_PMD;
1395 void dpaa2_sec_stats_get(struct rte_cryptodev *dev,
1396 struct rte_cryptodev_stats *stats)
1398 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
1399 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
1400 struct dpseci_sec_counters counters = {0};
1401 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
1402 dev->data->queue_pairs;
1405 PMD_INIT_FUNC_TRACE();
1406 if (stats == NULL) {
1407 PMD_DRV_LOG(ERR, "invalid stats ptr NULL");
1410 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
1411 if (qp[i] == NULL) {
1412 PMD_DRV_LOG(DEBUG, "Uninitialised queue pair");
1416 stats->enqueued_count += qp[i]->tx_vq.tx_pkts;
1417 stats->dequeued_count += qp[i]->rx_vq.rx_pkts;
1418 stats->enqueue_err_count += qp[i]->tx_vq.err_pkts;
1419 stats->dequeue_err_count += qp[i]->rx_vq.err_pkts;
1422 ret = dpseci_get_sec_counters(dpseci, CMD_PRI_LOW, priv->token,
1425 PMD_DRV_LOG(ERR, "dpseci_get_sec_counters failed\n");
1427 PMD_DRV_LOG(INFO, "dpseci hw stats:"
1428 "\n\tNumber of Requests Dequeued = %lu"
1429 "\n\tNumber of Outbound Encrypt Requests = %lu"
1430 "\n\tNumber of Inbound Decrypt Requests = %lu"
1431 "\n\tNumber of Outbound Bytes Encrypted = %lu"
1432 "\n\tNumber of Outbound Bytes Protected = %lu"
1433 "\n\tNumber of Inbound Bytes Decrypted = %lu"
1434 "\n\tNumber of Inbound Bytes Validated = %lu",
1435 counters.dequeued_requests,
1436 counters.ob_enc_requests,
1437 counters.ib_dec_requests,
1438 counters.ob_enc_bytes,
1439 counters.ob_prot_bytes,
1440 counters.ib_dec_bytes,
1441 counters.ib_valid_bytes);
1446 void dpaa2_sec_stats_reset(struct rte_cryptodev *dev)
1449 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
1450 (dev->data->queue_pairs);
1452 PMD_INIT_FUNC_TRACE();
1454 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
1455 if (qp[i] == NULL) {
1456 PMD_DRV_LOG(DEBUG, "Uninitialised queue pair");
1459 qp[i]->tx_vq.rx_pkts = 0;
1460 qp[i]->tx_vq.tx_pkts = 0;
1461 qp[i]->tx_vq.err_pkts = 0;
1462 qp[i]->rx_vq.rx_pkts = 0;
1463 qp[i]->rx_vq.tx_pkts = 0;
1464 qp[i]->rx_vq.err_pkts = 0;
1468 static struct rte_cryptodev_ops crypto_ops = {
1469 .dev_configure = dpaa2_sec_dev_configure,
1470 .dev_start = dpaa2_sec_dev_start,
1471 .dev_stop = dpaa2_sec_dev_stop,
1472 .dev_close = dpaa2_sec_dev_close,
1473 .dev_infos_get = dpaa2_sec_dev_infos_get,
1474 .stats_get = dpaa2_sec_stats_get,
1475 .stats_reset = dpaa2_sec_stats_reset,
1476 .queue_pair_setup = dpaa2_sec_queue_pair_setup,
1477 .queue_pair_release = dpaa2_sec_queue_pair_release,
1478 .queue_pair_start = dpaa2_sec_queue_pair_start,
1479 .queue_pair_stop = dpaa2_sec_queue_pair_stop,
1480 .queue_pair_count = dpaa2_sec_queue_pair_count,
1481 .session_get_size = dpaa2_sec_session_get_size,
1482 .session_initialize = dpaa2_sec_session_initialize,
1483 .session_configure = dpaa2_sec_session_configure,
1484 .session_clear = dpaa2_sec_session_clear,
1488 dpaa2_sec_uninit(const struct rte_cryptodev *dev)
1490 PMD_INIT_LOG(INFO, "Closing DPAA2_SEC device %s on numa socket %u\n",
1491 dev->data->name, rte_socket_id());
1497 dpaa2_sec_dev_init(struct rte_cryptodev *cryptodev)
1499 struct dpaa2_sec_dev_private *internals;
1500 struct rte_device *dev = cryptodev->device;
1501 struct rte_dpaa2_device *dpaa2_dev;
1502 struct fsl_mc_io *dpseci;
1504 struct dpseci_attr attr;
1507 PMD_INIT_FUNC_TRACE();
1508 dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
1509 if (dpaa2_dev == NULL) {
1510 PMD_INIT_LOG(ERR, "dpaa2_device not found\n");
1513 hw_id = dpaa2_dev->object_id;
1515 cryptodev->dev_type = RTE_CRYPTODEV_DPAA2_SEC_PMD;
1516 cryptodev->dev_ops = &crypto_ops;
1518 cryptodev->enqueue_burst = dpaa2_sec_enqueue_burst;
1519 cryptodev->dequeue_burst = dpaa2_sec_dequeue_burst;
1520 cryptodev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
1521 RTE_CRYPTODEV_FF_HW_ACCELERATED |
1522 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING;
1524 internals = cryptodev->data->dev_private;
1525 internals->max_nb_sessions = RTE_DPAA2_SEC_PMD_MAX_NB_SESSIONS;
1528 * For secondary processes, we don't initialise any further as primary
1529 * has already done this work. Only check we don't need a different
1532 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1533 PMD_INIT_LOG(DEBUG, "Device already init by primary process");
1536 /*Open the rte device via MC and save the handle for further use*/
1537 dpseci = (struct fsl_mc_io *)rte_calloc(NULL, 1,
1538 sizeof(struct fsl_mc_io), 0);
1541 "Error in allocating the memory for dpsec object");
1544 dpseci->regs = rte_mcp_ptr_list[0];
1546 retcode = dpseci_open(dpseci, CMD_PRI_LOW, hw_id, &token);
1548 PMD_INIT_LOG(ERR, "Cannot open the dpsec device: Error = %x",
1552 retcode = dpseci_get_attributes(dpseci, CMD_PRI_LOW, token, &attr);
1555 "Cannot get dpsec device attributed: Error = %x",
1559 sprintf(cryptodev->data->name, "dpsec-%u", hw_id);
1561 internals->max_nb_queue_pairs = attr.num_tx_queues;
1562 cryptodev->data->nb_queue_pairs = internals->max_nb_queue_pairs;
1563 internals->hw = dpseci;
1564 internals->token = token;
1566 PMD_INIT_LOG(DEBUG, "driver %s: created\n", cryptodev->data->name);
1570 PMD_INIT_LOG(ERR, "driver %s: create failed\n", cryptodev->data->name);
1572 /* dpaa2_sec_uninit(crypto_dev_name); */
1577 cryptodev_dpaa2_sec_probe(struct rte_dpaa2_driver *dpaa2_drv __rte_unused,
1578 struct rte_dpaa2_device *dpaa2_dev)
1580 struct rte_cryptodev *cryptodev;
1581 char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
1585 sprintf(cryptodev_name, "dpsec-%d", dpaa2_dev->object_id);
1587 cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
1588 if (cryptodev == NULL)
1591 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1592 cryptodev->data->dev_private = rte_zmalloc_socket(
1593 "cryptodev private structure",
1594 sizeof(struct dpaa2_sec_dev_private),
1595 RTE_CACHE_LINE_SIZE,
1598 if (cryptodev->data->dev_private == NULL)
1599 rte_panic("Cannot allocate memzone for private "
1603 dpaa2_dev->cryptodev = cryptodev;
1604 cryptodev->device = &dpaa2_dev->device;
1606 /* init user callbacks */
1607 TAILQ_INIT(&(cryptodev->link_intr_cbs));
1609 /* Invoke PMD device initialization function */
1610 retval = dpaa2_sec_dev_init(cryptodev);
1614 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1615 rte_free(cryptodev->data->dev_private);
1617 cryptodev->attached = RTE_CRYPTODEV_DETACHED;
1623 cryptodev_dpaa2_sec_remove(struct rte_dpaa2_device *dpaa2_dev)
1625 struct rte_cryptodev *cryptodev;
1628 cryptodev = dpaa2_dev->cryptodev;
1629 if (cryptodev == NULL)
1632 ret = dpaa2_sec_uninit(cryptodev);
1636 /* free crypto device */
1637 rte_cryptodev_pmd_release_device(cryptodev);
1639 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1640 rte_free(cryptodev->data->dev_private);
1642 cryptodev->device = NULL;
1643 cryptodev->data = NULL;
1648 static struct rte_dpaa2_driver rte_dpaa2_sec_driver = {
1649 .drv_type = DPAA2_MC_DPSECI_DEVID,
1651 .name = "DPAA2 SEC PMD"
1653 .probe = cryptodev_dpaa2_sec_probe,
1654 .remove = cryptodev_dpaa2_sec_remove,
1657 RTE_PMD_REGISTER_DPAA2(dpaa2_sec_pmd, rte_dpaa2_sec_driver);