crytpo: sun8i-ce - factor out prepare/unprepare from sun8i_ce_hash_run()

In order to make the ahash code more clear and modular, split the
monolithic sun8i_ce_hash_run() callback into two parts, prepare and
unprepare (therefore aligning it with the sun8i-ce skcipher code).

Signed-off-by: Ovidiu Panait <ovidiu.panait.oss@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
Ovidiu Panait
2025-09-02 16:21:34 +03:00
committed by Herbert Xu
parent c3a61eea65
commit 27d5a2d1ad

View File

@@ -313,18 +313,15 @@ static u64 hash_pad(__le32 *buf, unsigned int bufsize, u64 padi, u64 byte_count,
return j;
}
int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq)
static int sun8i_ce_hash_prepare(struct ahash_request *areq, struct ce_task *cet)
{
struct ahash_request *areq = container_of(breq, struct ahash_request, base);
struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
struct ahash_alg *alg = __crypto_ahash_alg(tfm->base.__crt_alg);
struct sun8i_ce_hash_reqctx *rctx = ahash_request_ctx_dma(areq);
struct sun8i_ce_alg_template *algt;
struct sun8i_ce_dev *ce;
struct sun8i_ce_flow *chan;
struct ce_task *cet;
struct scatterlist *sg;
int nr_sgs, flow, err;
int nr_sgs, err;
unsigned int len;
u32 common;
u64 byte_count;
@@ -345,18 +342,14 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq)
bf = (__le32 *)rctx->pad;
flow = rctx->flow;
chan = &ce->chanlist[flow];
if (IS_ENABLED(CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG))
algt->stat_req++;
dev_dbg(ce->dev, "%s %s len=%d\n", __func__, crypto_tfm_alg_name(areq->base.tfm), areq->nbytes);
cet = chan->tl;
memset(cet, 0, sizeof(struct ce_task));
cet->t_id = cpu_to_le32(flow);
cet->t_id = cpu_to_le32(rctx->flow);
common = ce->variant->alg_hash[algt->ce_algo_id];
common |= CE_COMM_INT;
cet->t_common_ctl = cpu_to_le32(common);
@@ -434,22 +427,59 @@ int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq)
else
cet->t_dlen = cpu_to_le32(areq->nbytes / 4 + j);
err = sun8i_ce_run_task(ce, flow, crypto_ahash_alg_name(tfm));
dma_unmap_single(ce->dev, rctx->addr_pad, rctx->pad_len, DMA_TO_DEVICE);
return 0;
err_unmap_result:
dma_unmap_single(ce->dev, rctx->addr_res, rctx->result_len,
DMA_FROM_DEVICE);
if (!err)
memcpy(areq->result, rctx->result, crypto_ahash_digestsize(tfm));
err_unmap_src:
dma_unmap_sg(ce->dev, areq->src, rctx->nr_sgs, DMA_TO_DEVICE);
err_out:
return err;
}
static void sun8i_ce_hash_unprepare(struct ahash_request *areq,
struct ce_task *cet)
{
struct sun8i_ce_hash_reqctx *rctx = ahash_request_ctx_dma(areq);
struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
struct sun8i_ce_hash_tfm_ctx *ctx = crypto_ahash_ctx(tfm);
struct sun8i_ce_dev *ce = ctx->ce;
dma_unmap_single(ce->dev, rctx->addr_pad, rctx->pad_len, DMA_TO_DEVICE);
dma_unmap_single(ce->dev, rctx->addr_res, rctx->result_len,
DMA_FROM_DEVICE);
dma_unmap_sg(ce->dev, areq->src, rctx->nr_sgs, DMA_TO_DEVICE);
}
int sun8i_ce_hash_run(struct crypto_engine *engine, void *async_req)
{
struct ahash_request *areq = ahash_request_cast(async_req);
struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
struct sun8i_ce_hash_tfm_ctx *ctx = crypto_ahash_ctx(tfm);
struct sun8i_ce_hash_reqctx *rctx = ahash_request_ctx_dma(areq);
struct sun8i_ce_dev *ce = ctx->ce;
struct sun8i_ce_flow *chan;
int err;
chan = &ce->chanlist[rctx->flow];
err = sun8i_ce_hash_prepare(areq, chan->tl);
if (err)
return err;
err = sun8i_ce_run_task(ce, rctx->flow, crypto_ahash_alg_name(tfm));
sun8i_ce_hash_unprepare(areq, chan->tl);
if (!err)
memcpy(areq->result, rctx->result,
crypto_ahash_digestsize(tfm));
local_bh_disable();
crypto_finalize_hash_request(engine, breq, err);
crypto_finalize_hash_request(engine, async_req, err);
local_bh_enable();
return 0;