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: 73260 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp1315446qga; Thu, 4 Aug 2016 03:30:35 -0700 (PDT) X-Received: by 10.98.60.217 with SMTP id b86mr125372857pfk.129.1470306628975; Thu, 04 Aug 2016 03:30:28 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g130si14018467pfb.296.2016.08.04.03.30.28; Thu, 04 Aug 2016 03:30:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-omap-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-omap-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757192AbcHDKa1 (ORCPT + 4 others); 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-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org 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(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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,