From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AF34CC2D0D1 for ; Mon, 24 Jun 2024 16:33:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=oVbv12CAtt0RRr0o/ivjyBXTwl5j9CzC13rESKs/8SI=; b=ChFMpJi83PmJBO2avTciLki2SC 2iZgEzO3KAl2Dfc9OqlJwpfaGzmjfq0bXWMn3RabwTvmWFJjY0TW/PxtLTrr2jBisBCB5NjNNDK2b VzAv/A+w7z5R/zplgk7fwKuIAD8aiVXT5fWrjSzoym5eq+lXUtydAElk0E+NdI1aczTVSroUNnTcb eRh+J2ll4vKyfSitj3DwYs6gnFzuPVbe/5c1ZguZLFD5Q4d8o358bFRCS9MgRu9cO7mDxRTx8KSKV EGdWTY98oR7W4+Xg2/MkTFlnOLXBlbM9Y4FxZB+/sDoG6CwAUDzQH3lxs9oK/2E7GN2oRAR8cEFSz uEJs2NFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLmcy-0000000HWp2-20HF; Mon, 24 Jun 2024 16:33:12 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sLmct-0000000HWn7-2rSx for linux-arm-kernel@lists.infradead.org; Mon, 24 Jun 2024 16:33:09 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 78979DA7; Mon, 24 Jun 2024 09:33:29 -0700 (PDT) Received: from donnerap.manchester.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9A1E43F6A8; Mon, 24 Jun 2024 09:33:02 -0700 (PDT) Date: Mon, 24 Jun 2024 17:32:59 +0100 From: Andre Przywara To: Chen-Yu Tsai Cc: Corentin Labbe , Herbert Xu , "David S . Miller" , Jernej Skrabec , Samuel Holland , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, devicetree@vger.kernel.org Subject: Re: [PATCH 2/4] crypto: sun8i-ce - wrap accesses to descriptor address fields Message-ID: <20240624173259.16bc6cd3@donnerap.manchester.arm.com> In-Reply-To: References: <20240616220719.26641-1-andre.przywara@arm.com> <20240616220719.26641-3-andre.przywara@arm.com> Organization: ARM X-Mailer: Claws Mail 3.18.0 (GTK+ 2.24.32; aarch64-unknown-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240624_093307_856681_114AD428 X-CRM114-Status: GOOD ( 30.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, 21 Jun 2024 22:53:47 +0800 Chen-Yu Tsai wrote: Hi, > On Mon, Jun 17, 2024 at 6:08=E2=80=AFAM Andre Przywara wrote: > > > > The Allwinner H616 (and later) SoCs support more than 32 bits worth of > > physical addresses. To accommodate the larger address space, the CE task > > descriptor fields holding addresses are now encoded as "word addresses", > > so take the actual address divided by four. > > This is true for the fields within the descriptor, but also for the > > descriptor base address, in the CE_TDA register. > > > > Wrap all accesses to those fields in a function, which will do the > > required division if needed. For now this in unused, so there should be > > no change in behaviour. > > > > Signed-off-by: Andre Przywara =20 >=20 > Reviewed-by: Chen-Yu Tsai Thanks for that! > though you need to fix up the reported sparse warning in sun8i_ce_run_tas= k(). Yeah, that turned out to be a nasty one, and uncovered an actual big endian bug. I dropped your R-b from v2 (in your inbox after testing), since I split up the function and used a different variant for this one writel() caller. So if you are happy with the changes in sun8i-ce.h and sun8i-ce-core.c: the other files just use the renamed function name and didn't change otherwise. Cheers, Andre >=20 > > --- > > drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c | 8 ++++---- > > drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c | 3 ++- > > drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c | 6 +++--- > > drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c | 6 +++--- > > drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c | 2 +- > > drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h | 10 ++++++++++ > > 6 files changed, 23 insertions(+), 12 deletions(-) > > > > diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c b/driv= ers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c > > index de50c00ba218f..3a5674b1bd3c0 100644 > > --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c > > +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-cipher.c > > @@ -190,7 +190,7 @@ static int sun8i_ce_cipher_prepare(struct crypto_en= gine *engine, void *async_req > > err =3D -EFAULT; > > goto theend; > > } > > - cet->t_key =3D cpu_to_le32(rctx->addr_key); > > + cet->t_key =3D sun8i_ce_desc_addr(ce, rctx->addr_key); > > > > ivsize =3D crypto_skcipher_ivsize(tfm); > > if (areq->iv && crypto_skcipher_ivsize(tfm) > 0) { > > @@ -208,7 +208,7 @@ static int sun8i_ce_cipher_prepare(struct crypto_en= gine *engine, void *async_req > > err =3D -ENOMEM; > > goto theend_iv; > > } > > - cet->t_iv =3D cpu_to_le32(rctx->addr_iv); > > + cet->t_iv =3D sun8i_ce_desc_addr(ce, rctx->addr_iv); > > } > > > > if (areq->src =3D=3D areq->dst) { > > @@ -236,7 +236,7 @@ static int sun8i_ce_cipher_prepare(struct crypto_en= gine *engine, void *async_req > > > > len =3D areq->cryptlen; > > for_each_sg(areq->src, sg, nr_sgs, i) { > > - cet->t_src[i].addr =3D cpu_to_le32(sg_dma_address(sg)); > > + cet->t_src[i].addr =3D sun8i_ce_desc_addr(ce, sg_dma_ad= dress(sg)); > > todo =3D min(len, sg_dma_len(sg)); > > cet->t_src[i].len =3D cpu_to_le32(todo / 4); > > dev_dbg(ce->dev, "%s total=3D%u SG(%d %u off=3D%d) todo= =3D%u\n", __func__, > > @@ -251,7 +251,7 @@ static int sun8i_ce_cipher_prepare(struct crypto_en= gine *engine, void *async_req > > > > len =3D areq->cryptlen; > > for_each_sg(areq->dst, sg, nr_sgd, i) { > > - cet->t_dst[i].addr =3D cpu_to_le32(sg_dma_address(sg)); > > + cet->t_dst[i].addr =3D sun8i_ce_desc_addr(ce, sg_dma_ad= dress(sg)); > > todo =3D min(len, sg_dma_len(sg)); > > cet->t_dst[i].len =3D cpu_to_le32(todo / 4); > > dev_dbg(ce->dev, "%s total=3D%u SG(%d %u off=3D%d) todo= =3D%u\n", __func__, > > diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c b/driver= s/crypto/allwinner/sun8i-ce/sun8i-ce-core.c > > index 0408b2d5d533b..89ab3e08f0697 100644 > > --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c > > +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-core.c > > @@ -172,7 +172,8 @@ int sun8i_ce_run_task(struct sun8i_ce_dev *ce, int = flow, const char *name) > > writel(v, ce->base + CE_ICR); > > > > reinit_completion(&ce->chanlist[flow].complete); > > - writel(ce->chanlist[flow].t_phy, ce->base + CE_TDQ); > > + writel(sun8i_ce_desc_addr(ce, ce->chanlist[flow].t_phy), > > + ce->base + CE_TDQ); > > > > ce->chanlist[flow].status =3D 0; > > /* Be sure all data is written before enabling the task */ > > diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c b/driver= s/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c > > index ee2a28c906ede..a710ec9aa96f1 100644 > > --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c > > +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-hash.c > > @@ -403,7 +403,7 @@ int sun8i_ce_hash_run(struct crypto_engine *engine,= void *breq) > > > > len =3D areq->nbytes; > > for_each_sg(areq->src, sg, nr_sgs, i) { > > - cet->t_src[i].addr =3D cpu_to_le32(sg_dma_address(sg)); > > + cet->t_src[i].addr =3D sun8i_ce_desc_addr(ce, sg_dma_ad= dress(sg)); > > todo =3D min(len, sg_dma_len(sg)); > > cet->t_src[i].len =3D cpu_to_le32(todo / 4); > > len -=3D todo; > > @@ -414,7 +414,7 @@ int sun8i_ce_hash_run(struct crypto_engine *engine,= void *breq) > > goto theend; > > } > > addr_res =3D dma_map_single(ce->dev, result, digestsize, DMA_FR= OM_DEVICE); > > - cet->t_dst[0].addr =3D cpu_to_le32(addr_res); > > + cet->t_dst[0].addr =3D sun8i_ce_desc_addr(ce, addr_res); > > cet->t_dst[0].len =3D cpu_to_le32(digestsize / 4); > > if (dma_mapping_error(ce->dev, addr_res)) { > > dev_err(ce->dev, "DMA map dest\n"); > > @@ -445,7 +445,7 @@ int sun8i_ce_hash_run(struct crypto_engine *engine,= void *breq) > > } > > > > addr_pad =3D dma_map_single(ce->dev, buf, j * 4, DMA_TO_DEVICE); > > - cet->t_src[i].addr =3D cpu_to_le32(addr_pad); > > + cet->t_src[i].addr =3D sun8i_ce_desc_addr(ce, addr_pad); > > cet->t_src[i].len =3D cpu_to_le32(j); > > if (dma_mapping_error(ce->dev, addr_pad)) { > > dev_err(ce->dev, "DMA error on padding SG\n"); > > diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c b/driver= s/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c > > index 80815379f6fc5..f030167f95945 100644 > > --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c > > +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-prng.c > > @@ -132,10 +132,10 @@ int sun8i_ce_prng_generate(struct crypto_rng *tfm= , const u8 *src, > > cet->t_sym_ctl =3D cpu_to_le32(sym); > > cet->t_asym_ctl =3D 0; > > > > - cet->t_key =3D cpu_to_le32(dma_iv); > > - cet->t_iv =3D cpu_to_le32(dma_iv); > > + cet->t_key =3D sun8i_ce_desc_addr(ce, dma_iv); > > + cet->t_iv =3D sun8i_ce_desc_addr(ce, dma_iv); > > > > - cet->t_dst[0].addr =3D cpu_to_le32(dma_dst); > > + cet->t_dst[0].addr =3D sun8i_ce_desc_addr(ce, dma_dst); > > cet->t_dst[0].len =3D cpu_to_le32(todo / 4); > > ce->chanlist[flow].timeout =3D 2000; > > > > diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c b/driver= s/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c > > index 9c35f2a83eda8..465c1c512eb85 100644 > > --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c > > +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce-trng.c > > @@ -77,7 +77,7 @@ static int sun8i_ce_trng_read(struct hwrng *rng, void= *data, size_t max, bool wa > > cet->t_sym_ctl =3D 0; > > cet->t_asym_ctl =3D 0; > > > > - cet->t_dst[0].addr =3D cpu_to_le32(dma_dst); > > + cet->t_dst[0].addr =3D sun8i_ce_desc_addr(ce, dma_dst); > > cet->t_dst[0].len =3D cpu_to_le32(todo / 4); > > ce->chanlist[flow].timeout =3D todo; > > > > diff --git a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h b/drivers/cry= pto/allwinner/sun8i-ce/sun8i-ce.h > > index 93d4985def87a..8fa58f3bb7f86 100644 > > --- a/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h > > +++ b/drivers/crypto/allwinner/sun8i-ce/sun8i-ce.h > > @@ -149,6 +149,7 @@ struct ce_variant { > > bool hash_t_dlen_in_bits; > > bool prng_t_dlen_in_bytes; > > bool trng_t_dlen_in_bytes; > > + bool needs_word_addresses; > > struct ce_clock ce_clks[CE_MAX_CLOCKS]; > > int esr; > > unsigned char prng; > > @@ -241,6 +242,15 @@ struct sun8i_ce_dev { > > #endif > > }; > > > > +static inline __le32 sun8i_ce_desc_addr(struct sun8i_ce_dev *dev, > > + dma_addr_t addr) > > +{ > > + if (dev->variant->needs_word_addresses) > > + return cpu_to_le32(addr / 4); > > + > > + return cpu_to_le32(addr); > > +} > > + > > /* > > * struct sun8i_cipher_req_ctx - context for a skcipher request > > * @op_dir: direction (encrypt vs decrypt) for this request > > -- > > 2.39.4 > > =20