Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5245853ybl; Tue, 14 Jan 2020 06:01:00 -0800 (PST) X-Google-Smtp-Source: APXvYqzttfwSeCEfvCfIATcfSd838QzHwwFyf8bpiiRLGeGs6jpkwJjRwvmR7zIkecW4Zf+ylTrQ X-Received: by 2002:a05:6808:197:: with SMTP id w23mr17301489oic.46.1579010460531; Tue, 14 Jan 2020 06:01:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579010460; cv=none; d=google.com; s=arc-20160816; b=WrKcfDa52vomzedT30+td6qBLYOzGFJeWXS2eEKfT1tZP+rM6RGkWqclLSLRZ2lWKf c44TEo1MHyhw8j4Gd8vc479HPTdD+zLSkLOzQdipgLX8owGajsfUMeOpiRQxxeKwrf5x Hw8IpeL8qDAI/ygaYjGO7ldBdypvpJNr08+bPMh7sHvE7dpgRlsHiYDcbJ+XMdInyXC3 MWP4yUWQaAk04dQ1imVFZPJU4Sexn2DZpkUeXWtpuWemdePetCCSuACB6wIL1ZLr5+Ep h4S+ja04I/j9Da0qjRiDZDRjDf+xcWWbfMO7uKF3dU8CYszlXMyKKQ70wyView5uThhk jz2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=t9FT5fa3SeoozrvYAEFmKmMXN/EPpMMGGoi0s6SDiyU=; b=dfJ5hVfyDrGgxy2C1uIU4J+kJaQVc8y/JjC99uLFGB6LVrJAnjRgZvotImiV6zOnMn 3KYw1FThKzrS6D2CdQaTSbwppFN2WMdKVme4LXxtgckhH2kg1ewlz1GKeAN/1ac9ys91 fenI50FHJqZ2BYtowUIoWmdz5cl6YTHYdltdagN3jZN7gVqf3mou/Tit1/owGOFRO+Fn ABivfa+qzTtVREPIRJPfOvvcmlZa2ymAYbjhzczTnxLjVUSpE69aTxxP3UfEuzxnvmYc 2ScS/yvql9UG3/eaXmbiaVsHRIl8L09UZAUape7Mi+VBwve6SdV2CGrtSCmSDGszc+4P aCbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="oSFvsfR/"; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l189si7718035oih.166.2020.01.14.06.00.49; Tue, 14 Jan 2020 06:01:00 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b="oSFvsfR/"; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728951AbgANN76 (ORCPT + 99 others); Tue, 14 Jan 2020 08:59:58 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:40020 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728926AbgANN75 (ORCPT ); Tue, 14 Jan 2020 08:59:57 -0500 Received: by mail-wr1-f67.google.com with SMTP id c14so12269688wrn.7; Tue, 14 Jan 2020 05:59:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t9FT5fa3SeoozrvYAEFmKmMXN/EPpMMGGoi0s6SDiyU=; b=oSFvsfR/LJOKaCs8d7wwS3haZMNmt9yVMFgpfRLn2shhRClhS1eumasQBeBg6P1WIf EWgofZKZ2JeBcfnsbgwg2NzMLRh51ivNtRUwOJW5KHOmEb5a1zY3ZLh7jB1lN/iQkEVH 8orzTRi/8f+jnRtzLhxEZ4LNftMcmaYCD/dS5lilG/OXNQTF/Y4HA/6SLS28Hm2wEkWj 6fCqEzadKadEgcFW04TPWTSsKtux74+cwwT871kCJy/rbMhsI9r25HBcMql4Kpuxwr7v 7r8ADb/enBtLFwrKWsyo7av1/mrgvaLqZgWDFUYTv21H25VfZyQYqmy8ykMObOCJtWpC Gysg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=t9FT5fa3SeoozrvYAEFmKmMXN/EPpMMGGoi0s6SDiyU=; b=Rcq0WHjquQ1hf+tcidjdXegnBGivq005jo0yGqWVGIH69cogNhM9PUnzIJfqIr4dON ueaWvth8kaGY8qnF69dAe2bOTu8iUwAODP7+UfXgFZY6jxAfsCYCMR/SL7fCfm/zAF9m 9ycmkzI2VU3J/TRQK/NcZI6OhdxJ85cXhLtEPtm0s1E7Bgt6EQTeYVU1j4pmzWKQXvWu XPM8svbMLk/CFYBavZL9WnKWItx0G/670JuQzrUZ9EFJ1G2mlI1copeonfsZRa8cXVr1 EeumgjKI0PZ+ay7Zs5aoY3uIWPmDMGTqWZokSk0dqRPxP+SECpS5tyv+B8shqZhGBFut 5hMQ== X-Gm-Message-State: APjAAAUDDSPMoUZwe/VKNBdfvIII8B6RYb2cdSs9FMCva+b0vK6n1isv 1DRQ5PO5DDaj2FMLynbu7yY= X-Received: by 2002:a5d:494f:: with SMTP id r15mr26124939wrs.143.1579010394666; Tue, 14 Jan 2020 05:59:54 -0800 (PST) Received: from Red.localdomain ([2a01:cb1d:147:7200:2e56:dcff:fed2:c6d6]) by smtp.googlemail.com with ESMTPSA id 4sm17854448wmg.22.2020.01.14.05.59.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2020 05:59:54 -0800 (PST) From: Corentin Labbe To: alexandre.torgue@st.com, davem@davemloft.net, herbert@gondor.apana.org.au, mcoquelin.stm32@gmail.com, mripard@kernel.org, wens@csie.org, iuliana.prodan@nxp.com, horia.geanta@nxp.com, aymen.sghaier@nxp.com Cc: linux-arm-kernel@lists.infradead.org, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH RFC 03/10] crypto: sun8i-ce: split into prepare/run/unprepare Date: Tue, 14 Jan 2020 14:59:29 +0100 Message-Id: <20200114135936.32422-4-clabbe.montjoie@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200114135936.32422-1-clabbe.montjoie@gmail.com> References: <20200114135936.32422-1-clabbe.montjoie@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org This patch split the do_one_request into three. Prepare will handle all DMA mapping and initialisation of the task structure. Unprepare will clean all DMA mapping. And the do_one_request will be limited to just excuting the task. Signed-off-by: Corentin Labbe --- .../allwinner/sun8i-ce/sun8i-ce-cipher.c | 70 ++++++++++++++++--- drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h | 4 ++ 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c index 6108cea0e0bd..401f39f144ea 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c @@ -78,8 +78,9 @@ static int sun8i_ce_cipher_fallback(struct skcipher_request *areq) return err; } -static int sun8i_ce_cipher(struct skcipher_request *areq) +static int sun8i_ce_cipher_prepare(struct crypto_engine *engine, void *async_req) { + struct skcipher_request *areq = container_of(async_req, struct skcipher_request, base); struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); struct sun8i_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); struct sun8i_ce_dev *ce = op->ce; @@ -237,7 +238,9 @@ static int sun8i_ce_cipher(struct skcipher_request *areq) } chan->timeout = areq->cryptlen; - err = sun8i_ce_run_task(ce, flow, crypto_tfm_alg_name(areq->base.tfm)); + rctx->nr_sgs = nr_sgs; + rctx->nr_sgd = nr_sgd; + return 0; theend_sgs: if (areq->src == areq->dst) { @@ -271,13 +274,64 @@ static int sun8i_ce_cipher(struct skcipher_request *areq) return err; } -static int sun8i_ce_handle_cipher_request(struct crypto_engine *engine, void *areq) +int sun8i_ce_cipher_run(struct crypto_engine *engine, void *areq) { - int err; struct skcipher_request *breq = container_of(areq, struct skcipher_request, base); + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(breq); + struct sun8i_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct sun8i_ce_dev *ce = op->ce; + struct sun8i_cipher_req_ctx *rctx = skcipher_request_ctx(breq); + int flow, err; - err = sun8i_ce_cipher(breq); + flow = rctx->flow; + err = sun8i_ce_run_task(ce, flow, crypto_tfm_alg_name(breq->base.tfm)); crypto_finalize_skcipher_request(engine, breq, err); + return 0; +} + +static int sun8i_ce_cipher_unprepare(struct crypto_engine *engine, void *async_req) +{ + struct skcipher_request *areq = container_of(async_req, struct skcipher_request, base); + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq); + struct sun8i_cipher_tfm_ctx *op = crypto_skcipher_ctx(tfm); + struct sun8i_ce_dev *ce = op->ce; + struct sun8i_cipher_req_ctx *rctx = skcipher_request_ctx(areq); + struct sun8i_ce_flow *chan; + struct ce_task *cet; + unsigned int ivsize, offset; + int nr_sgs = rctx->nr_sgs; + int nr_sgd = rctx->nr_sgd; + int flow; + + flow = rctx->flow; + chan = &ce->chanlist[flow]; + cet = chan->tl; + ivsize = crypto_skcipher_ivsize(tfm); + + if (areq->src == areq->dst) { + dma_unmap_sg(ce->dev, areq->src, nr_sgs, DMA_BIDIRECTIONAL); + } else { + if (nr_sgs > 0) + dma_unmap_sg(ce->dev, areq->src, nr_sgs, DMA_TO_DEVICE); + dma_unmap_sg(ce->dev, areq->dst, nr_sgd, DMA_FROM_DEVICE); + } + + if (areq->iv && ivsize > 0) { + if (cet->t_iv) + dma_unmap_single(ce->dev, cet->t_iv, rctx->ivlen, + DMA_TO_DEVICE); + offset = areq->cryptlen - ivsize; + if (rctx->op_dir & CE_DECRYPTION) { + memcpy(areq->iv, rctx->backup_iv, ivsize); + kzfree(rctx->backup_iv); + } else { + scatterwalk_map_and_copy(areq->iv, areq->dst, offset, + ivsize, 0); + } + kfree(rctx->bounce_iv); + } + + dma_unmap_single(ce->dev, cet->t_key, op->keylen, DMA_TO_DEVICE); return 0; } @@ -347,9 +401,9 @@ int sun8i_ce_cipher_init(struct crypto_tfm *tfm) crypto_tfm_alg_driver_name(&sktfm->base), crypto_tfm_alg_driver_name(crypto_skcipher_tfm(&op->fallback_tfm->base))); - op->enginectx.op.do_one_request = sun8i_ce_handle_cipher_request; - op->enginectx.op.prepare_request = NULL; - op->enginectx.op.unprepare_request = NULL; + op->enginectx.op.do_one_request = sun8i_ce_cipher_run; + op->enginectx.op.prepare_request = sun8i_ce_cipher_prepare; + op->enginectx.op.unprepare_request = sun8i_ce_cipher_unprepare; err = pm_runtime_get_sync(op->ce->dev); if (err < 0) diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h index 049b3175d755..2d3325a13bf1 100644 --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h @@ -183,6 +183,8 @@ struct sun8i_ce_dev { * @backup_iv: buffer which contain the next IV to store * @bounce_iv: buffer which contain a copy of IV * @ivlen: size of bounce_iv + * @nr_sgs: The number of source SG (as given by dma_map_sg()) + * @nr_sgd: The number of destination SG (as given by dma_map_sg()) */ struct sun8i_cipher_req_ctx { u32 op_dir; @@ -190,6 +192,8 @@ struct sun8i_cipher_req_ctx { void *backup_iv; void *bounce_iv; unsigned int ivlen; + int nr_sgs; + int nr_sgd; }; /* -- 2.24.1