Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2120934ybc; Sun, 17 Nov 2019 14:32:16 -0800 (PST) X-Google-Smtp-Source: APXvYqyVSAiexmWhjV9e6uUmCN3DBikwEGJOptaF70ipWYaHDgrtFh3uc+SSzNR8gpzV/ZzGPuZ1 X-Received: by 2002:a17:906:1da1:: with SMTP id u1mr21972853ejh.275.1574029936598; Sun, 17 Nov 2019 14:32:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574029936; cv=none; d=google.com; s=arc-20160816; b=eYe9qFzurMBU1vwoU3yccHdzo1V/ilM2aBMI1TFKIb9UiTpIKq/uMnhrP/JQUq2nnm 4jlgv6UvwHnSiJC3Bc9t0VCXBkpRV1rL/AjbPCoc9FPRB+DPdJhM8IembfZWFzE7opA7 oCYXW4OL8rIlycae8FyUlG78qPwgAVk04lSkc/RKEoRxJ9POverPAfurhGY2aJRPg952 5AjLWpWe6SypEBHLZGnTdRVil6ysyQ2HMIQB3wGcBjkJMN/aTFEiC9lrDgsminlc8VZD OJpF15eCSijBHaeSWIaJNI3VyhjH81ZGw1pr5xS20ZRXj3bt3BfU/BHFvYCwljYMGaLq 1JQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=AaKwJDbKSdJI3a0r7DXBcNZXtLuy+K7J/nuN00/ewsk=; b=nJEnCblrafGdXAulqZli0uldJjYJ6laa7ZFH32j6tnJ48+wmWpmElsasf4nS13KxGu 2XY7zhGgKRQKrZzJpAAstiAd1cVTJhYrg60ztfvGBt1Ts79heTcb5vq7v6c0PCCmTUxW JEaECmOC3WHCj3n/aFpR6t3ICjvmhVrWcwW4Lyw75AsZmxc8ifguRg7GRMaR/tfJItaA o0AV+W0/2j6X9w4q1NbHV27+qxtomi9sqAIsUUymy32AEMrwSZWnEgRnhiodADXaJgVq 40jUIZgjkMUmsY3bmRbMRyidKLGL3XhXQWy6w27z7mvkJ2dtEHnT4TeG0Wt2d0N1wG7s bJcg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ce20si10195148ejb.183.2019.11.17.14.31.51; Sun, 17 Nov 2019 14:32:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-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-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726541AbfKQWb2 (ORCPT + 99 others); Sun, 17 Nov 2019 17:31:28 -0500 Received: from inva020.nxp.com ([92.121.34.13]:57022 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726481AbfKQWbJ (ORCPT ); Sun, 17 Nov 2019 17:31:09 -0500 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id D98521A0D11; Sun, 17 Nov 2019 23:31:06 +0100 (CET) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id D689C1A0D0C; Sun, 17 Nov 2019 23:31:06 +0100 (CET) Received: from lorenz.ea.freescale.net (lorenz.ea.freescale.net [10.171.71.5]) by inva024.eu-rdc02.nxp.com (Postfix) with ESMTP id 78C2C202AF; Sun, 17 Nov 2019 23:31:06 +0100 (CET) From: Iuliana Prodan To: Herbert Xu , Horia Geanta , Aymen Sghaier Cc: "David S. Miller" , Tom Lendacky , Gary Hook , linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-imx , Iuliana Prodan Subject: [PATCH 10/12] crypto: caam - add crypto_engine support for AEAD algorithms Date: Mon, 18 Nov 2019 00:30:43 +0200 Message-Id: <1574029845-22796-11-git-send-email-iuliana.prodan@nxp.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1574029845-22796-1-git-send-email-iuliana.prodan@nxp.com> References: <1574029845-22796-1-git-send-email-iuliana.prodan@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Add crypto_engine support for AEAD algorithms, to make use of the engine queue. The requests, with backlog flag, will be listed into crypto-engine queue and processed by CAAM when free. In case the queue is empty, the request is directly sent to CAAM. Signed-off-by: Iuliana Prodan --- drivers/crypto/caam/caamalg.c | 80 +++++++++++++++++++++++++++++++++---------- drivers/crypto/caam/jr.c | 3 ++ 2 files changed, 64 insertions(+), 19 deletions(-) diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c index 23de94d..786713a 100644 --- a/drivers/crypto/caam/caamalg.c +++ b/drivers/crypto/caam/caamalg.c @@ -122,6 +122,12 @@ struct caam_skcipher_req_ctx { void *context); }; +struct caam_aead_req_ctx { + struct aead_edesc *edesc; + void (*aead_op_done)(struct device *jrdev, u32 *desc, u32 err, + void *context); +}; + static int aead_null_set_sh_desc(struct crypto_aead *aead) { struct caam_ctx *ctx = crypto_aead_ctx(aead); @@ -977,12 +983,14 @@ static void aead_crypt_done(struct device *jrdev, u32 *desc, u32 err, { struct caam_jr_request_entry *jrentry = context; struct aead_request *req = aead_request_cast(jrentry->base); + struct caam_aead_req_ctx *rctx = aead_request_ctx(req); + struct caam_drv_private_jr *jrp = dev_get_drvdata(jrdev); struct aead_edesc *edesc; int ecode = 0; dev_dbg(jrdev, "%s %d: err 0x%x\n", __func__, __LINE__, err); - edesc = container_of(desc, struct aead_edesc, hw_desc[0]); + edesc = rctx->edesc; if (err) ecode = caam_jr_strstatus(jrdev, err); @@ -991,7 +999,14 @@ static void aead_crypt_done(struct device *jrdev, u32 *desc, u32 err, kfree(edesc); - aead_request_complete(req, ecode); + /* + * If no backlog flag, the completion of the request is done + * by CAAM, not crypto engine. + */ + if (!jrentry->bklog) + aead_request_complete(req, ecode); + else + crypto_finalize_aead_request(jrp->engine, req, ecode); } static void skcipher_crypt_done(struct device *jrdev, u32 *desc, u32 err, @@ -1287,6 +1302,7 @@ static struct aead_edesc *aead_edesc_alloc(struct aead_request *req, struct crypto_aead *aead = crypto_aead_reqtfm(req); struct caam_ctx *ctx = crypto_aead_ctx(aead); struct device *jrdev = ctx->jrdev; + struct caam_aead_req_ctx *rctx = aead_request_ctx(req); gfp_t flags = (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ? GFP_KERNEL : GFP_ATOMIC; int src_nents, mapped_src_nents, dst_nents = 0, mapped_dst_nents = 0; @@ -1389,6 +1405,9 @@ static struct aead_edesc *aead_edesc_alloc(struct aead_request *req, desc_bytes; edesc->jrentry.base = &req->base; + rctx->edesc = edesc; + rctx->aead_op_done = aead_crypt_done; + *all_contig_ptr = !(mapped_src_nents > 1); sec4_sg_index = 0; @@ -1442,7 +1461,7 @@ static inline int chachapoly_crypt(struct aead_request *req, bool encrypt) 1); ret = caam_jr_enqueue(jrdev, desc, aead_crypt_done, &edesc->jrentry); - if (ret != -EINPROGRESS) { + if ((ret != -EINPROGRESS) && (ret != -EBUSY)) { aead_unmap(jrdev, edesc, req); kfree(edesc); } @@ -1465,7 +1484,6 @@ static inline int aead_crypt(struct aead_request *req, bool encrypt) struct aead_edesc *edesc; struct crypto_aead *aead = crypto_aead_reqtfm(req); struct caam_ctx *ctx = crypto_aead_ctx(aead); - struct caam_jr_request_entry *jrentry; struct device *jrdev = ctx->jrdev; bool all_contig; u32 *desc; @@ -1479,16 +1497,14 @@ static inline int aead_crypt(struct aead_request *req, bool encrypt) /* Create and submit job descriptor */ init_authenc_job(req, edesc, all_contig, encrypt); + desc = edesc->hw_desc; print_hex_dump_debug("aead jobdesc@"__stringify(__LINE__)": ", - DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc, - desc_bytes(edesc->hw_desc), 1); - - desc = edesc->hw_desc; - jrentry = &edesc->jrentry; + DUMP_PREFIX_ADDRESS, 16, 4, desc, + desc_bytes(desc), 1); - ret = caam_jr_enqueue(jrdev, desc, aead_crypt_done, jrentry); - if (ret != -EINPROGRESS) { + ret = caam_jr_enqueue(jrdev, desc, aead_crypt_done, &edesc->jrentry); + if ((ret != -EINPROGRESS) && (ret != -EBUSY)) { aead_unmap(jrdev, edesc, req); kfree(edesc); } @@ -1506,13 +1522,37 @@ static int aead_decrypt(struct aead_request *req) return aead_crypt(req, false); } +static int aead_do_one_req(struct crypto_engine *engine, void *areq) +{ + struct aead_request *req = aead_request_cast(areq); + struct caam_ctx *ctx = crypto_aead_ctx(crypto_aead_reqtfm(req)); + struct caam_aead_req_ctx *rctx = aead_request_ctx(req); + struct caam_jr_request_entry *jrentry; + u32 *desc = rctx->edesc->hw_desc; + int ret; + + jrentry = &rctx->edesc->jrentry; + jrentry->bklog = true; + + ret = caam_jr_enqueue_no_bklog(ctx->jrdev, desc, rctx->aead_op_done, + jrentry); + + if (ret != -EINPROGRESS) { + aead_unmap(ctx->jrdev, rctx->edesc, req); + kfree(rctx->edesc); + } else { + ret = 0; + } + + return ret; +} + static inline int gcm_crypt(struct aead_request *req, bool encrypt) { struct aead_edesc *edesc; struct crypto_aead *aead = crypto_aead_reqtfm(req); struct caam_ctx *ctx = crypto_aead_ctx(aead); struct device *jrdev = ctx->jrdev; - struct caam_jr_request_entry *jrentry; bool all_contig; u32 *desc; int ret = 0; @@ -1525,16 +1565,14 @@ static inline int gcm_crypt(struct aead_request *req, bool encrypt) /* Create and submit job descriptor */ init_gcm_job(req, edesc, all_contig, encrypt); + desc = edesc->hw_desc; print_hex_dump_debug("aead jobdesc@"__stringify(__LINE__)": ", - DUMP_PREFIX_ADDRESS, 16, 4, edesc->hw_desc, - desc_bytes(edesc->hw_desc), 1); - - desc = edesc->hw_desc; - jrentry = &edesc->jrentry; + DUMP_PREFIX_ADDRESS, 16, 4, desc, + desc_bytes(desc), 1); - ret = caam_jr_enqueue(jrdev, desc, aead_crypt_done, jrentry); - if (ret != -EINPROGRESS) { + ret = caam_jr_enqueue(jrdev, desc, aead_crypt_done, &edesc->jrentry); + if ((ret != -EINPROGRESS) && (ret != -EBUSY)) { aead_unmap(jrdev, edesc, req); kfree(edesc); } @@ -3364,6 +3402,10 @@ static int caam_aead_init(struct crypto_aead *tfm) container_of(alg, struct caam_aead_alg, aead); struct caam_ctx *ctx = crypto_aead_ctx(tfm); + crypto_aead_set_reqsize(tfm, sizeof(struct caam_aead_req_ctx)); + + ctx->enginectx.op.do_one_request = aead_do_one_req; + return caam_init_common(ctx, &caam_alg->caam, !caam_alg->caam.nodkp); } diff --git a/drivers/crypto/caam/jr.c b/drivers/crypto/caam/jr.c index ddf3d39..7e6632d 100644 --- a/drivers/crypto/caam/jr.c +++ b/drivers/crypto/caam/jr.c @@ -434,6 +434,9 @@ static int transfer_request_to_engine(struct crypto_engine *engine, case CRYPTO_ALG_TYPE_SKCIPHER: return crypto_transfer_skcipher_request_to_engine(engine, skcipher_request_cast(req)); + case CRYPTO_ALG_TYPE_AEAD: + return crypto_transfer_aead_request_to_engine(engine, + aead_request_cast(req)); default: return -EINVAL; } -- 2.1.0