mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Cyrille Pitchen <cyrille.pitchen@atmel.com>
To: <herbert@gondor.apana.org.au>, <davem@davemloft.net>,
	<nicolas.ferre@atmel.com>
Cc: <linux-crypto@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linux-arm-kernel@lists.infradead.org>,
	Cyrille Pitchen <cyrille.pitchen@atmel.com>
Subject: [PATCH 11/24] crypto: atmel-aes: rework crypto request completion
Date: Thu, 17 Dec 2015 17:48:42 +0100	[thread overview]
Message-ID: <1237ced97e6c1b8f676c8e8d68899a503a35f260.1450366831.git.cyrille.pitchen@atmel.com> (raw)
In-Reply-To: <cover.1450366831.git.cyrille.pitchen@atmel.com>

This patch introduces a new callback 'resume' in the struct atmel_aes_dev.
This callback is run to resume/complete the processing of the crypto
request when woken up by I/O events such as AES interrupts or DMA
completion.

This callback will help implementing the GCM mode support in further
patches.

Signed-off-by: Cyrille Pitchen <cyrille.pitchen@atmel.com>
---
 drivers/crypto/atmel-aes.c | 74 +++++++++++++++++++++++++++++-----------------
 1 file changed, 47 insertions(+), 27 deletions(-)

diff --git a/drivers/crypto/atmel-aes.c b/drivers/crypto/atmel-aes.c
index c10c54ccc606..ac551ee2d624 100644
--- a/drivers/crypto/atmel-aes.c
+++ b/drivers/crypto/atmel-aes.c
@@ -119,6 +119,9 @@ struct atmel_aes_dev {
 	struct crypto_async_request	*areq;
 	struct atmel_aes_base_ctx	*ctx;
 
+	bool			is_async;
+	atmel_aes_fn_t		resume;
+
 	struct device		*dev;
 	struct clk		*iclk;
 	int	irq;
@@ -319,14 +322,17 @@ static inline void atmel_aes_set_mode(struct atmel_aes_dev *dd,
 	dd->flags = (dd->flags & AES_FLAGS_PERSISTENT) | rctx->mode;
 }
 
-static void atmel_aes_finish_req(struct atmel_aes_dev *dd, int err)
+static inline int atmel_aes_complete(struct atmel_aes_dev *dd, int err)
 {
-	struct ablkcipher_request *req = ablkcipher_request_cast(dd->areq);
-
 	clk_disable_unprepare(dd->iclk);
 	dd->flags &= ~AES_FLAGS_BUSY;
 
-	req->base.complete(&req->base, err);
+	if (dd->is_async)
+		dd->areq->complete(dd->areq, err);
+
+	tasklet_schedule(&dd->queue_task);
+
+	return err;
 }
 
 static void atmel_aes_dma_callback(void *data)
@@ -423,6 +429,8 @@ static int atmel_aes_crypt_dma(struct atmel_aes_dev *dd,
 	return 0;
 }
 
+static int atmel_aes_cpu_complete(struct atmel_aes_dev *dd);
+
 static int atmel_aes_crypt_cpu_start(struct atmel_aes_dev *dd)
 {
 	struct ablkcipher_request *req = ablkcipher_request_cast(dd->areq);
@@ -455,9 +463,12 @@ static int atmel_aes_crypt_cpu_start(struct atmel_aes_dev *dd)
 	atmel_aes_write_n(dd, AES_IDATAR(0), (u32 *) dd->buf_in,
 				dd->bufcnt >> 2);
 
-	return 0;
+	dd->resume = atmel_aes_cpu_complete;
+	return -EINPROGRESS;
 }
 
+static int atmel_aes_dma_complete(struct atmel_aes_dev *dd);
+
 static int atmel_aes_crypt_dma_start(struct atmel_aes_dev *dd)
 {
 	int err, fast = 0, in, out;
@@ -524,7 +535,8 @@ static int atmel_aes_crypt_dma_start(struct atmel_aes_dev *dd)
 		dma_unmap_sg(dd->dev, dd->out_sg, 1, DMA_TO_DEVICE);
 	}
 
-	return err;
+	dd->resume = atmel_aes_dma_complete;
+	return err ? : -EINPROGRESS;
 }
 
 static void atmel_aes_write_ctrl(struct atmel_aes_dev *dd, bool use_dma,
@@ -590,9 +602,10 @@ static int atmel_aes_handle_queue(struct atmel_aes_dev *dd,
 
 	dd->areq = areq;
 	dd->ctx = ctx;
+	dd->is_async = (areq != new_areq);
 
 	err = ctx->start(dd);
-	return (areq != new_areq) ? ret : err;
+	return (dd->is_async) ? ret : err;
 }
 
 static int atmel_aes_start(struct atmel_aes_dev *dd)
@@ -621,10 +634,9 @@ static int atmel_aes_start(struct atmel_aes_dev *dd)
 		else
 			err = atmel_aes_crypt_cpu_start(dd);
 	}
