1 --- a/drivers/crypto/Kconfig
2 +++ b/drivers/crypto/Kconfig
3 @@ -437,4 +437,21 @@ config CRYPTO_DEV_QCE
4 hardware. To compile this driver as a module, choose M here. The
5 module will be called qcrypto.
7 +config CRYPTO_DEV_SUNXI_SS
8 + tristate "Support for Allwinner Security System cryptographic accelerator"
9 + depends on ARCH_SUNXI
14 + select CRYPTO_BLKCIPHER
16 + Some Allwinner SoC have a crypto accelerator named
17 + Security System. Select this if you want to use it.
18 + The Security System handle AES/DES/3DES ciphers in CBC mode
19 + and SHA1 and MD5 hash algorithms.
21 + To compile this driver as a module, choose M here: the module
22 + will be called sunxi-ss.
25 --- a/drivers/crypto/Makefile
26 +++ b/drivers/crypto/Makefile
27 @@ -25,3 +25,4 @@ obj-$(CONFIG_CRYPTO_DEV_TALITOS) += tali
28 obj-$(CONFIG_CRYPTO_DEV_UX500) += ux500/
29 obj-$(CONFIG_CRYPTO_DEV_QAT) += qat/
30 obj-$(CONFIG_CRYPTO_DEV_QCE) += qce/
31 +obj-$(CONFIG_CRYPTO_DEV_SUNXI_SS) += sunxi-ss/
33 +++ b/drivers/crypto/sunxi-ss/Makefile
35 +obj-$(CONFIG_CRYPTO_DEV_SUNXI_SS) += sunxi-ss.o
36 +sunxi-ss-y += sunxi-ss-core.o sunxi-ss-hash.o sunxi-ss-cipher.o
38 +++ b/drivers/crypto/sunxi-ss/sunxi-ss-cipher.c
41 + * sunxi-ss-cipher.c - hardware cryptographic accelerator for Allwinner A20 SoC
43 + * Copyright (C) 2013-2014 Corentin LABBE <clabbe.montjoie@gmail.com>
45 + * This file add support for AES cipher with 128,192,256 bits
46 + * keysize in CBC mode.
47 + * Add support also for DES and 3DES in CBC mode.
49 + * You could find the datasheet in Documentation/arm/sunxi/README
51 + * This program is free software; you can redistribute it and/or modify
52 + * it under the terms of the GNU General Public License as published by
53 + * the Free Software Foundation; either version 2 of the License, or
54 + * (at your option) any later version.
56 +#include "sunxi-ss.h"
58 +extern struct sunxi_ss_ctx *ss;
60 +static int sunxi_ss_cipher(struct ablkcipher_request *areq, u32 mode)
62 + struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(areq);
63 + struct sunxi_tfm_ctx *op = crypto_ablkcipher_ctx(tfm);
64 + const char *cipher_type;
66 + if (areq->nbytes == 0)
69 + if (areq->info == NULL) {
70 + dev_err(ss->dev, "ERROR: Empty IV\n");
74 + if (areq->src == NULL || areq->dst == NULL) {
75 + dev_err(ss->dev, "ERROR: Some SGs are NULL\n");
79 + cipher_type = crypto_tfm_alg_name(crypto_ablkcipher_tfm(tfm));
81 + if (strcmp("cbc(aes)", cipher_type) == 0) {
82 + mode |= SS_OP_AES | SS_CBC | SS_ENABLED | op->keymode;
83 + return sunxi_ss_aes_poll(areq, mode);
86 + if (strcmp("cbc(des)", cipher_type) == 0) {
87 + mode |= SS_OP_DES | SS_CBC | SS_ENABLED | op->keymode;
88 + return sunxi_ss_des_poll(areq, mode);
91 + if (strcmp("cbc(des3_ede)", cipher_type) == 0) {
92 + mode |= SS_OP_3DES | SS_CBC | SS_ENABLED | op->keymode;
93 + return sunxi_ss_des_poll(areq, mode);
96 + dev_err(ss->dev, "ERROR: Cipher %s not handled\n", cipher_type);
100 +int sunxi_ss_cipher_encrypt(struct ablkcipher_request *areq)
102 + return sunxi_ss_cipher(areq, SS_ENCRYPTION);
105 +int sunxi_ss_cipher_decrypt(struct ablkcipher_request *areq)
107 + return sunxi_ss_cipher(areq, SS_DECRYPTION);
110 +int sunxi_ss_cipher_init(struct crypto_tfm *tfm)
112 + struct sunxi_tfm_ctx *op = crypto_tfm_ctx(tfm);
114 + memset(op, 0, sizeof(struct sunxi_tfm_ctx));
119 + * Optimized function for the case where we have only one SG,
120 + * so we can use kmap_atomic
122 +static int sunxi_ss_aes_poll_atomic(struct ablkcipher_request *areq)
125 + struct scatterlist *in_sg = areq->src;
126 + struct scatterlist *out_sg = areq->dst;
129 + unsigned int ileft = areq->nbytes;
130 + unsigned int oleft = areq->nbytes;
138 + src_addr = kmap_atomic(sg_page(in_sg)) + in_sg->offset;
139 + if (src_addr == NULL) {
140 + dev_err(ss->dev, "kmap_atomic error for src SG\n");
141 + writel(0, ss->base + SS_CTL);
142 + mutex_unlock(&ss->lock);
146 + dst_addr = kmap_atomic(sg_page(out_sg)) + out_sg->offset;
147 + if (dst_addr == NULL) {
148 + dev_err(ss->dev, "kmap_atomic error for dst SG\n");
149 + writel(0, ss->base + SS_CTL);
150 + kunmap_atomic(src_addr);
151 + mutex_unlock(&ss->lock);
155 + src32 = (u32 *)src_addr;
156 + dst32 = (u32 *)dst_addr;
157 + ileft = areq->nbytes / 4;
158 + oleft = areq->nbytes / 4;
161 + if (ileft > 0 && rx_cnt > 0) {
162 + todo = min(rx_cnt, ileft);
165 + writel_relaxed(*src32++,
169 + } while (todo > 0);
172 + todo = min(tx_cnt, oleft);
175 + *dst32++ = readl_relaxed(ss->base +
178 + } while (todo > 0);
180 + spaces = readl_relaxed(ss->base + SS_FCSR);
181 + rx_cnt = SS_RXFIFO_SPACES(spaces);
182 + tx_cnt = SS_TXFIFO_SPACES(spaces);
183 + } while (oleft > 0);
184 + writel(0, ss->base + SS_CTL);
185 + kunmap_atomic(src_addr);
186 + kunmap_atomic(dst_addr);
187 + mutex_unlock(&ss->lock);
191 +int sunxi_ss_aes_poll(struct ablkcipher_request *areq, u32 mode)
194 + struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(areq);
195 + struct sunxi_tfm_ctx *op = crypto_ablkcipher_ctx(tfm);
196 + unsigned int ivsize = crypto_ablkcipher_ivsize(tfm);
197 + /* when activating SS, the default FIFO space is 32 */
202 + struct scatterlist *in_sg = areq->src;
203 + struct scatterlist *out_sg = areq->dst;
206 + unsigned int ileft = areq->nbytes;
207 + unsigned int oleft = areq->nbytes;
208 + unsigned int sgileft = areq->src->length;
209 + unsigned int sgoleft = areq->dst->length;
214 + mutex_lock(&ss->lock);
216 + for (i = 0; i < op->keylen; i += 4)
217 + writel(*(op->key + i/4), ss->base + SS_KEY0 + i);
219 + if (areq->info != NULL) {
220 + for (i = 0; i < 4 && i < ivsize / 4; i++) {
221 + v = *(u32 *)(areq->info + i * 4);
222 + writel(v, ss->base + SS_IV0 + i * 4);
225 + writel(mode, ss->base + SS_CTL);
227 + /* If we have only one SG, we can use kmap_atomic */
228 + if (sg_next(in_sg) == NULL && sg_next(out_sg) == NULL)
229 + return sunxi_ss_aes_poll_atomic(areq);
232 + * If we have more than one SG, we cannot use kmap_atomic since
233 + * we hold the mapping too long
235 + src_addr = kmap(sg_page(in_sg)) + in_sg->offset;
236 + if (src_addr == NULL) {
237 + dev_err(ss->dev, "KMAP error for src SG\n");
238 + mutex_unlock(&ss->lock);
241 + dst_addr = kmap(sg_page(out_sg)) + out_sg->offset;
242 + if (dst_addr == NULL) {
243 + kunmap(sg_page(in_sg));
244 + dev_err(ss->dev, "KMAP error for dst SG\n");
245 + mutex_unlock(&ss->lock);
248 + src32 = (u32 *)src_addr;
249 + dst32 = (u32 *)dst_addr;
250 + ileft = areq->nbytes / 4;
251 + oleft = areq->nbytes / 4;
252 + sgileft = in_sg->length / 4;
253 + sgoleft = out_sg->length / 4;
255 + spaces = readl_relaxed(ss->base + SS_FCSR);
256 + rx_cnt = SS_RXFIFO_SPACES(spaces);
257 + tx_cnt = SS_TXFIFO_SPACES(spaces);
258 + todo = min3(rx_cnt, ileft, sgileft);
264 + writel_relaxed(*src32++, ss->base + SS_RXFIFO);
267 + if (in_sg != NULL && sgileft == 0 && ileft > 0) {
268 + kunmap(sg_page(in_sg));
269 + in_sg = sg_next(in_sg);
270 + while (in_sg != NULL && in_sg->length == 0)
271 + in_sg = sg_next(in_sg);
272 + if (in_sg != NULL && ileft > 0) {
273 + src_addr = kmap(sg_page(in_sg)) + in_sg->offset;
274 + if (src_addr == NULL) {
275 + dev_err(ss->dev, "ERROR: KMAP for src SG\n");
276 + mutex_unlock(&ss->lock);
280 + sgileft = in_sg->length / 4;
283 + /* do not test oleft since when oleft == 0 we have finished */
284 + todo = min3(tx_cnt, oleft, sgoleft);
290 + *dst32++ = readl_relaxed(ss->base + SS_TXFIFO);
293 + if (out_sg != NULL && sgoleft == 0 && oleft >= 0) {
294 + kunmap(sg_page(out_sg));
295 + out_sg = sg_next(out_sg);
296 + while (out_sg != NULL && out_sg->length == 0)
297 + out_sg = sg_next(out_sg);
298 + if (out_sg != NULL && oleft > 0) {
299 + dst_addr = kmap(sg_page(out_sg)) +
301 + if (dst_addr == NULL) {
302 + dev_err(ss->dev, "KMAP error\n");
303 + mutex_unlock(&ss->lock);
307 + sgoleft = out_sg->length / 4;
310 + } while (oleft > 0);
312 + writel_relaxed(0, ss->base + SS_CTL);
313 + mutex_unlock(&ss->lock);
318 + * Pure CPU way of doing DES/3DES with SS
319 + * Since DES and 3DES SGs could be smaller than 4 bytes, I use sg_copy_to_buffer
320 + * for "linearize" them.
321 + * The problem with that is that I alloc (2 x areq->nbytes) for buf_in/buf_out
322 + * TODO: change this system, I need to support other mode than CBC where len
323 + * is not a multiple of 4 and the hack of linearize use too much memory
324 + * SGsrc -> buf_in -> SS -> buf_out -> SGdst
326 +int sunxi_ss_des_poll(struct ablkcipher_request *areq, u32 mode)
329 + size_t nb_in_sg_tx, nb_in_sg_rx;
331 + struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(areq);
332 + struct sunxi_tfm_ctx *op = crypto_ablkcipher_ctx(tfm);
333 + unsigned int ivsize = crypto_ablkcipher_ivsize(tfm);
339 + struct scatterlist *in_sg = areq->src;
340 + struct scatterlist *out_sg = areq->dst;
343 + * if we have only SGs with size multiple of 4,
344 + * we can use the SS AES function
346 + while (in_sg != NULL && no_chunk == 1) {
347 + if ((in_sg->length % 4) != 0)
349 + in_sg = sg_next(in_sg);
351 + while (out_sg != NULL && no_chunk == 1) {
352 + if ((out_sg->length % 4) != 0)
354 + out_sg = sg_next(out_sg);
358 + return sunxi_ss_aes_poll(areq, mode);
361 + out_sg = areq->dst;
363 + nb_in_sg_rx = sg_nents(in_sg);
364 + nb_in_sg_tx = sg_nents(out_sg);
367 + * buf_in and buf_out are allocated only one time
368 + * then we keep the buffer until driver end
369 + * the allocation can only grow more
370 + * we do not reduce it for simplification
372 + mutex_lock(&ss->bufin_lock);
373 + if (ss->buf_in == NULL) {
374 + ss->buf_in = kmalloc(areq->nbytes, GFP_KERNEL);
375 + ss->buf_in_size = areq->nbytes;
377 + if (areq->nbytes > ss->buf_in_size) {
379 + ss->buf_in = kmalloc(areq->nbytes, GFP_KERNEL);
380 + ss->buf_in_size = areq->nbytes;
383 + if (ss->buf_in == NULL) {
384 + ss->buf_in_size = 0;
385 + mutex_unlock(&ss->bufin_lock);
386 + dev_err(ss->dev, "Unable to allocate pages.\n");
389 + mutex_lock(&ss->bufout_lock);
390 + if (ss->buf_out == NULL) {
391 + ss->buf_out = kmalloc(areq->nbytes, GFP_KERNEL);
392 + if (ss->buf_out == NULL) {
393 + ss->buf_out_size = 0;
394 + mutex_unlock(&ss->bufin_lock);
395 + mutex_unlock(&ss->bufout_lock);
396 + dev_err(ss->dev, "Unable to allocate pages.\n");
399 + ss->buf_out_size = areq->nbytes;
401 + if (areq->nbytes > ss->buf_out_size) {
402 + kfree(ss->buf_out);
403 + ss->buf_out = kmalloc(areq->nbytes, GFP_KERNEL);
404 + if (ss->buf_out == NULL) {
405 + ss->buf_out_size = 0;
406 + mutex_unlock(&ss->bufin_lock);
407 + mutex_unlock(&ss->bufout_lock);
408 + dev_err(ss->dev, "Unable to allocate pages.\n");
411 + ss->buf_out_size = areq->nbytes;
415 + sg_copy_to_buffer(areq->src, nb_in_sg_rx, ss->buf_in, areq->nbytes);
419 + mutex_lock(&ss->lock);
421 + for (i = 0; i < op->keylen; i += 4)
422 + writel(*(op->key + i/4), ss->base + SS_KEY0 + i);
423 + if (areq->info != NULL) {
424 + for (i = 0; i < 4 && i < ivsize / 4; i++) {
425 + v = *(u32 *)(areq->info + i * 4);
426 + writel(v, ss->base + SS_IV0 + i * 4);
429 + writel(mode, ss->base + SS_CTL);
432 + if (rx_cnt == 0 || tx_cnt == 0) {
433 + spaces = readl(ss->base + SS_FCSR);
434 + rx_cnt = SS_RXFIFO_SPACES(spaces);
435 + tx_cnt = SS_TXFIFO_SPACES(spaces);
437 + if (rx_cnt > 0 && ir < areq->nbytes) {
439 + value = *(u32 *)(ss->buf_in + ir);
440 + writel(value, ss->base + SS_RXFIFO);
443 + } while (rx_cnt > 0 && ir < areq->nbytes);
445 + if (tx_cnt > 0 && it < areq->nbytes) {
447 + value = readl(ss->base + SS_TXFIFO);
448 + *(u32 *)(ss->buf_out + it) = value;
451 + } while (tx_cnt > 0 && it < areq->nbytes);
453 + if (ir == areq->nbytes) {
454 + mutex_unlock(&ss->bufin_lock);
457 + } while (it < areq->nbytes);
459 + writel(0, ss->base + SS_CTL);
460 + mutex_unlock(&ss->lock);
463 + * a simple optimization, since we dont need the hardware for this copy
464 + * we release the lock and do the copy. With that we gain 5/10% perf
466 + sg_copy_from_buffer(areq->dst, nb_in_sg_tx, ss->buf_out, areq->nbytes);
468 + mutex_unlock(&ss->bufout_lock);
472 +/* check and set the AES key, prepare the mode to be used */
473 +int sunxi_ss_aes_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
474 + unsigned int keylen)
476 + struct sunxi_tfm_ctx *op = crypto_ablkcipher_ctx(tfm);
480 + op->keymode = SS_AES_128BITS;
483 + op->keymode = SS_AES_192BITS;
486 + op->keymode = SS_AES_256BITS;
489 + dev_err(ss->dev, "ERROR: Invalid keylen %u\n", keylen);
490 + crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
493 + op->keylen = keylen;
494 + memcpy(op->key, key, keylen);
498 +/* check and set the DES key, prepare the mode to be used */
499 +int sunxi_ss_des_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
500 + unsigned int keylen)
502 + struct sunxi_tfm_ctx *op = crypto_ablkcipher_ctx(tfm);
504 + if (keylen != DES_KEY_SIZE) {
505 + dev_err(ss->dev, "Invalid keylen %u\n", keylen);
506 + crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
509 + op->keylen = keylen;
510 + memcpy(op->key, key, keylen);
514 +/* check and set the 3DES key, prepare the mode to be used */
515 +int sunxi_ss_des3_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
516 + unsigned int keylen)
518 + struct sunxi_tfm_ctx *op = crypto_ablkcipher_ctx(tfm);
520 + if (keylen != 3 * DES_KEY_SIZE) {
521 + dev_err(ss->dev, "Invalid keylen %u\n", keylen);
522 + crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
525 + op->keylen = keylen;
526 + memcpy(op->key, key, keylen);
530 +++ b/drivers/crypto/sunxi-ss/sunxi-ss-core.c
533 + * sunxi-ss-core.c - hardware cryptographic accelerator for Allwinner A20 SoC
535 + * Copyright (C) 2013-2014 Corentin LABBE <clabbe.montjoie@gmail.com>
537 + * Core file which registers crypto algorithms supported by the SS.
539 + * You could find a link for the datasheet in Documentation/arm/sunxi/README
541 + * This program is free software; you can redistribute it and/or modify
542 + * it under the terms of the GNU General Public License as published by
543 + * the Free Software Foundation; either version 2 of the License, or
544 + * (at your option) any later version.
546 +#include <linux/clk.h>
547 +#include <linux/crypto.h>
548 +#include <linux/io.h>
549 +#include <linux/module.h>
550 +#include <linux/of.h>
551 +#include <linux/platform_device.h>
552 +#include <crypto/scatterwalk.h>
553 +#include <linux/scatterlist.h>
554 +#include <linux/interrupt.h>
555 +#include <linux/delay.h>
557 +#include "sunxi-ss.h"
559 +struct sunxi_ss_ctx *ss;
562 + * General notes for whole driver:
564 + * After each request the device must be disabled with a write of 0 in SS_CTL
566 + * For performance reason, we use writel_relaxed/read_relaxed for all
567 + * operations on RX and TX FIFO and also SS_FCSR.
568 + * Excepts for the last write on TX FIFO.
569 + * For all other registers, we use writel/readl.
570 + * See http://permalink.gmane.org/gmane.linux.ports.arm.kernel/117644
571 + * and http://permalink.gmane.org/gmane.linux.ports.arm.kernel/117640
574 +static struct ahash_alg sunxi_md5_alg = {
575 + .init = sunxi_hash_init,
576 + .update = sunxi_hash_update,
577 + .final = sunxi_hash_final,
578 + .finup = sunxi_hash_finup,
579 + .digest = sunxi_hash_digest,
581 + .digestsize = MD5_DIGEST_SIZE,
584 + .cra_driver_name = "md5-sunxi-ss",
585 + .cra_priority = 300,
586 + .cra_alignmask = 3,
587 + .cra_flags = CRYPTO_ALG_TYPE_AHASH | CRYPTO_ALG_ASYNC,
588 + .cra_blocksize = MD5_HMAC_BLOCK_SIZE,
589 + .cra_ctxsize = sizeof(struct sunxi_req_ctx),
590 + .cra_module = THIS_MODULE,
591 + .cra_type = &crypto_ahash_type,
592 + .cra_init = sunxi_hash_crainit
597 +static struct ahash_alg sunxi_sha1_alg = {
598 + .init = sunxi_hash_init,
599 + .update = sunxi_hash_update,
600 + .final = sunxi_hash_final,
601 + .finup = sunxi_hash_finup,
602 + .digest = sunxi_hash_digest,
604 + .digestsize = SHA1_DIGEST_SIZE,
606 + .cra_name = "sha1",
607 + .cra_driver_name = "sha1-sunxi-ss",
608 + .cra_priority = 300,
609 + .cra_alignmask = 3,
610 + .cra_flags = CRYPTO_ALG_TYPE_AHASH | CRYPTO_ALG_ASYNC,
611 + .cra_blocksize = SHA1_BLOCK_SIZE,
612 + .cra_ctxsize = sizeof(struct sunxi_req_ctx),
613 + .cra_module = THIS_MODULE,
614 + .cra_type = &crypto_ahash_type,
615 + .cra_init = sunxi_hash_crainit
620 +static struct crypto_alg sunxi_cipher_algs[] = {
622 + .cra_name = "cbc(aes)",
623 + .cra_driver_name = "cbc-aes-sunxi-ss",
624 + .cra_priority = 300,
625 + .cra_blocksize = AES_BLOCK_SIZE,
626 + .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER,
627 + .cra_ctxsize = sizeof(struct sunxi_tfm_ctx),
628 + .cra_module = THIS_MODULE,
629 + .cra_alignmask = 3,
630 + .cra_type = &crypto_ablkcipher_type,
631 + .cra_init = sunxi_ss_cipher_init,
634 + .min_keysize = AES_MIN_KEY_SIZE,
635 + .max_keysize = AES_MAX_KEY_SIZE,
636 + .ivsize = AES_BLOCK_SIZE,
637 + .setkey = sunxi_ss_aes_setkey,
638 + .encrypt = sunxi_ss_cipher_encrypt,
639 + .decrypt = sunxi_ss_cipher_decrypt,
643 + .cra_name = "cbc(des)",
644 + .cra_driver_name = "cbc-des-sunxi-ss",
645 + .cra_priority = 300,
646 + .cra_blocksize = DES_BLOCK_SIZE,
647 + .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER,
648 + .cra_ctxsize = sizeof(struct sunxi_req_ctx),
649 + .cra_module = THIS_MODULE,
650 + .cra_alignmask = 3,
651 + .cra_type = &crypto_ablkcipher_type,
652 + .cra_init = sunxi_ss_cipher_init,
653 + .cra_u.ablkcipher = {
654 + .min_keysize = DES_KEY_SIZE,
655 + .max_keysize = DES_KEY_SIZE,
656 + .ivsize = DES_BLOCK_SIZE,
657 + .setkey = sunxi_ss_des_setkey,
658 + .encrypt = sunxi_ss_cipher_encrypt,
659 + .decrypt = sunxi_ss_cipher_decrypt,
662 + .cra_name = "cbc(des3_ede)",
663 + .cra_driver_name = "cbc-des3-sunxi-ss",
664 + .cra_priority = 300,
665 + .cra_blocksize = DES3_EDE_BLOCK_SIZE,
666 + .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER,
667 + .cra_ctxsize = sizeof(struct sunxi_req_ctx),
668 + .cra_module = THIS_MODULE,
669 + .cra_alignmask = 3,
670 + .cra_type = &crypto_ablkcipher_type,
671 + .cra_init = sunxi_ss_cipher_init,
672 + .cra_u.ablkcipher = {
673 + .min_keysize = DES3_EDE_KEY_SIZE,
674 + .max_keysize = DES3_EDE_KEY_SIZE,
675 + .ivsize = DES3_EDE_BLOCK_SIZE,
676 + .setkey = sunxi_ss_des3_setkey,
677 + .encrypt = sunxi_ss_cipher_encrypt,
678 + .decrypt = sunxi_ss_cipher_decrypt,
683 +static int sunxi_ss_probe(struct platform_device *pdev)
685 + struct resource *res;
689 + const unsigned long cr_ahb = 24 * 1000 * 1000;
690 + const unsigned long cr_mod = 150 * 1000 * 1000;
692 + if (!pdev->dev.of_node)
695 + ss = devm_kzalloc(&pdev->dev, sizeof(*ss), GFP_KERNEL);
699 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
700 + ss->base = devm_ioremap_resource(&pdev->dev, res);
701 + if (IS_ERR(ss->base)) {
702 + dev_err(&pdev->dev, "Cannot request MMIO\n");
703 + return PTR_ERR(ss->base);
706 + ss->ssclk = devm_clk_get(&pdev->dev, "mod");
707 + if (IS_ERR(ss->ssclk)) {
708 + err = PTR_ERR(ss->ssclk);
709 + dev_err(&pdev->dev, "Cannot get SS clock err=%d\n", err);
712 + dev_dbg(&pdev->dev, "clock ss acquired\n");
714 + ss->busclk = devm_clk_get(&pdev->dev, "ahb");
715 + if (IS_ERR(ss->busclk)) {
716 + err = PTR_ERR(ss->busclk);
717 + dev_err(&pdev->dev, "Cannot get AHB SS clock err=%d\n", err);
720 + dev_dbg(&pdev->dev, "clock ahb_ss acquired\n");
722 + /* Enable both clocks */
723 + err = clk_prepare_enable(ss->busclk);
725 + dev_err(&pdev->dev, "Cannot prepare_enable busclk\n");
728 + err = clk_prepare_enable(ss->ssclk);
730 + dev_err(&pdev->dev, "Cannot prepare_enable ssclk\n");
731 + clk_disable_unprepare(ss->busclk);
736 + * Check that clock have the correct rates gived in the datasheet
737 + * Try to set the clock to the maximum allowed
739 + err = clk_set_rate(ss->ssclk, cr_mod);
741 + dev_err(&pdev->dev, "Cannot set clock rate to ssclk\n");
742 + clk_disable_unprepare(ss->ssclk);
743 + clk_disable_unprepare(ss->busclk);
747 + cr = clk_get_rate(ss->busclk);
749 + dev_dbg(&pdev->dev, "Clock bus %lu (%lu MHz) (must be >= %lu)\n",
750 + cr, cr / 1000000, cr_ahb);
752 + dev_warn(&pdev->dev, "Clock bus %lu (%lu MHz) (must be >= %lu)\n",
753 + cr, cr / 1000000, cr_ahb);
755 + cr = clk_get_rate(ss->ssclk);
758 + dev_info(&pdev->dev, "Clock ss %lu (%lu MHz) (must be <= %lu)\n",
759 + cr, cr / 1000000, cr_mod);
761 + dev_dbg(&pdev->dev, "Clock ss %lu (%lu MHz) (must be <= %lu)\n",
762 + cr, cr / 1000000, cr_mod);
764 + dev_warn(&pdev->dev, "Clock ss is at %lu (%lu MHz) (must be <= %lu)\n",
765 + cr, cr / 1000000, cr_mod);
768 + * Datasheet named it "Die Bonding ID"
769 + * I expect to be a sort of Security System Revision number.
770 + * Since the A80 seems to have an other version of SS
771 + * this info could be useful
773 + writel(SS_ENABLED, ss->base + SS_CTL);
774 + v = readl(ss->base + SS_CTL);
777 + dev_info(&pdev->dev, "Die ID %d\n", v);
778 + writel(0, ss->base + SS_CTL);
780 + ss->dev = &pdev->dev;
782 + mutex_init(&ss->lock);
783 + mutex_init(&ss->bufin_lock);
784 + mutex_init(&ss->bufout_lock);
786 + err = crypto_register_ahash(&sunxi_md5_alg);
789 + err = crypto_register_ahash(&sunxi_sha1_alg);
792 + err = crypto_register_algs(sunxi_cipher_algs,
793 + ARRAY_SIZE(sunxi_cipher_algs));
795 + goto error_ciphers;
799 + crypto_unregister_ahash(&sunxi_sha1_alg);
801 + crypto_unregister_ahash(&sunxi_md5_alg);
803 + clk_disable_unprepare(ss->ssclk);
804 + clk_disable_unprepare(ss->busclk);
808 +static int __exit sunxi_ss_remove(struct platform_device *pdev)
810 + if (!pdev->dev.of_node)
813 + crypto_unregister_ahash(&sunxi_md5_alg);
814 + crypto_unregister_ahash(&sunxi_sha1_alg);
815 + crypto_unregister_algs(sunxi_cipher_algs,
816 + ARRAY_SIZE(sunxi_cipher_algs));
818 + if (ss->buf_in != NULL)
820 + if (ss->buf_out != NULL)
821 + kfree(ss->buf_out);
823 + writel(0, ss->base + SS_CTL);
824 + clk_disable_unprepare(ss->busclk);
825 + clk_disable_unprepare(ss->ssclk);
829 +static const struct of_device_id a20ss_crypto_of_match_table[] = {
830 + { .compatible = "allwinner,sun7i-a20-crypto" },
833 +MODULE_DEVICE_TABLE(of, a20ss_crypto_of_match_table);
835 +static struct platform_driver sunxi_ss_driver = {
836 + .probe = sunxi_ss_probe,
837 + .remove = __exit_p(sunxi_ss_remove),
839 + .owner = THIS_MODULE,
840 + .name = "sunxi-ss",
841 + .of_match_table = a20ss_crypto_of_match_table,
845 +module_platform_driver(sunxi_ss_driver);
847 +MODULE_DESCRIPTION("Allwinner Security System cryptographic accelerator");
848 +MODULE_LICENSE("GPL");
849 +MODULE_AUTHOR("Corentin LABBE <clabbe.montjoie@gmail.com>");
851 +++ b/drivers/crypto/sunxi-ss/sunxi-ss-hash.c
854 + * sunxi-ss-hash.c - hardware cryptographic accelerator for Allwinner A20 SoC
856 + * Copyright (C) 2013-2014 Corentin LABBE <clabbe.montjoie@gmail.com>
858 + * This file add support for MD5 and SHA1.
860 + * You could find the datasheet in Documentation/arm/sunxi/README
862 + * This program is free software; you can redistribute it and/or modify
863 + * it under the terms of the GNU General Public License as published by
864 + * the Free Software Foundation; either version 2 of the License, or
865 + * (at your option) any later version.
867 +#include "sunxi-ss.h"
869 +/* This is a totaly arbitrary value */
870 +#define SS_TIMEOUT 100
872 +extern struct sunxi_ss_ctx *ss;
874 +int sunxi_hash_crainit(struct crypto_tfm *tfm)
876 + crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm),
877 + sizeof(struct sunxi_req_ctx));
881 +/* sunxi_hash_init: initialize request context */
882 +int sunxi_hash_init(struct ahash_request *areq)
884 + const char *hash_type;
885 + struct sunxi_req_ctx *op = ahash_request_ctx(areq);
887 + memset(op, 0, sizeof(struct sunxi_req_ctx));
889 + hash_type = crypto_tfm_alg_name(areq->base.tfm);
891 + if (strcmp(hash_type, "sha1") == 0)
892 + op->mode = SS_OP_SHA1;
893 + if (strcmp(hash_type, "md5") == 0)
894 + op->mode = SS_OP_MD5;
903 +inline void ss_writer(const u32 v)
907 + writel(v, ss->base + SS_RXFIFO);
909 + while (rx_cnt == 0) {
910 + spaces = readl_relaxed(ss->base + SS_FCSR);
911 + rx_cnt = SS_RXFIFO_SPACES(spaces);
915 +inline void ss_writer_relaxed(const u32 v)
919 + writel_relaxed(v, ss->base + SS_RXFIFO);
921 + while (rx_cnt == 0) {
922 + spaces = readl_relaxed(ss->base + SS_FCSR);
923 + rx_cnt = SS_RXFIFO_SPACES(spaces);
928 + * sunxi_hash_update: update hash engine
930 + * Could be used for both SHA1 and MD5
931 + * Write data by step of 32bits and put then in the SS.
933 + * Since we cannot leave partial data and hash state in the engine,
934 + * we need to get the hash state at the end of this function.
935 + * After some work, I have found that we can get the hash state every 64o
937 + * So the first work is to get the number of bytes to write to SS modulo 64
938 + * The extra bytes will go to two different destination:
939 + * op->wait for full 32bits word
940 + * op->wb (waiting bytes) for partial 32 bits word
941 + * So we can have up to (64/4)-1 op->wait words and 0/1/2/3 bytes in wb
943 + * So at the begin of update()
944 + * if op->nwait * 4 + areq->nbytes < 64
945 + * => all data writed to wait buffers and end=0
946 + * if not write all nwait to the device and position end to complete to 64o
949 + * update1 60o => nwait=15
950 + * update2 60o => need one more word to have 64o
952 + * so write all data in op->wait and one word of SGs
953 + * write remaining data in op->wait
954 + * final state op->nwait=14
956 +int sunxi_hash_update(struct ahash_request *areq)
959 + unsigned int i = 0;
961 + * i is the total bytes read from SGs, to be compared to areq->nbytes
962 + * i is important because we cannot rely on SG length since the sum of
963 + * SG->length could be greater than areq->nbytes
966 + struct sunxi_req_ctx *op = ahash_request_ctx(areq);
967 + struct scatterlist *in_sg;
968 + unsigned int in_i = 0; /* advancement in the current SG */
971 + * end is the position when we need to stop writing to the device,
972 + * to be compared to i
977 + dev_dbg(ss->dev, "%s %s bc=%llu len=%u mode=%x bw=%u ww=%u",
978 + __func__, crypto_tfm_alg_name(areq->base.tfm),
979 + op->byte_count, areq->nbytes, op->mode,
980 + op->nbw, op->nwait);
982 + if (areq->nbytes == 0)
985 + end = ((areq->nbytes + op->nwait * 4 + op->nbw) / 64) * 64
986 + - op->nbw - op->nwait * 4;
988 + if (end > areq->nbytes || areq->nbytes - end > 63) {
989 + dev_err(ss->dev, "ERROR: Bound error %llu %u\n",
990 + end, areq->nbytes);
994 + if (op->nwait > 0 && end > 0) {
995 + /* a precedent update was done */
996 + for (i = 0; i < op->nwait; i++) {
997 + ss_writer(op->wait[i]);
998 + op->byte_count += 4;
1003 + mutex_lock(&ss->lock);
1005 + * if some data have been processed before,
1006 + * we need to restore the partial hash state
1008 + if (op->byte_count > 0) {
1009 + ivmode = SS_IV_ARBITRARY;
1010 + for (i = 0; i < 5; i++)
1011 + writel(op->hash[i], ss->base + SS_IV0 + i * 4);
1013 + /* Enable the device */
1014 + writel(op->mode | SS_ENABLED | ivmode, ss->base + SS_CTL);
1019 + in_sg = areq->src;
1020 + src_addr = kmap(sg_page(in_sg)) + in_sg->offset;
1021 + if (src_addr == NULL) {
1022 + mutex_unlock(&ss->lock);
1023 + dev_err(ss->dev, "ERROR: Cannot kmap source buffer\n");
1028 + * step 1, if some bytes remains from last SG,
1029 + * try to complete them to 4 and send that word
1031 + if (op->nbw > 0) {
1032 + while (op->nbw < 4 && i < areq->nbytes &&
1033 + in_i < in_sg->length) {
1034 + op->wb |= (*(u8 *)(src_addr + in_i))
1036 + dev_dbg(ss->dev, "%s Complete w=%d wb=%x\n",
1037 + __func__, op->nbw, op->wb);
1042 + if (op->nbw == 4) {
1044 + ss_writer(op->wb);
1045 + op->byte_count += 4;
1047 + op->wait[op->nwait] = op->wb;
1049 + dev_dbg(ss->dev, "%s Keep %u bytes after %llu\n",
1050 + __func__, op->nwait, end);
1056 + /* step 2, main loop, read data 4bytes at a time */
1057 + while (i < areq->nbytes && in_i < in_sg->length) {
1058 + /* how many bytes we can read, (we need 4) */
1059 + in_r = min(in_sg->length - in_i, areq->nbytes - i);
1061 + /* Not enough data to write to the device */
1063 + while (in_r > 0) {
1064 + op->wb |= (*(u8 *)(src_addr + in_i))
1066 + dev_dbg(ss->dev, "%s ending bw=%d wb=%x\n",
1067 + __func__, op->nbw, op->wb);
1075 + v = *(u32 *)(src_addr + in_i);
1077 + /* last write must be done without relaxed */
1081 + ss_writer_relaxed(v);
1083 + op->byte_count += 4;
1086 + op->wait[op->nwait] = v;
1090 + dev_dbg(ss->dev, "%s Keep word ww=%u after %llu\n",
1091 + __func__, op->nwait, end);
1092 + if (op->nwait > 15) {
1093 + dev_err(ss->dev, "FATAL: Cannot enqueue more, bug?\n");
1094 + writel(0, ss->base + SS_CTL);
1095 + mutex_unlock(&ss->lock);
1101 + /* Nothing more to read in this SG */
1102 + if (in_i == in_sg->length) {
1103 + kunmap(sg_page(in_sg));
1105 + in_sg = sg_next(in_sg);
1106 + } while (in_sg != NULL && in_sg->length == 0);
1108 + if (in_sg != NULL) {
1109 + src_addr = kmap(sg_page(in_sg)) + in_sg->offset;
1110 + if (src_addr == NULL) {
1111 + mutex_unlock(&ss->lock);
1112 + dev_err(ss->dev, "ERROR: Cannot kmap source buffer\n");
1117 + } while (in_sg != NULL && i < areq->nbytes);
1119 + /* ask the device to finish the hashing */
1120 + writel(op->mode | SS_ENABLED | SS_DATA_END, ss->base + SS_CTL);
1123 + v = readl(ss->base + SS_CTL);
1125 + } while (i < SS_TIMEOUT && (v & SS_DATA_END) > 0);
1126 + if (i >= SS_TIMEOUT) {
1127 + dev_err(ss->dev, "ERROR: %s hash end timeout after %d loop, CTL=%x\n",
1129 + writel(0, ss->base + SS_CTL);
1130 + mutex_unlock(&ss->lock);
1134 + /* get the partial hash */
1135 + if (op->mode == SS_OP_SHA1) {
1136 + for (i = 0; i < 5; i++)
1137 + op->hash[i] = readl(ss->base + SS_MD0 + i * 4);
1139 + for (i = 0; i < 4; i++)
1140 + op->hash[i] = readl(ss->base + SS_MD0 + i * 4);
1143 + writel(0, ss->base + SS_CTL);
1144 + mutex_unlock(&ss->lock);
1149 + * sunxi_hash_final: finalize hashing operation
1151 + * If we have some remaining bytes, we write them.
1152 + * Then ask the SS for finalizing the hashing operation
1154 +int sunxi_hash_final(struct ahash_request *areq)
1156 + u32 v, ivmode = 0;
1159 + unsigned int index, padlen;
1161 + struct sunxi_req_ctx *op = ahash_request_ctx(areq);
1163 + dev_dbg(ss->dev, "%s byte=%llu len=%u mode=%x bw=%u %x h=%x ww=%u",
1164 + __func__, op->byte_count, areq->nbytes, op->mode,
1165 + op->nbw, op->wb, op->hash[0], op->nwait);
1167 + mutex_lock(&ss->lock);
1171 + * if we have already writed something,
1172 + * restore the partial hash state
1174 + if (op->byte_count > 0) {
1175 + ivmode = SS_IV_ARBITRARY;
1176 + for (i = 0; i < 5; i++)
1177 + writel(op->hash[i], ss->base + SS_IV0 + i * 4);
1179 + writel(op->mode | SS_ENABLED | ivmode, ss->base + SS_CTL);
1181 + /* write the remaining words of the wait buffer */
1182 + if (op->nwait > 0) {
1183 + for (i = 0; i < op->nwait; i++) {
1186 + op->byte_count += 4;
1187 + dev_dbg(ss->dev, "%s write %llu i=%u %x\n",
1188 + __func__, op->byte_count, i, v);
1193 + /* write the remaining bytes of the nbw buffer */
1194 + if (op->nbw > 0) {
1195 + op->wb |= ((1 << 7) << (op->nbw * 8));
1196 + ss_writer(op->wb);
1198 + ss_writer((1 << 7));
1202 + * number of space to pad to obtain 64o minus 8(size) minus 4 (final 1)
1203 + * I take the operations from other md5/sha1 implementations
1206 + /* we have already send 4 more byte of which nbw data */
1207 + if (op->mode == SS_OP_MD5) {
1208 + index = (op->byte_count + 4) & 0x3f;
1209 + op->byte_count += op->nbw;
1211 + zeros = (120 - index) / 4;
1213 + zeros = (56 - index) / 4;
1215 + op->byte_count += op->nbw;
1216 + index = op->byte_count & 0x3f;
1217 + padlen = (index < 56) ? (56 - index) : ((64+56) - index);
1218 + zeros = (padlen - 1) / 4;
1220 + for (i = 0; i < zeros; i++)
1223 + /* write the length of data */
1224 + if (op->mode == SS_OP_SHA1) {
1225 + bits = cpu_to_be64(op->byte_count << 3);
1226 + ss_writer(bits & 0xffffffff);
1227 + ss_writer((bits >> 32) & 0xffffffff);
1229 + ss_writer((op->byte_count << 3) & 0xffffffff);
1230 + ss_writer((op->byte_count >> 29) & 0xffffffff);
1233 + /* Tell the SS to stop the hashing */
1234 + writel(op->mode | SS_ENABLED | SS_DATA_END, ss->base + SS_CTL);
1237 + * Wait for SS to finish the hash.
1238 + * The timeout could happend only in case of bad overcloking
1243 + v = readl(ss->base + SS_CTL);
1245 + } while (i < SS_TIMEOUT && (v & SS_DATA_END) > 0);
1246 + if (i >= SS_TIMEOUT) {
1247 + dev_err(ss->dev, "ERROR: hash end timeout %d>%d ctl=%x len=%u\n",
1248 + i, SS_TIMEOUT, v, areq->nbytes);
1249 + writel(0, ss->base + SS_CTL);
1250 + mutex_unlock(&ss->lock);
1254 + /* Get the hash from the device */
1255 + if (op->mode == SS_OP_SHA1) {
1256 + for (i = 0; i < 5; i++) {
1257 + v = cpu_to_be32(readl(ss->base + SS_MD0 + i * 4));
1258 + memcpy(areq->result + i * 4, &v, 4);
1261 + for (i = 0; i < 4; i++) {
1262 + v = readl(ss->base + SS_MD0 + i * 4);
1263 + memcpy(areq->result + i * 4, &v, 4);
1266 + writel(0, ss->base + SS_CTL);
1267 + mutex_unlock(&ss->lock);
1271 +/* sunxi_hash_finup: finalize hashing operation after an update */
1272 +int sunxi_hash_finup(struct ahash_request *areq)
1276 + err = sunxi_hash_update(areq);
1280 + return sunxi_hash_final(areq);
1283 +/* combo of init/update/final functions */
1284 +int sunxi_hash_digest(struct ahash_request *areq)
1288 + err = sunxi_hash_init(areq);
1292 + err = sunxi_hash_update(areq);
1296 + return sunxi_hash_final(areq);
1299 +++ b/drivers/crypto/sunxi-ss/sunxi-ss.h
1302 + * sunxi-ss.c - hardware cryptographic accelerator for Allwinner A20 SoC
1304 + * Copyright (C) 2013-2014 Corentin LABBE <clabbe.montjoie@gmail.com>
1306 + * Support AES cipher with 128,192,256 bits keysize.
1307 + * Support MD5 and SHA1 hash algorithms.
1308 + * Support DES and 3DES
1310 + * You could find the datasheet in Documentation/arm/sunxi/README
1312 + * Licensed under the GPL-2.
1315 +#include <linux/clk.h>
1316 +#include <linux/crypto.h>
1317 +#include <linux/io.h>
1318 +#include <linux/module.h>
1319 +#include <linux/of.h>
1320 +#include <linux/platform_device.h>
1321 +#include <crypto/scatterwalk.h>
1322 +#include <linux/scatterlist.h>
1323 +#include <linux/interrupt.h>
1324 +#include <linux/delay.h>
1325 +#include <crypto/md5.h>
1326 +#include <crypto/sha.h>
1327 +#include <crypto/hash.h>
1328 +#include <crypto/internal/hash.h>
1329 +#include <crypto/aes.h>
1330 +#include <crypto/des.h>
1331 +#include <crypto/internal/rng.h>
1333 +#define SS_CTL 0x00
1334 +#define SS_KEY0 0x04
1335 +#define SS_KEY1 0x08
1336 +#define SS_KEY2 0x0C
1337 +#define SS_KEY3 0x10
1338 +#define SS_KEY4 0x14
1339 +#define SS_KEY5 0x18
1340 +#define SS_KEY6 0x1C
1341 +#define SS_KEY7 0x20
1343 +#define SS_IV0 0x24
1344 +#define SS_IV1 0x28
1345 +#define SS_IV2 0x2C
1346 +#define SS_IV3 0x30
1348 +#define SS_CNT0 0x34
1349 +#define SS_CNT1 0x38
1350 +#define SS_CNT2 0x3C
1351 +#define SS_CNT3 0x40
1353 +#define SS_FCSR 0x44
1354 +#define SS_ICSR 0x48
1356 +#define SS_MD0 0x4C
1357 +#define SS_MD1 0x50
1358 +#define SS_MD2 0x54
1359 +#define SS_MD3 0x58
1360 +#define SS_MD4 0x5C
1362 +#define SS_RXFIFO 0x200
1363 +#define SS_TXFIFO 0x204
1365 +/* SS_CTL configuration values */
1367 +/* PRNG generator mode - bit 15 */
1368 +#define SS_PRNG_ONESHOT (0 << 15)
1369 +#define SS_PRNG_CONTINUE (1 << 15)
1371 +/* IV mode for hash */
1372 +#define SS_IV_ARBITRARY (1 << 14)
1374 +/* SS operation mode - bits 12-13 */
1375 +#define SS_ECB (0 << 12)
1376 +#define SS_CBC (1 << 12)
1377 +#define SS_CNT (2 << 12)
1379 +/* Counter width for CNT mode - bits 10-11 */
1380 +#define SS_CNT_16BITS (0 << 10)
1381 +#define SS_CNT_32BITS (1 << 10)
1382 +#define SS_CNT_64BITS (2 << 10)
1384 +/* Key size for AES - bits 8-9 */
1385 +#define SS_AES_128BITS (0 << 8)
1386 +#define SS_AES_192BITS (1 << 8)
1387 +#define SS_AES_256BITS (2 << 8)
1389 +/* Operation direction - bit 7 */
1390 +#define SS_ENCRYPTION (0 << 7)
1391 +#define SS_DECRYPTION (1 << 7)
1393 +/* SS Method - bits 4-6 */
1394 +#define SS_OP_AES (0 << 4)
1395 +#define SS_OP_DES (1 << 4)
1396 +#define SS_OP_3DES (2 << 4)
1397 +#define SS_OP_SHA1 (3 << 4)
1398 +#define SS_OP_MD5 (4 << 4)
1399 +#define SS_OP_PRNG (5 << 4)
1401 +/* Data end bit - bit 2 */
1402 +#define SS_DATA_END (1 << 2)
1404 +/* PRNG start bit - bit 1 */
1405 +#define SS_PRNG_START (1 << 1)
1407 +/* SS Enable bit - bit 0 */
1408 +#define SS_DISABLED (0 << 0)
1409 +#define SS_ENABLED (1 << 0)
1411 +/* SS_FCSR configuration values */
1412 +/* RX FIFO status - bit 30 */
1413 +#define SS_RXFIFO_FREE (1 << 30)
1415 +/* RX FIFO empty spaces - bits 24-29 */
1416 +#define SS_RXFIFO_SPACES(val) (((val) >> 24) & 0x3f)
1418 +/* TX FIFO status - bit 22 */
1419 +#define SS_TXFIFO_AVAILABLE (1 << 22)
1421 +/* TX FIFO available spaces - bits 16-21 */
1422 +#define SS_TXFIFO_SPACES(val) (((val) >> 16) & 0x3f)
1424 +#define SS_RXFIFO_EMP_INT_PENDING (1 << 10)
1425 +#define SS_TXFIFO_AVA_INT_PENDING (1 << 8)
1426 +#define SS_RXFIFO_EMP_INT_ENABLE (1 << 2)
1427 +#define SS_TXFIFO_AVA_INT_ENABLE (1 << 0)
1429 +/* SS_ICSR configuration values */
1430 +#define SS_ICS_DRQ_ENABLE (1 << 4)
1432 +struct sunxi_ss_ctx {
1433 + void __iomem *base;
1435 + struct clk *busclk;
1436 + struct clk *ssclk;
1437 + struct device *dev;
1438 + struct resource *res;
1439 + void *buf_in; /* pointer to data to be uploaded to the device */
1440 + size_t buf_in_size; /* size of buf_in */
1442 + size_t buf_out_size;
1443 + struct mutex lock; /* control the use of the device */
1444 + struct mutex bufout_lock; /* control the use of buf_out*/
1445 + struct mutex bufin_lock; /* control the sue of buf_in*/
1448 +struct sunxi_tfm_ctx {
1449 + u32 key[AES_MAX_KEY_SIZE / 4];/* divided by sizeof(u32) */
1454 +struct sunxi_req_ctx {
1456 + u64 byte_count; /* number of bytes "uploaded" to the device */
1457 + u32 wb; /* a partial word waiting to be completed and
1458 + uploaded to the device */
1459 + /* number of bytes to be uploaded in the wb word */
1463 + unsigned int nwait;
1466 +#define SS_SEED_LEN (192/8)
1467 +#define SS_DATA_LEN (160/8)
1469 +struct prng_context {
1470 + u32 seed[SS_SEED_LEN/4];
1471 + unsigned int slen;
1474 +int sunxi_hash_crainit(struct crypto_tfm *tfm);
1475 +int sunxi_hash_init(struct ahash_request *areq);
1476 +int sunxi_hash_update(struct ahash_request *areq);
1477 +int sunxi_hash_final(struct ahash_request *areq);
1478 +int sunxi_hash_finup(struct ahash_request *areq);
1479 +int sunxi_hash_digest(struct ahash_request *areq);
1480 +int sunxi_hash_export(struct ahash_request *areq, void *out);
1481 +int sunxi_hash_import(struct ahash_request *areq, const void *in);
1483 +int sunxi_ss_aes_poll(struct ablkcipher_request *areq, u32 mode);
1484 +int sunxi_ss_des_poll(struct ablkcipher_request *areq, u32 mode);
1485 +int sunxi_ss_cipher_init(struct crypto_tfm *tfm);
1486 +int sunxi_ss_cipher_encrypt(struct ablkcipher_request *areq);
1487 +int sunxi_ss_cipher_decrypt(struct ablkcipher_request *areq);
1488 +int sunxi_ss_aes_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
1489 + unsigned int keylen);
1490 +int sunxi_ss_des_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
1491 + unsigned int keylen);
1492 +int sunxi_ss_des3_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
1493 + unsigned int keylen);