From patchwork Fri Aug 18 09:19:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabien DESSENNE X-Patchwork-Id: 9908147 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 B013660382 for ; Fri, 18 Aug 2017 09:21:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A106C283BD for ; Fri, 18 Aug 2017 09:21:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9362E28C7C; Fri, 18 Aug 2017 09:21:54 +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=-2.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0149C283BD for ; Fri, 18 Aug 2017 09:21:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sPHEOw6e6+vy1yAx6+DZkGGzH3kAsBlPr0eAt56AJpQ=; b=A92bLDCY67LX6G OxPSxQYlE0ukr8f9Z4ILQiBIEuDDrtnePvbr2utRNKRNoctbaLG7fLhNrhuc9KZ0K1fJ+fgyeUflx NWhSOibT1n2vUtAxhYEoAb057Z8N7vjVUX6f+4lNVONf2+KF6VniuMZmTV3bVbzZtm/H39AXJk56X AU6GmgGw4BjKfqfRwHEFblSVXGdH0eP/dEApxAtCcvxpjW3Ul88EsMcjK87EQIuGhS+Du9D7fzlL5 PVirdjzU3tTd1w3zU33pI3c5wE+pmjMSFx4teu/8/g0YLKwSb7UBwSGVCF4lJq+lMglw8B3HbDNYt uWrpS8jnR2sHgKaGk3OA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1didTQ-0005pH-8X; Fri, 18 Aug 2017 09:21:48 +0000 Received: from mx08-00178001.pphosted.com ([91.207.212.93] helo=mx07-00178001.pphosted.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1didRp-0003J4-Vn for linux-arm-kernel@lists.infradead.org; Fri, 18 Aug 2017 09:21:12 +0000 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v7I9E8mm029892; Fri, 18 Aug 2017 11:19:29 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-.pphosted.com with ESMTP id 2cdg5dbtn1-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 18 Aug 2017 11:19:29 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 29A6C31; Fri, 18 Aug 2017 09:19:28 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas24.st.com [10.75.90.94]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id DA0CE14EF; Fri, 18 Aug 2017 09:19:27 +0000 (GMT) Received: from SAFEX1HUBCAS21.st.com (10.75.90.45) by Safex1hubcas24.st.com (10.75.90.94) with Microsoft SMTP Server (TLS) id 14.3.352.0; Fri, 18 Aug 2017 11:19:27 +0200 Received: from localhost (10.201.23.25) by Webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.339.0; Fri, 18 Aug 2017 11:19:27 +0200 From: Fabien Dessenne To: Herbert Xu , "David S . Miller" , Rob Herring , Mark Rutland , Maxime Coquelin , Alexandre Torgue , , , , Subject: [PATCH v3 1/3] crypto: engine - permit to enqueue aead_request Date: Fri, 18 Aug 2017 11:19:04 +0200 Message-ID: <1503047946-27799-2-git-send-email-fabien.dessenne@st.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503047946-27799-1-git-send-email-fabien.dessenne@st.com> References: <1503047946-27799-1-git-send-email-fabien.dessenne@st.com> MIME-Version: 1.0 X-Originating-IP: [10.201.23.25] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-08-18_02:, , signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170818_022011_041373_DD84E60B X-CRM114-Status: GOOD ( 14.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lionel Debieve , Benjamin Gaignard , Ludovic Barre 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 The current crypto engine allows ablkcipher_request and ahash_request to be enqueued. Extend this to aead_request. Signed-off-by: Fabien Dessenne --- crypto/crypto_engine.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++ include/crypto/engine.h | 16 ++++++++ 2 files changed, 117 insertions(+) diff --git a/crypto/crypto_engine.c b/crypto/crypto_engine.c index 61e7c4e..3cdf051 100644 --- a/crypto/crypto_engine.c +++ b/crypto/crypto_engine.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include "internal.h" @@ -35,6 +36,7 @@ static void crypto_pump_requests(struct crypto_engine *engine, { struct crypto_async_request *async_req, *backlog; struct ahash_request *hreq; + struct aead_request *areq; struct ablkcipher_request *breq; unsigned long flags; bool was_busy = false; @@ -122,6 +124,22 @@ static void crypto_pump_requests(struct crypto_engine *engine, goto req_err; } return; + case CRYPTO_ALG_TYPE_AEAD: + areq = aead_request_cast(engine->cur_req); + if (engine->prepare_aead_request) { + ret = engine->prepare_aead_request(engine, areq); + if (ret) { + pr_err("failed to prepare request: %d\n", ret); + goto req_err; + } + engine->cur_req_prepared = true; + } + ret = engine->aead_one_request(engine, areq); + if (ret) { + pr_err("failed to do aead one request from queue\n"); + goto req_err; + } + return; case CRYPTO_ALG_TYPE_ABLKCIPHER: breq = ablkcipher_request_cast(engine->cur_req); if (engine->prepare_cipher_request) { @@ -150,6 +168,10 @@ static void crypto_pump_requests(struct crypto_engine *engine, hreq = ahash_request_cast(engine->cur_req); crypto_finalize_hash_request(engine, hreq, ret); break; + case CRYPTO_ALG_TYPE_AEAD: + areq = aead_request_cast(engine->cur_req); + crypto_finalize_aead_request(engine, areq, ret); + break; case CRYPTO_ALG_TYPE_ABLKCIPHER: breq = ablkcipher_request_cast(engine->cur_req); crypto_finalize_cipher_request(engine, breq, ret); @@ -255,6 +277,48 @@ int crypto_transfer_hash_request_to_engine(struct crypto_engine *engine, EXPORT_SYMBOL_GPL(crypto_transfer_hash_request_to_engine); /** + * crypto_transfer_aead_request - transfer the new request into the + * enginequeue + * @engine: the hardware engine + * @req: the request need to be listed into the engine queue + */ +int crypto_transfer_aead_request(struct crypto_engine *engine, + struct aead_request *req, bool need_pump) +{ + unsigned long flags; + int ret; + + spin_lock_irqsave(&engine->queue_lock, flags); + + if (!engine->running) { + spin_unlock_irqrestore(&engine->queue_lock, flags); + return -ESHUTDOWN; + } + + ret = aead_enqueue_request((struct aead_queue *)&engine->queue, req); + + if (!engine->busy && need_pump) + kthread_queue_work(engine->kworker, &engine->pump_requests); + + spin_unlock_irqrestore(&engine->queue_lock, flags); + return ret; +} +EXPORT_SYMBOL_GPL(crypto_transfer_aead_request); + +/** + * crypto_transfer_aead_request_to_engine - transfer one request to list + * into the engine queue + * @engine: the hardware engine + * @req: the request need to be listed into the engine queue + */ +int crypto_transfer_aead_request_to_engine(struct crypto_engine *engine, + struct aead_request *req) +{ + return crypto_transfer_aead_request(engine, req, true); +} +EXPORT_SYMBOL_GPL(crypto_transfer_aead_request_to_engine); + +/** * crypto_finalize_cipher_request - finalize one request if the request is done * @engine: the hardware engine * @req: the request need to be finalized @@ -329,6 +393,43 @@ void crypto_finalize_hash_request(struct crypto_engine *engine, EXPORT_SYMBOL_GPL(crypto_finalize_hash_request); /** + * crypto_finalize_aead_request - finalize one request if the request is done + * @engine: the hardware engine + * @req: the request need to be finalized + * @err: error number + */ +void crypto_finalize_aead_request(struct crypto_engine *engine, + struct aead_request *req, int err) +{ + unsigned long flags; + bool finalize_cur_req = false; + int ret; + + spin_lock_irqsave(&engine->queue_lock, flags); + if (engine->cur_req == &req->base) + finalize_cur_req = true; + spin_unlock_irqrestore(&engine->queue_lock, flags); + + if (finalize_cur_req) { + if (engine->cur_req_prepared && + engine->unprepare_aead_request) { + ret = engine->unprepare_aead_request(engine, req); + if (ret) + pr_err("failed to unprepare request\n"); + } + spin_lock_irqsave(&engine->queue_lock, flags); + engine->cur_req = NULL; + engine->cur_req_prepared = false; + spin_unlock_irqrestore(&engine->queue_lock, flags); + } + + req->base.complete(&req->base, err); + + kthread_queue_work(engine->kworker, &engine->pump_requests); +} +EXPORT_SYMBOL_GPL(crypto_finalize_aead_request); + +/** * crypto_engine_start - start the hardware engine * @engine: the hardware engine need to be started * diff --git a/include/crypto/engine.h b/include/crypto/engine.h index dd04c16..9ee1722 100644 --- a/include/crypto/engine.h +++ b/include/crypto/engine.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -43,6 +44,9 @@ * @prepare_hash_request: do some prepare if need before handle the current request * @unprepare_hash_request: undo any work done by prepare_hash_request() * @hash_one_request: do hash for current request + * @prepare_aead_request: do some prepare if need before handle the current request + * @unprepare_aead_request: undo any work done by prepare_aead_request() + * @aead_one_request: do aead for current request * @kworker: kthread worker struct for request pump * @pump_requests: work struct for scheduling work to the request pump * @priv_data: the engine private data @@ -73,10 +77,16 @@ struct crypto_engine { struct ahash_request *req); int (*unprepare_hash_request)(struct crypto_engine *engine, struct ahash_request *req); + int (*prepare_aead_request)(struct crypto_engine *engine, + struct aead_request *req); + int (*unprepare_aead_request)(struct crypto_engine *engine, + struct aead_request *req); int (*cipher_one_request)(struct crypto_engine *engine, struct ablkcipher_request *req); int (*hash_one_request)(struct crypto_engine *engine, struct ahash_request *req); + int (*aead_one_request)(struct crypto_engine *engine, + struct aead_request *req); struct kthread_worker *kworker; struct kthread_work pump_requests; @@ -94,10 +104,16 @@ int crypto_transfer_hash_request(struct crypto_engine *engine, struct ahash_request *req, bool need_pump); int crypto_transfer_hash_request_to_engine(struct crypto_engine *engine, struct ahash_request *req); +int crypto_transfer_aead_request(struct crypto_engine *engine, + struct aead_request *req, bool need_pump); +int crypto_transfer_aead_request_to_engine(struct crypto_engine *engine, + struct aead_request *req); void crypto_finalize_cipher_request(struct crypto_engine *engine, struct ablkcipher_request *req, int err); void crypto_finalize_hash_request(struct crypto_engine *engine, struct ahash_request *req, int err); +void crypto_finalize_aead_request(struct crypto_engine *engine, + struct aead_request *req, int err); int crypto_engine_start(struct crypto_engine *engine); int crypto_engine_stop(struct crypto_engine *engine); struct crypto_engine *crypto_engine_alloc_init(struct device *dev, bool rt);