2 * AMD Cryptographic Coprocessor (CCP) driver
4 * Copyright (C) 2013,2017 Advanced Micro Devices, Inc.
6 * Author: Tom Lendacky <thomas.lendacky@amd.com>
7 * Author: Gary R Hook <gary.hook@amd.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/pci.h>
17 #include <linux/interrupt.h>
18 #include <crypto/scatterwalk.h>
19 #include <crypto/des.h>
20 #include <linux/ccp.h>
24 /* SHA initial context values */
25 static const __be32 ccp_sha1_init[SHA1_DIGEST_SIZE / sizeof(__be32)] = {
26 cpu_to_be32(SHA1_H0), cpu_to_be32(SHA1_H1),
27 cpu_to_be32(SHA1_H2), cpu_to_be32(SHA1_H3),
31 static const __be32 ccp_sha224_init[SHA256_DIGEST_SIZE / sizeof(__be32)] = {
32 cpu_to_be32(SHA224_H0), cpu_to_be32(SHA224_H1),
33 cpu_to_be32(SHA224_H2), cpu_to_be32(SHA224_H3),
34 cpu_to_be32(SHA224_H4), cpu_to_be32(SHA224_H5),
35 cpu_to_be32(SHA224_H6), cpu_to_be32(SHA224_H7),
38 static const __be32 ccp_sha256_init[SHA256_DIGEST_SIZE / sizeof(__be32)] = {
39 cpu_to_be32(SHA256_H0), cpu_to_be32(SHA256_H1),
40 cpu_to_be32(SHA256_H2), cpu_to_be32(SHA256_H3),
41 cpu_to_be32(SHA256_H4), cpu_to_be32(SHA256_H5),
42 cpu_to_be32(SHA256_H6), cpu_to_be32(SHA256_H7),
45 static const __be64 ccp_sha384_init[SHA512_DIGEST_SIZE / sizeof(__be64)] = {
46 cpu_to_be64(SHA384_H0), cpu_to_be64(SHA384_H1),
47 cpu_to_be64(SHA384_H2), cpu_to_be64(SHA384_H3),
48 cpu_to_be64(SHA384_H4), cpu_to_be64(SHA384_H5),
49 cpu_to_be64(SHA384_H6), cpu_to_be64(SHA384_H7),
52 static const __be64 ccp_sha512_init[SHA512_DIGEST_SIZE / sizeof(__be64)] = {
53 cpu_to_be64(SHA512_H0), cpu_to_be64(SHA512_H1),
54 cpu_to_be64(SHA512_H2), cpu_to_be64(SHA512_H3),
55 cpu_to_be64(SHA512_H4), cpu_to_be64(SHA512_H5),
56 cpu_to_be64(SHA512_H6), cpu_to_be64(SHA512_H7),
59 #define CCP_NEW_JOBID(ccp) ((ccp->vdata->version == CCP_VERSION(3, 0)) ? \
60 ccp_gen_jobid(ccp) : 0)
62 static u32 ccp_gen_jobid(struct ccp_device *ccp)
64 return atomic_inc_return(&ccp->current_id) & CCP_JOBID_MASK;
67 static void ccp_sg_free(struct ccp_sg_workarea *wa)
70 dma_unmap_sg(wa->dma_dev, wa->dma_sg_head, wa->nents, wa->dma_dir);
75 static int ccp_init_sg_workarea(struct ccp_sg_workarea *wa, struct device *dev,
76 struct scatterlist *sg, u64 len,
77 enum dma_data_direction dma_dir)
79 memset(wa, 0, sizeof(*wa));
85 wa->nents = sg_nents_for_len(sg, len);
95 if (dma_dir == DMA_NONE)
101 wa->dma_dir = dma_dir;
102 wa->dma_count = dma_map_sg(dev, sg, wa->nents, dma_dir);
109 static void ccp_update_sg_workarea(struct ccp_sg_workarea *wa, unsigned int len)
111 unsigned int nbytes = min_t(u64, len, wa->bytes_left);
112 unsigned int sg_combined_len = 0;
117 wa->sg_used += nbytes;
118 wa->bytes_left -= nbytes;
119 if (wa->sg_used == sg_dma_len(wa->dma_sg)) {
120 /* Advance to the next DMA scatterlist entry */
121 wa->dma_sg = sg_next(wa->dma_sg);
123 /* In the case that the DMA mapped scatterlist has entries
124 * that have been merged, the non-DMA mapped scatterlist
125 * must be advanced multiple times for each merged entry.
126 * This ensures that the current non-DMA mapped entry
127 * corresponds to the current DMA mapped entry.
130 sg_combined_len += wa->sg->length;
131 wa->sg = sg_next(wa->sg);
132 } while (wa->sg_used > sg_combined_len);
138 static void ccp_dm_free(struct ccp_dm_workarea *wa)
140 if (wa->length <= CCP_DMAPOOL_MAX_SIZE) {
142 dma_pool_free(wa->dma_pool, wa->address,
146 dma_unmap_single(wa->dev, wa->dma.address, wa->length,
155 static int ccp_init_dm_workarea(struct ccp_dm_workarea *wa,
156 struct ccp_cmd_queue *cmd_q,
158 enum dma_data_direction dir)
160 memset(wa, 0, sizeof(*wa));
165 wa->dev = cmd_q->ccp->dev;
168 if (len <= CCP_DMAPOOL_MAX_SIZE) {
169 wa->dma_pool = cmd_q->dma_pool;
171 wa->address = dma_pool_alloc(wa->dma_pool, GFP_KERNEL,
176 wa->dma.length = CCP_DMAPOOL_MAX_SIZE;
178 memset(wa->address, 0, CCP_DMAPOOL_MAX_SIZE);
180 wa->address = kzalloc(len, GFP_KERNEL);
184 wa->dma.address = dma_map_single(wa->dev, wa->address, len,
186 if (dma_mapping_error(wa->dev, wa->dma.address))
189 wa->dma.length = len;
196 static int ccp_set_dm_area(struct ccp_dm_workarea *wa, unsigned int wa_offset,
197 struct scatterlist *sg, unsigned int sg_offset,
200 WARN_ON(!wa->address);
202 if (len > (wa->length - wa_offset))
205 scatterwalk_map_and_copy(wa->address + wa_offset, sg, sg_offset, len,
210 static void ccp_get_dm_area(struct ccp_dm_workarea *wa, unsigned int wa_offset,
211 struct scatterlist *sg, unsigned int sg_offset,
214 WARN_ON(!wa->address);
216 scatterwalk_map_and_copy(wa->address + wa_offset, sg, sg_offset, len,
220 static int ccp_reverse_set_dm_area(struct ccp_dm_workarea *wa,
221 unsigned int wa_offset,
222 struct scatterlist *sg,
223 unsigned int sg_offset,
229 rc = ccp_set_dm_area(wa, wa_offset, sg, sg_offset, len);
233 p = wa->address + wa_offset;
245 static void ccp_reverse_get_dm_area(struct ccp_dm_workarea *wa,
246 unsigned int wa_offset,
247 struct scatterlist *sg,
248 unsigned int sg_offset,
253 p = wa->address + wa_offset;
263 ccp_get_dm_area(wa, wa_offset, sg, sg_offset, len);
266 static void ccp_free_data(struct ccp_data *data, struct ccp_cmd_queue *cmd_q)
268 ccp_dm_free(&data->dm_wa);
269 ccp_sg_free(&data->sg_wa);
272 static int ccp_init_data(struct ccp_data *data, struct ccp_cmd_queue *cmd_q,
273 struct scatterlist *sg, u64 sg_len,
275 enum dma_data_direction dir)
279 memset(data, 0, sizeof(*data));
281 ret = ccp_init_sg_workarea(&data->sg_wa, cmd_q->ccp->dev, sg, sg_len,
286 ret = ccp_init_dm_workarea(&data->dm_wa, cmd_q, dm_len, dir);
293 ccp_free_data(data, cmd_q);
298 static unsigned int ccp_queue_buf(struct ccp_data *data, unsigned int from)
300 struct ccp_sg_workarea *sg_wa = &data->sg_wa;
301 struct ccp_dm_workarea *dm_wa = &data->dm_wa;
302 unsigned int buf_count, nbytes;
304 /* Clear the buffer if setting it */
306 memset(dm_wa->address, 0, dm_wa->length);
311 /* Perform the copy operation
312 * nbytes will always be <= UINT_MAX because dm_wa->length is
315 nbytes = min_t(u64, sg_wa->bytes_left, dm_wa->length);
316 scatterwalk_map_and_copy(dm_wa->address, sg_wa->sg, sg_wa->sg_used,
319 /* Update the structures and generate the count */
321 while (sg_wa->bytes_left && (buf_count < dm_wa->length)) {
322 nbytes = min(sg_dma_len(sg_wa->dma_sg) - sg_wa->sg_used,
323 dm_wa->length - buf_count);
324 nbytes = min_t(u64, sg_wa->bytes_left, nbytes);
327 ccp_update_sg_workarea(sg_wa, nbytes);
333 static unsigned int ccp_fill_queue_buf(struct ccp_data *data)
335 return ccp_queue_buf(data, 0);
338 static unsigned int ccp_empty_queue_buf(struct ccp_data *data)
340 return ccp_queue_buf(data, 1);
343 static void ccp_prepare_data(struct ccp_data *src, struct ccp_data *dst,
344 struct ccp_op *op, unsigned int block_size,
347 unsigned int sg_src_len, sg_dst_len, op_len;
349 /* The CCP can only DMA from/to one address each per operation. This
350 * requires that we find the smallest DMA area between the source
351 * and destination. The resulting len values will always be <= UINT_MAX
352 * because the dma length is an unsigned int.
354 sg_src_len = sg_dma_len(src->sg_wa.dma_sg) - src->sg_wa.sg_used;
355 sg_src_len = min_t(u64, src->sg_wa.bytes_left, sg_src_len);
358 sg_dst_len = sg_dma_len(dst->sg_wa.dma_sg) - dst->sg_wa.sg_used;
359 sg_dst_len = min_t(u64, src->sg_wa.bytes_left, sg_dst_len);
360 op_len = min(sg_src_len, sg_dst_len);
365 /* The data operation length will be at least block_size in length
366 * or the smaller of available sg room remaining for the source or
369 op_len = max(op_len, block_size);
371 /* Unless we have to buffer data, there's no reason to wait */
374 if (sg_src_len < block_size) {
375 /* Not enough data in the sg element, so it
376 * needs to be buffered into a blocksize chunk
378 int cp_len = ccp_fill_queue_buf(src);
381 op->src.u.dma.address = src->dm_wa.dma.address;
382 op->src.u.dma.offset = 0;
383 op->src.u.dma.length = (blocksize_op) ? block_size : cp_len;
385 /* Enough data in the sg element, but we need to
386 * adjust for any previously copied data
388 op->src.u.dma.address = sg_dma_address(src->sg_wa.dma_sg);
389 op->src.u.dma.offset = src->sg_wa.sg_used;
390 op->src.u.dma.length = op_len & ~(block_size - 1);
392 ccp_update_sg_workarea(&src->sg_wa, op->src.u.dma.length);
396 if (sg_dst_len < block_size) {
397 /* Not enough room in the sg element or we're on the
398 * last piece of data (when using padding), so the
399 * output needs to be buffered into a blocksize chunk
402 op->dst.u.dma.address = dst->dm_wa.dma.address;
403 op->dst.u.dma.offset = 0;
404 op->dst.u.dma.length = op->src.u.dma.length;
406 /* Enough room in the sg element, but we need to
407 * adjust for any previously used area
409 op->dst.u.dma.address = sg_dma_address(dst->sg_wa.dma_sg);
410 op->dst.u.dma.offset = dst->sg_wa.sg_used;
411 op->dst.u.dma.length = op->src.u.dma.length;
416 static void ccp_process_data(struct ccp_data *src, struct ccp_data *dst,
422 if (op->dst.u.dma.address == dst->dm_wa.dma.address)
423 ccp_empty_queue_buf(dst);
425 ccp_update_sg_workarea(&dst->sg_wa,
426 op->dst.u.dma.length);
430 static int ccp_copy_to_from_sb(struct ccp_cmd_queue *cmd_q,
431 struct ccp_dm_workarea *wa, u32 jobid, u32 sb,
432 u32 byte_swap, bool from)
436 memset(&op, 0, sizeof(op));
444 op.src.type = CCP_MEMTYPE_SB;
446 op.dst.type = CCP_MEMTYPE_SYSTEM;
447 op.dst.u.dma.address = wa->dma.address;
448 op.dst.u.dma.length = wa->length;
450 op.src.type = CCP_MEMTYPE_SYSTEM;
451 op.src.u.dma.address = wa->dma.address;
452 op.src.u.dma.length = wa->length;
453 op.dst.type = CCP_MEMTYPE_SB;
457 op.u.passthru.byte_swap = byte_swap;
459 return cmd_q->ccp->vdata->perform->passthru(&op);
462 static int ccp_copy_to_sb(struct ccp_cmd_queue *cmd_q,
463 struct ccp_dm_workarea *wa, u32 jobid, u32 sb,
466 return ccp_copy_to_from_sb(cmd_q, wa, jobid, sb, byte_swap, false);
469 static int ccp_copy_from_sb(struct ccp_cmd_queue *cmd_q,
470 struct ccp_dm_workarea *wa, u32 jobid, u32 sb,
473 return ccp_copy_to_from_sb(cmd_q, wa, jobid, sb, byte_swap, true);
476 static noinline_for_stack int
477 ccp_run_aes_cmac_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
479 struct ccp_aes_engine *aes = &cmd->u.aes;
480 struct ccp_dm_workarea key, ctx;
483 unsigned int dm_offset;
486 if (!((aes->key_len == AES_KEYSIZE_128) ||
487 (aes->key_len == AES_KEYSIZE_192) ||
488 (aes->key_len == AES_KEYSIZE_256)))
491 if (aes->src_len & (AES_BLOCK_SIZE - 1))
494 if (aes->iv_len != AES_BLOCK_SIZE)
497 if (!aes->key || !aes->iv || !aes->src)
500 if (aes->cmac_final) {
501 if (aes->cmac_key_len != AES_BLOCK_SIZE)
508 BUILD_BUG_ON(CCP_AES_KEY_SB_COUNT != 1);
509 BUILD_BUG_ON(CCP_AES_CTX_SB_COUNT != 1);
512 memset(&op, 0, sizeof(op));
514 op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
515 op.sb_key = cmd_q->sb_key;
516 op.sb_ctx = cmd_q->sb_ctx;
518 op.u.aes.type = aes->type;
519 op.u.aes.mode = aes->mode;
520 op.u.aes.action = aes->action;
522 /* All supported key sizes fit in a single (32-byte) SB entry
523 * and must be in little endian format. Use the 256-bit byte
524 * swap passthru option to convert from big endian to little
527 ret = ccp_init_dm_workarea(&key, cmd_q,
528 CCP_AES_KEY_SB_COUNT * CCP_SB_BYTES,
533 dm_offset = CCP_SB_BYTES - aes->key_len;
534 ret = ccp_set_dm_area(&key, dm_offset, aes->key, 0, aes->key_len);
537 ret = ccp_copy_to_sb(cmd_q, &key, op.jobid, op.sb_key,
538 CCP_PASSTHRU_BYTESWAP_256BIT);
540 cmd->engine_error = cmd_q->cmd_error;
544 /* The AES context fits in a single (32-byte) SB entry and
545 * must be in little endian format. Use the 256-bit byte swap
546 * passthru option to convert from big endian to little endian.
548 ret = ccp_init_dm_workarea(&ctx, cmd_q,
549 CCP_AES_CTX_SB_COUNT * CCP_SB_BYTES,
554 dm_offset = CCP_SB_BYTES - AES_BLOCK_SIZE;
555 ret = ccp_set_dm_area(&ctx, dm_offset, aes->iv, 0, aes->iv_len);
558 ret = ccp_copy_to_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
559 CCP_PASSTHRU_BYTESWAP_256BIT);
561 cmd->engine_error = cmd_q->cmd_error;
565 /* Send data to the CCP AES engine */
566 ret = ccp_init_data(&src, cmd_q, aes->src, aes->src_len,
567 AES_BLOCK_SIZE, DMA_TO_DEVICE);
571 while (src.sg_wa.bytes_left) {
572 ccp_prepare_data(&src, NULL, &op, AES_BLOCK_SIZE, true);
573 if (aes->cmac_final && !src.sg_wa.bytes_left) {
576 /* Push the K1/K2 key to the CCP now */
577 ret = ccp_copy_from_sb(cmd_q, &ctx, op.jobid,
579 CCP_PASSTHRU_BYTESWAP_256BIT);
581 cmd->engine_error = cmd_q->cmd_error;
585 ret = ccp_set_dm_area(&ctx, 0, aes->cmac_key, 0,
589 ret = ccp_copy_to_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
590 CCP_PASSTHRU_BYTESWAP_256BIT);
592 cmd->engine_error = cmd_q->cmd_error;
597 ret = cmd_q->ccp->vdata->perform->aes(&op);
599 cmd->engine_error = cmd_q->cmd_error;
603 ccp_process_data(&src, NULL, &op);
606 /* Retrieve the AES context - convert from LE to BE using
607 * 32-byte (256-bit) byteswapping
609 ret = ccp_copy_from_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
610 CCP_PASSTHRU_BYTESWAP_256BIT);
612 cmd->engine_error = cmd_q->cmd_error;
616 /* ...but we only need AES_BLOCK_SIZE bytes */
617 dm_offset = CCP_SB_BYTES - AES_BLOCK_SIZE;
618 ccp_get_dm_area(&ctx, dm_offset, aes->iv, 0, aes->iv_len);
621 ccp_free_data(&src, cmd_q);
632 static noinline_for_stack int
633 ccp_run_aes_gcm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
635 struct ccp_aes_engine *aes = &cmd->u.aes;
636 struct ccp_dm_workarea key, ctx, final_wa, tag;
637 struct ccp_data src, dst;
641 unsigned long long *final;
642 unsigned int dm_offset;
643 unsigned int authsize;
646 bool in_place = true; /* Default value */
649 struct scatterlist *p_inp, sg_inp[2];
650 struct scatterlist *p_tag, sg_tag[2];
651 struct scatterlist *p_outp, sg_outp[2];
652 struct scatterlist *p_aad;
657 if (!((aes->key_len == AES_KEYSIZE_128) ||
658 (aes->key_len == AES_KEYSIZE_192) ||
659 (aes->key_len == AES_KEYSIZE_256)))
662 if (!aes->key) /* Gotta have a key SGL */
665 /* Zero defaults to 16 bytes, the maximum size */
666 authsize = aes->authsize ? aes->authsize : AES_BLOCK_SIZE;
680 /* First, decompose the source buffer into AAD & PT,
681 * and the destination buffer into AAD, CT & tag, or
682 * the input into CT & tag.
683 * It is expected that the input and output SGs will
684 * be valid, even if the AAD and input lengths are 0.
687 p_inp = scatterwalk_ffwd(sg_inp, aes->src, aes->aad_len);
688 p_outp = scatterwalk_ffwd(sg_outp, aes->dst, aes->aad_len);
689 if (aes->action == CCP_AES_ACTION_ENCRYPT) {
691 p_tag = scatterwalk_ffwd(sg_tag, p_outp, ilen);
693 /* Input length for decryption includes tag */
694 ilen = aes->src_len - authsize;
695 p_tag = scatterwalk_ffwd(sg_tag, p_inp, ilen);
698 jobid = CCP_NEW_JOBID(cmd_q->ccp);
700 memset(&op, 0, sizeof(op));
703 op.sb_key = cmd_q->sb_key; /* Pre-allocated */
704 op.sb_ctx = cmd_q->sb_ctx; /* Pre-allocated */
706 op.u.aes.type = aes->type;
708 /* Copy the key to the LSB */
709 ret = ccp_init_dm_workarea(&key, cmd_q,
710 CCP_AES_CTX_SB_COUNT * CCP_SB_BYTES,
715 dm_offset = CCP_SB_BYTES - aes->key_len;
716 ret = ccp_set_dm_area(&key, dm_offset, aes->key, 0, aes->key_len);
719 ret = ccp_copy_to_sb(cmd_q, &key, op.jobid, op.sb_key,
720 CCP_PASSTHRU_BYTESWAP_256BIT);
722 cmd->engine_error = cmd_q->cmd_error;
726 /* Copy the context (IV) to the LSB.
727 * There is an assumption here that the IV is 96 bits in length, plus
728 * a nonce of 32 bits. If no IV is present, use a zeroed buffer.
730 ret = ccp_init_dm_workarea(&ctx, cmd_q,
731 CCP_AES_CTX_SB_COUNT * CCP_SB_BYTES,
736 dm_offset = CCP_AES_CTX_SB_COUNT * CCP_SB_BYTES - aes->iv_len;
737 ret = ccp_set_dm_area(&ctx, dm_offset, aes->iv, 0, aes->iv_len);
741 ret = ccp_copy_to_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
742 CCP_PASSTHRU_BYTESWAP_256BIT);
744 cmd->engine_error = cmd_q->cmd_error;
749 if (aes->aad_len > 0) {
750 /* Step 1: Run a GHASH over the Additional Authenticated Data */
751 ret = ccp_init_data(&aad, cmd_q, p_aad, aes->aad_len,
757 op.u.aes.mode = CCP_AES_MODE_GHASH;
758 op.u.aes.action = CCP_AES_GHASHAAD;
760 while (aad.sg_wa.bytes_left) {
761 ccp_prepare_data(&aad, NULL, &op, AES_BLOCK_SIZE, true);
763 ret = cmd_q->ccp->vdata->perform->aes(&op);
765 cmd->engine_error = cmd_q->cmd_error;
769 ccp_process_data(&aad, NULL, &op);
774 op.u.aes.mode = CCP_AES_MODE_GCTR;
775 op.u.aes.action = aes->action;
778 /* Step 2: Run a GCTR over the plaintext */
779 in_place = (sg_virt(p_inp) == sg_virt(p_outp)) ? true : false;
781 ret = ccp_init_data(&src, cmd_q, p_inp, ilen,
783 in_place ? DMA_BIDIRECTIONAL
791 ret = ccp_init_data(&dst, cmd_q, p_outp, ilen,
792 AES_BLOCK_SIZE, DMA_FROM_DEVICE);
800 while (src.sg_wa.bytes_left) {
801 ccp_prepare_data(&src, &dst, &op, AES_BLOCK_SIZE, true);
802 if (!src.sg_wa.bytes_left) {
803 unsigned int nbytes = ilen % AES_BLOCK_SIZE;
807 op.u.aes.size = (nbytes * 8) - 1;
811 ret = cmd_q->ccp->vdata->perform->aes(&op);
813 cmd->engine_error = cmd_q->cmd_error;
817 ccp_process_data(&src, &dst, &op);
822 /* Step 3: Update the IV portion of the context with the original IV */
823 ret = ccp_copy_from_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
824 CCP_PASSTHRU_BYTESWAP_256BIT);
826 cmd->engine_error = cmd_q->cmd_error;
830 ret = ccp_set_dm_area(&ctx, dm_offset, aes->iv, 0, aes->iv_len);
834 ret = ccp_copy_to_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
835 CCP_PASSTHRU_BYTESWAP_256BIT);
837 cmd->engine_error = cmd_q->cmd_error;
841 /* Step 4: Concatenate the lengths of the AAD and source, and
842 * hash that 16 byte buffer.
844 ret = ccp_init_dm_workarea(&final_wa, cmd_q, AES_BLOCK_SIZE,
848 final = (unsigned long long *) final_wa.address;
849 final[0] = cpu_to_be64(aes->aad_len * 8);
850 final[1] = cpu_to_be64(ilen * 8);
852 memset(&op, 0, sizeof(op));
855 op.sb_key = cmd_q->sb_key; /* Pre-allocated */
856 op.sb_ctx = cmd_q->sb_ctx; /* Pre-allocated */
858 op.u.aes.type = aes->type;
859 op.u.aes.mode = CCP_AES_MODE_GHASH;
860 op.u.aes.action = CCP_AES_GHASHFINAL;
861 op.src.type = CCP_MEMTYPE_SYSTEM;
862 op.src.u.dma.address = final_wa.dma.address;
863 op.src.u.dma.length = AES_BLOCK_SIZE;
864 op.dst.type = CCP_MEMTYPE_SYSTEM;
865 op.dst.u.dma.address = final_wa.dma.address;
866 op.dst.u.dma.length = AES_BLOCK_SIZE;
869 ret = cmd_q->ccp->vdata->perform->aes(&op);
873 if (aes->action == CCP_AES_ACTION_ENCRYPT) {
874 /* Put the ciphered tag after the ciphertext. */
875 ccp_get_dm_area(&final_wa, 0, p_tag, 0, authsize);
877 /* Does this ciphered tag match the input? */
878 ret = ccp_init_dm_workarea(&tag, cmd_q, authsize,
882 ret = ccp_set_dm_area(&tag, 0, p_tag, 0, authsize);
888 ret = crypto_memneq(tag.address, final_wa.address,
889 authsize) ? -EBADMSG : 0;
894 ccp_dm_free(&final_wa);
897 if (ilen > 0 && !in_place)
898 ccp_free_data(&dst, cmd_q);
902 ccp_free_data(&src, cmd_q);
906 ccp_free_data(&aad, cmd_q);
917 static noinline_for_stack int
918 ccp_run_aes_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
920 struct ccp_aes_engine *aes = &cmd->u.aes;
921 struct ccp_dm_workarea key, ctx;
922 struct ccp_data src, dst;
924 unsigned int dm_offset;
925 bool in_place = false;
928 if (!((aes->key_len == AES_KEYSIZE_128) ||
929 (aes->key_len == AES_KEYSIZE_192) ||
930 (aes->key_len == AES_KEYSIZE_256)))
933 if (((aes->mode == CCP_AES_MODE_ECB) ||
934 (aes->mode == CCP_AES_MODE_CBC) ||
935 (aes->mode == CCP_AES_MODE_CFB)) &&
936 (aes->src_len & (AES_BLOCK_SIZE - 1)))
939 if (!aes->key || !aes->src || !aes->dst)
942 if (aes->mode != CCP_AES_MODE_ECB) {
943 if (aes->iv_len != AES_BLOCK_SIZE)
950 BUILD_BUG_ON(CCP_AES_KEY_SB_COUNT != 1);
951 BUILD_BUG_ON(CCP_AES_CTX_SB_COUNT != 1);
954 memset(&op, 0, sizeof(op));
956 op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
957 op.sb_key = cmd_q->sb_key;
958 op.sb_ctx = cmd_q->sb_ctx;
959 op.init = (aes->mode == CCP_AES_MODE_ECB) ? 0 : 1;
960 op.u.aes.type = aes->type;
961 op.u.aes.mode = aes->mode;
962 op.u.aes.action = aes->action;
964 /* All supported key sizes fit in a single (32-byte) SB entry
965 * and must be in little endian format. Use the 256-bit byte
966 * swap passthru option to convert from big endian to little
969 ret = ccp_init_dm_workarea(&key, cmd_q,
970 CCP_AES_KEY_SB_COUNT * CCP_SB_BYTES,
975 dm_offset = CCP_SB_BYTES - aes->key_len;
976 ret = ccp_set_dm_area(&key, dm_offset, aes->key, 0, aes->key_len);
979 ret = ccp_copy_to_sb(cmd_q, &key, op.jobid, op.sb_key,
980 CCP_PASSTHRU_BYTESWAP_256BIT);
982 cmd->engine_error = cmd_q->cmd_error;
986 /* The AES context fits in a single (32-byte) SB entry and
987 * must be in little endian format. Use the 256-bit byte swap
988 * passthru option to convert from big endian to little endian.
990 ret = ccp_init_dm_workarea(&ctx, cmd_q,
991 CCP_AES_CTX_SB_COUNT * CCP_SB_BYTES,
996 if (aes->mode != CCP_AES_MODE_ECB) {
997 /* Load the AES context - convert to LE */
998 dm_offset = CCP_SB_BYTES - AES_BLOCK_SIZE;
999 ret = ccp_set_dm_area(&ctx, dm_offset, aes->iv, 0, aes->iv_len);
1002 ret = ccp_copy_to_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
1003 CCP_PASSTHRU_BYTESWAP_256BIT);
1005 cmd->engine_error = cmd_q->cmd_error;
1009 switch (aes->mode) {
1010 case CCP_AES_MODE_CFB: /* CFB128 only */
1011 case CCP_AES_MODE_CTR:
1012 op.u.aes.size = AES_BLOCK_SIZE * BITS_PER_BYTE - 1;
1018 /* Prepare the input and output data workareas. For in-place
1019 * operations we need to set the dma direction to BIDIRECTIONAL
1020 * and copy the src workarea to the dst workarea.
1022 if (sg_virt(aes->src) == sg_virt(aes->dst))
1025 ret = ccp_init_data(&src, cmd_q, aes->src, aes->src_len,
1027 in_place ? DMA_BIDIRECTIONAL : DMA_TO_DEVICE);
1034 ret = ccp_init_data(&dst, cmd_q, aes->dst, aes->src_len,
1035 AES_BLOCK_SIZE, DMA_FROM_DEVICE);
1040 /* Send data to the CCP AES engine */
1041 while (src.sg_wa.bytes_left) {
1042 ccp_prepare_data(&src, &dst, &op, AES_BLOCK_SIZE, true);
1043 if (!src.sg_wa.bytes_left) {
1046 /* Since we don't retrieve the AES context in ECB
1047 * mode we have to wait for the operation to complete
1048 * on the last piece of data
1050 if (aes->mode == CCP_AES_MODE_ECB)
1054 ret = cmd_q->ccp->vdata->perform->aes(&op);
1056 cmd->engine_error = cmd_q->cmd_error;
1060 ccp_process_data(&src, &dst, &op);
1063 if (aes->mode != CCP_AES_MODE_ECB) {
1064 /* Retrieve the AES context - convert from LE to BE using
1065 * 32-byte (256-bit) byteswapping
1067 ret = ccp_copy_from_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
1068 CCP_PASSTHRU_BYTESWAP_256BIT);
1070 cmd->engine_error = cmd_q->cmd_error;
1074 /* ...but we only need AES_BLOCK_SIZE bytes */
1075 dm_offset = CCP_SB_BYTES - AES_BLOCK_SIZE;
1076 ccp_get_dm_area(&ctx, dm_offset, aes->iv, 0, aes->iv_len);
1081 ccp_free_data(&dst, cmd_q);
1084 ccp_free_data(&src, cmd_q);
1095 static noinline_for_stack int
1096 ccp_run_xts_aes_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
1098 struct ccp_xts_aes_engine *xts = &cmd->u.xts;
1099 struct ccp_dm_workarea key, ctx;
1100 struct ccp_data src, dst;
1102 unsigned int unit_size, dm_offset;
1103 bool in_place = false;
1104 unsigned int sb_count;
1105 enum ccp_aes_type aestype;
1108 switch (xts->unit_size) {
1109 case CCP_XTS_AES_UNIT_SIZE_16:
1112 case CCP_XTS_AES_UNIT_SIZE_512:
1115 case CCP_XTS_AES_UNIT_SIZE_1024:
1118 case CCP_XTS_AES_UNIT_SIZE_2048:
1121 case CCP_XTS_AES_UNIT_SIZE_4096:
1129 if (xts->key_len == AES_KEYSIZE_128)
1130 aestype = CCP_AES_TYPE_128;
1131 else if (xts->key_len == AES_KEYSIZE_256)
1132 aestype = CCP_AES_TYPE_256;
1136 if (!xts->final && (xts->src_len & (AES_BLOCK_SIZE - 1)))
1139 if (xts->iv_len != AES_BLOCK_SIZE)
1142 if (!xts->key || !xts->iv || !xts->src || !xts->dst)
1145 BUILD_BUG_ON(CCP_XTS_AES_KEY_SB_COUNT != 1);
1146 BUILD_BUG_ON(CCP_XTS_AES_CTX_SB_COUNT != 1);
1149 memset(&op, 0, sizeof(op));
1151 op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
1152 op.sb_key = cmd_q->sb_key;
1153 op.sb_ctx = cmd_q->sb_ctx;
1155 op.u.xts.type = aestype;
1156 op.u.xts.action = xts->action;
1157 op.u.xts.unit_size = xts->unit_size;
1159 /* A version 3 device only supports 128-bit keys, which fits into a
1160 * single SB entry. A version 5 device uses a 512-bit vector, so two
1163 if (cmd_q->ccp->vdata->version == CCP_VERSION(3, 0))
1164 sb_count = CCP_XTS_AES_KEY_SB_COUNT;
1166 sb_count = CCP5_XTS_AES_KEY_SB_COUNT;
1167 ret = ccp_init_dm_workarea(&key, cmd_q,
1168 sb_count * CCP_SB_BYTES,
1173 if (cmd_q->ccp->vdata->version == CCP_VERSION(3, 0)) {
1174 /* All supported key sizes must be in little endian format.
1175 * Use the 256-bit byte swap passthru option to convert from
1176 * big endian to little endian.
1178 dm_offset = CCP_SB_BYTES - AES_KEYSIZE_128;
1179 ret = ccp_set_dm_area(&key, dm_offset, xts->key, 0, xts->key_len);
1182 ret = ccp_set_dm_area(&key, 0, xts->key, xts->key_len, xts->key_len);
1186 /* Version 5 CCPs use a 512-bit space for the key: each portion
1187 * occupies 256 bits, or one entire slot, and is zero-padded.
1191 dm_offset = CCP_SB_BYTES;
1192 pad = dm_offset - xts->key_len;
1193 ret = ccp_set_dm_area(&key, pad, xts->key, 0, xts->key_len);
1196 ret = ccp_set_dm_area(&key, dm_offset + pad, xts->key,
1197 xts->key_len, xts->key_len);
1201 ret = ccp_copy_to_sb(cmd_q, &key, op.jobid, op.sb_key,
1202 CCP_PASSTHRU_BYTESWAP_256BIT);
1204 cmd->engine_error = cmd_q->cmd_error;
1208 /* The AES context fits in a single (32-byte) SB entry and
1209 * for XTS is already in little endian format so no byte swapping
1212 ret = ccp_init_dm_workarea(&ctx, cmd_q,
1213 CCP_XTS_AES_CTX_SB_COUNT * CCP_SB_BYTES,
1218 ret = ccp_set_dm_area(&ctx, 0, xts->iv, 0, xts->iv_len);
1221 ret = ccp_copy_to_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
1222 CCP_PASSTHRU_BYTESWAP_NOOP);
1224 cmd->engine_error = cmd_q->cmd_error;
1228 /* Prepare the input and output data workareas. For in-place
1229 * operations we need to set the dma direction to BIDIRECTIONAL
1230 * and copy the src workarea to the dst workarea.
1232 if (sg_virt(xts->src) == sg_virt(xts->dst))
1235 ret = ccp_init_data(&src, cmd_q, xts->src, xts->src_len,
1237 in_place ? DMA_BIDIRECTIONAL : DMA_TO_DEVICE);
1244 ret = ccp_init_data(&dst, cmd_q, xts->dst, xts->src_len,
1245 unit_size, DMA_FROM_DEVICE);
1250 /* Send data to the CCP AES engine */
1251 while (src.sg_wa.bytes_left) {
1252 ccp_prepare_data(&src, &dst, &op, unit_size, true);
1253 if (!src.sg_wa.bytes_left)
1256 ret = cmd_q->ccp->vdata->perform->xts_aes(&op);
1258 cmd->engine_error = cmd_q->cmd_error;
1262 ccp_process_data(&src, &dst, &op);
1265 /* Retrieve the AES context - convert from LE to BE using
1266 * 32-byte (256-bit) byteswapping
1268 ret = ccp_copy_from_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
1269 CCP_PASSTHRU_BYTESWAP_256BIT);
1271 cmd->engine_error = cmd_q->cmd_error;
1275 /* ...but we only need AES_BLOCK_SIZE bytes */
1276 dm_offset = CCP_SB_BYTES - AES_BLOCK_SIZE;
1277 ccp_get_dm_area(&ctx, dm_offset, xts->iv, 0, xts->iv_len);
1281 ccp_free_data(&dst, cmd_q);
1284 ccp_free_data(&src, cmd_q);
1295 static noinline_for_stack int
1296 ccp_run_des3_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
1298 struct ccp_des3_engine *des3 = &cmd->u.des3;
1300 struct ccp_dm_workarea key, ctx;
1301 struct ccp_data src, dst;
1303 unsigned int dm_offset;
1304 unsigned int len_singlekey;
1305 bool in_place = false;
1309 if (cmd_q->ccp->vdata->version < CCP_VERSION(5, 0))
1312 if (!cmd_q->ccp->vdata->perform->des3)
1315 if (des3->key_len != DES3_EDE_KEY_SIZE)
1318 if (((des3->mode == CCP_DES3_MODE_ECB) ||
1319 (des3->mode == CCP_DES3_MODE_CBC)) &&
1320 (des3->src_len & (DES3_EDE_BLOCK_SIZE - 1)))
1323 if (!des3->key || !des3->src || !des3->dst)
1326 if (des3->mode != CCP_DES3_MODE_ECB) {
1327 if (des3->iv_len != DES3_EDE_BLOCK_SIZE)
1335 /* Zero out all the fields of the command desc */
1336 memset(&op, 0, sizeof(op));
1338 /* Set up the Function field */
1340 op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
1341 op.sb_key = cmd_q->sb_key;
1343 op.init = (des3->mode == CCP_DES3_MODE_ECB) ? 0 : 1;
1344 op.u.des3.type = des3->type;
1345 op.u.des3.mode = des3->mode;
1346 op.u.des3.action = des3->action;
1349 * All supported key sizes fit in a single (32-byte) KSB entry and
1350 * (like AES) must be in little endian format. Use the 256-bit byte
1351 * swap passthru option to convert from big endian to little endian.
1353 ret = ccp_init_dm_workarea(&key, cmd_q,
1354 CCP_DES3_KEY_SB_COUNT * CCP_SB_BYTES,
1360 * The contents of the key triplet are in the reverse order of what
1361 * is required by the engine. Copy the 3 pieces individually to put
1362 * them where they belong.
1364 dm_offset = CCP_SB_BYTES - des3->key_len; /* Basic offset */
1366 len_singlekey = des3->key_len / 3;
1367 ret = ccp_set_dm_area(&key, dm_offset + 2 * len_singlekey,
1368 des3->key, 0, len_singlekey);
1371 ret = ccp_set_dm_area(&key, dm_offset + len_singlekey,
1372 des3->key, len_singlekey, len_singlekey);
1375 ret = ccp_set_dm_area(&key, dm_offset,
1376 des3->key, 2 * len_singlekey, len_singlekey);
1380 /* Copy the key to the SB */
1381 ret = ccp_copy_to_sb(cmd_q, &key, op.jobid, op.sb_key,
1382 CCP_PASSTHRU_BYTESWAP_256BIT);
1384 cmd->engine_error = cmd_q->cmd_error;
1389 * The DES3 context fits in a single (32-byte) KSB entry and
1390 * must be in little endian format. Use the 256-bit byte swap
1391 * passthru option to convert from big endian to little endian.
1393 if (des3->mode != CCP_DES3_MODE_ECB) {
1394 op.sb_ctx = cmd_q->sb_ctx;
1396 ret = ccp_init_dm_workarea(&ctx, cmd_q,
1397 CCP_DES3_CTX_SB_COUNT * CCP_SB_BYTES,
1402 /* Load the context into the LSB */
1403 dm_offset = CCP_SB_BYTES - des3->iv_len;
1404 ret = ccp_set_dm_area(&ctx, dm_offset, des3->iv, 0,
1409 ret = ccp_copy_to_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
1410 CCP_PASSTHRU_BYTESWAP_256BIT);
1412 cmd->engine_error = cmd_q->cmd_error;
1418 * Prepare the input and output data workareas. For in-place
1419 * operations we need to set the dma direction to BIDIRECTIONAL
1420 * and copy the src workarea to the dst workarea.
1422 if (sg_virt(des3->src) == sg_virt(des3->dst))
1425 ret = ccp_init_data(&src, cmd_q, des3->src, des3->src_len,
1426 DES3_EDE_BLOCK_SIZE,
1427 in_place ? DMA_BIDIRECTIONAL : DMA_TO_DEVICE);
1434 ret = ccp_init_data(&dst, cmd_q, des3->dst, des3->src_len,
1435 DES3_EDE_BLOCK_SIZE, DMA_FROM_DEVICE);
1440 /* Send data to the CCP DES3 engine */
1441 while (src.sg_wa.bytes_left) {
1442 ccp_prepare_data(&src, &dst, &op, DES3_EDE_BLOCK_SIZE, true);
1443 if (!src.sg_wa.bytes_left) {
1446 /* Since we don't retrieve the context in ECB mode
1447 * we have to wait for the operation to complete
1448 * on the last piece of data
1453 ret = cmd_q->ccp->vdata->perform->des3(&op);
1455 cmd->engine_error = cmd_q->cmd_error;
1459 ccp_process_data(&src, &dst, &op);
1462 if (des3->mode != CCP_DES3_MODE_ECB) {
1463 /* Retrieve the context and make BE */
1464 ret = ccp_copy_from_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
1465 CCP_PASSTHRU_BYTESWAP_256BIT);
1467 cmd->engine_error = cmd_q->cmd_error;
1471 /* ...but we only need the last DES3_EDE_BLOCK_SIZE bytes */
1472 ccp_get_dm_area(&ctx, dm_offset, des3->iv, 0,
1473 DES3_EDE_BLOCK_SIZE);
1477 ccp_free_data(&dst, cmd_q);
1480 ccp_free_data(&src, cmd_q);
1483 if (des3->mode != CCP_DES3_MODE_ECB)
1492 static noinline_for_stack int
1493 ccp_run_sha_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
1495 struct ccp_sha_engine *sha = &cmd->u.sha;
1496 struct ccp_dm_workarea ctx;
1497 struct ccp_data src;
1499 unsigned int ioffset, ooffset;
1500 unsigned int digest_size;
1507 switch (sha->type) {
1508 case CCP_SHA_TYPE_1:
1509 if (sha->ctx_len < SHA1_DIGEST_SIZE)
1511 block_size = SHA1_BLOCK_SIZE;
1513 case CCP_SHA_TYPE_224:
1514 if (sha->ctx_len < SHA224_DIGEST_SIZE)
1516 block_size = SHA224_BLOCK_SIZE;
1518 case CCP_SHA_TYPE_256:
1519 if (sha->ctx_len < SHA256_DIGEST_SIZE)
1521 block_size = SHA256_BLOCK_SIZE;
1523 case CCP_SHA_TYPE_384:
1524 if (cmd_q->ccp->vdata->version < CCP_VERSION(4, 0)
1525 || sha->ctx_len < SHA384_DIGEST_SIZE)
1527 block_size = SHA384_BLOCK_SIZE;
1529 case CCP_SHA_TYPE_512:
1530 if (cmd_q->ccp->vdata->version < CCP_VERSION(4, 0)
1531 || sha->ctx_len < SHA512_DIGEST_SIZE)
1533 block_size = SHA512_BLOCK_SIZE;
1542 if (!sha->final && (sha->src_len & (block_size - 1)))
1545 /* The version 3 device can't handle zero-length input */
1546 if (cmd_q->ccp->vdata->version == CCP_VERSION(3, 0)) {
1548 if (!sha->src_len) {
1549 unsigned int digest_len;
1552 /* Not final, just return */
1556 /* CCP can't do a zero length sha operation so the
1557 * caller must buffer the data.
1562 /* The CCP cannot perform zero-length sha operations
1563 * so the caller is required to buffer data for the
1564 * final operation. However, a sha operation for a
1565 * message with a total length of zero is valid so
1566 * known values are required to supply the result.
1568 switch (sha->type) {
1569 case CCP_SHA_TYPE_1:
1570 sha_zero = sha1_zero_message_hash;
1571 digest_len = SHA1_DIGEST_SIZE;
1573 case CCP_SHA_TYPE_224:
1574 sha_zero = sha224_zero_message_hash;
1575 digest_len = SHA224_DIGEST_SIZE;
1577 case CCP_SHA_TYPE_256:
1578 sha_zero = sha256_zero_message_hash;
1579 digest_len = SHA256_DIGEST_SIZE;
1585 scatterwalk_map_and_copy((void *)sha_zero, sha->ctx, 0,
1592 /* Set variables used throughout */
1593 switch (sha->type) {
1594 case CCP_SHA_TYPE_1:
1595 digest_size = SHA1_DIGEST_SIZE;
1596 init = (void *) ccp_sha1_init;
1597 ctx_size = SHA1_DIGEST_SIZE;
1599 if (cmd_q->ccp->vdata->version != CCP_VERSION(3, 0))
1600 ooffset = ioffset = CCP_SB_BYTES - SHA1_DIGEST_SIZE;
1602 ooffset = ioffset = 0;
1604 case CCP_SHA_TYPE_224:
1605 digest_size = SHA224_DIGEST_SIZE;
1606 init = (void *) ccp_sha224_init;
1607 ctx_size = SHA256_DIGEST_SIZE;
1610 if (cmd_q->ccp->vdata->version != CCP_VERSION(3, 0))
1611 ooffset = CCP_SB_BYTES - SHA224_DIGEST_SIZE;
1615 case CCP_SHA_TYPE_256:
1616 digest_size = SHA256_DIGEST_SIZE;
1617 init = (void *) ccp_sha256_init;
1618 ctx_size = SHA256_DIGEST_SIZE;
1620 ooffset = ioffset = 0;
1622 case CCP_SHA_TYPE_384:
1623 digest_size = SHA384_DIGEST_SIZE;
1624 init = (void *) ccp_sha384_init;
1625 ctx_size = SHA512_DIGEST_SIZE;
1628 ooffset = 2 * CCP_SB_BYTES - SHA384_DIGEST_SIZE;
1630 case CCP_SHA_TYPE_512:
1631 digest_size = SHA512_DIGEST_SIZE;
1632 init = (void *) ccp_sha512_init;
1633 ctx_size = SHA512_DIGEST_SIZE;
1635 ooffset = ioffset = 0;
1642 /* For zero-length plaintext the src pointer is ignored;
1643 * otherwise both parts must be valid
1645 if (sha->src_len && !sha->src)
1648 memset(&op, 0, sizeof(op));
1650 op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
1651 op.sb_ctx = cmd_q->sb_ctx; /* Pre-allocated */
1652 op.u.sha.type = sha->type;
1653 op.u.sha.msg_bits = sha->msg_bits;
1655 /* For SHA1/224/256 the context fits in a single (32-byte) SB entry;
1656 * SHA384/512 require 2 adjacent SB slots, with the right half in the
1657 * first slot, and the left half in the second. Each portion must then
1658 * be in little endian format: use the 256-bit byte swap option.
1660 ret = ccp_init_dm_workarea(&ctx, cmd_q, sb_count * CCP_SB_BYTES,
1665 switch (sha->type) {
1666 case CCP_SHA_TYPE_1:
1667 case CCP_SHA_TYPE_224:
1668 case CCP_SHA_TYPE_256:
1669 memcpy(ctx.address + ioffset, init, ctx_size);
1671 case CCP_SHA_TYPE_384:
1672 case CCP_SHA_TYPE_512:
1673 memcpy(ctx.address + ctx_size / 2, init,
1675 memcpy(ctx.address, init + ctx_size / 2,
1683 /* Restore the context */
1684 ret = ccp_set_dm_area(&ctx, 0, sha->ctx, 0,
1685 sb_count * CCP_SB_BYTES);
1690 ret = ccp_copy_to_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
1691 CCP_PASSTHRU_BYTESWAP_256BIT);
1693 cmd->engine_error = cmd_q->cmd_error;
1698 /* Send data to the CCP SHA engine; block_size is set above */
1699 ret = ccp_init_data(&src, cmd_q, sha->src, sha->src_len,
1700 block_size, DMA_TO_DEVICE);
1704 while (src.sg_wa.bytes_left) {
1705 ccp_prepare_data(&src, NULL, &op, block_size, false);
1706 if (sha->final && !src.sg_wa.bytes_left)
1709 ret = cmd_q->ccp->vdata->perform->sha(&op);
1711 cmd->engine_error = cmd_q->cmd_error;
1715 ccp_process_data(&src, NULL, &op);
1719 ret = cmd_q->ccp->vdata->perform->sha(&op);
1721 cmd->engine_error = cmd_q->cmd_error;
1726 /* Retrieve the SHA context - convert from LE to BE using
1727 * 32-byte (256-bit) byteswapping to BE
1729 ret = ccp_copy_from_sb(cmd_q, &ctx, op.jobid, op.sb_ctx,
1730 CCP_PASSTHRU_BYTESWAP_256BIT);
1732 cmd->engine_error = cmd_q->cmd_error;
1737 /* Finishing up, so get the digest */
1738 switch (sha->type) {
1739 case CCP_SHA_TYPE_1:
1740 case CCP_SHA_TYPE_224:
1741 case CCP_SHA_TYPE_256:
1742 ccp_get_dm_area(&ctx, ooffset,
1746 case CCP_SHA_TYPE_384:
1747 case CCP_SHA_TYPE_512:
1748 ccp_get_dm_area(&ctx, 0,
1749 sha->ctx, LSB_ITEM_SIZE - ooffset,
1751 ccp_get_dm_area(&ctx, LSB_ITEM_SIZE + ooffset,
1753 LSB_ITEM_SIZE - ooffset);
1760 /* Stash the context */
1761 ccp_get_dm_area(&ctx, 0, sha->ctx, 0,
1762 sb_count * CCP_SB_BYTES);
1765 if (sha->final && sha->opad) {
1766 /* HMAC operation, recursively perform final SHA */
1767 struct ccp_cmd hmac_cmd;
1768 struct scatterlist sg;
1771 if (sha->opad_len != block_size) {
1776 hmac_buf = kmalloc(block_size + digest_size, GFP_KERNEL);
1781 sg_init_one(&sg, hmac_buf, block_size + digest_size);
1783 scatterwalk_map_and_copy(hmac_buf, sha->opad, 0, block_size, 0);
1784 switch (sha->type) {
1785 case CCP_SHA_TYPE_1:
1786 case CCP_SHA_TYPE_224:
1787 case CCP_SHA_TYPE_256:
1788 memcpy(hmac_buf + block_size,
1789 ctx.address + ooffset,
1792 case CCP_SHA_TYPE_384:
1793 case CCP_SHA_TYPE_512:
1794 memcpy(hmac_buf + block_size,
1795 ctx.address + LSB_ITEM_SIZE + ooffset,
1797 memcpy(hmac_buf + block_size +
1798 (LSB_ITEM_SIZE - ooffset),
1808 memset(&hmac_cmd, 0, sizeof(hmac_cmd));
1809 hmac_cmd.engine = CCP_ENGINE_SHA;
1810 hmac_cmd.u.sha.type = sha->type;
1811 hmac_cmd.u.sha.ctx = sha->ctx;
1812 hmac_cmd.u.sha.ctx_len = sha->ctx_len;
1813 hmac_cmd.u.sha.src = &sg;
1814 hmac_cmd.u.sha.src_len = block_size + digest_size;
1815 hmac_cmd.u.sha.opad = NULL;
1816 hmac_cmd.u.sha.opad_len = 0;
1817 hmac_cmd.u.sha.first = 1;
1818 hmac_cmd.u.sha.final = 1;
1819 hmac_cmd.u.sha.msg_bits = (block_size + digest_size) << 3;
1821 ret = ccp_run_sha_cmd(cmd_q, &hmac_cmd);
1823 cmd->engine_error = hmac_cmd.engine_error;
1830 ccp_free_data(&src, cmd_q);
1838 static noinline_for_stack int
1839 ccp_run_rsa_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
1841 struct ccp_rsa_engine *rsa = &cmd->u.rsa;
1842 struct ccp_dm_workarea exp, src, dst;
1844 unsigned int sb_count, i_len, o_len;
1847 /* Check against the maximum allowable size, in bits */
1848 if (rsa->key_size > cmd_q->ccp->vdata->rsamax)
1851 if (!rsa->exp || !rsa->mod || !rsa->src || !rsa->dst)
1854 memset(&op, 0, sizeof(op));
1856 op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
1858 /* The RSA modulus must precede the message being acted upon, so
1859 * it must be copied to a DMA area where the message and the
1860 * modulus can be concatenated. Therefore the input buffer
1861 * length required is twice the output buffer length (which
1862 * must be a multiple of 256-bits). Compute o_len, i_len in bytes.
1863 * Buffer sizes must be a multiple of 32 bytes; rounding up may be
1866 o_len = 32 * ((rsa->key_size + 255) / 256);
1870 if (cmd_q->ccp->vdata->version < CCP_VERSION(5, 0)) {
1871 /* sb_count is the number of storage block slots required
1874 sb_count = o_len / CCP_SB_BYTES;
1875 op.sb_key = cmd_q->ccp->vdata->perform->sballoc(cmd_q,
1880 /* A version 5 device allows a modulus size that will not fit
1881 * in the LSB, so the command will transfer it from memory.
1882 * Set the sb key to the default, even though it's not used.
1884 op.sb_key = cmd_q->sb_key;
1887 /* The RSA exponent must be in little endian format. Reverse its
1890 ret = ccp_init_dm_workarea(&exp, cmd_q, o_len, DMA_TO_DEVICE);
1894 ret = ccp_reverse_set_dm_area(&exp, 0, rsa->exp, 0, rsa->exp_len);
1898 if (cmd_q->ccp->vdata->version < CCP_VERSION(5, 0)) {
1899 /* Copy the exponent to the local storage block, using
1900 * as many 32-byte blocks as were allocated above. It's
1901 * already little endian, so no further change is required.
1903 ret = ccp_copy_to_sb(cmd_q, &exp, op.jobid, op.sb_key,
1904 CCP_PASSTHRU_BYTESWAP_NOOP);
1906 cmd->engine_error = cmd_q->cmd_error;
1910 /* The exponent can be retrieved from memory via DMA. */
1911 op.exp.u.dma.address = exp.dma.address;
1912 op.exp.u.dma.offset = 0;
1915 /* Concatenate the modulus and the message. Both the modulus and
1916 * the operands must be in little endian format. Since the input
1917 * is in big endian format it must be converted.
1919 ret = ccp_init_dm_workarea(&src, cmd_q, i_len, DMA_TO_DEVICE);
1923 ret = ccp_reverse_set_dm_area(&src, 0, rsa->mod, 0, rsa->mod_len);
1926 ret = ccp_reverse_set_dm_area(&src, o_len, rsa->src, 0, rsa->src_len);
1930 /* Prepare the output area for the operation */
1931 ret = ccp_init_dm_workarea(&dst, cmd_q, o_len, DMA_FROM_DEVICE);
1936 op.src.u.dma.address = src.dma.address;
1937 op.src.u.dma.offset = 0;
1938 op.src.u.dma.length = i_len;
1939 op.dst.u.dma.address = dst.dma.address;
1940 op.dst.u.dma.offset = 0;
1941 op.dst.u.dma.length = o_len;
1943 op.u.rsa.mod_size = rsa->key_size;
1944 op.u.rsa.input_len = i_len;
1946 ret = cmd_q->ccp->vdata->perform->rsa(&op);
1948 cmd->engine_error = cmd_q->cmd_error;
1952 ccp_reverse_get_dm_area(&dst, 0, rsa->dst, 0, rsa->mod_len);
1965 cmd_q->ccp->vdata->perform->sbfree(cmd_q, op.sb_key, sb_count);
1970 static noinline_for_stack int
1971 ccp_run_passthru_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
1973 struct ccp_passthru_engine *pt = &cmd->u.passthru;
1974 struct ccp_dm_workarea mask;
1975 struct ccp_data src, dst;
1977 bool in_place = false;
1981 if (!pt->final && (pt->src_len & (CCP_PASSTHRU_BLOCKSIZE - 1)))
1984 if (!pt->src || !pt->dst)
1987 if (pt->bit_mod != CCP_PASSTHRU_BITWISE_NOOP) {
1988 if (pt->mask_len != CCP_PASSTHRU_MASKSIZE)
1994 BUILD_BUG_ON(CCP_PASSTHRU_SB_COUNT != 1);
1996 memset(&op, 0, sizeof(op));
1998 op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
2000 if (pt->bit_mod != CCP_PASSTHRU_BITWISE_NOOP) {
2002 op.sb_key = cmd_q->sb_key;
2004 ret = ccp_init_dm_workarea(&mask, cmd_q,
2005 CCP_PASSTHRU_SB_COUNT *
2011 ret = ccp_set_dm_area(&mask, 0, pt->mask, 0, pt->mask_len);
2014 ret = ccp_copy_to_sb(cmd_q, &mask, op.jobid, op.sb_key,
2015 CCP_PASSTHRU_BYTESWAP_NOOP);
2017 cmd->engine_error = cmd_q->cmd_error;
2022 /* Prepare the input and output data workareas. For in-place
2023 * operations we need to set the dma direction to BIDIRECTIONAL
2024 * and copy the src workarea to the dst workarea.
2026 if (sg_virt(pt->src) == sg_virt(pt->dst))
2029 ret = ccp_init_data(&src, cmd_q, pt->src, pt->src_len,
2030 CCP_PASSTHRU_MASKSIZE,
2031 in_place ? DMA_BIDIRECTIONAL : DMA_TO_DEVICE);
2038 ret = ccp_init_data(&dst, cmd_q, pt->dst, pt->src_len,
2039 CCP_PASSTHRU_MASKSIZE, DMA_FROM_DEVICE);
2044 /* Send data to the CCP Passthru engine
2045 * Because the CCP engine works on a single source and destination
2046 * dma address at a time, each entry in the source scatterlist
2047 * (after the dma_map_sg call) must be less than or equal to the
2048 * (remaining) length in the destination scatterlist entry and the
2049 * length must be a multiple of CCP_PASSTHRU_BLOCKSIZE
2051 dst.sg_wa.sg_used = 0;
2052 for (i = 1; i <= src.sg_wa.dma_count; i++) {
2053 if (!dst.sg_wa.sg ||
2054 (sg_dma_len(dst.sg_wa.sg) < sg_dma_len(src.sg_wa.sg))) {
2059 if (i == src.sg_wa.dma_count) {
2064 op.src.type = CCP_MEMTYPE_SYSTEM;
2065 op.src.u.dma.address = sg_dma_address(src.sg_wa.sg);
2066 op.src.u.dma.offset = 0;
2067 op.src.u.dma.length = sg_dma_len(src.sg_wa.sg);
2069 op.dst.type = CCP_MEMTYPE_SYSTEM;
2070 op.dst.u.dma.address = sg_dma_address(dst.sg_wa.sg);
2071 op.dst.u.dma.offset = dst.sg_wa.sg_used;
2072 op.dst.u.dma.length = op.src.u.dma.length;
2074 ret = cmd_q->ccp->vdata->perform->passthru(&op);
2076 cmd->engine_error = cmd_q->cmd_error;
2080 dst.sg_wa.sg_used += sg_dma_len(src.sg_wa.sg);
2081 if (dst.sg_wa.sg_used == sg_dma_len(dst.sg_wa.sg)) {
2082 dst.sg_wa.sg = sg_next(dst.sg_wa.sg);
2083 dst.sg_wa.sg_used = 0;
2085 src.sg_wa.sg = sg_next(src.sg_wa.sg);
2090 ccp_free_data(&dst, cmd_q);
2093 ccp_free_data(&src, cmd_q);
2096 if (pt->bit_mod != CCP_PASSTHRU_BITWISE_NOOP)
2102 static noinline_for_stack int
2103 ccp_run_passthru_nomap_cmd(struct ccp_cmd_queue *cmd_q,
2104 struct ccp_cmd *cmd)
2106 struct ccp_passthru_nomap_engine *pt = &cmd->u.passthru_nomap;
2107 struct ccp_dm_workarea mask;
2111 if (!pt->final && (pt->src_len & (CCP_PASSTHRU_BLOCKSIZE - 1)))
2114 if (!pt->src_dma || !pt->dst_dma)
2117 if (pt->bit_mod != CCP_PASSTHRU_BITWISE_NOOP) {
2118 if (pt->mask_len != CCP_PASSTHRU_MASKSIZE)
2124 BUILD_BUG_ON(CCP_PASSTHRU_SB_COUNT != 1);
2126 memset(&op, 0, sizeof(op));
2128 op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
2130 if (pt->bit_mod != CCP_PASSTHRU_BITWISE_NOOP) {
2132 op.sb_key = cmd_q->sb_key;
2134 mask.length = pt->mask_len;
2135 mask.dma.address = pt->mask;
2136 mask.dma.length = pt->mask_len;
2138 ret = ccp_copy_to_sb(cmd_q, &mask, op.jobid, op.sb_key,
2139 CCP_PASSTHRU_BYTESWAP_NOOP);
2141 cmd->engine_error = cmd_q->cmd_error;
2146 /* Send data to the CCP Passthru engine */
2150 op.src.type = CCP_MEMTYPE_SYSTEM;
2151 op.src.u.dma.address = pt->src_dma;
2152 op.src.u.dma.offset = 0;
2153 op.src.u.dma.length = pt->src_len;
2155 op.dst.type = CCP_MEMTYPE_SYSTEM;
2156 op.dst.u.dma.address = pt->dst_dma;
2157 op.dst.u.dma.offset = 0;
2158 op.dst.u.dma.length = pt->src_len;
2160 ret = cmd_q->ccp->vdata->perform->passthru(&op);
2162 cmd->engine_error = cmd_q->cmd_error;
2167 static int ccp_run_ecc_mm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
2169 struct ccp_ecc_engine *ecc = &cmd->u.ecc;
2170 struct ccp_dm_workarea src, dst;
2175 if (!ecc->u.mm.operand_1 ||
2176 (ecc->u.mm.operand_1_len > CCP_ECC_MODULUS_BYTES))
2179 if (ecc->function != CCP_ECC_FUNCTION_MINV_384BIT)
2180 if (!ecc->u.mm.operand_2 ||
2181 (ecc->u.mm.operand_2_len > CCP_ECC_MODULUS_BYTES))
2184 if (!ecc->u.mm.result ||
2185 (ecc->u.mm.result_len < CCP_ECC_MODULUS_BYTES))
2188 memset(&op, 0, sizeof(op));
2190 op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
2192 /* Concatenate the modulus and the operands. Both the modulus and
2193 * the operands must be in little endian format. Since the input
2194 * is in big endian format it must be converted and placed in a
2195 * fixed length buffer.
2197 ret = ccp_init_dm_workarea(&src, cmd_q, CCP_ECC_SRC_BUF_SIZE,
2202 /* Save the workarea address since it is updated in order to perform
2207 /* Copy the ECC modulus */
2208 ret = ccp_reverse_set_dm_area(&src, 0, ecc->mod, 0, ecc->mod_len);
2211 src.address += CCP_ECC_OPERAND_SIZE;
2213 /* Copy the first operand */
2214 ret = ccp_reverse_set_dm_area(&src, 0, ecc->u.mm.operand_1, 0,
2215 ecc->u.mm.operand_1_len);
2218 src.address += CCP_ECC_OPERAND_SIZE;
2220 if (ecc->function != CCP_ECC_FUNCTION_MINV_384BIT) {
2221 /* Copy the second operand */
2222 ret = ccp_reverse_set_dm_area(&src, 0, ecc->u.mm.operand_2, 0,
2223 ecc->u.mm.operand_2_len);
2226 src.address += CCP_ECC_OPERAND_SIZE;
2229 /* Restore the workarea address */
2232 /* Prepare the output area for the operation */
2233 ret = ccp_init_dm_workarea(&dst, cmd_q, CCP_ECC_DST_BUF_SIZE,
2239 op.src.u.dma.address = src.dma.address;
2240 op.src.u.dma.offset = 0;
2241 op.src.u.dma.length = src.length;
2242 op.dst.u.dma.address = dst.dma.address;
2243 op.dst.u.dma.offset = 0;
2244 op.dst.u.dma.length = dst.length;
2246 op.u.ecc.function = cmd->u.ecc.function;
2248 ret = cmd_q->ccp->vdata->perform->ecc(&op);
2250 cmd->engine_error = cmd_q->cmd_error;
2254 ecc->ecc_result = le16_to_cpup(
2255 (const __le16 *)(dst.address + CCP_ECC_RESULT_OFFSET));
2256 if (!(ecc->ecc_result & CCP_ECC_RESULT_SUCCESS)) {
2261 /* Save the ECC result */
2262 ccp_reverse_get_dm_area(&dst, 0, ecc->u.mm.result, 0,
2263 CCP_ECC_MODULUS_BYTES);
2274 static int ccp_run_ecc_pm_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
2276 struct ccp_ecc_engine *ecc = &cmd->u.ecc;
2277 struct ccp_dm_workarea src, dst;
2282 if (!ecc->u.pm.point_1.x ||
2283 (ecc->u.pm.point_1.x_len > CCP_ECC_MODULUS_BYTES) ||
2284 !ecc->u.pm.point_1.y ||
2285 (ecc->u.pm.point_1.y_len > CCP_ECC_MODULUS_BYTES))
2288 if (ecc->function == CCP_ECC_FUNCTION_PADD_384BIT) {
2289 if (!ecc->u.pm.point_2.x ||
2290 (ecc->u.pm.point_2.x_len > CCP_ECC_MODULUS_BYTES) ||
2291 !ecc->u.pm.point_2.y ||
2292 (ecc->u.pm.point_2.y_len > CCP_ECC_MODULUS_BYTES))
2295 if (!ecc->u.pm.domain_a ||
2296 (ecc->u.pm.domain_a_len > CCP_ECC_MODULUS_BYTES))
2299 if (ecc->function == CCP_ECC_FUNCTION_PMUL_384BIT)
2300 if (!ecc->u.pm.scalar ||
2301 (ecc->u.pm.scalar_len > CCP_ECC_MODULUS_BYTES))
2305 if (!ecc->u.pm.result.x ||
2306 (ecc->u.pm.result.x_len < CCP_ECC_MODULUS_BYTES) ||
2307 !ecc->u.pm.result.y ||
2308 (ecc->u.pm.result.y_len < CCP_ECC_MODULUS_BYTES))
2311 memset(&op, 0, sizeof(op));
2313 op.jobid = CCP_NEW_JOBID(cmd_q->ccp);
2315 /* Concatenate the modulus and the operands. Both the modulus and
2316 * the operands must be in little endian format. Since the input
2317 * is in big endian format it must be converted and placed in a
2318 * fixed length buffer.
2320 ret = ccp_init_dm_workarea(&src, cmd_q, CCP_ECC_SRC_BUF_SIZE,
2325 /* Save the workarea address since it is updated in order to perform
2330 /* Copy the ECC modulus */
2331 ret = ccp_reverse_set_dm_area(&src, 0, ecc->mod, 0, ecc->mod_len);
2334 src.address += CCP_ECC_OPERAND_SIZE;
2336 /* Copy the first point X and Y coordinate */
2337 ret = ccp_reverse_set_dm_area(&src, 0, ecc->u.pm.point_1.x, 0,
2338 ecc->u.pm.point_1.x_len);
2341 src.address += CCP_ECC_OPERAND_SIZE;
2342 ret = ccp_reverse_set_dm_area(&src, 0, ecc->u.pm.point_1.y, 0,
2343 ecc->u.pm.point_1.y_len);
2346 src.address += CCP_ECC_OPERAND_SIZE;
2348 /* Set the first point Z coordinate to 1 */
2349 *src.address = 0x01;
2350 src.address += CCP_ECC_OPERAND_SIZE;
2352 if (ecc->function == CCP_ECC_FUNCTION_PADD_384BIT) {
2353 /* Copy the second point X and Y coordinate */
2354 ret = ccp_reverse_set_dm_area(&src, 0, ecc->u.pm.point_2.x, 0,
2355 ecc->u.pm.point_2.x_len);
2358 src.address += CCP_ECC_OPERAND_SIZE;
2359 ret = ccp_reverse_set_dm_area(&src, 0, ecc->u.pm.point_2.y, 0,
2360 ecc->u.pm.point_2.y_len);
2363 src.address += CCP_ECC_OPERAND_SIZE;
2365 /* Set the second point Z coordinate to 1 */
2366 *src.address = 0x01;
2367 src.address += CCP_ECC_OPERAND_SIZE;
2369 /* Copy the Domain "a" parameter */
2370 ret = ccp_reverse_set_dm_area(&src, 0, ecc->u.pm.domain_a, 0,
2371 ecc->u.pm.domain_a_len);
2374 src.address += CCP_ECC_OPERAND_SIZE;
2376 if (ecc->function == CCP_ECC_FUNCTION_PMUL_384BIT) {
2377 /* Copy the scalar value */
2378 ret = ccp_reverse_set_dm_area(&src, 0,
2379 ecc->u.pm.scalar, 0,
2380 ecc->u.pm.scalar_len);
2383 src.address += CCP_ECC_OPERAND_SIZE;
2387 /* Restore the workarea address */
2390 /* Prepare the output area for the operation */
2391 ret = ccp_init_dm_workarea(&dst, cmd_q, CCP_ECC_DST_BUF_SIZE,
2397 op.src.u.dma.address = src.dma.address;
2398 op.src.u.dma.offset = 0;
2399 op.src.u.dma.length = src.length;
2400 op.dst.u.dma.address = dst.dma.address;
2401 op.dst.u.dma.offset = 0;
2402 op.dst.u.dma.length = dst.length;
2404 op.u.ecc.function = cmd->u.ecc.function;
2406 ret = cmd_q->ccp->vdata->perform->ecc(&op);
2408 cmd->engine_error = cmd_q->cmd_error;
2412 ecc->ecc_result = le16_to_cpup(
2413 (const __le16 *)(dst.address + CCP_ECC_RESULT_OFFSET));
2414 if (!(ecc->ecc_result & CCP_ECC_RESULT_SUCCESS)) {
2419 /* Save the workarea address since it is updated as we walk through
2420 * to copy the point math result
2424 /* Save the ECC result X and Y coordinates */
2425 ccp_reverse_get_dm_area(&dst, 0, ecc->u.pm.result.x, 0,
2426 CCP_ECC_MODULUS_BYTES);
2427 dst.address += CCP_ECC_OUTPUT_SIZE;
2428 ccp_reverse_get_dm_area(&dst, 0, ecc->u.pm.result.y, 0,
2429 CCP_ECC_MODULUS_BYTES);
2430 dst.address += CCP_ECC_OUTPUT_SIZE;
2432 /* Restore the workarea address */
2444 static noinline_for_stack int
2445 ccp_run_ecc_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
2447 struct ccp_ecc_engine *ecc = &cmd->u.ecc;
2449 ecc->ecc_result = 0;
2452 (ecc->mod_len > CCP_ECC_MODULUS_BYTES))
2455 switch (ecc->function) {
2456 case CCP_ECC_FUNCTION_MMUL_384BIT:
2457 case CCP_ECC_FUNCTION_MADD_384BIT:
2458 case CCP_ECC_FUNCTION_MINV_384BIT:
2459 return ccp_run_ecc_mm_cmd(cmd_q, cmd);
2461 case CCP_ECC_FUNCTION_PADD_384BIT:
2462 case CCP_ECC_FUNCTION_PMUL_384BIT:
2463 case CCP_ECC_FUNCTION_PDBL_384BIT:
2464 return ccp_run_ecc_pm_cmd(cmd_q, cmd);
2471 int ccp_run_cmd(struct ccp_cmd_queue *cmd_q, struct ccp_cmd *cmd)
2475 cmd->engine_error = 0;
2476 cmd_q->cmd_error = 0;
2477 cmd_q->int_rcvd = 0;
2478 cmd_q->free_slots = cmd_q->ccp->vdata->perform->get_free_slots(cmd_q);
2480 switch (cmd->engine) {
2481 case CCP_ENGINE_AES:
2482 switch (cmd->u.aes.mode) {
2483 case CCP_AES_MODE_CMAC:
2484 ret = ccp_run_aes_cmac_cmd(cmd_q, cmd);
2486 case CCP_AES_MODE_GCM:
2487 ret = ccp_run_aes_gcm_cmd(cmd_q, cmd);
2490 ret = ccp_run_aes_cmd(cmd_q, cmd);
2494 case CCP_ENGINE_XTS_AES_128:
2495 ret = ccp_run_xts_aes_cmd(cmd_q, cmd);
2497 case CCP_ENGINE_DES3:
2498 ret = ccp_run_des3_cmd(cmd_q, cmd);
2500 case CCP_ENGINE_SHA:
2501 ret = ccp_run_sha_cmd(cmd_q, cmd);
2503 case CCP_ENGINE_RSA:
2504 ret = ccp_run_rsa_cmd(cmd_q, cmd);
2506 case CCP_ENGINE_PASSTHRU:
2507 if (cmd->flags & CCP_CMD_PASSTHRU_NO_DMA_MAP)
2508 ret = ccp_run_passthru_nomap_cmd(cmd_q, cmd);
2510 ret = ccp_run_passthru_cmd(cmd_q, cmd);
2512 case CCP_ENGINE_ECC:
2513 ret = ccp_run_ecc_cmd(cmd_q, cmd);