blob: b8a81c568c99014b9be71eccd408f4e5f345dec2 [file] [log] [blame]
Antoine Ténart1b44c5a2017-05-24 16:10:34 +02001/*
2 * Copyright (C) 2017 Marvell
3 *
4 * Antoine Tenart <antoine.tenart@free-electrons.com>
5 *
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
9 */
10
11#ifndef __SAFEXCEL_H__
12#define __SAFEXCEL_H__
13
14#include <crypto/algapi.h>
15#include <crypto/internal/hash.h>
16#include <crypto/skcipher.h>
17
18#define EIP197_HIA_VERSION_LE 0xca35
19#define EIP197_HIA_VERSION_BE 0x35ca
20
21/* Static configuration */
22#define EIP197_DEFAULT_RING_SIZE 64
23#define EIP197_MAX_TOKENS 5
24#define EIP197_MAX_RINGS 4
25#define EIP197_FETCH_COUNT 1
26#define EIP197_MAX_BATCH_SZ 8
27
28#define EIP197_GFP_FLAGS(base) ((base).flags & CRYPTO_TFM_REQ_MAY_SLEEP ? \
29 GFP_KERNEL : GFP_ATOMIC)
30
31/* CDR/RDR register offsets */
32#define EIP197_HIA_xDR_OFF(r) (0x80000 + (r) * 0x1000)
33#define EIP197_HIA_CDR(r) (EIP197_HIA_xDR_OFF(r))
34#define EIP197_HIA_RDR(r) (EIP197_HIA_xDR_OFF(r) + 0x800)
35#define EIP197_HIA_xDR_RING_BASE_ADDR_LO 0x0
36#define EIP197_HIA_xDR_RING_BASE_ADDR_HI 0x4
37#define EIP197_HIA_xDR_RING_SIZE 0x18
38#define EIP197_HIA_xDR_DESC_SIZE 0x1c
39#define EIP197_HIA_xDR_CFG 0x20
40#define EIP197_HIA_xDR_DMA_CFG 0x24
41#define EIP197_HIA_xDR_THRESH 0x28
42#define EIP197_HIA_xDR_PREP_COUNT 0x2c
43#define EIP197_HIA_xDR_PROC_COUNT 0x30
44#define EIP197_HIA_xDR_PREP_PNTR 0x34
45#define EIP197_HIA_xDR_PROC_PNTR 0x38
46#define EIP197_HIA_xDR_STAT 0x3c
47
48/* register offsets */
49#define EIP197_HIA_DFE_CFG 0x8c000
50#define EIP197_HIA_DFE_THR_CTRL 0x8c040
51#define EIP197_HIA_DFE_THR_STAT 0x8c044
52#define EIP197_HIA_DSE_CFG 0x8d000
53#define EIP197_HIA_DSE_THR_CTRL 0x8d040
54#define EIP197_HIA_DSE_THR_STAT 0x8d044
55#define EIP197_HIA_RA_PE_CTRL 0x90010
56#define EIP197_HIA_RA_PE_STAT 0x90014
57#define EIP197_HIA_AIC_R_OFF(r) ((r) * 0x1000)
58#define EIP197_HIA_AIC_R_ENABLE_CTRL(r) (0x9e808 - EIP197_HIA_AIC_R_OFF(r))
59#define EIP197_HIA_AIC_R_ENABLED_STAT(r) (0x9e810 - EIP197_HIA_AIC_R_OFF(r))
60#define EIP197_HIA_AIC_R_ACK(r) (0x9e810 - EIP197_HIA_AIC_R_OFF(r))
61#define EIP197_HIA_AIC_R_ENABLE_CLR(r) (0x9e814 - EIP197_HIA_AIC_R_OFF(r))
62#define EIP197_HIA_AIC_G_ENABLE_CTRL 0x9f808
63#define EIP197_HIA_AIC_G_ENABLED_STAT 0x9f810
64#define EIP197_HIA_AIC_G_ACK 0x9f810
65#define EIP197_HIA_MST_CTRL 0x9fff4
66#define EIP197_HIA_OPTIONS 0x9fff8
67#define EIP197_HIA_VERSION 0x9fffc
68#define EIP197_PE_IN_DBUF_THRES 0xa0000
69#define EIP197_PE_IN_TBUF_THRES 0xa0100
70#define EIP197_PE_ICE_SCRATCH_RAM 0xa0800
71#define EIP197_PE_ICE_PUE_CTRL 0xa0c80
72#define EIP197_PE_ICE_SCRATCH_CTRL 0xa0d04
73#define EIP197_PE_ICE_FPP_CTRL 0xa0d80
74#define EIP197_PE_ICE_RAM_CTRL 0xa0ff0
75#define EIP197_PE_EIP96_FUNCTION_EN 0xa1004
76#define EIP197_PE_EIP96_CONTEXT_CTRL 0xa1008
77#define EIP197_PE_EIP96_CONTEXT_STAT 0xa100c
78#define EIP197_PE_OUT_DBUF_THRES 0xa1c00
79#define EIP197_PE_OUT_TBUF_THRES 0xa1d00
80#define EIP197_CLASSIFICATION_RAMS 0xe0000
81#define EIP197_TRC_CTRL 0xf0800
82#define EIP197_TRC_LASTRES 0xf0804
83#define EIP197_TRC_REGINDEX 0xf0808
84#define EIP197_TRC_PARAMS 0xf0820
85#define EIP197_TRC_FREECHAIN 0xf0824
86#define EIP197_TRC_PARAMS2 0xf0828
87#define EIP197_TRC_ECCCTRL 0xf0830
88#define EIP197_TRC_ECCSTAT 0xf0834
89#define EIP197_TRC_ECCADMINSTAT 0xf0838
90#define EIP197_TRC_ECCDATASTAT 0xf083c
91#define EIP197_TRC_ECCDATA 0xf0840
92#define EIP197_CS_RAM_CTRL 0xf7ff0
93#define EIP197_MST_CTRL 0xffff4
94
95/* EIP197_HIA_xDR_DESC_SIZE */
96#define EIP197_xDR_DESC_MODE_64BIT BIT(31)
97
98/* EIP197_HIA_xDR_DMA_CFG */
99#define EIP197_HIA_xDR_WR_RES_BUF BIT(22)
100#define EIP197_HIA_xDR_WR_CTRL_BUG BIT(23)
101#define EIP197_HIA_xDR_WR_OWN_BUF BIT(24)
Antoine Ténartaefa7942017-06-15 09:56:18 +0200102#define EIP197_HIA_xDR_CFG_WR_CACHE(n) (((n) & 0x7) << 25)
Antoine Ténart1b44c5a2017-05-24 16:10:34 +0200103#define EIP197_HIA_xDR_CFG_RD_CACHE(n) (((n) & 0x7) << 29)
104
105/* EIP197_HIA_CDR_THRESH */
106#define EIP197_HIA_CDR_THRESH_PROC_PKT(n) (n)
107#define EIP197_HIA_CDR_THRESH_PROC_MODE BIT(22)
108#define EIP197_HIA_CDR_THRESH_PKT_MODE BIT(23)
109#define EIP197_HIA_CDR_THRESH_TIMEOUT(n) ((n) << 24) /* x256 clk cycles */
110
111/* EIP197_HIA_RDR_THRESH */
112#define EIP197_HIA_RDR_THRESH_PROC_PKT(n) (n)
113#define EIP197_HIA_RDR_THRESH_PKT_MODE BIT(23)
114#define EIP197_HIA_RDR_THRESH_TIMEOUT(n) ((n) << 24) /* x256 clk cycles */
115
116/* EIP197_HIA_xDR_PREP_COUNT */
117#define EIP197_xDR_PREP_CLR_COUNT BIT(31)
118
119/* EIP197_HIA_xDR_PROC_COUNT */
120#define EIP197_xDR_PROC_xD_COUNT(n) ((n) << 2)
121#define EIP197_xDR_PROC_xD_PKT(n) ((n) << 24)
122#define EIP197_xDR_PROC_CLR_COUNT BIT(31)
123
124/* EIP197_HIA_xDR_STAT */
125#define EIP197_xDR_DMA_ERR BIT(0)
126#define EIP197_xDR_PREP_CMD_THRES BIT(1)
127#define EIP197_xDR_ERR BIT(2)
128#define EIP197_xDR_THRESH BIT(4)
129#define EIP197_xDR_TIMEOUT BIT(5)
130
131#define EIP197_HIA_RA_PE_CTRL_RESET BIT(31)
132#define EIP197_HIA_RA_PE_CTRL_EN BIT(30)
133
134/* EIP197_HIA_AIC_R_ENABLE_CTRL */
135#define EIP197_CDR_IRQ(n) BIT((n) * 2)
136#define EIP197_RDR_IRQ(n) BIT((n) * 2 + 1)
137
138/* EIP197_HIA_DFE/DSE_CFG */
139#define EIP197_HIA_DxE_CFG_MIN_DATA_SIZE(n) ((n) << 0)
140#define EIP197_HIA_DxE_CFG_DATA_CACHE_CTRL(n) (((n) & 0x7) << 4)
141#define EIP197_HIA_DxE_CFG_MAX_DATA_SIZE(n) ((n) << 8)
142#define EIP197_HIA_DxE_CFG_MIN_CTRL_SIZE(n) ((n) << 16)
143#define EIP197_HIA_DxE_CFG_CTRL_CACHE_CTRL(n) (((n) & 0x7) << 20)
144#define EIP197_HIA_DxE_CFG_MAX_CTRL_SIZE(n) ((n) << 24)
145#define EIP197_HIA_DFE_CFG_DIS_DEBUG (BIT(31) | BIT(29))
Igal Libermanc87925b2017-06-15 09:56:20 +0200146#define EIP197_HIA_DSE_CFG_EN_SINGLE_WR BIT(29)
Antoine Ténart1b44c5a2017-05-24 16:10:34 +0200147#define EIP197_HIA_DSE_CFG_DIS_DEBUG BIT(31)
148
149/* EIP197_HIA_DFE/DSE_THR_CTRL */
150#define EIP197_DxE_THR_CTRL_EN BIT(30)
151#define EIP197_DxE_THR_CTRL_RESET_PE BIT(31)
152
153/* EIP197_HIA_AIC_G_ENABLED_STAT */
154#define EIP197_G_IRQ_DFE(n) BIT((n) << 1)
155#define EIP197_G_IRQ_DSE(n) BIT(((n) << 1) + 1)
156#define EIP197_G_IRQ_RING BIT(16)
157#define EIP197_G_IRQ_PE(n) BIT((n) + 20)
158
159/* EIP197_HIA_MST_CTRL */
160#define RD_CACHE_3BITS 0x5
161#define WR_CACHE_3BITS 0x3
162#define RD_CACHE_4BITS (RD_CACHE_3BITS << 1 | BIT(0))
163#define WR_CACHE_4BITS (WR_CACHE_3BITS << 1 | BIT(0))
164#define EIP197_MST_CTRL_RD_CACHE(n) (((n) & 0xf) << 0)
165#define EIP197_MST_CTRL_WD_CACHE(n) (((n) & 0xf) << 4)
166#define EIP197_MST_CTRL_BYTE_SWAP BIT(24)
167#define EIP197_MST_CTRL_NO_BYTE_SWAP BIT(25)
168
169/* EIP197_PE_IN_DBUF/TBUF_THRES */
170#define EIP197_PE_IN_xBUF_THRES_MIN(n) ((n) << 8)
171#define EIP197_PE_IN_xBUF_THRES_MAX(n) ((n) << 12)
172
173/* EIP197_PE_OUT_DBUF_THRES */
174#define EIP197_PE_OUT_DBUF_THRES_MIN(n) ((n) << 0)
175#define EIP197_PE_OUT_DBUF_THRES_MAX(n) ((n) << 4)
176
177/* EIP197_PE_ICE_SCRATCH_CTRL */
178#define EIP197_PE_ICE_SCRATCH_CTRL_CHANGE_TIMER BIT(2)
179#define EIP197_PE_ICE_SCRATCH_CTRL_TIMER_EN BIT(3)
180#define EIP197_PE_ICE_SCRATCH_CTRL_CHANGE_ACCESS BIT(24)
181#define EIP197_PE_ICE_SCRATCH_CTRL_SCRATCH_ACCESS BIT(25)
182
183/* EIP197_PE_ICE_SCRATCH_RAM */
184#define EIP197_NUM_OF_SCRATCH_BLOCKS 32
185
186/* EIP197_PE_ICE_PUE/FPP_CTRL */
187#define EIP197_PE_ICE_x_CTRL_SW_RESET BIT(0)
188#define EIP197_PE_ICE_x_CTRL_CLR_ECC_NON_CORR BIT(14)
189#define EIP197_PE_ICE_x_CTRL_CLR_ECC_CORR BIT(15)
190
191/* EIP197_PE_ICE_RAM_CTRL */
192#define EIP197_PE_ICE_RAM_CTRL_PUE_PROG_EN BIT(0)
193#define EIP197_PE_ICE_RAM_CTRL_FPP_PROG_EN BIT(1)
194
195/* EIP197_PE_EIP96_FUNCTION_EN */
196#define EIP197_FUNCTION_RSVD (BIT(6) | BIT(15) | BIT(20) | BIT(23))
197#define EIP197_PROTOCOL_HASH_ONLY BIT(0)
198#define EIP197_PROTOCOL_ENCRYPT_ONLY BIT(1)
199#define EIP197_PROTOCOL_HASH_ENCRYPT BIT(2)
200#define EIP197_PROTOCOL_HASH_DECRYPT BIT(3)
201#define EIP197_PROTOCOL_ENCRYPT_HASH BIT(4)
202#define EIP197_PROTOCOL_DECRYPT_HASH BIT(5)
203#define EIP197_ALG_ARC4 BIT(7)
204#define EIP197_ALG_AES_ECB BIT(8)
205#define EIP197_ALG_AES_CBC BIT(9)
206#define EIP197_ALG_AES_CTR_ICM BIT(10)
207#define EIP197_ALG_AES_OFB BIT(11)
208#define EIP197_ALG_AES_CFB BIT(12)
209#define EIP197_ALG_DES_ECB BIT(13)
210#define EIP197_ALG_DES_CBC BIT(14)
211#define EIP197_ALG_DES_OFB BIT(16)
212#define EIP197_ALG_DES_CFB BIT(17)
213#define EIP197_ALG_3DES_ECB BIT(18)
214#define EIP197_ALG_3DES_CBC BIT(19)
215#define EIP197_ALG_3DES_OFB BIT(21)
216#define EIP197_ALG_3DES_CFB BIT(22)
217#define EIP197_ALG_MD5 BIT(24)
218#define EIP197_ALG_HMAC_MD5 BIT(25)
219#define EIP197_ALG_SHA1 BIT(26)
220#define EIP197_ALG_HMAC_SHA1 BIT(27)
221#define EIP197_ALG_SHA2 BIT(28)
222#define EIP197_ALG_HMAC_SHA2 BIT(29)
223#define EIP197_ALG_AES_XCBC_MAC BIT(30)
224#define EIP197_ALG_GCM_HASH BIT(31)
225
226/* EIP197_PE_EIP96_CONTEXT_CTRL */
227#define EIP197_CONTEXT_SIZE(n) (n)
228#define EIP197_ADDRESS_MODE BIT(8)
229#define EIP197_CONTROL_MODE BIT(9)
230
231/* Context Control */
232struct safexcel_context_record {
233 u32 control0;
234 u32 control1;
235
236 __le32 data[12];
237} __packed;
238
239/* control0 */
240#define CONTEXT_CONTROL_TYPE_NULL_OUT 0x0
241#define CONTEXT_CONTROL_TYPE_NULL_IN 0x1
242#define CONTEXT_CONTROL_TYPE_HASH_OUT 0x2
243#define CONTEXT_CONTROL_TYPE_HASH_IN 0x3
244#define CONTEXT_CONTROL_TYPE_CRYPTO_OUT 0x4
245#define CONTEXT_CONTROL_TYPE_CRYPTO_IN 0x5
246#define CONTEXT_CONTROL_TYPE_ENCRYPT_HASH_OUT 0x6
247#define CONTEXT_CONTROL_TYPE_DECRYPT_HASH_IN 0x7
248#define CONTEXT_CONTROL_TYPE_HASH_ENCRYPT_OUT 0x14
249#define CONTEXT_CONTROL_TYPE_HASH_DECRYPT_OUT 0x15
250#define CONTEXT_CONTROL_RESTART_HASH BIT(4)
251#define CONTEXT_CONTROL_NO_FINISH_HASH BIT(5)
252#define CONTEXT_CONTROL_SIZE(n) ((n) << 8)
253#define CONTEXT_CONTROL_KEY_EN BIT(16)
254#define CONTEXT_CONTROL_CRYPTO_ALG_AES128 (0x5 << 17)
255#define CONTEXT_CONTROL_CRYPTO_ALG_AES192 (0x6 << 17)
256#define CONTEXT_CONTROL_CRYPTO_ALG_AES256 (0x7 << 17)
257#define CONTEXT_CONTROL_DIGEST_PRECOMPUTED (0x1 << 21)
258#define CONTEXT_CONTROL_DIGEST_HMAC (0x3 << 21)
259#define CONTEXT_CONTROL_CRYPTO_ALG_SHA1 (0x2 << 23)
260#define CONTEXT_CONTROL_CRYPTO_ALG_SHA224 (0x4 << 23)
261#define CONTEXT_CONTROL_CRYPTO_ALG_SHA256 (0x3 << 23)
262#define CONTEXT_CONTROL_INV_FR (0x5 << 24)
263#define CONTEXT_CONTROL_INV_TR (0x6 << 24)
264
265/* control1 */
266#define CONTEXT_CONTROL_CRYPTO_MODE_ECB (0 << 0)
267#define CONTEXT_CONTROL_CRYPTO_MODE_CBC (1 << 0)
268#define CONTEXT_CONTROL_IV0 BIT(5)
269#define CONTEXT_CONTROL_IV1 BIT(6)
270#define CONTEXT_CONTROL_IV2 BIT(7)
271#define CONTEXT_CONTROL_IV3 BIT(8)
272#define CONTEXT_CONTROL_DIGEST_CNT BIT(9)
273#define CONTEXT_CONTROL_COUNTER_MODE BIT(10)
274#define CONTEXT_CONTROL_HASH_STORE BIT(19)
275
276/* EIP197_CS_RAM_CTRL */
277#define EIP197_TRC_ENABLE_0 BIT(4)
278#define EIP197_TRC_ENABLE_1 BIT(5)
279#define EIP197_TRC_ENABLE_2 BIT(6)
280#define EIP197_TRC_ENABLE_MASK GENMASK(6, 4)
281
282/* EIP197_TRC_PARAMS */
283#define EIP197_TRC_PARAMS_SW_RESET BIT(0)
284#define EIP197_TRC_PARAMS_DATA_ACCESS BIT(2)
285#define EIP197_TRC_PARAMS_HTABLE_SZ(x) ((x) << 4)
286#define EIP197_TRC_PARAMS_BLK_TIMER_SPEED(x) ((x) << 10)
287#define EIP197_TRC_PARAMS_RC_SZ_LARGE(n) ((n) << 18)
288
289/* EIP197_TRC_FREECHAIN */
290#define EIP197_TRC_FREECHAIN_HEAD_PTR(p) (p)
291#define EIP197_TRC_FREECHAIN_TAIL_PTR(p) ((p) << 16)
292
293/* EIP197_TRC_PARAMS2 */
294#define EIP197_TRC_PARAMS2_HTABLE_PTR(p) (p)
295#define EIP197_TRC_PARAMS2_RC_SZ_SMALL(n) ((n) << 18)
296
297/* Cache helpers */
298#define EIP197_CS_RC_MAX 52
299#define EIP197_CS_RC_SIZE (4 * sizeof(u32))
300#define EIP197_CS_RC_NEXT(x) (x)
301#define EIP197_CS_RC_PREV(x) ((x) << 10)
302#define EIP197_RC_NULL 0x3ff
303#define EIP197_CS_TRC_REC_WC 59
304#define EIP197_CS_TRC_LG_REC_WC 73
305
306/* Result data */
307struct result_data_desc {
308 u32 packet_length:17;
309 u32 error_code:15;
310
311 u8 bypass_length:4;
312 u8 e15:1;
313 u16 rsvd0;
314 u8 hash_bytes:1;
315 u8 hash_length:6;
316 u8 generic_bytes:1;
317 u8 checksum:1;
318 u8 next_header:1;
319 u8 length:1;
320
321 u16 application_id;
322 u16 rsvd1;
323
324 u32 rsvd2;
325} __packed;
326
327
328/* Basic Result Descriptor format */
329struct safexcel_result_desc {
330 u32 particle_size:17;
331 u8 rsvd0:3;
332 u8 descriptor_overflow:1;
333 u8 buffer_overflow:1;
334 u8 last_seg:1;
335 u8 first_seg:1;
336 u16 result_size:8;
337
338 u32 rsvd1;
339
340 u32 data_lo;
341 u32 data_hi;
342
343 struct result_data_desc result_data;
344} __packed;
345
346struct safexcel_token {
347 u32 packet_length:17;
348 u8 stat:2;
349 u16 instructions:9;
350 u8 opcode:4;
351} __packed;
352
353#define EIP197_TOKEN_STAT_LAST_HASH BIT(0)
354#define EIP197_TOKEN_STAT_LAST_PACKET BIT(1)
355#define EIP197_TOKEN_OPCODE_DIRECTION 0x0
356#define EIP197_TOKEN_OPCODE_INSERT 0x2
357#define EIP197_TOKEN_OPCODE_NOOP EIP197_TOKEN_OPCODE_INSERT
358#define EIP197_TOKEN_OPCODE_BYPASS GENMASK(3, 0)
359
360static inline void eip197_noop_token(struct safexcel_token *token)
361{
362 token->opcode = EIP197_TOKEN_OPCODE_NOOP;
363 token->packet_length = BIT(2);
364}
365
366/* Instructions */
367#define EIP197_TOKEN_INS_INSERT_HASH_DIGEST 0x1c
368#define EIP197_TOKEN_INS_TYPE_OUTPUT BIT(5)
369#define EIP197_TOKEN_INS_TYPE_HASH BIT(6)
370#define EIP197_TOKEN_INS_TYPE_CRYTO BIT(7)
371#define EIP197_TOKEN_INS_LAST BIT(8)
372
373/* Processing Engine Control Data */
374struct safexcel_control_data_desc {
375 u32 packet_length:17;
376 u16 options:13;
377 u8 type:2;
378
379 u16 application_id;
380 u16 rsvd;
381
382 u8 refresh:2;
383 u32 context_lo:30;
384 u32 context_hi;
385
386 u32 control0;
387 u32 control1;
388
389 u32 token[EIP197_MAX_TOKENS];
390} __packed;
391
392#define EIP197_OPTION_MAGIC_VALUE BIT(0)
393#define EIP197_OPTION_64BIT_CTX BIT(1)
394#define EIP197_OPTION_CTX_CTRL_IN_CMD BIT(8)
395#define EIP197_OPTION_4_TOKEN_IV_CMD GENMASK(11, 9)
396
397#define EIP197_TYPE_EXTENDED 0x3
398
399/* Basic Command Descriptor format */
400struct safexcel_command_desc {
401 u32 particle_size:17;
402 u8 rsvd0:5;
403 u8 last_seg:1;
404 u8 first_seg:1;
405 u16 additional_cdata_size:8;
406
407 u32 rsvd1;
408
409 u32 data_lo;
410 u32 data_hi;
411
412 struct safexcel_control_data_desc control_data;
413} __packed;
414
415/*
416 * Internal structures & functions
417 */
418
419enum eip197_fw {
420 FW_IFPP = 0,
421 FW_IPUE,
422 FW_NB
423};
424
425struct safexcel_ring {
426 void *base;
427 void *base_end;
428 dma_addr_t base_dma;
429
430 /* write and read pointers */
431 void *write;
432 void *read;
433
434 /* number of elements used in the ring */
435 unsigned nr;
436 unsigned offset;
437};
438
439enum safexcel_alg_type {
440 SAFEXCEL_ALG_TYPE_SKCIPHER,
441 SAFEXCEL_ALG_TYPE_AHASH,
442};
443
444struct safexcel_request {
445 struct list_head list;
446 struct crypto_async_request *req;
447};
448
449struct safexcel_config {
450 u32 rings;
451
452 u32 cd_size;
453 u32 cd_offset;
454
455 u32 rd_size;
456 u32 rd_offset;
457};
458
459struct safexcel_work_data {
460 struct work_struct work;
461 struct safexcel_crypto_priv *priv;
462 int ring;
463};
464
465struct safexcel_crypto_priv {
466 void __iomem *base;
467 struct device *dev;
468 struct clk *clk;
469 struct safexcel_config config;
470
471 spinlock_t lock;
472 struct crypto_queue queue;
473
474 bool need_dequeue;
475
476 /* context DMA pool */
477 struct dma_pool *context_pool;
478
479 atomic_t ring_used;
480
481 struct {
482 spinlock_t lock;
483 spinlock_t egress_lock;
484
485 struct list_head list;
486 struct workqueue_struct *workqueue;
487 struct safexcel_work_data work_data;
488
489 /* command/result rings */
490 struct safexcel_ring cdr;
491 struct safexcel_ring rdr;
492 } ring[EIP197_MAX_RINGS];
493};
494
495struct safexcel_context {
496 int (*send)(struct crypto_async_request *req, int ring,
497 struct safexcel_request *request, int *commands,
498 int *results);
499 int (*handle_result)(struct safexcel_crypto_priv *priv, int ring,
500 struct crypto_async_request *req, bool *complete,
501 int *ret);
502 struct safexcel_context_record *ctxr;
503 dma_addr_t ctxr_dma;
504
505 int ring;
506 bool needs_inv;
507 bool exit_inv;
508
509 /* Used for ahash requests */
510 dma_addr_t result_dma;
511 void *cache;
512 dma_addr_t cache_dma;
513 unsigned int cache_sz;
514};
515
516/*
517 * Template structure to describe the algorithms in order to register them.
518 * It also has the purpose to contain our private structure and is actually
519 * the only way I know in this framework to avoid having global pointers...
520 */
521struct safexcel_alg_template {
522 struct safexcel_crypto_priv *priv;
523 enum safexcel_alg_type type;
524 union {
525 struct skcipher_alg skcipher;
526 struct ahash_alg ahash;
527 } alg;
528};
529
530struct safexcel_inv_result {
531 struct completion completion;
532 int error;
533};
534
535void safexcel_dequeue(struct safexcel_crypto_priv *priv);
536void safexcel_complete(struct safexcel_crypto_priv *priv, int ring);
537void safexcel_free_context(struct safexcel_crypto_priv *priv,
538 struct crypto_async_request *req,
539 int result_sz);
540int safexcel_invalidate_cache(struct crypto_async_request *async,
541 struct safexcel_context *ctx,
542 struct safexcel_crypto_priv *priv,
543 dma_addr_t ctxr_dma, int ring,
544 struct safexcel_request *request);
545int safexcel_init_ring_descriptors(struct safexcel_crypto_priv *priv,
546 struct safexcel_ring *cdr,
547 struct safexcel_ring *rdr);
548int safexcel_select_ring(struct safexcel_crypto_priv *priv);
549void *safexcel_ring_next_rptr(struct safexcel_crypto_priv *priv,
550 struct safexcel_ring *ring);
551void safexcel_ring_rollback_wptr(struct safexcel_crypto_priv *priv,
552 struct safexcel_ring *ring);
553struct safexcel_command_desc *safexcel_add_cdesc(struct safexcel_crypto_priv *priv,
554 int ring_id,
555 bool first, bool last,
556 dma_addr_t data, u32 len,
557 u32 full_data_len,
558 dma_addr_t context);
559struct safexcel_result_desc *safexcel_add_rdesc(struct safexcel_crypto_priv *priv,
560 int ring_id,
561 bool first, bool last,
562 dma_addr_t data, u32 len);
563void safexcel_inv_complete(struct crypto_async_request *req, int error);
564
565/* available algorithms */
566extern struct safexcel_alg_template safexcel_alg_ecb_aes;
567extern struct safexcel_alg_template safexcel_alg_cbc_aes;
568extern struct safexcel_alg_template safexcel_alg_sha1;
569extern struct safexcel_alg_template safexcel_alg_sha224;
570extern struct safexcel_alg_template safexcel_alg_sha256;
571extern struct safexcel_alg_template safexcel_alg_hmac_sha1;
572
573#endif