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-ss.h - hardware cryptographic offloader for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Allwinner A80/A83T SoC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2016-2019 Corentin LABBE <clabbe.montjoie@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <crypto/aes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <crypto/des.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <crypto/engine.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <crypto/rng.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <crypto/skcipher.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/crypto.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/md5.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <crypto/sha.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define SS_START	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define SS_ENCRYPTION		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define SS_DECRYPTION		BIT(6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define SS_ALG_AES		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define SS_ALG_DES		(1 << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define SS_ALG_3DES		(2 << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define SS_ALG_MD5		(3 << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define SS_ALG_PRNG		(4 << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define SS_ALG_SHA1		(6 << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define SS_ALG_SHA224		(7 << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define SS_ALG_SHA256		(8 << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define SS_CTL_REG		0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define SS_INT_CTL_REG		0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define SS_INT_STA_REG		0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define SS_KEY_ADR_REG		0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define SS_IV_ADR_REG		0x18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define SS_SRC_ADR_REG		0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define SS_DST_ADR_REG		0x28
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define SS_LEN_ADR_REG		0x30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define SS_ID_NOTSUPP		0xFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define SS_ID_CIPHER_AES	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define SS_ID_CIPHER_DES	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define SS_ID_CIPHER_DES3	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define SS_ID_CIPHER_MAX	3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #define SS_ID_OP_ECB	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define SS_ID_OP_CBC	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define SS_ID_OP_MAX	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #define SS_AES_128BITS 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #define SS_AES_192BITS 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #define SS_AES_256BITS 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define SS_OP_ECB	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #define SS_OP_CBC	(1 << 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) #define SS_ID_HASH_MD5	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #define SS_ID_HASH_SHA1	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #define SS_ID_HASH_SHA224	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #define SS_ID_HASH_SHA256	3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #define SS_ID_HASH_MAX	4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #define SS_FLOW0	BIT(30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) #define SS_FLOW1	BIT(31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) #define SS_PRNG_CONTINUE	BIT(18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) #define MAX_SG 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) #define MAXFLOW 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) #define SS_MAX_CLOCKS 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #define SS_DIE_ID_SHIFT	20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) #define SS_DIE_ID_MASK	0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) #define PRNG_DATA_SIZE (160 / 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) #define PRNG_SEED_SIZE DIV_ROUND_UP(175, 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  * struct ss_clock - Describe clocks used by sun8i-ss
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  * @name:       Name of clock needed by this variant
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  * @freq:       Frequency to set for each clock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)  * @max_freq:   Maximum frequency for each clock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) struct ss_clock {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	unsigned long freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	unsigned long max_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  * struct ss_variant - Describe SS capability for each variant hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * @alg_cipher:	list of supported ciphers. for each SS_ID_ this will give the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  *              coresponding SS_ALG_XXX value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * @alg_hash:	list of supported hashes. for each SS_ID_ this will give the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  *              corresponding SS_ALG_XXX value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  * @op_mode:	list of supported block modes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  * @ss_clks:	list of clock needed by this variant
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct ss_variant {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	char alg_cipher[SS_ID_CIPHER_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	char alg_hash[SS_ID_HASH_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	u32 op_mode[SS_ID_OP_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	struct ss_clock ss_clks[SS_MAX_CLOCKS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct sginfo {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	u32 addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	u32 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  * struct sun8i_ss_flow - Information used by each flow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  * @engine:	ptr to the crypto_engine for this flow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  * @complete:	completion for the current task on this flow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  * @status:	set to 1 by interrupt if task is done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  * @stat_req:	number of request done by this flow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct sun8i_ss_flow {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	struct crypto_engine *engine;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	struct completion complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) #ifdef CONFIG_CRYPTO_DEV_SUN8I_SS_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	unsigned long stat_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) };
^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)  * struct sun8i_ss_dev - main container for all this driver information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  * @base:	base address of SS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  * @ssclks:	clocks used by SS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  * @reset:	pointer to reset controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  * @dev:	the platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  * @mlock:	Control access to device registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  * @flows:	array of all flow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)  * @flow:	flow to use in next request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  * @variant:	pointer to variant specific data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  * @dbgfs_dir:	Debugfs dentry for statistic directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  * @dbgfs_stats: Debugfs dentry for statistic counters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct sun8i_ss_dev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	void __iomem *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	struct clk *ssclks[SS_MAX_CLOCKS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	struct reset_control *reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	struct mutex mlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	struct sun8i_ss_flow *flows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	atomic_t flow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	const struct ss_variant *variant;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #ifdef CONFIG_CRYPTO_DEV_SUN8I_SS_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	struct dentry *dbgfs_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	struct dentry *dbgfs_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  * struct sun8i_cipher_req_ctx - context for a skcipher request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  * @t_src:		list of mapped SGs with their size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)  * @t_dst:		list of mapped SGs with their size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)  * @p_key:		DMA address of the key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)  * @p_iv:		DMA address of the IV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)  * @method:		current algorithm for this request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)  * @op_mode:		op_mode for this request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)  * @op_dir:		direction (encrypt vs decrypt) for this request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)  * @flow:		the flow to use for this request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)  * @ivlen:		size of biv
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)  * @keylen:		keylen for this request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)  * @biv:		buffer which contain the IV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)  * @fallback_req:	request struct for invoking the fallback skcipher TFM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct sun8i_cipher_req_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	struct sginfo t_src[MAX_SG];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	struct sginfo t_dst[MAX_SG];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	u32 p_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	u32 p_iv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	u32 method;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	u32 op_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	u32 op_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	int flow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	unsigned int ivlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	unsigned int keylen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	void *biv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	struct skcipher_request fallback_req;   // keep at the end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)  * struct sun8i_cipher_tfm_ctx - context for a skcipher TFM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)  * @enginectx:		crypto_engine used by this TFM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)  * @key:		pointer to key data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)  * @keylen:		len of the key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)  * @ss:			pointer to the private data of driver handling this TFM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)  * @fallback_tfm:	pointer to the fallback TFM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  * enginectx must be the first element
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct sun8i_cipher_tfm_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	struct crypto_engine_ctx enginectx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	u32 *key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	u32 keylen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	struct sun8i_ss_dev *ss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	struct crypto_skcipher *fallback_tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)  * struct sun8i_ss_prng_ctx - context for PRNG TFM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  * @seed:	The seed to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  * @slen:	The size of the seed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct sun8i_ss_rng_tfm_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	void *seed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	unsigned int slen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  * struct sun8i_ss_hash_tfm_ctx - context for an ahash TFM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)  * @enginectx:		crypto_engine used by this TFM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)  * @fallback_tfm:	pointer to the fallback TFM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)  * @ss:			pointer to the private data of driver handling this TFM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)  * enginectx must be the first element
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct sun8i_ss_hash_tfm_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	struct crypto_engine_ctx enginectx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	struct crypto_ahash *fallback_tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	struct sun8i_ss_dev *ss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  * struct sun8i_ss_hash_reqctx - context for an ahash request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  * @t_src:	list of DMA address and size for source SGs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  * @t_dst:	list of DMA address and size for destination SGs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  * @fallback_req:	pre-allocated fallback request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  * @method:	the register value for the algorithm used by this request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  * @flow:	the flow to use for this request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct sun8i_ss_hash_reqctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	struct sginfo t_src[MAX_SG];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	struct sginfo t_dst[MAX_SG];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	struct ahash_request fallback_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	u32 method;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	int flow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) };
^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)  * struct sun8i_ss_alg_template - crypto_alg template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)  * @type:		the CRYPTO_ALG_TYPE for this template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)  * @ss_algo_id:		the SS_ID for this template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)  * @ss_blockmode:	the type of block operation SS_ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)  * @ss:			pointer to the sun8i_ss_dev structure associated with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)  *			this template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)  * @alg:		one of sub struct must be used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)  * @stat_req:		number of request done on this template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)  * @stat_fb:		number of request which has fallbacked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)  * @stat_bytes:		total data size done by this template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) struct sun8i_ss_alg_template {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	u32 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	u32 ss_algo_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	u32 ss_blockmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	struct sun8i_ss_dev *ss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		struct skcipher_alg skcipher;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		struct rng_alg rng;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		struct ahash_alg hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	} alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) #ifdef CONFIG_CRYPTO_DEV_SUN8I_SS_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	unsigned long stat_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	unsigned long stat_fb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	unsigned long stat_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) int sun8i_ss_enqueue(struct crypto_async_request *areq, u32 type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) int sun8i_ss_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 			unsigned int keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) int sun8i_ss_des3_setkey(struct crypto_skcipher *tfm, const u8 *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			 unsigned int keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) int sun8i_ss_cipher_init(struct crypto_tfm *tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) void sun8i_ss_cipher_exit(struct crypto_tfm *tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) int sun8i_ss_skdecrypt(struct skcipher_request *areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) int sun8i_ss_skencrypt(struct skcipher_request *areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) int sun8i_ss_get_engine_number(struct sun8i_ss_dev *ss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) int sun8i_ss_run_task(struct sun8i_ss_dev *ss, struct sun8i_cipher_req_ctx *rctx, const char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) int sun8i_ss_prng_generate(struct crypto_rng *tfm, const u8 *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 			   unsigned int slen, u8 *dst, unsigned int dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) int sun8i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed, unsigned int slen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) int sun8i_ss_prng_init(struct crypto_tfm *tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) void sun8i_ss_prng_exit(struct crypto_tfm *tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) int sun8i_ss_hash_crainit(struct crypto_tfm *tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) void sun8i_ss_hash_craexit(struct crypto_tfm *tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) int sun8i_ss_hash_init(struct ahash_request *areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) int sun8i_ss_hash_export(struct ahash_request *areq, void *out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) int sun8i_ss_hash_import(struct ahash_request *areq, const void *in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) int sun8i_ss_hash_final(struct ahash_request *areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) int sun8i_ss_hash_update(struct ahash_request *areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) int sun8i_ss_hash_finup(struct ahash_request *areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) int sun8i_ss_hash_digest(struct ahash_request *areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) int sun8i_ss_hash_run(struct crypto_engine *engine, void *breq);