1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __STARFIVE_STR_H__
3 #define __STARFIVE_STR_H__
5 #include <crypto/aes.h>
6 #include <crypto/hash.h>
7 #include <crypto/scatterwalk.h>
8 #include <crypto/sha2.h>
9 #include <crypto/sm3.h>
10 #include <linux/delay.h>
11 #include <linux/dma-mapping.h>
12 #include <linux/dmaengine.h>
13 #include <linux/interrupt.h>
15 #define STARFIVE_ALG_CR_OFFSET 0x0
16 #define STARFIVE_ALG_FIFO_OFFSET 0x4
17 #define STARFIVE_IE_MASK_OFFSET 0x8
18 #define STARFIVE_IE_FLAG_OFFSET 0xc
19 #define STARFIVE_DMA_IN_LEN_OFFSET 0x10
20 #define STARFIVE_DMA_OUT_LEN_OFFSET 0x14
22 #define STARFIVE_IE_MASK_AES_DONE 0x1
23 #define STARFIVE_IE_MASK_HASH_DONE 0x4
24 #define STARFIVE_IE_MASK_PKA_DONE 0x8
25 #define STARFIVE_IE_FLAG_AES_DONE 0x1
26 #define STARFIVE_IE_FLAG_HASH_DONE 0x4
27 #define STARFIVE_IE_FLAG_PKA_DONE 0x8
29 #define STARFIVE_MSG_BUFFER_SIZE SZ_16K
30 #define MAX_KEY_SIZE SHA512_BLOCK_SIZE
31 #define STARFIVE_AES_IV_LEN AES_BLOCK_SIZE
32 #define STARFIVE_AES_CTR_LEN AES_BLOCK_SIZE
33 #define STARFIVE_RSA_MAX_KEYSZ 256
35 union starfive_aes_csr
{
39 #define STARFIVE_AES_KEYMODE_128 0x0
40 #define STARFIVE_AES_KEYMODE_192 0x1
41 #define STARFIVE_AES_KEYMODE_256 0x2
43 #define STARFIVE_AES_BUSY BIT(3)
46 #define STARFIVE_AES_KEY_DONE BIT(5)
50 #define STARFIVE_AES_CCM_START BIT(8)
52 #define STARFIVE_AES_MODE_ECB 0x0
53 #define STARFIVE_AES_MODE_CBC 0x1
54 #define STARFIVE_AES_MODE_CTR 0x4
55 #define STARFIVE_AES_MODE_CCM 0x5
56 #define STARFIVE_AES_MODE_GCM 0x6
58 #define STARFIVE_AES_GCM_START BIT(12)
60 #define STARFIVE_AES_GCM_DONE BIT(13)
65 #define STARFIVE_AES_MODE_XFB_1 0x0
66 #define STARFIVE_AES_MODE_XFB_128 0x5
72 union starfive_hash_csr
{
79 #define STARFIVE_HASH_SM3 0x0
80 #define STARFIVE_HASH_SHA224 0x3
81 #define STARFIVE_HASH_SHA256 0x4
82 #define STARFIVE_HASH_SHA384 0x5
83 #define STARFIVE_HASH_SHA512 0x6
84 #define STARFIVE_HASH_MODE_MASK 0x7
89 #define STARFIVE_HASH_HMAC_FLAGS 0x800
92 #define STARFIVE_HASH_KEY_DONE BIT(13)
95 #define STARFIVE_HASH_HMAC_DONE BIT(15)
97 #define STARFIVE_HASH_BUSY BIT(16)
104 union starfive_pka_cacr
{
128 union starfive_pka_casr
{
131 #define STARFIVE_PKA_DONE BIT(0)
137 struct starfive_rsa_key
{
147 union starfive_alg_cr
{
161 struct starfive_cryp_ctx
{
162 struct starfive_cryp_dev
*cryp
;
163 struct starfive_cryp_request_ctx
*rctx
;
165 unsigned int hash_mode
;
166 u8 key
[MAX_KEY_SIZE
];
169 struct starfive_rsa_key rsa_key
;
170 struct crypto_akcipher
*akcipher_fbk
;
171 struct crypto_ahash
*ahash_fbk
;
172 struct crypto_aead
*aead_fbk
;
173 struct crypto_skcipher
*skcipher_fbk
;
176 struct starfive_cryp_dev
{
177 struct list_head list
;
181 struct reset_control
*rst
;
184 phys_addr_t phys_base
;
189 struct dma_slave_config cfg_in
;
190 struct dma_slave_config cfg_out
;
191 struct crypto_engine
*engine
;
192 struct completion dma_done
;
198 unsigned int authsize
;
202 union starfive_alg_cr alg_cr
;
204 struct ahash_request
*hreq
;
205 struct aead_request
*areq
;
206 struct skcipher_request
*sreq
;
210 struct starfive_cryp_request_ctx
{
212 union starfive_hash_csr hash
;
213 union starfive_pka_cacr pka
;
214 union starfive_aes_csr aes
;
217 struct scatterlist
*in_sg
;
218 struct scatterlist
*out_sg
;
219 struct ahash_request ahash_fbk_req
;
221 unsigned int blksize
;
222 unsigned int digsize
;
223 unsigned long in_sg_len
;
224 unsigned char *adata
;
225 u8 rsa_data
[STARFIVE_RSA_MAX_KEYSZ
] __aligned(sizeof(u32
));
228 struct starfive_cryp_dev
*starfive_cryp_find_dev(struct starfive_cryp_ctx
*ctx
);
230 int starfive_hash_register_algs(void);
231 void starfive_hash_unregister_algs(void);
233 int starfive_rsa_register_algs(void);
234 void starfive_rsa_unregister_algs(void);
236 int starfive_aes_register_algs(void);
237 void starfive_aes_unregister_algs(void);