[PATCH] crypto: rockchip: Don't dequeue the request when device is busy

2017-08-15 Thread zain wang
The device can only process one request at a time. So if multiple
requests came at the same time, we can enqueue them first, and
dequeue them one by one when the device is idle.

Signed-off-by: zain wang <w...@rock-chips.com>
---
 drivers/crypto/rockchip/rk3288_crypto.c|  46 ++-
 drivers/crypto/rockchip/rk3288_crypto.h|  11 +-
 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c | 118 --
 drivers/crypto/rockchip/rk3288_crypto_ahash.c  | 133 ++---
 4 files changed, 160 insertions(+), 148 deletions(-)

diff --git a/drivers/crypto/rockchip/rk3288_crypto.c 
b/drivers/crypto/rockchip/rk3288_crypto.c
index 57c3783..c9d622a 100644
--- a/drivers/crypto/rockchip/rk3288_crypto.c
+++ b/drivers/crypto/rockchip/rk3288_crypto.c
@@ -184,15 +184,53 @@ static irqreturn_t rk_crypto_irq_handle(int irq, void 
*dev_id)
return IRQ_HANDLED;
 }
 
+static int rk_crypto_enqueue(struct rk_crypto_info *dev,
+ struct crypto_async_request *async_req)
+{
+   unsigned long flags;
+   int ret;
+
+   spin_lock_irqsave(>lock, flags);
+   ret = crypto_enqueue_request(>queue, async_req);
+   if (dev->busy) {
+   spin_unlock_irqrestore(>lock, flags);
+   return ret;
+   }
+   dev->busy = true;
+   spin_unlock_irqrestore(>lock, flags);
+   tasklet_schedule(>queue_task);
+
+   return ret;
+}
+
 static void rk_crypto_queue_task_cb(unsigned long data)
 {
struct rk_crypto_info *dev = (struct rk_crypto_info *)data;
+   struct crypto_async_request *async_req, *backlog;
+   unsigned long flags;
int err = 0;
 
dev->err = 0;
+   spin_lock_irqsave(>lock, flags);
+   backlog   = crypto_get_backlog(>queue);
+   async_req = crypto_dequeue_request(>queue);
+
+   if (!async_req) {
+   dev->busy = false;
+   spin_unlock_irqrestore(>lock, flags);
+   return;
+   }
+   spin_unlock_irqrestore(>lock, flags);
+
+   if (backlog) {
+   backlog->complete(backlog, -EINPROGRESS);
+   backlog = NULL;
+   }
+
+   dev->async_req = async_req;
err = dev->start(dev);
if (err)
-   dev->complete(dev, err);
+   dev->complete(dev->async_req, err);
 }
 
 static void rk_crypto_done_task_cb(unsigned long data)
@@ -200,13 +238,13 @@ static void rk_crypto_done_task_cb(unsigned long data)
struct rk_crypto_info *dev = (struct rk_crypto_info *)data;
 
if (dev->err) {
-   dev->complete(dev, dev->err);
+   dev->complete(dev->async_req, dev->err);
return;
}
 
