linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/10] crypto: at91: add support for SAMA5D4 and fix related bugs
@ 2015-04-07  9:45 Leilei Zhao
  2015-04-07  9:45 ` [PATCH 01/10] crypto: atmel-aes: add new version Leilei Zhao
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: Leilei Zhao @ 2015-04-07  9:45 UTC (permalink / raw)
  To: herbert, davem, linux-crypto, linux-kernel, nicolas.ferre,
	Ludovic.Desroches
  Cc: linux-arm-kernel, Leilei Zhao

The series of patches add crypto driver for SAMA5D4 and 
fix some bugs about Atmel crypto driver:
 - Add new IP version for AES and SHA.
 - The spinlock is not initialized before using.
 - Fix sg list management to avoid crash if there is a zero length sg in list.
 - The max burst size in DMA configuration is out of range.
 - The result of AES periodically goes wrong with performance test in OpenSSH.
 - Fix a hangup issue in driver's internal buffer process.

The patches were made from herbert/crypto-2.6.git repository, and tested on a
SAMA5D4EK board and also did regression tests on SAMA5D3EK.

Leilei Zhao (9):
  crypto: atmel-aes: add new version
  crypto: atmel-sha: add new version
  crypto: atmel-sha: fix sg list management
  crypto: atmel-sha: initialize spinlock in probe
  crypto: atmel-sha: correct the max burst size
  crypto: atmel-tdes: initialize spinlock in probe
  crypto: atmel-aes: initialize spinlock in probe
  crypto: atmel-aes: sync the buf used in DMA or CPU
  crypto: atmel-aes: correct usage of dma_sync_* API

Ludovic Desroches (1):
  crypto: atmel-sha: correct the way data are split

 drivers/crypto/atmel-aes.c  |   24 +++++++++++++++++++-----
 drivers/crypto/atmel-sha.c  |   35 ++++++++++++++++++++++++-----------
 drivers/crypto/atmel-tdes.c |    1 +
 3 files changed, 44 insertions(+), 16 deletions(-)

-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 01/10] crypto: atmel-aes: add new version
  2015-04-07  9:45 [PATCH 00/10] crypto: at91: add support for SAMA5D4 and fix related bugs Leilei Zhao
@ 2015-04-07  9:45 ` Leilei Zhao
  2015-04-07  9:45 ` [PATCH 02/10] crypto: atmel-sha: " Leilei Zhao
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Leilei Zhao @ 2015-04-07  9:45 UTC (permalink / raw)
  To: herbert, davem, linux-crypto, linux-kernel, nicolas.ferre,
	Ludovic.Desroches
  Cc: linux-arm-kernel, Leilei Zhao, Ludovic Desroches

Add new version of atmel-aes available with SAMA5D4 devices.

Signed-off-by: Leilei Zhao <leilei.zhao@atmel.com>
Signed-off-by: Ludovic Desroches <ludovic.desroches@atmel.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
 drivers/crypto/atmel-aes.c |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/crypto/atmel-aes.c b/drivers/crypto/atmel-aes.c
index 6597aac..ddea772 100644
--- a/drivers/crypto/atmel-aes.c
+++ b/drivers/crypto/atmel-aes.c
@@ -1246,6 +1246,11 @@ static void atmel_aes_get_cap(struct atmel_aes_dev *dd)
 
 	/* keep only major version number */
 	switch (dd->hw_version & 0xff0) {
+	case 0x200:
+		dd->caps.has_dualbuff = 1;
+		dd->caps.has_cfb64 = 1;
+		dd->caps.max_burst_size = 4;
+		break;
 	case 0x130:
 		dd->caps.has_dualbuff = 1;
 		dd->caps.has_cfb64 = 1;
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 02/10] crypto: atmel-sha: add new version
  2015-04-07  9:45 [PATCH 00/10] crypto: at91: add support for SAMA5D4 and fix related bugs Leilei Zhao
  2015-04-07  9:45 ` [PATCH 01/10] crypto: atmel-aes: add new version Leilei Zhao
@ 2015-04-07  9:45 ` Leilei Zhao
  2015-04-07  9:45 ` [PATCH 03/10] crypto: atmel-sha: correct the way data are split Leilei Zhao
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Leilei Zhao @ 2015-04-07  9:45 UTC (permalink / raw)
  To: herbert, davem, linux-crypto, linux-kernel, nicolas.ferre,
	Ludovic.Desroches
  Cc: linux-arm-kernel, Leilei Zhao, Ludovic Desroches

Add new version of atmel-sha available with SAMA5D4 devices.

Signed-off-by: Leilei Zhao <leilei.zhao@atmel.com>
Signed-off-by: Ludovic Desroches <ludovic.desroches@atmel.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
 drivers/crypto/atmel-sha.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/crypto/atmel-sha.c b/drivers/crypto/atmel-sha.c
index 34db04a..d092313 100644
--- a/drivers/crypto/atmel-sha.c
+++ b/drivers/crypto/atmel-sha.c
@@ -1266,6 +1266,12 @@ static void atmel_sha_get_cap(struct atmel_sha_dev *dd)
 
 	/* keep only major version number */
 	switch (dd->hw_version & 0xff0) {
+	case 0x420:
+		dd->caps.has_dma = 1;
+		dd->caps.has_dualbuff = 1;
+		dd->caps.has_sha224 = 1;
+		dd->caps.has_sha_384_512 = 1;
+		break;
 	case 0x410:
 		dd->caps.has_dma = 1;
 		dd->caps.has_dualbuff = 1;
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 03/10] crypto: atmel-sha: correct the way data are split
  2015-04-07  9:45 [PATCH 00/10] crypto: at91: add support for SAMA5D4 and fix related bugs Leilei Zhao
  2015-04-07  9:45 ` [PATCH 01/10] crypto: atmel-aes: add new version Leilei Zhao
  2015-04-07  9:45 ` [PATCH 02/10] crypto: atmel-sha: " Leilei Zhao
@ 2015-04-07  9:45 ` Leilei Zhao
  2015-04-07  9:45 ` [PATCH 04/10] crypto: atmel-sha: fix sg list management Leilei Zhao
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Leilei Zhao @ 2015-04-07  9:45 UTC (permalink / raw)
  To: herbert, davem, linux-crypto, linux-kernel, nicolas.ferre,
	Ludovic.Desroches
  Cc: linux-arm-kernel, Ludovic Desroches, Leilei Zhao

From: Ludovic Desroches <ludovic.desroches@atmel.com>

When a hash is requested on data bigger than the buffer allocated by the
SHA driver, the way DMA transfers are performed is quite strange:
The buffer is filled at each update request. When full, a DMA transfer
is done. On next update request, another DMA transfer is done. Then we
wait to have a full buffer (or the end of the data) to perform the dma
transfer. Such a situation lead sometimes, on SAMA5D4, to a case where
dma transfer is finished but the data ready irq never comes. Moreover
hash was incorrect in this case.

With this patch, dma transfers are only performed when the buffer is
full or when there is no more data. So it removes the transfer whose size
is equal the update size after the full buffer transmission.

Signed-off-by: Ludovic Desroches <ludovic.desroches@atmel.com>
Signed-off-by: Leilei Zhao <leilei.zhao@atmel.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
 drivers/crypto/atmel-sha.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/atmel-sha.c b/drivers/crypto/atmel-sha.c
index d092313..b471bbe 100644
--- a/drivers/crypto/atmel-sha.c
+++ b/drivers/crypto/atmel-sha.c
@@ -529,7 +529,7 @@ static int atmel_sha_update_dma_slow(struct atmel_sha_dev *dd)
 	if (final)
 		atmel_sha_fill_padding(ctx, 0);
 
