1 /* SPDX-License-Identifier: BSD-3-Clause
3 * Copyright (c) 2016 Freescale Semiconductor, Inc. All rights reserved.
4 * Copyright 2017-2018 NXP
13 #include <rte_byteorder.h>
14 #include <rte_common.h>
15 #include <rte_cryptodev_pmd.h>
16 #include <rte_crypto.h>
17 #include <rte_cryptodev.h>
18 #include <rte_security_driver.h>
19 #include <rte_cycles.h>
21 #include <rte_kvargs.h>
22 #include <rte_malloc.h>
24 #include <rte_memcpy.h>
25 #include <rte_string_fns.h>
31 /* RTA header files */
32 #include <hw/desc/common.h>
33 #include <hw/desc/algo.h>
34 #include <hw/desc/ipsec.h>
36 #include <rte_dpaa_bus.h>
38 #include <dpaa_sec_log.h>
40 enum rta_sec_era rta_sec_era;
44 static uint8_t cryptodev_driver_id;
46 static __thread struct rte_crypto_op **dpaa_sec_ops;
47 static __thread int dpaa_sec_op_nb;
50 dpaa_sec_attach_sess_q(struct dpaa_sec_qp *qp, dpaa_sec_session *sess);
53 dpaa_sec_op_ending(struct dpaa_sec_op_ctx *ctx)
55 if (!ctx->fd_status) {
56 ctx->op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
58 DPAA_SEC_DP_WARN("SEC return err: 0x%x", ctx->fd_status);
59 ctx->op->status = RTE_CRYPTO_OP_STATUS_ERROR;
62 /* report op status to sym->op and then free the ctx memeory */
63 rte_mempool_put(ctx->ctx_pool, (void *)ctx);
66 static inline struct dpaa_sec_op_ctx *
67 dpaa_sec_alloc_ctx(dpaa_sec_session *ses)
69 struct dpaa_sec_op_ctx *ctx;
72 retval = rte_mempool_get(ses->ctx_pool, (void **)(&ctx));
74 DPAA_SEC_DP_WARN("Alloc sec descriptor failed!");
78 * Clear SG memory. There are 16 SG entries of 16 Bytes each.
79 * one call to dcbz_64() clear 64 bytes, hence calling it 4 times
80 * to clear all the SG entries. dpaa_sec_alloc_ctx() is called for
81 * each packet, memset is costlier than dcbz_64().
83 dcbz_64(&ctx->job.sg[SG_CACHELINE_0]);
84 dcbz_64(&ctx->job.sg[SG_CACHELINE_1]);
85 dcbz_64(&ctx->job.sg[SG_CACHELINE_2]);
86 dcbz_64(&ctx->job.sg[SG_CACHELINE_3]);
88 ctx->ctx_pool = ses->ctx_pool;
89 ctx->vtop_offset = (size_t) ctx
90 - rte_mempool_virt2iova(ctx);
95 static inline rte_iova_t
96 dpaa_mem_vtop(void *vaddr)
98 const struct rte_memseg *ms;
100 ms = rte_mem_virt2memseg(vaddr, NULL);
102 return ms->iova + RTE_PTR_DIFF(vaddr, ms->addr);
107 dpaa_mem_ptov(rte_iova_t paddr)
109 return rte_mem_iova2virt(paddr);
113 ern_sec_fq_handler(struct qman_portal *qm __rte_unused,
115 const struct qm_mr_entry *msg)
117 DPAA_SEC_DP_ERR("sec fq %d error, RC = %x, seqnum = %x\n",
118 fq->fqid, msg->ern.rc, msg->ern.seqnum);
121 /* initialize the queue with dest chan as caam chan so that
122 * all the packets in this queue could be dispatched into caam
125 dpaa_sec_init_rx(struct qman_fq *fq_in, rte_iova_t hwdesc,
128 struct qm_mcc_initfq fq_opts;
132 /* Clear FQ options */
133 memset(&fq_opts, 0x00, sizeof(struct qm_mcc_initfq));
135 flags = QMAN_INITFQ_FLAG_SCHED;
136 fq_opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_CONTEXTA |
137 QM_INITFQ_WE_CONTEXTB;
139 qm_fqd_context_a_set64(&fq_opts.fqd, hwdesc);
140 fq_opts.fqd.context_b = fqid_out;
141 fq_opts.fqd.dest.channel = qm_channel_caam;
142 fq_opts.fqd.dest.wq = 0;
144 fq_in->cb.ern = ern_sec_fq_handler;
146 DPAA_SEC_DEBUG("in-%x out-%x", fq_in->fqid, fqid_out);
148 ret = qman_init_fq(fq_in, flags, &fq_opts);
149 if (unlikely(ret != 0))
150 DPAA_SEC_ERR("qman_init_fq failed %d", ret);
155 /* something is put into in_fq and caam put the crypto result into out_fq */
156 static enum qman_cb_dqrr_result
157 dqrr_out_fq_cb_rx(struct qman_portal *qm __always_unused,
158 struct qman_fq *fq __always_unused,
159 const struct qm_dqrr_entry *dqrr)
161 const struct qm_fd *fd;
162 struct dpaa_sec_job *job;
163 struct dpaa_sec_op_ctx *ctx;
165 if (dpaa_sec_op_nb >= DPAA_SEC_BURST)
166 return qman_cb_dqrr_defer;
168 if (!(dqrr->stat & QM_DQRR_STAT_FD_VALID))
169 return qman_cb_dqrr_consume;
172 /* sg is embedded in an op ctx,
173 * sg[0] is for output
176 job = dpaa_mem_ptov(qm_fd_addr_get64(fd));
178 ctx = container_of(job, struct dpaa_sec_op_ctx, job);
179 ctx->fd_status = fd->status;
180 if (ctx->op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
181 struct qm_sg_entry *sg_out;
184 sg_out = &job->sg[0];
185 hw_sg_to_cpu(sg_out);
186 len = sg_out->length;
187 ctx->op->sym->m_src->pkt_len = len;
188 ctx->op->sym->m_src->data_len = len;
190 dpaa_sec_ops[dpaa_sec_op_nb++] = ctx->op;
191 dpaa_sec_op_ending(ctx);
193 return qman_cb_dqrr_consume;
196 /* caam result is put into this queue */
198 dpaa_sec_init_tx(struct qman_fq *fq)
201 struct qm_mcc_initfq opts;
204 flags = QMAN_FQ_FLAG_NO_ENQUEUE | QMAN_FQ_FLAG_LOCKED |
205 QMAN_FQ_FLAG_DYNAMIC_FQID;
207 ret = qman_create_fq(0, flags, fq);
209 DPAA_SEC_ERR("qman_create_fq failed");
213 memset(&opts, 0, sizeof(opts));
214 opts.we_mask = QM_INITFQ_WE_DESTWQ | QM_INITFQ_WE_FQCTRL |
215 QM_INITFQ_WE_CONTEXTA | QM_INITFQ_WE_CONTEXTB;
217 /* opts.fqd.dest.channel = dpaa_sec_pool_chan; */
219 fq->cb.dqrr = dqrr_out_fq_cb_rx;
220 fq->cb.ern = ern_sec_fq_handler;
222 ret = qman_init_fq(fq, 0, &opts);
224 DPAA_SEC_ERR("unable to init caam source fq!");
231 static inline int is_cipher_only(dpaa_sec_session *ses)
233 return ((ses->cipher_alg != RTE_CRYPTO_CIPHER_NULL) &&
234 (ses->auth_alg == RTE_CRYPTO_AUTH_NULL));
237 static inline int is_auth_only(dpaa_sec_session *ses)
239 return ((ses->cipher_alg == RTE_CRYPTO_CIPHER_NULL) &&
240 (ses->auth_alg != RTE_CRYPTO_AUTH_NULL));
243 static inline int is_aead(dpaa_sec_session *ses)
245 return ((ses->cipher_alg == 0) &&
246 (ses->auth_alg == 0) &&
247 (ses->aead_alg != 0));
250 static inline int is_auth_cipher(dpaa_sec_session *ses)
252 return ((ses->cipher_alg != RTE_CRYPTO_CIPHER_NULL) &&
253 (ses->auth_alg != RTE_CRYPTO_AUTH_NULL) &&
254 (ses->proto_alg != RTE_SECURITY_PROTOCOL_IPSEC));
257 static inline int is_proto_ipsec(dpaa_sec_session *ses)
259 return (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC);
262 static inline int is_encode(dpaa_sec_session *ses)
264 return ses->dir == DIR_ENC;
267 static inline int is_decode(dpaa_sec_session *ses)
269 return ses->dir == DIR_DEC;
273 caam_auth_alg(dpaa_sec_session *ses, struct alginfo *alginfo_a)
275 switch (ses->auth_alg) {
276 case RTE_CRYPTO_AUTH_NULL:
277 ses->digest_length = 0;
279 case RTE_CRYPTO_AUTH_MD5_HMAC:
281 (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ?
282 OP_PCL_IPSEC_HMAC_MD5_96 : OP_ALG_ALGSEL_MD5;
283 alginfo_a->algmode = OP_ALG_AAI_HMAC;
285 case RTE_CRYPTO_AUTH_SHA1_HMAC:
287 (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ?
288 OP_PCL_IPSEC_HMAC_SHA1_96 : OP_ALG_ALGSEL_SHA1;
289 alginfo_a->algmode = OP_ALG_AAI_HMAC;
291 case RTE_CRYPTO_AUTH_SHA224_HMAC:
293 (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ?
294 OP_PCL_IPSEC_HMAC_SHA1_160 : OP_ALG_ALGSEL_SHA224;
295 alginfo_a->algmode = OP_ALG_AAI_HMAC;
297 case RTE_CRYPTO_AUTH_SHA256_HMAC:
299 (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ?
300 OP_PCL_IPSEC_HMAC_SHA2_256_128 : OP_ALG_ALGSEL_SHA256;
301 alginfo_a->algmode = OP_ALG_AAI_HMAC;
303 case RTE_CRYPTO_AUTH_SHA384_HMAC:
305 (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ?
306 OP_PCL_IPSEC_HMAC_SHA2_384_192 : OP_ALG_ALGSEL_SHA384;
307 alginfo_a->algmode = OP_ALG_AAI_HMAC;
309 case RTE_CRYPTO_AUTH_SHA512_HMAC:
311 (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ?
312 OP_PCL_IPSEC_HMAC_SHA2_512_256 : OP_ALG_ALGSEL_SHA512;
313 alginfo_a->algmode = OP_ALG_AAI_HMAC;
316 DPAA_SEC_ERR("unsupported auth alg %u", ses->auth_alg);
321 caam_cipher_alg(dpaa_sec_session *ses, struct alginfo *alginfo_c)
323 switch (ses->cipher_alg) {
324 case RTE_CRYPTO_CIPHER_NULL:
326 case RTE_CRYPTO_CIPHER_AES_CBC:
328 (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ?
329 OP_PCL_IPSEC_AES_CBC : OP_ALG_ALGSEL_AES;
330 alginfo_c->algmode = OP_ALG_AAI_CBC;
332 case RTE_CRYPTO_CIPHER_3DES_CBC:
334 (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ?
335 OP_PCL_IPSEC_3DES : OP_ALG_ALGSEL_3DES;
336 alginfo_c->algmode = OP_ALG_AAI_CBC;
338 case RTE_CRYPTO_CIPHER_AES_CTR:
340 (ses->proto_alg == RTE_SECURITY_PROTOCOL_IPSEC) ?
341 OP_PCL_IPSEC_AES_CTR : OP_ALG_ALGSEL_AES;
342 alginfo_c->algmode = OP_ALG_AAI_CTR;
345 DPAA_SEC_ERR("unsupported cipher alg %d", ses->cipher_alg);
350 caam_aead_alg(dpaa_sec_session *ses, struct alginfo *alginfo)
352 switch (ses->aead_alg) {
353 case RTE_CRYPTO_AEAD_AES_GCM:
354 alginfo->algtype = OP_ALG_ALGSEL_AES;
355 alginfo->algmode = OP_ALG_AAI_GCM;
358 DPAA_SEC_ERR("unsupported AEAD alg %d", ses->aead_alg);
363 /* prepare command block of the session */
365 dpaa_sec_prep_cdb(dpaa_sec_session *ses)
367 struct alginfo alginfo_c = {0}, alginfo_a = {0}, alginfo = {0};
368 int32_t shared_desc_len = 0;
369 struct sec_cdb *cdb = &ses->cdb;
371 #if RTE_BYTE_ORDER == RTE_BIG_ENDIAN
377 memset(cdb, 0, sizeof(struct sec_cdb));
379 if (is_cipher_only(ses)) {
380 caam_cipher_alg(ses, &alginfo_c);
381 if (alginfo_c.algtype == (unsigned int)DPAA_SEC_ALG_UNSUPPORT) {
382 DPAA_SEC_ERR("not supported cipher alg");
386 alginfo_c.key = (size_t)ses->cipher_key.data;
387 alginfo_c.keylen = ses->cipher_key.length;
388 alginfo_c.key_enc_flags = 0;
389 alginfo_c.key_type = RTA_DATA_IMM;
391 shared_desc_len = cnstr_shdsc_blkcipher(
397 } else if (is_auth_only(ses)) {
398 caam_auth_alg(ses, &alginfo_a);
399 if (alginfo_a.algtype == (unsigned int)DPAA_SEC_ALG_UNSUPPORT) {
400 DPAA_SEC_ERR("not supported auth alg");
404 alginfo_a.key = (size_t)ses->auth_key.data;
405 alginfo_a.keylen = ses->auth_key.length;
406 alginfo_a.key_enc_flags = 0;
407 alginfo_a.key_type = RTA_DATA_IMM;
409 shared_desc_len = cnstr_shdsc_hmac(cdb->sh_desc, true,
413 } else if (is_aead(ses)) {
414 caam_aead_alg(ses, &alginfo);
415 if (alginfo.algtype == (unsigned int)DPAA_SEC_ALG_UNSUPPORT) {
416 DPAA_SEC_ERR("not supported aead alg");
419 alginfo.key = (size_t)ses->aead_key.data;
420 alginfo.keylen = ses->aead_key.length;
421 alginfo.key_enc_flags = 0;
422 alginfo.key_type = RTA_DATA_IMM;
424 if (ses->dir == DIR_ENC)
425 shared_desc_len = cnstr_shdsc_gcm_encap(
426 cdb->sh_desc, true, swap,
431 shared_desc_len = cnstr_shdsc_gcm_decap(
432 cdb->sh_desc, true, swap,
437 caam_cipher_alg(ses, &alginfo_c);
438 if (alginfo_c.algtype == (unsigned int)DPAA_SEC_ALG_UNSUPPORT) {
439 DPAA_SEC_ERR("not supported cipher alg");
443 alginfo_c.key = (size_t)ses->cipher_key.data;
444 alginfo_c.keylen = ses->cipher_key.length;
445 alginfo_c.key_enc_flags = 0;
446 alginfo_c.key_type = RTA_DATA_IMM;
448 caam_auth_alg(ses, &alginfo_a);
449 if (alginfo_a.algtype == (unsigned int)DPAA_SEC_ALG_UNSUPPORT) {
450 DPAA_SEC_ERR("not supported auth alg");
454 alginfo_a.key = (size_t)ses->auth_key.data;
455 alginfo_a.keylen = ses->auth_key.length;
456 alginfo_a.key_enc_flags = 0;
457 alginfo_a.key_type = RTA_DATA_IMM;
459 cdb->sh_desc[0] = alginfo_c.keylen;
460 cdb->sh_desc[1] = alginfo_a.keylen;
461 err = rta_inline_query(IPSEC_AUTH_VAR_AES_DEC_BASE_DESC_LEN,
463 (unsigned int *)cdb->sh_desc,
464 &cdb->sh_desc[2], 2);
467 DPAA_SEC_ERR("Crypto: Incorrect key lengths");
470 if (cdb->sh_desc[2] & 1)
471 alginfo_c.key_type = RTA_DATA_IMM;
473 alginfo_c.key = (size_t)dpaa_mem_vtop(
474 (void *)(size_t)alginfo_c.key);
475 alginfo_c.key_type = RTA_DATA_PTR;
477 if (cdb->sh_desc[2] & (1<<1))
478 alginfo_a.key_type = RTA_DATA_IMM;
480 alginfo_a.key = (size_t)dpaa_mem_vtop(
481 (void *)(size_t)alginfo_a.key);
482 alginfo_a.key_type = RTA_DATA_PTR;
487 if (is_proto_ipsec(ses)) {
488 if (ses->dir == DIR_ENC) {
489 shared_desc_len = cnstr_shdsc_ipsec_new_encap(
491 true, swap, &ses->encap_pdb,
492 (uint8_t *)&ses->ip4_hdr,
493 &alginfo_c, &alginfo_a);
494 } else if (ses->dir == DIR_DEC) {
495 shared_desc_len = cnstr_shdsc_ipsec_new_decap(
497 true, swap, &ses->decap_pdb,
498 &alginfo_c, &alginfo_a);
501 /* Auth_only_len is set as 0 here and it will be
502 * overwritten in fd for each packet.
504 shared_desc_len = cnstr_shdsc_authenc(cdb->sh_desc,
505 true, swap, &alginfo_c, &alginfo_a,
507 ses->digest_length, ses->dir);
511 if (shared_desc_len < 0) {
512 DPAA_SEC_ERR("error in preparing command block");
513 return shared_desc_len;
516 cdb->sh_hdr.hi.field.idlen = shared_desc_len;
517 cdb->sh_hdr.hi.word = rte_cpu_to_be_32(cdb->sh_hdr.hi.word);
518 cdb->sh_hdr.lo.word = rte_cpu_to_be_32(cdb->sh_hdr.lo.word);
523 /* qp is lockless, should be accessed by only one thread */
525 dpaa_sec_deq(struct dpaa_sec_qp *qp, struct rte_crypto_op **ops, int nb_ops)
528 unsigned int pkts = 0;
530 struct qm_dqrr_entry *dq;
533 ret = qman_set_vdq(fq, (nb_ops > DPAA_MAX_DEQUEUE_NUM_FRAMES) ?
534 DPAA_MAX_DEQUEUE_NUM_FRAMES : nb_ops);
539 const struct qm_fd *fd;
540 struct dpaa_sec_job *job;
541 struct dpaa_sec_op_ctx *ctx;
542 struct rte_crypto_op *op;
544 dq = qman_dequeue(fq);
549 /* sg is embedded in an op ctx,
550 * sg[0] is for output
553 job = dpaa_mem_ptov(qm_fd_addr_get64(fd));
555 ctx = container_of(job, struct dpaa_sec_op_ctx, job);
556 ctx->fd_status = fd->status;
558 if (op->sess_type == RTE_CRYPTO_OP_SECURITY_SESSION) {
559 struct qm_sg_entry *sg_out;
562 sg_out = &job->sg[0];
563 hw_sg_to_cpu(sg_out);
564 len = sg_out->length;
565 op->sym->m_src->pkt_len = len;
566 op->sym->m_src->data_len = len;
568 if (!ctx->fd_status) {
569 op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
571 DPAA_SEC_DP_WARN("SEC return err:0x%x", ctx->fd_status);
572 op->status = RTE_CRYPTO_OP_STATUS_ERROR;
576 /* report op status to sym->op and then free the ctx memeory */
577 rte_mempool_put(ctx->ctx_pool, (void *)ctx);
579 qman_dqrr_consume(fq, dq);
580 } while (fq->flags & QMAN_FQ_STATE_VDQCR);
585 static inline struct dpaa_sec_job *
586 build_auth_only_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
588 struct rte_crypto_sym_op *sym = op->sym;
589 struct rte_mbuf *mbuf = sym->m_src;
590 struct dpaa_sec_job *cf;
591 struct dpaa_sec_op_ctx *ctx;
592 struct qm_sg_entry *sg, *out_sg, *in_sg;
593 phys_addr_t start_addr;
594 uint8_t *old_digest, extra_segs;
601 if ((mbuf->nb_segs + extra_segs) > MAX_SG_ENTRIES) {
602 DPAA_SEC_DP_ERR("Auth: Max sec segs supported is %d",
606 ctx = dpaa_sec_alloc_ctx(ses);
612 old_digest = ctx->digest;
616 qm_sg_entry_set64(out_sg, sym->auth.digest.phys_addr);
617 out_sg->length = ses->digest_length;
618 cpu_to_hw_sg(out_sg);
622 /* need to extend the input to a compound frame */
623 in_sg->extension = 1;
625 in_sg->length = sym->auth.data.length;
626 qm_sg_entry_set64(in_sg, dpaa_mem_vtop(&cf->sg[2]));
630 qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
631 sg->length = mbuf->data_len - sym->auth.data.offset;
632 sg->offset = sym->auth.data.offset;
634 /* Successive segs */
639 qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
640 sg->length = mbuf->data_len;
644 if (is_decode(ses)) {
645 /* Digest verification case */
648 rte_memcpy(old_digest, sym->auth.digest.data,
650 start_addr = dpaa_mem_vtop(old_digest);
651 qm_sg_entry_set64(sg, start_addr);
652 sg->length = ses->digest_length;
653 in_sg->length += ses->digest_length;
655 /* Digest calculation case */
656 sg->length -= ses->digest_length;
667 * |<----data_len------->|
668 * |ip_header|ah_header|icv|payload|
673 static inline struct dpaa_sec_job *
674 build_auth_only(struct rte_crypto_op *op, dpaa_sec_session *ses)
676 struct rte_crypto_sym_op *sym = op->sym;
677 struct rte_mbuf *mbuf = sym->m_src;
678 struct dpaa_sec_job *cf;
679 struct dpaa_sec_op_ctx *ctx;
680 struct qm_sg_entry *sg;
681 rte_iova_t start_addr;
684 ctx = dpaa_sec_alloc_ctx(ses);
690 old_digest = ctx->digest;
692 start_addr = rte_pktmbuf_iova(mbuf);
695 qm_sg_entry_set64(sg, sym->auth.digest.phys_addr);
696 sg->length = ses->digest_length;
701 if (is_decode(ses)) {
702 /* need to extend the input to a compound frame */
704 qm_sg_entry_set64(sg, dpaa_mem_vtop(&cf->sg[2]));
705 sg->length = sym->auth.data.length + ses->digest_length;
710 /* hash result or digest, save digest first */
711 rte_memcpy(old_digest, sym->auth.digest.data,
713 qm_sg_entry_set64(sg, start_addr + sym->auth.data.offset);
714 sg->length = sym->auth.data.length;
717 /* let's check digest by hw */
718 start_addr = dpaa_mem_vtop(old_digest);
720 qm_sg_entry_set64(sg, start_addr);
721 sg->length = ses->digest_length;
725 qm_sg_entry_set64(sg, start_addr + sym->auth.data.offset);
726 sg->length = sym->auth.data.length;
734 static inline struct dpaa_sec_job *
735 build_cipher_only_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
737 struct rte_crypto_sym_op *sym = op->sym;
738 struct dpaa_sec_job *cf;
739 struct dpaa_sec_op_ctx *ctx;
740 struct qm_sg_entry *sg, *out_sg, *in_sg;
741 struct rte_mbuf *mbuf;
743 uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
748 req_segs = mbuf->nb_segs + sym->m_src->nb_segs + 3;
751 req_segs = mbuf->nb_segs * 2 + 3;
754 if (req_segs > MAX_SG_ENTRIES) {
755 DPAA_SEC_DP_ERR("Cipher: Max sec segs supported is %d",
760 ctx = dpaa_sec_alloc_ctx(ses);
769 out_sg->extension = 1;
770 out_sg->length = sym->cipher.data.length;
771 qm_sg_entry_set64(out_sg, dpaa_mem_vtop(&cf->sg[2]));
772 cpu_to_hw_sg(out_sg);
776 qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
777 sg->length = mbuf->data_len - sym->cipher.data.offset;
778 sg->offset = sym->cipher.data.offset;
780 /* Successive segs */
785 qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
786 sg->length = mbuf->data_len;
795 in_sg->extension = 1;
797 in_sg->length = sym->cipher.data.length + ses->iv.length;
800 qm_sg_entry_set64(in_sg, dpaa_mem_vtop(sg));
804 qm_sg_entry_set64(sg, dpaa_mem_vtop(IV_ptr));
805 sg->length = ses->iv.length;
810 qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
811 sg->length = mbuf->data_len - sym->cipher.data.offset;
812 sg->offset = sym->cipher.data.offset;
814 /* Successive segs */
819 qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
820 sg->length = mbuf->data_len;
829 static inline struct dpaa_sec_job *
830 build_cipher_only(struct rte_crypto_op *op, dpaa_sec_session *ses)
832 struct rte_crypto_sym_op *sym = op->sym;
833 struct dpaa_sec_job *cf;
834 struct dpaa_sec_op_ctx *ctx;
835 struct qm_sg_entry *sg;
836 rte_iova_t src_start_addr, dst_start_addr;
837 uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
840 ctx = dpaa_sec_alloc_ctx(ses);
847 src_start_addr = rte_pktmbuf_iova(sym->m_src);
850 dst_start_addr = rte_pktmbuf_iova(sym->m_dst);
852 dst_start_addr = src_start_addr;
856 qm_sg_entry_set64(sg, dst_start_addr + sym->cipher.data.offset);
857 sg->length = sym->cipher.data.length + ses->iv.length;
863 /* need to extend the input to a compound frame */
866 sg->length = sym->cipher.data.length + ses->iv.length;
867 qm_sg_entry_set64(sg, dpaa_mem_vtop(&cf->sg[2]));
871 qm_sg_entry_set64(sg, dpaa_mem_vtop(IV_ptr));
872 sg->length = ses->iv.length;
876 qm_sg_entry_set64(sg, src_start_addr + sym->cipher.data.offset);
877 sg->length = sym->cipher.data.length;
884 static inline struct dpaa_sec_job *
885 build_cipher_auth_gcm_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
887 struct rte_crypto_sym_op *sym = op->sym;
888 struct dpaa_sec_job *cf;
889 struct dpaa_sec_op_ctx *ctx;
890 struct qm_sg_entry *sg, *out_sg, *in_sg;
891 struct rte_mbuf *mbuf;
893 uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
898 req_segs = mbuf->nb_segs + sym->m_src->nb_segs + 4;
901 req_segs = mbuf->nb_segs * 2 + 4;
904 if (ses->auth_only_len)
907 if (req_segs > MAX_SG_ENTRIES) {
908 DPAA_SEC_DP_ERR("AEAD: Max sec segs supported is %d",
913 ctx = dpaa_sec_alloc_ctx(ses);
920 rte_prefetch0(cf->sg);
924 out_sg->extension = 1;
926 out_sg->length = sym->aead.data.length + ses->auth_only_len
927 + ses->digest_length;
929 out_sg->length = sym->aead.data.length + ses->auth_only_len;
931 /* output sg entries */
933 qm_sg_entry_set64(out_sg, dpaa_mem_vtop(sg));
934 cpu_to_hw_sg(out_sg);
937 qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
938 sg->length = mbuf->data_len - sym->aead.data.offset +
940 sg->offset = sym->aead.data.offset - ses->auth_only_len;
942 /* Successive segs */
947 qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
948 sg->length = mbuf->data_len;
951 sg->length -= ses->digest_length;
953 if (is_encode(ses)) {
955 /* set auth output */
957 qm_sg_entry_set64(sg, sym->aead.digest.phys_addr);
958 sg->length = ses->digest_length;
966 in_sg->extension = 1;
969 in_sg->length = ses->iv.length + sym->aead.data.length
970 + ses->auth_only_len;
972 in_sg->length = ses->iv.length + sym->aead.data.length
973 + ses->auth_only_len + ses->digest_length;
975 /* input sg entries */
977 qm_sg_entry_set64(in_sg, dpaa_mem_vtop(sg));
981 qm_sg_entry_set64(sg, dpaa_mem_vtop(IV_ptr));
982 sg->length = ses->iv.length;
985 /* 2nd seg auth only */
986 if (ses->auth_only_len) {
988 qm_sg_entry_set64(sg, dpaa_mem_vtop(sym->aead.aad.data));
989 sg->length = ses->auth_only_len;
995 qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
996 sg->length = mbuf->data_len - sym->aead.data.offset;
997 sg->offset = sym->aead.data.offset;
999 /* Successive segs */
1004 qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1005 sg->length = mbuf->data_len;
1009 if (is_decode(ses)) {
1012 memcpy(ctx->digest, sym->aead.digest.data,
1013 ses->digest_length);
1014 qm_sg_entry_set64(sg, dpaa_mem_vtop(ctx->digest));
1015 sg->length = ses->digest_length;
1023 static inline struct dpaa_sec_job *
1024 build_cipher_auth_gcm(struct rte_crypto_op *op, dpaa_sec_session *ses)
1026 struct rte_crypto_sym_op *sym = op->sym;
1027 struct dpaa_sec_job *cf;
1028 struct dpaa_sec_op_ctx *ctx;
1029 struct qm_sg_entry *sg;
1030 uint32_t length = 0;
1031 rte_iova_t src_start_addr, dst_start_addr;
1032 uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1035 src_start_addr = sym->m_src->buf_iova + sym->m_src->data_off;
1038 dst_start_addr = sym->m_dst->buf_iova + sym->m_dst->data_off;
1040 dst_start_addr = src_start_addr;
1042 ctx = dpaa_sec_alloc_ctx(ses);
1050 rte_prefetch0(cf->sg);
1052 qm_sg_entry_set64(&cf->sg[1], dpaa_mem_vtop(sg));
1053 if (is_encode(ses)) {
1054 qm_sg_entry_set64(sg, dpaa_mem_vtop(IV_ptr));
1055 sg->length = ses->iv.length;
1056 length += sg->length;
1060 if (ses->auth_only_len) {
1061 qm_sg_entry_set64(sg,
1062 dpaa_mem_vtop(sym->aead.aad.data));
1063 sg->length = ses->auth_only_len;
1064 length += sg->length;
1068 qm_sg_entry_set64(sg, src_start_addr + sym->aead.data.offset);
1069 sg->length = sym->aead.data.length;
1070 length += sg->length;
1074 qm_sg_entry_set64(sg, dpaa_mem_vtop(IV_ptr));
1075 sg->length = ses->iv.length;
1076 length += sg->length;
1080 if (ses->auth_only_len) {
1081 qm_sg_entry_set64(sg,
1082 dpaa_mem_vtop(sym->aead.aad.data));
1083 sg->length = ses->auth_only_len;
1084 length += sg->length;
1088 qm_sg_entry_set64(sg, src_start_addr + sym->aead.data.offset);
1089 sg->length = sym->aead.data.length;
1090 length += sg->length;
1093 memcpy(ctx->digest, sym->aead.digest.data,
1094 ses->digest_length);
1097 qm_sg_entry_set64(sg, dpaa_mem_vtop(ctx->digest));
1098 sg->length = ses->digest_length;
1099 length += sg->length;
1103 /* input compound frame */
1104 cf->sg[1].length = length;
1105 cf->sg[1].extension = 1;
1106 cf->sg[1].final = 1;
1107 cpu_to_hw_sg(&cf->sg[1]);
1111 qm_sg_entry_set64(&cf->sg[0], dpaa_mem_vtop(sg));
1112 qm_sg_entry_set64(sg,
1113 dst_start_addr + sym->aead.data.offset - ses->auth_only_len);
1114 sg->length = sym->aead.data.length + ses->auth_only_len;
1115 length = sg->length;
1116 if (is_encode(ses)) {
1118 /* set auth output */
1120 qm_sg_entry_set64(sg, sym->aead.digest.phys_addr);
1121 sg->length = ses->digest_length;
1122 length += sg->length;
1127 /* output compound frame */
1128 cf->sg[0].length = length;
1129 cf->sg[0].extension = 1;
1130 cpu_to_hw_sg(&cf->sg[0]);
1135 static inline struct dpaa_sec_job *
1136 build_cipher_auth_sg(struct rte_crypto_op *op, dpaa_sec_session *ses)
1138 struct rte_crypto_sym_op *sym = op->sym;
1139 struct dpaa_sec_job *cf;
1140 struct dpaa_sec_op_ctx *ctx;
1141 struct qm_sg_entry *sg, *out_sg, *in_sg;
1142 struct rte_mbuf *mbuf;
1144 uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1149 req_segs = mbuf->nb_segs + sym->m_src->nb_segs + 4;
1152 req_segs = mbuf->nb_segs * 2 + 4;
1155 if (req_segs > MAX_SG_ENTRIES) {
1156 DPAA_SEC_DP_ERR("Cipher-Auth: Max sec segs supported is %d",
1161 ctx = dpaa_sec_alloc_ctx(ses);
1168 rte_prefetch0(cf->sg);
1171 out_sg = &cf->sg[0];
1172 out_sg->extension = 1;
1174 out_sg->length = sym->auth.data.length + ses->digest_length;
1176 out_sg->length = sym->auth.data.length;
1178 /* output sg entries */
1180 qm_sg_entry_set64(out_sg, dpaa_mem_vtop(sg));
1181 cpu_to_hw_sg(out_sg);
1184 qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1185 sg->length = mbuf->data_len - sym->auth.data.offset;
1186 sg->offset = sym->auth.data.offset;
1188 /* Successive segs */
1193 qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1194 sg->length = mbuf->data_len;
1197 sg->length -= ses->digest_length;
1199 if (is_encode(ses)) {
1201 /* set auth output */
1203 qm_sg_entry_set64(sg, sym->auth.digest.phys_addr);
1204 sg->length = ses->digest_length;
1212 in_sg->extension = 1;
1215 in_sg->length = ses->iv.length + sym->auth.data.length;
1217 in_sg->length = ses->iv.length + sym->auth.data.length
1218 + ses->digest_length;
1220 /* input sg entries */
1222 qm_sg_entry_set64(in_sg, dpaa_mem_vtop(sg));
1223 cpu_to_hw_sg(in_sg);
1226 qm_sg_entry_set64(sg, dpaa_mem_vtop(IV_ptr));
1227 sg->length = ses->iv.length;
1232 qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1233 sg->length = mbuf->data_len - sym->auth.data.offset;
1234 sg->offset = sym->auth.data.offset;
1236 /* Successive segs */
1241 qm_sg_entry_set64(sg, rte_pktmbuf_mtophys(mbuf));
1242 sg->length = mbuf->data_len;
1246 sg->length -= ses->digest_length;
1247 if (is_decode(ses)) {
1250 memcpy(ctx->digest, sym->auth.digest.data,
1251 ses->digest_length);
1252 qm_sg_entry_set64(sg, dpaa_mem_vtop(ctx->digest));
1253 sg->length = ses->digest_length;
1261 static inline struct dpaa_sec_job *
1262 build_cipher_auth(struct rte_crypto_op *op, dpaa_sec_session *ses)
1264 struct rte_crypto_sym_op *sym = op->sym;
1265 struct dpaa_sec_job *cf;
1266 struct dpaa_sec_op_ctx *ctx;
1267 struct qm_sg_entry *sg;
1268 rte_iova_t src_start_addr, dst_start_addr;
1269 uint32_t length = 0;
1270 uint8_t *IV_ptr = rte_crypto_op_ctod_offset(op, uint8_t *,
1273 src_start_addr = sym->m_src->buf_iova + sym->m_src->data_off;
1275 dst_start_addr = sym->m_dst->buf_iova + sym->m_dst->data_off;
1277 dst_start_addr = src_start_addr;
1279 ctx = dpaa_sec_alloc_ctx(ses);
1287 rte_prefetch0(cf->sg);
1289 qm_sg_entry_set64(&cf->sg[1], dpaa_mem_vtop(sg));
1290 if (is_encode(ses)) {
1291 qm_sg_entry_set64(sg, dpaa_mem_vtop(IV_ptr));
1292 sg->length = ses->iv.length;
1293 length += sg->length;
1297 qm_sg_entry_set64(sg, src_start_addr + sym->auth.data.offset);
1298 sg->length = sym->auth.data.length;
1299 length += sg->length;
1303 qm_sg_entry_set64(sg, dpaa_mem_vtop(IV_ptr));
1304 sg->length = ses->iv.length;
1305 length += sg->length;
1310 qm_sg_entry_set64(sg, src_start_addr + sym->auth.data.offset);
1311 sg->length = sym->auth.data.length;
1312 length += sg->length;
1315 memcpy(ctx->digest, sym->auth.digest.data,
1316 ses->digest_length);
1319 qm_sg_entry_set64(sg, dpaa_mem_vtop(ctx->digest));
1320 sg->length = ses->digest_length;
1321 length += sg->length;
1325 /* input compound frame */
1326 cf->sg[1].length = length;
1327 cf->sg[1].extension = 1;
1328 cf->sg[1].final = 1;
1329 cpu_to_hw_sg(&cf->sg[1]);
1333 qm_sg_entry_set64(&cf->sg[0], dpaa_mem_vtop(sg));
1334 qm_sg_entry_set64(sg, dst_start_addr + sym->cipher.data.offset);
1335 sg->length = sym->cipher.data.length;
1336 length = sg->length;
1337 if (is_encode(ses)) {
1339 /* set auth output */
1341 qm_sg_entry_set64(sg, sym->auth.digest.phys_addr);
1342 sg->length = ses->digest_length;
1343 length += sg->length;
1348 /* output compound frame */
1349 cf->sg[0].length = length;
1350 cf->sg[0].extension = 1;
1351 cpu_to_hw_sg(&cf->sg[0]);
1356 static inline struct dpaa_sec_job *
1357 build_proto(struct rte_crypto_op *op, dpaa_sec_session *ses)
1359 struct rte_crypto_sym_op *sym = op->sym;
1360 struct dpaa_sec_job *cf;
1361 struct dpaa_sec_op_ctx *ctx;
1362 struct qm_sg_entry *sg;
1363 phys_addr_t src_start_addr, dst_start_addr;
1365 ctx = dpaa_sec_alloc_ctx(ses);
1371 src_start_addr = rte_pktmbuf_mtophys(sym->m_src);
1374 dst_start_addr = rte_pktmbuf_mtophys(sym->m_dst);
1376 dst_start_addr = src_start_addr;
1380 qm_sg_entry_set64(sg, src_start_addr);
1381 sg->length = sym->m_src->pkt_len;
1385 sym->m_src->packet_type &= ~RTE_PTYPE_L4_MASK;
1388 qm_sg_entry_set64(sg, dst_start_addr);
1389 sg->length = sym->m_src->buf_len - sym->m_src->data_off;
1396 dpaa_sec_enqueue_burst(void *qp, struct rte_crypto_op **ops,
1399 /* Function to transmit the frames to given device and queuepair */
1401 struct dpaa_sec_qp *dpaa_qp = (struct dpaa_sec_qp *)qp;
1402 uint16_t num_tx = 0;
1403 struct qm_fd fds[DPAA_SEC_BURST], *fd;
1404 uint32_t frames_to_send;
1405 struct rte_crypto_op *op;
1406 struct dpaa_sec_job *cf;
1407 dpaa_sec_session *ses;
1408 uint32_t auth_only_len;
1409 struct qman_fq *inq[DPAA_SEC_BURST];
1412 frames_to_send = (nb_ops > DPAA_SEC_BURST) ?
1413 DPAA_SEC_BURST : nb_ops;
1414 for (loop = 0; loop < frames_to_send; loop++) {
1416 switch (op->sess_type) {
1417 case RTE_CRYPTO_OP_WITH_SESSION:
1418 ses = (dpaa_sec_session *)
1419 get_sym_session_private_data(
1421 cryptodev_driver_id);
1423 case RTE_CRYPTO_OP_SECURITY_SESSION:
1424 ses = (dpaa_sec_session *)
1425 get_sec_session_private_data(
1426 op->sym->sec_session);
1430 "sessionless crypto op not supported");
1431 frames_to_send = loop;
1435 if (unlikely(!ses->qp || ses->qp != qp)) {
1436 DPAA_SEC_DP_ERR("sess->qp - %p qp %p",
1438 if (dpaa_sec_attach_sess_q(qp, ses)) {
1439 frames_to_send = loop;
1445 auth_only_len = op->sym->auth.data.length -
1446 op->sym->cipher.data.length;
1447 if (rte_pktmbuf_is_contiguous(op->sym->m_src)) {
1448 if (is_auth_only(ses)) {
1449 cf = build_auth_only(op, ses);
1450 } else if (is_cipher_only(ses)) {
1451 cf = build_cipher_only(op, ses);
1452 } else if (is_aead(ses)) {
1453 cf = build_cipher_auth_gcm(op, ses);
1454 auth_only_len = ses->auth_only_len;
1455 } else if (is_auth_cipher(ses)) {
1456 cf = build_cipher_auth(op, ses);
1457 } else if (is_proto_ipsec(ses)) {
1458 cf = build_proto(op, ses);
1460 DPAA_SEC_DP_ERR("not supported ops");
1461 frames_to_send = loop;
1466 if (is_auth_only(ses)) {
1467 cf = build_auth_only_sg(op, ses);
1468 } else if (is_cipher_only(ses)) {
1469 cf = build_cipher_only_sg(op, ses);
1470 } else if (is_aead(ses)) {
1471 cf = build_cipher_auth_gcm_sg(op, ses);
1472 auth_only_len = ses->auth_only_len;
1473 } else if (is_auth_cipher(ses)) {
1474 cf = build_cipher_auth_sg(op, ses);
1476 DPAA_SEC_DP_ERR("not supported ops");
1477 frames_to_send = loop;
1482 if (unlikely(!cf)) {
1483 frames_to_send = loop;
1489 inq[loop] = ses->inq;
1490 fd->opaque_addr = 0;
1492 qm_fd_addr_set64(fd, dpaa_mem_vtop(cf->sg));
1493 fd->_format1 = qm_fd_compound;
1494 fd->length29 = 2 * sizeof(struct qm_sg_entry);
1495 /* Auth_only_len is set as 0 in descriptor and it is
1496 * overwritten here in the fd.cmd which will update
1500 fd->cmd = 0x80000000 | auth_only_len;
1505 while (loop < frames_to_send) {
1506 loop += qman_enqueue_multi_fq(&inq[loop], &fds[loop],
1507 frames_to_send - loop);
1509 nb_ops -= frames_to_send;
1510 num_tx += frames_to_send;
1513 dpaa_qp->tx_pkts += num_tx;
1514 dpaa_qp->tx_errs += nb_ops - num_tx;
1520 dpaa_sec_dequeue_burst(void *qp, struct rte_crypto_op **ops,
1524 struct dpaa_sec_qp *dpaa_qp = (struct dpaa_sec_qp *)qp;
1526 num_rx = dpaa_sec_deq(dpaa_qp, ops, nb_ops);
1528 dpaa_qp->rx_pkts += num_rx;
1529 dpaa_qp->rx_errs += nb_ops - num_rx;
1531 DPAA_SEC_DP_DEBUG("SEC Received %d Packets\n", num_rx);
1536 /** Release queue pair */
1538 dpaa_sec_queue_pair_release(struct rte_cryptodev *dev,
1541 struct dpaa_sec_dev_private *internals;
1542 struct dpaa_sec_qp *qp = NULL;
1544 PMD_INIT_FUNC_TRACE();
1546 DPAA_SEC_DEBUG("dev =%p, queue =%d", dev, qp_id);
1548 internals = dev->data->dev_private;
1549 if (qp_id >= internals->max_nb_queue_pairs) {
1550 DPAA_SEC_ERR("Max supported qpid %d",
1551 internals->max_nb_queue_pairs);
1555 qp = &internals->qps[qp_id];
1556 qp->internals = NULL;
1557 dev->data->queue_pairs[qp_id] = NULL;
1562 /** Setup a queue pair */
1564 dpaa_sec_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
1565 __rte_unused const struct rte_cryptodev_qp_conf *qp_conf,
1566 __rte_unused int socket_id,
1567 __rte_unused struct rte_mempool *session_pool)
1569 struct dpaa_sec_dev_private *internals;
1570 struct dpaa_sec_qp *qp = NULL;
1572 DPAA_SEC_DEBUG("dev =%p, queue =%d, conf =%p", dev, qp_id, qp_conf);
1574 internals = dev->data->dev_private;
1575 if (qp_id >= internals->max_nb_queue_pairs) {
1576 DPAA_SEC_ERR("Max supported qpid %d",
1577 internals->max_nb_queue_pairs);
1581 qp = &internals->qps[qp_id];
1582 qp->internals = internals;
1583 dev->data->queue_pairs[qp_id] = qp;
1588 /** Return the number of allocated queue pairs */
1590 dpaa_sec_queue_pair_count(struct rte_cryptodev *dev)
1592 PMD_INIT_FUNC_TRACE();
1594 return dev->data->nb_queue_pairs;
1597 /** Returns the size of session structure */
1599 dpaa_sec_sym_session_get_size(struct rte_cryptodev *dev __rte_unused)
1601 PMD_INIT_FUNC_TRACE();
1603 return sizeof(dpaa_sec_session);
1607 dpaa_sec_cipher_init(struct rte_cryptodev *dev __rte_unused,
1608 struct rte_crypto_sym_xform *xform,
1609 dpaa_sec_session *session)
1611 session->cipher_alg = xform->cipher.algo;
1612 session->iv.length = xform->cipher.iv.length;
1613 session->iv.offset = xform->cipher.iv.offset;
1614 session->cipher_key.data = rte_zmalloc(NULL, xform->cipher.key.length,
1615 RTE_CACHE_LINE_SIZE);
1616 if (session->cipher_key.data == NULL && xform->cipher.key.length > 0) {
1617 DPAA_SEC_ERR("No Memory for cipher key");
1620 session->cipher_key.length = xform->cipher.key.length;
1622 memcpy(session->cipher_key.data, xform->cipher.key.data,
1623 xform->cipher.key.length);
1624 session->dir = (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ?
1631 dpaa_sec_auth_init(struct rte_cryptodev *dev __rte_unused,
1632 struct rte_crypto_sym_xform *xform,
1633 dpaa_sec_session *session)
1635 session->auth_alg = xform->auth.algo;
1636 session->auth_key.data = rte_zmalloc(NULL, xform->auth.key.length,
1637 RTE_CACHE_LINE_SIZE);
1638 if (session->auth_key.data == NULL && xform->auth.key.length > 0) {
1639 DPAA_SEC_ERR("No Memory for auth key");
1642 session->auth_key.length = xform->auth.key.length;
1643 session->digest_length = xform->auth.digest_length;
1645 memcpy(session->auth_key.data, xform->auth.key.data,
1646 xform->auth.key.length);
1647 session->dir = (xform->auth.op == RTE_CRYPTO_AUTH_OP_GENERATE) ?
1654 dpaa_sec_aead_init(struct rte_cryptodev *dev __rte_unused,
1655 struct rte_crypto_sym_xform *xform,
1656 dpaa_sec_session *session)
1658 session->aead_alg = xform->aead.algo;
1659 session->iv.length = xform->aead.iv.length;
1660 session->iv.offset = xform->aead.iv.offset;
1661 session->auth_only_len = xform->aead.aad_length;
1662 session->aead_key.data = rte_zmalloc(NULL, xform->aead.key.length,
1663 RTE_CACHE_LINE_SIZE);
1664 if (session->aead_key.data == NULL && xform->aead.key.length > 0) {
1665 DPAA_SEC_ERR("No Memory for aead key\n");
1668 session->aead_key.length = xform->aead.key.length;
1669 session->digest_length = xform->aead.digest_length;
1671 memcpy(session->aead_key.data, xform->aead.key.data,
1672 xform->aead.key.length);
1673 session->dir = (xform->aead.op == RTE_CRYPTO_AEAD_OP_ENCRYPT) ?
1679 static struct qman_fq *
1680 dpaa_sec_attach_rxq(struct dpaa_sec_dev_private *qi)
1684 for (i = 0; i < qi->max_nb_sessions; i++) {
1685 if (qi->inq_attach[i] == 0) {
1686 qi->inq_attach[i] = 1;
1690 DPAA_SEC_WARN("All ses session in use %x", qi->max_nb_sessions);
1696 dpaa_sec_detach_rxq(struct dpaa_sec_dev_private *qi, struct qman_fq *fq)
1700 for (i = 0; i < qi->max_nb_sessions; i++) {
1701 if (&qi->inq[i] == fq) {
1702 qman_retire_fq(fq, NULL);
1704 qi->inq_attach[i] = 0;
1712 dpaa_sec_attach_sess_q(struct dpaa_sec_qp *qp, dpaa_sec_session *sess)
1717 ret = dpaa_sec_prep_cdb(sess);
1719 DPAA_SEC_ERR("Unable to prepare sec cdb");
1722 if (unlikely(!RTE_PER_LCORE(dpaa_io))) {
1723 ret = rte_dpaa_portal_init((void *)0);
1725 DPAA_SEC_ERR("Failure in affining portal");
1729 ret = dpaa_sec_init_rx(sess->inq, dpaa_mem_vtop(&sess->cdb),
1730 qman_fq_fqid(&qp->outq));
1732 DPAA_SEC_ERR("Unable to init sec queue");
1738 dpaa_sec_set_session_parameters(struct rte_cryptodev *dev,
1739 struct rte_crypto_sym_xform *xform, void *sess)
1741 struct dpaa_sec_dev_private *internals = dev->data->dev_private;
1742 dpaa_sec_session *session = sess;
1744 PMD_INIT_FUNC_TRACE();
1746 if (unlikely(sess == NULL)) {
1747 DPAA_SEC_ERR("invalid session struct");
1751 /* Default IV length = 0 */
1752 session->iv.length = 0;
1755 if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER && xform->next == NULL) {
1756 session->auth_alg = RTE_CRYPTO_AUTH_NULL;
1757 dpaa_sec_cipher_init(dev, xform, session);
1759 /* Authentication Only */
1760 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
1761 xform->next == NULL) {
1762 session->cipher_alg = RTE_CRYPTO_CIPHER_NULL;
1763 dpaa_sec_auth_init(dev, xform, session);
1765 /* Cipher then Authenticate */
1766 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
1767 xform->next->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
1768 if (xform->cipher.op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
1769 dpaa_sec_cipher_init(dev, xform, session);
1770 dpaa_sec_auth_init(dev, xform->next, session);
1772 DPAA_SEC_ERR("Not supported: Auth then Cipher");
1776 /* Authenticate then Cipher */
1777 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
1778 xform->next->type == RTE_CRYPTO_SYM_XFORM_CIPHER) {
1779 if (xform->next->cipher.op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
1780 dpaa_sec_auth_init(dev, xform, session);
1781 dpaa_sec_cipher_init(dev, xform->next, session);
1783 DPAA_SEC_ERR("Not supported: Auth then Cipher");
1787 /* AEAD operation for AES-GCM kind of Algorithms */
1788 } else if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD &&
1789 xform->next == NULL) {
1790 dpaa_sec_aead_init(dev, xform, session);
1793 DPAA_SEC_ERR("Invalid crypto type");
1796 session->ctx_pool = internals->ctx_pool;
1797 session->inq = dpaa_sec_attach_rxq(internals);
1798 if (session->inq == NULL) {
1799 DPAA_SEC_ERR("unable to attach sec queue");
1806 rte_free(session->cipher_key.data);
1807 rte_free(session->auth_key.data);
1808 memset(session, 0, sizeof(dpaa_sec_session));
1814 dpaa_sec_sym_session_configure(struct rte_cryptodev *dev,
1815 struct rte_crypto_sym_xform *xform,
1816 struct rte_cryptodev_sym_session *sess,
1817 struct rte_mempool *mempool)
1819 void *sess_private_data;
1822 PMD_INIT_FUNC_TRACE();
1824 if (rte_mempool_get(mempool, &sess_private_data)) {
1825 DPAA_SEC_ERR("Couldn't get object from session mempool");
1829 ret = dpaa_sec_set_session_parameters(dev, xform, sess_private_data);
1831 DPAA_SEC_ERR("failed to configure session parameters");
1833 /* Return session to mempool */
1834 rte_mempool_put(mempool, sess_private_data);
1838 set_sym_session_private_data(sess, dev->driver_id,
1845 /** Clear the memory of session so it doesn't leave key material behind */
1847 dpaa_sec_sym_session_clear(struct rte_cryptodev *dev,
1848 struct rte_cryptodev_sym_session *sess)
1850 struct dpaa_sec_dev_private *qi = dev->data->dev_private;
1851 uint8_t index = dev->driver_id;
1852 void *sess_priv = get_sym_session_private_data(sess, index);
1854 PMD_INIT_FUNC_TRACE();
1856 dpaa_sec_session *s = (dpaa_sec_session *)sess_priv;
1859 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
1862 dpaa_sec_detach_rxq(qi, s->inq);
1863 rte_free(s->cipher_key.data);
1864 rte_free(s->auth_key.data);
1865 memset(s, 0, sizeof(dpaa_sec_session));
1866 set_sym_session_private_data(sess, index, NULL);
1867 rte_mempool_put(sess_mp, sess_priv);
1872 dpaa_sec_set_ipsec_session(__rte_unused struct rte_cryptodev *dev,
1873 struct rte_security_session_conf *conf,
1876 struct dpaa_sec_dev_private *internals = dev->data->dev_private;
1877 struct rte_security_ipsec_xform *ipsec_xform = &conf->ipsec;
1878 struct rte_crypto_auth_xform *auth_xform;
1879 struct rte_crypto_cipher_xform *cipher_xform;
1880 dpaa_sec_session *session = (dpaa_sec_session *)sess;
1882 PMD_INIT_FUNC_TRACE();
1884 if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
1885 cipher_xform = &conf->crypto_xform->cipher;
1886 auth_xform = &conf->crypto_xform->next->auth;
1888 auth_xform = &conf->crypto_xform->auth;
1889 cipher_xform = &conf->crypto_xform->next->cipher;
1891 session->proto_alg = conf->protocol;
1892 session->cipher_key.data = rte_zmalloc(NULL,
1893 cipher_xform->key.length,
1894 RTE_CACHE_LINE_SIZE);
1895 if (session->cipher_key.data == NULL &&
1896 cipher_xform->key.length > 0) {
1897 DPAA_SEC_ERR("No Memory for cipher key");
1901 session->cipher_key.length = cipher_xform->key.length;
1902 session->auth_key.data = rte_zmalloc(NULL,
1903 auth_xform->key.length,
1904 RTE_CACHE_LINE_SIZE);
1905 if (session->auth_key.data == NULL &&
1906 auth_xform->key.length > 0) {
1907 DPAA_SEC_ERR("No Memory for auth key");
1908 rte_free(session->cipher_key.data);
1911 session->auth_key.length = auth_xform->key.length;
1912 memcpy(session->cipher_key.data, cipher_xform->key.data,
1913 cipher_xform->key.length);
1914 memcpy(session->auth_key.data, auth_xform->key.data,
1915 auth_xform->key.length);
1917 switch (auth_xform->algo) {
1918 case RTE_CRYPTO_AUTH_SHA1_HMAC:
1919 session->auth_alg = RTE_CRYPTO_AUTH_SHA1_HMAC;
1921 case RTE_CRYPTO_AUTH_MD5_HMAC:
1922 session->auth_alg = RTE_CRYPTO_AUTH_MD5_HMAC;
1924 case RTE_CRYPTO_AUTH_SHA256_HMAC:
1925 session->auth_alg = RTE_CRYPTO_AUTH_SHA256_HMAC;
1927 case RTE_CRYPTO_AUTH_SHA384_HMAC:
1928 session->auth_alg = RTE_CRYPTO_AUTH_SHA384_HMAC;
1930 case RTE_CRYPTO_AUTH_SHA512_HMAC:
1931 session->auth_alg = RTE_CRYPTO_AUTH_SHA512_HMAC;
1933 case RTE_CRYPTO_AUTH_AES_CMAC:
1934 session->auth_alg = RTE_CRYPTO_AUTH_AES_CMAC;
1936 case RTE_CRYPTO_AUTH_NULL:
1937 session->auth_alg = RTE_CRYPTO_AUTH_NULL;
1939 case RTE_CRYPTO_AUTH_SHA224_HMAC:
1940 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
1941 case RTE_CRYPTO_AUTH_SNOW3G_UIA2:
1942 case RTE_CRYPTO_AUTH_SHA1:
1943 case RTE_CRYPTO_AUTH_SHA256:
1944 case RTE_CRYPTO_AUTH_SHA512:
1945 case RTE_CRYPTO_AUTH_SHA224:
1946 case RTE_CRYPTO_AUTH_SHA384:
1947 case RTE_CRYPTO_AUTH_MD5:
1948 case RTE_CRYPTO_AUTH_AES_GMAC:
1949 case RTE_CRYPTO_AUTH_KASUMI_F9:
1950 case RTE_CRYPTO_AUTH_AES_CBC_MAC:
1951 case RTE_CRYPTO_AUTH_ZUC_EIA3:
1952 DPAA_SEC_ERR("Crypto: Unsupported auth alg %u",
1956 DPAA_SEC_ERR("Crypto: Undefined Auth specified %u",
1961 switch (cipher_xform->algo) {
1962 case RTE_CRYPTO_CIPHER_AES_CBC:
1963 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CBC;
1965 case RTE_CRYPTO_CIPHER_3DES_CBC:
1966 session->cipher_alg = RTE_CRYPTO_CIPHER_3DES_CBC;
1968 case RTE_CRYPTO_CIPHER_AES_CTR:
1969 session->cipher_alg = RTE_CRYPTO_CIPHER_AES_CTR;
1971 case RTE_CRYPTO_CIPHER_NULL:
1972 case RTE_CRYPTO_CIPHER_SNOW3G_UEA2:
1973 case RTE_CRYPTO_CIPHER_3DES_ECB:
1974 case RTE_CRYPTO_CIPHER_AES_ECB:
1975 case RTE_CRYPTO_CIPHER_KASUMI_F8:
1976 DPAA_SEC_ERR("Crypto: Unsupported Cipher alg %u",
1977 cipher_xform->algo);
1980 DPAA_SEC_ERR("Crypto: Undefined Cipher specified %u",
1981 cipher_xform->algo);
1985 if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
1986 memset(&session->encap_pdb, 0, sizeof(struct ipsec_encap_pdb) +
1987 sizeof(session->ip4_hdr));
1988 session->ip4_hdr.ip_v = IPVERSION;
1989 session->ip4_hdr.ip_hl = 5;
1990 session->ip4_hdr.ip_len = rte_cpu_to_be_16(
1991 sizeof(session->ip4_hdr));
1992 session->ip4_hdr.ip_tos = ipsec_xform->tunnel.ipv4.dscp;
1993 session->ip4_hdr.ip_id = 0;
1994 session->ip4_hdr.ip_off = 0;
1995 session->ip4_hdr.ip_ttl = ipsec_xform->tunnel.ipv4.ttl;
1996 session->ip4_hdr.ip_p = (ipsec_xform->proto ==
1997 RTE_SECURITY_IPSEC_SA_PROTO_ESP) ? IPPROTO_ESP
1999 session->ip4_hdr.ip_sum = 0;
2000 session->ip4_hdr.ip_src = ipsec_xform->tunnel.ipv4.src_ip;
2001 session->ip4_hdr.ip_dst = ipsec_xform->tunnel.ipv4.dst_ip;
2002 session->ip4_hdr.ip_sum = calc_chksum((uint16_t *)
2003 (void *)&session->ip4_hdr,
2006 session->encap_pdb.options =
2007 (IPVERSION << PDBNH_ESP_ENCAP_SHIFT) |
2008 PDBOPTS_ESP_OIHI_PDB_INL |
2010 PDBHMO_ESP_ENCAP_DTTL;
2011 session->encap_pdb.spi = ipsec_xform->spi;
2012 session->encap_pdb.ip_hdr_len = sizeof(struct ip);
2014 session->dir = DIR_ENC;
2015 } else if (ipsec_xform->direction ==
2016 RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
2017 memset(&session->decap_pdb, 0, sizeof(struct ipsec_decap_pdb));
2018 session->decap_pdb.options = sizeof(struct ip) << 16;
2019 session->dir = DIR_DEC;
2022 session->ctx_pool = internals->ctx_pool;
2023 session->inq = dpaa_sec_attach_rxq(internals);
2024 if (session->inq == NULL) {
2025 DPAA_SEC_ERR("unable to attach sec queue");
2032 rte_free(session->auth_key.data);
2033 rte_free(session->cipher_key.data);
2034 memset(session, 0, sizeof(dpaa_sec_session));
2039 dpaa_sec_security_session_create(void *dev,
2040 struct rte_security_session_conf *conf,
2041 struct rte_security_session *sess,
2042 struct rte_mempool *mempool)
2044 void *sess_private_data;
2045 struct rte_cryptodev *cdev = (struct rte_cryptodev *)dev;
2048 if (rte_mempool_get(mempool, &sess_private_data)) {
2049 DPAA_SEC_ERR("Couldn't get object from session mempool");
2053 switch (conf->protocol) {
2054 case RTE_SECURITY_PROTOCOL_IPSEC:
2055 ret = dpaa_sec_set_ipsec_session(cdev, conf,
2058 case RTE_SECURITY_PROTOCOL_MACSEC:
2064 DPAA_SEC_ERR("failed to configure session parameters");
2065 /* Return session to mempool */
2066 rte_mempool_put(mempool, sess_private_data);
2070 set_sec_session_private_data(sess, sess_private_data);
2075 /** Clear the memory of session so it doesn't leave key material behind */
2077 dpaa_sec_security_session_destroy(void *dev __rte_unused,
2078 struct rte_security_session *sess)
2080 PMD_INIT_FUNC_TRACE();
2081 void *sess_priv = get_sec_session_private_data(sess);
2083 dpaa_sec_session *s = (dpaa_sec_session *)sess_priv;
2086 struct rte_mempool *sess_mp = rte_mempool_from_obj(sess_priv);
2088 rte_free(s->cipher_key.data);
2089 rte_free(s->auth_key.data);
2090 memset(sess, 0, sizeof(dpaa_sec_session));
2091 set_sec_session_private_data(sess, NULL);
2092 rte_mempool_put(sess_mp, sess_priv);
2099 dpaa_sec_dev_configure(struct rte_cryptodev *dev,
2100 struct rte_cryptodev_config *config __rte_unused)
2104 struct dpaa_sec_dev_private *internals;
2106 PMD_INIT_FUNC_TRACE();
2108 internals = dev->data->dev_private;
2109 sprintf(str, "ctx_pool_%d", dev->data->dev_id);
2110 if (!internals->ctx_pool) {
2111 internals->ctx_pool = rte_mempool_create((const char *)str,
2114 CTX_POOL_CACHE_SIZE, 0,
2115 NULL, NULL, NULL, NULL,
2117 if (!internals->ctx_pool) {
2118 DPAA_SEC_ERR("%s create failed\n", str);
2122 DPAA_SEC_INFO("mempool already created for dev_id : %d",
2129 dpaa_sec_dev_start(struct rte_cryptodev *dev __rte_unused)
2131 PMD_INIT_FUNC_TRACE();
2136 dpaa_sec_dev_stop(struct rte_cryptodev *dev __rte_unused)
2138 PMD_INIT_FUNC_TRACE();
2142 dpaa_sec_dev_close(struct rte_cryptodev *dev)
2144 struct dpaa_sec_dev_private *internals;
2146 PMD_INIT_FUNC_TRACE();
2151 internals = dev->data->dev_private;
2152 rte_mempool_free(internals->ctx_pool);
2153 internals->ctx_pool = NULL;
2159 dpaa_sec_dev_infos_get(struct rte_cryptodev *dev,
2160 struct rte_cryptodev_info *info)
2162 struct dpaa_sec_dev_private *internals = dev->data->dev_private;
2164 PMD_INIT_FUNC_TRACE();
2166 info->max_nb_queue_pairs = internals->max_nb_queue_pairs;
2167 info->feature_flags = dev->feature_flags;
2168 info->capabilities = dpaa_sec_capabilities;
2169 info->sym.max_nb_sessions = internals->max_nb_sessions;
2170 info->driver_id = cryptodev_driver_id;
2174 static struct rte_cryptodev_ops crypto_ops = {
2175 .dev_configure = dpaa_sec_dev_configure,
2176 .dev_start = dpaa_sec_dev_start,
2177 .dev_stop = dpaa_sec_dev_stop,
2178 .dev_close = dpaa_sec_dev_close,
2179 .dev_infos_get = dpaa_sec_dev_infos_get,
2180 .queue_pair_setup = dpaa_sec_queue_pair_setup,
2181 .queue_pair_release = dpaa_sec_queue_pair_release,
2182 .queue_pair_count = dpaa_sec_queue_pair_count,
2183 .sym_session_get_size = dpaa_sec_sym_session_get_size,
2184 .sym_session_configure = dpaa_sec_sym_session_configure,
2185 .sym_session_clear = dpaa_sec_sym_session_clear
2188 static const struct rte_security_capability *
2189 dpaa_sec_capabilities_get(void *device __rte_unused)
2191 return dpaa_sec_security_cap;
2194 struct rte_security_ops dpaa_sec_security_ops = {
2195 .session_create = dpaa_sec_security_session_create,
2196 .session_update = NULL,
2197 .session_stats_get = NULL,
2198 .session_destroy = dpaa_sec_security_session_destroy,
2199 .set_pkt_metadata = NULL,
2200 .capabilities_get = dpaa_sec_capabilities_get
2204 dpaa_sec_uninit(struct rte_cryptodev *dev)
2206 struct dpaa_sec_dev_private *internals;
2211 internals = dev->data->dev_private;
2212 rte_free(dev->security_ctx);
2214 /* In case close has been called, internals->ctx_pool would be NULL */
2215 rte_mempool_free(internals->ctx_pool);
2216 rte_free(internals);
2218 DPAA_SEC_INFO("Closing DPAA_SEC device %s on numa socket %u",
2219 dev->data->name, rte_socket_id());
2225 dpaa_sec_dev_init(struct rte_cryptodev *cryptodev)
2227 struct dpaa_sec_dev_private *internals;
2228 struct rte_security_ctx *security_instance;
2229 struct dpaa_sec_qp *qp;
2233 PMD_INIT_FUNC_TRACE();
2235 cryptodev->driver_id = cryptodev_driver_id;
2236 cryptodev->dev_ops = &crypto_ops;
2238 cryptodev->enqueue_burst = dpaa_sec_enqueue_burst;
2239 cryptodev->dequeue_burst = dpaa_sec_dequeue_burst;
2240 cryptodev->feature_flags = RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO |
2241 RTE_CRYPTODEV_FF_HW_ACCELERATED |
2242 RTE_CRYPTODEV_FF_SYM_OPERATION_CHAINING |
2243 RTE_CRYPTODEV_FF_SECURITY |
2244 RTE_CRYPTODEV_FF_IN_PLACE_SGL |
2245 RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT |
2246 RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT |
2247 RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT |
2248 RTE_CRYPTODEV_FF_OOP_LB_IN_LB_OUT;
2250 internals = cryptodev->data->dev_private;
2251 internals->max_nb_queue_pairs = RTE_DPAA_MAX_NB_SEC_QPS;
2252 internals->max_nb_sessions = RTE_DPAA_SEC_PMD_MAX_NB_SESSIONS;
2255 * For secondary processes, we don't initialise any further as primary
2256 * has already done this work. Only check we don't need a different
2259 if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2260 DPAA_SEC_WARN("Device already init by primary process");
2264 /* Initialize security_ctx only for primary process*/
2265 security_instance = rte_malloc("rte_security_instances_ops",
2266 sizeof(struct rte_security_ctx), 0);
2267 if (security_instance == NULL)
2269 security_instance->device = (void *)cryptodev;
2270 security_instance->ops = &dpaa_sec_security_ops;
2271 security_instance->sess_cnt = 0;
2272 cryptodev->security_ctx = security_instance;
2274 for (i = 0; i < internals->max_nb_queue_pairs; i++) {
2275 /* init qman fq for queue pair */
2276 qp = &internals->qps[i];
2277 ret = dpaa_sec_init_tx(&qp->outq);
2279 DPAA_SEC_ERR("config tx of queue pair %d", i);
2284 flags = QMAN_FQ_FLAG_LOCKED | QMAN_FQ_FLAG_DYNAMIC_FQID |
2285 QMAN_FQ_FLAG_TO_DCPORTAL;
2286 for (i = 0; i < internals->max_nb_sessions; i++) {
2287 /* create rx qman fq for sessions*/
2288 ret = qman_create_fq(0, flags, &internals->inq[i]);
2289 if (unlikely(ret != 0)) {
2290 DPAA_SEC_ERR("sec qman_create_fq failed");
2295 RTE_LOG(INFO, PMD, "%s cryptodev init\n", cryptodev->data->name);
2299 DPAA_SEC_ERR("driver %s: create failed\n", cryptodev->data->name);
2301 dpaa_sec_uninit(cryptodev);
2306 cryptodev_dpaa_sec_probe(struct rte_dpaa_driver *dpaa_drv,
2307 struct rte_dpaa_device *dpaa_dev)
2309 struct rte_cryptodev *cryptodev;
2310 char cryptodev_name[RTE_CRYPTODEV_NAME_MAX_LEN];
2314 sprintf(cryptodev_name, "dpaa_sec-%d", dpaa_dev->id.dev_id);
2316 cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
2317 if (cryptodev == NULL)
2320 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
2321 cryptodev->data->dev_private = rte_zmalloc_socket(
2322 "cryptodev private structure",
2323 sizeof(struct dpaa_sec_dev_private),
2324 RTE_CACHE_LINE_SIZE,
2327 if (cryptodev->data->dev_private == NULL)
2328 rte_panic("Cannot allocate memzone for private "
2332 dpaa_dev->crypto_dev = cryptodev;
2333 cryptodev->device = &dpaa_dev->device;
2334 cryptodev->device->driver = &dpaa_drv->driver;
2336 /* init user callbacks */
2337 TAILQ_INIT(&(cryptodev->link_intr_cbs));
2339 /* if sec device version is not configured */
2340 if (!rta_get_sec_era()) {
2341 const struct device_node *caam_node;
2343 for_each_compatible_node(caam_node, NULL, "fsl,sec-v4.0") {
2344 const uint32_t *prop = of_get_property(caam_node,
2349 INTL_SEC_ERA(rte_cpu_to_be_32(*prop)));
2355 /* Invoke PMD device initialization function */
2356 retval = dpaa_sec_dev_init(cryptodev);
2360 /* In case of error, cleanup is done */
2361 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
2362 rte_free(cryptodev->data->dev_private);
2364 rte_cryptodev_pmd_release_device(cryptodev);
2370 cryptodev_dpaa_sec_remove(struct rte_dpaa_device *dpaa_dev)
2372 struct rte_cryptodev *cryptodev;
2375 cryptodev = dpaa_dev->crypto_dev;
2376 if (cryptodev == NULL)
2379 ret = dpaa_sec_uninit(cryptodev);
2383 return rte_cryptodev_pmd_destroy(cryptodev);
2386 static struct rte_dpaa_driver rte_dpaa_sec_driver = {
2387 .drv_type = FSL_DPAA_CRYPTO,
2389 .name = "DPAA SEC PMD"
2391 .probe = cryptodev_dpaa_sec_probe,
2392 .remove = cryptodev_dpaa_sec_remove,
2395 static struct cryptodev_driver dpaa_sec_crypto_drv;
2397 RTE_PMD_REGISTER_DPAA(CRYPTODEV_NAME_DPAA_SEC_PMD, rte_dpaa_sec_driver);
2398 RTE_PMD_REGISTER_CRYPTO_DRIVER(dpaa_sec_crypto_drv, rte_dpaa_sec_driver.driver,
2399 cryptodev_driver_id);
2401 RTE_INIT(dpaa_sec_init_log)
2403 dpaa_logtype_sec = rte_log_register("pmd.crypto.dpaa");
2404 if (dpaa_logtype_sec >= 0)
2405 rte_log_set_level(dpaa_logtype_sec, RTE_LOG_NOTICE);