dev->err = dev->update(dev);
if (dev->err)
-   dev->complete(dev, dev->err);
+   dev->complete(dev->async_req, dev->err);
 }
 
 static struct rk_crypto_tmp *rk_cipher_algs[] = {
@@ -365,6 +403,8 @@ static int rk_crypto_probe(struct platform_device *pdev)
crypto_info->disable_clk = rk_crypto_disable_clk;
crypto_info->load_data = rk_load_data;
crypto_info->unload_data = rk_unload_data;
+   crypto_info->enqueue = rk_crypto_enqueue;
+   crypto_info->busy = false;
 
err = rk_crypto_register(crypto_info);
if (err) {
diff --git a/drivers/crypto/rockchip/rk3288_crypto.h 
b/drivers/crypto/rockchip/rk3288_crypto.h
index 65ad1c2..ab6a1b4 100644
--- a/drivers/crypto/rockchip/rk3288_crypto.h
+++ b/drivers/crypto/rockchip/rk3288_crypto.h
@@ -192,8 +192,7 @@ struct rk_crypto_info {
struct crypto_queue queue;
struct tasklet_struct   queue_task;
struct tasklet_struct   done_task;
-   struct ablkcipher_request   *ablk_req;
-   struct ahash_request*ahash_req;
+   struct crypto_async_request *async_req;
int err;
/* device lock */
spinlock_t  lock;
@@ -210,18 +209,20 @@ struct rk_crypto_info {
size_t  nents;
unsigned inttotal;
unsigned intcount;
-   u32 mode;
dma_addr_t  addr_in;
dma_addr_t  addr_out;
+   boolbusy;
int (*start)(struct rk_crypto_info *dev);
int (*update)(struct rk_crypto_info *dev);
-   void (*complete)(struct rk_crypto_info *dev, int err);
+   void (*complete)(struct crypto_async_request *base, int err);
int (*enable_clk)(struct rk_crypto_info *dev);
void (*disable_clk)(struct rk_crypto_info *dev);
int (*load_data)(struct rk_crypto_info *dev,
 struct scatterlist *sg_src,
 struct scatt

[RESEND PATCH 2/2] crypto: rockchip - return the err code when unable dequeue the crypto request

2017-07-23 Thread zain wang
Sometime we would unable to dequeue the crypto request, in this case,
we should finish crypto and return the err code.

Signed-off-by: zain wang <w...@rock-chips.com>
---
 drivers/crypto/rockchip/rk3288_crypto.c| 19 ---
 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c | 15 +++
 drivers/crypto/rockchip/rk3288_crypto_ahash.c  | 14 ++
 3 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/drivers/crypto/rockchip/rk3288_crypto.c 
b/drivers/crypto/rockchip/rk3288_crypto.c
index c2b1dd7..57c3783 100644
--- a/drivers/crypto/rockchip/rk3288_crypto.c
+++ b/drivers/crypto/rockchip/rk3288_crypto.c
@@ -187,27 +187,8 @@ static irqreturn_t rk_crypto_irq_handle(int irq, void 
*dev_id)
 static void rk_crypto_queue_task_cb(unsigned long data)
 {
struct rk_crypto_info *dev = (struct rk_crypto_info *)data;
-   struct crypto_async_request *async_req, *backlog;
-   unsigned long flags;
int err = 0;
 
-   spin_lock_irqsave(>lock, flags);
-   backlog   = crypto_get_backlog(>queue);
-   async_req = crypto_dequeue_request(>queue);
-   spin_unlock_irqrestore(>lock, flags);
-   if (!async_req) {
-   dev_err(dev->dev, "async_req is NULL !!\n");
-   return;
-   }
-   if (backlog) {
-   backlog->complete(backlog, -EINPROGRESS);
-   backlog = NULL;
-   }
-
-   if (crypto_tfm_alg_type(async_req->tfm) == CRYPTO_ALG_TYPE_ABLKCIPHER)
-   dev->ablk_req = ablkcipher_request_cast(async_req);
-   else
-   dev->ahash_req = ahash_request_cast(async_req);
dev->err = 0;
err = dev->start(dev);
if (err)
diff --git a/drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c 
b/drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c
index 8787e44..dbe78de 100644
--- a/drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c
+++ b/drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c
@@ -25,6 +25,7 @@ static int rk_handle_req(struct rk_crypto_info *dev,
 struct ablkcipher_request *req)
 {
unsigned long flags;
+   struct crypto_async_request *async_req, *backlog;
int err;
 
if (!IS_ALIGNED(req->nbytes, dev->align_size))
@@ -41,7 +42,21 @@ static int rk_handle_req(struct rk_crypto_info *dev,
 
spin_lock_irqsave(>lock, flags);
err = ablkcipher_enqueue_request(>queue, req);
+   backlog   = crypto_get_backlog(>queue);
+   async_req = crypto_dequeue_request(>queue);
spin_unlock_irqrestore(>lock, flags);
+
+   if (!async_req) {
+   dev_err(dev->dev, "async_req is NULL !!\n");
+   return err;
+   }
+   if (backlog) {
+   backlog->complete(backlog, -EINPROGRESS);
+   backlog = NULL;
+   }
+
+   dev->ablk_req = ablkcipher_request_cast(async_req);
+
tasklet_schedule(>queue_task);
return err;
 }
diff --git a/drivers/crypto/rockchip/rk3288_crypto_ahash.c 
b/drivers/crypto/rockchip/rk3288_crypto_ahash.c
index 9b55585..ebc46e0 100644
--- a/drivers/crypto/rockchip/rk3288_crypto_ahash.c
+++ b/drivers/crypto/rockchip/rk3288_crypto_ahash.c
@@ -166,6 +166,7 @@ static int rk_ahash_digest(struct ahash_request *req)
 {
struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
struct rk_ahash_ctx *tctx = crypto_tfm_ctx(req->base.tfm);
+   struct crypto_async_request *async_req, *backlog;
struct rk_crypto_info *dev = NULL;
unsigned long flags;
int ret;
@@ -202,8 +203,21 @@ static int rk_ahash_digest(struct ahash_request *req)
 
spin_lock_irqsave(>lock, flags);
ret = crypto_enqueue_request(>queue, >base);
+   backlog   = crypto_get_backlog(>queue);
+   async_req = crypto_dequeue_request(>queue);
spin_unlock_irqrestore(>lock, flags);
 
+   if (!async_req) {
+   dev_err(dev->dev, "async_req is NULL !!\n");
+   return ret;
+   }
+   if (backlog) {
+   backlog->complete(backlog, -EINPROGRESS);
+   backlog = NULL;
+   }
+
+   dev->ahash_req = ahash_request_cast(async_req);
+
tasklet_schedule(>queue_task);
 
/*
-- 
1.9.1




[RESEND PATCH 1/2] crypto: rockchip - move the crypto completion from interrupt context

2017-07-23 Thread zain wang
It's illegal to call the completion function from hardirq context,
it will cause runtime tests to fail. Let's build a new task (done_task)
for moving update operation from hardirq context.

Signed-off-by: zain wang <w...@rock-chips.com>
---
 drivers/crypto/rockchip/rk3288_crypto.c| 39 --
 drivers/crypto/rockchip/rk3288_crypto.h|  4 ++-
 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c |  2 +-
 drivers/crypto/rockchip/rk3288_crypto_ahash.c  |  2 +-
 4 files changed, 33 insertions(+), 14 deletions(-)

diff --git a/drivers/crypto/rockchip/rk3288_crypto.c 
b/drivers/crypto/rockchip/rk3288_crypto.c
index d0f80c6..c2b1dd7 100644
--- a/drivers/crypto/rockchip/rk3288_crypto.c
+++ b/drivers/crypto/rockchip/rk3288_crypto.c
@@ -169,24 +169,22 @@ static irqreturn_t rk_crypto_irq_handle(int irq, void 
*dev_id)
 {
struct rk_crypto_info *dev  = platform_get_drvdata(dev_id);
u32 interrupt_status;
-   int err = 0;
 
spin_lock(>lock);
interrupt_status = CRYPTO_READ(dev, RK_CRYPTO_INTSTS);
CRYPTO_WRITE(dev, RK_CRYPTO_INTSTS, interrupt_status);
+
if (interrupt_status & 0x0a) {
dev_warn(dev->dev, "DMA Error\n");
-   err = -EFAULT;
-   } else if (interrupt_status & 0x05) {
-   err = dev->update(dev);
+   dev->err = -EFAULT;
}
-   if (err)
-   dev->complete(dev, err);
+   tasklet_schedule(>done_task);
+
spin_unlock(>lock);
return IRQ_HANDLED;
 }
 
-static void rk_crypto_tasklet_cb(unsigned long data)
+static void rk_crypto_queue_task_cb(unsigned long data)
 {
struct rk_crypto_info *dev = (struct rk_crypto_info *)data;
struct crypto_async_request *async_req, *backlog;
@@ -210,11 +208,26 @@ static void rk_crypto_tasklet_cb(unsigned long data)
dev->ablk_req = ablkcipher_request_cast(async_req);
else
dev->ahash_req = ahash_request_cast(async_req);
+   dev->err = 0;
err = dev->start(dev);
if (err)
dev->complete(dev, err);
 }
 
+static void rk_crypto_done_task_cb(unsigned long data)
+{
+   struct rk_crypto_info *dev = (struct rk_crypto_info *)data;
+
+   if (dev->err) {
+   dev->complete(dev, dev->err);
+   return;
+   }
+
+   dev->err = dev->update(dev);
+   if (dev->err)
+   dev->complete(dev, dev->err);
+}
+
 static struct rk_crypto_tmp *rk_cipher_algs[] = {
_ecb_aes_alg,
_cbc_aes_alg,
@@ -361,8 +374,10 @@ static int rk_crypto_probe(struct platform_device *pdev)
crypto_info->dev = >dev;
platform_set_drvdata(pdev, crypto_info);
 
-   tasklet_init(_info->crypto_tasklet,
-rk_crypto_tasklet_cb, (unsigned long)crypto_info);
+   tasklet_init(_info->queue_task,
+rk_crypto_queue_task_cb, (unsigned long)crypto_info);
+   tasklet_init(_info->done_task,
+rk_crypto_done_task_cb, (unsigned long)crypto_info);
crypto_init_queue(_info->queue, 50);
 
crypto_info->enable_clk = rk_crypto_enable_clk;
@@ -380,7 +395,8 @@ static int rk_crypto_probe(struct platform_device *pdev)
return 0;
 
 err_register_alg:
-   tasklet_kill(_info->crypto_tasklet);
+   tasklet_kill(_info->queue_task);
+   tasklet_kill(_info->done_task);
 err_crypto:
return err;
 }
@@ -390,7 +406,8 @@ static int rk_crypto_remove(struct platform_device *pdev)
struct rk_crypto_info *crypto_tmp = platform_get_drvdata(pdev);
 
rk_crypto_unregister();
-   tasklet_kill(_tmp->crypto_tasklet);
+   tasklet_kill(_tmp->done_task);
+   tasklet_kill(_tmp->queue_task);
return 0;
 }
 
diff --git a/drivers/crypto/rockchip/rk3288_crypto.h 
b/drivers/crypto/rockchip/rk3288_crypto.h
index d7b71fe..65ad1c2 100644
--- a/drivers/crypto/rockchip/rk3288_crypto.h
+++ b/drivers/crypto/rockchip/rk3288_crypto.h
@@ -190,9 +190,11 @@ struct rk_crypto_info {
void __iomem*reg;
int irq;
struct crypto_queue queue;
-   struct tasklet_struct   crypto_tasklet;
+   struct tasklet_struct   queue_task;
+   struct tasklet_struct   done_task;
struct ablkcipher_request   *ablk_req;
struct ahash_request*ahash_req;
+   int err;
/* device lock */
spinlock_t  lock;
 
diff --git a/drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c 
b/drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c
index b5a3afe..8787e44 100644
--- a/drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c
+++ b/drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c
@@ -42,7 +42,7 @@ static int rk_handle_re

[RESEND PATCH 0/2] crypto/rockchip: fix some issue which causes crypto failed

2017-07-23 Thread zain wang
These patches fix some bugs on rockchip's crypto which would cause crypto 
failed.

zain wang (2):
  crypto: rockchip - move the crypto completion from interrupt context
  crypto: rockchip - return the err code when unable dequeue the crypto
request

 drivers/crypto/rockchip/rk3288_crypto.c| 58 +++---
 drivers/crypto/rockchip/rk3288_crypto.h|  4 +-
 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c | 17 ++-
 drivers/crypto/rockchip/rk3288_crypto_ahash.c  | 16 +-
 4 files changed, 62 insertions(+), 33 deletions(-)

-- 
1.9.1




Re: encrypt_done called from interrupt context on rk3288 crypto driver

2017-06-25 Thread Zain Wang


在 2017/6/23 16:37, Herbert Xu 写道:

On Thu, May 25, 2017 at 10:38:13PM +0300, Emil Karlson wrote:

Greetings

It seems to me that rk3288 crypto driver calls encrypt_done from
interrupt context which causes runtime tests to fail.

Zain, can you please take a look at this?

It is illegal to call the completion function from hardirq context.

Thanks,

Thanks for your email, I will fix it next.

Thanks,
Zain



[RFC PATCH v6] Crypto: rockchip/crypto - add hash support for crypto engine in rk3288

2016-02-15 Thread Zain Wang
From: Zain Wang <zain.w...@rock-chips.com>

Add md5 sha1 sha256 support for crypto engine in rk3288.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
---
Changes in V6:
- add software fallback.
- add import/export functions.

Changes in V5:
- fix some mistakes with applying.

Changes in V4:
- remove CRYPTO_ALG_NEED_FALLBACK.

Changes in V3:
- add switch instead of multiple if.

Changes in V2:
- add some comments to code.
- fix some issues about zero message process.

 drivers/crypto/Kconfig |   4 +
 drivers/crypto/rockchip/Makefile   |   1 +
 drivers/crypto/rockchip/rk3288_crypto.c|  28 +-
 drivers/crypto/rockchip/rk3288_crypto.h|  56 ++-
 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c |  20 +-
 drivers/crypto/rockchip/rk3288_crypto_ahash.c  | 404 +
 6 files changed, 499 insertions(+), 14 deletions(-)
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto_ahash.c

diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index 3dd69df..e662568 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -506,6 +506,10 @@ config CRYPTO_DEV_ROCKCHIP
depends on OF && ARCH_ROCKCHIP
select CRYPTO_AES
select CRYPTO_DES
+   select CRYPTO_MD5
+   select CRYPTO_SHA1
+   select CRYPTO_SHA256
+   select CRYPTO_HASH
select CRYPTO_BLKCIPHER
 
help
diff --git a/drivers/crypto/rockchip/Makefile b/drivers/crypto/rockchip/Makefile
index 7051c6c..30f9129 100644
--- a/drivers/crypto/rockchip/Makefile
+++ b/drivers/crypto/rockchip/Makefile
@@ -1,3 +1,4 @@
 obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP) += rk_crypto.o
 rk_crypto-objs := rk3288_crypto.o \
  rk3288_crypto_ablkcipher.o \
+ rk3288_crypto_ahash.o
diff --git a/drivers/crypto/rockchip/rk3288_crypto.c 
b/drivers/crypto/rockchip/rk3288_crypto.c
index da9c73d..af50825 100644
--- a/drivers/crypto/rockchip/rk3288_crypto.c
+++ b/drivers/crypto/rockchip/rk3288_crypto.c
@@ -208,6 +208,8 @@ static void rk_crypto_tasklet_cb(unsigned long data)
 
if (crypto_tfm_alg_type(async_req->tfm) == CRYPTO_ALG_TYPE_ABLKCIPHER)
dev->ablk_req = ablkcipher_request_cast(async_req);
+   else
+   dev->ahash_req = ahash_request_cast(async_req);
err = dev->start(dev);
if (err)
dev->complete(dev, err);
@@ -220,6 +222,9 @@ static struct rk_crypto_tmp *rk_cipher_algs[] = {
_cbc_des_alg,
_ecb_des3_ede_alg,
_cbc_des3_ede_alg,
+   _ahash_sha1,
+   _ahash_sha256,
+   _ahash_md5,
 };
 
 static int rk_crypto_register(struct rk_crypto_info *crypto_info)
@@ -229,15 +234,24 @@ static int rk_crypto_register(struct rk_crypto_info 
*crypto_info)
 
for (i = 0; i < ARRAY_SIZE(rk_cipher_algs); i++) {
rk_cipher_algs[i]->dev = crypto_info;
-   err = crypto_register_alg(_cipher_algs[i]->alg);
+   if (rk_cipher_algs[i]->type == ALG_TYPE_CIPHER)
+   err = crypto_register_alg(
+   _cipher_algs[i]->alg.crypto);
+   else
+   err = crypto_register_ahash(
+   _cipher_algs[i]->alg.hash);
if (err)
goto err_cipher_algs;
}
return 0;
 
 err_cipher_algs:
-   for (k = 0; k < i; k++)
-   crypto_unregister_alg(_cipher_algs[k]->alg);
+   for (k = 0; k < i; k++) {
+   if (rk_cipher_algs[i]->type == ALG_TYPE_CIPHER)
+   crypto_unregister_alg(_cipher_algs[k]->alg.crypto);
+   else
+   crypto_unregister_ahash(_cipher_algs[i]->alg.hash);
+   }
return err;
 }
 
@@ -245,8 +259,12 @@ static void rk_crypto_unregister(void)
 {
unsigned int i;
 
-   for (i = 0; i < ARRAY_SIZE(rk_cipher_algs); i++)
-   crypto_unregister_alg(_cipher_algs[i]->alg);
+   for (i = 0; i < ARRAY_SIZE(rk_cipher_algs); i++) {
+   if (rk_cipher_algs[i]->type == ALG_TYPE_CIPHER)
+   crypto_unregister_alg(_cipher_algs[i]->alg.crypto);
+   else
+   crypto_unregister_ahash(_cipher_algs[i]->alg.hash);
+   }
 }
 
 static void rk_crypto_action(void *data)
diff --git a/drivers/crypto/rockchip/rk3288_crypto.h 
b/drivers/crypto/rockchip/rk3288_crypto.h
index e499c2c..d7b71fe 100644
--- a/drivers/crypto/rockchip/rk3288_crypto.h
+++ b/drivers/crypto/rockchip/rk3288_crypto.h
@@ -6,6 +6,10 @@
 #include 
 #include 
 #include 
+#include 
+
+#include 
+#include 
 
 #define _SBF(v, f) ((v) << (f))
 
@@ -149,6 +153,28 @@
 #define RK_CRYPTO_TDES_KEY3_0  0x0130
 #define RK_CRYPTO_TDES_KEY3_1  0x0134
 
+/* HASH */
+#define RK_CRYPTO_HASH_CTRL0x01

[RFC PATCH V4] Crypto: rockchip/crypto - add hash support for crypto engine in rk3288

2015-12-14 Thread Zain Wang
Add md5 sha1 sha256 support for crypto engine in rk3288.
This patch can't support multiple updatings because of limited of IC,
as result, it can't support import and export too.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
---
Changes in V4:
- remove CRYPTO_ALG_NEED_FALLBACK.

Changes in V3:
- add switch instead of multiple if.

Changes in V2:
- add some comments to code.
- fix some issues about zero message process.

 drivers/crypto/rockchip/Makefile   |   1 +
 drivers/crypto/rockchip/rk3288_crypto.c|  33 +-
 drivers/crypto/rockchip/rk3288_crypto.h|  50 ++-
 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c |  20 +-
 drivers/crypto/rockchip/rk3288_crypto_ahash.c  | 391 +
 5 files changed, 477 insertions(+), 18 deletions(-)
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto_ahash.c

diff --git a/drivers/crypto/rockchip/Makefile b/drivers/crypto/rockchip/Makefile
index 7051c6c..30f9129 100644
--- a/drivers/crypto/rockchip/Makefile
+++ b/drivers/crypto/rockchip/Makefile
@@ -1,3 +1,4 @@
 obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP) += rk_crypto.o
 rk_crypto-objs := rk3288_crypto.o \
  rk3288_crypto_ablkcipher.o \
+ rk3288_crypto_ahash.o
diff --git a/drivers/crypto/rockchip/rk3288_crypto.c 
b/drivers/crypto/rockchip/rk3288_crypto.c
index 82f3044..67d69d2 100644
--- a/drivers/crypto/rockchip/rk3288_crypto.c
+++ b/drivers/crypto/rockchip/rk3288_crypto.c
@@ -190,7 +190,6 @@ static void rk_crypto_tasklet_cb(unsigned long data)
 {
struct rk_crypto_info *dev = (struct rk_crypto_info *)data;
struct crypto_async_request *async_req, *backlog;
-   struct rk_cipher_reqctx *ablk_reqctx;
int err = 0;
unsigned long flags;
 
@@ -207,10 +206,10 @@ static void rk_crypto_tasklet_cb(unsigned long data)
backlog = NULL;
}
 
-   if (crypto_tfm_alg_type(async_req->tfm) == CRYPTO_ALG_TYPE_ABLKCIPHER) {
+   if (crypto_tfm_alg_type(async_req->tfm) == CRYPTO_ALG_TYPE_ABLKCIPHER)
dev->ablk_req = ablkcipher_request_cast(async_req);
-   ablk_reqctx   = ablkcipher_request_ctx(dev->ablk_req);
-   }
+   else
+   dev->ahash_req = ahash_request_cast(async_req);
err = dev->start(dev);
if (err)
dev->complete(dev, err);
@@ -223,6 +222,9 @@ static struct rk_crypto_tmp *rk_cipher_algs[] = {
_cbc_des_alg,
_ecb_des3_ede_alg,
_cbc_des3_ede_alg,
+   _ahash_sha1,
+   _ahash_sha256,
+   _ahash_md5,
 };
 
 static int rk_crypto_register(struct rk_crypto_info *crypto_info)
@@ -232,15 +234,24 @@ static int rk_crypto_register(struct rk_crypto_info 
*crypto_info)
 
for (i = 0; i < ARRAY_SIZE(rk_cipher_algs); i++) {
rk_cipher_algs[i]->dev = crypto_info;
-   err = crypto_register_alg(_cipher_algs[i]->alg);
+   if (rk_cipher_algs[i]->type == ALG_TYPE_CIPHER)
+   err = crypto_register_alg(
+   _cipher_algs[i]->alg.crypto);
+   else
+   err = crypto_register_ahash(
+   _cipher_algs[i]->alg.hash);
if (err)
goto err_cipher_algs;
}
return 0;
 
 err_cipher_algs:
-   for (k = 0; k < i; k++)
-   crypto_unregister_alg(_cipher_algs[k]->alg);
+   for (k = 0; k < i; k++) {
+   if (rk_cipher_algs[i]->type == ALG_TYPE_CIPHER)
+   crypto_unregister_alg(_cipher_algs[k]->alg.crypto);
+   else
+   crypto_unregister_ahash(_cipher_algs[i]->alg.hash);
+   }
return err;
 }
 
@@ -248,8 +259,12 @@ static void rk_crypto_unregister(void)
 {
unsigned int i;
 
-   for (i = 0; i < ARRAY_SIZE(rk_cipher_algs); i++)
-   crypto_unregister_alg(_cipher_algs[i]->alg);
+   for (i = 0; i < ARRAY_SIZE(rk_cipher_algs); i++) {
+   if (rk_cipher_algs[i]->type == ALG_TYPE_CIPHER)
+   crypto_unregister_alg(_cipher_algs[i]->alg.crypto);
+   else
+   crypto_unregister_ahash(_cipher_algs[i]->alg.hash);
+   }
 }
 
 static void rk_crypto_action(void *data)
diff --git a/drivers/crypto/rockchip/rk3288_crypto.h 
b/drivers/crypto/rockchip/rk3288_crypto.h
index 604ffe7..08623b8 100644
--- a/drivers/crypto/rockchip/rk3288_crypto.h
+++ b/drivers/crypto/rockchip/rk3288_crypto.h
@@ -6,6 +6,10 @@
 #include 
 #include 
 #include 
+#include 
+
+#include 
+#include 
 
 #define _SBF(v, f) ((v) << (f))
 
@@ -149,6 +153,28 @@
 #define RK_CRYPTO_TDES_KEY3_0  0x0130
 #define RK_CRYPTO_TDES_KEY3_1  0x0134
 
+/* HASH */
+#define RK_CRYPTO_HASH_CTRL0x0180
+#define RK_CRYPTO_HASH_SWAP_DO BIT(3)
+#de

[RFC PATCH V3] Crypto: rockchip/crypto - add hash support for crypto engine in rk3288

2015-12-10 Thread Zain Wang
Add md5 sha1 sha256 support for crypto engine in rk3288.
This patch can't support multiple updatings because of limited of IC,
as result, it can't support import and export too.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
---

Changes in V3:
- add switch instead of multiple if.

Changes in V2:
- add some comments to code.
- fix some issues about zero message process.

 drivers/crypto/rockchip/Makefile   |   1 +
 drivers/crypto/rockchip/rk3288_crypto.c|  33 +-
 drivers/crypto/rockchip/rk3288_crypto.h|  50 ++-
 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c |  20 +-
 drivers/crypto/rockchip/rk3288_crypto_ahash.c  | 394 +
 5 files changed, 480 insertions(+), 18 deletions(-)
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto_ahash.c

diff --git a/drivers/crypto/rockchip/Makefile b/drivers/crypto/rockchip/Makefile
index 7051c6c..30f9129 100644
--- a/drivers/crypto/rockchip/Makefile
+++ b/drivers/crypto/rockchip/Makefile
@@ -1,3 +1,4 @@
 obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP) += rk_crypto.o
 rk_crypto-objs := rk3288_crypto.o \
  rk3288_crypto_ablkcipher.o \
+ rk3288_crypto_ahash.o
diff --git a/drivers/crypto/rockchip/rk3288_crypto.c 
b/drivers/crypto/rockchip/rk3288_crypto.c
index 82f3044..67d69d2 100644
--- a/drivers/crypto/rockchip/rk3288_crypto.c
+++ b/drivers/crypto/rockchip/rk3288_crypto.c
@@ -190,7 +190,6 @@ static void rk_crypto_tasklet_cb(unsigned long data)
 {
struct rk_crypto_info *dev = (struct rk_crypto_info *)data;
struct crypto_async_request *async_req, *backlog;
-   struct rk_cipher_reqctx *ablk_reqctx;
int err = 0;
unsigned long flags;
 
@@ -207,10 +206,10 @@ static void rk_crypto_tasklet_cb(unsigned long data)
backlog = NULL;
}
 
-   if (crypto_tfm_alg_type(async_req->tfm) == CRYPTO_ALG_TYPE_ABLKCIPHER) {
+   if (crypto_tfm_alg_type(async_req->tfm) == CRYPTO_ALG_TYPE_ABLKCIPHER)
dev->ablk_req = ablkcipher_request_cast(async_req);
-   ablk_reqctx   = ablkcipher_request_ctx(dev->ablk_req);
-   }
+   else
+   dev->ahash_req = ahash_request_cast(async_req);
err = dev->start(dev);
if (err)
dev->complete(dev, err);
@@ -223,6 +222,9 @@ static struct rk_crypto_tmp *rk_cipher_algs[] = {
_cbc_des_alg,
_ecb_des3_ede_alg,
_cbc_des3_ede_alg,
+   _ahash_sha1,
+   _ahash_sha256,
+   _ahash_md5,
 };
 
 static int rk_crypto_register(struct rk_crypto_info *crypto_info)
@@ -232,15 +234,24 @@ static int rk_crypto_register(struct rk_crypto_info 
*crypto_info)
 
for (i = 0; i < ARRAY_SIZE(rk_cipher_algs); i++) {
rk_cipher_algs[i]->dev = crypto_info;
-   err = crypto_register_alg(_cipher_algs[i]->alg);
+   if (rk_cipher_algs[i]->type == ALG_TYPE_CIPHER)
+   err = crypto_register_alg(
+   _cipher_algs[i]->alg.crypto);
+   else
+   err = crypto_register_ahash(
+   _cipher_algs[i]->alg.hash);
if (err)
goto err_cipher_algs;
}
return 0;
 
 err_cipher_algs:
-   for (k = 0; k < i; k++)
-   crypto_unregister_alg(_cipher_algs[k]->alg);
+   for (k = 0; k < i; k++) {
+   if (rk_cipher_algs[i]->type == ALG_TYPE_CIPHER)
+   crypto_unregister_alg(_cipher_algs[k]->alg.crypto);
+   else
+   crypto_unregister_ahash(_cipher_algs[i]->alg.hash);
+   }
return err;
 }
 
@@ -248,8 +259,12 @@ static void rk_crypto_unregister(void)
 {
unsigned int i;
 
-   for (i = 0; i < ARRAY_SIZE(rk_cipher_algs); i++)
-   crypto_unregister_alg(_cipher_algs[i]->alg);
+   for (i = 0; i < ARRAY_SIZE(rk_cipher_algs); i++) {
+   if (rk_cipher_algs[i]->type == ALG_TYPE_CIPHER)
+   crypto_unregister_alg(_cipher_algs[i]->alg.crypto);
+   else
+   crypto_unregister_ahash(_cipher_algs[i]->alg.hash);
+   }
 }
 
 static void rk_crypto_action(void *data)
diff --git a/drivers/crypto/rockchip/rk3288_crypto.h 
b/drivers/crypto/rockchip/rk3288_crypto.h
index 604ffe7..01d8299 100644
--- a/drivers/crypto/rockchip/rk3288_crypto.h
+++ b/drivers/crypto/rockchip/rk3288_crypto.h
@@ -6,6 +6,10 @@
 #include 
 #include 
 #include 
+#include 
+
+#include "crypto/md5.h"
+#include "crypto/sha.h"
 
 #define _SBF(v, f) ((v) << (f))
 
@@ -149,6 +153,28 @@
 #define RK_CRYPTO_TDES_KEY3_0  0x0130
 #define RK_CRYPTO_TDES_KEY3_1  0x0134
 
+/* HASH */
+#define RK_CRYPTO_HASH_CTRL0x0180
+#define RK_CRYPTO_HASH_SWAP_DO BIT(3)
+#

[RFC PATCH V2] Crypto: rockchip/crypto - add hash support for crypto engine in rk3288

2015-12-09 Thread Zain Wang
Add md5 sha1 sha256 support for crypto engine in rk3288.
This patch can't support multiple updatings because of limited of IC,
as result, it can't support import and export too.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
---

Changes in V2:
- add some comments to code.
- fix some issues about zero message process.

 drivers/crypto/rockchip/Makefile   |   1 +
 drivers/crypto/rockchip/rk3288_crypto.c|  33 +-
 drivers/crypto/rockchip/rk3288_crypto.h|  50 ++-
 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c |  20 +-
 drivers/crypto/rockchip/rk3288_crypto_ahash.c  | 383 +
 5 files changed, 469 insertions(+), 18 deletions(-)
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto_ahash.c

diff --git a/drivers/crypto/rockchip/Makefile b/drivers/crypto/rockchip/Makefile
index 7051c6c..30f9129 100644
--- a/drivers/crypto/rockchip/Makefile
+++ b/drivers/crypto/rockchip/Makefile
@@ -1,3 +1,4 @@
 obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP) += rk_crypto.o
 rk_crypto-objs := rk3288_crypto.o \
  rk3288_crypto_ablkcipher.o \
+ rk3288_crypto_ahash.o
diff --git a/drivers/crypto/rockchip/rk3288_crypto.c 
b/drivers/crypto/rockchip/rk3288_crypto.c
index 82f3044..67d69d2 100644
--- a/drivers/crypto/rockchip/rk3288_crypto.c
+++ b/drivers/crypto/rockchip/rk3288_crypto.c
@@ -190,7 +190,6 @@ static void rk_crypto_tasklet_cb(unsigned long data)
 {
struct rk_crypto_info *dev = (struct rk_crypto_info *)data;
struct crypto_async_request *async_req, *backlog;
-   struct rk_cipher_reqctx *ablk_reqctx;
int err = 0;
unsigned long flags;
 
@@ -207,10 +206,10 @@ static void rk_crypto_tasklet_cb(unsigned long data)
backlog = NULL;
}
 
-   if (crypto_tfm_alg_type(async_req->tfm) == CRYPTO_ALG_TYPE_ABLKCIPHER) {
+   if (crypto_tfm_alg_type(async_req->tfm) == CRYPTO_ALG_TYPE_ABLKCIPHER)
dev->ablk_req = ablkcipher_request_cast(async_req);
-   ablk_reqctx   = ablkcipher_request_ctx(dev->ablk_req);
-   }
+   else
+   dev->ahash_req = ahash_request_cast(async_req);
err = dev->start(dev);
if (err)
dev->complete(dev, err);
@@ -223,6 +222,9 @@ static struct rk_crypto_tmp *rk_cipher_algs[] = {
_cbc_des_alg,
_ecb_des3_ede_alg,
_cbc_des3_ede_alg,
+   _ahash_sha1,
+   _ahash_sha256,
+   _ahash_md5,
 };
 
 static int rk_crypto_register(struct rk_crypto_info *crypto_info)
@@ -232,15 +234,24 @@ static int rk_crypto_register(struct rk_crypto_info 
*crypto_info)
 
for (i = 0; i < ARRAY_SIZE(rk_cipher_algs); i++) {
rk_cipher_algs[i]->dev = crypto_info;
-   err = crypto_register_alg(_cipher_algs[i]->alg);
+   if (rk_cipher_algs[i]->type == ALG_TYPE_CIPHER)
+   err = crypto_register_alg(
+   _cipher_algs[i]->alg.crypto);
+   else
+   err = crypto_register_ahash(
+   _cipher_algs[i]->alg.hash);
if (err)
goto err_cipher_algs;
}
return 0;
 
 err_cipher_algs:
-   for (k = 0; k < i; k++)
-   crypto_unregister_alg(_cipher_algs[k]->alg);
+   for (k = 0; k < i; k++) {
+   if (rk_cipher_algs[i]->type == ALG_TYPE_CIPHER)
+   crypto_unregister_alg(_cipher_algs[k]->alg.crypto);
+   else
+   crypto_unregister_ahash(_cipher_algs[i]->alg.hash);
+   }
return err;
 }
 