-	if (final || (ctx->bufcnt == ctx->buflen && ctx->total)) {
+	if (final || (ctx->bufcnt == ctx->buflen)) {
 		count = ctx->bufcnt;
 		ctx->bufcnt = 0;
 		return atmel_sha_xmit_dma_map(dd, ctx, count, final);
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 04/10] crypto: atmel-sha: fix sg list management
  2015-04-07  9:45 [PATCH 00/10] crypto: at91: add support for SAMA5D4 and fix related bugs Leilei Zhao
                   ` (2 preceding siblings ...)
  2015-04-07  9:45 ` [PATCH 03/10] crypto: atmel-sha: correct the way data are split Leilei Zhao
@ 2015-04-07  9:45 ` Leilei Zhao
  2015-04-07  9:45 ` [PATCH 05/10] crypto: atmel-sha: initialize spinlock in probe Leilei Zhao
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Leilei Zhao @ 2015-04-07  9:45 UTC (permalink / raw)
  To: herbert, davem, linux-crypto, linux-kernel, nicolas.ferre,
	Ludovic.Desroches
  Cc: linux-arm-kernel, Leilei Zhao, Ludovic Desroches

Having a zero length sg doesn't mean it is the end of the sg list. This
case happens when calculating HMAC of IPSec packet.

Signed-off-by: Leilei Zhao <leilei.zhao@atmel.com>
Signed-off-by: Ludovic Desroches <ludovic.desroches@atmel.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
 drivers/crypto/atmel-sha.c |   16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/crypto/atmel-sha.c b/drivers/crypto/atmel-sha.c
index b471bbe..9fb8af1 100644
--- a/drivers/crypto/atmel-sha.c
+++ b/drivers/crypto/atmel-sha.c
@@ -163,8 +163,20 @@ static size_t atmel_sha_append_sg(struct atmel_sha_reqctx *ctx)
 		count = min(ctx->sg->length - ctx->offset, ctx->total);
 		count = min(count, ctx->buflen - ctx->bufcnt);
 
-		if (count <= 0)
-			break;
+		if (count <= 0) {
+			/*
+			* Check if count <= 0 because the buffer is full or
+			* because the sg length is 0. In the latest case,
+			* check if there is another sg in the list, a 0 length
+			* sg doesn't necessarily mean the end of the sg list.
+			*/
+			if ((ctx->sg->length == 0) && !sg_is_last(ctx->sg)) {
+				ctx->sg = sg_next(ctx->sg);
+				continue;
+			} else {
+				break;
+			}
+		}
 
 		scatterwalk_map_and_copy(ctx->buffer + ctx->bufcnt, ctx->sg,
 			ctx->offset, count, 0);
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 05/10] crypto: atmel-sha: initialize spinlock in probe
  2015-04-07  9:45 [PATCH 00/10] crypto: at91: add support for SAMA5D4 and fix related bugs Leilei Zhao
                   ` (3 preceding siblings ...)
  2015-04-07  9:45 ` [PATCH 04/10] crypto: atmel-sha: fix sg list management Leilei Zhao
@ 2015-04-07  9:45 ` Leilei Zhao
  2015-04-07  9:45 ` [PATCH 06/10] crypto: atmel-sha: correct the max burst size Leilei Zhao
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Leilei Zhao @ 2015-04-07  9:45 UTC (permalink / raw)
  To: herbert, davem, linux-crypto, linux-kernel, nicolas.ferre,
	Ludovic.Desroches
  Cc: linux-arm-kernel, Leilei Zhao

Kernel will report "BUG: spinlock lockup suspected on CPU#0"
when CONFIG_DEBUG_SPINLOCK is enabled in kernel config and the
spinlock is used at the first time. It's caused by uninitialized
spinlock, so just initialize it in probe.

Signed-off-by: Leilei Zhao <leilei.zhao@atmel.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
 drivers/crypto/atmel-sha.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/crypto/atmel-sha.c b/drivers/crypto/atmel-sha.c
index 9fb8af1..6430f6a 100644
--- a/drivers/crypto/atmel-sha.c
+++ b/drivers/crypto/atmel-sha.c
@@ -1367,6 +1367,7 @@ static int atmel_sha_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, sha_dd);
 
 	INIT_LIST_HEAD(&sha_dd->list);
