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: 9263363 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 A1ED66048B for ; Thu, 4 Aug 2016 10:32:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92E6828333 for ; Thu, 4 Aug 2016 10:32:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 871A2283AC; Thu, 4 Aug 2016 10:32:19 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EAC1528333 for ; Thu, 4 Aug 2016 10:32:18 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bVFvJ-0002Iu-SW; Thu, 04 Aug 2016 10:30:46 +0000 Received: from comal.ext.ti.com ([198.47.26.152]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bVFu9-0000CX-GK for linux-arm-kernel@lists.infradead.org; Thu, 04 Aug 2016 10:29:42 +0000 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: , , , , , 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160804_032933_880348_469404FB X-CRM114-Status: GOOD ( 13.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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,