@@ -248,8 +259,12 @@ static void rk_crypto_unregister(void)
 {
unsigned int i;
 
-   for (i = 0; i < ARRAY_SIZE(rk_cipher_algs); i++)
-   crypto_unregister_alg(_cipher_algs[i]->alg);
+   for (i = 0; i < ARRAY_SIZE(rk_cipher_algs); i++) {
+   if (rk_cipher_algs[i]->type == ALG_TYPE_CIPHER)
+   crypto_unregister_alg(_cipher_algs[i]->alg.crypto);
+   else
+   crypto_unregister_ahash(_cipher_algs[i]->alg.hash);
+   }
 }
 
 static void rk_crypto_action(void *data)
diff --git a/drivers/crypto/rockchip/rk3288_crypto.h 
b/drivers/crypto/rockchip/rk3288_crypto.h
index 604ffe7..453a00f 100644
--- a/drivers/crypto/rockchip/rk3288_crypto.h
+++ b/drivers/crypto/rockchip/rk3288_crypto.h
@@ -6,6 +6,10 @@
 #include 
 #include 
 #include 
+#include 
+
+#include "crypto/md5.h"
+#include "crypto/sha.h"
 
 #define _SBF(v, f) ((v) << (f))
 
@@ -149,6 +153,28 @@
 #define RK_CRYPTO_TDES_KEY3_0  0x0130
 #define RK_CRYPTO_TDES_KEY3_1  0x0134
 