+	spin_lock_init(&sha_dd->lock);
 
 	tasklet_init(&sha_dd->done_task, atmel_sha_done_task,
 					(unsigned long)sha_dd);
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 06/10] crypto: atmel-sha: correct the max burst size
  2015-04-07  9:45 [PATCH 00/10] crypto: at91: add support for SAMA5D4 and fix related bugs Leilei Zhao
                   ` (4 preceding siblings ...)
  2015-04-07  9:45 ` [PATCH 05/10] crypto: atmel-sha: initialize spinlock in probe Leilei Zhao
@ 2015-04-07  9:45 ` Leilei Zhao
  2015-04-07  9:45 ` [PATCH 07/10] crypto: atmel-tdes: initialize spinlock in probe Leilei Zhao
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Leilei Zhao @ 2015-04-07  9:45 UTC (permalink / raw)
  To: herbert, davem, linux-crypto, linux-kernel, nicolas.ferre,
	Ludovic.Desroches
  Cc: linux-arm-kernel, Leilei Zhao

The maximum source and destination burst size is 16
according to the datasheet of Atmel DMA. And the value
is also checked in function at_xdmac_csize of Atmel
DMA driver. With the restrict, the value beyond maximum
value will not be processed in DMA driver, so SHA384 and
SHA512 will not work and the program will wait forever.

So here change the max burst size of all the cases to 16
in order to make SHA384 and SHA512 work and keep consistent
with DMA driver and datasheet.

Signed-off-by: Leilei Zhao <leilei.zhao@atmel.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
 drivers/crypto/atmel-sha.c |   10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/crypto/atmel-sha.c b/drivers/crypto/atmel-sha.c
index 6430f6a..99a632c 100644
--- a/drivers/crypto/atmel-sha.c
+++ b/drivers/crypto/atmel-sha.c
@@ -432,14 +432,8 @@ static int atmel_sha_xmit_dma(struct atmel_sha_dev *dd, dma_addr_t dma_addr1,
 	dev_dbg(dd->dev, "xmit_dma: digcnt: 0x%llx 0x%llx, length: %d, final: %d\n",
 		ctx->digcnt[1], ctx->digcnt[0], length1, final);
 
-	if (ctx->flags & (SHA_FLAGS_SHA1 | SHA_FLAGS_SHA224 |
-			SHA_FLAGS_SHA256)) {
-		dd->dma_lch_in.dma_conf.src_maxburst = 16;
-		dd->dma_lch_in.dma_conf.dst_maxburst = 16;
-	} else {
-		dd->dma_lch_in.dma_conf.src_maxburst = 32;
-		dd->dma_lch_in.dma_conf.dst_maxburst = 32;
-	}
+	dd->dma_lch_in.dma_conf.src_maxburst = 16;
+	dd->dma_lch_in.dma_conf.dst_maxburst = 16;
 
 	dmaengine_slave_config(dd->dma_lch_in.chan, &dd->dma_lch_in.dma_conf);
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 07/10] crypto: atmel-tdes: initialize spinlock in probe
  2015-04-07  9:45 [PATCH 00/10] crypto: at91: add support for SAMA5D4 and fix related bugs Leilei Zhao
                   ` (5 preceding siblings ...)
  2015-04-07  9:45 ` [PATCH 06/10] crypto: atmel-sha: correct the max burst size Leilei Zhao
@ 2015-04-07  9:45 ` Leilei Zhao
  2015-04-07  9:45 ` [PATCH 08/10] crypto: atmel-aes: " Leilei Zhao
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Leilei Zhao @ 2015-04-07  9:45 UTC (permalink / raw)
  To: herbert, davem, linux-crypto, linux-kernel, nicolas.ferre,
	Ludovic.Desroches
  Cc: linux-arm-kernel, Leilei Zhao

Kernel will report "BUG: spinlock lockup suspected on CPU#0"
when CONFIG_DEBUG_SPINLOCK is enabled in kernel config and the
spinlock is used at the first time. It's caused by uninitialized
spinlock, so just initialize it in probe.

Signed-off-by: Leilei Zhao <leilei.zhao@atmel.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
 drivers/crypto/atmel-tdes.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/crypto/atmel-tdes.c b/drivers/crypto/atmel-tdes.c