-	if (err) {
+	if (err && err != -EINPROGRESS) {
 		/* aes_task will not finish it, so do it here */
-		atmel_aes_finish_req(dd, err);
-		tasklet_schedule(&dd->queue_task);
+		return atmel_aes_complete(dd, err);
 	}
 
 	return -EINPROGRESS;
@@ -1149,20 +1161,14 @@ static void atmel_aes_queue_task(unsigned long data)
 static void atmel_aes_done_task(unsigned long data)
 {
 	struct atmel_aes_dev *dd = (struct atmel_aes_dev *) data;
-	int err;
-
-	if (!(dd->flags & AES_FLAGS_DMA)) {
-		atmel_aes_read_n(dd, AES_ODATAR(0), (u32 *) dd->buf_out,
-				dd->bufcnt >> 2);
 
-		if (sg_copy_from_buffer(dd->out_sg, dd->nb_out_sg,
-			dd->buf_out, dd->bufcnt))
-			err = 0;
-		else
-			err = -EINVAL;
+	dd->is_async = true;
+	(void)dd->resume(dd);
+}
 
-		goto cpu_end;
-	}
+static int atmel_aes_dma_complete(struct atmel_aes_dev *dd)
+{
+	int err;
 
 	err = atmel_aes_crypt_dma_stop(dd);
 
@@ -1177,13 +1183,27 @@ static void atmel_aes_done_task(unsigned long data)
 		}
 		if (!err)
 			err = atmel_aes_crypt_dma_start(dd);
-		if (!err)
-			return; /* DMA started. Not fininishing. */
+		if (!err || err == -EINPROGRESS)
+			return -EINPROGRESS; /* DMA started. Not fininishing. */
 	}
 
-cpu_end:
-	atmel_aes_finish_req(dd, err);
-	atmel_aes_handle_queue(dd, NULL);
+	return atmel_aes_complete(dd, err);
+}
+
+static int atmel_aes_cpu_complete(struct atmel_aes_dev *dd)
+{
+	int err;
+
+	atmel_aes_read_n(dd, AES_ODATAR(0), (u32 *) dd->buf_out,
+			 dd->bufcnt >> 2);
+
+	if (sg_copy_from_buffer(dd->out_sg, dd->nb_out_sg,
+				dd->buf_out, dd->bufcnt))
+		err = 0;
+	else
+		err = -EINVAL;
+
+	return atmel_aes_complete(dd, err);
 }
 
 static irqreturn_t atmel_aes_irq(int irq, void *dev_id)
-- 
1.8.2.2


  parent reply	other threads:[~2015-12-17 16:52 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-17 16:48 [PATCH 00/24] crypto: atmel-aes: global rework of the driver Cyrille Pitchen
2015-12-17 16:48 ` [PATCH 01/24] crypto: atmel-aes: add new version Cyrille Pitchen
2015-12-17 16:48 ` [PATCH 02/24] crypto: atmel-aes: constify value argument of atmel_aes_write_n() Cyrille Pitchen
2015-12-17 16:48 ` [PATCH 03/24] crypto: atmel-aes: change algorithm priorities Cyrille Pitchen
2015-12-17 16:48 ` [PATCH 04/24] crypto: atmel-aes: fix unregistration order of crypto algorithms Cyrille Pitchen
2015-12-17 16:48 ` [PATCH 05/24] crypto: atmel-aes: remove unused header includes Cyrille Pitchen
2015-12-17 16:48 ` [PATCH 06/24] crypto: atmel-aes: propagate error from atmel_aes_hw_version_init() Cyrille Pitchen
2015-12-17 16:48 ` [PATCH 07/24] crypto: atmel-aes: change atmel_aes_write_ctrl() signature Cyrille Pitchen
2015-12-17 16:48 ` [PATCH 08/24] crypto: atmel-aes: make crypto request queue management more generic Cyrille Pitchen
2015-12-17 16:48 ` [PATCH 09/24] crypto: atmel-aes: remove useless write in the Control Register Cyrille Pitchen
2015-12-17 16:48 ` [PATCH 10/24] crypto: atmel-aes: simplify the configuration of the AES IP Cyrille Pitchen
2015-12-17 16:48 ` Cyrille Pitchen [this message]
2015-12-17 16:48 ` [PATCH 12/24] crypto: atmel-aes: remove unused 'err' member of struct atmel_aes_dev Cyrille Pitchen
2015-12-17 16:48 ` [PATCH 13/24] crypto: atmel-aes: reduce latency of DMA completion Cyrille Pitchen
2015-12-17 16:48 ` [PATCH 14/24] crypto: atmel-aes: remove useless AES_FLAGS_DMA flag Cyrille Pitchen
2015-12-17 16:48 ` [PATCH 15/24] crypto: atmel-aes: fix atmel_aes_remove() Cyrille Pitchen
2015-12-17 17:13 ` [PATCH 16/24] crypto: atmel-aes: improve performances of data transfer Cyrille Pitchen
2015-12-17 17:13 ` [PATCH 17/24] crypto: atmel-aes: use SIZE_IN_WORDS() helper macro Cyrille Pitchen
2015-12-17 17:13 ` [PATCH 18/24] crypto: atmel-aes: fix typo and indentation Cyrille Pitchen
2015-12-17 17:13 ` [PATCH 19/24] crypto: atmel-aes: create sections to regroup functions by usage Cyrille Pitchen
2015-12-17 17:13 ` [PATCH 20/24] crypto: atmel-aes: fix atmel-ctr-aes driver for RFC 3686 Cyrille Pitchen
2015-12-17 17:13 ` [PATCH 21/24] crypto: atmel-aes: fix the counter overflow in CTR mode Cyrille Pitchen
2015-12-17 17:13 ` [PATCH 22/24] crypto: atmel-aes: change the DMA threshold Cyrille Pitchen
2015-12-17 17:13 ` [PATCH 23/24] crypto: atmel-aes: add support to GCM mode Cyrille Pitchen
2015-12-17 17:13 ` [PATCH 24/24] crypto: atmel-aes: add debug facilities to monitor register accesses Cyrille Pitchen
2015-12-23 10:24 ` [PATCH 00/24] crypto: atmel-aes: global rework of the driver Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1237ced97e6c1b8f676c8e8d68899a503a35f260.1450366831.git.cyrille.pitchen@atmel.com \
    --to=cyrille.pitchen@atmel.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicolas.ferre@atmel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®