From patchwork Thu Aug 4 10:28:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tero Kristo X-Patchwork-Id: 9263345 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E8A086048B for ; Thu, 4 Aug 2016 10:31:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA2DE28333 for ; Thu, 4 Aug 2016 10:31:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEF1F283AC; Thu, 4 Aug 2016 10:31:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F8B128333 for ; Thu, 4 Aug 2016 10:31:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932152AbcHDKa1 (ORCPT ); Thu, 4 Aug 2016 06:30:27 -0400 Received: from comal.ext.ti.com ([198.47.26.152]:52950 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753631AbcHDKaV (ORCPT ); Thu, 4 Aug 2016 06:30:21 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id u74AOuqo030167; Thu, 4 Aug 2016 05:24:56 -0500 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id u74AT56P015101; Thu, 4 Aug 2016 05:29:05 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.294.0; Thu, 4 Aug 2016 05:29:04 -0500 Received: from gomoku.home (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id u74ASu7Z032023; Thu, 4 Aug 2016 05:29:03 -0500 From: Tero Kristo To: , , , , , CC: Subject: [PATCHv3 02/11] crypto: omap-sham: add support for flushing the buffer Date: Thu, 4 Aug 2016 13:28:37 +0300 Message-ID: <1470306526-27219-3-git-send-email-t-kristo@ti.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1470306526-27219-1-git-send-email-t-kristo@ti.com> References: <1470306526-27219-1-git-send-email-t-kristo@ti.com> MIME-Version: 1.0 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This flushes any full blocks of data from the data buffer. Required for implementing the export/import APIs for the driver, as the flush allows saving a much smaller context; basically only one block of buffer is required. Signed-off-by: Tero Kristo --- drivers/crypto/omap-sham.c | 60 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/drivers/crypto/omap-sham.c b/drivers/crypto/omap-sham.c index fd50005..6e53944 100644 --- a/drivers/crypto/omap-sham.c +++ b/drivers/crypto/omap-sham.c @@ -112,6 +112,7 @@ #define FLAGS_DMA_READY 6 #define FLAGS_AUTO_XOR 7 #define FLAGS_BE32_SHA1 8 +#define FLAGS_FLUSH 9 /* context flags */ #define FLAGS_FINUP 16 #define FLAGS_SG 17 @@ -996,15 +997,16 @@ static void omap_sham_finish_req(struct ahash_request *req, int err) ctx->flags |= BIT(FLAGS_ERROR); } - /* atomic operation is not needed here */ - dd->flags &= ~(BIT(FLAGS_BUSY) | BIT(FLAGS_FINAL) | BIT(FLAGS_CPU) | - BIT(FLAGS_DMA_READY) | BIT(FLAGS_OUTPUT_READY)); - pm_runtime_mark_last_busy(dd->dev); pm_runtime_put_autosuspend(dd->dev); - if (req->base.complete) + if (!test_bit(FLAGS_FLUSH, &dd->flags) && req->base.complete) req->base.complete(&req->base, err); + + /* atomic operation is not needed here */ + dd->flags &= ~(BIT(FLAGS_BUSY) | BIT(FLAGS_FINAL) | BIT(FLAGS_CPU) | + BIT(FLAGS_DMA_READY) | BIT(FLAGS_OUTPUT_READY) | + BIT(FLAGS_FLUSH)); } static int omap_sham_handle_queue(struct omap_sham_dev *dd, @@ -1329,6 +1331,54 @@ static void omap_sham_cra_exit(struct crypto_tfm *tfm) } } +static int omap_sham_flush(struct ahash_request *req) +{ + struct omap_sham_reqctx *rctx = ahash_request_ctx(req); + struct omap_sham_dev *dd = rctx->dd; + int ret, len, bs; + unsigned long flags; + + bs = get_block_size(rctx); + + len = rctx->bufcnt / bs * bs; + + spin_lock_irqsave(&dd->lock, flags); + + if (test_bit(FLAGS_BUSY, &dd->flags)) { + ret = -EINPROGRESS; + goto exit_unlock; + } + + if (!len) { + ret = 0; + goto exit_unlock; + } + + set_bit(FLAGS_BUSY, &dd->flags); + + spin_unlock_irqrestore(&dd->lock, flags); + + rctx->total = 0; + + ret = omap_sham_hw_init(dd); + if (ret) + goto exit_unlock; + + set_bit(FLAGS_FLUSH, &dd->flags); + + ret = omap_sham_xmit_cpu(dd, rctx->buffer, len, 0); + if (ret == -EINPROGRESS) { + memcpy(rctx->buffer, rctx->buffer + len, rctx->bufcnt - len); + rctx->bufcnt -= len; + } + + return ret; + +exit_unlock: + spin_unlock_irqrestore(&dd->lock, flags); + return ret; +} + static struct ahash_alg algs_sha1_md5[] = { { .init = omap_sham_init,