index 258772d..3517e2a 100644
--- a/drivers/crypto/atmel-tdes.c
+++ b/drivers/crypto/atmel-tdes.c
@@ -1370,6 +1370,7 @@ static int atmel_tdes_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, tdes_dd);
 
 	INIT_LIST_HEAD(&tdes_dd->list);
+	spin_lock_init(&tdes_dd->lock);
 
 	tasklet_init(&tdes_dd->done_task, atmel_tdes_done_task,
 					(unsigned long)tdes_dd);
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 08/10] crypto: atmel-aes: initialize spinlock in probe
  2015-04-07  9:45 [PATCH 00/10] crypto: at91: add support for SAMA5D4 and fix related bugs Leilei Zhao
                   ` (6 preceding siblings ...)
  2015-04-07  9:45 ` [PATCH 07/10] crypto: atmel-tdes: initialize spinlock in probe Leilei Zhao
@ 2015-04-07  9:45 ` Leilei Zhao
  2015-04-07  9:45 ` [PATCH 09/10] crypto: atmel-aes: sync the buf used in DMA or CPU Leilei Zhao
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Leilei Zhao @ 2015-04-07  9:45 UTC (permalink / raw)
  To: herbert, davem, linux-crypto, linux-kernel, nicolas.ferre,
	Ludovic.Desroches
  Cc: linux-arm-kernel, Leilei Zhao

Kernel will report "BUG: spinlock lockup suspected on CPU#0"
when CONFIG_DEBUG_SPINLOCK is enabled in kernel config and the
spinlock is used at the first time. It's caused by uninitialized
spinlock, so just initialize it in probe.

Signed-off-by: Leilei Zhao <leilei.zhao@atmel.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
 drivers/crypto/atmel-aes.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/crypto/atmel-aes.c b/drivers/crypto/atmel-aes.c
index ddea772..f0532ab 100644
--- a/drivers/crypto/atmel-aes.c
+++ b/drivers/crypto/atmel-aes.c
@@ -1341,6 +1341,7 @@ static int atmel_aes_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, aes_dd);
 
 	INIT_LIST_HEAD(&aes_dd->list);
+	spin_lock_init(&aes_dd->lock);
 
 	tasklet_init(&aes_dd->done_task, atmel_aes_done_task,
 					(unsigned long)aes_dd);
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 09/10] crypto: atmel-aes: sync the buf used in DMA or CPU
  2015-04-07  9:45 [PATCH 00/10] crypto: at91: add support for SAMA5D4 and fix related bugs Leilei Zhao
                   ` (7 preceding siblings ...)
  2015-04-07  9:45 ` [PATCH 08/10] crypto: atmel-aes: " Leilei Zhao