+/* HASH */
+#define RK_CRYPTO_HASH_CTRL0x0180
+#define RK_CRYPTO_HASH_SWAP_DO BIT(3)
+#define RK_CRYPTO_HASH_SWAP_DI BIT(2)
+#define 

[RFC PATCH] Crypto: rockchip/crypto - add hash support for crypto engine in rk3288

2015-12-04 Thread Zain Wang
Add md5 sha1 sha256 support for crypto engine in rk3288.
This patch can't support multiple updatings because of limited of IC,
as result, it can't support import and export too.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
---
 drivers/crypto/rockchip/Makefile   |   1 +
 drivers/crypto/rockchip/rk3288_crypto.c|  33 +-
 drivers/crypto/rockchip/rk3288_crypto.h|  50 ++-
 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c |  20 +-
 drivers/crypto/rockchip/rk3288_crypto_ahash.c  | 369 +
 5 files changed, 455 insertions(+), 18 deletions(-)
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto_ahash.c

diff --git a/drivers/crypto/rockchip/Makefile b/drivers/crypto/rockchip/Makefile
index 7051c6c..30f9129 100644
--- a/drivers/crypto/rockchip/Makefile
+++ b/drivers/crypto/rockchip/Makefile
@@ -1,3 +1,4 @@
 obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP) += rk_crypto.o
 rk_crypto-objs := rk3288_crypto.o \
  rk3288_crypto_ablkcipher.o \
+ rk3288_crypto_ahash.o
diff --git a/drivers/crypto/rockchip/rk3288_crypto.c 
b/drivers/crypto/rockchip/rk3288_crypto.c
index 82f3044..67d69d2 100644
--- a/drivers/crypto/rockchip/rk3288_crypto.c
+++ b/drivers/crypto/rockchip/rk3288_crypto.c
@@ -190,7 +190,6 @@ static void rk_crypto_tasklet_cb(unsigned long data)
 {
struct rk_crypto_info *dev = (struct rk_crypto_info *)data;
struct crypto_async_request *async_req, *backlog;
-   struct rk_cipher_reqctx *ablk_reqctx;
int err = 0;
unsigned long flags;
 
@@ -207,10 +206,10 @@ static void rk_crypto_tasklet_cb(unsigned long data)
backlog = NULL;
}
 
-   if (crypto_tfm_alg_type(async_req->tfm) == CRYPTO_ALG_TYPE_ABLKCIPHER) {
+   if (crypto_tfm_alg_type(async_req->tfm) == CRYPTO_ALG_TYPE_ABLKCIPHER)
dev->ablk_req = ablkcipher_request_cast(async_req);
-   ablk_reqctx   = ablkcipher_request_ctx(dev->ablk_req);
-   }
+   else
+   dev->ahash_req = ahash_request_cast(async_req);
err = dev->start(dev);
if (err)
dev->complete(dev, err);
@@ -223,6 +222,9 @@ static struct rk_crypto_tmp *rk_cipher_algs[] = {
_cbc_des_alg,
_ecb_des3_ede_alg,
_cbc_des3_ede_alg,
+   _ahash_sha1,
+   _ahash_sha256,
+   _ahash_md5,
 };
 
 static int rk_crypto_register(struct rk_crypto_info *crypto_info)
@@ -232,15 +234,24 @@ static int rk_crypto_register(struct rk_crypto_info 
*crypto_info)
 
for (i = 0; i < ARRAY_SIZE(rk_cipher_algs); i++) {
rk_cipher_algs[i]->dev = crypto_info;
-   err = crypto_register_alg(_cipher_algs[i]->alg);
+   if (rk_cipher_algs[i]->type == ALG_TYPE_CIPHER)
+   err = crypto_register_alg(
+   _cipher_algs[i]->alg.crypto);
+   else
+   err = crypto_register_ahash(
+   _cipher_algs[i]->alg.hash);
if (err)
goto err_cipher_algs;
}
return 0;
 
 err_cipher_algs:
-   for (k = 0; k < i; k++)
-   crypto_unregister_alg(_cipher_algs[k]->alg);
+   for (k = 0; k < i; k++) {
+   if (rk_cipher_algs[i]->type == ALG_TYPE_CIPHER)
+   crypto_unregister_alg(_cipher_algs[k]->alg.crypto);
+   else
+   crypto_unregister_ahash(_cipher_algs[i]->alg.hash);
+   }
return err;
 }
 
@@ -248,8 +259,12 @@ static void rk_crypto_unregister(void)
 {
unsigned int i;
 
-   for (i = 0; i < ARRAY_SIZE(rk_cipher_algs); i++)
-   crypto_unregister_alg(_cipher_algs[i]->alg);
+   for (i = 0; i < ARRAY_SIZE(rk_cipher_algs); i++) {
+   if (rk_cipher_algs[i]->type == ALG_TYPE_CIPHER)
+   crypto_unregister_alg(_cipher_algs[i]->alg.crypto);
+   else
+   crypto_unregister_ahash(_cipher_algs[i]->alg.hash);
+   }
 }
 
 static void rk_crypto_action(void *data)
diff --git a/drivers/crypto/rockchip/rk3288_crypto.h 
b/drivers/crypto/rockchip/rk3288_crypto.h
index 604ffe7..453a00f 100644
--- a/drivers/crypto/rockchip/rk3288_crypto.h
+++ b/drivers/crypto/rockchip/rk3288_crypto.h
@@ -6,6 +6,10 @@
 #include 
 #include 
 #include 
+#include 
+
+#include "crypto/md5.h"
+#include "crypto/sha.h"
 
 #define _SBF(v, f) ((v) << (f))
 
@@ -149,6 +153,28 @@
 #define RK_CRYPTO_TDES_KEY3_0  0x0130
 #define RK_CRYPTO_TDES_KEY3_1  0x0134
 
+/* HASH */
+#define RK_CRYPTO_HASH_CTRL0x0180
+#define RK_CRYPTO_HASH_SWAP_DO BIT(3)
+#define RK_CRYPTO_HASH_SWAP_DI BIT(2)
+#define RK_CRYPTO_HASH_SHA1_SBF(0x00, 0)
+#define RK_CRYPTO_HASH_MD5 _SBF(0x01,

[PATCH v5 2/4] clk: rockchip: set an ID for crypto clk

2015-11-24 Thread Zain Wang
Set an ID for crypto clk, so that it can be called in other part.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
Acked-by: Michael Turquette <mturque...@baylibre.com>
Tested-by: Heiko Stuebner <he...@sntech.de>
---
Changed in v5:
- None
Changed in v4:
- None
Changed in v3:
- None
Changed in v2: 
- None
Changed in v1:
- define SCLK_CRYPTO in rk3288-cru.h
- use SCLK_CRYPTO instead of SRST_CRYPTO

 drivers/clk/rockchip/clk-rk3288.c  | 2 +-
 include/dt-bindings/clock/rk3288-cru.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/rockchip/clk-rk3288.c 
b/drivers/clk/rockchip/clk-rk3288.c
index 9040878..3fceda1 100644
--- a/drivers/clk/rockchip/clk-rk3288.c
+++ b/drivers/clk/rockchip/clk-rk3288.c
@@ -295,7 +295,7 @@ static struct rockchip_clk_branch rk3288_clk_branches[] 
__initdata = {
RK3288_CLKGATE_CON(0), 4, GFLAGS),
GATE(0, "c2c_host", "aclk_cpu_src", 0,
RK3288_CLKGATE_CON(13), 8, GFLAGS),
-   COMPOSITE_NOMUX(0, "crypto", "aclk_cpu_pre", 0,
+   COMPOSITE_NOMUX(SCLK_CRYPTO, "crypto", "aclk_cpu_pre", 0,
RK3288_CLKSEL_CON(26), 6, 2, DFLAGS,
RK3288_CLKGATE_CON(5), 4, GFLAGS),
GATE(0, "aclk_bus_2pmu", "aclk_cpu_pre", CLK_IGNORE_UNUSED,
diff --git a/include/dt-bindings/clock/rk3288-cru.h 
b/include/dt-bindings/clock/rk3288-cru.h
index c719aac..30dcd60 100644
--- a/include/dt-bindings/clock/rk3288-cru.h
+++ b/include/dt-bindings/clock/rk3288-cru.h
@@ -86,6 +86,7 @@
 #define SCLK_USBPHY480M_SRC122
 #define SCLK_PVTM_CORE 123
 #define SCLK_PVTM_GPU  124
+#define SCLK_CRYPTO125
 
 #define SCLK_MAC   151
 #define SCLK_MACREF_OUT152
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 3/4] Crypto: rockchip/crypto - add crypto driver for rk3288

2015-11-24 Thread Zain Wang
Crypto driver support:
 ecb(aes) cbc(aes) ecb(des) cbc(des) ecb(des3_ede) cbc(des3_ede)
You can alloc tags above in your case.

And other algorithms and platforms will be added later on.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
Tested-by: Heiko Stuebner <he...@sntech.de>
---
Changed in v5:
- copy IV back after operation
- use cra_block_size to tell AES from DES instaed flag AES/TDES

Changed in v4:
- modify irq function
- add devm_add_action in probe
- fix some minor mistakes

Changed in v3:
- add OF depended in Kconfig
- rename some variate
- add reset property
- remove crypto_p variate

Changed in v2:
- remove some part about hash
- add weak key detection
- changed some variate's type

Changed in v1:
- modify some variate's name
- modify some variate's type
- modify some return value
- remove or modify some print info
- use more dev_xxx in probe
- modify the prio of cipher
- add Kconfig

 drivers/crypto/Kconfig |  11 +
 drivers/crypto/Makefile|   1 +
 drivers/crypto/rockchip/Makefile   |   3 +
 drivers/crypto/rockchip/rk3288_crypto.c| 393 
 drivers/crypto/rockchip/rk3288_crypto.h| 216 +
 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c | 503 +
 6 files changed, 1127 insertions(+)
 create mode 100644 drivers/crypto/rockchip/Makefile
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto.c
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto.h
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c

diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index 5357bc1..95dccde 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -497,4 +497,15 @@ config CRYPTO_DEV_SUN4I_SS
  To compile this driver as a module, choose M here: the module
  will be called sun4i-ss.
 
+config CRYPTO_DEV_ROCKCHIP
+   tristate "Rockchip's Cryptographic Engine driver"
+   depends on OF && ARCH_ROCKCHIP
+   select CRYPTO_AES
+   select CRYPTO_DES
+   select CRYPTO_BLKCIPHER
+
+   help
+ This driver interfaces with the hardware crypto accelerator.
+ Supporting cbc/ecb chainmode, and aes/des/des3_ede cipher mode.
+
 endif # CRYPTO_HW
diff --git a/drivers/crypto/Makefile b/drivers/crypto/Makefile
index c3ced6f..713de9d 100644
--- a/drivers/crypto/Makefile
+++ b/drivers/crypto/Makefile
@@ -29,3 +29,4 @@ obj-$(CONFIG_CRYPTO_DEV_QAT) += qat/
 obj-$(CONFIG_CRYPTO_DEV_QCE) += qce/
 obj-$(CONFIG_CRYPTO_DEV_VMX) += vmx/
 obj-$(CONFIG_CRYPTO_DEV_SUN4I_SS) += sunxi-ss/
+obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP) += rockchip/
diff --git a/drivers/crypto/rockchip/Makefile b/drivers/crypto/rockchip/Makefile
new file mode 100644
index 000..7051c6c
--- /dev/null
+++ b/drivers/crypto/rockchip/Makefile
@@ -0,0 +1,3 @@
+obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP) += rk_crypto.o
+rk_crypto-objs := rk3288_crypto.o \
+ rk3288_crypto_ablkcipher.o \
diff --git a/drivers/crypto/rockchip/rk3288_crypto.c 
b/drivers/crypto/rockchip/rk3288_crypto.c
new file mode 100644
index 000..6b72f8d
--- /dev/null
+++ b/drivers/crypto/rockchip/rk3288_crypto.c
@@ -0,0 +1,393 @@
+/*
+ * Crypto acceleration support for Rockchip RK3288
+ *
+ * Copyright (c) 2015, Fuzhou Rockchip Electronics Co., Ltd
+ *
+ * Author: Zain Wang <zain.w...@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * Some ideas are from marvell-cesa.c and s5p-sss.c driver.
+ */
+
+#include "rk3288_crypto.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int rk_crypto_enable_clk(struct rk_crypto_info *dev)
+{
+   int err;
+
+   err = clk_prepare_enable(dev->sclk);
+   if (err) {
+   dev_err(dev->dev, "[%s:%d], Couldn't enable clock sclk\n",
+   __func__, __LINE__);
+   goto err_return;
+   }
+   err = clk_prepare_enable(dev->aclk);
+   if (err) {
+   dev_err(dev->dev, "[%s:%d], Couldn't enable clock aclk\n",
+   __func__, __LINE__);
+   goto err_aclk;
+   }
+   err = clk_prepare_enable(dev->hclk);
+   if (err) {
+   dev_err(dev->dev, "[%s:%d], Couldn't enable clock hclk\n",
+   __func__, __LINE__);
+   goto err_hclk;
+   }
+   err = clk_prepare_enable(dev->dmaclk);
+   if (err) {
+   dev_err(dev->dev, "[%s:%d], Couldn't enable clock dmaclk\n",
+   __func__, __LINE__);
+   goto err_dmaclk;
+   }
+   return err;
+err_dmaclk:
+   clk_disable_unprepare(dev->hclk);
+err_hclk:
+   clk_disable_unprepa

[PATCH v5 0/4] crypto: add crypto accelerator support for rk3288

2015-11-24 Thread Zain Wang
Changed in v5:
- copy IV back after operation
- use cra_block_size to tell AES from DES instaed flag AES/TDES

Changed in v4:
- modify irq function
- add devm_add_action in probe
- fix some minor mistakes

Changed in v3:
- add OF depended in Kconfig
- rename some variate
- add reset property
- remove crypto_p variate

Changed in v2:
- remove some part about hash
- add weak key detection
- changed some variate's type

Changed in v1:
- modify some variate's name
- modify some variate's type
- modify some return value
- remove or modify some print info
- use more dev_xxx in probe
- modify the prio of cipher
- add Kconfig

Zain Wang (4):
  crypto: rockchip/crypto - add DT bindings documentation
  clk: rockchip: set an ID for crypto clk
  Crypto: rockchip/crypto - add crypto driver for rk3288
  ARM: dts: rockchip: Add Crypto node for rk3288

 .../devicetree/bindings/crypto/rockchip-crypto.txt |  29 ++
 arch/arm/boot/dts/rk3288.dtsi  |  12 +
 drivers/clk/rockchip/clk-rk3288.c  |   2 +-
 drivers/crypto/Kconfig |  11 +
 drivers/crypto/Makefile|   1 +
 drivers/crypto/rockchip/Makefile   |   3 +
 drivers/crypto/rockchip/rk3288_crypto.c| 393 
 drivers/crypto/rockchip/rk3288_crypto.h| 216 +
 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c | 503 +
 include/dt-bindings/clock/rk3288-cru.h |   1 +
 10 files changed, 1170 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/crypto/rockchip-crypto.txt
 create mode 100644 drivers/crypto/rockchip/Makefile
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto.c
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto.h
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c

-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 4/4] ARM: dts: rockchip: Add Crypto node for rk3288

2015-11-24 Thread Zain Wang
Add Crypto node for rk3288 including crypto controller and dma clk.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
Tested-by: Heiko Stuebner <he...@sntech.de>
---
Changed in v5:
- None

Changed in v4:
- None

Changed in v3:
- add reset property

Changed in v2:
- None

Changed in v1:
- remove the _crypto suffix
- use "rockchip,rk3288-crypto" instead of "rockchip,rk3288"

 arch/arm/boot/dts/rk3288.dtsi | 12 
 1 file changed, 12 insertions(+)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index ad44d80..c6b1aa4 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -781,6 +781,18 @@
status = "disabled";
};
 
+   crypto: cypto-controller@ff8a {
+   compatible = "rockchip,rk3288-crypto";
+   reg = <0xff8a 0x4000>;
+   interrupts = ;
+   clocks = < ACLK_CRYPTO>, < HCLK_CRYPTO>,
+< SCLK_CRYPTO>, < ACLK_DMAC1>;
+   clock-names = "aclk", "hclk", "sclk", "apb_pclk";
+   resets = < SRST_CRYPTO>;
+   reset-names = "crypto-rst";
+   status = "okay";
+   };
+
vopb: vop@ff93 {
compatible = "rockchip,rk3288-vop";
reg = <0xff93 0x19c>;
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 1/4] crypto: rockchip/crypto - add DT bindings documentation

2015-11-24 Thread Zain Wang
Add DT bindings documentation for the rk3288 crypto drivers.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
Acked-by: Rob Herring <r...@kernel.org>
Tested-by: Heiko Stuebner <he...@sntech.de>
---
Changed in v5:
- None

Changed in v4:
- None

Changed in v3:
- add reset property

Changed in v2:
- None

Changed in v1:
- remove the _crypto suffix
- use "rockchip,rk3288-crypto" instead of "rockchip,rk3288"
- remove the description of status

 .../devicetree/bindings/crypto/rockchip-crypto.txt | 29 ++
 1 file changed, 29 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/crypto/rockchip-crypto.txt

diff --git a/Documentation/devicetree/bindings/crypto/rockchip-crypto.txt 
b/Documentation/devicetree/bindings/crypto/rockchip-crypto.txt
new file mode 100644
index 000..096df34
--- /dev/null
+++ b/Documentation/devicetree/bindings/crypto/rockchip-crypto.txt
@@ -0,0 +1,29 @@
+Rockchip Electronics And Security Accelerator
+
+Required properties:
+- compatible: Should be "rockchip,rk3288-crypto"
+- reg: Base physical address of the engine and length of memory mapped
+   region
+- interrupts: Interrupt number
+- clocks: Reference to the clocks about crypto
+- clock-names: "aclk" used to clock data
+  "hclk" used to clock data
+  "sclk" used to clock crypto accelerator
+  "apb_pclk" used to clock dma
+- resets: Must contain an entry for each entry in reset-names.
+ See ../reset/reset.txt for details.
+- reset-names: Must include the name "crypto-rst".
+
+Examples:
+
+   crypto: cypto-controller@ff8a {
+   compatible = "rockchip,rk3288-crypto";
+   reg = <0xff8a 0x4000>;
+   interrupts = ;
+   clocks = < ACLK_CRYPTO>, < HCLK_CRYPTO>,
+< SCLK_CRYPTO>, < ACLK_DMAC1>;
+   clock-names = "aclk", "hclk", "sclk", "apb_pclk";
+   resets = < SRST_CRYPTO>;
+   reset-names = "crypto-rst";
+   status = "okay";
+   };
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 3/4] Crypto: rockchip/crypto - add crypto driver for rk3288

2015-11-16 Thread Zain Wang
Crypto driver support:
 ecb(aes) cbc(aes) ecb(des) cbc(des) ecb(des3_ede) cbc(des3_ede)
You can alloc tags above in your case.

And other algorithms and platforms will be added later on.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
Tested-by: Heiko Stuebner <he...@sntech.de>
---
Changed in v4:
- modify irq function
- add devm_add_action in probe
- fix some minor mistakes

Changed in v3:
- add OF depended in Kconfig
- rename some variate
- add reset property
- remove crypto_p variate

Changed in v2:
- remove some part about hash
- add weak key detection
- changed some variate's type

Changed in v1:
- modify some variate's name
- modify some variate's type
- modify some return value
- remove or modify some print info
- use more dev_xxx in probe
- modify the prio of cipher
- add Kconfig

 drivers/crypto/Kconfig |  11 +
 drivers/crypto/Makefile|   1 +
 drivers/crypto/rockchip/Makefile   |   3 +
 drivers/crypto/rockchip/rk3288_crypto.c| 396 +
 drivers/crypto/rockchip/rk3288_crypto.h| 216 +
 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c | 489 +
 6 files changed, 1116 insertions(+)
 create mode 100644 drivers/crypto/rockchip/Makefile
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto.c
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto.h
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c

diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index 2569e04..e5451b6 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -498,4 +498,15 @@ config CRYPTO_DEV_SUN4I_SS
  To compile this driver as a module, choose M here: the module
  will be called sun4i-ss.
 
+config CRYPTO_DEV_ROCKCHIP
+   tristate "Rockchip's Cryptographic Engine driver"
+   depends on OF && ARCH_ROCKCHIP
+   select CRYPTO_AES
+   select CRYPTO_DES
+   select CRYPTO_BLKCIPHER
+
+   help
+ This driver interfaces with the hardware crypto accelerator.
+ Supporting cbc/ecb chainmode, and aes/des/des3_ede cipher mode.
+
 endif # CRYPTO_HW
diff --git a/drivers/crypto/Makefile b/drivers/crypto/Makefile
index c3ced6f..713de9d 100644
--- a/drivers/crypto/Makefile
+++ b/drivers/crypto/Makefile
@@ -29,3 +29,4 @@ obj-$(CONFIG_CRYPTO_DEV_QAT) += qat/
 obj-$(CONFIG_CRYPTO_DEV_QCE) += qce/
 obj-$(CONFIG_CRYPTO_DEV_VMX) += vmx/
 obj-$(CONFIG_CRYPTO_DEV_SUN4I_SS) += sunxi-ss/
+obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP) += rockchip/
diff --git a/drivers/crypto/rockchip/Makefile b/drivers/crypto/rockchip/Makefile
new file mode 100644
index 000..7051c6c
--- /dev/null
+++ b/drivers/crypto/rockchip/Makefile
@@ -0,0 +1,3 @@
+obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP) += rk_crypto.o
+rk_crypto-objs := rk3288_crypto.o \
+ rk3288_crypto_ablkcipher.o \
diff --git a/drivers/crypto/rockchip/rk3288_crypto.c 
b/drivers/crypto/rockchip/rk3288_crypto.c
new file mode 100644
index 000..3c79902
--- /dev/null
+++ b/drivers/crypto/rockchip/rk3288_crypto.c
@@ -0,0 +1,396 @@
+/*
+ * Crypto acceleration support for Rockchip RK3288
+ *
+ * Copyright (c) 2015, Fuzhou Rockchip Electronics Co., Ltd
+ *
+ * Author: Zain Wang <zain.w...@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * Some ideas are from marvell-cesa.c and s5p-sss.c driver.
+ */
+
+#include "rk3288_crypto.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int rk_crypto_enable_clk(struct rk_crypto_info *dev)
+{
+   int err;
+
+   err = clk_prepare_enable(dev->sclk);
+   if (err) {
+   dev_err(dev->dev, "[%s:%d], Couldn't enable clock sclk\n",
+   __func__, __LINE__);
+   goto err_return;
+   }
+   err = clk_prepare_enable(dev->aclk);
+   if (err) {
+   dev_err(dev->dev, "[%s:%d], Couldn't enable clock aclk\n",
+   __func__, __LINE__);
+   goto err_aclk;
+   }
+   err = clk_prepare_enable(dev->hclk);
+   if (err) {
+   dev_err(dev->dev, "[%s:%d], Couldn't enable clock hclk\n",
+   __func__, __LINE__);
+   goto err_hclk;
+   }
+   err = clk_prepare_enable(dev->dmaclk);
+   if (err) {
+   dev_err(dev->dev, "[%s:%d], Couldn't enable clock dmaclk\n",
+   __func__, __LINE__);
+   goto err_dmaclk;
+   }
+   return err;
+err_dmaclk:
+   clk_disable_unprepare(dev->hclk);
+err_hclk:
+   clk_disable_unprepare(dev->aclk);
+err_aclk:
+   clk_disable_unprepare(dev->sclk);
+err_return:
+   retur

[PATCH v4 1/4] crypto: rockchip/crypto - add DT bindings documentation

2015-11-16 Thread Zain Wang
Add DT bindings documentation for the rk3288 crypto drivers.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
Acked-by: Rob Herring <r...@kernel.org>
Tested-by: Heiko Stuebner <he...@sntech.de>

---
Changed in v4:
- None

Changed in v3:
- add reset property

Changed in v2:
- None

Changed in v1:
- remove the _crypto suffix
- use "rockchip,rk3288-crypto" instead of "rockchip,rk3288"
- remove the description of status

 .../devicetree/bindings/crypto/rockchip-crypto.txt | 29 ++
 1 file changed, 29 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/crypto/rockchip-crypto.txt

diff --git a/Documentation/devicetree/bindings/crypto/rockchip-crypto.txt 
b/Documentation/devicetree/bindings/crypto/rockchip-crypto.txt
new file mode 100644
index 000..096df34
--- /dev/null
+++ b/Documentation/devicetree/bindings/crypto/rockchip-crypto.txt
@@ -0,0 +1,29 @@
+Rockchip Electronics And Security Accelerator
+
+Required properties:
+- compatible: Should be "rockchip,rk3288-crypto"
+- reg: Base physical address of the engine and length of memory mapped
+   region
+- interrupts: Interrupt number
+- clocks: Reference to the clocks about crypto
+- clock-names: "aclk" used to clock data
+  "hclk" used to clock data
+  "sclk" used to clock crypto accelerator
+  "apb_pclk" used to clock dma
+- resets: Must contain an entry for each entry in reset-names.
+ See ../reset/reset.txt for details.
+- reset-names: Must include the name "crypto-rst".
+
+Examples:
+
+   crypto: cypto-controller@ff8a {
+   compatible = "rockchip,rk3288-crypto";
+   reg = <0xff8a 0x4000>;
+   interrupts = ;
+   clocks = < ACLK_CRYPTO>, < HCLK_CRYPTO>,
+< SCLK_CRYPTO>, < ACLK_DMAC1>;
+   clock-names = "aclk", "hclk", "sclk", "apb_pclk";
+   resets = < SRST_CRYPTO>;
+   reset-names = "crypto-rst";
+   status = "okay";
+   };
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 2/4] clk: rockchip: set an ID for crypto clk

