From: Phil Sutter Subject: [PATCH 07/13] mv_cesa: have DMA engine copy back the digest result Date: Tue, 12 Jun 2012 19:17:21 +0200 Message-ID: <1339521447-17721-8-git-send-email-phil.sutter@viprinet.com> References: <20120612113941.GA14757@gondor.apana.org.au> <1339521447-17721-1-git-send-email-phil.sutter@viprinet.com> Cc: Herbert Xu To: linux-crypto@vger.kernel.org Return-path: Received: from zimbra.vipri.net ([89.207.250.15]:58604 "EHLO zimbra.vipri.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753659Ab2FLRRo (ORCPT ); Tue, 12 Jun 2012 13:17:44 -0400 In-Reply-To: <1339521447-17721-1-git-send-email-phil.sutter@viprinet.com> Sender: linux-crypto-owner@vger.kernel.org List-ID: Signed-off-by: Phil Sutter --- drivers/crypto/mv_cesa.c | 40 +++++++++++++++++++++++++++++----------- 1 files changed, 29 insertions(+), 11 deletions(-) diff --git a/drivers/crypto/mv_cesa.c b/drivers/crypto/mv_cesa.c index cdbc82e..4b08137 100644 --- a/drivers/crypto/mv_cesa.c +++ b/drivers/crypto/mv_cesa.c @@ -161,8 +161,10 @@ struct mv_req_hash_ctx { int first_hash; /* marks that we don't have previous state */ int last_chunk; /* marks that this is the 'final' request */ int extra_bytes; /* unprocessed bytes in buffer */ + int digestsize; /* size of the digest */ enum hash_op op; int count_add; + dma_addr_t result_dma; }; static void mv_completion_timer_callback(unsigned long unused) @@ -499,9 +501,17 @@ static void mv_init_hash_config(struct ahash_request *req) mv_dma_separator(); - /* XXX: this fixes some ugly register fuckup bug in the tdma engine - * (no need to sync since the data is ignored anyway) */ - mv_dma_memcpy(cpg->sa_sram_dma, cpg->sram_phys + SRAM_CONFIG, 1); + if (req->result) { + req_ctx->result_dma = dma_map_single(cpg->dev, req->result, + req_ctx->digestsize, DMA_FROM_DEVICE); + mv_dma_memcpy(req_ctx->result_dma, + cpg->sram_phys + SRAM_DIGEST_BUF, req_ctx->digestsize); + } else { + /* XXX: this fixes some ugly register fuckup bug in the tdma engine + * (no need to sync since the data is ignored anyway) */ + mv_dma_memcpy(cpg->sa_sram_dma, + cpg->sram_phys + SRAM_CONFIG, 1); + } /* GO */ mv_setup_timer(); @@ -548,9 +558,17 @@ static void mv_update_hash_config(void) mv_dma_separator(); - /* XXX: this fixes some ugly register fuckup bug in the tdma engine - * (no need to sync since the data is ignored anyway) */ - mv_dma_memcpy(cpg->sa_sram_dma, cpg->sram_phys + SRAM_CONFIG, 1); + if (req->result) { + req_ctx->result_dma = dma_map_single(cpg->dev, req->result, + req_ctx->digestsize, DMA_FROM_DEVICE); + mv_dma_memcpy(req_ctx->result_dma, + cpg->sram_phys + SRAM_DIGEST_BUF, req_ctx->digestsize); + } else { + /* XXX: this fixes some ugly register fuckup bug in the tdma engine + * (no need to sync since the data is ignored anyway) */ + mv_dma_memcpy(cpg->sa_sram_dma, + cpg->sram_phys + SRAM_CONFIG, 1); + } /* GO */ mv_setup_timer(); @@ -617,11 +635,10 @@ static void mv_hash_algo_completion(void) copy_src_to_buf(&cpg->p, ctx->buffer, ctx->extra_bytes); if (likely(ctx->last_chunk)) { - if (likely(ctx->count <= MAX_HW_HASH_SIZE)) { - memcpy(req->result, cpg->sram + SRAM_DIGEST_BUF, - crypto_ahash_digestsize(crypto_ahash_reqtfm - (req))); - } else { + dma_unmap_single(cpg->dev, ctx->result_dma, + ctx->digestsize, DMA_FROM_DEVICE); + + if (unlikely(ctx->count > MAX_HW_HASH_SIZE)) { mv_save_digest_state(ctx); mv_hash_final_fallback(req); } @@ -719,6 +736,7 @@ static void mv_start_new_hash_req(struct ahash_request *req) memset(p, 0, sizeof(struct req_progress)); hw_bytes = req->nbytes + ctx->extra_bytes; old_extra_bytes = ctx->extra_bytes; + ctx->digestsize = crypto_ahash_digestsize(crypto_ahash_reqtfm(req)); ctx->extra_bytes = hw_bytes % SHA1_BLOCK_SIZE; if (ctx->extra_bytes != 0 -- 1.7.3.4