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.h - hardware cryptographic offloader for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Allwinner H3/A64/H5/H2+/H6 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/skcipher.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/crypto.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/hw_random.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/rng.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <crypto/sha.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) /* CE Registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define CE_TDQ	0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define CE_CTR	0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define CE_ICR	0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define CE_ISR	0x0C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define CE_TLR	0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define CE_TSR	0x14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define CE_ESR	0x18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define CE_CSSGR	0x1C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define CE_CDSGR	0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define CE_CSAR	0x24
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define CE_CDAR	0x28
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define CE_TPR	0x2C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) /* Used in struct ce_task */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) /* ce_task common */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define CE_ENCRYPTION		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define CE_DECRYPTION		BIT(8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define CE_COMM_INT		BIT(31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) /* ce_task symmetric */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define CE_AES_128BITS 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define CE_AES_192BITS 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define CE_AES_256BITS 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define CE_OP_ECB	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define CE_OP_CBC	(1 << 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #define CE_ALG_AES		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define CE_ALG_DES		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define CE_ALG_3DES		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #define CE_ALG_MD5              16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #define CE_ALG_SHA1             17
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #define CE_ALG_SHA224           18
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #define CE_ALG_SHA256           19
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #define CE_ALG_SHA384           20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #define CE_ALG_SHA512           21
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #define CE_ALG_TRNG		48
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #define CE_ALG_PRNG		49
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) #define CE_ALG_TRNG_V2		0x1c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #define CE_ALG_PRNG_V2		0x1d
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) /* Used in ce_variant */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #define CE_ID_NOTSUPP		0xFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #define CE_ID_CIPHER_AES	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) #define CE_ID_CIPHER_DES	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) #define CE_ID_CIPHER_DES3	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) #define CE_ID_CIPHER_MAX	3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) #define CE_ID_HASH_MD5		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) #define CE_ID_HASH_SHA1		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) #define CE_ID_HASH_SHA224	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) #define CE_ID_HASH_SHA256	3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) #define CE_ID_HASH_SHA384	4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) #define CE_ID_HASH_SHA512	5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) #define CE_ID_HASH_MAX		6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) #define CE_ID_OP_ECB	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) #define CE_ID_OP_CBC	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) #define CE_ID_OP_MAX	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) /* Used in CE registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) #define CE_ERR_ALGO_NOTSUP	BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) #define CE_ERR_DATALEN		BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) #define CE_ERR_KEYSRAM		BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) #define CE_ERR_ADDR_INVALID	BIT(5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) #define CE_ERR_KEYLADDER	BIT(6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) #define ESR_H3	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) #define ESR_A64	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) #define ESR_R40	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) #define ESR_H5	3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) #define ESR_H6	4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) #define PRNG_DATA_SIZE (160 / 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) #define PRNG_SEED_SIZE DIV_ROUND_UP(175, 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) #define PRNG_LD BIT(17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define CE_DIE_ID_SHIFT	16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define CE_DIE_ID_MASK	0x07
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define MAX_SG 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define CE_MAX_CLOCKS 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #define MAXFLOW 4
^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)  * struct ce_clock - Describe clocks used by sun8i-ce
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  * @name:	Name of clock needed by this variant
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)  * @freq:	Frequency to set for each clock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)  * @max_freq:	Maximum frequency for each clock (generally given by datasheet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct ce_clock {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	unsigned long freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	unsigned long max_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  * struct ce_variant - Describe CE capability for each variant hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  * @alg_cipher:	list of supported ciphers. for each CE_ID_ this will give the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  *              coresponding CE_ALG_XXX value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  * @alg_hash:	list of supported hashes. for each CE_ID_ this will give the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  *              corresponding CE_ALG_XXX value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  * @op_mode:	list of supported block modes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)  * @cipher_t_dlen_in_bytes:	Does the request size for cipher is in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)  *				bytes or words
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)  * @hash_t_dlen_in_bytes:	Does the request size for hash is in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)  *				bits or words
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  * @prng_t_dlen_in_bytes:	Does the request size for PRNG is in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  *				bytes or words
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  * @trng_t_dlen_in_bytes:	Does the request size for TRNG is in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  *				bytes or words
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  * @ce_clks:	list of clocks needed by this variant
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  * @esr:	The type of error register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  * @prng:	The CE_ALG_XXX value for the PRNG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  * @trng:	The CE_ALG_XXX value for the TRNG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct ce_variant {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	char alg_cipher[CE_ID_CIPHER_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	char alg_hash[CE_ID_HASH_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	u32 op_mode[CE_ID_OP_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	bool cipher_t_dlen_in_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	bool hash_t_dlen_in_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	bool prng_t_dlen_in_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	bool trng_t_dlen_in_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	struct ce_clock ce_clks[CE_MAX_CLOCKS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	int esr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	unsigned char prng;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	unsigned char trng;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct sginfo {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	__le32 addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	__le32 len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) } __packed;
^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 ce_task - CE Task descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  * The structure of this descriptor could be found in the datasheet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct ce_task {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	__le32 t_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	__le32 t_common_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	__le32 t_sym_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	__le32 t_asym_ctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	__le32 t_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	__le32 t_iv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	__le32 t_ctr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	__le32 t_dlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	struct sginfo t_src[MAX_SG];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	struct sginfo t_dst[MAX_SG];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	__le32 next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	__le32 reserved[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) } __packed __aligned(8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  * struct sun8i_ce_flow - Information used by each flow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  * @engine:	ptr to the crypto_engine for this flow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  * @complete:	completion for the current task on this flow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  * @status:	set to 1 by interrupt if task is done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  * @t_phy:	Physical address of task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  * @tl:		pointer to the current ce_task for this flow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  * @stat_req:	number of request done by this flow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct sun8i_ce_flow {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	struct crypto_engine *engine;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	struct completion complete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	dma_addr_t t_phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	int timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	struct ce_task *tl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) #ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	unsigned long stat_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)  * struct sun8i_ce_dev - main container for all this driver information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)  * @base:	base address of CE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)  * @ceclks:	clocks used by CE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)  * @reset:	pointer to reset controller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)  * @dev:	the platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)  * @mlock:	Control access to device registers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)  * @rnglock:	Control access to the RNG (dedicated channel 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)  * @chanlist:	array of all flow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)  * @flow:	flow to use in next request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)  * @variant:	pointer to variant specific data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)  * @dbgfs_dir:	Debugfs dentry for statistic directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)  * @dbgfs_stats: Debugfs dentry for statistic counters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct sun8i_ce_dev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	void __iomem *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	struct clk *ceclks[CE_MAX_CLOCKS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct reset_control *reset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	struct mutex mlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	struct mutex rnglock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	struct sun8i_ce_flow *chanlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	atomic_t flow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	const struct ce_variant *variant;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) #ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	struct dentry *dbgfs_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	struct dentry *dbgfs_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) #ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_TRNG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	struct hwrng trng;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) #ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	unsigned long hwrng_stat_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	unsigned long hwrng_stat_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  * struct sun8i_cipher_req_ctx - context for a skcipher request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)  * @op_dir:		direction (encrypt vs decrypt) for this request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)  * @flow:		the flow to use for this request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)  * @backup_iv:		buffer which contain the next IV to store
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)  * @bounce_iv:		buffer which contain the IV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)  * @ivlen:		size of bounce_iv
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)  * @nr_sgs:		The number of source SG (as given by dma_map_sg())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)  * @nr_sgd:		The number of destination SG (as given by dma_map_sg())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  * @addr_iv:		The IV addr returned by dma_map_single, need to unmap later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  * @addr_key:		The key addr returned by dma_map_single, need to unmap later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  * @fallback_req:	request struct for invoking the fallback skcipher TFM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct sun8i_cipher_req_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	u32 op_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	int flow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	void *backup_iv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	void *bounce_iv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	unsigned int ivlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	int nr_sgs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	int nr_sgd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	dma_addr_t addr_iv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	dma_addr_t addr_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	struct skcipher_request fallback_req;   // keep at the end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  * struct sun8i_cipher_tfm_ctx - context for a skcipher TFM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)  * @enginectx:		crypto_engine used by this TFM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)  * @key:		pointer to key data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)  * @keylen:		len of the key
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)  * @ce:			pointer to the private data of driver handling this TFM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)  * @fallback_tfm:	pointer to the fallback TFM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) struct sun8i_cipher_tfm_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	struct crypto_engine_ctx enginectx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	u32 *key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	u32 keylen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	struct sun8i_ce_dev *ce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	struct crypto_skcipher *fallback_tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)  * struct sun8i_ce_hash_tfm_ctx - context for an ahash TFM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)  * @enginectx:		crypto_engine used by this TFM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)  * @ce:			pointer to the private data of driver handling this TFM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)  * @fallback_tfm:	pointer to the fallback TFM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) struct sun8i_ce_hash_tfm_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	struct crypto_engine_ctx enginectx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	struct sun8i_ce_dev *ce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	struct crypto_ahash *fallback_tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)  * struct sun8i_ce_hash_reqctx - context for an ahash request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)  * @fallback_req:	pre-allocated fallback request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)  * @flow:	the flow to use for this request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) struct sun8i_ce_hash_reqctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	struct ahash_request fallback_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	int flow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)  * struct sun8i_ce_prng_ctx - context for PRNG TFM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)  * @seed:	The seed to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)  * @slen:	The size of the seed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) struct sun8i_ce_rng_tfm_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	void *seed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	unsigned int slen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)  * struct sun8i_ce_alg_template - crypto_alg template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)  * @type:		the CRYPTO_ALG_TYPE for this template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)  * @ce_algo_id:		the CE_ID for this template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)  * @ce_blockmode:	the type of block operation CE_ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)  * @ce:			pointer to the sun8i_ce_dev structure associated with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)  *			this template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)  * @alg:		one of sub struct must be used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)  * @stat_req:		number of request done on this template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)  * @stat_fb:		number of request which has fallbacked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)  * @stat_bytes:		total data size done by this template
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) struct sun8i_ce_alg_template {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	u32 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	u32 ce_algo_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	u32 ce_blockmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	struct sun8i_ce_dev *ce;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		struct skcipher_alg skcipher;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		struct ahash_alg hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		struct rng_alg rng;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	} alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) #ifdef CONFIG_CRYPTO_DEV_SUN8I_CE_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	unsigned long stat_req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	unsigned long stat_fb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	unsigned long stat_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) int sun8i_ce_enqueue(struct crypto_async_request *areq, u32 type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) int sun8i_ce_aes_setkey(struct crypto_skcipher *tfm, const u8 *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 			unsigned int keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) int sun8i_ce_des3_setkey(struct crypto_skcipher *tfm, const u8 *key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 			 unsigned int keylen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) int sun8i_ce_cipher_init(struct crypto_tfm *tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) void sun8i_ce_cipher_exit(struct crypto_tfm *tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) int sun8i_ce_skdecrypt(struct skcipher_request *areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) int sun8i_ce_skencrypt(struct skcipher_request *areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) int sun8i_ce_get_engine_number(struct sun8i_ce_dev *ce);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) int sun8i_ce_run_task(struct sun8i_ce_dev *ce, int flow, const char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) int sun8i_ce_hash_crainit(struct crypto_tfm *tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) void sun8i_ce_hash_craexit(struct crypto_tfm *tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) int sun8i_ce_hash_init(struct ahash_request *areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) int sun8i_ce_hash_export(struct ahash_request *areq, void *out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) int sun8i_ce_hash_import(struct ahash_request *areq, const void *in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) int sun8i_ce_hash(struct ahash_request *areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) int sun8i_ce_hash_final(struct ahash_request *areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) int sun8i_ce_hash_update(struct ahash_request *areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) int sun8i_ce_hash_finup(struct ahash_request *areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) int sun8i_ce_hash_digest(struct ahash_request *areq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) int sun8i_ce_hash_run(struct crypto_engine *engine, void *breq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) int sun8i_ce_prng_generate(struct crypto_rng *tfm, const u8 *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 			   unsigned int slen, u8 *dst, unsigned int dlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) int sun8i_ce_prng_seed(struct crypto_rng *tfm, const u8 *seed, unsigned int slen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) void sun8i_ce_prng_exit(struct crypto_tfm *tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) int sun8i_ce_prng_init(struct crypto_tfm *tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) int sun8i_ce_hwrng_register(struct sun8i_ce_dev *ce);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) void sun8i_ce_hwrng_unregister(struct sun8i_ce_dev *ce);