2015-11-16 Thread Zain Wang
Set an ID for crypto clk, so that it can be called in other part.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
Acked-by: Michael Turquette <mturque...@baylibre.com>
Tested-by: Heiko Stuebner <he...@sntech.de>
---
Changed in v4:
- None
Changed in v3:
- None
Changed in v2: 
- None
Changed in v1:
- define SCLK_CRYPTO in rk3288-cru.h
- use SCLK_CRYPTO instead of SRST_CRYPTO

 drivers/clk/rockchip/clk-rk3288.c  | 2 +-
 include/dt-bindings/clock/rk3288-cru.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/rockchip/clk-rk3288.c 
b/drivers/clk/rockchip/clk-rk3288.c
index 9040878..3fceda1 100644
--- a/drivers/clk/rockchip/clk-rk3288.c
+++ b/drivers/clk/rockchip/clk-rk3288.c
@@ -295,7 +295,7 @@ static struct rockchip_clk_branch rk3288_clk_branches[] 
__initdata = {
RK3288_CLKGATE_CON(0), 4, GFLAGS),
GATE(0, "c2c_host", "aclk_cpu_src", 0,
RK3288_CLKGATE_CON(13), 8, GFLAGS),
-   COMPOSITE_NOMUX(0, "crypto", "aclk_cpu_pre", 0,
+   COMPOSITE_NOMUX(SCLK_CRYPTO, "crypto", "aclk_cpu_pre", 0,
RK3288_CLKSEL_CON(26), 6, 2, DFLAGS,
RK3288_CLKGATE_CON(5), 4, GFLAGS),
GATE(0, "aclk_bus_2pmu", "aclk_cpu_pre", CLK_IGNORE_UNUSED,
diff --git a/include/dt-bindings/clock/rk3288-cru.h 
b/include/dt-bindings/clock/rk3288-cru.h
index c719aac..30dcd60 100644
--- a/include/dt-bindings/clock/rk3288-cru.h
+++ b/include/dt-bindings/clock/rk3288-cru.h
@@ -86,6 +86,7 @@
 #define SCLK_USBPHY480M_SRC122
 #define SCLK_PVTM_CORE 123
 #define SCLK_PVTM_GPU  124
+#define SCLK_CRYPTO125
 
 #define SCLK_MAC   151
 #define SCLK_MACREF_OUT152
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 4/4] ARM: dts: rockchip: Add Crypto node for rk3288

2015-11-16 Thread Zain Wang
Add Crypto node for rk3288 including crypto controller and dma clk.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
Tested-by: Heiko Stuebner <he...@sntech.de>
---
Changed in v4:
- None

Changed in v3:
- add reset property

Changed in v2:
- None

Changed in v1:
- remove the _crypto suffix
- use "rockchip,rk3288-crypto" instead of "rockchip,rk3288"

 arch/arm/boot/dts/rk3288.dtsi | 12 
 1 file changed, 12 insertions(+)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index 6a79c9c..f0d1217 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -778,6 +778,18 @@
status = "disabled";
};
 
+   crypto: cypto-controller@ff8a {
+   compatible = "rockchip,rk3288-crypto";
+   reg = <0xff8a 0x4000>;
+   interrupts = ;
+   clocks = < ACLK_CRYPTO>, < HCLK_CRYPTO>,
+< SCLK_CRYPTO>, < ACLK_DMAC1>;
+   clock-names = "aclk", "hclk", "sclk", "apb_pclk";
+   resets = < SRST_CRYPTO>;
+   reset-names = "crypto-rst";
+   status = "okay";
+   };
+
vopb: vop@ff93 {
compatible = "rockchip,rk3288-vop";
reg = <0xff93 0x19c>;
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 1/4] crypto: rockchip/crypto - add DT bindings documentation

2015-11-10 Thread Zain Wang
Add DT bindings documentation for the rk3288 crypto drivers.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
---

Changed in v3:
- add reset property

Changed in v2:
- None

Changed in v1:
- remove the _crypto suffix
- use "rockchip,rk3288-crypto" instead of "rockchip,rk3288"
- remove the description of status


 .../devicetree/bindings/crypto/rockchip-crypto.txt | 29 ++
 1 file changed, 29 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/crypto/rockchip-crypto.txt

diff --git a/Documentation/devicetree/bindings/crypto/rockchip-crypto.txt 
b/Documentation/devicetree/bindings/crypto/rockchip-crypto.txt
new file mode 100644
index 000..096df34
--- /dev/null
+++ b/Documentation/devicetree/bindings/crypto/rockchip-crypto.txt
@@ -0,0 +1,29 @@
+Rockchip Electronics And Security Accelerator
+
+Required properties:
+- compatible: Should be "rockchip,rk3288-crypto"
+- reg: Base physical address of the engine and length of memory mapped
+   region
+- interrupts: Interrupt number
+- clocks: Reference to the clocks about crypto
+- clock-names: "aclk" used to clock data
+  "hclk" used to clock data
+  "sclk" used to clock crypto accelerator
+  "apb_pclk" used to clock dma
+- resets: Must contain an entry for each entry in reset-names.
+ See ../reset/reset.txt for details.
+- reset-names: Must include the name "crypto-rst".
+
+Examples:
+
+   crypto: cypto-controller@ff8a {
+   compatible = "rockchip,rk3288-crypto";
+   reg = <0xff8a 0x4000>;
+   interrupts = ;
+   clocks = < ACLK_CRYPTO>, < HCLK_CRYPTO>,
+< SCLK_CRYPTO>, < ACLK_DMAC1>;
+   clock-names = "aclk", "hclk", "sclk", "apb_pclk";
+   resets = < SRST_CRYPTO>;
+   reset-names = "crypto-rst";
+   status = "okay";
+   };
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 4/4] ARM: dts: rockchip: Add Crypto node for rk3288

2015-11-10 Thread Zain Wang
Add Crypto node for rk3288 including crypto controller and dma clk.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
---
Changed in v3:
- add reset property

Changed in v2:
- None

Changed in v1:
- remove the _crypto suffix
- use "rockchip,rk3288-crypto" instead of "rockchip,rk3288"

 arch/arm/boot/dts/rk3288.dtsi | 12 
 1 file changed, 12 insertions(+)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index 6a79c9c..f0d1217 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -778,6 +778,18 @@
status = "disabled";
};
 
+   crypto: cypto-controller@ff8a {
+   compatible = "rockchip,rk3288-crypto";
+   reg = <0xff8a 0x4000>;
+   interrupts = ;
+   clocks = < ACLK_CRYPTO>, < HCLK_CRYPTO>,
+< SCLK_CRYPTO>, < ACLK_DMAC1>;
+   clock-names = "aclk", "hclk", "sclk", "apb_pclk";
+   resets = < SRST_CRYPTO>;
+   reset-names = "crypto-rst";
+   status = "okay";
+   };
+
vopb: vop@ff93 {
compatible = "rockchip,rk3288-vop";
reg = <0xff93 0x19c>;
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 3/4] Crypto: rockchip/crypto - add crypto driver for rk3288

2015-11-10 Thread Zain Wang
Crypto driver support:
 ecb(aes) cbc(aes) ecb(des) cbc(des) ecb(des3_ede) cbc(des3_ede)
You can alloc tags above in your case.

And other algorithms and platforms will be added later on.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
---

Changed in v3:
- add OF depended in Kconfig
- remove crypto_p variate
- fix of_device_id
- add reset property

Changed in v2:
- remove some part about hash
- add weak key detection
- changed some variate's type

Changde in v1:
- modify some variate's name
- modify some variate's type
- modify some return value
- remove or modify some print info
- use more dev_xxx in probe
- modify the prio of cipher

 drivers/crypto/Kconfig |  11 +
 drivers/crypto/Makefile|   1 +
 drivers/crypto/rockchip/Makefile   |   3 +
 drivers/crypto/rockchip/rk3288_crypto.c| 392 +++
 drivers/crypto/rockchip/rk3288_crypto.h| 220 +
 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c | 527 +
 6 files changed, 1154 insertions(+)
 create mode 100644 drivers/crypto/rockchip/Makefile
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto.c
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto.h
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c

diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index 2569e04..e5451b6 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -498,4 +498,15 @@ config CRYPTO_DEV_SUN4I_SS
  To compile this driver as a module, choose M here: the module
  will be called sun4i-ss.
 
+config CRYPTO_DEV_ROCKCHIP
+   tristate "Rockchip's Cryptographic Engine driver"
+   depends on OF && ARCH_ROCKCHIP
+   select CRYPTO_AES
+   select CRYPTO_DES
+   select CRYPTO_BLKCIPHER
+
+   help
+ This driver interfaces with the hardware crypto accelerator.
+ Supporting cbc/ecb chainmode, and aes/des/des3_ede cipher mode.
+
 endif # CRYPTO_HW
diff --git a/drivers/crypto/Makefile b/drivers/crypto/Makefile
index c3ced6f..713de9d 100644
--- a/drivers/crypto/Makefile
+++ b/drivers/crypto/Makefile
@@ -29,3 +29,4 @@ obj-$(CONFIG_CRYPTO_DEV_QAT) += qat/
 obj-$(CONFIG_CRYPTO_DEV_QCE) += qce/
 obj-$(CONFIG_CRYPTO_DEV_VMX) += vmx/
 obj-$(CONFIG_CRYPTO_DEV_SUN4I_SS) += sunxi-ss/
+obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP) += rockchip/
diff --git a/drivers/crypto/rockchip/Makefile b/drivers/crypto/rockchip/Makefile
new file mode 100644
index 000..7051c6c
--- /dev/null
+++ b/drivers/crypto/rockchip/Makefile
@@ -0,0 +1,3 @@
+obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP) += rk_crypto.o
+rk_crypto-objs := rk3288_crypto.o \
+ rk3288_crypto_ablkcipher.o \
diff --git a/drivers/crypto/rockchip/rk3288_crypto.c 
b/drivers/crypto/rockchip/rk3288_crypto.c
new file mode 100644
index 000..bb36baa
--- /dev/null
+++ b/drivers/crypto/rockchip/rk3288_crypto.c
@@ -0,0 +1,392 @@
+/*
+ *Crypto acceleration support for Rockchip RK3288
+ *
+ * Copyright (c) 2015, Fuzhou Rockchip Electronics Co., Ltd
+ *
+ * Author: Zain Wang <zain.w...@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * Some ideas are from marvell-cesa.c and s5p-sss.c driver.
+ */
+
+#include "rk3288_crypto.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int rk_crypto_enable_clk(struct rk_crypto_info *dev)
+{
+   int err;
+
+   err = clk_prepare_enable(dev->sclk);
+   if (err) {
+   dev_err(dev->dev, "[%s:%d], Couldn't enable clock 'sclk'\n",
+   __func__, __LINE__);
+   goto err_return;
+   }
+   err = clk_prepare_enable(dev->aclk);
+   if (err) {
+   dev_err(dev->dev, "[%s:%d], Couldn't enable clock 'aclk'\n",
+   __func__, __LINE__);
+   goto err_aclk;
+   }
+   err = clk_prepare_enable(dev->hclk);
+   if (err) {
+   dev_err(dev->dev, "[%s:%d], Couldn't enable clock 'hclk'\n",
+   __func__, __LINE__);
+   goto err_hclk;
+   }
+
+   err = clk_prepare_enable(dev->dmaclk);
+   if (err) {
+   dev_err(dev->dev, "[%s:%d], Couldn't enable clock 'dmaclk'\n",
+   __func__, __LINE__);
+   goto err_dmaclk;
+   }
+   return err;
+err_dmaclk:
+   clk_disable_unprepare(dev->hclk);
+err_hclk:
+   clk_disable_unprepare(dev->aclk);
+err_aclk:
+   clk_disable_unprepare(dev->sclk);
+err_return:
+   return err;
+}
+
+static void rk_crypto_disable_clk(struct rk_crypto_info *dev)
+{
+   clk_disable_unprepare(dev->dmaclk);
+   clk_disable_unprep

[PATCH v3 2/4] clk: rockchip: set an ID for crypto clk

2015-11-10 Thread Zain Wang
Set an ID for crypto clk, so that it can be called in other part.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
---

Changed in v3:
- None

Changed in v2: 
- None

Changed in v1:
- define SCLK_CRYPTO in rk3288-cru.h
- use SCLK_CRYPTO instead of SRST_CRYPTO

 drivers/clk/rockchip/clk-rk3288.c  | 2 +-
 include/dt-bindings/clock/rk3288-cru.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/rockchip/clk-rk3288.c 
b/drivers/clk/rockchip/clk-rk3288.c
index 9040878..3fceda1 100644
--- a/drivers/clk/rockchip/clk-rk3288.c
+++ b/drivers/clk/rockchip/clk-rk3288.c
@@ -295,7 +295,7 @@ static struct rockchip_clk_branch rk3288_clk_branches[] 
__initdata = {
RK3288_CLKGATE_CON(0), 4, GFLAGS),
GATE(0, "c2c_host", "aclk_cpu_src", 0,
RK3288_CLKGATE_CON(13), 8, GFLAGS),
-   COMPOSITE_NOMUX(0, "crypto", "aclk_cpu_pre", 0,
+   COMPOSITE_NOMUX(SCLK_CRYPTO, "crypto", "aclk_cpu_pre", 0,
RK3288_CLKSEL_CON(26), 6, 2, DFLAGS,
RK3288_CLKGATE_CON(5), 4, GFLAGS),
GATE(0, "aclk_bus_2pmu", "aclk_cpu_pre", CLK_IGNORE_UNUSED,
diff --git a/include/dt-bindings/clock/rk3288-cru.h 
b/include/dt-bindings/clock/rk3288-cru.h
index c719aac..30dcd60 100644
--- a/include/dt-bindings/clock/rk3288-cru.h
+++ b/include/dt-bindings/clock/rk3288-cru.h
@@ -86,6 +86,7 @@
 #define SCLK_USBPHY480M_SRC122
 #define SCLK_PVTM_CORE 123
 #define SCLK_PVTM_GPU  124
+#define SCLK_CRYPTO125
 
 #define SCLK_MAC   151
 #define SCLK_MACREF_OUT152
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 0/4] Crypto: add crypto accelerator support for rk3288

2015-11-05 Thread Zain Wang
This commit support three cipher(AES/DES/DES3) and two chainmode(ecb/cbc),
and the more algorithms and new hash drivers will be added later on.

Changed in v2:
- remove some part about hash
- add weak key detection
- changed some variate's type

Changed in v1:
- modify some variate's name
- modify some variate's type
- modify some return value
- remove or modify some print info
- use more dev_xxx in probe
- modify the prio of cipher
- add Kconfig

Zain Wang (4):
  Crypto: Crypto driver support aes/des/des3 for rk3288
  clk: rockchip: set an id for crypto clk
  ARM: dts: rockchip: Add Crypto drivers for rk3288
  crypto: rockchip/crypto - add DT bindings documentation

 .../devicetree/bindings/crypto/rockchip-crypto.txt |  29 ++
 arch/arm/boot/dts/rk3288.dtsi  |  15 +
 drivers/clk/rockchip/clk-rk3288.c  |   2 +-
 drivers/crypto/Kconfig |  11 +
 drivers/crypto/Makefile|   1 +
 drivers/crypto/rockchip/Makefile   |   3 +
 drivers/crypto/rockchip/rk3288_crypto.c| 380 +++
 drivers/crypto/rockchip/rk3288_crypto.h| 222 +
 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c | 511 +
 include/dt-bindings/clock/rk3288-cru.h |   1 +
 10 files changed, 1174 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/crypto/rockchip-crypto.txt
 create mode 100644 drivers/crypto/rockchip/Makefile
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto.c
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto.h
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c

-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 3/4] ARM: dts: rockchip: Add Crypto drivers for rk3288

2015-11-05 Thread Zain Wang
Add Crypto drivers for rk3288 including crypto controller and dma clk.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
---

Changed in v2:
- None

Changed in v1:
- remove the _crypto suffix
- use "rockchip,rk3288-crypto" instead of "rockchip,rk3288"

 arch/arm/boot/dts/rk3288.dtsi | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index 6a79c9c..7b7914e 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -170,6 +170,21 @@
};
};
 
