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
34 union starfive_aes_csr {
38 #define STARFIVE_AES_KEYMODE_128 0x0
39 #define STARFIVE_AES_KEYMODE_192 0x1
40 #define STARFIVE_AES_KEYMODE_256 0x2
42 #define STARFIVE_AES_BUSY BIT(3)
45 #define STARFIVE_AES_KEY_DONE BIT(5)
49 #define STARFIVE_AES_CCM_START BIT(8)
51 #define STARFIVE_AES_MODE_ECB 0x0
52 #define STARFIVE_AES_MODE_CBC 0x1
53 #define STARFIVE_AES_MODE_CTR 0x4
54 #define STARFIVE_AES_MODE_CCM 0x5
55 #define STARFIVE_AES_MODE_GCM 0x6
57 #define STARFIVE_AES_GCM_START BIT(12)
59 #define STARFIVE_AES_GCM_DONE BIT(13)
64 #define STARFIVE_AES_MODE_XFB_1 0x0
65 #define STARFIVE_AES_MODE_XFB_128 0x5
71 union starfive_hash_csr {
78 #define STARFIVE_HASH_SM3 0x0
79 #define STARFIVE_HASH_SHA224 0x3
80 #define STARFIVE_HASH_SHA256 0x4
81 #define STARFIVE_HASH_SHA384 0x5
82 #define STARFIVE_HASH_SHA512 0x6
83 #define STARFIVE_HASH_MODE_MASK 0x7
88 #define STARFIVE_HASH_HMAC_FLAGS 0x800
91 #define STARFIVE_HASH_KEY_DONE BIT(13)
95 #define STARFIVE_HASH_BUSY BIT(16)
102 union starfive_pka_cacr {
126 union starfive_pka_casr {
129 #define STARFIVE_PKA_DONE BIT(0)
135 struct starfive_rsa_key {
145 union starfive_alg_cr {
159 struct starfive_cryp_ctx {
160 struct starfive_cryp_dev *cryp;
161 struct starfive_cryp_request_ctx *rctx;
163 unsigned int hash_mode;
164 u8 key[MAX_KEY_SIZE];
167 struct starfive_rsa_key rsa_key;
168 struct crypto_akcipher *akcipher_fbk;
169 struct crypto_ahash *ahash_fbk;
170 struct crypto_aead *aead_fbk;
173 struct starfive_cryp_dev {
174 struct list_head list;
178 struct reset_control *rst;
181 phys_addr_t phys_base;
186 struct dma_slave_config cfg_in;
187 struct dma_slave_config cfg_out;
188 struct scatter_walk in_walk;
189 struct scatter_walk out_walk;
190 struct crypto_engine *engine;
191 struct tasklet_struct aes_done;
192 struct tasklet_struct hash_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;
222 unsigned int blksize;
223 unsigned int digsize;
224 unsigned long in_sg_len;
225 unsigned char *adata;
226 u8 rsa_data[] __aligned(sizeof(u32));
229 struct starfive_cryp_dev *starfive_cryp_find_dev(struct starfive_cryp_ctx *ctx);
231 int starfive_hash_register_algs(void);
232 void starfive_hash_unregister_algs(void);
234 int starfive_rsa_register_algs(void);
235 void starfive_rsa_unregister_algs(void);
237 int starfive_aes_register_algs(void);
238 void starfive_aes_unregister_algs(void);
240 void starfive_hash_done_task(unsigned long param);
241 void starfive_aes_done_task(unsigned long param);