Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * sun8i-ce-hash.c - hardware cryptographic offloader for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Allwinner H3/A64/H5/H2+/H6/R40 SoC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2015-2020 Corentin Labbe <clabbe@baylibre.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * This file add support for MD5 and SHA1/SHA224/SHA256/SHA384/SHA512.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * You could find the datasheet in Documentation/arm/sunxi.rst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/bottom_half.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/pm_runtime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/scatterlist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <crypto/internal/hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <crypto/sha.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <crypto/md5.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "sun8i-ce.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) int sun8i_ce_hash_crainit(struct crypto_tfm *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	struct sun8i_ce_hash_tfm_ctx *op = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	struct ahash_alg *alg = __crypto_ahash_alg(tfm->__crt_alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	struct sun8i_ce_alg_template *algt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	memset(op, 0, sizeof(struct sun8i_ce_hash_tfm_ctx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	algt = container_of(alg, struct sun8i_ce_alg_template, alg.hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	op->ce = algt->ce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	op->enginectx.op.do_one_request = sun8i_ce_hash_run;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	op->enginectx.op.prepare_request = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	op->enginectx.op.unprepare_request = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	/* FALLBACK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	op->fallback_tfm = crypto_alloc_ahash(crypto_tfm_alg_name(tfm), 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 					      CRYPTO_ALG_NEED_FALLBACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	if (IS_ERR(op->fallback_tfm)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		dev_err(algt->ce->dev, "Fallback driver could no be loaded\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		return PTR_ERR(op->fallback_tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if (algt->alg.hash.halg.statesize < crypto_ahash_statesize(op->fallback_tfm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		algt->alg.hash.halg.statesize = crypto_ahash_statesize(op->fallback_tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 				 sizeof(struct sun8i_ce_hash_reqctx) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 				 crypto_ahash_reqsize(op->fallback_tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	dev_info(op->ce->dev, "Fallback for %s is %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		 crypto_tfm_alg_driver_name(tfm),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		 crypto_tfm_alg_driver_name(&op->fallback_tfm->base));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	err = pm_runtime_get_sync(op->ce->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		goto error_pm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) error_pm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	pm_runtime_put_noidle(op->ce->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	crypto_free_ahash(op->fallback_tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) void sun8i_ce_hash_craexit(struct crypto_tfm *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	struct sun8i_ce_hash_tfm_ctx *tfmctx = crypto_tfm_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	crypto_free_ahash(tfmctx->fallback_tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	pm_runtime_put_sync_suspend(tfmctx->ce->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) int sun8i_ce_hash_init(struct ahash_request *areq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct sun8i_ce_hash_reqctx *rctx = ahash_request_ctx(areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct sun8i_ce_hash_tfm_ctx *tfmctx = crypto_ahash_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	memset(rctx, 0, sizeof(struct sun8i_ce_hash_reqctx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	ahash_request_set_tfm(&rctx->fallback_req, tfmctx->fallback_tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	rctx->fallback_req.base.flags = areq->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	return crypto_ahash_init(&rctx->fallback_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) int sun8i_ce_hash_export(struct ahash_request *areq, void *out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	struct sun8i_ce_hash_reqctx *rctx = ahash_request_ctx(areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	struct sun8i_ce_hash_tfm_ctx *tfmctx = crypto_ahash_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	ahash_request_set_tfm(&rctx->fallback_req, tfmctx->fallback_tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	rctx->fallback_req.base.flags = areq->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	return crypto_ahash_export(&rctx->fallback_req, out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) int sun8i_ce_hash_import(struct ahash_request *areq, const void *in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	struct sun8i_ce_hash_reqctx *rctx = ahash_request_ctx(areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	struct sun8i_ce_hash_tfm_ctx *tfmctx = crypto_ahash_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	ahash_request_set_tfm(&rctx->fallback_req, tfmctx->fallback_tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	rctx->fallback_req.base.flags = areq->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	return crypto_ahash_import(&rctx->fallback_req, in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) int sun8i_ce_hash_final(struct ahash_request *areq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	struct sun8i_ce_hash_reqctx *rctx = ahash_request_ctx(areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	struct sun8i_ce_hash_tfm_ctx *tfmctx = crypto_ahash_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct ahash_alg *alg = __crypto_ahash_alg(tfm->base.__crt_alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	struct sun8i_ce_alg_template *algt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	ahash_request_set_tfm(&rctx->fallback_req, tfmctx->fallback_tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	rctx->fallback_req.base.flags = areq->base.flags &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 					CRYPTO_TFM_REQ_MAY_SLEEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	rctx->fallback_req.result = areq->result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) #ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	algt = container_of(alg, struct sun8i_ce_alg_template, alg.hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	algt->stat_fb++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	return crypto_ahash_final(&rctx->fallback_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) int sun8i_ce_hash_update(struct ahash_request *areq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	struct sun8i_ce_hash_reqctx *rctx = ahash_request_ctx(areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	struct sun8i_ce_hash_tfm_ctx *tfmctx = crypto_ahash_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	ahash_request_set_tfm(&rctx->fallback_req, tfmctx->fallback_tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	rctx->fallback_req.base.flags = areq->base.flags &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 					CRYPTO_TFM_REQ_MAY_SLEEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	rctx->fallback_req.nbytes = areq->nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	rctx->fallback_req.src = areq->src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	return crypto_ahash_update(&rctx->fallback_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) int sun8i_ce_hash_finup(struct ahash_request *areq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	struct sun8i_ce_hash_reqctx *rctx = ahash_request_ctx(areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	struct sun8i_ce_hash_tfm_ctx *tfmctx = crypto_ahash_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	struct ahash_alg *alg = __crypto_ahash_alg(tfm->base.__crt_alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	struct sun8i_ce_alg_template *algt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	ahash_request_set_tfm(&rctx->fallback_req, tfmctx->fallback_tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	rctx->fallback_req.base.flags = areq->base.flags &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 					CRYPTO_TFM_REQ_MAY_SLEEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	rctx->fallback_req.nbytes = areq->nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	rctx->fallback_req.src = areq->src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	rctx->fallback_req.result = areq->result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) #ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	algt = container_of(alg, struct sun8i_ce_alg_template, alg.hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	algt->stat_fb++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	return crypto_ahash_finup(&rctx->fallback_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static int sun8i_ce_hash_digest_fb(struct ahash_request *areq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	struct sun8i_ce_hash_reqctx *rctx = ahash_request_ctx(areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	struct sun8i_ce_hash_tfm_ctx *tfmctx = crypto_ahash_ctx(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) #ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	struct ahash_alg *alg = __crypto_ahash_alg(tfm->base.__crt_alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct sun8i_ce_alg_template *algt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	ahash_request_set_tfm(&rctx->fallback_req, tfmctx->fallback_tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	rctx->fallback_req.base.flags = areq->base.flags &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 					CRYPTO_TFM_REQ_MAY_SLEEP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	rctx->fallback_req.nbytes = areq->nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	rctx->fallback_req.src = areq->src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	rctx->fallback_req.result = areq->result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) #ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	algt = container_of(alg, struct sun8i_ce_alg_template, alg.hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	algt->stat_fb++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	return crypto_ahash_digest(&rctx->fallback_req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static bool sun8i_ce_hash_need_fallback(struct ahash_request *areq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	struct scatterlist *sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (areq->nbytes == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	/* we need to reserve one SG for padding one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	if (sg_nents(areq->src) > MAX_SG - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	sg = areq->src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	while (sg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		if (sg->length % 4 || !IS_ALIGNED(sg->offset, sizeof(u32)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		sg = sg_next(sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) int sun8i_ce_hash_digest(struct ahash_request *areq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	struct ahash_alg *alg = __crypto_ahash_alg(tfm->base.__crt_alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	struct sun8i_ce_hash_reqctx *rctx = ahash_request_ctx(areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	struct sun8i_ce_alg_template *algt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	struct sun8i_ce_dev *ce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	struct crypto_engine *engine;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	struct scatterlist *sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	int nr_sgs, e, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	if (sun8i_ce_hash_need_fallback(areq))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		return sun8i_ce_hash_digest_fb(areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	nr_sgs = sg_nents(areq->src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if (nr_sgs > MAX_SG - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		return sun8i_ce_hash_digest_fb(areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	for_each_sg(areq->src, sg, nr_sgs, i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		if (sg->length % 4 || !IS_ALIGNED(sg->offset, sizeof(u32)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			return sun8i_ce_hash_digest_fb(areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	algt = container_of(alg, struct sun8i_ce_alg_template, alg.hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	ce = algt->ce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	e = sun8i_ce_get_engine_number(ce);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	rctx->flow = e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	engine = ce->chanlist[e].engine;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	return crypto_transfer_hash_request_to_engine(engine, areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	struct ahash_request *areq = container_of(breq, struct ahash_request, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	struct ahash_alg *alg = __crypto_ahash_alg(tfm->base.__crt_alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	struct sun8i_ce_hash_reqctx *rctx = ahash_request_ctx(areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	struct sun8i_ce_alg_template *algt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	struct sun8i_ce_dev *ce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	struct sun8i_ce_flow *chan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	struct ce_task *cet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	struct scatterlist *sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	int nr_sgs, flow, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	unsigned int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	u32 common;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	u64 byte_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	__le32 *bf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	void *buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	int j, i, todo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	int nbw = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	u64 fill, min_fill;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	__be64 *bebits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	__le64 *lebits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	void *result = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	u64 bs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	int digestsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	dma_addr_t addr_res, addr_pad;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	algt = container_of(alg, struct sun8i_ce_alg_template, alg.hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	ce = algt->ce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	bs = algt->alg.hash.halg.base.cra_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	digestsize = algt->alg.hash.halg.digestsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	if (digestsize == SHA224_DIGEST_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		digestsize = SHA256_DIGEST_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	if (digestsize == SHA384_DIGEST_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		digestsize = SHA512_DIGEST_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	/* the padding could be up to two block. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	buf = kzalloc(bs * 2, GFP_KERNEL | GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		goto theend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	bf = (__le32 *)buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	result = kzalloc(digestsize, GFP_KERNEL | GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	if (!result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		goto theend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	flow = rctx->flow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	chan = &ce->chanlist[flow];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) #ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	algt->stat_req++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	dev_dbg(ce->dev, "%s %s len=%d\n", __func__, crypto_tfm_alg_name(areq->base.tfm), areq->nbytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	cet = chan->tl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	memset(cet, 0, sizeof(struct ce_task));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	cet->t_id = cpu_to_le32(flow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	common = ce->variant->alg_hash[algt->ce_algo_id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	common |= CE_COMM_INT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	cet->t_common_ctl = cpu_to_le32(common);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	cet->t_sym_ctl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	cet->t_asym_ctl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	nr_sgs = dma_map_sg(ce->dev, areq->src, sg_nents(areq->src), DMA_TO_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	if (nr_sgs <= 0 || nr_sgs > MAX_SG) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		dev_err(ce->dev, "Invalid sg number %d\n", nr_sgs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		goto theend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	len = areq->nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	for_each_sg(areq->src, sg, nr_sgs, i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		cet->t_src[i].addr = cpu_to_le32(sg_dma_address(sg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		todo = min(len, sg_dma_len(sg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		cet->t_src[i].len = cpu_to_le32(todo / 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		len -= todo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	if (len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		dev_err(ce->dev, "remaining len %d\n", len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		goto theend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	addr_res = dma_map_single(ce->dev, result, digestsize, DMA_FROM_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	cet->t_dst[0].addr = cpu_to_le32(addr_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	cet->t_dst[0].len = cpu_to_le32(digestsize / 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	if (dma_mapping_error(ce->dev, addr_res)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		dev_err(ce->dev, "DMA map dest\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		goto theend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	byte_count = areq->nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	j = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	bf[j++] = cpu_to_le32(0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	if (bs == 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		fill = 64 - (byte_count % 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		min_fill = 2 * sizeof(u32) + (nbw ? 0 : sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		fill = 128 - (byte_count % 128);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		min_fill = 4 * sizeof(u32) + (nbw ? 0 : sizeof(u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	if (fill < min_fill)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		fill += bs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	j += (fill - min_fill) / sizeof(u32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	switch (algt->ce_algo_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	case CE_ID_HASH_MD5:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		lebits = (__le64 *)&bf[j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		*lebits = cpu_to_le64(byte_count << 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		j += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	case CE_ID_HASH_SHA1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	case CE_ID_HASH_SHA224:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	case CE_ID_HASH_SHA256:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		bebits = (__be64 *)&bf[j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 		*bebits = cpu_to_be64(byte_count << 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		j += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	case CE_ID_HASH_SHA384:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	case CE_ID_HASH_SHA512:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		bebits = (__be64 *)&bf[j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		*bebits = cpu_to_be64(byte_count >> 61);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		j += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		bebits = (__be64 *)&bf[j];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		*bebits = cpu_to_be64(byte_count << 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		j += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	addr_pad = dma_map_single(ce->dev, buf, j * 4, DMA_TO_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	cet->t_src[i].addr = cpu_to_le32(addr_pad);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	cet->t_src[i].len = cpu_to_le32(j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	if (dma_mapping_error(ce->dev, addr_pad)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		dev_err(ce->dev, "DMA error on padding SG\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		goto theend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	if (ce->variant->hash_t_dlen_in_bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		cet->t_dlen = cpu_to_le32((areq->nbytes + j * 4) * 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		cet->t_dlen = cpu_to_le32(areq->nbytes / 4 + j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	chan->timeout = areq->nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	err = sun8i_ce_run_task(ce, flow, crypto_tfm_alg_name(areq->base.tfm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	dma_unmap_single(ce->dev, addr_pad, j * 4, DMA_TO_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	dma_unmap_sg(ce->dev, areq->src, nr_sgs, DMA_TO_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	dma_unmap_single(ce->dev, addr_res, digestsize, DMA_FROM_DEVICE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	memcpy(areq->result, result, algt->alg.hash.halg.digestsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) theend:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	kfree(result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	local_bh_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	crypto_finalize_hash_request(engine, breq, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	local_bh_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) }