+   crypto: cypto-controller@ff8a {
+   compatible = "rockchip,rk3288-crypto";
+   reg = <0xff8a 0x4000>;
+   interrupts = ;
+   clocks = < ACLK_CRYPTO>,
+< HCLK_CRYPTO>,
+< SCLK_CRYPTO>,
+< ACLK_DMAC1>;
+   clock-names = "aclk",
+ "hclk",
+ "sclk",
+ "apb_pclk";
+   status = "okay";
+   };
+
reserved-memory {
#address-cells = <1>;
#size-cells = <1>;
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 4/4] crypto: rockchip/crypto - add DT bindings documentation

2015-11-05 Thread Zain Wang
Add DT bindings documentation for the rk3288 crypto drivers.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
---

Changde in v2:
- None

Changed in v1:
- remove the _crypto suffix
- use "rockchip,rk3288-crypto" instead of "rockchip,rk3288"
- remove the description of status

 .../devicetree/bindings/crypto/rockchip-crypto.txt | 29 ++
 1 file changed, 29 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/crypto/rockchip-crypto.txt

diff --git a/Documentation/devicetree/bindings/crypto/rockchip-crypto.txt 
b/Documentation/devicetree/bindings/crypto/rockchip-crypto.txt
new file mode 100644
index 000..d27e203
--- /dev/null
+++ b/Documentation/devicetree/bindings/crypto/rockchip-crypto.txt
@@ -0,0 +1,29 @@
+Rockchip Electronics And Security Accelerator
+
+Required properties:
+- compatible: Should be "rockchip,rk3288-crypto"
+- reg: base physical address of the engine and length of memory mapped
+   region
+- interrupts: interrupt number
+- clocks: reference to the clocks about crypto
+- clock-names: "aclk" used to clock data
+  "hclk" used to clock data
+  "srst" used to clock crypto accelerator
+  "apb_pclk" used to clock dma
+
+Examples:
+
+   crypto: cypto-controller@ff8a {
+   compatible = "rockchip,rk3288-crypto";
+   reg = <0xff8a 0x4000>;
+   interrupts = ;
+   clocks = < ACLK_CRYPTO>,
+< HCLK_CRYPTO>,
+< SCLK_CRYPTO>,
+< ACLK_DMAC1>;
+   clock-names = "aclk",
+ "hclk",
+ "sclk",
+ "apb_pclk";
+   status = "okay";
+   };
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/4] Crypto: Crypto driver support aes/des/des3 for rk3288

2015-11-05 Thread Zain Wang
The names registered are:
ecb(aes) cbc(aes) ecb(des) cbc(des) ecb(des3_ede) cbc(des3_ede)
You can alloc tags above in your case.

And other algorithms and platforms will be added later on.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
---

Changed in v2:
- remove some part about hash
- add weak key detection
- changed some variate's type

Changde in v1:
- modify some variate's name
- modify some variate's type
- modify some return value
- remove or modify some print info
- use more dev_xxx in probe
- modify the prio of cipher

 drivers/crypto/Kconfig |  11 +
 drivers/crypto/Makefile|   1 +
 drivers/crypto/rockchip/Makefile   |   3 +
 drivers/crypto/rockchip/rk3288_crypto.c| 380 +++
 drivers/crypto/rockchip/rk3288_crypto.h| 222 +
 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c | 511 +
 6 files changed, 1128 insertions(+)
 create mode 100644 drivers/crypto/rockchip/Makefile
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto.c
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto.h
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c

diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index 2569e04..d1e42cf 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -498,4 +498,15 @@ config CRYPTO_DEV_SUN4I_SS
  To compile this driver as a module, choose M here: the module
  will be called sun4i-ss.
 
+config CRYPTO_DEV_ROCKCHIP
+   tristate "Rockchip's Cryptographic Engine driver"
+
+   select CRYPTO_AES
+   select CRYPTO_DES
+   select CRYPTO_BLKCIPHER
+
+   help
+ This driver interfaces with the hardware crypto accelerator.
+ Supporting cbc/ecb chainmode, and aes/des/des3_ede cipher mode.
+
 endif # CRYPTO_HW
diff --git a/drivers/crypto/Makefile b/drivers/crypto/Makefile
index c3ced6f..713de9d 100644
--- a/drivers/crypto/Makefile
+++ b/drivers/crypto/Makefile
@@ -29,3 +29,4 @@ obj-$(CONFIG_CRYPTO_DEV_QAT) += qat/
 obj-$(CONFIG_CRYPTO_DEV_QCE) += qce/
 obj-$(CONFIG_CRYPTO_DEV_VMX) += vmx/
 obj-$(CONFIG_CRYPTO_DEV_SUN4I_SS) += sunxi-ss/
+obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP) += rockchip/
diff --git a/drivers/crypto/rockchip/Makefile b/drivers/crypto/rockchip/Makefile
new file mode 100644
index 000..7051c6c
--- /dev/null
+++ b/drivers/crypto/rockchip/Makefile
@@ -0,0 +1,3 @@
+obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP) += rk_crypto.o
+rk_crypto-objs := rk3288_crypto.o \
+ rk3288_crypto_ablkcipher.o \
diff --git a/drivers/crypto/rockchip/rk3288_crypto.c 
b/drivers/crypto/rockchip/rk3288_crypto.c
new file mode 100644
index 000..c2a419b
--- /dev/null
+++ b/drivers/crypto/rockchip/rk3288_crypto.c
@@ -0,0 +1,380 @@
+/*
+ *Crypto acceleration support for Rockchip RK3288
+ *
+ * Copyright (c) 2015, Fuzhou Rockchip Electronics Co., Ltd
+ *
+ * Author: Zain Wang <zain.w...@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * Some ideas are from marvell-cesa.c and s5p-sss.c driver.
+ */
+
+#include "rk3288_crypto.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct crypto_info_t *crypto_p;
+
+static int rk_crypto_enable_clk(struct crypto_info_t *dev)
+{
+   int err;
+
+   err = clk_prepare_enable(dev->sclk);
+   if (err) {
+   dev_err(dev->dev, "[%s:%d], Couldn't enable clock 'sclk'\n",
+   __func__, __LINE__);
+   goto err_return;
+   }
+   err = clk_prepare_enable(dev->aclk);
+   if (err) {
+   dev_err(dev->dev, "[%s:%d], Couldn't enable clock 'aclk'\n",
+   __func__, __LINE__);
+   goto err_aclk;
+   }
+   err = clk_prepare_enable(dev->hclk);
+   if (err) {
+   dev_err(dev->dev, "[%s:%d], Couldn't enable clock 'hclk'\n",
+   __func__, __LINE__);
+   goto err_hclk;
+   }
+
+   err = clk_prepare_enable(dev->dmaclk);
+   if (err) {
+   dev_err(dev->dev, "[%s:%d], Couldn't enable clock 'dmaclk'\n",
+   __func__, __LINE__);
+   goto err_dmaclk;
+   }
+   return err;
+err_dmaclk:
+   clk_disable_unprepare(dev->hclk);
+err_hclk:
+   clk_disable_unprepare(dev->aclk);
+err_aclk:
+   clk_disable_unprepare(dev->sclk);
+err_return:
+   return err;
+}
+
+static void rk_crypto_disable_clk(struct crypto_info_t *dev)
+{
+   clk_disable_unprepare(dev->dmaclk);
+   clk_disable_unprepare(dev->hclk);
+   clk_disable_unprepare(dev->aclk);
+   clk_disable_unprepare(dev->sclk);
+}
+
+static int check_alignm

[PATCH v1 1/4] Crypto: Crypto driver support aes/des/des3 for rk3288

2015-11-02 Thread Zain Wang
Crypto driver support cbc/ecb two chainmode, and aes/des/des3 three cipher
mode.
The names registered are:
ecb(aes) cbc(aes) ecb(des) cbc(des) ecb(des3_ede) cbc(des3_ede)
You can alloc tags above in your case.

And other algorithms and platforms will be added later on.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
---
 drivers/crypto/Kconfig |  11 +
 drivers/crypto/Makefile|   1 +
 drivers/crypto/rockchip/Makefile   |   3 +
 drivers/crypto/rockchip/rk3288_crypto.c| 383 
 drivers/crypto/rockchip/rk3288_crypto.h| 290 
 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c | 501 +
 6 files changed, 1189 insertions(+)
 create mode 100644 drivers/crypto/rockchip/Makefile
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto.c
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto.h
 create mode 100644 drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c

diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index 2569e04..d1e42cf 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -498,4 +498,15 @@ config CRYPTO_DEV_SUN4I_SS
  To compile this driver as a module, choose M here: the module
  will be called sun4i-ss.
 
+config CRYPTO_DEV_ROCKCHIP
+   tristate "Rockchip's Cryptographic Engine driver"
+
+   select CRYPTO_AES
+   select CRYPTO_DES
+   select CRYPTO_BLKCIPHER
+
+   help
+ This driver interfaces with the hardware crypto accelerator.
+ Supporting cbc/ecb chainmode, and aes/des/des3_ede cipher mode.
+
 endif # CRYPTO_HW
diff --git a/drivers/crypto/Makefile b/drivers/crypto/Makefile
index c3ced6f..713de9d 100644
--- a/drivers/crypto/Makefile
+++ b/drivers/crypto/Makefile
@@ -29,3 +29,4 @@ obj-$(CONFIG_CRYPTO_DEV_QAT) += qat/
 obj-$(CONFIG_CRYPTO_DEV_QCE) += qce/
 obj-$(CONFIG_CRYPTO_DEV_VMX) += vmx/
 obj-$(CONFIG_CRYPTO_DEV_SUN4I_SS) += sunxi-ss/
+obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP) += rockchip/
diff --git a/drivers/crypto/rockchip/Makefile b/drivers/crypto/rockchip/Makefile
new file mode 100644
index 000..7051c6c
--- /dev/null
+++ b/drivers/crypto/rockchip/Makefile
@@ -0,0 +1,3 @@
+obj-$(CONFIG_CRYPTO_DEV_ROCKCHIP) += rk_crypto.o
+rk_crypto-objs := rk3288_crypto.o \
+ rk3288_crypto_ablkcipher.o \
diff --git a/drivers/crypto/rockchip/rk3288_crypto.c 
b/drivers/crypto/rockchip/rk3288_crypto.c
new file mode 100644
index 000..02830f2
--- /dev/null
+++ b/drivers/crypto/rockchip/rk3288_crypto.c
@@ -0,0 +1,383 @@
+/*
+ *Crypto acceleration support for Rockchip RK3288
+ *
+ * Copyright (c) 2015, Fuzhou Rockchip Electronics Co., Ltd
+ *
+ * Author: Zain Wang <zain.w...@rock-chips.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * Some ideas are from marvell-cesa.c and s5p-sss.c driver.
+ */
+
+#include "rk3288_crypto.h"
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct crypto_info_t *crypto_p;
+
+static int rk_crypto_enable_clk(struct crypto_info_t *dev)
+{
+   int err;
+
+   err = clk_prepare_enable(dev->sclk);
+   if (err) {
+   dev_err(dev->dev, "[%s:%d], Couldn't enable clock 'sclk'\n",
+   __func__, __LINE__);
+   goto err_return;
+   }
+   err = clk_prepare_enable(dev->aclk);
+   if (err) {
+   dev_err(dev->dev, "[%s:%d], Couldn't enable clock 'aclk'\n",
+   __func__, __LINE__);
+   goto err_aclk;
+   }
+   err = clk_prepare_enable(dev->hclk);
+   if (err) {
+   dev_err(dev->dev, "[%s:%d], Couldn't enable clock 'hclk'\n",
+   __func__, __LINE__);
+   goto err_hclk;
+   }
+
+   err = clk_prepare_enable(dev->dmaclk);
+   if (err) {
+   dev_err(dev->dev, "[%s:%d], Couldn't enable clock 'dmaclk'\n",
+   __func__, __LINE__);
+   goto err_dmaclk;
+   }
+   return err;
+err_dmaclk:
+   clk_disable_unprepare(dev->hclk);
+err_hclk:
+   clk_disable_unprepare(dev->aclk);
+err_aclk:
+   clk_disable_unprepare(dev->sclk);
+err_return:
+   return err;
+}
+
+static void rk_crypto_disable_clk(struct crypto_info_t *dev)
+{
+   clk_disable_unprepare(dev->dmaclk);
+   clk_disable_unprepare(dev->hclk);
+   clk_disable_unprepare(dev->aclk);
+   clk_disable_unprepare(dev->sclk);
+}
+
+static int check_alignment(struct scatterlist *sg_src,
+  struct scatterlist *sg_dst,
+ 

[PATCH v1 4/4] crypto: rk_crypto - add DT bindings documentation

2015-11-02 Thread Zain Wang
Add DT bindings documentation for the rk3288 crypto drivers.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
---
 .../devicetree/bindings/crypto/rockchip-crypto.txt | 29 ++
 1 file changed, 29 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/crypto/rockchip-crypto.txt

diff --git a/Documentation/devicetree/bindings/crypto/rockchip-crypto.txt 
b/Documentation/devicetree/bindings/crypto/rockchip-crypto.txt
new file mode 100644
index 000..d27e203
--- /dev/null
+++ b/Documentation/devicetree/bindings/crypto/rockchip-crypto.txt
@@ -0,0 +1,29 @@
+Rockchip Electronics And Security Accelerator
+
+Required properties:
+- compatible: Should be "rockchip,rk3288-crypto"
+- reg: base physical address of the engine and length of memory mapped
+   region
+- interrupts: interrupt number
+- clocks: reference to the clocks about crypto
+- clock-names: "aclk" used to clock data
+  "hclk" used to clock data
+  "srst" used to clock crypto accelerator
+  "apb_pclk" used to clock dma
+
+Examples:
+
+   crypto: cypto-controller@ff8a {
+   compatible = "rockchip,rk3288-crypto";
+   reg = <0xff8a 0x4000>;
+   interrupts = ;
+   clocks = < ACLK_CRYPTO>,
+< HCLK_CRYPTO>,
+< SCLK_CRYPTO>,
+< ACLK_DMAC1>;
+   clock-names = "aclk",
+ "hclk",
+ "sclk",
+ "apb_pclk";
+   status = "okay";
+   };
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v1 2/4] clk: rockchip: set an id for crypto clk

2015-11-02 Thread Zain Wang
set an id for crypto clk, so that it can be called in other part.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
---
 drivers/clk/rockchip/clk-rk3288.c  | 2 +-
 include/dt-bindings/clock/rk3288-cru.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/rockchip/clk-rk3288.c 
b/drivers/clk/rockchip/clk-rk3288.c
index 9040878..3fceda1 100644
--- a/drivers/clk/rockchip/clk-rk3288.c
+++ b/drivers/clk/rockchip/clk-rk3288.c
@@ -295,7 +295,7 @@ static struct rockchip_clk_branch rk3288_clk_branches[] 
__initdata = {
RK3288_CLKGATE_CON(0), 4, GFLAGS),
GATE(0, "c2c_host", "aclk_cpu_src", 0,
RK3288_CLKGATE_CON(13), 8, GFLAGS),
-   COMPOSITE_NOMUX(0, "crypto", "aclk_cpu_pre", 0,
+   COMPOSITE_NOMUX(SCLK_CRYPTO, "crypto", "aclk_cpu_pre", 0,
RK3288_CLKSEL_CON(26), 6, 2, DFLAGS,
RK3288_CLKGATE_CON(5), 4, GFLAGS),
GATE(0, "aclk_bus_2pmu", "aclk_cpu_pre", CLK_IGNORE_UNUSED,
diff --git a/include/dt-bindings/clock/rk3288-cru.h 
b/include/dt-bindings/clock/rk3288-cru.h
index c719aac..30dcd60 100644
--- a/include/dt-bindings/clock/rk3288-cru.h
+++ b/include/dt-bindings/clock/rk3288-cru.h
@@ -86,6 +86,7 @@
 #define SCLK_USBPHY480M_SRC122
 #define SCLK_PVTM_CORE 123
 #define SCLK_PVTM_GPU  124
+#define SCLK_CRYPTO125
 
 #define SCLK_MAC   151
 #define SCLK_MACREF_OUT152
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v1 3/4] ARM: dts: rockchip: Add Crypto drivers for rk3288

2015-11-02 Thread Zain Wang
Add Crypto drivers for rk3288 including crypto controller and dma clk.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
---
 arch/arm/boot/dts/rk3288.dtsi | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index 6a79c9c..7b7914e 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -170,6 +170,21 @@
};
};
 
+   crypto: cypto-controller@ff8a {
+   compatible = "rockchip,rk3288-crypto";
+   reg = <0xff8a 0x4000>;
+   interrupts = ;
+   clocks = < ACLK_CRYPTO>,
+< HCLK_CRYPTO>,
+< SCLK_CRYPTO>,
+< ACLK_DMAC1>;
+   clock-names = "aclk",
+ "hclk",
+ "sclk",
+ "apb_pclk";
+   status = "okay";
+   };
+
reserved-memory {
#address-cells = <1>;
#size-cells = <1>;
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RESEND PATCH 0/4] Crypto: add crypto accelerator support for rk3288

2015-10-30 Thread Zain Wang
This commit support three cipher(AES/DES/DES3) and two chainmode(ecb/cbc),
and the more algorithms or new hash drivers will be added later on.

Zain Wang (4):
  Crypto: Crypto driver support aes/des/des3 for rk3288
  clk: rockchip: set an id for crypto clk
  ARM: dts: rockchip: Add Crypto drivers for rk3288
  crypto: rk_crypto - add DT bindings documentation

 .../devicetree/bindings/crypto/rk-crypto.txt   |  31 ++
 arch/arm/boot/dts/rk3288.dtsi  |  16 +
 drivers/clk/rockchip/clk-rk3288.c  |   2 +-
 drivers/crypto/Makefile|   1 +
 drivers/crypto/rk_crypto/Makefile  |   3 +
 drivers/crypto/rk_crypto/rk3288_crypto.c   | 393 
 drivers/crypto/rk_crypto/rk3288_crypto.h   | 291 
 .../crypto/rk_crypto/rk3288_crypto_ablkcipher.c| 502 +
 8 files changed, 1238 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/crypto/rk-crypto.txt
 create mode 100644 drivers/crypto/rk_crypto/Makefile
 create mode 100644 drivers/crypto/rk_crypto/rk3288_crypto.c
 create mode 100644 drivers/crypto/rk_crypto/rk3288_crypto.h
 create mode 100644 drivers/crypto/rk_crypto/rk3288_crypto_ablkcipher.c

-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RESEND PATCH 4/4] crypto: rk_crypto - add DT bindings documentation

2015-10-30 Thread Zain Wang
Add DT bindings documentation for the rk3288 crypto drivers.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
---
 .../devicetree/bindings/crypto/rk-crypto.txt   | 31 ++
 1 file changed, 31 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/crypto/rk-crypto.txt

diff --git a/Documentation/devicetree/bindings/crypto/rk-crypto.txt 
b/Documentation/devicetree/bindings/crypto/rk-crypto.txt
new file mode 100644
index 000..1e50768
--- /dev/null
+++ b/Documentation/devicetree/bindings/crypto/rk-crypto.txt
@@ -0,0 +1,31 @@
+Rockchip Electronics And Security Accelerator
+
+Required properties:
+- compatible: should be "rockchip,crypto"
+- reg: base physical address of the engine and length of memory mapped
+   region.
+- interrupts: interrupt number
+- clocks: clock specifiers
+- clock-names: "aclk_crypto" used to clock data
+  "hclk_crypto" used to clock data
+  "srst_crypto" used to clock crypto accelerator
+  "apb_pclk"used to clock dma
+-status: Enable
+
+Examples:
+
+   crypto: cypto-controller@ff8a {
+   compatible = "rockchip,crypto";
+   reg = <0xff8a 0x4000>;
+   interrupts = ;
+   clocks = < ACLK_CRYPTO>,
+< HCLK_CRYPTO>,
+< SRST_CRYPTO>,
+< ACLK_DMAC1>;
+
+   clock-names = "aclk_crypto",
+ "hclk_crypto",
+ "srst_crypto",
+ "apb_pclk";
+   status = "okay";
+   };
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RESEND PATCH 3/4] ARM: dts: rockchip: Add Crypto drivers for rk3288

2015-10-30 Thread Zain Wang
Add Crypto drivers for rk3288 including crypto controller and dma clk.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
---
 arch/arm/boot/dts/rk3288.dtsi | 16 
 1 file changed, 16 insertions(+)

diff --git a/arch/arm/boot/dts/rk3288.dtsi b/arch/arm/boot/dts/rk3288.dtsi
index 6a79c9c..1706706 100644
--- a/arch/arm/boot/dts/rk3288.dtsi
+++ b/arch/arm/boot/dts/rk3288.dtsi
@@ -170,6 +170,22 @@
};
};
 
+   crypto: cypto-controller@ff8a {
+   compatible = "rockchip,crypto";
+   reg = <0xff8a 0x4000>;
+   interrupts = ;
+   clocks = < ACLK_CRYPTO>,
+< HCLK_CRYPTO>,
+< SRST_CRYPTO>,
+< ACLK_DMAC1>;
+
+   clock-names = "aclk_crypto",
+ "hclk_crypto",
+ "srst_crypto",
+ "apb_pclk";
+   status = "okay";
+   };
+
reserved-memory {
#address-cells = <1>;
#size-cells = <1>;
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RESEND PATCH 2/4] clk: rockchip: set an id for crypto clk

2015-10-30 Thread Zain Wang
set an id for crypto clk, so that it can be called in other part.

Signed-off-by: Zain Wang <zain.w...@rock-chips.com>
---
 drivers/clk/rockchip/clk-rk3288.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/rockchip/clk-rk3288.c 
b/drivers/clk/rockchip/clk-rk3288.c
index 9040878..d74bd5d 100644
--- a/drivers/clk/rockchip/clk-rk3288.c
+++ b/drivers/clk/rockchip/clk-rk3288.c
@@ -295,7 +295,7 @@ static struct rockchip_clk_branch rk3288_clk_branches[] 
__initdata = {
RK3288_CLKGATE_CON(0), 4, GFLAGS),
GATE(0, "c2c_host", "aclk_cpu_src", 0,
RK3288_CLKGATE_CON(13), 8, GFLAGS),
-   COMPOSITE_NOMUX(0, "crypto", "aclk_cpu_pre", 0,
+   COMPOSITE_NOMUX(SRST_CRYPTO, "crypto", "aclk_cpu_pre", 0,
RK3288_CLKSEL_CON(26), 6, 2, DFLAGS,
RK3288_CLKGATE_CON(5), 4, GFLAGS),
GATE(0, "aclk_bus_2pmu", "aclk_cpu_pre", CLK_IGNORE_UNUSED,
-- 
1.9.1


--
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html