@ 2015-04-07  9:45 ` Leilei Zhao
  2015-04-07  9:45 ` [PATCH 10/10] crypto: atmel-aes: correct usage of dma_sync_* API Leilei Zhao
  2015-04-08 14:24 ` [PATCH 00/10] crypto: at91: add support for SAMA5D4 and fix related bugs Herbert Xu
  10 siblings, 0 replies; 12+ messages in thread
From: Leilei Zhao @ 2015-04-07  9:45 UTC (permalink / raw)
  To: herbert, davem, linux-crypto, linux-kernel, nicolas.ferre,
	Ludovic.Desroches
  Cc: linux-arm-kernel, Leilei Zhao

The input buffer and output buffer are mapped for DMA transfer
in Atmel AES driver. But they are also be used by CPU when
the requested crypt length is not bigger than the threshold
value 16. The buffers will be cached in cache line when CPU
accessed them. When DMA uses the buffers again, the memory
can happened to be flushed by cache while DMA starts transfer.

So using API dma_sync_single_for_device and dma_sync_single_for_cpu
in DMA to ensure DMA coherence and CPU always access the correct
value. This fix the issue that the encrypted result periodically goes
wrong when doing performance test with OpenSSH.

Signed-off-by: Leilei Zhao <leilei.zhao@atmel.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
 drivers/crypto/atmel-aes.c |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/atmel-aes.c b/drivers/crypto/atmel-aes.c
index f0532ab..9bd3437 100644
--- a/drivers/crypto/atmel-aes.c
+++ b/drivers/crypto/atmel-aes.c
@@ -315,10 +315,10 @@ static int atmel_aes_crypt_dma(struct atmel_aes_dev *dd,
 
 	dd->dma_size = length;
 
-	if (!(dd->flags & AES_FLAGS_FAST)) {
-		dma_sync_single_for_device(dd->dev, dma_addr_in, length,
-					   DMA_TO_DEVICE);
-	}
+	dma_sync_single_for_device(dd->dev, dma_addr_in, length,
+				   DMA_TO_DEVICE);
+	dma_sync_single_for_device(dd->dev, dma_addr_out, length,
+				   DMA_FROM_DEVICE);
 
 	if (dd->flags & AES_FLAGS_CFB8) {
 		dd->dma_lch_in.dma_conf.dst_addr_width =
@@ -391,6 +391,11 @@ static int atmel_aes_crypt_cpu_start(struct atmel_aes_dev *dd)
 {
 	dd->flags &= ~AES_FLAGS_DMA;
 
+	dma_sync_single_for_cpu(dd->dev, dd->dma_addr_in,
+				dd->dma_size, DMA_TO_DEVICE);
+	dma_sync_single_for_cpu(dd->dev, dd->dma_addr_out,
+				dd->dma_size, DMA_FROM_DEVICE);
+
 	/* use cache buffers */
 	dd->nb_in_sg = atmel_aes_sg_length(dd->req, dd->in_sg);
 	if (!dd->nb_in_sg)
@@ -459,6 +464,9 @@ static int atmel_aes_crypt_dma_start(struct atmel_aes_dev *dd)
 		dd->flags |= AES_FLAGS_FAST;
 
 	} else {
+		dma_sync_single_for_cpu(dd->dev, dd->dma_addr_in,
+					dd->dma_size, DMA_TO_DEVICE);
+
 		/* use cache buffers */
 		count = atmel_aes_sg_copy(&dd->in_sg, &dd->in_offset,
 				dd->buf_in, dd->buflen, dd->total, 0);
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 10/10] crypto: atmel-aes: correct usage of dma_sync_* API
  2015-04-07  9:45 [PATCH 00/10] crypto: at91: add support for SAMA5D4 and fix related bugs Leilei Zhao
                   ` (8 preceding siblings ...)
  2015-04-07  9:45 ` [PATCH 09/10] crypto: atmel-aes: sync the buf used in DMA or CPU Leilei Zhao
@ 2015-04-07  9:45 ` Leilei Zhao
  2015-04-08 14:24 ` [PATCH 00/10] crypto: at91: add support for SAMA5D4 and fix related bugs Herbert Xu
  10 siblings, 0 replies; 12+ messages in thread
From: Leilei Zhao @ 2015-04-07  9:45 UTC (permalink / raw)
  To: herbert, davem, linux-crypto, linux-kernel, nicolas.ferre,
	Ludovic.Desroches
  Cc: linux-arm-kernel, Leilei Zhao

The output buffer is used for CPU access, so
the API should be dma_sync_single_for_cpu which
makes the cache line invalid in order to reload
the value in memory.

Signed-off-by: Leilei Zhao <leilei.zhao@atmel.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
---
 drivers/crypto/atmel-aes.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/atmel-aes.c b/drivers/crypto/atmel-aes.c
index 9bd3437..aa84623 100644
--- a/drivers/crypto/atmel-aes.c
+++ b/drivers/crypto/atmel-aes.c
@@ -627,7 +627,7 @@ static int atmel_aes_crypt_dma_stop(struct atmel_aes_dev *dd)
 			dma_unmap_sg(dd->dev, dd->out_sg, 1, DMA_FROM_DEVICE);
 			dma_unmap_sg(dd->dev, dd->in_sg, 1, DMA_TO_DEVICE);
 		} else {
-			dma_sync_single_for_device(dd->dev, dd->dma_addr_out,
+			dma_sync_single_for_cpu(dd->dev, dd->dma_addr_out,
 				dd->dma_size, DMA_FROM_DEVICE);
 
 			/* copy data */
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 00/10] crypto: at91: add support for SAMA5D4 and fix related bugs
  2015-04-07  9:45 [PATCH 00/10] crypto: at91: add support for SAMA5D4 and fix related bugs Leilei Zhao
                   ` (9 preceding siblings ...)
  2015-04-07  9:45 ` [PATCH 10/10] crypto: atmel-aes: correct usage of dma_sync_* API Leilei Zhao
@ 2015-04-08 14:24 ` Herbert Xu
  10 siblings, 0 replies; 12+ messages in thread
