Commit 0d4a8266 authored by Ryder Lee's avatar Ryder Lee Committed by Herbert Xu

crypto: mediatek - add queue_task tasklet

This patch adds 'queue_task' to dequeue crypto requset. This will help to
avoid directly calling mtk_aes_handle_queue() / mtk_sha_handle_queue()
from done tasklet or error handler.

In order to avoid confusion, the new code properly renames DMA completion
"task" to "done_task".
Signed-off-by: default avatarRyder Lee <ryder.lee@mediatek.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 3d21c41f
...@@ -533,7 +533,8 @@ static int mtk_aes_complete(struct mtk_cryp *cryp, struct mtk_aes_rec *aes) ...@@ -533,7 +533,8 @@ static int mtk_aes_complete(struct mtk_cryp *cryp, struct mtk_aes_rec *aes)
aes->areq->complete(aes->areq, 0); aes->areq->complete(aes->areq, 0);
/* Handle new request */ /* Handle new request */
return mtk_aes_handle_queue(cryp, aes->id, NULL); tasklet_schedule(&aes->queue_task);
return 0;
} }
static int mtk_aes_start(struct mtk_cryp *cryp, struct mtk_aes_rec *aes) static int mtk_aes_start(struct mtk_cryp *cryp, struct mtk_aes_rec *aes)
...@@ -1094,6 +1095,13 @@ static struct aead_alg aes_gcm_alg = { ...@@ -1094,6 +1095,13 @@ static struct aead_alg aes_gcm_alg = {
}, },
}; };
static void mtk_aes_queue_task(unsigned long data)
{
struct mtk_aes_rec *aes = (struct mtk_aes_rec *)data;
mtk_aes_handle_queue(aes->cryp, aes->id, NULL);
}
static void mtk_aes_done_task(unsigned long data) static void mtk_aes_done_task(unsigned long data)
{ {
struct mtk_aes_rec *aes = (struct mtk_aes_rec *)data; struct mtk_aes_rec *aes = (struct mtk_aes_rec *)data;
...@@ -1116,7 +1124,7 @@ static irqreturn_t mtk_aes_irq(int irq, void *dev_id) ...@@ -1116,7 +1124,7 @@ static irqreturn_t mtk_aes_irq(int irq, void *dev_id)
mtk_aes_write(cryp, RDR_THRESH(aes->id), mtk_aes_write(cryp, RDR_THRESH(aes->id),
MTK_RDR_PROC_THRESH | MTK_RDR_PROC_MODE); MTK_RDR_PROC_THRESH | MTK_RDR_PROC_MODE);
tasklet_schedule(&aes->task); tasklet_schedule(&aes->done_task);
} else { } else {
dev_warn(cryp->dev, "AES interrupt when no active requests.\n"); dev_warn(cryp->dev, "AES interrupt when no active requests.\n");
} }
...@@ -1149,7 +1157,9 @@ static int mtk_aes_record_init(struct mtk_cryp *cryp) ...@@ -1149,7 +1157,9 @@ static int mtk_aes_record_init(struct mtk_cryp *cryp)
spin_lock_init(&aes[i]->lock); spin_lock_init(&aes[i]->lock);
crypto_init_queue(&aes[i]->queue, AES_QUEUE_SIZE); crypto_init_queue(&aes[i]->queue, AES_QUEUE_SIZE);
tasklet_init(&aes[i]->task, mtk_aes_done_task, tasklet_init(&aes[i]->queue_task, mtk_aes_queue_task,
(unsigned long)aes[i]);
tasklet_init(&aes[i]->done_task, mtk_aes_done_task,
(unsigned long)aes[i]); (unsigned long)aes[i]);
} }
...@@ -1173,7 +1183,9 @@ static void mtk_aes_record_free(struct mtk_cryp *cryp) ...@@ -1173,7 +1183,9 @@ static void mtk_aes_record_free(struct mtk_cryp *cryp)
int i; int i;
for (i = 0; i < MTK_REC_NUM; i++) { for (i = 0; i < MTK_REC_NUM; i++) {
tasklet_kill(&cryp->aes[i]->task); tasklet_kill(&cryp->aes[i]->done_task);
tasklet_kill(&cryp->aes[i]->queue_task);
free_page((unsigned long)cryp->aes[i]->buf); free_page((unsigned long)cryp->aes[i]->buf);
kfree(cryp->aes[i]); kfree(cryp->aes[i]);
} }
......
...@@ -128,7 +128,8 @@ typedef int (*mtk_aes_fn)(struct mtk_cryp *cryp, struct mtk_aes_rec *aes); ...@@ -128,7 +128,8 @@ typedef int (*mtk_aes_fn)(struct mtk_cryp *cryp, struct mtk_aes_rec *aes);
* @cryp: pointer to Cryptographic device * @cryp: pointer to Cryptographic device
* @queue: crypto request queue * @queue: crypto request queue
* @areq: pointer to async request * @areq: pointer to async request
* @task: the tasklet is use in AES interrupt * @done_task: the tasklet is use in AES interrupt
* @queue_task: the tasklet is used to dequeue request
* @ctx: pointer to current context * @ctx: pointer to current context
* @src: the structure that holds source sg list info * @src: the structure that holds source sg list info
* @dst: the structure that holds destination sg list info * @dst: the structure that holds destination sg list info
...@@ -147,7 +148,8 @@ struct mtk_aes_rec { ...@@ -147,7 +148,8 @@ struct mtk_aes_rec {
struct mtk_cryp *cryp; struct mtk_cryp *cryp;
struct crypto_queue queue; struct crypto_queue queue;
struct crypto_async_request *areq; struct crypto_async_request *areq;
struct tasklet_struct task; struct tasklet_struct done_task;
struct tasklet_struct queue_task;
struct mtk_aes_base_ctx *ctx; struct mtk_aes_base_ctx *ctx;
struct mtk_aes_dma src; struct mtk_aes_dma src;
struct mtk_aes_dma dst; struct mtk_aes_dma dst;
...@@ -171,7 +173,8 @@ struct mtk_aes_rec { ...@@ -171,7 +173,8 @@ struct mtk_aes_rec {
* @cryp: pointer to Cryptographic device * @cryp: pointer to Cryptographic device
* @queue: crypto request queue * @queue: crypto request queue
* @req: pointer to ahash request * @req: pointer to ahash request
* @task: the tasklet is use in SHA interrupt * @done_task: the tasklet is use in SHA interrupt
* @queue_task: the tasklet is used to dequeue request
* @id: the current use of ring * @id: the current use of ring
* @flags: it's describing SHA operation state * @flags: it's describing SHA operation state
* @lock: the async queue lock * @lock: the async queue lock
...@@ -182,7 +185,8 @@ struct mtk_sha_rec { ...@@ -182,7 +185,8 @@ struct mtk_sha_rec {
struct mtk_cryp *cryp; struct mtk_cryp *cryp;
struct crypto_queue queue; struct crypto_queue queue;
struct ahash_request *req; struct ahash_request *req;
struct tasklet_struct task; struct tasklet_struct done_task;
struct tasklet_struct queue_task;
u8 id; u8 id;
unsigned long flags; unsigned long flags;
......
...@@ -661,7 +661,7 @@ static void mtk_sha_finish_req(struct mtk_cryp *cryp, ...@@ -661,7 +661,7 @@ static void mtk_sha_finish_req(struct mtk_cryp *cryp,
sha->req->base.complete(&sha->req->base, err); sha->req->base.complete(&sha->req->base, err);
/* Handle new request */ /* Handle new request */
mtk_sha_handle_queue(cryp, sha->id - MTK_RING2, NULL); tasklet_schedule(&sha->queue_task);
} }
static int mtk_sha_handle_queue(struct mtk_cryp *cryp, u8 id, static int mtk_sha_handle_queue(struct mtk_cryp *cryp, u8 id,
...@@ -1183,6 +1183,13 @@ static struct ahash_alg algs_sha384_sha512[] = { ...@@ -1183,6 +1183,13 @@ static struct ahash_alg algs_sha384_sha512[] = {
}, },
}; };
static void mtk_sha_queue_task(unsigned long data)
{
struct mtk_sha_rec *sha = (struct mtk_sha_rec *)data;
mtk_sha_handle_queue(sha->cryp, sha->id - MTK_RING2, NULL);
}
static void mtk_sha_done_task(unsigned long data) static void mtk_sha_done_task(unsigned long data)
{ {
struct mtk_sha_rec *sha = (struct mtk_sha_rec *)data; struct mtk_sha_rec *sha = (struct mtk_sha_rec *)data;
...@@ -1205,7 +1212,7 @@ static irqreturn_t mtk_sha_irq(int irq, void *dev_id) ...@@ -1205,7 +1212,7 @@ static irqreturn_t mtk_sha_irq(int irq, void *dev_id)
mtk_sha_write(cryp, RDR_THRESH(sha->id), mtk_sha_write(cryp, RDR_THRESH(sha->id),
MTK_RDR_PROC_THRESH | MTK_RDR_PROC_MODE); MTK_RDR_PROC_THRESH | MTK_RDR_PROC_MODE);
tasklet_schedule(&sha->task); tasklet_schedule(&sha->done_task);
} else { } else {
dev_warn(cryp->dev, "SHA interrupt when no active requests.\n"); dev_warn(cryp->dev, "SHA interrupt when no active requests.\n");
} }
...@@ -1231,7 +1238,9 @@ static int mtk_sha_record_init(struct mtk_cryp *cryp) ...@@ -1231,7 +1238,9 @@ static int mtk_sha_record_init(struct mtk_cryp *cryp)
spin_lock_init(&sha[i]->lock); spin_lock_init(&sha[i]->lock);
crypto_init_queue(&sha[i]->queue, SHA_QUEUE_SIZE); crypto_init_queue(&sha[i]->queue, SHA_QUEUE_SIZE);
tasklet_init(&sha[i]->task, mtk_sha_done_task, tasklet_init(&sha[i]->queue_task, mtk_sha_queue_task,
(unsigned long)sha[i]);
tasklet_init(&sha[i]->done_task, mtk_sha_done_task,
(unsigned long)sha[i]); (unsigned long)sha[i]);
} }
...@@ -1254,7 +1263,9 @@ static void mtk_sha_record_free(struct mtk_cryp *cryp) ...@@ -1254,7 +1263,9 @@ static void mtk_sha_record_free(struct mtk_cryp *cryp)
int i; int i;
for (i = 0; i < MTK_REC_NUM; i++) { for (i = 0; i < MTK_REC_NUM; i++) {
tasklet_kill(&cryp->sha[i]->task); tasklet_kill(&cryp->sha[i]->done_task);
tasklet_kill(&cryp->sha[i]->queue_task);
kfree(cryp->sha[i]); kfree(cryp->sha[i]);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment