1
2
3
4
5
6
7
8 #ifndef __MTK_PLATFORM_H_
9 #define __MTK_PLATFORM_H_
10
11 #include <crypto/algapi.h>
12 #include <crypto/internal/aead.h>
13 #include <crypto/internal/hash.h>
14 #include <crypto/scatterwalk.h>
15 #include <crypto/skcipher.h>
16 #include <linux/crypto.h>
17 #include <linux/dma-mapping.h>
18 #include <linux/interrupt.h>
19 #include <linux/scatterlist.h>
20 #include "mtk-regs.h"
21
22 #define MTK_RDR_PROC_THRESH BIT(0)
23 #define MTK_RDR_PROC_MODE BIT(23)
24 #define MTK_CNT_RST BIT(31)
25 #define MTK_IRQ_RDR0 BIT(1)
26 #define MTK_IRQ_RDR1 BIT(3)
27 #define MTK_IRQ_RDR2 BIT(5)
28 #define MTK_IRQ_RDR3 BIT(7)
29
30 #define SIZE_IN_WORDS(x) ((x) >> 2)
31
32
33
34
35
36 enum {
37 MTK_RING0,
38 MTK_RING1,
39 MTK_RING2,
40 MTK_RING3,
41 MTK_RING_MAX
42 };
43
44 #define MTK_REC_NUM (MTK_RING_MAX / 2)
45 #define MTK_IRQ_NUM 5
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 struct mtk_desc {
61 __le32 hdr;
62 __le32 buf;
63 __le32 ct;
64 __le32 ct_hdr;
65 __le32 tag;
66 __le32 tfm;
67 __le32 bound[2];
68 };
69
70 #define MTK_DESC_NUM 512
71 #define MTK_DESC_OFF SIZE_IN_WORDS(sizeof(struct mtk_desc))
72 #define MTK_DESC_SZ (MTK_DESC_OFF - 2)
73 #define MTK_DESC_RING_SZ ((sizeof(struct mtk_desc) * MTK_DESC_NUM))
74 #define MTK_DESC_CNT(x) ((MTK_DESC_OFF * (x)) << 2)
75 #define MTK_DESC_LAST cpu_to_le32(BIT(22))
76 #define MTK_DESC_FIRST cpu_to_le32(BIT(23))
77 #define MTK_DESC_BUF_LEN(x) cpu_to_le32(x)
78 #define MTK_DESC_CT_LEN(x) cpu_to_le32((x) << 24)
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94 struct mtk_ring {
95 struct mtk_desc *cmd_base;
96 struct mtk_desc *cmd_next;
97 dma_addr_t cmd_dma;
98 struct mtk_desc *res_base;
99 struct mtk_desc *res_next;
100 struct mtk_desc *res_prev;
101 dma_addr_t res_dma;
102 };
103
104
105
106
107
108
109
110
111 struct mtk_aes_dma {
112 struct scatterlist *sg;
113 int nents;
114 u32 remainder;
115 u32 sg_len;
116 };
117
118 struct mtk_aes_base_ctx;
119 struct mtk_aes_rec;
120 struct mtk_cryp;
121
122 typedef int (*mtk_aes_fn)(struct mtk_cryp *cryp, struct mtk_aes_rec *aes);
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145 struct mtk_aes_rec {
146 struct mtk_cryp *cryp;
147 struct crypto_queue queue;
148 struct crypto_async_request *areq;
149 struct tasklet_struct done_task;
150 struct tasklet_struct queue_task;
151 struct mtk_aes_base_ctx *ctx;
152 struct mtk_aes_dma src;
153 struct mtk_aes_dma dst;
154
155 struct scatterlist aligned_sg;
156 struct scatterlist *real_dst;
157
158 mtk_aes_fn resume;
159
160 size_t total;
161 void *buf;
162
163 u8 id;
164 unsigned long flags;
165
166 spinlock_t lock;
167 };
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182 struct mtk_sha_rec {
183 struct mtk_cryp *cryp;
184 struct crypto_queue queue;
185 struct ahash_request *req;
186 struct tasklet_struct done_task;
187 struct tasklet_struct queue_task;
188
189 u8 id;
190 unsigned long flags;
191
192 spinlock_t lock;
193 };
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210 struct mtk_cryp {
211 void __iomem *base;
212 struct device *dev;
213 struct clk *clk_cryp;
214 int irq[MTK_IRQ_NUM];
215
216 struct mtk_ring *ring[MTK_RING_MAX];
217 struct mtk_aes_rec *aes[MTK_REC_NUM];
218 struct mtk_sha_rec *sha[MTK_REC_NUM];
219
220 struct list_head aes_list;
221 struct list_head sha_list;
222
223 bool rec;
224 };
225
226 int mtk_cipher_alg_register(struct mtk_cryp *cryp);
227 void mtk_cipher_alg_release(struct mtk_cryp *cryp);
228 int mtk_hash_alg_register(struct mtk_cryp *cryp);
229 void mtk_hash_alg_release(struct mtk_cryp *cryp);
230
231 #endif