From: Herbert Xu @ 2015-04-08 14:24 UTC (permalink / raw)
  To: Leilei Zhao
  Cc: davem, linux-crypto, linux-kernel, nicolas.ferre,
	Ludovic.Desroches, linux-arm-kernel

On Tue, Apr 07, 2015 at 05:45:01PM +0800, Leilei Zhao wrote:
> The series of patches add crypto driver for SAMA5D4 and 
> fix some bugs about Atmel crypto driver:
>  - Add new IP version for AES and SHA.
>  - The spinlock is not initialized before using.
>  - Fix sg list management to avoid crash if there is a zero length sg in list.
>  - The max burst size in DMA configuration is out of range.
>  - The result of AES periodically goes wrong with performance test in OpenSSH.
>  - Fix a hangup issue in driver's internal buffer process.
> 
> The patches were made from herbert/crypto-2.6.git repository, and tested on a
> SAMA5D4EK board and also did regression tests on SAMA5D3EK.
> 
> Leilei Zhao (9):
>   crypto: atmel-aes: add new version
>   crypto: atmel-sha: add new version
>   crypto: atmel-sha: fix sg list management
>   crypto: atmel-sha: initialize spinlock in probe
>   crypto: atmel-sha: correct the max burst size
>   crypto: atmel-tdes: initialize spinlock in probe
>   crypto: atmel-aes: initialize spinlock in probe
>   crypto: atmel-aes: sync the buf used in DMA or CPU
>   crypto: atmel-aes: correct usage of dma_sync_* API
> 
> Ludovic Desroches (1):
>   crypto: atmel-sha: correct the way data are split
> 
>  drivers/crypto/atmel-aes.c  |   24 +++++++++++++++++++-----
>  drivers/crypto/atmel-sha.c  |   35 ++++++++++++++++++++++++-----------
>  drivers/crypto/atmel-tdes.c |    1 +
>  3 files changed, 44 insertions(+), 16 deletions(-)

All applied.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-04-08 14:24 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-07  9:45 [PATCH 00/10] crypto: at91: add support for SAMA5D4 and fix related bugs Leilei Zhao
2015-04-07  9:45 ` [PATCH 01/10] crypto: atmel-aes: add new version Leilei Zhao
2015-04-07  9:45 ` [PATCH 02/10] crypto: atmel-sha: " Leilei Zhao
2015-04-07  9:45 ` [PATCH 03/10] crypto: atmel-sha: correct the way data are split Leilei Zhao
2015-04-07  9:45 ` [PATCH 04/10] crypto: atmel-sha: fix sg list management Leilei Zhao
2015-04-07  9:45 ` [PATCH 05/10] crypto: atmel-sha: initialize spinlock in probe Leilei Zhao
2015-04-07  9:45 ` [PATCH 06/10] crypto: atmel-sha: correct the max burst size Leilei Zhao
2015-04-07  9:45 ` [PATCH 07/10] crypto: atmel-tdes: initialize spinlock in probe Leilei Zhao
2015-04-07  9:45 ` [PATCH 08/10] crypto: atmel-aes: " Leilei Zhao
2015-04-07  9:45 ` [PATCH 09/10] crypto: atmel-aes: sync the buf used in DMA or CPU Leilei Zhao
2015-04-07  9:45 ` [PATCH 10/10] crypto: atmel-aes: correct usage of dma_sync_* API Leilei Zhao
2015-04-08 14:24 ` [PATCH 00/10] crypto: at91: add support for SAMA5D4 and fix related bugs Herbert Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).