4 * Copyright (c) 2016 Freescale Semiconductor, Inc. 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 /* FLE_POOL_NUM_BUFS is set as per the ipsec-secgw application */
73 #define FLE_POOL_NUM_BUFS 32000
74 #define FLE_POOL_BUF_SIZE 256
75 #define FLE_POOL_CACHE_SIZE 512
77 enum rta_sec_era rta_sec_era = RTA_SEC_ERA_8;
79 static uint8_t cryptodev_driver_id;
82 build_authenc_gcm_fd(dpaa2_sec_session *sess,
83 struct rte_crypto_op *op,
84 struct qbman_fd *fd, uint16_t bpid)
86 struct rte_crypto_sym_op *sym_op = op->sym;
87 struct ctxt_priv *priv = sess->ctxt;
88 struct qbman_fle *fle, *sge;
89 struct sec_flow_context *flc;
90 uint32_t auth_only_len = sess->ext_params.aead_ctxt.auth_only_len;
91 int icv_len = sess->digest_length, retval;
93 uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
96 PMD_INIT_FUNC_TRACE();
98 /* TODO we are using the first FLE entry to store Mbuf and session ctxt.
99 * Currently we donot know which FLE has the mbuf stored.
100 * So while retreiving we can go back 1 FLE from the FD -ADDR
101 * to get the MBUF Addr from the previous FLE.
102 * We can have a better approach to use the inline Mbuf
104 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
106 RTE_LOG(ERR, PMD, "Memory alloc failed for SGE\n");
109 memset(fle, 0, FLE_POOL_BUF_SIZE);
110 DPAA2_SET_FLE_ADDR(fle, DPAA2_OP_VADDR_TO_IOVA(op));
111 DPAA2_FLE_SAVE_CTXT(fle, priv);
114 if (likely(bpid < MAX_BPID)) {
115 DPAA2_SET_FD_BPID(fd, bpid);
116 DPAA2_SET_FLE_BPID(fle, bpid);
117 DPAA2_SET_FLE_BPID(fle + 1, bpid);
118 DPAA2_SET_FLE_BPID(sge, bpid);
119 DPAA2_SET_FLE_BPID(sge + 1, bpid);
120 DPAA2_SET_FLE_BPID(sge + 2, bpid);
121 DPAA2_SET_FLE_BPID(sge + 3, bpid);
123 DPAA2_SET_FD_IVP(fd);
124 DPAA2_SET_FLE_IVP(fle);
125 DPAA2_SET_FLE_IVP((fle + 1));
126 DPAA2_SET_FLE_IVP(sge);
127 DPAA2_SET_FLE_IVP((sge + 1));
128 DPAA2_SET_FLE_IVP((sge + 2));
129 DPAA2_SET_FLE_IVP((sge + 3));
132 /* Save the shared descriptor */
133 flc = &priv->flc_desc[0].flc;
134 /* Configure FD as a FRAME LIST */
135 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
136 DPAA2_SET_FD_COMPOUND_FMT(fd);
137 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
139 PMD_TX_LOG(DEBUG, "auth_off: 0x%x/length %d, digest-len=%d\n"
140 "iv-len=%d data_off: 0x%x\n",
141 sym_op->aead.data.offset,
142 sym_op->aead.data.length,
143 sym_op->aead.digest.length,
145 sym_op->m_src->data_off);
147 /* Configure Output FLE with Scatter/Gather Entry */
148 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
150 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
151 fle->length = (sess->dir == DIR_ENC) ?
152 (sym_op->aead.data.length + icv_len + auth_only_len) :
153 sym_op->aead.data.length + auth_only_len;
155 DPAA2_SET_FLE_SG_EXT(fle);
157 /* Configure Output SGE for Encap/Decap */
158 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
159 DPAA2_SET_FLE_OFFSET(sge, sym_op->aead.data.offset +
160 sym_op->m_src->data_off - auth_only_len);
161 sge->length = sym_op->aead.data.length + auth_only_len;
163 if (sess->dir == DIR_ENC) {
165 DPAA2_SET_FLE_ADDR(sge,
166 DPAA2_VADDR_TO_IOVA(sym_op->aead.digest.data));
167 sge->length = sess->digest_length;
168 DPAA2_SET_FD_LEN(fd, (sym_op->aead.data.length +
169 sess->iv.length + auth_only_len));
171 DPAA2_SET_FLE_FIN(sge);
176 /* Configure Input FLE with Scatter/Gather Entry */
177 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
178 DPAA2_SET_FLE_SG_EXT(fle);
179 DPAA2_SET_FLE_FIN(fle);
180 fle->length = (sess->dir == DIR_ENC) ?
181 (sym_op->aead.data.length + sess->iv.length + auth_only_len) :
182 (sym_op->aead.data.length + sess->iv.length + auth_only_len +
183 sess->digest_length);
185 /* Configure Input SGE for Encap/Decap */
186 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(IV_ptr));
187 sge->length = sess->iv.length;
190 DPAA2_SET_FLE_ADDR(sge,
191 DPAA2_VADDR_TO_IOVA(sym_op->aead.aad.data));
192 sge->length = auth_only_len;
193 DPAA2_SET_FLE_BPID(sge, bpid);
197 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
198 DPAA2_SET_FLE_OFFSET(sge, sym_op->aead.data.offset +
199 sym_op->m_src->data_off);
200 sge->length = sym_op->aead.data.length;
201 if (sess->dir == DIR_DEC) {
203 old_icv = (uint8_t *)(sge + 1);
204 memcpy(old_icv, sym_op->aead.digest.data,
205 sess->digest_length);
206 memset(sym_op->aead.digest.data, 0, sess->digest_length);
207 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
208 sge->length = sess->digest_length;
209 DPAA2_SET_FD_LEN(fd, (sym_op->aead.data.length +
210 sess->digest_length +
214 DPAA2_SET_FLE_FIN(sge);
217 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
218 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
225 build_authenc_fd(dpaa2_sec_session *sess,
226 struct rte_crypto_op *op,
227 struct qbman_fd *fd, uint16_t bpid)
229 struct rte_crypto_sym_op *sym_op = op->sym;
230 struct ctxt_priv *priv = sess->ctxt;
231 struct qbman_fle *fle, *sge;
232 struct sec_flow_context *flc;
233 uint32_t auth_only_len = sym_op->auth.data.length -
234 sym_op->cipher.data.length;
235 int icv_len = sess->digest_length, retval;
237 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
240 PMD_INIT_FUNC_TRACE();
242 /* we are using the first FLE entry to store Mbuf.
243 * Currently we donot know which FLE has the mbuf stored.
244 * So while retreiving we can go back 1 FLE from the FD -ADDR
245 * to get the MBUF Addr from the previous FLE.
246 * We can have a better approach to use the inline Mbuf
248 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
250 RTE_LOG(ERR, PMD, "Memory alloc failed for SGE\n");
253 memset(fle, 0, FLE_POOL_BUF_SIZE);
254 DPAA2_SET_FLE_ADDR(fle, DPAA2_OP_VADDR_TO_IOVA(op));
255 DPAA2_FLE_SAVE_CTXT(fle, priv);
258 if (likely(bpid < MAX_BPID)) {
259 DPAA2_SET_FD_BPID(fd, bpid);
260 DPAA2_SET_FLE_BPID(fle, bpid);
261 DPAA2_SET_FLE_BPID(fle + 1, bpid);
262 DPAA2_SET_FLE_BPID(sge, bpid);
263 DPAA2_SET_FLE_BPID(sge + 1, bpid);
264 DPAA2_SET_FLE_BPID(sge + 2, bpid);
265 DPAA2_SET_FLE_BPID(sge + 3, bpid);
267 DPAA2_SET_FD_IVP(fd);
268 DPAA2_SET_FLE_IVP(fle);
269 DPAA2_SET_FLE_IVP((fle + 1));
270 DPAA2_SET_FLE_IVP(sge);
271 DPAA2_SET_FLE_IVP((sge + 1));
272 DPAA2_SET_FLE_IVP((sge + 2));
273 DPAA2_SET_FLE_IVP((sge + 3));
276 /* Save the shared descriptor */
277 flc = &priv->flc_desc[0].flc;
278 /* Configure FD as a FRAME LIST */
279 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
280 DPAA2_SET_FD_COMPOUND_FMT(fd);
281 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
283 PMD_TX_LOG(DEBUG, "auth_off: 0x%x/length %d, digest-len=%d\n"
284 "cipher_off: 0x%x/length %d, iv-len=%d data_off: 0x%x\n",
285 sym_op->auth.data.offset,
286 sym_op->auth.data.length,
288 sym_op->cipher.data.offset,
289 sym_op->cipher.data.length,
291 sym_op->m_src->data_off);
293 /* Configure Output FLE with Scatter/Gather Entry */
294 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
296 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
297 fle->length = (sess->dir == DIR_ENC) ?
298 (sym_op->cipher.data.length + icv_len) :
299 sym_op->cipher.data.length;
301 DPAA2_SET_FLE_SG_EXT(fle);
303 /* Configure Output SGE for Encap/Decap */
304 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
305 DPAA2_SET_FLE_OFFSET(sge, sym_op->cipher.data.offset +
306 sym_op->m_src->data_off);
307 sge->length = sym_op->cipher.data.length;
309 if (sess->dir == DIR_ENC) {
311 DPAA2_SET_FLE_ADDR(sge,
312 DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
313 sge->length = sess->digest_length;
314 DPAA2_SET_FD_LEN(fd, (sym_op->auth.data.length +
317 DPAA2_SET_FLE_FIN(sge);
322 /* Configure Input FLE with Scatter/Gather Entry */
323 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
324 DPAA2_SET_FLE_SG_EXT(fle);
325 DPAA2_SET_FLE_FIN(fle);
326 fle->length = (sess->dir == DIR_ENC) ?
327 (sym_op->auth.data.length + sess->iv.length) :
328 (sym_op->auth.data.length + sess->iv.length +
329 sess->digest_length);
331 /* Configure Input SGE for Encap/Decap */
332 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
333 sge->length = sess->iv.length;
336 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
337 DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset +
338 sym_op->m_src->data_off);
339 sge->length = sym_op->auth.data.length;
340 if (sess->dir == DIR_DEC) {
342 old_icv = (uint8_t *)(sge + 1);
343 memcpy(old_icv, sym_op->auth.digest.data,
344 sess->digest_length);
345 memset(sym_op->auth.digest.data, 0, sess->digest_length);
346 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_icv));
347 sge->length = sess->digest_length;
348 DPAA2_SET_FD_LEN(fd, (sym_op->auth.data.length +
349 sess->digest_length +
352 DPAA2_SET_FLE_FIN(sge);
354 DPAA2_SET_FLE_INTERNAL_JD(fle, auth_only_len);
355 DPAA2_SET_FD_INTERNAL_JD(fd, auth_only_len);
361 build_auth_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
362 struct qbman_fd *fd, uint16_t bpid)
364 struct rte_crypto_sym_op *sym_op = op->sym;
365 struct qbman_fle *fle, *sge;
366 struct sec_flow_context *flc;
367 struct ctxt_priv *priv = sess->ctxt;
371 PMD_INIT_FUNC_TRACE();
373 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
375 RTE_LOG(ERR, PMD, "Memory alloc failed for SGE\n");
378 memset(fle, 0, FLE_POOL_BUF_SIZE);
379 /* TODO we are using the first FLE entry to store Mbuf.
380 * Currently we donot know which FLE has the mbuf stored.
381 * So while retreiving we can go back 1 FLE from the FD -ADDR
382 * to get the MBUF Addr from the previous FLE.
383 * We can have a better approach to use the inline Mbuf
385 DPAA2_SET_FLE_ADDR(fle, DPAA2_OP_VADDR_TO_IOVA(op));
386 DPAA2_FLE_SAVE_CTXT(fle, priv);
389 if (likely(bpid < MAX_BPID)) {
390 DPAA2_SET_FD_BPID(fd, bpid);
391 DPAA2_SET_FLE_BPID(fle, bpid);
392 DPAA2_SET_FLE_BPID(fle + 1, bpid);
394 DPAA2_SET_FD_IVP(fd);
395 DPAA2_SET_FLE_IVP(fle);
396 DPAA2_SET_FLE_IVP((fle + 1));
398 flc = &priv->flc_desc[DESC_INITFINAL].flc;
399 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
401 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sym_op->auth.digest.data));
402 fle->length = sess->digest_length;
404 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
405 DPAA2_SET_FD_COMPOUND_FMT(fd);
408 if (sess->dir == DIR_ENC) {
409 DPAA2_SET_FLE_ADDR(fle,
410 DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
411 DPAA2_SET_FLE_OFFSET(fle, sym_op->auth.data.offset +
412 sym_op->m_src->data_off);
413 DPAA2_SET_FD_LEN(fd, sym_op->auth.data.length);
414 fle->length = sym_op->auth.data.length;
417 DPAA2_SET_FLE_SG_EXT(fle);
418 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
420 if (likely(bpid < MAX_BPID)) {
421 DPAA2_SET_FLE_BPID(sge, bpid);
422 DPAA2_SET_FLE_BPID(sge + 1, bpid);
424 DPAA2_SET_FLE_IVP(sge);
425 DPAA2_SET_FLE_IVP((sge + 1));
427 DPAA2_SET_FLE_ADDR(sge,
428 DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
429 DPAA2_SET_FLE_OFFSET(sge, sym_op->auth.data.offset +
430 sym_op->m_src->data_off);
432 DPAA2_SET_FD_LEN(fd, sym_op->auth.data.length +
433 sess->digest_length);
434 sge->length = sym_op->auth.data.length;
436 old_digest = (uint8_t *)(sge + 1);
437 rte_memcpy(old_digest, sym_op->auth.digest.data,
438 sess->digest_length);
439 memset(sym_op->auth.digest.data, 0, sess->digest_length);
440 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(old_digest));
441 sge->length = sess->digest_length;
442 fle->length = sym_op->auth.data.length +
444 DPAA2_SET_FLE_FIN(sge);
446 DPAA2_SET_FLE_FIN(fle);
452 build_cipher_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
453 struct qbman_fd *fd, uint16_t bpid)
455 struct rte_crypto_sym_op *sym_op = op->sym;
456 struct qbman_fle *fle, *sge;
458 struct sec_flow_context *flc;
459 struct ctxt_priv *priv = sess->ctxt;
460 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
463 PMD_INIT_FUNC_TRACE();
465 retval = rte_mempool_get(priv->fle_pool, (void **)(&fle));
467 RTE_LOG(ERR, PMD, "Memory alloc failed for SGE\n");
470 memset(fle, 0, FLE_POOL_BUF_SIZE);
471 /* TODO we are using the first FLE entry to store Mbuf.
472 * Currently we donot know which FLE has the mbuf stored.
473 * So while retreiving we can go back 1 FLE from the FD -ADDR
474 * to get the MBUF Addr from the previous FLE.
475 * We can have a better approach to use the inline Mbuf
477 DPAA2_SET_FLE_ADDR(fle, DPAA2_OP_VADDR_TO_IOVA(op));
478 DPAA2_FLE_SAVE_CTXT(fle, priv);
482 if (likely(bpid < MAX_BPID)) {
483 DPAA2_SET_FD_BPID(fd, bpid);
484 DPAA2_SET_FLE_BPID(fle, bpid);
485 DPAA2_SET_FLE_BPID(fle + 1, bpid);
486 DPAA2_SET_FLE_BPID(sge, bpid);
487 DPAA2_SET_FLE_BPID(sge + 1, bpid);
489 DPAA2_SET_FD_IVP(fd);
490 DPAA2_SET_FLE_IVP(fle);
491 DPAA2_SET_FLE_IVP((fle + 1));
492 DPAA2_SET_FLE_IVP(sge);
493 DPAA2_SET_FLE_IVP((sge + 1));
496 flc = &priv->flc_desc[0].flc;
497 DPAA2_SET_FD_ADDR(fd, DPAA2_VADDR_TO_IOVA(fle));
498 DPAA2_SET_FD_LEN(fd, sym_op->cipher.data.length +
500 DPAA2_SET_FD_COMPOUND_FMT(fd);
501 DPAA2_SET_FD_FLC(fd, DPAA2_VADDR_TO_IOVA(flc));
503 PMD_TX_LOG(DEBUG, "cipher_off: 0x%x/length %d,ivlen=%d data_off: 0x%x",
504 sym_op->cipher.data.offset,
505 sym_op->cipher.data.length,
507 sym_op->m_src->data_off);
509 DPAA2_SET_FLE_ADDR(fle, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
510 DPAA2_SET_FLE_OFFSET(fle, sym_op->cipher.data.offset +
511 sym_op->m_src->data_off);
513 fle->length = sym_op->cipher.data.length + sess->iv.length;
515 PMD_TX_LOG(DEBUG, "1 - flc = %p, fle = %p FLEaddr = %x-%x, length %d",
516 flc, fle, fle->addr_hi, fle->addr_lo, fle->length);
520 DPAA2_SET_FLE_ADDR(fle, DPAA2_VADDR_TO_IOVA(sge));
521 fle->length = sym_op->cipher.data.length + sess->iv.length;
523 DPAA2_SET_FLE_SG_EXT(fle);
525 DPAA2_SET_FLE_ADDR(sge, DPAA2_VADDR_TO_IOVA(iv_ptr));
526 sge->length = sess->iv.length;
529 DPAA2_SET_FLE_ADDR(sge, DPAA2_MBUF_VADDR_TO_IOVA(sym_op->m_src));
530 DPAA2_SET_FLE_OFFSET(sge, sym_op->cipher.data.offset +
531 sym_op->m_src->data_off);
533 sge->length = sym_op->cipher.data.length;
534 DPAA2_SET_FLE_FIN(sge);
535 DPAA2_SET_FLE_FIN(fle);
537 PMD_TX_LOG(DEBUG, "fdaddr =%p bpid =%d meta =%d off =%d, len =%d",
538 (void *)DPAA2_GET_FD_ADDR(fd),
539 DPAA2_GET_FD_BPID(fd),
540 rte_dpaa2_bpid_info[bpid].meta_data_size,
541 DPAA2_GET_FD_OFFSET(fd),
542 DPAA2_GET_FD_LEN(fd));
548 build_sec_fd(dpaa2_sec_session *sess, struct rte_crypto_op *op,
549 struct qbman_fd *fd, uint16_t bpid)
553 PMD_INIT_FUNC_TRACE();
555 switch (sess->ctxt_type) {
556 case DPAA2_SEC_CIPHER:
557 ret = build_cipher_fd(sess, op, fd, bpid);
560 ret = build_auth_fd(sess, op, fd, bpid);
563 ret = build_authenc_gcm_fd(sess, op, fd, bpid);
565 case DPAA2_SEC_CIPHER_HASH:
566 ret = build_authenc_fd(sess, op, fd, bpid);
568 case DPAA2_SEC_HASH_CIPHER:
570 RTE_LOG(ERR, PMD, "error: Unsupported session\n");
576 dpaa2_sec_enqueue_burst(void *qp, struct rte_crypto_op **ops,
579 /* Function to transmit the frames to given device and VQ*/
582 struct qbman_fd fd_arr[MAX_TX_RING_SLOTS];
583 uint32_t frames_to_send;
584 struct qbman_eq_desc eqdesc;
585 struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
586 struct qbman_swp *swp;
588 /*todo - need to support multiple buffer pools */
590 struct rte_mempool *mb_pool;
591 dpaa2_sec_session *sess;
593 if (unlikely(nb_ops == 0))
596 if (ops[0]->sess_type != RTE_CRYPTO_OP_WITH_SESSION) {
597 RTE_LOG(ERR, PMD, "sessionless crypto op not supported\n");
600 /*Prepare enqueue descriptor*/
601 qbman_eq_desc_clear(&eqdesc);
602 qbman_eq_desc_set_no_orp(&eqdesc, DPAA2_EQ_RESP_ERR_FQ);
603 qbman_eq_desc_set_response(&eqdesc, 0, 0);
604 qbman_eq_desc_set_fq(&eqdesc, dpaa2_qp->tx_vq.fqid);
606 if (!DPAA2_PER_LCORE_SEC_DPIO) {
607 ret = dpaa2_affine_qbman_swp_sec();
609 RTE_LOG(ERR, PMD, "Failure in affining portal\n");
613 swp = DPAA2_PER_LCORE_SEC_PORTAL;
616 frames_to_send = (nb_ops >> 3) ? MAX_TX_RING_SLOTS : nb_ops;
618 for (loop = 0; loop < frames_to_send; loop++) {
619 /*Clear the unused FD fields before sending*/
620 memset(&fd_arr[loop], 0, sizeof(struct qbman_fd));
621 sess = (dpaa2_sec_session *)
622 get_session_private_data(
623 (*ops)->sym->session,
624 cryptodev_driver_id);
625 mb_pool = (*ops)->sym->m_src->pool;
626 bpid = mempool_to_bpid(mb_pool);
627 ret = build_sec_fd(sess, *ops, &fd_arr[loop], bpid);
629 PMD_DRV_LOG(ERR, "error: Improper packet"
630 " contents for crypto operation\n");
636 while (loop < frames_to_send) {
637 loop += qbman_swp_send_multiple(swp, &eqdesc,
639 frames_to_send - loop);
642 num_tx += frames_to_send;
643 nb_ops -= frames_to_send;
646 dpaa2_qp->tx_vq.tx_pkts += num_tx;
647 dpaa2_qp->tx_vq.err_pkts += nb_ops;
651 static inline struct rte_crypto_op *
652 sec_fd_to_mbuf(const struct qbman_fd *fd)
654 struct qbman_fle *fle;
655 struct rte_crypto_op *op;
656 struct ctxt_priv *priv;
658 fle = (struct qbman_fle *)DPAA2_IOVA_TO_VADDR(DPAA2_GET_FD_ADDR(fd));
660 PMD_RX_LOG(DEBUG, "FLE addr = %x - %x, offset = %x",
661 fle->addr_hi, fle->addr_lo, fle->fin_bpid_offset);
663 /* we are using the first FLE entry to store Mbuf.
664 * Currently we donot know which FLE has the mbuf stored.
665 * So while retreiving we can go back 1 FLE from the FD -ADDR
666 * to get the MBUF Addr from the previous FLE.
667 * We can have a better approach to use the inline Mbuf
670 if (unlikely(DPAA2_GET_FD_IVP(fd))) {
671 /* TODO complete it. */
672 RTE_LOG(ERR, PMD, "error: Non inline buffer - WHAT to DO?\n");
675 op = (struct rte_crypto_op *)DPAA2_IOVA_TO_VADDR(
676 DPAA2_GET_FLE_ADDR((fle - 1)));
679 rte_prefetch0(op->sym->m_src);
681 PMD_RX_LOG(DEBUG, "mbuf %p BMAN buf addr %p",
682 (void *)op->sym->m_src, op->sym->m_src->buf_addr);
684 PMD_RX_LOG(DEBUG, "fdaddr =%p bpid =%d meta =%d off =%d, len =%d",
685 (void *)DPAA2_GET_FD_ADDR(fd),
686 DPAA2_GET_FD_BPID(fd),
687 rte_dpaa2_bpid_info[DPAA2_GET_FD_BPID(fd)].meta_data_size,
688 DPAA2_GET_FD_OFFSET(fd),
689 DPAA2_GET_FD_LEN(fd));
691 /* free the fle memory */
692 priv = (struct ctxt_priv *)DPAA2_GET_FLE_CTXT(fle - 1);
693 rte_mempool_put(priv->fle_pool, (void *)(fle - 1));
699 dpaa2_sec_dequeue_burst(void *qp, struct rte_crypto_op **ops,
702 /* Function is responsible to receive frames for a given device and VQ*/
703 struct dpaa2_sec_qp *dpaa2_qp = (struct dpaa2_sec_qp *)qp;
704 struct qbman_result *dq_storage;
705 uint32_t fqid = dpaa2_qp->rx_vq.fqid;
707 uint8_t is_last = 0, status;
708 struct qbman_swp *swp;
709 const struct qbman_fd *fd;
710 struct qbman_pull_desc pulldesc;
712 if (!DPAA2_PER_LCORE_SEC_DPIO) {
713 ret = dpaa2_affine_qbman_swp_sec();
715 RTE_LOG(ERR, PMD, "Failure in affining portal\n");
719 swp = DPAA2_PER_LCORE_SEC_PORTAL;
720 dq_storage = dpaa2_qp->rx_vq.q_storage->dq_storage[0];
722 qbman_pull_desc_clear(&pulldesc);
723 qbman_pull_desc_set_numframes(&pulldesc,
724 (nb_ops > DPAA2_DQRR_RING_SIZE) ?
725 DPAA2_DQRR_RING_SIZE : nb_ops);
726 qbman_pull_desc_set_fq(&pulldesc, fqid);
727 qbman_pull_desc_set_storage(&pulldesc, dq_storage,
728 (dma_addr_t)DPAA2_VADDR_TO_IOVA(dq_storage),
731 /*Issue a volatile dequeue command. */
733 if (qbman_swp_pull(swp, &pulldesc)) {
734 RTE_LOG(WARNING, PMD,
735 "SEC VDQ command is not issued : QBMAN busy\n");
736 /* Portal was busy, try again */
742 /* Receive the packets till Last Dequeue entry is found with
743 * respect to the above issues PULL command.
746 /* Check if the previous issued command is completed.
747 * Also seems like the SWP is shared between the Ethernet Driver
748 * and the SEC driver.
750 while (!qbman_check_command_complete(swp, dq_storage))
753 /* Loop until the dq_storage is updated with
756 while (!qbman_result_has_new_result(swp, dq_storage))
758 /* Check whether Last Pull command is Expired and
759 * setting Condition for Loop termination
761 if (qbman_result_DQ_is_pull_complete(dq_storage)) {
763 /* Check for valid frame. */
764 status = (uint8_t)qbman_result_DQ_flags(dq_storage);
766 (status & QBMAN_DQ_STAT_VALIDFRAME) == 0)) {
767 PMD_RX_LOG(DEBUG, "No frame is delivered");
772 fd = qbman_result_DQ_fd(dq_storage);
773 ops[num_rx] = sec_fd_to_mbuf(fd);
775 if (unlikely(fd->simple.frc)) {
776 /* TODO Parse SEC errors */
777 RTE_LOG(ERR, PMD, "SEC returned Error - %x\n",
779 ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_ERROR;
781 ops[num_rx]->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
786 } /* End of Packet Rx loop */
788 dpaa2_qp->rx_vq.rx_pkts += num_rx;
790 PMD_RX_LOG(DEBUG, "SEC Received %d Packets", num_rx);
791 /*Return the total number of packets received to DPAA2 app*/
795 /** Release queue pair */
797 dpaa2_sec_queue_pair_release(struct rte_cryptodev *dev, uint16_t queue_pair_id)
799 struct dpaa2_sec_qp *qp =
800 (struct dpaa2_sec_qp *)dev->data->queue_pairs[queue_pair_id];
802 PMD_INIT_FUNC_TRACE();
804 if (qp->rx_vq.q_storage) {
805 dpaa2_free_dq_storage(qp->rx_vq.q_storage);
806 rte_free(qp->rx_vq.q_storage);
810 dev->data->queue_pairs[queue_pair_id] = NULL;
815 /** Setup a queue pair */
817 dpaa2_sec_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
818 __rte_unused const struct rte_cryptodev_qp_conf *qp_conf,
819 __rte_unused int socket_id,
820 __rte_unused struct rte_mempool *session_pool)
822 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
823 struct dpaa2_sec_qp *qp;
824 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
825 struct dpseci_rx_queue_cfg cfg;
828 PMD_INIT_FUNC_TRACE();
830 /* If qp is already in use free ring memory and qp metadata. */
831 if (dev->data->queue_pairs[qp_id] != NULL) {
832 PMD_DRV_LOG(INFO, "QP already setup");
836 PMD_DRV_LOG(DEBUG, "dev =%p, queue =%d, conf =%p",
837 dev, qp_id, qp_conf);
839 memset(&cfg, 0, sizeof(struct dpseci_rx_queue_cfg));
841 qp = rte_malloc(NULL, sizeof(struct dpaa2_sec_qp),
842 RTE_CACHE_LINE_SIZE);
844 RTE_LOG(ERR, PMD, "malloc failed for rx/tx queues\n");
850 qp->rx_vq.q_storage = rte_malloc("sec dq storage",
851 sizeof(struct queue_storage_info_t),
852 RTE_CACHE_LINE_SIZE);
853 if (!qp->rx_vq.q_storage) {
854 RTE_LOG(ERR, PMD, "malloc failed for q_storage\n");
857 memset(qp->rx_vq.q_storage, 0, sizeof(struct queue_storage_info_t));
859 if (dpaa2_alloc_dq_storage(qp->rx_vq.q_storage)) {
860 RTE_LOG(ERR, PMD, "dpaa2_alloc_dq_storage failed\n");
864 dev->data->queue_pairs[qp_id] = qp;
866 cfg.options = cfg.options | DPSECI_QUEUE_OPT_USER_CTX;
867 cfg.user_ctx = (uint64_t)(&qp->rx_vq);
868 retcode = dpseci_set_rx_queue(dpseci, CMD_PRI_LOW, priv->token,
873 /** Start queue pair */
875 dpaa2_sec_queue_pair_start(__rte_unused struct rte_cryptodev *dev,
876 __rte_unused uint16_t queue_pair_id)
878 PMD_INIT_FUNC_TRACE();
883 /** Stop queue pair */
885 dpaa2_sec_queue_pair_stop(__rte_unused struct rte_cryptodev *dev,
886 __rte_unused uint16_t queue_pair_id)
888 PMD_INIT_FUNC_TRACE();
893 /** Return the number of allocated queue pairs */
895 dpaa2_sec_queue_pair_count(struct rte_cryptodev *dev)
897 PMD_INIT_FUNC_TRACE();
899 return dev->data->nb_queue_pairs;
902 /** Returns the size of the aesni gcm session structure */
904 dpaa2_sec_session_get_size(struct rte_cryptodev *dev __rte_unused)
906 PMD_INIT_FUNC_TRACE();
908 return sizeof(dpaa2_sec_session);
912 dpaa2_sec_cipher_init(struct rte_cryptodev *dev,
913 struct rte_crypto_sym_xform *xform,
914 dpaa2_sec_session *session)
916 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
917 struct alginfo cipherdata;
919 struct ctxt_priv *priv;
920 struct sec_flow_context *flc;
922 PMD_INIT_FUNC_TRACE();
924 /* For SEC CIPHER only one descriptor is required. */
925 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
926 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
927 RTE_CACHE_LINE_SIZE);
929 RTE_LOG(ERR, PMD, "No Memory for priv CTXT\n");
933 priv->fle_pool = dev_priv->fle_pool;
935 flc = &priv->flc_desc[0].flc;
937 session->cipher_key.data = rte_zmalloc(NULL, xform->cipher.key.length,
938 RTE_CACHE_LINE_SIZE);
939 if (session->cipher_key.data == NULL) {
940 RTE_LOG(ERR, PMD, "No Memory for cipher key\n");
944 session->cipher_key.length = xform->cipher.key.length;
946 memcpy(session->cipher_key.data, xform->cipher.key.data,
947 xform->cipher.key.length);
948 cipherdata.key = (uint64_t)session->cipher_key.data;
949 cipherdata.keylen = session->cipher_key.length;
950 cipherdata.key_enc_flags = 0;
951 cipherdata.key_type = RTA_DATA_IMM;
953 /* Set IV parameters */
954 session->iv.offset = xform->cipher.iv.offset;
955 session->iv.length = xform->cipher.iv.length;
957 switch (xform->cipher.algo) {
958 case RTE_CRYPTO_CIPHER_AES_CBC:
959 cipherdata.algtype = OP_ALG_ALGSEL_AES;
960 cipherdata.algmode = OP_ALG_AAI_CBC;
961 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
963 case RTE_CRYPTO_CIPHER_3DES_CBC:
964 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
965 cipherdata.algmode = OP_ALG_AAI_CBC;
966 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
968 case RTE_CRYPTO_CIPHER_AES_CTR:
969 cipherdata.algtype = OP_ALG_ALGSEL_AES;
970 cipherdata.algmode = OP_ALG_AAI_CTR;
971 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
973 case RTE_CRYPTO_CIPHER_3DES_CTR:
974 case RTE_CRYPTO_CIPHER_AES_ECB:
975 case RTE_CRYPTO_CIPHER_3DES_ECB:
976 case RTE_CRYPTO_CIPHER_AES_XTS:
977 case RTE_CRYPTO_CIPHER_AES_F8:
978 case RTE_CRYPTO_CIPHER_ARC4:
979 case RTE_CRYPTO_CIPHER_KASUMI_F8:
980 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
981 case RTE_CRYPTO_CIPHER_ZUC_EEA3:
982 case RTE_CRYPTO_CIPHER_NULL:
983 RTE_LOG(ERR, PMD, "Crypto: Unsupported Cipher alg %u\n",
987 RTE_LOG(ERR, PMD, "Crypto: Undefined Cipher specified %u\n",
991 session->dir = (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
994 bufsize = cnstr_shdsc_blkcipher(priv->flc_desc[0].desc, 1, 0,
995 &cipherdata, NULL, session->iv.length,
998 RTE_LOG(ERR, PMD, "Crypto: Descriptor build failed\n");
1003 flc->mode_bits = 0x8000;
1005 flc->word1_sdl = (uint8_t)bufsize;
1006 flc->word2_rflc_31_0 = lower_32_bits(
1007 (uint64_t)&(((struct dpaa2_sec_qp *)
1008 dev->data->queue_pairs[0])->rx_vq));
1009 flc->word3_rflc_63_32 = upper_32_bits(
1010 (uint64_t)&(((struct dpaa2_sec_qp *)
1011 dev->data->queue_pairs[0])->rx_vq));
1012 session->ctxt = priv;
1014 for (i = 0; i < bufsize; i++)
1015 PMD_DRV_LOG(DEBUG, "DESC[%d]:0x%x\n",
1016 i, priv->flc_desc[0].desc[i]);
1021 rte_free(session->cipher_key.data);
1027 dpaa2_sec_auth_init(struct rte_cryptodev *dev,
1028 struct rte_crypto_sym_xform *xform,
1029 dpaa2_sec_session *session)
1031 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
1032 struct alginfo authdata;
1033 unsigned int bufsize, i;
1034 struct ctxt_priv *priv;
1035 struct sec_flow_context *flc;
1037 PMD_INIT_FUNC_TRACE();
1039 /* For SEC AUTH three descriptors are required for various stages */
1040 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
1041 sizeof(struct ctxt_priv) + 3 *
1042 sizeof(struct sec_flc_desc),
1043 RTE_CACHE_LINE_SIZE);
1045 RTE_LOG(ERR, PMD, "No Memory for priv CTXT\n");
1049 priv->fle_pool = dev_priv->fle_pool;
1050 flc = &priv->flc_desc[DESC_INITFINAL].flc;
1052 session->auth_key.data = rte_zmalloc(NULL, xform->auth.key.length,
1053 RTE_CACHE_LINE_SIZE);
1054 if (session->auth_key.data == NULL) {
1055 RTE_LOG(ERR, PMD, "No Memory for auth key\n");
1059 session->auth_key.length = xform->auth.key.length;
1061 memcpy(session->auth_key.data, xform->auth.key.data,
1062 xform->auth.key.length);
1063 authdata.key = (uint64_t)session->auth_key.data;
1064 authdata.keylen = session->auth_key.length;
1065 authdata.key_enc_flags = 0;
1066 authdata.key_type = RTA_DATA_IMM;
1068 session->digest_length = xform->auth.digest_length;
1070 switch (xform->auth.algo) {
1071 case RTE_CRYPTO_AUTH_SHA1_HMAC:
1072 authdata.algtype = OP_ALG_ALGSEL_SHA1;
1073 authdata.algmode = OP_ALG_AAI_HMAC;
1074 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
1076 case RTE_CRYPTO_AUTH_MD5_HMAC:
1077 authdata.algtype = OP_ALG_ALGSEL_MD5;
1078 authdata.algmode = OP_ALG_AAI_HMAC;
1079 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
1081 case RTE_CRYPTO_AUTH_SHA256_HMAC:
1082 authdata.algtype = OP_ALG_ALGSEL_SHA256;
1083 authdata.algmode = OP_ALG_AAI_HMAC;
1084 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
1086 case RTE_CRYPTO_AUTH_SHA384_HMAC:
1087 authdata.algtype = OP_ALG_ALGSEL_SHA384;
1088 authdata.algmode = OP_ALG_AAI_HMAC;
1089 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
1091 case RTE_CRYPTO_AUTH_SHA512_HMAC:
1092 authdata.algtype = OP_ALG_ALGSEL_SHA512;
1093 authdata.algmode = OP_ALG_AAI_HMAC;
1094 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
1096 case RTE_CRYPTO_AUTH_SHA224_HMAC:
1097 authdata.algtype = OP_ALG_ALGSEL_SHA224;
1098 authdata.algmode = OP_ALG_AAI_HMAC;
1099 session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
1101 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
1102 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
1103 case RTE_CRYPTO_AUTH_NULL:
1104 case RTE_CRYPTO_AUTH_SHA1:
1105 case RTE_CRYPTO_AUTH_SHA256:
1106 case RTE_CRYPTO_AUTH_SHA512:
1107 case RTE_CRYPTO_AUTH_SHA224:
1108 case RTE_CRYPTO_AUTH_SHA384:
1109 case RTE_CRYPTO_AUTH_MD5:
1110 case RTE_CRYPTO_AUTH_AES_GMAC:
1111 case RTE_CRYPTO_AUTH_KASUMI_F9:
1112 case RTE_CRYPTO_AUTH_AES_CMAC:
1113 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
1114 case RTE_CRYPTO_AUTH_ZUC_EIA3:
1115 RTE_LOG(ERR, PMD, "Crypto: Unsupported auth alg %u\n",
1119 RTE_LOG(ERR, PMD, "Crypto: Undefined Auth specified %u\n",
1123 session->dir = (xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE) ?
1126 bufsize = cnstr_shdsc_hmac(priv->flc_desc[DESC_INITFINAL].desc,
1127 1, 0, &authdata, !session->dir,
1128 session->digest_length);
1130 flc->word1_sdl = (uint8_t)bufsize;
1131 flc->word2_rflc_31_0 = lower_32_bits(
1132 (uint64_t)&(((struct dpaa2_sec_qp *)
1133 dev->data->queue_pairs[0])->rx_vq));
1134 flc->word3_rflc_63_32 = upper_32_bits(
1135 (uint64_t)&(((struct dpaa2_sec_qp *)
1136 dev->data->queue_pairs[0])->rx_vq));
1137 session->ctxt = priv;
1138 for (i = 0; i < bufsize; i++)
1139 PMD_DRV_LOG(DEBUG, "DESC[%d]:0x%x\n",
1140 i, priv->flc_desc[DESC_INITFINAL].desc[i]);
1146 rte_free(session->auth_key.data);
1152 dpaa2_sec_aead_init(struct rte_cryptodev *dev,
1153 struct rte_crypto_sym_xform *xform,
1154 dpaa2_sec_session *session)
1156 struct dpaa2_sec_aead_ctxt *ctxt = &session->ext_params.aead_ctxt;
1157 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
1158 struct alginfo aeaddata;
1159 unsigned int bufsize, i;
1160 struct ctxt_priv *priv;
1161 struct sec_flow_context *flc;
1162 struct rte_crypto_aead_xform *aead_xform = &xform->aead;
1165 PMD_INIT_FUNC_TRACE();
1167 /* Set IV parameters */
1168 session->iv.offset = aead_xform->iv.offset;
1169 session->iv.length = aead_xform->iv.length;
1170 session->ctxt_type = DPAA2_SEC_AEAD;
1172 /* For SEC AEAD only one descriptor is required */
1173 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
1174 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
1175 RTE_CACHE_LINE_SIZE);
1177 RTE_LOG(ERR, PMD, "No Memory for priv CTXT\n");
1181 priv->fle_pool = dev_priv->fle_pool;
1182 flc = &priv->flc_desc[0].flc;
1184 session->aead_key.data = rte_zmalloc(NULL, aead_xform->key.length,
1185 RTE_CACHE_LINE_SIZE);
1186 if (session->aead_key.data == NULL && aead_xform->key.length > 0) {
1187 RTE_LOG(ERR, PMD, "No Memory for aead key\n");
1191 memcpy(session->aead_key.data, aead_xform->key.data,
1192 aead_xform->key.length);
1194 session->digest_length = aead_xform->digest_length;
1195 session->aead_key.length = aead_xform->key.length;
1196 ctxt->auth_only_len = aead_xform->aad_length;
1198 aeaddata.key = (uint64_t)session->aead_key.data;
1199 aeaddata.keylen = session->aead_key.length;
1200 aeaddata.key_enc_flags = 0;
1201 aeaddata.key_type = RTA_DATA_IMM;
1203 switch (aead_xform->algo) {
1204 case RTE_CRYPTO_AEAD_AES_GCM:
1205 aeaddata.algtype = OP_ALG_ALGSEL_AES;
1206 aeaddata.algmode = OP_ALG_AAI_GCM;
1207 session->cipher_alg = RTE_CRYPTO_AEAD_AES_GCM;
1209 case RTE_CRYPTO_AEAD_AES_CCM:
1210 RTE_LOG(ERR, PMD, "Crypto: Unsupported AEAD alg %u\n",
1214 RTE_LOG(ERR, PMD, "Crypto: Undefined AEAD specified %u\n",
1218 session->dir = (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
1221 priv->flc_desc[0].desc[0] = aeaddata.keylen;
1222 err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
1224 (unsigned int *)priv->flc_desc[0].desc,
1225 &priv->flc_desc[0].desc[1], 1);
1228 PMD_DRV_LOG(ERR, "Crypto: Incorrect key lengths\n");
1231 if (priv->flc_desc[0].desc[1] & 1) {
1232 aeaddata.key_type = RTA_DATA_IMM;
1234 aeaddata.key = DPAA2_VADDR_TO_IOVA(aeaddata.key);
1235 aeaddata.key_type = RTA_DATA_PTR;
1237 priv->flc_desc[0].desc[0] = 0;
1238 priv->flc_desc[0].desc[1] = 0;
1240 if (session->dir == DIR_ENC)
1241 bufsize = cnstr_shdsc_gcm_encap(
1242 priv->flc_desc[0].desc, 1, 0,
1243 &aeaddata, session->iv.length,
1244 session->digest_length);
1246 bufsize = cnstr_shdsc_gcm_decap(
1247 priv->flc_desc[0].desc, 1, 0,
1248 &aeaddata, session->iv.length,
1249 session->digest_length);
1250 flc->word1_sdl = (uint8_t)bufsize;
1251 flc->word2_rflc_31_0 = lower_32_bits(
1252 (uint64_t)&(((struct dpaa2_sec_qp *)
1253 dev->data->queue_pairs[0])->rx_vq));
1254 flc->word3_rflc_63_32 = upper_32_bits(
1255 (uint64_t)&(((struct dpaa2_sec_qp *)
1256 dev->data->queue_pairs[0])->rx_vq));
1257 session->ctxt = priv;
1258 for (i = 0; i < bufsize; i++)
1259 PMD_DRV_LOG(DEBUG, "DESC[%d]:0x%x\n",
1260 i, priv->flc_desc[0].desc[i]);
1265 rte_free(session->aead_key.data);
1272 dpaa2_sec_aead_chain_init(struct rte_cryptodev *dev,
1273 struct rte_crypto_sym_xform *xform,
1274 dpaa2_sec_session *session)
1276 struct dpaa2_sec_aead_ctxt *ctxt = &session->ext_params.aead_ctxt;
1277 struct dpaa2_sec_dev_private *dev_priv = dev->data->dev_private;
1278 struct alginfo authdata, cipherdata;
1279 unsigned int bufsize, i;
1280 struct ctxt_priv *priv;
1281 struct sec_flow_context *flc;
1282 struct rte_crypto_cipher_xform *cipher_xform;
1283 struct rte_crypto_auth_xform *auth_xform;
1286 PMD_INIT_FUNC_TRACE();
1288 if (session->ext_params.aead_ctxt.auth_cipher_text) {
1289 cipher_xform = &xform->cipher;
1290 auth_xform = &xform->next->auth;
1291 session->ctxt_type =
1292 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
1293 DPAA2_SEC_CIPHER_HASH : DPAA2_SEC_HASH_CIPHER;
1295 cipher_xform = &xform->next->cipher;
1296 auth_xform = &xform->auth;
1297 session->ctxt_type =
1298 (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
1299 DPAA2_SEC_HASH_CIPHER : DPAA2_SEC_CIPHER_HASH;
1302 /* Set IV parameters */
1303 session->iv.offset = cipher_xform->iv.offset;
1304 session->iv.length = cipher_xform->iv.length;
1306 /* For SEC AEAD only one descriptor is required */
1307 priv = (struct ctxt_priv *)rte_zmalloc(NULL,
1308 sizeof(struct ctxt_priv) + sizeof(struct sec_flc_desc),
1309 RTE_CACHE_LINE_SIZE);
1311 RTE_LOG(ERR, PMD, "No Memory for priv CTXT\n");
1315 priv->fle_pool = dev_priv->fle_pool;
1316 flc = &priv->flc_desc[0].flc;
1318 session->cipher_key.data = rte_zmalloc(NULL, cipher_xform->key.length,
1319 RTE_CACHE_LINE_SIZE);
1320 if (session->cipher_key.data == NULL && cipher_xform->key.length > 0) {
1321 RTE_LOG(ERR, PMD, "No Memory for cipher key\n");
1325 session->cipher_key.length = cipher_xform->key.length;
1326 session->auth_key.data = rte_zmalloc(NULL, auth_xform->key.length,
1327 RTE_CACHE_LINE_SIZE);
1328 if (session->auth_key.data == NULL && auth_xform->key.length > 0) {
1329 RTE_LOG(ERR, PMD, "No Memory for auth key\n");
1330 rte_free(session->cipher_key.data);
1334 session->auth_key.length = auth_xform->key.length;
1335 memcpy(session->cipher_key.data, cipher_xform->key.data,
1336 cipher_xform->key.length);
1337 memcpy(session->auth_key.data, auth_xform->key.data,
1338 auth_xform->key.length);
1340 authdata.key = (uint64_t)session->auth_key.data;
1341 authdata.keylen = session->auth_key.length;
1342 authdata.key_enc_flags = 0;
1343 authdata.key_type = RTA_DATA_IMM;
1345 session->digest_length = auth_xform->digest_length;
1347 switch (auth_xform->algo) {
1348 case RTE_CRYPTO_AUTH_SHA1_HMAC:
1349 authdata.algtype = OP_ALG_ALGSEL_SHA1;
1350 authdata.algmode = OP_ALG_AAI_HMAC;
1351 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
1353 case RTE_CRYPTO_AUTH_MD5_HMAC:
1354 authdata.algtype = OP_ALG_ALGSEL_MD5;
1355 authdata.algmode = OP_ALG_AAI_HMAC;
1356 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
1358 case RTE_CRYPTO_AUTH_SHA224_HMAC:
1359 authdata.algtype = OP_ALG_ALGSEL_SHA224;
1360 authdata.algmode = OP_ALG_AAI_HMAC;
1361 session->auth_alg = RTE_CRYPTO_AUTH_SHA224_HMAC;
1363 case RTE_CRYPTO_AUTH_SHA256_HMAC:
1364 authdata.algtype = OP_ALG_ALGSEL_SHA256;
1365 authdata.algmode = OP_ALG_AAI_HMAC;
1366 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
1368 case RTE_CRYPTO_AUTH_SHA384_HMAC:
1369 authdata.algtype = OP_ALG_ALGSEL_SHA384;
1370 authdata.algmode = OP_ALG_AAI_HMAC;
1371 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
1373 case RTE_CRYPTO_AUTH_SHA512_HMAC:
1374 authdata.algtype = OP_ALG_ALGSEL_SHA512;
1375 authdata.algmode = OP_ALG_AAI_HMAC;
1376 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
1378 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
1379 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
1380 case RTE_CRYPTO_AUTH_NULL:
1381 case RTE_CRYPTO_AUTH_SHA1:
1382 case RTE_CRYPTO_AUTH_SHA256:
1383 case RTE_CRYPTO_AUTH_SHA512:
1384 case RTE_CRYPTO_AUTH_SHA224:
1385 case RTE_CRYPTO_AUTH_SHA384:
1386 case RTE_CRYPTO_AUTH_MD5:
1387 case RTE_CRYPTO_AUTH_AES_GMAC:
1388 case RTE_CRYPTO_AUTH_KASUMI_F9:
1389 case RTE_CRYPTO_AUTH_AES_CMAC:
1390 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
1391 case RTE_CRYPTO_AUTH_ZUC_EIA3:
1392 RTE_LOG(ERR, PMD, "Crypto: Unsupported auth alg %u\n",
1396 RTE_LOG(ERR, PMD, "Crypto: Undefined Auth specified %u\n",
1400 cipherdata.key = (uint64_t)session->cipher_key.data;
1401 cipherdata.keylen = session->cipher_key.length;
1402 cipherdata.key_enc_flags = 0;
1403 cipherdata.key_type = RTA_DATA_IMM;
1405 switch (cipher_xform->algo) {
1406 case RTE_CRYPTO_CIPHER_AES_CBC:
1407 cipherdata.algtype = OP_ALG_ALGSEL_AES;
1408 cipherdata.algmode = OP_ALG_AAI_CBC;
1409 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
1411 case RTE_CRYPTO_CIPHER_3DES_CBC:
1412 cipherdata.algtype = OP_ALG_ALGSEL_3DES;
1413 cipherdata.algmode = OP_ALG_AAI_CBC;
1414 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
1416 case RTE_CRYPTO_CIPHER_AES_CTR:
1417 cipherdata.algtype = OP_ALG_ALGSEL_AES;
1418 cipherdata.algmode = OP_ALG_AAI_CTR;
1419 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
1421 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
1422 case RTE_CRYPTO_CIPHER_NULL:
1423 case RTE_CRYPTO_CIPHER_3DES_ECB:
1424 case RTE_CRYPTO_CIPHER_AES_ECB:
1425 case RTE_CRYPTO_CIPHER_KASUMI_F8:
1426 RTE_LOG(ERR, PMD, "Crypto: Unsupported Cipher alg %u\n",
1427 cipher_xform->algo);
1430 RTE_LOG(ERR, PMD, "Crypto: Undefined Cipher specified %u\n",
1431 cipher_xform->algo);
1434 session->dir = (cipher_xform->op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
1437 priv->flc_desc[0].desc[0] = cipherdata.keylen;
1438 priv->flc_desc[0].desc[1] = authdata.keylen;
1439 err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
1441 (unsigned int *)priv->flc_desc[0].desc,
1442 &priv->flc_desc[0].desc[2], 2);
1445 PMD_DRV_LOG(ERR, "Crypto: Incorrect key lengths\n");
1448 if (priv->flc_desc[0].desc[2] & 1) {
1449 cipherdata.key_type = RTA_DATA_IMM;
1451 cipherdata.key = DPAA2_VADDR_TO_IOVA(cipherdata.key);
1452 cipherdata.key_type = RTA_DATA_PTR;
1454 if (priv->flc_desc[0].desc[2] & (1 << 1)) {
1455 authdata.key_type = RTA_DATA_IMM;
1457 authdata.key = DPAA2_VADDR_TO_IOVA(authdata.key);
1458 authdata.key_type = RTA_DATA_PTR;
1460 priv->flc_desc[0].desc[0] = 0;
1461 priv->flc_desc[0].desc[1] = 0;
1462 priv->flc_desc[0].desc[2] = 0;
1464 if (session->ctxt_type == DPAA2_SEC_CIPHER_HASH) {
1465 bufsize = cnstr_shdsc_authenc(priv->flc_desc[0].desc, 1,
1466 0, &cipherdata, &authdata,
1468 ctxt->auth_only_len,
1469 session->digest_length,
1472 RTE_LOG(ERR, PMD, "Hash before cipher not supported\n");
1476 flc->word1_sdl = (uint8_t)bufsize;
1477 flc->word2_rflc_31_0 = lower_32_bits(
1478 (uint64_t)&(((struct dpaa2_sec_qp *)
1479 dev->data->queue_pairs[0])->rx_vq));
1480 flc->word3_rflc_63_32 = upper_32_bits(
1481 (uint64_t)&(((struct dpaa2_sec_qp *)
1482 dev->data->queue_pairs[0])->rx_vq));
1483 session->ctxt = priv;
1484 for (i = 0; i < bufsize; i++)
1485 PMD_DRV_LOG(DEBUG, "DESC[%d]:0x%x\n",
1486 i, priv->flc_desc[0].desc[i]);
1491 rte_free(session->cipher_key.data);
1492 rte_free(session->auth_key.data);
1498 dpaa2_sec_set_session_parameters(struct rte_cryptodev *dev,
1499 struct rte_crypto_sym_xform *xform, void *sess)
1501 dpaa2_sec_session *session = sess;
1503 PMD_INIT_FUNC_TRACE();
1505 if (unlikely(sess == NULL)) {
1506 RTE_LOG(ERR, PMD, "invalid session struct\n");
1510 /* Default IV length = 0 */
1511 session->iv.length = 0;
1514 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
1515 session->ctxt_type = DPAA2_SEC_CIPHER;
1516 dpaa2_sec_cipher_init(dev, xform, session);
1518 /* Authentication Only */
1519 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
1520 xform->next == NULL) {
1521 session->ctxt_type = DPAA2_SEC_AUTH;
1522 dpaa2_sec_auth_init(dev, xform, session);
1524 /* Cipher then Authenticate */
1525 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
1526 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
1527 session->ext_params.aead_ctxt.auth_cipher_text = true;
1528 dpaa2_sec_aead_chain_init(dev, xform, session);
1530 /* Authenticate then Cipher */
1531 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
1532 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
1533 session->ext_params.aead_ctxt.auth_cipher_text = false;
1534 dpaa2_sec_aead_chain_init(dev, xform, session);
1536 /* AEAD operation for AES-GCM kind of Algorithms */
1537 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD &&
1538 xform->next == NULL) {
1539 dpaa2_sec_aead_init(dev, xform, session);
1542 RTE_LOG(ERR, PMD, "Invalid crypto type\n");
1550 dpaa2_sec_session_configure(struct rte_cryptodev *dev,
1551 struct rte_crypto_sym_xform *xform,
1552 struct rte_cryptodev_sym_session *sess,
1553 struct rte_mempool *mempool)
1555 void *sess_private_data;
1558 if (rte_mempool_get(mempool, &sess_private_data)) {
1560 "Couldn't get object from session mempool");
1564 ret = dpaa2_sec_set_session_parameters(dev, xform, sess_private_data);
1566 PMD_DRV_LOG(ERR, "DPAA2 PMD: failed to configure "
1567 "session parameters");
1569 /* Return session to mempool */
1570 rte_mempool_put(mempool, sess_private_data);
1574 set_session_private_data(sess, dev->driver_id,
1580 /** Clear the memory of session so it doesn't leave key material behind */
1582 dpaa2_sec_session_clear(struct rte_cryptodev *dev,
1583 struct rte_cryptodev_sym_session *sess)
1585 PMD_INIT_FUNC_TRACE();
1586 uint8_t index = dev->driver_id;
1587 void *sess_priv = get_session_private_data(sess, index);
1588 dpaa2_sec_session *s = (dpaa2_sec_session *)sess_priv;
1592 rte_free(s->cipher_key.data);
1593 rte_free(s->auth_key.data);
1594 memset(sess, 0, sizeof(dpaa2_sec_session));
1595 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
1596 set_session_private_data(sess, index, NULL);
1597 rte_mempool_put(sess_mp, sess_priv);
1602 dpaa2_sec_dev_configure(struct rte_cryptodev *dev __rte_unused,
1603 struct rte_cryptodev_config *config __rte_unused)
1605 PMD_INIT_FUNC_TRACE();
1611 dpaa2_sec_dev_start(struct rte_cryptodev *dev)
1613 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
1614 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
1615 struct dpseci_attr attr;
1616 struct dpaa2_queue *dpaa2_q;
1617 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
1618 dev->data->queue_pairs;
1619 struct dpseci_rx_queue_attr rx_attr;
1620 struct dpseci_tx_queue_attr tx_attr;
1623 PMD_INIT_FUNC_TRACE();
1625 memset(&attr, 0, sizeof(struct dpseci_attr));
1627 ret = dpseci_enable(dpseci, CMD_PRI_LOW, priv->token);
1629 PMD_INIT_LOG(ERR, "DPSECI with HW_ID = %d ENABLE FAILED\n",
1631 goto get_attr_failure;
1633 ret = dpseci_get_attributes(dpseci, CMD_PRI_LOW, priv->token, &attr);
1636 "DPSEC ATTRIBUTE READ FAILED, disabling DPSEC\n");
1637 goto get_attr_failure;
1639 for (i = 0; i < attr.num_rx_queues && qp[i]; i++) {
1640 dpaa2_q = &qp[i]->rx_vq;
1641 dpseci_get_rx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
1643 dpaa2_q->fqid = rx_attr.fqid;
1644 PMD_INIT_LOG(DEBUG, "rx_fqid: %d", dpaa2_q->fqid);
1646 for (i = 0; i < attr.num_tx_queues && qp[i]; i++) {
1647 dpaa2_q = &qp[i]->tx_vq;
1648 dpseci_get_tx_queue(dpseci, CMD_PRI_LOW, priv->token, i,
1650 dpaa2_q->fqid = tx_attr.fqid;
1651 PMD_INIT_LOG(DEBUG, "tx_fqid: %d", dpaa2_q->fqid);
1656 dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
1661 dpaa2_sec_dev_stop(struct rte_cryptodev *dev)
1663 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
1664 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
1667 PMD_INIT_FUNC_TRACE();
1669 ret = dpseci_disable(dpseci, CMD_PRI_LOW, priv->token);
1671 PMD_INIT_LOG(ERR, "Failure in disabling dpseci %d device",
1676 ret = dpseci_reset(dpseci, CMD_PRI_LOW, priv->token);
1678 PMD_INIT_LOG(ERR, "SEC Device cannot be reset:Error = %0x\n",
1685 dpaa2_sec_dev_close(struct rte_cryptodev *dev)
1687 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
1688 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
1691 PMD_INIT_FUNC_TRACE();
1693 /* Function is reverse of dpaa2_sec_dev_init.
1694 * It does the following:
1695 * 1. Detach a DPSECI from attached resources i.e. buffer pools, dpbp_id
1696 * 2. Close the DPSECI device
1697 * 3. Free the allocated resources.
1700 /*Close the device at underlying layer*/
1701 ret = dpseci_close(dpseci, CMD_PRI_LOW, priv->token);
1703 PMD_INIT_LOG(ERR, "Failure closing dpseci device with"
1704 " error code %d\n", ret);
1708 /*Free the allocated memory for ethernet private data and dpseci*/
1716 dpaa2_sec_dev_infos_get(struct rte_cryptodev *dev,
1717 struct rte_cryptodev_info *info)
1719 struct dpaa2_sec_dev_private *internals = dev->data->dev_private;
1721 PMD_INIT_FUNC_TRACE();
1723 info->max_nb_queue_pairs = internals->max_nb_queue_pairs;
1724 info->feature_flags = dev->feature_flags;
1725 info->capabilities = dpaa2_sec_capabilities;
1726 info->sym.max_nb_sessions = internals->max_nb_sessions;
1727 info->driver_id = cryptodev_driver_id;
1732 void dpaa2_sec_stats_get(struct rte_cryptodev *dev,
1733 struct rte_cryptodev_stats *stats)
1735 struct dpaa2_sec_dev_private *priv = dev->data->dev_private;
1736 struct fsl_mc_io *dpseci = (struct fsl_mc_io *)priv->hw;
1737 struct dpseci_sec_counters counters = {0};
1738 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
1739 dev->data->queue_pairs;
1742 PMD_INIT_FUNC_TRACE();
1743 if (stats == NULL) {
1744 PMD_DRV_LOG(ERR, "invalid stats ptr NULL");
1747 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
1748 if (qp[i] == NULL) {
1749 PMD_DRV_LOG(DEBUG, "Uninitialised queue pair");
1753 stats->enqueued_count += qp[i]->tx_vq.tx_pkts;
1754 stats->dequeued_count += qp[i]->rx_vq.rx_pkts;
1755 stats->enqueue_err_count += qp[i]->tx_vq.err_pkts;
1756 stats->dequeue_err_count += qp[i]->rx_vq.err_pkts;
1759 ret = dpseci_get_sec_counters(dpseci, CMD_PRI_LOW, priv->token,
1762 PMD_DRV_LOG(ERR, "dpseci_get_sec_counters failed\n");
1764 PMD_DRV_LOG(INFO, "dpseci hw stats:"
1765 "\n\tNumber of Requests Dequeued = %lu"
1766 "\n\tNumber of Outbound Encrypt Requests = %lu"
1767 "\n\tNumber of Inbound Decrypt Requests = %lu"
1768 "\n\tNumber of Outbound Bytes Encrypted = %lu"
1769 "\n\tNumber of Outbound Bytes Protected = %lu"
1770 "\n\tNumber of Inbound Bytes Decrypted = %lu"
1771 "\n\tNumber of Inbound Bytes Validated = %lu",
1772 counters.dequeued_requests,
1773 counters.ob_enc_requests,
1774 counters.ib_dec_requests,
1775 counters.ob_enc_bytes,
1776 counters.ob_prot_bytes,
1777 counters.ib_dec_bytes,
1778 counters.ib_valid_bytes);
1783 void dpaa2_sec_stats_reset(struct rte_cryptodev *dev)
1786 struct dpaa2_sec_qp **qp = (struct dpaa2_sec_qp **)
1787 (dev->data->queue_pairs);
1789 PMD_INIT_FUNC_TRACE();
1791 for (i = 0; i < dev->data->nb_queue_pairs; i++) {
1792 if (qp[i] == NULL) {
1793 PMD_DRV_LOG(DEBUG, "Uninitialised queue pair");
1796 qp[i]->tx_vq.rx_pkts = 0;
1797 qp[i]->tx_vq.tx_pkts = 0;
1798 qp[i]->tx_vq.err_pkts = 0;
1799 qp[i]->rx_vq.rx_pkts = 0;
1800 qp[i]->rx_vq.tx_pkts = 0;
1801 qp[i]->rx_vq.err_pkts = 0;
1805 static struct rte_cryptodev_ops crypto_ops = {
1806 .dev_configure = dpaa2_sec_dev_configure,
1807 .dev_start = dpaa2_sec_dev_start,
1808 .dev_stop = dpaa2_sec_dev_stop,
1809 .dev_close = dpaa2_sec_dev_close,
1810 .dev_infos_get = dpaa2_sec_dev_infos_get,
1811 .stats_get = dpaa2_sec_stats_get,
1812 .stats_reset = dpaa2_sec_stats_reset,
1813 .queue_pair_setup = dpaa2_sec_queue_pair_setup,
1814 .queue_pair_release = dpaa2_sec_queue_pair_release,
1815 .queue_pair_start = dpaa2_sec_queue_pair_start,
1816 .queue_pair_stop = dpaa2_sec_queue_pair_stop,
1817 .queue_pair_count = dpaa2_sec_queue_pair_count,
1818 .session_get_size = dpaa2_sec_session_get_size,
1819 .session_configure = dpaa2_sec_session_configure,
1820 .session_clear = dpaa2_sec_session_clear,
1824 dpaa2_sec_uninit(const struct rte_cryptodev *dev)
1826 struct dpaa2_sec_dev_private *internals = dev->data->dev_private;
1828 rte_mempool_free(internals->fle_pool);
1830 PMD_INIT_LOG(INFO, "Closing DPAA2_SEC device %s on numa socket %u\n",
1831 dev->data->name, rte_socket_id());
1837 dpaa2_sec_dev_init(struct rte_cryptodev *cryptodev)
1839 struct dpaa2_sec_dev_private *internals;
1840 struct rte_device *dev = cryptodev->device;
1841 struct rte_dpaa2_device *dpaa2_dev;
1842 struct fsl_mc_io *dpseci;
1844 struct dpseci_attr attr;
1848 PMD_INIT_FUNC_TRACE();
1849 dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
1850 if (dpaa2_dev == NULL) {
1851 PMD_INIT_LOG(ERR, "dpaa2_device not found\n");
1854 hw_id = dpaa2_dev->object_id;
1856 cryptodev->driver_id = cryptodev_driver_id;
1857 cryptodev->dev_ops = &crypto_ops;
1859 cryptodev->enqueue_burst = dpaa2_sec_enqueue_burst;
1860 cryptodev->dequeue_burst = dpaa2_sec_dequeue_burst;
1861 cryptodev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
1862 RTE_CRYPTODEV_FF_HW_ACCELERATED |
1863 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING;
1865 internals = cryptodev->data->dev_private;
1866 internals->max_nb_sessions = RTE_DPAA2_SEC_PMD_MAX_NB_SESSIONS;
1869 * For secondary processes, we don't initialise any further as primary
1870 * has already done this work. Only check we don't need a different
1873 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
1874 PMD_INIT_LOG(DEBUG, "Device already init by primary process");
1877 /*Open the rte device via MC and save the handle for further use*/
1878 dpseci = (struct fsl_mc_io *)rte_calloc(NULL, 1,
1879 sizeof(struct fsl_mc_io), 0);
1882 "Error in allocating the memory for dpsec object");
1885 dpseci->regs = rte_mcp_ptr_list[0];
1887 retcode = dpseci_open(dpseci, CMD_PRI_LOW, hw_id, &token);
1889 PMD_INIT_LOG(ERR, "Cannot open the dpsec device: Error = %x",
1893 retcode = dpseci_get_attributes(dpseci, CMD_PRI_LOW, token, &attr);
1896 "Cannot get dpsec device attributed: Error = %x",
1900 sprintf(cryptodev->data->name, "dpsec-%u", hw_id);
1902 internals->max_nb_queue_pairs = attr.num_tx_queues;
1903 cryptodev->data->nb_queue_pairs = internals->max_nb_queue_pairs;
1904 internals->hw = dpseci;
1905 internals->token = token;
1907 sprintf(str, "fle_pool_%d", cryptodev->data->dev_id);
1908 internals->fle_pool = rte_mempool_create((const char *)str,
1911 FLE_POOL_CACHE_SIZE, 0,
1912 NULL, NULL, NULL, NULL,
1914 if (!internals->fle_pool) {
1915 RTE_LOG(ERR, PMD, "%s create failed\n", str);
1919 PMD_INIT_LOG(DEBUG, "driver %s: created\n", cryptodev->data->name);
1923 PMD_INIT_LOG(ERR, "driver %s: create failed\n", cryptodev->data->name);
1925 /* dpaa2_sec_uninit(crypto_dev_name); */
1930 cryptodev_dpaa2_sec_probe(struct rte_dpaa2_driver *dpaa2_drv,
1931 struct rte_dpaa2_device *dpaa2_dev)
1933 struct rte_cryptodev *cryptodev;
1934 char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
1938 sprintf(cryptodev_name, "dpsec-%d", dpaa2_dev->object_id);
1940 cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
1941 if (cryptodev == NULL)
1944 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1945 cryptodev->data->dev_private = rte_zmalloc_socket(
1946 "cryptodev private structure",
1947 sizeof(struct dpaa2_sec_dev_private),
1948 RTE_CACHE_LINE_SIZE,
1951 if (cryptodev->data->dev_private == NULL)
1952 rte_panic("Cannot allocate memzone for private "
1956 dpaa2_dev->cryptodev = cryptodev;
1957 cryptodev->device = &dpaa2_dev->device;
1958 cryptodev->device->driver = &dpaa2_drv->driver;
1960 /* init user callbacks */
1961 TAILQ_INIT(&(cryptodev->link_intr_cbs));
1963 /* Invoke PMD device initialization function */
1964 retval = dpaa2_sec_dev_init(cryptodev);
1968 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1969 rte_free(cryptodev->data->dev_private);
1971 cryptodev->attached = RTE_CRYPTODEV_DETACHED;
1977 cryptodev_dpaa2_sec_remove(struct rte_dpaa2_device *dpaa2_dev)
1979 struct rte_cryptodev *cryptodev;
1982 cryptodev = dpaa2_dev->cryptodev;
1983 if (cryptodev == NULL)
1986 ret = dpaa2_sec_uninit(cryptodev);
1990 /* free crypto device */
1991 rte_cryptodev_pmd_release_device(cryptodev);
1993 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1994 rte_free(cryptodev->data->dev_private);
1996 cryptodev->device = NULL;
1997 cryptodev->data = NULL;
2002 static struct rte_dpaa2_driver rte_dpaa2_sec_driver = {
2003 .drv_type = DPAA2_CRYPTO,
2005 .name = "DPAA2 SEC PMD"
2007 .probe = cryptodev_dpaa2_sec_probe,
2008 .remove = cryptodev_dpaa2_sec_remove,
2011 RTE_PMD_REGISTER_DPAA2(CRYPTODEV_NAME_DPAA2_SEC_PMD, rte_dpaa2_sec_driver);
2012 RTE_PMD_REGISTER_CRYPTO_DRIVER(rte_dpaa2_sec_driver, cryptodev_driver_id);