1 // SPDX-License-Identifier: GPL-2.0-only
3 * AMD Cryptographic Coprocessor (CCP) driver
5 * Copyright (C) 2013-2019 Advanced Micro Devices, Inc.
11 #include <linux/dma-mapping.h>
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/interrupt.h>
15 #include <crypto/scatterwalk.h>
16 #include <crypto/des.h>
17 #include <linux/ccp.h>
21 /* SHA initial context values */
22 static const __be32 ccp_sha1_init[SHA1_DIGEST_SIZE / sizeof(__be32)] = {
23 cpu_to_be32(SHA1_H0), cpu_to_be32(SHA1_H1),
24 cpu_to_be32(SHA1_H2), cpu_to_be32(SHA1_H3),
28 static const __be32 ccp_sha224_init[SHA256_DIGEST_SIZE / sizeof(__be32)] = {
29 cpu_to_be32(SHA224_H0), cpu_to_be32(SHA224_H1),
30 cpu_to_be32(SHA224_H2), cpu_to_be32(SHA224_H3),
31 cpu_to_be32(SHA224_H4), cpu_to_be32(SHA224_H5),
32 cpu_to_be32(SHA224_H6), cpu_to_be32(SHA224_H7),
35 static const __be32 ccp_sha256_init[SHA256_DIGEST_SIZE / sizeof(__be32)] = {
36 cpu_to_be32(SHA256_H0), cpu_to_be32(SHA256_H1),
37 cpu_to_be32(SHA256_H2), cpu_to_be32(SHA256_H3),
38 cpu_to_be32(SHA256_H4), cpu_to_be32(SHA256_H5),
39 cpu_to_be32(SHA256_H6), cpu_to_be32(SHA256_H7),
42 static const __be64 ccp_sha384_init[SHA512_DIGEST_SIZE / sizeof(__be64)] = {
43 cpu_to_be64(SHA384_H0), cpu_to_be64(SHA384_H1),
44 cpu_to_be64(SHA384_H2), cpu_to_be64(SHA384_H3),
45 cpu_to_be64(SHA384_H4), cpu_to_be64(SHA384_H5),
46 cpu_to_be64(SHA384_H6), cpu_to_be64(SHA384_H7),
49 static const __be64 ccp_sha512_init[SHA512_DIGEST_SIZE / sizeof(__be64)] = {
50 cpu_to_be64(SHA512_H0), cpu_to_be64(SHA512_H1),
51 cpu_to_be64(SHA512_H2), cpu_to_be64(SHA512_H3),
52 cpu_to_be64(SHA512_H4), cpu_to_be64(SHA512_H5),
53 cpu_to_be64(SHA512_H6), cpu_to_be64(SHA512_H7),
56 #define CCP_NEW_JOBID(ccp) ((ccp->vdata->version == CCP_VERSION(3, 0)) ? \
57 ccp_gen_jobid(ccp) : 0)
59 static u32 ccp_gen_jobid(struct ccp_device *ccp)
61 return atomic_inc_return(&ccp->current_id) & CCP_JOBID_MASK;
64 static void ccp_sg_free(struct ccp_sg_workarea *wa)
67 dma_unmap_sg(wa->dma_dev, wa->dma_sg_head, wa->nents, wa->dma_dir);
72 static int ccp_init_sg_workarea(struct ccp_sg_workarea *wa, struct device *dev,
73 struct scatterlist *sg, u64 len,
74 enum dma_data_direction dma_dir)
76 memset(wa, 0, sizeof(*wa));
82 wa->nents = sg_nents_for_len(sg, len);
92 if (dma_dir == DMA_NONE)
98 wa->dma_dir = dma_dir;
99 wa->dma_count = dma_map_sg(dev, sg, wa->nents, dma_dir);
106 static void ccp_update_sg_workarea(struct ccp_sg_workarea *wa, unsigned int len)
108 unsigned int nbytes = min_t(u64, len, wa->bytes_left);
109 unsigned int sg_combined_len = 0;
114 wa->sg_used += nbytes;
115 wa->bytes_left -= nbytes;
116 if (wa->sg_used == sg_dma_len(wa->dma_sg)) {
117 /* Advance to the next DMA scatterlist entry */
118 wa->dma_sg = sg_next(wa->dma_sg);
120 /* In the case that the DMA mapped scatterlist has entries
121 * that have been merged, the non-DMA mapped scatterlist
122 * must be advanced multiple times for each merged entry.
123 * This ensures that the current non-DMA mapped entry
124 * corresponds to the current DMA mapped entry.
127 sg_combined_len += wa->sg->length;
128 wa->sg = sg_next(wa->sg);
129 } while (wa->sg_used > sg_combined_len);
135 static void ccp_dm_free(struct ccp_dm_workarea *wa)
137 if (wa->length <= CCP_DMAPOOL_MAX_SIZE) {
139 dma_pool_free(wa->dma_pool, wa->address,
143 dma_unmap_single(wa->dev, wa->dma.address, wa->length,
152 static int ccp_init_dm_workarea(struct ccp_dm_workarea *wa,
153 struct ccp_cmd_queue *cmd_q,
155 enum dma_data_direction dir)
157 memset(wa, 0, sizeof(*wa));
162 wa->dev = cmd_q->ccp->dev;
165 if (len <= CCP_DMAPOOL_MAX_SIZE) {
166 wa->dma_pool = cmd_q->dma_pool;
168 wa->address = dma_pool_zalloc(wa->dma_pool, GFP_KERNEL,
173 wa->dma.length = CCP_DMAPOOL_MAX_SIZE;
176 wa->address = kzalloc(len, GFP_KERNEL);
180 wa->dma.address = dma_map_single(wa->dev, wa->address, len,
182 if (dma_mapping_error(wa->dev, wa->dma.address))
185 wa->dma.length = len;
192 static int ccp_set_dm_area(struct ccp_dm_workarea *wa, unsigned int wa_offset,
193 struct scatterlist *sg, unsigned int sg_offset,
196 WARN_ON(!wa->address);
198 if (len > (wa->length - wa_offset))
201 scatterwalk_map_and_copy(wa->address + wa_offset, sg, sg_offset, len,
206 static void ccp_get_dm_area(struct ccp_dm_workarea *wa, unsigned int wa_offset,
207 struct scatterlist *sg, unsigned int sg_offset,
210 WARN_ON(!wa->address);
212 scatterwalk_map_and_copy(wa->address + wa_offset, sg, sg_offset, len,
216 static int ccp_reverse_set_dm_area(struct ccp_dm_workarea *wa,
217 unsigned int wa_offset,
218 struct scatterlist *sg,
219 unsigned int sg_offset,
225 rc = ccp_set_dm_area(wa, wa_offset, sg, sg_offset, len);
229 p = wa->address + wa_offset;
241 static void ccp_reverse_get_dm_area(struct ccp_dm_workarea *wa,
242 unsigned int wa_offset,
243 struct scatterlist *sg,
244 unsigned int sg_offset,
249 p = wa->address + wa_offset;
259 ccp_get_dm_area(wa, wa_offset, sg, sg_offset, len);
262 static void ccp_free_data(struct ccp_data *data, struct ccp_cmd_queue *cmd_q)
264 ccp_dm_free(&data->dm_wa);
265 ccp_sg_free(&data->sg_wa);
268 static int ccp_init_data(struct ccp_data *data, struct ccp_cmd_queue *cmd_q,
269 struct scatterlist *sg, u64 sg_len,
271 enum dma_data_direction dir)
275 memset(data, 0, sizeof(*data));
277 ret = ccp_init_sg_workarea(&data->sg_wa, cmd_q->ccp->dev, sg, sg_len,
282 ret = ccp_init_dm_workarea(&data->dm_wa, cmd_q, dm_len, dir);
289 ccp_free_data(data, cmd_q);
294 static unsigned int ccp_queue_buf(struct ccp_data *data, unsigned int from)
296 struct ccp_sg_workarea *sg_wa = &data->sg_wa;
297 struct ccp_dm_workarea *dm_wa = &data->dm_wa;
298 unsigned int buf_count, nbytes;
300 /* Clear the buffer if setting it */
302 memset(dm_wa->address, 0, dm_wa->length);
307 /* Perform the copy operation
308 * nbytes will always be <= UINT_MAX because dm_wa->length is
311 nbytes = min_t(u64, sg_wa->bytes_left, dm_wa->length);
312 scatterwalk_map_and_copy(dm_wa->address, sg_wa->sg, sg_wa->sg_used,
315 /* Update the structures and generate the count */
317 while (sg_wa->bytes_left && (buf_count < dm_wa->length)) {
318 nbytes = min(sg_dma_len(sg_wa->dma_sg) - sg_wa->sg_used,
319 dm_wa->length - buf_count);
320 nbytes = min_t(u64, sg_wa->bytes_left, nbytes);
323 ccp_update_sg_workarea(sg_wa, nbytes);
329 static unsigned int ccp_fill_queue_buf(struct ccp_data *data)
331 return ccp_queue_buf(data, 0);
334 static unsigned int ccp_empty_queue_buf(struct ccp_data *data)
336 return ccp_queue_buf(data, 1);
339 static void ccp_prepare_data(struct ccp_data *src, struct ccp_data *dst,
340 struct ccp_op *op, unsigned int block_size,
343 unsigned int sg_src_len, sg_dst_len, op_len;
345 /* The CCP can only DMA from/to one address each per operation. This
346 * requires that we find the smallest DMA area between the source
347 * and destination. The resulting len values will always be <= UINT_MAX
348 * because the dma length is an unsigned int.
350 sg_src_len = sg_dma_len(src->sg_wa.dma_sg) - src->sg_wa.sg_used;
351 sg_src_len = min_t(u64, src->sg_wa.bytes_left, sg_src_len);
354 sg_dst_len = sg_dma_len(dst->sg_wa.dma_sg) - dst->sg_wa.sg_used;
355 sg_dst_len = min_t(u64, src->sg_wa.bytes_left, sg_dst_len);
356 op_len = min(sg_src_len, sg_dst_len);
361 /* The data operation length will be at least block_size in length
362 * or the smaller of available sg room remaining for the source or
365 op_len = max(op_len, block_size);
367 /* Unless we have to buffer data, there's no reason to wait */
370 if (sg_src_len < block_size) {
371 /* Not enough data in the sg element, so it
372 * needs to be buffered into a blocksize chunk
374 int cp_len = ccp_fill_queue_buf(src);
377 op->src.u.dma.address = src->dm_wa.dma.address;
378 op->src.u.dma.offset = 0;
379 op->src.u.dma.length = (blocksize_op) ? block_size : cp_len;
381 /* Enough data in the sg element, but we need to
382 * adjust for any previously copied data
384 op->src.u.dma.address = sg_dma_address(src->sg_wa.dma_sg);
385 op->src.u.dma.offset = src->sg_wa.sg_used;
386 op->src.u.dma.length = op_len & ~(block_size - 1);
388 ccp_update_sg_workarea(&src->sg_wa, op->src.u.dma.length);
392 if (sg_dst_len < block_size) {
393 /* Not enough room in the sg element or we're on the
394 * last piece of data (when using padding), so the
395 * output needs to be buffered into a blocksize chunk
398 op->dst.u.dma.address = dst->dm_wa.dma.address;
399 op->dst.u.dma.offset = 0;
400 op->dst.u.dma.length = op->src.u.dma.length;
402 /* Enough room in the sg element, but we need to
403 * adjust for any previously used area
405 op->dst.u.dma.address = sg_dma_address(dst->sg_wa.dma_sg);
406 op->dst.u.dma.offset = dst->sg_wa.sg_used;
407 op->dst.u.dma.length = op->src.u.dma.length;
412 static void ccp_process_data(struct ccp_data *src, struct ccp_data *dst,
418 if (op->dst.u.dma.address == dst->dm_wa.dma.address)
419 ccp_empty_queue_buf(dst);
421 ccp_update_sg_workarea(&dst->sg_wa,
422 op->dst.u.dma.length);
426 static int ccp_copy_to_from_sb(struct ccp_cmd_queue *cmd_q,
427 struct ccp_dm_workarea *wa, u32 jobid, u32 sb,
428 u32 byte_swap, bool from)
432 memset(&op, 0, sizeof(op));
440 op.src.type = CCP_MEMTYPE_SB;
442 op.dst.type = CCP_MEMTYPE_SYSTEM;
443 op.dst.u.dma.address = wa->dma.address;
444 op.dst.u.dma.length = wa->length;
446 op.src.type = CCP_MEMTYPE_SYSTEM;
447 op.src.u.dma.address = wa->dma.address;
448 op.src.u.dma.length = wa->length;
449 op.dst.type = CCP_MEMTYPE_SB;
453 op.u.passthru.byte_swap = byte_swap;
455 return cmd_q->ccp->vdata->perform->passthru(&op);
458 static int ccp_copy_to_sb(struct ccp_cmd_queue *cmd_q,
459 struct ccp_dm_workarea *wa, u32 jobid, u32 sb,
462 return ccp_copy_to_from_sb(cmd_q, wa, jobid, sb, byte_swap, false);
465 static int ccp_copy_from_sb(struct ccp_cmd_queue *cmd_q,
466 struct ccp_dm_workarea *wa, u32 jobid, u32 sb,
469 return ccp_copy_to_from_sb(cmd_q, wa, jobid, sb, byte_swap, true);
472 static noinline_for_stack int
473 ccp_run_aes_cmac_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
475 struct ccp_aes_engine *aes = &cmd->u.aes;
476 struct ccp_dm_workarea key, ctx;
479 unsigned int dm_offset;
482 if (!((aes->key_len == AES_KEYSIZE_128) ||
483 (aes->key_len == AES_KEYSIZE_192) ||
484 (aes->key_len == AES_KEYSIZE_256)))
487 if (aes->src_len & (AES_BLOCK_SIZE - 1))
490 if (aes->iv_len != AES_BLOCK_SIZE)
493 if (!aes->key || !aes->iv || !aes->src)
496 if (aes->cmac_final) {
497 if (aes->cmac_key_len != AES_BLOCK_SIZE)
504 BUILD_BUG_ON(CCP_AES_KEY_SB_COUNT != 1);
505 BUILD_BUG_ON(CCP_AES_CTX_SB_COUNT != 1);
508 memset(&op, 0, sizeof(op));
510 op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
511 op.sb_key = cmd_q->sb_key;
512 op.sb_ctx = cmd_q->sb_ctx;
514 op.u.aes.type = aes->type;
515 op.u.aes.mode = aes->mode;
516 op.u.aes.action = aes->action;
518 /* All supported key sizes fit in a single (32-byte) SB entry
519 * and must be in little endian format. Use the 256-bit byte
520 * swap passthru option to convert from big endian to little
523 ret = ccp_init_dm_workarea(&key, cmd_q,
524 CCP_AES_KEY_SB_COUNT * CCP_SB_BYTES,
529 dm_offset = CCP_SB_BYTES - aes->key_len;
530 ret = ccp_set_dm_area(&key, dm_offset, aes->key, 0, aes->key_len);
533 ret = ccp_copy_to_sb(cmd_q, &key, op.jobid, op.sb_key,
534 CCP_PASSTHRU_BYTESWAP_256BIT);
536 cmd->engine_error = cmd_q->cmd_error;
540 /* The AES context fits in a single (32-byte) SB entry and
541 * must be in little endian format. Use the 256-bit byte swap
542 * passthru option to convert from big endian to little endian.
544 ret = ccp_init_dm_workarea(&ctx, cmd_q,
545 CCP_AES_CTX_SB_COUNT * CCP_SB_BYTES,
550 dm_offset = CCP_SB_BYTES - AES_BLOCK_SIZE;
551 ret = ccp_set_dm_area(&ctx, dm_offset, aes->iv, 0, aes->iv_len);
554 ret = ccp_copy_to_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
555 CCP_PASSTHRU_BYTESWAP_256BIT);
557 cmd->engine_error = cmd_q->cmd_error;
561 /* Send data to the CCP AES engine */
562 ret = ccp_init_data(&src, cmd_q, aes->src, aes->src_len,
563 AES_BLOCK_SIZE, DMA_TO_DEVICE);
567 while (src.sg_wa.bytes_left) {
568 ccp_prepare_data(&src, NULL, &op, AES_BLOCK_SIZE, true);
569 if (aes->cmac_final && !src.sg_wa.bytes_left) {
572 /* Push the K1/K2 key to the CCP now */
573 ret = ccp_copy_from_sb(cmd_q, &ctx, op.jobid,
575 CCP_PASSTHRU_BYTESWAP_256BIT);
577 cmd->engine_error = cmd_q->cmd_error;
581 ret = ccp_set_dm_area(&ctx, 0, aes->cmac_key, 0,
585 ret = ccp_copy_to_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
586 CCP_PASSTHRU_BYTESWAP_256BIT);
588 cmd->engine_error = cmd_q->cmd_error;
593 ret = cmd_q->ccp->vdata->perform->aes(&op);
595 cmd->engine_error = cmd_q->cmd_error;
599 ccp_process_data(&src, NULL, &op);
602 /* Retrieve the AES context - convert from LE to BE using
603 * 32-byte (256-bit) byteswapping
605 ret = ccp_copy_from_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
606 CCP_PASSTHRU_BYTESWAP_256BIT);
608 cmd->engine_error = cmd_q->cmd_error;
612 /* ...but we only need AES_BLOCK_SIZE bytes */
613 dm_offset = CCP_SB_BYTES - AES_BLOCK_SIZE;
614 ccp_get_dm_area(&ctx, dm_offset, aes->iv, 0, aes->iv_len);
617 ccp_free_data(&src, cmd_q);
628 static noinline_for_stack int
629 ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
631 struct ccp_aes_engine *aes = &cmd->u.aes;
632 struct ccp_dm_workarea key, ctx, final_wa, tag;
633 struct ccp_data src, dst;
636 unsigned int dm_offset;
637 unsigned int authsize;
640 bool in_place = true; /* Default value */
644 struct scatterlist *p_inp, sg_inp[2];
645 struct scatterlist *p_tag, sg_tag[2];
646 struct scatterlist *p_outp, sg_outp[2];
647 struct scatterlist *p_aad;
652 if (!((aes->key_len == AES_KEYSIZE_128) ||
653 (aes->key_len == AES_KEYSIZE_192) ||
654 (aes->key_len == AES_KEYSIZE_256)))
657 if (!aes->key) /* Gotta have a key SGL */
660 /* Zero defaults to 16 bytes, the maximum size */
661 authsize = aes->authsize ? aes->authsize : AES_BLOCK_SIZE;
675 /* First, decompose the source buffer into AAD & PT,
676 * and the destination buffer into AAD, CT & tag, or
677 * the input into CT & tag.
678 * It is expected that the input and output SGs will
679 * be valid, even if the AAD and input lengths are 0.
682 p_inp = scatterwalk_ffwd(sg_inp, aes->src, aes->aad_len);
683 p_outp = scatterwalk_ffwd(sg_outp, aes->dst, aes->aad_len);
684 if (aes->action == CCP_AES_ACTION_ENCRYPT) {
686 p_tag = scatterwalk_ffwd(sg_tag, p_outp, ilen);
688 /* Input length for decryption includes tag */
689 ilen = aes->src_len - authsize;
690 p_tag = scatterwalk_ffwd(sg_tag, p_inp, ilen);
693 jobid = CCP_NEW_JOBID(cmd_q->ccp);
695 memset(&op, 0, sizeof(op));
698 op.sb_key = cmd_q->sb_key; /* Pre-allocated */
699 op.sb_ctx = cmd_q->sb_ctx; /* Pre-allocated */
701 op.u.aes.type = aes->type;
703 /* Copy the key to the LSB */
704 ret = ccp_init_dm_workarea(&key, cmd_q,
705 CCP_AES_CTX_SB_COUNT * CCP_SB_BYTES,
710 dm_offset = CCP_SB_BYTES - aes->key_len;
711 ret = ccp_set_dm_area(&key, dm_offset, aes->key, 0, aes->key_len);
714 ret = ccp_copy_to_sb(cmd_q, &key, op.jobid, op.sb_key,
715 CCP_PASSTHRU_BYTESWAP_256BIT);
717 cmd->engine_error = cmd_q->cmd_error;
721 /* Copy the context (IV) to the LSB.
722 * There is an assumption here that the IV is 96 bits in length, plus
723 * a nonce of 32 bits. If no IV is present, use a zeroed buffer.
725 ret = ccp_init_dm_workarea(&ctx, cmd_q,
726 CCP_AES_CTX_SB_COUNT * CCP_SB_BYTES,
731 dm_offset = CCP_AES_CTX_SB_COUNT * CCP_SB_BYTES - aes->iv_len;
732 ret = ccp_set_dm_area(&ctx, dm_offset, aes->iv, 0, aes->iv_len);
736 ret = ccp_copy_to_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
737 CCP_PASSTHRU_BYTESWAP_256BIT);
739 cmd->engine_error = cmd_q->cmd_error;
744 if (aes->aad_len > 0) {
745 /* Step 1: Run a GHASH over the Additional Authenticated Data */
746 ret = ccp_init_data(&aad, cmd_q, p_aad, aes->aad_len,
752 op.u.aes.mode = CCP_AES_MODE_GHASH;
753 op.u.aes.action = CCP_AES_GHASHAAD;
755 while (aad.sg_wa.bytes_left) {
756 ccp_prepare_data(&aad, NULL, &op, AES_BLOCK_SIZE, true);
758 ret = cmd_q->ccp->vdata->perform->aes(&op);
760 cmd->engine_error = cmd_q->cmd_error;
764 ccp_process_data(&aad, NULL, &op);
769 op.u.aes.mode = CCP_AES_MODE_GCTR;
770 op.u.aes.action = aes->action;
773 /* Step 2: Run a GCTR over the plaintext */
774 in_place = (sg_virt(p_inp) == sg_virt(p_outp)) ? true : false;
776 ret = ccp_init_data(&src, cmd_q, p_inp, ilen,
778 in_place ? DMA_BIDIRECTIONAL
786 ret = ccp_init_data(&dst, cmd_q, p_outp, ilen,
787 AES_BLOCK_SIZE, DMA_FROM_DEVICE);
795 while (src.sg_wa.bytes_left) {
796 ccp_prepare_data(&src, &dst, &op, AES_BLOCK_SIZE, true);
797 if (!src.sg_wa.bytes_left) {
798 unsigned int nbytes = ilen % AES_BLOCK_SIZE;
802 op.u.aes.size = (nbytes * 8) - 1;
806 ret = cmd_q->ccp->vdata->perform->aes(&op);
808 cmd->engine_error = cmd_q->cmd_error;
812 ccp_process_data(&src, &dst, &op);
817 /* Step 3: Update the IV portion of the context with the original IV */
818 ret = ccp_copy_from_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
819 CCP_PASSTHRU_BYTESWAP_256BIT);
821 cmd->engine_error = cmd_q->cmd_error;
825 ret = ccp_set_dm_area(&ctx, dm_offset, aes->iv, 0, aes->iv_len);
829 ret = ccp_copy_to_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
830 CCP_PASSTHRU_BYTESWAP_256BIT);
832 cmd->engine_error = cmd_q->cmd_error;
836 /* Step 4: Concatenate the lengths of the AAD and source, and
837 * hash that 16 byte buffer.
839 ret = ccp_init_dm_workarea(&final_wa, cmd_q, AES_BLOCK_SIZE,
843 final = (__be64 *)final_wa.address;
844 final[0] = cpu_to_be64(aes->aad_len * 8);
845 final[1] = cpu_to_be64(ilen * 8);
847 memset(&op, 0, sizeof(op));
850 op.sb_key = cmd_q->sb_key; /* Pre-allocated */
851 op.sb_ctx = cmd_q->sb_ctx; /* Pre-allocated */
853 op.u.aes.type = aes->type;
854 op.u.aes.mode = CCP_AES_MODE_GHASH;
855 op.u.aes.action = CCP_AES_GHASHFINAL;
856 op.src.type = CCP_MEMTYPE_SYSTEM;
857 op.src.u.dma.address = final_wa.dma.address;
858 op.src.u.dma.length = AES_BLOCK_SIZE;
859 op.dst.type = CCP_MEMTYPE_SYSTEM;
860 op.dst.u.dma.address = final_wa.dma.address;
861 op.dst.u.dma.length = AES_BLOCK_SIZE;
864 ret = cmd_q->ccp->vdata->perform->aes(&op);
868 if (aes->action == CCP_AES_ACTION_ENCRYPT) {
869 /* Put the ciphered tag after the ciphertext. */
870 ccp_get_dm_area(&final_wa, 0, p_tag, 0, authsize);
872 /* Does this ciphered tag match the input? */
873 ret = ccp_init_dm_workarea(&tag, cmd_q, authsize,
877 ret = ccp_set_dm_area(&tag, 0, p_tag, 0, authsize);
883 ret = crypto_memneq(tag.address, final_wa.address,
884 authsize) ? -EBADMSG : 0;
889 ccp_dm_free(&final_wa);
892 if (ilen > 0 && !in_place)
893 ccp_free_data(&dst, cmd_q);
897 ccp_free_data(&src, cmd_q);
901 ccp_free_data(&aad, cmd_q);
912 static noinline_for_stack int
913 ccp_run_aes_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
915 struct ccp_aes_engine *aes = &cmd->u.aes;
916 struct ccp_dm_workarea key, ctx;
917 struct ccp_data src, dst;
919 unsigned int dm_offset;
920 bool in_place = false;
923 if (!((aes->key_len == AES_KEYSIZE_128) ||
924 (aes->key_len == AES_KEYSIZE_192) ||
925 (aes->key_len == AES_KEYSIZE_256)))
928 if (((aes->mode == CCP_AES_MODE_ECB) ||
929 (aes->mode == CCP_AES_MODE_CBC)) &&
930 (aes->src_len & (AES_BLOCK_SIZE - 1)))
933 if (!aes->key || !aes->src || !aes->dst)
936 if (aes->mode != CCP_AES_MODE_ECB) {
937 if (aes->iv_len != AES_BLOCK_SIZE)
944 BUILD_BUG_ON(CCP_AES_KEY_SB_COUNT != 1);
945 BUILD_BUG_ON(CCP_AES_CTX_SB_COUNT != 1);
948 memset(&op, 0, sizeof(op));
950 op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
951 op.sb_key = cmd_q->sb_key;
952 op.sb_ctx = cmd_q->sb_ctx;
953 op.init = (aes->mode == CCP_AES_MODE_ECB) ? 0 : 1;
954 op.u.aes.type = aes->type;
955 op.u.aes.mode = aes->mode;
956 op.u.aes.action = aes->action;
958 /* All supported key sizes fit in a single (32-byte) SB entry
959 * and must be in little endian format. Use the 256-bit byte
960 * swap passthru option to convert from big endian to little
963 ret = ccp_init_dm_workarea(&key, cmd_q,
964 CCP_AES_KEY_SB_COUNT * CCP_SB_BYTES,
969 dm_offset = CCP_SB_BYTES - aes->key_len;
970 ret = ccp_set_dm_area(&key, dm_offset, aes->key, 0, aes->key_len);
973 ret = ccp_copy_to_sb(cmd_q, &key, op.jobid, op.sb_key,
974 CCP_PASSTHRU_BYTESWAP_256BIT);
976 cmd->engine_error = cmd_q->cmd_error;
980 /* The AES context fits in a single (32-byte) SB entry and
981 * must be in little endian format. Use the 256-bit byte swap
982 * passthru option to convert from big endian to little endian.
984 ret = ccp_init_dm_workarea(&ctx, cmd_q,
985 CCP_AES_CTX_SB_COUNT * CCP_SB_BYTES,
990 if (aes->mode != CCP_AES_MODE_ECB) {
991 /* Load the AES context - convert to LE */
992 dm_offset = CCP_SB_BYTES - AES_BLOCK_SIZE;
993 ret = ccp_set_dm_area(&ctx, dm_offset, aes->iv, 0, aes->iv_len);
996 ret = ccp_copy_to_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
997 CCP_PASSTHRU_BYTESWAP_256BIT);
999 cmd->engine_error = cmd_q->cmd_error;
1003 switch (aes->mode) {
1004 case CCP_AES_MODE_CFB: /* CFB128 only */
1005 case CCP_AES_MODE_CTR:
1006 op.u.aes.size = AES_BLOCK_SIZE * BITS_PER_BYTE - 1;
1012 /* Prepare the input and output data workareas. For in-place
1013 * operations we need to set the dma direction to BIDIRECTIONAL
1014 * and copy the src workarea to the dst workarea.
1016 if (sg_virt(aes->src) == sg_virt(aes->dst))
1019 ret = ccp_init_data(&src, cmd_q, aes->src, aes->src_len,
1021 in_place ? DMA_BIDIRECTIONAL : DMA_TO_DEVICE);
1028 ret = ccp_init_data(&dst, cmd_q, aes->dst, aes->src_len,
1029 AES_BLOCK_SIZE, DMA_FROM_DEVICE);
1034 /* Send data to the CCP AES engine */
1035 while (src.sg_wa.bytes_left) {
1036 ccp_prepare_data(&src, &dst, &op, AES_BLOCK_SIZE, true);
1037 if (!src.sg_wa.bytes_left) {
1040 /* Since we don't retrieve the AES context in ECB
1041 * mode we have to wait for the operation to complete
1042 * on the last piece of data
1044 if (aes->mode == CCP_AES_MODE_ECB)
1048 ret = cmd_q->ccp->vdata->perform->aes(&op);
1050 cmd->engine_error = cmd_q->cmd_error;
1054 ccp_process_data(&src, &dst, &op);
1057 if (aes->mode != CCP_AES_MODE_ECB) {
1058 /* Retrieve the AES context - convert from LE to BE using
1059 * 32-byte (256-bit) byteswapping
1061 ret = ccp_copy_from_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
1062 CCP_PASSTHRU_BYTESWAP_256BIT);
1064 cmd->engine_error = cmd_q->cmd_error;
1068 /* ...but we only need AES_BLOCK_SIZE bytes */
1069 dm_offset = CCP_SB_BYTES - AES_BLOCK_SIZE;
1070 ccp_get_dm_area(&ctx, dm_offset, aes->iv, 0, aes->iv_len);
1075 ccp_free_data(&dst, cmd_q);
1078 ccp_free_data(&src, cmd_q);
1089 static noinline_for_stack int
1090 ccp_run_xts_aes_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
1092 struct ccp_xts_aes_engine *xts = &cmd->u.xts;
1093 struct ccp_dm_workarea key, ctx;
1094 struct ccp_data src, dst;
1096 unsigned int unit_size, dm_offset;
1097 bool in_place = false;
1098 unsigned int sb_count;
1099 enum ccp_aes_type aestype;
1102 switch (xts->unit_size) {
1103 case CCP_XTS_AES_UNIT_SIZE_16:
1106 case CCP_XTS_AES_UNIT_SIZE_512:
1109 case CCP_XTS_AES_UNIT_SIZE_1024:
1112 case CCP_XTS_AES_UNIT_SIZE_2048:
1115 case CCP_XTS_AES_UNIT_SIZE_4096:
1123 if (xts->key_len == AES_KEYSIZE_128)
1124 aestype = CCP_AES_TYPE_128;
1125 else if (xts->key_len == AES_KEYSIZE_256)
1126 aestype = CCP_AES_TYPE_256;
1130 if (!xts->final && (xts->src_len & (AES_BLOCK_SIZE - 1)))
1133 if (xts->iv_len != AES_BLOCK_SIZE)
1136 if (!xts->key || !xts->iv || !xts->src || !xts->dst)
1139 BUILD_BUG_ON(CCP_XTS_AES_KEY_SB_COUNT != 1);
1140 BUILD_BUG_ON(CCP_XTS_AES_CTX_SB_COUNT != 1);
1143 memset(&op, 0, sizeof(op));
1145 op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
1146 op.sb_key = cmd_q->sb_key;
1147 op.sb_ctx = cmd_q->sb_ctx;
1149 op.u.xts.type = aestype;
1150 op.u.xts.action = xts->action;
1151 op.u.xts.unit_size = xts->unit_size;
1153 /* A version 3 device only supports 128-bit keys, which fits into a
1154 * single SB entry. A version 5 device uses a 512-bit vector, so two
1157 if (cmd_q->ccp->vdata->version == CCP_VERSION(3, 0))
1158 sb_count = CCP_XTS_AES_KEY_SB_COUNT;
1160 sb_count = CCP5_XTS_AES_KEY_SB_COUNT;
1161 ret = ccp_init_dm_workarea(&key, cmd_q,
1162 sb_count * CCP_SB_BYTES,
1167 if (cmd_q->ccp->vdata->version == CCP_VERSION(3, 0)) {
1168 /* All supported key sizes must be in little endian format.
1169 * Use the 256-bit byte swap passthru option to convert from
1170 * big endian to little endian.
1172 dm_offset = CCP_SB_BYTES - AES_KEYSIZE_128;
1173 ret = ccp_set_dm_area(&key, dm_offset, xts->key, 0, xts->key_len);
1176 ret = ccp_set_dm_area(&key, 0, xts->key, xts->key_len, xts->key_len);
1180 /* Version 5 CCPs use a 512-bit space for the key: each portion
1181 * occupies 256 bits, or one entire slot, and is zero-padded.
1185 dm_offset = CCP_SB_BYTES;
1186 pad = dm_offset - xts->key_len;
1187 ret = ccp_set_dm_area(&key, pad, xts->key, 0, xts->key_len);
1190 ret = ccp_set_dm_area(&key, dm_offset + pad, xts->key,
1191 xts->key_len, xts->key_len);
1195 ret = ccp_copy_to_sb(cmd_q, &key, op.jobid, op.sb_key,
1196 CCP_PASSTHRU_BYTESWAP_256BIT);
1198 cmd->engine_error = cmd_q->cmd_error;
1202 /* The AES context fits in a single (32-byte) SB entry and
1203 * for XTS is already in little endian format so no byte swapping
1206 ret = ccp_init_dm_workarea(&ctx, cmd_q,
1207 CCP_XTS_AES_CTX_SB_COUNT * CCP_SB_BYTES,
1212 ret = ccp_set_dm_area(&ctx, 0, xts->iv, 0, xts->iv_len);
1215 ret = ccp_copy_to_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
1216 CCP_PASSTHRU_BYTESWAP_NOOP);
1218 cmd->engine_error = cmd_q->cmd_error;
1222 /* Prepare the input and output data workareas. For in-place
1223 * operations we need to set the dma direction to BIDIRECTIONAL
1224 * and copy the src workarea to the dst workarea.
1226 if (sg_virt(xts->src) == sg_virt(xts->dst))
1229 ret = ccp_init_data(&src, cmd_q, xts->src, xts->src_len,
1231 in_place ? DMA_BIDIRECTIONAL : DMA_TO_DEVICE);
1238 ret = ccp_init_data(&dst, cmd_q, xts->dst, xts->src_len,
1239 unit_size, DMA_FROM_DEVICE);
1244 /* Send data to the CCP AES engine */
1245 while (src.sg_wa.bytes_left) {
1246 ccp_prepare_data(&src, &dst, &op, unit_size, true);
1247 if (!src.sg_wa.bytes_left)
1250 ret = cmd_q->ccp->vdata->perform->xts_aes(&op);
1252 cmd->engine_error = cmd_q->cmd_error;
1256 ccp_process_data(&src, &dst, &op);
1259 /* Retrieve the AES context - convert from LE to BE using
1260 * 32-byte (256-bit) byteswapping
1262 ret = ccp_copy_from_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
1263 CCP_PASSTHRU_BYTESWAP_256BIT);
1265 cmd->engine_error = cmd_q->cmd_error;
1269 /* ...but we only need AES_BLOCK_SIZE bytes */
1270 dm_offset = CCP_SB_BYTES - AES_BLOCK_SIZE;
1271 ccp_get_dm_area(&ctx, dm_offset, xts->iv, 0, xts->iv_len);
1275 ccp_free_data(&dst, cmd_q);
1278 ccp_free_data(&src, cmd_q);
1289 static noinline_for_stack int
1290 ccp_run_des3_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
1292 struct ccp_des3_engine *des3 = &cmd->u.des3;
1294 struct ccp_dm_workarea key, ctx;
1295 struct ccp_data src, dst;
1297 unsigned int dm_offset;
1298 unsigned int len_singlekey;
1299 bool in_place = false;
1303 if (cmd_q->ccp->vdata->version < CCP_VERSION(5, 0))
1306 if (!cmd_q->ccp->vdata->perform->des3)
1309 if (des3->key_len != DES3_EDE_KEY_SIZE)
1312 if (((des3->mode == CCP_DES3_MODE_ECB) ||
1313 (des3->mode == CCP_DES3_MODE_CBC)) &&
1314 (des3->src_len & (DES3_EDE_BLOCK_SIZE - 1)))
1317 if (!des3->key || !des3->src || !des3->dst)
1320 if (des3->mode != CCP_DES3_MODE_ECB) {
1321 if (des3->iv_len != DES3_EDE_BLOCK_SIZE)
1328 /* Zero out all the fields of the command desc */
1329 memset(&op, 0, sizeof(op));
1331 /* Set up the Function field */
1333 op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
1334 op.sb_key = cmd_q->sb_key;
1336 op.init = (des3->mode == CCP_DES3_MODE_ECB) ? 0 : 1;
1337 op.u.des3.type = des3->type;
1338 op.u.des3.mode = des3->mode;
1339 op.u.des3.action = des3->action;
1342 * All supported key sizes fit in a single (32-byte) KSB entry and
1343 * (like AES) must be in little endian format. Use the 256-bit byte
1344 * swap passthru option to convert from big endian to little endian.
1346 ret = ccp_init_dm_workarea(&key, cmd_q,
1347 CCP_DES3_KEY_SB_COUNT * CCP_SB_BYTES,
1353 * The contents of the key triplet are in the reverse order of what
1354 * is required by the engine. Copy the 3 pieces individually to put
1355 * them where they belong.
1357 dm_offset = CCP_SB_BYTES - des3->key_len; /* Basic offset */
1359 len_singlekey = des3->key_len / 3;
1360 ret = ccp_set_dm_area(&key, dm_offset + 2 * len_singlekey,
1361 des3->key, 0, len_singlekey);
1364 ret = ccp_set_dm_area(&key, dm_offset + len_singlekey,
1365 des3->key, len_singlekey, len_singlekey);
1368 ret = ccp_set_dm_area(&key, dm_offset,
1369 des3->key, 2 * len_singlekey, len_singlekey);
1373 /* Copy the key to the SB */
1374 ret = ccp_copy_to_sb(cmd_q, &key, op.jobid, op.sb_key,
1375 CCP_PASSTHRU_BYTESWAP_256BIT);
1377 cmd->engine_error = cmd_q->cmd_error;
1382 * The DES3 context fits in a single (32-byte) KSB entry and
1383 * must be in little endian format. Use the 256-bit byte swap
1384 * passthru option to convert from big endian to little endian.
1386 if (des3->mode != CCP_DES3_MODE_ECB) {
1387 op.sb_ctx = cmd_q->sb_ctx;
1389 ret = ccp_init_dm_workarea(&ctx, cmd_q,
1390 CCP_DES3_CTX_SB_COUNT * CCP_SB_BYTES,
1395 /* Load the context into the LSB */
1396 dm_offset = CCP_SB_BYTES - des3->iv_len;
1397 ret = ccp_set_dm_area(&ctx, dm_offset, des3->iv, 0,
1402 ret = ccp_copy_to_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
1403 CCP_PASSTHRU_BYTESWAP_256BIT);
1405 cmd->engine_error = cmd_q->cmd_error;
1411 * Prepare the input and output data workareas. For in-place
1412 * operations we need to set the dma direction to BIDIRECTIONAL
1413 * and copy the src workarea to the dst workarea.
1415 if (sg_virt(des3->src) == sg_virt(des3->dst))
1418 ret = ccp_init_data(&src, cmd_q, des3->src, des3->src_len,
1419 DES3_EDE_BLOCK_SIZE,
1420 in_place ? DMA_BIDIRECTIONAL : DMA_TO_DEVICE);
1427 ret = ccp_init_data(&dst, cmd_q, des3->dst, des3->src_len,
1428 DES3_EDE_BLOCK_SIZE, DMA_FROM_DEVICE);
1433 /* Send data to the CCP DES3 engine */
1434 while (src.sg_wa.bytes_left) {
1435 ccp_prepare_data(&src, &dst, &op, DES3_EDE_BLOCK_SIZE, true);
1436 if (!src.sg_wa.bytes_left) {
1439 /* Since we don't retrieve the context in ECB mode
1440 * we have to wait for the operation to complete
1441 * on the last piece of data
1446 ret = cmd_q->ccp->vdata->perform->des3(&op);
1448 cmd->engine_error = cmd_q->cmd_error;
1452 ccp_process_data(&src, &dst, &op);
1455 if (des3->mode != CCP_DES3_MODE_ECB) {
1456 /* Retrieve the context and make BE */
1457 ret = ccp_copy_from_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
1458 CCP_PASSTHRU_BYTESWAP_256BIT);
1460 cmd->engine_error = cmd_q->cmd_error;
1464 /* ...but we only need the last DES3_EDE_BLOCK_SIZE bytes */
1465 ccp_get_dm_area(&ctx, dm_offset, des3->iv, 0,
1466 DES3_EDE_BLOCK_SIZE);
1470 ccp_free_data(&dst, cmd_q);
1473 ccp_free_data(&src, cmd_q);
1476 if (des3->mode != CCP_DES3_MODE_ECB)
1485 static noinline_for_stack int
1486 ccp_run_sha_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
1488 struct ccp_sha_engine *sha = &cmd->u.sha;
1489 struct ccp_dm_workarea ctx;
1490 struct ccp_data src;
1492 unsigned int ioffset, ooffset;
1493 unsigned int digest_size;
1500 switch (sha->type) {
1501 case CCP_SHA_TYPE_1:
1502 if (sha->ctx_len < SHA1_DIGEST_SIZE)
1504 block_size = SHA1_BLOCK_SIZE;
1506 case CCP_SHA_TYPE_224:
1507 if (sha->ctx_len < SHA224_DIGEST_SIZE)
1509 block_size = SHA224_BLOCK_SIZE;
1511 case CCP_SHA_TYPE_256:
1512 if (sha->ctx_len < SHA256_DIGEST_SIZE)
1514 block_size = SHA256_BLOCK_SIZE;
1516 case CCP_SHA_TYPE_384:
1517 if (cmd_q->ccp->vdata->version < CCP_VERSION(4, 0)
1518 || sha->ctx_len < SHA384_DIGEST_SIZE)
1520 block_size = SHA384_BLOCK_SIZE;
1522 case CCP_SHA_TYPE_512:
1523 if (cmd_q->ccp->vdata->version < CCP_VERSION(4, 0)
1524 || sha->ctx_len < SHA512_DIGEST_SIZE)
1526 block_size = SHA512_BLOCK_SIZE;
1535 if (!sha->final && (sha->src_len & (block_size - 1)))
1538 /* The version 3 device can't handle zero-length input */
1539 if (cmd_q->ccp->vdata->version == CCP_VERSION(3, 0)) {
1541 if (!sha->src_len) {
1542 unsigned int digest_len;
1545 /* Not final, just return */
1549 /* CCP can't do a zero length sha operation so the
1550 * caller must buffer the data.
1555 /* The CCP cannot perform zero-length sha operations
1556 * so the caller is required to buffer data for the
1557 * final operation. However, a sha operation for a
1558 * message with a total length of zero is valid so
1559 * known values are required to supply the result.
1561 switch (sha->type) {
1562 case CCP_SHA_TYPE_1:
1563 sha_zero = sha1_zero_message_hash;
1564 digest_len = SHA1_DIGEST_SIZE;
1566 case CCP_SHA_TYPE_224:
1567 sha_zero = sha224_zero_message_hash;
1568 digest_len = SHA224_DIGEST_SIZE;
1570 case CCP_SHA_TYPE_256:
1571 sha_zero = sha256_zero_message_hash;
1572 digest_len = SHA256_DIGEST_SIZE;
1578 scatterwalk_map_and_copy((void *)sha_zero, sha->ctx, 0,
1585 /* Set variables used throughout */
1586 switch (sha->type) {
1587 case CCP_SHA_TYPE_1:
1588 digest_size = SHA1_DIGEST_SIZE;
1589 init = (void *) ccp_sha1_init;
1590 ctx_size = SHA1_DIGEST_SIZE;
1592 if (cmd_q->ccp->vdata->version != CCP_VERSION(3, 0))
1593 ooffset = ioffset = CCP_SB_BYTES - SHA1_DIGEST_SIZE;
1595 ooffset = ioffset = 0;
1597 case CCP_SHA_TYPE_224:
1598 digest_size = SHA224_DIGEST_SIZE;
1599 init = (void *) ccp_sha224_init;
1600 ctx_size = SHA256_DIGEST_SIZE;
1603 if (cmd_q->ccp->vdata->version != CCP_VERSION(3, 0))
1604 ooffset = CCP_SB_BYTES - SHA224_DIGEST_SIZE;
1608 case CCP_SHA_TYPE_256:
1609 digest_size = SHA256_DIGEST_SIZE;
1610 init = (void *) ccp_sha256_init;
1611 ctx_size = SHA256_DIGEST_SIZE;
1613 ooffset = ioffset = 0;
1615 case CCP_SHA_TYPE_384:
1616 digest_size = SHA384_DIGEST_SIZE;
1617 init = (void *) ccp_sha384_init;
1618 ctx_size = SHA512_DIGEST_SIZE;
1621 ooffset = 2 * CCP_SB_BYTES - SHA384_DIGEST_SIZE;
1623 case CCP_SHA_TYPE_512:
1624 digest_size = SHA512_DIGEST_SIZE;
1625 init = (void *) ccp_sha512_init;
1626 ctx_size = SHA512_DIGEST_SIZE;
1628 ooffset = ioffset = 0;
1635 /* For zero-length plaintext the src pointer is ignored;
1636 * otherwise both parts must be valid
1638 if (sha->src_len && !sha->src)
1641 memset(&op, 0, sizeof(op));
1643 op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
1644 op.sb_ctx = cmd_q->sb_ctx; /* Pre-allocated */
1645 op.u.sha.type = sha->type;
1646 op.u.sha.msg_bits = sha->msg_bits;
1648 /* For SHA1/224/256 the context fits in a single (32-byte) SB entry;
1649 * SHA384/512 require 2 adjacent SB slots, with the right half in the
1650 * first slot, and the left half in the second. Each portion must then
1651 * be in little endian format: use the 256-bit byte swap option.
1653 ret = ccp_init_dm_workarea(&ctx, cmd_q, sb_count * CCP_SB_BYTES,
1658 switch (sha->type) {
1659 case CCP_SHA_TYPE_1:
1660 case CCP_SHA_TYPE_224:
1661 case CCP_SHA_TYPE_256:
1662 memcpy(ctx.address + ioffset, init, ctx_size);
1664 case CCP_SHA_TYPE_384:
1665 case CCP_SHA_TYPE_512:
1666 memcpy(ctx.address + ctx_size / 2, init,
1668 memcpy(ctx.address, init + ctx_size / 2,
1676 /* Restore the context */
1677 ret = ccp_set_dm_area(&ctx, 0, sha->ctx, 0,
1678 sb_count * CCP_SB_BYTES);
1683 ret = ccp_copy_to_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
1684 CCP_PASSTHRU_BYTESWAP_256BIT);
1686 cmd->engine_error = cmd_q->cmd_error;
1691 /* Send data to the CCP SHA engine; block_size is set above */
1692 ret = ccp_init_data(&src, cmd_q, sha->src, sha->src_len,
1693 block_size, DMA_TO_DEVICE);
1697 while (src.sg_wa.bytes_left) {
1698 ccp_prepare_data(&src, NULL, &op, block_size, false);
1699 if (sha->final && !src.sg_wa.bytes_left)
1702 ret = cmd_q->ccp->vdata->perform->sha(&op);
1704 cmd->engine_error = cmd_q->cmd_error;
1708 ccp_process_data(&src, NULL, &op);
1712 ret = cmd_q->ccp->vdata->perform->sha(&op);
1714 cmd->engine_error = cmd_q->cmd_error;
1719 /* Retrieve the SHA context - convert from LE to BE using
1720 * 32-byte (256-bit) byteswapping to BE
1722 ret = ccp_copy_from_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
1723 CCP_PASSTHRU_BYTESWAP_256BIT);
1725 cmd->engine_error = cmd_q->cmd_error;
1730 /* Finishing up, so get the digest */
1731 switch (sha->type) {
1732 case CCP_SHA_TYPE_1:
1733 case CCP_SHA_TYPE_224:
1734 case CCP_SHA_TYPE_256:
1735 ccp_get_dm_area(&ctx, ooffset,
1739 case CCP_SHA_TYPE_384:
1740 case CCP_SHA_TYPE_512:
1741 ccp_get_dm_area(&ctx, 0,
1742 sha->ctx, LSB_ITEM_SIZE - ooffset,
1744 ccp_get_dm_area(&ctx, LSB_ITEM_SIZE + ooffset,
1746 LSB_ITEM_SIZE - ooffset);
1753 /* Stash the context */
1754 ccp_get_dm_area(&ctx, 0, sha->ctx, 0,
1755 sb_count * CCP_SB_BYTES);
1758 if (sha->final && sha->opad) {
1759 /* HMAC operation, recursively perform final SHA */
1760 struct ccp_cmd hmac_cmd;
1761 struct scatterlist sg;
1764 if (sha->opad_len != block_size) {
1769 hmac_buf = kmalloc(block_size + digest_size, GFP_KERNEL);
1774 sg_init_one(&sg, hmac_buf, block_size + digest_size);
1776 scatterwalk_map_and_copy(hmac_buf, sha->opad, 0, block_size, 0);
1777 switch (sha->type) {
1778 case CCP_SHA_TYPE_1:
1779 case CCP_SHA_TYPE_224:
1780 case CCP_SHA_TYPE_256:
1781 memcpy(hmac_buf + block_size,
1782 ctx.address + ooffset,
1785 case CCP_SHA_TYPE_384:
1786 case CCP_SHA_TYPE_512:
1787 memcpy(hmac_buf + block_size,
1788 ctx.address + LSB_ITEM_SIZE + ooffset,
1790 memcpy(hmac_buf + block_size +
1791 (LSB_ITEM_SIZE - ooffset),
1801 memset(&hmac_cmd, 0, sizeof(hmac_cmd));
1802 hmac_cmd.engine = CCP_ENGINE_SHA;
1803 hmac_cmd.u.sha.type = sha->type;
1804 hmac_cmd.u.sha.ctx = sha->ctx;
1805 hmac_cmd.u.sha.ctx_len = sha->ctx_len;
1806 hmac_cmd.u.sha.src = &sg;
1807 hmac_cmd.u.sha.src_len = block_size + digest_size;
1808 hmac_cmd.u.sha.opad = NULL;
1809 hmac_cmd.u.sha.opad_len = 0;
1810 hmac_cmd.u.sha.first = 1;
1811 hmac_cmd.u.sha.final = 1;
1812 hmac_cmd.u.sha.msg_bits = (block_size + digest_size) << 3;
1814 ret = ccp_run_sha_cmd(cmd_q, &hmac_cmd);
1816 cmd->engine_error = hmac_cmd.engine_error;
1823 ccp_free_data(&src, cmd_q);
1831 static noinline_for_stack int
1832 ccp_run_rsa_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
1834 struct ccp_rsa_engine *rsa = &cmd->u.rsa;
1835 struct ccp_dm_workarea exp, src, dst;
1837 unsigned int sb_count, i_len, o_len;
1840 /* Check against the maximum allowable size, in bits */
1841 if (rsa->key_size > cmd_q->ccp->vdata->rsamax)
1844 if (!rsa->exp || !rsa->mod || !rsa->src || !rsa->dst)
1847 memset(&op, 0, sizeof(op));
1849 op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
1851 /* The RSA modulus must precede the message being acted upon, so
1852 * it must be copied to a DMA area where the message and the
1853 * modulus can be concatenated. Therefore the input buffer
1854 * length required is twice the output buffer length (which
1855 * must be a multiple of 256-bits). Compute o_len, i_len in bytes.
1856 * Buffer sizes must be a multiple of 32 bytes; rounding up may be
1859 o_len = 32 * ((rsa->key_size + 255) / 256);
1863 if (cmd_q->ccp->vdata->version < CCP_VERSION(5, 0)) {
1864 /* sb_count is the number of storage block slots required
1867 sb_count = o_len / CCP_SB_BYTES;
1868 op.sb_key = cmd_q->ccp->vdata->perform->sballoc(cmd_q,
1873 /* A version 5 device allows a modulus size that will not fit
1874 * in the LSB, so the command will transfer it from memory.
1875 * Set the sb key to the default, even though it's not used.
1877 op.sb_key = cmd_q->sb_key;
1880 /* The RSA exponent must be in little endian format. Reverse its
1883 ret = ccp_init_dm_workarea(&exp, cmd_q, o_len, DMA_TO_DEVICE);
1887 ret = ccp_reverse_set_dm_area(&exp, 0, rsa->exp, 0, rsa->exp_len);
1891 if (cmd_q->ccp->vdata->version < CCP_VERSION(5, 0)) {
1892 /* Copy the exponent to the local storage block, using
1893 * as many 32-byte blocks as were allocated above. It's
1894 * already little endian, so no further change is required.
1896 ret = ccp_copy_to_sb(cmd_q, &exp, op.jobid, op.sb_key,
1897 CCP_PASSTHRU_BYTESWAP_NOOP);
1899 cmd->engine_error = cmd_q->cmd_error;
1903 /* The exponent can be retrieved from memory via DMA. */
1904 op.exp.u.dma.address = exp.dma.address;
1905 op.exp.u.dma.offset = 0;
1908 /* Concatenate the modulus and the message. Both the modulus and
1909 * the operands must be in little endian format. Since the input
1910 * is in big endian format it must be converted.
1912 ret = ccp_init_dm_workarea(&src, cmd_q, i_len, DMA_TO_DEVICE);
1916 ret = ccp_reverse_set_dm_area(&src, 0, rsa->mod, 0, rsa->mod_len);
1919 ret = ccp_reverse_set_dm_area(&src, o_len, rsa->src, 0, rsa->src_len);
1923 /* Prepare the output area for the operation */
1924 ret = ccp_init_dm_workarea(&dst, cmd_q, o_len, DMA_FROM_DEVICE);
1929 op.src.u.dma.address = src.dma.address;
1930 op.src.u.dma.offset = 0;
1931 op.src.u.dma.length = i_len;
1932 op.dst.u.dma.address = dst.dma.address;
1933 op.dst.u.dma.offset = 0;
1934 op.dst.u.dma.length = o_len;
1936 op.u.rsa.mod_size = rsa->key_size;
1937 op.u.rsa.input_len = i_len;
1939 ret = cmd_q->ccp->vdata->perform->rsa(&op);
1941 cmd->engine_error = cmd_q->cmd_error;
1945 ccp_reverse_get_dm_area(&dst, 0, rsa->dst, 0, rsa->mod_len);
1958 cmd_q->ccp->vdata->perform->sbfree(cmd_q, op.sb_key, sb_count);
1963 static noinline_for_stack int
1964 ccp_run_passthru_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
1966 struct ccp_passthru_engine *pt = &cmd->u.passthru;
1967 struct ccp_dm_workarea mask;
1968 struct ccp_data src, dst;
1970 bool in_place = false;
1974 if (!pt->final && (pt->src_len & (CCP_PASSTHRU_BLOCKSIZE - 1)))
1977 if (!pt->src || !pt->dst)
1980 if (pt->bit_mod != CCP_PASSTHRU_BITWISE_NOOP) {
1981 if (pt->mask_len != CCP_PASSTHRU_MASKSIZE)
1987 BUILD_BUG_ON(CCP_PASSTHRU_SB_COUNT != 1);
1989 memset(&op, 0, sizeof(op));
1991 op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
1993 if (pt->bit_mod != CCP_PASSTHRU_BITWISE_NOOP) {
1995 op.sb_key = cmd_q->sb_key;
1997 ret = ccp_init_dm_workarea(&mask, cmd_q,
1998 CCP_PASSTHRU_SB_COUNT *
2004 ret = ccp_set_dm_area(&mask, 0, pt->mask, 0, pt->mask_len);
2007 ret = ccp_copy_to_sb(cmd_q, &mask, op.jobid, op.sb_key,
2008 CCP_PASSTHRU_BYTESWAP_NOOP);
2010 cmd->engine_error = cmd_q->cmd_error;
2015 /* Prepare the input and output data workareas. For in-place
2016 * operations we need to set the dma direction to BIDIRECTIONAL
2017 * and copy the src workarea to the dst workarea.
2019 if (sg_virt(pt->src) == sg_virt(pt->dst))
2022 ret = ccp_init_data(&src, cmd_q, pt->src, pt->src_len,
2023 CCP_PASSTHRU_MASKSIZE,
2024 in_place ? DMA_BIDIRECTIONAL : DMA_TO_DEVICE);
2031 ret = ccp_init_data(&dst, cmd_q, pt->dst, pt->src_len,
2032 CCP_PASSTHRU_MASKSIZE, DMA_FROM_DEVICE);
2037 /* Send data to the CCP Passthru engine
2038 * Because the CCP engine works on a single source and destination
2039 * dma address at a time, each entry in the source scatterlist
2040 * (after the dma_map_sg call) must be less than or equal to the
2041 * (remaining) length in the destination scatterlist entry and the
2042 * length must be a multiple of CCP_PASSTHRU_BLOCKSIZE
2044 dst.sg_wa.sg_used = 0;
2045 for (i = 1; i <= src.sg_wa.dma_count; i++) {
2046 if (!dst.sg_wa.sg ||
2047 (sg_dma_len(dst.sg_wa.sg) < sg_dma_len(src.sg_wa.sg))) {
2052 if (i == src.sg_wa.dma_count) {
2057 op.src.type = CCP_MEMTYPE_SYSTEM;
2058 op.src.u.dma.address = sg_dma_address(src.sg_wa.sg);
2059 op.src.u.dma.offset = 0;
2060 op.src.u.dma.length = sg_dma_len(src.sg_wa.sg);
2062 op.dst.type = CCP_MEMTYPE_SYSTEM;
2063 op.dst.u.dma.address = sg_dma_address(dst.sg_wa.sg);
2064 op.dst.u.dma.offset = dst.sg_wa.sg_used;
2065 op.dst.u.dma.length = op.src.u.dma.length;
2067 ret = cmd_q->ccp->vdata->perform->passthru(&op);
2069 cmd->engine_error = cmd_q->cmd_error;
2073 dst.sg_wa.sg_used += sg_dma_len(src.sg_wa.sg);
2074 if (dst.sg_wa.sg_used == sg_dma_len(dst.sg_wa.sg)) {
2075 dst.sg_wa.sg = sg_next(dst.sg_wa.sg);
2076 dst.sg_wa.sg_used = 0;
2078 src.sg_wa.sg = sg_next(src.sg_wa.sg);
2083 ccp_free_data(&dst, cmd_q);
2086 ccp_free_data(&src, cmd_q);
2089 if (pt->bit_mod != CCP_PASSTHRU_BITWISE_NOOP)
2095 static noinline_for_stack int
2096 ccp_run_passthru_nomap_cmd(struct ccp_cmd_queue *cmd_q,
2097 struct ccp_cmd *cmd)
2099 struct ccp_passthru_nomap_engine *pt = &cmd->u.passthru_nomap;
2100 struct ccp_dm_workarea mask;
2104 if (!pt->final && (pt->src_len & (CCP_PASSTHRU_BLOCKSIZE - 1)))
2107 if (!pt->src_dma || !pt->dst_dma)
2110 if (pt->bit_mod != CCP_PASSTHRU_BITWISE_NOOP) {
2111 if (pt->mask_len != CCP_PASSTHRU_MASKSIZE)
2117 BUILD_BUG_ON(CCP_PASSTHRU_SB_COUNT != 1);
2119 memset(&op, 0, sizeof(op));
2121 op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
2123 if (pt->bit_mod != CCP_PASSTHRU_BITWISE_NOOP) {
2125 op.sb_key = cmd_q->sb_key;
2127 mask.length = pt->mask_len;
2128 mask.dma.address = pt->mask;
2129 mask.dma.length = pt->mask_len;
2131 ret = ccp_copy_to_sb(cmd_q, &mask, op.jobid, op.sb_key,
2132 CCP_PASSTHRU_BYTESWAP_NOOP);
2134 cmd->engine_error = cmd_q->cmd_error;
2139 /* Send data to the CCP Passthru engine */
2143 op.src.type = CCP_MEMTYPE_SYSTEM;
2144 op.src.u.dma.address = pt->src_dma;
2145 op.src.u.dma.offset = 0;
2146 op.src.u.dma.length = pt->src_len;
2148 op.dst.type = CCP_MEMTYPE_SYSTEM;
2149 op.dst.u.dma.address = pt->dst_dma;
2150 op.dst.u.dma.offset = 0;
2151 op.dst.u.dma.length = pt->src_len;
2153 ret = cmd_q->ccp->vdata->perform->passthru(&op);
2155 cmd->engine_error = cmd_q->cmd_error;
2160 static int ccp_run_ecc_mm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
2162 struct ccp_ecc_engine *ecc = &cmd->u.ecc;
2163 struct ccp_dm_workarea src, dst;
2168 if (!ecc->u.mm.operand_1 ||
2169 (ecc->u.mm.operand_1_len > CCP_ECC_MODULUS_BYTES))
2172 if (ecc->function != CCP_ECC_FUNCTION_MINV_384BIT)
2173 if (!ecc->u.mm.operand_2 ||
2174 (ecc->u.mm.operand_2_len > CCP_ECC_MODULUS_BYTES))
2177 if (!ecc->u.mm.result ||
2178 (ecc->u.mm.result_len < CCP_ECC_MODULUS_BYTES))
2181 memset(&op, 0, sizeof(op));
2183 op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
2185 /* Concatenate the modulus and the operands. Both the modulus and
2186 * the operands must be in little endian format. Since the input
2187 * is in big endian format it must be converted and placed in a
2188 * fixed length buffer.
2190 ret = ccp_init_dm_workarea(&src, cmd_q, CCP_ECC_SRC_BUF_SIZE,
2195 /* Save the workarea address since it is updated in order to perform
2200 /* Copy the ECC modulus */
2201 ret = ccp_reverse_set_dm_area(&src, 0, ecc->mod, 0, ecc->mod_len);
2204 src.address += CCP_ECC_OPERAND_SIZE;
2206 /* Copy the first operand */
2207 ret = ccp_reverse_set_dm_area(&src, 0, ecc->u.mm.operand_1, 0,
2208 ecc->u.mm.operand_1_len);
2211 src.address += CCP_ECC_OPERAND_SIZE;
2213 if (ecc->function != CCP_ECC_FUNCTION_MINV_384BIT) {
2214 /* Copy the second operand */
2215 ret = ccp_reverse_set_dm_area(&src, 0, ecc->u.mm.operand_2, 0,
2216 ecc->u.mm.operand_2_len);
2219 src.address += CCP_ECC_OPERAND_SIZE;
2222 /* Restore the workarea address */
2225 /* Prepare the output area for the operation */
2226 ret = ccp_init_dm_workarea(&dst, cmd_q, CCP_ECC_DST_BUF_SIZE,
2232 op.src.u.dma.address = src.dma.address;
2233 op.src.u.dma.offset = 0;
2234 op.src.u.dma.length = src.length;
2235 op.dst.u.dma.address = dst.dma.address;
2236 op.dst.u.dma.offset = 0;
2237 op.dst.u.dma.length = dst.length;
2239 op.u.ecc.function = cmd->u.ecc.function;
2241 ret = cmd_q->ccp->vdata->perform->ecc(&op);
2243 cmd->engine_error = cmd_q->cmd_error;
2247 ecc->ecc_result = le16_to_cpup(
2248 (const __le16 *)(dst.address + CCP_ECC_RESULT_OFFSET));
2249 if (!(ecc->ecc_result & CCP_ECC_RESULT_SUCCESS)) {
2254 /* Save the ECC result */
2255 ccp_reverse_get_dm_area(&dst, 0, ecc->u.mm.result, 0,
2256 CCP_ECC_MODULUS_BYTES);
2267 static int ccp_run_ecc_pm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
2269 struct ccp_ecc_engine *ecc = &cmd->u.ecc;
2270 struct ccp_dm_workarea src, dst;
2275 if (!ecc->u.pm.point_1.x ||
2276 (ecc->u.pm.point_1.x_len > CCP_ECC_MODULUS_BYTES) ||
2277 !ecc->u.pm.point_1.y ||
2278 (ecc->u.pm.point_1.y_len > CCP_ECC_MODULUS_BYTES))
2281 if (ecc->function == CCP_ECC_FUNCTION_PADD_384BIT) {
2282 if (!ecc->u.pm.point_2.x ||
2283 (ecc->u.pm.point_2.x_len > CCP_ECC_MODULUS_BYTES) ||
2284 !ecc->u.pm.point_2.y ||
2285 (ecc->u.pm.point_2.y_len > CCP_ECC_MODULUS_BYTES))
2288 if (!ecc->u.pm.domain_a ||
2289 (ecc->u.pm.domain_a_len > CCP_ECC_MODULUS_BYTES))
2292 if (ecc->function == CCP_ECC_FUNCTION_PMUL_384BIT)
2293 if (!ecc->u.pm.scalar ||
2294 (ecc->u.pm.scalar_len > CCP_ECC_MODULUS_BYTES))
2298 if (!ecc->u.pm.result.x ||
2299 (ecc->u.pm.result.x_len < CCP_ECC_MODULUS_BYTES) ||
2300 !ecc->u.pm.result.y ||
2301 (ecc->u.pm.result.y_len < CCP_ECC_MODULUS_BYTES))
2304 memset(&op, 0, sizeof(op));
2306 op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
2308 /* Concatenate the modulus and the operands. Both the modulus and
2309 * the operands must be in little endian format. Since the input
2310 * is in big endian format it must be converted and placed in a
2311 * fixed length buffer.
2313 ret = ccp_init_dm_workarea(&src, cmd_q, CCP_ECC_SRC_BUF_SIZE,
2318 /* Save the workarea address since it is updated in order to perform
2323 /* Copy the ECC modulus */
2324 ret = ccp_reverse_set_dm_area(&src, 0, ecc->mod, 0, ecc->mod_len);
2327 src.address += CCP_ECC_OPERAND_SIZE;
2329 /* Copy the first point X and Y coordinate */
2330 ret = ccp_reverse_set_dm_area(&src, 0, ecc->u.pm.point_1.x, 0,
2331 ecc->u.pm.point_1.x_len);
2334 src.address += CCP_ECC_OPERAND_SIZE;
2335 ret = ccp_reverse_set_dm_area(&src, 0, ecc->u.pm.point_1.y, 0,
2336 ecc->u.pm.point_1.y_len);
2339 src.address += CCP_ECC_OPERAND_SIZE;
2341 /* Set the first point Z coordinate to 1 */
2342 *src.address = 0x01;
2343 src.address += CCP_ECC_OPERAND_SIZE;
2345 if (ecc->function == CCP_ECC_FUNCTION_PADD_384BIT) {
2346 /* Copy the second point X and Y coordinate */
2347 ret = ccp_reverse_set_dm_area(&src, 0, ecc->u.pm.point_2.x, 0,
2348 ecc->u.pm.point_2.x_len);
2351 src.address += CCP_ECC_OPERAND_SIZE;
2352 ret = ccp_reverse_set_dm_area(&src, 0, ecc->u.pm.point_2.y, 0,
2353 ecc->u.pm.point_2.y_len);
2356 src.address += CCP_ECC_OPERAND_SIZE;
2358 /* Set the second point Z coordinate to 1 */
2359 *src.address = 0x01;
2360 src.address += CCP_ECC_OPERAND_SIZE;
2362 /* Copy the Domain "a" parameter */
2363 ret = ccp_reverse_set_dm_area(&src, 0, ecc->u.pm.domain_a, 0,
2364 ecc->u.pm.domain_a_len);
2367 src.address += CCP_ECC_OPERAND_SIZE;
2369 if (ecc->function == CCP_ECC_FUNCTION_PMUL_384BIT) {
2370 /* Copy the scalar value */
2371 ret = ccp_reverse_set_dm_area(&src, 0,
2372 ecc->u.pm.scalar, 0,
2373 ecc->u.pm.scalar_len);
2376 src.address += CCP_ECC_OPERAND_SIZE;
2380 /* Restore the workarea address */
2383 /* Prepare the output area for the operation */
2384 ret = ccp_init_dm_workarea(&dst, cmd_q, CCP_ECC_DST_BUF_SIZE,
2390 op.src.u.dma.address = src.dma.address;
2391 op.src.u.dma.offset = 0;
2392 op.src.u.dma.length = src.length;
2393 op.dst.u.dma.address = dst.dma.address;
2394 op.dst.u.dma.offset = 0;
2395 op.dst.u.dma.length = dst.length;
2397 op.u.ecc.function = cmd->u.ecc.function;
2399 ret = cmd_q->ccp->vdata->perform->ecc(&op);
2401 cmd->engine_error = cmd_q->cmd_error;
2405 ecc->ecc_result = le16_to_cpup(
2406 (const __le16 *)(dst.address + CCP_ECC_RESULT_OFFSET));
2407 if (!(ecc->ecc_result & CCP_ECC_RESULT_SUCCESS)) {
2412 /* Save the workarea address since it is updated as we walk through
2413 * to copy the point math result
2417 /* Save the ECC result X and Y coordinates */
2418 ccp_reverse_get_dm_area(&dst, 0, ecc->u.pm.result.x, 0,
2419 CCP_ECC_MODULUS_BYTES);
2420 dst.address += CCP_ECC_OUTPUT_SIZE;
2421 ccp_reverse_get_dm_area(&dst, 0, ecc->u.pm.result.y, 0,
2422 CCP_ECC_MODULUS_BYTES);
2424 /* Restore the workarea address */
2436 static noinline_for_stack int
2437 ccp_run_ecc_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
2439 struct ccp_ecc_engine *ecc = &cmd->u.ecc;
2441 ecc->ecc_result = 0;
2444 (ecc->mod_len > CCP_ECC_MODULUS_BYTES))
2447 switch (ecc->function) {
2448 case CCP_ECC_FUNCTION_MMUL_384BIT:
2449 case CCP_ECC_FUNCTION_MADD_384BIT:
2450 case CCP_ECC_FUNCTION_MINV_384BIT:
2451 return ccp_run_ecc_mm_cmd(cmd_q, cmd);
2453 case CCP_ECC_FUNCTION_PADD_384BIT:
2454 case CCP_ECC_FUNCTION_PMUL_384BIT:
2455 case CCP_ECC_FUNCTION_PDBL_384BIT:
2456 return ccp_run_ecc_pm_cmd(cmd_q, cmd);
2463 int ccp_run_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
2467 cmd->engine_error = 0;
2468 cmd_q->cmd_error = 0;
2469 cmd_q->int_rcvd = 0;
2470 cmd_q->free_slots = cmd_q->ccp->vdata->perform->get_free_slots(cmd_q);
2472 switch (cmd->engine) {
2473 case CCP_ENGINE_AES:
2474 switch (cmd->u.aes.mode) {
2475 case CCP_AES_MODE_CMAC:
2476 ret = ccp_run_aes_cmac_cmd(cmd_q, cmd);
2478 case CCP_AES_MODE_GCM:
2479 ret = ccp_run_aes_gcm_cmd(cmd_q, cmd);
2482 ret = ccp_run_aes_cmd(cmd_q, cmd);
2486 case CCP_ENGINE_XTS_AES_128:
2487 ret = ccp_run_xts_aes_cmd(cmd_q, cmd);
2489 case CCP_ENGINE_DES3:
2490 ret = ccp_run_des3_cmd(cmd_q, cmd);
2492 case CCP_ENGINE_SHA:
2493 ret = ccp_run_sha_cmd(cmd_q, cmd);
2495 case CCP_ENGINE_RSA:
2496 ret = ccp_run_rsa_cmd(cmd_q, cmd);
2498 case CCP_ENGINE_PASSTHRU:
2499 if (cmd->flags & CCP_CMD_PASSTHRU_NO_DMA_MAP)
2500 ret = ccp_run_passthru_nomap_cmd(cmd_q, cmd);
2502 ret = ccp_run_passthru_cmd(cmd_q, cmd);
2504 case CCP_ENGINE_ECC:
2505 ret = ccp_run_ecc_cmd(cmd_q, cmd);