18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Crypto acceleration support for Rockchip RK3288
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (c) 2015, Fuzhou Rockchip Electronics Co., Ltd
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Author: Zain Wang <zain.wang@rock-chips.com>
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * Some ideas are from marvell-cesa.c and s5p-sss.c driver.
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci#include <linux/device.h>
128c2ecf20Sopenharmony_ci#include <crypto/scatterwalk.h>
138c2ecf20Sopenharmony_ci#include "rk3288_crypto.h"
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#define RK_CRYPTO_DEC			BIT(0)
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cistatic int rk_cipher_need_fallback(struct skcipher_request *req)
188c2ecf20Sopenharmony_ci{
198c2ecf20Sopenharmony_ci	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
208c2ecf20Sopenharmony_ci	unsigned int bs = crypto_skcipher_blocksize(tfm);
218c2ecf20Sopenharmony_ci	struct scatterlist *sgs, *sgd;
228c2ecf20Sopenharmony_ci	unsigned int stodo, dtodo, len;
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci	if (!req->cryptlen)
258c2ecf20Sopenharmony_ci		return true;
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci	len = req->cryptlen;
288c2ecf20Sopenharmony_ci	sgs = req->src;
298c2ecf20Sopenharmony_ci	sgd = req->dst;
308c2ecf20Sopenharmony_ci	while (sgs && sgd) {
318c2ecf20Sopenharmony_ci		if (!IS_ALIGNED(sgs->offset, sizeof(u32))) {
328c2ecf20Sopenharmony_ci			return true;
338c2ecf20Sopenharmony_ci		}
348c2ecf20Sopenharmony_ci		if (!IS_ALIGNED(sgd->offset, sizeof(u32))) {
358c2ecf20Sopenharmony_ci			return true;
368c2ecf20Sopenharmony_ci		}
378c2ecf20Sopenharmony_ci		stodo = min(len, sgs->length);
388c2ecf20Sopenharmony_ci		if (stodo % bs) {
398c2ecf20Sopenharmony_ci			return true;
408c2ecf20Sopenharmony_ci		}
418c2ecf20Sopenharmony_ci		dtodo = min(len, sgd->length);
428c2ecf20Sopenharmony_ci		if (dtodo % bs) {
438c2ecf20Sopenharmony_ci			return true;
448c2ecf20Sopenharmony_ci		}
458c2ecf20Sopenharmony_ci		if (stodo != dtodo) {
468c2ecf20Sopenharmony_ci			return true;
478c2ecf20Sopenharmony_ci		}
488c2ecf20Sopenharmony_ci		len -= stodo;
498c2ecf20Sopenharmony_ci		sgs = sg_next(sgs);
508c2ecf20Sopenharmony_ci		sgd = sg_next(sgd);
518c2ecf20Sopenharmony_ci	}
528c2ecf20Sopenharmony_ci	return false;
538c2ecf20Sopenharmony_ci}
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_cistatic int rk_cipher_fallback(struct skcipher_request *areq)
568c2ecf20Sopenharmony_ci{
578c2ecf20Sopenharmony_ci	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq);
588c2ecf20Sopenharmony_ci	struct rk_cipher_ctx *op = crypto_skcipher_ctx(tfm);
598c2ecf20Sopenharmony_ci	struct rk_cipher_rctx *rctx = skcipher_request_ctx(areq);
608c2ecf20Sopenharmony_ci	int err;
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	skcipher_request_set_tfm(&rctx->fallback_req, op->fallback_tfm);
638c2ecf20Sopenharmony_ci	skcipher_request_set_callback(&rctx->fallback_req, areq->base.flags,
648c2ecf20Sopenharmony_ci				      areq->base.complete, areq->base.data);
658c2ecf20Sopenharmony_ci	skcipher_request_set_crypt(&rctx->fallback_req, areq->src, areq->dst,
668c2ecf20Sopenharmony_ci				   areq->cryptlen, areq->iv);
678c2ecf20Sopenharmony_ci	if (rctx->mode & RK_CRYPTO_DEC)
688c2ecf20Sopenharmony_ci		err = crypto_skcipher_decrypt(&rctx->fallback_req);
698c2ecf20Sopenharmony_ci	else
708c2ecf20Sopenharmony_ci		err = crypto_skcipher_encrypt(&rctx->fallback_req);
718c2ecf20Sopenharmony_ci	return err;
728c2ecf20Sopenharmony_ci}
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_cistatic int rk_handle_req(struct rk_crypto_info *dev,
758c2ecf20Sopenharmony_ci			 struct skcipher_request *req)
768c2ecf20Sopenharmony_ci{
778c2ecf20Sopenharmony_ci	struct crypto_engine *engine = dev->engine;
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	if (rk_cipher_need_fallback(req))
808c2ecf20Sopenharmony_ci		return rk_cipher_fallback(req);
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	return crypto_transfer_skcipher_request_to_engine(engine, req);
838c2ecf20Sopenharmony_ci}
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_cistatic int rk_aes_setkey(struct crypto_skcipher *cipher,
868c2ecf20Sopenharmony_ci			 const u8 *key, unsigned int keylen)
878c2ecf20Sopenharmony_ci{
888c2ecf20Sopenharmony_ci	struct crypto_tfm *tfm = crypto_skcipher_tfm(cipher);
898c2ecf20Sopenharmony_ci	struct rk_cipher_ctx *ctx = crypto_tfm_ctx(tfm);
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci	if (keylen != AES_KEYSIZE_128 && keylen != AES_KEYSIZE_192 &&
928c2ecf20Sopenharmony_ci	    keylen != AES_KEYSIZE_256)
938c2ecf20Sopenharmony_ci		return -EINVAL;
948c2ecf20Sopenharmony_ci	ctx->keylen = keylen;
958c2ecf20Sopenharmony_ci	memcpy(ctx->key, key, keylen);
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	return crypto_skcipher_setkey(ctx->fallback_tfm, key, keylen);
988c2ecf20Sopenharmony_ci}
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_cistatic int rk_des_setkey(struct crypto_skcipher *cipher,
1018c2ecf20Sopenharmony_ci			 const u8 *key, unsigned int keylen)
1028c2ecf20Sopenharmony_ci{
1038c2ecf20Sopenharmony_ci	struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(cipher);
1048c2ecf20Sopenharmony_ci	int err;
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci	err = verify_skcipher_des_key(cipher, key);
1078c2ecf20Sopenharmony_ci	if (err)
1088c2ecf20Sopenharmony_ci		return err;
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	ctx->keylen = keylen;
1118c2ecf20Sopenharmony_ci	memcpy(ctx->key, key, keylen);
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci	return crypto_skcipher_setkey(ctx->fallback_tfm, key, keylen);
1148c2ecf20Sopenharmony_ci}
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_cistatic int rk_tdes_setkey(struct crypto_skcipher *cipher,
1178c2ecf20Sopenharmony_ci			  const u8 *key, unsigned int keylen)
1188c2ecf20Sopenharmony_ci{
1198c2ecf20Sopenharmony_ci	struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(cipher);
1208c2ecf20Sopenharmony_ci	int err;
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci	err = verify_skcipher_des3_key(cipher, key);
1238c2ecf20Sopenharmony_ci	if (err)
1248c2ecf20Sopenharmony_ci		return err;
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	ctx->keylen = keylen;
1278c2ecf20Sopenharmony_ci	memcpy(ctx->key, key, keylen);
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci	return crypto_skcipher_setkey(ctx->fallback_tfm, key, keylen);
1308c2ecf20Sopenharmony_ci}
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_cistatic int rk_aes_ecb_encrypt(struct skcipher_request *req)
1338c2ecf20Sopenharmony_ci{
1348c2ecf20Sopenharmony_ci	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
1358c2ecf20Sopenharmony_ci	struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
1368c2ecf20Sopenharmony_ci	struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
1378c2ecf20Sopenharmony_ci	struct rk_crypto_info *dev = ctx->dev;
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci	rctx->mode = RK_CRYPTO_AES_ECB_MODE;
1408c2ecf20Sopenharmony_ci	return rk_handle_req(dev, req);
1418c2ecf20Sopenharmony_ci}
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_cistatic int rk_aes_ecb_decrypt(struct skcipher_request *req)
1448c2ecf20Sopenharmony_ci{
1458c2ecf20Sopenharmony_ci	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
1468c2ecf20Sopenharmony_ci	struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
1478c2ecf20Sopenharmony_ci	struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
1488c2ecf20Sopenharmony_ci	struct rk_crypto_info *dev = ctx->dev;
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci	rctx->mode = RK_CRYPTO_AES_ECB_MODE | RK_CRYPTO_DEC;
1518c2ecf20Sopenharmony_ci	return rk_handle_req(dev, req);
1528c2ecf20Sopenharmony_ci}
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_cistatic int rk_aes_cbc_encrypt(struct skcipher_request *req)
1558c2ecf20Sopenharmony_ci{
1568c2ecf20Sopenharmony_ci	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
1578c2ecf20Sopenharmony_ci	struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
1588c2ecf20Sopenharmony_ci	struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
1598c2ecf20Sopenharmony_ci	struct rk_crypto_info *dev = ctx->dev;
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci	rctx->mode = RK_CRYPTO_AES_CBC_MODE;
1628c2ecf20Sopenharmony_ci	return rk_handle_req(dev, req);
1638c2ecf20Sopenharmony_ci}
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_cistatic int rk_aes_cbc_decrypt(struct skcipher_request *req)
1668c2ecf20Sopenharmony_ci{
1678c2ecf20Sopenharmony_ci	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
1688c2ecf20Sopenharmony_ci	struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
1698c2ecf20Sopenharmony_ci	struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
1708c2ecf20Sopenharmony_ci	struct rk_crypto_info *dev = ctx->dev;
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci	rctx->mode = RK_CRYPTO_AES_CBC_MODE | RK_CRYPTO_DEC;
1738c2ecf20Sopenharmony_ci	return rk_handle_req(dev, req);
1748c2ecf20Sopenharmony_ci}
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_cistatic int rk_des_ecb_encrypt(struct skcipher_request *req)
1778c2ecf20Sopenharmony_ci{
1788c2ecf20Sopenharmony_ci	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
1798c2ecf20Sopenharmony_ci	struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
1808c2ecf20Sopenharmony_ci	struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
1818c2ecf20Sopenharmony_ci	struct rk_crypto_info *dev = ctx->dev;
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci	rctx->mode = 0;
1848c2ecf20Sopenharmony_ci	return rk_handle_req(dev, req);
1858c2ecf20Sopenharmony_ci}
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_cistatic int rk_des_ecb_decrypt(struct skcipher_request *req)
1888c2ecf20Sopenharmony_ci{
1898c2ecf20Sopenharmony_ci	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
1908c2ecf20Sopenharmony_ci	struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
1918c2ecf20Sopenharmony_ci	struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
1928c2ecf20Sopenharmony_ci	struct rk_crypto_info *dev = ctx->dev;
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci	rctx->mode = RK_CRYPTO_DEC;
1958c2ecf20Sopenharmony_ci	return rk_handle_req(dev, req);
1968c2ecf20Sopenharmony_ci}
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_cistatic int rk_des_cbc_encrypt(struct skcipher_request *req)
1998c2ecf20Sopenharmony_ci{
2008c2ecf20Sopenharmony_ci	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
2018c2ecf20Sopenharmony_ci	struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
2028c2ecf20Sopenharmony_ci	struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
2038c2ecf20Sopenharmony_ci	struct rk_crypto_info *dev = ctx->dev;
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci	rctx->mode = RK_CRYPTO_TDES_CHAINMODE_CBC;
2068c2ecf20Sopenharmony_ci	return rk_handle_req(dev, req);
2078c2ecf20Sopenharmony_ci}
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_cistatic int rk_des_cbc_decrypt(struct skcipher_request *req)
2108c2ecf20Sopenharmony_ci{
2118c2ecf20Sopenharmony_ci	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
2128c2ecf20Sopenharmony_ci	struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
2138c2ecf20Sopenharmony_ci	struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
2148c2ecf20Sopenharmony_ci	struct rk_crypto_info *dev = ctx->dev;
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci	rctx->mode = RK_CRYPTO_TDES_CHAINMODE_CBC | RK_CRYPTO_DEC;
2178c2ecf20Sopenharmony_ci	return rk_handle_req(dev, req);
2188c2ecf20Sopenharmony_ci}
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_cistatic int rk_des3_ede_ecb_encrypt(struct skcipher_request *req)
2218c2ecf20Sopenharmony_ci{
2228c2ecf20Sopenharmony_ci	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
2238c2ecf20Sopenharmony_ci	struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
2248c2ecf20Sopenharmony_ci	struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
2258c2ecf20Sopenharmony_ci	struct rk_crypto_info *dev = ctx->dev;
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci	rctx->mode = RK_CRYPTO_TDES_SELECT;
2288c2ecf20Sopenharmony_ci	return rk_handle_req(dev, req);
2298c2ecf20Sopenharmony_ci}
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_cistatic int rk_des3_ede_ecb_decrypt(struct skcipher_request *req)
2328c2ecf20Sopenharmony_ci{
2338c2ecf20Sopenharmony_ci	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
2348c2ecf20Sopenharmony_ci	struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
2358c2ecf20Sopenharmony_ci	struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
2368c2ecf20Sopenharmony_ci	struct rk_crypto_info *dev = ctx->dev;
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci	rctx->mode = RK_CRYPTO_TDES_SELECT | RK_CRYPTO_DEC;
2398c2ecf20Sopenharmony_ci	return rk_handle_req(dev, req);
2408c2ecf20Sopenharmony_ci}
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_cistatic int rk_des3_ede_cbc_encrypt(struct skcipher_request *req)
2438c2ecf20Sopenharmony_ci{
2448c2ecf20Sopenharmony_ci	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
2458c2ecf20Sopenharmony_ci	struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
2468c2ecf20Sopenharmony_ci	struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
2478c2ecf20Sopenharmony_ci	struct rk_crypto_info *dev = ctx->dev;
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci	rctx->mode = RK_CRYPTO_TDES_SELECT | RK_CRYPTO_TDES_CHAINMODE_CBC;
2508c2ecf20Sopenharmony_ci	return rk_handle_req(dev, req);
2518c2ecf20Sopenharmony_ci}
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_cistatic int rk_des3_ede_cbc_decrypt(struct skcipher_request *req)
2548c2ecf20Sopenharmony_ci{
2558c2ecf20Sopenharmony_ci	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
2568c2ecf20Sopenharmony_ci	struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
2578c2ecf20Sopenharmony_ci	struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
2588c2ecf20Sopenharmony_ci	struct rk_crypto_info *dev = ctx->dev;
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci	rctx->mode = RK_CRYPTO_TDES_SELECT | RK_CRYPTO_TDES_CHAINMODE_CBC |
2618c2ecf20Sopenharmony_ci		    RK_CRYPTO_DEC;
2628c2ecf20Sopenharmony_ci	return rk_handle_req(dev, req);
2638c2ecf20Sopenharmony_ci}
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_cistatic void rk_ablk_hw_init(struct rk_crypto_info *dev, struct skcipher_request *req)
2668c2ecf20Sopenharmony_ci{
2678c2ecf20Sopenharmony_ci	struct crypto_skcipher *cipher = crypto_skcipher_reqtfm(req);
2688c2ecf20Sopenharmony_ci	struct crypto_tfm *tfm = crypto_skcipher_tfm(cipher);
2698c2ecf20Sopenharmony_ci	struct rk_cipher_rctx *rctx = skcipher_request_ctx(req);
2708c2ecf20Sopenharmony_ci	struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(cipher);
2718c2ecf20Sopenharmony_ci	u32 block, conf_reg = 0;
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci	block = crypto_tfm_alg_blocksize(tfm);
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci	if (block == DES_BLOCK_SIZE) {
2768c2ecf20Sopenharmony_ci		rctx->mode |= RK_CRYPTO_TDES_FIFO_MODE |
2778c2ecf20Sopenharmony_ci			     RK_CRYPTO_TDES_BYTESWAP_KEY |
2788c2ecf20Sopenharmony_ci			     RK_CRYPTO_TDES_BYTESWAP_IV;
2798c2ecf20Sopenharmony_ci		CRYPTO_WRITE(dev, RK_CRYPTO_TDES_CTRL, rctx->mode);
2808c2ecf20Sopenharmony_ci		memcpy_toio(ctx->dev->reg + RK_CRYPTO_TDES_KEY1_0, ctx->key, ctx->keylen);
2818c2ecf20Sopenharmony_ci		conf_reg = RK_CRYPTO_DESSEL;
2828c2ecf20Sopenharmony_ci	} else {
2838c2ecf20Sopenharmony_ci		rctx->mode |= RK_CRYPTO_AES_FIFO_MODE |
2848c2ecf20Sopenharmony_ci			     RK_CRYPTO_AES_KEY_CHANGE |
2858c2ecf20Sopenharmony_ci			     RK_CRYPTO_AES_BYTESWAP_KEY |
2868c2ecf20Sopenharmony_ci			     RK_CRYPTO_AES_BYTESWAP_IV;
2878c2ecf20Sopenharmony_ci		if (ctx->keylen == AES_KEYSIZE_192)
2888c2ecf20Sopenharmony_ci			rctx->mode |= RK_CRYPTO_AES_192BIT_key;
2898c2ecf20Sopenharmony_ci		else if (ctx->keylen == AES_KEYSIZE_256)
2908c2ecf20Sopenharmony_ci			rctx->mode |= RK_CRYPTO_AES_256BIT_key;
2918c2ecf20Sopenharmony_ci		CRYPTO_WRITE(dev, RK_CRYPTO_AES_CTRL, rctx->mode);
2928c2ecf20Sopenharmony_ci		memcpy_toio(ctx->dev->reg + RK_CRYPTO_AES_KEY_0, ctx->key, ctx->keylen);
2938c2ecf20Sopenharmony_ci	}
2948c2ecf20Sopenharmony_ci	conf_reg |= RK_CRYPTO_BYTESWAP_BTFIFO |
2958c2ecf20Sopenharmony_ci		    RK_CRYPTO_BYTESWAP_BRFIFO;
2968c2ecf20Sopenharmony_ci	CRYPTO_WRITE(dev, RK_CRYPTO_CONF, conf_reg);
2978c2ecf20Sopenharmony_ci	CRYPTO_WRITE(dev, RK_CRYPTO_INTENA,
2988c2ecf20Sopenharmony_ci		     RK_CRYPTO_BCDMA_ERR_ENA | RK_CRYPTO_BCDMA_DONE_ENA);
2998c2ecf20Sopenharmony_ci}
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_cistatic void crypto_dma_start(struct rk_crypto_info *dev,
3028c2ecf20Sopenharmony_ci			     struct scatterlist *sgs,
3038c2ecf20Sopenharmony_ci			     struct scatterlist *sgd, unsigned int todo)
3048c2ecf20Sopenharmony_ci{
3058c2ecf20Sopenharmony_ci	CRYPTO_WRITE(dev, RK_CRYPTO_BRDMAS, sg_dma_address(sgs));
3068c2ecf20Sopenharmony_ci	CRYPTO_WRITE(dev, RK_CRYPTO_BRDMAL, todo);
3078c2ecf20Sopenharmony_ci	CRYPTO_WRITE(dev, RK_CRYPTO_BTDMAS, sg_dma_address(sgd));
3088c2ecf20Sopenharmony_ci	CRYPTO_WRITE(dev, RK_CRYPTO_CTRL, RK_CRYPTO_BLOCK_START |
3098c2ecf20Sopenharmony_ci		     _SBF(RK_CRYPTO_BLOCK_START, 16));
3108c2ecf20Sopenharmony_ci}
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_cistatic int rk_cipher_run(struct crypto_engine *engine, void *async_req)
3138c2ecf20Sopenharmony_ci{
3148c2ecf20Sopenharmony_ci	struct skcipher_request *areq = container_of(async_req, struct skcipher_request, base);
3158c2ecf20Sopenharmony_ci	struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(areq);
3168c2ecf20Sopenharmony_ci	struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
3178c2ecf20Sopenharmony_ci	struct rk_cipher_rctx *rctx = skcipher_request_ctx(areq);
3188c2ecf20Sopenharmony_ci	struct scatterlist *sgs, *sgd;
3198c2ecf20Sopenharmony_ci	int err = 0;
3208c2ecf20Sopenharmony_ci	int ivsize = crypto_skcipher_ivsize(tfm);
3218c2ecf20Sopenharmony_ci	int offset;
3228c2ecf20Sopenharmony_ci	u8 iv[AES_BLOCK_SIZE];
3238c2ecf20Sopenharmony_ci	u8 biv[AES_BLOCK_SIZE];
3248c2ecf20Sopenharmony_ci	u8 *ivtouse = areq->iv;
3258c2ecf20Sopenharmony_ci	unsigned int len = areq->cryptlen;
3268c2ecf20Sopenharmony_ci	unsigned int todo;
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci	ivsize = crypto_skcipher_ivsize(tfm);
3298c2ecf20Sopenharmony_ci	if (areq->iv && crypto_skcipher_ivsize(tfm) > 0) {
3308c2ecf20Sopenharmony_ci		if (rctx->mode & RK_CRYPTO_DEC) {
3318c2ecf20Sopenharmony_ci			offset = areq->cryptlen - ivsize;
3328c2ecf20Sopenharmony_ci			scatterwalk_map_and_copy(rctx->backup_iv, areq->src,
3338c2ecf20Sopenharmony_ci						 offset, ivsize, 0);
3348c2ecf20Sopenharmony_ci		}
3358c2ecf20Sopenharmony_ci	}
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ci	sgs = areq->src;
3388c2ecf20Sopenharmony_ci	sgd = areq->dst;
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_ci	while (sgs && sgd && len) {
3418c2ecf20Sopenharmony_ci		if (!sgs->length) {
3428c2ecf20Sopenharmony_ci			sgs = sg_next(sgs);
3438c2ecf20Sopenharmony_ci			sgd = sg_next(sgd);
3448c2ecf20Sopenharmony_ci			continue;
3458c2ecf20Sopenharmony_ci		}
3468c2ecf20Sopenharmony_ci		if (rctx->mode & RK_CRYPTO_DEC) {
3478c2ecf20Sopenharmony_ci			/* we backup last block of source to be used as IV at next step */
3488c2ecf20Sopenharmony_ci			offset = sgs->length - ivsize;
3498c2ecf20Sopenharmony_ci			scatterwalk_map_and_copy(biv, sgs, offset, ivsize, 0);
3508c2ecf20Sopenharmony_ci		}
3518c2ecf20Sopenharmony_ci		if (sgs == sgd) {
3528c2ecf20Sopenharmony_ci			err = dma_map_sg(ctx->dev->dev, sgs, 1, DMA_BIDIRECTIONAL);
3538c2ecf20Sopenharmony_ci			if (err <= 0) {
3548c2ecf20Sopenharmony_ci				err = -EINVAL;
3558c2ecf20Sopenharmony_ci				goto theend_iv;
3568c2ecf20Sopenharmony_ci			}
3578c2ecf20Sopenharmony_ci		} else {
3588c2ecf20Sopenharmony_ci			err = dma_map_sg(ctx->dev->dev, sgs, 1, DMA_TO_DEVICE);
3598c2ecf20Sopenharmony_ci			if (err <= 0) {
3608c2ecf20Sopenharmony_ci				err = -EINVAL;
3618c2ecf20Sopenharmony_ci				goto theend_iv;
3628c2ecf20Sopenharmony_ci			}
3638c2ecf20Sopenharmony_ci			err = dma_map_sg(ctx->dev->dev, sgd, 1, DMA_FROM_DEVICE);
3648c2ecf20Sopenharmony_ci			if (err <= 0) {
3658c2ecf20Sopenharmony_ci				err = -EINVAL;
3668c2ecf20Sopenharmony_ci				goto theend_sgs;
3678c2ecf20Sopenharmony_ci			}
3688c2ecf20Sopenharmony_ci		}
3698c2ecf20Sopenharmony_ci		err = 0;
3708c2ecf20Sopenharmony_ci		rk_ablk_hw_init(ctx->dev, areq);
3718c2ecf20Sopenharmony_ci		if (ivsize) {
3728c2ecf20Sopenharmony_ci			if (ivsize == DES_BLOCK_SIZE)
3738c2ecf20Sopenharmony_ci				memcpy_toio(ctx->dev->reg + RK_CRYPTO_TDES_IV_0, ivtouse, ivsize);
3748c2ecf20Sopenharmony_ci			else
3758c2ecf20Sopenharmony_ci				memcpy_toio(ctx->dev->reg + RK_CRYPTO_AES_IV_0, ivtouse, ivsize);
3768c2ecf20Sopenharmony_ci		}
3778c2ecf20Sopenharmony_ci		reinit_completion(&ctx->dev->complete);
3788c2ecf20Sopenharmony_ci		ctx->dev->status = 0;
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci		todo = min(sg_dma_len(sgs), len);
3818c2ecf20Sopenharmony_ci		len -= todo;
3828c2ecf20Sopenharmony_ci		crypto_dma_start(ctx->dev, sgs, sgd, todo / 4);
3838c2ecf20Sopenharmony_ci		wait_for_completion_interruptible_timeout(&ctx->dev->complete,
3848c2ecf20Sopenharmony_ci							  msecs_to_jiffies(2000));
3858c2ecf20Sopenharmony_ci		if (!ctx->dev->status) {
3868c2ecf20Sopenharmony_ci			dev_err(ctx->dev->dev, "DMA timeout\n");
3878c2ecf20Sopenharmony_ci			err = -EFAULT;
3888c2ecf20Sopenharmony_ci			goto theend;
3898c2ecf20Sopenharmony_ci		}
3908c2ecf20Sopenharmony_ci		if (sgs == sgd) {
3918c2ecf20Sopenharmony_ci			dma_unmap_sg(ctx->dev->dev, sgs, 1, DMA_BIDIRECTIONAL);
3928c2ecf20Sopenharmony_ci		} else {
3938c2ecf20Sopenharmony_ci			dma_unmap_sg(ctx->dev->dev, sgs, 1, DMA_TO_DEVICE);
3948c2ecf20Sopenharmony_ci			dma_unmap_sg(ctx->dev->dev, sgd, 1, DMA_FROM_DEVICE);
3958c2ecf20Sopenharmony_ci		}
3968c2ecf20Sopenharmony_ci		if (rctx->mode & RK_CRYPTO_DEC) {
3978c2ecf20Sopenharmony_ci			memcpy(iv, biv, ivsize);
3988c2ecf20Sopenharmony_ci			ivtouse = iv;
3998c2ecf20Sopenharmony_ci		} else {
4008c2ecf20Sopenharmony_ci			offset = sgd->length - ivsize;
4018c2ecf20Sopenharmony_ci			scatterwalk_map_and_copy(iv, sgd, offset, ivsize, 0);
4028c2ecf20Sopenharmony_ci			ivtouse = iv;
4038c2ecf20Sopenharmony_ci		}
4048c2ecf20Sopenharmony_ci		sgs = sg_next(sgs);
4058c2ecf20Sopenharmony_ci		sgd = sg_next(sgd);
4068c2ecf20Sopenharmony_ci	}
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_ci	if (areq->iv && ivsize > 0) {
4098c2ecf20Sopenharmony_ci		offset = areq->cryptlen - ivsize;
4108c2ecf20Sopenharmony_ci		if (rctx->mode & RK_CRYPTO_DEC) {
4118c2ecf20Sopenharmony_ci			memcpy(areq->iv, rctx->backup_iv, ivsize);
4128c2ecf20Sopenharmony_ci			memzero_explicit(rctx->backup_iv, ivsize);
4138c2ecf20Sopenharmony_ci		} else {
4148c2ecf20Sopenharmony_ci			scatterwalk_map_and_copy(areq->iv, areq->dst, offset,
4158c2ecf20Sopenharmony_ci						 ivsize, 0);
4168c2ecf20Sopenharmony_ci		}
4178c2ecf20Sopenharmony_ci	}
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_citheend:
4208c2ecf20Sopenharmony_ci	local_bh_disable();
4218c2ecf20Sopenharmony_ci	crypto_finalize_skcipher_request(engine, areq, err);
4228c2ecf20Sopenharmony_ci	local_bh_enable();
4238c2ecf20Sopenharmony_ci	return 0;
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_citheend_sgs:
4268c2ecf20Sopenharmony_ci	if (sgs == sgd) {
4278c2ecf20Sopenharmony_ci		dma_unmap_sg(ctx->dev->dev, sgs, 1, DMA_BIDIRECTIONAL);
4288c2ecf20Sopenharmony_ci	} else {
4298c2ecf20Sopenharmony_ci		dma_unmap_sg(ctx->dev->dev, sgs, 1, DMA_TO_DEVICE);
4308c2ecf20Sopenharmony_ci		dma_unmap_sg(ctx->dev->dev, sgd, 1, DMA_FROM_DEVICE);
4318c2ecf20Sopenharmony_ci	}
4328c2ecf20Sopenharmony_citheend_iv:
4338c2ecf20Sopenharmony_ci	return err;
4348c2ecf20Sopenharmony_ci}
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_cistatic int rk_ablk_init_tfm(struct crypto_skcipher *tfm)
4378c2ecf20Sopenharmony_ci{
4388c2ecf20Sopenharmony_ci	struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
4398c2ecf20Sopenharmony_ci	struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
4408c2ecf20Sopenharmony_ci	const char *name = crypto_tfm_alg_name(&tfm->base);
4418c2ecf20Sopenharmony_ci	struct rk_crypto_tmp *algt;
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_ci	algt = container_of(alg, struct rk_crypto_tmp, alg.skcipher);
4448c2ecf20Sopenharmony_ci
4458c2ecf20Sopenharmony_ci	ctx->dev = algt->dev;
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ci	ctx->fallback_tfm = crypto_alloc_skcipher(name, 0, CRYPTO_ALG_NEED_FALLBACK);
4488c2ecf20Sopenharmony_ci	if (IS_ERR(ctx->fallback_tfm)) {
4498c2ecf20Sopenharmony_ci		dev_err(ctx->dev->dev, "ERROR: Cannot allocate fallback for %s %ld\n",
4508c2ecf20Sopenharmony_ci			name, PTR_ERR(ctx->fallback_tfm));
4518c2ecf20Sopenharmony_ci		return PTR_ERR(ctx->fallback_tfm);
4528c2ecf20Sopenharmony_ci	}
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_ci	tfm->reqsize = sizeof(struct rk_cipher_rctx) +
4558c2ecf20Sopenharmony_ci		crypto_skcipher_reqsize(ctx->fallback_tfm);
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_ci	ctx->enginectx.op.do_one_request = rk_cipher_run;
4588c2ecf20Sopenharmony_ci
4598c2ecf20Sopenharmony_ci	return 0;
4608c2ecf20Sopenharmony_ci}
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_cistatic void rk_ablk_exit_tfm(struct crypto_skcipher *tfm)
4638c2ecf20Sopenharmony_ci{
4648c2ecf20Sopenharmony_ci	struct rk_cipher_ctx *ctx = crypto_skcipher_ctx(tfm);
4658c2ecf20Sopenharmony_ci
4668c2ecf20Sopenharmony_ci	memzero_explicit(ctx->key, ctx->keylen);
4678c2ecf20Sopenharmony_ci	crypto_free_skcipher(ctx->fallback_tfm);
4688c2ecf20Sopenharmony_ci}
4698c2ecf20Sopenharmony_ci
4708c2ecf20Sopenharmony_cistruct rk_crypto_tmp rk_ecb_aes_alg = {
4718c2ecf20Sopenharmony_ci	.type = ALG_TYPE_CIPHER,
4728c2ecf20Sopenharmony_ci	.alg.skcipher = {
4738c2ecf20Sopenharmony_ci		.base.cra_name		= "ecb(aes)",
4748c2ecf20Sopenharmony_ci		.base.cra_driver_name	= "ecb-aes-rk",
4758c2ecf20Sopenharmony_ci		.base.cra_priority	= 300,
4768c2ecf20Sopenharmony_ci		.base.cra_flags		= CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK,
4778c2ecf20Sopenharmony_ci		.base.cra_blocksize	= AES_BLOCK_SIZE,
4788c2ecf20Sopenharmony_ci		.base.cra_ctxsize	= sizeof(struct rk_cipher_ctx),
4798c2ecf20Sopenharmony_ci		.base.cra_alignmask	= 0x0f,
4808c2ecf20Sopenharmony_ci		.base.cra_module	= THIS_MODULE,
4818c2ecf20Sopenharmony_ci
4828c2ecf20Sopenharmony_ci		.init			= rk_ablk_init_tfm,
4838c2ecf20Sopenharmony_ci		.exit			= rk_ablk_exit_tfm,
4848c2ecf20Sopenharmony_ci		.min_keysize		= AES_MIN_KEY_SIZE,
4858c2ecf20Sopenharmony_ci		.max_keysize		= AES_MAX_KEY_SIZE,
4868c2ecf20Sopenharmony_ci		.setkey			= rk_aes_setkey,
4878c2ecf20Sopenharmony_ci		.encrypt		= rk_aes_ecb_encrypt,
4888c2ecf20Sopenharmony_ci		.decrypt		= rk_aes_ecb_decrypt,
4898c2ecf20Sopenharmony_ci	}
4908c2ecf20Sopenharmony_ci};
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_cistruct rk_crypto_tmp rk_cbc_aes_alg = {
4938c2ecf20Sopenharmony_ci	.type = ALG_TYPE_CIPHER,
4948c2ecf20Sopenharmony_ci	.alg.skcipher = {
4958c2ecf20Sopenharmony_ci		.base.cra_name		= "cbc(aes)",
4968c2ecf20Sopenharmony_ci		.base.cra_driver_name	= "cbc-aes-rk",
4978c2ecf20Sopenharmony_ci		.base.cra_priority	= 300,
4988c2ecf20Sopenharmony_ci		.base.cra_flags		= CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK,
4998c2ecf20Sopenharmony_ci		.base.cra_blocksize	= AES_BLOCK_SIZE,
5008c2ecf20Sopenharmony_ci		.base.cra_ctxsize	= sizeof(struct rk_cipher_ctx),
5018c2ecf20Sopenharmony_ci		.base.cra_alignmask	= 0x0f,
5028c2ecf20Sopenharmony_ci		.base.cra_module	= THIS_MODULE,
5038c2ecf20Sopenharmony_ci
5048c2ecf20Sopenharmony_ci		.init			= rk_ablk_init_tfm,
5058c2ecf20Sopenharmony_ci		.exit			= rk_ablk_exit_tfm,
5068c2ecf20Sopenharmony_ci		.min_keysize		= AES_MIN_KEY_SIZE,
5078c2ecf20Sopenharmony_ci		.max_keysize		= AES_MAX_KEY_SIZE,
5088c2ecf20Sopenharmony_ci		.ivsize			= AES_BLOCK_SIZE,
5098c2ecf20Sopenharmony_ci		.setkey			= rk_aes_setkey,
5108c2ecf20Sopenharmony_ci		.encrypt		= rk_aes_cbc_encrypt,
5118c2ecf20Sopenharmony_ci		.decrypt		= rk_aes_cbc_decrypt,
5128c2ecf20Sopenharmony_ci	}
5138c2ecf20Sopenharmony_ci};
5148c2ecf20Sopenharmony_ci
5158c2ecf20Sopenharmony_cistruct rk_crypto_tmp rk_ecb_des_alg = {
5168c2ecf20Sopenharmony_ci	.type = ALG_TYPE_CIPHER,
5178c2ecf20Sopenharmony_ci	.alg.skcipher = {
5188c2ecf20Sopenharmony_ci		.base.cra_name		= "ecb(des)",
5198c2ecf20Sopenharmony_ci		.base.cra_driver_name	= "ecb-des-rk",
5208c2ecf20Sopenharmony_ci		.base.cra_priority	= 300,
5218c2ecf20Sopenharmony_ci		.base.cra_flags		= CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK,
5228c2ecf20Sopenharmony_ci		.base.cra_blocksize	= DES_BLOCK_SIZE,
5238c2ecf20Sopenharmony_ci		.base.cra_ctxsize	= sizeof(struct rk_cipher_ctx),
5248c2ecf20Sopenharmony_ci		.base.cra_alignmask	= 0x07,
5258c2ecf20Sopenharmony_ci		.base.cra_module	= THIS_MODULE,
5268c2ecf20Sopenharmony_ci
5278c2ecf20Sopenharmony_ci		.init			= rk_ablk_init_tfm,
5288c2ecf20Sopenharmony_ci		.exit			= rk_ablk_exit_tfm,
5298c2ecf20Sopenharmony_ci		.min_keysize		= DES_KEY_SIZE,
5308c2ecf20Sopenharmony_ci		.max_keysize		= DES_KEY_SIZE,
5318c2ecf20Sopenharmony_ci		.setkey			= rk_des_setkey,
5328c2ecf20Sopenharmony_ci		.encrypt		= rk_des_ecb_encrypt,
5338c2ecf20Sopenharmony_ci		.decrypt		= rk_des_ecb_decrypt,
5348c2ecf20Sopenharmony_ci	}
5358c2ecf20Sopenharmony_ci};
5368c2ecf20Sopenharmony_ci
5378c2ecf20Sopenharmony_cistruct rk_crypto_tmp rk_cbc_des_alg = {
5388c2ecf20Sopenharmony_ci	.type = ALG_TYPE_CIPHER,
5398c2ecf20Sopenharmony_ci	.alg.skcipher = {
5408c2ecf20Sopenharmony_ci		.base.cra_name		= "cbc(des)",
5418c2ecf20Sopenharmony_ci		.base.cra_driver_name	= "cbc-des-rk",
5428c2ecf20Sopenharmony_ci		.base.cra_priority	= 300,
5438c2ecf20Sopenharmony_ci		.base.cra_flags		= CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK,
5448c2ecf20Sopenharmony_ci		.base.cra_blocksize	= DES_BLOCK_SIZE,
5458c2ecf20Sopenharmony_ci		.base.cra_ctxsize	= sizeof(struct rk_cipher_ctx),
5468c2ecf20Sopenharmony_ci		.base.cra_alignmask	= 0x07,
5478c2ecf20Sopenharmony_ci		.base.cra_module	= THIS_MODULE,
5488c2ecf20Sopenharmony_ci
5498c2ecf20Sopenharmony_ci		.init			= rk_ablk_init_tfm,
5508c2ecf20Sopenharmony_ci		.exit			= rk_ablk_exit_tfm,
5518c2ecf20Sopenharmony_ci		.min_keysize		= DES_KEY_SIZE,
5528c2ecf20Sopenharmony_ci		.max_keysize		= DES_KEY_SIZE,
5538c2ecf20Sopenharmony_ci		.ivsize			= DES_BLOCK_SIZE,
5548c2ecf20Sopenharmony_ci		.setkey			= rk_des_setkey,
5558c2ecf20Sopenharmony_ci		.encrypt		= rk_des_cbc_encrypt,
5568c2ecf20Sopenharmony_ci		.decrypt		= rk_des_cbc_decrypt,
5578c2ecf20Sopenharmony_ci	}
5588c2ecf20Sopenharmony_ci};
5598c2ecf20Sopenharmony_ci
5608c2ecf20Sopenharmony_cistruct rk_crypto_tmp rk_ecb_des3_ede_alg = {
5618c2ecf20Sopenharmony_ci	.type = ALG_TYPE_CIPHER,
5628c2ecf20Sopenharmony_ci	.alg.skcipher = {
5638c2ecf20Sopenharmony_ci		.base.cra_name		= "ecb(des3_ede)",
5648c2ecf20Sopenharmony_ci		.base.cra_driver_name	= "ecb-des3-ede-rk",
5658c2ecf20Sopenharmony_ci		.base.cra_priority	= 300,
5668c2ecf20Sopenharmony_ci		.base.cra_flags		= CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK,
5678c2ecf20Sopenharmony_ci		.base.cra_blocksize	= DES_BLOCK_SIZE,
5688c2ecf20Sopenharmony_ci		.base.cra_ctxsize	= sizeof(struct rk_cipher_ctx),
5698c2ecf20Sopenharmony_ci		.base.cra_alignmask	= 0x07,
5708c2ecf20Sopenharmony_ci		.base.cra_module	= THIS_MODULE,
5718c2ecf20Sopenharmony_ci
5728c2ecf20Sopenharmony_ci		.init			= rk_ablk_init_tfm,
5738c2ecf20Sopenharmony_ci		.exit			= rk_ablk_exit_tfm,
5748c2ecf20Sopenharmony_ci		.min_keysize		= DES3_EDE_KEY_SIZE,
5758c2ecf20Sopenharmony_ci		.max_keysize		= DES3_EDE_KEY_SIZE,
5768c2ecf20Sopenharmony_ci		.setkey			= rk_tdes_setkey,
5778c2ecf20Sopenharmony_ci		.encrypt		= rk_des3_ede_ecb_encrypt,
5788c2ecf20Sopenharmony_ci		.decrypt		= rk_des3_ede_ecb_decrypt,
5798c2ecf20Sopenharmony_ci	}
5808c2ecf20Sopenharmony_ci};
5818c2ecf20Sopenharmony_ci
5828c2ecf20Sopenharmony_cistruct rk_crypto_tmp rk_cbc_des3_ede_alg = {
5838c2ecf20Sopenharmony_ci	.type = ALG_TYPE_CIPHER,
5848c2ecf20Sopenharmony_ci	.alg.skcipher = {
5858c2ecf20Sopenharmony_ci		.base.cra_name		= "cbc(des3_ede)",
5868c2ecf20Sopenharmony_ci		.base.cra_driver_name	= "cbc-des3-ede-rk",
5878c2ecf20Sopenharmony_ci		.base.cra_priority	= 300,
5888c2ecf20Sopenharmony_ci		.base.cra_flags		= CRYPTO_ALG_ASYNC | CRYPTO_ALG_NEED_FALLBACK,
5898c2ecf20Sopenharmony_ci		.base.cra_blocksize	= DES_BLOCK_SIZE,
5908c2ecf20Sopenharmony_ci		.base.cra_ctxsize	= sizeof(struct rk_cipher_ctx),
5918c2ecf20Sopenharmony_ci		.base.cra_alignmask	= 0x07,
5928c2ecf20Sopenharmony_ci		.base.cra_module	= THIS_MODULE,
5938c2ecf20Sopenharmony_ci
5948c2ecf20Sopenharmony_ci		.init			= rk_ablk_init_tfm,
5958c2ecf20Sopenharmony_ci		.exit			= rk_ablk_exit_tfm,
5968c2ecf20Sopenharmony_ci		.min_keysize		= DES3_EDE_KEY_SIZE,
5978c2ecf20Sopenharmony_ci		.max_keysize		= DES3_EDE_KEY_SIZE,
5988c2ecf20Sopenharmony_ci		.ivsize			= DES_BLOCK_SIZE,
5998c2ecf20Sopenharmony_ci		.setkey			= rk_tdes_setkey,
6008c2ecf20Sopenharmony_ci		.encrypt		= rk_des3_ede_cbc_encrypt,
6018c2ecf20Sopenharmony_ci		.decrypt		= rk_des3_ede_cbc_decrypt,
6028c2ecf20Sopenharmony_ci	}
6038c2ecf20Sopenharmony_ci};
604